1 #include <ccan/crypto/sha256/sha256.h>
2 /* Include the C files directly. */
3 #include <ccan/crypto/sha256/sha256.c>
4 #include <ccan/tap/tap.h>
7 /* This is the test introduced for SHA-3, which checks for 33-bit overflow:
8 "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno"
11 static uint32_t expected[] = {
12 CPU_TO_BE32(0x50e72a0e), CPU_TO_BE32(0x26442fe2),
13 CPU_TO_BE32(0x552dc393), CPU_TO_BE32(0x8ac58658),
14 CPU_TO_BE32(0x228c0cbf), CPU_TO_BE32(0xb1d2ca87),
15 CPU_TO_BE32(0x2ae43526), CPU_TO_BE32(0x6fcd055e)
18 /* Produced by actually running the code on x86. */
19 static const struct sha256_ctx after_16M_by_64 = {
20 #ifdef CCAN_CRYPTO_SHA256_USE_OPENSSL
21 { { LE32_TO_CPU(0x515e3215), LE32_TO_CPU(0x592f4ae0),
22 LE32_TO_CPU(0xd407a8fc), LE32_TO_CPU(0x1fad409b),
23 LE32_TO_CPU(0x51fa46cc), LE32_TO_CPU(0xea528ae5),
24 LE32_TO_CPU(0x5fa58ebb), LE32_TO_CPU(0x8be97931) },
26 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
29 { LE32_TO_CPU(0x515e3215), LE32_TO_CPU(0x592f4ae0),
30 LE32_TO_CPU(0xd407a8fc), LE32_TO_CPU(0x1fad409b),
31 LE32_TO_CPU(0x51fa46cc), LE32_TO_CPU(0xea528ae5),
32 LE32_TO_CPU(0x5fa58ebb), LE32_TO_CPU(0x8be97931) },
34 { .u32 = { 0x64636261, 0x68676665, 0x65646362, 0x69686766,
35 0x66656463, 0x6a696867, 0x67666564, 0x6b6a6968 } }
42 struct sha256_ctx ctx;
44 /* This is how many tests you plan to run */
47 ctx = after_16M_by_64;
48 sha256_done(&ctx, &h);
50 ok1(memcmp(&h.u, expected, sizeof(expected)) == 0);
52 /* This exits depending on whether all tests passed */