Repository navigation
AArch64 P-384: fuse the doubling's sums into three linear combinations - #2872
Merged
reaperhulk merged 3 commits intoOct 20, 2026
Merged
Conversation
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ma2fA9rUTPXEEQjYyCMCRw
…sed doubling Co-Authored-By: Claude <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
alex
force-pushed
the
claude/a64-p384-ecdh-linear
branch
from
October 20, 2026 06:32
73332c3 to
310913a
Compare
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. Stacked on #2870 (and #2867).
ECDH's window and verify's public NAF both use P-384's allocated doubling (#2867, #2870). It had 16 modular additions and subtractions, each with its own conditional reduction. Following s2n-bignum's
p384_montjdouble_alt, it now computes the same point with five of them and three linear combinations, each reduced once:d = 12 x y² - 9 m²x' = 4 x y² - dy' = 3 d m - 8 y⁴The squares and products are unchanged: 5 squares and 3 products.
Changes
Implementation
Impl/P384/Linear.leanaddslin o a b c d, which computes[o] = c [a] - d [b] mod pwith one reduction, as s2n-bignum'scmsub_p384does:p - [b]from the modulus's slot, multiplies it byd(rowInit), and addsc [a](row). The sum isV < (c + d) p, exactly, in seven words.q, the top word plus one, and addsq (2^384 - p)to the low words. Where that doesn't carry, it addspback under a mask, givingV - q porV - q p + p, which is in[0, p).q (2^384 - p)and of the maskedpare computed from registers, as the allocator follows only loads,movzand register operations.rowInit,rowandP384Mul.addsIn. One generic proof covers all three shapes.Impl/P384/EcdhDouble.lean. The raw doubling follows s2n-bignum's order:ops1,lin,ops2,lin,lin. The allocationImpl/P384/EcdhAllocatedCode.leanis regenerated bylean/GenerateP384Ecdh.lean.Proofs
Proof/P384/Linear.lean.lin_ok:linstores(c A + d (p - B)) mod pforA, B < pandc, d < 2^16, changing onlyclobXando(OpKeepX).reduce_arith, a statement about natural numbers.linOp_okis the same on the window's slots:ocomes to stand forc E_a - d E_b, bytoM_lin.Proof/P384/EcdhDouble/Vals.lean.raw_vals: the new order computesdblJF, by P-256'svalues_eq.Proof/P384/EcdhDouble/Raw.lean.raw_okis restated for the new order. Its slot conditions (RawSlots) are decided for each direction.Proof/P384/EcdhDouble/Verified.lean. Unchanged in substance. The certificates check the new allocation; each still takes a few seconds in the kernel.No changes to
TCB/orSpec/.Speed
Neoverse N2, run 39279849367, compared with #2870's head (8b6dc87):
ecdh_p384ecdsa_p384_sha384_verify64 B / 1 KiB / 16 KiBecdsa_p384_sha384_sign64 B / 1 KiB / 16 KiBec_p384_public_keyVG_CPU_FEATURES=none: ECDH −3.1%, verify −1.9 to −2.2%, sign +0.2 to +0.3%.Checks
These pass locally:
lake buildsrc/asm/aarch64/ecdh_p384.rsandecdsa_p384.rschange)check_lean_imports,check_lean_modules,check_registrations,check_lean_speed,check_vectors,check_arch_gates,check_variants,check_mcdt,cpu_tests.py lintalgorithms_table.py --checkGenerated by Claude Code