aboutsummaryrefslogtreecommitdiffstats
path: root/libhashsum_init_md4_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_md4_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_md4_hasher.c')
-rw-r--r--libhashsum_init_md4_hasher.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/libhashsum_init_md4_hasher.c b/libhashsum_init_md4_hasher.c
index c51ebf8..f3c26ac 100644
--- a/libhashsum_init_md4_hasher.c
+++ b/libhashsum_init_md4_hasher.c
@@ -98,10 +98,12 @@ finalise_common(struct libhashsum_hasher *this, uint8_t *m, size_t bytes, unsign
this->state.md4.count *= 8U;
this->state.md4.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.md4.m.m32[i] = LETO32(&m[i * 4U]);
@@ -143,6 +145,7 @@ finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, u
m = &m[r];
bytes -= r;
+ this->state.md4.m.m8[bytes] = 0;
memcpy(this->state.md4.m.m8, m, bytes + (size_t)(extra_bits > 0U));
return finalise_common(this, this->state.md4.m.m8, bytes, extra_bits);
}
@@ -161,6 +164,7 @@ finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extr
size -= r;
if (size < 64U) {
+ this->state.md4.m.m8[bytes] = 0;
memcpy(this->state.md4.m.m8, m, bytes + (size_t)(extra_bits > 0U));
m = this->state.md4.m.m8;
}