aboutsummaryrefslogtreecommitdiffstats
path: root/libhashsum_init_ripemd_256_hasher.c
diff options
context:
space:
mode:
Diffstat (limited to 'libhashsum_init_ripemd_256_hasher.c')
-rw-r--r--libhashsum_init_ripemd_256_hasher.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/libhashsum_init_ripemd_256_hasher.c b/libhashsum_init_ripemd_256_hasher.c
index b1e9241..f08acf7 100644
--- a/libhashsum_init_ripemd_256_hasher.c
+++ b/libhashsum_init_ripemd_256_hasher.c
@@ -145,10 +145,12 @@ finalise_common(struct libhashsum_hasher *this, uint8_t *m, size_t bytes, unsign
this->state.ripemd_256.count *= 8U;
this->state.ripemd_256.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_256.m.m32[i] = LETO32(&m[i * 4U]);
@@ -190,6 +192,7 @@ finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, u
m = &m[r];
bytes -= r;
+ this->state.ripemd_256.m.m8[bytes] = 0;
memcpy(this->state.ripemd_256.m.m8, m, bytes + (size_t)(extra_bits > 0U));
return finalise_common(this, this->state.ripemd_256.m.m8, bytes, extra_bits);
}
@@ -208,6 +211,7 @@ finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extr
size -= r;
if (size < 64U) {
+ this->state.ripemd_256.m.m8[bytes] = 0;
memcpy(this->state.ripemd_256.m.m8, m, bytes + (size_t)(extra_bits > 0U));
m = this->state.ripemd_256.m.m8;
}