forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream-fake-mascot-triples.cpp
71 lines (65 loc) · 1.61 KB
/
stream-fake-mascot-triples.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
/*
* stream-fake-mascot-triples.cpp
*
*/
#include "Protocols/Share.h"
#include "Math/gfpvar.h"
#include "Tools/benchmarking.h"
#include "Math/Setup.hpp"
#include "Protocols/fake-stuff.hpp"
class Info
{
public:
int thread_num;
int nplayers;
gfpvar key;
pthread_t thread;
};
void* run(void* arg)
{
auto& info = *(Info*) arg;
SeededPRNG G;
Files<Share<gfpvar>> files(info.nplayers, info.key, PREP_DIR, DATA_TRIPLE, G, info.thread_num);
int count = 0;
while (true)
{
for (int i = 0; i < 100000; i++)
{
gfpvar triple[3];
for (int i = 0; i < 2; i++)
triple[i].randomize(G);
triple[2] = triple[0] * triple[1];
for (int i = 0; i < 3; i++)
files.output_shares(triple[i]);
count++;
}
// take a break to make them wait
sleep(1);
}
cerr << "failed after " << count << endl;
return 0;
}
int main()
{
insecure_fake();
typedef Share<gfpvar> T;
int nplayers = 2;
int lgp = 128;
string prep_data_prefix = PREP_DIR;
gfpvar::generate_setup<T>(prep_data_prefix, nplayers, lgp);
T::mac_key_type keyp;
SeededPRNG G;
generate_mac_keys<T>(keyp, nplayers, prep_data_prefix, G);
int nthreads = 3;
OnlineOptions::singleton.file_prep_per_thread = true;
vector<Info> infos(3);
for (int i = 0; i < nthreads; i++)
{
auto& info = infos[i];
info.thread_num = i;
info.nplayers = nplayers;
info.key = keyp;
pthread_create(&info.thread, 0, run, &info);
}
pthread_join(infos[0].thread, 0);
}