From cc55d2b5489082d0801147c69b105005f74e0fd8 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Fri, 28 Apr 2017 22:51:36 +0100 Subject: [PATCH] sha512.[ch]: Remove a bunch of unused code. Signed-off-by: Mark Wooding --- sha512.c | 178 --------------------------------------------------------------- sha512.h | 13 ----- 2 files changed, 191 deletions(-) diff --git a/sha512.c b/sha512.c index 5c0b2ed..16129c3 100644 --- a/sha512.c +++ b/sha512.c @@ -171,184 +171,6 @@ sha384_finish_ctx (struct sha512_ctx *ctx, void *resbuf) return sha384_read_ctx (ctx, resbuf); } -/* Compute SHA512 message digest for bytes read from STREAM. The - resulting message digest number will be written into the 64 bytes - beginning at RESBLOCK. */ -int -sha512_stream (FILE *stream, void *resblock) -{ - struct sha512_ctx ctx; - size_t sum; - - char *buffer = malloc (BLOCKSIZE + 72); - if (!buffer) - return 1; - - /* Initialize the computation context. */ - sha512_init_ctx (&ctx); - - /* Iterate over full file contents. */ - while (1) - { - /* We read the file in blocks of BLOCKSIZE bytes. One call of the - computation function processes the whole buffer so that with the - next round of the loop another block can be read. */ - size_t n; - sum = 0; - - /* Read block. Take care for partial reads. */ - while (1) - { - n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); - - sum += n; - - if (sum == BLOCKSIZE) - break; - - if (n == 0) - { - /* Check for the error flag IFF N == 0, so that we don't - exit the loop after a partial read due to e.g., EAGAIN - or EWOULDBLOCK. */ - if (ferror (stream)) - { - free (buffer); - return 1; - } - goto process_partial_block; - } - - /* We've read at least one byte, so ignore errors. But always - check for EOF, since feof may be true even though N > 0. - Otherwise, we could end up calling fread after EOF. */ - if (feof (stream)) - goto process_partial_block; - } - - /* Process buffer with BLOCKSIZE bytes. Note that - BLOCKSIZE % 128 == 0 - */ - sha512_process_block (buffer, BLOCKSIZE, &ctx); - } - - process_partial_block:; - - /* Process any remaining bytes. */ - if (sum > 0) - sha512_process_bytes (buffer, sum, &ctx); - - /* Construct result in desired memory. */ - sha512_finish_ctx (&ctx, resblock); - free (buffer); - return 0; -} - -/* FIXME: Avoid code duplication */ -int -sha384_stream (FILE *stream, void *resblock) -{ - struct sha512_ctx ctx; - size_t sum; - - char *buffer = malloc (BLOCKSIZE + 72); - if (!buffer) - return 1; - - /* Initialize the computation context. */ - sha384_init_ctx (&ctx); - - /* Iterate over full file contents. */ - while (1) - { - /* We read the file in blocks of BLOCKSIZE bytes. One call of the - computation function processes the whole buffer so that with the - next round of the loop another block can be read. */ - size_t n; - sum = 0; - - /* Read block. Take care for partial reads. */ - while (1) - { - n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); - - sum += n; - - if (sum == BLOCKSIZE) - break; - - if (n == 0) - { - /* Check for the error flag IFF N == 0, so that we don't - exit the loop after a partial read due to e.g., EAGAIN - or EWOULDBLOCK. */ - if (ferror (stream)) - { - free (buffer); - return 1; - } - goto process_partial_block; - } - - /* We've read at least one byte, so ignore errors. But always - check for EOF, since feof may be true even though N > 0. - Otherwise, we could end up calling fread after EOF. */ - if (feof (stream)) - goto process_partial_block; - } - - /* Process buffer with BLOCKSIZE bytes. Note that - BLOCKSIZE % 128 == 0 - */ - sha512_process_block (buffer, BLOCKSIZE, &ctx); - } - - process_partial_block:; - - /* Process any remaining bytes. */ - if (sum > 0) - sha512_process_bytes (buffer, sum, &ctx); - - /* Construct result in desired memory. */ - sha384_finish_ctx (&ctx, resblock); - free (buffer); - return 0; -} - -/* Compute SHA512 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 - digest. */ -void * -sha512_buffer (const char *buffer, size_t len, void *resblock) -{ - struct sha512_ctx ctx; - - /* Initialize the computation context. */ - sha512_init_ctx (&ctx); - - /* Process whole buffer but last len % 128 bytes. */ - sha512_process_bytes (buffer, len, &ctx); - - /* Put result in desired memory area. */ - return sha512_finish_ctx (&ctx, resblock); -} - -void * -sha384_buffer (const char *buffer, size_t len, void *resblock) -{ - struct sha512_ctx ctx; - - /* Initialize the computation context. */ - sha384_init_ctx (&ctx); - - /* Process whole buffer but last len % 128 bytes. */ - sha512_process_bytes (buffer, len, &ctx); - - /* Put result in desired memory area. */ - return sha384_finish_ctx (&ctx, resblock); -} - void sha512_process_bytes (const void *buffer, size_t len, struct sha512_ctx *ctx) { diff --git a/sha512.h b/sha512.h index ea85194..9b06200 100644 --- a/sha512.h +++ b/sha512.h @@ -75,19 +75,6 @@ extern void *sha512_read_ctx (const struct sha512_ctx *ctx, void *resbuf); extern void *sha384_read_ctx (const struct sha512_ctx *ctx, void *resbuf); -/* Compute SHA512 (SHA384) message digest for bytes read from STREAM. The - resulting message digest number will be written into the 64 (48) bytes - beginning at RESBLOCK. */ -extern int sha512_stream (FILE *stream, void *resblock); -extern int sha384_stream (FILE *stream, void *resblock); - -/* Compute SHA512 (SHA384) 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 - digest. */ -extern void *sha512_buffer (const char *buffer, size_t len, void *resblock); -extern void *sha384_buffer (const char *buffer, size_t len, void *resblock); - # ifdef __cplusplus } # endif -- 2.11.0