]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - crypto/shash.c
crypto: shash - Add init_tfm/exit_tfm and verify descsize
[linux.git] / crypto / shash.c
index 7989258a46b4cc2ba4da5f1d85a78609a56024e6..8042bb0df9c057ed2c5fa11a87fe1280eae4b588 100644 (file)
@@ -385,15 +385,41 @@ int crypto_init_shash_ops_async(struct crypto_tfm *tfm)
        return 0;
 }
 
+static void crypto_shash_exit_tfm(struct crypto_tfm *tfm)
+{
+       struct crypto_shash *hash = __crypto_shash_cast(tfm);
+       struct shash_alg *alg = crypto_shash_alg(hash);
+
+       alg->exit_tfm(hash);
+}
+
 static int crypto_shash_init_tfm(struct crypto_tfm *tfm)
 {
        struct crypto_shash *hash = __crypto_shash_cast(tfm);
        struct shash_alg *alg = crypto_shash_alg(hash);
+       int err;
 
        hash->descsize = alg->descsize;
 
        shash_set_needkey(hash, alg);
 
+       if (alg->exit_tfm)
+               tfm->exit = crypto_shash_exit_tfm;
+
+       if (!alg->init_tfm)
+               return 0;
+
+       err = alg->init_tfm(hash);
+       if (err)
+               return err;
+
+       /* ->init_tfm() may have increased the descsize. */
+       if (WARN_ON_ONCE(hash->descsize > HASH_MAX_DESCSIZE)) {
+               if (alg->exit_tfm)
+                       alg->exit_tfm(hash);
+               return -EINVAL;
+       }
+
        return 0;
 }