Repository navigation
brainpoolP256r1 x86-64: sign by a fixed-base comb for any a - #4406
Merged
Merged
Conversation
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
enabled auto-merge
November 7, 2026 08:59
This was referenced Nov 7, 2026
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
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": brainpoolP256r1 signing 1.9× OpenSSL).
What was slow, and why
On x86-64 the Brainpool curves compute
[k]Gwithvg_<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 fora = -3(rcb3m), and Brainpool'sais 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 anya(rcb,3b R mod pstored in the slot of-yafter the negation), as AArch64'sgeneralComb.Impl/Ecdsa/X86_64/CombGeneral.lean:Cfg.combCfgG(the comb witha R mod pfromAP),Cfg.gMulGandCfg.signG:Cfg.signwith[k]Gby that comb.Proof/Ecdsa/X86_64/CombGeneral.lean:generalStep_ok/generalComb_ok, adapted fromtstep_ok/tcomb_okwithrcb_okandLaw.addin place ofrcb3m_ok/Law.add3m; the layout (tcombLayG),gMulG_ok,stage₂GandsignG_ok(assign_ok). Generic over the curve, for brainpoolP384r1/512r1 next.brainpoolp256r1S.signG brainpoolp256r1Comb, from the 7-bit comb tables AArch64, ARMv7 and RISC-V already use (Proof/BrainpoolP256r1/Comb7.leanchecks them): 37 additions. The tables are the new staticVG_BRAINPOOLP256R1_COMB.brainpoolp256r1Sisbrainpoolp256r1with the table as itsgtab(whose tablescombConstslists), so that the signature's contract and RFC 6979's (coreK,specK) declare it, without changing the sharedCfg(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.No change to
TCB/orSpec/. 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):ecdsa_brainpoolp256r1_sha256_sign/64ecdsa_brainpoolp256r1_sha256_sign/1024ecdsa_brainpoolp256r1_sha256_sign/16384ecdsa_brainpoolp256r1_sha256_sign_prehashed/32(The run also covered
VG_CPU_FEATURES=none,sha,ssse3andavx,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 buildof everything the change and the rebasedmainreach,Emit.lean --check, the Static checks steps,check_lean_public_imports.pyon the edited modules,cargo fmt --check,cargo clippy --all-targets -D warnings, andcargo test --releasewith 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