CR_1675:crypto:starfive: Add iv_out read after encryption
authorjiajie.ho <jiajie.ho@starfivetech.com>
Wed, 10 Aug 2022 07:39:41 +0000 (15:39 +0800)
committerjiajie.ho <jiajie.ho@starfivetech.com>
Wed, 10 Aug 2022 08:14:39 +0000 (16:14 +0800)
Add iv_out read required by Linux Self Test from hw engine
after AES encryption has been completed.

Signed-off-by: jiajie.ho <jiajie.ho@starfivetech.com>
drivers/crypto/starfive/jh7110/jh7110-aes.c

index 1aa8573..19cd4ea 100644 (file)
@@ -257,6 +257,19 @@ static int jh7110_cryp_hw_write_iv(struct jh7110_sec_ctx *ctx, u32 *iv)
        return 0;
 }
 
+static void jh7110_cryp_hw_get_iv(struct jh7110_sec_ctx *ctx, u32 *iv)
+{
+       struct jh7110_sec_dev *sdev = ctx->sdev;
+
+       if (!iv)
+               return;
+
+       iv[0] = jh7110_sec_read(sdev, JH7110_AES_IV0);
+       iv[1] = jh7110_sec_read(sdev, JH7110_AES_IV1);
+       iv[2] = jh7110_sec_read(sdev, JH7110_AES_IV2);
+       iv[3] = jh7110_sec_read(sdev, JH7110_AES_IV3);
+}
+
 static void jh7110_cryp_hw_write_ctr(struct jh7110_sec_ctx *ctx, u32 *ctr)
 {
        struct jh7110_sec_dev *sdev = ctx->sdev;
@@ -538,6 +551,9 @@ static int jh7110_cryp_finish_req(struct jh7110_sec_ctx *ctx, int err)
                err = jh7110_cryp_read_auth_tag(ctx);
        }
 
+       if (!err && (is_cbc(rctx) || is_ctr(rctx)))
+               jh7110_cryp_hw_get_iv(ctx, (void *)rctx->req.sreq->iv);
+
        if (is_gcm(rctx) || is_ccm(rctx))
                crypto_finalize_aead_request(ctx->sdev->engine, rctx->req.areq, err);
        else