]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
nettle-meta: Expose defined MACs through nettle_macs move-nettle_mac
authorNiels Möller <nisse@lysator.liu.se>
Sun, 9 Feb 2020 13:13:22 +0000 (14:13 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Sun, 9 Feb 2020 13:13:22 +0000 (14:13 +0100)
Based on patches by Daiki Ueno.

ChangeLog
Makefile.in
nettle-meta-macs.c [new file with mode: 0644]
nettle-meta.h
testsuite/.gitignore
testsuite/.test-rules.make
testsuite/Makefile.in
testsuite/meta-mac-test.c [new file with mode: 0644]

index 119408d97aaa59bc1f5cd6f152c9be186f10ef50..5bb766814041714fbf48114a41faf999b9505a60 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,9 @@
 2020-02-09  Niels Möller  <nisse@lysator.liu.se>
 
-       Based on patches by Daiki Ueno.
+       Addition of struct nettle_mac based on patches by Daiki Ueno.
+       * nettle-meta-macs.c (nettle_get_macs): New file, new function.
+       * testsuite/meta-mac-test.c: New test.
+
        * nettle-meta.h (_NETTLE_HMAC): New macro.
        (nettle_hmac_md5, nettle_hmac_ripemd160, nettle_hmac_sha1)
        (nettle_hmac_sha224, nettle_hmac_sha256, nettle_hmac_sha384)
index 9eb4408e3dbad2ea1f25fddbcff2b453dd3761c9..d4fcb81302a245313afe828e324c6bf3103b91a5 100644 (file)
@@ -117,7 +117,7 @@ nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \
                 memeql-sec.c memxor.c memxor3.c \
                 nettle-lookup-hash.c \
                 nettle-meta-aeads.c nettle-meta-armors.c \
-                nettle-meta-ciphers.c nettle-meta-hashes.c \
+                nettle-meta-ciphers.c nettle-meta-hashes.c nettle-meta-macs.c \
                 pbkdf2.c pbkdf2-hmac-gosthash94.c pbkdf2-hmac-sha1.c \
                 pbkdf2-hmac-sha256.c \
                 poly1305-aes.c poly1305-internal.c \
diff --git a/nettle-meta-macs.c b/nettle-meta-macs.c
new file mode 100644 (file)
index 0000000..cb9ede8
--- /dev/null
@@ -0,0 +1,57 @@
+/* nettle-meta-macs.c
+
+   Copyright (C) 2020 Daiki Ueno
+
+   This file is part of GNU Nettle.
+
+   GNU Nettle is free software: you can redistribute it and/or
+   modify it under the terms of either:
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at your
+       option) any later version.
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at your
+       option) any later version.
+
+   or both in parallel, as here.
+
+   GNU Nettle is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see http://www.gnu.org/licenses/.
+*/
+
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stddef.h>
+
+#include "nettle-meta.h"
+
+const struct nettle_mac * const _nettle_macs[] = {
+  &nettle_cmac_aes128,
+  &nettle_cmac_aes256,
+  &nettle_hmac_md5,
+  &nettle_hmac_ripemd160,
+  &nettle_hmac_sha1,
+  &nettle_hmac_sha224,
+  &nettle_hmac_sha256,
+  &nettle_hmac_sha384,
+  &nettle_hmac_sha512,
+  NULL
+};
+
+const struct nettle_mac * const *
+nettle_get_macs (void)
+{
+  return _nettle_macs;
+}
index d5a009f4ac909fdfbca2edc66d39a5584b24e26e..5d86615f94cc3d35aef71e7f778ed030e2c9f771 100644 (file)
@@ -267,6 +267,13 @@ extern const struct nettle_armor nettle_base16;
   (nettle_hash_digest_func *) name##_digest,   \
 }
 
+/* null-terminated list of macs implemented by this
+   version of nettle */
+const struct nettle_mac * const * _NETTLE_ATTRIBUTE_PURE
+nettle_get_macs (void);
+
+#define nettle_macs (nettle_get_macs())
+
 extern const struct nettle_mac nettle_cmac_aes128;
 extern const struct nettle_mac nettle_cmac_aes256;
 
index be3a48707580bfdc02fffdcb49a9d6b227a8e474..b8b36c2accc2cdc4487feae49baaca60043fa8ef 100644 (file)
@@ -60,6 +60,7 @@
 /meta-armor-test
 /meta-cipher-test
 /meta-hash-test
+/meta-mac-test
 /pbkdf2-test
 /pkcs1-test
 /pkcs1-sec-decrypt-test
index 9fd11fd6d1267c63363c15dc9164e2517701f362..922a2c7f135068bf304d29ab6d248024cf1c6005 100644 (file)
@@ -163,6 +163,9 @@ meta-aead-test$(EXEEXT): meta-aead-test.$(OBJEXT)
 meta-armor-test$(EXEEXT): meta-armor-test.$(OBJEXT)
        $(LINK) meta-armor-test.$(OBJEXT) $(TEST_OBJS) -o meta-armor-test$(EXEEXT)
 
+meta-mac-test$(EXEEXT): meta-mac-test.$(OBJEXT)
+       $(LINK) meta-mac-test.$(OBJEXT) $(TEST_OBJS) -o meta-mac-test$(EXEEXT)
+
 buffer-test$(EXEEXT): buffer-test.$(OBJEXT)
        $(LINK) buffer-test.$(OBJEXT) $(TEST_OBJS) -o buffer-test$(EXEEXT)
 
index 73a61685dfc1dcd498aace7fb2127e4999f80add..813467a548bd1ccf9e52e51d717613f6ce35463b 100644 (file)
@@ -32,7 +32,7 @@ TS_NETTLE_SOURCES = aes-test.c arcfour-test.c arctwo-test.c \
                    poly1305-test.c chacha-poly1305-test.c \
                    hmac-test.c umac-test.c \
                    meta-hash-test.c meta-cipher-test.c\
-                   meta-aead-test.c meta-armor-test.c \
+                   meta-aead-test.c meta-armor-test.c meta-mac-test.c \
                    buffer-test.c yarrow-test.c xts-test.c pbkdf2-test.c
 
 TS_HOGWEED_SOURCES = sexp-test.c sexp-format-test.c \
diff --git a/testsuite/meta-mac-test.c b/testsuite/meta-mac-test.c
new file mode 100644 (file)
index 0000000..32b6f20
--- /dev/null
@@ -0,0 +1,32 @@
+#include "testutils.h"
+#include "nettle-meta.h"
+
+const char* macs[] = {
+  "cmac_aes128",
+  "cmac_aes256",
+  "hmac_md5",
+  "hmac_ripemd160",
+  "hmac_sha1",
+  "hmac_sha224",
+  "hmac_sha256",
+  "hmac_sha384",
+  "hmac_sha512",
+};
+
+void
+test_main(void)
+{
+  int i, j;
+  int count = sizeof(macs)/sizeof(*macs);
+  for (i = 0; i < count; i++) {
+    for (j = 0; NULL != nettle_macs[j]; j++) {
+      if (0 == strcmp(macs[i], nettle_macs[j]->name))
+       break;
+    }
+    ASSERT(NULL != nettle_macs[j]); /* make sure we found a matching mac */
+  }
+  i = 0;
+  while (NULL != nettle_macs[i])
+    i++;
+  ASSERT(i == count); /* we are not missing testing any macs */
+}