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 aBIGNUM, in bytes. simple. clean. iconic. β¨BN_num_bits_word()β gives u the number of significant bits in a word. example time bestie: if we take0x00000432, it returns11β not16, not32. literally eleven. basically, except for a zero, it returnsfloor(log2(w))+1. π§BN_num_bits()β gives u the number of significant bits in aBIGNUM, following the exact same principle asBN_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:
- use functions like
RSA_size(),DH_size()andDSA_size()β the correct, cunty, purpose-built way π - use
BN_num_bytes()and multiply with8
β οΈ 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 π
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
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms