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