diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2009-07-07 02:07:37 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2009-07-07 06:55:28 -0400 |
commit | 70ec7bb91ad0d6cce84c8e17f8cbb608dda7b18c (patch) | |
tree | f8423c8e2a51b42c78ea63913a9e3654877555ca | |
parent | f2ac72e8268d9559c3114d5a22679f91f80a2238 (diff) |
crypto: api - Add crypto_alloc_instance2
This patch adds a new argument to crypto_alloc_instance which
sets aside some space before the instance for use by algorithms
such as shash that place type-specific data before crypto_alg.
For compatibility the function has been renamed so that existing
users aren't affected.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/algapi.c | 37 | ||||
-rw-r--r-- | include/crypto/algapi.h | 2 |
2 files changed, 33 insertions, 6 deletions
diff --git a/crypto/algapi.c b/crypto/algapi.c index 56c62e2858d5..429f1a003b06 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c | |||
@@ -627,17 +627,20 @@ int crypto_attr_u32(struct rtattr *rta, u32 *num) | |||
627 | } | 627 | } |
628 | EXPORT_SYMBOL_GPL(crypto_attr_u32); | 628 | EXPORT_SYMBOL_GPL(crypto_attr_u32); |
629 | 629 | ||
630 | struct crypto_instance *crypto_alloc_instance(const char *name, | 630 | void *crypto_alloc_instance2(const char *name, struct crypto_alg *alg, |
631 | struct crypto_alg *alg) | 631 | unsigned int head) |
632 | { | 632 | { |
633 | struct crypto_instance *inst; | 633 | struct crypto_instance *inst; |
634 | struct crypto_spawn *spawn; | 634 | char *p; |
635 | int err; | 635 | int err; |
636 | 636 | ||
637 | inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); | 637 | p = kzalloc(head + sizeof(*inst) + sizeof(struct crypto_spawn), |
638 | if (!inst) | 638 | GFP_KERNEL); |
639 | if (!p) | ||
639 | return ERR_PTR(-ENOMEM); | 640 | return ERR_PTR(-ENOMEM); |
640 | 641 | ||
642 | inst = (void *)(p + head); | ||
643 | |||
641 | err = -ENAMETOOLONG; | 644 | err = -ENAMETOOLONG; |
642 | if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME, "%s(%s)", name, | 645 | if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME, "%s(%s)", name, |
643 | alg->cra_name) >= CRYPTO_MAX_ALG_NAME) | 646 | alg->cra_name) >= CRYPTO_MAX_ALG_NAME) |
@@ -647,6 +650,25 @@ struct crypto_instance *crypto_alloc_instance(const char *name, | |||
647 | name, alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME) | 650 | name, alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME) |
648 | goto err_free_inst; | 651 | goto err_free_inst; |
649 | 652 | ||
653 | return p; | ||
654 | |||
655 | err_free_inst: | ||
656 | kfree(p); | ||
657 | return ERR_PTR(err); | ||
658 | } | ||
659 | EXPORT_SYMBOL_GPL(crypto_alloc_instance2); | ||
660 | |||
661 | struct crypto_instance *crypto_alloc_instance(const char *name, | ||
662 | struct crypto_alg *alg) | ||
663 | { | ||
664 | struct crypto_instance *inst; | ||
665 | struct crypto_spawn *spawn; | ||
666 | int err; | ||
667 | |||
668 | inst = crypto_alloc_instance2(name, alg, 0); | ||
669 | if (IS_ERR(inst)) | ||
670 | goto out; | ||
671 | |||
650 | spawn = crypto_instance_ctx(inst); | 672 | spawn = crypto_instance_ctx(inst); |
651 | err = crypto_init_spawn(spawn, alg, inst, | 673 | err = crypto_init_spawn(spawn, alg, inst, |
652 | CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC); | 674 | CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC); |
@@ -658,7 +680,10 @@ struct crypto_instance *crypto_alloc_instance(const char *name, | |||
658 | 680 | ||
659 | err_free_inst: | 681 | err_free_inst: |
660 | kfree(inst); | 682 | kfree(inst); |
661 | return ERR_PTR(err); | 683 | inst = ERR_PTR(err); |
684 | |||
685 | out: | ||
686 | return inst; | ||
662 | } | 687 | } |
663 | EXPORT_SYMBOL_GPL(crypto_alloc_instance); | 688 | EXPORT_SYMBOL_GPL(crypto_alloc_instance); |
664 | 689 | ||
diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index ce010a346420..99bb29723130 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h | |||
@@ -132,6 +132,8 @@ int crypto_check_attr_type(struct rtattr **tb, u32 type); | |||
132 | const char *crypto_attr_alg_name(struct rtattr *rta); | 132 | const char *crypto_attr_alg_name(struct rtattr *rta); |
133 | struct crypto_alg *crypto_attr_alg(struct rtattr *rta, u32 type, u32 mask); | 133 | struct crypto_alg *crypto_attr_alg(struct rtattr *rta, u32 type, u32 mask); |
134 | int crypto_attr_u32(struct rtattr *rta, u32 *num); | 134 | int crypto_attr_u32(struct rtattr *rta, u32 *num); |
135 | void *crypto_alloc_instance2(const char *name, struct crypto_alg *alg, | ||
136 | unsigned int head); | ||
135 | struct crypto_instance *crypto_alloc_instance(const char *name, | 137 | struct crypto_instance *crypto_alloc_instance(const char *name, |
136 | struct crypto_alg *alg); | 138 | struct crypto_alg *alg); |
137 | 139 | ||