Skip to content

Brainpool x86-64: verify with [v]Q by windows for any a - #4517

Merged
alex merged 5 commits into
mainfrom
claude/perf-4141-brainpool-verify
Nov 7, 2026
Merged

alex merged 5 commits into
mainfrom
claude/perf-4141-brainpool-verify

Conversation

@alex

@alex alex commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Part of #4141 (findings: #4141 (comment), "Brainpool ECDSA"). Follows #4414/#4433/#4418, which compute [u]G by 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]Q by 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 for a = -3: its doubling is dblJX/dblJMul, and its additions are rcb3.

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 = 1 where Z = 0) with two changes:

    • the additions are the complete ones for any a (rcb, 3 b R mod p in S.b3);
    • the four doublings per digit are the Jacobian doubling for any a, dbl-2007-bl (dblJGen, the operations of RISC-V's dblJa, a read from S.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:

    • WinFixedA is WinFixed with 3b in S.b3;
    • the additions end in Law.add instead of Law.add3;
    • the doublings end in InvJ.dblA', whose a is the loop environment's slot S.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.dblA and InvJ.dblA' move out of JacDblA.lean, which imports RISC-V's code. That way the x86-64 proof imports no other target's module (check_lean_imports.py). JacDblA keeps RISC-V's dblJaN and re-exports the moved lemmas. No statement changed.

  • Impl/Proof/Ecdsa/Verify/X86_64/CombGeneral.lean: Cfg.mulVA computes [v]Q by windowA on ECDH's PX, PY, with B3P for 3b (winQA, its layout winLayQA as winLayQ, and winMulA_ok as winMul_ok). pointsG/verifyG use it instead of the ladder, so all three Brainpool curves get it. Their proofs now take c.n ≤ 9, which each Verified.lean passes by decide. v is 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/ or Spec/. No new variant, and no Rust source changed: only the generated ecdsa_brainpoolp{256,384,512}r1 files.

Numbers

Local, Intel(R) Xeon(R) Processor @ 2.10GHz, cargo bench, all features:

benchmark before (main) this PR OpenSSL
ecdsa_brainpoolp256r1_sha256_verify_prehashed/32 330 µs 144 µs 521 µs
ecdsa_brainpoolp384r1_sha384_verify_prehashed/48 1.02 ms 0.469 ms 1.09 ms
ecdsa_brainpoolp512r1_sha512_verify_prehashed/64 2.21 ms 1.18 ms 1.88 ms
ecdsa_brainpoolp512r1_sha512_verify/16384 2.31 ms 1.25 ms 1.88 ms

Benchmarks 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/42400878714

Checks

These pass:

  • lake build (all modules) and Emit.lean --check
  • every Static checks step
  • check_lean_public_imports.py on the edited modules
  • cargo test --release of the brainpool tests with Wycheproof

🤖 Generated with Claude Code

https://claude.ai/code/session_01TKUFHEXYPYjjPyLdLUmbW1

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
@github-actions github-actions Bot added the untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified. label Nov 7, 2026
@alex
alex enabled auto-merge November 7, 2026 18:24
@alex
alex added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit 7d84a13 Nov 7, 2026
35 checks passed
@alex
alex deleted the claude/perf-4141-brainpool-verify branch November 7, 2026 18:59
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