pir_server.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 &enc_params, const PirParams &pir_params);
  10. // NOTE: server takes over ownership of db and frees it when it exits.
  11. // Caller cannot free db
  12. void set_database(std::unique_ptr<std::vector<seal::Plaintext>> &&db);
  13. void set_database(const std::unique_ptr<const std::uint8_t[]> &bytes, std::uint64_t ele_num, std::uint64_t ele_size);
  14. void preprocess_database();
  15. std::vector<seal::Ciphertext> expand_query(
  16. const seal::Ciphertext &encrypted, std::uint32_t m, uint32_t client_id);
  17. PirReply generate_reply(PirQuery query, std::uint32_t client_id);
  18. void set_galois_key(std::uint32_t client_id, seal::GaloisKeys galkey);
  19. private:
  20. seal::EncryptionParameters enc_params_; // SEAL parameters
  21. PirParams pir_params_; // PIR parameters
  22. std::unique_ptr<Database> db_;
  23. bool is_db_preprocessed_;
  24. std::map<int, seal::GaloisKeys> galoisKeys_;
  25. std::unique_ptr<seal::Evaluator> evaluator_;
  26. std::unique_ptr<seal::BatchEncoder> encoder_;
  27. std::shared_ptr<seal::SEALContext> context_;
  28. void decompose_to_plaintexts_ptr(const seal::Ciphertext &encrypted, seal::Plaintext *plain_ptr, int logt);
  29. std::vector<seal::Plaintext> decompose_to_plaintexts(const seal::Ciphertext &encrypted);
  30. void multiply_power_of_X(const seal::Ciphertext &encrypted, seal::Ciphertext &destination,
  31. std::uint32_t index);
  32. };