Skip to content

x86-64 hash inits, SHA-512 digest and zeroize return without secret residue - #4904

Merged
reaperhulk merged 3 commits into
mainfrom
claude/residue-core-names
Nov 10, 2026
Merged

reaperhulk merged 3 commits into
mainfrom
claude/residue-core-names

Conversation

@reaperhulk

@reaperhulk reaperhulk commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Continues the x86-64 residue burn-down (#4836). It converts 12 functions to prove NoResidue, and removes their 12 lines from ci/residue_allowlist.txt (−12/+0). No trust change: nothing under TCB/ or Spec/ changes.

These functions passed the residue analysis already. They stayed listed only because other verified code calls them by name: scrubbing the exported function changes the code that call runs, and the emitter refuses that. As with vg_poly1305_init_core (#4836), the callers now call the unscrubbed code under an internal _core name, and only the exported function is scrubbed.

What is converted

  • Inits (8): vg_md5_init, vg_sha1_init, vg_sha224_init, vg_sha256_init, vg_sha384_init, vg_sha512_init, vg_sha512_224_init and vg_sha512_256_init. Their tails clear registers only.

  • SHA-512 digest (2):

    • vg_sha512_digest wipes 144 bytes (9 stores);
    • vg_sha512_digest_shani wipes 32 bytes (2 stores).

    This matches the SHA-384 digests, which are already scrubbed.

  • Zeroize (2): vg_zeroize and vg_zeroize_avx. Their tails clear registers only.

New modules: Proof/{Sha1,Sha256,Sha512}/X86_64/Scrub.lean and Proof/Zeroize/X86_64Scrub.lean. The MD5 init is added to Proof/Md5/X86_64/Scrub.lean, and the SHA-512 digests to Proof/Variants/MdHash/X86_64/Sha512{,ShaNi}.lean.

The internal _core functions and their callers

  • vg_md5_init_core, vg_sha1_init_core, vg_sha224_init_core, vg_sha256_init_core, vg_sha384_init_core, vg_sha512_init_core, vg_sha512_224_init_core and vg_sha512_256_init_core:
    • HMAC and PBKDF2 (Proof/Pbkdf2/Md/X86_64/Hashes/*.lean);
    • the DSA parameter searches (SHA-1, SHA-256);
    • RSA PKCS#1 (SHA-224, SHA-256);
    • Ed25519 sign and verify (vg_sha512_init_core). Only the name string changes in Impl/Ed25519/X86_64/{SignCached,VerifyMessage}.lean and four proofs that mention it.
  • vg_sha512_digest_core, _shani_core and _avx2_core: Ed25519 key-pair generation (Artifacts/Ed25519/X86_64.lean names them digest512Api.name ++ c.suffix ++ "_core").
    • The AVX2 one is a copy of the code that is still listed. It is included so Ed25519 needs no change when the AVX2 digest is converted.
    • Each copy is a small function: the compression function it calls is shared.
  • vg_zeroize_core and vg_zeroize_avx_core: AES-CBC, AES-ECB and ML-KEM, through the Zeroize variants (Proof/Zeroize/X86_64Impl.lean).

Of the 238 changed files, 26 are written by hand. The other 212 are regenerated crate files: the new _core functions, and every caller's assembly and src, whose call names changed.

What stays listed

  • vg_sha512_digest_avx2: the analysis fails on its code, as it does on the rest of SHA-512's AVX2 family.

Checks

  • lake build (all modules), Emit.lean and Emit.lean --check: pass.
  • The Static checks job (--base origin/main where it applies): pass.
  • check_lean_public_imports.py: pass.
  • cargo fmt --check and cargo clippy --all-targets -- -D warnings: pass.
  • cargo test with Wycheproof, with every CPU feature and with VG_CPU_FEATURES=none: pass.

Speed

The callers run the same code as before under new names. The exported inits, digests and zeroize add a short tail.

Benchmarks run 42797918755: x86-64, sha512 sha256 sha1 md5 against the merge base, in every configuration that chooses among their implementations. One interleaved run.

  • SHA-512 (the digest's 144-byte wipe):
    • with the scalar code: 7.0% slower at 64 B (256 → 274 ns);
    • with sha,ssse3: 4.2% slower at 64 B (281 → 293 ns);
    • every other size and configuration within ±2%.
  • SHA-256, SHA-1 and MD5 (the inits): within ±1.1% at every size and in every configuration.

🤖 Generated with Claude Code

https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa

…residue

vg_md5_init, vg_sha1_init, vg_sha224_init, vg_sha256_init, the SHA-512
family's four inits, vg_sha512_digest and vg_sha512_digest_shani, and
vg_zeroize and vg_zeroize_avx are scrubbed (withScrub, StreamFn.scrub).
The verified code that calls them by name (HMAC, PBKDF2, DSA, RSA, Ed25519,
AES-CBC/ECB and ML-KEM through the Zeroize variants) calls their unscrubbed
code as internal functions of their own, vg_<name>_core, as
ChaCha20-Poly1305 calls vg_poly1305_init_core. Their lines leave
ci/residue_allowlist.txt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 10, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 10, 2026

Copy link
Copy Markdown
Member Author

The merge queue failed this PR on Emit.lean --check: crates/verified-garbage-asm-x86_64/{src/rsa_pkcs1_enc.rs,assembly/rsa_pkcs1_enc.s} are out of date. This PR and #4898 both regenerated rsa_pkcs1_enc, and their changes merged as text into a file the emitter would not write. A merge of main and a regeneration are coming; it needs re-queueing after that.


Generated by Claude Code

@reaperhulk
reaperhulk added this pull request to the merge queue Nov 10, 2026
The IFMA CRT decryption that main added calls vg_sha256_init, which this
branch renames to vg_sha256_init_core.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 10, 2026
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit 6a9ae99 Nov 10, 2026
33 checks passed
@reaperhulk
reaperhulk deleted the claude/residue-core-names branch November 10, 2026 19:47
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