1
2
3
4
5
6
7 package main
8
9 import (
10 "crypto/elliptic"
11 "encoding/binary"
12 "log"
13 "os"
14 )
15
16 func main() {
17
18 var pre [43][32 * 8]uint64
19 basePoint := []uint64{
20 0x79e730d418a9143c, 0x75ba95fc5fedb601, 0x79fb732b77622510, 0x18905f76a53755c6,
21 0xddf25357ce95560a, 0x8b4ab8e4ba19e45c, 0xd2e88688dd21f325, 0x8571ff1825885d85,
22 0x0000000000000001, 0xffffffff00000000, 0xffffffffffffffff, 0x00000000fffffffe,
23 }
24 t1 := make([]uint64, 12)
25 t2 := make([]uint64, 12)
26 copy(t2, basePoint)
27 zInv := make([]uint64, 4)
28 zInvSq := make([]uint64, 4)
29 for j := 0; j < 32; j++ {
30 copy(t1, t2)
31 for i := 0; i < 43; i++ {
32
33 if i != 0 {
34 for k := 0; k < 6; k++ {
35 elliptic.P256PointDoubleAsm(t1, t1)
36 }
37 }
38
39
40 elliptic.P256Inverse(zInv, t1[8:12])
41 elliptic.P256Sqr(zInvSq, zInv, 1)
42 elliptic.P256Mul(zInv, zInv, zInvSq)
43 elliptic.P256Mul(t1[:4], t1[:4], zInvSq)
44 elliptic.P256Mul(t1[4:8], t1[4:8], zInv)
45 copy(t1[8:12], basePoint[8:12])
46
47 copy(pre[i][j*8:], t1[:8])
48 }
49 if j == 0 {
50 elliptic.P256PointDoubleAsm(t2, basePoint)
51 } else {
52 elliptic.P256PointAddAsm(t2, t2, basePoint)
53 }
54 }
55
56 var bin []byte
57
58
59
60
61 for i := range &pre {
62 for _, v := range &pre[i] {
63 var u8 [8]byte
64 binary.LittleEndian.PutUint64(u8[:], v)
65 bin = append(bin, u8[:]...)
66 }
67 }
68
69 err := os.WriteFile("p256_asm_table.bin", bin, 0644)
70 if err != nil {
71 log.Fatal(err)
72 }
73 }
74
View as plain text