X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fcrypto%2Fshachain%2Fshachain.h;h=d95b97363f7d8e0bb243b6ebba9f35c8db3b5364;hp=ba4ba11cd64c02d1d66a362d35bac98e39a2f0bc;hb=e6abb93d50ba9f1e90163d7db53be70b8ef81a96;hpb=d23fb57c8e276090325162966b094ebf71e73e68 diff --git a/ccan/crypto/shachain/shachain.h b/ccan/crypto/shachain/shachain.h index ba4ba11c..d95b9736 100644 --- a/ccan/crypto/shachain/shachain.h +++ b/ccan/crypto/shachain/shachain.h @@ -6,9 +6,8 @@ #include #include -/* Useful for testing. */ -#ifndef shachain_index_t -#define shachain_index_t uint64_t +#ifndef SHACHAIN_BITS +#define SHACHAIN_BITS (sizeof(uint64_t) * 8) #endif /** @@ -38,7 +37,7 @@ * shachain_from_seed(&seed, index--, hash); * } */ -void shachain_from_seed(const struct sha256 *seed, shachain_index_t index, +void shachain_from_seed(const struct sha256 *seed, uint64_t index, struct sha256 *hash); /** @@ -51,12 +50,12 @@ void shachain_from_seed(const struct sha256 *seed, shachain_index_t index, * added. */ struct shachain { - shachain_index_t min_index; + uint64_t min_index; unsigned int num_valid; struct { - shachain_index_t index; + uint64_t index; struct sha256 hash; - } known[sizeof(shachain_index_t) * 8 + 1]; + } known[SHACHAIN_BITS + 1]; }; /** @@ -67,20 +66,28 @@ struct shachain { */ void shachain_init(struct shachain *chain); +/** + * shachain_next_index - what's the next index I can add to the shachain? + * @chain: the chain + * + * This returns 0xFFFFFFFFFFFFFFFF (for a freshly + * initialized chain), or one less than the previously successfully + * added value. + */ +uint64_t shachain_next_index(const struct shachain *chain); + /** * shachain_add_hash - record the hash for the next index. * @chain: the chain to add to * @index: the index of the hash * @hash: the hash value. * - * You can only add index 0xFFFFFFFFFFFFFFFF (for a freshly - * initialized chain), or one less than the previously successfully - * added value. + * You can only add shachain_next_index(@chain). * * This can fail (return false without altering @chain) if the hash * for this index isn't consistent with previous hashes (ie. wasn't * generated from the same seed), though it can't always detect that. - * If the hash is inconsistent yet undetected, the next addition will + * If the hash is inconsistent yet undetected, a future addition will * fail. * * Example: @@ -94,7 +101,7 @@ void shachain_init(struct shachain *chain); * } */ bool shachain_add_hash(struct shachain *chain, - shachain_index_t index, const struct sha256 *hash); + uint64_t index, const struct sha256 *hash); /** * shachain_get_hash - get the hash for a given index. @@ -125,5 +132,5 @@ bool shachain_add_hash(struct shachain *chain, * } */ bool shachain_get_hash(const struct shachain *chain, - shachain_index_t index, struct sha256 *hash); + uint64_t index, struct sha256 *hash); #endif /* CCAN_CRYPTO_SHACHAIN_H */