Clearmatics Libff  0.1
C++ library for Finite Fields and Elliptic Curves
alt_bn128_g2.hpp
Go to the documentation of this file.
1 
8 #ifndef ALT_BN128_G2_HPP_
9 #define ALT_BN128_G2_HPP_
12 #include <vector>
13 
14 namespace libff
15 {
16 
17 class alt_bn128_G2;
18 std::ostream &operator<<(std::ostream &, const alt_bn128_G2 &);
19 std::istream &operator>>(std::istream &, alt_bn128_G2 &);
20 
22 {
23 public:
24 #ifdef PROFILE_OP_COUNTS
25  static long long add_cnt;
26  static long long dbl_cnt;
27 #endif
28  static std::vector<size_t> wnaf_window_table;
29  static std::vector<size_t> fixed_base_exp_window_table;
34 
38 
39  // Cofactor
40  static const mp_size_t h_bitcount = 256;
41  static const mp_size_t h_limbs =
42  (h_bitcount + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS;
44 
46 
47  // using Jacobian coordinates
48  alt_bn128_G2();
50  const alt_bn128_Fq2 &X, const alt_bn128_Fq2 &Y, const alt_bn128_Fq2 &Z)
51  : X(X), Y(Y), Z(Z){};
52 
53  static alt_bn128_Fq2 mul_by_b(const alt_bn128_Fq2 &elt);
54 
55  void print() const;
56  void print_coordinates() const;
57 
58  void to_affine_coordinates();
59  void to_special();
60  bool is_special() const;
61 
62  bool is_zero() const;
63 
64  bool operator==(const alt_bn128_G2 &other) const;
65  bool operator!=(const alt_bn128_G2 &other) const;
66 
67  alt_bn128_G2 operator+(const alt_bn128_G2 &other) const;
68  alt_bn128_G2 operator-() const;
69  alt_bn128_G2 operator-(const alt_bn128_G2 &other) const;
70 
71  alt_bn128_G2 add(const alt_bn128_G2 &other) const;
72  alt_bn128_G2 mixed_add(const alt_bn128_G2 &other) const;
73  alt_bn128_G2 dbl() const;
74  alt_bn128_G2 mul_by_q() const;
76 
77  bool is_well_formed() const;
78  bool is_in_safe_subgroup() const;
79 
80  static const alt_bn128_G2 &zero();
81  static const alt_bn128_G2 &one();
83 
84  static size_t size_in_bits() { return twist_field::size_in_bits() + 1; }
86  {
87  return base_field::field_char();
88  }
90  {
91  return scalar_field::field_char();
92  }
93 
94  void write_uncompressed(std::ostream &) const;
95  void write_compressed(std::ostream &) const;
96  static void read_uncompressed(std::istream &, alt_bn128_G2 &);
97  static void read_compressed(std::istream &, alt_bn128_G2 &);
98 
99  static void batch_to_special_all_non_zeros(std::vector<alt_bn128_G2> &vec);
100 };
101 
102 template<mp_size_t m>
104 {
105  return scalar_mul<alt_bn128_G2, m>(rhs, lhs);
106 }
107 
108 template<mp_size_t m, const bigint<m> &modulus_p>
110  const Fp_model<m, modulus_p> &lhs, const alt_bn128_G2 &rhs)
111 {
112  return scalar_mul<alt_bn128_G2, m>(rhs, lhs.as_bigint());
113 }
114 
115 } // namespace libff
116 #endif // ALT_BN128_G2_HPP_
libff::alt_bn128_G2::read_uncompressed
static void read_uncompressed(std::istream &, alt_bn128_G2 &)
Definition: alt_bn128_g2.cpp:425
libff::alt_bn128_G2::batch_to_special_all_non_zeros
static void batch_to_special_all_non_zeros(std::vector< alt_bn128_G2 > &vec)
Definition: alt_bn128_g2.cpp:486
curve_utils.hpp
libff::alt_bn128_G2::is_special
bool is_special() const
Definition: alt_bn128_g2.cpp:103
libff::alt_bn128_G2::one
static const alt_bn128_G2 & one()
Definition: alt_bn128_g2.cpp:396
libff::alt_bn128_G2::operator==
bool operator==(const alt_bn128_G2 &other) const
Definition: alt_bn128_g2.cpp:110
libff::alt_bn128_G2::operator+
alt_bn128_G2 operator+(const alt_bn128_G2 &other) const
Definition: alt_bn128_g2.cpp:151
libff
Definition: ffi.cpp:8
libff::Fp2_model< alt_bn128_q_limbs, alt_bn128_modulus_q >::size_in_bits
static size_t size_in_bits()
Definition: fp2.hpp:108
libff::operator>>
std::istream & operator>>(std::istream &in, alt_bn128_G1 &g)
Definition: alt_bn128_g1.cpp:446
libff::alt_bn128_G2::h
static bigint< h_limbs > h
Definition: alt_bn128_g2.hpp:43
libff::alt_bn128_G2::Y
alt_bn128_Fq2 Y
Definition: alt_bn128_g2.hpp:45
libff::alt_bn128_G2::mul_by_q
alt_bn128_G2 mul_by_q() const
Definition: alt_bn128_g2.cpp:351
libff::alt_bn128_G2::order
static bigint< scalar_field::num_limbs > order()
Definition: alt_bn128_g2.hpp:89
libff::alt_bn128_G2::Z
alt_bn128_Fq2 Z
Definition: alt_bn128_g2.hpp:45
libff::alt_bn128_G2::size_in_bits
static size_t size_in_bits()
Definition: alt_bn128_g2.hpp:84
libff::alt_bn128_G2::X
alt_bn128_Fq2 X
Definition: alt_bn128_g2.hpp:45
libff::alt_bn128_G2::operator-
alt_bn128_G2 operator-() const
Definition: alt_bn128_g2.cpp:156
libff::alt_bn128_G2::scalar_field
alt_bn128_Fr scalar_field
Definition: alt_bn128_g2.hpp:37
libff::alt_bn128_G2::write_uncompressed
void write_uncompressed(std::ostream &) const
Definition: alt_bn128_g2.cpp:403
libff::alt_bn128_G2::fixed_base_exp_window_table
static std::vector< size_t > fixed_base_exp_window_table
Definition: alt_bn128_g2.hpp:29
libff::alt_bn128_G2::print
void print() const
Definition: alt_bn128_g2.cpp:43
libff::alt_bn128_G2::mul_by_cofactor
alt_bn128_G2 mul_by_cofactor() const
Definition: alt_bn128_g2.cpp:359
libff::alt_bn128_G2::G2_zero
static alt_bn128_G2 G2_zero
Definition: alt_bn128_g2.hpp:30
libff::alt_bn128_G2::base_field_char
static bigint< base_field::num_limbs > base_field_char()
Definition: alt_bn128_g2.hpp:85
libff::alt_bn128_G2::h_bitcount
static const mp_size_t h_bitcount
Definition: alt_bn128_g2.hpp:40
alt_bn128_init.hpp
libff::alt_bn128_G2::add
alt_bn128_G2 add(const alt_bn128_G2 &other) const
Definition: alt_bn128_g2.cpp:166
libff::alt_bn128_G2::coeff_a
static alt_bn128_Fq2 coeff_a
Definition: alt_bn128_g2.hpp:32
libff::alt_bn128_G2::base_field
alt_bn128_Fq base_field
Definition: alt_bn128_g2.hpp:35
libff::bigint< h_limbs >
libff::alt_bn128_G2
Definition: alt_bn128_g2.hpp:21
libff::alt_bn128_G2::twist_field
alt_bn128_Fq2 twist_field
Definition: alt_bn128_g2.hpp:36
libff::alt_bn128_G2::is_well_formed
bool is_well_formed() const
Definition: alt_bn128_g2.cpp:364
libff::Fp_model< alt_bn128_q_limbs, alt_bn128_modulus_q >::field_char
static const bigint< n > & field_char()
Definition: fp.hpp:136
libff::Fp_model::as_bigint
bigint< n > as_bigint() const
libff::Fp_model< alt_bn128_q_limbs, alt_bn128_modulus_q >
libff::alt_bn128_G2::alt_bn128_G2
alt_bn128_G2()
Definition: alt_bn128_g2.cpp:29
libff::operator<<
std::ostream & operator<<(std::ostream &out, const alt_bn128_G1 &g)
Definition: alt_bn128_g1.cpp:436
libff::alt_bn128_G2::to_affine_coordinates
void to_affine_coordinates()
Definition: alt_bn128_g2.cpp:85
libff::operator*
alt_bn128_G1 operator*(const bigint< m > &lhs, const alt_bn128_G1 &rhs)
Definition: alt_bn128_g1.hpp:99
libff::alt_bn128_G2::read_compressed
static void read_compressed(std::istream &, alt_bn128_G2 &)
Definition: alt_bn128_g2.cpp:440
libff::alt_bn128_G2::zero
static const alt_bn128_G2 & zero()
Definition: alt_bn128_g2.cpp:394
libff::Fp2_model< alt_bn128_q_limbs, alt_bn128_modulus_q >
libff::alt_bn128_G2::wnaf_window_table
static std::vector< size_t > wnaf_window_table
Definition: alt_bn128_g2.hpp:28
libff::alt_bn128_G2::alt_bn128_G2
alt_bn128_G2(const alt_bn128_Fq2 &X, const alt_bn128_Fq2 &Y, const alt_bn128_Fq2 &Z)
Definition: alt_bn128_g2.hpp:49
libff::alt_bn128_G2::G2_one
static alt_bn128_G2 G2_one
Definition: alt_bn128_g2.hpp:31
libff::alt_bn128_G2::to_special
void to_special()
Definition: alt_bn128_g2.cpp:101
libff::alt_bn128_G2::is_zero
bool is_zero() const
Definition: alt_bn128_g2.cpp:108
libff::alt_bn128_G2::operator!=
bool operator!=(const alt_bn128_G2 &other) const
Definition: alt_bn128_g2.cpp:146
libff::alt_bn128_G2::coeff_b
static alt_bn128_Fq2 coeff_b
Definition: alt_bn128_g2.hpp:33
libff::alt_bn128_G2::random_element
static alt_bn128_G2 random_element()
Definition: alt_bn128_g2.cpp:398
libff::alt_bn128_G2::mul_by_b
static alt_bn128_Fq2 mul_by_b(const alt_bn128_Fq2 &elt)
Definition: alt_bn128_g2.cpp:36
libff::alt_bn128_G2::write_compressed
void write_compressed(std::ostream &) const
Definition: alt_bn128_g2.cpp:412
libff::alt_bn128_G2::dbl
alt_bn128_G2 dbl() const
Definition: alt_bn128_g2.cpp:311
libff::alt_bn128_G2::mixed_add
alt_bn128_G2 mixed_add(const alt_bn128_G2 &other) const
Definition: alt_bn128_g2.cpp:234
libff::alt_bn128_G2::print_coordinates
void print_coordinates() const
Definition: alt_bn128_g2.cpp:63
libff::alt_bn128_G2::h_limbs
static const mp_size_t h_limbs
Definition: alt_bn128_g2.hpp:41
libff::alt_bn128_G2::is_in_safe_subgroup
bool is_in_safe_subgroup() const
Definition: alt_bn128_g2.cpp:389