types.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #ifndef __OBLIVDS_TYPES_HPP__
  2. #define __OBLIVDS_TYPES_HPP__
  3. #include <tuple>
  4. #include <cstdint>
  5. // The number of bits in an MPC secret-shared memory word
  6. #ifndef VALUE_BITS
  7. #define VALUE_BITS 64
  8. #endif
  9. // Values in MPC secret-shared memory are of this type
  10. #if VALUE_BITS == 64
  11. typedef uint64_t value_t;
  12. #elif VALUE_BITS == 32
  13. typedef uint32_t value_t;
  14. #else
  15. #error "Unsupported value of VALUE_BITS"
  16. #endif
  17. // The _maximum_ number of bits in an MPC address; the actual size of
  18. // the memory will typically be set at runtime, but it cannot exceed
  19. // this value. It is more efficient (in terms of communication) in some
  20. // places for this value to be at most 32.
  21. #ifndef ADDRESS_MAX_BITS
  22. #define ADDRESS_MAX_BITS 32
  23. #endif
  24. // Addresses of MPC secret-shared memory are of this type
  25. #if ADDRESS_MAX_BITS <= 32
  26. typedef uint32_t address_t;
  27. #elif ADDRESS_MAX_BITS <= 64
  28. typedef uint64_t address_t;
  29. #else
  30. #error "Unsupported value of ADDRESS_MAX_BITS"
  31. #endif
  32. #if ADDRESS_MAX_BITS > VALUE_BITS
  33. #error "VALUE_BITS must be at least as large as ADDRESS_MAX_BITS"
  34. #endif
  35. // Secret-shared bits are of this type. Note that it is standards
  36. // compliant to treat a bool as an unsigned integer type with values 0
  37. // and 1.
  38. typedef bool bit_t;
  39. // Counts of the number of bits in a value are of this type, which must
  40. // be large enough to store the _value_ VALUE_BITS
  41. typedef uint8_t nbits_t;
  42. // Convert a number of bits to the number of bytes required to store (or
  43. // more to the point, send) them.
  44. #define BITBYTES(nbits) (((nbits)+7)>>3)
  45. // A mask of this many bits; the test is to prevent 1<<nbits from
  46. // overflowing if nbits == VALUE_BITS
  47. #define MASKBITS(nbits) (((nbits) < VALUE_BITS) ? (value_t(1)<<(nbits))-1 : ~0)
  48. // A multiplication triple is a triple (X0,Y0,Z0) held by P0 (and
  49. // correspondingly (X1,Y1,Z1) held by P1), with all values random,
  50. // but subject to the relation that X0*Y1 + Y0*X1 = Z0+Z1
  51. typedef std::tuple<value_t, value_t, value_t> MultTriple;
  52. // A half-triple is (X0,Z0) held by P0 (and correspondingly (Y1,Z1) held
  53. // by P1), with all values random, but subject to the relation that
  54. // X0*Y1 = Z0+Z1
  55. typedef std::tuple<value_t, value_t> HalfTriple;
  56. #endif