gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [libmicrohttpd] branch master updated (8c44c704 -> c7d3fb71


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] branch master updated (8c44c704 -> c7d3fb71)
Date: Fri, 19 Apr 2019 08:18:22 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 8c44c704 .dir-locals.el: fixed language for dictionary
     new 0b8c463d mhd_bithelpers.h: fixed macro for BE mode, added macros to 
GET/PUT data in BE mode, added macro for bits rotation
     new c7d3fb71 Tests: added test_sha256 for SHA-256 testing

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/microhttpd/Makefile.am                   |   5 +
 src/microhttpd/mhd_bithelpers.h              | 107 ++++++++++++++++++----
 src/microhttpd/{test_md5.c => test_sha256.c} | 132 ++++++++++++++++-----------
 3 files changed, 171 insertions(+), 73 deletions(-)
 copy src/microhttpd/{test_md5.c => test_sha256.c} (64%)

diff --git a/src/microhttpd/Makefile.am b/src/microhttpd/Makefile.am
index 16db5009..2b0f3455 100644
--- a/src/microhttpd/Makefile.am
+++ b/src/microhttpd/Makefile.am
@@ -157,6 +157,7 @@ check_PROGRAMS = \
   test_str_token \
   test_http_reasons \
   test_md5 \
+  test_sha256 \
   test_start_stop \
   test_daemon \
   test_options
@@ -322,6 +323,10 @@ test_md5_SOURCES = \
   test_md5.c test_helpers.h \
   md5.c md5.h mhd_bithelpers.h
 
+test_sha256_SOURCES = \
+  test_sha256.c test_helpers.h \
+  sha256.c sha256.h mhd_bithelpers.h
+
 test_options_SOURCES = \
   test_options.c
 test_options_LDADD = \
diff --git a/src/microhttpd/mhd_bithelpers.h b/src/microhttpd/mhd_bithelpers.h
index d4a47ce4..bf20293f 100644
--- a/src/microhttpd/mhd_bithelpers.h
+++ b/src/microhttpd/mhd_bithelpers.h
@@ -29,32 +29,99 @@
 #include "mhd_byteorder.h"
 #include <stdint.h>
 
-
+/* _MHD_PUT_64BIT_LE (addr, value64)
+ * put native-endian 64-bit value64 to addr
+ * in little-endian mode.
+ */
 #if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN
-#define _MHD_PUT_64BIT_LE(addr, value64) \
-  ((*(uint64_t*)(addr)) = (uint64_t)(value64))
+#define _MHD_PUT_64BIT_LE(addr, value64)             \
+        ((*(uint64_t*)(addr)) = (uint64_t)(value64))
 #else  /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
-#define _MHD_PUT_64BIT_LE(addr, value64) do {                           \
-        (uint8_t*(addr))[7] = (uint8_t)((value64) >> 56);               \
-        (uint8_t*(addr))[6] = (uint8_t)((value64) >> 48);               \
-        (uint8_t*(addr))[5] = (uint8_t)((value64) >> 40);               \
-        (uint8_t*(addr))[4] = (uint8_t)((value64) >> 32);               \
-        (uint8_t*(addr))[3] = (uint8_t)((value64) >> 24);               \
-        (uint8_t*(addr))[2] = (uint8_t)((value64) >> 16);               \
-        (uint8_t*(addr))[1] = (uint8_t)((value64) >> 8);                \
-        (uint8_t*(addr))[0] = (uint8_t)((value64)); } while (0)
+#define _MHD_PUT_64BIT_LE(addr, value64) do {                            \
+        ((uint8_t*)(addr))[0] = (uint8_t)((uint64_t)(value64));           \
+        ((uint8_t*)(addr))[1] = (uint8_t)(((uint64_t)(value64)) >> 8);    \
+        ((uint8_t*)(addr))[2] = (uint8_t)(((uint64_t)(value64)) >> 16);   \
+        ((uint8_t*)(addr))[3] = (uint8_t)(((uint64_t)(value64)) >> 24);   \
+        ((uint8_t*)(addr))[4] = (uint8_t)(((uint64_t)(value64)) >> 32);   \
+        ((uint8_t*)(addr))[5] = (uint8_t)(((uint64_t)(value64)) >> 40);   \
+        ((uint8_t*)(addr))[6] = (uint8_t)(((uint64_t)(value64)) >> 48);   \
+        ((uint8_t*)(addr))[7] = (uint8_t)(((uint64_t)(value64)) >> 56);   \
+        } while (0)
 #endif /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
 
