EVP_CIPHER_CTX_INIT(3)
π EVP_CIPHER_CTX_INIT(3) π
okay so bestie, gather round β this is a page about three obsolete EVP cipher functions from libcrypto, and honestly the whole thing is giving "found in grandma's attic" energy. It's part of the Library Functions Manual, and yes, we're going to read it together. π«Ά
β¨ NAME β¨
EVP_CIPHER_CTX_init, EVP_CIPHER_CTX_cleanup, EVP_Cipher β the obsolete EVP cipher functions. like, these are the legacy girlies. π
πΈ SYNOPSIS πΈ
First things first, you gotta pull in the header, and this all lives in the libcrypto library:
#include <openssl/evp.h>
int
EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx);
int
EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *ctx);
int
EVP_Cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
const unsigned char *in, unsigned int in_len);
π¦ DESCRIPTION π¦
π
EVP_CIPHER_CTX_init()
So this one is deprecated, okay? periodt. Back in the day β before EVP_CIPHER_CTX was made opaque β you could use it to clear a cipher context that was sitting on the stack. but the way that era is over.
- Calling it on a cipher context that was just returned from
EVP_CIPHER_CTX_new(3)? literally has no effect. nothing. zero. π - Calling it on a cipher context that was already used? may leak memory with older versions of the library. not the vibe. π
Instead, bestie, use EVP_CIPHER_CTX_reset(3) or EVP_CIPHER_CTX_free(3). those are the main characters now. π
π EVP_CIPHER_CTX_cleanup()
This is a deprecated alias for EVP_CIPHER_CTX_reset(3). It clears all information from ctx and frees all allocated memory associated with it β except the ctx object itself, which stays. she's still there, just emotionally reset. β¨
π₯ EVP_Cipher()
okay this function is highkey a jumpscare: it exposes implementation details of EVP_CipherUpdate(3) and EVP_CipherFinal(3) that should never have become part of the public API. not me exposing my internals on main. π
Here's how the behaviour goes down:
- If the flag
EVP_CIPH_FLAG_CUSTOM_CIPHERis set for the cipher used byctx, behaviour depends onin:- If that argument is
NULLandin_lenis0, behaviour is similar toEVP_CipherFinal(3). - If
in_lenis not0, behaviour is undefined. π¨ (yes, undefined. we don't do that.) - If
inis notNULL, behaviour is similar toEVP_CipherUpdate(3). - In both cases, the exceptions to the similarity are that arguments and return values differ. iykyk.
- If that argument is
- If the flag
EVP_CIPH_FLAG_CUSTOM_CIPHERis not set for the cipher used byctx, it encrypts or decrypts aligned blocks of data whose lengths match the cipher block size. Requirements:- the previous encryption or decryption operation using the same
ctx, if there was any, must have ended exactly on a block boundary, and in_lenmust be an integer multiple of the cipher block size.
- the previous encryption or decryption operation using the same
β οΈ If either of these conditions is violated, EVP_Cipher() silently produces incorrect results. silently!! incorrect!! results!! πππ
For that reason, using EVP_CipherUpdate(3) instead is strongly recommended. She can safely handle partial blocks, and even if in_len actually is a multiple of the cipher block size for all calls, the overhead incurred by using EVP_CipherUpdate(3) is minimal. so likeβ¦ just use her. slay. π
β RETURN VALUES β
EVP_CIPHER_CTX_init()β always returns1. every time. no notes. πEVP_CIPHER_CTX_cleanup()β returns1for success or0for failure.EVP_Cipher():- With
EVP_CIPH_FLAG_CUSTOM_CIPHER: returns the number of bytes written tooutfor success, or-1for failure. - Without
EVP_CIPH_FLAG_CUSTOM_CIPHER: returns1for success or0for failure.
- With
π§ SEE ALSO π§
π HISTORY π
EVP_Cipher()first appeared in SSLeay 0.6.5. βEVP_CIPHER_CTX_cleanup()first appeared in SSLeay 0.8.0. πΈEVP_CIPHER_CTX_init()first appeared in SSLeay 0.9.0. π¦- All these functions have been available since
OpenBSD 2.4. iconic longevity fr fr.
π CAVEATS π
Checking the return value of EVP_Cipher() requires unusual caution: zero signals success if EVP_CIPH_FLAG_CUSTOM_CIPHER is set, or failure otherwise. yes bestie, 0 means two completely different things depending on a flag. that's the trap. do not get got. π¨
mwah, that's the whole page β brought to you by the Debian build of this manual, dated June 8, 2025. go forth, use EVP_CIPHER_CTX_reset(3), and stay hydrated πβ¨
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2018, 2019, 2023 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2000-2001, 2015 The OpenSSL Project
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms