Skip to content

AES and modes: remove dead declarations and modules - #4332

Merged
reaperhulk merged 1 commit into
mainfrom
claude/unify-random-bytes-crypto-xqmg0z-deadcode-aes-modes
Nov 6, 2026
Merged

reaperhulk merged 1 commit into
mainfrom
claude/unify-random-bytes-crypto-xqmg0z-deadcode-aes-modes

Conversation

@reaperhulk

Copy link
Copy Markdown
Member

Like #4305 (DSA) and #4314 (ECDSA), this removes the proof and implementation declarations that nothing reachable uses, for the AES family, its modes and CMAC. The scope is the directories under Proof/ and Impl/ named Aes, AesCbc, AesCcm, AesCfb, AesCfb8, AesCtr, AesOcb, AesOfb, AesSiv, AesXts, Modes, Ocb, Siv, Xts, Cmac, CmacAes and CmacTripleDes.

It removes 439 declarations (429 in Proof/, 10 in Impl/):

  • 51 of them are in 14 whole modules, now deleted;
  • the other 388 come from 205 modules that remain.

AesCfb, AesOfb and Siv had nothing dead.

  • No Spec/ or TCB/ file changes.
  • No generated crate changes: Emit.lean --check passes, so the emitted code is identical.

247 files, +79 / −4,142.

Per directory: CmacAes 54, Aes 53, CmacTripleDes 53, AesOcb 49, AesSiv 49, Modes 46, AesXts 44, AesCcm 36, AesCbc 19, Cmac 16, Ocb 8, AesCfb8 6, Xts 3, AesCtr 3.

How "dead" was decided

This follows the method of the shared dead-code tooling, the same one #4305 and #4314 used.

  • Graph. A declaration-level graph built from the .ilean files of a full build at 880b9378c.
  • Live roots. The live set starts from:
    • every declaration in Artifacts/, Generic/, Variants/, TCB/ and VerifiedGarbageTest/;
    • the non-Spec modules the lakefile names;
    • the modules the top-level *.lean files import.
  • Uses the .ilean files don't record:
    • Literals found by name. Every module-level command of a module the roots import is live, with what it references. Lit modules that live code imports stay.
    • Tactics, macros and notation. A module that defines syntax is never deleted.
    • Attributes and instances. Anything with a simp-set or instance attribute in a module the roots import is live.
  • Protected modules. A module that another algorithm's registration imports is never deleted, only trimmed. That covers the Generic/AesBlocks, AesCtr32, AesGcm, AesXts and CmacAesUpdate groups, AES-GCM(-SIV)'s registrations, and the other ciphers' modes. Here "another algorithm" was matched by path component, so Aes does not cover AesGcm.
  • Fixed point. The plan was iterated to a fixed point. The full build was the final check.

Deleted modules

  • Proof/AesXts/Arm/Verified
  • Proof/Cmac/Contract and Proof/Cmac/TripleDesContract: the contracts of the old internal subkeys/update/finalize and init functions, which only the dead *_verified proofs used.
  • Proof/CmacTripleDes/{AArch64,X86_64}/{CT,Implies}
  • Proof/Modes/AArch64/{CbcEncrypt,CbcDecrypt}, Proof/Modes/X86_64/{CbcEncrypt,CbcDecrypt} and Proof/Modes/RISCV64/{Ctr,Ctr32}. Only the chained CBC variants are emitted, so these were proofs of unchained functions.
  • Proof/Xts/Contract

Trimmed

