Skip to content

Block ciphers: remove dead declarations and modules - #4333

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

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

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 block and stream ciphers: Blowfish, Camellia, CAST5, IDEA, RC2, RC4, SEED, SM4 and Triple DES. That is 766 declarations, including 15 whole modules.

  • Nothing in Spec/, TCB/, src/ or the generated crates changes. Emit.lean --check passes, so the emitted code is identical.
  • There are no dead Spec/ definitions for these algorithms (0 of 555 across the nine).

274 files, +101 / −5,988.

Algorithm Declarations removed
SM4 214
RC2 155
Triple DES 149
Camellia 88
SEED 77
CAST5 38
Blowfish 31
IDEA 7
RC4 7

How "dead" was decided

This follows the method of #4305 and #4314.

  • Graph. A declaration-level graph built from the .ilean files of a full build.
  • 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 in a module the roots import is live, along with what it references. Lit modules that live code imports are kept.
    • Tactics, macros and notation. A module that defines syntax is never deleted. Its dead declarations may be trimmed.
    • Attributes and instances. Anything carrying a simp-set or instance attribute in a module the roots import is live.
  • Other registrations. Modules that another algorithm's registration imports are never deleted, only trimmed. CmacTripleDes and Sm4Gcm count as other algorithms here.
  • Final check. The full build is the arbiter.

One rule added for this PR. In the first build, Proof/Rc2/PPC64LE/Run.lean's rrun tactic failed because it names read_one, write_eight and other lemmas inside its macro_rules, and those uses leave nothing in the .ilean files. So a declaration is now also kept when a syntax definition names it: a syntax, macro, macro_rules, elab, tactic_template or notation block, in the declaration's own module or a module that imports it. Whatever such a declaration uses is kept too.

Removed

Modules (15):

  • Impl/Sm4/Arm/{Ctr,Fb}
  • Proof/Sm4/Arm/{CbcVerified,CtrVerified,FbVerified,ModeCore}
  • Proof/Sm4/RISCV64/PreparedVerified
  • Proof/Rc2/AArch64/Cbc/ConstantTime
  • Proof/Rc2/RestoreMemory
  • Proof/TripleDes/Contract
  • Proof/TripleDes/{Arm,PPC64LE,X86,X86_64}/VerifiedBlock
  • Proof/TripleDes/X86/BlockCT

Declarations: 650 more from 252 modules that remain. Most are unused helpers, *_ct, *_wp and *_implies lemmas, satisfiability witnesses and internal contracts. This includes the internal contracts of Proof/Camellia/Prepared.lean and Proof/Sm4/Prepared.lean. Their Layout, Holds and Keeps, which the proofs use, stay.

80 top-level Verified proofs of routines that no registration exports. Each one proves that an internal routine meets a contract as if it were exported on its own. No registration file names any of them, on any target; I checked this against every *_verified name in Artifacts/, Generic/ and Variants/. The registrations export the modes' and streams' framed proofs instead. These routines are reached only as internal callees, and their correctness proofs (*_correct, *_wp) stay wherever those are used. The removed proofs are:

  • Camellia:
    • AArch64.{prepare,crypt}_verified
    • AArch64.Serial.{prepare,crypt}_verified
    • {PPC64LE,X86,X86_64}.crypt_verified
  • RC2:
    • {key,encrypt,decrypt}_verified on AArch64, Arm, PPC64LE, RISCV64, X86 and X86_64
    • Cbc.{encrypt,decrypt}_verified on all six targets
    • X86.Cbc.cbc_verified
  • SEED:
    • {PPC64LE,X86}.{encrypt,decrypt}_blocks_verified
    • X86.ecb_verified
  • SM4:
    • {prepare,crypt}_verified on AArch64, Arm, PPC64LE, RISCV64 and X86
    • X86_64.crypt_verified
    • AArch64.ecb_verified
    • Arm.{cbcEncryptChained,cbcDecryptChained,cfbEncrypt,cfbDecrypt,ofb,ctr}_verified
    • {PPC64LE,RISCV64}.Modes.ctr32_verified
  • Triple DES:
    • {encrypt,decrypt}_verified on AArch64, Arm, PPC64LE, X86 and X86_64
    • X86.Ecb.{encrypt,decrypt}_verified
    • X86_64.Bitsliced{,Sse}.{encrypt,decrypt}_verified
    • AArch64.cbcEncryptChained_verified

