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

# libressl-RSA\_get0\_key(3)

get and set data in an RSA object

## NAME

**RSA\_get0\_key**, **RSA\_get0\_n**, **RSA\_get0\_e**, **RSA\_get0\_d**, **RSA\_set0\_key**, **RSA\_get0\_factors**, **RSA\_get0\_p**, **RSA\_get0\_q**, **RSA\_set0\_factors**, **RSA\_get0\_crt\_params**, **RSA\_get0\_dmp1**, **RSA\_get0\_dmq1**, **RSA\_get0\_iqmp**, **RSA\_set0\_crt\_params**, **RSA\_clear\_flags**, **RSA\_test\_flags**, **RSA\_set\_flags** – get and set data in an RSA object

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

*void*\

**RSA\_get0\_key**(*const RSA \*r*, *const BIGNUM \*\*n*, *const BIGNUM \*\*e*, *const BIGNUM \*\*d*);

*const* *BIGNUM* *\**\

**RSA\_get0\_n**(*const RSA \*r*);

*const* *BIGNUM* *\**\

**RSA\_get0\_e**(*const RSA \*r*);

*const* *BIGNUM* *\**\

**RSA\_get0\_d**(*const RSA \*r*);

*int*\

**RSA\_set0\_key**(*RSA \*r*, *BIGNUM \*n*, *BIGNUM \*e*, *BIGNUM \*d*);

*void*\

**RSA\_get0\_factors**(*const RSA \*r*, *const BIGNUM \*\*p*, *const BIGNUM \*\*q*);

*const* *BIGNUM* *\**\

**RSA\_get0\_p**(*const RSA \*r*);

*const* *BIGNUM* *\**\

**RSA\_get0\_q**(*const RSA \*r*);

*int*\

**RSA\_set0\_factors**(*RSA \*r*, *BIGNUM \*p*, *BIGNUM \*q*);

*void*\

**RSA\_get0\_crt\_params**(*const RSA \*r*, *const BIGNUM \*\*dmp1*, *const BIGNUM \*\*dmq1*, *const BIGNUM \*\*iqmp*);

*const* *BIGNUM* *\**\

**RSA\_get0\_dmp1**(*const RSA \*r*);

*const* *BIGNUM* *\**\

**RSA\_get0\_dmq1**(*const RSA \*r*);

*const* *BIGNUM* *\**\

**RSA\_get0\_iqmp**(*const RSA \*r*);

*int*\

**RSA\_set0\_crt\_params**(*RSA \*r*, *BIGNUM \*dmp1*, *BIGNUM \*dmq1*, *BIGNUM \*iqmp*);

*void*\

**RSA\_clear\_flags**(*RSA \*r*, *int flags*);

*int*\

**RSA\_test\_flags**(*const RSA \*r*, *int flags*);

*void*\

**RSA\_set\_flags**(*RSA \*r*, *int flags*);

## DESCRIPTION

