Skip to content
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

elliptic-curve: add Generate trait #220

Merged
merged 1 commit into from
Jul 25, 2020
Merged

Conversation

tarcieri
Copy link
Member

Trait for randomly generating types using a rand_core::CryptoRng.

Potentially useful in trait bounds that need to generate e.g. Scalar types.

@tarcieri
Copy link
Member Author

Scalar is the main use case I have in mind for this. If there aren't others that are useful, it could potentially be constrained to that.

@tarcieri tarcieri force-pushed the elliptic-curve/generate branch 2 times, most recently from 05d2013 to 1a024bb Compare July 25, 2020 18:41
#[cfg(feature = "rand_core")]
pub trait Generate {
/// Generate a random element of this type using the provided [`CryptoRng`]
fn generate(rng: &mut (impl CryptoRng + RngCore)) -> Self;
Copy link
Member

@newpavlov newpavlov Jul 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RngCore is implemented for mutable RNG references, so we can use rng: impl CryptoRng + RngCore here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, nice

Trait for randomly generating types using a `rand_core::CryptoRng`.
Potentially useful in trait bounds that need to generate e.g. `Scalar`
types.
@tarcieri tarcieri merged commit d009349 into master Jul 25, 2020
@tarcieri tarcieri deleted the elliptic-curve/generate branch July 25, 2020 18:48
tarcieri added a commit to RustCrypto/elliptic-curves that referenced this pull request Jul 27, 2020
Impls the new trait for random generation added in
RustCrypto/traits#220.

This can potentially be used to completely replace the
`GenerateSecretKey` trait, since that can now be made a conditionally
impl'd inherent method on `SecretKey` with where bounds on
`Scalar: Generate`.
tarcieri added a commit to RustCrypto/elliptic-curves that referenced this pull request Jul 27, 2020
Impls the new trait for random generation added in
RustCrypto/traits#220.

This can potentially be used to completely replace the
`GenerateSecretKey` trait, since that can now be made a conditionally
impl'd inherent method on `SecretKey` with where bounds on
`Scalar: Generate`.
tarcieri added a commit to RustCrypto/elliptic-curves that referenced this pull request Jul 27, 2020
Impls the new trait for random generation added in
RustCrypto/traits#220.

This can potentially be used to completely replace the
`GenerateSecretKey` trait, since that can now be made a conditionally
impl'd inherent method on `SecretKey` with where bounds on
`Scalar: Generate`.
@tarcieri tarcieri mentioned this pull request Aug 10, 2020
dns2utf8 pushed a commit to dns2utf8/traits that referenced this pull request Jan 24, 2023
This enables performing a much more exhaustive set of tests for `no_std`
targets, which as of RustCrypto#215 all crates in this repo are fully capable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants