Browse Source Download (without any required ccan dependencies)

Module:

crypto/shachain

Summary:

compactly-representable chain of 256-bit numbers.

Author:

Rusty Russell <[email protected]>

Dependencies:

Description:

This code produces a practically infinite (2^64) chain of 256-bit numbers from a single number, such that you can't derive element N from any element less than N, but can efficiently derive element N from a limited number of elements >= N.

Example:


#include <ccan/crypto/shachain/shachain.h>
#include <ccan/err/err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[])
{
     size_t i, j, limit = 10;
     struct sha256 seed;

     if (argc < 2)
             errx(1, "Usage: %s <passphrase> [<num-to-generate>]", argv[0]);
     sha256(&seed, argv[1], strlen(argv[1]));
     if (argv[2])
             limit = atol(argv[2]);

     for (i = 0; i < limit; i++) {
             struct sha256 v;
             shachain_from_seed(&seed, i, &v);
             printf("%zu: ", i);
             for (j = 0; j < sizeof(v.u.u8); j++)
                     printf("%02x", v.u.u8[j]);
             printf("\n");
     }
     return 0;
}

License:

BSD-MIT