Compare commits

...

1 Commits

Author SHA1 Message Date
Yury Luneff
f7603fa87b Fix a signed shift overflow in sha256_transform()
The message bytes were promoted to int before the shift by 24, which
overflows for every byte of 0x80 and above: undefined behaviour that
UBSan reports. Widen them to WORD first. The digest does not change.
2026-10-27 10:19:35 +03:00

View File

@@ -46,7 +46,7 @@ void sha256_transform(SHA256_CTX *ctx, const BYTE data[])
WORD a, b, c, d, e, f, g, h, i, j, t1, t2, m[64];
for (i = 0, j = 0; i < 16; ++i, j += 4)
m[i] = (data[j] << 24) | (data[j + 1] << 16) | (data[j + 2] << 8) | (data[j + 3]);
m[i] = ((WORD)data[j] << 24) | ((WORD)data[j + 1] << 16) | ((WORD)data[j + 2] << 8) | ((WORD)data[j + 3]);
for ( ; i < 64; ++i)
m[i] = SIG1(m[i - 2]) + m[i - 7] + SIG0(m[i - 15]) + m[i - 16];