spir.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef __SPIR_HPP__
  2. #define __SPIR_HPP__
  3. #include <string>
  4. #include <stdint.h>
  5. using std::string;
  6. class SPIR {
  7. public:
  8. typedef uint64_t DBEntry; // The type of each DB entry (64 bits)
  9. static void init(uint32_t nthreads); // Call this once at startup
  10. };
  11. class SPIR_Client {
  12. public:
  13. // constructor and destructor
  14. SPIR_Client(uint8_t r, string &pub_params); // 2^r records in the database; pub_params will be _filled in_
  15. ~SPIR_Client();
  16. // preprocessing
  17. string preproc(uint32_t num_pirs); // returns the string to send to the server
  18. void preproc_finish(const string &server_preproc);
  19. // SPIR query for index idx
  20. string query(size_t idx); // returns the string to send to the server
  21. // process the server's response to yield the server's db[(idx + rot)%N] + blind
  22. // where N=2^r, idx is provided by the client above, and
  23. // db, rot, and blind are provided by the server below
  24. SPIR::DBEntry query_finish(const string &server_reply);
  25. private:
  26. void *client;
  27. SPIR_Client() = default;
  28. SPIR_Client(const SPIR_Client&) = delete;
  29. SPIR_Client& operator=(const SPIR_Client&) = delete;
  30. };
  31. class SPIR_Server {
  32. public:
  33. // constructor and destructor
  34. SPIR_Server(uint8_t r, const string &client_pub_params);
  35. ~SPIR_Server();
  36. // preprocessing
  37. string preproc_process(const string &client_preproc); // returns the string to reply to the client
  38. // SPIR query on the given database of N=2^r records, each of type DBEntry
  39. // rotate the database by rot, and blind each entry in the database additively with blind
  40. // returns the string to reply to the client
  41. string query_process(const string &client_query, const SPIR::DBEntry *db,
  42. size_t rot, SPIR::DBEntry blind);
  43. private:
  44. void *server;
  45. SPIR_Server() = default;
  46. SPIR_Server(const SPIR_Server&) = delete;
  47. SPIR_Server& operator=(const SPIR_Server&) = delete;
  48. };
  49. #endif