-
Notifications
You must be signed in to change notification settings - Fork 30
/
main.cpp
105 lines (76 loc) · 2.32 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* This file is part of the BSGS distribution (https://github.com/JeanLucPons/BSGS).
* Copyright (c) 2020 Jean Luc PONS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Timer.h"
#include "BSGS.h"
#include "SECPK1/SECP256k1.h"
#include <fstream>
#include <string>
#include <string.h>
#include <stdexcept>
#define RELEASE "1.1"
using namespace std;
// ------------------------------------------------------------------------------------------
void printUsage() {
printf("BSGS [-v] [-t nbThread] inFile\n");
printf(" -v: Print version\n");
printf(" -t nbThread: Secify number of thread\n");
printf(" inFile: intput configuration file\n");
exit(0);
}
// ------------------------------------------------------------------------------------------
int getInt(string name,char *v) {
int r;
try {
r = std::stoi(string(v));
} catch(std::invalid_argument&) {
printf("Invalid %s argument, number expected\n",name.c_str());
exit(-1);
}
return r;
}
// ------------------------------------------------------------------------------------------
int main(int argc, char* argv[]) {
// Global Init
Timer::Init();
// Init SecpK1
Secp256K1 *secp = new Secp256K1();
secp->Init();
int a = 1;
int nbCPUThread = Timer::getCoreNumber();
string configFile = "";
while (a < argc) {
if(strcmp(argv[a], "-t") == 0) {
a++;
nbCPUThread = getInt("nbCPUThread",argv[a]);
a++;
} else if (strcmp(argv[a], "-h") == 0) {
printUsage();
} else if (a == argc - 1) {
configFile = string(argv[a]);
a++;
} else {
printf("Unexpected %s argument\n",argv[a]);
exit(-1);
}
}
printf("BSGS v" RELEASE "\n");
BSGS *v = new BSGS(secp);
if( !v->ParseConfigFile(configFile) )
exit(-1);
v->Run(nbCPUThread);
return 0;
}