Skip to content

Commit b97cc3c

Browse files
authored
feat: Validate input key size in SEIPDv2 decryption (#236)
Adds a validation step to ensure the input key size matches the expected algorithm key size before proceeding to the HKDF step in SEIPDv2 decryption.
1 parent 20ab0e4 commit b97cc3c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

openpgp/packet/symmetrically_encrypted_aead.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package packet
77
import (
88
"crypto/cipher"
99
"crypto/sha256"
10+
"fmt"
1011
"io"
1112
"strconv"
1213

@@ -63,8 +64,11 @@ func (se *SymmetricallyEncrypted) associatedData() []byte {
6364
// decryptAead decrypts a V2 SEIPD packet (AEAD) as specified in
6465
// https://www.ietf.org/archive/id/draft-ietf-openpgp-crypto-refresh-07.html#section-5.13.2
6566
func (se *SymmetricallyEncrypted) decryptAead(inputKey []byte) (io.ReadCloser, error) {
66-
aead, nonce := getSymmetricallyEncryptedAeadInstance(se.Cipher, se.Mode, inputKey, se.Salt[:], se.associatedData())
67+
if se.Cipher.KeySize() != len(inputKey) {
68+
return nil, errors.StructuralError(fmt.Sprintf("invalid session key length for cipher: got %d bytes, but expected %d bytes", len(inputKey), se.Cipher.KeySize()))
69+
}
6770

71+
aead, nonce := getSymmetricallyEncryptedAeadInstance(se.Cipher, se.Mode, inputKey, se.Salt[:], se.associatedData())
6872
// Carry the first tagLen bytes
6973
tagLen := se.Mode.TagLength()
7074
peekedBytes := make([]byte, tagLen)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy