Mercurial > dropbear
comparison libtomcrypt/testprof/x86_prof.c @ 435:337c45621e81
merge of 'a9b0496634cdd25647b65e585cc3240f3fa699ee'
and 'c22be8b8f570b48e9662dac32c7b3e7148a42206'
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 22 Feb 2007 14:53:49 +0000 |
parents | 0cbe8f6dbf9e |
children | f849a5ca2efc |
comparison
equal
deleted
inserted
replaced
434:0aaaf68e97dc | 435:337c45621e81 |
---|---|
16 | 16 |
17 void tally_results(int type) | 17 void tally_results(int type) |
18 { | 18 { |
19 int x; | 19 int x; |
20 | 20 |
21 // qsort the results | 21 /* qsort the results */ |
22 qsort(results, no_results, sizeof(struct list), &sorter); | 22 qsort(results, no_results, sizeof(struct list), &sorter); |
23 | 23 |
24 fprintf(stderr, "\n"); | 24 fprintf(stderr, "\n"); |
25 if (type == 0) { | 25 if (type == 0) { |
26 for (x = 0; x < no_results; x++) { | 26 for (x = 0; x < no_results; x++) { |
49 return a; | 49 return a; |
50 #elif defined(__i386__) || defined(__x86_64__) | 50 #elif defined(__i386__) || defined(__x86_64__) |
51 ulong64 a; | 51 ulong64 a; |
52 asm __volatile__ ("rdtsc\nmovl %%eax,(%0)\nmovl %%edx,4(%0)\n"::"r"(&a):"%eax","%edx"); | 52 asm __volatile__ ("rdtsc\nmovl %%eax,(%0)\nmovl %%edx,4(%0)\n"::"r"(&a):"%eax","%edx"); |
53 return a; | 53 return a; |
54 #elif defined(LTC_PPC32) || defined(TFM_PPC32) | |
55 unsigned long a, b; | |
56 __asm__ __volatile__ ("mftbu %1 \nmftb %0\n":"=r"(a), "=r"(b)); | |
57 return (((ulong64)b) << 32ULL) | ((ulong64)a); | |
54 #elif defined(__ia64__) /* gcc-IA64 version */ | 58 #elif defined(__ia64__) /* gcc-IA64 version */ |
55 unsigned long result; | 59 unsigned long result; |
56 __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory"); | 60 __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory"); |
57 while (__builtin_expect ((int) result == -1, 0)) | 61 while (__builtin_expect ((int) result == -1, 0)) |
58 __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory"); | 62 __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory"); |
59 return result; | 63 return result; |
64 #elif defined(__sparc__) | |
65 #if defined(__arch64__) | |
66 ulong64 a; | |
67 asm volatile("rd %%tick,%0" : "=r" (a)); | |
68 return a; | |
69 #else | |
70 register unsigned long x, y; | |
71 __asm__ __volatile__ ("rd %%tick, %0; clruw %0, %1; srlx %0, 32, %0" : "=r" (x), "=r" (y) : "0" (x), "1" (y)); | |
72 return ((unsigned long long) x << 32) | y; | |
73 #endif | |
60 #else | 74 #else |
61 return XCLOCK(); | 75 return XCLOCK(); |
62 #endif | 76 #endif |
63 | 77 |
64 // Microsoft and Intel Windows compilers | 78 /* Microsoft and Intel Windows compilers */ |
65 #elif defined _M_IX86 && !defined(LTC_NO_ASM) | 79 #elif defined _M_IX86 && !defined(LTC_NO_ASM) |
66 __asm rdtsc | 80 __asm rdtsc |
67 #elif defined _M_AMD64 && !defined(LTC_NO_ASM) | 81 #elif defined _M_AMD64 && !defined(LTC_NO_ASM) |
68 return __rdtsc (); | 82 return __rdtsc (); |
69 #elif defined _M_IA64 && !defined(LTC_NO_ASM) | 83 #elif defined _M_IA64 && !defined(LTC_NO_ASM) |
157 register_cipher (&khazad_desc); | 171 register_cipher (&khazad_desc); |
158 #endif | 172 #endif |
159 #ifdef ANUBIS | 173 #ifdef ANUBIS |
160 register_cipher (&anubis_desc); | 174 register_cipher (&anubis_desc); |
161 #endif | 175 #endif |
176 #ifdef KSEED | |
177 register_cipher (&kseed_desc); | |
178 #endif | |
179 #ifdef LTC_KASUMI | |
180 register_cipher (&kasumi_desc); | |
181 #endif | |
162 | 182 |
163 #ifdef TIGER | 183 #ifdef TIGER |
164 register_hash (&tiger_desc); | 184 register_hash (&tiger_desc); |
165 #endif | 185 #endif |
166 #ifdef MD2 | 186 #ifdef MD2 |
190 #ifdef RIPEMD128 | 210 #ifdef RIPEMD128 |
191 register_hash (&rmd128_desc); | 211 register_hash (&rmd128_desc); |
192 #endif | 212 #endif |
193 #ifdef RIPEMD160 | 213 #ifdef RIPEMD160 |
194 register_hash (&rmd160_desc); | 214 register_hash (&rmd160_desc); |
215 #endif | |
216 #ifdef RIPEMD256 | |
217 register_hash (&rmd256_desc); | |
218 #endif | |
219 #ifdef RIPEMD320 | |
220 register_hash (&rmd320_desc); | |
195 #endif | 221 #endif |
196 #ifdef WHIRLPOOL | 222 #ifdef WHIRLPOOL |
197 register_hash (&whirlpool_desc); | 223 register_hash (&whirlpool_desc); |
198 #endif | 224 #endif |
199 #ifdef CHC_HASH | 225 #ifdef CHC_HASH |
217 #endif | 243 #endif |
218 #ifdef SOBER128 | 244 #ifdef SOBER128 |
219 register_prng(&sober128_desc); | 245 register_prng(&sober128_desc); |
220 #endif | 246 #endif |
221 | 247 |
222 rng_make_prng(128, find_prng("yarrow"), &yarrow_prng, NULL); | 248 if ((err = rng_make_prng(128, find_prng("yarrow"), &yarrow_prng, NULL)) != CRYPT_OK) { |
249 fprintf(stderr, "rng_make_prng failed: %s\n", error_to_string(err)); | |
250 exit(EXIT_FAILURE); | |
251 } | |
252 | |
223 } | 253 } |
224 | 254 |
225 int time_keysched(void) | 255 int time_keysched(void) |
226 { | 256 { |
227 unsigned long x, y1; | 257 unsigned long x, y1; |
310 | 340 |
311 c1 = (t1 > c1 ? c1 : t1); | 341 c1 = (t1 > c1 ? c1 : t1); |
312 c2 = (t2 > c2 ? c2 : t2); | 342 c2 = (t2 > c2 ? c2 : t2); |
313 } | 343 } |
314 a2 = c2 - c1 - skew; | 344 a2 = c2 - c1 - skew; |
345 ecb_done(&ecb); | |
315 | 346 |
316 results[no_results].id = x; | 347 results[no_results].id = x; |
317 results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length); | 348 results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length); |
318 results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length); | 349 results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length); |
319 results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2; | 350 results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2; |
326 tally_results(1); | 357 tally_results(1); |
327 | 358 |
328 return 0; | 359 return 0; |
329 } | 360 } |
330 | 361 |
331 #ifdef CBC | 362 #ifdef LTC_CBC_MODE |
332 int time_cipher2(void) | 363 int time_cipher2(void) |
333 { | 364 { |
334 unsigned long x, y1; | 365 unsigned long x, y1; |
335 ulong64 t1, t2, c1, c2, a1, a2; | 366 ulong64 t1, t2, c1, c2, a1, a2; |
336 symmetric_CBC cbc; | 367 symmetric_CBC cbc; |
381 | 412 |
382 c1 = (t1 > c1 ? c1 : t1); | 413 c1 = (t1 > c1 ? c1 : t1); |
383 c2 = (t2 > c2 ? c2 : t2); | 414 c2 = (t2 > c2 ? c2 : t2); |
384 } | 415 } |
385 a2 = c2 - c1 - skew; | 416 a2 = c2 - c1 - skew; |
417 cbc_done(&cbc); | |
386 | 418 |
387 results[no_results].id = x; | 419 results[no_results].id = x; |
388 results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length); | 420 results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length); |
389 results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length); | 421 results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length); |
390 results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2; | 422 results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2; |
400 } | 432 } |
401 #else | 433 #else |
402 int time_cipher2(void) { fprintf(stderr, "NO CBC\n"); return 0; } | 434 int time_cipher2(void) { fprintf(stderr, "NO CBC\n"); return 0; } |
403 #endif | 435 #endif |
404 | 436 |
405 #ifdef CTR | 437 #ifdef LTC_CTR_MODE |
406 int time_cipher3(void) | 438 int time_cipher3(void) |
407 { | 439 { |
408 unsigned long x, y1; | 440 unsigned long x, y1; |
409 ulong64 t1, t2, c1, c2, a1, a2; | 441 ulong64 t1, t2, c1, c2, a1, a2; |
410 symmetric_CTR ctr; | 442 symmetric_CTR ctr; |
455 | 487 |
456 c1 = (t1 > c1 ? c1 : t1); | 488 c1 = (t1 > c1 ? c1 : t1); |
457 c2 = (t2 > c2 ? c2 : t2); | 489 c2 = (t2 > c2 ? c2 : t2); |
458 } | 490 } |
459 a2 = c2 - c1 - skew; | 491 a2 = c2 - c1 - skew; |
492 ctr_done(&ctr); | |
460 | 493 |
461 results[no_results].id = x; | 494 results[no_results].id = x; |
462 results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length); | 495 results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length); |
463 results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length); | 496 results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length); |
464 results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2; | 497 results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2; |
473 return 0; | 506 return 0; |
474 } | 507 } |
475 #else | 508 #else |
476 int time_cipher3(void) { fprintf(stderr, "NO CTR\n"); return 0; } | 509 int time_cipher3(void) { fprintf(stderr, "NO CTR\n"); return 0; } |
477 #endif | 510 #endif |
511 | |
512 #ifdef LTC_LRW_MODE | |
513 int time_cipher4(void) | |
514 { | |
515 unsigned long x, y1; | |
516 ulong64 t1, t2, c1, c2, a1, a2; | |
517 symmetric_LRW lrw; | |
518 unsigned char key[MAXBLOCKSIZE], pt[4096]; | |
519 int err; | |
520 | |
521 fprintf(stderr, "\n\nLRW Time Trials for the Symmetric Ciphers:\n"); | |
522 no_results = 0; | |
523 for (x = 0; cipher_descriptor[x].name != NULL; x++) { | |
524 if (cipher_descriptor[x].block_length != 16) continue; | |
525 lrw_start(x, pt, key, cipher_descriptor[x].min_key_length, key, 0, &lrw); | |
526 | |
527 /* sanity check on cipher */ | |
528 if ((err = cipher_descriptor[x].test()) != CRYPT_OK) { | |
529 fprintf(stderr, "\n\nERROR: Cipher %s failed self-test %s\n", cipher_descriptor[x].name, error_to_string(err)); | |
530 exit(EXIT_FAILURE); | |
531 } | |
532 | |
533 #define DO1 lrw_encrypt(pt, pt, sizeof(pt), &lrw); | |
534 #define DO2 DO1 DO1 | |
535 | |
536 c1 = c2 = (ulong64)-1; | |
537 for (y1 = 0; y1 < 100; y1++) { | |
538 t_start(); | |
539 DO1; | |
540 t1 = t_read(); | |
541 DO2; | |
542 t2 = t_read(); | |
543 t2 -= t1; | |
544 | |
545 c1 = (t1 > c1 ? c1 : t1); | |
546 c2 = (t2 > c2 ? c2 : t2); | |
547 } | |
548 a1 = c2 - c1 - skew; | |
549 | |
550 #undef DO1 | |
551 #undef DO2 | |
552 #define DO1 lrw_decrypt(pt, pt, sizeof(pt), &lrw); | |
553 #define DO2 DO1 DO1 | |
554 | |
555 c1 = c2 = (ulong64)-1; | |
556 for (y1 = 0; y1 < 100; y1++) { | |
557 t_start(); | |
558 DO1; | |
559 t1 = t_read(); | |
560 DO2; | |
561 t2 = t_read(); | |
562 t2 -= t1; | |
563 | |
564 c1 = (t1 > c1 ? c1 : t1); | |
565 c2 = (t2 > c2 ? c2 : t2); | |
566 } | |
567 a2 = c2 - c1 - skew; | |
568 | |
569 lrw_done(&lrw); | |
570 | |
571 results[no_results].id = x; | |
572 results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length); | |
573 results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length); | |
574 results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2; | |
575 ++no_results; | |
576 fprintf(stderr, "."); fflush(stdout); | |
577 | |
578 #undef DO2 | |
579 #undef DO1 | |
580 } | |
581 tally_results(1); | |
582 | |
583 return 0; | |
584 } | |
585 #else | |
586 int time_cipher4(void) { fprintf(stderr, "NO LRW\n"); return 0; } | |
587 #endif | |
588 | |
478 | 589 |
479 int time_hash(void) | 590 int time_hash(void) |
480 { | 591 { |
481 unsigned long x, y1, len; | 592 unsigned long x, y1, len; |
482 ulong64 t1, t2, c1, c2; | 593 ulong64 t1, t2, c1, c2; |
525 tally_results(2); | 636 tally_results(2); |
526 | 637 |
527 return 0; | 638 return 0; |
528 } | 639 } |
529 | 640 |
641 #undef MPI | |
642 /*#warning you need an mp_rand!!!*/ | |
643 | |
530 #ifdef MPI | 644 #ifdef MPI |
531 void time_mult(void) | 645 void time_mult(void) |
532 { | 646 { |
533 ulong64 t1, t2; | 647 ulong64 t1, t2; |
534 unsigned long x, y; | 648 unsigned long x, y; |
535 mp_int a, b, c; | 649 void *a, *b, *c; |
536 | 650 |
537 fprintf(stderr, "Timing Multiplying:\n"); | 651 fprintf(stderr, "Timing Multiplying:\n"); |
538 mp_init_multi(&a,&b,&c,NULL); | 652 mp_init_multi(&a,&b,&c,NULL); |
539 for (x = 128/DIGIT_BIT; x <= 1536/DIGIT_BIT; x += 128/DIGIT_BIT) { | 653 for (x = 128/DIGIT_BIT; x <= 1536/DIGIT_BIT; x += 128/DIGIT_BIT) { |
540 mp_rand(&a, x); | 654 mp_rand(&a, x); |
643 #undef DO1 | 757 #undef DO1 |
644 | 758 |
645 } | 759 } |
646 } | 760 } |
647 | 761 |
762 #ifdef MDSA | |
763 /* time various DSA operations */ | |
764 void time_dsa(void) | |
765 { | |
766 dsa_key key; | |
767 ulong64 t1, t2; | |
768 unsigned long x, y; | |
769 int err; | |
770 static const struct { | |
771 int group, modulus; | |
772 } groups[] = { | |
773 { 20, 96 }, | |
774 { 20, 128 }, | |
775 { 24, 192 }, | |
776 { 28, 256 }, | |
777 { 32, 512 } | |
778 }; | |
779 | |
780 for (x = 0; x < (sizeof(groups)/sizeof(groups[0])); x++) { | |
781 t2 = 0; | |
782 for (y = 0; y < 4; y++) { | |
783 t_start(); | |
784 t1 = t_read(); | |
785 if ((err = dsa_make_key(&yarrow_prng, find_prng("yarrow"), groups[x].group, groups[x].modulus, &key)) != CRYPT_OK) { | |
786 fprintf(stderr, "\n\ndsa_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); | |
787 exit(EXIT_FAILURE); | |
788 } | |
789 t1 = t_read() - t1; | |
790 t2 += t1; | |
791 | |
792 #ifdef LTC_PROFILE | |
793 t2 <<= 2; | |
794 break; | |
795 #endif | |
796 if (y < 3) { | |
797 dsa_free(&key); | |
798 } | |
799 } | |
800 t2 >>= 2; | |
801 fprintf(stderr, "DSA-(%lu, %lu) make_key took %15llu cycles\n", (unsigned long)groups[x].group*8, (unsigned long)groups[x].modulus*8, t2); | |
802 } | |
803 } | |
804 #endif | |
805 | |
806 | |
648 #ifdef MRSA | 807 #ifdef MRSA |
649 /* time various RSA operations */ | 808 /* time various RSA operations */ |
650 void time_rsa(void) | 809 void time_rsa(void) |
651 { | 810 { |
652 rsa_key key; | 811 rsa_key key; |
653 ulong64 t1, t2; | 812 ulong64 t1, t2; |
654 unsigned char buf[2][4096]; | 813 unsigned char buf[2][2048]; |
655 unsigned long x, y, z, zzz; | 814 unsigned long x, y, z, zzz; |
656 int err, zz; | 815 int err, zz, stat; |
657 | 816 |
658 for (x = 1024; x <= 2048; x += 512) { | 817 for (x = 1024; x <= 2048; x += 256) { |
659 t2 = 0; | 818 t2 = 0; |
660 for (y = 0; y < 16; y++) { | 819 for (y = 0; y < 4; y++) { |
661 t_start(); | 820 t_start(); |
662 t1 = t_read(); | 821 t1 = t_read(); |
663 if ((err = rsa_make_key(&yarrow_prng, find_prng("yarrow"), x/8, 65537, &key)) != CRYPT_OK) { | 822 if ((err = rsa_make_key(&yarrow_prng, find_prng("yarrow"), x/8, 65537, &key)) != CRYPT_OK) { |
664 fprintf(stderr, "\n\nrsa_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); | 823 fprintf(stderr, "\n\nrsa_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); |
665 exit(EXIT_FAILURE); | 824 exit(EXIT_FAILURE); |
666 } | 825 } |
667 t1 = t_read() - t1; | 826 t1 = t_read() - t1; |
668 t2 += t1; | 827 t2 += t1; |
669 | 828 |
670 if (y < 15) { | 829 #ifdef LTC_PROFILE |
830 t2 <<= 2; | |
831 break; | |
832 #endif | |
833 | |
834 if (y < 3) { | |
671 rsa_free(&key); | 835 rsa_free(&key); |
672 } | 836 } |
673 } | 837 } |
674 t2 >>= 4; | 838 t2 >>= 2; |
675 fprintf(stderr, "RSA-%lu make_key took %15llu cycles\n", x, t2); | 839 fprintf(stderr, "RSA-%lu make_key took %15llu cycles\n", x, t2); |
676 | 840 |
677 t2 = 0; | 841 t2 = 0; |
678 for (y = 0; y < 16; y++) { | 842 for (y = 0; y < 16; y++) { |
679 t_start(); | 843 t_start(); |
680 t1 = t_read(); | 844 t1 = t_read(); |
681 z = sizeof(buf[1]); | 845 z = sizeof(buf[1]); |
682 if ((err = rsa_encrypt_key(buf[0], 32, buf[1], &z, "testprog", 8, &yarrow_prng, | 846 if ((err = rsa_encrypt_key(buf[0], 32, buf[1], &z, (const unsigned char *)"testprog", 8, &yarrow_prng, |
683 find_prng("yarrow"), find_hash("sha1"), | 847 find_prng("yarrow"), find_hash("sha1"), |
684 &key)) != CRYPT_OK) { | 848 &key)) != CRYPT_OK) { |
685 fprintf(stderr, "\n\nrsa_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); | 849 fprintf(stderr, "\n\nrsa_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); |
686 exit(EXIT_FAILURE); | 850 exit(EXIT_FAILURE); |
687 } | 851 } |
688 t1 = t_read() - t1; | 852 t1 = t_read() - t1; |
689 t2 += t1; | 853 t2 += t1; |
854 #ifdef LTC_PROFILE | |
855 t2 <<= 4; | |
856 break; | |
857 #endif | |
690 } | 858 } |
691 t2 >>= 4; | 859 t2 >>= 4; |
692 fprintf(stderr, "RSA-%lu encrypt_key took %15llu cycles\n", x, t2); | 860 fprintf(stderr, "RSA-%lu encrypt_key took %15llu cycles\n", x, t2); |
861 | |
862 t2 = 0; | |
863 for (y = 0; y < 2048; y++) { | |
864 t_start(); | |
865 t1 = t_read(); | |
866 zzz = sizeof(buf[0]); | |
867 if ((err = rsa_decrypt_key(buf[1], z, buf[0], &zzz, (const unsigned char *)"testprog", 8, find_hash("sha1"), | |
868 &zz, &key)) != CRYPT_OK) { | |
869 fprintf(stderr, "\n\nrsa_decrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); | |
870 exit(EXIT_FAILURE); | |
871 } | |
872 t1 = t_read() - t1; | |
873 t2 += t1; | |
874 #ifdef LTC_PROFILE | |
875 t2 <<= 11; | |
876 break; | |
877 #endif | |
878 } | |
879 t2 >>= 11; | |
880 fprintf(stderr, "RSA-%lu decrypt_key took %15llu cycles\n", x, t2); | |
881 | |
882 t2 = 0; | |
883 for (y = 0; y < 256; y++) { | |
884 t_start(); | |
885 t1 = t_read(); | |
886 z = sizeof(buf[1]); | |
887 if ((err = rsa_sign_hash(buf[0], 20, buf[1], &z, &yarrow_prng, | |
888 find_prng("yarrow"), find_hash("sha1"), 8, &key)) != CRYPT_OK) { | |
889 fprintf(stderr, "\n\nrsa_sign_hash says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); | |
890 exit(EXIT_FAILURE); | |
891 } | |
892 t1 = t_read() - t1; | |
893 t2 += t1; | |
894 #ifdef LTC_PROFILE | |
895 t2 <<= 8; | |
896 break; | |
897 #endif | |
898 } | |
899 t2 >>= 8; | |
900 fprintf(stderr, "RSA-%lu sign_hash took %15llu cycles\n", x, t2); | |
901 | |
902 t2 = 0; | |
903 for (y = 0; y < 2048; y++) { | |
904 t_start(); | |
905 t1 = t_read(); | |
906 if ((err = rsa_verify_hash(buf[1], z, buf[0], 20, find_hash("sha1"), 8, &stat, &key)) != CRYPT_OK) { | |
907 fprintf(stderr, "\n\nrsa_verify_hash says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); | |
908 exit(EXIT_FAILURE); | |
909 } | |
910 if (stat == 0) { | |
911 fprintf(stderr, "\n\nrsa_verify_hash for RSA-%lu failed to verify signature(%lu)\n", x, y); | |
912 exit(EXIT_FAILURE); | |
913 } | |
914 t1 = t_read() - t1; | |
915 t2 += t1; | |
916 #ifdef LTC_PROFILE | |
917 t2 <<= 11; | |
918 break; | |
919 #endif | |
920 } | |
921 t2 >>= 11; | |
922 fprintf(stderr, "RSA-%lu verify_hash took %15llu cycles\n", x, t2); | |
923 fprintf(stderr, "\n\n"); | |
924 rsa_free(&key); | |
925 } | |
926 } | |
927 #else | |
928 void time_rsa(void) { fprintf(stderr, "NO RSA\n"); } | |
929 #endif | |
930 | |
931 #ifdef MKAT | |
932 /* time various KAT operations */ | |
933 void time_katja(void) | |
934 { | |
935 katja_key key; | |
936 ulong64 t1, t2; | |
937 unsigned char buf[2][4096]; | |
938 unsigned long x, y, z, zzz; | |
939 int err, zz; | |
940 | |
941 for (x = 1024; x <= 2048; x += 256) { | |
942 t2 = 0; | |
943 for (y = 0; y < 4; y++) { | |
944 t_start(); | |
945 t1 = t_read(); | |
946 if ((err = katja_make_key(&yarrow_prng, find_prng("yarrow"), x/8, &key)) != CRYPT_OK) { | |
947 fprintf(stderr, "\n\nkatja_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); | |
948 exit(EXIT_FAILURE); | |
949 } | |
950 t1 = t_read() - t1; | |
951 t2 += t1; | |
952 | |
953 if (y < 3) { | |
954 katja_free(&key); | |
955 } | |
956 } | |
957 t2 >>= 2; | |
958 fprintf(stderr, "Katja-%lu make_key took %15llu cycles\n", x, t2); | |
693 | 959 |
694 t2 = 0; | 960 t2 = 0; |
695 for (y = 0; y < 16; y++) { | 961 for (y = 0; y < 16; y++) { |
696 t_start(); | 962 t_start(); |
697 t1 = t_read(); | 963 t1 = t_read(); |
698 zzz = sizeof(buf[0]); | 964 z = sizeof(buf[1]); |
699 if ((err = rsa_decrypt_key(buf[1], z, buf[0], &zzz, "testprog", 8, find_hash("sha1"), | 965 if ((err = katja_encrypt_key(buf[0], 32, buf[1], &z, "testprog", 8, &yarrow_prng, |
700 &zz, &key)) != CRYPT_OK) { | 966 find_prng("yarrow"), find_hash("sha1"), |
701 fprintf(stderr, "\n\nrsa_decrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); | 967 &key)) != CRYPT_OK) { |
968 fprintf(stderr, "\n\nkatja_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); | |
702 exit(EXIT_FAILURE); | 969 exit(EXIT_FAILURE); |
703 } | 970 } |
704 t1 = t_read() - t1; | 971 t1 = t_read() - t1; |
705 t2 += t1; | 972 t2 += t1; |
706 } | 973 } |
707 t2 >>= 4; | 974 t2 >>= 4; |
708 fprintf(stderr, "RSA-%lu decrypt_key took %15llu cycles\n", x, t2); | 975 fprintf(stderr, "Katja-%lu encrypt_key took %15llu cycles\n", x, t2); |
709 | 976 |
710 | 977 t2 = 0; |
711 rsa_free(&key); | 978 for (y = 0; y < 2048; y++) { |
979 t_start(); | |
980 t1 = t_read(); | |
981 zzz = sizeof(buf[0]); | |
982 if ((err = katja_decrypt_key(buf[1], z, buf[0], &zzz, "testprog", 8, find_hash("sha1"), | |
983 &zz, &key)) != CRYPT_OK) { | |
984 fprintf(stderr, "\n\nkatja_decrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); | |
985 exit(EXIT_FAILURE); | |
986 } | |
987 t1 = t_read() - t1; | |
988 t2 += t1; | |
989 } | |
990 t2 >>= 11; | |
991 fprintf(stderr, "Katja-%lu decrypt_key took %15llu cycles\n", x, t2); | |
992 | |
993 | |
994 katja_free(&key); | |
712 } | 995 } |
713 } | 996 } |
714 #else | 997 #else |
715 void time_rsa(void) { fprintf(stderr, "NO RSA\n"); } | 998 void time_katja(void) { fprintf(stderr, "NO Katja\n"); } |
716 #endif | 999 #endif |
717 | 1000 |
718 #ifdef MECC | 1001 #ifdef MECC |
719 /* time various ECC operations */ | 1002 /* time various ECC operations */ |
720 void time_ecc(void) | 1003 void time_ecc(void) |
721 { | 1004 { |
722 ecc_key key; | 1005 ecc_key key; |
723 ulong64 t1, t2; | 1006 ulong64 t1, t2; |
724 unsigned char buf[2][4096]; | 1007 unsigned char buf[2][256]; |
725 unsigned long i, x, y, z; | 1008 unsigned long i, w, x, y, z; |
726 int err; | 1009 int err, stat; |
727 static unsigned long sizes[] = {192/8, 256/8, 384/8, 521/8, 100000}; | 1010 static unsigned long sizes[] = { |
1011 #ifdef ECC112 | |
1012 112/8, | |
1013 #endif | |
1014 #ifdef ECC128 | |
1015 128/8, | |
1016 #endif | |
1017 #ifdef ECC160 | |
1018 160/8, | |
1019 #endif | |
1020 #ifdef ECC192 | |
1021 192/8, | |
1022 #endif | |
1023 #ifdef ECC224 | |
1024 224/8, | |
1025 #endif | |
1026 #ifdef ECC256 | |
1027 256/8, | |
1028 #endif | |
1029 #ifdef ECC384 | |
1030 384/8, | |
1031 #endif | |
1032 #ifdef ECC521 | |
1033 521/8, | |
1034 #endif | |
1035 100000}; | |
728 | 1036 |
729 for (x = sizes[i=0]; x < 100000; x = sizes[++i]) { | 1037 for (x = sizes[i=0]; x < 100000; x = sizes[++i]) { |
730 t2 = 0; | 1038 t2 = 0; |
731 for (y = 0; y < 16; y++) { | 1039 for (y = 0; y < 256; y++) { |
732 t_start(); | 1040 t_start(); |
733 t1 = t_read(); | 1041 t1 = t_read(); |
734 if ((err = ecc_make_key(&yarrow_prng, find_prng("yarrow"), x, &key)) != CRYPT_OK) { | 1042 if ((err = ecc_make_key(&yarrow_prng, find_prng("yarrow"), x, &key)) != CRYPT_OK) { |
735 fprintf(stderr, "\n\necc_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); | 1043 fprintf(stderr, "\n\necc_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); |
736 exit(EXIT_FAILURE); | 1044 exit(EXIT_FAILURE); |
737 } | 1045 } |
738 t1 = t_read() - t1; | 1046 t1 = t_read() - t1; |
739 t2 += t1; | 1047 t2 += t1; |
740 | 1048 |
741 if (y < 15) { | 1049 #ifdef LTC_PROFILE |
1050 t2 <<= 8; | |
1051 break; | |
1052 #endif | |
1053 | |
1054 if (y < 255) { | |
742 ecc_free(&key); | 1055 ecc_free(&key); |
743 } | 1056 } |
744 } | 1057 } |
745 t2 >>= 4; | 1058 t2 >>= 8; |
746 fprintf(stderr, "ECC-%lu make_key took %15llu cycles\n", x*8, t2); | 1059 fprintf(stderr, "ECC-%lu make_key took %15llu cycles\n", x*8, t2); |
747 | 1060 |
748 t2 = 0; | 1061 t2 = 0; |
749 for (y = 0; y < 16; y++) { | 1062 for (y = 0; y < 256; y++) { |
750 t_start(); | 1063 t_start(); |
751 t1 = t_read(); | 1064 t1 = t_read(); |
752 z = sizeof(buf[1]); | 1065 z = sizeof(buf[1]); |
753 if ((err = ecc_encrypt_key(buf[0], 20, buf[1], &z, &yarrow_prng, find_prng("yarrow"), find_hash("sha1"), | 1066 if ((err = ecc_encrypt_key(buf[0], 20, buf[1], &z, &yarrow_prng, find_prng("yarrow"), find_hash("sha1"), |
754 &key)) != CRYPT_OK) { | 1067 &key)) != CRYPT_OK) { |
755 fprintf(stderr, "\n\necc_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); | 1068 fprintf(stderr, "\n\necc_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); |
756 exit(EXIT_FAILURE); | 1069 exit(EXIT_FAILURE); |
757 } | 1070 } |
758 t1 = t_read() - t1; | 1071 t1 = t_read() - t1; |
759 t2 += t1; | 1072 t2 += t1; |
1073 #ifdef LTC_PROFILE | |
1074 t2 <<= 8; | |
1075 break; | |
1076 #endif | |
760 } | 1077 } |
761 t2 >>= 4; | 1078 t2 >>= 8; |
762 fprintf(stderr, "ECC-%lu encrypt_key took %15llu cycles\n", x*8, t2); | 1079 fprintf(stderr, "ECC-%lu encrypt_key took %15llu cycles\n", x*8, t2); |
1080 | |
1081 t2 = 0; | |
1082 for (y = 0; y < 256; y++) { | |
1083 t_start(); | |
1084 t1 = t_read(); | |
1085 w = 20; | |
1086 if ((err = ecc_decrypt_key(buf[1], z, buf[0], &w, &key)) != CRYPT_OK) { | |
1087 fprintf(stderr, "\n\necc_decrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); | |
1088 exit(EXIT_FAILURE); | |
1089 } | |
1090 t1 = t_read() - t1; | |
1091 t2 += t1; | |
1092 #ifdef LTC_PROFILE | |
1093 t2 <<= 8; | |
1094 break; | |
1095 #endif | |
1096 } | |
1097 t2 >>= 8; | |
1098 fprintf(stderr, "ECC-%lu decrypt_key took %15llu cycles\n", x*8, t2); | |
1099 | |
1100 t2 = 0; | |
1101 for (y = 0; y < 256; y++) { | |
1102 t_start(); | |
1103 t1 = t_read(); | |
1104 z = sizeof(buf[1]); | |
1105 if ((err = ecc_sign_hash(buf[0], 20, buf[1], &z, &yarrow_prng, | |
1106 find_prng("yarrow"), &key)) != CRYPT_OK) { | |
1107 fprintf(stderr, "\n\necc_sign_hash says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); | |
1108 exit(EXIT_FAILURE); | |
1109 } | |
1110 t1 = t_read() - t1; | |
1111 t2 += t1; | |
1112 #ifdef LTC_PROFILE | |
1113 t2 <<= 8; | |
1114 break; | |
1115 #endif | |
1116 } | |
1117 t2 >>= 8; | |
1118 fprintf(stderr, "ECC-%lu sign_hash took %15llu cycles\n", x*8, t2); | |
1119 | |
1120 t2 = 0; | |
1121 for (y = 0; y < 256; y++) { | |
1122 t_start(); | |
1123 t1 = t_read(); | |
1124 if ((err = ecc_verify_hash(buf[1], z, buf[0], 20, &stat, &key)) != CRYPT_OK) { | |
1125 fprintf(stderr, "\n\necc_verify_hash says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); | |
1126 exit(EXIT_FAILURE); | |
1127 } | |
1128 if (stat == 0) { | |
1129 fprintf(stderr, "\n\necc_verify_hash for ECC-%lu failed to verify signature(%lu)\n", x*8, y); | |
1130 exit(EXIT_FAILURE); | |
1131 } | |
1132 t1 = t_read() - t1; | |
1133 t2 += t1; | |
1134 #ifdef LTC_PROFILE | |
1135 t2 <<= 8; | |
1136 break; | |
1137 #endif | |
1138 } | |
1139 t2 >>= 8; | |
1140 fprintf(stderr, "ECC-%lu verify_hash took %15llu cycles\n", x*8, t2); | |
1141 | |
1142 fprintf(stderr, "\n\n"); | |
763 ecc_free(&key); | 1143 ecc_free(&key); |
764 } | 1144 } |
765 } | 1145 } |
766 #else | 1146 #else |
767 void time_ecc(void) { fprintf(stderr, "NO ECC\n"); } | 1147 void time_ecc(void) { fprintf(stderr, "NO ECC\n"); } |
768 #endif | |
769 | |
770 #ifdef MDH | |
771 /* time various DH operations */ | |
772 void time_dh(void) | |
773 { | |
774 dh_key key; | |
775 ulong64 t1, t2; | |
776 unsigned char buf[2][4096]; | |
777 unsigned long i, x, y, z; | |
778 int err; | |
779 static unsigned long sizes[] = {768/8, 1024/8, 1536/8, 2048/8, 3072/8, 4096/8, 100000}; | |
780 | |
781 for (x = sizes[i=0]; x < 100000; x = sizes[++i]) { | |
782 t2 = 0; | |
783 for (y = 0; y < 16; y++) { | |
784 t_start(); | |
785 t1 = t_read(); | |
786 if ((err = dh_make_key(&yarrow_prng, find_prng("yarrow"), x, &key)) != CRYPT_OK) { | |
787 fprintf(stderr, "\n\ndh_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); | |
788 exit(EXIT_FAILURE); | |
789 } | |
790 t1 = t_read() - t1; | |
791 t2 += t1; | |
792 | |
793 if (y < 15) { | |
794 dh_free(&key); | |
795 } | |
796 } | |
797 t2 >>= 4; | |
798 fprintf(stderr, "DH-%4lu make_key took %15llu cycles\n", x*8, t2); | |
799 | |
800 t2 = 0; | |
801 for (y = 0; y < 16; y++) { | |
802 t_start(); | |
803 t1 = t_read(); | |
804 z = sizeof(buf[1]); | |
805 if ((err = dh_encrypt_key(buf[0], 20, buf[1], &z, &yarrow_prng, find_prng("yarrow"), find_hash("sha1"), | |
806 &key)) != CRYPT_OK) { | |
807 fprintf(stderr, "\n\ndh_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); | |
808 exit(EXIT_FAILURE); | |
809 } | |
810 t1 = t_read() - t1; | |
811 t2 += t1; | |
812 } | |
813 t2 >>= 4; | |
814 fprintf(stderr, "DH-%4lu encrypt_key took %15llu cycles\n", x*8, t2); | |
815 dh_free(&key); | |
816 } | |
817 } | |
818 #else | |
819 void time_dh(void) { fprintf(stderr, "NO DH\n"); } | |
820 #endif | 1148 #endif |
821 | 1149 |
822 void time_macs_(unsigned long MAC_SIZE) | 1150 void time_macs_(unsigned long MAC_SIZE) |
823 { | 1151 { |
824 unsigned char *buf, key[16], tag[16]; | 1152 unsigned char *buf, key[16], tag[16]; |
833 fprintf(stderr, "\n\nout of heap yo\n\n"); | 1161 fprintf(stderr, "\n\nout of heap yo\n\n"); |
834 exit(EXIT_FAILURE); | 1162 exit(EXIT_FAILURE); |
835 } | 1163 } |
836 | 1164 |
837 cipher_idx = find_cipher("aes"); | 1165 cipher_idx = find_cipher("aes"); |
838 hash_idx = find_hash("md5"); | 1166 hash_idx = find_hash("sha1"); |
1167 | |
1168 if (cipher_idx == -1 || hash_idx == -1) { | |
1169 fprintf(stderr, "Warning the MAC tests requires AES and SHA1 to operate... so sorry\n"); | |
1170 return; | |
1171 } | |
839 | 1172 |
840 yarrow_read(buf, MAC_SIZE*1024, &yarrow_prng); | 1173 yarrow_read(buf, MAC_SIZE*1024, &yarrow_prng); |
841 yarrow_read(key, 16, &yarrow_prng); | 1174 yarrow_read(key, 16, &yarrow_prng); |
842 | 1175 |
843 #ifdef OMAC | 1176 #ifdef LTC_OMAC |
844 t2 = -1; | 1177 t2 = -1; |
845 for (x = 0; x < 10000; x++) { | 1178 for (x = 0; x < 10000; x++) { |
846 t_start(); | 1179 t_start(); |
847 t1 = t_read(); | 1180 t1 = t_read(); |
848 z = 16; | 1181 z = 16; |
851 exit(EXIT_FAILURE); | 1184 exit(EXIT_FAILURE); |
852 } | 1185 } |
853 t1 = t_read() - t1; | 1186 t1 = t_read() - t1; |
854 if (t1 < t2) t2 = t1; | 1187 if (t1 < t2) t2 = t1; |
855 } | 1188 } |
856 fprintf(stderr, "OMAC-AES\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024)); | 1189 fprintf(stderr, "OMAC-%s\t\t%9llu\n", cipher_descriptor[cipher_idx].name, t2/(ulong64)(MAC_SIZE*1024)); |
857 #endif | 1190 #endif |
858 | 1191 |
859 #ifdef PMAC | 1192 #ifdef LTC_XCBC |
1193 t2 = -1; | |
1194 for (x = 0; x < 10000; x++) { | |
1195 t_start(); | |
1196 t1 = t_read(); | |
1197 z = 16; | |
1198 if ((err = xcbc_memory(cipher_idx, key, 16, buf, MAC_SIZE*1024, tag, &z)) != CRYPT_OK) { | |
1199 fprintf(stderr, "\n\nxcbc error... %s\n", error_to_string(err)); | |
1200 exit(EXIT_FAILURE); | |
1201 } | |
1202 t1 = t_read() - t1; | |
1203 if (t1 < t2) t2 = t1; | |
1204 } | |
1205 fprintf(stderr, "XCBC-%s\t\t%9llu\n", cipher_descriptor[cipher_idx].name, t2/(ulong64)(MAC_SIZE*1024)); | |
1206 #endif | |
1207 | |
1208 #ifdef LTC_F9_MODE | |
1209 t2 = -1; | |
1210 for (x = 0; x < 10000; x++) { | |
1211 t_start(); | |
1212 t1 = t_read(); | |
1213 z = 16; | |
1214 if ((err = f9_memory(cipher_idx, key, 16, buf, MAC_SIZE*1024, tag, &z)) != CRYPT_OK) { | |
1215 fprintf(stderr, "\n\nF9 error... %s\n", error_to_string(err)); | |
1216 exit(EXIT_FAILURE); | |
1217 } | |
1218 t1 = t_read() - t1; | |
1219 if (t1 < t2) t2 = t1; | |
1220 } | |
1221 fprintf(stderr, "F9-%s\t\t\t%9llu\n", cipher_descriptor[cipher_idx].name, t2/(ulong64)(MAC_SIZE*1024)); | |
1222 #endif | |
1223 | |
1224 #ifdef LTC_PMAC | |
860 t2 = -1; | 1225 t2 = -1; |
861 for (x = 0; x < 10000; x++) { | 1226 for (x = 0; x < 10000; x++) { |
862 t_start(); | 1227 t_start(); |
863 t1 = t_read(); | 1228 t1 = t_read(); |
864 z = 16; | 1229 z = 16; |
886 if (t1 < t2) t2 = t1; | 1251 if (t1 < t2) t2 = t1; |
887 } | 1252 } |
888 fprintf(stderr, "PELICAN \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024)); | 1253 fprintf(stderr, "PELICAN \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024)); |
889 #endif | 1254 #endif |
890 | 1255 |
891 #ifdef HMAC | 1256 #ifdef LTC_HMAC |
892 t2 = -1; | 1257 t2 = -1; |
893 for (x = 0; x < 10000; x++) { | 1258 for (x = 0; x < 10000; x++) { |
894 t_start(); | 1259 t_start(); |
895 t1 = t_read(); | 1260 t1 = t_read(); |
896 z = 16; | 1261 z = 16; |
899 exit(EXIT_FAILURE); | 1264 exit(EXIT_FAILURE); |
900 } | 1265 } |
901 t1 = t_read() - t1; | 1266 t1 = t_read() - t1; |
902 if (t1 < t2) t2 = t1; | 1267 if (t1 < t2) t2 = t1; |
903 } | 1268 } |
904 fprintf(stderr, "HMAC-MD5\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024)); | 1269 fprintf(stderr, "HMAC-%s\t\t%9llu\n", hash_descriptor[hash_idx].name, t2/(ulong64)(MAC_SIZE*1024)); |
905 #endif | 1270 #endif |
906 | 1271 |
907 XFREE(buf); | 1272 XFREE(buf); |
908 } | 1273 } |
909 | 1274 |
918 { | 1283 { |
919 unsigned char *buf, IV[16], key[16], tag[16]; | 1284 unsigned char *buf, IV[16], key[16], tag[16]; |
920 ulong64 t1, t2; | 1285 ulong64 t1, t2; |
921 unsigned long x, z; | 1286 unsigned long x, z; |
922 int err, cipher_idx; | 1287 int err, cipher_idx; |
1288 symmetric_key skey; | |
923 | 1289 |
924 fprintf(stderr, "\nENC+MAC Timings (zero byte AAD, 16 byte IV, cycles/byte on %luKB blocks):\n", MAC_SIZE); | 1290 fprintf(stderr, "\nENC+MAC Timings (zero byte AAD, 16 byte IV, cycles/byte on %luKB blocks):\n", MAC_SIZE); |
925 | 1291 |
926 buf = XMALLOC(MAC_SIZE*1024); | 1292 buf = XMALLOC(MAC_SIZE*1024); |
927 if (buf == NULL) { | 1293 if (buf == NULL) { |
946 exit(EXIT_FAILURE); | 1312 exit(EXIT_FAILURE); |
947 } | 1313 } |
948 t1 = t_read() - t1; | 1314 t1 = t_read() - t1; |
949 if (t1 < t2) t2 = t1; | 1315 if (t1 < t2) t2 = t1; |
950 } | 1316 } |
951 fprintf(stderr, "EAX \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024)); | 1317 fprintf(stderr, "EAX \t\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024)); |
952 #endif | 1318 #endif |
953 | 1319 |
954 #ifdef OCB_MODE | 1320 #ifdef OCB_MODE |
955 t2 = -1; | 1321 t2 = -1; |
956 for (x = 0; x < 10000; x++) { | 1322 for (x = 0; x < 10000; x++) { |
962 exit(EXIT_FAILURE); | 1328 exit(EXIT_FAILURE); |
963 } | 1329 } |
964 t1 = t_read() - t1; | 1330 t1 = t_read() - t1; |
965 if (t1 < t2) t2 = t1; | 1331 if (t1 < t2) t2 = t1; |
966 } | 1332 } |
967 fprintf(stderr, "OCB \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024)); | 1333 fprintf(stderr, "OCB \t\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024)); |
968 #endif | 1334 #endif |
969 | 1335 |
970 #ifdef CCM_MODE | 1336 #ifdef CCM_MODE |
971 t2 = -1; | 1337 t2 = -1; |
972 for (x = 0; x < 10000; x++) { | 1338 for (x = 0; x < 10000; x++) { |
973 t_start(); | 1339 t_start(); |
974 t1 = t_read(); | 1340 t1 = t_read(); |
975 z = 16; | 1341 z = 16; |
976 if ((err = ccm_memory(cipher_idx, key, 16, IV, 16, NULL, 0, buf, MAC_SIZE*1024, buf, tag, &z, CCM_ENCRYPT)) != CRYPT_OK) { | 1342 if ((err = ccm_memory(cipher_idx, key, 16, NULL, IV, 16, NULL, 0, buf, MAC_SIZE*1024, buf, tag, &z, CCM_ENCRYPT)) != CRYPT_OK) { |
977 fprintf(stderr, "\nCCM error... %s\n", error_to_string(err)); | 1343 fprintf(stderr, "\nCCM error... %s\n", error_to_string(err)); |
978 exit(EXIT_FAILURE); | 1344 exit(EXIT_FAILURE); |
979 } | 1345 } |
980 t1 = t_read() - t1; | 1346 t1 = t_read() - t1; |
981 if (t1 < t2) t2 = t1; | 1347 if (t1 < t2) t2 = t1; |
982 } | 1348 } |
983 fprintf(stderr, "CCM \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024)); | 1349 fprintf(stderr, "CCM (no-precomp) \t%9llu\n", t2/(ulong64)(MAC_SIZE*1024)); |
1350 | |
1351 cipher_descriptor[cipher_idx].setup(key, 16, 0, &skey); | |
1352 t2 = -1; | |
1353 for (x = 0; x < 10000; x++) { | |
1354 t_start(); | |
1355 t1 = t_read(); | |
1356 z = 16; | |
1357 if ((err = ccm_memory(cipher_idx, key, 16, &skey, IV, 16, NULL, 0, buf, MAC_SIZE*1024, buf, tag, &z, CCM_ENCRYPT)) != CRYPT_OK) { | |
1358 fprintf(stderr, "\nCCM error... %s\n", error_to_string(err)); | |
1359 exit(EXIT_FAILURE); | |
1360 } | |
1361 t1 = t_read() - t1; | |
1362 if (t1 < t2) t2 = t1; | |
1363 } | |
1364 fprintf(stderr, "CCM (precomp) \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024)); | |
1365 cipher_descriptor[cipher_idx].done(&skey); | |
984 #endif | 1366 #endif |
985 | 1367 |
986 #ifdef GCM_MODE | 1368 #ifdef GCM_MODE |
987 t2 = -1; | 1369 t2 = -1; |
988 for (x = 0; x < 100; x++) { | 1370 for (x = 0; x < 100; x++) { |
997 if (t1 < t2) t2 = t1; | 1379 if (t1 < t2) t2 = t1; |
998 } | 1380 } |
999 fprintf(stderr, "GCM (no-precomp)\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024)); | 1381 fprintf(stderr, "GCM (no-precomp)\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024)); |
1000 | 1382 |
1001 { | 1383 { |
1002 gcm_state gcm; | 1384 gcm_state gcm |
1385 #ifdef GCM_TABLES_SSE2 | |
1386 __attribute__ ((aligned (16))) | |
1387 #endif | |
1388 ; | |
1003 | 1389 |
1004 if ((err = gcm_init(&gcm, cipher_idx, key, 16)) != CRYPT_OK) { fprintf(stderr, "gcm_init: %s\n", error_to_string(err)); exit(EXIT_FAILURE); } | 1390 if ((err = gcm_init(&gcm, cipher_idx, key, 16)) != CRYPT_OK) { fprintf(stderr, "gcm_init: %s\n", error_to_string(err)); exit(EXIT_FAILURE); } |
1005 t2 = -1; | 1391 t2 = -1; |
1006 for (x = 0; x < 10000; x++) { | 1392 for (x = 0; x < 10000; x++) { |
1007 t_start(); | 1393 t_start(); |
1029 exit(EXIT_FAILURE); | 1415 exit(EXIT_FAILURE); |
1030 } | 1416 } |
1031 t1 = t_read() - t1; | 1417 t1 = t_read() - t1; |
1032 if (t1 < t2) t2 = t1; | 1418 if (t1 < t2) t2 = t1; |
1033 } | 1419 } |
1034 fprintf(stderr, "GCM (precomp)\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024)); | 1420 fprintf(stderr, "GCM (precomp)\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024)); |
1035 } | 1421 } |
1036 | 1422 |
1037 #endif | 1423 #endif |
1038 | 1424 |
1039 } | 1425 } |
1044 time_encmacs_(4); | 1430 time_encmacs_(4); |
1045 time_encmacs_(32); | 1431 time_encmacs_(32); |
1046 } | 1432 } |
1047 | 1433 |
1048 /* $Source: /cvs/libtom/libtomcrypt/testprof/x86_prof.c,v $ */ | 1434 /* $Source: /cvs/libtom/libtomcrypt/testprof/x86_prof.c,v $ */ |
1049 /* $Revision: 1.16 $ */ | 1435 /* $Revision: 1.51 $ */ |
1050 /* $Date: 2005/06/14 20:44:23 $ */ | 1436 /* $Date: 2006/11/21 00:10:18 $ */ |