Skip to content

x86-64: SM4 key expansion returns without secret residue - #4966

Merged
reaperhulk merged 1 commit into
mainfrom
claude/residue-core-sm4-expand-key
Nov 12, 2026
Merged

reaperhulk merged 1 commit into
mainfrom
claude/residue-core-sm4-expand-key

Conversation

@reaperhulk

Copy link
Copy Markdown
Member

vg_sm4_expand_key now ends with scrubTail (withScrub, Proof/Sm4/X86_64/Scrub.lean). The tail wipes the one 8-byte stack granule that the residue analysis finds may hold secrets, and clears the registers. Its line leaves ci/residue_allowlist.txt.

SM4-GCM's init calls key expansion by name, and the emitter refuses a function called by name whose code changes. So it now calls the unscrubbed code as an internal function of its own, vg_sm4_expand_key_core (Impl.Sm4Gcm.X86_64.keyFn). This is the same _core pattern as #4904 and #4951.

Nothing under TCB/ or Spec/ changes.

Benchmarks

Run 43072205210: every sm4 benchmark on x86-64, in every VG_CPU_FEATURES configuration, compared with 8564b91.

  • The change adds one 8-byte store and the register clearing to each key expansion.
  • Across the configurations, rows move within about ±5% in both directions, with no pattern by mode or size.
  • The largest single change is sm4-ctr/64 at aes,pclmulqdq,ssse3, 8.3% slower (3.38 → 3.66 µs). Within that same configuration, sm4-ofb and sm4-cfb128-encrypt are faster, and the CTR row is flat in the others.

Checks

All passed locally, after rebasing onto main with #4951 and #4962:

  • full lake build;
  • Emit.lean then --check;
  • every step of the Static checks job;
  • check_lean_public_imports.py --base origin/main;
  • cargo fmt and cargo clippy;
  • cargo test, and the VG_CPU_FEATURES=none run.

Generated by Claude Code

vg_sm4_expand_key is followed by scrubTail (withScrub,
Proof/Sm4/X86_64/Scrub.lean), which wipes the one 8-byte granule of its
stack the residue analysis finds may hold secrets. SM4-GCM's init, which
calls it by name, now calls its unscrubbed code as an internal function of
its own, vg_sm4_expand_key_core (Impl.Sm4Gcm.X86_64.keyFn). Its line leaves
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 12, 2026
Merged via the queue into main with commit 8bed970 Nov 12, 2026
48 checks passed
@reaperhulk
reaperhulk deleted the claude/residue-core-sm4-expand-key branch November 12, 2026 12:16
alex pushed a commit that referenced this pull request Nov 12, 2026
Brings in #4990, #4986, #4988, #4975 and #4966. The generated x86 rsa
crate conflicted with #4990's; it is regenerated in the next commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHH1um6BHmQjMB1jTPh
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