Skip to content

Commit

Permalink
switch minio/blake2b-simd to golang.org/x/crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
mroth authored and ribasushi committed Aug 31, 2024
1 parent a02b0e0 commit 6e7789e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
14 changes: 7 additions & 7 deletions address.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import (
"strings"

cbor "github.com/ipfs/go-ipld-cbor"
"github.com/minio/blake2b-simd"
"github.com/multiformats/go-varint"
"github.com/polydawn/refmt/obj/atlas"
"golang.org/x/xerrors"

cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/crypto/blake2b"
"golang.org/x/xerrors"
)

func init() {
Expand Down Expand Up @@ -211,7 +210,7 @@ func NewFromBytes(addr []byte) (Address, error) {

// Checksum returns the checksum of `ingest`.
func Checksum(ingest []byte) []byte {
return hash(ingest, checksumHashConfig)
return hash(ingest, ChecksumHashLength)
}

// ValidateChecksum returns true if the checksum of `ingest` is equal to `expected`>
Expand All @@ -221,7 +220,7 @@ func ValidateChecksum(ingest, expect []byte) bool {
}

func addressHash(ingest []byte) []byte {
return hash(ingest, payloadHashConfig)
return hash(ingest, PayloadHashLength)
}

// FIXME: This needs to be unified with the logic of `decode` (which would
Expand Down Expand Up @@ -444,8 +443,9 @@ func decode(a string) (Address, error) {
return newAddress(protocol, payload)
}

func hash(ingest []byte, cfg *blake2b.Config) []byte {
hasher, err := blake2b.New(cfg)
// hash returns the BLAKE2b checksum using a hasher of custom length size
func hash(ingest []byte, size int) []byte {
hasher, err := blake2b.New(size, nil)
if err != nil {
// If this happens sth is very wrong.
panic(fmt.Sprintf("invalid address hash configuration: %v", err)) // ok
Expand Down
5 changes: 0 additions & 5 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package address
import (
"encoding/base32"
"errors"

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

func init() {
Expand Down Expand Up @@ -69,9 +67,6 @@ const BlsPrivateKeyBytes = 32
// MaxSubaddressLen is the maximum length of a delegated address's sub-address.
const MaxSubaddressLen = 54

var payloadHashConfig = &blake2b.Config{Size: PayloadHashLength}
var checksumHashConfig = &blake2b.Config{Size: ChecksumHashLength}

const encodeStd = "abcdefghijklmnopqrstuvwxyz234567"

// AddressEncoding defines the base32 config used for address encoding and decoding.
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ go 1.22
require (
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03
github.com/ipfs/go-ipld-cbor v0.0.5
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1
github.com/multiformats/go-varint v0.0.6
github.com/polydawn/refmt v0.0.0-20190807091052-3d65705ee9f1
github.com/stretchr/testify v1.4.0
github.com/whyrusleeping/cbor-gen v0.0.0-20210303213153-67a261a1d291
golang.org/x/crypto v0.17.0
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
)

Expand All @@ -20,6 +20,7 @@ require (
github.com/ipfs/go-ipfs-util v0.0.1 // indirect
github.com/ipfs/go-ipld-format v0.0.1 // indirect
github.com/ipsn/go-secp256k1 v0.0.0-20180726113642-9d62b9f0bc52 // indirect
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect
github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771 // indirect
github.com/mr-tron/base58 v1.1.3 // indirect
github.com/multiformats/go-base32 v0.0.3 // indirect
Expand All @@ -28,7 +29,6 @@ require (
github.com/multiformats/go-multihash v0.0.13 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/sys v0.15.0 // indirect
gopkg.in/yaml.v2 v2.2.4 // indirect
)

0 comments on commit 6e7789e

Please sign in to comment.