1 #include <ccan/crypto/sha256/sha256.h>
2 #include <ccan/str/hex/hex.h>
3 /* Include the C files directly. */
4 #include <ccan/crypto/sha256/sha256.c>
5 #include <ccan/tap/tap.h>
14 static struct test tests[] = {
16 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" },
18 "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" },
19 { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1,
20 "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" },
21 { "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", 1,
22 "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1" },
24 "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0" }
25 #if 0 /* Good test, but takes ages! */
26 , { "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno",
28 "50e72a0e26442fe2552dc3938ac58658228c0cbfb1d2ca872ae435266fcd055e" },
32 static bool do_test(const struct test *t)
34 struct sha256 h, expected;
36 if (t->repetitions == 1)
37 sha256(&h, t->test, strlen(t->test));
39 struct sha256_ctx ctx = SHA256_INIT;
42 for (i = 0; i < t->repetitions; i++)
43 sha256_update(&ctx, t->test, strlen(t->test));
44 sha256_done(&ctx, &h);
47 hex_decode(t->result, strlen(t->result), &expected, sizeof(expected));
48 return memcmp(&h, &expected, sizeof(h)) == 0;
53 const size_t num_tests = sizeof(tests) / sizeof(tests[0]);
56 /* This is how many tests you plan to run */
57 plan_tests(num_tests);
59 for (i = 0; i < num_tests; i++)
60 ok1(do_test(&tests[i]));
62 /* This exits depending on whether all tests passed */