Repository navigation
AES-GCM x86-64: AES-NI+AVX seal ends without calls - #1688
Merged
Merged
Conversation
…re emit) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FoYWDDEDFq1DFev5X7n2aq
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.
What
On the AES-NI+AVX backend (
_aesni_pclmul_avx),vg_aes_gcm_sealhandles the end of the text with calls:vg_aes_ctr32_aesnifor the keystream of the last partial block,vg_ghash_pclmulfor the padded tail and again for the lengths block, thenvg_aes_ctr32_aesnionce more for the tag'sE(K, J₀). A profile of a 385-byteAesGcm::encryptshowedvg_ghash_pclmulandvg_aes_ctr32_aesnitaking about 25% of the time; at 1025 bytes they took 17%. This is most of the out-of-place gap to aws-lc-rs, and it affects every text that doesn't end on a block boundary.#1485 removed these calls from the AVX-512
seal(Short.finish). This PR makes that end usable without AVX-512:Short.finishbecomesShort.finishWith ks, parameterised by the program that computes the keystream ofJ₀and of the counter block intoK. The AVX-512finishisfinishWith finKs, unchanged.Short.finKsAcomputes the same two blocks with AES-NI on 128-bit registers (AesNi.aes [xmm5, xmm7]).SealFin.sealis the other instances'sealup to the whole blocks, thenfinishWith finKsA.GcmImpl.fin, set byStitchName.finfor the AES-NI+AVX loops only, selects it insealCode. That coversseal,seal_precomputed,seal_preparedand the gather'sseal.openis unchanged.This is part of #1228, following the rustls analysis in #991. It is independent of #1684 (the AES-NI+AVX loop's tail), which changes
encrypt_blocksrather thanseal.Measurements
Measured with the AES-NI+AVX backend chosen (
VG_CPU_FEATURES=avx,avx2,avx512f,avx512bw,avx512vl,bmi1,bmi2,adx,aes,pclmulqdq,ssse3), and aws-lc-rs masked to the same withOPENSSL_ia32cap='~0x0:~0x574220200000'. Xeon, pinned to one core, 16-byte key, 13-byte AAD, best-of-11 in ns, two alternating runs each, main → this PR. "+1" isAesGcm::encryptofn + 1bytes from two slices, so the text ends inside a block; for aws-lc-rs it is a copy plusseal_in_place_separate_tag.Texts ending inside a block are 20–60 ns faster. At 512 and 4096 bytes the out-of-place path is now level with aws-lc-rs. In-place texts of whole blocks take the same path's no-tail branch and are unchanged within noise.
Proofs
Assembly comes only from the Lean code. Spec, TCB and contracts are unchanged.
Short/Finish.lean:sealBodyF_oktakes the keystream program and its spec (KsOk ks,finKs_ok's effect, withxmm8also written);finKs_ksOkinstantiates it.Short/CT.lean:finish_relandsealRunF_reltakeKsOk ksandKsRel ks, the keystream program in two runs;finKs_relis the AVX-512 piece that was inline.Short/KsA.lean(new):finKsA_ksOk(fromAesNi.aes_ok) andfinKsA_rel(taint_decide: the rounds inrsiare public).Short/SealFin.lean(new):SealFin.seal's correctness (sealM_ofwithsealRunF_ok), constant time (sealM_relOfwithsealRunF_rel), and itsmxcsr,rspand stack facts. The selectors inShort/Verified.lean,Prepared/Short.leanand the generic file gain the third case.The existing tests cover the new path on CPUs with these features:
long_tails_agree, which checks every backend the CPU can run against the scalar one with partial tails, plus the Wycheproof and CAVP AES-GCM vectors.🤖 Generated with Claude Code
https://claude.ai/code/session_01FoYWDDEDFq1DFev5X7n2aq
Generated by Claude Code