1 #define shachain_index_t uint8_t
3 #include <ccan/crypto/shachain/shachain.h>
4 /* Include the C files directly. */
5 #include <ccan/crypto/shachain/shachain.c>
6 #include <ccan/tap/tap.h>
15 struct shachain chain;
16 struct sha256 expect[NUM_TESTS];
19 /* This is how many tests you plan to run */
20 plan_tests(NUM_TESTS + NUM_TESTS * (NUM_TESTS + 1) + NUM_TESTS);
22 memset(&seed, 0, sizeof(seed));
23 /* Generate a whole heap. */
24 for (i = 0; i < NUM_TESTS; i++) {
25 shachain_from_seed(&seed, i, &expect[i]);
27 ok1(memcmp(&expect[i], &seed, sizeof(expect[i])));
29 ok1(memcmp(&expect[i], &expect[i-1], sizeof(expect[i])));
32 shachain_init(&chain);
34 for (i = 0; i < NUM_TESTS; i++) {
37 shachain_add_hash(&chain, i, &expect[i]);
38 for (j = 0; j <= i; j++) {
39 ok1(shachain_get_hash(&chain, j, &hash));
40 ok1(memcmp(&hash, &expect[j], sizeof(hash)) == 0);
42 ok1(!shachain_get_hash(&chain, i+1, &hash));
43 if (chain.num_valid == 8) {
44 printf("%zu: num_valid %u\n", i, chain.num_valid);
45 for (j = 0; j < 8; j++)
46 printf("chain.known[%zu] = 0x%02x\n",
47 j, chain.known[j].index);