-
Notifications
You must be signed in to change notification settings - Fork 213
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
[Discussion] rand::RngCore for blocking RNG trait #128
Comments
Good question.
I am unaware about how many implementations of I think I like option 2 the most for now, including removing Opinions from hardware RNG implementers would be helpful here. |
Funny enough I had the exact same trait definition and implementation in my |
hmm, all interesting options! it's definitely neat to have consistent rand everywhere. i am also perhaps a little cautious about the weird breakages we might see trying to match libraries with different in related things there's also |
No strong opinions; I did also implement this unproven trait in our LPC55 HAL, just to not reinvent the wheel. Practically, all I need is a method to fill byte buffers with entropy, with the ability to ignore errors. Might it be possible to nudge In my opinion though I'd tend to prefer an infallible method for these reasons, but certainly someone is going to come up with some valid corner case on embedded Linux or something 😅. In any case, if the consensus is for a fallible method, then #229 seems applicable, I don't think cc @tarcieri as it would be great if the eventual trait integrated nicely with RustCrypto. |
Outside the embedded space, We've adopted |
In yesterdays meeting we mostly hovered around going option 2 with the possible path to go option 1 in the future if things get too wild. Personally I think if there's a perfectly fine universal solution like |
This is basically waiting for someone to PR the removal of |
I think you'll be a lot better off not re-exporting it, as it's one of the most common triggers of this bug: The |
The TRNG of the i.MX RT106x (and probably the similar chips) can fail at any time, and it does not (AFAIK) do any self-test on startup. It applies various statistical tests to its output and sets the error flag if any of them fail. Data will still be generated but is presumably not truly random (assuming tests are running properly; they are configurable). NXP's official SDK will not write the data to the out-pointer in this case. I don't believe I've seen a failure with its default configuration options but it might happen. NXP does not publicly provide documentation for the security features of the chip, so it's hard for me to know. (My current support for the TRNG just waits for good data forever.) I'll also note here that the TRNG of the 106x generates 512 bits at a time. I agree the mix of infallible/fallible methods of RngCore is odd. |
The [rand_core](https://crates.io/crates/rand_core) crate already implements relevant traits for random number generation. A HAL which provides access to a RNG peripheral should implement these traits instead and a driver should rely on these.
The RngCore trait seems like a good candidate for a blocking RNG trait. It is minimal, already in fairly wide use and
no-std
.The text was updated successfully, but these errors were encountered: