Repository navigation
x86-64 X25519: the iterations for the clamped bits 2, 1, 0 as three doublings - #2671
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ma2fA9rUTPXEEQjYyCMCRw
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ma2fA9rUTPXEEQjYyCMCRw
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.
Part of #991.
RFC 7748 clamping clears bits 0, 1 and 2 of the scalar. The ladder's last three iterations therefore always double
(x2, z2), after one conditional swap that folds in the pendingswap. On the baseline and ADX x86-64 ladders (the sharedx25519With F), the loop now runs bits 254 down to 3 (cmp rbx, 3). A tail follows it:muxes, selecting(x2, z2)or(x3, z3)by the pending swap;dbl: 2 sqr, 2 mul, a24add, 3 add/sub each, instead of a full step's 4 mul, 4 sqr, a24add and muxes);swap, solastSwapis a no-op.IFMA's own
vladderis unchanged.Proof
LPregainslow: bits 0, 1 and 2 of the clamped scalar are 0.Mainproves it fromscalar_bit.step_oknow reportszf = decide (n = 3), andloop_okruns from 255 down to 3.tail_okproves that the tail reachesladderAfter k u 0's (x2, z2) up to the final swap. It usesladderStep_zero: a step on bit 0 with swap 0 is a doubling of (x2, z2), and (x3, z3) does not matter.LPost's per-slot equalities becomeres: for somesw < 2in the swap word,cswap swof slots 3/5 and 4/6 gives the spec'scswap fin.swap. This is allMainneeds, since it passesswtolastSwap_ok.LPost.ofbuilds it from the old fields for the IFMA ladder.No change to
TCB/,Spec/, any contract or any registration.Benchmarks
Run 39069565593, x86_64. All three jobs ran on Zen 3 (AMD EPYC 7763):
x25519/32x25519_raw/32avx,avx2,bmi1,bmi2,adxnoneThe fixed-base rows (
x25519_generate,x25519_public_key) don't run the ladder, so their executed code is unchanged (unchanged code / placement). They read between 0.0% and 2.1% faster. Nothing is slower. With the ADX ladder, we're now ahead of aws-lc-rs's 27.99 µs.Generated by Claude Code