Clearmatics Libff  0.1
C++ library for Finite Fields and Elliptic Curves
mnt4_g2.hpp
Go to the documentation of this file.
1 
12 #ifndef MNT4_G2_HPP_
13 #define MNT4_G2_HPP_
14 
17 #include <vector>
18 
19 namespace libff
20 {
21 
22 class mnt4_G2;
23 std::ostream &operator<<(std::ostream &, const mnt4_G2 &);
24 std::istream &operator>>(std::istream &, mnt4_G2 &);
25 
26 class mnt4_G2
27 {
28 public:
29 #ifdef PROFILE_OP_COUNTS
30  static long long add_cnt;
31  static long long dbl_cnt;
32 #endif
33  static std::vector<size_t> wnaf_window_table;
34  static std::vector<size_t> fixed_base_exp_window_table;
35  static mnt4_G2 G2_zero;
36  static mnt4_G2 G2_one;
37  static mnt4_Fq2 twist;
38  static mnt4_Fq2 coeff_a;
39  static mnt4_Fq2 coeff_b;
40 
44 
45  // Cofactor
46  static const mp_size_t h_bitcount = 298;
47  static const mp_size_t h_limbs =
48  (h_bitcount + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS;
50 
52 
53  // using projective coordinates
54  mnt4_G2();
55  mnt4_G2(const mnt4_Fq2 &X, const mnt4_Fq2 &Y, const mnt4_Fq2 &Z)
56  : X(X), Y(Y), Z(Z){};
57 
58  static mnt4_Fq2 mul_by_a(const mnt4_Fq2 &elt);
59  static mnt4_Fq2 mul_by_b(const mnt4_Fq2 &elt);
60 
61  void print() const;
62  void print_coordinates() const;
63 
64  void to_affine_coordinates();
65  void to_special();
66  bool is_special() const;
67 
68  bool is_zero() const;
69 
70  bool operator==(const mnt4_G2 &other) const;
71  bool operator!=(const mnt4_G2 &other) const;
72 
73  mnt4_G2 operator+(const mnt4_G2 &other) const;
74  mnt4_G2 operator-() const;
75  mnt4_G2 operator-(const mnt4_G2 &other) const;
76 
77  mnt4_G2 add(const mnt4_G2 &other) const;
78  mnt4_G2 mixed_add(const mnt4_G2 &other) const;
79  mnt4_G2 dbl() const;
80  mnt4_G2 mul_by_q() const;
81  mnt4_G2 mul_by_cofactor() const;
82 
83  bool is_well_formed() const;
84  bool is_in_safe_subgroup() const;
85 
86  static const mnt4_G2 &zero();
87  static const mnt4_G2 &one();
88  static mnt4_G2 random_element();
89 
90  static size_t size_in_bits() { return mnt4_Fq2::size_in_bits() + 1; }
92  {
93  return mnt4_Fq::field_char();
94  }
96 
97  void write_uncompressed(std::ostream &) const;
98  void write_compressed(std::ostream &) const;
99  static void read_uncompressed(std::istream &, mnt4_G2 &);
100  static void read_compressed(std::istream &, mnt4_G2 &);
101 
102  static void batch_to_special_all_non_zeros(std::vector<mnt4_G2> &vec);
103 };
104 
105 template<mp_size_t m>
106 mnt4_G2 operator*(const bigint<m> &lhs, const mnt4_G2 &rhs)
107 {
108  return scalar_mul<mnt4_G2, m>(rhs, lhs);
109 }
110 
111 template<mp_size_t m, const bigint<m> &modulus_p>
113 {
114  return scalar_mul<mnt4_G2, m>(rhs, lhs.as_bigint());
115 }
116 
117 } // namespace libff
118 
119 #endif // MNT4_G2_HPP_
curve_utils.hpp
libff::mnt4_G2
Definition: mnt4_g2.hpp:26
libff::mnt4_G2::write_compressed
void write_compressed(std::ostream &) const
Definition: mnt4_g2.cpp:477
libff::mnt4_G2::print_coordinates
void print_coordinates() const
Definition: mnt4_g2.cpp:74
libff::mnt4_G2::add
mnt4_G2 add(const mnt4_G2 &other) const
Definition: mnt4_g2.cpp:262
libff::mnt4_G2::h_bitcount
static const mp_size_t h_bitcount
Definition: mnt4_g2.hpp:46
libff::mnt4_G2::G2_one
static mnt4_G2 G2_one
Definition: mnt4_g2.hpp:36
libff::mnt4_G2::X
mnt4_Fq2 X
Definition: mnt4_g2.hpp:51
libff
Definition: ffi.cpp:8
libff::mnt4_G2::h
static bigint< h_limbs > h
Definition: mnt4_g2.hpp:49
libff::Fp2_model< mnt4_q_limbs, mnt4_modulus_q >::size_in_bits
static size_t size_in_bits()
Definition: fp2.hpp:108
libff::mnt4_G2::read_compressed
static void read_compressed(std::istream &, mnt4_G2 &)
Definition: mnt4_g2.cpp:505
libff::mnt4_G2::coeff_b
static mnt4_Fq2 coeff_b
Definition: mnt4_g2.hpp:39
libff::operator>>
std::istream & operator>>(std::istream &in, alt_bn128_G1 &g)
Definition: alt_bn128_g1.cpp:446
libff::mnt4_G2::twist
static mnt4_Fq2 twist
Definition: mnt4_g2.hpp:37
libff::mnt4_G2::operator!=
bool operator!=(const mnt4_G2 &other) const
Definition: mnt4_g2.cpp:147
libff::mnt4_G2::is_well_formed
bool is_well_formed() const
Definition: mnt4_g2.cpp:431
libff::mnt4_G2::twist_field
mnt4_Fq2 twist_field
Definition: mnt4_g2.hpp:42
libff::mnt4_G2::base_field_char
static bigint< mnt4_Fq::num_limbs > base_field_char()
Definition: mnt4_g2.hpp:91
libff::mnt4_G2::size_in_bits
static size_t size_in_bits()
Definition: mnt4_g2.hpp:90
libff::mnt4_G2::operator+
mnt4_G2 operator+(const mnt4_G2 &other) const
Definition: mnt4_g2.cpp:152
libff::mnt4_G2::write_uncompressed
void write_uncompressed(std::ostream &) const
Definition: mnt4_g2.cpp:468
libff::mnt4_G2::to_affine_coordinates
void to_affine_coordinates()
Definition: mnt4_g2.cpp:96
libff::mnt4_G2::Z
mnt4_Fq2 Z
Definition: mnt4_g2.hpp:51
libff::mnt4_G2::mnt4_G2
mnt4_G2()
Definition: mnt4_g2.cpp:47
libff::mnt4_G2::batch_to_special_all_non_zeros
static void batch_to_special_all_non_zeros(std::vector< mnt4_G2 > &vec)
Definition: mnt4_g2.cpp:541
libff::mnt4_G2::is_special
bool is_special() const
Definition: mnt4_g2.cpp:112
libff::mnt4_G2::random_element
static mnt4_G2 random_element()
Definition: mnt4_g2.cpp:463
libff::mnt4_G2::fixed_base_exp_window_table
static std::vector< size_t > fixed_base_exp_window_table
Definition: mnt4_g2.hpp:34
libff::mnt4_G2::G2_zero
static mnt4_G2 G2_zero
Definition: mnt4_g2.hpp:35
libff::bigint< h_limbs >
mnt4_init.hpp
libff::Fp_model< mnt4_q_limbs, mnt4_modulus_q >::field_char
static const bigint< n > & field_char()
Definition: fp.hpp:136
libff::mnt4_G2::print
void print() const
Definition: mnt4_g2.cpp:54
libff::Fp_model::as_bigint
bigint< n > as_bigint() const
libff::mnt4_G2::scalar_field
mnt4_Fr scalar_field
Definition: mnt4_g2.hpp:43
libff::Fp_model< mnt4_q_limbs, mnt4_modulus_q >
libff::mnt4_G2::coeff_a
static mnt4_Fq2 coeff_a
Definition: mnt4_g2.hpp:38
libff::mnt4_G2::read_uncompressed
static void read_uncompressed(std::istream &, mnt4_G2 &)
Definition: mnt4_g2.cpp:488
libff::operator<<
std::ostream & operator<<(std::ostream &out, const alt_bn128_G1 &g)
Definition: alt_bn128_g1.cpp:436
libff::mnt4_G2::one
static const mnt4_G2 & one()
Definition: mnt4_g2.cpp:461
libff::operator*
alt_bn128_G1 operator*(const bigint< m > &lhs, const alt_bn128_G1 &rhs)
Definition: alt_bn128_g1.hpp:99
libff::mnt4_G2::mixed_add
mnt4_G2 mixed_add(const mnt4_G2 &other) const
Definition: mnt4_g2.cpp:317
libff::Fp2_model
Definition: fp2.hpp:18
libff::mnt4_G2::mul_by_a
static mnt4_Fq2 mul_by_a(const mnt4_Fq2 &elt)
Definition: mnt4_g2.cpp:33
libff::mnt4_G2::dbl
mnt4_G2 dbl() const
Definition: mnt4_g2.cpp:378
libff::mnt4_G2::to_special
void to_special()
Definition: mnt4_g2.cpp:110
libff::mnt4_G2::Y
mnt4_Fq2 Y
Definition: mnt4_g2.hpp:51
libff::mnt4_G2::operator-
mnt4_G2 operator-() const
Definition: mnt4_g2.cpp:252
libff::mnt4_G2::operator==
bool operator==(const mnt4_G2 &other) const
Definition: mnt4_g2.cpp:122
libff::mnt4_G2::base_field
mnt4_Fq base_field
Definition: mnt4_g2.hpp:41
libff::mnt4_G2::wnaf_window_table
static std::vector< size_t > wnaf_window_table
Definition: mnt4_g2.hpp:33
libff::mnt4_G2::h_limbs
static const mp_size_t h_limbs
Definition: mnt4_g2.hpp:47
libff::mnt4_G2::mul_by_cofactor
mnt4_G2 mul_by_cofactor() const
Definition: mnt4_g2.cpp:429
libff::mnt4_G2::is_in_safe_subgroup
bool is_in_safe_subgroup() const
Definition: mnt4_g2.cpp:454
libff::mnt4_G2::mul_by_q
mnt4_G2 mul_by_q() const
Definition: mnt4_g2.cpp:421
libff::mnt4_G2::mul_by_b
static mnt4_Fq2 mul_by_b(const mnt4_Fq2 &elt)
Definition: mnt4_g2.cpp:40
libff::mnt4_G2::is_zero
bool is_zero() const
Definition: mnt4_g2.cpp:117
libff::mnt4_G2::order
static bigint< mnt4_Fr::num_limbs > order()
Definition: mnt4_g2.hpp:95
libff::mnt4_G2::mnt4_G2
mnt4_G2(const mnt4_Fq2 &X, const mnt4_Fq2 &Y, const mnt4_Fq2 &Z)
Definition: mnt4_g2.hpp:55
libff::mnt4_G2::zero
static const mnt4_G2 & zero()
Definition: mnt4_g2.cpp:459