]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
hmac: Added a unit test for the HMAC hash generation
authorSteve Holme <steve_holme@hotmail.com>
Sun, 23 Feb 2020 22:54:26 +0000 (22:54 +0000)
committerSteve Holme <steve_holme@hotmail.com>
Mon, 24 Feb 2020 06:57:03 +0000 (06:57 +0000)
Closes #4973

tests/data/Makefile.inc
tests/data/test1612 [new file with mode: 0644]
tests/unit/Makefile.inc
tests/unit/unit1612.c [new file with mode: 0644]

index f543f3b3cbaabd603cf0f4a6bc5a2674899e9c9c..21ca571ef52972e5360c7011c19146265926f8d7 100644 (file)
@@ -183,7 +183,7 @@ test1558 test1559 test1560 test1561 test1562 test1563 test1564 test1565 \
 test1590 test1591 test1592 test1593 test1594 test1595 test1596 \
 \
 test1600 test1601 test1602 test1603 test1604 test1605 test1606 test1607 \
-test1608 test1609 test1610 test1611 \
+test1608 test1609 test1610 test1611 test1612 \
 \
 test1620 test1621 \
 \
diff --git a/tests/data/test1612 b/tests/data/test1612
new file mode 100644 (file)
index 0000000..c9a772b
--- /dev/null
@@ -0,0 +1,26 @@
+<testcase>
+<info>
+<keywords>
+unittest
+HMAC
+</keywords>
+</info>
+
+#
+# Client-side
+<client>
+<server>
+none
+</server>
+<features>
+unittest
+</features>
+ <name>
+HMAC unit tests
+ </name>
+<tool>
+unit1612
+</tool>
+</client>
+
+</testcase>
index b8da0c20c59eb4bfc472972e44786c37a71c1fc4..4fe80d5dbc202aafd665f8d0b2367c1b7f2c4a28 100644 (file)
@@ -32,7 +32,7 @@ UNITPROGS = unit1300 unit1301 unit1302 unit1303 unit1304 unit1305 unit1307 \
  unit1330 unit1394 unit1395 unit1396 unit1397 unit1398 \
  unit1399 \
  unit1600 unit1601 unit1602 unit1603 unit1604 unit1605 unit1606 unit1607 \
- unit1608 unit1609 unit1610 unit1611 \
+ unit1608 unit1609 unit1610 unit1611 unit1612 \
  unit1620 unit1621 \
  unit1650 unit1651 unit1652 unit1653 unit1654 unit1655
 
@@ -126,6 +126,9 @@ unit1610_CPPFLAGS = $(AM_CPPFLAGS)
 unit1611_SOURCES = unit1611.c $(UNITFILES)
 unit1611_CPPFLAGS = $(AM_CPPFLAGS)
 
+unit1612_SOURCES = unit1611.c $(UNITFILES)
+unit1612_CPPFLAGS = $(AM_CPPFLAGS)
+
 unit1620_SOURCES = unit1620.c $(UNITFILES)
 unit1620_CPPFLAGS = $(AM_CPPFLAGS)
 
diff --git a/tests/unit/unit1612.c b/tests/unit/unit1612.c
new file mode 100644 (file)
index 0000000..be45397
--- /dev/null
@@ -0,0 +1,65 @@
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at https://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+#include "curlcheck.h"
+
+#include "curl_hmac.h"
+
+static CURLcode unit_setup(void)
+{
+  return CURLE_OK;
+}
+
+static void unit_stop(void)
+{
+
+}
+
+UNITTEST_START
+
+#ifndef CURL_DISABLE_CRYPTO_AUTH
+  const char password[] = "Pa55worD";
+  const char string1[] = "1";
+  const char string2[] = "hello-you-fool";
+  unsigned char output[HMAC_MD5_LENGTH];
+  unsigned char *testp = output;
+
+  Curl_hmacit(Curl_HMAC_MD5,
+              (const unsigned char *) password, strlen(password),
+              (const unsigned char *) string1, strlen(string1)
+              output);
+
+  verify_memory(testp,
+                "\xd1\x29\x75\x43\x58\xdc\xab\x78\xdf\xcd\x7f\x2b\x29\x31\x13"
+                "\x37", HMAC_MD5_LENGTH);
+
+  Curl_hmacit(Curl_HMAC_MD5,
+              (const unsigned char *) password, strlen(password),
+              (const unsigned char *) string2, strlen(string2),
+              output);
+
+  verify_memory(testp,
+                "\x75\xf1\xa7\xb9\xf5\x40\xe5\xa4\x98\x83\x9f\x64\x5a\x27\x6d"
+                "\xd0", HMAC_MD5_LENGTH);
+#endif
+
+
+UNITTEST_STOP