1 // Copyright 2015 The btcsuite developers
2 // Use of this source code is governed by an ISC
3 // license that can be found in the LICENSE file.
15 //go:generate go run -tags gensecp256k1 genprecomps.go
17 // loadS256BytePoints decompresses and deserializes the pre-computed byte points
18 // used to accelerate scalar base multiplication for the secp256k1 curve. This
19 // approach is used since it allows the compile to use significantly less ram
20 // and be performed much faster than it is with hard-coding the final in-memory
21 // data structure. At the same time, it is quite fast to generate the in-memory
22 // data structure at init time with this approach versus computing the table.
23 func loadS256BytePoints() error {
24 // There will be no byte points to load when generating them.
25 bp := secp256k1BytePoints
30 // Decompress the pre-computed table used to accelerate scalar base
32 decoder := base64.NewDecoder(base64.StdEncoding, strings.NewReader(bp))
33 r, err := zlib.NewReader(decoder)
37 serialized, err := ioutil.ReadAll(r)
42 // Deserialize the precomputed byte points and set the curve to them.
44 var bytePoints [32][256][3]fieldVal
45 for byteNum := 0; byteNum < 32; byteNum++ {
46 // All points in this window.
47 for i := 0; i < 256; i++ {
48 px := &bytePoints[byteNum][i][0]
49 py := &bytePoints[byteNum][i][1]
50 pz := &bytePoints[byteNum][i][2]
51 for i := 0; i < 10; i++ {
52 px.n[i] = binary.LittleEndian.Uint32(serialized[offset:])
55 for i := 0; i < 10; i++ {
56 py.n[i] = binary.LittleEndian.Uint32(serialized[offset:])
59 for i := 0; i < 10; i++ {
60 pz.n[i] = binary.LittleEndian.Uint32(serialized[offset:])
65 secp256k1.bytePoints = &bytePoints