Received: from eggs.gnu.org ([2001:4830:134:3::10]:59449) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZIcwn-0002qf-Vu for qemu-devel@nongnu.org; Fri, 24 Jul 2015 09:23:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZIcwj-0007rP-1b for qemu-devel@nongnu.org; Fri, 24 Jul 2015 09:23:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47230) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZIcwi-0007qz-Sw for qemu-devel@nongnu.org; Fri, 24 Jul 2015 09:23:28 -0400 From: "Daniel P. Berrange" Date: Fri, 24 Jul 2015 13:23:54 +0100 Message-Id: <1437740634-6261-1-git-send-email-berrange@redhat.com> Subject: [Qemu-devel] [PATCH] crypto: fix built-in AES decrypt function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Peter Maydell 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 --- crypto/cipher-builtin.c | 8 ++++---- 1 file 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; -- 2.4.3