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