github.com/lbryio/lbcd@v0.22.119/btcec/genprecomps.go (about) 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. 4 5 // This file is ignored during the regular build due to the following build tag. 6 // It is called by go generate and used to automatically generate pre-computed 7 // tables used to accelerate operations. 8 //go:build ignore 9 // +build ignore 10 11 package main 12 13 import ( 14 "bytes" 15 "compress/zlib" 16 "encoding/base64" 17 "fmt" 18 "log" 19 "os" 20 21 "github.com/lbryio/lbcd/btcec" 22 ) 23 24 func main() { 25 fi, err := os.Create("secp256k1.go") 26 if err != nil { 27 log.Fatal(err) 28 } 29 defer fi.Close() 30 31 // Compress the serialized byte points. 32 serialized := btcec.S256().SerializedBytePoints() 33 var compressed bytes.Buffer 34 w := zlib.NewWriter(&compressed) 35 if _, err := w.Write(serialized); err != nil { 36 fmt.Println(err) 37 os.Exit(1) 38 } 39 w.Close() 40 41 // Encode the compressed byte points with base64. 42 encoded := make([]byte, base64.StdEncoding.EncodedLen(compressed.Len())) 43 base64.StdEncoding.Encode(encoded, compressed.Bytes()) 44 45 fmt.Fprintln(fi, "// Copyright (c) 2015 The btcsuite developers") 46 fmt.Fprintln(fi, "// Use of this source code is governed by an ISC") 47 fmt.Fprintln(fi, "// license that can be found in the LICENSE file.") 48 fmt.Fprintln(fi) 49 fmt.Fprintln(fi, "package btcec") 50 fmt.Fprintln(fi) 51 fmt.Fprintln(fi, "// Auto-generated file (see genprecomps.go)") 52 fmt.Fprintln(fi, "// DO NOT EDIT") 53 fmt.Fprintln(fi) 54 fmt.Fprintf(fi, "var secp256k1BytePoints = %q\n", string(encoded)) 55 56 a1, b1, a2, b2 := btcec.S256().EndomorphismVectors() 57 fmt.Println("The following values are the computed linearly " + 58 "independent vectors needed to make use of the secp256k1 " + 59 "endomorphism:") 60 fmt.Printf("a1: %x\n", a1) 61 fmt.Printf("b1: %x\n", b1) 62 fmt.Printf("a2: %x\n", a2) 63 fmt.Printf("b2: %x\n", b2) 64 }