Skip to content

Commit ee67844

Browse files
committed
Add SerializeSymmetricKeyEncryptedAEADReuseKey
Allow explicitly indicating whether AEAD is supported when creating an SKESK packet, instead of looking at config.AEAD(). The config is no longer reliable, and we shouldn't mix SKESKv3 and SEIPDv2, for example.
1 parent 63e3da1 commit ee67844

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Diff for: openpgp/packet/symmetric_key_encrypted.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,17 @@ func SerializeSymmetricKeyEncrypted(w io.Writer, passphrase []byte, config *Conf
196196
// SerializeSymmetricallyEncrypted.
197197
// If config is nil, sensible defaults will be used.
198198
func SerializeSymmetricKeyEncryptedReuseKey(w io.Writer, sessionKey []byte, passphrase []byte, config *Config) (err error) {
199+
return SerializeSymmetricKeyEncryptedAEADReuseKey(w, sessionKey, passphrase, config.AEAD() != nil, config)
200+
}
201+
202+
// SerializeSymmetricKeyEncryptedAEADReuseKey serializes a symmetric key packet to w.
203+
// The packet contains the given session key, encrypted by a key derived from
204+
// the given passphrase. The returned session key must be passed to
205+
// SerializeSymmetricallyEncrypted.
206+
// If config is nil, sensible defaults will be used.
207+
func SerializeSymmetricKeyEncryptedAEADReuseKey(w io.Writer, sessionKey []byte, passphrase []byte, aeadSupported bool, config *Config) (err error) {
199208
var version int
200-
if config.AEAD() != nil {
209+
if aeadSupported {
201210
version = 6
202211
} else {
203212
version = 4

Diff for: openpgp/v2/write.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ func encrypt(
691691
}
692692

693693
for _, password := range params.Passwords {
694-
if err = packet.SerializeSymmetricKeyEncryptedReuseKey(params.KeyWriter, params.SessionKey, password, params.Config); err != nil {
694+
if err = packet.SerializeSymmetricKeyEncryptedAEADReuseKey(params.KeyWriter, params.SessionKey, password, aeadSupported, params.Config); err != nil {
695695
return nil, err
696696
}
697697
}

0 commit comments

Comments
 (0)