Re: [PATCH 1/5] crypto: cast5 - use memcpy_and_pad() in cast5_setkey()
From: David Laight
Date: Fri Oct 02 2026 - 05:39:57 EST
On Mon, 21 Sep 2026 08:11:20 +0200
Thorsten Blum <blum@xxxxxxxxxx> wrote:
> Use memcpy_and_pad() instead of separate memcpy() and memset() calls to
> simplify cast5_setkey().
>
> Signed-off-by: Thorsten Blum <blum@xxxxxxxxxx>
> ---
> 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]);
>