There are 388 further declarations, mostly:

  • unused helper lemmas, *_wp/*_ct pieces and layout facts;
  • the unchained Impl.Modes.{AArch64,X86_64}.Core.cbcEncrypt/cbcDecrypt and their proofs;
  • Impl.AesSiv.X86.init and a few other unused Impl definitions.

Removed top-level Verified proofs (58)

Each is a Verified <target> proof of a routine that no registration file exports on any target. The registrations export other proofs for these functions:

  • vg_aes_ctr32 and vg_aes_expand_key: their *_framed, expandKey3_verified and the generic variants' proofs;
  • CMAC: the streaming API's init/absorb/finish_framed;
  • XTS: the Unit proofs and generic groups.

These routines are only reached as internal callees, and their correctness (*_correct) and constant-time (*_ct) proofs stay. The emitted functions are unchanged.

  • AES CTR and key expansion: Aes.{AArch64, AArch64.Aese, Arm, PPC64LE, RISCV64, X86, X86.AesNi, X86_64, X86_64.AesNi, X86_64.Vaes}.ctr32_verified, Aes.PPC64LE.expandKey_verified, Aes.X86_64.AesNi.Key.expandKey_verified
  • AES-XTS:
    • AesXts.{AArch64, AArch64.Aes, Arm, PPC64LE, RISCV64, X86, X86_64, X86_64.OnePassNi, X86_64.Vaes}.{encrypt,decrypt}_verified
    • AesXts.AArch64.{encrypt,decrypt}_verified_of
  • AES-CMAC:
    • CmacAes.{AArch64, Arm, PPC64LE, RISCV64, X86, X86_64}.{subkeys,update,finalize}_verified
    • CmacAes.AArch64.Aese.verified, CmacAes.X86_64.AesNi.verified
  • TDEA-CMAC: CmacTripleDes.{AArch64, X86_64}.{init,update,finalize}_verified

Kept on purpose

These 11 look dead to the analysis, but each is used in a way the .ilean files don't record. A rerun of the analysis on the final build finds only these:

  • Lemmas named inside macro bodies. The block-runner macros' simp only [...] lists name them, and macro expansions leave no reference in the index:
    • AesCbc.AArch64.{read8,write8} and AesOcb.AArch64.{read8,write8}
    • AesCcm.AArch64.{imm_lit,setWidth_8_32}
    • {AesCcm,AesOcb,AesSiv}.X86.readW_writeB_off
    • Modes.byte_xor_zero', used by Modes/Wide.lean's local arith_ifs macro
  • A lemma used in default arguments. Modes.Arm.tabsOk_nil is named in OfbCfb.lean's (ht : … := by exact tabsOk_nil _ _) default arguments. The ARM CBC/OFB/CFB proofs of TripleDes, IDEA, Blowfish, CAST5, Camellia, SEED and SM4 elaborate those at their call sites.

Each of these now has a one-line comment saying why it stays.

Other edits that come with the removal

  • Registration file: Artifacts/AesXts/Arm.lean (AES-XTS's own) only drops the import of the deleted Proof/AesXts/Arm/Verified (check_registrations passes).
  • Imports: Proof/CmacTripleDes/Scratch.lean now imports directly what the deleted Proof/Cmac/TripleDesContract passed on (Spec.Aes, Spec.TripleDes, TCB.Mem).
  • ci/lean_speed_allowed.py:
    • drops the two deleted CmacTripleDes/*/CT.lean entries;
    • lowers CmacTripleDes/Arm/CT.lean's bare-assumption count from 2 to 1, as check_lean_speed.py requires.
  • Cleanup:
    • removes dangling omit … in lines, an empty section/variable block and an empty namespace block;
    • rewords doc comments that named removed declarations: the deleted Proof.Xts/Proof.Cmac contracts, *_verified, the unchained CBC functions and removed lemmas.

Dead Spec/ definitions noticed in scope (not changed here)

  • VG.Spec.Ocb.encryptWith_ctx
  • VG.Spec.Ocb.decryptWith_ctx

No other Spec/ definition in these directories is dead (Spec/Aes 0/42, Spec/Cmac 0/54, Spec/Xts 0/29).

Checks

  • Lean:
    • the full lake build --log-level=warning passes (28,913 jobs);
    • Emit.lean --check passes, with the standard axiom audit;
    • git status crates/ is clean;
    • check_lean_public_imports.py --base origin/main -m <modified modules> passes.
  • Static checks: every step of the job passes, with check_lean_single_importer.py --base origin/main and run_unit_tests.py (641 tests).
  • Rust: cargo fmt --check and cargo clippy --all-targets -- -D warnings pass. No Rust changed.
  • No escape hatches: nothing adds sorry, admit, native_decide, bv_decide or maxHeartbeats.
  • Analysis rerun on the final build: nothing dead is left in scope beyond the 11 declarations above.

No benchmark: the emitted code is unchanged.


Generated by Claude Code

Remove the proof and implementation declarations of the AES family, its
modes and CMAC (Proof/ and Impl/ under Aes, AesCbc, AesCcm, AesCfb8,
AesCtr, AesOcb, AesSiv, AesXts, Modes, Ocb, Xts, Cmac, CmacAes,
CmacTripleDes) that nothing reachable from the registrations uses:
439 declarations, 14 of them whole modules, including 58 top-level
`Verified` proofs that no registration exports.

No Spec/, TCB/ or generated crate changes; Emit.lean --check passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWvk94BdaBuW7gdPFjj
@reaperhulk
reaperhulk enabled auto-merge November 6, 2026 16:47
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit e7072b2 Nov 6, 2026
19 checks passed
@reaperhulk
reaperhulk deleted the claude/unify-random-bytes-crypto-xqmg0z-deadcode-aes-modes branch November 6, 2026 17:18
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