summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2020-02-09 14:13:22 +0100
committerNiels Möller <nisse@lysator.liu.se>2020-02-09 14:13:22 +0100
commitd7f2dae963d279782582d785c80ddef377dfe6dc (patch)
tree3db098a5befa00d7e4a8cd40f5c0b2b55d17fc6b
parent07309ccbe5b6766441b7ae60fd9b8a8cf527511d (diff)
downloadnettle-move-nettle_mac.tar.gz
nettle-meta: Expose defined MACs through nettle_macsmove-nettle_mac
Based on patches by Daiki Ueno.
-rw-r--r--ChangeLog5
-rw-r--r--Makefile.in2
-rw-r--r--nettle-meta-macs.c57
-rw-r--r--nettle-meta.h7
-rw-r--r--testsuite/.gitignore1
-rw-r--r--testsuite/.test-rules.make3
-rw-r--r--testsuite/Makefile.in2
-rw-r--r--testsuite/meta-mac-test.c32
8 files changed, 106 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 119408d9..5bb76681 100644
--- 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)
diff --git a/Makefile.in b/Makefile.in
index 9eb4408e..d4fcb813 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -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
index 00000000..cb9ede85
--- /dev/null
+++ b/nettle-meta-macs.c
@@ -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;
+}
diff --git a/nettle-meta.h b/nettle-meta.h
index d5a009f4..5d86615f 100644
--- a/nettle-meta.h
+++ b/nettle-meta.h
@@ -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;
diff --git a/testsuite/.gitignore b/testsuite/.gitignore
index be3a4870..b8b36c2a 100644
--- a/testsuite/.gitignore
+++ b/testsuite/.gitignore
@@ -60,6 +60,7 @@
/meta-armor-test
/meta-cipher-test
/meta-hash-test
+/meta-mac-test
/pbkdf2-test
/pkcs1-test
/pkcs1-sec-decrypt-test
diff --git a/testsuite/.test-rules.make b/testsuite/.test-rules.make
index 9fd11fd6..922a2c7f 100644
--- a/testsuite/.test-rules.make
+++ b/testsuite/.test-rules.make
@@ -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)
diff --git a/testsuite/Makefile.in b/testsuite/Makefile.in
index 73a61685..813467a5 100644
--- a/testsuite/Makefile.in
+++ b/testsuite/Makefile.in
@@ -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
index 00000000..32b6f20f
--- /dev/null
+++ b/testsuite/meta-mac-test.c
@@ -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 */
+}