36 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 37 # pragma GCC diagnostic ignored "-Wdeprecated-declarations" 43 void OutputResultOperations(const
char *name, const
char *operation,
bool pc,
unsigned long iterations,
double timeTaken);
45 void BenchMarkEncryption(const
char *name,
PK_Encryptor &key,
double timeTotal,
bool pc=false)
47 unsigned int len = 16;
48 SecByteBlock plaintext(len), ciphertext(key.CiphertextLength(len));
51 const clock_t start = clock();
54 for (timeTaken=(
double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
55 key.Encrypt(GlobalRNG(), plaintext, len, ciphertext);
57 OutputResultOperations(name,
"Encryption", pc, i, timeTaken);
59 if (!pc && key.GetMaterial().SupportsPrecomputation())
61 key.AccessMaterial().Precompute(16);
62 BenchMarkEncryption(name, key, timeTotal,
true);
68 unsigned int len = 16;
72 pub.
Encrypt(GlobalRNG(), plaintext, len, ciphertext);
74 const clock_t start = clock();
77 for (timeTaken=(
double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
78 priv.
Decrypt(GlobalRNG(), ciphertext, ciphertext.size(), plaintext);
80 OutputResultOperations(name,
"Decryption",
false, i, timeTaken);
83 void BenchMarkSigning(
const char *name,
PK_Signer &key,
double timeTotal,
bool pc=
false)
85 unsigned int len = 16;
89 const clock_t start = clock();
92 for (timeTaken=(
double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
93 key.
SignMessage(GlobalRNG(), message, len, signature);
95 OutputResultOperations(name,
"Signature", pc, i, timeTaken);
100 BenchMarkSigning(name, key, timeTotal,
true);
104 void BenchMarkVerification(
const char *name,
const PK_Signer &priv,
PK_Verifier &pub,
double timeTotal,
bool pc=
false)
106 unsigned int len = 16;
109 priv.
SignMessage(GlobalRNG(), message, len, signature);
111 const clock_t start = clock();
114 for (timeTaken=(
double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
117 bool unused = pub.
VerifyMessage(message, len, signature, signature.size());
118 CRYPTOPP_UNUSED(unused);
121 OutputResultOperations(name,
"Verification", pc, i, timeTaken);
126 BenchMarkVerification(name, priv, pub, timeTotal,
true);
134 const clock_t start = clock();
137 for (timeTaken=(
double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
140 OutputResultOperations(name,
"Key-Pair Generation", pc, i, timeTaken);
145 BenchMarkKeyGen(name, d, timeTotal,
true);
153 const clock_t start = clock();
156 for (timeTaken=(
double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
159 OutputResultOperations(name,
"Key-Pair Generation", pc, i, timeTaken);
164 BenchMarkKeyGen(name, d, timeTotal,
true);
176 const clock_t start = clock();
179 for (timeTaken=(
double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i+=2)
181 d.
Agree(val, priv1, pub2);
182 d.
Agree(val, priv2, pub1);
185 OutputResultOperations(name,
"Key Agreement", pc, i, timeTaken);
200 const clock_t start = clock();
203 for (timeTaken=(
double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i+=2)
205 d.
Agree(val, spriv1, epriv1, spub2, epub2);
206 d.
Agree(val, spriv2, epriv2, spub1, epub1);
209 OutputResultOperations(name,
"Key Agreement", pc, i, timeTaken);
213 template <
class SCHEME>
214 void BenchMarkCrypto(
const char *filename,
const char *name,
double timeTotal, SCHEME *x=NULL)
219 typename SCHEME::Decryptor priv(f);
220 typename SCHEME::Encryptor pub(priv);
221 BenchMarkEncryption(name, pub, timeTotal);
222 BenchMarkDecryption(name, priv, pub, timeTotal);
226 template <
class SCHEME>
227 void BenchMarkSignature(
const char *filename,
const char *name,
double timeTotal, SCHEME *x=NULL)
232 typename SCHEME::Signer priv(f);
233 typename SCHEME::Verifier pub(priv);
234 BenchMarkSigning(name, priv, timeTotal);
235 BenchMarkVerification(name, priv, pub, timeTotal);
240 void BenchMarkKeyAgreement(
const char *filename,
const char *name,
double timeTotal, D *x=NULL)
246 BenchMarkKeyGen(name, d, timeTotal);
247 BenchMarkAgreement(name, d, timeTotal);
250 extern double g_hertz;
252 void BenchmarkAll2(
double t,
double hertz)
256 cout <<
"<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right>" << endl;
257 cout <<
"<THEAD><TR><TH>Operation<TH>Milliseconds/Operation" << (g_hertz ?
"<TH>Megacycles/Operation" :
"") << endl;
259 cout <<
"\n<TBODY style=\"background: yellow\">";
260 BenchMarkCrypto<RSAES<OAEP<SHA> > >(PACKAGE_DATA_DIR
"TestData/rsa1024.dat",
"RSA 1024", t);
261 BenchMarkCrypto<LUCES<OAEP<SHA> > >(PACKAGE_DATA_DIR
"TestData/luc1024.dat",
"LUC 1024", t);
262 BenchMarkCrypto<DLIES<> >(PACKAGE_DATA_DIR
"TestData/dlie1024.dat",
"DLIES 1024", t);
263 BenchMarkCrypto<LUC_IES<> >(PACKAGE_DATA_DIR
"TestData/lucc512.dat",
"LUCELG 512", t);
265 cout <<
"\n<TBODY style=\"background: white\">";
266 BenchMarkCrypto<RSAES<OAEP<SHA> > >(PACKAGE_DATA_DIR
"TestData/rsa2048.dat",
"RSA 2048", t);
267 BenchMarkCrypto<LUCES<OAEP<SHA> > >(PACKAGE_DATA_DIR
"TestData/luc2048.dat",
"LUC 2048", t);
268 BenchMarkCrypto<DLIES<> >(PACKAGE_DATA_DIR
"TestData/dlie2048.dat",
"DLIES 2048", t);
269 BenchMarkCrypto<LUC_IES<> >(PACKAGE_DATA_DIR
"TestData/lucc1024.dat",
"LUCELG 1024", t);
271 cout <<
"\n<TBODY style=\"background: yellow\">";
272 BenchMarkSignature<RSASS<PSSR, SHA> >(PACKAGE_DATA_DIR
"TestData/rsa1024.dat",
"RSA 1024", t);
273 BenchMarkSignature<RWSS<PSSR, SHA> >(PACKAGE_DATA_DIR
"TestData/rw1024.dat",
"RW 1024", t);
274 BenchMarkSignature<LUCSS<PSSR, SHA> >(PACKAGE_DATA_DIR
"TestData/luc1024.dat",
"LUC 1024", t);
275 BenchMarkSignature<NR<SHA> >(PACKAGE_DATA_DIR
"TestData/nr1024.dat",
"NR 1024", t);
276 BenchMarkSignature<DSA>(PACKAGE_DATA_DIR
"TestData/dsa1024.dat",
"DSA 1024", t);
277 BenchMarkSignature<LUC_HMP<SHA> >(PACKAGE_DATA_DIR
"TestData/lucs512.dat",
"LUC-HMP 512", t);
278 BenchMarkSignature<ESIGN<SHA> >(PACKAGE_DATA_DIR
"TestData/esig1023.dat",
"ESIGN 1023", t);
279 BenchMarkSignature<ESIGN<SHA> >(PACKAGE_DATA_DIR
"TestData/esig1536.dat",
"ESIGN 1536", t);
281 cout <<
"\n<TBODY style=\"background: white\">";
282 BenchMarkSignature<RSASS<PSSR, SHA> >(PACKAGE_DATA_DIR
"TestData/rsa2048.dat",
"RSA 2048", t);
283 BenchMarkSignature<RWSS<PSSR, SHA> >(PACKAGE_DATA_DIR
"TestData/rw2048.dat",
"RW 2048", t);
284 BenchMarkSignature<LUCSS<PSSR, SHA> >(PACKAGE_DATA_DIR
"TestData/luc2048.dat",
"LUC 2048", t);
285 BenchMarkSignature<NR<SHA> >(PACKAGE_DATA_DIR
"TestData/nr2048.dat",
"NR 2048", t);
286 BenchMarkSignature<LUC_HMP<SHA> >(PACKAGE_DATA_DIR
"TestData/lucs1024.dat",
"LUC-HMP 1024", t);
287 BenchMarkSignature<ESIGN<SHA> >(PACKAGE_DATA_DIR
"TestData/esig2046.dat",
"ESIGN 2046", t);
289 cout <<
"\n<TBODY style=\"background: yellow\">";
290 BenchMarkKeyAgreement<XTR_DH>(PACKAGE_DATA_DIR
"TestData/xtrdh171.dat",
"XTR-DH 171", t);
291 BenchMarkKeyAgreement<XTR_DH>(PACKAGE_DATA_DIR
"TestData/xtrdh342.dat",
"XTR-DH 342", t);
292 BenchMarkKeyAgreement<DH>(PACKAGE_DATA_DIR
"TestData/dh1024.dat",
"DH 1024", t);
293 BenchMarkKeyAgreement<DH>(PACKAGE_DATA_DIR
"TestData/dh2048.dat",
"DH 2048", t);
294 BenchMarkKeyAgreement<LUC_DH>(PACKAGE_DATA_DIR
"TestData/lucd512.dat",
"LUCDIF 512", t);
295 BenchMarkKeyAgreement<LUC_DH>(PACKAGE_DATA_DIR
"TestData/lucd1024.dat",
"LUCDIF 1024", t);
296 BenchMarkKeyAgreement<MQV>(PACKAGE_DATA_DIR
"TestData/mqv1024.dat",
"MQV 1024", t);
297 BenchMarkKeyAgreement<MQV>(PACKAGE_DATA_DIR
"TestData/mqv2048.dat",
"MQV 2048", t);
299 cout <<
"\n<TBODY style=\"background: white\">";
308 BenchMarkEncryption(
"ECIES over GF(p) 256", cpub, t);
309 BenchMarkDecryption(
"ECIES over GF(p) 256", cpriv, cpub, t);
310 BenchMarkSigning(
"ECDSA over GF(p) 256", spriv, t);
311 BenchMarkVerification(
"ECDSA over GF(p) 256", spriv, spub, t);
312 BenchMarkKeyGen(
"ECDHC over GF(p) 256", ecdhc, t);
313 BenchMarkAgreement(
"ECDHC over GF(p) 256", ecdhc, t);
314 BenchMarkKeyGen(
"ECMQVC over GF(p) 256", ecmqvc, t);
315 BenchMarkAgreement(
"ECMQVC over GF(p) 256", ecmqvc, t);
318 cout <<
"<TBODY style=\"background: yellow\">" << endl;
327 BenchMarkEncryption(
"ECIES over GF(2^n) 233", cpub, t);
328 BenchMarkDecryption(
"ECIES over GF(2^n) 233", cpriv, cpub, t);
329 BenchMarkSigning(
"ECDSA over GF(2^n) 233", spriv, t);
330 BenchMarkVerification(
"ECDSA over GF(2^n) 233", spriv, spub, t);
331 BenchMarkKeyGen(
"ECDHC over GF(2^n) 233", ecdhc, t);
332 BenchMarkAgreement(
"ECDHC over GF(2^n) 233", ecdhc, t);
333 BenchMarkKeyGen(
"ECMQVC over GF(2^n) 233", ecmqvc, t);
334 BenchMarkAgreement(
"ECMQVC over GF(2^n) 233", ecmqvc, t);
336 cout <<
"</TABLE>" << endl;
virtual void Precompute(unsigned int precomputationStorage)
Perform precomputation.
virtual void GenerateEphemeralKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
generate private/public key pair
virtual unsigned int StaticPublicKeyLength() const =0
return length of static public keys in this domain
virtual DecodingResult Decrypt(RandomNumberGenerator &rng, const byte *ciphertext, size_t ciphertextLength, byte *plaintext, const NameValuePairs ¶meters=g_nullNameValuePairs) const =0
Decrypt a byte string.
virtual void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
This file contains helper classes/functions for implementing public key algorithms.
virtual unsigned int AgreedValueLength() const =0
return length of agreed value produced
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.
CryptoMaterial & AccessMaterial()
returns a reference to the crypto material used by this object
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 from your private keys and couterparty's public keys, return false in case of fai...
virtual bool SupportsPrecomputation() const
Determines whether the object supports precomputation.
Object identifiers for algorthms and schemes.
SecByteBlock is a SecBlock<byte> typedef.
const CryptoMaterial & GetMaterial() const
returns a const reference to the crypto material used by this object
This file contains classes that implement the ESIGN signature schemes as defined in IEEE P1363a...
virtual unsigned int EphemeralPublicKeyLength() const =0
return length of ephemeral public keys in this domain
Classes for Elliptic Curves over binary fields.
Interface for domains of simple key agreement protocols.
Classes for Rabin-Williams signature schemes.
Interface for public-key decryptors.
MQV domain for performing authenticated key agreement.
virtual void GenerateKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
generate private/public key pair
virtual unsigned int AgreedValueLength() const =0
return length of agreed value produced
const CryptoMaterial & GetMaterial() const
returns a const reference to the crypto material used by this object
Classes for Diffie-Hellman key exchange.
Classes for HexEncoder and HexDecoder.
virtual void GenerateStaticKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
generate private/public key pair
virtual size_t MaxPlaintextLength(size_t ciphertextLength) const =0
maximum length of plaintext for a given ciphertext length
virtual size_t CiphertextLength(size_t plaintextLength) const =0
calculate length of ciphertext given length of plaintext
const CryptoMaterial & GetMaterial() const
returns a const reference to the crypto material used by this object
Implementation of schemes based on DL over GF(p)
AlignedSecByteBlock is a SecBlock<byte, 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 VerifyMessage(const byte *message, size_t messageLen, const byte *signature, size_t signatureLength) const
check whether input signature is a valid signature for input message
virtual unsigned int PrivateKeyLength() const =0
return length of private keys in this domain
Classes and functions for working with ANS.1 objects.
virtual bool Agree(byte *agreedValue, const byte *privateKey, const byte *otherPublicKey, bool validateOtherPublicKey=true) const =0
derive agreed value from your private key and couterparty's public key, return false in case of failu...
Implementation of BufferedTransformation's attachment interface in cryptlib.h.
"The XTR public key system" by Arjen K.
Classes for the RSA cryptosystem.
CryptoMaterial & AccessMaterial()
returns a reference to the crypto material used by this object
Interface for public-key signature verifiers.
virtual unsigned int StaticPrivateKeyLength() const =0
return length of static private keys in this domain
CryptoMaterial & AccessMaterial()
returns a reference to the crypto material used by this object
virtual unsigned int PublicKeyLength() const =0
return length of public keys in this domain
virtual unsigned int EphemeralPrivateKeyLength() const =0
return length of ephemeral private keys in this domain
Classes and functions for Elliptic Curves over prime and binary fields.
Crypto++ library namespace.
Interface for domains of authenticated key agreement protocols.
virtual void Encrypt(RandomNumberGenerator &rng, const byte *plaintext, size_t plaintextLength, byte *ciphertext, const NameValuePairs ¶meters=g_nullNameValuePairs) const =0
Encrypt a byte string.
Classes for Menezes–Qu–Vanstone (MQV) key agreement.
Classes for probablistic signature schemes.
A template implementing constructors for public key algorithm classes.
virtual size_t SignatureLength() const =0
signature length if it only depends on the key, otherwise 0