Skip to content

elliptic-curve: getrandom feature#2085

Merged
tarcieri merged 1 commit into
masterfrom
elliptic-curve/getrandom-feature
Nov 9, 2025
Merged

elliptic-curve: getrandom feature#2085
tarcieri merged 1 commit into
masterfrom
elliptic-curve/getrandom-feature

Conversation

@tarcieri
Copy link
Copy Markdown
Member

@tarcieri tarcieri commented Nov 9, 2025

Adds support for generating SecretKey and NonZeroScalar using the system's cryptographically secure random number generator. Notably this renames the former SecretKey::random and NonZeroScalar::random methods to SecretKey::generate and NonZeroScalar::generate, which take no parameters and are infallible.

This avoids the need for the user to import an OsRng type, or worry about the generation failing (which it won't on most notable modern OSes).

If a user still wants to handle RNG errors, the try_from_rng method still exists, and they can pass OsRng if they'd like.

Adds support for generating `SecretKey` and `NonZeroScalar` using the
system's cryptographically secure random number generator. Notably this
renames the former `SecretKey::random` and `NonZeroScalar::random`
methods to `SecretKey::generate` and `NonZeroScalar::generate`, which
take no parameters and are infallible.

This avoids the need for the user to import an `OsRng` type, or worry
about the generation failing (which it won't on most notable modern
OSes).

If a user still wants to handle RNG errors, the `try_from_rng` method
still exists, and they can pass `OsRng` if they'd like.
@tarcieri
Copy link
Copy Markdown
Member Author

tarcieri commented Nov 9, 2025

I think #1897 could potentially obviate the need for this, but I wanted to have a stopgap in place first before exploring that as an alternative.

@tarcieri tarcieri merged commit e122175 into master Nov 9, 2025
74 checks passed
@tarcieri tarcieri deleted the elliptic-curve/getrandom-feature branch November 9, 2025 20:23
tarcieri added a commit to RustCrypto/signatures that referenced this pull request Nov 9, 2025
Adds a `getrandom` feature which allows infallible generation of
`SigningKey`s using the system's cryptographically secure RNG.

Proxies through to the newly added `getrandom` feature in the
`elliptic-curve` crate: RustCrypto/traits#2085
tarcieri added a commit to RustCrypto/signatures that referenced this pull request Nov 9, 2025
Adds a `getrandom` feature which allows infallible generation of
`SigningKey`s using the system's cryptographically secure RNG.

Proxies through to the newly added `getrandom` feature in the
`elliptic-curve` crate: RustCrypto/traits#2085
tarcieri added a commit to RustCrypto/signatures that referenced this pull request Nov 9, 2025
Adds a `getrandom` feature which allows infallible generation of
`SigningKey`s using the system's cryptographically secure RNG.

Proxies through to the newly added `getrandom` feature in the
`elliptic-curve` crate: RustCrypto/traits#2085
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.

1 participant