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

383d26
From dfbbe38a74bec140652071dce9dad71514ec7091 Mon Sep 17 00:00:00 2001
383d26
From: "Daniel P. Berrange" <berrange@redhat.com>
383d26
Date: Wed, 24 Apr 2019 10:30:27 +0200
383d26
Subject: [PATCH 08/12] crypto: convert xts_mult_x to use xts_uint128 type
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-7-berrange@redhat.com>
383d26
Patchwork-id: 85895
383d26
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 6/9] crypto: convert xts_mult_x to use xts_uint128 type
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
Using 64-bit arithmetic increases the performance for xts-aes-128
383d26
when built with gcrypt:
383d26
383d26
  Encrypt: 355 MB/s -> 545 MB/s
383d26
  Decrypt: 362 MB/s -> 568 MB/s
383d26
383d26
Reviewed-by: Alberto Garcia <berto@igalia.com>
383d26
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
383d26
(cherry picked from commit 7dac0dd67426753646df0c23c819609b9e704f59)
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 crypto/xts.c | 40 ++++++++++++++++++++++++++++------------
383d26
 1 file changed, 28 insertions(+), 12 deletions(-)
383d26
383d26
diff --git a/crypto/xts.c b/crypto/xts.c
383d26
index 0ad231f..10ec83f 100644
383d26
--- a/crypto/xts.c
383d26
+++ b/crypto/xts.c
383d26
@@ -24,6 +24,7 @@
383d26
  */
383d26
 
383d26
 #include "qemu/osdep.h"
383d26
+#include "qemu/bswap.h"
383d26
 #include "crypto/xts.h"
383d26
 
383d26
 typedef union {
383d26
@@ -39,19 +40,34 @@ static inline void xts_uint128_xor(xts_uint128 *D,
383d26
     D->u[1] = S1->u[1] ^ S2->u[1];
383d26
 }
383d26
 
383d26
-static void xts_mult_x(uint8_t *I)
383d26
+static inline void xts_uint128_cpu_to_les(xts_uint128 *v)
383d26
 {
383d26
-    int x;
383d26
-    uint8_t t, tt;
383d26
+    cpu_to_le64s(&v->u[0]);
383d26
+    cpu_to_le64s(&v->u[1]);
383d26
+}
383d26
 
383d26
-    for (x = t = 0; x < 16; x++) {
383d26
-        tt = I[x] >> 7;
383d26
-        I[x] = ((I[x] << 1) | t) & 0xFF;
383d26
-        t = tt;
383d26
-    }
383d26
-    if (tt) {
383d26
-        I[0] ^= 0x87;
383d26
+static inline void xts_uint128_le_to_cpus(xts_uint128 *v)
383d26
+{
383d26
+    le64_to_cpus(&v->u[0]);
383d26
+    le64_to_cpus(&v->u[1]);
383d26
+}
383d26
+
383d26
+static void xts_mult_x(xts_uint128 *I)
383d26
+{
383d26
+    uint64_t tt;
383d26
+
383d26
+    xts_uint128_le_to_cpus(I);
383d26
+
383d26
+    tt = I->u[0] >> 63;
383d26
+    I->u[0] <<= 1;
383d26
+
383d26
+    if (I->u[1] >> 63) {
383d26
+        I->u[0] ^= 0x87;
383d26
     }
383d26
+    I->u[1] <<= 1;
383d26
+    I->u[1] |= tt;
383d26
+
383d26
+    xts_uint128_cpu_to_les(I);
383d26
 }
383d26
 
383d26
 
383d26
@@ -79,7 +95,7 @@ static void xts_tweak_encdec(const void *ctx,
383d26
     xts_uint128_xor(dst, dst, iv);
383d26
 
383d26
     /* LFSR the tweak */
383d26
-    xts_mult_x(iv->b);
383d26
+    xts_mult_x(iv);
383d26
 }
383d26
 
383d26
 
383d26
@@ -134,7 +150,7 @@ void xts_decrypt(const void *datactx,
383d26
     if (mo > 0) {
383d26
         xts_uint128 S, D;
383d26
         memcpy(&CC, &T, XTS_BLOCK_SIZE);
383d26
-        xts_mult_x(CC.b);
383d26
+        xts_mult_x(&CC;;
383d26
 
383d26
         /* PP = tweak decrypt block m-1 */
383d26
         memcpy(&S, src, XTS_BLOCK_SIZE);
383d26
-- 
383d26
1.8.3.1
383d26