2024-04-29 06:22:50

by Jia Jie Ho

[permalink] [raw]
Subject: [PATCH -next 0/4] crypto: starfive - Minor fixes for AES and RSA

This patch series fix a bug caused by freeing a stack buffer in RSA
module and skip some unneeded steps in StarFive crypto driver.

Jia Jie Ho (4):
crypto: starfive - Skip dma setup for zeroed message
crypto: starfive: Skip unneeded fallback allocation
crypto: starfive: Do not free stack buffer
crypto: starfive: Use fallback for unaligned dma access

drivers/crypto/starfive/jh7110-aes.c | 16 +++++++++++-----
drivers/crypto/starfive/jh7110-rsa.c | 11 ++++-------
2 files changed, 15 insertions(+), 12 deletions(-)

--
2.40.1



2024-04-29 06:23:16

by Jia Jie Ho

[permalink] [raw]
Subject: [PATCH -next 1/4] crypto: starfive - Skip dma setup for zeroed message

Skip dma setup and mapping for AES driver if plaintext is empty.

Signed-off-by: Jia Jie Ho <[email protected]>
---
drivers/crypto/starfive/jh7110-aes.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/crypto/starfive/jh7110-aes.c b/drivers/crypto/starfive/jh7110-aes.c
index 72b7d46150d5..9d6e2f936f03 100644
--- a/drivers/crypto/starfive/jh7110-aes.c
+++ b/drivers/crypto/starfive/jh7110-aes.c
@@ -590,12 +590,16 @@ static int starfive_aes_do_one_req(struct crypto_engine *engine, void *areq)
if (ret)
return ret;

+ if (!cryp->total_in)
+ goto finish_req;
+
starfive_aes_dma_init(cryp);

ret = starfive_aes_map_sg(cryp, rctx->in_sg, rctx->out_sg);
if (ret)
return ret;

+finish_req:
starfive_aes_finish_req(ctx);

return 0;
--
2.40.1


2024-04-29 06:24:53

by Jia Jie Ho

[permalink] [raw]
Subject: [PATCH -next 4/4] crypto: starfive: Use fallback for unaligned dma access

Dma address mapping fails on unaligned scatterlist offset. Use sw
fallback for these cases.

Signed-off-by: Jia Jie Ho <[email protected]>
---
drivers/crypto/starfive/jh7110-aes.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/crypto/starfive/jh7110-aes.c b/drivers/crypto/starfive/jh7110-aes.c
index 9d6e2f936f03..86a1a1fa9f8f 100644
--- a/drivers/crypto/starfive/jh7110-aes.c
+++ b/drivers/crypto/starfive/jh7110-aes.c
@@ -314,7 +314,7 @@ static int starfive_aes_read_authtag(struct starfive_cryp_ctx *ctx)
cryp->total_in, cryp->authsize, 1);
} else {
if (crypto_memneq(cryp->tag_in, cryp->tag_out, cryp->authsize))
- return dev_err_probe(cryp->dev, -EBADMSG, "Failed tag verification\n");
+ return -EBADMSG;
}

return 0;
@@ -753,14 +753,16 @@ static bool starfive_aes_check_unaligned(struct starfive_cryp_dev *cryp,
int i;

for_each_sg(src, tsg, sg_nents(src), i)
- if (!IS_ALIGNED(tsg->length, AES_BLOCK_SIZE) &&
- !sg_is_last(tsg))
+ if (!IS_ALIGNED(tsg->offset, sizeof(u32)) ||
+ (!IS_ALIGNED(tsg->length, AES_BLOCK_SIZE) &&
+ !sg_is_last(tsg)))
return true;

if (src != dst)
for_each_sg(dst, tsg, sg_nents(dst), i)
- if (!IS_ALIGNED(tsg->length, AES_BLOCK_SIZE) &&
- !sg_is_last(tsg))
+ if (!IS_ALIGNED(tsg->offset, sizeof(u32)) ||
+ (!IS_ALIGNED(tsg->length, AES_BLOCK_SIZE) &&
+ !sg_is_last(tsg)))
return true;

return false;
--
2.40.1