Browse Source

minor changes

avadapal 1 year ago
parent
commit
b0164f7bf3

+ 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 -DThreeParty #-DDEBUG -DVERBOSE
+FLAGS =  -DBOOST_ERROR_CODE_HEADER_ONLY -DThreeParty -DDEBUG -DVERBOSE
 
 all: duoram0 duoram1 p2
 

+ 17 - 17
duoram-online/duoram-read.h

@@ -1,14 +1,15 @@
 
 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;
+ read_flags_for_reading(party, db_nitems);
+
+ DB_t Gamma;
 		
 	size_t WritePb_ind_reads, WritePb_ind_reads_recv, rotate;
 	WritePb_ind_reads = where_to_read - ri;
 	
-    boost::asio::write(s2, boost::asio::buffer(&WritePb_ind_reads, sizeof(WritePb_ind_reads)));
+ boost::asio::write(s2, boost::asio::buffer(&WritePb_ind_reads, sizeof(WritePb_ind_reads)));
 	boost::asio::write(sb, boost::asio::buffer(&WritePb_ind_reads, sizeof(WritePb_ind_reads)));
 	boost::asio::read(sb, boost::asio::buffer(&WritePb_ind_reads_recv, sizeof(WritePb_ind_reads_recv)));
     
@@ -24,16 +25,16 @@ auto DuoramRead(bool party, size_t db_nitems, int64_t ri, int64_t where_to_read,
 	   	
 	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 )  +
-						  dot_product_with_bool(updated_blinds, reading_b, db_nitems, rotate) - 
-						  dot_product_with_bool(updated_blinds, reading_c, db_nitems, rotate) + Gamma;
+	if(!party) output  =  dot_product_with_bool(reading_temp, reading_b, db_nitems, rotate )  +
+						                 dot_product_with_bool(updated_blinds, reading_b, db_nitems, rotate) - 
+						                 dot_product_with_bool(updated_blinds, reading_c, db_nitems, rotate) + Gamma;
 
 	if(party)  output =   dot_product_with_bool(reading_temp, reading_c, db_nitems, rotate)   + 
-						  dot_product_with_bool(updated_blinds, reading_c, db_nitems, rotate) - 
-						  dot_product_with_bool(updated_blinds, reading_d, db_nitems, rotate) + Gamma;
+			               			  dot_product_with_bool(updated_blinds, reading_c, db_nitems, rotate) - 
+						                 dot_product_with_bool(updated_blinds, reading_d, db_nitems, rotate) + Gamma;
 
 
-    return output;
+ return output;
 
 }
 
@@ -42,20 +43,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_for_reading(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];
+	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;
+ return output;
 }

+ 69 - 98
duoram-online/duoram-refresh.h

@@ -1,124 +1,95 @@
-
-
- 
-
 void refresh_blinds(int8_t flags[], DB_t standard_basis_vector[], DB_t finalCW, bool party, size_t db_nitems, size_t rotate_by = 0)
