Skip to content

RSA: remove dead declarations and modules - #4344

Merged
reaperhulk merged 6 commits into
mainfrom
claude/unify-random-bytes-crypto-xqmg0z-deadcode-rsa
Nov 6, 2026
Merged

reaperhulk merged 6 commits into
mainfrom
claude/unify-random-bytes-crypto-xqmg0z-deadcode-rsa

Conversation

@reaperhulk

Copy link
Copy Markdown
Member

Like #4305 for DSA and #4314 for ECDSA, this removes the RSA family's proof and implementation declarations that nothing reachable uses. The scope is Proof/ and Impl/ of Rsa, RsaKeyGen, RsaOaep, RsaPkcs1Enc, RsaPkcs1Sig, RsaPss and Mgf1 (Mgf1 had nothing dead). It also deletes DSA's Proof/Dsa/X86/LoadSlot.lean, which #4305 left for RSA (below).

1,889 declarations removed: 480 with 102 whole modules, and 1,409 more from 551 modules that remain. DSA's LoadSlot (one dead theorem) is also deleted, for 103 modules in all. 707 files, +555 / −26,310.

  • Nothing in Spec/, TCB/, src/ or the generated crates changes. Emit.lean --check passes: the emitted code is identical.
  • The only file outside lean/ is ci/lean_speed_allowed.py. check_lean_speed.py asked for Mid1's allowance to be lowered (below).

How "dead" was decided

This is the method of #4314, with the shared scripts of the dead-code tooling branch.

  • Graph. A declaration-level graph built from the .ilean files of a full build at 880b9378c.
  • Live roots:
    • 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, and so is what it references.
    • Tactics, macros and notation. A module that defines syntax is never deleted.
    • Attributes and instances. Any declaration with an attribute or an instance in a module the roots import is live.
  • The plan. Iterated to a fixed point, then applied.
  • Final check. The full build. Rerunning the analysis on the result finds only what is kept on purpose (below).

Two more kinds of invisible use. This scope showed two the scripts don't catch. I kept every instance of both:

  • Syntax declarations and what they use. The plan trimmed syntax modules down to nothing, which would have removed:

    • the elabs hdr_disj, rsa_stack_shape and rsa_stack_use;
    • two local macros, T2 in InvBatchRt/Time/Comp and nword in FrontRt/Near;
    • the meta helpers these use.

    They are all kept, along with the lemmas their quotations name: loop_all, call_all, frame_all and the *_stack lemmas in Rsa/X86/StackTactic. Lemmas named only inside other macros' bodies are kept too. There are 32 of them, for example RecDet.b2n_le1 and RecDet.ite_le1 in Rsa/PPC64LE/RdOps, and the s*_lt and subFlags_* lemmas in RsaPss/Arm/Step.

  • Names built at run time. hdr_disj builds <list>_shape (Name.appendAfter) and looks the name up in the environment. So the 25 *Ranges_shape lemmas of RsaKeyGen AArch64 and X86-64 are kept with what they use.

Removed

103 modules: 102 under the RSA family's Proof/ and Impl/, and DSA's LoadSlot:

  • Rsa:
    • Impl:
      • Arm.CheckCrtKey, PPC64LE.CheckCrtKey
      • X86.MulMod, X86_64.WordValidation
    • Proof:
      • Checked, MontProductContract
      • AArch64.{CrtKeyHead, CrtKeyMain}
      • Arm.{CckCorrect, CckTaint}
      • PPC64LE.{KcCck, KcCckCT, KcCckMain}
      • X86.{CvHelperTiming, CvLoad, CvStore, InvHalf, KeyCopy, KeyEq, KeyRt.Gcd, KeyWord}
      • X86_64.{Implies8, PrivOutcome}
  • RsaKeyGen:
    • Impl.X86:
      • CandidateImport, CandidateLoad
      • Gcd64Check
      • KeyCrt, KeyInverse, KeyLcm, KeyPrimes
      • Product
    • Proof:
      • Checked
      • PPC64LE.Cand.{Instances, Verified}, RISCV64.Cand.{Instances, Verified}
      • 54 x86 modules: CandidateBitsTiming, CandidateDispatch, FastR2Timing, Inverse.Safety, InverseTiming, KeyArrayDivision, KeyConstant{,Timing}, KeyCrtTiming, KeyD{Part,Product,Select,ecrement}, KeyDivision{Correct,Timing}, KeyExponent{ResultFrame,Timing}, KeyGcdIsOne, KeyHalveStep, KeyHeaderTiming, KeyImport{Exponent,Prime,Timing}, KeyInitialize, KeyInputInitialize, KeyInverse{Correct,Timing}, KeyLcm{Correct,Timing}, KeyLoad{Exponent,Inputs}Timing, KeyNoSpCode, KeyOdd{Finish,Modulus,Prepare}, KeyOrder, KeyPartCorrect, KeyPrimes{Correct,Timing}, KeyProduct{,Value}, KeySafety, KeySmall, KeyVerified, KeyWidenCopy, KeyZero, OrScanTiming, Product{Bounds,Correct,Row,Timing,Window}, TrialTiming, WitnessPolicy
  • RsaOaep: Decrypt, Encoding, RISCV64.CTMgf
  • RsaPkcs1Enc: Checked, AArch64.Callee
  • RsaPkcs1Sig: Prefix, Sign, AArch64.{RecoverVerified, VerifyVerified}
  • RsaPss: Sign, Verify, X86_64.BufferXor
  • DSA: Proof.Dsa.X86.LoadSlot, as described below.

1,409 declarations removed from 551 modules that remain, mostly:

  • unused *_ok, *_ct, *_wp and *_implies lemmas;
  • one-hash versions of lemmas whose ₂ versions remain (RSA-PSS);
  • code definitions superseded by their …With forms, for example RsaKeyGen's millerRabin, mrRound, kMain and code on AArch64 and x86-64.

24 top-level Verified proofs of routines that no registration exports. Each proves that an internal routine meets a contract as if it were exported on its own. No registration file exports any of them on any target. Their routines are reached only as internal callees, or through a generic caller that is proven separately.

  • Rsa:
    • AArch64: precomputedChecked_verified, publicChecked_verified
    • ARMv7: CheckCrtKey.check_crt_key_verified
    • PPC64LE: KeyCheck.cck_verified, Priv.priv_verified
    • RISC-V: Priv.priv_verified
    • x86-64:
      • Instances.{crt, crtAdx, crtIfma}_verified
      • code_verified, crt_call_verified, publicChecked_verified
  • RsaKeyGen:
    • PPC64LE, RISC-V: Cand.cand_verified and Cand.candidate_verified. The Miller–Rabin generic registrations for these targets do not use them.
    • x86: Key.verified
  • RsaPkcs1Enc: AArch64.Enc.enc_verified, X86_64.enc_verified
  • RsaPkcs1Sig: {AArch64, X86_64}.{Rec, Ver}.code_verified

Outside the RSA directories:

  • Registration and variant files only drop imports of deleted modules (check_registrations.py passes):
    • Artifacts/RsaKeyGen/X86
    • Generic/MillerRabin/{PPC64LE, RISCV64}/RsaKeyGen
    • Generic/RsaPrivateCrt/{X86, X86_64}/RsaPkcs1Sig
    • Generic/RsaPublicPrecomputed/AArch64/RsaPkcs1Sig
    • Generic/RsaPublicPrecomputed/AllMdHash/X86_64/RsaOaep
    • Proof/Variants/RsaPrivateCrt/X86/Base
  • Impl/Dsa/X86/ProbablePrime drops its import of the deleted Impl/RsaKeyGen/X86/CandidateLoad. It used nothing from it.
  • Proof/Dsa/X86/LoadSlot.lean is deleted. DSA: remove dead declarations and modules #4305 kept it only because RSA's Generic/RsaPrivateCrt/X86/* and Proof/Variants/RsaPrivateCrt/X86/Base.lean import it. Its one theorem, loadSlot_ok, is unused: those files use nothing from it. So both imports are dropped, and the module goes with them.
  • ci/lean_speed_allowed.py lowers RsaKeyGen/Arm/Key/Mid1.lean's decide := true allowance from 25 to 21, as check_lean_speed.py asks now that the uses are gone.

