Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[sfrench/cifs-2.6.git] / crypto / ahash.c
index d9d65d1cc6690984fa141a48b4490ff80bf69dfb..c2ca631a111fc7fd0b860946d920a360f142fce7 100644 (file)
@@ -10,7 +10,6 @@
 
 #include <crypto/internal/hash.h>
 #include <crypto/scatterwalk.h>
-#include <linux/bug.h>
 #include <linux/err.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
@@ -46,10 +45,7 @@ static int hash_walk_next(struct crypto_hash_walk *walk)
        unsigned int nbytes = min(walk->entrylen,
                                  ((unsigned int)(PAGE_SIZE)) - offset);
 
-       if (walk->flags & CRYPTO_ALG_ASYNC)
-               walk->data = kmap(walk->pg);
-       else
-               walk->data = kmap_atomic(walk->pg);
+       walk->data = kmap_atomic(walk->pg);
        walk->data += offset;
 
        if (offset & alignmask) {
@@ -99,16 +95,8 @@ int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err)
                }
        }
 
-       if (walk->flags & CRYPTO_ALG_ASYNC)
-               kunmap(walk->pg);
-       else {
-               kunmap_atomic(walk->data);
-               /*
-                * The may sleep test only makes sense for sync users.
-                * Async users don't need to sleep here anyway.
-                */
-               crypto_yield(walk->flags);
-       }
+       kunmap_atomic(walk->data);
+       crypto_yield(walk->flags);
 
        if (err)
                return err;
@@ -140,33 +128,12 @@ int crypto_hash_walk_first(struct ahash_request *req,
 
        walk->alignmask = crypto_ahash_alignmask(crypto_ahash_reqtfm(req));
        walk->sg = req->src;
-       walk->flags = req->base.flags & CRYPTO_TFM_REQ_MASK;
+       walk->flags = req->base.flags;
 
        return hash_walk_new_entry(walk);
 }
 EXPORT_SYMBOL_GPL(crypto_hash_walk_first);
 
-int crypto_ahash_walk_first(struct ahash_request *req,
-                           struct crypto_hash_walk *walk)
-{
-       walk->total = req->nbytes;
-
-       if (!walk->total) {
-               walk->entrylen = 0;
-               return 0;
-       }
-
-       walk->alignmask = crypto_ahash_alignmask(crypto_ahash_reqtfm(req));
-       walk->sg = req->src;
-       walk->flags = req->base.flags & CRYPTO_TFM_REQ_MASK;
-       walk->flags |= CRYPTO_ALG_ASYNC;
-
-       BUILD_BUG_ON(CRYPTO_TFM_REQ_MASK & CRYPTO_ALG_ASYNC);
-
-       return hash_walk_new_entry(walk);
-}
-EXPORT_SYMBOL_GPL(crypto_ahash_walk_first);
-
 static int ahash_setkey_unaligned(struct crypto_ahash *tfm, const u8 *key,
                                unsigned int keylen)
 {
@@ -477,6 +444,14 @@ static int ahash_def_finup(struct ahash_request *req)
        return ahash_def_finup_finish1(req, err);
 }
 
+static void crypto_ahash_exit_tfm(struct crypto_tfm *tfm)
+{
+       struct crypto_ahash *hash = __crypto_ahash_cast(tfm);
+       struct ahash_alg *alg = crypto_ahash_alg(hash);
+
+       alg->exit_tfm(hash);
+}
+
 static int crypto_ahash_init_tfm(struct crypto_tfm *tfm)
 {
        struct crypto_ahash *hash = __crypto_ahash_cast(tfm);
@@ -500,7 +475,10 @@ static int crypto_ahash_init_tfm(struct crypto_tfm *tfm)
                ahash_set_needkey(hash);
        }
 
-       return 0;
+       if (alg->exit_tfm)
+               tfm->exit = crypto_ahash_exit_tfm;
+
+       return alg->init_tfm ? alg->init_tfm(hash) : 0;
 }
 
 static unsigned int crypto_ahash_extsize(struct crypto_alg *alg)