]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Add meta interface for HMAC functions.
authorNiels Möller <nisse@lysator.liu.se>
Sun, 9 Feb 2020 08:57:34 +0000 (09:57 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Sun, 9 Feb 2020 08:57:34 +0000 (09:57 +0100)
Based on patches by Daiki Ueno.

13 files changed:
ChangeLog
Makefile.in
hmac-md5-meta.c [new file with mode: 0644]
hmac-ripemd160-meta.c [new file with mode: 0644]
hmac-sha1-meta.c [new file with mode: 0644]
hmac-sha224-meta.c [new file with mode: 0644]
hmac-sha256-meta.c [new file with mode: 0644]
hmac-sha384-meta.c [new file with mode: 0644]
hmac-sha512-meta.c [new file with mode: 0644]
nettle-meta.h
testsuite/hmac-test.c
testsuite/testutils.c
testsuite/testutils.h

index a5da54b4282be1f2921329e95986a3c5f836b408..119408d97aaa59bc1f5cd6f152c9be186f10ef50 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,12 +1,35 @@
 2020-02-09  Niels Möller  <nisse@lysator.liu.se>
 
        Based on patches by Daiki Ueno.
+       * 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)
+       (nettle_hmac_sha512): Declare.
+       (struct nettle_mac): New public struct,
+       * testsuite/testutils.h: ...moved from this file.
+
+       * hmac-md5-meta.c: New file.
+       * hmac-ripemd160-meta.c: Likewise.
+       * hmac-sha1-meta.c: Likewise.
+       * hmac-sha224-meta.c: Likewise.
+       * hmac-sha256-meta.c: Likewise.
+       * hmac-sha384-meta.c: Likewise.
+       * hmac-sha512-meta.c: Likewise.
+
+       * Makefile.in (nettle_SOURCES): Add new files.
+
+       * testsuite/testutils.h (_NETTLE_HMAC): Delete unused version of
+       this macro.
+       * testsuite/testutils.c (test_mac): Allow testing with smaller
+       digest size.
+       * testsuite/hmac-test.c (test_main): Use test_mac for tests using
+       key size == digest size.
+
        * testsuite/cmac-test.c (nettle_cmac_aes128, nettle_cmac_aes256):
        Moved to...
        * cmac-aes128-meta.c: New file.
        * cmac-aes256-meta.c: New file.
 
-       * Makefile.in (nettle_SOURCES): Add cmac-aes128-meta.c cmac-aes256-meta.c.
        * nettle-meta.h (struct nettle_mac): New public struct,
        * testsuite/testutils.h: ...moved from this file.
 
index c1302a5faa084c99340dd54e078e0be2c18d2f9f..9eb4408e3dbad2ea1f25fddbcff2b453dd3761c9 100644 (file)
@@ -108,6 +108,9 @@ nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \
                 hmac.c hmac-gosthash94.c hmac-md5.c hmac-ripemd160.c \
                 hmac-sha1.c hmac-sha224.c hmac-sha256.c hmac-sha384.c \
                 hmac-sha512.c \
+                hmac-md5-meta.c hmac-ripemd160-meta.c hmac-sha1-meta.c \
+                hmac-sha224-meta.c hmac-sha256-meta.c hmac-sha384-meta.c \
+                hmac-sha512-meta.c \
                 knuth-lfib.c hkdf.c \
                 md2.c md2-meta.c md4.c md4-meta.c \
                 md5.c md5-compress.c md5-compat.c md5-meta.c \
