Skip to content

brainpoolP256r1 x86-64: sign by a fixed-base comb for any a - #4406

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

alex merged 1 commit into
mainfrom
claude/perf-4141-brainpool-ecdsa

Conversation

@alex

@alex alex commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Part of #4141 (findings: #4141 (comment), "Brainpool ECDSA": brainpoolP256r1 signing 1.9× OpenSSL).

What was slow, and why

On x86-64 the Brainpool curves compute [k]G with vg_<curve>_mul, the ladder of complete additions: per scalar bit one doubling and one addition (34 field products), 256 bits for brainpoolP256r1. Under callgrind the ladder is 87% of a signature's instructions; the inversions are about 1% each. P-256/P-384 avoid it with a comb, but x86-64's comb (TCombCfg.comb) adds by the complete formulas for a = -3 (rcb3m), and Brainpool's a is not -3. Field arithmetic is not the problem: a throwaway BMI2/ADX (adx := true) build of the ladder was only 10–20% faster.

What changed

  • Impl/Weierstrass/X86_64/TCombGeneral.lean: TCombCfg.generalComb, the x86-64 comb with the complete addition for any a (rcb, 3b R mod p stored in the slot of -y after the negation), as AArch64's generalComb.
  • Impl/Ecdsa/X86_64/CombGeneral.lean: Cfg.combCfgG (the comb with a R mod p from AP), Cfg.gMulG and Cfg.signG: Cfg.sign with [k]G by that comb.
  • Proof/Ecdsa/X86_64/CombGeneral.lean: generalStep_ok/generalComb_ok, adapted from tstep_ok/tcomb_ok with rcb_ok and Law.add in place of rcb3m_ok/Law.add3m; the layout (tcombLayG), gMulG_ok, stage₂G and signG_ok (as sign_ok). Generic over the curve, for brainpoolP384r1/512r1 next.
  • brainpoolP256r1: the signature is brainpoolp256r1S.signG brainpoolp256r1Comb, from the 7-bit comb tables AArch64, ARMv7 and RISC-V already use (Proof/BrainpoolP256r1/Comb7.lean checks them): 37 additions. The tables are the new static VG_BRAINPOOLP256R1_COMB. brainpoolp256r1S is brainpoolp256r1 with the table as its gtab (whose tables combConsts lists), so that the signature's contract and RFC 6979's (coreK, specK) declare it, without changing the shared Cfg (which ~500 modules import). The contract (Proof/Ecdsa/X86_64/BrainpoolP256r1/Contract.lean) now has the table's region; the registration requires the table's name to be apart from the HMAC tables', as P-256's does.
  • ECDH, verification and the public key keep the ladder.

No change to TCB/ or Spec/. No new variant (the comb is baseline x86-64), so the README tables are unchanged.

Numbers

Benchmarks workflow, x86_64, against 0e0724b (https://github.com/pyca/verified-garbage/actions/runs/42357686153, default features):

Benchmark Base Head Change OpenSSL Head vs OpenSSL
ecdsa_brainpoolp256r1_sha256_sign/64 238.80 µs 24.95 µs 89.6% faster 346.92 µs 13.9× faster
ecdsa_brainpoolp256r1_sha256_sign/1024 239.19 µs 25.49 µs 89.3% faster 347.14 µs 13.6× faster
ecdsa_brainpoolp256r1_sha256_sign/16384 247.70 µs 33.95 µs 86.3% faster 354.13 µs 10.4× faster
ecdsa_brainpoolp256r1_sha256_sign_prehashed/32 477.00 µs 49.23 µs 89.7% faster 340.38 µs 6.9× faster

(The run also covered VG_CPU_FEATURES=none, sha,ssse3 and avx,avx2,bmi1,bmi2,adx; the code chosen doesn't depend on them.)

Local, Intel(R) Xeon(R) Processor @ 2.1GHz, cargo bench: sign/64 359.5 → 28.9 µs (OpenSSL 368.7 µs), sign_prehashed/32 680.4 → 60.6 µs (OpenSSL 343.5 µs).

Checks

lake build of everything the change and the rebased main reach, Emit.lean --check, the Static checks steps, check_lean_public_imports.py on the edited modules, cargo fmt --check, cargo clippy --all-targets -D warnings, and cargo test --release with Wycheproof (brainpool ECDSA sign→verify, RFC 7027) pass. No Rust source changed.

Follow-ups (stacked locally, as separate PRs once this merges): brainpoolP384r1 and brainpoolP512r1 signing by the same comb, with new tables checked in the kernel (locally 1117 → 94 µs and 2415 → 206 µs prehashed), then verification.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TKUFHFtUGDUpzkcbWbx7P7

The x86-64 signature computed [k]G by the ladder of complete additions,
256 doublings and additions of 17 products each, since x86-64's comb
adds by the complete formulas for a = -3 and brainpoolP256r1's a is not
-3. Add TCombCfg.generalComb, the comb with the complete addition for any
a (rcb, with 3b R mod p in the slot of -y, as AArch64's generalComb), its
proof (generalComb_ok, from tcomb_ok's), and Cfg.signG, the signature
with [k]G by it, from the 7-bit comb tables AArch64, ARMv7 and RISC-V
already use (Proof/BrainpoolP256r1/Comb7.lean checks them): 37 additions.
The tables are the static VG_BRAINPOOLP256R1_COMB, which the signing
configuration declares as its gtab, so that combConsts and the RFC 6979
contract list it. ECDH, verification and the public key keep the ladder.

No change to TCB/ or Spec/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHFtUGDUpzkcbWbx7P7
@alex
alex enabled auto-merge November 7, 2026 08:59
@alex
alex added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit f8911ef Nov 7, 2026
33 checks passed
@alex
alex deleted the claude/perf-4141-brainpool-ecdsa branch November 7, 2026 09:48
alex pushed a commit that referenced this pull request Nov 7, 2026
…rate not yet regenerated)

The 7-bit comb tables for brainpoolP512r1 (74 tables of 64 points, with
their kernel-checked certificate, Proof/BrainpoolP512r1/Comb7.lean) and
the signature's [k]G by #4406's general-a comb (Cfg.signG).

No change to TCB/ or Spec/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHGTpD61aE4mEnWpUJP
alex pushed a commit that referenced this pull request Nov 7, 2026
…rate not yet regenerated)

The 7-bit comb tables for brainpoolP512r1 (74 tables of 64 points, with
their kernel-checked certificate, Proof/BrainpoolP512r1/Comb7.lean) and
the signature's [k]G by #4406's general-a comb (Cfg.signG).

No change to TCB/ or Spec/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHGTpD61aE4mEnWpUJP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants