]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/crypto/sha256/sha256.go
[dev.boringcrypto] all: merge master (nearly Go 1.10 beta 1) into dev.boringcrypto
[gostls13.git] / src / crypto / sha256 / sha256.go
index f078cab3783bcc6fcf9c918c746a6f57b5a6c79f..a5bb144f0e2f7b4e9d87ed73131474fe92dd415f 100644 (file)
@@ -8,6 +8,7 @@ package sha256
 
 import (
        "crypto"
+       "crypto/internal/boring"
        "errors"
        "hash"
 )
@@ -169,6 +170,9 @@ func (d *digest) Reset() {
 // encoding.BinaryUnmarshaler to marshal and unmarshal the internal
 // state of the hash.
 func New() hash.Hash {
+       if boring.Enabled {
+               return boring.NewSHA256()
+       }
        d := new(digest)
        d.Reset()
        return d
@@ -176,6 +180,9 @@ func New() hash.Hash {
 
 // New224 returns a new hash.Hash computing the SHA224 checksum.
 func New224() hash.Hash {
+       if boring.Enabled {
+               return boring.NewSHA224()
+       }
        d := new(digest)
        d.is224 = true
        d.Reset()
@@ -192,6 +199,7 @@ func (d *digest) Size() int {
 func (d *digest) BlockSize() int { return BlockSize }
 
 func (d *digest) Write(p []byte) (nn int, err error) {
+       boring.Unreachable()
        nn = len(p)
        d.len += uint64(nn)
        if d.nx > 0 {
@@ -215,6 +223,7 @@ func (d *digest) Write(p []byte) (nn int, err error) {
 }
 
 func (d0 *digest) Sum(in []byte) []byte {
+       boring.Unreachable()
        // Make a copy of d0 so that caller can keep writing and summing.
        d := *d0
        hash := d.checkSum()
@@ -264,6 +273,13 @@ func (d *digest) checkSum() [Size]byte {
 
 // Sum256 returns the SHA256 checksum of the data.
 func Sum256(data []byte) [Size]byte {
+       if boring.Enabled {
+               h := New()
+               h.Write(data)
+               var ret [Size]byte
+               h.Sum(ret[:0])
+               return ret
+       }
        var d digest
        d.Reset()
        d.Write(data)
@@ -272,6 +288,13 @@ func Sum256(data []byte) [Size]byte {
 
 // Sum224 returns the SHA224 checksum of the data.
 func Sum224(data []byte) (sum224 [Size224]byte) {
+       if boring.Enabled {
+               h := New224()
+               h.Write(data)
+               var ret [Size224]byte
+               h.Sum(ret[:0])
+               return ret
+       }
        var d digest
        d.is224 = true
        d.Reset()