crypto: qce - simplify qce_xts_swapiv()

Declare 'swap' as zero-initialized and use a single index variable to
simplify the byte-swapping loop in qce_xts_swapiv(). Add a comment for
clarity.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Bjorn Andersson <andersson@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
master
Thorsten Blum 2026-03-30 19:39:25 +02:00 committed by Herbert Xu
parent 1ee57ab93b
commit 3787fb7697
1 changed files with 6 additions and 6 deletions

View File

@ -280,17 +280,17 @@ static u32 qce_encr_cfg(unsigned long flags, u32 aes_key_size)
#ifdef CONFIG_CRYPTO_DEV_QCE_SKCIPHER #ifdef CONFIG_CRYPTO_DEV_QCE_SKCIPHER
static void qce_xts_swapiv(__be32 *dst, const u8 *src, unsigned int ivsize) static void qce_xts_swapiv(__be32 *dst, const u8 *src, unsigned int ivsize)
{ {
u8 swap[QCE_AES_IV_LENGTH]; u8 swap[QCE_AES_IV_LENGTH] = {0};
u32 i, j; unsigned int i, offset;
if (ivsize > QCE_AES_IV_LENGTH) if (ivsize > QCE_AES_IV_LENGTH)
return; return;
memset(swap, 0, QCE_AES_IV_LENGTH); offset = QCE_AES_IV_LENGTH - ivsize;
for (i = (QCE_AES_IV_LENGTH - ivsize), j = ivsize - 1; /* Reverse and right-align IV bytes. */
i < QCE_AES_IV_LENGTH; i++, j--) for (i = 0; i < ivsize; i++)
swap[i] = src[j]; swap[offset + i] = src[ivsize - 1 - i];
qce_cpu_to_be32p_array(dst, swap, QCE_AES_IV_LENGTH); qce_cpu_to_be32p_array(dst, swap, QCE_AES_IV_LENGTH);
} }