21 GFP2Element(
const byte *encodedElement,
unsigned int size)
22 : c1(encodedElement, size/2), c2(encodedElement+size/2, size/2) {}
24 void Encode(
byte *encodedElement,
unsigned int size)
26 c1.
Encode(encodedElement, size/2);
27 c2.
Encode(encodedElement+size/2, size/2);
54 throw InvalidArgument(
"GFP2_ONB: modulus must be equivalent to 2 mod 3");
57 const Integer& GetModulus()
const {
return modp.GetModulus();}
61 t = modp.Inverse(modp.ConvertIn(a));
66 {
return GFP2Element(modp.ConvertIn(a.c1), modp.ConvertIn(a.c2));}
69 {
return GFP2Element(modp.ConvertOut(a.c1), modp.ConvertOut(a.c2));}
73 return modp.Equal(a.c1, b.c1) && modp.Equal(a.c2, b.c2);
76 const Element& Identity()
const
78 return GFP2Element::Zero();
83 result.c1 = modp.Add(a.c1, b.c1);
84 result.c2 = modp.Add(a.c2, b.c2);
90 result.c1 = modp.Inverse(a.c1);
91 result.c2 = modp.Inverse(a.c2);
97 result.c1 = modp.Double(a.c1);
98 result.c2 = modp.Double(a.c2);
104 result.c1 = modp.Subtract(a.c1, b.c1);
105 result.c2 = modp.Subtract(a.c2, b.c2);
111 modp.Accumulate(a.c1, b.c1);
112 modp.Accumulate(a.c2, b.c2);
118 modp.Reduce(a.c1, b.c1);
119 modp.Reduce(a.c2, b.c2);
125 return a.c1.NotZero() || a.c2.NotZero();
128 const Element& MultiplicativeIdentity()
const
130 result.c1 = result.c2 = modp.Inverse(modp.MultiplicativeIdentity());
136 t = modp.Add(a.c1, a.c2);
137 t = modp.Multiply(t, modp.Add(b.c1, b.c2));
138 result.c1 = modp.Multiply(a.c1, b.c1);
139 result.c2 = modp.Multiply(a.c2, b.c2);
140 result.c1.
swap(result.c2);
141 modp.Reduce(t, result.c1);
142 modp.Reduce(t, result.c2);
143 modp.Reduce(result.c1, t);
144 modp.Reduce(result.c2, t);
155 const Integer &ac1 = (&a == &result) ? (t = a.c1) : a.c1;
156 result.c1 = modp.Multiply(modp.Subtract(modp.Subtract(a.c2, a.c1), a.c1), a.c2);
157 result.c2 = modp.Multiply(modp.Subtract(modp.Subtract(ac1, a.c2), a.c2), ac1);
169 const Element & PthPower(
const Element &a)
const
172 result.c1.
swap(result.c2);
176 void RaiseToPthPower(Element &a)
const
182 const Element & SpecialOperation1(
const Element &a)
const
186 modp.Reduce(result.c1, a.c2);
187 modp.Reduce(result.c1, a.c2);
188 modp.Reduce(result.c2, a.c1);
189 modp.Reduce(result.c2, a.c1);
194 const Element & SpecialOperation2(
const Element &x,
const Element &y,
const Element &z)
const
197 t = modp.Add(x.c2, y.c2);
198 result.c1 = modp.Multiply(z.c1, modp.Subtract(y.c1, t));
199 modp.Accumulate(result.c1, modp.Multiply(z.c2, modp.Subtract(t, x.c1)));
200 t = modp.Add(x.c1, y.c1);
201 result.c2 = modp.Multiply(z.c2, modp.Subtract(y.c2, t));
202 modp.Accumulate(result.c2, modp.Multiply(z.c1, modp.Subtract(t, x.c2)));