-{
-    
-   DB_t tmp = 0; 
-
-   for(size_t j = 0; j < db_nitems; ++j) 
-   {
-      if(flags[(j + rotate_by) % db_nitems] != 0) 
-      {
-         tmp = finalCW;      
-      }
-      else
-      {
-         tmp = 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;
-
- 
-   }
- 
+{    
+  DB_t tmp = 0; 
+  for(size_t j = 0; j < db_nitems; ++j) 
+  {
+   tmp = (flags[(j + rotate_by) % db_nitems] != 0) ? finalCW : 0;
+
+   // if(flags[(j + rotate_by) % db_nitems] != 0) 
+   //  {
+   //    tmp = finalCW;      
+   //  }
+   //  else
+   //  {
+   //    tmp = 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; 
+  }
 }
 
 
-void get_refresh_correction_words (tcp::socket& sb, DB_t one_shareA, DB_t one_shareB, 
-                                    DB_t one_shareC, DB_t& CW0, DB_t& CW1, DB_t& CW2, DB_t value)
-{
-  
-   DB_t tmp0 = value + one_shareA;
+// void get_refresh_correction_words (tcp::socket& sb, DB_t one_shareA, DB_t one_shareB, DB_t one_shareC, DB_t& CW0, DB_t& CW1, DB_t& CW2, DB_t value)
+// {
+   
+//    DB_t tmp0 = value + one_shareA;
  
-   write(sb, boost::asio::buffer(&tmp0, sizeof(tmp0)));
-   read(sb, boost::asio::buffer(&CW0, sizeof(CW0)));
-   CW0 = CW0 + tmp0;
+//    write(sb, boost::asio::buffer(&tmp0, sizeof(tmp0)));
+//    read(sb, boost::asio::buffer(&CW0, sizeof(CW0)));
+//    CW0 = CW0 + tmp0;
 
-   DB_t tmp1 = value + one_shareB; 
+//    DB_t tmp1 = value + one_shareB; 
 
-   write(sb, boost::asio::buffer(&tmp1, sizeof(tmp1)));
-   read(sb, boost::asio::buffer(&CW1, sizeof(CW1)));
-   CW1 = CW1 + tmp1;
+//    write(sb, boost::asio::buffer(&tmp1, sizeof(tmp1)));
+//    read(sb, boost::asio::buffer(&CW1, sizeof(CW1)));
+//    CW1 = CW1 + tmp1;
 
-   DB_t tmp2 = value + one_shareC;
+//    DB_t tmp2 = value + one_shareC;
  
-   write(sb, boost::asio::buffer(&tmp2, sizeof(tmp2)));
-   read(sb, boost::asio::buffer(&CW2, sizeof(CW2)));
+//    write(sb, boost::asio::buffer(&tmp2, sizeof(tmp2)));
+//    read(sb, boost::asio::buffer(&CW2, sizeof(CW2)));
  
-   CW2 = CW2 + tmp2;   
-}
+//    CW2 = CW2 + tmp2;   
+// }
 
-void refresh_blinded_vector(int8_t flags0[], int8_t flags2[], DB_t b[],  DB_t d[], 
-                            DB_t finalCW0, DB_t finalCW2, bool party, size_t db_nitems, size_t rotate_by = 0)
-{
- 
-    
+void refresh_blinded_vector(int8_t flags0[], int8_t flags2[], DB_t b[],  DB_t d[], DB_t finalCW0, DB_t finalCW2, bool party, size_t db_nitems, size_t rotate_by = 0)
+{   
    DB_t tmp0 = 0;
    DB_t tmp2 = 0; 
- 
    for(size_t j = 0; j < db_nitems; ++j) 
    {
-       
-      if(flags0[(j + rotate_by) % db_nitems] != 0) 
-      {
-        tmp0 =  finalCW0;
-      }
-      else
-      {
-       tmp0 = 0;
-      }
 
-      if(flags2[(j + rotate_by) % db_nitems] != 0) 
-      {
-       tmp2 =  finalCW2;
-      }
-      else
-      {
-        tmp2 = 0;
-      }
-
-      if(party) 
-      {
-       updated_blinded_DB_recv[j] = blinded_DB_recv[j] - b[(j + rotate_by) % db_nitems] + d[(j + rotate_by) % db_nitems]  - tmp0 + tmp2;
-      }
-      if(!party) 
-      {
-       updated_blinded_DB_recv[j] = blinded_DB_recv[j] - b[(j + rotate_by) % db_nitems] + d[(j + rotate_by) % db_nitems] + tmp0  - tmp2;
-      }
+    tmp0 = (flags0[(j + rotate_by) % db_nitems] != 0) ? finalCW0 : 0;
+    tmp2 = (flags2[(j + rotate_by) % db_nitems] != 0) ? finalCW2 : 0;
+ 
+    // if(flags0[(j + rotate_by) % db_nitems] != 0) 
+    // {
+    //  tmp0 =  finalCW0;
+    // }
+    // else
+    // {
+    //  tmp0 = 0;
+    // }   
+    // if(flags2[(j + rotate_by) % db_nitems] != 0) 
+    // {
+    //  tmp2 =  finalCW2;
+    // }
+    // else
+    // {
+    //  tmp2 = 0;
+    // }
+    if(party) 
+    {
+     updated_blinded_DB_recv[j] = blinded_DB_recv[j] - b[(j + rotate_by) % db_nitems] + d[(j + rotate_by) % db_nitems]  - tmp0 + tmp2;
+    }
+    if(!party) 
+    {
+     updated_blinded_DB_recv[j] = blinded_DB_recv[j] - b[(j + rotate_by) % db_nitems] + d[(j + rotate_by) % db_nitems] + tmp0  - tmp2;
+    }
    }
 }
 
 
 
 void refresh_blinded_vector_and_blinds(int8_t flags[], DB_t standard_basis_vector[], DB_t finalCW,int8_t flags0[], int8_t flags2[], DB_t b[],  DB_t d[], 
-                             bool party, size_t db_nitems, size_t rotate_by)
+                                       bool party, size_t db_nitems, size_t rotate_by)
 {
- 
-  
- 
-   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);
-       
-       blinds[j] = blinds[j] - standard_basis_vector[(j + rotate_by) % db_nitems]  -   (flags[(j + rotate_by) % db_nitems] * finalCW);// ((flags[(j + rotate_by) % db_nitems]!=0) ? finalCW : 0 );
-
-
-      // if(party) 
-      // {
-      //  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]!=0) ? finalCW : 0 ) + ((flags2[(j + rotate_by) % db_nitems]!=0) ? finalCW : 0 );
-      //  blinds[j] = blinds[j] - standard_basis_vector[(j + rotate_by) % db_nitems]  - ((flags[(j + rotate_by) % db_nitems]!=0) ? finalCW : 0 );
-      // }
-      // if(!party) 
-      // {
-      //  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]!=0) ? finalCW : 0 ) - ((flags2[(j + rotate_by) % db_nitems]!=0) ? finalCW : 0 );
-      //  blinds[j] = blinds[j] - standard_basis_vector[(j + rotate_by) % db_nitems]  + ((flags[(j + rotate_by) % db_nitems]!=0) ? finalCW : 0 );
-      // }
-   }
+ 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);       
+   blinds[j] = blinds[j] - standard_basis_vector[(j + rotate_by) % db_nitems] - (flags[(j + rotate_by) % db_nitems] * finalCW); 
+ }
 }
 
 void duoram_refresh (int8_t flags0[], int8_t flags1[], int8_t flags2[], DB_t b[], DB_t c[], DB_t d[],   DB_t CW, bool party, size_t db_nitems, size_t rotate_by_ = 0)

