aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/algapi.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-01-01 02:37:02 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2007-05-02 00:38:31 -0400
commitebc610e5bc76df073221e64e86c3f7533a09ea40 (patch)
treed53f4fa3da412f6df4b5891e23ca7c7607a3a5ce /crypto/algapi.c
parent6158efc09016d3186263f6fd3a50667446ec4008 (diff)
[CRYPTO] templates: Pass type/mask when creating instances
This patch passes the type/mask along when constructing instances of templates. This is in preparation for templates that may support multiple types of instances depending on what is requested. For example, the planned software async crypto driver will use this construct. For the moment this allows us to check whether the instance constructed is of the correct type and avoid returning success if the type does not match. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/algapi.c')
-rw-r--r--crypto/algapi.c42
1 files changed, 36 insertions, 6 deletions
diff --git a/crypto/algapi.c b/crypto/algapi.c
index f7d2185b2c8f..491205e11cbe 100644
--- a/crypto/algapi.c
+++ b/crypto/algapi.c
@@ -425,15 +425,45 @@ int crypto_unregister_notifier(struct notifier_block *nb)
425} 425}
426EXPORT_SYMBOL_GPL(crypto_unregister_notifier); 426EXPORT_SYMBOL_GPL(crypto_unregister_notifier);
427 427
428struct crypto_alg *crypto_get_attr_alg(void *param, unsigned int len, 428struct crypto_attr_type *crypto_get_attr_type(struct rtattr **tb)
429 u32 type, u32 mask)
430{ 429{
431 struct rtattr *rta = param; 430 struct rtattr *rta = tb[CRYPTOA_TYPE - 1];
431 struct crypto_attr_type *algt;
432
433 if (!rta)
434 return ERR_PTR(-ENOENT);
435 if (RTA_PAYLOAD(rta) < sizeof(*algt))
436 return ERR_PTR(-EINVAL);
437
438 algt = RTA_DATA(rta);
439
440 return algt;
441}
442EXPORT_SYMBOL_GPL(crypto_get_attr_type);
443
444int crypto_check_attr_type(struct rtattr **tb, u32 type)
445{
446 struct crypto_attr_type *algt;
447
448 algt = crypto_get_attr_type(tb);
449 if (IS_ERR(algt))
450 return PTR_ERR(algt);
451
452 if ((algt->type ^ type) & algt->mask)
453 return -EINVAL;
454
455 return 0;
456}
457EXPORT_SYMBOL_GPL(crypto_check_attr_type);
458
459struct crypto_alg *crypto_get_attr_alg(struct rtattr **tb, u32 type, u32 mask)
460{
461 struct rtattr *rta = tb[CRYPTOA_ALG - 1];
432 struct crypto_attr_alg *alga; 462 struct crypto_attr_alg *alga;
433 463
434 if (!RTA_OK(rta, len)) 464 if (!rta)
435 return ERR_PTR(-EBADR); 465 return ERR_PTR(-ENOENT);
436 if (rta->rta_type != CRYPTOA_ALG || RTA_PAYLOAD(rta) < sizeof(*alga)) 466 if (RTA_PAYLOAD(rta) < sizeof(*alga))
437 return ERR_PTR(-EINVAL); 467 return ERR_PTR(-EINVAL);
438 468
439 alga = RTA_DATA(rta); 469 alga = RTA_DATA(rta);