]> www.wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
gosthash2012: Change some byte (pointers) to union uint512_u
authordmitry dulesov <dmitry.dulesov@gmail.com>
Thu, 30 Jan 2020 02:30:49 +0000 (05:30 +0300)
committerDmitry Belyavskiy <beldmit@users.noreply.github.com>
Sun, 2 Feb 2020 18:05:29 +0000 (21:05 +0300)
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 <vt@altlinux.org>
gosthash2012.c
gosthash2012.h

index 632c4bfde4c9e106412b5369968cc6ef83de1c16..0868d6c1c2113d90ac920cf8e76a24adce8edb2d 100644 (file)
@@ -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;
         }
index 51cb0fecfc9db3cfca665b5ae74fd17d6d2991cd..4d57e14f2f34c6cd4fc2ad84524a9b50404269e5 100644 (file)
@@ -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;