2#include "barretenberg/numeric/random/engine.hpp"
5template <
typename base_field,
typename Fq6Params>
class field6 {
7 constexpr field6(
const base_field& a = base_field::zero(),
8 const base_field& b = base_field::zero(),
9 const base_field& c = base_field::zero())
27 constexpr field6& operator=(
const field6& other)
noexcept
46 constexpr ~field6()
noexcept =
default;
52 static constexpr field6 zero() {
return { base_field::zero(), base_field::zero(), base_field::zero() }; };
53 static constexpr field6 one() {
return { base_field::one(), base_field::zero(), base_field::zero() }; };
55 static constexpr base_field mul_by_non_residue(
const base_field& a) {
return Fq6Params::mul_by_non_residue(a); }
75 constexpr field6 operator-()
const
89 base_field T0 = c0 * other.c0;
90 base_field T1 = c1 * other.c1;
91 base_field T2 = c2 * other.c2;
93 base_field T3 = (c0 + c2) * (other.c0 + other.c2);
94 base_field T4 = (c0 + c1) * (other.c0 + other.c1);
95 base_field T5 = (c1 + c2) * (other.c1 + other.c2);
98 T0 + mul_by_non_residue(T5 - (T1 + T2)),
99 T4 - (T0 + T1) + mul_by_non_residue(T2),
104 constexpr field6 operator/(
const field6& other)
const {
return operator*(other.invert()); }
106 constexpr field6 sqr()
const
110 base_field S0 = c0.sqr();
111 base_field S1 = c0 * c1;
113 base_field S2 = (c0 + c2 - c1).sqr();
114 base_field S3 = c1 * c2;
116 base_field S4 = c2.sqr();
118 mul_by_non_residue(S3) + S0,
119 mul_by_non_residue(S4) + S1,
120 S1 + S2 + S3 - S0 - S4,
142 *
this = operator*(other);
148 *
this = operator/(other);
152 constexpr field6 invert()
const
156 base_field C0 = c0.sqr() - mul_by_non_residue(c1 * c2);
157 base_field C1 = mul_by_non_residue(c2.sqr()) - (c0 * c1);
158 base_field C2 = c1.sqr() - (c0 * c2);
159 base_field T0 = ((c0 * C0) + mul_by_non_residue((c2 * C1) + (c1 * C2))).invert();
168 constexpr field6 mul_by_fq2(
const base_field& other)
const {
return { other * c0, other * c1, other * c2 }; }
170 constexpr field6 frobenius_map_three()
const
174 Fq6Params::frobenius_coeffs_c1_3 * c1.frobenius_map(),
175 Fq6Params::frobenius_coeffs_c2_3 * c2.frobenius_map(),
179 constexpr field6 frobenius_map_two()
const
181 return { c0, Fq6Params::frobenius_coeffs_c1_2 * c1, Fq6Params::frobenius_coeffs_c2_2 * c2 };
184 constexpr field6 frobenius_map_one()
const
188 Fq6Params::frobenius_coeffs_c1_1 * c1.frobenius_map(),
189 Fq6Params::frobenius_coeffs_c2_1 * c2.frobenius_map(),
196 base_field::random_element(engine),
197 base_field::random_element(engine),
198 base_field::random_element(engine),
202 constexpr field6 to_montgomery_form()
const
205 c0.to_montgomery_form(),
206 c1.to_montgomery_form(),
207 c2.to_montgomery_form(),
211 constexpr field6 from_montgomery_form()
const
214 c0.from_montgomery_form(),
215 c1.from_montgomery_form(),
216 c2.from_montgomery_form(),
220 [[nodiscard]]
constexpr bool is_zero()
const {
return c0.is_zero() && c1.is_zero() && c2.is_zero(); }
222 constexpr bool operator==(
const field6& other)
const {
return c0 == other.c0 && c1 == other.c1 && c2 == other.c2; }
Definition: engine.hpp:10
constexpr_utils defines some helper methods that perform some stl-equivalent operations but in a cons...
Definition: constexpr_utils.hpp:16