All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Jerry Shih <jerry.shih@sifive.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>,
	palmer@dabbelt.com, Albert Ou <aou@eecs.berkeley.edu>,
	herbert@gondor.apana.org.au, davem@davemloft.net,
	conor.dooley@microchip.com, ardb@kernel.org, heiko@sntech.de,
	phoebe.chen@sifive.com, hongrong.hsu@sifive.com,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-crypto@vger.kernel.org
Subject: Re: [PATCH v2 05/13] crypto: simd - Update `walksize` in simd skcipher
Date: Tue, 28 Nov 2023 09:22:04 -0800	[thread overview]
Message-ID: <20231128172204.GB1148@sol.localdomain> (raw)
In-Reply-To: <56F07E23-CA7D-466B-84C7-643F2839E199@sifive.com>

On Tue, Nov 28, 2023 at 01:38:29PM +0800, Jerry Shih wrote:
> On Nov 28, 2023, at 11:58, Eric Biggers <ebiggers@kernel.org> wrote:
> > On Mon, Nov 27, 2023 at 03:06:55PM +0800, Jerry Shih wrote:
> >> The `walksize` assignment is missed in simd skcipher.
> >> 
> >> Signed-off-by: Jerry Shih <jerry.shih@sifive.com>
> >> ---
> >> crypto/cryptd.c | 1 +
> >> crypto/simd.c   | 1 +
> >> 2 files changed, 2 insertions(+)
> >> 
> >> diff --git a/crypto/cryptd.c b/crypto/cryptd.c
> >> index bbcc368b6a55..253d13504ccb 100644
> >> --- a/crypto/cryptd.c
> >> +++ b/crypto/cryptd.c
> >> @@ -405,6 +405,7 @@ static int cryptd_create_skcipher(struct crypto_template *tmpl,
> >> 		(alg->base.cra_flags & CRYPTO_ALG_INTERNAL);
> >> 	inst->alg.ivsize = crypto_skcipher_alg_ivsize(alg);
> >> 	inst->alg.chunksize = crypto_skcipher_alg_chunksize(alg);
> >> +	inst->alg.walksize = crypto_skcipher_alg_walksize(alg);
> >> 	inst->alg.min_keysize = crypto_skcipher_alg_min_keysize(alg);
> >> 	inst->alg.max_keysize = crypto_skcipher_alg_max_keysize(alg);
> >> 
> >> diff --git a/crypto/simd.c b/crypto/simd.c
> >> index edaa479a1ec5..ea0caabf90f1 100644
> >> --- a/crypto/simd.c
> >> +++ b/crypto/simd.c
> >> @@ -181,6 +181,7 @@ struct simd_skcipher_alg *simd_skcipher_create_compat(const char *algname,
> >> 
> >> 	alg->ivsize = ialg->ivsize;
> >> 	alg->chunksize = ialg->chunksize;
> >> +	alg->walksize = ialg->walksize;
> >> 	alg->min_keysize = ialg->min_keysize;
> >> 	alg->max_keysize = ialg->max_keysize;
> > 
> > What are the consequences of this bug?  I wonder if it actually matters?  The
> > "inner" algorithm is the one that actually gets used for the "walk", right?
> > 
> > - Eric
> 
> Without this, we might still use chunksize or cra_blocksize as the walksize
> even though we setup with the larger walksize.
> 
> Here is the code for the walksize default value:
> 	static int skcipher_prepare_alg(struct skcipher_alg *alg)
> 	{
> 		...
> 		if (!alg->chunksize)
> 			alg->chunksize = base->cra_blocksize;
> 		if (!alg->walksize)
> 			alg->walksize = alg->chunksize;
> 
> And we already have the bigger walksize for x86 aes-xts.
> 		.base = {
> 			.cra_name		= "__xts(aes)",
> 			...
> 		},
> 		.walksize	= 2 * AES_BLOCK_SIZE,
> 
> The x86 aes-xts only uses one `walk` to handle the tail elements. It assumes
> that the walksize contains 2 aes blocks. If walksize is not set correctly, maybe
> some tail elements is not processed in simd-cipher mode for x86 aes-xts.

With the SIMD helper there are three "algorithms": the underlying algorithm, the
cryptd algorithm, and the simd algorithm.  This patch makes the "walksize"
property be propagated from the underlying algorithm to the cryptd and simd
algorithms.  I don't see how that actually makes a difference, since the only
place the skcipher_walk happens is on the underlying algorithm.  So it uses the
"walksize" from the underlying algorithm, right?

- Eric

WARNING: multiple messages have this Message-ID (diff)
From: Eric Biggers <ebiggers@kernel.org>
To: Jerry Shih <jerry.shih@sifive.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>,
	palmer@dabbelt.com, Albert Ou <aou@eecs.berkeley.edu>,
	herbert@gondor.apana.org.au, davem@davemloft.net,
	conor.dooley@microchip.com, ardb@kernel.org, heiko@sntech.de,
	phoebe.chen@sifive.com, hongrong.hsu@sifive.com,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-crypto@vger.kernel.org
Subject: Re: [PATCH v2 05/13] crypto: simd - Update `walksize` in simd skcipher
Date: Tue, 28 Nov 2023 09:22:04 -0800	[thread overview]
Message-ID: <20231128172204.GB1148@sol.localdomain> (raw)
In-Reply-To: <56F07E23-CA7D-466B-84C7-643F2839E199@sifive.com>

On Tue, Nov 28, 2023 at 01:38:29PM +0800, Jerry Shih wrote:
> On Nov 28, 2023, at 11:58, Eric Biggers <ebiggers@kernel.org> wrote:
> > On Mon, Nov 27, 2023 at 03:06:55PM +0800, Jerry Shih wrote:
> >> The `walksize` assignment is missed in simd skcipher.
> >> 
> >> Signed-off-by: Jerry Shih <jerry.shih@sifive.com>
> >> ---
> >> crypto/cryptd.c | 1 +
> >> crypto/simd.c   | 1 +
> >> 2 files changed, 2 insertions(+)
> >> 
> >> diff --git a/crypto/cryptd.c b/crypto/cryptd.c
> >> index bbcc368b6a55..253d13504ccb 100644
> >> --- a/crypto/cryptd.c
> >> +++ b/crypto/cryptd.c
> >> @@ -405,6 +405,7 @@ static int cryptd_create_skcipher(struct crypto_template *tmpl,
> >> 		(alg->base.cra_flags & CRYPTO_ALG_INTERNAL);
> >> 	inst->alg.ivsize = crypto_skcipher_alg_ivsize(alg);
> >> 	inst->alg.chunksize = crypto_skcipher_alg_chunksize(alg);
> >> +	inst->alg.walksize = crypto_skcipher_alg_walksize(alg);
> >> 	inst->alg.min_keysize = crypto_skcipher_alg_min_keysize(alg);
> >> 	inst->alg.max_keysize = crypto_skcipher_alg_max_keysize(alg);
> >> 
> >> diff --git a/crypto/simd.c b/crypto/simd.c
> >> index edaa479a1ec5..ea0caabf90f1 100644
> >> --- a/crypto/simd.c
> >> +++ b/crypto/simd.c
> >> @@ -181,6 +181,7 @@ struct simd_skcipher_alg *simd_skcipher_create_compat(const char *algname,
> >> 
> >> 	alg->ivsize = ialg->ivsize;
> >> 	alg->chunksize = ialg->chunksize;
> >> +	alg->walksize = ialg->walksize;
> >> 	alg->min_keysize = ialg->min_keysize;
> >> 	alg->max_keysize = ialg->max_keysize;
> > 
> > What are the consequences of this bug?  I wonder if it actually matters?  The
> > "inner" algorithm is the one that actually gets used for the "walk", right?
> > 
> > - Eric
> 
> Without this, we might still use chunksize or cra_blocksize as the walksize
> even though we setup with the larger walksize.
> 
> Here is the code for the walksize default value:
> 	static int skcipher_prepare_alg(struct skcipher_alg *alg)
> 	{
> 		...
> 		if (!alg->chunksize)
> 			alg->chunksize = base->cra_blocksize;
> 		if (!alg->walksize)
> 			alg->walksize = alg->chunksize;
> 
> And we already have the bigger walksize for x86 aes-xts.
> 		.base = {
> 			.cra_name		= "__xts(aes)",
> 			...
> 		},
> 		.walksize	= 2 * AES_BLOCK_SIZE,
> 
> The x86 aes-xts only uses one `walk` to handle the tail elements. It assumes
> that the walksize contains 2 aes blocks. If walksize is not set correctly, maybe
> some tail elements is not processed in simd-cipher mode for x86 aes-xts.

With the SIMD helper there are three "algorithms": the underlying algorithm, the
cryptd algorithm, and the simd algorithm.  This patch makes the "walksize"
property be propagated from the underlying algorithm to the cryptd and simd
algorithms.  I don't see how that actually makes a difference, since the only
place the skcipher_walk happens is on the underlying algorithm.  So it uses the
"walksize" from the underlying algorithm, right?

- Eric

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2023-11-28 17:22 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-27  7:06 [PATCH v2 00/13] RISC-V: provide some accelerated cryptography implementations using vector extensions Jerry Shih
2023-11-27  7:06 ` Jerry Shih
2023-11-27  7:06 ` [PATCH v2 01/13] RISC-V: add helper function to read the vector VLEN Jerry Shih
2023-11-27  7:06   ` Jerry Shih
2023-11-28  3:45   ` Eric Biggers
2023-11-28  3:45     ` Eric Biggers
2023-11-27  7:06 ` [PATCH v2 02/13] RISC-V: hook new crypto subdir into build-system Jerry Shih
2023-11-27  7:06   ` Jerry Shih
2023-11-28  3:45   ` Eric Biggers
2023-11-28  3:45     ` Eric Biggers
2023-11-27  7:06 ` [PATCH v2 03/13] RISC-V: crypto: add OpenSSL perl module for vector instructions Jerry Shih
2023-11-27  7:06   ` Jerry Shih
2023-11-27  7:06 ` [PATCH v2 04/13] RISC-V: crypto: add Zvkned accelerated AES implementation Jerry Shih
2023-11-27  7:06   ` Jerry Shih
2023-11-28  3:56   ` Eric Biggers
2023-11-28  3:56     ` Eric Biggers
2023-11-28  4:22     ` Jerry Shih
2023-11-28  4:22       ` Jerry Shih
2023-11-28  4:38       ` Eric Biggers
2023-11-28  4:38         ` Eric Biggers
2023-11-28 17:54   ` Conor Dooley
2023-11-28 17:54     ` Conor Dooley
2023-11-28 20:12     ` Eric Biggers
2023-11-28 20:12       ` Eric Biggers
2023-11-29  2:39       ` Jerry Shih
2023-11-29  2:39         ` Jerry Shih
2023-11-29 11:12         ` Conor Dooley
2023-11-29 11:12           ` Conor Dooley
2023-11-29 20:26           ` Eric Biggers
2023-11-29 20:26             ` Eric Biggers
2023-11-27  7:06 ` [PATCH v2 05/13] crypto: simd - Update `walksize` in simd skcipher Jerry Shih
2023-11-27  7:06   ` Jerry Shih
2023-11-28  3:58   ` Eric Biggers
2023-11-28  3:58     ` Eric Biggers
2023-11-28  5:38     ` Jerry Shih
2023-11-28  5:38       ` Jerry Shih
2023-11-28 17:22       ` Eric Biggers [this message]
2023-11-28 17:22         ` Eric Biggers
2023-12-01  2:09         ` Jerry Shih
2023-12-01  2:09           ` Jerry Shih
2023-12-08  4:05   ` Herbert Xu
2023-12-08  4:05     ` Herbert Xu
2023-12-08  4:18     ` Jerry Shih
2023-12-08  4:18       ` Jerry Shih
2023-11-27  7:06 ` [PATCH v2 06/13] crypto: scatterwalk - Add scatterwalk_next() to get the next scatterlist in scatter_walk Jerry Shih
2023-11-27  7:06   ` Jerry Shih
2023-11-27  7:06 ` [PATCH v2 07/13] RISC-V: crypto: add accelerated AES-CBC/CTR/ECB/XTS implementations Jerry Shih
2023-11-27  7:06   ` Jerry Shih
2023-11-28  4:07   ` Eric Biggers
2023-11-28  4:07     ` Eric Biggers
2023-11-29  7:57     ` Jerry Shih
2023-11-29  7:57       ` Jerry Shih
2023-11-29 20:16       ` Eric Biggers
2023-11-29 20:16         ` Eric Biggers
2023-12-02 13:20         ` Jerry Shih
2023-12-02 13:20           ` Jerry Shih
2023-11-27  7:06 ` [PATCH v2 08/13] RISC-V: crypto: add Zvkg accelerated GCM GHASH implementation Jerry Shih
2023-11-27  7:06   ` Jerry Shih
2023-11-27  7:06 ` [PATCH v2 09/13] RISC-V: crypto: add Zvknha/b accelerated SHA224/256 implementations Jerry Shih
2023-11-27  7:06   ` Jerry Shih
2023-11-28  4:12   ` Eric Biggers
2023-11-28  4:12     ` Eric Biggers
2023-11-28  7:16     ` Jerry Shih
2023-11-28  7:16       ` Jerry Shih
2023-11-28 17:23       ` Eric Biggers
2023-11-28 17:23         ` Eric Biggers
2023-11-27  7:07 ` [PATCH v2 10/13] RISC-V: crypto: add Zvknhb accelerated SHA384/512 implementations Jerry Shih
2023-11-27  7:07   ` Jerry Shih
2023-11-27  7:07 ` [PATCH v2 11/13] RISC-V: crypto: add Zvksed accelerated SM4 implementation Jerry Shih
2023-11-27  7:07   ` Jerry Shih
2023-11-27  7:07 ` [PATCH v2 12/13] RISC-V: crypto: add Zvksh accelerated SM3 implementation Jerry Shih
2023-11-27  7:07   ` Jerry Shih
2023-11-28  4:13   ` Eric Biggers
2023-11-28  4:13     ` Eric Biggers
2023-11-29  5:32     ` Jerry Shih
2023-11-29  5:32       ` Jerry Shih
2023-11-27  7:07 ` [PATCH v2 13/13] RISC-V: crypto: add Zvkb accelerated ChaCha20 implementation Jerry Shih
2023-11-27  7:07   ` Jerry Shih
2023-11-28  4:25   ` Eric Biggers
2023-11-28  4:25     ` Eric Biggers
2023-11-28  8:57     ` Jerry Shih
2023-11-28  8:57       ` Jerry Shih

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231128172204.GB1148@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=aou@eecs.berkeley.edu \
    --cc=ardb@kernel.org \
    --cc=conor.dooley@microchip.com \
    --cc=davem@davemloft.net \
    --cc=heiko@sntech.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=hongrong.hsu@sifive.com \
    --cc=jerry.shih@sifive.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=phoebe.chen@sifive.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.