BN_rand.pod revision 89837
1295367Sdes=pod
292559Sdes
357429Smarkm=head1 NAME
457429Smarkm
557429SmarkmBN_rand, BN_pseudo_rand - generate pseudo-random number
657429Smarkm
757429Smarkm=head1 SYNOPSIS
860576Skris
965674Skris #include <openssl/bn.h>
1065674Skris
1165674Skris int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
1265674Skris
1365674Skris int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);
1457429Smarkm
1557429Smarkm int BN_rand_range(BIGNUM *rnd, BIGNUM *range);
1657429Smarkm
1757429Smarkm int BN_pseudo_rand_range(BIGNUM *rnd, int bits, int top, int bottom);
1857429Smarkm
1957429Smarkm=head1 DESCRIPTION
2057429Smarkm
2157429SmarkmBN_rand() generates a cryptographically strong pseudo-random number of
2257429SmarkmB<bits> bits in length and stores it in B<rnd>. If B<top> is -1, the
2357429Smarkmmost significant bit of the random number can be zero. If B<top> is 0,
2457429Smarkmit is set to 1, and if B<top> is 1, the two most significant bits of
2565674Skristhe number will be set to 1, so that the product of two such random
2676262Sgreennumbers will always have 2*B<bits> length.  If B<bottom> is true, the
27204917Sdesnumber will be odd.
28137019Sdes
29162856SdesBN_pseudo_rand() does the same, but pseudo-random numbers generated by
30226046Sdesthis function are not necessarily unpredictable. They can be used for
31248619Sdesnon-cryptographic purposes and for certain purposes in cryptographic
3257429Smarkmprotocols, but usually not for key generation etc.
3376262Sgreen
3476262SgreenBN_rand_range() generates a cryptographically strong pseudo-random
3576262Sgreennumber B<rnd> in the range 0 <lt>= B<rnd> E<lt> B<range>.
3676262SgreenBN_pseudo_rand_range() does the same, but is based on BN_pseudo_rand(),
3776262Sgreenand hence numbers generated by it are not necessarily unpredictable.
3876262Sgreen
3976262SgreenThe PRNG must be seeded prior to calling BN_rand() or BN_rand_range().
40226046Sdes
41226046Sdes=head1 RETURN VALUES
42226046Sdes
43240075SdesThe functions return 1 on success, 0 on error.
44226046SdesThe error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
45248619Sdes
46248619Sdes=head1 SEE ALSO
47248619Sdes
48248619SdesL<bn(3)|bn(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>,
49248619SdesL<RAND_add(3)|RAND_add(3)>, L<RAND_bytes(3)|RAND_bytes(3)>
50248619Sdes
51137019Sdes=head1 HISTORY
52181111Sdes
5376262SgreenBN_rand() is available in all versions of SSLeay and OpenSSL.
54181111SdesBN_pseudo_rand() was added in OpenSSL 0.9.5. The B<top> == -1 case
55181111Sdesand the function BN_rand_range() were added in OpenSSL 0.9.6a.
56181111SdesBN_pseudo_rand_range() was added in OpenSSL 0.9.6c.
5757429Smarkm
58192595Sdes=cut
59192595Sdes