Skip to content

Commit

Permalink
Add SerializeSymmetricKeyEncryptedAEADReuseKey
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
twiss committed Nov 11, 2024
1 parent 63e3da1 commit ee67844
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion openpgp/packet/symmetric_key_encrypted.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,17 @@ func SerializeSymmetricKeyEncrypted(w io.Writer, passphrase []byte, config *Conf
// SerializeSymmetricallyEncrypted.
// If config is nil, sensible defaults will be used.
func SerializeSymmetricKeyEncryptedReuseKey(w io.Writer, sessionKey []byte, passphrase []byte, config *Config) (err error) {
return SerializeSymmetricKeyEncryptedAEADReuseKey(w, sessionKey, passphrase, config.AEAD() != nil, config)
}

// SerializeSymmetricKeyEncryptedAEADReuseKey serializes a symmetric key packet to w.
// The packet contains the given session key, encrypted by a key derived from
// the given passphrase. The returned session key must be passed to
// SerializeSymmetricallyEncrypted.
// If config is nil, sensible defaults will be used.
func SerializeSymmetricKeyEncryptedAEADReuseKey(w io.Writer, sessionKey []byte, passphrase []byte, aeadSupported bool, config *Config) (err error) {
var version int
if config.AEAD() != nil {
if aeadSupported {
version = 6
} else {
version = 4
Expand Down
2 changes: 1 addition & 1 deletion openpgp/v2/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ func encrypt(
}

for _, password := range params.Passwords {
if err = packet.SerializeSymmetricKeyEncryptedReuseKey(params.KeyWriter, params.SessionKey, password, params.Config); err != nil {
if err = packet.SerializeSymmetricKeyEncryptedAEADReuseKey(params.KeyWriter, params.SessionKey, password, aeadSupported, params.Config); err != nil {
return nil, err
}
}
Expand Down

0 comments on commit ee67844

Please sign in to comment.