-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use standard library sha256 implementation for Go 1.21 (#2309)
See rational and benchmarks in multiformats/go-multihash#173. Fixes: #2308
- Loading branch information
Showing
8 changed files
with
53 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters