-
Notifications
You must be signed in to change notification settings - Fork 44
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
provide new generators: urandom and getentropy #250
Conversation
There's the question how to annotate Fortuna to be racy. Should there be an |
Provide guidance to use these by default, document that Fortuna is not thread-safe. As suggested in mirage#249
74690df
to
f6bf346
Compare
Co-authored-by: Reynir Björnsson <[email protected]>
Co-authored-by: Reynir Björnsson <[email protected]>
The failure semantics is now a bit sad: if for some reason the fd that has /dev/urandom open isn't able to read, we'll end up in an exception. previously with fortuna we were sure that once it is seeded, we'll never fail... but i guess if /dev/urandom doesn't deliver anymore we have other problems, and it's fine to raise an exception. |
since the pfortuna benchmark has been moved to bench/speed, remove bench/miou Mirage_crypto_rng_unix: remove getrandom_into
I think this is fine to merge now. |
@edwintorok happy new year! It'd be great if you could have a look at this PR -- together with a release and announcement on discuss.ocaml.org, I think this would solve #249. What do you think? |
Happy New Year! I started looking at the PR, in general it looks good, but is a complex topic with many (historic) OS specific bugs. Perhaps it might be useful to add a sanity test that fills the buffer with a poison value, calls the RNG, and then checks that (most) bytes have been changed. I can try to submit such a test independently from this PR. |
Dear @edwintorok thanks a lot for your review comments. I'll address them this week and likely cut a release thereafter. |
BTW I started writing some RNG tests last year: https://github.com/perf101/rage/tree/private/edvint/stats6/test/rngtest Although running the full suite takes several hours (and there are multiple testsuites where experts disagree which one is better, so I used them all: One discovery I made during those tests was that calling RDRAND in parallel from lots of cores caused some of them to fail repeatedly, and IIRC RDSEED didn't have that problem. Not relevant for this PR, but perhaps something to keep in mind if you boot lots of mirage unikernels all at the same time and they generate a lot of random data. |
Co-authored-by: Török Edwin <[email protected]>
Co-authored-by: Török Edwin <[email protected]>
…_into: emit unsafe warning
CI failures: OCaml-CI:
So, some issue with miou and windows. The github windows action: issues with gmp. TL;DR: CI errors are unrelated to the proposed change. The uint32_t -> size_t change awaits feedback from Edwin. I think otherwise the PR is fine to merge. |
There is one missing piece there: If you make that change I think this PR is ready then, thanks a lot for the improvements. |
Co-authored-by: Török Edwin <[email protected]>
Ok, I like the diff. One remaining question is whether we should immediately deprecate the Mirage_crypto_rng_unix.initialize, Mirage_crypto_rng_lwt.initialize, Mirage_crypto_rng_async.initialize, Mirage_crypto_rng_miou.initialize (also Mirage_crypto_rng_miou_unix.iniitialize) and point to Maybe @dinosaure and @reynir have ideas about that. It also doesn't block merging this PR, only blocks a subsequent release. It'd ease the opam package cone as well (since in the end we could remove these packages, and only retain mirage-crypto-rng and mirage-crypto-rng-mirage). |
CHANGES: Provide thread safety (Unix.fork and multi-domain safe) RNG generators by using getrandom/getentropy on UNIX (or /dev/urandom). In your UNIX applications, please use the "mirage-crypto-rng.unix" dependency and call "Mirage_crypto_rng_unix.use_default ()" (instead of depending on mirage-crypto-rng-{lwt,eio,async} and calling "Mirage_crypto_rng_{eio,lwt,async}.initialize". * mirage-crypto-rng: handle CPU_RNG failures (mirage/mirage-crypto#255 @hannesm, addresses mirage/mirage-crypto#251 mirage/mirage-crypto#252 mirage/mirage-crypto#253) * mirage-crypto-rng.unix: provide two generators: Urandom and Getentropy (mirage/mirage-crypto#250 @hannesm @reynir @edwintorok, addresses mirage/mirage-crypto#249) * mirage-crypto-rng: deprecate the initialize for lwt, async, eio (and advertise `Mirage_crypto_rng_unix.use_default ()` (mirage/mirage-crypto#254 @hannesm) * mirage-crypto-rng-eio: declare the cstruct dependency (mirage/mirage-crypto#247 @hannesm) * include "windows.h" (all lowercase) (mirage/mirage-crypto#248 @mefyl)
to fix #249