aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-11-04 15:01:50 +0100
committerMattias Andrée <maandree@operamail.com>2014-11-04 15:01:50 +0100
commit5f5d92169b1b02d3c4283f4992dcd3ec952102ec (patch)
treeb4072bd6c6fee3c750c6da984854316d073a6937
parentspecs for sha3, rawshake and shake (diff)
downloadlibkeccak-5f5d92169b1b02d3c4283f4992dcd3ec952102ec.tar.gz
libkeccak-5f5d92169b1b02d3c4283f4992dcd3ec952102ec.tar.bz2
libkeccak-5f5d92169b1b02d3c4283f4992dcd3ec952102ec.tar.xz
error checking for libkeccak_spec_t
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--src/libkeccak/spec.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/libkeccak/spec.h b/src/libkeccak/spec.h
index 0d1dd98..be82043 100644
--- a/src/libkeccak/spec.h
+++ b/src/libkeccak/spec.h
@@ -36,6 +36,38 @@
#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
+
+/**
+ * Invalue `libkeccak_spec_t` values: `.bitrate + `.capacity`
+ * is greater 1600 which is the largest supported state size
+ */
+#define LIBKECCAK_SPEC_ERROR_STATE_TOO_LARGE 6
+
+
/**
* Datastructure that describes the parameters
@@ -103,5 +135,25 @@ void libkeccak_spec_rawshake(libkeccak_spec_t* restrict spec, long x, long d)
#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
+ */
+static inline __attribute__((leaf, nonnull, nothrow, unused, warn_unused_result, pure))
+int libkeccak_spec_check(libkeccak_spec_t* restrict spec)
+{
+ 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 (spec->capacity + spec->bitrate > 1600)
+ return LIBKECCAK_SPEC_ERROR_STATE_TOO_LARGE;
+ return 0;
+}
+
+
#undef