pir_client.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. std::vector<uint8_t> decode_reply(PirReply reply, uint64_t offset);
  13. seal::Plaintext decrypt(seal::Ciphertext ct);
  14. seal::GaloisKeys generate_galois_keys();
  15. // Index and offset of an element in an FV plaintext
  16. uint64_t get_fv_index(uint64_t element_index);
  17. uint64_t get_fv_offset(uint64_t element_index);
  18. private:
  19. seal::EncryptionParameters enc_params_;
  20. PirParams pir_params_;
  21. std::unique_ptr<seal::Encryptor> encryptor_;
  22. std::unique_ptr<seal::Decryptor> decryptor_;
  23. std::unique_ptr<seal::Evaluator> evaluator_;
  24. std::unique_ptr<seal::KeyGenerator> keygen_;
  25. std::unique_ptr<seal::BatchEncoder> encoder_;
  26. std::shared_ptr<seal::SEALContext> context_;
  27. vector<uint64_t> indices_; // the indices for retrieval.
  28. vector<uint64_t> inverse_scales_;
  29. seal::Ciphertext compose_to_ciphertext(std::vector<seal::Plaintext> plains);
  30. friend class PIRServer;
  31. };