Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: David S. Miller <davem@davemloft.net>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

David S. Miller and committed by
Herbert Xu
a8f1a052 beb63da7

+48 -18
+48 -18
crypto/testmgr.c
··· 153 153 free_page((unsigned long)buf[i]); 154 154 } 155 155 156 + static int do_one_async_hash_op(struct ahash_request *req, 157 + struct tcrypt_result *tr, 158 + int ret) 159 + { 160 + if (ret == -EINPROGRESS || ret == -EBUSY) { 161 + ret = wait_for_completion_interruptible(&tr->completion); 162 + if (!ret) 163 + ret = tr->err; 164 + INIT_COMPLETION(tr->completion); 165 + } 166 + return ret; 167 + } 168 + 156 169 static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, 157 - unsigned int tcount) 170 + unsigned int tcount, bool use_digest) 158 171 { 159 172 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm)); 160 173 unsigned int i, j, k, temp; ··· 219 206 } 220 207 221 208 ahash_request_set_crypt(req, sg, result, template[i].psize); 222 - ret = crypto_ahash_digest(req); 223 - switch (ret) { 224 - case 0: 225 - break; 226 - case -EINPROGRESS: 227 - case -EBUSY: 228 - ret = wait_for_completion_interruptible( 229 - &tresult.completion); 230 - if (!ret && !(ret = tresult.err)) { 231 - INIT_COMPLETION(tresult.completion); 232 - break; 209 + if (use_digest) { 210 + ret = do_one_async_hash_op(req, &tresult, 211 + crypto_ahash_digest(req)); 212 + if (ret) { 213 + pr_err("alg: hash: digest failed on test %d " 214 + "for %s: ret=%d\n", j, algo, -ret); 215 + goto out; 233 216 } 234 - /* fall through */ 235 - default: 236 - printk(KERN_ERR "alg: hash: digest failed on test %d " 237 - "for %s: ret=%d\n", j, algo, -ret); 238 - goto out; 217 + } else { 218 + ret = do_one_async_hash_op(req, &tresult, 219 + crypto_ahash_init(req)); 220 + if (ret) { 221 + pr_err("alt: hash: init failed on test %d " 222 + "for %s: ret=%d\n", j, algo, -ret); 223 + goto out; 224 + } 225 + ret = do_one_async_hash_op(req, &tresult, 226 + crypto_ahash_update(req)); 227 + if (ret) { 228 + pr_err("alt: hash: update failed on test %d " 229 + "for %s: ret=%d\n", j, algo, -ret); 230 + goto out; 231 + } 232 + ret = do_one_async_hash_op(req, &tresult, 233 + crypto_ahash_final(req)); 234 + if (ret) { 235 + pr_err("alt: hash: final failed on test %d " 236 + "for %s: ret=%d\n", j, algo, -ret); 237 + goto out; 238 + } 239 239 } 240 240 241 241 if (memcmp(result, template[i].digest, ··· 1428 1402 return PTR_ERR(tfm); 1429 1403 } 1430 1404 1431 - err = test_hash(tfm, desc->suite.hash.vecs, desc->suite.hash.count); 1405 + err = test_hash(tfm, desc->suite.hash.vecs, 1406 + desc->suite.hash.count, true); 1407 + if (!err) 1408 + err = test_hash(tfm, desc->suite.hash.vecs, 1409 + desc->suite.hash.count, false); 1432 1410 1433 1411 crypto_free_ahash(tfm); 1434 1412 return err;