aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/api.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/api.c')
-rw-r--r--crypto/api.c52
1 files changed, 31 insertions, 21 deletions
diff --git a/crypto/api.c b/crypto/api.c
index 9975a7bd246c..314dab96840e 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -215,8 +215,19 @@ struct crypto_alg *crypto_larval_lookup(const char *name, u32 type, u32 mask)
215 mask &= ~(CRYPTO_ALG_LARVAL | CRYPTO_ALG_DEAD); 215 mask &= ~(CRYPTO_ALG_LARVAL | CRYPTO_ALG_DEAD);
216 type &= mask; 216 type &= mask;
217 217
218 alg = try_then_request_module(crypto_alg_lookup(name, type, mask), 218 alg = crypto_alg_lookup(name, type, mask);
219 name); 219 if (!alg) {
220 char tmp[CRYPTO_MAX_ALG_NAME];
221
222 request_module(name);
223
224 if (!((type ^ CRYPTO_ALG_NEED_FALLBACK) & mask) &&
225 snprintf(tmp, sizeof(tmp), "%s-all", name) < sizeof(tmp))
226 request_module(tmp);
227
228 alg = crypto_alg_lookup(name, type, mask);
229 }
230
220 if (alg) 231 if (alg)
221 return crypto_is_larval(alg) ? crypto_larval_wait(alg) : alg; 232 return crypto_is_larval(alg) ? crypto_larval_wait(alg) : alg;
222 233
@@ -244,7 +255,7 @@ struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask)
244 struct crypto_alg *larval; 255 struct crypto_alg *larval;
245 int ok; 256 int ok;
246 257
247 if (!(mask & CRYPTO_ALG_TESTED)) { 258 if (!((type | mask) & CRYPTO_ALG_TESTED)) {
248 type |= CRYPTO_ALG_TESTED; 259 type |= CRYPTO_ALG_TESTED;
249 mask |= CRYPTO_ALG_TESTED; 260 mask |= CRYPTO_ALG_TESTED;
250 } 261 }
@@ -453,8 +464,8 @@ err:
453} 464}
454EXPORT_SYMBOL_GPL(crypto_alloc_base); 465EXPORT_SYMBOL_GPL(crypto_alloc_base);
455 466
456struct crypto_tfm *crypto_create_tfm(struct crypto_alg *alg, 467void *crypto_create_tfm(struct crypto_alg *alg,
457 const struct crypto_type *frontend) 468 const struct crypto_type *frontend)
458{ 469{
459 char *mem; 470 char *mem;
460 struct crypto_tfm *tfm = NULL; 471 struct crypto_tfm *tfm = NULL;
@@ -488,9 +499,9 @@ out_free_tfm:
488 crypto_shoot_alg(alg); 499 crypto_shoot_alg(alg);
489 kfree(mem); 500 kfree(mem);
490out_err: 501out_err:
491 tfm = ERR_PTR(err); 502 mem = ERR_PTR(err);
492out: 503out:
493 return tfm; 504 return mem;
494} 505}
495EXPORT_SYMBOL_GPL(crypto_create_tfm); 506EXPORT_SYMBOL_GPL(crypto_create_tfm);
496 507
@@ -514,12 +525,11 @@ EXPORT_SYMBOL_GPL(crypto_create_tfm);
514 * 525 *
515 * In case of error the return value is an error pointer. 526 * In case of error the return value is an error pointer.
516 */ 527 */
517struct crypto_tfm *crypto_alloc_tfm(const char *alg_name, 528void *crypto_alloc_tfm(const char *alg_name,
518 const struct crypto_type *frontend, 529 const struct crypto_type *frontend, u32 type, u32 mask)
519 u32 type, u32 mask)
520{ 530{
521 struct crypto_alg *(*lookup)(const char *name, u32 type, u32 mask); 531 struct crypto_alg *(*lookup)(const char *name, u32 type, u32 mask);
522 struct crypto_tfm *tfm; 532 void *tfm;
523 int err; 533 int err;
524 534
525 type &= frontend->maskclear; 535 type &= frontend->maskclear;
@@ -557,34 +567,34 @@ err:
557 return ERR_PTR(err); 567 return ERR_PTR(err);
558} 568}
559EXPORT_SYMBOL_GPL(crypto_alloc_tfm); 569EXPORT_SYMBOL_GPL(crypto_alloc_tfm);
560 570
561/* 571/*
562 * crypto_free_tfm - Free crypto transform 572 * crypto_destroy_tfm - Free crypto transform
573 * @mem: Start of tfm slab
563 * @tfm: Transform to free 574 * @tfm: Transform to free
564 * 575 *
565 * crypto_free_tfm() frees up the transform and any associated resources, 576 * This function frees up the transform and any associated resources,
566 * then drops the refcount on the associated algorithm. 577 * then drops the refcount on the associated algorithm.
567 */ 578 */
568void crypto_free_tfm(struct crypto_tfm *tfm) 579void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm)
569{ 580{
570 struct crypto_alg *alg; 581 struct crypto_alg *alg;
571 int size; 582 int size;
572 583
573 if (unlikely(!tfm)) 584 if (unlikely(!mem))
574 return; 585 return;
575 586
576 alg = tfm->__crt_alg; 587 alg = tfm->__crt_alg;
577 size = sizeof(*tfm) + alg->cra_ctxsize; 588 size = ksize(mem);
578 589
579 if (!tfm->exit && alg->cra_exit) 590 if (!tfm->exit && alg->cra_exit)
580 alg->cra_exit(tfm); 591 alg->cra_exit(tfm);
581 crypto_exit_ops(tfm); 592 crypto_exit_ops(tfm);
582 crypto_mod_put(alg); 593 crypto_mod_put(alg);
583 memset(tfm, 0, size); 594 memset(mem, 0, size);
584 kfree(tfm); 595 kfree(mem);
585} 596}
586 597EXPORT_SYMBOL_GPL(crypto_destroy_tfm);
587EXPORT_SYMBOL_GPL(crypto_free_tfm);
588 598
589int crypto_has_alg(const char *name, u32 type, u32 mask) 599int crypto_has_alg(const char *name, u32 type, u32 mask)
590{ 600{