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

# libressl-RSA\_check\_key(3)

validate private RSA keys

## NAME

**RSA\_check\_key** – validate private RSA keys

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

*int*\

**RSA\_check\_key**(*RSA \*rsa*);

## DESCRIPTION

This function validates RSA keys. It checks that *rsa-\>p* and *rsa-\>q* are in fact prime, and that *rsa-\>n* satisfies n = p\*q.

It also checks that *rsa-\>d* and *rsa-\>e* satisfy d\*e = 1 mod ((p-1)\*(q-1)), and that *rsa-\>dmp1*, *rsa-\>dmq1*, and *resa-\>iqmp* are set correctly or are NULL.

This function does not work on RSA public keys that have only the modulus and public exponent elements populated. It performs integrity checks on all the RSA key material, so the *RSA* key structure must contain all the private key data too. Therefore, it cannot be used with any arbitrary *RSA* key object, even if it is otherwise fit for regular RSA operation.

## RETURN VALUES

**RSA\_check\_key**() returns 1 if *rsa* is a valid RSA key, and 0 otherwise. -1 is returned if an error occurs while checking the key.

If the key is invalid or an error occurred, the reason code can be obtained using ERR\_get\_error(3).

## SEE ALSO

BN\_is\_prime\_ex(3), RSA\_get0\_key(3), RSA\_new(3)

## HISTORY

**RSA\_check\_key**() first appeared in OpenSSL 0.9.4 and has been available since OpenBSD 2.6.

## BUGS

A method of verifying the RSA key using opaque RSA API functions might need to be considered. Right now **RSA\_check\_key**() simply uses the *RSA* structure elements directly, bypassing the *RSA\_METHOD* table altogether (and completely violating encapsulation and object-orientation in the process). The best fix will probably be to introduce a **check\_key**() handler to the *RSA\_METHOD* function table so that alternative implementations can also provide their own verifiers.
