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_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, EVP_PKEY_get0_siphash
  • EVP_PKEY_get0
  • EVP_PKEY_type
  • EVP_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 defining OPENSSL_API_COMPAT with a suitable version value, see openssl_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 an EVP_PKEY directly using the OSSL_DECODER APIs (see OSSL_DECODER_CTX_new_for_pkey(3)), or construct an EVP_PKEY from data using EVP_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 with EVP_PKEYs that have been assigned an internal key with EVP_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() and EVP_PKEY_set1_EC_KEY() β€” return 1 for success or 0 for failure. βœ…
  • EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and EVP_PKEY_get1_EC_KEY() β€” return the referenced key or NULL if an error occurred. 😭
  • 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() β€” return 1 for success and 0 for failure.
  • EVP_PKEY_get_base_id(), EVP_PKEY_get_id() and EVP_PKEY_type() β€” return a key type, or NID_undef (equivalently EVP_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 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