-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2ecdsa.cpp
140 lines (90 loc) · 3.31 KB
/
2ecdsa.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
Notation follows this logic:
P1Key : Party 1's share of the key
P2Key : Party 2's share of the key
P12Key : full key combined by Party 1
P21Key : full key combined by Party 2 */
#include "2ecdsa.h"
int main(int argc, char* argv[])
{
int n_sig = 10;
int n_key = 10;
if (argc >= 3) {
n_key = stoi(argv[1]);
n_sig = stoi(argv[2]);
}
else
{
cout << "Not enough arguments given, using the ones by default" << endl;
}
srand(time(NULL));
double time_off = 0, time_on = 0, time_gen = 0, time_MtA = 0, elapsed_time;
clock_t start, end;
cout << "Generating " << n_key << " key(s), and signing " << n_sig << " message(s) with each key" << endl;
for(int z = 0; z < n_key; z++)
{
vector<Fpoint> comms, m, s, s1, s2, a, b, P2EphKeysk, rands, rcoords, msgs;
vector<ECpoint> P12EphKeyPk, P1EphKeyPk, P2EphKeyPk, P21EphKeyPk, Z;
vector<KeyPair> P1EphKey, P2EphKey;
vector<string> messages;
vector<unsigned char*> P1proofs, P2proofs;
KeyPair P1Key, P2Key;
NIZKP P1ni, P2ni;
ECpoint KeyPk, P12KeyPk, P21KeyPk;
Commit cm;
for(int i = 0; i<n_sig; i++)
{
Fpoint random;
for (int j = 0; j < 32; j++)
{
random.m[j] = (unsigned char)rand();
}
m.push_back(random);
}
start = clock();
P1KeyGenPass1(&P1Key, &P1ni, &cm);
P2KeyGenPass1(&P2Key, &P2ni);
P1KeyGenPass2(&P12KeyPk, P2ni.proof, P1Key.Pk, P2Key.Pk);
P2KeyGenPass2(&P21KeyPk, P2Key, P1ni.proof, P1Key.Pk, cm.commitment, cm.rd, cm.message);
end = clock();
elapsed_time = double(end-start)/CLOCKS_PER_SEC;
time_gen += elapsed_time;
start = clock();
P1SignPass1(n_sig, P1EphKey, P1proofs, comms, messages, rands, P1EphKeyPk);
P2SignPass1(n_sig, P2EphKey, P2proofs, P2EphKeyPk, P2EphKeysk);
P1SignPass2(n_sig, P1EphKey, P12EphKeyPk, P2EphKeyPk, P2proofs, rcoords);
P2SignPass2(n_sig, P2EphKey, P21EphKeyPk, P1EphKeyPk, P1proofs, comms, messages, rands);
end = clock();
elapsed_time = double(end-start)/CLOCKS_PER_SEC;
time_off += elapsed_time;
//Note not timing MtA
MtA(n_sig, P1Key.sk, P2EphKeysk, a, b);
start = clock();
P1MtA(n_sig, a, Z);
P2MtA(n_sig, b, Z, P2EphKeysk, P1Key.Pk);
end = clock();
elapsed_time = double(end-start)/CLOCKS_PER_SEC;
time_MtA += elapsed_time;
start = clock();
P2SignPass3(n_sig, m, s2, b, P21EphKeyPk, P2EphKey, P2Key);
P1SignPass3(n_sig, s, s2, a, P12EphKeyPk, P1EphKey);
Verify(P12KeyPk, m, rcoords, s);
end = clock();
elapsed_time = double(end-start)/CLOCKS_PER_SEC;
time_on += elapsed_time;
for (auto it = P1proofs.begin(); it != P1proofs.end(); ++it)
{
delete *it;
}
for (auto it = P2proofs.begin(); it != P2proofs.end(); ++it)
{
delete *it;
}
}
cout << "All siganture were valid" << endl;
cout << "Runtimes in second:" << endl;
cout << "Average key generation time (i.e. time needed for one key generation) :" << time_gen/n_key << endl;
cout << "Average signature offline time (i.e. offline time needed for one signature excluding MtA) :" << (time_off + time_MtA)/(n_key*n_sig) << endl;
cout << "Average signature online time (i.e. online time needed for one signature) :" << time_on/(n_key*n_sig) << endl;
return 0;
}