Outside the nine algorithms' Proof/ and Impl/ directories: five of their own registration files only drop imports of deleted modules: Artifacts/Sm4/RISCV64 and Artifacts/TripleDes/{Arm,PPC64LE,X86,X86_64}. check_registrations passes. No other algorithm's file changes.

Other edits that come with the removal:

  • Doc comments that named removed declarations are reworded. These are mostly module docs that described a removed *_verified proof; they now describe the *_correct theorems that remain and drop the constant-time claims whose proofs are gone.
  • Section headers left empty are removed.

Kept on purpose

  • 180 declarations named inside syntax definitions (the new rule above). Examples:

    • the exec_*, *_mem and *_store rewrites that the ARM, AArch64 and x86 crun/rrun tactics of CAST5, Blowfish and RC4 list;
    • read_one, read_four, read_eight and write_* in the PPC64LE and RISC-V Run modules;
    • the AArch64 *_keeps_x30 lemmas that the *_keeps_x30 tactics use.

    Some of these are reached only by tactics no live proof calls. This PR leaves them, since the .ilean files can't tell.

  • VG.Proof.Rc2.X86.Cbc.{wideContract,narrowRd,narrowWr} and VG.Proof.Seed.X86.wideContract. The rc2_cbc_narrow and narrow_seed_x86_verified tactic templates name them by full name.

  • Proof/TripleDes/X86_64/BitslicedSse/ConstantTime. It holds the taint_summarys encSum and decSum, which EcbCall/Verified uses by name (using BitslicedSse.encSum). Only its two dead theorems, {encrypt,decrypt}_constantTime, are removed. This is the second gap the build caught: a summary used in another module's taint_summary … using command leaves no reference.

  • Cast5's slot notation (Proof/Cast5/Arm/Round.lean). Its macro_rules auxiliary declaration looked dead, but Block and Ecb use it.

A rerun of the analysis on the result finds 181 dead declarations in scope: exactly the kept set above.

Checks

  • Lean:
    • the full lake build --log-level=warning passes;
    • lake env lean --run Emit.lean --check passes with the standard axiom audit, so no generated crate changes;
    • check_lean_public_imports.py --base origin/main -m <modified modules> passes.
  • Static checks: every step of the Static checks job passes, including check_lean_single_importer.py --base origin/main, check_registrations.py, check_lean_speed.py and run_unit_tests.py.
  • 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.
  • No trust changes: no Spec/ or TCB/ file changes.

No benchmark: the emitted code is unchanged.


Generated by Claude Code

Remove the proof and implementation declarations of Blowfish, Camellia,
CAST5, IDEA, RC2, RC4, SEED, SM4 and Triple DES that nothing reachable
from the registrations, the TCB or the tests uses: 766 declarations,
including 15 whole modules, among them 80 top-level `Verified` proofs of
routines no registration exports. Declarations named inside tactic and
macro definitions, and the `taint_summary`s that other proofs use by
name, are kept. No Spec/, TCB/ or generated crate changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWvMak1dHwTxf2VtG2z
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit aef7a15 Nov 6, 2026
21 checks passed
@reaperhulk
reaperhulk deleted the claude/unify-random-bytes-crypto-xqmg0z-deadcode-ciphers branch November 6, 2026 18:59
alex pushed a commit that referenced this pull request Nov 7, 2026
…leave consts to the default

#4333 removed SM4 Arm's ecbCore and ecbSpec, which only the final functions
use now: define them in their modules. #4380 leaves registrations' tables of
constants to the default; drop the CAST5 final entries' consts likewise
(the generated code is unchanged).

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