|
|
b38b0f |
From a5301e637be3cdd123a3688901118e8d8099d29c Mon Sep 17 00:00:00 2001
|
|
|
b38b0f |
From: "Daniel P. Berrange" <berrange@redhat.com>
|
|
|
b38b0f |
Date: Wed, 24 Apr 2019 09:56:43 +0100
|
|
|
b38b0f |
Subject: [PATCH 9/9] crypto: add testing for unaligned buffers with XTS cipher
|
|
|
b38b0f |
mode
|
|
|
b38b0f |
MIME-Version: 1.0
|
|
|
b38b0f |
Content-Type: text/plain; charset=UTF-8
|
|
|
b38b0f |
Content-Transfer-Encoding: 8bit
|
|
|
b38b0f |
|
|
|
b38b0f |
RH-Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
b38b0f |
Message-id: <20190424095643.796-10-berrange@redhat.com>
|
|
|
b38b0f |
Patchwork-id: 85886
|
|
|
b38b0f |
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH 9/9] crypto: add testing for unaligned buffers with XTS cipher mode
|
|
|
b38b0f |
Bugzilla: 1680231
|
|
|
b38b0f |
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
|
|
|
b38b0f |
RH-Acked-by: John Snow <jsnow@redhat.com>
|
|
|
b38b0f |
RH-Acked-by: Eric Blake <eblake@redhat.com>
|
|
|
b38b0f |
|
|
|
b38b0f |
Validate that the XTS cipher mode will correctly operate with plain
|
|
|
b38b0f |
text, cipher text and IV buffers that are not 64-bit aligned.
|
|
|
b38b0f |
|
|
|
b38b0f |
Reviewed-by: Alberto Garcia <berto@igalia.com>
|
|
|
b38b0f |
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
|
|
|
b38b0f |
(cherry picked from commit 1e0fa32c6c952d2ce9c19d35717c609804dd55d5)
|
|
|
b38b0f |
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
|
|
|
b38b0f |
---
|
|
|
b38b0f |
tests/test-crypto-xts.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
b38b0f |
1 file changed, 86 insertions(+)
|
|
|
b38b0f |
|
|
|
b38b0f |
diff --git a/tests/test-crypto-xts.c b/tests/test-crypto-xts.c
|
|
|
b38b0f |
index 81606d9..6fb61cf 100644
|
|
|
b38b0f |
--- a/tests/test-crypto-xts.c
|
|
|
b38b0f |
+++ b/tests/test-crypto-xts.c
|
|
|
b38b0f |
@@ -416,6 +416,88 @@ static void test_xts_split(const void *opaque)
|
|
|
b38b0f |
}
|
|
|
b38b0f |
|
|
|
b38b0f |
|
|
|
b38b0f |
+static void test_xts_unaligned(const void *opaque)
|
|
|
b38b0f |
+{
|
|
|
b38b0f |
+#define BAD_ALIGN 3
|
|
|
b38b0f |
+ const QCryptoXTSTestData *data = opaque;
|
|
|
b38b0f |
+ uint8_t in[512 + BAD_ALIGN], out[512 + BAD_ALIGN];
|
|
|
b38b0f |
+ uint8_t Torg[16], T[16 + BAD_ALIGN];
|
|
|
b38b0f |
+ uint64_t seq;
|
|
|
b38b0f |
+ struct TestAES aesdata;
|
|
|
b38b0f |
+ struct TestAES aestweak;
|
|
|
b38b0f |
+
|
|
|
b38b0f |
+ AES_set_encrypt_key(data->key1, data->keylen / 2 * 8, &aesdata.enc);
|
|
|
b38b0f |
+ AES_set_decrypt_key(data->key1, data->keylen / 2 * 8, &aesdata.dec);
|
|
|
b38b0f |
+ AES_set_encrypt_key(data->key2, data->keylen / 2 * 8, &aestweak.enc);
|
|
|
b38b0f |
+ AES_set_decrypt_key(data->key2, data->keylen / 2 * 8, &aestweak.dec);
|
|
|
b38b0f |
+
|
|
|
b38b0f |
+ seq = data->seqnum;
|
|
|
b38b0f |
+ STORE64L(seq, Torg);
|
|
|
b38b0f |
+ memset(Torg + 8, 0, 8);
|
|
|
b38b0f |
+
|
|
|
b38b0f |
+ /* IV not aligned */
|
|
|
b38b0f |
+ memcpy(T + BAD_ALIGN, Torg, 16);
|
|
|
b38b0f |
+ memcpy(in, data->PTX, data->PTLEN);
|
|
|
b38b0f |
+ xts_encrypt(&aesdata, &aestweak,
|
|
|
b38b0f |
+ test_xts_aes_encrypt,
|
|
|
b38b0f |
+ test_xts_aes_decrypt,
|
|
|
b38b0f |
+ T + BAD_ALIGN, data->PTLEN, out, in);
|
|
|
b38b0f |
+
|
|
|
b38b0f |
+ g_assert(memcmp(out, data->CTX, data->PTLEN) == 0);
|
|
|
b38b0f |
+
|
|
|
b38b0f |
+ /* plain text not aligned */
|
|
|
b38b0f |
+ memcpy(T, Torg, 16);
|
|
|
b38b0f |
+ memcpy(in + BAD_ALIGN, data->PTX, data->PTLEN);
|
|
|
b38b0f |
+ xts_encrypt(&aesdata, &aestweak,
|
|
|
b38b0f |
+ test_xts_aes_encrypt,
|
|
|
b38b0f |
+ test_xts_aes_decrypt,
|
|
|
b38b0f |
+ T, data->PTLEN, out, in + BAD_ALIGN);
|
|
|
b38b0f |
+
|
|
|
b38b0f |
+ g_assert(memcmp(out, data->CTX, data->PTLEN) == 0);
|
|
|
b38b0f |
+
|
|
|
b38b0f |
+ /* cipher text not aligned */
|
|
|
b38b0f |
+ memcpy(T, Torg, 16);
|
|
|
b38b0f |
+ memcpy(in, data->PTX, data->PTLEN);
|
|
|
b38b0f |
+ xts_encrypt(&aesdata, &aestweak,
|
|
|
b38b0f |
+ test_xts_aes_encrypt,
|
|
|
b38b0f |
+ test_xts_aes_decrypt,
|
|
|
b38b0f |
+ T, data->PTLEN, out + BAD_ALIGN, in);
|
|
|
b38b0f |
+
|
|
|
b38b0f |
+ g_assert(memcmp(out + BAD_ALIGN, data->CTX, data->PTLEN) == 0);
|
|
|
b38b0f |
+
|
|
|
b38b0f |
+
|
|
|
b38b0f |
+ /* IV not aligned */
|
|
|
b38b0f |
+ memcpy(T + BAD_ALIGN, Torg, 16);
|
|
|
b38b0f |
+ memcpy(in, data->CTX, data->PTLEN);
|
|
|
b38b0f |
+ xts_decrypt(&aesdata, &aestweak,
|
|
|
b38b0f |
+ test_xts_aes_encrypt,
|
|
|
b38b0f |
+ test_xts_aes_decrypt,
|
|
|
b38b0f |
+ T + BAD_ALIGN, data->PTLEN, out, in);
|
|
|
b38b0f |
+
|
|
|
b38b0f |
+ g_assert(memcmp(out, data->PTX, data->PTLEN) == 0);
|
|
|
b38b0f |
+
|
|
|
b38b0f |
+ /* cipher text not aligned */
|
|
|
b38b0f |
+ memcpy(T, Torg, 16);
|
|
|
b38b0f |
+ memcpy(in + BAD_ALIGN, data->CTX, data->PTLEN);
|
|
|
b38b0f |
+ xts_decrypt(&aesdata, &aestweak,
|
|
|
b38b0f |
+ test_xts_aes_encrypt,
|
|
|
b38b0f |
+ test_xts_aes_decrypt,
|
|
|
b38b0f |
+ T, data->PTLEN, out, in + BAD_ALIGN);
|
|
|
b38b0f |
+
|
|
|
b38b0f |
+ g_assert(memcmp(out, data->PTX, data->PTLEN) == 0);
|
|
|
b38b0f |
+
|
|
|
b38b0f |
+ /* plain text not aligned */
|
|
|
b38b0f |
+ memcpy(T, Torg, 16);
|
|
|
b38b0f |
+ memcpy(in, data->CTX, data->PTLEN);
|
|
|
b38b0f |
+ xts_decrypt(&aesdata, &aestweak,
|
|
|
b38b0f |
+ test_xts_aes_encrypt,
|
|
|
b38b0f |
+ test_xts_aes_decrypt,
|
|
|
b38b0f |
+ T, data->PTLEN, out + BAD_ALIGN, in);
|
|
|
b38b0f |
+
|
|
|
b38b0f |
+ g_assert(memcmp(out + BAD_ALIGN, data->PTX, data->PTLEN) == 0);
|
|
|
b38b0f |
+}
|
|
|
b38b0f |
+
|
|
|
b38b0f |
+
|
|
|
b38b0f |
int main(int argc, char **argv)
|
|
|
b38b0f |
{
|
|
|
b38b0f |
size_t i;
|
|
|
b38b0f |
@@ -437,6 +519,10 @@ int main(int argc, char **argv)
|
|
|
b38b0f |
g_test_add_data_func(path, &test_data[i], test_xts_split);
|
|
|
b38b0f |
g_free(path);
|
|
|
b38b0f |
}
|
|
|
b38b0f |
+
|
|
|
b38b0f |
+ path = g_strdup_printf("%s/unaligned", test_data[i].path);
|
|
|
b38b0f |
+ g_test_add_data_func(path, &test_data[i], test_xts_unaligned);
|
|
|
b38b0f |
+ g_free(path);
|
|
|
b38b0f |
}
|
|
|
b38b0f |
|
|
|
b38b0f |
return g_test_run();
|
|
|
b38b0f |
--
|
|
|
b38b0f |
1.8.3.1
|
|
|
b38b0f |
|