Prechádzať zdrojové kódy

changed some data collection

avadapal 1 rok pred
rodič
commit
8d4c8c2d65

+ 74 - 146
preprocessing/dpfgen.h

@@ -1,9 +1,9 @@
 struct dpfP2
 {
 	__m128i root;
-	__m128i CW[26];
-	uint8_t cwt_L[26];
-	uint8_t cwt_R[26];
+	__m128i CW[30];
+	uint8_t cwt_L[30];
+	uint8_t cwt_R[30];
 	};
 
 void generate_random_targets(uint8_t ** target_share_read, size_t n_threads, bool party, size_t expo)
@@ -44,56 +44,16 @@ struct BlindsCW
   uint8_t cwbit[2];
  };
 
-// void compute_CW_bits(tcp::socket& sout,   __m128i L, __m128i R, uint8_t bit, uint8_t &cwt_L, uint8_t &cwt_R)
-// {
-
-// 	uint8_t advice_L = get_lsb(L) ^ bit;
-// 	uint8_t advice_R = get_lsb(R) ^ bit;
-
-// 	uint8_t advice[2];
-// 	uint8_t cwts[2];	
-
-// 	advice[0] = advice_L;
-// 	advice[1] = advice_R;
-		
-// 	boost::asio::write(sout, boost::asio::buffer(&advice, sizeof(advice)));
-// 	boost::asio::read(sout, boost::asio::buffer(&cwts, sizeof(cwts)));
-		
-// 	cwt_L = cwts[0];
-// 	cwt_R = cwts[1];
-
-// 	cwt_L = cwt_L ^ advice_L ^ 1;
-// 	cwt_R = cwt_R ^ advice_R;	
-// }
+ 
 
-void compute_CW(tcp::socket& sout, tcp::socket& sin, __m128i L, __m128i R, uint8_t bit, __m128i & CW, uint8_t &cwt_L, uint8_t &cwt_R)
+void compute_CW(cw_construction computecw_array, size_t ind, size_t layer,tcp::socket& sout,  __m128i L, __m128i R, uint8_t bit, __m128i & CW, uint8_t &cwt_L, uint8_t &cwt_R)
 {
 
-	cw_construction computecw;
-
- 
- reconstructioncw cwsent, cwrecv;
-	//Communication from P2 
-	read(sin, boost::asio::buffer(&computecw, sizeof(computecw)));
-
-	__m128i rand_b  = computecw.rand_b;
-	__m128i gamma_b = computecw.gamma_b;
-	uint8_t bit_b   = computecw.bit_b;
+ 	reconstructioncw cwsent, cwrecv;
+	__m128i rand_b  = computecw_array.rand_b;		//   computecw.rand_b;
+	__m128i gamma_b = computecw_array.gamma_b;	//   computecw.gamma_b;
+	uint8_t bit_b   = computecw_array.bit_b;		//   computecw.bit_b;
 	
-	#ifdef DEBUG 
-	__m128i rand_b2, gamma_b2;
-	uint8_t bit_b2;
-	read(sin, boost::asio::buffer(&rand_b2, sizeof(rand_b)));
-	read(sin, boost::asio::buffer(&gamma_b2, sizeof(gamma_b)));
-	read(sin, boost::asio::buffer(&bit_b2, sizeof(bit_b)));
-
-	assert(rand_b2[0] == rand_b[0]);
-	assert(rand_b2[1] == rand_b[1]);
-	assert(gamma_b2[0] == gamma_b[0]);
-	assert(gamma_b2[1] == gamma_b[1]);
-	assert(bit_b2 == bit_b);
- #endif
-
 	uint8_t blinded_bit, blinded_bit_read;
 	blinded_bit = bit ^ bit_b;
 
@@ -105,14 +65,13 @@ void compute_CW(tcp::socket& sout, tcp::socket& sin, __m128i L, __m128i R, uint8
 	blinds_sent.blinded_message = blinded_L;
 
 	//exchange blinded shares for OSWAP.
- boost::asio::write(sout, boost::asio::buffer(&blinds_sent, sizeof(BlindsCW)));
+  boost::asio::write(sout, boost::asio::buffer(&blinds_sent, sizeof(BlindsCW)));
 	boost::asio::read(sout, boost::asio::buffer(&blinds_recv, sizeof(BlindsCW)));
 	
 	blinded_bit_read = blinds_recv.blinded_bit;
 	blinded_L_read   =  blinds_recv.blinded_message;
 
-	//__m128i out_ = R ^ gamma_b;//_mm_setzero_si128;
- cwsent.cw = R ^ gamma_b;
+  cwsent.cw = R ^ gamma_b;
 
 	if(bit)
 	{
@@ -123,84 +82,51 @@ void compute_CW(tcp::socket& sout, tcp::socket& sin, __m128i L, __m128i R, uint8
 	  cwsent.cw ^= rand_b;
 	}
 
-
-
-	// uint8_t advice_L = get_lsb(L) ^ bit;
-	// uint8_t advice_R = get_lsb(R) ^ bit;
-
-	// uint8_t advice[2];
-	// // uint8_t cwts[2];	
-
-	// advice[0] = advice_L;
-	// advice[1] = advice_R;
-
-
-	//__m128i out_reconstruction; 
-	
-
- //cwsent.cw = out_; 
+ 
  cwsent.cwbit[0] = get_lsb(L) ^ bit;//advice[0];
  cwsent.cwbit[1] = get_lsb(R) ^ bit;//advice[1];
 
  boost::asio::write(sout, boost::asio::buffer(&cwsent, sizeof(cwsent)));
-	boost::asio::read(sout, boost::asio::buffer(&cwrecv, sizeof(cwrecv)));
-
- // boost::asio::write(sout, boost::asio::buffer(&out_, sizeof(out_)));
-	// boost::asio::read(sout, boost::asio::buffer(&CW, sizeof(CW)));
-	// CW = out_ ^ CW;
-
+ boost::asio::read(sout, boost::asio::buffer(&cwrecv, sizeof(cwrecv)));
  cwrecv.cw ^= cwsent.cw;
  cwrecv.cwbit[0] ^= (cwsent.cwbit[0] ^ 1);
  cwrecv.cwbit[1] ^= (cwsent.cwbit[1]);
  
- // assert(CW[0] == cwrecv.cw[0]);
-	// assert(CW[1] == cwrecv.cw[1]);
-
-	// boost::asio::write(sout, boost::asio::buffer(&advice, sizeof(advice)));
-	// boost::asio::read(sout, boost::asio::buffer(&cwts, sizeof(cwts)));
-		
-	// cwt_L = cwts[0];
-	// cwt_R = cwts[1];
-
-	// cwt_L = cwt_L ^ advice_L ^ 1;
-	// cwt_R = cwt_R ^ advice_R;	
-	
- // assert(cwt_L == cwrecv.cwbit[0]);
- // assert(cwt_R == cwrecv.cwbit[1]);
+ 
  cwt_L = cwrecv.cwbit[0];
  cwt_R = cwrecv.cwbit[1];
  CW = cwrecv.cw;
 
  // The following asserts the correctness of ComputeCW
 	#ifdef DEBUG
-	uint8_t bit_reconstruction; 
-	boost::asio::write(sout, boost::asio::buffer(&bit, sizeof(bit)));
-	boost::asio::read(sout, boost::asio::buffer(&bit_reconstruction, sizeof(bit_reconstruction)));
-	bit_reconstruction = bit ^ bit_reconstruction;
+			uint8_t bit_reconstruction; 
+			boost::asio::write(sout, boost::asio::buffer(&bit, sizeof(bit)));
+			boost::asio::read(sout, boost::asio::buffer(&bit_reconstruction, sizeof(bit_reconstruction)));
+			bit_reconstruction = bit ^ bit_reconstruction;
 
-	__m128i L_reconstruction; 
-	boost::asio::write(sout, boost::asio::buffer(&L, sizeof(L)));
-	boost::asio::read(sout, boost::asio::buffer(&L_reconstruction, sizeof(L_reconstruction)));
-	L_reconstruction = L ^ L_reconstruction;
+			__m128i L_reconstruction; 
+			boost::asio::write(sout, boost::asio::buffer(&L, sizeof(L)));
+			boost::asio::read(sout, boost::asio::buffer(&L_reconstruction, sizeof(L_reconstruction)));
+			L_reconstruction = L ^ L_reconstruction;
 
-	__m128i R_reconstruction; 
-	boost::asio::write(sout, boost::asio::buffer(&R, sizeof(R)));
-	boost::asio::read(sout, boost::asio::buffer(&R_reconstruction, sizeof(R_reconstruction)));
-	R_reconstruction = R ^ R_reconstruction;
+			__m128i R_reconstruction; 
+			boost::asio::write(sout, boost::asio::buffer(&R, sizeof(R)));
+			boost::asio::read(sout, boost::asio::buffer(&R_reconstruction, sizeof(R_reconstruction)));
+			R_reconstruction = R ^ R_reconstruction;
 
-	__m128i CW_debug;
+			__m128i CW_debug;
 
-	if(bit_reconstruction != 0)
-	{
-	 CW_debug = L_reconstruction;
-	}
-	else
-	{
-	 CW_debug = R_reconstruction;
-	}
+			if(bit_reconstruction != 0)
+			{
+			 CW_debug = L_reconstruction;
+			}
+			else
+			{
+			 CW_debug = R_reconstruction;
+			}
 
-	assert(CW_debug[0] == CW[0]);
-	assert(CW_debug[1] == CW[1]);
+			assert(CW_debug[0] == CW[0]);
+			assert(CW_debug[1] == CW[1]);
 	#endif
 }
 
@@ -231,16 +157,17 @@ static inline void traverse(const prgkey_t & prgkey, const node_t & seed,	node_t
  * @param party Party
  * @param socket_no 
  */
-inline void create_dpfs ( size_t db_nitems, const AES_KEY& prgkey,  uint8_t target_share[64], std::vector<socket_t>& socketsPb, std::vector<socket_t>& socketsP2,
-						                    const size_t from, const size_t to, __m128i * output, int8_t * _t, __m128i& final_correction_word, dpfP2 * dpf_instance, 
+inline void create_dpfs ( bool reading,  size_t db_nitems, const AES_KEY& prgkey,  uint8_t target_share[64], std::vector<socket_t>& socketsPb, std::vector<socket_t>& socketsP2,
+						              const size_t from, const size_t to, __m128i * output, int8_t * _t, __m128i& final_correction_word,  
+						              cw_construction computecw_array, dpfP2 * dpf_instance, 
                           bool party, size_t socket_no, size_t ind = 0)
 {
  
- const size_t bits_per_leaf = std::is_same<leaf_t, bool>::value ? 1 : sizeof(leaf_t) * CHAR_BIT;
+ 	const size_t bits_per_leaf = std::is_same<leaf_t, bool>::value ? 1 : sizeof(leaf_t) * CHAR_BIT;
 	const bool  is_packed = (sizeof(leaf_t) < sizeof(node_t));
 	const size_t nodes_per_leaf = is_packed ? 1 : std::ceil(static_cast<double>(bits_per_leaf) / (sizeof(node_t) * CHAR_BIT));
 
- const size_t depth = std::ceil(std::log2(db_nitems));
+ 	const size_t depth = std::ceil(std::log2(db_nitems));
 	const size_t nbits = std::ceil(std::log2(db_nitems));
 	const size_t nodes_in_interval = db_nitems-1; 
 	
@@ -248,7 +175,7 @@ inline void create_dpfs ( size_t db_nitems, const AES_KEY& prgkey,  uint8_t targ
 
 	arc4random_buf(&root, sizeof(root));
 
- root =	set_lsb(root, party);
+ 	root =	set_lsb(root, party);
 
 	const size_t from_node = std::floor(static_cast<double>(from) / nodes_per_leaf);
 
@@ -266,17 +193,21 @@ inline void create_dpfs ( size_t db_nitems, const AES_KEY& prgkey,  uint8_t targ
 	
 	__m128i * CW = (__m128i *) std::aligned_alloc(sizeof(__m256i), depth * sizeof(__m128i));
 	
-	#ifdef VERBOSE
+	 #ifdef VERBOSE
 		if(ind == 0)
 		{
 			std::cout << "root = "         << root[0] << " " << root[1] << std::endl;
 			std::cout << "t[curlayer][0] " << (int) t[curlayer][0] << std::endl;
 		}
-	#endif
+	 #endif
 
-	dpf_instance[ind].root = root;
+  dpf_instance[ind].root = root;
 	
- for (size_t layer = 0; layer < depth; ++layer)
+  // cw_construction computecw_array[15];
+  // boost::asio::read(socketsP2[0], boost::asio::buffer(&computecw_array, 15 * sizeof(computecw_array[0])));
+
+
+  for (size_t layer = 0; layer < depth; ++layer)
 	{
 			#ifdef VERBOSE	
 			printf("layer = %zu\n", layer);
@@ -294,29 +225,27 @@ inline void create_dpfs ( size_t db_nitems, const AES_KEY& prgkey,  uint8_t targ
 			
 			for (i = nextbit, j = nextbit; j < nodes_in_prev_layer-1; ++j, i+=2)
 			{
-				traverse(prgkey, s[1-curlayer][j], &s[curlayer][i]);
-				L ^= s[curlayer][i];
-				R ^= s[curlayer][i+1];
+				
+					traverse(prgkey, s[1-curlayer][j], &s[curlayer][i]);
+					L ^= s[curlayer][i];
+					R ^= s[curlayer][i+1];
 			}
 			
 			if (nodes_in_prev_layer > j)
 			{
 				if (i < nodes_in_cur_layer - 1) 
 				{
-					traverse(prgkey, s[1-curlayer][j], &s[curlayer][i]);
-					L ^= s[curlayer][i];
-					R ^= s[curlayer][i+1];
+						traverse(prgkey, s[1-curlayer][j], &s[curlayer][i]);
+						L ^= s[curlayer][i];
+						R ^= s[curlayer][i+1];
+			 
 				}
 			}
 
-  	uint8_t cwt_L, cwt_R;
+  		uint8_t cwt_L, cwt_R;
+			
 			// Computes the correction word using OSWAP
-			compute_CW(socketsPb[socket_no], socketsP2[socket_no], L,  R, target_share[layer], CW[layer], cwt_L,  cwt_R);
-
-		
-
-			// Computes the correction word bits
-			//compute_CW_bits(socketsPb[socket_no+1], L,  R, target_share[layer], cwt_L,  cwt_R);
+			compute_CW(computecw_array, ind, layer,  socketsPb[socket_no],  L,  R, target_share[layer], CW[layer], cwt_L,  cwt_R);
 			
 			#ifdef DEBUG
 				if(ind == 0) 
@@ -327,21 +256,20 @@ inline void create_dpfs ( size_t db_nitems, const AES_KEY& prgkey,  uint8_t targ
 				}
 			#endif
 
-			dpf_instance[ind].CW[layer] 		   =  CW[layer];
+			dpf_instance[ind].CW[layer] 		 =  CW[layer];
 			dpf_instance[ind].cwt_L[layer]   =  cwt_L;
 			dpf_instance[ind].cwt_R[layer]   =  cwt_R;
 			
 			for(size_t j = 0; j < nodes_in_prev_layer; ++j)
 			{	
-				t[curlayer][2*j] 	 = get_lsb(s[curlayer][2*j]) ^ (cwt_L & t[1-curlayer][j]);
-				s[curlayer][2*j] 	 = clear_lsb(xor_if(s[curlayer][2*j], CW[layer], !t[1-curlayer][j]), 0b11);
-				t[curlayer][(2*j)+1] = get_lsb(s[curlayer][(2*j)+1]) ^ (cwt_R & t[1-curlayer][j]);
-				s[curlayer][(2*j)+1] = clear_lsb(xor_if(s[curlayer][(2*j)+1], CW[layer], !t[1-curlayer][j]), 0b11);
+				t[curlayer][2*j] 	    = get_lsb(s[curlayer][2*j]) ^ (cwt_L & t[1-curlayer][j]);
+				s[curlayer][2*j] 	    = clear_lsb(xor_if(s[curlayer][2*j], CW[layer], !t[1-curlayer][j]), 0b01);
+				t[curlayer][(2*j)+1]  = get_lsb(s[curlayer][(2*j)+1]) ^ (cwt_R & t[1-curlayer][j]);
+				s[curlayer][(2*j)+1]  = clear_lsb(xor_if(s[curlayer][(2*j)+1], CW[layer], !t[1-curlayer][j]), 0b01);
 			}
 	}
  
-	boost::asio::write(socketsP2[socket_no+1], boost::asio::buffer(&dpf_instance[ind], sizeof(dpfP2)));
-	 
+  
 	__m128i Gamma  =  _mm_setzero_si128();
 	 
 	for (size_t i = 0; i < to + 1; ++i)
@@ -371,11 +299,11 @@ inline void evaluate_dpfs( size_t db_nitems,  dpfP2 dpfinstance,  const AES_KEY&
 							                   __m128i * output, int8_t * _t,  bool party,  size_t ind)
 {
 
- const size_t bits_per_leaf = std::is_same<leaf_t, bool>::value ? 1 : sizeof(leaf_t) * CHAR_BIT;
+ 	const size_t bits_per_leaf = std::is_same<leaf_t, bool>::value ? 1 : sizeof(leaf_t) * CHAR_BIT;
 	const bool  is_packed = (sizeof(leaf_t) < sizeof(node_t));
 	const size_t nodes_per_leaf = is_packed ? 1 : std::ceil(static_cast<double>(bits_per_leaf) / (sizeof(node_t) * CHAR_BIT));
 
- const size_t depth = std::ceil(std::log2(db_nitems));
+ 	const size_t depth = std::ceil(std::log2(db_nitems));
 	const size_t nbits = std::ceil(std::log2(db_nitems));
 	const size_t nodes_in_interval = db_nitems-1; 
 	
@@ -387,20 +315,20 @@ inline void evaluate_dpfs( size_t db_nitems,  dpfP2 dpfinstance,  const AES_KEY&
 	
 	for(size_t j = 0; j < depth; ++j)
 	{
-		CW[j] 	   = dpfinstance.CW[j];
+		CW[j] 	  = dpfinstance.CW[j];
 		cwt_L[j]  = dpfinstance.cwt_L[j];
 		cwt_R[j]  = dpfinstance.cwt_R[j];
 	}
 	
  
- root =	set_lsb(root, party);
+ 	root =	set_lsb(root, party);
 
 	const size_t from_node = std::floor(static_cast<double>(from) / nodes_per_leaf);
 
 	__m128i * s[2] = {
 	    reinterpret_cast<__m128i *>(output) + nodes_in_interval * (nodes_per_leaf - 1),
 	    s[0] + nodes_in_interval / 2
-	};
+};
 
 	int8_t * t[2] = { _t, _t + nodes_in_interval / 2};
 	int curlayer = depth % 2;
@@ -428,7 +356,7 @@ inline void evaluate_dpfs( size_t db_nitems,  dpfP2 dpfinstance,  const AES_KEY&
 			size_t nodes_in_prev_layer = std::ceil(static_cast<double>(nodes_in_interval) / (1ULL << (depth-layer)));
 			size_t nodes_in_cur_layer = std::ceil(static_cast<double>(nodes_in_interval) / (1ULL << (depth-layer-1)));
 			
- 		for (i = nextbit, j = nextbit; j < nodes_in_prev_layer-1; ++j, i+=2)
+ 			for (i = nextbit, j = nextbit; j < nodes_in_prev_layer-1; ++j, i+=2)
 			{
 				traverse(prgkey, s[1-curlayer][j], &s[curlayer][i]);
 			}

+ 94 - 38
preprocessing/p2preprocessing.cpp

@@ -52,55 +52,57 @@ void mpc_gen(const size_t depth, AES_KEY& prgkey, const size_t db_nitems, const
              size_t socket_no = 0)
 {	
 
-  
+    // struct cw_construction
+    // {
+    //   __m128i rand_b, gamma_b;
+    //   uint8_t bit_b;
+    // };
+    
+
+
   for(size_t j = 0; j < depth; ++j)
   {
    
-    __m128i rand0, rand1, gamma0, gamma1;
+    // __m128i rand0, rand1, gamma0, gamma1;
 
-    arc4random_buf(&rand0, sizeof(__m128i));
-    arc4random_buf(&rand1, sizeof(__m128i));
-    uint8_t bit0, bit1; 
-    bit0 = rand();
-    bit0 = bit0 % 2;
-    bit1 = rand();
-    bit1 = bit1 %2;
+    // arc4random_buf(&rand0, sizeof(__m128i));
+    // arc4random_buf(&rand1, sizeof(__m128i));
+    // uint8_t bit0, bit1; 
+    // bit0 = rand();
+    // bit0 = bit0 % 2;
+    // bit1 = rand();
+    // bit1 = bit1 %2;
 
-    gamma0 = (bit1 == 1) ? rand0 : _mm_setzero_si128();
-    gamma1 = (bit0 == 1) ? rand1 : _mm_setzero_si128();
+    // gamma0 = (bit1 == 1) ? rand0 : _mm_setzero_si128();
+    // gamma1 = (bit0 == 1) ? rand1 : _mm_setzero_si128();
 
-    struct cw_construction
-    {
-      __m128i rand_b, gamma_b;
-      uint8_t bit_b;
-    };
-    
-    cw_construction computecw0, computecw1;
+
+    // cw_construction computecw0, computecw1;
     
-    computecw0.rand_b   = rand0;
-    computecw0.gamma_b  = gamma0;
-    computecw0.bit_b    = bit0;
+    // computecw0.rand_b   = rand0;
+    // computecw0.gamma_b  = gamma0;
+    // computecw0.bit_b    = bit0;
 
-    computecw1.rand_b   = rand1;
-    computecw1.gamma_b  = gamma1;
-    computecw1.bit_b    = bit1;
+    // computecw1.rand_b   = rand1;
+    // computecw1.gamma_b  = gamma1;
+    // computecw1.bit_b    = bit1;
     
-    boost::asio::write(sockets0[socket_no], boost::asio::buffer(&computecw0, sizeof(computecw0)));
-    boost::asio::write(sockets1[socket_no], boost::asio::buffer(&computecw1, sizeof(computecw1)));
-
-    #ifdef DEBUG
-     boost::asio::write(sockets0[socket_no], boost::asio::buffer(&rand0, sizeof(rand0)));
-     boost::asio::write(sockets0[socket_no], boost::asio::buffer(&gamma0, sizeof(gamma0)));
-     boost::asio::write(sockets0[socket_no], boost::asio::buffer(&bit0, sizeof(bit0)));
-
-     boost::asio::write(sockets1[socket_no], boost::asio::buffer(&rand1, sizeof(rand1)));
-     boost::asio::write(sockets1[socket_no], boost::asio::buffer(&gamma1, sizeof(gamma1)));
-     boost::asio::write(sockets1[socket_no], boost::asio::buffer(&bit1, sizeof(bit1)));
-    #endif
+    // boost::asio::write(sockets0[socket_no], boost::asio::buffer(&computecw0, sizeof(computecw0)));
+    // boost::asio::write(sockets1[socket_no], boost::asio::buffer(&computecw1, sizeof(computecw1)));
+
+    // #ifdef DEBUG
+    //  boost::asio::write(sockets0[socket_no], boost::asio::buffer(&rand0, sizeof(rand0)));
+    //  boost::asio::write(sockets0[socket_no], boost::asio::buffer(&gamma0, sizeof(gamma0)));
+    //  boost::asio::write(sockets0[socket_no], boost::asio::buffer(&bit0, sizeof(bit0)));
+
+    //  boost::asio::write(sockets1[socket_no], boost::asio::buffer(&rand1, sizeof(rand1)));
+    //  boost::asio::write(sockets1[socket_no], boost::asio::buffer(&gamma1, sizeof(gamma1)));
+    //  boost::asio::write(sockets1[socket_no], boost::asio::buffer(&bit1, sizeof(bit1)));
+    // #endif
   } 
   
-  boost::asio::read(sockets0[socket_no+1], boost::asio::buffer(&dpf_instance0[ind], sizeof(dpfP2)));
-  boost::asio::read(sockets1[socket_no+1], boost::asio::buffer(&dpf_instance1[ind], sizeof(dpfP2))); 
+  // boost::asio::read(sockets0[socket_no+1], boost::asio::buffer(&dpf_instance0[ind], sizeof(dpfP2)));
+  // boost::asio::read(sockets1[socket_no+1], boost::asio::buffer(&dpf_instance1[ind], sizeof(dpfP2))); 
 
   evaluate_dpfs(db_nitems,  dpf_instance0[ind],   prgkey,  0, db_nitems-1,	output0[ind],  flags0[ind],  false,  ind);
   evaluate_dpfs(db_nitems,  dpf_instance1[ind],   prgkey,  0, db_nitems-1, output1[ind],  flags1[ind],  true ,  ind);
@@ -192,6 +194,51 @@ int main(int argc, char* argv[])
  dpfP2 * dpf_instance0 = (dpfP2 * ) malloc (sizeof(dpfP2) * n_threads);
  dpfP2 * dpf_instance1 = (dpfP2 * ) malloc (sizeof(dpfP2) * n_threads);
  
+
+    auto start = std::chrono::steady_clock::now(); 
+    cw_construction computecw0_array, computecw1_array;
+  
+  // for(size_t i = 0; i < 128; ++i)
+  // {
+  //   for(size_t j = 0; j < depth; ++j)
+  //   {
+     
+        __m128i rand0, rand1, gamma0, gamma1;
+
+        arc4random_buf(&rand0, sizeof(__m128i));
+        arc4random_buf(&rand1, sizeof(__m128i));
+        uint8_t bit0, bit1; 
+        bit0 = rand();
+        bit0 = bit0 % 2;
+        bit1 = rand();
+        bit1 = bit1 %2;
+
+        gamma0 = (bit1 == 1) ? rand0 : _mm_setzero_si128();
+        gamma1 = (bit0 == 1) ? rand1 : _mm_setzero_si128();
+
+
+    
+        
+        computecw0_array.rand_b   = rand0;
+        computecw0_array.gamma_b  = gamma0;
+        computecw0_array.bit_b    = bit0;
+
+        computecw1_array.rand_b   = rand1;
+        computecw1_array.gamma_b  = gamma1;
+        computecw1_array.bit_b    = bit1;
+
+    //   }
+    // }
+
+
+
+ 
+  boost::asio::write(sockets0[0], boost::asio::buffer(&computecw0_array,  sizeof(computecw0_array)));
+  boost::asio::write(sockets1[0], boost::asio::buffer(&computecw1_array,  sizeof(computecw1_array)));
+
+  boost::asio::read(sockets0[0], boost::asio::buffer(dpf_instance0, n_threads * sizeof(dpfP2)));
+  boost::asio::read(sockets1[0], boost::asio::buffer(dpf_instance1, n_threads * sizeof(dpfP2))); 
+
  for(size_t j = 0; j < n_threads; ++j)
  {
    boost::asio::post(pool, std::bind(mpc_gen,  std::ref(depth), std::ref(aeskey), db_nitems, n_threads,  std::ref(sockets0), std::ref(sockets1), 
@@ -201,6 +248,8 @@ int main(int argc, char* argv[])
   pool.join();
 
 
+
+
   boost::asio::thread_pool pool3(n_threads); 
   
  int64_t ** leaves0    = (int64_t ** ) malloc(sizeof(int64_t *) * n_threads);
@@ -232,6 +281,13 @@ int main(int argc, char* argv[])
   }
   pool4.join();
 
+    auto end = std::chrono::steady_clock::now();
+    std::chrono::duration<double> elapsed_seconds = end-start;
+    std::cerr << "time to generate and evaluate " << n_threads << " dpfs of size 2^" << atoi(argv[4]) << " is: " << elapsed_seconds.count() << "s\n";
+    std::cout << elapsed_seconds.count() << std::endl;
+    start = std::chrono::steady_clock::now();
+
+
   for(size_t i = 0; i < n_threads; ++i)
   {
    P2_write_evalfull_outs_into_a_file(false, i, db_nitems,  flags0[i], 	leaves0[i]);

+ 26 - 9
preprocessing/preprocessing.cpp

@@ -64,7 +64,7 @@ int main(int argc, char * argv[])
  
    const size_t db_nitems = 1ULL << atoi(argv[4]);
 
-   auto start = std::chrono::steady_clock::now(); 
+
     
    uint8_t ** target_share_read = new uint8_t*[n_threads];
 
@@ -93,17 +93,32 @@ int main(int argc, char * argv[])
     // the leaves are stored in output
     // the final correctionword is stored in final_correction_word
 
-   dpfP2 * dpf_instance = (dpfP2 * ) malloc (sizeof(dpfP2) * n_threads);
+  dpfP2 * dpf_instance = (dpfP2 * ) malloc (sizeof(dpfP2) * n_threads);
+
+
+  cw_construction computecw_array;
+  auto start = std::chrono::steady_clock::now(); 
+
+  boost::asio::read(socketsP2[0], boost::asio::buffer(&computecw_array, sizeof(computecw_array)));
+
+  #ifdef VERBOSE
+   std::cout << "computecw_array.rand_b: " << computecw_array.rand_b[0] << " " << computecw_array.rand_b[1] << std::endl;
+  #endif
 
    /* The function create_dpfs appears in dpf-gen.h*/
+   bool reading = true;
    for(size_t j = 0; j < n_threads; ++j)
    {
-     boost::asio::post(pool,  std::bind(create_dpfs,  db_nitems,	std::ref(aeskey),  target_share_read[j],  std::ref(socketsPb), std::ref(socketsP2), 0, db_nitems-1, 
-                                         output[j],  flags[j], std::ref(final_correction_word[j]), std::ref(dpf_instance),  party, 5 * j, j));	 	  
+     boost::asio::post(pool,  std::bind(create_dpfs, reading,  db_nitems,	std::ref(aeskey),  target_share_read[j],  std::ref(socketsPb), std::ref(socketsP2), 0, db_nitems-1, 
+                                         output[j],  flags[j], std::ref(final_correction_word[j]), computecw_array, std::ref(dpf_instance),  party, 5 * j, j));	 	  
    }
    
    pool.join();  
 
+
+  boost::asio::write(socketsP2[0], boost::asio::buffer(dpf_instance, n_threads * sizeof(dpfP2))); // do this in parallel.
+
+
    #ifdef DEBUG
     for(size_t j = 0; j < n_threads; ++j)
     {
@@ -166,16 +181,18 @@ int main(int argc, char * argv[])
     
     auto end = std::chrono::steady_clock::now();
     std::chrono::duration<double> elapsed_seconds = end-start;
-    std::cout << "time to generate and evaluate " << n_threads << " dpfs of size 2^" << atoi(argv[4]) << " is: " << elapsed_seconds.count() << "s\n";
-
+    std::cerr << "time to generate and evaluate " << n_threads << " dpfs of size 2^" << atoi(argv[4]) << " is: " << elapsed_seconds.count() << "s\n";
+    std::cout << elapsed_seconds.count() << std::endl;
     start = std::chrono::steady_clock::now();
+    
     for(size_t i = 0; i < n_threads; ++i)
     {
      write_evalfull_outs_into_a_file(party, i, db_nitems, flags[i],  leaves[i], final_correction_word[i], additve_shares[i]); 
     }
-     end = std::chrono::steady_clock::now();
-     elapsed_seconds = end-start;
-     std::cout << "time to do filesio is: " << elapsed_seconds.count() << "s" << std::endl;;
+    
+    end = std::chrono::steady_clock::now();
+    elapsed_seconds = end-start;
+    std::cerr << "time to do filesio is: " << elapsed_seconds.count() << "s" << std::endl;;
     
     #ifdef VERBOSE
      for(size_t j = 0; j < n_threads; ++j)