1
0
mirror of https://github.com/golang/go synced 2024-11-25 23:48:01 -07:00

Apply symmetric changes to sha1 and sha256 as to md4 and md5.

R=agl, agl1
CC=golang-dev
https://golang.org/cl/183083
This commit is contained in:
Robert Griesemer 2009-12-29 11:41:44 -08:00
parent 5042a4e9f9
commit e01459f567
2 changed files with 16 additions and 24 deletions

View File

@ -70,8 +70,8 @@ func (d *digest) Write(p []byte) (nn int, err os.Error) {
n := _Block(d, p) n := _Block(d, p)
p = p[n:] p = p[n:]
if len(p) > 0 { if len(p) > 0 {
for i := 0; i < len(p); i++ { for i, x := range p {
d.x[i] = p[i] d.x[i] = x
} }
d.nx = len(p) d.nx = len(p)
} }
@ -102,16 +102,12 @@ func (d *digest) Sum() []byte {
p := make([]byte, 20) p := make([]byte, 20)
j := 0 j := 0
for i := 0; i < 5; i++ { for _, s := range d.h {
s := d.h[i] p[j+0] = byte(s >> 24)
p[j] = byte(s >> 24) p[j+1] = byte(s >> 16)
j++ p[j+2] = byte(s >> 8)
p[j] = byte(s >> 16) p[j+3] = byte(s >> 0)
j++ j += 4
p[j] = byte(s >> 8)
j++
p[j] = byte(s)
j++
} }
return p return p
} }

View File

@ -76,8 +76,8 @@ func (d *digest) Write(p []byte) (nn int, err os.Error) {
n := _Block(d, p) n := _Block(d, p)
p = p[n:] p = p[n:]
if len(p) > 0 { if len(p) > 0 {
for i := 0; i < len(p); i++ { for i, x := range p {
d.x[i] = p[i] d.x[i] = x
} }
d.nx = len(p) d.nx = len(p)
} }
@ -108,16 +108,12 @@ func (d *digest) Sum() []byte {
p := make([]byte, 32) p := make([]byte, 32)
j := 0 j := 0
for i := 0; i < 8; i++ { for _, s := range d.h {
s := d.h[i] p[j+0] = byte(s >> 24)
p[j] = byte(s >> 24) p[j+1] = byte(s >> 16)
j++ p[j+2] = byte(s >> 8)
p[j] = byte(s >> 16) p[j+3] = byte(s >> 0)
j++ j += 4
p[j] = byte(s >> 8)
j++
p[j] = byte(s)
j++
} }
return p return p
} }