X-Git-Url: http://git.euphorik.ch/?p=crypto_lab3.git;a=blobdiff_plain;f=src%2Fmain.cpp;h=03d11737f596ce50d7aced80fce1c7441c7818ab;hp=9324bfc02d593ecb31faa926ba213035f809aa44;hb=fb173a9728e915fc7b3f99bc41f55034757105df;hpb=91989c2627abc2cdf511f17169e4f862dc55e838 diff --git a/src/main.cpp b/src/main.cpp index 9324bfc..03d1173 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,81 +6,20 @@ * Author: Grégory Burri */ +#include #include using namespace std; #include -#include "Utils.h" -#include "Rand.h" -#include "Rsa.h" -#include "RsaStd.h" -#include "RsaCrt.h" +#include "Tests.h" const uint KEY_SIZE_BITS = 1024; const uint RSA_PUBLIC_EXPONENT = 65537; -bool testRsaStandard() +void printUsage(const string& progName) { - const auto& keys = RsaStd::generateRSAKeys(RSA_PUBLIC_EXPONENT, KEY_SIZE_BITS); - const auto& kPub = keys.first; - const auto& kPriv = keys.second; - - mpz_class message = Rand::randSize(KEY_SIZE_BITS / 2); - mpz_class signature = RsaStd::sign(message, kPriv); - - return Rsa::verifySignature(message, signature, kPub) && !Rsa::verifySignature(message + 1, signature, kPub); -} - -bool testRsaCrt() -{ - const auto& keys = RsaCrt::generateRSAKeys(RSA_PUBLIC_EXPONENT, KEY_SIZE_BITS); - const auto& kPub = keys.first; - const auto& kPriv = keys.second; - - mpz_class message = Rand::randSize(KEY_SIZE_BITS / 2); - mpz_class signature = RsaCrt::sign(message, kPriv); - - return Rsa::verifySignature(message, signature, kPub) && !Rsa::verifySignature(message + 1, signature, kPub); -} - -int timeSignRsaStd(int N) -{ - Timer timer; - const auto& keys = RsaStd::generateRSAKeys(RSA_PUBLIC_EXPONENT, KEY_SIZE_BITS); - - for (int i = 0; i < N; i++) - { - mpz_class message = Rand::randSize(KEY_SIZE_BITS / 2); - RsaStd::sign(message, keys.second); - } - - return timer.ms(); -} - -int timeSignRsaCRT(int N) -{ - Timer timer; - const auto& keys = RsaCrt::generateRSAKeys(RSA_PUBLIC_EXPONENT, KEY_SIZE_BITS); - - for (int i = 0; i < N; i++) - { - mpz_class message = Rand::randSize(KEY_SIZE_BITS / 2); - RsaCrt::sign(message, keys.second); - } - - return timer.ms(); -} - -void measuresRsaDurations() -{ - const int N = 10000; - int timeRsaStd = timeSignRsaStd(N); - int timeRsaCRT = timeSignRsaCRT(N); - - cout << N << " x RSA standard: " << timeRsaStd << " ms" << endl; - cout << N << " x RSA CRT: " << timeRsaCRT << " ms" << endl; - cout << "Speedup: " << (double(timeRsaStd) / double(timeRsaCRT)) << endl; + cout << "Usage: " << progName << " [tests|time-measures]" << endl; } int main(int argc, char** argv) @@ -89,13 +28,12 @@ int main(int argc, char** argv) for (int i = 0; i < argc; i++) args.push_back(string(argv[i])); - if (!testRsaStandard()) - cout << "RSA standard failed!" << endl; - - if (!testRsaCrt()) - cout << "RSA CRT failed!" << endl; - - measuresRsaDurations(); + if (args.size() >= 2 && args[1] == "tests") + Tests(KEY_SIZE_BITS, RSA_PUBLIC_EXPONENT).runTests(); + else if (args.size() >= 2 && args[1] == "time-measures") + Tests(KEY_SIZE_BITS, RSA_PUBLIC_EXPONENT).runTimeMeasures(); + else + printUsage(args[0]); return 0; }