mpc.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. void du_attalah_P2(std::vector<socket_t>& sockets0, std::vector<socket_t>& sockets1, int socket_no = 0)
  2. {
  3. int64_t X0, X1, Y0, Y1, gamma0, gamma1;
  4. arc4random_buf(&X0, sizeof(int64_t));
  5. arc4random_buf(&Y0, sizeof(int64_t));
  6. arc4random_buf(&X1, sizeof(int64_t));
  7. arc4random_buf(&Y1, sizeof(int64_t));
  8. gamma0 = X0 * Y1;
  9. gamma1 = X1 * Y0;
  10. boost::asio::write(sockets0[socket_no], boost::asio::buffer(&X0, sizeof(X0)));
  11. boost::asio::write(sockets1[socket_no], boost::asio::buffer(&X1, sizeof(X1)));
  12. boost::asio::write(sockets0[socket_no], boost::asio::buffer(&Y0, sizeof(Y0)));
  13. boost::asio::write(sockets1[socket_no], boost::asio::buffer(&Y1, sizeof(Y1)));
  14. boost::asio::write(sockets0[socket_no], boost::asio::buffer(&gamma0, sizeof(gamma0)));
  15. boost::asio::write(sockets1[socket_no], boost::asio::buffer(&gamma1, sizeof(gamma1)));
  16. }
  17. int64_t du_attalah_Pb(int64_t rb, int64_t pm, tcp::socket& s2, tcp::socket& sb)
  18. {
  19. int64_t gamma;
  20. int64_t X, Y;
  21. int64_t rb_blinded, pm_blinded, pm_blinded_recv, rb_blinded_recv;
  22. boost::asio::read(s2, boost::asio::buffer(&X, sizeof(X)));
  23. boost::asio::read(s2, boost::asio::buffer(&Y, sizeof(Y)));
  24. boost::asio::read(s2, boost::asio::buffer(&gamma, sizeof(gamma)));
  25. rb_blinded = rb + X;
  26. pm_blinded = pm + Y;
  27. boost::asio::write(sb, boost::asio::buffer(&rb_blinded, sizeof(rb_blinded)));
  28. boost::asio::read(sb, boost::asio::buffer(&rb_blinded_recv, sizeof(rb_blinded_recv)));
  29. boost::asio::write(sb, boost::asio::buffer(&pm_blinded, sizeof(pm_blinded)));
  30. boost::asio::read(sb, boost::asio::buffer(&pm_blinded_recv, sizeof(pm_blinded_recv)));
  31. int64_t rb_prime = rb * (pm + (pm_blinded_recv)) - (Y * rb_blinded_recv) + gamma;
  32. return rb_prime;
  33. }