-
Notifications
You must be signed in to change notification settings - Fork 1
/
ffe_x.h
51 lines (40 loc) · 1011 Bytes
/
ffe_x.h
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
#ifndef FFE_X_H
#define FFE_X_H
#include <iostream>
using std::ostream;
template<long N>
class FFE_x {
private:
int value;
public:
FFE_x(int value) {
static_assert(is_prime_func(N), "Field order must be a prime number");
FFE_x<N>::value = value % N;
}
FFE_x<N>& operator+=(const FFE_x<N>& b) {
this->value += b.value%N;
if (this->value > N)
this->value = this->value %N;
return *this;
}
FFE_x<N>& operator*=(const FFE_x<N>& b) {
this->value *= b.value%N;
this->value = this->value%N;
return *this;
}
friend
ostream & operator<<(ostream& os, const FFE_x<N>& ffe) {
return os << ffe.value;
}
};
template<long N>
FFE_x<N> operator+(const FFE_x<N>& a, const FFE_x<N>& b) {
FFE<N> temp = FFE<N>(a);
return temp += b;
}
template<long N>
FFE_x<N> operator*(const FFE_x<N>& a, const FFE_x<N>& b) {
FFE_x<N> temp = FFE_x<N>(a);
return temp *= b;
}
#endif /* FFE_X_H */