Browse Source

PermuteTargetI tested

Boyoung- 9 years ago
parent
commit
c53dfbbbe7

+ 23 - 0
src/gc/GCUtil.java

@@ -7,6 +7,7 @@ import com.oblivm.backend.gc.GCSignal;
 
 import crypto.Crypto;
 import oram.Tuple;
+import util.Util;
 
 public class GCUtil {
 
@@ -81,4 +82,26 @@ public class GCUtil {
 		}
 		return output;
 	}
+	
+	public static GCSignal[][] recoverOutKeyPairs(GCSignal[] outZeroKeys) {
+		GCSignal[][] pairs = new GCSignal[outZeroKeys.length][2];
+		for (int i=0; i<outZeroKeys.length; i++) {
+			pairs[i][0] = outZeroKeys[i];
+			pairs[i][1] = GCGenComp.R.xor(pairs[i][0]);
+		}
+		return pairs;
+	}
+	
+	public static byte[] xorAll(GCSignal[] keys) {
+		byte[] out = keys[0].bytes.clone();
+		for (int i=1; i<keys.length; i++)
+			Util.setXor(out, keys[i].bytes);
+		return out;
+	}
+	
+	public static byte[] hashAll(GCSignal[] keys) {
+		for (int i=0; i<keys.length; i++)
+			Crypto.sha1.update(keys[i].bytes);
+		return Crypto.sha1.digest();
+	}
 }

+ 124 - 0
src/protocols/PermuteTarget.java

@@ -0,0 +1,124 @@
+package protocols;
+
+import java.math.BigInteger;
+
+import com.oblivm.backend.gc.GCSignal;
+
+import communication.Communication;
+import crypto.Crypto;
+import exceptions.NoSuchPartyException;
+import gc.GCUtil;
+import measure.Timer;
+import oram.Forest;
+import oram.Metadata;
+import util.Util;
+
+public class PermuteTarget extends Protocol {
+	public PermuteTarget(Communication con1, Communication con2) {
+		super(con1, con2);
+	}
+
+	public void runE(PreData predata, boolean firstTree, Timer timer) {
+		if (firstTree)
+			return;
+
+	}
+
+	public BigInteger[] runD(PreData predata, boolean firstTree, GCSignal[][] targetOutKeys, Timer timer) {
+		if (firstTree)
+			return null;
+
+		int d = targetOutKeys.length;
+		int I[] = new int[d];
+		BigInteger[] target = new BigInteger[d];
+
+		for (int i = 0; i < d; i++) {
+			BigInteger hashKeys = new BigInteger(GCUtil.hashAll(targetOutKeys[i]));
+			for (int j = 0; j < d; j++) {
+				if (hashKeys.compareTo(predata.pt_keyT[i][j]) == 0) {
+					I[i] = j;
+					target[i] = predata.pt_targetT[i][j];
+					break;
+				}
+			}
+		}
+		
+		for (int j=0; j<d; j++) {
+			System.out.print(target[j].intValue() + " ");
+		}
+		System.out.println();
+
+		return target;
+	}
+
+	public void runC(PreData predata, boolean firstTree, Timer timer) {
+		if (firstTree)
+			return;
+
+	}
+
+	// for testing correctness
+	@Override
+	public void run(Party party, Metadata md, Forest forest) {
+		Timer timer = new Timer();
+
+		for (int i = 0; i < 10; i++) {
+
+			System.out.println("i=" + i);
+
+			PreData predata = new PreData();
+			PrePermuteTarget prepermutetarget = new PrePermuteTarget(con1, con2);
+
+			if (party == Party.Eddie) {
+				int d = Crypto.sr.nextInt(1) + 5;
+				int logD = (int) Math.ceil(Math.log(d) / Math.log(2));
+				int[] target = Util.randomPermutation(d, Crypto.sr);
+
+				predata.evict_pi = Util.randomPermutation(d, Crypto.sr);
+				predata.evict_targetOutKeyPairs = new GCSignal[d][][];
+				GCSignal[][] targetOutKeys = new GCSignal[d][];
+				for (int j = 0; j < d; j++) {
+					predata.evict_targetOutKeyPairs[j] = GCUtil.genKeyPairs(logD);
+					targetOutKeys[j] = GCUtil.revSelectKeys(predata.evict_targetOutKeyPairs[j],
+							BigInteger.valueOf(target[j]).toByteArray());
+				}
+
+				con1.write(d);
+				con1.write(predata.evict_pi);
+				con1.write(predata.evict_targetOutKeyPairs);
+				con1.write(targetOutKeys);
+
+				prepermutetarget.runE(predata, d, timer);
+				
+				runE(predata, false, timer);
+				
+				int[] piTarget = new int[d];
+				for (int j=0; j<d; j++) {
+					piTarget[j] = predata.evict_pi[target[j]];
+					System.out.print(piTarget[j] + " ");
+				}
+				System.out.println();
+
+			} else if (party == Party.Debbie) {
+				int d = con1.readObject();
+				predata.evict_pi = con1.readObject();
+				predata.evict_targetOutKeyPairs = con1.readObject();
+				GCSignal[][] targetOutKeys = con1.readObject();
+
+				prepermutetarget.runD(predata, d, timer);
+				
+				runD(predata, false, targetOutKeys, timer);
+
+			} else if (party == Party.Charlie) {
+				prepermutetarget.runC(predata, timer);
+				
+				runC(predata, false, timer);
+
+			} else {
+				throw new NoSuchPartyException(party + "");
+			}
+		}
+
+		// timer.print();
+	}
+}

