diff options
author | Mattias Andrée <maandree@kth.se> | 2024-09-15 02:15:08 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-09-15 02:15:08 +0200 |
commit | d4ce8327ff902b5ecd42d057063c03793e6d91c2 (patch) | |
tree | 7ec1db1573f12225d6f6c324865b1b49a5a9580d /libkeccak_hmac_set_key.c | |
parent | m (diff) | |
download | libkeccak-d4ce8327ff902b5ecd42d057063c03793e6d91c2.tar.gz libkeccak-d4ce8327ff902b5ecd42d057063c03793e6d91c2.tar.bz2 libkeccak-d4ce8327ff902b5ecd42d057063c03793e6d91c2.tar.xz |
Organise files
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libkeccak_hmac_set_key.c')
-rw-r--r-- | libkeccak_hmac_set_key.c | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/libkeccak_hmac_set_key.c b/libkeccak_hmac_set_key.c deleted file mode 100644 index 2795e4f..0000000 --- a/libkeccak_hmac_set_key.c +++ /dev/null @@ -1,47 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#include "common.h" - - -/** - * 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 - */ -int -libkeccak_hmac_set_key(struct libkeccak_hmac_state *restrict state, const void *restrict key, size_t key_length) -{ - size_t i, size, new_key_length, key_bytes; - void *new; - - size = (size_t)(state->sponge.r) > key_length ? (size_t)(state->sponge.r) : key_length; - new_key_length = size; - size = (size + 7) >> 3; - key_bytes = (key_length + 7) >> 3; - - if (size != key_bytes) { - new = realloc(state->key_opad, 2 * size); - if (!new) - return -1; - state->key_opad = new; - state->key_ipad = state->key_opad + size; - } - - memcpy(state->key_opad, key, key_bytes); - if (key_length & 7) - state->key_opad[(key_bytes >> 3) - 1] &= (unsigned char)((1 << (key_length & 7)) - 1); - - if ((size_t)(state->sponge.r) > key_length) - __builtin_memset(state->key_opad + key_bytes, 0, size - key_bytes); - - for (i = 0; i < size; i++) { - state->key_ipad[i] = state->key_opad[i] ^ HMAC_INNER_PAD; - state->key_opad[i] ^= HMAC_OUTER_PAD; - } - - state->key_length = new_key_length; - - return 0; -} |