Add self-contained wNAF scalar multiplication in primeorder#1690
Open
tob-scott-a wants to merge 1 commit intoRustCrypto:wnaffrom
Open
Add self-contained wNAF scalar multiplication in primeorder#1690tob-scott-a wants to merge 1 commit intoRustCrypto:wnaffrom
tob-scott-a wants to merge 1 commit intoRustCrypto:wnaffrom
Conversation
The upstream `group::Wnaf` has two bugs that break SEC1/NIST curves: 1. `wnaf_form()` assumes `Scalar::to_repr()` returns little-endian bytes, but `ff::PrimeField` documents repr endianness as implementation-specific. All SEC1/NIST curves use big-endian. 2. `wnaf_form()` drops the final carry when the scalar fills all `bit_len` bits. This is masked on BLS12-381 (255-bit modulus in 256-bit repr) but causes wrong results for p256/k256/p384/p521. Rather than depending on an upstream group crate fix, this adds `primeorder::wnaf::WnafScalarMul` — a self-contained wNAF that handles big-endian repr and the carry correctly. The `WnafGroup` impl on `ProjectivePoint` is filled in (was `todo!()`) but warns that `group::Wnaf` itself remains broken for these curves. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Member
|
This sort of approach seems like a reasonable stopgap, but I'd probably prefer to vendor |
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.
The upstream
group::Wnafhas two bugs that break SEC1/NIST curves:wnaf_form()assumesScalar::to_repr()returns little-endian bytes, butff::PrimeFielddocuments repr endianness as implementation-specific. All SEC1/NIST curves use big-endian.wnaf_form()drops the final carry when the scalar fills allbit_lenbits. This is masked on BLS12-381 (255-bit modulus in 256-bit repr) but causes wrong results for p256/k256/p384/p521.Rather than depending on an upstream group crate fix, this adds
primeorder::wnaf::WnafScalarMul— a self-contained wNAF that handles big-endian repr and the carry correctly.The
WnafGroupimpl onProjectivePointis filled in (wastodo!()) but warns thatgroup::Wnafitself remains broken for these curves.This is an alternative to #1689 that doesn't rely on an external change to the group crate.