Blame SOURCES/kvm-crypto-convert-xts_mult_x-to-use-xts_uint128-type.patch

ae23c9
From 5249fe526e66a92e293bc638ab53eb3d8cd68881 Mon Sep 17 00:00:00 2001
ae23c9
From: "Daniel P. Berrange" <berrange@redhat.com>
ae23c9
Date: Wed, 24 Apr 2019 09:56:40 +0100
ae23c9
Subject: [PATCH 6/9] crypto: convert xts_mult_x to use xts_uint128 type
ae23c9
MIME-Version: 1.0
ae23c9
Content-Type: text/plain; charset=UTF-8
ae23c9
Content-Transfer-Encoding: 8bit
ae23c9
ae23c9
RH-Author: Daniel P. Berrange <berrange@redhat.com>
ae23c9
Message-id: <20190424095643.796-7-berrange@redhat.com>
ae23c9
Patchwork-id: 85879
ae23c9
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH 6/9] crypto: convert xts_mult_x to use xts_uint128 type
ae23c9
Bugzilla: 1680231
ae23c9
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
ae23c9
RH-Acked-by: John Snow <jsnow@redhat.com>
ae23c9
RH-Acked-by: Eric Blake <eblake@redhat.com>
ae23c9
ae23c9
Using 64-bit arithmetic increases the performance for xts-aes-128
ae23c9
when built with gcrypt:
ae23c9
ae23c9
  Encrypt: 355 MB/s -> 545 MB/s
ae23c9
  Decrypt: 362 MB/s -> 568 MB/s
ae23c9
ae23c9
Reviewed-by: Alberto Garcia <berto@igalia.com>
ae23c9
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
ae23c9
(cherry picked from commit 7dac0dd67426753646df0c23c819609b9e704f59)
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 crypto/xts.c | 40 ++++++++++++++++++++++++++++------------
ae23c9
 1 file changed, 28 insertions(+), 12 deletions(-)
ae23c9
ae23c9
diff --git a/crypto/xts.c b/crypto/xts.c
ae23c9
index 0ad231f..10ec83f 100644
ae23c9
--- a/crypto/xts.c
ae23c9
+++ b/crypto/xts.c
ae23c9
@@ -24,6 +24,7 @@
ae23c9
  */
ae23c9
 
ae23c9
 #include "qemu/osdep.h"
ae23c9
+#include "qemu/bswap.h"
ae23c9
 #include "crypto/xts.h"
ae23c9
 
ae23c9
 typedef union {
ae23c9
@@ -39,19 +40,34 @@ static inline void xts_uint128_xor(xts_uint128 *D,
ae23c9
     D->u[1] = S1->u[1] ^ S2->u[1];
ae23c9
 }
ae23c9
 
ae23c9
-static void xts_mult_x(uint8_t *I)
ae23c9
+static inline void xts_uint128_cpu_to_les(xts_uint128 *v)
ae23c9
 {
ae23c9
-    int x;
ae23c9
-    uint8_t t, tt;
ae23c9
+    cpu_to_le64s(&v->u[0]);
ae23c9
+    cpu_to_le64s(&v->u[1]);
ae23c9
+}
ae23c9
 
ae23c9
-    for (x = t = 0; x < 16; x++) {
ae23c9
-        tt = I[x] >> 7;
ae23c9
-        I[x] = ((I[x] << 1) | t) & 0xFF;
ae23c9
-        t = tt;
ae23c9
-    }
ae23c9
-    if (tt) {
ae23c9
-        I[0] ^= 0x87;
ae23c9
+static inline void xts_uint128_le_to_cpus(xts_uint128 *v)
ae23c9
+{
ae23c9
+    le64_to_cpus(&v->u[0]);
ae23c9
+    le64_to_cpus(&v->u[1]);
ae23c9
+}
ae23c9
+
ae23c9
+static void xts_mult_x(xts_uint128 *I)
ae23c9
+{
ae23c9
+    uint64_t tt;
ae23c9
+
ae23c9
+    xts_uint128_le_to_cpus(I);
ae23c9
+
ae23c9
+    tt = I->u[0] >> 63;
ae23c9
+    I->u[0] <<= 1;
ae23c9
+
ae23c9
+    if (I->u[1] >> 63) {
ae23c9
+        I->u[0] ^= 0x87;
ae23c9
     }
ae23c9
+    I->u[1] <<= 1;
ae23c9
+    I->u[1] |= tt;
ae23c9
+
ae23c9
+    xts_uint128_cpu_to_les(I);
ae23c9
 }
ae23c9
 
ae23c9
 
ae23c9
@@ -79,7 +95,7 @@ static void xts_tweak_encdec(const void *ctx,
ae23c9
     xts_uint128_xor(dst, dst, iv);
ae23c9
 
ae23c9
     /* LFSR the tweak */
ae23c9
-    xts_mult_x(iv->b);
ae23c9
+    xts_mult_x(iv);
ae23c9
 }
ae23c9
 
ae23c9
 
ae23c9
@@ -134,7 +150,7 @@ void xts_decrypt(const void *datactx,
ae23c9
     if (mo > 0) {
ae23c9
         xts_uint128 S, D;
ae23c9
         memcpy(&CC, &T, XTS_BLOCK_SIZE);
ae23c9
-        xts_mult_x(CC.b);
ae23c9
+        xts_mult_x(&CC;;
ae23c9
 
ae23c9
         /* PP = tweak decrypt block m-1 */
ae23c9
         memcpy(&S, src, XTS_BLOCK_SIZE);
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9