]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
crypto: tegra - Fix CMAC intermediate result handling
authorAkhil R <akhilrajeev@nvidia.com>
Mon, 24 Feb 2025 09:16:07 +0000 (14:46 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Apr 2025 12:39:18 +0000 (14:39 +0200)
[ Upstream commit ce390d6c2675d2e24d798169a1a0e3cdbc076907 ]

Saving and restoring of the intermediate results are needed if there is
context switch caused by another ongoing request on the same engine.
This is therefore not only to support import/export functionality.
Hence, save and restore the intermediate result for every non-first task.

Fixes: 0880bb3b00c8 ("crypto: tegra - Add Tegra Security Engine driver")
Signed-off-by: Akhil R <akhilrajeev@nvidia.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/crypto/tegra/tegra-se-aes.c

index 06f60260e0a0f65f2f3fd1a0e238aba75e30b87c..3308962f11c595bab570a92a201e9671569fbeb4 100644 (file)
@@ -1513,9 +1513,8 @@ static int tegra_cmac_do_update(struct ahash_request *req)
        rctx->residue.size = nresidue;
 
        /*
-        * If this is not the first 'update' call, paste the previous copied
+        * If this is not the first task, paste the previous copied
         * intermediate results to the registers so that it gets picked up.
-        * This is to support the import/export functionality.
         */
        if (!(rctx->task & SHA_FIRST))
                tegra_cmac_paste_result(ctx->se, rctx);
@@ -1523,13 +1522,7 @@ static int tegra_cmac_do_update(struct ahash_request *req)
        cmdlen = tegra_cmac_prep_cmd(ctx, rctx);
        ret = tegra_se_host1x_submit(se, se->cmdbuf, cmdlen);
 
-       /*
-        * If this is not the final update, copy the intermediate results
-        * from the registers so that it can be used in the next 'update'
-        * call. This is to support the import/export functionality.
-        */
-       if (!(rctx->task & SHA_FINAL))
-               tegra_cmac_copy_result(ctx->se, rctx);
+       tegra_cmac_copy_result(ctx->se, rctx);
 
        return ret;
 }
@@ -1553,6 +1546,13 @@ static int tegra_cmac_do_final(struct ahash_request *req)
        rctx->total_len += rctx->residue.size;
        rctx->config = tegra234_aes_cfg(SE_ALG_CMAC, 0);
 
+       /*
+        * If this is not the first task, paste the previous copied
+        * intermediate results to the registers so that it gets picked up.
+        */
+       if (!(rctx->task & SHA_FIRST))
+               tegra_cmac_paste_result(ctx->se, rctx);
+
        /* Prepare command and submit */
        cmdlen = tegra_cmac_prep_cmd(ctx, rctx);
        ret = tegra_se_host1x_submit(se, se->cmdbuf, cmdlen);