]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man3/BN_rand.pod
Update various man pages to place HISTORY section after SEE ALSO
[thirdparty/openssl.git] / doc / man3 / BN_rand.pod
CommitLineData
dd8dec69
UM
1=pod
2
3=head1 NAME
4
b26befb5
NT
5BN_rand, BN_priv_rand, BN_pseudo_rand,
6BN_rand_range, BN_priv_rand_range, BN_pseudo_rand_range
7- generate pseudo-random number
dd8dec69
UM
8
9=head1 SYNOPSIS
10
11 #include <openssl/bn.h>
12
13 int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
14
b26befb5
NT
15 int BN_priv_rand(BIGNUM *rnd, int bits, int top, int bottom);
16
4d524e10 17 int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);
38e33cef 18
e3068929 19 int BN_rand_range(BIGNUM *rnd, BIGNUM *range);
57e7d3ce 20
b26befb5
NT
21 int BN_priv_rand_range(BIGNUM *rnd, BIGNUM *range);
22
b49053ca 23 int BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range);
983495c4 24
dd8dec69
UM
25=head1 DESCRIPTION
26
27BN_rand() generates a cryptographically strong pseudo-random number of
f67cbb74 28B<bits> in length and stores it in B<rnd>.
01c09f9f 29If B<bits> is less than zero, or too small to
69687aa8 30accommodate the requirements specified by the B<top> and B<bottom>
01c09f9f 31parameters, an error is returned.
f67cbb74
RS
32The B<top> parameters specifies
33requirements on the most significant bit of the generated number.
34If it is B<BN_RAND_TOP_ANY>, there is no constraint.
35If it is B<BN_RAND_TOP_ONE>, the top bit must be one.
36If it is B<BN_RAND_TOP_TWO>, the two most significant bits of
335c4f09 37the number will be set to 1, so that the product of two such random
f67cbb74
RS
38numbers will always have 2*B<bits> length.
39If B<bottom> is B<BN_RAND_BOTTOM_ODD>, the number will be odd; if it
40is B<BN_RAND_BOTTOM_ANY> it can be odd or even.
41If B<bits> is 1 then B<top> cannot also be B<BN_RAND_FLG_TOPTWO>.
dd8dec69 42
57e7d3ce 43BN_rand_range() generates a cryptographically strong pseudo-random
31d6c0b2 44number B<rnd> in the range 0 E<lt>= B<rnd> E<lt> B<range>.
57e7d3ce 45
b26befb5
NT
46BN_priv_rand() and BN_priv_rand_range() have the same semantics as
47BN_rand() and BN_rand_range() respectively. They are intended to be
48used for generating values that should remain private, and mirror the
49same difference between L<RAND_bytes(3)> and L<RAND_priv_bytes(3)>.
50
51=head1 NOTES
52
53Always check the error return value of these functions and do not take
54randomness for granted: an error occurs if the CSPRNG has not been
55seeded with enough randomness to ensure an unpredictable byte sequence.
dd8dec69
UM
56
57=head1 RETURN VALUES
58
57e7d3ce 59The functions return 1 on success, 0 on error.
9b86974e 60The error codes can be obtained by L<ERR_get_error(3)>.
dd8dec69 61
b5c4bbbe
JL
62=head1 SEE ALSO
63
64L<ERR_get_error(3)>,
65L<RAND_add(3)>,
66L<RAND_bytes(3)>,
67L<RAND_priv_bytes(3)>,
68L<RAND(7)>,
69L<RAND_DRBG(7)>
70
5ecff87d
RS
71=head1 HISTORY
72
b26befb5
NT
73=over 2
74
75=item *
76
77Starting with OpenSSL release 1.1.0, BN_pseudo_rand() has been identical
78to BN_rand() and BN_pseudo_rand_range() has been identical to
79BN_rand_range().
5ecff87d
RS
80The "pseudo" functions should not be used and may be deprecated in
81a future release.
82
b26befb5
NT
83=item *
84
fc5ecadd
DMSP
85The
86BN_priv_rand() and BN_priv_rand_range() functions were added in OpenSSL 1.1.1.
b26befb5
NT
87
88=back
89
e2f92610
RS
90=head1 COPYRIGHT
91
b5c4bbbe 92Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
e2f92610 93
4746f25a 94Licensed under the Apache License 2.0 (the "License"). You may not use
e2f92610
RS
95this file except in compliance with the License. You can obtain a copy
96in the file LICENSE in the source distribution or at
97L<https://www.openssl.org/source/license.html>.
98
99=cut