~zooko/cryptopp/trunk

« back to all changes in this revision

Viewing changes to bench.cpp

  • Committer: noloader
  • Date: 2015-06-29 13:37:03 UTC
  • Revision ID: svn-v4:57ff6487-cd31-0410-9ec3-f628ee90f5f0:trunk/c5:558
Cleared warning on operator precedence

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
#define _CRT_SECURE_NO_DEPRECATE
4
4
 
5
5
#include "bench.h"
6
 
#include "crc.h"
7
 
#include "adler32.h"
8
 
#include "md2.h"
9
 
#include "md5.h"
10
 
#include "md5mac.h"
11
 
#include "sha.h"
12
 
#include "haval.h"
13
 
#include "tiger.h"
14
 
#include "ripemd.h"
15
 
#include "panama.h"
16
 
#include "whrlpool.h"
17
 
#include "idea.h"
18
 
#include "des.h"
19
 
#include "rc2.h"
20
 
#include "arc4.h"
21
 
#include "rc5.h"
22
 
#include "blowfish.h"
23
 
#include "wake.h"
24
 
#include "3way.h"
25
 
#include "safer.h"
26
 
#include "gost.h"
27
 
#include "shark.h"
28
 
#include "cast.h"
29
 
#include "square.h"
30
 
#include "skipjack.h"
31
 
#include "seal.h"
32
 
#include "rc6.h"
33
 
#include "mars.h"
34
 
#include "rijndael.h"
35
 
#include "twofish.h"
36
 
#include "serpent.h"
37
 
#include "shacal2.h"
38
 
#include "camellia.h"
39
 
#include "hmac.h"
40
 
#include "xormac.h"
41
 
#include "cbcmac.h"
42
 
#include "dmac.h"
43
 
#include "ttmac.h"
 
6
#include "validate.h"
 
7
#include "aes.h"
44
8
#include "blumshub.h"
45
 
#include "rng.h"
46
9
#include "files.h"
47
10
#include "hex.h"
48
11
#include "modes.h"
49
 
#include "mdc.h"
50
 
#include "lubyrack.h"
51
 
#include "tea.h"
52
 
#include "salsa.h"
 
12
#include "factory.h"
 
13
#include "cpu.h"
53
14
 
54
15
#include <time.h>
55
16
#include <math.h>
67
28
const double CLOCK_TICKS_PER_SECOND = 1000000.0;
68
29
#endif
69
30
 
70
 
double logtotal = 0;
 
31
double logtotal = 0, g_allocatedTime, g_hertz;
71
32
unsigned int logcount = 0;
72
33
 
73
34
static const byte *const key=(byte *)"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
75
36
void OutputResultBytes(const char *name, double length, double timeTaken)
76
37
{
77
38
        double mbs = length / timeTaken / (1024*1024);
78
 
        cout << "<TR><TH>" << name;
79
 
        cout << "<TD>" << setprecision(3) << length / (1024*1024);
 
39
        cout << "\n<TR><TH>" << name;
 
40
//      cout << "<TD>" << setprecision(3) << length / (1024*1024);
80
41
        cout << setiosflags(ios::fixed);
81
 
        cout << "<TD>" << setprecision(3) << timeTaken;
82
 
        cout << "<TD>" << setprecision(3) << mbs << endl;
 
42
//      cout << "<TD>" << setprecision(3) << timeTaken;
 
43
        cout << "<TD>" << setprecision(0) << setiosflags(ios::fixed) << mbs;
 
44
        if (g_hertz)
 
45
                cout << "<TD>" << setprecision(1) << setiosflags(ios::fixed) << timeTaken * g_hertz / length;
83
46
        cout << resetiosflags(ios::fixed);
84
47
        logtotal += log(mbs);
85
48
        logcount++;
86
49
}
87
50
 
 
51
void OutputResultKeying(double iterations, double timeTaken)
 
52
{
 
53
        cout << "<TD>" << setprecision(3) << setiosflags(ios::fixed) << (1000*1000*timeTaken/iterations);
 
54
        if (g_hertz)
 
55
                cout << "<TD>" << setprecision(0) << setiosflags(ios::fixed) << timeTaken * g_hertz / iterations;
 
56
}
 
57
 
