]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/crypto/sha1/sha1.go
[dev.boringcrypto] all: merge master into dev.boringcrypto
[gostls13.git] / src / crypto / sha1 / sha1.go
index db70b7d09aa8c52c9b629f7e9e085eb53c763ffd..a9546bb0a50e53402f277e30ff27c9310be30ae1 100644 (file)
@@ -118,6 +118,9 @@ func (d *digest) Reset() {
 // implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler to
 // marshal and unmarshal the internal state of the hash.
 func New() hash.Hash {
+       if boringEnabled {
+               return boringNewSHA1()
+       }
        d := new(digest)
        d.Reset()
        return d
@@ -128,6 +131,7 @@ func (d *digest) Size() int { return Size }
 func (d *digest) BlockSize() int { return BlockSize }
 
 func (d *digest) Write(p []byte) (nn int, err error) {
+       boringUnreachable()
        nn = len(p)
        d.len += uint64(nn)
        if d.nx > 0 {
@@ -151,6 +155,7 @@ func (d *digest) Write(p []byte) (nn int, err error) {
 }
 
 func (d *digest) Sum(in []byte) []byte {
+       boringUnreachable()
        // Make a copy of d so that caller can keep writing and summing.
        d0 := *d
        hash := d0.checkSum()
@@ -258,6 +263,13 @@ func (d *digest) constSum() [Size]byte {
 
 // Sum returns the SHA-1 checksum of the data.
 func Sum(data []byte) [Size]byte {
+       if boringEnabled {
+               h := New()
+               h.Write(data)
+               var ret [Size]byte
+               h.Sum(ret[:0])
+               return ret
+       }
        var d digest
        d.Reset()
        d.Write(data)