Browse Source

few ifdefs

avadapal 1 year ago
parent
commit
7b437f3861
4 changed files with 98 additions and 112 deletions
  1. 1 1
      duoram-online/Makefile
  2. 4 3
      duoram-online/duoram-write.h
  3. 93 81
      duoram-online/duoram.cpp
  4. 0 27
      duoram-online/p2.cpp

+ 1 - 1
duoram-online/Makefile

@@ -24,7 +24,7 @@
 CXX = g++
 CXXFLAGS = -g -march=native -std=c++17 -Wall -pedantic -fopenmp -O3 -Wno-ignored-attributes -pthread
 LIBS = -lbsd
-FLAGS =  -DBOOST_ERROR_CODE_HEADER_ONLY
+FLAGS =  -DBOOST_ERROR_CODE_HEADER_ONLY -DThreeParty
 
 all: setup duoram0 duoram1 p2
 

+ 4 - 3
duoram-online/duoram-write.h

@@ -85,7 +85,8 @@ auto DuoramUpdate(bool party, size_t db_nitems,   size_t rotate_by_,
    			
 			  write_into_the_database(DB, updated_DB, writing_b, b, final_CW, party, db_nitems, - rotate_by_);
 			
-			if(!party) duoram_refresh(writing_b, writing_c, writing_d, b, c, d,  final_CW, party, db_nitems, -rotate_by_); 
-			
-			if( party) duoram_refresh(writing_b, writing_d, writing_c, b, d, c,  final_CW, party, db_nitems, -rotate_by_); 
+			#ifdef ThreeParty
+				if(!party) duoram_refresh(writing_b, writing_c, writing_d, b, c, d,  final_CW, party, db_nitems, -rotate_by_); 			
+				if( party) duoram_refresh(writing_b, writing_d, writing_c, b, d, c,  final_CW, party, db_nitems, -rotate_by_); 
+			#endif
 }

+ 93 - 81
duoram-online/duoram.cpp

@@ -144,13 +144,14 @@ int main(const int argc, const char * argv[])
   	 
   	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])}));
