EVP_CIPHER_CTX_CTRL(3)

πŸ“¦ version 4.1.0, in opensuse-leap 16.0

πŸ’… EVP_CIPHER_CTX_CTRL β€” configure EVP cipher contexts ✨

okay so bestie, welcome to the EVP_CIPHER_CTX_CTRL(3) page from the Library Functions Manual πŸŽ€ this is the whole little friend group of functions that poke at your EVP cipher contexts and tell them how to behave. buckle up, it's giving "glow-up for your crypto context" πŸ’–

✨ NAME ✨

EVP_CIPHER_CTX_ctrl, EVP_CIPHER_CTX_set_padding, EVP_CIPHER_CTX_set_key_length, EVP_CIPHER_CTX_key_length, EVP_CIPHER_key_length, EVP_CIPHER_CTX_iv_length, EVP_CIPHER_iv_length, EVP_CIPHER_CTX_set_iv, EVP_CIPHER_CTX_get_iv β€” configure EVP cipher contexts πŸ¦‹


πŸŽ€ SYNOPSIS πŸŽ€

#include <openssl/evp.h>

int
EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);

int
EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *x, int padding);

int
EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen);

int
EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx);

int
EVP_CIPHER_key_length(const EVP_CIPHER *e);

int
EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx);

int
EVP_CIPHER_iv_length(const EVP_CIPHER *e);

int
EVP_CIPHER_CTX_set_iv(EVP_CIPHER_CTX *ctx, const unsigned char *iv,
    size_t len);

int
EVP_CIPHER_CTX_get_iv(const EVP_CIPHER_CTX *ctx, unsigned char *iv,
    size_t len);

🌸 DESCRIPTION 🌸

EVP_CIPHER_CTX_ctrl() β€” this is the little switchboard where you get and set all the cipher-specific params πŸ’… and rn? literally only the RC2 effective key length can be set. that's it, that's the whole menu. peep EVP_rc2_cbc(3) for the deets πŸ“

EVP_CIPHER_CTX_set_padding() β€” turns padding on or off, no cap ✨ but heads up: you gotta call this after the context is all set up for encryption or decryption with EVP_EncryptInit_ex(3), EVP_DecryptInit_ex(3), or EVP_CipherInit_ex(3). by default, encryption ops are padded using standard block padding, and the padding gets checked and removed when decrypting 🧚 if the padding parameter is zero, then no padding happens at all β€” and then the total amount of data you encrypt or decrypt must be a multiple of the block size or you get an error 😭 like fr fr, do not test it.

EVP_CIPHER_CTX_set_key_length() β€” sets the key length of the cipher ctx. but if the cipher is a fixed length cipher? then trying to set the key length to literally anything other than the fixed value is an error πŸ’€ no wiggle room, bestie.

EVP_CIPHER_CTX_key_length() and EVP_CIPHER_key_length() β€” these return the key length of a cipher when you pass them an EVP_CIPHER_CTX or EVP_CIPHER structure respectively πŸ‘‘ the constant EVP_MAX_KEY_LENGTH is the maximum key length for all ciphers. and okay, important note: even though EVP_CIPHER_key_length() is fixed for a given cipher, the value of EVP_CIPHER_CTX_key_length() may be different for variable key length ciphers πŸ¦‹ so like, don't assume they match, iykyk.

EVP_CIPHER_CTX_iv_length() and EVP_CIPHER_iv_length() β€” these return the IV length of a cipher when passed an EVP_CIPHER_CTX or EVP_CIPHER. and if the cipher doesn't use an IV? they return zero 🫢 also EVP_CIPHER_CTX_iv_length() can fail and return -1 πŸ™ˆ the constant EVP_MAX_IV_LENGTH is the maximum IV length for all ciphers ⭐

EVP_CIPHER_CTX_set_iv() and EVP_CIPHER_CTX_get_iv() β€” these set and retrieve the IV for an EVP_CIPHER_CTX, respectively πŸ’œ in both cases, the specified IV length must exactly equal the expected IV length for the context, as returned by EVP_CIPHER_CTX_iv_length() β€” exact match or nothing, periodt πŸ”₯


πŸ’€ RETURN VALUES πŸ’€

  • EVP_CIPHER_CTX_ctrl() β€” returns 1 for success or 0 for failure. some implementations may return negative values for some errors πŸ™ˆ
  • EVP_CIPHER_CTX_set_padding() β€” always returns 1 ✨ iconic, no notes.
  • EVP_CIPHER_CTX_set_key_length(), EVP_CIPHER_CTX_set_iv(), and EVP_CIPHER_CTX_get_iv() β€” return 1 for success or 0 for failure.
  • EVP_CIPHER_CTX_key_length() and EVP_CIPHER_key_length() β€” return the key length.
  • EVP_CIPHER_CTX_iv_length() and EVP_CIPHER_iv_length() β€” return the IV length, or zero if the cipher does not use an IV. and again, EVP_CIPHER_CTX_iv_length() can fail and return -1 😭

πŸ”₯ SEE ALSO πŸ”₯


🌈 HISTORY 🌈

  • EVP_CIPHER_CTX_key_length(), EVP_CIPHER_key_length(), EVP_CIPHER_CTX_iv_length(), and EVP_CIPHER_iv_length() first appeared in SSLeay 0.6.5 and have been available since OpenBSD 2.4 πŸ’–
  • EVP_CIPHER_CTX_ctrl() and EVP_CIPHER_CTX_set_key_length() first appeared in OpenSSL 0.9.6 and have been available since OpenBSD 2.9 πŸ¦‹
  • EVP_CIPHER_CTX_set_padding() first appeared in OpenSSL 0.9.7 and has been available since OpenBSD 3.2 🌸
  • EVP_CIPHER_CTX_set_iv() and EVP_CIPHER_CTX_get_iv() first appeared in LibreSSL 2.8.1 and have been available since OpenBSD 6.4 ⭐

🫢 BUGS 🫢

okay so this is the messy part, bestie 😭 EVP_MAX_KEY_LENGTH and EVP_MAX_IV_LENGTH only refer to the internal ciphers with default key lengths. if custom ciphers exceed these values, the results are unpredictable πŸ’€ and the reason? because it has become standard practice to define a generic key as a fixed unsigned char array containing EVP_MAX_KEY_LENGTH bytes. so yeah. that's the vibe. be careful out there πŸ™ˆ

and that's the page, angel πŸ’… this one's from the Debian build, dated March 25, 2025 β€” go forth and configure your cipher contexts responsibly, mwah πŸŽ€πŸ’–βœ¨

πŸ“¦ where this page comes from