HomomorphicCrypto.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_HOMOMORPHICCRYPTO
  18. #define DEF_HOMOMORPHICCRYPTO
  19. #include <string>
  20. #include <set>
  21. #include <boost/algorithm/string.hpp>
  22. #include "../pir/PIRParameters.hpp"
  23. #include "AbstractPublicParameters.hpp"
  24. #ifndef DEF_CRYPTOGRAPHICSYSTEM
  25. #define DEF_CRYPTOGRAPHICSYSTEM
  26. class CryptographicSystem
  27. {
  28. public:
  29. virtual AbstractPublicParameters& getPublicParameters()=0;
  30. virtual unsigned int getAllCryptoParams(std::set<std::string>& crypto_params_set)=0;
  31. virtual void setNewParameters(const std::string& crypto_param)=0;
  32. virtual ~CryptographicSystem(){};
  33. virtual std::string& toString()=0;
  34. };
  35. #endif
  36. class HomomorphicCrypto : public CryptographicSystem {
  37. protected:
  38. std::string cryptoName;
  39. static unsigned int default_security_bits;
  40. public:
  41. HomomorphicCrypto(const std::string& crypto_name);
  42. virtual char* encrypt(unsigned int ui, unsigned int )=0;
  43. virtual char* encrypt(char* data, size_t, unsigned int exponent )=0;
  44. virtual char* encrypt_perftest()=0;
  45. virtual char* decrypt(char* cipheredData, unsigned int rec_lvl, size_t, size_t)=0;
  46. virtual unsigned int getCryptoParams(unsigned int k, std::set<std::string>& crypto_params)=0;
  47. virtual long setandgetAbsBitPerCiphertext(unsigned int elt_nbr)=0;
  48. virtual std::string getSerializedCryptoParams(bool shortversion=true)=0;
  49. virtual double estimateAbsTime(std::string crypto_param)=0;
  50. virtual ~HomomorphicCrypto();
  51. double estimatePrecomputeTime(std::string crypto_param) { return 0;}
  52. std::string& toString() { return cryptoName;}
  53. };
  54. #endif