3#include "barretenberg/numeric/bitop/rotate.hpp"
9namespace blake2s_tables {
11static constexpr size_t BITS_IN_LAST_SLICE = 5UL;
12static constexpr size_t SIZE_OF_LAST_SLICE = (1UL << BITS_IN_LAST_SLICE);
19template <u
int64_t bits_per_slice, u
int64_t num_rotated_output_bits,
bool filter = false>
20inline std::array<barretenberg::fr, 2> get_xor_rotate_values_from_key(
const std::array<uint64_t, 2> key)
22 uint64_t filtered_key0 = filter ? key[0] & 3ULL : key[0];
23 uint64_t filtered_key1 = filter ? key[1] & 3ULL : key[1];
24 return {
uint256_t(numeric::rotate32(uint32_t(filtered_key0) ^ uint32_t(filtered_key1),
25 uint32_t(num_rotated_output_bits))),
32template <u
int64_t bits_per_slice, u
int64_t num_rotated_output_bits,
bool filter = false>
33inline BasicTable generate_xor_rotate_table(BasicTableId
id,
const size_t table_index)
35 const uint64_t base = 1UL << bits_per_slice;
38 table.table_index = table_index;
39 table.size = base * base;
40 table.use_twin_keys =
true;
42 for (uint64_t i = 0; i < base; ++i) {
43 for (uint64_t j = 0; j < base; ++j) {
44 table.column_1.emplace_back(i);
45 table.column_2.emplace_back(j);
52 table.column_3.emplace_back(
53 uint256_t(numeric::rotate32(uint32_t(i_copy) ^ uint32_t(j_copy), uint32_t(num_rotated_output_bits))));
57 table.get_values_from_key = &get_xor_rotate_values_from_key<bits_per_slice, num_rotated_output_bits, filter>;
59 table.column_1_step_size = base;
60 table.column_2_step_size = base;
61 table.column_3_step_size = base;
90inline MultiTable get_blake2s_xor_table(
const MultiTableId
id = BLAKE_XOR)
92 const size_t num_entries = (32 + 2) / 6 + 1;
93 const uint64_t base = 1 << 6;
94 MultiTable table(base, base, base, num_entries);
97 for (
size_t i = 0; i < num_entries - 1; ++i) {
98 table.slice_sizes.emplace_back(base);
99 table.lookup_ids.emplace_back(BLAKE_XOR_ROTATE0);
100 table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>);
103 table.slice_sizes.emplace_back(SIZE_OF_LAST_SLICE);
104 table.lookup_ids.emplace_back(BLAKE_XOR_ROTATE0_SLICE5_MOD4);
105 table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<BITS_IN_LAST_SLICE, 0, true>);
113inline MultiTable get_blake2s_xor_rotate_16_table(
const MultiTableId
id = BLAKE_XOR_ROTATE_16)
115 const uint64_t base = 1 << 6;
129 MultiTable table(column_1_coefficients, column_1_coefficients, column_3_coefficients);
132 table.slice_sizes = { base, base, base, base, base, SIZE_OF_LAST_SLICE };
133 table.lookup_ids = { BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE4,
134 BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0_SLICE5_MOD4 };
136 table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>);
137 table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>);
138 table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 4>);
139 table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>);
140 table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>);
141 table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<BITS_IN_LAST_SLICE, 0, true>);
149inline MultiTable get_blake2s_xor_rotate_8_table(
const MultiTableId
id = BLAKE_XOR_ROTATE_8)
151 const uint64_t base = 1 << 6;
165 MultiTable table(column_1_coefficients, column_1_coefficients, column_3_coefficients);
168 table.slice_sizes = { base, base, base, base, base, SIZE_OF_LAST_SLICE };
169 table.lookup_ids = { BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE2, BLAKE_XOR_ROTATE0,
170 BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0_SLICE5_MOD4 };
172 table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>);
173 table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 2>);
174 table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>);
175 table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>);
176 table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>);
177 table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<BITS_IN_LAST_SLICE, 0, true>);
185inline MultiTable get_blake2s_xor_rotate_7_table(
const MultiTableId
id = BLAKE_XOR_ROTATE_7)
187 const uint64_t base = 1 << 6;
201 MultiTable table(column_1_coefficients, column_1_coefficients, column_3_coefficients);
204 table.slice_sizes = { base, base, base, base, base, SIZE_OF_LAST_SLICE };
205 table.lookup_ids = { BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE1, BLAKE_XOR_ROTATE0,
206 BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0_SLICE5_MOD4 };
208 table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>);
209 table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 1>);
210 table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>);
211 table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>);
212 table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>);
213 table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<BITS_IN_LAST_SLICE, 0, true>);
Definition: uint256.hpp:25