]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: qce - simplify qce_xts_swapiv()
authorThorsten Blum <thorsten.blum@linux.dev>
Mon, 30 Mar 2026 17:39:25 +0000 (19:39 +0200)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sun, 12 Apr 2026 08:46:29 +0000 (16:46 +0800)
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>
drivers/crypto/qce/common.c

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