Repository navigation
DSA PPC64LE: key generation checks g^q mod p = 1 once - #4527
Merged
Merged
Conversation
vg_dsa_generate_key checks the domain with vg_dsa_check_parameters, whose g^q mod p = 1 is an exponentiation modulo p by q, then derives the key with vg_dsa_derive_key, whose checkParams repeats that check (checkElem's elemOrder on g) before computing g^x: three such exponentiations. Key generation now derives with vg_dsa_derive_key_checked (Derive.deriveChecked), an internal function: vg_dsa_derive_key with checkDomain for checkParams, the same checks of the domain but g's g^q mod p = 1 (rangeElem: g's load and range check, without elemOrder). It is proven against dcContract, dContract for a domain whose exact octets pass checkParametersBytes, and verified against the existing deriveKeyDomainCheckedContract (Spec/Dsa/DomainChecked.lean). Key generation's proof establishes the precondition from the domain check's result (chkOf) and the unchanged domain octets (Ctx.par). The constant-time proof follows vg_dsa_derive_key's, with the domain's validity as a fact of the public data (KD). vg_dsa_derive_key, which PrivateKey::from_private_components calls, is unchanged. No Spec/ or TCB/ change; the generated PPC64LE crate changes only by the call and the new internal function. Part of #4141. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHH5MNu65G8ZwHFGXrL
alex
enabled auto-merge
November 7, 2026 19:27
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): the PPC64LE port of #4411. This PR changes no
Spec/orTCB/file and no Rust code outside the generated PPC64LE crate.What was slow
vg_dsa_generate_keychecks the domain withvg_dsa_check_parameters, whoseg^q mod p = 1is an exponentiation modulo p by q. Then it derives the key withvg_dsa_derive_key, which on PPC64LE runs the same check again (checkParams→checkElemon g →elemOrder) before it computesg^x. So key generation did three such exponentiations where two are enough.What changed
Derive.deriveChecked(Impl/Dsa/PPC64LE/Derive.lean) is a new internal function, emitted asvg_dsa_derive_key_checked. It isDerive.derivewithcheckDomainin place ofcheckParams.checkDomainruns the same domain checks (sizes, odd p and q,p mod q = 1,1 < g < p) but notg^q mod p = 1:rangeElemloads g and checks its range, withoutelemOrder.Proof/Dsa/PPC64LE/DeriveChecked/):Check.lean:rangeElem_okandcheckDomain_ok. These copycheckElem_okandcheckParams_ok, except thatrestruns exactly whenDomainOkholds (ParamsOkwithoutg^q).Fn.lean:dcContractisdContractfor a domain whose exact octets passcheckParametersBytes.deriveChecked_correctgetsParamsOkfrom that precondition (checkParameters_spec) and reusesdbody_okanddzero_ok.CT.lean: the domain's validity is a fact of the public data (KD), sog^q mod p = 1holds of them (Base.gq), and g's range check leavesparamsTail_rel'sK8.Verified.lean:deriveChecked_verifiedproves it against the existing, reviewedderiveKeyDomainCheckedContract(Spec/Dsa/DomainChecked.lean). The witness isvalidKeyWitness's domain, as in x86-64's.Impl/Dsa/PPC64LE/Generate.lean) callsvg_dsa_derive_key_checked. Its proof (Generate/DeriveCall.lean,Fn.lean,CT.lean) buildsdcContract's precondition from two facts it already tracks: the domain check's result (chkOf s₀ = true) and the unchanged domain octets (Ctx.par).vg_dsa_derive_key, whichPrivateKey::from_private_componentscalls, is unchanged. In the generated PPC64LE crate, only thebltarget invg_dsa_generate_keychanges, plus the new internal function.Numbers
I could not measure locally: my machine is x86-64 (Intel Xeon @ 2.10 GHz), and timings under qemu mean nothing. Benchmarks workflow run (powerpc64;
dsa; groupsdsa_generate_key_q[0-9]+; with OpenSSL; base =mainat ae39a25): the results table will be added here when it finishes.Checks
lake build(all modules) andEmit.lean --checkpass.check_lean_public_imports.pyis OK on the changed modules.check_lean_single_importer.py --base origin/main.powerpc64le-unknown-linux-gnu), the library's DSA tests pass, includingdsa::keygen::tests::cavp_generated_keysand the other key generation tests, and so doescavp::dsa.cargo fmt --checkandcargo clippy --target powerpc64le-unknown-linux-gnu --all-targets -D warningsare clean. I did not run Wycheproof DSA (signature verification, which this does not touch) locally; CI runs it.Generated by Claude Code