]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/openpgp/packet: fix private key checksum
authorAdam Langley <agl@golang.org>
Wed, 23 Nov 2011 14:44:29 +0000 (09:44 -0500)
committerAdam Langley <agl@golang.org>
Wed, 23 Nov 2011 14:44:29 +0000 (09:44 -0500)
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

src/pkg/crypto/openpgp/packet/private_key.go

index c0ff82b4135fcd107d0cfa78745a6fe4f954302c..5ef3db2a7469bfd87eaab8b3bd6052e2a2a15bd1 100644 (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
 }