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