xref: /freebsd/crypto/openssl/doc/man3/BN_num_bytes.pod (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5e71b7053SJung-uk KimBN_num_bits, BN_num_bytes, BN_num_bits_word - get BIGNUM size
6e71b7053SJung-uk Kim
7e71b7053SJung-uk Kim=head1 SYNOPSIS
8e71b7053SJung-uk Kim
9e71b7053SJung-uk Kim #include <openssl/bn.h>
10e71b7053SJung-uk Kim
11e71b7053SJung-uk Kim int BN_num_bytes(const BIGNUM *a);
12e71b7053SJung-uk Kim
13e71b7053SJung-uk Kim int BN_num_bits(const BIGNUM *a);
14e71b7053SJung-uk Kim
15e71b7053SJung-uk Kim int BN_num_bits_word(BN_ULONG w);
16e71b7053SJung-uk Kim
17e71b7053SJung-uk Kim=head1 DESCRIPTION
18e71b7053SJung-uk Kim
19e71b7053SJung-uk KimBN_num_bytes() returns the size of a B<BIGNUM> in bytes.
20e71b7053SJung-uk Kim
21e71b7053SJung-uk KimBN_num_bits_word() returns the number of significant bits in a word.
22e71b7053SJung-uk KimIf we take 0x00000432 as an example, it returns 11, not 16, not 32.
23e71b7053SJung-uk KimBasically, except for a zero, it returns I<floor(log2(w))+1>.
24e71b7053SJung-uk Kim
25e71b7053SJung-uk KimBN_num_bits() returns the number of significant bits in a B<BIGNUM>,
26e71b7053SJung-uk Kimfollowing the same principle as BN_num_bits_word().
27e71b7053SJung-uk Kim
28e71b7053SJung-uk KimBN_num_bytes() is a macro.
29e71b7053SJung-uk Kim
30e71b7053SJung-uk Kim=head1 RETURN VALUES
31e71b7053SJung-uk Kim
32e71b7053SJung-uk KimThe size.
33e71b7053SJung-uk Kim
34e71b7053SJung-uk Kim=head1 NOTES
35e71b7053SJung-uk Kim
36e71b7053SJung-uk KimSome have tried using BN_num_bits() on individual numbers in RSA keys,
37e71b7053SJung-uk KimDH keys and DSA keys, and found that they don't always come up with
38e71b7053SJung-uk Kimthe number of bits they expected (something like 512, 1024, 2048,
39e71b7053SJung-uk Kim...).  This is because generating a number with some specific number
40e71b7053SJung-uk Kimof bits doesn't always set the highest bits, thereby making the number
41e71b7053SJung-uk Kimof I<significant> bits a little lower.  If you want to know the "key
42e71b7053SJung-uk Kimsize" of such a key, either use functions like RSA_size(), DH_size()
43e71b7053SJung-uk Kimand DSA_size(), or use BN_num_bytes() and multiply with 8 (although
44e71b7053SJung-uk Kimthere's no real guarantee that will match the "key size", just a lot
45e71b7053SJung-uk Kimmore probability).
46e71b7053SJung-uk Kim
47e71b7053SJung-uk Kim=head1 SEE ALSO
48e71b7053SJung-uk Kim
49e71b7053SJung-uk KimL<DH_size(3)>, L<DSA_size(3)>,
50e71b7053SJung-uk KimL<RSA_size(3)>
51e71b7053SJung-uk Kim
52e71b7053SJung-uk Kim=head1 COPYRIGHT
53e71b7053SJung-uk Kim
54e71b7053SJung-uk KimCopyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved.
55e71b7053SJung-uk Kim
56*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
57e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
58e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
59e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
60e71b7053SJung-uk Kim
61e71b7053SJung-uk Kim=cut
62