aboutsummaryrefslogtreecommitdiffstats
path: root/libhashsum_init_ripemd_160_hasher.c
diff options
context:
space:
mode:
Diffstat (limited to 'libhashsum_init_ripemd_160_hasher.c')
-rw-r--r--libhashsum_init_ripemd_160_hasher.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/libhashsum_init_ripemd_160_hasher.c b/libhashsum_init_ripemd_160_hasher.c
index 476fa97..001cbb8 100644
--- a/libhashsum_init_ripemd_160_hasher.c
+++ b/libhashsum_init_ripemd_160_hasher.c
@@ -133,10 +133,12 @@ finalise_common(struct libhashsum_hasher *this, uint8_t *m, size_t bytes, unsign
this->state.ripemd_160.count *= 8U;
this->state.ripemd_160.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_160.m.m32[i] = LETO32(&m[i * 4U]);
@@ -182,6 +184,7 @@ finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, u
m = &m[r];
bytes -= r;
+ this->state.ripemd_160.m.m8[bytes] = 0;
memcpy(this->state.ripemd_160.m.m8, m, bytes + (size_t)(extra_bits > 0U));
return finalise_common(this, this->state.ripemd_160.m.m8, bytes, extra_bits);
}
@@ -200,6 +203,7 @@ finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extr
size -= r;
if (size < 64U) {
+ this->state.ripemd_160.m.m8[bytes] = 0;
memcpy(this->state.ripemd_160.m.m8, m, bytes + (size_t)(extra_bits > 0U));
m = this->state.ripemd_160.m.m8;
}