Other edits that come with the removal:

  • Where a deleted module passed imports on, the in-scope modules that used them now import those modules directly.
  • Dangling open/omit/include … in prefixes, leftover variables, empty sections and namespace blocks, and their orphaned -- Formerly … comments are removed.
  • Doc comments that named removed declarations are reworded.

Kept on purpose

  • The syntax-related declarations above: the elaborators, macros, their helpers, the lemmas their quotations name, and the *_shape lemmas hdr_disj finds by name.
  • What other algorithms' code uses, even where that code is itself dead (a later pass per algorithm removes it). For example:
    • Impl.Rsa.X86_64.Crt.expLoop5
    • Impl.Rsa.AArch64.{Public, Precomputed, Crt}.code
    • Proof.Rsa.Mont{Window, Square, MulFixed}.* and Proof.Rsa.MontMulFixedContract, all used by Bignum
    • Proof.Rsa.X86_64.precomputedChecked_implies
    • Proof.Rsa.KeyWorkspace.Arrs.nil and Proof.Rsa.Arm.Keys.Arrs.nil, used by MillerRabin
  • Proof/Rsa/X86/StackTactic. The analysis counts all 15 of its declarations as dead, but it defines rsa_stack_shape and rsa_stack_use, which Rsa/X86/RtShape and FFDH's x86 proofs use.

Dead Spec/ definitions in scope (not removed)

These are listed only. Removing them is a trust change for the separate Spec PR.

  • Spec/RsaKeyGen/GenerationAgrees.lean: SearchAgrees, primeSearch_agrees, primeSearch_used_le, searchFrom, searchFrom_init, and 9 private helpers.
  • Spec/RsaPkcs1Enc/Contract.lean: encryptContract, encryptSig.
  • Spec/RsaPkcs1Sig/Contract.lean: recoverContract, recoverSig, verifyContract, verifySig.
  • Spec/RsaPss.lean: SaltLength (with .sign and .verify), dropWhile_db, eq_db, eq_db_of_take, verifyEncodingRfc, verifyEncoding_some.

Not in this PR

Generic/MillerRabin/X86/RsaKeyGen.lean has a -- shake: keep (the public artifact body uses code_all) comment. It was already stale before this PR, and is now more so: code_all is removed. Registration files only drop imports here, so it is left for a reviewed edit.

Checks

  • Lean:
    • the full lake build passes (28,824 jobs);
    • Emit.lean --check passes, with the standard-axiom, compiler-override and spec-origin audits, so no crate changes;
    • check_lean_public_imports --base origin/main passes on the modules whose imports changed.
  • Static checks: every step of the job passes, with check_lean_single_importer.py --base origin/main. The steps are:
    • check_lean_imports, check_lean_modules, check_lean_single_importer
    • check_case_collisions, check_registrations, check_lean_speed
    • audit_base check, algorithms_table --check
    • check_arch_gates, check_variants, check_skills
    • the VG_CPU_FEATURES grep, cpu_tests lint
    • run_unit_tests, check_mcdt, check_vectors
  • Rust: cargo fmt --check and cargo clippy --all-targets -- -D warnings pass. No Rust changed.
  • No escape hatches: nothing adds sorry, native_decide, bv_decide or maxHeartbeats.
  • Rerunning the analysis on the result: nothing dead is left in scope beyond what is kept above.
  • Against current main (683 Lean files changed upstream, none of this PR's): no upstream file imports a deleted module, and none names a removed declaration in full. The CI Lean build on the merge commit is the final check.

No benchmark: the emitted code is unchanged.


Generated by Claude Code

@reaperhulk
reaperhulk added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit dd2337b Nov 6, 2026
23 checks passed
@reaperhulk
reaperhulk deleted the claude/unify-random-bytes-crypto-xqmg0z-deadcode-rsa branch November 6, 2026 18:24
alex pushed a commit that referenced this pull request Nov 7, 2026
…SA modules it uses (work in progress)

Main's dead-code removals (#4305, #4336, #4344, #4367) deleted RISC-V
modules and declarations that only this search uses. Restore them as
they were before each removal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
alex pushed a commit that referenced this pull request Nov 7, 2026
…me_out beside their use

#4344 removed them from Proof/Rsa/RISCV64/KeyLayout.lean as dead; only
this search uses them.

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