]> git.ozlabs.org Git - ccan/blob - ccan/crypto/shachain/_info
shachain: remove unnecessary shachain_index_t
[ccan] / ccan / crypto / shachain / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * crypto/shachain - compactly-representable chain of 256-bit numbers.
7  *
8  * This code produces a practically infinite (2^64) chain of 256-bit numbers
9  * from a single number, such that you can't derive element N from any element
10  * less than N, but can efficiently derive element N from a limited number
11  * of elements >= N.
12  *
13  * License: BSD-MIT
14  * Author: Rusty Russell <rusty@rustcorp.com.au>
15  *
16  * Example:
17  *
18  * #include <ccan/crypto/shachain/shachain.h>
19  * #include <ccan/err/err.h>
20  * #include <stdio.h>
21  * #include <stdlib.h>
22  * #include <string.h>
23  *
24  * int main(int argc, char *argv[])
25  * {
26  *      size_t i, j, limit = 10;
27  *      struct sha256 seed;
28  *
29  *      if (argc < 2)
30  *              errx(1, "Usage: %s <passphrase> [<num-to-generate>]", argv[0]);
31  *      sha256(&seed, argv[1], strlen(argv[1]));
32  *      if (argv[2])
33  *              limit = atol(argv[2]);
34  *
35  *      for (i = 0; i < limit; i++) {
36  *              struct sha256 v;
37  *              shachain_from_seed(&seed, i, &v);
38  *              printf("%zu: ", i);
39  *              for (j = 0; j < sizeof(v.u.u8); j++)
40  *                      printf("%02x", v.u.u8[j]);
41  *              printf("\n");
42  *      }
43  *      return 0;
44  * }
45  */
46 int main(int argc, char *argv[])
47 {
48         /* Expect exactly one argument */
49         if (argc != 2)
50                 return 1;
51
52         if (strcmp(argv[1], "depends") == 0) {
53                 printf("ccan/ilog\n");
54                 printf("ccan/crypto/sha256\n");
55                 return 0;
56         }
57
58         return 1;
59 }