Skip to content

AArch64 AES-GCM: baseline store_powers and {seal,open}_with_powers - #4523

Closed
alex wants to merge 1 commit into
claude/gcm-one-family-mainfrom
claude/gcm-aarch64-baseline-powers-main
Closed

alex wants to merge 1 commit into
claude/gcm-one-family-mainfrom
claude/gcm-aarch64-baseline-powers-main

Conversation

@alex

@alex alex commented Nov 7, 2026

Copy link
Copy Markdown
Member

Step (2e) of the GCM single-family plan. Stacked on claude/gcm-one-family-main (main and widenFirstArray); review only the top commit. This replaces #4519, which was on the old claude/gcm-one-family; I restacked onto a new branch rather than force-push.

On AArch64, every implementation should register store_powers and {seal,open}_with_powers, so that the generated dispatchers alone choose. Until now only _aes and _aes_sha3 had them. This adds them for the baseline (no PMULL).

New functions

vg_aes_gcm_store_powers (baseline): Impl.Gcm.AArch64.keyPowers, proven in Proof/Gcm/AArch64/KeyPowers.lean.

  • Loads H from bytes 240–255 of the key context, as vg_ghash loads its h.
  • For k = 1 … 8, stores preparedPower(Hᵏ) at its slot of Powers8Repr, as two little-endian doublewords (enc_eq, readW128).
  • Between stores, computes Hᵏ⁺¹ = Hᵏ • H with the 128 steps of vg_ghash's software multiplication (mul_ok, reused).
  • Uses only caller-saved registers. Its only branches are the multiplications' counted loops. Constant time by taint_decide.

vg_aes_gcm_{seal,open}_with_powers for implementations without code that reads the powers:

  • They are their seal and open, the same code (basePwArtifacts, used where gh.withPowers is none). The code never reads the buffer, whose address is the next stack argument.
  • Proof/AesGcm/AArch64/BasePw.lean moves the proofs of seal/open to Spec.Gcm.sealWithPowersContract/openWithPowersContract.
  • open_to_with_powers is not added: nothing on AArch64 registers it, and the Rust does not use it.

New framework lemma

AArch64.Verified.dropTrailingRo (Proof/Framework/AArch64/TrailingRo.lean):

  • It applies to code verified for a function with at least one stack argument.
  • That code is then verified for the same function with one more argument, last: a read-only array it never reads.
  • The new contract's precondition must imply the old one, and its postcondition and leak must follow from the old ones.
  • It narrows the state to the old contract's regions (RegionModel.verified_narrowTo): the buffers without the array, and the stack-argument area one slot shorter.
  • It reuses StackArgScratch.lean's allArgs/pre_args/post_args/pub_args.

Proof/Framework/Scratch.lean's helpers only cover a writable trailing array, and editing that file would rebuild most of the tree. So the read-only counterparts (Sig.withRo, Sig.bufs_append_ro) live in this new module.

Scope

  • No TCB or Spec change.
  • Nothing in Rust calls the new functions yet: the Rust rework is step (3). The AArch64 crate gains the three baseline functions and the dispatchers vg_aes_gcm_store_powers_auto, vg_aes_gcm_seal_with_powers_auto and vg_aes_gcm_open_with_powers_auto.
  • Duplicated code: the baseline seal_with_powers/open_with_powers have the same machine code as the baseline seal/open. They are separate copies, not aliases, because the signatures differ. They stay duplicated until step (3) stops registering plain seal/open on AArch64.
  • No benchmark: no code the library runs changes.

Checks (on the new base)

  • lake build; Emit.lean --check clean.
  • Every Static checks step: check_lean_speed.py (no decide := true), check_variants.py, check_registrations.py, check_lean_single_importer.py against the base branch.
  • check_lean_public_imports.py on the five changed or added modules (on the old base; the modules are unchanged).
  • cargo fmt --check; cargo clippy --all-targets -D warnings on AArch64.

Generated by Claude Code

The baseline implementation (no PMULL) now has the functions of the
AArch64 single GCM layout, so that every implementation registers them and
the dispatchers alone choose:

* `vg_aes_gcm_store_powers` (`Impl.Gcm.AArch64.keyPowers`): `H` from byte
  240 of the key context, then for `k` from 1 to 8 `preparedPower(Hᵏ)`
  stored at its place in `Powers8Repr`, and `Hᵏ⁺¹` by the bit-by-bit
  multiplication of `vg_ghash`. Only caller-saved registers, straight-line
  but for the multiplications' counted loops; constant time by
  `taint_decide` (`Proof/Gcm/AArch64/KeyPowers.lean`).
* `vg_aes_gcm_seal_with_powers` and `vg_aes_gcm_open_with_powers` of an
  implementation without code that reads the powers: its `seal` and
  `open`, which never read the buffer, whose address is the next stack
  argument (`Generic/AesGcm/AArch64/AesGcm.lean`, `basePwArtifacts`;
  `Proof/AesGcm/AArch64/BasePw.lean`).
* `AArch64.Verified.dropTrailingRo` (`Proof/Framework/AArch64/TrailingRo.lean`):
  code verified for a function with at least one stack argument is verified
  for it with one more, last, a read-only array it never reads, with a
  stronger precondition and the same postcondition and leak. It narrows the
  state to the old contract's regions (`RegionModel.verified_narrowTo`).

No TCB or Spec change. Nothing in Rust calls the new functions yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHFuGsz7F32Tm9DLkuP

alex commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

Superseded by #4524: the same commit, on main directly, without the unrelated x86-64 WidenArray commit.


Generated by Claude Code

@alex alex closed this Nov 7, 2026
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