add PIC32 current_time() to benchmark

This commit is contained in:
Chris Conlon
2013-01-30 16:29:15 -07:00
parent 95e7226447
commit 2fc54ad751

View File

@@ -83,7 +83,7 @@ void bench_eccKeyGen(void);
void bench_eccKeyAgree(void); void bench_eccKeyAgree(void);
#endif #endif
double current_time(void); double current_time(int);
#ifdef HAVE_CAVIUM #ifdef HAVE_CAVIUM
@@ -239,12 +239,12 @@ void bench_aes(int show)
#endif #endif
AesSetKey(&enc, key, 16, iv, AES_ENCRYPTION); AesSetKey(&enc, key, 16, iv, AES_ENCRYPTION);
start = current_time(); start = current_time(1);
for(i = 0; i < numBlocks; i++) for(i = 0; i < numBlocks; i++)
AesCbcEncrypt(&enc, plain, cipher, sizeof(plain)); AesCbcEncrypt(&enc, plain, cipher, sizeof(plain));
total = current_time() - start; total = current_time(0) - start;
persec = 1 / total * numBlocks; persec = 1 / total * numBlocks;
#ifdef BENCH_EMBEDDED #ifdef BENCH_EMBEDDED
@@ -274,13 +274,13 @@ void bench_aesgcm(void)
int i; int i;
AesGcmSetKey(&enc, key, 16); AesGcmSetKey(&enc, key, 16);
start = current_time(); start = current_time(1);
for(i = 0; i < numBlocks; i++) for(i = 0; i < numBlocks; i++)
AesGcmEncrypt(&enc, cipher, plain, sizeof(plain), iv, 12, AesGcmEncrypt(&enc, cipher, plain, sizeof(plain), iv, 12,
tag, 16, additional, 13); tag, 16, additional, 13);
total = current_time() - start; total = current_time(0) - start;
persec = 1 / total * numBlocks; persec = 1 / total * numBlocks;
#ifdef BENCH_EMBEDDED #ifdef BENCH_EMBEDDED
@@ -302,13 +302,13 @@ void bench_aesccm(void)
int i; int i;
AesCcmSetKey(&enc, key, 16); AesCcmSetKey(&enc, key, 16);
start = current_time(); start = current_time(1);
for(i = 0; i < numBlocks; i++) for(i = 0; i < numBlocks; i++)
AesCcmEncrypt(&enc, cipher, plain, sizeof(plain), iv, 12, AesCcmEncrypt(&enc, cipher, plain, sizeof(plain), iv, 12,
tag, 16, additional, 13); tag, 16, additional, 13);
total = current_time() - start; total = current_time(0) - start;
persec = 1 / total * numBlocks; persec = 1 / total * numBlocks;
#ifdef BENCH_EMBEDDED #ifdef BENCH_EMBEDDED
@@ -330,12 +330,12 @@ void bench_camellia(void)
int i; int i;
CamelliaSetKey(&cam, key, 16, iv); CamelliaSetKey(&cam, key, 16, iv);
start = current_time(); start = current_time(1);
for(i = 0; i < numBlocks; i++) for(i = 0; i < numBlocks; i++)
CamelliaCbcEncrypt(&cam, plain, cipher, sizeof(plain)); CamelliaCbcEncrypt(&cam, plain, cipher, sizeof(plain));
total = current_time() - start; total = current_time(0) - start;
persec = 1 / total * numBlocks; persec = 1 / total * numBlocks;
#ifdef BENCH_EMBEDDED #ifdef BENCH_EMBEDDED
@@ -361,12 +361,12 @@ void bench_des(void)
printf("des3 init cavium failed\n"); printf("des3 init cavium failed\n");
#endif #endif
Des3_SetKey(&enc, key, iv, DES_ENCRYPTION); Des3_SetKey(&enc, key, iv, DES_ENCRYPTION);
start = current_time(); start = current_time(1);
for(i = 0; i < numBlocks; i++) for(i = 0; i < numBlocks; i++)
Des3_CbcEncrypt(&enc, plain, cipher, sizeof(plain)); Des3_CbcEncrypt(&enc, plain, cipher, sizeof(plain));
total = current_time() - start; total = current_time(0) - start;
persec = 1 / total * numBlocks; persec = 1 / total * numBlocks;
#ifdef BENCH_EMBEDDED #ifdef BENCH_EMBEDDED
@@ -396,12 +396,12 @@ void bench_arc4(void)
#endif #endif
Arc4SetKey(&enc, key, 16); Arc4SetKey(&enc, key, 16);
start = current_time(); start = current_time(1);
for(i = 0; i < numBlocks; i++) for(i = 0; i < numBlocks; i++)
Arc4Process(&enc, cipher, plain, sizeof(plain)); Arc4Process(&enc, cipher, plain, sizeof(plain));
total = current_time() - start; total = current_time(0) - start;
persec = 1 / total * numBlocks; persec = 1 / total * numBlocks;
#ifdef BENCH_EMBEDDED #ifdef BENCH_EMBEDDED
/* since using kB, convert to MB/s */ /* since using kB, convert to MB/s */
@@ -425,12 +425,12 @@ void bench_hc128(void)
int i; int i;
Hc128_SetKey(&enc, key, iv); Hc128_SetKey(&enc, key, iv);
start = current_time(); start = current_time(1);
for(i = 0; i < numBlocks; i++) for(i = 0; i < numBlocks; i++)
Hc128_Process(&enc, cipher, plain, sizeof(plain)); Hc128_Process(&enc, cipher, plain, sizeof(plain));
total = current_time() - start; total = current_time(0) - start;
persec = 1 / total * numBlocks; persec = 1 / total * numBlocks;
#ifdef BENCH_EMBEDDED #ifdef BENCH_EMBEDDED
/* since using kB, convert to MB/s */ /* since using kB, convert to MB/s */
@@ -451,12 +451,12 @@ void bench_rabbit(void)
int i; int i;
RabbitSetKey(&enc, key, iv); RabbitSetKey(&enc, key, iv);
start = current_time(); start = current_time(1);
for(i = 0; i < numBlocks; i++) for(i = 0; i < numBlocks; i++)
RabbitProcess(&enc, cipher, plain, sizeof(plain)); RabbitProcess(&enc, cipher, plain, sizeof(plain));
total = current_time() - start; total = current_time(0) - start;
persec = 1 / total * numBlocks; persec = 1 / total * numBlocks;
#ifdef BENCH_EMBEDDED #ifdef BENCH_EMBEDDED
/* since using kB, convert to MB/s */ /* since using kB, convert to MB/s */
@@ -478,14 +478,14 @@ void bench_md5(void)
int i; int i;
InitMd5(&hash); InitMd5(&hash);
start = current_time(); start = current_time(1);
for(i = 0; i < numBlocks; i++) for(i = 0; i < numBlocks; i++)
Md5Update(&hash, plain, sizeof(plain)); Md5Update(&hash, plain, sizeof(plain));
Md5Final(&hash, digest); Md5Final(&hash, digest);
total = current_time() - start; total = current_time(0) - start;
persec = 1 / total * numBlocks; persec = 1 / total * numBlocks;
#ifdef BENCH_EMBEDDED #ifdef BENCH_EMBEDDED
/* since using kB, convert to MB/s */ /* since using kB, convert to MB/s */
@@ -506,14 +506,14 @@ void bench_sha(void)
int i; int i;
InitSha(&hash); InitSha(&hash);
start = current_time(); start = current_time(1);
for(i = 0; i < numBlocks; i++) for(i = 0; i < numBlocks; i++)
ShaUpdate(&hash, plain, sizeof(plain)); ShaUpdate(&hash, plain, sizeof(plain));
ShaFinal(&hash, digest); ShaFinal(&hash, digest);
total = current_time() - start; total = current_time(0) - start;
persec = 1 / total * numBlocks; persec = 1 / total * numBlocks;
#ifdef BENCH_EMBEDDED #ifdef BENCH_EMBEDDED
/* since using kB, convert to MB/s */ /* since using kB, convert to MB/s */
@@ -534,14 +534,14 @@ void bench_sha256(void)
int i; int i;
InitSha256(&hash); InitSha256(&hash);
start = current_time(); start = current_time(1);
for(i = 0; i < numBlocks; i++) for(i = 0; i < numBlocks; i++)
Sha256Update(&hash, plain, sizeof(plain)); Sha256Update(&hash, plain, sizeof(plain));
Sha256Final(&hash, digest); Sha256Final(&hash, digest);
total = current_time() - start; total = current_time(0) - start;
persec = 1 / total * numBlocks; persec = 1 / total * numBlocks;
#ifdef BENCH_EMBEDDED #ifdef BENCH_EMBEDDED
/* since using kB, convert to MB/s */ /* since using kB, convert to MB/s */
@@ -562,14 +562,14 @@ void bench_sha512(void)
int i; int i;
InitSha512(&hash); InitSha512(&hash);
start = current_time(); start = current_time(1);
for(i = 0; i < numBlocks; i++) for(i = 0; i < numBlocks; i++)
Sha512Update(&hash, plain, sizeof(plain)); Sha512Update(&hash, plain, sizeof(plain));
Sha512Final(&hash, digest); Sha512Final(&hash, digest);
total = current_time() - start; total = current_time(0) - start;
persec = 1 / total * numBlocks; persec = 1 / total * numBlocks;
#ifdef BENCH_EMBEDDED #ifdef BENCH_EMBEDDED
/* since using kB, convert to MB/s */ /* since using kB, convert to MB/s */
@@ -590,14 +590,14 @@ void bench_ripemd(void)
int i; int i;
InitRipeMd(&hash); InitRipeMd(&hash);
start = current_time(); start = current_time(1);
for(i = 0; i < numBlocks; i++) for(i = 0; i < numBlocks; i++)
RipeMdUpdate(&hash, plain, sizeof(plain)); RipeMdUpdate(&hash, plain, sizeof(plain));
RipeMdFinal(&hash, digest); RipeMdFinal(&hash, digest);
total = current_time() - start; total = current_time(0) - start;
persec = 1 / total * numBlocks; persec = 1 / total * numBlocks;
#ifdef BENCH_EMBEDDED #ifdef BENCH_EMBEDDED
/* since using kB, convert to MB/s */ /* since using kB, convert to MB/s */
@@ -654,26 +654,26 @@ void bench_rsa(void)
InitRsaKey(&rsaKey, 0); InitRsaKey(&rsaKey, 0);
bytes = RsaPrivateKeyDecode(tmp, &idx, &rsaKey, (word32)bytes); bytes = RsaPrivateKeyDecode(tmp, &idx, &rsaKey, (word32)bytes);
start = current_time(); start = current_time(1);
for (i = 0; i < times; i++) for (i = 0; i < times; i++)
bytes = RsaPublicEncrypt(message,len,enc,sizeof(enc), &rsaKey, &rng); bytes = RsaPublicEncrypt(message,len,enc,sizeof(enc), &rsaKey, &rng);
total = current_time() - start; total = current_time(0) - start;
each = total / times; /* per second */ each = total / times; /* per second */
milliEach = each * 1000; /* milliseconds */ milliEach = each * 1000; /* milliseconds */
printf("RSA %d encryption took %6.2f milliseconds, avg over %d" printf("RSA %d encryption took %6.2f milliseconds, avg over %d"
" iterations\n", rsaKeySz, milliEach, times); " iterations\n", rsaKeySz, milliEach, times);
start = current_time(); start = current_time(1);
for (i = 0; i < times; i++) { for (i = 0; i < times; i++) {
byte out[512]; /* for up to 4096 bit */ byte out[512]; /* for up to 4096 bit */
RsaPrivateDecrypt(enc, (word32)bytes, out, sizeof(out), &rsaKey); RsaPrivateDecrypt(enc, (word32)bytes, out, sizeof(out), &rsaKey);
} }
total = current_time() - start; total = current_time(0) - start;
each = total / times; /* per second */ each = total / times; /* per second */
milliEach = each * 1000; /* milliseconds */ milliEach = each * 1000; /* milliseconds */
@@ -730,12 +730,12 @@ void bench_dh(void)
return; return;
} }
start = current_time(); start = current_time(1);
for (i = 0; i < times; i++) for (i = 0; i < times; i++)
DhGenerateKeyPair(&dhKey, &rng, priv, &privSz, pub, &pubSz); DhGenerateKeyPair(&dhKey, &rng, priv, &privSz, pub, &pubSz);
total = current_time() - start; total = current_time(0) - start;
each = total / times; /* per second */ each = total / times; /* per second */
milliEach = each * 1000; /* milliseconds */ milliEach = each * 1000; /* milliseconds */
@@ -743,12 +743,12 @@ void bench_dh(void)
" iterations\n", milliEach, times); " iterations\n", milliEach, times);
DhGenerateKeyPair(&dhKey, &rng, priv2, &privSz2, pub2, &pubSz2); DhGenerateKeyPair(&dhKey, &rng, priv2, &privSz2, pub2, &pubSz2);
start = current_time(); start = current_time(1);
for (i = 0; i < times; i++) for (i = 0; i < times; i++)
DhAgree(&dhKey, agree, &agreeSz, priv, privSz, pub2, pubSz2); DhAgree(&dhKey, agree, &agreeSz, priv, privSz, pub2, pubSz2);
total = current_time() - start; total = current_time(0) - start;
each = total / times; /* per second */ each = total / times; /* per second */
milliEach = each * 1000; /* milliseconds */ milliEach = each * 1000; /* milliseconds */
@@ -771,7 +771,7 @@ void bench_rsaKeyGen(void)
const int genTimes = 5; const int genTimes = 5;
/* 1024 bit */ /* 1024 bit */
start = current_time(); start = current_time(1);
for(i = 0; i < genTimes; i++) { for(i = 0; i < genTimes; i++) {
InitRsaKey(&genKey, 0); InitRsaKey(&genKey, 0);
@@ -779,7 +779,7 @@ void bench_rsaKeyGen(void)
FreeRsaKey(&genKey); FreeRsaKey(&genKey);
} }
total = current_time() - start; total = current_time(0) - start;
each = total / genTimes; /* per second */ each = total / genTimes; /* per second */
milliEach = each * 1000; /* millisconds */ milliEach = each * 1000; /* millisconds */
printf("\n"); printf("\n");
@@ -787,7 +787,7 @@ void bench_rsaKeyGen(void)
" iterations\n", milliEach, genTimes); " iterations\n", milliEach, genTimes);
/* 2048 bit */ /* 2048 bit */
start = current_time(); start = current_time(1);
for(i = 0; i < genTimes; i++) { for(i = 0; i < genTimes; i++) {
InitRsaKey(&genKey, 0); InitRsaKey(&genKey, 0);
@@ -795,7 +795,7 @@ void bench_rsaKeyGen(void)
FreeRsaKey(&genKey); FreeRsaKey(&genKey);
} }
total = current_time() - start; total = current_time(0) - start;
each = total / genTimes; /* per second */ each = total / genTimes; /* per second */
milliEach = each * 1000; /* millisconds */ milliEach = each * 1000; /* millisconds */
printf("RSA 2048 key generation %6.2f milliseconds, avg over %d" printf("RSA 2048 key generation %6.2f milliseconds, avg over %d"
@@ -812,14 +812,14 @@ void bench_eccKeyGen(void)
const int genTimes = 5; const int genTimes = 5;
/* 256 bit */ /* 256 bit */
start = current_time(); start = current_time(1);
for(i = 0; i < genTimes; i++) { for(i = 0; i < genTimes; i++) {
ecc_make_key(&rng, 32, &genKey); ecc_make_key(&rng, 32, &genKey);
ecc_free(&genKey); ecc_free(&genKey);
} }
total = current_time() - start; total = current_time(0) - start;
each = total / genTimes; /* per second */ each = total / genTimes; /* per second */
milliEach = each * 1000; /* millisconds */ milliEach = each * 1000; /* millisconds */
printf("\n"); printf("\n");
@@ -843,14 +843,14 @@ void bench_eccKeyAgree(void)
ecc_make_key(&rng, 32, &genKey2); ecc_make_key(&rng, 32, &genKey2);
/* 256 bit */ /* 256 bit */
start = current_time(); start = current_time(1);
for(i = 0; i < agreeTimes; i++) { for(i = 0; i < agreeTimes; i++) {
x = sizeof(shared); x = sizeof(shared);
ecc_shared_secret(&genKey, &genKey2, shared, &x); ecc_shared_secret(&genKey, &genKey2, shared, &x);
} }
total = current_time() - start; total = current_time(0) - start;
each = total / agreeTimes; /* per second */ each = total / agreeTimes; /* per second */
milliEach = each * 1000; /* millisconds */ milliEach = each * 1000; /* millisconds */
printf("EC-DHE key agreement %6.2f milliseconds, avg over %d" printf("EC-DHE key agreement %6.2f milliseconds, avg over %d"
@@ -861,14 +861,14 @@ void bench_eccKeyAgree(void)
digest[i] = i; digest[i] = i;
start = current_time(); start = current_time(1);
for(i = 0; i < agreeTimes; i++) { for(i = 0; i < agreeTimes; i++) {
x = sizeof(sig); x = sizeof(sig);
ecc_sign_hash(digest, sizeof(digest), sig, &x, &rng, &genKey); ecc_sign_hash(digest, sizeof(digest), sig, &x, &rng, &genKey);
} }
total = current_time() - start; total = current_time(0) - start;
each = total / agreeTimes; /* per second */ each = total / agreeTimes; /* per second */
milliEach = each * 1000; /* millisconds */ milliEach = each * 1000; /* millisconds */
printf("EC-DSA sign time %6.2f milliseconds, avg over %d" printf("EC-DSA sign time %6.2f milliseconds, avg over %d"
@@ -885,8 +885,10 @@ void bench_eccKeyAgree(void)
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
double current_time() double current_time(int reset)
{ {
(void)reset;
static int init = 0; static int init = 0;
static LARGE_INTEGER freq; static LARGE_INTEGER freq;
@@ -902,12 +904,38 @@ void bench_eccKeyAgree(void)
return (double)count.QuadPart / freq.QuadPart; return (double)count.QuadPart / freq.QuadPart;
} }
#elif defined MICROCHIP_PIC32
#include <peripheral/timer.h>
double current_time(int reset)
{
/* NOTE: core timer tick rate = 40 Mhz, 1 tick = 25 ns */
unsigned int ns;
/* should we reset our timer back to zero? Helps prevent timer
rollover */
if (reset) {
WriteCoreTimer(0);
}
/* get timer in ns */
ns = ReadCoreTimer() * 25;
/* return seconds as a double */
return ( ns / 1000000000.0 );
}
#else #else
#include <sys/time.h> #include <sys/time.h>
double current_time(void) double current_time(int reset)
{ {
(void) reset;
struct timeval tv; struct timeval tv;
gettimeofday(&tv, 0); gettimeofday(&tv, 0);