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

#include <bls12_381.h>

Public Member Functions

G2Projective add (const G2Projective &other) const
G2Projective add_mixed (const G2Affine &other) const
 G2Projective ()
bool is_identity () const
G2Projective mul (const Scalar &scalar) const
G2Projective negate () const
G2Affine to_affine () const

Static Public Member Functions

static G2Projective _unchecked_from_affine_coords (const FieldElement2 &x, const FieldElement2 &y)
static G2Projective from_affine (const G2Affine &affine)
static G2Projective generator ()
static G2Projective hash_to_curve_nu (std::span< const uint8_t > input, std::span< const uint8_t > dst)
static G2Projective hash_to_curve_ro (std::span< const uint8_t > input, std::span< const uint8_t > dst)
static G2Projective identity ()
static G2Projective msm_vartime (std::span< const G2Affine > points, std::span< const Scalar > scalars)
static G2Projective mul2 (const G2Projective &p, const Scalar &a, const G2Projective &q, const Scalar &b)
static G2Projective mul2_vartime (const G2Projective &p, const Scalar &a, const G2Projective &q, const Scalar &b)
static std::vector< G2Affine > to_affine_batch (std::span< const G2Projective > points)

Friends

class G2Affine
template<typename Group>
class GroupOps
template<typename Pt>
class PointMul

Detailed Description

An element of the group G2, in projective form

Definition at line 453 of file bls12_381.h.

Constructor & Destructor Documentation

◆ G2Projective()

Botan::BLS12_381::G2Projective::G2Projective ( )

Default constructed as the identity element

Definition at line 156 of file bls12_381_g2.cpp.

156: m_x({}), m_y(fe2_store(FieldElement2::one())), m_z({}) {}

Referenced by _unchecked_from_affine_coords(), add(), add_mixed(), from_affine(), generator(), hash_to_curve_nu(), hash_to_curve_ro(), identity(), msm_vartime(), mul(), mul2(), mul2_vartime(), and negate().

Member Function Documentation

◆ _unchecked_from_affine_coords()

G2Projective Botan::BLS12_381::G2Projective::_unchecked_from_affine_coords ( const FieldElement2 & x,
const FieldElement2 & y )
static

The input is assumed to be a point on the curve, though possibly outside the prime order subgroup.

Reserved for internal use, not covered by SemVer.

Definition at line 164 of file bls12_381_g2.cpp.

References G2Projective(), and Botan::BLS12_381::FieldElement2::one().

◆ add()

G2Projective Botan::BLS12_381::G2Projective::add ( const G2Projective & other) const

Return the sum of this point and other

Definition at line 198 of file bls12_381_g2.cpp.

198 {
199 return G2Ops::add(*this, other);
200}

References G2Projective().

◆ add_mixed()

G2Projective Botan::BLS12_381::G2Projective::add_mixed ( const G2Affine & other) const

Return the sum of this point and an affine point

Definition at line 202 of file bls12_381_g2.cpp.

202 {
203 return G2Ops::add_mixed(*this, other, false);
204}

References G2Affine, and G2Projective().

◆ from_affine()

G2Projective Botan::BLS12_381::G2Projective::from_affine ( const G2Affine & affine)
static

Convert an affine point to projective form

Definition at line 159 of file bls12_381_g2.cpp.

159 {
160 return G2Ops::from_affine(affine);
161}

References G2Affine, and G2Projective().

Referenced by Botan::BLS12_381::G2Affine::deserialize().

◆ generator()

G2Projective Botan::BLS12_381::G2Projective::generator ( )
static

Return the G2 standard group generator

Definition at line 169 of file bls12_381_g2.cpp.

169 {
170 return G2Projective(G2_X, G2_Y, FieldElement2::one());
171}

References G2Projective(), and Botan::BLS12_381::FieldElement2::one().

◆ hash_to_curve_nu()

G2Projective Botan::BLS12_381::G2Projective::hash_to_curve_nu ( std::span< const uint8_t > input,
std::span< const uint8_t > dst )
static

Nonuniform encoding to curve (RFC 9380 encode_to_curve), suite BLS12381G2_XMD:SHA-256_SSWU_NU_

Throws Invalid_Argument if dst is empty.

Definition at line 561 of file bls12_381_h2c.cpp.

561 {
562 const auto uniform = bls_expand_message<2 * H2C_L>(input, dst);
563 CT::poison(uniform);
564
565 const auto u = FieldElement2(fe_from_uniform(std::span{uniform}.first<H2C_L>()),
566 fe_from_uniform(std::span{uniform}.last<H2C_L>()));
567
568 const auto make_pt = [](const FieldElement2& x, const FieldElement2& y, const FieldElement2& z) {
569 return G2Projective(x, y, z);
570 };
571
572 const auto pt = map_to_curve_g2(u, make_pt).clear_cofactor();
573 CT::unpoison_all(uniform, pt.m_x, pt.m_y, pt.m_z);
574
575 return pt;
576}
constexpr void unpoison_all(const Ts &... ts)
Definition ct_utils.h:207
constexpr void poison(const T *p, size_t n)
Definition ct_utils.h:56

References G2Projective(), Botan::CT::poison(), and Botan::CT::unpoison_all().

◆ hash_to_curve_ro()

G2Projective Botan::BLS12_381::G2Projective::hash_to_curve_ro ( std::span< const uint8_t > input,
std::span< const uint8_t > dst )
static

Hash to curve (RFC 9380), suite BLS12381G2_XMD:SHA-256_SSWU_RO_

Throws Invalid_Argument if dst is empty.

Definition at line 538 of file bls12_381_h2c.cpp.

