BN_COPY(3)
π BN_COPY(3) β the libcrypto bignum-copying girlies
okay so real talk, bestie β we're in the libcrypto part of the OpenBSD-ish manual pages, section 3, and today's main characters are three little functions that copy BIGNUMs around. yes, that's the whole vibe. let's get into it β¨
πΈ SYNOPSIS πΈ
#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);
link against libcrypto like the good little C gremlin you are π
π DESCRIPTION π
BN_copy β the simple slay
BN_copy() copies from into to. that's it. that's the function. it's giving "no thoughts, head empty, just memcpy energy" and honestly? iconic.
BN_dup β the clone glows up
BN_dup() creates a brand new BIGNUM containing the value from from. new allocation, new bignum, same value. it's giving twin main character energy π
BN_with_flags β the risky one, proceed with caution π
okay bestie, listen. BN_with_flags() creates a temporary shallow copy of b in dest. and when I say "temporary" and "shallow" I need you to hear me, because this function places significant restrictions on the copied data. applications that do not adhere to these restrictions may encounter unexpected side effects or crashes. so like. for that reason alone, the use of this function is discouraged. ngl, it's giving "we don't gatekeep but we also don't recommend" π
any flags you hand it in flags will be set in dest in addition to any flags already set in b. for example β and this is the cute lil use case β you can use it 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. so because of that, these restrictions apply to how you use dest:
destshould be a newly allocatedBIGNUMobtained via a call toBN_new(3). it should not have been used for other purposes or initialised in any way.destmust only be used in "read-only" operations, i.e. typically those functions where the relevant parameter is declared"const".destmust be used and freed before any further subsequent use ofb.
π¨ fr fr do not skip these. this is the "shallow copy shares state" warning and it is not a drill. misuse = crashes, and nobody wants that for you π«Ά
π RETURN VALUES π
BN_copy()returnstoon success, orNULLon error.BN_dup()returns the newBIGNUM, orNULLon error.BN_with_flags()β it'svoid, bestie, it returns nothing. it just does things.
need the actual error codes? grab them with ERR_get_error(3). πβ¨
π¦ SEE ALSO π¦
π HISTORY π
BN_copy() and BN_dup() first appeared in SSLeay 0.5.1, and have been available since OpenBSD 2.4. vintage. antique. still serving.
BN_with_flags() first appeared in OpenSSL 0.9.7h and 0.9.8a, and has been available since OpenBSD 4.0. the risky queen arrived later π
and that's the whole page, bestie β shoutout to Debian, this one's dated June 8, 2025, and it's filed under BN_COPY(3). now go forth and copy your bignums responsibly ππ«Άπ
π¦ 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, 2015 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