Browse Source

continue removing PreData and Timer

Boyoung- 6 years ago
parent
commit
0db5414f60
4 changed files with 307 additions and 441 deletions
  1. 0 276
      src/pir/PIREviction.java
  2. 99 94
      src/pir/PIRRetrieve.java
  3. 1 1
      src/pir/ULiT.java
  4. 207 70
      src/protocols/Eviction.java

+ 0 - 276
src/pir/PIREviction.java

@@ -1,276 +0,0 @@
-package pir;
-
-import java.math.BigInteger;
-import java.util.Arrays;
-
-import com.oblivm.backend.gc.GCSignal;
-
-import communication.Communication;
-import gc.GCUtil;
-import oram.Bucket;
-import oram.Forest;
-import oram.Metadata;
-import oram.Tree;
-import oram.Tuple;
-import protocols.PermuteIndex;
-import protocols.PermuteTarget;
-import protocols.Protocol;
-import protocols.SSXOT;
-import protocols.struct.Party;
-import protocols.struct.PreData;
-import util.M;
-import util.P;
-import util.Timer;
-import util.Util;
-
-public class PIREviction extends Protocol {
-
-	private int pid = P.EVI;
-
-	public PIREviction(Communication con1, Communication con2) {
-		super(con1, con2);
-	}
-
-	private int[] prepareEviction(int target[], int[] ti, int W) {
-		int d = ti.length;
-		int[] evict = new int[W * d];
-		for (int r = 0; r < d; r++) {
-			int tupleIndex = r * W + ti[r];
-			for (int c = 0; c < W; c++) {
-				int currIndex = r * W + c;
-				if (currIndex == tupleIndex) {
-					int targetIndex = target[r] * W + ti[target[r]];
-					evict[targetIndex] = currIndex;
-				} else
-					evict[currIndex] = currIndex;
-			}
-		}
-		return evict;
-	}
-
-	public void runE(PreData predata, boolean firstTree, byte[] Li, Tuple[] originalPath, Tree OTi, Timer timer) {
-		timer.start(pid, M.online_comp);
-
-		if (firstTree) {
-			OTi.setBucketsOnPath(new BigInteger(1, Li).longValue(), new Bucket[] { new Bucket(originalPath) });
-			timer.stop(pid, M.online_comp);
-			return;
-		}
-
-		int d = OTi.getD();
-		int sw = OTi.getStashSize();
-		int w = OTi.getW();
-		Tuple[] pathTuples = new Tuple[d * w];
-		System.arraycopy(originalPath, 0, pathTuples, 0, w);
-		System.arraycopy(originalPath, sw, pathTuples, w, (d - 1) * w);
-
-		Bucket[] pathBuckets = Bucket.tuplesToBuckets(pathTuples, d, w, w);
-
-		GCSignal[] LiInputKeys = GCUtil.revSelectKeys(predata.evict_LiKeyPairs, Li);
-		GCSignal[][] E_feInputKeys = new GCSignal[d][];
-		GCSignal[][][] E_labelInputKeys = new GCSignal[d][][];
-		GCSignal[][] deltaInputKeys = new GCSignal[d][];
-		for (int i = 0; i < d; i++) {
-			E_feInputKeys[i] = GCUtil.selectFeKeys(predata.evict_E_feKeyPairs[i], pathBuckets[i].getTuples());
-			E_labelInputKeys[i] = GCUtil.selectLabelKeys(predata.evict_E_labelKeyPairs[i], pathBuckets[i].getTuples());
-			deltaInputKeys[i] = GCUtil.revSelectKeys(predata.evict_deltaKeyPairs[i], predata.evict_delta[i]);
-		}
-
-		timer.start(pid, M.online_write);
-		con1.write(pid, LiInputKeys);
-		con1.write(pid, E_feInputKeys);
-		con1.write(pid, E_labelInputKeys);
-		con1.write(pid, deltaInputKeys);
-		timer.stop(pid, M.online_write);
-
-		PermuteTarget permutetarget = new PermuteTarget(con1, con2);
-		permutetarget.runE();
-
-		PermuteIndex permuteindex = new PermuteIndex(con1, con2);
-		permuteindex.runE();
-
-		int logW = (int) Math.ceil(Math.log(w + 1) / Math.log(2));
-		int W = (int) Math.pow(2, logW);
-		for (int i = 0; i < d; i++) {
-			pathBuckets[i].expand(W);
-			pathBuckets[i].permute(predata.evict_delta_p[i]);
-		}
-		pathBuckets = Util.permute(pathBuckets, predata.evict_pi);
-		for (int i = 0; i < d; i++) {
-			pathBuckets[i].permute(predata.evict_rho_p[i]);
-		}
-		pathTuples = Bucket.bucketsToTuples(pathBuckets);
-
-		SSXOT ssxot = new SSXOT(con1, con2, 1);
-		pathTuples = ssxot.runE(predata, pathTuples, timer);
-
-		pathBuckets = Bucket.tuplesToBuckets(pathTuples, d, W, W);
-		for (int i = 0; i < d; i++) {
-			int[] rho_ivs = Util.inversePermutation(predata.evict_rho_p[i]);
-			pathBuckets[i].permute(rho_ivs);
-		}
-		int[] pi_ivs = Util.inversePermutation(predata.evict_pi);
-		pathBuckets = Util.permute(pathBuckets, pi_ivs);
-		for (int i = 0; i < d; i++) {
-			int[] delta_ivs = Util.inversePermutation(predata.evict_delta_p[i]);
-			pathBuckets[i].permute(delta_ivs);
-			pathBuckets[i].shrink(w);
-		}
-
-		pathBuckets[0].expand(Arrays.copyOfRange(originalPath, w, sw));
-
-		timer.start(pid, M.online_write);
-		con2.write(pid, pathBuckets);
-		timer.stop(pid, M.online_write);
-
-		timer.start(pid, M.online_read);
-		con2.readBucketArray(pid);
-		timer.stop(pid, M.online_read);
-
-		// OTi.setBucketsOnPath(new BigInteger(1, Li).longValue(), pathBuckets);
-
-		timer.stop(pid, M.online_comp);
-	}
-
-	public void runD(PreData predata, boolean firstTree, byte[] Li, Tree OTi, Timer timer) {
-		timer.start(pid, M.online_comp);
-
-		if (firstTree) {
-			timer.start(pid, M.online_read);
-			Tuple[] originalPath = con2.readTupleArray(pid);
-			timer.stop(pid, M.online_read);
-
-			OTi.setBucketsOnPath(new BigInteger(1, Li).longValue(), new Bucket[] { new Bucket(originalPath) });
-
-			timer.stop(pid, M.online_comp);
-			return;
-		}
-
-		timer.start(pid, M.online_read);
-		GCSignal[] LiInputKeys = con1.readGCSignalArray(pid);
-		GCSignal[][] E_feInputKeys = con1.readDoubleGCSignalArray(pid);
-		GCSignal[][][] E_labelInputKeys = con1.readTripleGCSignalArray(pid);
-		GCSignal[][] deltaInputKeys = con1.readDoubleGCSignalArray(pid);
-
-		GCSignal[][] C_feInputKeys = con2.readDoubleGCSignalArray(pid);
-		GCSignal[][][] C_labelInputKeys = con2.readTripleGCSignalArray(pid);
-		timer.stop(pid, M.online_read);
-
-		int w = OTi.getW();
-		int logW = (int) Math.ceil(Math.log(w + 1) / Math.log(2));
-
-		GCSignal[][][] outKeys = predata.evict_gcroute.routing(LiInputKeys, E_feInputKeys, C_feInputKeys,
-				E_labelInputKeys, C_labelInputKeys, deltaInputKeys);
-
-		byte[][] ti_p = new byte[deltaInputKeys.length][];
-		for (int i = 0; i < ti_p.length; i++) {
-			ti_p[i] = Util.padArray(GCUtil.evaOutKeys(outKeys[1][i], predata.evict_tiOutKeyHashes[i]).toByteArray(),
-					(logW + 7) / 8);
-		}
-
-		PermuteTarget permutetarget = new PermuteTarget(con1, con2);
-		int[] target_pp = permutetarget.runD(predata, firstTree, outKeys[0], timer);
-
-		PermuteIndex permuteindex = new PermuteIndex(con1, con2);
-		int[] ti_pp = permuteindex.runD(predata, firstTree, ti_p, w, timer);
-
-		int W = (int) Math.pow(2, logW);
-		int[] evict = prepareEviction(target_pp, ti_pp, W);
-
-		SSXOT ssxot = new SSXOT(con1, con2, 1);
-		ssxot.runD(predata, evict, timer);
-
-		// timer.start(pid, M.online_read);
-		// Bucket[] pathBuckets = con2.readBucketArray(pid);
-		// timer.stop(pid, M.online_read);
-
-		// OTi.setBucketsOnPath(new BigInteger(1, Li).longValue(), pathBuckets);
-
-		timer.stop(pid, M.online_comp);
-	}
-
-	public void runC(PreData predata, boolean firstTree, Tuple[] originalPath, int d, int sw, int w, Timer timer) {
-		if (firstTree) {
-			timer.start(pid, M.online_write);
-			con2.write(pid, originalPath);
-			timer.stop(pid, M.online_write);
-			return;
-		}
-
-		timer.start(pid, M.online_comp);
-
-		Tuple[] pathTuples = new Tuple[d * w];
-		System.arraycopy(originalPath, 0, pathTuples, 0, w);
-		System.arraycopy(originalPath, sw, pathTuples, w, (d - 1) * w);
-
-		Bucket[] pathBuckets = Bucket.tuplesToBuckets(pathTuples, d, w, w);
-
-		GCSignal[][] C_feInputKeys = new GCSignal[d][];
-		GCSignal[][][] C_labelInputKeys = new GCSignal[d][][];
-		for (int i = 0; i < d; i++) {
-			C_feInputKeys[i] = GCUtil.selectFeKeys(predata.evict_C_feKeyPairs[i], pathBuckets[i].getTuples());
-			C_labelInputKeys[i] = GCUtil.selectLabelKeys(predata.evict_C_labelKeyPairs[i], pathBuckets[i].getTuples());
-		}
-
-		timer.start(pid, M.online_write);
-		con2.write(pid, C_feInputKeys);
-		con2.write(pid, C_labelInputKeys);
-		timer.stop(pid, M.online_write);
-
-		PermuteTarget permutetarget = new PermuteTarget(con1, con2);
-		permutetarget.runC(predata, firstTree, timer);
-
-		PermuteIndex permuteindex = new PermuteIndex(con1, con2);
-		permuteindex.runC(predata, firstTree, timer);
-
-		int logW = (int) Math.ceil(Math.log(w + 1) / Math.log(2));
-		int W = (int) Math.pow(2, logW);
-		for (int i = 0; i < d; i++) {
-			pathBuckets[i].expand(W);
-			pathBuckets[i].permute(predata.evict_delta_p[i]);
-		}
-		pathBuckets = Util.permute(pathBuckets, predata.evict_pi);
-		for (int i = 0; i < d; i++) {
-			pathBuckets[i].permute(predata.evict_rho_p[i]);
-		}
-		pathTuples = Bucket.bucketsToTuples(pathBuckets);
-
-		SSXOT ssxot = new SSXOT(con1, con2, 1);
-		pathTuples = ssxot.runC(predata, pathTuples, timer);
-
-		pathBuckets = Bucket.tuplesToBuckets(pathTuples, d, W, W);
-		for (int i = 0; i < d; i++) {
-			int[] rho_ivs = Util.inversePermutation(predata.evict_rho_p[i]);
-			pathBuckets[i].permute(rho_ivs);
-		}
-		int[] pi_ivs = Util.inversePermutation(predata.evict_pi);
-		pathBuckets = Util.permute(pathBuckets, pi_ivs);
-		for (int i = 0; i < d; i++) {
-			int[] delta_ivs = Util.inversePermutation(predata.evict_delta_p[i]);
-			pathBuckets[i].permute(delta_ivs);
-			pathBuckets[i].shrink(w);
-		}
-
-		pathBuckets[0].expand(Arrays.copyOfRange(originalPath, w, sw));
-
-		timer.start(pid, M.online_write);
-		con1.write(pid, pathBuckets);
-		timer.stop(pid, M.online_write);
-
-		timer.start(pid, M.online_read);
-		con1.readBucketArray(pid);
-		timer.stop(pid, M.online_read);
-
-		timer.stop(pid, M.online_comp);
-	}
-
-	@Override
-	public void run(Party party, Metadata md, Forest[] forest) {
-		System.out.println("Use PIRRetrieve to test PIREviction");
-	}
-
-	@Override
-	public void run(Party party, Metadata md, Forest forest) {
-		System.out.println("Use Retrieve to test Eviction");
-	}
-}

