1BN_rand(3) OpenSSL BN_rand(3)
2
3
4
6 BN_rand, BN_pseudo_rand - generate pseudo-random number
7
9 #include <openssl/bn.h>
10
11 int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
12
13 int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);
14
15 int BN_rand_range(BIGNUM *rnd, BIGNUM *range);
16
17 int BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range);
18
20 BN_rand() generates a cryptographically strong pseudo-random number of
21 bits bits in length and stores it in rnd. If top is -1, the most sig‐
22 nificant bit of the random number can be zero. If top is 0, it is set
23 to 1, and if top is 1, the two most significant bits of the number will
24 be set to 1, so that the product of two such random numbers will always
25 have 2*bits length. If bottom is true, the number will be odd.
26
27 BN_pseudo_rand() does the same, but pseudo-random numbers generated by
28 this function are not necessarily unpredictable. They can be used for
29 non-cryptographic purposes and for certain purposes in cryptographic
30 protocols, but usually not for key generation etc.
31
32 BN_rand_range() generates a cryptographically strong pseudo-random num‐
33 ber rnd in the range 0 <lt>= rnd < range. BN_pseudo_rand_range() does
34 the same, but is based on BN_pseudo_rand(), and hence numbers generated
35 by it are not necessarily unpredictable.
36
37 The PRNG must be seeded prior to calling BN_rand() or BN_rand_range().
38
40 The functions return 1 on success, 0 on error. The error codes can be
41 obtained by ERR_get_error(3).
42
44 bn(3), ERR_get_error(3), rand(3), RAND_add(3), RAND_bytes(3)
45
47 BN_rand() is available in all versions of SSLeay and OpenSSL.
48 BN_pseudo_rand() was added in OpenSSL 0.9.5. The top == -1 case and the
49 function BN_rand_range() were added in OpenSSL 0.9.6a.
50 BN_pseudo_rand_range() was added in OpenSSL 0.9.6c.
51
52
53
540.9.8b 2002-09-25 BN_rand(3)