go.crypto/openpgp: Allow configuration of s2k hash during encryption.
This patch/CL allows the user to configure the hash function used in the s2k key-stretching transformation during encryption. It fixes the current limitation in which SHA1 is hard-coded for that task. With this change, packet.Config.DefaultHash is used by default for the mode 3 s2k key-stretching that is currently used for encryption, but the user may choose any other valid openpgp hash by passing a new (possibly nil) pointer argument to s2k.Serialize(). Note that this change introduces an API change to s2k.Serialize() in the form of an additional argument. However, the s2k package is a low-level facility that (as far as I could tell) is used directly by go.crypto/openpgp only. The CL comes with an modified test to check the use and decoding of all the valid hash functions with regard to s2k.Serialize(). This patch should be followed by one that allows the user to configure the iteration count in mode 3 s2k, and it is a prerequisite for that forthcoming change. R=golang-codereviews, agl CC=agl, golang-codereviews https://golang.org/cl/160110045
This commit is contained in:
committed by
Adam Langley
parent
3e2271302c
commit
c24604da51
@@ -6,11 +6,12 @@ package packet
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"code.google.com/p/go.crypto/openpgp/errors"
|
||||
"code.google.com/p/go.crypto/openpgp/s2k"
|
||||
"crypto/cipher"
|
||||
"io"
|
||||
"strconv"
|
||||
|
||||
"code.google.com/p/go.crypto/openpgp/errors"
|
||||
"code.google.com/p/go.crypto/openpgp/s2k"
|
||||
)
|
||||
|
||||
// This is the largest session key that we'll support. Since no 512-bit cipher
|
||||
@@ -119,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)
|
||||
err = s2k.Serialize(s2kBuf, keyEncryptingKey, config.Random(), passphrase, &s2k.Config{Hash: config.Hash()})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user