aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crypto/algapi.c55
-rw-r--r--include/crypto/algapi.h6
2 files changed, 58 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);
diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
index 99bb29723130..c9bff92a9e0e 100644
--- a/include/crypto/algapi.h
+++ b/include/crypto/algapi.h
@@ -61,6 +61,7 @@ struct crypto_spawn {
61 struct list_head list; 61 struct list_head list;
62 struct crypto_alg *alg; 62 struct crypto_alg *alg;
63 struct crypto_instance *inst; 63 struct crypto_instance *inst;
64 const struct crypto_type *frontend;
64 u32 mask; 65 u32 mask;
65}; 66};
66 67
@@ -117,9 +118,14 @@ struct crypto_template *crypto_lookup_template(const char *name);
117 118
118int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg, 119int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg,
119 struct crypto_instance *inst, u32 mask); 120 struct crypto_instance *inst, u32 mask);
121int crypto_init_spawn2(struct crypto_spawn *spawn, struct crypto_alg *alg,
122 struct crypto_instance *inst,
123 const struct crypto_type *frontend);
124
120void crypto_drop_spawn(struct crypto_spawn *spawn); 125void crypto_drop_spawn(struct crypto_spawn *spawn);
121struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type, 126struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type,
122 u32 mask); 127 u32 mask);
128void *crypto_spawn_tfm2(struct crypto_spawn *spawn);
123 129
124static inline void crypto_set_spawn(struct crypto_spawn *spawn, 130static inline void crypto_set_spawn(struct crypto_spawn *spawn,
125 struct crypto_instance *inst) 131 struct crypto_instance *inst)