Browse Source

grouped acc, rsf, ppt into retrieve

Boyoung- 9 years ago
parent
commit
8cb53bf007
3 changed files with 215 additions and 0 deletions
  1. 47 0
      src/protocols/PreRetrieve.java
  2. 166 0
      src/protocols/Retrieve.java
  3. 2 0
      src/ui/CLI.java

+ 47 - 0
src/protocols/PreRetrieve.java

@@ -0,0 +1,47 @@
+package protocols;
+
+import communication.Communication;
+import measure.Timer;
+import oram.Forest;
+import oram.Metadata;
+import oram.Tree;
+
+public class PreRetrieve extends Protocol {
+	public PreRetrieve(Communication con1, Communication con2) {
+		super(con1, con2);
+	}
+
+	public void runE(PreData predata, Metadata md, int ti, Tree OT, int numTuples, Timer timer) {
+		PreAccess preaccess = new PreAccess(con1, con2);
+		PreReshuffle prereshuffle = new PreReshuffle(con1, con2);
+		PrePostProcessT prepostprocesst = new PrePostProcessT(con1, con2);
+		
+		preaccess.runE(predata, OT, numTuples, timer);
+		prereshuffle.runE(predata, timer);
+		prepostprocesst.runE(predata, timer);
+	}
+
+	public void runD(PreData predata, Metadata md, int ti, PreData prev, int[] tupleParam, Timer timer) {
+		PreAccess preaccess = new PreAccess(con1, con2);
+		PreReshuffle prereshuffle = new PreReshuffle(con1, con2); 
+		PrePostProcessT prepostprocesst = new PrePostProcessT(con1, con2);
+		
+		preaccess.runD(predata, timer);
+		prereshuffle.runD(predata, tupleParam, timer);
+		prepostprocesst.runD(predata, prev, md.getLBytesOfTree(ti), md.getAlBytesOfTree(ti), md.getTau(), timer);
+	}
+
+	public void runC(PreData predata, Metadata md, int ti, PreData prev, Timer timer) {
+		PreAccess preaccess = new PreAccess(con1, con2);
+		PreReshuffle prereshuffle = new PreReshuffle(con1, con2); 
+		PrePostProcessT prepostprocesst = new PrePostProcessT(con1, con2);
+		
+		preaccess.runC(timer);
+		prereshuffle.runC(predata, timer);
+		prepostprocesst.runC(predata, prev, md.getLBytesOfTree(ti), md.getAlBytesOfTree(ti), timer);
+	}
+
+	@Override
+	public void run(Party party, Metadata md, Forest forest) {
+	}
+}

+ 166 - 0
src/protocols/Retrieve.java

