38 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
39 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
45 void OutputResultOperations(
const char *name,
const char *operation,
bool pc,
unsigned long iterations,
double timeTaken);
47 void BenchMarkEncryption(
const char *name,
PK_Encryptor &key,
double timeTotal,
bool pc=
false)
49 unsigned int len = 16;
53 const clock_t start = clock();
56 for (timeTaken=(
double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
57 key.
Encrypt(GlobalRNG(), plaintext, len, ciphertext);
59 OutputResultOperations(name,
"Encryption", pc, i, timeTaken);
64 BenchMarkEncryption(name, key, timeTotal,
true);
70 unsigned int len = 16;
74 pub.
Encrypt(GlobalRNG(), plaintext, len, ciphertext);
76 const clock_t start = clock();
79 for (timeTaken=(
double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
80 priv.
Decrypt(GlobalRNG(), ciphertext, ciphertext.size(), plaintext);
82 OutputResultOperations(name,
"Decryption",
false, i, timeTaken);
85 void BenchMarkSigning(
const char *name,
PK_Signer &key,
double timeTotal,
bool pc=
false)
87 unsigned int len = 16;
91 const clock_t start = clock();
94 for (timeTaken=(
double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
95 key.
SignMessage(GlobalRNG(), message, len, signature);
97 OutputResultOperations(name,
"Signature", pc, i, timeTaken);
102 BenchMarkSigning(name, key, timeTotal,
true);
106 void BenchMarkVerification(
const char *name,
const PK_Signer &priv,
PK_Verifier &pub,
double timeTotal,
bool pc=
false)
108 unsigned int len = 16;
111 priv.
SignMessage(GlobalRNG(), message, len, signature);
113 const clock_t start = clock();
116 for (timeTaken=(
double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
119 bool unused = pub.
VerifyMessage(message, len, signature, signature.size());
120 CRYPTOPP_UNUSED(unused);
123 OutputResultOperations(name,
"Verification", pc, i, timeTaken);
128 BenchMarkVerification(name, priv, pub, timeTotal,
true);
134 SecByteBlock priv(d.PrivateKeyLength()), pub(d.PublicKeyLength());
136 const clock_t start = clock();
139 for (timeTaken=(
double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
140 d.GenerateKeyPair(GlobalRNG(), priv, pub);
142 OutputResultOperations(name,
"Key-Pair Generation", pc, i, timeTaken);
144 if (!pc && d.GetMaterial().SupportsPrecomputation())
146 d.AccessMaterial().Precompute(16);
147 BenchMarkKeyGen(name, d, timeTotal,
true);
153 SecByteBlock priv(d.EphemeralPrivateKeyLength()), pub(d.EphemeralPublicKeyLength());
155 const clock_t start = clock();
158 for (timeTaken=(
double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
159 d.GenerateEphemeralKeyPair(GlobalRNG(), priv, pub);
161 OutputResultOperations(name,
"Key-Pair Generation", pc, i, timeTaken);
163 if (!pc && d.GetMaterial().SupportsPrecomputation())
165 d.AccessMaterial().Precompute(16);
166 BenchMarkKeyGen(name, d, timeTotal,
true);
172 SecByteBlock priv1(d.PrivateKeyLength()), priv2(d.PrivateKeyLength());
173 SecByteBlock pub1(d.PublicKeyLength()), pub2(d.PublicKeyLength());
174 d.GenerateKeyPair(GlobalRNG(), priv1, pub1);
175 d.GenerateKeyPair(GlobalRNG(), priv2, pub2);
178 const clock_t start = clock();
181 for (timeTaken=(
double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i+=2)
183 d.Agree(val, priv1, pub2);
184 d.Agree(val, priv2, pub1);
187 OutputResultOperations(name,
"Key Agreement", pc, i, timeTaken);
192 SecByteBlock spriv1(d.StaticPrivateKeyLength()), spriv2(d.StaticPrivateKeyLength());
193 SecByteBlock epriv1(d.EphemeralPrivateKeyLength()), epriv2(d.EphemeralPrivateKeyLength());
194 SecByteBlock spub1(d.StaticPublicKeyLength()), spub2(d.StaticPublicKeyLength());
195 SecByteBlock epub1(d.EphemeralPublicKeyLength()), epub2(d.EphemeralPublicKeyLength());
196 d.GenerateStaticKeyPair(GlobalRNG(), spriv1, spub1);
197 d.GenerateStaticKeyPair(GlobalRNG(), spriv2, spub2);
198 d.GenerateEphemeralKeyPair(GlobalRNG(), epriv1, epub1);
199 d.GenerateEphemeralKeyPair(GlobalRNG(), epriv2, epub2);
202 const clock_t start = clock();
205 for (timeTaken=(
double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i+=2)
207 d.Agree(val, spriv1, epriv1, spub2, epub2);
208 d.Agree(val, spriv2, epriv2, spub1, epub1);
211 OutputResultOperations(name,
"Key Agreement", pc, i, timeTaken);
215 void BenchMarkAgreement(
const char *name, AuthenticatedKeyAgreementDomainWithRoles &d,
double timeTotal,
bool pc=
false)
217 SecByteBlock spriv1(d.StaticPrivateKeyLength()), spriv2(d.StaticPrivateKeyLength());
218 SecByteBlock epriv1(d.EphemeralPrivateKeyLength()), epriv2(d.EphemeralPrivateKeyLength());
219 SecByteBlock spub1(d.StaticPublicKeyLength()), spub2(d.StaticPublicKeyLength());
220 SecByteBlock epub1(d.EphemeralPublicKeyLength()), epub2(d.EphemeralPublicKeyLength());
221 d.GenerateStaticKeyPair(GlobalRNG(), spriv1, spub1);
222 d.GenerateStaticKeyPair(GlobalRNG(), spriv2, spub2);
223 d.GenerateEphemeralKeyPair(GlobalRNG(), epriv1, epub1);
224 d.GenerateEphemeralKeyPair(GlobalRNG(), epriv2, epub2);
227 const clock_t start = clock();
230 for (timeTaken=(
double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i+=2)
232 d.Agree(val, spriv1, epriv1, spub2, epub2);
233 d.Agree(val, spriv2, epriv2, spub1, epub1);
236 OutputResultOperations(name,
"Key Agreement", pc, i, timeTaken);
241 template <
class SCHEME>
242 void BenchMarkCrypto(
const char *filename,
const char *name,
double timeTotal, SCHEME *x=NULL)
247 typename SCHEME::Decryptor priv(f);
248 typename SCHEME::Encryptor pub(priv);
249 BenchMarkEncryption(name, pub, timeTotal);
250 BenchMarkDecryption(name, priv, pub, timeTotal);
254 template <
class SCHEME>
255 void BenchMarkSignature(
const char *filename,
const char *name,
double timeTotal, SCHEME *x=NULL)
260 typename SCHEME::Signer priv(f);
261 typename SCHEME::Verifier pub(priv);
262 BenchMarkSigning(name, priv, timeTotal);
263 BenchMarkVerification(name, priv, pub, timeTotal);
268 void BenchMarkKeyAgreement(
const char *filename,
const char *name,
double timeTotal, D *x=NULL)
274 BenchMarkKeyGen(name, d, timeTotal);
275 BenchMarkAgreement(name, d, timeTotal);
278 extern double g_hertz;
280 void BenchmarkAll2(
double t,
double hertz)
284 cout <<
"<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right>" << endl;
285 cout <<
"<THEAD><TR><TH>Operation<TH>Milliseconds/Operation" << (g_hertz ?
"<TH>Megacycles/Operation" :
"") << endl;
287 cout <<
"\n<TBODY style=\"background: yellow\">";
288 BenchMarkCrypto<RSAES<OAEP<SHA> > >(CRYPTOPP_DATA_DIR
"TestData/rsa1024.dat",
"RSA 1024", t);
289 BenchMarkCrypto<LUCES<OAEP<SHA> > >(CRYPTOPP_DATA_DIR
"TestData/luc1024.dat",
"LUC 1024", t);
290 BenchMarkCrypto<DLIES<> >(CRYPTOPP_DATA_DIR
"TestData/dlie1024.dat",
"DLIES 1024", t);
291 BenchMarkCrypto<LUC_IES<> >(CRYPTOPP_DATA_DIR
"TestData/lucc512.dat",
"LUCELG 512", t);
293 cout <<
"\n<TBODY style=\"background: white\">";
294 BenchMarkCrypto<RSAES<OAEP<SHA> > >(CRYPTOPP_DATA_DIR
"TestData/rsa2048.dat",
"RSA 2048", t);
295 BenchMarkCrypto<LUCES<OAEP<SHA> > >(CRYPTOPP_DATA_DIR
"TestData/luc2048.dat",
"LUC 2048", t);
296 BenchMarkCrypto<DLIES<> >(CRYPTOPP_DATA_DIR
"TestData/dlie2048.dat",
"DLIES 2048", t);
297 BenchMarkCrypto<LUC_IES<> >(CRYPTOPP_DATA_DIR
"TestData/lucc1024.dat",
"LUCELG 1024", t);
299 cout <<
"\n<TBODY style=\"background: yellow\">";
300 BenchMarkSignature<RSASS<PSSR, SHA> >(CRYPTOPP_DATA_DIR
"TestData/rsa1024.dat",
"RSA 1024", t);
301 BenchMarkSignature<RWSS<PSSR, SHA> >(CRYPTOPP_DATA_DIR
"TestData/rw1024.dat",
"RW 1024", t);
302 BenchMarkSignature<LUCSS<PSSR, SHA> >(CRYPTOPP_DATA_DIR
"TestData/luc1024.dat",
"LUC 1024", t);
303 BenchMarkSignature<NR<SHA> >(CRYPTOPP_DATA_DIR
"TestData/nr1024.dat",
"NR 1024", t);
304 BenchMarkSignature<DSA>(CRYPTOPP_DATA_DIR
"TestData/dsa1024.dat",
"DSA 1024", t);
305 BenchMarkSignature<LUC_HMP<SHA> >(CRYPTOPP_DATA_DIR
"TestData/lucs512.dat",
"LUC-HMP 512", t);
306 BenchMarkSignature<ESIGN<SHA> >(CRYPTOPP_DATA_DIR
"TestData/esig1023.dat",
"ESIGN 1023", t);
307 BenchMarkSignature<ESIGN<SHA> >(CRYPTOPP_DATA_DIR
"TestData/esig1536.dat",
"ESIGN 1536", t);
309 cout <<
"\n<TBODY style=\"background: white\">";
310 BenchMarkSignature<RSASS<PSSR, SHA> >(CRYPTOPP_DATA_DIR
"TestData/rsa2048.dat",
"RSA 2048", t);
311 BenchMarkSignature<RWSS<PSSR, SHA> >(CRYPTOPP_DATA_DIR
"TestData/rw2048.dat",
"RW 2048", t);
312 BenchMarkSignature<LUCSS<PSSR, SHA> >(CRYPTOPP_DATA_DIR
"TestData/luc2048.dat",
"LUC 2048", t);
313 BenchMarkSignature<NR<SHA> >(CRYPTOPP_DATA_DIR
"TestData/nr2048.dat",
"NR 2048", t);
314 BenchMarkSignature<LUC_HMP<SHA> >(CRYPTOPP_DATA_DIR
"TestData/lucs1024.dat",
"LUC-HMP 1024", t);
315 BenchMarkSignature<ESIGN<SHA> >(CRYPTOPP_DATA_DIR
"TestData/esig2046.dat",
"ESIGN 2046", t);
317 cout <<
"\n<TBODY style=\"background: yellow\">";
318 BenchMarkKeyAgreement<XTR_DH>(CRYPTOPP_DATA_DIR
"TestData/xtrdh171.dat",
"XTR-DH 171", t);
319 BenchMarkKeyAgreement<XTR_DH>(CRYPTOPP_DATA_DIR
"TestData/xtrdh342.dat",
"XTR-DH 342", t);
320 BenchMarkKeyAgreement<DH>(CRYPTOPP_DATA_DIR
"TestData/dh1024.dat",
"DH 1024", t);
321 BenchMarkKeyAgreement<DH>(CRYPTOPP_DATA_DIR
"TestData/dh2048.dat",
"DH 2048", t);
322 BenchMarkKeyAgreement<LUC_DH>(CRYPTOPP_DATA_DIR
"TestData/lucd512.dat",
"LUCDIF 512", t);
323 BenchMarkKeyAgreement<LUC_DH>(CRYPTOPP_DATA_DIR
"TestData/lucd1024.dat",
"LUCDIF 1024", t);
324 BenchMarkKeyAgreement<MQV>(CRYPTOPP_DATA_DIR
"TestData/mqv1024.dat",
"MQV 1024", t);
325 BenchMarkKeyAgreement<MQV>(CRYPTOPP_DATA_DIR
"TestData/mqv2048.dat",
"MQV 2048", t);
328 BenchMarkKeyAgreement<ECHMQV160>(CRYPTOPP_DATA_DIR
"TestData/hmqv160.dat",
"HMQV P-160", t);
329 BenchMarkKeyAgreement<ECHMQV256>(CRYPTOPP_DATA_DIR
"TestData/hmqv256.dat",
"HMQV P-256", t);
330 BenchMarkKeyAgreement<ECHMQV384>(CRYPTOPP_DATA_DIR
"TestData/hmqv384.dat",
"HMQV P-384", t);
331 BenchMarkKeyAgreement<ECHMQV512>(CRYPTOPP_DATA_DIR
"TestData/hmqv512.dat",
"HMQV P-512", t);
333 BenchMarkKeyAgreement<ECFHMQV160>(CRYPTOPP_DATA_DIR
"TestData/fhmqv160.dat",
"FHMQV P-160", t);
334 BenchMarkKeyAgreement<ECFHMQV256>(CRYPTOPP_DATA_DIR
"TestData/fhmqv256.dat",
"FHMQV P-256", t);
335 BenchMarkKeyAgreement<ECFHMQV384>(CRYPTOPP_DATA_DIR
"TestData/fhmqv384.dat",
"FHMQV P-384", t);
336 BenchMarkKeyAgreement<ECFHMQV512>(CRYPTOPP_DATA_DIR
"TestData/fhmqv512.dat",
"FHMQV P-512", t);
339 cout <<
"\n<TBODY style=\"background: white\">";
348 BenchMarkEncryption(
"ECIES over GF(p) 256", cpub, t);
349 BenchMarkDecryption(
"ECIES over GF(p) 256", cpriv, cpub, t);
350 BenchMarkSigning(
"ECDSA over GF(p) 256", spriv, t);
351 BenchMarkVerification(
"ECDSA over GF(p) 256", spriv, spub, t);
352 BenchMarkKeyGen(
"ECDHC over GF(p) 256", ecdhc, t);
353 BenchMarkAgreement(
"ECDHC over GF(p) 256", ecdhc, t);
354 BenchMarkKeyGen(
"ECMQVC over GF(p) 256", ecmqvc, t);
355 BenchMarkAgreement(
"ECMQVC over GF(p) 256", ecmqvc, t);
358 cout <<
"<TBODY style=\"background: yellow\">" << endl;
367 BenchMarkEncryption(
"ECIES over GF(2^n) 233", cpub, t);
368 BenchMarkDecryption(
"ECIES over GF(2^n) 233", cpriv, cpub, t);
369 BenchMarkSigning(
"ECDSA over GF(2^n) 233", spriv, t);
370 BenchMarkVerification(
"ECDSA over GF(2^n) 233", spriv, spub, t);
371 BenchMarkKeyGen(
"ECDHC over GF(2^n) 233", ecdhc, t);
372 BenchMarkAgreement(
"ECDHC over GF(2^n) 233", ecdhc, t);
373 BenchMarkKeyGen(
"ECMQVC over GF(2^n) 233", ecmqvc, t);
374 BenchMarkAgreement(
"ECMQVC over GF(2^n) 233", ecmqvc, t);
376 cout <<
"</TABLE>" << endl;