Skip to content

Commit

Permalink
internal: drop golang.org/x/crypto dependency
Browse files Browse the repository at this point in the history
Along with deprecated RIPEMD160. It doesn't matter how we create hashes in
test code.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
  • Loading branch information
roman-khimov committed Mar 4, 2024
1 parent 351eccf commit fad4185
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
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
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,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
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 fad4185

Please sign in to comment.