Botan 3.14.1
Crypto and TLS for C&
Botan::BLS12_381::Fp6 Class Referencefinal

#include <bls12_381_tower.h>

Public Member Functions

Fp6 add (const Fp6 &x) const
const FieldElement2 & c0 () const
const FieldElement2 & c1 () const
const FieldElement2 & c2 () const
void conditional_assign (CT::Choice cnd, const Fp6 &other)
constexpr Fp6 ()=default
constexpr Fp6 (const FieldElement2 &c0, const FieldElement2 &c1, const FieldElement2 &c2)
Fp6 frobenius_map () const
Fp6 invert () const
CT::Choice is_zero () const
Fp6 mul (const Fp6 &x) const
Fp6 mul_by_01 (const FieldElement2 &b0, const FieldElement2 &b1) const
Fp6 mul_by_1 (const FieldElement2 &b1) const
Fp6 mul_by_nonresidue () const
Fp6 negate () const
CT::Choice operator== (const Fp6 &other) const
Fp6 square () const
Fp6 sub (const Fp6 &x) const

Static Public Member Functions

static Fp6 one ()
static Fp6 zero ()

Detailed Description

An element of Fp6 = Fp2[v]/(v^3 - (u + 1))

Represented as c0 + c1*v + c2*v^2

Definition at line 19 of file bls12_381_tower.h.

Constructor & Destructor Documentation

◆ Fp6() [1/2]

Botan::BLS12_381::Fp6::Fp6 ( )
constexprdefault

◆ Fp6() [2/2]

Botan::BLS12_381::Fp6::Fp6 ( const FieldElement2 & c0,
const FieldElement2 & c1,
const FieldElement2 & c2 )
inlineconstexpr

Definition at line 24 of file bls12_381_tower.h.

24 :
25 m_c0(c0), m_c1(c1), m_c2(c2) {}
const FieldElement2 & c1() const
const FieldElement2 & c2() const
const FieldElement2 & c0() const

References c0(), c1(), and c2().

Member Function Documentation

◆ add()

Fp6 Botan::BLS12_381::Fp6::add ( const Fp6 & x) const

Definition at line 17 of file bls12_381_fp6.cpp.

17 {
18 return Fp6(m_c0 + x.m_c0, m_c1 + x.m_c1, m_c2 + x.m_c2);
19}
constexpr Fp6()=default

References Fp6().

Referenced by Botan::BLS12_381::operator+().

◆ c0()

const FieldElement2 & Botan::BLS12_381::Fp6::c0 ( ) const
inline

Definition at line 31 of file bls12_381_tower.h.

31{ return m_c0; }

Referenced by Fp6(), and invert().

◆ c1()

const FieldElement2 & Botan::BLS12_381::Fp6::c1 ( ) const
inline

Definition at line 33 of file bls12_381_tower.h.

33{ return m_c1; }

Referenced by Botan::BLS12_381::Fp12::cyclotomic_square(), Fp6(), and invert().

◆ c2()

const FieldElement2 & Botan::BLS12_381::Fp6::c2 ( ) const
inline

Definition at line 35 of file bls12_381_tower.h.

35{ return m_c2; }

Referenced by Fp6(), and invert().

◆ conditional_assign()

void Botan::BLS12_381::Fp6::conditional_assign ( CT::Choice cnd,
const Fp6 & other )

Definition at line 109 of file bls12_381_fp6.cpp.

109 {
110 m_c0.conditional_assign(cnd, other.m_c0);
111 m_c1.conditional_assign(cnd, other.m_c1);
112 m_c2.conditional_assign(cnd, other.m_c2);
113}

References Fp6().

◆ frobenius_map()

Fp6 Botan::BLS12_381::Fp6::frobenius_map ( ) const

The Frobenius endomorphism x -> x^p

Definition at line 87 of file bls12_381_fp6.cpp.

87 {
88 // (u+1)^((p-1)/3)
89 constexpr auto FP6_FROBENIUS_C1 = FieldElement2::_unchecked_from_words(
91 "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
93 "18f020655463874103f97d6e83d050d28eb60ebe01bacb9e587042afd3851b955dab22461fcda5d2cd03c9e48671f071"));
94
95 // (u+1)^((2p-2)/3)
96 constexpr auto FP6_FROBENIUS_C2 = FieldElement2::_unchecked_from_words(
98 "14e56d3f1564853a14e4f04fe2db9068a20d1b8c7e88102450880866309b7e2c2af322533285a5d5890dc9e4867545c3"),
100 "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"));
101
102 return Fp6(m_c0.conjugate(), m_c1.conjugate() * FP6_FROBENIUS_C1, m_c2.conjugate() * FP6_FROBENIUS_C2);
103}
static constexpr FieldElement2 _unchecked_from_words(std::array< word, FieldElement::N > c0, std::array< word, FieldElement::N > c1)
constexpr auto hex_to_words(const char(&s)[N])
Definition mp_core.h:921

References Botan::BLS12_381::FieldElement2::_unchecked_from_words(), Fp6(), and Botan::hex_to_words().

◆ invert()

Fp6 Botan::BLS12_381::Fp6::invert ( ) const

Return the inverse of this element, or zero for zero

Definition at line 57 of file bls12_381_fp6.cpp.

57 {
58 const auto c0 = m_c0.square() - (m_c1 * m_c2).mul_by_nonresidue();
59 const auto c1 = m_c2.square().mul_by_nonresidue() - (m_c0 * m_c1);
60 const auto c2 = m_c1.square() - (m_c0 * m_c2);
61
62 const auto t = (((m_c1 * c2) + (m_c2 * c1)).mul_by_nonresidue() + (m_c0 * c0)).invert();
63
64 return Fp6(t * c0, t * c1, t * c2);
65}
Fp6 mul_by_nonresidue() const

