From nobody Thu Nov 6 01:06:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539089870806964.0510054880176; Tue, 9 Oct 2018 05:57:50 -0700 (PDT) Received: from localhost ([::1]:51290 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9ra9-0001ay-Lx for importer@patchew.org; Tue, 09 Oct 2018 08:57:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43942) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9rYJ-0000Uz-5h for qemu-devel@nongnu.org; Tue, 09 Oct 2018 08:55:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9rYI-00046x-3b for qemu-devel@nongnu.org; Tue, 09 Oct 2018 08:55:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34624) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9rYH-00046b-Ri for qemu-devel@nongnu.org; Tue, 09 Oct 2018 08:55:54 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 369667F6B3; Tue, 9 Oct 2018 12:55:53 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1ADD26A965; Tue, 9 Oct 2018 12:55:46 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 13:55:36 +0100 Message-Id: <20181009125541.24455-2-berrange@redhat.com> In-Reply-To: <20181009125541.24455-1-berrange@redhat.com> References: <20181009125541.24455-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 09 Oct 2018 12:55:53 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/6] crypto: expand algorithm coverage for cipher benchmark X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alberto Garcia Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add testing coverage for AES with XTS, ECB and CTR modes Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Alberto Garcia Reviewed-by: Marc-Andr=C3=A9 Lureau --- tests/benchmark-crypto-cipher.c | 149 +++++++++++++++++++++++++++----- 1 file changed, 126 insertions(+), 23 deletions(-) diff --git a/tests/benchmark-crypto-cipher.c b/tests/benchmark-crypto-ciphe= r.c index f5a0d0bc32..a8325a9510 100644 --- a/tests/benchmark-crypto-cipher.c +++ b/tests/benchmark-crypto-cipher.c @@ -15,17 +15,27 @@ #include "crypto/init.h" #include "crypto/cipher.h" =20 -static void test_cipher_speed(const void *opaque) +static void test_cipher_speed(size_t chunk_size, + QCryptoCipherMode mode, + QCryptoCipherAlgorithm alg) { QCryptoCipher *cipher; Error *err =3D NULL; double total =3D 0.0; - size_t chunk_size =3D (size_t)opaque; uint8_t *key =3D NULL, *iv =3D NULL; uint8_t *plaintext =3D NULL, *ciphertext =3D NULL; - size_t nkey =3D qcrypto_cipher_get_key_len(QCRYPTO_CIPHER_ALG_AES_128); - size_t niv =3D qcrypto_cipher_get_iv_len(QCRYPTO_CIPHER_ALG_AES_128, - QCRYPTO_CIPHER_MODE_CBC); + size_t nkey; + size_t niv; + + if (!qcrypto_cipher_supports(alg, mode)) { + return; + } + + nkey =3D qcrypto_cipher_get_key_len(alg); + niv =3D qcrypto_cipher_get_iv_len(alg, mode); + if (mode =3D=3D QCRYPTO_CIPHER_MODE_XTS) { + nkey *=3D 2; + } =20 key =3D g_new0(uint8_t, nkey); memset(key, g_test_rand_int(), nkey); @@ -38,14 +48,14 @@ static void test_cipher_speed(const void *opaque) plaintext =3D g_new0(uint8_t, chunk_size); memset(plaintext, g_test_rand_int(), chunk_size); =20 - cipher =3D qcrypto_cipher_new(QCRYPTO_CIPHER_ALG_AES_128, - QCRYPTO_CIPHER_MODE_CBC, + cipher =3D qcrypto_cipher_new(alg, mode, key, nkey, &err); g_assert(cipher !=3D NULL); =20 - g_assert(qcrypto_cipher_setiv(cipher, - iv, niv, - &err) =3D=3D 0); + if (mode !=3D QCRYPTO_CIPHER_MODE_ECB) + g_assert(qcrypto_cipher_setiv(cipher, + iv, niv, + &err) =3D=3D 0); =20 g_test_timer_start(); do { @@ -55,13 +65,26 @@ static void test_cipher_speed(const void *opaque) chunk_size, &err) =3D=3D 0); total +=3D chunk_size; - } while (g_test_timer_elapsed() < 5.0); + } while (g_test_timer_elapsed() < 1.0); =20 total /=3D MiB; - g_print("cbc(aes128): "); - g_print("Testing chunk_size %zu bytes ", chunk_size); - g_print("done: %.2f MB in %.2f secs: ", total, g_test_timer_last()); - g_print("%.2f MB/sec\n", total / g_test_timer_last()); + g_print("Enc chunk %zu bytes ", chunk_size); + g_print("%.2f MB/sec ", total / g_test_timer_last()); + + total =3D 0.0; + g_test_timer_start(); + do { + g_assert(qcrypto_cipher_decrypt(cipher, + plaintext, + ciphertext, + chunk_size, + &err) =3D=3D 0); + total +=3D chunk_size; + } while (g_test_timer_elapsed() < 1.0); + + total /=3D MiB; + g_print("Dec chunk %zu bytes ", chunk_size); + g_print("%.2f MB/sec ", total / g_test_timer_last()); =20 qcrypto_cipher_free(cipher); g_free(plaintext); @@ -70,19 +93,99 @@ static void test_cipher_speed(const void *opaque) g_free(key); } =20 -int main(int argc, char **argv) + +static void test_cipher_speed_ecb_aes_128(const void *opaque) +{ + size_t chunk_size =3D (size_t)opaque; + test_cipher_speed(chunk_size, + QCRYPTO_CIPHER_MODE_ECB, + QCRYPTO_CIPHER_ALG_AES_128); +} + +static void test_cipher_speed_ecb_aes_256(const void *opaque) { - size_t i; - char name[64]; + size_t chunk_size =3D (size_t)opaque; + test_cipher_speed(chunk_size, + QCRYPTO_CIPHER_MODE_ECB, + QCRYPTO_CIPHER_ALG_AES_256); +} + +static void test_cipher_speed_cbc_aes_128(const void *opaque) +{ + size_t chunk_size =3D (size_t)opaque; + test_cipher_speed(chunk_size, + QCRYPTO_CIPHER_MODE_CBC, + QCRYPTO_CIPHER_ALG_AES_128); +} =20 +static void test_cipher_speed_cbc_aes_256(const void *opaque) +{ + size_t chunk_size =3D (size_t)opaque; + test_cipher_speed(chunk_size, + QCRYPTO_CIPHER_MODE_CBC, + QCRYPTO_CIPHER_ALG_AES_256); +} + +static void test_cipher_speed_ctr_aes_128(const void *opaque) +{ + size_t chunk_size =3D (size_t)opaque; + test_cipher_speed(chunk_size, + QCRYPTO_CIPHER_MODE_CTR, + QCRYPTO_CIPHER_ALG_AES_128); +} + +static void test_cipher_speed_ctr_aes_256(const void *opaque) +{ + size_t chunk_size =3D (size_t)opaque; + test_cipher_speed(chunk_size, + QCRYPTO_CIPHER_MODE_CTR, + QCRYPTO_CIPHER_ALG_AES_256); +} + +static void test_cipher_speed_xts_aes_128(const void *opaque) +{ + size_t chunk_size =3D (size_t)opaque; + test_cipher_speed(chunk_size, + QCRYPTO_CIPHER_MODE_XTS, + QCRYPTO_CIPHER_ALG_AES_128); +} + +static void test_cipher_speed_xts_aes_256(const void *opaque) +{ + size_t chunk_size =3D (size_t)opaque; + test_cipher_speed(chunk_size, + QCRYPTO_CIPHER_MODE_XTS, + QCRYPTO_CIPHER_ALG_AES_256); +} + + +int main(int argc, char **argv) +{ g_test_init(&argc, &argv, NULL); g_assert(qcrypto_init(NULL) =3D=3D 0); =20 - for (i =3D 512; i <=3D 64 * KiB; i *=3D 2) { - memset(name, 0 , sizeof(name)); - snprintf(name, sizeof(name), "/crypto/cipher/speed-%zu", i); - g_test_add_data_func(name, (void *)i, test_cipher_speed); - } +#define ADD_TEST(mode, cipher, keysize, chunk) \ + g_test_add_data_func( \ + "/crypto/cipher/" #mode "-" #cipher "-" #keysize "/chunk-" #chunk,= \ + (void *)chunk, \ + test_cipher_speed_ ## mode ## _ ## cipher ## _ ## keysize) + +#define ADD_TESTS(chunk) \ + do { \ + ADD_TEST(ecb, aes, 128, chunk); \ + ADD_TEST(ecb, aes, 256, chunk); \ + ADD_TEST(cbc, aes, 128, chunk); \ + ADD_TEST(cbc, aes, 256, chunk); \ + ADD_TEST(ctr, aes, 128, chunk); \ + ADD_TEST(ctr, aes, 256, chunk); \ + ADD_TEST(xts, aes, 128, chunk); \ + ADD_TEST(xts, aes, 256, chunk); \ + } while (0) + + ADD_TESTS(512); + ADD_TESTS(4096); + ADD_TESTS(16384); + ADD_TESTS(65536); =20 return g_test_run(); } --=20 2.17.1 From nobody Thu Nov 6 01:06:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539089883863284.74420423089737; Tue, 9 Oct 2018 05:58:03 -0700 (PDT) Received: from localhost ([::1]:51291 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9raI-0001fR-R8 for importer@patchew.org; Tue, 09 Oct 2018 08:57:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9rYL-0000WZ-Fb for qemu-devel@nongnu.org; Tue, 09 Oct 2018 08:56:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9rYJ-00049r-Pk for qemu-devel@nongnu.org; Tue, 09 Oct 2018 08:55:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37810) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9rYJ-000482-HN for qemu-devel@nongnu.org; Tue, 09 Oct 2018 08:55:55 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D6AF4811A7; Tue, 9 Oct 2018 12:55:54 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C4B16A965; Tue, 9 Oct 2018 12:55:53 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 13:55:37 +0100 Message-Id: <20181009125541.24455-3-berrange@redhat.com> In-Reply-To: <20181009125541.24455-1-berrange@redhat.com> References: <20181009125541.24455-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 09 Oct 2018 12:55:54 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/6] crypto: remove code duplication in tweak encrypt/decrypt X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alberto Garcia Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The tweak encrypt/decrypt functions are identical except for the comments, so can be merged. Profiling data shows that the compiler is in fact already merging the two merges in the object files. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Alberto Garcia Reviewed-by: Marc-Andr=C3=A9 Lureau --- crypto/xts.c | 64 ++++++++++++---------------------------------------- 1 file changed, 15 insertions(+), 49 deletions(-) diff --git a/crypto/xts.c b/crypto/xts.c index 95212341f6..3c1a92f01d 100644 --- a/crypto/xts.c +++ b/crypto/xts.c @@ -43,20 +43,20 @@ static void xts_mult_x(uint8_t *I) =20 =20 /** - * xts_tweak_uncrypt: + * xts_tweak_encdec: * @param ctxt: the cipher context * @param func: the cipher function - * @src: buffer providing the cipher text of XTS_BLOCK_SIZE bytes - * @dst: buffer to output the plain text of XTS_BLOCK_SIZE bytes + * @src: buffer providing the input text of XTS_BLOCK_SIZE bytes + * @dst: buffer to output the output text of XTS_BLOCK_SIZE bytes * @iv: the initialization vector tweak of XTS_BLOCK_SIZE bytes * - * Decrypt data with a tweak + * Encrypt/decrypt data with a tweak */ -static void xts_tweak_decrypt(const void *ctx, - xts_cipher_func *func, - const uint8_t *src, - uint8_t *dst, - uint8_t *iv) +static void xts_tweak_encdec(const void *ctx, + xts_cipher_func *func, + const uint8_t *src, + uint8_t *dst, + uint8_t *iv) { unsigned long x; =20 @@ -105,7 +105,7 @@ void xts_decrypt(const void *datactx, encfunc(tweakctx, XTS_BLOCK_SIZE, T, iv); =20 for (i =3D 0; i < lim; i++) { - xts_tweak_decrypt(datactx, decfunc, src, dst, T); + xts_tweak_encdec(datactx, decfunc, src, dst, T); =20 src +=3D XTS_BLOCK_SIZE; dst +=3D XTS_BLOCK_SIZE; @@ -117,7 +117,7 @@ void xts_decrypt(const void *datactx, xts_mult_x(CC); =20 /* PP =3D tweak decrypt block m-1 */ - xts_tweak_decrypt(datactx, decfunc, src, PP, CC); + xts_tweak_encdec(datactx, decfunc, src, PP, CC); =20 /* Pm =3D first length % XTS_BLOCK_SIZE bytes of PP */ for (i =3D 0; i < mo; i++) { @@ -129,7 +129,7 @@ void xts_decrypt(const void *datactx, } =20 /* Pm-1 =3D Tweak uncrypt CC */ - xts_tweak_decrypt(datactx, decfunc, CC, dst, T); + xts_tweak_encdec(datactx, decfunc, CC, dst, T); } =20 /* Decrypt the iv back */ @@ -137,40 +137,6 @@ void xts_decrypt(const void *datactx, } =20 =20 -/** - * xts_tweak_crypt: - * @param ctxt: the cipher context - * @param func: the cipher function - * @src: buffer providing the plain text of XTS_BLOCK_SIZE bytes - * @dst: buffer to output the cipher text of XTS_BLOCK_SIZE bytes - * @iv: the initialization vector tweak of XTS_BLOCK_SIZE bytes - * - * Encrypt data with a tweak - */ -static void xts_tweak_encrypt(const void *ctx, - xts_cipher_func *func, - const uint8_t *src, - uint8_t *dst, - uint8_t *iv) -{ - unsigned long x; - - /* tweak encrypt block i */ - for (x =3D 0; x < XTS_BLOCK_SIZE; x++) { - dst[x] =3D src[x] ^ iv[x]; - } - - func(ctx, XTS_BLOCK_SIZE, dst, dst); - - for (x =3D 0; x < XTS_BLOCK_SIZE; x++) { - dst[x] =3D dst[x] ^ iv[x]; - } - - /* LFSR the tweak */ - xts_mult_x(iv); -} - - void xts_encrypt(const void *datactx, const void *tweakctx, xts_cipher_func *encfunc, @@ -200,7 +166,7 @@ void xts_encrypt(const void *datactx, encfunc(tweakctx, XTS_BLOCK_SIZE, T, iv); =20 for (i =3D 0; i < lim; i++) { - xts_tweak_encrypt(datactx, encfunc, src, dst, T); + xts_tweak_encdec(datactx, encfunc, src, dst, T); =20 dst +=3D XTS_BLOCK_SIZE; src +=3D XTS_BLOCK_SIZE; @@ -209,7 +175,7 @@ void xts_encrypt(const void *datactx, /* if length is not a multiple of XTS_BLOCK_SIZE then */ if (mo > 0) { /* CC =3D tweak encrypt block m-1 */ - xts_tweak_encrypt(datactx, encfunc, src, CC, T); + xts_tweak_encdec(datactx, encfunc, src, CC, T); =20 /* Cm =3D first length % XTS_BLOCK_SIZE bytes of CC */ for (i =3D 0; i < mo; i++) { @@ -222,7 +188,7 @@ void xts_encrypt(const void *datactx, } =20 /* Cm-1 =3D Tweak encrypt PP */ - xts_tweak_encrypt(datactx, encfunc, PP, dst, T); + xts_tweak_encdec(datactx, encfunc, PP, dst, T); } =20 /* Decrypt the iv back */ --=20 2.17.1 From nobody Thu Nov 6 01:06:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539089882273642.4936815807584; Tue, 9 Oct 2018 05:58:02 -0700 (PDT) Received: from localhost ([::1]:51292 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9raL-0001jZ-4O for importer@patchew.org; Tue, 09 Oct 2018 08:58:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9rYN-0000Xi-8D for qemu-devel@nongnu.org; Tue, 09 Oct 2018 08:56:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9rYL-0004E3-K5 for qemu-devel@nongnu.org; Tue, 09 Oct 2018 08:55:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54310) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9rYL-0004BB-B6 for qemu-devel@nongnu.org; Tue, 09 Oct 2018 08:55:57 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 28EF03082143; Tue, 9 Oct 2018 12:55:56 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2BB8C6A962; Tue, 9 Oct 2018 12:55:55 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 13:55:38 +0100 Message-Id: <20181009125541.24455-4-berrange@redhat.com> In-Reply-To: <20181009125541.24455-1-berrange@redhat.com> References: <20181009125541.24455-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Tue, 09 Oct 2018 12:55:56 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 3/6] crypto: introduce a xts_uint128 data type X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alberto Garcia Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The new type is designed to allow use of 64-bit arithmetic instead of operating 1-byte at a time. The following patches will use this to improve performance. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Alberto Garcia --- crypto/xts.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/crypto/xts.c b/crypto/xts.c index 3c1a92f01d..ded4365191 100644 --- a/crypto/xts.c +++ b/crypto/xts.c @@ -26,6 +26,11 @@ #include "qemu/osdep.h" #include "crypto/xts.h" =20 +typedef struct { + uint64_t a; + uint64_t b; +} xts_uint128; + static void xts_mult_x(uint8_t *I) { int x; @@ -85,7 +90,7 @@ void xts_decrypt(const void *datactx, uint8_t *dst, const uint8_t *src) { - uint8_t PP[XTS_BLOCK_SIZE], CC[XTS_BLOCK_SIZE], T[XTS_BLOCK_SIZE]; + xts_uint128 PP, CC, T; unsigned long i, m, mo, lim; =20 /* get number of blocks */ @@ -102,10 +107,10 @@ void xts_decrypt(const void *datactx, } =20 /* encrypt the iv */ - encfunc(tweakctx, XTS_BLOCK_SIZE, T, iv); + encfunc(tweakctx, XTS_BLOCK_SIZE, (uint8_t *)&T, iv); =20 for (i =3D 0; i < lim; i++) { - xts_tweak_encdec(datactx, decfunc, src, dst, T); + xts_tweak_encdec(datactx, decfunc, src, dst, (uint8_t *)&T); =20 src +=3D XTS_BLOCK_SIZE; dst +=3D XTS_BLOCK_SIZE; @@ -113,27 +118,27 @@ void xts_decrypt(const void *datactx, =20 /* if length is not a multiple of XTS_BLOCK_SIZE then */ if (mo > 0) { - memcpy(CC, T, XTS_BLOCK_SIZE); - xts_mult_x(CC); + memcpy(&CC, &T, XTS_BLOCK_SIZE); + xts_mult_x((uint8_t *)&CC); =20 /* PP =3D tweak decrypt block m-1 */ - xts_tweak_encdec(datactx, decfunc, src, PP, CC); + xts_tweak_encdec(datactx, decfunc, src, (uint8_t *)&PP, (uint8_t *= )&CC); =20 /* Pm =3D first length % XTS_BLOCK_SIZE bytes of PP */ for (i =3D 0; i < mo; i++) { - CC[i] =3D src[XTS_BLOCK_SIZE + i]; - dst[XTS_BLOCK_SIZE + i] =3D PP[i]; + ((uint8_t *)&CC)[i] =3D src[XTS_BLOCK_SIZE + i]; + dst[XTS_BLOCK_SIZE + i] =3D ((uint8_t *)&PP)[i]; } for (; i < XTS_BLOCK_SIZE; i++) { - CC[i] =3D PP[i]; + ((uint8_t *)&CC)[i] =3D ((uint8_t *)&PP)[i]; } =20 /* Pm-1 =3D Tweak uncrypt CC */ - xts_tweak_encdec(datactx, decfunc, CC, dst, T); + xts_tweak_encdec(datactx, decfunc, (uint8_t *)&CC, dst, (uint8_t *= )&T); } =20 /* Decrypt the iv back */ - decfunc(tweakctx, XTS_BLOCK_SIZE, iv, T); + decfunc(tweakctx, XTS_BLOCK_SIZE, iv, (uint8_t *)&T); } =20 =20 @@ -146,7 +151,7 @@ void xts_encrypt(const void *datactx, uint8_t *dst, const uint8_t *src) { - uint8_t PP[XTS_BLOCK_SIZE], CC[XTS_BLOCK_SIZE], T[XTS_BLOCK_SIZE]; + xts_uint128 PP, CC, T; unsigned long i, m, mo, lim; =20 /* get number of blocks */ @@ -163,10 +168,10 @@ void xts_encrypt(const void *datactx, } =20 /* encrypt the iv */ - encfunc(tweakctx, XTS_BLOCK_SIZE, T, iv); + encfunc(tweakctx, XTS_BLOCK_SIZE, (uint8_t *)&T, iv); =20 for (i =3D 0; i < lim; i++) { - xts_tweak_encdec(datactx, encfunc, src, dst, T); + xts_tweak_encdec(datactx, encfunc, src, dst, (uint8_t *)&T); =20 dst +=3D XTS_BLOCK_SIZE; src +=3D XTS_BLOCK_SIZE; @@ -175,22 +180,22 @@ void xts_encrypt(const void *datactx, /* if length is not a multiple of XTS_BLOCK_SIZE then */ if (mo > 0) { /* CC =3D tweak encrypt block m-1 */ - xts_tweak_encdec(datactx, encfunc, src, CC, T); + xts_tweak_encdec(datactx, encfunc, src, (uint8_t *)&CC, (uint8_t *= )&T); =20 /* Cm =3D first length % XTS_BLOCK_SIZE bytes of CC */ for (i =3D 0; i < mo; i++) { - PP[i] =3D src[XTS_BLOCK_SIZE + i]; - dst[XTS_BLOCK_SIZE + i] =3D CC[i]; + ((uint8_t *)&PP)[i] =3D src[XTS_BLOCK_SIZE + i]; + dst[XTS_BLOCK_SIZE + i] =3D ((uint8_t *)&CC)[i]; } =20 for (; i < XTS_BLOCK_SIZE; i++) { - PP[i] =3D CC[i]; + ((uint8_t *)&PP)[i] =3D ((uint8_t *)&CC)[i]; } =20 /* Cm-1 =3D Tweak encrypt PP */ - xts_tweak_encdec(datactx, encfunc, PP, dst, T); + xts_tweak_encdec(datactx, encfunc, (uint8_t *)&PP, dst, (uint8_t *= )&T); } =20 /* Decrypt the iv back */ - decfunc(tweakctx, XTS_BLOCK_SIZE, iv, T); + decfunc(tweakctx, XTS_BLOCK_SIZE, iv, (uint8_t *)&T); } --=20 2.17.1 From nobody Thu Nov 6 01:06:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539090239813366.12391318594496; Tue, 9 Oct 2018 06:03:59 -0700 (PDT) Received: from localhost ([::1]:51335 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9rg2-0006CV-Vj for importer@patchew.org; Tue, 09 Oct 2018 09:03:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44000) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9rYV-0000c1-7c for qemu-devel@nongnu.org; Tue, 09 Oct 2018 08:56:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9rYP-0004GI-6C for qemu-devel@nongnu.org; Tue, 09 Oct 2018 08:56:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37834) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9rYN-0004Dn-7U for qemu-devel@nongnu.org; Tue, 09 Oct 2018 08:55:59 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 59FFA811A4; Tue, 9 Oct 2018 12:55:57 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 62B366A965; Tue, 9 Oct 2018 12:55:56 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 13:55:39 +0100 Message-Id: <20181009125541.24455-5-berrange@redhat.com> In-Reply-To: <20181009125541.24455-1-berrange@redhat.com> References: <20181009125541.24455-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 09 Oct 2018 12:55:57 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 4/6] crypto: convert xts_tweak_encdec to use xts_uint128 type X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alberto Garcia Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using 64-bit arithmetic increases the performance for xts-aes-128 when built with gcrypt: Encrypt: 235 MB/s -> 320 MB/s Decrypt: 245 MB/s -> 325 MB/s Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/xts.c | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/crypto/xts.c b/crypto/xts.c index ded4365191..f109c8a3ee 100644 --- a/crypto/xts.c +++ b/crypto/xts.c @@ -31,6 +31,12 @@ typedef struct { uint64_t b; } xts_uint128; =20 +#define xts_uint128_xor(D, S1, S2) \ + do { \ + (D)->a =3D (S1)->a ^ (S2)->a; \ + (D)->b =3D (S1)->b ^ (S2)->b; \ + } while (0) + static void xts_mult_x(uint8_t *I) { int x; @@ -59,25 +65,19 @@ static void xts_mult_x(uint8_t *I) */ static void xts_tweak_encdec(const void *ctx, xts_cipher_func *func, - const uint8_t *src, - uint8_t *dst, - uint8_t *iv) + const xts_uint128 *src, + xts_uint128 *dst, + xts_uint128 *iv) { - unsigned long x; - /* tweak encrypt block i */ - for (x =3D 0; x < XTS_BLOCK_SIZE; x++) { - dst[x] =3D src[x] ^ iv[x]; - } + xts_uint128_xor(dst, src, iv); =20 - func(ctx, XTS_BLOCK_SIZE, dst, dst); + func(ctx, XTS_BLOCK_SIZE, (uint8_t *)dst, (uint8_t *)dst); =20 - for (x =3D 0; x < XTS_BLOCK_SIZE; x++) { - dst[x] =3D dst[x] ^ iv[x]; - } + xts_uint128_xor(dst, dst, iv); =20 /* LFSR the tweak */ - xts_mult_x(iv); + xts_mult_x((uint8_t *)iv); } =20 =20 @@ -110,7 +110,11 @@ void xts_decrypt(const void *datactx, encfunc(tweakctx, XTS_BLOCK_SIZE, (uint8_t *)&T, iv); =20 for (i =3D 0; i < lim; i++) { - xts_tweak_encdec(datactx, decfunc, src, dst, (uint8_t *)&T); + xts_uint128 S, D; + + memcpy(&S, src, XTS_BLOCK_SIZE); + xts_tweak_encdec(datactx, decfunc, &S, &D, &T); + memcpy(dst, &D, XTS_BLOCK_SIZE); =20 src +=3D XTS_BLOCK_SIZE; dst +=3D XTS_BLOCK_SIZE; @@ -118,11 +122,13 @@ void xts_decrypt(const void *datactx, =20 /* if length is not a multiple of XTS_BLOCK_SIZE then */ if (mo > 0) { + xts_uint128 S, D; memcpy(&CC, &T, XTS_BLOCK_SIZE); xts_mult_x((uint8_t *)&CC); =20 /* PP =3D tweak decrypt block m-1 */ - xts_tweak_encdec(datactx, decfunc, src, (uint8_t *)&PP, (uint8_t *= )&CC); + memcpy(&S, src, XTS_BLOCK_SIZE); + xts_tweak_encdec(datactx, decfunc, &S, &PP, &CC); =20 /* Pm =3D first length % XTS_BLOCK_SIZE bytes of PP */ for (i =3D 0; i < mo; i++) { @@ -134,7 +140,8 @@ void xts_decrypt(const void *datactx, } =20 /* Pm-1 =3D Tweak uncrypt CC */ - xts_tweak_encdec(datactx, decfunc, (uint8_t *)&CC, dst, (uint8_t *= )&T); + xts_tweak_encdec(datactx, decfunc, &CC, &D, &T); + memcpy(dst, &D, XTS_BLOCK_SIZE); } =20 /* Decrypt the iv back */ @@ -171,7 +178,11 @@ void xts_encrypt(const void *datactx, encfunc(tweakctx, XTS_BLOCK_SIZE, (uint8_t *)&T, iv); =20 for (i =3D 0; i < lim; i++) { - xts_tweak_encdec(datactx, encfunc, src, dst, (uint8_t *)&T); + xts_uint128 S, D; + + memcpy(&S, src, XTS_BLOCK_SIZE); + xts_tweak_encdec(datactx, encfunc, &S, &D, &T); + memcpy(dst, &D, XTS_BLOCK_SIZE); =20 dst +=3D XTS_BLOCK_SIZE; src +=3D XTS_BLOCK_SIZE; @@ -179,8 +190,10 @@ void xts_encrypt(const void *datactx, =20 /* if length is not a multiple of XTS_BLOCK_SIZE then */ if (mo > 0) { + xts_uint128 S, D; /* CC =3D tweak encrypt block m-1 */ - xts_tweak_encdec(datactx, encfunc, src, (uint8_t *)&CC, (uint8_t *= )&T); + memcpy(&S, src, XTS_BLOCK_SIZE); + xts_tweak_encdec(datactx, encfunc, &S, &CC, &T); =20 /* Cm =3D first length % XTS_BLOCK_SIZE bytes of CC */ for (i =3D 0; i < mo; i++) { @@ -193,7 +206,8 @@ void xts_encrypt(const void *datactx, } =20 /* Cm-1 =3D Tweak encrypt PP */ - xts_tweak_encdec(datactx, encfunc, (uint8_t *)&PP, dst, (uint8_t *= )&T); + xts_tweak_encdec(datactx, encfunc, &PP, &D, &T); + memcpy(dst, &D, XTS_BLOCK_SIZE); } =20 /* Decrypt the iv back */ --=20 2.17.1 From nobody Thu Nov 6 01:06:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539090017156830.922051912977; Tue, 9 Oct 2018 06:00:17 -0700 (PDT) Received: from localhost ([::1]:51301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9rcU-0003b7-01 for importer@patchew.org; Tue, 09 Oct 2018 09:00:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9rYV-0000c0-7X for qemu-devel@nongnu.org; Tue, 09 Oct 2018 08:56:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9rYP-0004Gp-BQ for qemu-devel@nongnu.org; Tue, 09 Oct 2018 08:56:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55444) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9rYP-0004EY-4C for qemu-devel@nongnu.org; Tue, 09 Oct 2018 08:56:01 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 85302307D912; Tue, 9 Oct 2018 12:55:58 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7A666A96D; Tue, 9 Oct 2018 12:55:57 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 13:55:40 +0100 Message-Id: <20181009125541.24455-6-berrange@redhat.com> In-Reply-To: <20181009125541.24455-1-berrange@redhat.com> References: <20181009125541.24455-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 09 Oct 2018 12:55:58 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 5/6] crypto: convert xts_mult_x to use xts_uint128 type X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alberto Garcia Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using 64-bit arithmetic increases the performance for xts-aes-128 when built with gcrypt: Encrypt: 320 MB/s -> 460 MB/s Decrypt: 325 MB/s -> 485 MB/s Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/xts.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/crypto/xts.c b/crypto/xts.c index f109c8a3ee..bba3280746 100644 --- a/crypto/xts.c +++ b/crypto/xts.c @@ -37,19 +37,17 @@ typedef struct { (D)->b =3D (S1)->b ^ (S2)->b; \ } while (0) =20 -static void xts_mult_x(uint8_t *I) +static void xts_mult_x(xts_uint128 *I) { - int x; - uint8_t t, tt; + uint64_t tt; =20 - for (x =3D t =3D 0; x < 16; x++) { - tt =3D I[x] >> 7; - I[x] =3D ((I[x] << 1) | t) & 0xFF; - t =3D tt; - } - if (tt) { - I[0] ^=3D 0x87; + tt =3D I->a >> 63; + I->a =3D I->a << 1; + + if (I->b >> 63) { + I->a ^=3D 0x87; } + I->b =3D (I->b << 1) | tt; } =20 =20 @@ -77,7 +75,7 @@ static void xts_tweak_encdec(const void *ctx, xts_uint128_xor(dst, dst, iv); =20 /* LFSR the tweak */ - xts_mult_x((uint8_t *)iv); + xts_mult_x(iv); } =20 =20 @@ -124,7 +122,7 @@ void xts_decrypt(const void *datactx, if (mo > 0) { xts_uint128 S, D; memcpy(&CC, &T, XTS_BLOCK_SIZE); - xts_mult_x((uint8_t *)&CC); + xts_mult_x(&CC); =20 /* PP =3D tweak decrypt block m-1 */ memcpy(&S, src, XTS_BLOCK_SIZE); --=20 2.17.1 From nobody Thu Nov 6 01:06:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15390900411701003.6333466960955; Tue, 9 Oct 2018 06:00:41 -0700 (PDT) Received: from localhost ([::1]:51302 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9rco-0003oY-4Y for importer@patchew.org; Tue, 09 Oct 2018 09:00:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43997) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9rYV-0000bz-7S for qemu-devel@nongnu.org; Tue, 09 Oct 2018 08:56:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9rYR-0004IS-Aw for qemu-devel@nongnu.org; Tue, 09 Oct 2018 08:56:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54068) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9rYP-0004Ey-8h for qemu-devel@nongnu.org; Tue, 09 Oct 2018 08:56:01 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A76363082E02; Tue, 9 Oct 2018 12:55:59 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE06C7A5E5; Tue, 9 Oct 2018 12:55:58 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 13:55:41 +0100 Message-Id: <20181009125541.24455-7-berrange@redhat.com> In-Reply-To: <20181009125541.24455-1-berrange@redhat.com> References: <20181009125541.24455-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 09 Oct 2018 12:55:59 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 6/6] crypto: annotate xts_tweak_encdec as inlineable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alberto Garcia Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Encouraging the compiler to inline xts_tweak_encdec increases the performance for xts-aes-128 when built with gcrypt: Encrypt: 460 MB/s -> 485 MB/s Decrypt: 485 MB/s -> 505 MB/s Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Alberto Garcia --- crypto/xts.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crypto/xts.c b/crypto/xts.c index bba3280746..02d3bc3f16 100644 --- a/crypto/xts.c +++ b/crypto/xts.c @@ -61,11 +61,11 @@ static void xts_mult_x(xts_uint128 *I) * * Encrypt/decrypt data with a tweak */ -static void xts_tweak_encdec(const void *ctx, - xts_cipher_func *func, - const xts_uint128 *src, - xts_uint128 *dst, - xts_uint128 *iv) +static inline void xts_tweak_encdec(const void *ctx, + xts_cipher_func *func, + const xts_uint128 *src, + xts_uint128 *dst, + xts_uint128 *iv) { /* tweak encrypt block i */ xts_uint128_xor(dst, src, iv); --=20 2.17.1