---
name: "libressl-BN_copy"
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_copy"
---

# libressl-BN\_copy(3)

copy BIGNUMs

## NAME

**BN\_copy**, **BN\_dup**, **BN\_with\_flags** – copy BIGNUMs

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

*BIGNUM* *\**\

**BN\_copy**(*BIGNUM \*to*, *const BIGNUM \*from*);

*BIGNUM* *\**\

**BN\_dup**(*const BIGNUM \*from*);

*void*\

**BN\_with\_flags**(*BIGNUM \*dest*, *const BIGNUM \*b*, *int flags*);

## DESCRIPTION

**BN\_copy**() copies *from* to *to*.

**BN\_dup**() creates a new *BIGNUM* containing the value *from*.

**BN\_with\_flags**() creates a *temporary* shallow copy of *b* in *dest*. It places significant restrictions on the copied data. Applications that do not adhere to these restrictions may encounter unexpected side effects or crashes. For that reason, use of this function is discouraged.

Any flags provided in *flags* will be set in *dest* in addition to any flags already set in *b*. For example, this can be used to create a temporary copy of a *BIGNUM* with the BN\_FLG\_CONSTTIME flag set for constant time operations.

The temporary copy in *dest* will share some internal state with *b*. For this reason, the following restrictions apply to the use of *dest*:

- *dest* should be a newly allocated *BIGNUM* obtained via a call to BN\_new(3). It should not have been used for other purposes or initialised in any way.

- *dest* must only be used in "read-only" operations, i.e. typically those functions where the relevant parameter is declared "const".

- *dest* must be used and freed before any further subsequent use of *b*.

## RETURN VALUES

**BN\_copy**() returns *to* on success or NULL on error. **BN\_dup**() returns the new *BIGNUM* or NULL on error. The error codes can be obtained by ERR\_get\_error(3).

## SEE ALSO

BN\_new(3), BN\_set\_flags(3)

## HISTORY

**BN\_copy**() and **BN\_dup**() first appeared in SSLeay 0.5.1 and have been available since OpenBSD 2.4.

**BN\_with\_flags**() first appeared in OpenSSL 0.9.7h and 0.9.8a and has been available since OpenBSD 4.0.
