Browse Source

removed the setting of zero for target

avadapal 1 year ago
parent
commit
c63f19f962

+ 0 - 2
duoram-online/duoram-read.h

@@ -1,7 +1,6 @@
 
 auto DuoramRead(bool party, size_t db_nitems, int64_t ri, int64_t where_to_read, tcp::socket&s2, tcp::socket& s2_b, tcp::socket& sb)
 {
-
  read_flags_for_reading(party, db_nitems);
 
  DB_t Gamma;
@@ -35,7 +34,6 @@ auto DuoramRead(bool party, size_t db_nitems, int64_t ri, int64_t where_to_read,
 
 
  return output;
-
 }
 
 

+ 3 - 2
duoram-online/duoram-refresh.h

@@ -13,7 +13,7 @@ void refresh_blinds(int8_t flags[], DB_t standard_basis_vector[], DB_t finalCW,
   DB_t tmp = 0; 
   for(size_t j = 0; j < db_nitems; ++j) 
   {
-   tmp = (flags[(j + rotate_by) % db_nitems] != 0) ? finalCW : 0;
+    tmp = (flags[(j + rotate_by) % db_nitems] != 0) ? finalCW : 0;
 
     if(party)  updated_blinds[j] = blinds[j] - standard_basis_vector[(j + rotate_by) % db_nitems]  - tmp;
     if(!party) updated_blinds[j] = blinds[j] - standard_basis_vector[(j + rotate_by) % db_nitems]  + tmp; 
@@ -26,7 +26,8 @@ void refresh_blinded_vector_and_blinds(int8_t flags[], DB_t standard_basis_vecto
  for(size_t j = 0; j < db_nitems; ++j) 
  {
    updated_blinded_DB_recv[j] =  blinded_DB_recv[j] - b[(j + rotate_by) % db_nitems] + d[(j + rotate_by) % db_nitems]  
-                                   - (flags0[(j + rotate_by) % db_nitems] * finalCW) + (flags2[(j + rotate_by) % db_nitems] * finalCW);       
+                               - (flags0[(j + rotate_by) % db_nitems] * finalCW) + (flags2[(j + rotate_by) % db_nitems] * finalCW);
+                                      
    blinds[j] = blinds[j] - standard_basis_vector[(j + rotate_by) % db_nitems] - (flags[(j + rotate_by) % db_nitems] * finalCW); 
  }
 }

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

@@ -9,22 +9,9 @@ void  write_into_the_database(DB_t DB[], DB_t updated_DB[], int8_t flags[], DB_t
  	}
 }
  
-void reconstruct_database(tcp::socket& sb, DB_t DB[], const size_t db_nitems)
-{
-		for(size_t j = 0; j < db_nitems; ++j)
-		{
-			DB_t DB_j;
-			boost::asio::write(sb, boost::asio::buffer(&DB[j], sizeof(DB[j])));
-			boost::asio::read(sb, boost::asio::buffer(&DB_j, sizeof(DB_j)));
-			DB_j = DB_j + DB[j];
-			if(DB_j != 0) std::cout << j << " -> " << DB_j << std::endl;
-		}
-}
-
-
-auto DuoramUpdate(bool party, size_t db_nitems,   size_t rotate_by_,
-				  DB_t DB[], DB_t updated_DB[], int8_t writing_b[], DB_t b[],  DB_t final_CW, DB_t message,
-				  int8_t writing_c[], int8_t writing_d[], DB_t c[], DB_t d[])
+auto DuoramUpdate( bool party, size_t db_nitems,   size_t rotate_by_,
+				               DB_t DB[], DB_t updated_DB[], int8_t writing_b[], DB_t b[],  DB_t final_CW, DB_t message,
+             				  int8_t writing_c[], int8_t writing_d[], DB_t c[], DB_t d[])
 {
 
 	read_flags_for_updating(party, db_nitems);

+ 265 - 257
duoram-online/duoram.cpp

@@ -107,280 +107,288 @@ int main(const int argc, const char * argv[])
 		 ports2_0.push_back(port + j);
 	 }
 
-	std::vector<int> ports2_1;
-	for(size_t j = 0; j < number_of_sockets; ++j) 
-	{
-		int port = 9000;
-		ports2_1.push_back(port + j);
-	}
-
-
-
- #if (PARTY == 0)     	 
-  party = false;
- 	#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)
+  std::vector<int> ports2_1;
+  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])}));
-    sockets_[j] = std::move(sb_a); 
+   int port = 9000;
+   ports2_1.push_back(port + j);
   }
