Skip to content

DSA AArch64: key generation checks g^q mod p = 1 once - #4531

Merged
alex merged 1 commit into
mainfrom
claude/perf-4141-dsa-keygen-aarch64
Nov 7, 2026
Merged

alex merged 1 commit into
mainfrom
claude/perf-4141-dsa-keygen-aarch64

Conversation

@alex

@alex alex commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Part of #4141 (finding 4 of the audit). This is #4411's change, ported to AArch64. It changes no Spec/, TCB/ or Rust file.

What was slow

vg_dsa_generate_key checks the domain with vg_dsa_check_parameters. That check's g^q mod p = 1 is one exponentiation modulo p. Key generation then derived the key with vg_dsa_derive_key, which repeated the same check (Checks.signingKey) after computing g^x. So AArch64 key generation did three such exponentiations where two are enough.

What changed

  • Generate.deriveChecked (Impl/Dsa/AArch64/Generate.lean) is a new internal function. It is deriveKey with the signer's cheap checks of g and y (Checks.publicPrefix), minus the g^q exponentiation.
  • Its contract is the existing, already-reviewed deriveKeyDomainCheckedContract (Spec/Dsa/DomainChecked.lean). The proofs are in Proof/Dsa/AArch64/DeriveChecked{,CT,Verified}.lean, translated from x86-64's and from AArch64's own Derive* proofs. keyPrefix_ok gives the exact mask of Checks.publicPrefix. For a domain that passes checkParametersBytes, that mask equals the full checks' mask.
  • Key generation (GenerateKey.code) now calls it as vg_dsa_derive_key_checked. Its proof establishes the precondition from two facts it already tracked: the domain check's result (keygenChecked) and the unchanged domain bytes (keygen_bytes_params). This is the new keygen_derive_checked_pre. vg_dsa_derive_key itself is unchanged; PrivateKey::from_private_components still calls it.
  • Wiring: new Backend fields, filled in Proof/Variants/DsaArithmetic/AArch64/Base.lean, and a one-line change in the generic keygen artifact (Generic/DsaArithmetic/AArch64/Dsa.lean).
  • Proof/Dsa/AArch64/ABIRegions.lean drops public import Mathlib.Algebra.Group.Nat.Defs, which nothing used. Without this, the three new modules (which import it transitively through Derive) would push it past check_lean_speed.py's 40-importer limit for heavy-algebra modules.

The generated code changes only on AArch64: dsa.rs/dsa.s (the call) and the new internal vg_dsa_derive_key_checked.

Numbers

Benchmarks workflow run: aarch64, dsa, groups dsa_generate_key_q[0-9]+.*, with OpenSSL, base = main 0691e88. The runner is Neoverse V2 (CPU part 0xd49).

base head vs base OpenSSL vs OpenSSL base, none head, none vs base, none
dsa_generate_key_q160/1024 194.89 µs 136.37 µs 30.0% faster 130.09 µs about the same 194.49 µs 136.07 µs 30.0% faster
dsa_generate_key_q160/2048 702.69 µs 501.61 µs 28.6% faster 447.39 µs 1.1× slower 710.41 µs 501.35 µs 29.4% faster
dsa_generate_key_q224/2048 1.10 ms 867.96 µs 20.7% faster 574.38 µs 1.5× slower 1.13 ms 849.03 µs 24.9% faster
dsa_generate_key_q256/2048 1.23 ms 996.59 µs 19.2% faster 606.08 µs 1.6× slower 1.26 ms 903.08 µs 28.1% faster
dsa_generate_key_q256/3072 2.68 ms 1.83 ms 31.7% faster 1.31 ms 1.4× slower 2.68 ms 2.14 ms 20.1% faster

AArch64's DSA has only the baseline backend, so the none columns run the same code and serve as a second sample. The two exponentiations left are the spec's: the domain check's g^q mod p = 1 and the public key's g^x mod p. OpenSSL does not check the domain.

My machine is x86-64 (Intel Xeon @ 2.10 GHz), so I could not time AArch64 locally.

Checks

  • lake build (all modules) and Emit.lean --check pass after rebasing on main 0691e88.
  • The Static checks job's steps pass. check_lean_public_imports.py reports the edited modules OK.
  • cargo fmt --check passes, and so does cargo clippy --target aarch64-unknown-linux-gnu --all-targets -- -D warnings.
  • The DSA tests (--lib, tests, cavp, filter dsa) pass for aarch64-unknown-linux-gnu under qemu-user: 28 + 4 + 42. CI runs them on native AArch64.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TKUFHFhuWRWXNwncFAgx4q

vg_dsa_generate_key checks the domain with vg_dsa_check_parameters, whose
g^q mod p = 1 is one exponentiation, and then derived the key with
vg_dsa_derive_key, which repeated that same check after computing g^x.

Port #4411 to AArch64: Generate.deriveChecked, an internal function, is
deriveKey with the signer's cheap checks of g and y (Checks.publicPrefix)
but without the g^q exponentiation, proven against the existing, reviewed
deriveKeyDomainCheckedContract (Spec/Dsa/DomainChecked.lean). Key
generation calls it as vg_dsa_derive_key_checked; its proof establishes
the precondition from the domain check's result and the unchanged domain
bytes. vg_dsa_derive_key itself is unchanged.

ABIRegions no longer imports Mathlib.Algebra.Group.Nat.Defs, which it did
not use: the new modules would otherwise make it a heavy-algebra hub of
more than 40 importers (ci/check_lean_speed.py).

No Spec/ or TCB/ change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHFhuWRWXNwncFAgx4q
@alex

alex commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

where are the benchmark results

alex commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

The Benchmarks run finished a few minutes after I opened the PR. Its table is now in the description. Key generation is 19–32% faster on AArch64 (Neoverse V2). For example, dsa_generate_key_q256/2048 went from 1.23 ms to 997 µs; OpenSSL takes 606 µs.


Generated by Claude Code

@alex
alex added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit d6762a2 Nov 7, 2026
26 checks passed
@alex
alex deleted the claude/perf-4141-dsa-keygen-aarch64 branch November 7, 2026 19:44
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