BN_NUM_BYTES(3SSL)

πŸ’– BN_NUM_BYTES πŸ’–

okay bestie so this is the OpenSSL page for BN_num_bits, BN_num_bytes, and BN_num_bits_word β€” the little trio that tells you how big your BIGNUM actually is. it lives in the 3SSL manual, and it's giving "measuring tape but for giant numbers" πŸ’…


✨ NAME ✨

BN_num_bits, BN_num_bytes, BN_num_bits_word β€” get BIGNUM size πŸŽ€


✨ SYNOPSIS ✨

#include <openssl/bn.h>

int BN_num_bytes(const BIGNUM *a);

int BN_num_bits(const BIGNUM *a);

int BN_num_bits_word(BN_ULONG w);

literally just three little function calls, no cap 🫢


✨ DESCRIPTION ✨

okay so real quick, here's the vibe of each one:

  • BN_num_bytes() β€” gives u the size of a BIGNUM, in bytes. simple. clean. iconic. ✨
  • BN_num_bits_word() β€” gives u the number of significant bits in a word. example time bestie: if we take 0x00000432, it returns 11 β€” not 16, not 32. literally eleven. basically, except for a zero, it returns floor(log2(w))+1. 🧠
  • BN_num_bits() β€” gives u the number of significant bits in a BIGNUM, following the exact same principle as BN_num_bits_word(). same energy, bigger number. πŸ’…

and one tiny detail that matters: BN_num_bytes() is a macro. not a real function. she's built different (literally). πŸ™ˆ


✨ RETURN VALUES ✨

the size. that's it. that's the answer. πŸ“


🚨 NOTES 🚨

ok so this is the part where people get humbled, and I need u to be seated for it.

some ppl have tried using BN_num_bits() on individual numbers in RSA keys, DH keys and DSA keys, and found that it doesn't always come up with the number of bits they expected (like 512, 1024, 2048, ...). and they're like "???" 😭

here's why: generating a number with some specific number of bits doesn't always set the highest bits, which makes the number of significant bits come out a little lower. that's just how she is. not a bug, it's a personality trait. πŸ’€

so if u wanna know the "key size" of a key like that, u have two options:

  1. use functions like RSA_size(), DH_size() and DSA_size() β€” the correct, cunty, purpose-built way πŸ‘‘
  2. use BN_num_bytes() and multiply with 8
⚠️ but bestie, listen: there's no real guarantee that option 2 will match the "key size". it's just a lot more probability. so like. yk. proceed accordingly. 🫠

πŸ‘€ SEE ALSO πŸ‘€


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, no notes πŸ’– this was OpenSSL version 4.0.3, dated 2026-09-29, and it goes by BN_NUM_BYTES(3SSL) β€” slay, bye bestie, go measure some big numbers πŸŒΈπŸ¦‹βœ¨

πŸ“¦ where this page comes from