|
@@ -2,34 +2,53 @@ package pir;
|
|
|
|
|
|
import communication.Communication;
|
|
|
import crypto.Crypto;
|
|
|
+import crypto.PRF;
|
|
|
import exceptions.NoSuchPartyException;
|
|
|
import exceptions.SSCOTException;
|
|
|
import oram.Forest;
|
|
|
import oram.Metadata;
|
|
|
-import pir.precomputation.PrePIRCOT;
|
|
|
import protocols.Protocol;
|
|
|
import protocols.struct.OutPIRCOT;
|
|
|
import protocols.struct.Party;
|
|
|
-import protocols.struct.PreData;
|
|
|
import util.M;
|
|
|
import util.Util;
|
|
|
|
|
|
+// KSearch
|
|
|
public class PIRCOT extends Protocol {
|
|
|
|
|
|
public PIRCOT(Communication con1, Communication con2) {
|
|
|
super(con1, con2);
|
|
|
}
|
|
|
|
|
|
- public OutPIRCOT runE(PreData predata, byte[][] u, byte[] v) {
|
|
|
- timer.start(M.online_comp);
|
|
|
+ public OutPIRCOT runE(byte[][] u, byte[] v) {
|
|
|
+ timer.start(M.offline_comp);
|
|
|
|
|
|
int l = u.length;
|
|
|
+ byte[] k = PRF.generateKey(Crypto.sr_DE);
|
|
|
+ byte[][] r = new byte[l][];
|
|
|
+ for (int i = 0; i < l; i++) {
|
|
|
+ r[i] = new byte[Crypto.secParamBytes];
|
|
|
+ Crypto.sr_DE.nextBytes(r[i]);
|
|
|
+ }
|
|
|
+ int s_DE = Crypto.sr_DE.nextInt(l);
|
|
|
+
|
|
|
+ int s_CE = Crypto.sr_CE.nextInt(l);
|
|
|
+
|
|
|
+ PRF F_k = new PRF(Crypto.secParam);
|
|
|
+ F_k.init(k);
|
|
|
+
|
|
|
+ timer.stop(M.offline_comp);
|
|
|
+
|
|
|
+ //////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+ timer.start(M.online_comp);
|
|
|
+
|
|
|
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]);
|
|
|
+ a[j] = Util.xor(u[(j + s_DE) % l], v);
|
|
|
+ a[j] = Util.padArray(a[j], r[j].length);
|
|
|
+ Util.setXor(a[j], r[j]);
|
|
|
+ a[j] = F_k.compute(a[j]);
|
|
|
}
|
|
|
|
|
|
timer.start(M.online_write);
|
|
@@ -40,27 +59,46 @@ public class PIRCOT extends Protocol {
|
|
|
int delta = con2.readIntAndDec();
|
|
|
timer.stop(M.online_read);
|
|
|
|
|
|
- int t_E = (predata.sscot_s_DE + delta) % l;
|
|
|
+ int t_E = (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;
|
|
|
+ out.s_DE = s_DE;
|
|
|
+ out.s_CE = s_CE;
|
|
|
|
|
|
timer.stop(M.online_comp);
|
|
|
return out;
|
|
|
}
|
|
|
|
|
|
- public OutPIRCOT runD(PreData predata, byte[][] u, byte[] v) {
|
|
|
- timer.start(M.online_comp);
|
|
|
+ public OutPIRCOT runD(byte[][] u, byte[] v) {
|
|
|
+ timer.start(M.offline_comp);
|
|
|
|
|
|
int l = u.length;
|
|
|
+ byte[] k = PRF.generateKey(Crypto.sr_DE);
|
|
|
+ byte[][] r = new byte[l][];
|
|
|
+ for (int i = 0; i < l; i++) {
|
|
|
+ r[i] = new byte[Crypto.secParamBytes];
|
|
|
+ Crypto.sr_DE.nextBytes(r[i]);
|
|
|
+ }
|
|
|
+ int s_DE = Crypto.sr_DE.nextInt(l);
|
|
|
+
|
|
|
+ int s_CD = Crypto.sr_CD.nextInt(l);
|
|
|
+
|
|
|
+ PRF F_k = new PRF(Crypto.secParam);
|
|
|
+ F_k.init(k);
|
|
|
+
|
|
|
+ timer.stop(M.offline_comp);
|
|
|
+
|
|
|
+ ///////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+ timer.start(M.online_comp);
|
|
|
+
|
|
|
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]);
|
|
|
+ a[j] = Util.xor(u[(j + s_DE) % l], v);
|
|
|
+ a[j] = Util.padArray(a[j], r[j].length);
|
|
|
+ Util.setXor(a[j], r[j]);
|
|
|
+ a[j] = F_k.compute(a[j]);
|
|
|
}
|
|
|
|
|
|
timer.start(M.online_write);
|
|
@@ -71,18 +109,27 @@ public class PIRCOT extends Protocol {
|
|
|
int delta = con2.readIntAndDec();
|
|
|
timer.stop(M.online_read);
|
|
|
|
|
|
- int t_D = (predata.sscot_s_DE + delta) % l;
|
|
|
+ int t_D = (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;
|
|
|
+ out.s_DE = s_DE;
|
|
|
+ out.s_CD = s_CD;
|
|
|
|
|
|
timer.stop(M.online_comp);
|
|
|
return out;
|
|
|
}
|
|
|
|
|
|
- public OutPIRCOT runC(PreData predata) {
|
|
|
+ public OutPIRCOT runC(int l) {
|
|
|
+ timer.start(M.offline_comp);
|
|
|
+
|
|
|
+ int s_CE = Crypto.sr_CE.nextInt(l);
|
|
|
+ int s_CD = Crypto.sr_CD.nextInt(l);
|
|
|
+
|
|
|
+ timer.stop(M.offline_comp);
|
|
|
+
|
|
|
+ /////////////////////////////////////////////////
|
|
|
+
|
|
|
timer.start(M.online_comp);
|
|
|
|
|
|
timer.start(M.online_read);
|
|
@@ -90,7 +137,6 @@ public class PIRCOT extends Protocol {
|
|
|
byte[][] y = con2.readDoubleByteArrayAndDec();
|
|
|
timer.stop(M.online_read);
|
|
|
|
|
|
- int l = x.length;
|
|
|
int count = 0;
|
|
|
int t_C = 0;
|
|
|
for (int i = 0; i < l; i++) {
|
|
@@ -104,8 +150,8 @@ public class PIRCOT extends Protocol {
|
|
|
throw new SSCOTException("Invariant error: " + count);
|
|
|
}
|
|
|
|
|
|
- int delta_D = (t_C - predata.sscot_s_CE + l) % l;
|
|
|
- int delta_E = (t_C - predata.sscot_s_CD + l) % l;
|
|
|
+ int delta_D = (t_C - s_CE + l) % l;
|
|
|
+ int delta_E = (t_C - s_CD + l) % l;
|
|
|
|
|
|
timer.start(M.online_write);
|
|
|
con2.write(online_band, delta_D);
|
|
@@ -114,8 +160,8 @@ public class PIRCOT extends Protocol {
|
|
|
|
|
|
OutPIRCOT out = new OutPIRCOT();
|
|
|
out.t_C = t_C;
|
|
|
- out.s_CE = predata.sscot_s_CE;
|
|
|
- out.s_CD = predata.sscot_s_CD;
|
|
|
+ out.s_CE = s_CE;
|
|
|
+ out.s_CD = s_CD;
|
|
|
|
|
|
timer.stop(M.online_comp);
|
|
|
return out;
|
|
@@ -125,7 +171,7 @@ public class PIRCOT extends Protocol {
|
|
|
public void run(Party party, Metadata md, Forest[] forest) {
|
|
|
|
|
|
for (int j = 0; j < 100; j++) {
|
|
|
- int n = 100;
|
|
|
+ int n = 500;
|
|
|
int FN = 5;
|
|
|
byte[][] a = new byte[n][FN];
|
|
|
byte[][] b = new byte[n][FN];
|
|
@@ -135,22 +181,18 @@ public class PIRCOT extends Protocol {
|
|
|
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);
|
|
|
- output = runE(predata, a, v);
|
|
|
+ output = runE(a, v);
|
|
|
|
|
|
con2.write(output.t_E);
|
|
|
con2.write(output.s_CE);
|
|
|
con2.write(output.s_DE);
|
|
|
|
|
|
} else if (party == Party.Debbie) {
|
|
|
- presscot.runD(predata, n);
|
|
|
- output = runD(predata, b, new byte[FN]);
|
|
|
+ output = runD(b, new byte[FN]);
|
|
|
|
|
|
con2.write(output.t_D);
|
|
|
con2.write(output.s_DE);
|
|
@@ -158,8 +200,7 @@ public class PIRCOT extends Protocol {
|
|
|
|
|
|
} else if (party == Party.Charlie) {
|
|
|
index = con1.readInt();
|
|
|
- presscot.runC(predata);
|
|
|
- output = runC(predata);
|
|
|
+ output = runC(n);
|
|
|
|
|
|
int t_E = con1.readInt();
|
|
|
int s_CE = con1.readInt();
|