libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

test_sha512_256.c (30283B)


      1 /*
      2   This file is part of libmicrohttpd
      3   Copyright (C) 2019-2022 Evgeny Grin (Karlson2k)
      4 
      5   This test tool is free software; you can redistribute it and/or
      6   modify it under the terms of the GNU General Public License as
      7   published by the Free Software Foundation; either version 2, or
      8   (at your option) any later version.
      9 
     10   This test tool is distributed in the hope that it will be useful,
     11   but WITHOUT ANY WARRANTY; without even the implied warranty of
     12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13   Lesser General Public License for more details.
     14 
     15   You should have received a copy of the GNU Lesser General Public
     16   License along with this library; if not, write to the Free Software
     17   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
     18 */
     19 
     20 /**
     21  * @file microhttpd/test_sha512_256.h
     22  * @brief  Unit tests for SHA-512/256 functions
     23  * @author Karlson2k (Evgeny Grin)
     24  */
     25 
     26 #include "mhd_options.h"
     27 #include "sha512_256.h"
     28 #include "test_helpers.h"
     29 #include <stdio.h>
     30 #include <stdlib.h>
     31 
     32 /* Turn any MHD_PANIC() or failing mhd_assert() reached from this
     33    test into a marked, classifiable test error (TESTING.md, P5). */
     34 #include "mhd_panic_tripwire.h"
     35 
     36 static int verbose = 0; /* verbose level (0-1)*/
     37 
     38 
     39 struct str_with_len
     40 {
     41   const char *const str;
     42   const size_t len;
     43 };
     44 
     45 #define D_STR_W_LEN(s) {(s), (sizeof((s)) / sizeof(char)) - 1}
     46 
     47 struct data_unit1
     48 {
     49   const struct str_with_len str_l;
     50   const uint8_t digest[SHA512_256_DIGEST_SIZE];
     51 };
     52 
     53 static const struct data_unit1 data_units1[] = {
     54   {D_STR_W_LEN ("abc"),
     55    {0x53, 0x04, 0x8E, 0x26, 0x81, 0x94, 0x1E, 0xF9, 0x9B, 0x2E, 0x29, 0xB7,
     56     0x6B, 0x4C, 0x7D, 0xAB, 0xE4, 0xC2, 0xD0, 0xC6, 0x34, 0xFC, 0x6D, 0x46,
     57     0xE0, 0xE2, 0xF1, 0x31, 0x07, 0xE7, 0xAF, 0x23}},
     58   {D_STR_W_LEN ("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi" \
     59                 "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"),
     60    {0x39, 0x28, 0xE1, 0x84, 0xFB, 0x86, 0x90, 0xF8, 0x40, 0xDA, 0x39, 0x88,
     61     0x12, 0x1D, 0x31, 0xBE, 0x65, 0xCB, 0x9D, 0x3E, 0xF8, 0x3E, 0xE6, 0x14,
     62     0x6F, 0xEA, 0xC8, 0x61, 0xE1, 0x9B, 0x56, 0x3A}},
     63   {D_STR_W_LEN (""), /* The empty zero-size input */
     64    {0xc6, 0x72, 0xb8, 0xd1, 0xef, 0x56, 0xed, 0x28, 0xab, 0x87, 0xc3, 0x62,
     65     0x2c, 0x51, 0x14, 0x06, 0x9b, 0xdd, 0x3a, 0xd7, 0xb8, 0xf9, 0x73, 0x74,
     66     0x98, 0xd0, 0xc0, 0x1e, 0xce, 0xf0, 0x96, 0x7a}},
     67   {D_STR_W_LEN ("1234567890!@~%&$@#{}[]\\/!?`."),
     68    {0xc8, 0x7c, 0x5a, 0x55, 0x27, 0x77, 0x1b, 0xe7, 0x69, 0x3c, 0x50, 0x79,
     69     0x32, 0xad, 0x7c, 0x79, 0xe9, 0x60, 0xa0, 0x18, 0xb7, 0x78, 0x2b, 0x6f,
     70     0xa9, 0x7b, 0xa3, 0xa0, 0xb5, 0x18, 0x17, 0xa5}},
     71   {D_STR_W_LEN ("Simple string."),
     72    {0xde, 0xcb, 0x3c, 0x81, 0x65, 0x4b, 0xa0, 0xf5, 0xf0, 0x45, 0x6b, 0x7e,
     73     0x61, 0xf5, 0x0d, 0xf5, 0x38, 0xa4, 0xfc, 0xb1, 0x8a, 0x95, 0xff, 0x59,
     74     0xbc, 0x04, 0x82, 0xcf, 0x23, 0xb2, 0x32, 0x56}},
     75   {D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyz"),
     76    {0xfc, 0x31, 0x89, 0x44, 0x3f, 0x9c, 0x26, 0x8f, 0x62, 0x6a, 0xea, 0x08,
     77     0xa7, 0x56, 0xab, 0xe7, 0xb7, 0x26, 0xb0, 0x5f, 0x70, 0x1c, 0xb0, 0x82,
     78     0x22, 0x31, 0x2c, 0xcf, 0xd6, 0x71, 0x0a, 0x26, }},
     79   {D_STR_W_LEN ("zyxwvutsrqponMLKJIHGFEDCBA"),
     80    {0xd2, 0x6d, 0x24, 0x81, 0xa4, 0xf9, 0x0a, 0x72, 0xd2, 0x7f, 0xc1, 0xac,
     81     0xac, 0xe1, 0xc0, 0x6b, 0x39, 0x94, 0xac, 0x73, 0x50, 0x2e, 0x27, 0x97,
     82     0xa3, 0x65, 0x37, 0x4e, 0xbb, 0x5c, 0x27, 0xe9}},
     83   {D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyzzyxwvutsrqponMLKJIHGFEDCBA" \
     84                 "abcdefghijklmnopqrstuvwxyzzyxwvutsrqponMLKJIHGFEDCBA"),
     85    {0xad, 0xe9, 0x5d, 0x55, 0x3b, 0x9e, 0x45, 0x69, 0xdb, 0x53, 0xa4, 0x04,
     86     0x92, 0xe7, 0x87, 0x94, 0xff, 0xc9, 0x98, 0x5f, 0x93, 0x03, 0x86, 0x45,
     87     0xe1, 0x97, 0x17, 0x72, 0x7c, 0xbc, 0x31, 0x15}},
     88   {D_STR_W_LEN ("/long/long/long/long/long/long/long/long/long/long/long" \
     89                 "/long/long/long/long/long/long/long/long/long/long/long" \
     90                 "/long/long/long/long/long/long/long/long/long/long/long" \
     91                 "/long/long/long/long/long/long/long/long/long/long/long" \
     92                 "/long/long/long/long/long/long/long/long/long/long/long" \
     93                 "/long/long/long/long/long/long/long/long/long/long/long" \
     94                 "/long/long/long/long/path?with%20some=parameters"),
     95    {0xbc, 0xab, 0xc6, 0x2c, 0x0a, 0x22, 0xd5, 0xcb, 0xac, 0xac, 0xe9, 0x25,
     96     0xcf, 0xce, 0xaa, 0xaf, 0x0e, 0xa1, 0xed, 0x42, 0x46, 0x8a, 0xe2, 0x01,
     97     0xee, 0x2f, 0xdb, 0x39, 0x75, 0x47, 0x73, 0xf1}}
     98 };
     99 
    100 static const size_t units1_num = sizeof(data_units1) / sizeof(data_units1[0]);
    101 
    102 struct bin_with_len
    103 {
    104   const uint8_t bin[512];
    105   const size_t len;
    106 };
    107 
    108 struct data_unit2
    109 {
    110   const struct bin_with_len bin_l;
    111   const uint8_t digest[SHA512_256_DIGEST_SIZE];
    112 };
    113 
    114 /* Size must be less than 512 bytes! */
    115 static const struct data_unit2 data_units2[] = {
    116   { { {97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
    117        112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122}, 26}, /* a..z ASCII sequence */
    118     {0xfc, 0x31, 0x89, 0x44, 0x3f, 0x9c, 0x26, 0x8f, 0x62, 0x6a, 0xea, 0x08,
    119      0xa7, 0x56, 0xab, 0xe7, 0xb7, 0x26, 0xb0, 0x5f, 0x70, 0x1c, 0xb0, 0x82,
    120      0x22, 0x31, 0x2c, 0xcf, 0xd6, 0x71, 0x0a, 0x26}},
    121   { { {65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
    122        65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
    123        65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
    124        65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65},
    125       72 }, /* 'A' x 72 times */
    126     {0x36, 0x5d, 0x41, 0x0e, 0x55, 0xd1, 0xfd, 0xe6, 0xc3, 0xb8, 0x68, 0xcc,
    127      0xed, 0xeb, 0xcd, 0x0d, 0x2e, 0x34, 0xb2, 0x5c, 0xdf, 0xe7, 0x79, 0xe2,
    128      0xe9, 0x65, 0x07, 0x33, 0x78, 0x0d, 0x01, 0x89}},
    129   { { {19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
    130        37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
    131        55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
    132        73}, 55}, /* 19..73 sequence */
    133     {0xb9, 0xe5, 0x74, 0x11, 0xbf, 0xa2, 0x0e, 0x98, 0xbe, 0x08, 0x69, 0x2e,
    134      0x17, 0x9e, 0xc3, 0xfe, 0x61, 0xe3, 0x7a, 0x80, 0x2e, 0x25, 0x8c, 0xf3,
    135      0x76, 0xda, 0x9f, 0x5f, 0xcd, 0x87, 0x48, 0x0d}},
    136   { { {7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
    137        26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
    138        44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
    139        62, 63, 64, 65, 66, 67, 68, 69}, 63}, /* 7..69 sequence */
    140     {0x80, 0x15, 0x83, 0xed, 0x7d, 0xef, 0x9f, 0xdf, 0xfb, 0x83, 0x1f, 0xc5,
    141      0x8b, 0x50, 0x37, 0x81, 0x00, 0xc3, 0x4f, 0xfd, 0xfe, 0xc2, 0x9b, 0xaf,
    142      0xfe, 0x15, 0x66, 0xe5, 0x08, 0x42, 0x5e, 0xae}},
    143   { { {38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
    144        56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
    145        74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
    146        92}, 55}, /* 38..92 sequence */
    147     {0x76, 0x2f, 0x27, 0x4d, 0xfa, 0xd5, 0xa9, 0x21, 0x4e, 0xe9, 0x56, 0x22,
    148      0x54, 0x38, 0x71, 0x3e, 0xef, 0x14, 0xa9, 0x22, 0x37, 0xf3, 0xb0, 0x50,
    149      0x3d, 0x95, 0x40, 0xb7, 0x08, 0x64, 0xa9, 0xfd}},
    150   { { {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
    151        21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
    152        39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
    153        57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72}, 72}, /* 1..72 sequence */
    154     {0x3f, 0x5c, 0xd3, 0xec, 0x40, 0xc4, 0xb9, 0x78, 0x35, 0x57, 0xc6, 0x4f,
    155      0x3e, 0x46, 0x82, 0xdc, 0xd4, 0x46, 0x11, 0xd0, 0xb3, 0x0a, 0xbb, 0x89,
    156      0xf1, 0x1d, 0x34, 0xb5, 0xf9, 0xd5, 0x10, 0x35}},
    157   { { {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
    158        21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
    159        39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
    160        57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
    161        75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
    162        93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108,
    163        109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122,
    164        123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
    165        137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150,
    166        151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
    167        165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178,
    168        179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192,
    169        193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206,
    170        207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220,
    171        221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234,
    172        235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248,
    173        249, 250, 251, 252, 253, 254, 255}, 256}, /* 0..255 sequence */
    174     {0x08, 0x37, 0xa1, 0x1d, 0x99, 0x4d, 0x5a, 0xa8, 0x60, 0xd0, 0x69, 0x17,
    175      0xa8, 0xa0, 0xf6, 0x3e, 0x31, 0x11, 0xb9, 0x56, 0x33, 0xde, 0xeb, 0x15,
    176      0xee, 0xd9, 0x94, 0x93, 0x76, 0xf3, 0x7d, 0x36, }},
    177   { { {199, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 188, 187, 186,
    178        185, 184, 183, 182, 181, 180,
    179        179, 178, 177, 176, 175, 174, 173, 172, 171, 170, 169, 168, 167, 166,
    180        165, 164, 163, 162, 161, 160,
    181        159, 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146,
    182        145, 144, 143, 142, 141, 140,
    183        139}, 61},  /* 199..139 sequence */
    184     {0xcf, 0x21, 0x4b, 0xb2, 0xdd, 0x40, 0x98, 0xdf, 0x3a, 0xb7, 0x21, 0xb4,
    185      0x69, 0x0e, 0x19, 0x36, 0x24, 0xa9, 0xbe, 0x30, 0xf7, 0xd0, 0x75, 0xb0,
    186      0x39, 0x94, 0x82, 0xda, 0x55, 0x97, 0xe4, 0x79}},
    187   { { {255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242,
    188        241, 240, 239, 238, 237, 236, 235, 234, 233, 232, 231, 230, 229, 228,
    189        227, 226, 225, 224, 223, 222, 221, 220, 219, 218, 217, 216, 215, 214,
    190        213, 212, 211, 210, 209, 208, 207, 206, 205, 204, 203, 202, 201, 200,
    191        199, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 188, 187, 186,
    192        185, 184, 183, 182, 181, 180, 179, 178, 177, 176, 175, 174, 173, 172,
    193        171, 170, 169, 168, 167, 166, 165, 164, 163, 162, 161, 160, 159, 158,
    194        157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 144,
    195        143, 142, 141, 140, 139, 138, 137, 136, 135, 134, 133, 132, 131, 130,
    196        129, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116,
    197        115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102,
    198        101, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85,
    199        84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67,
    200        66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49,
    201        48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31,
    202        30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13,
    203        12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, 255},  /* 255..1 sequence */
    204     {0x22, 0x31, 0xf2, 0xa1, 0xb4, 0x89, 0xb2, 0x44, 0xf7, 0x66, 0xa0, 0xb8,
    205      0x31, 0xed, 0xb7, 0x73, 0x8a, 0x34, 0xdc, 0x11, 0xc8, 0x2c, 0xf2, 0xb5,
    206      0x88, 0x60, 0x39, 0x6b, 0x5c, 0x06, 0x70, 0x37}},
    207   { { {41, 35, 190, 132, 225, 108, 214, 174, 82, 144, 73, 241, 241, 187, 233,
    208        235, 179, 166, 219, 60, 135, 12, 62, 153, 36, 94, 13, 28, 6, 183, 71,
    209        222, 179, 18, 77, 200, 67, 187, 139, 166, 31, 3, 90, 125, 9, 56, 37,
    210        31, 93, 212, 203, 252, 150, 245, 69, 59, 19, 13, 137, 10, 28, 219, 174,
    211        50, 32, 154, 80, 238, 64, 120, 54, 253, 18, 73, 50, 246, 158, 125, 73,
    212        220, 173, 79, 20, 242, 68, 64, 102, 208, 107, 196, 48, 183, 50, 59,
    213        161, 34, 246, 34, 145, 157, 225, 139, 31, 218, 176, 202, 153, 2, 185,
    214        114, 157, 73, 44, 128, 126, 197, 153, 213, 233, 128, 178, 234, 201,
    215        204, 83, 191, 103, 214, 191, 20, 214, 126, 45, 220, 142, 102, 131, 239,
    216        87, 73, 97, 255, 105, 143, 97, 205, 209, 30, 157, 156, 22, 114, 114,
    217        230, 29, 240, 132, 79, 74, 119, 2, 215, 232, 57, 44, 83, 203, 201, 18,
    218        30, 51, 116, 158, 12, 244, 213, 212, 159, 212, 164, 89, 126, 53, 207,
    219        50, 34, 244, 204, 207, 211, 144, 45, 72, 211, 143, 117, 230, 217, 29,
    220        42, 229, 192, 247, 43, 120, 129, 135, 68, 14, 95, 80, 0, 212, 97, 141,
    221        190, 123, 5, 21, 7, 59, 51, 130, 31, 24, 112, 146, 218, 100, 84, 206,
    222        177, 133, 62, 105, 21, 248, 70, 106, 4, 150, 115, 14, 217, 22, 47, 103,
    223        104, 212, 247, 74, 74, 208, 87, 104}, 255},  /* pseudo-random data */
    224     {0xb8, 0xdb, 0x2c, 0x2e, 0xf3, 0x12, 0x77, 0x14, 0xf9, 0x34, 0x2d, 0xfa,
    225      0xda, 0x42, 0xbe, 0xfe, 0x67, 0x3a, 0x8a, 0xf6, 0x71, 0x36, 0x00, 0xff,
    226      0x77, 0xa5, 0x83, 0x14, 0x55, 0x2a, 0x05, 0xaf}},
    227   { { {66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
    228        66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
    229        66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
    230        66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
    231        66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
    232        66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
    233        66, 66}, 110},  /* 'B' x 110 times */
    234     {0xc8, 0x9e, 0x0d, 0x8f, 0x7b, 0x35, 0xfd, 0x3e, 0xdc, 0x90, 0x87, 0x64,
    235      0x45, 0x94, 0x94, 0x21, 0xb3, 0x8e, 0xb5, 0xc7, 0x54, 0xc8, 0xee, 0xde,
    236      0xfc, 0x77, 0xd6, 0xe3, 0x9f, 0x81, 0x8e, 0x78}},
    237   { { {67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
    238        67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
    239        67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
    240        67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
    241        67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
    242        67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
    243        67, 67, 67}, 111},  /* 'C' x 111 times */
    244     {0x86, 0xca, 0x6d, 0x2a, 0x72, 0xe2, 0x8c, 0x17, 0x89, 0x86, 0x89, 0x1b,
    245      0x36, 0xf9, 0x6d, 0xda, 0x8c, 0xd6, 0x30, 0xb2, 0xd3, 0x60, 0x39, 0xfb,
    246      0xc9, 0x04, 0xc5, 0x11, 0xcd, 0x2d, 0xe3, 0x62}},
    247   { { {68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
    248        68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
    249        68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
    250        68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
    251        68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
    252        68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
    253        68, 68, 68, 68}, 112},  /* 'D' x 112 times */
    254     {0xdf, 0x9d, 0x4a, 0xcf, 0x81, 0x0d, 0x3a, 0xd4, 0x8e, 0xa4, 0x65, 0x9e,
    255      0x1e, 0x15, 0xe4, 0x15, 0x1b, 0x37, 0xb6, 0xeb, 0x17, 0xab, 0xf6, 0xb1,
    256      0xbc, 0x30, 0x46, 0x34, 0x24, 0x56, 0x1c, 0x06}},
    257   { { {69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69,
    258        69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69,
    259        69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69,
    260        69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69,
    261        69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69,
    262        69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69,
    263        69, 69, 69, 69, 69}, 113},  /* 'E' x 113 times */
    264     {0xa5, 0xf1, 0x47, 0x74, 0xf8, 0x2b, 0xed, 0x23, 0xe4, 0x10, 0x59, 0x8f,
    265      0x7e, 0xb1, 0x30, 0xe5, 0x7e, 0xd1, 0x4b, 0xbc, 0x72, 0x58, 0x58, 0x81,
    266      0xbb, 0xa0, 0xa5, 0xb6, 0x15, 0x39, 0x49, 0xa1}},
    267   { { {70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
    268        70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
    269        70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
    270        70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
    271        70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
    272        70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
    273        70, 70, 70, 70, 70, 70}, 114},  /* 'F' x 114 times */
    274     {0xe6, 0xa3, 0xc9, 0x63, 0xd5, 0x28, 0x6e, 0x2d, 0xfb, 0x71, 0xdf, 0xd4,
    275      0xff, 0xc2, 0xd4, 0x2b, 0x5d, 0x9b, 0x76, 0x28, 0xd2, 0xcb, 0x15, 0xc8,
    276      0x81, 0x57, 0x14, 0x09, 0xc3, 0x8e, 0x92, 0xce}},
    277   { { {76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76,
    278        76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76,
    279        76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76,
    280        76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76,
    281        76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76,
    282        76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76,
    283        76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76,
    284        76}, 127},  /* 'L' x 127 times */
    285     {0x5d, 0x18, 0xff, 0xd7, 0xbe, 0x23, 0xb2, 0xb2, 0xbd, 0xe3, 0x13, 0x12,
    286      0x1c, 0x16, 0x89, 0x14, 0x4a, 0x42, 0xb4, 0x3f, 0xab, 0xc8, 0x41, 0x14,
    287      0x62, 0x00, 0xb5, 0x53, 0xa7, 0xd6, 0xd5, 0x35}},
    288   { { {77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
    289        77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
    290        77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
    291        77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
    292        77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
    293        77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
    294        77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
    295        77, 77}, 128},  /* 'M' x 128 times */
    296     {0x6e, 0xf0, 0xda, 0x81, 0x3d, 0x50, 0x1d, 0x31, 0xf1, 0x4a, 0xf8, 0xd9,
    297      0x7d, 0xd2, 0x13, 0xdd, 0xa4, 0x46, 0x15, 0x0b, 0xb8, 0x5a, 0x8a, 0xc6,
    298      0x1e, 0x3a, 0x1f, 0x21, 0x35, 0xa2, 0xbb, 0x4f}},
    299   { { {78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
    300        78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
    301        78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
    302        78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
    303        78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
    304        78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
    305        78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
    306        78, 78, 78}, 129},  /* 'N' x 129 times */
    307     {0xee, 0xce, 0xd5, 0x34, 0xab, 0x14, 0x13, 0x9e, 0x8f, 0x5c, 0xb4, 0xef,
    308      0xac, 0xaf, 0xc5, 0xeb, 0x1d, 0x2f, 0xe3, 0xc5, 0xca, 0x09, 0x29, 0x96,
    309      0xfa, 0x84, 0xff, 0x12, 0x26, 0x6a, 0x50, 0x49}},
    310   { { {97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,
    311        97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,
    312        97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,
    313        97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,
    314        97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,
    315        97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,
    316        97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,
    317        97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,
    318        97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,
    319        97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,
    320        97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,
    321        97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,
    322        97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,
    323        97, 97, 97, 97}, 238},  /* 'a' x 238 times */
    324     {0xb4, 0x24, 0xe5, 0x7b, 0xa7, 0x37, 0xe3, 0xc4, 0xac, 0x35, 0x21, 0x17,
    325      0x98, 0xec, 0xb9, 0xae, 0x45, 0x13, 0x24, 0xa4, 0x2c, 0x76, 0xae, 0x7d,
    326      0x17, 0x75, 0x27, 0x8a, 0xaa, 0x4a, 0x48, 0x60}},
    327   { { {98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,
    328        98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,
    329        98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,
    330        98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,
    331        98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,
    332        98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,
    333        98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,
    334        98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,
    335        98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,
    336        98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,
    337        98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,
    338        98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,
    339        98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,
    340        98, 98, 98, 98, 98}, 239},  /* 'b' x 239 times */
    341     {0xcd, 0x93, 0xb8, 0xab, 0x6a, 0x74, 0xbd, 0x34, 0x8c, 0x43, 0x76, 0x0c,
    342      0x2a, 0xd0, 0x6e, 0xd8, 0x76, 0xcf, 0xdf, 0x2a, 0x21, 0x04, 0xfb, 0xf6,
    343      0x16, 0x53, 0x68, 0xf6, 0x10, 0xc3, 0xa1, 0xac}},
    344   { { {99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
    345        99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
    346        99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
    347        99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
    348        99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
    349        99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
    350        99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
    351        99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
    352        99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
    353        99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
    354        99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
    355        99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
    356        99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
    357        99, 99, 99, 99, 99, 99}, 240},  /* 'c' x 240 times */
    358     {0x5f, 0x60, 0xea, 0x44, 0xb6, 0xc6, 0x9e, 0xfe, 0xfc, 0x0e, 0x6a, 0x0a,
    359      0x99, 0x40, 0x1b, 0x61, 0x43, 0x58, 0xba, 0x4a, 0x0a, 0xee, 0x6b, 0x52,
    360      0x10, 0xdb, 0x32, 0xd9, 0x7f, 0x12, 0xba, 0x70}},
    361   { { {48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
    362        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
    363        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
    364        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
    365        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
    366        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
    367        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
    368        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
    369        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
    370        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
    371        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
    372        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
    373        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
    374        48, 48, 48, 48, 48, 48, 48}, 241}, /* '0' x 241 times */
    375     {0x3c, 0xcb, 0xcf, 0x50, 0x79, 0xd5, 0xb6, 0xf5, 0xbf, 0x25, 0x07, 0xfb,
    376      0x4d, 0x1f, 0xa3, 0x77, 0xc3, 0x6f, 0xe8, 0xe3, 0xc4, 0x4b, 0xf8, 0xcd,
    377      0x90, 0x93, 0xf1, 0x3e, 0x08, 0x09, 0xa7, 0x69}}
    378 };
    379 
    380 static const size_t units2_num = sizeof(data_units2) / sizeof(data_units2[0]);
    381 
    382 
    383 /*
    384  *  Helper functions
    385  */
    386 
    387 /**
    388  * Print bin as hex
    389  *
    390  * @param bin binary data
    391  * @param len number of bytes in bin
    392  * @param hex pointer to len*2+1 bytes buffer
    393  */
    394 static void
    395 bin2hex (const uint8_t *bin,
    396          size_t len,
    397          char *hex)
    398 {
    399   while (len-- > 0)
    400   {
    401     unsigned int b1, b2;
    402     b1 = (*bin >> 4) & 0xf;
    403     *hex++ = (char) ((b1 > 9) ? (b1 + 'A' - 10) : (b1 + '0'));
    404     b2 = *bin++ & 0xf;
    405     *hex++ = (char) ((b2 > 9) ? (b2 + 'A' - 10) : (b2 + '0'));
    406   }
    407   *hex = 0;
    408 }
    409 
    410 
    411 static int
    412 check_result (const char *test_name,
    413               unsigned int check_num,
    414               const uint8_t calculated[SHA512_256_DIGEST_SIZE],
    415               const uint8_t expected[SHA512_256_DIGEST_SIZE])
    416 {
    417   int failed = memcmp (calculated, expected, SHA512_256_DIGEST_SIZE);
    418   check_num++; /* Print 1-based numbers */
    419   if (failed)
    420   {
    421     char calc_str[SHA512_256_DIGEST_SIZE * 2 + 1];
    422     char expc_str[SHA512_256_DIGEST_SIZE * 2 + 1];
    423     bin2hex (calculated, SHA512_256_DIGEST_SIZE, calc_str);
    424     bin2hex (expected, SHA512_256_DIGEST_SIZE, expc_str);
    425     fprintf (stderr,
    426              "FAILED: %s check %u: calculated digest %s, expected digest %s.\n",
    427              test_name, check_num, calc_str, expc_str);
    428     fflush (stderr);
    429   }
    430   else if (verbose)
    431   {
    432     char calc_str[SHA512_256_DIGEST_SIZE * 2 + 1];
    433     bin2hex (calculated, SHA512_256_DIGEST_SIZE, calc_str);
    434     printf ("PASSED: %s check %u: calculated digest %s matches " \
    435             "expected digest.\n",
    436             test_name, check_num, calc_str);
    437     fflush (stdout);
    438   }
    439   return failed ? 1 : 0;
    440 }
    441 
    442 
    443 /*
    444  *  Tests
    445  */
    446 
    447 /* Calculated SHA-512/256 as one pass for whole data */
    448 static int
    449 test1_str (void)
    450 {
    451   int num_failed = 0;
    452   unsigned int i;
    453   struct Sha512_256Ctx ctx;
    454 
    455   for (i = 0; i < units1_num; i++)
    456   {
    457     uint8_t digest[SHA512_256_DIGEST_SIZE];
    458 
    459     MHD_SHA512_256_init (&ctx);
    460     MHD_SHA512_256_update (&ctx, (const uint8_t *) data_units1[i].str_l.str,
    461                            data_units1[i].str_l.len);
    462     MHD_SHA512_256_finish (&ctx, digest);
    463     num_failed += check_result (__FUNCTION__, i, digest,
    464                                 data_units1[i].digest);
    465   }
    466   return num_failed;
    467 }
    468 
    469 
    470 static int
    471 test1_bin (void)
    472 {
    473   int num_failed = 0;
    474   unsigned int i;
    475   struct Sha512_256Ctx ctx;
    476 
    477   for (i = 0; i < units2_num; i++)
    478   {
    479     uint8_t digest[SHA512_256_DIGEST_SIZE];
    480 
    481     MHD_SHA512_256_init (&ctx);
    482     MHD_SHA512_256_update (&ctx, data_units2[i].bin_l.bin,
    483                            data_units2[i].bin_l.len);
    484     MHD_SHA512_256_finish (&ctx, digest);
    485     num_failed += check_result (__FUNCTION__, i, digest,
    486                                 data_units2[i].digest);
    487   }
    488   return num_failed;
    489 }
    490 
    491 
    492 /* Calculated SHA-512/256 as two iterations for whole data */
    493 static int
    494 test2_str (void)
    495 {
    496   int num_failed = 0;
    497   unsigned int i;
    498   struct Sha512_256Ctx ctx;
    499 
    500   for (i = 0; i < units1_num; i++)
    501   {
    502     uint8_t digest[SHA512_256_DIGEST_SIZE];
    503     size_t part_s = data_units1[i].str_l.len / 4;
    504 
    505     MHD_SHA512_256_init (&ctx);
    506     MHD_SHA512_256_update (&ctx, (const uint8_t *) "", 0);
    507     MHD_SHA512_256_update (&ctx, (const uint8_t *) data_units1[i].str_l.str,
    508                            part_s);
    509     MHD_SHA512_256_update (&ctx, (const uint8_t *) "", 0);
    510     MHD_SHA512_256_update (&ctx, (const uint8_t *) data_units1[i].str_l.str
    511                            + part_s,
    512                            data_units1[i].str_l.len - part_s);
    513     MHD_SHA512_256_update (&ctx, (const uint8_t *) "", 0);
    514     MHD_SHA512_256_finish (&ctx, digest);
    515     num_failed += check_result (__FUNCTION__, i, digest,
    516                                 data_units1[i].digest);
    517   }
    518   return num_failed;
    519 }
    520 
    521 
    522 static int
    523 test2_bin (void)
    524 {
    525   int num_failed = 0;
    526   unsigned int i;
    527   struct Sha512_256Ctx ctx;
    528 
    529   for (i = 0; i < units2_num; i++)
    530   {
    531     uint8_t digest[SHA512_256_DIGEST_SIZE];
    532     size_t part_s = data_units2[i].bin_l.len * 2 / 3;
    533 
    534     MHD_SHA512_256_init (&ctx);
    535     MHD_SHA512_256_update (&ctx, data_units2[i].bin_l.bin, part_s);
    536     MHD_SHA512_256_update (&ctx, (const uint8_t *) "", 0);
    537     MHD_SHA512_256_update (&ctx, data_units2[i].bin_l.bin + part_s,
    538                            data_units2[i].bin_l.len - part_s);
    539     MHD_SHA512_256_finish (&ctx, digest);
    540     num_failed += check_result (__FUNCTION__, i, digest,
    541                                 data_units2[i].digest);
    542   }
    543   return num_failed;
    544 }
    545 
    546 
    547 /* Use data set number 7 as it has the longest sequence */
    548 #define DATA_POS 6
    549 #define MAX_OFFSET 63
    550 
    551 static int
    552 test_unaligned (void)
    553 {
    554   int num_failed = 0;
    555   unsigned int offset;
    556   uint8_t *buf;
    557   uint8_t *digest_buf;
    558   struct Sha512_256Ctx ctx;
    559 
    560   const struct data_unit2 *const tdata = data_units2 + DATA_POS;
    561 
    562   buf = malloc (tdata->bin_l.len + MAX_OFFSET);
    563   digest_buf = malloc (SHA512_256_DIGEST_SIZE + MAX_OFFSET);
    564   if ((NULL == buf) || (NULL == digest_buf))
    565     exit (99);
    566 
    567   for (offset = MAX_OFFSET; offset >= 1; --offset)
    568   {
    569     uint8_t *unaligned_digest;
    570     uint8_t *unaligned_buf;
    571 
    572     unaligned_buf = buf + offset;
    573     memcpy (unaligned_buf, tdata->bin_l.bin, tdata->bin_l.len);
    574     unaligned_digest = digest_buf + MAX_OFFSET - offset;
    575     memset (unaligned_digest, 0, SHA512_256_DIGEST_SIZE);
    576 
    577     MHD_SHA512_256_init (&ctx);
    578     MHD_SHA512_256_update (&ctx, unaligned_buf, tdata->bin_l.len);
    579     MHD_SHA512_256_finish (&ctx, unaligned_digest);
    580     num_failed += check_result (__FUNCTION__, MAX_OFFSET - offset,
    581                                 unaligned_digest, tdata->digest);
    582   }
    583   free (digest_buf);
    584   free (buf);
    585   return num_failed;
    586 }
    587 
    588 
    589 int
    590 main (int argc, char *argv[])
    591 {
    592   int num_failed = 0;
    593   (void) has_in_name; /* Mute compiler warning. */
    594   if (has_param (argc, argv, "-v") || has_param (argc, argv, "--verbose"))
    595     verbose = 1;
    596 
    597   num_failed += test1_str ();
    598   num_failed += test1_bin ();
    599 
    600   num_failed += test2_str ();
    601   num_failed += test2_bin ();
    602 
    603   num_failed += test_unaligned ();
    604 
    605   return num_failed ? 1 : 0;
    606 }