From nobody Thu Nov 6 10:23:58 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 1540405141048489.45893597815245; Wed, 24 Oct 2018 11:19:01 -0700 (PDT) Received: from localhost ([::1]:49740 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFNkB-00045h-Uf for importer@patchew.org; Wed, 24 Oct 2018 14:18:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45909) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFNaz-00046A-Uo for qemu-devel@nongnu.org; Wed, 24 Oct 2018 14:09:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFNXd-0007Qk-NA for qemu-devel@nongnu.org; Wed, 24 Oct 2018 14:06:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44854) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFNXd-0007P8-GK for qemu-devel@nongnu.org; Wed, 24 Oct 2018 14:06:01 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7E1843D97F; Wed, 24 Oct 2018 18:05:59 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30D6484E7; Wed, 24 Oct 2018 18:05:57 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Wed, 24 Oct 2018 19:05:44 +0100 Message-Id: <20181024180547.20429-6-berrange@redhat.com> In-Reply-To: <20181024180547.20429-1-berrange@redhat.com> References: <20181024180547.20429-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 24 Oct 2018 18:05: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] [PULL 5/8] 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: Peter Maydell 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: 355 MB/s -> 545 MB/s Decrypt: 362 MB/s -> 568 MB/s Reviewed-by: Alberto Garcia Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/xts.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/crypto/xts.c b/crypto/xts.c index 0ad231f3e5..10ec83ff21 100644 --- a/crypto/xts.c +++ b/crypto/xts.c @@ -24,6 +24,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "crypto/xts.h" =20 typedef union { @@ -39,19 +40,34 @@ static inline void xts_uint128_xor(xts_uint128 *D, D->u[1] =3D S1->u[1] ^ S2->u[1]; } =20 -static void xts_mult_x(uint8_t *I) +static inline void xts_uint128_cpu_to_les(xts_uint128 *v) { - int x; - uint8_t t, tt; + cpu_to_le64s(&v->u[0]); + cpu_to_le64s(&v->u[1]); +} =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; +static inline void xts_uint128_le_to_cpus(xts_uint128 *v) +{ + le64_to_cpus(&v->u[0]); + le64_to_cpus(&v->u[1]); +} + +static void xts_mult_x(xts_uint128 *I) +{ + uint64_t tt; + + xts_uint128_le_to_cpus(I); + + tt =3D I->u[0] >> 63; + I->u[0] <<=3D 1; + + if (I->u[1] >> 63) { + I->u[0] ^=3D 0x87; } + I->u[1] <<=3D 1; + I->u[1] |=3D tt; + + xts_uint128_cpu_to_les(I); } =20 =20 @@ -79,7 +95,7 @@ static void xts_tweak_encdec(const void *ctx, xts_uint128_xor(dst, dst, iv); =20 /* LFSR the tweak */ - xts_mult_x(iv->b); + xts_mult_x(iv); } =20 =20 @@ -134,7 +150,7 @@ void xts_decrypt(const void *datactx, if (mo > 0) { xts_uint128 S, D; memcpy(&CC, &T, XTS_BLOCK_SIZE); - xts_mult_x(CC.b); + xts_mult_x(&CC); =20 /* PP =3D tweak decrypt block m-1 */ memcpy(&S, src, XTS_BLOCK_SIZE); --=20 2.17.2