diff --git a/openpgp/v2/write.go b/openpgp/v2/write.go index 4c02e04a..7ecec8eb 100644 --- a/openpgp/v2/write.go +++ b/openpgp/v2/write.go @@ -664,7 +664,12 @@ func encrypt( } if params.SessionKey == nil { - params.SessionKey = make([]byte, cipher.KeySize()) + if aeadSupported { + params.SessionKey = make([]byte, aeadCipherSuite.Cipher.KeySize()) + } else { + params.SessionKey = make([]byte, cipher.KeySize()) + } + if _, err := io.ReadFull(config.Random(), params.SessionKey); err != nil { return nil, err } diff --git a/openpgp/write.go b/openpgp/write.go index 0db5526c..b0f6ef7b 100644 --- a/openpgp/write.go +++ b/openpgp/write.go @@ -444,7 +444,13 @@ func encrypt(keyWriter io.Writer, dataWriter io.Writer, to []*Entity, signed *En } } - symKey := make([]byte, cipher.KeySize()) + var symKey []byte + if aeadSupported { + symKey = make([]byte, aeadCipherSuite.Cipher.KeySize()) + } else { + symKey = make([]byte, cipher.KeySize()) + } + if _, err := io.ReadFull(config.Random(), symKey); err != nil { return nil, err }