diff options
author | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2019-04-05 18:52:47 +0300 |
---|---|---|
committer | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2019-04-05 18:52:47 +0300 |
commit | e76cd0e2b1f6025c1319576a5848815d1d231aeb (patch) | |
tree | 9615b401df9891583e0d95b1f7e6de370472a972 /cipher/tiger.c | |
parent | c54b1c96c644c941f3eb3d2a09432b82f25b6ff1 (diff) | |
download | libgcrypt-e76cd0e2b1f6025c1319576a5848815d1d231aeb.tar.gz |
Optimizations for digest final functions
* cipher/md4.c (md4_final): Avoid byte-by-byte buffer setting when
padding; Merge extra and last block processing.
* cipher/md5.c (md5_final): Ditto.
* cipher/rmd160.c (rmd160_final): Ditto.
* cipher/sha1.c (sha1_final): Ditto.
* cipher/sha256.c (sha256_final): Ditto.
* cipher/sm3.c (sm3_final): Ditto.
* cipher/tiger.c (tiger_final): Ditto.
* cipher/sha512.c (sha512_final): Avoid byte-by-byte buffer setting
when padding.
* cipher/stribog.c (stribog_final): Ditto.
* cipher/whirlpool.c (whirlpool_final): Ditto.
--
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'cipher/tiger.c')
-rw-r--r-- | cipher/tiger.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/cipher/tiger.c b/cipher/tiger.c index d24d1603..0319b711 100644 --- a/cipher/tiger.c +++ b/cipher/tiger.c @@ -760,22 +760,26 @@ tiger_final( void *context ) if( hd->bctx.count < 56 ) /* enough room */ { hd->bctx.buf[hd->bctx.count++] = pad; - while( hd->bctx.count < 56 ) - hd->bctx.buf[hd->bctx.count++] = 0; /* pad */ + if (hd->bctx.count < 56) + memset (&hd->bctx.buf[hd->bctx.count], 0, 56 - hd->bctx.count); + hd->bctx.count = 56; + /* append the 64 bit count */ + buf_put_le32(hd->bctx.buf + 56, lsb); + buf_put_le32(hd->bctx.buf + 60, msb); + burn = transform( hd, hd->bctx.buf, 1 ); } else /* need one extra block */ { hd->bctx.buf[hd->bctx.count++] = pad; /* pad character */ - while( hd->bctx.count < 64 ) - hd->bctx.buf[hd->bctx.count++] = 0; - _gcry_md_block_write(hd, NULL, 0); /* flush */; - memset(hd->bctx.buf, 0, 56 ); /* fill next block with zeroes */ + /* fill pad and next block with zeroes */ + memset (&hd->bctx.buf[hd->bctx.count], 0, 64 - hd->bctx.count + 56); + hd->bctx.count = 64 + 56; + + /* append the 64 bit count */ + buf_put_le32(hd->bctx.buf + 64 + 56, lsb); + buf_put_le32(hd->bctx.buf + 64 + 60, msb); + burn = transform( hd, hd->bctx.buf, 2 ); } - /* append the 64 bit count */ - buf_put_le32(hd->bctx.buf + 56, lsb); - buf_put_le32(hd->bctx.buf + 60, msb); - burn = transform( hd, hd->bctx.buf, 1 ); - _gcry_burn_stack (burn); p = hd->bctx.buf; #define X(a) do { buf_put_be64(p, hd->a); p += 8; } while(0) @@ -794,6 +798,8 @@ tiger_final( void *context ) } #undef X #undef Y + + _gcry_burn_stack (burn); } static byte * |