pir_client.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. // Serializes the query into the provided stream and returns number of bytes written
  12. int generate_serialized_query(std::uint64_t desiredIndex, std::stringstream &stream);
  13. seal::Plaintext decode_reply(PirReply &reply);
  14. std::vector<uint64_t> extract_coeffs(seal::Plaintext pt);
  15. std::vector<uint64_t> extract_coeffs(seal::Plaintext pt, std::uint64_t offset);
  16. std::vector<uint8_t> extract_bytes(seal::Plaintext pt, std::uint64_t offset);
  17. std::vector<uint8_t> decode_reply(PirReply &reply, uint64_t offset);
  18. seal::Plaintext decrypt(seal::Ciphertext ct);
  19. seal::GaloisKeys generate_galois_keys();
  20. // Index and offset of an element in an FV plaintext
  21. uint64_t get_fv_index(uint64_t element_index);
  22. uint64_t get_fv_offset(uint64_t element_index);
  23. // Only used for simple_query
  24. seal::Ciphertext get_one();
  25. seal::Plaintext replace_element(seal::Plaintext pt, std::vector<std::uint64_t> new_element, std::uint64_t offset);
  26. private:
  27. seal::EncryptionParameters enc_params_;
  28. PirParams pir_params_;
  29. std::unique_ptr<seal::Encryptor> encryptor_;
  30. std::unique_ptr<seal::Decryptor> decryptor_;
  31. std::unique_ptr<seal::Evaluator> evaluator_;
  32. std::unique_ptr<seal::KeyGenerator> keygen_;
  33. std::unique_ptr<seal::BatchEncoder> encoder_;
  34. std::shared_ptr<seal::SEALContext> context_;
  35. vector<uint64_t> indices_; // the indices for retrieval.
  36. vector<uint64_t> inverse_scales_;
  37. friend class PIRServer;
  38. };