RSA_NEW(3SSL)

πŸ’– RSA_new, RSA_free β€” the allocate-and-free glow-up for RSA objects πŸ’–

okay bestie, so this is a page from the OpenSSL manuals β€” the 3SSL section, specifically β€” and today we're talking about RSA_new and RSA_free. two little functions with one big job: making RSA objects exist, and then making them ✨not exist✨. let's get into it 🫢


✨ NAME ✨

RSA_new, RSA_free β€” allocate and free RSA objects 🌸


✨ SYNOPSIS ✨

okay so first, the include, because obviously:

#include <openssl/rsa.h>

now, heads up: the following functions have been deprecated since OpenSSL 3.0, and you can hide them entirely by defining OPENSSL_API_COMPAT with a suitable version value β€” check openssl_user_macros(7) for the deets. πŸ‘‘

RSA *RSA_new(void);

void RSA_free(RSA *rsa);

✨ DESCRIPTION ✨

so. RSA_new() allocates and initializes an RSA structure πŸŽ€ and ngl, it's literally equivalent to calling RSA_new_method(NULL). like, same thing. same vibe. no cap.

then there's RSA_free() β€” this one frees the RSA structure and its components. and here's the part that's giving very responsible: the key is erased before the memory gets handed back to the system. so it's not just yeeted into the void with secrets still in it, bestie, it's properly scrubbed first πŸ§ΌπŸ’…

oh and if rsa is NULL? nothing happens. no drama, no crash, nothing. we love a function that respects the empty case πŸ™ˆ


✨ RETURN VALUES ✨

if the allocation fails, RSA_new() returns NULL and sets an error code that you can grab with ERR_get_error(3). 😭 otherwise, it gives you a pointer to the freshly allocated structure. iconic.

RSA_free() returns no value. it's a void function, it simply does the thing and leaves. main character energy, honestly.


✨ SEE ALSO ✨

these ones, bestie, go read them too:


✨ HISTORY ✨

all the functions described here were deprecated in OpenSSL 3.0 πŸ’€ and if you're looking for the replacement, it's EVP_PKEY-RSA(7). go check that one out, it's the new era 🌈


Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


aaaand that's the whole page, bestie πŸ¦‹ this was OpenSSL 4.0.3, dated 2026-09-29, from the RSA_NEW(3SSL) corner of the manual. slay, go forth, allocate responsibly πŸ’–βœ¨πŸ‘‘

πŸ“¦ where this page comes from