88
58
void OutputResultOperations(const char *name, const char *operation, bool pc, unsigned long iterations, double timeTaken)
89
59
{
90
 
        cout << "<TR><TH>" << name << " " << operation << (pc ? " with precomputation" : "");
91
 
        cout << "<TD>" << iterations;
92
 
        cout << setiosflags(ios::fixed);
93
 
        cout << "<TD>" << setprecision(3) << timeTaken;
94
 
        cout << "<TD>" << setprecision(2) << (1000*timeTaken/iterations) << endl;
 
60
        cout << "\n<TR><TH>" << name << " " << operation << (pc ? " with precomputation" : "");
 
61
//      cout << "<TD>" << iterations;
 
62
//      cout << setiosflags(ios::fixed);
 
63
//      cout << "<TD>" << setprecision(3) << timeTaken;
 
64
        cout << "<TD>" << setprecision(2) << setiosflags(ios::fixed) << (1000*timeTaken/iterations);
 
65
        if (g_hertz)
 
66
                cout << "<TD>" << setprecision(2) << setiosflags(ios::fixed) << timeTaken * g_hertz / iterations / 1000000;
95
67
        cout << resetiosflags(ios::fixed);
96
68
 
97
69
        logtotal += log(iterations/timeTaken);
98
70
        logcount++;
99
71
}
100
72
 
 
73
/*
101
74
void BenchMark(const char *name, BlockTransformation &cipher, double timeTotal)
102
75
{
103
 
        const int BUF_SIZE = RoundDownToMultipleOf(1024U, cipher.OptimalNumberOfParallelBlocks() * cipher.BlockSize());
104
 
        SecByteBlock buf(BUF_SIZE);
 
76
        const int BUF_SIZE = RoundUpToMultipleOf(2048U, cipher.OptimalNumberOfParallelBlocks() * cipher.BlockSize());
 
77
        AlignedSecByteBlock buf(BUF_SIZE);
105
78
        const int nBlocks = BUF_SIZE / cipher.BlockSize();
106
79
        clock_t start = clock();
107
80
 
118
91
 
119
92
        OutputResultBytes(name, double(blocks) * BUF_SIZE, timeTaken);
120
93
}
 
94
*/
121
95
 
122
96
void BenchMark(const char *name, StreamTransformation &cipher, double timeTotal)
123
97
{
124
 
        const int BUF_SIZE=1024;
125
 
        SecByteBlock buf(BUF_SIZE);
 
98
        const int BUF_SIZE=RoundUpToMultipleOf(2048U, cipher.OptimalBlockSize());
 
99
        AlignedSecByteBlock buf(BUF_SIZE);
 
100
        GlobalRNG().GenerateBlock(buf, BUF_SIZE);
126
101
        clock_t start = clock();
127
102
 
128
103
        unsigned long i=0, blocks=1;
139
114
        OutputResultBytes(name, double(blocks) * BUF_SIZE, timeTaken);
140
115
}
141
116
 
 
117
void BenchMark(const char *name, AuthenticatedSymmetricCipher &cipher, double timeTotal)
 
118
{
 
119
        if (cipher.NeedsPrespecifiedDataLengths())
 
120
                cipher.SpecifyDataLengths(0, cipher.MaxMessageLength(), 0);
 
121
 
 
122
        BenchMark(name, static_cast<StreamTransformation &>(cipher), timeTotal);
 
123
}
 
124
 
