Skip to content

brainpoolP256r1 x86-64: verify with [u]G by the signature's comb - #4414

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

alex merged 1 commit 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": brainpoolP256r1 verification 1.1× OpenSSL). Built on #4406 (merged), whose comb this uses. #4418 (brainpoolP512r1) and the brainpoolP384r1 verification build on this PR's generic code.

What was slow, and why

On x86-64, Brainpool verification computes [u]G and [v]Q with two calls of vg_<curve>_mul. That function is a bit-by-bit ladder of complete additions: one doubling and one addition per scalar bit, for each scalar. I measured one call at about half of a verification (brainpoolP512r1: one ladder is ~2.1 ms, verification is 4.1 ms). #4406 found that BMI2/ADX field arithmetic speeds the ladder up by only 10–20%, so the cost is in the algorithm, not in the multiplications.

What changed

  • Impl/Ecdsa/Verify/X86_64/CombGeneral.lean: Cfg.verifyG d is Cfg.verify except for one step. [u]G comes from brainpoolP256r1 x86-64: sign by a fixed-base comb for any a #4406's comb for any a (Cfg.gMulG d: 37 complete additions for brainpoolP256r1, not 512). [v]Q keeps the ladder (mulV: inline, constant time).
  • Proof/Ecdsa/Verify/X86_64/CombGeneral.lean: pointsG_ok is pointsL_ok's proof with [u]G by gMulG_ok', its tables found through the configuration's gtab (tbl_of_held_mem). verifyG_ok is verify_ok's proof with pointsG_ok. Both are generic over the curve.
  • brainpoolP256r1: verifyBrainpoolP256r1 := Cfg.verifyG brainpoolp256r1S brainpoolp256r1Comb. Its contract (Proof/Ecdsa/Verify/X86_64/BrainpoolP256r1/Contract.lean) now declares the comb's tables (Abi.withConsts brainpoolp256r1S.combConsts, the static VG_BRAINPOOLP256R1_COMB), following P-224's verification contract. The satisfiability witness holds the tables at 0x100000.
  • Constant time: by taint tracking, as before (taintSym_eraseInv). The comb scans its entries as the signature does, so only the pointers and the table's address affect timing.

No change to TCB/ or Spec/. No new variant, and no Rust source changed: only the generated ecdsa_brainpoolp256r1 files.

Numbers

Local, Intel(R) Xeon(R) Processor @ 2.10GHz (BMI2/ADX/AVX-512 IFMA), cargo bench, all features:

benchmark before (#4406) this PR OpenSSL
ecdsa_brainpoolp256r1_sha256_verify_prehashed/32 595.9 µs 329.6 µs 591–629 µs
ecdsa_brainpoolp256r1_sha256_verify/64 — 354.2 µs 628.0 µs
ecdsa_brainpoolp256r1_sha256_verify/16384 — 432.3 µs 629.0 µs

Benchmarks workflow (x86_64, ecdsa_brainpoolp256r1 verify groups, with OpenSSL, against #4406's head ffa15e2; it measured this commit before the rebase onto main, which changes no brainpoolP256r1 code): https://github.com/pyca/verified-garbage/actions/runs/42359526499

The next step for verification is [v]Q, the remaining ladder. A public-scalar joint or window method for any a would need a Jacobian doubling for any a in x86-64's joint framework (JDblOk, which currently has no hypothesis on the slot of a). That is a separate change.

Checks

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

🤖 Generated with Claude Code

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 force-pushed the claude/perf-4141-brainpool-verify branch from 638278e to 19d9427 Compare November 7, 2026 09:26
@alex
alex changed the base branch from claude/perf-4141-brainpool-ecdsa to claude/perf-4141-brainpool-512-sign November 7, 2026 09:26
@alex
alex force-pushed the claude/perf-4141-brainpool-512-sign branch from 53108cf to 15edc59 Compare November 7, 2026 10:06
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
@alex
alex force-pushed the claude/perf-4141-brainpool-verify branch from 19d9427 to b00bbb7 Compare November 7, 2026 10:20
@github-actions github-actions Bot removed the untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified. label Nov 7, 2026
@alex
alex changed the base branch from claude/perf-4141-brainpool-512-sign to main November 7, 2026 10:20
@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 10:22
@alex
alex added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit b3e2ba9 Nov 7, 2026
39 of 40 checks passed
@alex
alex deleted the claude/perf-4141-brainpool-verify branch November 7, 2026 10:39
alex added a commit that referenced this pull request Nov 7, 2026
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/.


Claude-Session: https://claude.ai/code/session_01TKUFHEXYPYjjPyLdLUmbW1

Co-authored-by: Claude <noreply@anthropic.com>
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