25 #include "runtime.hpp"
28 #include "twofish.hpp"
29 #include "blowfish.hpp"
39 using namespace TaoCrypt;
41 void bench_aes(
bool show);
43 void bench_blowfish();
55 double current_time();
60 int main(
int argc,
char** argv)
88 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
89 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
90 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
95 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
96 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
97 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
102 byte plain [1024*1024];
103 byte cipher[1024*1024];
109 enc.SetKey(key, 16, iv);
111 double start = current_time();
113 for(
int i = 0;
i < megs;
i++)
114 enc.Process(plain, cipher,
sizeof(plain));
116 double total = current_time() - start;
118 double persec = 1 / total * megs;
120 printf(
"3DES %d megs took %5.3f seconds, %6.2f MB/s\n", megs, total,
125 void bench_aes(
bool show)
128 enc.SetKey(key, 16, iv);
130 double start = current_time();
132 for(
int i = 0;
i < megs;
i++)
133 enc.Process(plain, cipher,
sizeof(plain));
135 double total = current_time() - start;
137 double persec = 1 / total * megs;
140 printf(
"AES %d megs took %5.3f seconds, %6.2f MB/s\n", megs, total,
148 enc.SetKey(key, 16, iv);
150 double start = current_time();
152 for(
int i = 0;
i < megs;
i++)
153 enc.Process(plain, cipher,
sizeof(plain));
155 double total = current_time() - start;
157 double persec = 1 / total * megs;
159 printf(
"Twofish %d megs took %5.3f seconds, %6.2f MB/s\n", megs, total,
165 void bench_blowfish()
168 enc.SetKey(key, 16, iv);
170 double start = current_time();
172 for(
int i = 0;
i < megs;
i++)
173 enc.Process(plain, cipher,
sizeof(plain));
175 double total = current_time() - start;
177 double persec = 1 / total * megs;
179 printf(
"Blowfish %d megs took %5.3f seconds, %6.2f MB/s\n", megs, total,
189 double start = current_time();
191 for(
int i = 0;
i < megs;
i++)
192 enc.Process(cipher, plain,
sizeof(plain));
194 double total = current_time() - start;
196 double persec = 1 / total * megs;
198 printf(
"ARC4 %d megs took %5.3f seconds, %6.2f MB/s\n", megs, total,
206 byte digest[MD5::DIGEST_SIZE];
208 double start = current_time();
211 for(
int i = 0;
i < megs;
i++)
212 hash.Update(plain,
sizeof(plain));
216 double total = current_time() - start;
218 double persec = 1 / total * megs;
220 printf(
"MD5 %d megs took %5.3f seconds, %6.2f MB/s\n", megs, total,
228 byte digest[SHA::DIGEST_SIZE];
230 double start = current_time();
233 for(
int i = 0;
i < megs;
i++)
234 hash.Update(plain,
sizeof(plain));
244 double total = current_time() - start;
246 double persec = 1 / total * megs;
248 printf(
"SHA %d megs took %5.3f seconds, %6.2f MB/s\n", megs, total,
256 byte digest[RIPEMD160::DIGEST_SIZE];
258 double start = current_time();
261 for(
int i = 0;
i < megs;
i++)
262 hash.Update(plain,
sizeof(plain));
266 double total = current_time() - start;
268 double persec = 1 / total * megs;
270 printf(
"RIPEMD %d megs took %5.3f seconds, %6.2f MB/s\n", megs, total,
278 const int times = 100;
283 if (source.size() == 0) {
284 printf(
"can't find ./rsa1024.der\n");
290 byte
message[] =
"Everyone gets Friday off.";
293 const int len = (word32)strlen((
char*)message);
296 double start = current_time();
298 for (i = 0; i < times; i++)
299 enc.Encrypt(message, len, cipher, rng);
301 double total = current_time() - start;
302 double each = total / times;
303 double milliEach = each * 1000;
305 printf(
"RSA 1024 encryption took %6.2f milliseconds, avg over %d"
306 " iterations\n", milliEach, times);
310 start = current_time();
312 for (i = 0; i < times; i++)
313 dec.Decrypt(cipher, 128, plain, rng);
315 total = current_time() - start;
316 each = total / times;
317 milliEach = each * 1000;
319 printf(
"RSA 1024 decryption took %6.2f milliseconds, avg over %d"
320 " iterations\n", milliEach, times);
326 const int times = 100;
331 if (source.size() == 0) {
332 printf(
"can't find ./dh1024.der\n");
341 double start = current_time();
343 for (i = 0; i < times; i++)
344 dh.GenerateKeyPair(rng, priv, pub);
346 double total = current_time() - start;
347 double each = total / times;
348 double milliEach = each * 1000;
350 printf(
"DH 1024 key generation %6.2f milliseconds, avg over %d"
351 " iterations\n", milliEach, times);
356 dh2.GenerateKeyPair(rng, priv2, pub2);
357 unsigned char key[256];
359 start = current_time();
361 for (i = 0; i < times; i++)
362 dh.Agree(key, priv, pub2);
364 total = current_time() - start;
365 each = total / times;
366 milliEach = each * 1000;
368 printf(
"DH 1024 key agreement %6.2f milliseconds, avg over %d"
369 " iterations\n", milliEach, times);
374 const int times = 100;
379 if (source.size() == 0) {
380 printf(
"can't find ./dsa1024.der\n");
388 byte digest[SHA::DIGEST_SIZE];
390 const char msg[] =
"this is the message";
391 sha.Update((byte*)msg,
sizeof(msg));
395 double start = current_time();
397 for (i = 0; i < times; i++)
398 signer.Sign(digest, signature, rng);
400 double total = current_time() - start;
401 double each = total / times;
402 double milliEach = each * 1000;
404 printf(
"DSA 1024 sign took %6.2f milliseconds, avg over %d"
405 " iterations\n", milliEach, times);
409 start = current_time();
411 for (i = 0; i < times; i++)
412 verifier.Verify(digest, signature);
414 total = current_time() - start;
415 each = total / times;
416 milliEach = each * 1000;
418 printf(
"DSA 1024 verify took %6.2f milliseconds, avg over %d"
419 " iterations\n", milliEach, times);
426 #define WIN32_LEAN_AND_MEAN
429 double current_time()
431 static bool init(
false);
432 static LARGE_INTEGER freq;
435 QueryPerformanceFrequency(&freq);
440 QueryPerformanceCounter(&count);
442 return static_cast<double>(count.QuadPart) / freq.QuadPart;
447 #include <sys/time.h>
449 double current_time()
452 gettimeofday(&tv, 0);
454 return static_cast<double>(tv.tv_sec)
455 + static_cast<double>(tv.tv_usec) / 1000000;