mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/5] crypto: cast5 - use memcpy_and_pad() in cast5_setkey()
@ 2026-09-21  6:11 Thorsten Blum
  2026-09-21  6:11 ` [PATCH 2/5] crypto: cast6 - use memcpy_and_pad() in __cast6_setkey() Thorsten Blum
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Thorsten Blum @ 2026-09-21  6:11 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller; +Cc: Thorsten Blum, linux-crypto, linux-kernel

Use memcpy_and_pad() instead of separate memcpy() and memset() calls to
simplify cast5_setkey().

Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 crypto/cast5_generic.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/crypto/cast5_generic.c b/crypto/cast5_generic.c
index f68330793e0c..1de0dc966a03 100644
--- a/crypto/cast5_generic.c
+++ b/crypto/cast5_generic.c
@@ -483,9 +483,7 @@ int cast5_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int key_len)
 
 	c->rr = key_len <= 10 ? 1 : 0;
 
-	memset(p_key, 0, 16);
-	memcpy(p_key, key, key_len);
-
+	memcpy_and_pad(p_key, sizeof(p_key), key, key_len, 0);
 
 	x[0] = be32_to_cpu(p_key[0]);
 	x[1] = be32_to_cpu(p_key[1]);

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/5] crypto: cast6 - use memcpy_and_pad() in __cast6_setkey()
  2026-09-21  6:11 [PATCH 1/5] crypto: cast5 - use memcpy_and_pad() in cast5_setkey() Thorsten Blum
@ 2026-09-21  6:11 ` Thorsten Blum
  2026-09-21  6:11 ` [PATCH 3/5] crypto: ixp4xx - use memcpy_and_pad() in register_chain_var() Thorsten Blum
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Thorsten Blum @ 2026-09-21  6:11 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller; +Cc: Thorsten Blum, linux-crypto, linux-kernel

Use memcpy_and_pad() instead of separate memcpy() and memset() calls to
simplify __cast6_setkey().

Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 crypto/cast6_generic.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/crypto/cast6_generic.c b/crypto/cast6_generic.c
index 4c08c42646f0..9b6bdd2aa511 100644
--- a/crypto/cast6_generic.c
+++ b/crypto/cast6_generic.c
@@ -112,8 +112,7 @@ int __cast6_setkey(struct cast6_ctx *c, const u8 *in_key, unsigned int key_len)
 	if (key_len % 4 != 0)
 		return -EINVAL;
 
-	memset(p_key, 0, 32);
-	memcpy(p_key, in_key, key_len);
+	memcpy_and_pad(p_key, sizeof(p_key), in_key, key_len, 0);
 
 	key[0] = be32_to_cpu(p_key[0]);		/* A */
 	key[1] = be32_to_cpu(p_key[1]);		/* B */

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/5] crypto: ixp4xx - use memcpy_and_pad() in register_chain_var()
  2026-09-21  6:11 [PATCH 1/5] crypto: cast5 - use memcpy_and_pad() in cast5_setkey() Thorsten Blum
  2026-09-21  6:11 ` [PATCH 2/5] crypto: cast6 - use memcpy_and_pad() in __cast6_setkey() Thorsten Blum
@ 2026-09-21  6:11 ` Thorsten Blum
  2026-09-21  8:56   ` Linus Walleij
  2026-09-21  6:11 ` [PATCH 4/5] crypto: octeontx - use memcpy_and_pad() in aead_hmac_init() Thorsten Blum
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 8+ messages in thread
From: Thorsten Blum @ 2026-09-21  6:11 UTC (permalink / raw)
  To: Linus Walleij, Imre Kaloz, Corentin Labbe, Herbert Xu, David S. Miller
  Cc: Thorsten Blum, linux-crypto, linux-arm-kernel, linux-kernel

Use memcpy_and_pad() instead of separate memcpy() and memset() calls to
simplify register_chain_var().

Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 drivers/crypto/intel/ixp4xx/ixp4xx_crypto.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/crypto/intel/ixp4xx/ixp4xx_crypto.c b/drivers/crypto/intel/ixp4xx/ixp4xx_crypto.c
index fdda04672454..33e8e887a415 100644
--- a/drivers/crypto/intel/ixp4xx/ixp4xx_crypto.c
+++ b/drivers/crypto/intel/ixp4xx/ixp4xx_crypto.c
@@ -707,8 +707,7 @@ static int register_chain_var(struct crypto_tfm *tfm, u8 xpad, u32 target,
 		return -EAGAIN;
 	}
 
-	memcpy(pad, key, key_len);
-	memset(pad + key_len, 0, HMAC_PAD_BLOCKLEN - key_len);
+	memcpy_and_pad(pad, HMAC_PAD_BLOCKLEN, key, key_len, 0);
 	for (i = 0; i < HMAC_PAD_BLOCKLEN; i++)
 		pad[i] ^= xpad;
 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 4/5] crypto: octeontx - use memcpy_and_pad() in aead_hmac_init()
  2026-09-21  6:11 [PATCH 1/5] crypto: cast5 - use memcpy_and_pad() in cast5_setkey() Thorsten Blum
  2026-09-21  6:11 ` [PATCH 2/5] crypto: cast6 - use memcpy_and_pad() in __cast6_setkey() Thorsten Blum
  2026-09-21  6:11 ` [PATCH 3/5] crypto: ixp4xx - use memcpy_and_pad() in register_chain_var() Thorsten Blum
@ 2026-09-21  6:11 ` Thorsten Blum
  2026-09-21  6:11 ` [PATCH 5/5] crypto: octeontx2 " Thorsten Blum
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Thorsten Blum @ 2026-09-21  6:11 UTC (permalink / raw)
  To: Srujana Challa, Bharat Bhushan, Herbert Xu, David S. Miller,
	David C.C.M. Gall
  Cc: Thorsten Blum, linux-crypto, linux-kernel

Use memcpy_and_pad() instead of separate memcpy() and memset() calls to
simplify aead_hmac_init().

Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 drivers/crypto/marvell/octeontx/otx_cptvf_algs.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/crypto/marvell/octeontx/otx_cptvf_algs.c b/drivers/crypto/marvell/octeontx/otx_cptvf_algs.c
index 096be42e9d03..1becaf77b10c 100644
--- a/drivers/crypto/marvell/octeontx/otx_cptvf_algs.c
+++ b/drivers/crypto/marvell/octeontx/otx_cptvf_algs.c
@@ -792,8 +792,7 @@ static int aead_hmac_init(struct crypto_aead *cipher,
 	ipad = ctx->ipad;
 	opad = ctx->opad;
 
-	memcpy(ipad, ctx->key, authkeylen);
-	memset(ipad + authkeylen, 0, bs - authkeylen);
+	memcpy_and_pad(ipad, bs, ctx->key, authkeylen, 0);
 	memcpy(opad, ipad, bs);
 
 	for (icount = 0; icount < bs; icount++) {

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 5/5] crypto: octeontx2 - use memcpy_and_pad() in aead_hmac_init()
  2026-09-21  6:11 [PATCH 1/5] crypto: cast5 - use memcpy_and_pad() in cast5_setkey() Thorsten Blum
                   ` (2 preceding siblings ...)
  2026-09-21  6:11 ` [PATCH 4/5] crypto: octeontx - use memcpy_and_pad() in aead_hmac_init() Thorsten Blum
@ 2026-09-21  6:11 ` Thorsten Blum
  2026-10-02  8:15 ` [PATCH 1/5] crypto: cast5 - use memcpy_and_pad() in cast5_setkey() Herbert Xu
  2026-10-02  9:24 ` David Laight
  5 siblings, 0 replies; 8+ messages in thread
From: Thorsten Blum @ 2026-09-21  6:11 UTC (permalink / raw)
  To: Srujana Challa, Bharat Bhushan, Herbert Xu, David S. Miller,
	David C.C.M. Gall
  Cc: Thorsten Blum, linux-crypto, linux-kernel

Use memcpy_and_pad() instead of separate memcpy() and memset() calls to
simplify aead_hmac_init().

Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 drivers/crypto/marvell/octeontx2/otx2_cptvf_algs.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/crypto/marvell/octeontx2/otx2_cptvf_algs.c b/drivers/crypto/marvell/octeontx2/otx2_cptvf_algs.c
index 8d9f394d6b50..65ad29f1e47c 100644
--- a/drivers/crypto/marvell/octeontx2/otx2_cptvf_algs.c
+++ b/drivers/crypto/marvell/octeontx2/otx2_cptvf_algs.c
@@ -882,8 +882,7 @@ static int aead_hmac_init(struct crypto_aead *cipher,
 	ipad = ctx->ipad;
 	opad = ctx->opad;
 
-	memcpy(ipad, ctx->key, authkeylen);
-	memset(ipad + authkeylen, 0, bs - authkeylen);
+	memcpy_and_pad(ipad, bs, ctx->key, authkeylen, 0);
 	memcpy(opad, ipad, bs);
 
 	for (icount = 0; icount < bs; icount++) {

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/5] crypto: ixp4xx - use memcpy_and_pad() in register_chain_var()
  2026-09-21  6:11 ` [PATCH 3/5] crypto: ixp4xx - use memcpy_and_pad() in register_chain_var() Thorsten Blum
@ 2026-09-21  8:56   ` Linus Walleij
  0 siblings, 0 replies; 8+ messages in thread
From: Linus Walleij @ 2026-09-21  8:56 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Imre Kaloz, Corentin Labbe, Herbert Xu, David S. Miller,
	linux-crypto, linux-arm-kernel, linux-kernel

On Mon, Sep 21, 2026 at 8:12 AM Thorsten Blum <blum@kernel.org> wrote:

> Use memcpy_and_pad() instead of separate memcpy() and memset() calls to
> simplify register_chain_var().
>
> Signed-off-by: Thorsten Blum <blum@kernel.org>

This makes sense.
Reviewed-by: Linus Walleij <linusw@kernel.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/5] crypto: cast5 - use memcpy_and_pad() in cast5_setkey()
  2026-09-21  6:11 [PATCH 1/5] crypto: cast5 - use memcpy_and_pad() in cast5_setkey() Thorsten Blum
                   ` (3 preceding siblings ...)
  2026-09-21  6:11 ` [PATCH 5/5] crypto: octeontx2 " Thorsten Blum
