Skip to content

Commit

Permalink
Merge pull request #101 from nspcc-dev/drop-rfc6979
Browse files Browse the repository at this point in the history
internal: drop rfc6979 dependency
  • Loading branch information
AnnaShaleva authored Mar 5, 2024
2 parents 87e2570 + fad4185 commit 6d71362
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 22 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ module github.com/nspcc-dev/dbft
go 1.20

require (
github.com/nspcc-dev/rfc6979 v0.2.1
github.com/stretchr/testify v1.9.0
github.com/twmb/murmur3 v1.1.8
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.17.0
)

require (
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/nspcc-dev/rfc6979 v0.2.1 h1:8wWxkamHWFmO790GsewSoKUSJjVnL1fmdRpokU/RgRM=
github.com/nspcc-dev/rfc6979 v0.2.1/go.mod h1:Tk7h5kyUWkhjyO3zUgFFhy1v2vQv3BvQEntakdtqrWc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
Expand All @@ -13,8 +11,6 @@ go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
7 changes: 5 additions & 2 deletions internal/crypto/ecdsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package crypto
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/sha256"
"errors"
"io"
"math/big"

"github.com/nspcc-dev/dbft"
"github.com/nspcc-dev/rfc6979"
)

type (
Expand Down Expand Up @@ -50,7 +50,10 @@ func NewECDSAPrivateKey(key *ecdsa.PrivateKey) dbft.PrivateKey {
// Sign signs message using P-256 curve.
func (e ECDSAPriv) Sign(msg []byte) ([]byte, error) {
h := sha256.Sum256(msg)
r, s := rfc6979.SignECDSA(e.PrivateKey, h[:], sha256.New)
r, s, err := ecdsa.Sign(rand.Reader, e.PrivateKey, h[:])
if err != nil {
return nil, err
}

sig := make([]byte, 32*2)
_ = r.FillBytes(sig[:32])
Expand Down
12 changes: 5 additions & 7 deletions internal/crypto/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package crypto
import (
"crypto/sha256"
"encoding/hex"

"golang.org/x/crypto/ripemd160" //nolint:staticcheck // SA1019: package golang.org/x/crypto/ripemd160 is deprecated
)

const (
Expand Down Expand Up @@ -37,12 +35,12 @@ func Hash256(data []byte) Uint256 {

// Hash160 returns ripemd160 from sha256 of data.
func Hash160(data []byte) Uint160 {
h1 := sha256.Sum256(data)
rp := ripemd160.New()
_, _ = rp.Write(h1[:])
var (
h1 = sha256.Sum256(data)
h Uint160
)

var h Uint160
copy(h[:], rp.Sum(nil))
copy(h[:], h1[:Uint160Size])

return h
}
9 changes: 2 additions & 7 deletions internal/crypto/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ var hash160tc = []struct {
data []byte
hash Uint160
}{
{[]byte{}, parse160("b472a266d0bd89c13706a4132ccfb16f7c3b9fcb")},
{[]byte{0, 1, 2, 3}, parse160("3c3fa3d4adcaf8f52d5b1843975e122548269937")},
{[]byte{}, Uint160{0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4}},
{[]byte{0, 1, 2, 3}, Uint160{0x5, 0x4e, 0xde, 0xc1, 0xd0, 0x21, 0x1f, 0x62, 0x4f, 0xed, 0xc, 0xbc, 0xa9, 0xd4, 0xf9, 0x40, 0xb, 0xe, 0x49, 0x1c}},
}

func TestHash256(t *testing.T) {
Expand All @@ -40,11 +40,6 @@ func parse256(s string) (h Uint256) {
return
}

func parse160(s string) (h Uint160) {
parseHex(h[:], s)
return
}

func parseHex(b []byte, s string) {
buf, err := hex.DecodeString(s)
if err != nil || len(buf) != len(b) {
Expand Down

0 comments on commit 6d71362

Please sign in to comment.