duoram-read.h 2.4 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_for_reading(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. #ifdef VERBOSE
  12. std::cout << "[dependent reads] " << " rotate = " << rotate << std::endl;
  13. #endif
  14. read(s2_b, boost::asio::buffer(&Gamma, sizeof(Gamma)));
  15. DB_t output = 0;
  16. for(size_t j = 0; j < db_nitems; ++j) reading_temp[j] = DB[j] + updated_blinded_DB_recv[j];
  17. if(!party) output = dot_product_with_bool(reading_temp, reading_b, db_nitems, rotate ) +
  18. dot_product_with_bool(updated_blinds, reading_b, db_nitems, rotate) -
  19. dot_product_with_bool(updated_blinds, reading_c, db_nitems, rotate) + Gamma;
  20. if(party) output = dot_product_with_bool(reading_temp, reading_c, db_nitems, rotate) +
  21. dot_product_with_bool(updated_blinds, reading_c, db_nitems, rotate) -
  22. dot_product_with_bool(updated_blinds, reading_d, db_nitems, rotate) + Gamma;
  23. return output;
  24. }
  25. auto DuoramIndependentRead(bool party, size_t db_nitems, int64_t ri, DB_t * Gamma_reads, size_t * rotate, size_t r)
  26. {
  27. read_flags_for_reading(party, db_nitems);
  28. DB_t output = 0;
  29. for(size_t j = 0; j < db_nitems; ++j) reading_temp[j] = DB[j] + updated_blinded_DB_recv[j];
  30. if(!party) output = dot_product_with_bool(reading_temp, reading_b, db_nitems, rotate[r]) +
  31. dot_product_with_bool(updated_blinds, reading_b, db_nitems, rotate[r]) -
  32. dot_product_with_bool(updated_blinds, reading_c, db_nitems, rotate[r]) + Gamma_reads[r];
  33. if(party) output = dot_product_with_bool(reading_temp, reading_c, db_nitems, rotate[r]) +
  34. dot_product_with_bool(updated_blinds, reading_c, db_nitems, rotate[r]) -
  35. dot_product_with_bool(updated_blinds, reading_d, db_nitems, rotate[r]) + Gamma_reads[r];
  36. return output;
  37. }