Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
libff::alt_bn128_G2 Class Reference

#include <alt_bn128_g2.hpp>

Collaboration diagram for libff::alt_bn128_G2:

Public Types

typedef alt_bn128_Fq base_field
 
typedef alt_bn128_Fq2 twist_field
 
typedef alt_bn128_Fr scalar_field
 

Public Member Functions

 alt_bn128_G2 ()
 
 alt_bn128_G2 (const alt_bn128_Fq2 &X, const alt_bn128_Fq2 &Y, const alt_bn128_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 alt_bn128_G2 &other) const
 
bool operator!= (const alt_bn128_G2 &other) const
 
alt_bn128_G2 operator+ (const alt_bn128_G2 &other) const
 
alt_bn128_G2 operator- () const
 
alt_bn128_G2 operator- (const alt_bn128_G2 &other) const
 
alt_bn128_G2 add (const alt_bn128_G2 &other) const
 
alt_bn128_G2 mixed_add (const alt_bn128_G2 &other) const
 
alt_bn128_G2 dbl () const
 
alt_bn128_G2 mul_by_q () const
 
bool is_well_formed () const
 

Static Public Member Functions

static alt_bn128_Fq2 mul_by_b (const alt_bn128_Fq2 &elt)
 
static alt_bn128_G2 zero ()
 
static alt_bn128_G2 one ()
 
static alt_bn128_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 batch_to_special_all_non_zeros (std::vector< alt_bn128_G2 > &vec)
 

Public Attributes

alt_bn128_Fq2 X
 
alt_bn128_Fq2 Y
 
alt_bn128_Fq2 Z
 

Static Public Attributes

static std::vector< size_t > wnaf_window_table
 
static std::vector< size_t > fixed_base_exp_window_table
 
static alt_bn128_G2 G2_zero = {}
 
static alt_bn128_G2 G2_one = {}
 
static bool initialized = false
 

Friends

std::ostream & operator<< (std::ostream &out, const alt_bn128_G2 &g)
 
std::istream & operator>> (std::istream &in, alt_bn128_G2 &g)
 

Detailed Description

Definition at line 21 of file alt_bn128_g2.hpp.

Member Typedef Documentation

◆ base_field

◆ scalar_field

◆ twist_field

Constructor & Destructor Documentation

◆ alt_bn128_G2() [1/2]

libff::alt_bn128_G2::alt_bn128_G2 ( )

Definition at line 23 of file alt_bn128_g2.cpp.

24{
25 if (initialized)
26 {
27 this->X = G2_zero.X;
28 this->Y = G2_zero.Y;
29 this->Z = G2_zero.Z;
30 }
31}
static alt_bn128_G2 G2_zero
static bool initialized
Definition lib.h:43
Here is the caller graph for this function:

◆ alt_bn128_G2() [2/2]

libff::alt_bn128_G2::alt_bn128_G2 ( const alt_bn128_Fq2 & X,
const alt_bn128_Fq2 & Y,
const alt_bn128_Fq2 & Z )
inline

Definition at line 41 of file alt_bn128_g2.hpp.

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

Member Function Documentation

◆ add()

alt_bn128_G2 libff::alt_bn128_G2::add ( const alt_bn128_G2 & other) const

Definition at line 222 of file alt_bn128_g2.cpp.

