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