aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile52
-rw-r--r--README6
-rw-r--r--common.h23
-rw-r--r--config.mk24
-rw-r--r--keccak_224.c22
-rw-r--r--keccak_256.c22
-rw-r--r--keccak_384.c22
-rw-r--r--keccak_512.c24
-rw-r--r--libhashsum.h485
-rw-r--r--libhashsum_init_hasher.c29
-rw-r--r--libhashsum_init_hasher_from_string.c129
-rw-r--r--libhashsum_init_keccak_224_hasher.c9
-rw-r--r--libhashsum_init_keccak_256_hasher.c9
-rw-r--r--libhashsum_init_keccak_384_hasher.c9
-rw-r--r--libhashsum_init_keccak_512_hasher.c9
-rw-r--r--libhashsum_init_keccak__.c148
-rw-r--r--libhashsum_init_keccak_hasher.c75
-rw-r--r--libhashsum_init_md2_hasher.c1
-rw-r--r--libhashsum_init_md4_hasher.c1
-rw-r--r--libhashsum_init_md5_hasher.c1
-rw-r--r--libhashsum_init_rawshake128_hasher.c9
-rw-r--r--libhashsum_init_rawshake256_hasher.c9
-rw-r--r--libhashsum_init_rawshake512_hasher.c9
-rw-r--r--libhashsum_init_rawshake_hasher.c52
-rw-r--r--libhashsum_init_ripemd_128_hasher.c1
-rw-r--r--libhashsum_init_ripemd_160_hasher.c1
-rw-r--r--libhashsum_init_ripemd_256_hasher.c1
-rw-r--r--libhashsum_init_ripemd_320_hasher.c1
-rw-r--r--libhashsum_init_sha0_hasher.c1
-rw-r--r--libhashsum_init_sha1_hasher.c1
-rw-r--r--libhashsum_init_sha2_hasher.c1
-rw-r--r--libhashsum_init_sha3_224_hasher.c9
-rw-r--r--libhashsum_init_sha3_256_hasher.c9
-rw-r--r--libhashsum_init_sha3_384_hasher.c9
-rw-r--r--libhashsum_init_sha3_512_hasher.c9
-rw-r--r--libhashsum_init_sha3_hasher.c42
-rw-r--r--libhashsum_init_shake128_hasher.c9
-rw-r--r--libhashsum_init_shake256_hasher.c9
-rw-r--r--libhashsum_init_shake512_hasher.c9
-rw-r--r--libhashsum_init_shake_hasher.c52
l---------mk/keccak=no.mk1
-rw-r--r--mk/keccak=yes.mk4
l---------mk/rawshake=no.mk1
-rw-r--r--mk/rawshake=yes.mk4
l---------mk/sha3=no.mk1
-rw-r--r--mk/sha3=yes.mk4
l---------mk/shake=no.mk1
-rw-r--r--mk/shake=yes.mk4
-rw-r--r--sha3_224.c352
-rw-r--r--sha3_256.c22
-rw-r--r--sha3_384.c22
-rw-r--r--sha3_512.c24
52 files changed, 1750 insertions, 33 deletions
diff --git a/Makefile b/Makefile
index 039c15b..fd52be7 100644
--- a/Makefile
+++ b/Makefile
@@ -14,6 +14,10 @@ SUPPORT_RIPEMD_128 = $(DEFAULT_SUPPORT)
SUPPORT_RIPEMD_160 = $(DEFAULT_SUPPORT)
SUPPORT_RIPEMD_256 = $(DEFAULT_SUPPORT)
SUPPORT_RIPEMD_320 = $(DEFAULT_SUPPORT)
+SUPPORT_KECCAK = $(DEFAULT_SUPPORT)
+SUPPORT_SHA3 = $(DEFAULT_SUPPORT)
+SUPPORT_SHAKE = $(DEFAULT_SUPPORT)
+SUPPORT_RAWSHAKE = $(DEFAULT_SUPPORT)
CONFIGFILE = config.mk
@@ -32,6 +36,9 @@ LIB_VERSION = $(LIB_MAJOR).$(LIB_MINOR)
LIB_NAME = hashsum
+CPPFLAGS_LIBKECCAK_IF_SUPPORTED =
+LDFLAGS_LIBKECCAK_IF_SUPPORTED =
+
include mk/md2=$(SUPPORT_MD2).mk
include mk/md4=$(SUPPORT_MD4).mk
include mk/md5=$(SUPPORT_MD5).mk
@@ -41,6 +48,10 @@ include mk/ripemd-256=$(SUPPORT_RIPEMD_256).mk
include mk/ripemd-320=$(SUPPORT_RIPEMD_320).mk
include mk/sha1=$(SUPPORT_SHA1).mk
include mk/sha2=$(SUPPORT_SHA2).mk
+include mk/keccak=$(SUPPORT_KECCAK).mk
+include mk/sha3=$(SUPPORT_SHA3).mk
+include mk/shake=$(SUPPORT_SHAKE).mk
+include mk/rawshake=$(SUPPORT_RAWSHAKE).mk
CPPFLAGS_FULL =\
@@ -53,12 +64,18 @@ CPPFLAGS_FULL =\
$(CPPFLAGS_RIPEMD_256)\
$(CPPFLAGS_RIPEMD_320)\
$(CPPFLAGS_SHA1)\
- $(CPPFLAGS_SHA2)
+ $(CPPFLAGS_SHA2)\
+ $(CPPFLAGS_LIBKECCAK_IF_SUPPORTED)\
+ $(CPPFLAGS_KECCAK)\
+ $(CPPFLAGS_SHA3)\
+ $(CPPFLAGS_SHAKE)\
+ $(CPPFLAGS_RAWSHAKE)
LDFLAGS_FULL =\
$(LDFLAGS)\
$(LDFLAGS_SHA1)\
- $(LDFLAGS_SHA2)
+ $(LDFLAGS_SHA2)\
+ $(LDFLAGS_LIBKECCAK_IF_SUPPORTED)
OBJ =\
@@ -80,7 +97,26 @@ OBJ =\
libhashsum_init_sha_512_224_hasher.o\
libhashsum_init_sha_512_256_hasher.o\
libhashsum_init_sha2_hasher.o\
- libhashsum_reverse_byte__.o
+ libhashsum_init_keccak_224_hasher.o\
+ libhashsum_init_keccak_256_hasher.o\
+ libhashsum_init_keccak_384_hasher.o\
+ libhashsum_init_keccak_512_hasher.o\
+ libhashsum_init_keccak_hasher.o\
+ libhashsum_init_sha3_224_hasher.o\
+ libhashsum_init_sha3_256_hasher.o\
+ libhashsum_init_sha3_384_hasher.o\
+ libhashsum_init_sha3_512_hasher.o\
+ libhashsum_init_sha3_hasher.o\
+ libhashsum_init_shake128_hasher.o\
+ libhashsum_init_shake256_hasher.o\
+ libhashsum_init_shake512_hasher.o\
+ libhashsum_init_shake_hasher.o\
+ libhashsum_init_rawshake128_hasher.o\
+ libhashsum_init_rawshake256_hasher.o\
+ libhashsum_init_rawshake512_hasher.o\
+ libhashsum_init_rawshake_hasher.o\
+ libhashsum_reverse_byte__.o\
+ libhashsum_init_keccak__.o
HDR =\
libhashsum.h\
@@ -101,7 +137,15 @@ TEST =\
sha_384.t\
sha_512.t\
sha_512_224.t\
- sha_512_256.t
+ sha_512_256.t\
+ keccak_224.t\
+ keccak_256.t\
+ keccak_384.t\
+ keccak_512.t\
+ sha3_224.t\
+ sha3_256.t\
+ sha3_384.t\
+ sha3_512.t
LOBJ = $(OBJ:.o=.lo)
TOBJ = $(TEST:.t=.o)
diff --git a/README b/README
index 9f5d46e..b35360f 100644
--- a/README
+++ b/README
@@ -17,6 +17,12 @@ DESCRIPTION
SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224,
SHA-512/256
+ Via libkeccak>=1.3
+ Keccak[], Keccak-224, Keccak-256, Keccak-384,
+ Keccak-512, SHA3-224, SHA3-256, SHA3-384, SHA3-512,
+ SHAKE128, SHAKE256, SHAKE512, RawSHAKE128,
+ RawSHAKE256, RawSHAKE512
+
libhashsum makes it easy to select at compile-time which
functions to compile support for.
diff --git a/common.h b/common.h
index 2df927b..903a0e9 100644
--- a/common.h
+++ b/common.h
@@ -5,10 +5,23 @@
# pragma clang diagnostic ignored "-Wcomma"
# pragma clang diagnostic ignored "-Wcovered-switch-default"
#endif
+
+#if defined(SUPPORT_SHA0) || defined(SUPPORT_SHA1)
+# define LIBHASHSUM_INCLUDE_LIBSHA1_STATE
+#endif
+#if defined(SUPPORT_SHA2)
+# define LIBHASHSUM_INCLUDE_LIBSHA2_STATE
+#endif
+#if defined(SUPPORT_KECCAK) || defined(SUPPORT_SHA3) || defined(SUPPORT_SHAKE) || defined(SUPPORT_RAWSHAKE)
+# define LIBHASHSUM_INCLUDE_LIBKECCAK_STATE
+#endif
+
#include "libhashsum.h"
#include <ctype.h>
#include <errno.h>
#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
@@ -17,10 +30,14 @@ __attribute__((__const__))
#endif
uint8_t libhashsum_reverse_byte__(uint8_t);
+#ifdef LIBHASHSUM_INCLUDE_LIBKECCAK_STATE
+int libhashsum_init_keccak__(struct libhashsum_hasher *this, size_t hashbits, void *spec, const char *suffix);
+#endif
+
+#define KECCAKN(N) 1600 - 2 * (N), 2 * (N), (N)
+
#ifdef TEST
-# include <stdlib.h>
-# include <stdio.h>
struct testcase {
size_t input_repeat;
@@ -181,6 +198,8 @@ run_tests(const char *name, enum libhashsum_algorithm algorithm, size_t hash_siz
fprintf(stderr, "[\033[1;%s\033[m] %s(%zu * \"%s\"%s) = %s\n",
caseok ? "32mPASS" : "31mFAIL", name, testcases[i].input_repeat, input, bitstr, hexsum);
free(input);
+ if (hasher.destroy)
+ hasher.destroy(&hasher);
}
return !ok;
}
diff --git a/config.mk b/config.mk
index 5b5e94f..2e3e31a 100644
--- a/config.mk
+++ b/config.mk
@@ -14,17 +14,14 @@ CPPFLAGS_LIBSHA1 =
LDFLAGS_LIBSHA2 = -lsha2
CPPFLAGS_LIBSHA2 =
+LDFLAGS_LIBKECCAK = -lkeccak
+CPPFLAGS_LIBKECCAK =
+
DEFAULT_SUPPORT = yes
# Shall either be "yes" or "no", the same applies below where this macro is used
-SUPPORT_SHA1 = $(DEFAULT_SUPPORT)
-# Includes SHA0 and SHA1, requires libsha1
-
-SUPPORT_SHA2 = $(DEFAULT_SUPPORT)
-# Includes SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256, requires libsha2
-
SUPPORT_MD2 = $(DEFAULT_SUPPORT)
# Support is built in
@@ -45,3 +42,18 @@ SUPPORT_RIPEMD_256 = $(DEFAULT_SUPPORT)
SUPPORT_RIPEMD_320 = $(DEFAULT_SUPPORT)
# Support is built in
+
+SUPPORT_SHA1 = $(DEFAULT_SUPPORT)
+# Includes SHA0 and SHA1, requires libsha1
+
+SUPPORT_SHA2 = $(DEFAULT_SUPPORT)
+# Includes SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256, requires libsha2
+
+SUPPORT_SHA3 = $(DEFAULT_SUPPORT)
+# Includes SHA3-224, SHA3-256, SHA3-384, and SHA3-512, requires libkeccak>=1.2
+
+SUPPORT_SHAKE = $(DEFAULT_SUPPORT)
+# Includes SHAKE224, SHAKE256, SHAKE384, and SHAKE512, requires libkeccak>=1.2
+
+SUPPORT_RAWSHAKE = $(DEFAULT_SUPPORT)
+# Includes RawSHAKE224, RawSHAKE256, RawSHAKE384, and RawSHAKE512, requires libkeccak>=1.2
diff --git a/keccak_224.c b/keccak_224.c
new file mode 100644
index 0000000..64546ba
--- /dev/null
+++ b/keccak_224.c
@@ -0,0 +1,22 @@
+/* See LICENSE file for copyright and license details. */
+#ifdef SUPPORT_KECCAK
+# define TEST
+# include "common.h"
+
+
+static struct testcase testcases[] = {
+ {1, 0, "", "f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd"},
+};
+
+
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
+int
+main(void)
+{
+ TEST_MAIN("Keccak-224", KECCAK_224);
+}
diff --git a/keccak_256.c b/keccak_256.c
new file mode 100644
index 0000000..b232d1d
--- /dev/null
+++ b/keccak_256.c
@@ -0,0 +1,22 @@
+/* See LICENSE file for copyright and license details. */
+#ifdef SUPPORT_KECCAK
+# define TEST
+# include "common.h"
+
+
+static struct testcase testcases[] = {
+ {1, 0, "", "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"},
+};
+
+
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
+int
+main(void)
+{
+ TEST_MAIN("Keccak-256", KECCAK_256);
+}
diff --git a/keccak_384.c b/keccak_384.c
new file mode 100644
index 0000000..3884526
--- /dev/null
+++ b/keccak_384.c
@@ -0,0 +1,22 @@
+/* See LICENSE file for copyright and license details. */
+#ifdef SUPPORT_KECCAK
+# define TEST
+# include "common.h"
+
+
+static struct testcase testcases[] = {
+ {1, 0, "", "2c23146a63a29acf99e73b88f8c24eaa7dc60aa771780ccc006afbfa8fe2479b2dd2b21362337441ac12b515911957ff"},
+};
+
+
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
+int
+main(void)
+{
+ TEST_MAIN("Keccak-384", KECCAK_384);
+}
diff --git a/keccak_512.c b/keccak_512.c
new file mode 100644
index 0000000..a617a52
--- /dev/null
+++ b/keccak_512.c
@@ -0,0 +1,24 @@
+/* See LICENSE file for copyright and license details. */
+#ifdef SUPPORT_KECCAK
+# define TEST
+# include "common.h"
+
+
+static struct testcase testcases[] = {
+ {1, 0, "",
+ "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304"
+ "c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e"},
+};
+
+
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
+int
+main(void)
+{
+ TEST_MAIN("Keccak-512", KECCAK_512);
+}
diff --git a/libhashsum.h b/libhashsum.h
index 67f27b4..e7050c1 100644
--- a/libhashsum.h
+++ b/libhashsum.h
@@ -5,8 +5,15 @@
#include <stddef.h>
#include <stdint.h>
-#include <libsha1.h>
-#include <libsha2.h>
+#ifdef LIBHASHSUM_INCLUDE_LIBSHA1_STATE
+# include <libsha1.h>
+#endif
+#ifdef LIBHASHSUM_INCLUDE_LIBSHA2_STATE
+# include <libsha2.h>
+#endif
+#ifdef LIBHASHSUM_INCLUDE_LIBKECCAK_STATE
+# include <libkeccak.h>
+#endif
#if defined(__GNUC__)
@@ -27,21 +34,36 @@
*/
enum libhashsum_algorithm {
/* since 1.0 */
- LIBHASHSUM_MD2, /**< MD2 */
- LIBHASHSUM_MD4, /**< MD4 */
- LIBHASHSUM_MD5, /**< MD5; this algorithm has been compromised */
- LIBHASHSUM_RIPEMD_128, /**< RIPEMD-128 */
- LIBHASHSUM_RIPEMD_160, /**< RIPEMD-160 */
- LIBHASHSUM_RIPEMD_256, /**< RIPEMD-256 */
- LIBHASHSUM_RIPEMD_320, /**< RIPEMD-320 */
- LIBHASHSUM_SHA0, /**< SHA0; this algorithm has been compromised */
- LIBHASHSUM_SHA1, /**< SHA1; this algorithm has been compromised */
- LIBHASHSUM_SHA_224, /**< SHA-224 (SHA2) */
- LIBHASHSUM_SHA_256, /**< SHA-256 (SHA2) */
- LIBHASHSUM_SHA_384, /**< SHA-384 (SHA2) */
- LIBHASHSUM_SHA_512, /**< SHA-512 (SHA2) */
- LIBHASHSUM_SHA_512_224, /**< SHA-512/224 (SHA2) */
- LIBHASHSUM_SHA_512_256 /**< SHA-512/256 (SHA2) */
+ LIBHASHSUM_MD2, /**< MD2 */
+ LIBHASHSUM_MD4, /**< MD4 */
+ LIBHASHSUM_MD5, /**< MD5; this algorithm has been compromised */
+ LIBHASHSUM_RIPEMD_128, /**< RIPEMD-128 */
+ LIBHASHSUM_RIPEMD_160, /**< RIPEMD-160 */
+ LIBHASHSUM_RIPEMD_256, /**< RIPEMD-256 */
+ LIBHASHSUM_RIPEMD_320, /**< RIPEMD-320 */
+ LIBHASHSUM_SHA0, /**< SHA0; this algorithm has been compromised */
+ LIBHASHSUM_SHA1, /**< SHA1; this algorithm has been compromised */
+ LIBHASHSUM_SHA_224, /**< SHA-224 (SHA2) */
+ LIBHASHSUM_SHA_256, /**< SHA-256 (SHA2) */
+ LIBHASHSUM_SHA_384, /**< SHA-384 (SHA2) */
+ LIBHASHSUM_SHA_512, /**< SHA-512 (SHA2) */
+ LIBHASHSUM_SHA_512_224, /**< SHA-512/224 (SHA2) */
+ LIBHASHSUM_SHA_512_256, /**< SHA-512/256 (SHA2) */
+ LIBHASHSUM_KECCAK, /**< Keccak[] */
+ LIBHASHSUM_KECCAK_224, /**< Keccak-224 */
+ LIBHASHSUM_KECCAK_256, /**< Keccak-256 */
+ LIBHASHSUM_KECCAK_384, /**< Keccak-384 */
+ LIBHASHSUM_KECCAK_512, /**< Keccak-512 */
+ LIBHASHSUM_SHA3_224, /**< SHA3-224 */
+ LIBHASHSUM_SHA3_256, /**< SHA3-256 */
+ LIBHASHSUM_SHA3_384, /**< SHA3-384 */
+ LIBHASHSUM_SHA3_512, /**< SHA3-512 */
+ LIBHASHSUM_SHAKE128 , /**< SHAKE128 */
+ LIBHASHSUM_SHAKE256, /**< SHAKE256 */
+ LIBHASHSUM_SHAKE512, /**< SHAKE512 */
+ LIBHASHSUM_RAWSHAKE128, /**< RawSHAKE128 */
+ LIBHASHSUM_RAWSHAKE256, /**< RawSHAKE256 */
+ LIBHASHSUM_RAWSHAKE512 /**< RawSHAKE512 */
};
@@ -150,6 +172,104 @@ enum libhashsum_algorithm {
*/
#define LIBHASHSUM_SHA_512_256_HASH_SIZE 32
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHA3_224`
+ *
+ * @since 1.0
+ */
+#define LIBHASHSUM_KECCAK_224_HASH_SIZE 28
+
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_KECCAK_256`
+ *
+ * @since 1.0
+ */
+#define LIBHASHSUM_KECCAK_256_HASH_SIZE 32
+
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_KECCAK_384`
+ *
+ * @since 1.0
+ */
+#define LIBHASHSUM_KECCAK_384_HASH_SIZE 48
+
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_KECCAK_512`
+ *
+ * @since 1.0
+ */
+#define LIBHASHSUM_KECCAK_512_HASH_SIZE 64
+
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHA3_224`
+ *
+ * @since 1.0
+ */
+#define LIBHASHSUM_SHA3_224_HASH_SIZE 28
+
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHA3_256`
+ *
+ * @since 1.0
+ */
+#define LIBHASHSUM_SHA3_256_HASH_SIZE 32
+
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHA3_384`
+ *
+ * @since 1.0
+ */
+#define LIBHASHSUM_SHA3_384_HASH_SIZE 48
+
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHA3_512`
+ *
+ * @since 1.0
+ */
+#define LIBHASHSUM_SHA3_512_HASH_SIZE 64
+
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHAKE_128`
+ *
+ * @since 1.0
+ */
+#define LIBHASHSUM_SHAKE_128_HASH_SIZE 28
+
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHAKE_256`
+ *
+ * @since 1.0
+ */
+#define LIBHASHSUM_SHAKE_256_HASH_SIZE 32
+
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHAKE_512`
+ *
+ * @since 1.0
+ */
+#define LIBHASHSUM_SHAKE_512_HASH_SIZE 64
+
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_RAWSHAKE_128`
+ *
+ * @since 1.0
+ */
+#define LIBHASHSUM_RAWSHAKE_128_HASH_SIZE 28
+
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_RAWSHAKE_256`
+ *
+ * @since 1.0
+ */
+#define LIBHASHSUM_RAWSHAKE_256_HASH_SIZE 32
+
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_RAWSHAKE_512`
+ *
+ * @since 1.0
+ */
+#define LIBHASHSUM_RAWSHAKE_512_HASH_SIZE 64
+
/**
* Hash state
@@ -239,17 +359,32 @@ union libhashsum_state {
uint64_t count;
} ripemd_320; /* size = 152 */
+#ifdef LIBHASHSUM_INCLUDE_LIBSHA1_STATE
struct {
struct libsha1_state s;
uint8_t sum[20];
} sha0, sha1; /* size = [432, 440] */
+#endif
+#ifdef LIBHASHSUM_INCLUDE_LIBSHA2_STATE
struct {
struct libsha2_state s;
uint8_t sum[64];
} sha2; /* size = [1612, 1624] */
+#endif
+
+#ifdef LIBHASHSUM_INCLUDE_LIBKECCAK_STATE
+ struct {
+ struct libkeccak_state s;
+ union {
+ uint8_t buf[512];
+ uint8_t *dyn;
+ } sum;
+ const char *suffix;
+ char algostr[256];
+ } keccak; /* size = [1020, 1065] */
+#endif
- /* libkeccak: size = [248, 288] */
/* libblake: size = 56(s), 112(b), 48(2s), 96(2b), 144(2Xs), 276(2Xb) */
char max_size[1648];
@@ -384,6 +519,18 @@ struct libhashsum_hasher {
int (*finalise)(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extra_bits, size_t size);
/**
+ * Unless this pointer its `NULL`, it points to
+ * function that shall be once the object (`this`)
+ * is not needed anymore
+ *
+ * @param this The object containing this function pointer
+ *
+ * @since 1.0
+ */
+ LIBHASHSUM_1_NONNULL_
+ void (*destroy)(struct libhashsum_hasher *this);
+
+ /**
* The hash state
*
* For internal use
@@ -405,7 +552,7 @@ struct libhashsum_hasher {
* @throws EINVAL `algorithm` is not recognised
* @throws EINVAL `algorithm` requires parameters, and is therefore
* not supported by this function (use dedicated
- * initialiser instead)
+ * initialiser instead). (`algorithm` is `LIBHASHSUM_KECCAK`)
* @throws ENOSYS Support for `algorithm` was excluded at compile time
* @throws ENOSYS The `algorithm` requires a newer version of the library
* that application was compiled for (the application
@@ -413,6 +560,7 @@ struct libhashsum_hasher {
* (specifically this means that the application's version
* of `union libhashsum_state`, and thus also
* `struct libhashsum_hasher`, is too small to store the state)
+ * @throws ENOMEM Not enough memory available
*
* @since 1.0
*/
@@ -435,6 +583,7 @@ int libhashsum_init_hasher(struct libhashsum_hasher *this, enum libhashsum_algor
* (specifically this means that the application's version
* of `union libhashsum_state`, and thus also
* `struct libhashsum_hasher`, is too small to store the state)
+ * @throws ENOMEM Not enough memory available
*
* @since 1.0
*/
@@ -671,5 +820,303 @@ int libhashsum_init_sha_512_256_hasher(struct libhashsum_hasher *this);
LIBHASHSUM_1_NONNULL_
int libhashsum_init_sha2_hasher(struct libhashsum_hasher *this, unsigned algobits, size_t hashbits);
+/**
+ * Create an initialised state for Keccak-224
+ * hashing and return hash functions and details
+ *
+ * @param this The output parameter for the functions, details, and state
+ * @return 0 on success, -1 on failure
+ *
+ * @throws ENOSYS Support was excluded at compile time
+ * @throws ENOMEM Not enough memory available
+ *
+ * @since 1.0
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_keccak_224_hasher(struct libhashsum_hasher *this);
+
+/**
+ * Create an initialised state for Keccak-256
+ * hashing and return hash functions and details
+ *
+ * @param this The output parameter for the functions, details, and state
+ * @return 0 on success, -1 on failure
+ *
+ * @throws ENOSYS Support was excluded at compile time
+ * @throws ENOMEM Not enough memory available
+ *
+ * @since 1.0
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_keccak_256_hasher(struct libhashsum_hasher *this);
+
+/**
+ * Create an initialised state for Keccak-384
+ * hashing and return hash functions and details
+ *
+ * @param this The output parameter for the functions, details, and state
+ * @return 0 on success, -1 on failure
+ *
+ * @throws ENOSYS Support was excluded at compile time
+ * @throws ENOMEM Not enough memory available
+ *
+ * @since 1.0
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_keccak_384_hasher(struct libhashsum_hasher *this);
+
+/**
+ * Create an initialised state for Keccak-512
+ * hashing and return hash functions and details
+ *
+ * @param this The output parameter for the functions, details, and state
+ * @return 0 on success, -1 on failure
+ *
+ * @throws ENOSYS Support was excluded at compile time
+ * @throws ENOMEM Not enough memory available
+ *
+ * @since 1.0
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_keccak_512_hasher(struct libhashsum_hasher *this);
+
+/**
+ * Create an initialised state for Keccak
+ * hashing and return hash functions and details
+ *
+ * @param this The output parameter for the functions, details, and state
+ * @param ratebits Bitrate (in bits), 0 for automatic
+ * @param capbits Capacity in bits, 0 for automatic
+ * @param hashbits Hash output size in bits, 0 for automatic
+ * @return 0 on success, -1 on failure
+ *
+ * @throws EINVAL (`ratebits`, `capbits`, `hashbits`) is invalid
+ * @throws ENOSYS Support was excluded at compile time
+ * @throws ENOMEM Not enough memory available
+ *
+ * @since 1.0
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_keccak_hasher(struct libhashsum_hasher *this, size_t ratebits, size_t capbits, size_t hashbits);
+
+/**
+ * Create an initialised state for SHA3-224
+ * hashing and return hash functions and details
+ *
+ * @param this The output parameter for the functions, details, and state
+ * @return 0 on success, -1 on failure
+ *
+ * @throws ENOSYS Support was excluded at compile time
+ * @throws ENOMEM Not enough memory available
+ *
+ * @since 1.0
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_sha3_224_hasher(struct libhashsum_hasher *this);
+
+/**
+ * Create an initialised state for SHA3-256
+ * hashing and return hash functions and details
+ *
+ * @param this The output parameter for the functions, details, and state
+ * @return 0 on success, -1 on failure
+ *
+ * @throws ENOSYS Support was excluded at compile time
+ * @throws ENOMEM Not enough memory available
+ *
+ * @since 1.0
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_sha3_256_hasher(struct libhashsum_hasher *this);
+
+/**
+ * Create an initialised state for SHA3-384
+ * hashing and return hash functions and details
+ *
+ * @param this The output parameter for the functions, details, and state
+ * @return 0 on success, -1 on failure
+ *
+ * @throws ENOSYS Support was excluded at compile time
+ * @throws ENOMEM Not enough memory available
+ *
+ * @since 1.0
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_sha3_384_hasher(struct libhashsum_hasher *this);
+
+/**
+ * Create an initialised state for SHA3-512
+ * hashing and return hash functions and details
+ *
+ * @param this The output parameter for the functions, details, and state
+ * @return 0 on success, -1 on failure
+ *
+ * @throws ENOSYS Support was excluded at compile time
+ * @throws ENOMEM Not enough memory available
+ *
+ * @since 1.0
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_sha3_512_hasher(struct libhashsum_hasher *this);
+
+/**
+ * Create an initialised state for SHA3
+ * hashing and return hash functions and details
+ *
+ * @param this The output parameter for the functions, details, and state
+ * @param hashbits Hash output size in bits
+ * @return 0 on success, -1 on failure
+ *
+ * @throws EINVAL `hashbits` is invalid (neither 224, 256, 384, nor 512)
+ * @throws ENOSYS Support was excluded at compile time
+ * @throws ENOMEM Not enough memory available
+ *
+ * @since 1.0
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_sha3_hasher(struct libhashsum_hasher *this, size_t hashbits);
+
+/**
+ * Create an initialised state for SHAKE128
+ * hashing and return hash functions and details
+ *
+ * @param this The output parameter for the functions, details, and state
+ * @param hashbits Hash output size in bits, if 0, 128 is used
+ * @return 0 on success, -1 on failure
+ *
+ * @throws EINVAL `hashbits` is too large
+ * @throws ENOSYS Support was excluded at compile time
+ * @throws ENOMEM Not enough memory available
+ *
+ * @since 1.0
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_shake128_hasher(struct libhashsum_hasher *this, size_t hashbits);
+
+/**
+ * Create an initialised state for SHAKE256
+ * hashing and return hash functions and details
+ *
+ * @param this The output parameter for the functions, details, and state
+ * @param hashbits Hash output size in bits, if 0, 256 is used
+ * @return 0 on success, -1 on failure
+ *
+ * @throws EINVAL `hashbits` is too large
+ * @throws ENOSYS Support was excluded at compile time
+ * @throws ENOMEM Not enough memory available
+ *
+ * @since 1.0
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_shake256_hasher(struct libhashsum_hasher *this, size_t hashbits);
+
+/**
+ * Create an initialised state for SHAKE512
+ * hashing and return hash functions and details
+ *
+ * @param this The output parameter for the functions, details, and state
+ * @param hashbits Hash output size in bits, if 0, 512 is used
+ * @return 0 on success, -1 on failure
+ *
+ * @throws EINVAL `hashbits` is too large
+ * @throws ENOSYS Support was excluded at compile time
+ * @throws ENOMEM Not enough memory available
+ *
+ * @since 1.0
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_shake512_hasher(struct libhashsum_hasher *this, size_t hashbits);
+
+/**
+ * Create an initialised state for SHAKE
+ * hashing and return hash functions and details
+ *
+ * @param this The output parameter for the functions, details, and state
+ * @param hcapbits Half of the capacity, in bits (this is the
+ * value added behind the function name)
+ * @param hashbits Hash output size in bits, if 0, `hcapbits` is used
+ * @return 0 on success, -1 on failure
+ *
+ * @throws EINVAL `hcapbits` is invalid (neither 128, 256, nor 512)
+ * @throws EINVAL `hashbits` is too large
+ * @throws ENOSYS Support was excluded at compile time
+ * @throws ENOMEM Not enough memory available
+ *
+ * @since 1.0
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_shake_hasher(struct libhashsum_hasher *this, size_t hcapbits, size_t hashbits);
+
+/**
+ * Create an initialised state for RawSHAKE128
+ * hashing and return hash functions and details
+ *
+ * @param this The output parameter for the functions, details, and state
+ * @param hashbits Hash output size in bits, if 0, 128 is used
+ * @return 0 on success, -1 on failure
+ *
+ * @throws EINVAL `hashbits` is too large
+ * @throws ENOSYS Support was excluded at compile time
+ * @throws ENOMEM Not enough memory available
+ *
+ * @since 1.0
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_rawshake128_hasher(struct libhashsum_hasher *this, size_t hashbits);
+
+/**
+ * Create an initialised state for RawSHAKE256
+ * hashing and return hash functions and details
+ *
+ * @param this The output parameter for the functions, details, and state
+ * @param hashbits Hash output size in bits, if 0, 256 is used
+ * @return 0 on success, -1 on failure
+ *
+ * @throws EINVAL `hashbits` is too large
+ * @throws ENOSYS Support was excluded at compile time
+ * @throws ENOMEM Not enough memory available
+ *
+ * @since 1.0
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_rawshake256_hasher(struct libhashsum_hasher *this, size_t hashbits);
+
+/**
+ * Create an initialised state for RawSHAKE512
+ * hashing and return hash functions and details
+ *
+ * @param this The output parameter for the functions, details, and state
+ * @param hashbits Hash output size in bits, if 0, 512 is used
+ * @return 0 on success, -1 on failure
+ *
+ * @throws EINVAL `hashbits` is too large
+ * @throws ENOSYS Support was excluded at compile time
+ * @throws ENOMEM Not enough memory available
+ *
+ * @since 1.0
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_rawshake512_hasher(struct libhashsum_hasher *this, size_t hashbits);
+
+/**
+ * Create an initialised state for RawSHAKE
+ * hashing and return hash functions and details
+ *
+ * @param this The output parameter for the functions, details, and state
+ * @param hcapbits Half of the capacity, in bits (this is the
+ * value added behind the function name)
+ * @param hashbits Hash output size in bits, if 0, `hcapbits` is used
+ * @return 0 on success, -1 on failure
+ *
+ * @throws EINVAL `hcapbits` is invalid (neither 128, 256, nor 512)
+ * @throws EINVAL `hashbits` is too large
+ * @throws ENOSYS Support was excluded at compile time
+ * @throws ENOMEM Not enough memory available
+ *
+ * @since 1.0
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_rawshake_hasher(struct libhashsum_hasher *this, size_t hcapbits, size_t hashbits);
+
#endif
diff --git a/libhashsum_init_hasher.c b/libhashsum_init_hasher.c
index 3f99e6c..3d8a521 100644
--- a/libhashsum_init_hasher.c
+++ b/libhashsum_init_hasher.c
@@ -36,7 +36,36 @@ libhashsum_init_hasher(struct libhashsum_hasher *this, enum libhashsum_algorithm
return libhashsum_init_sha_512_224_hasher(this);
case LIBHASHSUM_SHA_512_256:
return libhashsum_init_sha_512_256_hasher(this);
+ case LIBHASHSUM_KECCAK_224:
+ return libhashsum_init_keccak_224_hasher(this);
+ case LIBHASHSUM_KECCAK_256:
+ return libhashsum_init_keccak_256_hasher(this);
+ case LIBHASHSUM_KECCAK_384:
+ return libhashsum_init_keccak_384_hasher(this);
+ case LIBHASHSUM_KECCAK_512:
+ return libhashsum_init_keccak_512_hasher(this);
+ case LIBHASHSUM_SHA3_224:
+ return libhashsum_init_sha3_224_hasher(this);
+ case LIBHASHSUM_SHA3_256:
+ return libhashsum_init_sha3_256_hasher(this);
+ case LIBHASHSUM_SHA3_384:
+ return libhashsum_init_sha3_384_hasher(this);
+ case LIBHASHSUM_SHA3_512:
+ return libhashsum_init_sha3_512_hasher(this);
+ case LIBHASHSUM_SHAKE128:
+ return libhashsum_init_shake128_hasher(this, 0);
+ case LIBHASHSUM_SHAKE256:
+ return libhashsum_init_shake256_hasher(this, 0);
+ case LIBHASHSUM_SHAKE512:
+ return libhashsum_init_shake512_hasher(this, 0);
+ case LIBHASHSUM_RAWSHAKE128:
+ return libhashsum_init_rawshake128_hasher(this, 0);
+ case LIBHASHSUM_RAWSHAKE256:
+ return libhashsum_init_rawshake256_hasher(this, 0);
+ case LIBHASHSUM_RAWSHAKE512:
+ return libhashsum_init_rawshake512_hasher(this, 0);
default:
+ case LIBHASHSUM_KECCAK:
errno = EINVAL;
return -1;
}
diff --git a/libhashsum_init_hasher_from_string.c b/libhashsum_init_hasher_from_string.c
index e41c8b1..30526da 100644
--- a/libhashsum_init_hasher_from_string.c
+++ b/libhashsum_init_hasher_from_string.c
@@ -8,7 +8,7 @@ __attribute__((__pure__))
static int
equiv(const char *a, const char *b)
{
- while (*a && *b) {
+ while (*a && *b && *b != '[') {
if (tolower(*a) == tolower(*b)) {
a++;
b++;
@@ -18,7 +18,102 @@ equiv(const char *a, const char *b)
return 0;
}
}
- return !*a && !*b;
+ return !*a && (!*b || *b == '[');
+}
+
+
+static int
+with_n(int (*initfunc)(struct libhashsum_hasher *, size_t), struct libhashsum_hasher *this, const char *algorithm)
+{
+ const char *p;
+ size_t n = 0, digit;
+
+ p = strchr(algorithm, '[');
+ if (!p || *++p == ']')
+ return initfunc(this, 0);
+
+ if ((*p++ != 'n' && *p++ != 'N'))
+ goto einval;
+ if (*p++ != '=' || !('1' <= *p && *p <= '9'))
+ goto einval;
+
+ while (isdigit(*p)) {
+ digit = (size_t)(*p++ & 15);
+ if (n > (SIZE_MAX - digit) / 10U)
+ goto einval;
+ n = n * 10U + digit;
+ }
+
+ if (*p++ != ']' || *p)
+ goto einval;
+
+ return initfunc(this, n);
+
+einval:
+ errno = EINVAL;
+ return -1;
+}
+
+
+static int
+parse_value(size_t *valp, const char *p, const char **end_out)
+{
+ size_t digit;
+ if (*valp)
+ return -1;
+ p++;
+ if (*p++ != '=' || !('1' <= *p && *p <= '9'))
+ return -1;
+ while (isdigit(*p)) {
+ digit = (size_t)(*p++ & 15);
+ if (*valp > (SIZE_MAX - digit) / 10U)
+ return -1;
+ *valp = *valp * 10U + digit;
+ }
+ *end_out = p;
+ return 0;
+}
+
+
+static int
+with_rcn(int (*initfunc)(struct libhashsum_hasher *, size_t, size_t, size_t),
+ struct libhashsum_hasher *this, const char *algorithm)
+{
+ const char *p;
+ size_t r = 0, c = 0, n = 0;
+
+ p = strchr(algorithm, '[');
+ if (!p || *++p == ']')
+ return initfunc(this, 0, 0, 0);
+
+ for (;;) {
+ if (*p == 'r' || *p == 'R') {
+ if (parse_value(&r, p, &p))
+ goto einval;
+ } else if (*p == 'c' || *p == 'C') {
+ if (parse_value(&c, p, &p))
+ goto einval;
+ } else if (*p == 'n' || *p == 'N') {
+ if (parse_value(&n, p, &p))
+ goto einval;
+ } else if (*p == ']') {
+ break;
+ } else {
+ goto einval;
+ }
+ if (*p == ']')
+ break;
+ if (*p++ != ',')
+ goto einval;
+ }
+ if (p[1])
+ goto einval;
+
+ return initfunc(this, r, c, n);
+
+einval:
+ errno = EINVAL;
+ return -1;
}
@@ -55,6 +150,36 @@ libhashsum_init_hasher_from_string(struct libhashsum_hasher *this, const char *a
return libhashsum_init_sha_512_224_hasher(this);
if (equiv(algorithm, "SHA-512/256") || !strcasecmp(algorithm, "SHA2-512/256"))
return libhashsum_init_sha_512_256_hasher(this);
+ if (equiv(algorithm, "Keccak-224"))
+ return libhashsum_init_keccak_224_hasher(this);
+ if (equiv(algorithm, "Keccak-256"))
+ return libhashsum_init_keccak_256_hasher(this);
+ if (equiv(algorithm, "Keccak-384"))
+ return libhashsum_init_keccak_384_hasher(this);
+ if (equiv(algorithm, "Keccak-512"))
+ return libhashsum_init_keccak_512_hasher(this);
+ if (!strcasecmp(algorithm, "SHA3-224"))
+ return libhashsum_init_sha3_224_hasher(this);
+ if (!strcasecmp(algorithm, "SHA3-256"))
+ return libhashsum_init_sha3_256_hasher(this);
+ if (!strcasecmp(algorithm, "SHA3-384"))
+ return libhashsum_init_sha3_384_hasher(this);
+ if (!strcasecmp(algorithm, "SHA3-512"))
+ return libhashsum_init_sha3_512_hasher(this);
+ if (equiv(algorithm, "SHAKE-128["))
+ return with_n(&libhashsum_init_shake128_hasher, this, algorithm);
+ if (equiv(algorithm, "SHAKE-256["))
+ return with_n(&libhashsum_init_shake256_hasher, this, algorithm);
+ if (equiv(algorithm, "SHAKE-512["))
+ return with_n(&libhashsum_init_shake512_hasher, this, algorithm);
+ if (equiv(algorithm, "RawSHAKE-128["))
+ return with_n(&libhashsum_init_rawshake128_hasher, this, algorithm);
+ if (equiv(algorithm, "RawSHAKE-256["))
+ return with_n(&libhashsum_init_rawshake256_hasher, this, algorithm);
+ if (equiv(algorithm, "RawSHAKE-512["))
+ return with_n(&libhashsum_init_rawshake512_hasher, this, algorithm);
+ if (equiv(algorithm, "Keccak["))
+ return with_rcn(&libhashsum_init_keccak_hasher, this, algorithm);
errno = EINVAL;
return -1;
diff --git a/libhashsum_init_keccak_224_hasher.c b/libhashsum_init_keccak_224_hasher.c
new file mode 100644
index 0000000..7a2b516
--- /dev/null
+++ b/libhashsum_init_keccak_224_hasher.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libhashsum_init_keccak_224_hasher(struct libhashsum_hasher *this)
+{
+ return libhashsum_init_keccak_hasher(this, KECCAKN(224));
+}
diff --git a/libhashsum_init_keccak_256_hasher.c b/libhashsum_init_keccak_256_hasher.c
new file mode 100644
index 0000000..2724e3a
--- /dev/null
+++ b/libhashsum_init_keccak_256_hasher.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libhashsum_init_keccak_256_hasher(struct libhashsum_hasher *this)
+{
+ return libhashsum_init_keccak_hasher(this, KECCAKN(256));
+}
diff --git a/libhashsum_init_keccak_384_hasher.c b/libhashsum_init_keccak_384_hasher.c
new file mode 100644
index 0000000..61e4f64
--- /dev/null
+++ b/libhashsum_init_keccak_384_hasher.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libhashsum_init_keccak_384_hasher(struct libhashsum_hasher *this)
+{
+ return libhashsum_init_keccak_hasher(this, KECCAKN(384));
+}
diff --git a/libhashsum_init_keccak_512_hasher.c b/libhashsum_init_keccak_512_hasher.c
new file mode 100644
index 0000000..1946aca
--- /dev/null
+++ b/libhashsum_init_keccak_512_hasher.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libhashsum_init_keccak_512_hasher(struct libhashsum_hasher *this)
+{
+ return libhashsum_init_keccak_hasher(this, KECCAKN(512));
+}
diff --git a/libhashsum_init_keccak__.c b/libhashsum_init_keccak__.c
new file mode 100644
index 0000000..b0023a5
--- /dev/null
+++ b/libhashsum_init_keccak__.c
@@ -0,0 +1,148 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+#ifdef LIBHASHSUM_INCLUDE_LIBKECCAK_STATE
+
+
+LIBHASHSUM_1_NONNULL_
+static size_t
+process(struct libhashsum_hasher *this, const void *data, size_t bytes)
+{
+ bytes -= bytes % this->input_block_size;
+ libkeccak_zerocopy_update(&this->state.keccak.s, data, bytes);
+ return bytes;
+}
+
+
+LIBHASHSUM_1_NONNULL_
+static int
+finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, unsigned extra_bits)
+{
+ const uint8_t *m = data;
+ size_t r;
+
+ if (extra_bits > 7U) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ r = process(this, m, bytes);
+ m = &m[r];
+ bytes -= r;
+
+ if (this->hash_size > sizeof(this->state.keccak.sum.buf))
+ this->hash_output = this->state.keccak.sum.dyn;
+ else
+ this->hash_output = this->state.keccak.sum.buf;
+ libkeccak_digest(&this->state.keccak.s, m, bytes, extra_bits, this->state.keccak.suffix, this->hash_output);
+ libkeccak_state_wipe_message(&this->state.keccak.s);
+ libkeccak_state_fast_destroy(&this->state.keccak.s);
+ memset(&this->state.keccak.s, 0, sizeof(this->state.keccak.s));
+ this->state.keccak.s.M = NULL;
+ return 0;
+}
+
+
+LIBHASHSUM_1_NONNULL_
+static int
+finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extra_bits, size_t size)
+{
+ uint8_t *m = data;
+ size_t r;
+ size_t need;
+
+ if (extra_bits > 7U) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ r = process(this, m, bytes);
+ m = &m[r];
+ bytes -= r;
+ size -= r;
+
+ need = strlen(this->state.keccak.suffix) + 2U + extra_bits;
+ need = (need + 7U) >> 3;
+ need += bytes;
+ if (need & (this->input_block_size - 1U)) {
+ need &= ~(this->input_block_size - 1U);
+ need += this->input_block_size;
+ }
+
+ if (this->hash_size > sizeof(this->state.keccak.sum.buf))
+ this->hash_output = this->state.keccak.sum.dyn;
+ else
+ this->hash_output = this->state.keccak.sum.buf;
+ if (size < need)
+ libkeccak_digest(&this->state.keccak.s, m, bytes, extra_bits,
+ this->state.keccak.suffix, this->hash_output);
+ else
+ libkeccak_zerocopy_digest(&this->state.keccak.s, m, bytes, extra_bits,
+ this->state.keccak.suffix, this->hash_output);
+ libkeccak_state_wipe_message(&this->state.keccak.s);
+ libkeccak_state_fast_destroy(&this->state.keccak.s);
+ memset(&this->state.keccak.s, 0, sizeof(this->state.keccak.s));
+ this->state.keccak.s.M = NULL;
+ return 0;
+}
+
+
+LIBHASHSUM_1_NONNULL_
+static void
+destroy(struct libhashsum_hasher *this)
+{
+ libkeccak_state_wipe_message(&this->state.keccak.s);
+ libkeccak_state_fast_destroy(&this->state.keccak.s);
+ memset(&this->state.keccak.s, 0, sizeof(this->state.keccak.s));
+ this->state.keccak.s.M = NULL;
+ if (this->hash_size > sizeof(this->state.keccak.sum.buf)) {
+ free(this->state.keccak.sum.dyn);
+ this->state.keccak.sum.dyn = NULL;
+ }
+}
+
+
+int
+libhashsum_init_keccak__(struct libhashsum_hasher *this, size_t hashbits, void *spec_, const char *suffix)
+{
+ struct libkeccak_spec *spec = spec_;
+
+ this->hash_size = hashbits >> 3;
+ this->hash_size += (size_t)!!(hashbits & 7U);
+ this->hash_output = NULL;
+ this->supports_non_whole_bytes = 1;
+ this->state.keccak.suffix = suffix;
+
+ if (this->hash_size > sizeof(this->state.keccak.sum.buf)) {
+ this->state.keccak.sum.dyn = malloc(this->hash_size);
+ if (!this->state.keccak.sum.dyn)
+ return -1;
+ }
+
+ if (libkeccak_state_initialise(&this->state.keccak.s, spec)) {
+ if (this->hash_size > sizeof(this->state.keccak.sum.buf)) {
+ free(this->state.keccak.sum.dyn);
+ this->state.keccak.sum.dyn = NULL;
+ }
+ return -1;
+ }
+
+ this->input_block_size = libkeccak_zerocopy_chunksize(&this->state.keccak.s);
+ this->process = &process;
+ this->finalise_const = &finalise_const;
+ this->finalise = &finalise;
+ this->destroy = &destroy;
+ return 0;
+}
+
+
+#else
+int
+libhashsum_init_keccak__(struct libhashsum_hasher *this, size_t hashbits, void *spec, const char *suffix);
+{
+ (void) this;
+ (void) spec;
+ (void) suffix;
+ errno = ENOSYS;
+ return -1;
+}
+#endif
diff --git a/libhashsum_init_keccak_hasher.c b/libhashsum_init_keccak_hasher.c
new file mode 100644
index 0000000..93622f6
--- /dev/null
+++ b/libhashsum_init_keccak_hasher.c
@@ -0,0 +1,75 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+#ifdef SUPPORT_KECCAK
+
+
+int
+libhashsum_init_keccak_hasher(struct libhashsum_hasher *this, size_t ratebits, size_t capbits, size_t hashbits)
+{
+ struct libkeccak_generalised_spec gspec;
+ struct libkeccak_spec spec;
+
+ if ((ratebits | capbits | hashbits) > (size_t)LONG_MAX) {
+ errno = EINVAL;
+ return -1;
+ } else if (!ratebits || !capbits || !hashbits) {
+ libkeccak_generalised_spec_initialise(&gspec);
+ if (ratebits)
+ gspec.bitrate = (long int)ratebits;
+ if (capbits)
+ gspec.capacity = (long int)capbits;
+ if (hashbits)
+ gspec.output = (long int)hashbits;
+ if (libkeccak_degeneralise_spec(&gspec, &spec)) {
+ errno = EINVAL;
+ return -1;
+ }
+ ratebits = (size_t)spec.bitrate;
+ capbits = (size_t)spec.capacity;
+ hashbits = (size_t)spec.output;
+ } else {
+ spec.bitrate = (long int)ratebits;
+ spec.capacity = (long int)capbits;
+ spec.output = (long int)hashbits;
+ }
+ if (libkeccak_spec_check(&spec)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ this->algorithm = LIBHASHSUM_KECCAK;
+ if ((capbits >> 1) == hashbits && !(capbits & 1U) &&
+ 1600U >= capbits && ratebits == 1600U - capbits) {
+ if (hashbits == 224U) {
+ this->algorithm = LIBHASHSUM_KECCAK_224;
+ this->algorithm_string = "Keccak-224";
+ } else if (hashbits == 256U) {
+ this->algorithm = LIBHASHSUM_KECCAK_256;
+ this->algorithm_string = "Keccak-256";
+ } else if (hashbits == 384U) {
+ this->algorithm = LIBHASHSUM_KECCAK_384;
+ this->algorithm_string = "Keccak-384";
+ } else if (hashbits == 512U) {
+ this->algorithm = LIBHASHSUM_KECCAK_512;
+ this->algorithm_string = "Keccak-512";
+ }
+ }
+ if (this->algorithm == LIBHASHSUM_KECCAK) {
+ sprintf(this->state.keccak.algostr, "Keccak[r=%zu,c=%zu,n=%zu]", ratebits, capbits, hashbits);
+ this->algorithm_string = this->state.keccak.algostr;
+ }
+
+ return libhashsum_init_keccak__(this, hashbits, &spec, "");
+}
+
+
+#else
+int
+libhashsum_init_keccak_hasher(struct libhashsum_hasher *this, size_t hashbits)
+{
+ (void) this;
+ (void) hashbits;
+ errno = ENOSYS;
+ return -1;
+}
+#endif
diff --git a/libhashsum_init_md2_hasher.c b/libhashsum_init_md2_hasher.c
index 6ea2063..cf0a495 100644
--- a/libhashsum_init_md2_hasher.c
+++ b/libhashsum_init_md2_hasher.c
@@ -142,6 +142,7 @@ libhashsum_init_md2_hasher(struct libhashsum_hasher *this)
this->process = &process;
this->finalise_const = &finalise_const;
this->finalise = &finalise;
+ this->destroy = NULL;
memset(&this->state.md2, 0, sizeof(this->state.md2));
return 0;
}
diff --git a/libhashsum_init_md4_hasher.c b/libhashsum_init_md4_hasher.c
index 22626a9..bc361d8 100644
--- a/libhashsum_init_md4_hasher.c
+++ b/libhashsum_init_md4_hasher.c
@@ -185,6 +185,7 @@ libhashsum_init_md4_hasher(struct libhashsum_hasher *this)
this->process = &process;
this->finalise_const = &finalise_const;
this->finalise = &finalise;
+ this->destroy = NULL;
memset(&this->state.md4, 0, sizeof(this->state.md4));
this->state.md4.h.h32[0] = UINT32_C(0x67452301);
this->state.md4.h.h32[1] = UINT32_C(0xefcdab89);
diff --git a/libhashsum_init_md5_hasher.c b/libhashsum_init_md5_hasher.c
index 6888f6e..8147204 100644
--- a/libhashsum_init_md5_hasher.c
+++ b/libhashsum_init_md5_hasher.c
@@ -200,6 +200,7 @@ libhashsum_init_md5_hasher(struct libhashsum_hasher *this)
this->process = &process;
this->finalise_const = &finalise_const;
this->finalise = &finalise;
+ this->destroy = NULL;
memset(&this->state.md5, 0, sizeof(this->state.md5));
this->state.md5.h.h32[0] = UINT32_C(0x67452301);
this->state.md5.h.h32[1] = UINT32_C(0xefcdab89);
diff --git a/libhashsum_init_rawshake128_hasher.c b/libhashsum_init_rawshake128_hasher.c
new file mode 100644
index 0000000..38a8bd3
--- /dev/null
+++ b/libhashsum_init_rawshake128_hasher.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libhashsum_init_rawshake128_hasher(struct libhashsum_hasher *this, size_t hashbits)
+{
+ return libhashsum_init_rawshake_hasher(this, 128, hashbits);
+}
diff --git a/libhashsum_init_rawshake256_hasher.c b/libhashsum_init_rawshake256_hasher.c
new file mode 100644
index 0000000..abd7bd7
--- /dev/null
+++ b/libhashsum_init_rawshake256_hasher.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libhashsum_init_rawshake256_hasher(struct libhashsum_hasher *this, size_t hashbits)
+{
+ return libhashsum_init_rawshake_hasher(this, 256, hashbits);
+}
diff --git a/libhashsum_init_rawshake512_hasher.c b/libhashsum_init_rawshake512_hasher.c
new file mode 100644
index 0000000..34009e1
--- /dev/null
+++ b/libhashsum_init_rawshake512_hasher.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libhashsum_init_rawshake512_hasher(struct libhashsum_hasher *this, size_t hashbits)
+{
+ return libhashsum_init_rawshake_hasher(this, 512, hashbits);
+}
diff --git a/libhashsum_init_rawshake_hasher.c b/libhashsum_init_rawshake_hasher.c
new file mode 100644
index 0000000..f90e3b7
--- /dev/null
+++ b/libhashsum_init_rawshake_hasher.c
@@ -0,0 +1,52 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+#ifdef SUPPORT_RAWSHAKE
+
+
+int
+libhashsum_init_rawshake_hasher(struct libhashsum_hasher *this, size_t hcapbits, size_t hashbits)
+{
+ struct libkeccak_spec spec;
+
+ if (hcapbits == 128U) {
+ this->algorithm = LIBHASHSUM_RAWSHAKE128;
+ this->algorithm_string = "RawSHAKE128";
+ } else if (hcapbits == 256U) {
+ this->algorithm = LIBHASHSUM_RAWSHAKE256;
+ this->algorithm_string = "RawSHAKE256";
+ } else if (hcapbits == 512U) {
+ this->algorithm = LIBHASHSUM_RAWSHAKE512;
+ this->algorithm_string = "RawSHAKE512";
+ } else {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (hashbits == 0U) {
+ hashbits = hcapbits;
+ } else if (hashbits > (size_t)LONG_MAX) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (hashbits != hcapbits) {
+ sprintf(this->state.keccak.algostr, "%s[n=%zu]", this->algorithm_string, hashbits);
+ this->algorithm_string = this->state.keccak.algostr;
+ }
+
+ libkeccak_spec_rawshake(&spec, (long int)hcapbits, (long int)hashbits);
+ return libhashsum_init_keccak__(this, hashbits, &spec, LIBKECCAK_RAWSHAKE_SUFFIX);
+}
+
+
+#else
+int
+libhashsum_init_rawshake_hasher(struct libhashsum_hasher *this, size_t hcapbits, size_t hashbits)
+{
+ (void) this;
+ (void) hcapbits;
+ (void) hashbits;
+ errno = ENOSYS;
+ return -1;
+}
+#endif
diff --git a/libhashsum_init_ripemd_128_hasher.c b/libhashsum_init_ripemd_128_hasher.c
index 39c5f1c..d958adb 100644
--- a/libhashsum_init_ripemd_128_hasher.c
+++ b/libhashsum_init_ripemd_128_hasher.c
@@ -221,6 +221,7 @@ libhashsum_init_ripemd_128_hasher(struct libhashsum_hasher *this)
this->process = &process;
this->finalise_const = &finalise_const;
this->finalise = &finalise;
+ this->destroy = NULL;
memset(&this->state.ripemd_128, 0, sizeof(this->state.ripemd_128));
this->state.ripemd_128.h.h32[0] = UINT32_C(0x67452301);
this->state.ripemd_128.h.h32[1] = UINT32_C(0xefcdab89);
diff --git a/libhashsum_init_ripemd_160_hasher.c b/libhashsum_init_ripemd_160_hasher.c
index 8b37b0a..edb1c5f 100644
--- a/libhashsum_init_ripemd_160_hasher.c
+++ b/libhashsum_init_ripemd_160_hasher.c
@@ -224,6 +224,7 @@ libhashsum_init_ripemd_160_hasher(struct libhashsum_hasher *this)
this->process = &process;
this->finalise_const = &finalise_const;
this->finalise = &finalise;
+ this->destroy = NULL;
memset(&this->state.ripemd_160, 0, sizeof(this->state.ripemd_160));
this->state.ripemd_160.h.h32[0] = UINT32_C(0x67452301);
this->state.ripemd_160.h.h32[1] = UINT32_C(0xefcdab89);
diff --git a/libhashsum_init_ripemd_256_hasher.c b/libhashsum_init_ripemd_256_hasher.c
index 6ba8aa0..ce3bf14 100644
--- a/libhashsum_init_ripemd_256_hasher.c
+++ b/libhashsum_init_ripemd_256_hasher.c
@@ -232,6 +232,7 @@ libhashsum_init_ripemd_256_hasher(struct libhashsum_hasher *this)
this->process = &process;
this->finalise_const = &finalise_const;
this->finalise = &finalise;
+ this->destroy = NULL;
memset(&this->state.ripemd_256, 0, sizeof(this->state.ripemd_256));
this->state.ripemd_256.h.h32[0] = UINT32_C(0x67452301);
this->state.ripemd_256.h.h32[1] = UINT32_C(0xefcdab89);
diff --git a/libhashsum_init_ripemd_320_hasher.c b/libhashsum_init_ripemd_320_hasher.c
index 2bb2383..d5af69a 100644
--- a/libhashsum_init_ripemd_320_hasher.c
+++ b/libhashsum_init_ripemd_320_hasher.c
@@ -238,6 +238,7 @@ libhashsum_init_ripemd_320_hasher(struct libhashsum_hasher *this)
this->process = &process;
this->finalise_const = &finalise_const;
this->finalise = &finalise;
+ this->destroy = NULL;
memset(&this->state.ripemd_320, 0, sizeof(this->state.ripemd_320));
this->state.ripemd_320.h.h32[0] = UINT32_C(0x67452301);
this->state.ripemd_320.h.h32[1] = UINT32_C(0xefcdab89);
diff --git a/libhashsum_init_sha0_hasher.c b/libhashsum_init_sha0_hasher.c
index eddb750..7f420d8 100644
--- a/libhashsum_init_sha0_hasher.c
+++ b/libhashsum_init_sha0_hasher.c
@@ -66,6 +66,7 @@ libhashsum_init_sha0_hasher(struct libhashsum_hasher *this)
this->process = &process;
this->finalise_const = &finalise_const;
this->finalise = &finalise;
+ this->destroy = NULL;
libsha1_init(&this->state.sha0.s, LIBSHA1_0);
return 0;
}
diff --git a/libhashsum_init_sha1_hasher.c b/libhashsum_init_sha1_hasher.c
index 023e856..91bcc15 100644
--- a/libhashsum_init_sha1_hasher.c
+++ b/libhashsum_init_sha1_hasher.c
@@ -66,6 +66,7 @@ libhashsum_init_sha1_hasher(struct libhashsum_hasher *this)
this->process = &process;
this->finalise_const = &finalise_const;
this->finalise = &finalise;
+ this->destroy = NULL;
libsha1_init(&this->state.sha1.s, LIBSHA1_1);
return 0;
}
diff --git a/libhashsum_init_sha2_hasher.c b/libhashsum_init_sha2_hasher.c
index b76f059..f06c59b 100644
--- a/libhashsum_init_sha2_hasher.c
+++ b/libhashsum_init_sha2_hasher.c
@@ -95,6 +95,7 @@ libhashsum_init_sha2_hasher(struct libhashsum_hasher *this, unsigned algobits, s
this->process = &process;
this->finalise_const = &finalise_const;
this->finalise = &finalise;
+ this->destroy = NULL;
libsha2_init(&this->state.sha2.s, algo);
return 0;
}
diff --git a/libhashsum_init_sha3_224_hasher.c b/libhashsum_init_sha3_224_hasher.c
new file mode 100644
index 0000000..d8ed53e
--- /dev/null
+++ b/libhashsum_init_sha3_224_hasher.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libhashsum_init_sha3_224_hasher(struct libhashsum_hasher *this)
+{
+ return libhashsum_init_sha3_hasher(this, 224);
+}
diff --git a/libhashsum_init_sha3_256_hasher.c b/libhashsum_init_sha3_256_hasher.c
new file mode 100644
index 0000000..5a89d72
--- /dev/null
+++ b/libhashsum_init_sha3_256_hasher.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libhashsum_init_sha3_256_hasher(struct libhashsum_hasher *this)
+{
+ return libhashsum_init_sha3_hasher(this, 256);
+}
diff --git a/libhashsum_init_sha3_384_hasher.c b/libhashsum_init_sha3_384_hasher.c
new file mode 100644
index 0000000..fb1f123
--- /dev/null
+++ b/libhashsum_init_sha3_384_hasher.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libhashsum_init_sha3_384_hasher(struct libhashsum_hasher *this)
+{
+ return libhashsum_init_sha3_hasher(this, 384);
+}
diff --git a/libhashsum_init_sha3_512_hasher.c b/libhashsum_init_sha3_512_hasher.c
new file mode 100644
index 0000000..029968b
--- /dev/null
+++ b/libhashsum_init_sha3_512_hasher.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libhashsum_init_sha3_512_hasher(struct libhashsum_hasher *this)
+{
+ return libhashsum_init_sha3_hasher(this, 512);
+}
diff --git a/libhashsum_init_sha3_hasher.c b/libhashsum_init_sha3_hasher.c
new file mode 100644
index 0000000..c9d6ac7
--- /dev/null
+++ b/libhashsum_init_sha3_hasher.c
@@ -0,0 +1,42 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+#ifdef SUPPORT_SHA3
+
+
+int
+libhashsum_init_sha3_hasher(struct libhashsum_hasher *this, size_t hashbits)
+{
+ struct libkeccak_spec spec;
+
+ if (hashbits == 224U) {
+ this->algorithm = LIBHASHSUM_SHA3_224;
+ this->algorithm_string = "SHA3-224";
+ } else if (hashbits == 256U) {
+ this->algorithm = LIBHASHSUM_SHA3_256;
+ this->algorithm_string = "SHA3-256";
+ } else if (hashbits == 384U) {
+ this->algorithm = LIBHASHSUM_SHA3_384;
+ this->algorithm_string = "SHA3-384";
+ } else if (hashbits == 512U) {
+ this->algorithm = LIBHASHSUM_SHA3_512;
+ this->algorithm_string = "SHA3-512";
+ } else {
+ errno = EINVAL;
+ return -1;
+ }
+
+ libkeccak_spec_sha3(&spec, (long int)hashbits);
+ return libhashsum_init_keccak__(this, hashbits, &spec, LIBKECCAK_SHA3_SUFFIX);
+}
+
+
+#else
+int
+libhashsum_init_sha3_hasher(struct libhashsum_hasher *this, size_t hashbits)
+{
+ (void) this;
+ (void) hashbits;
+ errno = ENOSYS;
+ return -1;
+}
+#endif
diff --git a/libhashsum_init_shake128_hasher.c b/libhashsum_init_shake128_hasher.c
new file mode 100644
index 0000000..2b7df6a
--- /dev/null
+++ b/libhashsum_init_shake128_hasher.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libhashsum_init_shake128_hasher(struct libhashsum_hasher *this, size_t hashbits)
+{
+ return libhashsum_init_shake_hasher(this, 128, hashbits);
+}
diff --git a/libhashsum_init_shake256_hasher.c b/libhashsum_init_shake256_hasher.c
new file mode 100644
index 0000000..26c4f09
--- /dev/null
+++ b/libhashsum_init_shake256_hasher.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libhashsum_init_shake256_hasher(struct libhashsum_hasher *this, size_t hashbits)
+{
+ return libhashsum_init_shake_hasher(this, 256, hashbits);
+}
diff --git a/libhashsum_init_shake512_hasher.c b/libhashsum_init_shake512_hasher.c
new file mode 100644
index 0000000..ddaf2ed
--- /dev/null
+++ b/libhashsum_init_shake512_hasher.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libhashsum_init_shake512_hasher(struct libhashsum_hasher *this, size_t hashbits)
+{
+ return libhashsum_init_shake_hasher(this, 512, hashbits);
+}
diff --git a/libhashsum_init_shake_hasher.c b/libhashsum_init_shake_hasher.c
new file mode 100644
index 0000000..a5f5746
--- /dev/null
+++ b/libhashsum_init_shake_hasher.c
@@ -0,0 +1,52 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+#ifdef SUPPORT_SHAKE
+
+
+int
+libhashsum_init_shake_hasher(struct libhashsum_hasher *this, size_t hcapbits, size_t hashbits)
+{
+ struct libkeccak_spec spec;
+
+ if (hcapbits == 128U) {
+ this->algorithm = LIBHASHSUM_SHAKE128;
+ this->algorithm_string = "SHAKE128";
+ } else if (hcapbits == 256U) {
+ this->algorithm = LIBHASHSUM_SHAKE256;
+ this->algorithm_string = "SHAKE256";
+ } else if (hcapbits == 512U) {
+ this->algorithm = LIBHASHSUM_SHAKE512;
+ this->algorithm_string = "SHAKE512";
+ } else {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (hashbits == 0U) {
+ hashbits = hcapbits;
+ } else if (hashbits > (size_t)LONG_MAX) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (hashbits != hcapbits) {
+ sprintf(this->state.keccak.algostr, "%s[n=%zu]", this->algorithm_string, hashbits);
+ this->algorithm_string = this->state.keccak.algostr;
+ }
+
+ libkeccak_spec_shake(&spec, (long int)hcapbits, (long int)hashbits);
+ return libhashsum_init_keccak__(this, hashbits, &spec, LIBKECCAK_SHAKE_SUFFIX);
+}
+
+
+#else
+int
+libhashsum_init_shake_hasher(struct libhashsum_hasher *this, size_t hcapbits, size_t hashbits)
+{
+ (void) this;
+ (void) hcapbits;
+ (void) hashbits;
+ errno = ENOSYS;
+ return -1;
+}
+#endif
diff --git a/mk/keccak=no.mk b/mk/keccak=no.mk
new file mode 120000
index 0000000..54299a4
--- /dev/null
+++ b/mk/keccak=no.mk
@@ -0,0 +1 @@
+no \ No newline at end of file
diff --git a/mk/keccak=yes.mk b/mk/keccak=yes.mk
new file mode 100644
index 0000000..d35f3e2
--- /dev/null
+++ b/mk/keccak=yes.mk
@@ -0,0 +1,4 @@
+CPPFLAGS_KECCAK = -DSUPPORT_KECCAK
+
+CPPFLAGS_LIBKECCAK_IF_SUPPORTED = $(CPPFLAGS_LIBKECCAK)
+LDFLAGS_LIBKECCAK_IF_SUPPORTED = $(LDFLAGS_LIBKECCAK)
diff --git a/mk/rawshake=no.mk b/mk/rawshake=no.mk
new file mode 120000
index 0000000..54299a4
--- /dev/null
+++ b/mk/rawshake=no.mk
@@ -0,0 +1 @@
+no \ No newline at end of file
diff --git a/mk/rawshake=yes.mk b/mk/rawshake=yes.mk
new file mode 100644
index 0000000..d41ab71
--- /dev/null
+++ b/mk/rawshake=yes.mk
@@ -0,0 +1,4 @@
+CPPFLAGS_RAWSHAKE = -DSUPPORT_RAWSHAKE
+
+CPPFLAGS_LIBKECCAK_IF_SUPPORTED = $(CPPFLAGS_LIBKECCAK)
+LDFLAGS_LIBKECCAK_IF_SUPPORTED = $(LDFLAGS_LIBKECCAK)
diff --git a/mk/sha3=no.mk b/mk/sha3=no.mk
new file mode 120000
index 0000000..54299a4
--- /dev/null
+++ b/mk/sha3=no.mk
@@ -0,0 +1 @@
+no \ No newline at end of file
diff --git a/mk/sha3=yes.mk b/mk/sha3=yes.mk
new file mode 100644
index 0000000..3d255f5
--- /dev/null
+++ b/mk/sha3=yes.mk
@@ -0,0 +1,4 @@
+CPPFLAGS_SHA3 = -DSUPPORT_SHA3
+
+CPPFLAGS_LIBKECCAK_IF_SUPPORTED = $(CPPFLAGS_LIBKECCAK)
+LDFLAGS_LIBKECCAK_IF_SUPPORTED = $(LDFLAGS_LIBKECCAK)
diff --git a/mk/shake=no.mk b/mk/shake=no.mk
new file mode 120000
index 0000000..54299a4
--- /dev/null
+++ b/mk/shake=no.mk
@@ -0,0 +1 @@
+no \ No newline at end of file
diff --git a/mk/shake=yes.mk b/mk/shake=yes.mk
new file mode 100644
index 0000000..b3f1fbc
--- /dev/null
+++ b/mk/shake=yes.mk
@@ -0,0 +1,4 @@
+CPPFLAGS_SHAKE = -DSUPPORT_SHAKE
+
+CPPFLAGS_LIBKECCAK_IF_SUPPORTED = $(CPPFLAGS_LIBKECCAK)
+LDFLAGS_LIBKECCAK_IF_SUPPORTED = $(LDFLAGS_LIBKECCAK)
diff --git a/sha3_224.c b/sha3_224.c
new file mode 100644
index 0000000..ccbf5cf
--- /dev/null
+++ b/sha3_224.c
@@ -0,0 +1,352 @@
+/* See LICENSE file for copyright and license details. */
+#ifdef SUPPORT_SHA3
+# define TEST
+# include "common.h"
+
+
+static struct testcase testcases[] = {
+ {1, 0, "", "6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7"},
+ {1UL, 0, " ", "4cb5f87b01b38adc0e6f13f915668c2394cb1fb7a2795635b894dda1"},
+ {2UL, 0, " ", "1a64ebab9deb5dd0428b68f9522b81c3db15c318665a820f280e38e3"},
+ {3UL, 0, " ", "d838e74fd7808ccb161a8b67d43049b5b331601e858efe112618ed29"},
+ {4UL, 0, " ", "a7df693f86a83049c6452db56af52c57bcca7246c2c11606e6a230b2"},
+ {5UL, 0, " ", "9e1da0d8926041736b61617e896aded2203152fe4f56435ddb8512c9"},
+ {6UL, 0, " ", "ad111c66761182a470fb8aaf23d93debac4ae844edf40fec64118ce8"},
+ {7UL, 0, " ", "1b3e1b9e7ee9efd83a847e9a54b38227722197da0ec6481fcb7fa477"},
+ {8UL, 0, " ", "bcb19154b2697ceab230a7264fd7c042fc069efabdcd657b300a0b13"},
+ {9UL, 0, " ", "b8570a90b9cc7908e71b3cb5a098a32a20beec327aa7b9711d5a6e62"},
+ {10UL, 0, " ", "10bd2239e774129ad7d6fcef1a07c601aa096d97abbec6af460f6c11"},
+ {11UL, 0, " ", "a06e08351a9c706bd7251e51b32609501e40db29dde5e4c3d4b90fc5"},
+ {12UL, 0, " ", "e0ebeba4160f2d899d82b1aaf8c8abed28d2543350ccb4c442de14b2"},
+ {13UL, 0, " ", "f2371db8557e2facab26a16099b6174350223b9d1d4d179e38264bf9"},
+ {14UL, 0, " ", "18a0d7b068e7d5ffda086f2e448d099422f1b358e68f2b42996a2015"},
+ {15UL, 0, " ", "06e2d9303ec62532aea711319046b654a8596dd1361410f9f964d91a"},
+ {16UL, 0, " ", "ff4cbd06962d3fae02e4afe3277df71112bc14e74dc3b287268cd057"},
+ {17UL, 0, " ", "32ff4116c85b93ec457ce63e2c7038dad660ac905bf8e05845cde5ba"},
+ {18UL, 0, " ", "efc9067b68668d57729c4a14a80cdec8773be97323b8f9b9d4ef99e0"},
+ {19UL, 0, " ", "54a7324aabb83369ca93f41b66c47f907d9e90677ee1c723618d2a6e"},
+ {20UL, 0, " ", "9b5896b60ce7c37794cf866d5c8b8f66f49326f9283b7677d89122ae"},
+ {21UL, 0, " ", "fb54443a0acdbbea12b12dfdcd71f623eda3e2eb7f1eb4e0d58e8c3d"},
+ {22UL, 0, " ", "764e6daf67d9a2f8ca871ca7b1bff5394c939d7acf2ed400c33726f1"},
+ {23UL, 0, " ", "ba70fed2e7fa01851fc86d70d8e2f8ae46d02aa81beb5e9b7b8b8886"},
+ {24UL, 0, " ", "dce29090fa1fc99fdea4a90f8a191812dadadf72bbddc339710e688a"},
+ {25UL, 0, " ", "fa8043b456cecfa7e7d330daba8d39fa96ec0dce1c92df40ec7eca45"},
+ {26UL, 0, " ", "05d6655e456684fec13b6619af2f0394cc39c6ffcf8126ec929947a7"},
+ {27UL, 0, " ", "12c7092dee52a14a6272f721da9e1ce0c758555d8951bdad87b2da91"},
+ {28UL, 0, " ", "12c61de3ed5da350a17c61682deaca1f68353af0d35462a9a024231b"},
+ {29UL, 0, " ", "2e91e9698e6df0fb0459c61be7eeedfa3cdbf08e1ca6e29fd808f44a"},
+ {30UL, 0, " ", "88b2dcb691f77593dbd6cc9f28138002adbfce3333c822d9696dac1c"},
+ {31UL, 0, " ", "ce463fbf3794d21f793a92499f53d02a44f53c01fa3eb5b18e20dafc"},
+ {32UL, 0, " ", "7eee3387239b3d9c4ac92fb1bed98c8246641da762187f5b63ea9bb8"},
+ {33UL, 0, " ", "d29e190bda24dace1f3b5b45157832b1fce97e1cea9320d918a6a315"},
+ {34UL, 0, " ", "bfe30323b49e91ff242575025fbea326c5351b0f8c9712babda2912e"},
+ {35UL, 0, " ", "80a7fa5d858830f6c4bdaf99baa4061264ab5213a85d69d002b29f55"},
+ {36UL, 0, " ", "519a4ea539502070782018bb54f610e60fc4a705a5aa6a5e449511b0"},
+ {37UL, 0, " ", "73e74ee7e6dfb2dfaa44bcac4180b602c78e14455ab9459435f8825e"},
+ {38UL, 0, " ", "de76b15308530e6feb7d658a5d9b8d405d9955da87531b83e457e4b8"},
+ {39UL, 0, " ", "d82efb62daa169f11143e75ecd3eddb448d0789ca3e66b390ee74f2f"},
+ {40UL, 0, " ", "03768212802432c868de50a057c500a6aea21e12248754b6d64eff41"},
+ {41UL, 0, " ", "ce6a5bbe300077d8fc583ae46db88589fd27e21395455479550c979d"},
+ {42UL, 0, " ", "9bb69a7ea6f590adf0b42f1589f0d6f98716bca86f8338f69da7f127"},
+ {43UL, 0, " ", "b515a6ca9748b3fdd6da818ae4524c7ab7ced020611a403e33f73827"},
+ {44UL, 0, " ", "f782b9e0ba4f1ddf599be79cb47318bdaa61261427480bd901d69f5d"},
+ {45UL, 0, " ", "7ac893d28cae4bf18c0d8c3b2ba1dff009df61bcf438ef66149c9d47"},
+ {46UL, 0, " ", "f18ab51a3cb90e8cc257619fb3e2ebd450338ab817fe929c31e7db1f"},
+ {47UL, 0, " ", "cc7633ad00aa9d18a50b8ef77a2af4d4938ca4102e37d404a0422640"},
+ {48UL, 0, " ", "49ba79273c4a52897c4dd2767fb14a1439a96121c47a69652c3a75a9"},
+ {49UL, 0, " ", "8637e3e08196289674e16691210e4af50fc44375addc8930e3f40016"},
+ {50UL, 0, " ", "4012c0272e94861368b163e49b665d21803ac058ce4f021b0d6756a3"},
+ {51UL, 0, " ", "4f4099d786e8537d4ee4985bfef12a914505181dff81f26b67e7f9ce"},
+ {52UL, 0, " ", "8232d738c5b463ff4da12231ee32fa1026581721477c948fcf6365cd"},
+ {53UL, 0, " ", "bdf05fa77432070260422b9337186ae9ba578c47d05f0b7999419b0a"},
+ {54UL, 0, " ", "e9ef0323574696dcbe5c35a4ce286749639259f71c77775b699c59d4"},
+ {55UL, 0, " ", "1f79f3a5e5ca2e56db8f5fc1a7653a119bdccfc8405766f6d3f3fb73"},
+ {56UL, 0, " ", "7dce65ef09f1d47fe6166dcd260808af141dd6ddc86865826b852edf"},
+ {57UL, 0, " ", "dac08738db2d96041219ad75f64cb4c9de20c41e6f102f952af8e7a3"},
+ {58UL, 0, " ", "48c4408d37ba8571d0984735ae18912d66fcef68534b7d3497b365db"},
+ {59UL, 0, " ", "e4ac9ecb01a5d7db7ba544d43b8b1358c61ddb1de32d19482bba325f"},
+ {60UL, 0, " ", "5df437e0149202acdb0d555e95ae13e2216235c8001046ebe707daf0"},
+ {61UL, 0, " ", "e47cfc77f4385d802ac83b3282b106449497fcf2ab8d43aa2e23f160"},
+ {62UL, 0, " ", "957c4dd152f2642cc3df6c999047613fa9fa0f4ea4104d45c4a098e5"},
+ {63UL, 0, " ", "9ea8e542b4b1d27dd9cfd8205fe38941e5ca1c08d6a0db40fe92e897"},
+ {64UL, 0, " ", "572105803c18e1e284815f7667d2df0adbec5010adf04ccceaa029bb"},
+ {65UL, 0, " ", "c51c7e150eee3675ac09762f28ba9a8c993d604cf5af7e97149b0942"},
+ {66UL, 0, " ", "25ef1f583f10ab515a952a0a4bb80df1686b8f5fa98104afd2a0277b"},
+ {67UL, 0, " ", "3e941387ba3ca58009254cab0cfe67b4e332f11fe845ef65a8fc1044"},
+ {68UL, 0, " ", "ac56a59ea8f1d5e8aba085f829dfcd7d56716dbf3b6a2c931d219d8d"},
+ {69UL, 0, " ", "522889e8d147ff961c1cc0d9891ad96564c155d89dd2d2f34bb42b76"},
+ {70UL, 0, " ", "b884d2b5edd4a00230019ac9bb910408f832255edea81a15d8fd0403"},
+ {71UL, 0, " ", "c81951643b4f59624c2b90f9af4bfc2d59fd4921f66122a79814b699"},
+ {72UL, 0, " ", "edf52515f6393414239ff789248febfe3b71b83a9d19f1c518b78c5e"},
+ {73UL, 0, " ", "af7414feef6be2ac8cff372a8b37c9e92b96fff10a84509aca9a6178"},
+ {74UL, 0, " ", "a17b44266b9d5c9a052f95f863f9b1adcddc969ec158d2b3dbba7f22"},
+ {75UL, 0, " ", "976d87634ad9da6d2f6032bc8baf1d9a5e913e12fceabbd6d4bc2515"},
+ {76UL, 0, " ", "df6968778add7ab73eb487d28d9ca92dcf5bce165e4061d09ed960b3"},
+ {77UL, 0, " ", "a1ae4032f560f357d82d0a6dbd1782cb52e668dccb793923d6c7c3f8"},
+ {78UL, 0, " ", "bf837f0dfe82d23e74811470045dce11d2119b3978692ba7b7d3c176"},
+ {79UL, 0, " ", "0ab8e4c4acf5139877677b7971864e583451ee4897f2a490abe66937"},
+ {80UL, 0, " ", "7a27bd7bf609c3f95a37a9580489eff4c59a5f5b843a88e7aae585e2"},
+ {81UL, 0, " ", "f574258fbc316d67fcf647964ef444ed6bd2bef2032e9becd15708f5"},
+ {82UL, 0, " ", "c0557fdc045f816aeb169b7bf1075c3ffe4f4631e870ba3d3b2fbd8d"},
+ {83UL, 0, " ", "3e0d19655af9efeba86341661a1245b59314056b49788fcea5b2a1ea"},
+ {84UL, 0, " ", "b7f060a7a4d669b7a7f56dfdbe5befefdd5f0242179a5a986b3118c5"},
+ {85UL, 0, " ", "aa622bb2da1853903900f61ec968c345d24fe32b24f9c395e023f414"},
+ {86UL, 0, " ", "61379ec35a3ff7d4c4c327f91416482dac46c284713a736688d66ab2"},
+ {87UL, 0, " ", "fff4d787733d1d158ad3dca19ae11ea49cb27b29b7d0409685c2583f"},
+ {88UL, 0, " ", "c2c0d7f738a17ef3de7fa4daa4e62fd010a543af705c7ec75abb350c"},
+ {89UL, 0, " ", "97eb020a8c387b3e7ffd8d3b61856b75c0ac295310c3cb385562aaf9"},
+ {90UL, 0, " ", "28f6b0b95e9aca22386ac708ee74201b810827188b4fb810a653e964"},
+ {91UL, 0, " ", "981168c506be7765db93600c8ce8526bd95d2ac1871c82c1fa97841a"},
+ {92UL, 0, " ", "4c92d48e9c6d8c584a6540581bc87ff4daf83b0fdce4dc824a78cdc5"},
+ {93UL, 0, " ", "26eb7b9940a4f4b02d4b93fa129e369c565b6276019d6d006fae1137"},
+ {94UL, 0, " ", "894e9cdc6f1662b5b4fd366553d91e167f6980f9522d8ad8555c1f4f"},
+ {95UL, 0, " ", "2003c4c6d3dd8cad0fde05541f43e8abd979510a389b0fa4b94d9488"},
+ {96UL, 0, " ", "84be87c12408e7898ea7a43f5eed3940ec23f1e33a81a6384272860a"},
+ {97UL, 0, " ", "d1f158b0d3c6b66f1e1f363fc5d5a9770f441b5d62479a22f53e091b"},
+ {98UL, 0, " ", "234dce0dae15f89a88940bf131bd68b3ba48c7df251ece6e7aa4a0fb"},
+ {99UL, 0, " ", "a830be7366b92ad0d737ca8167751b530cc15b66ed202118985e67ce"},
+ {100UL, 0, " ", "29219fdd0a2c69fb4f8b268ebd75f9f4f03c990fedc1f8627a9eaa14"},
+ {101UL, 0, " ", "5db8d277939bb5f2e6083c2c429298d3976b710abd152f5a6d7da81f"},
+ {102UL, 0, " ", "f4cf42a5b3cf0b693e9d1d4cd2e4cda7923e443a9803a488defe91b0"},
+ {103UL, 0, " ", "362857fd4ec32a40a99d4e19ecf1bd87f8308846a7eca1f9c6b9bb57"},
+ {104UL, 0, " ", "8857671a2b21ad783e8340c70cdcb71926a28fdbe7da27c564d88e99"},
+ {105UL, 0, " ", "6d36fdecaeb71720be1ad70c37f0640fbb64bf43bf6b95762c6c4642"},
+ {106UL, 0, " ", "2f26d1a7f946fb6adab62333937e0bb59e5e49735e6538c9d0acae89"},
+ {107UL, 0, " ", "eaeacd93c9479d1d9250df6ecd3b0a97f264e9d52eeef7d2d474769b"},
+ {108UL, 0, " ", "c3485a305320d22bcc25998b25e7661448de1ac6eb0f3c6712c7c7ae"},
+ {109UL, 0, " ", "a1d8721cf5ff48a5ddbab3cfa2d603179d25caa7db17f239abb170f4"},
+ {110UL, 0, " ", "cd83c5f724384ab58198450386d7840bf2f742e1b85f80a8d568368d"},
+ {111UL, 0, " ", "2c34a94c02ad8ab462f209807ad6a5162cebf1e1cdb363b39ea0252e"},
+ {112UL, 0, " ", "a524f6ee6a92588c0cff922fc9b8b0c99280e23273b48164dbfd7bdf"},
+ {113UL, 0, " ", "402990297221a85f5976adcbf720a49cdb55836516a1253262bdc946"},
+ {114UL, 0, " ", "4dd078df2de61eb96cbaa65aa2ad935555ef48d8379438174ab67a73"},
+ {115UL, 0, " ", "a0c205a884950c53d7754c0fab722b5fb6b65c5b085cbae471fe9715"},
+ {116UL, 0, " ", "3a3906ed6f57e0c5ea1bb33553a98260a4f9cb20a10eca11a3a08123"},
+ {117UL, 0, " ", "cefee50848b3c44d996b4a5700715ac2f0a83f694e72a9ff2ffea56b"},
+ {118UL, 0, " ", "8dba530e8e27f35f1152132c125de77e780072882a3ddb223b6e69e0"},
+ {119UL, 0, " ", "82b1aa5898c5503739e3f064fe145f5b90d610c948a295de14f7507d"},
+ {120UL, 0, " ", "d420a83627c4bc1b54add26040cb9268a809de63f98610ce76f8fca6"},
+ {121UL, 0, " ", "0fa086ae9132c82fcd2d5dafe09dd7d16895a7a48f2d77ae44872dfe"},
+ {122UL, 0, " ", "5edac9117c5e87baf24d046e3c1614578404ccacd727022d5beeb0a0"},
+ {123UL, 0, " ", "5edf8bb6725b42b450c8a670446249ce05cb6f993877d8ddb8709bee"},
+ {124UL, 0, " ", "19361cf4b805e43d70fbf21c8ed284c8abeabcf951449f93cf0319a0"},
+ {125UL, 0, " ", "fed5baeba6d2ec35ab1b8ee7c6772729a5dd6bf5c0831a59e6a892d7"},
+ {126UL, 0, " ", "feab143afa749f2ba23d3607009859fa25a09ba3aa8d248882af4d2f"},
+ {127UL, 0, " ", "34ff55e13946b0ca188362270e783bc3d9ed82e33472a195fe773d5f"},
+ {128UL, 0, " ", "e5d2ec01cc8b3a1ab662de562af04aa41d41b770a59a08fd689c6bbb"},
+ {129UL, 0, " ", "e43900681235ff6624e52e87ccc33ccfde5c0038b90999a7d23721c6"},
+ {130UL, 0, " ", "7f8085f41c8d60a0f1b0226dd0cfd6a24e5d73557f382ea6f3ce25ad"},
+ {131UL, 0, " ", "4a53fea203779ee4555620886f6b6357ff35a0655667d7174a2fd196"},
+ {132UL, 0, " ", "b17cf5ba26058d14e2330106ad46485ddf421286ae9bf5772b91e889"},
+ {133UL, 0, " ", "0dbc4c808e638cdacba32092666835bc2b2848fad0444afcad8d5e90"},
+ {134UL, 0, " ", "3c333f36bafcc787dfcb24d3744114d71a4a9c5e6e09e949a221fc8d"},
+ {135UL, 0, " ", "401c11810974a026b48bc9cc8bc72ada4788c97e1f919cc80b125583"},
+ {136UL, 0, " ", "4647b8b14eac49619abd178c385621d7658156ce62c5dbb0dc8ccc9d"},
+ {137UL, 0, " ", "730af9e6c492ae88b6b0f653f1739ef838c4aeae5b41fbc117c277f8"},
+ {138UL, 0, " ", "f3ec86ba95212e34ca2b309686697ac43b9494a7a4e065dfb38ad31a"},
+ {139UL, 0, " ", "46b77e999a65d67d295281d766c28be3ce56f98595d440193280e959"},
+ {140UL, 0, " ", "d034b0d20a0ab15c600c3bffa475d8d4e26d0ecb44a2e8ff671ab3c8"},
+ {141UL, 0, " ", "18342457f26702955f988b84641da1aa2e249478b8aed789588a8067"},
+ {142UL, 0, " ", "99714345f222e6a5a3fea9b6679a4b031b651213309bb5c43abb5f9d"},
+ {143UL, 0, " ", "7bb36d2c61072f1027ce753d8d6e08f6c7d1dab86576c55d7788c49a"},
+ {144UL, 0, " ", "d0f6b2d5d1f6b7c7c7a145226b90a97fa95ab9a3a5e2c444910d6170"},
+ {145UL, 0, " ", "1bff9b25b2f62b91dc72857c128a88bca25a9467f6694d6369c2961c"},
+ {146UL, 0, " ", "084fa64c2119a58d499b49ab41555f8c14cff3a5b3fb81263973fda4"},
+ {147UL, 0, " ", "7f1029071549eef525f187caf9de820b95393183273b34c719282a3d"},
+ {148UL, 0, " ", "059b18008a36d138bc67b1d9fa4c7b9d5250bf52a32a9f87268cfcfa"},
+ {149UL, 0, " ", "41f79bc4faaff75a9706e225fd36c0d04f5b2dd31500c32843ee5fbb"},
+ {150UL, 0, " ", "0884041331c9ccdfbb3bf0ffb104ff6c10442044e4c806daec38f380"},
+ {151UL, 0, " ", "db6d15f6b6e4628829841ccd4e6376e20a72e3a8995b0adffbc00d9f"},
+ {152UL, 0, " ", "9e5855a42bb807b811a4b4dd1f180a42b108a3f2ab1185b319dbe6df"},
+ {153UL, 0, " ", "1ff36fba37665c4dcf6b9975566896ce94b1d8559e1377abc05b885c"},
+ {154UL, 0, " ", "5a4b2fd5abc042870ec8b5412032e743d6e015d56c13e9f9face0c2f"},
+ {155UL, 0, " ", "46b3680f4bef3d4e2baa95422493c33f245e5c95254134a0548f68e3"},
+ {156UL, 0, " ", "834e49322303f470f85c8db3f6cb05a38ebc01a4f4d73573cc9eec79"},
+ {157UL, 0, " ", "0125d8e97087c77e72fc65d621853bbabf01a2aeb0d6c430af696fb3"},
+ {158UL, 0, " ", "d71341e59f3fccdeaed14c7870eda283cfbb5dbd2ec2f0094a3b5615"},
+ {159UL, 0, " ", "c84c32b3aef5d5b83761943e0e7d0f07daa02f4a7138ef5403c3934a"},
+ {160UL, 0, " ", "0fefcac220529ca60db134e9028459abcb8ef0a3d9dfdba582fcfca0"},
+ {161UL, 0, " ", "2027feef15cc3a0310cafbb8bf6b3df9979065e09f8a768bc269bed8"},
+ {162UL, 0, " ", "9ec8a224907e48f1adcb27687baad0e57ecf95058df0adaddc69370f"},
+ {163UL, 0, " ", "fa41e1a483ed9e7b8ba351988543d4c8ce3fe81fca2389b3b090f311"},
+ {164UL, 0, " ", "9e9f8dc4cf2006bea86845bacb9d450fff2d5df033d9f22fc7074e23"},
+ {165UL, 0, " ", "03badc3d8e615d4aba10f377d67d9dc4d95a014f4c28b5aeba4c0331"},
+ {166UL, 0, " ", "1c20b60fde8c3c68f5220333c78bcdecc6feb0b707b82cd456ea1d3b"},
+ {167UL, 0, " ", "5491e0cb786fb4159110c881963848ffbc732a13ca414bd87d4f5a68"},
+ {168UL, 0, " ", "d4a17fc033f1e1680924aeb1261dca3102a089cb817d2e6c498ea925"},
+ {169UL, 0, " ", "992025910bae8adacee7e601f02f6213590551f0bd84f5efc68be041"},
+ {170UL, 0, " ", "1760cd5fe286b53e3e4b17b6f0007e2b6efcc354888bb596177ef8b5"},
+ {171UL, 0, " ", "e700be875d52567a0cababe13d2fe85c0d9d6b3ca3f056e996d453a4"},
+ {172UL, 0, " ", "62dc712ee01eaf97db2fa4194473c4209b915d4456076332bc5a2da2"},
+ {173UL, 0, " ", "0c55c1464697e3dbbb76870b40dff5d6d5268c300d9baa36a6e603bd"},
+ {174UL, 0, " ", "35fdd560c15216f191d9783bb1b5d2caaa09f46fcf9d795a20c57d3b"},
+ {175UL, 0, " ", "adfecfc59b87f1d0d9ca2c7042f7668384119567b80b2b326ce77b84"},
+ {176UL, 0, " ", "422c69d68d00fcdcd4c9d3723f60a8f5c0d4bcabcc8106c2b1cadfae"},
+ {177UL, 0, " ", "481813c9490447df50f7684c392f058ee65d213003e4ca8fd5e1fe0a"},
+ {178UL, 0, " ", "702cd8b7fef21033b3fca367fc1a824aad6075f0db11bf6950e7b287"},
+ {179UL, 0, " ", "67122376b98ee2f5aceb47b43ab4c70e85d9a777757ce09ab9361466"},
+ {180UL, 0, " ", "e81bd70b2a72158614f78110cadd43e943743b9e4cad19227cc2901f"},
+ {181UL, 0, " ", "eb90179b1e6a8e614940e7484ff818bf423163b9e3febd2bde3f99d9"},
+ {182UL, 0, " ", "4670e30c7a073846d4181470d45c774c765265726cd87c3d61314d2e"},
+ {183UL, 0, " ", "8c15ac4278dbebd72ca9f677b67840855e2eb0bf21abd6b4c0c6fc59"},
+ {184UL, 0, " ", "9aac77501210594e973b178102ff0a912cefb5a8c650a3a3026edc97"},
+ {185UL, 0, " ", "c208a94b304b2c2f3c24fcd32b452a034f14e122a916d98a5cac8457"},
+ {186UL, 0, " ", "06faf62b1500cf7bfb97c22f28c0b7b20a061f75f805b89aaa0f8b4b"},
+ {187UL, 0, " ", "1c8a8dc40b0f1743462c8a078a12fe4c2fa470ee11d2ba2977b16457"},
+ {188UL, 0, " ", "278685b0b1db68fc81a5c58c93ad7d5ef3b0b41707fd50e99c6337eb"},
+ {189UL, 0, " ", "bda22e93b44bfa708e37c160d2550591d96bf3169ce6054dfefc4eaa"},
+ {190UL, 0, " ", "27dcd4f271994a8ff77070432d4dc7cfbfe44a3d715ff4784c7042b6"},
+ {191UL, 0, " ", "736d74d010feed3086fee86c7daf96ffb4f7f90bd67c323bf95c6c27"},
+ {192UL, 0, " ", "ff0e655fc2cc4cf5ec5e0a4842cc7eceac0909583fc2bed52d11ed7a"},
+ {193UL, 0, " ", "c9dca1cbe5a57db90be0fb8b96da1f5424fd213c698f5b8bd102557a"},
+ {194UL, 0, " ", "43406909b362eb9f54111e4e4fcd048b1c9a93147d7418d4008ac205"},
+ {195UL, 0, " ", "e6ea6206f13a10326fb177905abcd8085f31958790545ab874434a84"},
+ {196UL, 0, " ", "a4fd3f825de2167cf90811fdc171f14667af83b013018d342d7ac2a1"},
+ {197UL, 0, " ", "36444ff3b3c34c1b9065aa36b9b62ec31f6be00af4dbc688cdb366e7"},
+ {198UL, 0, " ", "bc4dcf21bd02a144773db1bdd63de1f48bd03c222273a9b5bf054926"},
+ {199UL, 0, " ", "0cb650297dbc2160cbc534aa52f6357ded53b234a05f010bbd61c81e"},
+ {200UL, 0, " ", "e879f9f6cdd4280408bafaf08f6175043945c3c8ec1cadef8432f9e6"},
+ {201UL, 0, " ", "820d8ba6fe7f9fd06e09c67210eaa6aacfa51910408d7c34502e29df"},
+ {202UL, 0, " ", "dceaee66685def76fd718e114c5e19435a4bcb370ec5bc8e244c954c"},
+ {203UL, 0, " ", "fe7c8d0059d34e5364a58b13608c503d1808d05e7fe5a19009615116"},
+ {204UL, 0, " ", "4501de44a9359bbfa19685627f98a241d5b6fc107511a727da045dba"},
+ {205UL, 0, " ", "e53ada896a5212c69200acad5c32c9b34552c8961267859af9297ea3"},
+ {206UL, 0, " ", "040d4f155c3d3ce1598f3926572db62055708a7b1cdbc98b49130073"},
+ {207UL, 0, " ", "3d35e459cb26376500cda5f74353e10edc4cdbd3796c6bc7d47fda41"},
+ {208UL, 0, " ", "0f9e5be5cc5af398ad7179adc41e4b8d24d1e291ca823bf6f3c75c9e"},
+ {209UL, 0, " ", "e7d74553892daa5a4588eaf60ce1e37a32c6fdccfa8ce5f90fb6990e"},
+ {210UL, 0, " ", "04957f64cebe1646fdda2c6f3e4161321789b892b901cd18a7497d7f"},
+ {211UL, 0, " ", "45683eeab0e5adc9b24ef9a776809226d8dde2a309e137c57fa773e7"},
+ {212UL, 0, " ", "568aa85b2003c6b13e5236fc0f256808bf080c23c84b3bae9e567d6b"},
+ {213UL, 0, " ", "365660746f5131062f168a91883f8a07a06db1f6336ebfe53d4def69"},
+ {214UL, 0, " ", "42136d0f54c770c73a6cddf00e7cbf4ed82a8777b86cc7c14684e142"},
+ {215UL, 0, " ", "510524ebb3b16b5fb59dd5fca70a99559804086fa9a3f008aa528827"},
+ {216UL, 0, " ", "8fa23e20bf52673db02494a2da8742c31eef7fd691475c64c4416610"},
+ {217UL, 0, " ", "e9256d61424c7f03e14037abbc87fa97dd4826f9c4bce86177474a7c"},
+ {218UL, 0, " ", "3b85b5435cc101ef24e1aba0647f1a848d237010e74baea82767efd6"},
+ {219UL, 0, " ", "378bd933849163a6594cdd93a90c9bb72bfac14f0b8c52affa696c0c"},
+ {220UL, 0, " ", "08bf93fa4ef7da7e49c50794f1868f9a27a3238b8d7dae16435389c4"},
+ {221UL, 0, " ", "ba96b341ab322c9c8a1d473c34f12c67a0e3054185c9ed04346a444d"},
+ {222UL, 0, " ", "399094522a7f468a9791f835c81e5155e2a404938d3540b7b76f9702"},
+ {223UL, 0, " ", "a11fec55ae6a2e04f2dee19d437d0db66e7a5db76baf26b385fd4ca0"},
+ {224UL, 0, " ", "5e5081a215179aaefab0dd558da783e445b57a67196665998d8d46be"},
+ {225UL, 0, " ", "2eb8bc3daed664c24c12c63215a59a005ad177cbf98387f6da5a7db6"},
+ {226UL, 0, " ", "94f104cf8efe1943995a66cab74deb6bb3a8feda71924398f151c751"},
+ {227UL, 0, " ", "c0560542f09724299cc3ef8b282f204a87534d7ee332bf1131c2d100"},
+ {228UL, 0, " ", "3ea4b9c6e1b13f9c2ba48fe545187a531161135addc01e3ce4448174"},
+ {229UL, 0, " ", "4b59dc53b5e3e10990eb2bdd5c9df86713bc09e4c52d2bfa8684856d"},
+ {230UL, 0, " ", "0d1322c2c4d8660bb4e420ca5e24aeab4efb844cdfdfcae7086c024a"},
+ {231UL, 0, " ", "154046fd5d42d559c28933e201b6de7b3460930c87601949374d045b"},
+ {232UL, 0, " ", "094da314a46279a975b2e7dde3f8461fc1a6db835f053fe5d69a7ece"},
+ {233UL, 0, " ", "eea04248aa221bc98e0fae363ec11e714eabac149b3659dfa64f9369"},
+ {234UL, 0, " ", "2e1259b1ccefffc67c1c3ac92b8218bd6e90fea28172531edba1d605"},
+ {235UL, 0, " ", "e5064894b918ba5d6a42ea1b35d45f104e0042eee6498b9889de4ae9"},
+ {236UL, 0, " ", "9e30b504cf8307ad4810ee6361714fa6c18f25268a40c7aed5feb438"},
+ {237UL, 0, " ", "58a083cb59226769d1008f7c27006006cd9b05875a4277391f57d6a3"},
+ {238UL, 0, " ", "589dfbe4d3a0d09e355535a73d6832ffd726afdc85cb6dcaeb2953ca"},
+ {239UL, 0, " ", "b5e94cceedcce99b64606378e9811b3f6f2ea615a1ac52c63bbb19aa"},
+ {240UL, 0, " ", "fb6a4855fa120425fa0b0dada82d52acbb39e9ec8e7e83b3775be115"},
+ {241UL, 0, " ", "c4135ba8ac972cb953e05cdecebd59a6d28da424113db1f1b3d351d8"},
+ {242UL, 0, " ", "93ac0273eb893107ab282fad3d15436c3c8485d5e68a35533d9652c4"},
+ {243UL, 0, " ", "3e71df415a48a0abe6e85d6279f49ee4dbb5ac3e99b3e57b525ec527"},
+ {244UL, 0, " ", "64f2803e60ddf00f9ea1d63c11d75bc5c01544782a5679366902499a"},
+ {245UL, 0, " ", "e1e89e00b7feab9060c360a902a52b536c30c30e2685d46519b75321"},
+ {246UL, 0, " ", "ad28e369fa0085880851b81dded4bc2057563ecb6e011a62f1d804da"},
+ {247UL, 0, " ", "e0442d5399aba8a6037cb68c5f9ce147b31a78beb6225a22a5026813"},
+ {248UL, 0, " ", "98efb15de4d815d6c8ea6e8a2bfb1d6be6ea527f158ca3af900c8274"},
+ {249UL, 0, " ", "a84147783a5fdf69ed4a85a5d466df7795f272fa3e0b560f76ec6e17"},
+ {250UL, 0, " ", "df7b41bfd68c5754f5c5844cce21125e103d18863329772794839771"},
+ {251UL, 0, " ", "85f68577896af03a6c110a5a96d4b5af893fedde7896ca0fc300f0ea"},
+ {252UL, 0, " ", "4df874bebfb8f6bb517a2591c798d12c9a51f618ea34d8133abc8aed"},
+ {253UL, 0, " ", "8d3840a59f4991629d3e22c5aae1b1416064e4752c208ef4d8bc29d7"},
+ {254UL, 0, " ", "ce0ad294e28c8c8b9a30af709cd39dd82995c842489ae5cbafa45b7d"},
+ {255UL, 0, " ", "21bde47a3e44ea0238d07bf5c7f0eafde3fd993773b5c7514b228f95"},
+ {256UL, 0, " ", "f254b95019ae83bcb0ed75b591d2152963971d0331437263de2c0529"},
+ {257UL, 0, " ", "2b5fc8c4c06e954caa54e7f5b3fde9124314896b5f5fcc5f7cfbb5bc"},
+ {258UL, 0, " ", "3c0b272ce7a6890f903826afe5f48609a391c049a4df6fd7de3a3a84"},
+ {259UL, 0, " ", "5e4386132842bb256799a9d469b6eb861916ea8dbc6d06a589f4e6cc"},
+ {260UL, 0, " ", "63aac12d08b9e4bc9c0b00421527e092a03c4e299311f9c0cb201f37"},
+ {261UL, 0, " ", "c292327df2173cd0bbbe87d50c2a3a44c9b912c4c9316ebfca341646"},
+ {262UL, 0, " ", "a3cbd97c8e4361ccc71aa5ba620948fcc2b5fbd3763d6cd6394942d4"},
+ {263UL, 0, " ", "e3cd028df09267d92d647d2720d86db9b94b4b8dcaa82c68b6cf2693"},
+ {264UL, 0, " ", "4867b23bdf67fd66ebc12f3f4b7582969fadb1748cfff4dff1b2aeaa"},
+ {265UL, 0, " ", "414cd976c99967269cc29e58d47461d9d01647e7e2270d2f0db07b7e"},
+ {266UL, 0, " ", "cb11852ed0fb978aee28dd6c6235de809bacd71fb3ef6f0fa78902bf"},
+ {267UL, 0, " ", "fb69179686bbebce15b13bf0500fcc2ca61ca38f7ff54cb013858873"},
+ {268UL, 0, " ", "638d9f85c37b9da8b39cacecb3e5a739b2840e63aab7df64f4f2f23e"},
+ {269UL, 0, " ", "8c57b259d72d7f3388a0e27330f0a8c01bc11a3e969aa3db34000f8f"},
+ {270UL, 0, " ", "f079dd786e5b0caa38cff0832e62cf42d5c6744dc65b17c0c5aeccb2"},
+ {271UL, 0, " ", "e6722d9d5018ead0b9fc7a14f7f2f9fe60889e43d278adbdeff3ad3d"},
+ {272UL, 0, " ", "a0ab2b81776450ff310753db78a03ef6673f67c0d2de815f8d276c49"},
+ {273UL, 0, " ", "e3bac307a12f7b57e5cd5b81faf31d6d3eae200a3a5fc18cad927ae6"},
+ {274UL, 0, " ", "d05704912f6c789320c4a756b1f7ebb79800fbdf7bf363dd3740dcdb"},
+ {275UL, 0, " ", "a4b30d96b234e8b51596f28a66ff18e0405abbcfdd75168b48c5e393"},
+ {276UL, 0, " ", "632da71b1d3bfdffe8ce31dee0c3f761b114dd5296dcb41e108a3531"},
+ {277UL, 0, " ", "19162d2b43b01cb24475f82955978bd8875b4df34cd965a582fe61ed"},
+ {278UL, 0, " ", "98f44bb1257b419f4cbcbc1c15bfa2c98b8c60d604b0c644672c6706"},
+ {279UL, 0, " ", "76aa65f391daafe3abfa3ad4280dd30f9c27bd8297b3d9737c57a0c8"},
+ {280UL, 0, " ", "330bc122c2e49c29952049f7d28cb700e227f7e35c2fe6519e20837d"},
+ {281UL, 0, " ", "b852fb3011ce42b87581a4acce470f361eb64309033f0e693ea3df0b"},
+ {282UL, 0, " ", "9b68b2226c3e539a22d878514dcbdbe63139a9025093ed4c9546d5f7"},
+ {283UL, 0, " ", "7137a0f46f4b673a82b955924c8b1c5bcf9166350fe4e2ffd31f2f6a"},
+ {284UL, 0, " ", "8f896d6341cadfa294d352970747f7161fcf95e661aa8297d39f1cbe"},
+ {285UL, 0, " ", "e44a0c6dda643ba7bbded6179e5541b1fb41221235c67663ce63bc62"},
+ {286UL, 0, " ", "9e3441070fdeabef066d7a8059bdb42d6662d9ddc0aa81b23fa09b67"},
+ {287UL, 0, " ", "4fcc36bbde5ebe0909af8ab543c400320e90b9a22f68e911404e79b1"},
+ {288UL, 0, " ", "be573b027ee2563bea89927c1c30873dee8dc80e30cf7a6f3e7637ff"},
+ {289UL, 0, " ", "a9a31e9b3f6e6a319d3997d60065b23d2295a723a99401f9f18fbe23"},
+ {290UL, 0, " ", "10ca78c979abc3bf008b53f55578389fcf971828bd222bfb0b0dba36"},
+ {291UL, 0, " ", "c93ff60f10edfbad2ec2e5dc962d9c8661dcaf35de83c7697b676b19"},
+ {292UL, 0, " ", "ef7b2c084dc0a4b114e927faa5ac73f26cc800e6fd5bb1ea4bf5cdb6"},
+ {293UL, 0, " ", "8fa5fb1f8efb64417f1f259490b4c9ceffd5b6b084e2f411c8ad39a7"},
+ {294UL, 0, " ", "cd02115f81d1210bd25c93255cdcdc39bb5702604a80bd37340742d0"},
+ {295UL, 0, " ", "6b4d5c817c648e778afc58894dfe4d4f891689759008c8a69d9685cb"},
+ {296UL, 0, " ", "8345df0eab6b16e1a44ead077328b164cd75ccc658d607848403ca99"},
+ {297UL, 0, " ", "b44daf778c692695217f1b54d711a6ef4d2b61634969344dce51b630"},
+ {298UL, 0, " ", "db3127d5b76149309a56db6569f066aec01ae8535d60adf57c3281c6"},
+ {299UL, 0, " ", "b5b32e77ee3e7513cda85d1d59ba761942f45259efdca91083072d04"},
+ {300UL, 0, " ", "35efd6428af373b1a129f471b8af317a28bb1669d8a7884d29653f63"},
+ {301UL, 0, " ", "7c665d57c853a1d43dd6ef6bf7068c3dd445c8b84b88ebd3a1d2d3b9"},
+ {302UL, 0, " ", "e39774432075fec2958d8a57c2a690a509493fe1553b66f8457b1963"},
+ {303UL, 0, " ", "ed5cfc6b074d185714c19825ab33081d6ab7e9b477d1219fe54b4b9c"},
+ {304UL, 0, " ", "0a5298110a1fcea7d8c1a1c638ac38704bc4671b4be4ce832bc4498a"},
+ {305UL, 0, " ", "e21c6a29c9a92ad78d7602e92c394db80d7fc4d09a5c86ede8f03d8e"},
+ {306UL, 0, " ", "3e0584a09c07839d94357e8d596c6d675fc352bad8894213c876826b"},
+ {307UL, 0, " ", "692e50890534f51426c4ce2ff5db0b44a28f9f58b03d8d2bd6fb00f5"},
+ {308UL, 0, " ", "dc1a17a25b78cb666580f06359589652530ac639801141fa7aad917b"},
+ {309UL, 0, " ", "9909d62bb9d4aea57ce6ce6cb7097da1d78a5284d48ebb65398ab1bb"},
+ {310UL, 0, " ", "0a81e94d03e7651217167df3512277c065bbdc0bdf22ef91153a4602"},
+ {311UL, 0, " ", "6a9e9048072ff95fa14493acbf1a10c572f38abe32991f6c0e18b64c"},
+ {312UL, 0, " ", "559fb367be5eb06a2078bc5448b796f389821540bb8ee44495fb858a"},
+ {313UL, 0, " ", "3210c0035698c9861111cd6c8ba68a3fdb2539554b797225faf4c472"},
+ {314UL, 0, " ", "579ec84c0623b3ad7402e6c056a9ac53453e2eee84dd3b30ac07b967"},
+ {315UL, 0, " ", "6cabec5717d36a76909bdf1090aab017cde5476f7dd3f1b431b84005"},
+ {316UL, 0, " ", "3ceb3c7f75a934bd7d195d1bd000115672c5cd19b28c696ac3c0dd4f"},
+ {317UL, 0, " ", "f16bba90866a163f5ffb0deecaf2f5e7e9a46c5580fa43a9912d8d4e"},
+ {318UL, 0, " ", "43dac236cb4e71c80c89e8c60e04372e2622510589e856aed71710d4"},
+ {319UL, 0, " ", "fa526a826144bec9c9aca05f81d0c1538033e20542a97ea4b8b6cd47"},
+ {320UL, 0, " ", "280cd257d0c4c9a4681d71743a7016e9acd7acec4d09dcd6afa05be2"},
+ {1, 0, "withdrew hypothesis snakebird qmc2", "22c8017ac8bcf65f59d1b7e92c9d4c6739d25e34ce5cb608b24ff096"},
+ {1, 0, "intensifierat sturdiness perl-image-exiftool vingla", "43808dde2662143dc4eed5dac5e98c74b06711829f02a3b121bd74f3"},
+ {1, 0, "timjan avogadro uppdriven lib32-llvm-amdgpu-snapshot", "d32b4ac86065774dee5eb5cdd2f67b4e86501086d7373884e8b20a36"},
+ {1, 0, "grilo-plugins auditorium tull dissimilarity's", "efbd76d45bfa952485148f8ad46143897f17c27ffdc8eb7287f9353b"},
+ {1, 0, "royalty tt yellowstone deficiencies", "6705aa36ecf58f333e0e6364ac1d0b7931d402e13282127cfd6f876c"},
+ {1, 0, "kdegames-kdiamond tunisisk occurrence's outtalad", "803a0ff09dda0df306e483a9f91b20a3dbbf9c2ebb8d0a3b28f3b9e0"},
+ {1, 0, "chevalier slat's spindel representations", "a64779aca943a6aef1d2e7c9a0f4e997f4dabd1f77112a22121d3ed5"},
+ {1, 0, "archery lexicographical equine veered", "f0a3e0587af7723f0aa4719059d3f5107115a5b3667cd5209cc4d867"},
+ {1, 0, "splay washbasin opposing there", "312e7e3c6403ab1a086155fb9a52b22a3d0d257876afd2b93fb7272e"},
+ {1, 0, "faktum desist thundered klen", "270ba05b764221ff5b5d94adfb4fdb1f36f07fe7c438904a5f3df071"}
+};
+
+
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
+int
+main(void)
+{
+ TEST_MAIN("SHA3-224", SHA3_224);
+}
diff --git a/sha3_256.c b/sha3_256.c
new file mode 100644
index 0000000..40614f6
--- /dev/null
+++ b/sha3_256.c
@@ -0,0 +1,22 @@
+/* See LICENSE file for copyright and license details. */
+#ifdef SUPPORT_SHA3
+# define TEST
+# include "common.h"
+
+
+static struct testcase testcases[] = {
+ {1, 0, "", "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a"},
+};
+
+
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
+int
+main(void)
+{
+ TEST_MAIN("SHA3-256", SHA3_256);
+}
diff --git a/sha3_384.c b/sha3_384.c
new file mode 100644
index 0000000..367c5ed
--- /dev/null
+++ b/sha3_384.c
@@ -0,0 +1,22 @@
+/* See LICENSE file for copyright and license details. */
+#ifdef SUPPORT_SHA3
+# define TEST
+# include "common.h"
+
+
+static struct testcase testcases[] = {
+ {1, 0, "", "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004"},
+};
+
+
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
+int
+main(void)
+{
+ TEST_MAIN("SHA3-384", SHA3_384);
+}
diff --git a/sha3_512.c b/sha3_512.c
new file mode 100644
index 0000000..cda82ed
--- /dev/null
+++ b/sha3_512.c
@@ -0,0 +1,24 @@
+/* See LICENSE file for copyright and license details. */
+#ifdef SUPPORT_SHA3
+# define TEST
+# include "common.h"
+
+
+static struct testcase testcases[] = {
+ {1, 0, "",
+ "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a6"
+ "15b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26"},
+};
+
+
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
+int
+main(void)
+{
+ TEST_MAIN("SHA3-512", SHA3_512);
+}