Skip to content

Commit 140b3d6

Browse files
authored
Fix session key length generation (#198)
If AEAD is in use, we should generate a session key of the length of the cipher suite. This triggers when a key has a different AEAD preference than the cipher.
1 parent 3a86725 commit 140b3d6

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

openpgp/v2/write.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,12 @@ func encrypt(
664664
}
665665

666666
if params.SessionKey == nil {
667-
params.SessionKey = make([]byte, cipher.KeySize())
667+
if aeadSupported {
668+
params.SessionKey = make([]byte, aeadCipherSuite.Cipher.KeySize())
669+
} else {
670+
params.SessionKey = make([]byte, cipher.KeySize())
671+
}
672+
668673
if _, err := io.ReadFull(config.Random(), params.SessionKey); err != nil {
669674
return nil, err
670675
}

openpgp/write.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,13 @@ func encrypt(keyWriter io.Writer, dataWriter io.Writer, to []*Entity, signed *En
444444
}
445445
}
446446

447-
symKey := make([]byte, cipher.KeySize())
447+
var symKey []byte
448+
if aeadSupported {
449+
symKey = make([]byte, aeadCipherSuite.Cipher.KeySize())
450+
} else {
451+
symKey = make([]byte, cipher.KeySize())
452+
}
453+
448454
if _, err := io.ReadFull(config.Random(), symKey); err != nil {
449455
return nil, err
450456
}

0 commit comments

Comments
 (0)