aboutsummaryrefslogtreecommitdiffstats
path: root/libkeccak_state_initialise.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2019-02-11 16:22:00 +0100
committerMattias Andrée <maandree@kth.se>2019-02-11 16:22:00 +0100
commit5ff4c5af715d098852d124de116d354ee10f4ea4 (patch)
tree5789ad5798f2dbf21d9406a2942e48b222f773ae /libkeccak_state_initialise.c
parentRemove old file (diff)
downloadlibkeccak-5ff4c5af715d098852d124de116d354ee10f4ea4.tar.gz
libkeccak-5ff4c5af715d098852d124de116d354ee10f4ea4.tar.bz2
libkeccak-5ff4c5af715d098852d124de116d354ee10f4ea4.tar.xz
Split most .c files into one per function and flatten file hierarchy
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libkeccak_state_initialise.c')
-rw-r--r--libkeccak_state_initialise.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/libkeccak_state_initialise.c b/libkeccak_state_initialise.c
new file mode 100644
index 0000000..2559f47
--- /dev/null
+++ b/libkeccak_state_initialise.c
@@ -0,0 +1,33 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+/**
+ * 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
+ */
+int
+libkeccak_state_initialise(libkeccak_state_t *restrict state, const libkeccak_spec_t *restrict spec)
+{
+ long int x;
+ state->r = spec->bitrate;
+ state->n = spec->output;
+ state->c = spec->capacity;
+ state->b = state->r + state->c;
+ state->w = x = state->b / 25;
+ state->l = 0;
+ if (x & 0xF0L) state->l |= 4, x >>= 4;
+ if (x & 0x0CL) state->l |= 2, x >>= 2;
+ if (x & 0x02L) state->l |= 1;
+ state->nr = 12 + (state->l << 1);
+ state->wmod = (state->w == 64) ? ~0LL : (int64_t)((1ULL << state->w) - 1);
+ for (x = 0; x < 25; x++)
+ state->S[x] = 0;
+ state->mptr = 0;
+ state->mlen = (size_t)(state->r * state->b) >> 2;
+ state->M = malloc(state->mlen * sizeof(char));
+ return state->M == NULL ? -1 : 0;
+}