|
@@ -1,14 +1,79 @@
|
|
|
package oram;
|
|
|
|
|
|
+import java.math.BigInteger;
|
|
|
+
|
|
|
+import crypto.OramCrypto;
|
|
|
+import util.Util;
|
|
|
+
|
|
|
public class TestForest {
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
- Forest forest1 = new Forest();
|
|
|
- Forest forest2 = new Forest();
|
|
|
- Forest forest3 = forest1.xor(forest2);
|
|
|
- forest1.print();
|
|
|
- forest2.print();
|
|
|
- forest3.print();
|
|
|
+ Metadata md = new Metadata();
|
|
|
+ Forest forest = new Forest(md);
|
|
|
+ int tau = md.getTau();
|
|
|
+ int addrBits = md.getAddrBits();
|
|
|
+ long numRecords = md.getNumInsertRecords();
|
|
|
+ int numTrees = forest.getNumTrees();
|
|
|
+
|
|
|
+ int numTests = 100;
|
|
|
+ for (int n = 0; n < numTests; n++) {
|
|
|
+
|
|
|
+ long testAddr = Util.nextLong(OramCrypto.sr, numRecords);
|
|
|
+ long L = 0;
|
|
|
+ long outRecord = 0;
|
|
|
+
|
|
|
+ for (int i = 0; i < numTrees; i++) {
|
|
|
+
|
|
|
+ long N;
|
|
|
+ int indexN;
|
|
|
+ if (i == 0) {
|
|
|
+ N = 0;
|
|
|
+ indexN = Util.getSubBits(BigInteger.valueOf(testAddr), addrBits, addrBits - tau).intValue();
|
|
|
+ } else if (i < numTrees - 1) {
|
|
|
+ N = Util.getSubBits(testAddr, addrBits, addrBits - i * tau);
|
|
|
+ indexN = Util.getSubBits(BigInteger.valueOf(testAddr), addrBits - i * tau,
|
|
|
+ Math.max(addrBits - (i + 1) * tau, 0)).intValue();
|
|
|
+ } else {
|
|
|
+ N = testAddr;
|
|
|
+ indexN = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Tree tree = forest.getTree(i);
|
|
|
+ Bucket[] pathBuckets = tree.getBucketsOnPath(L);
|
|
|
+ Tuple targetTuple = null;
|
|
|
+ if (i == 0) {
|
|
|
+ targetTuple = pathBuckets[0].getTuple(0);
|
|
|
+ } else {
|
|
|
+ for (int j = 0; j < pathBuckets.length; j++) {
|
|
|
+ for (int k = 0; k < pathBuckets[j].getNumTuples(); k++) {
|
|
|
+ Tuple tuple = pathBuckets[j].getTuple(k);
|
|
|
+ if (tuple.getF()[0] == 1 && new BigInteger(1, tuple.getL()).longValue() == L
|
|
|
+ && new BigInteger(1, tuple.getN()).longValue() == N) {
|
|
|
+ targetTuple = tuple;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (targetTuple != null)
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (i < numTrees - 1)
|
|
|
+ L = new BigInteger(1,
|
|
|
+ targetTuple.getSubA(indexN * tree.getAlBytes(), (indexN + 1) * tree.getAlBytes()))
|
|
|
+ .longValue();
|
|
|
+ else
|
|
|
+ outRecord = new BigInteger(1, targetTuple.getA()).longValue();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (testAddr == outRecord)
|
|
|
+ System.out.println("Success on address " + BigInteger.valueOf(testAddr).toString(2));
|
|
|
+ else
|
|
|
+ System.err.println("Error on address " + BigInteger.valueOf(testAddr).toString(2));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|