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

NAME

6       BN_rand_ex, BN_rand, BN_priv_rand_ex, BN_priv_rand, BN_pseudo_rand,
7       BN_rand_range_ex, BN_rand_range, BN_priv_rand_range_ex,
8       BN_priv_rand_range, BN_pseudo_rand_range - generate pseudo-random
9       number
10

SYNOPSIS

12        #include <openssl/bn.h>
13
14        int BN_rand_ex(BIGNUM *rnd, int bits, int top, int bottom,
15                       unsigned int strength, BN_CTX *ctx);
16        int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
17
18        int BN_priv_rand_ex(BIGNUM *rnd, int bits, int top, int bottom,
19                            unsigned int strength, BN_CTX *ctx);
20        int BN_priv_rand(BIGNUM *rnd, int bits, int top, int bottom);
21
22        int BN_rand_range_ex(BIGNUM *rnd, const BIGNUM *range, unsigned int strength,
23                             BN_CTX *ctx);
24        int BN_rand_range(BIGNUM *rnd, const BIGNUM *range);
25
26        int BN_priv_rand_range_ex(BIGNUM *rnd, const BIGNUM *range, unsigned int strength,
27                                  BN_CTX *ctx);
28        int BN_priv_rand_range(BIGNUM *rnd, const BIGNUM *range);
29
30       The following functions have been deprecated since OpenSSL 3.0, and can
31       be hidden entirely by defining OPENSSL_API_COMPAT with a suitable
32       version value, see openssl_user_macros(7):
33
34        int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);
35        int BN_pseudo_rand_range(BIGNUM *rnd, const BIGNUM *range);
36

DESCRIPTION

38       BN_rand_ex() generates a cryptographically strong pseudo-random number
39       of bits in length and security strength at least strength bits using
40       the random number generator for the library context associated with
41       ctx. The function stores the generated data in rnd. The parameter ctx
42       may be NULL in which case the default library context is used.  If bits
43       is less than zero, or too small to accommodate the requirements
44       specified by the top and bottom parameters, an error is returned.  The
45       top parameters specifies requirements on the most significant bit of
46       the generated number.  If it is BN_RAND_TOP_ANY, there is no
47       constraint.  If it is BN_RAND_TOP_ONE, the top bit must be one.  If it
48       is BN_RAND_TOP_TWO, the two most significant bits of the number will be
49       set to 1, so that the product of two such random numbers will always
50       have 2*bits length.  If bottom is BN_RAND_BOTTOM_ODD, the number will
51       be odd; if it is BN_RAND_BOTTOM_ANY it can be odd or even.  If bits is
52       1 then top cannot also be BN_RAND_TOP_TWO.
53
54       BN_rand() is the same as BN_rand_ex() except that the default library
55       context is always used.
56
57       BN_rand_range_ex() generates a cryptographically strong pseudo-random
58       number rnd, of security stength at least strength bits, in the range 0
59       <= rnd < range using the random number generator for the library
60       context associated with ctx. The parameter ctx may be NULL in which
61       case the default library context is used.
62
63       BN_rand_range() is the same as BN_rand_range_ex() except that the
64       default library context is always used.
65
66       BN_priv_rand_ex(), BN_priv_rand(), BN_priv_rand_rand_ex() and
67       BN_priv_rand_range() have the same semantics as BN_rand_ex(),
68       BN_rand(), BN_rand_range_ex() and BN_rand_range() respectively.  They
69       are intended to be used for generating values that should remain
70       private, and mirror the same difference between RAND_bytes(3) and
71       RAND_priv_bytes(3).
72

NOTES

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

RETURN VALUES

79       The functions return 1 on success, 0 on error.  The error codes can be
80       obtained by ERR_get_error(3).
81

SEE ALSO

83       ERR_get_error(3), RAND_add(3), RAND_bytes(3), RAND_priv_bytes(3),
84       RAND(7), EVP_RAND(7)
85

HISTORY

87       • Starting with OpenSSL release 1.1.0, BN_pseudo_rand() has been
88         identical to BN_rand() and BN_pseudo_rand_range() has been identical
89         to BN_rand_range().  The BN_pseudo_rand() and BN_pseudo_rand_range()
90         functions were deprecated in OpenSSL 3.0.
91
92       • The BN_priv_rand() and BN_priv_rand_range() functions were added in
93         OpenSSL 1.1.1.
94
95       • The BN_rand_ex(), BN_priv_rand_ex(), BN_rand_range_ex() and
96         BN_priv_rand_range_ex() functions were added in OpenSSL 3.0.
97
99       Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
100
101       Licensed under the Apache License 2.0 (the "License").  You may not use
102       this file except in compliance with the License.  You can obtain a copy
103       in the file LICENSE in the source distribution or at
104       <https://www.openssl.org/source/license.html>.
105
106
107
1083.0.5                             2022-11-01                    BN_RAND(3ossl)
Impressum