aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2009-07-08 05:53:16 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2009-07-08 06:58:29 -0400
commitd06854f0243d91badabaab14503f7f3bb770061d (patch)
tree252603fecb02a8cc4933b0e582444ff7cb504018 /crypto
parent942969992d86330c9700e2cd9afe8a6bea42df78 (diff)
crypto: api - Add crypto_attr_alg2 helper
This patch adds the helper crypto_attr_alg2 which is similar to crypto_attr_alg but takes an extra frontend argument. This is intended to be used by new style algorithm types such as shash. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/algapi.c8
-rw-r--r--crypto/api.c31
-rw-r--r--crypto/internal.h3
3 files changed, 30 insertions, 12 deletions
diff --git a/crypto/algapi.c b/crypto/algapi.c
index 17a5fff8f777..2154815201a7 100644
--- a/crypto/algapi.c
+++ b/crypto/algapi.c
@@ -644,7 +644,9 @@ const char *crypto_attr_alg_name(struct rtattr *rta)
644} 644}
645EXPORT_SYMBOL_GPL(crypto_attr_alg_name); 645EXPORT_SYMBOL_GPL(crypto_attr_alg_name);
646 646
647struct crypto_alg *crypto_attr_alg(struct rtattr *rta, u32 type, u32 mask) 647struct crypto_alg *crypto_attr_alg2(struct rtattr *rta,
648 const struct crypto_type *frontend,
649 u32 type, u32 mask)
648{ 650{
649 const char *name; 651 const char *name;
650 int err; 652 int err;
@@ -654,9 +656,9 @@ struct crypto_alg *crypto_attr_alg(struct rtattr *rta, u32 type, u32 mask)
654 if (IS_ERR(name)) 656 if (IS_ERR(name))
655 return ERR_PTR(err); 657 return ERR_PTR(err);
656 658
657 return crypto_alg_mod_lookup(name, type, mask); 659 return crypto_find_alg(name, frontend, type, mask);
658} 660}
659EXPORT_SYMBOL_GPL(crypto_attr_alg); 661EXPORT_SYMBOL_GPL(crypto_attr_alg2);
660 662
661int crypto_attr_u32(struct rtattr *rta, u32 *num) 663int crypto_attr_u32(struct rtattr *rta, u32 *num)
662{ 664{
diff --git a/crypto/api.c b/crypto/api.c
index d5944f92b416..ba81221b3bef 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -503,6 +503,27 @@ out:
503} 503}
504EXPORT_SYMBOL_GPL(crypto_create_tfm); 504EXPORT_SYMBOL_GPL(crypto_create_tfm);
505 505
506struct crypto_alg *crypto_find_alg(const char *alg_name,
507 const struct crypto_type *frontend,
508 u32 type, u32 mask)
509{
510 struct crypto_alg *(*lookup)(const char *name, u32 type, u32 mask) =
511 crypto_alg_mod_lookup;
512
513 if (frontend) {
514 type &= frontend->maskclear;
515 mask &= frontend->maskclear;
516 type |= frontend->type;
517 mask |= frontend->maskset;
518
519 if (frontend->lookup)
520 lookup = frontend->lookup;
521 }
522
523 return lookup(alg_name, type, mask);
524}
525EXPORT_SYMBOL_GPL(crypto_find_alg);
526
506/* 527/*
507 * crypto_alloc_tfm - Locate algorithm and allocate transform 528 * crypto_alloc_tfm - Locate algorithm and allocate transform
508 * @alg_name: Name of algorithm 529 * @alg_name: Name of algorithm
@@ -526,21 +547,13 @@ EXPORT_SYMBOL_GPL(crypto_create_tfm);
526void *crypto_alloc_tfm(const char *alg_name, 547void *crypto_alloc_tfm(const char *alg_name,
527 const struct crypto_type *frontend, u32 type, u32 mask) 548 const struct crypto_type *frontend, u32 type, u32 mask)
528{ 549{
529 struct crypto_alg *(*lookup)(const char *name, u32 type, u32 mask);
530 void *tfm; 550 void *tfm;
531 int err; 551 int err;
532 552
533 type &= frontend->maskclear;
534 mask &= frontend->maskclear;
535 type |= frontend->type;
536 mask |= frontend->maskset;
537
538 lookup = frontend->lookup ?: crypto_alg_mod_lookup;
539
540 for (;;) { 553 for (;;) {
541 struct crypto_alg *alg; 554 struct crypto_alg *alg;
542 555
543 alg = lookup(alg_name, type, mask); 556 alg = crypto_find_alg(alg_name, frontend, type, mask);
544 if (IS_ERR(alg)) { 557 if (IS_ERR(alg)) {
545 err = PTR_ERR(alg); 558 err = PTR_ERR(alg);
546 goto err; 559 goto err;
diff --git a/crypto/internal.h b/crypto/internal.h
index 95baaea21fbc..7efa4d0533ff 100644
--- a/crypto/internal.h
+++ b/crypto/internal.h
@@ -106,6 +106,9 @@ struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
106 u32 mask); 106 u32 mask);
107void *crypto_create_tfm(struct crypto_alg *alg, 107void *crypto_create_tfm(struct crypto_alg *alg,
108 const struct crypto_type *frontend); 108 const struct crypto_type *frontend);
109struct crypto_alg *crypto_find_alg(const char *alg_name,
110 const struct crypto_type *frontend,
111 u32 type, u32 mask);
109void *crypto_alloc_tfm(const char *alg_name, 112void *crypto_alloc_tfm(const char *alg_name,
110 const struct crypto_type *frontend, u32 type, u32 mask); 113 const struct crypto_type *frontend, u32 type, u32 mask);
111 114