36 #if CRYPTOPP_MSC_VERSION 37 # pragma warning(disable: 4505 4355) 43 void BenchMarkEncryption(
const char *name,
PK_Encryptor &key,
double timeTotal,
bool pc=
false)
45 unsigned int len = 16;
47 Test::GlobalRNG().GenerateBlock(plaintext, len);
57 key.
Encrypt(Test::GlobalRNG(), plaintext, len, ciphertext);
58 ++i; timeTaken = timer.ElapsedTimeAsDouble();
60 while (timeTaken < timeTotal);
62 OutputResultOperations(name,
"Encryption", pc, i, timeTaken);
67 BenchMarkEncryption(name, key, timeTotal,
true);
73 unsigned int len = 16;
76 Test::GlobalRNG().GenerateBlock(plaintext, len);
77 pub.
Encrypt(Test::GlobalRNG(), plaintext, len, ciphertext);
87 priv.
Decrypt(Test::GlobalRNG(), ciphertext, ciphertext.size(), plaintext);
88 ++i; timeTaken = timer.ElapsedTimeAsDouble();
90 while (timeTaken < timeTotal);
92 OutputResultOperations(name,
"Decryption",
false, i, timeTaken);
95 void BenchMarkSigning(
const char *name,
PK_Signer &key,
double timeTotal,
bool pc=
false)
97 unsigned int len = 16;
99 Test::GlobalRNG().GenerateBlock(message, len);
109 (void)key.
SignMessage(Test::GlobalRNG(), message, len, signature);
110 ++i; timeTaken = timer.ElapsedTimeAsDouble();
112 while (timeTaken < timeTotal);
114 OutputResultOperations(name,
"Signature", pc, i, timeTaken);
119 BenchMarkSigning(name, key, timeTotal,
true);
123 void BenchMarkVerification(
const char *name,
const PK_Signer &priv,
PK_Verifier &pub,
double timeTotal,
bool pc=
false)
125 unsigned int len = 16;
127 Test::GlobalRNG().GenerateBlock(message, len);
128 priv.
SignMessage(Test::GlobalRNG(), message, len, signature);
138 (void)pub.
VerifyMessage(message, len, signature, signature.size());
139 ++i; timeTaken = timer.ElapsedTimeAsDouble();
141 while (timeTaken < timeTotal);
143 OutputResultOperations(name,
"Verification", pc, i, timeTaken);
148 BenchMarkVerification(name, priv, pub, timeTotal,
true);
154 SecByteBlock priv(d.PrivateKeyLength()), pub(d.PublicKeyLength());
164 d.GenerateKeyPair(Test::GlobalRNG(), priv, pub);
165 ++i; timeTaken = timer.ElapsedTimeAsDouble();
167 while (timeTaken < timeTotal);
169 OutputResultOperations(name,
"Key-Pair Generation", pc, i, timeTaken);
171 if (!pc && d.GetMaterial().SupportsPrecomputation())
173 d.AccessMaterial().Precompute(16);
174 BenchMarkKeyGen(name, d, timeTotal,
true);
180 SecByteBlock priv(d.EphemeralPrivateKeyLength()), pub(d.EphemeralPublicKeyLength());
190 d.GenerateEphemeralKeyPair(Test::GlobalRNG(), priv, pub);
191 ++i; timeTaken = timer.ElapsedTimeAsDouble();
193 while (timeTaken < timeTotal);
195 OutputResultOperations(name,
"Key-Pair Generation", pc, i, timeTaken);
197 if (!pc && d.GetMaterial().SupportsPrecomputation())
199 d.AccessMaterial().Precompute(16);
200 BenchMarkKeyGen(name, d, timeTotal,
true);
206 SecByteBlock priv1(d.PrivateKeyLength()), priv2(d.PrivateKeyLength());
207 SecByteBlock pub1(d.PublicKeyLength()), pub2(d.PublicKeyLength());
208 d.GenerateKeyPair(Test::GlobalRNG(), priv1, pub1);
209 d.GenerateKeyPair(Test::GlobalRNG(), priv2, pub2);
220 d.Agree(val, priv1, pub2);
221 d.Agree(val, priv2, pub1);
222 i+=2; timeTaken = timer.ElapsedTimeAsDouble();
224 while (timeTaken < timeTotal);
226 OutputResultOperations(name,
"Key Agreement", pc, i, timeTaken);
231 SecByteBlock spriv1(d.StaticPrivateKeyLength()), spriv2(d.StaticPrivateKeyLength());
232 SecByteBlock epriv1(d.EphemeralPrivateKeyLength()), epriv2(d.EphemeralPrivateKeyLength());
233 SecByteBlock spub1(d.StaticPublicKeyLength()), spub2(d.StaticPublicKeyLength());
234 SecByteBlock epub1(d.EphemeralPublicKeyLength()), epub2(d.EphemeralPublicKeyLength());
235 d.GenerateStaticKeyPair(Test::GlobalRNG(), spriv1, spub1);
236 d.GenerateStaticKeyPair(Test::GlobalRNG(), spriv2, spub2);
237 d.GenerateEphemeralKeyPair(Test::GlobalRNG(), epriv1, epub1);
238 d.GenerateEphemeralKeyPair(Test::GlobalRNG(), epriv2, epub2);
249 d.Agree(val, spriv1, epriv1, spub2, epub2);
250 d.Agree(val, spriv2, epriv2, spub1, epub1);
251 i+=2; timeTaken = timer.ElapsedTimeAsDouble();
253 while (timeTaken < timeTotal);
255 OutputResultOperations(name,
"Key Agreement", pc, i, timeTaken);
258 template <
class SCHEME>
259 void BenchMarkCrypto(
const char *filename,
const char *name,
double timeTotal)
262 typename SCHEME::Decryptor priv(f);
263 typename SCHEME::Encryptor pub(priv);
264 BenchMarkEncryption(name, pub, timeTotal);
265 BenchMarkDecryption(name, priv, pub, timeTotal);
268 template <
class SCHEME>
269 void BenchMarkSignature(
const char *filename,
const char *name,
double timeTotal)
272 typename SCHEME::Signer priv(f);
273 typename SCHEME::Verifier pub(priv);
274 BenchMarkSigning(name, priv, timeTotal);
275 BenchMarkVerification(name, priv, pub, timeTotal);
279 void BenchMarkKeyAgreement(
const char *filename,
const char *name,
double timeTotal)
283 BenchMarkKeyGen(name, d, timeTotal);
284 BenchMarkAgreement(name, d, timeTotal);
287 void Benchmark3(
double t,
double hertz)
294 mco =
"<TH>Megacycles/Operation";
298 std::cout <<
"\n<TABLE>";
299 std::cout <<
"\n<COLGROUP><COL style=\"text-align: left;\"><COL style=";
300 std::cout <<
"\"text-align: right;\"><COL style=\"text-align: right;\">";
301 std::cout <<
"\n<THEAD style=\"background: #F0F0F0\">";
302 std::cout <<
"\n<TR><TH>Operation<TH>Milliseconds/Operation" << mco;
304 std::cout <<
"\n<TBODY style=\"background: white;\">";
306 BenchMarkCrypto<RSAES<OAEP<SHA1> > >(CRYPTOPP_DATA_DIR
"TestData/rsa1024.dat",
"RSA 1024", t);
307 BenchMarkCrypto<LUCES<OAEP<SHA1> > >(CRYPTOPP_DATA_DIR
"TestData/luc1024.dat",
"LUC 1024", t);
308 BenchMarkCrypto<DLIES<> >(CRYPTOPP_DATA_DIR
"TestData/dlie1024.dat",
"DLIES 1024", t);
309 BenchMarkCrypto<LUC_IES<> >(CRYPTOPP_DATA_DIR
"TestData/lucc512.dat",
"LUCELG 512", t);
312 std::cout <<
"\n<TBODY style=\"background: yellow;\">";
314 BenchMarkCrypto<RSAES<OAEP<SHA1> > >(CRYPTOPP_DATA_DIR
"TestData/rsa2048.dat",
"RSA 2048", t);
315 BenchMarkCrypto<LUCES<OAEP<SHA1> > >(CRYPTOPP_DATA_DIR
"TestData/luc2048.dat",
"LUC 2048", t);
316 BenchMarkCrypto<DLIES<> >(CRYPTOPP_DATA_DIR
"TestData/dlie2048.dat",
"DLIES 2048", t);
317 BenchMarkCrypto<LUC_IES<> >(CRYPTOPP_DATA_DIR
"TestData/lucc1024.dat",
"LUCELG 1024", t);
320 std::cout <<
"\n<TBODY style=\"background: white;\">";
322 BenchMarkSignature<RSASS<PSSR, SHA1> >(CRYPTOPP_DATA_DIR
"TestData/rsa1024.dat",
"RSA 1024", t);
323 BenchMarkSignature<RWSS<PSSR, SHA1> >(CRYPTOPP_DATA_DIR
"TestData/rw1024.dat",
"RW 1024", t);
324 BenchMarkSignature<LUCSS<PSSR, SHA1> >(CRYPTOPP_DATA_DIR
"TestData/luc1024.dat",
"LUC 1024", t);
325 BenchMarkSignature<NR<SHA1> >(CRYPTOPP_DATA_DIR
"TestData/nr1024.dat",
"NR 1024", t);
326 BenchMarkSignature<DSA>(CRYPTOPP_DATA_DIR
"TestData/dsa1024.dat",
"DSA 1024", t);
327 BenchMarkSignature<LUC_HMP<SHA1> >(CRYPTOPP_DATA_DIR
"TestData/lucs512.dat",
"LUC-HMP 512", t);
328 BenchMarkSignature<ESIGN<SHA1> >(CRYPTOPP_DATA_DIR
"TestData/esig1023.dat",
"ESIGN 1023", t);
329 BenchMarkSignature<ESIGN<SHA1> >(CRYPTOPP_DATA_DIR
"TestData/esig1536.dat",
"ESIGN 1536", t);
332 std::cout <<
"\n<TBODY style=\"background: yellow;\">";
334 BenchMarkSignature<RSASS<PSSR, SHA1> >(CRYPTOPP_DATA_DIR
"TestData/rsa2048.dat",
"RSA 2048", t);
335 BenchMarkSignature<RWSS<PSSR, SHA1> >(CRYPTOPP_DATA_DIR
"TestData/rw2048.dat",
"RW 2048", t);
336 BenchMarkSignature<LUCSS<PSSR, SHA1> >(CRYPTOPP_DATA_DIR
"TestData/luc2048.dat",
"LUC 2048", t);
337 BenchMarkSignature<NR<SHA1> >(CRYPTOPP_DATA_DIR
"TestData/nr2048.dat",
"NR 2048", t);
338 BenchMarkSignature<LUC_HMP<SHA1> >(CRYPTOPP_DATA_DIR
"TestData/lucs1024.dat",
"LUC-HMP 1024", t);
339 BenchMarkSignature<ESIGN<SHA1> >(CRYPTOPP_DATA_DIR
"TestData/esig2046.dat",
"ESIGN 2046", t);
342 std::cout <<
"\n<TBODY style=\"background: white;\">";
344 BenchMarkKeyAgreement<XTR_DH>(CRYPTOPP_DATA_DIR
"TestData/xtrdh171.dat",
"XTR-DH 171", t);
345 BenchMarkKeyAgreement<XTR_DH>(CRYPTOPP_DATA_DIR
"TestData/xtrdh342.dat",
"XTR-DH 342", t);
346 BenchMarkKeyAgreement<DH>(CRYPTOPP_DATA_DIR
"TestData/dh1024.dat",
"DH 1024", t);
347 BenchMarkKeyAgreement<DH>(CRYPTOPP_DATA_DIR
"TestData/dh2048.dat",
"DH 2048", t);
348 BenchMarkKeyAgreement<LUC_DH>(CRYPTOPP_DATA_DIR
"TestData/lucd512.dat",
"LUCDIF 512", t);
349 BenchMarkKeyAgreement<LUC_DH>(CRYPTOPP_DATA_DIR
"TestData/lucd1024.dat",
"LUCDIF 1024", t);
350 BenchMarkKeyAgreement<MQV>(CRYPTOPP_DATA_DIR
"TestData/mqv1024.dat",
"MQV 1024", t);
351 BenchMarkKeyAgreement<MQV>(CRYPTOPP_DATA_DIR
"TestData/mqv2048.dat",
"MQV 2048", t);
354 BenchMarkKeyAgreement<ECHMQV160>(CRYPTOPP_DATA_DIR
"TestData/hmqv160.dat",
"HMQV P-160", t);
355 BenchMarkKeyAgreement<ECHMQV256>(CRYPTOPP_DATA_DIR
"TestData/hmqv256.dat",
"HMQV P-256", t);
356 BenchMarkKeyAgreement<ECHMQV384>(CRYPTOPP_DATA_DIR
"TestData/hmqv384.dat",
"HMQV P-384", t);
357 BenchMarkKeyAgreement<ECHMQV512>(CRYPTOPP_DATA_DIR
"TestData/hmqv512.dat",
"HMQV P-512", t);
359 BenchMarkKeyAgreement<ECFHMQV160>(CRYPTOPP_DATA_DIR
"TestData/fhmqv160.dat",
"FHMQV P-160", t);
360 BenchMarkKeyAgreement<ECFHMQV256>(CRYPTOPP_DATA_DIR
"TestData/fhmqv256.dat",
"FHMQV P-256", t);
361 BenchMarkKeyAgreement<ECFHMQV384>(CRYPTOPP_DATA_DIR
"TestData/fhmqv384.dat",
"FHMQV P-384", t);
362 BenchMarkKeyAgreement<ECFHMQV512>(CRYPTOPP_DATA_DIR
"TestData/fhmqv512.dat",
"FHMQV P-512", t);
366 std::cout <<
"\n<TBODY style=\"background: yellow;\">";
379 BenchMarkEncryption(
"ECIES over GF(p) 256", cpub, t);
380 BenchMarkDecryption(
"ECIES over GF(p) 256", cpriv, cpub, t);
381 BenchMarkSigning(
"ECDSA over GF(p) 256", spriv, t);
382 BenchMarkVerification(
"ECDSA over GF(p) 256", spriv, spub, t);
383 BenchMarkSigning(
"ECDSA-RFC6979 over GF(p) 256", spriv2, t);
384 BenchMarkVerification(
"ECDSA-RFC6979 over GF(p) 256", spriv2, spub2, t);
385 BenchMarkSigning(
"ECGDSA over GF(p) 256", spriv3, t);
386 BenchMarkVerification(
"ECGDSA over GF(p) 256", spriv3, spub3, t);
387 BenchMarkKeyGen(
"ECDHC over GF(p) 256", ecdhc, t);
388 BenchMarkAgreement(
"ECDHC over GF(p) 256", ecdhc, t);
389 BenchMarkKeyGen(
"ECMQVC over GF(p) 256", ecmqvc, t);
390 BenchMarkAgreement(
"ECMQVC over GF(p) 256", ecmqvc, t);
393 std::cout <<
"\n<TBODY style=\"background: white;\">";
406 BenchMarkEncryption(
"ECIES over GF(2^n) 233", cpub, t);
407 BenchMarkDecryption(
"ECIES over GF(2^n) 233", cpriv, cpub, t);
408 BenchMarkSigning(
"ECDSA over GF(2^n) 233", spriv, t);
409 BenchMarkVerification(
"ECDSA over GF(2^n) 233", spriv, spub, t);
410 BenchMarkSigning(
"ECDSA-RFC6979 over GF(2^n) 233", spriv2, t);
411 BenchMarkVerification(
"ECDSA-RFC6979 over GF(2^n) 233", spriv2, spub2, t);
412 BenchMarkSigning(
"ECGDSA over GF(2^n) 233", spriv3, t);
413 BenchMarkVerification(
"ECGDSA over GF(2^n) 233", spriv3, spub3, t);
414 BenchMarkKeyGen(
"ECDHC over GF(2^n) 233", ecdhc, t);
415 BenchMarkAgreement(
"ECDHC over GF(2^n) 233", ecdhc, t);
416 BenchMarkKeyGen(
"ECMQVC over GF(2^n) 233", ecmqvc, t);
417 BenchMarkAgreement(
"ECMQVC over GF(2^n) 233", ecmqvc, t);
420 std::cout <<
"\n</TABLE>" << std::endl;
virtual void Precompute(unsigned int precomputationStorage)
Perform precomputation.
Classes for Fully Hashed Menezes-Qu-Vanstone key agreement in GF(p)
Class file for Randomness Pool.
This file contains helper classes/functions for implementing public key algorithms.
virtual size_t SignMessage(RandomNumberGenerator &rng, const byte *message, size_t messageLen, byte *signature) const
Sign a message.
Implementation of Store interface.
Classes for Elliptic Curves over prime fields.
Interface for public-key signers.
Interface for public-key encryptors.
Decode base 16 data back to bytes.
Abstract base classes that provide a uniform interface to this library.
virtual void Encrypt(RandomNumberGenerator &rng, const byte *plaintext, size_t plaintextLength, byte *ciphertext, const NameValuePairs ¶meters=g_nullNameValuePairs) const =0
Encrypt a byte string.
virtual size_t MaxPlaintextLength(size_t ciphertextLength) const =0
Provides the maximum length of plaintext for a given ciphertext length.
CryptoMaterial & AccessMaterial()
Retrieves a reference to a Private Key.
ASN.1 object identifiers for algorthms and schemes.
virtual size_t SignatureLength() const =0
Provides the signature length if it only depends on the key.
Classes providing ESIGN signature schemes as defined in IEEE P1363a.
Classes for Hashed Menezes-Qu-Vanstone key agreement in GF(p)
Classes for the LUC cryptosystem.
Classes for Elliptic Curves over binary fields.
Interface for domains of simple key agreement protocols.
const CryptoMaterial & GetMaterial() const
Retrieves a reference to a Private Key.
Classes for PKCS padding schemes.
Classes for Rabin-Williams signature scheme.
Interface for public-key decryptors.
MQV domain for performing authenticated key agreement.
Classes for Diffie-Hellman key exchange.
Classes for HexEncoder and HexDecoder.
virtual bool VerifyMessage(const byte *message, size_t messageLen, const byte *signature, size_t signatureLen) const
Check whether input signature is a valid signature for input message.
Namespace containing testing and benchmark classes.
Classes and functions for schemes based on Discrete Logs (DL) over GF(p)
SecBlock using AllocatorWithCleanup<byte, true> typedef.
Classes for the DSA signature algorithm.
Classes and functions for working with ANS.1 objects.
Implementation of BufferedTransformation's attachment interface.
Classes for the RSA cryptosystem.
CryptoMaterial & AccessMaterial()
Retrieves a reference to a Public Key.
Interface for public-key signature verifiers.
virtual size_t CiphertextLength(size_t plaintextLength) const =0
Calculate the length of ciphertext given length of plaintext.
Classes providing file-based library services.
Classes and functions for Elliptic Curves over prime and binary fields.
Crypto++ library namespace.
Interface for domains of authenticated key agreement protocols.
Measure CPU time spent executing instructions of this thread (if supported by OS)
virtual bool SupportsPrecomputation() const
Determines whether the object supports precomputation.
Classes for Menezes–Qu–Vanstone (MQV) key agreement.
Classes for probablistic signature schemes.
const CryptoMaterial & GetMaterial() const
Retrieves a reference to a Public Key.
virtual DecodingResult Decrypt(RandomNumberGenerator &rng, const byte *ciphertext, size_t ciphertextLength, byte *plaintext, const NameValuePairs ¶meters=g_nullNameValuePairs) const =0
Decrypt a byte string.
Template implementing constructors for public key algorithm classes.