X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fcrypto%2Fshachain%2Fshachain.h;h=8eabbab457a72b49c2c47736ce6e7d19f0b8fe82;hb=8ad6ab9ce9b78c6b28b727b11d571d11856479c6;hp=ba4ba11cd64c02d1d66a362d35bac98e39a2f0bc;hpb=d23fb57c8e276090325162966b094ebf71e73e68;p=ccan diff --git a/ccan/crypto/shachain/shachain.h b/ccan/crypto/shachain/shachain.h index ba4ba11c..8eabbab4 100644 --- a/ccan/crypto/shachain/shachain.h +++ b/ccan/crypto/shachain/shachain.h @@ -11,6 +11,10 @@ #define shachain_index_t uint64_t #endif +#ifndef SHACHAIN_BITS +#define SHACHAIN_BITS (sizeof(shachain_index_t) * 8) +#endif + /** * shachain_from_seed - Generate an unpredictable SHA from a seed value. * @seed: (secret) seed value to use @@ -56,7 +60,7 @@ struct shachain { struct { shachain_index_t index; struct sha256 hash; - } known[sizeof(shachain_index_t) * 8 + 1]; + } known[SHACHAIN_BITS + 1]; }; /** @@ -67,20 +71,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. + */ +shachain_index_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: