From 006691ca8e758089505469daf85dd34e0ab928f1 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 18 Feb 2011 15:21:34 +1100 Subject: [PATCH] Forgot the md5.x changes to support md5 on decompression. --- md5.c | 34 +++++++++++++++++++++------------- md5.h | 3 +++ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/md5.c b/md5.c index a5bc53e..4edae01 100644 --- a/md5.c +++ b/md5.c @@ -124,23 +124,15 @@ md5_finish_ctx (struct md5_ctx *ctx, void *resbuf) return md5_read_ctx (ctx, resbuf); } -/* Compute MD5 message digest for bytes read from STREAM. The - resulting message digest number will be written into the 16 bytes - beginning at RESBLOCK. */ -int -md5_stream (FILE *stream, void *resblock) +int md5_midstream (FILE *stream, struct md5_ctx *ctx) { - struct md5_ctx ctx; size_t sum; char *buffer = malloc (BLOCKSIZE + 72); if (!buffer) return 1; - /* Initialize the computation context. */ - md5_init_ctx (&ctx); - - /* Iterate over full file contents. */ + /* Iterate over the file contents so far written. */ while (1) { /* We read the file in blocks of BLOCKSIZE bytes. One call of the @@ -182,18 +174,34 @@ md5_stream (FILE *stream, void *resblock) /* Process buffer with BLOCKSIZE bytes. Note that BLOCKSIZE % 64 == 0 */ - md5_process_block (buffer, BLOCKSIZE, &ctx); + md5_process_block (buffer, BLOCKSIZE, ctx); } process_partial_block: /* Process any remaining bytes. */ if (sum > 0) - md5_process_bytes (buffer, sum, &ctx); + md5_process_bytes (buffer, sum, ctx); + free (buffer); + return 0; +} + +/* Compute MD5 message digest for bytes read from STREAM. The + resulting message digest number will be written into the 16 bytes + beginning at RESBLOCK. */ +int +md5_stream (FILE *stream, void *resblock) +{ + struct md5_ctx ctx; + + /* Initialize the computation context. */ + md5_init_ctx (&ctx); + + md5_midstream(stream, &ctx); + /* Construct result in desired memory. */ md5_finish_ctx (&ctx, resblock); - free (buffer); return 0; } diff --git a/md5.h b/md5.h index 261b733..532c9c6 100644 --- a/md5.h +++ b/md5.h @@ -54,6 +54,7 @@ # define __md5_process_bytes md5_process_bytes # define __md5_read_ctx md5_read_ctx # define __md5_stream md5_stream +# define __md5_midstream md5_midstream #endif # ifdef __cplusplus @@ -114,6 +115,8 @@ extern void *__md5_read_ctx (const struct md5_ctx *ctx, void *resbuf) __THROW; beginning at RESBLOCK. */ extern int __md5_stream (FILE *stream, void *resblock) __THROW; +extern int __md5_midstream (FILE *stream, struct md5_ctx *ctx) __THROW; + /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The result is always in little endian byte order, so that a byte-wise output yields to the wanted ASCII representation of the message