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