@@ -118,76 +118,82 @@ uint8_t* boolshare::get_clear_value_ptr() {
118
118
uint32_t nvals = m_ccirc->GetNumVals (m_ngateids[0 ]);
119
119
uint32_t bytelen = ceil_divide (m_ngateids.size (), 8 );
120
120
121
- out = (uint8_t *) calloc (ceil_divide (m_ngateids.size (), 8 ) * nvals, sizeof (uint8_t ));
121
+ out = (uint8_t *)calloc (ceil_divide (m_ngateids.size (), 8 ) * nvals, sizeof (uint8_t ));
122
122
123
123
for (uint32_t i = 0 , ibytes; i < m_ngateids.size (); i++) {
124
124
assert (nvals == m_ccirc->GetNumVals (m_ngateids[i]));
125
125
gatevals = m_ccirc->GetOutputGateValue (m_ngateids[i]);
126
126
127
- ibytes = i / 8 ;
128
- for (uint32_t j = 0 ; j < nvals; j++) {
129
- out[j * bytelen + ibytes] += (((gatevals[j / 64 ] >> (j % 64 )) & 0x01 ) << (i & 0x07 ));
127
+ // only write sth if there are values (output might not be for this party)
128
+ if (gatevals != nullptr ) {
129
+ ibytes = i / 8 ;
130
+ for (uint32_t j = 0 ; j < nvals; j++) {
131
+ out[j * bytelen + ibytes] += (((gatevals[j / 64 ] >> (j % 64 )) & 0x01 ) << (i & 0x07 ));
132
+ }
130
133
}
131
134
}
132
135
return out;
133
136
}
134
137
135
-
136
138
// TODO This method will only work up to a bitlength of 32
137
- void boolshare::get_clear_value_vec (uint32_t ** vec, uint32_t * bitlen, uint32_t * nvals) {
139
+ void boolshare::get_clear_value_vec (uint32_t ** vec, uint32_t * bitlen, uint32_t * nvals) {
138
140
assert (m_ngateids.size () <= sizeof (uint32_t ) * 8 );
139
141
UGATE_T* outvalptr;
140
142
uint32_t gnvals;
141
143
142
- *nvals = 1 ;
144
+ *nvals = 0 ;
143
145
*nvals = m_ccirc->GetOutputGateValue (m_ngateids[0 ], outvalptr);
144
- *vec = (uint32_t *) calloc (*nvals, sizeof (uint32_t ));
145
-
146
- for (uint32_t j = 0 ; j < *nvals; j++) {
147
- (*vec)[j] = (outvalptr[j / 64 ] >> (j % 64 )) & 0x01 ;
148
- }
149
146
150
- for ( uint32_t i = 1 ; i < m_ngateids. size (); i++) {
151
- gnvals = m_ccirc-> GetOutputGateValue (m_ngateids[i], outvalptr);
152
- assert (*nvals == gnvals );
147
+ // only continue if there are values (output might not be for this party)
148
+ if (*nvals > 0 ) {
149
+ *vec = ( uint32_t *) calloc (*nvals, sizeof ( uint32_t ) );
153
150
154
151
for (uint32_t j = 0 ; j < *nvals; j++) {
155
- (*vec)[j] = (*vec)[j] + ((( outvalptr[j / 64 ] >> (j % 64 )) & 0x01 ) << i) ;
152
+ (*vec)[j] = (outvalptr[j / 64 ] >> (j % 64 )) & 0x01 ;
156
153
}
154
+
155
+ for (uint32_t i = 1 ; i < m_ngateids.size (); i++) {
156
+ gnvals = m_ccirc->GetOutputGateValue (m_ngateids[i], outvalptr);
157
+ assert (*nvals == gnvals); // check that all wires have same nvals
158
+
159
+ for (uint32_t j = 0 ; j < *nvals; j++) {
160
+ (*vec)[j] = (*vec)[j] + (((outvalptr[j / 64 ] >> (j % 64 )) & 0x01 ) << i);
161
+ }
162
+ }
163
+ *bitlen = m_ngateids.size ();
157
164
}
158
- *bitlen = m_ngateids.size ();
159
- // return nvals;
160
165
}
161
166
162
-
163
167
// TODO: copied from 32 bits. Put template in and test later on!
164
168
// TODO This method will only work up to a bitlength of 64
165
- void boolshare::get_clear_value_vec (uint64_t ** vec, uint32_t * bitlen, uint32_t * nvals) {
169
+ void boolshare::get_clear_value_vec (uint64_t ** vec, uint32_t * bitlen, uint32_t * nvals) {
166
170
assert (m_ngateids.size () <= sizeof (uint64_t ) * 8 );
167
171
UGATE_T* outvalptr;
168
172
uint32_t gnvals;
169
173
170
- *nvals = 1 ;
174
+ *nvals = 0 ;
171
175
*nvals = m_ccirc->GetOutputGateValue (m_ngateids[0 ], outvalptr);
172
- *vec = (uint64_t *) calloc (*nvals, sizeof (uint64_t ));
173
-
174
- for (uint32_t j = 0 ; j < *nvals; j++) {
175
- (*vec)[j] = (outvalptr[j / 64 ] >> (j % 64 )) & 0x01 ;
176
- }
177
176
178
- for ( uint32_t i = 1 ; i < m_ngateids. size (); i++) {
179
- gnvals = m_ccirc-> GetOutputGateValue (m_ngateids[i], outvalptr);
180
- assert (*nvals == gnvals );
177
+ // only continue if there are values (output might not be for this party)
178
+ if (*nvals > 0 ) {
179
+ *vec = ( uint64_t *) calloc (*nvals, sizeof ( uint64_t ) );
181
180
182
181
for (uint32_t j = 0 ; j < *nvals; j++) {
183
- (*vec)[j] = (*vec)[j] + (((outvalptr[j / 64 ] >> (j % 64 )) & 0x01 ) << i);
182
+ (*vec)[j] = (outvalptr[j / 64 ] >> (j % 64 )) & 0x01 ;
183
+ }
184
+
185
+ for (uint32_t i = 1 ; i < m_ngateids.size (); i++) {
186
+ gnvals = m_ccirc->GetOutputGateValue (m_ngateids[i], outvalptr);
187
+ assert (*nvals == gnvals); // check that all wires have same nvals
188
+
189
+ for (uint32_t j = 0 ; j < *nvals; j++) {
190
+ (*vec)[j] = (*vec)[j] + (((outvalptr[j / 64 ] >> (j % 64 )) & 0x01 ) << i);
191
+ }
184
192
}
193
+ *bitlen = m_ngateids.size ();
185
194
}
186
- *bitlen = m_ngateids.size ();
187
- // return nvals;
188
195
}
189
196
190
-
191
197
yao_fields* boolshare::get_internal_yao_keys () {
192
198
yao_fields* out;
193
199
uint32_t nvals = m_ccirc->GetNumVals (m_ngateids[0 ]);
@@ -219,35 +225,44 @@ yao_fields* boolshare::get_internal_yao_keys() {
219
225
uint8_t * arithshare::get_clear_value_ptr () {
220
226
UGATE_T* gate_val;
221
227
uint32_t nvals = m_ccirc->GetOutputGateValue (m_ngateids[0 ], gate_val);
222
- uint8_t * out = (uint8_t *) malloc (nvals * sizeof (uint32_t ));
223
- for (uint32_t i = 0 ; i < nvals; i++) {
224
- ((uint32_t *) out)[i] = (uint32_t ) gate_val[i];
228
+ if (nvals > 0 ) {
229
+ uint8_t * out = (uint8_t *)malloc (nvals * sizeof (uint32_t ));
230
+ for (uint32_t i = 0 ; i < nvals; i++) {
231
+ ((uint32_t *)out)[i] = (uint32_t )gate_val[i];
232
+ }
233
+ return out;
234
+ }
235
+ else {
236
+ return nullptr ;
225
237
}
226
- return out;
227
238
}
228
239
229
240
void arithshare::get_clear_value_vec (uint32_t ** vec, uint32_t * bitlen, uint32_t * nvals) {
230
241
// assert(m_ngateids.size() <= sizeof(uint32_t) * 8);
231
242
232
243
UGATE_T* gate_val;
233
244
*nvals = 0 ;
234
- for (uint32_t i = 0 ; i < m_ngateids.size (); i++) {
235
- (*nvals) += m_ccirc->GetOutputGateValue (m_ngateids[i], gate_val);
236
- }
237
- uint32_t sharebytes = ceil_divide (m_ccirc->GetShareBitLen (), 8 );
238
245
239
- // *nvals = m_ccirc->GetOutputGateValue(m_ngateids[0], gate_val);
240
- *vec = (uint32_t *) calloc (*nvals, sizeof (uint32_t ));
246
+ // only continue if there are values (output might not be for this party)
247
+ if (m_ccirc->GetOutputGateValue (m_ngateids[0 ], gate_val) > 0 ) {
248
+ for (uint32_t i = 0 ; i < m_ngateids.size (); i++) {
249
+ (*nvals) += m_ccirc->GetOutputGateValue (m_ngateids[i], gate_val);
250
+ }
251
+ uint32_t sharebytes = ceil_divide (m_ccirc->GetShareBitLen (), 8 );
252
+
253
+ // *nvals = m_ccirc->GetOutputGateValue(m_ngateids[0], gate_val);
254
+ *vec = (uint32_t *)calloc (*nvals, sizeof (uint32_t ));
241
255
242
- for (uint32_t i = 0 , tmpctr=0 , tmpnvals; i < m_ngateids.size (); i++) {
243
- tmpnvals = m_ccirc->GetOutputGateValue (m_ngateids[i], gate_val);
244
- // cout << m_ngateids[i] << " gateval = " << gate_val[0] << ", nvals = " << *nvals << ", sharebitlen = " << m_ccirc->GetShareBitLen() << endl;
245
- for (uint32_t j = 0 ; j < tmpnvals; j++, tmpctr++) {
246
- memcpy ((*vec)+tmpctr, ((uint8_t *) gate_val)+(j*sharebytes), sharebytes);
256
+ for (uint32_t i = 0 , tmpctr = 0 , tmpnvals; i < m_ngateids.size (); i++) {
257
+ tmpnvals = m_ccirc->GetOutputGateValue (m_ngateids[i], gate_val);
258
+ // cout << m_ngateids[i] << " gateval = " << gate_val[0] << ", nvals = " << *nvals << ", sharebitlen = " << m_ccirc->GetShareBitLen() << endl;
259
+ for (uint32_t j = 0 ; j < tmpnvals; j++, tmpctr++) {
260
+ memcpy ((*vec) + tmpctr, ((uint8_t *)gate_val) + (j * sharebytes), sharebytes);
261
+ }
247
262
}
248
- }
249
263
250
- *bitlen = m_ccirc->GetShareBitLen ();
264
+ *bitlen = m_ccirc->GetShareBitLen ();
265
+ }
251
266
}
252
267
253
268
// TODO: copied from 32 bits. Put template in and test later on!
@@ -256,23 +271,26 @@ void arithshare::get_clear_value_vec(uint64_t** vec, uint32_t* bitlen, uint32_t*
256
271
257
272
UGATE_T* gate_val;
258
273
*nvals = 0 ;
259
- for (uint32_t i = 0 ; i < m_ngateids.size (); i++) {
260
- (*nvals) += m_ccirc->GetOutputGateValue (m_ngateids[i], gate_val);
261
- }
262
- uint32_t sharebytes = ceil_divide (m_ccirc->GetShareBitLen (), 8 );
274
+ // only continue if there are values (output might not be for this party)
275
+ if (m_ccirc->GetOutputGateValue (m_ngateids[0 ], gate_val) > 0 ) {
276
+ for (uint32_t i = 0 ; i < m_ngateids.size (); i++) {
277
+ (*nvals) += m_ccirc->GetOutputGateValue (m_ngateids[i], gate_val);
278
+ }
279
+ uint32_t sharebytes = ceil_divide (m_ccirc->GetShareBitLen (), 8 );
263
280
264
- // *nvals = m_ccirc->GetOutputGateValue(m_ngateids[0], gate_val);
265
- *vec = (uint64_t *) calloc (*nvals, sizeof (uint64_t ));
281
+ // *nvals = m_ccirc->GetOutputGateValue(m_ngateids[0], gate_val);
282
+ *vec = (uint64_t *)calloc (*nvals, sizeof (uint64_t ));
266
283
267
- for (uint32_t i = 0 , tmpctr=0 , tmpnvals; i < m_ngateids.size (); i++) {
268
- tmpnvals = m_ccirc->GetOutputGateValue (m_ngateids[i], gate_val);
269
- // cout << m_ngateids[i] << " gateval = " << gate_val[0] << ", nvals = " << *nvals << ", sharebitlen = " << m_ccirc->GetShareBitLen() << endl;
270
- for (uint32_t j = 0 ; j < tmpnvals; j++, tmpctr++) {
271
- memcpy ((*vec)+tmpctr, ((uint8_t *) gate_val)+(j*sharebytes), sharebytes);
284
+ for (uint32_t i = 0 , tmpctr = 0 , tmpnvals; i < m_ngateids.size (); i++) {
285
+ tmpnvals = m_ccirc->GetOutputGateValue (m_ngateids[i], gate_val);
286
+ // cout << m_ngateids[i] << " gateval = " << gate_val[0] << ", nvals = " << *nvals << ", sharebitlen = " << m_ccirc->GetShareBitLen() << endl;
287
+ for (uint32_t j = 0 ; j < tmpnvals; j++, tmpctr++) {
288
+ memcpy ((*vec) + tmpctr, ((uint8_t *)gate_val) + (j * sharebytes), sharebytes);
289
+ }
272
290
}
273
- }
274
291
275
- *bitlen = m_ccirc->GetShareBitLen ();
292
+ *bitlen = m_ccirc->GetShareBitLen ();
293
+ }
276
294
}
277
295
278
296
share* arithshare::get_share_from_wire_id (uint32_t shareid) {
@@ -288,7 +306,3 @@ share* boolshare::get_share_from_wire_id(uint32_t shareid) {
288
306
new_shr->set_wire_id (shareid,get_wire_id (shareid));
289
307
return new_shr;
290
308
}
291
-
292
-
293
-
294
-
0 commit comments