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;
50 SecByteBlock plaintext(len), ciphertext(key.CiphertextLength(len));
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);
61 if (!pc && key.GetMaterial().SupportsPrecomputation())
63 key.AccessMaterial().Precompute(16);
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);
136 const clock_t start = clock();
139 for (timeTaken=(
double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
142 OutputResultOperations(name,
"Key-Pair Generation", pc, i, timeTaken);
147 BenchMarkKeyGen(name, d, timeTotal,
true);
155 const clock_t start = clock();
158 for (timeTaken=(
double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
161 OutputResultOperations(name,
"Key-Pair Generation", pc, i, timeTaken);
166 BenchMarkKeyGen(name, d, timeTotal,
true);
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);
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;
virtual void Precompute(unsigned int precomputationStorage)
Perform precomputation.
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 GenerateEphemeralKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
Generate private/public key pair.
Classes for Fully Hashed Menezes-Qu-Vanstone key agreement in GF(p)
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.
virtual unsigned int StaticPublicKeyLength() const =0
Provides the size of the static public key.
Class file for Randomness Pool.
virtual unsigned int AgreedValueLength() const =0
Provides the size of the agreed value.
virtual void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
This file contains helper classes/functions for implementing public key algorithms.
file-based implementation of Source 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.
virtual bool SupportsPrecomputation() const
Determines whether the object supports precomputation.
ASN.1 object identifiers for algorthms and schemes.
virtual unsigned int PrivateKeyLength() const =0
Provides the size of the private key.
virtual size_t SignatureLength() const =0
Provides the signature length if it only depends on the key.
virtual unsigned int StaticPrivateKeyLength() const =0
Provides the size of the static private key.
virtual unsigned int PublicKeyLength() const =0
Provides the size of the public key.
const CryptoMaterial & GetMaterial() const
Retrieves a reference to a Private Key.
This file contains classes that implement the ESIGN signature schemes as defined in IEEE P1363a...
Classes for Hashed Menezes-Qu-Vanstone key agreement in GF(p)
Classes for Elliptic Curves over binary fields.
virtual unsigned int EphemeralPrivateKeyLength() const =0
Provides the size of ephemeral private key.
Interface for domains of simple key agreement protocols.
Classes for Rabin-Williams signature scheme.
Interface for public-key decryptors.
MQV domain for performing authenticated key agreement.
virtual void GenerateKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
Generate a private/public key pair.
const CryptoMaterial & GetMaterial() const
Retrieves a reference to Crypto Parameters.
Classes for Diffie-Hellman key exchange.
Classes for HexEncoder and HexDecoder.
virtual void GenerateStaticKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
Generate a static private/public key pair.
virtual unsigned int EphemeralPublicKeyLength() const =0
Provides the size of ephemeral public key.
const CryptoMaterial & GetMaterial() const
Retrieves a reference to a Public Key.
Implementation of schemes based on DL over GF(p)
SecBlock using AllocatorWithCleanup<byte, true> typedef.
Classes for the DSA signature algorithm.
virtual size_t SignMessage(RandomNumberGenerator &rng, const byte *message, size_t messageLen, byte *signature) const
Sign a message.
virtual bool Agree(byte *agreedValue, const byte *privateKey, const byte *otherPublicKey, bool validateOtherPublicKey=true) const =0
Derive agreed value.
Classes and functions for working with ANS.1 objects.
Implementation of BufferedTransformation's attachment interface.
"The XTR public key system" by Arjen K.
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.
virtual unsigned int AgreedValueLength() const =0
Provides the size of the agreed value.
CryptoMaterial & AccessMaterial()
Retrieves a reference to Crypto Parameters.
Classes and functions for Elliptic Curves over prime and binary fields.
Crypto++ library namespace.
Interface for domains of authenticated key agreement protocols.
Classes for Menezes–Qu–Vanstone (MQV) key agreement.
Classes for probablistic signature schemes.
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.