223{
224 // handle special cases having to do with O
225 if (this->is_zero())
226 {
227 return other;
228 }
229
230 if (other.is_zero())
231 {
232 return *this;
233 }
234
235 // no need to handle points of order 2,4
236 // (they cannot exist in a prime-order subgroup)
237
238 // handle double case
239 if (this->operator==(other))
240 {
241 return this->dbl();
242 }
243
244#ifdef PROFILE_OP_COUNTS
245 this->add_cnt++;
246#endif
247 // NOTE: does not handle O and pts of order 2,4
248 // http://www.hyperelliptic.org/EFD/g1p/auto-shortw-projective.html#addition-add-1998-cmo-2
249
250 alt_bn128_Fq2 Z1Z1 = (this->Z).squared(); // Z1Z1 = Z1^2
251 alt_bn128_Fq2 Z2Z2 = (other.Z).squared(); // Z2Z2 = Z2^2
252 alt_bn128_Fq2 U1 = (this->X) * Z2Z2; // U1 = X1 * Z2Z2
253 alt_bn128_Fq2 U2 = (other.X) * Z1Z1; // U2 = X2 * Z1Z1
254 alt_bn128_Fq2 S1 = (this->Y) * (other.Z) * Z2Z2; // S1 = Y1 * Z2 * Z2Z2
255 alt_bn128_Fq2 S2 = (other.Y) * (this->Z) * Z1Z1; // S2 = Y2 * Z1 * Z1Z1
256 alt_bn128_Fq2 H = U2 - U1; // H = U2-U1
257 alt_bn128_Fq2 S2_minus_S1 = S2-S1;
258 alt_bn128_Fq2 I = (H+H).squared(); // I = (2 * H)^2
259 alt_bn128_Fq2 J = H * I; // J = H * I
260 alt_bn128_Fq2 r = S2_minus_S1 + S2_minus_S1; // r = 2 * (S2-S1)
261 alt_bn128_Fq2 V = U1 * I; // V = U1 * I
262 alt_bn128_Fq2 X3 = r.squared() - J - (V+V); // X3 = r^2 - J - 2 * V
263 alt_bn128_Fq2 S1_J = S1 * J;
264 alt_bn128_Fq2 Y3 = r * (V-X3) - (S1_J+S1_J); // Y3 = r * (V-X3)-2 S1 J
265 alt_bn128_Fq2 Z3 = ((this->Z+other.Z).squared()-Z1Z1-Z2Z2) * H; // Z3 = ((Z1+Z2)^2-Z1Z1-Z2Z2) * H
266
267 return alt_bn128_G2(X3, Y3, Z3);
268}
const mie::Vuint & r
Definition bn.cpp:28
alt_bn128_G2 dbl() const
Fp2_model< alt_bn128_q_limbs, alt_bn128_modulus_q > alt_bn128_Fq2
Definition test_zm.cpp:19
Here is the call graph for this function:

◆ base_field_char()

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

Definition at line 73 of file alt_bn128_g2.hpp.

Here is the call graph for this function:

◆ batch_to_special_all_non_zeros()

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

Definition at line 484 of file alt_bn128_g2.cpp.

485{
486 std::vector<alt_bn128_Fq2> Z_vec;
487 Z_vec.reserve(vec.size());
488
489 for (auto &el: vec)
490 {
491 Z_vec.emplace_back(el.Z);
492 }
494
496
497 for (size_t i = 0; i < vec.size(); ++i)
498 {
499 alt_bn128_Fq2 Z2 = Z_vec[i].squared();
500 alt_bn128_Fq2 Z3 = Z_vec[i] * Z2;
501
502 vec[i].X = vec[i].X * Z2;
503 vec[i].Y = vec[i].Y * Z3;
504 vec[i].Z = one;
505 }
506}
Fp2_model squared() const
static alt_bn128_G2 one()
void batch_invert(std::vector< FieldT > &vec)
Here is the call graph for this function:

◆ dbl()

alt_bn128_G2 libff::alt_bn128_G2::dbl ( ) const

Definition at line 339 of file alt_bn128_g2.cpp.

