Clearmatics Libff  0.1
C++ library for Finite Fields and Elliptic Curves
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
libff::bls12_377_G2 Class Reference

#include <bls12_377_g2.hpp>

Collaboration diagram for libff::bls12_377_G2:
Collaboration graph
[legend]

Public Types

typedef bls12_377_Fq base_field
 
typedef bls12_377_Fq2 twist_field
 
typedef bls12_377_Fr scalar_field
 

Public Member Functions

 bls12_377_G2 ()
 
 bls12_377_G2 (const bls12_377_Fq2 &X, const bls12_377_Fq2 &Y, const bls12_377_Fq2 &Z)
 
void print () const
 
void print_coordinates () const
 
void to_affine_coordinates ()
 
void to_special ()
 
bool is_special () const
 
bool is_zero () const
 
bool operator== (const bls12_377_G2 &other) const
 
bool operator!= (const bls12_377_G2 &other) const
 
bls12_377_G2 operator+ (const bls12_377_G2 &other) const
 
bls12_377_G2 operator- () const
 
bls12_377_G2 operator- (const bls12_377_G2 &other) const
 
bls12_377_G2 add (const bls12_377_G2 &other) const
 
bls12_377_G2 mixed_add (const bls12_377_G2 &other) const
 
bls12_377_G2 dbl () const
 
bls12_377_G2 mul_by_q () const
 
bls12_377_G2 untwist_frobenius_twist () const
 
bls12_377_G2 mul_by_cofactor () const
 
bool is_well_formed () const
 
bool is_in_safe_subgroup () const
 
void write_uncompressed (std::ostream &) const
 
void write_compressed (std::ostream &) const
 

Static Public Member Functions

static bls12_377_Fq2 mul_by_b (const bls12_377_Fq2 &elt)
 
static const bls12_377_G2zero ()
 
static const bls12_377_G2one ()
 
static bls12_377_G2 random_element ()
 
static size_t size_in_bits ()
 
static bigint< base_field::num_limbsbase_field_char ()
 
static bigint< scalar_field::num_limbsorder ()
 
static void read_uncompressed (std::istream &, bls12_377_G2 &)
 
static void read_compressed (std::istream &, bls12_377_G2 &)
 
static void batch_to_special_all_non_zeros (std::vector< bls12_377_G2 > &vec)
 

Public Attributes

bls12_377_Fq2 X
 
bls12_377_Fq2 Y
 
bls12_377_Fq2 Z
 

Static Public Attributes

static std::vector< size_t > wnaf_window_table
 
static std::vector< size_t > fixed_base_exp_window_table
 
static bls12_377_G2 G2_zero
 
static bls12_377_G2 G2_one
 
static bls12_377_Fq2 coeff_a
 
static bls12_377_Fq2 coeff_b
 
static const mp_size_t h_bitcount = 502
 
static const mp_size_t h_limbs
 
static bigint< h_limbsh
 

Detailed Description

Definition at line 21 of file bls12_377_g2.hpp.

Member Typedef Documentation

◆ base_field

Definition at line 35 of file bls12_377_g2.hpp.

◆ scalar_field

Definition at line 37 of file bls12_377_g2.hpp.

◆ twist_field

Definition at line 36 of file bls12_377_g2.hpp.

Constructor & Destructor Documentation

◆ bls12_377_G2() [1/2]

libff::bls12_377_G2::bls12_377_G2 ( )

Definition at line 26 of file bls12_377_g2.cpp.

27 {
28  this->X = G2_zero.X;
29  this->Y = G2_zero.Y;
30  this->Z = G2_zero.Z;
31 }
Here is the caller graph for this function:

◆ bls12_377_G2() [2/2]

libff::bls12_377_G2::bls12_377_G2 ( const bls12_377_Fq2 X,
const bls12_377_Fq2 Y,
const bls12_377_Fq2 Z 
)
inline

Definition at line 49 of file bls12_377_g2.hpp.

51  : X(X), Y(Y), Z(Z){};

Member Function Documentation

◆ add()

bls12_377_G2 libff::bls12_377_G2::add ( const bls12_377_G2 other) const

Definition at line 209 of file bls12_377_g2.cpp.

