Browse Source

ssiot tested

Boyoung- 8 years ago
parent
commit
dc30495a20

BIN
data/forest_t3m12w4d4_i1000s16.bin


BIN
data/forest_t3m12w4d4_i1000s16.bin.share1


BIN
data/forest_t3m12w4d4_i1000s16.bin.share2


File diff suppressed because it is too large
+ 141 - 111
data/forest_t3m12w4d4_i1000s16.txt


+ 16 - 0
src/exceptions/SSIOTException.java

@@ -0,0 +1,16 @@
+package exceptions;
+
+public class SSIOTException extends RuntimeException {
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+	public SSIOTException() {
+		super();
+	}
+
+	public SSIOTException(String message) {
+		super(message);
+	}
+}

+ 15 - 0
src/oram/Bucket.java

@@ -92,4 +92,19 @@ public class Bucket implements Serializable {
 		return str;
 	}
 
+	public static Tuple[] bucketsToTuples(Bucket[] buckets) {
+		int numTuples = 0;
+		for (int i = 0; i < buckets.length; i++)
+			numTuples += buckets[i].getNumTuples();
+
+		Tuple[] tuples = new Tuple[numTuples];
+		int tupleCnt = 0;
+		for (int i = 0; i < buckets.length; i++)
+			for (int j = 0; j < buckets[i].getNumTuples(); j++) {
+				tuples[tupleCnt] = buckets[i].getTuple(j);
+				tupleCnt++;
+			}
+
+		return tuples;
+	}
 }

+ 21 - 0
src/oram/Tree.java

