BN_COPY(3ossl)

πŸ’– BN_COPY πŸ’–

okay bestie, gather round, because today we're talking about the BN_COPY(3ossl) page from OpenSSL β€” yes that OpenSSL, the one your whole internet depends on 🫢 β€” and it's literally all about copying BIGNUMs. iconic behavior tbh.


✨ NAME ✨

BN_copy, BN_dup, BN_with_flags β€” the three besties that copy BIGNUMs around πŸ’…


🌸 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);

no cap, that's the whole vibe right there ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

BN_copy() copies from into to. simple as that, she just moves the value over πŸ’–

BN_dup() is the glow-up version β€” she makes a brand new BIGNUM containing the value from from. fresh allocation, fresh energy, main character moment πŸ‘‘

BN_with_flags() β€” okay so this one, listen. she creates a temporary shallow copy of b in dest. and like… it places significant restrictions on the copied data. applications that don't adhere to these restrictions may encounter unexpected side effects or crashes. so for that reason, use of this function is discouraged. not me warning you fr fr 😭

any flags you pass in flags will be set in dest in addition to any flags already set in b. for example, this might commonly 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. and 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(). 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 πŸ’€
bestie please actually read those three bullets. this is the part where the manpage is being dead serious. shallow copy = shared state = chaos if you ignore the rules πŸ™ˆ

⭐ RETURN VALUES ⭐

  • BN_copy() returns to on success, NULL on error πŸ’–
  • BN_dup() returns the new BIGNUM, and NULL on error ✨

the error codes can be obtained by ERR_get_error(3) πŸ”


🌈 SEE ALSO 🌈

  • ERR_get_error(3) β€” go read it, she's got the deets on those error codes 🫢

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


and that's the whole page, bestie πŸŽ€ this was BN_COPY(3ossl) from OpenSSL 3.5.9, dated 2026-09-29 β€” go forth and copy your BIGNUMs responsibly, and remember: read the restrictions before you BN_with_flags anything, iykyk πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from