Clearmatics Libff  0.1
C++ library for Finite Fields and Elliptic Curves
mnt4_g1.hpp
Go to the documentation of this file.
1 
12 #ifndef MNT4_G1_HPP_
13 #define MNT4_G1_HPP_
14 
17 #include <vector>
18 
19 namespace libff
20 {
21 
22 class mnt4_G1;
23 std::ostream &operator<<(std::ostream &, const mnt4_G1 &);
24 std::istream &operator>>(std::istream &, mnt4_G1 &);
25 
26 class mnt4_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 mnt4_G1 G1_zero;
36  static mnt4_G1 G1_one;
37  static mnt4_Fq coeff_a;
38  static mnt4_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  mnt4_Fq X, Y, Z;
50 
51  // using projective coordinates
52  mnt4_G1();
53  mnt4_G1(const mnt4_Fq &X, const mnt4_Fq &Y)
54  : X(X), Y(Y), Z(base_field::one())
55  {
56  }
57  mnt4_G1(const mnt4_Fq &X, const mnt4_Fq &Y, const mnt4_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 mnt4_G1 &other) const;
72  bool operator!=(const mnt4_G1 &other) const;
73 
74  mnt4_G1 operator+(const mnt4_G1 &other) const;
75  mnt4_G1 operator-() const;
76  mnt4_G1 operator-(const mnt4_G1 &other) const;
77 
78  mnt4_G1 add(const mnt4_G1 &other) const;
79  mnt4_G1 mixed_add(const mnt4_G1 &other) const;
80  mnt4_G1 dbl() const;
81  mnt4_G1 mul_by_cofactor() const;
82 
83  bool is_well_formed() const;
84  bool is_in_safe_subgroup() const;
85 
86  static const mnt4_G1 &zero();
87  static const mnt4_G1 &one();
88  static mnt4_G1 random_element();
89 
90  static size_t size_in_bits() { return mnt4_Fq::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_G1 &);
100  static void read_compressed(std::istream &, mnt4_G1 &);
101 
102  static void batch_to_special_all_non_zeros(std::vector<mnt4_G1> &vec);
103 };
104 
105 template<mp_size_t m>
106 mnt4_G1 operator*(const bigint<m> &lhs, const mnt4_G1 &rhs)
107 {
108  return scalar_mul<mnt4_G1, m>(rhs, lhs);
109 }
110 
111 template<mp_size_t m, const bigint<m> &modulus_p>
113 {
114  return scalar_mul<mnt4_G1, m>(rhs, lhs.as_bigint());
115 }
116 
117 } // namespace libff
118 
119 #endif // MNT4_G1_HPP_
curve_utils.hpp
libff::mnt4_G1::mnt4_G1
mnt4_G1(const mnt4_Fq &X, const mnt4_Fq &Y)
Definition: mnt4_g1.hpp:53
libff::mnt4_G1::size_in_bits
static size_t size_in_bits()
Definition: mnt4_g1.hpp:90
libff
Definition: ffi.cpp:8
libff::mnt4_G1::Y
mnt4_Fq Y
Definition: mnt4_g1.hpp:49
libff::mnt4_G1::batch_to_special_all_non_zeros
static void batch_to_special_all_non_zeros(std::vector< mnt4_G1 > &vec)
Definition: mnt4_g1.cpp:527
libff::mnt4_G1::mixed_add
mnt4_G1 mixed_add(const mnt4_G1 &other) const
Definition: mnt4_g1.cpp:292
libff::operator>>
std::istream & operator>>(std::istream &in, alt_bn128_G1 &g)
Definition: alt_bn128_g1.cpp:446
libff::mnt4_G1::operator==
bool operator==(const mnt4_G1 &other) const
Definition: mnt4_g1.cpp:97
libff::mnt4_G1::base_field_char
static bigint< mnt4_Fq::num_limbs > base_field_char()
Definition: mnt4_g1.hpp:91
libff::mnt4_G1
Definition: mnt4_g1.hpp:26
libff::mnt4_G1::random_element
static mnt4_G1 random_element()
Definition: mnt4_g1.cpp:431
libff::mnt4_G1::mnt4_G1
mnt4_G1(const mnt4_Fq &X, const mnt4_Fq &Y, const mnt4_Fq &Z)
Definition: mnt4_g1.hpp:57
libff::mnt4_G1::Z
mnt4_Fq Z
Definition: mnt4_g1.hpp:49
libff::mnt4_G1::read_uncompressed
static void read_uncompressed(std::istream &, mnt4_G1 &)
Definition: mnt4_g1.cpp:455
libff::mnt4_G1::is_well_formed
bool is_well_formed() const
Definition: mnt4_g1.cpp:402
libff::mnt4_G1::G1_one
static mnt4_G1 G1_one
Definition: mnt4_g1.hpp:36
libff::mnt4_G1::order
static bigint< mnt4_Fr::num_limbs > order()
Definition: mnt4_g1.hpp:95
libff::mnt4_G1::base_field
mnt4_Fq base_field
Definition: mnt4_g1.hpp:40
libff::mnt4_G1::read_compressed
static void read_compressed(std::istream &, mnt4_G1 &)
Definition: mnt4_g1.cpp:472
libff::mnt4_G1::one
static const mnt4_G1 & one()
Definition: mnt4_g1.cpp:429
libff::mnt4_G1::mnt4_G1
mnt4_G1()
Definition: mnt4_g1.cpp:32
libff::mnt4_G1::coeff_a
static mnt4_Fq coeff_a
Definition: mnt4_g1.hpp:37
libff::Fp_model< mnt4_q_limbs, mnt4_modulus_q >::size_in_bits
static size_t size_in_bits()
Definition: fp.hpp:134
libff::mnt4_G1::fixed_base_exp_window_table
static std::vector< size_t > fixed_base_exp_window_table
Definition: mnt4_g1.hpp:34
libff::mnt4_G1::scalar_field
mnt4_Fr scalar_field
Definition: mnt4_g1.hpp:41
libff::mnt4_G1::print
void print() const
Definition: mnt4_g1.cpp:39
libff::mnt4_G1::is_special
bool is_special() const
Definition: mnt4_g1.cpp:87
libff::bigint< h_limbs >
libff::mnt4_G1::dbl
mnt4_G1 dbl() const
Definition: mnt4_g1.cpp:353
libff::mnt4_G1::is_zero
bool is_zero() const
Definition: mnt4_g1.cpp:92
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_G1::print_coordinates
void print_coordinates() const
Definition: mnt4_g1.cpp:55
libff::Fp_model::as_bigint
bigint< n > as_bigint() const
libff::mnt4_G1::h_limbs
static const mp_size_t h_limbs
Definition: mnt4_g1.hpp:45
libff::Fp_model< mnt4_q_limbs, mnt4_modulus_q >
libff::mnt4_G1::coeff_b
static mnt4_Fq coeff_b
Definition: mnt4_g1.hpp:38
libff::mnt4_G1::wnaf_window_table
static std::vector< size_t > wnaf_window_table
Definition: mnt4_g1.hpp:33
libff::operator<<
std::ostream & operator<<(std::ostream &out, const alt_bn128_G1 &g)
Definition: alt_bn128_g1.cpp:436
libff::operator*
alt_bn128_G1 operator*(const bigint< m > &lhs, const alt_bn128_G1 &rhs)
Definition: alt_bn128_g1.hpp:99
libff::mnt4_G1::operator!=
bool operator!=(const mnt4_G1 &other) const
Definition: mnt4_g1.cpp:122
libff::mnt4_G1::operator+
mnt4_G1 operator+(const mnt4_G1 &other) const
Definition: mnt4_g1.cpp:127
libff::mnt4_G1::operator-
mnt4_G1 operator-() const
Definition: mnt4_g1.cpp:227
libff::mnt4_G1::h
static bigint< h_limbs > h
Definition: mnt4_g1.hpp:47
libff::mnt4_G1::to_affine_coordinates
void to_affine_coordinates()
Definition: mnt4_g1.cpp:71
libff::mnt4_G1::write_compressed
void write_compressed(std::ostream &) const
Definition: mnt4_g1.cpp:445
libff::mnt4_G1::zero
static const mnt4_G1 & zero()
Definition: mnt4_g1.cpp:427
libff::mnt4_G1::X
mnt4_Fq X
Definition: mnt4_g1.hpp:49
libff::mnt4_G1::add
mnt4_G1 add(const mnt4_G1 &other) const
Definition: mnt4_g1.cpp:237
libff::mnt4_G1::to_special
void to_special()
Definition: mnt4_g1.cpp:85
libff::mnt4_G1::write_uncompressed
void write_uncompressed(std::ostream &) const
Definition: mnt4_g1.cpp:436
libff::mnt4_G1::G1_zero
static mnt4_G1 G1_zero
Definition: mnt4_g1.hpp:35
libff::mnt4_G1::is_in_safe_subgroup
bool is_in_safe_subgroup() const
Definition: mnt4_g1.cpp:425
libff::mnt4_G1::h_bitcount
static const mp_size_t h_bitcount
Definition: mnt4_g1.hpp:44
libff::mnt4_G1::mul_by_cofactor
mnt4_G1 mul_by_cofactor() const
Definition: mnt4_g1.cpp:396