Skip to content

brainpoolP512r1 x86-64: sign by the fixed-base comb for any a - #4413

Merged
alex merged 3 commits into
mainfrom
claude/perf-4141-brainpool-512-sign
Nov 7, 2026
Merged

alex merged 3 commits into
mainfrom
claude/perf-4141-brainpool-512-sign

Conversation

@alex

@alex alex commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Part of #4141 (audit findings).

Stacked on #4406 (its commit ffa15e20 is the first in this branch; I'll restack onto main once it merges). This PR's own changes are the commits after it.

What was slow

brainpoolP512r1 ECDSA signing on x86-64 (prehashed, full features) took 2.15 ms against OpenSSL's 1.19 ms (1.8×). The signature computed [k]G by the ladder of complete additions: 512 doublings and additions. x86-64's comb adds by the complete formulas for a = -3, and brainpoolP512r1's a is not -3.

What changed

  • [k]G now uses brainpoolP256r1 x86-64: sign by a fixed-base comb for any a #4406's comb with the complete addition for any a (Cfg.signG): 74 additions.
  • New 7-bit comb tables for brainpoolP512r1: Impl/BrainpoolP512r1/CombTable7.lean, 74 tables of [m 2^(7j)]G for m = 1 … 64, plus the comb's starting point. I computed them with Python's integers (affine addition, inverses by Fermat). The same script reproduces brainpoolP256r1's existing tables and partial sums exactly.
  • Their kernel-checked certificate, Proof/BrainpoolP512r1/Comb7.lean, built the way P-256's and brainpoolP256r1's are (combChecksW_of_fast, about 3 s). No native_decide.
  • In the generated code, the tables are the static VG_BRAINPOOLP512R1_COMB, which is the signing configuration's gtab. So combConsts, the contract and the RFC 6979 registration list it, as in brainpoolP256r1 x86-64: sign by a fixed-base comb for any a #4406.
  • ECDH, verification and the public key keep the ladder.
  • The P512 proofs are brainpoolP256r1 x86-64: sign by a fixed-base comb for any a #4406's P256 proofs with P512's sizes. Two P512-specific changes:
    • brainpoolp512r1S_sh goes through brainpoolp512r1S.C = brainpoolp512r1.C, because the direct defeq check with the larger table hits the elaborator's recursion limit.
    • The table-length lemma uses brainpoolp512r1S.R rather than the literal 2 ^ 512.
  • No change to shared code (CombGeneral, TCombGeneral), TCB/ or Spec/. Rust is unchanged apart from the regenerated crate.

Numbers

Benchmarks workflow run (x86_64, ecdsa_brainpoolp512r1, the sign groups, base #4406's commit, with OpenSSL). Full features (VG_CPU_FEATURES=avx,avx2,bmi1,bmi2,adx):

Benchmark Base Head Change OpenSSL
ecdsa_brainpoolp512r1_sha512_sign_prehashed/64 2.05 ms 183.65 µs 91.1% faster 1.30 ms (head 7.1× faster)
ecdsa_brainpoolp512r1_sha512_sign/1024 2.05 ms 185.22 µs 91.0% faster 1.43 ms
ecdsa_brainpoolp512r1_sha512_sign/16384 2.08 ms 206.60 µs 90.0% faster 1.33 ms
ecdsa_brainpoolp512r1_sha512_sign/64 4.10 ms 364.91 µs 91.1% faster 1.31 ms

VG_CPU_FEATURES=none gives the same picture: prehashed signing goes from 1.77 ms to 156.22 µs (91.2% faster).

Local run, Intel Xeon @ 2.10 GHz (Sapphire Rapids), ci/bench_compare.py --modules ecdsa_brainpoolp512r1 --openssl against main: prehashed signing goes from 2.04 ms to 182.5 µs (91.1% faster); OpenSSL takes 1.08 ms.

Checks

  • Every step of Static checks passes.
  • check_lean_public_imports.py passes on the edited modules.
  • Full lake build and Emit.lean both pass; the regenerated crate is committed.
  • cargo fmt --check and clippy -D warnings pass.
  • cargo test (Wycheproof) passes, also with VG_CPU_FEATURES=none.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TKUFHGTpD61aE4mEnWpUJP

@alex
alex enabled auto-merge November 7, 2026 09:19
@alex
alex added this pull request to the merge queue Nov 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

This pull request has conflicts with main, found after 8180ba2 landed on main: rebase it to resolve them. Before rebasing, see CLAUDE.md on checking how much Lean main changed, and on restacking a stacked pull request.

Posted by .github/workflows/conflicts.yml, once per push to a conflicting pull request.

@alex
alex force-pushed the claude/perf-4141-brainpool-512-sign branch from 53108cf to 15edc59 Compare November 7, 2026 10:06
@alex
alex added this pull request to the merge queue Nov 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

This pull request has conflicts with main, found after 307122b landed on main: rebase it to resolve them. Before rebasing, see CLAUDE.md on checking how much Lean main changed, and on restacking a stacked pull request.

Posted by .github/workflows/conflicts.yml, once per push to a conflicting pull request.

…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
vg_ecdsa_brainpoolp512r1_sign_k computes [k]G by the comb from the static
VG_BRAINPOOLP512R1_COMB (Emit.lean); and say why the tables' certificate
is a module of its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHGTpD61aE4mEnWpUJP
…1's comb

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHGTpD61aE4mEnWpUJP
@alex
alex force-pushed the claude/perf-4141-brainpool-512-sign branch from 15edc59 to e2bddf6 Compare November 7, 2026 10:39
@alex
alex enabled auto-merge November 7, 2026 10:41
@alex
alex added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit 8266248 Nov 7, 2026
28 checks passed
@alex
alex deleted the claude/perf-4141-brainpool-512-sign branch November 7, 2026 10:57
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