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

Configure Feed

Select the types of activity you want to include in your feed.

crypto: sahara - avoid skcipher fallback code duplication

Factor out duplicated skcipher fallback handling code to a helper function
sahara_aes_fallback(). Also, keep a single check if fallback is required in
sahara_aes_crypt().

Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Ovidiu Panait and committed by
Herbert Xu
01d70a4b 3d5a31df

+25 -60
+25 -60
drivers/crypto/sahara.c
··· 646 646 return crypto_skcipher_setkey(ctx->fallback, key, keylen); 647 647 } 648 648 649 + static int sahara_aes_fallback(struct skcipher_request *req, unsigned long mode) 650 + { 651 + struct sahara_aes_reqctx *rctx = skcipher_request_ctx(req); 652 + struct sahara_ctx *ctx = crypto_skcipher_ctx( 653 + crypto_skcipher_reqtfm(req)); 654 + 655 + skcipher_request_set_tfm(&rctx->fallback_req, ctx->fallback); 656 + skcipher_request_set_callback(&rctx->fallback_req, 657 + req->base.flags, 658 + req->base.complete, 659 + req->base.data); 660 + skcipher_request_set_crypt(&rctx->fallback_req, req->src, 661 + req->dst, req->cryptlen, req->iv); 662 + 663 + if (mode & FLAGS_ENCRYPT) 664 + return crypto_skcipher_encrypt(&rctx->fallback_req); 665 + 666 + return crypto_skcipher_decrypt(&rctx->fallback_req); 667 + } 668 + 649 669 static int sahara_aes_crypt(struct skcipher_request *req, unsigned long mode) 650 670 { 651 671 struct sahara_aes_reqctx *rctx = skcipher_request_ctx(req); 672 + struct sahara_ctx *ctx = crypto_skcipher_ctx( 673 + crypto_skcipher_reqtfm(req)); 652 674 struct sahara_dev *dev = dev_ptr; 653 675 int err = 0; 676 + 677 + if (unlikely(ctx->keylen != AES_KEYSIZE_128)) 678 + return sahara_aes_fallback(req, mode); 654 679 655 680 dev_dbg(dev->device, "nbytes: %d, enc: %d, cbc: %d\n", 656 681 req->cryptlen, !!(mode & FLAGS_ENCRYPT), !!(mode & FLAGS_CBC)); ··· 699 674 700 675 static int sahara_aes_ecb_encrypt(struct skcipher_request *req) 701 676 { 702 - struct sahara_aes_reqctx *rctx = skcipher_request_ctx(req); 703 - struct sahara_ctx *ctx = crypto_skcipher_ctx( 704 - crypto_skcipher_reqtfm(req)); 705 - 706 - if (unlikely(ctx->keylen != AES_KEYSIZE_128)) { 707 - skcipher_request_set_tfm(&rctx->fallback_req, ctx->fallback); 708 - skcipher_request_set_callback(&rctx->fallback_req, 709 - req->base.flags, 710 - req->base.complete, 711 - req->base.data); 712 - skcipher_request_set_crypt(&rctx->fallback_req, req->src, 713 - req->dst, req->cryptlen, req->iv); 714 - return crypto_skcipher_encrypt(&rctx->fallback_req); 715 - } 716 - 717 677 return sahara_aes_crypt(req, FLAGS_ENCRYPT); 718 678 } 719 679 720 680 static int sahara_aes_ecb_decrypt(struct skcipher_request *req) 721 681 { 722 - struct sahara_aes_reqctx *rctx = skcipher_request_ctx(req); 723 - struct sahara_ctx *ctx = crypto_skcipher_ctx( 724 - crypto_skcipher_reqtfm(req)); 725 - 726 - if (unlikely(ctx->keylen != AES_KEYSIZE_128)) { 727 - skcipher_request_set_tfm(&rctx->fallback_req, ctx->fallback); 728 - skcipher_request_set_callback(&rctx->fallback_req, 729 - req->base.flags, 730 - req->base.complete, 731 - req->base.data); 732 - skcipher_request_set_crypt(&rctx->fallback_req, req->src, 733 - req->dst, req->cryptlen, req->iv); 734 - return crypto_skcipher_decrypt(&rctx->fallback_req); 735 - } 736 - 737 682 return sahara_aes_crypt(req, 0); 738 683 } 739 684 740 685 static int sahara_aes_cbc_encrypt(struct skcipher_request *req) 741 686 { 742 - struct sahara_aes_reqctx *rctx = skcipher_request_ctx(req); 743 - struct sahara_ctx *ctx = crypto_skcipher_ctx( 744 - crypto_skcipher_reqtfm(req)); 745 - 746 - if (unlikely(ctx->keylen != AES_KEYSIZE_128)) { 747 - skcipher_request_set_tfm(&rctx->fallback_req, ctx->fallback); 748 - skcipher_request_set_callback(&rctx->fallback_req, 749 - req->base.flags, 750 - req->base.complete, 751 - req->base.data); 752 - skcipher_request_set_crypt(&rctx->fallback_req, req->src, 753 - req->dst, req->cryptlen, req->iv); 754 - return crypto_skcipher_encrypt(&rctx->fallback_req); 755 - } 756 - 757 687 return sahara_aes_crypt(req, FLAGS_ENCRYPT | FLAGS_CBC); 758 688 } 759 689 760 690 static int sahara_aes_cbc_decrypt(struct skcipher_request *req) 761 691 { 762 - struct sahara_aes_reqctx *rctx = skcipher_request_ctx(req); 763 - struct sahara_ctx *ctx = crypto_skcipher_ctx( 764 - crypto_skcipher_reqtfm(req)); 765 - 766 - if (unlikely(ctx->keylen != AES_KEYSIZE_128)) { 767 - skcipher_request_set_tfm(&rctx->fallback_req, ctx->fallback); 768 - skcipher_request_set_callback(&rctx->fallback_req, 769 - req->base.flags, 770 - req->base.complete, 771 - req->base.data); 772 - skcipher_request_set_crypt(&rctx->fallback_req, req->src, 773 - req->dst, req->cryptlen, req->iv); 774 - return crypto_skcipher_decrypt(&rctx->fallback_req); 775 - } 776 - 777 692 return sahara_aes_crypt(req, FLAGS_CBC); 778 693 } 779 694