diff options
Diffstat (limited to 'libhashsum_init_md5_hasher.c')
-rw-r--r-- | libhashsum_init_md5_hasher.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/libhashsum_init_md5_hasher.c b/libhashsum_init_md5_hasher.c index 292bd1e..7bf19af 100644 --- a/libhashsum_init_md5_hasher.c +++ b/libhashsum_init_md5_hasher.c @@ -109,9 +109,11 @@ finalise_common(struct libhashsum_hasher *this, uint8_t *m, size_t bytes, unsign this->state.md5.count *= 8U; this->state.md5.count += (size_t)extra_bits; + if (extra_bits) + m[bytes] = libhashsum_reverse_byte__(m[bytes]); mask = (uint8_t)(1U << (7U - extra_bits)); m[bytes] |= mask; - m[bytes] &= (uint8_t)~(mask - 1U); /* keep high bits */ + m[bytes] &= (uint8_t)~(mask - 1U); /* keep high bits (original value was reversed) */ bytes++; if (bytes > 56U) { @@ -159,6 +161,7 @@ finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, u m = &m[r]; bytes -= r; + this->state.md5.m[bytes] = 0; memcpy(this->state.md5.m, m, bytes + (size_t)(extra_bits > 0U)); return finalise_common(this, this->state.md5.m, bytes, extra_bits); } |