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,
25       following 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
38       significant 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
42       probability).
43

SEE ALSO

45       DH_size(3), DSA_size(3), RSA_size(3)
46
48       Copyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved.
49
50       Licensed under the OpenSSL license (the "License").  You may not use
51       this file except in compliance with the License.  You can obtain a copy
52       in the file LICENSE in the source distribution or at
53       <https://www.openssl.org/source/license.html>.
54
55
56
571.1.1q                            2022-07-21                   BN_NUM_BYTES(3)
Impressum