- #else	
 
-	party = true;	
+  #if (PARTY == 0)     	 
+   party = false;
+   #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)
+   {
+    tcp::socket sb_a(io_context);
+     boost::asio::connect(sb_a, resolver.resolve({host1, std::to_string(ports[j])}));
+     sockets_[j] = std::move(sb_a); 
+   }
+  #else	
+
+	 party = true;	
  	
-	#ifdef ThreeParty	
-	 for(size_t j = 0; j < number_of_sockets; ++j)
+	 #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])}));
+   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
+ 	#endif
    
-  boost::asio::thread_pool pool2(number_of_sockets); 
-  for(size_t j = 0; j < number_of_sockets; ++j)
-  {
+   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(sockets_), ports[j],  j));
-  } 
-  pool2.join();
-
-#endif
+   } 
+   pool2.join();
+  
+   #endif
  
  
-	generate_random_distinguished_points(party);
+	 generate_random_distinguished_points(party);
   
- AES_KEY aeskey;	  
- 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));
+  AES_KEY aeskey;	  
+  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));
 
-	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];
+	 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];
    
-   	
-	auto start_total = std::chrono::steady_clock::now();	
-
-	setup(DB, updated_DB, blinded_DB_recv, blinds, updated_blinds, updated_blinded_DB_recv, db_nitems, party);
-
-	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;
-		}	   
-		for(size_t j = 0; j < number_of_dep_reads; ++j)
-		{
-			where_to_read_dependent[j] = j + 4;
-		}
-		for(size_t j = 0; j < number_of_ind_reads; ++j)
-		{
-			where_to_read_independent[j] = j + 4;
-		}			
-		for(size_t j = 0; j < db_nitems; ++j) 
-		{
-			blinds[j] = 0;
-			updated_blinds[j] = blinds[j];
-			updated_blinded_DB_recv[j] = blinded_DB_recv[j];
-		}
-
-		int64_t ri, ri_recv;
-		arc4random_buf(&ri, sizeof(ri));
-		ri = ri % db_nitems;
-		boost::asio::write(sockets_[0], boost::asio::buffer(&ri, sizeof(ri)));
-		boost::asio::read(sockets_[0], boost::asio::buffer(&ri_recv, sizeof(ri_recv)));
-		
-	 
-  if(party) ri = 2 - ri_recv;
-
-		#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];
-			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 * update_message = new DB_t[number_of_writes];
-
-		auto start_writes = std::chrono::steady_clock::now();
-
-		#ifdef ThreeParty
-		for(size_t w = 0; w < number_of_writes; ++w)
-		{
-				DB_t FCW_read = 0;
-
-				/*The definition of read_final_correction_word appears in duoram-utils.h*/ 	
-				read_final_correction_word(party, FCW_read);
-				
-				#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];
-				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)));
-
-				/*The definition of read_flags_for_writing appears in duoram-utils.h*/ 	
-				read_flags_for_writing(party, db_nitems);
-	
-				rotate_by_[w] = WritePb_[w].shift + WritePb_recv[w].shift;		 			
-
-				#ifdef VERBOSE 		
-					std::cout << "print database (prints the non-zero database entries): " << std::endl;
-					/* The definition of reconstruct_database appears in duoram-utils.h */							
-					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];
-				
-				/*The definition of dot_product_with_bool appears in duoram-write.h*/ 
-				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 VERBOSE
-					std::cout << "read_out[" << w << "] = " << read_out[w] << std::endl;
-				#endif
-
-				#ifdef VERBOSE
-				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 VERBOSE
-				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 VERBOSE
-					std::cout << "cw = " << CW[w] << std::endl;
-				#endif 
-			}
-		#endif
-
-		for(size_t w = 0; w < number_of_writes; ++w)
- 	{			
-			/*The definition of DuoramUpdate appears in duoram-write.h*/  	 
-		 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
-					/*The definition debug_ appears in duoram-utils.h*/  
-					debug_(sockets_2[0], sockets_[0], db_nitems);
-			 	#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());
-	
-	#ifdef VERBOSE
-		std::cout << "Reconstructing the database after doing " << number_of_writes << " writes " << std::endl;
-		reconstruct_database(sockets_[0],  DB, db_nitems);
-	#endif
-	// WRITES END.
-
-  #ifdef ThreeParty
-  #ifdef VERBOSE
-		 std::cout << std::endl << std::endl << "============== WRITES END ==============" << std::endl << std::endl;
-  #endif
- 	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];
-	 	 
-	 	
-	 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)));
-	 	
-		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)
-		{
-			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 VERBOSE
-		 	std::cout << "rotate[r]" << rotate[r] << std::endl; 
-		 	std::cout << "Gamma_reads[r] = " << Gamma_reads[r] << std::endl;
-		 #endif
-			
-			 read_out_independent_reads[r] = DuoramIndependentRead(party,  db_nitems,  ri, Gamma_reads,  rotate,  r);
-
-		  #ifdef VERBOSE
-		 	std::cout << "---> [duoram independent reads] " <<  print_reconstruction(sockets_[0], read_out_independent_reads[r]) << std::endl;
-		  #endif
-	 }
+ 	auto start_total = std::chrono::steady_clock::now();	
 
