From 5caa621d9e0c3fc3893b0b94efe1503fcd6a5c88 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 1 Sep 2024 09:56:49 +0200 Subject: Add tests for SHAKE and RawSHAKE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- rawshake128.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 rawshake128.c (limited to 'rawshake128.c') diff --git a/rawshake128.c b/rawshake128.c new file mode 100644 index 0000000..fa914da --- /dev/null +++ b/rawshake128.c @@ -0,0 +1,80 @@ +/* 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, "", "fa019a3b17630df6014853b5470773f1"}, + {1, 0, MSG1600, "96a8092bb1419aefb092e1935190b10e"} +}; + + +#else +# define TEST_UNSUPPORTED +# include "common.h" +#endif + + +static int +main_test(void) +{ + TEST_MAIN("RawSHAKE128", RAWSHAKE128); +} + + +int +main(void) +{ +#ifdef SUPPORT_RAWSHAKE + struct libhashsum_hasher hasher; + char hexsum[1024]; +#endif + + int r = main_test(); + if (r) + return r; + + ASSERT(!libhashsum_init_rawshake128_hasher(&hasher, 8)); + ASSERT(!strcmp(hasher.algorithm_string, "RawSHAKE128[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, "fa")); + + ASSERT(!libhashsum_init_rawshake128_hasher(&hasher, 32)); + ASSERT(!strcmp(hasher.algorithm_string, "RawSHAKE128[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, "fa019a3b")); + + ASSERT(!libhashsum_init_rawshake128_hasher(&hasher, 32)); + ASSERT(!strcmp(hasher.algorithm_string, "RawSHAKE128[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, "96a8092b")); + + ASSERT(!libhashsum_init_rawshake128_hasher(&hasher, 128)); + ASSERT(!strcmp(hasher.algorithm_string, "RawSHAKE128")); + ASSERT(!hasher.finalise_const(&hasher, MSG1600, 1600/8, 0)); + ASSERT(hasher.hash_size == 128/8); + hex(hexsum, hasher.hash_output, hasher.hash_size); + ASSERT(!strcmp(hexsum, "96a8092bb1419aefb092e1935190b10e")); + + ASSERT(!libhashsum_init_rawshake128_hasher(&hasher, 256)); + ASSERT(!strcmp(hasher.algorithm_string, "RawSHAKE128[n=256]")); + ASSERT(!hasher.finalise_const(&hasher, MSG1600, 1600/8, 0)); + ASSERT(hasher.hash_size == 256/8); + hex(hexsum, hasher.hash_output, hasher.hash_size); + ASSERT(!strcmp(hexsum, "96a8092bb1419aefb092e1935190b10e6323db3b2e8e1ecc546518f20820da7b")); + + return 0; +} -- cgit v1.2.3-70-g09d2