44#if CRYPTOPP_MSC_VERSION
45# pragma warning(disable: 4505 4355)
51void BenchMarkEncryption(
const char *name,
PK_Encryptor &key,
double timeTotal,
bool pc =
false)
53 unsigned int len = 16;
55 Test::GlobalRNG().GenerateBlock(plaintext, len);
65 key.
Encrypt(Test::GlobalRNG(), plaintext, len, ciphertext);
68 while (timeTaken < timeTotal);
71 OutputResultOperations(name, provider.c_str(),
"Encryption", pc, i, timeTaken);
73 if (!pc && key.
GetMaterial().SupportsPrecomputation())
76 BenchMarkEncryption(name, key, timeTotal,
true);
82 unsigned int len = 16;
85 Test::GlobalRNG().GenerateBlock(plaintext, len);
86 pub.
Encrypt(Test::GlobalRNG(), plaintext, len, ciphertext);
96 priv.
Decrypt(Test::GlobalRNG(), ciphertext, ciphertext.size(), plaintext);
99 while (timeTaken < timeTotal);
102 OutputResultOperations(name, provider.c_str(),
"Decryption",
false, i, timeTaken);
105void BenchMarkSigning(
const char *name,
PK_Signer &key,
double timeTotal,
bool pc=
false)
107 unsigned int len = 16;
109 Test::GlobalRNG().GenerateBlock(message, len);
119 (void)key.
SignMessage(Test::GlobalRNG(), message, len, signature);
122 while (timeTaken < timeTotal);
125 OutputResultOperations(name, provider.c_str(),
"Signature", pc, i, timeTaken);
127 if (!pc && key.
GetMaterial().SupportsPrecomputation())
130 BenchMarkSigning(name, key, timeTotal,
true);
134void BenchMarkVerification(
const char *name,
const PK_Signer &priv,
PK_Verifier &pub,
double timeTotal,
bool pc=
false)
136 unsigned int len = 16;
138 Test::GlobalRNG().GenerateBlock(message, len);
139 priv.
SignMessage(Test::GlobalRNG(), message, len, signature);
149 (void)pub.
VerifyMessage(message, len, signature, signature.size());
152 while (timeTaken < timeTotal);
155 OutputResultOperations(name, provider.c_str(),
"Verification", pc, i, timeTaken);
157 if (!pc && pub.
GetMaterial().SupportsPrecomputation())
160 BenchMarkVerification(name, priv, pub, timeTotal,
true);
179 while (timeTaken < timeTotal);
182 OutputResultOperations(name, provider.c_str(),
"Key-Pair Generation", pc, i, timeTaken);
184 if (!pc && d.
GetMaterial().SupportsPrecomputation())
187 BenchMarkKeyGen(name, d, timeTotal,
true);
206 while (timeTaken < timeTotal);
209 OutputResultOperations(name, provider.c_str(),
"Key-Pair Generation", pc, i, timeTaken);
211 if (!pc && d.
GetMaterial().SupportsPrecomputation())
214 BenchMarkKeyGen(name, d, timeTotal,
true);
234 d.
Agree(val, priv1, pub2);
235 d.
Agree(val, priv2, pub1);
238 while (timeTaken < timeTotal);
241 OutputResultOperations(name, provider.c_str(),
"Key Agreement", pc, i, timeTaken);
264 d.
Agree(val, spriv1, epriv1, spub2, epub2);
265 d.
Agree(val, spriv2, epriv2, spub1, epub1);
268 while (timeTaken < timeTotal);
271 OutputResultOperations(name, provider.c_str(),
"Key Agreement", pc, i, timeTaken);
274template <
class SCHEME>
275void BenchMarkCrypto(
const char *filename,
const char *name,
double timeTotal)
278 typename SCHEME::Decryptor priv(f);
279 typename SCHEME::Encryptor pub(priv);
280 BenchMarkEncryption(name, pub, timeTotal);
281 BenchMarkDecryption(name, priv, pub, timeTotal);
284template <
class SCHEME>
285void BenchMarkSignature(
const char *filename,
const char *name,
double timeTotal)
288 typename SCHEME::Signer priv(f);
289 typename SCHEME::Verifier pub(priv);
290 BenchMarkSigning(name, priv, timeTotal);
291 BenchMarkVerification(name, priv, pub, timeTotal);
295void BenchMarkKeyAgreement(
const char *filename,
const char *name,
double timeTotal)
299 BenchMarkKeyGen(name, d, timeTotal);
300 BenchMarkAgreement(name, d, timeTotal);
303void BenchmarkPublicKeyAlgorithms(
double t,
double hertz)
310 mco =
"<TH>Megacycles/Operation";
314 std::cout <<
"\n<TABLE>";
315 std::cout <<
"\n<COLGROUP><COL style=\"text-align: left;\"><COL style=";
316 std::cout <<
"\"text-align: right;\"><COL style=\"text-align: right;\">";
317 std::cout <<
"\n<THEAD style=\"background: #F0F0F0\">";
318 std::cout <<
"\n<TR><TH>Operation<TH>Milliseconds/Operation" << mco;
320 std::cout <<
"\n<TBODY style=\"background: white;\">";
322 BenchMarkCrypto<RSAES<OAEP<SHA1> > >(
"TestData/rsa1024.dat",
"RSA 1024", t);
323 BenchMarkCrypto<LUCES<OAEP<SHA1> > >(
"TestData/luc1024.dat",
"LUC 1024", t);
324 BenchMarkCrypto<DLIES<> >(
"TestData/dlie1024.dat",
"DLIES 1024", t);
325 BenchMarkCrypto<LUC_IES<> >(
"TestData/lucc512.dat",
"LUCELG 512", t);
328 std::cout <<
"\n<TBODY style=\"background: yellow;\">";
330 BenchMarkCrypto<RSAES<OAEP<SHA1> > >(
"TestData/rsa2048.dat",
"RSA 2048", t);
331 BenchMarkCrypto<LUCES<OAEP<SHA1> > >(
"TestData/luc2048.dat",
"LUC 2048", t);
332 BenchMarkCrypto<DLIES<> >(
"TestData/dlie2048.dat",
"DLIES 2048", t);
333 BenchMarkCrypto<LUC_IES<> >(
"TestData/lucc1024.dat",
"LUCELG 1024", t);
336 std::cout <<
"\n<TBODY style=\"background: white;\">";
338 BenchMarkSignature<RSASS<PSSR, SHA1> >(
"TestData/rsa1024.dat",
"RSA 1024", t);
339 BenchMarkSignature<RWSS<PSSR, SHA1> >(
"TestData/rw1024.dat",
"RW 1024", t);
340 BenchMarkSignature<LUCSS<PSSR, SHA1> >(
"TestData/luc1024.dat",
"LUC 1024", t);
341 BenchMarkSignature<NR<SHA1> >(
"TestData/nr1024.dat",
"NR 1024", t);
342 BenchMarkSignature<DSA>(
"TestData/dsa1024.dat",
"DSA 1024", t);
343 BenchMarkSignature<LUC_HMP<SHA1> >(
"TestData/lucs512.dat",
"LUC-HMP 512", t);
344 BenchMarkSignature<ESIGN<SHA1> >(
"TestData/esig1023.dat",
"ESIGN 1023", t);
345 BenchMarkSignature<ESIGN<SHA1> >(
"TestData/esig1536.dat",
"ESIGN 1536", t);
348 std::cout <<
"\n<TBODY style=\"background: yellow;\">";
350 BenchMarkSignature<RSASS<PSSR, SHA1> >(
"TestData/rsa2048.dat",
"RSA 2048", t);
351 BenchMarkSignature<RWSS<PSSR, SHA1> >(
"TestData/rw2048.dat",
"RW 2048", t);
352 BenchMarkSignature<LUCSS<PSSR, SHA1> >(
"TestData/luc2048.dat",
"LUC 2048", t);
353 BenchMarkSignature<NR<SHA1> >(
"TestData/nr2048.dat",
"NR 2048", t);
354 BenchMarkSignature<LUC_HMP<SHA1> >(
"TestData/lucs1024.dat",
"LUC-HMP 1024", t);
355 BenchMarkSignature<ESIGN<SHA1> >(
"TestData/esig2046.dat",
"ESIGN 2046", t);
358 std::cout <<
"\n<TBODY style=\"background: white;\">";
360 BenchMarkKeyAgreement<XTR_DH>(
"TestData/xtrdh171.dat",
"XTR-DH 171", t);
361 BenchMarkKeyAgreement<XTR_DH>(
"TestData/xtrdh342.dat",
"XTR-DH 342", t);
362 BenchMarkKeyAgreement<DH>(
"TestData/dh1024.dat",
"DH 1024", t);
363 BenchMarkKeyAgreement<DH>(
"TestData/dh2048.dat",
"DH 2048", t);
364 BenchMarkKeyAgreement<LUC_DH>(
"TestData/lucd512.dat",
"LUCDIF 512", t);
365 BenchMarkKeyAgreement<LUC_DH>(
"TestData/lucd1024.dat",
"LUCDIF 1024", t);
366 BenchMarkKeyAgreement<MQV>(
"TestData/mqv1024.dat",
"MQV 1024", t);
367 BenchMarkKeyAgreement<MQV>(
"TestData/mqv2048.dat",
"MQV 2048", t);
370 std::cout <<
"\n</TABLE>" << std::endl;
373void BenchmarkEllipticCurveAlgorithms(
double t,
double hertz)
380 mco =
"<TH>Megacycles/Operation";
384 std::cout <<
"\n<TABLE>";
385 std::cout <<
"\n<COLGROUP><COL style=\"text-align: left;\"><COL style=";
386 std::cout <<
"\"text-align: right;\"><COL style=\"text-align: right;\">";
387 std::cout <<
"\n<THEAD style=\"background: #F0F0F0\">";
388 std::cout <<
"\n<TR><TH>Operation<TH>Milliseconds/Operation" << mco;
390 std::cout <<
"\n<TBODY style=\"background: white;\">";
394 x25519 agree(Test::GlobalRNG());
396 BenchMarkSigning(
"ed25519", sign, t);
397 BenchMarkVerification(
"ed25519", sign, verify, t);
398 BenchMarkKeyGen(
"x25519", agree, t);
399 BenchMarkAgreement(
"x25519", agree, t);
403 std::cout <<
"\n<TBODY style=\"background: yellow;\">";
405 BenchMarkKeyAgreement<ECMQV160>(
"TestData/mqv160.dat",
"MQV P-160", t);
406 BenchMarkKeyAgreement<ECMQV256>(
"TestData/mqv256.dat",
"MQV P-256", t);
407 BenchMarkKeyAgreement<ECMQV384>(
"TestData/mqv384.dat",
"MQV P-384", t);
408 BenchMarkKeyAgreement<ECMQV512>(
"TestData/mqv512.dat",
"MQV P-521", t);
410 BenchMarkKeyAgreement<ECHMQV160>(
"TestData/hmqv160.dat",
"HMQV P-160", t);
411 BenchMarkKeyAgreement<ECHMQV256>(
"TestData/hmqv256.dat",
"HMQV P-256", t);
412 BenchMarkKeyAgreement<ECHMQV384>(
"TestData/hmqv384.dat",
"HMQV P-384", t);
413 BenchMarkKeyAgreement<ECHMQV512>(
"TestData/hmqv512.dat",
"HMQV P-521", t);
415 BenchMarkKeyAgreement<ECFHMQV160>(
"TestData/fhmqv160.dat",
"FHMQV P-160", t);
416 BenchMarkKeyAgreement<ECFHMQV256>(
"TestData/fhmqv256.dat",
"FHMQV P-256", t);
417 BenchMarkKeyAgreement<ECFHMQV384>(
"TestData/fhmqv384.dat",
"FHMQV P-384", t);
418 BenchMarkKeyAgreement<ECFHMQV512>(
"TestData/fhmqv512.dat",
"FHMQV P-521", t);
422 std::cout <<
"\n<TBODY style=\"background: yellow;\">";
435 BenchMarkEncryption(
"ECIES over GF(p) 256", cpub, t);
436 BenchMarkDecryption(
"ECIES over GF(p) 256", cpriv, cpub, t);
437 BenchMarkSigning(
"ECDSA over GF(p) 256", spriv, t);
438 BenchMarkVerification(
"ECDSA over GF(p) 256", spriv, spub, t);
439 BenchMarkSigning(
"ECDSA-RFC6979 over GF(p) 256", spriv2, t);
440 BenchMarkVerification(
"ECDSA-RFC6979 over GF(p) 256", spriv2, spub2, t);
441 BenchMarkSigning(
"ECGDSA over GF(p) 256", spriv3, t);
442 BenchMarkVerification(
"ECGDSA over GF(p) 256", spriv3, spub3, t);
443 BenchMarkKeyGen(
"ECDHC over GF(p) 256", ecdhc, t);
444 BenchMarkAgreement(
"ECDHC over GF(p) 256", ecdhc, t);
445 BenchMarkKeyGen(
"ECMQVC over GF(p) 256", ecmqvc, t);
446 BenchMarkAgreement(
"ECMQVC over GF(p) 256", ecmqvc, t);
449 std::cout <<
"\n<TBODY style=\"background: white;\">";
462 BenchMarkEncryption(
"ECIES over GF(2^n) 233", cpub, t);
463 BenchMarkDecryption(
"ECIES over GF(2^n) 233", cpriv, cpub, t);
464 BenchMarkSigning(
"ECDSA over GF(2^n) 233", spriv, t);
465 BenchMarkVerification(
"ECDSA over GF(2^n) 233", spriv, spub, t);
466 BenchMarkSigning(
"ECDSA-RFC6979 over GF(2^n) 233", spriv2, t);
467 BenchMarkVerification(
"ECDSA-RFC6979 over GF(2^n) 233", spriv2, spub2, t);
468 BenchMarkSigning(
"ECGDSA over GF(2^n) 233", spriv3, t);
469 BenchMarkVerification(
"ECGDSA over GF(2^n) 233", spriv3, spub3, t);
470 BenchMarkKeyGen(
"ECDHC over GF(2^n) 233", ecdhc, t);
471 BenchMarkAgreement(
"ECDHC over GF(2^n) 233", ecdhc, t);
472 BenchMarkKeyGen(
"ECMQVC over GF(2^n) 233", ecmqvc, t);
473 BenchMarkAgreement(
"ECMQVC over GF(2^n) 233", ecmqvc, t);
476 std::cout <<
"\n</TABLE>" << std::endl;
Classes for working with NameValuePairs.
Standard names for retrieving values by name when working with NameValuePairs.
Classes and functions for working with ANS.1 objects.
virtual std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
SecBlock using AllocatorWithCleanup<byte, true> typedef.
Interface for domains of authenticated key agreement protocols.
virtual unsigned int StaticPrivateKeyLength() const =0
Provides the size of the static private key.
virtual unsigned int EphemeralPublicKeyLength() const =0
Provides the size of ephemeral public key.
virtual unsigned int EphemeralPrivateKeyLength() const =0
Provides the size of ephemeral private key.
virtual unsigned int AgreedValueLength() const =0
Provides the size of the agreed value.
virtual unsigned int StaticPublicKeyLength() const =0
Provides the size of the static public key.
virtual bool Agree(byte *agreedValue, const byte *staticPrivateKey, const byte *ephemeralPrivateKey, const byte *staticOtherPublicKey, const byte *ephemeralOtherPublicKey, bool validateStaticOtherPublicKey=true) const =0
Derive agreed value.
virtual void GenerateStaticKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
Generate a static private/public key pair.
virtual void GenerateEphemeralKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
Generate private/public key pair.
virtual void Precompute(unsigned int precomputationStorage)
Perform precomputation.
Implementation of Store interface.
Decode base 16 data back to bytes.
CryptoMaterial & AccessMaterial()
Retrieves a reference to Crypto Parameters.
const CryptoMaterial & GetMaterial() const
Retrieves a reference to Crypto Parameters.
MQV domain for performing authenticated key agreement.
virtual size_t MaxPlaintextLength(size_t ciphertextLength) const =0
Provides the maximum length of plaintext for a given ciphertext length.
virtual size_t CiphertextLength(size_t plaintextLength) const =0
Calculate the length of ciphertext given length of plaintext.
Interface for public-key decryptors.
virtual DecodingResult Decrypt(RandomNumberGenerator &rng, const byte *ciphertext, size_t ciphertextLength, byte *plaintext, const NameValuePairs ¶meters=g_nullNameValuePairs) const =0
Decrypt a byte string.
Interface for public-key encryptors.
virtual void Encrypt(RandomNumberGenerator &rng, const byte *plaintext, size_t plaintextLength, byte *ciphertext, const NameValuePairs ¶meters=g_nullNameValuePairs) const =0
Encrypt a byte string.
Template implementing constructors for public key algorithm classes.
virtual size_t SignatureLength() const =0
Provides the signature length if it only depends on the key.
Interface for public-key signers.
virtual size_t SignMessage(RandomNumberGenerator &rng, const byte *message, size_t messageLen, byte *signature) const
Sign a message.
Interface for public-key signature verifiers.
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.
const CryptoMaterial & GetMaterial() const
Retrieves a reference to a Private Key.
CryptoMaterial & AccessMaterial()
Retrieves a reference to a Private Key.
CryptoMaterial & AccessMaterial()
Retrieves a reference to a Public Key.
const CryptoMaterial & GetMaterial() const
Retrieves a reference to a Public Key.
Interface for domains of simple key agreement protocols.
virtual unsigned int PublicKeyLength() const =0
Provides the size of the public key.
virtual bool Agree(byte *agreedValue, const byte *privateKey, const byte *otherPublicKey, bool validateOtherPublicKey=true) const =0
Derive agreed value.
virtual unsigned int PrivateKeyLength() const =0
Provides the size of the private key.
virtual void GenerateKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
Generate a private/public key pair.
virtual unsigned int AgreedValueLength() const =0
Provides the size of the agreed value.
Measure CPU time spent executing instructions of this thread.
double ElapsedTimeAsDouble()
Retrieve the elapsed time.
void StartTimer()
Start the timer.
x25519 with key validation
Functions for CPU features and intrinsics.
Abstract base classes that provide a uniform interface to this library.
Classes for Diffie-Hellman key exchange.
Classes for the DSA signature algorithm.
Classes for Elliptic Curves over binary fields.
Classes and functions for Elliptic Curves over prime and binary fields.
Classes for Elliptic Curves over prime fields.
Classes providing ESIGN signature schemes as defined in IEEE P1363a.
Classes and functions for registering and locating library objects.
Classes for Fully Hashed Menezes-Qu-Vanstone key agreement in GF(p)
Classes providing file-based library services.
Implementation of BufferedTransformation's attachment interface.
Classes and functions for schemes based on Discrete Logs (DL) over GF(p)
Classes for HexEncoder and HexDecoder.
Classes for Hashed Menezes-Qu-Vanstone key agreement in GF(p)
Classes for the LUC cryptosystem.
Classes for Menezes–Qu–Vanstone (MQV) key agreement.
Crypto++ library namespace.
Namespace containing testing and benchmark classes.
Classes for Nyberg-Rueppel signature scheme.
ASN.1 object identifiers for algorithms and schemes.
Classes for PKCS padding schemes.
Classes for probabilistic signature schemes.
This file contains helper classes/functions for implementing public key algorithms.
Class file for Randomness Pool.
Classes for the RSA cryptosystem.
Classes for Rabin-Williams signature scheme.
Classes for automatic resource management.
Ed25519 signature algorithm.
Ed25519 signature verification algorithm.
Classes for x25519 and ed25519 operations.