Browse Source

moved write flagbits into a file function into a separate header

avadapal 1 year ago
parent
commit
98290e6d14
4 changed files with 475 additions and 230 deletions
  1. 225 220
      preprocessing/dpfgen.h
  2. 244 0
      preprocessing/filesio.h
  3. 5 9
      preprocessing/p2preprocessing.cpp
  4. 1 1
      preprocessing/preprocessing.cpp

+ 225 - 220
preprocessing/dpfgen.h

@@ -27,250 +27,250 @@ void generate_random_targets(uint8_t ** target_share_read, size_t n_threads, boo
 	}
 }
 
-void write_evalfull_outs_into_a_file(bool party, size_t i, size_t db_nitems,  int8_t ** flags, int64_t * outs_, __m128i * final_correction_word)
-{
- if(!party) 
- {  
-   	char const * p0_filename0;
-	char tmp[100];
-   	p0_filename0 = "../duoram-online/party0_read_flags_b";
-	strcpy(tmp, p0_filename0);
- 	strcat(tmp, std::to_string(i).c_str());
+// void write_evalfull_outs_into_a_file(bool party, size_t i, size_t db_nitems,  int8_t ** flags, int64_t * outs_, __m128i * final_correction_word)
+// {
+//  if(!party) 
+//  {  
+//    	char const * p0_filename0;
+// 	char tmp[100];
+//    	p0_filename0 = "../duoram-online/party0_read_flags_b";
+// 	strcpy(tmp, p0_filename0);
+//  	strcat(tmp, std::to_string(i).c_str());
 	
-	int w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
-   	int written = write(w0, flags[i], db_nitems * sizeof(flags[i][0]));
-      if(written<0) {
-             perror("Write error");
-       }
-      close(w0);
-
- 	 p0_filename0 = "../duoram-online/party0_read_flags_c";
-   	strcpy(tmp, p0_filename0);
- 	strcat(tmp, std::to_string(i).c_str());
-   	 int w1 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
-     written = write(w1, flags[i], db_nitems * sizeof(flags[i][0]));
-     if(written<0) {
-             perror("Write error");
-       }
-      close(w1);
+// 	int w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+//    	int written = write(w0, flags[i], db_nitems * sizeof(flags[i][0]));
+//       if(written<0) {
+//              perror("Write error");
+//        }
+//       close(w0);
+
+//  	 p0_filename0 = "../duoram-online/party0_read_flags_c";
+//    	strcpy(tmp, p0_filename0);
+//  	strcat(tmp, std::to_string(i).c_str());
+//    	 int w1 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+//      written = write(w1, flags[i], db_nitems * sizeof(flags[i][0]));
+//      if(written<0) {
+//              perror("Write error");
+//        }
+//       close(w1);
 	
-	  p0_filename0 = "../duoram-online/party0_read_flags_d";
-	  	strcpy(tmp, p0_filename0);
- 	strcat(tmp, std::to_string(i).c_str());
-   	  int w2 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
-   	   written = write(w2, flags[i], db_nitems * sizeof(flags[i][0]));
+// 	  p0_filename0 = "../duoram-online/party0_read_flags_d";
+// 	  	strcpy(tmp, p0_filename0);
+//  	strcat(tmp, std::to_string(i).c_str());
+//    	  int w2 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+//    	   written = write(w2, flags[i], db_nitems * sizeof(flags[i][0]));
       
-	  if(written<0) {
-             perror("Write error");
-       }  
-	  close(w2);
-
-
-	p0_filename0 = "../duoram-online/party0_write_flags_b";
-		strcpy(tmp, p0_filename0);
- 	strcat(tmp, std::to_string(i).c_str());
-    int w4 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
-    written = write(w4, flags[i], db_nitems * sizeof(flags[i][0]));
-      if(written<0) {
-             perror("Write error");
-       }
-      close(w4);
-
-   p0_filename0 = "../duoram-online/party0_write_flags_c";
-   	strcpy(tmp, p0_filename0);
- 	strcat(tmp, std::to_string(i).c_str());
-    int w5 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
-    written = write(w5, flags[i], db_nitems * sizeof(flags[i][0]));
-      if(written<0) {
-             perror("Write error");
-       }
-      close(w5);
-	  p0_filename0 = "../duoram-online/party0_write_flags_d";
-	  	strcpy(tmp, p0_filename0);
- 	strcat(tmp, std::to_string(i).c_str());
-   	   int w6 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
-   	   written = write(w6, flags[i], db_nitems * sizeof(flags[i][0]));
+// 	  if(written<0) {
+//              perror("Write error");
+//        }  
+// 	  close(w2);
+
+
+// 	p0_filename0 = "../duoram-online/party0_write_flags_b";
+// 		strcpy(tmp, p0_filename0);
+//  	strcat(tmp, std::to_string(i).c_str());
+//     int w4 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+//     written = write(w4, flags[i], db_nitems * sizeof(flags[i][0]));
+//       if(written<0) {
+//              perror("Write error");
+//        }
+//       close(w4);
+
+//    p0_filename0 = "../duoram-online/party0_write_flags_c";
+//    	strcpy(tmp, p0_filename0);
+//  	strcat(tmp, std::to_string(i).c_str());
+//     int w5 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+//     written = write(w5, flags[i], db_nitems * sizeof(flags[i][0]));
+//       if(written<0) {
+//              perror("Write error");
+//        }
+//       close(w5);
+// 	  p0_filename0 = "../duoram-online/party0_write_flags_d";
+// 	  	strcpy(tmp, p0_filename0);
+//  	strcat(tmp, std::to_string(i).c_str());
+//    	   int w6 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+//    	   written = write(w6, flags[i], db_nitems * sizeof(flags[i][0]));
       
-	  if(written<0) {
-             perror("Write error");
-       }
+// 	  if(written<0) {
+//              perror("Write error");
+//        }
       
-	  close(w6);
-
-	p0_filename0 = "../duoram-online/party0_write_b";
-		strcpy(tmp, p0_filename0);
- 	strcat(tmp, std::to_string(i).c_str());
-    w4 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
-    written = write(w4, outs_, db_nitems * sizeof(outs_[0]));
-      if(written<0) {
-             perror("Write error");
-       }
-      close(w4);
-
- 	  p0_filename0 = "../duoram-online/party0_write_c";
-	  	strcpy(tmp, p0_filename0);
- 	strcat(tmp, std::to_string(i).c_str());
-     w5 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
-    written = write(w5, outs_, db_nitems * sizeof(outs_[0]));
-      if(written<0) {
-             perror("Write error");
-       }
-    close(w5);
-
-    p0_filename0 = "../duoram-online/party0_write_d";
-		strcpy(tmp, p0_filename0);
- 	strcat(tmp, std::to_string(i).c_str());
-   	w6 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
-   	written = write(w6, outs_, db_nitems * sizeof(outs_[0]));
+// 	  close(w6);
+
+// 	p0_filename0 = "../duoram-online/party0_write_b";
+// 		strcpy(tmp, p0_filename0);
+//  	strcat(tmp, std::to_string(i).c_str());
+//     w4 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+//     written = write(w4, outs_, db_nitems * sizeof(outs_[0]));
+//       if(written<0) {
+//              perror("Write error");
+//        }
+//       close(w4);
+
+//  	  p0_filename0 = "../duoram-online/party0_write_c";
+// 	  	strcpy(tmp, p0_filename0);
+//  	strcat(tmp, std::to_string(i).c_str());
+//      w5 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+//     written = write(w5, outs_, db_nitems * sizeof(outs_[0]));
+//       if(written<0) {
+//              perror("Write error");
+//        }
+//     close(w5);
+
+//     p0_filename0 = "../duoram-online/party0_write_d";
+// 		strcpy(tmp, p0_filename0);
+//  	strcat(tmp, std::to_string(i).c_str());
+//    	w6 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+//    	written = write(w6, outs_, db_nitems * sizeof(outs_[0]));
       
-	if(written<0) {
-             perror("Write error");
-       }
+// 	if(written<0) {
+//              perror("Write error");
+//        }
       
-	  close(w6);
+// 	  close(w6);
 	  
-  }
-  if(party) 
-  {
-	 char const * p0_filename0;
-	 char tmp[100];
-     p0_filename0 = "../duoram-online/party1_read_flags_b";
-	 strcpy(tmp, p0_filename0);
- 	 strcat(tmp, std::to_string(i).c_str());
+//   }
+//   if(party) 
+//   {
+// 	 char const * p0_filename0;
+// 	 char tmp[100];
+//      p0_filename0 = "../duoram-online/party1_read_flags_b";
+// 	 strcpy(tmp, p0_filename0);
+//  	 strcat(tmp, std::to_string(i).c_str());
      
-	 int w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
-     int written = write(w0, flags[i], db_nitems * sizeof(flags[i][0]));
-     if(written<0) {
-             perror("Write error");
-       }
+// 	 int w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+//      int written = write(w0, flags[i], db_nitems * sizeof(flags[i][0]));
+//      if(written<0) {
+//              perror("Write error");
+//        }
      
-	 close(w0);	
+// 	 close(w0);	
 
-	 p0_filename0 = "../duoram-online/party1_read_flags_c";
-	 strcpy(tmp, p0_filename0);
- 	 strcat(tmp, std::to_string(i).c_str());
+// 	 p0_filename0 = "../duoram-online/party1_read_flags_c";
+// 	 strcpy(tmp, p0_filename0);
+//  	 strcat(tmp, std::to_string(i).c_str());
    	 
-	 int w1 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
-	 written = write(w1, flags[i], db_nitems * sizeof(flags[i][0]));
-	 if(written<0) {
-             perror("Write error");
-       }
-      close(w1);
-
-	  p0_filename0 = "../duoram-online/party1_read_flags_d";
-	  strcpy(tmp, p0_filename0);
- 	  strcat(tmp, std::to_string(i).c_str());
+// 	 int w1 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+// 	 written = write(w1, flags[i], db_nitems * sizeof(flags[i][0]));
+// 	 if(written<0) {
+//              perror("Write error");
+//        }
+//       close(w1);
+
+// 	  p0_filename0 = "../duoram-online/party1_read_flags_d";
+// 	  strcpy(tmp, p0_filename0);
+//  	  strcat(tmp, std::to_string(i).c_str());
    	  
-	  int w2 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
-   	   written = write(w2,flags[i], db_nitems * sizeof(flags[i][0]));
+// 	  int w2 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+//    	   written = write(w2,flags[i], db_nitems * sizeof(flags[i][0]));
       
-	  if(written<0) {
-             perror("Write error");
-       }
+// 	  if(written<0) {
+//              perror("Write error");
+//        }
       
-	  close(w2);
+// 	  close(w2);
 
 
-	p0_filename0 = "../duoram-online/party1_write_flags_b";
-	strcpy(tmp, p0_filename0);
- 	strcat(tmp, std::to_string(i).c_str());
+// 	p0_filename0 = "../duoram-online/party1_write_flags_b";
+// 	strcpy(tmp, p0_filename0);
+//  	strcat(tmp, std::to_string(i).c_str());
     
-	int w4 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
-    written = write(w4,flags[i], db_nitems * sizeof(flags[i][0]));
-      if(written<0) {
-             perror("Write error");
-       }
-      close(w4);
-
-   	p0_filename0 = "../duoram-online/party1_write_flags_c";
-	strcpy(tmp, p0_filename0);
- 	strcat(tmp, std::to_string(i).c_str());
+// 	int w4 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+//     written = write(w4,flags[i], db_nitems * sizeof(flags[i][0]));
+//       if(written<0) {
+//              perror("Write error");
+//        }
+//       close(w4);
+
+//    	p0_filename0 = "../duoram-online/party1_write_flags_c";
+// 	strcpy(tmp, p0_filename0);
+//  	strcat(tmp, std::to_string(i).c_str());
     
-	int w5 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
-    written = write(w5, flags[i], db_nitems * sizeof(flags[i][0]));
-     if(written<0) {
-             perror("Write error");
-       }
-      close(w5);
+// 	int w5 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+//     written = write(w5, flags[i], db_nitems * sizeof(flags[i][0]));
+//      if(written<0) {
+//              perror("Write error");
+//        }
+//       close(w5);
 	
-	p0_filename0 = "../duoram-online/party1_write_flags_d";
-	strcpy(tmp, p0_filename0);
- 	strcat(tmp, std::to_string(i).c_str());
+// 	p0_filename0 = "../duoram-online/party1_write_flags_d";
+// 	strcpy(tmp, p0_filename0);
+//  	strcat(tmp, std::to_string(i).c_str());
    	   
-	int w6 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
-   	written = write(w6, flags[i], db_nitems * sizeof(flags[i][0]));  
-	if(written<0) {
-             perror("Write error");
-       }
+// 	int w6 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+//    	written = write(w6, flags[i], db_nitems * sizeof(flags[i][0]));  
+// 	if(written<0) {
+//              perror("Write error");
+//        }
       
-	close(w6);
-
-	p0_filename0 = "../duoram-online/party1_write_b";
-	strcpy(tmp, p0_filename0);
- 	strcat(tmp, std::to_string(i).c_str());
-
-    w4 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
-    written = write(w4, outs_, db_nitems * sizeof(outs_[0]));
-      if(written<0) {
-             perror("Write error");
-       }
-      close(w4);
-
- //  char const * p0_filename0;
-   p0_filename0 = "../duoram-online/party1_write_c";
-   	strcpy(tmp, p0_filename0);
- 	strcat(tmp, std::to_string(i).c_str());
-    w5 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
-    written = write(w5, outs_, db_nitems * sizeof(outs_[0]));
-      if(written<0) {
-             perror("Write error");
-       }
-      close(w5);
-	  p0_filename0 = "../duoram-online/party1_write_d";
-	  	strcpy(tmp, p0_filename0);
- 	strcat(tmp, std::to_string(i).c_str());
-   	    w6 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
-   	   written = write(w6, outs_, db_nitems * sizeof(outs_[0]));
+// 	close(w6);
+
+// 	p0_filename0 = "../duoram-online/party1_write_b";
+// 	strcpy(tmp, p0_filename0);
+//  	strcat(tmp, std::to_string(i).c_str());
+
+//     w4 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+//     written = write(w4, outs_, db_nitems * sizeof(outs_[0]));
+//       if(written<0) {
+//              perror("Write error");
+//        }
+//       close(w4);
+
+//  //  char const * p0_filename0;
+//    p0_filename0 = "../duoram-online/party1_write_c";
+//    	strcpy(tmp, p0_filename0);
+//  	strcat(tmp, std::to_string(i).c_str());
+//     w5 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+//     written = write(w5, outs_, db_nitems * sizeof(outs_[0]));
+//       if(written<0) {
+//              perror("Write error");
+//        }
+//       close(w5);
+// 	  p0_filename0 = "../duoram-online/party1_write_d";
+// 	  	strcpy(tmp, p0_filename0);
+//  	strcat(tmp, std::to_string(i).c_str());
+//    	    w6 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+//    	   written = write(w6, outs_, db_nitems * sizeof(outs_[0]));
       
-	  if(written<0) {
-             perror("Write error");
-       }
+// 	  if(written<0) {
+//              perror("Write error");
+//        }
       
-	  close(w6);
-  }
-
-  	if(party)
-	{
-		char const * p1_filename0;
-		char tmp[100];
-		p1_filename0 = "../duoram-online/FCW1";
-		strcpy(tmp, p1_filename0);
- 		strcat(tmp, std::to_string(i).c_str());
+// 	  close(w6);
+//   }
+
+//   	if(party)
+// 	{
+// 		char const * p1_filename0;
+// 		char tmp[100];
+// 		p1_filename0 = "../duoram-online/FCW1";
+// 		strcpy(tmp, p1_filename0);
+//  		strcat(tmp, std::to_string(i).c_str());
 		
-		int w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
-		int written = write(w0, &final_correction_word[0][0],  sizeof(final_correction_word[0][0]));
-		if(written<0) {
-				perror("Write error");
-		}
-		close(w0);
-	}
+// 		int w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+// 		int written = write(w0, &final_correction_word[0][0],  sizeof(final_correction_word[0][0]));
+// 		if(written<0) {
+// 				perror("Write error");
+// 		}
+// 		close(w0);
+// 	}
 	
-	if(!party)
-	{
-		char const * p0_filename0;
-		char tmp[100];
-		p0_filename0 = "../duoram-online/FCW0";
-		strcpy(tmp, p0_filename0);
- 		strcat(tmp, std::to_string(i).c_str());
+// 	if(!party)
+// 	{
+// 		char const * p0_filename0;
+// 		char tmp[100];
+// 		p0_filename0 = "../duoram-online/FCW0";
+// 		strcpy(tmp, p0_filename0);
+//  		strcat(tmp, std::to_string(i).c_str());
 		
-		int w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
-		int written = write(w0, &final_correction_word[0][0],  sizeof(final_correction_word[0][0]));
-		if(written<0) {
-				perror("Write error");
-		}
-		close(w0);
-	}
-}
+// 		int w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+// 		int written = write(w0, &final_correction_word[0][0],  sizeof(final_correction_word[0][0]));
+// 		if(written<0) {
+// 				perror("Write error");
+// 		}
+// 		close(w0);
+// 	}
+// }
 
 
 struct cw_construction
