Clearmatics Libff  0.1
C++ library for Finite Fields and Elliptic Curves
mnt6_g2.hpp
Go to the documentation of this file.
1 
12 #ifndef MNT6_G2_HPP_
13 #define MNT6_G2_HPP_
14 
17 #include <vector>
18 
19 namespace libff
20 {
21 
22 class mnt6_G2;
23 std::ostream &operator<<(std::ostream &, const mnt6_G2 &);
24 std::istream &operator>>(std::istream &, mnt6_G2 &);
25 
26 class mnt6_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 mnt6_G2 G2_zero;
36  static mnt6_G2 G2_one;
37  static mnt6_Fq3 twist;
38  static mnt6_Fq3 coeff_a;
39  static mnt6_Fq3 coeff_b;
40 
44 
45  // Cofactor
46  static const mp_size_t h_bitcount = 596;
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  mnt6_G2();
55  mnt6_G2(const mnt6_Fq3 &X, const mnt6_Fq3 &Y, const mnt6_Fq3 &Z)
56  : X(X), Y(Y), Z(Z)
57  {
58  }
59 
60  static mnt6_Fq3 mul_by_a(const mnt6_Fq3 &elt);
61  static mnt6_Fq3 mul_by_b(const mnt6_Fq3 &elt);
62 
63  void print() const;
64  void print_coordinates() const;
65 
66  void to_affine_coordinates();
67  void to_special();
68  bool is_special() const;
69 
70  bool is_zero() const;
71 
72  bool operator==(const mnt6_G2 &other) const;
73  bool operator!=(const mnt6_G2 &other) const;
74 
75  mnt6_G2 operator+(const mnt6_G2 &other) const;
76  mnt6_G2 operator-() const;
77  mnt6_G2 operator-(const mnt6_G2 &other) const;
78 
79  mnt6_G2 add(const mnt6_G2 &other) const;
80  mnt6_G2 mixed_add(const mnt6_G2 &other) const;
81  mnt6_G2 dbl() const;
82  mnt6_G2 mul_by_q() const;
83  mnt6_G2 mul_by_cofactor() const;
84 
85  bool is_well_formed() const;
86  bool is_in_safe_subgroup() const;
87 
88  static const mnt6_G2 &zero();
89  static const mnt6_G2 &one();
90  static mnt6_G2 random_element();
91 
92  static size_t size_in_bits() { return twist_field::size_in_bits() + 1; }
94  {
95  return base_field::field_char();
96  }
98  {
99  return scalar_field::field_char();
100  }
101 
102  void write_uncompressed(std::ostream &) const;
103  void write_compressed(std::ostream &) const;
104  static void read_uncompressed(std::istream &, mnt6_G2 &);
105  static void read_compressed(std::istream &, mnt6_G2 &);
106 
107  static void batch_to_special_all_non_zeros(std::vector<mnt6_G2> &vec);
108 };
109 
110 template<mp_size_t m>
111 mnt6_G2 operator*(const bigint<m> &lhs, const mnt6_G2 &rhs)
112 {
113  return scalar_mul<mnt6_G2, m>(rhs, lhs);
114 }
115 
116 template<mp_size_t m, const bigint<m> &modulus_p>
118 {
119  return scalar_mul<mnt6_G2, m>(rhs, lhs.as_bigint());
120 }
121 
122 } // namespace libff
123 
124 #endif // MNT6_G2_HPP_
curve_utils.hpp
libff::mnt6_G2::is_in_safe_subgroup
bool is_in_safe_subgroup() const
Definition: mnt6_g2.cpp:468
libff::mnt6_G2::twist_field
mnt6_Fq3 twist_field
Definition: mnt6_g2.hpp:42
libff::mnt6_G2::coeff_b
static mnt6_Fq3 coeff_b
Definition: mnt6_g2.hpp:39
libff::mnt6_G2::Z
mnt6_Fq3 Z
Definition: mnt6_g2.hpp:51
libff::mnt6_G2::coeff_a
static mnt6_Fq3 coeff_a
Definition: mnt6_g2.hpp:38
libff::mnt6_G2::one
static const mnt6_G2 & one()
Definition: mnt6_g2.cpp:475
libff
Definition: ffi.cpp:8
libff::operator>>
std::istream & operator>>(std::istream &in, alt_bn128_G1 &g)
Definition: alt_bn128_g1.cpp:446
libff::mnt6_G2::X
mnt6_Fq3 X
Definition: mnt6_g2.hpp:51
libff::mnt6_G2::operator-
mnt6_G2 operator-() const
Definition: mnt6_g2.cpp:265
libff::mnt6_G2::print
void print() const
Definition: mnt6_g2.cpp:56
libff::mnt6_G2::G2_zero
static mnt6_G2 G2_zero
Definition: mnt6_g2.hpp:35
libff::mnt6_G2::print_coordinates
void print_coordinates() const
Definition: mnt6_g2.cpp:80
libff::mnt6_G2::is_special
bool is_special() const
Definition: mnt6_g2.cpp:125
libff::mnt6_G2
Definition: mnt6_g2.hpp:26
libff::mnt6_G2::size_in_bits
static size_t size_in_bits()
Definition: mnt6_g2.hpp:92
libff::mnt6_G2::Y
mnt6_Fq3 Y
Definition: mnt6_g2.hpp:51
libff::mnt6_G2::operator!=
bool operator!=(const mnt6_G2 &other) const
Definition: mnt6_g2.cpp:161
libff::mnt6_G2::h_bitcount
static const mp_size_t h_bitcount
Definition: mnt6_g2.hpp:46
libff::mnt6_G2::is_well_formed
bool is_well_formed() const
Definition: mnt6_g2.cpp:444
libff::mnt6_G2::operator==
bool operator==(const mnt6_G2 &other) const
Definition: mnt6_g2.cpp:136
libff::mnt6_G2::dbl
mnt6_G2 dbl() const
Definition: mnt6_g2.cpp:391
libff::mnt6_G2::write_uncompressed
void write_uncompressed(std::ostream &) const
Definition: mnt6_g2.cpp:482
libff::bigint< h_limbs >
libff::mnt6_G2::twist
static mnt6_Fq3 twist
Definition: mnt6_g2.hpp:37
libff::mnt6_G2::G2_one
static mnt6_G2 G2_one
Definition: mnt6_g2.hpp:36
libff::mnt6_G2::fixed_base_exp_window_table
static std::vector< size_t > fixed_base_exp_window_table
Definition: mnt6_g2.hpp:34
libff::mnt6_G2::zero
static const mnt6_G2 & zero()
Definition: mnt6_g2.cpp:473
libff::mnt6_G2::order
static bigint< scalar_field::num_limbs > order()
Definition: mnt6_g2.hpp:97
libff::Fp_model< mnt6_q_limbs, mnt6_modulus_q >::field_char
static const bigint< n > & field_char()
Definition: fp.hpp:136
libff::mnt6_G2::mnt6_G2
mnt6_G2()
Definition: mnt6_g2.cpp:33
libff::Fp3_model
Definition: fp3.hpp:18
libff::mnt6_G2::wnaf_window_table
static std::vector< size_t > wnaf_window_table
Definition: mnt6_g2.hpp:33
libff::mnt6_G2::mul_by_q
mnt6_G2 mul_by_q() const
Definition: mnt6_g2.cpp:434
libff::Fp_model::as_bigint
bigint< n > as_bigint() const
libff::Fp_model< mnt6_q_limbs, mnt6_modulus_q >
libff::mnt6_G2::read_uncompressed
static void read_uncompressed(std::istream &, mnt6_G2 &)
Definition: mnt6_g2.cpp:502
libff::mnt6_G2::mul_by_a
static mnt6_Fq3 mul_by_a(const mnt6_Fq3 &elt)
Definition: mnt6_g2.cpp:40
libff::mnt6_G2::write_compressed
void write_compressed(std::ostream &) const
Definition: mnt6_g2.cpp:491
libff::mnt6_G2::h
static bigint< h_limbs > h
Definition: mnt6_g2.hpp:49
libff::mnt6_G2::operator+
mnt6_G2 operator+(const mnt6_G2 &other) const
Definition: mnt6_g2.cpp:166
libff::operator<<
std::ostream & operator<<(std::ostream &out, const alt_bn128_G1 &g)
Definition: alt_bn128_g1.cpp:436
libff::mnt6_G2::mul_by_cofactor
mnt6_G2 mul_by_cofactor() const
Definition: mnt6_g2.cpp:442
mnt6_init.hpp
libff::mnt6_G2::base_field_char
static bigint< base_field::num_limbs > base_field_char()
Definition: mnt6_g2.hpp:93
libff::mnt6_G2::h_limbs
static const mp_size_t h_limbs
Definition: mnt6_g2.hpp:47
libff::operator*
alt_bn128_G1 operator*(const bigint< m > &lhs, const alt_bn128_G1 &rhs)
Definition: alt_bn128_g1.hpp:99
libff::mnt6_G2::batch_to_special_all_non_zeros
static void batch_to_special_all_non_zeros(std::vector< mnt6_G2 > &vec)
Definition: mnt6_g2.cpp:558
libff::mnt6_G2::read_compressed
static void read_compressed(std::istream &, mnt6_G2 &)
Definition: mnt6_g2.cpp:520
libff::Fp3_model< mnt6_q_limbs, mnt6_modulus_q >::size_in_bits
static size_t size_in_bits()
Definition: fp3.hpp:109
libff::mnt6_G2::scalar_field
mnt6_Fr scalar_field
Definition: mnt6_g2.hpp:43
libff::mnt6_G2::base_field
mnt6_Fq base_field
Definition: mnt6_g2.hpp:41
libff::mnt6_G2::add
mnt6_G2 add(const mnt6_G2 &other) const
Definition: mnt6_g2.cpp:275
libff::mnt6_G2::is_zero
bool is_zero() const
Definition: mnt6_g2.cpp:130
libff::mnt6_G2::mnt6_G2
mnt6_G2(const mnt6_Fq3 &X, const mnt6_Fq3 &Y, const mnt6_Fq3 &Z)
Definition: mnt6_g2.hpp:55
libff::mnt6_G2::random_element
static mnt6_G2 random_element()
Definition: mnt6_g2.cpp:477
libff::mnt6_G2::mixed_add
mnt6_G2 mixed_add(const mnt6_G2 &other) const
Definition: mnt6_g2.cpp:330
libff::mnt6_G2::mul_by_b
static mnt6_Fq3 mul_by_b(const mnt6_Fq3 &elt)
Definition: mnt6_g2.cpp:48
libff::mnt6_G2::to_affine_coordinates
void to_affine_coordinates()
Definition: mnt6_g2.cpp:109
libff::mnt6_G2::to_special
void to_special()
Definition: mnt6_g2.cpp:123