From fad41851f6d9f9dc259df6a6d841cc81fca77a86 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 4 Mar 2024 18:58:12 +0300 Subject: [PATCH] internal: drop golang.org/x/crypto dependency Along with deprecated RIPEMD160. It doesn't matter how we create hashes in test code. Signed-off-by: Roman Khimov --- go.mod | 1 - go.sum | 2 -- internal/crypto/hash.go | 12 +++++------- internal/crypto/hash_test.go | 9 ++------- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index bed08812..e0e071df 100644 --- a/go.mod +++ b/go.mod @@ -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 ( diff --git a/go.sum b/go.sum index 0fdf4341..6a692ceb 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/crypto/hash.go b/internal/crypto/hash.go index e99a29a6..aa2b3773 100644 --- a/internal/crypto/hash.go +++ b/internal/crypto/hash.go @@ -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 ( @@ -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 } diff --git a/internal/crypto/hash_test.go b/internal/crypto/hash_test.go index 33b96d74..9610b619 100644 --- a/internal/crypto/hash_test.go +++ b/internal/crypto/hash_test.go @@ -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) { @@ -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) {