From 4a69978816ed8f8a3dc522e9e51b541b28703d1d Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Tue, 14 Jan 2020 12:06:13 +0300 Subject: [PATCH] Update RFC6979 to new release --- go.mod | 2 +- go.sum | 4 ++-- rfc6979.go | 11 ++++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 21d3bdc..4c3f661 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.13 require ( github.com/mr-tron/base58 v1.1.2 - github.com/nspcc-dev/rfc6979 v0.1.0 + github.com/nspcc-dev/rfc6979 v0.2.0 github.com/pkg/errors v0.8.1 github.com/stretchr/testify v1.4.0 ) diff --git a/go.sum b/go.sum index ed5feea..d6d8473 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/mr-tron/base58 v1.1.2 h1:ZEw4I2EgPKDJ2iEw0cNmLB3ROrEmkOtXIkaG7wZg+78= github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/nspcc-dev/rfc6979 v0.1.0 h1:Lwg7esRRoyK1Up/IN1vAef1EmvrBeMHeeEkek2fAJ6c= -github.com/nspcc-dev/rfc6979 v0.1.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso= +github.com/nspcc-dev/rfc6979 v0.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE= +github.com/nspcc-dev/rfc6979 v0.2.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/rfc6979.go b/rfc6979.go index b54d2e8..007198a 100644 --- a/rfc6979.go +++ b/rfc6979.go @@ -34,11 +34,10 @@ func hashBytesRFC6979(data []byte) []byte { // Note that FIPS 186-3 section 4.6 specifies that the hash should be truncated // to the byte-length of the subgroup. This function does not perform that. func SignRFC6979(key *ecdsa.PrivateKey, msg []byte) ([]byte, error) { - r, s, err := rfc6979.SignECDSA(key, hashBytesRFC6979(msg), sha256.New) - if err != nil { - return nil, err + if key == nil { + return nil, ErrEmptyPrivateKey } - + r, s := rfc6979.SignECDSA(key, hashBytesRFC6979(msg), sha256.New) return append(r.Bytes(), s.Bytes()...), nil } @@ -53,7 +52,9 @@ func decodeSignature(sig []byte) (*big.Int, *big.Int, error) { // VerifyRFC6979 verifies the signature of msg using the public key. It // return nil only if signature is valid. func VerifyRFC6979(key *ecdsa.PublicKey, msg, sig []byte) error { - if r, s, err := decodeSignature(sig); err != nil { + if key == nil { + return ErrEmptyPublicKey + } else if r, s, err := decodeSignature(sig); err != nil { return err } else if !ecdsa.Verify(key, hashBytesRFC6979(msg), r, s) { return ErrWrongSignature