Skip to content

Commit 3787fb7

Browse files
tobluxherbertx
authored andcommitted
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>
1 parent 1ee57ab commit 3787fb7

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

drivers/crypto/qce/common.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,17 +280,17 @@ static u32 qce_encr_cfg(unsigned long flags, u32 aes_key_size)
280280
#ifdef CONFIG_CRYPTO_DEV_QCE_SKCIPHER
281281
static void qce_xts_swapiv(__be32 *dst, const u8 *src, unsigned int ivsize)
282282
{
283-
u8 swap[QCE_AES_IV_LENGTH];
284-
u32 i, j;
283+
u8 swap[QCE_AES_IV_LENGTH] = {0};
284+
unsigned int i, offset;
285285

286286
if (ivsize > QCE_AES_IV_LENGTH)
287287
return;
288288

289-
memset(swap, 0, QCE_AES_IV_LENGTH);
289+
offset = QCE_AES_IV_LENGTH - ivsize;
290290

291-
for (i = (QCE_AES_IV_LENGTH - ivsize), j = ivsize - 1;
292-
i < QCE_AES_IV_LENGTH; i++, j--)
293-
swap[i] = src[j];
291+
/* Reverse and right-align IV bytes. */
292+
for (i = 0; i < ivsize; i++)
293+
swap[offset + i] = src[ivsize - 1 - i];
294294

295295
qce_cpu_to_be32p_array(dst, swap, QCE_AES_IV_LENGTH);
296296
}

0 commit comments

Comments
 (0)