aboutsummaryrefslogtreecommitdiffstats
path: root/libhashsum_init_md5_hasher.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-08-24 01:05:44 +0200
committerMattias Andrée <maandree@kth.se>2024-08-24 01:05:44 +0200
commitcf0f05362e71c189b8052bbfddd2f270f907041e (patch)
tree371ba96e6d0cdda94a5ba0f07628b1d1ea0c5960 /libhashsum_init_md5_hasher.c
parentFix makefile (diff)
downloadlibhashsum-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 'libhashsum_init_md5_hasher.c')
-rw-r--r--libhashsum_init_md5_hasher.c5
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);
}