---
name: "libressl-BN_new"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-BN_new"
---

# libressl-BN\_new(3)

allocate and free BIGNUMs

## NAME

**BN\_new**, **BN\_clear**, **BN\_free**, **BN\_clear\_free** – allocate and free BIGNUMs

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/bn.h\>**

*BIGNUM* *\**\

**BN\_new**(*void*);

*void*\

**BN\_clear**(*BIGNUM \*a*);

*void*\

**BN\_free**(*BIGNUM \*a*);

*void*\

**BN\_clear\_free**(*BIGNUM \*a*);

## DESCRIPTION

The BN library performs arithmetic operations on integers of arbitrary size. It was written for use in public key cryptography, such as RSA and Diffie-Hellman.

It uses dynamic memory allocation for storing its data structures. That means that there is no limit on the size of the numbers manipulated by these functions, but return values must always be checked in case a memory allocation error has occurred.

The basic object in this library is a *BIGNUM*. It is used to hold a single large integer.

**BN\_new**() allocates and initializes a *BIGNUM* structure, in particular setting the value to zero and the flags to BN\_FLG\_MALLOCED. The security-relevant flag BN\_FLG\_CONSTTIME is not set by default.

**BN\_clear**() is used to destroy sensitive data such as keys when they are no longer needed. It erases the memory used by *a* and sets it to the value 0.

**BN\_free**() frees the components of the *BIGNUM* and, if it was created by **BN\_new**(), also the structure itself. **BN\_clear\_free**() additionally overwrites the data before the memory is returned to the system. If *a* is a NULL pointer, no action occurs.

## RETURN VALUES

**BN\_new**() returns a pointer to the *BIGNUM*. If the allocation fails, it returns NULL and sets an error code that can be obtained by ERR\_get\_error(3).

## SEE ALSO

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)](/crypto/3.md)

## 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.
