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 --- rawshake256.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 rawshake256.c (limited to 'rawshake256.c') diff --git a/rawshake256.c b/rawshake256.c new file mode 100644 index 0000000..e7836f0 --- /dev/null +++ b/rawshake256.c @@ -0,0 +1,81 @@ +/* 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, "", "3a1108d4a90a31b85a10bdce77f4bfbdcc5b1d70dd405686f8bbde834aa1a410"}, + {1, 0, MSG1600, "f353b1260d7a0adb3f5c08bf292f3372ad3ee4630d56cf11ba15ddfb2e70e7a2"} +}; + + +#else +# define TEST_UNSUPPORTED +# include "common.h" +#endif + + +static int +main_test(void) +{ + TEST_MAIN("RawSHAKE256", RAWSHAKE256); +} + + +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_rawshake256_hasher(&hasher, 8)); + ASSERT(!strcmp(hasher.algorithm_string, "RawSHAKE256[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, "3a")); + + ASSERT(!libhashsum_init_rawshake256_hasher(&hasher, 32)); + ASSERT(!strcmp(hasher.algorithm_string, "RawSHAKE256[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, "3a1108d4")); + + ASSERT(!libhashsum_init_rawshake256_hasher(&hasher, 32)); + ASSERT(!strcmp(hasher.algorithm_string, "RawSHAKE256[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, "f353b126")); + + ASSERT(!libhashsum_init_rawshake256_hasher(&hasher, 256)); + ASSERT(!strcmp(hasher.algorithm_string, "RawSHAKE256")); + 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, "f353b1260d7a0adb3f5c08bf292f3372ad3ee4630d56cf11ba15ddfb2e70e7a2")); + + ASSERT(!libhashsum_init_rawshake256_hasher(&hasher, 512)); + ASSERT(!strcmp(hasher.algorithm_string, "RawSHAKE256[n=512]")); + 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, "f353b1260d7a0adb3f5c08bf292f3372ad3ee4630d56cf11ba15ddfb2e70e7a2" + "3898431eb2500666c27251025869b0a6251029ba184e6075f5b3118cdc4abaa9")); + + return 0; +} -- cgit v1.2.3-70-g09d2