From 32a5ae4e65844615cb3e32aaefcdb7abe4af54c9 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 10 Feb 2019 17:10:20 +0100 Subject: Add HMAC and use void * instead of char * for binary data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- hmac_update.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 hmac_update.c (limited to 'hmac_update.c') diff --git a/hmac_update.c b/hmac_update.c new file mode 100644 index 0000000..7f4cef3 --- /dev/null +++ b/hmac_update.c @@ -0,0 +1,26 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +/** + * Feed data into the HMAC algorithm + * + * @param state The state of the algorithm + * @param data Data to feed into the algorithm + * @param n The number of bytes to feed into the + * algorithm, this must be a multiple of 8 + * @return Zero on success, -1 on error + */ +int +libsha2_hmac_update(struct libsha2_hmac_state *restrict state, const void *restrict data, size_t n) +{ + if (!state->inited) { + if (libsha2_init(&state->sha2_state, state->sha2_state.algorithm)) + return -1; + libsha2_update(&state->sha2_state, state->ipad, state->sha2_state.chunk_size * 8); + state->inited = 1; + } + + libsha2_update(&state->sha2_state, data, n); + return 0; +} -- cgit v1.2.3-70-g09d2