Commit a8f1a052 authored by David S. Miller's avatar David S. Miller Committed by Herbert Xu

crypto: testmgr - Add testing for async hashing and update/final

Extend testmgr such that it tests async hash algorithms,
and that for both sync and async hashes it tests both
->digest() and ->update()/->final() sequences.
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent beb63da7
...@@ -153,8 +153,21 @@ static void testmgr_free_buf(char *buf[XBUFSIZE]) ...@@ -153,8 +153,21 @@ static void testmgr_free_buf(char *buf[XBUFSIZE])
free_page((unsigned long)buf[i]); free_page((unsigned long)buf[i]);
} }
static int do_one_async_hash_op(struct ahash_request *req,
struct tcrypt_result *tr,
int ret)
{
if (ret == -EINPROGRESS || ret == -EBUSY) {
ret = wait_for_completion_interruptible(&tr->completion);
if (!ret)
ret = tr->err;
INIT_COMPLETION(tr->completion);
}
return ret;
}
static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
unsigned int tcount) unsigned int tcount, bool use_digest)
{ {
const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm)); const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
unsigned int i, j, k, temp; unsigned int i, j, k, temp;
...@@ -206,24 +219,37 @@ static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, ...@@ -206,24 +219,37 @@ static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
} }
ahash_request_set_crypt(req, sg, result, template[i].psize); ahash_request_set_crypt(req, sg, result, template[i].psize);
ret = crypto_ahash_digest(req); if (use_digest) {
switch (ret) { ret = do_one_async_hash_op(req, &tresult,
case 0: crypto_ahash_digest(req));
break; if (ret) {
case -EINPROGRESS: pr_err("alg: hash: digest failed on test %d "
case -EBUSY: "for %s: ret=%d\n", j, algo, -ret);
ret = wait_for_completion_interruptible( goto out;
&tresult.completion);
if (!ret && !(ret = tresult.err)) {
INIT_COMPLETION(tresult.completion);
break;
} }
/* fall through */ } else {
default: ret = do_one_async_hash_op(req, &tresult,
printk(KERN_ERR "alg: hash: digest failed on test %d " crypto_ahash_init(req));
if (ret) {
pr_err("alt: hash: init failed on test %d "
"for %s: ret=%d\n", j, algo, -ret);
goto out;
}
ret = do_one_async_hash_op(req, &tresult,
crypto_ahash_update(req));
if (ret) {
pr_err("alt: hash: update failed on test %d "
"for %s: ret=%d\n", j, algo, -ret);
goto out;
}
ret = do_one_async_hash_op(req, &tresult,
crypto_ahash_final(req));
if (ret) {
pr_err("alt: hash: final failed on test %d "
"for %s: ret=%d\n", j, algo, -ret); "for %s: ret=%d\n", j, algo, -ret);
goto out; goto out;
} }
}
if (memcmp(result, template[i].digest, if (memcmp(result, template[i].digest,
crypto_ahash_digestsize(tfm))) { crypto_ahash_digestsize(tfm))) {
...@@ -1402,7 +1428,11 @@ static int alg_test_hash(const struct alg_test_desc *desc, const char *driver, ...@@ -1402,7 +1428,11 @@ static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
return PTR_ERR(tfm); return PTR_ERR(tfm);
} }
err = test_hash(tfm, desc->suite.hash.vecs, desc->suite.hash.count); err = test_hash(tfm, desc->suite.hash.vecs,
desc->suite.hash.count, true);
if (!err)
err = test_hash(tfm, desc->suite.hash.vecs,
desc->suite.hash.count, false);
crypto_free_ahash(tfm); crypto_free_ahash(tfm);
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment