From 31138d02d9c3698c039154b3078c16f205e25902 Mon Sep 17 00:00:00 2001 From: dmitry dulesov Date: Thu, 30 Jan 2020 05:49:50 +0300 Subject: [PATCH] gosthash2012: Optimize out temporary `buf' from `stage3' On-stack `buf' is replaced by manipulation directly on `CTX->buffer'. Committed-by: Vitaly Chikunov --- gosthash2012.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/gosthash2012.c b/gosthash2012.c index b844ab3..ddd35fa 100644 --- a/gosthash2012.c +++ b/gosthash2012.c @@ -158,28 +158,19 @@ static INLINE void stage2(gost2012_hash_ctx * CTX, const union uint512_u *data) static INLINE void stage3(gost2012_hash_ctx * CTX) { - ALIGN(16) union uint512_u buf; - - memset(&buf, 0x00, sizeof buf); - memcpy(&buf, &(CTX->buffer), CTX->bufsize); - memcpy(&(CTX->buffer), &buf, sizeof(uint512_u)); + pad(CTX); + g(&(CTX->h), &(CTX->N), &(CTX->buffer)); + add512(&(CTX->Sigma), &CTX->buffer); - memset(&buf, 0x00, sizeof buf); + memset(&(CTX->buffer.B[0]), 0, sizeof(uint512_u)); #ifndef __GOST3411_BIG_ENDIAN__ - buf.QWORD[0] = CTX->bufsize << 3; + CTX->buffer.QWORD[0] = CTX->bufsize << 3; #else - buf.QWORD[0] = BSWAP64(CTX->bufsize << 3); + CTX->buffer.QWORD[0] = BSWAP64(CTX->bufsize << 3); #endif - - pad(CTX); - - g(&(CTX->h), &(CTX->N), &(CTX->buffer)); - - add512(&(CTX->N), &buf); - add512(&(CTX->Sigma), &CTX->buffer); + add512(&(CTX->N), &(CTX->buffer)); g(&(CTX->h), &buffer0, &(CTX->N)); - g(&(CTX->h), &buffer0, &(CTX->Sigma)); } -- 2.39.5