1.Dd $Mdocdate: February 23 2015 $ 2.Dt BN_NUM_BYTES 3 3.Os 4.Sh NAME 5.Nm BN_num_bits , 6.Nm BN_num_bytes , 7.Nm BN_num_bits_word 8.Nd get BIGNUM size 9.Sh SYNOPSIS 10.In openssl/bn.h 11.Ft int 12.Fo BN_num_bytes 13.Fa "const BIGNUM *a" 14.Fc 15.Ft int 16.Fo BN_num_bits 17.Fa "const BIGNUM *a" 18.Fc 19.Ft int 20.Fo BN_num_bits_word 21.Fa "BN_ULONG w" 22.Fc 23.Sh DESCRIPTION 24.Fn BN_num_bytes 25returns the size of a 26.Sy BIGNUM 27in bytes. 28.Pp 29.Fn BN_num_bits_word 30returns the number of significant bits in a word. 31If we take 0x00000432 as an example, it returns 11, not 16, not 32. 32Basically, except for a zero, it returns 33.Pp 34.D1 floor(log2( Ns Fa w ) ) No + 1 . 35.Pp 36.Fn BN_num_bits 37returns the number of significant bits in a 38.Sy BIGNUM , 39following the same principle as 40.Fn BN_num_bits_word . 41.Pp 42.Fn BN_num_bytes 43is a macro. 44.Sh RETURN VALUES 45The size. 46.Sh NOTES 47Some have tried using 48.Fn BN_num_bits 49on individual numbers in RSA keys, DH keys and DSA keys, and found that 50they don't always come up with the number of bits they expected 51(something like 512, 1024, 2048, ...). This is because generating a 52number with some specific number of bits doesn't always set the highest 53bits, thereby making the number of 54.Em significant 55bits a little lower. 56If you want to know the "key size" of such a key, either use functions 57like 58.Xr RSA_size 3 , 59.Xr DH_size 3 , 60and 61.Xr DSA_size 3 , 62or use 63.Fn BN_num_bytes 64and multiply with 8 (although there's no real guarantee that will match 65the "key size", just a lot more probability). 66.Sh SEE ALSO 67.Xr bn 3 , 68.Xr DH_size 3 , 69.Xr DSA_size 3 , 70.Xr RSA_size 3 71.Sh HISTORY 72.Fn BN_num_bytes , 73.Fn BN_num_bits , 74and 75.Fn BN_num_bits_word 76are available in all versions of SSLeay and OpenSSL. 77