-
Notifications
You must be signed in to change notification settings - Fork 69
Require RngCore
instead of CryptoRngCore
for various random methods
#710
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
Conversation
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.
There are many doc comments that reference cryptographically-secure generation, and are no longer accurate with the relaxed trait bound.
{ | ||
/// Generate a random `NonZero<T>`. | ||
fn random(mut rng: &mut impl CryptoRngCore) -> Self { | ||
fn random(mut rng: &mut impl RngCore) -> Self { |
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.
It may be useful to move aspects of the internal comment to the doc comment now that a CSPRNG is no longer guaranteed.
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 removed this doc comment and allowed the Random::random()
one take over.
pub trait Random: Sized { | ||
/// Generate a cryptographically secure random value. | ||
fn random(rng: &mut impl CryptoRngCore) -> Self; | ||
fn random(rng: &mut impl RngCore) -> Self; |
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.
The doc comment is no longer accurate.
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.
Added a note
/// | ||
/// A wrapper for [`RandomBits::try_random_bits`] that panics on error. | ||
fn random_bits(rng: &mut impl CryptoRngCore, bit_length: u32) -> Self { | ||
fn random_bits(rng: &mut impl RngCore, bit_length: u32) -> Self { |
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.
The doc comment is no longer accurate.
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.
Added notes for the methods in this trait
rng: &mut impl CryptoRngCore, | ||
bit_length: u32, | ||
) -> Result<Self, RandomBitsError>; | ||
fn try_random_bits(rng: &mut impl RngCore, bit_length: u32) -> Result<Self, RandomBitsError>; |
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.
The doc comment is no longer accurate.
/// A wrapper for [`RandomBits::try_random_bits_with_precision`] that panics on error. | ||
fn random_bits_with_precision( | ||
rng: &mut impl CryptoRngCore, | ||
rng: &mut impl RngCore, |
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.
The doc comment is no longer accurate.
/// CSRNG, where previous outputs are unrelated to subsequent | ||
/// outputs and do not reveal information about the RNG's internal state. | ||
fn random_mod(rng: &mut impl CryptoRngCore, modulus: &NonZero<Self>) -> Self; | ||
fn random_mod(rng: &mut impl RngCore, modulus: &NonZero<Self>) -> Self; |
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 would be very careful about this doc comment, as the user may not be aware of what constitutes a CSPRNG.
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.
At any rate, the top-line comment is no longer accurate.
/// underlying random number generator is truly a CSRNG, where previous outputs are unrelated to | ||
/// subsequent outputs and do not reveal information about the RNG's internal state. | ||
fn random_mod(rng: &mut impl CryptoRngCore, modulus: &NonZero<Self>) -> Self { | ||
fn random_mod(rng: &mut impl RngCore, modulus: &NonZero<Self>) -> Self { |
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 would be very careful about this doc comment, as the user may not be aware of what constitutes a CSPRNG.
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.
At any rate, the top-line comment is no longer accurate.
impl<const LIMBS: usize> Random for Uint<LIMBS> { | ||
/// Generate a cryptographically secure random [`Uint`]. | ||
fn random(mut rng: &mut impl CryptoRngCore) -> Self { | ||
fn random(mut rng: &mut impl RngCore) -> Self { |
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.
The doc comment is no longer accurate.
/// CSRNG, where previous outputs are unrelated to subsequent | ||
/// outputs and do not reveal information about the RNG's internal state. | ||
fn random_mod(rng: &mut impl CryptoRngCore, modulus: &NonZero<Self>) -> Self { | ||
fn random_mod(rng: &mut impl RngCore, modulus: &NonZero<Self>) -> Self { |
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.
See earlier comments.
Thanks for checking, that's what happens when you make a PR late at night |
I was in the process of adding a little more stuff to the docs... sorry, should have switched it to the draft form |
Basically just the additional lines
Maybe it would be too much hand-holding anyway. |
That seems okay if you want to submit a followup |
Does this change mean that random number generation functions using rejection sampling should be explicitly tagged with a |
Ugh, I mean it was always "vartime". I agree that now there are more footguns. |
Made some documentation updates in #711 toward this. |
Relaxes
CryptoRngCore
requirement toRngCore
. Fixes #137