Skip to content

Commit a18ccec

Browse files
committed
chore: update go-multihash, drop minio sha256 for go1.21
See rational and benchmarks in multiformats/go-multihash#173. Fixes: libp2p#2308
1 parent 305282b commit a18ccec

File tree

12 files changed

+59
-14
lines changed

12 files changed

+59
-14
lines changed

core/crypto/ecdsa.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import (
1212

1313
pb "github.com/libp2p/go-libp2p/core/crypto/pb"
1414
"github.com/libp2p/go-libp2p/core/internal/catch"
15-
16-
"github.com/minio/sha256-simd"
15+
"github.com/libp2p/go-libp2p/internal/sha256"
1716
)
1817

1918
// ECDSAPrivateKey is an implementation of an ECDSA private key

core/crypto/key_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import (
1616
. "github.com/libp2p/go-libp2p/core/crypto"
1717
pb "github.com/libp2p/go-libp2p/core/crypto/pb"
1818
"github.com/libp2p/go-libp2p/core/test"
19+
"github.com/libp2p/go-libp2p/internal/sha256"
1920

2021
"github.com/decred/dcrd/dcrec/secp256k1/v4"
2122
secp256k1ecdsa "github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa"
22-
"github.com/minio/sha256-simd"
2323
)
2424

2525
func TestKeys(t *testing.T) {

core/crypto/rsa_go.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import (
1010

1111
pb "github.com/libp2p/go-libp2p/core/crypto/pb"
1212
"github.com/libp2p/go-libp2p/core/internal/catch"
13-
14-
"github.com/minio/sha256-simd"
13+
"github.com/libp2p/go-libp2p/internal/sha256"
1514
)
1615

1716
// RsaPrivateKey is an rsa private key

core/crypto/secp256k1.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"github.com/decred/dcrd/dcrec/secp256k1/v4"
1111
"github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa"
12-
"github.com/minio/sha256-simd"
12+
"github.com/libp2p/go-libp2p/internal/sha256"
1313
)
1414

1515
// Secp256k1PrivateKey is an Secp256k1 private key

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ require (
4141
github.com/multiformats/go-multiaddr-fmt v0.1.0
4242
github.com/multiformats/go-multibase v0.2.0
4343
github.com/multiformats/go-multicodec v0.8.1
44-
github.com/multiformats/go-multihash v0.2.1
44+
github.com/multiformats/go-multihash v0.2.2
4545
github.com/multiformats/go-multistream v0.4.1
4646
github.com/multiformats/go-varint v0.0.7
4747
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ github.com/multiformats/go-multibase v0.2.0/go.mod h1:bFBZX4lKCA/2lyOFSAoKH5SS6o
265265
github.com/multiformats/go-multicodec v0.8.1 h1:ycepHwavHafh3grIbR1jIXnKCsFm0fqsfEOsJ8NtKE8=
266266
github.com/multiformats/go-multicodec v0.8.1/go.mod h1:L3QTQvMIaVBkXOXXtVmYE+LI16i14xuaojr/H7Ai54k=
267267
github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
268-
github.com/multiformats/go-multihash v0.2.1 h1:aem8ZT0VA2nCHHk7bPJ1BjUbHNciqZC/d16Vve9l108=
269-
github.com/multiformats/go-multihash v0.2.1/go.mod h1:WxoMcYG85AZVQUyRyo9s4wULvW5qrI9vb2Lt6evduFc=
268+
github.com/multiformats/go-multihash v0.2.2 h1:Uu7LWs/PmWby1gkj1S1DXx3zyd3aVabA4FiMKn/2tAc=
269+
github.com/multiformats/go-multihash v0.2.2/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM=
270270
github.com/multiformats/go-multistream v0.4.1 h1:rFy0Iiyn3YT0asivDUIR05leAdwZq3de4741sbiSdfo=
271271
github.com/multiformats/go-multistream v0.4.1/go.mod h1:Mz5eykRVAjJWckE2U78c6xqdtyNUEhKSM0Lwar2p77Q=
272272
github.com/multiformats/go-varint v0.0.1/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=

internal/sha256/post_go1_21.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//go:build go1.21
2+
3+
// This package use build tags to select between github.com/minio/sha256-simd
4+
// for go1.20 and bellow and crypto/sha256 for go1.21 and above.
5+
// This is used because a fast SHANI implementation of sha256 is only avaiable
6+
// in the std for go1.21 and above. See https://go.dev/issue/50543.
7+
// TODO: Once go1.22 releases remove this package and replace all uses
8+
// with crypto/sha256 because the two supported version of go will have the fast
9+
// implementation.
10+
package sha256
11+
12+
import (
13+
"crypto/sha256"
14+
"hash"
15+
)
16+
17+
func Sum256(b []byte) [sha256.Size]byte {
18+
return sha256.Sum256(b)
19+
}
20+
21+
func New() hash.Hash {
22+
return sha256.New()
23+
}

internal/sha256/pre_go1_21.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//go:build !go1.21
2+
3+
// This package use build tags to select between github.com/minio/sha256-simd
4+
// for go1.20 and bellow and crypto/sha256 for go1.21 and above.
5+
// This is used because a fast SHANI implementation of sha256 is only avaiable
6+
// in the std for go1.21 and above. See https://go.dev/issue/50543.
7+
// TODO: Once go1.22 releases remove this package and replace all uses
8+
// with crypto/sha256 because the two supported version of go will have the fast
9+
// implementation.
10+
package sha256
11+
12+
import (
13+
"hash"
14+
15+
"github.com/minio/sha256-simd"
16+
)
17+
18+
func Sum256(b []byte) [sha256.Size]byte {
19+
return sha256.Sum256(b)
20+
}
21+
22+
func New() hash.Hash {
23+
return sha256.New()
24+
}

p2p/net/swarm/swarm_addr_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/libp2p/go-libp2p/core/peer"
1010
"github.com/libp2p/go-libp2p/core/peerstore"
1111
"github.com/libp2p/go-libp2p/core/test"
12+
"github.com/libp2p/go-libp2p/internal/sha256"
1213
"github.com/libp2p/go-libp2p/p2p/host/eventbus"
1314
"github.com/libp2p/go-libp2p/p2p/net/swarm"
1415
swarmt "github.com/libp2p/go-libp2p/p2p/net/swarm/testing"
@@ -18,7 +19,6 @@ import (
1819
"github.com/libp2p/go-libp2p/p2p/transport/tcp"
1920
webtransport "github.com/libp2p/go-libp2p/p2p/transport/webtransport"
2021

21-
"github.com/minio/sha256-simd"
2222
ma "github.com/multiformats/go-multiaddr"
2323
"github.com/multiformats/go-multibase"
2424
"github.com/multiformats/go-multihash"

p2p/security/noise/handshake.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import (
1212

1313
"github.com/libp2p/go-libp2p/core/crypto"
1414
"github.com/libp2p/go-libp2p/core/peer"
15+
"github.com/libp2p/go-libp2p/internal/sha256"
1516
"github.com/libp2p/go-libp2p/p2p/security/noise/pb"
1617

1718
"github.com/flynn/noise"
1819
pool "github.com/libp2p/go-buffer-pool"
19-
"github.com/minio/sha256-simd"
2020
"google.golang.org/protobuf/proto"
2121
)
2222

0 commit comments

Comments
 (0)