Repository navigation
x86-64 SEED, Camellia and SM4 modes return without secret residue - #4895
Merged
Merged
Conversation
Key expansion (but SM4's) and the ECB, CBC, CFB128 and OFB functions of SEED, Camellia and SM4 on x86-64 are followed by the residue scrub (`X86_64.Scrub.withScrub`), with their postconditions shown to read the memory on return only within the buffers (`PostOut`), in `Proof/Seed/X86_64/Scrub.lean`, `Proof/Camellia/X86_64/Scrub.lean` and `Proof/Sm4/X86_64/Scrub.lean`. The registration files bind them, and the 32 functions leave `ci/residue_allowlist.txt`. Camellia's and SM4's CTR functions stay listed (`vg_*_ctr_final` calls `vg_*_ctr` by name with its code as it is, and its own analysis fails), as does `vg_sm4_expand_key`, which SM4-GCM calls by name, and SM4-GCM, whose analysis fails. 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
reaperhulk
marked this pull request as draft
November 10, 2026 11:48
|
This pull request has conflicts with Posted by |
…amellia-sm4 # Conflicts: # ci/residue_allowlist.txt
The residue analysis now knows the stack pointer after a return, so the scrub tails no longer wipe the frames that the code already wiped. 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.
A residue burn-down, following #4892 (Blowfish and IDEA). It converts the ECB, CBC, CFB and OFB functions of SEED, Camellia and SM4, plus SEED's and Camellia's key expansion, taking 32 lines off
ci/residue_allowlist.txt. No trust change: nothing underTCB/orSpec/changes.What is converted
expand_key;ecb_encryptandecb_decrypt;cbc_encrypt_chainedandcbc_decrypt_chained;cfb128_encrypt,cfb128_decryptand their_finalforms;ofbandofb_final.expand_key.Each function is scrubbed with
X86_64.Scrub.withScrub, using a residue analysis the kernel checks, as in #4892.What the scrub adds: these functions already wipe their stack scratch themselves (
withStackScratchWiped). Since #4907 the analysis counts that wipe, so each scrub tail adds one wipe store besides clearing registers. The first version of this PR, built before #4907, wiped the whole frame a second time: 205 stores for each Camellia mode, 201 for SM4, and 97 for SEED (69 for ECB).What stays listed, and why (30)
vg_camellia_ctrandvg_sm4_ctr:vg_*_ctr_finalcalls them by name with their current code (Impl/*/X86_64/CtrFinal.lean).vg_sm4_expand_key: SM4-GCM calls it by name with its current code.In these cases the emitter refuses a name whose code differs from the code its callers run. Converting them needs the callers to call the unscrubbed code under a name of its own, as x86-64 hash inits, SHA-512 digest and zeroize return without secret residue #4904 does for the hash inits.
vg_camellia_ctr_finalandvg_sm4_ctr_final: the analysis rejected them when this PR was written. Since x86-64 residue analysis: know the stack pointer again after a return #4907 it passes, so a follow-up needs only theirPostOutproofs.The 25 SM4-GCM functions: the analysis does not complete on them. Converting them needs work on the code or the analysis.
Proofs
Proof/{Seed,Camellia,Sm4}/X86_64/Scrub.lean(new): onePostOutproof per contract.*PostOut_localandProof.Modes.*FinalPost_locallemmas.Artifacts/{Seed,Camellia,Sm4}{,Cbc,Cfb,Ofb}/X86_64.lean) now only bind the scrubbed registrations.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 42852455288, at this head, against
ac141ad29. It covers x86-64, the ECB, CBC, CFB and OFB benchmarks of SEED, Camellia and SM4 (105 benchmarks), in one interleaved run.🤖 Generated with Claude Code
https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa