[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20251204112227.2659404-6-maobibo@loongson.cn>
Date: Thu, 4 Dec 2025 19:22:22 +0800
From: Bibo Mao <maobibo@...ngson.cn>
To: Gonglei <arei.gonglei@...wei.com>,
"Michael S. Tsirkin" <mst@...hat.com>,
Jason Wang <jasowang@...hat.com>,
Xuan Zhuo <xuanzhuo@...ux.alibaba.com>,
Eugenio Pérez <eperezma@...hat.com>,
Herbert Xu <herbert@...dor.apana.org.au>,
"David S. Miller" <davem@...emloft.net>
Cc: virtualization@...ts.linux.dev,
linux-crypto@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH v2 5/9] crypto: virtio: Remove AES specified marcro AES_BLOCK_SIZE
Macro AES_BLOCK_SIZE is meaningful only for algo AES, replace it
with generic API crypto_skcipher_blocksize(), so that new algo can
be added in later.
Signed-off-by: Bibo Mao <maobibo@...ngson.cn>
---
.../crypto/virtio/virtio_crypto_skcipher_algs.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
index 314ecda46311..7b3f21a40d78 100644
--- a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
+++ b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
@@ -416,8 +416,8 @@ __virtio_crypto_skcipher_do_req(struct virtio_crypto_sym_request *vc_sym_req,
memcpy(iv, req->iv, ivsize);
if (!vc_sym_req->encrypt)
scatterwalk_map_and_copy(req->iv, req->src,
- req->cryptlen - AES_BLOCK_SIZE,
- AES_BLOCK_SIZE, 0);
+ req->cryptlen - ivsize,
+ ivsize, 0);
sg_init_one(&iv_sg, iv, ivsize);
sgs[num_out++] = &iv_sg;
@@ -459,6 +459,7 @@ static int virtio_crypto_skcipher_encrypt(struct skcipher_request *req)
{
struct crypto_skcipher *atfm = crypto_skcipher_reqtfm(req);
struct virtio_crypto_skcipher_ctx *ctx = crypto_skcipher_ctx(atfm);
+ unsigned int blocksize = crypto_skcipher_blocksize(atfm);
struct virtio_crypto_sym_request *vc_sym_req =
skcipher_request_ctx(req);
struct virtio_crypto_request *vc_req = &vc_sym_req->base;
@@ -468,7 +469,7 @@ static int virtio_crypto_skcipher_encrypt(struct skcipher_request *req)
if (!req->cryptlen)
return 0;
- if (req->cryptlen % AES_BLOCK_SIZE)
+ if (req->cryptlen % blocksize)
return -EINVAL;
vc_req->dataq = data_vq;
@@ -482,6 +483,7 @@ static int virtio_crypto_skcipher_decrypt(struct skcipher_request *req)
{
struct crypto_skcipher *atfm = crypto_skcipher_reqtfm(req);
struct virtio_crypto_skcipher_ctx *ctx = crypto_skcipher_ctx(atfm);
+ unsigned int blocksize = crypto_skcipher_blocksize(atfm);
struct virtio_crypto_sym_request *vc_sym_req =
skcipher_request_ctx(req);
struct virtio_crypto_request *vc_req = &vc_sym_req->base;
@@ -491,7 +493,7 @@ static int virtio_crypto_skcipher_decrypt(struct skcipher_request *req)
if (!req->cryptlen)
return 0;
- if (req->cryptlen % AES_BLOCK_SIZE)
+ if (req->cryptlen % blocksize)
return -EINVAL;
vc_req->dataq = data_vq;
@@ -549,10 +551,13 @@ static void virtio_crypto_skcipher_finalize_req(
struct skcipher_request *req,
int err)
{
+ struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
+ unsigned int ivsize = crypto_skcipher_ivsize(tfm);
+
if (vc_sym_req->encrypt)
scatterwalk_map_and_copy(req->iv, req->dst,
- req->cryptlen - AES_BLOCK_SIZE,
- AES_BLOCK_SIZE, 0);
+ req->cryptlen - ivsize,
+ ivsize, 0);
kfree_sensitive(vc_sym_req->iv);
virtcrypto_clear_request(&vc_sym_req->base);
--
2.39.3
Powered by blists - more mailing lists