Repository navigation
TDEA-CMAC streaming on x86-64: a working space of the size the code uses - #4937
Merged
Merged
Conversation
The code of `init`, `update` and `finalize` that `vg_cmac_triple_des_stream_init`, `_absorb` and `_finish` run uses only slots 0-14 (120 bytes) of its 640-byte working space. Their scrub tails wiped the whole frame: stores the residue analysis cannot place (the round keys through the advancing `rbp` in `init`, the byte copies indexed by a loop counter in `absorb` and `finalize`) drop every public slot of the frame, so all of it is listed on free. The working space is now 120 bytes (160 for `absorb`, which keeps our caller's registers at 120 rather than 640), so the frames are 128 and 168 bytes: the tails wipe 8, 11 and 8 granules instead of 41, 44 and 41 (128/168/128 bytes instead of 656/704/656 per call). The proofs only change the region sizes; x86-64 states its own contracts with the working space as an argument (`Stream/X86_64/Implies.lean`). No contract in `Spec/` changes. 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.
This PR makes the x86-64 TDEA-CMAC streaming functions,
vg_cmac_triple_des_stream_init,_absorband_finish, reserve only the stack scratch their code uses. Their scrub tails (#4897) then wipe 4–5× less. No trust change: nothing underTCB/orSpec/changes, and the contracts the Rust code sees only shrink their stack bound.Why the tails were large
Each function took a 640-byte working space. The tail wiped the whole frame on every call: 41, 44 and 41 granules (656/704/656 bytes).
init,updateandfinalizeonly use slots 0–14 (120 bytes):[0,48));[48,96));absorbalso keeps the caller's callee-saved registers at[640,680). Bytes[120,640)were never written.The residue analysis still selected the whole frame, because each function makes one store it cannot place:
init's loop, whose base register advances by 128;copy's[rdx+r10]inabsorb;finalize's[r15+r10+96]infinish.Each such store makes every byte of the frame possibly secret. Wiping the scratch in the code (
withStackScratchWiped) would not help, since the analysis would still select the frame. Wiping fewer bytes means a smaller frame.The change
absorb, whose saves of the caller's registers move from 640–672 to 120–152 (savedinImpl/CmacTripleDes/Stream/X86_64.lean). The frames go from 648/696/648 to 128/168/128 bytes. The code is otherwise unchanged.Proof/CmacTripleDes/Stream/X86_64/Implies.lean).Frame.leanandScrub.leanpass the new frame sizes. The other architectures and the sharedStreamScratch.leando not change.vg_cmac_triple_des_stream_initvg_cmac_triple_des_absorbvg_cmac_triple_des_finishChecks
lake build(all modules),Emit.leanandEmit.lean --check: pass.--base origin/mainwhere it applies): pass.check_lean_public_imports.py: pass.cargo fmt --checkandcargo clippy --all-targets -- -D warnings: pass.cargo testwith Wycheproof, with every CPU feature and withVG_CPU_FEATURES=none: pass. That includes the TDEA-CMAC CAVP and unit tests.Speed
Benchmarks run 42944776393: x86-64,
cmac_triple_desagainst02b499097, in the default configuration, one interleaved run.tdes-cmacandtdes-cmac-verifyare within ±0.2% at 64 B, 1 KiB and 16 KiB. For example,tdes-cmac/64went from 16.48 to 16.44 µs.🤖 Generated with Claude Code
https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa