Skip to content

Automatically prepare reused ML-DSA keys on AArch64 - #3819

Closed
reaperhulk wants to merge 13 commits into
codex/mldsa-prepared-key-specsfrom
codex/arm64-mldsa-auto-cache
Closed

reaperhulk wants to merge 13 commits into
codex/mldsa-prepared-key-specsfrom
codex/arm64-mldsa-auto-cache

Conversation

@reaperhulk

@reaperhulk reaperhulk commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Repeated ML-DSA operations currently unpack and transform the same key polynomials on every call. On AArch64 with alloc, this change keeps the existing API and attempts to prepare an immutable polynomial cache on the second valid-context operation. Signing and verification each have their own cache; message and external-μ methods share their key's counter. No allocation is attempted on the first operation. Without alloc, the existing compact path remains available.

Stacked on #3806, which defines the prepared-key and shared-kernel contracts. This implementation adds no TCB instructions, axioms, or weakened contracts. Every new assembly entry is generated from Lean and has correctness, constant-time, ABI, and satisfiability proofs, including the preparers and the complete message/context wrappers. Ordinary and prepared entries call a shared arithmetic kernel for each parameter set and Keccak backend. The Rust publication protocol is tested separately.

One caller claims preparation. Concurrent callers continue on the compact path while it runs; allocation failure or an unwinding initializer is not retried. Published storage is immutable and freed only under exclusive ownership. Verifying-key clones start cold, equality ignores cache state, and cached secret bytes are wiped before deallocation. The encoded key bytes and existing cached public-key digest retain their meanings.

M1 Max production measurements

Three interleaved baseline/candidate comparisons against main d1dad5ab69c1ffba88b1ec720d3d601ffa1cd367, using Rust 1.99.0 / LLVM 23.1.1 and detected CPU features. Each reported lifetime includes construction, all operations, and destruction; each run uses 16 timed samples and a fixed 32-key workload. Values below are medians of the three run medians, in microseconds per 100-operation key lifetime.

Operation Main This PR Latency reduction
ML-DSA-44 sign 4049.156 3763.958 7.04%
ML-DSA-65 sign 5398.417 4965.677 8.02%
ML-DSA-87 sign 8549.989 8008.708 6.33%
ML-DSA-44 verify 1364.521 1274.458 6.60%
ML-DSA-65 verify 2175.834 2041.177 6.19%
ML-DSA-87 verify 3600.354 3417.583 5.08%

At eight operations per lifetime, reductions are 2.97–3.98%. Four operations are near break-even (0.82–1.20% lower medians). One operation stays within ±0.23%; two operations cost 3.28–4.14% more because they pay for preparation. These are repeated workload measurements, not confidence intervals or a promise of a universal break-even count.

Four shared-key workers doing 32 operations each also have lower M1 median times in all 12 cold/warm cases (1.85–10.83%). This short concurrency workload is reported separately from single-thread lifetimes.

The measurement binary's __text increases by 24,000 bytes; its page-rounded __TEXT segment increases by 32 KiB (671,744 → 704,512 bytes). Each cache adds 16 bytes of object metadata. Successful preparation allocates, including alignment: public keys 5,440 / 8,128 / 10,816 bytes; secret keys 14,848 / 21,440 / 28,480 bytes for 44 / 65 / 87. Storage is allocated independently for signing and verification, and includes an encoded-key prefix.

Validation

  • Rebased onto current main and restored its 1,193,459,829-byte CI Lean cache (27,603 modules; cache revision a97cae098, whose Lean tree matches the rebased main).
  • Full Lean build: 27,830 jobs; full emission/check and standard-axiom, compiler-override, and spec-origin audits pass.
  • All 13 source audits and the edited-module public-import audit pass; formatting and Clippy with warnings denied pass.
  • Native M1 detected/scalar configurations each pass 330 unit and 437 integration tests, including published ACVP/Wycheproof vectors. The no-allocation configuration passes 182 unit and 386 integration tests.
  • The CPU-feature ML-DSA group explicitly selects the cache API tests in mldsa44, mldsa65, and mldsa87, alongside mldsa_common. CI’s selected 20 unit tests pass locally in detected/scalar modes. Merging their coverage with the original CI artifacts gives 100% for every architecture (AArch64: 22,441/22,441 lines). This corrects the initial coverage failure caused by omitting the parameterized test modules from the group. The fresh CI Rust coverage job now passes, including 100% coverage for every architecture.
  • Tests cover cross-method promotion, ordinary/prepared equivalence, invalid signatures/contexts, concurrent shared-key use, cold clones/equality, fallible allocation, a busy or panicking initializer, and secret wiping at actual deallocation.

Neoverse N2 production measurements

Native comparison run, head abd2a0050c6a36079dff03a3d3a13fcb21b1eb78, base d1dad5ab69c1ffba88b1ec720d3d601ffa1cd367. CPU implementer 0x41, part 0xd49 (Neoverse N2), detected features including SHA3 and SVE2; Rust 1.99.1. This table uses the median of three interleaved Criterion median estimates per side, rather than the workflow summary's fastest run. Measurements are short: 25 samples and approximately 0.3 seconds per run, after 0.1 seconds warm-up. AWS-LC runs once for reference. Times are microseconds per operation on reused keys.

Operation Main This PR Reduction vs main AWS-LC Reduction vs AWS-LC
ML-DSA-44 sign 107.155 101.905 4.90% 126.803 19.64%
ML-DSA-65 sign 164.949 154.851 6.12% 194.069 20.21%
ML-DSA-87 sign 205.680 193.092 6.12% 254.445 24.11%
ML-DSA-44 verify 35.315 33.316 5.66% 39.324 15.28%
ML-DSA-65 verify 57.320 54.325 5.22% 66.293 18.05%
ML-DSA-87 verify 96.941 92.994 4.07% 108.071 13.95%

Deterministic message signing improves by 5.42–6.65%; external-μ signing by 3.95–12.47%, and external-μ verification by 4.11–5.73%. Key-generation medians stay within 0.08%. OpenSSL ML-DSA was not enabled in this runner's benchmark configuration, so this run supplies no OpenSSL ML-DSA comparison. These reused-key measurements do not replace the cold-lifetime measurements above.

The pushed head's native AArch64 CI job and static checks pass. The remaining CI runner queue is tracked by GitHub. No measurement artifacts are included in this PR.

@github-actions github-actions Bot added untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified. and removed untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified. labels Oct 31, 2026
@reaperhulk
reaperhulk force-pushed the codex/arm64-mldsa-auto-cache branch from 76bfbb8 to abd2a00 Compare November 1, 2026 05:12
@reaperhulk reaperhulk changed the title Cache AArch64 ML-DSA key transforms with shared operation kernels Automatically prepare reused ML-DSA keys on AArch64 Nov 1, 2026
@reaperhulk
reaperhulk marked this pull request as ready for review November 1, 2026 05:21
@reaperhulk
reaperhulk added this pull request to stack #3878 November 1, 2026 14:04
@reaperhulk
reaperhulk force-pushed the codex/arm64-mldsa-auto-cache branch from 88abce7 to 421c0a3 Compare November 1, 2026 14:06
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

This pull request has conflicts with codex/mldsa-prepared-key-specs, found after d3d8384 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 closed this Nov 6, 2026
reaperhulk pushed a commit that referenced this pull request Nov 6, 2026
SigningKey{44,65,87}::prepare and VerifyingKey{44,65,87}::prepare give a
PreparedSigningKey / PreparedVerifyingKey: the key, with its polynomials
decoded and transformed once (vg_mldsa*_prepare_signing_key,
vg_mldsa*_prepare_verifying_key), for a key that signs or verifies a
stream of messages. Its sign, sign_deterministic and verify call
vg_mldsa*_sign_message_prepared and vg_mldsa*_verify_message_prepared on
AArch64, and the ordinary functions elsewhere. The prepared bytes are
inline (no allocation), immutable, and wiped on drop for a private key.

The implementation and proofs are those of #3819,
rebased onto main:

* The ordinary and prepared entries share one signing and one
  verification kernel per parameter set and Keccak backend
  (vg_mldsa*_sign_with_cache, vg_mldsa*_verify_with_cache), which take an
  optional slice of the key's polynomials. They and the entries on mu with
  a prepared key (vg_mldsa*_sign_prepared, vg_mldsa*_verify_prepared) are
  internal functions now, their contracts untrusted in
  Proof/MlDsa/PreparedKeyContract.lean, with polyStored_iff relating the
  spec's PolyStored to PolyIs.
* Lemmas main deleted as dead code (PostB.refl, PPostB.mono,
  selectedPairedSignLoop_ok/_tr, finish_rootPair) are restated in the
  modules that use them, and the uses of removed names (KeyGen.prims,
  Sig.u64Bufs, the verify_message call lemmas) follow main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWy42drMfWKyQXeWwK8
