PrePermuteTarget.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package protocols.precomputation;
  2. import java.math.BigInteger;
  3. import com.oblivm.backend.gc.GCSignal;
  4. import communication.Communication;
  5. import crypto.Crypto;
  6. import gc.GCUtil;
  7. import oram.Forest;
  8. import oram.Metadata;
  9. import protocols.Protocol;
  10. import protocols.struct.Party;
  11. import protocols.struct.PreData;
  12. import util.M;
  13. import util.P;
  14. import util.Timer;
  15. import util.Util;
  16. public class PrePermuteTarget extends Protocol {
  17. private int pid = P.PT;
  18. public PrePermuteTarget(Communication con1, Communication con2) {
  19. super(con1, con2);
  20. }
  21. public void runE(PreData predata, int d, Timer timer) {
  22. timer.start(pid, M.offline_comp);
  23. // PermuteTargetI
  24. int logD = (int) Math.ceil(Math.log(d) / Math.log(2));
  25. predata.pt_keyT = new byte[d][d][];
  26. predata.pt_targetT = new byte[d][d][];
  27. predata.pt_maskT = new byte[d][d][];
  28. for (int i = 0; i < d; i++) {
  29. for (int j = 0; j < d; j++) {
  30. GCSignal[] keys = GCUtil.revSelectKeys(predata.evict_targetOutKeyPairs[i],
  31. BigInteger.valueOf(j).toByteArray());
  32. predata.pt_keyT[i][j] = GCUtil.hashAll(keys);
  33. predata.pt_maskT[i][j] = Util.nextBytes((logD + 7) / 8, Crypto.sr);
  34. predata.pt_targetT[i][j] = Util.xor(
  35. Util.padArray(BigInteger.valueOf(predata.evict_pi[j]).toByteArray(), (logD + 7) / 8),
  36. predata.pt_maskT[i][j]);
  37. }
  38. int[] randPerm = Util.randomPermutation(d, Crypto.sr);
  39. predata.pt_keyT[i] = Util.permute(predata.pt_keyT[i], randPerm);
  40. predata.pt_maskT[i] = Util.permute(predata.pt_maskT[i], randPerm);
  41. predata.pt_targetT[i] = Util.permute(predata.pt_targetT[i], randPerm);
  42. }
  43. timer.start(pid, M.offline_write);
  44. con1.write(predata.pt_keyT);
  45. con1.write(predata.pt_targetT);
  46. con2.write(predata.pt_maskT);
  47. timer.stop(pid, M.offline_write);
  48. // PermuteTargetII
  49. predata.pt_p = new byte[d][];
  50. predata.pt_r = new byte[d][];
  51. predata.pt_a = new byte[d][];
  52. for (int i = 0; i < d; i++) {
  53. predata.pt_p[i] = Util.nextBytes((logD + 7) / 8, Crypto.sr);
  54. predata.pt_r[i] = Util.nextBytes((logD + 7) / 8, Crypto.sr);
  55. predata.pt_a[i] = Util.xor(predata.pt_p[i], predata.pt_r[i]);
  56. }
  57. predata.pt_a = Util.permute(predata.pt_a, predata.evict_pi);
  58. timer.start(pid, M.offline_write);
  59. con1.write(predata.pt_p);
  60. con1.write(predata.pt_a);
  61. con2.write(predata.pt_r);
  62. timer.stop(pid, M.offline_write);
  63. timer.stop(pid, M.offline_comp);
  64. }
  65. public void runD(PreData predata, int d, Timer timer) {
  66. timer.start(pid, M.offline_read);
  67. // PermuteTargetI
  68. predata.pt_keyT = con1.readTripleByteArray();
  69. predata.pt_targetT = con1.readTripleByteArray();
  70. // PermuteTargetII
  71. predata.pt_p = con1.readDoubleByteArray();
  72. predata.pt_a = con1.readDoubleByteArray();
  73. timer.stop(pid, M.offline_read);
  74. }
  75. public void runC(PreData predata, Timer timer) {
  76. timer.start(pid, M.offline_read);
  77. // PermuteTargetI
  78. predata.pt_maskT = con1.readTripleByteArray();
  79. // PermuteTargetII
  80. predata.pt_r = con1.readDoubleByteArray();
  81. timer.stop(pid, M.offline_read);
  82. }
  83. @Override
  84. public void run(Party party, Metadata md, Forest forest) {
  85. }
  86. }