|
|
383d26 |
From f6c73edd44ee862b9b965cad1789a5dece3c5974 Mon Sep 17 00:00:00 2001
|
|
|
383d26 |
From: "Daniel P. Berrange" <berrange@redhat.com>
|
|
|
383d26 |
Date: Wed, 24 Apr 2019 10:30:23 +0200
|
|
|
383d26 |
Subject: [PATCH 04/12] crypto: expand algorithm coverage for cipher benchmark
|
|
|
383d26 |
MIME-Version: 1.0
|
|
|
383d26 |
Content-Type: text/plain; charset=UTF-8
|
|
|
383d26 |
Content-Transfer-Encoding: 8bit
|
|
|
383d26 |
|
|
|
383d26 |
RH-Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
383d26 |
Message-id: <20190424103030.2925-3-berrange@redhat.com>
|
|
|
383d26 |
Patchwork-id: 85888
|
|
|
383d26 |
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 2/9] crypto: expand algorithm coverage for cipher benchmark
|
|
|
383d26 |
Bugzilla: 1666336
|
|
|
383d26 |
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
|
|
|
383d26 |
RH-Acked-by: John Snow <jsnow@redhat.com>
|
|
|
383d26 |
RH-Acked-by: Eric Blake <eblake@redhat.com>
|
|
|
383d26 |
|
|
|
383d26 |
Add testing coverage for AES with XTS, ECB and CTR modes
|
|
|
383d26 |
|
|
|
383d26 |
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
|
|
|
383d26 |
Reviewed-by: Alberto Garcia <berto@igalia.com>
|
|
|
383d26 |
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
|
|
|
383d26 |
(cherry picked from commit a9e08155bd4ae096688a8ff19669023ab0fbc170)
|
|
|
383d26 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
383d26 |
---
|
|
|
383d26 |
tests/benchmark-crypto-cipher.c | 149 +++++++++++++++++++++++++++++++++-------
|
|
|
383d26 |
1 file changed, 126 insertions(+), 23 deletions(-)
|
|
|
383d26 |
|
|
|
383d26 |
diff --git a/tests/benchmark-crypto-cipher.c b/tests/benchmark-crypto-cipher.c
|
|
|
383d26 |
index f5a0d0b..67fdf8c 100644
|
|
|
383d26 |
--- a/tests/benchmark-crypto-cipher.c
|
|
|
383d26 |
+++ b/tests/benchmark-crypto-cipher.c
|
|
|
383d26 |
@@ -15,17 +15,27 @@
|
|
|
383d26 |
#include "crypto/init.h"
|
|
|
383d26 |
#include "crypto/cipher.h"
|
|
|
383d26 |
|
|
|
383d26 |
-static void test_cipher_speed(const void *opaque)
|
|
|
383d26 |
+static void test_cipher_speed(size_t chunk_size,
|
|
|
383d26 |
+ QCryptoCipherMode mode,
|
|
|
383d26 |
+ QCryptoCipherAlgorithm alg)
|
|
|
383d26 |
{
|
|
|
383d26 |
QCryptoCipher *cipher;
|
|
|
383d26 |
Error *err = NULL;
|
|
|
383d26 |
double total = 0.0;
|
|
|
383d26 |
- size_t chunk_size = (size_t)opaque;
|
|
|
383d26 |
uint8_t *key = NULL, *iv = NULL;
|
|
|
383d26 |
uint8_t *plaintext = NULL, *ciphertext = NULL;
|
|
|
383d26 |
- size_t nkey = qcrypto_cipher_get_key_len(QCRYPTO_CIPHER_ALG_AES_128);
|
|
|
383d26 |
- size_t niv = qcrypto_cipher_get_iv_len(QCRYPTO_CIPHER_ALG_AES_128,
|
|
|
383d26 |
- QCRYPTO_CIPHER_MODE_CBC);
|
|
|
383d26 |
+ size_t nkey;
|
|
|
383d26 |
+ size_t niv;
|
|
|
383d26 |
+
|
|
|
383d26 |
+ if (!qcrypto_cipher_supports(alg, mode)) {
|
|
|
383d26 |
+ return;
|
|
|
383d26 |
+ }
|
|
|
383d26 |
+
|
|
|
383d26 |
+ nkey = qcrypto_cipher_get_key_len(alg);
|
|
|
383d26 |
+ niv = qcrypto_cipher_get_iv_len(alg, mode);
|
|
|
383d26 |
+ if (mode == QCRYPTO_CIPHER_MODE_XTS) {
|
|
|
383d26 |
+ nkey *= 2;
|
|
|
383d26 |
+ }
|
|
|
383d26 |
|
|
|
383d26 |
key = g_new0(uint8_t, nkey);
|
|
|
383d26 |
memset(key, g_test_rand_int(), nkey);
|
|
|
383d26 |
@@ -38,14 +48,14 @@ static void test_cipher_speed(const void *opaque)
|
|
|
383d26 |
plaintext = g_new0(uint8_t, chunk_size);
|
|
|
383d26 |
memset(plaintext, g_test_rand_int(), chunk_size);
|
|
|
383d26 |
|
|
|
383d26 |
- cipher = qcrypto_cipher_new(QCRYPTO_CIPHER_ALG_AES_128,
|
|
|
383d26 |
- QCRYPTO_CIPHER_MODE_CBC,
|
|
|
383d26 |
+ cipher = qcrypto_cipher_new(alg, mode,
|
|
|
383d26 |
key, nkey, &err;;
|
|
|
383d26 |
g_assert(cipher != NULL);
|
|
|
383d26 |
|
|
|
383d26 |
- g_assert(qcrypto_cipher_setiv(cipher,
|
|
|
383d26 |
- iv, niv,
|
|
|
383d26 |
- &err) == 0);
|
|
|
383d26 |
+ if (mode != QCRYPTO_CIPHER_MODE_ECB)
|
|
|
383d26 |
+ g_assert(qcrypto_cipher_setiv(cipher,
|
|
|
383d26 |
+ iv, niv,
|
|
|
383d26 |
+ &err) == 0);
|
|
|
383d26 |
|
|
|
383d26 |
g_test_timer_start();
|
|
|
383d26 |
do {
|
|
|
383d26 |
@@ -55,13 +65,26 @@ static void test_cipher_speed(const void *opaque)
|
|
|
383d26 |
chunk_size,
|
|
|
383d26 |
&err) == 0);
|
|
|
383d26 |
total += chunk_size;
|
|
|
383d26 |
- } while (g_test_timer_elapsed() < 5.0);
|
|
|
383d26 |
+ } while (g_test_timer_elapsed() < 1.0);
|
|
|
383d26 |
|
|
|
383d26 |
total /= MiB;
|
|
|
383d26 |
- g_print("cbc(aes128): ");
|
|
|
383d26 |
- g_print("Testing chunk_size %zu bytes ", chunk_size);
|
|
|
383d26 |
- g_print("done: %.2f MB in %.2f secs: ", total, g_test_timer_last());
|
|
|
383d26 |
- g_print("%.2f MB/sec\n", total / g_test_timer_last());
|
|
|
383d26 |
+ g_print("Enc chunk %zu bytes ", chunk_size);
|
|
|
383d26 |
+ g_print("%.2f MB/sec ", total / g_test_timer_last());
|
|
|
383d26 |
+
|
|
|
383d26 |
+ total = 0.0;
|
|
|
383d26 |
+ g_test_timer_start();
|
|
|
383d26 |
+ do {
|
|
|
383d26 |
+ g_assert(qcrypto_cipher_decrypt(cipher,
|
|
|
383d26 |
+ plaintext,
|
|
|
383d26 |
+ ciphertext,
|
|
|
383d26 |
+ chunk_size,
|
|
|
383d26 |
+ &err) == 0);
|
|
|
383d26 |
+ total += chunk_size;
|
|
|
383d26 |
+ } while (g_test_timer_elapsed() < 1.0);
|
|
|
383d26 |
+
|
|
|
383d26 |
+ total /= MiB;
|
|
|
383d26 |
+ g_print("Dec chunk %zu bytes ", chunk_size);
|
|
|
383d26 |
+ g_print("%.2f MB/sec ", total / g_test_timer_last());
|
|
|
383d26 |
|
|
|
383d26 |
qcrypto_cipher_free(cipher);
|
|
|
383d26 |
g_free(plaintext);
|
|
|
383d26 |
@@ -70,19 +93,99 @@ static void test_cipher_speed(const void *opaque)
|
|
|
383d26 |
g_free(key);
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
-int main(int argc, char **argv)
|
|
|
383d26 |
+
|
|
|
383d26 |
+static void test_cipher_speed_ecb_aes_128(const void *opaque)
|
|
|
383d26 |
+{
|
|
|
383d26 |
+ size_t chunk_size = (size_t)opaque;
|
|
|
383d26 |
+ test_cipher_speed(chunk_size,
|
|
|
383d26 |
+ QCRYPTO_CIPHER_MODE_ECB,
|
|
|
383d26 |
+ QCRYPTO_CIPHER_ALG_AES_128);
|
|
|
383d26 |
+}
|
|
|
383d26 |
+
|
|
|
383d26 |
+static void test_cipher_speed_ecb_aes_256(const void *opaque)
|
|
|
383d26 |
{
|
|
|
383d26 |
- size_t i;
|
|
|
383d26 |
- char name[64];
|
|
|
383d26 |
+ size_t chunk_size = (size_t)opaque;
|
|
|
383d26 |
+ test_cipher_speed(chunk_size,
|
|
|
383d26 |
+ QCRYPTO_CIPHER_MODE_ECB,
|
|
|
383d26 |
+ QCRYPTO_CIPHER_ALG_AES_256);
|
|
|
383d26 |
+}
|
|
|
383d26 |
+
|
|
|
383d26 |
+static void test_cipher_speed_cbc_aes_128(const void *opaque)
|
|
|
383d26 |
+{
|
|
|
383d26 |
+ size_t chunk_size = (size_t)opaque;
|
|
|
383d26 |
+ test_cipher_speed(chunk_size,
|
|
|
383d26 |
+ QCRYPTO_CIPHER_MODE_CBC,
|
|
|
383d26 |
+ QCRYPTO_CIPHER_ALG_AES_128);
|
|
|
383d26 |
+}
|
|
|
383d26 |
|
|
|
383d26 |
+static void test_cipher_speed_cbc_aes_256(const void *opaque)
|
|
|
383d26 |
+{
|
|
|
383d26 |
+ size_t chunk_size = (size_t)opaque;
|
|
|
383d26 |
+ test_cipher_speed(chunk_size,
|
|
|
383d26 |
+ QCRYPTO_CIPHER_MODE_CBC,
|
|
|
383d26 |
+ QCRYPTO_CIPHER_ALG_AES_256);
|
|
|
383d26 |
+}
|
|
|
383d26 |
+
|
|
|
383d26 |
+static void test_cipher_speed_ctr_aes_128(const void *opaque)
|
|
|
383d26 |
+{
|
|
|
383d26 |
+ size_t chunk_size = (size_t)opaque;
|
|
|
383d26 |
+ test_cipher_speed(chunk_size,
|
|
|
383d26 |
+ QCRYPTO_CIPHER_MODE_CTR,
|
|
|
383d26 |
+ QCRYPTO_CIPHER_ALG_AES_128);
|
|
|
383d26 |
+}
|
|
|
383d26 |
+
|
|
|
383d26 |
+static void test_cipher_speed_ctr_aes_256(const void *opaque)
|
|
|
383d26 |
+{
|
|
|
383d26 |
+ size_t chunk_size = (size_t)opaque;
|
|
|
383d26 |
+ test_cipher_speed(chunk_size,
|
|
|
383d26 |
+ QCRYPTO_CIPHER_MODE_CTR,
|
|
|
383d26 |
+ QCRYPTO_CIPHER_ALG_AES_256);
|
|
|
383d26 |
+}
|
|
|
383d26 |
+
|
|
|
383d26 |
+static void test_cipher_speed_xts_aes_128(const void *opaque)
|
|
|
383d26 |
+{
|
|
|
383d26 |
+ size_t chunk_size = (size_t)opaque;
|
|
|
383d26 |
+ test_cipher_speed(chunk_size,
|
|
|
383d26 |
+ QCRYPTO_CIPHER_MODE_XTS,
|
|
|
383d26 |
+ QCRYPTO_CIPHER_ALG_AES_128);
|
|
|
383d26 |
+}
|
|
|
383d26 |
+
|
|
|
383d26 |
+static void test_cipher_speed_xts_aes_256(const void *opaque)
|
|
|
383d26 |
+{
|
|
|
383d26 |
+ size_t chunk_size = (size_t)opaque;
|
|
|
383d26 |
+ test_cipher_speed(chunk_size,
|
|
|
383d26 |
+ QCRYPTO_CIPHER_MODE_XTS,
|
|
|
383d26 |
+ QCRYPTO_CIPHER_ALG_AES_256);
|
|
|
383d26 |
+}
|
|
|
383d26 |
+
|
|
|
383d26 |
+
|
|
|
383d26 |
+int main(int argc, char **argv)
|
|
|
383d26 |
+{
|
|
|
383d26 |
g_test_init(&argc, &argv, NULL);
|
|
|
383d26 |
g_assert(qcrypto_init(NULL) == 0);
|
|
|
383d26 |
|
|
|
383d26 |
- for (i = 512; i <= 64 * KiB; i *= 2) {
|
|
|
383d26 |
- memset(name, 0 , sizeof(name));
|
|
|
383d26 |
- snprintf(name, sizeof(name), "/crypto/cipher/speed-%zu", i);
|
|
|
383d26 |
- g_test_add_data_func(name, (void *)i, test_cipher_speed);
|
|
|
383d26 |
- }
|
|
|
383d26 |
+#define ADD_TEST(mode, cipher, keysize, chunk) \
|
|
|
383d26 |
+ g_test_add_data_func( \
|
|
|
383d26 |
+ "/crypto/cipher/" #mode "-" #cipher "-" #keysize "/chunk-" #chunk, \
|
|
|
383d26 |
+ (void *)chunk, \
|
|
|
383d26 |
+ test_cipher_speed_ ## mode ## _ ## cipher ## _ ## keysize)
|
|
|
383d26 |
+
|
|
|
383d26 |
+#define ADD_TESTS(chunk) \
|
|
|
383d26 |
+ do { \
|
|
|
383d26 |
+ ADD_TEST(ecb, aes, 128, chunk); \
|
|
|
383d26 |
+ ADD_TEST(ecb, aes, 256, chunk); \
|
|
|
383d26 |
+ ADD_TEST(cbc, aes, 128, chunk); \
|
|
|
383d26 |
+ ADD_TEST(cbc, aes, 256, chunk); \
|
|
|
383d26 |
+ ADD_TEST(ctr, aes, 128, chunk); \
|
|
|
383d26 |
+ ADD_TEST(ctr, aes, 256, chunk); \
|
|
|
383d26 |
+ ADD_TEST(xts, aes, 128, chunk); \
|
|
|
383d26 |
+ ADD_TEST(xts, aes, 256, chunk); \
|
|
|
383d26 |
+ } while (0)
|
|
|
383d26 |
+
|
|
|
383d26 |
+ ADD_TESTS(512);
|
|
|
383d26 |
+ ADD_TESTS(4096);
|
|
|
383d26 |
+ ADD_TESTS(16384);
|
|
|
383d26 |
+ ADD_TESTS(65536);
|
|
|
383d26 |
|
|
|
383d26 |
return g_test_run();
|
|
|
383d26 |
}
|
|
|
383d26 |
--
|
|
|
383d26 |
1.8.3.1
|
|
|
383d26 |
|