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

#include <bls12_381.h>

Public Member Functions

G1Projective add (const G1Projective &other) const
G1Projective add_mixed (const G1Affine &other) const
 G1Projective ()
bool is_identity () const
G1Projective mul (const Scalar &scalar) const
G1Projective negate () const
G1Affine to_affine () const

Static Public Member Functions

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

Friends

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

Detailed Description

An element of the group G1, in projective form

Definition at line 258 of file bls12_381.h.

Constructor & Destructor Documentation

◆ G1Projective()

Botan::BLS12_381::G1Projective::G1Projective ( )

Default constructed as the identity element

Definition at line 113 of file bls12_381_g1.cpp.

113: m_x({}), m_y(FieldElement::one()._words()), m_z({}) {}
static FieldElement one()

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()

G1Projective Botan::BLS12_381::G1Projective::_unchecked_from_affine_coords ( const FieldElement & x,
const FieldElement & 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 121 of file bls12_381_g1.cpp.

References G1Projective(), and Botan::BLS12_381::FieldElement::one().

◆ add()

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

Return the sum of this point and other

Definition at line 155 of file bls12_381_g1.cpp.

155 {
156 return G1Ops::add(*this, other);
157}

References G1Projective().

◆ add_mixed()

G1Projective Botan::BLS12_381::G1Projective::add_mixed ( const G1Affine & other) const

Return the sum of this point and an affine point

Definition at line 159 of file bls12_381_g1.cpp.

159 {
160 return G1Ops::add_mixed(*this, other, false);
161}

References G1Affine, and G1Projective().

◆ from_affine()

G1Projective Botan::BLS12_381::G1Projective::from_affine ( const G1Affine & affine)
static

Convert an affine point to projective form

Definition at line 116 of file bls12_381_g1.cpp.

116 {
117 return G1Ops::from_affine(affine);
118}

References G1Affine, and G1Projective().

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

◆ generator()

G1Projective Botan::BLS12_381::G1Projective::generator ( )
static

Return the G1 standard group generator

Definition at line 126 of file bls12_381_g1.cpp.

126 {
127 return G1Projective(G1_X, G1_Y, FieldElement::one());
128}

References G1Projective(), and Botan::BLS12_381::FieldElement::one().

◆ hash_to_curve_nu()

G1Projective Botan::BLS12_381::G1Projective::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 BLS12381G1_XMD:SHA-256_SSWU_NU_

Throws Invalid_Argument if dst is empty.

Definition at line 523 of file bls12_381_h2c.cpp.

523 {
524 const auto uniform = bls_expand_message<H2C_L>(input, dst);
525 CT::poison(uniform);
526
527 const auto make_pt = [](const FieldElement& x, const FieldElement& y, const FieldElement& z) {
528 return G1Projective(x, y, z);
529 };
530
531 const auto pt = clear_cofactor_g1(map_to_curve_g1(fe_from_uniform(uniform), make_pt));
532 CT::unpoison_all(uniform, pt.m_x, pt.m_y, pt.m_z);
533
534 return pt;
535}
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 G1Projective(), Botan::CT::poison(), and Botan::CT::unpoison_all().

◆ hash_to_curve_ro()

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

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

Throws Invalid_Argument if dst is empty.

Definition at line 502 of file bls12_381_h2c.cpp.

502 {
503 const auto uniform = bls_expand_message<2 * H2C_L>(input, dst);
504 CT::poison(uniform);
505
506 const auto u0 = fe_from_uniform(std::span{uniform}.first<H2C_L>());
507 const auto u1 = fe_from_uniform(std::span{uniform}.last<H2C_L>());
508
509 const auto make_pt = [](const FieldElement& x, const FieldElement& y, const FieldElement& z) {
510 return G1Projective(x, y, z);
511 };
512
513 const auto q0 = map_to_curve_g1(u0, make_pt);
514 const auto q1 = map_to_curve_g1(u1, make_pt);
515
516 const auto pt = clear_cofactor_g1(q0.add(q1));
517 CT::unpoison_all(uniform, pt.m_x, pt.m_y, pt.m_z);
518
519 return pt;
520}

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

◆ identity()

G1Projective Botan::BLS12_381::G1Projective::identity ( )
inlinestatic

Return the G1 identity element

Definition at line 269 of file bls12_381.h.

269{ return G1Projective(); }

References G1Projective().

◆ is_identity()

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

Check if this point is the identity element

Definition at line 147 of file bls12_381_g1.cpp.

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

References Botan::CT::all_zeros().

◆ msm_vartime()

G1Projective Botan::BLS12_381::G1Projective::msm_vartime ( std::span< const G1Affine > 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 185 of file bls12_381_g1.cpp.

185 {
186 return PointMul<G1Projective>::msm_vartime(points, scalars);
187}
static Pt msm_vartime(std::span< const AffinePt > points, std::span< const Scalar > scalars)

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

◆ mul()

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

Scalar multiplication

Constant time; safe for secret scalars

Definition at line 167 of file bls12_381_g1.cpp.

167 {
168 return PointMul<G1Projective>::mul(*this, scalar);
169}
static Pt mul(const Pt &pt, const Scalar &scalar)

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

◆ mul2()

G1Projective Botan::BLS12_381::G1Projective::mul2 ( const G1Projective & p,
const Scalar & a,
const G1Projective & 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 172 of file bls12_381_g1.cpp.

172 {
173 return PointMul<G1Projective>::mul2(p, a, q, b);
174}
static Pt mul2(const Pt &p, const Scalar &a, const Pt &q, const Scalar &b)

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

◆ mul2_vartime()

G1Projective Botan::BLS12_381::G1Projective::mul2_vartime ( const G1Projective & p,
const Scalar & a,
const G1Projective & 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 177 of file bls12_381_g1.cpp.

180 {
181 return PointMul<G1Projective>::mul2_vartime(p, a, q, b);
182}
static Pt mul2_vartime(const Pt &p, const Scalar &a, const Pt &q, const Scalar &b)

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

◆ negate()

G1Projective Botan::BLS12_381::G1Projective::negate ( ) const

Return the negation of this point

Definition at line 139 of file bls12_381_g1.cpp.

139 {
140 return G1Ops::negate(*this);
141}

References G1Projective().

◆ to_affine()

G1Affine Botan::BLS12_381::G1Projective::to_affine ( ) const

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

Definition at line 130 of file bls12_381_g1.cpp.

130 {
131 return G1Ops::to_affine(*this);
132}

References G1Affine.

◆ to_affine_batch()

std::vector< G1Affine > Botan::BLS12_381::G1Projective::to_affine_batch ( std::span< const G1Projective > 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 135 of file bls12_381_g1.cpp.

135 {
136 return G1Ops::to_affine_batch(points);
137}

◆ G1Affine

friend class G1Affine
friend

Definition at line 366 of file bls12_381.h.

References G1Affine.

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

◆ GroupOps

template<typename Group>
friend class GroupOps
friend

Definition at line 372 of file bls12_381.h.

References GroupOps.

Referenced by GroupOps.

◆ PointMul

template<typename Pt>
friend class PointMul
friend

Definition at line 369 of file bls12_381.h.

References PointMul.

Referenced by PointMul.


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