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); const 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++) { // The return value is ignored because we are interested in throughput bool unused = pub.VerifyMessage(message, len, signature, signature.size()); CRYPTOPP_UNUSED(unused); } 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, PK_AuthenticatedKeyAgreementDomain &d, double timeTotal, bool pc=false) { LC_RNG rng(time(NULL)); 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(rng, priv, pub); OutputResultOperations(name, "Key-Pair Generation", pc, i, timeTaken); }
void BenchMarkSigning(const char *name, PK_Signer &key, double timeTotal, bool pc=false) { unsigned int len = 16; LC_RNG rng(time(NULL)); SecByteBlock message(len), signature(key.SignatureLength()); rng.GetBlock(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(rng, message, len, signature); OutputResultOperations(name, "Signature", pc, i, timeTaken); }
void BenchMarkEncryption(const char *name, PK_Encryptor &key, double timeTotal, bool pc=false) { unsigned int len = 16; LC_RNG rng(time(NULL)); SecByteBlock plaintext(len), ciphertext(key.CipherTextLength(len)); rng.GetBlock(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(rng, plaintext, len, ciphertext); OutputResultOperations(name, "Encryption", pc, i, timeTaken); }
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); const 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 BenchMarkKeyGen(const char *name, AuthenticatedKeyAgreementDomain &d, double timeTotal, bool pc=false) { SecByteBlock priv(d.EphemeralPrivateKeyLength()), pub(d.EphemeralPublicKeyLength()); const 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()); const 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 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); const 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 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); const 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 BenchMarkVerification(const char *name, const PK_Signer &priv, PK_Verifier &pub, double timeTotal, bool pc=false) { unsigned int len = 16; LC_RNG rng((word32)time(NULL)); AlignedSecByteBlock message(len), signature(pub.SignatureLength()); rng.GenerateBlock(message, len); priv.SignMessage(rng, 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 BenchMarkAgreement(const char *name, AuthenticatedKeyAgreementDomain &d, double timeTotal, bool pc=false) { LC_RNG rng((word32)time(NULL)); 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(rng, spriv1, spub1); d.GenerateStaticKeyPair(rng, spriv2, spub2); d.GenerateEphemeralKeyPair(rng, epriv1, epub1); d.GenerateEphemeralKeyPair(rng, 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); }