340{
341#ifdef PROFILE_OP_COUNTS
342 this->dbl_cnt++;
343#endif
344 // handle point at infinity
345 if (this->is_zero())
346 {
347 return (*this);
348 }
349
350 // NOTE: does not handle O and pts of order 2,4
351 // http://www.hyperelliptic.org/EFD/g1p/auto-shortw-projective.html#doubling-dbl-2007-bl
352
353 alt_bn128_Fq2 A = (this->X).squared(); // A = X1^2
354 alt_bn128_Fq2 B = (this->Y).squared(); // B = Y1^2
355 alt_bn128_Fq2 C = B.squared(); // C = B^2
356 alt_bn128_Fq2 D = (this->X + B).squared() - A - C;
357 D = D+D; // D = 2 * ((X1 + B)^2 - A - C)
358 alt_bn128_Fq2 E = A + A + A; // E = 3 * A
359 alt_bn128_Fq2 F = E.squared(); // F = E^2
360 alt_bn128_Fq2 X3 = F - (D+D); // X3 = F - 2 D
361 alt_bn128_Fq2 eightC = C+C;
362 eightC = eightC + eightC;
363 eightC = eightC + eightC;
364 alt_bn128_Fq2 Y3 = E * (D - X3) - eightC; // Y3 = E * (D - X3) - 8 * C
365 alt_bn128_Fq2 Y1Z1 = (this->Y)*(this->Z);
366 alt_bn128_Fq2 Z3 = Y1Z1 + Y1Z1; // Z3 = 2 * Y1 * Z1
367
368 return alt_bn128_G2(X3, Y3, Z3);
369}
#define D(var, file, col, who, lev,...)
Definition debug.h:44
#define A
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_special()

bool libff::alt_bn128_G2::is_special ( ) const

Definition at line 98 of file alt_bn128_g2.cpp.

99{
100 return (this->is_zero() || this->Z == alt_bn128_Fq2::one());
101}
Here is the call graph for this function:

◆ is_well_formed()

bool libff::alt_bn128_G2::is_well_formed ( ) const

Definition at line 378 of file alt_bn128_g2.cpp.

379{
380 if (this->is_zero())
381 {
382 return true;
383 }
384 else
385 {
386 /*
387 y^2 = x^3 + b
388
389 We are using Jacobian coordinates, so equation we need to check is actually
390
391 (y/z^3)^2 = (x/z^2)^3 + b
392 y^2 / z^6 = x^3 / z^6 + b
393 y^2 = x^3 + b z^6
394 */
395 alt_bn128_Fq2 X2 = this->X.squared();
396 alt_bn128_Fq2 Y2 = this->Y.squared();
397 alt_bn128_Fq2 Z2 = this->Z.squared();
398
399 alt_bn128_Fq2 X3 = this->X * X2;
400 alt_bn128_Fq2 Z3 = this->Z * Z2;
401 alt_bn128_Fq2 Z6 = Z3.squared();
402
403 return (Y2 == X3 + alt_bn128_twist_coeff_b * Z6);
404 }
405}
alt_bn128_Fq2 alt_bn128_twist_coeff_b
Here is the call graph for this function:

◆ is_zero()

bool libff::alt_bn128_G2::is_zero ( ) const

Definition at line 103 of file alt_bn128_g2.cpp.

104{
105 return (this->Z.is_zero());
106}
bool is_zero() const
Definition fp2.hpp:60
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mixed_add()

alt_bn128_G2 libff::alt_bn128_G2::mixed_add ( const alt_bn128_G2 & other) const

Definition at line 270 of file alt_bn128_g2.cpp.

