Browse Source

Solved bug in cache generation

Carlos Aguilar 8 years ago
parent
commit
1ad2f3a1ab

+ 0 - 4
apps/simplepir/simplePIR.cpp

@@ -210,7 +210,6 @@ int main(int argc, char * argv[]) {
   // nb_files=db.getNbStream();database_size = db.getDBSizeinbits();
   // nb_files=db.getNbStream();database_size = db.getDBSizeinbits();
   // maxFileBytesize = database_size/nb_files;
   // maxFileBytesize = database_size/nb_files;
 
 
-#if 0
   // Simple test
   // Simple test
   std::cout << "======================================================================" << std::endl;
   std::cout << "======================================================================" << std::endl;
   std::cout << "Test 1/7: database_size = 1ULL<<30; nb_files = 20;" << std::endl;
   std::cout << "Test 1/7: database_size = 1ULL<<30; nb_files = 20;" << std::endl;
@@ -239,7 +238,6 @@ int main(int argc, char * argv[]) {
   params.alpha = 100; params.d = 1; params.n[0] = 1; 
   params.alpha = 100; params.d = 1; params.n[0] = 1; 
   params.crypto_params = "LWE:80:2048:120";
   params.crypto_params = "LWE:80:2048:120";
   tests_failed |= run(&db2, chosen_element, params);
   tests_failed |= run(&db2, chosen_element, params);
-#endif
 
 
   // Test with recursion 2
   // Test with recursion 2
   std::cout << "======================================================================" << std::endl;
   std::cout << "======================================================================" << std::endl;
@@ -253,7 +251,6 @@ int main(int argc, char * argv[]) {
   params.crypto_params = "LWE:80:2048:120";
   params.crypto_params = "LWE:80:2048:120";
   tests_failed |= run(&db3, chosen_element, params);
   tests_failed |= run(&db3, chosen_element, params);
   
   
-#if 0
   // Test with recursion 2 and aggregation
   // Test with recursion 2 and aggregation
   std::cout << "======================================================================" << std::endl;
   std::cout << "======================================================================" << std::endl;
   std::cout << "Test 4/7: database_size = 1ULL<<25; nb_files = 100;" << std::endl;
   std::cout << "Test 4/7: database_size = 1ULL<<25; nb_files = 100;" << std::endl;
@@ -310,7 +307,6 @@ int main(int argc, char * argv[]) {
     params.crypto_params = "LWE:80:2048:120";
     params.crypto_params = "LWE:80:2048:120";
     tests_failed |= run(&db7, chosen_element, params);
     tests_failed |= run(&db7, chosen_element, params);
   }
   }
-#endif
 
 
   if (tests_failed) 
   if (tests_failed) 
   {
   {

+ 1 - 2
crypto/NFLlib.cpp

@@ -59,6 +59,7 @@ void  NFLlib::configureNTT()
   shoupinvomegas = (uint64_t **) malloc(nbModuli * sizeof(uint64_t *));  
   shoupinvomegas = (uint64_t **) malloc(nbModuli * sizeof(uint64_t *));  
   invpolyDegree = (uint64_t *) malloc(nbModuli * sizeof(uint64_t));
   invpolyDegree = (uint64_t *) malloc(nbModuli * sizeof(uint64_t));
   liftingIntegers = new mpz_t[nbModuli];
   liftingIntegers = new mpz_t[nbModuli];
+  moduli=new uint64_t[nbModuli]();
 
 
   // From now on, we have to do everything nbModuli times
   // From now on, we have to do everything nbModuli times
   for(unsigned short currentModulus=0;currentModulus<nbModuli;currentModulus++) 
   for(unsigned short currentModulus=0;currentModulus<nbModuli;currentModulus++) 
@@ -223,8 +224,6 @@ void NFLlib::setmodulus(uint64_t aggregatedModulusBitsize_)
   }
   }
   nbModuli=aggregatedModulusBitsize_/kModulusBitsize;
   nbModuli=aggregatedModulusBitsize_/kModulusBitsize;
   
   
-  moduli=new uint64_t[nbModuli]();
-
   configureNTT();
   configureNTT();
 }
 }
 
 

