cell.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include <functional>
  2. #include "types.hpp"
  3. #include "duoram.hpp"
  4. #include "cell.hpp"
  5. // We use the cell in various ways. This function is called by
  6. // online.cpp.
  7. void cell(MPCIO &mpcio,
  8. const PRACOptions &opts, char **args)
  9. {
  10. nbits_t depth=4;
  11. if (*args) {
  12. depth = atoi(*args);
  13. ++args;
  14. }
  15. MPCTIO tio(mpcio, 0, opts.num_threads);
  16. run_coroutines(tio, [&tio, depth] (yield_t &yield) {
  17. size_t size = size_t(1)<<depth;
  18. Duoram<Cell> oram(tio.player(), size);
  19. auto A = oram.flat(tio, yield);
  20. Cell c;
  21. c.key.set(0x0102030405060708);
  22. c.pointers.set(0x1112131415161718);
  23. c.value.set(0x2122232425262728);
  24. // Explicit write
  25. A[0] = c;
  26. RegAS idx;
  27. // Explicit read
  28. Cell expl_read_c = A[0];
  29. printf("expl_read_c = ");
  30. expl_read_c.dump();
  31. printf("\n");
  32. // ORAM read
  33. Cell oram_read_c = A[idx];
  34. printf("oram_read_c = ");
  35. oram_read_c.dump();
  36. printf("\n");
  37. RegXS valueupdate;
  38. valueupdate.set(0x4040404040404040 * tio.player());
  39. RegXS pointersset;
  40. pointersset.set(0x123456789abcdef0 * tio.player());
  41. // Explicit update and write of individual fields
  42. A[1].CELL_VALUE += valueupdate;
  43. A[3].CELL_POINTERS = pointersset;
  44. // Explicit read of individual field
  45. RegXS pointval = A[0].CELL_POINTERS;
  46. printf("pointval = ");
  47. pointval.dump();
  48. printf("\n");
  49. idx.set(1 * tio.player());
  50. // ORAM read of individual field
  51. RegXS oram_value_read = A[idx].CELL_VALUE;
  52. printf("oram_value_read = ");
  53. oram_value_read.dump();
  54. printf("\n");
  55. valueupdate.set(0x8080808080808080 * tio.player());
  56. // ORAM update of individual field
  57. A[idx].CELL_VALUE += valueupdate;
  58. idx.set(2 * tio.player());
  59. // ORAM write of individual field
  60. A[idx].CELL_VALUE = valueupdate;
  61. c.key.set(0x0102030405060708 * tio.player());
  62. c.pointers.set(0x1112131415161718 * tio.player());
  63. c.value.set(0x2122232425262728 * tio.player());
  64. // ORAM update of full Cell
  65. A[idx] += c;
  66. idx.set(3 * tio.player());
  67. // ORAM write of full Cell
  68. A[idx] = c;
  69. printf("\n");
  70. if (depth < 10) {
  71. oram.dump();
  72. auto R = A.reconstruct();
  73. if (tio.player() == 0) {
  74. for(size_t i=0;i<R.size();++i) {
  75. printf("\n%04lx ", i);
  76. R[i].dump();
  77. }
  78. printf("\n");
  79. }
  80. }
  81. });
  82. }