spir.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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_PIRs(uint32_t num_preproc)
  20. {
  21. VecData msg = spir_client_preproc_PIRs(this->client, num_preproc);
  22. string ret(msg.data, msg.len);
  23. spir_vecdata_free(msg);
  24. return ret;
  25. }
  26. SPIR_Server::SPIR_Server(uint8_t r, const string &pub_params)
  27. {
  28. this->server = spir_server_new(r, pub_params.data(),
  29. pub_params.length());
  30. }
  31. SPIR_Server::~SPIR_Server()
  32. {
  33. spir_server_free(this->server);
  34. }
  35. string SPIR_Server::preproc_PIRs(const string &msg)
  36. {
  37. VecData retmsg = spir_server_preproc_PIRs(this->server, msg.data(),
  38. msg.length());
  39. string ret(retmsg.data, retmsg.len);
  40. spir_vecdata_free(retmsg);
  41. return ret;
  42. }