Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: img-hash - Add support for export and import

Currently the img-hash accelerator does not probe
successfully due to a change in the checks made during
registration with the crypto framework. This is due to
import and export functions not being defined. Correct
this.

Signed-off-by: James Hartley <james.hartley@imgtec.com>
Signed-off-by: Will Thomas <will.thomas@imgtec.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

James Hartley and committed by
Herbert Xu
436e3bb5 d084e13a

+63 -6
+63 -6
drivers/crypto/img-hash.c
··· 590 590 return crypto_ahash_finup(&rctx->fallback_req); 591 591 } 592 592 593 + static int img_hash_import(struct ahash_request *req, const void *in) 594 + { 595 + struct img_hash_request_ctx *rctx = ahash_request_ctx(req); 596 + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 597 + struct img_hash_ctx *ctx = crypto_ahash_ctx(tfm); 598 + 599 + ahash_request_set_tfm(&rctx->fallback_req, ctx->fallback); 600 + rctx->fallback_req.base.flags = req->base.flags 601 + & CRYPTO_TFM_REQ_MAY_SLEEP; 602 + 603 + return crypto_ahash_import(&rctx->fallback_req, in); 604 + } 605 + 606 + static int img_hash_export(struct ahash_request *req, void *out) 607 + { 608 + struct img_hash_request_ctx *rctx = ahash_request_ctx(req); 609 + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 610 + struct img_hash_ctx *ctx = crypto_ahash_ctx(tfm); 611 + 612 + ahash_request_set_tfm(&rctx->fallback_req, ctx->fallback); 613 + rctx->fallback_req.base.flags = req->base.flags 614 + & CRYPTO_TFM_REQ_MAY_SLEEP; 615 + 616 + return crypto_ahash_export(&rctx->fallback_req, out); 617 + } 618 + 593 619 static int img_hash_digest(struct ahash_request *req) 594 620 { 595 621 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); ··· 672 646 return err; 673 647 } 674 648 675 - static int img_hash_cra_init(struct crypto_tfm *tfm) 649 + static int img_hash_cra_init(struct crypto_tfm *tfm, const char *alg_name) 676 650 { 677 651 struct img_hash_ctx *ctx = crypto_tfm_ctx(tfm); 678 - const char *alg_name = crypto_tfm_alg_name(tfm); 679 652 int err = -ENOMEM; 680 653 681 654 ctx->fallback = crypto_alloc_ahash(alg_name, 0, ··· 692 667 693 668 err: 694 669 return err; 670 + } 671 + 672 + static int img_hash_cra_md5_init(struct crypto_tfm *tfm) 673 + { 674 + return img_hash_cra_init(tfm, "md5-generic"); 675 + } 676 + 677 + static int img_hash_cra_sha1_init(struct crypto_tfm *tfm) 678 + { 679 + return img_hash_cra_init(tfm, "sha1-generic"); 680 + } 681 + 682 + static int img_hash_cra_sha224_init(struct crypto_tfm *tfm) 683 + { 684 + return img_hash_cra_init(tfm, "sha224-generic"); 685 + } 686 + 687 + static int img_hash_cra_sha256_init(struct crypto_tfm *tfm) 688 + { 689 + return img_hash_cra_init(tfm, "sha256-generic"); 695 690 } 696 691 697 692 static void img_hash_cra_exit(struct crypto_tfm *tfm) ··· 759 714 .update = img_hash_update, 760 715 .final = img_hash_final, 761 716 .finup = img_hash_finup, 717 + .export = img_hash_export, 718 + .import = img_hash_import, 762 719 .digest = img_hash_digest, 763 720 .halg = { 764 721 .digestsize = MD5_DIGEST_SIZE, 722 + .statesize = sizeof(struct md5_state), 765 723 .base = { 766 724 .cra_name = "md5", 767 725 .cra_driver_name = "img-md5", ··· 774 726 CRYPTO_ALG_NEED_FALLBACK, 775 727 .cra_blocksize = MD5_HMAC_BLOCK_SIZE, 776 728 .cra_ctxsize = sizeof(struct img_hash_ctx), 777 - .cra_init = img_hash_cra_init, 729 + .cra_init = img_hash_cra_md5_init, 778 730 .cra_exit = img_hash_cra_exit, 779 731 .cra_module = THIS_MODULE, 780 732 } ··· 785 737 .update = img_hash_update, 786 738 .final = img_hash_final, 787 739 .finup = img_hash_finup, 740 + .export = img_hash_export, 741 + .import = img_hash_import, 788 742 .digest = img_hash_digest, 789 743 .halg = { 790 744 .digestsize = SHA1_DIGEST_SIZE, 745 + .statesize = sizeof(struct sha1_state), 791 746 .base = { 792 747 .cra_name = "sha1", 793 748 .cra_driver_name = "img-sha1", ··· 800 749 CRYPTO_ALG_NEED_FALLBACK, 801 750 .cra_blocksize = SHA1_BLOCK_SIZE, 802 751 .cra_ctxsize = sizeof(struct img_hash_ctx), 803 - .cra_init = img_hash_cra_init, 752 + .cra_init = img_hash_cra_sha1_init, 804 753 .cra_exit = img_hash_cra_exit, 805 754 .cra_module = THIS_MODULE, 806 755 } ··· 811 760 .update = img_hash_update, 812 761 .final = img_hash_final, 813 762 .finup = img_hash_finup, 763 + .export = img_hash_export, 764 + .import = img_hash_import, 814 765 .digest = img_hash_digest, 815 766 .halg = { 816 767 .digestsize = SHA224_DIGEST_SIZE, 768 + .statesize = sizeof(struct sha256_state), 817 769 .base = { 818 770 .cra_name = "sha224", 819 771 .cra_driver_name = "img-sha224", ··· 826 772 CRYPTO_ALG_NEED_FALLBACK, 827 773 .cra_blocksize = SHA224_BLOCK_SIZE, 828 774 .cra_ctxsize = sizeof(struct img_hash_ctx), 829 - .cra_init = img_hash_cra_init, 775 + .cra_init = img_hash_cra_sha224_init, 830 776 .cra_exit = img_hash_cra_exit, 831 777 .cra_module = THIS_MODULE, 832 778 } ··· 837 783 .update = img_hash_update, 838 784 .final = img_hash_final, 839 785 .finup = img_hash_finup, 786 + .export = img_hash_export, 787 + .import = img_hash_import, 840 788 .digest = img_hash_digest, 841 789 .halg = { 842 790 .digestsize = SHA256_DIGEST_SIZE, 791 + .statesize = sizeof(struct sha256_state), 843 792 .base = { 844 793 .cra_name = "sha256", 845 794 .cra_driver_name = "img-sha256", ··· 852 795 CRYPTO_ALG_NEED_FALLBACK, 853 796 .cra_blocksize = SHA256_BLOCK_SIZE, 854 797 .cra_ctxsize = sizeof(struct img_hash_ctx), 855 - .cra_init = img_hash_cra_init, 798 + .cra_init = img_hash_cra_sha256_init, 856 799 .cra_exit = img_hash_cra_exit, 857 800 .cra_module = THIS_MODULE, 858 801 }