+ 3 - 1
pir/replyGenerator/PIROptimizer.cpp

@@ -145,7 +145,7 @@ std::string PIROptimizer::computeOptimData(const std::string& crypto_name)
     optim_data2write += crypto_param + " " + out.str() + "\n";
     optim_data2write += crypto_param + " " + out.str() + "\n";
   }
   }
 
 
-  //delete generator_ptr;
+  delete generator_ptr;
   delete crypto_ptr;
   delete crypto_ptr;
 
 
   return optim_data2write;
   return optim_data2write;
@@ -166,6 +166,7 @@ double PIROptimizer::getAbs1PlaintextTime(HomomorphicCrypto* crypto_ptr, Generic
 
 
   do
   do
   {
   {
+    generator->mutex.try_lock();
     generator->mutex.unlock();
     generator->mutex.unlock();
     result = generator->generateReplySimulation(pir_params, plaintext_nbr);
     result = generator->generateReplySimulation(pir_params, plaintext_nbr);
     plaintext_nbr *= 2;
     plaintext_nbr *= 2;
@@ -193,6 +194,7 @@ double PIROptimizer::getPrecompute1PlaintextTime(HomomorphicCrypto* crypto_ptr,
 
 
   do
   do
   {
   {
+    generator->mutex.try_lock();
     generator->mutex.unlock();
     generator->mutex.unlock();
     result = generator->precomputationSimulation(pir_params, plaintext_nbr);
     result = generator->precomputationSimulation(pir_params, plaintext_nbr);
     plaintext_nbr *= 2;
     plaintext_nbr *= 2;

+ 3 - 3
pir/replyGenerator/PIRReplyGeneratorNFL_internal.cpp

@@ -482,6 +482,7 @@ void PIRReplyGeneratorNFL_internal::generateReply()
 
 
 double PIRReplyGeneratorNFL_internal::generateReplySimulation(const PIRParameters& pir_params, uint64_t plaintext_nbr)
 double PIRReplyGeneratorNFL_internal::generateReplySimulation(const PIRParameters& pir_params, uint64_t plaintext_nbr)
 {
 {
+  
   setPirParams((PIRParameters&)pir_params);
   setPirParams((PIRParameters&)pir_params);
   pushFakeQuery();
   pushFakeQuery();
   
   
@@ -517,11 +518,10 @@ double PIRReplyGeneratorNFL_internal::precomputationSimulation(const PIRParamete
   double start = omp_get_wtime();
   double start = omp_get_wtime();
   for (unsigned int i = 0 ; i < files_nbr ; i++)
   for (unsigned int i = 0 ; i < files_nbr ; i++)
   {
   {
-    {
       poly64 *tmp;
       poly64 *tmp;
-      tmp= cryptoMethod->deserializeDataNFL((unsigned char**)(input_data[i].p), (uint64_t) plaintext_nbr, cryptoMethod->getPublicParameters().getCiphertextBitsize()/2 , input_data[i].nbPolys);
+      tmp = cryptoMethod->deserializeDataNFL((unsigned char**)(input_data[i].p), (uint64_t) plaintext_nbr, cryptoMethod->getPublicParameters().getCiphertextBitsize()/2 , input_data[i].nbPolys);
 	    free(tmp[0]);	
 	    free(tmp[0]);	
-    }
+      tmp = NULL;
   }
   }
   double result = omp_get_wtime() - start;
   double result = omp_get_wtime() - start;
   std::cout << "PIRReplyGeneratorNFL_internal: Deserialize took " << result << " (omp)seconds" << std::endl;
   std::cout << "PIRReplyGeneratorNFL_internal: Deserialize took " << result << " (omp)seconds" << std::endl;