Repository navigation
AArch64 P-384 ECDH: the window's mixed addition inline - #2874
Merged
reaperhulk merged 3 commits intoOct 20, 2026
Merged
Conversation
reaperhulk
added this pull request to stack #2887
October 20, 2026 05:56
The window (WinCfg.windowJ, stepJ, sumJ) takes an optional block for its mixed addition (maddRD), proven by MaddSpec in place of fprogB of maddJ. vg_ecdh_p384 passes Impl/P384/EcdhMadd.lean's madd, the field operations of maddJ as Ops.op's, proven by Ops.fprog_ok (Proof/P384/EcdhMadd.lean). 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
…t rules 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-madd
branch
from
October 20, 2026 06:37
43907ef to
d5823e2
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 #2872 (itself on #2870 and #2867); review only the last two commits.
Until now, the P-384 ECDH window's mixed addition
R + Ecalled out of line tovg_p384_mul_mod_pandvg_p384_sqr_mod_p, throughfprogBofmaddJ(8 products and 3 squares). It now runs as one straight-line block ofOps.opfield operations, the same inline cores the allocated doublings use.Changes
Implementation
Impl/Weierstrass/AArch64/WindowJ.lean.sumJ(andstepJ,windowJ) take an optional block for the mixed addition (maddRD), in place offprogBofmaddJ, the same way they take the doublings.Cfg.mulJ4andexchangeJ4pass it through. Every other caller keeps the default,none, so their code is unchanged.Impl/P384/EcdhMadd.lean.madd := (maddJ K.S K.R K.E K.D).flatMap Ops.op. It usesx1–x17andx21–x25; ECDH already savesx21–x25.vg_ecdh_p384passesmadd.Proofs
Proof/Weierstrass/AArch64/WinJStep.lean.MaddSpecis what a window's mixed addition must do: keep the registers outsideclob ++ winSavedand the memory outside the loop's slots, and leaveDholdingmaddJFofRandE.MaddOklifts it to the optional block.sumJ_oktakes a block withMaddOk; the defaultfprogBprogram meets it throughwinN_ok.winStepJ_ok,windowJ_okandmulJ4_okpass it on.Proof/P384/EcdhMadd.lean.madd_okisofN_ok's argument withOps.fprog_okin place offprogB_ok: the same slots, frame and values (ofN_run,maddJN_run).No certificate: the block is not register-allocated. llvm-mca (N2) puts the allocator's output at 856 cycles against 822 for the inline block, so allocation would cost time here, unlike the doubling.
No changes to
TCB/orSpec/.Speed
Neoverse N2, run 39288463032, against #2872's head (73332c3):
VG_CPU_FEATURES=noneecdh_p384ec_p384_public_keyecdsa_p384_sha384_sign64 B / 1 KiB / 16 KiBecdsa_p384_sha384_verify64 B / 1 KiB / 16 KiBSign and verify don't use this code; their changes are noise.
The whole stack against
main(da70d00), run 39288468635:Checks
These pass locally:
lake buildsrc/asm/aarch64/ecdh_p384.rschanges)check_lean_imports,check_lean_modules,check_registrations,check_lean_speed,check_vectors,check_arch_gates,check_variants,check_mcdtalgorithms_table.py(table unchanged)Generated by Claude Code