duoram-read.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. auto DuoramRead(bool party, size_t db_nitems, int64_t ri, int64_t where_to_read, tcp::socket&s2, tcp::socket& s2_b, tcp::socket& sb)
  2. {
  3. read_flags(party, db_nitems);
  4. DB_t Gamma;
  5. size_t WritePb_ind_reads, WritePb_ind_reads_recv, rotate;
  6. WritePb_ind_reads = where_to_read - ri;
  7. boost::asio::write(s2, boost::asio::buffer(&WritePb_ind_reads, sizeof(WritePb_ind_reads)));
  8. boost::asio::write(sb, boost::asio::buffer(&WritePb_ind_reads, sizeof(WritePb_ind_reads)));
  9. boost::asio::read(sb, boost::asio::buffer(&WritePb_ind_reads_recv, sizeof(WritePb_ind_reads_recv)));
  10. rotate = WritePb_ind_reads + WritePb_ind_reads_recv;
  11. std::cout << "[dependent reads] " << " rotate = " << rotate << std::endl;
  12. read(s2_b, boost::asio::buffer(&Gamma, sizeof(Gamma)));
  13. DB_t output = 0;
  14. for(size_t j = 0; j < db_nitems; ++j) reading_temp[j] = DB[j] + updated_blinded_DB_recv[j];
  15. if(!party) output = dot_product_with_bool(reading_temp, reading_b, db_nitems, rotate ) +
  16. dot_product_with_bool(updated_blinds, reading_b, db_nitems, rotate) -
  17. dot_product_with_bool(updated_blinds, reading_c, db_nitems, rotate) + Gamma;
  18. if(party) output = dot_product_with_bool(reading_temp, reading_c, db_nitems, rotate) +
  19. dot_product_with_bool(updated_blinds, reading_c, db_nitems, rotate) -
  20. dot_product_with_bool(updated_blinds, reading_d, db_nitems, rotate) + Gamma;
  21. return output;
  22. }
  23. auto DuoramIndependentRead(bool party, size_t db_nitems, int64_t ri, DB_t * Gamma_reads, size_t * rotate, size_t r)
  24. {
  25. read_flags(party, db_nitems);
  26. DB_t output = 0;
  27. for(size_t j = 0; j < db_nitems; ++j) reading_temp[j] = DB[j] + updated_blinded_DB_recv[j];
  28. if(!party) output = dot_product_with_bool(reading_temp, reading_b, db_nitems, rotate[r]) +
  29. dot_product_with_bool(updated_blinds, reading_b, db_nitems, rotate[r]) -
  30. dot_product_with_bool(updated_blinds, reading_c, db_nitems, rotate[r]) + Gamma_reads[r];
  31. if(party) output = dot_product_with_bool(reading_temp, reading_c, db_nitems, rotate[r]) +
  32. dot_product_with_bool(updated_blinds, reading_c, db_nitems, rotate[r]) -
  33. dot_product_with_bool(updated_blinds, reading_d, db_nitems, rotate[r]) + Gamma_reads[r];
  34. return output;
  35. }