[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnurl] 143/282: tests: Added a unit test for SHA256 digest generation
From: |
gnunet |
Subject: |
[gnurl] 143/282: tests: Added a unit test for SHA256 digest generation |
Date: |
Wed, 01 Apr 2020 14:30:08 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository gnurl.
commit 81c37124341e2c2f80a9c2f60cefaf61143c78b7
Author: Steve Holme <address@hidden>
AuthorDate: Sat Feb 22 18:17:12 2020 +0000
tests: Added a unit test for SHA256 digest generation
Follow up to 2b5b37c.
Closes #4968
---
lib/curl_sha256.h | 8 +++---
lib/sha256.c | 6 ++++-
tests/data/Makefile.inc | 4 ++-
tests/data/test1610 | 26 +++++++++++++++++++
tests/unit/Makefile.inc | 28 ++++++++++++++++++++-
lib/curl_sha256.h => tests/unit/unit1610.c | 40 +++++++++++++++++++++++++-----
6 files changed, 100 insertions(+), 12 deletions(-)
diff --git a/lib/curl_sha256.h b/lib/curl_sha256.h
index 14b6414ea..922e501da 100644
--- a/lib/curl_sha256.h
+++ b/lib/curl_sha256.h
@@ -7,7 +7,8 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2019, Florin Petriuc, <address@hidden>
+ * Copyright (C) 2017, Florin Petriuc, <address@hidden>
+ * Copyright (C) 2018 - 2020, Daniel Stenberg, <address@hidden>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -24,8 +25,9 @@
#ifndef CURL_DISABLE_CRYPTO_AUTH
-void Curl_sha256it(unsigned char *outbuffer,
- const unsigned char *input);
+#define SHA256_DIGEST_LENGTH 32
+
+void Curl_sha256it(unsigned char *outbuffer, const unsigned char *input);
#endif
diff --git a/lib/sha256.c b/lib/sha256.c
index bcaaeae30..5127a9edd 100644
--- a/lib/sha256.c
+++ b/lib/sha256.c
@@ -5,7 +5,8 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2019, Florin Petriuc, <address@hidden>
+ * Copyright (C) 2017, Florin Petriuc, <address@hidden>
+ * Copyright (C) 2018 - 2020, Daniel Stenberg, <address@hidden>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -255,6 +256,9 @@ static int SHA256_Final(unsigned char *out,
#endif
+/*
+ * @unittest: 1610
+ */
void Curl_sha256it(unsigned char *outbuffer, /* 32 unsigned chars */
const unsigned char *input)
{
diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc
index be55f0460..4cc040772 100644
--- a/tests/data/Makefile.inc
+++ b/tests/data/Makefile.inc
@@ -183,7 +183,9 @@ 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 test1620 test1621 \
+test1608 test1609 test1610 \
+\
+test1620 test1621 \
\
test1650 test1651 test1652 test1653 test1654 test1655 \
\
diff --git a/tests/data/test1610 b/tests/data/test1610
new file mode 100644
index 000000000..30d37779b
--- /dev/null
+++ b/tests/data/test1610
@@ -0,0 +1,26 @@
+<testcase>
+<info>
+<keywords>
+unittest
+SHA256
+</keywords>
+</info>
+
+#
+# Client-side
+<client>
+<server>
+none
+</server>
+<features>
+unittest
+</features>
+ <name>
+SHA256 unit tests
+ </name>
+<tool>
+unit1601
+</tool>
+</client>
+
+</testcase>
diff --git a/tests/unit/Makefile.inc b/tests/unit/Makefile.inc
index 45278ba81..b70d32004 100644
--- a/tests/unit/Makefile.inc
+++ b/tests/unit/Makefile.inc
@@ -1,3 +1,25 @@
+#***************************************************************************
+# _ _ ____ _
+# Project ___| | | | _ \| |
+# / __| | | | |_) | |
+# | (__| |_| | _ <| |___
+# \___|\___/|_| \_\_____|
+#
+# Copyright (C) 1998 - 2020, Daniel Stenberg, <address@hidden>, 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.
+#
+###########################################################################
+
# these files are used in every single unit test program
UNITFILES = curlcheck.h \
@@ -10,7 +32,8 @@ 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 unit1620 unit1621 \
+ unit1608 unit1609 unit1610 \
+ unit1620 unit1621 \
unit1650 unit1651 unit1652 unit1653 unit1654 unit1655
unit1300_SOURCES = unit1300.c $(UNITFILES)
@@ -97,6 +120,9 @@ unit1608_CPPFLAGS = $(AM_CPPFLAGS)
unit1609_SOURCES = unit1609.c $(UNITFILES)
unit1609_CPPFLAGS = $(AM_CPPFLAGS)
+unit1610_SOURCES = unit1610.c $(UNITFILES)
+unit1610_CPPFLAGS = $(AM_CPPFLAGS)
+
unit1620_SOURCES = unit1620.c $(UNITFILES)
unit1620_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/lib/curl_sha256.h b/tests/unit/unit1610.c
similarity index 50%
copy from lib/curl_sha256.h
copy to tests/unit/unit1610.c
index 14b6414ea..06c97198b 100644
--- a/lib/curl_sha256.h
+++ b/tests/unit/unit1610.c
@@ -1,5 +1,3 @@
-#ifndef HEADER_CURL_SHA256_H
-#define HEADER_CURL_SHA256_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
@@ -7,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2019, Florin Petriuc, <address@hidden>
+ * Copyright (C) 1998 - 2020, Daniel Stenberg, <address@hidden>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -21,12 +19,42 @@
* KIND, either express or implied.
*
***************************************************************************/
+#include "curlcheck.h"
+
+#include "curl_sha256.h"
+
+static CURLcode unit_setup(void)
+{
+ return CURLE_OK;
+}
+
+static void unit_stop(void)
+{
+
+}
+
+UNITTEST_START
#ifndef CURL_DISABLE_CRYPTO_AUTH
+ const char string1[] = "1";
+ const char string2[] = "hello-you-fool";
+ unsigned char output[SHA256_DIGEST_LENGTH];
+ unsigned char *testp = output;
+
+ Curl_sha256it(output, (const unsigned char *) string1);
-void Curl_sha256it(unsigned char *outbuffer,
- const unsigned char *input);
+ verify_memory(testp,
+ "\x6b\x86\xb2\x73\xff\x34\xfc\xe1\x9d\x6b\x80\x4e\xff\x5a\x3f"
+ "\x57\x47\xad\xa4\xea\xa2\x2f\x1d\x49\xc0\x1e\x52\xdd\xb7\x87"
+ "\x5b\x4b", SHA256_DIGEST_LENGTH);
+ Curl_sha256it(output, (const unsigned char *) string2);
+
+ verify_memory(testp,
+ "\xcb\xb1\x6a\x8a\xb9\xcb\xb9\x35\xa8\xcb\xa0\x2e\x28\xc0\x26"
+ "\x30\xd1\x19\x9c\x1f\x02\x17\xf4\x7c\x96\x20\xf3\xef\xe8\x27"
+ "\x15\xae", SHA256_DIGEST_LENGTH);
#endif
-#endif /* HEADER_CURL_SHA256_H */
+
+UNITTEST_STOP
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [gnurl] 142/282: md4: Fixed compilation issues when using GNU TLS gcrypt, (continued)
- [gnurl] 142/282: md4: Fixed compilation issues when using GNU TLS gcrypt, gnunet, 2020/04/01
- [gnurl] 131/282: tool_util: Improve Windows version of tvnow(), gnunet, 2020/04/01
- [gnurl] 128/282: docs/GOVERNANCE: refreshed + added "donations" and "commercial support", gnunet, 2020/04/01
- [gnurl] 138/282: GnuTLS: Always send client cert, gnunet, 2020/04/01
- [gnurl] 134/282: connect: remove some spurious infof() calls, gnunet, 2020/04/01
- [gnurl] 136/282: cleanup: comment typos, gnunet, 2020/04/01
- [gnurl] 139/282: gtls: fix the copyright year, gnunet, 2020/04/01
- [gnurl] 132/282: nit: Copyright year out of date, gnunet, 2020/04/01
- [gnurl] 137/282: github action: add CIFuzz, gnunet, 2020/04/01
- [gnurl] 141/282: RELEASE-NOTES: synced, gnunet, 2020/04/01
- [gnurl] 143/282: tests: Added a unit test for SHA256 digest generation,
gnunet <=
- [gnurl] 144/282: digest: Corrected the name of the local HTTP digest function, gnunet, 2020/04/01
- [gnurl] 146/282: ntlm: Removed the dependency on the TLS libaries when using MD5, gnunet, 2020/04/01
- [gnurl] 147/282: test1610: Fixed the link to the unit test, gnunet, 2020/04/01
- [gnurl] 150/282: ntlm: Moved the HMAC MD5 function into the HMAC module as a generic function, gnunet, 2020/04/01
- [gnurl] 140/282: http2: now require nghttp2 >= 1.12.0, gnunet, 2020/04/01
- [gnurl] 123/282: socks: make the connect phase non-blocking, gnunet, 2020/04/01
- [gnurl] 145/282: md5/sha256: Updated the functions to allow non-string data to be hashed, gnunet, 2020/04/01
- [gnurl] 153/282: ftpserver: Updated VRFY_smtp() so the response isn't necessary in the test case, gnunet, 2020/04/01
- [gnurl] 148/282: md4: Use const for the length input parameter, gnunet, 2020/04/01
- [gnurl] 152/282: ftpserver: Corrected the e-mail address regex in MAIL_smtp() and RCTP_smtp(), gnunet, 2020/04/01