commit cb4d6aa378f0dcbcb1c0521e065a571a333d9f65
parent e6dcee35e511b33033626579e0fec9d2837ea0c2
Author: vaplv <vaplv@free.fr>
Date: Tue, 19 Jan 2021 15:46:45 +0100
Rm double checks in hash_sha256 tests
Remove the test on the hash_sha256_chunked_data function. With these
tests, data were hashed 2 times, increasing the computation time by two.
Since hash_sha256 internally relies on hash_sha256_chunked_data, it
is sufficient to check the former only.
Diffstat:
1 file changed, 3 insertions(+), 25 deletions(-)
diff --git a/src/test_hash_sha256.c b/src/test_hash_sha256.c
@@ -35,36 +35,14 @@ struct buf {
};
static void
-get_chunk512(char dst[64], const size_t ichunk, void* ctx)
-{
- struct buf* buf = ctx;
- size_t offset = 0;
- CHK(dst && buf && ichunk < (buf->len + 63/*ceil*/)/64);
-
- offset = ichunk * 64;
- memcpy(dst, buf->mem + offset, MMIN(64, buf->len - offset));
-}
-
-static void
chk_hash(const void* data, const size_t data_len, const char* sha256sum)
{
- struct buf buf;
- struct chunked_data_desc chunked_data = CHUNKED_DATA_DESC_NULL;
- hash256_T hash0;
- hash256_T hash1;
+ hash256_T hash;
char hash_str[65];
ASSERT(sha256sum);
- buf.mem = data;
- buf.len = data_len;
- chunked_data.get_chunk512 = get_chunk512;
- chunked_data.size = data_len;
- chunked_data.context = &buf;
-
- hash_sha256(data, data_len, hash0);
- hash_sha256_chunked_data(&chunked_data, hash1);
- hash256_eq(hash0, hash1);
- hash256_to_cstr(hash0, hash_str);
+ hash_sha256(data, data_len, hash);
+ hash256_to_cstr(hash, hash_str);
CHK(!strcmp(hash_str, sha256sum));
}