From: dmitry dulesov Date: Thu, 30 Jan 2020 02:30:49 +0000 (+0300) Subject: gosthash2012: Change some byte (pointers) to union uint512_u X-Git-Tag: v3.0.0~217 X-Git-Url: http://wagner.pp.ru/gitweb/?a=commitdiff_plain;h=78ff909c3ca7260912360427fd3b029c9ba08d87;p=openssl-gost%2Fengine.git gosthash2012: Change some byte (pointers) to union uint512_u Introduce byte `.B' union type to `union uint512_u'. Change `CTX.buffer' type from `unsigned char' to `union uint512_u'. Change `data' argument of `stage2()' to `union uint512_u *'. Change `g()' arguments to `union uint512_u *' with `RESTRICT' allowing compiler to optimize more. No code changes, only type changes here. Committed-by: Vitaly Chikunov --- diff --git a/gosthash2012.c b/gosthash2012.c index 632c4bf..0868d6c 100644 --- a/gosthash2012.c +++ b/gosthash2012.c @@ -48,8 +48,8 @@ void init_gost2012_hash_ctx(gost2012_hash_ctx * CTX, static INLINE void pad(gost2012_hash_ctx * CTX) { - memset(&(CTX->buffer[CTX->bufsize]), 0, sizeof(CTX->buffer) - CTX->bufsize); - CTX->buffer[CTX->bufsize] = 1; + memset(&(CTX->buffer.B[CTX->bufsize]), 0, sizeof(CTX->buffer) - CTX->bufsize); + CTX->buffer.B[CTX->bufsize] = 1; } @@ -99,8 +99,8 @@ static INLINE void add512(union uint512_u * RESTRICT x, #endif } -static void g(union uint512_u *h, const union uint512_u *N, - const unsigned char *m) +static void g(union uint512_u *h, const union uint512_u * RESTRICT N, + const union uint512_u * RESTRICT m) { #ifdef __GOST3411_HAS_SSE2__ __m128i xmm0, xmm2, xmm4, xmm6; /* XMMR0-quadruple */ @@ -144,16 +144,16 @@ static void g(union uint512_u *h, const union uint512_u *N, /* E() done */ X((&data), h, (&data)); - X((&data), ((const union uint512_u *)&m[0]), h); + X((&data), m, h); #endif } -static INLINE void stage2(gost2012_hash_ctx * CTX, const unsigned char *data) +static INLINE void stage2(gost2012_hash_ctx * CTX, const union uint512_u *data) { g(&(CTX->h), &(CTX->N), data); add512(&(CTX->N), &buffer512); - add512(&(CTX->Sigma), (const union uint512_u *)data); + add512(&(CTX->Sigma), data); } static INLINE void stage3(gost2012_hash_ctx * CTX) @@ -173,14 +173,14 @@ static INLINE void stage3(gost2012_hash_ctx * CTX) pad(CTX); - g(&(CTX->h), &(CTX->N), (const unsigned char *)&(CTX->buffer)); + g(&(CTX->h), &(CTX->N), &(CTX->buffer)); add512(&(CTX->N), &buf); - add512(&(CTX->Sigma), (const union uint512_u *)&CTX->buffer[0]); + add512(&(CTX->Sigma), &CTX->buffer); - g(&(CTX->h), &buffer0, (const unsigned char *)&(CTX->N)); + g(&(CTX->h), &buffer0, &(CTX->N)); - g(&(CTX->h), &buffer0, (const unsigned char *)&(CTX->Sigma)); + g(&(CTX->h), &buffer0, &(CTX->Sigma)); } /* @@ -193,8 +193,8 @@ void gost2012_hash_block(gost2012_hash_ctx * CTX, size_t chunksize; while (len > 63 && CTX->bufsize == 0) { - memcpy(&CTX->buffer[0], data, 64); - stage2(CTX, &CTX->buffer[0]); + memcpy(CTX->buffer.B, data, 64); + stage2(CTX, &(CTX->buffer)); data += 64; len -= 64; @@ -205,14 +205,14 @@ void gost2012_hash_block(gost2012_hash_ctx * CTX, if (chunksize > len) chunksize = len; - memcpy(&CTX->buffer[CTX->bufsize], data, chunksize); + memcpy(&CTX->buffer.B[CTX->bufsize], data, chunksize); CTX->bufsize += chunksize; len -= chunksize; data += chunksize; if (CTX->bufsize == 64) { - stage2(CTX, CTX->buffer); + stage2(CTX, &(CTX->buffer)); CTX->bufsize = 0; } diff --git a/gosthash2012.h b/gosthash2012.h index 51cb0fe..4d57e14 100644 --- a/gosthash2012.h +++ b/gosthash2012.h @@ -48,6 +48,7 @@ ALIGN(16) typedef union uint512_u { unsigned long long QWORD[8]; + unsigned char B[64]; } uint512_u; #include "gosthash2012_const.h" @@ -55,7 +56,7 @@ typedef union uint512_u { /* GOST R 34.11-2012 hash context */ typedef struct gost2012_hash_ctx { - unsigned char buffer[64]; + union uint512_u buffer; union uint512_u h; union uint512_u N; union uint512_u Sigma;