k256: restore w-NAF support#1812
Merged
Merged
Conversation
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.
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.
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
allocdependency, and secondly so we can stabilizek256without having to stabilize thewnafcrate first (or find a solution to use the upstream implementation in thegroupcrate, 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/wnafimplementation we actually need, with the goal of eventually migrating onto an upstream crate (most likelywnaf, 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
allocin-place and using it when it's unavailable, only using w-NAF whenallocis enabled. So regardless of ifallocis enabled there is a variable-time fast path.The performance gains definitely seem to be worth it: