summaryrefslogtreecommitdiffstats
path: root/arch/x86/crypto/twofish_avx_glue.c
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2018-02-19 23:48:08 -0800
committerHerbert Xu <herbert@gondor.apana.org.au>2018-03-03 00:03:24 +0800
commitebeea983dd185a29e237ce1a5217fa7196cf64ad (patch)
tree5c2ee37efb487c233265d072f69f727a757896b8 /arch/x86/crypto/twofish_avx_glue.c
parent68bfc4924b536ed052198121aef01c525ff6831d (diff)
downloadop-kernel-dev-ebeea983dd185a29e237ce1a5217fa7196cf64ad.zip
op-kernel-dev-ebeea983dd185a29e237ce1a5217fa7196cf64ad.tar.gz
crypto: x86/twofish-3way - remove XTS algorithm
The XTS template now wraps an ECB mode algorithm rather than the block cipher directly. Therefore it is now redundant for crypto modules to wrap their ECB code with generic XTS code themselves via xts_crypt(). Remove the xts-twofish-3way algorithm which did this. Users who request xts(twofish) and previously would have gotten xts-twofish-3way will now get xts(ecb-twofish-3way) instead, which is just as fast. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'arch/x86/crypto/twofish_avx_glue.c')
-rw-r--r--arch/x86/crypto/twofish_avx_glue.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/arch/x86/crypto/twofish_avx_glue.c b/arch/x86/crypto/twofish_avx_glue.c
index 3358e23..3750b2c 100644
--- a/arch/x86/crypto/twofish_avx_glue.c
+++ b/arch/x86/crypto/twofish_avx_glue.c
@@ -79,6 +79,31 @@ static void twofish_xts_dec(void *ctx, u128 *dst, const u128 *src, le128 *iv)
GLUE_FUNC_CAST(twofish_dec_blk));
}
+struct twofish_xts_ctx {
+ struct twofish_ctx tweak_ctx;
+ struct twofish_ctx crypt_ctx;
+};
+
+static int xts_twofish_setkey(struct crypto_tfm *tfm, const u8 *key,
+ unsigned int keylen)
+{
+ struct twofish_xts_ctx *ctx = crypto_tfm_ctx(tfm);
+ u32 *flags = &tfm->crt_flags;
+ int err;
+
+ err = xts_check_key(tfm, key, keylen);
+ if (err)
+ return err;
+
+ /* first half of xts-key is for crypt */
+ err = __twofish_setkey(&ctx->crypt_ctx, key, keylen / 2, flags);
+ if (err)
+ return err;
+
+ /* second half of xts-key is for tweak */
+ return __twofish_setkey(&ctx->tweak_ctx, key + keylen / 2, keylen / 2,
+ flags);
+}
static const struct common_glue_ctx twofish_enc = {
.num_funcs = 3,
OpenPOWER on IntegriCloud