@@ -30,20 +30,27 @@ after generating 32 KiB of random data.
30
30
31
31
# Cryptographic security
32
32
33
- An application that requires random numbers for cryptographic purposes
34
- should prefer `OSRng`, which reads randomness from one of the source
35
- that the operating system provides (e.g. `/dev/urandom` on
36
- Unixes). The other random number generators provided by this module
37
- are either known to be insecure (`XorShiftRng`), or are not verified
38
- to be secure (`IsaacRng`, `Isaac64Rng` and `StdRng`).
39
-
40
- *Note*: on Linux, `/dev/random` is more secure than `/dev/urandom`,
41
- but it is a blocking RNG, and will wait until it has determined that
42
- it has collected enough entropy to fulfill a request for random
43
- data. It can be used with the `Rng` trait provided by this module by
44
- opening the file and passing it to `reader::ReaderRng`. Since it
45
- blocks, `/dev/random` should only be used to retrieve small amounts of
46
- randomness.
33
+ An application that requires an entropy source for cryptographic purposes
34
+ must use `OSRng`, which reads randomness from the source that the operating
35
+ system provides (e.g. `/dev/urandom` on Unixes or `CryptGenRandom()` on Windows).
36
+ The other random number generators provided by this module are not suitable
37
+ for such purposes.
38
+
39
+ *Note*: many Unix systems provide `/dev/random` as well as `/dev/urandom`.
40
+ This module uses `/dev/urandom` for the following reasons:
41
+
42
+ - On Linux, `/dev/random` may block if entropy pool is empty; `/dev/urandom` will not block.
43
+ This does not mean that `/dev/random` provides better output than
44
+ `/dev/urandom`; the kernel internally runs a cryptographically secure pseudorandom
45
+ number generator (CSPRNG) based on entropy pool for random number generation,
46
+ so the "quality" of `/dev/random` is not better than `/dev/urandom` in most cases.
47
+ However, this means that `/dev/urandom` can yield somewhat predictable randomness
48
+ if the entropy pool is very small, such as immediately after first booting.
49
+ If an application likely to be run soon after first booting, or on a system with very
50
+ few entropy sources, one should consider using `/dev/random` via `ReaderRng`.
51
+ - On some systems (e.g. FreeBSD, OpenBSD and Mac OS X) there is no difference
52
+ between the two sources. (Also note that, on some systems e.g. FreeBSD, both `/dev/random`
53
+ and `/dev/urandom` may block once if the CSPRNG has not seeded yet.)
47
54
48
55
# Examples
49
56
0 commit comments