aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2009-07-14 02:06:06 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2009-07-14 03:54:09 -0400
commit01c2dece4316dadc0f9fad1ad0b56d493980e492 (patch)
tree0d28b58ef64c4b286351ff18adc96899baac5ab8
parent88056ec346ccf41f63dbc7080b24b5fd19d1358d (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.c72
-rw-r--r--include/crypto/internal/hash.h51
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}
260EXPORT_SYMBOL_GPL(crypto_alloc_ahash); 260EXPORT_SYMBOL_GPL(crypto_alloc_ahash);
261 261
262static 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
277int 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}
288EXPORT_SYMBOL_GPL(crypto_register_ahash);
289
290int crypto_unregister_ahash(struct ahash_alg *alg)
291{
292 return crypto_unregister_alg(&alg->halg.base);
293}
294EXPORT_SYMBOL_GPL(crypto_unregister_ahash);
295
296int 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}
307EXPORT_SYMBOL_GPL(ahash_register_instance);
308
309void ahash_free_instance(struct crypto_instance *inst)
310{
311 crypto_drop_spawn(crypto_instance_ctx(inst));
312 kfree(ahash_instance(inst));
313}
314EXPORT_SYMBOL_GPL(ahash_free_instance);
315
316int 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}
323EXPORT_SYMBOL_GPL(crypto_init_ahash_spawn);
324
325struct 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}
332EXPORT_SYMBOL_GPL(ahash_attr_alg);
333
262MODULE_LICENSE("GPL"); 334MODULE_LICENSE("GPL");
263MODULE_DESCRIPTION("Asynchronous cryptographic hash type"); 335MODULE_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
37struct ahash_instance {
38 struct ahash_alg alg;
39};
40
37struct shash_instance { 41struct shash_instance {
38 struct shash_alg alg; 42 struct shash_alg alg;
39}; 43};
40 44
45struct crypto_ahash_spawn {
46 struct crypto_spawn base;
47};
48
41struct crypto_shash_spawn { 49struct 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
54int crypto_register_ahash(struct ahash_alg *alg); 62int crypto_register_ahash(struct ahash_alg *alg);
55int crypto_unregister_ahash(struct ahash_alg *alg); 63int crypto_unregister_ahash(struct ahash_alg *alg);
64int ahash_register_instance(struct crypto_template *tmpl,
65 struct ahash_instance *inst);
66void ahash_free_instance(struct crypto_instance *inst);
67
68int crypto_init_ahash_spawn(struct crypto_ahash_spawn *spawn,
69 struct hash_alg_common *alg,
70 struct crypto_instance *inst);
71
72struct hash_alg_common *ahash_attr_alg(struct rtattr *rta, u32 type, u32 mask);
56 73
57int crypto_register_shash(struct shash_alg *alg); 74int crypto_register_shash(struct shash_alg *alg);
58int crypto_unregister_shash(struct shash_alg *alg); 75int 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
108static 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
114static 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
120static inline void *ahash_instance_ctx(struct ahash_instance *inst)
121{
122 return crypto_instance_ctx(ahash_crypto_instance(inst));
123}
124
125static inline unsigned int ahash_instance_headroom(void)
126{
127 return sizeof(struct ahash_alg) - sizeof(struct crypto_alg);
128}
129
130static 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
136static inline struct crypto_ahash *crypto_spawn_ahash(
137 struct crypto_ahash_spawn *spawn)
138{
139 return crypto_spawn_tfm2(&spawn->base);
140}
141
91static inline int ahash_enqueue_request(struct crypto_queue *queue, 142static inline int ahash_enqueue_request(struct crypto_queue *queue,
92 struct ahash_request *request) 143 struct ahash_request *request)
93{ 144{