PIRReplyGeneratorGMP.hpp 2.4 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_PIRREPLYGENERATOR
  18. #define DEF_PIRREPLYGENERATOR
  19. #include <omp.h>
  20. #include <string>
  21. #include <boost/thread.hpp>
  22. #include <boost/interprocess/sync/interprocess_semaphore.hpp>
  23. #include "pir/PIRParameters.hpp"
  24. #include "pir/replyGenerator/GenericPIRReplyGenerator.hpp"
  25. #include "crypto/PaillierAdapter.hpp"
  26. using namespace std;
  27. class PIRReplyGeneratorGMP : public GenericPIRReplyGenerator
  28. {
  29. private:
  30. mpz_t **datae;
  31. mpz_t **queriesBuf;
  32. bool firstTime;
  33. bool finished;
  34. PaillierAdapter* cryptoMethod;
  35. void computeMul (mpz_t query, mpz_t n, mpz_t res, int);
  36. void computeSum (mpz_t a, mpz_t b, int);
  37. void pushReply(mpz_t* replies, unsigned init_reply, unsigned replies_size);
  38. void generateReply( mpz_t *queries,
  39. mpz_t** data, int begin_data,
  40. int s,
  41. mpz_t* result);
  42. void importData();
  43. void importFakeData(uint64_t plaintext_nbr);
  44. void clearFakeData(uint64_t plaintext_nbr);
  45. void generateReply();
  46. void cleanQueryBuffer();
  47. void freeResult();
  48. public:
  49. PIRReplyGeneratorGMP();
  50. PIRReplyGeneratorGMP(PIRParameters& param, DBHandler *db);
  51. ~PIRReplyGeneratorGMP();
  52. imported_database_t generateReplyGeneric(bool keep_imported_data);
  53. void generateReplyGenericFromData(const imported_database_t database);
  54. double generateReplySimulation(const PIRParameters& pir_params, uint64_t plaintext_nbr);
  55. void initQueriesBuffer();
  56. void setCryptoMethod(CryptographicSystem* generator);
  57. void setPirParams(PIRParameters&);
  58. shared_queue< char*>& getRepliesBuffer();
  59. bool isFinished();
  60. void pushQuery(char* rawQuery, unsigned int size, int dim, int nbr);
  61. unsigned long computeReplySizeInChunks(unsigned long int);
  62. };
  63. #endif