Merge tag 'drm-misc-next-fixes-2018-04-04' of git://anongit.freedesktop.org/drm/drm...
[sfrench/cifs-2.6.git] / crypto / skcipher.c
index 11af5fd6a443570550e1dac5b0a429b2cae801b1..0fe2a2923ad0b0d02da50c3b0464258d987e13ec 100644 (file)
@@ -598,8 +598,11 @@ static int skcipher_setkey_blkcipher(struct crypto_skcipher *tfm,
        err = crypto_blkcipher_setkey(blkcipher, key, keylen);
        crypto_skcipher_set_flags(tfm, crypto_blkcipher_get_flags(blkcipher) &
                                       CRYPTO_TFM_RES_MASK);
+       if (err)
+               return err;
 
-       return err;
+       crypto_skcipher_clear_flags(tfm, CRYPTO_TFM_NEED_KEY);
+       return 0;
 }
 
 static int skcipher_crypt_blkcipher(struct skcipher_request *req,
@@ -674,6 +677,9 @@ static int crypto_init_skcipher_ops_blkcipher(struct crypto_tfm *tfm)
        skcipher->ivsize = crypto_blkcipher_ivsize(blkcipher);
        skcipher->keysize = calg->cra_blkcipher.max_keysize;
 
+       if (skcipher->keysize)
+               crypto_skcipher_set_flags(skcipher, CRYPTO_TFM_NEED_KEY);
+
        return 0;
 }
 
@@ -692,8 +698,11 @@ static int skcipher_setkey_ablkcipher(struct crypto_skcipher *tfm,
        crypto_skcipher_set_flags(tfm,
                                  crypto_ablkcipher_get_flags(ablkcipher) &
                                  CRYPTO_TFM_RES_MASK);
+       if (err)
+               return err;
 
-       return err;
+       crypto_skcipher_clear_flags(tfm, CRYPTO_TFM_NEED_KEY);
+       return 0;
 }
 
 static int skcipher_crypt_ablkcipher(struct skcipher_request *req,
@@ -767,6 +776,9 @@ static int crypto_init_skcipher_ops_ablkcipher(struct crypto_tfm *tfm)
                            sizeof(struct ablkcipher_request);
        skcipher->keysize = calg->cra_ablkcipher.max_keysize;
 
+       if (skcipher->keysize)
+               crypto_skcipher_set_flags(skcipher, CRYPTO_TFM_NEED_KEY);
+
        return 0;
 }
 
@@ -796,6 +808,7 @@ static int skcipher_setkey(struct crypto_skcipher *tfm, const u8 *key,
 {
        struct skcipher_alg *cipher = crypto_skcipher_alg(tfm);
        unsigned long alignmask = crypto_skcipher_alignmask(tfm);
+       int err;
 
        if (keylen < cipher->min_keysize || keylen > cipher->max_keysize) {
                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,
        }
 
        if ((unsigned long)key & alignmask)
-               return skcipher_setkey_unaligned(tfm, key, keylen);
+               err = skcipher_setkey_unaligned(tfm, key, keylen);
+       else
+               err = cipher->setkey(tfm, key, keylen);
+
+       if (err)
+               return err;
 
-       return cipher->setkey(tfm, key, keylen);
+       crypto_skcipher_clear_flags(tfm, CRYPTO_TFM_NEED_KEY);
+       return 0;
 }
 
 static void crypto_skcipher_exit_tfm(struct crypto_tfm *tfm)
@@ -834,6 +853,9 @@ static int crypto_skcipher_init_tfm(struct crypto_tfm *tfm)
        skcipher->ivsize = alg->ivsize;
        skcipher->keysize = alg->max_keysize;
 
+       if (skcipher->keysize)
+               crypto_skcipher_set_flags(skcipher, CRYPTO_TFM_NEED_KEY);
+
        if (alg->exit)
                skcipher->base.exit = crypto_skcipher_exit_tfm;