HomomorphicCryptoFactory_internal.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. }