diff options
author | Mattias Andrée <maandree@kth.se> | 2024-08-24 01:05:44 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-08-24 01:05:44 +0200 |
commit | cf0f05362e71c189b8052bbfddd2f270f907041e (patch) | |
tree | 371ba96e6d0cdda94a5ba0f07628b1d1ea0c5960 /libhashsum_init_ripemd_160_hasher.c | |
parent | Fix makefile (diff) | |
download | libhashsum-cf0f05362e71c189b8052bbfddd2f270f907041e.tar.gz libhashsum-cf0f05362e71c189b8052bbfddd2f270f907041e.tar.bz2 libhashsum-cf0f05362e71c189b8052bbfddd2f270f907041e.tar.xz |
Standardise how to interpret a partial byte
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libhashsum_init_ripemd_160_hasher.c | 8 |
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; } |