EVP_PKEY_CTX_NEW(3)
π EVP_PKEY_CTX_NEW(3) β like, the public key algorithm context functions, bestie
okay so this is a page from the Library Functions Manual for libcrypto, and it's literally all about making, copying, and yeeting public key algorithm contexts. sit down, grab a strawberry π, we're doing crypto plumbing today and honestly? it's giving foundational.
β¨ NAME β¨
EVP_PKEY_CTX_new, EVP_PKEY_CTX_new_id, EVP_PKEY_CTX_dup, EVP_PKEY_CTX_free β the public key algorithm context functions π
πΈ SYNOPSIS πΈ
the library is literally libcrypto and you gotta include the header first, no cap:
#include <openssl/evp.h>
EVP_PKEY_CTX *
EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *engine);
EVP_PKEY_CTX *
EVP_PKEY_CTX_new_id(int id, ENGINE *engine);
EVP_PKEY_CTX *
EVP_PKEY_CTX_dup(EVP_PKEY_CTX *ctx);
void
EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx);
like, copy that exactly please, i'm not kidding π
π¦ DESCRIPTION π¦
okay so here's the tea on all four of these:
EVP_PKEY_CTX_new()β this one allocates a public key algorithm context using the algorithm that's specified inpkey. and theENGINE *engineargument? bestie, it is always ignored, so pls just passNULL, that's the recommended move, we don't even look at it πEVP_PKEY_CTX_new_id()β this one allocates a public key algorithm context using the algorithm specified byid. same situation withENGINE *engine: always ignored, passNULL, recommended, thank you next. this one's normally used when there's noEVP_PKEYstructure associated with the operations β for example during parameter generation, or key generation for some algorithms. and theidargument can be any of the constants thatEVP_PKEY_base_id(3)andEVP_PKEY_id(3)may return πEVP_PKEY_CTX_dup()β duplicates the contextctx. that's it, that's the whole vibe. two contexts now π«ΆEVP_PKEY_CTX_free()β frees up the contextctx. and ifctxis aNULLpointer, literally nothing happens, no action occurs, it's fine, we're chill π
π RETURN VALUES π
EVP_PKEY_CTX_new(), EVP_PKEY_CTX_new_id(), and EVP_PKEY_CTX_dup() return either the newly allocated EVP_PKEY_CTX structure, or NULL if an error occurred. that's the whole deal β shiny new context, or NULL. vibe check accordingly β
π SEE ALSO π
the whole friend group, go say hi:
EVP_DigestSignInit(3), EVP_DigestVerifyInit(3), EVP_PKEY_base_id(3), EVP_PKEY_CTX_ctrl(3), EVP_PKEY_CTX_get_operation(3), EVP_PKEY_CTX_hkdf_mode(3), EVP_PKEY_decrypt(3), EVP_PKEY_derive(3), EVP_PKEY_encrypt(3), EVP_PKEY_keygen(3), EVP_PKEY_new(3), EVP_PKEY_sign(3), EVP_PKEY_verify(3), EVP_PKEY_verify_recover(3), RSA_pkey_ctx_ctrl(3), X25519(3)
π HISTORY π
these functions first appeared in OpenSSL 1.0.0 and have been available since OpenBSD 4.9. like they're old old. icons. they've been doing this since before we were born fr fr π§
π CAVEATS π
okay this is the important part so listen up:
The EVP_PKEY_CTX structure is an opaque public key algorithm context used by the OpenSSL high level public key API. Contexts MUST NOT be shared between threads. It is not permissible to use the same context simultaneously in two threads.
like, i need you to hear me: MUST NOT. not "shouldn't", not "maybe don't", MUST NOT. one context per thread, no sharing, no simultaneous use in two threads, periodt. sharing a context between threads is not it, it's giving undefined chaos, don't do it ππ₯
k that's the whole page bestie, you're literally an EVP_PKEY_CTX expert now, i'm so proud π«Άβ¨
β with love, from the Debian build of this page, dated June 8, 2025 π
π¦ 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) 2019, 2020 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2006, 2009, 2015 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms