HomomorphicCryptoFactory_internal.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #include "HomomorphicCryptoFactory_internal.hpp"
  18. const unsigned int HomomorphicCryptoFactory_internal::crypto_method_nbr = 2;
  19. const std::vector<std::string> HomomorphicCryptoFactory_internal::crypto_method_name_vec = [] //use lambda function to initialise the vector
  20. {
  21. std::vector<std::string> v;
  22. v.push_back("Paillier");
  23. v.push_back("LWE");
  24. return v;
  25. }();
  26. HomomorphicCrypto* HomomorphicCryptoFactory_internal::getCrypto(std::string cryptoType)
  27. {
  28. HomomorphicCrypto* h;
  29. if (cryptoType == "Paillier")
  30. {
  31. h = new PaillierAdapter();
  32. }
  33. else if (cryptoType == "LWE")
  34. {
  35. h = new NFLLWE();
  36. }
  37. else if(cryptoType == "NoCryptography")
  38. {
  39. h = new NoCryptography();
  40. }
  41. else
  42. {
  43. std::cerr << "HomomorphicCryptoFactory_internal: Warning, unrecognized cryptosystem. Returning NULL" << std::endl;
  44. h = NULL;
  45. }
  46. return h;
  47. }
  48. HomomorphicCrypto* HomomorphicCryptoFactory_internal::getCryptoMethod(std::string crypto_system_desc)
  49. {
  50. std::vector<std::string> fields;
  51. boost::algorithm::split(fields, crypto_system_desc, boost::algorithm::is_any_of(":"));
  52. HomomorphicCrypto* h;
  53. h = getCrypto(fields[0]);
  54. h->setNewParameters(crypto_system_desc);
  55. return h;
  56. }
  57. // Returns a vector with all the cryptosystems THAT WE WANT TO BE USED
  58. void HomomorphicCryptoFactory_internal::getAllCryptoSystems(std::vector<HomomorphicCrypto*>& crypto_sys_vec)
  59. {
  60. HomomorphicCrypto* crypto_ptr = new PaillierAdapter();
  61. crypto_sys_vec.push_back(crypto_ptr);
  62. crypto_ptr = new NFLLWE();
  63. crypto_sys_vec.push_back(crypto_ptr);
  64. }
  65. void HomomorphicCryptoFactory_internal::getOneCryptoSystem(std::vector<HomomorphicCrypto*>& crypto_sys_vec, std::string crypto_system_desc)
  66. {
  67. std::vector<std::string> fields;
  68. boost::algorithm::split(fields, crypto_system_desc, boost::algorithm::is_any_of(":"));
  69. HomomorphicCrypto* h;
  70. h = getCrypto(fields[0]);
  71. crypto_sys_vec.push_back(h);
  72. }