From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49615) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZHEsD-0003vY-Ch for qemu-devel@nongnu.org; Mon, 20 Jul 2015 13:29:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZHEs9-0001yX-HG for qemu-devel@nongnu.org; Mon, 20 Jul 2015 13:29:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39381) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZHEs9-0001yE-Co for qemu-devel@nongnu.org; Mon, 20 Jul 2015 13:29:01 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 6AA1829330D for ; Mon, 20 Jul 2015 17:29:00 +0000 (UTC) From: "Daniel P. Berrange" Date: Mon, 20 Jul 2015 18:28:42 +0100 Message-Id: <1437413322-14808-1-git-send-email-berrange@redhat.com> Subject: [Qemu-devel] [PATCH] crypto: extend unit tests to cover decryption too List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini The current unit test only verify the encryption API, which resulted in us missing a recently introduced bug in the decryption API from commit d3462e3. It was fortunately later discovered & fixed by commit bd0959 thanks to the QEMU I/O tests for qcow2 encryption, but we should really detect this directly in the crypto unit tests. Signed-off-by: Daniel P. Berrange --- tests/test-crypto-cipher.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/test-crypto-cipher.c b/tests/test-crypto-cipher.c index f9b1a03..4485886 100644 --- a/tests/test-crypto-cipher.c +++ b/tests/test-crypto-cipher.c @@ -231,7 +231,6 @@ static void test_cipher(const void *opaque) size_t nkey, niv, nciphertext, nplaintext; char *outtexthex; - g_test_message("foo"); nkey = unhex_string(data->key, &key); niv = unhex_string(data->iv, &iv); nciphertext = unhex_string(data->ciphertext, &ciphertext); @@ -266,6 +265,25 @@ static void test_cipher(const void *opaque) g_assert_cmpstr(outtexthex, ==, data->ciphertext); + g_free(outtexthex); + + if (iv) { + g_assert(qcrypto_cipher_setiv(cipher, + iv, niv, + &err) == 0); + g_assert(err == NULL); + } + g_assert(qcrypto_cipher_decrypt(cipher, + ciphertext, + outtext, + nplaintext, + &err) == 0); + g_assert(err == NULL); + + outtexthex = hex_string(outtext, nplaintext); + + g_assert_cmpstr(outtexthex, ==, data->plaintext); + g_free(outtext); g_free(outtexthex); g_free(key); -- 2.4.3