1BN_num_bytes(3)                     OpenSSL                    BN_num_bytes(3)
2
3
4

NAME

6       BN_num_bits, BN_num_bytes, BN_num_bits_word - get BIGNUM size
7

SYNOPSIS

9        #include <openssl/bn.h>
10
11        int BN_num_bytes(const BIGNUM *a);
12
13        int BN_num_bits(const BIGNUM *a);
14
15        int BN_num_bits_word(BN_ULONG w);
16

DESCRIPTION

18       BN_num_bytes() returns the size of a BIGNUM in bytes.
19
20       BN_num_bits_word() returns the number of significant bits in a word.
21       If we take 0x00000432 as an example, it returns 11, not 16, not 32.
22       Basically, except for a zero, it returns floor(log2(w))+1.
23
24       BN_num_bits() returns the number of significant bits in a BIGNUM, fol‐
25       lowing the same principle as BN_num_bits_word().
26
27       BN_num_bytes() is a macro.
28

RETURN VALUES

30       The size.
31

NOTES

33       Some have tried using BN_num_bits() on individual numbers in RSA keys,
34       DH keys and DSA keys, and found that they don't always come up with the
35       number of bits they expected (something like 512, 1024, 2048, ...).
36       This is because generating a number with some specific number of bits
37       doesn't always set the highest bits, thereby making the number of sig‐
38       nificant bits a little lower.  If you want to know the "key size" of
39       such a key, either use functions like RSA_size(), DH_size() and
40       DSA_size(), or use BN_num_bytes() and multiply with 8 (although there's
41       no real guarantee that will match the "key size", just a lot more prob‐
42       ability).
43

SEE ALSO

45       bn(3), DH_size(3), DSA_size(3), RSA_size(3)
46

HISTORY

48       BN_num_bytes(), BN_num_bits() and BN_num_bits_word() are available in
49       all versions of SSLeay and OpenSSL.
50
51
52
530.9.8b                            2004-07-01                   BN_num_bytes(3)
Impressum