From: David Laight <david.laight.linux@gmail.com>
To: Thorsten Blum <blum@kernel.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/5] crypto: cast5 - use memcpy_and_pad() in cast5_setkey()
Date: Fri, 2 Oct 2026 10:24:30 +0100 [thread overview]
Message-ID: <20261002102430.65e546ae@pumpkin> (raw)
In-Reply-To: <20260921061120.29694-6-blum@kernel.org>
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]);
>
prev parent reply other threads:[~2026-10-02 9:24 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
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
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 message]
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=20261002102430.65e546ae@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=blum@kernel.org \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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 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®