|
@@ -1,5 +1,6 @@
|
|
|
package pir;
|
|
|
|
|
|
+import java.security.SecureRandom;
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
import communication.Communication;
|
|
@@ -10,121 +11,129 @@ import oram.Metadata;
|
|
|
import protocols.Protocol;
|
|
|
import protocols.struct.OutPIRCOT;
|
|
|
import protocols.struct.Party;
|
|
|
-import protocols.struct.PreData;
|
|
|
import protocols.struct.TwoOneXor;
|
|
|
import protocols.struct.TwoThreeXorByte;
|
|
|
import util.M;
|
|
|
-import util.P;
|
|
|
-import util.Timer;
|
|
|
import util.Util;
|
|
|
|
|
|
public class ThreeShiftXorPIR extends Protocol {
|
|
|
|
|
|
- private int pid = P.TSXPIR;
|
|
|
+ SecureRandom sr1;
|
|
|
+ SecureRandom sr2;
|
|
|
|
|
|
public ThreeShiftXorPIR(Communication con1, Communication con2) {
|
|
|
super(con1, con2);
|
|
|
}
|
|
|
|
|
|
- public TwoThreeXorByte runE(PreData predata, byte[][] x_DE, byte[][] x_CE, OutPIRCOT i, TwoOneXor dN, int ttp,
|
|
|
- Timer timer) {
|
|
|
- timer.start(pid, M.online_comp);
|
|
|
+ public ThreeShiftXorPIR(Communication con1, Communication con2, SecureRandom sr1, SecureRandom sr2) {
|
|
|
+ super(con1, con2);
|
|
|
+ this.sr1 = sr1;
|
|
|
+ this.sr2 = sr2;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void reinit(Communication con1, Communication con2, SecureRandom sr1, SecureRandom sr2) {
|
|
|
+ this.con1 = con1;
|
|
|
+ this.con2 = con2;
|
|
|
+ this.sr1 = sr1;
|
|
|
+ this.sr2 = sr2;
|
|
|
+ }
|
|
|
+
|
|
|
+ public TwoThreeXorByte runE(byte[][] x_DE, byte[][] x_CE, OutPIRCOT i, TwoOneXor dN, int ttp) {
|
|
|
+ timer.start(M.online_comp);
|
|
|
|
|
|
- ShiftXorPIR sftpir = new ShiftXorPIR(con1, con2);
|
|
|
- byte[] e1 = sftpir.runP1(predata, x_DE, i.s_DE, dN.s_DE, ttp, timer);
|
|
|
- sftpir = new ShiftXorPIR(con2, con1);
|
|
|
- byte[] e2 = sftpir.runP2(predata, x_CE, i.s_CE, dN.s_CE, ttp, timer);
|
|
|
- sftpir = new ShiftXorPIR(con1, con2);
|
|
|
- sftpir.runP3(predata, i.t_E, dN.t_E, ttp, timer);
|
|
|
+ int n = x_DE.length;
|
|
|
+ ShiftXorPIR sftpir = new ShiftXorPIR(con1, con2, sr1, sr2);
|
|
|
+ byte[] e1 = sftpir.runP1(x_DE, i.s_DE, dN.s_DE, ttp);
|
|
|
+ sftpir.reinit(con2, con1, sr2, sr1);
|
|
|
+ byte[] e2 = sftpir.runP2(x_CE, i.s_CE, dN.s_CE, ttp);
|
|
|
+ sftpir.reinit(con1, con2, sr1, sr2);
|
|
|
+ sftpir.runP3(i.t_E, dN.t_E, n, ttp);
|
|
|
Util.setXor(e1, e2);
|
|
|
|
|
|
- timer.start(pid, M.online_write);
|
|
|
- con1.write(pid, e1);
|
|
|
- con2.write(pid, e1);
|
|
|
- timer.stop(pid, M.online_write);
|
|
|
+ timer.start(M.online_write);
|
|
|
+ con1.write(online_band, e1);
|
|
|
+ con2.write(online_band, e1);
|
|
|
+ timer.stop(M.online_write);
|
|
|
|
|
|
- timer.start(pid, M.online_read);
|
|
|
- byte[] d = con1.read(pid);
|
|
|
- byte[] c = con2.read(pid);
|
|
|
- timer.stop(pid, M.online_read);
|
|
|
+ timer.start(M.online_read);
|
|
|
+ byte[] d = con1.readAndDec();
|
|
|
+ byte[] c = con2.readAndDec();
|
|
|
+ timer.stop(M.online_read);
|
|
|
|
|
|
TwoThreeXorByte nextL = new TwoThreeXorByte();
|
|
|
nextL.DE = e1;
|
|
|
nextL.CD = d;
|
|
|
nextL.CE = c;
|
|
|
|
|
|
- timer.stop(pid, M.online_comp);
|
|
|
+ timer.stop(M.online_comp);
|
|
|
return nextL;
|
|
|
}
|
|
|
|
|
|
- public TwoThreeXorByte runD(PreData predata, byte[][] x_DE, byte[][] x_CD, OutPIRCOT i, TwoOneXor dN, int ttp,
|
|
|
- Timer timer) {
|
|
|
- timer.start(pid, M.online_comp);
|
|
|
+ public TwoThreeXorByte runD(byte[][] x_DE, byte[][] x_CD, OutPIRCOT i, TwoOneXor dN, int ttp) {
|
|
|
+ timer.start(M.online_comp);
|
|
|
|
|
|
- ShiftXorPIR sftpir = new ShiftXorPIR(con1, con2);
|
|
|
- byte[] d1 = sftpir.runP2(predata, x_DE, i.s_DE, dN.s_DE, ttp, timer);
|
|
|
- sftpir = new ShiftXorPIR(con2, con1);
|
|
|
- sftpir.runP3(predata, i.t_D, dN.t_D, ttp, timer);
|
|
|
- sftpir = new ShiftXorPIR(con2, con1);
|
|
|
- byte[] d2 = sftpir.runP1(predata, x_CD, i.s_CD, dN.s_CD, ttp, timer);
|
|
|
+ int n = x_DE.length;
|
|
|
+ ShiftXorPIR sftpir = new ShiftXorPIR(con1, con2, sr1, sr2);
|
|
|
+ byte[] d1 = sftpir.runP2(x_DE, i.s_DE, dN.s_DE, ttp);
|
|
|
+ sftpir.reinit(con2, con1, sr2, sr1);
|
|
|
+ sftpir.runP3(i.t_D, dN.t_D, n, ttp);
|
|
|
+ sftpir.reinit(con2, con1, sr2, sr1);
|
|
|
+ byte[] d2 = sftpir.runP1(x_CD, i.s_CD, dN.s_CD, ttp);
|
|
|
Util.setXor(d1, d2);
|
|
|
|
|
|
- timer.start(pid, M.online_write);
|
|
|
- con1.write(pid, d1);
|
|
|
- con2.write(pid, d1);
|
|
|
- timer.stop(pid, M.online_write);
|
|
|
+ timer.start(M.online_write);
|
|
|
+ con1.write(online_band, d1);
|
|
|
+ con2.write(online_band, d1);
|
|
|
+ timer.stop(M.online_write);
|
|
|
|
|
|
- timer.start(pid, M.online_read);
|
|
|
- byte[] e = con1.read(pid);
|
|
|
- byte[] c = con2.read(pid);
|
|
|
- timer.stop(pid, M.online_read);
|
|
|
+ timer.start(M.online_read);
|
|
|
+ byte[] e = con1.readAndDec();
|
|
|
+ byte[] c = con2.readAndDec();
|
|
|
+ timer.stop(M.online_read);
|
|
|
|
|
|
TwoThreeXorByte nextL = new TwoThreeXorByte();
|
|
|
nextL.DE = e;
|
|
|
nextL.CD = d1;
|
|
|
nextL.CE = c;
|
|
|
|
|
|
- timer.stop(pid, M.online_comp);
|
|
|
+ timer.stop(M.online_comp);
|
|
|
return nextL;
|
|
|
}
|
|
|
|
|
|
- public TwoThreeXorByte runC(PreData predata, byte[][] x_CD, byte[][] x_CE, OutPIRCOT i, TwoOneXor dN, int ttp,
|
|
|
- Timer timer) {
|
|
|
- timer.start(pid, M.online_comp);
|
|
|
+ public TwoThreeXorByte runC(byte[][] x_CD, byte[][] x_CE, OutPIRCOT i, TwoOneXor dN, int ttp) {
|
|
|
+ timer.start(M.online_comp);
|
|
|
|
|
|
- ShiftXorPIR sftpir = new ShiftXorPIR(con1, con2);
|
|
|
- sftpir.runP3(predata, i.t_C, dN.t_C, ttp, timer);
|
|
|
- sftpir = new ShiftXorPIR(con1, con2);
|
|
|
- byte[] c1 = sftpir.runP1(predata, x_CE, i.s_CE, dN.s_CE, ttp, timer);
|
|
|
- sftpir = new ShiftXorPIR(con2, con1);
|
|
|
- byte[] c2 = sftpir.runP2(predata, x_CD, i.s_CD, dN.s_CD, ttp, timer);
|
|
|
+ int n = x_CD.length;
|
|
|
+ ShiftXorPIR sftpir = new ShiftXorPIR(con1, con2, sr1, sr2);
|
|
|
+ sftpir.runP3(i.t_C, dN.t_C, n, ttp);
|
|
|
+ sftpir.reinit(con1, con2, sr1, sr2);
|
|
|
+ byte[] c1 = sftpir.runP1(x_CE, i.s_CE, dN.s_CE, ttp);
|
|
|
+ sftpir.reinit(con2, con1, sr2, sr1);
|
|
|
+ byte[] c2 = sftpir.runP2(x_CD, i.s_CD, dN.s_CD, ttp);
|
|
|
Util.setXor(c1, c2);
|
|
|
|
|
|
- timer.start(pid, M.online_write);
|
|
|
- con1.write(pid, c1);
|
|
|
- con2.write(pid, c1);
|
|
|
- timer.stop(pid, M.online_write);
|
|
|
+ timer.start(M.online_write);
|
|
|
+ con1.write(online_band, c1);
|
|
|
+ con2.write(online_band, c1);
|
|
|
+ timer.stop(M.online_write);
|
|
|
|
|
|
- timer.start(pid, M.online_read);
|
|
|
- byte[] e = con1.read(pid);
|
|
|
- byte[] d = con2.read(pid);
|
|
|
- timer.stop(pid, M.online_read);
|
|
|
+ timer.start(M.online_read);
|
|
|
+ byte[] e = con1.readAndDec();
|
|
|
+ byte[] d = con2.readAndDec();
|
|
|
+ timer.stop(M.online_read);
|
|
|
|
|
|
TwoThreeXorByte nextL = new TwoThreeXorByte();
|
|
|
nextL.DE = e;
|
|
|
nextL.CD = d;
|
|
|
nextL.CE = c1;
|
|
|
|
|
|
- timer.stop(pid, M.online_comp);
|
|
|
+ timer.stop(M.online_comp);
|
|
|
return nextL;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void run(Party party, Metadata md, Forest[] forest) {
|
|
|
|
|
|
- Timer timer = new Timer();
|
|
|
- PreData predata = new PreData();
|
|
|
-
|
|
|
for (int j = 0; j < 100; j++) {
|
|
|
int n = 500;
|
|
|
int m = 16;
|
|
@@ -156,6 +165,8 @@ public class ThreeShiftXorPIR extends Protocol {
|
|
|
tox.s_CD = i2 ^ tox.t_E;
|
|
|
|
|
|
if (party == Party.Eddie) {
|
|
|
+ this.reinit(con1, con2, Crypto.sr_DE, Crypto.sr_CE);
|
|
|
+
|
|
|
con1.write(x_CD);
|
|
|
con1.write(x_DE);
|
|
|
con2.write(x_CD);
|
|
@@ -173,7 +184,7 @@ public class ThreeShiftXorPIR extends Protocol {
|
|
|
con2.write(tox.s_CE);
|
|
|
con2.write(tox.s_CD);
|
|
|
|
|
|
- TwoThreeXorByte nextL = this.runE(predata, x_DE, x_CE, ks, tox, m, timer);
|
|
|
+ TwoThreeXorByte nextL = this.runE(x_DE, x_CE, ks, tox, m);
|
|
|
byte[] e = Util.xor(Util.xor(nextL.DE, nextL.CE), nextL.CD);
|
|
|
byte[] d = con1.read();
|
|
|
byte[] c = con2.read();
|
|
@@ -189,6 +200,8 @@ public class ThreeShiftXorPIR extends Protocol {
|
|
|
System.out.println(j + ": 3ShiftXorPIR test passed");
|
|
|
|
|
|
} else if (party == Party.Debbie) {
|
|
|
+ this.reinit(con1, con2, Crypto.sr_DE, Crypto.sr_CD);
|
|
|
+
|
|
|
x_CD = con1.readDoubleByteArray();
|
|
|
x_DE = con1.readDoubleByteArray();
|
|
|
ks.t_D = con1.readInt();
|
|
@@ -198,11 +211,13 @@ public class ThreeShiftXorPIR extends Protocol {
|
|
|
tox.s_DE = con1.readInt();
|
|
|
tox.s_CD = con1.readInt();
|
|
|
|
|
|
- TwoThreeXorByte nextL = this.runD(predata, x_DE, x_CD, ks, tox, m, timer);
|
|
|
+ TwoThreeXorByte nextL = this.runD(x_DE, x_CD, ks, tox, m);
|
|
|
byte[] d = Util.xor(Util.xor(nextL.DE, nextL.CE), nextL.CD);
|
|
|
con1.write(d);
|
|
|
|
|
|
} else if (party == Party.Charlie) {
|
|
|
+ this.reinit(con1, con2, Crypto.sr_CE, Crypto.sr_CD);
|
|
|
+
|
|
|
x_CD = con1.readDoubleByteArray();
|
|
|
x_CE = con1.readDoubleByteArray();
|
|
|
ks.t_C = con1.readInt();
|
|
@@ -212,7 +227,7 @@ public class ThreeShiftXorPIR extends Protocol {
|
|
|
tox.s_CE = con1.readInt();
|
|
|
tox.s_CD = con1.readInt();
|
|
|
|
|
|
- TwoThreeXorByte nextL = this.runC(predata, x_CD, x_CE, ks, tox, m, timer);
|
|
|
+ TwoThreeXorByte nextL = this.runC(x_CD, x_CE, ks, tox, m);
|
|
|
byte[] c = Util.xor(Util.xor(nextL.DE, nextL.CE), nextL.CD);
|
|
|
con1.write(c);
|
|
|
|