BN_NEW(3SSL)

πŸ’– BN_NEW(3SSL) β€” the BIGNUM babysitting page πŸ’–

okay bestie, gather round, because this is BN_NEW(3SSL) from the OpenSSL manuals and it's literally all about making and unmaking BIGNUMs. Think of it as: how to birth a big number, and how to send it off respectfully (and sometimes, securely, into the void 🌈).


✨ NAME ✨

BN_new, BN_secure_new, BN_clear, BN_free, BN_clear_free β€” allocate and free BIGNUMs 🫢

The whole friend group:

  • BN_new β€” the standard issue allocator, main character energy
  • BN_secure_new β€” same but it lives in the secure heap, VIP section πŸ’…
  • BN_clear β€” wipes a number's memory and zeroes it, so nobody can snoop
  • BN_free β€” lets the pieces go
  • BN_clear_free β€” lets the pieces go and scribbles over the data first, chaotic good

🌸 SYNOPSIS 🌸

#include <openssl/bn.h>

BIGNUM *BN_new(void);

BIGNUM *BN_secure_new(void);

void BN_clear(BIGNUM *a);

void BN_free(BIGNUM *a);

void BN_clear_free(BIGNUM *a);

πŸ¦‹ DESCRIPTION πŸ¦‹

BN_new() allocates and initializes a BIGNUM structure. That's it, that's the job. ✨

BN_secure_new() does the same exact thing, except the value gets stored using the secure heap, aka OPENSSL_secure_malloc(3). So if you've got secrets, this is the one you want πŸ”.

BN_clear() is your "oops, gotta destroy the evidence" bestie. Use it to destroy sensitive data β€” keys, the whole vibe β€” once you don't need them anymore. It erases the memory used by a and sets it to the value 0. And if a is NULL? Nothing happens. Nothing. We simply don't. πŸ™ˆ

BN_free() frees the components of the BIGNUM, and if it was created by BN_new(), it frees the structure itself too. πŸŽ€

BN_clear_free() is BN_free() but extra: it additionally overwrites the data before the memory is handed back to the system. If a is NULL, nothing is done here either. πŸ’€


⭐ RETURN VALUES ⭐

BN_new() and BN_secure_new() return a pointer to the BIGNUM initialised to the value 0. Slay. But if the allocation fails, they return NULL and set an error code that you can grab with ERR_get_error(3). 😭

BN_clear(), BN_free() and BN_clear_free() have no return values. They just do the thing. periodt.


πŸ”₯ SEE ALSO πŸ”₯


πŸ‘‘ HISTORY πŸ‘‘

BN_init() was removed in OpenSSL 1.1.0; use BN_new() instead. She's gone, babe, we don't talk about her πŸ’…


Copyright 2000-2017 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>.


ngl if you're out here freeing BIGNUMs without clearing the sensitive ones first, the vibe check is failing 🚨

okay that's the whole page, bestie, you ate it up πŸ“ this was BN_NEW(3SSL) from the OpenSSL 4.0.3 manual, dated 2026-09-29. mwah, go allocate responsibly πŸ§šπŸ’–

πŸ“¦ where this page comes from