From 50b8c8342d023038a4b528af83153293dd2756ea Mon Sep 17 00:00:00 2001 From: Jussi Kivilinna Date: Tue, 17 Dec 2013 15:35:38 +0200 Subject: Add bulk processing for hash transform functions * cipher/hash-common.c (_gcry_md_block_write): Preload 'hd->blocksize' to stack, pass number of blocks to 'hd->bwrite'. * cipher/hash-common.c (_gcry_md_block_write_t): Add 'nblks'. * cipher/gostr3411-94.c: Rename 'transform' function to 'transform_blk', add new 'transform' function with 'nblks' as additional input. * cipher/md4.c: Ditto. * cipher/md5.c: Ditto. * cipher/md4.c: Ditto. * cipher/rmd160.c: Ditto. * cipher/sha1.c: Ditto. * cipher/sha256.c: Ditto. * cipher/sha512.c: Ditto. * cipher/stribog.c: Ditto. * cipher/tiger.c: Ditto. * cipher/whirlpool.c: Ditto. -- Pass number of blocks to algorithm for futher optimizations. Signed-off-by: Jussi Kivilinna --- cipher/hash-common.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'cipher/hash-common.c') diff --git a/cipher/hash-common.c b/cipher/hash-common.c index ffbc39ed..ed63a0ba 100644 --- a/cipher/hash-common.c +++ b/cipher/hash-common.c @@ -102,16 +102,18 @@ _gcry_md_block_write (void *context, const void *inbuf_arg, size_t inlen) const unsigned char *inbuf = inbuf_arg; gcry_md_block_ctx_t *hd = context; unsigned int stack_burn = 0; + const unsigned int blocksize = hd->blocksize; + size_t inblocks; - if (sizeof(hd->buf) < hd->blocksize) + if (sizeof(hd->buf) < blocksize) BUG(); if (hd->buf == NULL || hd->bwrite == NULL) return; - if (hd->count == hd->blocksize) /* Flush the buffer. */ + if (hd->count == blocksize) /* Flush the buffer. */ { - stack_burn = hd->bwrite (hd, hd->buf); + stack_burn = hd->bwrite (hd, hd->buf, 1); _gcry_burn_stack (stack_burn); stack_burn = 0; hd->count = 0; @@ -123,23 +125,24 @@ _gcry_md_block_write (void *context, const void *inbuf_arg, size_t inlen) if (hd->count) { - for (; inlen && hd->count < hd->blocksize; inlen--) + for (; inlen && hd->count < blocksize; inlen--) hd->buf[hd->count++] = *inbuf++; _gcry_md_block_write (hd, NULL, 0); if (!inlen) return; } - while (inlen >= hd->blocksize) + if (inlen >= blocksize) { - stack_burn = hd->bwrite (hd, inbuf); + inblocks = inlen / blocksize; + stack_burn = hd->bwrite (hd, inbuf, inblocks); hd->count = 0; - if (!++hd->nblocks) - hd->nblocks_high++; - inlen -= hd->blocksize; - inbuf += hd->blocksize; + hd->nblocks_high += (hd->nblocks + inblocks < inblocks); + hd->nblocks += inblocks; + inlen -= inblocks * blocksize; + inbuf += inblocks * blocksize; } _gcry_burn_stack (stack_burn); - for (; inlen && hd->count < hd->blocksize; inlen--) + for (; inlen && hd->count < blocksize; inlen--) hd->buf[hd->count++] = *inbuf++; } -- cgit v1.2.1