Commit d06854f0243d91badabaab14503f7f3bb770061d

Authored by Herbert Xu
1 parent 942969992d

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>

Showing 4 changed files with 40 additions and 13 deletions Side-by-side Diff

... ... @@ -644,7 +644,9 @@
644 644 }
645 645 EXPORT_SYMBOL_GPL(crypto_attr_alg_name);
646 646  
647   -struct crypto_alg *crypto_attr_alg(struct rtattr *rta, u32 type, u32 mask)
  647 +struct crypto_alg *crypto_attr_alg2(struct rtattr *rta,
  648 + const struct crypto_type *frontend,
  649 + u32 type, u32 mask)
648 650 {
649 651 const char *name;
650 652 int err;
651 653  
... ... @@ -654,9 +656,9 @@
654 656 if (IS_ERR(name))
655 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 }
659   -EXPORT_SYMBOL_GPL(crypto_attr_alg);
  661 +EXPORT_SYMBOL_GPL(crypto_attr_alg2);
660 662  
661 663 int crypto_attr_u32(struct rtattr *rta, u32 *num)
662 664 {
... ... @@ -503,6 +503,27 @@
503 503 }
504 504 EXPORT_SYMBOL_GPL(crypto_create_tfm);
505 505  
  506 +struct 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 +}
  525 +EXPORT_SYMBOL_GPL(crypto_find_alg);
  526 +
506 527 /*
507 528 * crypto_alloc_tfm - Locate algorithm and allocate transform
508 529 * @alg_name: Name of algorithm
509 530  
510 531  
... ... @@ -526,21 +547,13 @@
526 547 void *crypto_alloc_tfm(const char *alg_name,
527 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 550 void *tfm;
531 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 553 for (;;) {
541 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 557 if (IS_ERR(alg)) {
545 558 err = PTR_ERR(alg);
546 559 goto err;
... ... @@ -106,6 +106,9 @@
106 106 u32 mask);
107 107 void *crypto_create_tfm(struct crypto_alg *alg,
108 108 const struct crypto_type *frontend);
  109 +struct crypto_alg *crypto_find_alg(const char *alg_name,
  110 + const struct crypto_type *frontend,
  111 + u32 type, u32 mask);
109 112 void *crypto_alloc_tfm(const char *alg_name,
110 113 const struct crypto_type *frontend, u32 type, u32 mask);
111 114  
include/crypto/algapi.h
... ... @@ -136,7 +136,16 @@
136 136 struct crypto_attr_type *crypto_get_attr_type(struct rtattr **tb);
137 137 int crypto_check_attr_type(struct rtattr **tb, u32 type);
138 138 const char *crypto_attr_alg_name(struct rtattr *rta);
139   -struct crypto_alg *crypto_attr_alg(struct rtattr *rta, u32 type, u32 mask);
  139 +struct crypto_alg *crypto_attr_alg2(struct rtattr *rta,
  140 + const struct crypto_type *frontend,
  141 + u32 type, u32 mask);
  142 +
  143 +static inline struct crypto_alg *crypto_attr_alg(struct rtattr *rta,
  144 + u32 type, u32 mask)
  145 +{
  146 + return crypto_attr_alg2(rta, NULL, type, mask);
  147 +}
  148 +
140 149 int crypto_attr_u32(struct rtattr *rta, u32 *num);
141 150 void *crypto_alloc_instance2(const char *name, struct crypto_alg *alg,
142 151 unsigned int head);