271{
272#ifdef DEBUG
273 assert(other.is_special());
274#endif
275
276 // handle special cases having to do with O
277 if (this->is_zero())
278 {
279 return other;
280 }
281
282 if (other.is_zero())
283 {
284 return *this;
285 }
286
287 // no need to handle points of order 2,4
288 // (they cannot exist in a prime-order subgroup)
289
290 // check for doubling case
291
292 // using Jacobian coordinates so:
293 // (X1:Y1:Z1) = (X2:Y2:Z2)
294 // iff
295 // X1/Z1^2 == X2/Z2^2 and Y1/Z1^3 == Y2/Z2^3
296 // iff
297 // X1 * Z2^2 == X2 * Z1^2 and Y1 * Z2^3 == Y2 * Z1^3
298
299 // we know that Z2 = 1
300
301 const alt_bn128_Fq2 Z1Z1 = (this->Z).squared();
302
303 const alt_bn128_Fq2 &U1 = this->X;
304 const alt_bn128_Fq2 U2 = other.X * Z1Z1;
305
306 const alt_bn128_Fq2 Z1_cubed = (this->Z) * Z1Z1;
307
308 const alt_bn128_Fq2 &S1 = (this->Y); // S1 = Y1 * Z2 * Z2Z2
309 const alt_bn128_Fq2 S2 = (other.Y) * Z1_cubed; // S2 = Y2 * Z1 * Z1Z1
310
311 if (U1 == U2 && S1 == S2)
312 {
313 // dbl case; nothing of above can be reused
314 return this->dbl();
315 }
316
317#ifdef PROFILE_OP_COUNTS
318 this->add_cnt++;
319#endif
320
321 // NOTE: does not handle O and pts of order 2,4
322 // http://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#addition-madd-2007-bl
323 alt_bn128_Fq2 H = U2-(this->X); // H = U2-X1
324 alt_bn128_Fq2 HH = H.squared() ; // HH = H&2
325 alt_bn128_Fq2 I = HH+HH; // I = 4*HH
326 I = I + I;
327 alt_bn128_Fq2 J = H*I; // J = H*I
328 alt_bn128_Fq2 r = S2-(this->Y); // r = 2*(S2-Y1)
329 r = r + r;
330 alt_bn128_Fq2 V = (this->X) * I ; // V = X1*I
331 alt_bn128_Fq2 X3 = r.squared()-J-V-V; // X3 = r^2-J-2*V
332 alt_bn128_Fq2 Y3 = (this->Y)*J; // Y3 = r*(V-X3)-2*Y1*J
333 Y3 = r*(V-X3) - Y3 - Y3;
334 alt_bn128_Fq2 Z3 = ((this->Z)+H).squared() - Z1Z1 - HH; // Z3 = (Z1+H)^2-Z1Z1-HH
335
336 return alt_bn128_G2(X3, Y3, Z3);
337}
Here is the call graph for this function:

◆ mul_by_b()

alt_bn128_Fq2 libff::alt_bn128_G2::mul_by_b ( const alt_bn128_Fq2 & elt)
static

Definition at line 33 of file alt_bn128_g2.cpp.

34{
36}
alt_bn128_Fq alt_bn128_twist_mul_by_b_c0
alt_bn128_Fq alt_bn128_twist_mul_by_b_c1

◆ mul_by_q()

alt_bn128_G2 libff::alt_bn128_G2::mul_by_q ( ) const

Definition at line 371 of file alt_bn128_g2.cpp.

372{
373 return alt_bn128_G2(alt_bn128_twist_mul_by_q_X * (this->X).Frobenius_map(1),
374 alt_bn128_twist_mul_by_q_Y * (this->Y).Frobenius_map(1),
375 (this->Z).Frobenius_map(1));
376}
alt_bn128_Fq2 alt_bn128_twist_mul_by_q_Y
alt_bn128_Fq2 alt_bn128_twist_mul_by_q_X
Here is the call graph for this function:
Here is the caller graph for this function:

◆ one()

alt_bn128_G2 libff::alt_bn128_G2::one ( )
static

Definition at line 412 of file alt_bn128_g2.cpp.

413{
414 return G2_one;
415}
static alt_bn128_G2 G2_one
Here is the caller graph for this function:

◆ operator!=()

bool libff::alt_bn128_G2::operator!= ( const alt_bn128_G2 & other) const

Definition at line 148 of file alt_bn128_g2.cpp.

149{
150 return !(operator==(other));
151}
bool operator==(const alt_bn128_G2 &other) const
Here is the call graph for this function:

◆ operator+()

alt_bn128_G2 libff::alt_bn128_G2::operator+ ( const alt_bn128_G2 & other) const

Definition at line 153 of file alt_bn128_g2.cpp.

154{
155 // handle special cases having to do with O
156 if (this->is_zero())
157 {
158 return other;
159 }
160
161 if (other.is_zero())
162 {
163 return *this;
164 }
165
166 // no need to handle points of order 2,4
167 // (they cannot exist in a prime-order subgroup)
168
169 // check for doubling case
170
171 // using Jacobian coordinates so:
172 // (X1:Y1:Z1) = (X2:Y2:Z2)
173 // iff
174 // X1/Z1^2 == X2/Z2^2 and Y1/Z1^3 == Y2/Z2^3
175 // iff
176 // X1 * Z2^2 == X2 * Z1^2 and Y1 * Z2^3 == Y2 * Z1^3
177
178 alt_bn128_Fq2 Z1Z1 = (this->Z).squared();
179 alt_bn128_Fq2 Z2Z2 = (other.Z).squared();
180
181 alt_bn128_Fq2 U1 = this->X * Z2Z2;
182 alt_bn128_Fq2 U2 = other.X * Z1Z1;
183
184 alt_bn128_Fq2 Z1_cubed = (this->Z) * Z1Z1;
185 alt_bn128_Fq2 Z2_cubed = (other.Z) * Z2Z2;
186
187 alt_bn128_Fq2 S1 = (this->Y) * Z2_cubed; // S1 = Y1 * Z2 * Z2Z2
188 alt_bn128_Fq2 S2 = (other.Y) * Z1_cubed; // S2 = Y2 * Z1 * Z1Z1
189
190 if (U1 == U2 && S1 == S2)
191 {
192 // dbl case; nothing of above can be reused
193 return this->dbl();
194 }
195
196 // rest of add case
197 alt_bn128_Fq2 H = U2 - U1; // H = U2-U1
198 alt_bn128_Fq2 S2_minus_S1 = S2-S1;
199 alt_bn128_Fq2 I = (H+H).squared(); // I = (2 * H)^2
200 alt_bn128_Fq2 J = H * I; // J = H * I
201 alt_bn128_Fq2 r = S2_minus_S1 + S2_minus_S1; // r = 2 * (S2-S1)
202 alt_bn128_Fq2 V = U1 * I; // V = U1 * I
203 alt_bn128_Fq2 X3 = r.squared() - J - (V+V); // X3 = r^2 - J - 2 * V
204 alt_bn128_Fq2 S1_J = S1 * J;
205 alt_bn128_Fq2 Y3 = r * (V-X3) - (S1_J+S1_J); // Y3 = r * (V-X3)-2 S1 J
206 alt_bn128_Fq2 Z3 = ((this->Z+other.Z).squared()-Z1Z1-Z2Z2) * H; // Z3 = ((Z1+Z2)^2-Z1Z1-Z2Z2) * H
207
208 return alt_bn128_G2(X3, Y3, Z3);
209}
Here is the call graph for this function:

◆ operator-() [1/2]

alt_bn128_G2 libff::alt_bn128_G2::operator- ( ) const

Definition at line 211 of file alt_bn128_g2.cpp.

212{
213 return alt_bn128_G2(this->X, -(this->Y), this->Z);
214}
Here is the call graph for this function:

◆ operator-() [2/2]

alt_bn128_G2 libff::alt_bn128_G2::operator- ( const alt_bn128_G2 & other) const

Definition at line 217 of file alt_bn128_g2.cpp.

218{
219 return (*this) + (-other);
220}

◆ operator==()

bool libff::alt_bn128_G2::operator== ( const alt_bn128_G2 & other) const

Definition at line 108 of file alt_bn128_g2.cpp.

