EVP_PKEY_CTX_NEW(3ossl)
π EVP_PKEY_CTX_NEW(3ossl) β OpenSSL public key algorithm context manual, bestie cut π
okay so real talk: this is the 3ossl page for all the EVP_PKEY_CTX new/dup/free/is_a functions, and itβs lowkey the backstage pass to OpenSSLβs high-level public key API. no cap. π
πΈ NAME πΈ
EVP_PKEY_CTX_new, EVP_PKEY_CTX_new_id, EVP_PKEY_CTX_new_from_name, EVP_PKEY_CTX_new_from_pkey, EVP_PKEY_CTX_dup, EVP_PKEY_CTX_free, EVP_PKEY_CTX_is_a β these are the public key algorithm context functions. yes bestie, all of them, weβre covering every single one π«Ά
β¨ 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 π¦
okay so hereβs the vibe check on every function, one by one:
EVP_PKEY_CTX_new()β allocates a public key algorithm context using thepkeykey type andENGINEe. thatβs the O.G. move πEVP_PKEY_CTX_new_id()β allocates a public key algorithm context using the key type specified byidandENGINEe. iconic, honestly β¨EVP_PKEY_CTX_new_from_name()β allocates a public key algorithm context using the library contextlibctx(seeOSSL_LIB_CTX(3)), the key type specified byname, and the property querypropquery. and bestie, listen: none of the arguments are duplicated, so they must remain unchanged for the lifetime of the returnedEVP_PKEY_CTXor of any of its duplicates. read further about the possible names in NOTES below πEVP_PKEY_CTX_new_from_pkey()β allocates a public key algorithm context using the library contextlibctx(seeOSSL_LIB_CTX(3)) and the algorithm specified bypkeyand the property querypropquery. again: none of the arguments are duplicated, so they must remain unchanged for the lifetime of the returnedEVP_PKEY_CTXor any of its duplicates. noted, queen πEVP_PKEY_CTX_new_id()andEVP_PKEY_CTX_new_from_name()are normally used when noEVP_PKEYstructure is associated with the operations, for example during parameter generation or key generation for some algorithms. itβs giving βno pkey? no problemβ energy π₯EVP_PKEY_CTX_dup()β duplicates the contextctx. it is not supported for a keygen operation. it is however possible to duplicate a context 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. lowkey specific, but important π«ΆEVP_PKEY_CTX_free()β frees up the contextctx. ifctxisNULL, nothing is done. clean, simple, no drama πEVP_PKEY_is_a()β checks if the key type associated withctxiskeytype. yes, thatβs exactly how the page says it here, bestie π
π 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.
π¨ major warning, bestie: contexts MUST NOT be shared between threads: that is it is not permissible to use the same context simultaneously in two threads. do not do it. iβm serious. π
π¦ On Key Types π¦
we mention βkey typeβ in this manual, which is the same as βalgorithmβ in most cases, allowing either term to be used interchangeably.
there are algorithms where the key type and the algorithm of the operations that use the keys are not the same, such as EC keys being used for ECDSA and ECDH operations. iykyk π
key types are given in two different manners:
π 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 are used by legacy methods. vintage, but make it cryptographic β¨
π 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. provider girlies stay winning π
β 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. classic βitβs giving success or itβs givingNULLβ πEVP_PKEY_CTX_free()does not return a value. itβs above returning things, honestly πEVP_PKEY_CTX_is_a()returns1for true and0for false. binary queen π
π SEE ALSO π
π°οΈ HISTORY π°οΈ
the EVP_PKEY_CTX_new(), EVP_PKEY_CTX_new_id(), EVP_PKEY_CTX_dup() and EVP_PKEY_CTX_free() functions were added in OpenSSL 1.0.0.
the EVP_PKEY_CTX_new_from_name() and EVP_PKEY_CTX_new_from_pkey() functions were added in OpenSSL 3.0. glow-up timeline fr fr β¨
Β©οΈ COPYRIGHT Β©οΈ
Copyright 2006-2025 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>.
π thatβs the whole page, bestie! this one is from OpenSSL3.5.6, dated2026-04-07, and itβs theEVP_PKEY_CTX_NEW(3ossl)manual. mwah π
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms