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 | |
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-- | Makefile | 6 | ||||
-rw-r--r-- | common.h | 2 | ||||
-rw-r--r-- | libhashsum.h | 24 | ||||
-rw-r--r-- | rawshake128.c | 80 | ||||
-rw-r--r-- | rawshake256.c | 81 | ||||
-rw-r--r-- | rawshake512.c | 88 | ||||
-rw-r--r-- | shake128.c | 88 | ||||
-rw-r--r-- | shake256.c | 89 | ||||
-rw-r--r-- | shake512.c | 88 |
9 files changed, 533 insertions, 13 deletions
@@ -106,6 +106,12 @@ TEST =\ sha3_256.t\ sha3_384.t\ sha3_512.t\ + shake128.t\ + shake256.t\ + shake512.t\ + rawshake128.t\ + rawshake256.t\ + rawshake512.t\ blake224.t\ blake256.t\ blake384.t\ @@ -63,7 +63,7 @@ struct testcase { }; static void -hex(char *out, const unsigned char *in, size_t n) +hex(char *restrict out, const unsigned char *restrict in, size_t n) { for (; n--; in++) { *out++ = "0123456789abcdef"[(*in >> 4) & 15]; diff --git a/libhashsum.h b/libhashsum.h index 22f7488..780b567 100644 --- a/libhashsum.h +++ b/libhashsum.h @@ -178,46 +178,46 @@ #define LIBHASHSUM_SHA3_512_HASH_SIZE 64 /** - * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHAKE_128` + * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHAKE128` * * @since 1.0 */ -#define LIBHASHSUM_SHAKE_128_HASH_SIZE 16 +#define LIBHASHSUM_SHAKE128_HASH_SIZE 16 /** - * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHAKE_256` + * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHAKE256` * * @since 1.0 */ -#define LIBHASHSUM_SHAKE_256_HASH_SIZE 32 +#define LIBHASHSUM_SHAKE256_HASH_SIZE 32 /** - * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHAKE_512` + * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHAKE512` * * @since 1.0 */ -#define LIBHASHSUM_SHAKE_512_HASH_SIZE 64 +#define LIBHASHSUM_SHAKE512_HASH_SIZE 64 /** - * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_RAWSHAKE_128` + * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_RAWSHAKE128` * * @since 1.0 */ -#define LIBHASHSUM_RAWSHAKE_128_HASH_SIZE 16 +#define LIBHASHSUM_RAWSHAKE128_HASH_SIZE 16 /** - * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_RAWSHAKE_256` + * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_RAWSHAKE256` * * @since 1.0 */ -#define LIBHASHSUM_RAWSHAKE_256_HASH_SIZE 32 +#define LIBHASHSUM_RAWSHAKE256_HASH_SIZE 32 /** - * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_RAWSHAKE_512` + * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_RAWSHAKE512` * * @since 1.0 */ -#define LIBHASHSUM_RAWSHAKE_512_HASH_SIZE 64 +#define LIBHASHSUM_RAWSHAKE512_HASH_SIZE 64 /** * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_BLAKE224` 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; +} 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; +} diff --git a/rawshake512.c b/rawshake512.c new file mode 100644 index 0000000..64dc31a --- /dev/null +++ b/rawshake512.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, "", + "0ae7dac687c3525d5c2a6c4119ea3968d43dfe69c2407a44d3de6b804d784530" + "462440e4881fd42785e1cb69af4f036d96d8ff1ee35d9b3fa4a2859f592fb2dc"}, + {1, 0, MSG1600, + "052eec877ef891c595c00dade1b0bc6717fde267635ef3883ff1f15161e83278" + "8078da28fbd2ae6d3309682b20c39aa40071b184f3db19a03b9251c8b0c323a7"} +}; + + +#else +# define TEST_UNSUPPORTED +# include "common.h" +#endif + + +static int +main_test(void) +{ + TEST_MAIN("RawSHAKE512", RAWSHAKE512); +} + + +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_rawshake512_hasher(&hasher, 8)); + ASSERT(!strcmp(hasher.algorithm_string, "RawSHAKE512[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, "0a")); + + ASSERT(!libhashsum_init_rawshake512_hasher(&hasher, 32)); + ASSERT(!strcmp(hasher.algorithm_string, "RawSHAKE512[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, "0ae7dac6")); + + ASSERT(!libhashsum_init_rawshake512_hasher(&hasher, 32)); + ASSERT(!strcmp(hasher.algorithm_string, "RawSHAKE512[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, "052eec87")); + + ASSERT(!libhashsum_init_rawshake512_hasher(&hasher, 512)); + ASSERT(!strcmp(hasher.algorithm_string, "RawSHAKE512")); + 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, "052eec877ef891c595c00dade1b0bc6717fde267635ef3883ff1f15161e83278" + "8078da28fbd2ae6d3309682b20c39aa40071b184f3db19a03b9251c8b0c323a7")); + + ASSERT(!libhashsum_init_rawshake512_hasher(&hasher, 1024)); + ASSERT(!strcmp(hasher.algorithm_string, "RawSHAKE512[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, "052eec877ef891c595c00dade1b0bc6717fde267635ef3883ff1f15161e83278" + "8078da28fbd2ae6d3309682b20c39aa40071b184f3db19a03b9251c8b0c323a7" + "e1699d793f43a292de7ccbe4f8621284bfcce07db44a3c20e23e691aebc8cd81" + "a9bebcdbbe5137f38292d62a2d5f34022d06b579ab18e6659f6e9fcea36c8e5a")); + + return 0; +} diff --git a/shake128.c b/shake128.c new file mode 100644 index 0000000..d0ac638 --- /dev/null +++ b/shake128.c @@ -0,0 +1,88 @@ +/* See LICENSE file for copyright and license details. */ +#ifdef SUPPORT_SHAKE +# define TEST +# include "common.h" + + +#define MSG5 "\x13" +#define MSG30 "\x53\x58\x7B\x19" +#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 +#define MSG1605 MSG1600_800 MSG1600_800 "\x03" +#define MSG1630 MSG1600_800 MSG1600_800 "\xA3\xA3\xA3\x23" + + +static struct testcase testcases[] = { + {1, 0, "", "7f9c2ba4e88f827d616045507605853e"}, + {1, 5, MSG5, "2e0abfba83e6720bfbc225ff6b7ab9ff"}, + {1, 6, MSG30, "6d5d39c55f3cca567feaf422dc64ba17"}, + {1, 0, MSG1600, "131ab8d2b594946b9c81333f9bb6e0ce"}, + {1, 5, MSG1605, "4ac38ebd1678b4a452792c5673f9777d"}, + {1, 6, MSG1630, "89846dc776ac0f014572ea79f5607734"} +}; + + +#else +# define TEST_UNSUPPORTED +# include "common.h" +#endif + + +static int +main_test(void) +{ + TEST_MAIN("SHAKE128", SHAKE128); +} + + +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_shake128_hasher(&hasher, 8)); + ASSERT(!strcmp(hasher.algorithm_string, "SHAKE128[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, "7f")); + + ASSERT(!libhashsum_init_shake128_hasher(&hasher, 32)); + ASSERT(!strcmp(hasher.algorithm_string, "SHAKE128[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, "7f9c2ba4")); + + ASSERT(!libhashsum_init_shake128_hasher(&hasher, 32)); + ASSERT(!strcmp(hasher.algorithm_string, "SHAKE128[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, "131ab8d2")); + + ASSERT(!libhashsum_init_shake128_hasher(&hasher, 128)); + ASSERT(!strcmp(hasher.algorithm_string, "SHAKE128")); + 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, "131ab8d2b594946b9c81333f9bb6e0ce")); + + ASSERT(!libhashsum_init_shake128_hasher(&hasher, 256)); + ASSERT(!strcmp(hasher.algorithm_string, "SHAKE128[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, "131ab8d2b594946b9c81333f9bb6e0ce75c3b93104fa3469d3917457385da037")); + + return 0; +} diff --git a/shake256.c b/shake256.c new file mode 100644 index 0000000..38c9b40 --- /dev/null +++ b/shake256.c @@ -0,0 +1,89 @@ +/* See LICENSE file for copyright and license details. */ +#ifdef SUPPORT_SHAKE +# define TEST +# include "common.h" + + +#define MSG5 "\x13" +#define MSG30 "\x53\x58\x7B\x19" +#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 +#define MSG1605 MSG1600_800 MSG1600_800 "\x03" +#define MSG1630 MSG1600_800 MSG1600_800 "\xA3\xA3\xA3\x23" + + +static struct testcase testcases[] = { + {1, 0, "", "46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762f"}, + {1, 5, MSG5, "48a5c11abaeeff092f3646ef0d6b3d3ff76c2f55f9c732ac6470c03764008212"}, + {1, 6, MSG30, "465d081dff875e396200e4481a3e9dcd88d079aa6d66226cb6ba454107cb81a7"}, + {1, 0, MSG1600, "cd8a920ed141aa0407a22d59288652e9d9f1a7ee0c1e7c1ca699424da84a904d"}, + {1, 5, MSG1605, "98d093b067475760124ffb9204a5b327c6bb05c54ff234f0b43fac7240415166"}, + {1, 6, MSG1630, "8a8325079b0fc3265d52f59855cafe655df438aa639f6fec991f2494330ce32f"} +}; + + +#else +# define TEST_UNSUPPORTED +# include "common.h" +#endif + + +static int +main_test(void) +{ + TEST_MAIN("SHAKE256", SHAKE256); +} + + +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_shake256_hasher(&hasher, 8)); + ASSERT(!strcmp(hasher.algorithm_string, "SHAKE256[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, "46")); + + ASSERT(!libhashsum_init_shake256_hasher(&hasher, 32)); + ASSERT(!strcmp(hasher.algorithm_string, "SHAKE256[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, "46b9dd2b")); + + ASSERT(!libhashsum_init_shake256_hasher(&hasher, 32)); + ASSERT(!strcmp(hasher.algorithm_string, "SHAKE256[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, "cd8a920e")); + + ASSERT(!libhashsum_init_shake256_hasher(&hasher, 256)); + ASSERT(!strcmp(hasher.algorithm_string, "SHAKE256")); + 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, "cd8a920ed141aa0407a22d59288652e9d9f1a7ee0c1e7c1ca699424da84a904d")); + + ASSERT(!libhashsum_init_shake256_hasher(&hasher, 512)); + ASSERT(!strcmp(hasher.algorithm_string, "SHAKE256[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, "cd8a920ed141aa0407a22d59288652e9d9f1a7ee0c1e7c1ca699424da84a904d" + "2d700caae7396ece96604440577da4f3aa22aeb8857f961c4cd8e06f0ae6610b")); + + return 0; +} diff --git a/shake512.c b/shake512.c new file mode 100644 index 0000000..ac6e951 --- /dev/null +++ b/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; +} |