endif
endif
-PACKAGES := $(shell go list ./... | grep -v '/vendor/' | grep -v '/crypto/ed25519/chainkd')
+PACKAGES := $(shell go list ./... | grep -v '/lib/')
BUILD_FLAGS := -ldflags "-X github.com/bytom/bytom/version.GitCommit=`git rev-parse HEAD`"
test:
@echo "====> Running go test"
- @go test -tags "network" $(PACKAGES)
+ @go test $(PACKAGES)
benchmark:
@go test -bench $(PACKAGES)
import (
"context"
+ "crypto/ed25519"
"encoding/hex"
"strings"
"github.com/bytom/bytom/common"
"github.com/bytom/bytom/consensus"
"github.com/bytom/bytom/crypto"
- "github.com/bytom/bytom/crypto/ed25519"
"github.com/bytom/bytom/crypto/ed25519/chainkd"
chainjson "github.com/bytom/bytom/encoding/json"
)
import (
"context"
+ "crypto/ed25519"
"encoding/hex"
"fmt"
"github.com/bytom/bytom/blockchain/signers"
"github.com/bytom/bytom/blockchain/txbuilder"
"github.com/bytom/bytom/consensus"
- "github.com/bytom/bytom/crypto/ed25519"
"github.com/bytom/bytom/crypto/ed25519/chainkd"
chainjson "github.com/bytom/bytom/encoding/json"
"github.com/bytom/bytom/errors"
import (
"context"
+ "crypto/ed25519"
"encoding/json"
"strings"
"sync"
"github.com/bytom/bytom/blockchain/signers"
"github.com/bytom/bytom/common"
"github.com/bytom/bytom/consensus"
- "github.com/bytom/bytom/crypto/ed25519"
"github.com/bytom/bytom/crypto/ed25519/chainkd"
dbm "github.com/bytom/bytom/database/leveldb"
chainjson "github.com/bytom/bytom/encoding/json"
package pseudohsm
import (
+ "crypto/ed25519"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
- "github.com/bytom/bytom/crypto/ed25519"
"github.com/bytom/bytom/errors"
)
import (
"context"
+ "crypto/ed25519"
"encoding/hex"
"encoding/json"
"math"
"github.com/bytom/bytom/common"
"github.com/bytom/bytom/consensus"
"github.com/bytom/bytom/crypto"
- "github.com/bytom/bytom/crypto/ed25519"
"github.com/bytom/bytom/crypto/ed25519/chainkd"
chainjson "github.com/bytom/bytom/encoding/json"
"github.com/bytom/bytom/errors"
package chainkd
import (
+ "crypto/ed25519"
"crypto/hmac"
"crypto/rand"
"crypto/sha512"
"io"
- "github.com/bytom/bytom/crypto/ed25519"
"github.com/bytom/bytom/crypto/ed25519/ecmath"
)
import (
"crypto"
+ "crypto/ed25519"
"crypto/sha512"
"errors"
"io"
"strconv"
- "github.com/bytom/bytom/crypto/ed25519"
"github.com/bytom/bytom/crypto/ed25519/internal/edwards25519"
)
import (
"bytes"
"crypto"
+ "crypto/ed25519"
"testing"
-
- "github.com/bytom/bytom/crypto/ed25519"
)
// Testing basic InnerSign+Verify and the invariants:
package chainkd
import (
+ "crypto/ed25519"
"io"
-
- "github.com/bytom/bytom/crypto/ed25519"
)
// Utility functions
+++ /dev/null
-// Package ed25519 implements the Ed25519 signature algorithm. See
-// http://ed25519.cr.yp.to/.
-//
-// These functions are also compatible with the “Ed25519” function defined in
-// https://tools.ietf.org/html/draft-irtf-cfrg-eddsa-05.
-package ed25519
-
-// This code is a port of the public domain, “ref10” implementation of ed25519
-// from SUPERCOP.
-
-import (
- cryptorand "crypto/rand"
- "crypto/sha512"
- "crypto/subtle"
- "encoding/hex"
- "io"
- "strconv"
-
- "github.com/bytom/bytom/crypto/ed25519/internal/edwards25519"
-)
-
-const (
- // PublicKeySize is the size, in bytes, of public keys as used in this package.
- PublicKeySize = 32
- // PrivateKeySize is the size, in bytes, of private keys as used in this package.
- PrivateKeySize = 64
- // SignatureSize is the size, in bytes, of signatures generated and verified by this package.
- SignatureSize = 64
- // SeedSize is the size, in bytes, of private key seeds. These are the private key representations used by RFC 8032.
- SeedSize = 32
-)
-
-// PublicKey is the type of Ed25519 public keys.
-type PublicKey []byte
-
-// PrivateKey is the type of Ed25519 private keys. It implements crypto.Signer.
-type PrivateKey []byte
-
-// Public returns the PublicKey corresponding to priv.
-func (priv PrivateKey) Public() PublicKey {
- publicKey := make([]byte, PublicKeySize)
- copy(publicKey, priv[32:])
- return PublicKey(publicKey)
-}
-
-// Seed returns the private key seed corresponding to priv. It is provided for
-// interoperability with RFC 8032. RFC 8032's private keys correspond to seeds
-// in this package.
-func (priv PrivateKey) Seed() []byte {
- seed := make([]byte, SeedSize)
- copy(seed, priv[:32])
- return seed
-}
-
-func (priv PrivateKey) String() string {
- return hex.EncodeToString(priv)
-}
-
-// GenerateKey generates a public/private key pair using entropy from rand.
-// If rand is nil, crypto/rand.Reader will be used.
-func GenerateKey(rand io.Reader) (publicKey PublicKey, privateKey PrivateKey, err error) {
- if rand == nil {
- rand = cryptorand.Reader
- }
-
- privateKey = make([]byte, PrivateKeySize)
- publicKey = make([]byte, PublicKeySize)
- _, err = io.ReadFull(rand, privateKey[:32])
- if err != nil {
- return nil, nil, err
- }
-
- digest := sha512.Sum512(privateKey[:32])
- digest[0] &= 248
- digest[31] &= 127
- digest[31] |= 64
-
- var A edwards25519.ExtendedGroupElement
- var hBytes [32]byte
- copy(hBytes[:], digest[:])
- edwards25519.GeScalarMultBase(&A, &hBytes)
- var publicKeyBytes [32]byte
- A.ToBytes(&publicKeyBytes)
-
- copy(privateKey[32:], publicKeyBytes[:])
- copy(publicKey, publicKeyBytes[:])
-
- return publicKey, privateKey, nil
-}
-
-// NewKeyFromSeed calculates a private key from a seed. It will panic if
-// len(seed) is not SeedSize. This function is provided for interoperability
-// with RFC 8032. RFC 8032's private keys correspond to seeds in this
-// package.
-func NewKeyFromSeed(seed []byte) PrivateKey {
- if l := len(seed); l != SeedSize {
- panic("ed25519: bad seed length: " + strconv.Itoa(l))
- }
-
- digest := sha512.Sum512(seed)
- digest[0] &= 248
- digest[31] &= 127
- digest[31] |= 64
-
- var A edwards25519.ExtendedGroupElement
- var hBytes [32]byte
- copy(hBytes[:], digest[:])
- edwards25519.GeScalarMultBase(&A, &hBytes)
- var publicKeyBytes [32]byte
- A.ToBytes(&publicKeyBytes)
-
- privateKey := make([]byte, PrivateKeySize)
- copy(privateKey, seed)
- copy(privateKey[32:], publicKeyBytes[:])
-
- return privateKey
-}
-
-// Sign signs the message with privateKey and returns a signature. It will
-// panic if len(privateKey) is not PrivateKeySize.
-func Sign(privateKey PrivateKey, message []byte) []byte {
- if l := len(privateKey); l != PrivateKeySize {
- panic("ed25519: bad private key length: " + strconv.Itoa(l))
- }
-
- h := sha512.New()
- h.Write(privateKey[:32])
-
- var digest1, messageDigest, hramDigest [64]byte
- var expandedSecretKey [32]byte
- h.Sum(digest1[:0])
- copy(expandedSecretKey[:], digest1[:])
- expandedSecretKey[0] &= 248
- expandedSecretKey[31] &= 63
- expandedSecretKey[31] |= 64
-
- h.Reset()
- h.Write(digest1[32:])
- h.Write(message)
- h.Sum(messageDigest[:0])
-
- var messageDigestReduced [32]byte
- edwards25519.ScReduce(&messageDigestReduced, &messageDigest)
- var R edwards25519.ExtendedGroupElement
- edwards25519.GeScalarMultBase(&R, &messageDigestReduced)
-
- var encodedR [32]byte
- R.ToBytes(&encodedR)
-
- h.Reset()
- h.Write(encodedR[:])
- h.Write(privateKey[32:])
- h.Write(message)
- h.Sum(hramDigest[:0])
- var hramDigestReduced [32]byte
- edwards25519.ScReduce(&hramDigestReduced, &hramDigest)
-
- var s [32]byte
- edwards25519.ScMulAdd(&s, &hramDigestReduced, &expandedSecretKey, &messageDigestReduced)
-
- signature := make([]byte, SignatureSize)
- copy(signature[:], encodedR[:])
- copy(signature[32:], s[:])
-
- return signature
-}
-
-// Verify reports whether sig is a valid signature of message by publicKey. It
-// will panic if len(publicKey) is not PublicKeySize.
-func Verify(publicKey PublicKey, message, sig []byte) bool {
- if l := len(publicKey); l != PublicKeySize {
- panic("ed25519: bad public key length: " + strconv.Itoa(l))
- }
-
- if len(sig) != SignatureSize || sig[63]&224 != 0 {
- return false
- }
-
- var A edwards25519.ExtendedGroupElement
- var publicKeyBytes [32]byte
- copy(publicKeyBytes[:], publicKey)
- if !A.FromBytes(&publicKeyBytes) {
- return false
- }
- edwards25519.FeNeg(&A.X, &A.X)
- edwards25519.FeNeg(&A.T, &A.T)
-
- h := sha512.New()
- h.Write(sig[:32])
- h.Write(publicKey[:])
- h.Write(message)
- var digest [64]byte
- h.Sum(digest[:0])
-
- var hReduced [32]byte
- edwards25519.ScReduce(&hReduced, &digest)
-
- var R edwards25519.ProjectiveGroupElement
- var b [32]byte
- copy(b[:], sig[32:])
- edwards25519.GeDoubleScalarMultVartime(&R, &hReduced, &A, &b)
-
- var checkR [32]byte
- R.ToBytes(&checkR)
- return subtle.ConstantTimeCompare(sig[:32], checkR[:]) == 1
-}
+++ /dev/null
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file at
-// https://github.com/golang/crypto/blob/master/LICENSE.
-
-package ed25519
-
-import (
- "bufio"
- "bytes"
- "compress/gzip"
- "crypto/rand"
- "encoding/hex"
- "os"
- "strings"
- "testing"
-
- "github.com/bytom/bytom/crypto/ed25519/internal/edwards25519"
-)
-
-type zeroReader struct{}
-
-func (zeroReader) Read(buf []byte) (int, error) {
- for i := range buf {
- buf[i] = 0
- }
- return len(buf), nil
-}
-
-func TestUnmarshalMarshal(t *testing.T) {
- pub, _, _ := GenerateKey(rand.Reader)
-
- var A edwards25519.ExtendedGroupElement
- var pubBytes [32]byte
- copy(pubBytes[:], pub)
- if !A.FromBytes(&pubBytes) {
- t.Fatalf("ExtendedGroupElement.FromBytes failed")
- }
-
- var pub2 [32]byte
- A.ToBytes(&pub2)
-
- if pubBytes != pub2 {
- t.Errorf("FromBytes(%v)->ToBytes does not round-trip, got %x\n", pubBytes, pub2)
- }
-}
-
-func TestSignVerify(t *testing.T) {
- var zero zeroReader
- public, private, _ := GenerateKey(zero)
-
- message := []byte("test message")
- sig := Sign(private, message)
- if !Verify(public, message, sig) {
- t.Errorf("valid signature rejected")
- }
-
- wrongMessage := []byte("wrong message")
- if Verify(public, wrongMessage, sig) {
- t.Errorf("signature of different message accepted")
- }
-}
-
-func TestGolden(t *testing.T) {
- // sign.input.gz is a selection of test cases from
- // http://ed25519.cr.yp.to/python/sign.input
- testDataZ, err := os.Open("testdata/sign.input.gz")
- if err != nil {
- t.Fatal(err)
- }
- defer testDataZ.Close()
- testData, err := gzip.NewReader(testDataZ)
- if err != nil {
- t.Fatal(err)
- }
- defer testData.Close()
-
- scanner := bufio.NewScanner(testData)
- lineNo := 0
-
- for scanner.Scan() {
- lineNo++
-
- line := scanner.Text()
- parts := strings.Split(line, ":")
- if len(parts) != 5 {
- t.Fatalf("bad number of parts on line %d", lineNo)
- }
-
- privBytes, _ := hex.DecodeString(parts[0])
- pubKey, _ := hex.DecodeString(parts[1])
- msg, _ := hex.DecodeString(parts[2])
- sig, _ := hex.DecodeString(parts[3])
- // The signatures in the test vectors also include the message
- // at the end, but we just want R and S.
- sig = sig[:SignatureSize]
-
- if l := len(pubKey); l != PublicKeySize {
- t.Fatalf("bad public key length on line %d: got %d bytes", lineNo, l)
- }
-
- var priv [PrivateKeySize]byte
- copy(priv[:], privBytes)
- copy(priv[32:], pubKey)
-
- sig2 := Sign(priv[:], msg)
- if !bytes.Equal(sig, sig2[:]) {
- t.Errorf("different signature result on line %d: %x vs %x", lineNo, sig, sig2)
- }
-
- if !Verify(pubKey, msg, sig2) {
- t.Errorf("signature failed to verify on line %d", lineNo)
- }
- }
-
- if err := scanner.Err(); err != nil {
- t.Fatalf("error reading test data: %s", err)
- }
-}
-
-func BenchmarkKeyGeneration(b *testing.B) {
- var zero zeroReader
- for i := 0; i < b.N; i++ {
- if _, _, err := GenerateKey(zero); err != nil {
- b.Fatal(err)
- }
- }
-}
-
-func BenchmarkSigning(b *testing.B) {
- var zero zeroReader
- _, priv, err := GenerateKey(zero)
- if err != nil {
- b.Fatal(err)
- }
- message := []byte("Hello, world!")
- b.ResetTimer()
- for i := 0; i < b.N; i++ {
- Sign(priv, message)
- }
-}
-
-func BenchmarkVerification(b *testing.B) {
- var zero zeroReader
- pub, priv, err := GenerateKey(zero)
- if err != nil {
- b.Fatal(err)
- }
- message := []byte("Hello, world!")
- signature := Sign(priv, message)
- b.ResetTimer()
- for i := 0; i < b.N; i++ {
- Verify(pub, message, signature)
- }
-}
go 1.16
replace (
- github.com/agl/ed25519 => ./lib/github.com/tendermint/ed25519
github.com/prometheus/prometheus/util/flock => ./lib/github.com/prometheus/prometheus/util/flock
github.com/tendermint/go-wire => github.com/tendermint/go-amino v0.6.2
github.com/zondax/ledger-goclient => github.com/Zondax/ledger-cosmos-go v0.1.0
)
require (
- github.com/agl/ed25519 v0.0.0-00010101000000-000000000000 // indirect
github.com/btcsuite/btcd v0.21.0-beta // indirect
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd
github.com/cespare/cp v1.1.1
import (
"bytes"
+ "crypto"
"encoding/hex"
"errors"
"fmt"
"golang.org/x/crypto/sha3"
"github.com/bytom/bytom/common"
- "github.com/bytom/bytom/crypto/ed25519"
"github.com/bytom/bytom/p2p/netutil"
)
node *Node
}
-func newNetwork(conn transport, ourPubkey ed25519.PublicKey, dbPath string, netrestrict *netutil.Netlist) (*Network, error) {
+func newNetwork(conn transport, ourPubkey crypto.PublicKey, dbPath string, netrestrict *netutil.Netlist) (*Network, error) {
var ourID NodeID
- copy(ourID[:], ourPubkey[:nodeIDBits])
+ copy(ourID[:], ourPubkey.([]byte)[:nodeIDBits])
var db *nodeDB
if dbPath != "<no database>" {
import (
"bytes"
"crypto/ecdsa"
+ "crypto/ed25519"
"encoding/hex"
"errors"
"fmt"
"github.com/bytom/bytom/common"
cfg "github.com/bytom/bytom/config"
"github.com/bytom/bytom/crypto"
- "github.com/bytom/bytom/crypto/ed25519"
"github.com/bytom/bytom/p2p/netutil"
"github.com/bytom/bytom/version"
)
nodeID := priv.Public()
sig := ed25519.Sign(priv, common.BytesToHash(packet[headSize:]).Bytes())
copy(packet, versionPrefix)
- copy(packet[versionPrefixSize:], nodeID[:])
+ copy(packet[versionPrefixSize:], nodeID.([]byte)[:])
copy(packet[versionPrefixSize+nodeIDSize:], sig)
hash = common.BytesToHash(packet[versionPrefixSize:]).Bytes()
package p2p
import (
+ "crypto/ed25519"
"fmt"
"net"
"sync"
cfg "github.com/bytom/bytom/config"
"github.com/bytom/bytom/consensus"
- "github.com/bytom/bytom/crypto/ed25519"
"github.com/bytom/bytom/errors"
"github.com/bytom/bytom/event"
"github.com/bytom/bytom/p2p/connection"
package vm
import (
+ "crypto/ed25519"
"crypto/sha256"
"hash"
"golang.org/x/crypto/sha3"
"github.com/bytom/bytom/crypto"
- "github.com/bytom/bytom/crypto/ed25519"
"github.com/bytom/bytom/math/checked"
)
package vmutil
import (
+ "crypto/ed25519"
+
"github.com/bytom/bytom/consensus/bcrp"
- "github.com/bytom/bytom/crypto/ed25519"
"github.com/bytom/bytom/errors"
"github.com/bytom/bytom/protocol/vm"
)
package vmutil
import (
+ "crypto/ed25519"
"encoding/hex"
"testing"
- "github.com/bytom/bytom/crypto/ed25519"
"github.com/bytom/bytom/errors"
)
package testutil
import (
- "github.com/bytom/bytom/crypto/ed25519"
+ "crypto/ed25519"
+
"github.com/bytom/bytom/crypto/ed25519/chainkd"
)