aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crypto/testmgr.c153
1 files changed, 105 insertions, 48 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index 00f54d54fc44..941d75cd1f7c 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -358,8 +358,9 @@ out_nobuf:
358 return ret; 358 return ret;
359} 359}
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{ 364{
364 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));
365 unsigned int i, j, k, n, temp; 366 unsigned int i, j, k, n, temp;
@@ -367,15 +368,18 @@ static int test_aead(struct crypto_aead *tfm, int enc,
367 char *q; 368 char *q;
368 char *key; 369 char *key;
369 struct aead_request *req; 370 struct aead_request *req;
370 struct scatterlist sg[8]; 371 struct scatterlist *sg;
371 struct scatterlist asg[8]; 372 struct scatterlist *asg;
372 const char *e; 373 struct scatterlist *sgout;
374 const char *e, *d;
373 struct tcrypt_result result; 375 struct tcrypt_result result;
374 unsigned int authsize; 376 unsigned int authsize;
375 void *input; 377 void *input;
378 void *output;
376 void *assoc; 379 void *assoc;
377 char iv[MAX_IVLEN]; 380 char iv[MAX_IVLEN];
378 char *xbuf[XBUFSIZE]; 381 char *xbuf[XBUFSIZE];
382 char *xoutbuf[XBUFSIZE];
379 char *axbuf[XBUFSIZE]; 383 char *axbuf[XBUFSIZE];
380 384
381 if (testmgr_alloc_buf(xbuf)) 385 if (testmgr_alloc_buf(xbuf))
@@ -383,6 +387,21 @@ static int test_aead(struct crypto_aead *tfm, int enc,
383 if (testmgr_alloc_buf(axbuf)) 387 if (testmgr_alloc_buf(axbuf))
384 goto out_noaxbuf; 388 goto out_noaxbuf;
385 389
390 if (diff_dst && testmgr_alloc_buf(xoutbuf))
391 goto out_nooutbuf;
392
393 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
394 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 3 : 2), GFP_KERNEL);
395 if (!sg)
396 goto out_nosg;
397 asg = &sg[8];
398 sgout = &asg[8];
399
400 if (diff_dst)
401 d = "-ddst";
402 else
403 d = "";
404
386 if (enc == ENCRYPT) 405 if (enc == ENCRYPT)
387 e = "encryption"; 406 e = "encryption";
388 else 407 else
@@ -392,8 +411,8 @@ static int test_aead(struct crypto_aead *tfm, int enc,
392 411
393 req = aead_request_alloc(tfm, GFP_KERNEL); 412 req = aead_request_alloc(tfm, GFP_KERNEL);
394 if (!req) { 413 if (!req) {
395 printk(KERN_ERR "alg: aead: Failed to allocate request for " 414 pr_err("alg: aead%s: Failed to allocate request for %s\n",
396 "%s\n", algo); 415 d, algo);
397 goto out; 416 goto out;
398 } 417 }
399 418
@@ -432,9 +451,8 @@ static int test_aead(struct crypto_aead *tfm, int enc,
432 ret = crypto_aead_setkey(tfm, key, 451 ret = crypto_aead_setkey(tfm, key,
433 template[i].klen); 452 template[i].klen);
434 if (!ret == template[i].fail) { 453 if (!ret == template[i].fail) {
435 printk(KERN_ERR "alg: aead: setkey failed on " 454 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
436 "test %d for %s: flags=%x\n", j, algo, 455 d, j, algo, crypto_aead_get_flags(tfm));
437 crypto_aead_get_flags(tfm));
438 goto out; 456 goto out;
439 } else if (ret) 457 } else if (ret)
440 continue; 458 continue;
@@ -442,18 +460,26 @@ static int test_aead(struct crypto_aead *tfm, int enc,
442 authsize = abs(template[i].rlen - template[i].ilen); 460 authsize = abs(template[i].rlen - template[i].ilen);
443 ret = crypto_aead_setauthsize(tfm, authsize); 461 ret = crypto_aead_setauthsize(tfm, authsize);
444 if (ret) { 462 if (ret) {
445 printk(KERN_ERR "alg: aead: Failed to set " 463 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
446 "authsize to %u on test %d for %s\n", 464 d, authsize, j, algo);
447 authsize, j, algo);
448 goto out; 465 goto out;
449 } 466 }
450 467
451 sg_init_one(&sg[0], input, 468 sg_init_one(&sg[0], input,
452 template[i].ilen + (enc ? authsize : 0)); 469 template[i].ilen + (enc ? authsize : 0));
453 470
471 if (diff_dst) {
472 output = xoutbuf[0];
473 sg_init_one(&sgout[0], output,
474 template[i].ilen +
475 (enc ? authsize : 0));
476 } else {
477 output = input;
478 }
479
454 sg_init_one(&asg[0], assoc, template[i].alen); 480 sg_init_one(&asg[0], assoc, template[i].alen);
455 481
456 aead_request_set_crypt(req, sg, sg, 482 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
457 template[i].ilen, iv); 483 template[i].ilen, iv);
458 484
459 aead_request_set_assoc(req, asg, template[i].alen); 485 aead_request_set_assoc(req, asg, template[i].alen);
@@ -466,10 +492,8 @@ static int test_aead(struct crypto_aead *tfm, int enc,
466 case 0: 492 case 0:
467 if (template[i].novrfy) { 493 if (template[i].novrfy) {
468 /* verification was supposed to fail */ 494 /* verification was supposed to fail */
469 printk(KERN_ERR "alg: aead: %s failed " 495 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
470 "on test %d for %s: ret was 0, " 496 d, e, j, algo);
471 "expected -EBADMSG\n",
472 e, j, algo);
473 /* so really, we got a bad message */ 497 /* so really, we got a bad message */
474 ret = -EBADMSG; 498 ret = -EBADMSG;
475 goto out; 499 goto out;
@@ -489,15 +513,15 @@ static int test_aead(struct crypto_aead *tfm, int enc,
489 continue; 513 continue;
490 /* fall through */ 514 /* fall through */
491 default: 515 default:
492 printk(KERN_ERR "alg: aead: %s failed on test " 516 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
493 "%d for %s: ret=%d\n", e, j, algo, -ret); 517 d, e, j, algo, -ret);
494 goto out; 518 goto out;
495 } 519 }
496 520
497 q = input; 521 q = output;
498 if (memcmp(q, template[i].result, template[i].rlen)) { 522 if (memcmp(q, template[i].result, template[i].rlen)) {
499 printk(KERN_ERR "alg: aead: Test %d failed on " 523 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
500 "%s for %s\n", j, e, algo); 524 d, j, e, algo);
501 hexdump(q, template[i].rlen); 525 hexdump(q, template[i].rlen);
502 ret = -EINVAL; 526 ret = -EINVAL;
503 goto out; 527 goto out;
@@ -522,9 +546,8 @@ static int test_aead(struct crypto_aead *tfm, int enc,
522 546
523 ret = crypto_aead_setkey(tfm, key, template[i].klen); 547 ret = crypto_aead_setkey(tfm, key, template[i].klen);
524 if (!ret == template[i].fail) { 548 if (!ret == template[i].fail) {
525 printk(KERN_ERR "alg: aead: setkey failed on " 549 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
526 "chunk test %d for %s: flags=%x\n", j, 550 d, j, algo, crypto_aead_get_flags(tfm));
527 algo, crypto_aead_get_flags(tfm));
528 goto out; 551 goto out;
529 } else if (ret) 552 } else if (ret)
530 continue; 553 continue;
@@ -533,6 +556,8 @@ static int test_aead(struct crypto_aead *tfm, int enc,
533 556
534 ret = -EINVAL; 557 ret = -EINVAL;
535 sg_init_table(sg, template[i].np); 558 sg_init_table(sg, template[i].np);
559 if (diff_dst)
560 sg_init_table(sgout, template[i].np);
536 for (k = 0, temp = 0; k < template[i].np; k++) { 561 for (k = 0, temp = 0; k < template[i].np; k++) {
537 if (WARN_ON(offset_in_page(IDX[k]) + 562 if (WARN_ON(offset_in_page(IDX[k]) +
538 template[i].tap[k] > PAGE_SIZE)) 563 template[i].tap[k] > PAGE_SIZE))
@@ -551,14 +576,26 @@ static int test_aead(struct crypto_aead *tfm, int enc,
551 q[n] = 0; 576 q[n] = 0;
552 577
553