⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 x86_prof.c

📁 Dropbear is an SSH 2 server, designed to be usable in small memory environments. It supports:
💻 C
📖 第 1 页 / 共 2 页
字号:
   return 0;}#ifdef MPIvoid time_mult(void){   ulong64 t1, t2;   unsigned long x, y;   mp_int  a, b, c;   fprintf(stderr, "Timing Multiplying:\n");   mp_init_multi(&a,&b,&c,NULL);   for (x = 128/DIGIT_BIT; x <= 1536/DIGIT_BIT; x += 128/DIGIT_BIT) {       mp_rand(&a, x);       mp_rand(&b, x);#define DO1 mp_mul(&a, &b, &c);#define DO2 DO1; DO1;       t2 = -1;       for (y = 0; y < TIMES; y++) {           t_start();           t1 = t_read();           DO2;           t1 = (t_read() - t1)>>1;           if (t1 < t2) t2 = t1;       }       fprintf(stderr, "%4lu bits: %9llu cycles\n", x*DIGIT_BIT, t2);   }   mp_clear_multi(&a,&b,&c,NULL);#undef DO1#undef DO2} void time_sqr(void){   ulong64 t1, t2;   unsigned long x, y;   mp_int  a, b;   fprintf(stderr, "Timing Squaring:\n");   mp_init_multi(&a,&b,NULL);   for (x = 128/DIGIT_BIT; x <= 1536/DIGIT_BIT; x += 128/DIGIT_BIT) {       mp_rand(&a, x);#define DO1 mp_sqr(&a, &b);#define DO2 DO1; DO1;       t2 = -1;       for (y = 0; y < TIMES; y++) {           t_start();           t1 = t_read();           DO2;           t1 = (t_read() - t1)>>1;           if (t1 < t2) t2 = t1;       }       fprintf(stderr, "%4lu bits: %9llu cycles\n", x*DIGIT_BIT, t2);   }   mp_clear_multi(&a,&b,NULL);#undef DO1#undef DO2}#elsevoid time_mult(void) { fprintf(stderr, "NO MULT\n"); }void time_sqr(void) { fprintf(stderr, "NO SQR\n"); }#endif   void time_prng(void){   ulong64 t1, t2;   unsigned char buf[4096];   prng_state tprng;   unsigned long x, y;   int           err;   fprintf(stderr, "Timing PRNGs (cycles/byte output, cycles add_entropy (32 bytes) :\n");   for (x = 0; prng_descriptor[x].name != NULL; x++) {      /* sanity check on prng */      if ((err = prng_descriptor[x].test()) != CRYPT_OK) {         fprintf(stderr, "\n\nERROR: PRNG %s failed self-test %s\n", prng_descriptor[x].name, error_to_string(err));         exit(EXIT_FAILURE);      }      prng_descriptor[x].start(&tprng);      zeromem(buf, 256);      prng_descriptor[x].add_entropy(buf, 256, &tprng);      prng_descriptor[x].ready(&tprng);      t2 = -1;#define DO1 if (prng_descriptor[x].read(buf, 4096, &tprng) != 4096) { fprintf(stderr, "\n\nERROR READ != 4096\n\n"); exit(EXIT_FAILURE); }#define DO2 DO1 DO1      for (y = 0; y < 10000; y++) {         t_start();         t1 = t_read();         DO2;         t1 = (t_read() - t1)>>1;         if (t1 < t2) t2 = t1;      }      fprintf(stderr, "%20s: %5llu ", prng_descriptor[x].name, t2>>12);#undef DO2#undef DO1#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);#define DO2 DO1 DO1      for (y = 0; y < 10000; y++) {         t_start();         t1 = t_read();         DO2;         t1 = (t_read() - t1)>>1;         if (t1 < t2) t2 = t1;      }      fprintf(stderr, "%5llu\n", t2);#undef DO2#undef DO1   }}#ifdef MRSA      /* time various RSA operations */void time_rsa(void){   rsa_key key;   ulong64 t1, t2;   unsigned char buf[2][4096];   unsigned long x, y, z, zzz;   int           err, zz;   for (x = 1024; x <= 2048; x += 512) {       t2 = 0;       for (y = 0; y < 16; y++) {           t_start();           t1 = t_read();           if ((err = rsa_make_key(&yarrow_prng, find_prng("yarrow"), x/8, 65537, &key)) != CRYPT_OK) {              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));              exit(EXIT_FAILURE);           }           t1 = t_read() - t1;           t2 += t1;           if (y < 15) {              rsa_free(&key);           }       }       t2 >>= 4;       fprintf(stderr, "RSA-%lu make_key    took %15llu cycles\n", x, t2);       t2 = 0;       for (y = 0; y < 16; y++) {           t_start();           t1 = t_read();           z = sizeof(buf[1]);           if ((err = rsa_encrypt_key(buf[0], 32, buf[1], &z, "testprog", 8, &yarrow_prng,                                      find_prng("yarrow"), find_hash("sha1"),                                      &key)) != CRYPT_OK) {              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));              exit(EXIT_FAILURE);           }           t1 = t_read() - t1;           t2 += t1;       }       t2 >>= 4;       fprintf(stderr, "RSA-%lu encrypt_key took %15llu cycles\n", x, t2);       t2 = 0;       for (y = 0; y < 16; y++) {           t_start();           t1 = t_read();           zzz = sizeof(buf[0]);           if ((err = rsa_decrypt_key(buf[1], z, buf[0], &zzz, "testprog", 8,  find_hash("sha1"),                                       &zz, &key)) != CRYPT_OK) {              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));              exit(EXIT_FAILURE);           }           t1 = t_read() - t1;           t2 += t1;       }       t2 >>= 4;       fprintf(stderr, "RSA-%lu decrypt_key took %15llu cycles\n", x, t2);       rsa_free(&key);  }}#elsevoid time_rsa(void) { fprintf(stderr, "NO RSA\n"); }#endif#ifdef MECC/* time various ECC operations */void time_ecc(void){   ecc_key key;   ulong64 t1, t2;   unsigned char buf[2][4096];   unsigned long i, x, y, z;   int           err;   static unsigned long sizes[] = {192/8, 256/8, 384/8, 521/8, 100000};   for (x = sizes[i=0]; x < 100000; x = sizes[++i]) {       t2 = 0;       for (y = 0; y < 16; y++) {           t_start();           t1 = t_read();           if ((err = ecc_make_key(&yarrow_prng, find_prng("yarrow"), x, &key)) != CRYPT_OK) {              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));              exit(EXIT_FAILURE);           }           t1 = t_read() - t1;           t2 += t1;           if (y < 15) {              ecc_free(&key);           }       }       t2 >>= 4;       fprintf(stderr, "ECC-%lu make_key    took %15llu cycles\n", x*8, t2);       t2 = 0;       for (y = 0; y < 16; y++) {           t_start();           t1 = t_read();           z = sizeof(buf[1]);           if ((err = ecc_encrypt_key(buf[0], 20, buf[1], &z, &yarrow_prng, find_prng("yarrow"), find_hash("sha1"),                                      &key)) != CRYPT_OK) {              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));              exit(EXIT_FAILURE);           }           t1 = t_read() - t1;           t2 += t1;       }       t2 >>= 4;       fprintf(stderr, "ECC-%lu encrypt_key took %15llu cycles\n", x*8, t2);       ecc_free(&key);  }}#elsevoid time_ecc(void) { fprintf(stderr, "NO ECC\n"); }#endif#ifdef MDH/* time various DH operations */void time_dh(void){   dh_key key;   ulong64 t1, t2;   unsigned char buf[2][4096];   unsigned long i, x, y, z;   int           err;   static unsigned long sizes[] = {768/8, 1024/8, 1536/8, 2048/8, 3072/8, 4096/8, 100000};   for (x = sizes[i=0]; x < 100000; x = sizes[++i]) {       t2 = 0;       for (y = 0; y < 16; y++) {           t_start();           t1 = t_read();           if ((err = dh_make_key(&yarrow_prng, find_prng("yarrow"), x, &key)) != CRYPT_OK) {              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));              exit(EXIT_FAILURE);           }           t1 = t_read() - t1;           t2 += t1;           if (y < 15) {              dh_free(&key);           }       }       t2 >>= 4;       fprintf(stderr, "DH-%4lu make_key    took %15llu cycles\n", x*8, t2);       t2 = 0;       for (y = 0; y < 16; y++) {           t_start();           t1 = t_read();           z = sizeof(buf[1]);           if ((err = dh_encrypt_key(buf[0], 20, buf[1], &z, &yarrow_prng, find_prng("yarrow"), find_hash("sha1"),                                      &key)) != CRYPT_OK) {              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));              exit(EXIT_FAILURE);           }           t1 = t_read() - t1;           t2 += t1;       }       t2 >>= 4;       fprintf(stderr, "DH-%4lu encrypt_key took %15llu cycles\n", x*8, t2);       dh_free(&key);  }}#elsevoid time_dh(void) { fprintf(stderr, "NO DH\n"); }#endifvoid time_macs_(unsigned long MAC_SIZE){   unsigned char *buf, key[16], tag[16];   ulong64 t1, t2;   unsigned long x, z;   int err, cipher_idx, hash_idx;   fprintf(stderr, "\nMAC Timings (cycles/byte on %luKB blocks):\n", MAC_SIZE);   buf = XMALLOC(MAC_SIZE*1024);   if (buf == NULL) {      fprintf(stderr, "\n\nout of heap yo\n\n");      exit(EXIT_FAILURE);   }   cipher_idx = find_cipher("aes");   hash_idx   = find_hash("md5");   yarrow_read(buf, MAC_SIZE*1024, &yarrow_prng);   yarrow_read(key, 16, &yarrow_prng);#ifdef OMAC   t2 = -1;   for (x = 0; x < 10000; x++) {        t_start();        t1 = t_read();        z = 16;        if ((err = omac_memory(cipher_idx, key, 16, buf, MAC_SIZE*1024, tag, &z)) != CRYPT_OK) {           fprintf(stderr, "\n\nomac error... %s\n", error_to_string(err));           exit(EXIT_FAILURE);        }        t1 = t_read() - t1;        if (t1 < t2) t2 = t1;   }   fprintf(stderr, "OMAC-AES\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));#endif#ifdef PMAC   t2 = -1;   for (x = 0; x < 10000; x++) {        t_start();        t1 = t_read();        z = 16;        if ((err = pmac_memory(cipher_idx, key, 16, buf, MAC_SIZE*1024, tag, &z)) != CRYPT_OK) {           fprintf(stderr, "\n\npmac error... %s\n", error_to_string(err));           exit(EXIT_FAILURE);        }        t1 = t_read() - t1;        if (t1 < t2) t2 = t1;   }   fprintf(stderr, "PMAC-AES\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));#endif#ifdef PELICAN   t2 = -1;   for (x = 0; x < 10000; x++) {        t_start();        t1 = t_read();        z = 16;        if ((err = pelican_memory(key, 16, buf, MAC_SIZE*1024, tag)) != CRYPT_OK) {           fprintf(stderr, "\n\npelican error... %s\n", error_to_string(err));           exit(EXIT_FAILURE);        }        t1 = t_read() - t1;        if (t1 < t2) t2 = t1;   }   fprintf(stderr, "PELICAN \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));#endif#ifdef HMAC   t2 = -1;   for (x = 0; x < 10000; x++) {        t_start();        t1 = t_read();        z = 16;        if ((err = hmac_memory(hash_idx, key, 16, buf, MAC_SIZE*1024, tag, &z)) != CRYPT_OK) {           fprintf(stderr, "\n\nhmac error... %s\n", error_to_string(err));           exit(EXIT_FAILURE);        }        t1 = t_read() - t1;        if (t1 < t2) t2 = t1;   }   fprintf(stderr, "HMAC-MD5\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));#endif   XFREE(buf);}void time_macs(void){   time_macs_(1);   time_macs_(4);   time_macs_(32);}void time_encmacs_(unsigned long MAC_SIZE){   unsigned char *buf, IV[16], key[16], tag[16];   ulong64 t1, t2;   unsigned long x, z;   int err, cipher_idx;   fprintf(stderr, "\nENC+MAC Timings (zero byte AAD, 16 byte IV, cycles/byte on %luKB blocks):\n", MAC_SIZE);   buf = XMALLOC(MAC_SIZE*1024);   if (buf == NULL) {      fprintf(stderr, "\n\nout of heap yo\n\n");      exit(EXIT_FAILURE);   }   cipher_idx = find_cipher("aes");   yarrow_read(buf, MAC_SIZE*1024, &yarrow_prng);   yarrow_read(key, 16, &yarrow_prng);   yarrow_read(IV, 16, &yarrow_prng);#ifdef EAX_MODE   t2 = -1;   for (x = 0; x < 10000; x++) {        t_start();        t1 = t_read();        z = 16;        if ((err = eax_encrypt_authenticate_memory(cipher_idx, key, 16, IV, 16, NULL, 0, buf, MAC_SIZE*1024, buf, tag, &z)) != CRYPT_OK) {           fprintf(stderr, "\nEAX error... %s\n", error_to_string(err));           exit(EXIT_FAILURE);        }        t1 = t_read() - t1;        if (t1 < t2) t2 = t1;   }   fprintf(stderr, "EAX \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));#endif#ifdef OCB_MODE   t2 = -1;   for (x = 0; x < 10000; x++) {        t_start();        t1 = t_read();        z = 16;        if ((err = ocb_encrypt_authenticate_memory(cipher_idx, key, 16, IV, buf, MAC_SIZE*1024, buf, tag, &z)) != CRYPT_OK) {           fprintf(stderr, "\nOCB error... %s\n", error_to_string(err));           exit(EXIT_FAILURE);        }        t1 = t_read() - t1;        if (t1 < t2) t2 = t1;   }   fprintf(stderr, "OCB \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));#endif#ifdef CCM_MODE   t2 = -1;   for (x = 0; x < 10000; x++) {        t_start();        t1 = t_read();        z = 16;        if ((err = ccm_memory(cipher_idx, key, 16, IV, 16, NULL, 0, buf, MAC_SIZE*1024, buf, tag, &z, CCM_ENCRYPT)) != CRYPT_OK) {           fprintf(stderr, "\nCCM error... %s\n", error_to_string(err));           exit(EXIT_FAILURE);        }        t1 = t_read() - t1;        if (t1 < t2) t2 = t1;   }   fprintf(stderr, "CCM \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));#endif#ifdef GCM_MODE   t2 = -1;   for (x = 0; x < 100; x++) {        t_start();        t1 = t_read();        z = 16;        if ((err = gcm_memory(cipher_idx, key, 16, IV, 16, NULL, 0, buf, MAC_SIZE*1024, buf, tag, &z, GCM_ENCRYPT)) != CRYPT_OK) {           fprintf(stderr, "\nGCM error... %s\n", error_to_string(err));           exit(EXIT_FAILURE);        }        t1 = t_read() - t1;        if (t1 < t2) t2 = t1;   }   fprintf(stderr, "GCM (no-precomp)\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));   {   gcm_state gcm;   if ((err = gcm_init(&gcm, cipher_idx, key, 16)) != CRYPT_OK) { fprintf(stderr, "gcm_init: %s\n", error_to_string(err)); exit(EXIT_FAILURE); }   t2 = -1;   for (x = 0; x < 10000; x++) {        t_start();        t1 = t_read();        z = 16;        if ((err = gcm_reset(&gcm)) != CRYPT_OK) {            fprintf(stderr, "\nGCM error[%d]... %s\n", __LINE__, error_to_string(err));           exit(EXIT_FAILURE);        }        if ((err = gcm_add_iv(&gcm, IV, 16)) != CRYPT_OK) {            fprintf(stderr, "\nGCM error[%d]... %s\n", __LINE__, error_to_string(err));           exit(EXIT_FAILURE);        }        if ((err = gcm_add_aad(&gcm, NULL, 0)) != CRYPT_OK) {            fprintf(stderr, "\nGCM error[%d]... %s\n", __LINE__, error_to_string(err));           exit(EXIT_FAILURE);        }        if ((err = gcm_process(&gcm, buf, MAC_SIZE*1024, buf, GCM_ENCRYPT)) != CRYPT_OK) {            fprintf(stderr, "\nGCM error[%d]... %s\n", __LINE__, error_to_string(err));           exit(EXIT_FAILURE);        }                if ((err = gcm_done(&gcm, tag, &z)) != CRYPT_OK) {            fprintf(stderr, "\nGCM error[%d]... %s\n", __LINE__, error_to_string(err));           exit(EXIT_FAILURE);        }        t1 = t_read() - t1;        if (t1 < t2) t2 = t1;   }   fprintf(stderr, "GCM (precomp)\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));   }#endif} void time_encmacs(void){   time_encmacs_(1);   time_encmacs_(4);   time_encmacs_(32);}/* $Source: /cvs/libtom/libtomcrypt/testprof/x86_prof.c,v $ *//* $Revision: 1.16 $ *//* $Date: 2005/06/14 20:44:23 $ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -