3#ifdef STARKNET_GARAGA_FLAVORS
10template <
typename Params>
class PoseidonPermutation {
20 using State = std::array<FF, t>;
21 using RoundConstants = std::array<FF, t>;
22 using MatrixDiagonal = std::array<FF, t>;
28 static constexpr void add_round_constants(State& input,
const RoundConstants& rc)
30 for (
size_t i = 0; i < t; ++i) {
35 static constexpr void matrix_multiplication_internal(State& input)
38 for (
size_t i = 1; i < t; ++i) {
41 for (
size_t i = 0; i < t; ++i) {
42 input[i] *= internal_matrix_diagonal[i];
47 static constexpr void apply_single_sbox(
FF& input)
49 static_assert(d == 3);
50 auto xx = input.
sqr();
54 static constexpr void apply_sbox(State& input)
56 for (
auto& in : input) {
57 apply_single_sbox(in);
61 static constexpr State permutation(
const State& input)
63 State current_state(input);
65 constexpr size_t rounds_f_beginning = rounds_f / 2;
66 for (
size_t i = 0; i < rounds_f_beginning; ++i) {
67 add_round_constants(current_state, round_constants[i]);
68 apply_sbox(current_state);
69 matrix_multiplication_internal(current_state);
72 const size_t p_end = rounds_f_beginning + rounds_p;
73 for (
size_t i = rounds_f_beginning; i < p_end; ++i) {
75 apply_single_sbox(current_state[2]);
76 matrix_multiplication_internal(current_state);
79 for (
size_t i = p_end; i < NUM_ROUNDS; ++i) {
80 add_round_constants(current_state, round_constants[i]);
81 apply_sbox(current_state);
82 matrix_multiplication_internal(current_state);
constexpr uint32_t round_constants[64]
Inner sum(Cont< Inner, Args... > const &in)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
static constexpr size_t t
static constexpr std::array< FF, t > internal_matrix_diagonal
static constexpr size_t sbox_size
static constexpr size_t rounds_f
static constexpr size_t d
static constexpr size_t rounds_p
static constexpr std::array< std::array< FF, t >, rounds_f+rounds_p > round_constants
BB_INLINE constexpr field sqr() const noexcept