SSIOT.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package protocols;
  2. import communication.Communication;
  3. import crypto.Crypto;
  4. import crypto.PRF;
  5. import crypto.PRG;
  6. import exceptions.NoSuchPartyException;
  7. import exceptions.SSIOTException;
  8. import oram.Forest;
  9. import oram.Metadata;
  10. import util.Util;
  11. public class SSIOT extends Protocol {
  12. public SSIOT(Communication con1, Communication con2) {
  13. super(con1, con2);
  14. }
  15. public void runE(PreData predata, byte[][] y, byte[] Nip1_pr) {
  16. // step 1
  17. int n = y.length;
  18. int l = y[0].length * 8;
  19. byte[][] x = new byte[n][];
  20. byte[][] e = new byte[n][];
  21. byte[][] v = new byte[n][];
  22. PRF F_k = new PRF(Crypto.secParam);
  23. F_k.init(predata.ssiot_k);
  24. PRF F_kprime = new PRF(Crypto.secParam);
  25. F_kprime.init(predata.ssiot_kprime);
  26. PRG G = new PRG(l);
  27. for (int i = 0; i < n; i++) {
  28. byte[] i_bytes = Util.intToBytes(i);
  29. x[i] = predata.ssiot_r.clone();
  30. for (int j = 0; j < Nip1_pr.length; j++)
  31. x[i][x[i].length - 1 - j] ^= Nip1_pr[Nip1_pr.length - 1 - j] ^ i_bytes[i_bytes.length - 1 - j];
  32. e[i] = Util.xor(G.compute(F_k.compute(x[i])), y[i]);
  33. v[i] = F_kprime.compute(x[i]);
  34. }
  35. con2.write(e);
  36. con2.write(v);
  37. }
  38. public void runD(PreData predata, byte[] Nip1_pr) {
  39. // step 2
  40. PRF F_k = new PRF(Crypto.secParam);
  41. F_k.init(predata.ssiot_k);
  42. PRF F_kprime = new PRF(Crypto.secParam);
  43. F_kprime.init(predata.ssiot_kprime);
  44. byte[] y = predata.ssiot_r;
  45. for (int i = 0; i < Nip1_pr.length; i++)
  46. y[y.length - 1 - i] ^= Nip1_pr[Nip1_pr.length - 1 - i];
  47. byte[] p = F_k.compute(y);
  48. byte[] w = F_kprime.compute(y);
  49. con2.write(p);
  50. con2.write(w);
  51. }
  52. public OutSSIOT runC() {
  53. // step 1
  54. byte[][] e = con1.readObject();
  55. byte[][] v = con1.readObject();
  56. // step 2
  57. byte[] p = con2.read();
  58. byte[] w = con2.read();
  59. // step 3
  60. int n = e.length;
  61. int l = e[0].length * 8;
  62. PRG G = new PRG(l);
  63. OutSSIOT output = null;
  64. int invariant = 0;
  65. for (int i = 0; i < n; i++) {
  66. if (Util.equal(v[i], w)) {
  67. byte[] y = Util.xor(e[i], G.compute(p));
  68. output = new OutSSIOT(i, y);
  69. invariant++;
  70. }
  71. }
  72. if (invariant != 1)
  73. throw new SSIOTException("Invariant error: " + invariant);
  74. return output;
  75. }
  76. @Override
  77. public void run(Party party, Metadata md, Forest forest) {
  78. for (int j = 0; j < 100; j++) {
  79. int twoTauPow = 64;
  80. int label = 4;
  81. byte[][] y = new byte[twoTauPow][label];
  82. byte[] sE_Nip1_pr = new byte[1];
  83. byte[] sD_Nip1_pr = new byte[1];
  84. for (int i = 0; i < twoTauPow; i++)
  85. Crypto.sr.nextBytes(y[i]);
  86. int index = Crypto.sr.nextInt(twoTauPow);
  87. Crypto.sr.nextBytes(sE_Nip1_pr);
  88. sD_Nip1_pr[0] = (byte) (Util.intToBytes(index)[3] ^ sE_Nip1_pr[0]);
  89. PreData predata = new PreData();
  90. PreSSIOT pressiot = new PreSSIOT(con1, con2);
  91. if (party == Party.Eddie) {
  92. con1.write(sD_Nip1_pr);
  93. con2.write(y);
  94. con2.write(index);
  95. pressiot.runE(predata, twoTauPow);
  96. runE(predata, y, sE_Nip1_pr);
  97. } else if (party == Party.Debbie) {
  98. sD_Nip1_pr = con1.read();
  99. pressiot.runD(predata);
  100. runD(predata, sD_Nip1_pr);
  101. } else if (party == Party.Charlie) {
  102. y = con1.readObject();
  103. index = con1.readObject();
  104. pressiot.runC();
  105. OutSSIOT output = runC();
  106. if (output.t == index && Util.equal(output.m_t, y[index]))
  107. System.out.println("SSIOT test passed");
  108. else
  109. System.err.println("SSIOT test failed");
  110. } else {
  111. throw new NoSuchPartyException(party + "");
  112. }
  113. }
  114. }
  115. }