Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
blake3s.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#pragma once
8
9#include "../../primitives/byte_array/byte_array.hpp"
10#include "../../primitives/field/field.hpp"
12
13namespace bb::stdlib {
14template <typename Builder> class Blake3s {
17
18/*
19 * Constants and more.
20 */
21#define BLAKE3_VERSION_STRING "0.3.7"
22
23 // internal flags
25 CHUNK_START = 1 << 0,
26 CHUNK_END = 1 << 1,
27 PARENT = 1 << 2,
28 ROOT = 1 << 3,
29 KEYED_HASH = 1 << 4,
32 };
34 // constants
36
37 static constexpr std::array<uint32_t, 8> IV{ 0x6A09E667UL, 0xBB67AE85UL, 0x3C6EF372UL, 0xA54FF53AUL,
38 0x510E527FUL, 0x9B05688CUL, 0x1F83D9ABUL, 0x5BE0CD19UL };
39
49
57 const field_t<Builder> cv[8],
58 const byte_array_ct& block,
59 uint8_t block_len,
60 uint8_t flags);
61
62 static void compress_in_place(field_t<Builder> cv[8], const byte_array_ct& block, uint8_t block_len, uint8_t flags);
63
64 static void compress_xof(
65 const field_t<Builder> cv[8], const byte_array_ct& block, uint8_t block_len, uint8_t flags, byte_array_ct& out);
66
67 /*
68 * Blake3s helper functions.
69 *
70 */
71 static uint8_t maybe_start_flag(const blake3_hasher* self)
72 {
73 if (self->blocks_compressed == 0) {
74 return CHUNK_START;
75 } else {
76 return 0;
77 }
78 }
79 static output_t make_output(const field_t<Builder> input_cv[8],
80 const byte_array_ct& block,
81 uint8_t block_len,
82 uint8_t flags);
83
84 static void hasher_init(blake3_hasher* self);
85
86 static void hasher_update(blake3_hasher* self, const byte_array_ct& input, size_t input_len);
87
88 static void hasher_finalize(const blake3_hasher* self, byte_array_ct& out);
89
90 public:
91 static byte_array_ct hash(const byte_array_ct& input);
92};
93
94} // namespace bb::stdlib
static void hasher_init(blake3_hasher *self)
Definition blake3s.cpp:126
static byte_array_ct hash(const byte_array_ct &input)
Definition blake3s.cpp:183
static void compress_in_place(field_t< Builder > cv[8], const byte_array_ct &block, uint8_t block_len, uint8_t flags)
Definition blake3s.cpp:55
static void compress_xof(const field_t< Builder > cv[8], const byte_array_ct &block, uint8_t block_len, uint8_t flags, byte_array_ct &out)
Definition blake3s.cpp:77
static constexpr size_t BLAKE3_STATE_SIZE
Definition blake3s.hpp:33
static void compress_pre(field_t< Builder > state[BLAKE3_STATE_SIZE], const field_t< Builder > cv[8], const byte_array_ct &block, uint8_t block_len, uint8_t flags)
Definition blake3s.cpp:21
static constexpr std::array< uint32_t, 8 > IV
Definition blake3s.hpp:37
static void hasher_finalize(const blake3_hasher *self, byte_array_ct &out)
Definition blake3s.cpp:171
static uint8_t maybe_start_flag(const blake3_hasher *self)
Definition blake3s.hpp:71
static output_t make_output(const field_t< Builder > input_cv[8], const byte_array_ct &block, uint8_t block_len, uint8_t flags)
Definition blake3s.cpp:103
static void hasher_update(blake3_hasher *self, const byte_array_ct &input, size_t input_len)
Definition blake3s.cpp:142
Represents a dynamic array of bytes in-circuit.
byte_array< Builder > buf
Definition blake3s.hpp:43
field_t< Builder > cv[8]
Definition blake3s.hpp:42
field_t< Builder > key[8]
Definition blake3s.hpp:41
byte_array< Builder > block
Definition blake3s.hpp:52
field_t< Builder > input_cv[8]
Definition blake3s.hpp:51