+ 5 - 1
src/protocols/PreData.java

@@ -59,12 +59,16 @@ public class PreData {
 	public GCSignal[][][][] evict_C_labelKeyPairs;
 	public GCSignal[][][] evict_deltaKeyPairs;
 	public BigInteger[][] evict_tiOutKeyHashes;
+	public GCSignal[][][] evict_targetOutKeyPairs;
 	public GCLib<GCSignal> evict_gc;
 	public int[] evict_pi;
 	public BigInteger[] evict_delta;
 	public BigInteger[] evict_rho;
 	public int[][] evict_delta_p;
 	public int[][] evict_rho_p;
-
 	// public BigInteger[][] tmpKeyHashes;
+	
+	public BigInteger[][] pt_maskT;
+	public BigInteger[][] pt_keyT;
+	public BigInteger[][] pt_targetT;
 }

+ 6 - 10
src/protocols/PreEviction.java

@@ -65,16 +65,20 @@ public class PreEviction extends Protocol {
 				E_labelZeroKeys, C_labelZeroKeys, deltaZeroKeys);
 
 		predata.evict_tiOutKeyHashes = new BigInteger[d][];
+		predata.evict_targetOutKeyPairs = new GCSignal[d][][];
 		// predata.tmpKeyHashes = new BigInteger[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]);
 			// predata.tmpKeyHashes[i] =
 			// GCUtil.genOutKeyHashes(outZeroKeys[0][i]);
 		}
-
+		
 		con2.write(predata.evict_C_feKeyPairs);
 		con2.write(predata.evict_C_labelKeyPairs);
+		
 		con1.write(predata.evict_tiOutKeyHashes);
+		con1.write(predata.evict_targetOutKeyPairs);
 		// con1.write(predata.tmpKeyHashes);
 
 		// Permutation
