Jesse Keating 3494df0
From e45009229be6a7fae49bdfa3459905668c0b0fb1 Mon Sep 17 00:00:00 2001
Jesse Keating 3494df0
From: David S. Miller <davem@davemloft.net>
Jesse Keating 3494df0
Date: Wed, 19 May 2010 14:12:03 +1000
Jesse Keating 3494df0
Subject: crypto: testmgr - Add testing for async hashing and update/final
Jesse Keating 3494df0
Jesse Keating 3494df0
Extend testmgr such that it tests async hash algorithms,
Jesse Keating 3494df0
and that for both sync and async hashes it tests both
Jesse Keating 3494df0
->digest() and ->update()/->final() sequences.
Jesse Keating 3494df0
Jesse Keating 3494df0
Signed-off-by: David S. Miller <davem@davemloft.net>
Jesse Keating 3494df0
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Jesse Keating 3494df0
---
Jesse Keating 3494df0
 crypto/testmgr.c |   66 +++++++++++++++++++++++++++++++++++++++--------------
Jesse Keating 3494df0
 1 files changed, 48 insertions(+), 18 deletions(-)
Jesse Keating 3494df0
Jesse Keating 3494df0
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
Jesse Keating 3494df0
index c494d76..5c8aaa0 100644
Jesse Keating 3494df0
--- a/crypto/testmgr.c
Jesse Keating 3494df0
+++ b/crypto/testmgr.c
Jesse Keating 3494df0
@@ -153,8 +153,21 @@ static void testmgr_free_buf(char *buf[XBUFSIZE])
Jesse Keating 3494df0
 		free_page((unsigned long)buf[i]);
Jesse Keating 3494df0
 }
Jesse Keating 3494df0
 
Jesse Keating 3494df0
+static int do_one_async_hash_op(struct ahash_request *req,
Jesse Keating 3494df0
+				struct tcrypt_result *tr,
Jesse Keating 3494df0
+				int ret)
Jesse Keating 3494df0
+{
Jesse Keating 3494df0
+	if (ret == -EINPROGRESS || ret == -EBUSY) {
Jesse Keating 3494df0
+		ret = wait_for_completion_interruptible(&tr->completion);
Jesse Keating 3494df0
+		if (!ret)
Jesse Keating 3494df0
+			ret = tr->err;
Jesse Keating 3494df0
+		INIT_COMPLETION(tr->completion);
Jesse Keating 3494df0
+	}
Jesse Keating 3494df0
+	return ret;
Jesse Keating 3494df0
+}
Jesse Keating 3494df0
+
Jesse Keating 3494df0
 static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
Jesse Keating 3494df0
-		     unsigned int tcount)
Jesse Keating 3494df0
+		     unsigned int tcount, bool use_digest)
Jesse Keating 3494df0
 {
Jesse Keating 3494df0
 	const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
Jesse Keating 3494df0
 	unsigned int i, j, k, temp;
Jesse Keating 3494df0
@@ -206,23 +219,36 @@ static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
Jesse Keating 3494df0
 		}
Jesse Keating 3494df0
 
Jesse Keating 3494df0
 		ahash_request_set_crypt(req, sg, result, template[i].psize);
Jesse Keating 3494df0
-		ret = crypto_ahash_digest(req);
Jesse Keating 3494df0
-		switch (ret) {
Jesse Keating 3494df0
-		case 0:
Jesse Keating 3494df0
-			break;
Jesse Keating 3494df0
-		case -EINPROGRESS:
Jesse Keating 3494df0
-		case -EBUSY:
Jesse Keating 3494df0
-			ret = wait_for_completion_interruptible(
Jesse Keating 3494df0
-				&tresult.completion);
Jesse Keating 3494df0
-			if (!ret && !(ret = tresult.err)) {
Jesse Keating 3494df0
-				INIT_COMPLETION(tresult.completion);
Jesse Keating 3494df0
-				break;
Jesse Keating 3494df0
+		if (use_digest) {
Jesse Keating 3494df0
+			ret = do_one_async_hash_op(req, &tresult,
Jesse Keating 3494df0
+						   crypto_ahash_digest(req));
Jesse Keating 3494df0
+			if (ret) {
Jesse Keating 3494df0
+				pr_err("alg: hash: digest failed on test %d "
Jesse Keating 3494df0
+				       "for %s: ret=%d\n", j, algo, -ret);
Jesse Keating 3494df0
+				goto out;
Jesse Keating 3494df0
+			}
Jesse Keating 3494df0
+		} else {
Jesse Keating 3494df0
+			ret = do_one_async_hash_op(req, &tresult,
Jesse Keating 3494df0
+						   crypto_ahash_init(req));
Jesse Keating 3494df0
+			if (ret) {
Jesse Keating 3494df0
+				pr_err("alt: hash: init failed on test %d "
Jesse Keating 3494df0
+				       "for %s: ret=%d\n", j, algo, -ret);
Jesse Keating 3494df0
+				goto out;
Jesse Keating 3494df0
+			}
Jesse Keating 3494df0
+			ret = do_one_async_hash_op(req, &tresult,
Jesse Keating 3494df0
+						   crypto_ahash_update(req));
Jesse Keating 3494df0
+			if (ret) {
Jesse Keating 3494df0
+				pr_err("alt: hash: update failed on test %d "
Jesse Keating 3494df0
+				       "for %s: ret=%d\n", j, algo, -ret);
Jesse Keating 3494df0
+				goto out;
Jesse Keating 3494df0
+			}
Jesse Keating 3494df0
+			ret = do_one_async_hash_op(req, &tresult,
Jesse Keating 3494df0
+						   crypto_ahash_final(req));
Jesse Keating 3494df0
+			if (ret) {
Jesse Keating 3494df0
+				pr_err("alt: hash: final failed on test %d "
Jesse Keating 3494df0
+				       "for %s: ret=%d\n", j, algo, -ret);
Jesse Keating 3494df0
+				goto out;
Jesse Keating 3494df0
 			}
Jesse Keating 3494df0
-			/* fall through */
Jesse Keating 3494df0
-		default:
Jesse Keating 3494df0
-			printk(KERN_ERR "alg: hash: digest failed on test %d "
Jesse Keating 3494df0
-			       "for %s: ret=%d\n", j, algo, -ret);
Jesse Keating 3494df0
-			goto out;
Jesse Keating 3494df0
 		}
Jesse Keating 3494df0
 
Jesse Keating 3494df0
 		if (memcmp(result, template[i].digest,
Jesse Keating 3494df0
@@ -1402,7 +1428,11 @@ static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
Jesse Keating 3494df0
 		return PTR_ERR(tfm);
Jesse Keating 3494df0
 	}
Jesse Keating 3494df0
 
Jesse Keating 3494df0
-	err = test_hash(tfm, desc->suite.hash.vecs, desc->suite.hash.count);
Jesse Keating 3494df0
+	err = test_hash(tfm, desc->suite.hash.vecs,
Jesse Keating 3494df0
+			desc->suite.hash.count, true);
Jesse Keating 3494df0
+	if (!err)
Jesse Keating 3494df0
+		err = test_hash(tfm, desc->suite.hash.vecs,
Jesse Keating 3494df0
+				desc->suite.hash.count, false);
Jesse Keating 3494df0
 
Jesse Keating 3494df0
 	crypto_free_ahash(tfm);
Jesse Keating 3494df0
 	return err;
Jesse Keating 3494df0
-- 
Jesse Keating 3494df0
1.7.0.1
Jesse Keating 3494df0