- auto end_ind_reads = std::chrono::steady_clock::now();
- std::chrono::duration<double> elapsed_seconds_ind_reads = end_ind_reads - start_ind_reads;
- printf("elapsed_seconds_ind_reads = %f\n",elapsed_seconds_ind_reads.count());
-	#ifdef VERBOSE
- std::cout << std::endl << std::endl << "============== INDEPENDENT READS END  ==============" << std::endl << std::endl;
-	#endif
- auto start_dep_reads = std::chrono::steady_clock::now();
-	
- #ifdef VERBOSE
-	std::cout << std::endl << std::endl << "============== DEPENDENT READS START  ==============" << std::endl << std::endl;
- #endif
-	DB_t * read_out_dependent_reads = new DB_t[number_of_dep_reads];
-	 
- for(size_t r = 0; r < number_of_dep_reads; ++r)
-	{
-	  read_out_dependent_reads[r] = DuoramRead(party, db_nitems, ri, where_to_read_dependent[r], sockets_2[5], sockets_2[6], sockets_[5]);
-	  #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
-  }
-		
-	 auto end_dep_reads = std::chrono::steady_clock::now();
-	 std::chrono::duration<double> elapsed_seconds_dep_reads = end_dep_reads - start_dep_reads;
-	 printf("elapsed_seconds_dep_reads = %f\n",elapsed_seconds_dep_reads.count()); 
-  #ifdef VERBOSE
-	 std::cout << std::endl << std::endl << "============== DEPENDENT READS END  ==============" << std::endl << std::endl;
- #endif
+	 setup(DB, updated_DB, blinded_DB_recv, blinds, updated_blinds, updated_blinded_DB_recv, db_nitems, party);
+
+ 	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;
+    }	   
+    for(size_t j = 0; j < number_of_dep_reads; ++j)
+    {
+     where_to_read_dependent[j] = j + 4;
+    }
+    for(size_t j = 0; j < number_of_ind_reads; ++j)
+    {
+     where_to_read_independent[j] = j + 4;
+    }			
+    for(size_t j = 0; j < db_nitems; ++j) 
+    {
+     blinds[j] = 0;
+     updated_blinds[j] = blinds[j];
+     updated_blinded_DB_recv[j] = blinded_DB_recv[j];
+    }
 
+   
+    // arc4random_buf(&ri, sizeof(ri));
+    // ri = ri % db_nitems;
+    // boost::asio::write(sockets_[0], boost::asio::buffer(&ri, sizeof(ri)));
+    // boost::asio::read(sockets_[0], boost::asio::buffer(&ri_recv, sizeof(ri_recv)));
+		
 	 
