crypto: extend unit tests to cover decryption too
The current unit test only verifies the encryption API, resulting in us missing a recently introduced bug in the decryption API from commitd3462e3
. It was fortunately later discovered & fixed by commitbd09594
, thanks to the QEMU I/O tests for qcow2 encryption, but we should really detect this directly in the crypto unit tests. Also remove an accidental debug message and simplify some asserts. Signed-off-by: Daniel P. Berrange <berrange@redhat.com> Message-Id: <1437468902-23230-1-git-send-email-berrange@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
6775e2c429
commit
019c2ab862
@ -226,12 +226,10 @@ static void test_cipher(const void *opaque)
|
|||||||
const QCryptoCipherTestData *data = opaque;
|
const QCryptoCipherTestData *data = opaque;
|
||||||
|
|
||||||
QCryptoCipher *cipher;
|
QCryptoCipher *cipher;
|
||||||
Error *err = NULL;
|
|
||||||
uint8_t *key, *iv, *ciphertext, *plaintext, *outtext;
|
uint8_t *key, *iv, *ciphertext, *plaintext, *outtext;
|
||||||
size_t nkey, niv, nciphertext, nplaintext;
|
size_t nkey, niv, nciphertext, nplaintext;
|
||||||
char *outtexthex;
|
char *outtexthex;
|
||||||
|
|
||||||
g_test_message("foo");
|
|
||||||
nkey = unhex_string(data->key, &key);
|
nkey = unhex_string(data->key, &key);
|
||||||
niv = unhex_string(data->iv, &iv);
|
niv = unhex_string(data->iv, &iv);
|
||||||
nciphertext = unhex_string(data->ciphertext, &ciphertext);
|
nciphertext = unhex_string(data->ciphertext, &ciphertext);
|
||||||
@ -244,28 +242,42 @@ static void test_cipher(const void *opaque)
|
|||||||
cipher = qcrypto_cipher_new(
|
cipher = qcrypto_cipher_new(
|
||||||
data->alg, data->mode,
|
data->alg, data->mode,
|
||||||
key, nkey,
|
key, nkey,
|
||||||
&err);
|
&error_abort);
|
||||||
g_assert(cipher != NULL);
|
g_assert(cipher != NULL);
|
||||||
g_assert(err == NULL);
|
|
||||||
|
|
||||||
|
|
||||||
if (iv) {
|
if (iv) {
|
||||||
g_assert(qcrypto_cipher_setiv(cipher,
|
g_assert(qcrypto_cipher_setiv(cipher,
|
||||||
iv, niv,
|
iv, niv,
|
||||||
&err) == 0);
|
&error_abort) == 0);
|
||||||
g_assert(err == NULL);
|
|
||||||
}
|
}
|
||||||
g_assert(qcrypto_cipher_encrypt(cipher,
|
g_assert(qcrypto_cipher_encrypt(cipher,
|
||||||
plaintext,
|
plaintext,
|
||||||
outtext,
|
outtext,
|
||||||
nplaintext,
|
nplaintext,
|
||||||
&err) == 0);
|
&error_abort) == 0);
|
||||||
g_assert(err == NULL);
|
|
||||||
|
|
||||||
outtexthex = hex_string(outtext, nciphertext);
|
outtexthex = hex_string(outtext, nciphertext);
|
||||||
|
|
||||||
g_assert_cmpstr(outtexthex, ==, data->ciphertext);
|
g_assert_cmpstr(outtexthex, ==, data->ciphertext);
|
||||||
|
|
||||||
|
g_free(outtexthex);
|
||||||
|
|
||||||
|
if (iv) {
|
||||||
|
g_assert(qcrypto_cipher_setiv(cipher,
|
||||||
|
iv, niv,
|
||||||
|
&error_abort) == 0);
|
||||||
|
}
|
||||||
|
g_assert(qcrypto_cipher_decrypt(cipher,
|
||||||
|
ciphertext,
|
||||||
|
outtext,
|
||||||
|
nplaintext,
|
||||||
|
&error_abort) == 0);
|
||||||
|
|
||||||
|
outtexthex = hex_string(outtext, nplaintext);
|
||||||
|
|
||||||
|
g_assert_cmpstr(outtexthex, ==, data->plaintext);
|
||||||
|
|
||||||
g_free(outtext);
|
g_free(outtext);
|
||||||
g_free(outtexthex);
|
g_free(outtexthex);
|
||||||
g_free(key);
|
g_free(key);
|
||||||
|
Loading…
Reference in New Issue
Block a user