Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
fp2.hpp
Go to the documentation of this file.
1
10#ifndef FP2_HPP_
11#define FP2_HPP_
12#include <vector>
13
15
16namespace libff {
17
18template<mp_size_t n, const bigint<n>& modulus>
19class Fp2_model;
20
21template<mp_size_t n, const bigint<n>& modulus>
22std::ostream& operator<<(std::ostream &, const Fp2_model<n, modulus> &);
23
24template<mp_size_t n, const bigint<n>& modulus>
25std::istream& operator>>(std::istream &, Fp2_model<n, modulus> &);
26
35template<mp_size_t n, const bigint<n>& modulus>
36class Fp2_model {
37public:
39
40 static bigint<2*n> euler; // (modulus^2-1)/2
41 static size_t s; // modulus^2 = 2^s * t + 1
42 static bigint<2*n> t; // with t odd
43 static bigint<2*n> t_minus_1_over_2; // (t-1)/2
44 static my_Fp non_residue; // X^4-non_residue irreducible over Fp; used for constructing Fp2 = Fp[X] / (X^2 - non_residue)
45 static Fp2_model<n, modulus> nqr; // a quadratic nonresidue in Fp2
47 static my_Fp Frobenius_coeffs_c1[2]; // non_residue^((modulus^i-1)/2) for i=0,1
48
51 Fp2_model(const my_Fp& c0, const my_Fp& c1) : c0(c0), c1(c1) {};
52
53 void clear() { c0.clear(); c1.clear(); }
54 void print() const { printf("c0/c1:\n"); c0.print(); c1.print(); }
55
59
60 bool is_zero() const { return c0.is_zero() && c1.is_zero(); }
61 bool operator==(const Fp2_model &other) const;
62 bool operator!=(const Fp2_model &other) const;
63
64 Fp2_model operator+(const Fp2_model &other) const;
65 Fp2_model operator-(const Fp2_model &other) const;
66 Fp2_model operator*(const Fp2_model &other) const;
68 Fp2_model squared() const; // default is squared_complex
70 Fp2_model Frobenius_map(unsigned long power) const;
71 Fp2_model sqrt() const; // HAS TO BE A SQUARE (else does not terminate)
74
75 template<mp_size_t m>
76 Fp2_model operator^(const bigint<m> &other) const;
77
78 static size_t size_in_bits() { return 2*my_Fp::size_in_bits(); }
79 static bigint<n> base_field_char() { return modulus; }
80
81 friend std::ostream& operator<< <n, modulus>(std::ostream &out, const Fp2_model<n, modulus> &el);
82 friend std::istream& operator>> <n, modulus>(std::istream &in, Fp2_model<n, modulus> &el);
83};
84
85template<mp_size_t n, const bigint<n>& modulus>
86std::ostream& operator<<(std::ostream& out, const std::vector<Fp2_model<n, modulus> > &v);
87
88template<mp_size_t n, const bigint<n>& modulus>
89std::istream& operator>>(std::istream& in, std::vector<Fp2_model<n, modulus> > &v);
90
91template<mp_size_t n, const bigint<n>& modulus>
93
94template<mp_size_t n, const bigint<n>& modulus>
96
97template<mp_size_t n, const bigint<n>& modulus>
99
100template<mp_size_t n, const bigint<n>& modulus>
102
103template<mp_size_t n, const bigint<n>& modulus>
105
106template<mp_size_t n, const bigint<n>& modulus>
108
109template<mp_size_t n, const bigint<n>& modulus>
111
112template<mp_size_t n, const bigint<n>& modulus>
114
115template<mp_size_t n, const bigint<n>& modulus>
117
118} // libff
119#include <libff/algebra/fields/fp2.tcc>
120
121#endif // FP2_HPP_
static bigint< 2 *n > t_minus_1_over_2
Definition fp2.hpp:43
static Fp2_model< n, modulus > zero()
bool is_zero() const
Definition fp2.hpp:60
static Fp2_model< n, modulus > random_element()
static Fp2_model< n, modulus > nqr_to_t
Definition fp2.hpp:46
static size_t s
Definition fp2.hpp:41
Fp2_model operator-(const Fp2_model &other) const
Fp2_model squared_karatsuba() const
Fp2_model operator*(const Fp2_model &other) const
void print() const
Definition fp2.hpp:54
Fp2_model sqrt() const
bool operator==(const Fp2_model &other) const
Fp2_model inverse() const
static bigint< 2 *n > t
Definition fp2.hpp:42
static Fp2_model< n, modulus > one()
void clear()
Definition fp2.hpp:53
static my_Fp Frobenius_coeffs_c1[2]
Definition fp2.hpp:47
Fp2_model squared_complex() const
Fp2_model operator-() const
Fp2_model operator+(const Fp2_model &other) const
static my_Fp non_residue
Definition fp2.hpp:44
static Fp2_model< n, modulus > nqr
Definition fp2.hpp:45
Fp2_model squared() const
static bigint< n > base_field_char()
Definition fp2.hpp:79
Fp2_model(const my_Fp &c0, const my_Fp &c1)
Definition fp2.hpp:51
Fp2_model Frobenius_map(unsigned long power) const
Fp_model< n, modulus > my_Fp
Definition fp2.hpp:38
friend std::ostream & operator(std::ostream &out, const Fp2_model< n, modulus > &el)
bool operator!=(const Fp2_model &other) const
Fp2_model operator^(const bigint< m > &other) const
static bigint< 2 *n > euler
Definition fp2.hpp:40
static size_t size_in_bits()
Definition fp2.hpp:78
bool is_zero() const
void print() const
static size_t size_in_bits()
Definition fp.hpp:114
std::istream & operator>>(std::istream &in, alt_bn128_G1 &g)
std::ostream & operator<<(std::ostream &out, const alt_bn128_G1 &g)
alt_bn128_G1 operator*(const bigint< m > &lhs, const alt_bn128_G1 &rhs)
FieldT power(const FieldT &base, const bigint< m > &exponent)