Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
fp.hpp
Go to the documentation of this file.
1
10#ifndef FP_HPP_
11#define FP_HPP_
12
15
16namespace libff {
17
18template<mp_size_t n, const bigint<n>& modulus>
19class Fp_model;
20
21template<mp_size_t n, const bigint<n>& modulus>
22std::ostream& operator<<(std::ostream &, const Fp_model<n, modulus>&);
23
24template<mp_size_t n, const bigint<n>& modulus>
25std::istream& operator>>(std::istream &, Fp_model<n, modulus> &);
26
39template<mp_size_t n, const bigint<n>& modulus>
40class Fp_model {
41public:
43public:
44 static const mp_size_t num_limbs = n;
45 static const constexpr bigint<n>& mod = modulus;
46#ifdef PROFILE_OP_COUNTS
47 static long long add_cnt;
48 static long long sub_cnt;
49 static long long mul_cnt;
50 static long long sqr_cnt;
51 static long long inv_cnt;
52#endif
53 static size_t num_bits;
54 static bigint<n> euler; // (modulus-1)/2
55 static size_t s; // modulus = 2^s * t + 1
56 static bigint<n> t; // with t odd
57 static bigint<n> t_minus_1_over_2; // (t-1)/2
58 static Fp_model<n, modulus> nqr; // a quadratic nonresidue
61 static Fp_model<n, modulus> root_of_unity; // generator^((modulus-1)/2^s)
62 static mp_limb_t inv; // modulus^(-1) mod W, where W = 2^(word size)
63 static bigint<n> Rsquared; // R^2, where R = W^k, where k = ??
64 static bigint<n> Rcubed; // R^3
65
66 static bool modulus_is_valid() { return modulus.data[n-1] != 0; } // mpn inverse assumes that highest limb is non-zero
67
70 Fp_model(const long x, const bool is_unsigned=false);
71
72 void set_ulong(const unsigned long x);
73
74 void mul_reduce(const bigint<n> &other);
75
76 void clear();
77
78 /* Return the standard (not Montgomery) representation of the
79 Field element's requivalence class. I.e. Fp(2).as_bigint()
80 would return bigint(2) */
82 /* Return the last limb of the standard representation of the
83 field element. E.g. on 64-bit architectures Fp(123).as_ulong()
84 and Fp(2^64+123).as_ulong() would both return 123. */
85 unsigned long as_ulong() const;
86
87 bool operator==(const Fp_model& other) const;
88 bool operator!=(const Fp_model& other) const;
89 bool is_zero() const;
90
91 void print() const;
92
96 Fp_model& operator^=(const unsigned long pow);
97
98 template<mp_size_t m>
100
101 Fp_model operator+(const Fp_model& other) const;
102 Fp_model operator-(const Fp_model& other) const;
103 Fp_model operator*(const Fp_model& other) const;
108 Fp_model sqrt() const; // HAS TO BE A SQUARE (else does not terminate)
109
110 Fp_model operator^(const unsigned long pow) const;
111 template<mp_size_t m>
112 Fp_model operator^(const bigint<m> &pow) const;
113
114 static size_t size_in_bits() { return num_bits; }
115 static size_t capacity() { return num_bits - 1; }
116 static bigint<n> field_char() { return modulus; }
117
121 static Fp_model<n, modulus> geometric_generator(); // generator^k, for k = 1 to m, domain size m
122 static Fp_model<n, modulus> arithmetic_generator();// generator++, for k = 1 to m, domain size m
123
124 friend std::ostream& operator<< <n,modulus>(std::ostream &out, const Fp_model<n, modulus> &p);
125 friend std::istream& operator>> <n,modulus>(std::istream &in, Fp_model<n, modulus> &p);
126};
127
128#ifdef PROFILE_OP_COUNTS
129template<mp_size_t n, const bigint<n>& modulus>
131
132template<mp_size_t n, const bigint<n>& modulus>
134
135template<mp_size_t n, const bigint<n>& modulus>
137
138template<mp_size_t n, const bigint<n>& modulus>
140
141template<mp_size_t n, const bigint<n>& modulus>
143#endif
144
145template<mp_size_t n, const bigint<n>& modulus>
147
148template<mp_size_t n, const bigint<n>& modulus>
150
151template<mp_size_t n, const bigint<n>& modulus>
153
154template<mp_size_t n, const bigint<n>& modulus>
156
157template<mp_size_t n, const bigint<n>& modulus>
159
160template<mp_size_t n, const bigint<n>& modulus>
162
163template<mp_size_t n, const bigint<n>& modulus>
165
166template<mp_size_t n, const bigint<n>& modulus>
168
169template<mp_size_t n, const bigint<n>& modulus>
171
172template<mp_size_t n, const bigint<n>& modulus>
174
175template<mp_size_t n, const bigint<n>& modulus>
177
178template<mp_size_t n, const bigint<n>& modulus>
180
181} // libff
182#include <libff/algebra/fields/fp.tcc>
183
184#endif // FP_HPP_
const mie::Vuint & p
Definition bn.cpp:27
bool operator!=(const Fp_model &other) const
Fp_model operator-() const
static bigint< n > euler
Definition fp.hpp:54
static size_t capacity()
Definition fp.hpp:115
bool is_zero() const
static Fp_model< n, modulus > multiplicative_generator
Definition fp.hpp:60
Fp_model operator*(const Fp_model &other) const
static bigint< n > field_char()
Definition fp.hpp:116
static Fp_model< n, modulus > zero()
Fp_model(const bigint< n > &b)
void print() const
Fp_model & invert()
Fp_model & operator*=(const Fp_model &other)
static Fp_model< n, modulus > one()
static size_t s
Definition fp.hpp:55
Fp_model sqrt() const
static bigint< n > t
Definition fp.hpp:56
unsigned long as_ulong() const
static const mp_size_t num_limbs
Definition fp.hpp:44
Fp_model(const long x, const bool is_unsigned=false)
bool operator==(const Fp_model &other) const
Fp_model & operator-=(const Fp_model &other)
void mul_reduce(const bigint< n > &other)
static bigint< n > t_minus_1_over_2
Definition fp.hpp:57
static Fp_model< n, modulus > root_of_unity
Definition fp.hpp:61
static Fp_model< n, modulus > geometric_generator()
Fp_model squared() const
static size_t size_in_bits()
Definition fp.hpp:114
bigint< n > mont_repr
Definition fp.hpp:42
Fp_model operator+(const Fp_model &other) const
static bigint< n > Rcubed
Definition fp.hpp:64
static bool modulus_is_valid()
Definition fp.hpp:66
friend std::ostream & operator(std::ostream &out, const Fp_model< n, modulus > &p)
static mp_limb_t inv
Definition fp.hpp:62
static Fp_model< n, modulus > nqr_to_t
Definition fp.hpp:59
void set_ulong(const unsigned long x)
Fp_model & operator^=(const bigint< m > &pow)
static Fp_model< n, modulus > nqr
Definition fp.hpp:58
Fp_model operator^(const bigint< m > &pow) const
static bigint< n > Rsquared
Definition fp.hpp:63
static Fp_model< n, modulus > arithmetic_generator()
Fp_model inverse() const
Fp_model & operator+=(const Fp_model &other)
bigint< n > as_bigint() const
Fp_model operator-(const Fp_model &other) const
static size_t num_bits
Definition fp.hpp:53
static Fp_model< n, modulus > random_element()
Fp_model operator^(const unsigned long pow) const
Fp_model & operator^=(const unsigned long pow)
static const constexpr bigint< n > & mod
Definition fp.hpp:45
std::istream & operator>>(std::istream &in, alt_bn128_G1 &g)
std::ostream & operator<<(std::ostream &out, const alt_bn128_G1 &g)