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

# libressl-EVP\_PKEY\_set1\_RSA(3)

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\_get0\_hmac**, **EVP\_PKEY\_get0**, **EVP\_PKEY\_assign\_RSA**, **EVP\_PKEY\_assign\_DSA**, **EVP\_PKEY\_assign\_DH**, **EVP\_PKEY\_assign\_EC\_KEY**, **EVP\_PKEY\_assign**, **EVP\_PKEY\_base\_id**, **EVP\_PKEY\_id**, **EVP\_PKEY\_type**, **EVP\_PKEY\_set\_type**, **EVP\_PKEY\_set\_type\_str** – EVP\_PKEY assignment functions

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/evp.h\>**

*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**(*const EVP\_PKEY \*pkey*);

*DSA* *\**\

**EVP\_PKEY\_get1\_DSA**(*const EVP\_PKEY \*pkey*);

*DH* *\**\

**EVP\_PKEY\_get1\_DH**(*const EVP\_PKEY \*pkey*);

*EC\_KEY* *\**\

**EVP\_PKEY\_get1\_EC\_KEY**(*const EVP\_PKEY \*pkey*);

*RSA* *\**\

**EVP\_PKEY\_get0\_RSA**(*const EVP\_PKEY \*pkey*);

*DSA* *\**\

**EVP\_PKEY\_get0\_DSA**(*const EVP\_PKEY \*pkey*);

*DH* *\**\

**EVP\_PKEY\_get0\_DH**(*const EVP\_PKEY \*pkey*);

*EC\_KEY* *\**\

**EVP\_PKEY\_get0\_EC\_KEY**(*const EVP\_PKEY \*pkey*);

*const* *unsigned* *char* *\**\

**EVP\_PKEY\_get0\_hmac**(*const EVP\_PKEY \*pkey*, *size\_t \*len*);

*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**(*EVP\_PKEY \*pkey*, *int type*, *void \*key*);

*int*\

**EVP\_PKEY\_base\_id**(*const EVP\_PKEY \*pkey*);

*int*\

**EVP\_PKEY\_id**(*const EVP\_PKEY \*pkey*);

*int*\

**EVP\_PKEY\_type**(*int type*);

*int*\

**EVP\_PKEY\_set\_type**(*EVP\_PKEY \*pkey*, *int type*);

*int*\

**EVP\_PKEY\_set\_type\_str**(*EVP\_PKEY \*pkey*, *const char \*str*, *int len*);

## DESCRIPTION

**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* and increment the reference count of *key* by 1 in case of success.

**EVP\_PKEY\_get1\_RSA**(), **EVP\_PKEY\_get1\_DSA**(), **EVP\_PKEY\_get1\_DH**(), and **EVP\_PKEY\_get1\_EC\_KEY**() return the key referenced in *pkey*, incrementing its reference count by 1, or NULL if the key is not of the correct type.

**EVP\_PKEY\_get0\_RSA**(), **EVP\_PKEY\_get0\_DSA**(), **EVP\_PKEY\_get0\_DH**(), **EVP\_PKEY\_get0\_EC\_KEY**(), and **EVP\_PKEY\_get0**() are identical except that they do not increment the reference count. Consequently, the returned key must not be freed by the caller.

**EVP\_PKEY\_get0\_hmac**() returns an internal pointer to the key referenced in *pkey* and sets \**len* to its length in bytes. The returned pointer must not be freed by the caller. If *pkey* is not of the correct type, NULL is returned and the content of \**len* becomes unspecified.

**EVP\_PKEY\_assign\_RSA**(), **EVP\_PKEY\_assign\_DSA**(), **EVP\_PKEY\_assign\_DH**(), **EVP\_PKEY\_assign\_EC\_KEY**(), and **EVP\_PKEY\_assign**() also set the referenced key to *key*; however these use the supplied *key* internally without incrementing its reference count, such that *key* will be freed when the parent *pkey* is freed. If the *key* is of the wrong type, these functions report success even though *pkey* ends up in a corrupted state. Even the functions explicitly containing the type in their name are *not* type safe because they are implemented as macros. The following types are supported: EVP\_PKEY\_RSA, EVP\_PKEY\_DSA, EVP\_PKEY\_DH, and EVP\_PKEY\_EC.

**EVP\_PKEY\_base\_id**() returns the type of *pkey* according to the following table:

| | | |
| --- | --- | --- |
| **return** **value** |  | **PEM** **type** **string** |
| EVP\_PKEY\_CMAC | = NID\_cmac | CMAC |
| EVP\_PKEY\_DH | = NID\_dhKeyAgreement | DH |
| EVP\_PKEY\_DSA | = NID\_dsa | DSA |
| EVP\_PKEY\_EC | = NID\_X9\_62\_id\_ecPublicKey | EC |
| EVP\_PKEY\_HMAC | = NID\_hmac | HMAC |
| EVP\_PKEY\_RSA | = NID\_rsaEncryption | RSA |
| EVP\_PKEY\_RSA\_PSS | = NID\_rsassaPss | RSA-PSS |

