#include <sys/types.h>
#include <sys/systm.h>
#ifndef _BLAKE2S_H_
#define _BLAKE2S_H_
enum blake2s_lengths {
BLAKE2S_BLOCK_SIZE = 64,
BLAKE2S_HASH_SIZE = 32,
BLAKE2S_KEY_SIZE = 32
};
struct blake2s_state {
uint32_t h[8];
uint32_t t[2];
uint32_t f[2];
uint8_t buf[BLAKE2S_BLOCK_SIZE];
unsigned int buflen;
unsigned int outlen;
};
void blake2s_init(struct blake2s_state *state, size_t outlen);
void blake2s_init_key(struct blake2s_state *state, size_t outlen,
const void *key, size_t keylen);
void blake2s_update(struct blake2s_state *state, const uint8_t *in,
size_t inlen);
void blake2s_final(struct blake2s_state *state, uint8_t *out);
static inline void
blake2s(uint8_t *out, const uint8_t *in, const uint8_t *key,
size_t outlen, size_t inlen, size_t keylen)
{
struct blake2s_state state;
KKASSERT((in != NULL || inlen == 0) &&
out != NULL && outlen <= BLAKE2S_HASH_SIZE &&
(key != NULL || keylen == 0) && keylen <= BLAKE2S_KEY_SIZE);
if (keylen > 0)
blake2s_init_key(&state, outlen, key, keylen);
else
blake2s_init(&state, outlen);
blake2s_update(&state, in, inlen);
blake2s_final(&state, out);
}
#endif