aboutsummaryrefslogtreecommitdiffstats
path: root/rawshake512.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-09-01 09:56:49 +0200
committerMattias Andrée <maandree@kth.se>2024-09-01 09:56:49 +0200
commit5caa621d9e0c3fc3893b0b94efe1503fcd6a5c88 (patch)
tree8494e1940f082441a06ad35e55d6e874d9855001 /rawshake512.c
parentMore testing (diff)
downloadlibhashsum-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 'rawshake512.c')
-rw-r--r--rawshake512.c88
1 files changed, 88 insertions, 0 deletions
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;
+}