19 GFP2Element(
const Integer &c1,
const Integer &c2) : c1(c1), c2(c2) {}
20 GFP2Element(
const byte *encodedElement,
unsigned int size)
21 : c1(encodedElement, size/2), c2(encodedElement+size/2, size/2) {}
23 void Encode(byte *encodedElement,
unsigned int size)
25 c1.
Encode(encodedElement, size/2);
26 c2.
Encode(encodedElement+size/2, size/2);
29 bool operator==(
const GFP2Element &rhs)
const {
return c1 == rhs.c1 && c2 == rhs.c2;}
30 bool operator!=(
const GFP2Element &rhs)
const {
return !operator==(rhs);}
32 void swap(GFP2Element &a)
38 static const GFP2Element & Zero();
53 throw InvalidArgument(
"GFP2_ONB: modulus must be equivalent to 2 mod 3");
56 const Integer& GetModulus()
const {
return modp.GetModulus();}
60 t = modp.Inverse(modp.ConvertIn(a));
65 {
return GFP2Element(modp.ConvertIn(a.c1), modp.ConvertIn(a.c2));}
68 {
return GFP2Element(modp.ConvertOut(a.c1), modp.ConvertOut(a.c2));}
72 return modp.Equal(a.c1, b.c1) && modp.Equal(a.c2, b.c2);
77 return GFP2Element::Zero();
82 result.c1 = modp.Add(a.c1, b.c1);
83 result.c2 = modp.Add(a.c2, b.c2);
89 result.c1 = modp.Inverse(a.c1);
90 result.c2 = modp.Inverse(a.c2);
96 result.c1 = modp.Double(a.c1);
97 result.c2 = modp.Double(a.c2);
103 result.c1 = modp.Subtract(a.c1, b.c1);
104 result.c2 = modp.Subtract(a.c2, b.c2);
110 modp.Accumulate(a.c1, b.c1);
111 modp.Accumulate(a.c2, b.c2);
117 modp.Reduce(a.c1, b.c1);
118 modp.Reduce(a.c2, b.c2);
122 bool IsUnit(
const Element &a)
const 124 return a.c1.NotZero() || a.c2.NotZero();
127 const Element& MultiplicativeIdentity()
const 129 result.c1 = result.c2 = modp.Inverse(modp.MultiplicativeIdentity());
135 t = modp.Add(a.c1, a.c2);
136 t = modp.Multiply(t, modp.Add(b.c1, b.c2));
137 result.c1 = modp.Multiply(a.c1, b.c1);
138 result.c2 = modp.Multiply(a.c2, b.c2);
139 result.c1.
swap(result.c2);
140 modp.Reduce(t, result.c1);
141 modp.Reduce(t, result.c2);
142 modp.Reduce(result.c1, t);
143 modp.Reduce(result.c2, t);
149 return result = Exponentiate(a, modp.GetModulus()-2);
154 const Integer &ac1 = (&a == &result) ? (t = a.c1) : a.c1;
155 result.c1 = modp.Multiply(modp.Subtract(modp.Subtract(a.c2, a.c1), a.c1), a.c2);
156 result.c2 = modp.Multiply(modp.Subtract(modp.Subtract(ac1, a.c2), a.c2), ac1);
171 result.c1.
swap(result.c2);
175 void RaiseToPthPower(
Element &a)
const 183 assert(&a != &result);
185 modp.Reduce(result.c1, a.c2);
186 modp.Reduce(result.c1, a.c2);
187 modp.Reduce(result.c2, a.c1);
188 modp.Reduce(result.c2, a.c1);
195 assert(&x != &result && &y != &result && &z != &result);
196 t = modp.Add(x.c2, y.c2);
197 result.c1 = modp.Multiply(z.c1, modp.Subtract(y.c1, t));
198 modp.Accumulate(result.c1, modp.Multiply(z.c2, modp.Subtract(t, x.c1)));
199 t = modp.Add(x.c1, y.c1);
200 result.c2 = modp.Multiply(z.c2, modp.Subtract(y.c2, t));
201 modp.Accumulate(result.c2, modp.Multiply(z.c1, modp.Subtract(t, x.c2)));
An invalid argument was detected.
void Encode(byte *output, size_t outputLen, Signedness sign=UNSIGNED) const
Encode in big-endian format.
Abstract base classes that provide a uniform interface to this library.
Interface for random number generators.
void swap(Integer &a)
Swaps this Integer with another Integer.
Multiple precision integer with arithmetic operations.
static void Divide(Integer &r, Integer &q, const Integer &a, const Integer &d)
calculate r and q such that (a == d*q + r) && (0 <= r < abs(d))
Class file for performing modular arithmetic.
Crypto++ library namespace.
GF(p^2), optimal normal basis.