mpcops.hpp 3.1 KB

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