From 61cbd07dec2d9670f170bed44f1815ea29a8a214 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Wed, 20 Apr 2016 18:29:33 -0400 Subject: rand: add comments about getrandom() fallback 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 --- src/libstd/sys/unix/rand.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/libstd/sys') diff --git a/src/libstd/sys/unix/rand.rs b/src/libstd/sys/unix/rand.rs index 7f52a9c1bee..25a7a3ce50d 100644 --- a/src/libstd/sys/unix/rand.rs +++ b/src/libstd/sys/unix/rand.rs @@ -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..]); -- cgit 1.4.1-3-g733a5