diff options
author | Mattias Andrée <maandree@kth.se> | 2024-08-31 21:11:07 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-08-31 21:11:07 +0200 |
commit | 3a4c26ddeaaffcbd7d808ef6322cfd61f2b84420 (patch) | |
tree | b31f57bfbee94ecf92be205617caae0d50b1172b /blake512.c | |
parent | Add support for extended hash + add support for output hash to custom buffer when supported (diff) | |
download | libhashsum-3a4c26ddeaaffcbd7d808ef6322cfd61f2b84420.tar.gz libhashsum-3a4c26ddeaaffcbd7d808ef6322cfd61f2b84420.tar.bz2 libhashsum-3a4c26ddeaaffcbd7d808ef6322cfd61f2b84420.tar.xz |
More testing
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'blake512.c')
-rw-r--r-- | blake512.c | 63 |
1 files changed, 62 insertions, 1 deletions
@@ -188,8 +188,69 @@ static struct testcase testcases[] = { #endif +static int +kat_test(void) +{ + TEST_MAIN("BLAKE512", BLAKE512); +} + + int main(void) { - TEST_MAIN("BLAKE512", BLAKE512); +#ifdef SUPPORT_BLAKE512 + struct libhashsum_hasher hasher1, hasher2; + char salt1[32], salt2[32]; +#endif + + int r = kat_test(); + if (r) + return r; + +#ifdef SUPPORT_BLAKE512 + memset(salt1, 0, sizeof(salt1)); + memset(salt2, 0xAB, sizeof(salt2)); + + ASSERT(!libhashsum_init_blake512_hasher(&hasher1, NULL)); + ASSERT(!libhashsum_init_blake512_hasher(&hasher2, salt1)); + ASSERT(!strcmp(hasher1.algorithm_string, "BLAKE512")); + ASSERT(!strcmp(hasher2.algorithm_string, "BLAKE512")); + ASSERT(!hasher1.finalise_const(&hasher1, NULL, 0, 0)); + ASSERT(!hasher2.finalise_const(&hasher2, NULL, 0, 0)); + ASSERT(!memcmp(hasher1.hash_output, hasher2.hash_output, hasher1.hash_size)); + + ASSERT(!libhashsum_init_blake512_hasher(&hasher1, NULL)); + ASSERT(!libhashsum_init_blake512_hasher(&hasher2, salt1)); + ASSERT(!hasher1.finalise_const(&hasher1, "testdata", 8U, 0)); + ASSERT(!hasher2.finalise_const(&hasher2, "testdata", 8U, 0)); + ASSERT(!memcmp(hasher1.hash_output, hasher2.hash_output, hasher1.hash_size)); + + ASSERT(!libhashsum_init_blake512_hasher(&hasher1, salt1)); + ASSERT(!libhashsum_init_blake512_hasher(&hasher2, salt2)); + ASSERT(!strcmp(hasher1.algorithm_string, "BLAKE512")); + ASSERT(!strcmp(hasher2.algorithm_string, "BLAKE512[salt=abababababababababababababababab" + "abababababababababababababababab]")); + ASSERT(!hasher1.finalise_const(&hasher1, NULL, 0, 0)); + ASSERT(!hasher2.finalise_const(&hasher2, NULL, 0, 0)); + ASSERT(memcmp(hasher1.hash_output, hasher2.hash_output, hasher1.hash_size)); + + ASSERT(!libhashsum_init_blake512_hasher(&hasher1, salt1)); + ASSERT(!libhashsum_init_blake512_hasher(&hasher2, salt2)); + ASSERT(!hasher1.finalise_const(&hasher1, "testdata", 8U, 0)); + ASSERT(!hasher2.finalise_const(&hasher2, "testdata", 8U, 0)); + ASSERT(memcmp(hasher1.hash_output, hasher2.hash_output, hasher1.hash_size)); + + ASSERT(!libhashsum_init_hasher_from_string(&hasher1, "BLAKE512[salt=00000000000000000000000000000000" + "00000000000000000000000000000000]")); + ASSERT(!libhashsum_init_hasher_from_string(&hasher2, "BLAKE512[salt=abababababababababababababababab" + "abababababababababababababababab]")); + ASSERT(!strcmp(hasher1.algorithm_string, "BLAKE512")); + ASSERT(!strcmp(hasher2.algorithm_string, "BLAKE512[salt=abababababababababababababababab" + "abababababababababababababababab]")); + ASSERT(!hasher1.finalise_const(&hasher1, NULL, 0, 0)); + ASSERT(!hasher2.finalise_const(&hasher2, NULL, 0, 0)); + ASSERT(memcmp(hasher1.hash_output, hasher2.hash_output, hasher1.hash_size)); +#endif + + return 0; } |