BN_NUM_BYTES(3ossl)
๐ BN_NUM_BYTES ๐
okay bestie so this is the BN_NUM_BYTES(3ossl) page from the OpenSSL manual, and it's literally all about asking your BIGNUM "girl how big are you actually" ๐
three different flavours of that question, to be exact.
โจ 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);
โจ DESCRIPTION โจ
so here's the tea, one function at a time ๐ซ
BN_num_bytes()โ hands you the size of aBIGNUMin bytes. that's it, that's the whole job, and she does it flawlessly. ๐BN_num_bits_word()โ returns the number of significant bits in a word. ok let's do the classic example: take0x00000432. she says 11. not 16. not 32. eleven. โจ basically โ except for a zero โ she returnsfloor(log2(w))+1. math queen behavior, no cap. ๐งฎ๐BN_num_bits()โ same energy asBN_num_bits_word()but for a wholeBIGNUM: she gives you the number of significant bits, following that exact same principle. ๐ธ
oh and important lil detail: BN_num_bytes() is a macro. not a real function, a macro. just so you know what you're dealing with, bestie ๐ฆ
โจ RETURN VALUES โจ
The size. that's it. that's the answer. iconic, unbothered, brief. ๐
โจ NOTES โจ
ok so listen, this is the part where people get confused and honestly I get it ๐ญ
some people have tried calling BN_num_bits() on individual numbers inside RSA keys, DH keys, and DSA keys, and found that it doesn't always give back the number of bits they expected โ like, they were expecting something like 512, 1024, 2048, ... and got something else. ๐
and the reason is: 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. the vibe check fails, basically. ๐
so if you actually want to know the "key size" of a key like that, don't do the naive thing! instead either use functions likeRSA_size(),DH_size()andDSA_size(), or useBN_num_bytes()and multiply with8. and ngl, even then there's no real guarantee that it'll match the "key size" โ it's just a lot more probability. so like. set your expectations accordingly, bestie. ๐ซถ
โจ SEE ALSO โจ
DH_size(3), DSA_size(3), RSA_size(3) โ go read these, they're the moment ๐ฅ
โจ 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, bestie!! ๐ this was OpenSSL 3.5.9, dated 2026-09-29 โ so if you're reading this in the future, hiii, hope your BIGNUMs are all behaving ๐โจ๐ฆ mwah, go count some bits, ily ๐ซถ๐
๐ฆ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 ยท Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 ยท Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 ยท Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 ยท Apache-2.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms