crypto: Fix buffer extension in Decrypt()

This commit is contained in:
Alexander Neumann committed 2015-05-05 00:12:05 +02:00
1 parent 589dbaaed2
commit 1f33e29ce2
2 files changed
+7 -7

No files matched your search

+5 -5
View File
@@ -276,11 +276,6 @@ func Decrypt(ks *Key, plaintext []byte, ciphertextWithMac []byte) ([]byte, error
panic("trying to decrypt invalid data: ciphertext too small")
}
if cap(plaintext) < len(ciphertextWithMac) {
// extend plaintext
plaintext = append(plaintext, make([]byte, len(ciphertextWithMac)-cap(plaintext))...)
}
// extract mac
l := len(ciphertextWithMac) - macSize
ciphertextWithIV, mac := ciphertextWithMac[:l], ciphertextWithMac[l:]
@@ -293,6 +288,11 @@ func Decrypt(ks *Key, plaintext []byte, ciphertextWithMac []byte) ([]byte, error
// extract iv
iv, ciphertext := ciphertextWithIV[:ivSize], ciphertextWithIV[ivSize:]
if cap(plaintext) < len(ciphertext) {
// extend plaintext
plaintext = append(plaintext, make([]byte, len(ciphertext)-cap(plaintext))...)
}
// decrypt data
c, err := aes.NewCipher(ks.Encrypt[:])
if err != nil {