diff options
Diffstat (limited to 'src/crypto/sha512')
-rw-r--r-- | src/crypto/sha512/sha512.go | 15 | ||||
-rw-r--r-- | src/crypto/sha512/sha512_test.go | 32 |
2 files changed, 27 insertions, 20 deletions
diff --git a/src/crypto/sha512/sha512.go b/src/crypto/sha512/sha512.go index 1285cca7ee6..c800a294a27 100644 --- a/src/crypto/sha512/sha512.go +++ b/src/crypto/sha512/sha512.go @@ -12,13 +12,12 @@ package sha512 import ( "crypto" + "crypto/internal/boring" "encoding/binary" "errors" "hash" ) -import "crypto/internal/boring" - func init() { crypto.RegisterHash(crypto.SHA384, New384) crypto.RegisterHash(crypto.SHA512, New) @@ -345,11 +344,7 @@ func (d *digest) checkSum() [Size]byte { // Sum512 returns the SHA512 checksum of the data. func Sum512(data []byte) [Size]byte { if boring.Enabled { - h := New() - h.Write(data) - var ret [Size]byte - h.Sum(ret[:0]) - return ret + return boring.SHA512(data) } d := digest{function: crypto.SHA512} d.Reset() @@ -360,11 +355,7 @@ func Sum512(data []byte) [Size]byte { // Sum384 returns the SHA384 checksum of the data. func Sum384(data []byte) [Size384]byte { if boring.Enabled { - h := New384() - h.Write(data) - var ret [Size384]byte - h.Sum(ret[:0]) - return ret + return boring.SHA384(data) } d := digest{function: crypto.SHA384} d.Reset() diff --git a/src/crypto/sha512/sha512_test.go b/src/crypto/sha512/sha512_test.go index 99d1423527b..921cdbb7bbd 100644 --- a/src/crypto/sha512/sha512_test.go +++ b/src/crypto/sha512/sha512_test.go @@ -8,6 +8,7 @@ package sha512 import ( "bytes" + "crypto/internal/boring" "crypto/rand" "encoding" "encoding/hex" @@ -17,8 +18,6 @@ import ( "testing" ) -import "crypto/internal/boring" - type sha512Test struct { out string in string @@ -914,13 +913,30 @@ var bench = New() var buf = make([]byte, 8192) func benchmarkSize(b *testing.B, size int) { - b.SetBytes(int64(size)) sum := make([]byte, bench.Size()) - for i := 0; i < b.N; i++ { - bench.Reset() - bench.Write(buf[:size]) - bench.Sum(sum[:0]) - } + b.Run("New", func(b *testing.B) { + b.ReportAllocs() + b.SetBytes(int64(size)) + for i := 0; i < b.N; i++ { + bench.Reset() + bench.Write(buf[:size]) + bench.Sum(sum[:0]) + } + }) + b.Run("Sum384", func(b *testing.B) { + b.ReportAllocs() + b.SetBytes(int64(size)) + for i := 0; i < b.N; i++ { + Sum384(buf[:size]) + } + }) + b.Run("Sum512", func(b *testing.B) { + b.ReportAllocs() + b.SetBytes(int64(size)) + for i := 0; i < b.N; i++ { + Sum512(buf[:size]) + } + }) } func BenchmarkHash8Bytes(b *testing.B) { |