mpcops.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. When called by another task during preprocessing, set tally
  30. // to false so that the required halftriples aren't accounted for
  31. // separately from the main preprocessing task.
  32. //
  33. // Cost:
  34. // 1 word sent in 1 message
  35. // consumes 1 HalfTriple
  36. void mpc_valuemul(MPCTIO &tio, yield_t &yield,
  37. RegAS &z, value_t x,
  38. nbits_t nbits = VALUE_BITS, bool tally = true);
  39. // P0 and P1 hold bit shares f0 and f1 of the single bit f, and additive
  40. // shares y0 and y1 of the value y; compute additive shares of
  41. // z = f * y = (f0 XOR f1) * (y0 + y1). y and z are each at most nbits
  42. // bits long.
  43. //
  44. // Cost:
  45. // 2 words sent in 1 message
  46. // consumes 1 MultTriple
  47. void mpc_flagmult(MPCTIO &tio, yield_t &yield,
  48. RegAS &z, RegBS f, RegAS y,
  49. nbits_t nbits = VALUE_BITS);
  50. // P0 and P1 hold bit shares f0 and f1 of the single bit f, and additive
  51. // shares of the values x and y; compute additive shares of z, where
  52. // z = x if f=0 and z = y if f=1. x, y, and z are each at most nbits
  53. // bits long.
  54. //
  55. // Cost:
  56. // 2 words sent in 1 message
  57. // consumes 1 MultTriple
  58. void mpc_select(MPCTIO &tio, yield_t &yield,
  59. RegAS &z, RegBS f, RegAS x, RegAS y,
  60. nbits_t nbits = VALUE_BITS);
  61. // P0 and P1 hold bit shares f0 and f1 of the single bit f, and additive
  62. // shares of the values x and y. Obliviously swap x and y; that is,
  63. // replace x and y with new additive sharings of x and y respectively
  64. // (if f=0) or y and x respectively (if f=1). x and y are each at most
  65. // nbits bits long.
  66. //
  67. // Cost:
  68. // 2 words sent in 1 message
  69. // consumes 1 MultTriple
  70. void mpc_oswap(MPCTIO &tio, yield_t &yield,
  71. RegAS &x, RegAS &y, RegBS f,
  72. nbits_t nbits = VALUE_BITS);
  73. // P0 and P1 hold XOR shares of x. Compute additive shares of the same
  74. // x. x is at most nbits bits long. When called by another task during
  75. // preprocessing, set tally to false so that the required halftriples
  76. // aren't accounted for separately from the main preprocessing task.
  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. RegAS &as_x, RegXS xs_x,
  83. nbits_t nbits = VALUE_BITS, bool tally = true);
  84. // P0 and P1 hold bit shares of f, and DPFnode XOR shares x0,y0 and
  85. // x1,y1 of x and y. Set z to x=x0^x1 if f=0 and to y=y0^y1 if f=1.
  86. //
  87. // Cost:
  88. // 6 64-bit words sent in 2 messages
  89. // consumes one AndTriple
  90. void mpc_reconstruct_choice(MPCTIO &tio, yield_t &yield,
  91. DPFnode &z, RegBS f, DPFnode x, DPFnode y);
  92. #endif