Cleaning.
[crypto_lab3.git] / src / main.cpp
1 /**
2 * ICR - Labo 3.
3 * It uses GMPxx lib and C++11.
4 * It needs the RNG file "/dev/urandom".
5 *
6 * Author: Grégory Burri
7 */
8
9 #include <vector>
10 #include <iostream>
11 using namespace std;
12
13 #include <gmpxx.h>
14
15 #include "Tests.h"
16
17 const uint KEY_SIZE_BITS = 1024;
18 const uint RSA_PUBLIC_EXPONENT = 65537;
19
20 void printUsage(const string& progName)
21 {
22 cout << "Usage: " << progName << " <command>" << endl;
23 cout << " <command> can be one of the following:" << endl;
24 cout << " * tests: Do some tests for RSA and RSA-CRT" << endl;
25 cout << " * tests-with-shamirs-trick: Do some tests for RSA-CRT with Shamir's trick" << endl;
26 cout << " * time-measures: Compute the ratio between RSA and RSA-CRT" << endl;
27 cout << " * attack: Simulate the Boneh-DeMillo-Lipton attack against RSA-CRT" << endl;
28 cout << " * attack-fixed: Try the attack with the Shamir's trick version" << endl;
29 }
30
31 int main(int argc, char** argv)
32 {
33 vector<string> args;
34 for (int i = 0; i < argc; i++)
35 args.push_back(string(argv[i]));
36
37 if (args.size() >= 2 && args[1] == "tests")
38 Tests(KEY_SIZE_BITS, RSA_PUBLIC_EXPONENT).runTests();
39 else if (args.size() >= 2 && args[1] == "tests-with-shamirs-trick")
40 Tests(KEY_SIZE_BITS, RSA_PUBLIC_EXPONENT).runTestsWithShamirsTrick();
41 else if (args.size() >= 2 && args[1] == "time-measures")
42 Tests(KEY_SIZE_BITS, RSA_PUBLIC_EXPONENT).runTimeMeasures();
43 else if (args.size() >= 2 && args[1] == "attack")
44 Tests(KEY_SIZE_BITS, RSA_PUBLIC_EXPONENT).doAttack();
45 else if (args.size() >= 2 && args[1] == "attack-fixed")
46 Tests(KEY_SIZE_BITS, RSA_PUBLIC_EXPONENT).doAttackFixed();
47 else
48 printUsage(args[0]);
49
50 return 0;
51 }