24 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 25 # pragma GCC diagnostic ignored "-Wdeprecated-declarations" 33 #elif defined(CLK_TCK) 34 const double CLOCK_TICKS_PER_SECOND = (double)CLK_TCK;
36 const double CLOCK_TICKS_PER_SECOND = 1000000.0;
42 static const byte defaultKey[] =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" 43 "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
51 if (length < 0.0000000001
f) length = 0.000001f;
52 if (timeTaken < 0.0000000001
f) timeTaken = 0.000001f;
54 double mbs = length / timeTaken / (1024*1024);
55 cout <<
"\n<TR><TH>" <<
name;
57 cout << setiosflags(ios::fixed);
59 cout <<
"<TD>" << setprecision(0) << setiosflags(ios::fixed) << mbs;
61 cout <<
"<TD>" << setprecision(1) << setiosflags(ios::fixed) << timeTaken *
g_hertz / length;
72 if (iterations < 0.0000000001
f) iterations = 0.000001f;
73 if (timeTaken < 0.0000000001
f) timeTaken = 0.000001f;
75 cout <<
"<TD>" << setprecision(3) << setiosflags(ios::fixed) << (1000*1000*timeTaken/iterations);
77 cout <<
"<TD>" << setprecision(0) << setiosflags(ios::fixed) << timeTaken *
g_hertz / iterations;
86 if (!iterations) iterations++;
87 if (timeTaken < 0.0000000001
f) timeTaken = 0.000001f;
89 cout <<
"\n<TR><TH>" << name <<
" " << operation << (pc ?
" with precomputation" :
"");
90 cout <<
"<TD>" << setprecision(2) << setiosflags(ios::fixed) << (1000*timeTaken/iterations);
92 cout <<
"<TD>" << setprecision(2) << setiosflags(ios::fixed) << timeTaken *
g_hertz / iterations / 1000000;
94 logtotal += log(iterations/timeTaken);
126 clock_t start =
clock();
128 unsigned long i=0, blocks=1;
133 for (; i<blocks; i++)
137 while (timeTaken < 2.0/3*timeTotal);
147 BenchMark(name, static_cast<StreamTransformation &>(cipher), timeTotal);
152 const int BUF_SIZE=2048U;
155 clock_t start =
clock();
157 unsigned long i=0, blocks=1;
162 for (; i<blocks; i++)
166 while (timeTaken < 2.0/3*timeTotal);
173 const int BUF_SIZE=2048U;
176 clock_t start =
clock();
178 unsigned long i=0, blocks=1;
183 for (; i<blocks; i++)
184 bt.
Put(buf, BUF_SIZE);
187 while (timeTaken < 2.0/3*timeTotal);
194 unsigned long iterations = 0;
195 clock_t start =
clock();
199 for (
unsigned int i=0; i<1024; i++)
200 c.
SetKey(defaultKey, keyLength, params);
209 template <
class T_FactoryOutput,
class T_Interface>
213 std::string
name(factoryName ? factoryName :
"");
217 keyLength = obj->DefaultKeyLength();
222 name +=
" (" +
IntToString(keyLength * 8) +
"-bit key)";
229 template <
class T_FactoryOutput>
233 BenchMarkByName2<T_FactoryOutput, T_FactoryOutput>(factoryName, keyLength, displayName, params);
240 std::string
name = factoryName;
256 const char *cpb, *cpk;
259 cpb =
"<TH>Cycles Per Byte";
260 cpk =
"<TH>Cycles to<br>Setup Key and IV";
261 cout <<
"CPU frequency of the test platform is " <<
g_hertz <<
" Hz.\n";
266 cout <<
"CPU frequency of the test platform was not provided.\n";
269 cout <<
"<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right><COL align=right><COL align=right>" << endl;
270 cout <<
"<THEAD><TR><TH>Algorithm<TH>MiB/Second" << cpb <<
"<TH>Microseconds to<br>Setup Key and IV" << cpk << endl;
272 cout <<
"\n<TBODY style=\"background: yellow\">";
273 #if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE 275 BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>(
"AES/GCM", 0,
"AES/GCM");
279 BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>(
"AES/GCM", 0,
"AES/GCM (2K tables)",
MakeParameters(Name::TableSize(), 2048));
280 BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>(
"AES/GCM", 0,
"AES/GCM (64K tables)",
MakeParameters(Name::TableSize(), 64*1024));
282 BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>(
"AES/CCM");
283 BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>(
"AES/EAX");
285 cout <<
"\n<TBODY style=\"background: white\">";
286 #if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE 288 BenchMarkByName2<AuthenticatedSymmetricCipher, MessageAuthenticationCode>(
"AES/GCM", 0,
"GMAC(AES)");
292 BenchMarkByName2<AuthenticatedSymmetricCipher, MessageAuthenticationCode>(
"AES/GCM", 0,
"GMAC(AES) (2K tables)",
MakeParameters(Name::TableSize(), 2048));
293 BenchMarkByName2<AuthenticatedSymmetricCipher, MessageAuthenticationCode>(
"AES/GCM", 0,
"GMAC(AES) (64K tables)",
MakeParameters(Name::TableSize(), 64*1024));
295 BenchMarkByName<MessageAuthenticationCode>(
"VMAC(AES)-64");
296 BenchMarkByName<MessageAuthenticationCode>(
"VMAC(AES)-128");
297 BenchMarkByName<MessageAuthenticationCode>(
"HMAC(SHA-1)");
298 BenchMarkByName<MessageAuthenticationCode>(
"Two-Track-MAC");
299 BenchMarkByName<MessageAuthenticationCode>(
"CMAC(AES)");
300 BenchMarkByName<MessageAuthenticationCode>(
"DMAC(AES)");
301 BenchMarkByName<MessageAuthenticationCode>(
"Poly1305(AES)");
302 BenchMarkByName<MessageAuthenticationCode>(
"BLAKE2s");
303 BenchMarkByName<MessageAuthenticationCode>(
"BLAKE2b");
304 BenchMarkByName<MessageAuthenticationCode>(
"SipHash-2-4");
305 BenchMarkByName<MessageAuthenticationCode>(
"SipHash-4-8");
307 cout <<
"\n<TBODY style=\"background: yellow\">";
308 BenchMarkByNameKeyLess<HashTransformation>(
"CRC32");
309 BenchMarkByNameKeyLess<HashTransformation>(
"CRC32C");
310 BenchMarkByNameKeyLess<HashTransformation>(
"Adler32");
311 BenchMarkByNameKeyLess<HashTransformation>(
"MD5");
312 BenchMarkByNameKeyLess<HashTransformation>(
"SHA-1");
313 BenchMarkByNameKeyLess<HashTransformation>(
"SHA-256");
314 BenchMarkByNameKeyLess<HashTransformation>(
"SHA-512");
315 BenchMarkByNameKeyLess<HashTransformation>(
"Keccak-224");
316 BenchMarkByNameKeyLess<HashTransformation>(
"Keccak-256");
317 BenchMarkByNameKeyLess<HashTransformation>(
"Keccak-384");
318 BenchMarkByNameKeyLess<HashTransformation>(
"Keccak-512");
319 BenchMarkByNameKeyLess<HashTransformation>(
"SHA3-224");
320 BenchMarkByNameKeyLess<HashTransformation>(
"SHA3-256");
321 BenchMarkByNameKeyLess<HashTransformation>(
"SHA3-384");
322 BenchMarkByNameKeyLess<HashTransformation>(
"SHA3-512");
323 BenchMarkByNameKeyLess<HashTransformation>(
"Tiger");
324 BenchMarkByNameKeyLess<HashTransformation>(
"Whirlpool");
325 BenchMarkByNameKeyLess<HashTransformation>(
"RIPEMD-160");
326 BenchMarkByNameKeyLess<HashTransformation>(
"RIPEMD-320");
327 BenchMarkByNameKeyLess<HashTransformation>(
"RIPEMD-128");
328 BenchMarkByNameKeyLess<HashTransformation>(
"RIPEMD-256");
329 BenchMarkByNameKeyLess<HashTransformation>(
"BLAKE2s");
330 BenchMarkByNameKeyLess<HashTransformation>(
"BLAKE2b");
332 cout <<
"\n<TBODY style=\"background: white\">";
333 BenchMarkByName<SymmetricCipher>(
"Panama-LE");
334 BenchMarkByName<SymmetricCipher>(
"Panama-BE");
335 BenchMarkByName<SymmetricCipher>(
"Salsa20");
336 BenchMarkByName<SymmetricCipher>(
"Salsa20", 0,
"Salsa20/12",
MakeParameters(Name::Rounds(), 12));
337 BenchMarkByName<SymmetricCipher>(
"Salsa20", 0,
"Salsa20/8",
MakeParameters(Name::Rounds(), 8));
338 BenchMarkByName<SymmetricCipher>(
"ChaCha20");
339 BenchMarkByName<SymmetricCipher>(
"ChaCha12");
340 BenchMarkByName<SymmetricCipher>(
"ChaCha8");
341 BenchMarkByName<SymmetricCipher>(
"Sosemanuk");
342 BenchMarkByName<SymmetricCipher>(
"MARC4");
343 BenchMarkByName<SymmetricCipher>(
"SEAL-3.0-LE");
344 BenchMarkByName<SymmetricCipher>(
"WAKE-OFB-LE");
346 cout <<
"\n<TBODY style=\"background: yellow\">";
347 BenchMarkByName<SymmetricCipher>(
"AES/CTR", 16);
348 BenchMarkByName<SymmetricCipher>(
"AES/CTR", 24);
349 BenchMarkByName<SymmetricCipher>(
"AES/CTR", 32);
350 BenchMarkByName<SymmetricCipher>(
"AES/CBC", 16);
351 BenchMarkByName<SymmetricCipher>(
"AES/CBC", 24);
352 BenchMarkByName<SymmetricCipher>(
"AES/CBC", 32);
353 BenchMarkByName<SymmetricCipher>(
"AES/OFB", 16);
354 BenchMarkByName<SymmetricCipher>(
"AES/CFB", 16);
355 BenchMarkByName<SymmetricCipher>(
"AES/ECB", 16);
356 BenchMarkByName<SymmetricCipher>(
"Camellia/CTR", 16);
357 BenchMarkByName<SymmetricCipher>(
"Camellia/CTR", 32);
358 BenchMarkByName<SymmetricCipher>(
"Twofish/CTR");
359 BenchMarkByName<SymmetricCipher>(
"Serpent/CTR");
360 BenchMarkByName<SymmetricCipher>(
"CAST-256/CTR");
361 BenchMarkByName<SymmetricCipher>(
"RC6/CTR");
362 BenchMarkByName<SymmetricCipher>(
"MARS/CTR");
363 BenchMarkByName<SymmetricCipher>(
"SHACAL-2/CTR", 16);
364 BenchMarkByName<SymmetricCipher>(
"SHACAL-2/CTR", 64);
365 BenchMarkByName<SymmetricCipher>(
"DES/CTR");
366 BenchMarkByName<SymmetricCipher>(
"DES-XEX3/CTR");
367 BenchMarkByName<SymmetricCipher>(
"DES-EDE3/CTR");
368 BenchMarkByName<SymmetricCipher>(
"IDEA/CTR");
369 BenchMarkByName<SymmetricCipher>(
"RC5/CTR", 0,
"RC5 (r=16)");
370 BenchMarkByName<SymmetricCipher>(
"Blowfish/CTR");
371 BenchMarkByName<SymmetricCipher>(
"TEA/CTR");
372 BenchMarkByName<SymmetricCipher>(
"XTEA/CTR");
373 BenchMarkByName<SymmetricCipher>(
"CAST-128/CTR");
374 BenchMarkByName<SymmetricCipher>(
"SKIPJACK/CTR");
375 BenchMarkByName<SymmetricCipher>(
"SEED/CTR", 0,
"SEED/CTR (1/2 K table)");
376 cout <<
"</TABLE>" << endl;
379 cout <<
"Throughput Geometric Average: " << setiosflags(ios::fixed) << exp(logtotal/(logcount ? logcount : 1)) << endl;
382 #if (CRYPTOPP_MSC_VERSION >= 1400) 387 const time_t endTime = time(NULL);
388 err = localtime_s(&localTime, &endTime);
390 err = asctime_s(timeBuf,
sizeof(timeBuf), &localTime);
393 cout <<
"\nTest ended at " << timeBuf;
395 const time_t endTime = time(NULL);
396 cout <<
"\nTest ended at " << asctime(localtime(&endTime));
Used to pass byte array input as part of a NameValuePairs object.
virtual void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms=g_nullNameValuePairs)
Sets or reset the key of this object.
Interface for one direction (encryption or decryption) of a stream cipher or block cipher mode with a...
Class file for modes of operation.
virtual void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
virtual bool NeedsPrespecifiedDataLengths() const
Determines if data lengths must be specified prior to inputting data.
Abstract base classes that provide a uniform interface to this library.
void BenchMarkByNameKeyLess(const char *factoryName, const char *displayName=NULL, const NameValuePairs ¶ms=g_nullNameValuePairs)
RandomNumberGenerator & GlobalRNG()
Classes for automatic resource management.
std::hash for asio::adress
Combines two sets of NameValuePairs.
void BenchMarkKeying(SimpleKeyingInterface &c, size_t keyLength, const NameValuePairs ¶ms)
Pointer that overloads operator ->
void BenchmarkAll2(double t, double hertz)
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
void BenchMarkByName2(const char *factoryName, size_t keyLength=0, const char *displayName=NULL, const NameValuePairs ¶ms=g_nullNameValuePairs)
Classes for HexEncoder and HexDecoder.
Class file for the AES cipher (Rijndael)
void OutputResultBytes(const char *name, double length, double timeTaken)
Interface for algorithms that take byte strings as keys.
void OutputResultKeying(double iterations, double timeTaken)
Classes and functions for registering and locating library objects.
#define CRYPTOPP_ASSERT(exp)
const NameValuePairs & g_nullNameValuePairs
An empty set of name-value pairs.
void BenchMarkByName(const char *factoryName, size_t keyLength=0, const char *displayName=NULL, const NameValuePairs ¶ms=g_nullNameValuePairs)
Functions for CPU features and intrinsics.
Implementation of BufferedTransformation's attachment interface.
virtual lword MaxMessageLength() const =0
Provides the maximum length of encrypted data.
#define USING_NAMESPACE(x)
Classes for Blum Blum Shub generator.
#define CRYPTOPP_UNUSED(x)
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
T1 RoundUpToMultipleOf(const T1 &n, const T2 &m)
Rounds a value up to a multiple of a second value.
Classes providing file-based library services.
void SpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength=0)
Prespecifies the data lengths.
void BenchmarkAll(double t, double hertz)
void OutputResultOperations(const char *name, const char *operation, bool pc, unsigned long iterations, double timeTaken)
const double CLOCK_TICKS_PER_SECOND
void BenchMark(const char *name, StreamTransformation &cipher, double timeTotal)
Interface for retrieving values given their names.