aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2009-07-14 06:45:45 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2009-07-14 06:45:45 -0400
commit9cd899a32f611eb6328014f1d9e0ba31977812d9 (patch)
tree5f217da3aaec5caffe86a80053c44d01a4211ff0 /crypto
parent52861c7cd711fac97b37ae0f4842a9ad26ecae72 (diff)
crypto: cryptd - Switch to template create API
This patch changes cryptd to use the template->create function instead of alloc in anticipation for the switch to new style ahash algorithms. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/cryptd.c53
-rw-r--r--crypto/internal.h3
2 files changed, 29 insertions, 27 deletions
diff --git a/crypto/cryptd.c b/crypto/cryptd.c
index 6e6722edd0d9..ad58f513ba8b 100644
--- a/crypto/cryptd.c
+++ b/crypto/cryptd.c
@@ -287,8 +287,9 @@ out_free_inst:
287 goto out; 287 goto out;
288} 288}
289 289
290static struct crypto_instance *cryptd_alloc_blkcipher( 290static int cryptd_create_blkcipher(struct crypto_template *tmpl,
291 struct rtattr **tb, struct cryptd_queue *queue) 291 struct rtattr **tb,
292 struct cryptd_queue *queue)
292{ 293{
293 struct cryptd_instance_ctx *ctx; 294 struct cryptd_instance_ctx *ctx;
294 struct crypto_instance *inst; 295 struct crypto_instance *inst;
@@ -298,7 +299,7 @@ static struct crypto_instance *cryptd_alloc_blkcipher(
298 alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_BLKCIPHER, 299 alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_BLKCIPHER,
299 CRYPTO_ALG_TYPE_MASK); 300 CRYPTO_ALG_TYPE_MASK);
300 if (IS_ERR(alg)) 301 if (IS_ERR(alg))
301 return ERR_CAST(alg); 302 return PTR_ERR(alg);
302 303
303 inst = cryptd_alloc_instance(alg, sizeof(*ctx)); 304 inst = cryptd_alloc_instance(alg, sizeof(*ctx));
304 if (IS_ERR(inst)) 305 if (IS_ERR(inst))
@@ -330,14 +331,16 @@ static struct crypto_instance *cryptd_alloc_blkcipher(
330 inst->alg.cra_ablkcipher.encrypt = cryptd_blkcipher_encrypt_enqueue; 331 inst->alg.cra_ablkcipher.encrypt = cryptd_blkcipher_encrypt_enqueue;
331 inst->alg.cra_ablkcipher.decrypt = cryptd_blkcipher_decrypt_enqueue; 332 inst->alg.cra_ablkcipher.decrypt = cryptd_blkcipher_decrypt_enqueue;
332 333
334 err = crypto_register_instance(tmpl, inst);
335 if (err) {
336 crypto_drop_spawn(&ctx->spawn);
337out_free_inst:
338 kfree(inst);
339 }
340
333out_put_alg: 341out_put_alg:
334 crypto_mod_put(alg); 342 crypto_mod_put(alg);
335 return inst; 343 return err;
336
337out_free_inst:
338 kfree(inst);
339 inst = ERR_PTR(err);
340 goto out_put_alg;
341} 344}
342 345
343static int cryptd_hash_init_tfm(struct crypto_tfm *tfm) 346static int cryptd_hash_init_tfm(struct crypto_tfm *tfm)
@@ -502,8 +505,8 @@ static int cryptd_hash_digest_enqueue(struct ahash_request *req)
502 return cryptd_hash_enqueue(req, cryptd_hash_digest); 505 return cryptd_hash_enqueue(req, cryptd_hash_digest);
503} 506}
504 507
505static struct crypto_instance *cryptd_alloc_hash( 508static int cryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb,
506 struct rtattr **tb, struct cryptd_queue *queue) 509 struct cryptd_queue *queue)
507{ 510{
508 struct hashd_instance_ctx *ctx; 511 struct hashd_instance_ctx *ctx;
509 struct crypto_instance *inst; 512 struct crypto_instance *inst;
@@ -513,7 +516,7 @@ static struct crypto_instance *cryptd_alloc_hash(
513 516
514 salg = shash_attr_alg(tb[1], 0, 0); 517 salg = shash_attr_alg(tb[1], 0, 0);
515 if (IS_ERR(salg)) 518 if (IS_ERR(salg))
516 return ERR_CAST(salg); 519 return PTR_ERR(salg);
517 520
518 alg = &salg->base; 521 alg = &salg->base;
519 inst = cryptd_alloc_instance(alg, sizeof(*ctx)); 522 inst = cryptd_alloc_instance(alg, sizeof(*ctx));
@@ -542,34 +545,36 @@ static struct crypto_instance *cryptd_alloc_hash(
542 inst->alg.cra_ahash.setkey = cryptd_hash_setkey; 545 inst->alg.cra_ahash.setkey = cryptd_hash_setkey;
543 inst->alg.cra_ahash.digest = cryptd_hash_digest_enqueue; 546 inst->alg.cra_ahash.digest = cryptd_hash_digest_enqueue;
544 547
548 err = crypto_register_instance(tmpl, inst);
549 if (err) {
550 crypto_drop_shash(&ctx->spawn);
551out_free_inst:
552 kfree(inst);
553 }
554
545out_put_alg: 555out_put_alg:
546 crypto_mod_put(alg); 556 crypto_mod_put(alg);
547 return inst; 557 return err;
548
549out_free_inst:
550 kfree(inst);
551 inst = ERR_PTR(err);
552 goto out_put_alg;
553} 558}
554 559
555static struct cryptd_queue queue; 560static struct cryptd_queue queue;
556 561
557static struct crypto_instance *cryptd_alloc(struct rtattr **tb) 562static int cryptd_create(struct crypto_template *tmpl, struct rtattr **tb)
558{ 563{
559 struct crypto_attr_type *algt; 564 struct crypto_attr_type *algt;
560 565
561 algt = crypto_get_attr_type(tb); 566 algt = crypto_get_attr_type(tb);
562 if (IS_ERR(algt)) 567 if (IS_ERR(algt))
563 return ERR_CAST(algt); 568 return PTR_ERR(algt);
564 569
565 switch (algt->type & algt->mask & CRYPTO_ALG_TYPE_MASK) { 570 switch (algt->type & algt->mask & CRYPTO_ALG_TYPE_MASK) {
566 case CRYPTO_ALG_TYPE_BLKCIPHER: 571 case CRYPTO_ALG_TYPE_BLKCIPHER:
567 return cryptd_alloc_blkcipher(tb, &queue); 572 return cryptd_create_blkcipher(tmpl, tb, &queue);
568 case CRYPTO_ALG_TYPE_DIGEST: 573 case CRYPTO_ALG_TYPE_DIGEST:
569 return cryptd_alloc_hash(tb, &queue); 574 return cryptd_create_hash(tmpl, tb, &queue);
570 } 575 }
571 576
572 return ERR_PTR(-EINVAL); 577 return -EINVAL;
573} 578}
574 579
575static void cryptd_free(struct crypto_instance *inst) 580static void cryptd_free(struct crypto_instance *inst)
@@ -582,7 +587,7 @@ static void cryptd_free(struct crypto_instance *inst)
582 587
583static struct crypto_template cryptd_tmpl = { 588static struct crypto_template cryptd_tmpl = {
584 .name = "cryptd", 589 .name = "cryptd",
585 .alloc = cryptd_alloc, 590 .create = cryptd_create,
586 .free = cryptd_free, 591 .free = cryptd_free,
587 .module = THIS_MODULE, 592 .module = THIS_MODULE,
588}; 593};
diff --git a/crypto/internal.h b/crypto/internal.h
index 030e22921c30..2d226362e594 100644
--- a/crypto/internal.h
+++ b/crypto/internal.h
@@ -97,9 +97,6 @@ struct crypto_alg *crypto_find_alg(const char *alg_name,
97void *crypto_alloc_tfm(const char *alg_name, 97void *crypto_alloc_tfm(const char *alg_name,
98 const struct crypto_type *frontend, u32 type, u32 mask); 98 const struct crypto_type *frontend, u32 type, u32 mask);
99 99
100int crypto_register_instance(struct crypto_template *tmpl,
101 struct crypto_instance *inst);
102
103int crypto_register_notifier(struct notifier_block *nb); 100int crypto_register_notifier(struct notifier_block *nb);
104int crypto_unregister_notifier(struct notifier_block *nb); 101int crypto_unregister_notifier(struct notifier_block *nb);
105int crypto_probing_notify(unsigned long val, void *v); 102int crypto_probing_notify(unsigned long val, void *v);