Browse Source

printf outs

avadapal 1 year ago
parent
commit
39b68804a4
1 changed files with 87 additions and 92 deletions
  1. 87 92
      2p-preprocessing/preprocessing.cpp

+ 87 - 92
2p-preprocessing/preprocessing.cpp

@@ -71,13 +71,9 @@ void generate_random_targets(uint8_t **target_share_read, size_t n_threads, bool
 	{
 		for (size_t i = 0; i < n_threads; ++i)
 		{
-			srand(3);
 			uint8_t random_value;
 			arc4random_buf(&random_value, sizeof(uint8_t));
 			target_share_read[i][j] = random_value; // rand();
-			target_share_read[i][j] = 0;			// target_share_read[i][j] % 2;
-			if (party)
-				target_share_read[i][expo - 2] = 1;
 		}
 	}
 }
@@ -179,36 +175,36 @@ void compute_CW(bool party, tcp::socket &sout, __m128i L, __m128i R, uint8_t bit
 
 	CW = out_reconstruction;
 
-#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;
-
-	__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 CW_debug;
-
-	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]);
-#endif
+ #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;
+
+  __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 CW_debug;
+
+  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]);
+ #endif
 }
 
 __m128i bit_mask_avx2_msb(unsigned int n)
@@ -266,64 +262,63 @@ inline void evalfull_mpc(const size_t &nodes_per_leaf, const size_t &depth, cons
 	for (size_t layer = 0; layer < depth; ++layer)
 	{
    #ifdef VERBOSE
-		 printf("layer = %zu\n", layer);
+		  printf("layer = %zu\n", layer);
    #endif
-		curlayer = 1 - curlayer;
-
-		size_t i = 0, j = 0;
-		auto nextbit = (from_node >> (nbits - layer - 1)) & 1;
-		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)));
-
-		__m128i L = _mm_setzero_si128();
-		__m128i R = _mm_setzero_si128();
-
-		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];
-		}
-
-		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];
-			}
-		}
-
-		compute_CW(party, socketsPb[socket_no], L, R, target_share[layer], CW[layer]);
-
-		uint8_t advice_L = get_lsb(L) ^ target_share[layer];
-		uint8_t advice_R = get_lsb(R) ^ target_share[layer];
-
-		uint8_t cwt_L, cwt_R;
-
-		uint8_t advice[2];
-		uint8_t cwts[2];
-		advice[0] = advice_L;
-		advice[1] = advice_R;
-
-		boost::asio::write(socketsPb[socket_no + 1], boost::asio::buffer(&advice, sizeof(advice)));
-		boost::asio::read(socketsPb[socket_no + 1], 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;
-
-		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);
-		}
-	}
+		 curlayer = 1 - curlayer;
+
+		 size_t i = 0, j = 0;
+		 auto nextbit = (from_node >> (nbits - layer - 1)) & 1;
+		 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)));
+
+		 __m128i L = _mm_setzero_si128();
+		 __m128i R = _mm_setzero_si128();
+
+   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];
+   }
+
+   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];
+    }
+   }
+
+		 compute_CW(party, socketsPb[socket_no], L, R, target_share[layer], CW[layer]);
+
+		 uint8_t advice_L = get_lsb(L) ^ target_share[layer];
+		 uint8_t advice_R = get_lsb(R) ^ target_share[layer];
+
+		 uint8_t cwt_L, cwt_R;
+		 uint8_t advice[2];
+		 uint8_t cwts[2];
+		 advice[0] = advice_L;
+		 advice[1] = advice_R;
+
+		 boost::asio::write(socketsPb[socket_no + 1], boost::asio::buffer(&advice, sizeof(advice)));
+		 boost::asio::read(socketsPb[socket_no + 1], 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;
+
+		 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);
+		 }
+	 }
 
 	__m128i Gamma = _mm_setzero_si128();
 
@@ -523,7 +518,7 @@ bool party;
 
 	convert_shares(output, flags, n_threads, db_nitems, final_correction_word, socketsPb[0], party);
 
-	if (!party)
+	if(!party)
 	{
 		char const *p0_filename0;
 		p0_filename0 = "../duoram-online/preprocflags/party0_read_flags_b";