From: "Daniel P. Berrangé" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Daniel P. Berrangé" <berrange@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>
Subject: [Qemu-devel] [PULL 5/8] crypto: convert xts_mult_x to use xts_uint128 type
Date: Wed, 24 Oct 2018 19:05:44 +0100 [thread overview]
Message-ID: <20181024180547.20429-6-berrange@redhat.com> (raw)
In-Reply-To: <20181024180547.20429-1-berrange@redhat.com>
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 <berto@igalia.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
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 @@
*/
#include "qemu/osdep.h"
+#include "qemu/bswap.h"
#include "crypto/xts.h"
typedef union {
@@ -39,19 +40,34 @@ static inline void xts_uint128_xor(xts_uint128 *D,
D->u[1] = S1->u[1] ^ S2->u[1];
}
-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]);
+}
- for (x = t = 0; x < 16; x++) {
- tt = I[x] >> 7;
- I[x] = ((I[x] << 1) | t) & 0xFF;
- t = tt;
- }
- if (tt) {
- I[0] ^= 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 = I->u[0] >> 63;
+ I->u[0] <<= 1;
+
+ if (I->u[1] >> 63) {
+ I->u[0] ^= 0x87;
}
+ I->u[1] <<= 1;
+ I->u[1] |= tt;
+
+ xts_uint128_cpu_to_les(I);
}
@@ -79,7 +95,7 @@ static void xts_tweak_encdec(const void *ctx,
xts_uint128_xor(dst, dst, iv);
/* LFSR the tweak */
- xts_mult_x(iv->b);
+ xts_mult_x(iv);
}
@@ -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);
/* PP = tweak decrypt block m-1 */
memcpy(&S, src, XTS_BLOCK_SIZE);
--
2.17.2
next prev parent reply other threads:[~2018-10-24 18:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-24 18:05 [Qemu-devel] [PULL 0/8] Qcrypto next patches Daniel P. Berrangé
2018-10-24 18:05 ` [Qemu-devel] [PULL 1/8] crypto: expand algorithm coverage for cipher benchmark Daniel P. Berrangé
2018-10-24 18:05 ` [Qemu-devel] [PULL 2/8] crypto: remove code duplication in tweak encrypt/decrypt Daniel P. Berrangé
2018-10-24 18:05 ` [Qemu-devel] [PULL 3/8] crypto: introduce a xts_uint128 data type Daniel P. Berrangé
2018-10-24 18:05 ` [Qemu-devel] [PULL 4/8] crypto: convert xts_tweak_encdec to use xts_uint128 type Daniel P. Berrangé
2018-10-24 18:05 ` Daniel P. Berrangé [this message]
2018-10-24 18:05 ` [Qemu-devel] [PULL 6/8] crypto: annotate xts_tweak_encdec as inlineable Daniel P. Berrangé
2018-10-24 18:05 ` [Qemu-devel] [PULL 7/8] crypto: refactor XTS cipher mode test suite Daniel P. Berrangé
2018-10-24 18:05 ` [Qemu-devel] [PULL 8/8] crypto: add testing for unaligned buffers with XTS cipher mode Daniel P. Berrangé
2018-10-25 16:41 ` [Qemu-devel] [PULL 0/8] Qcrypto next patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181024180547.20429-6-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).