1*2175Sjp161948=pod 2*2175Sjp161948 3*2175Sjp161948=head1 NAME 4*2175Sjp161948 5*2175Sjp161948BN_rand, BN_pseudo_rand - generate pseudo-random number 6*2175Sjp161948 7*2175Sjp161948=head1 SYNOPSIS 8*2175Sjp161948 9*2175Sjp161948 #include <openssl/bn.h> 10*2175Sjp161948 11*2175Sjp161948 int BN_rand(BIGNUM *rnd, int bits, int top, int bottom); 12*2175Sjp161948 13*2175Sjp161948 int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom); 14*2175Sjp161948 15*2175Sjp161948 int BN_rand_range(BIGNUM *rnd, BIGNUM *range); 16*2175Sjp161948 17*2175Sjp161948 int BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range); 18*2175Sjp161948 19*2175Sjp161948=head1 DESCRIPTION 20*2175Sjp161948 21*2175Sjp161948BN_rand() generates a cryptographically strong pseudo-random number of 22*2175Sjp161948B<bits> bits in length and stores it in B<rnd>. If B<top> is -1, the 23*2175Sjp161948most significant bit of the random number can be zero. If B<top> is 0, 24*2175Sjp161948it is set to 1, and if B<top> is 1, the two most significant bits of 25*2175Sjp161948the number will be set to 1, so that the product of two such random 26*2175Sjp161948numbers will always have 2*B<bits> length. If B<bottom> is true, the 27*2175Sjp161948number will be odd. 28*2175Sjp161948 29*2175Sjp161948BN_pseudo_rand() does the same, but pseudo-random numbers generated by 30*2175Sjp161948this function are not necessarily unpredictable. They can be used for 31*2175Sjp161948non-cryptographic purposes and for certain purposes in cryptographic 32*2175Sjp161948protocols, but usually not for key generation etc. 33*2175Sjp161948 34*2175Sjp161948BN_rand_range() generates a cryptographically strong pseudo-random 35*2175Sjp161948number B<rnd> in the range 0 <lt>= B<rnd> E<lt> B<range>. 36*2175Sjp161948BN_pseudo_rand_range() does the same, but is based on BN_pseudo_rand(), 37*2175Sjp161948and hence numbers generated by it are not necessarily unpredictable. 38*2175Sjp161948 39*2175Sjp161948The PRNG must be seeded prior to calling BN_rand() or BN_rand_range(). 40*2175Sjp161948 41*2175Sjp161948=head1 RETURN VALUES 42*2175Sjp161948 43*2175Sjp161948The functions return 1 on success, 0 on error. 44*2175Sjp161948The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. 45*2175Sjp161948 46*2175Sjp161948=head1 SEE ALSO 47*2175Sjp161948 48*2175Sjp161948L<bn(3)|bn(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, 49*2175Sjp161948L<RAND_add(3)|RAND_add(3)>, L<RAND_bytes(3)|RAND_bytes(3)> 50*2175Sjp161948 51*2175Sjp161948=head1 HISTORY 52*2175Sjp161948 53*2175Sjp161948BN_rand() is available in all versions of SSLeay and OpenSSL. 54*2175Sjp161948BN_pseudo_rand() was added in OpenSSL 0.9.5. The B<top> == -1 case 55*2175Sjp161948and the function BN_rand_range() were added in OpenSSL 0.9.6a. 56*2175Sjp161948BN_pseudo_rand_range() was added in OpenSSL 0.9.6c. 57*2175Sjp161948 58*2175Sjp161948=cut 59