diff options
author | Mattias Andrée <maandree@kth.se> | 2024-09-01 09:56:49 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-09-01 09:56:49 +0200 |
commit | 5caa621d9e0c3fc3893b0b94efe1503fcd6a5c88 (patch) | |
tree | 8494e1940f082441a06ad35e55d6e874d9855001 /rawshake256.c | |
parent | More testing (diff) | |
download | libhashsum-5caa621d9e0c3fc3893b0b94efe1503fcd6a5c88.tar.gz libhashsum-5caa621d9e0c3fc3893b0b94efe1503fcd6a5c88.tar.bz2 libhashsum-5caa621d9e0c3fc3893b0b94efe1503fcd6a5c88.tar.xz |
Add tests for SHAKE and RawSHAKE
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | rawshake256.c | 81 |
1 files changed, 81 insertions, 0 deletions
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; +} |