1*6236dae4SAndroid Build Coastguard Worker /***************************************************************************
2*6236dae4SAndroid Build Coastguard Worker * _ _ ____ _
3*6236dae4SAndroid Build Coastguard Worker * Project ___| | | | _ \| |
4*6236dae4SAndroid Build Coastguard Worker * / __| | | | |_) | |
5*6236dae4SAndroid Build Coastguard Worker * | (__| |_| | _ <| |___
6*6236dae4SAndroid Build Coastguard Worker * \___|\___/|_| \_\_____|
7*6236dae4SAndroid Build Coastguard Worker *
8*6236dae4SAndroid Build Coastguard Worker * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9*6236dae4SAndroid Build Coastguard Worker * Copyright (C) Evgeny Grin (Karlson2k), <[email protected]>.
10*6236dae4SAndroid Build Coastguard Worker *
11*6236dae4SAndroid Build Coastguard Worker * This software is licensed as described in the file COPYING, which
12*6236dae4SAndroid Build Coastguard Worker * you should have received as part of this distribution. The terms
13*6236dae4SAndroid Build Coastguard Worker * are also available at https://curl.se/docs/copyright.html.
14*6236dae4SAndroid Build Coastguard Worker *
15*6236dae4SAndroid Build Coastguard Worker * You may opt to use, copy, modify, merge, publish, distribute and/or sell
16*6236dae4SAndroid Build Coastguard Worker * copies of the Software, and permit persons to whom the Software is
17*6236dae4SAndroid Build Coastguard Worker * furnished to do so, under the terms of the COPYING file.
18*6236dae4SAndroid Build Coastguard Worker *
19*6236dae4SAndroid Build Coastguard Worker * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20*6236dae4SAndroid Build Coastguard Worker * KIND, either express or implied.
21*6236dae4SAndroid Build Coastguard Worker *
22*6236dae4SAndroid Build Coastguard Worker * SPDX-License-Identifier: curl
23*6236dae4SAndroid Build Coastguard Worker *
24*6236dae4SAndroid Build Coastguard Worker ***************************************************************************/
25*6236dae4SAndroid Build Coastguard Worker #include "curlcheck.h"
26*6236dae4SAndroid Build Coastguard Worker
27*6236dae4SAndroid Build Coastguard Worker #include "curl_sha512_256.h"
28*6236dae4SAndroid Build Coastguard Worker
unit_setup(void)29*6236dae4SAndroid Build Coastguard Worker static CURLcode unit_setup(void)
30*6236dae4SAndroid Build Coastguard Worker {
31*6236dae4SAndroid Build Coastguard Worker return CURLE_OK;
32*6236dae4SAndroid Build Coastguard Worker }
33*6236dae4SAndroid Build Coastguard Worker
unit_stop(void)34*6236dae4SAndroid Build Coastguard Worker static void unit_stop(void)
35*6236dae4SAndroid Build Coastguard Worker {
36*6236dae4SAndroid Build Coastguard Worker
37*6236dae4SAndroid Build Coastguard Worker }
38*6236dae4SAndroid Build Coastguard Worker
39*6236dae4SAndroid Build Coastguard Worker UNITTEST_START
40*6236dae4SAndroid Build Coastguard Worker
41*6236dae4SAndroid Build Coastguard Worker #ifdef CURL_HAVE_SHA512_256
42*6236dae4SAndroid Build Coastguard Worker
43*6236dae4SAndroid Build Coastguard Worker static const char test_str1[] = "1";
44*6236dae4SAndroid Build Coastguard Worker static const unsigned char precomp_hash1[CURL_SHA512_256_DIGEST_LENGTH] = {
45*6236dae4SAndroid Build Coastguard Worker 0x18, 0xd2, 0x75, 0x66, 0xbd, 0x1a, 0xc6, 0x6b, 0x23, 0x32, 0xd8,
46*6236dae4SAndroid Build Coastguard Worker 0xc5, 0x4a, 0xd4, 0x3f, 0x7b, 0xb2, 0x20, 0x79, 0xc9, 0x06, 0xd0,
47*6236dae4SAndroid Build Coastguard Worker 0x5f, 0x49, 0x1f, 0x3f, 0x07, 0xa2, 0x8d, 0x5c, 0x69, 0x90
48*6236dae4SAndroid Build Coastguard Worker };
49*6236dae4SAndroid Build Coastguard Worker static const char test_str2[] = "hello-you-fool";
50*6236dae4SAndroid Build Coastguard Worker static const unsigned char precomp_hash2[CURL_SHA512_256_DIGEST_LENGTH] = {
51*6236dae4SAndroid Build Coastguard Worker 0xaf, 0x6f, 0xb4, 0xb0, 0x13, 0x9b, 0xee, 0x13, 0xd1, 0x95, 0x3c,
52*6236dae4SAndroid Build Coastguard Worker 0xb8, 0xc7, 0xcd, 0x5b, 0x19, 0xf9, 0xcd, 0xcd, 0x21, 0xef, 0xdf,
53*6236dae4SAndroid Build Coastguard Worker 0xa7, 0x42, 0x5c, 0x07, 0x13, 0xea, 0xcc, 0x1a, 0x39, 0x76
54*6236dae4SAndroid Build Coastguard Worker };
55*6236dae4SAndroid Build Coastguard Worker static const char test_str3[] = "abc";
56*6236dae4SAndroid Build Coastguard Worker static const unsigned char precomp_hash3[CURL_SHA512_256_DIGEST_LENGTH] = {
57*6236dae4SAndroid Build Coastguard Worker 0x53, 0x04, 0x8E, 0x26, 0x81, 0x94, 0x1E, 0xF9, 0x9B, 0x2E, 0x29,
58*6236dae4SAndroid Build Coastguard Worker 0xB7, 0x6B, 0x4C, 0x7D, 0xAB, 0xE4, 0xC2, 0xD0, 0xC6, 0x34, 0xFC,
59*6236dae4SAndroid Build Coastguard Worker 0x6D, 0x46, 0xE0, 0xE2, 0xF1, 0x31, 0x07, 0xE7, 0xAF, 0x23
60*6236dae4SAndroid Build Coastguard Worker };
61*6236dae4SAndroid Build Coastguard Worker static const char test_str4[] = ""; /* empty, zero size input */
62*6236dae4SAndroid Build Coastguard Worker static const unsigned char precomp_hash4[CURL_SHA512_256_DIGEST_LENGTH] = {
63*6236dae4SAndroid Build Coastguard Worker 0xc6, 0x72, 0xb8, 0xd1, 0xef, 0x56, 0xed, 0x28, 0xab, 0x87, 0xc3,
64*6236dae4SAndroid Build Coastguard Worker 0x62, 0x2c, 0x51, 0x14, 0x06, 0x9b, 0xdd, 0x3a, 0xd7, 0xb8, 0xf9,
65*6236dae4SAndroid Build Coastguard Worker 0x73, 0x74, 0x98, 0xd0, 0xc0, 0x1e, 0xce, 0xf0, 0x96, 0x7a
66*6236dae4SAndroid Build Coastguard Worker };
67*6236dae4SAndroid Build Coastguard Worker static const char test_str5[] =
68*6236dae4SAndroid Build Coastguard Worker "abcdefghijklmnopqrstuvwxyzzyxwvutsrqponMLKJIHGFEDCBA" \
69*6236dae4SAndroid Build Coastguard Worker "abcdefghijklmnopqrstuvwxyzzyxwvutsrqponMLKJIHGFEDCBA";
70*6236dae4SAndroid Build Coastguard Worker static const unsigned char precomp_hash5[CURL_SHA512_256_DIGEST_LENGTH] = {
71*6236dae4SAndroid Build Coastguard Worker 0xad, 0xe9, 0x5d, 0x55, 0x3b, 0x9e, 0x45, 0x69, 0xdb, 0x53, 0xa4,
72*6236dae4SAndroid Build Coastguard Worker 0x04, 0x92, 0xe7, 0x87, 0x94, 0xff, 0xc9, 0x98, 0x5f, 0x93, 0x03,
73*6236dae4SAndroid Build Coastguard Worker 0x86, 0x45, 0xe1, 0x97, 0x17, 0x72, 0x7c, 0xbc, 0x31, 0x15
74*6236dae4SAndroid Build Coastguard Worker };
75*6236dae4SAndroid Build Coastguard Worker static const char test_str6[] =
76*6236dae4SAndroid Build Coastguard Worker "/long/long/long/long/long/long/long/long/long/long/long" \
77*6236dae4SAndroid Build Coastguard Worker "/long/long/long/long/long/long/long/long/long/long/long" \
78*6236dae4SAndroid Build Coastguard Worker "/long/long/long/long/long/long/long/long/long/long/long" \
79*6236dae4SAndroid Build Coastguard Worker "/long/long/long/long/long/long/long/long/long/long/long" \
80*6236dae4SAndroid Build Coastguard Worker "/long/long/long/long/long/long/long/long/long/long/long" \
81*6236dae4SAndroid Build Coastguard Worker "/long/long/long/long/long/long/long/long/long/long/long" \
82*6236dae4SAndroid Build Coastguard Worker "/long/long/long/long/path?with%20some=parameters";
83*6236dae4SAndroid Build Coastguard Worker static const unsigned char precomp_hash6[CURL_SHA512_256_DIGEST_LENGTH] = {
84*6236dae4SAndroid Build Coastguard Worker 0xbc, 0xab, 0xc6, 0x2c, 0x0a, 0x22, 0xd5, 0xcb, 0xac, 0xac, 0xe9,
85*6236dae4SAndroid Build Coastguard Worker 0x25, 0xcf, 0xce, 0xaa, 0xaf, 0x0e, 0xa1, 0xed, 0x42, 0x46, 0x8a,
86*6236dae4SAndroid Build Coastguard Worker 0xe2, 0x01, 0xee, 0x2f, 0xdb, 0x39, 0x75, 0x47, 0x73, 0xf1
87*6236dae4SAndroid Build Coastguard Worker };
88*6236dae4SAndroid Build Coastguard Worker static const char test_str7[] = "Simple string.";
89*6236dae4SAndroid Build Coastguard Worker static const unsigned char precomp_hash7[CURL_SHA512_256_DIGEST_LENGTH] = {
90*6236dae4SAndroid Build Coastguard Worker 0xde, 0xcb, 0x3c, 0x81, 0x65, 0x4b, 0xa0, 0xf5, 0xf0, 0x45, 0x6b,
91*6236dae4SAndroid Build Coastguard Worker 0x7e, 0x61, 0xf5, 0x0d, 0xf5, 0x38, 0xa4, 0xfc, 0xb1, 0x8a, 0x95,
92*6236dae4SAndroid Build Coastguard Worker 0xff, 0x59, 0xbc, 0x04, 0x82, 0xcf, 0x23, 0xb2, 0x32, 0x56
93*6236dae4SAndroid Build Coastguard Worker };
94*6236dae4SAndroid Build Coastguard Worker static const unsigned char test_seq8[]= {
95*6236dae4SAndroid Build Coastguard Worker 255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242,
96*6236dae4SAndroid Build Coastguard Worker 241, 240, 239, 238, 237, 236, 235, 234, 233, 232, 231, 230, 229, 228,
97*6236dae4SAndroid Build Coastguard Worker 227, 226, 225, 224, 223, 222, 221, 220, 219, 218, 217, 216, 215, 214,
98*6236dae4SAndroid Build Coastguard Worker 213, 212, 211, 210, 209, 208, 207, 206, 205, 204, 203, 202, 201, 200,
99*6236dae4SAndroid Build Coastguard Worker 199, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 188, 187, 186,
100*6236dae4SAndroid Build Coastguard Worker 185, 184, 183, 182, 181, 180, 179, 178, 177, 176, 175, 174, 173, 172,
101*6236dae4SAndroid Build Coastguard Worker 171, 170, 169, 168, 167, 166, 165, 164, 163, 162, 161, 160, 159, 158,
102*6236dae4SAndroid Build Coastguard Worker 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 144,
103*6236dae4SAndroid Build Coastguard Worker 143, 142, 141, 140, 139, 138, 137, 136, 135, 134, 133, 132, 131, 130,
104*6236dae4SAndroid Build Coastguard Worker 129, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116,
105*6236dae4SAndroid Build Coastguard Worker 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102,
106*6236dae4SAndroid Build Coastguard Worker 101, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85,
107*6236dae4SAndroid Build Coastguard Worker 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67,
108*6236dae4SAndroid Build Coastguard Worker 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49,
109*6236dae4SAndroid Build Coastguard Worker 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31,
110*6236dae4SAndroid Build Coastguard Worker 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13,
111*6236dae4SAndroid Build Coastguard Worker 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; /* 255..1 sequence */
112*6236dae4SAndroid Build Coastguard Worker static const unsigned char precomp_hash8[CURL_SHA512_256_DIGEST_LENGTH] = {
113*6236dae4SAndroid Build Coastguard Worker 0x22, 0x31, 0xf2, 0xa1, 0xb4, 0x89, 0xb2, 0x44, 0xf7, 0x66, 0xa0,
114*6236dae4SAndroid Build Coastguard Worker 0xb8, 0x31, 0xed, 0xb7, 0x73, 0x8a, 0x34, 0xdc, 0x11, 0xc8, 0x2c,
115*6236dae4SAndroid Build Coastguard Worker 0xf2, 0xb5, 0x88, 0x60, 0x39, 0x6b, 0x5c, 0x06, 0x70, 0x37
116*6236dae4SAndroid Build Coastguard Worker };
117*6236dae4SAndroid Build Coastguard Worker
118*6236dae4SAndroid Build Coastguard Worker unsigned char output_buf[CURL_SHA512_256_DIGEST_LENGTH];
119*6236dae4SAndroid Build Coastguard Worker unsigned char *computed_hash; /* Just to mute compiler warning */
120*6236dae4SAndroid Build Coastguard Worker
121*6236dae4SAndroid Build Coastguard Worker /* Mute compiler warnings in 'verify_memory' macros below */
122*6236dae4SAndroid Build Coastguard Worker computed_hash = output_buf;
123*6236dae4SAndroid Build Coastguard Worker
124*6236dae4SAndroid Build Coastguard Worker Curl_sha512_256it(output_buf, (const unsigned char *) test_str1,
125*6236dae4SAndroid Build Coastguard Worker (sizeof(test_str1) / sizeof(char)) - 1);
126*6236dae4SAndroid Build Coastguard Worker verify_memory(computed_hash, precomp_hash1, CURL_SHA512_256_DIGEST_LENGTH);
127*6236dae4SAndroid Build Coastguard Worker
128*6236dae4SAndroid Build Coastguard Worker Curl_sha512_256it(output_buf, (const unsigned char *) test_str2,
129*6236dae4SAndroid Build Coastguard Worker (sizeof(test_str2) / sizeof(char)) - 1);
130*6236dae4SAndroid Build Coastguard Worker verify_memory(computed_hash, precomp_hash2, CURL_SHA512_256_DIGEST_LENGTH);
131*6236dae4SAndroid Build Coastguard Worker
132*6236dae4SAndroid Build Coastguard Worker Curl_sha512_256it(output_buf, (const unsigned char *) test_str3,
133*6236dae4SAndroid Build Coastguard Worker (sizeof(test_str3) / sizeof(char)) - 1);
134*6236dae4SAndroid Build Coastguard Worker verify_memory(computed_hash, precomp_hash3, CURL_SHA512_256_DIGEST_LENGTH);
135*6236dae4SAndroid Build Coastguard Worker
136*6236dae4SAndroid Build Coastguard Worker Curl_sha512_256it(output_buf, (const unsigned char *) test_str4,
137*6236dae4SAndroid Build Coastguard Worker (sizeof(test_str4) / sizeof(char)) - 1);
138*6236dae4SAndroid Build Coastguard Worker verify_memory(computed_hash, precomp_hash4, CURL_SHA512_256_DIGEST_LENGTH);
139*6236dae4SAndroid Build Coastguard Worker
140*6236dae4SAndroid Build Coastguard Worker Curl_sha512_256it(output_buf, (const unsigned char *) test_str5,
141*6236dae4SAndroid Build Coastguard Worker (sizeof(test_str5) / sizeof(char)) - 1);
142*6236dae4SAndroid Build Coastguard Worker verify_memory(computed_hash, precomp_hash5, CURL_SHA512_256_DIGEST_LENGTH);
143*6236dae4SAndroid Build Coastguard Worker
144*6236dae4SAndroid Build Coastguard Worker Curl_sha512_256it(output_buf, (const unsigned char *) test_str6,
145*6236dae4SAndroid Build Coastguard Worker (sizeof(test_str6) / sizeof(char)) - 1);
146*6236dae4SAndroid Build Coastguard Worker verify_memory(computed_hash, precomp_hash6, CURL_SHA512_256_DIGEST_LENGTH);
147*6236dae4SAndroid Build Coastguard Worker
148*6236dae4SAndroid Build Coastguard Worker Curl_sha512_256it(output_buf, (const unsigned char *) test_str7,
149*6236dae4SAndroid Build Coastguard Worker (sizeof(test_str7) / sizeof(char)) - 1);
150*6236dae4SAndroid Build Coastguard Worker verify_memory(computed_hash, precomp_hash7, CURL_SHA512_256_DIGEST_LENGTH);
151*6236dae4SAndroid Build Coastguard Worker
152*6236dae4SAndroid Build Coastguard Worker Curl_sha512_256it(output_buf, test_seq8,
153*6236dae4SAndroid Build Coastguard Worker sizeof(test_seq8) / sizeof(unsigned char));
154*6236dae4SAndroid Build Coastguard Worker verify_memory(computed_hash, precomp_hash8, CURL_SHA512_256_DIGEST_LENGTH);
155*6236dae4SAndroid Build Coastguard Worker
156*6236dae4SAndroid Build Coastguard Worker #endif /* CURL_HAVE_SHA512_256 */
157*6236dae4SAndroid Build Coastguard Worker
158*6236dae4SAndroid Build Coastguard Worker
159*6236dae4SAndroid Build Coastguard Worker UNITTEST_STOP
160