Browse Source

removed the setting of zero for target

avadapal 1 year ago
parent
commit
0e1fe1e199
4 changed files with 85 additions and 38 deletions
  1. 5 6
      preprocessing/dpfgen.h
  2. 21 1
      preprocessing/filesio.h
  3. 15 3
      preprocessing/preprocessing.cpp
  4. 44 28
      preprocessing/share-conversion.h

+ 5 - 6
preprocessing/dpfgen.h

@@ -17,12 +17,11 @@ void generate_random_targets(uint8_t ** target_share_read, size_t n_threads, boo
 	{	
  		for(size_t i = 0; i < n_threads; ++i)
 		{
-			srand(3);
 			uint8_t random_value;
 			arc4random_buf(&random_value, sizeof(uint8_t));
 			target_share_read[i][j] = random_value;//rand();
-			target_share_read[i][j] = 0;//target_share_read[i][j] % 2;
-			if(party) target_share_read[i][expo-2] = 1;
+			target_share_read[i][j] = target_share_read[i][j] % 2;
+			//if(party) target_share_read[i][expo-2] = 1;
 		}
 	}
 }
@@ -328,7 +327,7 @@ inline void create_dpfs ( size_t db_nitems, const AES_KEY& prgkey,  uint8_t targ
 				}
 			#endif
 
-			dpf_instance[ind].CW[layer] 		=  CW[layer];
+			dpf_instance[ind].CW[layer] 		   =  CW[layer];
 			dpf_instance[ind].cwt_L[layer]   =  cwt_L;
 			dpf_instance[ind].cwt_R[layer]   =  cwt_R;
 			
@@ -453,8 +452,8 @@ inline void evaluate_dpfs( size_t db_nitems,  dpfP2 dpfinstance,  const AES_KEY&
 
 			for(size_t j = 0; j < nodes_in_prev_layer; ++j)
 			{	
-				t[curlayer][2*j] 	 = get_lsb(s[curlayer][2*j]) ^ (cwt_L[layer] & t[1-curlayer][j]);
-				s[curlayer][2*j] 	 = clear_lsb(xor_if(s[curlayer][2*j], CW[layer], !t[1-curlayer][j]), 0b11);
+				t[curlayer][2*j]   	 = get_lsb(s[curlayer][2*j]) ^ (cwt_L[layer] & t[1-curlayer][j]);
+				s[curlayer][2*j] 	   = clear_lsb(xor_if(s[curlayer][2*j], CW[layer], !t[1-curlayer][j]), 0b11);
 				t[curlayer][(2*j)+1] = get_lsb(s[curlayer][(2*j)+1]) ^ (cwt_R[layer] & t[1-curlayer][j]);
 				s[curlayer][(2*j)+1] = clear_lsb(xor_if(s[curlayer][(2*j)+1], CW[layer], !t[1-curlayer][j]), 0b11);
 			}

+ 21 - 1
preprocessing/filesio.h

@@ -9,7 +9,7 @@
  * @param final_correction_word 
  */
 
-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)
+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, int64_t additve_sharesR)
 {
  if(!party) 
  {  
@@ -179,6 +179,16 @@ void write_evalfull_outs_into_a_file(bool party, size_t i, size_t db_nitems,  in
 		 int w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
 		 int written = write(w0, &final_correction_word[0],  sizeof(uint64_t));
 		 if(written<0)	perror("Write error");
+   close(w0);
+   
+   p1_filename0 = "../duoram-online/preprocflags/R1";
+	 	strcpy(tmp, p1_filename0);
+ 		strcat(tmp, std::to_string(i).c_str());
+		
+		 w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+		 written = write(w0, &additve_sharesR,  sizeof(int64_t));
+		 if(written<0)	perror("Write error");
+
 		 close(w0);
 	}
 	
@@ -194,6 +204,16 @@ void write_evalfull_outs_into_a_file(bool party, size_t i, size_t db_nitems,  in
 		int written = write(w0, &final_correction_word[0],  sizeof(uint64_t));
 		if(written<0) perror("Write error");
 		close(w0);
+
+  p0_filename0 = "../duoram-online/preprocflags/R0";
+	 strcpy(tmp, p0_filename0);
+ 	strcat(tmp, std::to_string(i).c_str());
+		
+		w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
+		written = write(w0, &additve_sharesR,  sizeof(int64_t));
+		if(written<0)	perror("Write error");
+
+		 close(w0);
 	}
  
 }

+ 15 - 3
preprocessing/preprocessing.cpp

@@ -156,9 +156,10 @@ int main(int argc, char * argv[])
 
     boost::asio::thread_pool pool_xor_to_additive(n_threads); 
 
+    std::array<int64_t, 128> additve_shares; 
     for(size_t j = 0; j < n_threads; ++j)
     {
-     boost::asio::post(pool_xor_to_additive, std::bind(xor_to_additive, party, target_share_read[j], std::ref(socketsPb[j]), std::ref(socketsP2[j])));
+     boost::asio::post(pool_xor_to_additive, std::bind(xor_to_additive, party, target_share_read[j], std::ref(socketsPb[j]), std::ref(socketsP2[j]), expo, std::ref(additve_shares[j])));
     }
 
     pool_xor_to_additive.join();
@@ -169,8 +170,19 @@ int main(int argc, char * argv[])
 
     for(size_t i = 0; i < n_threads; ++i)
     {
-     write_evalfull_outs_into_a_file(party, i, db_nitems, flags[i],  leaves[i], final_correction_word[i]); 
+     write_evalfull_outs_into_a_file(party, i, db_nitems, flags[i],  leaves[i], final_correction_word[i], additve_shares[i]); 
     }
-
+    
+    #ifdef VERBOSE
+     for(size_t j = 0; j < n_threads; ++j)
+     {
+      int64_t add_;
+      boost::asio::write(socketsPb[0], boost::asio::buffer(&additve_shares[j], sizeof(additve_shares[j])));
+      boost::asio::read(socketsPb[0], boost::asio::buffer(&add_, sizeof(add_)));
+      add_ = add_ + additve_shares[j];
+      std::cout << "add_ = " << add_ << std::endl;
+     }
+    #endif
+    
     return 0;
 }

