diff options
author | Mattias Andrée <maandree@kth.se> | 2019-02-10 20:21:19 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2019-02-10 20:21:19 +0100 |
commit | ed0296b9055713df0d910e4e7528ffe6fc539514 (patch) | |
tree | 8cbf8ecc9b6352257d6bc4946ff75cb8a4b484c0 /init.c | |
download | libsha1-ed0296b9055713df0d910e4e7528ffe6fc539514.tar.gz libsha1-ed0296b9055713df0d910e4e7528ffe6fc539514.tar.bz2 libsha1-ed0296b9055713df0d910e4e7528ffe6fc539514.tar.xz |
First commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'init.c')
-rw-r--r-- | init.c | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -0,0 +1,46 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +/** + * Initial state for SHA-0 + */ +static const uint32_t H_0[] = { + 0, 0, 0, 0, 0 +}; + +/** + * Initial state for SHA_1 + */ +static const uint32_t H_1[] = { + 0x67452301UL, 0xEFCDAB89UL, 0x98BADCFEUL, 0x10325476UL, 0xC3D2E1F0UL +}; + + +/** + * Initialise a state + * + * @param state The state that should be initialised + * @param algorithm The hashing algorithm + * @return Zero on success, -1 on error + */ +int +libsha1_init(struct libsha1_state *restrict state, enum libsha1_algorithm algorithm) +{ + memset(state, 0, sizeof(*state)); + state->message_size = 0; + state->algorithm = algorithm; + + /* Set initial hash values. */ + switch (algorithm) { + case LIBSHA1_0: memcpy(state->h, H_0, sizeof(H_0)); break; + case LIBSHA1_1: memcpy(state->h, H_1, sizeof(H_1)); break; + default: + errno = EINVAL; + return -1; + } + + state->chunk_size = 64; + + return 0; +} |