|
@@ -8,6 +8,7 @@ import oram.Forest;
|
|
|
import oram.Metadata;
|
|
|
import pir.precomputation.PrePIRCOT;
|
|
|
import protocols.Protocol;
|
|
|
+import protocols.struct.OutPIRCOT;
|
|
|
import protocols.struct.OutSSCOT;
|
|
|
import protocols.struct.Party;
|
|
|
import protocols.struct.PreData;
|
|
@@ -24,6 +25,152 @@ public class PIRCOT extends Protocol {
|
|
|
super(con1, con2);
|
|
|
}
|
|
|
|
|
|
+ public OutPIRCOT runE(PreData predata, byte[][] u, byte[] v, Timer timer) {
|
|
|
+ int l = u.length;
|
|
|
+ byte[][] a = new byte[l][];
|
|
|
+ for (int j = 0; j < l; j++) {
|
|
|
+ a[j] = Util.xor(u[(j + predata.sscot_s_DE) % l], v);
|
|
|
+ a[j] = Util.padArray(a[j], predata.sscot_r[j].length);
|
|
|
+ Util.setXor(a[j], predata.sscot_r[j]);
|
|
|
+ a[j] = predata.sscot_F_k.compute(a[j]);
|
|
|
+ }
|
|
|
+
|
|
|
+ con2.write(pid, a);
|
|
|
+
|
|
|
+ int delta = con2.readInt(pid);
|
|
|
+ int t_E = (predata.sscot_s_DE + delta) % l;
|
|
|
+
|
|
|
+ OutPIRCOT out = new OutPIRCOT();
|
|
|
+ out.t_E = t_E;
|
|
|
+ out.s_DE = predata.sscot_s_DE;
|
|
|
+ out.s_CE = predata.sscot_s_CE;
|
|
|
+ return out;
|
|
|
+ }
|
|
|
+
|
|
|
+ public OutPIRCOT runD(PreData predata, byte[][] u, byte[] v, Timer timer) {
|
|
|
+ int l = u.length;
|
|
|
+ byte[][] a = new byte[l][];
|
|
|
+ for (int j = 0; j < l; j++) {
|
|
|
+ a[j] = Util.xor(u[(j + l - predata.sscot_s_DE) % l], v);
|
|
|
+ a[j] = Util.padArray(a[j], predata.sscot_r[j].length);
|
|
|
+ Util.setXor(a[j], predata.sscot_r[j]);
|
|
|
+ a[j] = predata.sscot_F_k.compute(a[j]);
|
|
|
+ }
|
|
|
+
|
|
|
+ con2.write(pid, a);
|
|
|
+
|
|
|
+ int delta = con2.readInt(pid);
|
|
|
+ int t_D = (predata.sscot_s_DE + delta) % l;
|
|
|
+
|
|
|
+ OutPIRCOT out = new OutPIRCOT();
|
|
|
+ out.t_D = t_D;
|
|
|
+ out.s_DE = predata.sscot_s_DE;
|
|
|
+ out.s_CD = predata.sscot_s_CD;
|
|
|
+ return out;
|
|
|
+ }
|
|
|
+
|
|
|
+ public OutPIRCOT runC(PreData predata, Timer timer) {
|
|
|
+ byte[][] x = con1.readDoubleByteArray(pid);
|
|
|
+ byte[][] y = con2.readDoubleByteArray(pid);
|
|
|
+ int l = x.length;
|
|
|
+
|
|
|
+ int count = 0;
|
|
|
+ int t_C = 0;
|
|
|
+ for (int i = 0; i < l; i++) {
|
|
|
+ if (Util.equal(x[i], y[i])) {
|
|
|
+ t_C = i;
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (count != 1) {
|
|
|
+ throw new SSCOTException("Invariant error: " + count);
|
|
|
+ }
|
|
|
+
|
|
|
+ int delta_D = (t_C - predata.sscot_s_CE + l) % l;
|
|
|
+ con2.write(pid, delta_D);
|
|
|
+ int delta_E = (t_C - predata.sscot_s_CD + l) % l;
|
|
|
+ con1.write(pid, delta_E);
|
|
|
+
|
|
|
+ OutPIRCOT out = new OutPIRCOT();
|
|
|
+ out.t_C = t_C;
|
|
|
+ out.s_CE = predata.sscot_s_CE;
|
|
|
+ out.s_CD = predata.sscot_s_CD;
|
|
|
+ return out;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run(Party party, Metadata md, Forest[] forest) {
|
|
|
+
|
|
|
+ Timer timer = new Timer();
|
|
|
+
|
|
|
+ for (int j = 0; j < 100; j++) {
|
|
|
+ int n = 100;
|
|
|
+ int FN = 5;
|
|
|
+ byte[][] a = new byte[n][FN];
|
|
|
+ byte[][] b = new byte[n][FN];
|
|
|
+ for (int i = 0; i < n; i++) {
|
|
|
+ Crypto.sr.nextBytes(a[i]);
|
|
|
+ }
|
|
|
+ int index = Crypto.sr.nextInt(n);
|
|
|
+ byte[] v = a[index].clone();
|
|
|
+
|
|
|
+ PreData predata = new PreData();
|
|
|
+ PrePIRCOT presscot = new PrePIRCOT(con1, con2);
|
|
|
+ OutPIRCOT output;
|
|
|
+
|
|
|
+ if (party == Party.Eddie) {
|
|
|
+ con2.write(index);
|
|
|
+ presscot.runE(predata, n, timer);
|
|
|
+ output = runE(predata, a, v, timer);
|
|
|
+
|
|
|
+ con2.write(output.t_E);
|
|
|
+ con2.write(output.s_CE);
|
|
|
+ con2.write(output.s_DE);
|
|
|
+
|
|
|
+ } else if (party == Party.Debbie) {
|
|
|
+ presscot.runD(predata, n, timer);
|
|
|
+ output = runD(predata, b, new byte[FN], timer);
|
|
|
+
|
|
|
+ con2.write(output.t_D);
|
|
|
+ con2.write(output.s_DE);
|
|
|
+ con2.write(output.s_CD);
|
|
|
+
|
|
|
+ } else if (party == Party.Charlie) {
|
|
|
+ index = con1.readInt();
|
|
|
+ presscot.runC(predata, timer);
|
|
|
+ output = runC(predata, timer);
|
|
|
+
|
|
|
+ int t_E = con1.readInt();
|
|
|
+ int s_CE = con1.readInt();
|
|
|
+ int s_DE = con1.readInt();
|
|
|
+ if ((t_E + output.s_CD) % n != index)
|
|
|
+ System.err.println(j + ": PIRCOT test failed 1");
|
|
|
+ else if (s_CE != output.s_CE)
|
|
|
+ System.err.println(j + ": PIRCOT test failed 2");
|
|
|
+ else if ((s_DE + output.t_C) % n != index)
|
|
|
+ System.err.println(j + ": PIRCOT test failed 3");
|
|
|
+ else
|
|
|
+ System.out.println(j + ": PIRCOT first half test passed");
|
|
|
+
|
|
|
+ int t_D = con2.readInt();
|
|
|
+ s_DE = con2.readInt();
|
|
|
+ int s_CD = con2.readInt();
|
|
|
+ if ((t_D + output.s_CE) % n != index)
|
|
|
+ System.err.println(j + ": PIRCOT test failed 4");
|
|
|
+ else if (s_CD != output.s_CD)
|
|
|
+ System.err.println(j + ": PIRCOT test failed 5");
|
|
|
+ else if ((s_DE + output.t_C) % n != index)
|
|
|
+ System.err.println(j + ": PIRCOT test failed 6");
|
|
|
+ else
|
|
|
+ System.out.println(j + ": PIRCOT all test passed");
|
|
|
+
|
|
|
+ } else {
|
|
|
+ throw new NoSuchPartyException(party + "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void runE(PreData predata, byte[][] a, Timer timer) {
|
|
|
timer.start(pid, M.online_comp);
|
|
|
|
|
@@ -101,55 +248,5 @@ public class PIRCOT extends Protocol {
|
|
|
|
|
|
@Override
|
|
|
public void run(Party party, Metadata md, Forest forest) {
|
|
|
- Timer timer = new Timer();
|
|
|
-
|
|
|
- for (int j = 0; j < 100; j++) {
|
|
|
- int n = 100;
|
|
|
- int FN = 5;
|
|
|
- byte[][] a = new byte[n][FN];
|
|
|
- byte[][] b = new byte[n][FN];
|
|
|
- for (int i = 0; i < n; i++) {
|
|
|
- Crypto.sr.nextBytes(a[i]);
|
|
|
- Crypto.sr.nextBytes(b[i]);
|
|
|
- while (Util.equal(a[i], b[i]))
|
|
|
- Crypto.sr.nextBytes(b[i]);
|
|
|
- }
|
|
|
- int index = Crypto.sr.nextInt(n);
|
|
|
- b[index] = a[index].clone();
|
|
|
-
|
|
|
- PreData predata = new PreData();
|
|
|
- PrePIRCOT presscot = new PrePIRCOT(con1, con2);
|
|
|
- if (party == Party.Eddie) {
|
|
|
- con1.write(b);
|
|
|
- con2.write(index);
|
|
|
- presscot.runE(predata, n, timer);
|
|
|
- runE(predata, a, timer);
|
|
|
-
|
|
|
- } else if (party == Party.Debbie) {
|
|
|
- b = con1.readDoubleByteArray();
|
|
|
- presscot.runD(predata, timer);
|
|
|
- runD(predata, b, timer);
|
|
|
-
|
|
|
- } else if (party == Party.Charlie) {
|
|
|
- index = con1.readInt();
|
|
|
- presscot.runC();
|
|
|
- OutSSCOT output = runC(timer);
|
|
|
- if (output.t == index)
|
|
|
- System.out.println("PIRCOT test passed");
|
|
|
- else
|
|
|
- System.err.println("PIRCOT test failed");
|
|
|
-
|
|
|
- } else {
|
|
|
- throw new NoSuchPartyException(party + "");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void run(Party party, Metadata md, Forest[] forest) {
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
}
|