Browse Source

correcting a bug introduced in previous commit

avadapal 1 year ago
parent
commit
bd12d7963b
2 changed files with 79 additions and 104 deletions
  1. 66 52
      2p-preprocessing/ot_blinds.cpp
  2. 13 52
      2p-preprocessing/preprocessing.cpp

+ 66 - 52
2p-preprocessing/ot_blinds.cpp

@@ -162,14 +162,17 @@ void run_test_sender(uint32_t numots, uint32_t bitlength, snd_ot_flavor stype, r
 	X0.Reset();
 	X0.XOR(X[1]);
 	//Y[0]->Copy(X[1]);
-	printf("X0:\n");
-	//X[1]->PrintBinary();  // I added this line 
-	X0.PrintHex();  // I added this line 
-	printf("Y0:\n");
-	Y[0]->PrintHex();  // I added this line
-	printf("T0: \n");
-	X[0]->PrintHex();
 	
+ #ifdef VERBOSE
+  printf("X0:\n");
+	 //X[1]->PrintBinary();  // I added this line 
+	 X0.PrintHex();  // I added this line 
+ 	printf("Y0:\n");
+ 	Y[0]->PrintHex();  // I added this line
+	 printf("T0: \n");
+	 X[0]->PrintHex();
+	#endif
+
 	X[1]->XOR(X[0]);
 
 	//X[1] --> X0 \oplus T0
@@ -198,24 +201,25 @@ void run_test_sender(uint32_t numots, uint32_t bitlength, snd_ot_flavor stype, r
 	
 	printf("\n\nLearnt Gamma0 = (X1 /cdot Y0) /oplus T------>>>>>> \n");
 	response.PrintHex();
-	//  std::ofstream gammafile0, X0file, Y0file;
-	//  gammafile0.open ("gamma0.txt", std::ios::out);
-	//  X0file.open("X0.txt", std::ios::out);
-	//  Y0file.open("Y0.txt", std::ios::out);
+
+	 // std::ofstream gammafile0, X0file, Y0file;
+	 // gammafile0.open ("gamma0.txt", std::ios::out);
+	 // X0file.open("X0.txt", std::ios::out);
+	 // Y0file.open("Y0.txt", std::ios::out);
 
 	  int fd = open("./y0", O_WRONLY, O_CREAT);
  	  ssize_t bytes = write(fd, Y[0]->GetArr(), Y[0]->GetSize());
- 	  //std::cout << "bytes = " << bytes << std::endl;
+ 	  std::cout << "bytes = " << bytes << std::endl;
 	  close(fd);
 
 	  int fd2 = open("./x0", O_WRONLY, O_CREAT);
  	  ssize_t bytes2 = write(fd2, X0.GetArr(), X0.GetSize());
- 	  //std::cout << "bytes = " << bytes2 << std::endl;
+ 	  std::cout << "bytes = " << bytes2 << std::endl;
 	  close(fd2);
 
-	  int fd3 = open("./gamma0", O_WRONLY, O_CREAT);
+	   int fd3 = open("./gamma0", O_WRONLY, O_CREAT);
  	  ssize_t bytes3 = write(fd3, response.GetArr(), response.GetSize());
- 	  //std::cout << "bytes = " << bytes3 << std::endl;
+ 	  std::cout << "bytes = " << bytes3 << std::endl;
 	  close(fd3);
 
 	// for(size_t j = 0; j < numots; ++j)
@@ -267,14 +271,16 @@ void run_test_receiver(uint32_t numots, uint32_t bitlength, snd_ot_flavor stype,
 	X1.Create(numots, bitlength);
 	X1.Reset();
 	X1.XOR(X[1]);
-	printf("X1:\n");
-	//X[1]->PrintBinary();  // I added this line 
-	X1.PrintHex();  // I added this line 
-	printf("Y1:\n");
-	Y[0]->PrintHex();  // I added this line
-	printf("T1: \n");
-	X[0]->PrintHex();
 	
+ #ifdef VERBOSE
+  printf("X1:\n");
+  //X[1]->PrintBinary();  // I added this line 
+  X1.PrintHex();  // I added this line 
+  printf("Y1:\n");
+  Y[0]->PrintHex();  // I added this line
+  printf("T1: \n");
+  X[0]->PrintHex();
+	#endif
 	// X[1] -- > X1 \oplus T1
 	X[1]->XOR(X[0]);
 
@@ -305,42 +311,50 @@ void run_test_receiver(uint32_t numots, uint32_t bitlength, snd_ot_flavor stype,
 
 	// response.PrintBinary();
 	response.XOR(X[0]);
-	printf("\n\nLearnt: Gamma1 =  (X0 /cdot Y1) /oplus T------>>>>>> \n");
-	response.PrintHex();
-	std::ofstream gammafile1, X1file, Y1file;
+	
+ #ifdef VERBOSE
+  printf("\n\nLearnt: Gamma1 =  (X0 /cdot Y1) /oplus T------>>>>>> \n");
+ 	response.PrintHex();
+	#endif
+ //std::ofstream gammafile1, X1file, Y1file;
 	
 	
 
-	  int fd = open("./y1", O_WRONLY, O_CREAT);
- 	  ssize_t bytes = write(fd, Y[0]->GetArr(), Y[0]->GetSize());
- 	  std::cout << "bytes = " << bytes << std::endl;
-	  close(fd);
-
-	  int fd2 = open("./x1", O_WRONLY, O_CREAT);
- 	  ssize_t bytes2 = write(fd2, X1.GetArr(), X1.GetSize());
- 	  std::cout << "bytes = " << bytes2 << std::endl;
-	  close(fd2);
-
-	   int fd3 = open("./gamma1", O_WRONLY, O_CREAT);
- 	  ssize_t bytes3 = write(fd3, response.GetArr(), response.GetSize());
- 	  std::cout << "bytes = " << bytes3 << std::endl;
-	  close(fd3);
+	int fd = open("./y1", O_WRONLY, O_CREAT);
+ ssize_t bytes = write(fd, Y[0]->GetArr(), Y[0]->GetSize());
+ 
+ #ifdef VERBOSE
+  std::cout << "bytes = " << bytes << std::endl;
+	#endif
+ 
+ close(fd);
 
-	  std::cout << "X1: \n\n";
-	  X1.PrintHex();
+	int fd2 = open("./x1", O_WRONLY, O_CREAT);
+ ssize_t bytes2 = write(fd2, X1.GetArr(), X1.GetSize());
+ 
+	close(fd2);
 
-	 gammafile1.open ("gamma1.txt", std::ios::out);
-	 X1file.open("X1.txt", std::ios::out);
-	 Y1file.open("Y1.txt", std::ios::out);
-	for(size_t j = 0; j < numots; ++j)
-	{
-	//	std::cout << (int) response.GetBitNoMask(j);
-		gammafile1 << (int) response.GetBitNoMask(j);
-		X1file 	  << (int) X1.GetBitNoMask(j);
-		Y1file 	  << (int) Y[0]->GetBitNoMask(j);
-	}
+	int fd3 = open("./gamma1", O_WRONLY, O_CREAT);
+ ssize_t bytes3 = write(fd3, response.GetArr(), response.GetSize());
+ 
+	close(fd3);
+
+  #ifdef VERBOSE
+	   std::cout << "X1: \n\n";
+	   X1.PrintHex();
+   #endif
+	//  gammafile1.open ("gamma1.txt", std::ios::out);
+	//  X1file.open("X1.txt", std::ios::out);
+	//  Y1file.open("Y1.txt", std::ios::out);
+	// for(size_t j = 0; j < numots; ++j)
+	// {
+	// //	std::cout << (int) response.GetBitNoMask(j);
+	// 	gammafile1 << (int) response.GetBitNoMask(j);
+	// 	X1file 	  << (int) X1.GetBitNoMask(j);
+	// 	Y1file 	  << (int) Y[0]->GetBitNoMask(j);
+	// }
  
- 	gammafile1.close();
+ 	//gammafile1.close();
 	delete m_fMaskFct;
 //	choices.delCBitVector();
 	response.delCBitVector();

+ 13 - 52
2p-preprocessing/preprocessing.cpp

@@ -138,20 +138,6 @@ void compute_CW(bool party, tcp::socket &sout, __m128i L, __m128i R, uint8_t bit
 		bit_b = 1;		// 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;
 
@@ -374,7 +360,7 @@ void convert_shares(__m128i **output, int8_t **flags, size_t n_threads, size_t d
 			}
 		}
 
-		// #ifdef DEBUG
+		 #ifdef DEBUG
 		int8_t out = flags[0][j];
 		int8_t out_rec;
 
@@ -382,6 +368,7 @@ void convert_shares(__m128i **output, int8_t **flags, size_t n_threads, size_t d
 		boost::asio::read(sb, boost::asio::buffer(&out_rec, sizeof(out_rec)));
 		out_rec = out_rec + out;
 
+		
 		if (out_rec != 0)
 			std::cout << j << "(flags) --> " << (int)out_rec << std::endl
 					  << std::endl;
@@ -394,7 +381,7 @@ void convert_shares(__m128i **output, int8_t **flags, size_t n_threads, size_t d
 		out_rec2 = out_rec2 + out2;
 		if (out_rec2[0] != 0)
 			std::cout << j << "--> " << out_rec2[0] << std::endl;
-		// #endif
+		 #endif
 	}
 
 	for (size_t i = 0; i < n_threads; ++i)
@@ -432,12 +419,13 @@ int main(int argc, char *argv[])
 
 	boost::asio::io_context io_context;
 	tcp::resolver resolver(io_context);
-	std::string addr = "127.0.0.1";
-	const std::string host1 = (argc < 2) ? "127.0.0.1" : argv[1];
+	const std::string host1 = argv[1];
  
 
 	const size_t n_threads = atoi(argv[2]);
 	const size_t number_of_sockets = 5 * n_threads;
+	const size_t expo = atoi(argv[3]);
+	const size_t db_nitems = 1ULL << expo;
 
 	std::vector<socket_t> socketsPb;
 	for (size_t j = 0; j < number_of_sockets + 1; ++j)
@@ -447,7 +435,6 @@ int main(int argc, char *argv[])
 	}
 	socketsPb.reserve(number_of_sockets + 1);
 
-	// std::vector<socket_t> socketsP2;
 
 	std::vector<int> ports;
 	for (size_t j = 0; j < number_of_sockets; ++j)
@@ -470,38 +457,19 @@ int main(int argc, char *argv[])
 		ports2_1.push_back(port + j);
 	}
 
-	bool party;
+bool party;
 
 #if (PARTY == 0)
-
-	party = false;
-	// for(size_t j = 0; j < number_of_sockets; ++j)
-	// {
-	//   tcp::socket sb_a(io_context);
-	//   boost::asio::connect(sb_a, resolver.resolve({host2, std::to_string(ports2_0[j])}));
-	//   socketsP2.emplace_back(std::move(sb_a));
-	// }
-
+	party = false; 
 	for (size_t j = 0; j < number_of_sockets; ++j)
 	{
 		tcp::socket sb_a(io_context);
 		boost::asio::connect(sb_a, resolver.resolve({host1, std::to_string(ports[j])}));
 		socketsPb[j] = std::move(sb_a);
 	}
-
 #else
-
-	party = true;
-
-	for (size_t j = 0; j < number_of_sockets; ++j)
-	{
-		//   tcp::socket sb_a(io_context);
-		//   boost::asio::connect(sb_a, resolver.resolve({host2, std::to_string(ports2_1[j])}));
-		//   socketsP2.emplace_back(std::move(sb_a));
-	}
-
+	party = true;	
 	boost::asio::thread_pool pool2(number_of_sockets);
-
 	for (size_t j = 0; j < number_of_sockets; ++j)
 	{
 		boost::asio::post(pool2, std::bind(accept_conncections_from_Pb, std::ref(io_context), std::ref(socketsPb), ports[j], j));
@@ -510,14 +478,6 @@ int main(int argc, char *argv[])
 	pool2.join();
 #endif
 
-	const size_t expo = atoi(argv[2]);
-	const size_t db_nitems = 1ULL << atoi(argv[2]);
- 
- 
-
- 
- 
-
 	__m128i *final_correction_word = (__m128i *)std::aligned_alloc(sizeof(__m256i), n_threads * sizeof(__m128i));
 
 	AES_KEY aeskey;
@@ -540,8 +500,9 @@ int main(int argc, char *argv[])
 
 	boost::asio::thread_pool pool(n_threads);
 
-	printf("n_threads = %zu\n\n", n_threads);
-
+	#ifdef VERBOSE
+		printf("n_threads = %zu\n\n", n_threads);
+	#endif
 	auto start = std::chrono::steady_clock::now();
 	uint8_t **target_share_read = new uint8_t *[n_threads];
 
@@ -557,7 +518,7 @@ int main(int argc, char *argv[])
 	pool.join();
 	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::cout << "time to generate and evaluate " << n_threads << " dpfs of size 2^" << expo << " is: " << elapsed_seconds.count() << "s\n";
 
 	convert_shares(output, flags, n_threads, db_nitems, final_correction_word, socketsPb[0], party);