diff options
Diffstat (limited to 'include/crypto/algapi.h')
-rw-r--r-- | include/crypto/algapi.h | 84 |
1 files changed, 80 insertions, 4 deletions
diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index 4e05e93ff681..b2b1e6efd812 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h | |||
@@ -13,8 +13,11 @@ | |||
13 | #define _CRYPTO_ALGAPI_H | 13 | #define _CRYPTO_ALGAPI_H |
14 | 14 | ||
15 | #include <linux/crypto.h> | 15 | #include <linux/crypto.h> |
16 | #include <linux/list.h> | ||
17 | #include <linux/kernel.h> | ||
16 | 18 | ||
17 | struct module; | 19 | struct module; |
20 | struct rtattr; | ||
18 | struct seq_file; | 21 | struct seq_file; |
19 | 22 | ||
20 | struct crypto_type { | 23 | struct crypto_type { |
@@ -38,7 +41,7 @@ struct crypto_template { | |||
38 | struct hlist_head instances; | 41 | struct hlist_head instances; |
39 | struct module *module; | 42 | struct module *module; |
40 | 43 | ||
41 | struct crypto_instance *(*alloc)(void *param, unsigned int len); | 44 | struct crypto_instance *(*alloc)(struct rtattr **tb); |
42 | void (*free)(struct crypto_instance *inst); | 45 | void (*free)(struct crypto_instance *inst); |
43 | 46 | ||
44 | char name[CRYPTO_MAX_ALG_NAME]; | 47 | char name[CRYPTO_MAX_ALG_NAME]; |
@@ -48,6 +51,15 @@ struct crypto_spawn { | |||
48 | struct list_head list; | 51 | struct list_head list; |
49 | struct crypto_alg *alg; | 52 | struct crypto_alg *alg; |
50 | struct crypto_instance *inst; | 53 | struct crypto_instance *inst; |
54 | u32 mask; | ||
55 | }; | ||
56 | |||
57 | struct crypto_queue { | ||
58 | struct list_head list; | ||
59 | struct list_head *backlog; | ||
60 | |||
61 | unsigned int qlen; | ||
62 | unsigned int max_qlen; | ||
51 | }; | 63 | }; |
52 | 64 | ||
53 | struct scatter_walk { | 65 | struct scatter_walk { |
@@ -81,6 +93,7 @@ struct blkcipher_walk { | |||
81 | int flags; | 93 | int flags; |
82 | }; | 94 | }; |
83 | 95 | ||
96 | extern const struct crypto_type crypto_ablkcipher_type; | ||
84 | extern const struct crypto_type crypto_blkcipher_type; | 97 | extern const struct crypto_type crypto_blkcipher_type; |
85 | extern const struct crypto_type crypto_hash_type; | 98 | extern const struct crypto_type crypto_hash_type; |
86 | 99 | ||
@@ -91,16 +104,23 @@ void crypto_unregister_template(struct crypto_template *tmpl); | |||
91 | struct crypto_template *crypto_lookup_template(const char *name); | 104 | struct crypto_template *crypto_lookup_template(const char *name); |
92 | 105 | ||
93 | int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg, | 106 | int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg, |
94 | struct crypto_instance *inst); | 107 | struct crypto_instance *inst, u32 mask); |
95 | void crypto_drop_spawn(struct crypto_spawn *spawn); | 108 | void crypto_drop_spawn(struct crypto_spawn *spawn); |
96 | struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type, | 109 | struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type, |
97 | u32 mask); | 110 | u32 mask); |
98 | 111 | ||
99 | struct crypto_alg *crypto_get_attr_alg(void *param, unsigned int len, | 112 | struct crypto_attr_type *crypto_get_attr_type(struct rtattr **tb); |
100 | u32 type, u32 mask); | 113 | int crypto_check_attr_type(struct rtattr **tb, u32 type); |
114 | struct crypto_alg *crypto_get_attr_alg(struct rtattr **tb, u32 type, u32 mask); | ||
101 | struct crypto_instance *crypto_alloc_instance(const char *name, | 115 | struct crypto_instance *crypto_alloc_instance(const char *name, |
102 | struct crypto_alg *alg); | 116 | struct crypto_alg *alg); |
103 | 117 | ||
118 | void crypto_init_queue(struct crypto_queue *queue, unsigned int max_qlen); | ||
119 | int crypto_enqueue_request(struct crypto_queue *queue, | ||
120 | struct crypto_async_request *request); | ||
121 | struct crypto_async_request *crypto_dequeue_request(struct crypto_queue *queue); | ||
122 | int crypto_tfm_in_queue(struct crypto_queue *queue, struct crypto_tfm *tfm); | ||
123 | |||
104 | int blkcipher_walk_done(struct blkcipher_desc *desc, | 124 | int blkcipher_walk_done(struct blkcipher_desc *desc, |
105 | struct blkcipher_walk *walk, int err); | 125 | struct blkcipher_walk *walk, int err); |
106 | int blkcipher_walk_virt(struct blkcipher_desc *desc, | 126 | int blkcipher_walk_virt(struct blkcipher_desc *desc, |
@@ -118,11 +138,37 @@ static inline void *crypto_tfm_ctx_aligned(struct crypto_tfm *tfm) | |||
118 | return (void *)ALIGN(addr, align); | 138 | return (void *)ALIGN(addr, align); |
119 | } | 139 | } |
120 | 140 | ||
141 | static inline struct crypto_instance *crypto_tfm_alg_instance( | ||
142 | struct crypto_tfm *tfm) | ||
143 | { | ||
144 | return container_of(tfm->__crt_alg, struct crypto_instance, alg); | ||
145 | } | ||
146 | |||
121 | static inline void *crypto_instance_ctx(struct crypto_instance *inst) | 147 | static inline void *crypto_instance_ctx(struct crypto_instance *inst) |
122 | { | 148 | { |
123 | return inst->__ctx; | 149 | return inst->__ctx; |
124 | } | 150 | } |
125 | 151 | ||
152 | static inline struct ablkcipher_alg *crypto_ablkcipher_alg( | ||
153 | struct crypto_ablkcipher *tfm) | ||
154 | { | ||
155 | return &crypto_ablkcipher_tfm(tfm)->__crt_alg->cra_ablkcipher; | ||
156 | } | ||
157 | |||
158 | static inline void *crypto_ablkcipher_ctx(struct crypto_ablkcipher *tfm) | ||
159 | { | ||
160 | return crypto_tfm_ctx(&tfm->base); | ||
161 | } | ||
162 | |||
163 | static inline struct crypto_blkcipher *crypto_spawn_blkcipher( | ||
164 | struct crypto_spawn *spawn) | ||
165 | { | ||
166 | u32 type = CRYPTO_ALG_TYPE_BLKCIPHER; | ||
167 | u32 mask = CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC; | ||
168 | |||
169 | return __crypto_blkcipher_cast(crypto_spawn_tfm(spawn, type, mask)); | ||
170 | } | ||
171 | |||
126 | static inline void *crypto_blkcipher_ctx(struct crypto_blkcipher *tfm) | 172 | static inline void *crypto_blkcipher_ctx(struct crypto_blkcipher *tfm) |
127 | { | 173 | { |
128 | return crypto_tfm_ctx(&tfm->base); | 174 | return crypto_tfm_ctx(&tfm->base); |
@@ -170,5 +216,35 @@ static inline void blkcipher_walk_init(struct blkcipher_walk *walk, | |||
170 | walk->total = nbytes; | 216 | walk->total = nbytes; |
171 | } | 217 | } |
172 | 218 | ||
219 | static inline struct crypto_async_request *crypto_get_backlog( | ||
220 | struct crypto_queue *queue) | ||
221 | { | ||
222 | return queue->backlog == &queue->list ? NULL : | ||
223 | container_of(queue->backlog, struct crypto_async_request, list); | ||
224 | } | ||
225 | |||
226 | static inline int ablkcipher_enqueue_request(struct ablkcipher_alg *alg, | ||
227 | struct ablkcipher_request *request) | ||
228 | { | ||
229 | return crypto_enqueue_request(alg->queue, &request->base); | ||
230 | } | ||
231 | |||
232 | static inline struct ablkcipher_request *ablkcipher_dequeue_request( | ||
233 | struct ablkcipher_alg *alg) | ||
234 | { | ||
235 | return ablkcipher_request_cast(crypto_dequeue_request(alg->queue)); | ||
236 | } | ||
237 | |||
238 | static inline void *ablkcipher_request_ctx(struct ablkcipher_request *req) | ||
239 | { | ||
240 | return req->__ctx; | ||
241 | } | ||
242 | |||
243 | static inline int ablkcipher_tfm_in_queue(struct crypto_ablkcipher *tfm) | ||
244 | { | ||
245 | return crypto_tfm_in_queue(crypto_ablkcipher_alg(tfm)->queue, | ||
246 | crypto_ablkcipher_tfm(tfm)); | ||
247 | } | ||
248 | |||
173 | #endif /* _CRYPTO_ALGAPI_H */ | 249 | #endif /* _CRYPTO_ALGAPI_H */ |
174 | 250 | ||