github.com/chain5j/chain5j-pkg@v1.0.7/crypto/signature/secp256k1/btcecv1/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 22 func main() { 23 fi, err := os.Create("secp256k1.go") 24 if err != nil { 25 log.Fatal(err) 26 } 27 defer fi.Close() 28 29 // Compress the serialized byte points. 30 serialized := S256().SerializedBytePoints() 31 var compressed bytes.Buffer 32 w := zlib.NewWriter(&compressed) 33 if _, err := w.Write(serialized); err != nil { 34 fmt.Println(err) 35 os.Exit(1) 36 } 37 w.Close() 38 39 // Encode the compressed byte points with base64. 40 encoded := make([]byte, base64.StdEncoding.EncodedLen(compressed.Len())) 41 base64.StdEncoding.Encode(encoded, compressed.Bytes()) 42 43 fmt.Fprintln(fi, "// Copyright (c) 2015 The btcsuite developers") 44 fmt.Fprintln(fi, "// Use of this source code is governed by an ISC") 45 fmt.Fprintln(fi, "// license that can be found in the LICENSE file.") 46 fmt.Fprintln(fi) 47 fmt.Fprintln(fi, "package btcec") 48 fmt.Fprintln(fi) 49 fmt.Fprintln(fi, "// Auto-generated file (see genprecomps.go)") 50 fmt.Fprintln(fi, "// DO NOT EDIT") 51 fmt.Fprintln(fi) 52 fmt.Fprintf(fi, "var secp256k1BytePoints = %q\n", string(encoded)) 53 54 a1, b1, a2, b2 := btcec.S256().EndomorphismVectors() 55 fmt.Println("The following values are the computed linearly " + 56 "independent vectors needed to make use of the secp256k1 " + 57 "endomorphism:") 58 fmt.Printf("a1: %x\n", a1) 59 fmt.Printf("b1: %x\n", b1) 60 fmt.Printf("a2: %x\n", a2) 61 fmt.Printf("b2: %x\n", b2) 62 }