@@ -14,6 +14,8 @@ public class Tree implements Serializable {
 	 */
 	private static final long serialVersionUID = 1L;
 
+	private int tau;
+	private int twoTauPow;
 	private int treeIndex;
 	private int w;
 	private int stashSize;
@@ -28,10 +30,13 @@ public class Tree implements Serializable {
 	private long numBuckets;
 	private long numBytes;
 	private int d;
+	private int h;
 
 	private Array64<Bucket> buckets;
 
 	public Tree(int index, Metadata md, Random rand) {
+		tau = md.getTau();
+		twoTauPow = md.getTwoTauPow();
 		treeIndex = index;
 		w = md.getW();
 		stashSize = md.getStashSizeOfTree(treeIndex);
@@ -46,6 +51,7 @@ public class Tree implements Serializable {
 		numBuckets = md.getNumBucketsOfTree(treeIndex);
 		numBytes = md.getTreeBytesOfTree(treeIndex);
 		d = lBits + 1;
+		h = md.getNumTrees();
 
 		int fBytes = treeIndex == 0 ? 0 : 1;
 		int[] tupleParams = new int[] { fBytes, nBytes, lBytes, aBytes };
@@ -58,6 +64,8 @@ public class Tree implements Serializable {
 	// only used for xor operation
 	// does not shallow/deep copy buckets
 	private Tree(Tree t) {
+		tau = t.getTau();
+		twoTauPow = t.getTwoTauPow();
 		treeIndex = t.getTreeIndex();
 		w = t.getW();
 		stashSize = t.getStashSize();
@@ -72,6 +80,7 @@ public class Tree implements Serializable {
 		numBuckets = t.getNumBuckets();
 		numBytes = t.getNumBytes();
 		d = t.getD();
+		h = t.getH();
 		buckets = new Array64<Bucket>(numBuckets);
 	}
 
@@ -138,6 +147,14 @@ public class Tree implements Serializable {
 			setBucket(indices[i], buckets[i]);
 	}
 
+	public int getTau() {
+		return tau;
+	}
+
+	public int getTwoTauPow() {
+		return twoTauPow;
+	}
+
 	public int getTreeIndex() {
 		return treeIndex;
 	}
@@ -197,4 +214,8 @@ public class Tree implements Serializable {
 	public int getD() {
 		return d;
 	}
+
+	public int getH() {
+		return h;
+	}
 }

+ 30 - 32
src/protocols/Access.java

@@ -6,6 +6,7 @@ import java.util.Arrays;
 import org.apache.commons.lang3.ArrayUtils;
 
 import communication.Communication;
+import crypto.Crypto;
 import exceptions.NoSuchPartyException;
 import oram.Bucket;
 import oram.Forest;
@@ -26,29 +27,30 @@ public class Access extends Protocol {
 		// Object[] objArray = Util.permute(pathBuckets, predata.access_sigma);
 		// pathBuckets = Arrays.copyOf(objArray, objArray.length,
 		// Bucket[].class);
-		for (int i = 0; i < pathBuckets.length; i++) {
+		for (int i = 0; i < pathBuckets.length; i++)
 			pathBuckets[i].setXor(predata.access_p[i]);
-		}
+		Tuple[] pathTuples = Bucket.bucketsToTuples(pathBuckets);
 
 		// step 3
-		int numTuples = OTi.getStashSize() + (pathBuckets.length - 1) * OTi.getW();
-		byte[][] a = new byte[numTuples][];
-		byte[][] m = new byte[numTuples][];
-		int tupleCnt = 0;
-		for (int i = 0; i < pathBuckets.length; i++)
-			for (int j = 0; j < pathBuckets[i].getNumTuples(); j++) {
-				Tuple tuple = pathBuckets[i].getTuple(j);
-				a[tupleCnt] = ArrayUtils.addAll(tuple.getF(), tuple.getN());
-				m[tupleCnt] = tuple.getA();
-				tupleCnt++;
-			}
-		for (int i = 0; i < numTuples; i++) {
+		byte[][] a = new byte[pathTuples.length][];
+		byte[][] m = new byte[pathTuples.length][];
+		byte[] y = Util.nextBytes(OTi.getABytes(), Crypto.sr);
+		for (int i = 0; i < pathTuples.length; i++) {
+			m[i] = Util.xor(pathTuples[i].getA(), y);
+			a[i] = ArrayUtils.addAll(pathTuples[i].getF(), pathTuples[i].getN());
 			for (int j = 0; j < Ni.length; j++)
 				a[i][a[i].length - 1 - j] ^= Ni[Ni.length - 1 - j];
 		}
 
 		SSCOT sscot = new SSCOT(con1, con2);
 		sscot.runE(predata, m, a);
+
+		// step 4
+		System.out.println(OTi.getTau() + " " + OTi.getTwoTauPow());
+		int ySegBytes = y.length / OTi.getTwoTauPow();
+		byte[][] y_array = new byte[OTi.getTwoTauPow()][];
+		for (int i = 0; i < OTi.getTwoTauPow(); i++)
+			y_array[i] = Arrays.copyOfRange(y, i * ySegBytes, (i + 1) * ySegBytes);
 	}
 
 	public void runD(PreData predata, Tree OTi, byte[] Li, byte[] Nip1, byte[] Ni, byte[] Nip1_pr) {
@@ -57,25 +59,18 @@ public class Access extends Protocol {
 		// Object[] objArray = Util.permute(pathBuckets, predata.access_sigma);
 		// pathBuckets = Arrays.copyOf(objArray, objArray.length,
 		// Bucket[].class);
-		for (int i = 0; i < pathBuckets.length; i++) {
+		for (int i = 0; i < pathBuckets.length; i++)
 			pathBuckets[i].setXor(predata.access_p[i]);
-		}
+		Tuple[] pathTuples = Bucket.bucketsToTuples(pathBuckets);
 
 		// step 2
-		con2.write(pathBuckets);
-		con2.write(Nip1);
+		con2.write(pathTuples);
+		// con2.write(Nip1);
 
 		// step 3
-		int numTuples = OTi.getStashSize() + (pathBuckets.length - 1) * OTi.getW();
-		byte[][] b = new byte[numTuples][];
-		int tupleCnt = 0;
-		for (int i = 0; i < pathBuckets.length; i++)
-			for (int j = 0; j < pathBuckets[i].getNumTuples(); j++) {
-				Tuple tuple = pathBuckets[i].getTuple(j);
-				b[tupleCnt] = ArrayUtils.addAll(tuple.getF(), tuple.getN());
-				tupleCnt++;
-			}
-		for (int i = 0; i < numTuples; i++) {
+		byte[][] b = new byte[pathTuples.length][];
+		for (int i = 0; i < pathTuples.length; i++) {
+			b[i] = ArrayUtils.addAll(pathTuples[i].getF(), pathTuples[i].getN());
 			b[i][0] ^= 1;
 			for (int j = 0; j < Ni.length; j++)
 				b[i][b[i].length - 1 - j] ^= Ni[Ni.length - 1 - j];
@@ -88,12 +83,15 @@ public class Access extends Protocol {
 	public void runC() {
 		// step 2
 		Object[] objArray = con2.readObjectArray();
-		Bucket[] pathBuckets = Arrays.copyOf(objArray, objArray.length, Bucket[].class);
-		byte[] Nip1 = con2.read();
+		Tuple[] pathTuples = Arrays.copyOf(objArray, objArray.length, Tuple[].class);
+		// byte[] Nip1 = con2.read();
 
 		// step 3
 		SSCOT sscot = new SSCOT(con1, con2);
-		sscot.runC();
+		OutSSCOT je = sscot.runC();
+		byte[] d = pathTuples[je.t].getA();
+		byte[] z = Util.xor(je.m_t, d);
+
 	}
 
 	@Override
@@ -107,7 +105,7 @@ public class Access extends Protocol {
 			tree = forest.getTree(treeIndex);
 			numBuckets = tree.getD();
 		}
-		byte[] Li = new BigInteger("101", 2).toByteArray();
+		byte[] Li = new BigInteger("11", 2).toByteArray();
 		byte[] Nip1 = new byte[] { 0 };
 		byte[] Ni = new byte[] { 0 };
 		byte[] Nip1_pr = new byte[] { 0 };

+ 11 - 0
src/protocols/OutSSIOT.java

@@ -0,0 +1,11 @@
+package protocols;
+
+public class OutSSIOT {
+	public int t;
+	public byte[] m_t;
+
+	public OutSSIOT(int t, byte[] m_t) {
+		this.t = t;
+		this.m_t = m_t;
+	}
+}

+ 17 - 0
src/protocols/PreAccess.java

@@ -16,10 +16,16 @@ public class PreAccess extends Protocol {
 	}
 
 	public void runE(PreData predata, Tree OT, int numBuckets) {
+		// SSCOT
 		int numTuples = OT.getStashSize() + (numBuckets - 1) * OT.getW();
 		PreSSCOT presscot = new PreSSCOT(con1, con2);
 		presscot.runE(predata, numTuples);
 
+		// SSIOT
+		PreSSIOT pressiot = new PreSSIOT(con1, con2);
+		pressiot.runE(predata, OT.getTwoTauPow());
+
+		// Access
 		predata.access_sigma = Util.randomPermutation(numBuckets, Crypto.sr);
 
 		int[] tupleParam = new int[] { OT.getFBytes(), OT.getNBytes(), OT.getLBytes(), OT.getABytes() };
@@ -33,17 +39,28 @@ public class PreAccess extends Protocol {
 	}
 
 	public void runD(PreData predata) {
+		// SSCOT
 		PreSSCOT presscot = new PreSSCOT(con1, con2);
 		presscot.runD(predata);
 
+		// SSIOT
+		PreSSIOT pressiot = new PreSSIOT(con1, con2);
+		pressiot.runD(predata);
+
+		// Access
 		predata.access_sigma = con1.readIntArray();
 		Object[] objArray = con1.readObjectArray();
 		predata.access_p = Arrays.copyOf(objArray, objArray.length, Bucket[].class);
 	}
 
 	public void runC() {
+		// SSCOT
 		PreSSCOT presscot = new PreSSCOT(con1, con2);
 		presscot.runC();
+
+		// SSIOT
+		PreSSIOT pressiot = new PreSSIOT(con1, con2);
+		pressiot.runC();
 	}
 
 	@Override

+ 4 - 0
src/protocols/PreData.java

@@ -7,6 +7,10 @@ public class PreData {
 	public byte[] sscot_kprime;
 	public byte[][] sscot_r;
 
+	public byte[] ssiot_k;
+	public byte[] ssiot_kprime;
+	public byte[] ssiot_r;
+
 	public int[] access_sigma;
 	public int[] access_delta;
 	public int[] access_rho;

+ 37 - 0
src/protocols/PreSSIOT.java

@@ -0,0 +1,37 @@
+package protocols;
+
+import communication.Communication;
+import crypto.Crypto;
+import crypto.PRF;
+import oram.Forest;
+import oram.Metadata;
+import util.Util;
+
+public class PreSSIOT extends Protocol {
+	public PreSSIOT(Communication con1, Communication con2) {
+		super(con1, con2);
+	}
+
+	public void runE(PreData predata, int n) {
+		predata.ssiot_k = PRF.generateKey(Crypto.sr);
+		predata.ssiot_kprime = PRF.generateKey(Crypto.sr);
+		predata.ssiot_r = Util.nextBytes(Crypto.secParamBytes, Crypto.sr);
+
+		con1.write(predata.ssiot_k);
+		con1.write(predata.ssiot_kprime);
+		con1.write(predata.ssiot_r);
+	}
+
+	public void runD(PreData predata) {
+		predata.ssiot_k = con1.read();
+		predata.ssiot_kprime = con1.read();
+		predata.ssiot_r = con1.read();
+	}
+
+	public void runC() {
+	}
+
+	@Override
+	public void run(Party party, Metadata md, Forest forest) {
+	}
+}

+ 135 - 0
src/protocols/SSIOT.java

@@ -0,0 +1,135 @@
+package protocols;
+
+import communication.Communication;
+import crypto.Crypto;
+import crypto.PRF;
+import crypto.PRG;
+import exceptions.NoSuchPartyException;
+import exceptions.SSIOTException;
+import oram.Forest;
+import oram.Metadata;
+import util.Util;
+
+public class SSIOT extends Protocol {
+	public SSIOT(Communication con1, Communication con2) {
+		super(con1, con2);
+	}
+
+	public void runE(PreData predata, byte[][] y, byte[] Nip1_pr) {
+		// step 1
+		int n = y.length;
+		int l = y[0].length * 8;
+		byte[][] x = new byte[n][];
+		byte[][] e = new byte[n][];
+		byte[][] v = new byte[n][];
+		PRF F_k = new PRF(Crypto.secParam);
+		F_k.init(predata.ssiot_k);
+		PRF F_kprime = new PRF(Crypto.secParam);
+		F_kprime.init(predata.ssiot_kprime);
+		PRG G = new PRG(l);
+
+		for (int i = 0; i < n; i++) {
+			byte[] i_bytes = Util.intToBytes(i);
+			x[i] = predata.ssiot_r.clone();
+			for (int j = 0; j < Nip1_pr.length; j++)
+				x[i][x[i].length - 1 - j] ^= Nip1_pr[Nip1_pr.length - 1 - j] ^ i_bytes[i_bytes.length - 1 - j];
+
+			e[i] = Util.xor(G.compute(F_k.compute(x[i])), y[i]);
+			v[i] = F_kprime.compute(x[i]);
+		}
+
+		con2.write(e);
+		con2.write(v);
+	}
+
+	public void runD(PreData predata, byte[] Nip1_pr) {
+		// step 2
+		PRF F_k = new PRF(Crypto.secParam);
+		F_k.init(predata.ssiot_k);
+		PRF F_kprime = new PRF(Crypto.secParam);
+		F_kprime.init(predata.ssiot_kprime);
+
+		byte[] y = predata.ssiot_r;
+		for (int i = 0; i < Nip1_pr.length; i++)
+			y[y.length - 1 - i] ^= Nip1_pr[Nip1_pr.length - 1 - i];
+		byte[] p = F_k.compute(y);
+		byte[] w = F_kprime.compute(y);
+
+		con2.write(p);
+		con2.write(w);
+	}
+
+	public OutSSIOT runC() {
+		// step 1
+		byte[][] e = con1.readDoubleByteArray();
+		byte[][] v = con1.readDoubleByteArray();
+
+		// step 2
+		byte[] p = con2.read();
+		byte[] w = con2.read();
+
+		// step 3
+		int n = e.length;
+		int l = e[0].length * 8;
+		PRG G = new PRG(l);
+		OutSSIOT output = null;
+		int invariant = 0;
+
+		for (int i = 0; i < n; i++) {
+			if (Util.equal(v[i], w)) {
+				byte[] y = Util.xor(e[i], G.compute(p));
+				output = new OutSSIOT(i, y);
+				invariant++;
+			}
+		}
+
+		if (invariant != 1)
+			throw new SSIOTException("Invariant error: " + invariant);
+		return output;
+	}
+
+	@Override
+	public void run(Party party, Metadata md, Forest forest) {
+		for (int j = 0; j < 100; j++) {
+			int twoTauPow = 64;
+			int label = 4;
+			byte[][] y = new byte[twoTauPow][label];
+			byte[] sE_Nip1_pr = new byte[1];
+			byte[] sD_Nip1_pr = new byte[1];
+			for (int i = 0; i < twoTauPow; i++)
+				Crypto.sr.nextBytes(y[i]);
+			int index = Crypto.sr.nextInt(twoTauPow);
+			Crypto.sr.nextBytes(sE_Nip1_pr);
+			sD_Nip1_pr[0] = (byte) (Util.intToBytes(index)[3] ^ sE_Nip1_pr[0]);
+
+			PreData predata = new PreData();
+			PreSSIOT pressiot = new PreSSIOT(con1, con2);
+
+			if (party == Party.Eddie) {
+				con1.write(sD_Nip1_pr);
+				con2.write(y);
+				con2.write(index);
+				pressiot.runE(predata, twoTauPow);
+				runE(predata, y, sE_Nip1_pr);
+
+			} else if (party == Party.Debbie) {
+				sD_Nip1_pr = con1.read();
+				pressiot.runD(predata);
+				runD(predata, sD_Nip1_pr);
+
+			} else if (party == Party.Charlie) {
+				y = con1.readDoubleByteArray();
+				index = con1.readInt();
+				pressiot.runC();
+				OutSSIOT output = runC();
+				if (output.t == index && Util.equal(output.m_t, y[index]))
+					System.out.println("SSIOT test passed");
+				else
+					System.err.println("SSIOT test failed");
+
+			} else {
+				throw new NoSuchPartyException(party + "");
+			}
+		}
+	}
+}

+ 3 - 0
src/ui/CLI.java

@@ -15,6 +15,7 @@ import exceptions.NoSuchPartyException;
 import protocols.Party;
 import protocols.Protocol;
 import protocols.SSCOT;
+import protocols.SSIOT;
 import protocols.Access;
 
 public class CLI {
@@ -68,6 +69,8 @@ public class CLI {
 
 		if (protocol.equals("sscot")) {
 			operation = SSCOT.class;
+		} else if (protocol.equals("ssiot")) {
+			operation = SSIOT.class;
 		} else if (protocol.equals("access")) {
 			operation = Access.class;
 		} else {

+ 50 - 0
test/protocols/TestSSIOT_C.java

@@ -0,0 +1,50 @@
+package protocols;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Arrays;
+
+public class TestSSIOT_C {
+
+	public static void main(String[] args) {
+		Runtime runTime = Runtime.getRuntime();
+		Process process = null;
+		String dir = System.getProperty("user.dir");
+		String binDir = dir + "\\bin";
+		String libs = dir + "\\lib\\*";
+		try {
+			process = runTime.exec("java -classpath " + binDir + ";" + libs + " ui.CLI -protocol ssiot charlie");
+
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		InputStream inputStream = process.getInputStream();
+		InputStreamReader isr = new InputStreamReader(inputStream);
+		InputStream errorStream = process.getErrorStream();
+		InputStreamReader esr = new InputStreamReader(errorStream);
+
+		System.out.println("STANDARD OUTPUT:");
+		int n1;
+		char[] c1 = new char[1024];
+		try {
+			while ((n1 = isr.read(c1)) > 0) {
+				System.out.print(new String(Arrays.copyOfRange(c1, 0, n1)));
+			}
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+
+		System.out.println("STANDARD ERROR:");
+		int n2;
+		char[] c2 = new char[1024];
+		try {
+			while ((n2 = esr.read(c2)) > 0) {
+				System.err.print(new String(Arrays.copyOfRange(c2, 0, n2)));
+			}
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+}

+ 50 - 0
test/protocols/TestSSIOT_D.java

@@ -0,0 +1,50 @@
+package protocols;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Arrays;
+
+public class TestSSIOT_D {
+
+	public static void main(String[] args) {
+		Runtime runTime = Runtime.getRuntime();
+		Process process = null;
+		String dir = System.getProperty("user.dir");
+		String binDir = dir + "\\bin";
+		String libs = dir + "\\lib\\*";
+		try {
+			process = runTime.exec("java -classpath " + binDir + ";" + libs + " ui.CLI -protocol ssiot debbie");
+
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		InputStream inputStream = process.getInputStream();
+		InputStreamReader isr = new InputStreamReader(inputStream);
+		InputStream errorStream = process.getErrorStream();
+		InputStreamReader esr = new InputStreamReader(errorStream);
+
+		System.out.println("STANDARD OUTPUT:");
+		int n1;
+		char[] c1 = new char[1024];
+		try {
+			while ((n1 = isr.read(c1)) > 0) {
+				System.out.print(new String(Arrays.copyOfRange(c1, 0, n1)));
+			}
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+
+		System.out.println("STANDARD ERROR:");
+		int n2;
+		char[] c2 = new char[1024];
+		try {
+			while ((n2 = esr.read(c2)) > 0) {
+				System.err.print(new String(Arrays.copyOfRange(c2, 0, n2)));
+			}
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+}

+ 50 - 0
test/protocols/TestSSIOT_E.java

@@ -0,0 +1,50 @@
+package protocols;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Arrays;
+
+public class TestSSIOT_E {
+
+	public static void main(String[] args) {
+		Runtime runTime = Runtime.getRuntime();
+		Process process = null;
+		String dir = System.getProperty("user.dir");
+		String binDir = dir + "\\bin";
+		String libs = dir + "\\lib\\*";
+		try {
+			process = runTime.exec("java -classpath " + binDir + ";" + libs + " ui.CLI -protocol ssiot eddie");
+
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		InputStream inputStream = process.getInputStream();
+		InputStreamReader isr = new InputStreamReader(inputStream);
+		InputStream errorStream = process.getErrorStream();
+		InputStreamReader esr = new InputStreamReader(errorStream);
+
+		System.out.println("STANDARD OUTPUT:");
+		int n1;
+		char[] c1 = new char[1024];
+		try {
+			while ((n1 = isr.read(c1)) > 0) {
+				System.out.print(new String(Arrays.copyOfRange(c1, 0, n1)));
+			}
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+
+		System.out.println("STANDARD ERROR:");
+		int n2;
+		char[] c2 = new char[1024];
+		try {
+			while ((n2 = esr.read(c2)) > 0) {
+				System.err.print(new String(Arrays.copyOfRange(c2, 0, n2)));
+			}
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+}

Some files were not shown because too many files changed in this diff