aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/algapi.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2006-12-16 18:05:58 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2007-02-06 17:21:01 -0500
commit2e306ee016fd4750289e65c3b1856db569f1f3f2 (patch)
tree53ace6081967c640f052d53397250657af855c25 /crypto/algapi.c
parentf1ddcaf3393b7a3871809b97fae90fac841a1f39 (diff)
[CRYPTO] api: Add type-safe spawns
This patch allows spawns of specific types (e.g., cipher) to be allocated. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/algapi.c')
-rw-r--r--crypto/algapi.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/crypto/algapi.c b/crypto/algapi.c
index 69eb504721a4..0f1abca1b98c 100644
--- a/crypto/algapi.c
+++ b/crypto/algapi.c
@@ -377,7 +377,8 @@ void crypto_drop_spawn(struct crypto_spawn *spawn)
377} 377}
378EXPORT_SYMBOL_GPL(crypto_drop_spawn); 378EXPORT_SYMBOL_GPL(crypto_drop_spawn);
379 379
380struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn) 380struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type,
381 u32 mask)
381{ 382{
382 struct crypto_alg *alg; 383 struct crypto_alg *alg;
383 struct crypto_alg *alg2; 384 struct crypto_alg *alg2;
@@ -396,10 +397,18 @@ struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn)
396 return ERR_PTR(-EAGAIN); 397 return ERR_PTR(-EAGAIN);
397 } 398 }
398 399
400 tfm = ERR_PTR(-EINVAL);
401 if (unlikely((alg->cra_flags ^ type) & mask))
402 goto out_put_alg;
403
399 tfm = __crypto_alloc_tfm(alg); 404 tfm = __crypto_alloc_tfm(alg);
400 if (IS_ERR(tfm)) 405 if (IS_ERR(tfm))
401 crypto_mod_put(alg); 406 goto out_put_alg;
407
408 return tfm;
402 409
410out_put_alg:
411 crypto_mod_put(alg);
403 return tfm; 412 return tfm;
404} 413}
405EXPORT_SYMBOL_GPL(crypto_spawn_tfm); 414EXPORT_SYMBOL_GPL(crypto_spawn_tfm);