References c0(), c1(), c2(), Fp6(), and mul_by_nonresidue().

◆ is_zero()

CT::Choice Botan::BLS12_381::Fp6::is_zero ( ) const

Definition at line 13 of file bls12_381_fp6.cpp.

13 {
14 return m_c0.is_zero() && m_c1.is_zero() && m_c2.is_zero();
15}

◆ mul()

Fp6 Botan::BLS12_381::Fp6::mul ( const Fp6 & x) const

Definition at line 29 of file bls12_381_fp6.cpp.

29 {
30 // Karatsuba multiplication using 6 Fp2 multiplications, with xi = u+1:
31 // c0 = t0 + xi*((a1+a2)(b1+b2) - t1 - t2)
32 // c1 = (a0+a1)(b0+b1) - t0 - t1 + xi*t2
33 // c2 = (a0+a2)(b0+b2) - t0 - t2 + t1
34 const auto t0 = m_c0 * x.m_c0;
35 const auto t1 = m_c1 * x.m_c1;
36 const auto t2 = m_c2 * x.m_c2;
37
38 const auto s12 = (m_c1 + m_c2) * (x.m_c1 + x.m_c2);
39 const auto s01 = (m_c0 + m_c1) * (x.m_c0 + x.m_c1);
40 const auto s02 = (m_c0 + m_c2) * (x.m_c0 + x.m_c2);
41
42 return Fp6((s12 - t1 - t2).mul_by_nonresidue() + t0, s01 - t0 - t1 + t2.mul_by_nonresidue(), s02 - t0 - t2 + t1);
43}

References Fp6(), and mul_by_nonresidue().

Referenced by Botan::BLS12_381::operator*().

◆ mul_by_01()

Fp6 Botan::BLS12_381::Fp6::mul_by_01 ( const FieldElement2 & b0,
const FieldElement2 & b1 ) const

Sparse multiplication by b0 + b1*v

Definition at line 76 of file bls12_381_fp6.cpp.

76 {
77 const auto a_a = m_c0 * b0;
78 const auto b_b = m_c1 * b1;
79
80 const auto t1 = (m_c2 * b1).mul_by_nonresidue() + a_a;
81 const auto t2 = (b0 + b1) * (m_c0 + m_c1) - a_a - b_b;
82 const auto t3 = m_c2 * b0 + b_b;
83
84 return Fp6(t1, t2, t3);
85}

References Fp6(), and mul_by_nonresidue().

◆ mul_by_1()

Fp6 Botan::BLS12_381::Fp6::mul_by_1 ( const FieldElement2 & b1) const

Sparse multiplication by b1*v

Definition at line 72 of file bls12_381_fp6.cpp.

72 {
73 return Fp6((m_c2 * b1).mul_by_nonresidue(), m_c0 * b1, m_c1 * b1);
74}

References Fp6(), and mul_by_nonresidue().

◆ mul_by_nonresidue()

Fp6 Botan::BLS12_381::Fp6::mul_by_nonresidue ( ) const

Multiplication by v

Definition at line 67 of file bls12_381_fp6.cpp.

67 {
68 // (c0 + c1*v + c2*v^2)*v = c2*(u+1) + c0*v + c1*v^2 using v^3 = u+1
69 return Fp6(m_c2.mul_by_nonresidue(), m_c0, m_c1);
70}

References Fp6().

Referenced by invert(), mul(), mul_by_01(), and mul_by_1().

◆ negate()

Fp6 Botan::BLS12_381::Fp6::negate ( ) const

Definition at line 25 of file bls12_381_fp6.cpp.

25 {
26 return Fp6(m_c0.negate(), m_c1.negate(), m_c2.negate());
27}

References Fp6().

◆ one()

Fp6 Botan::BLS12_381::Fp6::one ( )
inlinestatic

◆ operator==()

CT::Choice Botan::BLS12_381::Fp6::operator== ( const Fp6 & other) const

Definition at line 105 of file bls12_381_fp6.cpp.

105 {
106 return (m_c0 == other.m_c0) && (m_c1 == other.m_c1) && (m_c2 == other.m_c2);
107}

References Fp6().

◆ square()

Fp6 Botan::BLS12_381::Fp6::square ( ) const

Definition at line 45 of file bls12_381_fp6.cpp.

45 {
46 const auto s0 = m_c0.square();
47 const auto ab = m_c0 * m_c1;
48 const auto s1 = ab + ab;
49 const auto s2 = (m_c0 - m_c1 + m_c2).square();
50 const auto bc = m_c1 * m_c2;
51 const auto s3 = bc + bc;
52 const auto s4 = m_c2.square();
53
54 return Fp6(s3.mul_by_nonresidue() + s0, s4.mul_by_nonresidue() + s1, s1 + s2 + s3 - s0 - s4);
55}

References Fp6(), and square().

Referenced by square().

◆ sub()

Fp6 Botan::BLS12_381::Fp6::sub ( const Fp6 & x) const

Definition at line 21 of file bls12_381_fp6.cpp.

21 {
22 return Fp6(m_c0 - x.m_c0, m_c1 - x.m_c1, m_c2 - x.m_c2);
23}

References Fp6().

Referenced by Botan::BLS12_381::operator-().

◆ zero()

Fp6 Botan::BLS12_381::Fp6::zero ( )
inlinestatic

Definition at line 27 of file bls12_381_tower.h.

27{ return Fp6(); }

References Fp6().

Referenced by Botan::BLS12_381::Fp12::one().


The documentation for this class was generated from the following files: