table of contents
BN_NUM_BYTES(3) | Library Functions Manual | BN_NUM_BYTES(3) |
NAME¶
BN_num_bits_word
,
BN_num_bits
, BN_num_bytes
— get BIGNUM size
SYNOPSIS¶
#include
<openssl/bn.h>
int
BN_num_bits_word
(BN_ULONG
w);
int
BN_num_bits
(const BIGNUM
*a);
int
BN_num_bytes
(const BIGNUM
*a);
DESCRIPTION¶
BN_num_bits_word
()
returns the number of significant bits in w, that is,
the minimum number of digits needed to write w as a
binary number. Except for an argument of 0, this is
BN_ULONG is a macro that expands to
unsigned long (= uint64_t) on
_LP64
platforms and unsigned
int (= uint32_t) elsewhere.
BN_num_bits
()
returns the number of significant bits in the value of the
BIGNUM *a, following the same principle as
BN_num_bits_word
().
BN_num_bytes
()
is a macro that returns the number of significant bytes in
a, i.e. the minimum number of bytes needed to store
the value of a, that is,
BN_num_bits
(a) divided by
eight and rounded up to the next integer number.
RETURN VALUES¶
BN_num_bits_word
() returns the number of
significant bits in w or 0 if w
is 0. The maximum return value that can occur is
BN_BITS2
, which is 64 on
_LP64
platforms and 32 elsewhere.
BN_num_bits
() returns the number of
significant bits and BN_num_bytes
() the number of
significant bytes in a, or 0 if the value of
a is 0.
SEE ALSO¶
BN_new(3), BN_security_bits(3), DH_size(3), DSA_size(3), RSA_size(3)
HISTORY¶
BN_num_bytes
() and
BN_num_bits
() first appeared in SSLeay 0.5.1.
BN_num_bits_word
() first appeared in SSLeay 0.5.2.
These functions have been available since OpenBSD
2.4.
CAVEATS¶
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, ...). This is 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 smaller. If you want to know the "key size" of such
a key, use functions like RSA_size(3),
DH_size(3), and DSA_size(3).
November 22, 2022 | Linux 6.4.0-150600.23.25-default |