From patchwork Mon May 6 19:19:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Moreira X-Patchwork-Id: 10931871 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E76E13AD for ; Mon, 6 May 2019 19:20:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7ED92286F7 for ; Mon, 6 May 2019 19:20:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 727A02888E; Mon, 6 May 2019 19:20:44 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 152DA286F7 for ; Mon, 6 May 2019 19:20:42 +0000 (UTC) Received: (qmail 9448 invoked by uid 550); 6 May 2019 19:20:22 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 9374 invoked from network); 6 May 2019 19:20:21 -0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Joao Moreira To: kernel-hardening@lists.openwall.com Cc: linux-kernel@vger.kernel.org, x86@kernel.org, herbert@gondor.apana.org.au, davem@davemloft.net, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, gregkh@linuxfoundation.org, keescook@chromium.org Subject: [RFC PATCH v2 3/4] Fix twofish crypto functions prototype casts Date: Mon, 6 May 2019 16:19:49 -0300 Message-Id: <20190506191950.9521-4-jmoreira@suse.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190506191950.9521-1-jmoreira@suse.de> References: <20190506191950.9521-1-jmoreira@suse.de> X-Virus-Scanned: ClamAV using ClamSMTP Add macros that generate glue functions for twofish crypto functions. Remove GLUE_FUNC_CAST macros from function pointer assignement and use the helper instead, making the prototypes compliant. RFC: twofish_enc_blk_ctr_3way is assigned both to .ecb and to .ctr, what makes its declaration through the macro undoable, as thought in this patch. Suggestions on how to fix this are welcome. Signed-off-by: Joao Moreira --- arch/x86/crypto/twofish_avx_glue.c | 65 ++++++++++++++++------------------- arch/x86/crypto/twofish_glue_3way.c | 33 +++++++++--------- arch/x86/include/asm/crypto/twofish.h | 33 +++++++++++++----- 3 files changed, 71 insertions(+), 60 deletions(-) diff --git a/arch/x86/crypto/twofish_avx_glue.c b/arch/x86/crypto/twofish_avx_glue.c index 66d989230d10..e895096fbc3b 100644 --- a/arch/x86/crypto/twofish_avx_glue.c +++ b/arch/x86/crypto/twofish_avx_glue.c @@ -37,20 +37,19 @@ #define TWOFISH_PARALLEL_BLOCKS 8 /* 8-way parallel cipher functions */ -asmlinkage void twofish_ecb_enc_8way(struct twofish_ctx *ctx, u8 *dst, - const u8 *src); -asmlinkage void twofish_ecb_dec_8way(struct twofish_ctx *ctx, u8 *dst, - const u8 *src); +TWOFISH_GLUE(twofish_ecb_enc_8way, twofish_ecb_enc_8way_glue); +TWOFISH_GLUE(twofish_ecb_dec_8way, twofish_ecb_dec_8way_glue); +TWOFISH_GLUE_CTR(twofish_ctr_8way, twofish_ctr_8way_glue); +TWOFISH_GLUE_CTR(twofish_enc_blk_ctr, twofish_enc_blk_ctr_glue); +TWOFISH_GLUE_XTS(twofish_xts_enc_8way, twofish_xts_enc_8way_glue); +TWOFISH_GLUE_XTS(twofish_xts_dec_8way, twofish_xts_dec_8way_glue); +TWOFISH_GLUE_CBC(twofish_cbc_dec_8way, twofish_cbc_dec_8way_glue); asmlinkage void twofish_cbc_dec_8way(struct twofish_ctx *ctx, u8 *dst, const u8 *src); -asmlinkage void twofish_ctr_8way(struct twofish_ctx *ctx, u8 *dst, - const u8 *src, le128 *iv); -asmlinkage void twofish_xts_enc_8way(struct twofish_ctx *ctx, u8 *dst, - const u8 *src, le128 *iv); -asmlinkage void twofish_xts_dec_8way(struct twofish_ctx *ctx, u8 *dst, - const u8 *src, le128 *iv); +asmlinkage void twofish_xts_dec_8way(struct twofish_ctx *ctx, u128 *dst, + const u128 *src, le128 *iv); static int twofish_setkey_skcipher(struct crypto_skcipher *tfm, const u8 *key, unsigned int keylen) @@ -58,22 +57,19 @@ static int twofish_setkey_skcipher(struct crypto_skcipher *tfm, return twofish_setkey(&tfm->base, key, keylen); } -static inline void twofish_enc_blk_3way(struct twofish_ctx *ctx, u8 *dst, - const u8 *src) +static inline void twofish_enc_blk_3way(void *ctx, u8 *dst, const u8 *src) { - __twofish_enc_blk_3way(ctx, dst, src, false); + __twofish_enc_blk_3way((struct twofish_ctx *) ctx, dst, src, false); } static void twofish_xts_enc(void *ctx, u128 *dst, const u128 *src, le128 *iv) { - glue_xts_crypt_128bit_one(ctx, dst, src, iv, - GLUE_FUNC_CAST(twofish_enc_blk)); + glue_xts_crypt_128bit_one(ctx, dst, src, iv, twofish_enc_blk_glue); } static void twofish_xts_dec(void *ctx, u128 *dst, const u128 *src, le128 *iv) { - glue_xts_crypt_128bit_one(ctx, dst, src, iv, - GLUE_FUNC_CAST(twofish_dec_blk)); + glue_xts_crypt_128bit_one(ctx, dst, src, iv, twofish_dec_blk_glue); } struct twofish_xts_ctx { @@ -108,13 +104,13 @@ static const struct common_glue_ctx twofish_enc = { .funcs = { { .num_blocks = TWOFISH_PARALLEL_BLOCKS, - .fn_u = { .ecb = GLUE_FUNC_CAST(twofish_ecb_enc_8way) } + .fn_u = { .ecb = twofish_ecb_enc_8way_glue } }, { .num_blocks = 3, - .fn_u = { .ecb = GLUE_FUNC_CAST(twofish_enc_blk_3way) } + .fn_u = { .ecb = twofish_enc_blk_3way } }, { .num_blocks = 1, - .fn_u = { .ecb = GLUE_FUNC_CAST(twofish_enc_blk) } + .fn_u = { .ecb = twofish_enc_blk_glue } } } }; @@ -124,13 +120,13 @@ static const struct common_glue_ctx twofish_ctr = { .funcs = { { .num_blocks = TWOFISH_PARALLEL_BLOCKS, - .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(twofish_ctr_8way) } + .fn_u = { .ctr = twofish_ctr_8way_glue } }, { .num_blocks = 3, - .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(twofish_enc_blk_ctr_3way) } + .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(twofish_enc_blk_ctr_3way)} }, { .num_blocks = 1, - .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(twofish_enc_blk_ctr) } + .fn_u = { .ctr = twofish_enc_blk_ctr_glue } } } }; @@ -140,10 +136,10 @@ static const struct common_glue_ctx twofish_enc_xts = { .funcs = { { .num_blocks = TWOFISH_PARALLEL_BLOCKS, - .fn_u = { .xts = GLUE_XTS_FUNC_CAST(twofish_xts_enc_8way) } + .fn_u = { .xts = twofish_xts_enc_8way_glue } }, { .num_blocks = 1, - .fn_u = { .xts = GLUE_XTS_FUNC_CAST(twofish_xts_enc) } + .fn_u = { .xts = twofish_xts_enc } } } }; @@ -153,13 +149,13 @@ static const struct common_glue_ctx twofish_dec = { .funcs = { { .num_blocks = TWOFISH_PARALLEL_BLOCKS, - .fn_u = { .ecb = GLUE_FUNC_CAST(twofish_ecb_dec_8way) } + .fn_u = { .ecb = twofish_ecb_dec_8way_glue } }, { .num_blocks = 3, - .fn_u = { .ecb = GLUE_FUNC_CAST(twofish_dec_blk_3way) } + .fn_u = { .ecb = twofish_dec_blk_3way_glue } }, { .num_blocks = 1, - .fn_u = { .ecb = GLUE_FUNC_CAST(twofish_dec_blk) } + .fn_u = { .ecb = twofish_dec_blk_glue } } } }; @@ -169,13 +165,13 @@ static const struct common_glue_ctx twofish_dec_cbc = { .funcs = { { .num_blocks = TWOFISH_PARALLEL_BLOCKS, - .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(twofish_cbc_dec_8way) } + .fn_u = { .cbc = twofish_cbc_dec_8way_glue } }, { .num_blocks = 3, - .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(twofish_dec_blk_cbc_3way) } + .fn_u = { .cbc = twofish_dec_blk_cbc_3way } }, { .num_blocks = 1, - .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(twofish_dec_blk) } + .fn_u = { .cbc = twofish_dec_blk_cbc_glue } } } }; @@ -185,10 +181,10 @@ static const struct common_glue_ctx twofish_dec_xts = { .funcs = { { .num_blocks = TWOFISH_PARALLEL_BLOCKS, - .fn_u = { .xts = GLUE_XTS_FUNC_CAST(twofish_xts_dec_8way) } + .fn_u = { .xts = twofish_xts_dec_8way_glue } }, { .num_blocks = 1, - .fn_u = { .xts = GLUE_XTS_FUNC_CAST(twofish_xts_dec) } + .fn_u = { .xts = twofish_xts_dec } } } }; @@ -204,8 +200,7 @@ static int ecb_decrypt(struct skcipher_request *req) static int cbc_encrypt(struct skcipher_request *req) { - return glue_cbc_encrypt_req_128bit(GLUE_FUNC_CAST(twofish_enc_blk), - req); + return glue_cbc_encrypt_req_128bit(twofish_enc_blk_glue, req); } static int cbc_decrypt(struct skcipher_request *req) diff --git a/arch/x86/crypto/twofish_glue_3way.c b/arch/x86/crypto/twofish_glue_3way.c index 571485502ec8..0b10c5b3f486 100644 --- a/arch/x86/crypto/twofish_glue_3way.c +++ b/arch/x86/crypto/twofish_glue_3way.c @@ -31,6 +31,8 @@ #include #include +TWOFISH_GLUE_CTR(twofish_enc_blk_ctr, twofish_enc_blk_ctr_glue) + EXPORT_SYMBOL_GPL(__twofish_enc_blk_3way); EXPORT_SYMBOL_GPL(twofish_dec_blk_3way); @@ -40,10 +42,9 @@ static int twofish_setkey_skcipher(struct crypto_skcipher *tfm, return twofish_setkey(&tfm->base, key, keylen); } -static inline void twofish_enc_blk_3way(struct twofish_ctx *ctx, u8 *dst, - const u8 *src) +static inline void twofish_enc_blk_3way(void *ctx, u8 *dst, const u8 *src) { - __twofish_enc_blk_3way(ctx, dst, src, false); + __twofish_enc_blk_3way((struct twofish_ctx *) ctx, dst, src, false); } static inline void twofish_enc_blk_xor_3way(struct twofish_ctx *ctx, u8 *dst, @@ -66,7 +67,8 @@ void twofish_dec_blk_cbc_3way(void *ctx, u128 *dst, const u128 *src) } EXPORT_SYMBOL_GPL(twofish_dec_blk_cbc_3way); -void twofish_enc_blk_ctr(void *ctx, u128 *dst, const u128 *src, le128 *iv) +void twofish_enc_blk_ctr(struct twofish_ctx *ctx, u128 *dst, const u128 *src, + le128 *iv) { be128 ctrblk; @@ -81,8 +83,8 @@ void twofish_enc_blk_ctr(void *ctx, u128 *dst, const u128 *src, le128 *iv) } EXPORT_SYMBOL_GPL(twofish_enc_blk_ctr); -void twofish_enc_blk_ctr_3way(void *ctx, u128 *dst, const u128 *src, - le128 *iv) +void twofish_enc_blk_ctr_3way(void *ctx, u128 *dst, + const u128 *src, le128 *iv) { be128 ctrblks[3]; @@ -109,10 +111,10 @@ static const struct common_glue_ctx twofish_enc = { .funcs = { { .num_blocks = 3, - .fn_u = { .ecb = GLUE_FUNC_CAST(twofish_enc_blk_3way) } + .fn_u = { .ecb = twofish_enc_blk_3way } }, { .num_blocks = 1, - .fn_u = { .ecb = GLUE_FUNC_CAST(twofish_enc_blk) } + .fn_u = { .ecb = twofish_enc_blk_glue } } } }; @@ -122,10 +124,10 @@ static const struct common_glue_ctx twofish_ctr = { .funcs = { { .num_blocks = 3, - .fn_u = { .ecb = GLUE_FUNC_CAST(twofish_enc_blk_ctr_3way) } + .fn_u = { .ecb = GLUE_FUNC_CAST(twofish_enc_blk_ctr_3way)} }, { .num_blocks = 1, - .fn_u = { .ecb = GLUE_FUNC_CAST(twofish_enc_blk_ctr) } + .fn_u = { .ecb = GLUE_FUNC_CAST(twofish_enc_blk_ctr)} } } }; @@ -135,10 +137,10 @@ static const struct common_glue_ctx twofish_dec = { .funcs = { { .num_blocks = 3, - .fn_u = { .ecb = GLUE_FUNC_CAST(twofish_dec_blk_3way) } + .fn_u = { .ecb = twofish_dec_blk_3way_glue} }, { .num_blocks = 1, - .fn_u = { .ecb = GLUE_FUNC_CAST(twofish_dec_blk) } + .fn_u = { .ecb = twofish_dec_blk_glue} } } }; @@ -148,10 +150,10 @@ static const struct common_glue_ctx twofish_dec_cbc = { .funcs = { { .num_blocks = 3, - .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(twofish_dec_blk_cbc_3way) } + .fn_u = { .cbc = twofish_dec_blk_cbc_3way } }, { .num_blocks = 1, - .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(twofish_dec_blk) } + .fn_u = { .cbc = twofish_dec_blk_cbc_glue } } } }; @@ -167,8 +169,7 @@ static int ecb_decrypt(struct skcipher_request *req) static int cbc_encrypt(struct skcipher_request *req) { - return glue_cbc_encrypt_req_128bit(GLUE_FUNC_CAST(twofish_enc_blk), - req); + return glue_cbc_encrypt_req_128bit(twofish_enc_blk_glue, req); } static int cbc_decrypt(struct skcipher_request *req) diff --git a/arch/x86/include/asm/crypto/twofish.h b/arch/x86/include/asm/crypto/twofish.h index f618bf272b90..fe52a06a734a 100644 --- a/arch/x86/include/asm/crypto/twofish.h +++ b/arch/x86/include/asm/crypto/twofish.h @@ -6,22 +6,37 @@ #include #include -/* regular block cipher functions from twofish_x86_64 module */ -asmlinkage void twofish_enc_blk(struct twofish_ctx *ctx, u8 *dst, - const u8 *src); -asmlinkage void twofish_dec_blk(struct twofish_ctx *ctx, u8 *dst, - const u8 *src); +#define TWOFISH_GLUE(func, helper) \ +asmlinkage void func(struct twofish_ctx *ctx, u8 *dst, const u8 *src); \ +asmlinkage static inline void helper(void *ctx, u8 *dst, const u8 *src) \ +{ func((struct twofish_ctx *) ctx, dst, src); } + +#define TWOFISH_GLUE_CBC(func, helper) \ +asmlinkage void func(struct twofish_ctx *ctx, u8 *dst, const u8 *src); \ +asmlinkage static inline void helper(void *ctx, u128 *dst, \ + const u128 *src) \ +{ func((struct twofish_ctx *) ctx, (u8 *) dst, (u8 *) src); } + +#define TWOFISH_GLUE_CTR(func, helper) \ +asmlinkage void func(struct twofish_ctx *ctx, u128 *dst, const u128 *src, \ + le128 *iv); \ +asmlinkage static inline void helper(void *ctx, u128 *dst, \ + const u128 *src, le128 *iv) \ +{ func((struct twofish_ctx *) ctx, dst, src, iv); } + +#define TWOFISH_GLUE_XTS(func, helper) TWOFISH_GLUE_CTR(func, helper) + +TWOFISH_GLUE(twofish_enc_blk, twofish_enc_blk_glue); +TWOFISH_GLUE(twofish_dec_blk, twofish_dec_blk_glue); +TWOFISH_GLUE_CBC(twofish_dec_blk, twofish_dec_blk_cbc_glue); +TWOFISH_GLUE(twofish_dec_blk_3way, twofish_dec_blk_3way_glue) /* 3-way parallel cipher functions */ asmlinkage void __twofish_enc_blk_3way(struct twofish_ctx *ctx, u8 *dst, const u8 *src, bool xor); -asmlinkage void twofish_dec_blk_3way(struct twofish_ctx *ctx, u8 *dst, - const u8 *src); /* helpers from twofish_x86_64-3way module */ extern void twofish_dec_blk_cbc_3way(void *ctx, u128 *dst, const u128 *src); -extern void twofish_enc_blk_ctr(void *ctx, u128 *dst, const u128 *src, - le128 *iv); extern void twofish_enc_blk_ctr_3way(void *ctx, u128 *dst, const u128 *src, le128 *iv);