xref: /freebsd/crypto/openssl/doc/man7/RAND.pod (revision b077aed3)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5e71b7053SJung-uk KimRAND
6e71b7053SJung-uk Kim- the OpenSSL random generator
7e71b7053SJung-uk Kim
8e71b7053SJung-uk Kim=head1 DESCRIPTION
9e71b7053SJung-uk Kim
10e71b7053SJung-uk KimRandom numbers are a vital part of cryptography, they are needed to provide
11e71b7053SJung-uk Kimunpredictability for tasks like key generation, creating salts, and many more.
12e71b7053SJung-uk KimSoftware-based generators must be seeded with external randomness before they
13e71b7053SJung-uk Kimcan be used as a cryptographically-secure pseudo-random number generator
14e71b7053SJung-uk Kim(CSPRNG).
15e71b7053SJung-uk KimThe availability of common hardware with special instructions and
16e71b7053SJung-uk Kimmodern operating systems, which may use items such as interrupt jitter
17e71b7053SJung-uk Kimand network packet timings, can be reasonable sources of seeding material.
18e71b7053SJung-uk Kim
19e71b7053SJung-uk KimOpenSSL comes with a default implementation of the RAND API which is based on
20e71b7053SJung-uk Kimthe deterministic random bit generator (DRBG) model as described in
21e71b7053SJung-uk Kim[NIST SP 800-90A Rev. 1]. The default random generator will initialize
22e71b7053SJung-uk Kimautomatically on first use and will be fully functional without having
23e71b7053SJung-uk Kimto be initialized ('seeded') explicitly.
24e71b7053SJung-uk KimIt seeds and reseeds itself automatically using trusted random sources
25e71b7053SJung-uk Kimprovided by the operating system.
26e71b7053SJung-uk Kim
27e71b7053SJung-uk KimAs a normal application developer, you do not have to worry about any details,
28e71b7053SJung-uk Kimjust use L<RAND_bytes(3)> to obtain random data.
29e71b7053SJung-uk KimHaving said that, there is one important rule to obey: Always check the error
30e71b7053SJung-uk Kimreturn value of L<RAND_bytes(3)> and do not take randomness for granted.
31da327cd2SJung-uk KimAlthough (re-)seeding is automatic, it can fail because no trusted random source
32da327cd2SJung-uk Kimis available or the trusted source(s) temporarily fail to provide sufficient
33da327cd2SJung-uk Kimrandom seed material.
34da327cd2SJung-uk KimIn this case the CSPRNG enters an error state and ceases to provide output,
35da327cd2SJung-uk Kimuntil it is able to recover from the error by reseeding itself.
36*b077aed3SPierre ProncheryFor more details on reseeding and error recovery, see L<EVP_RAND(7)>.
37e71b7053SJung-uk Kim
38e71b7053SJung-uk KimFor values that should remain secret, you can use L<RAND_priv_bytes(3)>
39e71b7053SJung-uk Kiminstead.
40*b077aed3SPierre ProncheryThis method does not provide 'better' randomness, it uses the same type of
41*b077aed3SPierre ProncheryCSPRNG.
42e71b7053SJung-uk KimThe intention behind using a dedicated CSPRNG exclusively for private
43e71b7053SJung-uk Kimvalues is that none of its output should be visible to an attacker (e.g.,
44e71b7053SJung-uk Kimused as salt value), in order to reveal as little information as
45e71b7053SJung-uk Kimpossible about its internal state, and that a compromise of the "public"
46e71b7053SJung-uk KimCSPRNG instance will not affect the secrecy of these private values.
47e71b7053SJung-uk Kim
48e71b7053SJung-uk KimIn the rare case where the default implementation does not satisfy your special
49*b077aed3SPierre Proncheryrequirements, the default RAND internals can be replaced by your own
50*b077aed3SPierre ProncheryL<EVP_RAND(3)> objects.
51e71b7053SJung-uk Kim
52*b077aed3SPierre ProncheryChanging the default random generator should be necessary
53*b077aed3SPierre Proncheryonly in exceptional cases and is not recommended, unless you have a profound
54*b077aed3SPierre Proncheryknowledge of cryptographic principles and understand the implications of your
55*b077aed3SPierre Proncherychanges.
56e71b7053SJung-uk Kim
57*b077aed3SPierre Pronchery=head1 DEFAULT SETUP
58e71b7053SJung-uk Kim
59*b077aed3SPierre ProncheryThe default OpenSSL RAND method is based on the EVP_RAND deterministic random
60*b077aed3SPierre Proncherybit generator (DRBG) classes.
61*b077aed3SPierre ProncheryA DRBG is a certain type of cryptographically-secure pseudo-random
62*b077aed3SPierre Proncherynumber generator (CSPRNG), which is described in [NIST SP 800-90A Rev. 1].
63e71b7053SJung-uk Kim
64e71b7053SJung-uk Kim
65e71b7053SJung-uk Kim=head1 SEE ALSO
66e71b7053SJung-uk Kim
67e71b7053SJung-uk KimL<RAND_bytes(3)>,
68e71b7053SJung-uk KimL<RAND_priv_bytes(3)>,
69*b077aed3SPierre ProncheryL<EVP_RAND(3)>,
70*b077aed3SPierre ProncheryL<RAND_get0_primary(3)>,
71*b077aed3SPierre ProncheryL<EVP_RAND(7)>
72e71b7053SJung-uk Kim
73e71b7053SJung-uk Kim=head1 COPYRIGHT
74e71b7053SJung-uk Kim
75*b077aed3SPierre ProncheryCopyright 2018-2021 The OpenSSL Project Authors. All Rights Reserved.
76e71b7053SJung-uk Kim
77*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
78e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
79e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
80e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
81e71b7053SJung-uk Kim
82e71b7053SJung-uk Kim=cut
83