---
name: "libressl-RSA_pkey_ctx_ctrl"
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-RSA_pkey_ctx_ctrl"
---

# libressl-RSA\_pkey\_ctx\_ctrl(3)

RSA private key control operations

## NAME

**RSA\_pkey\_ctx\_ctrl**, **EVP\_PKEY\_CTX\_set\_rsa\_padding**, **EVP\_PKEY\_CTX\_get\_rsa\_padding**, **EVP\_PKEY\_CTX\_set\_rsa\_keygen\_bits**, **EVP\_PKEY\_CTX\_set\_rsa\_keygen\_pubexp**, **EVP\_PKEY\_CTX\_set\_rsa\_mgf1\_md**, **EVP\_PKEY\_CTX\_get\_rsa\_mgf1\_md**, **EVP\_PKEY\_CTX\_set\_rsa\_oaep\_md**, **EVP\_PKEY\_CTX\_get\_rsa\_oaep\_md**, **EVP\_PKEY\_CTX\_set0\_rsa\_oaep\_label**, **EVP\_PKEY\_CTX\_get0\_rsa\_oaep\_label**, **EVP\_PKEY\_CTX\_set\_rsa\_pss\_saltlen**, **EVP\_PKEY\_CTX\_get\_rsa\_pss\_saltlen**, **EVP\_PKEY\_CTX\_set\_rsa\_pss\_keygen\_md**, **EVP\_PKEY\_CTX\_set\_rsa\_pss\_keygen\_mgf1\_md**, **EVP\_PKEY\_CTX\_set\_rsa\_pss\_keygen\_saltlen** – RSA private key control operations

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

*int*\

**RSA\_pkey\_ctx\_ctrl**(*EVP\_PKEY\_CTX \*ctx*, *int optype*, *int cmd*, *int p1*, *void \*p2*);

*int*\

**EVP\_PKEY\_CTX\_set\_rsa\_padding**(*EVP\_PKEY\_CTX \*ctx*, *int pad*);

*int*\

**EVP\_PKEY\_CTX\_get\_rsa\_padding**(*EVP\_PKEY\_CTX \*ctx*, *int \*ppad*);

*int*\

**EVP\_PKEY\_CTX\_set\_rsa\_keygen\_bits**(*EVP\_PKEY\_CTX \*ctx*, *int mbits*);

*int*\

**EVP\_PKEY\_CTX\_set\_rsa\_keygen\_pubexp**(*EVP\_PKEY\_CTX \*ctx*, *BIGNUM \*pubexp*);

*int*\

**EVP\_PKEY\_CTX\_set\_rsa\_mgf1\_md**(*EVP\_PKEY\_CTX \*ctx*, *const EVP\_MD \*md*);

*int*\

**EVP\_PKEY\_CTX\_get\_rsa\_mgf1\_md**(*EVP\_PKEY\_CTX \*ctx*, *const EVP\_MD \*\*pmd*);

*int*\

**EVP\_PKEY\_CTX\_set\_rsa\_oaep\_md**(*EVP\_PKEY\_CTX \*ctx*, *const EVP\_MD \*md*);

*int*\

**EVP\_PKEY\_CTX\_get\_rsa\_oaep\_md**(*EVP\_PKEY\_CTX \*ctx*, *const EVP\_MD \*\*pmd*);

*int*\

**EVP\_PKEY\_CTX\_set0\_rsa\_oaep\_label**(*EVP\_PKEY\_CTX \*ctx*, *unsigned char \*label*, *int len*);

*int*\

**EVP\_PKEY\_CTX\_get0\_rsa\_oaep\_label**(*EVP\_PKEY\_CTX \*ctx*, *unsigned char \*\*plabel*);

*int*\

**EVP\_PKEY\_CTX\_set\_rsa\_pss\_saltlen**(*EVP\_PKEY\_CTX \*ctx*, *int len*);

*int*\

**EVP\_PKEY\_CTX\_get\_rsa\_pss\_saltlen**(*EVP\_PKEY\_CTX \*ctx*, *int \*plen*);

*int*\

**EVP\_PKEY\_CTX\_set\_rsa\_pss\_keygen\_md**(*EVP\_PKEY\_CTX \*pctx*, *const EVP\_MD \*md*);

*int*\

