#include "crypto/Signature.h" #include #include #include #include typedef std::function KeyGenerator; template void benchmark(std::size_t count, std::size_t public_key_size, std::size_t private_key_size, std::size_t signature_size, KeyGenerator generator) { typedef std::chrono::time_point TimePoint; CryptoPP::AutoSeededRandomPool rng; uint8_t private_key[private_key_size] = {}; uint8_t public_key[public_key_size] = {}; generator(rng, private_key, public_key); Verifier verifier(public_key); Signer signer(private_key); uint8_t message[512] = {}; uint8_t output[signature_size] = {}; std::chrono::nanoseconds sign_duration(0); std::chrono::nanoseconds verify_duration(0); for(std::size_t i = 0; i < count; ++i) { rng.GenerateBlock(message, 512); TimePoint begin1 = std::chrono::high_resolution_clock::now(); signer.Sign(rng, message, 512, output); TimePoint end1 = std::chrono::high_resolution_clock::now(); sign_duration += std::chrono::duration_cast(end1 - begin1); TimePoint begin2 = std::chrono::high_resolution_clock::now(); verifier.Verify(message, 512, output); TimePoint end2 = std::chrono::high_resolution_clock::now(); verify_duration += std::chrono::duration_cast(end2 - begin2); } std::cout << "Conducted " << count << " experiments." << std::endl; std::cout << "Total sign time: " << std::chrono::duration_cast(sign_duration).count() << std::endl; std::cout << "Total verify time: " << std::chrono::duration_cast(verify_duration).count() << std::endl; } int main() { using namespace i2p::crypto; std::cout << "--------DSA---------" << std::endl; benchmark( 1000, DSA_PUBLIC_KEY_LENGTH, DSA_PRIVATE_KEY_LENGTH, DSA_SIGNATURE_LENGTH, &CreateDSARandomKeys ); std::cout << "-----ECDSAP256------" << std::endl; benchmark( 1000, ECDSAP256_KEY_LENGTH, ECDSAP256_KEY_LENGTH, 64, &CreateECDSAP256RandomKeys ); std::cout << "-----ECDSAP384------" << std::endl; benchmark( 1000, ECDSAP384_KEY_LENGTH, ECDSAP384_KEY_LENGTH, 64, &CreateECDSAP384RandomKeys ); std::cout << "-----ECDSAP521------" << std::endl; benchmark( 1000, ECDSAP521_KEY_LENGTH, ECDSAP521_KEY_LENGTH, 64, &CreateECDSAP521RandomKeys ); std::cout << "-----EDDSA25519-----" << std::endl; benchmark( 1000, EDDSA25519_PUBLIC_KEY_LENGTH, EDDSA25519_PRIVATE_KEY_LENGTH, 64, &CreateEDDSARandomKeys ); }