From: Jens Axboe Date: Sun, 29 Jul 2007 18:59:01 +0000 (+0200) Subject: Fix bug in md5 calculation X-Git-Tag: fio-1.17~27 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=fd00954ca87b3b083ec6987e593a16ff01913fe8 Fix bug in md5 calculation Commit 8c432325c3df2075a77b27eab8a87704cf7b48ee introduced a bug for smaller sizes. Just basically revert the optimization, safer to stay with a 'reference' implementation than skip a memset. Signed-off-by: Jens Axboe --- diff --git a/md5.c b/md5.c index 6b61012e..cf1f814a 100644 --- a/md5.c +++ b/md5.c @@ -9,11 +9,10 @@ static void md5_transform(uint32_t *hash, uint32_t const *in) { uint32_t a, b, c, d; - /* - * This used to be set from the hash[0..3] input, but we can - * skip a memory clear if we just start from 0 instead. - */ - a = b = c = d = 0; + a = hash[0]; + b = hash[1]; + c = hash[2]; + d = hash[3]; MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); @@ -83,10 +82,10 @@ static void md5_transform(uint32_t *hash, uint32_t const *in) MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); - hash[0] = a; - hash[1] = b; - hash[2] = c; - hash[3] = d; + hash[0] += a; + hash[1] += b; + hash[2] += c; + hash[3] += d; } void md5_update(struct md5_ctx *mctx, const uint8_t *data, unsigned int len) diff --git a/verify.c b/verify.c index 91509e5b..6972fe3f 100644 --- a/verify.c +++ b/verify.c @@ -145,6 +145,7 @@ static int verify_io_u_md5(struct verify_header *hdr, struct io_u *io_u, .hash = hash, }; + memset(md5_ctx.hash, 0, sizeof(hdr->md5_digest)); md5_update(&md5_ctx, p, hdr->len - sizeof(*hdr)); if (memcmp(hdr->md5_digest, md5_ctx.hash, sizeof(hash))) { @@ -236,6 +237,7 @@ static void fill_md5(struct verify_header *hdr, void *p, unsigned int len) .hash = (uint32_t *) hdr->md5_digest, }; + memset(md5_ctx.hash, 0, sizeof(hdr->md5_digest)); md5_update(&md5_ctx, p, len); }