Преглед изворни кода

added offline timing for ACC, COT, IOT

Boyoung- пре 9 година
родитељ
комит
cbbd569a0f

+ 2 - 2
src/measure/Timing.java → src/measure/Timer.java

@@ -5,11 +5,11 @@ import java.util.Stack;
 import exceptions.TimingException;
 import util.StopWatch;
 
-public class Timing {
+public class Timer {
 	StopWatch[][] watches;
 	Stack<StopWatch> stack;
 
-	public Timing() {
+	public Timer() {
 		watches = new StopWatch[P.size][M.size];
 		for (int i = 0; i < P.size; i++)
 			for (int j = 0; j < M.size; j++)

+ 34 - 34
src/protocols/Access.java

@@ -11,7 +11,7 @@ import exceptions.AccessException;
 import exceptions.NoSuchPartyException;
 import measure.M;
 import measure.P;
-import measure.Timing;
+import measure.Timer;
 import oram.Bucket;
 import oram.Forest;
 import oram.Metadata;
@@ -25,15 +25,15 @@ public class Access extends Protocol {
 		super(con1, con2);
 	}
 
-	public OutAccess runE(PreData predata, Tree OTi, byte[] Ni, byte[] Nip1_pr, Timing time) {
-		time.start(P.ACC, M.online_comp);
+	public OutAccess runE(PreData predata, Tree OTi, byte[] Ni, byte[] Nip1_pr, Timer timer) {
+		timer.start(P.ACC, M.online_comp);
 
 		// step 0: get Li from C
-		time.start(P.ACC, M.online_read);
+		timer.start(P.ACC, M.online_read);
 		byte[] Li = new byte[0];
 		if (OTi.getTreeIndex() > 0)
 			Li = con2.read();
-		time.stop(P.ACC, M.online_read);
+		timer.stop(P.ACC, M.online_read);
 
 		// step 1
 		Bucket[] pathBuckets = OTi.getBucketsOnPath(new BigInteger(1, Li).longValue());
@@ -63,7 +63,7 @@ public class Access extends Protocol {
 			}
 
 			SSCOT sscot = new SSCOT(con1, con2);
-			sscot.runE(predata, m, a, time);
+			sscot.runE(predata, m, a, timer);
 		}
 
 		// step 4
@@ -74,7 +74,7 @@ public class Access extends Protocol {
 				y_array[i] = Arrays.copyOfRange(y, i * ySegBytes, (i + 1) * ySegBytes);
 
 			SSIOT ssiot = new SSIOT(con1, con2);
-			ssiot.runE(predata, y_array, Nip1_pr, time);
+			ssiot.runE(predata, y_array, Nip1_pr, timer);
 		}
 
 		// step 5
@@ -86,19 +86,19 @@ public class Access extends Protocol {
 
 		OutAccess outaccess = new OutAccess(null, null, null, Ti, pathTuples);
 
-		time.stop(P.ACC, M.online_comp);
+		timer.stop(P.ACC, M.online_comp);
 		return outaccess;
 	}
 
-	public void runD(PreData predata, Tree OTi, byte[] Ni, byte[] Nip1_pr, Timing time) {
-		time.start(P.ACC, M.online_comp);
+	public void runD(PreData predata, Tree OTi, byte[] Ni, byte[] Nip1_pr, Timer timer) {
+		timer.start(P.ACC, M.online_comp);
 
 		// step 0: get Li from C
-		time.start(P.ACC, M.online_read);
+		timer.start(P.ACC, M.online_read);
 		byte[] Li = new byte[0];
 		if (OTi.getTreeIndex() > 0)
 			Li = con2.read();
-		time.stop(P.ACC, M.online_read);
+		timer.stop(P.ACC, M.online_read);
 
 		// step 1
 		Bucket[] pathBuckets = OTi.getBucketsOnPath(new BigInteger(1, Li).longValue());
@@ -109,10 +109,10 @@ public class Access extends Protocol {
 		pathTuples = Arrays.copyOf(objArray, objArray.length, Tuple[].class);
 
 		// step 2
-		time.start(P.ACC, M.online_write);
+		timer.start(P.ACC, M.online_write);
 		con2.write(pathTuples);
 		con2.write(Ni);
-		time.stop(P.ACC, M.online_write);
+		timer.stop(P.ACC, M.online_write);
 
 		// step 3
 		if (OTi.getTreeIndex() > 0) {
@@ -125,34 +125,34 @@ public class Access extends Protocol {
 			}
 
 			SSCOT sscot = new SSCOT(con1, con2);
-			sscot.runD(predata, b, time);
+			sscot.runD(predata, b, timer);
 		}
 
 		// step 4
 		if (OTi.getTreeIndex() < OTi.getH() - 1) {
 			SSIOT ssiot = new SSIOT(con1, con2);
-			ssiot.runD(predata, Nip1_pr, time);
+			ssiot.runD(predata, Nip1_pr, timer);
 		}
 
-		time.stop(P.ACC, M.online_comp);
+		timer.stop(P.ACC, M.online_comp);
 	}
 
-	public OutAccess runC(Metadata md, int treeIndex, byte[] Li, Timing time) {
-		time.start(P.ACC, M.online_comp);
+	public OutAccess runC(Metadata md, int treeIndex, byte[] Li, Timer timer) {
+		timer.start(P.ACC, M.online_comp);
 
 		// step 0: send Li to E and D
-		time.start(P.ACC, M.online_write);
+		timer.start(P.ACC, M.online_write);
 		if (treeIndex > 0) {
 			con1.write(Li);
 			con2.write(Li);
 		}
-		time.stop(P.ACC, M.online_write);
+		timer.stop(P.ACC, M.online_write);
 
 		// step 2
-		time.start(P.ACC, M.online_read);
+		timer.start(P.ACC, M.online_read);
 		Tuple[] pathTuples = con2.readObject();
 		byte[] Ni = con2.read();
-		time.stop(P.ACC, M.online_read);
+		timer.stop(P.ACC, M.online_read);
 
 		// step 3
 		int j1 = 0;
@@ -161,7 +161,7 @@ public class Access extends Protocol {
 			z = pathTuples[0].getA();
 		} else {
 			SSCOT sscot = new SSCOT(con1, con2);
-			OutSSCOT je = sscot.runC(time);
+			OutSSCOT je = sscot.runC(timer);
 			j1 = je.t;
 			byte[] d = pathTuples[j1].getA();
 			z = Util.xor(je.m_t, d);
@@ -172,7 +172,7 @@ public class Access extends Protocol {
 		byte[] Lip1 = null;
 		if (treeIndex < md.getNumTrees() - 1) {
 			SSIOT ssiot = new SSIOT(con1, con2);
-			OutSSIOT jy = ssiot.runC(time);
+			OutSSIOT jy = ssiot.runC(timer);
 
 			// step 5
 			j2 = jy.t;
@@ -195,7 +195,7 @@ public class Access extends Protocol {
 
 		OutAccess outaccess = new OutAccess(Lip1, Ti, pathTuples, null, null);
 
-		time.stop(P.ACC, M.online_comp);
+		timer.stop(P.ACC, M.online_comp);
 		return outaccess;
 	}
 
@@ -209,7 +209,7 @@ public class Access extends Protocol {
 		long numInsert = md.getNumInsertRecords();
 		int addrBits = md.getAddrBits();
 
-		Timing time = new Timing();
+		Timer timer = new Timer();
 
 		sanityCheck();
 
@@ -237,7 +237,7 @@ public class Access extends Protocol {
 					if (party == Party.Eddie) {
 						Tree OTi = forest.getTree(ti);
 						int numTuples = (OTi.getD() - 1) * OTi.getW() + OTi.getStashSize();
-						preaccess.runE(predata, OTi, numTuples);
+						preaccess.runE(predata, OTi, numTuples, timer);
 
 						byte[] sE_Ni = Util.nextBytes(Ni.length, Crypto.sr);
 						byte[] sD_Ni = Util.xor(Ni, sE_Ni);
@@ -247,27 +247,27 @@ public class Access extends Protocol {
 						byte[] sD_Nip1_pr = Util.xor(Nip1_pr, sE_Nip1_pr);
 						con1.write(sD_Nip1_pr);
 
-						runE(predata, OTi, sE_Ni, sE_Nip1_pr, time);
+						runE(predata, OTi, sE_Ni, sE_Nip1_pr, timer);
 
 						if (ti == numTrees - 1)
 							con2.write(N);
 
 					} else if (party == Party.Debbie) {
 						Tree OTi = forest.getTree(ti);
-						preaccess.runD(predata);
+						preaccess.runD(predata, timer);
 
 						byte[] sD_Ni = con1.read();
 
 						byte[] sD_Nip1_pr = con1.read();
 
-						runD(predata, OTi, sD_Ni, sD_Nip1_pr, time);
+						runD(predata, OTi, sD_Ni, sD_Nip1_pr, timer);
 
 					} else if (party == Party.Charlie) {
-						preaccess.runC();
+						preaccess.runC(timer);
 
 						System.out.println("L" + ti + "=" + new BigInteger(1, Li).toString(2));
 
-						OutAccess outaccess = runC(md, ti, Li, time);
+						OutAccess outaccess = runC(md, ti, Li, timer);
 
 						Li = outaccess.C_Lip1;
 
@@ -289,6 +289,6 @@ public class Access extends Protocol {
 			}
 		}
 
-		time.print();
+		timer.print();
 	}
 }

+ 26 - 7
src/protocols/PreAccess.java

@@ -2,6 +2,9 @@ package protocols;
 
 import communication.Communication;
 import crypto.Crypto;
+import measure.M;
+import measure.P;
+import measure.Timer;
 import oram.Forest;
 import oram.Metadata;
 import oram.Tree;
@@ -13,14 +16,16 @@ public class PreAccess extends Protocol {
 		super(con1, con2);
 	}
 
-	public void runE(PreData predata, Tree OT, int numTuples) {
+	public void runE(PreData predata, Tree OT, int numTuples, Timer timer) {
+		timer.start(P.ACC, M.offline_comp);
+
 		// SSCOT
 		PreSSCOT presscot = new PreSSCOT(con1, con2);
-		presscot.runE(predata, numTuples);
+		presscot.runE(predata, numTuples, timer);
 
 		// SSIOT
 		PreSSIOT pressiot = new PreSSIOT(con1, con2);
-		pressiot.runE(predata, OT.getTwoTauPow());
+		pressiot.runE(predata, OT.getTwoTauPow(), timer);
 
 		// Access
 		predata.access_sigma = Util.randomPermutation(numTuples, Crypto.sr);
@@ -28,25 +33,37 @@ public class PreAccess extends Protocol {
 		for (int i = 0; i < numTuples; i++)
 			predata.access_p[i] = new Tuple(OT.getFBytes(), OT.getNBytes(), OT.getLBytes(), OT.getABytes(), Crypto.sr);
 
+		timer.start(P.ACC, M.offline_write);
 		con1.write(predata.access_sigma);
 		con1.write(predata.access_p);
+		timer.stop(P.ACC, M.offline_write);
+
+		timer.stop(P.ACC, M.offline_comp);
 	}
 
-	public void runD(PreData predata) {
+	public void runD(PreData predata, Timer timer) {
+		timer.start(P.ACC, M.offline_comp);
+
 		// SSCOT
 		PreSSCOT presscot = new PreSSCOT(con1, con2);
-		presscot.runD(predata);
+		presscot.runD(predata, timer);
 
 		// SSIOT
 		PreSSIOT pressiot = new PreSSIOT(con1, con2);
-		pressiot.runD(predata);
+		pressiot.runD(predata, timer);
 
 		// Access
+		timer.start(P.ACC, M.offline_read);
 		predata.access_sigma = con1.readObject();
 		predata.access_p = con1.readObject();
+		timer.stop(P.ACC, M.offline_read);
+
+		timer.stop(P.ACC, M.offline_comp);
 	}
 
-	public void runC() {
+	public void runC(Timer timer) {
+		timer.start(P.ACC, M.offline_comp);
+
 		// SSCOT
 		PreSSCOT presscot = new PreSSCOT(con1, con2);
 		presscot.runC();
@@ -54,6 +71,8 @@ public class PreAccess extends Protocol {
 		// SSIOT
 		PreSSIOT pressiot = new PreSSIOT(con1, con2);
 		pressiot.runC();
+
+		timer.stop(P.ACC, M.offline_comp);
 	}
 
 	@Override

+ 14 - 2
src/protocols/PreSSCOT.java

@@ -3,6 +3,9 @@ package protocols;
 import communication.Communication;
 import crypto.Crypto;
 import crypto.PRF;
+import measure.M;
+import measure.P;
+import measure.Timer;
 import oram.Forest;
 import oram.Metadata;
 
@@ -11,7 +14,9 @@ public class PreSSCOT extends Protocol {
 		super(con1, con2);
 	}
 
-	public void runE(PreData predata, int n) {
+	public void runE(PreData predata, int n, Timer timer) {
+		timer.start(P.COT, M.offline_comp);
+
 		predata.sscot_k = PRF.generateKey(Crypto.sr);
 		predata.sscot_kprime = PRF.generateKey(Crypto.sr);
 		predata.sscot_r = new byte[n][];
@@ -19,15 +24,22 @@ public class PreSSCOT extends Protocol {
 			predata.sscot_r[i] = new byte[Crypto.secParamBytes];
 			Crypto.sr.nextBytes(predata.sscot_r[i]);
 		}
+
+		timer.start(P.COT, M.offline_write);
 		con1.write(predata.sscot_k);
 		con1.write(predata.sscot_kprime);
 		con1.write(predata.sscot_r);
+		timer.stop(P.COT, M.offline_write);
+
+		timer.stop(P.COT, M.offline_comp);
 	}
 
-	public void runD(PreData predata) {
+	public void runD(PreData predata, Timer timer) {
+		timer.start(P.COT, M.offline_read);
 		predata.sscot_k = con1.read();
 		predata.sscot_kprime = con1.read();
 		predata.sscot_r = con1.readObject();
+		timer.stop(P.COT, M.offline_read);
 	}
 
 	public void runC() {

+ 13 - 2
src/protocols/PreSSIOT.java

@@ -3,6 +3,9 @@ package protocols;
 import communication.Communication;
 import crypto.Crypto;
 import crypto.PRF;
+import measure.M;
+import measure.P;
+import measure.Timer;
 import oram.Forest;
 import oram.Metadata;
 import util.Util;
@@ -12,20 +15,28 @@ public class PreSSIOT extends Protocol {
 		super(con1, con2);
 	}
 
-	public void runE(PreData predata, int n) {
+	public void runE(PreData predata, int n, Timer timer) {
+		timer.start(P.IOT, M.offline_comp);
+
 		predata.ssiot_k = PRF.generateKey(Crypto.sr);
 		predata.ssiot_kprime = PRF.generateKey(Crypto.sr);
 		predata.ssiot_r = Util.nextBytes(Crypto.secParamBytes, Crypto.sr);
 
+		timer.start(P.IOT, M.offline_write);
 		con1.write(predata.ssiot_k);
 		con1.write(predata.ssiot_kprime);
 		con1.write(predata.ssiot_r);
+		timer.stop(P.IOT, M.offline_write);
+
+		timer.stop(P.IOT, M.offline_comp);
 	}
 
-	public void runD(PreData predata) {
+	public void runD(PreData predata, Timer timer) {
+		timer.start(P.IOT, M.offline_read);
 		predata.ssiot_k = con1.read();
 		predata.ssiot_kprime = con1.read();
 		predata.ssiot_r = con1.read();
+		timer.stop(P.IOT, M.offline_read);
 	}
 
 	public void runC() {

+ 22 - 22
src/protocols/SSCOT.java

@@ -8,7 +8,7 @@ import exceptions.NoSuchPartyException;
 import exceptions.SSCOTException;
 import measure.M;
 import measure.P;
-import measure.Timing;
+import measure.Timer;
 import oram.Forest;
 import oram.Metadata;
 import util.Util;
@@ -18,8 +18,8 @@ public class SSCOT extends Protocol {
 		super(con1, con2);
 	}
 
-	public void runE(PreData predata, byte[][] m, byte[][] a, Timing time) {
-		time.start(P.COT, M.online_comp);
+	public void runE(PreData predata, byte[][] m, byte[][] a, Timer timer) {
+		timer.start(P.COT, M.online_comp);
 
 		// step 1
 		int n = m.length;
@@ -41,16 +41,16 @@ public class SSCOT extends Protocol {
 			v[i] = F_kprime.compute(x[i]);
 		}
 
-		time.start(P.COT, M.online_write);
+		timer.start(P.COT, M.online_write);
 		con2.write(e);
 		con2.write(v);
-		time.stop(P.COT, M.online_write);
+		timer.stop(P.COT, M.online_write);
 
-		time.stop(P.COT, M.online_comp);
+		timer.stop(P.COT, M.online_comp);
 	}
 
-	public void runD(PreData predata, byte[][] b, Timing time) {
-		time.start(P.COT, M.online_comp);
+	public void runD(PreData predata, byte[][] b, Timer timer) {
+		timer.start(P.COT, M.online_comp);
 
 		// step 2
 		int n = b.length;
@@ -70,26 +70,26 @@ public class SSCOT extends Protocol {
 			w[i] = F_kprime.compute(y[i]);
 		}
 
-		time.start(P.COT, M.online_write);
+		timer.start(P.COT, M.online_write);
 		con2.write(p);
 		con2.write(w);
-		time.stop(P.COT, M.online_write);
+		timer.stop(P.COT, M.online_write);
 
-		time.stop(P.COT, M.online_comp);
+		timer.stop(P.COT, M.online_comp);
 	}
 
-	public OutSSCOT runC(Timing time) {
-		time.start(P.COT, M.online_comp);
+	public OutSSCOT runC(Timer timer) {
+		timer.start(P.COT, M.online_comp);
 
 		// step 1
-		time.start(P.COT, M.online_read);
+		timer.start(P.COT, M.online_read);
 		byte[][] e = con1.readObject();
 		byte[][] v = con1.readObject();
 
 		// step 2
 		byte[][] p = con2.readObject();
 		byte[][] w = con2.readObject();
-		time.stop(P.COT, M.online_read);
+		timer.stop(P.COT, M.online_read);
 
 		// step 3
 		int n = e.length;
@@ -109,13 +109,13 @@ public class SSCOT extends Protocol {
 		if (invariant != 1)
 			throw new SSCOTException("Invariant error: " + invariant);
 
-		time.stop(P.COT, M.online_comp);
+		timer.stop(P.COT, M.online_comp);
 		return output;
 	}
 
 	@Override
 	public void run(Party party, Metadata md, Forest forest) {
-		Timing time = new Timing();
+		Timer timer = new Timer();
 
 		for (int j = 0; j < 100; j++) {
 			int n = 100;
@@ -140,19 +140,19 @@ public class SSCOT extends Protocol {
 				con1.write(b);
 				con2.write(m);
 				con2.write(index);
-				presscot.runE(predata, n);
-				runE(predata, m, a, time);
+				presscot.runE(predata, n, timer);
+				runE(predata, m, a, timer);
 
 			} else if (party == Party.Debbie) {
 				b = con1.readObject();
-				presscot.runD(predata);
-				runD(predata, b, time);
+				presscot.runD(predata, timer);
+				runD(predata, b, timer);
 
 			} else if (party == Party.Charlie) {
 				m = con1.readObject();
 				index = con1.readObject();
 				presscot.runC();
-				OutSSCOT output = runC(time);
+				OutSSCOT output = runC(timer);
 				if (output.t == index && Util.equal(output.m_t, m[index]))
 					System.out.println("SSCOT test passed");
 				else

+ 22 - 22
src/protocols/SSIOT.java

@@ -8,7 +8,7 @@ import exceptions.NoSuchPartyException;
 import exceptions.SSIOTException;
 import measure.M;
 import measure.P;
-import measure.Timing;
+import measure.Timer;
 import oram.Forest;
 import oram.Metadata;
 import util.Util;
@@ -18,8 +18,8 @@ public class SSIOT extends Protocol {
 		super(con1, con2);
 	}
 
-	public void runE(PreData predata, byte[][] y, byte[] Nip1_pr, Timing time) {
-		time.start(P.IOT, M.online_comp);
+	public void runE(PreData predata, byte[][] y, byte[] Nip1_pr, Timer timer) {
+		timer.start(P.IOT, M.online_comp);
 
 		// step 1
 		int n = y.length;
@@ -43,16 +43,16 @@ public class SSIOT extends Protocol {
 			v[i] = F_kprime.compute(x[i]);
 		}
 
-		time.start(P.IOT, M.online_write);
+		timer.start(P.IOT, M.online_write);
 		con2.write(e);
 		con2.write(v);
-		time.stop(P.IOT, M.online_write);
+		timer.stop(P.IOT, M.online_write);
 
-		time.stop(P.IOT, M.online_comp);
+		timer.stop(P.IOT, M.online_comp);
 	}
 
-	public void runD(PreData predata, byte[] Nip1_pr, Timing time) {
-		time.start(P.IOT, M.online_comp);
+	public void runD(PreData predata, byte[] Nip1_pr, Timer timer) {
+		timer.start(P.IOT, M.online_comp);
 
 		// step 2
 		PRF F_k = new PRF(Crypto.secParam);
@@ -66,26 +66,26 @@ public class SSIOT extends Protocol {
 		byte[] p = F_k.compute(y);
 		byte[] w = F_kprime.compute(y);
 
-		time.start(P.IOT, M.online_write);
+		timer.start(P.IOT, M.online_write);
 		con2.write(p);
 		con2.write(w);
-		time.stop(P.IOT, M.online_write);
+		timer.stop(P.IOT, M.online_write);
 
-		time.stop(P.IOT, M.online_comp);
+		timer.stop(P.IOT, M.online_comp);
 	}
 
-	public OutSSIOT runC(Timing time) {
-		time.start(P.IOT, M.online_comp);
+	public OutSSIOT runC(Timer timer) {
+		timer.start(P.IOT, M.online_comp);
 
 		// step 1
-		time.start(P.IOT, M.online_read);
+		timer.start(P.IOT, M.online_read);
 		byte[][] e = con1.readObject();
 		byte[][] v = con1.readObject();
 
 		// step 2
 		byte[] p = con2.read();
 		byte[] w = con2.read();
-		time.stop(P.IOT, M.online_read);
+		timer.stop(P.IOT, M.online_read);
 
 		// step 3
 		int n = e.length;
@@ -105,13 +105,13 @@ public class SSIOT extends Protocol {
 		if (invariant != 1)
 			throw new SSIOTException("Invariant error: " + invariant);
 
-		time.stop(P.IOT, M.online_comp);
+		timer.stop(P.IOT, M.online_comp);
 		return output;
 	}
 
 	@Override
 	public void run(Party party, Metadata md, Forest forest) {
-		Timing time = new Timing();
+		Timer timer = new Timer();
 
 		for (int j = 0; j < 100; j++) {
 			int twoTauPow = 64;
@@ -132,19 +132,19 @@ public class SSIOT extends Protocol {
 				con1.write(sD_Nip1_pr);
 				con2.write(y);
 				con2.write(index);
-				pressiot.runE(predata, twoTauPow);
-				runE(predata, y, sE_Nip1_pr, time);
+				pressiot.runE(predata, twoTauPow, timer);
+				runE(predata, y, sE_Nip1_pr, timer);
 
 			} else if (party == Party.Debbie) {
 				sD_Nip1_pr = con1.read();
-				pressiot.runD(predata);
-				runD(predata, sD_Nip1_pr, time);
+				pressiot.runD(predata, timer);
+				runD(predata, sD_Nip1_pr, timer);
 
 			} else if (party == Party.Charlie) {
 				y = con1.readObject();
 				index = con1.readObject();
 				pressiot.runC();
-				OutSSIOT output = runC(time);
+				OutSSIOT output = runC(timer);
 				if (output.t == index && Util.equal(output.m_t, y[index]))
 					System.out.println("SSIOT test passed");
 				else