aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'crypto')
-rw-r--r--crypto/tcrypt.c346
1 files changed, 200 insertions, 146 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index b6d4b5ce00a3..97ec2bdfcce0 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -98,8 +98,8 @@ static void tcrypt_complete(struct crypto_async_request *req, int err)
98 complete(&res->completion); 98 complete(&res->completion);
99} 99}
100 100
101static void test_hash(char *algo, struct hash_testvec *template, 101static int test_hash(char *algo, struct hash_testvec *template,
102 unsigned int tcount) 102 unsigned int tcount)
103{ 103{
104 unsigned int i, j, k, temp; 104 unsigned int i, j, k, temp;
105 struct scatterlist sg[8]; 105 struct scatterlist sg[8];
@@ -110,27 +110,26 @@ static void test_hash(char *algo, struct hash_testvec *template,
110 int ret; 110 int ret;
111 void *hash_buff; 111 void *hash_buff;
112 112
113 printk("\ntesting %s\n", algo);
114
115 init_completion(&tresult.completion); 113 init_completion(&tresult.completion);
116 114
117 tfm = crypto_alloc_ahash(algo, 0, 0); 115 tfm = crypto_alloc_ahash(algo, 0, 0);
118 if (IS_ERR(tfm)) { 116 if (IS_ERR(tfm)) {
119 printk("failed to load transform for %s: %ld\n", algo, 117 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
120 PTR_ERR(tfm)); 118 "%ld\n", algo, PTR_ERR(tfm));
121 return; 119 return PTR_ERR(tfm);
122 } 120 }
123 121
124 req = ahash_request_alloc(tfm, GFP_KERNEL); 122 req = ahash_request_alloc(tfm, GFP_KERNEL);
125 if (!req) { 123 if (!req) {
126 printk(KERN_ERR "failed to allocate request for %s\n", algo); 124 printk(KERN_ERR "alg: hash: Failed to allocate request for "
125 "%s\n", algo);
126 ret = -ENOMEM;
127 goto out_noreq; 127 goto out_noreq;
128 } 128 }
129 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 129 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
130 tcrypt_complete, &tresult); 130 tcrypt_complete, &tresult);
131 131
132 for (i = 0; i < tcount; i++) { 132 for (i = 0; i < tcount; i++) {
133 printk("test %u:\n", i + 1);
134 memset(result, 0, 64); 133 memset(result, 0, 64);
135 134
136 hash_buff = xbuf[0]; 135 hash_buff = xbuf[0];
@@ -143,7 +142,9 @@ static void test_hash(char *algo, struct hash_testvec *template,
143 ret = crypto_ahash_setkey(tfm, template[i].key, 142 ret = crypto_ahash_setkey(tfm, template[i].key,
144 template[i].ksize); 143 template[i].ksize);
145 if (ret) { 144 if (ret) {
146 printk("setkey() failed ret=%d\n", ret); 145 printk(KERN_ERR "alg: hash: setkey failed on "
146 "test %d for %s: ret=%d\n", i + 1, algo,
147 -ret);
147 goto out; 148 goto out;
148 } 149 }
149 } 150 }
@@ -163,24 +164,25 @@ static void test_hash(char *algo, struct hash_testvec *template,
163 } 164 }
164 /* fall through */ 165 /* fall through */
165 default: 166 default:
166 printk("digest () failed ret=%d\n", ret); 167 printk(KERN_ERR "alg: hash: digest failed on test %d "
168 "for %s: ret=%d\n", i + 1, algo, -ret);
167 goto out; 169 goto out;
168 } 170 }
169 171
170 hexdump(result, crypto_ahash_digestsize(tfm)); 172 if (memcmp(result, template[i].digest,
171 printk("%s\n", 173 crypto_ahash_digestsize(tfm))) {
172 memcmp(result, template[i].digest, 174 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
173 crypto_ahash_digestsize(tfm)) ? 175 i + 1, algo);
174 "fail" : "pass"); 176 hexdump(result, crypto_ahash_digestsize(tfm));
177 ret = -EINVAL;
178 goto out;
179 }
175 } 180 }
176 181
177 printk("testing %s across pages\n", algo);
178
179 j = 0; 182 j = 0;
180 for (i = 0; i < tcount; i++) { 183 for (i = 0; i < tcount; i++) {
181 if (template[i].np) { 184 if (template[i].np) {
182 j++; 185 j++;
183 printk("test %u:\n", j);
184 memset(result, 0, 64); 186 memset(result, 0, 64);
185 187
186 temp = 0; 188 temp = 0;
@@ -201,7 +203,10 @@ static void test_hash(char *algo, struct hash_testvec *template,
201 template[i].ksize); 203 template[i].ksize);
202 204
203 if (ret) { 205 if (ret) {
204 printk("setkey() failed ret=%d\n", ret); 206 printk(KERN_ERR "alg: hash: setkey "
207 "failed on chunking test %d "
208 "for %s: ret=%d\n", j, algo,
209 -ret);
205 goto out; 210 goto out;
206 } 211 }
207 } 212 }
@@ -222,28 +227,37 @@ static void test_hash(char *algo, struct hash_testvec *template,
222 } 227 }
223 /* fall through */ 228 /* fall through */
224 default: 229 default:
225 printk("digest () failed ret=%d\n", ret); 230 printk(KERN_ERR "alg: hash: digest failed "
231 "on chunking test %d for %s: "
232 "ret=%d\n", j, algo, -ret);
226 goto out; 233 goto out;
227 } 234 }
228 235
229 hexdump(result, crypto_ahash_digestsize(tfm)); 236 if (memcmp(result, template[i].digest,
230 printk("%s\n", 237 crypto_ahash_digestsize(tfm))) {
231 memcmp(result, template[i].digest, 238 printk(KERN_ERR "alg: hash: Chunking test %d "
232 crypto_ahash_digestsize(tfm)) ? 239 "failed for %s\n", j, algo);
233 "fail" : "pass"); 240 hexdump(result, crypto_ahash_digestsize(tfm));
241 ret = -EINVAL;
242 goto out;
243 }
234 } 244 }
235 } 245 }
236 246
247 ret = 0;
248
237out: 249out:
238 ahash_request_free(req); 250 ahash_request_free(req);
239out_noreq: 251out_noreq:
240 crypto_free_ahash(tfm); 252 crypto_free_ahash(tfm);
253 return ret;
241} 254}
242 255
243static void test_aead(char *algo, int enc, struct aead_testvec *template, 256static int test_aead(char *algo, int enc, struct aead_testvec *template,
244 unsigned int tcount) 257 unsigned int tcount)
245{ 258{
246 unsigned int ret, i, j, k, n, temp; 259 unsigned int i, j, k, n, temp;
260 int ret = 0;
247 char *q; 261 char *q;
248 struct crypto_aead *tfm; 262 struct crypto_aead *tfm;
249 char *key; 263 char *key;
@@ -262,21 +276,21 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template,
262 else 276 else
263 e = "decryption"; 277 e = "decryption";
264 278
265 printk(KERN_INFO "\ntesting %s %s\n", algo, e);
266
267 init_completion(&result.completion); 279 init_completion(&result.completion);
268 280
269 tfm = crypto_alloc_aead(algo, 0, 0); 281 tfm = crypto_alloc_aead(algo, 0, 0);
270 282
271 if (IS_ERR(tfm)) { 283 if (IS_ERR(tfm)) {
272 printk(KERN_INFO "failed to load transform for %s: %ld\n", 284 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
273 algo, PTR_ERR(tfm)); 285 "%ld\n", algo, PTR_ERR(tfm));
274 return; 286 return PTR_ERR(tfm);
275 } 287 }
276 288
277 req = aead_request_alloc(tfm, GFP_KERNEL); 289 req = aead_request_alloc(tfm, GFP_KERNEL);
278 if (!req) { 290 if (!req) {
279 printk(KERN_INFO "failed to allocate request for %s\n", algo); 291 printk(KERN_ERR "alg: aead: Failed to allocate request for "
292 "%s\n", algo);
293 ret = -ENOMEM;
280 goto out; 294 goto out;
281 } 295 }
282 296
@@ -285,8 +299,7 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template,
285 299
286 for (i = 0, j = 0; i < tcount; i++) { 300 for (i = 0, j = 0; i < tcount; i++) {
287 if (!template[i].np) { 301 if (!template[i].np) {
288 printk(KERN_INFO "test %u (%d bit key):\n", 302 j++;
289 ++j, template[i].klen * 8);
290 303
291 /* some tepmplates have no input data but they will 304 /* some tepmplates have no input data but they will
292 * touch input 305 * touch input
@@ -310,21 +323,21 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template,
310 323
311 ret = crypto_aead_setkey(tfm, key, 324 ret = crypto_aead_setkey(tfm, key,
312 template[i].klen); 325 template[i].klen);
313 if (ret) { 326 if (!ret == template[i].fail) {
314 printk(KERN_INFO "setkey() failed flags=%x\n", 327 printk(KERN_ERR "alg: aead: setkey failed on "
328 "test %d for %s: flags=%x\n", j, algo,
315 crypto_aead_get_flags(tfm)); 329 crypto_aead_get_flags(tfm));
316 330 goto out;
317 if (!template[i].fail) 331 } else if (ret)
318 continue; 332 continue;
319 }
320 333
321 authsize = abs(template[i].rlen - template[i].ilen); 334 authsize = abs(template[i].rlen - template[i].ilen);
322 ret = crypto_aead_setauthsize(tfm, authsize); 335 ret = crypto_aead_setauthsize(tfm, authsize);
323 if (ret) { 336 if (ret) {
324 printk(KERN_INFO 337 printk(KERN_ERR "alg: aead: Failed to set "
325 "failed to set authsize = %u\n", 338 "authsize to %u on test %d for %s\n",
326 authsize); 339 authsize, j, algo);
327 continue; 340 goto out;
328 } 341 }
329 342
330 sg_init_one(&sg[0], input, 343 sg_init_one(&sg[0], input,
@@ -354,26 +367,25 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template,
354 } 367 }
355 /* fall through */ 368 /* fall through */
356 default: 369 default:
357 printk(KERN_INFO "%s () failed err=%d\n", 370 printk(KERN_ERR "alg: aead: %s failed on test "
358 e, -ret); 371 "%d for %s: ret=%d\n", e, j, algo, -ret);
359 continue; 372 goto out;
360 } 373 }
361 374
362 q = input; 375 q = input;
363 hexdump(q, template[i].rlen); 376 if (memcmp(q, template[i].result, template[i].rlen)) {
364 377 printk(KERN_ERR "alg: aead: Test %d failed on "
365 printk(KERN_INFO "enc/dec: %s\n", 378 "%s for %s\n", j, e, algo);
366 memcmp(q, template[i].result, 379 hexdump(q, template[i].rlen);
367 template[i].rlen) ? "fail" : "pass"); 380 ret = -EINVAL;
381 goto out;
382 }
368 } 383 }
369 } 384 }
370 385
371 printk(KERN_INFO "\ntesting %s %s across pages (chunking)\n", algo, e);
372
373 for (i = 0, j = 0; i < tcount; i++) { 386 for (i = 0, j = 0; i < tcount; i++) {
374 if (template[i].np) { 387 if (template[i].np) {
375 printk(KERN_INFO "test %u (%d bit key):\n", 388 j++;
376 ++j, template[i].klen * 8);
377 389
378 if (template[i].iv) 390 if (template[i].iv)
379 memcpy(iv, template[i].iv, MAX_IVLEN); 391 memcpy(iv, template[i].iv, MAX_IVLEN);
@@ -387,16 +399,17 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template,
387 key = template[i].key; 399 key = template[i].key;
388 400
389 ret = crypto_aead_setkey(tfm, key, template[i].klen); 401 ret = crypto_aead_setkey(tfm, key, template[i].klen);
390 if (ret) { 402 if (!ret == template[i].fail) {
391 printk(KERN_INFO "setkey() failed flags=%x\n", 403 printk(KERN_ERR "alg: aead: setkey failed on "
392 crypto_aead_get_flags(tfm)); 404 "chunk test %d for %s: flags=%x\n", j,
393 405 algo, crypto_aead_get_flags(tfm));
394 if (!template[i].fail) 406 goto out;
395 goto out; 407 } else if (ret)
396 } 408 continue;
397 409
398 authsize = abs(template[i].rlen - template[i].ilen); 410 authsize = abs(template[i].rlen - template[i].ilen);
399 411
412 ret = -EINVAL;
400 sg_init_table(sg, template[i].np); 413 sg_init_table(sg, template[i].np);
401 for (k = 0, temp = 0; k < template[i].np; k++) { 414 for (k = 0, temp = 0; k < template[i].np; k++) {
402 if (WARN_ON(offset_in_page(IDX[k]) + 415 if (WARN_ON(offset_in_page(IDX[k]) +
@@ -421,17 +434,19 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template,
421 434
422 ret = crypto_aead_setauthsize(tfm, authsize); 435 ret = crypto_aead_setauthsize(tfm, authsize);
423 if (ret) { 436 if (ret) {
424 printk(KERN_INFO 437 printk(KERN_ERR "alg: aead: Failed to set "
425 "failed to set authsize = %u\n", 438 "authsize to %u on chunk test %d for "
426 authsize); 439 "%s\n", authsize, j, algo);
427 goto out; 440 goto out;
428 } 441 }
429 442
430 if (enc) { 443 if (enc) {
431 if (WARN_ON(sg[k - 1].offset + 444 if (WARN_ON(sg[k - 1].offset +
432 sg[k - 1].length + authsize > 445 sg[k - 1].length + authsize >
433 PAGE_SIZE)) 446 PAGE_SIZE)) {
447 ret = -EINVAL;
434 goto out; 448 goto out;
449 }
435 450
436 sg[k - 1].length += authsize; 451 sg[k - 1].length += authsize;
437 } 452 }
@@ -470,23 +485,28 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template,
470 } 485 }
471 /* fall through */ 486 /* fall through */
472 default: 487 default:
473 printk(KERN_INFO "%s () failed err=%d\n", 488 printk(KERN_ERR "alg: aead: %s failed on "
474 e, -ret); 489 "chunk test %d for %s: ret=%d\n", e, j,
490 algo, -ret);
475 goto out; 491 goto out;
476 } 492 }
477 493
494 ret = -EINVAL;
478 for (k = 0, temp = 0; k < template[i].np; k++) { 495 for (k = 0, temp = 0; k < template[i].np; k++) {
479 printk(KERN_INFO "page %u\n", k);
480 q = xbuf[IDX[k] >> PAGE_SHIFT] + 496 q = xbuf[IDX[k] >> PAGE_SHIFT] +
481 offset_in_page(IDX[k]); 497 offset_in_page(IDX[k]);
482 498
483 n = template[i].tap[k]; 499 n = template[i].tap[k];
484 if (k == template[i].np - 1) 500 if (k == template[i].np - 1)
485 n += enc ? authsize : -authsize; 501 n += enc ? authsize : -authsize;
486 hexdump(q, n); 502
487 printk(KERN_INFO "%s\n", 503 if (memcmp(q, template[i].result + temp, n)) {
488 memcmp(q, template[i].result + temp, n) ? 504 printk(KERN_ERR "alg: aead: Chunk "
489 "fail" : "pass"); 505 "test %d failed on %s at page "
506 "%u for %s\n", j, e, k, algo);
507 hexdump(q, n);
508 goto out;
509 }
490 510
491 q += n; 511 q += n;
492 if (k == template[i].np - 1 && !enc) { 512 if (k == template[i].np - 1 && !enc) {
@@ -501,9 +521,13 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template,
501 ; 521 ;
502 } 522 }
503 if (n) { 523 if (n) {
504 printk("Result buffer corruption %u " 524 printk(KERN_ERR "alg: aead: Result "
505 "bytes:\n", n); 525 "buffer corruption in chunk "
526 "test %d on %s at page %u for "
527 "%s: %u bytes:\n", j, e, k,
528 algo, n);
506 hexdump(q, n); 529 hexdump(q, n);
530 goto out;
507 } 531 }
508 532
509 temp += template[i].tap[k]; 533 temp += template[i].tap[k];
@@ -511,15 +535,19 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template,
511 } 535 }
512 } 536 }
513 537
538 ret = 0;
539
514out: 540out:
515 crypto_free_aead(tfm); 541 crypto_free_aead(tfm);
516 aead_request_free(req); 542 aead_request_free(req);
543 return ret;
517} 544}
518 545
519static void test_cipher(char *algo, int enc, 546static int test_cipher(char *algo, int enc,
520 struct cipher_testvec *template, unsigned int tcount) 547 struct cipher_testvec *template, unsigned int tcount)
521{ 548{
522 unsigned int ret, i, j, k, n, temp; 549 unsigned int i, j, k, n, temp;
550 int ret;
523 char *q; 551 char *q;
524 struct crypto_ablkcipher *tfm; 552 struct crypto_ablkcipher *tfm;
525 struct ablkcipher_request *req; 553 struct ablkcipher_request *req;
@@ -534,20 +562,20 @@ static void test_cipher(char *algo, int enc,
534 else 562 else
535 e = "decryption"; 563 e = "decryption";
536 564
537 printk("\ntesting %s %s\n", algo, e);
538
539 init_completion(&result.completion); 565 init_completion(&result.completion);
540 tfm = crypto_alloc_ablkcipher(algo, 0, 0); 566 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
541 567
542 if (IS_ERR(tfm)) { 568 if (IS_ERR(tfm)) {
543 printk("failed to load transform for %s: %ld\n", algo, 569 printk(KERN_ERR "alg: cipher: Failed to load transform for "
544 PTR_ERR(tfm)); 570 "%s: %ld\n", algo, PTR_ERR(tfm));
545 return; 571 return PTR_ERR(tfm);
546 } 572 }
547 573
548 req = ablkcipher_request_alloc(tfm, GFP_KERNEL); 574 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
549 if (!req) { 575 if (!req) {
550 printk("failed to allocate request for %s\n", algo); 576 printk(KERN_ERR "alg: cipher: Failed to allocate request for "
577 "%s\n", algo);
578 ret = -ENOMEM;
551 goto out; 579 goto out;
552 } 580 }
553 581
@@ -563,8 +591,6 @@ static void test_cipher(char *algo, int enc,
563 591
564 if (!(template[i].np)) { 592 if (!(template[i].np)) {
565 j++; 593 j++;
566 printk("test %u (%d bit key):\n",
567 j, template[i].klen * 8);
568 594
569 data = xbuf[0]; 595 data = xbuf[0];
570 memcpy(data, template[i].input, template[i].ilen); 596 memcpy(data, template[i].input, template[i].ilen);
@@ -576,13 +602,13 @@ static void test_cipher(char *algo, int enc,
576 602
577 ret = crypto_ablkcipher_setkey(tfm, template[i].key, 603 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
578 template[i].klen); 604 template[i].klen);
579 if (ret) { 605 if (!ret == template[i].fail) {
580 printk("setkey() failed flags=%x\n", 606 printk(KERN_ERR "alg: cipher: setkey failed "
581 crypto_ablkcipher_get_flags(tfm)); 607 "on test %d for %s: flags=%x\n", j,
582 608 algo, crypto_ablkcipher_get_flags(tfm));
583 if (!template[i].fail) 609 goto out;
584 goto out; 610 } else if (ret)
585 } 611 continue;
586 612
587 sg_init_one(&sg[0], data, template[i].ilen); 613 sg_init_one(&sg[0], data, template[i].ilen);
588 614
@@ -605,21 +631,23 @@ static void test_cipher(char *algo, int enc,
605 } 631 }
606 /* fall through */ 632 /* fall through */
607 default: 633 default:
608 printk("%s () failed err=%d\n", e, -ret); 634 printk(KERN_ERR "alg: cipher: %s failed on "
635 "test %d for %s: ret=%d\n", e, j, algo,
636 -ret);
609 goto out; 637 goto out;
610 } 638 }
611 639
612 q = data; 640 q = data;
613 hexdump(q, template[i].rlen); 641 if (memcmp(q, template[i].result, template[i].rlen)) {
614 642 printk(KERN_ERR "alg: cipher: Test %d failed "
615 printk("%s\n", 643 "on %s for %s\n", j, e, algo);
616 memcmp(q, template[i].result, 644 hexdump(q, template[i].rlen);
617 template[i].rlen) ? "fail" : "pass"); 645 ret = -EINVAL;
646 goto out;
647 }
618 } 648 }
619 } 649 }
620 650
621 printk("\ntesting %s %s across pages (chunking)\n", algo, e);
622
623 j = 0; 651 j = 0;
624 for (i = 0; i < tcount; i++) { 652 for (i = 0; i < tcount; i++) {
625 653
@@ -630,8 +658,6 @@ static void test_cipher(char *algo, int enc,
630 658
631 if (template[i].np) { 659 if (template[i].np) {
632 j++; 660 j++;
633 printk("test %u (%d bit key):\n",
634 j, template[i].klen * 8);
635 661
636 crypto_ablkcipher_clear_flags(tfm, ~0); 662 crypto_ablkcipher_clear_flags(tfm, ~0);
637 if (template[i].wk) 663 if (template[i].wk)
@@ -640,15 +666,17 @@ static void test_cipher(char *algo, int enc,
640 666
641 ret = crypto_ablkcipher_setkey(tfm, template[i].key, 667 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
642 template[i].klen); 668 template[i].klen);
643 if (ret) { 669 if (!ret == template[i].fail) {
644 printk("setkey() failed flags=%x\n", 670 printk(KERN_ERR "alg: cipher: setkey failed "
645 crypto_ablkcipher_get_flags(tfm)); 671 "on chunk test %d for %s: flags=%x\n",
646 672 j, algo,
647 if (!template[i].fail) 673 crypto_ablkcipher_get_flags(tfm));
648 goto out; 674 goto out;
649 } 675 } else if (ret)
676 continue;
650 677
651 temp = 0; 678 temp = 0;
679 ret = -EINVAL;
652 sg_init_table(sg, template[i].np); 680 sg_init_table(sg, template[i].np);
653 for (k = 0; k < template[i].np; k++) { 681 for (k = 0; k < template[i].np; k++) {
654 if (WARN_ON(offset_in_page(IDX[k]) + 682 if (WARN_ON(offset_in_page(IDX[k]) +
@@ -690,36 +718,50 @@ static void test_cipher(char *algo, int enc,
690 } 718 }
691 /* fall through */ 719 /* fall through */
692 default: 720 default:
693 printk("%s () failed err=%d\n", e, -ret); 721 printk(KERN_ERR "alg: cipher: %s failed on "
722 "chunk test %d for %s: ret=%d\n", e, j,
723 algo, -ret);
694 goto out; 724 goto out;
695 } 725 }
696 726
697 temp = 0; 727 temp = 0;
728 ret = -EINVAL;
698 for (k = 0; k < template[i].np; k++) { 729 for (k = 0; k < template[i].np; k++) {
699 printk("page %u\n", k);
700 q = xbuf[IDX[k] >> PAGE_SHIFT] + 730 q = xbuf[IDX[k] >> PAGE_SHIFT] +
701 offset_in_page(IDX[k]); 731 offset_in_page(IDX[k]);
702 hexdump(q, template[i].tap[k]); 732
703 printk("%s\n", 733 if (memcmp(q, template[i].result + temp,
704 memcmp(q, template[i].result + temp, 734 template[i].tap[k])) {
705 template[i].tap[k]) ? "fail" : 735 printk(KERN_ERR "alg: cipher: Chunk "
706 "pass"); 736 "test %d failed on %s at page "
737 "%u for %s\n", j, e, k, algo);
738 hexdump(q, template[i].tap[k]);
739 goto out;
740 }
707 741
708 q += template[i].tap[k]; 742 q += template[i].tap[k];
709 for (n = 0; offset_in_page(q + n) && q[n]; n++) 743 for (n = 0; offset_in_page(q + n) && q[n]; n++)
710 ; 744 ;
711 if (n) { 745 if (n) {
712 printk("Result buffer corruption %u " 746 printk(KERN_ERR "alg: cipher: "
713 "bytes:\n", n); 747 "Result buffer corruption in "
748 "chunk test %d on %s at page "
749 "%u for %s: %u bytes:\n", j, e,
750 k, algo, n);
714 hexdump(q, n); 751 hexdump(q, n);
752 goto out;
715 } 753 }
716 temp += template[i].tap[k]; 754 temp += template[i].tap[k];
717 } 755 }
718 } 756 }
719 } 757 }
758
759 ret = 0;
760
720out: 761out:
721 crypto_free_ablkcipher(tfm); 762 crypto_free_ablkcipher(tfm);
722 ablkcipher_request_free(req); 763 ablkcipher_request_free(req);
764 return ret;
723} 765}
724 766
725static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, 767static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
@@ -1118,62 +1160,74 @@ out:
1118 crypto_free_hash(tfm); 1160 crypto_free_hash(tfm);
1119} 1161}
1120 1162
1121static void test_comp(char *algo, struct comp_testvec *ctemplate, 1163static int test_comp(char *algo, struct comp_testvec *ctemplate,
1122 struct comp_testvec *dtemplate, int ctcount, int dtcount) 1164 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1123{ 1165{
1124 unsigned int i; 1166 unsigned int i;
1125 char result[COMP_BUF_SIZE]; 1167 char result[COMP_BUF_SIZE];
1126 struct crypto_comp *tfm; 1168 struct crypto_comp *tfm;
1127 1169 int ret;
1128 printk("\ntesting %s compression\n", algo);
1129 1170
1130 tfm = crypto_alloc_comp(algo, 0, CRYPTO_ALG_ASYNC); 1171 tfm = crypto_alloc_comp(algo, 0, CRYPTO_ALG_ASYNC);
1131 if (IS_ERR(tfm)) { 1172 if (IS_ERR(tfm)) {
1132 printk("failed to load transform for %s\n", algo); 1173 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1133 return; 1174 "%ld\n", algo, PTR_ERR(tfm));
1175 return PTR_ERR(tfm);
1134 } 1176 }
1135 1177
1136 for (i = 0; i < ctcount; i++) { 1178 for (i = 0; i < ctcount; i++) {
1137 int ilen, ret, dlen = COMP_BUF_SIZE; 1179 int ilen, dlen = COMP_BUF_SIZE;
1138 1180
1139 printk("test %u:\n", i + 1);
1140 memset(result, 0, sizeof (result)); 1181 memset(result, 0, sizeof (result));
1141 1182
1142 ilen = ctemplate[i].inlen; 1183 ilen = ctemplate[i].inlen;
1143 ret = crypto_comp_compress(tfm, ctemplate[i].input, 1184 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1144 ilen, result, &dlen); 1185 ilen, result, &dlen);
1145 if (ret) { 1186 if (ret) {
1146 printk("fail: ret=%d\n", ret); 1187 printk(KERN_ERR "alg: comp: compression failed "
1147 continue; 1188 "on test %d for %s: ret=%d\n", i + 1, algo,
1189 -ret);
1190 goto out;
1148 } 1191 }
1149 hexdump(result, dlen);
1150 printk("%s (ratio %d:%d)\n",
1151 memcmp(result, ctemplate[i].output, dlen) ? "fail" : "pass",
1152 ilen, dlen);
1153 }
1154 1192
1155 printk("\ntesting %s decompression\n", algo); 1193 if (memcmp(result, ctemplate[i].output, dlen)) {
1194 printk(KERN_ERR "alg: comp: Compression test %d "
1195 "failed for %s\n", i + 1, algo);
1196 hexdump(result, dlen);
1197 ret = -EINVAL;
1198 goto out;
1199 }
1200 }
1156 1201
1157 for (i = 0; i < dtcount; i++) { 1202 for (i = 0; i < dtcount; i++) {
1158 int ilen, ret, dlen = COMP_BUF_SIZE; 1203 int ilen, ret, dlen = COMP_BUF_SIZE;
1159 1204
1160 printk("test %u:\n", i + 1);
1161 memset(result, 0, sizeof (result)); 1205 memset(result, 0, sizeof (result));
1162 1206
1163 ilen = dtemplate[i].inlen; 1207 ilen = dtemplate[i].inlen;
1164 ret = crypto_comp_decompress(tfm, dtemplate[i].input, 1208 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1165 ilen, result, &dlen); 1209 ilen, result, &dlen);
1166 if (ret) { 1210 if (ret) {
1167 printk("fail: ret=%d\n", ret); 1211 printk(KERN_ERR "alg: comp: decompression failed "
1168 continue; 1212 "on test %d for %s: ret=%d\n", i + 1, algo,
1213 -ret);
1214 goto out;
1215 }
1216
1217 if (memcmp(result, dtemplate[i].output, dlen)) {
1218 printk(KERN_ERR "alg: comp: Decompression test %d "
1219 "failed for %s\n", i + 1, algo);
1220 hexdump(result, dlen);
1221 ret = -EINVAL;
1222 goto out;
1169 } 1223 }
1170 hexdump(result, dlen);
1171 printk("%s (ratio %d:%d)\n",
1172 memcmp(result, dtemplate[i].output, dlen) ? "fail" : "pass",
1173 ilen, dlen);
1174 } 1224 }
1175 1225
1226 ret = 0;
1227
1228out:
1176 crypto_free_comp(tfm); 1229 crypto_free_comp(tfm);
1230 return ret;
1177} 1231}
1178 1232
1179static void test_available(void) 1233static void test_available(void)