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

#include <bls12_381.h>

Public Member Functions

FieldElement2 _x () const
FieldElement2 _y () const
bool is_identity () const
std::array< uint8_t, G2Affine::BYTES > serialize () const

Static Public Member Functions

static std::optional< G2Affine > deserialize (std::span< const uint8_t > bytes)
static G2Affine generator ()
static G2Affine identity ()

Static Public Attributes

static constexpr size_t BYTES = 96

Friends

class G2Projective
template<typename Group>
class GroupOps

Detailed Description

An element of the group G2, in affine form

Group arithmetic is performed on G2Projective; the affine form is used for serialization, pairings, and mixed addition

Definition at line 387 of file bls12_381.h.

Member Function Documentation

◆ _x()

FieldElement2 Botan::BLS12_381::G2Affine::_x ( ) const

Access the coordinates directly; the values are meaningless if the point is the identity element.

Reserved for internal use, not covered by SemVer.

Definition at line 109 of file bls12_381_g2.cpp.

109 {
110 return fe2_load(m_x);
111}

References _x().

Referenced by _x().

◆ _y()

FieldElement2 Botan::BLS12_381::G2Affine::_y ( ) const

Definition at line 113 of file bls12_381_g2.cpp.

113 {
114 return fe2_load(m_y);
115}

References _y().

Referenced by _y().

◆ deserialize()

std::optional< G2Affine > Botan::BLS12_381::G2Affine::deserialize ( std::span< const uint8_t > bytes)
static

Point deserialization

Only compressed point encoding is supported.

This rejects points not in the prime order subgroup. The canonical encoding of the identity element is accepted; callers for which the identity is not a legal value (such as BLS signatures) must check is_identity() themselves.

Definition at line 122 of file bls12_381_g2.cpp.

122 {
123 auto pt = G2Ops::deserialize_unchecked(bytes);
124 if(!pt || pt->is_identity()) {
125 return pt;
126 }
127
128 // Fast subgroup check (https://eprint.iacr.org/2021/1130 section 4):
129 // P is in the prime order subgroup iff psi(P) == [z]P, where psi is
130 // the untwist-Frobenius-twist endomorphism; the test is conclusive
131 // since "Q is of order r under the condition gcd(h1, h2) = 1" and
132 // for BLS12 curves "h2 mod h1 = 1 so that the condition is true"
134
135 const auto psi_x = pt->_x().conjugate() * G2_PSI_X;
136 const auto psi_y = pt->_y().conjugate() * G2_PSI_Y;
137
138 // Compare the projective [z]P with the affine psi(P)
139 const auto z_p_z = fe2_load(z_p.m_z);
140 const auto x_eq = (fe2_load(z_p.m_x) == psi_x * z_p_z);
141 const auto y_eq = (fe2_load(z_p.m_y) == psi_y * z_p_z);
142 if(!(x_eq && y_eq).as_bool()) {
143 return {};
144 }
145
146 return pt;
147}
static G2Projective from_affine(const G2Affine &affine)
static Pt mul_by_z_abs(const Pt &pt)

References deserialize(), Botan::BLS12_381::G2Projective::from_affine(), and Botan::BLS12_381::PointMul< Pt >::mul_by_z_abs().

Referenced by deserialize().

◆ generator()

G2Affine Botan::BLS12_381::G2Affine::generator ( )
static

Return the G2 standard group generator

Definition at line 105 of file bls12_381_g2.cpp.

105 {
106 return G2Affine(G2_X, G2_Y, 0);
107}

References generator().

Referenced by generator().

◆ identity()

G2Affine Botan::BLS12_381::G2Affine::identity ( )
static

Return the G2 identity element

Definition at line 100 of file bls12_381_g2.cpp.

100 {
101 return G2Affine(FieldElement2::zero(), FieldElement2::one(), 1);
102}

References identity(), Botan::BLS12_381::FieldElement2::one(), and Botan::BLS12_381::FieldElement2::zero().

Referenced by identity().

◆ is_identity()

bool Botan::BLS12_381::G2Affine::is_identity ( ) const

Check if this point is the identity element

Definition at line 117 of file bls12_381_g2.cpp.

117 {
118 return m_infinity != 0;
119}

References is_identity().

Referenced by is_identity(), and Botan::BLS12_381::Gt::pairing().

◆ serialize()

std::array< uint8_t, G2Affine::BYTES > Botan::BLS12_381::G2Affine::serialize ( ) const

Point serialization

Only compressed point encoding is supported.

Definition at line 149 of file bls12_381_g2.cpp.

149 {
150 return G2Ops::serialize(*this);
151}

References serialize().

Referenced by serialize().

◆ G2Projective

friend class G2Projective
friend

Definition at line 436 of file bls12_381.h.

References G2Projective.

Referenced by G2Projective.

◆ GroupOps

template<typename Group>
friend class GroupOps
friend

Definition at line 439 of file bls12_381.h.

References GroupOps.

Referenced by GroupOps.

Member Data Documentation

◆ BYTES

size_t Botan::BLS12_381::G2Affine::BYTES = 96
staticconstexpr

The byte length of the compressed point encoding

Definition at line 390 of file bls12_381.h.


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