Skip to content

x86-64 vg_ecdsa_p256_verify_ifma: Q's odd multiples kept as limbs - #4983

Merged
alex merged 1 commit into
mainfrom
claude/blissful-faraday-ofi3p6
Nov 12, 2026
Merged

alex merged 1 commit into
mainfrom
claude/blissful-faraday-ofi3p6

Conversation

@alex

@alex alex commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

For each digit of Q's scalar that is not zero, the loop in vectors made the entry of the digit's multiple of Q from the words of the table (convQPieces: words to 52-bit limbs, for the five field elements of an entry). Now the entries of 3Q, …, 15Q are made once, before the loop, and kept as limbs in the working space; a digit loads its entry (seven loads and three vpermq). Q's own entry is still made from its words.

The allocator of the blocks' registers (Impl/P256/X86_64/Ifma/Vec.lean) also aims each value at the register its result is wanted in (wants, AS.getRegFor), which saves register moves at the ends of the blocks: the doubling is 736 instructions for 750, the addition 1,038 for 1,054, the conversion 127 for 138, with the same vpmadd52. The blocks are vg_ecdh_p256_ifma's too, so its generated code changes with them.

vg_ecdsa_p256_verify_ifma is 23,823 instructions for 22,874 (the seven entries' code is written out), 880 of them vpmadd52luq or vpmadd52huq as before; vg_ecdh_p256_ifma is 7,249 for 7,326.

No change to TCB/ or Spec/.

Measurements

Benchmarks run 43134292048, against main (57d3b56734), scoped to what changed (modules=ecdsa_p256 ecdh_p256, groups=ecdsa_p256_.*_verify ecdh_p256, arches=x86_64, cpu_features=-), on an AMD EPYC 9V74 (which has AVX512_IFMA); one run of each side, interleaved:

Benchmark main this branch Change
ecdsa_p256_sha256_verify/64 25.77 µs 24.96 µs 3.1% faster
ecdsa_p256_sha256_verify/1024 26.89 µs 25.82 µs 4.0% faster
ecdsa_p256_sha256_verify/16384 35.20 µs 34.33 µs 2.5% faster
ecdsa_p256_sha384_verify/64 26.11 µs 25.44 µs 2.5% faster
ecdsa_p256_sha384_verify/1024 27.19 µs 26.40 µs 2.9% faster
ecdsa_p256_sha384_verify/16384 46.29 µs 45.55 µs 1.6% faster
ecdh_p256/32 25.51 µs 25.49 µs 0.1% faster

On the machine the proofs were built on (an Emerald Rapids Xeon VM, noisy), a harness that times the verification function alone over 6,000 signatures, taking the least of the runs for each, measures less: 0.6% less time (three runs: 0.61%, 0.64%, 0.65%).

The code

Impl/P256/X86_64/Ifma/Loop.lean:

  • tabEnt c a, for a from 1 to 7: rcx and rdx at the words of entry a + 1 of the table and of its Z² and Z³, convQPieces, then the entry's seven vectors stored (packTPieces, storeEnt): the five of ta, the first four limbs of tb's first lane as one vector, and its fifth. An entry is 200 bytes: the last vector's three other lanes are written over by the next entry.
  • qBody: after the digit's sign, cmp r8, 1; Q's entry as before, any other's from its limbs (entryT, loadAPieces, loadBPieces).
  • regionAt mx: region with the offset of MXCSR's two words a parameter (region := regionAt MX, which vg_ecdh_p256_ifma uses).

The working space's 8,192 bytes, from the table of Q's multiples as words (nine entries, to 3,616): the entries as limbs (TOFF, 3,616, 1,424 bytes); the vectors' slots (SL, 5,056), of which the blocks write nine; the generator's digits (5,344); MXCSR's two words (MXV, 5,864); the table's Z² and Z³ (5,920); the blocks' constants (KB, 6,432, to the end). The selected entry's Z² and Z³, which only Joint.run uses, are in the first two slots, which the vectors' code has left by then (publicJointIfma). vg_ecdh_p256_ifma's slots stay where they were (EO).

The proofs

  • Proof/P256/X86_64/Ifma/Sym.lean: the stores a run of the symbolic execution checks are at offsets of one residue modulo 32 (Par.al, zero for the blocks), so that it runs an entry's stores too, which are 200 bytes apart.
  • Stage.lean, Step.lean, DblOk.lean: a stage's check says how much of the slots its code stores to (chkSegW, KeptW): the nine slots of the joint multiplication's blocks (chkSeg, Kept), whose working space has the generator's digits past them, or the twenty of ECDH's saveAcc.
  • ConvOk.lean: LEnt, what the 25 quadwords of an entry at an address stand for, as EntOk says of the registers; loadA_ok, loadB_ok (an entry loaded) and store_ok, lent_of (an entry stored).
  • Pass.lean: LTab, the seven entries, of the table's words in the same memory; tabEnt_ok, vtab_ok; qEntry_ok with the branch (cmp1_ok, entryT_ok).
  • VLoop.lean, Window.lean: the loop's invariant has LTab (VInv.ltab), which vtabs_ok establishes after vinit_ok; the layout's numbers (vW, VLay).
  • Timing.lean, JointChecks.lean, Config.lean: the taint check of the entries' code (VChecks.tab), and the layouts and checks of publicJointIfma that named the selected entry's and the table's Z² and Z³.

Checks

lake build --log-level=warning and lake env lean --run Emit.lean: the regenerated x86-64 crate changes only ecdsa_p256 and ecdh_p256. Every step of the Static checks job, ci/check_lean_public_imports.py on the modules changed, cargo fmt --check, cargo clippy --all-targets -- -D warnings, and cargo test --release of the P-256, ECDSA and ECDH tests with Wycheproof on a CPU with AVX512_IFMA, where the dispatchers run the two functions.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TKUFHFEUkKJRQvsEBN9oBp

The loop in vectors made the entry of a digit's multiple of Q from the
words of the table for each digit of Q's scalar that is not zero. The
entries of 3Q, ..., 15Q are now made once, before the loop, and kept as
limbs in the working space (tabEnt): a digit loads its entry (loadAPieces,
loadBPieces). Q's own is still made from its words.

The allocator of the blocks' registers aims each value at the register
its result is wanted in (wants), which saves moves at the ends of the
blocks; vg_ecdh_p256_ifma has the same blocks, so its code changes too.

The working space's layout (publicJointIfma, SL, MXV, KB, TOFF) makes
room for the entries; ECDH's slots stay where they were (EO).

Proofs: the symbolic execution's stores are at offsets of one residue
modulo 32 (Par.al); a stage's check says how much of the slots its code
stores to (chkSegW, KeptW); LEnt, LTab and the lemmas of an entry stored
and loaded (ConvOk, Pass); the loop's invariant has the entries (VInv.ltab,
vtabs_ok); the layouts and taint checks of publicJointIfma.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHFEUkKJRQvsEBN9oBp
@github-actions github-actions Bot added the untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified. label Nov 12, 2026
@alex
alex added this pull request to the merge queue Nov 12, 2026
Merged via the queue into main with commit 82dcd68 Nov 12, 2026
36 checks passed
@alex
alex deleted the claude/blissful-faraday-ofi3p6 branch November 12, 2026 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified.

Development

Successfully merging this pull request may close these issues.

2 participants