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