Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | 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 "nr.h"
    00043 #include "dsa.h"
    00044 #include "luc.h"
    00045 #include "rabin.h"
    00046 #include "rw.h"
    00047 #include "eccrypto.h"
    00048 #include "ecp.h"
    00049 #include "ec2n.h"
    00050 #include "asn.h"
    00051 #include "rng.h"
    00052 #include "files.h"
    00053 #include "hex.h"
    00054 #include "modes.h"
    00055 #include "mdc.h"
    00056 #include "lubyrack.h"
    00057 #include "sapphire.h"
    00058 #include "tea.h"
    00059 #include "dh.h"
    00060 #include "mqv.h"
    00061 #include "xtrcrypt.h"
    00062 #include "esign.h"
    00063
    00064 #include "bench.h"
    00065
    00066 #include <time.h>
    00067 #include <math.h>
    00068 #include <iostream>
    00069 #include <iomanip>
    00070
    00071 USING_NAMESPACE(CryptoPP)
    00072 USING_NAMESPACE(std)
    00073
    00074 #ifdef CLOCKS_PER_SEC
    00075 static const double CLOCK_TICKS_PER_SECOND = (double)CLOCKS_PER_SEC;
    00076 #elif defined(CLK_TCK)
    00077 static const double CLOCK_TICKS_PER_SECOND = (double)CLK_TCK;
    00078 #else
    00079 static const double CLOCK_TICKS_PER_SECOND = 1000000.0;
    00080 #endif
    00081
    00082 static const byte *const key=(byte *)"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
    00083
    00084 static double logtotal = 0;
    00085 static unsigned int logcount = 0;
    00086
    00087 void OutputResultBytes(const char *name, unsigned long length, double timeTaken)
    00088 {
    00089         double mbs = length / timeTaken / (1024*1024);
    00090         cout << "<TR><TH>" << name;
    00091         cout << "<TD>" << length;
    00092         cout << setiosflags(ios::fixed);
    00093         cout << "<TD>" << setprecision(3) << timeTaken;
    00094         cout << "<TD>" << setprecision(3) << mbs << endl;
    00095         cout << resetiosflags(ios::fixed);
    00096         logtotal += log(mbs);
    00097         logcount++;
    00098 }
    00099
    00100 void OutputResultOperations(const char *name, const char *operation, bool pc, unsigned long iterations, double timeTaken)
    00101 {
    00102         cout << "<TR><TH>" << name << " " << operation << (pc ? " with precomputation" : "");
    00103         cout << "<TD>" << iterations;
    00104         cout << setiosflags(ios::fixed);
    00105         cout << "<TD>" << setprecision(3) << timeTaken;
    00106         cout << "<TD>" << setprecision(2) << (1000*timeTaken/iterations) << endl;
    00107         cout << resetiosflags(ios::fixed);
    00108
    00109         logtotal += log(iterations/timeTaken);
    00110         logcount++;
    00111 }
    00112
    00113 void BenchMark(const char *name, BlockTransformation &cipher, double timeTotal)
    00114 {
    00115         const int BUF_SIZE = RoundDownToMultipleOf(1024U, cipher.OptimalNumberOfParallelBlocks() * cipher.BlockSize());
    00116         SecByteBlock buf(BUF_SIZE);
    00117         const int nBlocks = BUF_SIZE / cipher.BlockSize();
    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.ProcessAndXorMultipleBlocks(buf, NULL, buf, nBlocks);
    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, StreamTransformation &cipher, double timeTotal)
    00135 {
    00136         const int BUF_SIZE=1024;
    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, HashTransformation &hash, double timeTotal)
    00155 {
    00156         const int BUF_SIZE=1024;
    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;
    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.GenerateBlock(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         if (!pc && key.GetMaterial().SupportsPrecomputation())
    00214         {
    00215                 key.AccessMaterial().Precompute(16);
    00216                 BenchMarkEncryption(name, key, timeTotal, true);
    00217         }
    00218 }
    00219
    00220 void BenchMarkDecryption(const char *name, PK_Decryptor &priv, PK_Encryptor &pub, double timeTotal)
    00221 {
    00222         unsigned int len = 16;
    00223         LC_RNG rng(time(NULL));
    00224         SecByteBlock ciphertext(pub.CiphertextLength(len));
    00225         SecByteBlock plaintext(pub.MaxPlaintextLength(ciphertext.size()));
    00226         rng.GenerateBlock(plaintext, len);
    00227         pub.Encrypt(rng, plaintext, len, ciphertext);
    00228
    00229         clock_t start = clock();
    00230         unsigned int i;
    00231         double timeTaken;
    00232         for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
    00233                 priv.Decrypt(ciphertext, ciphertext.size(), plaintext);
    00234
    00235         OutputResultOperations(name, "Decryption", false, i, timeTaken);
    00236 }
    00237
    00238 void BenchMarkSigning(const char *name, PK_Signer &key, double timeTotal, bool pc=false)
    00239 {
    00240         unsigned int len = 16;
    00241         LC_RNG rng(time(NULL));
    00242         SecByteBlock message(len), signature(key.SignatureLength());
    00243         rng.GenerateBlock(message, len);
    00244
    00245         clock_t start = clock();
    00246         unsigned int i;
    00247         double timeTaken;
    00248         for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
    00249                 key.SignMessage(rng, message, len, signature);
    00250
    00251         OutputResultOperations(name, "Signature", pc, i, timeTaken);
    00252
    00253         if (!pc && key.GetMaterial().SupportsPrecomputation())
    00254         {
    00255                 key.AccessMaterial().Precompute(16);
    00256                 BenchMarkSigning(name, key, timeTotal, true);
    00257         }
    00258 }
    00259
    00260 void BenchMarkVerification(const char *name, const PK_Signer &priv, PK_Verifier &pub, double timeTotal, bool pc=false)
    00261 {
    00262         unsigned int len = 16;
    00263         LC_RNG rng(time(NULL));
    00264         SecByteBlock message(len), signature(pub.SignatureLength());
    00265         rng.GenerateBlock(message, len);
    00266         priv.SignMessage(rng, message, len, signature);
    00267
    00268         clock_t start = clock();
    00269         unsigned int i;
    00270         double timeTaken;
    00271         for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
    00272                 pub.VerifyMessage(message, len, signature);
    00273
    00274         OutputResultOperations(name, "Verification", pc, i, timeTaken);
    00275
    00276         if (!pc && pub.GetMaterial().SupportsPrecomputation())
    00277         {
    00278                 pub.AccessMaterial().Precompute(16);
    00279                 BenchMarkVerification(name, priv, pub, timeTotal, true);
    00280         }
    00281 }
    00282
    00283 void BenchMarkKeyGen(const char *name, SimpleKeyAgreementDomain &d, double timeTotal, bool pc=false)
    00284 {
    00285         LC_RNG rng(time(NULL));
    00286         SecByteBlock priv(d.PrivateKeyLength()), pub(d.PublicKeyLength());
    00287
    00288         clock_t start = clock();
    00289         unsigned int i;
    00290         double timeTaken;
    00291         for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
    00292                 d.GenerateKeyPair(rng, priv, pub);
    00293
    00294         OutputResultOperations(name, "Key-Pair Generation", pc, i, timeTaken);
    00295
    00296         if (!pc && d.GetMaterial().SupportsPrecomputation())
    00297         {
    00298                 d.AccessMaterial().Precompute(16);
    00299                 BenchMarkKeyGen(name, d, timeTotal, true);
    00300         }
    00301 }
    00302
    00303 void BenchMarkKeyGen(const char *name, AuthenticatedKeyAgreementDomain &d, double timeTotal, bool pc=false)
    00304 {
    00305         LC_RNG rng(time(NULL));
    00306         SecByteBlock priv(d.EphemeralPrivateKeyLength()), pub(d.EphemeralPublicKeyLength());
    00307
    00308         clock_t start = clock();
    00309         unsigned int i;
    00310         double timeTaken;
    00311         for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
    00312                 d.GenerateEphemeralKeyPair(rng, priv, pub);
    00313
    00314         OutputResultOperations(name, "Key-Pair Generation", pc, i, timeTaken);
    00315
    00316         if (!pc && d.GetMaterial().SupportsPrecomputation())
    00317         {
    00318                 d.AccessMaterial().Precompute(16);
    00319                 BenchMarkKeyGen(name, d, timeTotal, true);
    00320         }
    00321 }
    00322
    00323 void BenchMarkAgreement(const char *name, SimpleKeyAgreementDomain &d, double timeTotal, bool pc=false)
    00324 {
    00325         LC_RNG rng(time(NULL));
    00326         SecByteBlock priv1(d.PrivateKeyLength()), priv2(d.PrivateKeyLength());
    00327         SecByteBlock pub1(d.PublicKeyLength()), pub2(d.PublicKeyLength());
    00328         d.GenerateKeyPair(rng, priv1, pub1);
    00329         d.GenerateKeyPair(rng, priv2, pub2);
    00330         SecByteBlock val(d.AgreedValueLength());
    00331
    00332         clock_t start = clock();
    00333         unsigned int i;
    00334         double timeTaken;
    00335         for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i+=2)
    00336         {
    00337                 d.Agree(val, priv1, pub2);
    00338                 d.Agree(val, priv2, pub1);
    00339         }
    00340
    00341         OutputResultOperations(name, "Key Agreement", pc, i, timeTaken);
    00342 }
    00343
    00344 void BenchMarkAgreement(const char *name, AuthenticatedKeyAgreementDomain &d, double timeTotal, bool pc=false)
    00345 {
    00346         LC_RNG rng(time(NULL));
    00347         SecByteBlock spriv1(d.StaticPrivateKeyLength()), spriv2(d.StaticPrivateKeyLength());
    00348         SecByteBlock epriv1(d.EphemeralPrivateKeyLength()), epriv2(d.EphemeralPrivateKeyLength());
    00349         SecByteBlock spub1(d.StaticPublicKeyLength()), spub2(d.StaticPublicKeyLength());
    00350         SecByteBlock epub1(d.EphemeralPublicKeyLength()), epub2(d.EphemeralPublicKeyLength());
    00351         d.GenerateStaticKeyPair(rng, spriv1, spub1);
    00352         d.GenerateStaticKeyPair(rng, spriv2, spub2);
    00353         d.GenerateEphemeralKeyPair(rng, epriv1, epub1);
    00354         d.GenerateEphemeralKeyPair(rng, epriv2, epub2);
    00355         SecByteBlock val(d.AgreedValueLength());
    00356
    00357         clock_t start = clock();
    00358         unsigned int i;
    00359         double timeTaken;
    00360         for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i+=2)
    00361         {
    00362                 d.Agree(val, spriv1, epriv1, spub2, epub2);
    00363                 d.Agree(val, spriv2, epriv2, spub1, epub1);
    00364         }
    00365
    00366         OutputResultOperations(name, "Key Agreement", pc, i, timeTaken);
    00367 }
    00368
    00369 //VC60 workaround: compiler bug triggered without the extra dummy parameters
    00370 template <class T>
    00371 void BenchMarkKeyed(const char *name, double timeTotal, T *x=NULL)
    00372 {
    00373         T c;
    00374         c.SetKeyWithIV(key, c.DefaultKeyLength(), key);
    00375         BenchMark(name, c, timeTotal);
    00376 }
    00377
    00378 //VC60 workaround: compiler bug triggered without the extra dummy parameters
    00379 template <class T>
    00380 void BenchMarkKeyedVariable(const char *name, double timeTotal, unsigned int keyLength, T *x=NULL)
    00381 {
    00382         T c;
    00383         c.SetKeyWithIV(key, keyLength, key);
    00384         BenchMark(name, c, timeTotal);
    00385 }
    00386
    00387 //VC60 workaround: compiler bug triggered without the extra dummy parameters
    00388 template <class T>
    00389 void BenchMarkKeyless(const char *name, double timeTotal, T *x=NULL)
    00390 {
    00391         T c;
    00392         BenchMark(name, c, timeTotal);
    00393 }
    00394
    00395 //VC60 workaround: compiler bug triggered without the extra dummy parameters
    00396 template <class SCHEME>
    00397 void BenchMarkCrypto(const char *filename, const char *name, double timeTotal, SCHEME *x=NULL)
    00398 {
    00399         FileSource f(filename, true, new HexDecoder());
    00400         typename SCHEME::Decryptor priv(f);
    00401         typename SCHEME::Encryptor pub(priv);
    00402         BenchMarkEncryption(name, pub, timeTotal);
    00403         BenchMarkDecryption(name, priv, pub, timeTotal);
    00404 }
    00405
    00406 //VC60 workaround: compiler bug triggered without the extra dummy parameters
    00407 template <class SCHEME>
    00408 void BenchMarkSignature(const char *filename, const char *name, double timeTotal, SCHEME *x=NULL)
    00409 {
    00410         FileSource f(filename, true, new HexDecoder());
    00411         typename SCHEME::Signer priv(f);
    00412         typename SCHEME::Verifier pub(priv);
    00413         BenchMarkSigning(name, priv, timeTotal);
    00414         BenchMarkVerification(name, priv, pub, timeTotal);
    00415 }
    00416
    00417 //VC60 workaround: compiler bug triggered without the extra dummy parameters
    00418 template <class D>
    00419 void BenchMarkKeyAgreement(const char *filename, const char *name, double timeTotal, D *x=NULL)
    00420 {
    00421         FileSource f(filename, true, new HexDecoder());
    00422         D d(f);
    00423         BenchMarkKeyGen(name, d, timeTotal);
    00424         BenchMarkAgreement(name, d, timeTotal);
    00425 }
    00426
    00427 void BenchMarkAll(double t)
    00428 {
    00429 #if 1
    00430         logtotal = 0;
    00431         logcount = 0;
    00432
    00433         cout << "<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right><COL align=right>" << endl;
    00434         cout << "<THEAD><TR><TH>Algorithm<TH>Bytes Processed<TH>Time Taken<TH>Megabytes(2^20 bytes)/Second\n<TBODY>" << endl;
    00435
    00436         BenchMarkKeyless<CRC32>("CRC-32", t);
    00437         BenchMarkKeyless<Adler32>("Adler-32", t);
    00438         BenchMarkKeyless<MD2>("MD2", t);
    00439         BenchMarkKeyless<MD5>("MD5", t);
    00440         BenchMarkKeyless<SHA>("SHA-1", t);
    00441         BenchMarkKeyless<SHA256>("SHA-256", t);
    00442         BenchMarkKeyless<SHA512>("SHA-512", t);
    00443         BenchMarkKeyless<HAVAL3>("HAVAL (pass=3)", t);
    00444         BenchMarkKeyless<HAVAL4>("HAVAL (pass=4)", t);
    00445         BenchMarkKeyless<HAVAL5>("HAVAL (pass=5)", t);
    00446 #ifdef WORD64_AVAILABLE
    00447         BenchMarkKeyless<Tiger>("Tiger", t);
    00448 #endif
    00449         BenchMarkKeyless<RIPEMD160>("RIPE-MD160", t);
    00450         BenchMarkKeyless<PanamaHash<LittleEndian> >("Panama Hash (little endian)", t);
    00451         BenchMarkKeyless<PanamaHash<BigEndian> >("Panama Hash (big endian)", t);
    00452         BenchMarkKeyed<MDC<MD5>::Encryption>("MDC/MD5", t);
    00453         BenchMarkKeyed<LR<MD5>::Encryption>("Luby-Rackoff/MD5", t);
    00454         BenchMarkKeyed<DES::Encryption>("DES", t);
    00455         BenchMarkKeyed<DES_XEX3::Encryption>("DES-XEX3", t);
    00456         BenchMarkKeyed<DES_EDE3::Encryption>("DES-EDE3", t);
    00457         BenchMarkKeyed<IDEA::Encryption>("IDEA", t);
    00458         BenchMarkKeyed<RC2::Encryption>("RC2", t);
    00459         BenchMarkKeyed<RC5::Encryption>("RC5 (r=16)", t);
    00460         BenchMarkKeyed<Blowfish::Encryption>("Blowfish", t);
    00461         BenchMarkKeyed<Diamond2::Encryption>("Diamond2", t);
    00462         BenchMarkKeyed<Diamond2Lite::Encryption>("Diamond2 Lite", t);
    00463         BenchMarkKeyed<ThreeWayDecryption>("3-WAY", t);
    00464         BenchMarkKeyed<TEA::Encryption>("TEA", t);
    00465         BenchMarkKeyedVariable<SAFER_SK::Encryption>("SAFER (r=8)", t, 8);
    00466         BenchMarkKeyed<GOST::Encryption>("GOST", t);
    00467 #ifdef WORD64_AVAILABLE
    00468         BenchMarkKeyed<SHARK::Encryption>("SHARK (r=6)", t);
    00469 #endif
    00470         BenchMarkKeyed<CAST128::Encryption>("CAST-128", t);
    00471         BenchMarkKeyed<CAST256::Encryption>("CAST-256", t);
    00472         BenchMarkKeyed<Square::Encryption>("Square", t);
    00473         BenchMarkKeyed<SKIPJACK::Encryption>("SKIPJACK", t);
    00474         BenchMarkKeyed<RC6::Encryption>("RC6", t);
    00475         BenchMarkKeyed<MARS::Encryption>("MARS", t);
    00476         BenchMarkKeyedVariable<Rijndael::Encryption>("Rijndael (128-bit key)", t, 16);
    00477         BenchMarkKeyedVariable<Rijndael::Encryption>("Rijndael (192-bit key)", t, 24);
    00478         BenchMarkKeyedVariable<Rijndael::Encryption>("Rijndael (256-bit key)", t, 32);
    00479         BenchMarkKeyedVariable<CTR_Mode<Rijndael>::Encryption>("Rijndael (128) CTR", t, 16);
    00480         BenchMarkKeyedVariable<OFB_Mode<Rijndael>::Encryption>("Rijndael (128) OFB", t, 16);
    00481         BenchMarkKeyedVariable<CFB_Mode<Rijndael>::Encryption>("Rijndael (128) CFB", t, 16);
    00482         BenchMarkKeyedVariable<CBC_Mode<Rijndael>::Encryption>("Rijndael (128) CBC", t, 16);
    00483         BenchMarkKeyed<Twofish::Encryption>("Twofish", t);
    00484         BenchMarkKeyed<Serpent::Encryption>("Serpent", t);
    00485         BenchMarkKeyed<ARC4>("ARC4", t);
    00486         BenchMarkKeyed<SEAL<BigEndian>::Encryption>("SEAL-3.0-BE", t);
    00487         BenchMarkKeyed<SEAL<LittleEndian>::Encryption>("SEAL-3.0-LE", t);
    00488         BenchMarkKeyed<WAKE_CFB<BigEndian>::Encryption>("WAKE-CFB-BE", t);
    00489         BenchMarkKeyed<WAKE_CFB<LittleEndian>::Encryption>("WAKE-CFB-LE", t);
    00490         BenchMarkKeyed<WAKE_OFB<BigEndian>::Encryption>("WAKE-OFB-BE", t);
    00491         BenchMarkKeyed<WAKE_OFB<LittleEndian>::Encryption>("WAKE-OFB-LE", t);
    00492         BenchMarkKeyed<PanamaCipher<LittleEndian>::Encryption>("Panama Cipher (little endian)", t);
    00493         BenchMarkKeyed<PanamaCipher<BigEndian>::Encryption>("Panama Cipher (big endian)", t);
    00494         BenchMarkKeyed<MD5MAC>("MD5-MAC", t);
    00495         BenchMarkKeyed<XMACC<MD5> >("XMACC/MD5", t);
    00496         BenchMarkKeyed<HMAC<MD5> >("HMAC/MD5", t);
    00497         BenchMarkKeyed<CBC_MAC<Rijndael> >("CBC-MAC/Rijndael", t);
    00498         BenchMarkKeyed<DMAC<Rijndael> >("DMAC/Rijndael", t);
    00499
    00500         {
    00501                 Integer p("CB6C,B8CE,6351,164F,5D0C,0C9E,9E31,E231,CF4E,D551,CBD0,E671,5D6A,7B06,D8DF,C4A7h");
    00502                 Integer q("FD2A,8594,A132,20CC,4E6D,DE77,3AAA,CF15,CD9E,E447,8592,FF46,CC77,87BE,9876,A2AFh");
    00503                 Integer s("63239752671357255800299643604761065219897634268887145610573595874544114193025997412441121667211431");
    00504                 BlumBlumShub c(p, q, s);
    00505                 BenchMark("BlumBlumShub 512", c, t);
    00506         }
    00507         {
    00508                 Integer p("FD2A,8594,A132,20CC,4E6D,DE77,3AAA,CF15,CD9E,E447,8592,FF46,CC77,87BE,9876,9E2C,"
    00509                                   "8572,64C3,4CF4,188A,44D4,2130,1135,7982,6FF6,EDD3,26F0,5FAA,BAF4,A81E,7ADC,B80Bh");
    00510                 Integer q("C8B9,5797,B349,6BA3,FD72,F2C0,A796,8A65,EE0F,B4BA,272F,4FEE,4DB1,06D5,ECEB,7142,"
    00511                                   "E8A8,E5A8,6BF9,A32F,BA37,BACC,8A75,8A6B,2DCE,D6EC,B515,980A,4BB1,08FB,6F2C,2383h");
    00512                 Integer s("3578,8F00,2965,71A4,4382,699F,45FD,3922,8238,241B,CEBA,0543,3443,E8D9,12FB,AC46,"
    00513                                   "7EC4,8505,EC9E,7EE8,5A23,9B2A,B615,D0C4,9448,F23A,ADEE,E850,1A7A,CA30,0B5B,A408,"
    00514                                   "D936,21BA,844E,BDD6,7848,3D1E,9137,CC87,DAA5,773B,D45A,C8BB,5392,1393,108B,6992,"
    00515                                   "74E3,C5E2,C235,A321,0111,3BA4,BAB4,1A2F,17EE,C371,DE67,01C9,0F3D,907A,B252,9BDDh");
    00516                 BlumBlumShub c(p, q, s);
    00517                 BenchMark("BlumBlumShub 1024", c, t);
    00518         }
    00519         {
    00520                 Integer p("EB56,978A,7BA7,B5D9,1383,4611,94F5,4766,FCEF,CF41,958A,FC41,43D0,839F,C56B,B568,"
    00521                                   "4ED3,9E5A,BABB,5ACE,8B11,CEBC,88A2,7C12,FFEE,E6E8,CF0A,E231,5BC2,DEDE,80B7,32F6,"
    00522                                   "340E,D8A6,B7DE,C779,7EE5,0E16,9C88,FC9F,2A0E,EE6C,7D47,C5F2,6B06,EB8C,F1C8,2E67,"
    00523                                   "5B82,8C28,4FB8,542F,2874,C355,CEEE,7A54,1B06,A8AB,8B66,6A5C,9DB2,72B8,74F3,7BC7h");
    00524                 Integer q("EB6B,3645,4591,8343,7331,7CAC,B02E,4BB9,DEF5,8EDC,1772,DB9B,9571,5FAB,1CDD,4FB1,"
    00525                                   "7B9A,07CD,E715,D448,F552,CBBD,D387,C037,DE70,6661,F360,D0E8,D42E,292A,9321,DDCB,"
    00526                                   "0BF9,C514,BFAC,3F2C,C06E,DF64,A9B8,50D6,AC4F,B9E4,014B,5624,2B40,A0D4,5D0B,6DD4,"
    00527                                   "0989,D00E,0268,99AB,21DB,0BB4,DB38,84DA,594F,575F,95AC,1B70,45E4,96C8,C6AD,CE67h");
    00528                 Integer s("C75A,8A0D,E231,295F,C08A,1716,8611,D5EC,E9EF,B565,90EC,58C0,57D0,DA7D,C6E6,DB00,"
    00529                                   "2282,1CA7,EA31,D64E,768C,0B19,8563,36DF,2226,F4EC,74A4,2844,2E8D,37E8,53DC,0172,"
    00530                                   "5F56,8CF9,B444,CA02,78B3,17AF,7C78,D320,16AE,AC3D,B97F,7259,1B8F,9C84,6A16,B878,"
    00531                                   "0595,70BB,9C52,18B5,9100,9C1F,E85A,4035,06F3,5F38,7462,F01D,0462,BFBC,A4CD,4A45,"
    00532                                   "3A77,E7F8,DED1,D6EF,CEF7,0937,CD3F,3AF1,4F88,932D,6D4B,002C,3735,304C,C5D3,B88A,"
    00533                                   "B57B,24B6,5346,9B46,5153,B7ED,B216,C181,B1C6,C52E,CD2B,E0AA,B1BB,0A93,C92E,4F79,"
    00534                                   "4931,E303,7C8F,A408,8ACF,56CD,6EC0,76A2,5015,6BA4,4C50,C44D,53B9,E168,5F84,B381,"
    00535                                   "2514,10B2,00E5,B4D1,4156,A2FE,0BF6,6F33,0A1B,91C6,31B8,1C90,02F1,FB1F,C494,8B65h");
    00536                 BlumBlumShub c(p, q, s);
    00537                 BenchMark("BlumBlumShub 2048", c, t);
    00538         }
    00539         cout << "</TABLE>" << endl;
    00540
    00541         cout << "<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right><COL align=right>" << endl;
    00542         cout << "<THEAD><TR><TH>Operation<TH>Iterations<TH>Total Time<TH>Milliseconds/Operation" << endl;
    00543
    00544         cout << "<TBODY style=\"background: yellow\">" << endl;
    00545         BenchMarkCrypto<RSAES<OAEP<SHA> > >("rsa1024.dat", "RSA 1024", t);
    00546         BenchMarkCrypto<RabinES<OAEP<SHA> > >("rabi1024.dat", "Rabin 1024", t);
    00547         BenchMarkCrypto<LUCES<OAEP<SHA> > >("luc1024.dat", "LUC 1024", t);
    00548         BenchMarkCrypto<DLIES<> >("dlie1024.dat", "DLIES 1024", t);
    00549         BenchMarkCrypto<LUC_IES<> >("lucc512.dat", "LUCELG 512", t);
    00550
    00551         cout << "<TBODY style=\"background: white\">" << endl;
    00552         BenchMarkCrypto<RSAES<OAEP<SHA> > >("rsa2048.dat", "RSA 2048", t);
    00553         BenchMarkCrypto<RabinES<OAEP<SHA> > >("rabi2048.dat", "Rabin 2048", t);
    00554         BenchMarkCrypto<LUCES<OAEP<SHA> > >("luc2048.dat", "LUC 2048", t);
    00555         BenchMarkCrypto<DLIES<> >("dlie2048.dat", "DLIES 2048", t);
    00556         BenchMarkCrypto<LUC_IES<> >("lucc1024.dat", "LUCELG 1024", t);
    00557
    00558         cout << "<TBODY style=\"background: yellow\">" << endl;
    00559         BenchMarkSignature<RSASSA<PKCS1v15, SHA> >("rsa1024.dat", "RSA 1024", t);
    00560         BenchMarkSignature<RabinPSSR<SHA> >("rabi1024.dat", "Rabin 1024", t);
    00561         BenchMarkSignature<RWSSA<SHA> >("rw1024.dat", "RW 1024", t);
    00562         BenchMarkSignature<LUCSSA<SHA> >("luc1024.dat", "LUC 1024", t);
    00563         BenchMarkSignature<NR<SHA> >("nr1024.dat", "NR 1024", t);
    00564         BenchMarkSignature<DSA>("dsa1024.dat", "DSA 1024", t);
    00565         BenchMarkSignature<LUC_HMP<SHA> >("lucs512.dat", "LUC-HMP 512", t);
    00566         BenchMarkSignature<ESIGN<SHA> >("esig1023.dat", "ESIGN 1023", t);
    00567         BenchMarkSignature<ESIGN<SHA> >("esig1536.dat", "ESIGN 1536", t);
    00568
    00569         cout << "<TBODY style=\"background: white\">" << endl;
    00570         BenchMarkSignature<RSASSA<PKCS1v15, SHA> >("rsa2048.dat", "RSA 2048", t);
    00571         BenchMarkSignature<RabinPSSR<SHA> >("rabi2048.dat", "Rabin 2048", t);
    00572         BenchMarkSignature<RWSSA<SHA> >("rw2048.dat", "RW 2048", t);
    00573         BenchMarkSignature<LUCSSA<SHA> >("luc2048.dat", "LUC 2048", t);
    00574         BenchMarkSignature<NR<SHA> >("nr2048.dat", "NR 2048", t);
    00575         BenchMarkSignature<LUC_HMP<SHA> >("lucs1024.dat", "LUC-HMP 1024", t);
    00576         BenchMarkSignature<ESIGN<SHA> >("esig2046.dat", "ESIGN 2046", t);
    00577
    00578         cout << "<TBODY style=\"background: yellow\">" << endl;
    00579         BenchMarkKeyAgreement<XTR_DH>("xtrdh171.dat", "XTR-DH 171", t);
    00580         BenchMarkKeyAgreement<XTR_DH>("xtrdh342.dat", "XTR-DH 342", t);
    00581         BenchMarkKeyAgreement<DH>("dh1024.dat", "DH 1024", t);
    00582         BenchMarkKeyAgreement<DH>("dh2048.dat", "DH 2048", t);
    00583         BenchMarkKeyAgreement<LUC_DH>("lucd512.dat", "LUCDIF 512", t);
    00584         BenchMarkKeyAgreement<LUC_DH>("lucd1024.dat", "LUCDIF 1024", t);
    00585         BenchMarkKeyAgreement<MQV>("mqv1024.dat", "MQV 1024", t);
    00586         BenchMarkKeyAgreement<MQV>("mqv2048.dat", "MQV 2048", t);
    00587
    00588         cout << "<TBODY style=\"background: white\">" << endl;
    00589         {
    00590                 Integer modulus("199999999999999999999999980586675243082581144187569");
    00591                 Integer a("659942,b7261b,249174,c86bd5,e2a65b,45fe07,37d110h");
    00592                 Integer b("3ece7d,09473d,666000,5baef5,d4e00e,30159d,2df49ah");
    00593                 Integer x("25dd61,4c0667,81abc0,fe6c84,fefaa3,858ca6,96d0e8h");
    00594                 Integer y("4e2477,05aab0,b3497f,d62b5e,78a531,446729,6c3fach");
    00595                 Integer r("100000000000000000000000000000000000000000000000151");
    00596                 Integer k(2);
    00597                 Integer d("76572944925670636209790912427415155085360939712345");
    00598
    00599                 ECP ec(modulus, a, b);
    00600                 ECP::Point P(x, y);
    00601                 P = ec.Multiply(k, P);
    00602                 ECP::Point Q(ec.Multiply(d, P));
    00603                 ECIES<ECP>::Decryptor cpriv(ec, P, r, d);
    00604                 ECIES<ECP>::Encryptor cpub(cpriv);
    00605                 ECDSA<ECP, SHA>::Signer spriv(cpriv);
    00606                 ECDSA<ECP, SHA>::Verifier spub(spriv);
    00607                 ECDH<ECP>::Domain ecdhc(ec, P, r, k);
    00608                 ECMQV<ECP>::Domain ecmqvc(ec, P, r, k);
    00609
    00610                 BenchMarkEncryption("ECIES over GF(p) 168", cpub, t);
    00611                 BenchMarkDecryption("ECIES over GF(p) 168", cpriv, cpub, t);
    00612                 BenchMarkSigning("ECNR over GF(p) 168", spriv, t);
    00613                 BenchMarkVerification("ECNR over GF(p) 168", spriv, spub, t);
    00614                 BenchMarkKeyGen("ECDHC over GF(p) 168", ecdhc, t);
    00615                 BenchMarkAgreement("ECDHC over GF(p) 168", ecdhc, t);
    00616                 BenchMarkKeyGen("ECMQVC over GF(p) 168", ecmqvc, t);
    00617                 BenchMarkAgreement("ECMQVC over GF(p) 168", ecmqvc, t);
    00618         }
    00619
    00620         cout << "<TBODY style=\"background: yellow\">" << endl;
    00621         {
    00622                 Integer r("3805993847215893016155463826195386266397436443");
    00623                 Integer k(12);
    00624                 Integer d("2065729449256706362097909124274151550853609397");
    00625
    00626                 GF2NT gf2n(155, 62, 0);
    00627                 byte b[]={0x7, 0x33, 0x8f};
    00628                 EC2N ec(gf2n, PolynomialMod2::Zero(), PolynomialMod2(b,3));
    00629                 EC2N::Point P(0x7B, 0x1C8);
    00630                 P = ec.Multiply(k, P);
    00631                 EC2N::Point Q(ec.Multiply(d, P));
    00632                 ECIES<EC2N>::Decryptor cpriv(ec, P, r, d);
    00633                 ECIES<EC2N>::Encryptor cpub(cpriv);
    00634                 ECDSA<EC2N, SHA>::Signer spriv(cpriv);
    00635                 ECDSA<EC2N, SHA>::Verifier spub(spriv);
    00636                 ECDH<EC2N>::Domain ecdhc(ec, P, r, k);
    00637                 ECMQV<EC2N>::Domain ecmqvc(ec, P, r, k);
    00638
    00639                 BenchMarkEncryption("ECIES over GF(2^n) 155", cpub, t);
    00640                 BenchMarkDecryption("ECIES over GF(2^n) 155", cpriv, cpub, t);
    00641                 BenchMarkSigning("ECNR over GF(2^n) 155", spriv, t);
    00642                 BenchMarkVerification("ECNR over GF(2^n) 155", spriv, spub, t);
    00643                 BenchMarkKeyGen("ECDHC over GF(2^n) 155", ecdhc, t);
    00644                 BenchMarkAgreement("ECDHC over GF(2^n) 155", ecdhc, t);
    00645                 BenchMarkKeyGen("ECMQVC over GF(2^n) 155", ecmqvc, t);
    00646                 BenchMarkAgreement("ECMQVC over GF(2^n) 155", ecmqvc, t);
    00647         }
    00648         cout << "</TABLE>" << endl;
    00649
    00650         cout << "Throughput Geometric Average: " << setiosflags(ios::fixed) << exp(logtotal/logcount) << endl;
    00651
    00652         time_t endTime = time(NULL);
    00653         cout << "\nTest ended at " << asctime(localtime(&endTime));
    00654 #endif
    00655 }