reaperhulk pushed a commit that referenced this pull request Nov 6, 2026
SigningKey{44,65,87}::prepare and VerifyingKey{44,65,87}::prepare give a
PreparedSigningKey / PreparedVerifyingKey: the key, with its polynomials
decoded and transformed once (vg_mldsa*_prepare_signing_key,
vg_mldsa*_prepare_verifying_key), for a key that signs or verifies a
stream of messages. Its sign, sign_deterministic and verify call
vg_mldsa*_sign_message_prepared and vg_mldsa*_verify_message_prepared on
AArch64, and the ordinary functions elsewhere. The prepared bytes are
inline (no allocation), immutable, and wiped on drop for a private key.

The implementation and proofs are those of #3819,
rebased onto main:

* The ordinary and prepared entries share one signing and one
  verification kernel per parameter set and Keccak backend
  (vg_mldsa*_sign_with_cache, vg_mldsa*_verify_with_cache), which take an
  optional slice of the key's polynomials. They and the entries on mu with
  a prepared key (vg_mldsa*_sign_prepared, vg_mldsa*_verify_prepared) are
  internal functions now, their contracts untrusted in
  Proof/MlDsa/PreparedKeyContract.lean, with polyStored_iff relating the
  spec's PolyStored to PolyIs.
* Lemmas main deleted as dead code (PostB.refl, PPostB.mono,
  selectedPairedSignLoop_ok/_tr, finish_rootPair) are restated in the
  modules that use them, and the uses of removed names (KeyGen.prims,
  Sig.u64Bufs, the verify_message call lemmas) follow main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWy42drMfWKyQXeWwK8
reaperhulk pushed a commit that referenced this pull request Nov 6, 2026
SigningKey{44,65,87}::prepare and VerifyingKey{44,65,87}::prepare give a
PreparedSigningKey / PreparedVerifyingKey: the key, with its polynomials
decoded and transformed once (vg_mldsa*_prepare_signing_key,
vg_mldsa*_prepare_verifying_key), for a key that signs or verifies a
stream of messages. Its sign, sign_deterministic and verify call
vg_mldsa*_sign_message_prepared and vg_mldsa*_verify_message_prepared on
AArch64, and the ordinary functions elsewhere. The prepared bytes are
inline (no allocation), immutable, and wiped on drop for a private key.

The implementation and proofs are those of #3819,
rebased onto main:

* The ordinary and prepared entries share one signing and one
  verification kernel per parameter set and Keccak backend
  (vg_mldsa*_sign_with_cache, vg_mldsa*_verify_with_cache), which take an
  optional slice of the key's polynomials. They and the entries on mu with
  a prepared key (vg_mldsa*_sign_prepared, vg_mldsa*_verify_prepared) are
  internal functions now, their contracts untrusted in
  Proof/MlDsa/PreparedKeyContract.lean, with polyStored_iff relating the
  spec's PolyStored to PolyIs.
* Lemmas main deleted as dead code (PostB.refl, PPostB.mono,
  selectedPairedSignLoop_ok/_tr, finish_rootPair) are restated in the
  modules that use them, and the uses of removed names (KeyGen.prims,
  Sig.u64Bufs, the verify_message call lemmas) follow main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWy42drMfWKyQXeWwK8
reaperhulk pushed a commit that referenced this pull request Nov 6, 2026
SigningKey{44,65,87}::prepare and VerifyingKey{44,65,87}::prepare give a
PreparedSigningKey / PreparedVerifyingKey: the key, with its polynomials
decoded and transformed once (vg_mldsa*_prepare_signing_key,
vg_mldsa*_prepare_verifying_key), for a key that signs or verifies a
stream of messages. Its sign, sign_deterministic and verify call
vg_mldsa*_sign_message_prepared and vg_mldsa*_verify_message_prepared on
AArch64, and the ordinary functions elsewhere. The prepared bytes are
inline (no allocation), immutable, and wiped on drop for a private key.

The implementation and proofs are those of #3819,
rebased onto main:

* The ordinary and prepared entries share one signing and one
  verification kernel per parameter set and Keccak backend
  (vg_mldsa*_sign_with_cache, vg_mldsa*_verify_with_cache), which take an
  optional slice of the key's polynomials. They and the entries on mu with
  a prepared key (vg_mldsa*_sign_prepared, vg_mldsa*_verify_prepared) are
  internal functions now, their contracts untrusted in
  Proof/MlDsa/PreparedKeyContract.lean, with polyStored_iff relating the
  spec's PolyStored to PolyIs.
* Lemmas main deleted as dead code (PostB.refl, PPostB.mono,
  selectedPairedSignLoop_ok/_tr, finish_rootPair) are restated in the
  modules that use them, and the uses of removed names (KeyGen.prims,
  Sig.u64Bufs, the verify_message call lemmas) follow main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWy42drMfWKyQXeWwK8
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.

1 participant