crypto: virtio - Use new crypto_engine_op interface
[platform/kernel/linux-starfive.git] / drivers / crypto / virtio / virtio_crypto_akcipher_algs.c
index ff3369c..2621ff8 100644 (file)
@@ -7,15 +7,16 @@
   * Copyright 2022 Bytedance CO., LTD.
   */
 
-#include <linux/mpi.h>
-#include <linux/scatterlist.h>
-#include <crypto/algapi.h>
+#include <crypto/engine.h>
 #include <crypto/internal/akcipher.h>
 #include <crypto/internal/rsa.h>
-#include <linux/err.h>
 #include <crypto/scatterwalk.h>
-#include <linux/atomic.h>
-
+#include <linux/err.h>
+#include <linux/kernel.h>
+#include <linux/mpi.h>
+#include <linux/scatterlist.h>
+#include <linux/slab.h>
+#include <linux/string.h>
 #include <uapi/linux/virtio_crypto.h>
 #include "virtio_crypto_common.h"
 
@@ -24,7 +25,6 @@ struct virtio_crypto_rsa_ctx {
 };
 
 struct virtio_crypto_akcipher_ctx {
-       struct crypto_engine_ctx enginectx;
        struct virtio_crypto *vcrypto;
        struct crypto_akcipher *tfm;
        bool session_valid;
@@ -47,7 +47,7 @@ struct virtio_crypto_akcipher_algo {
        uint32_t algonum;
        uint32_t service;
        unsigned int active_devs;
-       struct akcipher_alg algo;
+       struct akcipher_engine_alg algo;
 };
 
 static DEFINE_MUTEX(algs_lock);
@@ -475,7 +475,6 @@ static int virtio_crypto_rsa_init_tfm(struct crypto_akcipher *tfm)
        struct virtio_crypto_akcipher_ctx *ctx = akcipher_tfm_ctx(tfm);
 
        ctx->tfm = tfm;
-       ctx->enginectx.op.do_one_request = virtio_crypto_rsa_do_req;
 
        akcipher_set_reqsize(tfm,
                             sizeof(struct virtio_crypto_akcipher_request));
@@ -498,7 +497,7 @@ static struct virtio_crypto_akcipher_algo virtio_crypto_akcipher_algs[] = {
        {
                .algonum = VIRTIO_CRYPTO_AKCIPHER_RSA,
                .service = VIRTIO_CRYPTO_SERVICE_AKCIPHER,
-               .algo = {
+               .algo.base = {
                        .encrypt = virtio_crypto_rsa_encrypt,
                        .decrypt = virtio_crypto_rsa_decrypt,
                        .set_pub_key = virtio_crypto_rsa_raw_set_pub_key,
@@ -514,11 +513,14 @@ static struct virtio_crypto_akcipher_algo virtio_crypto_akcipher_algs[] = {
                                .cra_ctxsize = sizeof(struct virtio_crypto_akcipher_ctx),
                        },
                },
+               .algo.op = {
+                       .do_one_request = virtio_crypto_rsa_do_req,
+               },
        },
        {
                .algonum = VIRTIO_CRYPTO_AKCIPHER_RSA,
                .service = VIRTIO_CRYPTO_SERVICE_AKCIPHER,
-               .algo = {
+               .algo.base = {
                        .encrypt = virtio_crypto_rsa_encrypt,
                        .decrypt = virtio_crypto_rsa_decrypt,
                        .sign = virtio_crypto_rsa_sign,
@@ -536,6 +538,9 @@ static struct virtio_crypto_akcipher_algo virtio_crypto_akcipher_algs[] = {
                                .cra_ctxsize = sizeof(struct virtio_crypto_akcipher_ctx),
                        },
                },
+               .algo.op = {
+                       .do_one_request = virtio_crypto_rsa_do_req,
+               },
        },
 };
 
@@ -554,14 +559,14 @@ int virtio_crypto_akcipher_algs_register(struct virtio_crypto *vcrypto)
                        continue;
 
                if (virtio_crypto_akcipher_algs[i].active_devs == 0) {
-                       ret = crypto_register_akcipher(&virtio_crypto_akcipher_algs[i].algo);
+                       ret = crypto_engine_register_akcipher(&virtio_crypto_akcipher_algs[i].algo);
                        if (ret)
                                goto unlock;
                }
 
                virtio_crypto_akcipher_algs[i].active_devs++;
                dev_info(&vcrypto->vdev->dev, "Registered akcipher algo %s\n",
-                        virtio_crypto_akcipher_algs[i].algo.base.cra_name);
+                        virtio_crypto_akcipher_algs[i].algo.base.base.cra_name);
        }
 
 unlock:
@@ -584,7 +589,7 @@ void virtio_crypto_akcipher_algs_unregister(struct virtio_crypto *vcrypto)
                        continue;
 
                if (virtio_crypto_akcipher_algs[i].active_devs == 1)
-                       crypto_unregister_akcipher(&virtio_crypto_akcipher_algs[i].algo);
+                       crypto_engine_unregister_akcipher(&virtio_crypto_akcipher_algs[i].algo);
 
                virtio_crypto_akcipher_algs[i].active_devs--;
        }