Skip to content

Commit 2f66a75

Browse files
committed
fix SHA1Compress NI bug
1 parent 5662638 commit 2f66a75

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

HashLib/src/Include/Simd/SHA1/SHA1CompressShaNi.inc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,22 @@
4242
// Save state for final addition
4343
movdqa xmm8, xmm0 // ABCD_SAVE
4444

45-
// Load and byte-swap all 4 message blocks
45+
// Load, byte-swap, and reverse dword order for all 4 message blocks.
46+
// The per-dword BSWAP mask puts W[0] at [31:0], but sha1rnds4 reads
47+
// W[0] from [127:96]. The pshufd $1B reverses the dword order.
4648
movdqu xmm7, oword [r9] // BSWAP mask at offset 0
4749
movdqu xmm3, oword [rdx]
4850
pshufb xmm3, xmm7
51+
pshufd xmm3, xmm3, $1B
4952
movdqu xmm4, oword [rdx + $10]
5053
pshufb xmm4, xmm7
54+
pshufd xmm4, xmm4, $1B
5155
movdqu xmm5, oword [rdx + $20]
5256
pshufb xmm5, xmm7
57+
pshufd xmm5, xmm5, $1B
5358
movdqu xmm6, oword [rdx + $30]
5459
pshufb xmm6, xmm7
60+
pshufd xmm6, xmm6, $1B
5561

5662
// Save E for final addition (reuse xmm7)
5763
movdqa xmm7, xmm1 // E_SAVE

0 commit comments

Comments
 (0)