summaryrefslogtreecommitdiffstats
path: root/crypto/testmgr.c
diff options
context:
space:
mode:
authorGilad Ben-Yossef <gilad@benyossef.com>2018-07-01 03:02:35 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2018-07-08 12:33:35 -0400
commit76715095933b3a2e6082e171bc82ecd90baf9af0 (patch)
tree99285819cd07febce9284d17db2aeb21cb267f07 /crypto/testmgr.c
parent26497e72a1aba4d27c50c4cbf0182db94e58a590 (diff)
crypto: testmgr - add hash finup tests
The testmgr hash tests were testing init, digest, update and final methods but not the finup method. Add a test for this one too. While doing this, make sure we only run the partial tests once with the digest tests and skip them with the final and finup tests since they are the same. Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/testmgr.c')
-rw-r--r--crypto/testmgr.c55
1 files changed, 46 insertions, 9 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index 63f263fd1dae..a1d42245082a 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -259,9 +259,15 @@ out_nostate:
259 return ret; 259 return ret;
260} 260}
261 261
262enum hash_test {
263 HASH_TEST_DIGEST,
264 HASH_TEST_FINAL,
265 HASH_TEST_FINUP
266};
267
262static int __test_hash(struct crypto_ahash *tfm, 268static int __test_hash(struct crypto_ahash *tfm,
263 const struct hash_testvec *template, unsigned int tcount, 269 const struct hash_testvec *template, unsigned int tcount,
264 bool use_digest, const int align_offset) 270 enum hash_test test_type, const int align_offset)
265{ 271{
266 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm)); 272 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
267 size_t digest_size = crypto_ahash_digestsize(tfm); 273 size_t digest_size = crypto_ahash_digestsize(tfm);
@@ -332,14 +338,17 @@ static int __test_hash(struct crypto_ahash *tfm,
332 } 338 }
333 339
334 ahash_request_set_crypt(req, sg, result, template[i].psize); 340 ahash_request_set_crypt(req, sg, result, template[i].psize);
335 if (use_digest) { 341 switch (test_type) {
342 case HASH_TEST_DIGEST:
336 ret = crypto_wait_req(crypto_ahash_digest(req), &wait); 343 ret = crypto_wait_req(crypto_ahash_digest(req), &wait);
337 if (ret) { 344 if (ret) {
338 pr_err("alg: hash: digest failed on test %d " 345 pr_err("alg: hash: digest failed on test %d "
339 "for %s: ret=%d\n", j, algo, -ret); 346 "for %s: ret=%d\n", j, algo, -ret);
340 goto out; 347 goto out;
341 } 348 }
342 } else { 349 break;
350
351 case HASH_TEST_FINAL:
343 memset(result, 1, digest_size); 352 memset(result, 1, digest_size);
344 ret = crypto_wait_req(crypto_ahash_init(req), &wait); 353 ret = crypto_wait_req(crypto_ahash_init(req), &wait);
345 if (ret) { 354 if (ret) {
@@ -371,6 +380,29 @@ static int __test_hash(struct crypto_ahash *tfm,
371 "for %s: ret=%d\n", j, algo, -ret); 380 "for %s: ret=%d\n", j, algo, -ret);
372 goto out; 381 goto out;
373 } 382 }
383 break;
384
385 case HASH_TEST_FINUP:
386 memset(result, 1, digest_size);
387 ret = crypto_wait_req(crypto_ahash_init(req), &wait);
388 if (ret) {
389 pr_err("alg: hash: init failed on test %d "
390 "for %s: ret=%d\n", j, algo, -ret);
391 goto out;
392 }
393 ret = ahash_guard_result(result, 1, digest_size);
394 if (ret) {
395 pr_err("alg: hash: init failed on test %d "
396 "for %s: used req->result\n", j, algo);
397 goto out;
398 }
399 ret = crypto_wait_req(crypto_ahash_finup(req), &wait);
400 if (ret) {
401 pr_err("alg: hash: final failed on test %d "
402 "for %s: ret=%d\n", j, algo, -ret);
403 goto out;
404 }
405 break;
374 } 406 }
375 407
376 if (memcmp(result, template[i].digest, 408 if (memcmp(result, template[i].digest,
@@ -383,6 +415,9 @@ static int __test_hash(struct crypto_ahash *tfm,
383 } 415 }
384 } 416 }
385 417
418 if (test_type)
419 goto out;
420
386 j = 0; 421 j = 0;
387 for (i = 0; i < tcount; i++) { 422 for (i = 0; i < tcount; i++) {
388 /* alignment tests are only done with continuous buffers */ 423 /* alignment tests are only done with continuous buffers */
@@ -540,24 +575,24 @@ out_nobuf:
540 575
541static int test_hash(struct crypto_ahash *tfm, 576static int test_hash(struct crypto_ahash *tfm,
542 const struct hash_testvec *template, 577 const struct hash_testvec *template,
543 unsigned int tcount, bool use_digest) 578 unsigned int tcount, enum hash_test test_type)
544{ 579{
545 unsigned int alignmask; 580 unsigned int alignmask;
546 int ret; 581 int ret;
547 582
548 ret = __test_hash(tfm, template, tcount, use_digest, 0); 583 ret = __test_hash(tfm, template, tcount, test_type, 0);
549 if (ret) 584 if (ret)
550 return ret; 585 return ret;
551 586
552 /* test unaligned buffers, check with one byte offset */ 587 /* test unaligned buffers, check with one byte offset */
553 ret = __test_hash(tfm, template, tcount, use_digest, 1); 588 ret = __test_hash(tfm, template, tcount, test_type, 1);
554 if (ret) 589 if (ret)
555 return ret; 590 return ret;
556 591
557 alignmask = crypto_tfm_alg_alignmask(&tfm->base); 592 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
558 if (alignmask) { 593 if (alignmask) {
559 /* Check if alignment mask for tfm is correctly set. */ 594 /* Check if alignment mask for tfm is correctly set. */
560 ret = __test_hash(tfm, template, tcount, use_digest, 595 ret = __test_hash(tfm, template, tcount, test_type,
561 alignmask + 1); 596 alignmask + 1);
562 if (ret) 597 if (ret)
563 return ret; 598 return ret;
@@ -1803,9 +1838,11 @@ static int __alg_test_hash(const struct hash_testvec *template,
1803 return PTR_ERR(tfm); 1838 return PTR_ERR(tfm);
1804 } 1839 }
1805 1840
1806 err = test_hash(tfm, template, tcount, true); 1841 err = test_hash(tfm, template, tcount, HASH_TEST_DIGEST);
1842 if (!err)
1843 err = test_hash(tfm, template, tcount, HASH_TEST_FINAL);
1807 if (!err) 1844 if (!err)
1808 err = test_hash(tfm, template, tcount, false); 1845 err = test_hash(tfm, template, tcount, HASH_TEST_FINUP);
1809 crypto_free_ahash(tfm); 1846 crypto_free_ahash(tfm);
1810 return err; 1847 return err;
1811} 1848}