+/* _MHD_PUT_32BIT_LE (addr, value32)
+ * put native-endian 32-bit value32 to addr
+ * in little-endian mode.
+ */
 #if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN
-#define _MHD_PUT_32BIT_LE(addr, value32) \
-  ((*(uint32_t*)(addr)) = (uint32_t)(value32))
+#define _MHD_PUT_32BIT_LE(addr, value32)             \
+        ((*(uint32_t*)(addr)) = (uint32_t)(value32))
 #else  /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
-
-#define _MHD_PUT_32BIT_LE(addr, value32) do {                           \
-        (uint8_t*(addr))[3] = (uint8_t)((value32) >> 24);               \
-        (uint8_t*(addr))[2] = (uint8_t)((value32) >> 16);               \
-        (uint8_t*(addr))[1] = (uint8_t)((value32) >> 8);                \
-        (uint8_t*(addr))[0] = (uint8_t)((value32)); } while (0)
+#define _MHD_PUT_32BIT_LE(addr, value32) do {                            \
+        ((uint8_t*)(addr))[0] = (uint8_t)((uint32_t)(value32));           \
+        ((uint8_t*)(addr))[1] = (uint8_t)(((uint32_t)(value32)) >> 8);    \
+        ((uint8_t*)(addr))[2] = (uint8_t)(((uint32_t)(value32)) >> 16);   \
+        ((uint8_t*)(addr))[3] = (uint8_t)(((uint32_t)(value32)) >> 24);   \
+        } while (0)
 #endif /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
 
+
+/* _MHD_PUT_64BIT_BE (addr, value64)
+ * put native-endian 64-bit value64 to addr
+ * in big-endian mode.
+ */
+#if _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN
+#define _MHD_PUT_64BIT_BE(addr, value64)             \
+        ((*(uint64_t*)(addr)) = (uint64_t)(value64))
+#else  /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
+#define _MHD_PUT_64BIT_BE(addr, value64) do {                            \
+        ((uint8_t*)(addr))[7] = (uint8_t)((uint64_t)(value64));           \
+        ((uint8_t*)(addr))[6] = (uint8_t)(((uint64_t)(value64)) >> 8);    \
+        ((uint8_t*)(addr))[5] = (uint8_t)(((uint64_t)(value64)) >> 16);   \
+        ((uint8_t*)(addr))[4] = (uint8_t)(((uint64_t)(value64)) >> 24);   \
+        ((uint8_t*)(addr))[3] = (uint8_t)(((uint64_t)(value64)) >> 32);   \
+        ((uint8_t*)(addr))[2] = (uint8_t)(((uint64_t)(value64)) >> 40);   \
+        ((uint8_t*)(addr))[1] = (uint8_t)(((uint64_t)(value64)) >> 48);   \
+        ((uint8_t*)(addr))[0] = (uint8_t)(((uint64_t)(value64)) >> 56);   \
+        } while (0)
+#endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
+
+/* _MHD_PUT_32BIT_BE (addr, value32)
+ * put native-endian 32-bit value32 to addr
+ * in big-endian mode.
+ */
+#if _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN
+#define _MHD_PUT_32BIT_BE(addr, value32)             \
+        ((*(uint32_t*)(addr)) = (uint32_t)(value32))
+#else  /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
+#define _MHD_PUT_32BIT_BE(addr, value32) do {                            \
+        ((uint8_t*)(addr))[3] = (uint8_t)((uint32_t)(value32));           \
+        ((uint8_t*)(addr))[2] = (uint8_t)(((uint32_t)(value32)) >> 8);    \
+        ((uint8_t*)(addr))[1] = (uint8_t)(((uint32_t)(value32)) >> 16);   \
+        ((uint8_t*)(addr))[0] = (uint8_t)(((uint32_t)(value32)) >> 24);   \
+        } while (0)
+#endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
+
+/* _MHD_GET_32BIT_BE (addr)
+ * get big-endian 32-bit value storied at addr
+ * and return it in native-endian mode.
+ */
+#if _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN
+#define _MHD_GET_32BIT_BE(addr)             \
+        (*(uint32_t*)(addr))
+#else  /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
+#define _MHD_GET_32BIT_BE(addr)                       \
+        ( (((uint32_t)(((uint8_t*)addr)[0])) << 24) | \
+          (((uint32_t)(((uint8_t*)addr)[1])) << 16) | \
+          (((uint32_t)(((uint8_t*)addr)[2])) << 8)  | \
+          ((uint32_t) (((uint8_t*)addr)[3])) )
+#endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
+
+/**
+ * Rotate right 32-bit value by number of bits.
+ * bits parameter must be more than zero and must be less than 32.
+ * Defined in form which modern compiler could optimize.
+ */
+#define _MHD_ROTR32(value32, bits) ((value32) >> (bits) | (value32) << (32 - 
bits))
+
 #endif /* ! MHD_BITHELPERS_H */