538 {
539 const auto uniform = bls_expand_message<4 * H2C_L>(input, dst);
540 CT::poison(uniform);
541
542 const auto us = std::span{uniform};
543 const auto u0 = FieldElement2(fe_from_uniform(us.subspan(0, H2C_L)), fe_from_uniform(us.subspan(H2C_L, H2C_L)));
544 const auto u1 =
545 FieldElement2(fe_from_uniform(us.subspan(2 * H2C_L, H2C_L)), fe_from_uniform(us.subspan(3 * H2C_L, H2C_L)));
546
547 const auto make_pt = [](const FieldElement2& x, const FieldElement2& y, const FieldElement2& z) {
548 return G2Projective(x, y, z);
549 };
550
551 const auto q0 = map_to_curve_g2(u0, make_pt);
552 const auto q1 = map_to_curve_g2(u1, make_pt);
553
554 const auto pt = q0.add(q1).clear_cofactor();
555 CT::unpoison_all(uniform, pt.m_x, pt.m_y, pt.m_z);
556
557 return pt;
558}

References G2Projective(), Botan::CT::poison(), and Botan::CT::unpoison_all().

◆ identity()

G2Projective Botan::BLS12_381::G2Projective::identity ( )
inlinestatic

Return the G2 identity element

Definition at line 464 of file bls12_381.h.

464{ return G2Projective(); }

References G2Projective().

◆ is_identity()

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

Check if this point is the identity element

Definition at line 190 of file bls12_381_g2.cpp.

190 {
191 return CT::all_zeros(m_z.data(), m_z.size()).as_bool();
192}
constexpr CT::Mask< T > all_zeros(const T elem[], size_t len)
Definition ct_utils.h:790

References Botan::CT::all_zeros().

◆ msm_vartime()

G2Projective Botan::BLS12_381::G2Projective::msm_vartime ( std::span< const G2Affine > points,
std::span< const Scalar > scalars )
static

Multiscalar multiplication, the sum of scalars[i]*points[i]

The empty sum is the identity element. Throws Invalid_Argument if the spans are of unequal length.

Warning: this function runs in variable time and must be used only with public inputs, such as signature verification. Use mul() with secret scalars.

Definition at line 228 of file bls12_381_g2.cpp.

228 {
229 return PointMul<G2Projective>::msm_vartime(points, scalars);
230}
static Pt msm_vartime(std::span< const AffinePt > points, std::span< const Scalar > scalars)

References G2Projective(), and Botan::BLS12_381::PointMul< Pt >::msm_vartime().

◆ mul()

G2Projective Botan::BLS12_381::G2Projective::mul ( const Scalar & scalar) const

Scalar multiplication

Constant time; safe for secret scalars

Definition at line 210 of file bls12_381_g2.cpp.

210 {
211 return PointMul<G2Projective>::mul(*this, scalar);
212}
static Pt mul(const Pt &pt, const Scalar &scalar)

References G2Projective(), and Botan::BLS12_381::PointMul< Pt >::mul().

◆ mul2()

G2Projective Botan::BLS12_381::G2Projective::mul2 ( const G2Projective & p,
const Scalar & a,
const G2Projective & q,
const Scalar & b )
static

Compute a*p + b*q in constant time

Faster than composing mul() and add(), and safe for secret scalars, as arise for example in Pedersen commitments.

Definition at line 215 of file bls12_381_g2.cpp.

215 {
216 return PointMul<G2Projective>::mul2(p, a, q, b);
217}
static Pt mul2(const Pt &p, const Scalar &a, const Pt &q, const Scalar &b)

References G2Projective(), and Botan::BLS12_381::PointMul< Pt >::mul2().

◆ mul2_vartime()

G2Projective Botan::BLS12_381::G2Projective::mul2_vartime ( const G2Projective & p,
const Scalar & a,
const G2Projective & q,
const Scalar & b )
static

Compute a*p + b*q

Warning: this function runs in variable time and must be used only with public inputs, such as signature verification. Use mul2() with secret scalars.

Definition at line 220 of file bls12_381_g2.cpp.

223 {
224 return PointMul<G2Projective>::mul2_vartime(p, a, q, b);
225}
static Pt mul2_vartime(const Pt &p, const Scalar &a, const Pt &q, const Scalar &b)

References G2Projective(), and Botan::BLS12_381::PointMul< Pt >::mul2_vartime().

◆ negate()

G2Projective Botan::BLS12_381::G2Projective::negate ( ) const

Return the negation of this point

Definition at line 182 of file bls12_381_g2.cpp.

182 {
183 return G2Ops::negate(*this);
184}

References G2Projective().

◆ to_affine()

G2Affine Botan::BLS12_381::G2Projective::to_affine ( ) const

Convert to affine form, at the cost of a field inversion

Definition at line 173 of file bls12_381_g2.cpp.

173 {
174 return G2Ops::to_affine(*this);
175}

References G2Affine.

◆ to_affine_batch()

std::vector< G2Affine > Botan::BLS12_381::G2Projective::to_affine_batch ( std::span< const G2Projective > points)
static

Convert a batch of points to affine

Equivalent to calling to_affine on each point, but much faster, since a single field inversion is shared across the batch.

Definition at line 178 of file bls12_381_g2.cpp.

178 {
179 return G2Ops::to_affine_batch(points);
180}

◆ G2Affine

friend class G2Affine
friend

Definition at line 572 of file bls12_381.h.

References G2Affine.

Referenced by add_mixed(), from_affine(), G2Affine, and to_affine().

◆ GroupOps

template<typename Group>
friend class GroupOps
friend

Definition at line 578 of file bls12_381.h.

References GroupOps.

Referenced by GroupOps.

◆ PointMul

template<typename Pt>
friend class PointMul
friend

Definition at line 575 of file bls12_381.h.

References PointMul.

Referenced by PointMul.


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