EVP_PKEY_CTX_NEW(3SSL)
π EVP_PKEY_CTX_NEW β public key algorithm context functions π
okay bestie, sit down, hydrate, and let's talk about contexts, because this is the OpenSSL 3SSL manual and it's lowkey iconic. this one's all about making (and yeeting) your public key algorithm contexts. no cap, it's giving "plumbing that everything else sits on top of" energy. β¨
π¦ SYNOPSIS π¦
#include <openssl/evp.h>
EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e);
EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e);
EVP_PKEY_CTX *EVP_PKEY_CTX_new_from_name(OSSL_LIB_CTX *libctx,
const char *name,
const char *propquery);
EVP_PKEY_CTX *EVP_PKEY_CTX_new_from_pkey(OSSL_LIB_CTX *libctx,
EVP_PKEY *pkey,
const char *propquery);
EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *ctx);
void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx);
int EVP_PKEY_CTX_is_a(EVP_PKEY_CTX *ctx, const char *keytype);
πΈ DESCRIPTION πΈ
So here's the tea, function by function:
EVP_PKEY_CTX_new()allocates a public key algorithm context using thepkeykey type. and<italic>e</italic>must beNULL. that's not a suggestion, that's the rule. πEVP_PKEY_CTX_new_id()allocates a public key algorithm context using the key type specified byid. same deal:<italic>e</italic>must beNULL.EVP_PKEY_CTX_new_from_name()allocates a public key algorithm context using the library contextlibctx(peepOSSL_LIB_CTX(3)), the key type specified byname, and the property querypropquery. β οΈ none of the arguments are duplicated, so they must remain unchanged for the lifetime of the returnedEVP_PKEY_CTXor of any of its duplicates. want the deets on possible names? scroll to NOTES below, bestie.EVP_PKEY_CTX_new_from_pkey()allocates a public key algorithm context using the library contextlibctx(yep,OSSL_LIB_CTX(3)again) and the algorithm specified bypkey, plus the property querypropquery. and again: none of the arguments are duplicated, so they must remain unchanged for the lifetime of the returnedEVP_PKEY_CTXor any of its duplicates. π«ΆEVP_PKEY_CTX_new_id()andEVP_PKEY_CTX_new_from_name()are normally the ones you reach for when there's noEVP_PKEYstructure chillin' with the operations β like during parameter generation, or key generation for some algorithms. and listen: the key thatEVP_PKEY_generate(3)hands back is not associated with the generation context. so if you wanna actually do stuff with that key, you make a fresh context withEVP_PKEY_CTX_new_from_pkey(3). periodt.EVP_PKEY_CTX_dup()duplicates the contextctx. it is not supported for a keygen operation. but!!! it is possible to duplicate a context that was freshly created via any of the above "new" functions β providedEVP_PKEY_keygen_init(3)has not yet been called on the source context β and then use the copy for key generation. sneaky but legal. πEVP_PKEY_CTX_free()frees up the contextctx. and ifctxisNULL? nothing happens. no drama, no crash, just vibes. β¨EVP_PKEY_is_a()checks if the key type associated withctxiskeytype.
π NOTES π
π On EVP_PKEY_CTX π
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. like, it is not permissible to use the same context simultaneously in two threads. do not do it. don't even think about it. π
π§ On Key Types π§
We say "key type" in this manual, which is the same as "algorithm" in most cases β either term is fine, they're interchangeable, slay. but heads up: there are algorithms where the key type and the algorithm of the operations that use those keys are not the same. prime example: EC keys being used for ECDSA and ECDH operations. π¦
Key types come in two different flavors:
β Legacy NID or EVP_PKEY type
This is the id used with EVP_PKEY_CTX_new_id().
These are EVP_PKEY_RSA, EVP_PKEY_RSA_PSS, EVP_PKEY_DSA, EVP_PKEY_DH, EVP_PKEY_EC, EVP_PKEY_SM2, EVP_PKEY_X25519, EVP_PKEY_X448, and they're used by legacy methods.
β Name strings
This is the name used with EVP_PKEY_CTX_new_from_name().
These are names like "RSA", "DSA", and what's available depends on what providers are currently accessible. π₯
The OpenSSL providers offer a set of key types available this way β please see OSSL_PROVIDER-FIPS(7) and OSSL_PROVIDER-default(7) and related documentation for more information. iykyk.
π RETURN VALUES π
EVP_PKEY_CTX_new(),EVP_PKEY_CTX_new_id()andEVP_PKEY_CTX_dup()return either the newly allocatedEVP_PKEY_CTXstructure orNULLif an error occurred. πEVP_PKEY_CTX_free()does not return a value. it just. does the thing. πEVP_PKEY_CTX_is_a()returns1for true and0for false. β¨
π₯ SEE ALSO π₯
π HISTORY π
EVP_PKEY_CTX_new(),EVP_PKEY_CTX_new_id(),EVP_PKEY_CTX_dup()andEVP_PKEY_CTX_free()were added in OpenSSL 1.0.0.EVP_PKEY_CTX_new_from_name()andEVP_PKEY_CTX_new_from_pkey()were added in OpenSSL 3.0.
π COPYRIGHT π
Copyright 2006-2026 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>.
okay bestie that's the whole page, you ate it, no crumbs left. π go forth and make your contexts (and remember to free them, the memory leak allegations are not the vibe π).
version 4.0.3 Β· dated 2026-09-29 Β· from your favorite EVP_PKEY_CTX_NEW(3SSL) manual, mwah π
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms