From patchwork Sun Nov 13 16:56:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taehee Yoo X-Patchwork-Id: 624627 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A46E7C4332F for ; Sun, 13 Nov 2022 16:57:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233792AbiKMQ5E (ORCPT ); Sun, 13 Nov 2022 11:57:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231972AbiKMQ5D (ORCPT ); Sun, 13 Nov 2022 11:57:03 -0500 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8642D11C16 for ; Sun, 13 Nov 2022 08:57:02 -0800 (PST) Received: by mail-pg1-x530.google.com with SMTP id v3so8352513pgh.4 for ; Sun, 13 Nov 2022 08:57:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=XnNKd0lfAw9xQy1orqKXmmUAGUez2iUd5ui9HrKTj+M=; b=NSjMV5E0VcM8kSRBB0XhwnKrDhlY+nPasdgQkh6AChyYvcz6SP+kom3zRaYk2F6H1q mdJ2QxgQugpPq9uk80yRW6AsUzrH7f8PG+qd7DWQZWMYCABr7UeF6EUvrMuv7kYcxkJN nQUi4rlSXDx6H/Ag0rKhMujtINSoD1vVq4auhf+dAqAguaOw4iYJQznTlOmFvAltX0F7 Pfqh6l7slm58nAPGWFBZEs0O2HRWKflfHPPqidu7lSn07321VicMyVskHDNEhPsXoFxd 5/EEe5LpuiBeXNKVKqsmwMilGBl1EbVl9BkHTtvdPuo6xREvFUmNBq+hZvHT61uFUGL4 Y8cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XnNKd0lfAw9xQy1orqKXmmUAGUez2iUd5ui9HrKTj+M=; b=yGWMGanofeBjAagH6oq9Pki/XAI77+PmRtn9MH8UFpQxdxwCqUjTrjMMCGwaqHFkGL Ow3kaDzETlTX0RIps4kd2yZvbZWJ0JCY/34WlVV++UU1Lp08wqDAAemANiZYRvduYeCm ailoZDytJ8CsxMGEksCwWj/imwng4FzqzzTsUvgfXWEwXsR/MhOrrwAk51CD//NldLX/ IYtjIyW93Kzu8h7GcgvC0WMj+JnMD0puw4hpe695FD1wfEdLLoRRZ6BuIjAQEIvxvLKo A2mwDKRMhUmVxDpXYDsoqDIVPS59PsOXlbkY2uKmUi/X4OJc8eStB+k/48xcAegWJYdb Ii+g== X-Gm-Message-State: ANoB5pnC2vjRt/LY36Q/C811L8azifVofyZtZaRssK88fd0WXETzZzid v1v9Bl25gKlyGXnmh/yjbn2EHLyzK6dt/w== X-Google-Smtp-Source: AA0mqf4E3qPEbv7qP+sl5c+QbpUUgphg/i5Age5rLnwDvgKKES8jq3rIoiFVzacASz0ESuvmxa6qLA== X-Received: by 2002:a62:180f:0:b0:56b:f23a:7854 with SMTP id 15-20020a62180f000000b0056bf23a7854mr10910024pfy.66.1668358621861; Sun, 13 Nov 2022 08:57:01 -0800 (PST) Received: from localhost.localdomain ([182.213.254.91]) by smtp.gmail.com with ESMTPSA id qi18-20020a17090b275200b001f8c532b93dsm4910477pjb.15.2022.11.13.08.56.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Nov 2022 08:57:01 -0800 (PST) From: Taehee Yoo To: linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au, davem@davemloft.net, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, kirill.shutemov@linux.intel.com, richard@nod.at, viro@zeniv.linux.org.uk, sathyanarayanan.kuppuswamy@linux.intel.com, jpoimboe@kernel.org, elliott@hpe.com, x86@kernel.org, jussi.kivilinna@iki.fi Cc: ap420073@gmail.com Subject: [PATCH v4 1/4] crypto: aria: add keystream array into request ctx Date: Sun, 13 Nov 2022 16:56:42 +0000 Message-Id: <20221113165645.4652-2-ap420073@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221113165645.4652-1-ap420073@gmail.com> References: <20221113165645.4652-1-ap420073@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org avx accelerated aria module used local keystream array. But, keystream array size is too big. So, it puts the keystream array into request ctx. Signed-off-by: Taehee Yoo --- v4: - Add aria_avx_request ctx for keystream array v3: - No changes. v2: - Patch introduced. arch/x86/crypto/aria_aesni_avx_glue.c | 39 ++++++++++++++++++--------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/arch/x86/crypto/aria_aesni_avx_glue.c b/arch/x86/crypto/aria_aesni_avx_glue.c index c561ea4fefa5..5f97e442349f 100644 --- a/arch/x86/crypto/aria_aesni_avx_glue.c +++ b/arch/x86/crypto/aria_aesni_avx_glue.c @@ -33,6 +33,10 @@ asmlinkage void aria_aesni_avx_gfni_ctr_crypt_16way(const void *ctx, u8 *dst, static struct aria_avx_ops aria_ops; +struct aria_avx_request_ctx { + u8 keystream[ARIA_AESNI_PARALLEL_BLOCK_SIZE]; +}; + static int ecb_do_encrypt(struct skcipher_request *req, const u32 *rkey) { ECB_WALK_START(req, ARIA_BLOCK_SIZE, ARIA_AESNI_PARALLEL_BLOCKS); @@ -73,6 +77,7 @@ static int aria_avx_set_key(struct crypto_skcipher *tfm, const u8 *key, static int aria_avx_ctr_encrypt(struct skcipher_request *req) { + struct aria_avx_request_ctx *req_ctx = skcipher_request_ctx(req); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); struct aria_ctx *ctx = crypto_skcipher_ctx(tfm); struct skcipher_walk walk; @@ -86,10 +91,9 @@ static int aria_avx_ctr_encrypt(struct skcipher_request *req) u8 *dst = walk.dst.virt.addr; while (nbytes >= ARIA_AESNI_PARALLEL_BLOCK_SIZE) { - u8 keystream[ARIA_AESNI_PARALLEL_BLOCK_SIZE]; - kernel_fpu_begin(); - aria_ops.aria_ctr_crypt_16way(ctx, dst, src, keystream, + aria_ops.aria_ctr_crypt_16way(ctx, dst, src, + &req_ctx->keystream[0], walk.iv); kernel_fpu_end(); dst += ARIA_AESNI_PARALLEL_BLOCK_SIZE; @@ -98,28 +102,29 @@ static int aria_avx_ctr_encrypt(struct skcipher_request *req) } while (nbytes >= ARIA_BLOCK_SIZE) { - u8 keystream[ARIA_BLOCK_SIZE]; - - memcpy(keystream, walk.iv, ARIA_BLOCK_SIZE); + memcpy(&req_ctx->keystream[0], walk.iv, ARIA_BLOCK_SIZE); crypto_inc(walk.iv, ARIA_BLOCK_SIZE); - aria_encrypt(ctx, keystream, keystream); + aria_encrypt(ctx, &req_ctx->keystream[0], + &req_ctx->keystream[0]); - crypto_xor_cpy(dst, src, keystream, ARIA_BLOCK_SIZE); + crypto_xor_cpy(dst, src, &req_ctx->keystream[0], + ARIA_BLOCK_SIZE); dst += ARIA_BLOCK_SIZE; src += ARIA_BLOCK_SIZE; nbytes -= ARIA_BLOCK_SIZE; } if (walk.nbytes == walk.total && nbytes > 0) { - u8 keystream[ARIA_BLOCK_SIZE]; - - memcpy(keystream, walk.iv, ARIA_BLOCK_SIZE); + memcpy(&req_ctx->keystream[0], walk.iv, + ARIA_BLOCK_SIZE); crypto_inc(walk.iv, ARIA_BLOCK_SIZE); - aria_encrypt(ctx, keystream, keystream); + aria_encrypt(ctx, &req_ctx->keystream[0], + &req_ctx->keystream[0]); - crypto_xor_cpy(dst, src, keystream, nbytes); + crypto_xor_cpy(dst, src, &req_ctx->keystream[0], + nbytes); dst += nbytes; src += nbytes; nbytes = 0; @@ -130,6 +135,13 @@ static int aria_avx_ctr_encrypt(struct skcipher_request *req) return err; } +static int aria_avx_init_tfm(struct crypto_skcipher *tfm) +{ + crypto_skcipher_set_reqsize(tfm, sizeof(struct aria_avx_request_ctx)); + + return 0; +} + static struct skcipher_alg aria_algs[] = { { .base.cra_name = "__ecb(aria)", @@ -160,6 +172,7 @@ static struct skcipher_alg aria_algs[] = { .setkey = aria_avx_set_key, .encrypt = aria_avx_ctr_encrypt, .decrypt = aria_avx_ctr_encrypt, + .init = aria_avx_init_tfm, } };