BN_rand 3 2003-07-24 0.9.9-dev OpenSSL

NAME

BN_rand, BN_pseudo_rand - generate pseudo-random number

LIBRARY

libcrypto, -lcrypto

SYNOPSIS


 #include 


 int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);


 int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);


 int BN_rand_range(BIGNUM *rnd, BIGNUM *range);


 int BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range);

DESCRIPTION

_B_N___r_a_n_d_(_) generates a cryptographically strong pseudo-random number of bbiittss bits in length and stores it in rrnndd. If ttoopp is -1, the most significant bit of the random number can be zero. If ttoopp is 0, it is set to 1, and if ttoopp is 1, the two most significant bits of the number will be set to 1, so that the product of two such random numbers will always have 2*bbiittss length. If bboottttoomm is true, the number will be odd.

_B_N___p_s_e_u_d_o___r_a_n_d_(_) does the same, but pseudo-random numbers generated by this function are not necessarily unpredictable. They can be used for non-cryptographic purposes and for certain purposes in cryptographic protocols, but usually not for key generation etc.

_B_N___r_a_n_d___r_a_n_g_e_(_) generates a cryptographically strong pseudo-random number rrnndd in the range 0 = rrnndd < rraannggee. _B_N___p_s_e_u_d_o___r_a_n_d___r_a_n_g_e_(_) does the same, but is based on _B_N___p_s_e_u_d_o___r_a_n_d_(_), and hence numbers generated by it are not necessarily unpredictable.

The PRNG must be seeded prior to calling _B_N___r_a_n_d_(_) or _B_N___r_a_n_d___r_a_n_g_e_(_).

RETURN VALUES

The functions return 1 on success, 0 on error. The error codes can be obtained by _E_R_R___g_e_t___e_r_r_o_r(3).

SEE ALSO

_o_p_e_n_s_s_l___b_n(3), _E_R_R___g_e_t___e_r_r_o_r(3), _o_p_e_n_s_s_l___r_a_n_d(3), _R_A_N_D___a_d_d(3), _R_A_N_D___b_y_t_e_s(3)

HISTORY

_B_N___r_a_n_d_(_) is available in all versions of SSLeay and OpenSSL. _B_N___p_s_e_u_d_o___r_a_n_d_(_) was added in OpenSSL 0.9.5. The ttoopp == -1 case and the function _B_N___r_a_n_d___r_a_n_g_e_(_) were added in OpenSSL 0.9.6a. _B_N___p_s_e_u_d_o___r_a_n_d___r_a_n_g_e_(_) was added in OpenSSL 0.9.6c.