- #endif
-}  
+    // if(party) ri = 2 - ri_recv;
+     int64_t ri;
+    read_rand_indx(party, ri);
+
+   
+    #ifdef DEBUG
+    int64_t  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)));
+    ri_recv = ri_recv + ri;
+    std::cout << "ri_recv = "  << ri_recv % db_nitems << std::endl;
+    #endif
+    #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];
+     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 * update_message = new DB_t[number_of_writes];
+
+    auto start_writes = std::chrono::steady_clock::now();
+
+    #ifdef ThreeParty
+    for(size_t w = 0; w < number_of_writes; ++w)
+    {
+      DB_t FCW_read = 0;
+
+      /*The definition of read_final_correction_word appears in duoram-utils.h*/ 	
+      read_final_correction_word(party, FCW_read);
+      
+      #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];
+      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)));
+
+      /*The definition of read_flags_for_writing appears in duoram-utils.h*/ 	
+      read_flags_for_writing(party, db_nitems);
+   
+      rotate_by_[w] = WritePb_[w].shift + WritePb_recv[w].shift;		 			
+
+      #ifdef VERBOSE 		
+       std::cout << "print database (prints the non-zero database entries): " << std::endl;
+       /* The definition of reconstruct_database appears in duoram-utils.h */							
+       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];
+      
+      /*The definition of dot_product_with_bool appears in duoram-write.h*/ 
+      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 VERBOSE
+       std::cout << "read_out[" << w << "] = " << read_out[w] << std::endl;
+      #endif
+
+      #ifdef VERBOSE
+      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 VERBOSE
+      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 VERBOSE
+       std::cout << "cw = " << CW[w] << std::endl;
+      #endif 
+     }
+    #endif
+
+    for(size_t w = 0; w < number_of_writes; ++w)
+    {			
+     /*The definition of DuoramUpdate appears in duoram-write.h*/  	 
+     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
+       /*The definition debug_ appears in duoram-utils.h*/  
+       debug_(sockets_2[0], sockets_[0], db_nitems);
+       #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());
+   
+   #ifdef VERBOSE
+    std::cout << "Reconstructing the database after doing " << number_of_writes << " writes " << std::endl;
+    reconstruct_database(sockets_[0],  DB, db_nitems);
+   #endif
+   // WRITES END.
+
+    #ifdef ThreeParty
+    #ifdef VERBOSE
+     std::cout << std::endl << std::endl << "============== WRITES END ==============" << std::endl << std::endl;
+    #endif
+    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];
+      
+     
+    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)));
+     
+    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)
+    {
+     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 VERBOSE
+       std::cout << "rotate[r]" << rotate[r] << std::endl; 
+       std::cout << "Gamma_reads[r] = " << Gamma_reads[r] << std::endl;
+      #endif
+     
+      read_out_independent_reads[r] = DuoramIndependentRead(party,  db_nitems,  ri, Gamma_reads,  rotate,  r);
+
+      #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();
+    std::chrono::duration<double> elapsed_seconds_ind_reads = end_ind_reads - start_ind_reads;
+    printf("elapsed_seconds_ind_reads = %f\n",elapsed_seconds_ind_reads.count());
+
+    #ifdef VERBOSE
+    std::cout << std::endl << std::endl << "============== INDEPENDENT READS END  ==============" << std::endl << std::endl;
+    #endif
+
+    auto start_dep_reads = std::chrono::steady_clock::now();
+    #ifdef VERBOSE
+    std::cout << std::endl << std::endl << "============== DEPENDENT READS START  ==============" << std::endl << std::endl;
+    #endif
+    DB_t * read_out_dependent_reads = new DB_t[number_of_dep_reads];
+    
+    for(size_t r = 0; r < number_of_dep_reads; ++r)
+    {
+      read_out_dependent_reads[r] = DuoramRead(party, db_nitems, ri, where_to_read_dependent[r], sockets_2[5], sockets_2[6], sockets_[5]);
+      #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
+    }
+    
+    auto end_dep_reads = std::chrono::steady_clock::now();
+    std::chrono::duration<double> elapsed_seconds_dep_reads = end_dep_reads - start_dep_reads;
+    printf("elapsed_seconds_dep_reads = %f\n",elapsed_seconds_dep_reads.count()); 
+
+    #ifdef VERBOSE
+     std::cout << std::endl << std::endl << "============== DEPENDENT READS END  ==============" << std::endl << std::endl;
+    #endif
+   #endif
+  }  
 
 auto end_total = std::chrono::steady_clock::now();
 std::chrono::duration<double> elapsed_seconds_total = end_total - start_total;

+ 23 - 0
duoram-online/readvectors.h

@@ -28,6 +28,29 @@ int read_final_correction_word(bool party, DB_t& FCW_read, int i = 0)
   return 0;
 }
 
+int read_rand_indx(bool party, DB_t& R, int i = 0)
+{
+  if(!party)
+		{
+   char tmp[100];
+   concatanate_index("preprocflags/R0", tmp, i);
+			int const in0 { open(tmp, O_RDONLY ) };
+	 	size_t r = read(in0, &R,   sizeof(R));	
+   if(r < 0) perror("Read error");
+		}
+		
+  if(party)
+		{
+   char tmp[100];
+   concatanate_index("preprocflags/R1", tmp, i);
+		 int const in0 { open(tmp, O_RDONLY ) };
+	 	size_t r = read(in0, &R,   sizeof(R));	
+ 		if(r < 0) perror("Read error");
+		}
+
+  return 0;
+}
+
 int read_flags_for_reading(bool party, size_t db_nitems, int i = 0)
 {
 	if(!party)