xref: /freebsd/crypto/openssl/doc/man7/RAND.pod (revision 0957b409)
1=pod
2
3=head1 NAME
4
5RAND
6- the OpenSSL random generator
7
8=head1 DESCRIPTION
9
10Random numbers are a vital part of cryptography, they are needed to provide
11unpredictability for tasks like key generation, creating salts, and many more.
12Software-based generators must be seeded with external randomness before they
13can be used as a cryptographically-secure pseudo-random number generator
14(CSPRNG).
15The availability of common hardware with special instructions and
16modern operating systems, which may use items such as interrupt jitter
17and network packet timings, can be reasonable sources of seeding material.
18
19OpenSSL comes with a default implementation of the RAND API which is based on
20the deterministic random bit generator (DRBG) model as described in
21[NIST SP 800-90A Rev. 1]. The default random generator will initialize
22automatically on first use and will be fully functional without having
23to be initialized ('seeded') explicitly.
24It seeds and reseeds itself automatically using trusted random sources
25provided by the operating system.
26
27As a normal application developer, you do not have to worry about any details,
28just use L<RAND_bytes(3)> to obtain random data.
29Having said that, there is one important rule to obey: Always check the error
30return value of L<RAND_bytes(3)> and do not take randomness for granted.
31
32For values that should remain secret, you can use L<RAND_priv_bytes(3)>
33instead.
34This method does not provide 'better' randomness, it uses the same type of CSPRNG.
35The intention behind using a dedicated CSPRNG exclusively for private
36values is that none of its output should be visible to an attacker (e.g.,
37used as salt value), in order to reveal as little information as
38possible about its internal state, and that a compromise of the "public"
39CSPRNG instance will not affect the secrecy of these private values.
40
41In the rare case where the default implementation does not satisfy your special
42requirements, there are two options:
43
44=over 2
45
46=item *
47
48Replace the default RAND method by your own RAND method using
49L<RAND_set_rand_method(3)>.
50
51=item *
52
53Modify the default settings of the OpenSSL RAND method by modifying the security
54parameters of the underlying DRBG, which is described in detail in L<RAND_DRBG(7)>.
55
56=back
57
58Changing the default random generator or its default parameters should be necessary
59only in exceptional cases and is not recommended, unless you have a profound knowledge
60of cryptographic principles and understand the implications of your changes.
61
62=head1 SEE ALSO
63
64L<RAND_add(3)>,
65L<RAND_bytes(3)>,
66L<RAND_priv_bytes(3)>,
67L<RAND_get_rand_method(3)>,
68L<RAND_set_rand_method(3)>,
69L<RAND_OpenSSL(3)>,
70L<RAND_DRBG(7)>
71
72=head1 COPYRIGHT
73
74Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
75
76Licensed under the OpenSSL license (the "License").  You may not use
77this file except in compliance with the License.  You can obtain a copy
78in the file LICENSE in the source distribution or at
79L<https://www.openssl.org/source/license.html>.
80
81=cut
82