1 /* 2 * Algorithm testing framework and tests. 3 * 4 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> 5 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org> 6 * Copyright (c) 2007 Nokia Siemens Networks 7 * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au> 8 * 9 * Updated RFC4106 AES-GCM testing. 10 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com) 11 * Adrian Hoban <adrian.hoban@intel.com> 12 * Gabriele Paoloni <gabriele.paoloni@intel.com> 13 * Tadeusz Struk (tadeusz.struk@intel.com) 14 * Copyright (c) 2010, Intel Corporation. 15 * 16 * This program is free software; you can redistribute it and/or modify it 17 * under the terms of the GNU General Public License as published by the Free 18 * Software Foundation; either version 2 of the License, or (at your option) 19 * any later version. 20 * 21 */ 22 23 #include <crypto/hash.h> 24 #include <linux/err.h> 25 #include <linux/module.h> 26 #include <linux/scatterlist.h> 27 #include <linux/slab.h> 28 #include <linux/string.h> 29 #include <crypto/rng.h> 30 #include <crypto/drbg.h> 31 32 #include "internal.h" 33 34 #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS 35 36 /* a perfect nop */ 37 int alg_test(const char *driver, const char *alg, u32 type, u32 mask) 38 { 39 return 0; 40 } 41 42 #else 43 44 #include "testmgr.h" 45 46 /* 47 * Need slab memory for testing (size in number of pages). 48 */ 49 #define XBUFSIZE 8 50 51 /* 52 * Indexes into the xbuf to simulate cross-page access. 53 */ 54 #define IDX1 32 55 #define IDX2 32400 56 #define IDX3 1 57 #define IDX4 8193 58 #define IDX5 22222 59 #define IDX6 17101 60 #define IDX7 27333 61 #define IDX8 3000 62 63 /* 64 * Used by test_cipher() 65 */ 66 #define ENCRYPT 1 67 #define DECRYPT 0 68 69 struct tcrypt_result { 70 struct completion completion; 71 int err; 72 }; 73 74 struct aead_test_suite { 75 struct { 76 struct aead_testvec *vecs; 77 unsigned int count; 78 } enc, dec; 79 }; 80 81 struct cipher_test_suite { 82 struct { 83 struct cipher_testvec *vecs; 84 unsigned int count; 85 } enc, dec; 86 }; 87 88 struct comp_test_suite { 89 struct { 90 struct comp_testvec *vecs; 91 unsigned int count; 92 } comp, decomp; 93 }; 94 95 struct pcomp_test_suite { 96 struct { 97 struct pcomp_testvec *vecs; 98 unsigned int count; 99 } comp, decomp; 100 }; 101 102 struct hash_test_suite { 103 struct hash_testvec *vecs; 104 unsigned int count; 105 }; 106 107 struct cprng_test_suite { 108 struct cprng_testvec *vecs; 109 unsigned int count; 110 }; 111 112 struct drbg_test_suite { 113 struct drbg_testvec *vecs; 114 unsigned int count; 115 }; 116 117 struct alg_test_desc { 118 const char *alg; 119 int (*test)(const struct alg_test_desc *desc, const char *driver, 120 u32 type, u32 mask); 121 int fips_allowed; /* set if alg is allowed in fips mode */ 122 123 union { 124 struct aead_test_suite aead; 125 struct cipher_test_suite cipher; 126 struct comp_test_suite comp; 127 struct pcomp_test_suite pcomp; 128 struct hash_test_suite hash; 129 struct cprng_test_suite cprng; 130 struct drbg_test_suite drbg; 131 } suite; 132 }; 133 134 static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 }; 135 136 static void hexdump(unsigned char *buf, unsigned int len) 137 { 138 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET, 139 16, 1, 140 buf, len, false); 141 } 142 143 static void tcrypt_complete(struct crypto_async_request *req, int err) 144 { 145 struct tcrypt_result *res = req->data; 146 147 if (err == -EINPROGRESS) 148 return; 149 150 res->err = err; 151 complete(&res->completion); 152 } 153 154 static int testmgr_alloc_buf(char *buf[XBUFSIZE]) 155 { 156 int i; 157 158 for (i = 0; i < XBUFSIZE; i++) { 159 buf[i] = (void *)__get_free_page(GFP_KERNEL); 160 if (!buf[i]) 161 goto err_free_buf; 162 } 163 164 return 0; 165 166 err_free_buf: 167 while (i-- > 0) 168 free_page((unsigned long)buf[i]); 169 170 return -ENOMEM; 171 } 172 173 static void testmgr_free_buf(char *buf[XBUFSIZE]) 174 { 175 int i; 176 177 for (i = 0; i < XBUFSIZE; i++) 178 free_page((unsigned long)buf[i]); 179 } 180 181 static int wait_async_op(struct tcrypt_result *tr, int ret) 182 { 183 if (ret == -EINPROGRESS || ret == -EBUSY) { 184 wait_for_completion(&tr->completion); 185 reinit_completion(&tr->completion); 186 ret = tr->err; 187 } 188 return ret; 189 } 190 191 static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, 192 unsigned int tcount, bool use_digest, 193 const int align_offset) 194 { 195 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm)); 196 unsigned int i, j, k, temp; 197 struct scatterlist sg[8]; 198 char *result; 199 char *key; 200 struct ahash_request *req; 201 struct tcrypt_result tresult; 202 void *hash_buff; 203 char *xbuf[XBUFSIZE]; 204 int ret = -ENOMEM; 205 206 result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL); 207 if (!result) 208 return ret; 209 key = kmalloc(MAX_KEYLEN, GFP_KERNEL); 210 if (!key) 211 goto out_nobuf; 212 if (testmgr_alloc_buf(xbuf)) 213 goto out_nobuf; 214 215 init_completion(&tresult.completion); 216 217 req = ahash_request_alloc(tfm, GFP_KERNEL); 218 if (!req) { 219 printk(KERN_ERR "alg: hash: Failed to allocate request for " 220 "%s\n", algo); 221 goto out_noreq; 222 } 223 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 224 tcrypt_complete, &tresult); 225 226 j = 0; 227 for (i = 0; i < tcount; i++) { 228 if (template[i].np) 229 continue; 230 231 ret = -EINVAL; 232 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE)) 233 goto out; 234 235 j++; 236 memset(result, 0, MAX_DIGEST_SIZE); 237 238 hash_buff = xbuf[0]; 239 hash_buff += align_offset; 240 241 memcpy(hash_buff, template[i].plaintext, template[i].psize); 242 sg_init_one(&sg[0], hash_buff, template[i].psize); 243 244 if (template[i].ksize) { 245 crypto_ahash_clear_flags(tfm, ~0); 246 if (template[i].ksize > MAX_KEYLEN) { 247 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n", 248 j, algo, template[i].ksize, MAX_KEYLEN); 249 ret = -EINVAL; 250 goto out; 251 } 252 memcpy(key, template[i].key, template[i].ksize); 253 ret = crypto_ahash_setkey(tfm, key, template[i].ksize); 254 if (ret) { 255 printk(KERN_ERR "alg: hash: setkey failed on " 256 "test %d for %s: ret=%d\n", j, algo, 257 -ret); 258 goto out; 259 } 260 } 261 262 ahash_request_set_crypt(req, sg, result, template[i].psize); 263 if (use_digest) { 264 ret = wait_async_op(&tresult, crypto_ahash_digest(req)); 265 if (ret) { 266 pr_err("alg: hash: digest failed on test %d " 267 "for %s: ret=%d\n", j, algo, -ret); 268 goto out; 269 } 270 } else { 271 ret = wait_async_op(&tresult, crypto_ahash_init(req)); 272 if (ret) { 273 pr_err("alt: hash: init failed on test %d " 274 "for %s: ret=%d\n", j, algo, -ret); 275 goto out; 276 } 277 ret = wait_async_op(&tresult, crypto_ahash_update(req)); 278 if (ret) { 279 pr_err("alt: hash: update failed on test %d " 280 "for %s: ret=%d\n", j, algo, -ret); 281 goto out; 282 } 283 ret = wait_async_op(&tresult, crypto_ahash_final(req)); 284 if (ret) { 285 pr_err("alt: hash: final failed on test %d " 286 "for %s: ret=%d\n", j, algo, -ret); 287 goto out; 288 } 289 } 290 291 if (memcmp(result, template[i].digest, 292 crypto_ahash_digestsize(tfm))) { 293 printk(KERN_ERR "alg: hash: Test %d failed for %s\n", 294 j, algo); 295 hexdump(result, crypto_ahash_digestsize(tfm)); 296 ret = -EINVAL; 297 goto out; 298 } 299 } 300 301 j = 0; 302 for (i = 0; i < tcount; i++) { 303 /* alignment tests are only done with continuous buffers */ 304 if (align_offset != 0) 305 break; 306 307 if (!template[i].np) 308 continue; 309 310 j++; 311 memset(result, 0, MAX_DIGEST_SIZE); 312 313 temp = 0; 314 sg_init_table(sg, template[i].np); 315 ret = -EINVAL; 316 for (k = 0; k < template[i].np; k++) { 317 if (WARN_ON(offset_in_page(IDX[k]) + 318 template[i].tap[k] > PAGE_SIZE)) 319 goto out; 320 sg_set_buf(&sg[k], 321 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] + 322 offset_in_page(IDX[k]), 323 template[i].plaintext + temp, 324 template[i].tap[k]), 325 template[i].tap[k]); 326 temp += template[i].tap[k]; 327 } 328 329 if (template[i].ksize) { 330 if (template[i].ksize > MAX_KEYLEN) { 331 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n", 332 j, algo, template[i].ksize, MAX_KEYLEN); 333 ret = -EINVAL; 334 goto out; 335 } 336 crypto_ahash_clear_flags(tfm, ~0); 337 memcpy(key, template[i].key, template[i].ksize); 338 ret = crypto_ahash_setkey(tfm, key, template[i].ksize); 339 340 if (ret) { 341 printk(KERN_ERR "alg: hash: setkey " 342 "failed on chunking test %d " 343 "for %s: ret=%d\n", j, algo, -ret); 344 goto out; 345 } 346 } 347 348 ahash_request_set_crypt(req, sg, result, template[i].psize); 349 ret = crypto_ahash_digest(req); 350 switch (ret) { 351 case 0: 352 break; 353 case -EINPROGRESS: 354 case -EBUSY: 355 wait_for_completion(&tresult.completion); 356 reinit_completion(&tresult.completion); 357 ret = tresult.err; 358 if (!ret) 359 break; 360 /* fall through */ 361 default: 362 printk(KERN_ERR "alg: hash: digest failed " 363 "on chunking test %d for %s: " 364 "ret=%d\n", j, algo, -ret); 365 goto out; 366 } 367 368 if (memcmp(result, template[i].digest, 369 crypto_ahash_digestsize(tfm))) { 370 printk(KERN_ERR "alg: hash: Chunking test %d " 371 "failed for %s\n", j, algo); 372 hexdump(result, crypto_ahash_digestsize(tfm)); 373 ret = -EINVAL; 374 goto out; 375 } 376 } 377 378 ret = 0; 379 380 out: 381 ahash_request_free(req); 382 out_noreq: 383 testmgr_free_buf(xbuf); 384 out_nobuf: 385 kfree(key); 386 kfree(result); 387 return ret; 388 } 389 390 static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, 391 unsigned int tcount, bool use_digest) 392 { 393 unsigned int alignmask; 394 int ret; 395 396 ret = __test_hash(tfm, template, tcount, use_digest, 0); 397 if (ret) 398 return ret; 399 400 /* test unaligned buffers, check with one byte offset */ 401 ret = __test_hash(tfm, template, tcount, use_digest, 1); 402 if (ret) 403 return ret; 404 405 alignmask = crypto_tfm_alg_alignmask(&tfm->base); 406 if (alignmask) { 407 /* Check if alignment mask for tfm is correctly set. */ 408 ret = __test_hash(tfm, template, tcount, use_digest, 409 alignmask + 1); 410 if (ret) 411 return ret; 412 } 413 414 return 0; 415 } 416 417 static int __test_aead(struct crypto_aead *tfm, int enc, 418 struct aead_testvec *template, unsigned int tcount, 419 const bool diff_dst, const int align_offset) 420 { 421 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)); 422 unsigned int i, j, k, n, temp; 423 int ret = -ENOMEM; 424 char *q; 425 char *key; 426 struct aead_request *req; 427 struct scatterlist *sg; 428 struct scatterlist *asg; 429 struct scatterlist *sgout; 430 const char *e, *d; 431 struct tcrypt_result result; 432 unsigned int authsize, iv_len; 433 void *input; 434 void *output; 435 void *assoc; 436 char *iv; 437 char *xbuf[XBUFSIZE]; 438 char *xoutbuf[XBUFSIZE]; 439 char *axbuf[XBUFSIZE]; 440 441 iv = kzalloc(MAX_IVLEN, GFP_KERNEL); 442 if (!iv) 443 return ret; 444 key = kmalloc(MAX_KEYLEN, GFP_KERNEL); 445 if (!key) 446 goto out_noxbuf; 447 if (testmgr_alloc_buf(xbuf)) 448 goto out_noxbuf; 449 if (testmgr_alloc_buf(axbuf)) 450 goto out_noaxbuf; 451 if (diff_dst && testmgr_alloc_buf(xoutbuf)) 452 goto out_nooutbuf; 453 454 /* avoid "the frame size is larger than 1024 bytes" compiler warning */ 455 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 3 : 2), GFP_KERNEL); 456 if (!sg) 457 goto out_nosg; 458 asg = &sg[8]; 459 sgout = &asg[8]; 460 461 if (diff_dst) 462 d = "-ddst"; 463 else 464 d = ""; 465 466 if (enc == ENCRYPT) 467 e = "encryption"; 468 else 469 e = "decryption"; 470 471 init_completion(&result.completion); 472 473 req = aead_request_alloc(tfm, GFP_KERNEL); 474 if (!req) { 475 pr_err("alg: aead%s: Failed to allocate request for %s\n", 476 d, algo); 477 goto out; 478 } 479 480 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 481 tcrypt_complete, &result); 482 483 for (i = 0, j = 0; i < tcount; i++) { 484 if (template[i].np) 485 continue; 486 487 j++; 488 489 /* some templates have no input data but they will 490 * touch input 491 */ 492 input = xbuf[0]; 493 input += align_offset; 494 assoc = axbuf[0]; 495 496 ret = -EINVAL; 497 if (WARN_ON(align_offset + template[i].ilen > 498 PAGE_SIZE || template[i].alen > PAGE_SIZE)) 499 goto out; 500 501 memcpy(input, template[i].input, template[i].ilen); 502 memcpy(assoc, template[i].assoc, template[i].alen); 503 iv_len = crypto_aead_ivsize(tfm); 504 if (template[i].iv) 505 memcpy(iv, template[i].iv, iv_len); 506 else 507 memset(iv, 0, iv_len); 508 509 crypto_aead_clear_flags(tfm, ~0); 510 if (template[i].wk) 511 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY); 512 513 if (template[i].klen > MAX_KEYLEN) { 514 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n", 515 d, j, algo, template[i].klen, 516 MAX_KEYLEN); 517 ret = -EINVAL; 518 goto out; 519 } 520 memcpy(key, template[i].key, template[i].klen); 521 522 ret = crypto_aead_setkey(tfm, key, template[i].klen); 523 if (!ret == template[i].fail) { 524 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n", 525 d, j, algo, crypto_aead_get_flags(tfm)); 526 goto out; 527 } else if (ret) 528 continue; 529 530 authsize = abs(template[i].rlen - template[i].ilen); 531 ret = crypto_aead_setauthsize(tfm, authsize); 532 if (ret) { 533 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n", 534 d, authsize, j, algo); 535 goto out; 536 } 537 538 if (diff_dst) { 539 output = xoutbuf[0]; 540 output += align_offset; 541 sg_init_one(&sg[0], input, template[i].ilen); 542 sg_init_one(&sgout[0], output, template[i].rlen); 543 } else { 544 sg_init_one(&sg[0], input, 545 template[i].ilen + (enc ? authsize : 0)); 546 output = input; 547 } 548 549 sg_init_one(&asg[0], assoc, template[i].alen); 550 551 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, 552 template[i].ilen, iv); 553 554 aead_request_set_assoc(req, asg, template[i].alen); 555 556 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req); 557 558 switch (ret) { 559 case 0: 560 if (template[i].novrfy) { 561 /* verification was supposed to fail */ 562 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n", 563 d, e, j, algo); 564 /* so really, we got a bad message */ 565 ret = -EBADMSG; 566 goto out; 567 } 568 break; 569 case -EINPROGRESS: 570 case -EBUSY: 571 wait_for_completion(&result.completion); 572 reinit_completion(&result.completion); 573 ret = result.err; 574 if (!ret) 575 break; 576 case -EBADMSG: 577 if (template[i].novrfy) 578 /* verification failure was expected */ 579 continue; 580 /* fall through */ 581 default: 582 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n", 583 d, e, j, algo, -ret); 584 goto out; 585 } 586 587 q = output; 588 if (memcmp(q, template[i].result, template[i].rlen)) { 589 pr_err("alg: aead%s: Test %d failed on %s for %s\n", 590 d, j, e, algo); 591 hexdump(q, template[i].rlen); 592 ret = -EINVAL; 593 goto out; 594 } 595 } 596 597 for (i = 0, j = 0; i < tcount; i++) { 598 /* alignment tests are only done with continuous buffers */ 599 if (align_offset != 0) 600 break; 601 602 if (!template[i].np) 603 continue; 604 605 j++; 606 607 if (template[i].iv) 608 memcpy(iv, template[i].iv, MAX_IVLEN); 609 else 610 memset(iv, 0, MAX_IVLEN); 611 612 crypto_aead_clear_flags(tfm, ~0); 613 if (template[i].wk) 614 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY); 615 if (template[i].klen > MAX_KEYLEN) { 616 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n", 617 d, j, algo, template[i].klen, MAX_KEYLEN); 618 ret = -EINVAL; 619 goto out; 620 } 621 memcpy(key, template[i].key, template[i].klen); 622 623 ret = crypto_aead_setkey(tfm, key, template[i].klen); 624 if (!ret == template[i].fail) { 625 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n", 626 d, j, algo, crypto_aead_get_flags(tfm)); 627 goto out; 628 } else if (ret) 629 continue; 630 631 authsize = abs(template[i].rlen - template[i].ilen); 632 633 ret = -EINVAL; 634 sg_init_table(sg, template[i].np); 635 if (diff_dst) 636 sg_init_table(sgout, template[i].np); 637 for (k = 0, temp = 0; k < template[i].np; k++) { 638 if (WARN_ON(offset_in_page(IDX[k]) + 639 template[i].tap[k] > PAGE_SIZE)) 640 goto out; 641 642 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]); 643 memcpy(q, template[i].input + temp, template[i].tap[k]); 644 sg_set_buf(&sg[k], q, template[i].tap[k]); 645 646 if (diff_dst) { 647 q = xoutbuf[IDX[k] >> PAGE_SHIFT] + 648 offset_in_page(IDX[k]); 649 650 memset(q, 0, template[i].tap[k]); 651 652 sg_set_buf(&sgout[k], q, template[i].tap[k]); 653 } 654 655 n = template[i].tap[k]; 656 if (k == template[i].np - 1 && enc) 657 n += authsize; 658 if (offset_in_page(q) + n < PAGE_SIZE) 659 q[n] = 0; 660 661 temp += template[i].tap[k]; 662 } 663 664 ret = crypto_aead_setauthsize(tfm, authsize); 665 if (ret) { 666 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n", 667 d, authsize, j, algo); 668 goto out; 669 } 670 671 if (enc) { 672 if (WARN_ON(sg[k - 1].offset + 673 sg[k - 1].length + authsize > 674 PAGE_SIZE)) { 675 ret = -EINVAL; 676 goto out; 677 } 678 679 if (diff_dst) 680 sgout[k - 1].length += authsize; 681 else 682 sg[k - 1].length += authsize; 683 } 684 685 sg_init_table(asg, template[i].anp); 686 ret = -EINVAL; 687 for (k = 0, temp = 0; k < template[i].anp; k++) { 688 if (WARN_ON(offset_in_page(IDX[k]) + 689 template[i].atap[k] > PAGE_SIZE)) 690 goto out; 691 sg_set_buf(&asg[k], 692 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] + 693 offset_in_page(IDX[k]), 694 template[i].assoc + temp, 695 template[i].atap[k]), 696 template[i].atap[k]); 697 temp += template[i].atap[k]; 698 } 699 700 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, 701 template[i].ilen, 702 iv); 703 704 aead_request_set_assoc(req, asg, template[i].alen); 705 706 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req); 707 708 switch (ret) { 709 case 0: 710 if (template[i].novrfy) { 711 /* verification was supposed to fail */ 712 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n", 713 d, e, j, algo); 714 /* so really, we got a bad message */ 715 ret = -EBADMSG; 716 goto out; 717 } 718 break; 719 case -EINPROGRESS: 720 case -EBUSY: 721 wait_for_completion(&result.completion); 722 reinit_completion(&result.completion); 723 ret = result.err; 724 if (!ret) 725 break; 726 case -EBADMSG: 727 if (template[i].novrfy) 728 /* verification failure was expected */ 729 continue; 730 /* fall through */ 731 default: 732 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n", 733 d, e, j, algo, -ret); 734 goto out; 735 } 736 737 ret = -EINVAL; 738 for (k = 0, temp = 0; k < template[i].np; k++) { 739 if (diff_dst) 740 q = xoutbuf[IDX[k] >> PAGE_SHIFT] + 741 offset_in_page(IDX[k]); 742 else 743 q = xbuf[IDX[k] >> PAGE_SHIFT] + 744 offset_in_page(IDX[k]); 745 746 n = template[i].tap[k]; 747 if (k == template[i].np - 1) 748 n += enc ? authsize : -authsize; 749 750 if (memcmp(q, template[i].result + temp, n)) { 751 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n", 752 d, j, e, k, algo); 753 hexdump(q, n); 754 goto out; 755 } 756 757 q += n; 758 if (k == template[i].np - 1 && !enc) { 759 if (!diff_dst && 760 memcmp(q, template[i].input + 761 temp + n, authsize)) 762 n = authsize; 763 else 764 n = 0; 765 } else { 766 for (n = 0; offset_in_page(q + n) && q[n]; n++) 767 ; 768 } 769 if (n) { 770 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n", 771 d, j, e, k, algo, n); 772 hexdump(q, n); 773 goto out; 774 } 775 776 temp += template[i].tap[k]; 777 } 778 } 779 780 ret = 0; 781 782 out: 783 aead_request_free(req); 784 kfree(sg); 785 out_nosg: 786 if (diff_dst) 787 testmgr_free_buf(xoutbuf); 788 out_nooutbuf: 789 testmgr_free_buf(axbuf); 790 out_noaxbuf: 791 testmgr_free_buf(xbuf); 792 out_noxbuf: 793 kfree(key); 794 kfree(iv); 795 return ret; 796 } 797 798 static int test_aead(struct crypto_aead *tfm, int enc, 799 struct aead_testvec *template, unsigned int tcount) 800 { 801 unsigned int alignmask; 802 int ret; 803 804 /* test 'dst == src' case */ 805 ret = __test_aead(tfm, enc, template, tcount, false, 0); 806 if (ret) 807 return ret; 808 809 /* test 'dst != src' case */ 810 ret = __test_aead(tfm, enc, template, tcount, true, 0); 811 if (ret) 812 return ret; 813 814 /* test unaligned buffers, check with one byte offset */ 815 ret = __test_aead(tfm, enc, template, tcount, true, 1); 816 if (ret) 817 return ret; 818 819 alignmask = crypto_tfm_alg_alignmask(&tfm->base); 820 if (alignmask) { 821 /* Check if alignment mask for tfm is correctly set. */ 822 ret = __test_aead(tfm, enc, template, tcount, true, 823 alignmask + 1); 824 if (ret) 825 return ret; 826 } 827 828 return 0; 829 } 830 831 static int test_cipher(struct crypto_cipher *tfm, int enc, 832 struct cipher_testvec *template, unsigned int tcount) 833 { 834 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm)); 835 unsigned int i, j, k; 836 char *q; 837 const char *e; 838 void *data; 839 char *xbuf[XBUFSIZE]; 840 int ret = -ENOMEM; 841 842 if (testmgr_alloc_buf(xbuf)) 843 goto out_nobuf; 844 845 if (enc == ENCRYPT) 846 e = "encryption"; 847 else 848 e = "decryption"; 849 850 j = 0; 851 for (i = 0; i < tcount; i++) { 852 if (template[i].np) 853 continue; 854 855 j++; 856 857 ret = -EINVAL; 858 if (WARN_ON(template[i].ilen > PAGE_SIZE)) 859 goto out; 860 861 data = xbuf[0]; 862 memcpy(data, template[i].input, template[i].ilen); 863 864 crypto_cipher_clear_flags(tfm, ~0); 865 if (template[i].wk) 866 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY); 867 868 ret = crypto_cipher_setkey(tfm, template[i].key, 869 template[i].klen); 870 if (!ret == template[i].fail) { 871 printk(KERN_ERR "alg: cipher: setkey failed " 872 "on test %d for %s: flags=%x\n", j, 873 algo, crypto_cipher_get_flags(tfm)); 874 goto out; 875 } else if (ret) 876 continue; 877 878 for (k = 0; k < template[i].ilen; 879 k += crypto_cipher_blocksize(tfm)) { 880 if (enc) 881 crypto_cipher_encrypt_one(tfm, data + k, 882 data + k); 883 else 884 crypto_cipher_decrypt_one(tfm, data + k, 885 data + k); 886 } 887 888 q = data; 889 if (memcmp(q, template[i].result, template[i].rlen)) { 890 printk(KERN_ERR "alg: cipher: Test %d failed " 891 "on %s for %s\n", j, e, algo); 892 hexdump(q, template[i].rlen); 893 ret = -EINVAL; 894 goto out; 895 } 896 } 897 898 ret = 0; 899 900 out: 901 testmgr_free_buf(xbuf); 902 out_nobuf: 903 return ret; 904 } 905 906 static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc, 907 struct cipher_testvec *template, unsigned int tcount, 908 const bool diff_dst, const int align_offset) 909 { 910 const char *algo = 911 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm)); 912 unsigned int i, j, k, n, temp; 913 char *q; 914 struct ablkcipher_request *req; 915 struct scatterlist sg[8]; 916 struct scatterlist sgout[8]; 917 const char *e, *d; 918 struct tcrypt_result result; 919 void *data; 920 char iv[MAX_IVLEN]; 921 char *xbuf[XBUFSIZE]; 922 char *xoutbuf[XBUFSIZE]; 923 int ret = -ENOMEM; 924 925 if (testmgr_alloc_buf(xbuf)) 926 goto out_nobuf; 927 928 if (diff_dst && testmgr_alloc_buf(xoutbuf)) 929 goto out_nooutbuf; 930 931 if (diff_dst) 932 d = "-ddst"; 933 else 934 d = ""; 935 936 if (enc == ENCRYPT) 937 e = "encryption"; 938 else 939 e = "decryption"; 940 941 init_completion(&result.completion); 942 943 req = ablkcipher_request_alloc(tfm, GFP_KERNEL); 944 if (!req) { 945 pr_err("alg: skcipher%s: Failed to allocate request for %s\n", 946 d, algo); 947 goto out; 948 } 949 950 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 951 tcrypt_complete, &result); 952 953 j = 0; 954 for (i = 0; i < tcount; i++) { 955 if (template[i].np && !template[i].also_non_np) 956 continue; 957 958 if (template[i].iv) 959 memcpy(iv, template[i].iv, MAX_IVLEN); 960 else 961 memset(iv, 0, MAX_IVLEN); 962 963 j++; 964 ret = -EINVAL; 965 if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE)) 966 goto out; 967 968 data = xbuf[0]; 969 data += align_offset; 970 memcpy(data, template[i].input, template[i].ilen); 971 972 crypto_ablkcipher_clear_flags(tfm, ~0); 973 if (template[i].wk) 974 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY); 975 976 ret = crypto_ablkcipher_setkey(tfm, template[i].key, 977 template[i].klen); 978 if (!ret == template[i].fail) { 979 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n", 980 d, j, algo, crypto_ablkcipher_get_flags(tfm)); 981 goto out; 982 } else if (ret) 983 continue; 984 985 sg_init_one(&sg[0], data, template[i].ilen); 986 if (diff_dst) { 987 data = xoutbuf[0]; 988 data += align_offset; 989 sg_init_one(&sgout[0], data, template[i].ilen); 990 } 991 992 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, 993 template[i].ilen, iv); 994 ret = enc ? crypto_ablkcipher_encrypt(req) : 995 crypto_ablkcipher_decrypt(req); 996 997 switch (ret) { 998 case 0: 999 break; 1000 case -EINPROGRESS: 1001 case -EBUSY: 1002 wait_for_completion(&result.completion); 1003 reinit_completion(&result.completion); 1004 ret = result.err; 1005 if (!ret) 1006 break; 1007 /* fall through */ 1008 default: 1009 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n", 1010 d, e, j, algo, -ret); 1011 goto out; 1012 } 1013 1014 q = data; 1015 if (memcmp(q, template[i].result, template[i].rlen)) { 1016 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n", 1017 d, j, e, algo); 1018 hexdump(q, template[i].rlen); 1019 ret = -EINVAL; 1020 goto out; 1021 } 1022 } 1023 1024 j = 0; 1025 for (i = 0; i < tcount; i++) { 1026 /* alignment tests are only done with continuous buffers */ 1027 if (align_offset != 0) 1028 break; 1029 1030 if (!template[i].np) 1031 continue; 1032 1033 if (template[i].iv) 1034 memcpy(iv, template[i].iv, MAX_IVLEN); 1035 else 1036 memset(iv, 0, MAX_IVLEN); 1037 1038 j++; 1039 crypto_ablkcipher_clear_flags(tfm, ~0); 1040 if (template[i].wk) 1041 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY); 1042 1043 ret = crypto_ablkcipher_setkey(tfm, template[i].key, 1044 template[i].klen); 1045 if (!ret == template[i].fail) { 1046 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n", 1047 d, j, algo, crypto_ablkcipher_get_flags(tfm)); 1048 goto out; 1049 } else if (ret) 1050 continue; 1051 1052 temp = 0; 1053 ret = -EINVAL; 1054 sg_init_table(sg, template[i].np); 1055 if (diff_dst) 1056 sg_init_table(sgout, template[i].np); 1057 for (k = 0; k < template[i].np; k++) { 1058 if (WARN_ON(offset_in_page(IDX[k]) + 1059 template[i].tap[k] > PAGE_SIZE)) 1060 goto out; 1061 1062 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]); 1063 1064 memcpy(q, template[i].input + temp, template[i].tap[k]); 1065 1066 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE) 1067 q[template[i].tap[k]] = 0; 1068 1069 sg_set_buf(&sg[k], q, template[i].tap[k]); 1070 if (diff_dst) { 1071 q = xoutbuf[IDX[k] >> PAGE_SHIFT] + 1072 offset_in_page(IDX[k]); 1073 1074 sg_set_buf(&sgout[k], q, template[i].tap[k]); 1075 1076 memset(q, 0, template[i].tap[k]); 1077 if (offset_in_page(q) + 1078 template[i].tap[k] < PAGE_SIZE) 1079 q[template[i].tap[k]] = 0; 1080 } 1081 1082 temp += template[i].tap[k]; 1083 } 1084 1085 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, 1086 template[i].ilen, iv); 1087 1088 ret = enc ? crypto_ablkcipher_encrypt(req) : 1089 crypto_ablkcipher_decrypt(req); 1090 1091 switch (ret) { 1092 case 0: 1093 break; 1094 case -EINPROGRESS: 1095 case -EBUSY: 1096 wait_for_completion(&result.completion); 1097 reinit_completion(&result.completion); 1098 ret = result.err; 1099 if (!ret) 1100 break; 1101 /* fall through */ 1102 default: 1103 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n", 1104 d, e, j, algo, -ret); 1105 goto out; 1106 } 1107 1108 temp = 0; 1109 ret = -EINVAL; 1110 for (k = 0; k < template[i].np; k++) { 1111 if (diff_dst) 1112 q = xoutbuf[IDX[k] >> PAGE_SHIFT] + 1113 offset_in_page(IDX[k]); 1114 else 1115 q = xbuf[IDX[k] >> PAGE_SHIFT] + 1116 offset_in_page(IDX[k]); 1117 1118 if (memcmp(q, template[i].result + temp, 1119 template[i].tap[k])) { 1120 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n", 1121 d, j, e, k, algo); 1122 hexdump(q, template[i].tap[k]); 1123 goto out; 1124 } 1125 1126 q += template[i].tap[k]; 1127 for (n = 0; offset_in_page(q + n) && q[n]; n++) 1128 ; 1129 if (n) { 1130 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n", 1131 d, j, e, k, algo, n); 1132 hexdump(q, n); 1133 goto out; 1134 } 1135 temp += template[i].tap[k]; 1136 } 1137 } 1138 1139 ret = 0; 1140 1141 out: 1142 ablkcipher_request_free(req); 1143 if (diff_dst) 1144 testmgr_free_buf(xoutbuf); 1145 out_nooutbuf: 1146 testmgr_free_buf(xbuf); 1147 out_nobuf: 1148 return ret; 1149 } 1150 1151 static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, 1152 struct cipher_testvec *template, unsigned int tcount) 1153 { 1154 unsigned int alignmask; 1155 int ret; 1156 1157 /* test 'dst == src' case */ 1158 ret = __test_skcipher(tfm, enc, template, tcount, false, 0); 1159 if (ret) 1160 return ret; 1161 1162 /* test 'dst != src' case */ 1163 ret = __test_skcipher(tfm, enc, template, tcount, true, 0); 1164 if (ret) 1165 return ret; 1166 1167 /* test unaligned buffers, check with one byte offset */ 1168 ret = __test_skcipher(tfm, enc, template, tcount, true, 1); 1169 if (ret) 1170 return ret; 1171 1172 alignmask = crypto_tfm_alg_alignmask(&tfm->base); 1173 if (alignmask) { 1174 /* Check if alignment mask for tfm is correctly set. */ 1175 ret = __test_skcipher(tfm, enc, template, tcount, true, 1176 alignmask + 1); 1177 if (ret) 1178 return ret; 1179 } 1180 1181 return 0; 1182 } 1183 1184 static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate, 1185 struct comp_testvec *dtemplate, int ctcount, int dtcount) 1186 { 1187 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm)); 1188 unsigned int i; 1189 char result[COMP_BUF_SIZE]; 1190 int ret; 1191 1192 for (i = 0; i < ctcount; i++) { 1193 int ilen; 1194 unsigned int dlen = COMP_BUF_SIZE; 1195 1196 memset(result, 0, sizeof (result)); 1197 1198 ilen = ctemplate[i].inlen; 1199 ret = crypto_comp_compress(tfm, ctemplate[i].input, 1200 ilen, result, &dlen); 1201 if (ret) { 1202 printk(KERN_ERR "alg: comp: compression failed " 1203 "on test %d for %s: ret=%d\n", i + 1, algo, 1204 -ret); 1205 goto out; 1206 } 1207 1208 if (dlen != ctemplate[i].outlen) { 1209 printk(KERN_ERR "alg: comp: Compression test %d " 1210 "failed for %s: output len = %d\n", i + 1, algo, 1211 dlen); 1212 ret = -EINVAL; 1213 goto out; 1214 } 1215 1216 if (memcmp(result, ctemplate[i].output, dlen)) { 1217 printk(KERN_ERR "alg: comp: Compression test %d " 1218 "failed for %s\n", i + 1, algo); 1219 hexdump(result, dlen); 1220 ret = -EINVAL; 1221 goto out; 1222 } 1223 } 1224 1225 for (i = 0; i < dtcount; i++) { 1226 int ilen; 1227 unsigned int dlen = COMP_BUF_SIZE; 1228 1229 memset(result, 0, sizeof (result)); 1230 1231 ilen = dtemplate[i].inlen; 1232 ret = crypto_comp_decompress(tfm, dtemplate[i].input, 1233 ilen, result, &dlen); 1234 if (ret) { 1235 printk(KERN_ERR "alg: comp: decompression failed " 1236 "on test %d for %s: ret=%d\n", i + 1, algo, 1237 -ret); 1238 goto out; 1239 } 1240 1241 if (dlen != dtemplate[i].outlen) { 1242 printk(KERN_ERR "alg: comp: Decompression test %d " 1243 "failed for %s: output len = %d\n", i + 1, algo, 1244 dlen); 1245 ret = -EINVAL; 1246 goto out; 1247 } 1248 1249 if (memcmp(result, dtemplate[i].output, dlen)) { 1250 printk(KERN_ERR "alg: comp: Decompression test %d " 1251 "failed for %s\n", i + 1, algo); 1252 hexdump(result, dlen); 1253 ret = -EINVAL; 1254 goto out; 1255 } 1256 } 1257 1258 ret = 0; 1259 1260 out: 1261 return ret; 1262 } 1263 1264 static int test_pcomp(struct crypto_pcomp *tfm, 1265 struct pcomp_testvec *ctemplate, 1266 struct pcomp_testvec *dtemplate, int ctcount, 1267 int dtcount) 1268 { 1269 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm)); 1270 unsigned int i; 1271 char result[COMP_BUF_SIZE]; 1272 int res; 1273 1274 for (i = 0; i < ctcount; i++) { 1275 struct comp_request req; 1276 unsigned int produced = 0; 1277 1278 res = crypto_compress_setup(tfm, ctemplate[i].params, 1279 ctemplate[i].paramsize); 1280 if (res) { 1281 pr_err("alg: pcomp: compression setup failed on test " 1282 "%d for %s: error=%d\n", i + 1, algo, res); 1283 return res; 1284 } 1285 1286 res = crypto_compress_init(tfm); 1287 if (res) { 1288 pr_err("alg: pcomp: compression init failed on test " 1289 "%d for %s: error=%d\n", i + 1, algo, res); 1290 return res; 1291 } 1292 1293 memset(result, 0, sizeof(result)); 1294 1295 req.next_in = ctemplate[i].input; 1296 req.avail_in = ctemplate[i].inlen / 2; 1297 req.next_out = result; 1298 req.avail_out = ctemplate[i].outlen / 2; 1299 1300 res = crypto_compress_update(tfm, &req); 1301 if (res < 0 && (res != -EAGAIN || req.avail_in)) { 1302 pr_err("alg: pcomp: compression update failed on test " 1303 "%d for %s: error=%d\n", i + 1, algo, res); 1304 return res; 1305 } 1306 if (res > 0) 1307 produced += res; 1308 1309 /* Add remaining input data */ 1310 req.avail_in += (ctemplate[i].inlen + 1) / 2; 1311 1312 res = crypto_compress_update(tfm, &req); 1313 if (res < 0 && (res != -EAGAIN || req.avail_in)) { 1314 pr_err("alg: pcomp: compression update failed on test " 1315 "%d for %s: error=%d\n", i + 1, algo, res); 1316 return res; 1317 } 1318 if (res > 0) 1319 produced += res; 1320 1321 /* Provide remaining output space */ 1322 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2; 1323 1324 res = crypto_compress_final(tfm, &req); 1325 if (res < 0) { 1326 pr_err("alg: pcomp: compression final failed on test " 1327 "%d for %s: error=%d\n", i + 1, algo, res); 1328 return res; 1329 } 1330 produced += res; 1331 1332 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) { 1333 pr_err("alg: comp: Compression test %d failed for %s: " 1334 "output len = %d (expected %d)\n", i + 1, algo, 1335 COMP_BUF_SIZE - req.avail_out, 1336 ctemplate[i].outlen); 1337 return -EINVAL; 1338 } 1339 1340 if (produced != ctemplate[i].outlen) { 1341 pr_err("alg: comp: Compression test %d failed for %s: " 1342 "returned len = %u (expected %d)\n", i + 1, 1343 algo, produced, ctemplate[i].outlen); 1344 return -EINVAL; 1345 } 1346 1347 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) { 1348 pr_err("alg: pcomp: Compression test %d failed for " 1349 "%s\n", i + 1, algo); 1350 hexdump(result, ctemplate[i].outlen); 1351 return -EINVAL; 1352 } 1353 } 1354 1355 for (i = 0; i < dtcount; i++) { 1356 struct comp_request req; 1357 unsigned int produced = 0; 1358 1359 res = crypto_decompress_setup(tfm, dtemplate[i].params, 1360 dtemplate[i].paramsize); 1361 if (res) { 1362 pr_err("alg: pcomp: decompression setup failed on " 1363 "test %d for %s: error=%d\n", i + 1, algo, res); 1364 return res; 1365 } 1366 1367 res = crypto_decompress_init(tfm); 1368 if (res) { 1369 pr_err("alg: pcomp: decompression init failed on test " 1370 "%d for %s: error=%d\n", i + 1, algo, res); 1371 return res; 1372 } 1373 1374 memset(result, 0, sizeof(result)); 1375 1376 req.next_in = dtemplate[i].input; 1377 req.avail_in = dtemplate[i].inlen / 2; 1378 req.next_out = result; 1379 req.avail_out = dtemplate[i].outlen / 2; 1380 1381 res = crypto_decompress_update(tfm, &req); 1382 if (res < 0 && (res != -EAGAIN || req.avail_in)) { 1383 pr_err("alg: pcomp: decompression update failed on " 1384 "test %d for %s: error=%d\n", i + 1, algo, res); 1385 return res; 1386 } 1387 if (res > 0) 1388 produced += res; 1389 1390 /* Add remaining input data */ 1391 req.avail_in += (dtemplate[i].inlen + 1) / 2; 1392 1393 res = crypto_decompress_update(tfm, &req); 1394 if (res < 0 && (res != -EAGAIN || req.avail_in)) { 1395 pr_err("alg: pcomp: decompression update failed on " 1396 "test %d for %s: error=%d\n", i + 1, algo, res); 1397 return res; 1398 } 1399 if (res > 0) 1400 produced += res; 1401 1402 /* Provide remaining output space */ 1403 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2; 1404 1405 res = crypto_decompress_final(tfm, &req); 1406 if (res < 0 && (res != -EAGAIN || req.avail_in)) { 1407 pr_err("alg: pcomp: decompression final failed on " 1408 "test %d for %s: error=%d\n", i + 1, algo, res); 1409 return res; 1410 } 1411 if (res > 0) 1412 produced += res; 1413 1414 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) { 1415 pr_err("alg: comp: Decompression test %d failed for " 1416 "%s: output len = %d (expected %d)\n", i + 1, 1417 algo, COMP_BUF_SIZE - req.avail_out, 1418 dtemplate[i].outlen); 1419 return -EINVAL; 1420 } 1421 1422 if (produced != dtemplate[i].outlen) { 1423 pr_err("alg: comp: Decompression test %d failed for " 1424 "%s: returned len = %u (expected %d)\n", i + 1, 1425 algo, produced, dtemplate[i].outlen); 1426 return -EINVAL; 1427 } 1428 1429 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) { 1430 pr_err("alg: pcomp: Decompression test %d failed for " 1431 "%s\n", i + 1, algo); 1432 hexdump(result, dtemplate[i].outlen); 1433 return -EINVAL; 1434 } 1435 } 1436 1437 return 0; 1438 } 1439 1440 1441 static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template, 1442 unsigned int tcount) 1443 { 1444 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm)); 1445 int err = 0, i, j, seedsize; 1446 u8 *seed; 1447 char result[32]; 1448 1449 seedsize = crypto_rng_seedsize(tfm); 1450 1451 seed = kmalloc(seedsize, GFP_KERNEL); 1452 if (!seed) { 1453 printk(KERN_ERR "alg: cprng: Failed to allocate seed space " 1454 "for %s\n", algo); 1455 return -ENOMEM; 1456 } 1457 1458 for (i = 0; i < tcount; i++) { 1459 memset(result, 0, 32); 1460 1461 memcpy(seed, template[i].v, template[i].vlen); 1462 memcpy(seed + template[i].vlen, template[i].key, 1463 template[i].klen); 1464 memcpy(seed + template[i].vlen + template[i].klen, 1465 template[i].dt, template[i].dtlen); 1466 1467 err = crypto_rng_reset(tfm, seed, seedsize); 1468 if (err) { 1469 printk(KERN_ERR "alg: cprng: Failed to reset rng " 1470 "for %s\n", algo); 1471 goto out; 1472 } 1473 1474 for (j = 0; j < template[i].loops; j++) { 1475 err = crypto_rng_get_bytes(tfm, result, 1476 template[i].rlen); 1477 if (err < 0) { 1478 printk(KERN_ERR "alg: cprng: Failed to obtain " 1479 "the correct amount of random data for " 1480 "%s (requested %d)\n", algo, 1481 template[i].rlen); 1482 goto out; 1483 } 1484 } 1485 1486 err = memcmp(result, template[i].result, 1487 template[i].rlen); 1488 if (err) { 1489 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n", 1490 i, algo); 1491 hexdump(result, template[i].rlen); 1492 err = -EINVAL; 1493 goto out; 1494 } 1495 } 1496 1497 out: 1498 kfree(seed); 1499 return err; 1500 } 1501 1502 static int alg_test_aead(const struct alg_test_desc *desc, const char *driver, 1503 u32 type, u32 mask) 1504 { 1505 struct crypto_aead *tfm; 1506 int err = 0; 1507 1508 tfm = crypto_alloc_aead(driver, type | CRYPTO_ALG_INTERNAL, mask); 1509 if (IS_ERR(tfm)) { 1510 printk(KERN_ERR "alg: aead: Failed to load transform for %s: " 1511 "%ld\n", driver, PTR_ERR(tfm)); 1512 return PTR_ERR(tfm); 1513 } 1514 1515 if (desc->suite.aead.enc.vecs) { 1516 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs, 1517 desc->suite.aead.enc.count); 1518 if (err) 1519 goto out; 1520 } 1521 1522 if (!err && desc->suite.aead.dec.vecs) 1523 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs, 1524 desc->suite.aead.dec.count); 1525 1526 out: 1527 crypto_free_aead(tfm); 1528 return err; 1529 } 1530 1531 static int alg_test_cipher(const struct alg_test_desc *desc, 1532 const char *driver, u32 type, u32 mask) 1533 { 1534 struct crypto_cipher *tfm; 1535 int err = 0; 1536 1537 tfm = crypto_alloc_cipher(driver, type | CRYPTO_ALG_INTERNAL, mask); 1538 if (IS_ERR(tfm)) { 1539 printk(KERN_ERR "alg: cipher: Failed to load transform for " 1540 "%s: %ld\n", driver, PTR_ERR(tfm)); 1541 return PTR_ERR(tfm); 1542 } 1543 1544 if (desc->suite.cipher.enc.vecs) { 1545 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs, 1546 desc->suite.cipher.enc.count); 1547 if (err) 1548 goto out; 1549 } 1550 1551 if (desc->suite.cipher.dec.vecs) 1552 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs, 1553 desc->suite.cipher.dec.count); 1554 1555 out: 1556 crypto_free_cipher(tfm); 1557 return err; 1558 } 1559 1560 static int alg_test_skcipher(const struct alg_test_desc *desc, 1561 const char *driver, u32 type, u32 mask) 1562 { 1563 struct crypto_ablkcipher *tfm; 1564 int err = 0; 1565 1566 tfm = crypto_alloc_ablkcipher(driver, type | CRYPTO_ALG_INTERNAL, mask); 1567 if (IS_ERR(tfm)) { 1568 printk(KERN_ERR "alg: skcipher: Failed to load transform for " 1569 "%s: %ld\n", driver, PTR_ERR(tfm)); 1570 return PTR_ERR(tfm); 1571 } 1572 1573 if (desc->suite.cipher.enc.vecs) { 1574 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs, 1575 desc->suite.cipher.enc.count); 1576 if (err) 1577 goto out; 1578 } 1579 1580 if (desc->suite.cipher.dec.vecs) 1581 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs, 1582 desc->suite.cipher.dec.count); 1583 1584 out: 1585 crypto_free_ablkcipher(tfm); 1586 return err; 1587 } 1588 1589 static int alg_test_comp(const struct alg_test_desc *desc, const char *driver, 1590 u32 type, u32 mask) 1591 { 1592 struct crypto_comp *tfm; 1593 int err; 1594 1595 tfm = crypto_alloc_comp(driver, type, mask); 1596 if (IS_ERR(tfm)) { 1597 printk(KERN_ERR "alg: comp: Failed to load transform for %s: " 1598 "%ld\n", driver, PTR_ERR(tfm)); 1599 return PTR_ERR(tfm); 1600 } 1601 1602 err = test_comp(tfm, desc->suite.comp.comp.vecs, 1603 desc->suite.comp.decomp.vecs, 1604 desc->suite.comp.comp.count, 1605 desc->suite.comp.decomp.count); 1606 1607 crypto_free_comp(tfm); 1608 return err; 1609 } 1610 1611 static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver, 1612 u32 type, u32 mask) 1613 { 1614 struct crypto_pcomp *tfm; 1615 int err; 1616 1617 tfm = crypto_alloc_pcomp(driver, type, mask); 1618 if (IS_ERR(tfm)) { 1619 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n", 1620 driver, PTR_ERR(tfm)); 1621 return PTR_ERR(tfm); 1622 } 1623 1624 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs, 1625 desc->suite.pcomp.decomp.vecs, 1626 desc->suite.pcomp.comp.count, 1627 desc->suite.pcomp.decomp.count); 1628 1629 crypto_free_pcomp(tfm); 1630 return err; 1631 } 1632 1633 static int alg_test_hash(const struct alg_test_desc *desc, const char *driver, 1634 u32 type, u32 mask) 1635 { 1636 struct crypto_ahash *tfm; 1637 int err; 1638 1639 tfm = crypto_alloc_ahash(driver, type | CRYPTO_ALG_INTERNAL, mask); 1640 if (IS_ERR(tfm)) { 1641 printk(KERN_ERR "alg: hash: Failed to load transform for %s: " 1642 "%ld\n", driver, PTR_ERR(tfm)); 1643 return PTR_ERR(tfm); 1644 } 1645 1646 err = test_hash(tfm, desc->suite.hash.vecs, 1647 desc->suite.hash.count, true); 1648 if (!err) 1649 err = test_hash(tfm, desc->suite.hash.vecs, 1650 desc->suite.hash.count, false); 1651 1652 crypto_free_ahash(tfm); 1653 return err; 1654 } 1655 1656 static int alg_test_crc32c(const struct alg_test_desc *desc, 1657 const char *driver, u32 type, u32 mask) 1658 { 1659 struct crypto_shash *tfm; 1660 u32 val; 1661 int err; 1662 1663 err = alg_test_hash(desc, driver, type, mask); 1664 if (err) 1665 goto out; 1666 1667 tfm = crypto_alloc_shash(driver, type | CRYPTO_ALG_INTERNAL, mask); 1668 if (IS_ERR(tfm)) { 1669 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: " 1670 "%ld\n", driver, PTR_ERR(tfm)); 1671 err = PTR_ERR(tfm); 1672 goto out; 1673 } 1674 1675 do { 1676 SHASH_DESC_ON_STACK(shash, tfm); 1677 u32 *ctx = (u32 *)shash_desc_ctx(shash); 1678 1679 shash->tfm = tfm; 1680 shash->flags = 0; 1681 1682 *ctx = le32_to_cpu(420553207); 1683 err = crypto_shash_final(shash, (u8 *)&val); 1684 if (err) { 1685 printk(KERN_ERR "alg: crc32c: Operation failed for " 1686 "%s: %d\n", driver, err); 1687 break; 1688 } 1689 1690 if (val != ~420553207) { 1691 printk(KERN_ERR "alg: crc32c: Test failed for %s: " 1692 "%d\n", driver, val); 1693 err = -EINVAL; 1694 } 1695 } while (0); 1696 1697 crypto_free_shash(tfm); 1698 1699 out: 1700 return err; 1701 } 1702 1703 static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver, 1704 u32 type, u32 mask) 1705 { 1706 struct crypto_rng *rng; 1707 int err; 1708 1709 rng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask); 1710 if (IS_ERR(rng)) { 1711 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: " 1712 "%ld\n", driver, PTR_ERR(rng)); 1713 return PTR_ERR(rng); 1714 } 1715 1716 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count); 1717 1718 crypto_free_rng(rng); 1719 1720 return err; 1721 } 1722 1723 1724 static int drbg_cavs_test(struct drbg_testvec *test, int pr, 1725 const char *driver, u32 type, u32 mask) 1726 { 1727 int ret = -EAGAIN; 1728 struct crypto_rng *drng; 1729 struct drbg_test_data test_data; 1730 struct drbg_string addtl, pers, testentropy; 1731 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL); 1732 1733 if (!buf) 1734 return -ENOMEM; 1735 1736 drng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask); 1737 if (IS_ERR(drng)) { 1738 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for " 1739 "%s\n", driver); 1740 kzfree(buf); 1741 return -ENOMEM; 1742 } 1743 1744 test_data.testentropy = &testentropy; 1745 drbg_string_fill(&testentropy, test->entropy, test->entropylen); 1746 drbg_string_fill(&pers, test->pers, test->perslen); 1747 ret = crypto_drbg_reset_test(drng, &pers, &test_data); 1748 if (ret) { 1749 printk(KERN_ERR "alg: drbg: Failed to reset rng\n"); 1750 goto outbuf; 1751 } 1752 1753 drbg_string_fill(&addtl, test->addtla, test->addtllen); 1754 if (pr) { 1755 drbg_string_fill(&testentropy, test->entpra, test->entprlen); 1756 ret = crypto_drbg_get_bytes_addtl_test(drng, 1757 buf, test->expectedlen, &addtl, &test_data); 1758 } else { 1759 ret = crypto_drbg_get_bytes_addtl(drng, 1760 buf, test->expectedlen, &addtl); 1761 } 1762 if (ret < 0) { 1763 printk(KERN_ERR "alg: drbg: could not obtain random data for " 1764 "driver %s\n", driver); 1765 goto outbuf; 1766 } 1767 1768 drbg_string_fill(&addtl, test->addtlb, test->addtllen); 1769 if (pr) { 1770 drbg_string_fill(&testentropy, test->entprb, test->entprlen); 1771 ret = crypto_drbg_get_bytes_addtl_test(drng, 1772 buf, test->expectedlen, &addtl, &test_data); 1773 } else { 1774 ret = crypto_drbg_get_bytes_addtl(drng, 1775 buf, test->expectedlen, &addtl); 1776 } 1777 if (ret < 0) { 1778 printk(KERN_ERR "alg: drbg: could not obtain random data for " 1779 "driver %s\n", driver); 1780 goto outbuf; 1781 } 1782 1783 ret = memcmp(test->expected, buf, test->expectedlen); 1784 1785 outbuf: 1786 crypto_free_rng(drng); 1787 kzfree(buf); 1788 return ret; 1789 } 1790 1791 1792 static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver, 1793 u32 type, u32 mask) 1794 { 1795 int err = 0; 1796 int pr = 0; 1797 int i = 0; 1798 struct drbg_testvec *template = desc->suite.drbg.vecs; 1799 unsigned int tcount = desc->suite.drbg.count; 1800 1801 if (0 == memcmp(driver, "drbg_pr_", 8)) 1802 pr = 1; 1803 1804 for (i = 0; i < tcount; i++) { 1805 err = drbg_cavs_test(&template[i], pr, driver, type, mask); 1806 if (err) { 1807 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n", 1808 i, driver); 1809 err = -EINVAL; 1810 break; 1811 } 1812 } 1813 return err; 1814 1815 } 1816 1817 static int alg_test_null(const struct alg_test_desc *desc, 1818 const char *driver, u32 type, u32 mask) 1819 { 1820 return 0; 1821 } 1822 1823 /* Please keep this list sorted by algorithm name. */ 1824 static const struct alg_test_desc alg_test_descs[] = { 1825 { 1826 .alg = "__cbc-cast5-avx", 1827 .test = alg_test_null, 1828 }, { 1829 .alg = "__cbc-cast6-avx", 1830 .test = alg_test_null, 1831 }, { 1832 .alg = "__cbc-serpent-avx", 1833 .test = alg_test_null, 1834 }, { 1835 .alg = "__cbc-serpent-avx2", 1836 .test = alg_test_null, 1837 }, { 1838 .alg = "__cbc-serpent-sse2", 1839 .test = alg_test_null, 1840 }, { 1841 .alg = "__cbc-twofish-avx", 1842 .test = alg_test_null, 1843 }, { 1844 .alg = "__driver-cbc-aes-aesni", 1845 .test = alg_test_null, 1846 .fips_allowed = 1, 1847 }, { 1848 .alg = "__driver-cbc-camellia-aesni", 1849 .test = alg_test_null, 1850 }, { 1851 .alg = "__driver-cbc-camellia-aesni-avx2", 1852 .test = alg_test_null, 1853 }, { 1854 .alg = "__driver-cbc-cast5-avx", 1855 .test = alg_test_null, 1856 }, { 1857 .alg = "__driver-cbc-cast6-avx", 1858 .test = alg_test_null, 1859 }, { 1860 .alg = "__driver-cbc-serpent-avx", 1861 .test = alg_test_null, 1862 }, { 1863 .alg = "__driver-cbc-serpent-avx2", 1864 .test = alg_test_null, 1865 }, { 1866 .alg = "__driver-cbc-serpent-sse2", 1867 .test = alg_test_null, 1868 }, { 1869 .alg = "__driver-cbc-twofish-avx", 1870 .test = alg_test_null, 1871 }, { 1872 .alg = "__driver-ecb-aes-aesni", 1873 .test = alg_test_null, 1874 .fips_allowed = 1, 1875 }, { 1876 .alg = "__driver-ecb-camellia-aesni", 1877 .test = alg_test_null, 1878 }, { 1879 .alg = "__driver-ecb-camellia-aesni-avx2", 1880 .test = alg_test_null, 1881 }, { 1882 .alg = "__driver-ecb-cast5-avx", 1883 .test = alg_test_null, 1884 }, { 1885 .alg = "__driver-ecb-cast6-avx", 1886 .test = alg_test_null, 1887 }, { 1888 .alg = "__driver-ecb-serpent-avx", 1889 .test = alg_test_null, 1890 }, { 1891 .alg = "__driver-ecb-serpent-avx2", 1892 .test = alg_test_null, 1893 }, { 1894 .alg = "__driver-ecb-serpent-sse2", 1895 .test = alg_test_null, 1896 }, { 1897 .alg = "__driver-ecb-twofish-avx", 1898 .test = alg_test_null, 1899 }, { 1900 .alg = "__ghash-pclmulqdqni", 1901 .test = alg_test_null, 1902 .fips_allowed = 1, 1903 }, { 1904 .alg = "ansi_cprng", 1905 .test = alg_test_cprng, 1906 .fips_allowed = 1, 1907 .suite = { 1908 .cprng = { 1909 .vecs = ansi_cprng_aes_tv_template, 1910 .count = ANSI_CPRNG_AES_TEST_VECTORS 1911 } 1912 } 1913 }, { 1914 .alg = "authenc(hmac(md5),ecb(cipher_null))", 1915 .test = alg_test_aead, 1916 .fips_allowed = 1, 1917 .suite = { 1918 .aead = { 1919 .enc = { 1920 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template, 1921 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS 1922 }, 1923 .dec = { 1924 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template, 1925 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS 1926 } 1927 } 1928 } 1929 }, { 1930 .alg = "authenc(hmac(sha1),cbc(aes))", 1931 .test = alg_test_aead, 1932 .fips_allowed = 1, 1933 .suite = { 1934 .aead = { 1935 .enc = { 1936 .vecs = 1937 hmac_sha1_aes_cbc_enc_tv_temp, 1938 .count = 1939 HMAC_SHA1_AES_CBC_ENC_TEST_VEC 1940 } 1941 } 1942 } 1943 }, { 1944 .alg = "authenc(hmac(sha1),cbc(des))", 1945 .test = alg_test_aead, 1946 .fips_allowed = 1, 1947 .suite = { 1948 .aead = { 1949 .enc = { 1950 .vecs = 1951 hmac_sha1_des_cbc_enc_tv_temp, 1952 .count = 1953 HMAC_SHA1_DES_CBC_ENC_TEST_VEC 1954 } 1955 } 1956 } 1957 }, { 1958 .alg = "authenc(hmac(sha1),cbc(des3_ede))", 1959 .test = alg_test_aead, 1960 .fips_allowed = 1, 1961 .suite = { 1962 .aead = { 1963 .enc = { 1964 .vecs = 1965 hmac_sha1_des3_ede_cbc_enc_tv_temp, 1966 .count = 1967 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC 1968 } 1969 } 1970 } 1971 }, { 1972 .alg = "authenc(hmac(sha1),ecb(cipher_null))", 1973 .test = alg_test_aead, 1974 .fips_allowed = 1, 1975 .suite = { 1976 .aead = { 1977 .enc = { 1978 .vecs = 1979 hmac_sha1_ecb_cipher_null_enc_tv_temp, 1980 .count = 1981 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC 1982 }, 1983 .dec = { 1984 .vecs = 1985 hmac_sha1_ecb_cipher_null_dec_tv_temp, 1986 .count = 1987 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC 1988 } 1989 } 1990 } 1991 }, { 1992 .alg = "authenc(hmac(sha224),cbc(des))", 1993 .test = alg_test_aead, 1994 .fips_allowed = 1, 1995 .suite = { 1996 .aead = { 1997 .enc = { 1998 .vecs = 1999 hmac_sha224_des_cbc_enc_tv_temp, 2000 .count = 2001 HMAC_SHA224_DES_CBC_ENC_TEST_VEC 2002 } 2003 } 2004 } 2005 }, { 2006 .alg = "authenc(hmac(sha224),cbc(des3_ede))", 2007 .test = alg_test_aead, 2008 .fips_allowed = 1, 2009 .suite = { 2010 .aead = { 2011 .enc = { 2012 .vecs = 2013 hmac_sha224_des3_ede_cbc_enc_tv_temp, 2014 .count = 2015 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC 2016 } 2017 } 2018 } 2019 }, { 2020 .alg = "authenc(hmac(sha256),cbc(aes))", 2021 .test = alg_test_aead, 2022 .fips_allowed = 1, 2023 .suite = { 2024 .aead = { 2025 .enc = { 2026 .vecs = 2027 hmac_sha256_aes_cbc_enc_tv_temp, 2028 .count = 2029 HMAC_SHA256_AES_CBC_ENC_TEST_VEC 2030 } 2031 } 2032 } 2033 }, { 2034 .alg = "authenc(hmac(sha256),cbc(des))", 2035 .test = alg_test_aead, 2036 .fips_allowed = 1, 2037 .suite = { 2038 .aead = { 2039 .enc = { 2040 .vecs = 2041 hmac_sha256_des_cbc_enc_tv_temp, 2042 .count = 2043 HMAC_SHA256_DES_CBC_ENC_TEST_VEC 2044 } 2045 } 2046 } 2047 }, { 2048 .alg = "authenc(hmac(sha256),cbc(des3_ede))", 2049 .test = alg_test_aead, 2050 .fips_allowed = 1, 2051 .suite = { 2052 .aead = { 2053 .enc = { 2054 .vecs = 2055 hmac_sha256_des3_ede_cbc_enc_tv_temp, 2056 .count = 2057 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC 2058 } 2059 } 2060 } 2061 }, { 2062 .alg = "authenc(hmac(sha384),cbc(des))", 2063 .test = alg_test_aead, 2064 .fips_allowed = 1, 2065 .suite = { 2066 .aead = { 2067 .enc = { 2068 .vecs = 2069 hmac_sha384_des_cbc_enc_tv_temp, 2070 .count = 2071 HMAC_SHA384_DES_CBC_ENC_TEST_VEC 2072 } 2073 } 2074 } 2075 }, { 2076 .alg = "authenc(hmac(sha384),cbc(des3_ede))", 2077 .test = alg_test_aead, 2078 .fips_allowed = 1, 2079 .suite = { 2080 .aead = { 2081 .enc = { 2082 .vecs = 2083 hmac_sha384_des3_ede_cbc_enc_tv_temp, 2084 .count = 2085 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC 2086 } 2087 } 2088 } 2089 }, { 2090 .alg = "authenc(hmac(sha512),cbc(aes))", 2091 .test = alg_test_aead, 2092 .fips_allowed = 1, 2093 .suite = { 2094 .aead = { 2095 .enc = { 2096 .vecs = 2097 hmac_sha512_aes_cbc_enc_tv_temp, 2098 .count = 2099 HMAC_SHA512_AES_CBC_ENC_TEST_VEC 2100 } 2101 } 2102 } 2103 }, { 2104 .alg = "authenc(hmac(sha512),cbc(des))", 2105 .test = alg_test_aead, 2106 .fips_allowed = 1, 2107 .suite = { 2108 .aead = { 2109 .enc = { 2110 .vecs = 2111 hmac_sha512_des_cbc_enc_tv_temp, 2112 .count = 2113 HMAC_SHA512_DES_CBC_ENC_TEST_VEC 2114 } 2115 } 2116 } 2117 }, { 2118 .alg = "authenc(hmac(sha512),cbc(des3_ede))", 2119 .test = alg_test_aead, 2120 .fips_allowed = 1, 2121 .suite = { 2122 .aead = { 2123 .enc = { 2124 .vecs = 2125 hmac_sha512_des3_ede_cbc_enc_tv_temp, 2126 .count = 2127 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC 2128 } 2129 } 2130 } 2131 }, { 2132 .alg = "cbc(aes)", 2133 .test = alg_test_skcipher, 2134 .fips_allowed = 1, 2135 .suite = { 2136 .cipher = { 2137 .enc = { 2138 .vecs = aes_cbc_enc_tv_template, 2139 .count = AES_CBC_ENC_TEST_VECTORS 2140 }, 2141 .dec = { 2142 .vecs = aes_cbc_dec_tv_template, 2143 .count = AES_CBC_DEC_TEST_VECTORS 2144 } 2145 } 2146 } 2147 }, { 2148 .alg = "cbc(anubis)", 2149 .test = alg_test_skcipher, 2150 .suite = { 2151 .cipher = { 2152 .enc = { 2153 .vecs = anubis_cbc_enc_tv_template, 2154 .count = ANUBIS_CBC_ENC_TEST_VECTORS 2155 }, 2156 .dec = { 2157 .vecs = anubis_cbc_dec_tv_template, 2158 .count = ANUBIS_CBC_DEC_TEST_VECTORS 2159 } 2160 } 2161 } 2162 }, { 2163 .alg = "cbc(blowfish)", 2164 .test = alg_test_skcipher, 2165 .suite = { 2166 .cipher = { 2167 .enc = { 2168 .vecs = bf_cbc_enc_tv_template, 2169 .count = BF_CBC_ENC_TEST_VECTORS 2170 }, 2171 .dec = { 2172 .vecs = bf_cbc_dec_tv_template, 2173 .count = BF_CBC_DEC_TEST_VECTORS 2174 } 2175 } 2176 } 2177 }, { 2178 .alg = "cbc(camellia)", 2179 .test = alg_test_skcipher, 2180 .suite = { 2181 .cipher = { 2182 .enc = { 2183 .vecs = camellia_cbc_enc_tv_template, 2184 .count = CAMELLIA_CBC_ENC_TEST_VECTORS 2185 }, 2186 .dec = { 2187 .vecs = camellia_cbc_dec_tv_template, 2188 .count = CAMELLIA_CBC_DEC_TEST_VECTORS 2189 } 2190 } 2191 } 2192 }, { 2193 .alg = "cbc(cast5)", 2194 .test = alg_test_skcipher, 2195 .suite = { 2196 .cipher = { 2197 .enc = { 2198 .vecs = cast5_cbc_enc_tv_template, 2199 .count = CAST5_CBC_ENC_TEST_VECTORS 2200 }, 2201 .dec = { 2202 .vecs = cast5_cbc_dec_tv_template, 2203 .count = CAST5_CBC_DEC_TEST_VECTORS 2204 } 2205 } 2206 } 2207 }, { 2208 .alg = "cbc(cast6)", 2209 .test = alg_test_skcipher, 2210 .suite = { 2211 .cipher = { 2212 .enc = { 2213 .vecs = cast6_cbc_enc_tv_template, 2214 .count = CAST6_CBC_ENC_TEST_VECTORS 2215 }, 2216 .dec = { 2217 .vecs = cast6_cbc_dec_tv_template, 2218 .count = CAST6_CBC_DEC_TEST_VECTORS 2219 } 2220 } 2221 } 2222 }, { 2223 .alg = "cbc(des)", 2224 .test = alg_test_skcipher, 2225 .suite = { 2226 .cipher = { 2227 .enc = { 2228 .vecs = des_cbc_enc_tv_template, 2229 .count = DES_CBC_ENC_TEST_VECTORS 2230 }, 2231 .dec = { 2232 .vecs = des_cbc_dec_tv_template, 2233 .count = DES_CBC_DEC_TEST_VECTORS 2234 } 2235 } 2236 } 2237 }, { 2238 .alg = "cbc(des3_ede)", 2239 .test = alg_test_skcipher, 2240 .fips_allowed = 1, 2241 .suite = { 2242 .cipher = { 2243 .enc = { 2244 .vecs = des3_ede_cbc_enc_tv_template, 2245 .count = DES3_EDE_CBC_ENC_TEST_VECTORS 2246 }, 2247 .dec = { 2248 .vecs = des3_ede_cbc_dec_tv_template, 2249 .count = DES3_EDE_CBC_DEC_TEST_VECTORS 2250 } 2251 } 2252 } 2253 }, { 2254 .alg = "cbc(serpent)", 2255 .test = alg_test_skcipher, 2256 .suite = { 2257 .cipher = { 2258 .enc = { 2259 .vecs = serpent_cbc_enc_tv_template, 2260 .count = SERPENT_CBC_ENC_TEST_VECTORS 2261 }, 2262 .dec = { 2263 .vecs = serpent_cbc_dec_tv_template, 2264 .count = SERPENT_CBC_DEC_TEST_VECTORS 2265 } 2266 } 2267 } 2268 }, { 2269 .alg = "cbc(twofish)", 2270 .test = alg_test_skcipher, 2271 .suite = { 2272 .cipher = { 2273 .enc = { 2274 .vecs = tf_cbc_enc_tv_template, 2275 .count = TF_CBC_ENC_TEST_VECTORS 2276 }, 2277 .dec = { 2278 .vecs = tf_cbc_dec_tv_template, 2279 .count = TF_CBC_DEC_TEST_VECTORS 2280 } 2281 } 2282 } 2283 }, { 2284 .alg = "ccm(aes)", 2285 .test = alg_test_aead, 2286 .fips_allowed = 1, 2287 .suite = { 2288 .aead = { 2289 .enc = { 2290 .vecs = aes_ccm_enc_tv_template, 2291 .count = AES_CCM_ENC_TEST_VECTORS 2292 }, 2293 .dec = { 2294 .vecs = aes_ccm_dec_tv_template, 2295 .count = AES_CCM_DEC_TEST_VECTORS 2296 } 2297 } 2298 } 2299 }, { 2300 .alg = "cmac(aes)", 2301 .test = alg_test_hash, 2302 .suite = { 2303 .hash = { 2304 .vecs = aes_cmac128_tv_template, 2305 .count = CMAC_AES_TEST_VECTORS 2306 } 2307 } 2308 }, { 2309 .alg = "cmac(des3_ede)", 2310 .test = alg_test_hash, 2311 .suite = { 2312 .hash = { 2313 .vecs = des3_ede_cmac64_tv_template, 2314 .count = CMAC_DES3_EDE_TEST_VECTORS 2315 } 2316 } 2317 }, { 2318 .alg = "compress_null", 2319 .test = alg_test_null, 2320 }, { 2321 .alg = "crc32c", 2322 .test = alg_test_crc32c, 2323 .fips_allowed = 1, 2324 .suite = { 2325 .hash = { 2326 .vecs = crc32c_tv_template, 2327 .count = CRC32C_TEST_VECTORS 2328 } 2329 } 2330 }, { 2331 .alg = "crct10dif", 2332 .test = alg_test_hash, 2333 .fips_allowed = 1, 2334 .suite = { 2335 .hash = { 2336 .vecs = crct10dif_tv_template, 2337 .count = CRCT10DIF_TEST_VECTORS 2338 } 2339 } 2340 }, { 2341 .alg = "cryptd(__driver-cbc-aes-aesni)", 2342 .test = alg_test_null, 2343 .fips_allowed = 1, 2344 }, { 2345 .alg = "cryptd(__driver-cbc-camellia-aesni)", 2346 .test = alg_test_null, 2347 }, { 2348 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)", 2349 .test = alg_test_null, 2350 }, { 2351 .alg = "cryptd(__driver-cbc-serpent-avx2)", 2352 .test = alg_test_null, 2353 }, { 2354 .alg = "cryptd(__driver-ecb-aes-aesni)", 2355 .test = alg_test_null, 2356 .fips_allowed = 1, 2357 }, { 2358 .alg = "cryptd(__driver-ecb-camellia-aesni)", 2359 .test = alg_test_null, 2360 }, { 2361 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)", 2362 .test = alg_test_null, 2363 }, { 2364 .alg = "cryptd(__driver-ecb-cast5-avx)", 2365 .test = alg_test_null, 2366 }, { 2367 .alg = "cryptd(__driver-ecb-cast6-avx)", 2368 .test = alg_test_null, 2369 }, { 2370 .alg = "cryptd(__driver-ecb-serpent-avx)", 2371 .test = alg_test_null, 2372 }, { 2373 .alg = "cryptd(__driver-ecb-serpent-avx2)", 2374 .test = alg_test_null, 2375 }, { 2376 .alg = "cryptd(__driver-ecb-serpent-sse2)", 2377 .test = alg_test_null, 2378 }, { 2379 .alg = "cryptd(__driver-ecb-twofish-avx)", 2380 .test = alg_test_null, 2381 }, { 2382 .alg = "cryptd(__driver-gcm-aes-aesni)", 2383 .test = alg_test_null, 2384 .fips_allowed = 1, 2385 }, { 2386 .alg = "cryptd(__ghash-pclmulqdqni)", 2387 .test = alg_test_null, 2388 .fips_allowed = 1, 2389 }, { 2390 .alg = "ctr(aes)", 2391 .test = alg_test_skcipher, 2392 .fips_allowed = 1, 2393 .suite = { 2394 .cipher = { 2395 .enc = { 2396 .vecs = aes_ctr_enc_tv_template, 2397 .count = AES_CTR_ENC_TEST_VECTORS 2398 }, 2399 .dec = { 2400 .vecs = aes_ctr_dec_tv_template, 2401 .count = AES_CTR_DEC_TEST_VECTORS 2402 } 2403 } 2404 } 2405 }, { 2406 .alg = "ctr(blowfish)", 2407 .test = alg_test_skcipher, 2408 .suite = { 2409 .cipher = { 2410 .enc = { 2411 .vecs = bf_ctr_enc_tv_template, 2412 .count = BF_CTR_ENC_TEST_VECTORS 2413 }, 2414 .dec = { 2415 .vecs = bf_ctr_dec_tv_template, 2416 .count = BF_CTR_DEC_TEST_VECTORS 2417 } 2418 } 2419 } 2420 }, { 2421 .alg = "ctr(camellia)", 2422 .test = alg_test_skcipher, 2423 .suite = { 2424 .cipher = { 2425 .enc = { 2426 .vecs = camellia_ctr_enc_tv_template, 2427 .count = CAMELLIA_CTR_ENC_TEST_VECTORS 2428 }, 2429 .dec = { 2430 .vecs = camellia_ctr_dec_tv_template, 2431 .count = CAMELLIA_CTR_DEC_TEST_VECTORS 2432 } 2433 } 2434 } 2435 }, { 2436 .alg = "ctr(cast5)", 2437 .test = alg_test_skcipher, 2438 .suite = { 2439 .cipher = { 2440 .enc = { 2441 .vecs = cast5_ctr_enc_tv_template, 2442 .count = CAST5_CTR_ENC_TEST_VECTORS 2443 }, 2444 .dec = { 2445 .vecs = cast5_ctr_dec_tv_template, 2446 .count = CAST5_CTR_DEC_TEST_VECTORS 2447 } 2448 } 2449 } 2450 }, { 2451 .alg = "ctr(cast6)", 2452 .test = alg_test_skcipher, 2453 .suite = { 2454 .cipher = { 2455 .enc = { 2456 .vecs = cast6_ctr_enc_tv_template, 2457 .count = CAST6_CTR_ENC_TEST_VECTORS 2458 }, 2459 .dec = { 2460 .vecs = cast6_ctr_dec_tv_template, 2461 .count = CAST6_CTR_DEC_TEST_VECTORS 2462 } 2463 } 2464 } 2465 }, { 2466 .alg = "ctr(des)", 2467 .test = alg_test_skcipher, 2468 .suite = { 2469 .cipher = { 2470 .enc = { 2471 .vecs = des_ctr_enc_tv_template, 2472 .count = DES_CTR_ENC_TEST_VECTORS 2473 }, 2474 .dec = { 2475 .vecs = des_ctr_dec_tv_template, 2476 .count = DES_CTR_DEC_TEST_VECTORS 2477 } 2478 } 2479 } 2480 }, { 2481 .alg = "ctr(des3_ede)", 2482 .test = alg_test_skcipher, 2483 .suite = { 2484 .cipher = { 2485 .enc = { 2486 .vecs = des3_ede_ctr_enc_tv_template, 2487 .count = DES3_EDE_CTR_ENC_TEST_VECTORS 2488 }, 2489 .dec = { 2490 .vecs = des3_ede_ctr_dec_tv_template, 2491 .count = DES3_EDE_CTR_DEC_TEST_VECTORS 2492 } 2493 } 2494 } 2495 }, { 2496 .alg = "ctr(serpent)", 2497 .test = alg_test_skcipher, 2498 .suite = { 2499 .cipher = { 2500 .enc = { 2501 .vecs = serpent_ctr_enc_tv_template, 2502 .count = SERPENT_CTR_ENC_TEST_VECTORS 2503 }, 2504 .dec = { 2505 .vecs = serpent_ctr_dec_tv_template, 2506 .count = SERPENT_CTR_DEC_TEST_VECTORS 2507 } 2508 } 2509 } 2510 }, { 2511 .alg = "ctr(twofish)", 2512 .test = alg_test_skcipher, 2513 .suite = { 2514 .cipher = { 2515 .enc = { 2516 .vecs = tf_ctr_enc_tv_template, 2517 .count = TF_CTR_ENC_TEST_VECTORS 2518 }, 2519 .dec = { 2520 .vecs = tf_ctr_dec_tv_template, 2521 .count = TF_CTR_DEC_TEST_VECTORS 2522 } 2523 } 2524 } 2525 }, { 2526 .alg = "cts(cbc(aes))", 2527 .test = alg_test_skcipher, 2528 .suite = { 2529 .cipher = { 2530 .enc = { 2531 .vecs = cts_mode_enc_tv_template, 2532 .count = CTS_MODE_ENC_TEST_VECTORS 2533 }, 2534 .dec = { 2535 .vecs = cts_mode_dec_tv_template, 2536 .count = CTS_MODE_DEC_TEST_VECTORS 2537 } 2538 } 2539 } 2540 }, { 2541 .alg = "deflate", 2542 .test = alg_test_comp, 2543 .fips_allowed = 1, 2544 .suite = { 2545 .comp = { 2546 .comp = { 2547 .vecs = deflate_comp_tv_template, 2548 .count = DEFLATE_COMP_TEST_VECTORS 2549 }, 2550 .decomp = { 2551 .vecs = deflate_decomp_tv_template, 2552 .count = DEFLATE_DECOMP_TEST_VECTORS 2553 } 2554 } 2555 } 2556 }, { 2557 .alg = "digest_null", 2558 .test = alg_test_null, 2559 }, { 2560 .alg = "drbg_nopr_ctr_aes128", 2561 .test = alg_test_drbg, 2562 .fips_allowed = 1, 2563 .suite = { 2564 .drbg = { 2565 .vecs = drbg_nopr_ctr_aes128_tv_template, 2566 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template) 2567 } 2568 } 2569 }, { 2570 .alg = "drbg_nopr_ctr_aes192", 2571 .test = alg_test_drbg, 2572 .fips_allowed = 1, 2573 .suite = { 2574 .drbg = { 2575 .vecs = drbg_nopr_ctr_aes192_tv_template, 2576 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template) 2577 } 2578 } 2579 }, { 2580 .alg = "drbg_nopr_ctr_aes256", 2581 .test = alg_test_drbg, 2582 .fips_allowed = 1, 2583 .suite = { 2584 .drbg = { 2585 .vecs = drbg_nopr_ctr_aes256_tv_template, 2586 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template) 2587 } 2588 } 2589 }, { 2590 /* 2591 * There is no need to specifically test the DRBG with every 2592 * backend cipher -- covered by drbg_nopr_hmac_sha256 test 2593 */ 2594 .alg = "drbg_nopr_hmac_sha1", 2595 .fips_allowed = 1, 2596 .test = alg_test_null, 2597 }, { 2598 .alg = "drbg_nopr_hmac_sha256", 2599 .test = alg_test_drbg, 2600 .fips_allowed = 1, 2601 .suite = { 2602 .drbg = { 2603 .vecs = drbg_nopr_hmac_sha256_tv_template, 2604 .count = 2605 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template) 2606 } 2607 } 2608 }, { 2609 /* covered by drbg_nopr_hmac_sha256 test */ 2610 .alg = "drbg_nopr_hmac_sha384", 2611 .fips_allowed = 1, 2612 .test = alg_test_null, 2613 }, { 2614 .alg = "drbg_nopr_hmac_sha512", 2615 .test = alg_test_null, 2616 .fips_allowed = 1, 2617 }, { 2618 .alg = "drbg_nopr_sha1", 2619 .fips_allowed = 1, 2620 .test = alg_test_null, 2621 }, { 2622 .alg = "drbg_nopr_sha256", 2623 .test = alg_test_drbg, 2624 .fips_allowed = 1, 2625 .suite = { 2626 .drbg = { 2627 .vecs = drbg_nopr_sha256_tv_template, 2628 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template) 2629 } 2630 } 2631 }, { 2632 /* covered by drbg_nopr_sha256 test */ 2633 .alg = "drbg_nopr_sha384", 2634 .fips_allowed = 1, 2635 .test = alg_test_null, 2636 }, { 2637 .alg = "drbg_nopr_sha512", 2638 .fips_allowed = 1, 2639 .test = alg_test_null, 2640 }, { 2641 .alg = "drbg_pr_ctr_aes128", 2642 .test = alg_test_drbg, 2643 .fips_allowed = 1, 2644 .suite = { 2645 .drbg = { 2646 .vecs = drbg_pr_ctr_aes128_tv_template, 2647 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template) 2648 } 2649 } 2650 }, { 2651 /* covered by drbg_pr_ctr_aes128 test */ 2652 .alg = "drbg_pr_ctr_aes192", 2653 .fips_allowed = 1, 2654 .test = alg_test_null, 2655 }, { 2656 .alg = "drbg_pr_ctr_aes256", 2657 .fips_allowed = 1, 2658 .test = alg_test_null, 2659 }, { 2660 .alg = "drbg_pr_hmac_sha1", 2661 .fips_allowed = 1, 2662 .test = alg_test_null, 2663 }, { 2664 .alg = "drbg_pr_hmac_sha256", 2665 .test = alg_test_drbg, 2666 .fips_allowed = 1, 2667 .suite = { 2668 .drbg = { 2669 .vecs = drbg_pr_hmac_sha256_tv_template, 2670 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template) 2671 } 2672 } 2673 }, { 2674 /* covered by drbg_pr_hmac_sha256 test */ 2675 .alg = "drbg_pr_hmac_sha384", 2676 .fips_allowed = 1, 2677 .test = alg_test_null, 2678 }, { 2679 .alg = "drbg_pr_hmac_sha512", 2680 .test = alg_test_null, 2681 .fips_allowed = 1, 2682 }, { 2683 .alg = "drbg_pr_sha1", 2684 .fips_allowed = 1, 2685 .test = alg_test_null, 2686 }, { 2687 .alg = "drbg_pr_sha256", 2688 .test = alg_test_drbg, 2689 .fips_allowed = 1, 2690 .suite = { 2691 .drbg = { 2692 .vecs = drbg_pr_sha256_tv_template, 2693 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template) 2694 } 2695 } 2696 }, { 2697 /* covered by drbg_pr_sha256 test */ 2698 .alg = "drbg_pr_sha384", 2699 .fips_allowed = 1, 2700 .test = alg_test_null, 2701 }, { 2702 .alg = "drbg_pr_sha512", 2703 .fips_allowed = 1, 2704 .test = alg_test_null, 2705 }, { 2706 .alg = "ecb(__aes-aesni)", 2707 .test = alg_test_null, 2708 .fips_allowed = 1, 2709 }, { 2710 .alg = "ecb(aes)", 2711 .test = alg_test_skcipher, 2712 .fips_allowed = 1, 2713 .suite = { 2714 .cipher = { 2715 .enc = { 2716 .vecs = aes_enc_tv_template, 2717 .count = AES_ENC_TEST_VECTORS 2718 }, 2719 .dec = { 2720 .vecs = aes_dec_tv_template, 2721 .count = AES_DEC_TEST_VECTORS 2722 } 2723 } 2724 } 2725 }, { 2726 .alg = "ecb(anubis)", 2727 .test = alg_test_skcipher, 2728 .suite = { 2729 .cipher = { 2730 .enc = { 2731 .vecs = anubis_enc_tv_template, 2732 .count = ANUBIS_ENC_TEST_VECTORS 2733 }, 2734 .dec = { 2735 .vecs = anubis_dec_tv_template, 2736 .count = ANUBIS_DEC_TEST_VECTORS 2737 } 2738 } 2739 } 2740 }, { 2741 .alg = "ecb(arc4)", 2742 .test = alg_test_skcipher, 2743 .suite = { 2744 .cipher = { 2745 .enc = { 2746 .vecs = arc4_enc_tv_template, 2747 .count = ARC4_ENC_TEST_VECTORS 2748 }, 2749 .dec = { 2750 .vecs = arc4_dec_tv_template, 2751 .count = ARC4_DEC_TEST_VECTORS 2752 } 2753 } 2754 } 2755 }, { 2756 .alg = "ecb(blowfish)", 2757 .test = alg_test_skcipher, 2758 .suite = { 2759 .cipher = { 2760 .enc = { 2761 .vecs = bf_enc_tv_template, 2762 .count = BF_ENC_TEST_VECTORS 2763 }, 2764 .dec = { 2765 .vecs = bf_dec_tv_template, 2766 .count = BF_DEC_TEST_VECTORS 2767 } 2768 } 2769 } 2770 }, { 2771 .alg = "ecb(camellia)", 2772 .test = alg_test_skcipher, 2773 .suite = { 2774 .cipher = { 2775 .enc = { 2776 .vecs = camellia_enc_tv_template, 2777 .count = CAMELLIA_ENC_TEST_VECTORS 2778 }, 2779 .dec = { 2780 .vecs = camellia_dec_tv_template, 2781 .count = CAMELLIA_DEC_TEST_VECTORS 2782 } 2783 } 2784 } 2785 }, { 2786 .alg = "ecb(cast5)", 2787 .test = alg_test_skcipher, 2788 .suite = { 2789 .cipher = { 2790 .enc = { 2791 .vecs = cast5_enc_tv_template, 2792 .count = CAST5_ENC_TEST_VECTORS 2793 }, 2794 .dec = { 2795 .vecs = cast5_dec_tv_template, 2796 .count = CAST5_DEC_TEST_VECTORS 2797 } 2798 } 2799 } 2800 }, { 2801 .alg = "ecb(cast6)", 2802 .test = alg_test_skcipher, 2803 .suite = { 2804 .cipher = { 2805 .enc = { 2806 .vecs = cast6_enc_tv_template, 2807 .count = CAST6_ENC_TEST_VECTORS 2808 }, 2809 .dec = { 2810 .vecs = cast6_dec_tv_template, 2811 .count = CAST6_DEC_TEST_VECTORS 2812 } 2813 } 2814 } 2815 }, { 2816 .alg = "ecb(cipher_null)", 2817 .test = alg_test_null, 2818 }, { 2819 .alg = "ecb(des)", 2820 .test = alg_test_skcipher, 2821 .fips_allowed = 1, 2822 .suite = { 2823 .cipher = { 2824 .enc = { 2825 .vecs = des_enc_tv_template, 2826 .count = DES_ENC_TEST_VECTORS 2827 }, 2828 .dec = { 2829 .vecs = des_dec_tv_template, 2830 .count = DES_DEC_TEST_VECTORS 2831 } 2832 } 2833 } 2834 }, { 2835 .alg = "ecb(des3_ede)", 2836 .test = alg_test_skcipher, 2837 .fips_allowed = 1, 2838 .suite = { 2839 .cipher = { 2840 .enc = { 2841 .vecs = des3_ede_enc_tv_template, 2842 .count = DES3_EDE_ENC_TEST_VECTORS 2843 }, 2844 .dec = { 2845 .vecs = des3_ede_dec_tv_template, 2846 .count = DES3_EDE_DEC_TEST_VECTORS 2847 } 2848 } 2849 } 2850 }, { 2851 .alg = "ecb(fcrypt)", 2852 .test = alg_test_skcipher, 2853 .suite = { 2854 .cipher = { 2855 .enc = { 2856 .vecs = fcrypt_pcbc_enc_tv_template, 2857 .count = 1 2858 }, 2859 .dec = { 2860 .vecs = fcrypt_pcbc_dec_tv_template, 2861 .count = 1 2862 } 2863 } 2864 } 2865 }, { 2866 .alg = "ecb(khazad)", 2867 .test = alg_test_skcipher, 2868 .suite = { 2869 .cipher = { 2870 .enc = { 2871 .vecs = khazad_enc_tv_template, 2872 .count = KHAZAD_ENC_TEST_VECTORS 2873 }, 2874 .dec = { 2875 .vecs = khazad_dec_tv_template, 2876 .count = KHAZAD_DEC_TEST_VECTORS 2877 } 2878 } 2879 } 2880 }, { 2881 .alg = "ecb(seed)", 2882 .test = alg_test_skcipher, 2883 .suite = { 2884 .cipher = { 2885 .enc = { 2886 .vecs = seed_enc_tv_template, 2887 .count = SEED_ENC_TEST_VECTORS 2888 }, 2889 .dec = { 2890 .vecs = seed_dec_tv_template, 2891 .count = SEED_DEC_TEST_VECTORS 2892 } 2893 } 2894 } 2895 }, { 2896 .alg = "ecb(serpent)", 2897 .test = alg_test_skcipher, 2898 .suite = { 2899 .cipher = { 2900 .enc = { 2901 .vecs = serpent_enc_tv_template, 2902 .count = SERPENT_ENC_TEST_VECTORS 2903 }, 2904 .dec = { 2905 .vecs = serpent_dec_tv_template, 2906 .count = SERPENT_DEC_TEST_VECTORS 2907 } 2908 } 2909 } 2910 }, { 2911 .alg = "ecb(tea)", 2912 .test = alg_test_skcipher, 2913 .suite = { 2914 .cipher = { 2915 .enc = { 2916 .vecs = tea_enc_tv_template, 2917 .count = TEA_ENC_TEST_VECTORS 2918 }, 2919 .dec = { 2920 .vecs = tea_dec_tv_template, 2921 .count = TEA_DEC_TEST_VECTORS 2922 } 2923 } 2924 } 2925 }, { 2926 .alg = "ecb(tnepres)", 2927 .test = alg_test_skcipher, 2928 .suite = { 2929 .cipher = { 2930 .enc = { 2931 .vecs = tnepres_enc_tv_template, 2932 .count = TNEPRES_ENC_TEST_VECTORS 2933 }, 2934 .dec = { 2935 .vecs = tnepres_dec_tv_template, 2936 .count = TNEPRES_DEC_TEST_VECTORS 2937 } 2938 } 2939 } 2940 }, { 2941 .alg = "ecb(twofish)", 2942 .test = alg_test_skcipher, 2943 .suite = { 2944 .cipher = { 2945 .enc = { 2946 .vecs = tf_enc_tv_template, 2947 .count = TF_ENC_TEST_VECTORS 2948 }, 2949 .dec = { 2950 .vecs = tf_dec_tv_template, 2951 .count = TF_DEC_TEST_VECTORS 2952 } 2953 } 2954 } 2955 }, { 2956 .alg = "ecb(xeta)", 2957 .test = alg_test_skcipher, 2958 .suite = { 2959 .cipher = { 2960 .enc = { 2961 .vecs = xeta_enc_tv_template, 2962 .count = XETA_ENC_TEST_VECTORS 2963 }, 2964 .dec = { 2965 .vecs = xeta_dec_tv_template, 2966 .count = XETA_DEC_TEST_VECTORS 2967 } 2968 } 2969 } 2970 }, { 2971 .alg = "ecb(xtea)", 2972 .test = alg_test_skcipher, 2973 .suite = { 2974 .cipher = { 2975 .enc = { 2976 .vecs = xtea_enc_tv_template, 2977 .count = XTEA_ENC_TEST_VECTORS 2978 }, 2979 .dec = { 2980 .vecs = xtea_dec_tv_template, 2981 .count = XTEA_DEC_TEST_VECTORS 2982 } 2983 } 2984 } 2985 }, { 2986 .alg = "gcm(aes)", 2987 .test = alg_test_aead, 2988 .fips_allowed = 1, 2989 .suite = { 2990 .aead = { 2991 .enc = { 2992 .vecs = aes_gcm_enc_tv_template, 2993 .count = AES_GCM_ENC_TEST_VECTORS 2994 }, 2995 .dec = { 2996 .vecs = aes_gcm_dec_tv_template, 2997 .count = AES_GCM_DEC_TEST_VECTORS 2998 } 2999 } 3000 } 3001 }, { 3002 .alg = "ghash", 3003 .test = alg_test_hash, 3004 .fips_allowed = 1, 3005 .suite = { 3006 .hash = { 3007 .vecs = ghash_tv_template, 3008 .count = GHASH_TEST_VECTORS 3009 } 3010 } 3011 }, { 3012 .alg = "hmac(crc32)", 3013 .test = alg_test_hash, 3014 .suite = { 3015 .hash = { 3016 .vecs = bfin_crc_tv_template, 3017 .count = BFIN_CRC_TEST_VECTORS 3018 } 3019 } 3020 }, { 3021 .alg = "hmac(md5)", 3022 .test = alg_test_hash, 3023 .suite = { 3024 .hash = { 3025 .vecs = hmac_md5_tv_template, 3026 .count = HMAC_MD5_TEST_VECTORS 3027 } 3028 } 3029 }, { 3030 .alg = "hmac(rmd128)", 3031 .test = alg_test_hash, 3032 .suite = { 3033 .hash = { 3034 .vecs = hmac_rmd128_tv_template, 3035 .count = HMAC_RMD128_TEST_VECTORS 3036 } 3037 } 3038 }, { 3039 .alg = "hmac(rmd160)", 3040 .test = alg_test_hash, 3041 .suite = { 3042 .hash = { 3043 .vecs = hmac_rmd160_tv_template, 3044 .count = HMAC_RMD160_TEST_VECTORS 3045 } 3046 } 3047 }, { 3048 .alg = "hmac(sha1)", 3049 .test = alg_test_hash, 3050 .fips_allowed = 1, 3051 .suite = { 3052 .hash = { 3053 .vecs = hmac_sha1_tv_template, 3054 .count = HMAC_SHA1_TEST_VECTORS 3055 } 3056 } 3057 }, { 3058 .alg = "hmac(sha224)", 3059 .test = alg_test_hash, 3060 .fips_allowed = 1, 3061 .suite = { 3062 .hash = { 3063 .vecs = hmac_sha224_tv_template, 3064 .count = HMAC_SHA224_TEST_VECTORS 3065 } 3066 } 3067 }, { 3068 .alg = "hmac(sha256)", 3069 .test = alg_test_hash, 3070 .fips_allowed = 1, 3071 .suite = { 3072 .hash = { 3073 .vecs = hmac_sha256_tv_template, 3074 .count = HMAC_SHA256_TEST_VECTORS 3075 } 3076 } 3077 }, { 3078 .alg = "hmac(sha384)", 3079 .test = alg_test_hash, 3080 .fips_allowed = 1, 3081 .suite = { 3082 .hash = { 3083 .vecs = hmac_sha384_tv_template, 3084 .count = HMAC_SHA384_TEST_VECTORS 3085 } 3086 } 3087 }, { 3088 .alg = "hmac(sha512)", 3089 .test = alg_test_hash, 3090 .fips_allowed = 1, 3091 .suite = { 3092 .hash = { 3093 .vecs = hmac_sha512_tv_template, 3094 .count = HMAC_SHA512_TEST_VECTORS 3095 } 3096 } 3097 }, { 3098 .alg = "lrw(aes)", 3099 .test = alg_test_skcipher, 3100 .suite = { 3101 .cipher = { 3102 .enc = { 3103 .vecs = aes_lrw_enc_tv_template, 3104 .count = AES_LRW_ENC_TEST_VECTORS 3105 }, 3106 .dec = { 3107 .vecs = aes_lrw_dec_tv_template, 3108 .count = AES_LRW_DEC_TEST_VECTORS 3109 } 3110 } 3111 } 3112 }, { 3113 .alg = "lrw(camellia)", 3114 .test = alg_test_skcipher, 3115 .suite = { 3116 .cipher = { 3117 .enc = { 3118 .vecs = camellia_lrw_enc_tv_template, 3119 .count = CAMELLIA_LRW_ENC_TEST_VECTORS 3120 }, 3121 .dec = { 3122 .vecs = camellia_lrw_dec_tv_template, 3123 .count = CAMELLIA_LRW_DEC_TEST_VECTORS 3124 } 3125 } 3126 } 3127 }, { 3128 .alg = "lrw(cast6)", 3129 .test = alg_test_skcipher, 3130 .suite = { 3131 .cipher = { 3132 .enc = { 3133 .vecs = cast6_lrw_enc_tv_template, 3134 .count = CAST6_LRW_ENC_TEST_VECTORS 3135 }, 3136 .dec = { 3137 .vecs = cast6_lrw_dec_tv_template, 3138 .count = CAST6_LRW_DEC_TEST_VECTORS 3139 } 3140 } 3141 } 3142 }, { 3143 .alg = "lrw(serpent)", 3144 .test = alg_test_skcipher, 3145 .suite = { 3146 .cipher = { 3147 .enc = { 3148 .vecs = serpent_lrw_enc_tv_template, 3149 .count = SERPENT_LRW_ENC_TEST_VECTORS 3150 }, 3151 .dec = { 3152 .vecs = serpent_lrw_dec_tv_template, 3153 .count = SERPENT_LRW_DEC_TEST_VECTORS 3154 } 3155 } 3156 } 3157 }, { 3158 .alg = "lrw(twofish)", 3159 .test = alg_test_skcipher, 3160 .suite = { 3161 .cipher = { 3162 .enc = { 3163 .vecs = tf_lrw_enc_tv_template, 3164 .count = TF_LRW_ENC_TEST_VECTORS 3165 }, 3166 .dec = { 3167 .vecs = tf_lrw_dec_tv_template, 3168 .count = TF_LRW_DEC_TEST_VECTORS 3169 } 3170 } 3171 } 3172 }, { 3173 .alg = "lz4", 3174 .test = alg_test_comp, 3175 .fips_allowed = 1, 3176 .suite = { 3177 .comp = { 3178 .comp = { 3179 .vecs = lz4_comp_tv_template, 3180 .count = LZ4_COMP_TEST_VECTORS 3181 }, 3182 .decomp = { 3183 .vecs = lz4_decomp_tv_template, 3184 .count = LZ4_DECOMP_TEST_VECTORS 3185 } 3186 } 3187 } 3188 }, { 3189 .alg = "lz4hc", 3190 .test = alg_test_comp, 3191 .fips_allowed = 1, 3192 .suite = { 3193 .comp = { 3194 .comp = { 3195 .vecs = lz4hc_comp_tv_template, 3196 .count = LZ4HC_COMP_TEST_VECTORS 3197 }, 3198 .decomp = { 3199 .vecs = lz4hc_decomp_tv_template, 3200 .count = LZ4HC_DECOMP_TEST_VECTORS 3201 } 3202 } 3203 } 3204 }, { 3205 .alg = "lzo", 3206 .test = alg_test_comp, 3207 .fips_allowed = 1, 3208 .suite = { 3209 .comp = { 3210 .comp = { 3211 .vecs = lzo_comp_tv_template, 3212 .count = LZO_COMP_TEST_VECTORS 3213 }, 3214 .decomp = { 3215 .vecs = lzo_decomp_tv_template, 3216 .count = LZO_DECOMP_TEST_VECTORS 3217 } 3218 } 3219 } 3220 }, { 3221 .alg = "md4", 3222 .test = alg_test_hash, 3223 .suite = { 3224 .hash = { 3225 .vecs = md4_tv_template, 3226 .count = MD4_TEST_VECTORS 3227 } 3228 } 3229 }, { 3230 .alg = "md5", 3231 .test = alg_test_hash, 3232 .suite = { 3233 .hash = { 3234 .vecs = md5_tv_template, 3235 .count = MD5_TEST_VECTORS 3236 } 3237 } 3238 }, { 3239 .alg = "michael_mic", 3240 .test = alg_test_hash, 3241 .suite = { 3242 .hash = { 3243 .vecs = michael_mic_tv_template, 3244 .count = MICHAEL_MIC_TEST_VECTORS 3245 } 3246 } 3247 }, { 3248 .alg = "ofb(aes)", 3249 .test = alg_test_skcipher, 3250 .fips_allowed = 1, 3251 .suite = { 3252 .cipher = { 3253 .enc = { 3254 .vecs = aes_ofb_enc_tv_template, 3255 .count = AES_OFB_ENC_TEST_VECTORS 3256 }, 3257 .dec = { 3258 .vecs = aes_ofb_dec_tv_template, 3259 .count = AES_OFB_DEC_TEST_VECTORS 3260 } 3261 } 3262 } 3263 }, { 3264 .alg = "pcbc(fcrypt)", 3265 .test = alg_test_skcipher, 3266 .suite = { 3267 .cipher = { 3268 .enc = { 3269 .vecs = fcrypt_pcbc_enc_tv_template, 3270 .count = FCRYPT_ENC_TEST_VECTORS 3271 }, 3272 .dec = { 3273 .vecs = fcrypt_pcbc_dec_tv_template, 3274 .count = FCRYPT_DEC_TEST_VECTORS 3275 } 3276 } 3277 } 3278 }, { 3279 .alg = "rfc3686(ctr(aes))", 3280 .test = alg_test_skcipher, 3281 .fips_allowed = 1, 3282 .suite = { 3283 .cipher = { 3284 .enc = { 3285 .vecs = aes_ctr_rfc3686_enc_tv_template, 3286 .count = AES_CTR_3686_ENC_TEST_VECTORS 3287 }, 3288 .dec = { 3289 .vecs = aes_ctr_rfc3686_dec_tv_template, 3290 .count = AES_CTR_3686_DEC_TEST_VECTORS 3291 } 3292 } 3293 } 3294 }, { 3295 .alg = "rfc4106(gcm(aes))", 3296 .test = alg_test_aead, 3297 .fips_allowed = 1, 3298 .suite = { 3299 .aead = { 3300 .enc = { 3301 .vecs = aes_gcm_rfc4106_enc_tv_template, 3302 .count = AES_GCM_4106_ENC_TEST_VECTORS 3303 }, 3304 .dec = { 3305 .vecs = aes_gcm_rfc4106_dec_tv_template, 3306 .count = AES_GCM_4106_DEC_TEST_VECTORS 3307 } 3308 } 3309 } 3310 }, { 3311 .alg = "rfc4309(ccm(aes))", 3312 .test = alg_test_aead, 3313 .fips_allowed = 1, 3314 .suite = { 3315 .aead = { 3316 .enc = { 3317 .vecs = aes_ccm_rfc4309_enc_tv_template, 3318 .count = AES_CCM_4309_ENC_TEST_VECTORS 3319 }, 3320 .dec = { 3321 .vecs = aes_ccm_rfc4309_dec_tv_template, 3322 .count = AES_CCM_4309_DEC_TEST_VECTORS 3323 } 3324 } 3325 } 3326 }, { 3327 .alg = "rfc4543(gcm(aes))", 3328 .test = alg_test_aead, 3329 .suite = { 3330 .aead = { 3331 .enc = { 3332 .vecs = aes_gcm_rfc4543_enc_tv_template, 3333 .count = AES_GCM_4543_ENC_TEST_VECTORS 3334 }, 3335 .dec = { 3336 .vecs = aes_gcm_rfc4543_dec_tv_template, 3337 .count = AES_GCM_4543_DEC_TEST_VECTORS 3338 }, 3339 } 3340 } 3341 }, { 3342 .alg = "rmd128", 3343 .test = alg_test_hash, 3344 .suite = { 3345 .hash = { 3346 .vecs = rmd128_tv_template, 3347 .count = RMD128_TEST_VECTORS 3348 } 3349 } 3350 }, { 3351 .alg = "rmd160", 3352 .test = alg_test_hash, 3353 .suite = { 3354 .hash = { 3355 .vecs = rmd160_tv_template, 3356 .count = RMD160_TEST_VECTORS 3357 } 3358 } 3359 }, { 3360 .alg = "rmd256", 3361 .test = alg_test_hash, 3362 .suite = { 3363 .hash = { 3364 .vecs = rmd256_tv_template, 3365 .count = RMD256_TEST_VECTORS 3366 } 3367 } 3368 }, { 3369 .alg = "rmd320", 3370 .test = alg_test_hash, 3371 .suite = { 3372 .hash = { 3373 .vecs = rmd320_tv_template, 3374 .count = RMD320_TEST_VECTORS 3375 } 3376 } 3377 }, { 3378 .alg = "salsa20", 3379 .test = alg_test_skcipher, 3380 .suite = { 3381 .cipher = { 3382 .enc = { 3383 .vecs = salsa20_stream_enc_tv_template, 3384 .count = SALSA20_STREAM_ENC_TEST_VECTORS 3385 } 3386 } 3387 } 3388 }, { 3389 .alg = "sha1", 3390 .test = alg_test_hash, 3391 .fips_allowed = 1, 3392 .suite = { 3393 .hash = { 3394 .vecs = sha1_tv_template, 3395 .count = SHA1_TEST_VECTORS 3396 } 3397 } 3398 }, { 3399 .alg = "sha224", 3400 .test = alg_test_hash, 3401 .fips_allowed = 1, 3402 .suite = { 3403 .hash = { 3404 .vecs = sha224_tv_template, 3405 .count = SHA224_TEST_VECTORS 3406 } 3407 } 3408 }, { 3409 .alg = "sha256", 3410 .test = alg_test_hash, 3411 .fips_allowed = 1, 3412 .suite = { 3413 .hash = { 3414 .vecs = sha256_tv_template, 3415 .count = SHA256_TEST_VECTORS 3416 } 3417 } 3418 }, { 3419 .alg = "sha384", 3420 .test = alg_test_hash, 3421 .fips_allowed = 1, 3422 .suite = { 3423 .hash = { 3424 .vecs = sha384_tv_template, 3425 .count = SHA384_TEST_VECTORS 3426 } 3427 } 3428 }, { 3429 .alg = "sha512", 3430 .test = alg_test_hash, 3431 .fips_allowed = 1, 3432 .suite = { 3433 .hash = { 3434 .vecs = sha512_tv_template, 3435 .count = SHA512_TEST_VECTORS 3436 } 3437 } 3438 }, { 3439 .alg = "tgr128", 3440 .test = alg_test_hash, 3441 .suite = { 3442 .hash = { 3443 .vecs = tgr128_tv_template, 3444 .count = TGR128_TEST_VECTORS 3445 } 3446 } 3447 }, { 3448 .alg = "tgr160", 3449 .test = alg_test_hash, 3450 .suite = { 3451 .hash = { 3452 .vecs = tgr160_tv_template, 3453 .count = TGR160_TEST_VECTORS 3454 } 3455 } 3456 }, { 3457 .alg = "tgr192", 3458 .test = alg_test_hash, 3459 .suite = { 3460 .hash = { 3461 .vecs = tgr192_tv_template, 3462 .count = TGR192_TEST_VECTORS 3463 } 3464 } 3465 }, { 3466 .alg = "vmac(aes)", 3467 .test = alg_test_hash, 3468 .suite = { 3469 .hash = { 3470 .vecs = aes_vmac128_tv_template, 3471 .count = VMAC_AES_TEST_VECTORS 3472 } 3473 } 3474 }, { 3475 .alg = "wp256", 3476 .test = alg_test_hash, 3477 .suite = { 3478 .hash = { 3479 .vecs = wp256_tv_template, 3480 .count = WP256_TEST_VECTORS 3481 } 3482 } 3483 }, { 3484 .alg = "wp384", 3485 .test = alg_test_hash, 3486 .suite = { 3487 .hash = { 3488 .vecs = wp384_tv_template, 3489 .count = WP384_TEST_VECTORS 3490 } 3491 } 3492 }, { 3493 .alg = "wp512", 3494 .test = alg_test_hash, 3495 .suite = { 3496 .hash = { 3497 .vecs = wp512_tv_template, 3498 .count = WP512_TEST_VECTORS 3499 } 3500 } 3501 }, { 3502 .alg = "xcbc(aes)", 3503 .test = alg_test_hash, 3504 .suite = { 3505 .hash = { 3506 .vecs = aes_xcbc128_tv_template, 3507 .count = XCBC_AES_TEST_VECTORS 3508 } 3509 } 3510 }, { 3511 .alg = "xts(aes)", 3512 .test = alg_test_skcipher, 3513 .fips_allowed = 1, 3514 .suite = { 3515 .cipher = { 3516 .enc = { 3517 .vecs = aes_xts_enc_tv_template, 3518 .count = AES_XTS_ENC_TEST_VECTORS 3519 }, 3520 .dec = { 3521 .vecs = aes_xts_dec_tv_template, 3522 .count = AES_XTS_DEC_TEST_VECTORS 3523 } 3524 } 3525 } 3526 }, { 3527 .alg = "xts(camellia)", 3528 .test = alg_test_skcipher, 3529 .suite = { 3530 .cipher = { 3531 .enc = { 3532 .vecs = camellia_xts_enc_tv_template, 3533 .count = CAMELLIA_XTS_ENC_TEST_VECTORS 3534 }, 3535 .dec = { 3536 .vecs = camellia_xts_dec_tv_template, 3537 .count = CAMELLIA_XTS_DEC_TEST_VECTORS 3538 } 3539 } 3540 } 3541 }, { 3542 .alg = "xts(cast6)", 3543 .test = alg_test_skcipher, 3544 .suite = { 3545 .cipher = { 3546 .enc = { 3547 .vecs = cast6_xts_enc_tv_template, 3548 .count = CAST6_XTS_ENC_TEST_VECTORS 3549 }, 3550 .dec = { 3551 .vecs = cast6_xts_dec_tv_template, 3552 .count = CAST6_XTS_DEC_TEST_VECTORS 3553 } 3554 } 3555 } 3556 }, { 3557 .alg = "xts(serpent)", 3558 .test = alg_test_skcipher, 3559 .suite = { 3560 .cipher = { 3561 .enc = { 3562 .vecs = serpent_xts_enc_tv_template, 3563 .count = SERPENT_XTS_ENC_TEST_VECTORS 3564 }, 3565 .dec = { 3566 .vecs = serpent_xts_dec_tv_template, 3567 .count = SERPENT_XTS_DEC_TEST_VECTORS 3568 } 3569 } 3570 } 3571 }, { 3572 .alg = "xts(twofish)", 3573 .test = alg_test_skcipher, 3574 .suite = { 3575 .cipher = { 3576 .enc = { 3577 .vecs = tf_xts_enc_tv_template, 3578 .count = TF_XTS_ENC_TEST_VECTORS 3579 }, 3580 .dec = { 3581 .vecs = tf_xts_dec_tv_template, 3582 .count = TF_XTS_DEC_TEST_VECTORS 3583 } 3584 } 3585 } 3586 }, { 3587 .alg = "zlib", 3588 .test = alg_test_pcomp, 3589 .fips_allowed = 1, 3590 .suite = { 3591 .pcomp = { 3592 .comp = { 3593 .vecs = zlib_comp_tv_template, 3594 .count = ZLIB_COMP_TEST_VECTORS 3595 }, 3596 .decomp = { 3597 .vecs = zlib_decomp_tv_template, 3598 .count = ZLIB_DECOMP_TEST_VECTORS 3599 } 3600 } 3601 } 3602 } 3603 }; 3604 3605 static bool alg_test_descs_checked; 3606 3607 static void alg_test_descs_check_order(void) 3608 { 3609 int i; 3610 3611 /* only check once */ 3612 if (alg_test_descs_checked) 3613 return; 3614 3615 alg_test_descs_checked = true; 3616 3617 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) { 3618 int diff = strcmp(alg_test_descs[i - 1].alg, 3619 alg_test_descs[i].alg); 3620 3621 if (WARN_ON(diff > 0)) { 3622 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n", 3623 alg_test_descs[i - 1].alg, 3624 alg_test_descs[i].alg); 3625 } 3626 3627 if (WARN_ON(diff == 0)) { 3628 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n", 3629 alg_test_descs[i].alg); 3630 } 3631 } 3632 } 3633 3634 static int alg_find_test(const char *alg) 3635 { 3636 int start = 0; 3637 int end = ARRAY_SIZE(alg_test_descs); 3638 3639 while (start < end) { 3640 int i = (start + end) / 2; 3641 int diff = strcmp(alg_test_descs[i].alg, alg); 3642 3643 if (diff > 0) { 3644 end = i; 3645 continue; 3646 } 3647 3648 if (diff < 0) { 3649 start = i + 1; 3650 continue; 3651 } 3652 3653 return i; 3654 } 3655 3656 return -1; 3657 } 3658 3659 int alg_test(const char *driver, const char *alg, u32 type, u32 mask) 3660 { 3661 int i; 3662 int j; 3663 int rc; 3664 3665 alg_test_descs_check_order(); 3666 3667 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) { 3668 char nalg[CRYPTO_MAX_ALG_NAME]; 3669 3670 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >= 3671 sizeof(nalg)) 3672 return -ENAMETOOLONG; 3673 3674 i = alg_find_test(nalg); 3675 if (i < 0) 3676 goto notest; 3677 3678 if (fips_enabled && !alg_test_descs[i].fips_allowed) 3679 goto non_fips_alg; 3680 3681 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask); 3682 goto test_done; 3683 } 3684 3685 i = alg_find_test(alg); 3686 j = alg_find_test(driver); 3687 if (i < 0 && j < 0) 3688 goto notest; 3689 3690 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) || 3691 (j >= 0 && !alg_test_descs[j].fips_allowed))) 3692 goto non_fips_alg; 3693 3694 rc = 0; 3695 if (i >= 0) 3696 rc |= alg_test_descs[i].test(alg_test_descs + i, driver, 3697 type, mask); 3698 if (j >= 0 && j != i) 3699 rc |= alg_test_descs[j].test(alg_test_descs + j, driver, 3700 type, mask); 3701 3702 test_done: 3703 if (fips_enabled && rc) 3704 panic("%s: %s alg self test failed in fips mode!\n", driver, alg); 3705 3706 if (fips_enabled && !rc) 3707 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg); 3708 3709 return rc; 3710 3711 notest: 3712 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver); 3713 return 0; 3714 non_fips_alg: 3715 return -EINVAL; 3716 } 3717 3718 #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */ 3719 3720 EXPORT_SYMBOL_GPL(alg_test); 3721