From 85b12e691577b4d4fe09b80b06e91a801dc3dfa9 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 1 Sep 2024 18:12:21 +0200 Subject: Move test files into t/ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- t/shake512.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 t/shake512.c (limited to 't/shake512.c') diff --git a/t/shake512.c b/t/shake512.c new file mode 100644 index 0000000..f9f0a54 --- /dev/null +++ b/t/shake512.c @@ -0,0 +1,88 @@ +/* See LICENSE file for copyright and license details. */ +#ifdef SUPPORT_SHAKE +# define TEST +# include "../common.h" + + +#define MSG1600_32 "\xA3\xA3\xA3\xA3" +#define MSG1600_160 MSG1600_32 MSG1600_32 MSG1600_32 MSG1600_32 MSG1600_32 +#define MSG1600_800 MSG1600_160 MSG1600_160 MSG1600_160 MSG1600_160 MSG1600_160 +#define MSG1600 MSG1600_800 MSG1600_800 + + +static struct testcase testcases[] = { + {1, 0, "", + "ae1b4eea1eaf5ea633e66045f03ff11b8b7d3193119075442117bd786dfd939f" + "25a53a30fae503488d42683c1917b3964f6b1cf5d27c2b40cbaf53c5b749666a"}, + {1, 0, MSG1600, + "9701303d390f51968c25b6eee54816d19ab149a1c06b0625940bb8e04a1ceccd" + "d88010234f53abbbaf181f49761a3ecefaee56de7b59b5aaf0031e3c1552c9ac"} +}; + + +#else +# define TEST_UNSUPPORTED +# include "../common.h" +#endif + + +static int +main_test(void) +{ + TEST_MAIN("SHAKE512", SHAKE512); +} + + +int +main(void) +{ +#ifdef SUPPORT_SHAKE + struct libhashsum_hasher hasher; + char hexsum[1024]; +#endif + + int r = main_test(); + if (r) + return r; + + ASSERT(!libhashsum_init_shake512_hasher(&hasher, 8)); + ASSERT(!strcmp(hasher.algorithm_string, "SHAKE512[n=8]")); + ASSERT(!hasher.finalise_const(&hasher, "", 0, 0)); + ASSERT(hasher.hash_size == 1); + hex(hexsum, hasher.hash_output, hasher.hash_size); + ASSERT(!strcmp(hexsum, "ae")); + + ASSERT(!libhashsum_init_shake512_hasher(&hasher, 32)); + ASSERT(!strcmp(hasher.algorithm_string, "SHAKE512[n=32]")); + ASSERT(!hasher.finalise_const(&hasher, "", 0, 0)); + ASSERT(hasher.hash_size == 4); + hex(hexsum, hasher.hash_output, hasher.hash_size); + ASSERT(!strcmp(hexsum, "ae1b4eea")); + + ASSERT(!libhashsum_init_shake512_hasher(&hasher, 32)); + ASSERT(!strcmp(hasher.algorithm_string, "SHAKE512[n=32]")); + ASSERT(!hasher.finalise_const(&hasher, MSG1600, 1600/8, 0)); + ASSERT(hasher.hash_size == 4); + hex(hexsum, hasher.hash_output, hasher.hash_size); + ASSERT(!strcmp(hexsum, "9701303d")); + + ASSERT(!libhashsum_init_shake512_hasher(&hasher, 512)); + ASSERT(!strcmp(hasher.algorithm_string, "SHAKE512")); + ASSERT(!hasher.finalise_const(&hasher, MSG1600, 1600/8, 0)); + ASSERT(hasher.hash_size == 512/8); + hex(hexsum, hasher.hash_output, hasher.hash_size); + ASSERT(!strcmp(hexsum, "9701303d390f51968c25b6eee54816d19ab149a1c06b0625940bb8e04a1ceccd" + "d88010234f53abbbaf181f49761a3ecefaee56de7b59b5aaf0031e3c1552c9ac")); + + ASSERT(!libhashsum_init_shake512_hasher(&hasher, 1024)); + ASSERT(!strcmp(hasher.algorithm_string, "SHAKE512[n=1024]")); + ASSERT(!hasher.finalise_const(&hasher, MSG1600, 1600/8, 0)); + ASSERT(hasher.hash_size == 1024/8); + hex(hexsum, hasher.hash_output, hasher.hash_size); + ASSERT(!strcmp(hexsum, "9701303d390f51968c25b6eee54816d19ab149a1c06b0625940bb8e04a1ceccd" + "d88010234f53abbbaf181f49761a3ecefaee56de7b59b5aaf0031e3c1552c9ac" + "40dfaf6aac934fd644dbc4a3d753e1f3845a5901f415dff2a88440f6a8f5688f" + "f26e68ecc6ad23acf18e0a54be745db919fab01f77a251d5f66b01e2426bf020")); + + return 0; +} -- cgit v1.2.3-70-g09d2