Clearmatics Libff
0.1
C++ library for Finite Fields and Elliptic Curves
|
Go to the documentation of this file.
13 static const uint8_t G1_ZERO_FLAG = 1 << 0;
14 static const uint8_t G1_Y_LSB_FLAG = 1 << 1;
16 #ifdef PROFILE_OP_COUNTS
17 long long alt_bn128_G1::add_cnt = 0;
18 long long alt_bn128_G1::dbl_cnt = 0;
58 "(%Nd : %Nd : %Nd)\n",
61 this->Y.as_bigint().data,
63 this->Z.as_bigint().data,
78 this->
X = this->
X * Z2_inv;
79 this->
Y = this->
Y * Z3_inv;
115 if ((this->
X * Z2_squared) != (other.
X * Z1_squared)) {
122 if ((this->
Y * Z2_cubed) != (other.
Y * Z1_cubed)) {
146 return (*
this) + (-other);
164 if (this->
operator==(other)) {
168 #ifdef PROFILE_OP_COUNTS
203 const alt_bn128_Fq Z3 = ((this->
Z + other.
Z).squared() - Z1Z1 - Z2Z2) * H;
249 if (U1 == U2 && S1 == S2) {
254 #ifdef PROFILE_OP_COUNTS
278 Y3 = r * (V - X3) - Y3 - Y3;
287 #ifdef PROFILE_OP_COUNTS
317 eightC = eightC + eightC;
318 eightC = eightC + eightC;
380 out.write(&
is_zero, 1) << copy.
X << copy.
Y;
388 const uint8_t flags =
389 (copy.
is_zero() ? G1_ZERO_FLAG : 0) |
390 ((copy.
Y.
as_bigint().data[0] & 1) ? G1_Y_LSB_FLAG : 0);
391 const char flags_char =
'0' + flags;
392 out.write(&flags_char, 1) << copy.
X;
399 in.read(&is_zero_char, 1) >> out.
X >> out.
Y;
400 const uint8_t
is_zero = (is_zero_char -
'0') & G1_ZERO_FLAG;
413 in.read(&flags_char, 1) >> out.
X;
416 const uint8_t flags = flags_char -
'0';
419 if (0 == (flags & G1_ZERO_FLAG)) {
421 const uint8_t Y_lsb = 0 != (flags & G1_Y_LSB_FLAG);
426 if ((uint8_t)(out.
Y.
as_bigint().data[0] & 1) != Y_lsb) {
438 #ifdef NO_PT_COMPRESSION
448 #ifdef NO_PT_COMPRESSION
457 std::vector<alt_bn128_G1> &vec)
459 std::vector<alt_bn128_Fq> Z_vec;
460 Z_vec.reserve(vec.size());
462 for (
auto &el : vec) {
463 Z_vec.emplace_back(el.Z);
465 batch_invert<alt_bn128_Fq>(Z_vec);
469 for (
size_t i = 0; i < vec.size(); ++i) {
473 vec[i].X = vec[i].X * Z2;
474 vec[i].Y = vec[i].Y * Z3;
bool is_in_safe_subgroup() const
static Fp_model< n, modulus > random_element()
returns random element of Fp_model
void to_affine_coordinates()
alt_bn128_G1 mul_by_cofactor() const
static const Fp_model< n, modulus > & zero()
void write_compressed(std::ostream &) const
std::istream & operator>>(std::istream &in, alt_bn128_G1 &g)
static alt_bn128_Fq coeff_b
static void read_compressed(std::istream &, alt_bn128_G1 &)
void write_uncompressed(std::ostream &) const
bool operator!=(const alt_bn128_G1 &other) const
static alt_bn128_G1 G1_zero
Fp_model sqrt() const
HAS TO BE A SQUARE (else does not terminate)
static const Fp_model< n, modulus > & one()
bool operator==(const alt_bn128_G1 &other) const
void consume_OUTPUT_SEPARATOR(std::istream &in)
static alt_bn128_G1 G1_one
static const mp_size_t num_limbs
alt_bn128_G1 operator+(const alt_bn128_G1 &other) const
static bigint< h_limbs > h
alt_bn128_G1 add(const alt_bn128_G1 &other) const
alt_bn128_G1 operator-() const
static alt_bn128_G1 random_element()
static std::vector< size_t > fixed_base_exp_window_table
Fp_model< alt_bn128_q_limbs, alt_bn128_modulus_q > alt_bn128_Fq
static alt_bn128_Fq coeff_a
void print_coordinates() const
bigint< n > as_bigint() const
static void batch_to_special_all_non_zeros(std::vector< alt_bn128_G1 > &vec)
static const alt_bn128_G1 & one()
std::ostream & operator<<(std::ostream &out, const alt_bn128_G1 &g)
static const alt_bn128_G1 & zero()
static std::vector< size_t > wnaf_window_table
bool is_well_formed() const
static void read_uncompressed(std::istream &, alt_bn128_G1 &)
alt_bn128_G1 mixed_add(const alt_bn128_G1 &other) const
alt_bn128_Fq alt_bn128_coeff_b