BN_COPY(3SSL)
π BN_COPY(3SSL) β bestie's guide to BIGNUM copy shenanigans π
okay so hi π«Ά you're here because you need to copy a BIGNUM, and honestly? fair. this is the OpenSSL 3SSL page for BN_copy, BN_dup, and BN_with_flags. two of these are chill. one of these is lowkey a menace and I need you to hear me out before you use it. π
πΈ NAME πΈ
BN_copy, BN_dup, BN_with_flags β copy BIGNUMs, girl. that's the whole job. copying. iconic behaviour ngl. β¨
π 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);
look at that signature lineup. two of them give you back a BIGNUM *. the third one gives you nothing back, which, bestie, is your first clue. π©
π¦ DESCRIPTION π¦
the two normal ones π
BN_copy()β copies from into to. that's it. that's the function. it does the thing you think it does.BN_dup()β makes a brand-newBIGNUMholding the value of from. fresh allocation, fresh vibes, no shared trauma. π«Ά
now the gremlin: BN_with_flags π
BN_with_flags creates a temporary shallow copy of b into dest. and like... bestie. it places significant restrictions on the copied data. applications that don't adhere to these restrictions "may encounter unexpected side effects or crashes." CRASHES?? ma'am. π
because of that whole situation, use of this function is discouraged. I'm just the messenger. the manpage said it, not me.
okay but here's what it actually does: any flags you pass in flags get set in dest, on top of any flags b already had. so like, a common use case is making a temp copy of a BIGNUM with the BN_FLG_CONSTTIME flag set, for constant-time operations. cute right? β¨
BUT. π
the temporary copy in dest shares some internal state with b. like they're sharing a brain. a joint custody situation. and because of that, these restrictions apply to how you use dest:
- dest should be a newly allocated
BIGNUMobtained via a call toBN_new(). it should not have been used for other purposes, and it should not have been initialised in any way. brand new. factory sealed. untouched. π§ - dest must only be used in "read-only" operations β i.e. typically those functions where the relevant parameter is declared
"const". look, don't be writing to it. just don't. π - dest must be used and freed before any further subsequent use of b. it's a "you first, then them" situation. no interleaving. periodt.
π RETURN VALUES π
BN_copy()returns to on success, andNULLon error.BN_dup()returns the newBIGNUM, andNULLon error.BN_with_flagsreturns...void. nothing. silence. as established. π
and if you got an error, you can grab the error codes with ERR_get_error(3). π
π SEE ALSO π
ERR_get_error(3)β go here when theNULLhits and you need to know why. π₯
π 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>.
and that's the page, bestie β¨ version 4.0.3, dated 2026-09-29, filed under BN_COPY(3SSL). remember: BN_copy and BN_dup are your friends, BN_with_flags is the friend you only invite over with very clear ground rules. stay safe out there, don't share internal state, and hydrate. πππ¦
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms