]> git.ozlabs.org Git - ccan/blob - ccan/crypto/shachain/test/run-can_derive.c
shachain: clarify design in terms of binary tree, reverse indexes.
[ccan] / ccan / crypto / shachain / test / run-can_derive.c
1 #define shachain_index_t uint8_t
2
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>
7
8 #include <stdio.h>
9
10 static bool bit_set(shachain_index_t index, int bit)
11 {
12         return index & (1ULL << bit);
13 }
14
15 /* As per design.txt */
16 static bool naive_can_derive(shachain_index_t from, shachain_index_t to)
17 {
18         int i;
19
20         for (i = count_trailing_zeroes(from); i < 8; i++) {
21                 if (bit_set(from, i) != bit_set(to, i))
22                         return false;
23         }
24         return true;
25 }
26
27 int main(void)
28 {
29         int i, j;
30
31         /* This is how many tests you plan to run */
32         plan_tests(65536);
33
34         for (i = 0; i < 256; i++) {
35                 for (j = 0; j < 256; j++) {
36                         ok1(can_derive(i, j) == naive_can_derive(i, j));
37                 }
38         }
39
40         return exit_status();
41 }