==> tests/vectors.c <==1/* FIPS 180-4 / NIST vectors, and the same digest however the bytes are split. */
2#include "mesh/check.h"
3#include "sha256_stream.h"
4
5static void hex_of(const char *msg, size_t n, size_t chunk, char out[65]) {
6 sha256_stream s;
7 sha256_stream_init(&s);
8 for (size_t i = 0; i < n; i += chunk) sha256_stream_update(&s, msg + i, n - i < chunk ? n - i : chunk);
9 uint8_t d[32];
10 sha256_stream_final(&s, d);
11 sha256_stream_hex(d, out);
12}
13
14int main(void) {
15 char h[65];
16 hex_of("", 0, 1, h);
17 CHECK_S(h, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
18 hex_of("abc", 3, 1, h);
19 CHECK_S(h, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
20 const char *two = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
21 for (size_t c = 1; c <= 64; c++) {
22 hex_of(two, strlen(two), c, h);
23 CHECK_S(h, "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1");
24 }
25 static char million[1000000];
26 memset(million, 'a', sizeof million);
27 hex_of(million, sizeof million, 4093, h);
28 CHECK_S(h, "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0");
29 return mesh_check_done();
30}