Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

bench.cpp

00001 // bench.cpp - written and placed in the public domain by Wei Dai
00002 
00003 #include "pch.h"
00004 
00005 #include "crc.h"
00006 #include "adler32.h"
00007 #include "md2.h"
00008 #include "md5.h"
00009 #include "md5mac.h"
00010 #include "sha.h"
00011 #include "haval.h"
00012 #include "tiger.h"
00013 #include "ripemd.h"
00014 #include "panama.h"
00015 #include "idea.h"
00016 #include "des.h"
00017 #include "rc2.h"
00018 #include "arc4.h"
00019 #include "rc5.h"
00020 #include "blowfish.h"
00021 #include "diamond.h"
00022 #include "wake.h"
00023 #include "3way.h"
00024 #include "safer.h"
00025 #include "gost.h"
00026 #include "shark.h"
00027 #include "cast.h"
00028 #include "square.h"
00029 #include "skipjack.h"
00030 #include "seal.h"
00031 #include "rc6.h"
00032 #include "mars.h"
00033 #include "rijndael.h"
00034 #include "twofish.h"
00035 #include "serpent.h"
00036 #include "hmac.h"
00037 #include "xormac.h"
00038 #include "cbcmac.h"
00039 #include "dmac.h"
00040 #include "blumshub.h"
00041 #include "rsa.h"
00042 #include "elgamal.h"
00043 #include "nr.h"
00044 #include "dsa.h"
00045 #include "luc.h"
00046 #include "rabin.h"
00047 #include "rw.h"
00048 #include "blumgold.h"
00049 #include "eccrypto.h"
00050 #include "ecp.h"
00051 #include "ec2n.h"
00052 #include "asn.h"
00053 #include "rng.h"
00054 #include "files.h"
00055 #include "hex.h"
00056 #include "modes.h"
00057 #include "mdc.h"
00058 #include "lubyrack.h"
00059 #include "sapphire.h"
00060 #include "tea.h"
00061 #include "dh.h"
00062 #include "mqv.h"
00063 #include "xtrcrypt.h"
00064 
00065 #include "bench.h"
00066 
00067 #include <time.h>
00068 #include <math.h>
00069 #include <iostream>
00070 #include <iomanip>
00071 
00072 USING_NAMESPACE(CryptoPP)
00073 USING_NAMESPACE(std)
00074 
00075 #ifdef CLOCKS_PER_SEC
00076 static const double CLOCK_TICKS_PER_SECOND = (double)CLOCKS_PER_SEC;
00077 #elif defined(CLK_TCK)
00078 static const double CLOCK_TICKS_PER_SECOND = (double)CLK_TCK;
00079 #else
00080 static const double CLOCK_TICKS_PER_SECOND = 1000000.0;
00081 #endif
00082 
00083 static const byte *const key=(byte *)"0123456789abcdef000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
00084 
00085 static double logtotal = 0;
00086 static unsigned int logcount = 0;
00087 
00088 void OutputResultBytes(const char *name, unsigned long length, double timeTaken)
00089 {
00090         double mbs = length / timeTaken / (1024*1024);
00091         cout << "<TR><TH>" << name;
00092         cout << "<TD>" << length;
00093         cout << setiosflags(ios::fixed);
00094         cout << "<TD>" << setprecision(3) << timeTaken;
00095         cout << "<TD>" << setprecision(3) << mbs << endl;
00096         cout << resetiosflags(ios::fixed);
00097         logtotal += log(mbs);
00098         logcount++;
00099 }
00100 
00101 void OutputResultOperations(const char *name, const char *operation, bool pc, unsigned long iterations, double timeTaken)
00102 {
00103         cout << "<TR><TH>" << name << " " << operation << (pc ? " with precomputation" : "");
00104         cout << "<TD>" << iterations;
00105         cout << setiosflags(ios::fixed);
00106         cout << "<TD>" << setprecision(3) << timeTaken;
00107         cout << "<TD>" << setprecision(2) << (1000*timeTaken/iterations) << endl;
00108         cout << resetiosflags(ios::fixed);
00109 
00110         logtotal += log(iterations/timeTaken);
00111         logcount++;
00112 }
00113 
00114 void BenchMark(const char *name, BlockTransformation &cipher, double timeTotal)
00115 {
00116         const int BUF_SIZE = cipher.BlockSize();
00117         SecByteBlock buf(BUF_SIZE);
00118         clock_t start = clock();
00119 
00120         unsigned long i=0, length=BUF_SIZE;
00121         double timeTaken;
00122         do
00123         {
00124                 length *= 2;
00125                 for (; i<length; i+=BUF_SIZE)
00126                         cipher.ProcessBlock(buf);
00127                 timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND;
00128         }
00129         while (timeTaken < 2.0/3*timeTotal);
00130 
00131         OutputResultBytes(name, length, timeTaken);
00132 }
00133 
00134 void BenchMark(const char *name, StreamCipher &cipher, double timeTotal)
00135 {
00136         const int BUF_SIZE=128; // encrypt 128 bytes at a time
00137         SecByteBlock buf(BUF_SIZE);
00138         clock_t start = clock();
00139 
00140         unsigned long i=0, length=BUF_SIZE;
00141         double timeTaken;
00142         do
00143         {
00144                 length *= 2;
00145                 for (; i<length; i+=BUF_SIZE)
00146                         cipher.ProcessString(buf, BUF_SIZE);
00147                 timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND;
00148         }
00149         while (timeTaken < 2.0/3*timeTotal);
00150 
00151         OutputResultBytes(name, length, timeTaken);
00152 }
00153 
00154 void BenchMark(const char *name, HashModule &hash, double timeTotal)
00155 {
00156         const int BUF_SIZE=1024; // update 1024 bytes at a time
00157         SecByteBlock buf(BUF_SIZE);
00158         LC_RNG rng(time(NULL));
00159         rng.GenerateBlock(buf, BUF_SIZE);
00160         clock_t start = clock();
00161 
00162         unsigned long i=0, length=BUF_SIZE;
00163         double timeTaken;
00164         do
00165         {
00166                 length *= 2;
00167                 for (; i<length; i+=BUF_SIZE)
00168                         hash.Update(buf, BUF_SIZE);
00169                 timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND;
00170         }
00171         while (timeTaken < 2.0/3*timeTotal);
00172 
00173         OutputResultBytes(name, length, timeTaken);
00174 }
00175 
00176 void BenchMark(const char *name, BufferedTransformation &bt, double timeTotal)
00177 {
00178         const int BUF_SIZE=1024; // update 1024 bytes at a time
00179         SecByteBlock buf(BUF_SIZE);
00180         LC_RNG rng(time(NULL));
00181         rng.GenerateBlock(buf, BUF_SIZE);
00182         clock_t start = clock();
00183 
00184         unsigned long i=0, length=BUF_SIZE;
00185         double timeTaken;
00186         do
00187         {
00188                 length *= 2;
00189                 for (; i<length; i+=BUF_SIZE)
00190                         bt.Put(buf, BUF_SIZE);
00191                 timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND;
00192         }
00193         while (timeTaken < 2.0/3*timeTotal);
00194 
00195         OutputResultBytes(name, length, timeTaken);
00196 }
00197 
00198 void BenchMarkEncryption(const char *name, PK_Encryptor &key, double timeTotal, bool pc=false)
00199 {
00200         unsigned int len = 16;
00201         LC_RNG rng(time(NULL));
00202         SecByteBlock plaintext(len), ciphertext(key.CipherTextLength(len));
00203         rng.GetBlock(plaintext, len);
00204 
00205         clock_t start = clock();
00206         unsigned int i;
00207         double timeTaken;
00208         for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
00209                 key.Encrypt(rng, plaintext, len, ciphertext);
00210 
00211         OutputResultOperations(name, "Encryption", pc, i, timeTaken);
00212 }
00213 
00214 void BenchMarkEncryption(const char *name, PK_WithPrecomputation<PK_FixedLengthEncryptor> &key, double timeTotal)
00215 {
00216         BenchMarkEncryption(name, dynamic_cast<PK_Encryptor &>(key), timeTotal);
00217         key.Precompute(16);
00218         BenchMarkEncryption(name, dynamic_cast<PK_Encryptor &>(key), timeTotal, true);
00219 }
00220 
00221 void BenchMarkEncryption(const char *name, PK_WithPrecomputation<PK_Encryptor> &key, double timeTotal)
00222 {
00223         BenchMarkEncryption(name, dynamic_cast<PK_Encryptor &>(key), timeTotal);
00224         key.Precompute(16);
00225         BenchMarkEncryption(name, dynamic_cast<PK_Encryptor &>(key), timeTotal, true);
00226 }
00227 
00228 void BenchMarkDecryption(const char *name, PK_Decryptor &priv, PK_Encryptor &pub, double timeTotal)
00229 {
00230         unsigned int len = 16;
00231         LC_RNG rng(time(NULL));
00232         SecByteBlock ciphertext(pub.CipherTextLength(len));
00233         SecByteBlock plaintext(pub.MaxPlainTextLength(ciphertext.size));
00234         rng.GetBlock(plaintext, len);
00235         pub.Encrypt(rng, plaintext, len, ciphertext);
00236 
00237         clock_t start = clock();
00238         unsigned int i;
00239         double timeTaken;
00240         for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
00241                 priv.Decrypt(ciphertext, ciphertext.size, plaintext);
00242 
00243         OutputResultOperations(name, "Decryption", false, i, timeTaken);
00244 }
00245 
00246 void BenchMarkSigning(const char *name, PK_Signer &key, double timeTotal, bool pc=false)
00247 {
00248         unsigned int len = 16;
00249         LC_RNG rng(time(NULL));
00250         SecByteBlock message(len), signature(key.SignatureLength());
00251         rng.GetBlock(message, len);
00252 
00253         clock_t start = clock();
00254         unsigned int i;
00255         double timeTaken;
00256         for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
00257                 key.SignMessage(rng, message, len, signature);
00258 
00259         OutputResultOperations(name, "Signature", pc, i, timeTaken);
00260 }
00261 
00262 void BenchMarkSigning(const char *name, PK_WithPrecomputation<PK_Signer> &key, double timeTotal)
00263 {
00264         BenchMarkSigning(name, dynamic_cast<PK_Signer &>(key), timeTotal);
00265         key.Precompute(16);
00266         BenchMarkSigning(name, dynamic_cast<PK_Signer &>(key), timeTotal, true);
00267 }
00268 
00269 void BenchMarkVerification(const char *name, PK_Signer &priv, PK_Verifier &pub, double timeTotal, bool pc=false)
00270 {
00271         unsigned int len = 16;
00272         LC_RNG rng(time(NULL));
00273         SecByteBlock message(len), signature(pub.SignatureLength());
00274         rng.GetBlock(message, len);
00275         priv.SignMessage(rng, message, len, signature);
00276 
00277         clock_t start = clock();
00278         unsigned int i;
00279         double timeTaken;
00280         for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
00281                 pub.VerifyMessage(message, len, signature);
00282 
00283         OutputResultOperations(name, "Verification", pc, i, timeTaken);
00284 }
00285 
00286 void BenchMarkVerification(const char *name, PK_Signer &priv, PK_WithPrecomputation<PK_Verifier> &pub, double timeTotal)
00287 {
00288         BenchMarkVerification(name, priv, dynamic_cast<PK_Verifier &>(pub), timeTotal);
00289         pub.Precompute(16);
00290         BenchMarkVerification(name, priv, dynamic_cast<PK_Verifier &>(pub), timeTotal, true);
00291 }
00292 
00293 void BenchMarkKeyGen(const char *name, PK_SimpleKeyAgreementDomain &d, double timeTotal, bool pc=false)
00294 {
00295         LC_RNG rng(time(NULL));
00296         SecByteBlock priv(d.PrivateKeyLength()), pub(d.PublicKeyLength());
00297 
00298         clock_t start = clock();
00299         unsigned int i;
00300         double timeTaken;
00301         for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
00302                 d.GenerateKeyPair(rng, priv, pub);
00303 
00304         OutputResultOperations(name, "Key-Pair Generation", pc, i, timeTaken);
00305 }
00306 
00307 void BenchMarkKeyGen(const char *name, PK_WithPrecomputation<PK_SimpleKeyAgreementDomain> &d, double timeTotal)
00308 {
00309         BenchMarkKeyGen(name, dynamic_cast<PK_SimpleKeyAgreementDomain &>(d), timeTotal);
00310         d.Precompute(16);
00311         BenchMarkKeyGen(name, dynamic_cast<PK_SimpleKeyAgreementDomain &>(d), timeTotal, true);
00312 }
00313 
00314 void BenchMarkKeyGen(const char *name, PK_AuthenticatedKeyAgreementDomain &d, double timeTotal, bool pc=false)
00315 {
00316         LC_RNG rng(time(NULL));
00317         SecByteBlock priv(d.EphemeralPrivateKeyLength()), pub(d.EphemeralPublicKeyLength());
00318 
00319         clock_t start = clock();
00320         unsigned int i;
00321         double timeTaken;
00322         for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
00323                 d.GenerateEphemeralKeyPair(rng, priv, pub);
00324 
00325         OutputResultOperations(name, "Key-Pair Generation", pc, i, timeTaken);
00326 }
00327 
00328 void BenchMarkKeyGen(const char *name, PK_WithPrecomputation<PK_AuthenticatedKeyAgreementDomain> &d, double timeTotal)
00329 {
00330         BenchMarkKeyGen(name, dynamic_cast<PK_AuthenticatedKeyAgreementDomain &>(d), timeTotal);
00331         d.Precompute(16);
00332         BenchMarkKeyGen(name, dynamic_cast<PK_AuthenticatedKeyAgreementDomain &>(d), timeTotal, true);
00333 }
00334 
00335 void BenchMarkAgreement(const char *name, PK_SimpleKeyAgreementDomain &d, double timeTotal, bool pc=false)
00336 {
00337         LC_RNG rng(time(NULL));
00338         SecByteBlock priv1(d.PrivateKeyLength()), priv2(d.PrivateKeyLength());
00339         SecByteBlock pub1(d.PublicKeyLength()), pub2(d.PublicKeyLength());
00340         d.GenerateKeyPair(rng, priv1, pub1);
00341         d.GenerateKeyPair(rng, priv2, pub2);
00342         SecByteBlock val(d.AgreedValueLength());
00343 
00344         clock_t start = clock();
00345         unsigned int i;
00346         double timeTaken;
00347         for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i+=2)
00348         {
00349                 d.Agree(val, priv1, pub2);
00350                 d.Agree(val, priv2, pub1);
00351         }
00352 
00353         OutputResultOperations(name, "Key Agreement", pc, i, timeTaken);
00354 }
00355 
00356 void BenchMarkAgreement(const char *name, PK_AuthenticatedKeyAgreementDomain &d, double timeTotal, bool pc=false)
00357 {
00358         LC_RNG rng(time(NULL));
00359         SecByteBlock spriv1(d.StaticPrivateKeyLength()), spriv2(d.StaticPrivateKeyLength());
00360         SecByteBlock epriv1(d.EphemeralPrivateKeyLength()), epriv2(d.EphemeralPrivateKeyLength());
00361         SecByteBlock spub1(d.StaticPublicKeyLength()), spub2(d.StaticPublicKeyLength());
00362         SecByteBlock epub1(d.EphemeralPublicKeyLength()), epub2(d.EphemeralPublicKeyLength());
00363         d.GenerateStaticKeyPair(rng, spriv1, spub1);
00364         d.GenerateStaticKeyPair(rng, spriv2, spub2);
00365         d.GenerateEphemeralKeyPair(rng, epriv1, epub1);
00366         d.GenerateEphemeralKeyPair(rng, epriv2, epub2);
00367         SecByteBlock val(d.AgreedValueLength());
00368 
00369         clock_t start = clock();
00370         unsigned int i;
00371         double timeTaken;
00372         for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i+=2)
00373         {
00374                 d.Agree(val, spriv1, epriv1, spub2, epub2);
00375                 d.Agree(val, spriv2, epriv2, spub1, epub1);
00376         }
00377 
00378         OutputResultOperations(name, "Key Agreement", pc, i, timeTaken);
00379 }
00380 
00381 //VC60 workaround: compiler bug triggered without the extra dummy parameters
00382 template <class T>
00383 void BenchMarkKeyed(const char *name, double timeTotal, T *x=NULL)
00384 {
00385         T c(key);
00386         BenchMark(name, c, timeTotal);
00387 }
00388 
00389 //VC60 workaround: compiler bug triggered without the extra dummy parameters
00390 template <class T>
00391 void BenchMarkKeyedVariable(const char *name, double timeTotal, unsigned int keyLength, T *x=NULL)
00392 {
00393         T c(key, keyLength);
00394         BenchMark(name, c, timeTotal);
00395 }
00396 
00397 //VC60 workaround: compiler bug triggered without the extra dummy parameters
00398 template <class T>
00399 void BenchMarkKeyless(const char *name, double timeTotal, T *x=NULL)
00400 {
00401         T c;
00402         BenchMark(name, c, timeTotal);
00403 }
00404 
00405 //VC60 workaround: compiler bug triggered without the extra dummy parameters
00406 template <class D, class E>
00407 void BenchMarkCrypto(const char *filename, const char *name, double timeTotal, D *x=NULL, E *y=NULL)
00408 {
00409         FileSource f(filename, true, new HexDecoder());
00410         D priv(f);
00411         E pub(priv);
00412         BenchMarkEncryption(name, pub, timeTotal);
00413         BenchMarkDecryption(name, priv, pub, timeTotal);
00414 }
00415 
00416 //VC60 workaround: compiler bug triggered without the extra dummy parameters
00417 template <class S, class V>
00418 void BenchMarkSignature(const char *filename, const char *name, double timeTotal, S *x=NULL, V *y=NULL)
00419 {
00420         FileSource f(filename, true, new HexDecoder());
00421         S priv(f);
00422         V pub(priv);
00423         BenchMarkSigning(name, priv, timeTotal);
00424         BenchMarkVerification(name, priv, pub, timeTotal);
00425 }
00426 
00427 //VC60 workaround: compiler bug triggered without the extra dummy parameters
00428 template <class D>
00429 void BenchMarkKeyAgreement(const char *filename, const char *name, double timeTotal, D *x=NULL)
00430 {
00431         FileSource f(filename, true, new HexDecoder());
00432         D d(f);
00433         BenchMarkKeyGen(name, d, timeTotal);
00434         BenchMarkAgreement(name, d, timeTotal);
00435 }
00436 
00437 void BenchMarkAll(double t)
00438 {
00439         logtotal = 0;
00440         logcount = 0;
00441 
00442         cout << "<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right><COL align=right>" << endl;
00443         cout << "<THEAD><TR><TH>Algorithm<TH>Bytes Processed<TH>Time Taken<TH>Megabytes(2^20 bytes)/Second\n<TBODY>" << endl;
00444 
00445         BenchMarkKeyless<CRC32>("CRC-32", t);
00446         BenchMarkKeyless<Adler32>("Adler-32", t);
00447         BenchMarkKeyless<MD2>("MD2", t);
00448         BenchMarkKeyless<MD5>("MD5", t);
00449         BenchMarkKeyless<SHA>("SHA-1", t);
00450         BenchMarkKeyless<SHA256>("SHA-256", t);
00451         BenchMarkKeyless<SHA512>("SHA-512", t);
00452         BenchMarkKeyless<HAVAL3>("HAVAL (pass=3)", t);
00453         BenchMarkKeyless<HAVAL4>("HAVAL (pass=4)", t);
00454         BenchMarkKeyless<HAVAL5>("HAVAL (pass=5)", t);
00455 #ifdef WORD64_AVAILABLE
00456         BenchMarkKeyless<Tiger>("Tiger", t);
00457 #endif
00458         BenchMarkKeyless<RIPEMD160>("RIPE-MD160", t);
00459         BenchMarkKeyless<PanamaHash<false> >("Panama Hash (little endian)", t);
00460         BenchMarkKeyless<PanamaHash<true> >("Panama Hash (big endian)", t);
00461         BenchMarkKeyed<MDC<MD5> >("MDC/MD5", t);
00462         BenchMarkKeyed<LREncryption<MD5> >("Luby-Rackoff/MD5", t);
00463         BenchMarkKeyed<DESEncryption>("DES", t);
00464         BenchMarkKeyed<DES_XEX3_Encryption>("DES-XEX3", t);
00465         BenchMarkKeyed<DES_EDE3_Encryption>("DES-EDE3", t);
00466         BenchMarkKeyed<IDEAEncryption>("IDEA", t);
00467         BenchMarkKeyed<RC2Encryption>("RC2", t);
00468         BenchMarkKeyed<RC5Encryption>("RC5 (r=16)", t);
00469         BenchMarkKeyed<BlowfishEncryption>("Blowfish", t);
00470         BenchMarkKeyed<Diamond2Encryption>("Diamond2", t);
00471         BenchMarkKeyed<Diamond2LiteEncryption>("Diamond2 Lite", t);
00472         BenchMarkKeyed<ThreeWayDecryption>("3-WAY", t);
00473         BenchMarkKeyed<TEAEncryption>("TEA", t);
00474         BenchMarkKeyed<SAFER_SK64_Encryption>("SAFER (r=8)", t);
00475         BenchMarkKeyed<GOSTEncryption>("GOST", t);
00476 #ifdef WORD64_AVAILABLE
00477         BenchMarkKeyed<SHARKEncryption>("SHARK (r=6)", t);
00478 #endif
00479         BenchMarkKeyed<CAST128Encryption>("CAST-128", t);
00480         BenchMarkKeyed<CAST256Encryption>("CAST-256", t);
00481         BenchMarkKeyed<SquareEncryption>("Square", t);
00482         BenchMarkKeyed<SKIPJACKEncryption>("SKIPJACK", t);
00483         BenchMarkKeyed<RC6Encryption>("RC6", t);
00484         BenchMarkKeyed<MARSEncryption>("MARS", t);
00485         BenchMarkKeyedVariable<RijndaelEncryption>("Rijndael (128-bit key)", t, 16);
00486         BenchMarkKeyedVariable<RijndaelEncryption>("Rijndael (192-bit key)", t, 24);
00487         BenchMarkKeyedVariable<RijndaelEncryption>("Rijndael (256-bit key)", t, 32);
00488         BenchMarkKeyed<TwofishEncryption>("Twofish", t);
00489         BenchMarkKeyed<SerpentEncryption>("Serpent", t);
00490         BenchMarkKeyed<ARC4>("ARC4", t);
00491         BenchMarkKeyed<SEAL>("SEAL", t);
00492         {
00493                 WAKEEncryption c(key, new BitBucket);
00494                 BenchMark("WAKE", c, t);
00495         }
00496         BenchMarkKeyed<PanamaCipher<false> >("Panama Cipher (little endian)", t);
00497         BenchMarkKeyed<PanamaCipher<true> >("Panama Cipher (big endian)", t);
00498         BenchMarkKeyed<SapphireEncryption>("Sapphire", t);
00499         BenchMarkKeyed<MD5MAC>("MD5-MAC", t);
00500         BenchMarkKeyed<XMACC<MD5> >("XMACC/MD5", t);
00501         BenchMarkKeyed<HMAC<MD5> >("HMAC/MD5", t);
00502         BenchMarkKeyed<CBC_MAC<RijndaelEncryption> >("CBC-MAC/Rijndael", t);
00503         BenchMarkKeyed<DMAC<RijndaelEncryption> >("DMAC/Rijndael", t);
00504 
00505         {
00506                 Integer p("CB6C,B8CE,6351,164F,5D0C,0C9E,9E31,E231,CF4E,D551,CBD0,E671,5D6A,7B06,D8DF,C4A7h");
00507                 Integer q("FD2A,8594,A132,20CC,4E6D,DE77,3AAA,CF15,CD9E,E447,8592,FF46,CC77,87BE,9876,A2AFh");
00508                 Integer s("63239752671357255800299643604761065219897634268887145610573595874544114193025997412441121667211431");
00509                 BlumBlumShub c(p, q, s);
00510                 BenchMark("BlumBlumShub 512", c, t);
00511         }
00512         {
00513                 Integer p("FD2A,8594,A132,20CC,4E6D,DE77,3AAA,CF15,CD9E,E447,8592,FF46,CC77,87BE,9876,9E2C,"
00514                                   "8572,64C3,4CF4,188A,44D4,2130,1135,7982,6FF6,EDD3,26F0,5FAA,BAF4,A81E,7ADC,B80Bh");
00515                 Integer q("C8B9,5797,B349,6BA3,FD72,F2C0,A796,8A65,EE0F,B4BA,272F,4FEE,4DB1,06D5,ECEB,7142,"
00516                                   "E8A8,E5A8,6BF9,A32F,BA37,BACC,8A75,8A6B,2DCE,D6EC,B515,980A,4BB1,08FB,6F2C,2383h");
00517                 Integer s("3578,8F00,2965,71A4,4382,699F,45FD,3922,8238,241B,CEBA,0543,3443,E8D9,12FB,AC46,"
00518                                   "7EC4,8505,EC9E,7EE8,5A23,9B2A,B615,D0C4,9448,F23A,ADEE,E850,1A7A,CA30,0B5B,A408,"
00519                                   "D936,21BA,844E,BDD6,7848,3D1E,9137,CC87,DAA5,773B,D45A,C8BB,5392,1393,108B,6992,"
00520                                   "74E3,C5E2,C235,A321,0111,3BA4,BAB4,1A2F,17EE,C371,DE67,01C9,0F3D,907A,B252,9BDDh");
00521                 BlumBlumShub c(p, q, s);
00522                 BenchMark("BlumBlumShub 1024", c, t);
00523         }
00524         {
00525                 Integer p("EB56,978A,7BA7,B5D9,1383,4611,94F5,4766,FCEF,CF41,958A,FC41,43D0,839F,C56B,B568,"
00526                                   "4ED3,9E5A,BABB,5ACE,8B11,CEBC,88A2,7C12,FFEE,E6E8,CF0A,E231,5BC2,DEDE,80B7,32F6,"
00527                                   "340E,D8A6,B7DE,C779,7EE5,0E16,9C88,FC9F,2A0E,EE6C,7D47,C5F2,6B06,EB8C,F1C8,2E67,"
00528                                   "5B82,8C28,4FB8,542F,2874,C355,CEEE,7A54,1B06,A8AB,8B66,6A5C,9DB2,72B8,74F3,7BC7h");
00529                 Integer q("EB6B,3645,4591,8343,7331,7CAC,B02E,4BB9,DEF5,8EDC,1772,DB9B,9571,5FAB,1CDD,4FB1,"
00530                                   "7B9A,07CD,E715,D448,F552,CBBD,D387,C037,DE70,6661,F360,D0E8,D42E,292A,9321,DDCB,"
00531                                   "0BF9,C514,BFAC,3F2C,C06E,DF64,A9B8,50D6,AC4F,B9E4,014B,5624,2B40,A0D4,5D0B,6DD4,"
00532                                   "0989,D00E,0268,99AB,21DB,0BB4,DB38,84DA,594F,575F,95AC,1B70,45E4,96C8,C6AD,CE67h");
00533                 Integer s("C75A,8A0D,E231,295F,C08A,1716,8611,D5EC,E9EF,B565,90EC,58C0,57D0,DA7D,C6E6,DB00,"
00534                                   "2282,1CA7,EA31,D64E,768C,0B19,8563,36DF,2226,F4EC,74A4,2844,2E8D,37E8,53DC,0172,"
00535                                   "5F56,8CF9,B444,CA02,78B3,17AF,7C78,D320,16AE,AC3D,B97F,7259,1B8F,9C84,6A16,B878,"
00536                                   "0595,70BB,9C52,18B5,9100,9C1F,E85A,4035,06F3,5F38,7462,F01D,0462,BFBC,A4CD,4A45,"
00537                                   "3A77,E7F8,DED1,D6EF,CEF7,0937,CD3F,3AF1,4F88,932D,6D4B,002C,3735,304C,C5D3,B88A,"
00538                                   "B57B,24B6,5346,9B46,5153,B7ED,B216,C181,B1C6,C52E,CD2B,E0AA,B1BB,0A93,C92E,4F79,"
00539                                   "4931,E303,7C8F,A408,8ACF,56CD,6EC0,76A2,5015,6BA4,4C50,C44D,53B9,E168,5F84,B381,"
00540                                   "2514,10B2,00E5,B4D1,4156,A2FE,0BF6,6F33,0A1B,91C6,31B8,1C90,02F1,FB1F,C494,8B65h");
00541                 BlumBlumShub c(p, q, s);
00542                 BenchMark("BlumBlumShub 2048", c, t);
00543         }
00544         cout << "</TABLE>" << endl;
00545 
00546         cout << "<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right><COL align=right>" << endl;
00547         cout << "<THEAD><TR><TH>Operation<TH>Iterations<TH>Total Time<TH>Milliseconds/Operation" << endl;
00548         cout << "<TBODY style=\"background: yellow\">" << endl;
00549         BenchMarkCrypto<RSAES_OAEP_SHA_Decryptor, RSAES_OAEP_SHA_Encryptor>("rsa512.dat", "RSA 512", t);
00550         BenchMarkCrypto<RabinDecryptor, RabinEncryptor>("rabi512.dat", "Rabin 512", t);
00551         BenchMarkCrypto<BlumGoldwasserPrivateKey, BlumGoldwasserPublicKey>("blum512.dat", "BlumGoldwasser 512", t);
00552         BenchMarkCrypto<LUCES_OAEP_SHA_Decryptor, LUCES_OAEP_SHA_Encryptor>("luc512.dat", "LUC 512", t);
00553         BenchMarkCrypto<ElGamalDecryptor, ElGamalEncryptor>("elgc512.dat", "ElGamal 512", t);
00554 
00555         cout << "<TBODY style=\"background: white\">" << endl;
00556         BenchMarkCrypto<RSAES_OAEP_SHA_Decryptor, RSAES_OAEP_SHA_Encryptor>("rsa1024.dat", "RSA 1024", t);
00557         BenchMarkCrypto<RabinDecryptor, RabinEncryptor>("rabi1024.dat", "Rabin 1024", t);
00558         BenchMarkCrypto<BlumGoldwasserPrivateKey, BlumGoldwasserPublicKey>("blum1024.dat", "BlumGoldwasser 1024", t);
00559         BenchMarkCrypto<LUCES_OAEP_SHA_Decryptor, LUCES_OAEP_SHA_Encryptor>("luc1024.dat", "LUC 1024", t);
00560         BenchMarkCrypto<ElGamalDecryptor, ElGamalEncryptor>("elgc1024.dat", "ElGamal 1024", t);
00561         BenchMarkCrypto<LUCELG_Decryptor, LUCELG_Encryptor>("lucc512.dat", "LUCELG 512", t);
00562 
00563         cout << "<TBODY style=\"background: yellow\">" << endl;
00564         BenchMarkCrypto<RSAES_OAEP_SHA_Decryptor, RSAES_OAEP_SHA_Encryptor>("rsa2048.dat", "RSA 2048", t);
00565         BenchMarkCrypto<RabinDecryptor, RabinEncryptor>("rabi2048.dat", "Rabin 2048", t);
00566         BenchMarkCrypto<BlumGoldwasserPrivateKey, BlumGoldwasserPublicKey>("blum2048.dat", "BlumGoldwasser 2048", t);
00567         BenchMarkCrypto<LUCES_OAEP_SHA_Decryptor, LUCES_OAEP_SHA_Encryptor>("luc2048.dat", "LUC 2048", t);
00568         BenchMarkCrypto<ElGamalDecryptor, ElGamalEncryptor>("elgc2048.dat", "ElGamal 2048", t);
00569         BenchMarkCrypto<LUCELG_Decryptor, LUCELG_Encryptor>("lucc1024.dat", "LUCELG 1024", t);
00570 
00571         cout << "<TBODY style=\"background: white\">" << endl;
00572         BenchMarkSignature<RSASSA_PKCS1v15_SHA_Signer, RSASSA_PKCS1v15_SHA_Verifier>("rsa512.dat", "RSA 512", t);
00573         BenchMarkSignature<RabinSignerWith(SHA), RabinVerifierWith(SHA) >("rabi512.dat", "Rabin 512", t);
00574         BenchMarkSignature<RWSigner<SHA>, RWVerifier<SHA> >("rw512.dat", "RW 512", t);
00575         BenchMarkSignature<LUCSSA_PKCS1v15_SHA_Signer, LUCSSA_PKCS1v15_SHA_Verifier>("luc512.dat", "LUC 512", t);
00576         BenchMarkSignature<NRSigner<SHA>, NRVerifier<SHA> >("nr512.dat", "NR 512", t);
00577         BenchMarkSignature<DSAPrivateKey, DSAPublicKey>("dsa512.dat", "DSA 512", t);
00578 
00579         cout << "<TBODY style=\"background: yellow\">" << endl;
00580         BenchMarkSignature<RSASSA_PKCS1v15_SHA_Signer, RSASSA_PKCS1v15_SHA_Verifier>("rsa1024.dat", "RSA 1024", t);
00581         BenchMarkSignature<RabinSignerWith(SHA), RabinVerifierWith(SHA) >("rabi1024.dat", "Rabin 1024", t);
00582         BenchMarkSignature<RWSigner<SHA>, RWVerifier<SHA> >("rw1024.dat", "RW 1024", t);
00583         BenchMarkSignature<LUCSSA_PKCS1v15_SHA_Signer, LUCSSA_PKCS1v15_SHA_Verifier>("luc1024.dat", "LUC 1024", t);
00584         BenchMarkSignature<NRSigner<SHA>, NRVerifier<SHA> >("nr1024.dat", "NR 1024", t);
00585         BenchMarkSignature<DSAPrivateKey, DSAPublicKey>("dsa1024.dat", "DSA 1024", t);
00586         BenchMarkSignature<LUCELG_Signer<SHA>, LUCELG_Verifier<SHA> >("lucs512.dat", "LUCELG 512", t);
00587 
00588         cout << "<TBODY style=\"background: white\">" << endl;
00589         BenchMarkSignature<RSASSA_PKCS1v15_SHA_Signer, RSASSA_PKCS1v15_SHA_Verifier>("rsa2048.dat", "RSA 2048", t);
00590         BenchMarkSignature<RabinSignerWith(SHA), RabinVerifierWith(SHA) >("rabi2048.dat", "Rabin 2048", t);
00591         BenchMarkSignature<RWSigner<SHA>, RWVerifier<SHA> >("rw2048.dat", "RW 2048", t);
00592         BenchMarkSignature<LUCSSA_PKCS1v15_SHA_Signer, LUCSSA_PKCS1v15_SHA_Verifier>("luc2048.dat", "LUC 2048", t);
00593         BenchMarkSignature<NRSigner<SHA>, NRVerifier<SHA> >("nr2048.dat", "NR 2048", t);
00594         BenchMarkSignature<LUCELG_Signer<SHA>, LUCELG_Verifier<SHA> >("lucs1024.dat", "LUCELG 1024", t);
00595 
00596         cout << "<TBODY style=\"background: yellow\">" << endl;
00597         BenchMarkKeyAgreement<XTR_DH>("xtrdh171.dat", "XTR-DH 171", t);
00598         BenchMarkKeyAgreement<XTR_DH>("xtrdh342.dat", "XTR-DH 342", t);
00599         BenchMarkKeyAgreement<DH>("dh512.dat", "DH 512", t);
00600         BenchMarkKeyAgreement<DH>("dh1024.dat", "DH 1024", t);
00601         BenchMarkKeyAgreement<DH>("dh2048.dat", "DH 2048", t);
00602         BenchMarkKeyAgreement<LUCDIF>("lucd512.dat", "LUCDIF 512", t);
00603         BenchMarkKeyAgreement<LUCDIF>("lucd1024.dat", "LUCDIF 1024", t);
00604         BenchMarkKeyAgreement<MQV>("mqv512.dat", "MQV 512", t);
00605         BenchMarkKeyAgreement<MQV>("mqv1024.dat", "MQV 1024", t);
00606         BenchMarkKeyAgreement<MQV>("mqv2048.dat", "MQV 2048", t);
00607 
00608         cout << "<TBODY style=\"background: white\">" << endl;
00609         {
00610                 Integer modulus("199999999999999999999999980586675243082581144187569");
00611                 Integer a("659942,b7261b,249174,c86bd5,e2a65b,45fe07,37d110h");
00612                 Integer b("3ece7d,09473d,666000,5baef5,d4e00e,30159d,2df49ah");
00613                 Integer x("25dd61,4c0667,81abc0,fe6c84,fefaa3,858ca6,96d0e8h");
00614                 Integer y("4e2477,05aab0,b3497f,d62b5e,78a531,446729,6c3fach");
00615                 Integer r("100000000000000000000000000000000000000000000000151");
00616                 Integer k(2);
00617                 Integer d("76572944925670636209790912427415155085360939712345");
00618 
00619                 ECP ec(modulus, a, b);
00620                 ECP::Point P(x, y);
00621                 P = ec.Multiply(k, P);
00622                 ECP::Point Q(ec.Multiply(d, P));
00623                 ECDecryptor<ECP> cpriv(ec, P, r, Q, d);
00624                 ECEncryptor<ECP> cpub(cpriv);
00625                 ECSigner<ECP, SHA> spriv(cpriv);
00626                 ECVerifier<ECP, SHA> spub(spriv);
00627                 ECDHC<ECP> ecdhc(ec, P, r, k);
00628                 ECMQVC<ECP> ecmqvc(ec, P, r, k);
00629 
00630                 BenchMarkEncryption("ECIES over GF(p) 168", cpub, t);
00631                 BenchMarkDecryption("ECIES over GF(p) 168", cpriv, cpub, t);
00632                 BenchMarkSigning("ECNR over GF(p) 168", spriv, t);
00633                 BenchMarkVerification("ECNR over GF(p) 168", spriv, spub, t);
00634                 BenchMarkKeyGen("ECDHC over GF(p) 168", ecdhc, t);
00635                 BenchMarkAgreement("ECDHC over GF(p) 168", ecdhc, t);
00636                 BenchMarkKeyGen("ECMQVC over GF(p) 168", ecmqvc, t);
00637                 BenchMarkAgreement("ECMQVC over GF(p) 168", ecmqvc, t);
00638         }
00639 
00640         cout << "<TBODY style=\"background: yellow\">" << endl;
00641         {
00642                 Integer r("3805993847215893016155463826195386266397436443");
00643                 Integer k(12);
00644                 Integer d("2065729449256706362097909124274151550853609397");
00645 
00646                 GF2NT gf2n(155, 62, 0);
00647                 byte b[]={0x7, 0x33, 0x8f};
00648                 EC2N ec(gf2n, PolynomialMod2::Zero(), PolynomialMod2(b,3));
00649                 EC2N::Point P(0x7B, 0x1C8);
00650                 P = ec.Multiply(k, P);
00651                 EC2N::Point Q(ec.Multiply(d, P));
00652                 ECDecryptor<EC2N> cpriv(ec, P, r, Q, d);
00653                 ECEncryptor<EC2N> cpub(cpriv);
00654                 ECSigner<EC2N, SHA> spriv(cpriv);
00655                 ECVerifier<EC2N, SHA> spub(spriv);
00656                 ECDHC<EC2N> ecdhc(ec, P, r, k);
00657                 ECMQVC<EC2N> ecmqvc(ec, P, r, k);
00658 
00659                 BenchMarkEncryption("ECIES over GF(2^n) 155", cpub, t);
00660                 BenchMarkDecryption("ECIES over GF(2^n) 155", cpriv, cpub, t);
00661                 BenchMarkSigning("ECNR over GF(2^n) 155", spriv, t);
00662                 BenchMarkVerification("ECNR over GF(2^n) 155", spriv, spub, t);
00663                 BenchMarkKeyGen("ECDHC over GF(2^n) 155", ecdhc, t);
00664                 BenchMarkAgreement("ECDHC over GF(2^n) 155", ecdhc, t);
00665                 BenchMarkKeyGen("ECMQVC over GF(2^n) 155", ecmqvc, t);
00666                 BenchMarkAgreement("ECMQVC over GF(2^n) 155", ecmqvc, t);
00667         }
00668         cout << "</TABLE>" << endl;
00669 
00670         cout << "Throughput Geometric Average: " << setiosflags(ios::fixed) << exp(logtotal/logcount) << endl;
00671 }

Generated at Mon Jan 15 01:16:29 2001 for Crypto++ by doxygen1.2.4 written by Dimitri van Heesch, © 1997-2000