BN_COPY(3ossl)
π BN_COPY(3ossl) β bestie's guide to copying BIGNUMs
okay so this is the OpenSSL page for BN_copy, BN_dup, and BN_with_flags, and it lives in section 3ossl of the manual β yes, the 3ossl part is literally the manual name, that's just how OpenSSL rolls. it's all about copying big numbers around, and one of these three functions is genuinely giving "handle with care or perish" energy. π
β¨ SYNOPSIS β¨
like, here's the whole vibe in code form, bestie:
#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);
three little lines, three very different personalities. iykyk. πΈ
π¦ DESCRIPTION π¦
the chill ones first π«Ά
BN_copy() copies from into to. simple. iconic. no drama.
BN_dup() makes a brand-new BIGNUM that holds the value of from. new number, who dis. β¨
and now the main character with baggage π
BN_with_flags makes a temporary shallow copy of b into dest. and listen β shallow copy here is not a cute casual thing, it comes with significant restrictions on the copied data. applications that don't follow these restrictions may hit unexpected side effects or straight-up crashes. so yeah, the manual says use of this function is discouraged. not me warning you twice, the page did it first. π
any flags you pass in flags get set in dest in addition to any flags already set in b. the classic example: making a temporary copy of a BIGNUM with the BN_FLG_CONSTTIME flag set, for constant time operations. π
the catch is that the temporary copy in dest shares some internal state with b. which is exactly why these rules apply to how you use dest:
destshould be a freshly allocatedBIGNUMyou got from a call toBN_new(). it should not have been used for anything else, and it should not have been initialised in any way.destmust only be used in "read-only" operations β like, typically the functions where the relevant parameter is declared"const".destmust be used and freed before any further subsequent use ofb.
fr fr, read those three bullets again before you ship anything. the "shared internal state" thing is the whole reason this function is discouraged, and breaking the rules is a crash speedrun. π«
π RETURN VALUES π
BN_copy()hands you backtoon success, andNULLon error.BN_dup()gives you the shiny newBIGNUM, andNULLon error.- you can grab the error codes via
ERR_get_error(3).
π§ SEE ALSO π§
π COPYRIGHT π
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>.
that's the whole thing, bestie β nothing withheld, all facts intact, no cap. π this slay little page is from OpenSSL 3.5.0, dated 2026-09-25, and it's the BN_COPY(3ossl) manual page saying bye bye. go copy some numbers responsibly, mwah. ππ
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms