diff options
Diffstat (limited to 'libhashsum_init_ripemd_128_hasher.c')
-rw-r--r-- | libhashsum_init_ripemd_128_hasher.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/libhashsum_init_ripemd_128_hasher.c b/libhashsum_init_ripemd_128_hasher.c index d4e818f..ef9f215 100644 --- a/libhashsum_init_ripemd_128_hasher.c +++ b/libhashsum_init_ripemd_128_hasher.c @@ -134,10 +134,12 @@ finalise_common(struct libhashsum_hasher *this, uint8_t *m, size_t bytes, unsign this->state.ripemd_128.count *= 8U; this->state.ripemd_128.count += (size_t)extra_bits; - memset(&m[bytes], 0, 64U - bytes); + if (extra_bits) + m[bytes] = libhashsum_reverse_byte__(m[bytes]); + memset(&m[bytes + 1U], 0, 63U - 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) */ for (i = 0; i < 14; i++) this->state.ripemd_128.m.m32[i] = LETO32(&m[i * 4U]); @@ -179,6 +181,7 @@ finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, u m = &m[r]; bytes -= r; + this->state.ripemd_128.m.m8[bytes] = 0; memcpy(this->state.ripemd_128.m.m8, m, bytes + (size_t)(extra_bits > 0U)); return finalise_common(this, this->state.ripemd_128.m.m8, bytes, extra_bits); } @@ -197,6 +200,7 @@ finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extr size -= r; if (size < 64U) { + this->state.ripemd_128.m.m8[bytes] = 0; memcpy(this->state.ripemd_128.m.m8, m, bytes + (size_t)(extra_bits > 0U)); m = this->state.ripemd_128.m.m8; } |