1rand(3)                             OpenSSL                            rand(3)
2
3
4

NAME

6       rand - pseudo-random number generator
7

SYNOPSIS

9        #include <openssl/rand.h>
10
11        int  RAND_set_rand_engine(ENGINE *engine);
12
13        int  RAND_bytes(unsigned char *buf, int num);
14        int  RAND_pseudo_bytes(unsigned char *buf, int num);
15
16        void RAND_seed(const void *buf, int num);
17        void RAND_add(const void *buf, int num, double entropy);
18        int  RAND_status(void);
19
20        int  RAND_load_file(const char *file, long max_bytes);
21        int  RAND_write_file(const char *file);
22        const char *RAND_file_name(char *file, size_t num);
23
24        int  RAND_egd(const char *path);
25
26        void RAND_set_rand_method(const RAND_METHOD *meth);
27        const RAND_METHOD *RAND_get_rand_method(void);
28        RAND_METHOD *RAND_SSLeay(void);
29
30        void RAND_cleanup(void);
31
32        /* For Win32 only */
33        void RAND_screen(void);
34        int RAND_event(UINT, WPARAM, LPARAM);
35

DESCRIPTION

37       Since the introduction of the ENGINE API, the recommended way of
38       controlling default implementations is by using the ENGINE API
39       functions. The default RAND_METHOD, as set by RAND_set_rand_method()
40       and returned by RAND_get_rand_method(), is only used if no ENGINE has
41       been set as the default "rand" implementation. Hence, these two
42       functions are no longer the recommended way to control defaults.
43
44       If an alternative RAND_METHOD implementation is being used (either set
45       directly or as provided by an ENGINE module), then it is entirely
46       responsible for the generation and management of a cryptographically
47       secure PRNG stream. The mechanisms described below relate solely to the
48       software PRNG implementation built in to OpenSSL and used by default.
49
50       These functions implement a cryptographically secure pseudo-random
51       number generator (PRNG). It is used by other library functions for
52       example to generate random keys, and applications can use it when they
53       need randomness.
54
55       A cryptographic PRNG must be seeded with unpredictable data such as
56       mouse movements or keys pressed at random by the user. This is
57       described in RAND_add(3). Its state can be saved in a seed file (see
58       RAND_load_file(3)) to avoid having to go through the seeding process
59       whenever the application is started.
60
61       RAND_bytes(3) describes how to obtain random data from the PRNG.
62

INTERNALS

64       The RAND_SSLeay() method implements a PRNG based on a cryptographic
65       hash function.
66
67       The following description of its design is based on the SSLeay
68       documentation:
69
70       First up I will state the things I believe I need for a good RNG.
71
72       1.  A good hashing algorithm to mix things up and to convert the RNG
73           'state' to random numbers.
74
75       2.  An initial source of random 'state'.
76
77       3.  The state should be very large.  If the RNG is being used to
78           generate 4096 bit RSA keys, 2 2048 bit random strings are required
79           (at a minimum).  If your RNG state only has 128 bits, you are
80           obviously limiting the search space to 128 bits, not 2048.  I'