+ 42 - 85
duoram-online/duoram-utils.h

@@ -5,15 +5,9 @@ enum step
   num_steps
 };
 size_t duoram_progress[step::num_steps] = { 0 };
-
- 
-
  
 const size_t number_of_writes = 2;
 
-
- 
-
 typedef  int64_t DB_t;
 
 struct DuORAM_Write
@@ -22,64 +16,46 @@ struct DuORAM_Write
 	DB_t CW;
 };
 
-
-
 size_t target_index = 2;
 size_t bytes_written2 =0;
 
-DB_t final_cw;
-
-DB_t * DB; 
-DB_t * updated_DB; 
-DB_t * blinds;
-DB_t * updated_blinds;
-DB_t * blinded_DB;
-DB_t * blinded_DB_recv;
-DB_t * updated_blinded_DB_recv;
-
-DB_t M;
+ DB_t final_cw;
 
+ DB_t * DB; 
+ DB_t * updated_DB; 
+ DB_t * blinds; 
+ DB_t * updated_blinds; 
+ DB_t * blinded_DB; 
+ DB_t * blinded_DB_recv;
+ DB_t * updated_blinded_DB_recv;
+ DB_t M;
+ DB_t * reading_temp; 
+ DB_t distinguised_value[number_of_writes];
 
 
-DB_t * reading_temp; 
-DB_t distinguised_value[number_of_writes];
+ DB_t * b;
+ DB_t * c;
+ DB_t * d;
 
