EVP_CIPHER_C..._CIPHER_DATA(3ossl)

πŸ’– EVP_CIPHER_CTX_get_cipher_data, EVP_CIPHER_CTX_set_cipher_data πŸ’–

okay bestie, welcome to the OpenSSL manual, section 3ossl β€” yes the whole page title got squished into EVP_CIPHER_C..._CIPHER_DATA(3ossl) and honestly? iconic of them. today we're talking about two lil functions that peek at and swap out the cipher data inside an EVP_CIPHER_CTX. get comfy, we're going in 🫢


✨ NAME ✨

EVP_CIPHER_CTX_get_cipher_data, EVP_CIPHER_CTX_set_cipher_data β€” the routines you call to inspect and modify EVP_CIPHER_CTX objects. that's the whole vibe. 🌸


🌈 SYNOPSIS 🌈

#include <openssl/evp.h>

void *EVP_CIPHER_CTX_get_cipher_data(const EVP_CIPHER_CTX *ctx);
void *EVP_CIPHER_CTX_set_cipher_data(EVP_CIPHER_CTX *ctx, void *cipher_data);

so cute, so simple, two little lines πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so like, EVP_CIPHER_CTX_get_cipher_data() returns a pointer to the cipher data that's relevant to the EVP_CIPHER_CTX. and the tea is: what's actually inside that data is specific to the particular implementation of the cipher. it's giving ✨mystery box✨. for example, this data can be used by engines to store engine specific information. engines love a little secret pocket, iykyk.

and the data is automatically allocated and freed by OpenSSL, so applications and engines should not normally free this directly β€” but hold on, keep reading, there's a "but see below" situation going on πŸ‘€.

EVP_CIPHER_CTX_set_cipher_data() is the glow-up function: it lets an application or an engine replace the cipher data with new data. and as a lil bonus, a pointer to any existing cipher data gets returned from this function. if the old data is no longer required then it should be freed through a call to OPENSSL_free().

⚠️ bestie listen: that OPENSSL_free() part is on YOU. don't just walk away from the old pointer and let it haunt the heap, okay? πŸ™ˆ

πŸ’€ RETURN VALUES πŸ’€

  • EVP_CIPHER_CTX_get_cipher_data() returns a pointer to the current cipher data for the EVP_CIPHER_CTX.
  • EVP_CIPHER_CTX_set_cipher_data() returns a pointer to the old cipher data for the EVP_CIPHER_CTX.

that's it. that's the returns. no tricks, no surprise negative values, just pointers doing their thing πŸŽ€


πŸ‘‘ HISTORY πŸ‘‘

not me looking up the lore: the EVP_CIPHER_CTX_get_cipher_data() and EVP_CIPHER_CTX_set_cipher_data() functions were added in OpenSSL 1.1.0. so they're not new-new but they're not ancient either. middle child energy fr fr ⭐


Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.

so like, read the license, respect the license, it's the law and also it's just polite πŸ’œ


and that's the whole page, bestie!! you understood the assignment. slay πŸ’…βœ¨

this was OpenSSL 3.5.9, dated 2026-09-29 β€” mwah, go forth and cipher responsibly πŸ§šπŸ’–

πŸ“¦ where this page comes from