BN_num_bytes 3 2005-03-25 0.9.9-dev OpenSSL
NAME
BN_num_bits, BN_num_bytes, BN_num_bits_word - get BIGNUM size
LIBRARY
libcrypto, -lcrypto
SYNOPSIS
#include
int BN_num_bytes(const BIGNUM *a);
int BN_num_bits(const BIGNUM *a);
int BN_num_bits_word(BN_ULONG w);
DESCRIPTION
_B_N___n_u_m___b_y_t_e_s_(_) returns the size of a BBIIGGNNUUMM in bytes.
_B_N___n_u_m___b_i_t_s___w_o_r_d_(_) returns the number of significant bits in a word.
If we take 0x00000432 as an example, it returns 11, not 16, not 32.
Basically, except for a zero, it returns _f_l_o_o_r_(_l_o_g_2_(_w_)_)_+_1.
_B_N___n_u_m___b_i_t_s_(_) returns the number of significant bits in a BBIIGGNNUUMM,
following the same principle as _B_N___n_u_m___b_i_t_s___w_o_r_d_(_).
_B_N___n_u_m___b_y_t_e_s_(_) is a macro.
RETURN VALUES
The size.
NOTES
Some have tried using _B_N___n_u_m___b_i_t_s_(_) on individual numbers in RSA keys,
DH keys and DSA keys, and found that they don't always come up with
the number of bits they expected (something like 512, 1024, 2048,
...). This is because generating a number with some specific number
of bits doesn't always set the highest bits, thereby making the number
of _s_i_g_n_i_f_i_c_a_n_t bits a little lower. If you want to know the "key
size" of such a key, either use functions like _R_S_A___s_i_z_e_(_), _D_H___s_i_z_e_(_)
and _D_S_A___s_i_z_e_(_), or use _B_N___n_u_m___b_y_t_e_s_(_) and multiply with 8 (although
there's no real guarantee that will match the "key size", just a lot
more probability).
SEE ALSO
_o_p_e_n_s_s_l___b_n(3), _D_H___s_i_z_e(3), _D_S_A___s_i_z_e(3),
_R_S_A___s_i_z_e(3)
HISTORY
_B_N___n_u_m___b_y_t_e_s_(_), _B_N___n_u_m___b_i_t_s_(_) and _B_N___n_u_m___b_i_t_s___w_o_r_d_(_) are available in
all versions of SSLeay and OpenSSL.