]> www.wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
disable gost key mask on gost94 digest steps due to performance issues
authorArseniy Ankudinov <afalinuz@gmail.com>
Wed, 23 Sep 2020 15:54:58 +0000 (18:54 +0300)
committerDmitry Belyavskiy <beldmit@users.noreply.github.com>
Wed, 23 Sep 2020 17:09:38 +0000 (20:09 +0300)
gost89.c
gost89.h

index 953c6ec7788e96a45141dd6f0f03ea34ebdd9af0..337204b8c91f79ac2a2042a3267c567bedf03254 100644 (file)
--- a/gost89.c
+++ b/gost89.c
@@ -444,15 +444,13 @@ void gost_dec_cfb(gost_ctx * ctx, const byte * iv, const byte * cipher,
 void gost_enc_with_key(gost_ctx * c, byte * key, byte * inblock,
                        byte * outblock)
 {
-    gost_key(c, key);
+    gost_key_nomask(c, key);
     gostcrypt(c, inblock, outblock);
 }
 
-/* Set 256 bit gost89 key into context */
-void gost_key(gost_ctx * c, const byte * k)
+static void gost_key_impl(gost_ctx * c, const byte * k)
 {
     int i, j;
-    RAND_priv_bytes((unsigned char *)c->mask, sizeof(c->mask));
     for (i = 0, j = 0; i < 8; ++i, j += 4) {
         c->key[i] =
             (k[j] | (k[j + 1] << 8) | (k[j + 2] << 16) | ((word32) k[j + 3] <<
@@ -460,6 +458,20 @@ void gost_key(gost_ctx * c, const byte * k)
     }
 }
 
+/* Set 256 bit gost89 key into context */
+void gost_key(gost_ctx * c, const byte * k)
+{
+    RAND_priv_bytes((unsigned char *)c->mask, sizeof(c->mask));
+    gost_key_impl(c, k);
+}
+
+/* Set 256 bit gost89 key into context without key mask */
+void gost_key_nomask(gost_ctx * c, const byte * k)
+{
+    memset(c->mask, 0, sizeof(c->mask));
+    gost_key_impl(c, k);
+}
+
 /* Set 256 bit Magma key into context */
 void magma_key(gost_ctx * c, const byte * k)
 {
index 569db5b059816eee5fa162fc74b6d0940c867913..b67375b7ddfbad80b9fa787646874dbaada5fb67 100644 (file)
--- a/gost89.h
+++ b/gost89.h
@@ -60,6 +60,8 @@ void gostcrypt(gost_ctx * c, const byte * in, byte * out);
 void gostdecrypt(gost_ctx * c, const byte * in, byte * out);
 /* Set key into context */
 void gost_key(gost_ctx * c, const byte * k);
+/* Set key into context without key mask */
+void gost_key_nomask(gost_ctx * c, const byte * k);
 /* Set key into context */
 void magma_key(gost_ctx * c, const byte * k);
 /* Get key from context */