comparison testprof/x86_prof.c @ 209:39d5d58461d6 libtomcrypt-orig LTC_1.05

Import of libtomcrypt 1.05
author Matt Johnston <matt@ucc.asn.au>
date Wed, 06 Jul 2005 03:53:40 +0000
parents 1c15b283127b
children
comparison
equal deleted inserted replaced
191:1c15b283127b 209:39d5d58461d6
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 printf("\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++) {
27 printf("%-20s: Schedule at %6lu\n", cipher_descriptor[results[x].id].name, (unsigned long)results[x].spd1); 27 fprintf(stderr, "%-20s: Schedule at %6lu\n", cipher_descriptor[results[x].id].name, (unsigned long)results[x].spd1);
28 } 28 }
29 } else if (type == 1) { 29 } else if (type == 1) {
30 for (x = 0; x < no_results; x++) { 30 for (x = 0; x < no_results; x++) {
31 printf 31 printf
32 ("%-20s[%3d]: Encrypt at %5lu, Decrypt at %5lu\n", cipher_descriptor[results[x].id].name, cipher_descriptor[results[x].id].ID, results[x].spd1, results[x].spd2); 32 ("%-20s[%3d]: Encrypt at %5lu, Decrypt at %5lu\n", cipher_descriptor[results[x].id].name, cipher_descriptor[results[x].id].ID, results[x].spd1, results[x].spd2);
40 } 40 }
41 41
42 /* RDTSC from Scott Duplichan */ 42 /* RDTSC from Scott Duplichan */
43 ulong64 rdtsc (void) 43 ulong64 rdtsc (void)
44 { 44 {
45 #if defined __GNUC__ 45 #if defined __GNUC__ && !defined(LTC_NO_ASM)
46 #ifdef INTEL_CC 46 #ifdef INTEL_CC
47 ulong64 a; 47 ulong64 a;
48 asm ( " rdtsc ":"=A"(a)); 48 asm ( " rdtsc ":"=A"(a));
49 return a; 49 return a;
50 #elif defined(__i386__) || defined(__x86_64__) 50 #elif defined(__i386__) || defined(__x86_64__)
60 #else 60 #else
61 return XCLOCK(); 61 return XCLOCK();
62 #endif 62 #endif
63 63
64 // Microsoft and Intel Windows compilers 64 // Microsoft and Intel Windows compilers
65 #elif defined _M_IX86 65 #elif defined _M_IX86 && !defined(LTC_NO_ASM)
66 __asm rdtsc 66 __asm rdtsc
67 #elif defined _M_AMD64 67 #elif defined _M_AMD64 && !defined(LTC_NO_ASM)
68 return __rdtsc (); 68 return __rdtsc ();
69 #elif defined _M_IA64 69 #elif defined _M_IA64 && !defined(LTC_NO_ASM)
70 #if defined __INTEL_COMPILER 70 #if defined __INTEL_COMPILER
71 #include <ia64intrin.h> 71 #include <ia64intrin.h>
72 #endif 72 #endif
73 return __getReg (3116); 73 return __getReg (3116);
74 #else 74 #else
102 102
103 c1 = (t1 > c1) ? t1 : c1; 103 c1 = (t1 > c1) ? t1 : c1;
104 c2 = (t2 > c2) ? t2 : c2; 104 c2 = (t2 > c2) ? t2 : c2;
105 } 105 }
106 skew = c2 - c1; 106 skew = c2 - c1;
107 printf("Clock Skew: %lu\n", (unsigned long)skew); 107 fprintf(stderr, "Clock Skew: %lu\n", (unsigned long)skew);
108 } 108 }
109 109
110 void reg_algs(void) 110 void reg_algs(void)
111 { 111 {
112 int err; 112 int err;
197 register_hash (&whirlpool_desc); 197 register_hash (&whirlpool_desc);
198 #endif 198 #endif
199 #ifdef CHC_HASH 199 #ifdef CHC_HASH
200 register_hash(&chc_desc); 200 register_hash(&chc_desc);
201 if ((err = chc_register(register_cipher(&aes_desc))) != CRYPT_OK) { 201 if ((err = chc_register(register_cipher(&aes_desc))) != CRYPT_OK) {
202 printf("chc_register error: %s\n", error_to_string(err)); 202 fprintf(stderr, "chc_register error: %s\n", error_to_string(err));
203 exit(EXIT_FAILURE); 203 exit(EXIT_FAILURE);
204 } 204 }
205 #endif 205 #endif
206 206
207 207
229 symmetric_key skey; 229 symmetric_key skey;
230 int kl; 230 int kl;
231 int (*func) (const unsigned char *, int , int , symmetric_key *); 231 int (*func) (const unsigned char *, int , int , symmetric_key *);
232 unsigned char key[MAXBLOCKSIZE]; 232 unsigned char key[MAXBLOCKSIZE];
233 233
234 printf ("\n\nKey Schedule Time Trials for the Symmetric Ciphers:\n(Times are cycles per key)\n"); 234 fprintf(stderr, "\n\nKey Schedule Time Trials for the Symmetric Ciphers:\n(Times are cycles per key)\n");
235 no_results = 0; 235 no_results = 0;
236 for (x = 0; cipher_descriptor[x].name != NULL; x++) { 236 for (x = 0; cipher_descriptor[x].name != NULL; x++) {
237 #define DO1(k) func(k, kl, 0, &skey); 237 #define DO1(k) func(k, kl, 0, &skey);
238 238
239 func = cipher_descriptor[x].setup; 239 func = cipher_descriptor[x].setup;
247 c1 = (t1 > c1) ? c1 : t1; 247 c1 = (t1 > c1) ? c1 : t1;
248 } 248 }
249 t1 = c1 - skew; 249 t1 = c1 - skew;
250 results[no_results].spd1 = results[no_results].avg = t1; 250 results[no_results].spd1 = results[no_results].avg = t1;
251 results[no_results++].id = x; 251 results[no_results++].id = x;
252 printf("."); fflush(stdout); 252 fprintf(stderr, "."); fflush(stdout);
253 253
254 #undef DO1 254 #undef DO1
255 } 255 }
256 tally_results(0); 256 tally_results(0);
257 257
264 ulong64 t1, t2, c1, c2, a1, a2; 264 ulong64 t1, t2, c1, c2, a1, a2;
265 symmetric_ECB ecb; 265 symmetric_ECB ecb;
266 unsigned char key[MAXBLOCKSIZE], pt[4096]; 266 unsigned char key[MAXBLOCKSIZE], pt[4096];
267 int err; 267 int err;
268 268
269 printf ("\n\nECB Time Trials for the Symmetric Ciphers:\n"); 269 fprintf(stderr, "\n\nECB Time Trials for the Symmetric Ciphers:\n");
270 no_results = 0; 270 no_results = 0;
271 for (x = 0; cipher_descriptor[x].name != NULL; x++) { 271 for (x = 0; cipher_descriptor[x].name != NULL; x++) {
272 ecb_start(x, key, cipher_descriptor[x].min_key_length, 0, &ecb); 272 ecb_start(x, key, cipher_descriptor[x].min_key_length, 0, &ecb);
273 273
274 /* sanity check on cipher */ 274 /* sanity check on cipher */
316 results[no_results].id = x; 316 results[no_results].id = x;
317 results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length); 317 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); 318 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; 319 results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2;
320 ++no_results; 320 ++no_results;
321 printf("."); fflush(stdout); 321 fprintf(stderr, "."); fflush(stdout);
322 322
323 #undef DO2 323 #undef DO2
324 #undef DO1 324 #undef DO1
325 } 325 }
326 tally_results(1); 326 tally_results(1);
335 ulong64 t1, t2, c1, c2, a1, a2; 335 ulong64 t1, t2, c1, c2, a1, a2;
336 symmetric_CBC cbc; 336 symmetric_CBC cbc;
337 unsigned char key[MAXBLOCKSIZE], pt[4096]; 337 unsigned char key[MAXBLOCKSIZE], pt[4096];
338 int err; 338 int err;
339 339
340 printf ("\n\nCBC Time Trials for the Symmetric Ciphers:\n"); 340 fprintf(stderr, "\n\nCBC Time Trials for the Symmetric Ciphers:\n");
341 no_results = 0; 341 no_results = 0;
342 for (x = 0; cipher_descriptor[x].name != NULL; x++) { 342 for (x = 0; cipher_descriptor[x].name != NULL; x++) {
343 cbc_start(x, pt, key, cipher_descriptor[x].min_key_length, 0, &cbc); 343 cbc_start(x, pt, key, cipher_descriptor[x].min_key_length, 0, &cbc);
344 344
345 /* sanity check on cipher */ 345 /* sanity check on cipher */
387 results[no_results].id = x; 387 results[no_results].id = x;
388 results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length); 388 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); 389 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; 390 results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2;
391 ++no_results; 391 ++no_results;
392 printf("."); fflush(stdout); 392 fprintf(stderr, "."); fflush(stdout);
393 393
394 #undef DO2 394 #undef DO2
395 #undef DO1 395 #undef DO1
396 } 396 }
397 tally_results(1); 397 tally_results(1);
398 398
399 return 0; 399 return 0;
400 } 400 }
401 #else 401 #else
402 int time_cipher2(void) { printf("NO CBC\n"); return 0; } 402 int time_cipher2(void) { fprintf(stderr, "NO CBC\n"); return 0; }
403 #endif 403 #endif
404 404
405 #ifdef CTR 405 #ifdef CTR
406 int time_cipher3(void) 406 int time_cipher3(void)
407 { 407 {
409 ulong64 t1, t2, c1, c2, a1, a2; 409 ulong64 t1, t2, c1, c2, a1, a2;
410 symmetric_CTR ctr; 410 symmetric_CTR ctr;
411 unsigned char key[MAXBLOCKSIZE], pt[4096]; 411 unsigned char key[MAXBLOCKSIZE], pt[4096];
412 int err; 412 int err;
413 413
414 printf ("\n\nCTR Time Trials for the Symmetric Ciphers:\n"); 414 fprintf(stderr, "\n\nCTR Time Trials for the Symmetric Ciphers:\n");
415 no_results = 0; 415 no_results = 0;
416 for (x = 0; cipher_descriptor[x].name != NULL; x++) { 416 for (x = 0; cipher_descriptor[x].name != NULL; x++) {
417 ctr_start(x, pt, key, cipher_descriptor[x].min_key_length, 0, &ctr); 417 ctr_start(x, pt, key, cipher_descriptor[x].min_key_length, 0, CTR_COUNTER_LITTLE_ENDIAN, &ctr);
418 418
419 /* sanity check on cipher */ 419 /* sanity check on cipher */
420 if ((err = cipher_descriptor[x].test()) != CRYPT_OK) { 420 if ((err = cipher_descriptor[x].test()) != CRYPT_OK) {
421 fprintf(stderr, "\n\nERROR: Cipher %s failed self-test %s\n", cipher_descriptor[x].name, error_to_string(err)); 421 fprintf(stderr, "\n\nERROR: Cipher %s failed self-test %s\n", cipher_descriptor[x].name, error_to_string(err));
422 exit(EXIT_FAILURE); 422 exit(EXIT_FAILURE);
461 results[no_results].id = x; 461 results[no_results].id = x;
462 results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length); 462 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); 463 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; 464 results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2;
465 ++no_results; 465 ++no_results;
466 printf("."); fflush(stdout); 466 fprintf(stderr, "."); fflush(stdout);
467 467
468 #undef DO2 468 #undef DO2
469 #undef DO1 469 #undef DO1
470 } 470 }
471 tally_results(1); 471 tally_results(1);
472 472
473 return 0; 473 return 0;
474 } 474 }
475 #else 475 #else
476 int time_cipher3(void) { printf("NO CTR\n"); return 0; } 476 int time_cipher3(void) { fprintf(stderr, "NO CTR\n"); return 0; }
477 #endif 477 #endif
478 478
479 int time_hash(void) 479 int time_hash(void)
480 { 480 {
481 unsigned long x, y1, len; 481 unsigned long x, y1, len;
483 hash_state md; 483 hash_state md;
484 int (*func)(hash_state *, const unsigned char *, unsigned long), err; 484 int (*func)(hash_state *, const unsigned char *, unsigned long), err;
485 unsigned char pt[MAXBLOCKSIZE]; 485 unsigned char pt[MAXBLOCKSIZE];
486 486
487 487
488 printf ("\n\nHASH Time Trials for:\n"); 488 fprintf(stderr, "\n\nHASH Time Trials for:\n");
489 no_results = 0; 489 no_results = 0;
490 for (x = 0; hash_descriptor[x].name != NULL; x++) { 490 for (x = 0; hash_descriptor[x].name != NULL; x++) {
491 491
492 /* sanity check on hash */ 492 /* sanity check on hash */
493 if ((err = hash_descriptor[x].test()) != CRYPT_OK) { 493 if ((err = hash_descriptor[x].test()) != CRYPT_OK) {
516 t1 = c2 - c1 - skew; 516 t1 = c2 - c1 - skew;
517 t1 = ((t1 * CONST64(1000))) / ((ulong64)hash_descriptor[x].blocksize); 517 t1 = ((t1 * CONST64(1000))) / ((ulong64)hash_descriptor[x].blocksize);
518 results[no_results].id = x; 518 results[no_results].id = x;
519 results[no_results].spd1 = results[no_results].avg = t1; 519 results[no_results].spd1 = results[no_results].avg = t1;
520 ++no_results; 520 ++no_results;
521 printf("."); fflush(stdout); 521 fprintf(stderr, "."); fflush(stdout);
522 #undef DO2 522 #undef DO2
523 #undef DO1 523 #undef DO1
524 } 524 }
525 tally_results(2); 525 tally_results(2);
526 526
532 { 532 {
533 ulong64 t1, t2; 533 ulong64 t1, t2;
534 unsigned long x, y; 534 unsigned long x, y;
535 mp_int a, b, c; 535 mp_int a, b, c;
536 536
537 printf("Timing Multiplying:\n"); 537 fprintf(stderr, "Timing Multiplying:\n");
538 mp_init_multi(&a,&b,&c,NULL); 538 mp_init_multi(&a,&b,&c,NULL);
539 for (x = 128/DIGIT_BIT; x <= 1536/DIGIT_BIT; x += 128/DIGIT_BIT) { 539 for (x = 128/DIGIT_BIT; x <= 1536/DIGIT_BIT; x += 128/DIGIT_BIT) {
540 mp_rand(&a, x); 540 mp_rand(&a, x);
541 mp_rand(&b, x); 541 mp_rand(&b, x);
542 542
549 t1 = t_read(); 549 t1 = t_read();
550 DO2; 550 DO2;
551 t1 = (t_read() - t1)>>1; 551 t1 = (t_read() - t1)>>1;
552 if (t1 < t2) t2 = t1; 552 if (t1 < t2) t2 = t1;
553 } 553 }
554 printf("%4lu bits: %9llu cycles\n", x*DIGIT_BIT, t2); 554 fprintf(stderr, "%4lu bits: %9llu cycles\n", x*DIGIT_BIT, t2);
555 } 555 }
556 mp_clear_multi(&a,&b,&c,NULL); 556 mp_clear_multi(&a,&b,&c,NULL);
557 557
558 #undef DO1 558 #undef DO1
559 #undef DO2 559 #undef DO2
563 { 563 {
564 ulong64 t1, t2; 564 ulong64 t1, t2;
565 unsigned long x, y; 565 unsigned long x, y;
566 mp_int a, b; 566 mp_int a, b;
567 567
568 printf("Timing Squaring:\n"); 568 fprintf(stderr, "Timing Squaring:\n");
569 mp_init_multi(&a,&b,NULL); 569 mp_init_multi(&a,&b,NULL);
570 for (x = 128/DIGIT_BIT; x <= 1536/DIGIT_BIT; x += 128/DIGIT_BIT) { 570 for (x = 128/DIGIT_BIT; x <= 1536/DIGIT_BIT; x += 128/DIGIT_BIT) {
571 mp_rand(&a, x); 571 mp_rand(&a, x);
572 572
573 #define DO1 mp_sqr(&a, &b); 573 #define DO1 mp_sqr(&a, &b);
579 t1 = t_read(); 579 t1 = t_read();
580 DO2; 580 DO2;
581 t1 = (t_read() - t1)>>1; 581 t1 = (t_read() - t1)>>1;
582 if (t1 < t2) t2 = t1; 582 if (t1 < t2) t2 = t1;
583 } 583 }
584 printf("%4lu bits: %9llu cycles\n", x*DIGIT_BIT, t2); 584 fprintf(stderr, "%4lu bits: %9llu cycles\n", x*DIGIT_BIT, t2);
585 } 585 }
586 mp_clear_multi(&a,&b,NULL); 586 mp_clear_multi(&a,&b,NULL);
587 587
588 #undef DO1 588 #undef DO1
589 #undef DO2 589 #undef DO2
590 } 590 }
591 #else 591 #else
592 void time_mult(void) { printf("NO MULT\n"); } 592 void time_mult(void) { fprintf(stderr, "NO MULT\n"); }
593 void time_sqr(void) { printf("NO SQR\n"); } 593 void time_sqr(void) { fprintf(stderr, "NO SQR\n"); }
594 #endif 594 #endif
595 595
596 void time_prng(void) 596 void time_prng(void)
597 { 597 {
598 ulong64 t1, t2; 598 ulong64 t1, t2;
599 unsigned char buf[4096]; 599 unsigned char buf[4096];
600 prng_state tprng; 600 prng_state tprng;
601 unsigned long x, y; 601 unsigned long x, y;
602 int err; 602 int err;
603 603
604 printf("Timing PRNGs (cycles/byte output, cycles add_entropy (32 bytes) :\n"); 604 fprintf(stderr, "Timing PRNGs (cycles/byte output, cycles add_entropy (32 bytes) :\n");
605 for (x = 0; prng_descriptor[x].name != NULL; x++) { 605 for (x = 0; prng_descriptor[x].name != NULL; x++) {
606 606
607 /* sanity check on prng */ 607 /* sanity check on prng */
608 if ((err = prng_descriptor[x].test()) != CRYPT_OK) { 608 if ((err = prng_descriptor[x].test()) != CRYPT_OK) {
609 fprintf(stderr, "\n\nERROR: PRNG %s failed self-test %s\n", prng_descriptor[x].name, error_to_string(err)); 609 fprintf(stderr, "\n\nERROR: PRNG %s failed self-test %s\n", prng_descriptor[x].name, error_to_string(err));
614 zeromem(buf, 256); 614 zeromem(buf, 256);
615 prng_descriptor[x].add_entropy(buf, 256, &tprng); 615 prng_descriptor[x].add_entropy(buf, 256, &tprng);
616 prng_descriptor[x].ready(&tprng); 616 prng_descriptor[x].ready(&tprng);
617 t2 = -1; 617 t2 = -1;
618 618
619 #define DO1 if (prng_descriptor[x].read(buf, 4096, &tprng) != 4096) { printf("\n\nERROR READ != 4096\n\n"); exit(EXIT_FAILURE); } 619 #define DO1 if (prng_descriptor[x].read(buf, 4096, &tprng) != 4096) { fprintf(stderr, "\n\nERROR READ != 4096\n\n"); exit(EXIT_FAILURE); }
620 #define DO2 DO1 DO1 620 #define DO2 DO1 DO1
621 for (y = 0; y < 10000; y++) { 621 for (y = 0; y < 10000; y++) {
622 t_start(); 622 t_start();
623 t1 = t_read(); 623 t1 = t_read();
624 DO2; 624 DO2;
625 t1 = (t_read() - t1)>>1; 625 t1 = (t_read() - t1)>>1;
626 if (t1 < t2) t2 = t1; 626 if (t1 < t2) t2 = t1;
627 } 627 }
628 printf("%20s: %5llu ", prng_descriptor[x].name, t2>>12); 628 fprintf(stderr, "%20s: %5llu ", prng_descriptor[x].name, t2>>12);
629 #undef DO2 629 #undef DO2
630 #undef DO1 630 #undef DO1
631 631
632 #define DO1 prng_descriptor[x].start(&tprng); prng_descriptor[x].add_entropy(buf, 32, &tprng); prng_descriptor[x].ready(&tprng); prng_descriptor[x].done(&tprng); 632 #define DO1 prng_descriptor[x].start(&tprng); prng_descriptor[x].add_entropy(buf, 32, &tprng); prng_descriptor[x].ready(&tprng); prng_descriptor[x].done(&tprng);
633 #define DO2 DO1 DO1 633 #define DO2 DO1 DO1
636 t1 = t_read(); 636 t1 = t_read();
637 DO2; 637 DO2;
638 t1 = (t_read() - t1)>>1; 638 t1 = (t_read() - t1)>>1;
639 if (t1 < t2) t2 = t1; 639 if (t1 < t2) t2 = t1;
640 } 640 }
641 printf("%5llu\n", t2); 641 fprintf(stderr, "%5llu\n", t2);
642 #undef DO2 642 #undef DO2
643 #undef DO1 643 #undef DO1
644 644
645 } 645 }
646 } 646 }
670 if (y < 15) { 670 if (y < 15) {
671 rsa_free(&key); 671 rsa_free(&key);
672 } 672 }
673 } 673 }
674 t2 >>= 4; 674 t2 >>= 4;
675 printf("RSA-%lu make_key took %15llu cycles\n", x, t2); 675 fprintf(stderr, "RSA-%lu make_key took %15llu cycles\n", x, t2);
676 676
677 t2 = 0; 677 t2 = 0;
678 for (y = 0; y < 16; y++) { 678 for (y = 0; y < 16; y++) {
679 t_start(); 679 t_start();
680 t1 = t_read(); 680 t1 = t_read();
687 } 687 }
688 t1 = t_read() - t1; 688 t1 = t_read() - t1;
689 t2 += t1; 689 t2 += t1;
690 } 690 }
691 t2 >>= 4; 691 t2 >>= 4;
692 printf("RSA-%lu encrypt_key took %15llu cycles\n", x, t2); 692 fprintf(stderr, "RSA-%lu encrypt_key took %15llu cycles\n", x, t2);
693 693
694 t2 = 0; 694 t2 = 0;
695 for (y = 0; y < 16; y++) { 695 for (y = 0; y < 16; y++) {
696 t_start(); 696 t_start();
697 t1 = t_read(); 697 t1 = t_read();
703 } 703 }
704 t1 = t_read() - t1; 704 t1 = t_read() - t1;
705 t2 += t1; 705 t2 += t1;
706 } 706 }
707 t2 >>= 4; 707 t2 >>= 4;
708 printf("RSA-%lu decrypt_key took %15llu cycles\n", x, t2); 708 fprintf(stderr, "RSA-%lu decrypt_key took %15llu cycles\n", x, t2);
709 709
710 710
711 rsa_free(&key); 711 rsa_free(&key);
712 } 712 }
713 } 713 }
714 #else 714 #else
715 void time_rsa(void) { printf("NO RSA\n"); } 715 void time_rsa(void) { fprintf(stderr, "NO RSA\n"); }
716 #endif 716 #endif
717 717
718 #ifdef MECC 718 #ifdef MECC
719 /* time various ECC operations */ 719 /* time various ECC operations */
720 void time_ecc(void) 720 void time_ecc(void)
722 ecc_key key; 722 ecc_key key;
723 ulong64 t1, t2; 723 ulong64 t1, t2;
724 unsigned char buf[2][4096]; 724 unsigned char buf[2][4096];
725 unsigned long i, x, y, z; 725 unsigned long i, x, y, z;
726 int err; 726 int err;
727 static unsigned long sizes[] = {160/8, 256/8, 521/8, 100000}; 727 static unsigned long sizes[] = {192/8, 256/8, 384/8, 521/8, 100000};
728 728
729 for (x = sizes[i=0]; x < 100000; x = sizes[++i]) { 729 for (x = sizes[i=0]; x < 100000; x = sizes[++i]) {
730 t2 = 0; 730 t2 = 0;
731 for (y = 0; y < 16; y++) { 731 for (y = 0; y < 16; y++) {
732 t_start(); 732 t_start();
741 if (y < 15) { 741 if (y < 15) {
742 ecc_free(&key); 742 ecc_free(&key);
743 } 743 }
744 } 744 }
745 t2 >>= 4; 745 t2 >>= 4;
746 printf("ECC-%lu make_key took %15llu cycles\n", x*8, t2); 746 fprintf(stderr, "ECC-%lu make_key took %15llu cycles\n", x*8, t2);
747 747
748 t2 = 0; 748 t2 = 0;
749 for (y = 0; y < 16; y++) { 749 for (y = 0; y < 16; y++) {
750 t_start(); 750 t_start();
751 t1 = t_read(); 751 t1 = t_read();
757 } 757 }
758 t1 = t_read() - t1; 758 t1 = t_read() - t1;
759 t2 += t1; 759 t2 += t1;
760 } 760 }
761 t2 >>= 4; 761 t2 >>= 4;
762 printf("ECC-%lu encrypt_key took %15llu cycles\n", x*8, t2); 762 fprintf(stderr, "ECC-%lu encrypt_key took %15llu cycles\n", x*8, t2);
763 ecc_free(&key); 763 ecc_free(&key);
764 } 764 }
765 } 765 }
766 #else 766 #else
767 void time_ecc(void) { printf("NO ECC\n"); } 767 void time_ecc(void) { fprintf(stderr, "NO ECC\n"); }
768 #endif 768 #endif
769 769
770 #ifdef MDH 770 #ifdef MDH
771 /* time various DH operations */ 771 /* time various DH operations */
772 void time_dh(void) 772 void time_dh(void)
793 if (y < 15) { 793 if (y < 15) {
794 dh_free(&key); 794 dh_free(&key);
795 } 795 }
796 } 796 }
797 t2 >>= 4; 797 t2 >>= 4;
798 printf("DH-%4lu make_key took %15llu cycles\n", x*8, t2); 798 fprintf(stderr, "DH-%4lu make_key took %15llu cycles\n", x*8, t2);
799 799
800 t2 = 0; 800 t2 = 0;
801 for (y = 0; y < 16; y++) { 801 for (y = 0; y < 16; y++) {
802 t_start(); 802 t_start();
803 t1 = t_read(); 803 t1 = t_read();
809 } 809 }
810 t1 = t_read() - t1; 810 t1 = t_read() - t1;
811 t2 += t1; 811 t2 += t1;
812 } 812 }
813 t2 >>= 4; 813 t2 >>= 4;
814 printf("DH-%4lu encrypt_key took %15llu cycles\n", x*8, t2); 814 fprintf(stderr, "DH-%4lu encrypt_key took %15llu cycles\n", x*8, t2);
815 dh_free(&key); 815 dh_free(&key);
816 } 816 }
817 } 817 }
818 #else 818 #else
819 void time_dh(void) { printf("NO DH\n"); } 819 void time_dh(void) { fprintf(stderr, "NO DH\n"); }
820 #endif 820 #endif
821 821
822 void time_macs_(unsigned long MAC_SIZE) 822 void time_macs_(unsigned long MAC_SIZE)
823 { 823 {
824 unsigned char *buf, key[16], tag[16]; 824 unsigned char *buf, key[16], tag[16];
825 ulong64 t1, t2; 825 ulong64 t1, t2;
826 unsigned long x, z; 826 unsigned long x, z;
827 int err, cipher_idx, hash_idx; 827 int err, cipher_idx, hash_idx;
828 828
829 printf("\nMAC Timings (cycles/byte on %dKB blocks):\n", MAC_SIZE); 829 fprintf(stderr, "\nMAC Timings (cycles/byte on %luKB blocks):\n", MAC_SIZE);
830 830
831 buf = XMALLOC(MAC_SIZE*1024); 831 buf = XMALLOC(MAC_SIZE*1024);
832 if (buf == NULL) { 832 if (buf == NULL) {
833 fprintf(stderr, "\n\nout of heap yo\n\n"); 833 fprintf(stderr, "\n\nout of heap yo\n\n");
834 exit(EXIT_FAILURE); 834 exit(EXIT_FAILURE);
851 exit(EXIT_FAILURE); 851 exit(EXIT_FAILURE);
852 } 852 }
853 t1 = t_read() - t1; 853 t1 = t_read() - t1;
854 if (t1 < t2) t2 = t1; 854 if (t1 < t2) t2 = t1;
855 } 855 }
856 printf("OMAC-AES\t\t%9llu\n", t2/(MAC_SIZE*1024)); 856 fprintf(stderr, "OMAC-AES\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
857 #endif 857 #endif
858 858
859 #ifdef PMAC 859 #ifdef PMAC
860 t2 = -1; 860 t2 = -1;
861 for (x = 0; x < 10000; x++) { 861 for (x = 0; x < 10000; x++) {
867 exit(EXIT_FAILURE); 867 exit(EXIT_FAILURE);
868 } 868 }
869 t1 = t_read() - t1; 869 t1 = t_read() - t1;
870 if (t1 < t2) t2 = t1; 870 if (t1 < t2) t2 = t1;
871 } 871 }
872 printf("PMAC-AES\t\t%9llu\n", t2/(MAC_SIZE*1024)); 872 fprintf(stderr, "PMAC-AES\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
873 #endif 873 #endif
874 874
875 #ifdef PELICAN 875 #ifdef PELICAN
876 t2 = -1; 876 t2 = -1;
877 for (x = 0; x < 10000; x++) { 877 for (x = 0; x < 10000; x++) {
883 exit(EXIT_FAILURE); 883 exit(EXIT_FAILURE);
884 } 884 }
885 t1 = t_read() - t1; 885 t1 = t_read() - t1;
886 if (t1 < t2) t2 = t1; 886 if (t1 < t2) t2 = t1;
887 } 887 }
888 printf("PELICAN \t\t%9llu\n", t2/(MAC_SIZE*1024)); 888 fprintf(stderr, "PELICAN \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
889 #endif 889 #endif
890 890
891 #ifdef HMAC 891 #ifdef HMAC
892 t2 = -1; 892 t2 = -1;
893 for (x = 0; x < 10000; x++) { 893 for (x = 0; x < 10000; x++) {
899 exit(EXIT_FAILURE); 899 exit(EXIT_FAILURE);
900 } 900 }
901 t1 = t_read() - t1; 901 t1 = t_read() - t1;
902 if (t1 < t2) t2 = t1; 902 if (t1 < t2) t2 = t1;
903 } 903 }
904 printf("HMAC-MD5\t\t%9llu\n", t2/(MAC_SIZE*1024)); 904 fprintf(stderr, "HMAC-MD5\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
905 #endif 905 #endif
906 906
907 XFREE(buf); 907 XFREE(buf);
908 } 908 }
909 909
919 unsigned char *buf, IV[16], key[16], tag[16]; 919 unsigned char *buf, IV[16], key[16], tag[16];
920 ulong64 t1, t2; 920 ulong64 t1, t2;
921 unsigned long x, z; 921 unsigned long x, z;
922 int err, cipher_idx; 922 int err, cipher_idx;
923 923
924 printf("\nENC+MAC Timings (zero byte AAD, 16 byte IV, cycles/byte on %dKB blocks):\n", MAC_SIZE); 924 fprintf(stderr, "\nENC+MAC Timings (zero byte AAD, 16 byte IV, cycles/byte on %luKB blocks):\n", MAC_SIZE);
925 925
926 buf = XMALLOC(MAC_SIZE*1024); 926 buf = XMALLOC(MAC_SIZE*1024);
927 if (buf == NULL) { 927 if (buf == NULL) {
928 fprintf(stderr, "\n\nout of heap yo\n\n"); 928 fprintf(stderr, "\n\nout of heap yo\n\n");
929 exit(EXIT_FAILURE); 929 exit(EXIT_FAILURE);
946 exit(EXIT_FAILURE); 946 exit(EXIT_FAILURE);
947 } 947 }
948 t1 = t_read() - t1; 948 t1 = t_read() - t1;
949 if (t1 < t2) t2 = t1; 949 if (t1 < t2) t2 = t1;
950 } 950 }
951 printf("EAX \t\t%9llu\n", t2/(MAC_SIZE*1024)); 951 fprintf(stderr, "EAX \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
952 #endif 952 #endif
953 953
954 #ifdef OCB_MODE 954 #ifdef OCB_MODE
955 t2 = -1; 955 t2 = -1;
956 for (x = 0; x < 10000; x++) { 956 for (x = 0; x < 10000; x++) {
962 exit(EXIT_FAILURE); 962 exit(EXIT_FAILURE);
963 } 963 }
964 t1 = t_read() - t1; 964 t1 = t_read() - t1;
965 if (t1 < t2) t2 = t1; 965 if (t1 < t2) t2 = t1;
966 } 966 }
967 printf("OCB \t\t%9llu\n", t2/(MAC_SIZE*1024)); 967 fprintf(stderr, "OCB \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
968 #endif 968 #endif
969 969
970 #ifdef CCM_MODE 970 #ifdef CCM_MODE
971 t2 = -1; 971 t2 = -1;
972 for (x = 0; x < 10000; x++) { 972 for (x = 0; x < 10000; x++) {
978 exit(EXIT_FAILURE); 978 exit(EXIT_FAILURE);
979 } 979 }
980 t1 = t_read() - t1; 980 t1 = t_read() - t1;
981 if (t1 < t2) t2 = t1; 981 if (t1 < t2) t2 = t1;
982 } 982 }
983 printf("CCM \t\t%9llu\n", t2/(MAC_SIZE*1024)); 983 fprintf(stderr, "CCM \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
984 #endif 984 #endif
985 985
986 #ifdef GCM_MODE 986 #ifdef GCM_MODE
987 t2 = -1; 987 t2 = -1;
988 for (x = 0; x < 100; x++) { 988 for (x = 0; x < 100; x++) {
994 exit(EXIT_FAILURE); 994 exit(EXIT_FAILURE);
995 } 995 }
996 t1 = t_read() - t1; 996 t1 = t_read() - t1;
997 if (t1 < t2) t2 = t1; 997 if (t1 < t2) t2 = t1;
998 } 998 }
999 printf("GCM (no-precomp)\t%9llu\n", t2/(MAC_SIZE*1024)); 999 fprintf(stderr, "GCM (no-precomp)\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
1000 1000
1001 { 1001 {
1002 gcm_state gcm; 1002 gcm_state gcm;
1003 1003
1004 if ((err = gcm_init(&gcm, cipher_idx, key, 16)) != CRYPT_OK) { printf("gcm_init: %s\n", error_to_string(err)); exit(EXIT_FAILURE); } 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); }
1005 t2 = -1; 1005 t2 = -1;
1006 for (x = 0; x < 10000; x++) { 1006 for (x = 0; x < 10000; x++) {
1007 t_start(); 1007 t_start();
1008 t1 = t_read(); 1008 t1 = t_read();
1009 z = 16; 1009 z = 16;
1029 exit(EXIT_FAILURE); 1029 exit(EXIT_FAILURE);
1030 } 1030 }
1031 t1 = t_read() - t1; 1031 t1 = t_read() - t1;
1032 if (t1 < t2) t2 = t1; 1032 if (t1 < t2) t2 = t1;
1033 } 1033 }
1034 printf("GCM (precomp)\t%9llu\n", t2/(MAC_SIZE*1024)); 1034 fprintf(stderr, "GCM (precomp)\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
1035 } 1035 }
1036 1036
1037 #endif 1037 #endif
1038 1038
1039 } 1039 }
1042 { 1042 {
1043 time_encmacs_(1); 1043 time_encmacs_(1);
1044 time_encmacs_(4); 1044 time_encmacs_(4);
1045 time_encmacs_(32); 1045 time_encmacs_(32);
1046 } 1046 }
1047
1048 /* $Source: /cvs/libtom/libtomcrypt/testprof/x86_prof.c,v $ */
1049 /* $Revision: 1.16 $ */
1050 /* $Date: 2005/06/14 20:44:23 $ */