]> git.ozlabs.org Git - ccan/blob - ccan/crypto/shachain/shachain.h
crypto/shachain: detect if we're inserting a bogus hash.
[ccan] / ccan / crypto / shachain / shachain.h
1 /* MIT (BSD) license - see LICENSE file for details */
2 #ifndef CCAN_CRYPTO_SHACHAIN_H
3 #define CCAN_CRYPTO_SHACHAIN_H
4 #include "config.h"
5 #include <ccan/crypto/sha256/sha256.h>
6 #include <stdbool.h>
7 #include <stdint.h>
8
9 /* Useful for testing. */
10 #ifndef shachain_index_t
11 #define shachain_index_t uint64_t
12 #endif
13
14 void shachain_from_seed(const struct sha256 *seed, shachain_index_t index,
15                         struct sha256 *hash);
16
17 struct shachain {
18         unsigned int num_valid;
19         struct {
20                 shachain_index_t index;
21                 struct sha256 hash;
22         } known[sizeof(shachain_index_t) * 8];
23 };
24
25 void shachain_init(struct shachain *shachain);
26
27 bool shachain_add_hash(struct shachain *shachain,
28                        shachain_index_t index, const struct sha256 *hash);
29
30 bool shachain_get_hash(const struct shachain *shachain,
31                        shachain_index_t index, struct sha256 *hash);
32 #endif /* CCAN_CRYPTO_SHACHAIN_H */