cell.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 init;
  21. init.key.set(0xffffffffffffffff);
  22. init.pointers.set(0xeeeeeeeeeeeeeeee);
  23. init.value.set(0xdddddddddddddddd);
  24. A.init(init);
  25. Cell c;
  26. c.key.set(0x0102030405060708);
  27. c.pointers.set(0x1112131415161718);
  28. c.value.set(0x2122232425262728);
  29. // Explicit write
  30. A[0] = c;
  31. RegAS idx;
  32. // Explicit read
  33. Cell expl_read_c = A[0];
  34. printf("expl_read_c = ");
  35. expl_read_c.dump();
  36. printf("\n");
  37. // ORAM read
  38. Cell oram_read_c = A[idx];
  39. printf("oram_read_c = ");
  40. oram_read_c.dump();
  41. printf("\n");
  42. RegXS valueupdate;
  43. valueupdate.set(0x4040404040404040 * tio.player());
  44. RegXS pointersset;
  45. pointersset.set(0x123456789abcdef0 * tio.player());
  46. // Explicit update and write of individual fields
  47. A[1].CELL_VALUE += valueupdate;
  48. A[3].CELL_POINTERS = pointersset;
  49. // Explicit read of individual field
  50. RegXS pointval = A[0].CELL_POINTERS;
  51. printf("pointval = ");
  52. pointval.dump();
  53. printf("\n");
  54. idx.set(1 * tio.player());
  55. // ORAM read of individual field
  56. RegXS oram_value_read = A[idx].CELL_VALUE;
  57. printf("oram_value_read = ");
  58. oram_value_read.dump();
  59. printf("\n");
  60. valueupdate.set(0x8080808080808080 * tio.player());
  61. // ORAM update of individual field
  62. A[idx].CELL_VALUE += valueupdate;
  63. idx.set(2 * tio.player());
  64. // ORAM write of individual field
  65. A[idx].CELL_VALUE = valueupdate;
  66. c.key.set(0x0102030405060708 * tio.player());
  67. c.pointers.set(0x1112131415161718 * tio.player());
  68. c.value.set(0x2122232425262728 * tio.player());
  69. // ORAM update of full Cell
  70. A[idx] += c;
  71. idx.set(3 * tio.player());
  72. // ORAM write of full Cell
  73. A[idx] = c;
  74. printf("\n");
  75. if (depth < 10) {
  76. oram.dump();
  77. auto R = A.reconstruct();
  78. if (tio.player() == 0) {
  79. for(size_t i=0;i<R.size();++i) {
  80. printf("\n%04lx ", i);
  81. R[i].dump();
  82. }
  83. printf("\n");
  84. }
  85. }
  86. });
  87. }