1BN_RAND(3)                          OpenSSL                         BN_RAND(3)
2
3
4

NAME

6       BN_rand, BN_priv_rand, BN_pseudo_rand, BN_rand_range,
7       BN_priv_rand_range, BN_pseudo_rand_range - generate pseudo-random
8       number
9

SYNOPSIS

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

DESCRIPTION

26       BN_rand() generates a cryptographically strong pseudo-random number of
27       bits in length and stores it in rnd.  If bits is less than zero, or too
28       small to accommodate the requirements specified by the top and bottom
29       parameters, an error is returned.  The top parameters specifies
30       requirements on the most significant bit of the generated number.  If
31       it is BN_RAND_TOP_ANY, there is no constraint.  If it is
32       BN_RAND_TOP_ONE, the top bit must be one.  If it is BN_RAND_TOP_TWO,
33       the two most significant bits of the number will be set to 1, so that
34       the product of two such random numbers will always have 2*bits length.
35       If bottom is BN_RAND_BOTTOM_ODD, the number will be odd; if it is
36       BN_RAND_BOTTOM_ANY it can be odd or even.  If bits is 1 then top cannot
37       also be BN_RAND_FLG_TOPTWO.
38
39       BN_rand_range() generates a cryptographically strong pseudo-random
40       number rnd in the range 0 <= rnd < range.
41
42       BN_priv_rand() and BN_priv_rand_range() have the same semantics as
43       BN_rand() and BN_rand_range() respectively.  They are intended to be
44       used for generating values that should remain private, and mirror the
45       same difference between RAND_bytes(3) and RAND_priv_bytes(3).
46

NOTES

48       Always check the error return value of these functions and do not take
49       randomness for granted: an error occurs if the CSPRNG has not been
50       seeded with enough randomness to ensure an unpredictable byte sequence.
51

RETURN VALUES

53       The functions return 1 on success, 0 on error.  The error codes can be
54       obtained by ERR_get_error(3).
55

SEE ALSO

57       ERR_get_error(3), RAND_add(3), RAND_bytes(3), RAND_priv_bytes(3),
58       RAND(7), RAND_DRBG(7)
59

HISTORY

61       • Starting with OpenSSL release 1.1.0, BN_pseudo_rand() has been
62         identical to BN_rand() and BN_pseudo_rand_range() has been identical
63         to BN_rand_range().  The "pseudo" functions should not be used and
64         may be deprecated in a future release.
65
66       • The BN_priv_rand() and BN_priv_rand_range() functions were added in
67         OpenSSL 1.1.1.
68
70       Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
71
72       Licensed under the OpenSSL license (the "License").  You may not use
73       this file except in compliance with the License.  You can obtain a copy
74       in the file LICENSE in the source distribution or at
75       <https://www.openssl.org/source/license.html>.
76
77
78
791.1.1i                            2021-01-26                        BN_RAND(3)
Impressum