pir_server.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #pragma once
  2. #include "pir.hpp"
  3. #include <map>
  4. #include <memory>
  5. #include <vector>
  6. #include "pir_client.hpp"
  7. class PIRServer {
  8. public:
  9. PIRServer(const seal::EncryptionParameters &params, const PirParams &pir_params);
  10. //void update_parameters(const seal::EncryptionParameters &expanded_params,
  11. // const PirParams &pir_params);
  12. // NOTE: server takes over ownership of db and frees it when it exits.
  13. // Caller cannot free db
  14. void set_database(std::unique_ptr<std::vector<seal::Plaintext>> &&db);
  15. void set_database(const std::unique_ptr<const std::uint8_t[]> &bytes, std::uint64_t ele_num, std::uint64_t ele_size);
  16. void preprocess_database();
  17. std::vector<seal::Ciphertext> expand_query(
  18. const seal::Ciphertext &encrypted, std::uint32_t m, uint32_t client_id, PIRClient &client);
  19. PirReply generate_reply(PirQuery query, std::uint32_t client_id, PIRClient &client);
  20. void set_galois_key(std::uint32_t client_id, seal::GaloisKeys galkey);
  21. private:
  22. seal::EncryptionParameters params_; // SEAL parameters
  23. //seal::EncryptionParameters expanded_params_; // SEAL parameters
  24. PirParams pir_params_; // PIR parameters
  25. std::unique_ptr<Database> db_;
  26. bool is_db_preprocessed_;
  27. std::map<int, seal::GaloisKeys> galoisKeys_;
  28. std::unique_ptr<seal::Evaluator> evaluator_;
  29. void decompose_to_plaintexts_ptr(const seal::Ciphertext &encrypted, seal::Plaintext *plain_ptr, int logt);
  30. std::vector<seal::Plaintext> decompose_to_plaintexts(const seal::Ciphertext &encrypted);
  31. void multiply_power_of_X(const seal::Ciphertext &encrypted, seal::Ciphertext &destination,
  32. std::uint32_t index);
  33. };