1
2
3
4
5
6
7 package fiat
8
9
10
11
12 func (e *P384Element) Invert(x *P384Element) *P384Element {
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 var z = new(P384Element).Set(e)
37 var t0 = new(P384Element)
38 var t1 = new(P384Element)
39 var t2 = new(P384Element)
40 var t3 = new(P384Element)
41
42 z.Square(x)
43 z.Mul(x, z)
44 z.Square(z)
45 t1.Mul(x, z)
46 z.Square(t1)
47 for s := 1; s < 3; s++ {
48 z.Square(z)
49 }
50 z.Mul(t1, z)
51 t0.Square(z)
52 for s := 1; s < 6; s++ {
53 t0.Square(t0)
54 }
55 t0.Mul(z, t0)
56 t2.Square(t0)
57 for s := 1; s < 12; s++ {
58 t2.Square(t2)
59 }
60 t0.Mul(t0, t2)
61 for s := 0; s < 6; s++ {
62 t0.Square(t0)
63 }
64 z.Mul(z, t0)
65 t0.Square(z)
66 t2.Mul(x, t0)
67 t0.Square(t2)
68 t0.Mul(x, t0)
69 t3.Square(t0)
70 for s := 1; s < 31; s++ {
71 t3.Square(t3)
72 }
73 t2.Mul(t2, t3)
74 t3.Square(t2)
75 for s := 1; s < 63; s++ {
76 t3.Square(t3)
77 }
78 t2.Mul(t2, t3)
79 t3.Square(t2)
80 for s := 1; s < 126; s++ {
81 t3.Square(t3)
82 }
83 t2.Mul(t2, t3)
84 for s := 0; s < 3; s++ {
85 t2.Square(t2)
86 }
87 t1.Mul(t1, t2)
88 for s := 0; s < 33; s++ {
89 t1.Square(t1)
90 }
91 t0.Mul(t0, t1)
92 for s := 0; s < 94; s++ {
93 t0.Square(t0)
94 }
95 z.Mul(z, t0)
96 for s := 0; s < 2; s++ {
97 z.Square(z)
98 }
99 z.Mul(x, z)
100
101 return e.Set(z)
102 }
103
View as plain text