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

#include <bls12_381.h>

Public Member Functions

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

Static Public Member Functions

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

Static Public Attributes

static constexpr size_t BYTES = 48

Friends

class G1Projective
template<typename Group>
class GroupOps

Detailed Description

An element of the group G1, in affine form

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

Definition at line 192 of file bls12_381.h.

Member Function Documentation

◆ _x()

FieldElement Botan::BLS12_381::G1Affine::_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 69 of file bls12_381_g1.cpp.

69 {
70 return G1Group::load(m_x);
71}

References _x().

Referenced by _x().

◆ _y()

FieldElement Botan::BLS12_381::G1Affine::_y ( ) const

Definition at line 73 of file bls12_381_g1.cpp.

73 {
74 return G1Group::load(m_y);
75}

References _y().

Referenced by _y().

◆ deserialize()

std::optional< G1Affine > Botan::BLS12_381::G1Affine::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 public keys) must check is_identity() themselves.

Definition at line 82 of file bls12_381_g1.cpp.

82 {
83 auto pt = G1Ops::deserialize_unchecked(bytes);
84 if(!pt || pt->is_identity()) {
85 return pt;
86 }
87
88 // Fast subgroup check (https://eprint.iacr.org/2021/1130 section 6):
89 // P is in the prime order subgroup iff phi(P) == -[z^2]P, where
90 // phi(x, y) = (beta*x, y); per the paper, "if the endomorphism is
91 // true, then P must be of order r"
92 using Mul = PointMul<G1Projective>;
93 const auto zz_p = Mul::mul_by_z_abs(Mul::mul_by_z_abs(G1Projective::from_affine(*pt))).negate();
94
95 // Compare the projective -[z^2]P with the affine phi(P)
96 const auto zz_p_z = G1Group::load(zz_p.m_z);
97 const auto x_eq = (G1Group::load(zz_p.m_x) == (pt->_x() * G1_BETA) * zz_p_z);
98 const auto y_eq = (G1Group::load(zz_p.m_y) == pt->_y() * zz_p_z);
99 if(!(x_eq && y_eq).as_bool()) {
100 return {};
101 }
102
103 return pt;
104}
static G1Projective from_affine(const G1Affine &affine)

References deserialize(), and Botan::BLS12_381::G1Projective::from_affine().

Referenced by deserialize().

◆ generator()

G1Affine Botan::BLS12_381::G1Affine::generator ( )
static

Return the G1 standard group generator

Definition at line 65 of file bls12_381_g1.cpp.

65 {
66 return G1Affine(G1_X, G1_Y, 0);
67}

References generator().

Referenced by generator().

◆ identity()

G1Affine Botan::BLS12_381::G1Affine::identity ( )
static

Return the G1 identity element

Definition at line 60 of file bls12_381_g1.cpp.

60 {
61 return G1Affine(FieldElement::zero(), FieldElement::one(), 1);
62}
static FieldElement one()

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

Referenced by identity().

◆ is_identity()

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

Check if this point is the identity element

Definition at line 77 of file bls12_381_g1.cpp.

77 {
78 return m_infinity != 0;
79}

References is_identity().

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

◆ serialize()

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

Point serialization

Only compressed point encoding is supported.

Definition at line 106 of file bls12_381_g1.cpp.

106 {
107 return G1Ops::serialize(*this);
108}

References serialize().

Referenced by serialize().

◆ G1Projective

friend class G1Projective
friend

Definition at line 241 of file bls12_381.h.

References G1Projective.

Referenced by G1Projective.

◆ GroupOps

template<typename Group>
friend class GroupOps
friend

Definition at line 244 of file bls12_381.h.

References GroupOps.

Referenced by GroupOps.

Member Data Documentation

◆ BYTES

size_t Botan::BLS12_381::G1Affine::BYTES = 48
staticconstexpr

The byte length of the compressed point encoding

Definition at line 195 of file bls12_381.h.


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