pir_client.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. seal::Ciphertext compose_to_ciphertext(std::vector<seal::Plaintext> plains);
  38. friend class PIRServer;
  39. };