Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class 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 "md4.h" 00009 #include "md5.h" 00010 #include "md5mac.h" 00011 #include "sha.h" 00012 #include "haval.h" 00013 #include "tiger.h" 00014 #include "ripemd.h" 00015 #include "panama.h" 00016 #include "idea.h" 00017 #include "des.h" 00018 #include "rc2.h" 00019 #include "arc4.h" 00020 #include "rc5.h" 00021 #include "blowfish.h" 00022 #include "diamond.h" 00023 #include "wake.h" 00024 #include "3way.h" 00025 #include "safer.h" 00026 #include "gost.h" 00027 #include "shark.h" 00028 #include "cast.h" 00029 #include "square.h" 00030 #include "skipjack.h" 00031 #include "seal.h" 00032 #include "rc6.h" 00033 #include "mars.h" 00034 #include "rijndael.h" 00035 #include "twofish.h" 00036 #include "serpent.h" 00037 #include "hmac.h" 00038 #include "xormac.h" 00039 #include "cbcmac.h" 00040 #include "dmac.h" 00041 #include "blumshub.h" 00042 #include "rsa.h" 00043 #include "nr.h" 00044 #include "dsa.h" 00045 #include "luc.h" 00046 #include "rabin.h" 00047 #include "rw.h" 00048 #include "eccrypto.h" 00049 #include "ecp.h" 00050 #include "ec2n.h" 00051 #include "asn.h" 00052 #include "rng.h" 00053 #include "files.h" 00054 #include "hex.h" 00055 #include "modes.h" 00056 #include "mdc.h" 00057 #include "lubyrack.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(rng, 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, signature.size()); 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>Hashing Algorithms<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<MD4>("MD4", t); 00440 BenchMarkKeyless<MD5>("MD5", t); 00441 BenchMarkKeyless<SHA>("SHA-1", t); 00442 BenchMarkKeyless<SHA256>("SHA-256", t); 00443 BenchMarkKeyless<SHA512>("SHA-512", t); 00444 BenchMarkKeyless<HAVAL3>("HAVAL (pass=3)", t); 00445 BenchMarkKeyless<HAVAL4>("HAVAL (pass=4)", t); 00446 BenchMarkKeyless<HAVAL5>("HAVAL (pass=5)", t); 00447 #ifdef WORD64_AVAILABLE 00448 BenchMarkKeyless<Tiger>("Tiger", t); 00449 #endif 00450 BenchMarkKeyless<RIPEMD160>("RIPE-MD160", t); 00451 BenchMarkKeyless<PanamaHash<LittleEndian> >("Panama Hash (little endian)", t); 00452 BenchMarkKeyless<PanamaHash<BigEndian> >("Panama Hash (big endian)", t); 00453 00454 cout << "</TABLE><P>" << endl; 00455 cout << "<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right><COL align=right>" << endl; 00456 cout << "<THEAD><TR><TH>Encryption Algorithms<TH>Bytes Processed<TH>Time Taken<TH>Megabytes(2^20 bytes)/Second\n<TBODY>" << endl; 00457 00458 BenchMarkKeyed<MDC<MD5>::Encryption>("MDC/MD5", t); 00459 BenchMarkKeyed<LR<MD5>::Encryption>("Luby-Rackoff/MD5", t); 00460 BenchMarkKeyed<DES::Encryption>("DES", t); 00461 BenchMarkKeyed<DES_XEX3::Encryption>("DES-XEX3", t); 00462 BenchMarkKeyed<DES_EDE3::Encryption>("DES-EDE3", t); 00463 BenchMarkKeyed<IDEA::Encryption>("IDEA", t); 00464 BenchMarkKeyed<RC2::Encryption>("RC2", t); 00465 BenchMarkKeyed<RC5::Encryption>("RC5 (r=16)", t); 00466 BenchMarkKeyed<Blowfish::Encryption>("Blowfish", t); 00467 BenchMarkKeyed<Diamond2::Encryption>("Diamond2", t); 00468 BenchMarkKeyed<Diamond2Lite::Encryption>("Diamond2 Lite", t); 00469 BenchMarkKeyed<ThreeWayDecryption>("3-WAY", t); 00470 BenchMarkKeyed<TEA::Encryption>("TEA", t); 00471 BenchMarkKeyedVariable<SAFER_SK::Encryption>("SAFER (r=8)", t, 8); 00472 BenchMarkKeyed<GOST::Encryption>("GOST", t); 00473 #ifdef WORD64_AVAILABLE 00474 BenchMarkKeyed<SHARK::Encryption>("SHARK (r=6)", t); 00475 #endif 00476 BenchMarkKeyed<CAST128::Encryption>("CAST-128", t); 00477 BenchMarkKeyed<CAST256::Encryption>("CAST-256", t); 00478 BenchMarkKeyed<Square::Encryption>("Square", t); 00479 BenchMarkKeyed<SKIPJACK::Encryption>("SKIPJACK", t); 00480 BenchMarkKeyed<RC6::Encryption>("RC6", t); 00481 BenchMarkKeyed<MARS::Encryption>("MARS", t); 00482 BenchMarkKeyedVariable<Rijndael::Encryption>("Rijndael (128-bit key)", t, 16); 00483 BenchMarkKeyedVariable<Rijndael::Encryption>("Rijndael (192-bit key)", t, 24); 00484 BenchMarkKeyedVariable<Rijndael::Encryption>("Rijndael (256-bit key)", t, 32); 00485 BenchMarkKeyedVariable<CTR_Mode<Rijndael>::Encryption>("Rijndael (128) CTR", t, 16); 00486 BenchMarkKeyedVariable<OFB_Mode<Rijndael>::Encryption>("Rijndael (128) OFB", t, 16); 00487 BenchMarkKeyedVariable<CFB_Mode<Rijndael>::Encryption>("Rijndael (128) CFB", t, 16); 00488 BenchMarkKeyedVariable<CBC_Mode<Rijndael>::Encryption>("Rijndael (128) CBC", t, 16); 00489 BenchMarkKeyed<Twofish::Encryption>("Twofish", t); 00490 BenchMarkKeyed<Serpent::Encryption>("Serpent", t); 00491 BenchMarkKeyed<ARC4>("ARC4", t); 00492 BenchMarkKeyed<SEAL<BigEndian>::Encryption>("SEAL-3.0-BE", t); 00493 BenchMarkKeyed<SEAL<LittleEndian>::Encryption>("SEAL-3.0-LE", t); 00494 BenchMarkKeyed<WAKE_CFB<BigEndian>::Encryption>("WAKE-CFB-BE", t); 00495 BenchMarkKeyed<WAKE_CFB<LittleEndian>::Encryption>("WAKE-CFB-LE", t); 00496 BenchMarkKeyed<WAKE_OFB<BigEndian>::Encryption>("WAKE-OFB-BE", t); 00497 BenchMarkKeyed<WAKE_OFB<LittleEndian>::Encryption>("WAKE-OFB-LE", t); 00498 BenchMarkKeyed<PanamaCipher<LittleEndian>::Encryption>("Panama Cipher (little endian)", t); 00499 BenchMarkKeyed<PanamaCipher<BigEndian>::Encryption>("Panama Cipher (big endian)", t); 00500 BenchMarkKeyed<MD5MAC>("MD5-MAC", t); 00501 BenchMarkKeyed<XMACC<MD5> >("XMACC/MD5", t); 00502 BenchMarkKeyed<HMAC<MD5> >("HMAC/MD5", t); 00503 BenchMarkKeyed<CBC_MAC<Rijndael> >("CBC-MAC/Rijndael", t); 00504 BenchMarkKeyed<DMAC<Rijndael> >("DMAC/Rijndael", t); 00505 00506 { 00507 Integer p("CB6C,B8CE,6351,164F,5D0C,0C9E,9E31,E231,CF4E,D551,CBD0,E671,5D6A,7B06,D8DF,C4A7h"); 00508 Integer q("FD2A,8594,A132,20CC,4E6D,DE77,3AAA,CF15,CD9E,E447,8592,FF46,CC77,87BE,9876,A2AFh"); 00509 Integer s("63239752671357255800299643604761065219897634268887145610573595874544114193025997412441121667211431"); 00510 BlumBlumShub c(p, q, s); 00511 BenchMark("BlumBlumShub 512", c, t); 00512 } 00513 { 00514 Integer p("FD2A,8594,A132,20CC,4E6D,DE77,3AAA,CF15,CD9E,E447,8592,FF46,CC77,87BE,9876,9E2C," 00515 "8572,64C3,4CF4,188A,44D4,2130,1135,7982,6FF6,EDD3,26F0,5FAA,BAF4,A81E,7ADC,B80Bh"); 00516 Integer q("C8B9,5797,B349,6BA3,FD72,F2C0,A796,8A65,EE0F,B4BA,272F,4FEE,4DB1,06D5,ECEB,7142," 00517 "E8A8,E5A8,6BF9,A32F,BA37,BACC,8A75,8A6B,2DCE,D6EC,B515,980A,4BB1,08FB,6F2C,2383h"); 00518 Integer s("3578,8F00,2965,71A4,4382,699F,45FD,3922,8238,241B,CEBA,0543,3443,E8D9,12FB,AC46," 00519 "7EC4,8505,EC9E,7EE8,5A23,9B2A,B615,D0C4,9448,F23A,ADEE,E850,1A7A,CA30,0B5B,A408," 00520 "D936,21BA,844E,BDD6,7848,3D1E,9137,CC87,DAA5,773B,D45A,C8BB,5392,1393,108B,6992," 00521 "74E3,C5E2,C235,A321,0111,3BA4,BAB4,1A2F,17EE,C371,DE67,01C9,0F3D,907A,B252,9BDDh"); 00522 BlumBlumShub c(p, q, s); 00523 BenchMark("BlumBlumShub 1024", c, t); 00524 } 00525 { 00526 Integer p("EB56,978A,7BA7,B5D9,1383,4611,94F5,4766,FCEF,CF41,958A,FC41,43D0,839F,C56B,B568," 00527 "4ED3,9E5A,BABB,5ACE,8B11,CEBC,88A2,7C12,FFEE,E6E8,CF0A,E231,5BC2,DEDE,80B7,32F6," 00528 "340E,D8A6,B7DE,C779,7EE5,0E16,9C88,FC9F,2A0E,EE6C,7D47,C5F2,6B06,EB8C,F1C8,2E67," 00529 "5B82,8C28,4FB8,542F,2874,C355,CEEE,7A54,1B06,A8AB,8B66,6A5C,9DB2,72B8,74F3,7BC7h"); 00530 Integer q("EB6B,3645,4591,8343,7331,7CAC,B02E,4BB9,DEF5,8EDC,1772,DB9B,9571,5FAB,1CDD,4FB1," 00531 "7B9A,07CD,E715,D448,F552,CBBD,D387,C037,DE70,6661,F360,D0E8,D42E,292A,9321,DDCB," 00532 "0BF9,C514,BFAC,3F2C,C06E,DF64,A9B8,50D6,AC4F,B9E4,014B,5624,2B40,A0D4,5D0B,6DD4," 00533 "0989,D00E,0268,99AB,21DB,0BB4,DB38,84DA,594F,575F,95AC,1B70,45E4,96C8,C6AD,CE67h"); 00534 Integer s("C75A,8A0D,E231,295F,C08A,1716,8611,D5EC,E9EF,B565,90EC,58C0,57D0,DA7D,C6E6,DB00," 00535 "2282,1CA7,EA31,D64E,768C,0B19,8563,36DF,2226,F4EC,74A4,2844,2E8D,37E8,53DC,0172," 00536 "5F56,8CF9,B444,CA02,78B3,17AF,7C78,D320,16AE,AC3D,B97F,7259,1B8F,9C84,6A16,B878," 00537 "0595,70BB,9C52,18B5,9100,9C1F,E85A,4035,06F3,5F38,7462,F01D,0462,BFBC,A4CD,4A45," 00538 "3A77,E7F8,DED1,D6EF,CEF7,0937,CD3F,3AF1,4F88,932D,6D4B,002C,3735,304C,C5D3,B88A," 00539 "B57B,24B6,5346,9B46,5153,B7ED,B216,C181,B1C6,C52E,CD2B,E0AA,B1BB,0A93,C92E,4F79," 00540 "4931,E303,7C8F,A408,8ACF,56CD,6EC0,76A2,5015,6BA4,4C50,C44D,53B9,E168,5F84,B381," 00541 "2514,10B2,00E5,B4D1,4156,A2FE,0BF6,6F33,0A1B,91C6,31B8,1C90,02F1,FB1F,C494,8B65h"); 00542 BlumBlumShub c(p, q, s); 00543 BenchMark("BlumBlumShub 2048", c, t); 00544 } 00545 cout << "</TABLE><P>" << endl; 00546 00547 cout << "<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right><COL align=right>" << endl; 00548 cout << "<THEAD><TR><TH>Operation<TH>Iterations<TH>Total Time<TH>Milliseconds/Operation" << endl; 00549 00550 cout << "<TBODY style=\"background: yellow\">" << endl; 00551 BenchMarkCrypto<RSAES<OAEP<SHA> > >(PKGDATADIR "rsa1024.dat", "RSA 1024", t); 00552 BenchMarkCrypto<RabinES<OAEP<SHA> > >(PKGDATADIR "rabi1024.dat", "Rabin 1024", t); 00553 BenchMarkCrypto<LUCES<OAEP<SHA> > >(PKGDATADIR "luc1024.dat", "LUC 1024", t); 00554 BenchMarkCrypto<DLIES<> >(PKGDATADIR "dlie1024.dat", "DLIES 1024", t); 00555 BenchMarkCrypto<LUC_IES<> >(PKGDATADIR "lucc512.dat", "LUCELG 512", t); 00556 00557 cout << "<TBODY style=\"background: white\">" << endl; 00558 BenchMarkCrypto<RSAES<OAEP<SHA> > >(PKGDATADIR "rsa2048.dat", "RSA 2048", t); 00559 BenchMarkCrypto<RabinES<OAEP<SHA> > >(PKGDATADIR "rabi2048.dat", "Rabin 2048", t); 00560 BenchMarkCrypto<LUCES<OAEP<SHA> > >(PKGDATADIR "luc2048.dat", "LUC 2048", t); 00561 BenchMarkCrypto<DLIES<> >(PKGDATADIR "dlie2048.dat", "DLIES 2048", t); 00562 BenchMarkCrypto<LUC_IES<> >(PKGDATADIR "lucc1024.dat", "LUCELG 1024", t); 00563 00564 cout << "<TBODY style=\"background: yellow\">" << endl; 00565 BenchMarkSignature<RSASS<PSSR, SHA> >(PKGDATADIR "rsa1024.dat", "RSA 1024", t); 00566 BenchMarkSignature<RabinSS<PSSR, SHA> >(PKGDATADIR "rabi1024.dat", "Rabin 1024", t); 00567 BenchMarkSignature<RWSS<PSSR, SHA> >(PKGDATADIR "rw1024.dat", "RW 1024", t); 00568 BenchMarkSignature<LUCSS<PSSR, SHA> >(PKGDATADIR "luc1024.dat", "LUC 1024", t); 00569 BenchMarkSignature<NR<SHA> >(PKGDATADIR "nr1024.dat", "NR 1024", t); 00570 BenchMarkSignature<DSA>(PKGDATADIR "dsa1024.dat", "DSA 1024", t); 00571 BenchMarkSignature<LUC_HMP<SHA> >(PKGDATADIR "lucs512.dat", "LUC-HMP 512", t); 00572 BenchMarkSignature<ESIGN<SHA> >(PKGDATADIR "esig1023.dat", "ESIGN 1023", t); 00573 BenchMarkSignature<ESIGN<SHA> >(PKGDATADIR "esig1536.dat", "ESIGN 1536", t); 00574 00575 cout << "<TBODY style=\"background: white\">" << endl; 00576 BenchMarkSignature<RSASS<PSSR, SHA> >(PKGDATADIR "rsa2048.dat", "RSA 2048", t); 00577 BenchMarkSignature<RabinSS<PSSR, SHA> >(PKGDATADIR "rabi2048.dat", "Rabin 2048", t); 00578 BenchMarkSignature<RWSS<PSSR, SHA> >(PKGDATADIR "rw2048.dat", "RW 2048", t); 00579 BenchMarkSignature<LUCSS<PSSR, SHA> >(PKGDATADIR "luc2048.dat", "LUC 2048", t); 00580 BenchMarkSignature<NR<SHA> >(PKGDATADIR "nr2048.dat", "NR 2048", t); 00581 BenchMarkSignature<LUC_HMP<SHA> >(PKGDATADIR "lucs1024.dat", "LUC-HMP 1024", t); 00582 BenchMarkSignature<ESIGN<SHA> >(PKGDATADIR "esig2046.dat", "ESIGN 2046", t); 00583 00584 cout << "<TBODY style=\"background: yellow\">" << endl; 00585 BenchMarkKeyAgreement<XTR_DH>(PKGDATADIR "xtrdh171.dat", "XTR-DH 171", t); 00586 BenchMarkKeyAgreement<XTR_DH>(PKGDATADIR "xtrdh342.dat", "XTR-DH 342", t); 00587 BenchMarkKeyAgreement<DH>(PKGDATADIR "dh1024.dat", "DH 1024", t); 00588 BenchMarkKeyAgreement<DH>(PKGDATADIR "dh2048.dat", "DH 2048", t); 00589 BenchMarkKeyAgreement<LUC_DH>(PKGDATADIR "lucd512.dat", "LUCDIF 512", t); 00590 BenchMarkKeyAgreement<LUC_DH>(PKGDATADIR "lucd1024.dat", "LUCDIF 1024", t); 00591 BenchMarkKeyAgreement<MQV>(PKGDATADIR "mqv1024.dat", "MQV 1024", t); 00592 BenchMarkKeyAgreement<MQV>(PKGDATADIR "mqv2048.dat", "MQV 2048", t); 00593 00594 cout << "<TBODY style=\"background: white\">" << endl; 00595 { 00596 Integer modulus("199999999999999999999999980586675243082581144187569"); 00597 Integer a("659942,b7261b,249174,c86bd5,e2a65b,45fe07,37d110h"); 00598 Integer b("3ece7d,09473d,666000,5baef5,d4e00e,30159d,2df49ah"); 00599 Integer x("25dd61,4c0667,81abc0,fe6c84,fefaa3,858ca6,96d0e8h"); 00600 Integer y("4e2477,05aab0,b3497f,d62b5e,78a531,446729,6c3fach"); 00601 Integer r("100000000000000000000000000000000000000000000000151"); 00602 Integer k(2); 00603 Integer d("76572944925670636209790912427415155085360939712345"); 00604 00605 ECP ec(modulus, a, b); 00606 ECP::Point P(x, y); 00607 P = ec.Multiply(k, P); 00608 ECP::Point Q(ec.Multiply(d, P)); 00609 ECIES<ECP>::Decryptor cpriv(ec, P, r, d); 00610 ECIES<ECP>::Encryptor cpub(cpriv); 00611 ECDSA<ECP, SHA>::Signer spriv(cpriv); 00612 ECDSA<ECP, SHA>::Verifier spub(spriv); 00613 ECDH<ECP>::Domain ecdhc(ec, P, r, k); 00614 ECMQV<ECP>::Domain ecmqvc(ec, P, r, k); 00615 00616 BenchMarkEncryption("ECIES over GF(p) 168", cpub, t); 00617 BenchMarkDecryption("ECIES over GF(p) 168", cpriv, cpub, t); 00618 BenchMarkSigning("ECNR over GF(p) 168", spriv, t); 00619 BenchMarkVerification("ECNR over GF(p) 168", spriv, spub, t); 00620 BenchMarkKeyGen("ECDHC over GF(p) 168", ecdhc, t); 00621 BenchMarkAgreement("ECDHC over GF(p) 168", ecdhc, t); 00622 BenchMarkKeyGen("ECMQVC over GF(p) 168", ecmqvc, t); 00623 BenchMarkAgreement("ECMQVC over GF(p) 168", ecmqvc, t); 00624 } 00625 00626 cout << "<TBODY style=\"background: yellow\">" << endl; 00627 { 00628 Integer r("3805993847215893016155463826195386266397436443"); 00629 Integer k(12); 00630 Integer d("2065729449256706362097909124274151550853609397"); 00631 00632 GF2NT gf2n(155, 62, 0); 00633 byte b[]={0x7, 0x33, 0x8f}; 00634 EC2N ec(gf2n, PolynomialMod2::Zero(), PolynomialMod2(b,3)); 00635 EC2N::Point P(0x7B, 0x1C8); 00636 P = ec.Multiply(k, P); 00637 EC2N::Point Q(ec.Multiply(d, P)); 00638 ECIES<EC2N>::Decryptor cpriv(ec, P, r, d); 00639 ECIES<EC2N>::Encryptor cpub(cpriv); 00640 ECDSA<EC2N, SHA>::Signer spriv(cpriv); 00641 ECDSA<EC2N, SHA>::Verifier spub(spriv); 00642 ECDH<EC2N>::Domain ecdhc(ec, P, r, k); 00643 ECMQV<EC2N>::Domain ecmqvc(ec, P, r, k); 00644 00645 BenchMarkEncryption("ECIES over GF(2^n) 155", cpub, t); 00646 BenchMarkDecryption("ECIES over GF(2^n) 155", cpriv, cpub, t); 00647 BenchMarkSigning("ECNR over GF(2^n) 155", spriv, t); 00648 BenchMarkVerification("ECNR over GF(2^n) 155", spriv, spub, t); 00649 BenchMarkKeyGen("ECDHC over GF(2^n) 155", ecdhc, t); 00650 BenchMarkAgreement("ECDHC over GF(2^n) 155", ecdhc, t); 00651 BenchMarkKeyGen("ECMQVC over GF(2^n) 155", ecmqvc, t); 00652 BenchMarkAgreement("ECMQVC over GF(2^n) 155", ecmqvc, t); 00653 } 00654 cout << "</TABLE>" << endl; 00655 00656 cout << "<P>Throughput Geometric Average: " << setiosflags(ios::fixed) << exp(logtotal/logcount) << endl; 00657 00658 time_t endTime = time(NULL); 00659 cout << "\nTest ended at " << asctime(localtime(&endTime)); 00660 #endif 00661 }

Generated on Fri Aug 13 09:56:52 2004 for Crypto++ by doxygen 1.3.7