aboutsummaryrefslogtreecommitdiff
path: root/openpgp/packet
diff options
context:
space:
mode:
authorBrian Gitonga Marete <marete@toshnix.com>2014-11-21 14:04:52 -0800
committerAdam Langley <agl@golang.org>2014-11-21 14:04:52 -0800
commitca455997ca6d2a6417e954eace2fa47de4c7e932 (patch)
treee7599d81c5440e69ddb96bdd44808422e5bce2ae /openpgp/packet
parent5ff91abc762244e802d98aa34c6c0d78f70791f3 (diff)
downloadgo-x-crypto-ca455997ca6d2a6417e954eace2fa47de4c7e932.tar.xz
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
Diffstat (limited to 'openpgp/packet')
-rw-r--r--openpgp/packet/config.go11
-rw-r--r--openpgp/packet/symmetric_key_encrypted.go2
2 files changed, 12 insertions, 1 deletions
diff --git a/openpgp/packet/config.go b/openpgp/packet/config.go
index 8c4f213..3f17096 100644
--- a/openpgp/packet/config.go
+++ b/openpgp/packet/config.go
@@ -32,6 +32,17 @@ type Config struct {
DefaultCompressionAlgo CompressionAlgo
// CompressionConfig configures the compression settings.
CompressionConfig *CompressionConfig
+ // S2KCount is only used for symmetric encryption. It
+ // determines the strength of the passphrase stretching when
+ // the said passphrase is hashed to produce a key. S2KCount
+ // should be between 1024 and 65011712, inclusive. If Config
+ // is nil or S2KCount is 0, the value 65536 used. Not all
+ // values in the above range can be represented. S2KCount will
+ // be rounded up to the next representable value if it cannot
+ // be encoded exactly. When set, it is strongly encrouraged to
+ // use a value that is at least 65536. See RFC 4880 Section
+ // 3.7.1.3.
+ S2KCount int
}
func (c *Config) Random() io.Reader {
diff --git a/openpgp/packet/symmetric_key_encrypted.go b/openpgp/packet/symmetric_key_encrypted.go
index 23721bc..21739a1 100644
--- a/openpgp/packet/symmetric_key_encrypted.go
+++ b/openpgp/packet/symmetric_key_encrypted.go
@@ -120,7 +120,7 @@ func SerializeSymmetricKeyEncrypted(w io.Writer, passphrase []byte, config *Conf
keyEncryptingKey := make([]byte, keySize)
// s2k.Serialize salts and stretches the passphrase, and writes the
// resulting key to keyEncryptingKey and the s2k descriptor to s2kBuf.
- err = s2k.Serialize(s2kBuf, keyEncryptingKey, config.Random(), passphrase, &s2k.Config{Hash: config.Hash()})
+ err = s2k.Serialize(s2kBuf, keyEncryptingKey, config.Random(), passphrase, &s2k.Config{Hash: config.Hash(), S2KCount: config.S2KCount})
if err != nil {
return
}