142
125
void BenchMark(const char *name, HashTransformation &ht, double timeTotal)
143
126
{
144
 
        const int BUF_SIZE=1024;
145
 
        SecByteBlock buf(BUF_SIZE);
146
 
        LC_RNG rng((word32)time(NULL));
147
 
        rng.GenerateBlock(buf, BUF_SIZE);
 
127
        const int BUF_SIZE=2048U;
 
128
        AlignedSecByteBlock buf(BUF_SIZE);
 
129
        GlobalRNG().GenerateBlock(buf, BUF_SIZE);
148
130
        clock_t start = clock();
149
131
 
150
132
        unsigned long i=0, blocks=1;
163
145
 
164
146
void BenchMark(const char *name, BufferedTransformation &bt, double timeTotal)
165
147
{
166
 
        const int BUF_SIZE=1024;
167
 
        SecByteBlock buf(BUF_SIZE);
168
 
        LC_RNG rng((word32)time(NULL));
169
 
        rng.GenerateBlock(buf, BUF_SIZE);
 
148
        const int BUF_SIZE=2048U;
 
149
        AlignedSecByteBlock buf(BUF_SIZE);
 
150
        GlobalRNG().GenerateBlock(buf, BUF_SIZE);
170
151
        clock_t start = clock();
171
152
 
172
153
        unsigned long i=0, blocks=1;
183
164
        OutputResultBytes(name, double(blocks) * BUF_SIZE, timeTaken);
184
165
}
185
166
 
186
 
//VC60 workaround: compiler bug triggered without the extra dummy parameters
187
 
template <class T>
188
 
void BenchMarkKeyed(const char *name, double timeTotal, const NameValuePairs &params = g_nullNameValuePairs, T *x=NULL)
189
 
{
190
 
        T c;
191
 
        c.SetKey(key, c.DefaultKeyLength(), CombinedNameValuePairs(params, MakeParameters(Name::IV(), key, false)));
192
 
        BenchMark(name, c, timeTotal);
193
 
}
194
 
 
195
 
//VC60 workaround: compiler bug triggered without the extra dummy parameters
196
 
template <class T>
197
 
void BenchMarkKeyedVariable(const char *name, double timeTotal, unsigned int keyLength, const NameValuePairs &params = g_nullNameValuePairs, T *x=NULL)
198
 
{
199
 
        T c;
200
 
        c.SetKey(key, keyLength, CombinedNameValuePairs(params, MakeParameters(Name::IV(), key, false)));
201
 
        BenchMark(name, c, timeTotal);
202
 
}
203
 
 
204
 
//VC60 workaround: compiler bug triggered without the extra dummy parameters
205
 
template <class T>
206
 
void BenchMarkKeyless(const char *name, double timeTotal, T *x=NULL)
207
 
{
208
 
        T c;
209
 
        BenchMark(name, c, timeTotal);
210
 
}
211
 
 
212
 
void BenchmarkAll(double t)
 
167
void BenchMarkKeying(SimpleKeyingInterface &c, size_t keyLength, const NameValuePairs &params)
 
168
{
 
169
        unsigned long iterations = 0;
 
170
        clock_t start = clock();
 
171
        double timeTaken;
 
172
        do
 
173
        {
 
174
                for (unsigned int i=0; i<1024; i++)
 
175
                        c.SetKey(key, keyLength, params);
 
176
                timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND;
 
177
                iterations += 1024;
 
178
        }
 
179
        while (timeTaken < g_allocatedTime);
 
180
 
 
181
        OutputResultKeying(iterations, timeTaken);
 
182
}
 
183
 
 
184
//VC60 workaround: compiler bug triggered without the extra dummy parameters
 
185
// on VC60 also needs to be named differently from BenchMarkByName
 
186
template <class T_FactoryOutput, class T_Interface>
 
187
void BenchMarkByName2(const char *factoryName, size_t keyLength = 0, const char *displayName=NULL, const NameValuePairs &params = g_nullNameValuePairs, T_FactoryOutput *x=NULL, T_Interface *y=NULL)
 
188
{
 
189
        std::string name = factoryName;
 
190
        if (displayName)
 
191
                name = displayName;
 
192
        else if (keyLength)
 
193
                name += " (" + IntToString(keyLength * 8) + "-bit key)";
 
194
 
 
195
        std::auto_ptr<T_FactoryOutput> obj(ObjectFactoryRegistry<T_FactoryOutput>::Registry().CreateObject(factoryName));
 
196
        if (!keyLength)
 
197
                keyLength = obj->DefaultKeyLength();
 
198
        obj->SetKey(key, keyLength, CombinedNameValuePairs(params, MakeParameters(Name::IV(), ConstByteArrayParameter(key, obj->IVSize()), false)));
 
199
        BenchMark(name.c_str(), *static_cast<T_Interface *>(obj.get()), g_allocatedTime);
 
200
        BenchMarkKeying(*obj, keyLength, CombinedNameValuePairs(params, MakeParameters(Name::IV(), ConstByteArrayParameter(key, obj->IVSize()), false)));
 
201
}
 
202
 
 
203
//VC60 workaround: compiler bug triggered without the extra dummy parameters
 
204
template <class T_FactoryOutput>
 
205
void BenchMarkByName(const char *factoryName, size_t keyLength = 0, const char *displayName=NULL, const NameValuePairs &params = g_nullNameValuePairs, T_FactoryOutput *x=NULL)
 
206
{
 
207
        BenchMarkByName2<T_FactoryOutput, T_FactoryOutput>(factoryName, keyLength, displayName, params, x, x);
 
208
}
 
209
 
 
210
template <class T>
 
211
void BenchMarkByNameKeyLess(const char *factoryName, const char *displayName=NULL, const NameValuePairs &params = g_nullNameValuePairs, T *x=NULL)
 
212
{
 
213
        std::string name = factoryName;
 
214
        if (displayName)
 
215
                name = displayName;
 
216
 
 
217
        std::auto_ptr<T> obj(ObjectFactoryRegistry<T>::Registry().CreateObject(factoryName));
 
218
        BenchMark(name.c_str(), *obj, g_allocatedTime);
 
219
}
 
220
 
 
221
void BenchmarkAll(double t, double hertz)
213
222
{
214
223
#if 1
215
224
        logtotal = 0;
216
225
        logcount = 0;
217
 
 
218
 
        cout << "<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right><COL align=right>" << endl;
219
 
        cout << "<THEAD><TR><TH>Algorithm<TH>Megabytes(2^20 bytes) Processed<TH>Time Taken<TH>MB/Second\n<TBODY>" << endl;
220
 
 
221
 
        BenchMarkKeyless<CRC32>("CRC-32", t);
222
 
        BenchMarkKeyless<Adler32>("Adler-32", t);
223
 
        BenchMarkKeyless<MD2>("MD2", t);
224
 
        BenchMarkKeyless<MD5>("MD5", t);
225
 
        BenchMarkKeyless<SHA>("SHA-1", t);
226
 
        BenchMarkKeyless<SHA256>("SHA-256", t);
227
 
#ifdef WORD64_AVAILABLE
228
 
        BenchMarkKeyless<SHA512>("SHA-512", t);
229
 
#endif
230
 
        BenchMarkKeyless<HAVAL3>("HAVAL (pass=3)", t);
231
 
        BenchMarkKeyless<HAVAL4>("HAVAL (pass=4)", t);
232
 
        BenchMarkKeyless<HAVAL5>("HAVAL (pass=5)", t);
233
 
#ifdef WORD64_AVAILABLE
234
 
        BenchMarkKeyless<Tiger>("Tiger", t);
235
 
#endif
236
 
        BenchMarkKeyless<RIPEMD160>("RIPE-MD160", t);
237
 
        BenchMarkKeyless<RIPEMD320>("RIPE-MD320", t);
238
 
        BenchMarkKeyless<RIPEMD128>("RIPE-MD128", t);
239
 
        BenchMarkKeyless<RIPEMD256>("RIPE-MD256", t);
240
 
        BenchMarkKeyless<PanamaHash<LittleEndian> >("Panama Hash (little endian)", t);
241
 
        BenchMarkKeyless<PanamaHash<BigEndian> >("Panama Hash (big endian)", t);
242
 
#ifdef WORD64_AVAILABLE
243
 
        BenchMarkKeyless<Whirlpool>("Whirlpool", t);
244
 
#endif
245
 
        BenchMarkKeyed<MDC<MD5>::Encryption>("MDC/MD5", t);
246
 
        BenchMarkKeyed<LR<MD5>::Encryption>("Luby-Rackoff/MD5", t);
247
 
        BenchMarkKeyed<DES::Encryption>("DES", t);
248
 
        BenchMarkKeyed<DES_XEX3::Encryption>("DES-XEX3", t);
249
 
        BenchMarkKeyed<DES_EDE3::Encryption>("DES-EDE3", t);
250
 
        BenchMarkKeyed<IDEA::Encryption>("IDEA", t);
251
 
        BenchMarkKeyed<RC2::Encryption>("RC2", t);
252
 
        BenchMarkKeyed<RC5::Encryption>("RC5 (r=16)", t);
253
 
        BenchMarkKeyed<Blowfish::Encryption>("Blowfish", t);
254
 
        BenchMarkKeyed<ThreeWayDecryption>("3-WAY", t);
255
 
        BenchMarkKeyed<TEA::Encryption>("TEA", t);
256
 
        BenchMarkKeyedVariable<SAFER_SK::Encryption>("SAFER (r=8)", t, 8);
257
 
        BenchMarkKeyed<GOST::Encryption>("GOST", t);
258
 
#ifdef WORD64_AVAILABLE
259
 
        BenchMarkKeyed<SHARK::Encryption>("SHARK (r=6)", t);
260
 
#endif
261
 
        BenchMarkKeyed<CAST128::Encryption>("CAST-128", t);
262
 
        BenchMarkKeyed<CAST256::Encryption>("CAST-256", t);
263
 
        BenchMarkKeyed<Square::Encryption>("Square", t);
264
 
        BenchMarkKeyed<SKIPJACK::Encryption>("SKIPJACK", t);
265
 
        BenchMarkKeyed<RC6::Encryption>("RC6", t);
266
 
        BenchMarkKeyed<MARS::Encryption>("MARS", t);
267
 
        BenchMarkKeyedVariable<Rijndael::Encryption>("Rijndael (128-bit key)", t, 16);
268
 
        BenchMarkKeyedVariable<Rijndael::Encryption>("Rijndael (192-bit key)", t, 24);
269
 
        BenchMarkKeyedVariable<Rijndael::Encryption>("Rijndael (256-bit key)", t, 32);
270
 
        BenchMarkKeyedVariable<CTR_Mode<Rijndael>::Encryption>("Rijndael (128) CTR", t, 16);
271
 
        BenchMarkKeyedVariable<OFB_Mode<Rijndael>::Encryption>("Rijndael (128) OFB", t, 16);
272
 
        BenchMarkKeyedVariable<CFB_Mode<Rijndael>::Encryption>("Rijndael (128) CFB", t, 16);
273
 
        BenchMarkKeyedVariable<CBC_Mode<Rijndael>::Encryption>("Rijndael (128) CBC", t, 16);
274
 
        BenchMarkKeyed<Twofish::Encryption>("Twofish", t);
275
 
        BenchMarkKeyed<Serpent::Encryption>("Serpent", t);
276
 
        BenchMarkKeyed<ARC4>("ARC4", t);
277
 
        BenchMarkKeyed<SEAL<BigEndian>::Encryption>("SEAL-3.0-BE", t);
278
 
        BenchMarkKeyed<SEAL<LittleEndian>::Encryption>("SEAL-3.0-LE", t);
279
 
        BenchMarkKeyed<WAKE_CFB<BigEndian>::Encryption>("WAKE-CFB-BE", t);
280
 
        BenchMarkKeyed<WAKE_CFB<LittleEndian>::Encryption>("WAKE-CFB-LE", t);
281
 
        BenchMarkKeyed<WAKE_OFB<BigEndian>::Encryption>("WAKE-OFB-BE", t);
282
 
        BenchMarkKeyed<WAKE_OFB<LittleEndian>::Encryption>("WAKE-OFB-LE", t);
283
 
        BenchMarkKeyed<PanamaCipher<LittleEndian>::Encryption>("Panama Cipher (little endian)", t);
284
 
        BenchMarkKeyed<PanamaCipher<BigEndian>::Encryption>("Panama Cipher (big endian)", t);
285
 
        BenchMarkKeyedVariable<SHACAL2::Encryption>("SHACAL-2 (128-bit key)", t, 16);
286
 
        BenchMarkKeyedVariable<SHACAL2::Encryption>("SHACAL-2 (512-bit key)", t, 64);
287
 
#ifdef WORD64_AVAILABLE
288
 
        BenchMarkKeyedVariable<Camellia::Encryption>("Camellia (128-bit key)", t, 16);
289
 
        BenchMarkKeyedVariable<Camellia::Encryption>("Camellia (256-bit key)", t, 32);
290
 
#endif
291
 
        BenchMarkKeyed<Salsa20::Encryption>("Salsa20", t);
292
 
        BenchMarkKeyed<Salsa20::Encryption>("Salsa20/12", t, MakeParameters(Name::Rounds(), 12));
293
 
        BenchMarkKeyed<Salsa20::Encryption>("Salsa20/8", t, MakeParameters(Name::Rounds(), 8));
294
 
 
295
 
        BenchMarkKeyed<MD5MAC>("MD5-MAC", t);
296
 
        BenchMarkKeyed<XMACC<MD5> >("XMACC/MD5", t);
297
 
        BenchMarkKeyed<HMAC<MD5> >("HMAC/MD5", t);
298
 
        BenchMarkKeyed<TTMAC>("Two-Track-MAC", t);
299
 
        BenchMarkKeyed<CBC_MAC<Rijndael> >("CBC-MAC/Rijndael", t);
300
 
        BenchMarkKeyed<DMAC<Rijndael> >("DMAC/Rijndael", t);
301
 
 
302
 
        {
303
 
                Integer p("CB6C,B8CE,6351,164F,5D0C,0C9E,9E31,E231,CF4E,D551,CBD0,E671,5D6A,7B06,D8DF,C4A7h");
304
 
                Integer q("FD2A,8594,A132,20CC,4E6D,DE77,3AAA,CF15,CD9E,E447,8592,FF46,CC77,87BE,9876,A2AFh");
305
 
                Integer s("63239752671357255800299643604761065219897634268887145610573595874544114193025997412441121667211431");
306
 
                BlumBlumShub c(p, q, s);
307
 
                BenchMark("BlumBlumShub 512", c, t);
308
 
        }
309
 
        {
310
 
                Integer p("FD2A,8594,A132,20CC,4E6D,DE77,3AAA,CF15,CD9E,E447,8592,FF46,CC77,87BE,9876,9E2C,"
311
 
                                  "8572,64C3,4CF4,188A,44D4,2130,1135,7982,6FF6,EDD3,26F0,5FAA,BAF4,A81E,7ADC,B80Bh");
312
 
                Integer q("C8B9,5797,B349,6BA3,FD72,F2C0,A796,8A65,EE0F,B4BA,272F,4FEE,4DB1,06D5,ECEB,7142,"
313
 
                                  "E8A8,E5A8,6BF9,A32F,BA37,BACC,8A75,8A6B,2DCE,D6EC,B515,980A,4BB1,08FB,6F2C,2383h");
314
 
                Integer s("3578,8F00,2965,71A4,4382,699F,45FD,3922,8238,241B,CEBA,0543,3443,E8D9,12FB,AC46,"
315
 
                                  "7EC4,8505,EC9E,7EE8,5A23,9B2A,B615,D0C4,9448,F23A,ADEE,E850,1A7A,CA30,0B5B,A408,"
316
 
                                  "D936,21BA,844E,BDD6,7848,3D1E,9137,CC87,DAA5,773B,D45A,C8BB,5392,1393,108B,6992,"
317
 
                                  "74E3,C5E2,C235,A321,0111,3BA4,BAB4,1A2F,17EE,C371,DE67,01C9,0F3D,907A,B252,9BDDh");
318
 
                BlumBlumShub c(p, q, s);
319
 
                BenchMark("BlumBlumShub 1024", c, t);
320
 
        }
321
 
        {
322
 
                Integer p("EB56,978A,7BA7,B5D9,1383,4611,94F5,4766,FCEF,CF41,958A,FC41,43D0,839F,C56B,B568,"
323
 
                                  "4ED3,9E5A,BABB,5ACE,8B11,CEBC,88A2,7C12,FFEE,E6E8,CF0A,E231,5BC2,DEDE,80B7,32F6,"
324
 
                                  "340E,D8A6,B7DE,C779,7EE5,0E16,9C88,FC9F,2A0E,EE6C,7D47,C5F2,6B06,EB8C,F1C8,2E67,"
325
 
                                  "5B82,8C28,4FB8,542F,2874,C355,CEEE,7A54,1B06,A8AB,8B66,6A5C,9DB2,72B8,74F3,7BC7h");
326
 
                Integer q("EB6B,3645,4591,8343,7331,7CAC,B02E,4BB9,DEF5,8EDC,1772,DB9B,9571,5FAB,1CDD,4FB1,"
327
 
                                  "7B9A,07CD,E715,D448,F552,CBBD,D387,C037,DE70,6661,F360,D0E8,D42E,292A,9321,DDCB,"
328
 
                                  "0BF9,C514,BFAC,3F2C,C06E,DF64,A9B8,50D6,AC4F,B9E4,014B,5624,2B40,A0D4,5D0B,6DD4,"
329
 
                                  "0989,D00E,0268,99AB,21DB,0BB4,DB38,84DA,594F,575F,95AC,1B70,45E4,96C8,C6AD,CE67h");
330
 
                Integer s("C75A,8A0D,E231,295F,C08A,1716,8611,D5EC,E9EF,B565,90EC,58C0,57D0,DA7D,C6E6,DB00,"
331
 
                                  "2282,1CA7,EA31,D64E,768C,0B19,8563,36DF,2226,F4EC,74A4,2844,2E8D,37E8,53DC,0172,"
332
 
                                  "5F56,8CF9,B444,CA02,78B3,17AF,7C78,D320,16AE,AC3D,B97F,7259,1B8F,9C84,6A16,B878,"
333
 
                                  "0595,70BB,9C52,18B5,9100,9C1F,E85A,4035,06F3,5F38,7462,F01D,0462,BFBC,A4CD,4A45,"
334
 
                                  "3A77,E7F8,DED1,D6EF,CEF7,0937,CD3F,3AF1,4F88,932D,6D4B,002C,3735,304C,C5D3,B88A,"
335
 
                                  "B57B,24B6,5346,9B46,5153,B7ED,B216,C181,B1C6,C52E,CD2B,E0AA,B1BB,0A93,C92E,4F79,"
336
 
                                  "4931,E303,7C8F,A408,8ACF,56CD,6EC0,76A2,5015,6BA4,4C50,C44D,53B9,E168,5F84,B381,"
337
 
                                  "2514,10B2,00E5,B4D1,4156,A2FE,0BF6,6F33,0A1B,91C6,31B8,1C90,02F1,FB1F,C494,8B65h");
338
 
                BlumBlumShub c(p, q, s);
339
 
                BenchMark("BlumBlumShub 2048", c, t);
340
 
        }
 
226
        g_allocatedTime = t;
 
227
        g_hertz = hertz;
 
228
 
 
229
        const char *cpb, *cpk;
 
230
        if (g_hertz)
 
231
        {
 
232
                cpb = "<TH>Cycles Per Byte";
 
233
                cpk = "<TH>Cycles to<br>Setup Key and IV";
 
234
                cout << "CPU frequency of the test platform is " << g_hertz << " Hz.\n";
 
235
        }
 
236
        else
 
237
        {
 
238
                cpb = cpk = "";
 
239
                cout << "CPU frequency of the test platform was not provided.\n";
 
240
        }
 
241
 
 
242
        cout << "<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right><COL align=right><COL align=right>" << endl;
 
243
        cout << "<THEAD><TR><TH>Algorithm<TH>MiB/Second" << cpb << "<TH>Microseconds to<br>Setup Key and IV" << cpk << endl;
 
244
 
 
245
        cout << "\n<TBODY style=\"background: yellow\">";
 
246
#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE
 
247
        if (HasCLMUL())
 
248
                BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>("AES/GCM", 0, "AES/GCM");
 
249
        else
 
250
#endif
 
251
        {
 
252
                BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>("AES/GCM", 0, "AES/GCM (2K tables)", MakeParameters(Name::TableSize(), 2048));
 
253
                BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>("AES/GCM", 0, "AES/GCM (64K tables)", MakeParameters(Name::TableSize(), 64*1024));
 
254
        }
 
255
        BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>("AES/CCM");
 
256
        BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>("AES/EAX");
 
257
 
 
258
        cout << "\n<TBODY style=\"background: white\">";
 
259
#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE
 
260
        if (HasCLMUL())
 
261
                BenchMarkByName2<AuthenticatedSymmetricCipher, MessageAuthenticationCode>("AES/GCM", 0, "GMAC(AES)");
 
262
        else
 
263
#endif
 
264
        {
 
265
                BenchMarkByName2<AuthenticatedSymmetricCipher, MessageAuthenticationCode>("AES/GCM", 0, "GMAC(AES) (2K tables)", MakeParameters(Name::TableSize(), 2048));
 
266
                BenchMarkByName2<AuthenticatedSymmetricCipher, MessageAuthenticationCode>("AES/GCM", 0, "GMAC(AES) (64K tables)", MakeParameters(Name::TableSize(), 64*1024));
 
267
        }
 
268
        BenchMarkByName<MessageAuthenticationCode>("VMAC(AES)-64");
 
269
        BenchMarkByName<MessageAuthenticationCode>("VMAC(AES)-128");
 
270
        BenchMarkByName<MessageAuthenticationCode>("HMAC(SHA-1)");
 
271
        BenchMarkByName<MessageAuthenticationCode>("Two-Track-MAC");
 
272
        BenchMarkByName<MessageAuthenticationCode>("CMAC(AES)");
 
273
        BenchMarkByName<MessageAuthenticationCode>("DMAC(AES)");
 
274
 
 
275
        cout << "\n<TBODY style=\"background: yellow\">";
 
276
        BenchMarkByNameKeyLess<HashTransformation>("CRC32");
 
277
        BenchMarkByNameKeyLess<HashTransformation>("Adler32");
 
278
        BenchMarkByNameKeyLess<HashTransformation>("MD5");
 
279
        BenchMarkByNameKeyLess<HashTransformation>("SHA-1");
 
280
        BenchMarkByNameKeyLess<HashTransformation>("SHA-256");
 
281
        BenchMarkByNameKeyLess<HashTransformation>("SHA-512");
 
282
        BenchMarkByNameKeyLess<HashTransformation>("SHA-3-224");
 
283
        BenchMarkByNameKeyLess<HashTransformation>("SHA-3-256");
 
284
        BenchMarkByNameKeyLess<HashTransformation>("SHA-3-384");
 
285
        BenchMarkByNameKeyLess<HashTransformation>("SHA-3-512");
 
286
        BenchMarkByNameKeyLess<HashTransformation>("Tiger");
 
287
        BenchMarkByNameKeyLess<HashTransformation>("Whirlpool");
 
288
        BenchMarkByNameKeyLess<HashTransformation>("RIPEMD-160");
 
289
        BenchMarkByNameKeyLess<HashTransformation>("RIPEMD-320");
 
290
        BenchMarkByNameKeyLess<HashTransformation>("RIPEMD-128");
 
291
        BenchMarkByNameKeyLess<HashTransformation>("RIPEMD-256");
 
292
 
 
293
        cout << "\n<TBODY style=\"background: white\">";
 
294
        BenchMarkByName<SymmetricCipher>("Panama-LE");
 
295
        BenchMarkByName<SymmetricCipher>("Panama-BE");
 
296
        BenchMarkByName<SymmetricCipher>("Salsa20");
 
297
        BenchMarkByName<SymmetricCipher>("Salsa20", 0, "Salsa20/12", MakeParameters(Name::Rounds(), 12));
 
298
        BenchMarkByName<SymmetricCipher>("Salsa20", 0, "Salsa20/8", MakeParameters(Name::Rounds(), 8));
 
299
        BenchMarkByName<SymmetricCipher>("Sosemanuk");
 
300
        BenchMarkByName<SymmetricCipher>("MARC4");
 
301
        BenchMarkByName<SymmetricCipher>("SEAL-3.0-LE");
 
302
        BenchMarkByName<SymmetricCipher>("WAKE-OFB-LE");
 
303
 
 
304
        cout << "\n<TBODY style=\"background: yellow\">";
 
305
        BenchMarkByName<SymmetricCipher>("AES/CTR", 16);
 
306
        BenchMarkByName<SymmetricCipher>("AES/CTR", 24);
 
307
        BenchMarkByName<SymmetricCipher>("AES/CTR", 32);
 
308
        BenchMarkByName<SymmetricCipher>("AES/CBC", 16);
 
309
        BenchMarkByName<SymmetricCipher>("AES/CBC", 24);
 
310
        BenchMarkByName<SymmetricCipher>("AES/CBC", 32);
 
311
        BenchMarkByName<SymmetricCipher>("AES/OFB", 16);
 
312
        BenchMarkByName<SymmetricCipher>("AES/CFB", 16);
 
313
        BenchMarkByName<SymmetricCipher>("AES/ECB", 16);
 
314
        BenchMarkByName<SymmetricCipher>("Camellia/CTR", 16);
 
315
        BenchMarkByName<SymmetricCipher>("Camellia/CTR", 32);
 
316
        BenchMarkByName<SymmetricCipher>("Twofish/CTR");
 
317
        BenchMarkByName<SymmetricCipher>("Serpent/CTR");
 
318
        BenchMarkByName<SymmetricCipher>("CAST-256/CTR");
 
319
        BenchMarkByName<SymmetricCipher>("RC6/CTR");
 
320
        BenchMarkByName<SymmetricCipher>("MARS/CTR");
 
321
        BenchMarkByName<SymmetricCipher>("SHACAL-2/CTR", 16);
 
322
        BenchMarkByName<SymmetricCipher>("SHACAL-2/CTR", 64);
 
323
        BenchMarkByName<SymmetricCipher>("DES/CTR");
 
324
        BenchMarkByName<SymmetricCipher>("DES-XEX3/CTR");
 
325
        BenchMarkByName<SymmetricCipher>("DES-EDE3/CTR");
 
326
        BenchMarkByName<SymmetricCipher>("IDEA/CTR");
 
327
        BenchMarkByName<SymmetricCipher>("RC5/CTR", 0, "RC5 (r=16)");
 
328
        BenchMarkByName<SymmetricCipher>("Blowfish/CTR");
 
329
        BenchMarkByName<SymmetricCipher>("TEA/CTR");
 
330
        BenchMarkByName<SymmetricCipher>("XTEA/CTR");
 
331
        BenchMarkByName<SymmetricCipher>("CAST-128/CTR");
 
332
        BenchMarkByName<SymmetricCipher>("SKIPJACK/CTR");
 
333
        BenchMarkByName<SymmetricCipher>("SEED/CTR", 0, "SEED/CTR (1/2 K table)");
341
334
        cout << "</TABLE>" << endl;
342
335
 
343
 
        BenchmarkAll2(t);
 
336
        BenchmarkAll2(t, hertz);
344
337
 
345
338
        cout << "Throughput Geometric Average: " << setiosflags(ios::fixed) << exp(logtotal/logcount) << endl;
346
339