From: dmitry dulesov Date: Thu, 30 Jan 2020 02:41:36 +0000 (+0300) Subject: gosthash2012: Optimize `gost2012_hash_block' loop X-Git-Tag: v3.0.0~216 X-Git-Url: http://www.wagner.pp.ru/gitweb/?p=openssl-gost%2Fengine.git;a=commitdiff_plain;h=9ff7d05ba8018b679c2b40e12b2ecfe51dc4127c gosthash2012: Optimize `gost2012_hash_block' loop Some simple optimizations. Committed-by: Vitaly Chikunov --- diff --git a/gosthash2012.c b/gosthash2012.c index 0868d6c..b844ab3 100644 --- a/gosthash2012.c +++ b/gosthash2012.c @@ -190,33 +190,35 @@ static INLINE void stage3(gost2012_hash_ctx * CTX) void gost2012_hash_block(gost2012_hash_ctx * CTX, const unsigned char *data, size_t len) { - size_t chunksize; + register size_t chunksize; + register size_t bufsize = CTX->bufsize; - while (len > 63 && CTX->bufsize == 0) { - memcpy(CTX->buffer.B, data, 64); - stage2(CTX, &(CTX->buffer)); - - data += 64; - len -= 64; + if (bufsize == 0) { + while (len >= 64) { + memcpy(&CTX->buffer.B[0], data, 64); + stage2(CTX, &(CTX->buffer)); + data += 64; + len -= 64; + } } while (len) { - chunksize = 64 - CTX->bufsize; + chunksize = 64 - bufsize; if (chunksize > len) chunksize = len; - memcpy(&CTX->buffer.B[CTX->bufsize], data, chunksize); + memcpy(&CTX->buffer.B[bufsize], data, chunksize); - CTX->bufsize += chunksize; + bufsize += chunksize; len -= chunksize; data += chunksize; - if (CTX->bufsize == 64) { - stage2(CTX, &(CTX->buffer)); - - CTX->bufsize = 0; + if (bufsize == 64) { + stage2(CTX, &(CTX->buffer) ); + bufsize = 0; } } + CTX->bufsize = bufsize; } /*