aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile89
-rw-r--r--common.h38
-rw-r--r--digest.c51
-rw-r--r--extra/libkeccak_state_copy.c (renamed from libkeccak_state_copy.c)2
-rw-r--r--extra/libkeccak_state_create.c (renamed from libkeccak_state_create.c)2
-rw-r--r--extra/libkeccak_state_duplicate.c (renamed from libkeccak_state_duplicate.c)2
-rw-r--r--extra/libkeccak_state_fast_free.c (renamed from libkeccak_state_fast_free.c)2
-rw-r--r--extra/libkeccak_state_free.c (renamed from libkeccak_state_free.c)2
-rw-r--r--extra/libkeccak_state_marshal.c (renamed from libkeccak_state_marshal.c)2
-rw-r--r--extra/libkeccak_state_reset.c (renamed from libkeccak_state_reset.c)2
-rw-r--r--extra/libkeccak_state_unmarshal.c (renamed from libkeccak_state_unmarshal.c)2
-rw-r--r--extra/libkeccak_state_wipe.c (renamed from libkeccak_state_wipe.c)4
-rw-r--r--extra/libkeccak_state_wipe_message.c (renamed from libkeccak_state_wipe_message.c)4
-rw-r--r--extra/libkeccak_state_wipe_sponge.c (renamed from libkeccak_state_wipe_sponge.c)4
-rw-r--r--hmac/libkeccak_hmac_copy.c (renamed from libkeccak_hmac_copy.c)2
-rw-r--r--hmac/libkeccak_hmac_create.c (renamed from libkeccak_hmac_create.c)2
-rw-r--r--hmac/libkeccak_hmac_destroy.c (renamed from libkeccak_hmac_destroy.c)2
-rw-r--r--hmac/libkeccak_hmac_digest.c (renamed from libkeccak_hmac_digest.c)2
-rw-r--r--hmac/libkeccak_hmac_duplicate.c (renamed from libkeccak_hmac_duplicate.c)2
-rw-r--r--hmac/libkeccak_hmac_fast_destroy.c (renamed from libkeccak_hmac_fast_destroy.c)2
-rw-r--r--hmac/libkeccak_hmac_fast_digest.c (renamed from libkeccak_hmac_fast_digest.c)2
-rw-r--r--hmac/libkeccak_hmac_fast_free.c (renamed from libkeccak_hmac_fast_free.c)2
-rw-r--r--hmac/libkeccak_hmac_fast_update.c (renamed from libkeccak_hmac_fast_update.c)2
-rw-r--r--hmac/libkeccak_hmac_free.c (renamed from libkeccak_hmac_free.c)2
-rw-r--r--hmac/libkeccak_hmac_initialise.c (renamed from libkeccak_hmac_initialise.c)2
-rw-r--r--hmac/libkeccak_hmac_marshal.c (renamed from libkeccak_hmac_marshal.c)2
-rw-r--r--hmac/libkeccak_hmac_reset.c (renamed from libkeccak_hmac_reset.c)2
-rw-r--r--hmac/libkeccak_hmac_set_key.c (renamed from libkeccak_hmac_set_key.c)2
-rw-r--r--hmac/libkeccak_hmac_unmarshal.c (renamed from libkeccak_hmac_unmarshal.c)2
-rw-r--r--hmac/libkeccak_hmac_update.c (renamed from libkeccak_hmac_update.c)2
-rw-r--r--hmac/libkeccak_hmac_wipe.c (renamed from libkeccak_hmac_wipe.c)2
-rw-r--r--libkeccak.h188
-rw-r--r--libkeccak/extra.h140
-rw-r--r--spec/libkeccak_cshake_suffix.c (renamed from libkeccak_cshake_suffix.c)2
-rw-r--r--spec/libkeccak_degeneralise_spec.c (renamed from libkeccak_degeneralise_spec.c)2
-rw-r--r--spec/libkeccak_generalised_spec_initialise.c (renamed from libkeccak_generalised_spec_initialise.c)2
-rw-r--r--spec/libkeccak_spec_check.c (renamed from libkeccak_spec_check.c)2
-rw-r--r--spec/libkeccak_spec_rawshake.c (renamed from libkeccak_spec_rawshake.c)2
-rw-r--r--spec/libkeccak_spec_sha3.c (renamed from libkeccak_spec_sha3.c)2
-rw-r--r--util/libkeccak_behex_lower.c (renamed from libkeccak_behex_lower.c)2
-rw-r--r--util/libkeccak_behex_upper.c (renamed from libkeccak_behex_upper.c)2
-rw-r--r--util/libkeccak_generalised_sum_fd.c (renamed from libkeccak_generalised_sum_fd.c)2
-rw-r--r--util/libkeccak_keccaksum_fd.c (renamed from libkeccak_keccaksum_fd.c)2
-rw-r--r--util/libkeccak_rawshakesum_fd.c (renamed from libkeccak_rawshakesum_fd.c)2
-rw-r--r--util/libkeccak_sha3sum_fd.c (renamed from libkeccak_sha3sum_fd.c)2
-rw-r--r--util/libkeccak_shakesum_fd.c (renamed from libkeccak_shakesum_fd.c)2
-rw-r--r--util/libkeccak_unhex.c (renamed from libkeccak_unhex.c)2
47 files changed, 321 insertions, 275 deletions
diff --git a/Makefile b/Makefile
index 6db74cf..1897ce4 100644
--- a/Makefile
+++ b/Makefile
@@ -19,53 +19,53 @@ LIB_VERSION = $(LIB_MAJOR).$(LIB_MINOR)
OBJ =\
digest.o\
- libkeccak_behex_lower.o\
- libkeccak_behex_upper.o\
libkeccak_cshake_initialise.o\
- libkeccak_cshake_suffix.o\
- libkeccak_degeneralise_spec.o\
- libkeccak_generalised_spec_initialise.o\
- libkeccak_generalised_sum_fd.o\
- libkeccak_hmac_copy.o\
- libkeccak_hmac_create.o\
- libkeccak_hmac_destroy.o\
- libkeccak_hmac_digest.o\
- libkeccak_hmac_duplicate.o\
- libkeccak_hmac_fast_destroy.o\
- libkeccak_hmac_fast_digest.o\
- libkeccak_hmac_fast_free.o\
- libkeccak_hmac_fast_update.o\
- libkeccak_hmac_free.o\
- libkeccak_hmac_initialise.o\
- libkeccak_hmac_marshal.o\
- libkeccak_hmac_reset.o\
- libkeccak_hmac_set_key.o\
- libkeccak_hmac_unmarshal.o\
- libkeccak_hmac_update.o\
- libkeccak_hmac_wipe.o\
- libkeccak_keccaksum_fd.o\
- libkeccak_rawshakesum_fd.o\
- libkeccak_sha3sum_fd.o\
- libkeccak_shakesum_fd.o\
- libkeccak_spec_check.o\
- libkeccak_spec_rawshake.o\
- libkeccak_spec_sha3.o\
- libkeccak_state_copy.o\
- libkeccak_state_create.o\
libkeccak_state_destroy.o\
- libkeccak_state_duplicate.o\
libkeccak_state_fast_destroy.o\
- libkeccak_state_fast_free.o\
- libkeccak_state_free.o\
libkeccak_state_initialise.o\
- libkeccak_state_marshal.o\
- libkeccak_state_reset.o\
- libkeccak_state_unmarshal.o\
- libkeccak_state_wipe.o\
- libkeccak_state_wipe_message.o\
- libkeccak_state_wipe_sponge.o\
- libkeccak_unhex.o\
- libkeccak_zerocopy_chunksize.o
+ libkeccak_zerocopy_chunksize.o\
+ extra/libkeccak_state_copy.o\
+ extra/libkeccak_state_create.o\
+ extra/libkeccak_state_duplicate.o\
+ extra/libkeccak_state_fast_free.o\
+ extra/libkeccak_state_free.o\
+ extra/libkeccak_state_marshal.o\
+ extra/libkeccak_state_reset.o\
+ extra/libkeccak_state_unmarshal.o\
+ extra/libkeccak_state_wipe.o\
+ extra/libkeccak_state_wipe_message.o\
+ extra/libkeccak_state_wipe_sponge.o\
+ hmac/libkeccak_hmac_copy.o\
+ hmac/libkeccak_hmac_create.o\
+ hmac/libkeccak_hmac_destroy.o\
+ hmac/libkeccak_hmac_digest.o\
+ hmac/libkeccak_hmac_duplicate.o\
+ hmac/libkeccak_hmac_fast_destroy.o\
+ hmac/libkeccak_hmac_fast_digest.o\
+ hmac/libkeccak_hmac_fast_free.o\
+ hmac/libkeccak_hmac_fast_update.o\
+ hmac/libkeccak_hmac_free.o\
+ hmac/libkeccak_hmac_initialise.o\
+ hmac/libkeccak_hmac_marshal.o\
+ hmac/libkeccak_hmac_reset.o\
+ hmac/libkeccak_hmac_set_key.o\
+ hmac/libkeccak_hmac_unmarshal.o\
+ hmac/libkeccak_hmac_update.o\
+ hmac/libkeccak_hmac_wipe.o\
+ spec/libkeccak_cshake_suffix.o\
+ spec/libkeccak_degeneralise_spec.o\
+ spec/libkeccak_generalised_spec_initialise.o\
+ spec/libkeccak_spec_check.o\
+ spec/libkeccak_spec_rawshake.o\
+ spec/libkeccak_spec_sha3.o\
+ util/libkeccak_behex_lower.o\
+ util/libkeccak_behex_upper.o\
+ util/libkeccak_generalised_sum_fd.o\
+ util/libkeccak_keccaksum_fd.o\
+ util/libkeccak_rawshakesum_fd.o\
+ util/libkeccak_sha3sum_fd.o\
+ util/libkeccak_shakesum_fd.o\
+ util/libkeccak_unhex.o
HDR =\
libkeccak.h\
@@ -78,6 +78,7 @@ SUBHDR =\
libkeccak/rawshake.h\
libkeccak/shake.h\
libkeccak/cshake.h\
+ libkeccak/extra.h\
libkeccak/hmac.h\
libkeccak/legacy.h\
libkeccak/util.h
@@ -214,7 +215,7 @@ uninstall:
-rm -rf -- "$(DESTDIR)$(PREFIX)/share/licenses/libkeccak"
clean:
- -rm -f -- *.o *.su test benchmark benchfile
+ -rm -f -- *.o *.su */*.o */*.su test benchmark benchfile
-rm -f -- *.a libkeccak.$(LIBEXT) libkeccak.$(LIBEXT).* libkeccak.*.$(LIBEXT)
.SUFFIXES:
diff --git a/common.h b/common.h
index 4b95a06..96df9e7 100644
--- a/common.h
+++ b/common.h
@@ -33,6 +33,44 @@
/**
+ * Literal comma that can be passed as a macro argument
+ */
+#define COMMA ,
+
+/**
+ * X-macro-enabled listing of all intergers in [0, 4]
+ *
+ * @param X(int) The macro to expand 5 times
+ * @param D Code to insert between each expansion of `X`
+ */
+#define LIST_5(X, D)\
+ X(0) D X(1) D X(2) D X(3) D X(4)
+
+/**
+ * X-macro-enabled listing of all intergers in [0, 7]
+ *
+ * @param X(int) The macro to expand 8 times
+ * @param D Code to insert between each expansion of `X`
+ */
+#define LIST_8(X, D)\
+ X(0) D X(1) D X(2) D X(3) D X(4) D\
+ X(5) D X(6) D X(7)
+
+/**
+ * X-macro-enabled listing of all intergers in [0, 24]
+ *
+ * @param X(int) The macro to expand 25 times
+ * @param D Code to insert between each expansion of `X`
+ */
+#define LIST_25(X, D)\
+ X( 0) D X( 1) D X( 2) D X( 3) D X( 4) D\
+ X( 5) D X( 6) D X( 7) D X( 8) D X( 9) D\
+ X(10) D X(11) D X(12) D X(13) D X(14) D\
+ X(15) D X(16) D X(17) D X(18) D X(19) D\
+ X(20) D X(21) D X(22) D X(23) D X(24)
+
+
+/**
* The outer pad pattern for HMAC
*/
#define HMAC_OUTER_PAD 0x5C
diff --git a/digest.c b/digest.c
index 6a81f80..7ee744a 100644
--- a/digest.c
+++ b/digest.c
@@ -2,34 +2,15 @@
#include "common.h"
-/**
- * X-macro-enabled listing of all intergers in [0, 4]
- */
-#define LIST_5 X(0) X(1) X(2) X(3) X(4)
-
-/**
- * X-macro-enabled listing of all intergers in [0, 7]
- */
-#define LIST_8 LIST_5 X(5) X(6) X(7)
-
-/**
- * X-macro-enabled listing of all intergers in [0, 24]
- */
-#define LIST_25 LIST_8 X(8) X(9) X(10) X(11) X(12) X(13) X(14) X(15)\
- X(16) X(17) X(18) X(19) X(20) X(21) X(22) X(23) X(24)
-
-
-
-#define X(N) (N % 5) * 5 + N / 5,
+#define X(N) (N % 5) * 5 + N / 5
/**
* The order the lanes should be read when absorbing or squeezing,
* it transposes the lanes in the sponge
*/
-static const long int LANE_TRANSPOSE_MAP[] = { LIST_25 };
+static const long int LANE_TRANSPOSE_MAP[] = { LIST_25(X, COMMA) };
#undef X
-
/**
* Keccak-f round constants
*/
@@ -83,8 +64,8 @@ libkeccak_f_round(register struct libkeccak_state *state, register int_fast64_t
long int w = state->w;
/* θ step (step 1 of 3). */
-#define X(N) C[N] = A[N * 5] ^ A[N * 5 + 1] ^ A[N * 5 + 2] ^ A[N * 5 + 3] ^ A[N * 5 + 4];
- LIST_5
+#define X(N) C[N] = A[N * 5] ^ A[N * 5 + 1] ^ A[N * 5 + 2] ^ A[N * 5 + 3] ^ A[N * 5 + 4]
+ LIST_5(X, ;);
#undef X
/* θ step (step 2 of 3). */
@@ -104,8 +85,8 @@ libkeccak_f_round(register struct libkeccak_state *state, register int_fast64_t
#undef X
/* ξ step. */
-#define X(N) A[N] = B[N] ^ ((~(B[(N + 5) % 25])) & B[(N + 10) % 25]);
- LIST_25
+#define X(N) A[N] = B[N] ^ ((~(B[(N + 5) % 25])) & B[(N + 10) % 25])
+ LIST_25(X, ;);
#undef X
/* ι step. */
@@ -129,8 +110,8 @@ libkeccak_f_round64(register struct libkeccak_state *state, register int_fast64_
int_fast64_t da, db, dc, dd, de;
/* θ step (step 1 of 3). */
-#define X(N) C[N] = A[N * 5] ^ A[N * 5 + 1] ^ A[N * 5 + 2] ^ A[N * 5 + 3] ^ A[N * 5 + 4];
- LIST_5
+#define X(N) C[N] = A[N * 5] ^ A[N * 5 + 1] ^ A[N * 5 + 2] ^ A[N * 5 + 3] ^ A[N * 5 + 4]
+ LIST_5(X, ;);
#undef X
/* θ step (step 2 of 3). */
@@ -150,8 +131,8 @@ libkeccak_f_round64(register struct libkeccak_state *state, register int_fast64_
#undef X
/* ξ step. */
-#define X(N) A[N] = B[N] ^ ((~(B[(N + 5) % 25])) & B[(N + 10) % 25]);
- LIST_25
+#define X(N) A[N] = B[N] ^ ((~(B[(N + 5) % 25])) & B[(N + 10) % 25])
+ LIST_25(X, ;);
#undef X
/* ι step. */
@@ -224,8 +205,8 @@ libkeccak_to_lane64(register const unsigned char *message, register size_t msgle
int_fast64_t rc = 0;
message += off;
#define X(N) if (__builtin_expect(N < n, 1)) rc |= (int_fast64_t)(unsigned char)(message[N]) << (N * 8);\
- else return rc;
- LIST_8
+ else return rc
+ LIST_8(X, ;);
#undef X
return rc;
}
@@ -284,8 +265,8 @@ libkeccak_absorption_phase(register struct libkeccak_state *restrict state,
register long int n = (long)len / rr;
if (__builtin_expect(ww >= 8, 1)) { /* ww > 8 is impossible, it is just for optimisation possibilities. */
while (n--) {
-#define X(N) state->S[N] ^= libkeccak_to_lane64(message, len, rr, (size_t)(LANE_TRANSPOSE_MAP[N] * 8));
- LIST_25
+#define X(N) state->S[N] ^= libkeccak_to_lane64(message, len, rr, (size_t)(LANE_TRANSPOSE_MAP[N] * 8))
+ LIST_25(X, ;);
#undef X
libkeccak_f(state);
message += (size_t)rr;
@@ -293,8 +274,8 @@ libkeccak_absorption_phase(register struct libkeccak_state *restrict state,
}
} else {
while (n--) {
-#define X(N) state->S[N] ^= libkeccak_to_lane(message, len, rr, ww, (size_t)(LANE_TRANSPOSE_MAP[N] * ww));
- LIST_25
+#define X(N) state->S[N] ^= libkeccak_to_lane(message, len, rr, ww, (size_t)(LANE_TRANSPOSE_MAP[N] * ww))
+ LIST_25(X, ;);
#undef X
libkeccak_f(state);
message += (size_t)rr;
diff --git a/libkeccak_state_copy.c b/extra/libkeccak_state_copy.c
index abec573..950fc91 100644
--- a/libkeccak_state_copy.c
+++ b/extra/libkeccak_state_copy.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
/**
diff --git a/libkeccak_state_create.c b/extra/libkeccak_state_create.c
index b5a6990..eda9011 100644
--- a/libkeccak_state_create.c
+++ b/extra/libkeccak_state_create.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
/**
diff --git a/libkeccak_state_duplicate.c b/extra/libkeccak_state_duplicate.c
index 75f85da..3d90d02 100644
--- a/libkeccak_state_duplicate.c
+++ b/extra/libkeccak_state_duplicate.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
/**
diff --git a/libkeccak_state_fast_free.c b/extra/libkeccak_state_fast_free.c
index db2e44f..af75e39 100644
--- a/libkeccak_state_fast_free.c
+++ b/extra/libkeccak_state_fast_free.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline void libkeccak_state_fast_free(struct libkeccak_state *);
diff --git a/libkeccak_state_free.c b/extra/libkeccak_state_free.c
index 41e635e..6a879b3 100644
--- a/libkeccak_state_free.c
+++ b/extra/libkeccak_state_free.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline void libkeccak_state_free(volatile struct libkeccak_state *);
diff --git a/libkeccak_state_marshal.c b/extra/libkeccak_state_marshal.c
index 480b4a4..7541164 100644
--- a/libkeccak_state_marshal.c
+++ b/extra/libkeccak_state_marshal.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
#if defined(__clang__)
diff --git a/libkeccak_state_reset.c b/extra/libkeccak_state_reset.c
index bfbbfbd..44eb5a4 100644
--- a/libkeccak_state_reset.c
+++ b/extra/libkeccak_state_reset.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline void libkeccak_state_reset(struct libkeccak_state *);
diff --git a/libkeccak_state_unmarshal.c b/extra/libkeccak_state_unmarshal.c
index f9604a2..4714566 100644
--- a/libkeccak_state_unmarshal.c
+++ b/extra/libkeccak_state_unmarshal.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
#if defined(__clang__)
diff --git a/libkeccak_state_wipe.c b/extra/libkeccak_state_wipe.c
index e46a25d..728f72f 100644
--- a/libkeccak_state_wipe.c
+++ b/extra/libkeccak_state_wipe.c
@@ -1,9 +1,9 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
/**
- * Wipe sensitive data wihout freeing any data
+ * Wipe sensitive data without freeing any data
*
* @param state The state that should be wipe
*/
diff --git a/libkeccak_state_wipe_message.c b/extra/libkeccak_state_wipe_message.c
index 135960c..364eb8e 100644
--- a/libkeccak_state_wipe_message.c
+++ b/extra/libkeccak_state_wipe_message.c
@@ -1,9 +1,9 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
/**
- * Wipe data in the state's message wihout freeing any data
+ * Wipe data in the state's message without freeing any data
*
* @param state The state that should be wipe
*/
diff --git a/libkeccak_state_wipe_sponge.c b/extra/libkeccak_state_wipe_sponge.c
index f57ec26..91e845a 100644
--- a/libkeccak_state_wipe_sponge.c
+++ b/extra/libkeccak_state_wipe_sponge.c
@@ -1,9 +1,9 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
/**
- * Wipe data in the state's sponge wihout freeing any data
+ * Wipe data in the state's sponge without freeing any data
*
* @param state The state that should be wipe
*/
diff --git a/libkeccak_hmac_copy.c b/hmac/libkeccak_hmac_copy.c
index 6c61553..8a4077b 100644
--- a/libkeccak_hmac_copy.c
+++ b/hmac/libkeccak_hmac_copy.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
/**
diff --git a/libkeccak_hmac_create.c b/hmac/libkeccak_hmac_create.c
index 15286b6..ef6f025 100644
--- a/libkeccak_hmac_create.c
+++ b/hmac/libkeccak_hmac_create.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline struct libkeccak_hmac_state *libkeccak_hmac_create(const struct libkeccak_spec *restrict, const void *restrict, size_t);
diff --git a/libkeccak_hmac_destroy.c b/hmac/libkeccak_hmac_destroy.c
index 9444c0d..f2d7419 100644
--- a/libkeccak_hmac_destroy.c
+++ b/hmac/libkeccak_hmac_destroy.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline void libkeccak_hmac_destroy(volatile struct libkeccak_hmac_state *);
diff --git a/libkeccak_hmac_digest.c b/hmac/libkeccak_hmac_digest.c
index 2e1732f..a9e3609 100644
--- a/libkeccak_hmac_digest.c
+++ b/hmac/libkeccak_hmac_digest.c
@@ -1,6 +1,6 @@
/* See LICENSE file for copyright and license details. */
#define NEED_EXPLICIT_BZERO 1
-#include "common.h"
+#include "../common.h"
/**
diff --git a/libkeccak_hmac_duplicate.c b/hmac/libkeccak_hmac_duplicate.c
index 6c07854..959eae9 100644
--- a/libkeccak_hmac_duplicate.c
+++ b/hmac/libkeccak_hmac_duplicate.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline struct libkeccak_hmac_state *libkeccak_hmac_duplicate(const struct libkeccak_hmac_state *);
diff --git a/libkeccak_hmac_fast_destroy.c b/hmac/libkeccak_hmac_fast_destroy.c
index 529175e..7d9feab 100644
--- a/libkeccak_hmac_fast_destroy.c
+++ b/hmac/libkeccak_hmac_fast_destroy.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline void libkeccak_hmac_fast_destroy(struct libkeccak_hmac_state *);
diff --git a/libkeccak_hmac_fast_digest.c b/hmac/libkeccak_hmac_fast_digest.c
index db242a5..dc98136 100644
--- a/libkeccak_hmac_fast_digest.c
+++ b/hmac/libkeccak_hmac_fast_digest.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
/**
diff --git a/libkeccak_hmac_fast_free.c b/hmac/libkeccak_hmac_fast_free.c
index 897f6e1..5a38207 100644
--- a/libkeccak_hmac_fast_free.c
+++ b/hmac/libkeccak_hmac_fast_free.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline void libkeccak_hmac_fast_free(struct libkeccak_hmac_state *);
diff --git a/libkeccak_hmac_fast_update.c b/hmac/libkeccak_hmac_fast_update.c
index 50c34dd..fe163b7 100644
--- a/libkeccak_hmac_fast_update.c
+++ b/hmac/libkeccak_hmac_fast_update.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
/**
diff --git a/libkeccak_hmac_free.c b/hmac/libkeccak_hmac_free.c
index 2e8e3fb..d31e3a8 100644
--- a/libkeccak_hmac_free.c
+++ b/hmac/libkeccak_hmac_free.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline void libkeccak_hmac_free(volatile struct libkeccak_hmac_state *);
diff --git a/libkeccak_hmac_initialise.c b/hmac/libkeccak_hmac_initialise.c
index b2f2552..ca71860 100644
--- a/libkeccak_hmac_initialise.c
+++ b/hmac/libkeccak_hmac_initialise.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline int
diff --git a/libkeccak_hmac_marshal.c b/hmac/libkeccak_hmac_marshal.c
index 604bde2..acd8f63 100644
--- a/libkeccak_hmac_marshal.c
+++ b/hmac/libkeccak_hmac_marshal.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline size_t libkeccak_hmac_marshal(const struct libkeccak_hmac_state *restrict, void *restrict);
diff --git a/libkeccak_hmac_reset.c b/hmac/libkeccak_hmac_reset.c
index 13d7c0e..b6eccf5 100644
--- a/libkeccak_hmac_reset.c
+++ b/hmac/libkeccak_hmac_reset.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline int libkeccak_hmac_reset(struct libkeccak_hmac_state *restrict, const void *restrict, size_t);
diff --git a/libkeccak_hmac_set_key.c b/hmac/libkeccak_hmac_set_key.c
index 2795e4f..e329f5b 100644
--- a/libkeccak_hmac_set_key.c
+++ b/hmac/libkeccak_hmac_set_key.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
/**
diff --git a/libkeccak_hmac_unmarshal.c b/hmac/libkeccak_hmac_unmarshal.c
index 070c7b5..ddada17 100644
--- a/libkeccak_hmac_unmarshal.c
+++ b/hmac/libkeccak_hmac_unmarshal.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
#if defined(__clang__)
# pragma clang diagnostic ignored "-Wcast-align"
diff --git a/libkeccak_hmac_update.c b/hmac/libkeccak_hmac_update.c
index 6f38348..1717390 100644
--- a/libkeccak_hmac_update.c
+++ b/hmac/libkeccak_hmac_update.c
@@ -1,6 +1,6 @@
/* See LICENSE file for copyright and license details. */
#define NEED_EXPLICIT_BZERO 1
-#include "common.h"
+#include "../common.h"
/**
diff --git a/libkeccak_hmac_wipe.c b/hmac/libkeccak_hmac_wipe.c
index 11d268a..ec0be2d 100644
--- a/libkeccak_hmac_wipe.c
+++ b/hmac/libkeccak_hmac_wipe.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
/**
diff --git a/libkeccak.h b/libkeccak.h
index 081e9e2..670c69e 100644
--- a/libkeccak.h
+++ b/libkeccak.h
@@ -16,7 +16,6 @@
#endif
-
/**
* Only include some C code if compiling with GCC.
*
@@ -50,6 +49,7 @@ struct libkeccak_spec {
long int output;
};
+
/**
* Data structure that describes the state of a hashing process
*
@@ -117,6 +117,7 @@ struct libkeccak_state {
unsigned char *M;
};
+
/**
* Initialise a state according to hashing specifications
*
@@ -128,154 +129,6 @@ LIBKECCAK_GCC_ONLY(__attribute__((__leaf__, __nonnull__)))
int libkeccak_state_initialise(struct libkeccak_state *, const struct libkeccak_spec *);
/**
- * Reset a state according to hashing specifications
- *
- * @param state The state that should be reset
- */
-LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__)))
-inline void
-libkeccak_state_reset(struct libkeccak_state *state)
-{
- state->mptr = 0;
- memset(state->S, 0, sizeof(state->S));
-}
-
-/**
- * Release resources allocation for a state without wiping sensitive data
- *
- * @param state The state that should be destroyed
- */
-inline void
-libkeccak_state_fast_destroy(struct libkeccak_state *state)
-{
- if (state) {
- free(state->M);
- state->M = NULL;
- }
-}
-
-/**
- * Wipe data in the state's message wihout freeing any data
- *
- * @param state The state that should be wipe
- */
-LIBKECCAK_GCC_ONLY(__attribute__((__leaf__, __nonnull__, __nothrow__, __optimize__("-O0"))))
-void libkeccak_state_wipe_message(volatile struct libkeccak_state *);
-
-/**
- * Wipe data in the state's sponge wihout freeing any data
- *
- * @param state The state that should be wipe
- */
-LIBKECCAK_GCC_ONLY(__attribute__((__leaf__, __nonnull__, __nothrow__, __optimize__("-O0"))))
-void libkeccak_state_wipe_sponge(volatile struct libkeccak_state *);
-
-/**
- * Wipe sensitive data wihout freeing any data
- *
- * @param state The state that should be wipe
- */
-LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__, __optimize__("-O0"))))
-void libkeccak_state_wipe(volatile struct libkeccak_state *);
-
-/**
- * Release resources allocation for a state and wipe sensitive data
- *
- * @param state The state that should be destroyed
- */
-LIBKECCAK_GCC_ONLY(__attribute__((__optimize__("-O0"))))
-inline void
-libkeccak_state_destroy(volatile struct libkeccak_state *state)
-{
- if (state) {
- libkeccak_state_wipe(state);
- free(state->M);
- state->M = NULL;
- }
-}
-
-/**
- * Wrapper for `libkeccak_state_initialise` that also allocates the states
- *
- * @param spec The specifications for the state
- * @return The state, `NULL` on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __warn_unused_result__, __malloc__)))
-struct libkeccak_state *libkeccak_state_create(const struct libkeccak_spec *);
-
-/**
- * Wrapper for `libkeccak_state_fast_destroy` that also frees the allocation of the state
- *
- * @param state The state that should be freed
- */
-inline void
-libkeccak_state_fast_free(struct libkeccak_state *state)
-{
- libkeccak_state_fast_destroy(state);
- free(state);
-}
-
-/**
- * Wrapper for `libkeccak_state_destroy` that also frees the allocation of the state
- *
- * @param state The state that should be freed
- */
-LIBKECCAK_GCC_ONLY(__attribute__((__optimize__("-O0"))))
-inline void
-libkeccak_state_free(volatile struct libkeccak_state *state)
-{
-#ifdef __GNUC__
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wcast-qual"
-#endif
- libkeccak_state_destroy(state);
- free((struct libkeccak_state *)state);
-#ifdef __GNUC__
-# pragma GCC diagnostic pop
-#endif
-}
-
-/**
- * Make a copy of a state
- *
- * @param dest The slot for the duplicate, must not be initialised (memory leak otherwise)
- * @param src The state to duplicate
- * @return Zero on success, -1 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((__leaf__, __nonnull__)))
-int libkeccak_state_copy(struct libkeccak_state *restrict, const struct libkeccak_state *restrict);
-
-/**
- * A wrapper for `libkeccak_state_copy` that also allocates the duplicate
- *
- * @param src The state to duplicate
- * @return The duplicate, `NULL` on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __warn_unused_result__, __malloc__)))
-struct libkeccak_state *libkeccak_state_duplicate(const struct libkeccak_state *);
-
-/**
- * Marshal a `struct libkeccak_state` into a buffer
- *
- * @param state The state to marshal
- * @param data The output buffer, can be `NULL`
- * @return The number of bytes stored to `data`
- */
-LIBKECCAK_GCC_ONLY(__attribute__((__leaf__, __nonnull__(1), __nothrow__)))
-size_t libkeccak_state_marshal(const struct libkeccak_state *restrict, void *restrict);
-
-/**
- * Unmarshal a `struct libkeccak_state` from a buffer
- *
- * @param state The slot for the unmarshalled state, must not be
- * initialised (memory leak otherwise), can be `NULL`
- * @param data The input buffer
- * @return The number of bytes read from `data`, 0 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((__leaf__, __nonnull__(2))))
-size_t libkeccak_state_unmarshal(struct libkeccak_state *restrict, const void *restrict);
-
-/**
* Get the number of bytes that are absorbed during
* one pass of the absorption phase
*
@@ -413,10 +266,40 @@ void libkeccak_fast_squeeze(register struct libkeccak_state *, register long int
LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__)))
void libkeccak_squeeze(register struct libkeccak_state *restrict, register void *restrict);
+#include "libkeccak/extra.h"
+
+/**
+ * Release resources allocation for a state without wiping sensitive data
+ *
+ * @param state The state that should be destroyed
+ */
+inline void
+libkeccak_state_fast_destroy(struct libkeccak_state *state)
+{
+ if (state) {
+ free(state->M);
+ state->M = NULL;
+ }
+}
+
+/**
+ * Release resources allocation for a state and wipe sensitive data
+ *
+ * @param state The state that should be destroyed
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__optimize__("-O0"))))
+inline void
+libkeccak_state_destroy(volatile struct libkeccak_state *state)
+{
+ if (state) {
+ libkeccak_state_wipe(state);
+ free(state->M);
+ state->M = NULL;
+ }
+}
-#include "libkeccak/hmac.h"
-#include "libkeccak/legacy.h"
#include "libkeccak/util.h"
+#include "libkeccak/hmac.h"
#include "libkeccak/keccak.h"
#include "libkeccak/sha3.h"
@@ -424,6 +307,9 @@ void libkeccak_squeeze(register struct libkeccak_state *restrict, register void
#include "libkeccak/shake.h"
#include "libkeccak/cshake.h"
+#include "libkeccak/legacy.h"
+
+
#if defined(__clang__)
# pragma clang diagnostic pop
diff --git a/libkeccak/extra.h b/libkeccak/extra.h
new file mode 100644
index 0000000..60a2601
--- /dev/null
+++ b/libkeccak/extra.h
@@ -0,0 +1,140 @@
+/* See LICENSE file for copyright and license details. */
+
+
+/**
+ * Reset a state according to hashing specifications
+ *
+ * @param state The state that should be reset
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__)))
+inline void
+libkeccak_state_reset(struct libkeccak_state *state)
+{
+ state->mptr = 0;
+ memset(state->S, 0, sizeof(state->S));
+}
+
+
+/**
+ * Wipe data in the state's message without freeing any data
+ *
+ * @param state The state that should be wipe
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__leaf__, __nonnull__, __nothrow__, __optimize__("-O0"))))
+void libkeccak_state_wipe_message(volatile struct libkeccak_state *);
+
+
+/**
+ * Wipe data in the state's sponge without freeing any data
+ *
+ * @param state The state that should be wipe
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__leaf__, __nonnull__, __nothrow__, __optimize__("-O0"))))
+void libkeccak_state_wipe_sponge(volatile struct libkeccak_state *);
+
+
+/**
+ * Wipe sensitive data without freeing any data
+ *
+ * @param state The state that should be wipe
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__, __optimize__("-O0"))))
+void libkeccak_state_wipe(volatile struct libkeccak_state *);
+
+
+/**
+ * Wrapper for `libkeccak_state_initialise` that also allocates the states
+ *
+ * @param spec The specifications for the state
+ * @return The state, `NULL` on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __warn_unused_result__, __malloc__)))
+struct libkeccak_state *libkeccak_state_create(const struct libkeccak_spec *);
+
+
+/**
+ * Release resources allocation for a state,
+ * without wiping sensitive data, and deallocate
+ * the state object itself
+ *
+ * @param state The state that should be freed
+ */
+inline void
+libkeccak_state_fast_free(struct libkeccak_state *state)
+{
+ if (state) {
+ free(state->M);
+ state->M = NULL;
+ free(state);
+ }
+}
+
+
+/**
+ * Release resources allocation for a state, and wipe
+ * sensitive data, and deallocate the state object itself
+ *
+ * @param state The state that should be freed
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__optimize__("-O0"))))
+inline void
+libkeccak_state_free(volatile struct libkeccak_state *state)
+{
+#ifdef __GNUC__
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wcast-qual"
+#endif
+ if (state) {
+ libkeccak_state_wipe(state);
+ free(state->M);
+ state->M = NULL;
+ free((struct libkeccak_state *)state);
+ }
+#ifdef __GNUC__
+# pragma GCC diagnostic pop
+#endif
+}
+
+
+/**
+ * Make a copy of a state
+ *
+ * @param dest The slot for the duplicate, must not be initialised (memory leak otherwise)
+ * @param src The state to duplicate
+ * @return Zero on success, -1 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__leaf__, __nonnull__)))
+int libkeccak_state_copy(struct libkeccak_state *restrict, const struct libkeccak_state *restrict);
+
+
+/**
+ * A wrapper for `libkeccak_state_copy` that also allocates the duplicate
+ *
+ * @param src The state to duplicate
+ * @return The duplicate, `NULL` on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __warn_unused_result__, __malloc__)))
+struct libkeccak_state *libkeccak_state_duplicate(const struct libkeccak_state *);
+
+
+/**
+ * Marshal a `struct libkeccak_state` into a buffer
+ *
+ * @param state The state to marshal
+ * @param data The output buffer, can be `NULL`
+ * @return The number of bytes stored to `data`
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__leaf__, __nonnull__(1), __nothrow__)))
+size_t libkeccak_state_marshal(const struct libkeccak_state *restrict, void *restrict);
+
+
+/**
+ * Unmarshal a `struct libkeccak_state` from a buffer
+ *
+ * @param state The slot for the unmarshalled state, must not be
+ * initialised (memory leak otherwise), can be `NULL`
+ * @param data The input buffer
+ * @return The number of bytes read from `data`, 0 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__leaf__, __nonnull__(2))))
+size_t libkeccak_state_unmarshal(struct libkeccak_state *restrict, const void *restrict);
diff --git a/libkeccak_cshake_suffix.c b/spec/libkeccak_cshake_suffix.c
index f4068dd..c7e8c51 100644
--- a/libkeccak_cshake_suffix.c
+++ b/spec/libkeccak_cshake_suffix.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline const char *libkeccak_cshake_suffix(size_t, size_t);
diff --git a/libkeccak_degeneralise_spec.c b/spec/libkeccak_degeneralise_spec.c
index efe5127..2a719e9 100644
--- a/libkeccak_degeneralise_spec.c
+++ b/spec/libkeccak_degeneralise_spec.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
#if defined(__clang__)
diff --git a/libkeccak_generalised_spec_initialise.c b/spec/libkeccak_generalised_spec_initialise.c
index 736618c..b2ed3f0 100644
--- a/libkeccak_generalised_spec_initialise.c
+++ b/spec/libkeccak_generalised_spec_initialise.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline void libkeccak_generalised_spec_initialise(struct libkeccak_generalised_spec *);
diff --git a/libkeccak_spec_check.c b/spec/libkeccak_spec_check.c
index 0649e5a..92b8e75 100644
--- a/libkeccak_spec_check.c
+++ b/spec/libkeccak_spec_check.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline int libkeccak_spec_check(const struct libkeccak_spec *);
diff --git a/libkeccak_spec_rawshake.c b/spec/libkeccak_spec_rawshake.c
index 99b704c..434604c 100644
--- a/libkeccak_spec_rawshake.c
+++ b/spec/libkeccak_spec_rawshake.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline void libkeccak_spec_rawshake(struct libkeccak_spec *, long int, long int);
diff --git a/libkeccak_spec_sha3.c b/spec/libkeccak_spec_sha3.c
index 1ac387e..fe18d72 100644
--- a/libkeccak_spec_sha3.c
+++ b/spec/libkeccak_spec_sha3.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline void libkeccak_spec_sha3(struct libkeccak_spec *, long int);
diff --git a/libkeccak_behex_lower.c b/util/libkeccak_behex_lower.c
index fe71e19..07593e8 100644
--- a/libkeccak_behex_lower.c
+++ b/util/libkeccak_behex_lower.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
/**
diff --git a/libkeccak_behex_upper.c b/util/libkeccak_behex_upper.c
index e3bae6a..5186a28 100644
--- a/libkeccak_behex_upper.c
+++ b/util/libkeccak_behex_upper.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
/**
diff --git a/libkeccak_generalised_sum_fd.c b/util/libkeccak_generalised_sum_fd.c
index 11431f0..bad35e9 100644
--- a/libkeccak_generalised_sum_fd.c
+++ b/util/libkeccak_generalised_sum_fd.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
#include <stdio.h>
diff --git a/libkeccak_keccaksum_fd.c b/util/libkeccak_keccaksum_fd.c
index f738115..560e390 100644
--- a/libkeccak_keccaksum_fd.c
+++ b/util/libkeccak_keccaksum_fd.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline int libkeccak_keccaksum_fd(int, struct libkeccak_state *restrict, const struct libkeccak_spec *restrict, void *restrict);
diff --git a/libkeccak_rawshakesum_fd.c b/util/libkeccak_rawshakesum_fd.c
index a988cf2..c9c66ec 100644
--- a/libkeccak_rawshakesum_fd.c
+++ b/util/libkeccak_rawshakesum_fd.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline int libkeccak_rawshakesum_fd(int, struct libkeccak_state *restrict, long, long, void *restrict);
diff --git a/libkeccak_sha3sum_fd.c b/util/libkeccak_sha3sum_fd.c
index 6662ad4..43be4b7 100644
--- a/libkeccak_sha3sum_fd.c
+++ b/util/libkeccak_sha3sum_fd.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline int libkeccak_sha3sum_fd(int, struct libkeccak_state *restrict, long, void *restrict);
diff --git a/libkeccak_shakesum_fd.c b/util/libkeccak_shakesum_fd.c
index 45289f7..9bb4b80 100644
--- a/libkeccak_shakesum_fd.c
+++ b/util/libkeccak_shakesum_fd.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
extern inline int libkeccak_shakesum_fd(int, struct libkeccak_state *restrict, long, long, void *restrict);
diff --git a/libkeccak_unhex.c b/util/libkeccak_unhex.c
index 26a6e7d..b32a3f3 100644
--- a/libkeccak_unhex.c
+++ b/util/libkeccak_unhex.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "common.h"
+#include "../common.h"
/**