**EVP\_PKEY\_CTX\_set\_rsa\_pss\_keygen\_mgf1\_md**(*EVP\_PKEY\_CTX \*pctx*, *const EVP\_MD \*md*);

*int*\

**EVP\_PKEY\_CTX\_set\_rsa\_pss\_keygen\_saltlen**(*EVP\_PKEY\_CTX \*pctx*, *int saltlen*);

## DESCRIPTION

The function **RSA\_pkey\_ctx\_ctrl**() is a shallow wrapper around EVP\_PKEY\_CTX\_ctrl(3) which only succeeds if *ctx* matches either EVP\_PKEY\_RSA or EVP\_PKEY\_RSA\_PSS.

All the remaining "functions" are implemented as macros.

The **EVP\_PKEY\_CTX\_set\_rsa\_padding**() macro sets the RSA padding mode for *ctx*. The *pad* parameter can take the value RSA\_PKCS1\_PADDING for PKCS#1 padding, RSA\_NO\_PADDING for no padding, RSA\_PKCS1\_OAEP\_PADDING for OAEP padding (encrypt and decrypt only), RSA\_X931\_PADDING for X9.31 padding (signature operations only) and RSA\_PKCS1\_PSS\_PADDING (sign and verify only). Only the last one can be used with keys of the type EVP\_PKEY\_RSA\_PSS.

Two RSA padding modes behave differently if EVP\_PKEY\_CTX\_set\_signature\_md(3) is used. If this macro is called for PKCS#1 padding, the plaintext buffer is an actual digest value and is encapsulated in a *DigestInfo* structure according to PKCS#1 when signing and this structure is expected (and stripped off) when verifying. If this control is not used with RSA and PKCS#1 padding then the supplied data is used directly and not encapsulated. In the case of X9.31 padding for RSA the algorithm identifier byte is added or checked and removed if this control is called. If it is not called then the first byte of the plaintext buffer is expected to be the algorithm identifier byte.

The **EVP\_PKEY\_CTX\_get\_rsa\_padding**() macro retrieves the RSA padding mode for *ctx*.

The **EVP\_PKEY\_CTX\_set\_rsa\_keygen\_bits**() macro sets the RSA key length for RSA or RSA-PSS key generation to *mbits*. The smallest supported value is 512 bits. If not specified, 1024 bits is used.

The **EVP\_PKEY\_CTX\_set\_rsa\_keygen\_pubexp**() macro sets the public exponent value for RSA or RSA-PSS key generation to *pubexp*. Currently, it should be an odd integer. The *pubexp* pointer is used internally by this function, so it should not be modified or freed after the call. If this macro is not called, then 65537 is used.

The **EVP\_PKEY\_CTX\_set\_rsa\_mgf1\_md**() macro sets the MGF1 digest for RSA padding schemes to *md*. Unless explicitly specified, the signing digest is used. The padding mode must have been set to RSA\_PKCS1\_OAEP\_PADDING or RSA\_PKCS1\_PSS\_PADDING. If the key is of the type EVP\_PKEY\_RSA\_PSS and has usage restrictions, an error occurs if an attempt is made to set the digest to anything other than the restricted value.

The **EVP\_PKEY\_CTX\_get\_rsa\_mgf1\_md**() macro retrieves the MGF1 digest for *ctx*. Unless explicitly specified, the signing digest is used. The padding mode must have been set to RSA\_PKCS1\_OAEP\_PADDING or RSA\_PKCS1\_PSS\_PADDING.

### Optimal asymmetric encryption padding

The following macros require that the padding mode was set to RSA\_PKCS1\_OAEP\_PADDING.

The **EVP\_PKEY\_CTX\_set\_rsa\_oaep\_md**() macro sets the message digest type used in RSA OAEP to *md*.

The **EVP\_PKEY\_CTX\_get\_rsa\_oaep\_md**() macro gets the message digest type used in RSA OAEP to \**pmd*.

The **EVP\_PKEY\_CTX\_set0\_rsa\_oaep\_label**() macro sets the RSA OAEP label to *label* and its length to *len*. If *label* is NULL or *len* is 0, the label is cleared. The library takes ownership of the label so the caller should not free the original memory pointed to by *label*.

