PIRReplyGeneratorNFL_internal.hpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 "pir/dbhandlers/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. protected:
  51. void freeResult();
  52. void freeQueries();
  53. void freeQueriesBuffer();
  54. void generateReply();
  55. imported_database_t generateReplyGeneric(bool keep_imported_data = false);
  56. void generateReplyGenericFromData(const imported_database_t database);
  57. size_t getTotalSystemMemory();
  58. lwe_in_data* input_data;
  59. LatticesBasedCryptosystem* cryptoMethod;
  60. uint64_t currentMaxNbPolys;
  61. public:
  62. PIRReplyGeneratorNFL_internal();
  63. PIRReplyGeneratorNFL_internal(PIRParameters& param, DBHandler *db);
  64. ~PIRReplyGeneratorNFL_internal();
  65. void importDataNFL(uint64_t offset, uint64_t bytes_per_file);
  66. void initQueriesBuffer();
  67. void generateReplyExternal(imported_database_t* database);
  68. double generateReplySimulation(const PIRParameters& pir_params, uint64_t plaintext_nbr);
  69. double precomputationSimulation(const PIRParameters& pir_params, uint64_t plaintext_nbr);
  70. unsigned long computeReplySizeInChunks(unsigned long int);
  71. void pushQuery(char* rawQuery, unsigned int size, int dim, int nbr);
  72. void pushQuery(char* rawQuery);
  73. void setCryptoMethod(CryptographicSystem* cm);
  74. };
  75. #endif