diff --git a/src/microhttpd/test_md5.c b/src/microhttpd/test_sha256.c
similarity index 64%
copy from src/microhttpd/test_md5.c
copy to src/microhttpd/test_sha256.c
index 38c1e8b9..50e119f8 100644
--- a/src/microhttpd/test_md5.c
+++ b/src/microhttpd/test_sha256.c
@@ -18,14 +18,15 @@
 */
 
 /**
- * @file microhttpd/test_md5.h
- * @brief  Unit tests for md5 functions
+ * @file microhttpd/test_sha256.h
+ * @brief  Unit tests for SHA-256 functions
  * @author Karlson2k (Evgeny Grin)
  */
 
 #include "mhd_options.h"
-#include "md5.h"
+#include "sha256.h"
 #include "test_helpers.h"
+#include <stdio.h>
 
 static int verbose = 0; /* verbose level (0-1)*/
 
@@ -41,21 +42,35 @@ struct str_with_len
 struct data_unit1
 {
   const struct str_with_len str_l;
-  const uint8_t digest[MD5_DIGEST_SIZE];
+  const uint8_t digest[SHA256_DIGEST_SIZE];
 };
 
 static const struct data_unit1 data_units1[] = {
+    {D_STR_W_LEN("abc"),
+        {0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 
0xde, 0x5d, 0xae, 0x22, 0x23,
+         0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10, 0xff, 
0x61, 0xf2, 0x00, 0x15, 0xad}},
+    {D_STR_W_LEN("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"),
+        {0x24, 0x8d, 0x6a, 0x61, 0xd2, 0x06, 0x38, 0xb8, 0xe5, 0xc0, 0x26, 
0x93, 0x0c, 0x3e, 0x60, 0x39,
+         0xa3, 0x3c, 0xe4, 0x59, 0x64, 0xff, 0x21, 0x67, 0xf6, 0xec, 0xed, 
0xd4, 0x19, 0xdb, 0x06, 0xc1}},
+    {D_STR_W_LEN(""),
+        {0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 
0xc8, 0x99, 0x6f, 0xb9, 0x24,
+         0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 
0x1b, 0x78, 0x52, 0xb8, 0x55}},
     {D_STR_W_LEN("address@hidden&address@hidden/!?`."),
-        {0x1c, 0x68, 0xc2, 0xe5, 0x1f, 0x63, 0xc9, 0x5f, 0x17, 0xab, 0x1f, 
0x20, 0x8b, 0x86, 0x39, 0x57}},
+        {0x2f, 0xad, 0x7a, 0xff, 0x7d, 0xfe, 0xcd, 0x78, 0xe4, 0xa6, 0xf3, 
0x85, 0x97, 0x9d, 0xdc, 0x39,
+         0x55, 0x24, 0x35, 0x4a, 0x00, 0x6f, 0x42, 0x72, 0x41, 0xc1, 0x52, 
0xa7, 0x01, 0x0b, 0x2c, 0x41}},
     {D_STR_W_LEN("Simple string."),
-        {0xf1, 0x2b, 0x7c, 0xad, 0xa0, 0x41, 0xfe, 0xde, 0x4e, 0x68, 0x16, 
0x63, 0xb4, 0x60, 0x5d, 0x78}},
+        {0x01, 0x73, 0x17, 0xc4, 0x0a, 0x9a, 0x0e, 0x81, 0xb3, 0xa4, 0xb1, 
0x8e, 0xe9, 0xd6, 0xc2, 0xdf,
+         0xfa, 0x7d, 0x53, 0x4e, 0xa1, 0xda, 0xb2, 0x5a, 0x75, 0xbb, 0x2c, 
0x30, 0x2f, 0x5f, 0x7a, 0xf4}},
     {D_STR_W_LEN("abcdefghijklmnopqrstuvwxyz"),
-        {0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, 0x7d, 0xfb, 0x49, 
0x6c, 0xca, 0x67, 0xe1, 0x3b}},
+        {0x71, 0xc4, 0x80, 0xdf, 0x93, 0xd6, 0xae, 0x2f, 0x1e, 0xfa, 0xd1, 
0x44, 0x7c, 0x66, 0xc9, 0x52,
+         0x5e, 0x31, 0x62, 0x18, 0xcf, 0x51, 0xfc, 0x8d, 0x9e, 0xd8, 0x32, 
0xf2, 0xda, 0xf1, 0x8b, 0x73}},
     {D_STR_W_LEN("zyxwvutsrqponMLKJIHGFEDCBA"),
-        {0x05, 0x61, 0x3a, 0x6b, 0xde, 0x75, 0x3a, 0x45, 0x91, 0xa8, 0x81, 
0xb0, 0xa7, 0xe2, 0xe2, 0x0e}},
+        {0xce, 0x7d, 0xde, 0xb6, 0x1f, 0x7c, 0x1d, 0x83, 0x7c, 0x60, 0xd8, 
0x36, 0x73, 0x82, 0xac, 0x92,
+         0xca, 0x37, 0xfd, 0x72, 0x8b, 0x0c, 0xd1, 0x6c, 0x55, 0xd5, 0x88, 
0x98, 0x24, 0xfa, 0x16, 0xf2}},
     {D_STR_W_LEN("abcdefghijklmnopqrstuvwxyzzyxwvutsrqponMLKJIHGFEDCBA"
                  "abcdefghijklmnopqrstuvwxyzzyxwvutsrqponMLKJIHGFEDCBA"),
-        {0xaf, 0xab, 0xc7, 0xe9, 0xe7, 0x17, 0xbe, 0xd6, 0xc0, 0x0f, 0x78, 
0x8c, 0xde, 0xdd, 0x11, 0xd1}},
+        {0x27, 0xd1, 0xe8, 0xbc, 0x6a, 0x79, 0x16, 0x83, 0x61, 0x73, 0xa9, 
0xa8, 0x9b, 0xaf, 0xaf, 0xcf,
+         0x47, 0x4d, 0x09, 0xef, 0x6d, 0x50, 0x35, 0x12, 0x25, 0x72, 0xd8, 
0x68, 0xdc, 0x1f, 0xd2, 0xf4}},
 };
 
 static const size_t units1_num = sizeof(data_units1) / sizeof(data_units1[0]);
