Repository navigation
DSA AArch64: key generation checks g^q mod p = 1 once - #4531
Merged
Merged
Conversation
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
Member
Author
|
where are the benchmark results |
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, Generated by Claude Code |
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 (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_keychecks the domain withvg_dsa_check_parameters. That check'sg^q mod p = 1is one exponentiation modulo p. Key generation then derived the key withvg_dsa_derive_key, which repeated the same check (Checks.signingKey) after computingg^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 isderiveKeywith the signer's cheap checks of g and y (Checks.publicPrefix), minus theg^qexponentiation.deriveKeyDomainCheckedContract(Spec/Dsa/DomainChecked.lean). The proofs are inProof/Dsa/AArch64/DeriveChecked{,CT,Verified}.lean, translated from x86-64's and from AArch64's ownDerive*proofs.keyPrefix_okgives the exact mask ofChecks.publicPrefix. For a domain that passescheckParametersBytes, that mask equals the full checks' mask.GenerateKey.code) now calls it asvg_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 newkeygen_derive_checked_pre.vg_dsa_derive_keyitself is unchanged;PrivateKey::from_private_componentsstill calls it.Backendfields, filled inProof/Variants/DsaArithmetic/AArch64/Base.lean, and a one-line change in the generic keygen artifact (Generic/DsaArithmetic/AArch64/Dsa.lean).Proof/Dsa/AArch64/ABIRegions.leandropspublic import Mathlib.Algebra.Group.Nat.Defs, which nothing used. Without this, the three new modules (which import it transitively throughDerive) would push it pastcheck_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 internalvg_dsa_derive_key_checked.Numbers
Benchmarks workflow run:
aarch64,dsa, groupsdsa_generate_key_q[0-9]+.*, with OpenSSL, base =main0691e88. The runner is Neoverse V2 (CPU part 0xd49).nonenonenonedsa_generate_key_q160/1024dsa_generate_key_q160/2048dsa_generate_key_q224/2048dsa_generate_key_q256/2048dsa_generate_key_q256/3072AArch64's DSA has only the baseline backend, so the
nonecolumns run the same code and serve as a second sample. The two exponentiations left are the spec's: the domain check'sg^q mod p = 1and the public key'sg^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) andEmit.lean --checkpass after rebasing onmain0691e88.Static checksjob's steps pass.check_lean_public_imports.pyreports the edited modules OK.cargo fmt --checkpasses, and so doescargo clippy --target aarch64-unknown-linux-gnu --all-targets -- -D warnings.--lib,tests,cavp, filterdsa) pass foraarch64-unknown-linux-gnuunder qemu-user: 28 + 4 + 42. CI runs them on native AArch64.🤖 Generated with Claude Code
https://claude.ai/code/session_01TKUFHFhuWRWXNwncFAgx4q