mpcops.hpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef __MPCOPS_HPP__
  2. #define __MPCOPS_HPP__
  3. #include "types.hpp"
  4. #include "mpcio.hpp"
  5. #include "coroutine.hpp"
  6. // as_ denotes additive shares
  7. // xs_ denotes xor shares
  8. // bs_ denotes a share of a single bit (which is effectively both an xor
  9. // share and an additive share mod 2)
  10. // P0 and P1 both hold additive shares of x (shares are x0 and x1) and y
  11. // (shares are y0 and y1); compute additive shares of z = x*y =
  12. // (x0+x1)*(y0+y1). x, y, and z are each at most nbits bits long.
  13. //
  14. // Cost:
  15. // 2 words sent in 1 message
  16. // consumes 1 MultTriple
  17. void mpc_mul(MPCTIO &tio, yield_t &yield,
  18. value_t &as_z, value_t as_x, value_t as_y,
  19. nbits_t nbits = VALUE_BITS);
  20. // P0 and P1 both hold additive shares of x (shares are x0 and x1) and y
  21. // (shares are y0 and y1); compute additive shares of z = x0*y1 + y0*x1.
  22. // x, y, and z are each at most nbits bits long.
  23. //
  24. // Cost:
  25. // 2 words sent in 1 message
  26. // consumes 1 MultTriple
  27. void mpc_cross(MPCTIO &tio, yield_t &yield,
  28. value_t &as_z, value_t as_x, value_t as_y,
  29. nbits_t nbits = VALUE_BITS);
  30. // P0 holds the (complete) value x, P1 holds the (complete) value y;
  31. // compute additive shares of z = x*y. x, y, and z are each at most
  32. // nbits bits long. The parameter is called x, but P1 will pass y
  33. // there.
  34. //
  35. // Cost:
  36. // 1 word sent in 1 message
  37. // consumes 1 HalfTriple
  38. void mpc_valuemul(MPCTIO &tio, yield_t &yield,
  39. value_t &as_z, value_t x,
  40. nbits_t nbits = VALUE_BITS);
  41. // P0 and P1 hold bit shares f0 and f1 of the single bit f, and additive
  42. // shares y0 and y1 of the value y; compute additive shares of
  43. // z = f * y = (f0 XOR f1) * (y0 + y1). y and z are each at most nbits
  44. // bits long.
  45. //
  46. // Cost:
  47. // 2 words sent in 1 message
  48. // consumes 1 MultTriple
  49. void mpc_flagmult(MPCTIO &tio, yield_t &yield,
  50. value_t &as_z, bit_t bs_f, value_t as_y,
  51. nbits_t nbits = VALUE_BITS);
  52. // P0 and P1 hold bit shares f0 and f1 of the single bit f, and additive
  53. // shares of the values x and y; compute additive shares of z, where
  54. // z = x if f=0 and z = y if f=1. x, y, and z are each at most nbits
  55. // bits long.
  56. //
  57. // Cost:
  58. // 2 words sent in 1 message
  59. // consumes 1 MultTriple
  60. void mpc_select(MPCTIO &tio, yield_t &yield,
  61. value_t &as_z, bit_t bs_f, value_t as_x, value_t as_y,
  62. nbits_t nbits = VALUE_BITS);
  63. // P0 and P1 hold bit shares f0 and f1 of the single bit f, and additive
  64. // shares of the values x and y. Obliviously swap x and y; that is,
  65. // replace x and y with new additive sharings of x and y respectively
  66. // (if f=0) or y and x respectively (if f=1). x and y are each at most
  67. // nbits bits long.
  68. //
  69. // Cost:
  70. // 2 words sent in 1 message
  71. // consumes 1 MultTriple
  72. void mpc_oswap(MPCTIO &tio, yield_t &yield,
  73. value_t &as_x, value_t &as_y, bit_t bs_f,
  74. nbits_t nbits = VALUE_BITS);
  75. // P0 and P1 hold XOR shares of x. Compute additive shares of the same
  76. // x. x is at most nbits bits long.
  77. //
  78. // Cost:
  79. // nbits-1 words sent in 1 message
  80. // consumes nbits-1 HalfTriples
  81. void mpc_xs_to_as(MPCTIO &tio, yield_t &yield,
  82. value_t &as_x, value_t xs_x,
  83. nbits_t nbits = VALUE_BITS);
  84. #endif