Skip to content

k256: replace wnaf with built-in vartime scalar mul/lincomb#1810

Merged
tarcieri merged 1 commit into
masterfrom
k256/replace-wnaf-with-built-in-vartime
Jun 17, 2026
Merged

k256: replace wnaf with built-in vartime scalar mul/lincomb#1810
tarcieri merged 1 commit into
masterfrom
k256/replace-wnaf-with-built-in-vartime

Conversation

@tarcieri

@tarcieri tarcieri commented Jun 17, 2026

Copy link
Copy Markdown
Member

Follows suit with #1798 and removes the integration with the wnaf crate originally added in #1745. This removes wnaf as a stabilization block for the time being. We can always add it back.

The result is ~20% slower, but doesn't require alloc, and avoids the need to stabilize wnaf to stabilize k256.

high-level operations/point-scalar mul (variable-time)
    time:   [33.719 µs 33.895 µs 34.123 µs]
    change: [+15.985% +18.087% +20.911%] (p = 0.00 < 0.05)
    Performance has regressed.

ecdsa/verify_prehashed
    time:   [55.777 µs 56.194 µs 56.685 µs]
    change: [+9.2821% +13.258% +17.003%] (p = 0.00 < 0.05)
    Performance has regressed.

The performance regression is fairly significant though, so we should investigate bringing it back when stabilization blockers are resolved.

Follows suit with #1798 and removes the integration with the `wnaf`
crate originally added in #1745. This removes `wnaf` as a stabilization
block for the time being. We can always add it back.

The result is ~20% slower, but doesn't require `alloc`, and avoids the
need to stabilize `wnaf` to stabilize `k256`.

high-level operations/point-scalar mul (variable-time)
    time:   [33.719 µs 33.895 µs 34.123 µs]
    change: [+15.985% +18.087% +20.911%] (p = 0.00 < 0.05)
    Performance has regressed.

ecdsa/verify_prehashed
    time:   [55.777 µs 56.194 µs 56.685 µs]
    change: [+9.2821% +13.258% +17.003%] (p = 0.00 < 0.05)
    Performance has regressed.

The performance regression is fairly significant though, so we should
investigate bringing it back when stabilization blockers are resolved.
@tarcieri tarcieri force-pushed the k256/replace-wnaf-with-built-in-vartime branch from b15b88c to 2289110 Compare June 17, 2026 01:08
@tarcieri tarcieri merged commit 9540d4d into master Jun 17, 2026
165 checks passed
@tarcieri tarcieri deleted the k256/replace-wnaf-with-built-in-vartime branch June 17, 2026 01:23
tarcieri added a commit that referenced this pull request Jun 17, 2026
Support for w-NAF was removed in #1810 which replaced it with a
variable-time path through the existing scalar multiplication / linear
combination implementation, first because that works without an `alloc`
dependency, and secondly so we can stabilize `k256` without having to
stabilize the `wnaf` crate first (or find a solution to use the upstream
implementation in the `group` crate, since we need many changes to make
that work with the GLV endomorphism).

But that may have been too hasty when there's another option: vendor the
parts of the `group`/`wnaf` implementation we actually need, with the
goal of eventually migrating onto an upstream crate (most likely `wnaf`,
which is located in-repo here and therefore easy to co-develop).

This brings back w-NAF support that was removed in #1810 but also
leaves the (slower) variable-time implementation that doesn't require
`alloc` in-place and using it when it's unavailable, only using w-NAF
when `alloc` is enabled. So regardless of if `alloc` is enabled there is
a variable-time fast path.

The performance gains definitely seem to be worth it:

ecdsa/verify_prehashed  time:   [46.603 µs 46.699 µs 46.802 µs]
                        change: [−18.301% −16.734% −15.271%] (p = 0.00 < 0.05)
                        Performance has improved.

high-level operations/point-scalar mul (variable-time)
                        time:   [29.060 µs 29.138 µs 29.218 µs]
                        change: [−15.332% −14.118% −12.622%] (p = 0.00 < 0.05)
                        Performance has improved.

schnorr/verify          time:   [44.450 µs 44.554 µs 44.659 µs]
                        change: [−17.402% −16.639% −15.827%] (p = 0.00 < 0.05)
                        Performance has improved.
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