Closed suizman closed 5 years ago
I reckon that this is all we need to test it:
diff --git a/hashing/hash.go b/hashing/hash.go
index 1871e20..3a819ea 100644
--- a/hashing/hash.go
+++ b/hashing/hash.go
@@ -17,8 +17,9 @@
package hashing
import (
- "crypto/sha256"
"hash"
+
+ "golang.org/x/crypto/blake2b"
)
type Digest []byte
@@ -58,7 +59,7 @@ type Sha256Hasher struct {
}
func NewSha256Hasher() Hasher {
- return &Sha256Hasher{underlying: sha256.New()}
+ return &Sha256Hasher{underlying: blake2b.New256(nil)}
}
func (s *Sha256Hasher) Salted(salt []byte, data ...[]byte) Digest {
Sure! Check-out the current state at this branch. I've also done some benchmarking with this results on my machine:
~/g/s/g/b/qed ⎇ blake2b ?
❯ go test -benchmem -short -run=\^\$ github.com/bbva/qed/hashing -bench \^\(Benchmark\)
goos: linux
goarch: amd64
pkg: github.com/bbva/qed/hashing
BenchmarkSha256HasherRandomBytes-6 1000000 2712 ns/op 192 B/op 3 allocs/op
BenchmarkBlake2bHasherRandomBytes-6 1000000 1864 ns/op 192 B/op 3 allocs/op
BenchmarkSha256HasherFixedBytes-6 100000000 541 ns/op 64 B/op 2 allocs/op
BenchmarkBlake2bHasherFixedBytes-6 100000000 385 ns/op 64 B/op 2 allocs/op
BenchmarkBlake2bFixedBytesNoWrite-6 100000000 203 ns/op 0 B/op 0 allocs/op
BenchmarkSha256FixedBytesNoWrite-6 100000000 364 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/bbva/qed/hashing 154.161s
Just need to finish some tests before doing the PR
As @panchoh suggested it's worth trying BLAKE2b hashing algorithm. It suppose to be x2 faster than SHA256. We've find a Go implementation in BLAKE2b.
Adding support in QED of this algorithm should't be a difficult task. And performing some benchmark to compare between the SHA256 performance.