BN_SWAP(3)
π BN_SWAP(3) β Library Functions Manual π
okay so bestie, welcome to the group chat for BN_swap and BN_consttime_swap β we're exchanging BIGNUMs today and honestly it's giving iconic pointer-and-buffer drama π
β¨ NAME β¨
BN_swap, BN_consttime_swap β exchange BIGNUMs
πΈ SYNOPSIS πΈ
library βlibcryptoβ #include <openssl/bn.h>
void
BN_swap(BIGNUM *a, BIGNUM *b);
void
BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords);
π¦ DESCRIPTION π¦
okay so here's the tea: BN_swap() and BN_consttime_swap() exchange the values of a and b. That's the whole vibe. But they do it in two very different ways, so let's get into it, no cap.
BN_swap()β this one implements the exchange by exchanging the pointers to the data buffers ofaandb, and also exchanging the values of theBN_FLG_STATIC_DATAbits. Consequently, the operation is fast, and execution time does not depend on any properties of the two numbers. However, execution time obviously differs between swapping (by calling this function) and not swapping (by not calling this function). Not me pointing out the obvious, but the man page said it, so I'm saying it too πBN_consttime_swap()β this icon only performs the exchange if theconditionis non-zero; otherwise, it has no effect. It implements the exchange by exchanging the contents of the data buffers rather than the pointers to the data buffers. This is slower, but implemented in such a way that the execution time is not only independent of the properties of the two numbers, but also independent of theconditionargument, i.e. the same for swapping or not swapping. Execution time does however grow in an approximately linear manner with thenwordsargument. Slay for constant-time vibes, lowkey.
π¨ warning bestie:BN_consttime_swap()callsabort(3)if at least one ofaorbhas fewer thannwordsdata words allocated, or more thannwordsdata words are currently in use in at least one of them. So like, check your word counts before you send it, fr fr π
π SEE ALSO π
go bother these icons next, bestie:
π HISTORY π
BN_swap()first appeared in OpenSSL 0.9.7 and has been available since OpenBSD 3.2.BN_consttime_swap()first appeared in OpenSSL 1.0.1g and has been available since OpenBSD 5.6.
okay that's the whole page, mwah π β this cutie is sourced from Debian, dated June 8, 2025, and filed under BN_SWAP(3), periodt π«Ά
π¦ 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) 2021 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2000 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