Simplify AEAD ProcessBytes dispatch and tidy WipeKeyMaterial - #166
Merged
Conversation
Refactor the large, duplicative ProcessBytes methods of the AEAD modes, keeping every hot kernel and the byte-for-byte crypto output unchanged -- only the dispatch scaffolding around them is restructured. GCM - Collapse the near-mirror encrypt/decrypt whole-block dispatch (the 8-4-2-1 tiered staircase plus the repeated two-block advance) into a single RunTieredWholeBlocks(AForEncrypt, ..., AHoldBack) helper. The hold-back (0 on encrypt, the tag size on decrypt) unifies the two threshold families; the per-tier methods are unchanged. 243 -> 110 lines. EAX - Extract the buffer drain / residue-stash / decrypt-stitch boilerplate repeated across the four dispatch paths into DrainInto / StashResidue / StitchDecryptBlock0. The OMAC lookahead sequencing and fused-kernel logic are untouched. 367 -> 314 lines. ChaCha20-Poly1305 - Stop rejecting a nil output buffer in DoFinal; rely on the output-length check like the other AEAD modes. In Pascal an empty result array is nil, so the old check wrongly failed a legitimate empty-plaintext decrypt. All modes - Drop the redundant "if F <> nil then" guards around the WipeKeyMaterial fills; the fill helper already no-ops on a nil (or empty) array. Tests - Add a chunked-streaming equivalence harness (chunk sizes across every buffer/tag boundary, both directions, out-of-place and in-place, with per-call Result accounting) that runs each mode under the kernel on/off toggle and the software engines, so every dispatch tier is exercised.
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.
Refactor the large, duplicative ProcessBytes methods of the AEAD modes, keeping every hot kernel and the byte-for-byte crypto output unchanged -- only the dispatch scaffolding around them is restructured.
GCM
EAX
ChaCha20-Poly1305
All modes
Tests