RSA_GET0_KEY(3)
π RSA_GET0_KEY(3) β get and set data in an RSA object π
okay so bestie, this is RSA_GET0_KEY(3) straight out of the Library Functions Manual, and itβs literally the group chat for getting and setting data inside an RSA object. No cap, itβs giving crypto internals, but weβre gonna make it make sense. π«Ά
π 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 β¨
bestie, hereβs the signature dump exactly as the page gives it β libcrypto and all:
library βlibcryptoβ #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 is literally the little vault that holds 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. Then 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. And dmp1, dmq1, and iqmp are the exponents and coefficient for Chinese Remainder Theorem (CRT) calculations. π
You can grab n, e, and d 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. Not your keys, not your cleanup, okay? π
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. Periodt. π
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(). Slay, symmetry. β¨
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. So you can pass NULL for the stuff you donβt care about β iconic lazy-girl behavior, but make it code. π
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. Do not skip this, bestie, or youβre gonna have a bad time. π
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. No cap. π¦
Okay, flags time. 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. Very demure, very bitwise. π
π© The following flags are supported π©
RSA_FLAG_CACHE_PRIVATEandRSA_FLAG_CACHE_PUBLICβ Precompute information needed for Montgomery multiplication from the private and public key, respectively, and cache it inrfor 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 withRSA_meth_set_mod_exp(3)is used for private key operations even ifp,q,dmp1,dmq1, andiqmpare allNULL. 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 withRSA_meth_set_bn_mod_exp(3)is used withnanddinstead.RSA_FLAG_NO_BLINDINGβ Turn off blinding during private key encryption and decryption. This flag is set byRSA_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. So bestie, if you see them, theyβre just vibes β no behavior attached. π
π 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)
go read these next, bestie β iykyk. π«Ά
π 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.
Thatβs the whole page, bestie. Source/version/date tea: Debian, June 13, 2025, page RSA_GET0_KEY(3) β slay and stay cryptographic π
β¨
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2019 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2016 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms