EVP_CIPHER_CTX_INIT(3)
π EVP_CIPHER_CTX_INIT(3) β Library Functions Manual
okay so bestie, buckle up π this page is literally the "obsolete EVP cipher functions" page β the library-functions-manual one β and it's giving retirement home for C functions. we're talking EVP_CIPHER_CTX_init, EVP_CIPHER_CTX_cleanup, and EVP_Cipher, and honestly? they're all deprecated. like, all three. the whole squad. π
β¨ NAME β¨
EVP_CIPHER_CTX_init, EVP_CIPHER_CTX_cleanup, EVP_Cipher β obsolete EVP cipher functions π«Ά
πΈ SYNOPSIS πΈ
#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 π¦
the init one (deprecated, gorl π)
EVP_CIPHER_CTX_init() is a deprecated function that could be used to clear a cipher context on the stack back in the day β y'know, before EVP_CIPHER_CTX was made opaque. if you call it on a cipher context you just got back from EVP_CIPHER_CTX_new(3), it literally does nothing β no effect, zero, nada β¨
but calling it on a cipher context that was already used? yeah that may leak memory with older versions of the library π so instead, do yourself a favor and use EVP_CIPHER_CTX_reset(3) or EVP_CIPHER_CTX_free(3). periodt.
the cleanup one (a deprecated alias, iykyk)
EVP_CIPHER_CTX_cleanup() is a deprecated alias for EVP_CIPHER_CTX_reset(3). it clears all the information from ctx and frees all allocated memory associated with it β everything except the ctx object itself π«Ά so the context container stays, but the vibes inside get yeeted.
the Cipher one (exposing dev secrets, not slay)
EVP_Cipher() exposes implementation details of EVP_CipherUpdate(3) and EVP_CipherFinal(3) that should never have become part of the public API. like, who let that happen π not me, not you.
if the flag EVP_CIPH_FLAG_CUSTOM_CIPHER is set for the cipher used by ctx, behaviour depends on in:
- if that argument is
NULLandin_lenis0, behaviour is similar toEVP_CipherFinal(3) - if
in_lenis not0, behaviour is undefined π (yes, undefined, like your ex's plans) - if
inis notNULL, behaviour is similar toEVP_CipherUpdate(3)
in both of those cases, the exceptions to the similarity are that arguments and return values differ. so like⦠similar but not same same, yfm?
if the flag EVP_CIPH_FLAG_CUSTOM_CIPHER is not set for the cipher used by ctx, it encrypts or decrypts aligned blocks of data whose lengths match the cipher block size. it requires:
- that the previous encryption or decryption operation using the same
ctx, if there was any, ended exactly on a block boundary - that
in_lenis an integer multiple of the cipher block size
if either of these conditions is violated, EVP_Cipher() silently produces incorrect results ππ that's the worst kind of bug, the quiet kind. for that reason, using the function EVP_CipherUpdate(3) instead is strongly recommended. the latter 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 the good one, bestie π«Ά
π RETURN VALUES π
EVP_CIPHER_CTX_init()β always returns1. iconic, unbothered, never fails.EVP_CIPHER_CTX_cleanup()β returns1for success or0for failure.- with
EVP_CIPH_FLAG_CUSTOM_CIPHER,EVP_Cipher()returns the number of bytes written tooutfor success or-1for failure. - without
EVP_CIPH_FLAG_CUSTOM_CIPHER,EVP_Cipher()returns1for success or0for failure.
π SEE ALSO π
evp(3), EVP_EncryptInit(3) β go read those, they're the main characters here π
β 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.
so yeah, they've been around since forever β genuine elders of the codebase π§
π CAVEATS π
checking the return value ofEVP_Cipher()requires unusual caution:0signals success ifEVP_CIPH_FLAG_CUSTOM_CIPHERis set β or failure otherwise. yes literally the same number means opposite things depending on a flag π that is not a vibe check that is a vibe trap, be careful out there fr fr.
mwah π this lil page was brought to you by Debian, dated December 6, 2024 β EVP_CIPHER_CTX_INIT(3), out. go reset your contexts properly, ily π«Άβ¨
π¦ where this page comes from
- opensuse-leap 16.0: libressl-devel-doc 4.1.0-bp160.1.1 Β· 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