-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemp-agmpc.patch
206 lines (199 loc) · 5.9 KB
/
emp-agmpc.patch
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 359326b..4c8436e 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,5 +11,5 @@ INCLUDE_DIRECTORIES(${EMP-OT_INCLUDE_DIRS})
install(FILES cmake/emp-agmpc-config.cmake DESTINATION cmake/)
install(DIRECTORY emp-agmpc DESTINATION include/)
-ENABLE_TESTING()
-ADD_SUBDIRECTORY(test)
+# ENABLE_TESTING()
+# ADD_SUBDIRECTORY(test)
diff --git a/emp-agmpc/fpremp.h b/emp-agmpc/fpremp.h
index 4a0c44d..4ea08f0 100644
--- a/emp-agmpc/fpremp.h
+++ b/emp-agmpc/fpremp.h
@@ -98,7 +98,7 @@ class FpreMP { public:
joinNclean(res);
for(int k = 0; k < length*bucket_size; ++k) {
s[0][k] = (tr[3*k] and tr[3*k+1]);
- for(int i = 1; i <= nP; ++i)
+ for(int i = 1; i <= nP; ++i)
if (i != party) {
s[0][k] = (s[0][k] != s[i][k]);
}
@@ -112,15 +112,18 @@ class FpreMP { public:
for(int i = 1; i <= nP; ++i) for(int j = 1; j<= nP; ++j) if( (i < j) and (i == party or j == party) ) {
int party2 = i + j - party;
res.push_back(pool->enqueue([this, e, length, bucket_size, party2]() {
- io->send_data(party2, e, length*bucket_size);
+ for (int k = 0; k < length*bucket_size; ++k) {
+ io->send_data(party2, e+k, 1);
+ }
io->flush(party2);
}));
res.push_back(pool->enqueue([this, tKEY, length, bucket_size, party2]() {
bool * tmp = new bool[length*bucket_size];
- io->recv_data(party2, tmp, length*bucket_size);
- for(int k = 0; k < length*bucket_size; ++k) {
- if(tmp[k])
- tKEY[party2][3*k+2] = tKEY[party2][3*k+2] ^ Delta;
+ for (int k = 0; k < length * bucket_size; ++k) {
+ io->recv_data(party2, tmp+k, 1);
+ if(tmp[k]) {
+ tKEY[party2][3*k+2] = tKEY[party2][3*k+2] ^ Delta;
+ }
}
delete[] tmp;
}));
@@ -128,7 +131,7 @@ class FpreMP { public:
joinNclean(res);
#ifdef __debug
check_MAC(io, tMAC, tKEY, tr, Delta, length*bucket_size*3, party);
-#endif
+#endif
auto ret = abit->check(tMAC, tKEY, tr, length*bucket_size*3 + 3*ssp);
ret.get();
//check compute phi
@@ -227,8 +230,8 @@ class FpreMP { public:
xorBlocks_arr(X[1], X[1], X[i], ssp);
for(int i = 0; i < ssp; ++i)X[2][i] = zero_block;
if(!cmpBlock(X[1], X[2], ssp)) error("AND check");
-
- //land -> and
+
+ //land -> and
block S = sampleRandom<nP>(io, &prg, pool, party);
int * ind = new int[length*bucket_size];
@@ -248,7 +251,7 @@ class FpreMP { public:
location[index] = tmp;
}
delete[] ind;
-
+
for(int i = 0; i < length; ++i) {
for(int j = 0; j < bucket_size-1; ++j)
d[party][(bucket_size-1)*i+j] = tr[3*location[i*bucket_size]+1] != tr[3*location[i*bucket_size+1+j]+1];
@@ -284,9 +287,9 @@ class FpreMP { public:
for(int i = 2; i <= nP; ++i)
for(int j = 0; j < (bucket_size-1)*length; ++j)
d[1][j] = d[1][j]!=d[i][j];
-
+
for(int i = 0; i < length; ++i) {
- for(int j = 1; j <= nP; ++j)if (j!= party) {
+ for(int j = 1; j <= nP; ++j)if (j!= party) {
for(int k = 1; k < bucket_size; ++k)
if(d[1][(bucket_size-1)*i+k-1]) {
MAC[j][3*i+2] = MAC[j][3*i+2] ^ tMAC[j][3*location[i*bucket_size+k]];
@@ -298,12 +301,12 @@ class FpreMP { public:
r[3*i+2] = r[3*i+2] != tr[3*location[i*bucket_size+k]];
}
}
-
+
#ifdef __debug
check_MAC(io, MAC, KEY, r, Delta, length*3, party);
check_correctness(io, r, length, party);
#endif
-
+
// ret.get();
delete[] tr;
delete[] phi;
@@ -360,7 +363,7 @@ class FpreMP { public:
uint8_t res = LSB(bH);
tmp >>= (r[3*i+1]*2+r[3*i]);
return (tmp&0x1) != (res&0x1);
- }
+ }
void check_MAC_phi(block * MAC[nP+1], block * KEY[nP+1], block * phi, bool * r, int length) {
block * tmp = new block[length];
@@ -383,7 +386,7 @@ class FpreMP { public:
delete[] tmp;
delete[] tD;
if(party == 1)
- cerr<<"check_MAC_phi pass!\n"<<flush;
+ cerr<<"check_MAC_phi pass!\n"<<flush;
}
@@ -400,7 +403,7 @@ class FpreMP { public:
for(int i = 0; i < l; ++i)
if(!cmpBlock(&z, &tmp1[i], 1))
error("check sum zero failed!");
- cerr<<"check zero sum pass!\n"<<flush;
+ cerr<<"check zero sum pass!\n"<<flush;
delete[] tmp1;
delete[] tmp2;
} else {
diff --git a/emp-agmpc/netmp.h b/emp-agmpc/netmp.h
index 3811afc..8510018 100644
--- a/emp-agmpc/netmp.h
+++ b/emp-agmpc/netmp.h
@@ -22,7 +22,7 @@ class NetIOMP { public:
usleep(1000);
ios[j] = new NetIO(IP[j], port+2*(i), true);
#endif
- ios[j]->set_nodelay();
+ ios[j]->set_nodelay();
#ifdef LOCALHOST
usleep(1000);
@@ -31,7 +31,7 @@ class NetIOMP { public:
usleep(1000);
ios2[j] = new NetIO(nullptr, port+2*(j)+1, true);
#endif
- ios2[j]->set_nodelay();
+ ios2[j]->set_nodelay();
} else if(j == party) {
#ifdef LOCALHOST
usleep(1000);
@@ -40,7 +40,7 @@ class NetIOMP { public:
usleep(1000);
ios[i] = new NetIO(nullptr, port+2*(i), true);
#endif
- ios[i]->set_nodelay();
+ ios[i]->set_nodelay();
#ifdef LOCALHOST
usleep(1000);
@@ -49,10 +49,41 @@ class NetIOMP { public:
usleep(1000);
ios2[i] = new NetIO(IP[i], port+2*(j)+1, true);
#endif
- ios2[i]->set_nodelay();
+ ios2[i]->set_nodelay();
}
}
}
+
+ NetIOMP(const char* serverIP, int party, int port) {
+ this->party = party;
+ memset(sent, false, nP+1);
+ for (int i = 1; i <= nP; ++i) {
+ for (int j = 1; j <= nP; ++j) {
+ if(i < j) {
+ if(i == party) {
+ // client party, will be party 1
+ usleep(1000);
+ ios[j] = new NetIO(serverIP, port, true);
+ ios[j]->set_nodelay();
+
+ usleep(1000);
+ ios2[j] = new NetIO(serverIP, port + 1, true);
+ ios2[j]->set_nodelay();
+ } else if (j == party) {
+ // server party, will be party 2
+ usleep(1000);
+ ios[i] = new NetIO(nullptr, port, true);
+ ios[i]->set_nodelay();
+
+ usleep(1000);
+ ios2[i] = new NetIO(nullptr, port + 1, true);
+ ios2[i]->set_nodelay();
+ }
+ }
+ }
+ }
+ }
+
int64_t count() {
int64_t res = 0;
for(int i = 1; i <= nP; ++i) if(i != party){