109{
110 if (this->is_zero())
111 {
112 return other.is_zero();
113 }
114
115 if (other.is_zero())
116 {
117 return false;
118 }
119
120 /* now neither is O */
121
122 // using Jacobian coordinates so:
123 // (X1:Y1:Z1) = (X2:Y2:Z2)
124 // iff
125 // X1/Z1^2 == X2/Z2^2 and Y1/Z1^3 == Y2/Z2^3
126 // iff
127 // X1 * Z2^2 == X2 * Z1^2 and Y1 * Z2^3 == Y2 * Z1^3
128
129 alt_bn128_Fq2 Z1_squared = (this->Z).squared();
130 alt_bn128_Fq2 Z2_squared = (other.Z).squared();
131
132 if ((this->X * Z2_squared) != (other.X * Z1_squared))
133 {
134 return false;
135 }
136
137 alt_bn128_Fq2 Z1_cubed = (this->Z) * Z1_squared;
138 alt_bn128_Fq2 Z2_cubed = (other.Z) * Z2_squared;
139
140 if ((this->Y * Z2_cubed) != (other.Y * Z1_cubed))
141 {
142 return false;
143 }
144
145 return true;
146}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ order()

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

Definition at line 74 of file alt_bn128_g2.hpp.

74{ return scalar_field::field_char(); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print()

void libff::alt_bn128_G2::print ( ) const

Definition at line 38 of file alt_bn128_g2.cpp.

39{
40 if (this->is_zero())
41 {
42 printf("O\n");
43 }
44 else
45 {
46 alt_bn128_G2 copy(*this);
47 copy.to_affine_coordinates();
48 gmp_printf("(%Nd*z + %Nd , %Nd*z + %Nd)\n",
49 copy.X.c1.as_bigint().data, alt_bn128_Fq::num_limbs,
50 copy.X.c0.as_bigint().data, alt_bn128_Fq::num_limbs,
51 copy.Y.c1.as_bigint().data, alt_bn128_Fq::num_limbs,
52 copy.Y.c0.as_bigint().data, alt_bn128_Fq::num_limbs);
53 }
54}
LOGGING_API void printf(Category category, const char *format,...)
Definition Logging.cpp:30
void copy(const path &from, const path &to)
Here is the call graph for this function:

◆ print_coordinates()

void libff::alt_bn128_G2::print_coordinates ( ) const

Definition at line 56 of file alt_bn128_g2.cpp.

57{
58 if (this->is_zero())
59 {
60 printf("O\n");
61 }
62 else
63 {
64 gmp_printf("(%Nd*z + %Nd : %Nd*z + %Nd : %Nd*z + %Nd)\n",
65 this->X.c1.as_bigint().data, alt_bn128_Fq::num_limbs,
66 this->X.c0.as_bigint().data, alt_bn128_Fq::num_limbs,
67 this->Y.c1.as_bigint().data, alt_bn128_Fq::num_limbs,
68 this->Y.c0.as_bigint().data, alt_bn128_Fq::num_limbs,
69 this->Z.c1.as_bigint().data, alt_bn128_Fq::num_limbs,
70 this->Z.c0.as_bigint().data, alt_bn128_Fq::num_limbs);
71 }
72}
Here is the call graph for this function:

◆ random_element()

alt_bn128_G2 libff::alt_bn128_G2::random_element ( )
static

Definition at line 417 of file alt_bn128_g2.cpp.

418{
419 return (alt_bn128_Fr::random_element().as_bigint()) * G2_one;
420}
static Fp_model< n, modulus > random_element()
Here is the call graph for this function:

◆ size_in_bits()

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

Definition at line 72 of file alt_bn128_g2.hpp.

Here is the call graph for this function:

◆ to_affine_coordinates()

void libff::alt_bn128_G2::to_affine_coordinates ( )

Definition at line 74 of file alt_bn128_g2.cpp.

75{
76 if (this->is_zero())
77 {
78 this->X = alt_bn128_Fq2::zero();
79 this->Y = alt_bn128_Fq2::one();
80 this->Z = alt_bn128_Fq2::zero();
81 }
82 else
83 {
84 alt_bn128_Fq2 Z_inv = Z.inverse();
85 alt_bn128_Fq2 Z2_inv = Z_inv.squared();
86 alt_bn128_Fq2 Z3_inv = Z2_inv * Z_inv;
87 this->X = this->X * Z2_inv;
88 this->Y = this->Y * Z3_inv;
89 this->Z = alt_bn128_Fq2::one();
90 }
91}
Fp2_model inverse() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ to_special()

void libff::alt_bn128_G2::to_special ( )

Definition at line 93 of file alt_bn128_g2.cpp.

94{
96}
Here is the call graph for this function:

◆ zero()

alt_bn128_G2 libff::alt_bn128_G2::zero ( )
static

Definition at line 407 of file alt_bn128_g2.cpp.

408{
409 return G2_zero;
410}
Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & out,
const alt_bn128_G2 & g )
friend

