PrePIRRetrieve.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package pir.precomputation;
  2. import communication.Communication;
  3. import oram.Forest;
  4. import oram.Metadata;
  5. import protocols.Protocol;
  6. import protocols.precomputation.PreEviction;
  7. import protocols.precomputation.PrePostProcessT;
  8. import protocols.precomputation.PreUpdateRoot;
  9. import protocols.struct.Party;
  10. import protocols.struct.PreData;
  11. import util.Timer;
  12. public class PrePIRRetrieve extends Protocol {
  13. public PrePIRRetrieve(Communication con1, Communication con2) {
  14. super(con1, con2);
  15. }
  16. // TODO: not all protocols run on all trees (remove unnecessary precomp)
  17. public void runE(PreData[] predata, Metadata md, int ti, Timer timer) {
  18. // 1st eviction
  19. PrePIRAccess preaccess = new PrePIRAccess(con1, con2);
  20. PrePIRReshuffle prereshuffle = new PrePIRReshuffle(con1, con2);
  21. PrePostProcessT prepostprocesst = new PrePostProcessT(con1, con2);
  22. PreUpdateRoot preupdateroot = new PreUpdateRoot(con1, con2);
  23. PreEviction preeviction = new PreEviction(con1, con2);
  24. int numTuples = md.getStashSizeOfTree(ti) + md.getLBitsOfTree(ti) * md.getW();
  25. int[] tupleParam = new int[] { ti == 0 ? 0 : 1, md.getNBytesOfTree(ti), md.getLBytesOfTree(ti),
  26. md.getABytesOfTree(ti) };
  27. preaccess.runE(predata[0], md.getTwoTauPow(), numTuples, tupleParam, timer);
  28. prereshuffle.runE(predata[0], timer);
  29. prepostprocesst.runE(predata[0], timer);
  30. preupdateroot.runE(predata[0], ti == 0, md.getStashSizeOfTree(ti), md.getLBitsOfTree(ti), timer);
  31. preeviction.runE(predata[0], ti == 0, md.getLBitsOfTree(ti) + 1, md.getW(), timer);
  32. // 2nd eviction
  33. preupdateroot.runE(predata[1], ti == 0, md.getStashSizeOfTree(ti), md.getLBitsOfTree(ti), timer);
  34. preeviction.runE(predata[1], ti == 0, md.getLBitsOfTree(ti) + 1, md.getW(), timer);
  35. }
  36. public long[] runD(PreData[] predata, Metadata md, int ti, PreData prev, Timer timer) {
  37. // 1st eviction
  38. PrePIRAccess preaccess = new PrePIRAccess(con1, con2);
  39. PrePIRReshuffle prereshuffle = new PrePIRReshuffle(con1, con2);
  40. PrePostProcessT prepostprocesst = new PrePostProcessT(con1, con2);
  41. PreUpdateRoot preupdateroot = new PreUpdateRoot(con1, con2);
  42. PreEviction preeviction = new PreEviction(con1, con2);
  43. int[] tupleParam = new int[] { ti == 0 ? 0 : 1, md.getNBytesOfTree(ti), md.getLBytesOfTree(ti),
  44. md.getABytesOfTree(ti) };
  45. long[] cnt = new long[2];
  46. preaccess.runD(predata[0], timer);
  47. prereshuffle.runD(predata[0], tupleParam, timer);
  48. prepostprocesst.runD(predata[0], prev, md.getLBytesOfTree(ti), md.getAlBytesOfTree(ti), md.getTau(), timer);
  49. cnt[0] += preupdateroot.runD(predata[0], ti == 0, md.getStashSizeOfTree(ti), md.getLBitsOfTree(ti), tupleParam,
  50. timer);
  51. cnt[1] += preeviction.runD(predata[0], ti == 0, md.getLBitsOfTree(ti) + 1, md.getW(), tupleParam, timer);
  52. // 2nd eviction
  53. cnt[0] += preupdateroot.runD(predata[1], ti == 0, md.getStashSizeOfTree(ti), md.getLBitsOfTree(ti), tupleParam,
  54. timer);
  55. cnt[1] += preeviction.runD(predata[1], ti == 0, md.getLBitsOfTree(ti) + 1, md.getW(), tupleParam, timer);
  56. return cnt;
  57. }
  58. public void runC(PreData[] predata, Metadata md, int ti, PreData prev, Timer timer) {
  59. // 1st eviction
  60. PrePIRAccess preaccess = new PrePIRAccess(con1, con2);
  61. PrePIRReshuffle prereshuffle = new PrePIRReshuffle(con1, con2);
  62. PrePostProcessT prepostprocesst = new PrePostProcessT(con1, con2);
  63. PreUpdateRoot preupdateroot = new PreUpdateRoot(con1, con2);
  64. PreEviction preeviction = new PreEviction(con1, con2);
  65. preaccess.runC(timer);
  66. prereshuffle.runC(predata[0], timer);
  67. prepostprocesst.runC(predata[0], prev, md.getLBytesOfTree(ti), md.getAlBytesOfTree(ti), timer);
  68. preupdateroot.runC(predata[0], ti == 0, timer);
  69. preeviction.runC(predata[0], ti == 0, timer);
  70. // 2nd eviction
  71. preupdateroot.runC(predata[1], ti == 0, timer);
  72. preeviction.runC(predata[1], ti == 0, timer);
  73. }
  74. @Override
  75. public void run(Party party, Metadata md, Forest forest) {
  76. }
  77. @Override
  78. public void run(Party party, Metadata md, Forest[] forest) {
  79. // TODO Auto-generated method stub
  80. }
  81. }