Skip to content

DSA PPC64LE: key generation checks g^q mod p = 1 once - #4527

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

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

Conversation

@alex

@alex alex commented Nov 7, 2026

Copy link
Copy Markdown
Member

Part of #4141 (finding 4 of the audit): the PPC64LE port of #4411. This PR changes no Spec/ or TCB/ file and no Rust code outside the generated PPC64LE crate.

What was slow

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 it derives the key with vg_dsa_derive_key, which on PPC64LE runs the same check again (checkParams → checkElem on g → elemOrder) before it computes g^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 as vg_dsa_derive_key_checked. It is Derive.derive with checkDomain in place of checkParams. checkDomain runs the same domain checks (sizes, odd p and q, p mod q = 1, 1 < g < p) but not g^q mod p = 1: rangeElem loads g and checks its range, without elemOrder.
  • Proofs (Proof/Dsa/PPC64LE/DeriveChecked/):
    • Check.lean: rangeElem_ok and checkDomain_ok. These copy checkElem_ok and checkParams_ok, except that rest runs exactly when DomainOk holds (ParamsOk without g^q).
    • Fn.lean: dcContract is dContract for a domain whose exact octets pass checkParametersBytes. deriveChecked_correct gets ParamsOk from that precondition (checkParameters_spec) and reuses dbody_ok and dzero_ok.
    • CT.lean: the domain's validity is a fact of the public data (KD), so g^q mod p = 1 holds of them (Base.gq), and g's range check leaves paramsTail_rel's K8.
    • Verified.lean: deriveChecked_verified proves it against the existing, reviewed deriveKeyDomainCheckedContract (Spec/Dsa/DomainChecked.lean). The witness is validKeyWitness's domain, as in x86-64's.
  • Key generation (Impl/Dsa/PPC64LE/Generate.lean) calls vg_dsa_derive_key_checked. Its proof (Generate/DeriveCall.lean, Fn.lean, CT.lean) builds dcContract'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, which PrivateKey::from_private_components calls, is unchanged. In the generated PPC64LE crate, only the bl target in vg_dsa_generate_key changes, 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; groups dsa_generate_key_q[0-9]+; with OpenSSL; base = main at ae39a25): the results table will be added here when it finishes.

Checks

  • lake build (all modules) and Emit.lean --check pass. check_lean_public_imports.py is OK on the changed modules.
  • Every step of the Static checks job passes, with check_lean_single_importer.py --base origin/main.
  • Under qemu-ppc64le (powerpc64le-unknown-linux-gnu), the library's DSA tests pass, including dsa::keygen::tests::cavp_generated_keys and the other key generation tests, and so does cavp::dsa. cargo fmt --check and cargo clippy --target powerpc64le-unknown-linux-gnu --all-targets -D warnings are clean. I did not run Wycheproof DSA (signature verification, which this does not touch) locally; CI runs it.

Generated by Claude Code

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
@github-actions github-actions Bot added the untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified. label Nov 7, 2026
@alex
alex enabled auto-merge November 7, 2026 19:27
@alex
alex added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit 31e169a Nov 7, 2026
23 checks passed
@alex
alex deleted the claude/perf-4141-dsa-keygen-ppc64le branch November 7, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified.

Development

Successfully merging this pull request may close these issues.

2 participants