From fc13fb2ba5993d06d9d6ae5e80bc337aebbdc119 Mon Sep 17 00:00:00 2001 From: aqua Date: Sun, 8 Oct 2023 19:50:00 +0300 Subject: Use meson build system --- lib/blake2/include/blake2s.h | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 lib/blake2/include/blake2s.h (limited to 'lib/blake2/include') diff --git a/lib/blake2/include/blake2s.h b/lib/blake2/include/blake2s.h new file mode 100644 index 0000000..ede170c --- /dev/null +++ b/lib/blake2/include/blake2s.h @@ -0,0 +1,56 @@ +#pragma once + +#include +#include + +struct BLAKE2s_param { + uint8_t outlen; /* digest length */ + uint8_t keylen; /* key length */ + uint8_t fanout; + uint8_t depth; + uint32_t leaf_length; + uint32_t node_offset; + uint16_t node_offset_ex; + uint8_t node_depth; + uint8_t inner_length; + uint64_t salt; + uint64_t personalization; +}; + +struct BLAKE2s_ctx { + uint8_t b[64]; /* input buffer */ + size_t c; /* pointer for b[] */ + uint32_t h[8]; /* chained state vector h */ + uint32_t t[2]; /* total number of bytes */ + struct BLAKE2s_param param; /* parameter block */ +}; + +/** + * 3.1 Mixing Function G + */ +void G(uint32_t V[16], unsigned a, unsigned b, unsigned c, unsigned d, uint32_t x, uint32_t y); + +/** + * 3.2 Compression Function F + * @param t: 2w-bit offset counter t + * @param f: final block indicator flag f + */ +void F(struct BLAKE2s_ctx *context, uint32_t m[16], uint32_t f); + +int BLAKE2s_init(struct BLAKE2s_ctx *ctx, uint8_t outlen, const void *key, uint8_t keylen); +void BLAKE2s_update(struct BLAKE2s_ctx *ctx, const void *d, size_t dd); +void BLAKE2s_final(struct BLAKE2s_ctx *ctx, void *out); + +/* All-in-one convenience function. */ +static __inline__ int +BLAKE2s(void *out, uint8_t outlen, /* return buffer for digest */ + const void *key, uint8_t keylen, /* optional secret key */ + const void *in, size_t inlen) /* data to be hashed */ +{ + struct BLAKE2s_ctx ctx; + if (BLAKE2s_init(&ctx, outlen, key, keylen)) return -1; + BLAKE2s_update(&ctx, in, inlen); + BLAKE2s_final(&ctx, out); + + return 0; +} -- cgit v1.2.1