...
1 package ff
2
3 import (
4 "testing"
5
6 "github.com/cloudflare/circl/internal/test"
7 )
8
9 func TestFP12CubicAdd(t *testing.T) {
10 const testTimes = 1 << 8
11 for i := 0; i < testTimes; i++ {
12 var xalt, yalt, zalt Fp12Cubic
13 var z, zcmp Fp12
14 x := randomFp12(t)
15 y := randomFp12(t)
16 xalt.FromFp12(x)
17 yalt.FromFp12(y)
18 zalt.Add(&xalt, &yalt)
19 z.Add(x, y)
20 zcmp.FromFp12Alt(&zalt)
21 if z.IsEqual(&zcmp) == 0 {
22 test.ReportError(t, z, zcmp, x, y)
23 }
24 }
25 }
26
27 func TestFP12CubicMul(t *testing.T) {
28 const testTimes = 1 << 8
29 for i := 0; i < testTimes; i++ {
30 var xalt, yalt, zalt Fp12Cubic
31 var z, zcmp Fp12
32 x := randomFp12(t)
33 y := randomFp12(t)
34 xalt.FromFp12(x)
35 yalt.FromFp12(y)
36 zalt.Mul(&xalt, &yalt)
37 z.Mul(x, y)
38 zcmp.FromFp12Alt(&zalt)
39 if z.IsEqual(&zcmp) == 0 {
40 test.ReportError(t, z, zcmp, x, y)
41 }
42 }
43 }
44
45 func TestFP12AltSqr(t *testing.T) {
46 const testTimes = 1 << 8
47 for i := 0; i < testTimes; i++ {
48 var xalt, zalt Fp12Cubic
49 var z, zcmp Fp12
50 x := randomFp12(t)
51 xalt.FromFp12(x)
52 zalt.Sqr(&xalt)
53 z.Sqr(x)
54 zcmp.FromFp12Alt(&zalt)
55 if z.IsEqual(&zcmp) == 0 {
56 test.ReportError(t, z, zcmp, x)
57 }
58 }
59 }
60
61 func TestFP12CubicLine(t *testing.T) {
62 const testTimes = 1 << 8
63 for i := 0; i < testTimes; i++ {
64 var x, y, z, zcmp Fp12Cubic
65 var yline LineValue
66 xnorm := randomFp12(t)
67 x.FromFp12(xnorm)
68
69 yline[0] = *randomFp2(t)
70 yline[1] = *randomFp2(t)
71 yline[2] = *randomFp2(t)
72
73 y[0][0] = yline[0]
74 y[0][1] = yline[2]
75 y[2][0] = yline[1]
76
77 zcmp.Mul(&x, &y)
78 z.MulLine(&x, &yline)
79 if z.IsEqual(&zcmp) == 0 {
80 test.ReportError(t, z, zcmp, x)
81 }
82 }
83 }
84
View as plain text