elliptic-curve: add MulByGeneratorVartime trait#2381
Merged
tarcieri merged 1 commit intoApr 11, 2026
Conversation
Closes #2375 We now have variable-time precomputed basepoint tables that use wNAF when the `basepoint-table` and `alloc` features are enabled, which can be opportunistically used when these features are enabled to accelerate this operation. We use `Group::mul_by_generator` for the constant-time basepoint tables, however for an extension trait this is captured as `MulByGeneratorVartime::mul_by_generator_vartime`. As discussed in the above issue, and inspired by `curve25519-dalek`'s `EdwardsPoint::vartime_double_scalar_mul_basepoint` function, this adds `MulByGeneratorVartime::mul_by_generator_and_mul_add_point_vartime` as a provided method. This function is the core of many signature algorithms, and when the basepoint tables and alloc are unavailable it can fall back to a linear combination and still provide better performance than the naive constant time version.
tarcieri
added a commit
to RustCrypto/elliptic-curves
that referenced
this pull request
Apr 15, 2026
Implements the trait introduced in RustCrypto/traits#2381 which makes it possible to provide optimized implementations of multiplication by the generator. Currently this just naively calls `mul_vartime` on `ProjectivePoint::GENERATOR`, which still provides some optimization when the `alloc` feature is enabled: scalar operations/generator-scalar mul time: [122.08 µs 122.48 µs 122.97 µs] scalar operations/generator-scalar mul (variable-time) time: [105.83 µs 107.98 µs 111.45 µs] When `alloc` isn't available, it uses linear combinations to implement computing `aG * bB`, which should still provide a speedup in that case.
tarcieri
added a commit
to RustCrypto/elliptic-curves
that referenced
this pull request
Apr 15, 2026
Implements the trait introduced in RustCrypto/traits#2381 which makes it possible to provide optimized implementations of multiplication by the generator. Currently this just naively calls `mul_vartime` on `ProjectivePoint::GENERATOR`, which still provides some optimization when the `alloc` feature is enabled: scalar operations/generator-scalar mul time: [122.08 µs 122.48 µs 122.97 µs] scalar operations/generator-scalar mul (variable-time) time: [105.83 µs 107.98 µs 111.45 µs] When `alloc` isn't available, it uses linear combinations to implement computing `aG * bB`, which should still provide a speedup in that case.
tarcieri
added a commit
to RustCrypto/elliptic-curves
that referenced
this pull request
Apr 15, 2026
Like #1726 did for `primeorder`, this impls this new trait which was introduced in RustCrypto/traits#2381. Since `group::Wnaf` winds up being slower since it doesn't support the endomorphism optimization, this just calls into the constant-time operation.
tarcieri
added a commit
to RustCrypto/elliptic-curves
that referenced
this pull request
Apr 15, 2026
Like #1726 did for `primeorder`, this impls this new trait which was introduced in RustCrypto/traits#2381. Since `group::Wnaf` winds up being slower since it doesn't support the endomorphism optimization, this just calls into the constant-time operation.
tarcieri
added a commit
to RustCrypto/elliptic-curves
that referenced
this pull request
Apr 15, 2026
Like #1726 did for `primeorder` and #1728 did for `k256`, this impls this new trait which was introduced in RustCrypto/traits#2381. We don't actually have vartime support in this crate, so this just falls back to the constant-time implementation.
tarcieri
added a commit
to RustCrypto/elliptic-curves
that referenced
this pull request
Apr 15, 2026
Like #1726 did for `primeorder` and #1728 did for `k256`, this impls this new trait which was introduced in RustCrypto/traits#2381. We don't actually have vartime support in this crate, so this just falls back to the constant-time implementation.
Merged
tarcieri
added a commit
that referenced
this pull request
Jun 23, 2026
## Added - Implement `PartialEq + Eq` for `NonIdentity` and `NonZeroScalar` (#1834) - Implement `Zeroize` for `NonIdentity` (#1832) - `NonIdentity::mul_by_generator()` (#1833) - Implement `Mul<&NonZeroScalar>` for `NonIdentity` (#1852) - Implement `Mul<NonIdentity>` for `NonZeroScalar` (#1855) - Expose `AffineCoordinates::y` (#1891) - Scalar macros originall from `primeorder` (#1894) - Implement `BatchNormalize` for `NonIdentity` (#1896) - Re-export `group::Curve` as `CurveGroup` (#1902) - `NonIdentity`/`NonZeroScalar` casting methods (#1903) - `AffineCoordinates::from_coordinates` (#1996) - `getrandom` feature (#2085) - `ctutils` traits to `arithmetic` bounds (#2166) - `Retrieve` bound for `C::Scalar` (#2169) - `crypto_common::Generate` support (#2173, #2208) - Implement `crypto_common::TryKeyInit` for `SecretKey<C>` (#2174) - `dev::bench_projective!` macro (#2177) - Provide `Sec1Point::from/to_sec1_bytes` (#2221) - Implement `From<SecretKey<C>>` for `PublicKey<C>` (#2247) - `SecretKey::diffie_hellman` (#2248) - `LinearCombination::lincomb_vartime` method (#2286) - `ops::MulVartime` trait and bound `Scalar` (#2379) - `ops::MulByGeneratorVartime` trait ([#2381]) - `SecretKey::from_pem` (#2387) - `SecretKey::from_der` (#2408) - `hazmat` module with `FieldArithmetic` trait (#2458) - `Double::double_in_place` (#2464) ## Changed - Migrate from `generic-array` to `hybrid-array` (#1462) - Rename `LinearCombinationExt` => `LinearCombination`; replacing old trait (#1501) - Edition changed to 2024 and MSRV bumped to 1.85 (#1759) - Make `SecretKey::new` fallible (#1804) - Replace `ops::Invert` trait with `crypto_bigint::Invert` (#1839) - Rename `SecretKey::new` => `::from_scalar` (#1893) - Replace `Reduce` trait with `crypto_bigint::Reduce` (#1949) - Bump `serdect` dependency to v0.4 (#1978) - Use `crypto_bigint::Odd` to represent `Curve::ORDER` (#2006) - Bound `Curve::Uint` on `Unsigned` (#2007) - Rename `ScalarPrimitive` => `ScalarValue` (#2008) - Accept mixed-case hex-encoded strings in `FromStr` impl for `ScalarValue` (#2037) - Deprecate `SecretKey::random` (#2086) - Move `MockCurve` to `dev::mock_curve` (#2176) - Bump `rand_core` to v0.10 (#2250) - Rename `EncodedPoint` => `Sec1Point` (#2264) - Bump `crypto-bigint` to v0.7 (#2330) - Bump `digest` to v0.11 (#2331) - Bump `sec1` to v0.8 (#2339) - Bump `hkdf` dependency to v0.13 (#2349) - Use `*Vartime` as a suffix in names (#2378) - Bump `pkcs8` to v0.11 (#2397) - Bump `ff` and `group` to v0.14 (#2430, #2431) - Simplify `BatchInvert` trait (#2455) - Replace `FieldBytesEncoding` trait with `C::FIELD_ENDIANNESS` (#2457) - Move `Double` to `ops` module (#2465) ## Removed - `hazmat` feature (#1599) - `hash2curve` and `oprf` modules: moved to same-name crates (#1929) - PKCS#8 blanket impls for SEC1 private key traits (#1930) - `ShrAssign` bound on `Scalar`s (#1938) - JWK support: migrated to `jose-jwk` crate (#1963) - `weierstrass` module (#2005) - `bits` feature (#2417) ## Fixed - Include curve OID in SEC1 private keys (#1707, #1933)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2375
We now have variable-time precomputed basepoint tables that use wNAF when the
basepoint-tableandallocfeatures are enabled, which can be opportunistically used when these features are enabled to accelerate this operation.We use
Group::mul_by_generatorfor the constant-time basepoint tables, however for an extension trait this is captured asMulByGeneratorVartime::mul_by_generator_vartime.As discussed in the above issue, and inspired by
curve25519-dalek'sEdwardsPoint::vartime_double_scalar_mul_basepointfunction, this addsMulByGeneratorVartime::mul_by_generator_and_mul_add_point_vartimeas a provided method. This function is the core of many signature algorithms, and when the basepoint tables and alloc are unavailable it can fall back to a linear combination and still provide better performance than the naive constant time version.