Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
fp3.hpp
Go to the documentation of this file.
1
10#ifndef FP3_HPP_
11#define FP3_HPP_
12#include <vector>
13
15
16namespace libff {
17
18template<mp_size_t n, const bigint<n>& modulus>
19class Fp3_model;
20
21template<mp_size_t n, const bigint<n>& modulus>
22std::ostream& operator<<(std::ostream &, const Fp3_model<n, modulus> &);
23
24template<mp_size_t n, const bigint<n>& modulus>
25std::istream& operator>>(std::istream &, Fp3_model<n, modulus> &);
26
35template<mp_size_t n, const bigint<n>& modulus>
36class Fp3_model {
37public:
39
40 static bigint<3*n> euler; // (modulus^3-1)/2
41 static size_t s; // modulus^3 = 2^s * t + 1
42 static bigint<3*n> t; // with t odd
43 static bigint<3*n> t_minus_1_over_2; // (t-1)/2
44 static my_Fp non_residue; // X^6-non_residue irreducible over Fp; used for constructing Fp3 = Fp[X] / (X^3 - non_residue)
45 static Fp3_model<n, modulus> nqr; // a quadratic nonresidue in Fp3
47 static my_Fp Frobenius_coeffs_c1[3]; // non_residue^((modulus^i-1)/3) for i=0,1,2
48 static my_Fp Frobenius_coeffs_c2[3]; // non_residue^((2*modulus^i-2)/3) for i=0,1,2
49
52 Fp3_model(const my_Fp& c0, const my_Fp& c1, const my_Fp& c2) : c0(c0), c1(c1), c2(c2) {};
53
54 void clear() { c0.clear(); c1.clear(); c2.clear(); }
55 void print() const { printf("c0/c1/c2:\n"); c0.print(); c1.print(); c2.print(); }
56
60
61 bool is_zero() const { return c0.is_zero() && c1.is_zero() && c2.is_zero(); }
62 bool operator==(const Fp3_model &other) const;
63 bool operator!=(const Fp3_model &other) const;
64
65 Fp3_model operator+(const Fp3_model &other) const;
66 Fp3_model operator-(const Fp3_model &other) const;
67 Fp3_model operator*(const Fp3_model &other) const;
71 Fp3_model Frobenius_map(unsigned long power) const;
72 Fp3_model sqrt() const; // HAS TO BE A SQUARE (else does not terminate)
73
74 template<mp_size_t m>
75 Fp3_model operator^(const bigint<m> &other) const;
76
77 static size_t size_in_bits() { return 3*my_Fp::size_in_bits(); }
78 static bigint<n> base_field_char() { return modulus; }
79
80 friend std::ostream& operator<< <n, modulus>(std::ostream &out, const Fp3_model<n, modulus> &el);
81 friend std::istream& operator>> <n, modulus>(std::istream &in, Fp3_model<n, modulus> &el);
82};
83
84template<mp_size_t n, const bigint<n>& modulus>
85std::ostream& operator<<(std::ostream& out, const std::vector<Fp3_model<n, modulus> > &v);
86
87template<mp_size_t n, const bigint<n>& modulus>
88std::istream& operator>>(std::istream& in, std::vector<Fp3_model<n, modulus> > &v);
89
90template<mp_size_t n, const bigint<n>& modulus>
92
93template<mp_size_t n, const bigint<n>& modulus>
95
96template<mp_size_t n, const bigint<n>& modulus>
98
99template<mp_size_t n, const bigint<n>& modulus>
101
102template<mp_size_t n, const bigint<n>& modulus>
104
105template<mp_size_t n, const bigint<n>& modulus>
107
108template<mp_size_t n, const bigint<n>& modulus>
110
111template<mp_size_t n, const bigint<n>& modulus>
113
114template<mp_size_t n, const bigint<n>& modulus>
116
117template<mp_size_t n, const bigint<n>& modulus>
119
120} // libff
121#include <libff/algebra/fields/fp3.tcc>
122
123#endif // FP3_HPP_
static Fp3_model< n, modulus > nqr_to_t
Definition fp3.hpp:46
void clear()
Definition fp3.hpp:54
Fp3_model operator*(const Fp3_model &other) const
static bigint< 3 *n > t
Definition fp3.hpp:42
static my_Fp Frobenius_coeffs_c1[3]
Definition fp3.hpp:47
static size_t size_in_bits()
Definition fp3.hpp:77
Fp3_model inverse() const
Fp3_model squared() const
Fp3_model operator-() const
Fp3_model Frobenius_map(unsigned long power) const
bool operator==(const Fp3_model &other) const
Fp3_model(const my_Fp &c0, const my_Fp &c1, const my_Fp &c2)
Definition fp3.hpp:52
Fp_model< n, modulus > my_Fp
Definition fp3.hpp:38
static Fp3_model< n, modulus > one()
static size_t s
Definition fp3.hpp:41
void print() const
Definition fp3.hpp:55
static bigint< 3 *n > t_minus_1_over_2
Definition fp3.hpp:43
Fp3_model sqrt() const
static my_Fp Frobenius_coeffs_c2[3]
Definition fp3.hpp:48
bool operator!=(const Fp3_model &other) const
static Fp3_model< n, modulus > random_element()
Fp3_model operator^(const bigint< m > &other) const
bool is_zero() const
Definition fp3.hpp:61
friend std::ostream & operator(std::ostream &out, const Fp3_model< n, modulus > &el)
static Fp3_model< n, modulus > zero()
Fp3_model operator-(const Fp3_model &other) const
static bigint< 3 *n > euler
Definition fp3.hpp:40
static Fp3_model< n, modulus > nqr
Definition fp3.hpp:45
static my_Fp non_residue
Definition fp3.hpp:44
Fp3_model operator+(const Fp3_model &other) const
static bigint< n > base_field_char()
Definition fp3.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)