From e01459f567dcc86818e90c1b378f6499f0a4300f Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 29 Dec 2009 11:41:44 -0800 Subject: [PATCH] Apply symmetric changes to sha1 and sha256 as to md4 and md5. R=agl, agl1 CC=golang-dev https://golang.org/cl/183083 --- src/pkg/crypto/sha1/sha1.go | 20 ++++++++------------ src/pkg/crypto/sha256/sha256.go | 20 ++++++++------------ 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/pkg/crypto/sha1/sha1.go b/src/pkg/crypto/sha1/sha1.go index da70b7314a..7209041ee1 100644 --- a/src/pkg/crypto/sha1/sha1.go +++ b/src/pkg/crypto/sha1/sha1.go @@ -70,8 +70,8 @@ func (d *digest) Write(p []byte) (nn int, err os.Error) { n := _Block(d, p) p = p[n:] if len(p) > 0 { - for i := 0; i < len(p); i++ { - d.x[i] = p[i] + for i, x := range p { + d.x[i] = x } d.nx = len(p) } @@ -102,16 +102,12 @@ func (d *digest) Sum() []byte { p := make([]byte, 20) j := 0 - for i := 0; i < 5; i++ { - s := d.h[i] - p[j] = byte(s >> 24) - j++ - p[j] = byte(s >> 16) - j++ - p[j] = byte(s >> 8) - j++ - p[j] = byte(s) - j++ + for _, s := range d.h { + p[j+0] = byte(s >> 24) + p[j+1] = byte(s >> 16) + p[j+2] = byte(s >> 8) + p[j+3] = byte(s >> 0) + j += 4 } return p } diff --git a/src/pkg/crypto/sha256/sha256.go b/src/pkg/crypto/sha256/sha256.go index 050dd22118..bacefc5637 100644 --- a/src/pkg/crypto/sha256/sha256.go +++ b/src/pkg/crypto/sha256/sha256.go @@ -76,8 +76,8 @@ func (d *digest) Write(p []byte) (nn int, err os.Error) { n := _Block(d, p) p = p[n:] if len(p) > 0 { - for i := 0; i < len(p); i++ { - d.x[i] = p[i] + for i, x := range p { + d.x[i] = x } d.nx = len(p) } @@ -108,16 +108,12 @@ func (d *digest) Sum() []byte { p := make([]byte, 32) j := 0 - for i := 0; i < 8; i++ { - s := d.h[i] - p[j] = byte(s >> 24) - j++ - p[j] = byte(s >> 16) - j++ - p[j] = byte(s >> 8) - j++ - p[j] = byte(s) - j++ + for _, s := range d.h { + p[j+0] = byte(s >> 24) + p[j+1] = byte(s >> 16) + p[j+2] = byte(s >> 8) + p[j+3] = byte(s >> 0) + j += 4 } return p } -- 2.50.0