OptimService.hpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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_OPTIM_SERVICES
  18. #define DEF_OPTIM_SERVICES
  19. #include <map>
  20. #include <string>
  21. #include <vector>
  22. #include <set>
  23. #include <fstream>
  24. #include <iostream>
  25. #include <boost/algorithm/string.hpp>
  26. #include "OptimVars.hpp"
  27. #include "crypto/HomomorphicCrypto.hpp"
  28. #include "crypto/HomomorphicCryptoFactory_internal.hpp"
  29. using namespace std;
  30. class OptimService
  31. {
  32. protected:
  33. static const std::string testValuesFileName;
  34. static const std::string getCurrentTime();
  35. public:
  36. static const std::string folderName;
  37. static const std::string fileName;
  38. static const std::string absFileExtension;
  39. static const std::string encFileExtension;
  40. static const std::string decFileExtension;
  41. static bool fileOutdated(std::string crypto_name, std::string extension);
  42. static int readEntireFile(std::string& file_content, const std::string& file_path);
  43. static void getAllOptimData(std::vector<FixedVars>& fixed_vars_vec, std::string testValuesFileName);
  44. static int readOptimData(map<std::string, double>& values, const std::string& file_path);
  45. static int writeOptimData(double encrypt_time, double decrypt_time, std::string crypto_params_desc, std::string crypto_name);
  46. static int writeOptimDataBuffer(const std::string& buffer, const std::string& file_path);
  47. static int readTestValues(unsigned int i, FixedVars& vars, std::string testValuesFileName);
  48. static void gotoLine(std::ifstream& file, unsigned int num);
  49. static int getNumberOfExperiences(std::string testValuesFileName);
  50. static unsigned int getNumberOfLines(std::ifstream& f);
  51. static int verifyOptimData(set<string> crypto_params_set, const std::string& fenc_path, const std::string& fdec_path);
  52. static void writeHeadFile(unsigned int i, FixedVars& fixedVars);
  53. static void writeTestCurrentResult(unsigned int alpha, unsigned int alphaMul, unsigned int d, unsigned int i, OptimVars& vars);
  54. static void writeTestCurrentResult(unsigned int alpha_min, unsigned int alpha_max, unsigned int alpha_curr, unsigned int a_inf_bound, unsigned int a_sup_bound, unsigned int d, unsigned int i, OptimVars& vars);
  55. static void writeFootFile(unsigned int i);
  56. static void writeMessage(unsigned int i, std::string const& message);
  57. static void writeConfigFile(unsigned int alpha, unsigned int alphaMul, unsigned int d, unsigned int exp_nbr);
  58. static void writeLWEFile(unsigned int order, unsigned int p_size, unsigned int exp_nbr);
  59. };
  60. #endif