EVP_CIPHER_CTX_CTRL(3)
π 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()β returns1for success or0for failure. some implementations may return negative values for some errors πEVP_CIPHER_CTX_set_padding()β always returns1β¨ iconic, no notes.EVP_CIPHER_CTX_set_key_length(),EVP_CIPHER_CTX_set_iv(), andEVP_CIPHER_CTX_get_iv()β return1for success or0for failure.EVP_CIPHER_CTX_key_length()andEVP_CIPHER_key_length()β return the key length.EVP_CIPHER_CTX_iv_length()andEVP_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(), andEVP_CIPHER_iv_length()first appeared in SSLeay 0.6.5 and have been available since OpenBSD 2.4 πEVP_CIPHER_CTX_ctrl()andEVP_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()andEVP_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_LENGTHandEVP_MAX_IV_LENGTHonly 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 fixedunsigned chararray containingEVP_MAX_KEY_LENGTHbytes. 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
- opensuse-leap 16.0: libressl-devel-doc 4.1.0-bp160.1.1 Β· OpenSSL
- Copyright (c) 2018, 2023 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2018 Damien Miller <djm@openbsd.org>
- Copyright (c) 2000, 2001, 2016 The OpenSSL Project
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms