mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00

* [NOD-510] Change coinbase flags to kaspad. * [NOD-510] Removed superfluous spaces after periods in comments. * [NOD-510] Rename btcd -> kaspad in the root folder. * [NOD-510] Rename BtcEncode -> KaspaEncode and BtcDecode -> KaspaDecode. * [NOD-510] Rename BtcEncode -> KaspaEncode and BtcDecode -> KaspaDecode. * [NOD-510] Continue renaming btcd -> kaspad. * [NOD-510] Rename btcjson -> kaspajson. * [NOD-510] Rename file names inside kaspajson. * [NOD-510] Rename kaspajson -> jsonrpc. * [NOD-510] Finish renaming in addrmgr. * [NOD-510] Rename package btcec to ecc. * [NOD-510] Finish renaming stuff in blockdag. * [NOD-510] Rename stuff in cmd. * [NOD-510] Rename stuff in config. * [NOD-510] Rename stuff in connmgr. * [NOD-510] Rename stuff in dagconfig. * [NOD-510] Rename stuff in database. * [NOD-510] Rename stuff in docker. * [NOD-510] Rename stuff in integration. * [NOD-510] Rename jsonrpc to rpcmodel. * [NOD-510] Rename stuff in limits. * [NOD-510] Rename stuff in logger. * [NOD-510] Rename stuff in mempool. * [NOD-510] Rename stuff in mining. * [NOD-510] Rename stuff in netsync. * [NOD-510] Rename stuff in peer. * [NOD-510] Rename stuff in release. * [NOD-510] Rename stuff in rpcclient. * [NOD-510] Rename stuff in server. * [NOD-510] Rename stuff in signal. * [NOD-510] Rename stuff in txscript. * [NOD-510] Rename stuff in util. * [NOD-510] Rename stuff in wire. * [NOD-510] Fix failing tests. * [NOD-510] Fix merge errors. * [NOD-510] Fix go vet errors. * [NOD-510] Remove merged file that's no longer relevant. * [NOD-510] Add a comment above Op0. * [NOD-510] Fix some comments referencing Bitcoin Core. * [NOD-510] Fix some more comments referencing Bitcoin Core. * [NOD-510] Fix bitcoin -> kaspa. * [NOD-510] Fix more bitcoin -> kaspa. * [NOD-510] Fix comments, remove DisconnectBlock in addrindex. * [NOD-510] Rename KSPD to KASD. * [NOD-510] Fix comments and user agent.
68 lines
1.9 KiB
Go
68 lines
1.9 KiB
Go
// Copyright 2015 The btcsuite developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package ecc
|
|
|
|
import (
|
|
"compress/zlib"
|
|
"encoding/base64"
|
|
"encoding/binary"
|
|
"io/ioutil"
|
|
"strings"
|
|
)
|
|
|
|
//go:generate go run -tags gensecp256k1 genprecomps.go
|
|
|
|
// loadS256BytePoints decompresses and deserializes the pre-computed byte points
|
|
// used to accelerate scalar base multiplication for the secp256k1 curve. This
|
|
// approach is used since it allows the compile to use significantly less ram
|
|
// and be performed much faster than it is with hard-coding the final in-memory
|
|
// data structure. At the same time, it is quite fast to generate the in-memory
|
|
// data structure at init time with this approach versus computing the table.
|
|
func loadS256BytePoints() error {
|
|
// There will be no byte points to load when generating them.
|
|
bp := secp256k1BytePoints
|
|
if len(bp) == 0 {
|
|
return nil
|
|
}
|
|
|
|
// Decompress the pre-computed table used to accelerate scalar base
|
|
// multiplication.
|
|
decoder := base64.NewDecoder(base64.StdEncoding, strings.NewReader(bp))
|
|
r, err := zlib.NewReader(decoder)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
serialized, err := ioutil.ReadAll(r)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Deserialize the precomputed byte points and set the curve to them.
|
|
offset := 0
|
|
var bytePoints [32][256][3]fieldVal
|
|
for byteNum := 0; byteNum < 32; byteNum++ {
|
|
// All points in this window.
|
|
for i := 0; i < 256; i++ {
|
|
px := &bytePoints[byteNum][i][0]
|
|
py := &bytePoints[byteNum][i][1]
|
|
pz := &bytePoints[byteNum][i][2]
|
|
for i := 0; i < 10; i++ {
|
|
px.n[i] = binary.LittleEndian.Uint32(serialized[offset:])
|
|
offset += 4
|
|
}
|
|
for i := 0; i < 10; i++ {
|
|
py.n[i] = binary.LittleEndian.Uint32(serialized[offset:])
|
|
offset += 4
|
|
}
|
|
for i := 0; i < 10; i++ {
|
|
pz.n[i] = binary.LittleEndian.Uint32(serialized[offset:])
|
|
offset += 4
|
|
}
|
|
}
|
|
}
|
|
secp256k1.bytePoints = &bytePoints
|
|
return nil
|
|
}
|