2 .\" Copyright (C) 2008, George Spelvin <linux@horizon.com>,
3 .\" and Copyright (C) 2008, Matt Mackall <mpm@selenic.com>
4 .\" and Copyright (C) 2016, Laurent Georget <laurent.georget@supelec.fr>
5 .\" and Copyright (C) 2016, Nikos Mavrogiannopoulos <nmav@redhat.com>
7 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
9 .\" The following web page is quite informative:
10 .\" http://www.2uo.de/myths-about-urandom/
12 .TH random 7 (date) "Linux man-pages (unreleased)"
14 random \- overview of interfaces for obtaining randomness
16 The kernel random-number generator relies on entropy gathered from
17 device drivers and other sources of environmental noise to seed
18 a cryptographically secure pseudorandom number generator (CSPRNG).
19 It is designed for security, rather than speed.
21 The following interfaces provide access to output from the kernel CSPRNG:
27 devices, both described in
29 These devices have been present on Linux since early times,
30 and are also available on many other systems.
34 system call, available since Linux 3.17.
35 This system call provides access either to the same source as
40 or to the same source as
49 source is selected by specifying the
51 flag to the system call.
54 function provides a slightly more portable interface on top of
57 .SS Initialization of the entropy pool
58 The kernel collects bits of entropy from the environment.
59 When a sufficient number of random bits has been collected, the
60 entropy pool is considered to be initialized.
61 .SS Choice of random source
62 Unless you are doing long-term key generation (and most likely not even
63 then), you probably shouldn't be reading from the
70 Instead, either read from the
77 The cryptographic algorithms used for the
79 source are quite conservative, and so should be sufficient for all purposes.
85 is that the operation can block for an indefinite period of time.
86 Furthermore, dealing with the partially fulfilled
87 requests that can occur when using
91 increases code complexity.
93 .SS Monte Carlo and other probabilistic sampling applications
94 Using these interfaces to provide large quantities of data for
95 Monte Carlo simulations or other programs/algorithms which are
96 doing probabilistic sampling will be slow.
97 Furthermore, it is unnecessary, because such applications do not
98 need cryptographically secure random numbers.
99 Instead, use the interfaces described in this page to obtain
100 a small amount of data to seed a user-space pseudorandom
101 number generator for use by such applications.
103 .SS Comparison between getrandom, /dev/urandom, and /dev/random
104 The following table summarizes the behavior of the various
105 interfaces that can be used to obtain randomness.
107 is a flag that can be used to control the blocking behavior of
109 The final column of the table considers the case that can occur
110 in early boot time when the entropy pool is not yet initialized.
114 lbw13 lbw12 lbw14 lbw18
120 Behavior when pool is not yet ready
127 If entropy too low, blocks until there is enough entropy again
129 Blocks until enough entropy gathered
138 Returns output from uninitialized CSPRNG (may be low entropy and unsuitable for cryptography)
146 Does not block once is pool ready
148 Blocks until pool ready
157 If entropy too low, blocks until there is enough entropy again
159 Blocks until pool ready
168 Does not block once is pool ready
182 if not enough entropy available
189 .SS Generating cryptographic keys
190 The amount of seed material required to generate a cryptographic key
191 equals the effective key size of the key.
192 For example, a 3072-bit RSA
193 or Diffie-Hellman private key has an effective key size of 128 bits
194 (it requires about 2\[ha]128 operations to break) so a key generator
195 needs only 128 bits (16 bytes) of seed material from
198 While some safety margin above that minimum is reasonable, as a guard
199 against flaws in the CSPRNG algorithm, no cryptographic primitive
200 available today can hope to promise more than 256 bits of security,
201 so if any program reads more than 256 bits (32 bytes) from the kernel
202 random pool per invocation, or per reasonable reseed interval (not less
203 than one minute), that should be taken as a sign that its cryptography is
205 skillfully implemented.