Commit d7f2dae9 authored by Niels Möller's avatar Niels Möller
Browse files

nettle-meta: Expose defined MACs through nettle_macs

Based on patches by Daiki Ueno.
parent 07309ccb
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)
......
......@@ -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 \
......
/* 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;
}
......@@ -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;
......
......@@ -60,6 +60,7 @@
/meta-armor-test
/meta-cipher-test
/meta-hash-test
/meta-mac-test
/pbkdf2-test
/pkcs1-test
/pkcs1-sec-decrypt-test
......
......@@ -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)
......
......@@ -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 \
......
#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 */
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment