go.crypto/openpgp: Allow config. of s2k count for symmetric encrypt.

This patch allows the user to choose the strength of the
passphrase mangling during the process in which the key is
produced from the passphrase. It only affects symmetric
encryption.

Unmodified code that calls openpgp.SymmetricallyEncrypt() will
continue to get the now-default count of 65536. Otherwise, a
count in the range [1024, 65011712] may be configured. Illegal
values in and outside this range will silently be rounded up
to legal values within the said range.

The test to s2k.Serialize() has been modified to test a
variety of non-default counts with all the valid hashes and
ensure that the decoding component of s2k can parse and
decrypt the result.

Additional testing has been done with GPG to ensure that the
latter can parse and decrypt files encrypted/encoded with
various counts.

LGTM=agl
R=golang-codereviews, agl
CC=golang-codereviews
https://golang.org/cl/176080043
This commit is contained in:
Brian Gitonga Marete
2014-11-21 14:04:52 -08:00
committed by Adam Langley
parent 5ff91abc76
commit ca455997ca
4 changed files with 74 additions and 5 deletions
+4 -1
View File
@@ -104,8 +104,11 @@ func TestParse(t *testing.T) {
func TestSerialize(t *testing.T) {
hashes := []crypto.Hash{crypto.MD5, crypto.SHA1, crypto.RIPEMD160,
crypto.SHA256, crypto.SHA384, crypto.SHA512, crypto.SHA224}
testCounts := []int{-1, 0, 1024, 65536, 4063232, 65011712}
for _, h := range hashes {
testSerializeConfig(t, &Config{Hash: h})
for _, c := range testCounts {
testSerializeConfig(t, &Config{Hash: h, S2KCount: c})
}
}
}