Repository navigation
Brainpool x86-64: verify with [v]Q by windows for any a - #4517
Merged
Merged
Conversation
Verification computed [u]G and [v]Q by two calls of vg_brainpoolp256r1_mul, the ladder of complete additions, 256 doublings and additions each. Compute [u]G by the signature's fixed-base comb for any a instead (Cfg.gMulG, from VG_BRAINPOOLP256R1_COMB: 37 additions), and keep the ladder for [v]Q: Cfg.verifyG (Impl/Ecdsa/Verify/X86_64/CombGeneral.lean), with its proof verifyG_ok (Proof/Ecdsa/Verify/X86_64/CombGeneral.lean), verify_ok's with pointsG_ok, which is pointsL_ok's with gMulG_ok'. The contract declares the comb's tables (Abi.withConsts brainpoolp256r1S.combConsts), as P-224's does; the entries are scanned in constant time, and only the pointers and the tables' address affect timing. No change to TCB/ or Spec/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHEXYPYjjPyLdLUmbW1
…not yet regenerated) Verification computed [v]Q by the ladder of complete additions. Compute it by ECDH's signed 4-bit windows instead, for any a: WinCfg.windowA (Impl/Weierstrass/X86_64/WindowGeneral.lean), window's code with the complete addition for any a (rcb, 3b R mod p from B3P) and the Jacobian doubling for any a (dblJGen, dblJa's operations). Its proof (Proof/Weierstrass/X86_64/WindowGeneral.lean) is window_ok's, with the lemmas that see the formulas copied: WinFixedA (3b in S.b3), Law.add for the additions and InvJ.dblA' (a from the slot S.a) for the doublings. Cfg.verifyG's points now use it (mulVA, winMulA_ok, mulVA_ok), for the three Brainpool curves (c.n <= 9). No change to TCB/ or Spec/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHEXYPYjjPyLdLUmbW1
… for any a in its own module The formulas of the doubling for any a (dblAF, InvJ.dblA, InvJ.dblA') move from Proof/Weierstrass/JacDblA.lean, which imports RISC-V's code, to the target-independent Proof/Weierstrass/JacDblAF.lean, so that the x86-64 window proof (which numbers its own dblJGen: dblJGenN_run) imports no other target's module. JacDblA keeps RISC-V's dblJaN. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHEXYPYjjPyLdLUmbW1
alex
enabled auto-merge
November 7, 2026 18:24
6 tasks done
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 #4141 (findings: #4141 (comment), "Brainpool ECDSA"). Follows #4414/#4433/#4418, which compute
[u]Gby the signing comb. It closes the remaining brainpoolP512r1 gap (2.21 ms against OpenSSL's 1.78 ms after #4418).What was slow, and why
After #4414, the x86-64 Brainpool verification (
Cfg.verifyG) still computed[v]Qby the ladder of complete additions: one doubling and one addition per bit, 17 field products each. The window method that ECDH and the other curves use (WinCfg.window) is written fora = -3: its doubling isdblJX/dblJMul, and its additions arercb3.What changed
Impl/Weierstrass/X86_64/WindowGeneral.lean(new):WinCfg.windowA,window's code (the recoding, the table[1 … 8]P, constant-time selection and negation of entries,Y = 1whereZ = 0) with two changes:a(rcb,3 b R mod pinS.b3);a, dbl-2007-bl (dblJGen, the operations of RISC-V'sdblJa,aread fromS.a).Proof/Weierstrass/X86_64/WindowGeneral.lean(new):windowA_ok,window_ok's proof. The lemmas that see the formulas are copied here, with these changes:WinFixedAisWinFixedwith3binS.b3;Law.addinstead ofLaw.add3;InvJ.dblA', whoseais the loop environment's slotS.a.Everything else is
window's lemmas, unchanged. I did not edit the shared window files: the Impl one is imported by 524 modules.Proof/Weierstrass/JacDblAF.lean(new, moved):dblAF,InvJ.dblAandInvJ.dblA'move out ofJacDblA.lean, which imports RISC-V's code. That way the x86-64 proof imports no other target's module (check_lean_imports.py).JacDblAkeeps RISC-V'sdblJaNand re-exports the moved lemmas. No statement changed.Impl/Proof/Ecdsa/Verify/X86_64/CombGeneral.lean:Cfg.mulVAcomputes[v]QbywindowAon ECDH'sPX,PY, withB3Pfor3b(winQA, its layoutwinLayQAaswinLayQ, andwinMulA_okaswinMul_ok).pointsG/verifyGuse it instead of the ladder, so all three Brainpool curves get it. Their proofs now takec.n ≤ 9, which eachVerified.leanpassesby decide.vis public, but the windows run in constant time anyway. Timing is still proved by taint tracking over the whole function, so only the pointers and the comb table's address affect it.No change to
TCB/orSpec/. No new variant, and no Rust source changed: only the generatedecdsa_brainpoolp{256,384,512}r1files.Numbers
Local,
Intel(R) Xeon(R) Processor @ 2.10GHz,cargo bench, all features:ecdsa_brainpoolp256r1_sha256_verify_prehashed/32ecdsa_brainpoolp384r1_sha384_verify_prehashed/48ecdsa_brainpoolp512r1_sha512_verify_prehashed/64ecdsa_brainpoolp512r1_sha512_verify/16384Benchmarks workflow (x86_64, the three modules' verify groups, all features, with OpenSSL, against
4d9b18b, this branch's base): https://github.com/pyca/verified-garbage/actions/runs/42400878714Checks
These pass:
lake build(all modules) andEmit.lean --checkcheck_lean_public_imports.pyon the edited modulescargo test --releaseof the brainpool tests with Wycheproof🤖 Generated with Claude Code
https://claude.ai/code/session_01TKUFHEXYPYjjPyLdLUmbW1