diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2009-07-14 02:06:06 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2009-07-14 03:54:09 -0400 |
commit | 01c2dece4316dadc0f9fad1ad0b56d493980e492 (patch) | |
tree | 0d28b58ef64c4b286351ff18adc96899baac5ab8 | |
parent | 88056ec346ccf41f63dbc7080b24b5fd19d1358d (diff) |
crypto: ahash - Add instance/spawn support
This patch adds support for creating ahash instances and using
ahash as spawns.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/ahash.c | 72 | ||||
-rw-r--r-- | include/crypto/internal/hash.h | 51 |
2 files changed, 123 insertions, 0 deletions
diff --git a/crypto/ahash.c b/crypto/ahash.c index 838519386215..7f599d26086a 100644 --- a/crypto/ahash.c +++ b/crypto/ahash.c | |||
@@ -259,5 +259,77 @@ struct crypto_ahash *crypto_alloc_ahash(const char *alg_name, u32 type, | |||
259 | } | 259 | } |
260 | EXPORT_SYMBOL_GPL(crypto_alloc_ahash); | 260 | EXPORT_SYMBOL_GPL(crypto_alloc_ahash); |
261 | 261 | ||
262 | static int ahash_prepare_alg(struct ahash_alg *alg) | ||
263 | { | ||
264 | struct crypto_alg *base = &alg->halg.base; | ||
265 | |||
266 | if (alg->halg.digestsize > PAGE_SIZE / 8 || | ||
267 | alg->halg.statesize > PAGE_SIZE / 8) | ||
268 | return -EINVAL; | ||
269 | |||
270 | base->cra_type = &crypto_ahash_type; | ||
271 | base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK; | ||
272 | base->cra_flags |= CRYPTO_ALG_TYPE_AHASH; | ||
273 | |||
274 | return 0; | ||
275 | } | ||
276 | |||
277 | int crypto_register_ahash(struct ahash_alg *alg) | ||
278 | { | ||
279 | struct crypto_alg *base = &alg->halg.base; | ||
280 | int err; | ||
281 | |||
282 | err = ahash_prepare_alg(alg); | ||
283 | if (err) | ||
284 | return err; | ||
285 | |||
286 | return crypto_register_alg(base); | ||
287 | } | ||
288 | EXPORT_SYMBOL_GPL(crypto_register_ahash); | ||
289 | |||
290 | int crypto_unregister_ahash(struct ahash_alg *alg) | ||
291 | { | ||
292 | return crypto_unregister_alg(&alg->halg.base); | ||
293 | } | ||
294 | EXPORT_SYMBOL_GPL(crypto_unregister_ahash); | ||
295 | |||
296 | int ahash_register_instance(struct crypto_template *tmpl, | ||
297 | struct ahash_instance *inst) | ||
298 | { | ||
299 | int err; | ||
300 | |||
301 | err = ahash_prepare_alg(&inst->alg); | ||
302 | if (err) | ||
303 | return err; | ||
304 | |||
305 | return crypto_register_instance(tmpl, ahash_crypto_instance(inst)); | ||
306 | } | ||
307 | EXPORT_SYMBOL_GPL(ahash_register_instance); | ||
308 | |||
309 | void ahash_free_instance(struct crypto_instance *inst) | ||
310 | { | ||
311 | crypto_drop_spawn(crypto_instance_ctx(inst)); | ||
312 | kfree(ahash_instance(inst)); | ||
313 | } | ||
314 | EXPORT_SYMBOL_GPL(ahash_free_instance); | ||
315 | |||
316 | int crypto_init_ahash_spawn(struct crypto_ahash_spawn *spawn, | ||
317 | struct hash_alg_common *alg, | ||
318 | struct crypto_instance *inst) | ||
319 | { | ||
320 | return crypto_init_spawn2(&spawn->base, &alg->base, inst, | ||
321 | &crypto_ahash_type); | ||
322 | } | ||
323 | EXPORT_SYMBOL_GPL(crypto_init_ahash_spawn); | ||
324 | |||
325 | struct hash_alg_common *ahash_attr_alg(struct rtattr *rta, u32 type, u32 mask) | ||
326 | { | ||
327 | struct crypto_alg *alg; | ||
328 | |||
329 | alg = crypto_attr_alg2(rta, &crypto_ahash_type, type, mask); | ||
330 | return IS_ERR(alg) ? ERR_CAST(alg) : __crypto_hash_alg_common(alg); | ||
331 | } | ||
332 | EXPORT_SYMBOL_GPL(ahash_attr_alg); | ||
333 | |||
262 | MODULE_LICENSE("GPL"); | 334 | MODULE_LICENSE("GPL"); |
263 | MODULE_DESCRIPTION("Asynchronous cryptographic hash type"); | 335 | MODULE_DESCRIPTION("Asynchronous cryptographic hash type"); |
diff --git a/include/crypto/internal/hash.h b/include/crypto/internal/hash.h index 08bdffafefad..34eda233ee67 100644 --- a/include/crypto/internal/hash.h +++ b/include/crypto/internal/hash.h | |||
@@ -34,10 +34,18 @@ struct crypto_hash_walk { | |||
34 | unsigned int flags; | 34 | unsigned int flags; |
35 | }; | 35 | }; |
36 | 36 | ||
37 | struct ahash_instance { | ||
38 | struct ahash_alg alg; | ||
39 | }; | ||
40 | |||
37 | struct shash_instance { | 41 | struct shash_instance { |
38 | struct shash_alg alg; | 42 | struct shash_alg alg; |
39 | }; | 43 | }; |
40 | 44 | ||
45 | struct crypto_ahash_spawn { | ||
46 | struct crypto_spawn base; | ||
47 | }; | ||
48 | |||
41 | struct crypto_shash_spawn { | 49 | struct crypto_shash_spawn { |
42 | struct crypto_spawn base; | 50 | struct crypto_spawn base; |
43 | }; | 51 | }; |
@@ -53,6 +61,15 @@ int crypto_hash_walk_first_compat(struct hash_desc *hdesc, | |||
53 | 61 | ||
54 | int crypto_register_ahash(struct ahash_alg *alg); | 62 | int crypto_register_ahash(struct ahash_alg *alg); |
55 | int crypto_unregister_ahash(struct ahash_alg *alg); | 63 | int crypto_unregister_ahash(struct ahash_alg *alg); |
64 | int ahash_register_instance(struct crypto_template *tmpl, | ||
65 | struct ahash_instance *inst); | ||
66 | void ahash_free_instance(struct crypto_instance *inst); | ||
67 | |||
68 | int crypto_init_ahash_spawn(struct crypto_ahash_spawn *spawn, | ||
69 | struct hash_alg_common *alg, | ||
70 | struct crypto_instance *inst); | ||
71 | |||
72 | struct hash_alg_common *ahash_attr_alg(struct rtattr *rta, u32 type, u32 mask); | ||
56 | 73 | ||
57 | int crypto_register_shash(struct shash_alg *alg); | 74 | int crypto_register_shash(struct shash_alg *alg); |
58 | int crypto_unregister_shash(struct shash_alg *alg); | 75 | int crypto_unregister_shash(struct shash_alg *alg); |
@@ -88,6 +105,40 @@ static inline void crypto_ahash_set_reqsize(struct crypto_ahash *tfm, | |||
88 | tfm->reqsize = reqsize; | 105 | tfm->reqsize = reqsize; |
89 | } | 106 | } |
90 | 107 | ||
108 | static inline struct crypto_instance *ahash_crypto_instance( | ||
109 | struct ahash_instance *inst) | ||
110 | { | ||
111 | return container_of(&inst->alg.halg.base, struct crypto_instance, alg); | ||
112 | } | ||
113 | |||
114 | static inline struct ahash_instance *ahash_instance( | ||
115 | struct crypto_instance *inst) | ||
116 | { | ||
117 | return container_of(&inst->alg, struct ahash_instance, alg.halg.base); | ||
118 | } | ||
119 | |||
120 | static inline void *ahash_instance_ctx(struct ahash_instance *inst) | ||
121 | { | ||
122 | return crypto_instance_ctx(ahash_crypto_instance(inst)); | ||
123 | } | ||
124 | |||
125 | static inline unsigned int ahash_instance_headroom(void) | ||
126 | { | ||
127 | return sizeof(struct ahash_alg) - sizeof(struct crypto_alg); | ||
128 | } | ||
129 | |||
130 | static inline struct ahash_instance *ahash_alloc_instance( | ||
131 | const char *name, struct crypto_alg *alg) | ||
132 | { | ||
133 | return crypto_alloc_instance2(name, alg, ahash_instance_headroom()); | ||
134 | } | ||
135 | |||
136 | static inline struct crypto_ahash *crypto_spawn_ahash( | ||
137 | struct crypto_ahash_spawn *spawn) | ||
138 | { | ||
139 | return crypto_spawn_tfm2(&spawn->base); | ||
140 | } | ||
141 | |||
91 | static inline int ahash_enqueue_request(struct crypto_queue *queue, | 142 | static inline int ahash_enqueue_request(struct crypto_queue *queue, |
92 | struct ahash_request *request) | 143 | struct ahash_request *request) |
93 | { | 144 | { |