28 FieldT zero = FieldT::zero();
29 FieldT
one = FieldT::one();
30 FieldT
a = FieldT::random_element();
35 FieldT b = FieldT::random_element();
36 FieldT c = FieldT::random_element();
37 FieldT
d = FieldT::random_element();
42 assert(
a *
a ==
a.squared());
43 assert((
a + b).squared() ==
a.squared() +
a*b + b*
a + b.squared());
44 assert((
a + b)*(c +
d) ==
a*c +
a*
d + b*c + b*
d);
45 assert(
a - b ==
a + (-b));
46 assert(
a - b == (-b) +
a);
48 assert((
a ^ rand1) * (
a ^ rand2) == (
a^randsum));
50 assert(
a *
a.inverse() ==
one);
51 assert((
a + b) * c.inverse() ==
a * c.inverse() + (b.inverse() * c).inverse());
159 typedef typename Fp4T::my_Fp FieldT;
160 for (
size_t i = 0; i < 100; ++i)
162 const Fp4T
a = Fp4T::random_element();
163 const Fp4T b = Fp4T::random_element();
164 const Fp4T correct_res =
a * b;
186 const FieldT v0 = a0 * b0;
187 const FieldT v1 = (a0 + a1 + a2 + a3) * (b0 + b1 + b2 + b3);
188 const FieldT v2 = (a0 - a1 + a2 - a3) * (b0 - b1 + b2 - b3);
189 const FieldT v3 = (a0 + FieldT(2)*a1 + FieldT(4)*a2 + FieldT(8)*a3) * (b0 + FieldT(2)*b1 + FieldT(4)*b2 + FieldT(8)*b3);
190 const FieldT v4 = (a0 - FieldT(2)*a1 + FieldT(4)*a2 - FieldT(8)*a3) * (b0 - FieldT(2)*b1 + FieldT(4)*b2 - FieldT(8)*b3);
191 const FieldT v5 = (a0 + FieldT(3)*a1 + FieldT(9)*a2 + FieldT(27)*a3) * (b0 + FieldT(3)*b1 + FieldT(9)*b2 + FieldT(27)*b3);
192 const FieldT v6 = a3 * b3;
194 const FieldT beta = Fp4T::non_residue;
196 c0 = v0 + beta*(FieldT(4).inverse()*v0 - FieldT(6).inverse()*(v1 + v2) + FieldT(24).inverse() * (v3 + v4) - FieldT(5) * v6);
197 c1 = - FieldT(3).inverse()*v0 + v1 - FieldT(2).inverse()*v2 - FieldT(4).inverse()*v3 + FieldT(20).inverse() * v4 + FieldT(30).inverse() * v5 - FieldT(12) * v6 + beta * ( - FieldT(12).inverse() * (v0 - v1) + FieldT(24).inverse()*(v2 - v3) - FieldT(120).inverse() * (v4 - v5) - FieldT(3) * v6);
198 c2 = - (FieldT(5)*(FieldT(4).inverse()))* v0 + (FieldT(2)*(FieldT(3).inverse()))*(v1 + v2) - FieldT(24).inverse()*(v3 + v4) + FieldT(4)*v6 + beta*v6;
199 c3 = FieldT(12).inverse() * (FieldT(5)*v0 - FieldT(7)*v1) - FieldT(24).inverse()*(v2 - FieldT(7)*v3 + v4 + v5) + FieldT(15)*v6;
201 assert(res == correct_res);
204 const FieldT u = (FieldT::one() - beta).inverse();
205 assert(v0 == u * c0 + beta * u * c2 - beta * u * FieldT(2).inverse() * v1 - beta * u * FieldT(2).inverse() * v2 + beta * v6);
206 assert(v3 == - FieldT(15) * u * c0 - FieldT(30) * u * c1 - FieldT(3) * (FieldT(4) + beta) * u * c2 - FieldT(6) * (FieldT(4) + beta) * u * c3 + (FieldT(24) - FieldT(3) * beta * FieldT(2).inverse()) * u * v1 + (-FieldT(8) + beta * FieldT(2).inverse()) * u * v2
207 - FieldT(3) * (-FieldT(16) + beta) * v6);
208 assert(v4 == - FieldT(15) * u * c0 + FieldT(30) * u * c1 - FieldT(3) * (FieldT(4) + beta) * u * c2 + FieldT(6) * (FieldT(4) + beta) * u * c3 + (FieldT(24) - FieldT(3) * beta * FieldT(2).inverse()) * u * v2 + (-FieldT(8) + beta * FieldT(2).inverse()) * u * v1
209 - FieldT(3) * (-FieldT(16) + beta) * v6);
210 assert(v5 == - FieldT(80) * u * c0 - FieldT(240) * u * c1 - FieldT(8) * (FieldT(9) + beta) * u * c2 - FieldT(24) * (FieldT(9) + beta) * u * c3 - FieldT(2) * (-FieldT(81) + beta) * u * v1 + (-FieldT(81) + beta) * u * v2
211 - FieldT(8) * (-FieldT(81) + beta) * v6);