1BN_rand(3)                          OpenSSL                         BN_rand(3)
2
3
4

NAME

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

SYNOPSIS

10        #include <openssl/bn.h>
11
12        int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
13
14        int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);
15
16        int BN_rand_range(BIGNUM *rnd, BIGNUM *range);
17
18        int BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range);
19

DESCRIPTION

21       BN_rand() generates a cryptographically strong pseudo-random number of
22       bits in length and stores it in rnd.  If bits is less than zero, or too
23       small to accomodate the requirements specified by the top and bottom
24       parameters, an error is returned.  If top is -1, the most significant
25       bit of the random number can be zero. If top is 0, it is set to 1, and
26       if top is 1, the two most significant bits of the number will be set to
27       1, so that the product of two such random numbers will always have
28       2*bits length.  If bottom is true, the number will be odd. The value of
29       bits must be zero or greater. If bits is 1 then top cannot also be 1.
30
31       BN_pseudo_rand() does the same, but pseudo-random numbers generated by
32       this function are not necessarily unpredictable. They can be used for
33       non-cryptographic purposes and for certain purposes in cryptographic
34       protocols, but usually not for key generation etc.
35
36       BN_rand_range() generates a cryptographically strong pseudo-random
37       number rnd in the range 0 <= rnd < range.  BN_pseudo_rand_range() does
38       the same, but is based on BN_pseudo_rand(), and hence numbers generated
39       by it are not necessarily unpredictable.
40
41       The PRNG must be seeded prior to calling BN_rand() or BN_rand_range().
42

RETURN VALUES

44       The functions return 1 on success, 0 on error.  The error codes can be
45       obtained by ERR_get_error(3).
46

SEE ALSO

48       bn(3), ERR_get_error(3), rand(3), RAND_add(3), RAND_bytes(3)
49

HISTORY

51       BN_rand() is available in all versions of SSLeay and OpenSSL.
52       BN_pseudo_rand() was added in OpenSSL 0.9.5. The top == -1 case and the
53       function BN_rand_range() were added in OpenSSL 0.9.6a.
54       BN_pseudo_rand_range() was added in OpenSSL 0.9.6c.
55
56
57
581.0.2o                            2020-08-01                        BN_rand(3)
Impressum