**EVP\_PKEY\_id**() returns the actual OID associated with *pkey*. Historically keys using the same algorithm could use different OIDs. The following deprecated aliases are still supported:

| | | |
| --- | --- | --- |
| **return** **value** |  | **alias** **for** |
| EVP\_PKEY\_DSA1 | = NID\_dsa\_2 | DSA |
| EVP\_PKEY\_DSA2 | = NID\_dsaWithSHA | DSA |
| EVP\_PKEY\_DSA3 | = NID\_dsaWithSHA1 | DSA |
| EVP\_PKEY\_DSA4 | = NID\_dsaWithSHA1\_2 | DSA |
| EVP\_PKEY\_RSA2 | = NID\_rsa | RSA |

Most applications wishing to know a key type will simply call **EVP\_PKEY\_base\_id**() and will not care about the actual type, which will be identical in almost all cases.

**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\_set\_type**() frees the key referenced in *pkey*, if any, and sets the key type of *pkey* to *type* without referencing a new key from *pkey* yet. For *type*, any of the possible return values of **EVP\_PKEY\_base\_id**() and **EVP\_PKEY\_id**() can be passed.

**EVP\_PKEY\_set\_type\_str**() frees the key referenced in *pkey*, if any, and sets the key type of *pkey* according to the PEM type string given by the first *len* bytes of *str*. If *len* is -1, the [strlen(3)](/strlen/3.md) of *str* is used instead. The PEM type strings supported by default are listed in the table above. This function does not reference a new key from *pkey*.

If *pkey* is a NULL pointer, **EVP\_PKEY\_set\_type**() and **EVP\_PKEY\_set\_type\_str**() check that a matching key type exists but do not change any object.

In accordance with the OpenSSL naming convention, the key obtained from or assigned to *pkey* using the **1** functions must be freed as well as *pkey*.

## RETURN VALUES

**EVP\_PKEY\_set1\_RSA**(), **EVP\_PKEY\_set1\_DSA**(), **EVP\_PKEY\_set1\_DH**(), **EVP\_PKEY\_set1\_EC\_KEY**(), **EVP\_PKEY\_assign\_RSA**(), **EVP\_PKEY\_assign\_DSA**(), **EVP\_PKEY\_assign\_DH**(), **EVP\_PKEY\_assign\_EC\_KEY**(), **EVP\_PKEY\_assign**(), **EVP\_PKEY\_set\_type**(), and **EVP\_PKEY\_set\_type\_str**() return 1 for success or 0 for failure.

**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\_get0\_hmac**(), and **EVP\_PKEY\_get0**() return the referenced key or NULL if an error occurred. For **EVP\_PKEY\_get0**(), the return value points to an *RSA*, *DSA*, *DH*, *EC\_KEY*, or *ASN1\_OCTET\_STRING* object depending on the type of *pkey*.

**EVP\_PKEY\_base\_id**(), **EVP\_PKEY\_id**(), and **EVP\_PKEY\_type**() return a key type or NID\_undef (equivalently EVP\_PKEY\_NONE) on error.

## SEE ALSO

DH\_new(3), DSA\_new(3), EC\_KEY\_new(3), EVP\_PKEY\_get0\_asn1(3), EVP\_PKEY\_new(3), RSA\_new(3)

## HISTORY

**EVP\_PKEY\_assign\_RSA**(), **EVP\_PKEY\_assign\_DSA**(), **EVP\_PKEY\_assign\_DH**(), **EVP\_PKEY\_assign**(), and **EVP\_PKEY\_type**() first appeared in SSLeay 0.8.0 and have been available since OpenBSD 2.4.

**EVP\_PKEY\_set1\_RSA**(), **EVP\_PKEY\_set1\_DSA**(), **EVP\_PKEY\_set1\_DH**(), **EVP\_PKEY\_get1\_RSA**(), **EVP\_PKEY\_get1\_DSA**(), and **EVP\_PKEY\_get1\_DH**() first appeared in OpenSSL 0.9.5 and have been available since OpenBSD 2.7.

**EVP\_PKEY\_set1\_EC\_KEY**(), **EVP\_PKEY\_get1\_EC\_KEY**(), and **EVP\_PKEY\_assign\_EC\_KEY**() first appeared in OpenSSL 0.9.8 and have been available since OpenBSD 4.5.

**EVP\_PKEY\_get0**(), **EVP\_PKEY\_base\_id**(), **EVP\_PKEY\_id**(), **EVP\_PKEY\_set\_type**(), and **EVP\_PKEY\_set\_type\_str**() first appeared in OpenSSL 1.0.0 and have been available since OpenBSD 4.9.

**EVP\_PKEY\_get0\_RSA**(), **EVP\_PKEY\_get0\_DSA**(), **EVP\_PKEY\_get0\_DH**(), and **EVP\_PKEY\_get0\_EC\_KEY**() first appeared in OpenSSL 1.1.0 and have been available since OpenBSD 6.3.

**EVP\_PKEY\_get0\_hmac**() first appeared in OpenSSL 1.1.0 and has been available since OpenBSD 6.5.