An *RSA* object contains the components for the public and private key. *n* is the modulus common to both public and private key, *e* is the public exponent and *d* is the private exponent. *p*, *q*, *dmp1*, *dmq1*, and *iqmp* are the factors for the second representation of a private key (see PKCS#1 section 3 Key Types), where *p* and *q* are the first and second factor of *n*. *dmp1*, *dmq1*, and *iqmp* are the exponents and coefficient for Chinese Remainder Theorem (CRT) calculations.

The *n*, *e*, and *d* parameters can be obtained by calling **RSA\_get0\_key**(). If they have not been set yet, then \**n*, \**e*, and \**d* are set to NULL. Otherwise, they are set to pointers to the internal representations of the values that should not be freed by the caller.

The *n*, *e*, and *d* parameter values can be set by calling **RSA\_set0\_key**(). The values *n* and *e* must be non-NULL the first time this function is called on a given *RSA* object. The value *d* may be NULL. On subsequent calls, any of these values may be NULL, which means that the corresponding field is left untouched. Calling this function transfers the memory management of the values to the RSA object. Therefore, the values that have been passed in should not be freed by the caller.

In a similar fashion, the *p* and *q* parameters can be obtained and set with **RSA\_get0\_factors**() and **RSA\_set0\_factors**(), and the *dmp1*, *dmq1*, and *iqmp* parameters can be obtained and set with **RSA\_get0\_crt\_params**() and **RSA\_set0\_crt\_params**().

For **RSA\_get0\_key**(), **RSA\_get0\_factors**(), and **RSA\_get0\_crt\_params**(), NULL value *BIGNUM* *\*\** output arguments are permitted. The functions ignore NULL arguments but return values for other, non-NULL, arguments.

Values retrieved with **RSA\_get0\_key**(), **RSA\_get0\_factors**(), and **RSA\_get0\_crt\_params**() are owned by the *RSA* object used in the call and may therefore *not* be passed to **RSA\_set0\_key**(), **RSA\_set0\_factors**(), or **RSA\_set0\_crt\_params**(). If needed, duplicate the received value using BN\_dup(3) and pass the duplicate.

Any of the values *n*, *e*, *d*, *p*, *q*, *dmp1*, *dmq1*, and *iqmp* can also be retrieved separately by the corresponding functions **RSA\_get0\_n**(), **RSA\_get0\_e**(), **RSA\_get0\_d**(), **RSA\_get0\_p**(), **RSA\_get0\_q**(), **RSA\_get0\_dmp1**(), **RSA\_get0\_dmq1**(), and **RSA\_get0\_iqmp**(), respectively. The pointers are owned by the *RSA* object.

**RSA\_clear\_flags**() clears the specified *flags* in *r*. **RSA\_test\_flags**() tests the *flags* in *r*. **RSA\_set\_flags**() sets the *flags* in *r*; any flags already set remain set. For all three functions, multiple flags can be passed in one call, OR'ed together bitwise.

The following flags are supported:

- RSA\_FLAG\_CACHE\_PRIVATE and RSA\_FLAG\_CACHE\_PUBLIC

  Precompute information needed for Montgomery multiplication from the private and public key, respectively, and cache it in *r* for repeated use. These two flags are set by default for the default RSA implementation, RSA\_PKCS1\_SSLeay(3).

- RSA\_FLAG\_EXT\_PKEY

  The function set with RSA\_meth\_set\_mod\_exp(3) is used for private key operations even if *p*, *q*, *dmp1*, *dmq1*, and *iqmp* are all NULL. This flag may be useful with RSA implementations that do not use the private key components stored in the standard fields, for example because they store the private key in external hardware. If this flag is unset, the function set with RSA\_meth\_set\_bn\_mod\_exp(3) is used with *n* and *d* instead.

- RSA\_FLAG\_NO\_BLINDING

  Turn off blinding during private key encryption and decryption. This flag is set by RSA\_blinding\_off(3).

- RSA\_FLAG\_SIGN\_VER

  This flag has no effect. It is provided only for backward compatibility with legacy applications.

The flags RSA\_FLAG\_BLINDING, RSA\_FLAG\_CHECKED, RSA\_FLAG\_FIPS\_METHOD, RSA\_FLAG\_NON\_FIPS\_ALLOW, and RSA\_FLAG\_THREAD\_SAFE are defined for compatibility with existing code but have no effect.

## RETURN VALUES

**RSA\_get0\_n**(), **RSA\_get0\_e**(), **RSA\_get0\_d**(), **RSA\_get0\_p**(), **RSA\_get0\_q**(), **RSA\_get0\_dmp1**(), **RSA\_get0\_dmq1**(), and **RSA\_get0\_iqmp**() return a pointer owned by the *RSA* object if the corresponding value has been set, otherwise they return NULL.

**RSA\_set0\_key**(), **RSA\_set0\_factors**(), and **RSA\_set0\_crt\_params**() return 1 on success or 0 on failure.

**RSA\_test\_flags**() returns those of the given *flags* currently set in *r* or 0 if none of the given *flags* are set.

## SEE ALSO

RSA\_check\_key(3), RSA\_generate\_key(3), RSA\_new(3), RSA\_print(3), RSA\_size(3)

## HISTORY

**RSA\_get0\_key**(), **RSA\_set0\_key**(), **RSA\_get0\_factors**(), **RSA\_set0\_factors**(), **RSA\_get0\_crt\_params**(), **RSA\_set0\_crt\_params**(), **RSA\_clear\_flags**(), **RSA\_test\_flags**(), and **RSA\_set\_flags**() first appeared in OpenSSL 1.1.0 and have been available since OpenBSD 6.3.

**RSA\_get0\_n**(), **RSA\_get0\_e**(), **RSA\_get0\_d**(), **RSA\_get0\_p**(), **RSA\_get0\_q**(), **RSA\_get0\_dmp1**(), **RSA\_get0\_dmq1**(), and **RSA\_get0\_iqmp**() first appeared in OpenSSL 1.1.1 and have been available since OpenBSD 7.1.
