From patchwork Tue Feb 20 07:48:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10229497 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3514260594 for ; Tue, 20 Feb 2018 07:51:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29647284F9 for ; Tue, 20 Feb 2018 07:51:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13E1F2852B; Tue, 20 Feb 2018 07:51:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D4D32852B for ; Tue, 20 Feb 2018 07:51:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751320AbeBTHvl (ORCPT ); Tue, 20 Feb 2018 02:51:41 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:35309 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751252AbeBTHvg (ORCPT ); Tue, 20 Feb 2018 02:51:36 -0500 Received: by mail-pf0-f194.google.com with SMTP id a6so3147638pfi.2 for ; Mon, 19 Feb 2018 23:51:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Yqiubk/aqr16J74w6gyTePD1/wyFCu8q1o40wX3Dt+Y=; b=L430oZxGib3DkcK0OIzQJZYMyXjJZ2lFMmsK1mQhSCOOm/0hwsDm22C/XpHkKauqk0 IihVquOPf4QVr9KsjRXBVK/CmgT4HUPbjEuo891ctzCqRiH+D85V82Z2iPUTHzYWKgLA FUM/B1Dfx2xQG53ShrYfqcx8h5BHPXQcNVsmbkHJEWAYR2r7xrkuDK9/oKyk8Rb1DKsj tjvqkS+DJcL0GG6X/Cm1Ow9epRSwz/WQw0KodwQxrjLrquKEl1KhqagmQbFBhuY9ug9h erW7uuheCoLpaktZsyBOzZXgZAWGktKinXieuqxHehQyVgOM98HQ8WrGqIhDRSrf1RNJ o8RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Yqiubk/aqr16J74w6gyTePD1/wyFCu8q1o40wX3Dt+Y=; b=C2q2nB6PdChEDLsFC8Hq86dkx7OHiUuHLikA5dcbeKkM+yt8czUQMbI3y7DZKnsmr4 SNbYrbcS/TBn4RFFGxQ2H/QidszqNKqeB4ZaPyVDEiAr23Djrc8CsZYbtpulLMHxWJDg NXWb2YKazPrVwtao83Yhhi/jfKrUo1REdI3cJc4ReGXgcPCHl5yjfhtB539m8idJFRaf qgm1wWdBZa3dfQDxG3747KQ+APZt4e//52knId5nwwdtRnvRZ3AefQsF7q0I05ijkjiL Ni5jsyLOxIDzVOV8b6C9fixGUADZRszmtQ4W2VhlNTfST/rFUEiqVGM5TGgbbcyM3wFK XvUw== X-Gm-Message-State: APf1xPAaFvZzjLMz4WC74qrA6ZBLuWc1GR4rHYjsjmAJv085vshyB2BP Bt5OdourQkAaacSTwTE/LxwUeFDL X-Google-Smtp-Source: AH8x227dgiS3ZQplowxtkPwQeFvNP1vZIhxWU4c5IRvN7k4yuUrdcGLfShYVZzxyzQlw5A3STjB18g== X-Received: by 10.98.163.143 with SMTP id q15mr6820081pfl.94.1519113095869; Mon, 19 Feb 2018 23:51:35 -0800 (PST) Received: from zzz.localdomain (c-67-185-97-198.hsd1.wa.comcast.net. [67.185.97.198]) by smtp.gmail.com with ESMTPSA id z17sm16412772pfh.183.2018.02.19.23.51.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Feb 2018 23:51:35 -0800 (PST) From: Eric Biggers To: linux-crypto@vger.kernel.org Cc: Herbert Xu , Jussi Kivilinna , Eric Biggers Subject: [PATCH 09/30] crypto: x86/twofish-3way - remove LRW algorithm Date: Mon, 19 Feb 2018 23:48:07 -0800 Message-Id: <20180220074828.2050-10-ebiggers3@gmail.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180220074828.2050-1-ebiggers3@gmail.com> References: <20180220074828.2050-1-ebiggers3@gmail.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers The LRW 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 LRW code themselves via lrw_crypt(). Remove the lrw-twofish-3way algorithm which did this. Users who request lrw(twofish) and previously would have gotten lrw-twofish-3way will now get lrw(ecb-twofish-3way) instead, which is just as fast. Signed-off-by: Eric Biggers --- arch/x86/crypto/twofish_avx_glue.c | 26 +++++++++++ arch/x86/crypto/twofish_glue_3way.c | 81 +---------------------------------- arch/x86/include/asm/crypto/twofish.h | 11 ----- crypto/Kconfig | 1 - 4 files changed, 27 insertions(+), 92 deletions(-) diff --git a/arch/x86/crypto/twofish_avx_glue.c b/arch/x86/crypto/twofish_avx_glue.c index b7a3904b953c6..3358e23f9ffb9 100644 --- a/arch/x86/crypto/twofish_avx_glue.c +++ b/arch/x86/crypto/twofish_avx_glue.c @@ -262,6 +262,32 @@ static void decrypt_callback(void *priv, u8 *srcdst, unsigned int nbytes) twofish_dec_blk(ctx->ctx, srcdst, srcdst); } +struct twofish_lrw_ctx { + struct lrw_table_ctx lrw_table; + struct twofish_ctx twofish_ctx; +}; + +static int lrw_twofish_setkey(struct crypto_tfm *tfm, const u8 *key, + unsigned int keylen) +{ + struct twofish_lrw_ctx *ctx = crypto_tfm_ctx(tfm); + int err; + + err = __twofish_setkey(&ctx->twofish_ctx, key, keylen - TF_BLOCK_SIZE, + &tfm->crt_flags); + if (err) + return err; + + return lrw_init_table(&ctx->lrw_table, key + keylen - TF_BLOCK_SIZE); +} + +static void lrw_twofish_exit_tfm(struct crypto_tfm *tfm) +{ + struct twofish_lrw_ctx *ctx = crypto_tfm_ctx(tfm); + + lrw_free_table(&ctx->lrw_table); +} + static int lrw_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes) { diff --git a/arch/x86/crypto/twofish_glue_3way.c b/arch/x86/crypto/twofish_glue_3way.c index 243e90a4b5d91..2d6dc5d7f0aaf 100644 --- a/arch/x86/crypto/twofish_glue_3way.c +++ b/arch/x86/crypto/twofish_glue_3way.c @@ -30,7 +30,6 @@ #include #include #include -#include #include EXPORT_SYMBOL_GPL(__twofish_enc_blk_3way); @@ -213,63 +212,6 @@ static void decrypt_callback(void *priv, u8 *srcdst, unsigned int nbytes) twofish_dec_blk(ctx, srcdst, srcdst); } -int lrw_twofish_setkey(struct crypto_tfm *tfm, const u8 *key, - unsigned int keylen) -{ - struct twofish_lrw_ctx *ctx = crypto_tfm_ctx(tfm); - int err; - - err = __twofish_setkey(&ctx->twofish_ctx, key, keylen - TF_BLOCK_SIZE, - &tfm->crt_flags); - if (err) - return err; - - return lrw_init_table(&ctx->lrw_table, key + keylen - TF_BLOCK_SIZE); -} -EXPORT_SYMBOL_GPL(lrw_twofish_setkey); - -static int lrw_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, - struct scatterlist *src, unsigned int nbytes) -{ - struct twofish_lrw_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); - be128 buf[3]; - struct lrw_crypt_req req = { - .tbuf = buf, - .tbuflen = sizeof(buf), - - .table_ctx = &ctx->lrw_table, - .crypt_ctx = &ctx->twofish_ctx, - .crypt_fn = encrypt_callback, - }; - - return lrw_crypt(desc, dst, src, nbytes, &req); -} - -static int lrw_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, - struct scatterlist *src, unsigned int nbytes) -{ - struct twofish_lrw_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); - be128 buf[3]; - struct lrw_crypt_req req = { - .tbuf = buf, - .tbuflen = sizeof(buf), - - .table_ctx = &ctx->lrw_table, - .crypt_ctx = &ctx->twofish_ctx, - .crypt_fn = decrypt_callback, - }; - - return lrw_crypt(desc, dst, src, nbytes, &req); -} - -void lrw_twofish_exit_tfm(struct crypto_tfm *tfm) -{ - struct twofish_lrw_ctx *ctx = crypto_tfm_ctx(tfm); - - lrw_free_table(&ctx->lrw_table); -} -EXPORT_SYMBOL_GPL(lrw_twofish_exit_tfm); - int xts_twofish_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) { @@ -328,7 +270,7 @@ static int xts_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, return xts_crypt(desc, dst, src, nbytes, &req); } -static struct crypto_alg tf_algs[5] = { { +static struct crypto_alg tf_algs[] = { { .cra_name = "ecb(twofish)", .cra_driver_name = "ecb-twofish-3way", .cra_priority = 300, @@ -387,27 +329,6 @@ static struct crypto_alg tf_algs[5] = { { .decrypt = ctr_crypt, }, }, -}, { - .cra_name = "lrw(twofish)", - .cra_driver_name = "lrw-twofish-3way", - .cra_priority = 300, - .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, - .cra_blocksize = TF_BLOCK_SIZE, - .cra_ctxsize = sizeof(struct twofish_lrw_ctx), - .cra_alignmask = 0, - .cra_type = &crypto_blkcipher_type, - .cra_module = THIS_MODULE, - .cra_exit = lrw_twofish_exit_tfm, - .cra_u = { - .blkcipher = { - .min_keysize = TF_MIN_KEY_SIZE + TF_BLOCK_SIZE, - .max_keysize = TF_MAX_KEY_SIZE + TF_BLOCK_SIZE, - .ivsize = TF_BLOCK_SIZE, - .setkey = lrw_twofish_setkey, - .encrypt = lrw_encrypt, - .decrypt = lrw_decrypt, - }, - }, }, { .cra_name = "xts(twofish)", .cra_driver_name = "xts-twofish-3way", diff --git a/arch/x86/include/asm/crypto/twofish.h b/arch/x86/include/asm/crypto/twofish.h index 65bb80adba3ef..3c904116ee002 100644 --- a/arch/x86/include/asm/crypto/twofish.h +++ b/arch/x86/include/asm/crypto/twofish.h @@ -4,14 +4,8 @@ #include #include -#include #include -struct twofish_lrw_ctx { - struct lrw_table_ctx lrw_table; - struct twofish_ctx twofish_ctx; -}; - struct twofish_xts_ctx { struct twofish_ctx tweak_ctx; struct twofish_ctx crypt_ctx; @@ -36,11 +30,6 @@ 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 lrw_twofish_setkey(struct crypto_tfm *tfm, const u8 *key, - unsigned int keylen); - -extern void lrw_twofish_exit_tfm(struct crypto_tfm *tfm); - extern int xts_twofish_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen); diff --git a/crypto/Kconfig b/crypto/Kconfig index 9b81b6f731ddd..fd854fa28072d 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -1570,7 +1570,6 @@ config CRYPTO_TWOFISH_X86_64_3WAY select CRYPTO_TWOFISH_COMMON select CRYPTO_TWOFISH_X86_64 select CRYPTO_GLUE_HELPER_X86 - select CRYPTO_LRW select CRYPTO_XTS help Twofish cipher algorithm (x86_64, 3-way parallel).