13using namespace blake_util;
20template <
typename Builder>
27 field_ct block_words[BLAKE3_STATE_SIZE];
28 for (
size_t i = 0; i < BLAKE3_STATE_SIZE; ++i) {
49 for (
size_t idx = 0; idx < 7; idx++) {
50 round_fn(state, block_words, idx,
true);
54template <
typename Builder>
61 compress_pre(state, cv, block, block_len, flags);
70 for (
size_t i = 0; i < (BLAKE3_STATE_SIZE >> 1); i++) {
72 cv[i] = lookup[ColumnIdx::C3][0];
76template <
typename Builder>
85 compress_pre(state, cv, block, block_len, flags);
91 for (
size_t i = 0; i < (BLAKE3_STATE_SIZE >> 1); i++) {
106template <
typename Builder>
114 output_t ret{ .
input_cv = {}, .block = block_copy, .block_len = block_len, .flags = flags };
116 for (
size_t i = 0; i < (BLAKE3_OUT_LEN >> 2); ++i) {
117 ret.input_cv[i] = input_cv[i];
129 for (
size_t i = 0; i < (BLAKE3_KEY_LEN >> 2); ++i) {
140template <
typename Builder>
143 if (input_len == 0) {
147 size_t start_counter = 0;
148 while (input_len > BLAKE3_BLOCK_LEN) {
149 compress_in_place(self->
cv,
150 input.
slice(start_counter, BLAKE3_BLOCK_LEN),
152 self->
flags | maybe_start_flag(self));
154 start_counter += BLAKE3_BLOCK_LEN;
155 input_len -= BLAKE3_BLOCK_LEN;
158 size_t take = BLAKE3_BLOCK_LEN - ((size_t)self->
buf_len);
159 if (take > input_len) {
166 self->
buf_len =
static_cast<uint8_t
>(self->
buf_len + (uint8_t)take);
172 uint8_t block_flags = self->
flags | maybe_start_flag(self) | CHUNK_END;
179 out = wide_buf.
slice(0, BLAKE3_OUT_LEN);
185 "Barretenberg does not support blake3s with input lengths greater than 1024 bytes.");
192 .
key = {}, .cv = {}, .buf =
buf, .buf_len = 0, .blocks_compressed = 0, .flags = 0, .
context = ctx
195 hasher_init(&hasher);
196 hasher_update(&hasher, input, input.
size());
200 hasher_finalize(&hasher, result);
#define BB_ASSERT(expression,...)
static void hasher_init(blake3_hasher *self)
static output_t make_output(const field_ct input_cv[BLAKE3_CV_WORDS], const byte_array_ct &block, uint8_t block_len, uint8_t flags)
static byte_array_ct hash(const byte_array_ct &input)
static void compress_in_place(field_ct cv[BLAKE3_CV_WORDS], const byte_array_ct &block, uint8_t block_len, uint8_t flags)
static void hasher_finalize(const blake3_hasher *self, byte_array_ct &out)
static void compress_xof(const field_ct cv[BLAKE3_CV_WORDS], const byte_array_ct &block, uint8_t block_len, uint8_t flags, byte_array_ct &out)
static void compress_pre(field_ct state[BLAKE3_STATE_SIZE], const field_ct cv[BLAKE3_CV_WORDS], const byte_array_ct &block, uint8_t block_len, uint8_t flags)
static void hasher_update(blake3_hasher *self, const byte_array_ct &input, size_t input_len)
Represents a dynamic array of bytes in-circuit.
byte_array slice(size_t offset) const
Slice bytes from the byte array starting at offset. Does not add any constraints.
byte_array reverse() const
Reverse the bytes in the byte array.
byte_array & write_at(byte_array const &other, size_t index)
Overwrites this byte_array starting at index with the contents of other.
Builder * get_context() const
static byte_array constant_padding(Builder *parent_context, size_t num_bytes, uint8_t value=0)
stdlib::field_t< Builder > field_ct
void round_fn(field_t< Builder > state[BLAKE_STATE_SIZE], field_t< Builder > msg[BLAKE_STATE_SIZE], size_t round, const bool which_blake=false)
field_ct cv[BLAKE3_CV_WORDS]
uint8_t blocks_compressed
field_ct key[BLAKE3_CV_WORDS]
field_ct input_cv[BLAKE3_CV_WORDS]