Index: src/OFHashes.m ================================================================== --- src/OFHashes.m +++ src/OFHashes.m @@ -328,16 +328,17 @@ state[3] += d; state[4] += e; } static inline void -sha1_update(uint8_t buffer, const uint8_t *buf, size_t size) +sha1_update(uint32_t *state, uint64_t *count, uint8_t *buffer, + const uint8_t *buf, size_t size) { size_t i, j; - j = (size_t)((count >> 3) & 63); - count += (size << 3); + j = (size_t)((*count >> 3) & 63); + *count += (size << 3); if ((j + size) > 63) { memcpy(&buffer[j], buf, (i = 64 - j)); sha1_transform(state, buffer); @@ -373,11 +374,11 @@ if (calculated) return self; if (size == 0) return self; - sha1_update(buffer, buf, size); + sha1_update(state, &count, buffer, buf, size); return self; } - (uint8_t*)digest @@ -389,16 +390,16 @@ return digest; for (i = 0; i < 8; i++) /* Endian independent */ finalcount[i] = (uint8_t)((count >> ((7 - (i & 7)) * 8)) & 255); - sha1_update(buffer, (const uint8_t*)"\200", 1); + sha1_update(state, &count, buffer, (const uint8_t*)"\200", 1); while ((count & 504) != 448) - sha1_update(buffer, (const uint8_t*)"\0", 1); + sha1_update(state, &count, buffer, (const uint8_t*)"\0", 1); /* Should cause a sha1_transform() */ - sha1_update(buffer, finalcount, 8); + sha1_update(state, &count, buffer, finalcount, 8); for (i = 0; i < SHA1_DIGEST_SIZE; i++) digest[i] = (uint8_t)((state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255);