refactor(sha): decouple BSWAP masks from SHA round-constant arrays#80
Merged
Conversation
The x86 SIMD kernels previously appended a pshufb byte-swap mask to the end
of the K256/K512/K_SHA1 round-constant arrays and reached it via an offset
from the constants pointer (e.g. [r9+$100]). This conflated two unrelated
things: the algorithm's round constants and an x86-only implementation
detail, and it bloated the public K arrays with values that are not part of
the SHA specification.
Separate the two concerns:
- Shrink K256 [0..63], K512 [0..79] and K_SHA1 [0..15] back to exactly the
spec-defined round constants.
- Introduce dedicated BSWAP32_MASK / BSWAP64_MASK constants, guarded by
{$IFDEF HASHLIB_X86_SIMD} since they are an x86 SIMD concern only (ARM
byte-swaps natively via REV32/REV64 and needs no mask table).
- Pass the mask as a separate 5th pointer argument: the SSSE3/AVX2/SHA-NI
compress procedures now use SimdProc5Begin instead of SimdProc4Begin, and
the kernels load the mask from the dedicated pointer (r10 on x86-64, ecx
on i386) instead of an offset past the constants. SSE2 backends are
unchanged (they byte-swap without a mask).
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.
The x86 SIMD kernels previously appended a pshufb byte-swap mask to the end of the K256/K512/K_SHA1 round-constant arrays and reached it via an offset from the constants pointer (e.g. [r9+$100]). This conflated two unrelated things: the algorithm's round constants and an x86-only implementation detail, and it bloated the public K arrays with values that are not part of the SHA specification.
Separate the two concerns: