Skip to content

Commit

Permalink
rand: add comments about getrandom() fallback
Browse files Browse the repository at this point in the history
Add some comments so that people know why we are performing a fallback
from getrandom() and what that fallback aims to achieve.

Signed-off-by: Doug Goldstein <cardoe@cardoe.com>
  • Loading branch information
cardoe committed Apr 21, 2016
1 parent 121225f commit 61cbd07
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/libstd/sys/unix/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ mod imp {
if err == libc::EINTR {
continue;
} else if err == libc::EAGAIN {
// if getrandom() returns EAGAIN it would have blocked
// because the non-blocking pool (urandom) has not
// initialized in the kernel yet due to a lack of entropy
// the fallback we do here is to avoid blocking applications
// which could depend on this call without ever knowing
// they do and don't have a work around. The PRNG of
// /dev/urandom will still be used but not over a completely
// full entropy pool
let reader = File::open("/dev/urandom").expect("Unable to open /dev/urandom");
let mut reader_rng = ReaderRng::new(reader);
reader_rng.fill_bytes(& mut v[read..]);
Expand Down

0 comments on commit 61cbd07

Please sign in to comment.