BN_ZERO(3SSL)

πŸ’– BN_ZERO β€” bestie, it's assignment ops for BIGNUMs πŸ’–

Okay so real quick: this is a page from the OpenSSL manual, section 3SSL, all about the little assignment glow-ups you can do to a BIGNUM. It's called BN_ZERO but it's really the whole squad: BN_zero, BN_one, BN_value_one, BN_set_word, BN_get_word. No cap, it's a group chat situation.


✨ NAME ✨

BN_zero, BN_one, BN_value_one, BN_set_word, BN_get_word β€” BIGNUM assignment operations πŸŽ€


✨ SYNOPSIS ✨

#include <openssl/bn.h>

void BN_zero(BIGNUM *a);
int BN_one(BIGNUM *a);

const BIGNUM *BN_value_one(void);

int BN_set_word(BIGNUM *a, BN_ULONG w);
unsigned BN_ULONG BN_get_word(BIGNUM *a);

✨ DESCRIPTION ✨

First things first bestie, let's talk about BN_ULONG πŸ’… It's a macro, and it expands to an unsigned integral type. Which type? The one that's optimized to be the most efficient implementation on your local platform. It's giving main character energy, tailored to wherever it lives. 🌍

  • BN_zero(), BN_one() and BN_set_word() set a to the values 0, 1 and w respectively. And okay fun fact: BN_zero() and BN_one() are macros. Not functions. Macros. ✨
  • BN_value_one() returns a BIGNUM constant that has the value 1. This constant is lowkey so useful β€” you'd use it in comparisons and in assignment. It's the little 1 that could. 🫢
  • BN_get_word() hands you back a, but only if it can actually be represented as a BN_ULONG. Otherwise... keep reading, babes. 😭

✨ RETURN VALUES ✨

  • BN_get_word() returns the value a, OR β€” and this is the important part β€” all-bits-set if a can't be represented as a single integer. 🚨
  • BN_one() and BN_set_word() return 1 on success, 0 otherwise.
  • BN_value_one() returns the constant. Obviously. It's literally her whole job. πŸ‘‘
  • BN_zero() never fails and returns no value. She simply cannot flop. Periodt. πŸ’…

✨ BUGS ✨

Okay so here's the tea, and it's a little cursed 😭

If a BIGNUM is equal to the value of all-bits-set, it will collide with the error condition returned by BN_get_word() β€” because BN_get_word() uses that exact same all-bits-set value as its error value. So like... is it a real number or is it an error? The function does not know and honestly neither do we. πŸ’€ Watch out for that one, bestie.

Also: BN_ULONG should probably be a typedef. That's it, that's the note. πŸ™ˆ


✨ SEE ALSO ✨


✨ HISTORY ✨

Back in OpenSSL 0.9.8, BN_zero() got changed to not return a value. Before that, older versions returned an int. Character development, honestly. 🌈✨


Copyright 2000-2018 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. 🫢


okay that's the whole page, you ate that, no crumbs left πŸ“

signed off with love β€” version 4.0.3, dated 2026-09-29 πŸ’…βœ¨

πŸ“¦ where this page comes from