Browse Source

simplepir, more verbosity on tests, some memory leaks fixed

Carlos Aguilar 6 years ago
parent
commit
e1cf7c1f91

+ 12 - 3
apps/simplepir/simplePIR.cpp

@@ -140,7 +140,7 @@ bool run(DBHandler *db, uint64_t chosen_element, PIRParameters params){
     outptr+=r_extractor->getPlaintextReplyBytesize();
     free(tmp);
   }
-  // Result is in ... result  
+  // Result is in ... result
   
 
   /******************************************************************************
@@ -167,7 +167,8 @@ bool run(DBHandler *db, uint64_t chosen_element, PIRParameters params){
   delete imported_db;
   r_generator->freeQueries();
   delete r_generator;
-
+  free(result);
+  free(db_element);
   
 	return fail;
 	
@@ -202,7 +203,8 @@ int main(int argc, char * argv[]) {
   // maxFileBytesize = database_size/nb_files;
 
   // Simple test
-  database_size = 1ULL<<25; nb_files = 20; maxFileBytesize = database_size/nb_files;
+  std::cout << "Test 1/7: database_size = 1ULL<<31; nb_files = 20; params.alpha = 1; params.d = 1;params.crypto_params = LWE:80:2048:120;" << std::endl; 
+  database_size = 1ULL<<31; nb_files = 20; maxFileBytesize = database_size/nb_files;
   DBGenerator db(nb_files, maxFileBytesize, /*bool silent*/ false); 
   chosen_element = 3;
   params.alpha = 1; params.d = 1; params.n[0] = nb_files; 