-     sockets_2.emplace_back(std::move(sb_a)); 
-   }
+	#ifdef ThreeParty	
+		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])}));
+			sockets_2.emplace_back(std::move(sb_a)); 
+		}
+	#endif
  
     for(size_t j = 0; j < number_of_sockets; ++j)
     {
@@ -161,14 +162,16 @@ int main(const int argc, const char * argv[])
  #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])}));
-     sockets_2.emplace_back(std::move(sb_a)); 
-   }
-
+ 	
+	#ifdef ThreeParty	
+	  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])}));
+   		sockets_2.emplace_back(std::move(sb_a)); 
+	  }
+	#endif
+   
    boost::asio::thread_pool pool2(number_of_sockets); 
    for(size_t j = 0; j < number_of_sockets; ++j)
    {
@@ -187,8 +190,9 @@ int main(const int argc, const char * argv[])
  
 
 	block<__m128i> seed;
-  
-    read(sockets_2[0], boost::asio::buffer(&seed, sizeof(seed)));
+	#ifdef ThreeParty	
+    	read(sockets_2[0], boost::asio::buffer(&seed, sizeof(seed)));
+	#endif
     blinds =	(DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));	
     updated_blinds =	(DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
 
@@ -233,79 +237,86 @@ int main(const int argc, const char * argv[])
 	  	int64_t ri_reconstruction = ri + ri_recv;
 	  	std::cout << "ri_reconstruction = " << ri_reconstruction << std::endl;
 
-	  	DuORAM_Write * WritePb_     = new DuORAM_Write[number_of_writes];
-	  	DuORAM_Write * WritePb_recv = new DuORAM_Write[number_of_writes];
- 	  	
+		#ifdef ThreeParty
+			DuORAM_Write * WritePb_     = new DuORAM_Write[number_of_writes];
+			DuORAM_Write * WritePb_recv = new DuORAM_Write[number_of_writes];
+			DB_t * read_out = new DB_t[number_of_writes];
+			DB_t * Gamma =  new DB_t[number_of_writes];
+		#endif
+		
 		DB_t * CW = new DB_t[number_of_writes];  
-	 	DB_t * read_out = new DB_t[number_of_writes];
+	 	
 		DB_t * update_message = new DB_t[number_of_writes];
-		DB_t * Gamma =  new DB_t[number_of_writes];
+		
 		 
 		auto start_writes = std::chrono::steady_clock::now();
-		
-		for(size_t w = 0; w < number_of_writes; ++w)
-		{
-			DB_t FCW_read = 0;
-
-			read_final_correction_word(party, FCW_read);
-			std::cout << "FCW_read (from) = " << FCW_read << std::endl;	
-			DB_t alpha0 = -FCW_read;
-			WritePb_[w].shift = where_to_write[w] -ri;
-			WritePb_[w].CW = distinguised_value[0];
-			boost::asio::write(sockets_2[0], boost::asio::buffer(&WritePb_[w],   sizeof(DuORAM_Write)));
-			read(sockets_2[1], boost::asio::buffer(&Gamma[w],  sizeof(DB_t))); 
-			boost::asio::write(sockets_[0],  boost::asio::buffer(&WritePb_[w],    sizeof(DuORAM_Write)));
-			boost::asio::read(sockets_[0],   boost::asio::buffer(&WritePb_recv[w], sizeof(DuORAM_Write)));
-				
-		 	read_flags(party, db_nitems);
- 
-			rotate_by_[w] = WritePb_[w].shift + WritePb_recv[w].shift;		 			
-
-			#ifdef DEBUG 		
-				std::cout << "print database: " << std::endl;							
-				reconstruct_database(sockets_[0],  DB, db_nitems);
-			#endif
 
-			for(size_t j = 0; j < db_nitems; ++j) reading_temp[j] = DB[j] + updated_blinded_DB_recv[j];
-					 	
-			if(!party) read_out[w] 		=   dot_product_with_bool(reading_temp,   writing_b, db_nitems, rotate_by_[w]) + 
-											dot_product_with_bool(updated_blinds, writing_b, db_nitems, rotate_by_[w]) - 
-											dot_product_with_bool(updated_blinds, writing_c, db_nitems, rotate_by_[w]) + Gamma[w];
-					  	
-			if(party)  read_out[w] 		=   dot_product_with_bool(reading_temp,   writing_c, db_nitems, rotate_by_[w]) + 
-											dot_product_with_bool(updated_blinds, writing_c, db_nitems, rotate_by_[w])	- 
-											dot_product_with_bool(updated_blinds, writing_d, db_nitems, rotate_by_[w]) + Gamma[w];
-					    
-			//#ifdef DEBUG
-				std::cout << "read_out[" << w << "] = " << read_out[w] << std::endl;
-			//#endif
-
-			//#ifdef DEBUG
-			std::cout << "reconstructing the output: " << print_reconstruction(sockets_[0], read_out[w]) << "\n";	
-			//#endif
-		
-			distinguised_value[0] = 80 * (1 + w);
-			update_message[w] = distinguised_value[0] - read_out[w]   + alpha0;
-
-			#ifdef DEBUG
-				std::cout << "-> The updated message shares is " << update_message[w] << std::endl;
-			#endif 
-			boost::asio::write(sockets_2[2], boost::asio::buffer(&update_message[w],  sizeof(DB_t)));
-	  		boost::asio::write(sockets_[2], boost::asio::buffer(&update_message[w], sizeof(DB_t)));
-	 		boost::asio::read(sockets_[2], boost::asio::buffer(&CW[w], sizeof(DB_t)));
-				
-		 	CW[w] = CW[w] + update_message[w];
-
-			#ifdef DEBUG
-				std::cout << "cw = " << CW[w] << std::endl;
-			#endif 
-		}
+		#ifdef ThreeParty
+			for(size_t w = 0; w < number_of_writes; ++w)
+			{
+				DB_t FCW_read = 0;
+
+				read_final_correction_word(party, FCW_read);
+				std::cout << "FCW_read (from) = " << FCW_read << std::endl;	
+				DB_t alpha0 = -FCW_read;
+				WritePb_[w].shift = where_to_write[w] -ri;
+				WritePb_[w].CW = distinguised_value[0];
+				boost::asio::write(sockets_2[0], boost::asio::buffer(&WritePb_[w],   sizeof(DuORAM_Write)));
+				read(sockets_2[1], boost::asio::buffer(&Gamma[w],  sizeof(DB_t))); 
+				boost::asio::write(sockets_[0],  boost::asio::buffer(&WritePb_[w],    sizeof(DuORAM_Write)));
+				boost::asio::read(sockets_[0],   boost::asio::buffer(&WritePb_recv[w], sizeof(DuORAM_Write)));
+					
+				read_flags(party, db_nitems);
 	
+				rotate_by_[w] = WritePb_[w].shift + WritePb_recv[w].shift;		 			
+
+				#ifdef DEBUG 		
+					std::cout << "print database: " << std::endl;							
+					reconstruct_database(sockets_[0],  DB, db_nitems);
+				#endif
+
+				for(size_t j = 0; j < db_nitems; ++j) reading_temp[j] = DB[j] + updated_blinded_DB_recv[j];
+							
+				if(!party) read_out[w] 		=   dot_product_with_bool(reading_temp,   writing_b, db_nitems, rotate_by_[w]) + 
+												dot_product_with_bool(updated_blinds, writing_b, db_nitems, rotate_by_[w]) - 
+												dot_product_with_bool(updated_blinds, writing_c, db_nitems, rotate_by_[w]) + Gamma[w];
+							
+				if(party)  read_out[w] 		=   dot_product_with_bool(reading_temp,   writing_c, db_nitems, rotate_by_[w]) + 
+												dot_product_with_bool(updated_blinds, writing_c, db_nitems, rotate_by_[w])	- 
+												dot_product_with_bool(updated_blinds, writing_d, db_nitems, rotate_by_[w]) + Gamma[w];
+							
+				//#ifdef DEBUG
+					std::cout << "read_out[" << w << "] = " << read_out[w] << std::endl;
+				//#endif
+
+				//#ifdef DEBUG
+				std::cout << "reconstructing the output: " << print_reconstruction(sockets_[0], read_out[w]) << "\n";	
+				//#endif
+			
+				distinguised_value[0] = 80 * (1 + w);
+				update_message[w] = distinguised_value[0] - read_out[w]   + alpha0;
+
+				#ifdef DEBUG
+					std::cout << "-> The updated message shares is " << update_message[w] << std::endl;
+				#endif 
+				boost::asio::write(sockets_2[2], boost::asio::buffer(&update_message[w],  sizeof(DB_t)));
+				boost::asio::write(sockets_[2], boost::asio::buffer(&update_message[w], sizeof(DB_t)));
+				boost::asio::read(sockets_[2], boost::asio::buffer(&CW[w], sizeof(DB_t)));
+					
+				CW[w] = CW[w] + update_message[w];
+
+				#ifdef DEBUG
+					std::cout << "cw = " << CW[w] << std::endl;
+				#endif 
+			}
+		#endif
 		for(size_t w = 0; w < number_of_writes; ++w)
  		{		 
 		  	DuoramUpdate(party,  db_nitems,  rotate_by_[w],  DB, updated_DB, writing_b, b,  CW[w],  update_message[w],  writing_c, writing_d, c, d);
 		//	#ifdef DEBUG		
-			debug_(sockets_2[0], sockets_[0], db_nitems);
+			#ifdef ThreeParty
+				debug_(sockets_2[0], sockets_[0], db_nitems);
+			#endif
 		//	#endif
  	 	}  
 
@@ -317,6 +328,7 @@ int main(const int argc, const char * argv[])
 
 
 	// WRITES END.
+  #ifdef ThreeParty
 
 	printf("\n\n================================= WRITES END =================================\n\n\n");	
  	auto start_ind_reads = std::chrono::steady_clock::now();
@@ -386,7 +398,7 @@ int main(const int argc, const char * argv[])
 		printf("\n\n\n\n\n-----------------------------------------------------------------------------------------------------------\n\n\n\n\n\n");
 
  
-
+#endif
      
    auto end_total = std::chrono::steady_clock::now();
    std::chrono::duration<double> elapsed_seconds_total = end_total - start_total;

+ 0 - 27
duoram-online/p2.cpp

@@ -120,38 +120,11 @@ void refresh_blinds(int8_t writing_c[], int8_t writing_d[],
                     DB_t c[], DB_t d[],
                     DB_t finalcw0, DB_t finalcw1, size_t db_nitems, size_t rotate_by = 0)
 {
-  // DB_t tmp0 = 0;
-  // DB_t tmp1 = 0;
   for(size_t j = 0; j < db_nitems; ++j)
   {
-
-    // if(writing_c[j] != 0) 
-    // {
-    //   tmp0 = finalcw0;
-    // }
-    // else 
-    //   tmp0 = 0;
-    // }
-
-    // if(writing_d[j] != 0) 
-    // {
-    //   tmp1 = finalcw1;
-    // }
-    // else
-    // {
-    //   tmp1 = 0;
-    // }
-    
-    // X0[j] = X0[j] - c[(j + rotate_by) % db_nitems] + ((writing_c[(j + rotate_by) % db_nitems] != 0) ? finalcw0: 0);//   tmp0; //c0
-    // X1[j] = X1[j] - d[(j + rotate_by) % db_nitems] - ((writing_d[(j + rotate_by) % db_nitems] != 0) ? finalcw1: 0);; //c2
-
     X0[j] = X0[j] - c[(j + rotate_by) % db_nitems] - ((writing_c[(j + rotate_by) % db_nitems]) * finalcw0);//   tmp0; //c0
     X1[j] = X1[j] - d[(j + rotate_by) % db_nitems] - ((writing_d[(j + rotate_by) % db_nitems]) * finalcw1); //c2
-
-  //  std::cout << "X0 <-> X1 " << X0[j] << " " << X1[j] << std::endl;
   }
-
-
 }