Definition at line 422 of file alt_bn128_g2.cpp.

423{
425 copy.to_affine_coordinates();
426 out << (copy.is_zero() ? 1 : 0) << OUTPUT_SEPARATOR;
427#ifdef NO_PT_COMPRESSION
428 out << copy.X << OUTPUT_SEPARATOR << copy.Y;
429#else
430 /* storing LSB of Y */
431 out << copy.X << OUTPUT_SEPARATOR << (copy.Y.c0.as_bigint().data[0] & 1);
432#endif
433
434 return out;
435}
#define OUTPUT_SEPARATOR

◆ operator>>

std::istream & operator>> ( std::istream & in,
alt_bn128_G2 & g )
friend

Definition at line 437 of file alt_bn128_g2.cpp.

438{
439 char is_zero;
440 alt_bn128_Fq2 tX, tY;
441
442#ifdef NO_PT_COMPRESSION
443 in >> is_zero >> tX >> tY;
444 is_zero -= '0';
445#else
446 in.read((char*)&is_zero, 1); // this reads is_zero;
447 is_zero -= '0';
449
450 unsigned char Y_lsb;
451 in >> tX;
453 in.read((char*)&Y_lsb, 1);
454 Y_lsb -= '0';
455
456 // y = +/- sqrt(x^3 + b)
457 if (!is_zero)
458 {
459 alt_bn128_Fq2 tX2 = tX.squared();
460 alt_bn128_Fq2 tY2 = tX2 * tX + alt_bn128_twist_coeff_b;
461 tY = tY2.sqrt();
462
463 if ((tY.c0.as_bigint().data[0] & 1) != Y_lsb)
464 {
465 tY = -tY;
466 }
467 }
468#endif
469 // using projective coordinates
470 if (!is_zero)
471 {
472 g.X = tX;
473 g.Y = tY;
474 g.Z = alt_bn128_Fq2::one();
475 }
476 else
477 {
478 g = alt_bn128_G2::zero();
479 }
480
481 return in;
482}
Fp2_model sqrt() const
static alt_bn128_G2 zero()
void consume_OUTPUT_SEPARATOR(std::istream &in)

Member Data Documentation

◆ fixed_base_exp_window_table

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

Definition at line 28 of file alt_bn128_g2.hpp.

◆ G2_one

alt_bn128_G2 libff::alt_bn128_G2::G2_one = {}
static

Definition at line 30 of file alt_bn128_g2.hpp.

◆ G2_zero

alt_bn128_G2 libff::alt_bn128_G2::G2_zero = {}
static

Definition at line 29 of file alt_bn128_g2.hpp.

◆ initialized

bool libff::alt_bn128_G2::initialized = false
static

Definition at line 31 of file alt_bn128_g2.hpp.

◆ wnaf_window_table

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

Definition at line 27 of file alt_bn128_g2.hpp.

◆ X

alt_bn128_Fq2 libff::alt_bn128_G2::X

Definition at line 37 of file alt_bn128_g2.hpp.

◆ Y

alt_bn128_Fq2 libff::alt_bn128_G2::Y

Definition at line 37 of file alt_bn128_g2.hpp.

◆ Z

alt_bn128_Fq2 libff::alt_bn128_G2::Z

Definition at line 37 of file alt_bn128_g2.hpp.


The documentation for this class was generated from the following files: