summaryrefslogtreecommitdiff
path: root/libgo/go/crypto/sha256/sha256.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/crypto/sha256/sha256.go')
-rw-r--r--libgo/go/crypto/sha256/sha256.go22
1 files changed, 10 insertions, 12 deletions
diff --git a/libgo/go/crypto/sha256/sha256.go b/libgo/go/crypto/sha256/sha256.go
index 14b8cfc7eca..34861f6cf49 100644
--- a/libgo/go/crypto/sha256/sha256.go
+++ b/libgo/go/crypto/sha256/sha256.go
@@ -123,7 +123,7 @@ func (d *digest) Write(p []byte) (nn int, err error) {
return
}
-func (d0 *digest) Sum() []byte {
+func (d0 *digest) Sum(in []byte) []byte {
// Make a copy of d0 so that caller can keep writing and summing.
d := new(digest)
*d = *d0
@@ -149,17 +149,15 @@ func (d0 *digest) Sum() []byte {
panic("d.nx != 0")
}
- p := make([]byte, 32)
- j := 0
- 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
- }
+ h := d.h[:]
if d.is224 {
- return p[0:28]
+ h = d.h[:7]
+ }
+ for _, s := range h {
+ in = append(in, byte(s>>24))
+ in = append(in, byte(s>>16))
+ in = append(in, byte(s>>8))
+ in = append(in, byte(s))
}
- return p
+ return in
}