Skip to content

Conversation

@tarcieri
Copy link
Member

@tarcieri tarcieri commented Jan 6, 2026

Replaces various bespoke RNG APIs with the new Generate trait from crypto_common, which was added to elliptic-curve in RustCrypto/traits#2173.

It's now a required bound for all affine/projective points and scalars, as well as the RNG API used by all generic types defined in the elliptic-curve crate itself.

This API avoids having to directly import getrandom::SysRng, making it possible to call T::generate() instead so long as the getrandom feature of elliptic-curve is enabled.

Replaces various bespoke RNG APIs with the new `Generate` trait from
`crypto_common`, which was added to `elliptic-curve` in
RustCrypto/traits#2173.

It's now a required bound for all affine/projective points and scalars,
as well as the RNG API used by all generic types defined in the
`elliptic-curve` crate itself.

This API avoids having to directly import `getrandom::SysRng`, making it
possible to call `T::generate()` instead so long as the `getrandom`
feature of `elliptic-curve` is enabled.
@tarcieri tarcieri merged commit 8006f06 into master Jan 6, 2026
160 checks passed
@tarcieri tarcieri deleted the generate-trait branch January 6, 2026 21:23
tarcieri added a commit that referenced this pull request Jan 9, 2026
This fixes a critical security vulnerability originally reported as
GHSA-w3g8-fp6j-wvqw by @XlabAITeam.

Previously the module defined its own `next_k` function which invoked
the `RandomBits::try_random_bits` API to generate a `k` value via
rejection sampling, however it was passing previous calculation of the
number of bytes to generate to an API expecting a number of bits.
This bits/bytes confusion lead to highly biased values for `k`
consisting of mostly zeros.

Such a bias can be exploited for full plaintext recovery, and
potentially key recovery. All ciphertexts ever encrypted using this API
are vulnerable.

This commit replaces the `next_k` function with the recently added
`Scalar::try_generate_from_rng` method which uses the `Generate` trait
impl'd in #1586, and is backed by the rejection sampling implemenatation
from `crypto-bigint`.
tarcieri added a commit that referenced this pull request Jan 9, 2026
This fixes a critical security vulnerability originally reported as
GHSA-w3g8-fp6j-wvqw by @XlabAITeam.

Previously the module defined its own `next_k` function which invoked
the `RandomBits::try_random_bits` API to generate a `k` value via
rejection sampling, however it was passing previous calculation of the
number of bytes to generate to an API expecting a number of bits.
This bits/bytes confusion lead to highly biased values for `k`
consisting of mostly zeros.

Such a bias can be exploited for full plaintext recovery, and
potentially key recovery. All ciphertexts ever encrypted using this API
are vulnerable.

This commit replaces the `next_k` function with the recently added
`Generate` trait (#1586), using `NonZeroScalar::try_generate_from_rng`
which is backed by the rejection sampling implemenatation from
`crypto-bigint`.
tarcieri added a commit that referenced this pull request Jan 9, 2026
This fixes a critical security vulnerability originally reported as
GHSA-w3g8-fp6j-wvqw by @XlabAITeam.

Previously the module defined its own `next_k` function which invoked
the `RandomBits::try_random_bits` API to generate a `k` value via
rejection sampling, however it was passing previous calculation of the
number of bytes to generate to an API expecting a number of bits.
This bits/bytes confusion lead to highly biased values for `k`
consisting of mostly zeros.

Such a bias can be exploited for full plaintext recovery, and
potentially key recovery. All ciphertexts ever encrypted using this API
are vulnerable.

This commit replaces the `next_k` function with the recently added
`Generate` trait (#1586), using `NonZeroScalar::try_generate_from_rng`
which is backed by the rejection sampling implemenatation from
`crypto-bigint`.
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