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