@@ -69,40 +84,47 @@ struct bin_with_len
 struct data_unit2
 {
   const struct bin_with_len bin_l;
-  const uint8_t digest[MD5_DIGEST_SIZE];
+  const uint8_t digest[SHA256_DIGEST_SIZE];
 };
 
+/* Size must be less than 512 bytes! */
 static const struct data_unit2 data_units2[] = {
     { { {97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 
111, 112, 113, 114, 115, 116,
         117, 118, 119, 120, 121, 122}, 26},/* a..z ASCII sequence */
-      {0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, 0x7d, 0xfb, 0x49, 0x6c, 
0xca, 0x67, 0xe1, 0x3b}
+      {0x71, 0xc4, 0x80, 0xdf, 0x93, 0xd6, 0xae, 0x2f, 0x1e, 0xfa, 0xd1, 0x44, 
0x7c, 0x66, 0xc9, 0x52,
+       0x5e, 0x31, 0x62, 0x18, 0xcf, 0x51, 0xfc, 0x8d, 0x9e, 0xd8, 0x32, 0xf2, 
0xda, 0xf1, 0x8b, 0x73}
     },
     { { {65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 
65, 65, 65, 65, 65, 65, 65,
         65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 
65, 65, 65, 65, 65, 65, 65,
         65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 
65, 65, 65, 65, 65, 65, 65
         }, 72 },/* 'A' x 72 times */
-      {0x24, 0xa5, 0xef, 0x36, 0x82, 0x80, 0x3a, 0x06, 0x2f, 0xea, 0xad, 0xad, 
0x76, 0xda, 0xbd, 0xa8}
+      {0x6a, 0x6d, 0x69, 0x1a, 0xc9, 0xba, 0x70, 0x95, 0x50, 0x46, 0x75, 0x7c, 
0xd6, 0x85, 0xb6, 0x25,
+       0x77, 0x73, 0xff, 0x3a, 0xd9, 0x3f, 0x43, 0xd4, 0xd4, 0x81, 0x2c, 0x5b, 
0x10, 0x6f, 0x4b, 0x5b}
     },
     { { {19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 
36, 37, 38, 39, 40, 41, 42,
         43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 
60, 61, 62, 63, 64, 65, 66, 67,
         68, 69, 70, 71, 72, 73}, 55},/* 19..73 sequence */
-      {0x6d, 0x2e, 0x6e, 0xde, 0x5d, 0x64, 0x6a, 0x17, 0xf1, 0x09, 0x2c, 0xac, 
0x19, 0x10, 0xe3, 0xd6}
+      {0x06, 0xe4, 0xb3, 0x9e, 0xf1, 0xfb, 0x6c, 0xcf, 0xd7, 0x3f, 0x50, 0x9e, 
0xf4, 0x16, 0x17, 0xd4,
+       0x63, 0x7c, 0x39, 0x1e, 0xa8, 0x0f, 0xa9, 0x88, 0x03, 0x44, 0x98, 0x0e, 
0x95, 0x81, 0xf0, 0x2a}
     },
     { { {7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 
25, 26, 27, 28, 29, 30, 31,
         32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 
49, 50, 51, 52, 53, 54, 55, 56,
         57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69}, 63},/* 7..69 
sequence */
-      {0x88, 0x13, 0x48, 0x47, 0x73, 0xaa, 0x92, 0xf2, 0xc9, 0xdd, 0x69, 0xb3, 
0xac, 0xf4, 0xba, 0x6e}
+      {0x4a, 0xd3, 0xc6, 0x87, 0x1f, 0xd1, 0xc5, 0xe2, 0x3e, 0x52, 0xdc, 0x22, 
0xd1, 0x10, 0xd2, 0x05,
+       0x15, 0x23, 0xcd, 0x15, 0xac, 0x24, 0x88, 0x26, 0x02, 0x00, 0x70, 0x78, 
0x9f, 0x17, 0xf8, 0xd9}
     },
     { { {38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 
55, 56, 57, 58, 59, 60, 61,
         62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 
79, 80, 81, 82, 83, 84, 85, 86,
         87, 88, 89, 90, 91, 92}, 55},/* 38..92 sequence */
-      {0x80, 0xf0, 0x05, 0x7e, 0xa2, 0xf7, 0xc8, 0x43, 0x12, 0xd3, 0xb1, 0x61, 
0xab, 0x52, 0x3b, 0xaf}
+      {0xe6, 0x03, 0x0f, 0xc9, 0x0d, 0xca, 0x0c, 0x26, 0x41, 0xcf, 0x43, 0x27, 
0xec, 0xd6, 0x28, 0x2a,
+       0x98, 0x24, 0x55, 0xd3, 0x5a, 0xed, 0x8b, 0x32, 0x19, 0x78, 0xeb, 0x83, 
0x1d, 0x19, 0x92, 0x79}
     },
     { { {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 
20, 21, 22, 23, 24, 25, 26, 27,
         28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 
45, 46, 47, 48, 49, 50, 51, 52,
         53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 
70, 71, 72},
       72},/* 1..72 sequence */
-      {0xc3, 0x28, 0xc5, 0xad, 0xc9, 0x26, 0xa9, 0x99, 0x95, 0x4a, 0x5e, 0x25, 
0x50, 0x34, 0x51, 0x73}
+      {0x87, 0xa2, 0xfa, 0x2e, 0xec, 0x53, 0x05, 0x3c, 0xb1, 0xee, 0x07, 0xd7, 
0x59, 0x70, 0xf6, 0x50,
+       0xcd, 0x9d, 0xc5, 0x8b, 0xdc, 0xb8, 0x65, 0x30, 0x4f, 0x70, 0x82, 0x9e, 
0xbd, 0xe2, 0x7d, 0xac}
     },
     { { {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 
20, 21, 22, 23, 24, 25, 26,
         27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 
44, 45, 46, 47, 48, 49, 50, 51,
@@ -116,13 +138,15 @@ static const struct data_unit2 data_units2[] = {
         201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 
215, 216, 217, 218, 219, 220,
         221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 
235, 236, 237, 238, 239, 240,
         241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 
255}, 256}, /* 0..255 sequence */
-      {0xe2, 0xc8, 0x65, 0xdb, 0x41, 0x62, 0xbe, 0xd9, 0x63, 0xbf, 0xaa, 0x9e, 
0xf6, 0xac, 0x18, 0xf0}
+      {0x40, 0xaf, 0xf2, 0xe9, 0xd2, 0xd8, 0x92, 0x2e, 0x47, 0xaf, 0xd4, 0x64, 
0x8e, 0x69, 0x67, 0x49,
+       0x71, 0x58, 0x78, 0x5f, 0xbd, 0x1d, 0xa8, 0x70, 0xe7, 0x11, 0x02, 0x66, 
0xbf, 0x94, 0x48, 0x80}
     },
     { { {199, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 188, 187, 186, 
185, 184, 183, 182, 181, 180,
         179, 178, 177, 176, 175, 174, 173, 172, 171, 170, 169, 168, 167, 166, 
165, 164, 163, 162, 161, 160,
         159, 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 
145, 144, 143, 142, 141, 140,
         139}, 61}, /* 199..139 sequence */
-      {0xbb, 0x3f, 0xdb, 0x4a, 0x96, 0x03, 0x36, 0x37, 0x38, 0x78, 0x5e, 0x44, 
0xbf, 0x3a, 0x85, 0x51}
+      {0x85, 0xf8, 0xa2, 0x83, 0xd6, 0x3c, 0x76, 0x8e, 0xea, 0x8f, 0x1c, 0x57, 
0x2d, 0x85, 0xb6, 0xff,
+       0xd8, 0x33, 0x57, 0x62, 0x1d, 0x37, 0xae, 0x0e, 0xfc, 0x22, 0xd3, 0xd5, 
0x8f, 0x53, 0x21, 0xb7}
     },
     { { {255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 
241, 240, 239, 238, 237, 236,
         235, 234, 233, 232, 231, 230, 229, 228, 227, 226, 225, 224, 223, 222, 
221, 220, 219, 218, 217, 216,
@@ -136,7 +160,8 @@ static const struct data_unit2 data_units2[] = {
         69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 
52, 51, 50, 49, 48, 47, 46, 45,
         44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 
27, 26, 25, 24, 23, 22, 21, 20,
         19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, 
255}, /* 255..1 sequence */
-      {0x52, 0x21, 0xa5, 0x83, 0x4f, 0x38, 0x7c, 0x73, 0xba, 0x18, 0x22, 0xb1, 
0xf9, 0x7e, 0xae, 0x8b}
+      {0x61, 0x86, 0x96, 0xab, 0x3e, 0xaa, 0x0e, 0x64, 0xb2, 0xf7, 0x2d, 0x75, 
0x47, 0x5a, 0x14, 0x97,
+       0xa3, 0x3d, 0x59, 0xa4, 0x08, 0xd9, 0x9e, 0x73, 0xf2, 0x78, 0x00, 0x5b, 
0x4b, 0x55, 0xca, 0x43}
     },
     { { {41, 35, 190, 132, 225, 108, 214, 174, 82, 144, 73, 241, 241, 187, 
233, 235, 179, 166, 219, 60, 135,
         12, 62, 153, 36, 94, 13, 28, 6, 183, 71, 222, 179, 18, 77, 200, 67, 
187, 139, 166, 31, 3, 90, 125, 9,
@@ -150,7 +175,8 @@ static const struct data_unit2 data_units2[] = {
         217, 29, 42, 229, 192, 247, 43, 120, 129, 135, 68, 14, 95, 80, 0, 212, 
97, 141, 190, 123, 5, 21, 7,
         59, 51, 130, 31, 24, 112, 146, 218, 100, 84, 206, 177, 133, 62, 105, 
21, 248, 70, 106, 4, 150, 115,
         14, 217, 22, 47, 103, 104, 212, 247, 74, 74, 208, 87, 104}, 255}, /* 
pseudo-random data */
-      {0x55, 0x61, 0x2c, 0xeb, 0x29, 0xee, 0xa8, 0xb2, 0xf6, 0x10, 0x7b, 0xc1, 
0x5b, 0x0f, 0x01, 0x95}
+      {0x08, 0x7f, 0x86, 0xac, 0xe2, 0x2e, 0x28, 0x56, 0x74, 0x53, 0x4f, 0xc0, 
0xfb, 0xb8, 0x79, 0x57,
+       0xc5, 0xc8, 0xd1, 0xb7, 0x47, 0xb7, 0xd9, 0xea, 0x97, 0xa8, 0x67, 0xe9, 
0x26, 0x93, 0xee, 0xa3}
     }
 };
 
@@ -187,25 +213,25 @@ bin2hex (const uint8_t *bin,
 static int
 check_result (const char *test_name,
               unsigned int check_num,
-              const uint8_t calcualted[MD5_DIGEST_SIZE],
-              const uint8_t expected[MD5_DIGEST_SIZE])
+              const uint8_t calcualted[SHA256_DIGEST_SIZE],
+              const uint8_t expected[SHA256_DIGEST_SIZE])
 {
-  int failed = memcmp(calcualted, expected, MD5_DIGEST_SIZE);
+  int failed = memcmp(calcualted, expected, SHA256_DIGEST_SIZE);
   check_num++; /* Print 1-based numbers */
   if (failed)
     {
-      char calc_str[MD5_DIGEST_STRING_LENGTH];
-      char expc_str[MD5_DIGEST_STRING_LENGTH];
-      bin2hex(calcualted, MD5_DIGEST_SIZE, calc_str);
-      bin2hex(expected, MD5_DIGEST_SIZE, expc_str);
+      char calc_str[SHA256_DIGEST_STRING_SIZE];
+      char expc_str[SHA256_DIGEST_STRING_SIZE];
+      bin2hex(calcualted, SHA256_DIGEST_SIZE, calc_str);
+      bin2hex(expected, SHA256_DIGEST_SIZE, expc_str);
       fprintf (stderr, "FAILED: %s check %u: calculated digest %s, expected 
digest %s.\n",
                test_name, check_num, calc_str, expc_str);
       fflush (stderr);
     }
   else if (verbose)
     {
-      char calc_str[MD5_DIGEST_STRING_LENGTH];
-      bin2hex(calcualted, MD5_DIGEST_SIZE, calc_str);
+      char calc_str[SHA256_DIGEST_STRING_SIZE];
+      bin2hex(calcualted, SHA256_DIGEST_SIZE, calc_str);
       printf ("PASSED: %s check %u: calculated digest %s match expected 
digest.\n",
                test_name, check_num, calc_str);
       fflush (stdout);
@@ -218,18 +244,18 @@ check_result (const char *test_name,
  *  Tests
  */
 
-/* Calculated MD5 as one pass for whole data */
+/* Calculated SHA-256 as one pass for whole data */
 int test1_str(void)
 {
   int num_failed = 0;
   for (unsigned int i = 0; i < units1_num; i++)
     {
-      struct MD5Context ctx;
-      uint8_t digest[MD5_DIGEST_SIZE];
+      struct sha256_ctx ctx;
+      uint8_t digest[SHA256_DIGEST_SIZE];
 
-      MD5Init (&ctx);
-      MD5Update (&ctx, (const uint8_t*)data_units1[i].str_l.str, 
data_units1[i].str_l.len);
-      MD5Final (&ctx, digest);
+      sha256_init (&ctx);
+      sha256_update (&ctx, (const uint8_t*)data_units1[i].str_l.str, 
data_units1[i].str_l.len);
+      sha256_digest (&ctx, digest);
       num_failed += check_result (__FUNCTION__, i, digest,
                                   data_units1[i].digest);
     }
@@ -241,32 +267,32 @@ int test1_bin(void)
   int num_failed = 0;
   for (unsigned int i = 0; i < units2_num; i++)
     {
-      struct MD5Context ctx;
-      uint8_t digest[MD5_DIGEST_SIZE];
+      struct sha256_ctx ctx;
+      uint8_t digest[SHA256_DIGEST_SIZE];
 
-      MD5Init (&ctx);
-      MD5Update (&ctx, data_units2[i].bin_l.bin, data_units2[i].bin_l.len);
-      MD5Final (&ctx, digest);
+      sha256_init (&ctx);
+      sha256_update (&ctx, data_units2[i].bin_l.bin, data_units2[i].bin_l.len);
+      sha256_digest (&ctx, digest);
       num_failed += check_result (__FUNCTION__, i, digest,
                                   data_units2[i].digest);
     }
   return num_failed;
 }
 
-/* Calculated MD5 as two iterations for whole data */
+/* Calculated SHA-256 as two iterations for whole data */
 int test2_str(void)
 {
   int num_failed = 0;
   for (unsigned int i = 0; i < units1_num; i++)
     {
-      struct MD5Context ctx;
-      uint8_t digest[MD5_DIGEST_SIZE];
+      struct sha256_ctx ctx;
+      uint8_t digest[SHA256_DIGEST_SIZE];
       size_t part_s = data_units1[i].str_l.len / 4;
 
-      MD5Init (&ctx);
-      MD5Update (&ctx, (const uint8_t*)data_units1[i].str_l.str, part_s);
-      MD5Update (&ctx, (const uint8_t*)data_units1[i].str_l.str + part_s, 
data_units1[i].str_l.len - part_s);
-      MD5Final (&ctx, digest);
+      sha256_init (&ctx);
+      sha256_update (&ctx, (const uint8_t*)data_units1[i].str_l.str, part_s);
+      sha256_update (&ctx, (const uint8_t*)data_units1[i].str_l.str + part_s, 
data_units1[i].str_l.len - part_s);
+      sha256_digest (&ctx, digest);
       num_failed += check_result (__FUNCTION__, i, digest,
                                   data_units1[i].digest);
     }
@@ -278,14 +304,14 @@ int test2_bin(void)
   int num_failed = 0;
   for (unsigned int i = 0; i < units2_num; i++)
     {
-      struct MD5Context ctx;
-      uint8_t digest[MD5_DIGEST_SIZE];
+      struct sha256_ctx ctx;
+      uint8_t digest[SHA256_DIGEST_SIZE];
       size_t part_s = data_units2[i].bin_l.len * 2 / 3;
 
-      MD5Init (&ctx);
-      MD5Update (&ctx, data_units2[i].bin_l.bin, part_s);
-      MD5Update (&ctx, data_units2[i].bin_l.bin + part_s, 
data_units2[i].bin_l.len - part_s);
-      MD5Final (&ctx, digest);
+      sha256_init (&ctx);
+      sha256_update (&ctx, data_units2[i].bin_l.bin, part_s);
+      sha256_update (&ctx, data_units2[i].bin_l.bin + part_s, 
data_units2[i].bin_l.len - part_s);
+      sha256_digest (&ctx, digest);
       num_failed += check_result (__FUNCTION__, i, digest,
                                   data_units2[i].digest);
     }

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]