diff options
Diffstat (limited to 'crypto/mcryptd.c')
-rw-r--r-- | crypto/mcryptd.c | 132 |
1 files changed, 56 insertions, 76 deletions
diff --git a/crypto/mcryptd.c b/crypto/mcryptd.c index c4eb9da49d4f..86fb59b109a9 100644 --- a/crypto/mcryptd.c +++ b/crypto/mcryptd.c | |||
@@ -41,7 +41,7 @@ struct mcryptd_flush_list { | |||
41 | static struct mcryptd_flush_list __percpu *mcryptd_flist; | 41 | static struct mcryptd_flush_list __percpu *mcryptd_flist; |
42 | 42 | ||
43 | struct hashd_instance_ctx { | 43 | struct hashd_instance_ctx { |
44 | struct crypto_shash_spawn spawn; | 44 | struct crypto_ahash_spawn spawn; |
45 | struct mcryptd_queue *queue; | 45 | struct mcryptd_queue *queue; |
46 | }; | 46 | }; |
47 | 47 | ||
@@ -272,18 +272,18 @@ static int mcryptd_hash_init_tfm(struct crypto_tfm *tfm) | |||
272 | { | 272 | { |
273 | struct crypto_instance *inst = crypto_tfm_alg_instance(tfm); | 273 | struct crypto_instance *inst = crypto_tfm_alg_instance(tfm); |
274 | struct hashd_instance_ctx *ictx = crypto_instance_ctx(inst); | 274 | struct hashd_instance_ctx *ictx = crypto_instance_ctx(inst); |
275 | struct crypto_shash_spawn *spawn = &ictx->spawn; | 275 | struct crypto_ahash_spawn *spawn = &ictx->spawn; |
276 | struct mcryptd_hash_ctx *ctx = crypto_tfm_ctx(tfm); | 276 | struct mcryptd_hash_ctx *ctx = crypto_tfm_ctx(tfm); |
277 | struct crypto_shash *hash; | 277 | struct crypto_ahash *hash; |
278 | 278 | ||
279 | hash = crypto_spawn_shash(spawn); | 279 | hash = crypto_spawn_ahash(spawn); |
280 | if (IS_ERR(hash)) | 280 | if (IS_ERR(hash)) |
281 | return PTR_ERR(hash); | 281 | return PTR_ERR(hash); |
282 | 282 | ||
283 | ctx->child = hash; | 283 | ctx->child = hash; |
284 | crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm), | 284 | crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm), |
285 | sizeof(struct mcryptd_hash_request_ctx) + | 285 | sizeof(struct mcryptd_hash_request_ctx) + |
286 | crypto_shash_descsize(hash)); | 286 | crypto_ahash_reqsize(hash)); |
287 | return 0; | 287 | return 0; |
288 | } | 288 | } |
289 | 289 | ||
@@ -291,21 +291,21 @@ static void mcryptd_hash_exit_tfm(struct crypto_tfm *tfm) | |||
291 | { | 291 | { |
292 | struct mcryptd_hash_ctx *ctx = crypto_tfm_ctx(tfm); | 292 | struct mcryptd_hash_ctx *ctx = crypto_tfm_ctx(tfm); |
293 | 293 | ||
294 | crypto_free_shash(ctx->child); | 294 | crypto_free_ahash(ctx->child); |
295 | } | 295 | } |
296 | 296 | ||
297 | static int mcryptd_hash_setkey(struct crypto_ahash *parent, | 297 | static int mcryptd_hash_setkey(struct crypto_ahash *parent, |
298 | const u8 *key, unsigned int keylen) | 298 | const u8 *key, unsigned int keylen) |
299 | { | 299 | { |
300 | struct mcryptd_hash_ctx *ctx = crypto_ahash_ctx(parent); | 300 | struct mcryptd_hash_ctx *ctx = crypto_ahash_ctx(parent); |
301 | struct crypto_shash *child = ctx->child; | 301 | struct crypto_ahash *child = ctx->child; |
302 | int err; | 302 | int err; |
303 | 303 | ||
304 | crypto_shash_clear_flags(child, CRYPTO_TFM_REQ_MASK); | 304 | crypto_ahash_clear_flags(child, CRYPTO_TFM_REQ_MASK); |
305 | crypto_shash_set_flags(child, crypto_ahash_get_flags(parent) & | 305 | crypto_ahash_set_flags(child, crypto_ahash_get_flags(parent) & |
306 | CRYPTO_TFM_REQ_MASK); | 306 | CRYPTO_TFM_REQ_MASK); |
307 | err = crypto_shash_setkey(child, key, keylen); | 307 | err = crypto_ahash_setkey(child, key, keylen); |
308 | crypto_ahash_set_flags(parent, crypto_shash_get_flags(child) & | 308 | crypto_ahash_set_flags(parent, crypto_ahash_get_flags(child) & |
309 | CRYPTO_TFM_RES_MASK); | 309 | CRYPTO_TFM_RES_MASK); |
310 | return err; | 310 | return err; |
311 | } | 311 | } |
@@ -331,20 +331,20 @@ static int mcryptd_hash_enqueue(struct ahash_request *req, | |||
331 | static void mcryptd_hash_init(struct crypto_async_request *req_async, int err) | 331 | static void mcryptd_hash_init(struct crypto_async_request *req_async, int err) |
332 | { | 332 | { |
333 | struct mcryptd_hash_ctx *ctx = crypto_tfm_ctx(req_async->tfm); | 333 | struct mcryptd_hash_ctx *ctx = crypto_tfm_ctx(req_async->tfm); |
334 | struct crypto_shash *child = ctx->child; | 334 | struct crypto_ahash *child = ctx->child; |
335 | struct ahash_request *req = ahash_request_cast(req_async); | 335 | struct ahash_request *req = ahash_request_cast(req_async); |
336 | struct mcryptd_hash_request_ctx *rctx = ahash_request_ctx(req); | 336 | struct mcryptd_hash_request_ctx *rctx = ahash_request_ctx(req); |
337 | struct shash_desc *desc = &rctx->desc; | 337 | struct ahash_request *desc = &rctx->areq; |
338 | 338 | ||
339 | if (unlikely(err == -EINPROGRESS)) | 339 | if (unlikely(err == -EINPROGRESS)) |
340 | goto out; | 340 | goto out; |
341 | 341 | ||
342 | desc->tfm = child; | 342 | ahash_request_set_tfm(desc, child); |
343 | desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP; | 343 | ahash_request_set_callback(desc, CRYPTO_TFM_REQ_MAY_SLEEP, |
344 | rctx->complete, req_async); | ||
344 | 345 | ||
345 | err = crypto_shash_init(desc); | 346 | rctx->out = req->result; |
346 | 347 | err = crypto_ahash_init(desc); | |
347 | req->base.complete = rctx->complete; | ||
348 | 348 | ||
349 | out: | 349 | out: |
350 | local_bh_disable(); | 350 | local_bh_disable(); |
@@ -365,7 +365,8 @@ static void mcryptd_hash_update(struct crypto_async_request *req_async, int err) | |||
365 | if (unlikely(err == -EINPROGRESS)) | 365 | if (unlikely(err == -EINPROGRESS)) |
366 | goto out; | 366 | goto out; |
367 | 367 | ||
368 | err = shash_ahash_mcryptd_update(req, &rctx->desc); | 368 | rctx->out = req->result; |
369 | err = ahash_mcryptd_update(&rctx->areq); | ||
369 | if (err) { | 370 | if (err) { |
370 | req->base.complete = rctx->complete; | 371 | req->base.complete = rctx->complete; |
371 | goto out; | 372 | goto out; |
@@ -391,7 +392,8 @@ static void mcryptd_hash_final(struct crypto_async_request *req_async, int err) | |||
391 | if (unlikely(err == -EINPROGRESS)) | 392 | if (unlikely(err == -EINPROGRESS)) |
392 | goto out; | 393 | goto out; |
393 | 394 | ||
394 | err = shash_ahash_mcryptd_final(req, &rctx->desc); | 395 | rctx->out = req->result; |
396 | err = ahash_mcryptd_final(&rctx->areq); | ||
395 | if (err) { | 397 | if (err) { |
396 | req->base.complete = rctx->complete; | 398 | req->base.complete = rctx->complete; |
397 | goto out; | 399 | goto out; |
@@ -416,8 +418,8 @@ static void mcryptd_hash_finup(struct crypto_async_request *req_async, int err) | |||
416 | 418 | ||
417 | if (unlikely(err == -EINPROGRESS)) | 419 | if (unlikely(err == -EINPROGRESS)) |
418 | goto out; | 420 | goto out; |
419 | 421 | rctx->out = req->result; | |
420 | err = shash_ahash_mcryptd_finup(req, &rctx->desc); | 422 | err = ahash_mcryptd_finup(&rctx->areq); |
421 | 423 | ||
422 | if (err) { | 424 | if (err) { |
423 | req->base.complete = rctx->complete; | 425 | req->base.complete = rctx->complete; |
@@ -439,25 +441,21 @@ static int mcryptd_hash_finup_enqueue(struct ahash_request *req) | |||
439 | static void mcryptd_hash_digest(struct crypto_async_request *req_async, int err) | 441 | static void mcryptd_hash_digest(struct crypto_async_request *req_async, int err) |
440 | { | 442 | { |
441 | struct mcryptd_hash_ctx *ctx = crypto_tfm_ctx(req_async->tfm); | 443 | struct mcryptd_hash_ctx *ctx = crypto_tfm_ctx(req_async->tfm); |
442 | struct crypto_shash *child = ctx->child; | 444 | struct crypto_ahash *child = ctx->child; |
443 | struct ahash_request *req = ahash_request_cast(req_async); | 445 | struct ahash_request *req = ahash_request_cast(req_async); |
444 | struct mcryptd_hash_request_ctx *rctx = ahash_request_ctx(req); | 446 | struct mcryptd_hash_request_ctx *rctx = ahash_request_ctx(req); |
445 | struct shash_desc *desc = &rctx->desc; | 447 | struct ahash_request *desc = &rctx->areq; |
446 | 448 | ||
447 | if (unlikely(err == -EINPROGRESS)) | 449 | if (unlikely(err == -EINPROGRESS)) |
448 | goto out; | 450 | goto out; |
449 | 451 | ||
450 | desc->tfm = child; | 452 | ahash_request_set_tfm(desc, child); |
451 | desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP; /* check this again */ | 453 | ahash_request_set_callback(desc, CRYPTO_TFM_REQ_MAY_SLEEP, |
452 | 454 | rctx->complete, req_async); | |
453 | err = shash_ahash_mcryptd_digest(req, desc); | ||
454 | 455 | ||
455 | if (err) { | 456 | rctx->out = req->result; |
456 | req->base.complete = rctx->complete; | 457 | err = ahash_mcryptd_digest(desc); |
457 | goto out; | ||
458 | } | ||
459 | 458 | ||
460 | return; | ||
461 | out: | 459 | out: |
462 | local_bh_disable(); | 460 | local_bh_disable(); |
463 | rctx->complete(&req->base, err); | 461 | rctx->complete(&req->base, err); |
@@ -473,14 +471,14 @@ static int mcryptd_hash_export(struct ahash_request *req, void *out) | |||
473 | { | 471 | { |
474 | struct mcryptd_hash_request_ctx *rctx = ahash_request_ctx(req); | 472 | struct mcryptd_hash_request_ctx *rctx = ahash_request_ctx(req); |
475 | 473 | ||
476 | return crypto_shash_export(&rctx->desc, out); | 474 | return crypto_ahash_export(&rctx->areq, out); |
477 | } | 475 | } |
478 | 476 | ||
479 | static int mcryptd_hash_import(struct ahash_request *req, const void *in) | 477 | static int mcryptd_hash_import(struct ahash_request *req, const void *in) |
480 | { | 478 | { |
481 | struct mcryptd_hash_request_ctx *rctx = ahash_request_ctx(req); | 479 | struct mcryptd_hash_request_ctx *rctx = ahash_request_ctx(req); |
482 | 480 | ||
483 | return crypto_shash_import(&rctx->desc, in); | 481 | return crypto_ahash_import(&rctx->areq, in); |
484 | } | 482 | } |
485 | 483 | ||
486 | static int mcryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb, | 484 | static int mcryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb, |
@@ -488,7 +486,7 @@ static int mcryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb, | |||
488 | { | 486 | { |
489 | struct hashd_instance_ctx *ctx; | 487 | struct hashd_instance_ctx *ctx; |
490 | struct ahash_instance *inst; | 488 | struct ahash_instance *inst; |
491 | struct shash_alg *salg; | 489 | struct hash_alg_common *halg; |
492 | struct crypto_alg *alg; | 490 | struct crypto_alg *alg; |
493 | u32 type = 0; | 491 | u32 type = 0; |
494 | u32 mask = 0; | 492 | u32 mask = 0; |
@@ -496,11 +494,11 @@ static int mcryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb, | |||
496 | 494 | ||
497 | mcryptd_check_internal(tb, &type, &mask); | 495 | mcryptd_check_internal(tb, &type, &mask); |
498 | 496 | ||
499 | salg = shash_attr_alg(tb[1], type, mask); | 497 | halg = ahash_attr_alg(tb[1], type, mask); |
500 | if (IS_ERR(salg)) | 498 | if (IS_ERR(halg)) |
501 | return PTR_ERR(salg); | 499 | return PTR_ERR(halg); |
502 | 500 | ||
503 | alg = &salg->base; | 501 | alg = &halg->base; |
504 | pr_debug("crypto: mcryptd hash alg: %s\n", alg->cra_name); | 502 | pr_debug("crypto: mcryptd hash alg: %s\n", alg->cra_name); |
505 | inst = mcryptd_alloc_instance(alg, ahash_instance_headroom(), | 503 | inst = mcryptd_alloc_instance(alg, ahash_instance_headroom(), |
506 | sizeof(*ctx)); | 504 | sizeof(*ctx)); |
@@ -511,7 +509,7 @@ static int mcryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb, | |||
511 | ctx = ahash_instance_ctx(inst); | 509 | ctx = ahash_instance_ctx(inst); |
512 | ctx->queue = queue; | 510 | ctx->queue = queue; |
513 | 511 | ||
514 | err = crypto_init_shash_spawn(&ctx->spawn, salg, | 512 | err = crypto_init_ahash_spawn(&ctx->spawn, halg, |
515 | ahash_crypto_instance(inst)); | 513 | ahash_crypto_instance(inst)); |
516 | if (err) | 514 | if (err) |
517 | goto out_free_inst; | 515 | goto out_free_inst; |
@@ -521,8 +519,8 @@ static int mcryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb, | |||
521 | type |= CRYPTO_ALG_INTERNAL; | 519 | type |= CRYPTO_ALG_INTERNAL; |
522 | inst->alg.halg.base.cra_flags = type; | 520 | inst->alg.halg.base.cra_flags = type; |
523 | 521 | ||
524 | inst->alg.halg.digestsize = salg->digestsize; | 522 | inst->alg.halg.digestsize = halg->digestsize; |
525 | inst->alg.halg.statesize = salg->statesize; | 523 | inst->alg.halg.statesize = halg->statesize; |
526 | inst->alg.halg.base.cra_ctxsize = sizeof(struct mcryptd_hash_ctx); | 524 | inst->alg.halg.base.cra_ctxsize = sizeof(struct mcryptd_hash_ctx); |
527 | 525 | ||
528 | inst->alg.halg.base.cra_init = mcryptd_hash_init_tfm; | 526 | inst->alg.halg.base.cra_init = mcryptd_hash_init_tfm; |
@@ -539,7 +537,7 @@ static int mcryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb, | |||
539 | 537 | ||
540 | err = ahash_register_instance(tmpl, inst); | 538 | err = ahash_register_instance(tmpl, inst); |
541 | if (err) { | 539 | if (err) { |
542 | crypto_drop_shash(&ctx->spawn); | 540 | crypto_drop_ahash(&ctx->spawn); |
543 | out_free_inst: | 541 | out_free_inst: |
544 | kfree(inst); | 542 | kfree(inst); |
545 | } | 543 | } |
@@ -575,7 +573,7 @@ static void mcryptd_free(struct crypto_instance *inst) | |||
575 | 573 | ||
576 | switch (inst->alg.cra_flags & CRYPTO_ALG_TYPE_MASK) { | 574 | switch (inst->alg.cra_flags & CRYPTO_ALG_TYPE_MASK) { |
577 | case CRYPTO_ALG_TYPE_AHASH: | 575 | case CRYPTO_ALG_TYPE_AHASH: |
578 | crypto_drop_shash(&hctx->spawn); | 576 | crypto_drop_ahash(&hctx->spawn); |
579 | kfree(ahash_instance(inst)); | 577 | kfree(ahash_instance(inst)); |
580 | return; | 578 | return; |
581 | default: | 579 | default: |
@@ -612,55 +610,38 @@ struct mcryptd_ahash *mcryptd_alloc_ahash(const char *alg_name, | |||
612 | } | 610 | } |
613 | EXPORT_SYMBOL_GPL(mcryptd_alloc_ahash); | 611 | EXPORT_SYMBOL_GPL(mcryptd_alloc_ahash); |
614 | 612 | ||
615 | int shash_ahash_mcryptd_digest(struct ahash_request *req, | 613 | int ahash_mcryptd_digest(struct ahash_request *desc) |
616 | struct shash_desc *desc) | ||
617 | { | 614 | { |
618 | int err; | 615 | int err; |
619 | 616 | ||
620 | err = crypto_shash_init(desc) ?: | 617 | err = crypto_ahash_init(desc) ?: |
621 | shash_ahash_mcryptd_finup(req, desc); | 618 | ahash_mcryptd_finup(desc); |
622 | 619 | ||
623 | return err; | 620 | return err; |
624 | } | 621 | } |
625 | EXPORT_SYMBOL_GPL(shash_ahash_mcryptd_digest); | ||
626 | 622 | ||
627 | int shash_ahash_mcryptd_update(struct ahash_request *req, | 623 | int ahash_mcryptd_update(struct ahash_request *desc) |
628 | struct shash_desc *desc) | ||
629 | { | 624 | { |
630 | struct crypto_shash *tfm = desc->tfm; | ||
631 | struct shash_alg *shash = crypto_shash_alg(tfm); | ||
632 | |||
633 | /* alignment is to be done by multi-buffer crypto algorithm if needed */ | 625 | /* alignment is to be done by multi-buffer crypto algorithm if needed */ |
634 | 626 | ||
635 | return shash->update(desc, NULL, 0); | 627 | return crypto_ahash_update(desc); |
636 | } | 628 | } |
637 | EXPORT_SYMBOL_GPL(shash_ahash_mcryptd_update); | ||
638 | 629 | ||
639 | int shash_ahash_mcryptd_finup(struct ahash_request *req, | 630 | int ahash_mcryptd_finup(struct ahash_request *desc) |
640 | struct shash_desc *desc) | ||
641 | { | 631 | { |
642 | struct crypto_shash *tfm = desc->tfm; | ||
643 | struct shash_alg *shash = crypto_shash_alg(tfm); | ||
644 | |||
645 | /* alignment is to be done by multi-buffer crypto algorithm if needed */ | 632 | /* alignment is to be done by multi-buffer crypto algorithm if needed */ |
646 | 633 | ||
647 | return shash->finup(desc, NULL, 0, req->result); | 634 | return crypto_ahash_finup(desc); |
648 | } | 635 | } |
649 | EXPORT_SYMBOL_GPL(shash_ahash_mcryptd_finup); | ||
650 | 636 | ||
651 | int shash_ahash_mcryptd_final(struct ahash_request *req, | 637 | int ahash_mcryptd_final(struct ahash_request *desc) |
652 | struct shash_desc *desc) | ||
653 | { | 638 | { |
654 | struct crypto_shash *tfm = desc->tfm; | ||
655 | struct shash_alg *shash = crypto_shash_alg(tfm); | ||
656 | |||
657 | /* alignment is to be done by multi-buffer crypto algorithm if needed */ | 639 | /* alignment is to be done by multi-buffer crypto algorithm if needed */ |
658 | 640 | ||
659 | return shash->final(desc, req->result); | 641 | return crypto_ahash_final(desc); |
660 | } | 642 | } |
661 | EXPORT_SYMBOL_GPL(shash_ahash_mcryptd_final); | ||
662 | 643 | ||
663 | struct crypto_shash *mcryptd_ahash_child(struct mcryptd_ahash *tfm) | 644 | struct crypto_ahash *mcryptd_ahash_child(struct mcryptd_ahash *tfm) |
664 | { | 645 | { |
665 | struct mcryptd_hash_ctx *ctx = crypto_ahash_ctx(&tfm->base); | 646 | struct mcryptd_hash_ctx *ctx = crypto_ahash_ctx(&tfm->base); |
666 | 647 | ||
@@ -668,12 +649,12 @@ struct crypto_shash *mcryptd_ahash_child(struct mcryptd_ahash *tfm) | |||
668 | } | 649 | } |
669 | EXPORT_SYMBOL_GPL(mcryptd_ahash_child); | 650 | EXPORT_SYMBOL_GPL(mcryptd_ahash_child); |
670 | 651 | ||
671 | struct shash_desc *mcryptd_shash_desc(struct ahash_request *req) | 652 | struct ahash_request *mcryptd_ahash_desc(struct ahash_request *req) |
672 | { | 653 | { |
673 | struct mcryptd_hash_request_ctx *rctx = ahash_request_ctx(req); | 654 | struct mcryptd_hash_request_ctx *rctx = ahash_request_ctx(req); |
674 | return &rctx->desc; | 655 | return &rctx->areq; |
675 | } | 656 | } |
676 | EXPORT_SYMBOL_GPL(mcryptd_shash_desc); | 657 | EXPORT_SYMBOL_GPL(mcryptd_ahash_desc); |
677 | 658 | ||
678 | void mcryptd_free_ahash(struct mcryptd_ahash *tfm) | 659 | void mcryptd_free_ahash(struct mcryptd_ahash *tfm) |
679 | { | 660 | { |
@@ -681,7 +662,6 @@ void mcryptd_free_ahash(struct mcryptd_ahash *tfm) | |||
681 | } | 662 | } |
682 | EXPORT_SYMBOL_GPL(mcryptd_free_ahash); | 663 | EXPORT_SYMBOL_GPL(mcryptd_free_ahash); |
683 | 664 | ||
684 | |||
685 | static int __init mcryptd_init(void) | 665 | static int __init mcryptd_init(void) |
686 | { | 666 | { |
687 | int err, cpu; | 667 | int err, cpu; |