[PATCH 1/3] gost: add keymeshing support per RFC 4357

dbaryshkov at gmail.com dbaryshkov at gmail.com
Sun Feb 9 19:29:42 CET 2020


From: Dmitry Baryshkov <dbaryshkov at gmail.com>

* cipher/gost-s-box.c (gost_sbox): define if keymeshing should be
  enabled or not.
  (main): output whether we should enable or disable keymeshing for a
  particular parameters set.
--

RFC 4357 defines CryptoPro keymeshing that should be applied depending
on selected S-BOX (param set). Declare if particular S-BOX should enable
or disable CryptoPro KeyMeshing.

Signed-off-by: Dmitry Baryshkov <dbaryshkov at gmail.com>
---
 cipher/gost-s-box.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/cipher/gost-s-box.c b/cipher/gost-s-box.c
index 7aa544476fb3..5d5ed7dc449a 100644
--- a/cipher/gost-s-box.c
+++ b/cipher/gost-s-box.c
@@ -26,9 +26,11 @@ struct gost_sbox
 {
   const char *name;
   const char *oid;
+  unsigned int keymeshing;
   unsigned char sbox[16*8];
 } gost_sboxes[] = {
-  { "test_3411", "1.2.643.2.2.30.0", {
+  { "test_3411", "1.2.643.2.2.30.0", 0,
+    {
       0x4, 0xE, 0x5, 0x7, 0x6, 0x4, 0xD, 0x1,
       0xA, 0xB, 0x8, 0xD, 0xC, 0xB, 0xB, 0xF,
       0x9, 0x4, 0x1, 0xA, 0x7, 0xA, 0x4, 0xD,
@@ -50,7 +52,8 @@ struct gost_sbox
       0x3, 0x9, 0xB, 0x3, 0x2, 0xE, 0xC, 0xC,
     }
   },
-  { "CryptoPro_3411", "1.2.643.2.2.30.1", {
+  { "CryptoPro_3411", "1.2.643.2.2.30.1", 0,
+     {
       0xA, 0x5, 0x7, 0x4, 0x7, 0x7, 0xD, 0x1,
       0x4, 0xF, 0xF, 0xA, 0x6, 0x6, 0xE, 0x3,
       0x5, 0x4, 0xC, 0x7, 0x4, 0x2, 0x4, 0xA,
@@ -72,7 +75,8 @@ struct gost_sbox
       0xF, 0x8, 0xD, 0x3, 0x5, 0x3, 0xB, 0xC,
     }
   },
-  { "Test_89", "1.2.643.2.2.31.0", {
+  { "Test_89", "1.2.643.2.2.31.0", 0,
+    {
       0x4, 0xC, 0xD, 0xE, 0x3, 0x8, 0x9, 0xC,
       0x2, 0x9, 0x8, 0x9, 0xE, 0xF, 0xB, 0x6,
       0xF, 0xF, 0xE, 0xB, 0x5, 0x6, 0xC, 0x5,
@@ -94,7 +98,8 @@ struct gost_sbox
       0x6, 0x5, 0xB, 0x8, 0x4, 0x4, 0xD, 0x8,
     }
   },
-  { "CryptoPro_A", "1.2.643.2.2.31.1", {
+  { "CryptoPro_A", "1.2.643.2.2.31.1", 1,
+    {
       0x9, 0x3, 0xE, 0xE, 0xB, 0x3, 0x1, 0xB,
       0x6, 0x7, 0x4, 0x7, 0x5, 0xA, 0xD, 0xA,
       0x3, 0xE, 0x6, 0xA, 0x1, 0xD, 0x2, 0xF,
@@ -116,7 +121,8 @@ struct gost_sbox
       0x5, 0x1, 0x9, 0x6, 0x6, 0x6, 0xE, 0x4,
     }
   },
-  { "CryptoPro_B", "1.2.643.2.2.31.2", {
+  { "CryptoPro_B", "1.2.643.2.2.31.2", 1,
+    {
       0x8, 0x0, 0xE, 0x7, 0x2, 0x8, 0x5, 0x0,
       0x4, 0x1, 0xC, 0x5, 0x7, 0x3, 0x2, 0x4,
       0xB, 0x2, 0x0, 0x0, 0xC, 0x2, 0xA, 0xB,
@@ -138,7 +144,8 @@ struct gost_sbox
       0xF, 0xE, 0x4, 0x8, 0x3, 0x5, 0xE, 0xC,
     }
   },
-  { "CryptoPro_C", "1.2.643.2.2.31.3", {
+  { "CryptoPro_C", "1.2.643.2.2.31.3", 1,
+    {
       0x1, 0x0, 0x8, 0x3, 0x8, 0xC, 0xA, 0x7,
       0xB, 0x1, 0x2, 0x6, 0xD, 0x9, 0x9, 0x4,
       0xC, 0x7, 0x5, 0x0, 0xB, 0xB, 0x6, 0x0,
@@ -160,7 +167,8 @@ struct gost_sbox
       0x3, 0x3, 0xB, 0x4, 0x7, 0xD, 0x7, 0x8,
     }
   },
-  { "CryptoPro_D", "1.2.643.2.2.31.4", {
+  { "CryptoPro_D", "1.2.643.2.2.31.4", 1,
+    {
       0xF, 0xB, 0x1, 0x1, 0x0, 0x8, 0x3, 0x1,
       0xC, 0x6, 0xC, 0x5, 0xC, 0x0, 0x0, 0xA,
       0x2, 0x3, 0xB, 0xE, 0x8, 0xF, 0x6, 0x6,
@@ -182,7 +190,8 @@ struct gost_sbox
       0x3, 0x1, 0x2, 0x8, 0x1, 0x6, 0x7, 0xE,
     }
   },
-  { "TC26_Z", "1.2.643.7.1.2.5.1.1", {
+  { "TC26_Z", "1.2.643.7.1.2.5.1.1", 1,
+    {
       0xc, 0x6, 0xb, 0xc, 0x7, 0x5, 0x8, 0x1,
       0x4, 0x8, 0x3, 0x8, 0xf, 0xd, 0xe, 0x7,
       0x6, 0x2, 0x5, 0x2, 0x5, 0xf, 0x2, 0xe,
@@ -242,14 +251,14 @@ int main(int argc, char **argv)
       fprintf (f, "\n  };\n\n");
     }
 
-  fprintf (f, "static struct\n{\n  const char *oid;\n  const u32 *sbox;\n} gost_oid_map[] = {\n");
+  fprintf (f, "static struct\n{\n  const char *oid;\n  const u32 *sbox;\n  const int keymeshing;\n} gost_oid_map[] = {\n");
 
   for (s = 0; s < DIM(gost_sboxes); s++)
     {
-      fprintf (f, "  { \"%s\", sbox_%s },\n", gost_sboxes[s].oid, gost_sboxes[s].name );
+      fprintf (f, "  { \"%s\", sbox_%s, %d },\n", gost_sboxes[s].oid, gost_sboxes[s].name, gost_sboxes[s].keymeshing );
     }
 
-  fprintf(f, "  { NULL, NULL }\n};\n");
+  fprintf(f, "  { NULL, NULL, 0 }\n};\n");
 
   fclose (f);
 
-- 
2.24.1




More information about the Gcrypt-devel mailing list