From caf9e032e6b4ccb114a74a3936c916bcfaba262d Mon Sep 17 00:00:00 2001 From: weidai Date: Mon, 2 Mar 2009 02:39:17 +0000 Subject: changes for 5.6: - added AuthenticatedSymmetricCipher interface class and Filter wrappers - added CCM, GCM (with SSE2 assembly), CMAC, and SEED - improved AES speed on x86 and x64 - removed WORD64_AVAILABLE; compiler 64-bit int support is now required git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@433 57ff6487-cd31-0410-9ec3-f628ee90f5f0 --- bench.cpp | 103 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 54 insertions(+), 49 deletions(-) (limited to 'bench.cpp') diff --git a/bench.cpp b/bench.cpp index 3190087..88f1501 100644 --- a/bench.cpp +++ b/bench.cpp @@ -5,20 +5,8 @@ #include "bench.h" #include "crc.h" #include "adler32.h" -#include "idea.h" -#include "des.h" -#include "rc5.h" -#include "blowfish.h" #include "wake.h" -#include "cast.h" #include "seal.h" -#include "rc6.h" -#include "mars.h" -#include "twofish.h" -#include "serpent.h" -#include "skipjack.h" -#include "cbcmac.h" -#include "dmac.h" #include "aes.h" #include "blumshub.h" #include "rng.h" @@ -85,6 +73,7 @@ void OutputResultOperations(const char *name, const char *operation, bool pc, un logcount++; } +/* void BenchMark(const char *name, BlockTransformation &cipher, double timeTotal) { const int BUF_SIZE = RoundUpToMultipleOf(2048U, cipher.OptimalNumberOfParallelBlocks() * cipher.BlockSize()); @@ -105,6 +94,7 @@ void BenchMark(const char *name, BlockTransformation &cipher, double timeTotal) OutputResultBytes(name, double(blocks) * BUF_SIZE, timeTaken); } +*/ void BenchMark(const char *name, StreamTransformation &cipher, double timeTotal) { @@ -192,9 +182,9 @@ template void BenchMarkKeyed(const char *name, double timeTotal, const NameValuePairs ¶ms = g_nullNameValuePairs, T *x=NULL) { T c; - c.SetKey(key, c.DefaultKeyLength(), CombinedNameValuePairs(params, MakeParameters(Name::IV(), key, false))); + c.SetKey(key, c.DefaultKeyLength(), CombinedNameValuePairs(params, MakeParameters(Name::IV(), ConstByteArrayParameter(key, c.IVSize()), false))); BenchMark(name, c, timeTotal); - BenchMarkKeying(c, c.DefaultKeyLength(), CombinedNameValuePairs(params, MakeParameters(Name::IV(), key, false))); + BenchMarkKeying(c, c.DefaultKeyLength(), CombinedNameValuePairs(params, MakeParameters(Name::IV(), ConstByteArrayParameter(key, c.IVSize()), false))); } //VC60 workaround: compiler bug triggered without the extra dummy parameters @@ -202,9 +192,9 @@ template void BenchMarkKeyedVariable(const char *name, double timeTotal, unsigned int keyLength, const NameValuePairs ¶ms = g_nullNameValuePairs, T *x=NULL) { T c; - c.SetKey(key, keyLength, CombinedNameValuePairs(params, MakeParameters(Name::IV(), key, false))); + c.SetKey(key, keyLength, CombinedNameValuePairs(params, MakeParameters(Name::IV(), ConstByteArrayParameter(key, c.IVSize()), false))); BenchMark(name, c, timeTotal); - BenchMarkKeying(c, keyLength, CombinedNameValuePairs(params, MakeParameters(Name::IV(), key, false))); + BenchMarkKeying(c, keyLength, CombinedNameValuePairs(params, MakeParameters(Name::IV(), ConstByteArrayParameter(key, c.IVSize()), false))); } //VC60 workaround: compiler bug triggered without the extra dummy parameters @@ -216,8 +206,8 @@ void BenchMarkKeyless(const char *name, double timeTotal, T *x=NULL) } //VC60 workaround: compiler bug triggered without the extra dummy parameters -template -void BenchMarkByName(const char *factoryName, size_t keyLength = 0, const char *displayName=NULL, const NameValuePairs ¶ms = g_nullNameValuePairs, T *x=NULL) +template +void BenchMarkByName(const char *factoryName, size_t keyLength = 0, const char *displayName=NULL, const NameValuePairs ¶ms = g_nullNameValuePairs, T_FactoryOutput *x=NULL, T_Interface *y=NULL) { std::string name = factoryName; if (displayName) @@ -225,12 +215,19 @@ void BenchMarkByName(const char *factoryName, size_t keyLength = 0, const char * else if (keyLength) name += " (" + IntToString(keyLength * 8) + "-bit key)"; - std::auto_ptr obj(ObjectFactoryRegistry::Registry().CreateObject(factoryName)); + std::auto_ptr obj(ObjectFactoryRegistry::Registry().CreateObject(factoryName)); if (!keyLength) keyLength = obj->DefaultKeyLength(); - obj->SetKey(key, keyLength, CombinedNameValuePairs(params, MakeParameters(Name::IV(), key, false))); - BenchMark(name.c_str(), *obj, g_allocatedTime); - BenchMarkKeying(*obj, keyLength, CombinedNameValuePairs(params, MakeParameters(Name::IV(), key, false))); + obj->SetKey(key, keyLength, CombinedNameValuePairs(params, MakeParameters(Name::IV(), ConstByteArrayParameter(key, obj->IVSize()), false))); + BenchMark(name.c_str(), *static_cast(obj.get()), g_allocatedTime); + BenchMarkKeying(*obj, keyLength, CombinedNameValuePairs(params, MakeParameters(Name::IV(), ConstByteArrayParameter(key, obj->IVSize()), false))); +} + +//VC60 workaround: compiler bug triggered without the extra dummy parameters +template +void BenchMarkByName(const char *factoryName, size_t keyLength = 0, const char *displayName=NULL, const NameValuePairs ¶ms = g_nullNameValuePairs, T_FactoryOutput *x=NULL) +{ + BenchMarkByName(factoryName, keyLength, displayName, params, x, x); } template @@ -268,13 +265,20 @@ void BenchmarkAll(double t, double hertz) cout << "" << endl; cout << ""; + BenchMarkByName("AES/GCM", 0, "AES/GCM (2K tables)", MakeParameters(Name::TableSize(), 2048)); + BenchMarkByName("AES/GCM", 0, "AES/GCM (64K tables)", MakeParameters(Name::TableSize(), 64*1024)); + BenchMarkByName("AES/CCM"); + cout << "\n"; + BenchMarkByName("AES/GCM", 0, "GMAC(AES) (2K tables)", MakeParameters(Name::TableSize(), 2048)); + BenchMarkByName("AES/GCM", 0, "GMAC(AES) (64K tables)", MakeParameters(Name::TableSize(), 64*1024)); BenchMarkByName("VMAC(AES)-64"); BenchMarkByName("VMAC(AES)-128"); BenchMarkByName("HMAC(SHA-1)"); BenchMarkByName("Two-Track-MAC"); - BenchMarkKeyed >("CBC-MAC/AES", t); - BenchMarkKeyed >("DMAC/AES", t); + BenchMarkByName("CMAC(AES)"); + BenchMarkByName("DMAC(AES)"); cout << "\n"; BenchMarkKeyless("CRC-32", t); @@ -282,11 +286,9 @@ void BenchmarkAll(double t, double hertz) BenchMarkByNameKeyLess("MD5"); BenchMarkByNameKeyLess("SHA-1"); BenchMarkByNameKeyLess("SHA-256"); -#ifdef WORD64_AVAILABLE BenchMarkByNameKeyLess("SHA-512"); BenchMarkByNameKeyLess("Tiger"); BenchMarkByNameKeyLess("Whirlpool"); -#endif BenchMarkByNameKeyLess("RIPEMD-160"); BenchMarkByNameKeyLess("RIPEMD-320"); BenchMarkByNameKeyLess("RIPEMD-128"); @@ -306,32 +308,35 @@ void BenchmarkAll(double t, double hertz) BenchMarkKeyed::Encryption>("WAKE-OFB-LE", t); cout << "\n"; - BenchMarkByName("AES/ECB", 16); - BenchMarkByName("AES/ECB", 24); - BenchMarkByName("AES/ECB", 32); BenchMarkByName("AES/CTR", 16); + BenchMarkByName("AES/CTR", 24); + BenchMarkByName("AES/CTR", 32); + BenchMarkByName("AES/CBC", 16); + BenchMarkByName("AES/CBC", 24); + BenchMarkByName("AES/CBC", 32); BenchMarkByName("AES/OFB", 16); BenchMarkByName("AES/CFB", 16); - BenchMarkByName("AES/CBC", 16); - BenchMarkByName("Camellia/ECB", 16); - BenchMarkByName("Camellia/ECB", 32); - BenchMarkKeyed("Twofish", t); - BenchMarkKeyed("Serpent", t); - BenchMarkKeyed("CAST-256", t); - BenchMarkKeyed("RC6", t); - BenchMarkKeyed("MARS", t); - BenchMarkByName("SHACAL-2/ECB", 16); - BenchMarkByName("SHACAL-2/ECB", 64); - BenchMarkKeyed("DES", t); - BenchMarkKeyed("DES-XEX3", t); - BenchMarkKeyed("DES-EDE3", t); - BenchMarkKeyed("IDEA", t); - BenchMarkKeyed("RC5 (r=16)", t); - BenchMarkKeyed("Blowfish", t); - BenchMarkByName("TEA/ECB"); - BenchMarkByName("XTEA/ECB"); - BenchMarkKeyed("CAST-128", t); - BenchMarkKeyed("SKIPJACK", t); + BenchMarkByName("AES/ECB", 16); + BenchMarkByName("Camellia/CTR", 16); + BenchMarkByName("Camellia/CTR", 32); + BenchMarkByName("Twofish/CTR"); + BenchMarkByName("Serpent/CTR"); + BenchMarkByName("CAST-256/CTR"); + BenchMarkByName("RC6/CTR"); + BenchMarkByName("MARS/CTR"); + BenchMarkByName("SHACAL-2/CTR", 16); + BenchMarkByName("SHACAL-2/CTR", 64); + BenchMarkByName("DES/CTR"); + BenchMarkByName("DES-XEX3/CTR"); + BenchMarkByName("DES-EDE3/CTR"); + BenchMarkByName("IDEA/CTR"); + BenchMarkByName("RC5/CTR", 0, "RC5 (r=16)"); + BenchMarkByName("Blowfish/CTR"); + BenchMarkByName("TEA/CTR"); + BenchMarkByName("XTEA/CTR"); + BenchMarkByName("CAST-128/CTR"); + BenchMarkByName("SKIPJACK/CTR"); + BenchMarkByName("SEED/CTR", 0, "SEED/CTR (1/2 K table)"); cout << "
AlgorithmMiB/Second" << cpb << "Microseconds to
Setup Key and IV" << cpk << endl; + cout << "\n
" << endl; BenchmarkAll2(t, hertz); -- cgit v1.2.1