Structure virtio_crypto_skcipher_ctx is allocated together with crypto_skcipher, and skcipher_alg is set in strucutre crypto_skcipher when it is created. Here add virtio_crypto_algo pointer in virtio_crypto_skcipher_ctx and set it in function virtio_crypto_skcipher_init(). So crypto service and algo can be acquired from virtio_crypto_algo pointer. Signed-off-by: Bibo Mao --- .../virtio/virtio_crypto_skcipher_algs.c | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c index 11053d1786d4..8a139de3d064 100644 --- a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c +++ b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c @@ -15,9 +15,11 @@ #include "virtio_crypto_common.h" +struct virtio_crypto_algo; struct virtio_crypto_skcipher_ctx { struct virtio_crypto *vcrypto; + struct virtio_crypto_algo *alg; struct virtio_crypto_sym_session_info enc_sess_info; struct virtio_crypto_sym_session_info dec_sess_info; }; @@ -108,9 +110,7 @@ virtio_crypto_alg_validate_key(int key_len, uint32_t *alg) static int virtio_crypto_alg_skcipher_init_session( struct virtio_crypto_skcipher_ctx *ctx, - uint32_t alg, const uint8_t *key, - unsigned int keylen, - int encrypt) + const uint8_t *key, unsigned int keylen, int encrypt) { struct scatterlist outhdr, key_sg, inhdr, *sgs[3]; struct virtio_crypto *vcrypto = ctx->vcrypto; @@ -140,7 +140,7 @@ static int virtio_crypto_alg_skcipher_init_session( /* Pad ctrl header */ ctrl = &vc_ctrl_req->ctrl; ctrl->header.opcode = cpu_to_le32(VIRTIO_CRYPTO_CIPHER_CREATE_SESSION); - ctrl->header.algo = cpu_to_le32(alg); + ctrl->header.algo = cpu_to_le32(ctx->alg->algonum); /* Set the default dataqueue id to 0 */ ctrl->header.queue_id = 0; @@ -261,13 +261,11 @@ static int virtio_crypto_alg_skcipher_init_sessions( return -EINVAL; /* Create encryption session */ - ret = virtio_crypto_alg_skcipher_init_session(ctx, - alg, key, keylen, 1); + ret = virtio_crypto_alg_skcipher_init_session(ctx, key, keylen, 1); if (ret) return ret; /* Create decryption session */ - ret = virtio_crypto_alg_skcipher_init_session(ctx, - alg, key, keylen, 0); + ret = virtio_crypto_alg_skcipher_init_session(ctx, key, keylen, 0); if (ret) { virtio_crypto_alg_skcipher_close_session(ctx, 1); return ret; @@ -293,7 +291,7 @@ static int virtio_crypto_skcipher_setkey(struct crypto_skcipher *tfm, int node = virtio_crypto_get_current_node(); struct virtio_crypto *vcrypto = virtcrypto_get_dev_node(node, - VIRTIO_CRYPTO_SERVICE_CIPHER, alg); + ctx->alg->service, ctx->alg->algonum); if (!vcrypto) { pr_err("virtio_crypto: Could not find a virtio device in the system or unsupported algo\n"); return -ENODEV; @@ -509,7 +507,11 @@ static int virtio_crypto_skcipher_decrypt(struct skcipher_request *req) static int virtio_crypto_skcipher_init(struct crypto_skcipher *tfm) { + struct virtio_crypto_skcipher_ctx *ctx = crypto_skcipher_ctx(tfm); + struct skcipher_alg *alg = crypto_skcipher_alg(tfm); + crypto_skcipher_set_reqsize(tfm, sizeof(struct virtio_crypto_sym_request)); + ctx->alg = container_of(alg, struct virtio_crypto_algo, algo.base); return 0; } -- 2.39.3