-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathmnt4_g2.hpp
More file actions
executable file
·111 lines (84 loc) · 3.1 KB
/
Copy pathmnt4_g2.hpp
File metadata and controls
executable file
·111 lines (84 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/** @file
*****************************************************************************
Declaration of interfaces for the MNT4 G2 group.
*****************************************************************************
* @author This file is part of libff, developed by SCIPR Lab
* and contributors (see AUTHORS).
* @copyright MIT license (see LICENSE file)
*****************************************************************************/
#ifndef MNT4_G2_HPP_
#define MNT4_G2_HPP_
#include <vector>
#include "algebra/curves/curve_utils.hpp"
#include "algebra/curves/mnt/mnt4/mnt4_init.hpp"
namespace libff {
class mnt4_G2;
std::ostream& operator<<(std::ostream &, const mnt4_G2&);
std::istream& operator>>(std::istream &, mnt4_G2&);
class mnt4_G2 {
private:
mnt4_Fq2 X_, Y_, Z_;
public:
#ifdef PROFILE_OP_COUNTS
static long long add_cnt;
static long long dbl_cnt;
#endif
static std::vector<size_t> wnaf_window_table;
static std::vector<size_t> fixed_base_exp_window_table;
static mnt4_G2 G2_zero;
static mnt4_G2 G2_one;
static mnt4_Fq2 twist;
static mnt4_Fq2 coeff_a;
static mnt4_Fq2 coeff_b;
typedef mnt4_Fq base_field;
typedef mnt4_Fq2 twist_field;
typedef mnt4_Fr scalar_field;
// using projective coordinates
mnt4_G2();
mnt4_G2(const mnt4_Fq2& X, const mnt4_Fq2& Y, const mnt4_Fq2& Z) : X_(X), Y_(Y), Z_(Z) {};
mnt4_Fq2 X() const { return X_; }
mnt4_Fq2 Y() const { return Y_; }
mnt4_Fq2 Z() const { return Z_; }
static mnt4_Fq2 mul_by_a(const mnt4_Fq2 &elt);
static mnt4_Fq2 mul_by_b(const mnt4_Fq2 &elt);
void print() const;
void print_coordinates() const;
void to_affine_coordinates();
void to_special();
bool is_special() const;
bool is_zero() const;
bool operator==(const mnt4_G2 &other) const;
bool operator!=(const mnt4_G2 &other) const;
mnt4_G2 operator+(const mnt4_G2 &other) const;
mnt4_G2 operator-() const;
mnt4_G2 operator-(const mnt4_G2 &other) const;
mnt4_G2 add(const mnt4_G2 &other) const;
mnt4_G2 mixed_add(const mnt4_G2 &other) const;
mnt4_G2 dbl() const;
mnt4_G2 mul_by_q() const;
bool is_well_formed() const;
static mnt4_G2 zero();
static mnt4_G2 one();
static mnt4_G2 random_element();
static size_t size_in_bits() { return mnt4_Fq2::size_in_bits() + 1; }
static bigint<mnt4_Fq::num_limbs> base_field_char() { return mnt4_Fq::field_char(); }
static bigint<mnt4_Fr::num_limbs> order() { return mnt4_Fr::field_char(); }
friend std::ostream& operator<<(std::ostream &out, const mnt4_G2 &g);
friend std::istream& operator>>(std::istream &in, mnt4_G2 &g);
};
template<mp_size_t m>
mnt4_G2 operator*(const bigint<m> &lhs, const mnt4_G2 &rhs)
{
return scalar_mul<mnt4_G2, m>(rhs, lhs);
}
template<typename T>
mnt4_G2 operator*(const T &lhs, const mnt4_G2 &rhs)
{
return scalar_mul<mnt4_G2, T::num_limbs>(rhs, lhs.as_bigint());
}
template<typename T>
void batch_to_special_all_non_zeros(std::vector<T> &vec);
template<>
void batch_to_special_all_non_zeros<mnt4_G2>(std::vector<mnt4_G2> &vec);
} // libff
#endif // MNT4_G2_HPP_