4#include "barretenberg/common/constexpr_utils.hpp"
5#include "barretenberg/numeric/bitop/pow.hpp"
8namespace keccak_tables {
55 static constexpr size_t TABLE_BITS = 4;
56 static constexpr uint64_t BASE = 11;
58 static constexpr uint64_t THETA_NORMALIZATION_TABLE[11]{
59 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
98 uint64_t accumulator = 0;
99 uint64_t input = key[0];
100 uint64_t base_shift = 1;
102 uint64_t slice = input % BASE;
103 uint64_t bit = THETA_NORMALIZATION_TABLE[
static_cast<size_t>(slice)];
104 accumulator += (bit * base_shift);
119 std::array<uint64_t, TABLE_BITS> result;
121 for (
size_t i = 0; i < TABLE_BITS; ++i) {
141 for (
size_t i = 0; i < TABLE_BITS; ++i) {
142 if (counts[i] == BASE - 1) {
151 uint64_t normalized_value = 0;
152 for (
size_t i = 0; i < TABLE_BITS; ++i) {
153 value += counts[i] * scaled_bases[i];
154 normalized_value += (THETA_NORMALIZATION_TABLE[counts[i]]) * scaled_bases[i];
156 return { value, normalized_value };
173 table.table_index = table_index;
174 table.use_twin_keys =
false;
175 table.size = numeric::pow64(
static_cast<uint64_t
>(BASE), TABLE_BITS);
177 std::array<size_t, TABLE_BITS> counts{};
178 std::array<uint64_t, 2> column_values{ 0, 0 };
180 for (
size_t i = 0; i < table.size; ++i) {
181 table.column_1.emplace_back(column_values[0]);
182 table.column_2.emplace_back(column_values[1]);
183 table.column_3.emplace_back(0);
189 constexpr uint64_t step_size = numeric::pow64(
static_cast<uint64_t
>(BASE), TABLE_BITS);
239 constexpr size_t num_tables_per_multitable =
240 (64 / TABLE_BITS) + (64 % TABLE_BITS == 0 ? 0 : 1);
242 uint64_t column_multiplier = numeric::pow64(BASE, TABLE_BITS);
243 MultiTable table(column_multiplier, column_multiplier, 0, num_tables_per_multitable);
246 for (
size_t i = 0; i < num_tables_per_multitable; ++i) {
247 table.slice_sizes.emplace_back(numeric::pow64(BASE, TABLE_BITS));
248 table.lookup_ids.emplace_back(KECCAK_THETA);
Generates plookup tables required for THETA round of Keccak hash function.
Definition: keccak_theta.hpp:53
static std::array< barretenberg::fr, 2 > get_theta_renormalization_values(const std::array< uint64_t, 2 > key)
Given a table input value, return the table output value.
Definition: keccak_theta.hpp:96
static MultiTable get_theta_output_table(const MultiTableId id=KECCAK_THETA_OUTPUT)
Create the THETA MultiTable used by plookup to generate a sequence of lookups.
Definition: keccak_theta.hpp:237
static std::array< uint64_t, 2 > get_column_values_for_next_row(std::array< size_t, TABLE_BITS > &counts)
Get column values for next row of plookup table. Used to generate plookup table row values.
Definition: keccak_theta.hpp:137
static constexpr std::array< uint64_t, TABLE_BITS > get_scaled_bases()
Precompute an array of base multipliers (11^i for i = [0, ..., TABLE_BITS - 1]) Code is slightly fast...
Definition: keccak_theta.hpp:117
static BasicTable generate_theta_renormalization_table(BasicTableId id, const size_t table_index)
Generate plookup table that normalizes a TABLE_BITS-slice of a base-11 integer.
Definition: keccak_theta.hpp:166
The structure contains the most basic table serving one function (for, example an xor table)
Definition: types.hpp:263
Definition: types.hpp:124