diff --git a/hmac-md5-meta.c b/hmac-md5-meta.c
new file mode 100644 (file)
index 0000000..94dc865
--- /dev/null
@@ -0,0 +1,47 @@
+/* hmac-md5-meta.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 "nettle-meta.h"
+
+#include "hmac.h"
+
+static void
+hmac_md5_set_key_wrapper (void *ctx, const uint8_t *key)
+{
+  hmac_md5_set_key (ctx, MD5_DIGEST_SIZE, key);
+}
+
+const struct nettle_mac nettle_hmac_md5
+= _NETTLE_HMAC(hmac_md5, MD5);
diff --git a/hmac-ripemd160-meta.c b/hmac-ripemd160-meta.c
new file mode 100644 (file)
index 0000000..cd561bc
--- /dev/null
@@ -0,0 +1,47 @@
+/* hmac-ripemd160-meta.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 "nettle-meta.h"
+
+#include "hmac.h"
+
+static void
+hmac_ripemd160_set_key_wrapper (void *ctx, const uint8_t *key)
+{
+  hmac_ripemd160_set_key (ctx, RIPEMD160_DIGEST_SIZE, key);
+}
+
+const struct nettle_mac nettle_hmac_ripemd160
+= _NETTLE_HMAC(hmac_ripemd160, RIPEMD160);
diff --git a/hmac-sha1-meta.c b/hmac-sha1-meta.c
new file mode 100644 (file)
index 0000000..2b23f83
--- /dev/null
@@ -0,0 +1,47 @@
+/* hmac-sha1-meta.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 "nettle-meta.h"
+
+#include "hmac.h"
+
+static void
+hmac_sha1_set_key_wrapper (void *ctx, const uint8_t *key)
+{
+  hmac_sha1_set_key (ctx, SHA1_DIGEST_SIZE, key);
+}
+
+const struct nettle_mac nettle_hmac_sha1
+= _NETTLE_HMAC(hmac_sha1, SHA1);
diff --git a/hmac-sha224-meta.c b/hmac-sha224-meta.c
new file mode 100644 (file)
index 0000000..65e7414
--- /dev/null
@@ -0,0 +1,47 @@
+/* hmac-sha224-meta.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 "nettle-meta.h"
+
+#include "hmac.h"
+
+static void
+hmac_sha224_set_key_wrapper (void *ctx, const uint8_t *key)
+{
+  hmac_sha224_set_key (ctx, SHA224_DIGEST_SIZE, key);
+}
+
+const struct nettle_mac nettle_hmac_sha224
+= _NETTLE_HMAC(hmac_sha224, SHA224);
diff --git a/hmac-sha256-meta.c b/hmac-sha256-meta.c
new file mode 100644 (file)
index 0000000..4805c2b
--- /dev/null
@@ -0,0 +1,47 @@
+/* hmac-sha256-meta.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 "nettle-meta.h"
+
+#include "hmac.h"
+
+static void
+hmac_sha256_set_key_wrapper (void *ctx, const uint8_t *key)
+{
+  hmac_sha256_set_key (ctx, SHA256_DIGEST_SIZE, key);
+}
+
+const struct nettle_mac nettle_hmac_sha256
+= _NETTLE_HMAC(hmac_sha256, SHA256);
diff --git a/hmac-sha384-meta.c b/hmac-sha384-meta.c
new file mode 100644 (file)
index 0000000..974d4ce
--- /dev/null
@@ -0,0 +1,47 @@
+/* hmac-sha384-meta.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 "nettle-meta.h"
+
+#include "hmac.h"
+
+static void
+hmac_sha384_set_key_wrapper (void *ctx, const uint8_t *key)
+{
+  hmac_sha384_set_key (ctx, SHA384_DIGEST_SIZE, key);
+}
+
+const struct nettle_mac nettle_hmac_sha384
+= _NETTLE_HMAC(hmac_sha384, SHA384);
diff --git a/hmac-sha512-meta.c b/hmac-sha512-meta.c
new file mode 100644 (file)
index 0000000..a8a61d8
--- /dev/null
@@ -0,0 +1,47 @@
+/* hmac-sha512-meta.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 "nettle-meta.h"
+
+#include "hmac.h"
+
+static void
+hmac_sha512_set_key_wrapper (void *ctx, const uint8_t *key)
+{
+  hmac_sha512_set_key (ctx, SHA512_DIGEST_SIZE, key);
+}
+
+const struct nettle_mac nettle_hmac_sha512
+= _NETTLE_HMAC(hmac_sha512, SHA512);
index 42f8a8635bbada69a345990610dbcc47556b13dc..d5a009f4ac909fdfbca2edc66d39a5584b24e26e 100644 (file)
@@ -2,7 +2,7 @@
 
    Information about algorithms.
 
-   Copyright (C) 2002, 2014 Niels Möller
+   Copyright (C) 2002, 2014, 2020 Niels Möller
 
    This file is part of GNU Nettle.
 
@@ -257,9 +257,28 @@ extern const struct nettle_armor nettle_base64;
 extern const struct nettle_armor nettle_base64url;
 extern const struct nettle_armor nettle_base16;
 
+#define _NETTLE_HMAC(name, HASH) {             \
+  #name,                                       \
+  sizeof(struct name##_ctx),                   \
+  HASH##_DIGEST_SIZE,                          \
+  HASH##_DIGEST_SIZE,                          \
+  name##_set_key_wrapper,                      \
+  (nettle_hash_update_func *) name##_update,   \
+  (nettle_hash_digest_func *) name##_digest,   \
+}
+
 extern const struct nettle_mac nettle_cmac_aes128;
 extern const struct nettle_mac nettle_cmac_aes256;
 
+/* HMAC variants with key size = digest size */
+extern const struct nettle_mac nettle_hmac_md5;
+extern const struct nettle_mac nettle_hmac_ripemd160;
+extern const struct nettle_mac nettle_hmac_sha1;
+extern const struct nettle_mac nettle_hmac_sha224;
+extern const struct nettle_mac nettle_hmac_sha256;
+extern const struct nettle_mac nettle_hmac_sha384;
+extern const struct nettle_mac nettle_hmac_sha512;
+
 #ifdef __cplusplus
 }
 #endif
index f009c8003d34097faac24736bb4fd6fe09a00e80..de1b6bfe057c034dd8772a8aa65f35fd9aa768dd 100644 (file)
@@ -24,12 +24,11 @@ test_main(void)
   /* Test vectors for md5, from RFC-2202 */
 
   /* md5 - 1 */
-  HMAC_TEST(md5,
+  test_mac (&nettle_hmac_md5,
            SHEX("0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b"),
            SDATA("Hi There"),
            SHEX("9294727a3638bb1c 13f48ef8158bfc9d"));
 
-
   /* md5 - 2 */
   HMAC_TEST(md5,
            SDATA("Jefe"),
@@ -37,7 +36,7 @@ test_main(void)
            SHEX("750c783e6ab0b503 eaa86e310a5db738"));     
 
   /* md5 - 3 */
-  HMAC_TEST(md5,
+  test_mac(&nettle_hmac_md5,
            SHEX("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
            SHEX("dddddddddddddddd dddddddddddddddd"
                 "dddddddddddddddd dddddddddddddddd"
@@ -56,7 +55,7 @@ test_main(void)
            SHEX("697eaf0aca3a3aea 3a75164746ffaa79"));
 
   /* md5 - 5 */
-  HMAC_TEST(md5,
+  test_mac(&nettle_hmac_md5,
            SHEX("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c"),
            SDATA("Test With Truncation"),
            SHEX("56461ef2342edc00 f9bab995"));
@@ -125,73 +124,73 @@ test_main(void)
 
   /* Test vectors for ripemd160, from
      http://homes.esat.kuleuven.be/~bosselae/ripemd160.html */
-  HMAC_TEST(ripemd160,
+  test_mac(&nettle_hmac_ripemd160,
            SHEX("00112233445566778899aabbccddeeff01234567"),
            SDATA(""),
            SHEX("cf387677bfda8483e63b57e06c3b5ecd8b7fc055"));
 
-  HMAC_TEST(ripemd160,
+  test_mac(&nettle_hmac_ripemd160,
            SHEX("00112233445566778899aabbccddeeff01234567"),
            SDATA("a"),
            SHEX("0d351d71b78e36dbb7391c810a0d2b6240ddbafc"));
 
-  HMAC_TEST(ripemd160,
+  test_mac(&nettle_hmac_ripemd160,
            SHEX("00112233445566778899aabbccddeeff01234567"),
            SDATA("abc"),
            SHEX("f7ef288cb1bbcc6160d76507e0a3bbf712fb67d6"));
 
-  HMAC_TEST(ripemd160,
+  test_mac(&nettle_hmac_ripemd160,
            SHEX("00112233445566778899aabbccddeeff01234567"),
            SDATA("message digest"),
            SHEX("f83662cc8d339c227e600fcd636c57d2571b1c34"));
 
-  HMAC_TEST(ripemd160,
+  test_mac(&nettle_hmac_ripemd160,
            SHEX("00112233445566778899aabbccddeeff01234567"),
            SDATA("abcdefghijklmnopqrstuvwxyz"),
            SHEX("843d1c4eb880ac8ac0c9c95696507957d0155ddb"));
 
-  HMAC_TEST(ripemd160,
+  test_mac(&nettle_hmac_ripemd160,
            SHEX("00112233445566778899aabbccddeeff01234567"),
            SDATA("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"),
            SHEX("60f5ef198a2dd5745545c1f0c47aa3fb5776f881"));
 
-  HMAC_TEST(ripemd160,
+  test_mac(&nettle_hmac_ripemd160,
            SHEX("00112233445566778899aabbccddeeff01234567"),
            SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
            SHEX("e49c136a9e5627e0681b808a3b97e6a6e661ae79"));
 
   /* Other key */
-  HMAC_TEST(ripemd160,
+  test_mac(&nettle_hmac_ripemd160,
            SHEX("0123456789abcdeffedcba987654321000112233"),
            SDATA(""),
            SHEX("fe69a66c7423eea9c8fa2eff8d9dafb4f17a62f5"));
 
-  HMAC_TEST(ripemd160,
+  test_mac(&nettle_hmac_ripemd160,
            SHEX("0123456789abcdeffedcba987654321000112233"),
            SDATA("a"),
            SHEX("85743e899bc82dbfa36faaa7a25b7cfd372432cd"));
 
-  HMAC_TEST(ripemd160,
+  test_mac(&nettle_hmac_ripemd160,
            SHEX("0123456789abcdeffedcba987654321000112233"),
            SDATA("abc"),
            SHEX("6e4afd501fa6b4a1823ca3b10bd9aa0ba97ba182"));
 
-  HMAC_TEST(ripemd160,
+  test_mac(&nettle_hmac_ripemd160,
            SHEX("0123456789abcdeffedcba987654321000112233"),
            SDATA("message digest"),
            SHEX("2e066e624badb76a184c8f90fba053330e650e92"));
 
-  HMAC_TEST(ripemd160,
+  test_mac(&nettle_hmac_ripemd160,
            SHEX("0123456789abcdeffedcba987654321000112233"),
            SDATA("abcdefghijklmnopqrstuvwxyz"),
            SHEX("07e942aa4e3cd7c04dedc1d46e2e8cc4c741b3d9"));
 
-  HMAC_TEST(ripemd160,
+  test_mac(&nettle_hmac_ripemd160,
            SHEX("0123456789abcdeffedcba987654321000112233"),
            SDATA("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"),
            SHEX("b6582318ddcfb67a53a67d676b8ad869aded629a"));
 
-  HMAC_TEST(ripemd160,
+  test_mac(&nettle_hmac_ripemd160,
            SHEX("0123456789abcdeffedcba987654321000112233"),
            SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
            SHEX("f1be3ee877703140d34f97ea1ab3a07c141333e2"));
@@ -199,7 +198,7 @@ test_main(void)
   /* Test vectors for sha1, from RFC-2202 */
 
   /* sha1 - 1 */
-  HMAC_TEST(sha1,
+  test_mac(&nettle_hmac_sha1,
            SHEX("0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b 0b0b0b0b"),
            SDATA("Hi There"),
            SHEX("b617318655057264 e28bc0b6fb378c8e f146be00"));
@@ -211,7 +210,7 @@ test_main(void)
            SHEX("effcdf6ae5eb2fa2 d27416d5f184df9c 259a7c79"));
 
   /* sha1 - 3 */
-  HMAC_TEST(sha1,
+  test_mac(&nettle_hmac_sha1,
            SHEX("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa aaaaaaaa"),
            SHEX("dddddddddddddddd dddddddddddddddd"
                 "dddddddddddddddd dddddddddddddddd"
@@ -230,7 +229,7 @@ test_main(void)
            SHEX("4c9007f4026250c6 bc8414f9bf50c86c 2d7235da"));
 
   /* sha1 - 5 */
-  HMAC_TEST(sha1,
+  test_mac(&nettle_hmac_sha1,
            SHEX("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"),
            SDATA("Test With Truncation"),
            SHEX("4c1a03424b55e07f e7f27be1"));
@@ -256,47 +255,6 @@ test_main(void)
                  "Than One Block-Size Data"),
            SHEX("e8e99d0f45237d78 6d6bbaa7965c7808 bbff1a91"));
 
-  /* Additional test vectors, from Daniel Kahn Gillmor */
-  HMAC_TEST(md5,
-           SDATA("monkey monkey monkey monkey"),
-           SDATA(""),
-           SHEX("e84db42a188813f30a15e611d64c7869"));
-  
-  HMAC_TEST(md5,
-           SDATA("monkey monkey monkey monkey"),
-           SDATA("a"),
-           SHEX("123662062e67c2aab371cc49db0df134"));
-  
-  HMAC_TEST(md5,
-           SDATA("monkey monkey monkey monkey"),
-           SDATA("38"),
-           SHEX("0a46cc10a49d4b7025c040c597bf5d76"));
-  
-  HMAC_TEST(md5,
-           SDATA("monkey monkey monkey monkey"),
-           SDATA("abc"),
-           SHEX("d1f4d89f0e8b2b6ed0623c99ec298310"));
-  
-  HMAC_TEST(md5,
-           SDATA("monkey monkey monkey monkey"),
-           SDATA("message digest"),
-           SHEX("1627207b9bed5009a4f6e9ca8d2ca01e"));
-  
-  HMAC_TEST(md5,
-           SDATA("monkey monkey monkey monkey"),
-           SDATA("abcdefghijklmnopqrstuvwxyz"),
-           SHEX("922aae6ab3b3a29202e21ce5f916ae9a"));
-
-  HMAC_TEST(md5,
-           SDATA("monkey monkey monkey monkey"),
-           SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
-           SHEX("ede9cb83679ba82d88fbeae865b3f8fc"));
-
-  HMAC_TEST(md5,
-           SDATA("monkey monkey monkey monkey"),
-           SDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"),
-           SHEX("939dd45512ee3a594b6654f6b8de27f7"));
-
   /* Test vectors for sha224, from RFC 4231 */
   HMAC_TEST(sha224,
            SHEX("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
@@ -490,7 +448,7 @@ test_main(void)
      draft-ietf-ipsec-ciph-sha-256-01.txt */
 
   /* Test Case #1: HMAC-SHA-256 with 3-byte input and 32-byte key */
-  HMAC_TEST(sha256,
+  test_mac(&nettle_hmac_sha256,
            SHEX("0102030405060708 090a0b0c0d0e0f10"
                 "1112131415161718 191a1b1c1d1e1f20"),
            SDATA("abc"),
@@ -498,7 +456,7 @@ test_main(void)
                 "7f98cc131cb16a66 92759021cfab8181"));
 
   /* Test Case #2: HMAC-SHA-256 with 56-byte input and 32-byte key */
-  HMAC_TEST(sha256,
+  test_mac(&nettle_hmac_sha256,
            SHEX("0102030405060708 090a0b0c0d0e0f10"
                 "1112131415161718 191a1b1c1d1e1f20"),
            SDATA("abcdbcdecdefdefgefghfghighijhijk"
@@ -508,7 +466,7 @@ test_main(void)
 
   /* Test Case #3: HMAC-SHA-256 with 112-byte (multi-block) input
      and 32-byte key */
-  HMAC_TEST(sha256,
+  test_mac(&nettle_hmac_sha256,
            SHEX("0102030405060708 090a0b0c0d0e0f10"
                 "1112131415161718 191a1b1c1d1e1f20"),
            SDATA("abcdbcdecdefdefgefghfghighijhijk"
@@ -519,7 +477,7 @@ test_main(void)
                 "73acf0fd060447a5 eb4595bf33a9d1a3"));
 
   /* Test Case #4:  HMAC-SHA-256 with 8-byte input and 32-byte key */
-  HMAC_TEST(sha256,
+  test_mac(&nettle_hmac_sha256,
            SHEX("0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b"
                 "0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b"),
            SDATA("Hi There"),
@@ -527,7 +485,7 @@ test_main(void)
                 "ba0aa3f3d9ae3c1c 7a3b1696a0b68cf7"));
 
   /* Test Case #6: HMAC-SHA-256 with 50-byte input and 32-byte key */
-  HMAC_TEST(sha256,
+  test_mac(&nettle_hmac_sha256,
            SHEX("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
                 "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
            SHEX("dddddddddddddddd dddddddddddddddd"
@@ -550,7 +508,7 @@ test_main(void)
                 "6ec4af55ef079985 41468eb49bd2e917"));
 
   /* Test Case #8: HMAC-SHA-256 with 20-byte input and 32-byte key */
-  HMAC_TEST(sha256,
+  test_mac(&nettle_hmac_sha256,
            SHEX("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c"
                 "0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c"),
            SDATA("Test With Truncation"),
@@ -855,7 +813,7 @@ test_main(void)
      draft-kelly-ipsec-ciph-sha2-01.txt */
 
   /* Test case AUTH512-1: */
-  HMAC_TEST(sha512,
+  test_mac(&nettle_hmac_sha512,
            SHEX("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
                 "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
                 "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
@@ -879,7 +837,7 @@ test_main(void)
                 "fa0ffb93466cfcceaae38c833b7dba38"));
 
   /* Test case AUTH512-3: */
-  HMAC_TEST(sha512,
+  test_mac(&nettle_hmac_sha512,
            SHEX("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
                 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
                 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
index bb6ad54bffd881a8ec8755ca5dafdaeb223878ed..187da0efda2935323aa27d23a8e62b29a5c34920 100644 (file)
@@ -963,8 +963,7 @@ test_mac(const struct nettle_mac *mac,
   uint8_t *hash = xalloc(mac->digest_size);
   unsigned i;
 
-
-  ASSERT (digest->length == mac->digest_size);
+  ASSERT (digest->length <= mac->digest_size);
   ASSERT (key->length == mac->key_size);
   mac->set_key (ctx, key->data);
   mac->update (ctx, msg->length, msg->data);
index 221255c5d01eee1d3d65d5acb6f0ce3ce89350cc..8ace6a82357f416a4a461d652f6e3acdb4262ee4 100644 (file)
@@ -79,16 +79,6 @@ test_main(void);
 
 extern int verbose;
 
-#define _NETTLE_HMAC(name, NAME, keysize) {    \
-  #name,                                       \
-  sizeof(struct hmac_##name##_ctx),            \
-  NAME##_DIGEST_SIZE,                          \
-  NAME##_DIGEST_SIZE,                          \
-  hmac_##name##_set_key,                       \
-  hmac_##name##_update,                                \
-  hmac_##name##_digest,                                \
-}
-
 /* Test functions deallocate their inputs when finished.*/
 void
 test_cipher(const struct nettle_cipher *cipher,