From 3a4c26ddeaaffcbd7d808ef6322cfd61f2b84420 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 31 Aug 2024 21:11:07 +0200 Subject: More testing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- blake224.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'blake224.c') diff --git a/blake224.c b/blake224.c index 04d78f7..a0b6a9e 100644 --- a/blake224.c +++ b/blake224.c @@ -69,8 +69,65 @@ static struct testcase testcases[] = { #endif +static int +kat_test(void) +{ + TEST_MAIN("BLAKE224", BLAKE224); +} + + int main(void) { - TEST_MAIN("BLAKE224", BLAKE224); +#ifdef SUPPORT_BLAKE224 + struct libhashsum_hasher hasher1, hasher2; + char salt1[16], salt2[16]; +#endif + + int r = kat_test(); + if (r) + return r; + +#ifdef SUPPORT_BLAKE224 + memset(salt1, 0, sizeof(salt1)); + memset(salt2, 0xAB, sizeof(salt2)); + + ASSERT(!libhashsum_init_blake224_hasher(&hasher1, NULL)); + ASSERT(!libhashsum_init_blake224_hasher(&hasher2, salt1)); + ASSERT(!strcmp(hasher1.algorithm_string, "BLAKE224")); + ASSERT(!strcmp(hasher2.algorithm_string, "BLAKE224")); + 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_blake224_hasher(&hasher1, NULL)); + ASSERT(!libhashsum_init_blake224_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_blake224_hasher(&hasher1, salt1)); + ASSERT(!libhashsum_init_blake224_hasher(&hasher2, salt2)); + ASSERT(!strcmp(hasher1.algorithm_string, "BLAKE224")); + ASSERT(!strcmp(hasher2.algorithm_string, "BLAKE224[salt=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_blake224_hasher(&hasher1, salt1)); + ASSERT(!libhashsum_init_blake224_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, "BLAKE224[salt=00000000000000000000000000000000]")); + ASSERT(!libhashsum_init_hasher_from_string(&hasher2, "BLAKE224[salt=abababababababababababababababab]")); + ASSERT(!strcmp(hasher1.algorithm_string, "BLAKE224")); + ASSERT(!strcmp(hasher2.algorithm_string, "BLAKE224[salt=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; } -- cgit v1.2.3-70-g09d2