summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorJussi Kivilinna <jussi.kivilinna@iki.fi>2013-06-13 10:37:50 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2013-06-21 02:44:30 -0400
commit58dcf5484c0cbaddbba1d3ed074729f5078346bb (patch)
tree4e7e73d794519d84258e47a80ee320d9a6cdbd71 /crypto
parent3a338f20c3c5c33c45ab1c36c8eccd62289c6401 (diff)
crypto: testmgr - test AEADs with unaligned buffers
This patch adds unaligned buffer tests for AEADs. The first new test is with one byte offset and the second test checks if cra_alignmask for driver is big enough; for example, for testing a case where cra_alignmask is set to 7, but driver really needs buffers to be aligned to 16 bytes. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/testmgr.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index 8bd185f068b6..f20538616776 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -360,7 +360,7 @@ out_nobuf:
360 360
361static int __test_aead(struct crypto_aead *tfm, int enc, 361static int __test_aead(struct crypto_aead *tfm, int enc,
362 struct aead_testvec *template, unsigned int tcount, 362 struct aead_testvec *template, unsigned int tcount,
363 const bool diff_dst) 363 const bool diff_dst, const int align_offset)
364{ 364{
365 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)); 365 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
366 unsigned int i, j, k, n, temp; 366 unsigned int i, j, k, n, temp;
@@ -423,15 +423,16 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
423 if (!template[i].np) { 423 if (!template[i].np) {
424 j++; 424 j++;
425 425
426 /* some tepmplates have no input data but they will 426 /* some templates have no input data but they will
427 * touch input 427 * touch input
428 */ 428 */
429 input = xbuf[0]; 429 input = xbuf[0];
430 input += align_offset;
430 assoc = axbuf[0]; 431 assoc = axbuf[0];
431 432
432 ret = -EINVAL; 433 ret = -EINVAL;
433 if (WARN_ON(template[i].ilen > PAGE_SIZE || 434 if (WARN_ON(align_offset + template[i].ilen >
434 template[i].alen > PAGE_SIZE)) 435 PAGE_SIZE || template[i].alen > PAGE_SIZE))
435 goto out; 436 goto out;
436 437
437 memcpy(input, template[i].input, template[i].ilen); 438 memcpy(input, template[i].input, template[i].ilen);
@@ -470,6 +471,7 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
470 471
471 if (diff_dst) { 472 if (diff_dst) {
472 output = xoutbuf[0]; 473 output = xoutbuf[0];
474 output += align_offset;
473 sg_init_one(&sgout[0], output, 475 sg_init_one(&sgout[0], output,
474 template[i].ilen + 476 template[i].ilen +
475 (enc ? authsize : 0)); 477 (enc ? authsize : 0));
@@ -530,6 +532,10 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
530 } 532 }
531 533
532 for (i = 0, j = 0; i < tcount; i++) { 534 for (i = 0, j = 0; i < tcount; i++) {
535 /* alignment tests are only done with continuous buffers */
536 if (align_offset != 0)
537 break;
538
533 if (template[i].np) { 539 if (template[i].np) {
534 j++; 540 j++;
535 541
@@ -732,15 +738,34 @@ out_noxbuf:
732static int test_aead(struct crypto_aead *tfm, int enc, 738static int test_aead(struct crypto_aead *tfm, int enc,
733 struct aead_testvec *template, unsigned int tcount) 739 struct aead_testvec *template, unsigned int tcount)
734{ 740{
741 unsigned int alignmask;
735 int ret; 742 int ret;
736 743
737 /* test 'dst == src' case */ 744 /* test 'dst == src' case */
738 ret = __test_aead(tfm, enc, template, tcount, false); 745 ret = __test_aead(tfm, enc, template, tcount, false, 0);
739 if (ret) 746 if (ret)
740 return ret; 747 return ret;
741 748
742 /* test 'dst != src' case */ 749 /* test 'dst != src' case */
743 return __test_aead(tfm, enc, template, tcount, true); 750 ret = __test_aead(tfm, enc, template, tcount, true, 0);
751 if (ret)
752 return ret;
753
754 /* test unaligned buffers, check with one byte offset */
755 ret = __test_aead(tfm, enc, template, tcount, true, 1);
756 if (ret)
757 return ret;
758
759 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
760 if (alignmask) {
761 /* Check if alignment mask for tfm is correctly set. */
762 ret = __test_aead(tfm, enc, template, tcount, true,
763 alignmask + 1);
764 if (ret)
765 return ret;
766 }
767
768 return 0;
744} 769}
745 770
746static int test_cipher(struct crypto_cipher *tfm, int enc, 771static int test_cipher(struct crypto_cipher *tfm, int enc,