Skip to content

Commit db0466c

Browse files
committed
---
yaml --- r: 113406 b: refs/heads/snap-stage3 c: 967366e h: refs/heads/master v: v3
1 parent a495953 commit db0466c

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: abdacecdf86b4b5a4f432560445a24e1c5f4751b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 5001a666650962f00137f126247c50fa1188a599
4+
refs/heads/snap-stage3: 967366e988a811ae0fb47d3ad5ce0499a1414a43
55
refs/heads/try: 7c6c492fb2af9a85f21ff952942df3523b22fd17
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librand/lib.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,27 @@ after generating 32 KiB of random data.
3030
3131
# Cryptographic security
3232
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.)
4754
4855
# Examples
4956

branches/snap-stage3/src/librand/os.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ mod imp {
109109
CRYPT_VERIFYCONTEXT | CRYPT_SILENT)
110110
};
111111

112+
// FIXME #13259:
112113
// It turns out that if we can't acquire a context with the
113114
// NTE_BAD_SIGNATURE error code, the documentation states:
114115
//

0 commit comments

Comments
 (0)