whirlpool: do bitcount calculation in finalization part
authorJussi Kivilinna <jussi.kivilinna@iki.fi>
Sat, 21 Sep 2013 10:54:38 +0000 (13:54 +0300)
committerJussi Kivilinna <jussi.kivilinna@iki.fi>
Mon, 30 Sep 2013 17:04:52 +0000 (20:04 +0300)
commit10d7351411f19bb2c03d2e24ca5a38dabe45023b
treeebd5ccd8cd988dba1f672113d0e6372757cfece0
parentd2076f27bb7c5d505abf25fc622d21794c4a5df3
whirlpool: do bitcount calculation in finalization part

* cipher/whirlpool.c (whirlpool_context_t): Remove 'length', add
'nblocks'.
(whirlpool_add): Update 'nblocks' instead of 'length', and add early
return at one spot.
(whirlpool_write): Check for 'nblocks' overflow.
(whirlpool_final): Convert 'nblocks' to bit-counter, and use
whirlpool_write instead of whirlpool_add.
--

Currently Whirlpool uses large 256 bit counter that is increased in the
'write' function. However, we could to bit counter calculation as is
done in all the rest hash algorithms; use 64-bit block counter that is
converted to bit counter in finalization function. This change does
limit amount of bytes Whirlpool can process before overflowing bit counter.
With 256-bit counter, overflow happens after ~1.3e67 gigabytes. With 64-bit
block counter, overflow happens just after ~1.1e12 gigabytes. Patch keeps
the old behaviour of halting if counter overflows.

Main benefit for this patch is that after this change, we can use the
_gcry_md_block_write helper for Whirlpool too.

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
cipher/whirlpool.c