Fix Incorrect SHA256 Hashes for Large Inputs (#2247)

* fix >256MiB sha256 bitcount computation overflow
This commit is contained in:
Zack Puhl
2025-06-27 21:20:33 -04:00
committed by GitHub
parent 2d535aaa25
commit 0448e50b3d
3 changed files with 31 additions and 4 deletions

View File

@@ -71,7 +71,7 @@ fn void Sha256.update(&self, char[] data) {
uint i = 0;
uint len = data.len;
uint buffer_pos = (uint)(self.bitcount / 8) % BLOCK_SIZE;
self.bitcount += (ulong)(len * 8);
self.bitcount += ((ulong)len * 8);
while (len--) {
self.buffer[buffer_pos++] = data[i++];
@@ -173,4 +173,5 @@ fn void sha256_transform(uint* state, char* buffer) @local {
state[7] += h;
a = b = c = d = e = f = g = h = t1 = t2 = i = 0;
m[:64] = buffer[:64] = 0;
}
}