diff options
Diffstat (limited to 'crypto/ahash.c')
-rw-r--r-- | crypto/ahash.c | 72 |
1 files changed, 72 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"); |