crypto: shash - Fix async finup handling of null digest
[safe/jmp/linux-2.6] / crypto / shash.c
index 834d9d2..7713b52 100644 (file)
@@ -240,12 +240,17 @@ int shash_ahash_finup(struct ahash_request *req, struct shash_desc *desc)
        struct crypto_hash_walk walk;
        int nbytes;
 
-       for (nbytes = crypto_hash_walk_first(req, &walk); nbytes > 0;
-            nbytes = crypto_hash_walk_done(&walk, nbytes))
+       nbytes = crypto_hash_walk_first(req, &walk);
+       if (!nbytes)
+               return crypto_shash_final(desc, req->result);
+
+       do {
                nbytes = crypto_hash_walk_last(&walk) ?
                         crypto_shash_finup(desc, walk.data, nbytes,
                                            req->result) :
                         crypto_shash_update(desc, walk.data, nbytes);
+               nbytes = crypto_hash_walk_done(&walk, nbytes);
+       } while (nbytes > 0);
 
        return nbytes;
 }