Repository navigation
AArch64 P-384 verify: cache the NAF table entries' Z² and Z³ - #2730
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ma2fA9rUTPXEEQjYyCMCRw
Regenerate src/asm/aarch64/ecdsa_p384.rs, and describe the cache in the registration's notes and window_ok's documentation. 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-verify-cached
branch
from
October 18, 2026 03:53
909010c to
5eccde2
Compare
alex
marked this pull request as ready for review
October 18, 2026 03:59
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. Follows #2729.
What
AArch64
vg_ecdsa_p384_verify's public NAF multiplication keeps each table entry'sZ²andZ³(cache,Impl/Weierstrass/AArch64/PubNaf.lean). They are computed once, after the co-Z table, into 128·6 bytes ofscratchabove the table. Each addition of an entry then reads them instead of computing them (addC, the Jacobian addition with the headCachedJac.headAt).The only generated file that changes is
src/asm/aarch64/ecdsa_p384.rs(+443/−29 lines). The cache is unrolled for the eight entries. P-256's code, which sharesCachedJac, is unchanged.No
TCB/orSpec/changes.Impl/Weierstrass/CachedJac.leangeneralizesheadtoheadAt, which readsZ²andZ³from any two slots, andheadis nowheadAtat P-256's slots. The registration file's notes describe the cache.Proof
PubNaf/CacheBuild.lean:cacheTo_ok. TheZ²andZ³of each of the 8 entries are stored atcacheAt, with the table, the scalar and every other slot of the window kept.PubNaf/Cache.lean:CacheOk(the cache's words areZ²,Z³of each table entry).CacheOk.unch,away_loopW).NafFixed.rebase, which moves the loop's fixed facts to the state after the cache.PubNaf/AddC.lean:addCB_ok. It isjacAddB_ok's contract given slots holdingZ²andZ³ofq.PubNaf/AddCTiming.leangives its timing.PubNaf/Digit.lean,DigitTiming.lean:R.y,R.z(entry_ok,entryFields_ok).CacheOk.PubNaf/Window.lean,WindowTiming.lean: the cache between the table and the loop, branch-free (cache_relCT).PubNafMul,PubNafPoints) places the cache above the table (cacheLayQ) and adds its range to the frame of words the multiplication writes.Performance
Benchmarks run 39094784345, against #2729's head (
1d5a8df9). Its scope is aarch64,cpu_features='- none',modules=ecdsa_p384.VG_CPU_FEATURES=noneecdsa_p384_sha384_verify/64ecdsa_p384_sha384_verify/1024ecdsa_p384_sha384_verify/16384Sign and
ec_p384_public_key, whose code is unchanged, moved by at most 0.1%.llvm-mca, with the multiply and square callees inlined (cycles):
So the cache pays for itself after about 9 additions.
Tests
lake build,Emit.lean --checkand theci/check_*.pyscripts pass. Wycheproof and RFC 6979 P-384 verification (cargo test --release --target aarch64-unknown-linux-gnu -- p384, under qemu) pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01Ma2fA9rUTPXEEQjYyCMCRw