RSA_CHECK_KEY(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸ’… NAME πŸ’…

okay bestie, welcome to the libcrypto Library Functions Manual page for RSA_check_key(3). Its whole entire job? validate private RSA keys. that's it, that's the vibe ✨


πŸŽ€ SYNOPSIS πŸŽ€

library β€œlibcrypto” #include <openssl/rsa.h>

int
RSA_check_key(RSA *rsa);

πŸ¦‹ DESCRIPTION πŸ¦‹

so RSA_check_key() is literally the vibe check for an RSA key β€” it validates RSA keys, no cap πŸ’–

here's what it's actually checking, bestie:

  • 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 it checks that rsa->dmp1, rsa->dmq1, and resa->iqmp are set correctly or are NULL. yes, that's literally resa->iqmp in the original β€” keeping it exact, bestie πŸ’…
huge caveat incoming 🚨: 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 🌈

πŸ‘‘ HISTORY πŸ‘‘

RSA_check_key() first appeared in OpenSSL 0.9.4 and has been available since OpenBSD 2.6. iconic behavior, honestly ⭐

πŸ’€ BUGS πŸ’€

okay so there's some design discourse here, and ngl it's giving "we know, we know":

  • 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). not me calling out the whole architecture πŸ’€
  • 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. slay, future-proofing, we love to see it 🌟

xoxo, this page is from the Debian source, dated June 8, 2025, and it's RSA_CHECK_KEY(3) β€” mwah πŸ’‹

πŸ“¦ where this page comes from