1
0
mirror of https://github.com/golang/go synced 2024-11-20 06:44:40 -07:00

crypto/openpgp/packet: fix private key checksum

I misinterpreted http://tools.ietf.org/html/rfc4880#section-5.5.3
and implemented the sum of 16-bit values, rather than the 16-bit sum
of 8-bit values.

Thanks to Szabolcs Nagy for pointing it out.

R=bradfitz, r, rsc
CC=golang-dev
https://golang.org/cl/5372091
This commit is contained in:
Adam Langley 2011-11-23 09:44:29 -05:00
parent f2c858749a
commit 8281f6bd1b

View File

@ -99,13 +99,9 @@ func (pk *PrivateKey) parse(r io.Reader) (err error) {
}
func mod64kHash(d []byte) uint16 {
h := uint16(0)
for i := 0; i < len(d); i += 2 {
v := uint16(d[i]) << 8
if i+1 < len(d) {
v += uint16(d[i+1])
}
h += v
var h uint16
for _, b := range d {
h += uint16(b)
}
return h
}