Repository navigation
MdStream x86-64: bound each indexed buffer store by clamping its index - #4745
Merged
Merged
Conversation
…x; re-prove Each store into the buffer of the streaming (MdStream) and one-shot (OneShot) Merkle–Damgård code goes through one memory operand, whose index is first clamped to the buffer (mov32 lim; cmp idx, lim; cmovb lim, idx): the same value whenever the existing invariant holds, so the proofs are the same but for that lemma, and the residue analysis can tell the store stays in the buffer. Covers MD5, SHA-1, SHA-2 and SM3 on x86-64. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
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.
Groundwork for verified residue clearing on x86-64 (proving that a function leaves no secret in registers or on the stack when it returns). It changes no contract, spec or TCB.
What changes
Every store into the 64- or 128-byte block buffer of the streaming (
Impl/MdStream/X86_64.lean) and one-shot (Impl/MdStream/X86_64/OneShot.lean) Merkle–Damgård code now goes through one memory operand,bufByteandblkByte. Its index is first clamped to the buffer:Whenever the existing invariant holds (the index plus the width fits the buffer), this is the same index, so the stored bytes and every contract are unchanged. The proofs are the same but for that one lemma (
Proof/MdStream/X86_64/Common.lean).Why
The residue analysis can only tell that a store stays in the buffer from a bound on its index register. Without the clamp, the bound is a relation between two registers (
r13 + rax ≤ 64), which it does not track. The analysis then assumes the store may hit any stack slot, and gives up on knowing which slots hold secrets. The clamp gives the bound directly.Affected
Every x86-64 MD5, SHA-1, SHA-2 and SM3 function (streaming update/finalize, one-shot digest), and their HMAC, PBKDF2 and ECDSA-RFC 6979 callers' scratch helpers: the regenerated
crates/verified-garbage-asm-x86_64/files.Checks
lake build,Emit.lean, the Static checks job,check_lean_public_imports.pyon the edited modules: pass (on PPC64LE DSA: R² mod p by r2Hi (r2Prime when p's top word is zero) #4678; it merges cleanly with TCB: dispatch each function's implementations in the order its file lists them #4685, which changed only dispatcher files).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 42525736855: x86-64, every
VG_CPU_FEATURESconfiguration that chooses among these modules' implementations, against #4678. No benchmark slowed by more than 5%.none.noneshard holding MD5, SHA-224, SHA-384 and SM3: within ±5% either way, where the spread between copies of the same binary was 3–17%.A local run had shown SHA-256 1–4% slower with
none; the runners do not reproduce it.🤖 Generated with Claude Code
https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa