BN_COPY(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’… 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:

  • dest should be a freshly allocated BIGNUM you got from a call to BN_new(). it should not have been used for anything else, and it should not have been initialised in any way.
  • dest must only be used in "read-only" operations β€” like, typically the functions where the relevant parameter is declared "const".
  • dest must be used and freed before any further subsequent use of b.
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 back to on success, and NULL on error.
  • BN_dup() gives you the shiny new BIGNUM, and NULL on error.
  • you can grab the error codes via ERR_get_error(3).

🧚 SEE ALSO 🧚


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