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>