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