Repository navigation
AArch64 P-256 verify: double with ECDH's fused doubling - #2690
Merged
Merged
Conversation
The fused doubling's raw proof is generalized over the slot predicate and live slots, so verify's joint loop reuses ECDH's certificate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ma2fA9rUTPXEEQjYyCMCRw
…ertificate 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.
On AArch64,
vg_ecdsa_p256_verify's joint loop now doubles withImpl.P256.EcdhDouble.program, the doublingvg_ecdh_p256already uses. It uses five squares and three products, and reduces each linear combination (12a − 9b,4a − b,3a − 8b) once. The old unfused doubling used four squares, four products and twelve separately reduced additions and subtractions. ECDH's doubling is in place on the same accumulator slots. Its certificate was already checked against verify's observation set and work regions (VerifyAllocated.observe .doubleRR,VerifyAllocated.work), so it drops in.Proof
Proof/P256/EcdhDouble/):weakMul_ok,linearField_ok,linear41Field_okandinv_keep_unusednow take any slot predicate with itsLayandAlignedfacts, instead of ECDH's.rawR_okproves the raw fused doubling from the accumulator alone.raw_okextends it to any live list holdingR; slots it doesn't write are kept, byProgKeepand the layout.result_ofrelates the raw result torunOps (operations .doubleRR)on any such live list.AllocatedArithmetic):double_field_okanddouble_okproveEcdhDouble.programon the joint loop'sjointLivewith the same postcondition as before, through ECDH's certificate.Certificate.ct(FieldCT) throughfieldWP_relCT.VerifyAllocatedCode, its certificate (Proof/P256/VerifyAllocated/Double.lean) and itsDouble_ct, along with its entry inGenerateP256Verify.lean.No change to
TCB/,Spec/or any contract. Onlysrc/asm/aarch64/ecdsa_p256.rschanges: verify's loop body, and its note inGeneric/P256/AArch64/EcdsaP256.lean.Benchmarks
This PR's Benchmarks check ran on N2 (Neoverse N2,
0xd49), comparing against main.sha3noneecdsa_p256_sha256_verify/64ecdsa_p256_sha256_verify/1024ecdsa_p256_sha256_verify/16384ecdsa_p256_sha384_verify/64ecdsa_p256_sha384_verify/1024ecdsa_p256_sha384_verify/16384Every sign row and
ec_p256_public_keymoves between −0.3% and +0.0%; their code is byte-identical to main (unchanged code / placement).verify/64against aws-lc-rs's 52.24 µs on N2 goes from 0.94× to 0.91×.Doubling alone on N2: 256 doublings, timed on a throwaway branch that will never be merged (run 39072614399). The blocks are copied from the generated code.
p256_montjdouble_alt(call overhead included)llvm-mca, cycles per doubling (200 iterations of each block). This PR can't be benchmarked on Apple, so llvm-mca stands in for it:
apple-m1neoverse-n2llvm-mca's N2 model gets the direction wrong: N2 measured −5.8% on the doubling and −3.8% on verify. So llvm-mca's M1 prediction is supporting evidence only.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Ma2fA9rUTPXEEQjYyCMCRw