[PATCH 1/2] mac: add support for gcry_mac_ctl(GCRYCTL_SET_SBOX)

dbaryshkov at gmail.com dbaryshkov at gmail.com
Sat Mar 21 20:33:50 CET 2020


From: Dmitry Baryshkov <dbaryshkov at gmail.com>

* cipher/mac-internal.h (gcry_mac_spec_ops_t): add set_extra_info field
for providing additional settings.
* cipher/mac.c (_gcry_mac_ctl): support GCRYCTL_SET_SBOX call.
* cipher/mac-cmac.c (cmac_ops): set set_extra_info to NULL.
* cipher/mac-gmac.c (gmac_ops): the same.
* cipher/mac-hmac.c (hmac_ops): the same.
* cipher/mac-poly1305.c (poly1305mac_ops): the same.

--
New MAC GOST28147-IMIT needs info about S-Box to be used. This info can
be passed via a call to gcry_mac_ctl(GCRYCTL_SET_SBOX, ...).

Signed-off-by: Dmitry Baryshkov <dbaryshkov at gmail.com>
---
 cipher/mac-cmac.c     | 3 ++-
 cipher/mac-gmac.c     | 3 ++-
 cipher/mac-hmac.c     | 3 ++-
 cipher/mac-internal.h | 4 ++++
 cipher/mac-poly1305.c | 3 ++-
 cipher/mac.c          | 7 +++++++
 6 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/cipher/mac-cmac.c b/cipher/mac-cmac.c
index e42a764de592..aee5bb63d05f 100644
--- a/cipher/mac-cmac.c
+++ b/cipher/mac-cmac.c
@@ -154,7 +154,8 @@ static gcry_mac_spec_ops_t cmac_ops = {
   cmac_read,
   cmac_verify,
   cmac_get_maclen,
-  cmac_get_keylen
+  cmac_get_keylen,
+  NULL
 };
 
 
diff --git a/cipher/mac-gmac.c b/cipher/mac-gmac.c
index 9bc86d970e6e..aa78c7e37d4d 100644
--- a/cipher/mac-gmac.c
+++ b/cipher/mac-gmac.c
@@ -149,7 +149,8 @@ static gcry_mac_spec_ops_t gmac_ops = {
   gmac_read,
   gmac_verify,
   gmac_get_maclen,
-  gmac_get_keylen
+  gmac_get_keylen,
+  NULL
 };
 
 
diff --git a/cipher/mac-hmac.c b/cipher/mac-hmac.c
index e488d03aa317..d0cc5775bb08 100644
--- a/cipher/mac-hmac.c
+++ b/cipher/mac-hmac.c
@@ -233,7 +233,8 @@ static const gcry_mac_spec_ops_t hmac_ops = {
   hmac_read,
   hmac_verify,
   hmac_get_maclen,
-  hmac_get_keylen
+  hmac_get_keylen,
+  NULL
 };
 
 
diff --git a/cipher/mac-internal.h b/cipher/mac-internal.h
index 03f5b8da8f4c..15b4dfc2c5de 100644
--- a/cipher/mac-internal.h
+++ b/cipher/mac-internal.h
@@ -63,6 +63,9 @@ typedef gcry_err_code_t (*gcry_mac_verify_func_t)(gcry_mac_hd_t h,
 typedef unsigned int (*gcry_mac_get_maclen_func_t)(int algo);
 typedef unsigned int (*gcry_mac_get_keylen_func_t)(int algo);
 
+/* The type used to convey additional information to a MAC.  */
+typedef gpg_err_code_t (*gcry_mac_set_extra_info_t)
+     (gcry_mac_hd_t h, int what, const void *buffer, size_t buflen);
 
 typedef struct gcry_mac_spec_ops
 {
@@ -76,6 +79,7 @@ typedef struct gcry_mac_spec_ops
   gcry_mac_verify_func_t verify;
   gcry_mac_get_maclen_func_t get_maclen;
   gcry_mac_get_keylen_func_t get_keylen;
+  gcry_mac_set_extra_info_t set_extra_info;
 } gcry_mac_spec_ops_t;
 
 
diff --git a/cipher/mac-poly1305.c b/cipher/mac-poly1305.c
index b80f87db3676..39ba790f8eee 100644
--- a/cipher/mac-poly1305.c
+++ b/cipher/mac-poly1305.c
@@ -322,7 +322,8 @@ static gcry_mac_spec_ops_t poly1305mac_ops = {
   poly1305mac_read,
   poly1305mac_verify,
   poly1305mac_get_maclen,
-  poly1305mac_get_keylen
+  poly1305mac_get_keylen,
+  NULL
 };
 
 
diff --git a/cipher/mac.c b/cipher/mac.c
index 0bbac3e414e4..1bc1aa985c93 100644
--- a/cipher/mac.c
+++ b/cipher/mac.c
@@ -708,6 +708,13 @@ _gcry_mac_ctl (gcry_mac_hd_t hd, int cmd, void *buffer, size_t buflen)
     case GCRYCTL_RESET:
       rc = mac_reset (hd);
       break;
+    case GCRYCTL_SET_SBOX:
+      if (hd->spec->ops->set_extra_info)
+        rc = hd->spec->ops->set_extra_info
+          (hd, GCRYCTL_SET_SBOX, buffer, buflen);
+      else
+        rc = GPG_ERR_NOT_SUPPORTED;
+      break;
     default:
       rc = GPG_ERR_INV_OP;
     }
-- 
2.25.1




More information about the Gcrypt-devel mailing list