crypto: tegra - Fix IV usage for AES ECB
authorAkhil R <akhilrajeev@nvidia.com>
Wed, 26 Mar 2025 14:51:10 +0000 (20:21 +0530)
committerHerbert Xu <herbert@gondor.apana.org.au>
Mon, 7 Apr 2025 05:22:25 +0000 (13:22 +0800)
Modifying the crypto_request turns out to be not the right way to handle
the stale value issue with the IV. Though the IV is not used for AES ECB,
it eventually get used in algorithms like LRW in the next step after
AES ECB encryption/decryption. Setting req->iv to NULL breaks the
implementation of such algorithms. Hence modify only the local reqctx
to check for IV.

Fixes: bde558220866 ("crypto: tegra - Set IV to NULL explicitly for AES ECB")
Signed-off-by: Akhil R <akhilrajeev@nvidia.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/tegra/tegra-se-aes.c

index ca9d0cca1f748e99120dc1774e7d30dab3cf37be..0e07d0523291a59a86793ed9d575353147084da4 100644 (file)
@@ -269,7 +269,7 @@ static int tegra_aes_do_one_req(struct crypto_engine *engine, void *areq)
        unsigned int cmdlen, key1_id, key2_id;
        int ret;
 
-       rctx->iv = (u32 *)req->iv;
+       rctx->iv = (ctx->alg == SE_ALG_ECB) ? NULL : (u32 *)req->iv;
        rctx->len = req->cryptlen;
        key1_id = ctx->key1_id;
        key2_id = ctx->key2_id;
@@ -498,9 +498,6 @@ static int tegra_aes_crypt(struct skcipher_request *req, bool encrypt)
        if (!req->cryptlen)
                return 0;
 
-       if (ctx->alg == SE_ALG_ECB)
-               req->iv = NULL;
-
        rctx->encrypt = encrypt;
 
        return crypto_transfer_skcipher_request_to_engine(ctx->se->engine, req);