PIRReplyGeneratorNFL_internal.hpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Copyright (C) 2014 Carlos Aguilar Melchor, Joris Barrier, Marc-Olivier Killijian
  2. * This file is part of XPIR.
  3. *
  4. * XPIR is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * XPIR is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with XPIR. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef DEF_PIRREPLYGENERATORNFL
  18. #define DEF_PIRREPLYGENERATORNFL
  19. #include <unistd.h>
  20. #include <omp.h>
  21. #include "pir/replyGenerator/GenericPIRReplyGenerator.hpp"
  22. #include "crypto/HomomorphicCrypto.hpp"
  23. #include "crypto/NFLLWE.hpp"
  24. #include "apps/server/DBGenerator.hpp"
  25. class PIRReplyGeneratorNFL_internal : public GenericPIRReplyGenerator
  26. {
  27. public:
  28. void setPirParams(PIRParameters& param);
  29. private:
  30. bool lwe;
  31. uint64_t current_query_index;
  32. uint64_t current_dim_index;
  33. #ifdef SHOUP
  34. lwe_query ***queriesBuf;
  35. #else
  36. lwe_query **queriesBuf;
  37. #endif
  38. //NFLLWE* cryptoMethod;
  39. void generateReply( lwe_query *queries,
  40. lwe_in_data* data,
  41. unsigned int lvl,
  42. lwe_cipher* result);
  43. char** exportResult(lwe_cipher** inter_reply, unsigned int absp_nbr, unsigned int max_chunk, unsigned int rec_lvl);
  44. lwe_cipher** importDatabase(char** database, unsigned int x_size, unsigned int y_size, unsigned int absp_nbr);
  45. lwe_in_data* fromResulttoInData(lwe_cipher** inter_reply, uint64_t reply_elt_nbr, unsigned int reply_rec_lvl);
  46. void importFakeData(uint64_t plaintext_nbr);
  47. void pushFakeQuery();
  48. void freeInputData();
  49. void freeFakeInputData();
  50. void freeResult();
  51. protected:
  52. void freeQuery();
  53. void generateReply();
  54. imported_database_t generateReplyGeneric(bool keep_imported_data = false);
  55. void generateReplyGenericFromData(const imported_database_t database);
  56. size_t getTotalSystemMemory();
  57. lwe_in_data* input_data;
  58. LatticesBasedCryptosystem* cryptoMethod;
  59. uint64_t currentMaxNbPolys;
  60. public:
  61. PIRReplyGeneratorNFL_internal();
  62. PIRReplyGeneratorNFL_internal(PIRParameters& param, DBHandler *db);
  63. ~PIRReplyGeneratorNFL_internal();
  64. void importDataNFL(uint64_t offset, uint64_t bytes_per_file);
  65. void initQueriesBuffer();
  66. void generateReplyExternal(imported_database_t* database);
  67. double generateReplySimulation(const PIRParameters& pir_params, uint64_t plaintext_nbr);
  68. double precomputationSimulation(const PIRParameters& pir_params, uint64_t plaintext_nbr);
  69. unsigned long computeReplySizeInChunks(unsigned long int);
  70. void pushQuery(char* rawQuery, unsigned int size, int dim, int nbr);
  71. void pushQuery(char* rawQuery);
  72. void setCryptoMethod(CryptographicSystem* cm);
  73. };
  74. #endif