summaryrefslogtreecommitdiff
path: root/cipher/hash-common.c
diff options
context:
space:
mode:
authorJussi Kivilinna <jussi.kivilinna@iki.fi>2013-12-17 15:35:38 +0200
committerJussi Kivilinna <jussi.kivilinna@iki.fi>2013-12-17 15:35:38 +0200
commit50b8c8342d023038a4b528af83153293dd2756ea (patch)
tree603423305ea81754f728c85814d0dc908e6e96d6 /cipher/hash-common.c
parent210b7237706f6ad5cbc1a3362707f63db2c8a780 (diff)
downloadlibgcrypt-50b8c8342d023038a4b528af83153293dd2756ea.tar.gz
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 <jussi.kivilinna@iki.fi>
Diffstat (limited to 'cipher/hash-common.c')
-rw-r--r--cipher/hash-common.c25
1 files changed, 14 insertions, 11 deletions
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++;
}