7#include <botan/bls12_381.h>
9#include <botan/internal/bls12_381_fields.h>
10#include <botan/internal/bls12_381_group.h>
11#include <botan/internal/bls12_381_point_mul.h>
12#include <botan/internal/ct_utils.h>
13#include <botan/internal/mp_core.h>
21 "120177419e0bfb75edce6ecc21dbf440f0ae6acdf3d0e747154f95c7143ba1c17817fc679976fff55cb38790fd530c16"));
24 "0bbc3efc5008a26a0e1c8c3fad0059c051ac582950405194dd595f13570725ce8c22631a7918fd8ebaac93d50ce72271"));
28 "051ba4ab241b61603636b76660701c6ec26a2ff874fd029b16a8ca3ac61577f7f3b8ddab7ece5a2a30f1361b798a64e8"));
34 using Affine = G1Affine;
35 using Projective = G1Projective;
36 using FE = FieldElement;
40 static std::array<word, FieldElement::N> store(
const FE& v) {
return v._words(); }
42 static FE mul_by_3b(
const FE& fe) {
44 const auto fe2 = fe + fe;
45 const auto fe4 = fe2 + fe2;
46 return fe4 + fe4 + fe4;
57 m_x(x._words()), m_y(y._words()), m_infinity(infinity) {}
66 return G1Affine(G1_X, G1_Y, 0);
70 return G1Group::load(m_x);
74 return G1Group::load(m_y);
78 return m_infinity != 0;
83 auto pt = G1Ops::deserialize_unchecked(bytes);
84 if(!pt || pt->is_identity()) {
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()) {
107 return G1Ops::serialize(*
this);
111 m_x(x._words()), m_y(y._words()), m_z(z._words()) {}
117 return G1Ops::from_affine(affine);
131 return G1Ops::to_affine(*
this);
136 return G1Ops::to_affine_batch(points);
140 return G1Ops::negate(*
this);
143void G1Projective::conditional_negate(uint32_t negate) {
144 G1Ops::conditional_negate(*
this,
negate);
152 return G1Ops::dbl(*
this);
156 return G1Ops::add(*
this, other);
160 return G1Ops::add_mixed(*
this, other,
false);
164 return G1Ops::add_mixed(*
this, other, negate_other);
static constexpr FieldElement _unchecked_from_words(std::array< word, FieldElement::N > v)
static FieldElement one()
static FieldElement from_u32(uint32_t v)
static FieldElement zero()
static G1Affine identity()
static std::optional< G1Affine > deserialize(std::span< const uint8_t > bytes)
std::array< uint8_t, G1Affine::BYTES > serialize() const
static G1Affine generator()
G1Projective mul(const Scalar &scalar) const
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)
static G1Projective mul2(const G1Projective &p, const Scalar &a, const G1Projective &q, const Scalar &b)
static G1Projective generator()
G1Projective add_mixed(const G1Affine &other) const
G1Projective add(const G1Projective &other) const
static G1Projective from_affine(const G1Affine &affine)
G1Projective negate() const
static G1Projective msm_vartime(std::span< const G1Affine > points, std::span< const Scalar > scalars)
static G1Projective _unchecked_from_affine_coords(const FieldElement &x, const FieldElement &y)
G1Affine to_affine() const
static Pt mul2_vartime(const Pt &p, const Scalar &a, const Pt &q, const Scalar &b)
static Pt msm_vartime(std::span< const AffinePt > points, std::span< const Scalar > scalars)
static Pt mul2(const Pt &p, const Scalar &a, const Pt &q, const Scalar &b)
static Pt mul(const Pt &pt, const Scalar &scalar)
constexpr CT::Mask< T > all_zeros(const T elem[], size_t len)
constexpr auto hex_to_words(const char(&s)[N])