|
@@ -1,5 +1,7 @@
|
|
|
package pir;
|
|
|
|
|
|
+import java.security.SecureRandom;
|
|
|
+
|
|
|
import communication.Communication;
|
|
|
import crypto.Crypto;
|
|
|
import exceptions.NoSuchPartyException;
|
|
@@ -8,105 +10,116 @@ import oram.Metadata;
|
|
|
import protocols.Protocol;
|
|
|
import protocols.struct.OutPIRCOT;
|
|
|
import protocols.struct.Party;
|
|
|
-import protocols.struct.PreData;
|
|
|
import protocols.struct.TwoThreeXorByte;
|
|
|
import util.M;
|
|
|
-import util.P;
|
|
|
-import util.Timer;
|
|
|
import util.Util;
|
|
|
|
|
|
public class ThreeShiftPIR extends Protocol {
|
|
|
|
|
|
- private int pid = P.TSPIR;
|
|
|
+ SecureRandom sr1;
|
|
|
+ SecureRandom sr2;
|
|
|
|
|
|
public ThreeShiftPIR(Communication con1, Communication con2) {
|
|
|
super(con1, con2);
|
|
|
}
|
|
|
|
|
|
- public TwoThreeXorByte runE(PreData predata, byte[][] x_DE, byte[][] x_CE, OutPIRCOT i, Timer timer) {
|
|
|
- timer.start(pid, M.online_comp);
|
|
|
+ public ThreeShiftPIR(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) {
|
|
|
+ timer.start(M.online_comp);
|
|
|
|
|
|
- ShiftPIR sftpir = new ShiftPIR(con1, con2);
|
|
|
- byte[] e1 = sftpir.runP1(predata, x_DE, i.s_DE, timer);
|
|
|
- sftpir = new ShiftPIR(con2, con1);
|
|
|
- byte[] e2 = sftpir.runP2(predata, x_CE, i.s_CE, timer);
|
|
|
- sftpir = new ShiftPIR(con1, con2);
|
|
|
- sftpir.runP3(predata, i.t_E, timer);
|
|
|
+ int l = x_DE.length;
|
|
|
+ ShiftPIR sftpir = new ShiftPIR(con1, con2, sr1, sr2);
|
|
|
+ byte[] e1 = sftpir.runP1(x_DE, i.s_DE);
|
|
|
+ sftpir.reinit(con2, con1, sr2, sr1);
|
|
|
+ byte[] e2 = sftpir.runP2(x_CE, i.s_CE);
|
|
|
+ sftpir.reinit(con1, con2, sr1, sr2);
|
|
|
+ sftpir.runP3(l, i.t_E);
|
|
|
Util.setXor(e1, e2);
|
|
|
|
|
|
TwoThreeXorByte X = new TwoThreeXorByte();
|
|
|
X.DE = e1;
|
|
|
|
|
|
- timer.start(pid, M.online_write);
|
|
|
- con1.write(pid, X.DE);
|
|
|
- timer.stop(pid, M.online_write);
|
|
|
+ timer.start(M.online_write);
|
|
|
+ con1.write(online_band, X.DE);
|
|
|
+ timer.stop(M.online_write);
|
|
|
|
|
|
- timer.start(pid, M.online_read);
|
|
|
- X.CE = con2.read(pid);
|
|
|
- timer.stop(pid, M.online_read);
|
|
|
+ timer.start(M.online_read);
|
|
|
+ X.CE = con2.readAndDec();
|
|
|
+ timer.stop(M.online_read);
|
|
|
|
|
|
- timer.stop(pid, M.online_comp);
|
|
|
+ timer.stop(M.online_comp);
|
|
|
return X;
|
|
|
}
|
|
|
|
|
|
- public TwoThreeXorByte runD(PreData predata, byte[][] x_DE, byte[][] x_CD, OutPIRCOT i, Timer timer) {
|
|
|
- timer.start(pid, M.online_comp);
|
|
|
+ public TwoThreeXorByte runD(byte[][] x_DE, byte[][] x_CD, OutPIRCOT i) {
|
|
|
+ timer.start(M.online_comp);
|
|
|
|
|
|
- ShiftPIR sftpir = new ShiftPIR(con1, con2);
|
|
|
- byte[] d1 = sftpir.runP2(predata, x_DE, i.s_DE, timer);
|
|
|
- sftpir = new ShiftPIR(con2, con1);
|
|
|
- sftpir.runP3(predata, i.t_D, timer);
|
|
|
- sftpir = new ShiftPIR(con2, con1);
|
|
|
- byte[] d2 = sftpir.runP1(predata, x_CD, i.s_CD, timer);
|
|
|
+ int l = x_DE.length;
|
|
|
+ ShiftPIR sftpir = new ShiftPIR(con1, con2, sr1, sr2);
|
|
|
+ byte[] d1 = sftpir.runP2(x_DE, i.s_DE);
|
|
|
+ sftpir.reinit(con2, con1, sr2, sr1);
|
|
|
+ sftpir.runP3(l, i.t_D);
|
|
|
+ sftpir.reinit(con2, con1, sr2, sr1);
|
|
|
+ byte[] d2 = sftpir.runP1(x_CD, i.s_CD);
|
|
|
Util.setXor(d1, d2);
|
|
|
|
|
|
TwoThreeXorByte X = new TwoThreeXorByte();
|
|
|
X.CD = d1;
|
|
|
|
|
|
- timer.start(pid, M.online_write);
|
|
|
- con2.write(pid, X.CD);
|
|
|
- timer.stop(pid, M.online_write);
|
|
|
+ timer.start(M.online_write);
|
|
|
+ con2.write(online_band, X.CD);
|
|
|
+ timer.stop(M.online_write);
|
|
|
|
|
|
- timer.start(pid, M.online_read);
|
|
|
- X.DE = con1.read(pid);
|
|
|
- timer.stop(pid, M.online_read);
|
|
|
+ timer.start(M.online_read);
|
|
|
+ X.DE = con1.readAndDec();
|
|
|
+ timer.stop(M.online_read);
|
|
|
|
|
|
- timer.stop(pid, M.online_comp);
|
|
|
+ timer.stop(M.online_comp);
|
|
|
return X;
|
|
|
}
|
|
|
|
|
|
- public TwoThreeXorByte runC(PreData predata, byte[][] x_CD, byte[][] x_CE, OutPIRCOT i, Timer timer) {
|
|
|
- timer.start(pid, M.online_comp);
|
|
|
+ public TwoThreeXorByte runC(byte[][] x_CD, byte[][] x_CE, OutPIRCOT i) {
|
|
|
+ timer.start(M.online_comp);
|
|
|
|
|
|
- ShiftPIR sftpir = new ShiftPIR(con1, con2);
|
|
|
- sftpir.runP3(predata, i.t_C, timer);
|
|
|
- sftpir = new ShiftPIR(con1, con2);
|
|
|
- byte[] c1 = sftpir.runP1(predata, x_CE, i.s_CE, timer);
|
|
|
- sftpir = new ShiftPIR(con2, con1);
|
|
|
- byte[] c2 = sftpir.runP2(predata, x_CD, i.s_CD, timer);
|
|
|
+ int l = x_CD.length;
|
|
|
+ ShiftPIR sftpir = new ShiftPIR(con1, con2, sr1, sr2);
|
|
|
+ sftpir.runP3(l, i.t_C);
|
|
|
+ sftpir.reinit(con1, con2, sr1, sr2);
|
|
|
+ byte[] c1 = sftpir.runP1(x_CE, i.s_CE);
|
|
|
+ sftpir.reinit(con2, con1, sr2, sr1);
|
|
|
+ byte[] c2 = sftpir.runP2(x_CD, i.s_CD);
|
|
|
Util.setXor(c1, c2);
|
|
|
|
|
|
TwoThreeXorByte X = new TwoThreeXorByte();
|
|
|
X.CE = c1;
|
|
|
|
|
|
- timer.start(pid, M.online_write);
|
|
|
- con1.write(pid, X.CE);
|
|
|
- timer.stop(pid, M.online_write);
|
|
|
+ timer.start(M.online_write);
|
|
|
+ con1.write(online_band, X.CE);
|
|
|
+ timer.stop(M.online_write);
|
|
|
|
|
|
- timer.start(pid, M.online_read);
|
|
|
- X.CD = con2.read(pid);
|
|
|
- timer.stop(pid, M.online_read);
|
|
|
+ timer.start(M.online_read);
|
|
|
+ X.CD = con2.readAndDec();
|
|
|
+ timer.stop(M.online_read);
|
|
|
|
|
|
- timer.stop(pid, M.online_comp);
|
|
|
+ timer.stop(M.online_comp);
|
|
|
return X;
|
|
|
}
|
|
|
|
|
|
@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 l = 500;
|
|
|
int m = 50;
|
|
@@ -130,6 +143,8 @@ public class ThreeShiftPIR extends Protocol {
|
|
|
TwoThreeXorByte X = new TwoThreeXorByte();
|
|
|
|
|
|
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);
|
|
@@ -141,7 +156,7 @@ public class ThreeShiftPIR extends Protocol {
|
|
|
con2.write(ks.s_CE);
|
|
|
con2.write(ks.s_CD);
|
|
|
|
|
|
- X = this.runE(predata, x_DE, x_CE, ks, timer);
|
|
|
+ X = this.runE(x_DE, x_CE, ks);
|
|
|
X.CD = con1.read();
|
|
|
byte[] e = X.CE;
|
|
|
Util.setXor(e, X.CD);
|
|
@@ -156,23 +171,27 @@ public class ThreeShiftPIR extends Protocol {
|
|
|
System.out.println(j + ": 3ShiftPIR 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();
|
|
|
ks.s_DE = con1.readInt();
|
|
|
ks.s_CD = con1.readInt();
|
|
|
|
|
|
- X = this.runD(predata, x_DE, x_CD, ks, timer);
|
|
|
+ X = this.runD(x_DE, x_CD, ks);
|
|
|
con1.write(X.CD);
|
|
|
|
|
|
} 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();
|
|
|
ks.s_CE = con1.readInt();
|
|
|
ks.s_CD = con1.readInt();
|
|
|
|
|
|
- this.runC(predata, x_CD, x_CE, ks, timer);
|
|
|
+ this.runC(x_CD, x_CE, ks);
|
|
|
|
|
|
} else {
|
|
|
throw new NoSuchPartyException(party + "");
|