diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2009-07-08 03:55:52 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2009-07-08 06:57:10 -0400 |
commit | 97eedce1a64a57648ac5e39f03825528c47ba72e (patch) | |
tree | 5dea863a2b51b01b8e436d4e395ef15ae3f4bcd9 /crypto | |
parent | 2e4fddd8e420e8f531a34e7a97f9cdb851a6ad13 (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.c | 55 |
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 | } |
489 | EXPORT_SYMBOL_GPL(crypto_init_spawn); | 489 | EXPORT_SYMBOL_GPL(crypto_init_spawn); |
490 | 490 | ||
491 | int 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 | |||
503 | out: | ||
504 | return err; | ||
505 | } | ||
506 | EXPORT_SYMBOL_GPL(crypto_init_spawn2); | ||
507 | |||
491 | void crypto_drop_spawn(struct crypto_spawn *spawn) | 508 | void 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 | } |
497 | EXPORT_SYMBOL_GPL(crypto_drop_spawn); | 514 | EXPORT_SYMBOL_GPL(crypto_drop_spawn); |
498 | 515 | ||
499 | struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type, | 516 | static 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 | |||
537 | struct 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 | } |
533 | EXPORT_SYMBOL_GPL(crypto_spawn_tfm); | 561 | EXPORT_SYMBOL_GPL(crypto_spawn_tfm); |
534 | 562 | ||
563 | void *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 | |||
578 | out_put_alg: | ||
579 | crypto_mod_put(alg); | ||
580 | return tfm; | ||
581 | } | ||
582 | EXPORT_SYMBOL_GPL(crypto_spawn_tfm2); | ||
583 | |||
535 | int crypto_register_notifier(struct notifier_block *nb) | 584 | int 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); |