aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2009-07-08 03:55:52 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2009-07-08 06:57:10 -0400
commit97eedce1a64a57648ac5e39f03825528c47ba72e (patch)
tree5dea863a2b51b01b8e436d4e395ef15ae3f4bcd9 /crypto
parent2e4fddd8e420e8f531a34e7a97f9cdb851a6ad13 (diff)
crypto: api - Add new style spawn support
This patch modifies the spawn infrastructure to support new style algorithms like shash. In particular, this means storing the frontend type in the spawn and using crypto_create_tfm to allocate the tfm. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/algapi.c55
1 files changed, 52 insertions, 3 deletions
diff --git a/crypto/algapi.c b/crypto/algapi.c
index 429f1a003b06..17a5fff8f777 100644
--- a/crypto/algapi.c
+++ b/crypto/algapi.c
@@ -488,6 +488,23 @@ int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg,
488} 488}
489EXPORT_SYMBOL_GPL(crypto_init_spawn); 489EXPORT_SYMBOL_GPL(crypto_init_spawn);
490 490
491int crypto_init_spawn2(struct crypto_spawn *spawn, struct crypto_alg *alg,
492 struct crypto_instance *inst,
493 const struct crypto_type *frontend)
494{
495 int err = -EINVAL;
496
497 if (frontend && (alg->cra_flags ^ frontend->type) & frontend->maskset)
498 goto out;
499
500 spawn->frontend = frontend;
501 err = crypto_init_spawn(spawn, alg, inst, frontend->maskset);
502
503out:
504 return err;
505}
506EXPORT_SYMBOL_GPL(crypto_init_spawn2);
507
491void crypto_drop_spawn(struct crypto_spawn *spawn) 508void crypto_drop_spawn(struct crypto_spawn *spawn)
492{ 509{
493 down_write(&crypto_alg_sem); 510 down_write(&crypto_alg_sem);
@@ -496,12 +513,10 @@ void crypto_drop_spawn(struct crypto_spawn *spawn)
496} 513}
497EXPORT_SYMBOL_GPL(crypto_drop_spawn); 514EXPORT_SYMBOL_GPL(crypto_drop_spawn);
498 515
499struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type, 516static struct crypto_alg *crypto_spawn_alg(struct crypto_spawn *spawn)
500 u32 mask)
501{ 517{
502 struct crypto_alg *alg; 518 struct crypto_alg *alg;
503 struct crypto_alg *alg2; 519 struct crypto_alg *alg2;
504 struct crypto_tfm *tfm;
505 520
506 down_read(&crypto_alg_sem); 521 down_read(&crypto_alg_sem);
507 alg = spawn->alg; 522 alg = spawn->alg;
@@ -516,6 +531,19 @@ struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type,
516 return ERR_PTR(-EAGAIN); 531 return ERR_PTR(-EAGAIN);
517 } 532 }
518 533
534 return alg;
535}
536
537struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type,
538 u32 mask)
539{
540 struct crypto_alg *alg;
541 struct crypto_tfm *tfm;
542
543 alg = crypto_spawn_alg(spawn);
544 if (IS_ERR(alg))
545 return ERR_CAST(alg);
546
519 tfm = ERR_PTR(-EINVAL); 547 tfm = ERR_PTR(-EINVAL);
520 if (unlikely((alg->cra_flags ^ type) & mask)) 548 if (unlikely((alg->cra_flags ^ type) & mask))
521 goto out_put_alg; 549 goto out_put_alg;
@@ -532,6 +560,27 @@ out_put_alg:
532} 560}
533EXPORT_SYMBOL_GPL(crypto_spawn_tfm); 561EXPORT_SYMBOL_GPL(crypto_spawn_tfm);
534 562
563void *crypto_spawn_tfm2(struct crypto_spawn *spawn)
564{
565 struct crypto_alg *alg;
566 struct crypto_tfm *tfm;
567
568 alg = crypto_spawn_alg(spawn);
569 if (IS_ERR(alg))
570 return ERR_CAST(alg);
571
572 tfm = crypto_create_tfm(alg, spawn->frontend);
573 if (IS_ERR(tfm))
574 goto out_put_alg;
575
576 return tfm;
577
578out_put_alg:
579 crypto_mod_put(alg);
580 return tfm;
581}
582EXPORT_SYMBOL_GPL(crypto_spawn_tfm2);
583
535int crypto_register_notifier(struct notifier_block *nb) 584int crypto_register_notifier(struct notifier_block *nb)
536{ 585{
537 return blocking_notifier_chain_register(&crypto_chain, nb); 586 return blocking_notifier_chain_register(&crypto_chain, nb);