summaryrefslogtreecommitdiffstats
path: root/libgo/go/crypto/openpgp/s2k/s2k.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/crypto/openpgp/s2k/s2k.go')
-rw-r--r--libgo/go/crypto/openpgp/s2k/s2k.go8
1 files changed, 6 insertions, 2 deletions
diff --git a/libgo/go/crypto/openpgp/s2k/s2k.go b/libgo/go/crypto/openpgp/s2k/s2k.go
index 83673e17335..8bc0bb320bb 100644
--- a/libgo/go/crypto/openpgp/s2k/s2k.go
+++ b/libgo/go/crypto/openpgp/s2k/s2k.go
@@ -26,6 +26,7 @@ var zero [1]byte
// 4880, section 3.7.1.2) using the given hash, input passphrase and salt.
func Salted(out []byte, h hash.Hash, in []byte, salt []byte) {
done := 0
+ var digest []byte
for i := 0; done < len(out); i++ {
h.Reset()
@@ -34,7 +35,8 @@ func Salted(out []byte, h hash.Hash, in []byte, salt []byte) {
}
h.Write(salt)
h.Write(in)
- n := copy(out[done:], h.Sum(nil))
+ digest = h.Sum(digest[:0])
+ n := copy(out[done:], digest)
done += n
}
}
@@ -52,6 +54,7 @@ func Iterated(out []byte, h hash.Hash, in []byte, salt []byte, count int) {
}
done := 0
+ var digest []byte
for i := 0; done < len(out); i++ {
h.Reset()
for j := 0; j < i; j++ {
@@ -68,7 +71,8 @@ func Iterated(out []byte, h hash.Hash, in []byte, salt []byte, count int) {
written += len(combined)
}
}
- n := copy(out[done:], h.Sum(nil))
+ digest = h.Sum(digest[:0])
+ n := copy(out[done:], digest)
done += n
}
}
OpenPOWER on IntegriCloud