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