SSOT.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package subprotocols;
  2. import communication.Communication;
  3. import crypto.Crypto;
  4. import exceptions.NoSuchPartyException;
  5. import oram.Forest;
  6. import oram.Metadata;
  7. import protocols.Protocol;
  8. import struct.Party;
  9. import util.Util;
  10. public class SSOT extends Protocol {
  11. public SSOT(Communication con1, Communication con2) {
  12. super(con1, con2);
  13. }
  14. public byte[] runE(int b1, byte[][] v01) {
  15. int mBytes = v01[0].length;
  16. byte[][] y01 = new byte[2][];
  17. y01[0] = Util.nextBytes(mBytes, Crypto.sr_DE);
  18. y01[1] = Util.nextBytes(mBytes, Crypto.sr_DE);
  19. int e = Crypto.sr_DE.nextInt(2);
  20. byte[] x = con1.read();
  21. /////////////////////////////////////////////
  22. int t = b1 ^ e;
  23. con2.write(t);
  24. int s = con2.readInt();
  25. byte[][] v01_p = new byte[2][];
  26. v01_p[0] = Util.xor(v01[b1], y01[s]);
  27. v01_p[1] = Util.xor(v01[1 - b1], y01[1 - s]);
  28. con2.write(v01_p);
  29. byte[][] u01_p = con2.readDoubleByteArray();
  30. byte[] p1 = Util.xor(u01_p[b1], x);
  31. return p1;
  32. }
  33. public void runD(int mBytes) {
  34. byte[][] x01 = new byte[2][];
  35. x01[0] = Util.nextBytes(mBytes, Crypto.sr_CD);
  36. x01[1] = Util.nextBytes(mBytes, Crypto.sr_CD);
  37. byte[][] y01 = new byte[2][];
  38. y01[0] = Util.nextBytes(mBytes, Crypto.sr_DE);
  39. y01[1] = Util.nextBytes(mBytes, Crypto.sr_DE);
  40. byte[] delta = Util.nextBytes(mBytes, Crypto.sr);
  41. int c = Crypto.sr_CD.nextInt(2);
  42. int e = Crypto.sr_DE.nextInt(2);
  43. byte[] x = Util.xor(x01[e], delta);
  44. byte[] y = Util.xor(y01[c], delta);
  45. con2.write(y);
  46. con1.write(x);
  47. /////////////////////////////////////////////
  48. }
  49. public byte[] runC(int b0, byte[][] u01) {
  50. int mBytes = u01[0].length;
  51. byte[][] x01 = new byte[2][];
  52. x01[0] = Util.nextBytes(mBytes, Crypto.sr_CD);
  53. x01[1] = Util.nextBytes(mBytes, Crypto.sr_CD);
  54. int c = Crypto.sr_CD.nextInt(2);
  55. byte[] y = con2.read();
  56. /////////////////////////////////////////////
  57. int s = b0 ^ c;
  58. con1.write(s);
  59. int t = con1.readInt();
  60. byte[][] u01_p = new byte[2][];
  61. u01_p[0] = Util.xor(u01[b0], x01[t]);
  62. u01_p[1] = Util.xor(u01[1 - b0], x01[1 - t]);
  63. con1.write(u01_p);
  64. byte[][] v01_p = con1.readDoubleByteArray();
  65. byte[] p0 = Util.xor(v01_p[b0], y);
  66. return p0;
  67. }
  68. @Override
  69. public void run(Party party, Metadata md, Forest[] forest) {
  70. for (int j = 0; j < 1000; j++) {
  71. int mBytes = 100;
  72. int b0 = Crypto.sr.nextInt(2);
  73. int b1 = Crypto.sr.nextInt(2);
  74. byte[][] u01 = new byte[2][];
  75. byte[][] v01 = new byte[2][];
  76. u01[0] = Util.nextBytes(mBytes, Crypto.sr);
  77. u01[1] = Util.nextBytes(mBytes, Crypto.sr);
  78. v01[0] = Util.nextBytes(mBytes, Crypto.sr);
  79. v01[1] = Util.nextBytes(mBytes, Crypto.sr);
  80. if (party == Party.Eddie) {
  81. byte[] p1 = this.runE(b1, v01);
  82. b0 = con2.readInt();
  83. u01 = con2.readDoubleByteArray();
  84. byte[] p0 = con2.read();
  85. byte[][] m01 = new byte[2][];
  86. m01[0] = Util.xor(u01[0], v01[0]);
  87. m01[1] = Util.xor(u01[1], v01[1]);
  88. int b = b0 ^ b1;
  89. byte[] p = Util.xor(p0, p1);
  90. if (Util.equal(p, m01[b])) {
  91. System.out.println("j = " + j + ": SSOT Passed");
  92. } else {
  93. System.err.println("j = " + j + ": SSOT Failed");
  94. }
  95. } else if (party == Party.Debbie) {
  96. this.runD(mBytes);
  97. } else if (party == Party.Charlie) {
  98. byte[] p0 = this.runC(b0, u01);
  99. con1.write(b0);
  100. con1.write(u01);
  101. con1.write(p0);
  102. } else {
  103. throw new NoSuchPartyException(party + "");
  104. }
  105. }
  106. }
  107. @Override
  108. public void run(Party party, Metadata md, Forest forest) {
  109. }
  110. }