aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/sha512/sha512.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto/sha512/sha512.go')
-rw-r--r--src/crypto/sha512/sha512.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/crypto/sha512/sha512.go b/src/crypto/sha512/sha512.go
index c685319480..394e001eee 100644
--- a/src/crypto/sha512/sha512.go
+++ b/src/crypto/sha512/sha512.go
@@ -12,6 +12,7 @@ package sha512
import (
"crypto"
+ "crypto/internal/boring"
"errors"
"hash"
)
@@ -222,6 +223,9 @@ func consumeUint64(b []byte) ([]byte, uint64) {
// New returns a new hash.Hash computing the SHA-512 checksum.
func New() hash.Hash {
+ if boring.Enabled {
+ return boring.NewSHA512()
+ }
d := &digest{function: crypto.SHA512}
d.Reset()
return d
@@ -243,6 +247,9 @@ func New512_256() hash.Hash {
// New384 returns a new hash.Hash computing the SHA-384 checksum.
func New384() hash.Hash {
+ if boring.Enabled {
+ return boring.NewSHA384()
+ }
d := &digest{function: crypto.SHA384}
d.Reset()
return d
@@ -264,6 +271,9 @@ func (d *digest) Size() int {
func (d *digest) BlockSize() int { return BlockSize }
func (d *digest) Write(p []byte) (nn int, err error) {
+ if d.function != crypto.SHA512_224 && d.function != crypto.SHA512_256 {
+ boring.Unreachable()
+ }
nn = len(p)
d.len += uint64(nn)
if d.nx > 0 {
@@ -287,6 +297,9 @@ func (d *digest) Write(p []byte) (nn int, err error) {
}
func (d *digest) Sum(in []byte) []byte {
+ if d.function != crypto.SHA512_224 && d.function != crypto.SHA512_256 {
+ boring.Unreachable()
+ }
// Make a copy of d so that caller can keep writing and summing.
d0 := new(digest)
*d0 = *d
@@ -341,6 +354,13 @@ 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
+ }
d := digest{function: crypto.SHA512}
d.Reset()
d.Write(data)
@@ -349,6 +369,13 @@ func Sum512(data []byte) [Size]byte {
// Sum384 returns the SHA384 checksum of the data.
func Sum384(data []byte) (sum384 [Size384]byte) {
+ if boring.Enabled {
+ h := New384()
+ h.Write(data)
+ var ret [Size384]byte
+ h.Sum(ret[:0])
+ return ret
+ }
d := digest{function: crypto.SHA384}
d.Reset()
d.Write(data)