@@ -96,9 +100,6 @@ public class PreEviction extends Protocol {
 		con2.write(predata.evict_rho);
 		con2.write(predata.evict_delta_p);
 		con2.write(predata.evict_rho_p);
-
-		// PreSSXOT pressxot = new PreSSXOT(con1, con2, 0);
-		// pressxot.runE(predata, timer);
 	}
 
 	public void runD(PreData predata, int d, int w, int[] tupleParam, Timer timer) {
@@ -131,10 +132,8 @@ public class PreEviction extends Protocol {
 		eva.setEvaluate();
 
 		predata.evict_tiOutKeyHashes = con1.readObject();
+		predata.evict_targetOutKeyPairs = con1.readObject();
 		// predata.tmpKeyHashes = con1.readObject();
-
-		// PreSSXOT pressxot = new PreSSXOT(con1, con2, 0);
-		// pressxot.runD(predata, sw + 1, sw, tupleParam, timer);
 	}
 
 	public void runC(PreData predata, Timer timer) {
@@ -148,9 +147,6 @@ public class PreEviction extends Protocol {
 		predata.evict_rho = con1.readObject();
 		predata.evict_delta_p = con1.readObject();
 		predata.evict_rho_p = con1.readObject();
-
-		// PreSSXOT pressxot = new PreSSXOT(con1, con2, 0);
-		// pressxot.runC(predata, timer);
 	}
 
 	@Override

+ 62 - 0
src/protocols/PrePermuteTarget.java

@@ -0,0 +1,62 @@
+package protocols;
+
+import java.math.BigInteger;
+
+import com.oblivm.backend.gc.GCSignal;
+
+import communication.Communication;
+import crypto.Crypto;
+import gc.GCUtil;
+import measure.Timer;
+import oram.Forest;
+import oram.Metadata;
+import util.Util;
+
+public class PrePermuteTarget extends Protocol {
+	public PrePermuteTarget(Communication con1, Communication con2) {
+		super(con1, con2);
+	}
+
+	public void runE(PreData predata, int d, Timer timer) {
+		int logD = (int) Math.ceil(Math.log(d) / Math.log(2));
+
+		predata.pt_keyT = new BigInteger[d][d];
+		predata.pt_targetT = new BigInteger[d][d];
+		predata.pt_maskT = new BigInteger[d][d];
+		
+		for (int i = 0; i < d; i++) {
+			for (int j = 0; j < d; j++) {
+				GCSignal[] keys = GCUtil.revSelectKeys(predata.evict_targetOutKeyPairs[i],
+						BigInteger.valueOf(j).toByteArray());
+				predata.pt_keyT[i][j] = new BigInteger(GCUtil.hashAll(keys));
+
+				predata.pt_maskT[i][j] = BigInteger.ZERO; //new BigInteger(logD, Crypto.sr);
+
+				predata.pt_targetT[i][j] = BigInteger.valueOf(predata.evict_pi[j]).xor(predata.pt_maskT[i][j]);
+			}
+			
+			int[] randPerm = Util.randomPermutation(d, Crypto.sr);
+			predata.pt_keyT[i] = Util.permute(predata.pt_keyT[i], randPerm);
+			predata.pt_maskT[i] = Util.permute(predata.pt_maskT[i], randPerm);
+			predata.pt_targetT[i] = Util.permute(predata.pt_targetT[i], randPerm);
+		}
+
+		con1.write(predata.pt_keyT);
+		con1.write(predata.pt_targetT);
+		
+		con2.write(predata.pt_maskT);
+	}
+
+	public void runD(PreData predata, int d, Timer timer) {
+		predata.pt_keyT = con1.readObject();
+		predata.pt_targetT = con1.readObject();
+	}
+
+	public void runC(PreData predata, Timer timer) {
+		predata.pt_maskT = con1.readObject();
+	}
+
+	@Override
+	public void run(Party party, Metadata md, Forest forest) {
+	}
+}

+ 2 - 0
src/ui/CLI.java

@@ -85,6 +85,8 @@ public class CLI {
 			operation = PrepareDeepest.class;
 		} else if (protocol.equals("pt")) {
 			operation = PrepareTarget.class;
+		} else if (protocol.equals("permt")) {
+			operation = PermuteTarget.class;
 		} else if (protocol.equals("mc")) {
 			operation = MakeCycle.class;
 		} else if (protocol.equals("update")) {