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