]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/md5: uniform Write func
authorunknown <nonamezeil@gmail.com>
Wed, 4 Nov 2015 12:55:21 +0000 (15:55 +0300)
committerIan Lance Taylor <iant@golang.org>
Wed, 4 Nov 2015 15:41:25 +0000 (15:41 +0000)
Unification of implementation of existing md5.Write function
with other implementations (sha1, sha256, sha512).

Change-Id: I58ae02d165b17fc221953a5b4b986048b46c0508
Reviewed-on: https://go-review.googlesource.com/16621
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/crypto/md5/md5.go

index 8c50c6d0bfaa7db920a48988ae5af5ecff7dd411..a3550cb7dda2891e2ae6fa2f22d7e01c7c3726cd 100644 (file)
@@ -62,16 +62,10 @@ func (d *digest) Write(p []byte) (nn int, err error) {
        nn = len(p)
        d.len += uint64(nn)
        if d.nx > 0 {
-               n := len(p)
-               if n > chunk-d.nx {
-                       n = chunk - d.nx
-               }
-               for i := 0; i < n; i++ {
-                       d.x[d.nx+i] = p[i]
-               }
+               n := copy(d.x[d.nx:], p)
                d.nx += n
                if d.nx == chunk {
-                       block(d, d.x[0:chunk])
+                       block(d, d.x[:])
                        d.nx = 0
                }
                p = p[n:]