BN_NEW(3)
π BN_NEW β the one where we birth and yeet BIGNUMs
okay so first things first: this is BN_NEW(3), bestie β section 3, Library Functions Manual, the whole BN_new / BN_clear / BN_free / BN_clear_free girl squad. Buckle up π
β¨ NAME β¨
BN_new, BN_clear, BN_free, BN_clear_free β the four functions that allocate and free BIGNUMs. that's it, that's the job. π
πΈ SYNOPSIS πΈ
like, the library is βlibcryptoβ, and you gotta invite the header in first:
#include <openssl/bn.h>
then the actual cast, in order:
BIGNUM *
BN_new(void);
void
BN_clear(BIGNUM *a);
void
BN_free(BIGNUM *a);
void
BN_clear_free(BIGNUM *a);
no cap, that's the whole synopsis. π¦
π« DESCRIPTION π«
so the BN library does arithmetic on integers of arbitrary size β like, any size, the number can be as big as it wants, no body shaming here π₯. it was written for public key cryptography, such as RSA and Diffie-Hellman. iconic origin story fr fr.
it uses dynamic memory allocation to store its data structures. and what that means is there is no limit on the size of the numbers these functions can manipulate β but β οΈ return values must always be checked in case a memory allocation error has occurred. always. check them. don't be that girl.
the basic object in this library is a BIGNUM. it holds a single large integer. that's its whole personality and it's serving π
BN_new()β allocates and initializes aBIGNUMstructure. in particular it sets the value to zero and the flags toBN_FLG_MALLOCED. and important: the security-relevant flagBN_FLG_CONSTTIMEis not set by default. like ever. you have to go get that yourself, bestie πBN_clear()β the sensitive-data destroyer. used to destroy sensitive data such as keys when they are no longer needed. it erases the memory used byaand sets it to the value0. bye bye secrets, you will not be missed πBN_free()β frees the components of theBIGNUMand, if it was created byBN_new(), also the structure itself. the full cleanout πBN_clear_free()β same vibe, but it additionally overwrites the data before the memory is returned to the system. the extra-paranoid, extra-thorough version. she ate, honestly π
π«Ά oh and: ifais aNULLpointer, no action occurs. nobody crashes, nobody screams, it's fine. very demure.
β RETURN VALUES β
BN_new() returns a pointer to the BIGNUM. and if the allocation fails? it returns NULL and sets an error code that you can grab with ERR_get_error(3). so like, check it. π
π§ SEE ALSO π§
the whole extended universe, mwah:
BN_add(3)BN_add_word(3)BN_bn2bin(3)BN_cmp(3)BN_copy(3)BN_CTX_new(3)BN_CTX_start(3)BN_generate_prime(3)BN_get_rfc3526_prime_8192(3)BN_kronecker(3)BN_mod_inverse(3)BN_mod_mul_montgomery(3)BN_mod_sqrt(3)BN_num_bytes(3)BN_rand(3)BN_security_bits(3)BN_set_bit(3)BN_set_flags(3)BN_set_negative(3)BN_swap(3)BN_zero(3)crypto(3)
iykyk π
π HISTORY π
BN_new(), BN_clear(), BN_free(), and BN_clear_free() first appeared in SSLeay 0.5.1 and have been available since OpenBSD 2.4. like, they've been doing this since before we were born. legends only π
and that's the page!! πβ¨ππ¦πΈπ
cute little sign-off: this one's from the Debian build, dated June 8, 2025, chillin' in the BN_NEW(3) slot of the Library Functions Manual. luv u, go check your return values π«Άβ
π¦ 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) 2000, 2004 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