-
Notifications
You must be signed in to change notification settings - Fork 432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try /dev/random before using /dev/urandom #338
Conversation
I'll work a bit more on this one... |
8ec25de
to
937e856
Compare
I have taken the numbers for I know I made a type in the function but I am stumped by this error by the CI for ARM: https://travis-ci.org/rust-lang-nursery/rand/jobs/358410616
Edit: found the problem. |
937e856
to
c6599ca
Compare
I added back storing the fd in a static on Redox, and the CI is finally green 🎉. Gives a little less confidence though... I think it is ready to took a look at. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surprise surprise, I do actually like the changes, though it took me a while to review!
|
||
Ok(ReadRng {}) | ||
} | ||
|
||
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish diffs were smart enough to realise that the only thing changed was a variable name... these tools haven't changed much since the '70s!
src/os.rs
Outdated
|
||
// Since we have an instance of Self, we can assume that our memory was | ||
// set with a valid object. | ||
let mutex = unsafe{ READ_RNG_FILE.as_ref().unwrap() }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is incorrect; it was there in ReadRng
because existence of the self
parameter proves the constructor ran. Here we just have to use local-analysis to see that this function only gets called after open_dev_random
succeeds.
|
||
// Since we have an instance of Self, we can assume that our memory was | ||
// set with a valid object. | ||
let mutex = unsafe { READ_RNG_FILE.as_ref().unwrap() }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the old comment actually makes sense — we have self
on an object whose constructor initialised the mutex.
I'll just trust you got this right... or wait for error reports.
Wait, the full Yep, happy for this to be merged (though one comment ought to be fixed as mentioned). |
c6599ca
to
8ab3708
Compare
😄 Nice!
I forgot to add back the |
Ready to merge? |
Try /dev/random before using /dev/urandom
@dhardy You are maybe not going to like this PR (it is partly similar to dhardy#48), but I try it anyway 😄.
I have removed the custom
ReadRng
wrapper fromOsRng
, which was only used by Redox, and the module with Linux and non-specified Unix platforms.Redox now has a very basic implementation, without caching the file descriptor. I am not sure it is needed there https://github.com/redox-os/redox/issues/1172.
The implementation of
ReadRng
is mostly folded into the Linux etc. module. It will now attempt to read a single byte from/dev/random
to confirm the OS RNG is initialized, before using/dev/urandom
.In two ways this is not entirely optimal:
/dev/random
may error when the system for some reason thinks it is out of 'entropy', giving a false positive. The change of this happening are unlikely, especially when you consider we only do this test once during the lifetime of the program.But I think these problems are minor.