X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=src%2Fmain.cpp;h=8c4ec7e52bdeaa17bf7c4915b24a9e4d3df846d1;hb=22aac262156e81085b22bdfcd0cc38950768be9b;hp=ac75df1f1a7ab658ee3163590a67a779f13553cf;hpb=7975d02c6c1ee679a236087e86955c086f1a9a8e;p=crypto_lab3.git diff --git a/src/main.cpp b/src/main.cpp index ac75df1..8c4ec7e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,35 +6,46 @@ * Author: Grégory Burri */ +#include #include using namespace std; #include -#include "Rsa.h" -#include "RsaCrt.h" +#include "Tests.h" const uint KEY_SIZE_BITS = 1024; const uint RSA_PUBLIC_EXPONENT = 65537; +void printUsage(const string& progName) +{ + cout << "Usage: " << progName << " " << endl; + cout << " can be one of the following:" << endl; + cout << " * tests: Do some tests for RSA and RSA-CRT" << endl; + cout << " * tests-with-shamirs-trick: Do some tests for RSA-CRT with Shamir's trick" << endl; + cout << " * time-measures: Compute the ratio between RSA and RSA-CRT" << endl; + cout << " * attack: Simulate the Boneh-DeMillo-Lipton attack against RSA-CRT" << endl; + cout << " * attack-fixed: Try the attack with the Shamir's trick version" << endl; +} + int main(int argc, char** argv) { vector args; for (int i = 0; i < argc; i++) args.push_back(string(argv[i])); - const auto& keys = Rsa::generateRSAKeys(RSA_PUBLIC_EXPONENT, KEY_SIZE_BITS); - const auto& kPub = keys.first; - const auto& kPriv = keys.second; - - mpz_class message(42); - mpz_class signature = Rsa::sign(message, kPriv); - - mpz_class message2(42); - cout << "verify: " << Rsa::verifySignature(message2, signature, kPub) << endl; - - mpz_class message3(43); - cout << "verify: " << Rsa::verifySignature(message3, signature, kPub) << endl; + if (args.size() >= 2 && args[1] == "tests") + Tests(KEY_SIZE_BITS, RSA_PUBLIC_EXPONENT).runTests(); + else if (args.size() >= 2 && args[1] == "tests-with-shamirs-trick") + Tests(KEY_SIZE_BITS, RSA_PUBLIC_EXPONENT).runTestsWithShamirsTrick(); + else if (args.size() >= 2 && args[1] == "time-measures") + Tests(KEY_SIZE_BITS, RSA_PUBLIC_EXPONENT).runTimeMeasures(); + else if (args.size() >= 2 && args[1] == "attack") + Tests(KEY_SIZE_BITS, RSA_PUBLIC_EXPONENT).doAttack(); + else if (args.size() >= 2 && args[1] == "attack-fixed") + Tests(KEY_SIZE_BITS, RSA_PUBLIC_EXPONENT).doAttackFixed(); + else + printUsage(args[0]); return 0; }