SSCOT.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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.SSCOTException;
  8. import oram.Forest;
  9. import oram.Metadata;
  10. import util.Util;
  11. public class SSCOT extends Protocol {
  12. public SSCOT(Communication con1, Communication con2) {
  13. super(con1, con2);
  14. }
  15. public void runE(PreData predata, byte[][] m, byte[][] a) {
  16. // step 1
  17. int n = m.length;
  18. int l = m[0].length * 8;
  19. byte[][] x = predata.sscot_r;
  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.sscot_k);
  24. PRF F_kprime = new PRF(Crypto.secParam);
  25. F_kprime.init(predata.sscot_kprime);
  26. PRG G = new PRG(l);
  27. for (int i = 0; i < n; i++) {
  28. for (int j = 0; j < a[i].length; j++)
  29. x[i][j] = (byte) (predata.sscot_r[i][j] ^ a[i][j]);
  30. e[i] = Util.xor(G.compute(F_k.compute(x[i])), m[i]);
  31. v[i] = F_kprime.compute(x[i]);
  32. }
  33. con2.write(e);
  34. con2.write(v);
  35. }
  36. public void runD(PreData predata, byte[][] b) {
  37. // step 2
  38. int n = b.length;
  39. byte[][] y = predata.sscot_r;
  40. byte[][] p = new byte[n][];
  41. byte[][] w = new byte[n][];
  42. PRF F_k = new PRF(Crypto.secParam);
  43. F_k.init(predata.sscot_k);
  44. PRF F_kprime = new PRF(Crypto.secParam);
  45. F_kprime.init(predata.sscot_kprime);
  46. for (int i = 0; i < n; i++) {
  47. for (int j = 0; j < b[i].length; j++)
  48. y[i][j] = (byte) (predata.sscot_r[i][j] ^ b[i][j]);
  49. p[i] = F_k.compute(y[i]);
  50. w[i] = F_kprime.compute(y[i]);
  51. }
  52. con2.write(p);
  53. con2.write(w);
  54. }
  55. public OutSSCOT runC() {
  56. // step 1
  57. byte[][] e = con1.readObject();
  58. byte[][] v = con1.readObject();
  59. // step 2
  60. byte[][] p = con2.readObject();
  61. byte[][] w = con2.readObject();
  62. // step 3
  63. int n = e.length;
  64. int l = e[0].length * 8;
  65. PRG G = new PRG(l);
  66. OutSSCOT output = null;
  67. int invariant = 0;
  68. for (int i = 0; i < n; i++) {
  69. if (Util.equal(v[i], w[i])) {
  70. byte[] m = Util.xor(e[i], G.compute(p[i]));
  71. output = new OutSSCOT(i, m);
  72. invariant++;
  73. }
  74. }
  75. if (invariant != 1)
  76. throw new SSCOTException("Invariant error: " + invariant);
  77. return output;
  78. }
  79. @Override
  80. public void run(Party party, Metadata md, Forest forest) {
  81. for (int j = 0; j < 100; j++) {
  82. int n = 100;
  83. int A = 32;
  84. int FN = 5;
  85. byte[][] m = new byte[n][A];
  86. byte[][] a = new byte[n][FN];
  87. byte[][] b = new byte[n][FN];
  88. for (int i = 0; i < n; i++) {
  89. Crypto.sr.nextBytes(m[i]);
  90. Crypto.sr.nextBytes(a[i]);
  91. Crypto.sr.nextBytes(b[i]);
  92. while (Util.equal(a[i], b[i]))
  93. Crypto.sr.nextBytes(b[i]);
  94. }
  95. int index = Crypto.sr.nextInt(n);
  96. b[index] = a[index].clone();
  97. PreData predata = new PreData();
  98. PreSSCOT presscot = new PreSSCOT(con1, con2);
  99. if (party == Party.Eddie) {
  100. con1.write(b);
  101. con2.write(m);
  102. con2.write(index);
  103. presscot.runE(predata, n);
  104. runE(predata, m, a);
  105. } else if (party == Party.Debbie) {
  106. b = con1.readObject();
  107. presscot.runD(predata);
  108. runD(predata, b);
  109. } else if (party == Party.Charlie) {
  110. m = con1.readObject();
  111. index = con1.readObject();
  112. presscot.runC();
  113. OutSSCOT output = runC();
  114. if (output.t == index && Util.equal(output.m_t, m[index]))
  115. System.out.println("SSCOT test passed");
  116. else
  117. System.err.println("SSCOT test failed");
  118. } else {
  119. throw new NoSuchPartyException(party + "");
  120. }
  121. }
  122. }
  123. }