crypto: cast5 - use memcpy_and_pad() in cast5_setkey()
Subsystems (4)
PATCH 1/5 crypto: cast5 - use memcpy_and_pad() in cast5_setkey()
Use memcpy_and_pad() instead of separate memcpy() and memset() calls to simplify cast5_setkey().
--- crypto/cast5_generic.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
crypto/cast5_generic.c +1 -3
@@ -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 ]);
PATCH 2/5 crypto: cast6 - use memcpy_and_pad() in __cast6_setkey()
Use memcpy_and_pad() instead of separate memcpy() and memset() calls to simplify __cast6_setkey().
--- crypto/cast6_generic.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
crypto/cast6_generic.c +1 -2
@@ -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 */
PATCH 3/5 crypto: ixp4xx - use memcpy_and_pad() in register_chain_var()
In reply to Thorsten BlumUse memcpy_and_pad() instead of separate memcpy() and memset() calls to simplify register_chain_var().
--- drivers/crypto/intel/ixp4xx/ixp4xx_crypto.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/crypto/intel/ixp4xx/ixp4xx_crypto.c +1 -2
@@ -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;
Re: [PATCH 3/5] crypto: ixp4xx - use memcpy_and_pad() in register_chain_var()
Quoted 4 lines · Thorsten Blum
Use
memcpy_and_pad()instead of separatememcpy()andmemset()calls to simplifyregister_chain_var().Signed-off-by Thorsten Blum <[email protected]>
This makes sense.
Yours,
Linus Walleij
PATCH 4/5 crypto: octeontx - use memcpy_and_pad() in aead_hmac_init()
In reply to Thorsten BlumUse memcpy_and_pad() instead of separate memcpy() and memset() calls to simplify aead_hmac_init().
--- drivers/crypto/marvell/octeontx/otx_cptvf_algs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/crypto/marvell/octeontx/otx_cptvf_algs.c +1 -2
@@ -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++) {
PATCH 5/5 crypto: octeontx2 - use memcpy_and_pad() in aead_hmac_init()
In reply to Thorsten BlumUse memcpy_and_pad() instead of separate memcpy() and memset() calls to simplify aead_hmac_init().
--- drivers/crypto/marvell/octeontx2/otx2_cptvf_algs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/crypto/marvell/octeontx2/otx2_cptvf_algs.c +1 -2
@@ -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++) {
Herbert Xu
maintainerQuoted 7 lines · Thorsten Blum
Use
memcpy_and_pad()instead of separatememcpy()andmemset()calls to simplifycast5_setkey().Signed-off-by Thorsten Blum <[email protected]>--- crypto/cast5_generic.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
All applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 13 lines · On Mon, 21 Sep 2026 08:11:20 +0200 Thorsten Blum <[email protected]> wrote:
Use
memcpy_and_pad()instead of separatememcpy()andmemset()calls to simplifycast5_setkey().Signed-off-by Thorsten Blum <[email protected]>--- crypto/cast5_generic.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)crypto/cast5_generic.c +0
-0
crypto/cast5_generic.c int cast5_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int key_len) · line 486
Quoted 7 lines
crypto/cast5_generic.c +1
-3@@ -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
Quoted 4 lines
crypto/cast5_generic.c +0
-0x[0 ] =be32_to_cpu (p_key[0 ]); x[1 ] =be32_to_cpu (p_key[1 ]);