@@ -215,6 +217,7 @@ int main(int argc, char * argv[]) {
   // Test with aggregation
   // WARNING we must provide the representation of the database GIVEN recursion and aggregation
   // as here we have 100 elements and aggregate them in a unique group we have params.n[0]=1
+  std::cout << "Test 2/7: database_size = 1ULL<<25; nb_files = 100; params.alpha = 100; params.d = 1;params.crypto_params = LWE:80:2048:120;" << std::endl; 
   database_size = 1ULL<<25; nb_files = 100; maxFileBytesize = database_size/nb_files;
   DBGenerator db2(nb_files, maxFileBytesize, /*bool silent*/ false); 
   chosen_element = 0;
@@ -223,6 +226,7 @@ int main(int argc, char * argv[]) {
   tests_failed |= run(&db2, chosen_element, params);
   
   // Test with recursion 2
+  std::cout << "Test 3/7: database_size = 1ULL<<25; nb_files = 100; params.alpha = 1; params.d = 2;params.crypto_params = LWE:80:2048:120;" << std::endl; 
   database_size = 1ULL<<25; nb_files = 100; maxFileBytesize = database_size/nb_files;
   DBGenerator db3(nb_files, maxFileBytesize, /*bool silent*/ false); 
   chosen_element = 3;
@@ -231,6 +235,7 @@ int main(int argc, char * argv[]) {
   tests_failed |= run(&db3, chosen_element, params);
   
   // Test with recursion 2 and aggregation
+  std::cout << "Test 4/7: database_size = 1ULL<<25; nb_files = 100; params.alpha = 2; params.d = 2;params.crypto_params = LWE:80:2048:120;" << std::endl; 
   database_size = 1ULL<<25; nb_files = 100; maxFileBytesize = database_size/nb_files;
   DBGenerator db4(nb_files, maxFileBytesize, /*bool silent*/ false); 
   chosen_element = 3;
@@ -239,6 +244,7 @@ int main(int argc, char * argv[]) {
   tests_failed |= run(&db4, chosen_element, params);
   
   // Test with recursion 3
+  std::cout << "Test 5/7: database_size = 1ULL<<25; nb_files = 100; params.alpha = 1; params.d = 3;params.crypto_params = LWE:80:2048:120;" << std::endl; 
   database_size = 1ULL<<25; nb_files = 100; maxFileBytesize = database_size/nb_files;
   DBGenerator db5(nb_files, maxFileBytesize, /*bool silent*/ false); 
   chosen_element = 3;
@@ -247,6 +253,7 @@ int main(int argc, char * argv[]) {
   tests_failed |= run(&db5, chosen_element, params);
   
   // Test with a DBDirectoryProcessor splitting a big real file
+  std::cout << "Test 6/7: DBDirectoryProcessor with split; database_size = 1ULL<<25; nb_files = 4; params.alpha = 1; params.d = 1;params.crypto_params = LWE:80:2048:120;" << std::endl; 
   database_size = 1ULL<<25; nb_files = 4; maxFileBytesize = database_size/nb_files;
   DBDirectoryProcessor db6(/*split the bit file in*/ nb_files /*files*/);
   chosen_element = 3;
@@ -255,6 +262,7 @@ int main(int argc, char * argv[]) {
   tests_failed |= run(&db6, chosen_element, params);
   
   // Test with a DBDirectoryProcessor reading real files
+  std::cout << "Test 7/7: DBDirectoryProcessor without split; params.alpha = 1; params.d = 1;params.crypto_params = LWE:80:2048:120;" << std::endl; 
   DBDirectoryProcessor db7;
   database_size = db7.getDBSizeBits()/8; nb_files = db7.getNbStream(); 
   maxFileBytesize = database_size/nb_files;
@@ -262,6 +270,7 @@ int main(int argc, char * argv[]) {
   params.alpha = 1; params.d = 1; params.n[0] = nb_files; 
   params.crypto_params = "LWE:80:2048:120";
   tests_failed |= run(&db7, chosen_element, params);
+
   if (tests_failed) 
   {
     std::cout << "WARNING : at least one tests failed" << std::endl;

+ 1 - 1
apps/tools/check-correctness.sh

@@ -207,7 +207,7 @@ if [[ TEST_PAILLIER -eq 1 ]]; then
     done
 fi
 
-echo -e "\n\nOther tests\n#################\n"
+echo -e "\n\nTests\n#################\n"
 for DB in $ONE_MBIT $TEN_MBIT $HUNDRED_MBIT $ONE_GBIT 
 do
     for L in $ONE_KBIT $HUNDRED_KBIT $TEN_MBIT $ONE_GBIT  

+ 7 - 0
apps/tools/mkdb-correctness.sh

@@ -27,6 +27,13 @@ ONE_GBIT=1024000000
 #files: 1kbits, 100kbits, 10mbits 1gbit
 #bases: 1Mbits, 10M, 100M, 1G, 10G
 
+if [[ -e check.repo ]]
+then
+  echo "Check repo exists, not rebuilding it"
+  echo "Remove it manually if you want it rebuilt"
+  return
+fi
+
 mkdir check.repo
 cp -r ../client/exp check.repo/
 cd check.repo

+ 3 - 1
crypto/NFLLWE.cpp

@@ -449,7 +449,9 @@ void NFLLWE::dec(poly64 m, lwe_cipher *c)
 	    mpz_clear(tmprez[i]);
 	  }
     
-    free(tmprez);
+    delete[] tmprez;
+    mpz_clear(moduliProduct);
+    mpz_clear(tmpz);
   } else { // nbModuli=1
 	
 	

+ 1 - 0
pir/libpir.cpp

@@ -7,6 +7,7 @@
       free(((lwe_in_data *)imported_database_ptr)[i].p[0]);
       free(((lwe_in_data *)imported_database_ptr)[i].p);
     }
+    free(imported_database_ptr);
   }
 
 

+ 1 - 1
pir/replyGenerator/PIRReplyGeneratorNFL_internal.cpp

@@ -75,7 +75,7 @@ void PIRReplyGeneratorNFL_internal::importDataNFL(uint64_t offset, uint64_t byte
 
 	for (unsigned int i = 0 ; i < pirParam.d ; i++) theoretical_files_nbr *= pirParam.n[i];
 
-	input_data = new lwe_in_data[theoretical_files_nbr];
+	input_data = (lwe_in_data *) malloc(sizeof(lwe_in_data)*theoretical_files_nbr);
 	char *rawBits = (char*)calloc(fileByteSize*pirParam.alpha, sizeof(char));
 
 	currentMaxNbPolys=0;