crypto: aead - prevent using AEADs without setting key
[linux-2.6-microblaze.git] / crypto / aead.c
index fe00cbd..60b3bbe 100644 (file)
@@ -54,11 +54,18 @@ int crypto_aead_setkey(struct crypto_aead *tfm,
                       const u8 *key, unsigned int keylen)
 {
        unsigned long alignmask = crypto_aead_alignmask(tfm);
+       int err;
 
        if ((unsigned long)key & alignmask)
-               return setkey_unaligned(tfm, key, keylen);
+               err = setkey_unaligned(tfm, key, keylen);
+       else
+               err = crypto_aead_alg(tfm)->setkey(tfm, key, keylen);
+
+       if (err)
+               return err;
 
-       return crypto_aead_alg(tfm)->setkey(tfm, key, keylen);
+       crypto_aead_clear_flags(tfm, CRYPTO_TFM_NEED_KEY);
+       return 0;
 }
 EXPORT_SYMBOL_GPL(crypto_aead_setkey);
 
@@ -93,6 +100,8 @@ static int crypto_aead_init_tfm(struct crypto_tfm *tfm)
        struct crypto_aead *aead = __crypto_aead_cast(tfm);
        struct aead_alg *alg = crypto_aead_alg(aead);
 
+       crypto_aead_set_flags(aead, CRYPTO_TFM_NEED_KEY);
+
        aead->authsize = alg->maxauthsize;
 
        if (alg->exit)