25template <
typename Builder>
class keccak {
36 static constexpr size_t BITS = 256;
54 static constexpr std::array<uint64_t, NUM_KECCAK_ROUNDS>
RC = {
55 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, 0x8000000080008000, 0x000000000000808b,
56 0x0000000080000001, 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, 0x0000000000000088,
57 0x0000000080008009, 0x000000008000000a, 0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
58 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, 0x000000000000800a, 0x800000008000000a,
59 0x8000000080008081, 0x8000000000008080, 0x0000000080000001, 0x8000000080008008
63 static constexpr std::array<size_t, NUM_KECCAK_LANES>
ROTATIONS = {
64 0, 1, 62, 28, 27, 36, 44, 6, 55, 20, 3, 10, 43, 25, 39, 41, 45, 15, 21, 8, 18, 2, 61, 56, 14,
81 uint64_t bit =
static_cast<uint64_t
>(input & 1);
82 out_bits[count++] = bit;
86 for (
size_t i = 0; i < count; ++i) {
88 output += out_bits[count - 1 - i];
110 uint64_t bit =
static_cast<uint64_t
>(
slice) & 1;
111 out_bits[count++] = bit;
115 for (
size_t i = 0; i < count; ++i) {
117 out += out_bits[count - 1 - i];
130 for (
size_t i = 0; i < 24; ++i) {
150 for (
size_t i = 0; i < 64; ++i) {
185 std::vector<uint8_t> output;
188 memcpy((
void*)&output[0], (
void*)&hash_result.word64s[0], 32);
198 const size_t input_size);
constexpr std::pair< uint256_t, uint256_t > divmod(const uint256_t &b) const
Implements boolean logic in-circuit.
Represents a dynamic array of bytes in-circuit.
static constexpr uint256_t get_chi_offset()
Compute the constant offset added in the Chi round.
static void rho(keccak_state &state)
RHO round.
static constexpr uint256_t CHI_OFFSET
static constexpr uint256_t BASE
static constexpr uint256_t normalize_sparse(uint256_t input)
Normalize a base-11 integer where each base value can be > 1.
static constexpr std::array< uint256_t, NUM_KECCAK_ROUNDS > get_sparse_round_constants()
Get the sparse round constants object.
static void sponge_absorb_with_permutation_opcode(keccak_state &internal, std::vector< field_ct > &input_buffer, const size_t input_size)
static byte_array_ct sponge_squeeze_for_permutation_opcode(std::array< field_ct, NUM_KECCAK_LANES > lanes, Builder *context)
static void pi(keccak_state &state)
PI.
static void theta(keccak_state &state)
THETA round.
static std::vector< field_ct > format_input_lanes(byte_array_ct &input)
Convert the input buffer into 8-bit keccak lanes in little-endian form. Additionally,...
static void compute_twisted_state(keccak_state &internal)
Compute twisted representation of hash lane.
static void chi(keccak_state &state)
CHI.
static std::vector< uint8_t > hash_native(const std::vector< uint8_t > &data)
static byte_array_ct sponge_squeeze(keccak_state &internal)
static constexpr size_t LIMBS_PER_BLOCK
static field_t< Builder > normalize_and_rotate(const field_ct &limb, field_ct &msb)
Normalize a base-11 limb and left-rotate by keccak::ROTATIONS[lane_index] bits. This method also extr...
static constexpr std::array< size_t, NUM_KECCAK_LANES > ROTATIONS
static constexpr std::array< uint64_t, NUM_KECCAK_ROUNDS > RC
static constexpr size_t NUM_KECCAK_ROUNDS
static constexpr std::array< uint256_t, NUM_KECCAK_ROUNDS > SPARSE_RC
static std::array< field_ct, NUM_KECCAK_LANES > permutation_opcode(std::array< field_ct, NUM_KECCAK_LANES > state, Builder *context)
static std::array< field_ct, NUM_KECCAK_LANES > extended_2_normal(keccak_state &internal)
static byte_array_ct hash_using_permutation_opcode(byte_array_ct &input)
static constexpr size_t WORD_SIZE
static void keccakf1600(keccak_state &state)
static byte_array_ct hash(byte_array_ct &input)
static constexpr size_t NUM_KECCAK_LANES
static constexpr size_t BLOCK_SIZE
static void sponge_absorb(keccak_state &internal, const std::vector< field_ct > &input_buffer, const std::vector< field_ct > &msb_buffer)
static constexpr size_t BITS
static void iota(keccak_state &state, size_t round)
IOTA.
static constexpr uint256_t convert_to_sparse(uint256_t input)
Convert a binary integer into a base11 integer.
const std::vector< FF > data
StrictMock< MockContext > context
struct keccak256 ethash_keccak256(const uint8_t *data, size_t size) NOEXCEPT
void generate_keccak_test_circuit(Builder &builder, size_t num_iterations)
Generate a simple keccak circuit for testing purposes.
C slice(C const &container, size_t start)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::array< field_ct, NUM_KECCAK_LANES > state
std::array< field_ct, NUM_KECCAK_LANES > twisted_state
std::array< field_ct, NUM_KECCAK_LANES > state_msb