7#include <botan/internal/bls12_381_tower.h>
9#include <botan/internal/mp_core.h>
14 return m_c0.is_zero() && m_c1.is_zero();
20 const std::array<const FieldElement*, 12> coeffs = {
35 for(
size_t i = 0; i != coeffs.size(); ++i) {
36 coeffs[i]->serialize_to(bytes.subspan(i * fe_bytes).first<fe_bytes>());
41 return Fp12(m_c0 + x.m_c0, m_c1 + x.m_c1);
45 return Fp12(m_c0 - x.m_c0, m_c1 - x.m_c1);
49 return Fp12(m_c0.negate(), m_c1.negate());
54 const auto aa = m_c0 * x.m_c0;
55 const auto bb = m_c1 * x.m_c1;
56 const auto c1 = (m_c1 + m_c0) * (x.m_c0 + x.m_c1) - aa - bb;
58 return Fp12(bb.mul_by_nonresidue() + aa,
c1);
62 const auto ab = m_c0 * m_c1;
63 const auto c0c1 = m_c0 + m_c1;
64 const auto c0 = (m_c1.mul_by_nonresidue() + m_c0) * c0c1 - ab - ab.mul_by_nonresidue();
65 const auto c1 = ab + ab;
71 const auto t = (m_c0.square() - m_c1.square().mul_by_nonresidue()).
invert();
76 return Fp12(m_c0, m_c1.negate());
80 const auto aa = m_c0.mul_by_01(b0, b1);
81 const auto bb = m_c1.mul_by_1(b4);
82 const auto c1 = (m_c1 + m_c0).mul_by_01(b0, b1 + b4) - aa - bb;
84 return Fp12(bb.mul_by_nonresidue() + aa,
c1);
91 "08f2220fb0fb66eb1ce393ea5daace4da35baecab2dc29ee97e83cccd117228fc6695f92b50a831307089552b319d465"),
93 "110eefda88847faf2e3813cbe5a0de89c11b9cba40a8e8d0cf4895d42599d3945842a06bfc497cecb2f66aad4ce5d646"));
95 const auto c0 = m_c0.frobenius_map();
96 const auto c1 = m_c1.frobenius_map();
99 return Fp12(
c0,
Fp6(
c1.c0() * FP12_FROBENIUS_C1,
c1.c1() * FP12_FROBENIUS_C1,
c1.c2() * FP12_FROBENIUS_C1));
107 const FieldElement2& b) -> std::pair<FieldElement2, FieldElement2> {
108 const auto t0 = a.
square();
109 const auto t1 = b.
square();
110 const auto c0 = t1.mul_by_nonresidue() + t0;
111 const auto c1 = (a + b).
square() - t0 - t1;
122 const auto [t0a, t1a] = fp4_square(z0, z1);
129 const auto [t0b, t1b] = fp4_square(z2, z3);
130 const auto [t2, t3] = fp4_square(z4, z5);
137 const auto t = t3.mul_by_nonresidue();
143 return Fp12(
Fp6(z0, z4, z3),
Fp6(z2, z1, z5));
147 return (m_c0 == other.m_c0) && (m_c1 == other.m_c1);
151 m_c0.conditional_assign(cnd, other.m_c0);
152 m_c1.conditional_assign(cnd, other.m_c1);
FieldElement2 square() const
static constexpr FieldElement2 _unchecked_from_words(std::array< word, FieldElement::N > c0, std::array< word, FieldElement::N > c1)
const FieldElement & c0() const
static constexpr size_t BYTES
Fp12 mul(const Fp12 &x) const
void serialize_to(std::span< uint8_t, Fp12::BYTES > bytes) const
Fp12 cyclotomic_square() const
CT::Choice is_zero() const
Fp12 frobenius_map() const
Fp12 mul_by_014(const FieldElement2 &b0, const FieldElement2 &b1, const FieldElement2 &b4) const
Fp12 sub(const Fp12 &x) const
Fp12 add(const Fp12 &x) const
void conditional_assign(CT::Choice cnd, const Fp12 &other)
CT::Choice operator==(const Fp12 &other) const
const FieldElement2 & c1() const
constexpr auto hex_to_words(const char(&s)[N])