44 #if CRYPTOPP_MSC_VERSION 45 # pragma warning(disable: 4505 4355) 51 void 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);
66 ++i; timeTaken = timer.ElapsedTimeAsDouble();
68 while (timeTaken < timeTotal);
71 OutputResultOperations(name, provider.c_str(),
"Encryption", pc, i, timeTaken);
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);
97 ++i; timeTaken = timer.ElapsedTimeAsDouble();
99 while (timeTaken < timeTotal);
102 OutputResultOperations(name, provider.c_str(),
"Decryption",
false, i, timeTaken);
105 void 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);
120 ++i; timeTaken = timer.ElapsedTimeAsDouble();
122 while (timeTaken < timeTotal);
125 OutputResultOperations(name, provider.c_str(),
"Signature", pc, i, timeTaken);
130 BenchMarkSigning(name, key, timeTotal,
true);
134 void 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());
150 ++i; timeTaken = timer.ElapsedTimeAsDouble();
152 while (timeTaken < timeTotal);
155 OutputResultOperations(name, provider.c_str(),
"Verification", pc, i, timeTaken);
160 BenchMarkVerification(name, priv, pub, timeTotal,
true);
166 SecByteBlock priv(d.PrivateKeyLength()), pub(d.PublicKeyLength());
176 d.GenerateKeyPair(Test::GlobalRNG(), priv, pub);
177 ++i; timeTaken = timer.ElapsedTimeAsDouble();
179 while (timeTaken < timeTotal);
181 std::string provider = d.AlgorithmProvider();
182 OutputResultOperations(name, provider.c_str(),
"Key-Pair Generation", pc, i, timeTaken);
184 if (!pc && d.GetMaterial().SupportsPrecomputation())
186 d.AccessMaterial().Precompute(16);
187 BenchMarkKeyGen(name, d, timeTotal,
true);
193 SecByteBlock priv(d.EphemeralPrivateKeyLength()), pub(d.EphemeralPublicKeyLength());
203 d.GenerateEphemeralKeyPair(Test::GlobalRNG(), priv, pub);
204 ++i; timeTaken = timer.ElapsedTimeAsDouble();
206 while (timeTaken < timeTotal);
208 std::string provider = d.AlgorithmProvider();
209 OutputResultOperations(name, provider.c_str(),
"Key-Pair Generation", pc, i, timeTaken);
211 if (!pc && d.GetMaterial().SupportsPrecomputation())
213 d.AccessMaterial().Precompute(16);
214 BenchMarkKeyGen(name, d, timeTotal,
true);
220 SecByteBlock priv1(d.PrivateKeyLength()), priv2(d.PrivateKeyLength());
221 SecByteBlock pub1(d.PublicKeyLength()), pub2(d.PublicKeyLength());
222 d.GenerateKeyPair(Test::GlobalRNG(), priv1, pub1);
223 d.GenerateKeyPair(Test::GlobalRNG(), priv2, pub2);
234 d.Agree(val, priv1, pub2);
235 d.Agree(val, priv2, pub1);
236 i+=2; timeTaken = timer.ElapsedTimeAsDouble();
238 while (timeTaken < timeTotal);
240 std::string provider = d.AlgorithmProvider();
241 OutputResultOperations(name, provider.c_str(),
"Key Agreement", pc, i, timeTaken);
246 SecByteBlock spriv1(d.StaticPrivateKeyLength()), spriv2(d.StaticPrivateKeyLength());
247 SecByteBlock epriv1(d.EphemeralPrivateKeyLength()), epriv2(d.EphemeralPrivateKeyLength());
248 SecByteBlock spub1(d.StaticPublicKeyLength()), spub2(d.StaticPublicKeyLength());
249 SecByteBlock epub1(d.EphemeralPublicKeyLength()), epub2(d.EphemeralPublicKeyLength());
250 d.GenerateStaticKeyPair(Test::GlobalRNG(), spriv1, spub1);
251 d.GenerateStaticKeyPair(Test::GlobalRNG(), spriv2, spub2);
252 d.GenerateEphemeralKeyPair(Test::GlobalRNG(), epriv1, epub1);
253 d.GenerateEphemeralKeyPair(Test::GlobalRNG(), epriv2, epub2);
264 d.Agree(val, spriv1, epriv1, spub2, epub2);
265 d.Agree(val, spriv2, epriv2, spub1, epub1);
266 i+=2; timeTaken = timer.ElapsedTimeAsDouble();
268 while (timeTaken < timeTotal);
270 std::string provider = d.AlgorithmProvider();
271 OutputResultOperations(name, provider.c_str(),
"Key Agreement", pc, i, timeTaken);
274 template <
class SCHEME>
275 void 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);
284 template <
class SCHEME>
285 void 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);
295 void BenchMarkKeyAgreement(
const char *filename,
const char *name,
double timeTotal)
299 BenchMarkKeyGen(name, d, timeTotal);
300 BenchMarkAgreement(name, d, timeTotal);
303 void Benchmark3(
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 BenchMarkKeyAgreement<ECHMQV160>(
"TestData/hmqv160.dat",
"HMQV P-160", t);
371 BenchMarkKeyAgreement<ECHMQV256>(
"TestData/hmqv256.dat",
"HMQV P-256", t);
372 BenchMarkKeyAgreement<ECHMQV384>(
"TestData/hmqv384.dat",
"HMQV P-384", t);
373 BenchMarkKeyAgreement<ECHMQV512>(
"TestData/hmqv512.dat",
"HMQV P-512", t);
375 BenchMarkKeyAgreement<ECFHMQV160>(
"TestData/fhmqv160.dat",
"FHMQV P-160", t);
376 BenchMarkKeyAgreement<ECFHMQV256>(
"TestData/fhmqv256.dat",
"FHMQV P-256", t);
377 BenchMarkKeyAgreement<ECFHMQV384>(
"TestData/fhmqv384.dat",
"FHMQV P-384", t);
378 BenchMarkKeyAgreement<ECFHMQV512>(
"TestData/fhmqv512.dat",
"FHMQV P-512", t);
382 std::cout <<
"\n<TBODY style=\"background: yellow;\">";
386 x25519 agree(Test::GlobalRNG());
388 BenchMarkSigning(
"ed25519", sign, t);
389 BenchMarkVerification(
"ed25519", sign, verify, t);
390 BenchMarkKeyGen(
"x25519", agree, t);
391 BenchMarkAgreement(
"x25519", agree, t);
394 std::cout <<
"\n<TBODY style=\"background: white;\">";
407 BenchMarkEncryption(
"ECIES over GF(p) 256", cpub, t);
408 BenchMarkDecryption(
"ECIES over GF(p) 256", cpriv, cpub, t);
409 BenchMarkSigning(
"ECDSA over GF(p) 256", spriv, t);
410 BenchMarkVerification(
"ECDSA over GF(p) 256", spriv, spub, t);
411 BenchMarkSigning(
"ECDSA-RFC6979 over GF(p) 256", spriv2, t);
412 BenchMarkVerification(
"ECDSA-RFC6979 over GF(p) 256", spriv2, spub2, t);
413 BenchMarkSigning(
"ECGDSA over GF(p) 256", spriv3, t);
414 BenchMarkVerification(
"ECGDSA over GF(p) 256", spriv3, spub3, t);
415 BenchMarkKeyGen(
"ECDHC over GF(p) 256", ecdhc, t);
416 BenchMarkAgreement(
"ECDHC over GF(p) 256", ecdhc, t);
417 BenchMarkKeyGen(
"ECMQVC over GF(p) 256", ecmqvc, t);
418 BenchMarkAgreement(
"ECMQVC over GF(p) 256", ecmqvc, t);
421 std::cout <<
"\n<TBODY style=\"background: yellow;\">";
434 BenchMarkEncryption(
"ECIES over GF(2^n) 233", cpub, t);
435 BenchMarkDecryption(
"ECIES over GF(2^n) 233", cpriv, cpub, t);
436 BenchMarkSigning(
"ECDSA over GF(2^n) 233", spriv, t);
437 BenchMarkVerification(
"ECDSA over GF(2^n) 233", spriv, spub, t);
438 BenchMarkSigning(
"ECDSA-RFC6979 over GF(2^n) 233", spriv2, t);
439 BenchMarkVerification(
"ECDSA-RFC6979 over GF(2^n) 233", spriv2, spub2, t);
440 BenchMarkSigning(
"ECGDSA over GF(2^n) 233", spriv3, t);
441 BenchMarkVerification(
"ECGDSA over GF(2^n) 233", spriv3, spub3, t);
442 BenchMarkKeyGen(
"ECDHC over GF(2^n) 233", ecdhc, t);
443 BenchMarkAgreement(
"ECDHC over GF(2^n) 233", ecdhc, t);
444 BenchMarkKeyGen(
"ECMQVC over GF(2^n) 233", ecmqvc, t);
445 BenchMarkAgreement(
"ECMQVC over GF(2^n) 233", ecmqvc, t);
448 std::cout <<
"\n</TABLE>" << std::endl;
virtual void Precompute(unsigned int precomputationStorage)
Perform precomputation.
x25519 with key validation
Standard names for retrieving values by name when working with NameValuePairs.
Classes for working with NameValuePairs.
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.
Ed25519 signature verification algorithm.
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.
Classes for automatic resource management.
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.
virtual std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
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 registering and locating library objects.
Classes for x25519 and ed25519 operations.
Functions for CPU features and intrinsics.
Classes and functions for working with ANS.1 objects.
Implementation of BufferedTransformation's attachment interface.
Ed25519 signature algorithm.
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.