pir_client.hpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #include "pir.hpp"
  3. #include <memory>
  4. #include <vector>
  5. using namespace std;
  6. class PIRClient {
  7. public:
  8. PIRClient(const seal::EncryptionParameters &encparms,
  9. const PirParams &pirparams);
  10. PirQuery generate_query(std::uint64_t desiredIndex);
  11. seal::Plaintext decode_reply(PirReply reply);
  12. seal::GaloisKeys generate_galois_keys();
  13. // Index and offset of an element in an FV plaintext
  14. uint64_t get_fv_index(uint64_t element_idx, uint64_t ele_size);
  15. uint64_t get_fv_offset(uint64_t element_idx, uint64_t ele_size);
  16. private:
  17. seal::EncryptionParameters enc_params_;
  18. PirParams pir_params_;
  19. std::unique_ptr<seal::Encryptor> encryptor_;
  20. std::unique_ptr<seal::Decryptor> decryptor_;
  21. std::unique_ptr<seal::Evaluator> evaluator_;
  22. std::unique_ptr<seal::KeyGenerator> keygen_;
  23. std::shared_ptr<seal::SEALContext> context_;
  24. vector<uint64_t> indices_; // the indices for retrieval.
  25. vector<uint64_t> inverse_scales_;
  26. seal::Ciphertext compose_to_ciphertext(std::vector<seal::Plaintext> plains);
  27. friend class PIRServer;
  28. };