210 {
211  // handle special cases having to do with O
212  if (this->is_zero()) {
213  return other;
214  }
215 
216  if (other.is_zero()) {
217  return *this;
218  }
219 
220  // No need to handle points of order 2,4
221  // (they cannot exist in a prime-order subgroup)
222 
223  // Handle double case
224  if (this->operator==(other)) {
225  return this->dbl();
226  }
227 
228 #ifdef PROFILE_OP_COUNTS
229  this->add_cnt++;
230 #endif
231  // NOTE: does not handle O and pts of order 2,4
232  // https://www.hyperelliptic.org/EFD/g1p/data/shortw/jacobian-0/addition/add-2007-bl
233  // Z1Z1 = Z1*Z1
234  bls12_377_Fq2 Z1Z1 = (this->Z).squared();
235  // Z2Z2 = Z2*Z2
236  bls12_377_Fq2 Z2Z2 = (other.Z).squared();
237  // U1 = X1*Z2Z2
238  bls12_377_Fq2 U1 = this->X * Z2Z2;
239  // U2 = X2*Z1Z1
240  bls12_377_Fq2 U2 = other.X * Z1Z1;
241  // S1 = Y1*Z2*Z2Z2
242  bls12_377_Fq2 S1 = (this->Y) * ((other.Z) * Z2Z2);
243  // S2 = Y2*Z1*Z1Z1
244  bls12_377_Fq2 S2 = (other.Y) * ((this->Z) * Z1Z1);
245  // H = U2-U1
246  bls12_377_Fq2 H = U2 - U1;
247  // I = (2*H)^2
248  bls12_377_Fq2 I = (H + H).squared();
249  // J = H*I
250  bls12_377_Fq2 J = H * I;
251  // r = 2*(S2-S1)
252  bls12_377_Fq2 S2_minus_S1 = S2 - S1;
253  bls12_377_Fq2 r = S2_minus_S1 + S2_minus_S1;
254  // V = U1*I
255  bls12_377_Fq2 V = U1 * I;
256  // X3 = r^2-J-2*V
257  bls12_377_Fq2 X3 = r.squared() - J - (V + V);
258  bls12_377_Fq2 S1_J = S1 * J;
259  // Y3 = r*(V-X3)-2*S1*J
260  bls12_377_Fq2 Y3 = r * (V - X3) - (S1_J + S1_J);
261  // Z3 = ((Z1+Z2)^2-Z1Z1-Z2Z2) * H
262  bls12_377_Fq2 Z3 = ((this->Z + other.Z).squared() - Z1Z1 - Z2Z2) * H;
263 
264  return bls12_377_G2(X3, Y3, Z3);
265 }
Here is the call graph for this function:

◆ base_field_char()

static bigint<base_field::num_limbs> libff::bls12_377_G2::base_field_char ( )
inlinestatic

Definition at line 86 of file bls12_377_g2.hpp.

87  {
88  return base_field::field_char();
89  }
Here is the call graph for this function:

◆ batch_to_special_all_non_zeros()

void libff::bls12_377_G2::batch_to_special_all_non_zeros ( std::vector< bls12_377_G2 > &  vec)
static

Definition at line 570 of file bls12_377_g2.cpp.

572 {
573  std::vector<bls12_377_Fq2> Z_vec;
574  Z_vec.reserve(vec.size());
575 
576  for (auto &el : vec) {
577  Z_vec.emplace_back(el.Z);
578  }
579  batch_invert<bls12_377_Fq2>(Z_vec);
580 
582 
583  for (size_t i = 0; i < vec.size(); ++i) {
584  bls12_377_Fq2 Z2 = Z_vec[i].squared();
585  bls12_377_Fq2 Z3 = Z_vec[i] * Z2;
586 
587  vec[i].X = vec[i].X * Z2;
588  vec[i].Y = vec[i].Y * Z3;
589  vec[i].Z = one;
590  }
591 }
Here is the call graph for this function:

◆ dbl()

bls12_377_G2 libff::bls12_377_G2::dbl ( ) const

Definition at line 331 of file bls12_377_g2.cpp.

332 {
333 #ifdef PROFILE_OP_COUNTS
334  this->dbl_cnt++;
335 #endif
336  // Handle point at infinity
337  if (this->is_zero()) {
338  return (*this);
339  }
340 
341  // NOTE: does not handle O and pts of order 2,4
342  // https://www.hyperelliptic.org/EFD/g1p/data/shortw/jacobian-0/doubling/dbl-2009-l
343  // A = X1^2
344  bls12_377_Fq2 A = (this->X).squared();
345  // B = Y1^2
346  bls12_377_Fq2 B = (this->Y).squared();
347  // C = B^2
348  bls12_377_Fq2 C = B.squared();
349  // D = 2 * ((X1 + B)^2 - A - C)
350  bls12_377_Fq2 D = (this->X + B).squared() - A - C;
351  D = D + D;
352  // E = 3 * A
353  bls12_377_Fq2 E = A + A + A;
354  // F = E^2
355  bls12_377_Fq2 F = E.squared();
356  // X3 = F - 2 D
357  bls12_377_Fq2 X3 = F - (D + D);
358  // Y3 = E * (D - X3) - 8 * C
359  bls12_377_Fq2 eightC = C + C;
360  eightC = eightC + eightC;
361  eightC = eightC + eightC;
362  bls12_377_Fq2 Y3 = E * (D - X3) - eightC;
363  // Z3 = 2 * Y1 * Z1
364  bls12_377_Fq2 Y1Z1 = (this->Y) * (this->Z);
365  bls12_377_Fq2 Z3 = Y1Z1 + Y1Z1;
366 
367  return bls12_377_G2(X3, Y3, Z3);
368 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_in_safe_subgroup()

bool libff::bls12_377_G2::is_in_safe_subgroup ( ) const

Definition at line 461 of file bls12_377_g2.cpp.

462 {
463  // Check that [h1.r]P == 0, where
464  // [h1.r]P as P + [t](\psi(P) - P) - \psi^2(P)
465  // (See bls12_377.sage).
466 
467  const bls12_377_G2 psi_p = untwist_frobenius_twist();
468  const bls12_377_G2 psi_2_p = psi_p.untwist_frobenius_twist();
469  const bls12_377_G2 psi_p_minus_p = psi_p - *this;
470  const bls12_377_G2 h1_r_p =
471  *this + bls12_377_trace_of_frobenius * psi_p_minus_p - psi_2_p;
472  return zero() == h1_r_p;
473 }
Here is the call graph for this function:

◆ is_special()

bool libff::bls12_377_G2::is_special ( ) const

Definition at line 100 of file bls12_377_g2.cpp.

101 {
102  return (this->is_zero() || this->Z == bls12_377_Fq2::one());
103 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_well_formed()

bool libff::bls12_377_G2::is_well_formed ( ) const

Definition at line 441 of file bls12_377_g2.cpp.

442 {
443  if (this->is_zero()) {
444  return true;
445  }
446 
447  // The curve equation is
448  // E': y^2 = x^3 + ax + b', where a=0 and b'= b*xi
449  // We are using Jacobian coordinates. As such, the equation becomes:
450  // y^2/z^6 = x^3/z^6 + b'
451  // = y^2 = x^3 + b' z^6
452  bls12_377_Fq2 X2 = this->X.squared();
453  bls12_377_Fq2 Y2 = this->Y.squared();
454  bls12_377_Fq2 Z2 = this->Z.squared();
455  bls12_377_Fq2 X3 = this->X * X2;
456  bls12_377_Fq2 Z3 = this->Z * Z2;
457  bls12_377_Fq2 Z6 = Z3.squared();
458  return (Y2 == X3 + bls12_377_twist_coeff_b * Z6);
459 }
Here is the call graph for this function:

◆ is_zero()

bool libff::bls12_377_G2::is_zero ( ) const

Definition at line 105 of file bls12_377_g2.cpp.

105 { return (this->Z.is_zero()); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mixed_add()

bls12_377_G2 libff::bls12_377_G2::mixed_add ( const bls12_377_G2 other) const

Definition at line 270 of file bls12_377_g2.cpp.

271 {
272 #ifdef DEBUG
273  assert(other.is_special());
274 #endif
275 
276  if (this->is_zero()) {
277  return other;
278  }
279 
280  if (other.is_zero()) {
281  return *this;
282  }
283 
284  // No need to handle points of order 2,4
285  // (they cannot exist in a prime-order subgroup)
286 
287  // Z1Z1 = Z1*Z1
288  const bls12_377_Fq2 Z1Z1 = (this->Z).squared();
289  // U2 = X2*Z1Z1
290  const bls12_377_Fq2 U2 = other.X * Z1Z1;
291  // S2 = Y2 * Z1 * Z1Z1
292  const bls12_377_Fq2 S2 = (other.Y) * ((this->Z) * Z1Z1);
293 
294  // (X1/Z1^2) == X2 => X1 == X2*Z1^2
295  // (Y1/Z1^3) == Y2 => Y1 == Y2*Z1^3
296  if (this->X == U2 && this->Y == S2) {
297  return this->dbl();
298  }
299 
300 #ifdef PROFILE_OP_COUNTS
301  this->add_cnt++;
302 #endif
303 
304  // NOTE: does not handle O and pts of order 2,4
305  // https://www.hyperelliptic.org/EFD/g1p/data/shortw/jacobian-0/addition/madd-2007-bl
306  // H = U2-X1
307  bls12_377_Fq2 H = U2 - (this->X);
308  // HH = H^2
309  bls12_377_Fq2 HH = H.squared();
310  // I = 4*HH
311  bls12_377_Fq2 I = HH + HH;
312  I = I + I;
313  // J = H*I
314  bls12_377_Fq2 J = H * I;
315  // r = 2*(S2-Y1)
316  bls12_377_Fq2 r = S2 - (this->Y);
317  r = r + r;
318  // V = X1*I
319  bls12_377_Fq2 V = (this->X) * I;
320  // X3 = r^2-J-2*V
321  bls12_377_Fq2 X3 = r.squared() - J - V - V;
322  // Y3 = r*(V-X3)-2*Y1*J
323  bls12_377_Fq2 Y3 = (this->Y) * J;
324  Y3 = r * (V - X3) - Y3 - Y3;
325  // Z3 = (Z1+H)^2-Z1Z1-HH
326  bls12_377_Fq2 Z3 = ((this->Z) + H).squared() - Z1Z1 - HH;
327 
328  return bls12_377_G2(X3, Y3, Z3);
329 }
Here is the call graph for this function:

◆ mul_by_b()

bls12_377_Fq2 libff::bls12_377_G2::mul_by_b ( const bls12_377_Fq2 elt)
static

Definition at line 33 of file bls12_377_g2.cpp.

34 {
35  return bls12_377_Fq2(
36  bls12_377_twist_mul_by_b_c0 * elt.coeffs[0],
37  bls12_377_twist_mul_by_b_c1 * elt.coeffs[1]);
38 }

◆ mul_by_cofactor()

bls12_377_G2 libff::bls12_377_G2::mul_by_cofactor ( ) const

Definition at line 423 of file bls12_377_g2.cpp.

424 {
425  // See bls12_377.sage.
426  // [h2]P = [h2_0]P + [h2_1]([t] psi_p - psi_2_p)
427  // where:
428  // h2_0 = 293634935485640680722085584138834120318524213360527933441
429  // h2_1 = 30631250834960419227450344600217059328
430  // t = 9586122913090633730
431  const bls12_377_G2 psi_p = untwist_frobenius_twist();
432  const bls12_377_G2 psi_2_p = psi_p.untwist_frobenius_twist();
433  const bls12_377_G2 t_psi_mins_psi_2 =
434  bls12_377_trace_of_frobenius * psi_p - psi_2_p;
435  const bls12_377_G2 result =
437  bls12_377_g2_mul_by_cofactor_h2_1 * t_psi_mins_psi_2;
438  return result;
439 }
Here is the call graph for this function:

◆ mul_by_q()

bls12_377_G2 libff::bls12_377_G2::mul_by_q ( ) const

Definition at line 370 of file bls12_377_g2.cpp.

371 {
372  return bls12_377_G2(
373  bls12_377_twist_mul_by_q_X * (this->X).Frobenius_map(1),
374  bls12_377_twist_mul_by_q_Y * (this->Y).Frobenius_map(1),
375  (this->Z).Frobenius_map(1));
376 }
Here is the call graph for this function:

◆ one()

const bls12_377_G2 & libff::bls12_377_G2::one ( )
static

Definition at line 477 of file bls12_377_g2.cpp.

477 { return G2_one; }
Here is the caller graph for this function:

◆ operator!=()

bool libff::bls12_377_G2::operator!= ( const bls12_377_G2 other) const

Definition at line 135 of file bls12_377_g2.cpp.

136 {
137  return !(operator==(other));
138 }
Here is the call graph for this function:

◆ operator+()

bls12_377_G2 libff::bls12_377_G2::operator+ ( const bls12_377_G2 other) const

Definition at line 140 of file bls12_377_g2.cpp.

141 {
142  // Handle special cases having to do with O
143  if (this->is_zero()) {
144  return other;
145  }
146 
147  if (other.is_zero()) {
148  return *this;
149  }
150 
151  // No need to handle points of order 2,4
152  // (they cannot exist in a prime-order subgroup)
153 
154  // Z1Z1 = Z1*Z1
155  bls12_377_Fq2 Z1Z1 = (this->Z).squared();
156  // Z2Z2 = Z2*Z2
157  bls12_377_Fq2 Z2Z2 = (other.Z).squared();
158 
159  // U1 = X1*Z2Z2
160  bls12_377_Fq2 U1 = this->X * Z2Z2;
161  // U2 = X2*Z1Z1
162  bls12_377_Fq2 U2 = other.X * Z1Z1;
163 
164  // S1 = Y1*Z2*Z2Z2
165  bls12_377_Fq2 S1 = (this->Y) * ((other.Z) * Z2Z2);
166  // S2 = Y2*Z1*Z1Z1
167  bls12_377_Fq2 S2 = (other.Y) * ((this->Z) * Z1Z1);
168 
169  // Check if the 2 points are equal, in which can we do a point doubling
170  // (i.e. P + P)
171  if (U1 == U2 && S1 == S2) {
172  return this->dbl();
173  }
174 
175  // Point addition (i.e. P + Q, P =/= Q)
176  // https://www.hyperelliptic.org/EFD/g1p/data/shortw/jacobian-0/addition/add-2007-bl
177  // H = U2-U1
178  bls12_377_Fq2 H = U2 - U1;
179  // I = (2*H)^2
180  bls12_377_Fq2 I = (H + H).squared();
181  // J = H*I
182  bls12_377_Fq2 J = H * I;
183  // r = 2*(S2-S1)
184  bls12_377_Fq2 S2_minus_S1 = S2 - S1;
185  bls12_377_Fq2 r = S2_minus_S1 + S2_minus_S1;
186  // V = U1*I
187  bls12_377_Fq2 V = U1 * I;
188  // X3 = r^2-J-2*V
189  bls12_377_Fq2 X3 = r.squared() - J - (V + V);
190  bls12_377_Fq2 S1_J = S1 * J;
191  // Y3 = r*(V-X3)-2*S1*J
192  bls12_377_Fq2 Y3 = r * (V - X3) - (S1_J + S1_J);
193  // Z3 = ((Z1+Z2)^2-Z1Z1-Z2Z2) * H
194  bls12_377_Fq2 Z3 = ((this->Z + other.Z).squared() - Z1Z1 - Z2Z2) * H;
195 
196  return bls12_377_G2(X3, Y3, Z3);
197 }
Here is the call graph for this function:

◆ operator-() [1/2]

bls12_377_G2 libff::bls12_377_G2::operator- ( ) const

Definition at line 199 of file bls12_377_g2.cpp.

200 {
201  return bls12_377_G2(this->X, -(this->Y), this->Z);
202 }
Here is the call graph for this function:

◆ operator-() [2/2]

bls12_377_G2 libff::bls12_377_G2::operator- ( const bls12_377_G2 other) const

Definition at line 204 of file bls12_377_g2.cpp.

205 {
206  return (*this) + (-other);
207 }

◆ operator==()

bool libff::bls12_377_G2::operator== ( const bls12_377_G2 other) const

Definition at line 107 of file bls12_377_g2.cpp.

108 {
109  if (this->is_zero()) {
110  return other.is_zero();
111  }
112 
113  if (other.is_zero()) {
114  return false;
115  }
116 
117  // now neither is O
118 
119  // Using Jacobian coordinates so:
120  // (X1:Y1:Z1) = (X2:Y2:Z2) <=>
121  // X1/Z1^2 == X2/Z2^2 AND Y1/Z1^3 == Y2/Z2^3 <=>
122  // X1 * Z2^2 == X2 * Z1^2 AND Y1 * Z2^3 == Y2 * Z1^3
123  bls12_377_Fq2 Z1_squared = (this->Z).squared();
124  bls12_377_Fq2 Z2_squared = (other.Z).squared();
125  bls12_377_Fq2 Z1_cubed = (this->Z) * Z1_squared;
126  bls12_377_Fq2 Z2_cubed = (other.Z) * Z2_squared;
127  if (((this->X * Z2_squared) != (other.X * Z1_squared)) ||
128  ((this->Y * Z2_cubed) != (other.Y * Z1_cubed))) {
129  return false;
130  }
131 
132  return true;
133 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ order()

static bigint<scalar_field::num_limbs> libff::bls12_377_G2::order ( )
inlinestatic

Definition at line 90 of file bls12_377_g2.hpp.

91  {
92  return scalar_field::field_char();
93  }
Here is the call graph for this function:

◆ print()

void libff::bls12_377_G2::print ( ) const

Definition at line 40 of file bls12_377_g2.cpp.

41 {
42  if (this->is_zero()) {
43  printf("O\n");
44  } else {
45  bls12_377_G2 copy(*this);
46  copy.to_affine_coordinates();
47  gmp_printf(
48  "(%Nd*z + %Nd , %Nd*z + %Nd)\n",
49  copy.X.coeffs[1].as_bigint().data,
51  copy.X.coeffs[0].as_bigint().data,
53  copy.Y.coeffs[1].as_bigint().data,
55  copy.Y.coeffs[0].as_bigint().data,
57  }
58 }
Here is the call graph for this function:

◆ print_coordinates()

void libff::bls12_377_G2::print_coordinates ( ) const

Definition at line 60 of file bls12_377_g2.cpp.

61 {
62  if (this->is_zero()) {
63  printf("O\n");
64  } else {
65  gmp_printf(
66  "(%Nd*z + %Nd : %Nd*z + %Nd : %Nd*z + %Nd)\n",
67  this->X.coeffs[1].as_bigint().data,
69  this->X.coeffs[0].as_bigint().data,
71  this->Y.coeffs[1].as_bigint().data,
73  this->Y.coeffs[0].as_bigint().data,
75  this->Z.coeffs[1].as_bigint().data,
77  this->Z.coeffs[0].as_bigint().data,
79  }
80 }
Here is the call graph for this function:

◆ random_element()

bls12_377_G2 libff::bls12_377_G2::random_element ( )
static

Definition at line 479 of file bls12_377_g2.cpp.

480 {
481  return (bls12_377_Fr::random_element().as_bigint()) * G2_one;
482 }
Here is the call graph for this function:

◆ read_compressed()

void libff::bls12_377_G2::read_compressed ( std::istream &  in,
bls12_377_G2 g 
)
static

Definition at line 518 of file bls12_377_g2.cpp.

519 {
520  char is_zero;
521  bls12_377_Fq2 tX, tY;
522  // this reads is_zero;
523  in.read((char *)&is_zero, 1);
524  is_zero -= '0';
526 
527  unsigned char Y_lsb;
528  in >> tX;
530  in.read((char *)&Y_lsb, 1);
531  Y_lsb -= '0';
532 
533  // y = +/- sqrt(x^3 + b)
534  if (!is_zero) {
535  bls12_377_Fq2 tX2 = tX.squared();
536  bls12_377_Fq2 tY2 = tX2 * tX + bls12_377_twist_coeff_b;
537  tY = tY2.sqrt();
538 
539  if ((tY.coeffs[0].as_bigint().data[0] & 1) != Y_lsb) {
540  tY = -tY;
541  }
542 
543  g.X = tX;
544  g.Y = tY;
545  g.Z = bls12_377_Fq2::one();
546  } else {
547  g = bls12_377_G2::zero();
548  }
549 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_uncompressed()

void libff::bls12_377_G2::read_uncompressed ( std::istream &  in,
bls12_377_G2 g 
)
static

Definition at line 502 of file bls12_377_g2.cpp.

503 {
504  char is_zero;
505  bls12_377_Fq2 tX, tY;
506  in >> is_zero >> tX >> tY;
507  is_zero -= '0';
508 
509  if (!is_zero) {
510  g.X = tX;
511  g.Y = tY;
512  g.Z = bls12_377_Fq2::one();
513  } else {
514  g = bls12_377_G2::zero();
515  }
516 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ size_in_bits()

static size_t libff::bls12_377_G2::size_in_bits ( )
inlinestatic

Definition at line 85 of file bls12_377_g2.hpp.

85 { return twist_field::size_in_bits() + 1; }
Here is the call graph for this function:

◆ to_affine_coordinates()

void libff::bls12_377_G2::to_affine_coordinates ( )

Definition at line 82 of file bls12_377_g2.cpp.

83 {
84  if (this->is_zero()) {
85  this->X = bls12_377_Fq2::zero();
86  this->Y = bls12_377_Fq2::one();
87  this->Z = bls12_377_Fq2::zero();
88  } else {
89  bls12_377_Fq2 Z_inv = Z.inverse();
90  bls12_377_Fq2 Z2_inv = Z_inv.squared();
91  bls12_377_Fq2 Z3_inv = Z2_inv * Z_inv;
92  this->X = this->X * Z2_inv;
93  this->Y = this->Y * Z3_inv;
94  this->Z = bls12_377_Fq2::one();
95  }
96 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ to_special()

void libff::bls12_377_G2::to_special ( )

Definition at line 98 of file bls12_377_g2.cpp.

98 { this->to_affine_coordinates(); }
Here is the call graph for this function:

◆ untwist_frobenius_twist()

bls12_377_G2 libff::bls12_377_G2::untwist_frobenius_twist ( ) const

Definition at line 378 of file bls12_377_g2.cpp.

379 {
380  bls12_377_G2 g = *this;
381  g.to_affine_coordinates();
382 
383  // Note, the algebra works out such that the first component of the
384  // untwisted point only ever occupies Fq6, and so we use this type to avoid
385  // the extra multiplications involved in Fq12 operations.
386 
387  // TODO: There are further optimizations we can make here, because we know
388  // that many components will be zero and unused. For now, we use generic
389  // Fp6 and Fp12 operations for conveneience.
390 
391  // Untwist
392  const bls12_377_Fq6 x_fq6(
394  const bls12_377_Fq12 y_fq12(
397  const bls12_377_Fq6 untwist_x =
399  const bls12_377_Fq12 untwist_y =
401  // Frobenius
402  const bls12_377_Fq6 frob_untwist_x = untwist_x.Frobenius_map(1);
403  const bls12_377_Fq12 frob_untwist_y = untwist_y.Frobenius_map(1);
404  // Twist
405  const bls12_377_Fq6 twist_frob_untwist_x =
406  frob_untwist_x *
408  const bls12_377_Fq12 twist_frob_untwist_y =
410 
411  assert(twist_frob_untwist_x.coeffs[2] == bls12_377_Fq2::zero());
412  assert(twist_frob_untwist_x.coeffs[1] == bls12_377_Fq2::zero());
413  assert(twist_frob_untwist_y.coeffs[1] == bls12_377_Fq6::zero());
414  assert(twist_frob_untwist_y.coeffs[0].coeffs[2] == bls12_377_Fq2::zero());
415  assert(twist_frob_untwist_y.coeffs[0].coeffs[1] == bls12_377_Fq2::zero());
416 
417  return bls12_377_G2(
418  twist_frob_untwist_x.coeffs[0],
419  twist_frob_untwist_y.coeffs[0].coeffs[0],
421 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_compressed()

void libff::bls12_377_G2::write_compressed ( std::ostream &  out) const

Definition at line 492 of file bls12_377_g2.cpp.

493 {
494  bls12_377_G2 copy(*this);
495  copy.to_affine_coordinates();
496  out << (copy.is_zero() ? 1 : 0) << OUTPUT_SEPARATOR;
497  /* storing LSB of Y */
498  out << copy.X << OUTPUT_SEPARATOR
499  << (copy.Y.coeffs[0].as_bigint().data[0] & 1);
500 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_uncompressed()

void libff::bls12_377_G2::write_uncompressed ( std::ostream &  out) const

Definition at line 484 of file bls12_377_g2.cpp.

485 {
486  bls12_377_G2 copy(*this);
487  copy.to_affine_coordinates();
488  out << (copy.is_zero() ? 1 : 0) << OUTPUT_SEPARATOR;
489  out << copy.X << OUTPUT_SEPARATOR << copy.Y;
490 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zero()

const bls12_377_G2 & libff::bls12_377_G2::zero ( )
static

Definition at line 475 of file bls12_377_g2.cpp.

475 { return G2_zero; }
Here is the caller graph for this function:

Member Data Documentation

◆ coeff_a

bls12_377_Fq2 libff::bls12_377_G2::coeff_a
static

Definition at line 32 of file bls12_377_g2.hpp.

◆ coeff_b

bls12_377_Fq2 libff::bls12_377_G2::coeff_b
static

Definition at line 33 of file bls12_377_g2.hpp.

◆ fixed_base_exp_window_table

std::vector< size_t > libff::bls12_377_G2::fixed_base_exp_window_table
static

Definition at line 29 of file bls12_377_g2.hpp.

◆ G2_one

bls12_377_G2 libff::bls12_377_G2::G2_one
static

Definition at line 31 of file bls12_377_g2.hpp.

◆ G2_zero

bls12_377_G2 libff::bls12_377_G2::G2_zero
static

Definition at line 30 of file bls12_377_g2.hpp.

◆ h

bigint< bls12_377_G2::h_limbs > libff::bls12_377_G2::h
static

Definition at line 43 of file bls12_377_g2.hpp.

◆ h_bitcount

const mp_size_t libff::bls12_377_G2::h_bitcount = 502
static

Definition at line 40 of file bls12_377_g2.hpp.

◆ h_limbs

const mp_size_t libff::bls12_377_G2::h_limbs
static
Initial value:
=
(h_bitcount + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS

Definition at line 41 of file bls12_377_g2.hpp.

◆ wnaf_window_table

std::vector< size_t > libff::bls12_377_G2::wnaf_window_table
static

Definition at line 28 of file bls12_377_g2.hpp.

◆ X

bls12_377_Fq2 libff::bls12_377_G2::X

Definition at line 45 of file bls12_377_g2.hpp.

◆ Y

bls12_377_Fq2 libff::bls12_377_G2::Y

Definition at line 45 of file bls12_377_g2.hpp.

◆ Z

bls12_377_Fq2 libff::bls12_377_G2::Z

Definition at line 45 of file bls12_377_g2.hpp.


The documentation for this class was generated from the following files:
libff::Fp2_model::coeffs
my_Fp coeffs[2]
Definition: fp2.hpp:63
libff::bls12_377_g2_untwist_frobenius_twist_v_inverse
bls12_377_Fq12 bls12_377_g2_untwist_frobenius_twist_v_inverse
Definition: bls12_377_init.cpp:36
libff::bls12_377_G2::G2_one
static bls12_377_G2 G2_one
Definition: bls12_377_g2.hpp:31
libff::bls12_377_G2::is_zero
bool is_zero() const
Definition: bls12_377_g2.cpp:105
libff::Fp_model::random_element
static Fp_model< n, modulus > random_element()
returns random element of Fp_model
libff::bls12_377_g2_untwist_frobenius_twist_v
bls12_377_Fq12 bls12_377_g2_untwist_frobenius_twist_v
Definition: bls12_377_init.cpp:34
libff::bls12_377_G2::bls12_377_G2
bls12_377_G2()
Definition: bls12_377_g2.cpp:26
libff::Fp6_3over2_model::zero
static Fp6_3over2_model< n, modulus > zero()
libff::Fp2_model< bls12_377_q_limbs, bls12_377_modulus_q >::one
static const Fp2_model< n, modulus > & one()
libff::Fp2_model< bls12_377_q_limbs, bls12_377_modulus_q >::size_in_bits
static size_t size_in_bits()
Definition: fp2.hpp:108
libff::bls12_377_G2::one
static const bls12_377_G2 & one()
Definition: bls12_377_g2.cpp:477
libff::bls12_377_Fq12
Fp12_2over3over2_model< bls12_377_q_limbs, bls12_377_modulus_q > bls12_377_Fq12
Definition: bls12_377_init.hpp:52
libff::bls12_377_twist_coeff_b
bls12_377_Fq2 bls12_377_twist_coeff_b
Definition: bls12_377_init.cpp:19
libff::bls12_377_g2_untwist_frobenius_twist_w_3
bls12_377_Fq12 bls12_377_g2_untwist_frobenius_twist_w_3
Definition: bls12_377_init.cpp:35
libff::bls12_377_twist_mul_by_q_X
bls12_377_Fq2 bls12_377_twist_mul_by_q_X
Definition: bls12_377_init.cpp:22
libff::bls12_377_G2::to_affine_coordinates
void to_affine_coordinates()
Definition: bls12_377_g2.cpp:82
libff::Fp2_model::inverse
Fp2_model inverse() const
OUTPUT_SEPARATOR
#define OUTPUT_SEPARATOR
Definition: serialization.hpp:69
libff::Fp2_model::is_zero
bool is_zero() const
Definition: fp2.hpp:89
libff::bls12_377_twist_mul_by_q_Y
bls12_377_Fq2 bls12_377_twist_mul_by_q_Y
Definition: bls12_377_init.cpp:23
libff::bls12_377_g2_mul_by_cofactor_h2_1
bigint< bls12_377_r_limbs > bls12_377_g2_mul_by_cofactor_h2_1
Definition: bls12_377_init.cpp:41
libff::bls12_377_G2::X
bls12_377_Fq2 X
Definition: bls12_377_g2.hpp:45
libff::bls12_377_Fq2
Fp2_model< bls12_377_q_limbs, bls12_377_modulus_q > bls12_377_Fq2
Definition: bls12_377_init.hpp:49
libff::bls12_377_Fq6
Fp6_3over2_model< bls12_377_q_limbs, bls12_377_modulus_q > bls12_377_Fq6
Definition: bls12_377_init.hpp:50
libff::consume_OUTPUT_SEPARATOR
void consume_OUTPUT_SEPARATOR(std::istream &in)
libff::Fp_model< bls12_377_q_limbs, bls12_377_modulus_q >::num_limbs
static const mp_size_t num_limbs
Definition: fp.hpp:47
libff::bls12_377_G2::Z
bls12_377_Fq2 Z
Definition: bls12_377_g2.hpp:45
libff::bls12_377_twist_mul_by_b_c1
bls12_377_Fq bls12_377_twist_mul_by_b_c1
Definition: bls12_377_init.cpp:21
libff::bls12_377_G2::dbl
bls12_377_G2 dbl() const
Definition: bls12_377_g2.cpp:331
libff::bls12_377_G2::zero
static const bls12_377_G2 & zero()
Definition: bls12_377_g2.cpp:475
libff::bls12_377_trace_of_frobenius
bigint< bls12_377_r_limbs > bls12_377_trace_of_frobenius
Definition: bls12_377_init.cpp:17
libff::Fp_model< bls12_377_q_limbs, bls12_377_modulus_q >::field_char
static const bigint< n > & field_char()
Definition: fp.hpp:136
libff::bls12_377_G2::G2_zero
static bls12_377_G2 G2_zero
Definition: bls12_377_g2.hpp:30
libff::Fp_model::as_bigint
bigint< n > as_bigint() const
libff::bls12_377_g2_untwist_frobenius_twist_w_3_inverse
bls12_377_Fq12 bls12_377_g2_untwist_frobenius_twist_w_3_inverse
Definition: bls12_377_init.cpp:37
libff::Fp2_model::squared
Fp2_model squared() const
default is squared_complex
libff::Fp2_model::sqrt
Fp2_model sqrt() const
HAS TO BE A SQUARE (else does not terminate)
libff::bls12_377_g2_mul_by_cofactor_h2_0
bigint< bls12_377_r_limbs > bls12_377_g2_mul_by_cofactor_h2_0
Definition: bls12_377_init.cpp:40
libff::Fp2_model< bls12_377_q_limbs, bls12_377_modulus_q >::zero
static const Fp2_model< n, modulus > & zero()
libff::bls12_377_G2::Y
bls12_377_Fq2 Y
Definition: bls12_377_g2.hpp:45
libff::bls12_377_G2::h_bitcount
static const mp_size_t h_bitcount
Definition: bls12_377_g2.hpp:40
libff::Fp12_2over3over2_model::coeffs
my_Fp6 coeffs[2]
Definition: fp12_2over3over2.hpp:62
libff::bls12_377_twist_mul_by_b_c0
bls12_377_Fq bls12_377_twist_mul_by_b_c0
Definition: bls12_377_init.cpp:20
libff::bls12_377_G2::untwist_frobenius_twist
bls12_377_G2 untwist_frobenius_twist() const
Definition: bls12_377_g2.cpp:378
libff::bls12_377_G2::operator==
bool operator==(const bls12_377_G2 &other) const
Definition: bls12_377_g2.cpp:107