18#ifdef PROFILE_OP_COUNTS
19long long mnt4_G1::add_cnt = 0;
20long long mnt4_G1::dbl_cnt = 0;
50 copy.to_affine_coordinates();
51 gmp_printf(
"(%Nd , %Nd)\n",
65 gmp_printf(
"(%Nd : %Nd : %Nd)\n",
83 this->
X = this->
X * Z_inv;
84 this->
Y = this->
Y * Z_inv;
101 return (this->
X.is_zero() && this->Z.is_zero());
119 if ((this->
X * other.Z) != (other.X * this->Z))
125 if ((this->
Y * other.
Z) != (other.Y * this->Z))
168 const mnt4_Fq X1Z2 = (this->
X) * (other.
Z);
169 const mnt4_Fq X2Z1 = (this->
Z) * (other.
X);
173 const mnt4_Fq Y1Z2 = (this->
Y) * (other.
Z);
174 const mnt4_Fq Y2Z1 = (this->
Z) * (other.
Y);
176 if (X1Z2 == X2Z1 && Y1Z2 == Y2Z1)
179 const mnt4_Fq XX = (this->
X).squared();
180 const mnt4_Fq ZZ = (this->
Z).squared();
182 const mnt4_Fq Y1Z1 = (this->
Y) * (this->
Z);
188 const mnt4_Fq B = ((this->
X)+
R).squared()-XX-RR;
191 const mnt4_Fq Y3 = w * (
B-h)-(RR+RR);
198 const mnt4_Fq Z1Z2 = (this->
Z) * (other.
Z);
207 const mnt4_Fq Y3 = u * (
R-
A) - vvv * Y1Z2;
221 return (*
this) + (-other);
241 if (this->
operator==(other))
246#ifdef PROFILE_OP_COUNTS
252 const mnt4_Fq Y1Z2 = (this->
Y) * (other.
Z);
253 const mnt4_Fq X1Z2 = (this->
X) * (other.
Z);
254 const mnt4_Fq Z1Z2 = (this->
Z) * (other.
Z);
255 const mnt4_Fq u = (other.Y) * (this->
Z) - Y1Z2;
257 const mnt4_Fq v = (other.X) * (this->
Z) - X1Z2;
263 const mnt4_Fq Y3 = u * (
R-
A) - vvv * Y1Z2;
271#ifdef PROFILE_OP_COUNTS
289 assert(other.is_special());
293 const mnt4_Fq X2Z1 = (this->
Z) * (other.
X);
298 const mnt4_Fq Y2Z1 = (this->
Z) * (other.
Y);
300 if (X1Z2 == X2Z1 && Y1Z2 == Y2Z1)
313 const mnt4_Fq Y3 = u*(
R-
A) - vvv * this->Y;
321#ifdef PROFILE_OP_COUNTS
333 const mnt4_Fq XX = (this->
X).squared();
334 const mnt4_Fq ZZ = (this->
Z).squared();
336 const mnt4_Fq Y1Z1 = (this->
Y) * (this->
Z);
342 const mnt4_Fq B = ((this->
X)+
R).squared()-XX-RR;
345 const mnt4_Fq Y3 = w * (
B-h)-(RR+RR);
370 const mnt4_Fq X2 = this->
X.squared();
396 copy.to_affine_coordinates();
399#ifdef NO_PT_COMPRESSION
414#ifdef NO_PT_COMPRESSION
415 in >> is_zero >> tX >> tY;
418 in.read((
char*)&is_zero, 1);
425 in.read((
char*)&Y_lsb, 1);
435 if ((tY.
as_bigint().data[0] & 1) != Y_lsb)
456std::ostream&
operator<<(std::ostream& out,
const std::vector<mnt4_G1> &v)
458 out << v.size() <<
"\n";
467std::istream&
operator>>(std::istream& in, std::vector<mnt4_G1> &v)
478 for (
size_t i = 0; i <
s; ++i)
491 std::vector<mnt4_Fq> Z_vec;
492 Z_vec.reserve(vec.size());
496 Z_vec.emplace_back(el.Z);
502 for (
size_t i = 0; i < vec.size(); ++i)
504 vec[i] =
mnt4_G1(vec[i].
X * Z_vec[i], vec[i].
Y * Z_vec[i],
one);
static Fp_model< n, modulus > zero()
static Fp_model< n, modulus > one()
static const mp_size_t num_limbs
bigint< n > as_bigint() const
static Fp_model< n, modulus > random_element()
static std::vector< size_t > wnaf_window_table
static mnt4_G1 random_element()
mnt4_G1 operator+(const mnt4_G1 &other) const
mnt4_G1 operator-() const
void to_affine_coordinates()
bool operator!=(const mnt4_G1 &other) const
void print_coordinates() const
static std::vector< size_t > fixed_base_exp_window_table
bool is_well_formed() const
mnt4_G1 add(const mnt4_G1 &other) const
mnt4_G1 mixed_add(const mnt4_G1 &other) const
static void batch_to_special_all_non_zeros(std::vector< mnt4_G1 > &vec)
bool operator==(const mnt4_G1 &other) const
Fp_model< mnt4_q_limbs, mnt4_modulus_q > mnt4_Fq
void consume_OUTPUT_NEWLINE(std::istream &in)
std::istream & operator>>(std::istream &in, alt_bn128_G1 &g)
void consume_OUTPUT_SEPARATOR(std::istream &in)
std::ostream & operator<<(std::ostream &out, const alt_bn128_G1 &g)
void consume_newline(std::istream &in)
void batch_invert(std::vector< FieldT > &vec)