Repository navigation
Hashes, MACs and KDFs: remove dead declarations and modules - #4349
Merged
reaperhulk merged 1 commit intoNov 6, 2026
Merged
Conversation
Remove the 1,135 proof and implementation declarations of the hash, MAC and KDF algorithms (SHA-1, SHA-2, SHA-3, SM3, MD5, BLAKE2, the shared Merkle-Damgard streaming code, HMAC, PBKDF2, scrypt, Argon2) that nothing reachable from the registrations uses, including 7 whole modules and 146 top-level `Verified` proofs of routines no registration exports. Nothing in Spec/, TCB/, src/ or the generated crates changes; Emit.lean --check passes, so the emitted code is identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWu41XvSg4zgCD1juXF
reaperhulk
deleted the
claude/unify-random-bytes-crypto-xqmg0z-deadcode-hashes
branch
November 6, 2026 20:11
This was referenced Nov 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Like #4305 (DSA) and #4314 (ECDSA), this removes the proof and implementation declarations that nothing reachable uses, for the hashes, MACs and KDFs: SHA-1, SHA-2 (SHA-256, SHA-512), SHA-3, SM3, MD5, BLAKE2, the shared Merkle–Damgård streaming code (
MdStream), HMAC, PBKDF2, scrypt and Argon2. That is 1,135 declarations, including 7 whole modules, underProof/andImpl/of those algorithms.Spec/,TCB/,src/or the generated crates changes.Emit.lean --checkpasses, so the emitted code is identical.MdHashTableandHashTablehad nothing dead to remove, and there is noSha2directory.366 files, +95 / −9,423.
How "dead" was decided
The method of
tools/deadcode/README.md(on the tooling branch), withSCOPEset to the directories above:.ileanfiles of a full build.Artifacts/,Generic/,Variants/,TCB/andVerifiedGarbageTest/; the non-Spec modules the lakefile names; the modules the top-level*.leanfiles import..ileanfiles don't record, kept conservatively:materialize_*,taint_summary), and Lit modules that live code imports stay.The analysis also proposed the auxiliary declarations of notations and syntax; I took those out of the removal set by hand (see "Kept on purpose"), since their uses leave no reference.
Removed
7 modules:
Proof/MdStream/X86/ArgWordProof/Pbkdf2/HmacProof/Scrypt/Contract,Proof/Sm3/Contract(the per-routine contracts only the removedVerifiedproofs used)Proof/Sha256/AArch64/Stream/Common,Proof/Sha256/Arm/Stream/CommonProof/Sha3/AArch64/Neon/Rounds1,128 further declarations from 343 modules that remain, mostly unused helpers,
*_ct/*_wp/*_oklemmas, contracts and satisfying states of the removed proofs, and unusedImpldefinitions in 12 files (code shapes nothing emits or proves, such ascompressAt,referenceBlockMix,progWith,*Main := *With .scalar). By algorithm: scrypt 227, SHA-256 145, PBKDF2 134, Argon2 128, SHA-3 119, SHA-512 113, BLAKE2 78, SM3 65, SHA-1 57, MD5 35, MdStream 25, HMAC 8, HmacTable 1.146 top-level
Verifiedproofs of routines that no registration exports. Each proves that an internal routine meets a contract (usually the shared one, with widened scratch) as if it were exported on its own. No registration file (Artifacts/,Generic/,Variants/) refers to any of them on any target: the routines are only internal callees of what is exported (update/finalize, HMAC, PBKDF2, scrypt, Argon2), and their correctness and constant-time proofs, which those callers use, stay. The emitted functions are unchanged.Shared.compress,compressWide_verified,compress_of,compressWide_of,compress_shani,compress_avx2) on each target; SHA-512'sX86_64.compressWide_verifiedandX86_64.Avx2.compress_verified; and the per-fileupdate_verified/finalize_verifiedof SHA-1 (AArch64, x86-64, and x86-64'sCompress) and SHA-256 (AArch64).permute_verified,permute_verified',Shared.permute) on AArch64 (includingScalar.LazyandHybrid.X3), ARMv7, PPC64LE, RISC-V, x86 and x86-64.compressB_verified/compressS_verified(and their primed forms) on AArch64, PPC64LE and RISC-V, ARMv7's and x86'scompress_verified/compressB_verified, and the scratch-taking stream functions on RISC-V and x86-64 (updateScratchB_verified,finalizeScratchB_verified,updateB_verified,finalizeB_verified).iterateon PPC64LE (8) and RISC-V (7), the genericPPC64LE.verifiedandRISCV64.verified, andSha1.RISCV64.iterate_verified.salsa_verified,blockMix_verifiedandroMix_verifiedon every target (including AArch64'sResidentand x86-64'sFusedandDirectFill).compress_verified(AArch64, ARMv7, PPC64LE, x86'scompressShared/compressWide, x86-64 scalar, AVX2 and AVX-512) and H′'sverified/hPrimeShared_verified/hPrimeWide_verified(AArch64, ARMv7, PPC64LE, x86, x86-64).Outside these directories, only imports of deleted modules are dropped:
Generic/MdHash/AArch64/{Hmac,Pbkdf2}.lean(check_registrationspasses);Proof/Variants/Sha1/X86/{Scalar,ShaNi}.lean;Proof/Ed448/X86/SignCached/Hash.lean,Proof/Ecdsa/Rfc6979/AArch64/Hash.lean,Proof/RsaPkcs1Enc/{Arm,X86}/DecKdk.leanand sixProof/MlKem/AArch64/modules.Other edits that come with the removal:
Proof/Pbkdf2/Memorynow importsProof/Sha256/Streamitself, which the deletedPbkdf2/Hmacpassed on.compressWideis dropped from thenarrowsimp sets of SHA-256 (ARMv7) and SHA-512 (ARMv7, x86); SM3 x86'snarrowCand thenarrowmacros of Argon2 x86 and scrypt x86 (Salsa,BlockMixVerified,RoMixCT), which only the removed proofs used, are removed.omit … in,include … in,open … inandset_option … inlines, emptysections and namespace blocks, and headings with nothing left under them are removed.Sharedfiles, PBKDF2's per-hashiteratefiles, scrypt's and Argon2'sVerifiedfiles, and others).ci/lean_speed_allowed.pylowers its counts forSha512/X86_64/Avx2/Compress.leanand drops one forBlake2/AArch64/Compress.lean, ascheck_lean_speed.pyasked.Kept on purpose
Rerunning the analysis after the removal leaves 106 dead declarations in scope, all kept for these reasons:
+++notation (Argon2, BLAKE2, SHA-3 and SHA-512Implfiles on ARMv7/x86) and thepropertynotation (Argon2DeriveVerifiedon AArch64 and x86-64), and SHA-3 AArch64'ssponge_taint_summariescommand andsponge_taint_decidetactic (Proof/Sha3/AArch64/Sums) with the helpers their elaborators run (spongeSumCmds,spongeSumNames,spongeSumSavingCmds,mlkemSumNames,spongeSaved). Their uses leave no reference, so the analysis cannot see them.Scrypt.PPC64LE.Whole.fr_addr, which theframe_runmacro's simp set names.Permutation.scalarand what it needs, withProof/Sha3/{Env,Lanes}lemmas) andImpl.Sha3.AArch64.Stream.{absorb,pad,squeeze}, which ML-KEM, ML-KEM-1024 and ML-DSA AArch64 proofs use; SHA-256 x86'sShared.compressWide{,_of,_implies}with their helpers, andProof.Sha256.compressContract/compressSig, whichProof/Variants/Sha256/X86/ShaNi'scompress_shareduses. Removing these belongs with those algorithms' passes.Dead
Spec/definitions noticed in scope (not removed here)Listed only; a separate PR removes dead Spec definitions.
Spec/Sha3/Length.lean:flatMap_lanes_length,sha3_256_length,shake256_length,squeezeBlocks_length,squeeze_length,toBytes_lengthSpec/Blake2/Contract.lean:blake2s_eq_finalHashSpec/HashTable.lean:index_hashesChecks
lake build --log-level=warningpasses, before (28,920 jobs) and after (28,828 jobs) rebasing onto currentmain(5d3313ab7);Emit.lean --checkpasses with the standard axiom audit, with no change to any crate;check_lean_public_imports.py --base origin/main -mon the 358 modified modules passes (it checks the one whose imports changed,Proof/Pbkdf2/Memory).Static checksjob passes, withcheck_lean_single_importer.py --base origin/main, includingrun_unit_tests(641 tests).cargo fmt --checkandcargo clippy --all-targets -- -D warningspass. No Rust changed.sorry,native_decide,bv_decideormaxHeartbeats.No benchmark: the emitted code is unchanged.
Generated by Claude Code