Constant-time AES-GCM bulk batching, mode-wide in-place AEAD correctness#160
Merged
Merged
Conversation
Constant-time AES-GCM bulk batching, mode-wide in-place AEAD correctness, and non-lagged fused decrypt Bulk batching (constant-time software AES-GCM): - TAesBitSlicedEngine implements IBulkBlockCipher, transforming four blocks per pass (the aes_ct64 lane width) with a 1..3-block tail; bit-exact with N sequential ProcessBlock calls. SIC/CTR over it now batches automatically. - GCM gains a software-bulk 4-block path (bulk AES keystream + scalar GHASH) gated on the engine being bulk-capable rather than on SIMD GHASH, so the bitsliced + software-multiplier stack batches even without hardware GHASH. - Scalar aggregated 4-way GHASH: split the field multiply into MultiplyNoReduce + ReduceProduct and fold four blocks with a single reduction (reduction is XOR-linear); H^1..H^4 precomputed per key. - TGcmBlockCipher gains a destructor and zeroizes the hash subkey, H-power tables, keystream buffers and last key on teardown/rekey. In-place AEAD correctness (out buffer aliasing in buffer): - In-place GCM was broken mode-wide in both directions. Fixed uniformly: CipherBlock/CipherBlocks2 use the three-operand XOR (read both sources before writing), and every block step orders GHASH so decrypt folds the input before the XOR overwrites it and encrypt folds the output after. - EAX (the only other affected mode) captures each block's ciphertext into the OMAC look-ahead before the in-place counter transform overwrites it. - The other block-cipher modes were reviewed and are already in-place safe. Non-lagged fused decrypt (x86_64, i386, aarch64): - The fused CTR + 8-way GHASH kernel lagged GHASH by one batch, so in-place decrypt read overwritten memory. Encrypt still lags (its ciphertext is the output); decrypt now GHASHes each batch's own input during that batch's AES rounds, before the XOR, with identical instruction-level parallelism and no prime/drain. In-place GCM decrypt now runs at full fused speed on all three architectures with no aliasing fallback. Also: TAesBitSlicedEngine.ProcessBlocks (pointer form) computes its byte count in Int64 to avoid a 32-bit overflow on very large block counts. Tests: in-place round-trip coverage (both directions, sizes crossing the fused thresholds, cipher-kernel on/off) added to the GCM, EAX and bitsliced suites; ProcessBlocks parity, CTR batched-vs-single, aggregated-GHASH parity, and chunked-stream parity.
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.
Constant-time AES-GCM bulk batching, mode-wide in-place AEAD correctness, and non-lagged fused decrypt
Bulk batching (constant-time software AES-GCM):
In-place AEAD correctness (out buffer aliasing in buffer):
Non-lagged fused decrypt (x86_64, i386, aarch64):
Also: TAesBitSlicedEngine.ProcessBlocks (pointer form) computes its byte count in Int64 to avoid a 32-bit overflow on very large block counts.
Tests: in-place round-trip coverage (both directions, sizes crossing the fused thresholds, cipher-kernel on/off) added to the GCM, EAX and bitsliced suites; ProcessBlocks parity, CTR batched-vs-single, aggregated-GHASH parity, and chunked-stream parity.