Skip to content

Commit 7a2673d

Browse files
committed
crypto: virtio - Use new crypto_engine_op interface
Use the new crypto_engine_op interface where the callback is stored in the algorithm object. Signed-off-by: Herbert Xu <[email protected]>
1 parent d5e6b48 commit 7a2673d

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

drivers/crypto/virtio/virtio_crypto_akcipher_algs.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
* Copyright 2022 Bytedance CO., LTD.
88
*/
99

10-
#include <linux/mpi.h>
11-
#include <linux/scatterlist.h>
12-
#include <crypto/algapi.h>
10+
#include <crypto/engine.h>
1311
#include <crypto/internal/akcipher.h>
1412
#include <crypto/internal/rsa.h>
15-
#include <linux/err.h>
1613
#include <crypto/scatterwalk.h>
17-
#include <linux/atomic.h>
18-
14+
#include <linux/err.h>
15+
#include <linux/kernel.h>
16+
#include <linux/mpi.h>
17+
#include <linux/scatterlist.h>
18+
#include <linux/slab.h>
19+
#include <linux/string.h>
1920
#include <uapi/linux/virtio_crypto.h>
2021
#include "virtio_crypto_common.h"
2122

@@ -24,7 +25,6 @@ struct virtio_crypto_rsa_ctx {
2425
};
2526

2627
struct virtio_crypto_akcipher_ctx {
27-
struct crypto_engine_ctx enginectx;
2828
struct virtio_crypto *vcrypto;
2929
struct crypto_akcipher *tfm;
3030
bool session_valid;
@@ -47,7 +47,7 @@ struct virtio_crypto_akcipher_algo {
4747
uint32_t algonum;
4848
uint32_t service;
4949
unsigned int active_devs;
50-
struct akcipher_alg algo;
50+
struct akcipher_engine_alg algo;
5151
};
5252

5353
static DEFINE_MUTEX(algs_lock);
@@ -475,7 +475,6 @@ static int virtio_crypto_rsa_init_tfm(struct crypto_akcipher *tfm)
475475
struct virtio_crypto_akcipher_ctx *ctx = akcipher_tfm_ctx(tfm);
476476

477477
ctx->tfm = tfm;
478-
ctx->enginectx.op.do_one_request = virtio_crypto_rsa_do_req;
479478

480479
akcipher_set_reqsize(tfm,
481480
sizeof(struct virtio_crypto_akcipher_request));
@@ -498,7 +497,7 @@ static struct virtio_crypto_akcipher_algo virtio_crypto_akcipher_algs[] = {
498497
{
499498
.algonum = VIRTIO_CRYPTO_AKCIPHER_RSA,
500499
.service = VIRTIO_CRYPTO_SERVICE_AKCIPHER,
501-
.algo = {
500+
.algo.base = {
502501
.encrypt = virtio_crypto_rsa_encrypt,
503502
.decrypt = virtio_crypto_rsa_decrypt,
504503
.set_pub_key = virtio_crypto_rsa_raw_set_pub_key,
@@ -514,11 +513,14 @@ static struct virtio_crypto_akcipher_algo virtio_crypto_akcipher_algs[] = {
514513
.cra_ctxsize = sizeof(struct virtio_crypto_akcipher_ctx),
515514
},
516515
},
516+
.algo.op = {
517+
.do_one_request = virtio_crypto_rsa_do_req,
518+
},
517519
},
518520
{
519521
.algonum = VIRTIO_CRYPTO_AKCIPHER_RSA,
520522
.service = VIRTIO_CRYPTO_SERVICE_AKCIPHER,
521-
.algo = {
523+
.algo.base = {
522524
.encrypt = virtio_crypto_rsa_encrypt,
523525
.decrypt = virtio_crypto_rsa_decrypt,
524526
.sign = virtio_crypto_rsa_sign,
@@ -536,6 +538,9 @@ static struct virtio_crypto_akcipher_algo virtio_crypto_akcipher_algs[] = {
536538
.cra_ctxsize = sizeof(struct virtio_crypto_akcipher_ctx),
537539
},
538540
},
541+
.algo.op = {
542+
.do_one_request = virtio_crypto_rsa_do_req,
543+
},
539544
},
540545
};
541546

@@ -554,14 +559,14 @@ int virtio_crypto_akcipher_algs_register(struct virtio_crypto *vcrypto)
554559
continue;
555560

556561
if (virtio_crypto_akcipher_algs[i].active_devs == 0) {
557-
ret = crypto_register_akcipher(&virtio_crypto_akcipher_algs[i].algo);
562+
ret = crypto_engine_register_akcipher(&virtio_crypto_akcipher_algs[i].algo);
558563
if (ret)
559564
goto unlock;
560565
}
561566

562567
virtio_crypto_akcipher_algs[i].active_devs++;
563568
dev_info(&vcrypto->vdev->dev, "Registered akcipher algo %s\n",
564-
virtio_crypto_akcipher_algs[i].algo.base.cra_name);
569+
virtio_crypto_akcipher_algs[i].algo.base.base.cra_name);
565570
}
566571

567572
unlock:
@@ -584,7 +589,7 @@ void virtio_crypto_akcipher_algs_unregister(struct virtio_crypto *vcrypto)
584589
continue;
585590

586591
if (virtio_crypto_akcipher_algs[i].active_devs == 1)
587-
crypto_unregister_akcipher(&virtio_crypto_akcipher_algs[i].algo);
592+
crypto_engine_unregister_akcipher(&virtio_crypto_akcipher_algs[i].algo);
588593

589594
virtio_crypto_akcipher_algs[i].active_devs--;
590595
}

