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

#include <bls12_381.h>

Public Member Functions

bool is_identity () const
bool operator== (const Gt &other) const
std::array< uint8_t, BYTES > serialize () const

Static Public Member Functions

static Gt identity ()
static Gt multi_pairing (std::span< const G1Affine > p, std::span< const G2Affine > q)
static Gt pairing (const G1Affine &p, const G2Affine &q)

Static Public Attributes

static constexpr size_t BYTES = 576

Detailed Description

An element of the pairing target group, a subgroup of Fp12*

Elements are members of the prime order subgroup by construction; there is no deserialization.

Definition at line 593 of file bls12_381.h.

Member Function Documentation

◆ identity()

Gt Botan::BLS12_381::Gt::identity ( )
static

Return the Gt identity element

Definition at line 238 of file bls12_381_pairing.cpp.

238 {
239 return Gt(Fp12::one());
240}

References identity(), and Botan::BLS12_381::Fp12::one().

Referenced by identity(), is_identity(), multi_pairing(), and pairing().

◆ is_identity()

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

Check if this element is the identity

Definition at line 242 of file bls12_381_pairing.cpp.

242 {
243 return (*this) == Gt::identity();
244}

References identity(), and is_identity().

Referenced by is_identity(), and multi_pairing().

◆ multi_pairing()

Gt Botan::BLS12_381::Gt::multi_pairing ( std::span< const G1Affine > p,
std::span< const G2Affine > q )
static

Compute the product of pairings prod_i e(p[i], q[i])

More efficient than computing each pairing individually, since the final exponentiation is shared. The empty product yields the identity.

Throws Invalid_Argument if the spans are of unequal length.

Definition at line 265 of file bls12_381_pairing.cpp.

265 {
266 if(p.size() != q.size()) {
267 throw Invalid_Argument("BLS12_381::multi_pairing spans must have equal length");
268 }
269
270 std::vector<PairingTerm> terms;
271 terms.reserve(p.size());
272
273 for(size_t i = 0; i != p.size(); ++i) {
274 // By bilinearity e(I,Q) = e(P,I) = I, contributing nothing to the product
275 if(p[i].is_identity() || q[i].is_identity()) {
276 continue;
277 }
278 terms.push_back(make_term(p[i], q[i]));
279 }
280
281 if(terms.empty()) {
282 return Gt::identity();
283 }
284
285 return Gt(final_exponentiation(multi_miller_loop(terms)));
286}

References identity(), is_identity(), and multi_pairing().

Referenced by multi_pairing().

◆ operator==()

bool Botan::BLS12_381::Gt::operator== ( const Gt & other) const

Constant time equality

Definition at line 246 of file bls12_381_pairing.cpp.

246 {
247 // The Montgomery representation of a reduced element is unique
248 return CT::is_equal(m_coeffs.data(), other.m_coeffs.data(), m_coeffs.size()).as_bool();
249}
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)
Definition ct_utils.h:803

References Botan::CT::is_equal(), and operator==().

Referenced by operator==().

◆ pairing()

Gt Botan::BLS12_381::Gt::pairing ( const G1Affine & p,
const G2Affine & q )
static

Compute the optimal ate pairing e(p, q)

Definition at line 255 of file bls12_381_pairing.cpp.

255 {
256 if(p.is_identity() || q.is_identity()) {
257 return Gt::identity();
258 }
259
260 std::array<PairingTerm, 1> terms = {make_term(p, q)};
261
262 return Gt(final_exponentiation(multi_miller_loop(terms)));
263}

References identity(), Botan::BLS12_381::G1Affine::is_identity(), Botan::BLS12_381::G2Affine::is_identity(), and pairing().

Referenced by pairing().

◆ serialize()

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

Serialization of the underlying Fp12 element; the coefficients are encoded in the order c0.c0.c0, c0.c0.c1, ..., c1.c2.c1 with each Fp coefficient as 48 big-endian bytes

Definition at line 251 of file bls12_381_pairing.cpp.

251 {
252 return this->_to_fp12().serialize();
253}

References serialize().

Referenced by serialize().

Member Data Documentation

◆ BYTES

size_t Botan::BLS12_381::Gt::BYTES = 576
staticconstexpr

The byte length of the Gt serialization

Definition at line 596 of file bls12_381.h.


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