avadapal 1 rok pred
rodič
commit
89d8f8a8b6
3 zmenil súbory, kde vykonal 107 pridanie a 99 odobranie
  1. 14 11
      duoram-online/duoram-read.h
  2. 53 49
      duoram-online/duoram.cpp
  3. 40 39
      duoram-online/p2.cpp

+ 14 - 11
duoram-online/duoram-read.h

@@ -13,7 +13,9 @@ auto DuoramRead(bool party, size_t db_nitems, int64_t ri, int64_t where_to_read,
     
 	rotate =  WritePb_ind_reads + WritePb_ind_reads_recv;
 
-	std::cout << "[dependent reads] " << " rotate = " << rotate << std::endl;
+	#ifdef VERBOSE
+		std::cout << "[dependent reads] " << " rotate = " << rotate << std::endl;
+	#endif
 
 	read(s2_b, boost::asio::buffer(&Gamma, sizeof(Gamma)));
 
@@ -40,18 +42,19 @@ auto DuoramRead(bool party, size_t db_nitems, int64_t ri, int64_t where_to_read,
 auto DuoramIndependentRead(bool party, size_t db_nitems, int64_t ri, DB_t * Gamma_reads, size_t * rotate, size_t r)
 {
 
-           read_flags(party, db_nitems); 
-            DB_t output = 0;
+	read_flags(party, db_nitems); 
+	
+	DB_t output = 0;
 
-		 	for(size_t j = 0; j < db_nitems; ++j) reading_temp[j] =  DB[j] + updated_blinded_DB_recv[j];
-		    
-			if(!party) output =   dot_product_with_bool(reading_temp, 	reading_b, db_nitems, rotate[r]) + 
-								  dot_product_with_bool(updated_blinds, reading_b, db_nitems, rotate[r]) - 
-								  dot_product_with_bool(updated_blinds, reading_c, db_nitems, rotate[r]) + Gamma_reads[r];
+	for(size_t j = 0; j < db_nitems; ++j) reading_temp[j] =  DB[j] + updated_blinded_DB_recv[j];
+	
+	if(!party) output =   dot_product_with_bool(reading_temp, 	reading_b, db_nitems, rotate[r]) + 
+							dot_product_with_bool(updated_blinds, reading_b, db_nitems, rotate[r]) - 
+							dot_product_with_bool(updated_blinds, reading_c, db_nitems, rotate[r]) + Gamma_reads[r];
 
-		  	if(party)  output =   dot_product_with_bool(reading_temp, 	reading_c, db_nitems, rotate[r]) + 
-								  dot_product_with_bool(updated_blinds, reading_c, db_nitems, rotate[r]) - 
-								  dot_product_with_bool(updated_blinds, reading_d, db_nitems, rotate[r]) + Gamma_reads[r];
+	if(party)  output =   dot_product_with_bool(reading_temp, 	reading_c, db_nitems, rotate[r]) + 
+							dot_product_with_bool(updated_blinds, reading_c, db_nitems, rotate[r]) - 
+							dot_product_with_bool(updated_blinds, reading_d, db_nitems, rotate[r]) + Gamma_reads[r];
 
 
     return output;

+ 53 - 49
duoram-online/duoram.cpp

@@ -64,11 +64,12 @@ int main(const int argc, const char * argv[])
 	 size_t expo =  atoi(argv[3]);
 	 size_t db_nitems = 1ULL << expo;
   
-   size_t number_of_writes	   =  atoi(argv[4]);;
-   size_t number_of_ind_reads  =  atoi(argv[5]);; 
-   size_t number_of_dep_reads  =  atoi(argv[6]);;
- 	
- 	reading_temp = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
+   size_t number_of_writes	   =  atoi(argv[4]);
+   size_t number_of_ind_reads  =  atoi(argv[5]); 
+   size_t number_of_dep_reads  =  atoi(argv[6]);
+   size_t number_of_accesses   =  atoi(argv[7]);
+   
+   reading_temp = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
  	
   	DB = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
  	updated_DB = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
@@ -197,9 +198,13 @@ int main(const int argc, const char * argv[])
    	
 	auto start_total = std::chrono::steady_clock::now();
 	
+
 		size_t * where_to_write = new size_t[number_of_writes];
 		size_t * where_to_read_dependent = new size_t[number_of_dep_reads];
 		size_t * where_to_read_independent = new size_t[number_of_ind_reads];
+	
+	for(size_t i = 0; i < number_of_accesses; ++i)
+	{
 		for(size_t j = 0; j < number_of_writes; ++j)
 		{
 			where_to_write[j] = j + 4;
@@ -227,13 +232,15 @@ int main(const int argc, const char * argv[])
 		
 	  	std::cout << "ri = " << ri << std::endl;
       	if(party) ri = 2 - ri_recv;
- 
-	  	boost::asio::write(sockets_[0], boost::asio::buffer(&ri, sizeof(ri)));
-	  	boost::asio::read(sockets_[0], boost::asio::buffer(&ri_recv, sizeof(ri_recv)));
-	
-	  	int64_t ri_reconstruction = ri + ri_recv;
-	  	std::cout << "ri_reconstruction = " << ri_reconstruction << std::endl;
 
+		#ifdef VERBOSE
+			boost::asio::write(sockets_[0], boost::asio::buffer(&ri, sizeof(ri)));
+			boost::asio::read(sockets_[0], boost::asio::buffer(&ri_recv, sizeof(ri_recv)));
+		
+			int64_t ri_reconstruction = ri + ri_recv;
+			std::cout << "ri_reconstruction = " << ri_reconstruction << std::endl;
+		#endif
+		
 		#ifdef ThreeParty
 			DuORAM_Write * WritePb_     = new DuORAM_Write[number_of_writes];
 			DuORAM_Write * WritePb_recv = new DuORAM_Write[number_of_writes];
@@ -242,10 +249,8 @@ int main(const int argc, const char * argv[])
 		#endif
 
 		DB_t * CW = new DB_t[number_of_writes];  
-	 	
 		DB_t * update_message = new DB_t[number_of_writes];
-		
-		 
+
 		auto start_writes = std::chrono::steady_clock::now();
 
 		#ifdef ThreeParty
@@ -254,7 +259,11 @@ int main(const int argc, const char * argv[])
 				DB_t FCW_read = 0;
 
 				read_final_correction_word(party, FCW_read);
-				std::cout << "FCW_read (from) = " << FCW_read << std::endl;	
+				
+				#ifdef VERBOSE
+					std::cout << "FCW_read (from) = " << FCW_read << std::endl;	
+				#endif
+
 				DB_t alpha0 = -FCW_read;
 				WritePb_[w].shift = where_to_write[w] -ri;
 				WritePb_[w].CW = distinguised_value[0];
@@ -267,7 +276,7 @@ int main(const int argc, const char * argv[])
 	
 				rotate_by_[w] = WritePb_[w].shift + WritePb_recv[w].shift;		 			
 
-				#ifdef DEBUG 		
+				#ifdef VERBOSE 		
 					std::cout << "print database: " << std::endl;							
 					reconstruct_database(sockets_[0],  DB, db_nitems);
 				#endif
@@ -311,40 +320,38 @@ int main(const int argc, const char * argv[])
 		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		
-			#ifdef ThreeParty
-				debug_(sockets_2[0], sockets_[0], db_nitems);
+			#ifdef DEBUG		
+				#ifdef ThreeParty
+					debug_(sockets_2[0], sockets_[0], db_nitems);
+				#endif
 			#endif
-		//	#endif
  	 	}  
 
-   auto end_writes = std::chrono::steady_clock::now();
-   std::chrono::duration<double> elapsed_seconds_writes = end_writes - start_writes;
-   printf("elapsed_seconds_writes = %f\n",elapsed_seconds_writes.count());
+   	auto end_writes = std::chrono::steady_clock::now();
+   	std::chrono::duration<double> elapsed_seconds_writes = end_writes - start_writes;
+   	printf("elapsed_seconds_writes = %f\n",elapsed_seconds_writes.count());
 	
-	reconstruct_database(sockets_[0],  DB, db_nitems);
-
+	#ifdef VERBOSE
+		reconstruct_database(sockets_[0],  DB, db_nitems);
+	#endif
 
 	// WRITES END.
-  #ifdef ThreeParty
+  	#ifdef ThreeParty
 
-	printf("\n\n================================= WRITES END =================================\n\n\n");	
- 	auto start_ind_reads = std::chrono::steady_clock::now();
-	size_t * WritePb_ind_reads = new size_t[number_of_ind_reads];
-	size_t * WritePb_ind_reads_recv = new size_t[number_of_ind_reads];
-	size_t *  rotate = new size_t[number_of_ind_reads];
+		printf("\n\n================================= WRITES END =================================\n\n\n");	
+ 		auto start_ind_reads = std::chrono::steady_clock::now();
+		size_t *  WritePb_ind_reads = new size_t[number_of_ind_reads];
+		size_t *  WritePb_ind_reads_recv = new size_t[number_of_ind_reads];
+		size_t *  rotate = new size_t[number_of_ind_reads];
 	 	 
-	 	// size_t * WritePb_ind_reads      = new size_t[number_of_ind_reads];
-	 	// size_t * WritePb_ind_reads_recv = new size_t[number_of_ind_reads];
-	 	// size_t * rotate                 = new size_t[number_of_ind_reads];
 	 	
 	 	for(size_t r = 0; r < number_of_ind_reads; ++r) WritePb_ind_reads[r] = where_to_read_independent[r] -ri;
 
 	  	boost::asio::write(sockets_2[3], boost::asio::buffer(WritePb_ind_reads, number_of_ind_reads * sizeof(size_t)));
 	  	boost::asio::write(sockets_[3], boost::asio::buffer(WritePb_ind_reads, number_of_ind_reads * sizeof(size_t)));
 	  	boost::asio::read(sockets_[3], boost::asio::buffer(WritePb_ind_reads_recv, number_of_ind_reads * sizeof(size_t)));
-	 	// //std::array<DB_t, number_of_ind_reads> Gamma_reads;
- 		DB_t * Gamma_reads = new DB_t[number_of_ind_reads];
+	 	
+		DB_t * Gamma_reads = new DB_t[number_of_ind_reads];
  		boost::asio::read(sockets_2[4], boost::asio::buffer(Gamma_reads, number_of_ind_reads * sizeof(DB_t)));
 
 		for(size_t j = 0; j < number_of_ind_reads; ++j)
@@ -352,19 +359,19 @@ int main(const int argc, const char * argv[])
 			rotate[j] = WritePb_ind_reads[j] + WritePb_ind_reads_recv[j];
 		}
 
-		
+		DB_t * read_out_independent_reads = new DB_t[number_of_ind_reads];
 		for(size_t r = 0; r < number_of_ind_reads; ++r)
 		{
-	 		#ifdef DEBUG
+	 		#ifdef VERBOSE
 		    	std::cout << "rotate[r]" << rotate[r] << std::endl; 
 		    	std::cout << "Gamma_reads[r] = " << Gamma_reads[r] << std::endl;
 		    #endif
 			
-			auto output = DuoramIndependentRead(party,  db_nitems,  ri, Gamma_reads,  rotate,  r);
+			read_out_independent_reads[r] = DuoramIndependentRead(party,  db_nitems,  ri, Gamma_reads,  rotate,  r);
 
-		   // #ifdef DEBUG
-		  	std::cout << "---> [duoram independent reads] " <<  print_reconstruction(sockets_[0], output) << std::endl;
-		   // #endif
+		    #ifdef VERBOSE
+		  		std::cout << "---> [duoram independent reads] " <<  print_reconstruction(sockets_[0], read_out_independent_reads[r]) << std::endl;
+		    #endif
 	    }
 
   	auto end_ind_reads = std::chrono::steady_clock::now();
@@ -380,11 +387,10 @@ int main(const int argc, const char * argv[])
 	 {
 		  read_out_dependent_reads[r] = DuoramRead(party, db_nitems, ri, where_to_read_dependent[r], sockets_2[5], sockets_2[6], sockets_[5]);
 
-		  std::cout << "dependent read (share) " << r << " -> " << read_out_dependent_reads[r] << std::endl;	
-
-		 // #ifdef DEBUG
+		  #ifdef VERBOSE
+		    std::cout << "dependent read (share) " << r << " -> " << read_out_dependent_reads[r] << std::endl;	
 		 	std::cout << print_reconstruction(sockets_[0], read_out_dependent_reads[r]) << std::endl;
-		//  #endif
+		  #endif
 	  }
 		
 		auto end_dep_reads = std::chrono::steady_clock::now();
@@ -394,10 +400,8 @@ 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;
    printf("elapsed_seconds_total = %f\n",elapsed_seconds_total.count());

+ 40 - 39
duoram-online/p2.cpp

@@ -146,7 +146,7 @@ int main(int argc, char* argv[])
   size_t number_of_ind_writes = atoi(argv[4]);;
   size_t number_of_ind_reads  = atoi(argv[5]);;
   size_t number_of_dep_reads  = atoi(argv[6]);;
-
+  size_t number_of_accesses   =  atoi(argv[7]);
   b = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
   c = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
   d = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
@@ -274,27 +274,30 @@ int main(int argc, char* argv[])
     DB_t * update_message1 = new DB_t[number_of_ind_writes];
     DB_t * FCW = new DB_t[number_of_ind_writes];
 
+for(size_t i = 0; i < number_of_accesses; ++i)
+{
     for(size_t w = 0; w < number_of_ind_writes; ++w)
     {
  
 
-     int const in1_w { open( "party0_write_flags_c", O_RDONLY ) };
-     size_t r = read(in1_w, writing_c,  db_nitems * sizeof(writing_c[0]));
-     if(r < 0) {
-     perror("Read error");
-     close(in1_w);
-     return 1;
-     }
-     
-     int const in2_w { open( "party1_write_flags_d", O_RDONLY ) };
-     r = read(in2_w, writing_d,  db_nitems * sizeof(writing_d[0])); 
-     if(r < 0) {
-     perror("Read error");
-     close(in2_w);
-     return 1;
-     }
-               int const in1_w_ { open( "party0_write_c", O_RDONLY ) };
-           r = read(in1_w_, c,  db_nitems * sizeof(c[0]));
+        int const in1_w { open( "party0_write_flags_c", O_RDONLY ) };
+        size_t r = read(in1_w, writing_c,  db_nitems * sizeof(writing_c[0]));
+        if(r < 0) {
+        perror("Read error");
+        close(in1_w);
+        return 1;
+        }
+        
+        int const in2_w { open( "party1_write_flags_d", O_RDONLY ) };
+        r = read(in2_w, writing_d,  db_nitems * sizeof(writing_d[0])); 
+        if(r < 0) {
+        perror("Read error");
+        close(in2_w);
+        return 1;
+        }
+
+         int const in1_w_ { open( "party0_write_c", O_RDONLY ) };
+         r = read(in1_w_, c,  db_nitems * sizeof(c[0]));
           if(r < 0) {
           perror("Read error");
           close(in1_w_);
@@ -307,20 +310,22 @@ int main(int argc, char* argv[])
           close(in2_w_);
           return 1;
           }
-        size_t rotate_by_ = WriteP0_recv[w].shift + WriteP1_recv[w].shift;
+      
+      
+      size_t rotate_by_ = WriteP0_recv[w].shift + WriteP1_recv[w].shift;
      
-        auto [Gamma0, Gamma1] = generate_cancelation_terms(writing_c, writing_d, db_nitems, rotate_by_);
-        Gamma0_[w] = Gamma0;
-        Gamma1_[w] = Gamma1; 
+      auto [Gamma0, Gamma1] = generate_cancelation_terms(writing_c, writing_d, db_nitems, rotate_by_);
+      Gamma0_[w] = Gamma0;
+      Gamma1_[w] = Gamma1; 
  
-       boost::asio::read(sockets_0[0], boost::asio::buffer(&WriteP0_recv[w],  sizeof(DuORAM_Write)));
-       boost::asio::read(sockets_1[0], boost::asio::buffer(&WriteP1_recv[w],  sizeof(DuORAM_Write)));
-       boost::asio::write(sockets_0[1], boost::asio::buffer(&Gamma0_[w], sizeof(DB_t))); 
-       boost::asio::write(sockets_1[1], boost::asio::buffer(&Gamma1_[w], sizeof(DB_t)));
-
-       boost::asio::read(sockets_0[2], boost::asio::buffer(&update_message0[w],  sizeof(DB_t))); 
-       boost::asio::read(sockets_1[2], boost::asio::buffer(&update_message1[w],  sizeof(DB_t)));
-       FCW[w] = update_message0[w] + update_message1[w];
+      boost::asio::read(sockets_0[0], boost::asio::buffer(&WriteP0_recv[w],  sizeof(DuORAM_Write)));
+      boost::asio::read(sockets_1[0], boost::asio::buffer(&WriteP1_recv[w],  sizeof(DuORAM_Write)));
+      boost::asio::write(sockets_0[1], boost::asio::buffer(&Gamma0_[w], sizeof(DB_t))); 
+      boost::asio::write(sockets_1[1], boost::asio::buffer(&Gamma1_[w], sizeof(DB_t)));
+
+      boost::asio::read(sockets_0[2], boost::asio::buffer(&update_message0[w],  sizeof(DB_t))); 
+      boost::asio::read(sockets_1[2], boost::asio::buffer(&update_message1[w],  sizeof(DB_t)));
+      FCW[w] = update_message0[w] + update_message1[w];
       
     }
 
@@ -329,13 +334,13 @@ int main(int argc, char* argv[])
       size_t rotate_by_ = WriteP0_recv[w].shift + WriteP1_recv[w].shift;
       refresh_blinds(writing_c, writing_d, c, d, FCW[w], FCW[w], db_nitems, -rotate_by_);
    
-      //#ifdef DEBUG
+      #ifdef DEBUG
       for(size_t j = 0; j < db_nitems; ++j)
       {
         boost::asio::write(sockets_0[0], boost::asio::buffer(&X0[j], sizeof(X0[j]))); //DEBUG
         boost::asio::write(sockets_1[0], boost::asio::buffer(&X1[j], sizeof(X1[j]))); //DUBUG
       }
-      //#endif
+      #endif
     }
 
 
@@ -355,9 +360,7 @@ int main(int argc, char* argv[])
     for(size_t r = 0; r < number_of_ind_reads; ++r) rotate[r] = reads_shift_from_P0[r] + reads_shift_from_P1[r];
 
     for(size_t r = 0; r < number_of_ind_reads; ++r)
-    {
-    //  // rotate_all(reading_b, reading_b_rotated, reading_c, reading_c_rotated, reading_d, reading_d_rotated, rotate[r], db_nitems);
-      
+    {  
       #ifdef DEBUG
         std::cout << "rotate[r] " << rotate[r] << std::endl;
       #endif
@@ -366,7 +369,7 @@ int main(int argc, char* argv[])
      
       Gamma0_reads[r] = Gamma0;
       Gamma1_reads[r] = Gamma1;
-     }
+    }
 
     boost::asio::write(sockets_0[4], boost::asio::buffer(Gamma0_reads, number_of_ind_reads * sizeof(DB_t)));  
     boost::asio::write(sockets_1[4], boost::asio::buffer(Gamma1_reads, number_of_ind_reads * sizeof(DB_t)));
@@ -379,14 +382,12 @@ int main(int argc, char* argv[])
         boost::asio::read(sockets_0[5], boost::asio::buffer(&shifts0, sizeof(shifts0)));
         boost::asio::read(sockets_1[5], boost::asio::buffer(&shifts1, sizeof(shifts1)));
         rotate = shifts0 + shifts1;
-        //rotate_all(reading_b, reading_b_rotated, reading_c, reading_c_rotated, reading_d, reading_d_rotated, rotate, db_nitems);
-
         auto [Gamma0, Gamma1] =   generate_cancelation_terms(reading_c, reading_d, db_nitems, rotate);
         boost::asio::write(sockets_0[6], boost::asio::buffer(&Gamma0, sizeof(Gamma0)));  
         boost::asio::write(sockets_1[6], boost::asio::buffer(&Gamma1, sizeof(Gamma1)));
      }
 
-
+}
   return 0;
 }