Clearmatics Libff  0.1
C++ library for Finite Fields and Elliptic Curves
alt_bn128_g1.hpp
Go to the documentation of this file.
1 
8 #ifndef ALT_BN128_G1_HPP_
9 #define ALT_BN128_G1_HPP_
12 #include <vector>
13 
14 namespace libff
15 {
16 
17 class alt_bn128_G1;
18 std::ostream &operator<<(std::ostream &, const alt_bn128_G1 &);
19 std::istream &operator>>(std::istream &, alt_bn128_G1 &);
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 
37 
38  // Cofactor
39  static const mp_size_t h_bitcount = 1;
40  static const mp_size_t h_limbs =
41  (h_bitcount + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS;
43 
45 
46  // using Jacobian coordinates
47  alt_bn128_G1();
49  const alt_bn128_Fq &X, const alt_bn128_Fq &Y, const alt_bn128_Fq &Z)
50  : X(X), Y(Y), Z(Z){};
51 
52  void print() const;
53  void print_coordinates() const;
54 
55  void to_affine_coordinates();
56  void to_special();
57  bool is_special() const;
58 
59  bool is_zero() const;
60 
61  bool operator==(const alt_bn128_G1 &other) const;
62  bool operator!=(const alt_bn128_G1 &other) const;
63 
64  alt_bn128_G1 operator+(const alt_bn128_G1 &other) const;
65  alt_bn128_G1 operator-() const;
66  alt_bn128_G1 operator-(const alt_bn128_G1 &other) const;
67 
68  alt_bn128_G1 add(const alt_bn128_G1 &other) const;
69  alt_bn128_G1 mixed_add(const alt_bn128_G1 &other) const;
70  alt_bn128_G1 dbl() const;
72 
73  bool is_well_formed() const;
74  bool is_in_safe_subgroup() const;
75 
76  static const alt_bn128_G1 &zero();
77  static const alt_bn128_G1 &one();
79 
80  static size_t size_in_bits() { return base_field::size_in_bits() + 1; }
82  {
83  return base_field::field_char();
84  }
86  {
87  return scalar_field::field_char();
88  }
89 
90  void write_uncompressed(std::ostream &) const;
91  void write_compressed(std::ostream &) const;
92  static void read_uncompressed(std::istream &, alt_bn128_G1 &);
93  static void read_compressed(std::istream &, alt_bn128_G1 &);
94 
95  static void batch_to_special_all_non_zeros(std::vector<alt_bn128_G1> &vec);
96 };
97 
98 template<mp_size_t m>
100 {
101  return scalar_mul<alt_bn128_G1, m>(rhs, lhs);
102 }
103 
104 template<mp_size_t m, const bigint<m> &modulus_p>
106  const Fp_model<m, modulus_p> &lhs, const alt_bn128_G1 &rhs)
107 {
108  return scalar_mul<alt_bn128_G1, m>(rhs, lhs.as_bigint());
109 }
110 
111 } // namespace libff
112 
113 #endif // ALT_BN128_G1_HPP_
curve_utils.hpp
libff::alt_bn128_G1::is_in_safe_subgroup
bool is_in_safe_subgroup() const
Definition: alt_bn128_g1.cpp:359
libff::alt_bn128_G1::is_zero
bool is_zero() const
Definition: alt_bn128_g1.cpp:91
libff::alt_bn128_G1::to_affine_coordinates
void to_affine_coordinates()
Definition: alt_bn128_g1.cpp:68
libff
Definition: ffi.cpp:8
libff::alt_bn128_G1::size_in_bits
static size_t size_in_bits()
Definition: alt_bn128_g1.hpp:80
libff::alt_bn128_G1::mul_by_cofactor
alt_bn128_G1 mul_by_cofactor() const
Definition: alt_bn128_g1.cpp:328
libff::alt_bn128_G1::X
alt_bn128_Fq X
Definition: alt_bn128_g1.hpp:44
libff::alt_bn128_G1::write_compressed
void write_compressed(std::ostream &) const
Definition: alt_bn128_g1.cpp:383
libff::operator>>
std::istream & operator>>(std::istream &in, alt_bn128_G1 &g)
Definition: alt_bn128_g1.cpp:446
libff::alt_bn128_G1::coeff_b
static alt_bn128_Fq coeff_b
Definition: alt_bn128_g1.hpp:33
libff::alt_bn128_G1::read_compressed
static void read_compressed(std::istream &, alt_bn128_G1 &)
Definition: alt_bn128_g1.cpp:409
libff::alt_bn128_G1::alt_bn128_G1
alt_bn128_G1()
Definition: alt_bn128_g1.cpp:29
libff::alt_bn128_G1::write_uncompressed
void write_uncompressed(std::ostream &) const
Definition: alt_bn128_g1.cpp:374
libff::alt_bn128_G1::operator!=
bool operator!=(const alt_bn128_G1 &other) const
Definition: alt_bn128_g1.cpp:129
libff::alt_bn128_G1::Y
alt_bn128_Fq Y
Definition: alt_bn128_g1.hpp:44
libff::alt_bn128_G1::G1_zero
static alt_bn128_G1 G1_zero
Definition: alt_bn128_g1.hpp:30
libff::alt_bn128_G1::base_field
alt_bn128_Fq base_field
Definition: alt_bn128_g1.hpp:35
libff::alt_bn128_G1::operator==
bool operator==(const alt_bn128_G1 &other) const
Definition: alt_bn128_g1.cpp:93
libff::alt_bn128_G1::alt_bn128_G1
alt_bn128_G1(const alt_bn128_Fq &X, const alt_bn128_Fq &Y, const alt_bn128_Fq &Z)
Definition: alt_bn128_g1.hpp:48
libff::alt_bn128_G1::scalar_field
alt_bn128_Fr scalar_field
Definition: alt_bn128_g1.hpp:36
alt_bn128_init.hpp
libff::Fp_model< alt_bn128_q_limbs, alt_bn128_modulus_q >::size_in_bits
static size_t size_in_bits()
Definition: fp.hpp:134
libff::alt_bn128_G1::is_special
bool is_special() const
Definition: alt_bn128_g1.cpp:86
libff::alt_bn128_G1::G1_one
static alt_bn128_G1 G1_one
Definition: alt_bn128_g1.hpp:31
libff::alt_bn128_G1::operator+
alt_bn128_G1 operator+(const alt_bn128_G1 &other) const
Definition: alt_bn128_g1.cpp:134
libff::alt_bn128_G1::h
static bigint< h_limbs > h
Definition: alt_bn128_g1.hpp:42
libff::alt_bn128_G1::add
alt_bn128_G1 add(const alt_bn128_G1 &other) const
Definition: alt_bn128_g1.cpp:149
libff::alt_bn128_G1::Z
alt_bn128_Fq Z
Definition: alt_bn128_g1.hpp:44
libff::bigint< h_limbs >
libff::alt_bn128_G1::operator-
alt_bn128_G1 operator-() const
Definition: alt_bn128_g1.cpp:139
libff::alt_bn128_G1::random_element
static alt_bn128_G1 random_element()
Definition: alt_bn128_g1.cpp:369
libff::alt_bn128_G1::fixed_base_exp_window_table
static std::vector< size_t > fixed_base_exp_window_table
Definition: alt_bn128_g1.hpp:29
libff::alt_bn128_G1::to_special
void to_special()
Definition: alt_bn128_g1.cpp:84
libff::alt_bn128_G1::order
static bigint< scalar_field::num_limbs > order()
Definition: alt_bn128_g1.hpp:85
libff::Fp_model< alt_bn128_q_limbs, alt_bn128_modulus_q >::field_char
static const bigint< n > & field_char()
Definition: fp.hpp:136
libff::alt_bn128_G1::coeff_a
static alt_bn128_Fq coeff_a
Definition: alt_bn128_g1.hpp:32
libff::alt_bn128_G1::print_coordinates
void print_coordinates() const
Definition: alt_bn128_g1.cpp:52
libff::Fp_model::as_bigint
bigint< n > as_bigint() const
libff::alt_bn128_G1::batch_to_special_all_non_zeros
static void batch_to_special_all_non_zeros(std::vector< alt_bn128_G1 > &vec)
Definition: alt_bn128_g1.cpp:456
libff::Fp_model< alt_bn128_q_limbs, alt_bn128_modulus_q >
libff::alt_bn128_G1::h_limbs
static const mp_size_t h_limbs
Definition: alt_bn128_g1.hpp:40
libff::alt_bn128_G1::one
static const alt_bn128_G1 & one()
Definition: alt_bn128_g1.cpp:367
libff::operator<<
std::ostream & operator<<(std::ostream &out, const alt_bn128_G1 &g)
Definition: alt_bn128_g1.cpp:436
libff::alt_bn128_G1::print
void print() const
Definition: alt_bn128_g1.cpp:36
libff::operator*
alt_bn128_G1 operator*(const bigint< m > &lhs, const alt_bn128_G1 &rhs)
Definition: alt_bn128_g1.hpp:99
libff::alt_bn128_G1::zero
static const alt_bn128_G1 & zero()
Definition: alt_bn128_g1.cpp:365
libff::alt_bn128_G1::wnaf_window_table
static std::vector< size_t > wnaf_window_table
Definition: alt_bn128_g1.hpp:28
libff::alt_bn128_G1::dbl
alt_bn128_G1 dbl() const
Definition: alt_bn128_g1.cpp:285
libff::alt_bn128_G1
Definition: alt_bn128_g1.hpp:21
libff::alt_bn128_G1::is_well_formed
bool is_well_formed() const
Definition: alt_bn128_g1.cpp:334
libff::alt_bn128_G1::read_uncompressed
static void read_uncompressed(std::istream &, alt_bn128_G1 &)
Definition: alt_bn128_g1.cpp:395
libff::alt_bn128_G1::mixed_add
alt_bn128_G1 mixed_add(const alt_bn128_G1 &other) const
Definition: alt_bn128_g1.cpp:208
libff::alt_bn128_G1::h_bitcount
static const mp_size_t h_bitcount
Definition: alt_bn128_g1.hpp:39
libff::alt_bn128_G1::base_field_char
static bigint< base_field::num_limbs > base_field_char()
Definition: alt_bn128_g1.hpp:81