EVP_PKEY_SET1_RSA(3SSL)
π EVP_PKEY_SET1_RSA (3SSL) π
okay so bestie, welcome to the OpenSSL manual page for the EVP_PKEY assignment functions π this is the EVP_PKEY_SET1_RSA(3SSL) page and honestly it's giving "legacy API reunion tour". Buckle up. π¦
β¨ NAME β¨
Not me listing literally every single function on this page. There are SO many. Here they all are, no cap:
EVP_PKEY_set1_RSA,EVP_PKEY_set1_DSA,EVP_PKEY_set1_DH,EVP_PKEY_set1_EC_KEYEVP_PKEY_get1_RSA,EVP_PKEY_get1_DSA,EVP_PKEY_get1_DH,EVP_PKEY_get1_EC_KEYEVP_PKEY_get0_RSA,EVP_PKEY_get0_DSA,EVP_PKEY_get0_DH,EVP_PKEY_get0_EC_KEYEVP_PKEY_assign_RSA,EVP_PKEY_assign_DSA,EVP_PKEY_assign_DH,EVP_PKEY_assign_EC_KEY,EVP_PKEY_assign_POLY1305,EVP_PKEY_assign_SIPHASHEVP_PKEY_get0_hmac,EVP_PKEY_get0_poly1305,EVP_PKEY_get0_siphashEVP_PKEY_get0EVP_PKEY_typeEVP_PKEY_get_id,EVP_PKEY_get_base_id,EVP_PKEY_id,EVP_PKEY_base_id
^^ that whole squad is the EVP_PKEY assignment functions. periodt. π
πΈ SYNOPSIS πΈ
okay first things first, you gotta pull in the header:
#include <openssl/evp.h>
then the non-deprecated girlies (these are the ones you can still vibe with):
int EVP_PKEY_get_id(const EVP_PKEY *pkey);
int EVP_PKEY_get_base_id(const EVP_PKEY *pkey);
int EVP_PKEY_type(int type);
and the aliases, which are literally just macros (no cap, they're free):
#define EVP_PKEY_id EVP_PKEY_get_id
#define EVP_PKEY_base_id EVP_PKEY_get_base_id
β οΈ okay NOW the messy part. The following functions have been deprecated since OpenSSL 3.0, and can be hidden entirely by definingOPENSSL_API_COMPATwith a suitable version value, seeopenssl_user_macros(7):
int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key);
int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key);
int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key);
int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key);
RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey);
DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey);
DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey);
EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey);
const unsigned char *EVP_PKEY_get0_hmac(const EVP_PKEY *pkey, size_t *len);
const unsigned char *EVP_PKEY_get0_poly1305(const EVP_PKEY *pkey, size_t *len);
const unsigned char *EVP_PKEY_get0_siphash(const EVP_PKEY *pkey, size_t *len);
const RSA *EVP_PKEY_get0_RSA(const EVP_PKEY *pkey);
const DSA *EVP_PKEY_get0_DSA(const EVP_PKEY *pkey);
const DH *EVP_PKEY_get0_DH(const EVP_PKEY *pkey);
const EC_KEY *EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey);
void *EVP_PKEY_get0(const EVP_PKEY *pkey);
int EVP_PKEY_assign_RSA(EVP_PKEY *pkey, RSA *key);
int EVP_PKEY_assign_DSA(EVP_PKEY *pkey, DSA *key);
int EVP_PKEY_assign_DH(EVP_PKEY *pkey, DH *key);
int EVP_PKEY_assign_EC_KEY(EVP_PKEY *pkey, EC_KEY *key);
int EVP_PKEY_assign_POLY1305(EVP_PKEY *pkey, ASN1_OCTET_STRING *key);
int EVP_PKEY_assign_SIPHASH(EVP_PKEY *pkey, ASN1_OCTET_STRING *key);
π DESCRIPTION π
okay so let's go function by function, because there's a LOT of lore here. π«Ά
the type-checker girlies
EVP_PKEY_get_base_id() returns the type of pkey. For example, an RSA key will return EVP_PKEY_RSA. iconic, straightforward, we love her. β¨
EVP_PKEY_get_id() returns the actual NID associated with pkey β but ONLY if the pkey type isn't implemented just in a provider(7). Historically, keys using the same algorithm could use different NIDs. For example, an RSA key could use the NIDs corresponding to the NIDs NID_rsaEncryption (equivalent to EVP_PKEY_RSA) or NID_rsa (equivalent to EVP_PKEY_RSA2). The use of alternative non-standard NIDs is now rare, so EVP_PKEY_RSA2 et al are not often seen in practice. And if the pkey is only implemented in a provider(7), EVP_PKEY_get_id() returns -1 (EVP_PKEY_KEYMGMT). π
EVP_PKEY_type() returns the underlying type of the NID type. For example, EVP_PKEY_type(EVP_PKEY_RSA2) will return EVP_PKEY_RSA. it's giving "mystery solved". π
the set1 functions π
EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() and EVP_PKEY_set1_EC_KEY() set the key referenced by pkey to key.
π¨ bestie these are DEPRECATED. Applications should instead use EVP_PKEY_fromdata(3). fr fr, move on.
the assign functions π
EVP_PKEY_assign_RSA(), EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH(), EVP_PKEY_assign_EC_KEY(), EVP_PKEY_assign_POLY1305() and EVP_PKEY_assign_SIPHASH() set the referenced key to key β HOWEVER, these use the supplied key internally, and so key will be freed when the parent pkey is freed. π± (yes, she takes ownership. she's a little possessive like that.)
β οΈ These macros are deprecated. Applications should instead read anEVP_PKEYdirectly using theOSSL_DECODERAPIs (seeOSSL_DECODER_CTX_new_for_pkey(3)), or construct anEVP_PKEYfrom data usingEVP_PKEY_fromdata(3).
the get1 functions π
EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and EVP_PKEY_get1_EC_KEY() return the referenced key in pkey, or NULL if the key is not of the correct type.
π the returned key must be freed after use. yes girl, it's yours now, you're responsible for her.
These functions are deprecated. Applications should instead use the EVP_PKEY directly where possible. If access to the low level key parameters is required, then applications should use EVP_PKEY_get_params(3) and other similar functions. To write an EVP_PKEY out, use the OSSL_ENCODER APIs (see OSSL_ENCODER_CTX_new_for_pkey(3)).
the get0 functions π
EVP_PKEY_get0_hmac(), EVP_PKEY_get0_poly1305(), EVP_PKEY_get0_siphash(), EVP_PKEY_get0_RSA(), EVP_PKEY_get0_DSA(), EVP_PKEY_get0_DH() and EVP_PKEY_get0_EC_KEY() return the referenced key in pkey, or NULL if the key is not of the correct type.
π« the reference count of the returned key is NOT incremented, and so the key must not be freed after use. unlike her sister get1. do not free her, she does not belong to you.
These functions are deprecated. Applications should instead use the EVP_PKEY directly where possible. If access to the low level key parameters is required, then applications should use EVP_PKEY_get_params(3) and other similar functions. To write an EVP_PKEY out, use the OSSL_ENCODER APIs (see OSSL_ENCODER_CTX_new_for_pkey(3)).
EVP_PKEY_get0() returns a pointer to the legacy key, or NULL if the key is not legacy. β¨
the provider plot twist π
okay so here's the drama. Note that if an EVP_PKEY was not constructed using one of the deprecated functions such as EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() or EVP_PKEY_set1_EC_KEY(), or via the similarly named EVP_PKEY_assign macros described above β then the internal key will be managed by a provider (see provider(7)). π
And in that case, the key returned by EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH(), EVP_PKEY_get1_EC_KEY(), EVP_PKEY_get0_hmac(), EVP_PKEY_get0_poly1305(), EVP_PKEY_get0_siphash(), EVP_PKEY_get0_RSA(), EVP_PKEY_get0_DSA(), EVP_PKEY_get0_DH() or EVP_PKEY_get0_EC_KEY() will be a cached copy of the provider's key.
And likeβ¦ the two copies do NOT stay in sync, bestie. π Subsequent updates to the provider's key will not be reflected back in the cached copy, and updates made by an application to the returned key will not be reflected back in the provider's key. And subsequent calls to EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and EVP_PKEY_get1_EC_KEY() will always return the cached copy returned by the first call. it's the same copy every time. she's committed. π«Ά
π WARNINGS π
girl, listen. The following functions are only reliable withEVP_PKEYs that have been assigned an internal key withEVP_PKEY_assign_*():
EVP_PKEY_get_id(),EVP_PKEY_get_base_id(),EVP_PKEY_type()
For EVP_PKEY key type checking purposes, EVP_PKEY_is_a(3) is more generic. π
For purposes of retrieving the name of the EVP_PKEY, the function EVP_PKEY_get0_type_name(3) is more generally useful.
and then β the keys returned from the functions EVP_PKEY_get0_RSA(), EVP_PKEY_get0_DSA(), EVP_PKEY_get0_DH() and EVP_PKEY_get0_EC_KEY() were changed to have a "const" return type in OpenSSL 3.0. β¨ As described above, the keys returned may be cached copies of the key held in a provider. Because of this β and unlike in earlier versions of OpenSSL β they should be considered read-only copies of the key. Updates to these keys will not be reflected back in the provider side key.
The EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and EVP_PKEY_get1_EC_KEY() functions were not changed to have a "const" return type, in order that applications can "free" the return value. However, applications should still consider them as read-only copies. π read-only. we said what we said.
π§ NOTES π§
In accordance with the OpenSSL naming convention, the key obtained from β or assigned to β the pkey using the 1 functions must be freed as well as pkey. (that's the whole "1" lore, iykyk π )
EVP_PKEY_assign_RSA(), EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH(), EVP_PKEY_assign_EC_KEY(), EVP_PKEY_assign_POLY1305() and EVP_PKEY_assign_SIPHASH() are implemented as macros.
EVP_PKEY_assign_EC_KEY() looks at the curve name id to determine if the passed EC_KEY is an SM2(7) key, and will set the EVP_PKEY type to EVP_PKEY_SM2 in that case, instead of EVP_PKEY_EC. πΈ plot twist era.
Most applications wishing to know a key type will simply call EVP_PKEY_get_base_id() and will not care about the actual type: which will be identical in almost all cases. π
Previous versions of this document suggested using EVP_PKEY_type(pkey->type) to determine the type of a key. Since EVP_PKEY is now opaque, this is no longer possible: the equivalent is EVP_PKEY_get_base_id(pkey). π rip to that old syntax, you will not be missed.
β RETURN VALUES β
EVP_PKEY_set1_RSA(),EVP_PKEY_set1_DSA(),EVP_PKEY_set1_DH()andEVP_PKEY_set1_EC_KEY()β return1for success or0for failure. βEVP_PKEY_get1_RSA(),EVP_PKEY_get1_DSA(),EVP_PKEY_get1_DH()andEVP_PKEY_get1_EC_KEY()β return the referenced key orNULLif an error occurred. πEVP_PKEY_assign_RSA(),EVP_PKEY_assign_DSA(),EVP_PKEY_assign_DH(),EVP_PKEY_assign_EC_KEY(),EVP_PKEY_assign_POLY1305()andEVP_PKEY_assign_SIPHASH()β return1for success and0for failure.EVP_PKEY_get_base_id(),EVP_PKEY_get_id()andEVP_PKEY_type()β return a key type, orNID_undef(equivalentlyEVP_PKEY_NONE) on error. π
π SEE ALSO π
that's the whole friend group tbh.
π¦ HISTORY π¦
The EVP_PKEY_id() and EVP_PKEY_base_id() functions were renamed to include "get" in their names in OpenSSL 3.0, respectively. The old names are kept as non-deprecated alias macros. π so you can still call them, bestie, no shame.
EVP_PKEY_set1_RSA, EVP_PKEY_set1_DSA, EVP_PKEY_set1_DH, EVP_PKEY_set1_EC_KEY, EVP_PKEY_get1_RSA, EVP_PKEY_get1_DSA, EVP_PKEY_get1_DH, EVP_PKEY_get1_EC_KEY, EVP_PKEY_get0_RSA, EVP_PKEY_get0_DSA, EVP_PKEY_get0_DH, EVP_PKEY_get0_EC_KEY, EVP_PKEY_assign_RSA, EVP_PKEY_assign_DSA, EVP_PKEY_assign_DH, EVP_PKEY_assign_EC_KEY, EVP_PKEY_assign_POLY1305, EVP_PKEY_assign_SIPHASH, EVP_PKEY_get0_hmac, EVP_PKEY_get0_poly1305 and EVP_PKEY_get0_siphash were deprecated in OpenSSL 3.0. π―οΈ
The return value from EVP_PKEY_get0_RSA, EVP_PKEY_get0_DSA, EVP_PKEY_get0_DH, EVP_PKEY_get0_EC_KEY were made const in OpenSSL 3.0. β¨
The function EVP_PKEY_set_alias_type() was previously documented on this page. It was removed in OpenSSL 3.0. π gone but not forgotten.
π COPYRIGHT π
Copyright 2002-2023 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>.
and that's the whole page, bestie π«Ά tysm for reading, stay deprecated-free, and remember: this was EVP_PKEY_SET1_RSA(3SSL) from OpenSSL 4.0.3, dated 2026-09-29. 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