aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2019-02-10 23:19:58 +0100
committerMattias Andrée <maandree@kth.se>2019-02-10 23:19:58 +0100
commitc461a856bc3bca4b1190cf46a1d8a4f401f79b5c (patch)
treedae918632e8bfc1f3d0c23f00a23e7c2e68db4ef
parentAdd test from github issue #10 (diff)
downloadlibkeccak-c461a856bc3bca4b1190cf46a1d8a4f401f79b5c.tar.gz
libkeccak-c461a856bc3bca4b1190cf46a1d8a4f401f79b5c.tar.bz2
libkeccak-c461a856bc3bca4b1190cf46a1d8a4f401f79b5c.tar.xz
General API improvements
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--Makefile19
-rw-r--r--common.h17
-rw-r--r--libkeccak.h1151
-rw-r--r--libkeccak/digest.c94
-rw-r--r--libkeccak/digest.h100
-rw-r--r--libkeccak/files.c14
-rw-r--r--libkeccak/files.h115
-rw-r--r--libkeccak/generalised-spec.c5
-rw-r--r--libkeccak/generalised-spec.h142
-rw-r--r--libkeccak/hex.c14
-rw-r--r--libkeccak/hex.h44
-rw-r--r--libkeccak/hmac.c (renamed from libkeccak/mac/hmac.c)29
-rw-r--r--libkeccak/internal.h11
-rw-r--r--libkeccak/mac/hmac.h393
-rw-r--r--libkeccak/spec.h177
-rw-r--r--libkeccak/state.c47
-rw-r--r--libkeccak/state.h295
-rw-r--r--man3/libkeccak_behex_lower.313
-rw-r--r--man3/libkeccak_behex_upper.314
-rw-r--r--man3/libkeccak_degeneralise_spec.324
-rw-r--r--man3/libkeccak_digest.344
-rw-r--r--man3/libkeccak_fast_digest.341
-rw-r--r--man3/libkeccak_fast_squeeze.311
-rw-r--r--man3/libkeccak_fast_update.340
-rw-r--r--man3/libkeccak_generalised_spec_initialise.311
-rw-r--r--man3/libkeccak_generalised_sum_fd.320
-rw-r--r--man3/libkeccak_hmac_copy.312
-rw-r--r--man3/libkeccak_hmac_create.312
-rw-r--r--man3/libkeccak_hmac_destroy.311
-rw-r--r--man3/libkeccak_hmac_digest.316
-rw-r--r--man3/libkeccak_hmac_duplicate.311
-rw-r--r--man3/libkeccak_hmac_fast_destroy.311
-rw-r--r--man3/libkeccak_hmac_fast_digest.316
-rw-r--r--man3/libkeccak_hmac_fast_free.311
-rw-r--r--man3/libkeccak_hmac_fast_update.312
-rw-r--r--man3/libkeccak_hmac_free.311
-rw-r--r--man3/libkeccak_hmac_initialise.314
-rw-r--r--man3/libkeccak_hmac_marshal.312
-rw-r--r--man3/libkeccak_hmac_marshal_size.311
-rw-r--r--man3/libkeccak_hmac_reset.312
-rw-r--r--man3/libkeccak_hmac_set_key.312
-rw-r--r--man3/libkeccak_hmac_unmarshal.314
-rw-r--r--man3/libkeccak_hmac_unmarshal_skip.311
-rw-r--r--man3/libkeccak_hmac_update.312
-rw-r--r--man3/libkeccak_hmac_wipe.311
-rw-r--r--man3/libkeccak_keccaksum_fd.316
-rw-r--r--man3/libkeccak_rawshakesum_fd.317
-rw-r--r--man3/libkeccak_sha3sum_fd.316
-rw-r--r--man3/libkeccak_shakesum_fd.317
-rw-r--r--man3/libkeccak_simple_squeeze.311
-rw-r--r--man3/libkeccak_spec_check.317
-rw-r--r--man3/libkeccak_spec_rawshake.314
-rw-r--r--man3/libkeccak_spec_sha3.313
-rw-r--r--man3/libkeccak_spec_shake.313
-rw-r--r--man3/libkeccak_squeeze.311
-rw-r--r--man3/libkeccak_state_copy.312
-rw-r--r--man3/libkeccak_state_create.311
-rw-r--r--man3/libkeccak_state_destroy.311
-rw-r--r--man3/libkeccak_state_duplicate.311
-rw-r--r--man3/libkeccak_state_fast_destroy.311
-rw-r--r--man3/libkeccak_state_fast_free.311
-rw-r--r--man3/libkeccak_state_free.311
-rw-r--r--man3/libkeccak_state_initialise.312
-rw-r--r--man3/libkeccak_state_marshal.315
-rw-r--r--man3/libkeccak_state_marshal_size.311
-rw-r--r--man3/libkeccak_state_reset.311
-rw-r--r--man3/libkeccak_state_unmarshal.311
-rw-r--r--man3/libkeccak_state_unmarshal_skip.311
-rw-r--r--man3/libkeccak_state_wipe.311
-rw-r--r--man3/libkeccak_state_wipe_message.311
-rw-r--r--man3/libkeccak_state_wipe_sponge.311
-rw-r--r--man3/libkeccak_unhex.311
-rw-r--r--man3/libkeccak_update.340
73 files changed, 1526 insertions, 1969 deletions
diff --git a/Makefile b/Makefile
index 7528040..e8c9b80 100644
--- a/Makefile
+++ b/Makefile
@@ -23,18 +23,11 @@ OBJ =\
libkeccak/generalised-spec.o\
libkeccak/hex.o\
libkeccak/state.o\
- libkeccak/mac/hmac.o
+ libkeccak/hmac.o
HDR =\
libkeccak.h\
- libkeccak/digest.h\
- libkeccak/files.h\
- libkeccak/generalised-spec.h\
- libkeccak/hex.h\
- libkeccak/spec.h\
- libkeccak/state.h\
- libkeccak/internal.h\
- libkeccak/mac/hmac.h
+ common.h
MAN3 =\
man3/libkeccak_behex_lower.3\
@@ -146,8 +139,7 @@ install: libkeccak.$(LIBEXT) libkeccak.a
ln -sf -- libkeccak.$(LIBMINOREXT) "$(DESTDIR)$(PREFIX)/lib/libkeccak.$(LIBMAJOREXT)"
ln -sf -- libkeccak.$(LIBMINOREXT) "$(DESTDIR)$(PREFIX)/lib/libkeccak.$(LIBEXT)"
cp -- libkeccak.a "$(DESTDIR)$(PREFIX)/lib/libkeccak.a"
- mkdir -p -- "$(DESTDIR)$(PREFIX)/include/libkeccak/mac"
- for f in $(HDR); do cp -- "$$f" "$(DESTDIR)$(PREFIX)/include/$$f" || exit 1; done
+ cp -- libkeccak.h "$(DESTDIR)$(PREFIX)/include/"
mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man3"
mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man7"
cp -- $(MAN3) "$(DESTDIR)$(MANPREFIX)/man3"
@@ -166,9 +158,8 @@ uninstall:
-rm -rf -- "$(DESTDIR)$(PREFIX)/share/licenses/libkeccak"
clean:
- -rm -f -- *.o libkeccak/*.o libkeccak/mac/*.o
- -rm -f -- *.su libkeccak/*.su libkeccak/mac/*.su
- -rm -f -- *.info *.pdf *.ps *.dvi *.a libkeccak.$(LIBEXT)* test benchmark benchfile
+ -rm -f -- *.o *.su libkeccak/*.o libkeccak/*.su test benchmark benchfile
+ -rm -f -- *.a libkeccak.$(LIBEXT) libkeccak.$(LIBEXT).* libkeccak.*.$(LIBEXT)
.SUFFIXES:
.SUFFIXES: .c .o
diff --git a/common.h b/common.h
new file mode 100644
index 0000000..1245bf6
--- /dev/null
+++ b/common.h
@@ -0,0 +1,17 @@
+/* See LICENSE file for copyright and license details. */
+#include "libkeccak.h"
+
+
+#include <sys/stat.h>
+#include <alloca.h>
+#include <errno.h>
+#include <unistd.h>
+
+
+/* Use built in functions and branching optimisation if available */
+#ifndef __GNUC__
+# define __builtin_expect(expression, expect) expression
+# define __builtin_memset(dest, c, n) memset(dest, c, n)
+# define __builtin_memcpy(dest, src, n) memcpy(dest, src, n)
+# define __builtin_memmove(dest, src, n) memmove(dest, src, n)
+#endif
diff --git a/libkeccak.h b/libkeccak.h
index 7c71801..21b4b47 100644
--- a/libkeccak.h
+++ b/libkeccak.h
@@ -2,12 +2,1149 @@
#ifndef LIBKECCAK_H
#define LIBKECCAK_H 1
-#include "libkeccak/spec.h"
-#include "libkeccak/generalised-spec.h"
-#include "libkeccak/state.h"
-#include "libkeccak/digest.h"
-#include "libkeccak/hex.h"
-#include "libkeccak/files.h"
-#include "libkeccak/mac/hmac.h"
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+/**
+ * Only include some C code if compiling with GCC.
+ *
+ * For internal use.
+ */
+#ifdef __GNUC__
+# define LIBKECCAK_GCC_ONLY(x) x
+#else
+# define LIBKECCAK_GCC_ONLY(x)
+#endif
+
+
+
+/**
+ * Message suffix for SHA3 hashing
+ */
+#define LIBKECCAK_SHA3_SUFFIX "01"
+
+/**
+ * Message suffix for RawSHAKE hashing
+ */
+#define LIBKECCAK_RAWSHAKE_SUFFIX "11"
+
+/**
+ * Message suffix for SHAKE hashing
+ */
+#define LIBKECCAK_SHAKE_SUFFIX "1111"
+
+
+/**
+ * Invalid `libkeccak_spec_t.bitrate`: non-positive
+ */
+#define LIBKECCAK_SPEC_ERROR_BITRATE_NONPOSITIVE 1
+
+/**
+ * Invalid `libkeccak_spec_t.bitrate`: not a multiple of 8
+ */
+#define LIBKECCAK_SPEC_ERROR_BITRATE_MOD_8 2
+
+/**
+ * Invalid `libkeccak_spec_t.capacity`: non-positive
+ */
+#define LIBKECCAK_SPEC_ERROR_CAPACITY_NONPOSITIVE 3
+
+/**
+ * Invalid `libkeccak_spec_t.capacity`: not a multiple of 8
+ */
+#define LIBKECCAK_SPEC_ERROR_CAPACITY_MOD_8 4
+
+/**
+ * Invalid `libkeccak_spec_t.output`: non-positive
+ */
+#define LIBKECCAK_SPEC_ERROR_OUTPUT_NONPOSITIVE 5
+
+/**
+ * Invalid `libkeccak_spec_t` values: `.bitrate + `.capacity`
+ * is greater 1600 which is the largest supported state size
+ */
+#define LIBKECCAK_SPEC_ERROR_STATE_TOO_LARGE 6
+
+/**
+ * Invalid `libkeccak_spec_t` values:
+ * `.bitrate + `.capacity` is not a multiple of 25
+ */
+#define LIBKECCAK_SPEC_ERROR_STATE_MOD_25 7
+
+/**
+ * Invalid `libkeccak_spec_t` values: `.bitrate + `.capacity`
+ * is a not a 2-potent multiple of 25
+ */
+#define LIBKECCAK_SPEC_ERROR_WORD_NON_2_POTENT 8
+
+/**
+ * Invalid `libkeccak_spec_t` values: `.bitrate + `.capacity`
+ * is a not multiple of 100, and thus the word size is not
+ * a multiple of 8
+ */
+#define LIBKECCAK_SPEC_ERROR_WORD_MOD_8 9
+
+
+/**
+ * Value for `libkeccak_generalised_spec_t` member that
+ * is used to automatically select the value
+ */
+#define LIBKECCAK_GENERALISED_SPEC_AUTOMATIC (-65536L)
+
+
+/**
+ * Invalid `libkeccak_generalised_spec_t.state_size`: non-positive
+ */
+#define LIBKECCAK_GENERALISED_SPEC_ERROR_STATE_NONPOSITIVE 1
+
+/**
+ * Invalid `libkeccak_generalised_spec_t.state_size`: larger than 1600
+ */
+#define LIBKECCAK_GENERALISED_SPEC_ERROR_STATE_TOO_LARGE 2
+
+/**
+ * Invalid `libkeccak_generalised_spec_t.state_size`: not a multiple of 25
+ */
+#define LIBKECCAK_GENERALISED_SPEC_ERROR_STATE_MOD_25 3
+
+/**
+ * Invalid `libkeccak_generalised_spec_t.word_size`: non-positive
+ */
+#define LIBKECCAK_GENERALISED_SPEC_ERROR_WORD_NONPOSITIVE 4
+
+/**
+ * Invalid `libkeccak_generalised_spec_t.word_size`: larger than 1600 / 25
+ */
+#define LIBKECCAK_GENERALISED_SPEC_ERROR_WORD_TOO_LARGE 5
+
+/**
+ * Invalid `libkeccak_generalised_spec_t.word_size` and
+ * `libkeccak_generalised_spec_t.state_size`: `.word_size * 25 != .state_size`
+ */
+#define LIBKECCAK_GENERALISED_SPEC_ERROR_STATE_WORD_INCOHERENCY 6
+
+/**
+ * Invalid `libkeccak_generalised_spec_t.capacity`: non-positive
+ */
+#define LIBKECCAK_GENERALISED_SPEC_ERROR_CAPACITY_NONPOSITIVE 7
+
+/**
+ * Invalid `libkeccak_generalised_spec_t.capacity`: not a multiple of 8
+ */
+#define LIBKECCAK_GENERALISED_SPEC_ERROR_CAPACITY_MOD_8 8
+
+/**
+ * Invalid `libkeccak_generalised_spec_t.bitrate`: non-positive
+ */
+#define LIBKECCAK_GENERALISED_SPEC_ERROR_BITRATE_NONPOSITIVE 9
+
+/**
+ * Invalid `libkeccak_generalised_spec_t.bitrate`: not a multiple of 8
+ */
+#define LIBKECCAK_GENERALISED_SPEC_ERROR_BITRATE_MOD_8 10
+
+/**
+ * Invalid `libkeccak_generalised_spec_t.output`: non-positive
+ */
+#define LIBKECCAK_GENERALISED_SPEC_ERROR_OUTPUT_NONPOSITIVE 11
+
+
+/**
+ * Data structure that describes the parameters
+ * that should be used when hashing
+ */
+typedef struct libkeccak_spec {
+ /**
+ * The bitrate
+ */
+ long int bitrate;
+
+ /**
+ * The capacity
+ */
+ long int capacity;
+
+ /**
+ * The output size
+ */
+ long int output;
+
+} libkeccak_spec_t;
+
+/**
+ * Generalised datastructure that describes the
+ * parameters that should be used when hashing
+ */
+typedef struct libkeccak_generalised_spec
+{
+ /**
+ * The bitrate
+ */
+ long int bitrate;
+
+ /**
+ * The capacity
+ */
+ long int capacity;
+
+ /**
+ * The output size
+ */
+ long int output;
+
+ /**
+ * The state size
+ */
+ long int state_size;
+
+ /**
+ * The word size
+ */
+ long int word_size;
+
+} libkeccak_generalised_spec_t;
+
+/**
+ * Data structure that describes the state of a hashing process
+ *
+ * The `char`-size of the output hashsum is calculated by `(.n + 7) / 8`
+ */
+typedef struct libkeccak_state {
+ /**
+ * The lanes (state/sponge)
+ */
+ int64_t S[25];
+
+ /**
+ * The bitrate
+ */
+ long int r;
+
+ /**
+ * The capacity
+ */
+ long int c;
+
+ /**
+ * The output size
+ */
+ long int n;
+
+ /**
+ * The state size
+ */
+ long int b;
+
+ /**
+ * The word size
+ */
+ long int w;
+
+ /**
+ * The word mask
+ */
+ int64_t wmod;
+
+ /**
+ * ℓ, the binary logarithm of the word size
+ */
+ long int l;
+
+ /**
+ * 12 + 2ℓ, the number of rounds
+ */
+ long int nr;
+
+ /**
+ * Pointer for `M`
+ */
+ size_t mptr;
+
+ /**
+ * Size of `M`
+ */
+ size_t mlen;
+
+ /**
+ * Left over water to fill the sponge with at next update
+ */
+ char *M;
+
+} libkeccak_state_t;
+
+
+/**
+ * Fill in a `libkeccak_spec_t` for a SHA3-x hashing
+ *
+ * @param spec The specifications datastructure to fill in
+ * @param x The value of x in `SHA3-x`, the output size
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow)))
+static inline void
+libkeccak_spec_sha3(libkeccak_spec_t *restrict spec, long int x)
+{
+ spec->bitrate = 1600 - 2 * x;
+ spec->capacity = 2 * x;
+ spec->output = x;
+}
+
+/**
+ * Fill in a `libkeccak_spec_t` for a RawSHAKEx hashing
+ *
+ * @param spec The specifications datastructure to fill in
+ * @param x The value of x in `RawSHAKEx`, half the capacity
+ * @param d The output size
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow)))
+static inline void
+libkeccak_spec_rawshake(libkeccak_spec_t *restrict spec, long int x, long int d)
+{
+ spec->bitrate = 1600 - 2 * x;
+ spec->capacity = 2 * x;
+ spec->output = d;
+}
+
+/**
+ * Fill in a `libkeccak_spec_t` for a SHAKEx hashing
+ *
+ * @param spec:libkeccak_spec_t* The specifications datastructure to fill in
+ * @param x:long The value of x in `SHAKEx`, half the capacity
+ * @param d:long The output size
+ */
+#define libkeccak_spec_shake libkeccak_spec_rawshake
+
+/**
+ * Check for errors in a `libkeccak_spec_t`
+ *
+ * @param spec The specifications datastructure to check
+ * @return Zero if error free, a `LIBKECCAK_SPEC_ERROR_*` if an error was found
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow, unused, warn_unused_result, pure)))
+static inline int
+libkeccak_spec_check(const libkeccak_spec_t *restrict spec)
+{
+ long int state_size = spec->capacity + spec->bitrate;
+ int32_t word_size = (int32_t)(state_size / 25);
+ if (spec->bitrate <= 0) return LIBKECCAK_SPEC_ERROR_BITRATE_NONPOSITIVE;
+ if (spec->bitrate % 8) return LIBKECCAK_SPEC_ERROR_BITRATE_MOD_8;
+ if (spec->capacity <= 0) return LIBKECCAK_SPEC_ERROR_CAPACITY_NONPOSITIVE;
+ if (spec->capacity % 8) return LIBKECCAK_SPEC_ERROR_CAPACITY_MOD_8;
+ if (spec->output <= 0) return LIBKECCAK_SPEC_ERROR_OUTPUT_NONPOSITIVE;
+ if (state_size > 1600) return LIBKECCAK_SPEC_ERROR_STATE_TOO_LARGE;
+ if (state_size % 25) return LIBKECCAK_SPEC_ERROR_STATE_MOD_25;
+ if (word_size % 8) return LIBKECCAK_SPEC_ERROR_WORD_MOD_8;
+
+ /* `(x & -x) != x` assumes two's complement, which of course is always
+ * satisfied by GCC, however C99 guarantees that `int32_t` exists,
+ * and it is basically the same thing as `long int`; with one important
+ * difference: it is guaranteed to use two's complement. */
+ if ((word_size & -word_size) != word_size)
+ return LIBKECCAK_SPEC_ERROR_WORD_NON_2_POTENT;
+
+ return 0;
+}
+
+/**
+ * Set all specification parameters to automatic
+ *
+ * @param spec The specification datastructure to fill in
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__, __unused__)))
+static inline void
+libkeccak_generalised_spec_initialise(libkeccak_generalised_spec_t *restrict spec)
+{
+ spec->bitrate = LIBKECCAK_GENERALISED_SPEC_AUTOMATIC;
+ spec->capacity = LIBKECCAK_GENERALISED_SPEC_AUTOMATIC;
+ spec->output = LIBKECCAK_GENERALISED_SPEC_AUTOMATIC;
+ spec->state_size = LIBKECCAK_GENERALISED_SPEC_AUTOMATIC;
+ spec->word_size = LIBKECCAK_GENERALISED_SPEC_AUTOMATIC;
+}
+
+/**
+ * Convert a `libkeccak_generalised_spec_t` to a `libkeccak_spec_t`
+ *
+ * @param spec The generalised input specifications, will be update with resolved automatic values
+ * @param output_spec The specification datastructure to fill in
+ * @return Zero if `spec` is valid, a `LIBKECCAK_GENERALISED_SPEC_ERROR_*` if an error was found
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__leaf__, __nonnull__, __nothrow__)))
+int libkeccak_degeneralise_spec(libkeccak_generalised_spec_t *restrict, libkeccak_spec_t *restrict);
+
+/**
+ * Initialise a state according to hashing specifications
+ *
+ * @param state The state that should be initialised
+ * @param spec The specifications for the state
+ * @return Zero on success, -1 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__leaf__, __nonnull__)))
+int libkeccak_state_initialise(libkeccak_state_t *restrict, const libkeccak_spec_t *restrict);
+
+/**
+ * Reset a state according to hashing specifications
+ *
+ * @param state The state that should be reset
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__, __unused__)))
+static inline void
+libkeccak_state_reset(libkeccak_state_t *restrict 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
+ */
+static inline void
+libkeccak_state_fast_destroy(libkeccak_state_t *restrict 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 libkeccak_state_t *restrict);
+
+/**
+ * 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 libkeccak_state_t *restrict);
+
+/**
+ * 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 libkeccak_state_t *restrict);
+
+/**
+ * Release resources allocation for a state and wipe sensitive data
+ *
+ * @param state The state that should be destroyed
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__unused__, __optimize__("-O0"))))
+static inline void
+libkeccak_state_destroy(volatile libkeccak_state_t *restrict 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__, __unused__, __warn_unused_result__, __malloc__)))
+static inline libkeccak_state_t *
+libkeccak_state_create(const libkeccak_spec_t *restrict spec)
+{
+ libkeccak_state_t *restrict state = malloc(sizeof(libkeccak_state_t));
+ if (!state || libkeccak_state_initialise(state, spec)) {
+ free(state);
+ return NULL;
+ }
+ return state;
+}
+
+/**
+ * Wrapper for `libkeccak_state_fast_destroy` that also frees the allocation of the state
+ *
+ * @param state The state that should be freed
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__unused__)))
+static inline void
+libkeccak_state_fast_free(libkeccak_state_t *restrict 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__((__unused__, __optimize__("-O0"))))
+static inline void
+libkeccak_state_free(volatile libkeccak_state_t *restrict state)
+{
+#ifdef __GNUC__
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wcast-qual"
+#endif
+ libkeccak_state_destroy(state);
+ free((libkeccak_state_t *)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(libkeccak_state_t *restrict, const libkeccak_state_t *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__, __unused__, __warn_unused_result__, __malloc__)))
+static inline libkeccak_state_t *
+libkeccak_state_duplicate(const libkeccak_state_t *restrict src)
+{
+ libkeccak_state_t *restrict dest = malloc(sizeof(libkeccak_state_t));
+ if (!dest || libkeccak_state_copy(dest, src)) {
+ libkeccak_state_free(dest);
+ return NULL;
+ }
+ return dest;
+}
+
+/**
+ * Calculates the allocation size required for the second argument
+ * of `libkeccak_state_marshal` (`char* restrict data)`)
+ *
+ * @param state The state as it will be marshalled by a subsequent call to `libkeccak_state_marshal`
+ * @return The allocation size needed for the buffer to which the state will be marshalled
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__, __unused__, __warn_unused_result__, __pure__)))
+static inline size_t
+libkeccak_state_marshal_size(const libkeccak_state_t *restrict state)
+{
+ return sizeof(libkeccak_state_t) - sizeof(char *) + state->mptr * sizeof(char);
+}
+
+/**
+ * Marshal a `libkeccak_state_t` into a buffer
+ *
+ * @param state The state to marshal
+ * @param data The output buffer
+ * @return The number of bytes stored to `data`
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__leaf__, __nonnull__, __nothrow__)))
+size_t libkeccak_state_marshal(const libkeccak_state_t *restrict, void *restrict);
+
+/**
+ * Unmarshal a `libkeccak_state_t` from a buffer
+ *
+ * @param state The slot for the unmarshalled state, must not be initialised (memory leak otherwise)
+ * @param data The input buffer
+ * @return The number of bytes read from `data`, 0 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__leaf__, __nonnull__)))
+size_t libkeccak_state_unmarshal(libkeccak_state_t *restrict, const void *restrict);
+
+/**
+ * Gets the number of bytes the `libkeccak_state_t` stored
+ * at the beginning of `data` occupies
+ *
+ * @param data The data buffer
+ * @return The byte size of the stored state
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__leaf__, __nonnull__, __nothrow__, __warn_unused_result__, __pure__)))
+size_t libkeccak_state_unmarshal_skip(const void *restrict);
+
+/**
+ * Absorb more of the message to the Keccak sponge
+ * without wiping sensitive data when possible
+ *
+ * @param state The hashing state
+ * @param msg The partial message
+ * @param msglen The length of the partial message
+ * @return Zero on success, -1 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__)))
+int libkeccak_fast_update(libkeccak_state_t *restrict, const void *restrict, size_t);
+
+/**
+ * Absorb more of the message to the Keccak sponge
+ * and wipe sensitive data when possible
+ *
+ * @param state The hashing state
+ * @param msg The partial message
+ * @param msglen The length of the partial message
+ * @return Zero on success, -1 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__)))
+int libkeccak_update(libkeccak_state_t *restrict, const void *restrict, size_t);
+
+/**
+ * Absorb the last part of the message and squeeze the Keccak sponge
+ * without wiping sensitive data when possible
+ *
+ * @param state The hashing state
+ * @param msg The rest of the message, may be `NULL`
+ * @param msglen The length of the partial message
+ * @param bits The number of bits at the end of the message not covered by `msglen`
+ * @param suffix The suffix concatenate to the message, only '1':s and '0':s, and NUL-termination
+ * @param hashsum Output parameter for the hashsum, may be `NULL`
+ * @return Zero on success, -1 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__(1))))
+int libkeccak_fast_digest(libkeccak_state_t *restrict, const void *restrict, size_t,
+ size_t, const char *restrict, void *restrict);
+
+/**
+ * Absorb the last part of the message and squeeze the Keccak sponge
+ * and wipe sensitive data when possible
+ *
+ * @param state The hashing state
+ * @param msg The rest of the message, may be `NULL`
+ * @param msglen The length of the partial message
+ * @param bits The number of bits at the end of the message not covered by `msglen`
+ * @param suffix The suffix concatenate to the message, only '1':s and '0':s, and NUL-termination
+ * @param hashsum Output parameter for the hashsum, may be `NULL`
+ * @return Zero on success, -1 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__(1))))
+int libkeccak_digest(libkeccak_state_t *restrict, const void *restrict, size_t,
+ size_t, const char *restrict, void *restrict);
+
+/**
+ * Force some rounds of Keccak-f
+ *
+ * @param state The hashing state
+ * @param times The number of rounds
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__)))
+void libkeccak_simple_squeeze(register libkeccak_state_t *restrict, register long int);
+
+/**
+ * Squeeze as much as is needed to get a digest a number of times
+ *
+ * @param state The hashing state
+ * @param times The number of digests
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__)))
+void libkeccak_fast_squeeze(register libkeccak_state_t *restrict, register long int);
+
+/**
+ * Squeeze out another digest
+ *
+ * @param state The hashing state
+ * @param hashsum Output parameter for the hashsum
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__)))
+void libkeccak_squeeze(register libkeccak_state_t *restrict, register void *restrict);
+
+/**
+ * Convert a binary hashsum to lower case hexadecimal representation
+ *
+ * @param output Output array, should have an allocation size of at least `2 * n + 1`
+ * @param hashsum The hashsum to convert
+ * @param n The size of `hashsum`
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__leaf__, __nonnull__, __nothrow__)))
+void libkeccak_behex_lower(char *restrict, const void *restrict, size_t);
+
+/**
+ * Convert a binary hashsum to upper case hexadecimal representation
+ *
+ * @param output Output array, should have an allocation size of at least `2 * n + 1`
+ * @param hashsum The hashsum to convert
+ * @param n The size of `hashsum`
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__leaf__, __nonnull__, __nothrow__)))
+void libkeccak_behex_upper(char *restrict, const void *restrict, size_t);
+
+/**
+ * Convert a hexadecimal hashsum (both lower case, upper
+ * case and mixed is supported) to binary representation
+ *
+ * @param output Output array, should have an allocation size of at least `strlen(hashsum) / 2`
+ * @param hashsum The hashsum to convert
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__leaf__, __nonnull__, __nothrow__)))
+void libkeccak_unhex(void *restrict, const char *restrict);
+
+/**
+ * Calculate a Keccak-family hashsum of a file,
+ * the content of the file is assumed non-sensitive
+ *
+ * @param fd The file descriptor of the file to hash
+ * @param state The hashing state, should not be initialised (memory leak otherwise)
+ * @param spec Specifications for the hashing algorithm
+ * @param suffix The data suffix, see `libkeccak_digest`
+ * @param hashsum Output array for the hashsum, have an allocation size of
+ * at least `((spec->output + 7) / 8) * sizeof(char)`, may be `NULL`
+ * @return Zero on success, -1 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__(2, 3))))
+int libkeccak_generalised_sum_fd(int, libkeccak_state_t *restrict, const libkeccak_spec_t *restrict,
+ const char *restrict, void *restrict);
+
+/**
+ * Calculate the Keccak hashsum of a file,
+ * the content of the file is assumed non-sensitive
+ *
+ * @param fd The file descriptor of the file to hash
+ * @param state The hashing state, should not be initialised (memory leak otherwise)
+ * @param spec Specifications for the hashing algorithm
+ * @param hashsum Output array for the hashsum, have an allocation size of
+ * at least `((spec->output + 7) / 8) * sizeof(char)`, may be `NULL`
+ * @return Zero on success, -1 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__(2, 3), __artificial__, __gnu_inline__)))
+static inline int
+libkeccak_keccaksum_fd(int fd, libkeccak_state_t *restrict state, const libkeccak_spec_t *restrict spec, void *restrict hashsum)
+{
+ return libkeccak_generalised_sum_fd(fd, state, spec, NULL, hashsum);
+}
+
+/**
+ * Calculate the SHA3 hashsum of a file,
+ * the content of the file is assumed non-sensitive
+ *
+ * @param fd The file descriptor of the file to hash
+ * @param state The hashing state, should not be initialised (memory leak otherwise)
+ * @param output The output size parameter for the hashing algorithm
+ * @param hashsum Output array for the hashsum, have an allocation size of
+ * at least `((output + 7) / 8) * sizeof(char)`, may be `NULL`
+ * @return Zero on success, -1 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__(2), __artificial__, __gnu_inline__)))
+static inline int
+libkeccak_sha3sum_fd(int fd, libkeccak_state_t *restrict state, long output, void *restrict hashsum)
+{
+ libkeccak_spec_t spec;
+ libkeccak_spec_sha3(&spec, output);
+ return libkeccak_generalised_sum_fd(fd, state, &spec, LIBKECCAK_SHA3_SUFFIX, hashsum);
+}
+
+/**
+ * Calculate the RawSHAKE hashsum of a file,
+ * the content of the file is assumed non-sensitive
+ *
+ * @param fd The file descriptor of the file to hash
+ * @param state The hashing state, should not be initialised (memory leak otherwise)
+ * @param semicapacity The semicapacity parameter for the hashing algorithm
+ * @param output The output size parameter for the hashing algorithm
+ * @param hashsum Output array for the hashsum, have an allocation size of
+ * at least `((output + 7) / 8) * sizeof(char)`, may be `NULL`
+ * @return Zero on success, -1 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__(2), __artificial__, __gnu_inline__)))
+static inline int
+libkeccak_rawshakesum_fd(int fd, libkeccak_state_t *restrict state, long semicapacity, long output, void *restrict hashsum)
+{
+ libkeccak_spec_t spec;
+ libkeccak_spec_rawshake(&spec, semicapacity, output);
+ return libkeccak_generalised_sum_fd(fd, state, &spec, LIBKECCAK_RAWSHAKE_SUFFIX, hashsum);
+}
+
+/**
+ * Calculate the SHAKE hashsum of a file,
+ * the content of the file is assumed non-sensitive
+ *
+ * @param fd The file descriptor of the file to hash
+ * @param state The hashing state, should not be initialised (memory leak otherwise)
+ * @param semicapacity The semicapacity parameter for the hashing algorithm
+ * @param output The output size parameter for the hashing algorithm
+ * @param hashsum Output array for the hashsum, have an allocation size of
+ * at least `((output + 7) / 8) * sizeof(char)`, may be `NULL`
+ * @return Zero on success, -1 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__(2), __artificial__, __gnu_inline__)))
+static inline int
+libkeccak_shakesum_fd(int fd, libkeccak_state_t *restrict state, long semicapacity, long output, void *restrict hashsum)
+{
+ libkeccak_spec_t spec;
+ libkeccak_spec_shake(&spec, semicapacity, output);
+ return libkeccak_generalised_sum_fd(fd, state, &spec, LIBKECCAK_SHAKE_SUFFIX, hashsum);
+}
+
+
+/*
+ * The Keccak hash-function, that was selected by NIST as the SHA-3 competition winner,
+ * doesn't need this nested approach and can be used to generate a MAC by simply prepending
+ * the key to the message. [http://keccak.noekeon.org]
+ */
+
+
+/**
+ * Datastructure that describes the state of an HMAC-hashing process
+ */
+typedef struct libkeccak_hmac_state
+{
+ /**
+ * The key right-padded and XOR:ed with the outer pad
+ */
+ char *restrict key_opad;
+
+ /**
+ * The key right-padded and XOR:ed with the inner pad
+ */
+ char *restrict key_ipad;
+ /* Not marshalled, implicitly unmarshalled using `key_opad`. */
+ /* Shares allocation with `key_opad`, do not `free`. */
+
+ /**
+ * The length of key, but at least the input block size, in bits
+ */
+ size_t key_length;
+
+ /**
+ * The state of the underlaying hash-algorithm
+ */
+ libkeccak_state_t sponge;
+
+ /**
+ * Buffer used to temporarily store bit shift message if
+ * `.key_length` is not zero modulus 8
+ */
+ char *restrict buffer;
+
+ /**
+ * The allocation size of `.buffer`
+ */
+ size_t buffer_size;
+
+ /**
+ * Part of feed key, message or digest that have not been passed yet
+ */
+ char leftover;
+
+ char __pad[sizeof(void*) / sizeof(char) - 1];
+
+} libkeccak_hmac_state_t;
+
+
+/**
+ * Change the HMAC-hashing key on the state
+ *
+ * @param state The state that should be reset
+ * @param key The new key
+ * @param key_length The length of key, in bits
+ * @return Zero on success, -1 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__(1))))
+int libkeccak_hmac_set_key(libkeccak_hmac_state_t *restrict, const void *restrict, size_t);
+
+/**
+ * Initialise an HMAC hashing-state according to hashing specifications
+ *
+ * @param state The state that should be initialised
+ * @param spec The specifications for the state
+ * @param key The key
+ * @param key_length The length of key, in bits
+ * @return Zero on success, -1 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__)))
+static inline int
+libkeccak_hmac_initialise(libkeccak_hmac_state_t *restrict state, const libkeccak_spec_t *restrict spec,
+ const void *restrict key, size_t key_length)
+{
+ if (libkeccak_state_initialise(&state->sponge, spec) < 0)
+ return -1;
+ if (libkeccak_hmac_set_key(state, key, key_length) < 0) {
+ libkeccak_state_destroy(&state->sponge);
+ return -1;
+ }
+ state->leftover = 0;
+ state->buffer = NULL;
+ state->buffer_size = 0;
+ return 0;
+}
+
+/**
+ * Wrapper for `libkeccak_hmac_initialise` that also allocates the states
+ *
+ * @param spec The specifications for the state
+ * @param key The key
+ * @param key_length The length of key, in bits
+ * @return The state, `NULL` on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __unused__, __warn_unused_result__, __malloc__)))
+static inline libkeccak_hmac_state_t *
+libkeccak_hmac_create(const libkeccak_spec_t *restrict spec, const void *restrict key, size_t key_length)
+{
+ libkeccak_hmac_state_t *restrict state = malloc(sizeof(libkeccak_hmac_state_t));
+ if (!state || libkeccak_hmac_initialise(state, spec, key, key_length)) {
+ free(state);
+ return NULL;
+ }
+ return state;
+}
+
+/**
+ * Reset an HMAC-hashing state according to hashing specifications,
+ * you can choose whether to change the key
+ *
+ * @param state The state that should be reset
+ * @param key The new key, `NULL` to keep the old key
+ * @param key_length The length of key, in bits, ignored if `key == NULL`
+ * @return Zero on success, -1 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__(1), __unused__)))
+static inline int
+libkeccak_hmac_reset(libkeccak_hmac_state_t *restrict state, const void *restrict key, size_t key_length)
+{
+ libkeccak_state_reset(&state->sponge);
+ return key ? libkeccak_hmac_set_key(state, key, key_length) : 0;
+}
+
+/**
+ * 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_hmac_wipe(volatile libkeccak_hmac_state_t *restrict);
+
+/**
+ * Release resources allocation for an HMAC hashing-state without wiping sensitive data
+ *
+ * @param state The state that should be destroyed
+ */
+static inline void
+libkeccak_hmac_fast_destroy(libkeccak_hmac_state_t *restrict state)
+{
+ if (!state)
+ return;
+ free(state->key_opad);
+ state->key_opad = NULL;
+ state->key_ipad = NULL;
+ state->key_length = 0;
+ free(state->buffer);
+ state->buffer = NULL;
+ state->buffer_size = 0;
+}
+
+/**
+ * Release resources allocation for an HMAC hasing-state and wipe sensitive data
+ *
+ * @param state The state that should be destroyed
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__unused__, __optimize__("-O0"))))
+static inline void
+libkeccak_hmac_destroy(volatile libkeccak_hmac_state_t *restrict state)
+{
+ if (!state)
+ return;
+ libkeccak_hmac_wipe(state);
+ free(state->key_opad);
+ state->key_opad = NULL;
+ state->key_ipad = NULL;
+ state->key_length = 0;
+ state->leftover = 0;
+ free(state->buffer);
+ state->buffer = NULL;
+ state->buffer_size = 0;
+}
+
+/**
+ * Wrapper for `libkeccak_fast_destroy` that also frees the allocation of the state
+ *
+ * @param state The state that should be freed
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__unused__)))
+static inline void
+libkeccak_hmac_fast_free(libkeccak_hmac_state_t *restrict state)
+{
+ libkeccak_hmac_fast_destroy(state);
+ free(state);
+}
+
+/**
+ * Wrapper for `libkeccak_hmac_destroy` that also frees the allocation of the state
+ *
+ * @param state The state that should be freed
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__unused__, __optimize__("-O0"))))
+static inline void
+libkeccak_hmac_free(volatile libkeccak_hmac_state_t *restrict state)
+{
+#ifdef __GNUC__
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wcast-qual"
+#endif
+ libkeccak_hmac_destroy(state);
+ free((libkeccak_hmac_state_t*)state);
+#ifdef __GNUC__
+# pragma GCC diagnostic pop
+#endif
+}
+
+/**
+ * Make a copy of an HMAC hashing-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__((__nonnull__)))
+int libkeccak_hmac_copy(libkeccak_hmac_state_t *restrict, const libkeccak_hmac_state_t *restrict);
+
+/**
+ * A wrapper for `libkeccak_hmac_copy` that also allocates the duplicate
+ *
+ * @param src The state to duplicate
+ * @return The duplicate, `NULL` on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __unused__, __warn_unused_result__, __malloc__)))
+static inline libkeccak_hmac_state_t *
+libkeccak_hmac_duplicate(const libkeccak_hmac_state_t *restrict src)
+{
+ libkeccak_hmac_state_t* restrict dest = malloc(sizeof(libkeccak_hmac_state_t));
+ if (!dest || libkeccak_hmac_copy(dest, src))
+ return libkeccak_hmac_free(dest), NULL;
+ return dest;
+}
+
+/**
+ * Calculates the allocation size required for the second argument
+ * of `libkeccak_hmac_marshal` (`char* restrict data)`)
+ *
+ * @param state The state as it will be marshalled by a subsequent call to `libkeccak_hamc_marshal`
+ * @return The allocation size needed for the buffer to which the state will be marshalled
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__, __unused__, __warn_unused_result__, __pure__)))
+static inline size_t
+libkeccak_hmac_marshal_size(const libkeccak_hmac_state_t *restrict state)
+{
+ return libkeccak_state_marshal_size(&state->sponge) + sizeof(size_t) +
+ ((state->key_length + 7) >> 3) + 2 * sizeof(char);
+}
+
+/**
+ * Marshal a `libkeccak_hmac_state_t` into a buffer
+ *
+ * @param state The state to marshal
+ * @param data The output buffer
+ * @return The number of bytes stored to `data`
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__)))
+static inline size_t
+libkeccak_hmac_marshal(const libkeccak_hmac_state_t *restrict state, void *restrict data_)
+{
+ char *restrict data = data_;
+ size_t written = libkeccak_state_marshal(&state->sponge, data);
+ data += written / sizeof(char);
+ *(size_t *)data = state->key_length;
+ data += sizeof(size_t) / sizeof(char);
+ memcpy(data, state->key_opad, (state->key_length + 7) >> 3);
+ data += ((state->key_length + 7) >> 3) / sizeof(char);
+ data[0] = (char)!!state->key_ipad;
+ data[1] = state->leftover;
+ return written + sizeof(size_t) + ((state->key_length + 7) >> 3) + 2 * sizeof(char);
+}
+
+/**
+ * Unmarshal a `libkeccak_hmac_state_t` from a buffer
+ *
+ * @param state The slot for the unmarshalled state, must not be initialised (memory leak otherwise)
+ * @param data The input buffer
+ * @return The number of bytes read from `data`, 0 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__)))
+size_t libkeccak_hmac_unmarshal(libkeccak_hmac_state_t *restrict, const void *restrict);
+
+/**
+ * Gets the number of bytes the `libkeccak_hmac_state_t` stored
+ * at the beginning of `data` occupies
+ *
+ * @param data The data buffer
+ * @return The byte size of the stored state
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__, __warn_unused_result__, __pure__)))
+static inline size_t
+libkeccak_hmac_unmarshal_skip(const void *restrict data_)
+{
+ const char *restrict data = data_;
+ size_t skip = libkeccak_state_unmarshal_skip(data);
+ data += skip / sizeof(char);
+ return skip + sizeof(size_t) + *(const size_t *)data + 2 * sizeof(char);
+}
+
+/**
+ * Absorb more, or the first part, of the message
+ * without wiping sensitive data when possible
+ *
+ * @param state The hashing state
+ * @param msg The partial message
+ * @param msglen The length of the partial message, in bytes
+ * @return Zero on success, -1 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__(1))))
+int libkeccak_hmac_fast_update(libkeccak_hmac_state_t *restrict state, const void *restrict msg, size_t msglen);
+
+/**
+ * Absorb more, or the first part, of the message
+ * and wipe sensitive data when possible
+ *
+ * @param state The hashing state
+ * @param msg The partial message
+ * @param msglen The length of the partial message, in bytes
+ * @return Zero on success, -1 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__(1))))
+int libkeccak_hmac_update(libkeccak_hmac_state_t *restrict state, const void *restrict msg, size_t msglen);
+
+/**
+ * Absorb the last part of the message and fetch the hash
+ * without wiping sensitive data when possible
+ *
+ * You may use `&state->sponge` for continued squeezing
+ *
+ * @param state The hashing state
+ * @param msg The rest of the message, may be `NULL`, may be modified
+ * @param msglen The length of the partial message
+ * @param bits The number of bits at the end of the message not covered by `msglen`
+ * @param suffix The suffix concatenate to the message, only '1':s and '0':s, and NUL-termination
+ * @param hashsum Output parameter for the hashsum, may be `NULL`
+ * @return Zero on success, -1 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__(1))))
+int libkeccak_hmac_fast_digest(libkeccak_hmac_state_t *restrict state, const void *restrict msg, size_t msglen,
+ size_t bits, const char *restrict suffix, void *restrict hashsum);
+
+/**
+ * Absorb the last part of the message and fetch the hash
+ * and wipe sensitive data when possible
+ *
+ * You may use `&state->sponge` for continued squeezing
+ *
+ * @param state The hashing state
+ * @param msg The rest of the message, may be `NULL`, may be modified
+ * @param msglen The length of the partial message
+ * @param bits The number of bits at the end of the message not covered by `msglen`
+ * @param suffix The suffix concatenate to the message, only '1':s and '0':s, and NUL-termination
+ * @param hashsum Output parameter for the hashsum, may be `NULL`
+ * @return Zero on success, -1 on error
+ */
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__(1))))
+int libkeccak_hmac_digest(libkeccak_hmac_state_t *restrict state, const void *restrict msg, size_t msglen,
+ size_t bits, const char *restrict suffix, void *restrict hashsum);
+
#endif
diff --git a/libkeccak/digest.c b/libkeccak/digest.c
index 26a2587..3e74361 100644
--- a/libkeccak/digest.c
+++ b/libkeccak/digest.c
@@ -1,8 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "digest.h"
-
-#include "state.h"
-
+#include "../common.h"
/**
@@ -33,7 +30,7 @@
* The order the lanes should be read when absorbing or squeezing,
* it transposes the lanes in the sponge
*/
-static const long LANE_TRANSPOSE_MAP[] = { LIST_25 };
+static const long int LANE_TRANSPOSE_MAP[] = { LIST_25 };
#undef X
@@ -79,7 +76,7 @@ static const uint_fast64_t RC[] = {
* @param state The hashing state
* @param rc The round contant for this round
*/
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow, hot)))
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__, __hot__)))
static void
libkeccak_f_round(register libkeccak_state_t *restrict state, register int_fast64_t rc)
{
@@ -88,7 +85,7 @@ libkeccak_f_round(register libkeccak_state_t *restrict state, register int_fast6
int_fast64_t C[5];
int_fast64_t da, db, dc, dd, de;
int_fast64_t wmod = state->wmod;
- long w = state->w;
+ 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];
@@ -127,7 +124,7 @@ libkeccak_f_round(register libkeccak_state_t *restrict state, register int_fast6
* @param state The hashing state
* @param rc The round contant for this round
*/
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow, hot)))
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__, __hot__)))
static void
libkeccak_f_round64(register libkeccak_state_t *restrict state, register int_fast64_t rc)
{
@@ -172,13 +169,13 @@ libkeccak_f_round64(register libkeccak_state_t *restrict state, register int_fas
*
* @param state The hashing state
*/
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow, gnu_inline)))
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__, __gnu_inline__)))
static inline void
libkeccak_f(register libkeccak_state_t *restrict state)
{
- register long i = 0;
- register long nr = state->nr;
- register long wmod = state->wmod;
+ register long int i = 0;
+ register long int nr = state->nr;
+ register long int wmod = state->wmod;
if (nr == 24) {
for (; i < nr; i++)
libkeccak_f_round64(state, (int_fast64_t)(RC[i]));
@@ -199,12 +196,12 @@ libkeccak_f(register libkeccak_state_t *restrict state)
* @param off The offset in the message
* @return The lane
*/
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow, pure, warn_unused_result, gnu_inline)))
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__, __pure__, __warn_unused_result__, __gnu_inline__)))
static inline int_fast64_t
libkeccak_to_lane(register const char *restrict message, register size_t msglen,
- register long rr, register long ww, size_t off)
+ register long int rr, register long int ww, size_t off)
{
- register long n = (long)((msglen < (size_t)rr ? msglen : (size_t)rr) - off);
+ register long int n = (long)((msglen < (size_t)rr ? msglen : (size_t)rr) - off);
int_fast64_t rc = 0;
message += off;
while (ww--) {
@@ -224,12 +221,11 @@ libkeccak_to_lane(register const char *restrict message, register size_t msglen,
* @param off The offset in the message
* @return The lane
*/
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow, pure, hot, warn_unused_result, gnu_inline)))
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__, __pure__, __hot__, __warn_unused_result__, __gnu_inline__)))
static inline int_fast64_t
-libkeccak_to_lane64(register const char* restrict message, register size_t msglen,
- register long rr, size_t off)
+libkeccak_to_lane64(register const char *restrict message, register size_t msglen, register long int rr, size_t off)
{
- register long n = (long)((msglen < (size_t)rr ? msglen : (size_t)rr) - off);
+ register long int n = (long)((msglen < (size_t)rr ? msglen : (size_t)rr) - off);
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);\
@@ -247,7 +243,7 @@ libkeccak_to_lane64(register const char* restrict message, register size_t msgle
* `state->M` should have `state->r / 8` bytes left over at the end
* @param bits The number of bits in the end of the message that does not make a whole byte
*/
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow, gnu_inline)))
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__, __gnu_inline__)))
static inline void
libkeccak_pad10star1(register libkeccak_state_t *restrict state, register size_t bits)
{
@@ -278,13 +274,13 @@ libkeccak_pad10star1(register libkeccak_state_t *restrict state, register size_t
* @param state The hashing state
* @param len The number of bytes from `state->M` to absorb
*/
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow)))
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__)))
static void
libkeccak_absorption_phase(register libkeccak_state_t *restrict state, register size_t len)
{
- register long rr = state->r >> 3;
- register long ww = state->w >> 3;
- register long n = (long)len / rr;
+ register long int rr = state->r >> 3;
+ register long int ww = state->w >> 3;
+ register long int n = (long)len / rr;
register const char* restrict message = state->M;
if (__builtin_expect(ww >= 8, 1)) { /* ww > 8 is impossible, it is just for optimisation possibilities. */
while (n--) {
@@ -317,27 +313,27 @@ libkeccak_absorption_phase(register libkeccak_state_t *restrict state, register
* @param ww The word size in bytes
* @param hashsum Output parameter for the hashsum
*/
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow, hot)))
+LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __nothrow__, __hot__)))
static void
-libkeccak_squeezing_phase(register libkeccak_state_t *restrict state, long rr,
- long nn, long ww, register char *restrict hashsum)
+libkeccak_squeezing_phase(register libkeccak_state_t *restrict state, long int rr,
+ long int nn, long int ww, register unsigned char *restrict hashsum)
{
register int_fast64_t v;
- register long ni = rr / ww;
- auto long olen = state->n;
- auto long i, j = 0;
- register long k;
+ register long int ni = rr / ww;
+ auto long int olen = state->n;
+ auto long int i, j = 0;
+ register long int k;
while (olen > 0) {
for (i = 0; i < ni && j < nn; i++) {
v = state->S[LANE_TRANSPOSE_MAP[i]];
for (k = 0; k++ < ww && j++ < nn; v >>= 8)
- *hashsum++ = (char)v;
+ *hashsum++ = (unsigned char)v;
}
if (olen -= state->r, olen > 0)
libkeccak_f(state);
}
if (state->n & 7)
- hashsum[-1] &= (char)((1 << (state->n & 7)) - 1);
+ hashsum[-1] &= (unsigned char)((1 << (state->n & 7)) - 1);
}
@@ -351,7 +347,7 @@ libkeccak_squeezing_phase(register libkeccak_state_t *restrict state, long rr,
* @return Zero on success, -1 on error
*/
int
-libkeccak_fast_update(libkeccak_state_t *restrict state, const char *restrict msg, size_t msglen)
+libkeccak_fast_update(libkeccak_state_t *restrict state, const void *restrict msg, size_t msglen)
{
size_t len;
auto char *restrict new;
@@ -387,7 +383,7 @@ libkeccak_fast_update(libkeccak_state_t *restrict state, const char *restrict ms
* @return Zero on success, -1 on error
*/
int
-libkeccak_update(libkeccak_state_t *restrict state, const char *restrict msg, size_t msglen)
+libkeccak_update(libkeccak_state_t *restrict state, const void *restrict msg, size_t msglen)
{
size_t len;
auto char *restrict new;
@@ -428,16 +424,17 @@ libkeccak_update(libkeccak_state_t *restrict state, const char *restrict msg, si
* @return Zero on success, -1 on error
*/
int
-libkeccak_fast_digest(libkeccak_state_t *restrict state, const char *restrict msg, size_t msglen,
- size_t bits, const char *restrict suffix, char *restrict hashsum)
+libkeccak_fast_digest(libkeccak_state_t *restrict state, const void *restrict msg_, size_t msglen,
+ size_t bits, const char *restrict suffix, void *restrict hashsum)
{
+ const char *restrict msg = msg_;
auto char *restrict new;
- register long rr = state->r >> 3;
+ register long int rr = state->r >> 3;
auto size_t suffix_len = suffix ? __builtin_strlen(suffix) : 0;
register size_t ext;
- register long i;
+ register long int i;
- if (msg == NULL)
+ if (!msg)
msglen = bits = 0;
else
msglen += bits >> 3, bits &= 7;
@@ -496,16 +493,17 @@ libkeccak_fast_digest(libkeccak_state_t *restrict state, const char *restrict ms
* @return Zero on success, -1 on error
*/
int
-libkeccak_digest(libkeccak_state_t *restrict state, const char *restrict msg, size_t msglen,
- size_t bits, const char *restrict suffix, char *restrict hashsum)
+libkeccak_digest(libkeccak_state_t *restrict state, const void *restrict msg_, size_t msglen,
+ size_t bits, const char *restrict suffix, void *restrict hashsum)
{
+ const char *restrict msg = msg_;
auto char *restrict new;
- register long rr = state->r >> 3;
+ register long int rr = state->r >> 3;
auto size_t suffix_len = suffix ? __builtin_strlen(suffix) : 0;
register size_t ext;
- register long i;
+ register long int i;
- if (msg == NULL)
+ if (!msg)
msglen = bits = 0;
else
msglen += bits >> 3, bits &= 7;
@@ -560,7 +558,7 @@ libkeccak_digest(libkeccak_state_t *restrict state, const char *restrict msg, si
* @param times The number of rounds
*/
void
-libkeccak_simple_squeeze(register libkeccak_state_t *restrict state, register long times)
+libkeccak_simple_squeeze(register libkeccak_state_t *restrict state, register long int times)
{
while (times--)
libkeccak_f(state);
@@ -574,7 +572,7 @@ libkeccak_simple_squeeze(register libkeccak_state_t *restrict state, register lo
* @param times The number of digests
*/
void
-libkeccak_fast_squeeze(register libkeccak_state_t *restrict state, register long times)
+libkeccak_fast_squeeze(register libkeccak_state_t *restrict state, register long int times)
{
times *= (state->n - 1) / state->r + 1;
while (times--)
@@ -589,7 +587,7 @@ libkeccak_fast_squeeze(register libkeccak_state_t *restrict state, register long
* @param hashsum Output parameter for the hashsum
*/
void
-libkeccak_squeeze(register libkeccak_state_t *restrict state, register char* restrict hashsum)
+libkeccak_squeeze(register libkeccak_state_t *restrict state, register void *restrict hashsum)
{
libkeccak_f(state);
libkeccak_squeezing_phase(state, state->r >> 3, (state->n + 7) >> 3, state->w >> 3, hashsum);
diff --git a/libkeccak/digest.h b/libkeccak/digest.h
deleted file mode 100644
index 832f0c0..0000000
--- a/libkeccak/digest.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef LIBKECCAK_DIGEST_H
-#define LIBKECCAK_DIGEST_H 1
-
-#include "state.h"
-#include "internal.h"
-
-
-/**
- * Absorb more of the message to the Keccak sponge
- * without wiping sensitive data when possible
- *
- * @param state The hashing state
- * @param msg The partial message
- * @param msglen The length of the partial message
- * @return Zero on success, -1 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull)))
-int libkeccak_fast_update(libkeccak_state_t *restrict state, const char* restrict msg, size_t msglen);
-
-
-/**
- * Absorb more of the message to the Keccak sponge
- * and wipe sensitive data when possible
- *
- * @param state The hashing state
- * @param msg The partial message
- * @param msglen The length of the partial message
- * @return Zero on success, -1 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull)))
-int libkeccak_update(libkeccak_state_t *restrict state, const char *restrict msg, size_t msglen);
-
-
-/**
- * Absorb the last part of the message and squeeze the Keccak sponge
- * without wiping sensitive data when possible
- *
- * @param state The hashing state
- * @param msg The rest of the message, may be `NULL`
- * @param msglen The length of the partial message
- * @param bits The number of bits at the end of the message not covered by `msglen`
- * @param suffix The suffix concatenate to the message, only '1':s and '0':s, and NUL-termination
- * @param hashsum Output parameter for the hashsum, may be `NULL`
- * @return Zero on success, -1 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull(1))))
-int libkeccak_fast_digest(libkeccak_state_t *restrict state, const char *restrict msg, size_t msglen,
- size_t bits, const char *restrict suffix, char *restrict hashsum);
-
-
-/**
- * Absorb the last part of the message and squeeze the Keccak sponge
- * and wipe sensitive data when possible
- *
- * @param state The hashing state
- * @param msg The rest of the message, may be `NULL`
- * @param msglen The length of the partial message
- * @param bits The number of bits at the end of the message not covered by `msglen`
- * @param suffix The suffix concatenate to the message, only '1':s and '0':s, and NUL-termination
- * @param hashsum Output parameter for the hashsum, may be `NULL`
- * @return Zero on success, -1 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull(1))))
-int libkeccak_digest(libkeccak_state_t *restrict state, const char *restrict msg, size_t msglen,
- size_t bits, const char *restrict suffix, char *restrict hashsum);
-
-
-/**
- * Force some rounds of Keccak-f
- *
- * @param state The hashing state
- * @param times The number of rounds
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow)))
-void libkeccak_simple_squeeze(register libkeccak_state_t *restrict state, register long times);
-
-
-/**
- * Squeeze as much as is needed to get a digest a number of times
- *
- * @param state The hashing state
- * @param times The number of digests
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow)))
-void libkeccak_fast_squeeze(register libkeccak_state_t *restrict state, register long times);
-
-
-/**
- * Squeeze out another digest
- *
- * @param state The hashing state
- * @param hashsum Output parameter for the hashsum
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow)))
-void libkeccak_squeeze(register libkeccak_state_t *restrict state, register char* restrict hashsum);
-
-
-#endif
-
diff --git a/libkeccak/files.c b/libkeccak/files.c
index 22d12f3..14a4290 100644
--- a/libkeccak/files.c
+++ b/libkeccak/files.c
@@ -1,12 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "files.h"
-
-#include <sys/stat.h>
-#include <alloca.h>
-#include <errno.h>
-#include <stddef.h>
-#include <unistd.h>
-
+#include "../common.h"
/**
@@ -22,9 +15,8 @@
* @return Zero on success, -1 on error
*/
int
-libkeccak_generalised_sum_fd(int fd, libkeccak_state_t *restrict state,
- const libkeccak_spec_t *restrict spec,
- const char *restrict suffix, char *restrict hashsum)
+libkeccak_generalised_sum_fd(int fd, libkeccak_state_t *restrict state, const libkeccak_spec_t *restrict spec,
+ const char *restrict suffix, void *restrict hashsum)
{
ssize_t got;
struct stat attr;
diff --git a/libkeccak/files.h b/libkeccak/files.h
deleted file mode 100644
index 92038fb..0000000
--- a/libkeccak/files.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef LIBKECCAK_FILES_H
-#define LIBKECCAK_FILES_H 1
-
-#include "../libkeccak.h"
-#include "internal.h"
-
-
-/**
- * Calculate a Keccak-family hashsum of a file,
- * the content of the file is assumed non-sensitive
- *
- * @param fd The file descriptor of the file to hash
- * @param state The hashing state, should not be initialised (memory leak otherwise)
- * @param spec Specifications for the hashing algorithm
- * @param suffix The data suffix, see `libkeccak_digest`
- * @param hashsum Output array for the hashsum, have an allocation size of
- * at least `((spec->output + 7) / 8) * sizeof(char)`, may be `NULL`
- * @return Zero on success, -1 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull(2, 3))))
-int libkeccak_generalised_sum_fd(int fd, libkeccak_state_t *restrict state,
- const libkeccak_spec_t *restrict spec,
- const char *restrict suffix, char *restrict hashsum);
-
-
-/**
- * Calculate the Keccak hashsum of a file,
- * the content of the file is assumed non-sensitive
- *
- * @param fd The file descriptor of the file to hash
- * @param state The hashing state, should not be initialised (memory leak otherwise)
- * @param spec Specifications for the hashing algorithm
- * @param hashsum Output array for the hashsum, have an allocation size of
- * at least `((spec->output + 7) / 8) * sizeof(char)`, may be `NULL`
- * @return Zero on success, -1 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull(2, 3), artificial, gnu_inline)))
-static inline int
-libkeccak_keccaksum_fd(int fd, libkeccak_state_t *restrict state,
- const libkeccak_spec_t *restrict spec, char *restrict hashsum)
-{
- return libkeccak_generalised_sum_fd(fd, state, spec, NULL, hashsum);
-}
-
-
-/**
- * Calculate the SHA3 hashsum of a file,
- * the content of the file is assumed non-sensitive
- *
- * @param fd The file descriptor of the file to hash
- * @param state The hashing state, should not be initialised (memory leak otherwise)
- * @param output The output size parameter for the hashing algorithm
- * @param hashsum Output array for the hashsum, have an allocation size of
- * at least `((output + 7) / 8) * sizeof(char)`, may be `NULL`
- * @return Zero on success, -1 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull(2), artificial, gnu_inline)))
-static inline int
-libkeccak_sha3sum_fd(int fd, libkeccak_state_t *restrict state,
- long output, char *restrict hashsum)
-{
- libkeccak_spec_t spec;
- libkeccak_spec_sha3(&spec, output);
- return libkeccak_generalised_sum_fd(fd, state, &spec, LIBKECCAK_SHA3_SUFFIX, hashsum);
-}
-
-
-/**
- * Calculate the RawSHAKE hashsum of a file,
- * the content of the file is assumed non-sensitive
- *
- * @param fd The file descriptor of the file to hash
- * @param state The hashing state, should not be initialised (memory leak otherwise)
- * @param semicapacity The semicapacity parameter for the hashing algorithm
- * @param output The output size parameter for the hashing algorithm
- * @param hashsum Output array for the hashsum, have an allocation size of
- * at least `((output + 7) / 8) * sizeof(char)`, may be `NULL`
- * @return Zero on success, -1 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull(2), artificial, gnu_inline)))
-static inline int
-libkeccak_rawshakesum_fd(int fd, libkeccak_state_t *restrict state,
- long semicapacity, long output, char *restrict hashsum)
-{
- libkeccak_spec_t spec;
- libkeccak_spec_rawshake(&spec, semicapacity, output);
- return libkeccak_generalised_sum_fd(fd, state, &spec, LIBKECCAK_RAWSHAKE_SUFFIX, hashsum);
-}
-
-
-/**
- * Calculate the SHAKE hashsum of a file,
- * the content of the file is assumed non-sensitive
- *
- * @param fd The file descriptor of the file to hash
- * @param state The hashing state, should not be initialised (memory leak otherwise)
- * @param semicapacity The semicapacity parameter for the hashing algorithm
- * @param output The output size parameter for the hashing algorithm
- * @param hashsum Output array for the hashsum, have an allocation size of
- * at least `((output + 7) / 8) * sizeof(char)`, may be `NULL`
- * @return Zero on success, -1 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull(2), artificial, gnu_inline)))
-static inline int
-libkeccak_shakesum_fd(int fd, libkeccak_state_t *restrict state,
- long semicapacity, long output, char *restrict hashsum)
-{
- libkeccak_spec_t spec;
- libkeccak_spec_shake(&spec, semicapacity, output);
- return libkeccak_generalised_sum_fd(fd, state, &spec, LIBKECCAK_SHAKE_SUFFIX, hashsum);
-}
-
-
-#endif
diff --git a/libkeccak/generalised-spec.c b/libkeccak/generalised-spec.c
index 9dfa918..0f78583 100644
--- a/libkeccak/generalised-spec.c
+++ b/libkeccak/generalised-spec.c
@@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
-#include "generalised-spec.h"
+#include "../common.h"
+
#ifdef __GNUC__
# pragma GCC diagnostic push
@@ -26,7 +27,7 @@ int
libkeccak_degeneralise_spec(libkeccak_generalised_spec_t *restrict spec,
libkeccak_spec_t *restrict output_spec)
{
- long state_size, word_size, capacity, bitrate, output;
+ long int state_size, word_size, capacity, bitrate, output;
const int have_state_size = have(state_size);
const int have_word_size = have(word_size);
const int have_capacity = have(capacity);
diff --git a/libkeccak/generalised-spec.h b/libkeccak/generalised-spec.h
deleted file mode 100644
index 2725961..0000000
--- a/libkeccak/generalised-spec.h
+++ /dev/null
@@ -1,142 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef LIBKECCAK_GENERALISED_SPEC_H
-#define LIBKECCAK_GENERALISED_SPEC_H 1
-
-#include "spec.h"
-#include "internal.h"
-
-#include <inttypes.h>
-
-
-
-/**
- * Value for `libkeccak_generalised_spec_t` member that
- * is used to automatically select the value
- */
-#define LIBKECCAK_GENERALISED_SPEC_AUTOMATIC (-65536L)
-
-
-/**
- * Invalid `libkeccak_generalised_spec_t.state_size`: non-positive
- */
-#define LIBKECCAK_GENERALISED_SPEC_ERROR_STATE_NONPOSITIVE 1
-
-/**
- * Invalid `libkeccak_generalised_spec_t.state_size`: larger than 1600
- */
-#define LIBKECCAK_GENERALISED_SPEC_ERROR_STATE_TOO_LARGE 2
-
-/**
- * Invalid `libkeccak_generalised_spec_t.state_size`: not a multiple of 25
- */
-#define LIBKECCAK_GENERALISED_SPEC_ERROR_STATE_MOD_25 3
-
-/**
- * Invalid `libkeccak_generalised_spec_t.word_size`: non-positive
- */
-#define LIBKECCAK_GENERALISED_SPEC_ERROR_WORD_NONPOSITIVE 4
-
-/**
- * Invalid `libkeccak_generalised_spec_t.word_size`: larger than 1600 / 25
- */
-#define LIBKECCAK_GENERALISED_SPEC_ERROR_WORD_TOO_LARGE 5
-
-/**
- * Invalid `libkeccak_generalised_spec_t.word_size` and
- * `libkeccak_generalised_spec_t.state_size`: `.word_size * 25 != .state_size`
- */
-#define LIBKECCAK_GENERALISED_SPEC_ERROR_STATE_WORD_INCOHERENCY 6
-
-/**
- * Invalid `libkeccak_generalised_spec_t.capacity`: non-positive
- */
-#define LIBKECCAK_GENERALISED_SPEC_ERROR_CAPACITY_NONPOSITIVE 7
-
-/**
- * Invalid `libkeccak_generalised_spec_t.capacity`: not a multiple of 8
- */
-#define LIBKECCAK_GENERALISED_SPEC_ERROR_CAPACITY_MOD_8 8
-
-/**
- * Invalid `libkeccak_generalised_spec_t.bitrate`: non-positive
- */
-#define LIBKECCAK_GENERALISED_SPEC_ERROR_BITRATE_NONPOSITIVE 9
-
-/**
- * Invalid `libkeccak_generalised_spec_t.bitrate`: not a multiple of 8
- */
-#define LIBKECCAK_GENERALISED_SPEC_ERROR_BITRATE_MOD_8 10
-
-/**
- * Invalid `libkeccak_generalised_spec_t.output`: non-positive
- */
-#define LIBKECCAK_GENERALISED_SPEC_ERROR_OUTPUT_NONPOSITIVE 11
-
-
-
-/**
- * Generalised datastructure that describes the
- * parameters that should be used when hashing
- */
-typedef struct libkeccak_generalised_spec
-{
- /**
- * The bitrate
- */
- long bitrate;
-
- /**
- * The capacity
- */
- long capacity;
-
- /**
- * The output size
- */
- long output;
-
- /**
- * The state size
- */
- long state_size;
-
- /**
- * The word size
- */
- long word_size;
-
-} libkeccak_generalised_spec_t;
-
-
-
-/**
- * Set all specification parameters to automatic
- *
- * @param spec The specification datastructure to fill in
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow, unused)))
-static inline void
-libkeccak_generalised_spec_initialise(libkeccak_generalised_spec_t *restrict spec)
-{
- spec->bitrate = LIBKECCAK_GENERALISED_SPEC_AUTOMATIC;
- spec->capacity = LIBKECCAK_GENERALISED_SPEC_AUTOMATIC;
- spec->output = LIBKECCAK_GENERALISED_SPEC_AUTOMATIC;
- spec->state_size = LIBKECCAK_GENERALISED_SPEC_AUTOMATIC;
- spec->word_size = LIBKECCAK_GENERALISED_SPEC_AUTOMATIC;
-}
-
-
-/**
- * Convert a `libkeccak_generalised_spec_t` to a `libkeccak_spec_t`
- *
- * @param spec The generalised input specifications, will be update with resolved automatic values
- * @param output_spec The specification datastructure to fill in
- * @return Zero if `spec` is valid, a `LIBKECCAK_GENERALISED_SPEC_ERROR_*` if an error was found
- */
-LIBKECCAK_GCC_ONLY(__attribute__((leaf, nonnull, nothrow)))
-int libkeccak_degeneralise_spec(libkeccak_generalised_spec_t *restrict spec,
- libkeccak_spec_t *restrict output_spec);
-
-
-#endif
-
diff --git a/libkeccak/hex.c b/libkeccak/hex.c
index 7531223..7db49a6 100644
--- a/libkeccak/hex.c
+++ b/libkeccak/hex.c
@@ -1,8 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "hex.h"
-
-#include <string.h>
-
+#include "../libkeccak.h"
/**
@@ -13,8 +10,9 @@
* @param n The size of `hashsum`
*/
void
-libkeccak_behex_lower(char *restrict output, const char *restrict hashsum, size_t n)
+libkeccak_behex_lower(char *restrict output, const void *restrict hashsum_, size_t n)
{
+ const char *restrict hashsum = hashsum_;
output[2 * n] = '\0';
while (n--) {
output[2 * n + 0] = "0123456789abcdef"[(hashsum[n] >> 4) & 15];
@@ -31,8 +29,9 @@ libkeccak_behex_lower(char *restrict output, const char *restrict hashsum, size_
* @param n The size of `hashsum`
*/
void
-libkeccak_behex_upper(char *restrict output, const char *restrict hashsum, size_t n)
+libkeccak_behex_upper(char *restrict output, const void *restrict hashsum_, size_t n)
{
+ const char *restrict hashsum = hashsum_;
output[2 * n] = '\0';
while (n--) {
output[2 * n + 0] = "0123456789ABCDEF"[(hashsum[n] >> 4) & 15];
@@ -49,8 +48,9 @@ libkeccak_behex_upper(char *restrict output, const char *restrict hashsum, size_
* @param hashsum The hashsum to convert
*/
void
-libkeccak_unhex(char *restrict output, const char *restrict hashsum)
+libkeccak_unhex(void *restrict output_, const char *restrict hashsum)
{
+ char *restrict output = output_;
size_t n = strlen(hashsum) / 2;
char a, b;
while (n--) {
diff --git a/libkeccak/hex.h b/libkeccak/hex.h
deleted file mode 100644
index 25375d5..0000000
--- a/libkeccak/hex.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef LIBKECCAK_HEX_H
-#define LIBKECCAK_HEX_H 1
-
-#include "internal.h"
-
-#include <stddef.h>
-
-
-/**
- * Convert a binary hashsum to lower case hexadecimal representation
- *
- * @param output Output array, should have an allocation size of at least `2 * n + 1`
- * @param hashsum The hashsum to convert
- * @param n The size of `hashsum`
- */
-LIBKECCAK_GCC_ONLY(__attribute__((leaf, nonnull, nothrow)))
-void libkeccak_behex_lower(char *restrict output, const char *restrict hashsum, size_t n);
-
-
-/**
- * Convert a binary hashsum to upper case hexadecimal representation
- *
- * @param output Output array, should have an allocation size of at least `2 * n + 1`
- * @param hashsum The hashsum to convert
- * @param n The size of `hashsum`
- */
-LIBKECCAK_GCC_ONLY(__attribute__((leaf, nonnull, nothrow)))
-void libkeccak_behex_upper(char *restrict output, const char *restrict hashsum, size_t n);
-
-
-/**
- * Convert a hexadecimal hashsum (both lower case, upper
- * case and mixed is supported) to binary representation
- *
- * @param output Output array, should have an allocation size of at least `strlen(hashsum) / 2`
- * @param hashsum The hashsum to convert
- */
-LIBKECCAK_GCC_ONLY(__attribute__((leaf, nonnull, nothrow)))
-void libkeccak_unhex(char *restrict output, const char *restrict hashsum);
-
-
-#endif
-
diff --git a/libkeccak/mac/hmac.c b/libkeccak/hmac.c
index ee3bc6a..aca938e 100644
--- a/libkeccak/mac/hmac.c
+++ b/libkeccak/hmac.c
@@ -1,7 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "hmac.h"
-
-#include "../digest.h"
+#include "../common.h"
@@ -18,7 +16,7 @@
static void *(*volatile my_explicit_memset)(void *, int, size_t) = memset;
-static __attribute__((optimize("-O0"))) void
+static __attribute__((__optimize__("-O0"))) void
my_explicit_bzero(void *ptr, size_t size)
{
(*my_explicit_memset)(ptr, 0, size);
@@ -34,7 +32,7 @@ my_explicit_bzero(void *ptr, size_t size)
* @return Zero on success, -1 on error
*/
int
-libkeccak_hmac_set_key(libkeccak_hmac_state_t *restrict state, const char *restrict key, size_t key_length)
+libkeccak_hmac_set_key(libkeccak_hmac_state_t *restrict state, const void *restrict key, size_t key_length)
{
size_t i, size, new_key_length, key_bytes;
char *old;
@@ -131,8 +129,9 @@ libkeccak_hmac_copy(libkeccak_hmac_state_t *restrict dest, const libkeccak_hmac_
* @return The number of bytes read from `data`, 0 on error
*/
size_t
-libkeccak_hmac_unmarshal(libkeccak_hmac_state_t *restrict state, const char *restrict data)
+libkeccak_hmac_unmarshal(libkeccak_hmac_state_t *restrict state, const void *restrict data_)
{
+ const char *restrict data = data_;
size_t parsed, size, i;
state->key_opad = NULL;
@@ -178,8 +177,9 @@ libkeccak_hmac_unmarshal(libkeccak_hmac_state_t *restrict state, const char *res
* @return Zero on success, -1 on error
*/
int
-libkeccak_hmac_fast_update(libkeccak_hmac_state_t *restrict state, const char *restrict msg, size_t msglen)
+libkeccak_hmac_fast_update(libkeccak_hmac_state_t *restrict state, const void *restrict msg_, size_t msglen)
{
+ const char *restrict msg = msg_;
char *old;
size_t i;
int n, cn;
@@ -226,8 +226,9 @@ libkeccak_hmac_fast_update(libkeccak_hmac_state_t *restrict state, const char *r
* @return Zero on success, -1 on error
*/
int
-libkeccak_hmac_update(libkeccak_hmac_state_t *restrict state, const char *restrict msg, size_t msglen)
+libkeccak_hmac_update(libkeccak_hmac_state_t *restrict state, const void *restrict msg_, size_t msglen)
{
+ const char *restrict msg = msg_;
size_t i;
int n, cn, r;
@@ -280,9 +281,10 @@ libkeccak_hmac_update(libkeccak_hmac_state_t *restrict state, const char *restri
* @return Zero on success, -1 on error
*/
int
-libkeccak_hmac_fast_digest(libkeccak_hmac_state_t *restrict state, const char *restrict msg, size_t msglen,
- size_t bits, const char *restrict suffix, char *restrict hashsum)
+libkeccak_hmac_fast_digest(libkeccak_hmac_state_t *restrict state, const void *restrict msg_, size_t msglen,
+ size_t bits, const char *restrict suffix, void *restrict hashsum)
{
+ const char *restrict msg = msg_;
size_t hashsize = state->sponge.n >> 3;
char *tmp = malloc(((state->sponge.n + 7) >> 3) * sizeof(char));
char leftover[2];
@@ -355,9 +357,10 @@ fail:
* @return Zero on success, -1 on error
*/
int
-libkeccak_hmac_digest(libkeccak_hmac_state_t *restrict state, const char *restrict msg, size_t msglen,
- size_t bits, const char *restrict suffix, char *restrict hashsum)
+libkeccak_hmac_digest(libkeccak_hmac_state_t *restrict state, const void *restrict msg_, size_t msglen,
+ size_t bits, const char *restrict suffix, void *restrict hashsum)
{
+ const char *restrict msg = msg_;
size_t hashsize = state->sponge.n >> 3;
char *tmp = malloc(((state->sponge.n + 7) >> 3) * sizeof(char));
char leftover[2];
@@ -410,7 +413,7 @@ stage_3:
my_explicit_bzero(tmp, ((state->sponge.n + 7) >> 3) * sizeof(char));
free(tmp);
return 0;
- fail:
+fail:
my_explicit_bzero(tmp, ((state->sponge.n + 7) >> 3) * sizeof(char));
free(tmp);
return -1;
diff --git a/libkeccak/internal.h b/libkeccak/internal.h
index 466abf9..3e45c15 100644
--- a/libkeccak/internal.h
+++ b/libkeccak/internal.h
@@ -3,17 +3,6 @@
#define LIBKECCAK_INTERNAL_H 1
-/**
- * Only include some C code (not for CPP directives)
- * if compiling with GCC.
- */
-#ifdef __GNUC__
-# define LIBKECCAK_GCC_ONLY(x) x
-#else
-# define LIBKECCAK_GCC_ONLY(x)
-#endif
-
-
/* Use built in functions and branching optimisation if available */
#ifndef __GNUC__
# define __builtin_expect(expression, expect) expression
diff --git a/libkeccak/mac/hmac.h b/libkeccak/mac/hmac.h
deleted file mode 100644
index 2681e61..0000000
--- a/libkeccak/mac/hmac.h
+++ /dev/null
@@ -1,393 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef LIBKECCAK_MAC_HMAC_H
-#define LIBKECCAK_MAC_HMAC_H 1
-
-/*
- * The Keccak hash-function, that was selected by NIST as the SHA-3 competition winner,
- * doesn't need this nested approach and can be used to generate a MAC by simply prepending
- * the key to the message. [http://keccak.noekeon.org]
- */
-
-#include "../spec.h"
-#include "../state.h"
-#include "../internal.h"
-
-#include <stddef.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-
-
-
-/**
- * Datastructure that describes the state of an HMAC-hashing process
- */
-typedef struct libkeccak_hmac_state
-{
- /**
- * The key right-padded and XOR:ed with the outer pad
- */
- char *restrict key_opad;
-
- /**
- * The key right-padded and XOR:ed with the inner pad
- */
- char *restrict key_ipad;
- /* Not marshalled, implicitly unmarshalled using `key_opad`. */
- /* Shares allocation with `key_opad`, do not `free`. */
-
- /**
- * The length of key, but at least the input block size, in bits
- */
- size_t key_length;
-
- /**
- * The state of the underlaying hash-algorithm
- */
- libkeccak_state_t sponge;
-
- /**
- * Buffer used to temporarily store bit shift message if
- * `.key_length` is not zero modulus 8
- */
- char *restrict buffer;
-
- /**
- * The allocation size of `.buffer`
- */
- size_t buffer_size;
-
- /**
- * Part of feed key, message or digest that have not been passed yet
- */
- char leftover;
-
- char __pad[sizeof(void*) / sizeof(char) - 1];
-
-} libkeccak_hmac_state_t;
-
-
-
-/**
- * Change the HMAC-hashing key on the state
- *
- * @param state The state that should be reset
- * @param key The new key
- * @param key_length The length of key, in bits
- * @return Zero on success, -1 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull(1), unused)))
-int libkeccak_hmac_set_key(libkeccak_hmac_state_t *restrict state, const char *restrict key, size_t key_length);
-
-
-/**
- * Initialise an HMAC hashing-state according to hashing specifications
- *
- * @param state The state that should be initialised
- * @param spec The specifications for the state
- * @param key The key
- * @param key_length The length of key, in bits
- * @return Zero on success, -1 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull)))
-static inline int
-libkeccak_hmac_initialise(libkeccak_hmac_state_t *restrict state, const libkeccak_spec_t *restrict spec,
- const char *restrict key, size_t key_length)
-{
- if (libkeccak_state_initialise(&state->sponge, spec) < 0)
- return -1;
- if (libkeccak_hmac_set_key(state, key, key_length) < 0)
- return libkeccak_state_destroy(&state->sponge), -1;
- state->leftover = 0;
- state->buffer = NULL;
- state->buffer_size = 0;
- return 0;
-}
-
-
-/**
- * Wrapper for `libkeccak_hmac_initialise` that also allocates the states
- *
- * @param spec The specifications for the state
- * @param key The key
- * @param key_length The length of key, in bits
- * @return The state, `NULL` on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, unused, warn_unused_result, malloc)))
-static inline libkeccak_hmac_state_t *
-libkeccak_hmac_create(const libkeccak_spec_t *restrict spec,
- const char *restrict key, size_t key_length)
-{
- libkeccak_hmac_state_t *restrict state = malloc(sizeof(libkeccak_hmac_state_t));
- if (!state || libkeccak_hmac_initialise(state, spec, key, key_length))
- return free(state), NULL;
- return state;
-}
-
-
-/**
- * Reset an HMAC-hashing state according to hashing specifications,
- * you can choose whether to change the key
- *
- * @param state The state that should be reset
- * @param key The new key, `NULL` to keep the old key
- * @param key_length The length of key, in bits, ignored if `key == NULL`
- * @return Zero on success, -1 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull(1), unused)))
-static inline int
-libkeccak_hmac_reset(libkeccak_hmac_state_t *restrict state, const char *restrict key, size_t key_length)
-{
- libkeccak_state_reset(&state->sponge);
- return key ? libkeccak_hmac_set_key(state, key, key_length) : 0;
-}
-
-
-/**
- * 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_hmac_wipe(volatile libkeccak_hmac_state_t *restrict state);
-
-
-/**
- * Release resources allocation for an HMAC hashing-state without wiping sensitive data
- *
- * @param state The state that should be destroyed
- */
-static inline void
-libkeccak_hmac_fast_destroy(libkeccak_hmac_state_t *restrict state)
-{
- if (!state)
- return;
- free(state->key_opad);
- state->key_opad = NULL;
- state->key_ipad = NULL;
- state->key_length = 0;
- free(state->buffer);
- state->buffer = NULL;
- state->buffer_size = 0;
-}
-
-
-/**
- * Release resources allocation for an HMAC hasing-state and wipe sensitive data
- *
- * @param state The state that should be destroyed
- */
-LIBKECCAK_GCC_ONLY(__attribute__((unused, optimize("-O0"))))
-static inline void
-libkeccak_hmac_destroy(volatile libkeccak_hmac_state_t *restrict state)
-{
- if (!state)
- return;
- libkeccak_hmac_wipe(state);
- free(state->key_opad);
- state->key_opad = NULL;
- state->key_ipad = NULL;
- state->key_length = 0;
- state->leftover = 0;
- free(state->buffer);
- state->buffer = NULL;
- state->buffer_size = 0;
-}
-
-
-/**
- * Wrapper for `libkeccak_fast_destroy` that also frees the allocation of the state
- *
- * @param state The state that should be freed
- */
-LIBKECCAK_GCC_ONLY(__attribute__((unused)))
-static inline void
-libkeccak_hmac_fast_free(libkeccak_hmac_state_t *restrict state)
-{
- libkeccak_hmac_fast_destroy(state);
- free(state);
-}
-
-
-/**
- * Wrapper for `libkeccak_hmac_destroy` that also frees the allocation of the state
- *
- * @param state The state that should be freed
- */
-LIBKECCAK_GCC_ONLY(__attribute__((unused, optimize("-O0"))))
-static inline void
-libkeccak_hmac_free(volatile libkeccak_hmac_state_t *restrict state)
-{
-#ifdef __GNUC__
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wcast-qual"
-#endif
- libkeccak_hmac_destroy(state);
- free((libkeccak_hmac_state_t*)state);
-#ifdef __GNUC__
-# pragma GCC diagnostic pop
-#endif
-}
-
-
-/**
- * Make a copy of an HMAC hashing-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__((nonnull)))
-int libkeccak_hmac_copy(libkeccak_hmac_state_t *restrict dest, const libkeccak_hmac_state_t *restrict src);
-
-
-/**
- * A wrapper for `libkeccak_hmac_copy` that also allocates the duplicate
- *
- * @param src The state to duplicate
- * @return The duplicate, `NULL` on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, unused, warn_unused_result, malloc)))
-static inline libkeccak_hmac_state_t *
-libkeccak_hmac_duplicate(const libkeccak_hmac_state_t *restrict src)
-{
- libkeccak_hmac_state_t* restrict dest = malloc(sizeof(libkeccak_hmac_state_t));
- if (!dest || libkeccak_hmac_copy(dest, src))
- return libkeccak_hmac_free(dest), NULL;
- return dest;
-}
-
-
-/**
- * Calculates the allocation size required for the second argument
- * of `libkeccak_hmac_marshal` (`char* restrict data)`)
- *
- * @param state The state as it will be marshalled by a subsequent call to `libkeccak_hamc_marshal`
- * @return The allocation size needed for the buffer to which the state will be marshalled
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow, unused, warn_unused_result, pure)))
-static inline size_t
-libkeccak_hmac_marshal_size(const libkeccak_hmac_state_t *restrict state)
-{
- return libkeccak_state_marshal_size(&state->sponge) + sizeof(size_t) +
- ((state->key_length + 7) >> 3) + 2 * sizeof(char);
-}
-
-
-/**
- * Marshal a `libkeccak_hmac_state_t` into a buffer
- *
- * @param state The state to marshal
- * @param data The output buffer
- * @return The number of bytes stored to `data`
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow)))
-static inline size_t
-libkeccak_hmac_marshal(const libkeccak_hmac_state_t *restrict state, char *restrict data)
-{
- size_t written = libkeccak_state_marshal(&state->sponge, data);
- data += written / sizeof(char);
- *(size_t *)data = state->key_length;
- data += sizeof(size_t) / sizeof(char);
- memcpy(data, state->key_opad, (state->key_length + 7) >> 3);
- data += ((state->key_length + 7) >> 3) / sizeof(char);
- data[0] = (char)!!state->key_ipad;
- data[1] = state->leftover;
- return written + sizeof(size_t) + ((state->key_length + 7) >> 3) + 2 * sizeof(char);
-}
-
-
-/**
- * Unmarshal a `libkeccak_hmac_state_t` from a buffer
- *
- * @param state The slot for the unmarshalled state, must not be initialised (memory leak otherwise)
- * @param data The input buffer
- * @return The number of bytes read from `data`, 0 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull)))
-size_t libkeccak_hmac_unmarshal(libkeccak_hmac_state_t *restrict state, const char *restrict data);
-
-
-/**
- * Gets the number of bytes the `libkeccak_hmac_state_t` stored
- * at the beginning of `data` occupies
- *
- * @param data The data buffer
- * @return The byte size of the stored state
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow, warn_unused_result, pure)))
-static inline size_t
-libkeccak_hmac_unmarshal_skip(const char *restrict data)
-{
- size_t skip = libkeccak_state_unmarshal_skip(data);
- data += skip / sizeof(char);
- return skip + sizeof(size_t) + *(const size_t *)data + 2 * sizeof(char);
-}
-
-
-/**
- * Absorb more, or the first part, of the message
- * without wiping sensitive data when possible
- *
- * @param state The hashing state
- * @param msg The partial message
- * @param msglen The length of the partial message, in bytes
- * @return Zero on success, -1 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull(1))))
-int libkeccak_hmac_fast_update(libkeccak_hmac_state_t *restrict state, const char *restrict msg, size_t msglen);
-
-
-/**
- * Absorb more, or the first part, of the message
- * and wipe sensitive data when possible
- *
- * @param state The hashing state
- * @param msg The partial message
- * @param msglen The length of the partial message, in bytes
- * @return Zero on success, -1 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull(1))))
-int libkeccak_hmac_update(libkeccak_hmac_state_t *restrict state, const char *restrict msg, size_t msglen);
-
-
-/**
- * Absorb the last part of the message and fetch the hash
- * without wiping sensitive data when possible
- *
- * You may use `&state->sponge` for continued squeezing
- *
- * @param state The hashing state
- * @param msg The rest of the message, may be `NULL`, may be modified
- * @param msglen The length of the partial message
- * @param bits The number of bits at the end of the message not covered by `msglen`
- * @param suffix The suffix concatenate to the message, only '1':s and '0':s, and NUL-termination
- * @param hashsum Output parameter for the hashsum, may be `NULL`
- * @return Zero on success, -1 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull(1))))
-int libkeccak_hmac_fast_digest(libkeccak_hmac_state_t *restrict state, const char *restrict msg, size_t msglen,
- size_t bits, const char *restrict suffix, char *restrict hashsum);
-
-
-/**
- * Absorb the last part of the message and fetch the hash
- * and wipe sensitive data when possible
- *
- * You may use `&state->sponge` for continued squeezing
- *
- * @param state The hashing state
- * @param msg The rest of the message, may be `NULL`, may be modified
- * @param msglen The length of the partial message
- * @param bits The number of bits at the end of the message not covered by `msglen`
- * @param suffix The suffix concatenate to the message, only '1':s and '0':s, and NUL-termination
- * @param hashsum Output parameter for the hashsum, may be `NULL`
- * @return Zero on success, -1 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull(1))))
-int libkeccak_hmac_digest(libkeccak_hmac_state_t *restrict state, const char *restrict msg, size_t msglen,
- size_t bits, const char *restrict suffix, char *restrict hashsum);
-
-
-#endif
diff --git a/libkeccak/spec.h b/libkeccak/spec.h
deleted file mode 100644
index 8d73c52..0000000
--- a/libkeccak/spec.h
+++ /dev/null
@@ -1,177 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef LIBKECCAK_SPEC_H
-#define LIBKECCAK_SPEC_H 1
-
-#include "internal.h"
-
-#include <stdint.h>
-#include <limits.h>
-
-
-/**
- * Message suffix for SHA3 hashing
- */
-#define LIBKECCAK_SHA3_SUFFIX "01"
-
-/**
- * Message suffix for RawSHAKE hashing
- */
-#define LIBKECCAK_RAWSHAKE_SUFFIX "11"
-
-/**
- * Message suffix for SHAKE hashing
- */
-#define LIBKECCAK_SHAKE_SUFFIX "1111"
-
-
-/**
- * Invalid `libkeccak_spec_t.bitrate`: non-positive
- */
-#define LIBKECCAK_SPEC_ERROR_BITRATE_NONPOSITIVE 1
-
-/**
- * Invalid `libkeccak_spec_t.bitrate`: not a multiple of 8
- */
-#define LIBKECCAK_SPEC_ERROR_BITRATE_MOD_8 2
-
-/**
- * Invalid `libkeccak_spec_t.capacity`: non-positive
- */
-#define LIBKECCAK_SPEC_ERROR_CAPACITY_NONPOSITIVE 3
-
-/**
- * Invalid `libkeccak_spec_t.capacity`: not a multiple of 8
- */
-#define LIBKECCAK_SPEC_ERROR_CAPACITY_MOD_8 4
-
-/**
- * Invalid `libkeccak_spec_t.output`: non-positive
- */
-#define LIBKECCAK_SPEC_ERROR_OUTPUT_NONPOSITIVE 5
-
-/**
- * Invalid `libkeccak_spec_t` values: `.bitrate + `.capacity`
- * is greater 1600 which is the largest supported state size
- */
-#define LIBKECCAK_SPEC_ERROR_STATE_TOO_LARGE 6
-
-/**
- * Invalid `libkeccak_spec_t` values:
- * `.bitrate + `.capacity` is not a multiple of 25
- */
-#define LIBKECCAK_SPEC_ERROR_STATE_MOD_25 7
-
-/**
- * Invalid `libkeccak_spec_t` values: `.bitrate + `.capacity`
- * is a not a 2-potent multiple of 25
- */
-#define LIBKECCAK_SPEC_ERROR_WORD_NON_2_POTENT 8
-
-/**
- * Invalid `libkeccak_spec_t` values: `.bitrate + `.capacity`
- * is a not multiple of 100, and thus the word size is not
- * a multiple of 8
- */
-#define LIBKECCAK_SPEC_ERROR_WORD_MOD_8 9
-
-
-
-/**
- * Datastructure that describes the parameters
- * that should be used when hashing
- */
-typedef struct libkeccak_spec {
- /**
- * The bitrate
- */
- long bitrate;
-
- /**
- * The capacity
- */
- long capacity;
-
- /**
- * The output size
- */
- long output;
-
-} libkeccak_spec_t;
-
-
-
-/**
- * Fill in a `libkeccak_spec_t` for a SHA3-x hashing
- *
- * @param spec The specifications datastructure to fill in
- * @param x The value of x in `SHA3-x`, the output size
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow)))
-static inline void
-libkeccak_spec_sha3(libkeccak_spec_t *restrict spec, long x)
-{
- spec->bitrate = 1600 - 2 * x;
- spec->capacity = 2 * x;
- spec->output = x;
-}
-
-
-/**
- * Fill in a `libkeccak_spec_t` for a RawSHAKEx hashing
- *
- * @param spec The specifications datastructure to fill in
- * @param x The value of x in `RawSHAKEx`, half the capacity
- * @param d The output size
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow)))
-static inline void
-libkeccak_spec_rawshake(libkeccak_spec_t *restrict spec, long x, long d)
-{
- spec->bitrate = 1600 - 2 * x;
- spec->capacity = 2 * x;
- spec->output = d;
-}
-
-
-/**
- * Fill in a `libkeccak_spec_t` for a SHAKEx hashing
- *
- * @param spec:libkeccak_spec_t* The specifications datastructure to fill in
- * @param x:long The value of x in `SHAKEx`, half the capacity
- * @param d:long The output size
- */
-#define libkeccak_spec_shake libkeccak_spec_rawshake
-
-
-/**
- * Check for errors in a `libkeccak_spec_t`
- *
- * @param spec The specifications datastructure to check
- * @return Zero if error free, a `LIBKECCAK_SPEC_ERROR_*` if an error was found
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow, unused, warn_unused_result, pure)))
-static inline int
-libkeccak_spec_check(const libkeccak_spec_t *restrict spec)
-{
- long state_size = spec->capacity + spec->bitrate;
- int32_t word_size = (int32_t)(state_size / 25);
- if (spec->bitrate <= 0) return LIBKECCAK_SPEC_ERROR_BITRATE_NONPOSITIVE;
- if (spec->bitrate % 8) return LIBKECCAK_SPEC_ERROR_BITRATE_MOD_8;
- if (spec->capacity <= 0) return LIBKECCAK_SPEC_ERROR_CAPACITY_NONPOSITIVE;
- if (spec->capacity % 8) return LIBKECCAK_SPEC_ERROR_CAPACITY_MOD_8;
- if (spec->output <= 0) return LIBKECCAK_SPEC_ERROR_OUTPUT_NONPOSITIVE;
- if (state_size > 1600) return LIBKECCAK_SPEC_ERROR_STATE_TOO_LARGE;
- if (state_size % 25) return LIBKECCAK_SPEC_ERROR_STATE_MOD_25;
- if (word_size % 8) return LIBKECCAK_SPEC_ERROR_WORD_MOD_8;
-
- /* `(x & -x) != x` assumes two's complement, which of course is always
- * satisfied by GCC, however C99 guarantees that `int32_t` exists,
- * and it is basically the same thing as `long int`; with one important
- * difference: it is guaranteed to use two's complement. */
- if ((word_size & -word_size) != word_size)
- return LIBKECCAK_SPEC_ERROR_WORD_NON_2_POTENT;
-
- return 0;
-}
-
-#endif
diff --git a/libkeccak/state.c b/libkeccak/state.c
index c6360b7..9e0ffb1 100644
--- a/libkeccak/state.c
+++ b/libkeccak/state.c
@@ -1,8 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "state.h"
-
-#include <string.h>
-
+#include "../common.h"
/**
@@ -15,7 +12,7 @@
int
libkeccak_state_initialise(libkeccak_state_t *restrict state, const libkeccak_spec_t *restrict spec)
{
- long x;
+ long int x;
state->r = spec->bitrate;
state->n = spec->output;
state->c = spec->capacity;
@@ -104,17 +101,18 @@ libkeccak_state_copy(libkeccak_state_t *restrict dest, const libkeccak_state_t *
* @return The number of bytes stored to `data`
*/
size_t
-libkeccak_state_marshal(const libkeccak_state_t *restrict state, char *restrict data)
+libkeccak_state_marshal(const libkeccak_state_t *restrict state, void *restrict data_)
{
#define set(type, var) *((type *)data) = state->var, data += sizeof(type) / sizeof(char)
- set(long, r);
- set(long, c);
- set(long, n);
- set(long, b);
- set(long, w);
+ char *restrict data = data_;
+ set(long int, r);
+ set(long int, c);
+ set(long int, n);
+ set(long int, b);
+ set(long int, w);
set(int64_t, wmod);
- set(long, l);
- set(long, nr);
+ set(long int, l);
+ set(long int, nr);
memcpy(data, state->S, sizeof(state->S));
data += sizeof(state->S) / sizeof(char);
set(size_t, mptr);
@@ -134,17 +132,18 @@ libkeccak_state_marshal(const libkeccak_state_t *restrict state, char *restrict
* @return The number of bytes read from `data`, 0 on error
*/
size_t
-libkeccak_state_unmarshal(libkeccak_state_t *restrict state, const char *restrict data)
+libkeccak_state_unmarshal(libkeccak_state_t *restrict state, const void *restrict data_)
{
#define get(type, var) state->var = *((const type *)data), data += sizeof(type) / sizeof(char)
- get(long, r);
- get(long, c);
- get(long, n);
- get(long, b);
- get(long, w);
+ const char *restrict data = data_;
+ get(long int, r);
+ get(long int, c);
+ get(long int, n);
+ get(long int, b);
+ get(long int, w);
get(int64_t, wmod);
- get(long, l);
- get(long, nr);
+ get(long int, l);
+ get(long int, nr);
memcpy(state->S, data, sizeof(state->S));
data += sizeof(state->S) / sizeof(char);
get(size_t, mptr);
@@ -167,9 +166,9 @@ libkeccak_state_unmarshal(libkeccak_state_t *restrict state, const char *restric
* @return The byte size of the stored state
*/
size_t
-libkeccak_state_unmarshal_skip(const char *restrict data)
+libkeccak_state_unmarshal_skip(const void *restrict data_)
{
- data += (7 * sizeof(long) + 26 * sizeof(int64_t)) / sizeof(char);
+ const char *restrict data = data_;
+ data += (7 * sizeof(long int) + 26 * sizeof(int64_t)) / sizeof(char);
return sizeof(libkeccak_state_t) - sizeof(char *) + *(const size_t *)data * sizeof(char);
}
-
diff --git a/libkeccak/state.h b/libkeccak/state.h
deleted file mode 100644
index 1c4b24e..0000000
--- a/libkeccak/state.h
+++ /dev/null
@@ -1,295 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef LIBKECCAK_STATE_H
-#define LIBKECCAK_STATE_H 1
-
-#include "spec.h"
-#include "internal.h"
-
-#include <errno.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-
-
-
-/**
- * Datastructure that describes the state of a hashing process
- *
- * The `char`-size of the output hashsum is calculated by `(.n + 7) / 8`
- */
-typedef struct libkeccak_state {
- /**
- * The lanes (state/sponge)
- */
- int64_t S[25];
-
- /**
- * The bitrate
- */
- long r;
-
- /**
- * The capacity
- */
- long c;
-
- /**
- * The output size
- */
- long n;
-
- /**
- * The state size
- */
- long b;
-
- /**
- * The word size
- */
- long w;
-
- /**
- * The word mask
- */
- int64_t wmod;
-
- /**
- * ℓ, the binary logarithm of the word size
- */
- long l;
-
- /**
- * 12 + 2ℓ, the number of rounds
- */
- long nr;
-
- /**
- * Pointer for `M`
- */
- size_t mptr;
-
- /**
- * Size of `M`
- */
- size_t mlen;
-
- /**
- * Left over water to fill the sponge with at next update
- */
- char *M;
-
-} libkeccak_state_t;
-
-
-
-/**
- * Initialise a state according to hashing specifications
- *
- * @param state The state that should be initialised
- * @param spec The specifications for the state
- * @return Zero on success, -1 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((leaf, nonnull)))
-int libkeccak_state_initialise(libkeccak_state_t *restrict state, const libkeccak_spec_t *restrict spec);
-
-
-/**
- * Reset a state according to hashing specifications
- *
- * @param state The state that should be reset
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow, unused)))
-static inline void
-libkeccak_state_reset(libkeccak_state_t *restrict 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
- */
-static inline void
-libkeccak_state_fast_destroy(libkeccak_state_t *restrict state)
-{
- if (state == NULL)
- return;
- 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 libkeccak_state_t *restrict 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 libkeccak_state_t *restrict 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 libkeccak_state_t *restrict state);
-
-
-/**
- * Release resources allocation for a state and wipe sensitive data
- *
- * @param state The state that should be destroyed
- */
-LIBKECCAK_GCC_ONLY(__attribute__((unused, optimize("-O0"))))
-static inline void
-libkeccak_state_destroy(volatile libkeccak_state_t *restrict state)
-{
- if (!state)
- return;
- 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, unused, warn_unused_result, malloc)))
-static inline libkeccak_state_t *
-libkeccak_state_create(const libkeccak_spec_t *restrict spec)
-{
- libkeccak_state_t *restrict state = malloc(sizeof(libkeccak_state_t));
- if (!state || libkeccak_state_initialise(state, spec))
- return free(state), NULL;
- return state;
-}
-
-
-/**
- * Wrapper for `libkeccak_state_fast_destroy` that also frees the allocation of the state
- *
- * @param state The state that should be freed
- */
-LIBKECCAK_GCC_ONLY(__attribute__((unused)))
-static inline void
-libkeccak_state_fast_free(libkeccak_state_t *restrict 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__((unused, optimize("-O0"))))
-static inline void
-libkeccak_state_free(volatile libkeccak_state_t *restrict state)
-{
-#ifdef __GNUC__
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wcast-qual"
-#endif
- libkeccak_state_destroy(state);
- free((libkeccak_state_t *)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(libkeccak_state_t *restrict dest, const libkeccak_state_t *restrict src);
-
-
-/**
- * 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, unused, warn_unused_result, malloc)))
-static inline libkeccak_state_t *
-libkeccak_state_duplicate(const libkeccak_state_t *restrict src)
-{
- libkeccak_state_t *restrict dest = malloc(sizeof(libkeccak_state_t));
- if (!dest || libkeccak_state_copy(dest, src))
- return libkeccak_state_free(dest), NULL;
- return dest;
-}
-
-
-/**
- * Calculates the allocation size required for the second argument
- * of `libkeccak_state_marshal` (`char* restrict data)`)
- *
- * @param state The state as it will be marshalled by a subsequent call to `libkeccak_state_marshal`
- * @return The allocation size needed for the buffer to which the state will be marshalled
- */
-LIBKECCAK_GCC_ONLY(__attribute__((nonnull, nothrow, unused, warn_unused_result, pure)))
-static inline size_t
-libkeccak_state_marshal_size(const libkeccak_state_t *restrict state)
-{
- return sizeof(libkeccak_state_t) - sizeof(char*) + state->mptr * sizeof(char);
-}
-
-
-/**
- * Marshal a `libkeccak_state_t` into a buffer
- *
- * @param state The state to marshal
- * @param data The output buffer
- * @return The number of bytes stored to `data`
- */
-LIBKECCAK_GCC_ONLY(__attribute__((leaf, nonnull, nothrow)))
-size_t libkeccak_state_marshal(const libkeccak_state_t *restrict state, char *restrict data);
-
-
-/**
- * Unmarshal a `libkeccak_state_t` from a buffer
- *
- * @param state The slot for the unmarshalled state, must not be initialised (memory leak otherwise)
- * @param data The input buffer
- * @return The number of bytes read from `data`, 0 on error
- */
-LIBKECCAK_GCC_ONLY(__attribute__((leaf, nonnull)))
-size_t libkeccak_state_unmarshal(libkeccak_state_t *restrict state, const char *restrict data);
-
-
-/**
- * Gets the number of bytes the `libkeccak_state_t` stored
- * at the beginning of `data` occupies
- *
- * @param data The data buffer
- * @return The byte size of the stored state
- */
-LIBKECCAK_GCC_ONLY(__attribute__((leaf, nonnull, nothrow, warn_unused_result, pure)))
-size_t libkeccak_state_unmarshal_skip(const char *restrict data);
-
-#endif
diff --git a/man3/libkeccak_behex_lower.3 b/man3/libkeccak_behex_lower.3
index 85bc843..2078790 100644
--- a/man3/libkeccak_behex_lower.3
+++ b/man3/libkeccak_behex_lower.3
@@ -1,16 +1,14 @@
.TH LIBKECCAK_BEHEX_LOWER 3 LIBKECCAK
.SH NAME
-libkeccak_behex_lower - Converts a binary hashsum to lowercase hexadecimal
+libkeccak_behex_lower - Converts a binary hashsum to lower case hexadecimal
.SH SYNOPSIS
.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_behex_lower(char *restrict \fIoutput\fP,
- const char *restrict \fIhashsum\fP, size_t \fIn\fP);
+
+void libkeccak_behex_lower(char *restrict \fIoutput\fP, const void *restrict \fIhashsum\fP, size_t \fIn\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -45,6 +43,3 @@ function cannot fail.
.SH SEE ALSO
.BR libkeccak_behex_upper (3),
.BR libkeccak_unhex (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_behex_upper.3 b/man3/libkeccak_behex_upper.3
index 7925efc..b5c67bb 100644
--- a/man3/libkeccak_behex_upper.3
+++ b/man3/libkeccak_behex_upper.3
@@ -1,16 +1,13 @@
.TH LIBKECCAK_BEHEX_UPPER 3 LIBKECCAK
.SH NAME
-libkeccak_behex_upper - Converts a binary hashsum to uppercase hexadecimal
+libkeccak_behex_upper - Converts a binary hashsum to upper case hexadecimal
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_behex_upper(char *restrict \fIoutput\fP,
- const char *restrict \fIhashsum\fP, size_t \fIn\fP);
+
+void libkeccak_behex_upper(char *restrict \fIoutput\fP, const void *restrict \fIhashsum\fP, size_t \fIn\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -45,6 +42,3 @@ function cannot fail.
.SH SEE ALSO
.BR libkeccak_behex_lower (3),
.BR libkeccak_unhex (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_degeneralise_spec.3 b/man3/libkeccak_degeneralise_spec.3
index 38a1b73..7ec2b72 100644
--- a/man3/libkeccak_degeneralise_spec.3
+++ b/man3/libkeccak_degeneralise_spec.3
@@ -2,15 +2,12 @@
.SH NAME
libkeccak_degeneralise_spec - Set all specification parameters to automatic
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_degeneralise_spec(libkeccak_generalised_spec_t *\fIspec\fP,
- libkeccak_spec_t *\fIoutput_spec\fP);
+
+int libkeccak_degeneralise_spec(libkeccak_generalised_spec_t *\fIspec\fP, libkeccak_spec_t *\fIoutput_spec\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -34,11 +31,11 @@ function after calling
.PP
.nf
typedef struct libkeccak_generalised_spec {
- long int bitrate; /* bitrate (in bits) */
- long int capacity; /* capacity (in bits) */
- long int output; /* output size (in bits) */
- long int state_size; /* state size (in bits) */
- long int word_size; /* word size (in bits) */
+ long int bitrate; /* bitrate (in bits) */
+ long int capacity; /* capacity (in bits) */
+ long int output; /* output size (in bits) */
+ long int state_size; /* state size (in bits) */
+ long int word_size; /* word size (in bits) */
} libkeccak_generalised_spec_t;
.fi
.SH RETURN VALUES
@@ -99,7 +96,7 @@ function cannot fail.
This examples configure a
.B libkeccak_spec_t
to specify settings for Keccak[c = 512]:
-.LP
+.PP
.nf
int r;
libkeccak_spec_t spec;
@@ -119,6 +116,3 @@ if ((r = libkeccak_spec_check(&spec)));
.BR libkeccak_spec_shake (3),
.BR libkeccak_state_initialise (3),
.BR libkeccak_hmac_initialise (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_digest.3 b/man3/libkeccak_digest.3
index 33b0479..5f42796 100644
--- a/man3/libkeccak_digest.3
+++ b/man3/libkeccak_digest.3
@@ -2,16 +2,13 @@
.SH NAME
libkeccak_digest - Complete the hashing of a message with erasure
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_digest(libkeccak_state_t *\fIstate\fP, const char *\fImsg\fP,
- size_t \fImsglen\fP, size_t \fIbits\fP, const char *\fIsuffix\fP,
- char *\fIhashsum\fP);
+
+int libkeccak_digest(libkeccak_state_t *\fIstate\fP, const void *\fImsg\fP, size_t \fImsglen\fP,
+ size_t \fIbits\fP, const char *\fIsuffix\fP, void *\fIhashsum\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -54,7 +51,7 @@ the message. If this string is empty,
may be used instead. This is used to select hash algorithm.
For pure Keccak,
.I NULL
-or "" is used. For the other algorithms the constants
+or \(dq\(dq is used. For the other algorithms the constants
.B LIBKECCAK_SHA3_SUFFIX
(for SHA-3),
.B LIBKECCAK_RAWSHAKE_SUFFIX
@@ -97,7 +94,7 @@ function may fail for any reason specified by the function
This example calculates the Keccak[b = 1024, c = 576, n = 256]
hash of the input from stdin, and prints the hash, in hexadecimal
form, to stdout.
-.LP
+.PP
.nf
libkeccak_state_t state;
libkeccak_spec_t spec;
@@ -110,26 +107,26 @@ spec.bitrate = 1024;
spec.capacity = 576;
spec.output = 256;
if (libkeccak_state_initialise(&state, &spec) < 0)
- goto fail;
+ goto fail;
for (;;) {
- len = read(STDIN_FILENO, chunk, sizeof(chunk));
+ len = read(STDIN_FILENO, chunk, sizeof(chunk));
- if ((len < 0) && (errno == EINTR))
- continue;
- if (len < 0)
- goto fail;
- if (len == 0)
- break;
+ if ((len < 0) && (errno == EINTR))
+ continue;
+ if (len < 0)
+ goto fail;
+ if (len == 0)
+ break;
- if (libkeccak_update(&state, chunk, (size_t)len) < 0)
- goto fail;
+ if (libkeccak_update(&state, chunk, (size_t)len) < 0)
+ goto fail;
}
-if (libkeccak_digest(&state, NULL, 0, 0, "", binhash) < 0)
- goto fail;
+if (libkeccak_digest(&state, NULL, 0, 0, \(dq\(dq, binhash) < 0)
+ goto fail;
libkeccak_behex_lower(hexhash, binhash, sizeof(binhash));
-printf("%s\\n", hexhash);
+printf(\(dq%s\en\(dq, hexhash);
libkeccak_state_destroy(&state);
.fi
.SH SEE ALSO
@@ -140,6 +137,3 @@ libkeccak_state_destroy(&state);
.BR libkeccak_simple_squeeze (3),
.BR libkeccak_fast_squeeze (3),
.BR libkeccak_squeeze (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_fast_digest.3 b/man3/libkeccak_fast_digest.3
index d5c55a5..9e9c1f3 100644
--- a/man3/libkeccak_fast_digest.3
+++ b/man3/libkeccak_fast_digest.3
@@ -5,11 +5,9 @@ libkeccak_fast_digest - Complete the hashing of a message without erasure
.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_fast_digest(libkeccak_state_t *\fIstate\fP, const char *\fImsg\fP,
- size_t \fImsglen\fP, size_t \fIbits\fP, const char *\fIsuffix\fP,
- char *\fIhashsum\fP);
+
+int libkeccak_fast_digest(libkeccak_state_t *\fIstate\fP, const void *\fImsg\fP, size_t \fImsglen\fP,
+ size_t \fIbits\fP, const char *\fIsuffix\fP, void *\fIhashsum\fP);
.fi
.P
Link with
@@ -54,7 +52,7 @@ message. If this string is empty,
may be used instead. This is used to select hash algorithm.
For pure Keccak,
.I NULL
-or "" is used. For the other algorithms the constants
+or \(dq\(dq is used. For the other algorithms the constants
.B LIBKECCAK_SHA3_SUFFIX
(for SHA-3),
.B LIBKECCAK_RAWSHAKE_SUFFIX
@@ -98,7 +96,7 @@ function may fail for any reason specified by the function
This example calculates the Keccak[b = 1024, c = 576, n = 256]
hash of the input from stdin, and prints the hash, in hexadecimal
form, to stdout.
-.LP
+.PP
.nf
libkeccak_state_t state;
libkeccak_spec_t spec;
@@ -111,26 +109,26 @@ spec.bitrate = 1024;
spec.capacity = 576;
spec.output = 256;
if (libkeccak_state_initialise(&state, &spec) < 0)
- goto fail;
+ goto fail;
for (;;) {
- len = read(STDIN_FILENO, chunk, sizeof(chunk));
+ len = read(STDIN_FILENO, chunk, sizeof(chunk));
- if ((len < 0) && (errno == EINTR))
- continue;
- if (len < 0)
- goto fail;
- if (len == 0)
- break;
+ if ((len < 0) && (errno == EINTR))
+ continue;
+ if (len < 0)
+ goto fail;
+ if (len == 0)
+ break;
- if (libkeccak_fast_update(&state, chunk, (size_t)len) < 0)
- goto fail;
+ if (libkeccak_fast_update(&state, chunk, (size_t)len) < 0)
+ goto fail;
}
-if (libkeccak_fast_digest(&state, NULL, 0, 0, "", binhash) < 0)
- goto fail;
+if (libkeccak_fast_digest(&state, NULL, 0, 0, \(dq\(dq, binhash) < 0)
+ goto fail;
libkeccak_behex_lower(hexhash, binhash, sizeof(binhash));
-printf("%s\\n", hexhash);
+printf(\(dq%s\en\(dq, hexhash);
libkeccak_state_fast_destroy(&state);
.fi
.SH SEE ALSO
@@ -141,6 +139,3 @@ libkeccak_state_fast_destroy(&state);
.BR libkeccak_simple_squeeze (3),
.BR libkeccak_fast_squeeze (3),
.BR libkeccak_squeeze (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_fast_squeeze.3 b/man3/libkeccak_fast_squeeze.3
index d782a95..393e264 100644
--- a/man3/libkeccak_fast_squeeze.3
+++ b/man3/libkeccak_fast_squeeze.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_fast_squeeze - Runs the squeeze phase a number of times
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_fast_squeeze(libkeccak_state_t *\fIstate\fP, long int \fItimes\fP);
+
+void libkeccak_fast_squeeze(libkeccak_state_t *\fIstate\fP, long int \fItimes\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -34,6 +32,3 @@ function cannot fail.
.BR libkeccak_fast_digest (3),
.BR libkeccak_simple_squeeze (3),
.BR libkeccak_squeeze (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_fast_update.3 b/man3/libkeccak_fast_update.3
index c619e7d..3398984 100644
--- a/man3/libkeccak_fast_update.3
+++ b/man3/libkeccak_fast_update.3
@@ -2,15 +2,12 @@
.SH NAME
libkeccak_fast_update - Partially hash a message without erasure
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_fast_update(libkeccak_state_t *\fIstate\fP, const char *\fImsg\fP,
- size_t \fImsglen\fP);
+
+int libkeccak_fast_update(libkeccak_state_t *\fIstate\fP, const void *\fImsg\fP, size_t \fImsglen\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -51,7 +48,7 @@ or 0.
This example calculates the Keccak[b = 1024, c = 576, n = 256]
hash of the input from stdin, and prints the hash, in hexadecimal
form, to stdout.
-.LP
+.PP
.nf
libkeccak_state_t state;
libkeccak_spec_t spec;
@@ -64,26 +61,26 @@ spec.bitrate = 1024;
spec.capacity = 576;
spec.output = 256;
if (libkeccak_state_initialise(&state, &spec) < 0)
- goto fail;
+ goto fail;
for (;;) {
- len = read(STDIN_FILENO, chunk, sizeof(chunk));
+ len = read(STDIN_FILENO, chunk, sizeof(chunk));
- if ((len < 0) && (errno == EINTR))
- continue;
- if (len < 0)
- goto fail;
- if (len == 0)
- break;
+ if ((len < 0) && (errno == EINTR))
+ continue;
+ if (len < 0)
+ goto fail;
+ if (len == 0)
+ break;
- if (libkeccak_fast_update(&state, chunk, (size_t)len) < 0)
- goto fail;
+ if (libkeccak_fast_update(&state, chunk, (size_t)len) < 0)
+ goto fail;
}
-if (libkeccak_fast_digest(&state, NULL, 0, 0, "", binhash) < 0)
- goto fail;
+if (libkeccak_fast_digest(&state, NULL, 0, 0, \(dq\(dq, binhash) < 0)
+ goto fail;
libkeccak_behex_lower(hexhash, binhash, sizeof(binhash));
-printf("%s\\n", hexhash);
+printf(\(dq%s\en\(dq, hexhash);
libkeccak_state_fast_destroy(&state);
.fi
.SH SEE ALSO
@@ -91,6 +88,3 @@ libkeccak_state_fast_destroy(&state);
.BR libkeccak_update (3),
.BR libkeccak_fast_digest (3),
.BR libkeccak_digest (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_generalised_spec_initialise.3 b/man3/libkeccak_generalised_spec_initialise.3
index 42bd62f..1a3bccb 100644
--- a/man3/libkeccak_generalised_spec_initialise.3
+++ b/man3/libkeccak_generalised_spec_initialise.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_generalised_spec_initialise - Set all specification parameters to automatic
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_generalised_spec_initialise(libkeccak_generalised_spec_t *\fIspec\fP);
+
+void libkeccak_generalised_spec_initialise(libkeccak_generalised_spec_t *\fIspec\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -41,6 +39,3 @@ function cannot fail.
.BR libkeccak_spec_sha3 (3),
.BR libkeccak_spec_rawshake (3),
.BR libkeccak_spec_shake (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_generalised_sum_fd.3 b/man3/libkeccak_generalised_sum_fd.3
index 98e6329..bae5bae 100644
--- a/man3/libkeccak_generalised_sum_fd.3
+++ b/man3/libkeccak_generalised_sum_fd.3
@@ -2,16 +2,13 @@
.SH NAME
libkeccak_generalised_sum_fd - Calculate the hash of a file
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_generalised_sum_fd(int \fIfd\fP, libkeccak_state_t *\fIstate\fP,
- const libkeccak_spec_t *\fIspec\fP,
- const char *\fIsuffix\fP, char *\fIhashsum\fP);
+
+int libkeccak_generalised_sum_fd(int \fIfd\fP, libkeccak_state_t *\fIstate\fP, const libkeccak_spec_t *\fIspec\fP,
+ const char *\fIsuffix\fP, void *\fIhashsum\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -97,7 +94,7 @@ does not validate the tuning of the algorithm.
This example calculates the Keccak[b = 1024, c = 576, n = 256]
hash of the input from stdin, and prints the hash, in hexadecimal
form, to stdout.
-.LP
+.PP
.nf
libkeccak_state_t state;
libkeccak_spec_t spec;
@@ -109,9 +106,9 @@ spec.capacity = 576;
spec.output = 256;
if (libkeccak_generalised_sum_fd(STDIN_FILENO, &state, &spec, NULL, binhash) < 0)
- goto fail;
+ goto fail;
libkeccak_behex_lower(hexhash, binhash, sizeof(binhash));
-printf("%s\\n", hexhash);
+printf(\(dq%s\en\(dq, hexhash);
libkeccak_state_destroy(&state);
.fi
.SH SEE ALSO
@@ -127,6 +124,3 @@ libkeccak_state_destroy(&state);
.BR libkeccak_spec_check (3),
.BR libkeccak_generalised_spec_initialise (3),
.BR libkeccak_state_initialise (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_hmac_copy.3 b/man3/libkeccak_hmac_copy.3
index f3939f5..0f29ae8 100644
--- a/man3/libkeccak_hmac_copy.3
+++ b/man3/libkeccak_hmac_copy.3
@@ -2,15 +2,12 @@
.SH NAME
libkeccak_hmac_copy - Copies an HMAC-hashing state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_hmac_copy(libkeccak_hmac_state_t *\fIdest\fP,
- const libkeccak_hmac_state_t *\fIsrc\fP);
+
+int libkeccak_hmac_copy(libkeccak_hmac_state_t *\fIdest\fP, const libkeccak_hmac_state_t *\fIsrc\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -39,6 +36,3 @@ function may fail for any specified for the function
.SH SEE ALSO
.BR libkeccak_hmac_duplicate (3),
.BR libkeccak_hmac_initialise (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_hmac_create.3 b/man3/libkeccak_hmac_create.3
index fcb99cb..91bb8a1 100644
--- a/man3/libkeccak_hmac_create.3
+++ b/man3/libkeccak_hmac_create.3
@@ -2,15 +2,12 @@
.SH NAME
libkeccak_hmac_create - Allocate and initialise HMAC-hashing state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-libkeccak_hmac_state_t *
-libkeccak_hmac_create(const libkeccak_spec_t *\fIspec\fP, const char *\fIkey\fP,
- size_t \fIkey_length\fP);
+
+libkeccak_hmac_state_t *libkeccak_hmac_create(const libkeccak_spec_t *\fIspec\fP, const void *\fIkey\fP, size_t \fIkey_length\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -48,6 +45,3 @@ and
.BR libkeccak_hmac_free (3),
.BR libkeccak_hmac_fast_free (3),
.BR libkeccak_hmac_duplicate (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_hmac_destroy.3 b/man3/libkeccak_hmac_destroy.3
index 2f3bbf8..0038eca 100644
--- a/man3/libkeccak_hmac_destroy.3
+++ b/man3/libkeccak_hmac_destroy.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_hmac_destroy - Destroys an HMAC-hashing state with erasure
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_hmac_destroy(libkeccak_hmac_state_t *\fIstate\fP);
+
+void libkeccak_hmac_destroy(libkeccak_hmac_state_t *\fIstate\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -38,6 +36,3 @@ function cannot fail.
.BR libkeccak_hmac_initialise (3),
.BR libkeccak_hmac_reset (3),
.BR libkeccak_hmac_wipe (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_hmac_digest.3 b/man3/libkeccak_hmac_digest.3
index 66d35d4..99e460a 100644
--- a/man3/libkeccak_hmac_digest.3
+++ b/man3/libkeccak_hmac_digest.3
@@ -2,16 +2,13 @@
.SH NAME
libkeccak_hmac_digest - Complete the HMAC-hashing of a message with erasure
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_hmac_digest(libkeccak_hmac_state_t *\fIstate\fP, const char *\fImsg\fP,
- size_t \fImsglen\fP, size_t \fIbits\fP, const char *\fIsuffix\fP,
- char *\fIhashsum\fP);
+
+int libkeccak_hmac_digest(libkeccak_hmac_state_t *\fIstate\fP, const void *\fImsg\fP, size_t \fImsglen\fP,
+ size_t \fIbits\fP, const char *\fIsuffix\fP, void *\fIhashsum\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -54,7 +51,7 @@ to the message. If this string is empty,
may be used instead. This is used to select hash algorithm.
For pure Keccak,
.I NULL
-or "" is used. For the other algorithms the constants
+or \(dq\(dq is used. For the other algorithms the constants
.B LIBKECCAK_SHA3_SUFFIX
(for SHA-3),
.B LIBKECCAK_RAWSHAKE_SUFFIX
@@ -98,6 +95,3 @@ function may fail for any reason specified by the function
.BR libkeccak_hmac_initialise (3),
.BR libkeccak_hmac_update (3),
.BR libkeccak_hmac_fast_digest (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_hmac_duplicate.3 b/man3/libkeccak_hmac_duplicate.3
index 70c994c..bb16139 100644
--- a/man3/libkeccak_hmac_duplicate.3
+++ b/man3/libkeccak_hmac_duplicate.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_hmac_duplicate - Allocate a duplicate an HMAC-hashing state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-libkeccak_hmac_state_t *
-libkeccak_hmac_duplicate(const libkeccak_hmac_state_t *\fIsrc\fP);
+
+libkeccak_hmac_state_t *libkeccak_hmac_duplicate(const libkeccak_hmac_state_t *\fIsrc\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -41,6 +39,3 @@ function may fail for any specified for the function
.SH SEE ALSO
.BR libkeccak_hmac_copy (3),
.BR libkeccak_hmac_create (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_hmac_fast_destroy.3 b/man3/libkeccak_hmac_fast_destroy.3
index d2af66e..31bf894 100644
--- a/man3/libkeccak_hmac_fast_destroy.3
+++ b/man3/libkeccak_hmac_fast_destroy.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_hmac_fast_destroy - Destroys an HMAC-hashing state without erasure
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_hamc_fast_destroy(libkeccak_hmac_state_t *\fIstate\fP);
+
+void libkeccak_hamc_fast_destroy(libkeccak_hmac_state_t *\fIstate\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -38,6 +36,3 @@ function cannot fail.
.BR libkeccak_hmac_initialise (3),
.BR libkeccak_hmac_reset (3),
.BR libkeccak_hmac_wipe (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_hmac_fast_digest.3 b/man3/libkeccak_hmac_fast_digest.3
index 008477c..68fcc69 100644
--- a/man3/libkeccak_hmac_fast_digest.3
+++ b/man3/libkeccak_hmac_fast_digest.3
@@ -2,16 +2,13 @@
.SH NAME
libkeccak_hmac_fast_digest - Complete the HMAC-hashing of a message without erasure
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_hmac_fast_digest(libkeccak_hmac_state_t *\fIstate\fP,
- const char *\fImsg\fP, size_t \fImsglen\fP, size_t \fIbits\fP,
- const char *\fIsuffix\fP, char *\fIhashsum\fP);
+
+int libkeccak_hmac_fast_digest(libkeccak_hmac_state_t *\fIstate\fP, const void *\fImsg\fP, size_t \fImsglen\fP,
+ size_t \fIbits\fP, const char *\fIsuffix\fP, void *\fIhashsum\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -54,7 +51,7 @@ to the message. If this string is empty,
may be used instead. This is used to select hash algorithm.
For pure Keccak,
.I NULL
-or "" is used. For the other algorithms the constants
+or \(dq\(dq is used. For the other algorithms the constants
.B LIBKECCAK_SHA3_SUFFIX
(for SHA-3),
.B LIBKECCAK_RAWSHAKE_SUFFIX
@@ -99,6 +96,3 @@ function may fail for any reason specified by the function
.BR libkeccak_hmac_initialise (3),
.BR libkeccak_hmac_fast_update (3),
.BR libkeccak_hmac_fast_digest (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_hmac_fast_free.3 b/man3/libkeccak_hmac_fast_free.3
index b4817ce..f888872 100644
--- a/man3/libkeccak_hmac_fast_free.3
+++ b/man3/libkeccak_hmac_fast_free.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_hmac_fast_free - Destroys and deallocates an HMAC-hashing state without erasure
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_hmac_fast_free(libkeccak_hmac_state_t *\fIstate\fP);
+
+void libkeccak_hmac_fast_free(libkeccak_hmac_state_t *\fIstate\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -46,6 +44,3 @@ to be freed, resulting in undefined behaviour.
.BR libkeccak_hmac_initialise (3),
.BR libkeccak_hmac_reset (3),
.BR libkeccak_hmac_wipe (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_hmac_fast_update.3 b/man3/libkeccak_hmac_fast_update.3
index 43077d3..a41b72f 100644
--- a/man3/libkeccak_hmac_fast_update.3
+++ b/man3/libkeccak_hmac_fast_update.3
@@ -2,15 +2,12 @@
.SH NAME
libkeccak_hmac_fast_update - Partially HMAC-hash a message without erasure
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_hmac_fast_update(libkeccak_state_t *\fIstate\fP, const char *\fImsg\fP,
- size_t \fImsglen\fP);
+
+int libkeccak_hmac_fast_update(libkeccak_state_t *\fIstate\fP, const void *\fImsg\fP, size_t \fImsglen\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -54,6 +51,3 @@ or 0.
.BR libkeccak_hmac_initialise (3),
.BR libkeccak_hmac_fast_digest (3),
.BR libkeccak_hmac_update (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_hmac_free.3 b/man3/libkeccak_hmac_free.3
index d1f9c84..c70f369 100644
--- a/man3/libkeccak_hmac_free.3
+++ b/man3/libkeccak_hmac_free.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_hmac_free - Destroys and deallocates an HMAC-hashing state with erasure
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_hmac_free(libkeccak_hmac_state_t *\fIstate\fP);
+
+void libkeccak_hmac_free(libkeccak_hmac_state_t *\fIstate\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -46,6 +44,3 @@ to be freed, resulting in undefined behaviour.
.BR libkeccak_hmac_initialise (3),
.BR libkeccak_hmac_reset (3),
.BR libkeccak_hmac_wipe (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_hmac_initialise.3 b/man3/libkeccak_hmac_initialise.3
index de514e9..17b2b9f 100644
--- a/man3/libkeccak_hmac_initialise.3
+++ b/man3/libkeccak_hmac_initialise.3
@@ -2,16 +2,13 @@
.SH NAME
libkeccak_hmac_initialise - Initialise HMAC-hashing state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_hmac_initialise(libkeccak_hmac_state_t *\fIstate\fP,
- const libkeccak_spec_t *\fIspec\fP,
- const char *\fIkey\fP, size_t \fIkey_length\fP);
+
+int libkeccak_hmac_initialise(libkeccak_hmac_state_t *\fIstate\fP, const libkeccak_spec_t *\fIspec\fP,
+ const void *\fIkey\fP, size_t \fIkey_length\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -52,6 +49,3 @@ and
.BR libkeccak_spec_check (3),
.BR libkeccak_generalised_spec_initialise (3),
.BR libkeccak_state_initialise (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_hmac_marshal.3 b/man3/libkeccak_hmac_marshal.3
index b7270f6..2e31dd7 100644
--- a/man3/libkeccak_hmac_marshal.3
+++ b/man3/libkeccak_hmac_marshal.3
@@ -2,15 +2,12 @@
.SH NAME
libkeccak_hmac_marshal - Marshals an HMAC-hashing state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-size_t
-libkeccak_hmac_marshal(const libkeccak_hmac_state_t *\fIstate\fP,
- char *\fIdata\fP);
+
+size_t libkeccak_hmac_marshal(const libkeccak_hmac_state_t *\fIstate\fP, void *\fIdata\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -39,6 +36,3 @@ function cannot fail.
.BR libkeccak_hmac_marshal_size (3),
.BR libkeccak_hmac_unmarshal (3),
.BR libkeccak_hmac_unmarshal_skip (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_hmac_marshal_size.3 b/man3/libkeccak_hmac_marshal_size.3
index 5195b81..fe8ec2f 100644
--- a/man3/libkeccak_hmac_marshal_size.3
+++ b/man3/libkeccak_hmac_marshal_size.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_hmac_marshal_size - Calculates the marshal-size of an HMAC-hashing state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-size_t
-libkeccak_hmac_marshal_size(const libkeccak_hmac_state_t *\fIstate\fP);
+
+size_t libkeccak_hmac_marshal_size(const libkeccak_hmac_state_t *\fIstate\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -31,6 +29,3 @@ function cannot fail.
.BR libkeccak_hmac_marshal (3),
.BR libkeccak_hmac_unmarshal (3),
.BR libkeccak_hmac_unmarshal_skip (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_hmac_reset.3 b/man3/libkeccak_hmac_reset.3
index d5634d9..4a9aadf 100644
--- a/man3/libkeccak_hmac_reset.3
+++ b/man3/libkeccak_hmac_reset.3
@@ -2,15 +2,12 @@
.SH NAME
libkeccak_hmac_reset - Reinitialise a HMAC-hashing state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_hmac_reset(libkeccak_hmac_state_t *\fIstate\fP, const char *\fIkey\fP,
- size_t \fIkey_length\fP);
+
+int libkeccak_hmac_reset(libkeccak_hmac_state_t *\fIstate\fP, const void *\fIkey\fP, size_t \fIkey_length\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -46,6 +43,3 @@ and
.BR libkeccak_hmac_free (3),
.BR libkeccak_hmac_fast_destroy (3),
.BR libkeccak_hmac_destroy (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_hmac_set_key.3 b/man3/libkeccak_hmac_set_key.3
index 2f4682d..ea8084e 100644
--- a/man3/libkeccak_hmac_set_key.3
+++ b/man3/libkeccak_hmac_set_key.3
@@ -2,15 +2,12 @@
.SH NAME
libkeccak_hmac_set_key - Changes key for a the HMAC-hashing state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_hmac_set_key(libkeccak_hmac_state_t *\fIstate\fP, const char *\fIkey\fP,
- size_t \fIkey_length\fP);
+
+int libkeccak_hmac_set_key(libkeccak_hmac_state_t *\fIstate\fP, const void *\fIkey\fP, size_t \fIkey_length\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -36,6 +33,3 @@ function may fail for any specified for the function
.BR libkeccak_hmac_create (3),
.BR libkeccak_hmac_initialise (3),
.BR libkeccak_hmac_reset (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_hmac_unmarshal.3 b/man3/libkeccak_hmac_unmarshal.3
index 64e8f24..c3ed187 100644
--- a/man3/libkeccak_hmac_unmarshal.3
+++ b/man3/libkeccak_hmac_unmarshal.3
@@ -2,15 +2,12 @@
.SH NAME
libkeccak_hmac_unmarshal - Unharshals an HMAC-hashing state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-size_t
-libkeccak_hmac_unmarshal(libkeccak_hmac_state_t *\fIstate\fP,
- const char *\fIdata\fP);
+
+size_t libkeccak_hmac_unmarshal(libkeccak_hmac_state_t *\fIstate\fP, const void *\fIdata\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -24,7 +21,7 @@ and stores it in
The
.BR libkeccak_hmac_unmarshal ()
returns the number of bytes reads from
-.IR data x.
+.IR data .
.SH ERRORS
The
.BR libkeccak_hmac_unmarshal ()
@@ -34,6 +31,3 @@ function may fail for any specified for the function
.BR libkeccak_hmac_marshal_size (3),
.BR libkeccak_hmac_marshal (3),
.BR libkeccak_hmac_unmarshal_skip (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_hmac_unmarshal_skip.3 b/man3/libkeccak_hmac_unmarshal_skip.3
index 30e7ccf..25db1ba 100644
--- a/man3/libkeccak_hmac_unmarshal_skip.3
+++ b/man3/libkeccak_hmac_unmarshal_skip.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_hmac_unmarshal_skip - Calculates the marshal-size of a marshalled HMAC-hashing state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-size_t
-libkeccak_hmac_unmarshal_skip(const char *\fIdata\fP);
+
+size_t libkeccak_hmac_unmarshal_skip(const void *\fIdata\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -35,6 +33,3 @@ function cannot fail.
.BR libkeccak_hmac_marshal_size (3),
.BR libkeccak_hmac_marshal (3),
.BR libkeccak_hmac_unmarshal (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_hmac_update.3 b/man3/libkeccak_hmac_update.3
index daaf3fb..13891cb 100644
--- a/man3/libkeccak_hmac_update.3
+++ b/man3/libkeccak_hmac_update.3
@@ -2,15 +2,12 @@
.SH NAME
libkeccak_hmac_update - Partially HMAC-hash a message with erasure
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_hmac_update(libkeccak_state_t *\fIstate\fP, const char *\fImsg\fP,
- size_t \fImsglen\fP);
+
+int libkeccak_hmac_update(libkeccak_state_t *\fIstate\fP, const void *\fImsg\fP, size_t \fImsglen\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -51,6 +48,3 @@ or 0.
.BR libkeccak_hmac_initialise (3),
.BR libkeccak_hmac_digest (3),
.BR libkeccak_hmac_fast_update (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_hmac_wipe.3 b/man3/libkeccak_hmac_wipe.3
index bad351b..471a9a8 100644
--- a/man3/libkeccak_hmac_wipe.3
+++ b/man3/libkeccak_hmac_wipe.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_hmac_wipe - Securely erase sensitive data from a HMAC-hashing state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_hmac_wipe(libkeccak_hmac_state_t *\fIstate\fP);
+
+int libkeccak_hmac_wipe(libkeccak_hmac_state_t *\fIstate\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -31,6 +29,3 @@ function cannot fail.
.BR libkeccak_hmac_free (3),
.BR libkeccak_hmac_fast_destroy (3),
.BR libkeccak_hmac_destroy (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_keccaksum_fd.3 b/man3/libkeccak_keccaksum_fd.3
index 2fc1b21..ccd1f8a 100644
--- a/man3/libkeccak_keccaksum_fd.3
+++ b/man3/libkeccak_keccaksum_fd.3
@@ -2,15 +2,12 @@
.SH NAME
libkeccak_keccaksum_fd - Calculate a Keccak hashsum of a file
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_keccaksum_fd(int \fIfd\fP, libkeccak_state_t *\fIstate\fP,
- const libkeccak_spec_t *\fIspec\fP, char *\fIhashsum\fP);
+
+int libkeccak_keccaksum_fd(int \fIfd\fP, libkeccak_state_t *\fIstate\fP, const libkeccak_spec_t *\fIspec\fP, void *\fIhashsum\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -99,9 +96,9 @@ spec.capacity = 576;
spec.output = 256;
if (libkeccak_keccaksum_fd(STDIN_FILENO, &state, &spec, binhash) < 0)
- goto fail;
+ goto fail;
libkeccak_behex_lower(hexhash, binhash, sizeof(binhash));
-printf("%s\\n", hexhash);
+printf(\(dq%s\en\(dq, hexhash);
libkeccak_state_destroy(&state);
.fi
.SH SEE ALSO
@@ -114,6 +111,3 @@ libkeccak_state_destroy(&state);
.BR libkeccak_spec_check (3),
.BR libkeccak_generalised_spec_initialise (3),
.BR libkeccak_state_initialise (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_rawshakesum_fd.3 b/man3/libkeccak_rawshakesum_fd.3
index 27c4f45..8fad150 100644
--- a/man3/libkeccak_rawshakesum_fd.3
+++ b/man3/libkeccak_rawshakesum_fd.3
@@ -2,16 +2,12 @@
.SH NAME
libkeccak_rawshakesum_fd - Calculate a RawSHAKE hashsum of a file
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_rawshakesum_fd(int \fIfd\fP, libkeccak_state_t *\fIstate\fP,
- long int \fIsemicapacity\fP, long int \fIoutput\fP,
- char *\fIhashsum\fP);
+
+int libkeccak_rawshakesum_fd(int \fIfd\fP, libkeccak_state_t *\fIstate\fP, long int \fIsemicapacity\fP, long int \fIoutput\fP, void *\fIhashsum\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -94,9 +90,9 @@ from stdin, and prints the hash, in hexadecimal form, to stdout.
.nf
libkeccak_state_t state;
if (libkeccak_rawshakesum_fd(STDIN_FILENO, &state, 256, 512, binhash) < 0)
- goto fail;
+ goto fail;
libkeccak_behex_lower(hexhash, binhash, sizeof(binhash));
-printf("%s\\n", hexhash);
+printf(\(dq%s\en\(dq, hexhash);
libkeccak_state_destroy(&state);
.fi
.SH SEE ALSO
@@ -110,6 +106,3 @@ libkeccak_state_destroy(&state);
.BR libkeccak_spec_check (3),
.BR libkeccak_generalised_spec_initialise (3),
.BR libkeccak_state_initialise (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_sha3sum_fd.3 b/man3/libkeccak_sha3sum_fd.3
index e8c4fc0..0d697e6 100644
--- a/man3/libkeccak_sha3sum_fd.3
+++ b/man3/libkeccak_sha3sum_fd.3
@@ -2,15 +2,12 @@
.SH NAME
libkeccak_sha3sum_fd - Calculate a SHA-3 hashsum of a file
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_sha3sum_fd(int \fIfd\fP, libkeccak_state_t *\fIstate\fP, long int \fIoutput\fP,
- char *\fIhashsum\fP);
+
+int libkeccak_sha3sum_fd(int \fIfd\fP, libkeccak_state_t *\fIstate\fP, long int \fIoutput\fP, void *\fIhashsum\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -90,9 +87,9 @@ from stdin, and prints the hash, in hexadecimal form, to stdout.
.nf
libkeccak_state_t state;
if (libkeccak_sha3sum_fd(STDIN_FILENO, &state, 256, binhash) < 0)
- goto fail;
+ goto fail;
libkeccak_behex_lower(hexhash, binhash, sizeof(binhash));
-printf("%s\\n", hexhash);
+printf(\(dq%s\en\(dq, hexhash);
libkeccak_state_destroy(&state);
.fi
.SH SEE ALSO
@@ -106,6 +103,3 @@ libkeccak_state_destroy(&state);
.BR libkeccak_spec_check (3),
.BR libkeccak_generalised_spec_initialise (3),
.BR libkeccak_state_initialise (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_shakesum_fd.3 b/man3/libkeccak_shakesum_fd.3
index 0d89f39..441c549 100644
--- a/man3/libkeccak_shakesum_fd.3
+++ b/man3/libkeccak_shakesum_fd.3
@@ -2,16 +2,12 @@
.SH NAME
libkeccak_shakesum_fd - Calculate a SHAKE hashsum of a file
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_shakesum_fd(int \fIfd\fP, libkeccak_state_t *\fIstate\fP,
- long int \fIsemicapacity\fP, long int \fIoutput\fP,
- char *\fIhashsum\fP);
+
+int libkeccak_shakesum_fd(int \fIfd\fP, libkeccak_state_t *\fIstate\fP, long int \fIsemicapacity\fP, long int \fIoutput\fP, void *\fIhashsum\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -94,9 +90,9 @@ from stdin, and prints the hash, in hexadecimal form, to stdout.
.nf
libkeccak_state_t state;
if (libkeccak_shakesum_fd(STDIN_FILENO, &state, 256, 512, binhash) < 0)
- goto fail;
+ goto fail;
libkeccak_behex_lower(hexhash, binhash, sizeof(binhash));
-printf("%s\\n", hexhash);
+printf(\(dq%s\en\(dq, hexhash);
libkeccak_state_destroy(&state);
.fi
.SH SEE ALSO
@@ -110,6 +106,3 @@ libkeccak_state_destroy(&state);
.BR libkeccak_spec_check (3),
.BR libkeccak_generalised_spec_initialise (3),
.BR libkeccak_state_initialise (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_simple_squeeze.3 b/man3/libkeccak_simple_squeeze.3
index 52605ed..8626f5a 100644
--- a/man3/libkeccak_simple_squeeze.3
+++ b/man3/libkeccak_simple_squeeze.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_simple_squeeze - Runs Keccak-f a number of times
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_simple_squeeze(libkeccak_state_t *\fIstate\fP, long int \fItimes\fP);
+
+void libkeccak_simple_squeeze(libkeccak_state_t *\fIstate\fP, long int \fItimes\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -33,6 +31,3 @@ function cannot fail.
.BR libkeccak_fast_digest (3),
.BR libkeccak_fast_squeeze (3),
.BR libkeccak_squeeze (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_spec_check.3 b/man3/libkeccak_spec_check.3
index 9fc70f6..7dd19d8 100644
--- a/man3/libkeccak_spec_check.3
+++ b/man3/libkeccak_spec_check.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_spec_check - Validate hashing parameters
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_spec_check(const libkeccak_spec_t *\fIspec\fP);
+
+int libkeccak_spec_check(const libkeccak_spec_t *\fIspec\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -27,9 +25,9 @@ manually for Keccak hashing.
.PP
.nf
typedef struct libkeccak_spec {
- long int bitrate; /* bitrate (in bits) */
- long int capacity; /* capacity (in bits) */
- long int output; /* output size (in bits) */
+ long int bitrate; /* bitrate (in bits) */
+ long int capacity; /* capacity (in bits) */
+ long int output; /* output size (in bits) */
} libkeccak_spec_t;
.fi
.SH RETURN VALUES
@@ -90,6 +88,3 @@ function cannot fail.
.BR libkeccak_generalised_spec_initialise (3),
.BR libkeccak_state_initialise (3),
.BR libkeccak_hmac_initialise (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_spec_rawshake.3 b/man3/libkeccak_spec_rawshake.3
index 6f60c36..f5f16b8 100644
--- a/man3/libkeccak_spec_rawshake.3
+++ b/man3/libkeccak_spec_rawshake.3
@@ -2,15 +2,12 @@
.SH NAME
libkeccak_spec_rawshake - Configure RawSHAKE hashing parameters
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_spec_rawshake(libkeccak_spec_t *\fIspec\fP, long int \fIx\fP,
- long int \fId\fP);
+
+void libkeccak_spec_rawshake(libkeccak_spec_t *\fIspec\fP, long int \fIx\fP, long int \fId\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -36,7 +33,7 @@ function cannot fail.
This example configure a
.B libkeccak_spec_t
to specify the Keccak parameters used for RawSHAKE256(, 512):
-.LP
+.PP
.nf
libkeccak_spec_t spec;
libkeccak_spec_rawshake(&spec, 256, 512);
@@ -48,6 +45,3 @@ libkeccak_spec_rawshake(&spec, 256, 512);
.BR libkeccak_generalised_spec_initialise (3),
.BR libkeccak_state_initialise (3),
.BR libkeccak_hmac_initialise (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_spec_sha3.3 b/man3/libkeccak_spec_sha3.3
index 8e07a7d..1320631 100644
--- a/man3/libkeccak_spec_sha3.3
+++ b/man3/libkeccak_spec_sha3.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_spec_sha3 - Configure SHA-3 hashing parameters
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_spec_sha3(libkeccak_spec_t *\fIspec\fP, long int \fIx\fP);
+
+void libkeccak_spec_sha3(libkeccak_spec_t *\fIspec\fP, long int \fIx\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -34,7 +32,7 @@ function cannot fail.
This example configure a
.B libkeccak_spec_t
to specify the Keccak parameters used for SHA3-256:
-.LP
+.PP
.nf
libkeccak_spec_t spec;
libkeccak_spec_sha3(&spec, 256);
@@ -46,6 +44,3 @@ libkeccak_spec_sha3(&spec, 256);
.BR libkeccak_generalised_spec_initialise (3),
.BR libkeccak_state_initialise (3),
.BR libkeccak_hmac_initialise (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_spec_shake.3 b/man3/libkeccak_spec_shake.3
index 9e2d763..4beea49 100644
--- a/man3/libkeccak_spec_shake.3
+++ b/man3/libkeccak_spec_shake.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_spec_shake - Configure SHAKE hashing parameters
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_spec_shake(libkeccak_spec_t *\fIspec\fP, long int \fIx\fP, long int \fId\fP);
+
+void libkeccak_spec_shake(libkeccak_spec_t *\fIspec\fP, long int \fIx\fP, long int \fId\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -35,7 +33,7 @@ function cannot fail.
This example configure a
.B libkeccak_spec_t
to specify the Keccak parameters used for SHAKE256(, 512):
-.LP
+.PP
.nf
libkeccak_spec_t spec;
libkeccak_spec_shake(&spec, 256, 512);
@@ -47,6 +45,3 @@ libkeccak_spec_shake(&spec, 256, 512);
.BR libkeccak_generalised_spec_initialise (3),
.BR libkeccak_state_initialise (3),
.BR libkeccak_hmac_initialise (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_squeeze.3 b/man3/libkeccak_squeeze.3
index c6c8d01..67430a4 100644
--- a/man3/libkeccak_squeeze.3
+++ b/man3/libkeccak_squeeze.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_squeeze - Runs the squeeze phase
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_squeeze(libkeccak_state_t *\fIstate\fP, char *\fIhashsum\fP);
+
+void libkeccak_squeeze(libkeccak_state_t *\fIstate\fP, void *\fIhashsum\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -43,6 +41,3 @@ function cannot fail.
.BR libkeccak_fast_digest (3),
.BR libkeccak_simple_squeeze (3),
.BR libkeccak_fast_squeeze (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_state_copy.3 b/man3/libkeccak_state_copy.3
index c9283ca..4bd892c 100644
--- a/man3/libkeccak_state_copy.3
+++ b/man3/libkeccak_state_copy.3
@@ -2,15 +2,12 @@
.SH NAME
libkeccak_state_copy - Copies hash state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_state_copy(libkeccak_state_t *\fIdest\fP,
- const libkeccak_state_t *\fIsrc\fP);
+
+int libkeccak_state_copy(libkeccak_state_t *\fIdest\fP, const libkeccak_state_t *\fIsrc\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -39,6 +36,3 @@ function may fail for any specified for the function
.SH SEE ALSO
.BR libkeccak_state_duplicate (3),
.BR libkeccak_state_initialise (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_state_create.3 b/man3/libkeccak_state_create.3
index 77880a3..f27e124 100644
--- a/man3/libkeccak_state_create.3
+++ b/man3/libkeccak_state_create.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_state_create - Allocate and initialise hash state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-libkeccak_state_t *
-libkeccak_state_create(const libkeccak_spec_t *\fIspec\fP);
+
+libkeccak_state_t *libkeccak_state_create(const libkeccak_spec_t *\fIspec\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -41,6 +39,3 @@ function may fail for any specified for the function
.BR libkeccak_state_free (3),
.BR libkeccak_state_fast_free (3)
.BR libkeccak_state_duplicate (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_state_destroy.3 b/man3/libkeccak_state_destroy.3
index 0a78215..2df1f49 100644
--- a/man3/libkeccak_state_destroy.3
+++ b/man3/libkeccak_state_destroy.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_state_destroy - Destroys a hash state with erasure
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_state_destroy(libkeccak_state_t *\fIstate\fP);
+
+void libkeccak_state_destroy(libkeccak_state_t *\fIstate\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -38,6 +36,3 @@ function cannot fail.
.BR libkeccak_state_initialise (3),
.BR libkeccak_state_reset (3),
.BR libkeccak_state_wipe (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_state_duplicate.3 b/man3/libkeccak_state_duplicate.3
index 54c9be3..dfd0612 100644
--- a/man3/libkeccak_state_duplicate.3
+++ b/man3/libkeccak_state_duplicate.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_state_duplicate - Allocate a duplicate hash state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-libkeccak_state_t *
-libkeccak_state_duplicate(const libkeccak_state_t *\fIsrc\fP);
+
+libkeccak_state_t *libkeccak_state_duplicate(const libkeccak_state_t *\fIsrc\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak P.
.SH DESCRIPTION
@@ -41,6 +39,3 @@ function may fail for any specified for the function
.SH SEE ALSO
.BR libkeccak_state_copy (3),
.BR libkeccak_state_create (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_state_fast_destroy.3 b/man3/libkeccak_state_fast_destroy.3
index e04ca86..f346611 100644
--- a/man3/libkeccak_state_fast_destroy.3
+++ b/man3/libkeccak_state_fast_destroy.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_state_fast_destroy - Destroys a hash state without erasure
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_state_fast_destroy(libkeccak_state_t *\fIstate\fP);
+
+void libkeccak_state_fast_destroy(libkeccak_state_t *\fIstate\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -38,6 +36,3 @@ function cannot fail.
.BR libkeccak_state_initialise (3),
.BR libkeccak_state_reset (3),
.BR libkeccak_state_wipe (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_state_fast_free.3 b/man3/libkeccak_state_fast_free.3
index e617e21..01d0ed8 100644
--- a/man3/libkeccak_state_fast_free.3
+++ b/man3/libkeccak_state_fast_free.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_state_fast_free - Destroys and deallocates a hash state without erasure
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_state_fast_free(libkeccak_state_t *\fIstate\fP);
+
+void libkeccak_state_fast_free(libkeccak_state_t *\fIstate\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -46,6 +44,3 @@ to be freed, resulting in undefined behaviour.
.BR libkeccak_state_initialise (3),
.BR libkeccak_state_reset (3),
.BR libkeccak_state_wipe (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_state_free.3 b/man3/libkeccak_state_free.3
index e6dd3f8..8761d54 100644
--- a/man3/libkeccak_state_free.3
+++ b/man3/libkeccak_state_free.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_state_free - Destroys and deallocates a hash state with erasure
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_state_free(libkeccak_state_t *\fIstate\fP);
+
+void libkeccak_state_free(libkeccak_state_t *\fIstate\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -46,6 +44,3 @@ to be freed, resulting in undefined behaviour.
.BR libkeccak_state_initialise (3),
.BR libkeccak_state_reset (3),
.BR libkeccak_state_wipe (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_state_initialise.3 b/man3/libkeccak_state_initialise.3
index 2620686..cef4d3d 100644
--- a/man3/libkeccak_state_initialise.3
+++ b/man3/libkeccak_state_initialise.3
@@ -2,15 +2,12 @@
.SH NAME
libkeccak_state_initialise - Initialise hash state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_state_initialise(libkeccak_state_t *\fIstate\fP,
- const libkeccak_spec_t *\fIspec\fP);
+
+int libkeccak_state_initialise(libkeccak_state_t *\fIstate\fP, const libkeccak_spec_t *\fIspec\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -55,6 +52,3 @@ function may fail for any specified for the function
.BR libkeccak_generalised_spec_initialise (3),
.BR libkeccak_state_marshal_size (3),
.BR libkeccak_hmac_initialise (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_state_marshal.3 b/man3/libkeccak_state_marshal.3
index f5d5e05..ae21d17 100644
--- a/man3/libkeccak_state_marshal.3
+++ b/man3/libkeccak_state_marshal.3
@@ -2,20 +2,20 @@
.SH NAME
libkeccak_state_marshal - Marshals a hash state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-size_t
-libkeccak_state_marshal(const libkeccak_state_t *\fIstate\fP, char *\fIdata\fP);
+
+size_t libkeccak_state_marshal(const libkeccak_state_t *\fIstate\fP, void *\fIdata\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
The
.BR libkeccak_state_marshal ()
-function marshals \fI*state\fP into the beginning of
+function marshals
+.I *state
+into the beginning of
.IR data .
.PP
Use the
@@ -36,6 +36,3 @@ function cannot fail.
.BR libkeccak_state_marshal_size (3),
.BR libkeccak_state_unmarshal (3),
.BR libkeccak_state_unmarshal_skip (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_state_marshal_size.3 b/man3/libkeccak_state_marshal_size.3
index 8ebb16a..9eca42b 100644
--- a/man3/libkeccak_state_marshal_size.3
+++ b/man3/libkeccak_state_marshal_size.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_state_marshal_size - Calculates the marshal-size of a hash state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-size_t
-libkeccak_state_marshal_size(const libkeccak_state_t *\fIstate\fP);
+
+size_t libkeccak_state_marshal_size(const libkeccak_state_t *\fIstate\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -31,6 +29,3 @@ function cannot fail.
.BR libkeccak_state_marshal (3),
.BR libkeccak_state_unmarshal (3),
.BR libkeccak_state_unmarshal_skip (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_state_reset.3 b/man3/libkeccak_state_reset.3
index 60bb778..566bd6b 100644
--- a/man3/libkeccak_state_reset.3
+++ b/man3/libkeccak_state_reset.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_state_reset - Reinitialise hash state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_state_reset(libkeccak_state_t *\fIstate\fP);
+
+void libkeccak_state_reset(libkeccak_state_t *\fIstate\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -32,6 +30,3 @@ function cannot fail.
.BR libkeccak_state_destroy (3),
.BR libkeccak_state_fast_destroy (3),
.BR libkeccak_state_wipe (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_state_unmarshal.3 b/man3/libkeccak_state_unmarshal.3
index 5a9e59b..8643164 100644
--- a/man3/libkeccak_state_unmarshal.3
+++ b/man3/libkeccak_state_unmarshal.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_state_unmarshal - Unharshals a hash state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-size_t
-libkeccak_state_unmarshal(libkeccak_state_t *\fIstate\fP, const char *\fIdata\fP);
+
+size_t libkeccak_state_unmarshal(libkeccak_state_t *\fIstate\fP, const void *\fIdata\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -34,6 +32,3 @@ function may fail for any specified for the function
.BR libkeccak_state_marshal_size (3),
.BR libkeccak_state_marshal (3),
.BR libkeccak_state_unmarshal_skip (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_state_unmarshal_skip.3 b/man3/libkeccak_state_unmarshal_skip.3
index b87386c..9fb9336 100644
--- a/man3/libkeccak_state_unmarshal_skip.3
+++ b/man3/libkeccak_state_unmarshal_skip.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_state_unmarshal_skip - Calculates the marshal-size of a marshalled hash state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-size_t
-libkeccak_state_unmarshal_skip(const char *\fIdata\fP);
+
+size_t libkeccak_state_unmarshal_skip(const void *\fIdata\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -35,6 +33,3 @@ function cannot fail.
.BR libkeccak_state_marshal_size (3),
.BR libkeccak_state_marshal (3),
.BR libkeccak_state_unmarshal (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_state_wipe.3 b/man3/libkeccak_state_wipe.3
index 664cd51..1ae2759 100644
--- a/man3/libkeccak_state_wipe.3
+++ b/man3/libkeccak_state_wipe.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_state_wipe - Securely erase sensitive data
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_state_wipe(libkeccak_state_t *\fIstate\fP);
+
+void libkeccak_state_wipe(libkeccak_state_t *\fIstate\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -32,6 +30,3 @@ function cannot fail.
.BR libkeccak_state_fast_destroy (3),
.BR libkeccak_state_destroy (3),
.BR libkeccak_state_reset (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_state_wipe_message.3 b/man3/libkeccak_state_wipe_message.3
index c734560..7d53afb 100644
--- a/man3/libkeccak_state_wipe_message.3
+++ b/man3/libkeccak_state_wipe_message.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_state_wipe_message - Securely erase the message chunk buffer
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_state_wipe_message(libkeccak_state_t *\fIstate\fP);
+
+void libkeccak_state_wipe_message(libkeccak_state_t *\fIstate\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -30,6 +28,3 @@ function cannot fail.
.BR libkeccak_state_fast_destroy (3),
.BR libkeccak_state_destroy (3),
.BR libkeccak_state_reset (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_state_wipe_sponge.3 b/man3/libkeccak_state_wipe_sponge.3
index 4651fc0..31d6c66 100644
--- a/man3/libkeccak_state_wipe_sponge.3
+++ b/man3/libkeccak_state_wipe_sponge.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_state_wipe_sponge - Securely erase the Keccak sponge state
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_state_wipe_sponge(libkeccak_state_t *\fIstate\fP);
+
+void libkeccak_state_wipe_sponge(libkeccak_state_t *\fIstate\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -30,6 +28,3 @@ function cannot fail.
.BR libkeccak_state_fast_destroy (3),
.BR libkeccak_state_destroy (3),
.BR libkeccak_state_reset (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_unhex.3 b/man3/libkeccak_unhex.3
index 93cde63..c7dc9bc 100644
--- a/man3/libkeccak_unhex.3
+++ b/man3/libkeccak_unhex.3
@@ -2,14 +2,12 @@
.SH NAME
libkeccak_unhex - Converts a hexadecimal hashsum to binary
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-void
-libkeccak_unhex(char *restrict \fIoutput\fP, const char *restrict \fIhashsum\fP);
+
+void libkeccak_unhex(void *restrict \fIoutput\fP, const char *restrict \fIhashsum\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -48,6 +46,3 @@ must have an even number of digits
.SH SEE ALSO
.BR libkeccak_behex_lower (3),
.BR libkeccak_behex_upper (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se
diff --git a/man3/libkeccak_update.3 b/man3/libkeccak_update.3
index d83f74b..4e9f584 100644
--- a/man3/libkeccak_update.3
+++ b/man3/libkeccak_update.3
@@ -2,15 +2,12 @@
.SH NAME
libkeccak_update - Partially hash a message with erasure
.SH SYNOPSIS
-.LP
.nf
#include <libkeccak.h>
-.P
-int
-libkeccak_update(libkeccak_state_t *\fIstate\fP, const char *\fImsg\fP,
- size_t \fImsglen\fP);
+
+int libkeccak_update(libkeccak_state_t *\fIstate\fP, const void *\fImsg\fP, size_t \fImsglen\fP);
.fi
-.P
+.PP
Link with
.IR -lkeccak .
.SH DESCRIPTION
@@ -50,7 +47,7 @@ or 0.
This example calculates the Keccak[b = 1024, c = 576, n = 256]
hash of the input from stdin, and prints the hash, in hexadecimal
form, to stdout.
-.LP
+.PP
.nf
libkeccak_state_t state;
libkeccak_spec_t spec;
@@ -63,26 +60,26 @@ spec.bitrate = 1024;
spec.capacity = 576;
spec.output = 256;
if (libkeccak_state_initialise(&state, &spec) < 0)
- goto fail;
+ goto fail;
for (;;) {
- len = read(STDIN_FILENO, chunk, sizeof(chunk));
+ len = read(STDIN_FILENO, chunk, sizeof(chunk));
- if ((len < 0) && (errno == EINTR))
- continue;
- if (len < 0)
- goto fail;
- if (len == 0)
- break;
+ if ((len < 0) && (errno == EINTR))
+ continue;
+ if (len < 0)
+ goto fail;
+ if (len == 0)
+ break;
- if (libkeccak_update(&state, chunk, (size_t)len) < 0)
- goto fail;
+ if (libkeccak_update(&state, chunk, (size_t)len) < 0)
+ goto fail;
}
-if (libkeccak_digest(&state, NULL, 0, 0, "", binhash) < 0)
- goto fail;
+if (libkeccak_digest(&state, NULL, 0, 0, \(dq\(dq, binhash) < 0)
+ goto fail;
libkeccak_behex_lower(hexhash, binhash, sizeof(binhash));
-printf("%s\\n", hexhash);
+printf(\(dq%s\en\(dq, hexhash);
libkeccak_state_destroy(&state);
.fi
.SH SEE ALSO
@@ -90,6 +87,3 @@ libkeccak_state_destroy(&state);
.BR libkeccak_fast_update (3),
.BR libkeccak_fast_digest (3),
.BR libkeccak_digest (3)
-.SH BUGS
-Please report bugs to https://github.com/maandree/libkeccak/issues or to
-maandree@kth.se