Skip to content

ML-DSA PPC64LE: prepared keys for many signatures and verifications - #4386

Merged
reaperhulk merged 1 commit into
mainfrom
claude/mldsa-prepared-ppc64le
Nov 7, 2026
Merged

reaperhulk merged 1 commit into
mainfrom
claude/mldsa-prepared-ppc64le

Conversation

@reaperhulk

@reaperhulk reaperhulk commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Follows #4375 (AArch64), #4387 (ARMv7) and #4366 (the specification). It brings verified prepared ML-DSA keys to PPC64LE. There's only a baseline implementation there, so there are no CPU-feature variants to cover. This was stacked on #4387 while both were open; now that #4387 has merged, it's based on main again.

Is it worth it on PPC64LE?

I measured this before writing any code, by counting instructions under QEMU (-one-insn-per-tb). The work a prepared key removes, decoding the key plus its NTTs, is this share of each operation:

44 65 87
sign 9.0% 7.8% n/a
verify 9.4% 8.5% 6.7%

That's somewhat more than AArch64's 4–7%, and the benchmarks below agree.

Verified code (PPC64LE)

  • New registration file: Artifacts/MlDsaPreparedKey/PPC64LE.lean registers vg_mldsa*_prepare_{signing,verifying}_key. Each copies the encoded key with the gathers' doubleword loop, then for each polynomial unpacks it into its slot (vg_mldsa_bit_unpack / vg_mldsa_unpack_t1) and transforms it there (vg_mldsa_ntt).
  • Message functions with prepared keys: MlDsaSignMessage/PPC64LE and MlDsaVerifyMessageCached/PPC64LE now also register vg_mldsa*_{sign,verify}_message_prepared. They use the message functions' existing code, which calls vg_mldsa*_{sign,verify}_prepared.
  • Shared kernels: as on AArch64, the ordinary and prepared μ entries share one kernel per parameter set, vg_mldsa*_sign_with_cache and vg_mldsa*_verify_with_cache. These are internal functions, checked against the untrusted contracts already in Proof/MlDsa/PreparedKeyContract.lean.
    • The kernel keeps the cache pointer and length in r14/r15, saved in frames.
    • When the cache isn't empty, signing copies ŝ₁, ŝ₂ and t̂₀ from it instead of decoding them, and verification copies NTT(t₁·2ᵈ) for each row.
    • The entries are a frame saving the link register, two moves, and a call.
  • Proof structure:
    • Sign: the precondition gains the cache (CPre = SPre ∧ SCache). Its contents survive until decoding by Exec.frameAny.
    • Verify: the invariant VC gains a field that the existing keep lemmas maintain, so it covers the cache polynomials through to each row.
    • Constant time across the new frames comes from narrowing the permissions (relct_frameN, by Exec.widen and determinism). Every new loop is checked with taint_decide.
    • The message proofs are generalized over the key kind (pr : Bool: key length, callee contract, and the prepared-key precondition, which the body's frame keeps).
    • Each prepared contract is shown satisfiable from memory that the verified preparation itself writes (PreparedKey.secret_mem, public_mem).
  • Stack: the ordinary entries now use 240 bytes of stack instead of 96 (the kernel's frames plus the entry's). Their code shrinks, because the bodies now sit once in the internal kernels: mldsa44.s goes from 4,714 to 2,330 lines.
  • Trusted code: nothing in TCB/, Spec/ or Proof/Framework/ changes. There's no sorry, native_decide or bv_decide, and no resource-limit option.

Rust

src/mldsa_common.rs: the prepared key types now store and use the prepared key on all(target_arch = "powerpc64", target_endian = "little") as well, sharing the single-implementation prepare blocks of AArch64, ARM, x86 and RISC-V. The Backend matches stay exhaustive: PPC64LE has only Backend::Scalar. Its baseline functions carry no *_FEATURES constants, so REQUIRED stays empty there. With this PR, every architecture the module compiles for has prepared keys.

Performance (PPC64LE)

Scoped Benchmarks run (arches=powerpc64, modules=mldsa, against main 9ff6f96c). It's one interleaved pass per side, so the numbers are indicative. The rebases since then changed no PPC64LE code.

Prepared vs ordinary, both on this branch:

Ordinary Prepared Faster
44 sign (deterministic) 518.72 µs 464.63 µs 10.4%
65 sign (deterministic) 876.86 µs 791.90 µs 9.7%
44 verify 139.69 µs 122.06 µs 12.6%
65 verify 221.88 µs 198.41 µs 10.6%
  • Ordinary methods vs main (44, 65): within 2.6% either way, covering keygen, deterministic signing, sign_mu, verify, verify_mu and public_key. Hedged sign varies more, because its randomness changes how many times the rejection loop runs.
  • ML-DSA-87: the rows are too noisy on this runner to read either way. On the base side alone, verify measured 545.8 µs against verify_mu's 360.6 µs, though both do the same work, and keygen moves 23% between the two sides with no change to its code. I haven't rerun it to get better numbers.
  • The run's red "Compare with base" gate fires on mldsa*_prepare/verifying: 32 / 46 / 60 ns on main, 18.6 / 27.9 / 37.3 µs here. On main, prepare on PPC64LE only wraps the key; now it decodes and transforms it. That's the one-time cost of the feature, and it pays for itself after one or two verifications. prepare/signing times keygen plus preparation together, so it grows by about 56 / 84 / 126 µs for the same reason.

Validation

  • Lean: the full lake build passes, and Emit.lean --check is clean, its axiom, compiled-code and spec-origin audits included.
  • Every step of the Static checks job passes locally.
  • Rust, PPC64LE cross-compiled under qemu-ppc64le: all 24 ML-DSA integration tests pass, including ACVP prepared and Wycheproof sign_seed_prepared / verify_prepared, with detected features and with VG_CPU_FEATURES=none. They also pass natively on x86-64.
  • cargo clippy --all-targets -D warnings is clean natively and for powerpc64le-unknown-linux-gnu, and cargo fmt --check is clean.
  • CI passed in full on the stacked version, and the diff onto main is identical.

🤖 Generated with Claude Code

https://claude.ai/code/session_015ajQWuKibVLbRQDRNZ3SgM

Copy link
Copy Markdown
Member Author

The red "Compare with base (powerpc64)" check comes from the manual Benchmarks run, and it's the expected cost of this change, not a regression. Its >35% gate fires only on mldsa*_prepare/verifying. On main, prepare on PPC64LE just wraps the key (32–60 ns); with this PR it decodes and transforms the key (18.6–37.3 µs), which is what makes the prepared verifications 10–13% faster. The description's Performance section has the full numbers. I haven't rerun the benchmark.


Generated by Claude Code

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

This pull request has conflicts with main, found after f63cc42 landed on main: rebase it to resolve them. Before rebasing, see CLAUDE.md on checking how much Lean main changed, and on restacking a stacked pull request.

Posted by .github/workflows/conflicts.yml, once per push to a conflicting pull request.

@reaperhulk
reaperhulk force-pushed the claude/mldsa-prepared-ppc64le branch from 4209a03 to 35ae2de Compare November 6, 2026 23:38
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

This pull request has conflicts with main, found after 8b31da4 landed on main: rebase it to resolve them. Before rebasing, see CLAUDE.md on checking how much Lean main changed, and on restacking a stacked pull request.

Posted by .github/workflows/conflicts.yml, once per push to a conflicting pull request.

@reaperhulk
reaperhulk force-pushed the claude/mldsa-prepared-ppc64le branch from 35ae2de to d906cda Compare November 7, 2026 00:06
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

This pull request has conflicts with main, found after 264add2 landed on main: rebase it to resolve them. Before rebasing, see CLAUDE.md on checking how much Lean main changed, and on restacking a stacked pull request.

Posted by .github/workflows/conflicts.yml, once per push to a conflicting pull request.

@reaperhulk
reaperhulk force-pushed the claude/mldsa-prepared-ppc64le branch from d906cda to 53eff68 Compare November 7, 2026 09:04
@reaperhulk
reaperhulk changed the base branch from main to claude/mldsa-prepared-arm November 7, 2026 09:04
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

This pull request has conflicts with claude/mldsa-prepared-arm, found after fce05b0 landed on main: rebase it to resolve them. Before rebasing, see CLAUDE.md on checking how much Lean main changed, and on restacking a stacked pull request.

Posted by .github/workflows/conflicts.yml, once per push to a conflicting pull request.

@reaperhulk
reaperhulk force-pushed the claude/mldsa-prepared-ppc64le branch from 53eff68 to eafcd74 Compare November 7, 2026 09:08
@reaperhulk
reaperhulk added this pull request to stack #4412 November 7, 2026 09:17
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 7, 2026
Base automatically changed from claude/mldsa-prepared-arm to main November 7, 2026 10:03
PPC64LE implementations, verified, of the prepared-key functions whose
specification is Spec/MlDsa/PreparedKey.lean, as AArch64 has them:

* vg_mldsa{44,65,87}_prepare_signing_key and _prepare_verifying_key
  (a new registration file, Artifacts/MlDsaPreparedKey/PPC64LE.lean): the
  encoded key copied, then each of its polynomials unpacked and transformed
  with vg_mldsa_ntt.
* vg_mldsa*_sign_message_prepared and _verify_message_prepared, the message
  functions' code calling vg_mldsa*_sign_prepared and _verify_prepared.

The ordinary and prepared entries share one kernel per parameter set,
vg_mldsa*_sign_with_cache and vg_mldsa*_verify_with_cache (internal, with
their untrusted contracts in Proof/MlDsa/PreparedKeyContract.lean): signing
copies s1, s2 and t0 from the cache instead of decoding them when its length
is nonzero, and verification copies NTT(t1 * 2^d) for each row. The message
proofs are generalized over the key kind, and the prepared contracts'
satisfiability comes from the memory the verified preparation writes.

The Rust prepared key types use these functions on PPC64LE.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWuKibVLbRQDRNZ3SgM
@reaperhulk
reaperhulk force-pushed the claude/mldsa-prepared-ppc64le branch from eafcd74 to 0f40e85 Compare November 7, 2026 10:03
@reaperhulk
reaperhulk enabled stacked auto-merge November 7, 2026 10:06
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit 5edcc5b Nov 7, 2026
38 checks passed
@reaperhulk
reaperhulk deleted the claude/mldsa-prepared-ppc64le branch November 7, 2026 10:26
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