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