1
2
3
4
5
6
7 #ifndef _CRYPTO_ENGINE_H
8 #define _CRYPTO_ENGINE_H
9
10 #include <linux/crypto.h>
11 #include <linux/list.h>
12 #include <linux/kernel.h>
13 #include <linux/kthread.h>
14 #include <crypto/algapi.h>
15 #include <crypto/aead.h>
16 #include <crypto/akcipher.h>
17 #include <crypto/hash.h>
18 #include <crypto/skcipher.h>
19
20 #define ENGINE_NAME_LEN 30
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 struct crypto_engine {
44 char name[ENGINE_NAME_LEN];
45 bool idling;
46 bool busy;
47 bool running;
48 bool cur_req_prepared;
49
50 struct list_head list;
51 spinlock_t queue_lock;
52 struct crypto_queue queue;
53 struct device *dev;
54
55 bool rt;
56
57 int (*prepare_crypt_hardware)(struct crypto_engine *engine);
58 int (*unprepare_crypt_hardware)(struct crypto_engine *engine);
59
60 struct kthread_worker *kworker;
61 struct kthread_work pump_requests;
62
63 void *priv_data;
64 struct crypto_async_request *cur_req;
65 };
66
67
68
69
70
71
72
73 struct crypto_engine_op {
74 int (*prepare_request)(struct crypto_engine *engine,
75 void *areq);
76 int (*unprepare_request)(struct crypto_engine *engine,
77 void *areq);
78 int (*do_one_request)(struct crypto_engine *engine,
79 void *areq);
80 };
81
82 struct crypto_engine_ctx {
83 struct crypto_engine_op op;
84 };
85
86 int crypto_transfer_ablkcipher_request_to_engine(struct crypto_engine *engine,
87 struct ablkcipher_request *req);
88 int crypto_transfer_aead_request_to_engine(struct crypto_engine *engine,
89 struct aead_request *req);
90 int crypto_transfer_akcipher_request_to_engine(struct crypto_engine *engine,
91 struct akcipher_request *req);
92 int crypto_transfer_hash_request_to_engine(struct crypto_engine *engine,
93 struct ahash_request *req);
94 int crypto_transfer_skcipher_request_to_engine(struct crypto_engine *engine,
95 struct skcipher_request *req);
96 void crypto_finalize_ablkcipher_request(struct crypto_engine *engine,
97 struct ablkcipher_request *req, int err);
98 void crypto_finalize_aead_request(struct crypto_engine *engine,
99 struct aead_request *req, int err);
100 void crypto_finalize_akcipher_request(struct crypto_engine *engine,
101 struct akcipher_request *req, int err);
102 void crypto_finalize_hash_request(struct crypto_engine *engine,
103 struct ahash_request *req, int err);
104 void crypto_finalize_skcipher_request(struct crypto_engine *engine,
105 struct skcipher_request *req, int err);
106 int crypto_engine_start(struct crypto_engine *engine);
107 int crypto_engine_stop(struct crypto_engine *engine);
108 struct crypto_engine *crypto_engine_alloc_init(struct device *dev, bool rt);
109 int crypto_engine_exit(struct crypto_engine *engine);
110
111 #endif