barretenberg
Loading...
Searching...
No Matches
blake2s.hpp
1/*
2 BLAKE2 reference source code package - reference C implementations
3
4 Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the
5 terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
6 your option. The terms of these licenses can be found at:
7
8 - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
9 - OpenSSL license : https://www.openssl.org/source/license.html
10 - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
11
12 More information about the BLAKE2 hash function can be found at
13 https://blake2.net.
14*/
15#pragma once
16
17#include <array>
18#include <cstddef>
19#include <cstdint>
20#include <vector>
21
22namespace blake2 {
23
24#if defined(_MSC_VER)
25#define BLAKE2_PACKED(x) __pragma(pack(push, 1)) x __pragma(pack(pop))
26#else
27#define BLAKE2_PACKED(x) x __attribute__((packed))
28#endif
29
30enum blake2s_constant {
31 BLAKE2S_BLOCKBYTES = 64,
32 BLAKE2S_OUTBYTES = 32,
33 BLAKE2S_KEYBYTES = 32,
34 BLAKE2S_SALTBYTES = 8,
35 BLAKE2S_PERSONALBYTES = 8
36};
37
38typedef struct blake2s_state__ {
39 uint32_t h[8];
40 uint32_t t[2];
41 uint32_t f[2];
42 uint8_t buf[BLAKE2S_BLOCKBYTES];
43 size_t buflen;
44 size_t outlen;
45 uint8_t last_node;
47
48BLAKE2_PACKED(struct blake2s_param__ {
49 uint8_t digest_length; /* 1 */
50 uint8_t key_length; /* 2 */
51 uint8_t fanout; /* 3 */
52 uint8_t depth; /* 4 */
53 uint32_t leaf_length; /* 8 */
54 uint32_t node_offset; /* 12 */
55 uint16_t xof_length; /* 14 */
56 uint8_t node_depth; /* 15 */
57 uint8_t inner_length; /* 16 */
58 /* uint8_t reserved[0]; */
59 uint8_t salt[BLAKE2S_SALTBYTES]; /* 24 */
60 uint8_t personal[BLAKE2S_PERSONALBYTES]; /* 32 */
61});
62
63typedef struct blake2s_param__ blake2s_param;
64
65/* Padded structs result in a compile-time error */
66enum { BLAKE2_DUMMY_1 = 1 / (sizeof(blake2s_param) == BLAKE2S_OUTBYTES) };
67
68int blake2s_init(blake2s_state* S, size_t outlen);
69int blake2s_init_key(blake2s_state* S, size_t outlen, const void* key, size_t keylen);
70int blake2s_init_param(blake2s_state* S, const blake2s_param* P);
71int blake2s_update(blake2s_state* S, const void* in, size_t inlen);
72int blake2s_final(blake2s_state* S, void* out, size_t outlen);
73
74std::array<uint8_t, BLAKE2S_OUTBYTES> blake2s(std::vector<uint8_t> const& input);
75
76} // namespace blake2
Definition: blake2s.hpp:38