Clearmatics Libff
0.1
C++ library for Finite Fields and Elliptic Curves
|
Go to the documentation of this file.
13 static const uint8_t G2_ZERO_FLAG = 1 << 0;
14 static const uint8_t G2_Y_LSB_FLAG = 1 << 1;
16 #ifdef PROFILE_OP_COUNTS
17 long long alt_bn128_G2::add_cnt = 0;
18 long long alt_bn128_G2::dbl_cnt = 0;
51 "(%Nd*z + %Nd , %Nd*z + %Nd)\n",
69 "(%Nd*z + %Nd : %Nd*z + %Nd : %Nd*z + %Nd)\n",
72 this->X.coeffs[0].as_bigint().data,
74 this->Y.coeffs[1].as_bigint().data,
76 this->Y.coeffs[0].as_bigint().data,
78 this->Z.coeffs[1].as_bigint().data,
80 this->Z.coeffs[0].as_bigint().data,
95 this->
X = this->
X * Z2_inv;
96 this->
Y = this->
Y * Z3_inv;
132 if ((this->
X * Z2_squared) != (other.
X * Z1_squared)) {
139 if ((this->
Y * Z2_cubed) != (other.
Y * Z1_cubed)) {
163 return (*
this) + (-other);
203 if (U1 == U2 && S1 == S2) {
208 #ifdef PROFILE_OP_COUNTS
229 const alt_bn128_Fq2 Z3 = ((this->
Z + other.
Z).squared() - Z1Z1 - Z2Z2) * H;
275 if (U1 == U2 && S1 == S2) {
280 #ifdef PROFILE_OP_COUNTS
304 Y3 = r * (V - X3) - Y3 - Y3;
313 #ifdef PROFILE_OP_COUNTS
340 eightC = eightC + eightC;
341 eightC = eightC + eightC;
356 (this->
Z).Frobenius_map(1));
409 out.write(&
is_zero, 1) << copy.
X << copy.
Y;
418 const uint8_t flags =
419 (copy.
is_zero() ? G2_ZERO_FLAG : 0) |
421 const char flags_char =
'0' + flags;
422 out.write(&flags_char, 1) << copy.
X;
444 in.read(&flags_char, 1) >> g.
X;
445 const uint8_t flags = flags_char -
'0';
450 if (0 == (flags & G2_ZERO_FLAG)) {
451 const uint8_t Y_lsb = (flags & G2_Y_LSB_FLAG) ? 1 : 0;
468 #ifdef NO_PT_COMPRESSION
478 #ifdef NO_PT_COMPRESSION
487 std::vector<alt_bn128_G2> &vec)
489 std::vector<alt_bn128_Fq2> Z_vec;
490 Z_vec.reserve(vec.size());
492 for (
auto &el : vec) {
493 Z_vec.emplace_back(el.Z);
495 batch_invert<alt_bn128_Fq2>(Z_vec);
499 for (
size_t i = 0; i < vec.size(); ++i) {
503 vec[i].X = vec[i].X * Z2;
504 vec[i].Y = vec[i].Y * Z3;
static void read_uncompressed(std::istream &, alt_bn128_G2 &)
static void batch_to_special_all_non_zeros(std::vector< alt_bn128_G2 > &vec)
alt_bn128_Fq2 alt_bn128_twist_mul_by_q_Y
static const alt_bn128_G2 & one()
static Fp_model< n, modulus > random_element()
returns random element of Fp_model
bool operator==(const alt_bn128_G2 &other) const
alt_bn128_G2 operator+(const alt_bn128_G2 &other) const
static const Fp2_model< n, modulus > & one()
std::istream & operator>>(std::istream &in, alt_bn128_G1 &g)
static bigint< h_limbs > h
alt_bn128_G2 mul_by_q() const
alt_bn128_Fq2 alt_bn128_twist_coeff_b
alt_bn128_Fq2 alt_bn128_twist_mul_by_q_X
Fp2_model inverse() const
alt_bn128_G2 operator-() const
void write_uncompressed(std::ostream &) const
static std::vector< size_t > fixed_base_exp_window_table
alt_bn128_G2 mul_by_cofactor() const
static alt_bn128_G2 G2_zero
alt_bn128_Fq alt_bn128_twist_mul_by_b_c1
Fp2_model< alt_bn128_q_limbs, alt_bn128_modulus_q > alt_bn128_Fq2
alt_bn128_G2 add(const alt_bn128_G2 &other) const
static const mp_size_t num_limbs
static alt_bn128_Fq2 coeff_a
bool is_well_formed() const
bigint< n > as_bigint() const
std::ostream & operator<<(std::ostream &out, const alt_bn128_G1 &g)
void to_affine_coordinates()
static void read_compressed(std::istream &, alt_bn128_G2 &)
static const alt_bn128_G2 & zero()
Fp2_model squared() const
default is squared_complex
static std::vector< size_t > wnaf_window_table
alt_bn128_Fq alt_bn128_twist_mul_by_b_c0
static const constexpr bigint< n > & mod
Fp2_model sqrt() const
HAS TO BE A SQUARE (else does not terminate)
static alt_bn128_G2 G2_one
static const Fp2_model< n, modulus > & zero()
bool operator!=(const alt_bn128_G2 &other) const
static alt_bn128_Fq2 coeff_b
static alt_bn128_G2 random_element()
static alt_bn128_Fq2 mul_by_b(const alt_bn128_Fq2 &elt)
void write_compressed(std::ostream &) const
alt_bn128_G2 mixed_add(const alt_bn128_G2 &other) const
void print_coordinates() const
bool is_in_safe_subgroup() const