spir.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include <stdio.h>
  2. #include "spir.hpp"
  3. #include "spir_ffi.h"
  4. void SPIR::init(uint32_t num_threads)
  5. {
  6. spir_init(num_threads);
  7. }
  8. SPIR_Client::SPIR_Client(uint8_t r, string &pub_params)
  9. {
  10. ClientNewRet ret = spir_client_new(r);
  11. pub_params.assign(ret.pub_params.data, ret.pub_params.len);
  12. spir_vecdata_free(ret.pub_params);
  13. this->client = ret.client;
  14. }
  15. SPIR_Client::~SPIR_Client()
  16. {
  17. spir_client_free(this->client);
  18. }
  19. string SPIR_Client::preproc(uint32_t num_preproc)
  20. {
  21. VecData msg = spir_client_preproc(this->client, num_preproc);
  22. string ret(msg.data, msg.len);
  23. spir_vecdata_free(msg);
  24. return ret;
  25. }
  26. void SPIR_Client::preproc_finish(const string &server_preproc)
  27. {
  28. spir_client_preproc_finish(this->client, server_preproc.data(),
  29. server_preproc.length());
  30. }
  31. string SPIR_Client::query(size_t idx)
  32. {
  33. VecData msg = spir_client_query(this->client, idx);
  34. string ret(msg.data, msg.len);
  35. spir_vecdata_free(msg);
  36. return ret;
  37. }
  38. SPIR::DBEntry SPIR_Client::query_finish(const string &server_resp)
  39. {
  40. return spir_client_query_finish(this->client,
  41. server_resp.data(), server_resp.length());
  42. }
  43. SPIR_Server::SPIR_Server(uint8_t r, const string &pub_params)
  44. {
  45. this->server = spir_server_new(r, pub_params.data(),
  46. pub_params.length());
  47. }
  48. SPIR_Server::~SPIR_Server()
  49. {
  50. spir_server_free(this->server);
  51. }
  52. string SPIR_Server::preproc_process(const string &msg)
  53. {
  54. VecData retmsg = spir_server_preproc_process(this->server, msg.data(),
  55. msg.length());
  56. string ret(retmsg.data, retmsg.len);
  57. spir_vecdata_free(retmsg);
  58. return ret;
  59. }
  60. string SPIR_Server::query_process(const string &client_query,
  61. const SPIR::DBEntry *db, size_t rot, SPIR::DBEntry blind)
  62. {
  63. VecData retmsg = spir_server_query_process(this->server,
  64. client_query.data(), client_query.length(), db, rot, blind);
  65. string ret(retmsg.data, retmsg.len);
  66. spir_vecdata_free(retmsg);
  67. return ret;
  68. }