summaryrefslogtreecommitdiffstats
path: root/crypto/skcipher.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/skcipher.c')
-rw-r--r--crypto/skcipher.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/crypto/skcipher.c b/crypto/skcipher.c
index 11af5fd6a443..0fe2a2923ad0 100644
--- a/crypto/skcipher.c
+++ b/crypto/skcipher.c
@@ -598,8 +598,11 @@ static int skcipher_setkey_blkcipher(struct crypto_skcipher *tfm,
598 err = crypto_blkcipher_setkey(blkcipher, key, keylen); 598 err = crypto_blkcipher_setkey(blkcipher, key, keylen);
599 crypto_skcipher_set_flags(tfm, crypto_blkcipher_get_flags(blkcipher) & 599 crypto_skcipher_set_flags(tfm, crypto_blkcipher_get_flags(blkcipher) &
600 CRYPTO_TFM_RES_MASK); 600 CRYPTO_TFM_RES_MASK);
601 if (err)
602 return err;
601 603
602 return err; 604 crypto_skcipher_clear_flags(tfm, CRYPTO_TFM_NEED_KEY);
605 return 0;
603} 606}
604 607
605static int skcipher_crypt_blkcipher(struct skcipher_request *req, 608static int skcipher_crypt_blkcipher(struct skcipher_request *req,
@@ -674,6 +677,9 @@ static int crypto_init_skcipher_ops_blkcipher(struct crypto_tfm *tfm)
674 skcipher->ivsize = crypto_blkcipher_ivsize(blkcipher); 677 skcipher->ivsize = crypto_blkcipher_ivsize(blkcipher);
675 skcipher->keysize = calg->cra_blkcipher.max_keysize; 678 skcipher->keysize = calg->cra_blkcipher.max_keysize;
676 679
680 if (skcipher->keysize)
681 crypto_skcipher_set_flags(skcipher, CRYPTO_TFM_NEED_KEY);
682
677 return 0; 683 return 0;
678} 684}
679 685
@@ -692,8 +698,11 @@ static int skcipher_setkey_ablkcipher(struct crypto_skcipher *tfm,
692 crypto_skcipher_set_flags(tfm, 698 crypto_skcipher_set_flags(tfm,
693 crypto_ablkcipher_get_flags(ablkcipher) & 699 crypto_ablkcipher_get_flags(ablkcipher) &
694 CRYPTO_TFM_RES_MASK); 700 CRYPTO_TFM_RES_MASK);
701 if (err)
702 return err;
695 703
696 return err; 704 crypto_skcipher_clear_flags(tfm, CRYPTO_TFM_NEED_KEY);
705 return 0;
697} 706}
698 707
699static int skcipher_crypt_ablkcipher(struct skcipher_request *req, 708static int skcipher_crypt_ablkcipher(struct skcipher_request *req,
@@ -767,6 +776,9 @@ static int crypto_init_skcipher_ops_ablkcipher(struct crypto_tfm *tfm)
767 sizeof(struct ablkcipher_request); 776 sizeof(struct ablkcipher_request);
768 skcipher->keysize = calg->cra_ablkcipher.max_keysize; 777 skcipher->keysize = calg->cra_ablkcipher.max_keysize;
769 778
779 if (skcipher->keysize)
780 crypto_skcipher_set_flags(skcipher, CRYPTO_TFM_NEED_KEY);
781
770 return 0; 782 return 0;
771} 783}
772 784
@@ -796,6 +808,7 @@ static int skcipher_setkey(struct crypto_skcipher *tfm, const u8 *key,
796{ 808{
797 struct skcipher_alg *cipher = crypto_skcipher_alg(tfm); 809 struct skcipher_alg *cipher = crypto_skcipher_alg(tfm);
798 unsigned long alignmask = crypto_skcipher_alignmask(tfm); 810 unsigned long alignmask = crypto_skcipher_alignmask(tfm);
811 int err;
799 812
800 if (keylen < cipher->min_keysize || keylen > cipher->max_keysize) { 813 if (keylen < cipher->min_keysize || keylen > cipher->max_keysize) {
801 crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); 814 crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
@@ -803,9 +816,15 @@ static int skcipher_setkey(struct crypto_skcipher *tfm, const u8 *key,
803 } 816 }
804 817
805 if ((unsigned long)key & alignmask) 818 if ((unsigned long)key & alignmask)
806 return skcipher_setkey_unaligned(tfm, key, keylen); 819 err = skcipher_setkey_unaligned(tfm, key, keylen);
820 else
821 err = cipher->setkey(tfm, key, keylen);
822
823 if (err)
824 return err;
807 825
808 return cipher->setkey(tfm, key, keylen); 826 crypto_skcipher_clear_flags(tfm, CRYPTO_TFM_NEED_KEY);
827 return 0;
809} 828}
810 829
811static void crypto_skcipher_exit_tfm(struct crypto_tfm *tfm) 830static void crypto_skcipher_exit_tfm(struct crypto_tfm *tfm)
@@ -834,6 +853,9 @@ static int crypto_skcipher_init_tfm(struct crypto_tfm *tfm)
834 skcipher->ivsize = alg->ivsize; 853 skcipher->ivsize = alg->ivsize;
835 skcipher->keysize = alg->max_keysize; 854 skcipher->keysize = alg->max_keysize;
836 855
856 if (skcipher->keysize)
857 crypto_skcipher_set_flags(skcipher, CRYPTO_TFM_NEED_KEY);
858
837 if (alg->exit) 859 if (alg->exit)
838 skcipher->base.exit = crypto_skcipher_exit_tfm; 860 skcipher->base.exit = crypto_skcipher_exit_tfm;
839 861