Skip to content

Commit

Permalink
chore: drop minio sha256 for go1.21
Browse files Browse the repository at this point in the history
See rational and benchmarks in multiformats/go-multihash#173.

Fixes: #2308
  • Loading branch information
Jorropo committed Aug 16, 2023
1 parent 4090dcc commit 6e6da49
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 8 deletions.
3 changes: 1 addition & 2 deletions core/crypto/ecdsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import (

pb "github.com/libp2p/go-libp2p/core/crypto/pb"
"github.com/libp2p/go-libp2p/core/internal/catch"

"github.com/minio/sha256-simd"
"github.com/libp2p/go-libp2p/internal/sha256"
)

// ECDSAPrivateKey is an implementation of an ECDSA private key
Expand Down
2 changes: 1 addition & 1 deletion core/crypto/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
. "github.com/libp2p/go-libp2p/core/crypto"
pb "github.com/libp2p/go-libp2p/core/crypto/pb"
"github.com/libp2p/go-libp2p/core/test"
"github.com/libp2p/go-libp2p/internal/sha256"

"github.com/decred/dcrd/dcrec/secp256k1/v4"
secp256k1ecdsa "github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa"
"github.com/minio/sha256-simd"
)

func TestKeys(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions core/crypto/rsa_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (

pb "github.com/libp2p/go-libp2p/core/crypto/pb"
"github.com/libp2p/go-libp2p/core/internal/catch"

"github.com/minio/sha256-simd"
"github.com/libp2p/go-libp2p/internal/sha256"
)

// RsaPrivateKey is a rsa private key
Expand Down
2 changes: 1 addition & 1 deletion core/crypto/secp256k1.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/decred/dcrd/dcrec/secp256k1/v4"
"github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa"
"github.com/minio/sha256-simd"
"github.com/libp2p/go-libp2p/internal/sha256"
)

// Secp256k1PrivateKey is a Secp256k1 private key
Expand Down
23 changes: 23 additions & 0 deletions internal/sha256/post_go1_21.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//go:build go1.21

// This package use build tags to select between github.com/minio/sha256-simd
// for go1.20 and bellow and crypto/sha256 for go1.21 and above.
// This is used because a fast SHANI implementation of sha256 is only avaiable
// in the std for go1.21 and above. See https://go.dev/issue/50543.
// TODO: Once go1.22 releases remove this package and replace all uses
// with crypto/sha256 because the two supported version of go will have the fast
// implementation.
package sha256

import (
"crypto/sha256"
"hash"
)

func Sum256(b []byte) [sha256.Size]byte {
return sha256.Sum256(b)
}

func New() hash.Hash {
return sha256.New()
}
24 changes: 24 additions & 0 deletions internal/sha256/pre_go1_21.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build !go1.21

// This package use build tags to select between github.com/minio/sha256-simd
// for go1.20 and bellow and crypto/sha256 for go1.21 and above.
// This is used because a fast SHANI implementation of sha256 is only avaiable
// in the std for go1.21 and above. See https://go.dev/issue/50543.
// TODO: Once go1.22 releases remove this package and replace all uses
// with crypto/sha256 because the two supported version of go will have the fast
// implementation.
package sha256

import (
"hash"

"github.com/minio/sha256-simd"
)

func Sum256(b []byte) [sha256.Size]byte {
return sha256.Sum256(b)
}

func New() hash.Hash {
return sha256.New()
}
2 changes: 1 addition & 1 deletion p2p/net/swarm/swarm_addr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/peerstore"
"github.com/libp2p/go-libp2p/core/test"
"github.com/libp2p/go-libp2p/internal/sha256"
"github.com/libp2p/go-libp2p/p2p/host/eventbus"
"github.com/libp2p/go-libp2p/p2p/net/swarm"
swarmt "github.com/libp2p/go-libp2p/p2p/net/swarm/testing"
Expand All @@ -18,7 +19,6 @@ import (
"github.com/libp2p/go-libp2p/p2p/transport/tcp"
webtransport "github.com/libp2p/go-libp2p/p2p/transport/webtransport"

"github.com/minio/sha256-simd"
ma "github.com/multiformats/go-multiaddr"
"github.com/multiformats/go-multibase"
"github.com/multiformats/go-multihash"
Expand Down
2 changes: 1 addition & 1 deletion p2p/security/noise/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (

"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/internal/sha256"
"github.com/libp2p/go-libp2p/p2p/security/noise/pb"

"github.com/flynn/noise"
pool "github.com/libp2p/go-buffer-pool"
"github.com/minio/sha256-simd"
"google.golang.org/protobuf/proto"
)

Expand Down

0 comments on commit 6e6da49

Please sign in to comment.