RSA_NEW(3)
πΈ RSA_NEW(3) β Library Functions Manual πΈ
okay bestie, welcome to the RSA allocation page π
this one's a whole family of functions: RSA_new, RSAPrivateKey_dup, RSAPublicKey_dup, RSA_up_ref, and RSA_free. They're all about making RSA objects and yeeting them into the void when you're done. Iconic behavior honestly.
β¨ NAME β¨
RSA_new, RSAPrivateKey_dup, RSAPublicKey_dup, RSA_up_ref, RSA_free β allocate and free RSA objects π
β¨ SYNOPSIS β¨
library βlibcryptoβ #include <openssl/rsa.h>
RSA *
RSA_new(void);
RSA *
RSAPrivateKey_dup(RSA *rsa);
RSA *
RSAPublicKey_dup(RSA *rsa);
int
RSA_up_ref(RSA *rsa);
void
RSA_free(RSA *rsa);
β¨ DESCRIPTION β¨
so the RSA functions implement RSA public key encryption and signatures, as defined in PKCS #1 v2.0 (RFC 2437). that's the whole vibe π₯
RSA_new() allocates and initializes an RSA structure, and sets the reference count to 1. it's literally equivalent to calling RSA_new_method(3) with a NULL argument. same energy, no cap.
RSAPrivateKey_dup() calls RSA_new() and copies the public and private key components from rsa into the shiny new structure π«Ά RSAPublicKey_dup() does the exact same thing except it copies the public key components only. keeping it modest, we respect it.
RSA_up_ref() increments the reference count by 1. that's it. that's the whole job. β¨
RSA_free() decrements the reference count by 1. if it hits 0, it calls the optional finish function set up with RSA_meth_set_finish(3), and then frees the RSA structure and its components. the key is erased before the memory is returned to the system (yes, erased erased, we don't leave secrets lying around π§Ή). and if rsa is a NULL pointer, literally nothing happens. no action. zero. nada. you're fine bestie.
The RSA structure consists of several BIGNUM components. It can hold public as well as private RSA keys:
typedef struct {
BIGNUM *n; // public modulus
BIGNUM *e; // public exponent
BIGNUM *d; // private exponent
BIGNUM *p; // secret prime factor
BIGNUM *q; // secret prime factor
BIGNUM *dmp1; // d mod (p-1)
BIGNUM *dmq1; // d mod (q-1)
BIGNUM *iqmp; // q^-1 mod p
// ...
} RSA;
In public keys, the private exponent d and the related secret values p, q, dmp1, dmp2, and iqmp are NULL. they're just not invited to the public key party π
p, q, dmp1, dmq1, and iqmp may be NULL in private keys β but the RSA operations are much faster when these values are available. so like, technically optional, but your performance said "please don't" π
β οΈ note that RSA keys may use non-standardRSA_METHODimplementations. in some cases, theseBIGNUMvalues will not be used by the implementation, or may be used for alternative data storage. for this reason, applications should generally avoid using RSA structure elements directly, and instead use API functions to query or modify keys. like, i'm begging you β use the API. don't reach into the struct. π
β¨ RETURN VALUES β¨
RSA_new(),RSAPrivateKey_dup(), andRSAPublicKey_dup()return a pointer to the newly allocated structure, orNULLif an error occurs. you can grab an error code withERR_get_error(3).RSA_up_ref()returns1for success or0for failure.
β¨ SEE ALSO β¨
BN_new(3), crypto(3), d2i_RSAPublicKey(3), DH_new(3), DSA_new(3), EVP_PKEY_set1_RSA(3), RSA_blinding_on(3), RSA_check_key(3), RSA_generate_key(3), RSA_get0_key(3), RSA_get_ex_new_index(3), RSA_meth_new(3), RSA_padding_add_PKCS1_type_1(3), RSA_pkey_ctx_ctrl(3), RSA_print(3), RSA_private_encrypt(3), RSA_PSS_PARAMS_new(3), RSA_public_encrypt(3), RSA_security_bits(3), RSA_set_method(3), RSA_sign(3), RSA_sign_ASN1_OCTET_STRING(3), RSA_size(3) β the whole friend group, go say hi π¦
β¨ STANDARDS β¨
SSL, PKCS #1 v2.0
fun fact: RSA was covered by a US patent which expired in September 2000. we love a expired patent moment π
β¨ HISTORY β¨
RSA_new() and RSA_free() appeared in SSLeay 0.4 or earlier. RSAPrivateKey_dup() first appeared in SSLeay 0.5.1, and RSAPublicKey_dup() in SSLeay 0.5.2. these functions have been available since OpenBSD 2.4. ancient. legendary. main character energy since forever β
RSA_up_ref() first appeared in OpenSSL 0.9.7 and has been available since OpenBSD 3.2. a slightly younger icon, still iconic π
π ok that's the whole page bestie, now go RSA_free() your keys responsibly and don't leak memory, i'm watching π«Άβ¨
Debian Β· June 8, 2025 Β· RSA_NEW(3) β mwah, that's the tea ππ
π¦ 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) 2018, 2019 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2000, 2002, 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