Repository navigation
x86-64 SHA-1, SHA-224, the SHA-512 family, MD5 and SM3 return without secret residue - #4842
Merged
Merged
Conversation
…sidue SHA-224's finalize and digest over each SHA-256 compression function, SHA-1's update, finalize and digest over each of its own, and SHA-384's, SHA-512's, SHA-512/224's and SHA-512/256's over the scalar and SHA-NI compression functions, scrubbed as SHA-256's are (StreamFn.scrub): each variant file checks the residue analysis of its own code with taint_decide, and the PostOut lemmas of each spec say its postconditions read only the buffers. The SHA-512 AVX2 functions stay listed: the analysis does not yet accept them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
MD5's and SM3's init, update and finalize, and the init of SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224 and SHA-512/256, each scrubbed with withScrub and its residue analysis checked by taint_decide; their registration files bind the results. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
HMAC, PBKDF2, DSA and RSA call each hash's init by its exported name, with its unscrubbed code, so scrubbing those needs a separate name for the callers' code (as vg_poly1305_init_core): a change of its own. SM3's init, which nothing calls, stays converted. Removes the 37 converted functions' lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
Ed25519's key-pair generation calls vg_sha512_digest (and its SHA-NI variant) with its unscrubbed code, so it waits for a callers' name of its own, as the hash inits do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
This was referenced Nov 10, 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.
The first burn-down after #4836. It converts the rest of the Merkle–Damgård hashes, taking 36 lines off
ci/residue_allowlist.txt(861 → 825). No trust change: nothing underTCB/orSpec/changes.What is converted
Each function is scrubbed the way #4836 scrubbed SHA-256. Its code is followed by
scrubTail, which clears what the residue analysis finds may hold secrets, and the kernel checks that analysis withtaint_decidein the module that registers the function.update,finalizeanddigest, for the scalar, AVX/BMI and SHA-NI compression functions (9).finalizeanddigest, over each SHA-256 compression function (6).updateandfinalize.finalizeanddigest.updateandfinalize(2).init,updateandfinalize(3).What stays listed, and why
digest: Ed25519's key-pair generation callsvg_sha512_digestandvg_sha512_digest_shaniby name.initfunctions of MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224 and SHA-512/256: HMAC, PBKDF2, DSA and RSA call each by its exported name.In both of the last two cases, the emitter refuses a name whose code differs from the code its callers run. Converting them takes what #4836 did for Poly1305's
init: the callers call the unscrubbed code under a name of its own (vg_poly1305_init_core). That changes every caller's generated code, so it gets its own PR.Proofs
Hashes/Sha1Scrub.lean,Hashes/Sha512Scrub.lean, and SHA-224's part ofHashes/Sha256Scrub.lean: eachPostOutfact says the function's postcondition reads memory on return only within its buffers. That is the streaming state (repr_congr) and the digest.Hashes/Sha1.lean,Sha224.leanandSha512.lean: each stream list is split into one definition per function, as x86-64: the residue analysis and scrub, an allowlist that only shrinks, and SHA-256, Poly1305 and ChaCha20 apply without residue #4836 did for SHA-256.Variants/MdHash/X86_64/Sha1.lean,Sha512.leanandSha512ShaNi.lean(new), plus the existing SHA-1 and SHA-256 variant files: the scrubs, each checked against its own variant's code.Proof/Md5/X86_64/Scrub.leanandProof/Sm3/X86_64/Scrub.lean: registrations built withwithScrub, whichArtifacts/{Md5,Sm3}/X86_64.leanbind.Checks
lake build(all modules),Emit.lean --check, the Static checks job,check_lean_public_imports.pyon the changed modules: pass.cargo fmt --check,cargo clippy --all-targets -- -D warnings: pass.cargo testwith Wycheproof, with every CPU feature and withVG_CPU_FEATURES=none: pass.Speed
Benchmarks run 42657421527: x86-64, against #4836's merge, on an AMD EPYC 7763, one interleaved run. It covers the
md5 sha1 sha224 sha384 sha512 sha512-224 sha512-256 sm3groups, in every configuration that chooses among their implementations.The scrub is a fixed cost per call. No benchmark slowed by more than 4.0%, and none by more than 12 ns:
avx,avx2,bmi1,bmi2(312 → 324 ns), 3.2% withsha,ssse3(93 → 96 ns). At 1 KiB, 0.4%.sha,ssse3(the scalar compression function): 3.8% slower (257 → 266 ns).The default and
avx,avx2,bmi1,bmi2configurations show SHA-384, SHA-512, SHA-512/224 and SHA-512/256 8–11% faster at 32–111 B. They run the SHA-512 AVX2 code, which this PR does not change, so I don't credit this PR with the speedup: it is noise or code layout.The AVX-512 IFMA configuration was not measured, since the runner lacks it. It runs the same hash code as the default configuration.
🤖 Generated with Claude Code
https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa