BN_ADD_WORD(3ossl)

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

πŸ’… BN_ADD_WORD(3ossl) β€” the OpenSSL manual page, bestie edition ✨

okay so this is a page straight out of the OpenSSL manual, and it's about the lil' shortcuts for doing math on big numbers with plain unsigned integers. group-chat recap below, no cap 🫢


✨ NAME ✨

BN_add_word, BN_sub_word, BN_mul_word, BN_div_word, BN_mod_word β€” these are the arithmetic functions on BIGNUMs with integers. yeah. that's the whole vibe. big-number math but the other operand is just a regular little integer πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

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

like, look at them. five little functions. all iconic. all doing one (1) job πŸ‘‘


πŸ’– DESCRIPTION πŸ’–

So here's the tea: these functions perform arithmetic operations on BIGNUMs with unsigned integers. and the way that they're much more efficient than the normal BIGNUM arithmetic operations?? we love a fast path. literally obsessed. πŸ”₯

  • BN_add_word() β€” adds w to a ("a+=w"). that's it. that's the function. slay. πŸ’–
  • BN_sub_word() β€” subtracts w from a ("a-=w"). bye bye w, you will not be missed πŸ¦‹
  • BN_mul_word() β€” multiplies a and w ("a*=w"). growth era ✨
  • BN_div_word() β€” divides a by w ("a/=w") and returns the remainder. not me giving you two things at once, main character energy fr 😭
  • BN_mod_word() β€” returns the remainder of a divided by w ("a%w"). stays in its lane, gives you the leftovers πŸŽ€
⚠️ okay important bestie: for BN_div_word() and BN_mod_word(), w must not be 0. like. do not. that's a no from me πŸ’€ dividing by zero is not the vibe and it is not covered by these functions.

🌸 RETURN VALUES 🌸

  • BN_add_word(), BN_sub_word() and BN_mul_word() return 1 for success, 0 on error. and if you're sitting there like "hmm what went wrong tho", the error codes can be obtained by ERR_get_error(3) 🧚
  • BN_mod_word() and BN_div_word() return a%w on success and (BN_ULONG)-1 if an error occurred. yes, that's the cast, keep it exactly like that, don't get cute with it πŸ™ˆ

πŸ”₯ SEE ALSO πŸ”₯

iykyk. go read those next, bestie πŸ“šβœ¨


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!! πŸŽ€ this version of the docs is from 3.5.0, dated 2026-09-25, and it says BN_ADD_WORD(3ossl) at the bottom too β€” so if you ever forget where you are, that's your girl. mwah πŸ’œπŸ«Άβœ¨

πŸ“¦ where this page comes from