crypto: x86/twofish-3way - remove XTS algorithm
authorEric Biggers <ebiggers@google.com>
Tue, 20 Feb 2018 07:48:08 +0000 (23:48 -0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 2 Mar 2018 16:03:24 +0000 (00:03 +0800)
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>
arch/x86/crypto/twofish_avx_glue.c
arch/x86/crypto/twofish_glue_3way.c
arch/x86/include/asm/crypto/twofish.h
crypto/Kconfig

index 3358e23f9ffb9bb75daf91d9c8003840680017db..3750b2cd3019770e76e1a33e90208aeca897883e 100644 (file)
@@ -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,
index 2d6dc5d7f0aaf8ffc4698a1eca27997e9b5e5dc4..bdbd2f6ab9d7fc2fc8003f982f20189a29925e7f 100644 (file)
@@ -30,7 +30,6 @@
 #include <crypto/b128ops.h>
 #include <asm/crypto/twofish.h>
 #include <asm/crypto/glue_helper.h>
-#include <crypto/xts.h>
 
 EXPORT_SYMBOL_GPL(__twofish_enc_blk_3way);
 EXPORT_SYMBOL_GPL(twofish_dec_blk_3way);
@@ -182,94 +181,6 @@ static int ctr_crypt(struct blkcipher_desc *desc, struct scatterlist *dst,
        return glue_ctr_crypt_128bit(&twofish_ctr, desc, dst, src, nbytes);
 }
 
-static void encrypt_callback(void *priv, u8 *srcdst, unsigned int nbytes)
-{
-       const unsigned int bsize = TF_BLOCK_SIZE;
-       struct twofish_ctx *ctx = priv;
-       int i;
-
-       if (nbytes == 3 * bsize) {
-               twofish_enc_blk_3way(ctx, srcdst, srcdst);
-               return;
-       }
-
-       for (i = 0; i < nbytes / bsize; i++, srcdst += bsize)
-               twofish_enc_blk(ctx, srcdst, srcdst);
-}
-
-static void decrypt_callback(void *priv, u8 *srcdst, unsigned int nbytes)
-{
-       const unsigned int bsize = TF_BLOCK_SIZE;
-       struct twofish_ctx *ctx = priv;
-       int i;
-
-       if (nbytes == 3 * bsize) {
-               twofish_dec_blk_3way(ctx, srcdst, srcdst);
-               return;
-       }
-
-       for (i = 0; i < nbytes / bsize; i++, srcdst += bsize)
-               twofish_dec_blk(ctx, srcdst, srcdst);
-}
-
-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);
-}
-EXPORT_SYMBOL_GPL(xts_twofish_setkey);
-
-static int xts_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
-                      struct scatterlist *src, unsigned int nbytes)
-{
-       struct twofish_xts_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
-       le128 buf[3];
-       struct xts_crypt_req req = {
-               .tbuf = buf,
-               .tbuflen = sizeof(buf),
-
-               .tweak_ctx = &ctx->tweak_ctx,
-               .tweak_fn = XTS_TWEAK_CAST(twofish_enc_blk),
-               .crypt_ctx = &ctx->crypt_ctx,
-               .crypt_fn = encrypt_callback,
-       };
-
-       return xts_crypt(desc, dst, src, nbytes, &req);
-}
-
-static int xts_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
-                      struct scatterlist *src, unsigned int nbytes)
-{
-       struct twofish_xts_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
-       le128 buf[3];
-       struct xts_crypt_req req = {
-               .tbuf = buf,
-               .tbuflen = sizeof(buf),
-
-               .tweak_ctx = &ctx->tweak_ctx,
-               .tweak_fn = XTS_TWEAK_CAST(twofish_enc_blk),
-               .crypt_ctx = &ctx->crypt_ctx,
-               .crypt_fn = decrypt_callback,
-       };
-
-       return xts_crypt(desc, dst, src, nbytes, &req);
-}
-
 static struct crypto_alg tf_algs[] = { {
        .cra_name               = "ecb(twofish)",
        .cra_driver_name        = "ecb-twofish-3way",
@@ -329,26 +240,6 @@ static struct crypto_alg tf_algs[] = { {
                        .decrypt        = ctr_crypt,
                },
        },
-}, {
-       .cra_name               = "xts(twofish)",
-       .cra_driver_name        = "xts-twofish-3way",
-       .cra_priority           = 300,
-       .cra_flags              = CRYPTO_ALG_TYPE_BLKCIPHER,
-       .cra_blocksize          = TF_BLOCK_SIZE,
-       .cra_ctxsize            = sizeof(struct twofish_xts_ctx),
-       .cra_alignmask          = 0,
-       .cra_type               = &crypto_blkcipher_type,
-       .cra_module             = THIS_MODULE,
-       .cra_u = {
-               .blkcipher = {
-                       .min_keysize    = TF_MIN_KEY_SIZE * 2,
-                       .max_keysize    = TF_MAX_KEY_SIZE * 2,
-                       .ivsize         = TF_BLOCK_SIZE,
-                       .setkey         = xts_twofish_setkey,
-                       .encrypt        = xts_encrypt,
-                       .decrypt        = xts_decrypt,
-               },
-       },
 } };
 
 static bool is_blacklisted_cpu(void)
index 3c904116ee002114068f42406e7f016a3f45e009..f618bf272b900b1992f0ca2c2381d4d6d20d8900 100644 (file)
@@ -6,11 +6,6 @@
 #include <crypto/twofish.h>
 #include <crypto/b128ops.h>
 
-struct twofish_xts_ctx {
-       struct twofish_ctx tweak_ctx;
-       struct twofish_ctx crypt_ctx;
-};
-
 /* regular block cipher functions from twofish_x86_64 module */
 asmlinkage void twofish_enc_blk(struct twofish_ctx *ctx, u8 *dst,
                                const u8 *src);
@@ -30,7 +25,4 @@ extern void twofish_enc_blk_ctr(void *ctx, u128 *dst, const u128 *src,
 extern void twofish_enc_blk_ctr_3way(void *ctx, u128 *dst, const u128 *src,
                                     le128 *iv);
 
-extern int xts_twofish_setkey(struct crypto_tfm *tfm, const u8 *key,
-                             unsigned int keylen);
-
 #endif /* ASM_X86_TWOFISH_H */
index eba78fa8514705b41755558ed7c63ed2ab3cd87d..6a18aa26bbc787b4d81c767ff3f46bbea3fd81ba 100644 (file)
@@ -1584,7 +1584,6 @@ config CRYPTO_TWOFISH_X86_64_3WAY
        select CRYPTO_TWOFISH_COMMON
        select CRYPTO_TWOFISH_X86_64
        select CRYPTO_GLUE_HELPER_X86
-       select CRYPTO_XTS
        help
          Twofish cipher algorithm (x86_64, 3-way parallel).