@@ -316,6 +316,7 @@ void compute_CW(tcp::socket& sout, tcp::socket& sin, __m128i L, __m128i R, uint8
 
 	cw_construction computecw;
 
+	//Communication from P2 
 	read(sin, boost::asio::buffer(&computecw, sizeof(computecw)));
 
 	__m128i rand_b  = computecw.rand_b;
@@ -345,6 +346,8 @@ void compute_CW(tcp::socket& sout, tcp::socket& sin, __m128i L, __m128i R, uint8
 	BlindsCW blinds_sent, blinds_recv;
 	blinds_sent.blinded_bit = blinded_bit;
 	blinds_sent.blinded_message = blinded_L;
+
+	//exchange blinded shares for OSWAP.
  	boost::asio::write(sout, boost::asio::buffer(&blinds_sent, sizeof(BlindsCW)));
 	boost::asio::read(sout, boost::asio::buffer(&blinds_recv, sizeof(BlindsCW)));
 	
@@ -369,6 +372,8 @@ void compute_CW(tcp::socket& sout, tcp::socket& sin, __m128i L, __m128i R, uint8
 	
 	CW = out_reconstruction;
 	
+
+	// The following asserts the correctness of ComputeCW
 	#ifdef DEBUG
 		uint8_t bit_reconstruction; 
 		boost::asio::write(sout, boost::asio::buffer(&bit, sizeof(bit)));
@@ -399,7 +404,6 @@ void compute_CW(tcp::socket& sout, tcp::socket& sin, __m128i L, __m128i R, uint8
 		assert(CW_debug[0] == CW[0]);
 		assert(CW_debug[1] == CW[1]);
 	#endif
-	
 }
 
 
@@ -409,6 +413,7 @@ static inline void traverse(const prgkey_t & prgkey, const node_t & seed,	node_t
 	dpf::PRG(prgkey, clear_lsb(seed, 0b11), s, 2);
 } // dpf::expand
 
+
 /**
  * @brief 
  * 
@@ -509,6 +514,7 @@ inline void create_dpfs(  size_t db_nitems,
 			compute_CW(socketsPb[socket_no], socketsP2[socket_no], L,  R, target_share[layer], CW[layer]);
 
 			uint8_t 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);
 			
@@ -520,8 +526,7 @@ inline void create_dpfs(  size_t db_nitems,
 					std::cout << "			   cwt_R = " << (int) cwt_R << std::endl;
 				}
 			#endif
-			
-			
+
 			dpf_instance.CW[layer] 		=  CW[layer];
 			dpf_instance.cwt_L[layer]   =  cwt_L;
 			dpf_instance.cwt_R[layer]   =  cwt_R;

+ 244 - 0
preprocessing/filesio.h

@@ -0,0 +1,244 @@
+void write_evalfull_outs_into_a_file(bool party, size_t i, size_t db_nitems,  int8_t ** flags, int64_t * outs_, __m128i * final_correction_word)
+{
+ if(!party) 
+ {  
+   	char const * p0_filename0;
+	char tmp[100];
+   	p0_filename0 = "../duoram-online/party0_read_flags_b";
+	strcpy(tmp, p0_filename0);
+ 	strcat(tmp, std::to_string(i).c_str());
+	
+	int w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+   	int written = write(w0, flags[i], db_nitems * sizeof(flags[i][0]));
+      if(written<0) {
+             perror("Write error");
+       }
+      close(w0);
+
+ 	 p0_filename0 = "../duoram-online/party0_read_flags_c";
+   	strcpy(tmp, p0_filename0);
+ 	strcat(tmp, std::to_string(i).c_str());
+   	 int w1 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+     written = write(w1, flags[i], db_nitems * sizeof(flags[i][0]));
+     if(written<0) {
+             perror("Write error");
+       }
+      close(w1);
+	
+	  p0_filename0 = "../duoram-online/party0_read_flags_d";
+	  	strcpy(tmp, p0_filename0);
+ 	strcat(tmp, std::to_string(i).c_str());
+   	  int w2 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+   	   written = write(w2, flags[i], db_nitems * sizeof(flags[i][0]));
+      
+	  if(written<0) {
+             perror("Write error");
+       }  
+	  close(w2);
+
+
+	p0_filename0 = "../duoram-online/party0_write_flags_b";
+		strcpy(tmp, p0_filename0);
+ 	strcat(tmp, std::to_string(i).c_str());
+    int w4 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+    written = write(w4, flags[i], db_nitems * sizeof(flags[i][0]));
+      if(written<0) {
+             perror("Write error");
+       }
+      close(w4);
+
+   p0_filename0 = "../duoram-online/party0_write_flags_c";
+   	strcpy(tmp, p0_filename0);
+ 	strcat(tmp, std::to_string(i).c_str());
+    int w5 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+    written = write(w5, flags[i], db_nitems * sizeof(flags[i][0]));
+      if(written<0) {
+             perror("Write error");
+       }
+      close(w5);
+	  p0_filename0 = "../duoram-online/party0_write_flags_d";
+	  	strcpy(tmp, p0_filename0);
+ 	strcat(tmp, std::to_string(i).c_str());
+   	   int w6 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+   	   written = write(w6, flags[i], db_nitems * sizeof(flags[i][0]));
+      
+	  if(written<0) {
+             perror("Write error");
+       }
+      
+	  close(w6);
+
+	p0_filename0 = "../duoram-online/party0_write_b";
+		strcpy(tmp, p0_filename0);
+ 	strcat(tmp, std::to_string(i).c_str());
+    w4 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+    written = write(w4, outs_, db_nitems * sizeof(outs_[0]));
+      if(written<0) {
+             perror("Write error");
+       }
+      close(w4);
+
+ 	  p0_filename0 = "../duoram-online/party0_write_c";
+	  	strcpy(tmp, p0_filename0);
+ 	strcat(tmp, std::to_string(i).c_str());
+     w5 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+    written = write(w5, outs_, db_nitems * sizeof(outs_[0]));
+      if(written<0) {
+             perror("Write error");
+       }
+    close(w5);
+
+    p0_filename0 = "../duoram-online/party0_write_d";
+		strcpy(tmp, p0_filename0);
+ 	strcat(tmp, std::to_string(i).c_str());
+   	w6 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+   	written = write(w6, outs_, db_nitems * sizeof(outs_[0]));
+      
+	if(written<0) {
+             perror("Write error");
+       }
+      
+	  close(w6);
+	  
+  }
+  if(party) 
+  {
+	 char const * p0_filename0;
+	 char tmp[100];
+     p0_filename0 = "../duoram-online/party1_read_flags_b";
+	 strcpy(tmp, p0_filename0);
+ 	 strcat(tmp, std::to_string(i).c_str());
+     
+	 int w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+     int written = write(w0, flags[i], db_nitems * sizeof(flags[i][0]));
+     if(written<0) {
+             perror("Write error");
+       }
+     
+	 close(w0);	
+
+	 p0_filename0 = "../duoram-online/party1_read_flags_c";
+	 strcpy(tmp, p0_filename0);
+ 	 strcat(tmp, std::to_string(i).c_str());
+   	 
+	 int w1 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+	 written = write(w1, flags[i], db_nitems * sizeof(flags[i][0]));
+	 if(written<0) {
+             perror("Write error");
+       }
+      close(w1);
+
+	  p0_filename0 = "../duoram-online/party1_read_flags_d";
+	  strcpy(tmp, p0_filename0);
+ 	  strcat(tmp, std::to_string(i).c_str());
+   	  
+	  int w2 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+   	   written = write(w2,flags[i], db_nitems * sizeof(flags[i][0]));
+      
+	  if(written<0) {
+             perror("Write error");
+       }
+      
+	  close(w2);
+
+
+	p0_filename0 = "../duoram-online/party1_write_flags_b";
+	strcpy(tmp, p0_filename0);
+ 	strcat(tmp, std::to_string(i).c_str());
+    
+	int w4 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+    written = write(w4,flags[i], db_nitems * sizeof(flags[i][0]));
+      if(written<0) {
+             perror("Write error");
+       }
+      close(w4);
+
+   	p0_filename0 = "../duoram-online/party1_write_flags_c";
+	strcpy(tmp, p0_filename0);
+ 	strcat(tmp, std::to_string(i).c_str());
+    
+	int w5 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+    written = write(w5, flags[i], db_nitems * sizeof(flags[i][0]));
+     if(written<0) {
+             perror("Write error");
+       }
+      close(w5);
+	
+	p0_filename0 = "../duoram-online/party1_write_flags_d";
+	strcpy(tmp, p0_filename0);
+ 	strcat(tmp, std::to_string(i).c_str());
+   	   
+	int w6 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+   	written = write(w6, flags[i], db_nitems * sizeof(flags[i][0]));  
+	if(written<0) {
+             perror("Write error");
+       }
+      
+	close(w6);
+
+	p0_filename0 = "../duoram-online/party1_write_b";
+	strcpy(tmp, p0_filename0);
+ 	strcat(tmp, std::to_string(i).c_str());
+
+    w4 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+    written = write(w4, outs_, db_nitems * sizeof(outs_[0]));
+      if(written<0) {
+             perror("Write error");
+       }
+      close(w4);
+
+ //  char const * p0_filename0;
+   p0_filename0 = "../duoram-online/party1_write_c";
+   	strcpy(tmp, p0_filename0);
+ 	strcat(tmp, std::to_string(i).c_str());
+    w5 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+    written = write(w5, outs_, db_nitems * sizeof(outs_[0]));
+      if(written<0) {
+             perror("Write error");
+       }
+      close(w5);
+	  p0_filename0 = "../duoram-online/party1_write_d";
+	  	strcpy(tmp, p0_filename0);
+ 	strcat(tmp, std::to_string(i).c_str());
+   	    w6 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+   	   written = write(w6, outs_, db_nitems * sizeof(outs_[0]));
+      
+	  if(written<0) {
+             perror("Write error");
+       }
+      
+	  close(w6);
+  }
+
+  	if(party)
+	{
+		char const * p1_filename0;
+		char tmp[100];
+		p1_filename0 = "../duoram-online/FCW1";
+		strcpy(tmp, p1_filename0);
+ 		strcat(tmp, std::to_string(i).c_str());
+		
+		int w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+		int written = write(w0, &final_correction_word[0][0],  sizeof(final_correction_word[0][0]));
+		if(written<0) {
+				perror("Write error");
+		}
+		close(w0);
+	}
+	
+	if(!party)
+	{
+		char const * p0_filename0;
+		char tmp[100];
+		p0_filename0 = "../duoram-online/FCW0";
+		strcpy(tmp, p0_filename0);
+ 		strcat(tmp, std::to_string(i).c_str());
+		
+		int w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+		int written = write(w0, &final_correction_word[0][0],  sizeof(final_correction_word[0][0]));
+		if(written<0) {
+				perror("Write error");
+		}
+		close(w0);
+	}
+}

+ 5 - 9
preprocessing/p2preprocessing.cpp

@@ -25,7 +25,7 @@
 #include "bitutils.h"
 #include "block.h"
 #include "prg_aes_impl.h" 
-
+#include "filesio.h"
 using boost::asio::ip::tcp;
 
 using namespace dpf;
@@ -52,11 +52,6 @@ size_t __depth(const size_t nitems) { return std::ceil(std::log2(std::ceil(stati
 #include "dpfgen.h"
 #include "share-conversion.h"
 
-void convert_sharesP2(std::vector<socket_t>& sockets0, std::vector<socket_t>& sockets1, size_t socket_no = 0)
-{ 
-  du_attalah_P2(sockets0, sockets1, socket_no); 
-} 
-
 void mpc_gen(const size_t depth, AES_KEY& prgkey, const size_t db_nitems, const size_t n_threads, std::vector<socket_t>& sockets0, std::vector<socket_t>& sockets1, 
              __m128i** output0, int8_t ** flags0, __m128i* final_correction_word0,  __m128i** output1, int8_t ** flags1, __m128i* final_correction_word1, 
             size_t socket_no = 0)
@@ -121,9 +116,8 @@ void mpc_gen(const size_t depth, AES_KEY& prgkey, const size_t db_nitems, const
   #ifdef DEBUG
     for(size_t j = 0; j < db_nitems; ++j)
     {
-    
-      std::cout << j << "-> "  << (int) flags[0][j] << " <-> " << (int) flags1[0][j] << std::endl;
-      std::cout << j << "-> " << output[0][j][0] << " <-> " << output1[0][j][0] << std::endl << std::endl;
+      std::cout << j << "-> "  << (int) flags0[0][j] << " <-> " << (int) flags1[0][j] << std::endl;
+      std::cout << j << "-> " << output0[0][j][0] << " <-> " << output1[0][j][0] << std::endl << std::endl;
     }
   #endif
 }
@@ -216,6 +210,7 @@ int main(int argc, char* argv[])
 
   boost::asio::thread_pool pool3(n_threads); 
 
+ /* The function convert_sharesP2 appears in share-conversion.h */
   for(size_t j = 0; j < n_threads; ++j)
   {
      boost::asio::post(pool3, std::bind(convert_sharesP2, std::ref(sockets0), std::ref(sockets1), j));    
@@ -223,6 +218,7 @@ int main(int argc, char* argv[])
 
   pool3.join(); 
   
+  /* The function P2_xor_to_additive appears in share-conversion.h */
   P2_xor_to_additive(sockets0, sockets1, 0);
   
   return 0;

+ 1 - 1
preprocessing/preprocessing.cpp

@@ -28,7 +28,7 @@
 #include "bitutils.h"
 #include "block.h" 
 #include "prg_aes_impl.h"
- 
+#include "filesio.h"
 
 using boost::asio::ip::tcp;
 using socket_t = boost::asio::ip::tcp::socket;