aboutsummaryrefslogtreecommitdiff
path: root/crypto
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2015-07-24 13:23:54 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2015-07-27 12:22:01 +0200
commit6775e2c4298618828de9bb3c5584d4de20120e46 (patch)
tree5d0e2e223dc4ed301f3245b8a8a7295ac345269e /crypto
parentf793d97e454a56d17e404004867985622ca1a63b (diff)
downloadqemu-6775e2c4298618828de9bb3c5584d4de20120e46.zip
qemu-6775e2c4298618828de9bb3c5584d4de20120e46.tar.gz
qemu-6775e2c4298618828de9bb3c5584d4de20120e46.tar.bz2
crypto: fix built-in AES decrypt function
The qcrypto_cipher_decrypt_aes method was using the wrong key material, and passing the wrong mode. This caused it to incorrectly decrypt ciphertext. Signed-off-by: Daniel P. Berrange <berrange@redhat.com> Message-Id: <1437740634-6261-1-git-send-email-berrange@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/cipher-builtin.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/crypto/cipher-builtin.c b/crypto/cipher-builtin.c
index 912c1b9..30f4853 100644
--- a/crypto/cipher-builtin.c
+++ b/crypto/cipher-builtin.c
@@ -117,7 +117,7 @@ static int qcrypto_cipher_decrypt_aes(QCryptoCipher *cipher,
uint8_t *outptr = out;
while (len) {
if (len > AES_BLOCK_SIZE) {
- AES_decrypt(inptr, outptr, &ctxt->state.aes.encrypt_key);
+ AES_decrypt(inptr, outptr, &ctxt->state.aes.decrypt_key);
inptr += AES_BLOCK_SIZE;
outptr += AES_BLOCK_SIZE;
len -= AES_BLOCK_SIZE;
@@ -126,15 +126,15 @@ static int qcrypto_cipher_decrypt_aes(QCryptoCipher *cipher,
memcpy(tmp1, inptr, len);
/* Fill with 0 to avoid valgrind uninitialized reads */
memset(tmp1 + len, 0, sizeof(tmp1) - len);
- AES_decrypt(tmp1, tmp2, &ctxt->state.aes.encrypt_key);
+ AES_decrypt(tmp1, tmp2, &ctxt->state.aes.decrypt_key);
memcpy(outptr, tmp2, len);
len = 0;
}
}
} else {
AES_cbc_encrypt(in, out, len,
- &ctxt->state.aes.encrypt_key,
- ctxt->state.aes.iv, 1);
+ &ctxt->state.aes.decrypt_key,
+ ctxt->state.aes.iv, 0);
}
return 0;