Clearmatics Libff  0.1
C++ library for Finite Fields and Elliptic Curves
mnt6_g1.hpp
Go to the documentation of this file.
1 
12 #ifndef MNT6_G1_HPP_
13 #define MNT6_G1_HPP_
14 
17 #include <vector>
18 
19 namespace libff
20 {
21 
22 class mnt6_G1;
23 std::ostream &operator<<(std::ostream &, const mnt6_G1 &);
24 std::istream &operator>>(std::istream &, mnt6_G1 &);
25 
26 class mnt6_G1
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_G1 G1_zero;
36  static mnt6_G1 G1_one;
37  static mnt6_Fq coeff_a;
38  static mnt6_Fq coeff_b;
39 
42 
43  // Cofactor
44  static const mp_size_t h_bitcount = 1;
45  static const mp_size_t h_limbs =
46  (h_bitcount + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS;
48 
49  mnt6_Fq X, Y, Z;
50 
51  // using projective coordinates
52  mnt6_G1();
53  mnt6_G1(const mnt6_Fq &X, const mnt6_Fq &Y)
54  : X(X), Y(Y), Z(base_field::one())
55  {
56  }
57  mnt6_G1(const mnt6_Fq &X, const mnt6_Fq &Y, const mnt6_Fq &Z)
58  : X(X), Y(Y), Z(Z)
59  {
60  }
61 
62  void print() const;
63  void print_coordinates() const;
64 
65  void to_affine_coordinates();
66  void to_special();
67  bool is_special() const;
68 
69  bool is_zero() const;
70 
71  bool operator==(const mnt6_G1 &other) const;
72  bool operator!=(const mnt6_G1 &other) const;
73 
74  mnt6_G1 operator+(const mnt6_G1 &other) const;
75  mnt6_G1 operator-() const;
76  mnt6_G1 operator-(const mnt6_G1 &other) const;
77 
78  mnt6_G1 add(const mnt6_G1 &other) const;
79  mnt6_G1 mixed_add(const mnt6_G1 &other) const;
80  mnt6_G1 dbl() const;
81  mnt6_G1 mul_by_cofactor() const;
82 
83  bool is_well_formed() const;
84  bool is_in_safe_subgroup() const;
85 
86  static const mnt6_G1 &zero();
87  static const mnt6_G1 &one();
88  static mnt6_G1 random_element();
89 
90  static size_t size_in_bits() { return base_field::size_in_bits() + 1; }
92  {
93  return base_field::field_char();
94  }
96  {
97  return scalar_field::field_char();
98  }
99 
100  void write_uncompressed(std::ostream &) const;
101  void write_compressed(std::ostream &) const;
102  static void read_uncompressed(std::istream &, mnt6_G1 &);
103  static void read_compressed(std::istream &, mnt6_G1 &);
104 
105  static void batch_to_special_all_non_zeros(std::vector<mnt6_G1> &vec);
106 };
107 
108 template<mp_size_t m>
109 mnt6_G1 operator*(const bigint<m> &lhs, const mnt6_G1 &rhs)
110 {
111  return scalar_mul<mnt6_G1, m>(rhs, lhs);
112 }
113 
114 template<mp_size_t m, const bigint<m> &modulus_p>
116 {
117  return scalar_mul<mnt6_G1, m>(rhs, lhs.as_bigint());
118 }
119 
120 } // namespace libff
121 
122 #endif // MNT6_G1_HPP_
libff::mnt6_G1::to_special
void to_special()
Definition: mnt6_g1.cpp:85
curve_utils.hpp
libff::mnt6_G1::mixed_add
mnt6_G1 mixed_add(const mnt6_G1 &other) const
Definition: mnt6_g1.cpp:291
libff::mnt6_G1::coeff_a
static mnt6_Fq coeff_a
Definition: mnt6_g1.hpp:37
libff::mnt6_G1::operator+
mnt6_G1 operator+(const mnt6_G1 &other) const
Definition: mnt6_g1.cpp:127
libff::mnt6_G1::mnt6_G1
mnt6_G1(const mnt6_Fq &X, const mnt6_Fq &Y, const mnt6_Fq &Z)
Definition: mnt6_g1.hpp:57
libff
Definition: ffi.cpp:8
libff::mnt6_G1::mul_by_cofactor
mnt6_G1 mul_by_cofactor() const
Definition: mnt6_g1.cpp:395
libff::mnt6_G1::size_in_bits
static size_t size_in_bits()
Definition: mnt6_g1.hpp:90
libff::mnt6_G1::read_uncompressed
static void read_uncompressed(std::istream &, mnt6_G1 &)
Definition: mnt6_g1.cpp:454
libff::mnt6_G1::G1_one
static mnt6_G1 G1_one
Definition: mnt6_g1.hpp:36
libff::operator>>
std::istream & operator>>(std::istream &in, alt_bn128_G1 &g)
Definition: alt_bn128_g1.cpp:446
libff::mnt6_G1::Z
mnt6_Fq Z
Definition: mnt6_g1.hpp:49
libff::mnt6_G1::operator-
mnt6_G1 operator-() const
Definition: mnt6_g1.cpp:226
libff::mnt6_G1::is_zero
bool is_zero() const
Definition: mnt6_g1.cpp:92
libff::mnt6_G1::G1_zero
static mnt6_G1 G1_zero
Definition: mnt6_g1.hpp:35
libff::mnt6_G1::to_affine_coordinates
void to_affine_coordinates()
Definition: mnt6_g1.cpp:71
libff::mnt6_G1::operator==
bool operator==(const mnt6_G1 &other) const
Definition: mnt6_g1.cpp:97
libff::mnt6_G1::coeff_b
static mnt6_Fq coeff_b
Definition: mnt6_g1.hpp:38
libff::mnt6_G1::add
mnt6_G1 add(const mnt6_G1 &other) const
Definition: mnt6_g1.cpp:236
libff::mnt6_G1::is_in_safe_subgroup
bool is_in_safe_subgroup() const
Definition: mnt6_g1.cpp:424
libff::mnt6_G1::operator!=
bool operator!=(const mnt6_G1 &other) const
Definition: mnt6_g1.cpp:122
libff::mnt6_G1::wnaf_window_table
static std::vector< size_t > wnaf_window_table
Definition: mnt6_g1.hpp:33
libff::mnt6_G1::base_field_char
static bigint< base_field::num_limbs > base_field_char()
Definition: mnt6_g1.hpp:91
libff::Fp_model< mnt6_q_limbs, mnt6_modulus_q >::size_in_bits
static size_t size_in_bits()
Definition: fp.hpp:134
libff::mnt6_G1::print
void print() const
Definition: mnt6_g1.cpp:39
libff::mnt6_G1::print_coordinates
void print_coordinates() const
Definition: mnt6_g1.cpp:55
libff::mnt6_G1::h
static bigint< h_limbs > h
Definition: mnt6_g1.hpp:47
libff::mnt6_G1::fixed_base_exp_window_table
static std::vector< size_t > fixed_base_exp_window_table
Definition: mnt6_g1.hpp:34
libff::bigint< h_limbs >
libff::mnt6_G1::read_compressed
static void read_compressed(std::istream &, mnt6_G1 &)
Definition: mnt6_g1.cpp:471
libff::mnt6_G1::X
mnt6_Fq X
Definition: mnt6_g1.hpp:49
libff::mnt6_G1::zero
static const mnt6_G1 & zero()
Definition: mnt6_g1.cpp:426
libff::mnt6_G1::dbl
mnt6_G1 dbl() const
Definition: mnt6_g1.cpp:352
libff::Fp_model< mnt6_q_limbs, mnt6_modulus_q >::field_char
static const bigint< n > & field_char()
Definition: fp.hpp:136
libff::mnt6_G1
Definition: mnt6_g1.hpp:26
libff::mnt6_G1::scalar_field
mnt6_Fr scalar_field
Definition: mnt6_g1.hpp:41
libff::mnt6_G1::order
static bigint< scalar_field::num_limbs > order()
Definition: mnt6_g1.hpp:95
libff::Fp_model::as_bigint
bigint< n > as_bigint() const
libff::mnt6_G1::h_bitcount
static const mp_size_t h_bitcount
Definition: mnt6_g1.hpp:44
libff::Fp_model< mnt6_q_limbs, mnt6_modulus_q >
libff::mnt6_G1::Y
mnt6_Fq Y
Definition: mnt6_g1.hpp:49
libff::mnt6_G1::one
static const mnt6_G1 & one()
Definition: mnt6_g1.cpp:428
libff::operator<<
std::ostream & operator<<(std::ostream &out, const alt_bn128_G1 &g)
Definition: alt_bn128_g1.cpp:436
libff::mnt6_G1::random_element
static mnt6_G1 random_element()
Definition: mnt6_g1.cpp:430
mnt6_init.hpp
libff::operator*
alt_bn128_G1 operator*(const bigint< m > &lhs, const alt_bn128_G1 &rhs)
Definition: alt_bn128_g1.hpp:99
libff::mnt6_G1::is_special
bool is_special() const
Definition: mnt6_g1.cpp:87
libff::mnt6_G1::mnt6_G1
mnt6_G1(const mnt6_Fq &X, const mnt6_Fq &Y)
Definition: mnt6_g1.hpp:53
libff::mnt6_G1::h_limbs
static const mp_size_t h_limbs
Definition: mnt6_g1.hpp:45
libff::mnt6_G1::base_field
mnt6_Fq base_field
Definition: mnt6_g1.hpp:40
libff::mnt6_G1::write_compressed
void write_compressed(std::ostream &) const
Definition: mnt6_g1.cpp:444
libff::mnt6_G1::is_well_formed
bool is_well_formed() const
Definition: mnt6_g1.cpp:401
libff::mnt6_G1::write_uncompressed
void write_uncompressed(std::ostream &) const
Definition: mnt6_g1.cpp:435
libff::mnt6_G1::mnt6_G1
mnt6_G1()
Definition: mnt6_g1.cpp:32
libff::mnt6_G1::batch_to_special_all_non_zeros
static void batch_to_special_all_non_zeros(std::vector< mnt6_G1 > &vec)
Definition: mnt6_g1.cpp:507