Merge pull request #10 from nspcc-dev/update-rfc6979-library
Update RFC6979 to new release
This commit is contained in:
commit
5ba9a8ffc6
3 changed files with 9 additions and 8 deletions
2
go.mod
2
go.mod
|
@ -4,7 +4,7 @@ go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/mr-tron/base58 v1.1.2
|
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/pkg/errors v0.8.1
|
||||||
github.com/stretchr/testify v1.4.0
|
github.com/stretchr/testify v1.4.0
|
||||||
)
|
)
|
||||||
|
|
4
go.sum
4
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/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 h1:ZEw4I2EgPKDJ2iEw0cNmLB3ROrEmkOtXIkaG7wZg+78=
|
||||||
github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
|
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.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE=
|
||||||
github.com/nspcc-dev/rfc6979 v0.1.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
|
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 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
|
11
rfc6979.go
11
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
|
// 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.
|
// to the byte-length of the subgroup. This function does not perform that.
|
||||||
func SignRFC6979(key *ecdsa.PrivateKey, msg []byte) ([]byte, error) {
|
func SignRFC6979(key *ecdsa.PrivateKey, msg []byte) ([]byte, error) {
|
||||||
r, s, err := rfc6979.SignECDSA(key, hashBytesRFC6979(msg), sha256.New)
|
if key == nil {
|
||||||
if err != nil {
|
return nil, ErrEmptyPrivateKey
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
r, s := rfc6979.SignECDSA(key, hashBytesRFC6979(msg), sha256.New)
|
||||||
return append(r.Bytes(), s.Bytes()...), nil
|
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
|
// VerifyRFC6979 verifies the signature of msg using the public key. It
|
||||||
// return nil only if signature is valid.
|
// return nil only if signature is valid.
|
||||||
func VerifyRFC6979(key *ecdsa.PublicKey, msg, sig []byte) error {
|
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
|
return err
|
||||||
} else if !ecdsa.Verify(key, hashBytesRFC6979(msg), r, s) {
|
} else if !ecdsa.Verify(key, hashBytesRFC6979(msg), r, s) {
|
||||||
return ErrWrongSignature
|
return ErrWrongSignature
|
||||||
|
|
Loading…
Reference in a new issue