mirror of
https://github.com/nillerusr/source-engine.git
synced 2026-08-30 14:09:19 +00:00
update thirdparty, add build script
This commit is contained in:
Vendored
+317
-267
@@ -1,267 +1,317 @@
|
||||
// bench2.cpp - originally written and placed in the public domain by Wei Dai
|
||||
// CryptoPP::Test namespace added by JW in February 2017
|
||||
|
||||
#include "cryptlib.h"
|
||||
#include "bench.h"
|
||||
#include "validate.h"
|
||||
|
||||
#include "cpu.h"
|
||||
#include "factory.h"
|
||||
#include "algparam.h"
|
||||
#include "argnames.h"
|
||||
#include "smartptr.h"
|
||||
#include "stdcpp.h"
|
||||
|
||||
#include "vmac.h"
|
||||
#include "hmac.h"
|
||||
#include "ttmac.h"
|
||||
#include "cmac.h"
|
||||
#include "dmac.h"
|
||||
|
||||
#if CRYPTOPP_MSC_VERSION
|
||||
# pragma warning(disable: 4355)
|
||||
#endif
|
||||
|
||||
#if CRYPTOPP_MSC_VERSION
|
||||
# pragma warning(disable: 4505 4355)
|
||||
#endif
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
NAMESPACE_BEGIN(Test)
|
||||
|
||||
void BenchMarkKeying(SimpleKeyingInterface &c, size_t keyLength, const NameValuePairs ¶ms)
|
||||
{
|
||||
unsigned long iterations = 0;
|
||||
double timeTaken;
|
||||
|
||||
clock_t start = ::clock();
|
||||
do
|
||||
{
|
||||
for (unsigned int i=0; i<1024; i++)
|
||||
c.SetKey(defaultKey, keyLength, params);
|
||||
timeTaken = double(::clock() - start) / CLOCK_TICKS_PER_SECOND;
|
||||
iterations += 1024;
|
||||
}
|
||||
while (timeTaken < g_allocatedTime);
|
||||
|
||||
OutputResultKeying(iterations, timeTaken);
|
||||
}
|
||||
|
||||
void BenchMark(const char *name, AuthenticatedSymmetricCipher &cipher, double timeTotal)
|
||||
{
|
||||
if (cipher.NeedsPrespecifiedDataLengths())
|
||||
cipher.SpecifyDataLengths(0, cipher.MaxMessageLength(), 0);
|
||||
|
||||
BenchMark(name, static_cast<StreamTransformation &>(cipher), timeTotal);
|
||||
}
|
||||
|
||||
template <class T_FactoryOutput, class T_Interface>
|
||||
void BenchMarkByName2(const char *factoryName, size_t keyLength=0, const char *displayName=NULLPTR, const NameValuePairs ¶ms = g_nullNameValuePairs)
|
||||
{
|
||||
std::string name(factoryName ? factoryName : "");
|
||||
member_ptr<T_FactoryOutput> obj(ObjectFactoryRegistry<T_FactoryOutput>::Registry().CreateObject(name.c_str()));
|
||||
|
||||
if (keyLength == 0)
|
||||
keyLength = obj->DefaultKeyLength();
|
||||
|
||||
if (displayName != NULLPTR)
|
||||
name = displayName;
|
||||
else if (keyLength != 0)
|
||||
name += " (" + IntToString(keyLength * 8) + "-bit key)";
|
||||
|
||||
obj->SetKey(defaultKey, keyLength, CombinedNameValuePairs(params, MakeParameters(Name::IV(), ConstByteArrayParameter(defaultKey, obj->IVSize()), false)));
|
||||
BenchMark(name.c_str(), *static_cast<T_Interface *>(obj.get()), g_allocatedTime);
|
||||
BenchMarkKeying(*obj, keyLength, CombinedNameValuePairs(params, MakeParameters(Name::IV(), ConstByteArrayParameter(defaultKey, obj->IVSize()), false)));
|
||||
}
|
||||
|
||||
template <class T_FactoryOutput>
|
||||
void BenchMarkByName(const char *factoryName, size_t keyLength=0, const char *displayName=NULLPTR, const NameValuePairs ¶ms = g_nullNameValuePairs)
|
||||
{
|
||||
BenchMarkByName2<T_FactoryOutput,T_FactoryOutput>(factoryName, keyLength, displayName, params);
|
||||
}
|
||||
|
||||
void Benchmark2(double t, double hertz)
|
||||
{
|
||||
g_allocatedTime = t;
|
||||
g_hertz = hertz;
|
||||
|
||||
const char *cpb, *cpk;
|
||||
if (g_hertz > 1.0f)
|
||||
{
|
||||
cpb = "<TH>Cycles/Byte";
|
||||
cpk = "<TH>Cycles to<BR>Setup Key and IV";
|
||||
}
|
||||
else
|
||||
{
|
||||
cpb = cpk = "";
|
||||
}
|
||||
|
||||
std::cout << "\n<TABLE>";
|
||||
std::cout << "\n<COLGROUP><COL style=\"text-align: left;\"><COL style=\"text-align: right;\"><COL style=";
|
||||
std::cout << "\"text-align: right;\"><COL style=\"text-align: right;\"><COL style=\"text-align: right;\">";
|
||||
std::cout << "\n<THEAD style=\"background: #F0F0F0\">";
|
||||
std::cout << "\n<TR><TH>Algorithm<TH>Provider<TH>MiB/Second" << cpb;
|
||||
std::cout << "<TH>Microseconds to<BR>Setup Key and IV" << cpk;
|
||||
|
||||
std::cout << "\n<TBODY style=\"background: white;\">";
|
||||
{
|
||||
#if CRYPTOPP_AESNI_AVAILABLE
|
||||
if (HasCLMUL())
|
||||
BenchMarkByName2<AuthenticatedSymmetricCipher, MessageAuthenticationCode>("AES/GCM", 0, "GMAC(AES)");
|
||||
else
|
||||
#elif CRYPTOPP_ARM_PMULL_AVAILABLE
|
||||
if (HasPMULL())
|
||||
BenchMarkByName2<AuthenticatedSymmetricCipher, MessageAuthenticationCode>("AES/GCM", 0, "GMAC(AES)");
|
||||
else
|
||||
#elif CRYPTOPP_POWER8_VMULL_AVAILABLE
|
||||
if (HasPMULL())
|
||||
BenchMarkByName2<AuthenticatedSymmetricCipher, MessageAuthenticationCode>("AES/GCM", 0, "GMAC(AES)");
|
||||
else
|
||||
#endif
|
||||
{
|
||||
BenchMarkByName2<AuthenticatedSymmetricCipher, MessageAuthenticationCode>("AES/GCM", 0, "GMAC(AES) (2K tables)", MakeParameters(Name::TableSize(), 2048));
|
||||
BenchMarkByName2<AuthenticatedSymmetricCipher, MessageAuthenticationCode>("AES/GCM", 0, "GMAC(AES) (64K tables)", MakeParameters(Name::TableSize(), 64 * 1024));
|
||||
}
|
||||
|
||||
BenchMarkByName<MessageAuthenticationCode>("VMAC(AES)-64");
|
||||
BenchMarkByName<MessageAuthenticationCode>("VMAC(AES)-128");
|
||||
BenchMarkByName<MessageAuthenticationCode>("HMAC(SHA-1)");
|
||||
BenchMarkByName<MessageAuthenticationCode>("HMAC(SHA-256)");
|
||||
BenchMarkByName<MessageAuthenticationCode>("Two-Track-MAC");
|
||||
BenchMarkByName<MessageAuthenticationCode>("CMAC(AES)");
|
||||
BenchMarkByName<MessageAuthenticationCode>("DMAC(AES)");
|
||||
BenchMarkByName<MessageAuthenticationCode>("Poly1305(AES)");
|
||||
BenchMarkByName<MessageAuthenticationCode>("Poly1305TLS");
|
||||
BenchMarkByName<MessageAuthenticationCode>("BLAKE2s");
|
||||
BenchMarkByName<MessageAuthenticationCode>("BLAKE2b");
|
||||
BenchMarkByName<MessageAuthenticationCode>("SipHash-2-4");
|
||||
BenchMarkByName<MessageAuthenticationCode>("SipHash-4-8");
|
||||
}
|
||||
|
||||
std::cout << "\n<TBODY style=\"background: yellow;\">";
|
||||
{
|
||||
BenchMarkByName<SymmetricCipher>("Panama-LE");
|
||||
BenchMarkByName<SymmetricCipher>("Panama-BE");
|
||||
BenchMarkByName<SymmetricCipher>("Salsa20", 0, "Salsa20");
|
||||
BenchMarkByName<SymmetricCipher>("Salsa20", 0, "Salsa20/12", MakeParameters(Name::Rounds(), 12));
|
||||
BenchMarkByName<SymmetricCipher>("Salsa20", 0, "Salsa20/8", MakeParameters(Name::Rounds(), 8));
|
||||
BenchMarkByName<SymmetricCipher>("ChaCha", 0, "ChaCha20");
|
||||
BenchMarkByName<SymmetricCipher>("ChaCha", 0, "ChaCha12", MakeParameters(Name::Rounds(), 12));
|
||||
BenchMarkByName<SymmetricCipher>("ChaCha", 0, "ChaCha8", MakeParameters(Name::Rounds(), 8));
|
||||
BenchMarkByName<SymmetricCipher>("ChaChaTLS");
|
||||
BenchMarkByName<SymmetricCipher>("Sosemanuk");
|
||||
BenchMarkByName<SymmetricCipher>("Rabbit");
|
||||
BenchMarkByName<SymmetricCipher>("RabbitWithIV");
|
||||
BenchMarkByName<SymmetricCipher>("HC-128");
|
||||
BenchMarkByName<SymmetricCipher>("HC-256");
|
||||
BenchMarkByName<SymmetricCipher>("MARC4");
|
||||
BenchMarkByName<SymmetricCipher>("SEAL-3.0-LE");
|
||||
BenchMarkByName<SymmetricCipher>("WAKE-OFB-LE");
|
||||
}
|
||||
|
||||
std::cout << "\n<TBODY style=\"background: white;\">";
|
||||
{
|
||||
BenchMarkByName<SymmetricCipher>("AES/CTR", 16);
|
||||
BenchMarkByName<SymmetricCipher>("AES/CTR", 24);
|
||||
BenchMarkByName<SymmetricCipher>("AES/CTR", 32);
|
||||
BenchMarkByName<SymmetricCipher>("AES/CBC", 16);
|
||||
BenchMarkByName<SymmetricCipher>("AES/CBC", 24);
|
||||
BenchMarkByName<SymmetricCipher>("AES/CBC", 32);
|
||||
BenchMarkByName<SymmetricCipher>("AES/XTS", 32);
|
||||
BenchMarkByName<SymmetricCipher>("AES/XTS", 48);
|
||||
BenchMarkByName<SymmetricCipher>("AES/XTS", 64);
|
||||
BenchMarkByName<SymmetricCipher>("AES/OFB", 16);
|
||||
BenchMarkByName<SymmetricCipher>("AES/CFB", 16);
|
||||
BenchMarkByName<SymmetricCipher>("AES/ECB", 16);
|
||||
BenchMarkByName<SymmetricCipher>("ARIA/CTR", 16);
|
||||
BenchMarkByName<SymmetricCipher>("ARIA/CTR", 32);
|
||||
BenchMarkByName<SymmetricCipher>("HIGHT/CTR");
|
||||
BenchMarkByName<SymmetricCipher>("Camellia/CTR", 16);
|
||||
BenchMarkByName<SymmetricCipher>("Camellia/CTR", 32);
|
||||
BenchMarkByName<SymmetricCipher>("Twofish/CTR");
|
||||
BenchMarkByName<SymmetricCipher>("Threefish-256(256)/CTR", 32);
|
||||
BenchMarkByName<SymmetricCipher>("Threefish-512(512)/CTR", 64);
|
||||
BenchMarkByName<SymmetricCipher>("Threefish-1024(1024)/CTR", 128);
|
||||
BenchMarkByName<SymmetricCipher>("Serpent/CTR");
|
||||
BenchMarkByName<SymmetricCipher>("CAST-128/CTR");
|
||||
BenchMarkByName<SymmetricCipher>("CAST-256/CTR", 32);
|
||||
BenchMarkByName<SymmetricCipher>("RC6/CTR");
|
||||
BenchMarkByName<SymmetricCipher>("MARS/CTR");
|
||||
BenchMarkByName<SymmetricCipher>("SHACAL-2/CTR", 16);
|
||||
BenchMarkByName<SymmetricCipher>("SHACAL-2/CTR", 64);
|
||||
BenchMarkByName<SymmetricCipher>("DES/CTR");
|
||||
BenchMarkByName<SymmetricCipher>("DES-XEX3/CTR");
|
||||
BenchMarkByName<SymmetricCipher>("DES-EDE3/CTR");
|
||||
BenchMarkByName<SymmetricCipher>("IDEA/CTR");
|
||||
BenchMarkByName<SymmetricCipher>("RC5/CTR", 0, "RC5 (r=16)");
|
||||
BenchMarkByName<SymmetricCipher>("Blowfish/CTR");
|
||||
BenchMarkByName<SymmetricCipher>("SKIPJACK/CTR");
|
||||
BenchMarkByName<SymmetricCipher>("SEED/CTR", 0, "SEED/CTR (1/2 K table)");
|
||||
BenchMarkByName<SymmetricCipher>("SM4/CTR");
|
||||
|
||||
BenchMarkByName<SymmetricCipher>("Kalyna-128/CTR", 16, "Kalyna-128(128)/CTR (128-bit key)");
|
||||
BenchMarkByName<SymmetricCipher>("Kalyna-128/CTR", 32, "Kalyna-128(256)/CTR (256-bit key)");
|
||||
BenchMarkByName<SymmetricCipher>("Kalyna-256/CTR", 32, "Kalyna-256(256)/CTR (256-bit key)");
|
||||
BenchMarkByName<SymmetricCipher>("Kalyna-256/CTR", 64, "Kalyna-256(512)/CTR (512-bit key)");
|
||||
BenchMarkByName<SymmetricCipher>("Kalyna-512/CTR", 64, "Kalyna-512(512)/CTR (512-bit key)");
|
||||
}
|
||||
|
||||
std::cout << "\n<TBODY style=\"background: yellow;\">";
|
||||
{
|
||||
BenchMarkByName<SymmetricCipher>("CHAM-64/CTR", 16, "CHAM-64(128)/CTR (128-bit key)");
|
||||
BenchMarkByName<SymmetricCipher>("CHAM-128/CTR", 16, "CHAM-128(128)/CTR (128-bit key)");
|
||||
BenchMarkByName<SymmetricCipher>("CHAM-128/CTR", 32, "CHAM-128(256)/CTR (256-bit key)");
|
||||
|
||||
BenchMarkByName<SymmetricCipher>("LEA-128/CTR", 16, "LEA-128(128)/CTR (128-bit key)");
|
||||
BenchMarkByName<SymmetricCipher>("LEA-128/CTR", 24, "LEA-128(192)/CTR (192-bit key)");
|
||||
BenchMarkByName<SymmetricCipher>("LEA-128/CTR", 32, "LEA-128(256)/CTR (256-bit key)");
|
||||
|
||||
BenchMarkByName<SymmetricCipher>("SIMECK-32/CTR", 8, "SIMECK-32(64)/CTR (64-bit key)");
|
||||
BenchMarkByName<SymmetricCipher>("SIMECK-64/CTR", 16, "SIMECK-64(128)/CTR (128-bit key)");
|
||||
|
||||
BenchMarkByName<SymmetricCipher>("SIMON-64/CTR", 12, "SIMON-64(96)/CTR (96-bit key)");
|
||||
BenchMarkByName<SymmetricCipher>("SIMON-64/CTR", 16, "SIMON-64(128)/CTR (128-bit key)");
|
||||
BenchMarkByName<SymmetricCipher>("SIMON-128/CTR", 16, "SIMON-128(128)/CTR (128-bit key)");
|
||||
BenchMarkByName<SymmetricCipher>("SIMON-128/CTR", 24, "SIMON-128(192)/CTR (192-bit key)");
|
||||
BenchMarkByName<SymmetricCipher>("SIMON-128/CTR", 32, "SIMON-128(256)/CTR (256-bit key)");
|
||||
|
||||
BenchMarkByName<SymmetricCipher>("SPECK-64/CTR", 12, "SPECK-64(96)/CTR (96-bit key)");
|
||||
BenchMarkByName<SymmetricCipher>("SPECK-64/CTR", 16, "SPECK-64(128)/CTR (128-bit key)");
|
||||
BenchMarkByName<SymmetricCipher>("SPECK-128/CTR", 16, "SPECK-128(128)/CTR (128-bit key)");
|
||||
BenchMarkByName<SymmetricCipher>("SPECK-128/CTR", 24, "SPECK-128(192)/CTR (192-bit key)");
|
||||
BenchMarkByName<SymmetricCipher>("SPECK-128/CTR", 32, "SPECK-128(256)/CTR (256-bit key)");
|
||||
|
||||
BenchMarkByName<SymmetricCipher>("TEA/CTR");
|
||||
BenchMarkByName<SymmetricCipher>("XTEA/CTR");
|
||||
}
|
||||
|
||||
std::cout << "\n<TBODY style=\"background: white;\">";
|
||||
{
|
||||
#if CRYPTOPP_AESNI_AVAILABLE
|
||||
if (HasCLMUL())
|
||||
BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>("AES/GCM", 0, "AES/GCM");
|
||||
else
|
||||
#elif CRYPTOPP_ARM_PMULL_AVAILABLE
|
||||
if (HasPMULL())
|
||||
BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>("AES/GCM", 0, "AES/GCM");
|
||||
else
|
||||
#elif CRYPTOPP_POWER8_VMULL_AVAILABLE
|
||||
if (HasPMULL())
|
||||
BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>("AES/GCM", 0, "AES/GCM");
|
||||
else
|
||||
#endif
|
||||
{
|
||||
BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>("AES/GCM", 0, "AES/GCM (2K tables)", MakeParameters(Name::TableSize(), 2048));
|
||||
BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>("AES/GCM", 0, "AES/GCM (64K tables)", MakeParameters(Name::TableSize(), 64 * 1024));
|
||||
}
|
||||
BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>("AES/CCM");
|
||||
BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>("AES/EAX");
|
||||
BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>("ChaCha20/Poly1305");
|
||||
BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>("XChaCha20/Poly1305");
|
||||
}
|
||||
|
||||
std::cout << "\n</TABLE>" << std::endl;
|
||||
}
|
||||
|
||||
NAMESPACE_END // Test
|
||||
NAMESPACE_END // CryptoPP
|
||||
// bench2.cpp - written and placed in the public domain by Wei Dai
|
||||
|
||||
#include "bench.h"
|
||||
#include "validate.h"
|
||||
#include "files.h"
|
||||
#include "hex.h"
|
||||
|
||||
#include "rsa.h"
|
||||
#include "nr.h"
|
||||
#include "dsa.h"
|
||||
#include "luc.h"
|
||||
#include "rw.h"
|
||||
#include "eccrypto.h"
|
||||
#include "ecp.h"
|
||||
#include "ec2n.h"
|
||||
#include "asn.h"
|
||||
#include "dh.h"
|
||||
#include "mqv.h"
|
||||
#include "xtrcrypt.h"
|
||||
#include "esign.h"
|
||||
#include "pssr.h"
|
||||
#include "oids.h"
|
||||
#include "randpool.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
USING_NAMESPACE(CryptoPP)
|
||||
USING_NAMESPACE(std)
|
||||
|
||||
void OutputResultOperations(const char *name, const char *operation, bool pc, unsigned long iterations, double timeTaken);
|
||||
|
||||
void BenchMarkEncryption(const char *name, PK_Encryptor &key, double timeTotal, bool pc=false)
|
||||
{
|
||||
unsigned int len = 16;
|
||||
SecByteBlock plaintext(len), ciphertext(key.CiphertextLength(len));
|
||||
GlobalRNG().GenerateBlock(plaintext, len);
|
||||
|
||||
clock_t start = clock();
|
||||
unsigned int i;
|
||||
double timeTaken;
|
||||
for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
|
||||
key.Encrypt(GlobalRNG(), plaintext, len, ciphertext);
|
||||
|
||||
OutputResultOperations(name, "Encryption", pc, i, timeTaken);
|
||||
|
||||
if (!pc && key.GetMaterial().SupportsPrecomputation())
|
||||
{
|
||||
key.AccessMaterial().Precompute(16);
|
||||
BenchMarkEncryption(name, key, timeTotal, true);
|
||||
}
|
||||
}
|
||||
|
||||
void BenchMarkDecryption(const char *name, PK_Decryptor &priv, PK_Encryptor &pub, double timeTotal)
|
||||
{
|
||||
unsigned int len = 16;
|
||||
SecByteBlock ciphertext(pub.CiphertextLength(len));
|
||||
SecByteBlock plaintext(pub.MaxPlaintextLength(ciphertext.size()));
|
||||
GlobalRNG().GenerateBlock(plaintext, len);
|
||||
pub.Encrypt(GlobalRNG(), plaintext, len, ciphertext);
|
||||
|
||||
clock_t start = clock();
|
||||
unsigned int i;
|
||||
double timeTaken;
|
||||
for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
|
||||
priv.Decrypt(GlobalRNG(), ciphertext, ciphertext.size(), plaintext);
|
||||
|
||||
OutputResultOperations(name, "Decryption", false, i, timeTaken);
|
||||
}
|
||||
|
||||
void BenchMarkSigning(const char *name, PK_Signer &key, double timeTotal, bool pc=false)
|
||||
{
|
||||
unsigned int len = 16;
|
||||
AlignedSecByteBlock message(len), signature(key.SignatureLength());
|
||||
GlobalRNG().GenerateBlock(message, len);
|
||||
|
||||
clock_t start = clock();
|
||||
unsigned int i;
|
||||
double timeTaken;
|
||||
for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
|
||||
key.SignMessage(GlobalRNG(), message, len, signature);
|
||||
|
||||
OutputResultOperations(name, "Signature", pc, i, timeTaken);
|
||||
|
||||
if (!pc && key.GetMaterial().SupportsPrecomputation())
|
||||
{
|
||||
key.AccessMaterial().Precompute(16);
|
||||
BenchMarkSigning(name, key, timeTotal, true);
|
||||
}
|
||||
}
|
||||
|
||||
void BenchMarkVerification(const char *name, const PK_Signer &priv, PK_Verifier &pub, double timeTotal, bool pc=false)
|
||||
{
|
||||
unsigned int len = 16;
|
||||
AlignedSecByteBlock message(len), signature(pub.SignatureLength());
|
||||
GlobalRNG().GenerateBlock(message, len);
|
||||
priv.SignMessage(GlobalRNG(), message, len, signature);
|
||||
|
||||
clock_t start = clock();
|
||||
unsigned int i;
|
||||
double timeTaken;
|
||||
for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
|
||||
pub.VerifyMessage(message, len, signature, signature.size());
|
||||
|
||||
OutputResultOperations(name, "Verification", pc, i, timeTaken);
|
||||
|
||||
if (!pc && pub.GetMaterial().SupportsPrecomputation())
|
||||
{
|
||||
pub.AccessMaterial().Precompute(16);
|
||||
BenchMarkVerification(name, priv, pub, timeTotal, true);
|
||||
}
|
||||
}
|
||||
|
||||
void BenchMarkKeyGen(const char *name, SimpleKeyAgreementDomain &d, double timeTotal, bool pc=false)
|
||||
{
|
||||
SecByteBlock priv(d.PrivateKeyLength()), pub(d.PublicKeyLength());
|
||||
|
||||
clock_t start = clock();
|
||||
unsigned int i;
|
||||
double timeTaken;
|
||||
for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
|
||||
d.GenerateKeyPair(GlobalRNG(), priv, pub);
|
||||
|
||||
OutputResultOperations(name, "Key-Pair Generation", pc, i, timeTaken);
|
||||
|
||||
if (!pc && d.GetMaterial().SupportsPrecomputation())
|
||||
{
|
||||
d.AccessMaterial().Precompute(16);
|
||||
BenchMarkKeyGen(name, d, timeTotal, true);
|
||||
}
|
||||
}
|
||||
|
||||
void BenchMarkKeyGen(const char *name, AuthenticatedKeyAgreementDomain &d, double timeTotal, bool pc=false)
|
||||
{
|
||||
SecByteBlock priv(d.EphemeralPrivateKeyLength()), pub(d.EphemeralPublicKeyLength());
|
||||
|
||||
clock_t start = clock();
|
||||
unsigned int i;
|
||||
double timeTaken;
|
||||
for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
|
||||
d.GenerateEphemeralKeyPair(GlobalRNG(), priv, pub);
|
||||
|
||||
OutputResultOperations(name, "Key-Pair Generation", pc, i, timeTaken);
|
||||
|
||||
if (!pc && d.GetMaterial().SupportsPrecomputation())
|
||||
{
|
||||
d.AccessMaterial().Precompute(16);
|
||||
BenchMarkKeyGen(name, d, timeTotal, true);
|
||||
}
|
||||
}
|
||||
|
||||
void BenchMarkAgreement(const char *name, SimpleKeyAgreementDomain &d, double timeTotal, bool pc=false)
|
||||
{
|
||||
SecByteBlock priv1(d.PrivateKeyLength()), priv2(d.PrivateKeyLength());
|
||||
SecByteBlock pub1(d.PublicKeyLength()), pub2(d.PublicKeyLength());
|
||||
d.GenerateKeyPair(GlobalRNG(), priv1, pub1);
|
||||
d.GenerateKeyPair(GlobalRNG(), priv2, pub2);
|
||||
SecByteBlock val(d.AgreedValueLength());
|
||||
|
||||
clock_t start = clock();
|
||||
unsigned int i;
|
||||
double timeTaken;
|
||||
for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i+=2)
|
||||
{
|
||||
d.Agree(val, priv1, pub2);
|
||||
d.Agree(val, priv2, pub1);
|
||||
}
|
||||
|
||||
OutputResultOperations(name, "Key Agreement", pc, i, timeTaken);
|
||||
}
|
||||
|
||||
void BenchMarkAgreement(const char *name, AuthenticatedKeyAgreementDomain &d, double timeTotal, bool pc=false)
|
||||
{
|
||||
SecByteBlock spriv1(d.StaticPrivateKeyLength()), spriv2(d.StaticPrivateKeyLength());
|
||||
SecByteBlock epriv1(d.EphemeralPrivateKeyLength()), epriv2(d.EphemeralPrivateKeyLength());
|
||||
SecByteBlock spub1(d.StaticPublicKeyLength()), spub2(d.StaticPublicKeyLength());
|
||||
SecByteBlock epub1(d.EphemeralPublicKeyLength()), epub2(d.EphemeralPublicKeyLength());
|
||||
d.GenerateStaticKeyPair(GlobalRNG(), spriv1, spub1);
|
||||
d.GenerateStaticKeyPair(GlobalRNG(), spriv2, spub2);
|
||||
d.GenerateEphemeralKeyPair(GlobalRNG(), epriv1, epub1);
|
||||
d.GenerateEphemeralKeyPair(GlobalRNG(), epriv2, epub2);
|
||||
SecByteBlock val(d.AgreedValueLength());
|
||||
|
||||
clock_t start = clock();
|
||||
unsigned int i;
|
||||
double timeTaken;
|
||||
for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i+=2)
|
||||
{
|
||||
d.Agree(val, spriv1, epriv1, spub2, epub2);
|
||||
d.Agree(val, spriv2, epriv2, spub1, epub1);
|
||||
}
|
||||
|
||||
OutputResultOperations(name, "Key Agreement", pc, i, timeTaken);
|
||||
}
|
||||
|
||||
//VC60 workaround: compiler bug triggered without the extra dummy parameters
|
||||
template <class SCHEME>
|
||||
void BenchMarkCrypto(const char *filename, const char *name, double timeTotal, SCHEME *x=NULL)
|
||||
{
|
||||
FileSource f(filename, true, new HexDecoder());
|
||||
typename SCHEME::Decryptor priv(f);
|
||||
typename SCHEME::Encryptor pub(priv);
|
||||
BenchMarkEncryption(name, pub, timeTotal);
|
||||
BenchMarkDecryption(name, priv, pub, timeTotal);
|
||||
}
|
||||
|
||||
//VC60 workaround: compiler bug triggered without the extra dummy parameters
|
||||
template <class SCHEME>
|
||||
void BenchMarkSignature(const char *filename, const char *name, double timeTotal, SCHEME *x=NULL)
|
||||
{
|
||||
FileSource f(filename, true, new HexDecoder());
|
||||
typename SCHEME::Signer priv(f);
|
||||
typename SCHEME::Verifier pub(priv);
|
||||
BenchMarkSigning(name, priv, timeTotal);
|
||||
BenchMarkVerification(name, priv, pub, timeTotal);
|
||||
}
|
||||
|
||||
//VC60 workaround: compiler bug triggered without the extra dummy parameters
|
||||
template <class D>
|
||||
void BenchMarkKeyAgreement(const char *filename, const char *name, double timeTotal, D *x=NULL)
|
||||
{
|
||||
FileSource f(filename, true, new HexDecoder());
|
||||
D d(f);
|
||||
BenchMarkKeyGen(name, d, timeTotal);
|
||||
BenchMarkAgreement(name, d, timeTotal);
|
||||
}
|
||||
|
||||
extern double g_hertz;
|
||||
|
||||
void BenchmarkAll2(double t, double hertz)
|
||||
{
|
||||
g_hertz = hertz;
|
||||
#if 0
|
||||
cout << "<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right>" << endl;
|
||||
cout << "<THEAD><TR><TH>Operation<TH>Milliseconds/Operation" << (g_hertz ? "<TH>Megacycles/Operation" : "") << endl;
|
||||
|
||||
cout << "\n<TBODY style=\"background: yellow\">";
|
||||
BenchMarkCrypto<RSAES<OAEP<SHA> > >("TestData/rsa1024.dat", "RSA 1024", t);
|
||||
BenchMarkCrypto<LUCES<OAEP<SHA> > >("TestData/luc1024.dat", "LUC 1024", t);
|
||||
BenchMarkCrypto<DLIES<> >("TestData/dlie1024.dat", "DLIES 1024", t);
|
||||
BenchMarkCrypto<LUC_IES<> >("TestData/lucc512.dat", "LUCELG 512", t);
|
||||
|
||||
cout << "\n<TBODY style=\"background: white\">";
|
||||
BenchMarkCrypto<RSAES<OAEP<SHA> > >("TestData/rsa2048.dat", "RSA 2048", t);
|
||||
BenchMarkCrypto<LUCES<OAEP<SHA> > >("TestData/luc2048.dat", "LUC 2048", t);
|
||||
BenchMarkCrypto<DLIES<> >("TestData/dlie2048.dat", "DLIES 2048", t);
|
||||
BenchMarkCrypto<LUC_IES<> >("TestData/lucc1024.dat", "LUCELG 1024", t);
|
||||
|
||||
cout << "\n<TBODY style=\"background: yellow\">";
|
||||
BenchMarkSignature<RSASS<PSSR, SHA> >("TestData/rsa1024.dat", "RSA 1024", t);
|
||||
BenchMarkSignature<RWSS<PSSR, SHA> >("TestData/rw1024.dat", "RW 1024", t);
|
||||
BenchMarkSignature<LUCSS<PSSR, SHA> >("TestData/luc1024.dat", "LUC 1024", t);
|
||||
BenchMarkSignature<NR<SHA> >("TestData/nr1024.dat", "NR 1024", t);
|
||||
BenchMarkSignature<DSA>("TestData/dsa1024.dat", "DSA 1024", t);
|
||||
BenchMarkSignature<LUC_HMP<SHA> >("TestData/lucs512.dat", "LUC-HMP 512", t);
|
||||
BenchMarkSignature<ESIGN<SHA> >("TestData/esig1023.dat", "ESIGN 1023", t);
|
||||
BenchMarkSignature<ESIGN<SHA> >("TestData/esig1536.dat", "ESIGN 1536", t);
|
||||
|
||||
cout << "\n<TBODY style=\"background: white\">";
|
||||
BenchMarkSignature<RSASS<PSSR, SHA> >("TestData/rsa2048.dat", "RSA 2048", t);
|
||||
BenchMarkSignature<RWSS<PSSR, SHA> >("TestData/rw2048.dat", "RW 2048", t);
|
||||
BenchMarkSignature<LUCSS<PSSR, SHA> >("TestData/luc2048.dat", "LUC 2048", t);
|
||||
BenchMarkSignature<NR<SHA> >("TestData/nr2048.dat", "NR 2048", t);
|
||||
BenchMarkSignature<LUC_HMP<SHA> >("TestData/lucs1024.dat", "LUC-HMP 1024", t);
|
||||
BenchMarkSignature<ESIGN<SHA> >("TestData/esig2046.dat", "ESIGN 2046", t);
|
||||
|
||||
cout << "\n<TBODY style=\"background: yellow\">";
|
||||
BenchMarkKeyAgreement<XTR_DH>("TestData/xtrdh171.dat", "XTR-DH 171", t);
|
||||
BenchMarkKeyAgreement<XTR_DH>("TestData/xtrdh342.dat", "XTR-DH 342", t);
|
||||
BenchMarkKeyAgreement<DH>("TestData/dh1024.dat", "DH 1024", t);
|
||||
BenchMarkKeyAgreement<DH>("TestData/dh2048.dat", "DH 2048", t);
|
||||
BenchMarkKeyAgreement<LUC_DH>("TestData/lucd512.dat", "LUCDIF 512", t);
|
||||
BenchMarkKeyAgreement<LUC_DH>("TestData/lucd1024.dat", "LUCDIF 1024", t);
|
||||
BenchMarkKeyAgreement<MQV>("TestData/mqv1024.dat", "MQV 1024", t);
|
||||
BenchMarkKeyAgreement<MQV>("TestData/mqv2048.dat", "MQV 2048", t);
|
||||
#endif
|
||||
cout << "\n<TBODY style=\"background: white\">";
|
||||
{
|
||||
ECIES<ECP>::Decryptor cpriv(GlobalRNG(), ASN1::secp256k1());
|
||||
ECIES<ECP>::Encryptor cpub(cpriv);
|
||||
ECDSA<ECP, SHA>::Signer spriv(cpriv);
|
||||
ECDSA<ECP, SHA>::Verifier spub(spriv);
|
||||
ECDH<ECP>::Domain ecdhc(ASN1::secp256k1());
|
||||
ECMQV<ECP>::Domain ecmqvc(ASN1::secp256k1());
|
||||
|
||||
BenchMarkEncryption("ECIES over GF(p) 256", cpub, t);
|
||||
BenchMarkDecryption("ECIES over GF(p) 256", cpriv, cpub, t);
|
||||
BenchMarkSigning("ECDSA over GF(p) 256", spriv, t);
|
||||
BenchMarkVerification("ECDSA over GF(p) 256", spriv, spub, t);
|
||||
BenchMarkKeyGen("ECDHC over GF(p) 256", ecdhc, t);
|
||||
BenchMarkAgreement("ECDHC over GF(p) 256", ecdhc, t);
|
||||
BenchMarkKeyGen("ECMQVC over GF(p) 256", ecmqvc, t);
|
||||
BenchMarkAgreement("ECMQVC over GF(p) 256", ecmqvc, t);
|
||||
}
|
||||
|
||||
cout << "<TBODY style=\"background: yellow\">" << endl;
|
||||
{
|
||||
ECIES<EC2N>::Decryptor cpriv(GlobalRNG(), ASN1::sect233r1());
|
||||
ECIES<EC2N>::Encryptor cpub(cpriv);
|
||||
ECDSA<EC2N, SHA>::Signer spriv(cpriv);
|
||||
ECDSA<EC2N, SHA>::Verifier spub(spriv);
|
||||
ECDH<EC2N>::Domain ecdhc(ASN1::sect233r1());
|
||||
ECMQV<EC2N>::Domain ecmqvc(ASN1::sect233r1());
|
||||
|
||||
BenchMarkEncryption("ECIES over GF(2^n) 233", cpub, t);
|
||||
BenchMarkDecryption("ECIES over GF(2^n) 233", cpriv, cpub, t);
|
||||
BenchMarkSigning("ECDSA over GF(2^n) 233", spriv, t);
|
||||
BenchMarkVerification("ECDSA over GF(2^n) 233", spriv, spub, t);
|
||||
BenchMarkKeyGen("ECDHC over GF(2^n) 233", ecdhc, t);
|
||||
BenchMarkAgreement("ECDHC over GF(2^n) 233", ecdhc, t);
|
||||
BenchMarkKeyGen("ECMQVC over GF(2^n) 233", ecmqvc, t);
|
||||
BenchMarkAgreement("ECMQVC over GF(2^n) 233", ecmqvc, t);
|
||||
}
|
||||
cout << "</TABLE>" << endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user