Received: from eggs.gnu.org ([2001:4830:134:3::10]:60653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJzsp-0000Za-TR for qemu-devel@nongnu.org; Tue, 28 Jul 2015 04:05:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZJzsh-0008G0-Ih for qemu-devel@nongnu.org; Tue, 28 Jul 2015 04:05:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38377) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJzsh-0008FY-DJ for qemu-devel@nongnu.org; Tue, 28 Jul 2015 04:04:59 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 0ACD332B591 for ; Tue, 28 Jul 2015 08:04:59 +0000 (UTC) From: Paolo Bonzini Date: Tue, 28 Jul 2015 10:04:52 +0200 Message-Id: <1438070695-24889-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1438070695-24889-1-git-send-email-pbonzini@redhat.com> References: <1438070695-24889-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 1/4] crypto: fix built-in AES decrypt function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org From: "Daniel P. Berrange" 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 Message-Id: <1437740634-6261-1-git-send-email-berrange@redhat.com> Signed-off-by: Paolo Bonzini --- 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