BN_ADD_WORD(3)
๐ BN_ADD_WORD(3) โ bestie's guide to BIGNUM math with plain integers โจ
okay so this is BN_ADD_WORD(3), from the Library Functions Manual โ it's giving "tiny manpage, huge flex" because these functions do arithmetic on BIGNUMs with regular unsigned ints and they're so much faster than the normal BIGNUM ops. like, unbelievably faster. you're welcome. ๐
โจ NAME โจ
BN_add_word, BN_sub_word, BN_mul_word, BN_div_word, BN_mod_word โ arithmetic functions on BIGNUMs with integers ๐งฎ๐
๐ธ SYNOPSIS ๐ธ
library โlibcryptoโ
#include <openssl/bn.h>
int
BN_add_word(BIGNUM *a, BN_ULONG w);
int
BN_sub_word(BIGNUM *a, BN_ULONG w);
int
BN_mul_word(BIGNUM *a, BN_ULONG w);
BN_ULONG
BN_div_word(BIGNUM *a, BN_ULONG w);
BN_ULONG
BN_mod_word(const BIGNUM *a, BN_ULONG w);
๐ฆ DESCRIPTION ๐ฆ
These functions do arithmetic operations on BIGNUMs with unsigned integers, and bestie, they are much more efficient than the normal BIGNUM arithmetic operations. like not even close. it's giving "why would you ever do it the slow way" energy. ๐ฅ
BN_ULONG is a macro that expands to unsigned long (= uint64_t) on _LP64 platforms, and to unsigned int (= uint32_t) everywhere else. iykyk ๐
BN_add_word()โ addswtoa(a+=w). simple. iconic. โจBN_sub_word()โ subtractswfroma(a-=w). bye byew๐BN_mul_word()โ multipliesaandw(a*=w). they're in their multiplication era ๐ซถBN_div_word()โ dividesabyw(a/=w) and returns the remainder. yes, it does both. main character behavior ๐BN_mod_word()โ returns the remainder ofadivided byw(a%w). just the leftovers, no division happening to youra๐
โ ๏ธ forBN_div_word()andBN_mod_word(),wmust not be0. literally do not. div by zero is not the vibe and it will not slay. ๐
๐ RETURN VALUES ๐
BN_add_word(), BN_sub_word(), and BN_mul_word() return 1 for success or 0 on error. the error codes can be obtained by ERR_get_error(3) โ go look them up if something's off, bestie, don't just sit there guessing ๐ญ
BN_mod_word() and BN_div_word() return a%w on success, and (BN_ULONG)-1 if an error occurred. yup, that's the error sentinel. remember it. โจ
๐ SEE ALSO ๐
๐ง HISTORY ๐ง
BN_add_word(), BN_div_word(), and BN_mod_word() first appeared in SSLeay 0.5.1. BN_sub_word() and BN_mul_word() first appeared in SSLeay 0.9.0. all these functions have been available since OpenBSD 2.4. ancient. historical. still serving. โญ
๐ lowkey important: before 0.9.8a, the return value forBN_div_word()andBN_mod_word()in case of an error was0. so like, if you're reading really old code, that's a thing that existed. fr fr.
that's the whole page bestie, we ate and left no crumbs ๐
โ this one's from the Debian build, dated June 8, 2025, and it lives at BN_ADD_WORD(3) in the Library Functions Manual. mwah ๐ซถ๐
๐ฆ 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) 2000, 2005 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