amosnier/sha-2

Add a streaming API for computing SHA-256.

arnavyc opened this issue · 1 comments

This API could be useful for computing checksum of a file without storing all of the file's data in the memory, or checksumming 2 strings together without concatenating them. Example -

const char *a = "hello,";
const char *b = " world!";
uint8_t hash[32];

sha256_ctx_t ctx;
sha256_init(&ctx);
sha256_update(&ctx, a, strlen(a));
sha256_update(&ctx, b, strlen(b));
sha256_final(&ctx, hash);

Implemented in 6e94ad4.

That is in fact a complete rewrite, but I think the resulting structure is significantly better, because the hash value is calculated in chunks anyway. Thanks a lot for this suggestion. Enjoy!