+ 99 - 94
src/pir/PIRRetrieve.java

@@ -4,16 +4,16 @@ import java.math.BigInteger;
 import java.util.Arrays;
 
 import communication.Communication;
+import crypto.Crypto;
 import exceptions.NoSuchPartyException;
 import oram.Forest;
+import oram.Global;
 import oram.Metadata;
 import oram.Tree;
 import oram.Tuple;
 import protocols.Eviction;
 import protocols.Protocol;
 import protocols.UpdateRoot;
-import protocols.precomputation.PreEviction;
-import protocols.precomputation.PreUpdateRoot;
 import protocols.struct.OutFF;
 import protocols.struct.OutPIRAccess;
 import protocols.struct.OutULiT;
@@ -21,9 +21,7 @@ import protocols.struct.Party;
 import protocols.struct.PreData;
 import protocols.struct.TwoThreeXorByte;
 import protocols.struct.TwoThreeXorInt;
-import util.Bandwidth;
 import util.M;
-import util.P;
 import util.StopWatch;
 import util.Timer;
 import util.Util;
@@ -32,8 +30,6 @@ import util.Util;
 
 public class PIRRetrieve extends Protocol {
 
-	private int pid = P.PIRRtv;
-
 	Communication[] cons1;
 	Communication[] cons2;
 
@@ -47,22 +43,22 @@ public class PIRRetrieve extends Protocol {
 	}
 
 	public OutPIRAccess runE(Metadata md, PreData predata, Tree tree_DE, Tree tree_CE, byte[] Li, TwoThreeXorByte L,
-			TwoThreeXorByte N, TwoThreeXorInt dN, Timer timer) {
-		timer.start(pid, M.online_comp);
+			TwoThreeXorByte N, TwoThreeXorInt dN) {
+		timer.start(M.online_comp);
 
 		int treeIndex = tree_DE.getTreeIndex();
 		boolean isLastTree = treeIndex == md.getNumTrees() - 1;
 		boolean isFirstTree = treeIndex == 0;
 
 		PIRAccess piracc = new PIRAccess(con1, con2);
-		OutPIRAccess outpiracc = piracc.runE(md, predata, tree_DE, tree_CE, Li, L, N, dN, timer);
+		OutPIRAccess outpiracc = piracc.runE(md, tree_DE, tree_CE, Li, L, N, dN);
 
 		OutULiT T = new OutULiT();
 		if (!isLastTree) {
 			TwoThreeXorByte Lp = new TwoThreeXorByte(md.getLBytesOfTree(treeIndex));
 			TwoThreeXorByte Lpi = new TwoThreeXorByte(md.getLBytesOfTree(treeIndex + 1));
-			ULiT ulit = new ULiT(con1, con2);
-			T = ulit.runE(predata, outpiracc.X, N, dN, Lp, Lpi, outpiracc.nextL, md.getTwoTauPow(), timer);
+			ULiT ulit = new ULiT(con1, con2, Crypto.sr_DE, Crypto.sr_CE);
+			T = ulit.runE(outpiracc.X, N, dN, Lp, Lpi, outpiracc.nextL, md.getTwoTauPow());
 		} else {
 			T.DE = outpiracc.pathTuples_DE[0];
 			T.CE = outpiracc.pathTuples_CE[0];
@@ -78,7 +74,7 @@ public class PIRRetrieve extends Protocol {
 				fb_CE[i] = outpiracc.pathTuples_CE[i].getF();
 			}
 			FlipFlag ff = new FlipFlag(con1, con2);
-			OutFF outff = ff.runE(predata, fb_DE, fb_CE, outpiracc.j.s_DE, timer);
+			OutFF outff = ff.runE(fb_DE, fb_CE, outpiracc.j.s_DE);
 			for (int i = 0; i < pathTuples; i++) {
 				// outpiracc.pathTuples_DE[i].setF(outff.fb_DE[i]);
 				// outpiracc.pathTuples_CE[i].setF(outff.fb_CE[i]);
@@ -86,8 +82,11 @@ public class PIRRetrieve extends Protocol {
 		}
 
 		int stashSize = tree_DE.getStashSize();
-		PreUpdateRoot preupdateroot = new PreUpdateRoot(con1, con2);
-		preupdateroot.runE(predata, isFirstTree, stashSize, md.getLBitsOfTree(treeIndex), timer);
+		int[] tupleParam = new int[] { treeIndex == 0 ? 0 : 1, md.getNBytesOfTree(treeIndex),
+				md.getLBytesOfTree(treeIndex), md.getABytesOfTree(treeIndex) };
+		// PreUpdateRoot preupdateroot = new PreUpdateRoot(con1, con2);
+		// preupdateroot.runE(predata, isFirstTree, stashSize,
+		// md.getLBitsOfTree(treeIndex), timer);
 
 		Tuple[] path = new Tuple[pathTuples];
 		for (int i = 0; i < pathTuples; i++) {
@@ -95,68 +94,71 @@ public class PIRRetrieve extends Protocol {
 		}
 		Tuple[] R = Arrays.copyOfRange(path, 0, stashSize);
 		UpdateRoot updateroot = new UpdateRoot(con1, con2);
-		R = updateroot.runE(predata, isFirstTree, Li, R, T.DE.xor(T.CE), timer);
+		R = updateroot.runE(isFirstTree, stashSize, md.getLBitsOfTree(treeIndex), tupleParam, Li, R, T.DE.xor(T.CE));
 		System.arraycopy(R, 0, path, 0, R.length);
 
-		PreEviction preeviction = new PreEviction(con1, con2);
-		preeviction.runE(predata, isFirstTree, tree_DE.getD(), tree_DE.getW(), timer);
+		// PreEviction preeviction = new PreEviction(con1, con2);
+		// preeviction.runE(predata, isFirstTree, tree_DE.getD(), tree_DE.getW(),
+		// timer);
 
 		Eviction eviction = new Eviction(con1, con2);
-		eviction.runE(predata, isFirstTree, Li, path, tree_DE, timer);
+		eviction.runE(predata, isFirstTree, tupleParam, Li, path, tree_DE);
 
 		// simulation of Reshare
-		timer.start(pid, M.online_write);
-		con2.write(pid, path);
-		timer.stop(pid, M.online_write);
+		timer.start(M.online_write);
+		con2.write(online_band, path);
+		timer.stop(M.online_write);
 
-		timer.start(pid, M.online_read);
-		con2.readTupleArray(pid);
-		timer.stop(pid, M.online_read);
+		timer.start(M.online_read);
+		con2.readTupleArrayAndDec();
+		timer.stop(M.online_read);
 
 		// second eviction sim
-		preupdateroot.runE(predata, isFirstTree, stashSize, md.getLBitsOfTree(treeIndex), timer);
+		// preupdateroot.runE(predata, isFirstTree, stashSize,
+		// md.getLBitsOfTree(treeIndex), timer);
 
 		for (int i = 0; i < pathTuples; i++) {
 			path[i] = outpiracc.pathTuples_DE[i].xor(outpiracc.pathTuples_CE[i]);
 		}
 		R = Arrays.copyOfRange(path, 0, stashSize);
-		R = updateroot.runE(predata, isFirstTree, Li, R, T.DE.xor(T.CE), timer);
+		R = updateroot.runE(isFirstTree, stashSize, md.getLBitsOfTree(treeIndex), tupleParam, Li, R, T.DE.xor(T.CE));
 		System.arraycopy(R, 0, path, 0, R.length);
 
-		preeviction.runE(predata, isFirstTree, tree_DE.getD(), tree_DE.getW(), timer);
+		// preeviction.runE(predata, isFirstTree, tree_DE.getD(), tree_DE.getW(),
+		// timer);
 
-		eviction.runE(predata, isFirstTree, Li, path, tree_DE, timer);
+		eviction.runE(predata, isFirstTree, tupleParam, Li, path, tree_DE);
 
 		// simulation of Reshare
-		timer.start(pid, M.online_write);
-		con2.write(pid, path);
-		timer.stop(pid, M.online_write);
+		timer.start(M.online_write);
+		con2.write(online_band, path);
+		timer.stop(M.online_write);
 
-		timer.start(pid, M.online_read);
-		con2.readTupleArray(pid);
-		timer.stop(pid, M.online_read);
+		timer.start(M.online_read);
+		con2.readTupleArrayAndDec();
+		timer.stop(M.online_read);
 
-		timer.stop(pid, M.online_comp);
+		timer.stop(M.online_comp);
 		return outpiracc;
 	}
 
 	public OutPIRAccess runD(Metadata md, PreData predata, Tree tree_DE, Tree tree_CD, byte[] Li, TwoThreeXorByte L,
-			TwoThreeXorByte N, TwoThreeXorInt dN, Timer timer) {
-		timer.start(pid, M.online_comp);
+			TwoThreeXorByte N, TwoThreeXorInt dN) {
+		timer.start(M.online_comp);
 
 		int treeIndex = tree_DE.getTreeIndex();
 		boolean isLastTree = treeIndex == md.getNumTrees() - 1;
 		boolean isFirstTree = treeIndex == 0;
 
 		PIRAccess piracc = new PIRAccess(con1, con2);
-		OutPIRAccess outpiracc = piracc.runD(md, predata, tree_DE, tree_CD, Li, L, N, dN, timer);
+		OutPIRAccess outpiracc = piracc.runD(md, tree_DE, tree_CD, Li, L, N, dN);
 
 		OutULiT T = new OutULiT();
 		if (!isLastTree) {
 			TwoThreeXorByte Lp = new TwoThreeXorByte(md.getLBytesOfTree(treeIndex));
 			TwoThreeXorByte Lpi = new TwoThreeXorByte(md.getLBytesOfTree(treeIndex + 1));
-			ULiT ulit = new ULiT(con1, con2);
-			T = ulit.runD(predata, outpiracc.X, N, dN, Lp, Lpi, outpiracc.nextL, md.getTwoTauPow(), timer);
+			ULiT ulit = new ULiT(con1, con2, Crypto.sr_DE, Crypto.sr_CD);
+			T = ulit.runD(outpiracc.X, N, dN, Lp, Lpi, outpiracc.nextL, md.getTwoTauPow());
 		} else {
 			T.CD = outpiracc.pathTuples_CD[0];
 			T.DE = outpiracc.pathTuples_DE[0];
@@ -172,7 +174,7 @@ public class PIRRetrieve extends Protocol {
 				fb_CD[i] = outpiracc.pathTuples_CD[i].getF();
 			}
 			FlipFlag ff = new FlipFlag(con1, con2);
-			OutFF outff = ff.runD(predata, fb_DE, fb_CD, outpiracc.j.s_DE, timer);
+			OutFF outff = ff.runD(fb_DE, fb_CD, outpiracc.j.s_DE);
 			for (int i = 0; i < pathTuples; i++) {
 				// outpiracc.pathTuples_DE[i].setF(outff.fb_DE[i]);
 				// outpiracc.pathTuples_CD[i].setF(outff.fb_CD[i]);
@@ -182,48 +184,52 @@ public class PIRRetrieve extends Protocol {
 		int stashSize = tree_DE.getStashSize();
 		int[] tupleParam = new int[] { treeIndex == 0 ? 0 : 1, md.getNBytesOfTree(treeIndex),
 				md.getLBytesOfTree(treeIndex), md.getABytesOfTree(treeIndex) };
-		PreUpdateRoot preupdateroot = new PreUpdateRoot(con1, con2);
-		preupdateroot.runD(predata, isFirstTree, stashSize, md.getLBitsOfTree(treeIndex), tupleParam, timer);
+		// PreUpdateRoot preupdateroot = new PreUpdateRoot(con1, con2);
+		// preupdateroot.runD(predata, isFirstTree, stashSize,
+		// md.getLBitsOfTree(treeIndex), tupleParam, timer);
 
 		UpdateRoot updateroot = new UpdateRoot(con1, con2);
-		updateroot.runD(predata, isFirstTree, Li, tree_DE.getW(), timer);
+		updateroot.runD(isFirstTree, stashSize, md.getLBitsOfTree(treeIndex), tupleParam, Li, tree_DE.getW());
 
-		PreEviction preeviction = new PreEviction(con1, con2);
-		preeviction.runD(predata, isFirstTree, tree_DE.getD(), tree_DE.getW(), tupleParam, timer);
+		// PreEviction preeviction = new PreEviction(con1, con2);
+		// preeviction.runD(predata, isFirstTree, tree_DE.getD(), tree_DE.getW(),
+		// tupleParam, timer);
 
 		Eviction eviction = new Eviction(con1, con2);
-		eviction.runD(predata, isFirstTree, Li, tree_DE, timer);
+		eviction.runD(predata, isFirstTree, tupleParam, Li, tree_DE);
 
 		// second eviction sim
-		preupdateroot.runD(predata, isFirstTree, stashSize, md.getLBitsOfTree(treeIndex), tupleParam, timer);
+		// preupdateroot.runD(predata, isFirstTree, stashSize,
+		// md.getLBitsOfTree(treeIndex), tupleParam, timer);
 
-		updateroot.runD(predata, isFirstTree, Li, tree_DE.getW(), timer);
+		updateroot.runD(isFirstTree, stashSize, md.getLBitsOfTree(treeIndex), tupleParam, Li, tree_DE.getW());
 
-		preeviction.runD(predata, isFirstTree, tree_DE.getD(), tree_DE.getW(), tupleParam, timer);
+		// preeviction.runD(predata, isFirstTree, tree_DE.getD(), tree_DE.getW(),
+		// tupleParam, timer);
 
-		eviction.runD(predata, isFirstTree, Li, tree_DE, timer);
+		eviction.runD(predata, isFirstTree, tupleParam, Li, tree_DE);
 
-		timer.stop(pid, M.online_comp);
+		timer.stop(M.online_comp);
 		return outpiracc;
 	}
 
 	public OutPIRAccess runC(Metadata md, PreData predata, Tree tree_CD, Tree tree_CE, byte[] Li, TwoThreeXorByte L,
-			TwoThreeXorByte N, TwoThreeXorInt dN, Timer timer) {
-		timer.start(pid, M.online_comp);
+			TwoThreeXorByte N, TwoThreeXorInt dN) {
+		timer.start(M.online_comp);
 
 		int treeIndex = tree_CE.getTreeIndex();
 		boolean isLastTree = treeIndex == md.getNumTrees() - 1;
 		boolean isFirstTree = treeIndex == 0;
 
 		PIRAccess piracc = new PIRAccess(con1, con2);
-		OutPIRAccess outpiracc = piracc.runC(md, predata, tree_CD, tree_CE, Li, L, N, dN, timer);
+		OutPIRAccess outpiracc = piracc.runC(md, tree_CD, tree_CE, Li, L, N, dN);
 
 		OutULiT T = new OutULiT();
 		if (!isLastTree) {
 			TwoThreeXorByte Lp = new TwoThreeXorByte(md.getLBytesOfTree(treeIndex));
 			TwoThreeXorByte Lpi = new TwoThreeXorByte(md.getLBytesOfTree(treeIndex + 1));
-			ULiT ulit = new ULiT(con1, con2);
-			T = ulit.runC(predata, outpiracc.X, N, dN, Lp, Lpi, outpiracc.nextL, md.getTwoTauPow(), timer);
+			ULiT ulit = new ULiT(con1, con2, Crypto.sr_CE, Crypto.sr_CD);
+			T = ulit.runC(outpiracc.X, N, dN, Lp, Lpi, outpiracc.nextL, md.getTwoTauPow());
 		} else {
 			T.CD = outpiracc.pathTuples_CD[0];
 			T.CE = outpiracc.pathTuples_CE[0];
@@ -239,7 +245,7 @@ public class PIRRetrieve extends Protocol {
 				fb_CD[i] = outpiracc.pathTuples_CD[i].getF();
 			}
 			FlipFlag ff = new FlipFlag(con1, con2);
-			OutFF outff = ff.runC(predata, fb_CD, fb_CE, outpiracc.j.t_C, timer);
+			OutFF outff = ff.runC(fb_CD, fb_CE, outpiracc.j.t_C);
 			for (int i = 0; i < pathTuples; i++) {
 				// outpiracc.pathTuples_CD[i].setF(outff.fb_CD[i]);
 				// outpiracc.pathTuples_CE[i].setF(outff.fb_CE[i]);
@@ -247,53 +253,55 @@ public class PIRRetrieve extends Protocol {
 		}
 
 		int stashSize = tree_CE.getStashSize();
-		PreUpdateRoot preupdateroot = new PreUpdateRoot(con1, con2);
-		preupdateroot.runC(predata, isFirstTree, timer);
+		int[] tupleParam = new int[] { treeIndex == 0 ? 0 : 1, md.getNBytesOfTree(treeIndex),
+				md.getLBytesOfTree(treeIndex), md.getABytesOfTree(treeIndex) };
+		// PreUpdateRoot preupdateroot = new PreUpdateRoot(con1, con2);
+		// preupdateroot.runC(predata, isFirstTree, timer);
 
 		Tuple[] path = outpiracc.pathTuples_CD;
 		Tuple[] R = Arrays.copyOfRange(path, 0, stashSize);
 
 		UpdateRoot updateroot = new UpdateRoot(con1, con2);
-		R = updateroot.runC(predata, isFirstTree, R, T.CD, timer);
+		R = updateroot.runC(isFirstTree, tupleParam, R, T.CD);
 		System.arraycopy(R, 0, path, 0, R.length);
 
-		PreEviction preeviction = new PreEviction(con1, con2);
-		preeviction.runC(predata, isFirstTree, timer);
+		// PreEviction preeviction = new PreEviction(con1, con2);
+		// preeviction.runC(predata, isFirstTree, timer);
 
 		Eviction eviction = new Eviction(con1, con2);
-		eviction.runC(predata, isFirstTree, path, tree_CD.getD(), stashSize, tree_CD.getW(), timer);
+		eviction.runC(predata, isFirstTree, tupleParam, path, tree_CD.getD(), stashSize, tree_CD.getW());
 
 		// simulation of Reshare
-		timer.start(pid, M.online_write);
-		con1.write(pid, path);
-		timer.stop(pid, M.online_write);
+		timer.start(M.online_write);
+		con1.write(online_band, path);
+		timer.stop(M.online_write);
 
-		timer.start(pid, M.online_read);
-		con1.readTupleArray(pid);
-		timer.stop(pid, M.online_read);
+		timer.start(M.online_read);
+		con1.readTupleArrayAndDec();
+		timer.stop(M.online_read);
 
 		// second eviction sim
-		preupdateroot.runC(predata, isFirstTree, timer);
+		// preupdateroot.runC(predata, isFirstTree, timer);
 
 		R = Arrays.copyOfRange(path, 0, stashSize);
 
-		R = updateroot.runC(predata, isFirstTree, R, T.CD, timer);
+		R = updateroot.runC(isFirstTree, tupleParam, R, T.CD);
 		System.arraycopy(R, 0, path, 0, R.length);
 
-		preeviction.runC(predata, isFirstTree, timer);
+		// preeviction.runC(predata, isFirstTree, timer);
 
-		eviction.runC(predata, isFirstTree, path, tree_CD.getD(), stashSize, tree_CD.getW(), timer);
+		eviction.runC(predata, isFirstTree, tupleParam, path, tree_CD.getD(), stashSize, tree_CD.getW());
 
 		// simulation of Reshare
-		timer.start(pid, M.online_write);
-		con1.write(pid, path);
-		timer.stop(pid, M.online_write);
+		timer.start(M.online_write);
+		con1.write(online_band, path);
+		timer.stop(M.online_write);
 
-		timer.start(pid, M.online_read);
-		con1.readTupleArray(pid);
-		timer.stop(pid, M.online_read);
+		timer.start(M.online_read);
+		con1.readTupleArrayAndDec();
+		timer.stop(M.online_read);
 
-		timer.stop(pid, M.online_comp);
+		timer.stop(M.online_comp);
 		return outpiracc;
 	}
 
@@ -318,10 +326,7 @@ public class PIRRetrieve extends Protocol {
 				ete.reset();
 			}
 			if (test == 1) {
-				for (int k = 0; k < cons1.length; k++) {
-					cons1[k].bandSwitch = false;
-					cons2[k].bandSwitch = false;
-				}
+				Global.bandSwitch = false;
 			}
 
 			for (int treeIndex = 0; treeIndex < md.getNumTrees(); treeIndex++) {
@@ -355,7 +360,7 @@ public class PIRRetrieve extends Protocol {
 
 				if (party == Party.Eddie) {
 					ete.start();
-					OutPIRAccess out = this.runE(md, predata, tree_DE, tree_CE, Li, L, N, dN, timer);
+					OutPIRAccess out = this.runE(md, predata, tree_DE, tree_CE, Li, L, N, dN);
 					ete.stop();
 
 					out.j.t_D = con1.readInt();
@@ -383,7 +388,7 @@ public class PIRRetrieve extends Protocol {
 
 				} else if (party == Party.Debbie) {
 					ete.start();
-					OutPIRAccess out = this.runD(md, predata, tree_DE, tree_CD, Li, L, N, dN, timer);
+					OutPIRAccess out = this.runD(md, predata, tree_DE, tree_CD, Li, L, N, dN);
 					ete.stop();
 
 					con1.write(out.j.t_D);
@@ -391,7 +396,7 @@ public class PIRRetrieve extends Protocol {
 
 				} else if (party == Party.Charlie) {
 					ete.start();
-					OutPIRAccess out = this.runC(md, predata, tree_CD, tree_CE, Li, L, N, dN, timer);
+					OutPIRAccess out = this.runC(md, predata, tree_CD, tree_CE, Li, L, N, dN);
 					ete.stop();
 
 					con1.write(out.j.t_C);
@@ -403,12 +408,12 @@ public class PIRRetrieve extends Protocol {
 
 		}
 
-		Bandwidth total = new Bandwidth("Total Online");
-		for (int i = 0; i < P.size; i++) {
-			for (int j = 0; j < cons1.length; j++)
-				total.add(cons1[j].bandwidth[i].add(cons2[j].bandwidth[i]).bandwidth);
-		}
-		System.out.println(total.toString());
+		// Bandwidth total = new Bandwidth("Total Online");
+		// for (int i = 0; i < P.size; i++) {
+		// for (int j = 0; j < cons1.length; j++)
+		// total.add(cons1[j].bandwidth[i].add(cons2[j].bandwidth[i]).bandwidth);
+		// }
+		// System.out.println(total.toString());
 
 		// timer.divideBy(iterations - reset);
 		// timer.print();

+ 1 - 1
src/pir/ULiT.java

@@ -45,7 +45,7 @@ public class ULiT extends Protocol {
 
 		int l = Li.CE.length;
 
-		byte[] x2 = Util.nextBytes(X.CD.length, sr1);
+		byte[] x2 = Util.nextBytes(X.DE.length, sr1);
 
 		timer.stop(M.offline_comp);
 

+ 207 - 70
src/protocols/Eviction.java

@@ -1,11 +1,16 @@
 package protocols;
 
-import java.math.BigInteger;
 import java.util.Arrays;
 
+import com.oblivm.backend.flexsc.CompEnv;
 import com.oblivm.backend.gc.GCSignal;
+import com.oblivm.backend.gc.regular.GCEva;
+import com.oblivm.backend.gc.regular.GCGen;
+import com.oblivm.backend.network.Network;
 
 import communication.Communication;
+import crypto.Crypto;
+import gc.GCRoute;
 import gc.GCUtil;
 import oram.Bucket;
 import oram.Forest;
@@ -15,21 +20,17 @@ import oram.Tuple;
 import protocols.struct.Party;
 import protocols.struct.PreData;
 import util.M;
-import util.P;
-import util.Timer;
 import util.Util;
 
 // TODO: set bucket on path
 
 public class Eviction extends Protocol {
 
-	private int pid = P.EVI;
-
 	public Eviction(Communication con1, Communication con2) {
 		super(con1, con2);
 	}
 
-	private int[] prepareEviction(int target[], int[] ti, int W) {
+	private int[] prepareEviction(int[] target, int[] ti, int W) {
 		int d = ti.length;
 		int[] evict = new int[W * d];
 		for (int r = 0; r < d; r++) {
@@ -46,19 +47,103 @@ public class Eviction extends Protocol {
 		return evict;
 	}
 
-	public void runE(PreData predata, boolean firstTree, byte[] Li, Tuple[] originalPath, Tree OTi, Timer timer) {
-		timer.start(pid, M.online_comp);
-
+	public void runE(PreData predata, boolean firstTree, int[] tupleParam, byte[] Li, Tuple[] originalPath, Tree OTi) {
 		if (firstTree) {
 			// OTi.setBucketsOnPath(new BigInteger(1, Li).longValue(), new Bucket[] { new
 			// Bucket(originalPath) });
-			timer.stop(pid, M.online_comp);
 			return;
 		}
 
+		timer.start(M.offline_comp);
+
+		// GC
 		int d = OTi.getD();
 		int sw = OTi.getStashSize();
 		int w = OTi.getW();
+		int logW = (int) Math.ceil(Math.log(w + 1) / Math.log(2));
+
+		predata.evict_LiKeyPairs = GCUtil.genKeyPairs(d - 1);
+		GCSignal[] LiZeroKeys = GCUtil.getZeroKeys(predata.evict_LiKeyPairs);
+
+		predata.evict_E_feKeyPairs = new GCSignal[d][][];
+		predata.evict_C_feKeyPairs = new GCSignal[d][][];
+		GCSignal[][] E_feZeroKeys = new GCSignal[d][];
+		GCSignal[][] C_feZeroKeys = new GCSignal[d][];
+
+		predata.evict_E_labelKeyPairs = new GCSignal[d][w][][];
+		predata.evict_C_labelKeyPairs = new GCSignal[d][w][][];
+		GCSignal[][][] E_labelZeroKeys = new GCSignal[d][w][];
+		GCSignal[][][] C_labelZeroKeys = new GCSignal[d][w][];
+
+		predata.evict_deltaKeyPairs = new GCSignal[d][][];
+		GCSignal[][] deltaZeroKeys = new GCSignal[d][];
+
+		for (int i = 0; i < d; i++) {
+			predata.evict_E_feKeyPairs[i] = GCUtil.genKeyPairs(w);
+			predata.evict_C_feKeyPairs[i] = GCUtil.genKeyPairs(w);
+			E_feZeroKeys[i] = GCUtil.getZeroKeys(predata.evict_E_feKeyPairs[i]);
+			C_feZeroKeys[i] = GCUtil.getZeroKeys(predata.evict_C_feKeyPairs[i]);
+
+			predata.evict_deltaKeyPairs[i] = GCUtil.genKeyPairs(logW);
+			deltaZeroKeys[i] = GCUtil.getZeroKeys(predata.evict_deltaKeyPairs[i]);
+
+			for (int j = 0; j < w; j++) {
+				predata.evict_E_labelKeyPairs[i][j] = GCUtil.genKeyPairs(d - 1);
+				predata.evict_C_labelKeyPairs[i][j] = GCUtil.genKeyPairs(d - 1);
+				E_labelZeroKeys[i][j] = GCUtil.getZeroKeys(predata.evict_E_labelKeyPairs[i][j]);
+				C_labelZeroKeys[i][j] = GCUtil.getZeroKeys(predata.evict_C_labelKeyPairs[i][j]);
+			}
+		}
+
+		Network channel = new Network(null, con1);
+		CompEnv<GCSignal> gen = new GCGen(channel, timer, offline_band, M.offline_write);
+		GCSignal[][][] outZeroKeys = new GCRoute<GCSignal>(gen, d, w).routing(LiZeroKeys, E_feZeroKeys, C_feZeroKeys,
+				E_labelZeroKeys, C_labelZeroKeys, deltaZeroKeys);
+		((GCGen) gen).sendLastSetGTT();
+
+		predata.evict_tiOutKeyHashes = new byte[d][][];
+		predata.evict_targetOutKeyPairs = new GCSignal[d][][];
+		for (int i = 0; i < d; i++) {
+			predata.evict_tiOutKeyHashes[i] = GCUtil.genOutKeyHashes(outZeroKeys[1][i]);
+			predata.evict_targetOutKeyPairs[i] = GCUtil.recoverOutKeyPairs(outZeroKeys[0][i]);
+		}
+
+		timer.start(M.offline_write);
+		con2.write(predata.evict_C_feKeyPairs);
+		con2.write(predata.evict_C_labelKeyPairs);
+
+		con1.write(predata.evict_tiOutKeyHashes);
+		con1.write(predata.evict_targetOutKeyPairs);
+		timer.stop(M.offline_write);
+
+		// Permutation
+		predata.evict_pi = Util.randomPermutation(d, Crypto.sr);
+		predata.evict_delta = new byte[d][];
+		predata.evict_rho = new byte[d][];
+		predata.evict_delta_p = new int[d][];
+		predata.evict_rho_p = new int[d][];
+
+		for (int i = 0; i < d; i++) {
+			predata.evict_delta[i] = Util.nextBytes((logW + 7) / 8, Crypto.sr);
+			predata.evict_rho[i] = Util.nextBytes((logW + 7) / 8, Crypto.sr);
+			predata.evict_delta_p[i] = Util.getXorPermutation(predata.evict_delta[i], logW);
+			predata.evict_rho_p[i] = Util.getXorPermutation(predata.evict_rho[i], logW);
+		}
+
+		timer.start(M.offline_write);
+		con2.write(predata.evict_pi);
+		con2.write(predata.evict_delta);
+		con2.write(predata.evict_rho);
+		con2.write(predata.evict_delta_p);
+		con2.write(predata.evict_rho_p);
+		timer.stop(M.offline_write);
+
+		timer.stop(M.offline_comp);
+
+		///////////////////////////////////////////////////////////////////
+
+		timer.start(M.online_comp);
+
 		Tuple[] pathTuples = new Tuple[d * w];
 		System.arraycopy(originalPath, 0, pathTuples, 0, w);
 		System.arraycopy(originalPath, sw, pathTuples, w, (d - 1) * w);
@@ -75,20 +160,19 @@ public class Eviction extends Protocol {
 			deltaInputKeys[i] = GCUtil.revSelectKeys(predata.evict_deltaKeyPairs[i], predata.evict_delta[i]);
 		}
 
-		timer.start(pid, M.online_write);
-		con1.write(pid, LiInputKeys);
-		con1.write(pid, E_feInputKeys);
-		con1.write(pid, E_labelInputKeys);
-		con1.write(pid, deltaInputKeys);
-		timer.stop(pid, M.online_write);
+		timer.start(M.online_write);
+		con1.write(online_band, LiInputKeys);
+		con1.write(online_band, E_feInputKeys);
+		con1.write(online_band, E_labelInputKeys);
+		con1.write(online_band, deltaInputKeys);
+		timer.stop(M.online_write);
 
 		PermuteTarget permutetarget = new PermuteTarget(con1, con2);
-		permutetarget.runE();
+		permutetarget.runE(d, predata.evict_pi, predata.evict_targetOutKeyPairs);
 
 		PermuteIndex permuteindex = new PermuteIndex(con1, con2);
-		permuteindex.runE();
+		permuteindex.runE(w, predata.evict_pi);
 
-		int logW = (int) Math.ceil(Math.log(w + 1) / Math.log(2));
 		int W = (int) Math.pow(2, logW);
 		for (int i = 0; i < d; i++) {
 			pathBuckets[i].expand(W);
@@ -100,8 +184,8 @@ public class Eviction extends Protocol {
 		}
 		pathTuples = Bucket.bucketsToTuples(pathBuckets);
 
-		SSXOT ssxot = new SSXOT(con1, con2, 1);
-		pathTuples = ssxot.runE(predata, pathTuples, timer);
+		SSXOT ssxot = new SSXOT(con1, con2);
+		pathTuples = ssxot.runE(pathTuples, tupleParam);
 
 		pathBuckets = Bucket.tuplesToBuckets(pathTuples, d, W, W);
 		for (int i = 0; i < d; i++) {
@@ -119,37 +203,74 @@ public class Eviction extends Protocol {
 		pathBuckets[0].expand(Arrays.copyOfRange(originalPath, w, sw));
 		// OTi.setBucketsOnPath(new BigInteger(1, Li).longValue(), pathBuckets);
 
-		timer.stop(pid, M.online_comp);
+		timer.stop(M.online_comp);
 	}
 
-	public void runD(PreData predata, boolean firstTree, byte[] Li, Tree OTi, Timer timer) {
-		timer.start(pid, M.online_comp);
-
+	public void runD(PreData predata, boolean firstTree, int[] tupleParam, byte[] Li, Tree OTi) {
 		if (firstTree) {
-			timer.start(pid, M.online_read);
-			// Tuple[] originalPath = con2.readTupleArray(pid);
-			timer.stop(pid, M.online_read);
+			timer.start(M.online_read);
+			// Tuple[] originalPath = con2.readTupleArrayAndDec();
+			timer.stop(M.online_read);
 
 			// OTi.setBucketsOnPath(new BigInteger(1, Li).longValue(), new Bucket[] { new
 			// Bucket(originalPath) });
-
-			timer.stop(pid, M.online_comp);
 			return;
 		}
 
-		timer.start(pid, M.online_read);
-		GCSignal[] LiInputKeys = con1.readGCSignalArray(pid);
-		GCSignal[][] E_feInputKeys = con1.readDoubleGCSignalArray(pid);
-		GCSignal[][][] E_labelInputKeys = con1.readTripleGCSignalArray(pid);
-		GCSignal[][] deltaInputKeys = con1.readDoubleGCSignalArray(pid);
-
-		GCSignal[][] C_feInputKeys = con2.readDoubleGCSignalArray(pid);
-		GCSignal[][][] C_labelInputKeys = con2.readTripleGCSignalArray(pid);
-		timer.stop(pid, M.online_read);
+		timer.start(M.offline_comp);
 
+		// GC
+		int d = OTi.getD();
 		int w = OTi.getW();
 		int logW = (int) Math.ceil(Math.log(w + 1) / Math.log(2));
 
+		GCSignal[] LiZeroKeys = GCUtil.genEmptyKeys(d - 1);
+		GCSignal[][] E_feZeroKeys = new GCSignal[d][];
+		GCSignal[][] C_feZeroKeys = new GCSignal[d][];
+		GCSignal[][][] E_labelZeroKeys = new GCSignal[d][w][];
+		GCSignal[][][] C_labelZeroKeys = new GCSignal[d][w][];
+		GCSignal[][] deltaZeroKeys = new GCSignal[d][];
+
+		for (int i = 0; i < d; i++) {
+			E_feZeroKeys[i] = GCUtil.genEmptyKeys(w);
+			C_feZeroKeys[i] = GCUtil.genEmptyKeys(w);
+			deltaZeroKeys[i] = GCUtil.genEmptyKeys(logW);
+
+			for (int j = 0; j < w; j++) {
+				E_labelZeroKeys[i][j] = GCUtil.genEmptyKeys(d - 1);
+				C_labelZeroKeys[i][j] = GCUtil.genEmptyKeys(d - 1);
+			}
+		}
+
+		Network channel = new Network(con1, null);
+		CompEnv<GCSignal> eva = new GCEva(channel, timer, M.offline_read);
+		predata.evict_gcroute = new GCRoute<GCSignal>(eva, d, w);
+		predata.evict_gcroute.routing(LiZeroKeys, E_feZeroKeys, C_feZeroKeys, E_labelZeroKeys, C_labelZeroKeys,
+				deltaZeroKeys);
+		((GCEva) eva).receiveLastSetGTT();
+		eva.setEvaluate();
+
+		timer.start(M.offline_read);
+		predata.evict_tiOutKeyHashes = con1.readTripleByteArray();
+		predata.evict_targetOutKeyPairs = con1.readTripleGCSignalArray();
+		timer.stop(M.offline_read);
+
+		timer.stop(M.offline_comp);
+
+		//////////////////////////////////////////////////////////////////////
+
+		timer.start(M.online_comp);
+
+		timer.start(M.online_read);
+		GCSignal[] LiInputKeys = con1.readGCSignalArrayAndDec();
+		GCSignal[][] E_feInputKeys = con1.readDoubleGCSignalArrayAndDec();
+		GCSignal[][][] E_labelInputKeys = con1.readTripleGCSignalArrayAndDec();
+		GCSignal[][] deltaInputKeys = con1.readDoubleGCSignalArrayAndDec();
+
+		GCSignal[][] C_feInputKeys = con2.readDoubleGCSignalArrayAndDec();
+		GCSignal[][][] C_labelInputKeys = con2.readTripleGCSignalArrayAndDec();
+		timer.stop(M.online_read);
+
 		GCSignal[][][] outKeys = predata.evict_gcroute.routing(LiInputKeys, E_feInputKeys, C_feInputKeys,
 				E_labelInputKeys, C_labelInputKeys, deltaInputKeys);
 
@@ -160,35 +281,54 @@ public class Eviction extends Protocol {
 		}
 
 		PermuteTarget permutetarget = new PermuteTarget(con1, con2);
-		int[] target_pp = permutetarget.runD(predata, firstTree, outKeys[0], timer);
+		int[] target_pp = permutetarget.runD(firstTree, outKeys[0]);
 
 		PermuteIndex permuteindex = new PermuteIndex(con1, con2);
-		int[] ti_pp = permuteindex.runD(predata, firstTree, ti_p, w, timer);
+		int[] ti_pp = permuteindex.runD(firstTree, ti_p, w);
 
 		int W = (int) Math.pow(2, logW);
 		int[] evict = prepareEviction(target_pp, ti_pp, W);
 
-		SSXOT ssxot = new SSXOT(con1, con2, 1);
-		ssxot.runD(predata, evict, timer);
+		SSXOT ssxot = new SSXOT(con1, con2);
+		ssxot.runD(evict.length, evict.length, tupleParam, evict);
 
-		timer.start(pid, M.online_read);
-		// Bucket[] pathBuckets = con2.readBucketArray(pid);
-		timer.stop(pid, M.online_read);
+		timer.start(M.online_read);
+		// Bucket[] pathBuckets = con2.readBucketArrayAndDec();
+		timer.stop(M.online_read);
 
 		// OTi.setBucketsOnPath(new BigInteger(1, Li).longValue(), pathBuckets);
 
-		timer.stop(pid, M.online_comp);
+		timer.stop(M.online_comp);
 	}
 
-	public void runC(PreData predata, boolean firstTree, Tuple[] originalPath, int d, int sw, int w, Timer timer) {
+	public void runC(PreData predata, boolean firstTree, int[] tupleParam, Tuple[] originalPath, int d, int sw, int w) {
 		if (firstTree) {
-			timer.start(pid, M.online_write);
-			// con2.write(pid, originalPath);
-			timer.stop(pid, M.online_write);
+			timer.start(M.online_write);
+			// con2.write(online_band, originalPath);
+			timer.stop(M.online_write);
 			return;
 		}
 
-		timer.start(pid, M.online_comp);
+		timer.start(M.offline_comp);
+
+		// GC
+		timer.start(M.offline_read);
+		predata.evict_C_feKeyPairs = con1.readTripleGCSignalArray();
+		predata.evict_C_labelKeyPairs = con1.readQuadGCSignalArray();
+
+		// Permutation
+		predata.evict_pi = con1.readIntArray();
+		predata.evict_delta = con1.readDoubleByteArray();
+		predata.evict_rho = con1.readDoubleByteArray();
+		predata.evict_delta_p = con1.readDoubleIntArray();
+		predata.evict_rho_p = con1.readDoubleIntArray();
+		timer.stop(M.offline_read);
+
+		timer.stop(M.offline_comp);
+
+		///////////////////////////////////////////////////////////////
+
+		timer.start(M.online_comp);
 
 		Tuple[] pathTuples = new Tuple[d * w];
 		System.arraycopy(originalPath, 0, pathTuples, 0, w);
@@ -203,16 +343,16 @@ public class Eviction extends Protocol {
 			C_labelInputKeys[i] = GCUtil.selectLabelKeys(predata.evict_C_labelKeyPairs[i], pathBuckets[i].getTuples());
 		}
 
-		timer.start(pid, M.online_write);
-		con2.write(pid, C_feInputKeys);
-		con2.write(pid, C_labelInputKeys);
-		timer.stop(pid, M.online_write);
+		timer.start(M.online_write);
+		con2.write(online_band, C_feInputKeys);
+		con2.write(online_band, C_labelInputKeys);
+		timer.stop(M.online_write);
 
 		PermuteTarget permutetarget = new PermuteTarget(con1, con2);
-		permutetarget.runC(predata, firstTree, timer);
+		permutetarget.runC(firstTree, d, predata.evict_pi);
 
 		PermuteIndex permuteindex = new PermuteIndex(con1, con2);
-		permuteindex.runC(predata, firstTree, timer);
+		permuteindex.runC(firstTree, w, predata.evict_pi, predata.evict_rho);
 
 		int logW = (int) Math.ceil(Math.log(w + 1) / Math.log(2));
 		int W = (int) Math.pow(2, logW);
@@ -226,8 +366,8 @@ public class Eviction extends Protocol {
 		}
 		pathTuples = Bucket.bucketsToTuples(pathBuckets);
 
-		SSXOT ssxot = new SSXOT(con1, con2, 1);
-		pathTuples = ssxot.runC(predata, pathTuples, timer);
+		SSXOT ssxot = new SSXOT(con1, con2);
+		pathTuples = ssxot.runC(pathTuples, tupleParam);
 
 		pathBuckets = Bucket.tuplesToBuckets(pathTuples, d, W, W);
 		for (int i = 0; i < d; i++) {
@@ -244,22 +384,19 @@ public class Eviction extends Protocol {
 
 		pathBuckets[0].expand(Arrays.copyOfRange(originalPath, w, sw));
 
-		timer.start(pid, M.online_write);
-		// con2.write(pid, pathBuckets);
-		timer.stop(pid, M.online_write);
+		timer.start(M.online_write);
+		// con2.write(online_band, pathBuckets);
+		timer.stop(M.online_write);
 
-		timer.stop(pid, M.online_comp);
+		timer.stop(M.online_comp);
 	}
 
-	// for testing correctness
 	@Override
-	public void run(Party party, Metadata md, Forest forest) {
-		System.out.println("Use Retrieve to test Eviction");
+	public void run(Party party, Metadata md, Forest[] forest) {
+		System.out.println("Use PIRRetrieve to test Eviction");
 	}
 
 	@Override
-	public void run(Party party, Metadata md, Forest[] forest) {
-		// TODO Auto-generated method stub
-
+	public void run(Party party, Metadata md, Forest forest) {
 	}
 }