sha256: fix verify failure
authorJens Axboe <axboe@fb.com>
Fri, 16 Jan 2015 21:25:15 +0000 (14:25 -0700)
committerJens Axboe <axboe@fb.com>
Fri, 16 Jan 2015 21:25:15 +0000 (14:25 -0700)
After the checksumming update, it's required that we call the
_final() to get consistent checksums between data generation
and data verification. Seems to only affect sha256, but we should
do it for sha1 and md5 too.

Fixes: f99d67f932ab
Signed-off-by: Jens Axboe <axboe@fb.com>
crc/sha1.c
crc/sha1.h
verify.c

index 117fbd9c2938b35a57b691ab05cf5a5acb8bcfad..8d64c8ee7b836e9322c8c6b9dde01b718f1416d6 100644 (file)
@@ -55,7 +55,7 @@ void fio_sha1_update(struct fio_sha1_ctx *ctx, const void *data,
                memcpy(ctx->W, data, len);
 }
 
                memcpy(ctx->W, data, len);
 }
 
-void fio_sha1_final(unsigned char hashout[20], struct fio_sha1_ctx *ctx)
+void fio_sha1_final(struct fio_sha1_ctx *ctx)
 {
        static const unsigned char pad[64] = { 0x80 };
        unsigned int padlen[2];
 {
        static const unsigned char pad[64] = { 0x80 };
        unsigned int padlen[2];
@@ -69,11 +69,6 @@ void fio_sha1_final(unsigned char hashout[20], struct fio_sha1_ctx *ctx)
        i = ctx->size & 63;
        fio_sha1_update(ctx, pad, 1+ (63 & (55 - i)));
        fio_sha1_update(ctx, padlen, 8);
        i = ctx->size & 63;
        fio_sha1_update(ctx, pad, 1+ (63 & (55 - i)));
        fio_sha1_update(ctx, padlen, 8);
-
-       /* Output hash
-        */
-       for (i = 0; i < 5; i++)
-               ((unsigned int *)hashout)[i] = htonl(ctx->H[i]);
 }
 
 #if defined(__i386__) || defined(__x86_64__)
 }
 
 #if defined(__i386__) || defined(__x86_64__)
index 14af44a922a70686bc96c4477c3ca202761b947e..75317f76c6f553621862073ed8d5a21dc29e1f32 100644 (file)
@@ -15,6 +15,6 @@ struct fio_sha1_ctx {
 
 void fio_sha1_init(struct fio_sha1_ctx *);
 void fio_sha1_update(struct fio_sha1_ctx *, const void *dataIn, unsigned long len);
 
 void fio_sha1_init(struct fio_sha1_ctx *);
 void fio_sha1_update(struct fio_sha1_ctx *, const void *dataIn, unsigned long len);
-void fio_sha1_final(unsigned char hashout[20], struct fio_sha1_ctx *);
+void fio_sha1_final(struct fio_sha1_ctx *);
 
 #endif
 
 #endif
index 260fa2ae2fad1f298b7ddad8cb421019708a09d1..b6793d7da76a7f98d68df2847de727ee359cd3dc 100644 (file)
--- a/verify.c
+++ b/verify.c
@@ -472,6 +472,7 @@ static int verify_io_u_sha256(struct verify_header *hdr, struct vcont *vc)
 
        fio_sha256_init(&sha256_ctx);
        fio_sha256_update(&sha256_ctx, p, hdr->len - hdr_size(hdr));
 
        fio_sha256_init(&sha256_ctx);
        fio_sha256_update(&sha256_ctx, p, hdr->len - hdr_size(hdr));
+       fio_sha256_final(&sha256_ctx);
 
        if (!memcmp(vh->sha256, sha256_ctx.buf, sizeof(sha256)))
                return 0;
 
        if (!memcmp(vh->sha256, sha256_ctx.buf, sizeof(sha256)))
                return 0;
@@ -497,6 +498,7 @@ static int verify_io_u_sha1(struct verify_header *hdr, struct vcont *vc)
 
        fio_sha1_init(&sha1_ctx);
        fio_sha1_update(&sha1_ctx, p, hdr->len - hdr_size(hdr));
 
        fio_sha1_init(&sha1_ctx);
        fio_sha1_update(&sha1_ctx, p, hdr->len - hdr_size(hdr));
+       fio_sha1_final(&sha1_ctx);
 
        if (!memcmp(vh->sha1, sha1_ctx.H, sizeof(sha1)))
                return 0;
 
        if (!memcmp(vh->sha1, sha1_ctx.H, sizeof(sha1)))
                return 0;
@@ -627,6 +629,7 @@ static int verify_io_u_md5(struct verify_header *hdr, struct vcont *vc)
 
        fio_md5_init(&md5_ctx);
        fio_md5_update(&md5_ctx, p, hdr->len - hdr_size(hdr));
 
        fio_md5_init(&md5_ctx);
        fio_md5_update(&md5_ctx, p, hdr->len - hdr_size(hdr));
+       fio_md5_final(&md5_ctx);
 
        if (!memcmp(vh->md5_digest, md5_ctx.hash, sizeof(hash)))
                return 0;
 
        if (!memcmp(vh->md5_digest, md5_ctx.hash, sizeof(hash)))
                return 0;
@@ -893,6 +896,7 @@ static void fill_sha256(struct verify_header *hdr, void *p, unsigned int len)
 
        fio_sha256_init(&sha256_ctx);
        fio_sha256_update(&sha256_ctx, p, len);
 
        fio_sha256_init(&sha256_ctx);
        fio_sha256_update(&sha256_ctx, p, len);
+       fio_sha256_final(&sha256_ctx);
 }
 
 static void fill_sha1(struct verify_header *hdr, void *p, unsigned int len)
 }
 
 static void fill_sha1(struct verify_header *hdr, void *p, unsigned int len)
@@ -904,6 +908,7 @@ static void fill_sha1(struct verify_header *hdr, void *p, unsigned int len)
 
        fio_sha1_init(&sha1_ctx);
        fio_sha1_update(&sha1_ctx, p, len);
 
        fio_sha1_init(&sha1_ctx);
        fio_sha1_update(&sha1_ctx, p, len);
+       fio_sha1_final(&sha1_ctx);
 }
 
 static void fill_crc7(struct verify_header *hdr, void *p, unsigned int len)
 }
 
 static void fill_crc7(struct verify_header *hdr, void *p, unsigned int len)
@@ -950,6 +955,7 @@ static void fill_md5(struct verify_header *hdr, void *p, unsigned int len)
 
        fio_md5_init(&md5_ctx);
        fio_md5_update(&md5_ctx, p, len);
 
        fio_md5_init(&md5_ctx);
        fio_md5_update(&md5_ctx, p, len);
+       fio_md5_final(&md5_ctx);
 }
 
 static void populate_hdr(struct thread_data *td, struct io_u *io_u,
 }
 
 static void populate_hdr(struct thread_data *td, struct io_u *io_u,