-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·125 lines (108 loc) · 4.55 KB
/
main.cpp
File metadata and controls
executable file
·125 lines (108 loc) · 4.55 KB
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
#include <stdlib.h>
#include "ProtocolParty.h"
#include <smmintrin.h>
#include <inttypes.h>
#include <stdio.h>
#include <x86intrin.h>
#ifdef __CUDA_ARCH__
#include "cudaGemm.h"
#endif
/**
* The main structure of our protocol is as follows:
* 1. Initialization Phase: Initialize some global variables (parties, field, circuit, etc).
* 2. Preparation Phase: Prepare enough random double-sharings: a random double-sharing is a pair of
* two sharings of the same random value, one with degree t, and one with degree 2t. One such double-
* sharing is consumed for multiplying two values. We also consume double-sharings for input gates
* and for random gates (this is slightly wasteful, but we assume that the number of multiplication
* gates is dominating the number of input and random gates).
* 3. Input Phase: For each input gate, reconstruct one of the random sharings towards the input party.
* Then, all input parties broadcast a vector of correction values, namely the differences of the inputs
* they actually choose and the random values they got. These correction values are then added on
* the random sharings.
* 4. Computation Phase: Walk through the circuit, and evaluate as many gates as possible in parallel.
* Addition gates and random gates can be evaluated locally (random gates consume a random double-
* sharing). Multiplication gates are more involved: First, every party computes local product of the
* respective shares; these shares form de facto a 2t-sharing of the product. Then, from this sharing,
* a degree-2t sharing of a random value is subtracted, the difference is reconstructed and added on
* the degree-t sharing of the same random value.
* 5. Output Phase: The value of each output gate is reconstructed towards the corresponding party.
* @param argc
* @param argv[1] = id of parties (1,...,N)
* @param argv[2] = N: number of parties
* @param argv[3] = path of inputs file
* @param argv[4] = path of output file
* @param argv[5] = path of circuit file
* @param argv[6] = fieldType
* @return
*/
int main(int argc, char* argv[])
{
CmdParser parser;
auto parameters = parser.parseArguments("", argc, argv);
int times = stoi(parser.getValueByKey(parameters, "internalIterationsNumber"));
string fieldType = parser.getValueByKey(parameters, "fieldType");
cout<<"fieldType = "<<fieldType<<endl;
if(fieldType.compare("ZpMersenne31") == 0)
{
ProtocolParty<ZpMersenneIntElement> protocol(argc, argv);
auto t1 = high_resolution_clock::now();
protocol.run();
auto t2 = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(t2-t1).count();
cout << "time in milliseconds for " << times << " runs: " << duration << endl;
cout << "end main" << '\n';
}
else if(fieldType.compare("ZpMersenne61") == 0)
{
ProtocolParty<ZpMersenneLongElement> protocol(argc, argv);
auto t1 = high_resolution_clock::now();
protocol.run();
auto t2 = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(t2-t1).count();
cout << "time in milliseconds for " << times << " runs: " << duration << endl;
cout << "end main" << '\n';
}
// else if(fieldType.compare("ZpKaratsuba") == 0) {
// ProtocolParty<ZpKaratsubaElement> protocol(argc, argv);
// auto t1 = high_resolution_clock::now();
// protocol.run();
//
// auto t2 = high_resolution_clock::now();
//
// auto duration = duration_cast<milliseconds>(t2 - t1).count();
// cout << "time in milliseconds for " << times << " runs: " << duration << endl;
// cout << "end main" << '\n';
// }
//
//
//
// else if(fieldType.compare("GF2m") == 0)
// {
// ProtocolParty<GF2E> protocol(argc, argv);
// auto t1 = high_resolution_clock::now();
// protocol.run();
//
// auto t2 = high_resolution_clock::now();
//
// auto duration = duration_cast<milliseconds>(t2-t1).count();
// cout << "time in milliseconds for " << times << " runs: " << duration << endl;
// cout << "end main" << '\n';
// }
//
// else if(fieldType.compare("Zp") == 0)
// {
// ProtocolParty<ZZ_p> protocol(argc, argv);
//
// auto t1 = high_resolution_clock::now();
//
// protocol.run();
//
// auto t2 = high_resolution_clock::now();
//
// auto duration = duration_cast<milliseconds>(t2-t1).count();
// cout << "time in milliseconds for " << times << " runs: " << duration << endl;
// cout << "end main" << '\n';
//
// }
return 0;
}