drivers/crypto/virtio/virtio_crypto_skcipher_algs.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
66
* Copyright 2016 HUAWEI TECHNOLOGIES CO., LTD.
77
*/
88

9-
#include <linux/scatterlist.h>
10-
#include <crypto/algapi.h>
9+
#include <crypto/engine.h>
1110
#include <crypto/internal/skcipher.h>
12-
#include <linux/err.h>
1311
#include <crypto/scatterwalk.h>
14-
#include <linux/atomic.h>
15-
12+
#include <linux/err.h>
13+
#include <linux/scatterlist.h>
1614
#include <uapi/linux/virtio_crypto.h>
1715
#include "virtio_crypto_common.h"
1816

1917

2018
struct virtio_crypto_skcipher_ctx {
21-
struct crypto_engine_ctx enginectx;
2219
struct virtio_crypto *vcrypto;
2320
struct crypto_skcipher *tfm;
2421

@@ -42,7 +39,7 @@ struct virtio_crypto_algo {
4239
uint32_t algonum;
4340
uint32_t service;
4441
unsigned int active_devs;
45-
struct skcipher_alg algo;
42+
struct skcipher_engine_alg algo;
4643
};
4744

4845
/*
@@ -523,7 +520,6 @@ static int virtio_crypto_skcipher_init(struct crypto_skcipher *tfm)
523520
crypto_skcipher_set_reqsize(tfm, sizeof(struct virtio_crypto_sym_request));
524521
ctx->tfm = tfm;
525522

526-
ctx->enginectx.op.do_one_request = virtio_crypto_skcipher_crypt_req;
527523
return 0;
528524
}
529525

@@ -578,7 +574,7 @@ static void virtio_crypto_skcipher_finalize_req(
578574
static struct virtio_crypto_algo virtio_crypto_algs[] = { {
579575
.algonum = VIRTIO_CRYPTO_CIPHER_AES_CBC,
580576
.service = VIRTIO_CRYPTO_SERVICE_CIPHER,
581-
.algo = {
577+
.algo.base = {
582578
.base.cra_name = "cbc(aes)",
583579
.base.cra_driver_name = "virtio_crypto_aes_cbc",
584580
.base.cra_priority = 150,
@@ -596,6 +592,9 @@ static struct virtio_crypto_algo virtio_crypto_algs[] = { {
596592
.max_keysize = AES_MAX_KEY_SIZE,
597593
.ivsize = AES_BLOCK_SIZE,
598594
},
595+
.algo.op = {
596+
.do_one_request = virtio_crypto_skcipher_crypt_req,
597+
},
599598
} };
600599

601600
int virtio_crypto_skcipher_algs_register(struct virtio_crypto *vcrypto)
@@ -614,14 +613,14 @@ int virtio_crypto_skcipher_algs_register(struct virtio_crypto *vcrypto)
614613
continue;
615614

616615
if (virtio_crypto_algs[i].active_devs == 0) {
617-
ret = crypto_register_skcipher(&virtio_crypto_algs[i].algo);
616+
ret = crypto_engine_register_skcipher(&virtio_crypto_algs[i].algo);
618617
if (ret)
619618
goto unlock;
620619
}
621620

622621
virtio_crypto_algs[i].active_devs++;
623622
dev_info(&vcrypto->vdev->dev, "Registered algo %s\n",
624-
virtio_crypto_algs[i].algo.base.cra_name);
623+
virtio_crypto_algs[i].algo.base.base.cra_name);
625624
}
626625

627626
unlock:
@@ -645,7 +644,7 @@ void virtio_crypto_skcipher_algs_unregister(struct virtio_crypto *vcrypto)
645644
continue;
646645

647646
if (virtio_crypto_algs[i].active_devs == 1)
648-
crypto_unregister_skcipher(&virtio_crypto_algs[i].algo);
647+
crypto_engine_unregister_skcipher(&virtio_crypto_algs[i].algo);
649648

650649
virtio_crypto_algs[i].active_devs--;
651650
}

0 commit comments

Comments
 (0)