Repository navigation
AES-GCM: write and wipe only the key context's proven bytes on x86-64 - #3317
Merged
Merged
Conversation
AesGcm::new zeroed the whole 1 KiB key context, and drop wiped all of
it, though the AES-NI+AVX and VAES-256 backends' prepare16 write only
its first 512 bytes. The registrations now state that bound
(`written := [("ctx", 512)]`, proven from each implementation's frame),
the context is a MaybeUninit, new clears only init's 256 bytes, and
drop wipes the bytes its backend's `_CTX_WRITTEN` names (all of them
for AVX-512, 256 for backends without prepared instances).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FoYWDDEDFq1DFev5X7n2aq
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.
AesGcm::newzeroed the whole 1 KiB key context, anddropwiped all of it. But the AES-NI+AVX and VAES-256 backends'prepare16write only the first 512 bytes. This is the same fix as #3167 for AES-ECB's scratch, applied to GCM key setup.Proofs and registration
Proof/Gcm/X86_64/PrepareCT.leanaddsPrepare16.written16. It turns aprepare16implementation's frame (memory outside[ctx + 256, ctx + 512)unchanged) intoSig.writtenWithin … [("ctx", 512)].PrepareAvx/Ok.lean(its invariant's frame narrowed from 768 to 256 bytes past the key context) andPrepare16.lean.Artifacts/Gcm/X86_64.leangives bothprepare16artifactswritten := [("ctx", 512)]andwrittenOk. The emitter exportsVG_AES_GCM_PREPARE16_{PCLMUL_AVX,VPCLMUL}_CTX_WRITTEN = 512.TCB/orSpec/changes.Rust (
src/aes_gcm.rs)MaybeUninit<KeyCtx>.newclears only the 256 bytesvg_aes_gcm_initwrites (keyreads them), andpreparewrites its proven bytes after them. Nothing reads the rest.Fns/Preparedcarrywritten, whichdropwipes withzeroize_raw:_CTX_WRITTENconstant for the twoprepare16backends;preparewrites all 48 powers;KeyCtxon other architectures, as before.with_backendwipes the old backend's powers before switching, sincedropwipes only up to the new backend'swritten.eager_powerscompares only the written words.Benchmarks
The Benchmarks gate was x86_64
aes_gcm, default and forced AES-NI+AVX (aes,avx,pclmulqdq,ssse3), with base a793a45:None of the three runs drew a Zen 5 runner. Zen 5 takes the AVX-512 backend by default. There the change only removes
new's zero-fill of the 768 bytes after the key context, whichprepareoverwrites, anddropstill wipes the whole context. So Zen 5 does strictly less work innewand the same indrop.Other rows more than 0.7% slower: AES-GCM-SIV,
stream-bytes/64, the two-piece reused-key andtls-sealrows on one Zen 3 AVX job, andtls-open/63. The code they run is unchanged. Comparing--emit asmof the library (one codegen unit) at base and at this branch, onlyAesGcm::newand<AesGcm as Drop>::dropdiffer.AesGcm::encrypt,encrypt_in_place,open_with, the streaming types and all ofAesGcmSivare identical. These rows also flip between runs: SIV decrypt/64 was 9.2% faster on Zen 3 in the first run and 2.9% slower in the third.AArch64 (
aes_gcm, default; 40015103240):gcm-new−0.6%,tls-connection/1−0.5%.tls-openat 111–255 is 1.1–1.3% slower. AArch64's open path is unchanged (self.ctx.as_ptr()in place of&self.ctx, same type and layout), and itsKeyCtxis the 256 bytesnewalready cleared.Generated by Claude Code