BN_rand.pod revision 225736
138889Sjdp=pod
238889Sjdp
338889Sjdp=head1 NAME
438889Sjdp
538889SjdpBN_rand, BN_pseudo_rand - generate pseudo-random number
660484Sobrien
760484Sobrien=head1 SYNOPSIS
860484Sobrien
938889Sjdp #include <openssl/bn.h>
1038889Sjdp
1138889Sjdp int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
1238889Sjdp
1338889Sjdp int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);
1438889Sjdp
1538889Sjdp int BN_rand_range(BIGNUM *rnd, BIGNUM *range);
1638889Sjdp
1738889Sjdp int BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range);
1838889Sjdp
1960484Sobrien=head1 DESCRIPTION
2060484Sobrien
2160484SobrienBN_rand() generates a cryptographically strong pseudo-random number of
2238889SjdpB<bits> bits in length and stores it in B<rnd>. If B<top> is -1, the
2338889Sjdpmost significant bit of the random number can be zero. If B<top> is 0,
2438889Sjdpit is set to 1, and if B<top> is 1, the two most significant bits of
2560484Sobrienthe number will be set to 1, so that the product of two such random
2660484Sobriennumbers will always have 2*B<bits> length.  If B<bottom> is true, the
2760484Sobriennumber will be odd.
2860484Sobrien
2960484SobrienBN_pseudo_rand() does the same, but pseudo-random numbers generated by
3060484Sobrienthis function are not necessarily unpredictable. They can be used for
3138889Sjdpnon-cryptographic purposes and for certain purposes in cryptographic
3238889Sjdpprotocols, but usually not for key generation etc.
3338889Sjdp
3438889SjdpBN_rand_range() generates a cryptographically strong pseudo-random
3538889Sjdpnumber B<rnd> in the range 0 <lt>= B<rnd> E<lt> B<range>.
3638889SjdpBN_pseudo_rand_range() does the same, but is based on BN_pseudo_rand(),
3738889Sjdpand hence numbers generated by it are not necessarily unpredictable.
3838889Sjdp
3938889SjdpThe PRNG must be seeded prior to calling BN_rand() or BN_rand_range().
4060484Sobrien
4160484Sobrien=head1 RETURN VALUES
4260484Sobrien
4338889SjdpThe functions return 1 on success, 0 on error.
4438889SjdpThe error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
4538889Sjdp
4660484Sobrien=head1 SEE ALSO
4760484Sobrien
4838889SjdpL<bn(3)|bn(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>,
4960484SobrienL<RAND_add(3)|RAND_add(3)>, L<RAND_bytes(3)|RAND_bytes(3)>
5060484Sobrien
5138889Sjdp=head1 HISTORY
5260484Sobrien
5360484SobrienBN_rand() is available in all versions of SSLeay and OpenSSL.
5438889SjdpBN_pseudo_rand() was added in OpenSSL 0.9.5. The B<top> == -1 case
5560484Sobrienand the function BN_rand_range() were added in OpenSSL 0.9.6a.
5660484SobrienBN_pseudo_rand_range() was added in OpenSSL 0.9.6c.
5738889Sjdp
5860484Sobrien=cut
5960484Sobrien