@ 2026-10-02  8:15 ` Herbert Xu
  2026-10-02  9:24 ` David Laight
  5 siblings, 0 replies; 8+ messages in thread
From: Herbert Xu @ 2026-10-02  8:15 UTC (permalink / raw)
  To: Thorsten Blum; +Cc: David S. Miller, linux-crypto, linux-kernel

On Mon, Sep 21, 2026 at 08:11:20AM +0200, Thorsten Blum wrote:
> Use memcpy_and_pad() instead of separate memcpy() and memset() calls to
> simplify cast5_setkey().
> 
> Signed-off-by: Thorsten Blum <blum@kernel.org>
> ---
>  crypto/cast5_generic.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)

All applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/5] crypto: cast5 - use memcpy_and_pad() in cast5_setkey()
  2026-09-21  6:11 [PATCH 1/5] crypto: cast5 - use memcpy_and_pad() in cast5_setkey() Thorsten Blum
                   ` (4 preceding siblings ...)
  2026-10-02  8:15 ` [PATCH 1/5] crypto: cast5 - use memcpy_and_pad() in cast5_setkey() Herbert Xu
@ 2026-10-02  9:24 ` David Laight
  5 siblings, 0 replies; 8+ messages in thread
From: David Laight @ 2026-10-02  9:24 UTC (permalink / raw)
  To: Thorsten Blum; +Cc: Herbert Xu, David S. Miller, linux-crypto, linux-kernel

On Mon, 21 Sep 2026 08:11:20 +0200
Thorsten Blum <blum@kernel.org> wrote:

> Use memcpy_and_pad() instead of separate memcpy() and memset() calls to
> simplify cast5_setkey().
> 
> Signed-off-by: Thorsten Blum <blum@kernel.org>
> ---
>  crypto/cast5_generic.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/crypto/cast5_generic.c b/crypto/cast5_generic.c
> index f68330793e0c..1de0dc966a03 100644
> --- a/crypto/cast5_generic.c
> +++ b/crypto/cast5_generic.c
> @@ -483,9 +483,7 @@ int cast5_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int key_len)
>  
>  	c->rr = key_len <= 10 ? 1 : 0;
>  
> -	memset(p_key, 0, 16);
> -	memcpy(p_key, key, key_len);
> -
> +	memcpy_and_pad(p_key, sizeof(p_key), key, key_len, 0);

This will almost certainly be slower and larger.
The fixed size memset() will be two 8byte writes on 64bit,
definitely cheaper than the calculations required for the memset.

More worrying in not verifying that the key_len isn't too big.
Maybe the length is validated against cia_max_keysize somewhere,
but there are whole lot of unrelated constants that have to match.

David
 
>  
>  	x[0] = be32_to_cpu(p_key[0]);
>  	x[1] = be32_to_cpu(p_key[1]);
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-10-02  9:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-21  6:11 [PATCH 1/5] crypto: cast5 - use memcpy_and_pad() in cast5_setkey() Thorsten Blum
2026-09-21  6:11 ` [PATCH 2/5] crypto: cast6 - use memcpy_and_pad() in __cast6_setkey() Thorsten Blum
2026-09-21  6:11 ` [PATCH 3/5] crypto: ixp4xx - use memcpy_and_pad() in register_chain_var() Thorsten Blum
2026-09-21  8:56   ` Linus Walleij
2026-09-21  6:11 ` [PATCH 4/5] crypto: octeontx - use memcpy_and_pad() in aead_hmac_init() Thorsten Blum
2026-09-21  6:11 ` [PATCH 5/5] crypto: octeontx2 " Thorsten Blum
2026-10-02  8:15 ` [PATCH 1/5] crypto: cast5 - use memcpy_and_pad() in cast5_setkey() Herbert Xu
2026-10-02  9:24 ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®