BN_NUM_BYTES(3ossl)
π BN_NUM_BYTES β get BIGNUM size β¨
okay bestie, welcome to BN_NUM_BYTES(3ossl) β the OpenSSL page that answers the eternal question: "how big is this number actually, like really?" π
β¨ 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 vibe check on each one, bestie π
BN_num_bytes()β tells you the size of aBIGNUMin bytes. That's it, that's the whole gig πBN_num_bits_word()β returns the number of significant bits in a word. Not me about to blow your mind: take0x00000432as an example β it returns11, not16, and not32π Basically, except for a zero, it returnsfloor(log2(w))+1. Periodt.BN_num_bits()β returns the number of significant bits in aBIGNUM, following the exact same principle asBN_num_bits_word()π
oh and β plot twist β BN_num_bytes() is a macro π lowkey important, keep that in your pocket.
β RETURN VALUES β
The size. that's the answer. iconic brevity, no notes π«Ά
π₯ NOTES π₯
okay so this is the part where people get humbled, listen up π
Some have tried using BN_num_bits() on individual numbers in RSA keys, DH keys and DSA keys, and found that they don't always come up with the number of bits they expected (something like 512, 1024, 2048, ...). π³ And no, it's not haunted β it's because generating a number with some specific number of bits doesn't always set the highest bits, thereby making the number of significant bits a little lower. the math said "close enough" basically π§
so if you want to know the "key size" of such a key, either use functions likeRSA_size(),DH_size()andDSA_size(), or useBN_num_bytes()and multiply with8β although there's no real guarantee that will match the "key size", just a lot more probability π
fr fr, don't @ me when your bit count comes back one short. it's giving expected behaviour π
π¦ SEE ALSO π¦
go read those next, bestie, they're the main characters of this friend group π
π 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 masterpiece is from version 3.5.0, dated 2026-09-25 β go forth and count your bits responsibly, ily, mwah πβ¨π
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms