---
name: "EVP_PKEY_set1_RSA"
section: "3ssl"
platform: "linux"
package: "openssl"
version: "3.6.5-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/EVP_PKEY_set1_RSA"
---

# EVP\_PKEY\_set1\_RSA(3ssl)

EVP\_PKEY assignment functions

## NAME

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\_set1\_engine, EVP\_PKEY\_get0\_engine, EVP\_PKEY\_id, EVP\_PKEY\_base\_id - EVP\_PKEY assignment functions

## SYNOPSIS

```
 #include <openssl/evp.h>
 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);
 #define EVP_PKEY_id EVP_PKEY_get_id
 #define EVP_PKEY_base_id EVP_PKEY_get_base_id
```

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);
 ENGINE *EVP_PKEY_get0_engine(const EVP_PKEY *pkey);
 int EVP_PKEY_set1_engine(EVP_PKEY *pkey, ENGINE *engine);
```

## DESCRIPTION

**EVP\_PKEY\_get\_base\_id()** returns the type of *pkey*. For example an RSA key will return **EVP\_PKEY\_RSA**.

**EVP\_PKEY\_get\_id()** returns the actual NID associated with *pkey* 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. **EVP\_PKEY\_get\_id()** returns -1 (**EVP\_PKEY\_KEYMGMT**) if the *pkey* is only implemented in a **provider**(7).

**EVP\_PKEY\_type()** returns the underlying type of the NID *type*. For example EVP\_PKEY\_type(EVP\_PKEY\_RSA2) will return **EVP\_PKEY\_RSA**.

**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*. These functions are deprecated. Applications should instead use **EVP\_PKEY\_fromdata**(3).

**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. 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).

**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. 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\_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. 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.

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)). 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. 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. 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.

**EVP\_PKEY\_get0\_engine()** returns a reference to the ENGINE handling *pkey*. This function is deprecated. Applications should use providers instead of engines (see **provider**(7) for details).

**EVP\_PKEY\_set1\_engine()** sets the ENGINE handling *pkey* to *engine*. It must be called after the key algorithm and components are set up. If *engine* does not include an **EVP\_PKEY\_METHOD** for *pkey* an error occurs. This function is deprecated. Applications should use providers instead of engines (see **provider**(7) for details).

## WARNINGS

The following functions are only reliable with **EVP\_PKEY**s 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.

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. Due to 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.

## 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*.

**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**.

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).

**EVP\_PKEY\_set1\_engine()** is typically used by an ENGINE returning an HSM key as part of its routine to load a private key.

## 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.

**EVP\_PKEY\_set1\_engine()** returns 1 for success and 0 for failure.

## SEE ALSO

**EVP\_PKEY\_new**(3), **SM2**(7)

## 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.

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\_set1\_engine and EVP\_PKEY\_get0\_engine 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.

## 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\>.