+ int8_t * reading_b;
+ int8_t * reading_c;
+ int8_t * reading_d; 
 
-DB_t * b;
-DB_t * c;
-DB_t * d;
+ int8_t * writing_b;
+ int8_t * writing_c; 
+ int8_t * writing_d; 
 
  
- 
-
-int8_t * reading_b;
-int8_t * reading_c;
-int8_t * reading_d; 
-
-int8_t * writing_b;
-int8_t * writing_c;
-int8_t * writing_d; 
-
- 
- void setup(DB_t * DB, DB_t * updated_DB, DB_t * blinded_DB_recv, DB_t * blinds, DB_t * updated_blinds, DB_t * updated_blinded_DB_recv, size_t db_nitems, bool party)
- {
- 	for(size_t j = 0; j < db_nitems; ++j)
- 	{
-      if(party)
-      {
-        DB[j] 				      = 0;
-        updated_DB[j] 		  = 0;
-        blinded_DB_recv[j]  = 0; 
-      }
-      else
-      {
-        DB[j] 				      = 0;
-        updated_DB[j] 		  = 0;
-        blinded_DB_recv[j]  = 0; 
-      }
- 	}
+void setup(DB_t * DB, DB_t * updated_DB, DB_t * blinded_DB_recv, DB_t * blinds, DB_t * updated_blinds, DB_t * updated_blinded_DB_recv, size_t db_nitems, bool party)
+{
+	for(size_t j = 0; j < db_nitems; ++j)
+	{
+   DB[j] 				          = 0;
+   updated_DB[j] 		    = 0;
+   blinded_DB_recv[j]  = 0;  
+ }
 
-  for(size_t j = 0; j < db_nitems; ++j) 
+ for(size_t j = 0; j < db_nitems; ++j) 
 	{
 		blinds[j] = 0;
 		updated_blinds[j] = blinds[j];
@@ -91,38 +67,36 @@ void debug_(tcp::socket& in2, tcp::socket& sb, size_t db_nitems)
 {
 	for(size_t j = 0; j < db_nitems; ++j)
   {
-    	DB_t debug_blinds2;
-      boost::asio::read(in2, boost::asio::buffer(&debug_blinds2, sizeof(debug_blinds2)));
-      assert(blinds[j] == debug_blinds2);
+   	DB_t debug_blinds2;
+    boost::asio::read(in2, boost::asio::buffer(&debug_blinds2, sizeof(debug_blinds2)));
+    assert(blinds[j] == debug_blinds2);
   }
 
 	for(size_t jj = 0; jj < db_nitems; ++jj)
 	{
 		DB_t debug_refresh;
-	  boost::asio::write(sb, boost::asio::buffer(&updated_blinded_DB_recv[jj], sizeof(updated_blinded_DB_recv[jj])));
-	  boost::asio::read(sb, boost::asio::buffer(&debug_refresh, sizeof(debug_refresh)));	
+	 boost::asio::write(sb, boost::asio::buffer(&updated_blinded_DB_recv[jj], sizeof(updated_blinded_DB_recv[jj])));
+	 boost::asio::read(sb, boost::asio::buffer(&debug_refresh, sizeof(debug_refresh)));	
 		assert(debug_refresh == DB[jj] + blinds[jj]);
 	}
 	
 		DB_t DB_out;
-	 	boost::asio::write(sb, boost::asio::buffer(&DB[target_index], sizeof(DB[target_index])));
+	 boost::asio::write(sb, boost::asio::buffer(&DB[target_index], sizeof(DB[target_index])));
 		boost::asio::read(sb, boost::asio::buffer(&DB_out, sizeof(DB_out)));
 
-
-	 	DB_out = DB_out + DB[target_index];
-	  
-	  std::cout << "DB_out = " << DB_out << std::endl;
+	 DB_out = DB_out + DB[target_index];	  
+	 std::cout << "DB_out = " << DB_out << std::endl;
 }
 
 
 DB_t print_reconstruction(tcp::socket& sb, DB_t output)
 {
-		  		DB_t out_reconstruction;
-		    	boost::asio::write(sb, boost::asio::buffer(&output, sizeof(output)));
-		    	boost::asio::read(sb, boost::asio::buffer(&out_reconstruction, sizeof(out_reconstruction)));
-		    	out_reconstruction = out_reconstruction + output;
+		DB_t out_reconstruction;
+ 	boost::asio::write(sb, boost::asio::buffer(&output, sizeof(output)));
+ 	boost::asio::read(sb, boost::asio::buffer(&out_reconstruction, sizeof(out_reconstruction)));
+ 	out_reconstruction = out_reconstruction + output;
 
-          return out_reconstruction;
+  return out_reconstruction;
 }
 
 
@@ -176,23 +150,6 @@ void generate_random_distinguished_points(bool party)
 }
 
 
-/* This function is never called*/
-template<typename T1> 
-void rotate_all( T1 * orginal_vector1, T1 * rotated_vector1,
-								 T1 * orginal_vector3, T1 * rotated_vector3,
-							   T1 * orginal_vector5, T1 * rotated_vector5, 
-								size_t rotate_by, size_t db_nitems)
-{
-
- 			 for(size_t j = 0; j < db_nitems; ++j)
-			 {
-				
-			 	 rotated_vector1[(j + rotate_by) % db_nitems] = orginal_vector1[j];
-			 	 rotated_vector3[(j + rotate_by) % db_nitems] = orginal_vector3[j];
-			 	 rotated_vector5[(j + rotate_by) % db_nitems] = orginal_vector5[j];			 	 
-			 }
-}
-
 DB_t dot_product_with_bool(DB_t D[], int8_t flags[], size_t db_nitems, size_t rotate_by = 0)
 {
   DB_t result = 0;

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

@@ -1,13 +1,12 @@
  
 void  write_into_the_database(DB_t DB[], DB_t updated_DB[], int8_t flags[], DB_t b[],  DB_t final_CW, bool party, size_t db_nitems, size_t rotate_by = 0)
 {
-
  	for(size_t j = 0; j < db_nitems; ++j)
  	{ 
-	   const size_t ind = (j + rotate_by) % db_nitems;
+	  const size_t ind = (j + rotate_by) % db_nitems;
 	 	DB_t tmp = (flags[ind] * final_CW);
 	 	DB[j] = DB[j] + b[ind]  + tmp;     
-		updated_DB[j] = DB[j];
+		 updated_DB[j] = DB[j];
  	}
 }
 
@@ -19,12 +18,9 @@ void duoram_update(tcp::socket& in2, tcp::socket& sb, DB_t DB[], DB_t updated_DB
 	write(sb, boost::asio::buffer(&tmp, sizeof(tmp)));
 	write(in2, boost::asio::buffer(&tmp, sizeof(tmp)));
 	read(sb, boost::asio::buffer(&recv_final_cw, sizeof(recv_final_cw)));
- 
-	recv_final_cw = recv_final_cw + tmp;
-   
+	recv_final_cw = recv_final_cw + tmp;   
 	write_into_the_database(DB, updated_DB, flags, standard_basis, recv_final_cw, party, db_nitems, offset);
 
-
 }
 
 void reconstruct_database(tcp::socket& sb, DB_t DB[], const size_t db_nitems)
@@ -46,7 +42,6 @@ auto DuoramUpdate(bool party, size_t db_nitems,   size_t rotate_by_,
 {
 
 	read_flags_for_updating(party, db_nitems);
-	
 	write_into_the_database(DB, updated_DB, writing_b, b, final_CW, party, db_nitems, - rotate_by_);
 			
 	#ifdef ThreeParty

+ 26 - 34
duoram-online/duoram.cpp

@@ -32,9 +32,6 @@ using socket_t = boost::asio::ip::tcp::socket;
 #include "duoram-refresh.h"
 #include "duoram-write.h"
 
-
-
- 
 void accept_conncections_from_Pb(boost::asio::io_context&io_context, std::vector<socket_t>& sockets_, int port, size_t j)
 {
   tcp::acceptor acceptor_a(io_context, tcp::endpoint(tcp::v4(), port));
@@ -42,8 +39,6 @@ void accept_conncections_from_Pb(boost::asio::io_context&io_context, std::vector
 	 sockets_[j] = std::move(sb_a);    
 }
 
- 
-
 int main(const int argc, const char * argv[])
 {
 	
@@ -121,10 +116,8 @@ int main(const int argc, const char * argv[])
 
 
 
-#if (PARTY == 0)    
-  	 
- 	party = false;
-
+ #if (PARTY == 0)     	 
+  party = false;
  	#ifdef ThreeParty	
 		for(size_t j = 0; j < number_of_sockets; ++j)
 		{
@@ -279,9 +272,9 @@ int main(const int argc, const char * argv[])
 				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 
+				#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)));
@@ -295,22 +288,21 @@ int main(const int argc, const char * argv[])
 		#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);
+		 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
+		 #ifdef DEBUG		
+			 #ifdef ThreeParty
 					/*The definition debug_ appears in duoram-utils.h*/  
 					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());
 	
 	#ifdef VERBOSE
 		std::cout << "Reconstructing the database after doing " << number_of_writes << " writes " << std::endl;
@@ -319,9 +311,9 @@ int main(const int argc, const char * argv[])
 	// WRITES END.
 
   #ifdef ThreeParty
-   #ifdef VERBOSE
-		   std::cout << std::endl << std::endl << "============== WRITES END ==============" << std::endl << std::endl;
-   #endif
+  #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];
@@ -345,17 +337,17 @@ int main(const int argc, const char * argv[])
 		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
+	 	#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);
+			 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
-	    }
+		  #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;

+ 16 - 22
duoram-online/p2.cpp

@@ -36,13 +36,8 @@ DB_t alpha;
 
 typedef __m128i leaf_t;
 typedef __m128i node_t;
- 
   
-const size_t target = 22;
-const leaf_t val =   _mm_set1_epi8(0x01);
-
 using socket_t = boost::asio::ip::tcp::socket;
- 
 
 using namespace std;
  
@@ -54,7 +49,7 @@ auto generate_cancelation_terms(int8_t c0[], int8_t d1[], size_t db_nitems, size
    DB_t cancelation_term0 = -Z0 ;
    DB_t cancelation_term1 = -Z1 ; 
 
-  return std::make_pair(cancelation_term0, cancelation_term1);
+   return std::make_pair(cancelation_term0, cancelation_term1);
 }
  
  
@@ -144,24 +139,24 @@ int main(int argc, char* argv[])
    X0 = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
    X1 = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
     
-  for(size_t j = 0; j < db_nitems; ++j)
-  {
-   X0[j] = 0;
-   X1[j] = 0; 
-  }
+   for(size_t j = 0; j < db_nitems; ++j)
+   {
+    X0[j] = 0;
+    X1[j] = 0; 
+   }
 
   
-  DuORAM_Write * WriteP0_recv = new DuORAM_Write[number_of_ind_writes];
-  DuORAM_Write * WriteP1_recv = new DuORAM_Write[number_of_ind_writes];
-
-  DB_t * Gamma0_ = new DB_t[number_of_ind_writes];
-  DB_t * Gamma1_ = new DB_t[number_of_ind_writes];
-  DB_t * update_message0 = new DB_t[number_of_ind_writes];
-  DB_t * update_message1 = new DB_t[number_of_ind_writes];
-  DB_t * FCW = new DB_t[number_of_ind_writes];
+   DuORAM_Write * WriteP0_recv = new DuORAM_Write[number_of_ind_writes];
+   DuORAM_Write * WriteP1_recv = new DuORAM_Write[number_of_ind_writes];
+
+   DB_t * Gamma0_ = new DB_t[number_of_ind_writes];
+   DB_t * Gamma1_ = new DB_t[number_of_ind_writes];
+   DB_t * update_message0 = new DB_t[number_of_ind_writes];
+   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 i = 0; i < number_of_accesses; ++i)
+   {
      for(size_t w = 0; w < number_of_ind_writes; ++w)
      {
        read_flags_for_refreshing(db_nitems);
@@ -238,7 +233,6 @@ int main(int argc, char* argv[])
   }
 
   return 0;
-
 }
 
  

+ 0 - 7
duoram-online/prg_aes_impl.h

@@ -1,10 +1,3 @@
-/* Copyright (C) 2019  Anonymous
- *
- * This is a pre-release version of the DPF++ library distributed anonymously
- * for peer review. A public release of the software will be published under the
- * LPGL v2.1 license in the near future. Please do not redistribute this version
- * of the software.
- */
 
 #ifndef DPFPP_PRG_AES_IMPL_H__
 #define DPFPP_PRG_AES_IMPL_H__

+ 20 - 20
duoram-online/readvectors.h

@@ -144,45 +144,45 @@ int read_flags_for_writing(bool party, size_t db_nitems, int i = 0)
 
 int read_flags_for_generating_cancellation_terms(size_t db_nitems, int i = 0)
 {
-    char tmp[100];
-    concatanate_index("preprocflags/P2_party1_read_flags_d", tmp, i);
-    int const in2 { open(tmp, O_RDONLY ) };
-    size_t r = read(in2, reading_d,  db_nitems * sizeof(reading_d[0])); 
-    if(r < 0) perror("Read error");
+  char tmp[100];
+  concatanate_index("preprocflags/P2_party1_read_flags_d", tmp, i);
+  int const in2 { open(tmp, O_RDONLY ) };
+  size_t r = read(in2, reading_d,  db_nitems * sizeof(reading_d[0])); 
+  if(r < 0) perror("Read error");
 
-    concatanate_index("preprocflags/P2_party0_read_flags_c", tmp, i);
-    int const in2_ { open(tmp, O_RDONLY ) };
-    r = read(in2_, reading_c,  db_nitems * sizeof(reading_c[0])); 
-    if(r < 0) perror("Read error");
+  concatanate_index("preprocflags/P2_party0_read_flags_c", tmp, i);
+  int const in2_ { open(tmp, O_RDONLY ) };
+  r = read(in2_, reading_c,  db_nitems * sizeof(reading_c[0])); 
+  if(r < 0) perror("Read error");
    
-   return 0;
+  return 0;
 }
 
 
 int read_flags_for_updating(bool party, size_t db_nitems, int i = 0)
 {
-  char tmp[100];
+ char tmp[100];
 	if(!party)
 	{
-    concatanate_index("preprocflags/party0_write_b", tmp, i);
+  concatanate_index("preprocflags/party0_write_b", tmp, i);
 		int const in0_w_ { open(tmp, O_RDONLY ) };
 		size_t r = read(in0_w_, b,  db_nitems * sizeof(b[0]));	
-	  if(r < 0) perror("Read error");
+	 if(r < 0) perror("Read error");
  	
-    concatanate_index("preprocflags/party0_write_c", tmp, i);
-    int const in1_w_ { open(tmp, O_RDONLY ) };
+  concatanate_index("preprocflags/party0_write_c", tmp, i);
+  int const in1_w_ { open(tmp, O_RDONLY ) };
 		r = read(in1_w_, c,  db_nitems * sizeof(c[0]));
-    if(r < 0) perror("Read error");
+  if(r < 0) perror("Read error");
 
-    concatanate_index("preprocflags/party0_write_d", tmp, i); 
-   int const in2_w_ { open(tmp, O_RDONLY ) };
+  concatanate_index("preprocflags/party0_write_d", tmp, i); 
+  int const in2_w_ { open(tmp, O_RDONLY ) };
 	 r = read(in2_w_, d,  db_nitems * sizeof(d[0]));	
-   if(r < 0) perror("Read error");
+  if(r < 0) perror("Read error");
 	}
 
 	if(party)
 	{
-     concatanate_index("preprocflags/party1_write_b", tmp, i);
+  concatanate_index("preprocflags/party1_write_b", tmp, i);
  	int const in0_w_ { open( tmp, O_RDONLY ) };
 	 size_t r = read(in0_w_, b,  db_nitems * sizeof(b[0]));	
   if(r < 0) perror("Read error");