diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2009-07-14 07:11:32 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2009-07-14 07:11:32 -0400 |
commit | 0b535adfb102bac1edb046444172b6b77d99bc92 (patch) | |
tree | f113cae3f022b6d39ddcf63a71c7b3dc65b120fe /crypto | |
parent | 9cd899a32f611eb6328014f1d9e0ba31977812d9 (diff) |
crypto: cryptd - Switch to new style ahash
This patch changes cryptd to use the new style ahash type. In
particular, the instance is enlarged to encapsulate the new
ahash_alg structure.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/cryptd.c | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/crypto/cryptd.c b/crypto/cryptd.c index ad58f513ba8b..5dabb7dbad84 100644 --- a/crypto/cryptd.c +++ b/crypto/cryptd.c | |||
@@ -255,17 +255,18 @@ static void cryptd_blkcipher_exit_tfm(struct crypto_tfm *tfm) | |||
255 | crypto_free_blkcipher(ctx->child); | 255 | crypto_free_blkcipher(ctx->child); |
256 | } | 256 | } |
257 | 257 | ||
258 | static struct crypto_instance *cryptd_alloc_instance(struct crypto_alg *alg, | 258 | static void *cryptd_alloc_instance(struct crypto_alg *alg, unsigned int head, |
259 | unsigned int tail) | 259 | unsigned int tail) |
260 | { | 260 | { |
261 | char *p; | ||
261 | struct crypto_instance *inst; | 262 | struct crypto_instance *inst; |
262 | int err; | 263 | int err; |
263 | 264 | ||
264 | inst = kzalloc(sizeof(*inst) + tail, GFP_KERNEL); | 265 | p = kzalloc(head + sizeof(*inst) + tail, GFP_KERNEL); |
265 | if (!inst) { | 266 | if (!p) |
266 | inst = ERR_PTR(-ENOMEM); | 267 | return ERR_PTR(-ENOMEM); |
267 | goto out; | 268 | |
268 | } | 269 | inst = (void *)(p + head); |
269 | 270 | ||
270 | err = -ENAMETOOLONG; | 271 | err = -ENAMETOOLONG; |
271 | if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, | 272 | if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, |
@@ -279,11 +280,11 @@ static struct crypto_instance *cryptd_alloc_instance(struct crypto_alg *alg, | |||
279 | inst->alg.cra_alignmask = alg->cra_alignmask; | 280 | inst->alg.cra_alignmask = alg->cra_alignmask; |
280 | 281 | ||
281 | out: | 282 | out: |
282 | return inst; | 283 | return p; |
283 | 284 | ||
284 | out_free_inst: | 285 | out_free_inst: |
285 | kfree(inst); | 286 | kfree(p); |
286 | inst = ERR_PTR(err); | 287 | p = ERR_PTR(err); |
287 | goto out; | 288 | goto out; |
288 | } | 289 | } |
289 | 290 | ||
@@ -301,7 +302,7 @@ static int cryptd_create_blkcipher(struct crypto_template *tmpl, | |||
301 | if (IS_ERR(alg)) | 302 | if (IS_ERR(alg)) |
302 | return PTR_ERR(alg); | 303 | return PTR_ERR(alg); |
303 | 304 | ||
304 | inst = cryptd_alloc_instance(alg, sizeof(*ctx)); | 305 | inst = cryptd_alloc_instance(alg, 0, sizeof(*ctx)); |
305 | if (IS_ERR(inst)) | 306 | if (IS_ERR(inst)) |
306 | goto out_put_alg; | 307 | goto out_put_alg; |
307 | 308 | ||
@@ -509,7 +510,7 @@ static int cryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb, | |||
509 | struct cryptd_queue *queue) | 510 | struct cryptd_queue *queue) |
510 | { | 511 | { |
511 | struct hashd_instance_ctx *ctx; | 512 | struct hashd_instance_ctx *ctx; |
512 | struct crypto_instance *inst; | 513 | struct ahash_instance *inst; |
513 | struct shash_alg *salg; | 514 | struct shash_alg *salg; |
514 | struct crypto_alg *alg; | 515 | struct crypto_alg *alg; |
515 | int err; | 516 | int err; |
@@ -519,33 +520,34 @@ static int cryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb, | |||
519 | return PTR_ERR(salg); | 520 | return PTR_ERR(salg); |
520 | 521 | ||
521 | alg = &salg->base; | 522 | alg = &salg->base; |
522 | inst = cryptd_alloc_instance(alg, sizeof(*ctx)); | 523 | inst = cryptd_alloc_instance(alg, ahash_instance_headroom(), |
524 | sizeof(*ctx)); | ||
523 | if (IS_ERR(inst)) | 525 | if (IS_ERR(inst)) |
524 | goto out_put_alg; | 526 | goto out_put_alg; |
525 | 527 | ||
526 | ctx = crypto_instance_ctx(inst); | 528 | ctx = ahash_instance_ctx(inst); |
527 | ctx->queue = queue; | 529 | ctx->queue = queue; |
528 | 530 | ||
529 | err = crypto_init_shash_spawn(&ctx->spawn, salg, inst); | 531 | err = crypto_init_shash_spawn(&ctx->spawn, salg, |
532 | ahash_crypto_instance(inst)); | ||
530 | if (err) | 533 | if (err) |
531 | goto out_free_inst; | 534 | goto out_free_inst; |
532 | 535 | ||
533 | inst->alg.cra_flags = CRYPTO_ALG_TYPE_AHASH | CRYPTO_ALG_ASYNC; | 536 | inst->alg.halg.base.cra_flags = CRYPTO_ALG_ASYNC; |
534 | inst->alg.cra_type = &crypto_ahash_type; | ||
535 | 537 | ||
536 | inst->alg.cra_ahash.digestsize = salg->digestsize; | 538 | inst->alg.halg.digestsize = salg->digestsize; |
537 | inst->alg.cra_ctxsize = sizeof(struct cryptd_hash_ctx); | 539 | inst->alg.halg.base.cra_ctxsize = sizeof(struct cryptd_hash_ctx); |
538 | 540 | ||
539 | inst->alg.cra_init = cryptd_hash_init_tfm; | 541 | inst->alg.halg.base.cra_init = cryptd_hash_init_tfm; |
540 | inst->alg.cra_exit = cryptd_hash_exit_tfm; | 542 | inst->alg.halg.base.cra_exit = cryptd_hash_exit_tfm; |
541 | 543 | ||
542 | inst->alg.cra_ahash.init = cryptd_hash_init_enqueue; | 544 | inst->alg.init = cryptd_hash_init_enqueue; |
543 | inst->alg.cra_ahash.update = cryptd_hash_update_enqueue; | 545 | inst->alg.update = cryptd_hash_update_enqueue; |
544 | inst->alg.cra_ahash.final = cryptd_hash_final_enqueue; | 546 | inst->alg.final = cryptd_hash_final_enqueue; |
545 | inst->alg.cra_ahash.setkey = cryptd_hash_setkey; | 547 | inst->alg.setkey = cryptd_hash_setkey; |
546 | inst->alg.cra_ahash.digest = cryptd_hash_digest_enqueue; | 548 | inst->alg.digest = cryptd_hash_digest_enqueue; |
547 | 549 | ||
548 | err = crypto_register_instance(tmpl, inst); | 550 | err = ahash_register_instance(tmpl, inst); |
549 | if (err) { | 551 | if (err) { |
550 | crypto_drop_shash(&ctx->spawn); | 552 | crypto_drop_shash(&ctx->spawn); |
551 | out_free_inst: | 553 | out_free_inst: |
@@ -580,6 +582,14 @@ static int cryptd_create(struct crypto_template *tmpl, struct rtattr **tb) | |||
580 | static void cryptd_free(struct crypto_instance *inst) | 582 | static void cryptd_free(struct crypto_instance *inst) |
581 | { | 583 | { |
582 | struct cryptd_instance_ctx *ctx = crypto_instance_ctx(inst); | 584 | struct cryptd_instance_ctx *ctx = crypto_instance_ctx(inst); |
585 | struct hashd_instance_ctx *hctx = crypto_instance_ctx(inst); | ||
586 | |||
587 | switch (inst->alg.cra_flags & CRYPTO_ALG_TYPE_MASK) { | ||
588 | case CRYPTO_ALG_TYPE_AHASH: | ||
589 | crypto_drop_shash(&hctx->spawn); | ||
590 | kfree(ahash_instance(inst)); | ||
591 | return; | ||
592 | } | ||
583 | 593 | ||
584 | crypto_drop_spawn(&ctx->spawn); | 594 | crypto_drop_spawn(&ctx->spawn); |
585 | kfree(inst); | 595 | kfree(inst); |