Skip to content

Spec: retire the Apis of vg_rsa_prime_search, vg_rsa_prime_search_init and vg_rsa_keygen_key - #4419

Merged
alex merged 1 commit into
mainfrom
claude/audit-4139-rsa-keygen
Nov 7, 2026
Merged

alex merged 1 commit into
mainfrom
claude/audit-4139-rsa-keygen

Conversation

@alex

@alex alex commented Nov 7, 2026

Copy link
Copy Markdown
Member

Part of #4139 (finding 1: RSA key generation's outer loop)

This retires what #4368 left without a Rust caller, following #4303 and #4377. Since #4368, vg_rsa_generate calls the prime search and the key from verified code, on every target. Nothing calls the prime search's init.

Trust change (removal only)

This PR removes trusted definitions from Spec/ and adds none. No contract that remains is weakened.

  • Spec/RsaKeyGen/GenerationContract.lean is deleted. It held three groups of definitions:

    • primeInitSig, primeInitContract and primeInitApi: the init is dead.
    • primeSearchApi.
    • primeSearchSig and primeSearchContract. These move, unchanged, to Proof/RsaKeyGen/SearchContract.lean, which is untrusted. The prime search is now an internal function.
  • Spec/RsaKeyGen/Contract.lean loses five definitions:

    • keyApi.
    • keySig, keyContract, keyOp and keyStatus. Only the key's contract used keyOp and keyStatus. All four move, unchanged, to Proof/RsaKeyGen/Contract.lean, next to the contract of the key's own helper, vg_rsa_keygen_inverse.
    • The file's docstring now describes only what it still holds: primeLenValid, otherPrime and the candidate's candidateOp, candidateStatus and candidateLeak.
  • Docstrings only, in four files. They named the moved contracts, and now say what those contracts meant directly:

    • Spec/RsaKeyGen/Generation.lean: the first tape's length is the code's choice, within Entropy.RequestValid.
    • KeySearch.lean: the timing may depend on each prime search's trace (primeSearch's) and each key's status (keyResultStatus).
    • GenerationAgrees.lean: vg_rsa_generate runs primeSearch for each prime.
    • KeySearchContract.lean:
      • the state's first four words are primeSearch's;
      • keySearchApi's summary now says what the search for each prime and the key do, instead of pointing at the retired functions;
      • its timing clause now names the prime searches' rejected candidates and accepted reads, and each key's status. That is what keySearchContract's leak (keySearch's trace) already contains.

    No definition in these four files changes.

Proofs and code

  • References move from Spec.RsaKeyGen.{primeSearchSig, primeSearchContract, keySig, keyContract, keyOp, keyStatus} to Proof.RsaKeyGen.*. Each module that uses them imports Proof/RsaKeyGen/Contract.lean or SearchContract.lean.
  • The prime search's init is deleted:
    • On x86-64, x86, AArch64, PPC64LE and RISC-V, both Impl/RsaKeyGen/<T>/SearchInit.lean and Proof/RsaKeyGen/<T>/SearchInit.lean are deleted. No registration emits them since RSA key generation: the whole generation in verified code #4368.
    • x86-64's prime-search proofs had imported its SearchInit only for the helpers in Proof/RsaKeyGen/InitWords.lean, which they now import directly.
  • Arm keeps its SearchInit, because DSA's Arm key generation reuses its code and proofs (Impl/Dsa/Arm/Generation.lean, Proof/Dsa/Arm/Gen/Init.lean). It loses only init_verified, the proof against the deleted contract.
  • Test: VerifiedGarbageTest/RsaPrimeSearch.lean now:
    • imports Proof/RsaKeyGen/SearchContract.lean;
    • asserts the standard axioms of Proof.RsaKeyGen.primeSearchContract;
    • asserts that the two functions it evaluates, primeInit and primeSearch, have no compiler overrides.

Generated code

Only vg_rsa_generate's doc comment changes, in each target's rsa_keygen.rs: the keySearchApi summary above. The functions themselves are unchanged. The prime search and the key were already internal since #4368.

Overlap: the open dead-code PRs don't touch RsaKeyGen, and #4392 merged and kept RsaKeyGen whole.

Testing

All of these ran locally on main (dfb1dd9):

  • lake build, then Emit.lean. Its audits passed: standard axioms only, and every VG.Spec definition is in Spec/.
  • Every step of the Static checks job.
  • check_lean_public_imports.py --base origin/main on the 56 edited modules.
  • cargo fmt --check and cargo clippy --all-targets -D warnings.
  • The RSA key generation tests.

No Rust changed, and no emitted function's code changed. Nothing here can affect speed, so there is no benchmark run.


Generated by Claude Code

…t and vg_rsa_keygen_key

Since #4368 no Rust calls them: vg_rsa_generate calls the prime search
and the key from its verified code, and nothing calls the search's init.

- Spec loses primeInitSig, primeInitContract, primeInitApi, primeSearchApi
  and keyApi; Spec/RsaKeyGen/GenerationContract.lean is deleted.
- primeSearchSig and primeSearchContract move, unchanged, to
  Proof/RsaKeyGen/SearchContract.lean; keySig, keyContract, keyOp and
  keyStatus to Proof/RsaKeyGen/Contract.lean.
- The Spec docstrings that named the moved contracts describe what they
  meant directly.
- The prime search's init is dead: its Impl and Proof modules are deleted
  on x86-64, x86, AArch64, PPC64LE and RISC-V. Arm keeps them, which DSA's
  key generation reuses, without init_verified.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHJ2FcxfeqKwuVNLR6Y
@alex
alex enabled auto-merge November 7, 2026 09:39
@alex
alex added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit e0adf68 Nov 7, 2026
38 checks passed
@alex
alex deleted the claude/audit-4139-rsa-keygen branch November 7, 2026 10:15
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