The **EVP\_PKEY\_CTX\_get0\_rsa\_oaep\_label**() macro gets the RSA OAEP label to \**plabel*. The return value is the label length. The resulting pointer is owned by the library and should not be freed by the caller.

### Probabilistic signature scheme

The following macros require that the padding mode was set to RSA\_PKCS1\_PSS\_PADDING.

The **EVP\_PKEY\_CTX\_set\_rsa\_pss\_saltlen**() macro sets the RSA PSS salt length to *len*. Three special values are supported: RSA\_PSS\_SALTLEN\_DIGEST sets the salt length to the digest length. RSA\_PSS\_SALTLEN\_MAX sets the salt length to the maximum permissible value. When signing, RSA\_PSS\_SALTLEN\_AUTO sets the salt length to the maximum permissible value. When verifying, RSA\_PSS\_SALTLEN\_AUTO causes the salt length to be automatically determined based on the PSS block structure. If this macro is not called, a salt length value of RSA\_PSS\_SALTLEN\_AUTO is used by default.

If the key has usage restrictions and an attempt is made to set the salt length below the minimum value, an error occurs. Also, if the key has usage restrictions, RSA\_PSS\_SALTLEN\_AUTO is not supported for verification.

The **EVP\_PKEY\_CTX\_get\_rsa\_pss\_saltlen**() macro retrieves the RSA PSS salt length for *ctx*.

Optional parameter restrictions can be specified when generating a PSS key. If any restrictions are set using the macros described below, then all parameters are restricted. For example, setting a minimum salt length also restricts the digest and MGF1 algorithms. If any restrictions are in place, then they are reflected in the corresponding parameters of the public key when (for example) a certificate request is signed.

**EVP\_PKEY\_CTX\_set\_rsa\_pss\_keygen\_md**() restricts the digest algorithm the generated key can use to *md*.

**EVP\_PKEY\_CTX\_set\_rsa\_pss\_keygen\_mgf1\_md**() restricts the MGF1 algorithm the generated key can use to *md*.

**EVP\_PKEY\_CTX\_set\_rsa\_pss\_keygen\_saltlen**() restricts the minimum salt length to *saltlen*.

## RETURN VALUES

These functions return a positive value for success or 0 or a negative value for failure. In particular, a return value of -2 indicates the operation is not supported by the public key algorithm.

## SEE ALSO

EVP\_DigestInit(3), EVP\_PKEY\_CTX\_ctrl(3), EVP\_PKEY\_CTX\_new(3), EVP\_PKEY\_decrypt(3), EVP\_PKEY\_derive(3), EVP\_PKEY\_encrypt(3), EVP\_PKEY\_get\_default\_digest\_nid(3), EVP\_PKEY\_keygen(3), EVP\_PKEY\_sign(3), EVP\_PKEY\_verify(3), EVP\_PKEY\_verify\_recover(3)

## HISTORY

The functions **EVP\_PKEY\_CTX\_set\_rsa\_padding**(), **EVP\_PKEY\_CTX\_set\_rsa\_keygen\_bits**(), **EVP\_PKEY\_CTX\_set\_rsa\_keygen\_pubexp**(), and **EVP\_PKEY\_CTX\_set\_rsa\_pss\_saltlen**() first appeared in OpenSSL 1.0.0 and have been available since OpenBSD 4.9.

The functions **EVP\_PKEY\_CTX\_get\_rsa\_padding**(), **EVP\_PKEY\_CTX\_set\_rsa\_mgf1\_md**(), **EVP\_PKEY\_CTX\_get\_rsa\_mgf1\_md**(), and **EVP\_PKEY\_CTX\_get\_rsa\_pss\_saltlen**() first appeared in OpenSSL 1.0.1 and have been available since OpenBSD 5.3.

The functions **EVP\_PKEY\_CTX\_set\_rsa\_oaep\_md**(), **EVP\_PKEY\_CTX\_get\_rsa\_oaep\_md**(), **EVP\_PKEY\_CTX\_set0\_rsa\_oaep\_label**(), and **EVP\_PKEY\_CTX\_get0\_rsa\_oaep\_label**() first appeared in OpenSSL 1.0.2 and have been available since OpenBSD 6.7.

The function **RSA\_pkey\_ctx\_ctrl**() first appeared in OpenSSL 1.1.1 and has been available since OpenBSD 6.7.