+ 44 - 28
preprocessing/share-conversion.h

@@ -1,7 +1,8 @@
-uint64_t binary_to_decimal(std::array<uint64_t, 64> inp)
+//template<size_t N>
+int64_t binary_to_decimal(int64_t* inp, size_t logn)
 {
-	uint64_t output = 0;		
-	for(size_t j = 0; j < 64; ++j)
+	int64_t output = 0;		
+	for(size_t j = 0; j < logn; ++j)
 	{
 		output += (1ULL << j) * inp[j];
 	}
@@ -102,13 +103,18 @@ void P2_xor_to_additive(tcp::socket& s0, tcp::socket& s1, size_t socket_no)
   boost::asio::write(s1, boost::asio::buffer(&gamma1, sizeof(gamma1)));
 }
 
-int64_t xor_to_additive(bool party, uint8_t * target_share_read, tcp::socket& sb, tcp::socket& s2)
+void xor_to_additive(bool party, uint8_t * target_share_read, tcp::socket& sb, tcp::socket& s2, const size_t height, int64_t& R_share)
 {
-    const size_t logn = 64;
-    std::array<uint64_t, logn> b, b_blinded, b_recv;
+    const size_t logn = height;
+    //std::array<uint64_t, logn> b, b_blinded, b_recv;
+
+    int64_t b[64], b_blinded[64], b_recv[64]; 
+    
+ 
+
     for(size_t j = 0; j < logn; ++j)
     {
-      b[j] = target_share_read[j];
+      b[j] = target_share_read[logn-j - 1];
 
       #ifdef DEBUG
        uint8_t target_bit_rec;   
@@ -119,16 +125,18 @@ int64_t xor_to_additive(bool party, uint8_t * target_share_read, tcp::socket& sb
     }
 
     #ifdef DEBUG
-     uint64_t b_ = binary_to_decimal(b);
+     uint64_t b_ = binary_to_decimal(b, logn);;
      std::cout << "b_ = " << b_ << std::endl;
     #endif
     
-    std::array<uint64_t, logn> c_mul;
-    std::array<uint64_t, logn> d;
-  
-    uint64_t BLIND, Gamma;
-    boost::asio::read(s2, boost::asio::buffer(&BLIND, sizeof(uint64_t)));
-    boost::asio::read(s2, boost::asio::buffer(&Gamma, sizeof(uint64_t)));
+    // std::array<uint64_t, logn> c_mul;
+    // std::array<uint64_t, logn> d;
+    //uint64_t c_mul[logn], d[logn];
+    int64_t * c_mul = (int64_t*) malloc(logn * sizeof(int64_t));
+    int64_t * d     = (int64_t*) malloc(logn * sizeof(int64_t));
+    int64_t BLIND, Gamma;
+    boost::asio::read(s2, boost::asio::buffer(&BLIND, sizeof(int64_t)));
+    boost::asio::read(s2, boost::asio::buffer(&Gamma, sizeof(int64_t)));
 
 
     for(size_t j = 0; j < logn; ++j)
@@ -144,8 +152,8 @@ int64_t xor_to_additive(bool party, uint8_t * target_share_read, tcp::socket& sb
     std::cout << "Gamma = " << Gamma << std::endl;
     #endif
     
-    uint64_t R_share = 0;
-    
+   // uint64_t R_share = 0;
+ 
     if(!party) 
     {
      for(size_t j = 0; j < logn; ++j) 
@@ -165,12 +173,12 @@ int64_t xor_to_additive(bool party, uint8_t * target_share_read, tcp::socket& sb
        R_share += (1ULL << j) * d[j];
       }
     }
-
+ 
     #ifdef DEBUG
      for(size_t j = 0; j < 1; ++j)
      {
        std::cout << "b = " << b[j] << std::endl;
-       uint64_t mul_Rec = 0;
+       int64_t mul_Rec = 0;
        boost::asio::write(sb, boost::asio::buffer(&c_mul[j], sizeof(c_mul[j])));
        boost::asio::read(sb, boost::asio::buffer(&mul_Rec, sizeof(mul_Rec)));
        std::cout << "c_mul = " << c_mul[j] << std::endl;
@@ -178,9 +186,14 @@ int64_t xor_to_additive(bool party, uint8_t * target_share_read, tcp::socket& sb
        std::cout << "mul_Rec = " << mul_Rec << std::endl;
      }
 
-     std::array<uint64_t, logn> b_reconstruction_;
-     std::array<uint64_t, logn> d_reconstruction_;
-     std::array<uint64_t, logn> d_recv;
+     //std::array<uint64_t, logn> b_reconstruction_;
+     //std::array<uint64_t, logn> d_reconstruction_;
+    // uint64_t b_reconstruction_[logn], d_reconstruction_[logn], d_recv[logn];
+     int64_t * b_reconstruction_         = (int64_t*) malloc(logn * sizeof(int64_t));
+     int64_t * d_reconstruction_ = (int64_t*) malloc(logn * sizeof(int64_t));
+     int64_t * d_recv    = (int64_t*) malloc(logn * sizeof(int64_t));
+     
+     //std::array<uint64_t, logn> d_recv;
      for(size_t j = 0; j < logn; ++j)
      {
       boost::asio::write(sb, boost::asio::buffer(&d[j], sizeof(d[j])));
@@ -192,30 +205,33 @@ int64_t xor_to_additive(bool party, uint8_t * target_share_read, tcp::socket& sb
 
      for(size_t j = 0; j < logn; ++j)
      {
-      uint64_t d_reconstruction = d[j] + d_recv[j];
+      int64_t d_reconstruction = d[j] + d_recv[j];
       d_reconstruction_[j] = d_reconstruction;
-      uint64_t b_reconstruction = b[j] ^ b_recv[j];
+      int64_t b_reconstruction = b[j] ^ b_recv[j];
       b_reconstruction_[j] = b_reconstruction;
       assert(d_reconstruction == b_reconstruction);
      }
       
-     uint64_t b_value =	binary_to_decimal(b_reconstruction_);
+     int64_t b_value =	binary_to_decimal(b_reconstruction_, logn);
      std::cout << "b_value = " << b_value << std::endl;
      std::cout << "logn = " << logn << std::endl;
 
      std::cout << "R_share = " << R_share << std::endl;
-     R_share = binary_to_decimal(d);
+     #endif
+     R_share = binary_to_decimal(d, logn);
+    
+    #ifdef DEBUG
      std::cout << "R_share = " << R_share << std::endl;
-     uint64_t R_share_reconstruction;
+     int64_t R_share_reconstruction;
      boost::asio::write(sb, boost::asio::buffer(&R_share, sizeof(R_share)));
      boost::asio::read(sb, boost::asio::buffer(&R_share_reconstruction, sizeof(R_share_reconstruction)));
      R_share_reconstruction = R_share_reconstruction + R_share;
      std::cout << "R_share_reconstruction = " << R_share_reconstruction << std::endl;
      std::cout << "b_value                = " << b_value << std::endl;
-     std::cout << "d_recons		 = " << binary_to_decimal(d_reconstruction_)<< std::endl;
+     std::cout << "d_recons		 = " << binary_to_decimal(d_reconstruction_, logn) << std::endl;
     #endif
 
-   return R_share;
+  // return R_share;
 }