Przeglądaj źródła

PermuteTarget tested

Boyoung- 8 lat temu
rodzic
commit
24494aac8e

+ 6 - 6
src/gc/GCUtil.java

@@ -82,25 +82,25 @@ 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++) {
+		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++)
+		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++)
+		for (int i = 0; i < keys.length; i++)
 			Crypto.sha1.update(keys[i].bytes);
 		return Crypto.sha1.digest();
 	}

+ 39 - 10
src/protocols/PermuteTarget.java

@@ -28,6 +28,7 @@ public class PermuteTarget extends Protocol {
 		if (firstTree)
 			return null;
 
+		// PermuteTargetI
 		int d = targetOutKeys.length;
 		int I[] = new int[d];
 		BigInteger[] target = new BigInteger[d];
@@ -42,8 +43,18 @@ public class PermuteTarget extends Protocol {
 				}
 			}
 		}
-		
-		for (int j=0; j<d; j++) {
+
+		// PermuteTargetII
+		BigInteger[] z = Util.xor(target, predata.pt_p);
+
+		con2.write(z);
+		con2.write(I);
+
+		BigInteger[] g = con2.readObject();
+
+		target = Util.xor(predata.pt_a, g);
+
+		for (int j = 0; j < d; j++) {
 			System.out.print(target[j].intValue() + " ");
 		}
 		System.out.println();
@@ -55,6 +66,18 @@ public class PermuteTarget extends Protocol {
 		if (firstTree)
 			return;
 
+		// PermuteTargetII
+		BigInteger[] z = con2.readObject();
+		int[] I = con2.readObject();
+
+		BigInteger[] mk = new BigInteger[z.length];
+		for (int i = 0; i < mk.length; i++) {
+			mk[i] = predata.pt_maskT[i][I[i]].xor(z[i]);
+			mk[i] = predata.pt_r[i].xor(mk[i]);
+		}
+		BigInteger[] g = Util.permute(mk, predata.evict_pi);
+
+		con2.write(g);
 	}
 
 	// for testing correctness
@@ -88,14 +111,18 @@ public class PermuteTarget extends Protocol {
 				con1.write(predata.evict_targetOutKeyPairs);
 				con1.write(targetOutKeys);
 
+				con2.write(predata.evict_pi);
+
 				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] + " ");
+
+				int[] pi_ivs = Util.inversePermutation(predata.evict_pi);
+
+				int[] piTargetPiIvs = new int[d];
+				for (int j = 0; j < d; j++) {
+					piTargetPiIvs[j] = predata.evict_pi[target[pi_ivs[j]]];
+					System.out.print(piTargetPiIvs[j] + " ");
 				}
 				System.out.println();
 
@@ -106,12 +133,14 @@ public class PermuteTarget extends Protocol {
 				GCSignal[][] targetOutKeys = con1.readObject();
 
 				prepermutetarget.runD(predata, d, timer);
-				
+
 				runD(predata, false, targetOutKeys, timer);
 
 			} else if (party == Party.Charlie) {
+				predata.evict_pi = con1.readObject();
+
 				prepermutetarget.runC(predata, timer);
-				
+
 				runC(predata, false, timer);
 
 			} else {

+ 6 - 1
src/protocols/PreData.java

@@ -67,8 +67,13 @@ public class PreData {
 	public int[][] evict_delta_p;
 	public int[][] evict_rho_p;
 	// public BigInteger[][] tmpKeyHashes;
-	
+
+	// PermuteTargetI
 	public BigInteger[][] pt_maskT;
 	public BigInteger[][] pt_keyT;
 	public BigInteger[][] pt_targetT;
+	// PermuteTargetII
+	public BigInteger[] pt_p;
+	public BigInteger[] pt_r;
+	public BigInteger[] pt_a;
 }

+ 2 - 2
src/protocols/PreEviction.java

@@ -73,10 +73,10 @@ public class PreEviction extends Protocol {
 			// 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);

+ 28 - 4
src/protocols/PrePermuteTarget.java

@@ -23,18 +23,18 @@ public class PrePermuteTarget extends Protocol {
 		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_maskT[i][j] = 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);
@@ -43,17 +43,41 @@ public class PrePermuteTarget extends Protocol {
 
 		con1.write(predata.pt_keyT);
 		con1.write(predata.pt_targetT);
-		
+
 		con2.write(predata.pt_maskT);
+
+		predata.pt_p = new BigInteger[d];
+		predata.pt_r = new BigInteger[d];
+		predata.pt_a = new BigInteger[d];
+		for (int i = 0; i < d; i++) {
+			predata.pt_p[i] = new BigInteger(logD, Crypto.sr);
+			predata.pt_r[i] = new BigInteger(logD, Crypto.sr);
+			predata.pt_a[i] = predata.pt_p[i].xor(predata.pt_r[i]);
+		}
+		predata.pt_a = Util.permute(predata.pt_a, predata.evict_pi);
+
+		con1.write(predata.pt_p);
+		con1.write(predata.pt_a);
+
+		con2.write(predata.pt_r);
 	}
 
 	public void runD(PreData predata, int d, Timer timer) {
+		// PermuteTargetI
 		predata.pt_keyT = con1.readObject();
 		predata.pt_targetT = con1.readObject();
+
+		// PermuteTargetII
+		predata.pt_p = con1.readObject();
+		predata.pt_a = con1.readObject();
 	}
 
 	public void runC(PreData predata, Timer timer) {
+		// PermuteTargetI
 		predata.pt_maskT = con1.readObject();
+
+		// PermuteTargetII
+		predata.pt_r = con1.readObject();
 	}
 
 	@Override

+ 9 - 0
src/util/Util.java

@@ -89,6 +89,15 @@ public class Util {
 			a[i] = (byte) (a[i] ^ b[i]);
 	}
 
+	public static BigInteger[] xor(BigInteger[] a, BigInteger[] b) {
+		if (a.length != b.length)
+			throw new LengthNotMatchException(a.length + " != " + b.length);
+		BigInteger[] c = new BigInteger[a.length];
+		for (int i = 0; i < a.length; i++)
+			c[i] = a[i].xor(b[i]);
+		return c;
+	}
+
 	public static byte[] intToBytes(int i) {
 		ByteBuffer bb = ByteBuffer.allocate(4);
 		bb.putInt(i);