X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fcrypto%2Fshachain%2Ftest%2Frun-8bit.c;h=6fe874bed433c9d975b05c7c569d4c590bb4df89;hp=10520bc354d8f4ce2aa99e424bf0d218b71098af;hb=e6abb93d50ba9f1e90163d7db53be70b8ef81a96;hpb=fc6655ed3c4840a5d4d669ad3c44e2ffe1019173 diff --git a/ccan/crypto/shachain/test/run-8bit.c b/ccan/crypto/shachain/test/run-8bit.c index 10520bc3..6fe874be 100644 --- a/ccan/crypto/shachain/test/run-8bit.c +++ b/ccan/crypto/shachain/test/run-8bit.c @@ -1,4 +1,4 @@ -#define shachain_index_t uint8_t +#define SHACHAIN_BITS 8 #include /* Include the C files directly. */ @@ -13,39 +13,41 @@ int main(void) { struct sha256 seed; struct shachain chain; - struct sha256 expect[NUM_TESTS]; - size_t i, j; + struct sha256 expect[NUM_TESTS+1]; + int i, j; /* This is how many tests you plan to run */ - plan_tests(NUM_TESTS + NUM_TESTS * (NUM_TESTS + 1) + NUM_TESTS); + plan_tests(66559); memset(&seed, 0, sizeof(seed)); - /* Generate a whole heap. */ - for (i = 0; i < NUM_TESTS; i++) { + /* Generate a whole heap; each should be different */ + for (i = 0; i <= NUM_TESTS; i++) { shachain_from_seed(&seed, i, &expect[i]); if (i == 0) - ok1(memcmp(&expect[i], &seed, sizeof(expect[i]))); + ok1(memcmp(&expect[i], &seed, sizeof(expect[i])) == 0); else ok1(memcmp(&expect[i], &expect[i-1], sizeof(expect[i]))); } shachain_init(&chain); - for (i = 0; i < NUM_TESTS; i++) { + for (i = NUM_TESTS; i > 0; i--) { struct sha256 hash; - shachain_add_hash(&chain, i, &expect[i]); - for (j = 0; j <= i; j++) { + ok1(shachain_add_hash(&chain, i, &expect[i])); + for (j = i; j <= NUM_TESTS; j++) { ok1(shachain_get_hash(&chain, j, &hash)); ok1(memcmp(&hash, &expect[j], sizeof(hash)) == 0); } - ok1(!shachain_get_hash(&chain, i+1, &hash)); - if (chain.num_valid == 8) { - printf("%zu: num_valid %u\n", i, chain.num_valid); - for (j = 0; j < 8; j++) - printf("chain.known[%zu] = 0x%02x\n", - j, chain.known[j].index); - } + ok1(!shachain_get_hash(&chain, i-1, &hash)); + } + + /* Now add seed. */ + ok1(shachain_add_hash(&chain, 0, &expect[0])); + for (j = 0; j <= NUM_TESTS; j++) { + struct sha256 hash; + ok1(shachain_get_hash(&chain, j, &hash)); + ok1(memcmp(&hash, &expect[j], sizeof(hash)) == 0); } return exit_status();