@@ -0,0 +1,166 @@
+package protocols;
+
+import java.math.BigInteger;
+
+import communication.Communication;
+import crypto.Crypto;
+import exceptions.AccessException;
+import exceptions.NoSuchPartyException;
+import measure.Timer;
+import oram.Forest;
+import oram.Metadata;
+import oram.Tree;
+import oram.Tuple;
+import util.StopWatch;
+import util.Util;
+
+public class Retrieve extends Protocol {
+
+	public Retrieve(Communication con1, Communication con2) {
+		super(con1, con2);
+	}
+
+	public OutAccess runE(PreData predata, Tree OTi, byte[] Ni, byte[] Nip1_pr, int h, Timer timer) {
+		Access access = new Access(con1, con2);
+		Reshuffle reshuffle = new Reshuffle(con1, con2);
+		PostProcessT postprocesst = new PostProcessT(con1, con2);
+		
+		OutAccess outaccess =  access.runE(predata, OTi, Ni, Nip1_pr, timer);
+		Tuple[] path = reshuffle.runE(predata, outaccess.E_P, OTi.getTreeIndex() == 0, timer);
+		postprocesst.runE(predata, outaccess.E_Ti, OTi.getTreeIndex() == h-1, timer);
+		
+		return outaccess;
+	}
+
+	public void runD(PreData predata, Tree OTi, byte[] Ni, byte[] Nip1_pr, Timer timer) {
+		Access access = new Access(con1, con2);
+		Reshuffle reshuffle = new Reshuffle(con1, con2);
+		PostProcessT postprocesst = new PostProcessT(con1, con2);
+		
+		access.runD(predata, OTi, Ni, Nip1_pr, timer);
+		reshuffle.runD();
+		postprocesst.runD();
+	}
+
+	public OutAccess runC(PreData predata, Metadata md, int ti, byte[] Li, int h, Timer timer) {
+		Access access = new Access(con1, con2);
+		Reshuffle reshuffle = new Reshuffle(con1, con2);
+		PostProcessT postprocesst = new PostProcessT(con1, con2);
+		
+		OutAccess outaccess = access.runC(md, ti, Li, timer);
+		Tuple[] path = reshuffle.runC(predata, outaccess.C_P, ti == 0, timer);
+		postprocesst.runC(predata, outaccess.C_Ti, Li, outaccess.C_Lip1, outaccess.C_j2, ti == h-1, timer);
+		
+		return outaccess;
+	}
+
+	// for testing correctness
+	@Override
+	public void run(Party party, Metadata md, Forest forest) {
+		int records = 5;
+		int repeat = 5;
+
+		int tau = md.getTau();
+		int numTrees = md.getNumTrees();
+		long numInsert = md.getNumInsertRecords();
+		int addrBits = md.getAddrBits();
+
+		Timer timer = new Timer();
+		StopWatch sw = new StopWatch();
+
+		sanityCheck();
+
+		System.out.println();
+
+		for (int i = 0; i < records; i++) {
+			long N = Util.nextLong(numInsert, Crypto.sr);
+
+			for (int j = 0; j < repeat; j++) {
+				System.out.println("Test: " + i + " " + j);
+				System.out.println("N=" + BigInteger.valueOf(N).toString(2));
+
+				byte[] Li = new byte[0];
+
+				PreData prev = null;
+
+				for (int ti = 0; ti < numTrees; ti++) {
+					long Ni_value = Util.getSubBits(N, addrBits, addrBits - md.getNBitsOfTree(ti));
+					long Nip1_pr_value = Util.getSubBits(N, addrBits - md.getNBitsOfTree(ti),
+							Math.max(addrBits - md.getNBitsOfTree(ti) - tau, 0));
+					byte[] Ni = Util.longToBytes(Ni_value, md.getNBytesOfTree(ti));
+					byte[] Nip1_pr = Util.longToBytes(Nip1_pr_value, (tau + 7) / 8);
+
+					PreData predata = new PreData();
+					PreRetrieve preretrieve = new PreRetrieve(con1, con2);
+
+					if (party == Party.Eddie) {
+						Tree OTi = forest.getTree(ti);
+						int numTuples = (OTi.getD() - 1) * OTi.getW() + OTi.getStashSize();
+						preretrieve.runE(predata, md, ti, OTi, numTuples, timer);
+
+						byte[] sE_Ni = Util.nextBytes(Ni.length, Crypto.sr);
+						byte[] sD_Ni = Util.xor(Ni, sE_Ni);
+						con1.write(sD_Ni);
+
+						byte[] sE_Nip1_pr = Util.nextBytes(Nip1_pr.length, Crypto.sr);
+						byte[] sD_Nip1_pr = Util.xor(Nip1_pr, sE_Nip1_pr);
+						con1.write(sD_Nip1_pr);
+
+						sw.start();
+						runE(predata, OTi, sE_Ni, sE_Nip1_pr, numTrees, timer);
+						sw.stop();
+
+						if (ti == numTrees - 1)
+							con2.write(N);
+
+					} else if (party == Party.Debbie) {
+						Tree OTi = forest.getTree(ti);
+						int[] tupleParam = new int[] { ti == 0 ? 0 : 1, md.getNBytesOfTree(ti), md.getLBytesOfTree(ti),
+								md.getABytesOfTree(ti) };
+						preretrieve.runD(predata, md, ti, prev, tupleParam, timer);
+
+						byte[] sD_Ni = con1.read();
+
+						byte[] sD_Nip1_pr = con1.read();
+
+						sw.start();
+						runD(predata, OTi, sD_Ni, sD_Nip1_pr, timer);
+						sw.stop();
+
+					} else if (party == Party.Charlie) {
+						preretrieve.runC(predata, md, ti, prev, timer);
+
+						System.out.println("L" + ti + "=" + new BigInteger(1, Li).toString(2));
+
+						sw.start();
+						OutAccess outaccess = runC(predata, md, ti, Li, numTrees, timer);
+						sw.stop();
+
+						Li = outaccess.C_Lip1;
+
+						if (ti == numTrees - 1) {
+							N = con1.readObject();
+							long data = new BigInteger(1, outaccess.C_Ti.getA()).longValue();
+							if (N == data) {
+								System.out.println("Access passed");
+								System.out.println();
+							} else {
+								throw new AccessException("Access failed");
+							}
+						}
+
+					} else {
+						throw new NoSuchPartyException(party + "");
+					}
+
+					prev = predata;
+				}
+			}
+		}
+
+		//timer.print();
+
+		//System.out.println();
+		//System.out.println(sw.toMS());
+	}
+}

+ 2 - 0
src/ui/CLI.java

@@ -87,6 +87,8 @@ public class CLI {
 			operation = PrepareTarget.class;
 		} else if (protocol.equals("mc")) {
 			operation = MakeCycle.class;
+		} else if (protocol.equals("rtv")) {
+			operation = Retrieve.class;
 		} else {
 			System.out.println("Protocol " + protocol + " not supported");
 			System.exit(-1);