1
0
Fork 0

fixed stuff

This commit is contained in:
Alexander Munch-Hansen 2019-12-01 13:46:06 +01:00
parent 306f2d660b
commit 4ec05cf83a
3 changed files with 93 additions and 1 deletions

View file

@ -9,6 +9,24 @@ import java.util.Arrays;
public class Driver {
private static int[] generalInterPolyTest(int index) {
PIRSettings settings = new PIRSettings(8, 3, 1);
int s = settings.getS();
System.out.println("s is: " + s);
InterPolyDatabase database = new InterPolyDatabase(settings, new int[] {0,0, 1,0, 0,0, 0,1});
InterPolyServer[] servers = new InterPolyServer[settings.getNumServers()];
for (int i = 0; i < settings.getNumServers(); i++) {
servers[i] = new InterPolyServer(database, settings);
}
InterPolyClient client = new InterPolyClient(settings, servers);
int[] res = client.receive(index);
System.out.println("res: " + Arrays.toString(res));
return res;
}
private static int[] generalBlockInterPolyTest(int index) {
PIRSettings settings = new PIRSettings(8, 3, 2);
int s = settings.getS();
System.out.println("s is: " + s);
@ -26,8 +44,27 @@ public class Driver {
return res;
}
private static int[] generalBlockInterPolyTestButBetter(int record) {
PIRSettings settings = new PIRSettings(8, 3, 2);
int s = settings.getS();
System.out.println("s is: " + s);
InterPolyDatabase database = new InterPolyDatabase(settings, new int[] {0,0, 1,1, 0,0, 0,1});
InterPolyServer[] servers = new InterPolyServer[settings.getNumServers()];
for (int i = 0; i < settings.getNumServers(); i++) {
servers[i] = new InterPolyServer(database, settings);
}
InterPolyClient client = new InterPolyClient(settings, servers);
int[] res = client.receiveBlock(record);
System.out.println("res: " + Arrays.toString(res));
return res;
}
public static void main(String[] args) {
generalInterPolyTest(1);
generalBlockInterPolyTestButBetter(1);
/*
int sum = 0;
for (int i = 0; i < 1; i++) {

View file

@ -6,6 +6,7 @@ import dk.au.pir.utils.FieldElement;
import dk.au.pir.utils.FieldElementLagrange;
import java.math.BigInteger;
import java.util.Arrays;
import static dk.au.pir.utils.ProtocolUtils.printIntArrayArray;
@ -35,6 +36,15 @@ public class InterPolyClient {
return fieldElements;
}
private FieldElement[][] getRandomFieldElementsBlock() {
FieldElement[][] fieldElements = new FieldElement[this.settings.getBlocksize()][this.s];
for (int i = 0; i < this.settings.getBlocksize(); i++) {
fieldElements[i] = getRandomFieldElements();
}
return fieldElements;
}
private FieldElement[] getGs(int index, int serverNumber, FieldElement[] random) {
FieldElement[] gs = new FieldElement[this.s];
int[] i = this.sequences[index];
@ -63,4 +73,36 @@ public class InterPolyClient {
}
return results;
}
public int[] receiveBlock(int record) {
int[] results = new int[settings.getBlocksize()];
FieldElement[][] randoms = this.getRandomFieldElementsBlock();
FieldElement[][] Fs = new FieldElement[this.servers.length][settings.getBlocksize()];
/**
* 1) Compute all the Gs for each server, s.t. the first index should be the blocksize and it should contain all the Gs for the given index
*/
for (int z = 0; z < this.servers.length; z++) {
FieldElement[][] Gs = new FieldElement[settings.getBlocksize()][this.s];
for (int i = 0; i < settings.getBlocksize(); i++) {
Gs[i] = this.getGs(record*settings.getBlocksize() + i, z+1, randoms[i]);
}
Fs[z] = this.servers[z].FBlock(Gs);
}
for (int i = 0; i < settings.getBlocksize(); i++) {
FieldElement[] tmp = new FieldElement[this.servers.length];
for (int z = 0; z < this.servers.length; z++) {
tmp[z] = Fs[z][i];
}
FieldElement res = FieldElementLagrange.interpolate(this.field, tmp);
results[i] = res.getValue().intValue();
}
return results;
}
}

View file

@ -30,4 +30,17 @@ public class InterPolyServer {
}
return sum;
}
public FieldElement[] FBlock(FieldElement[][] gs) {
FieldElement[] sum = new FieldElement[this.settings.getBlocksize()];
for (int i = 0; i < sum.length; i++) {
sum[i] = this.field.valueOf(0);
}
for (int i = 0; i < this.settings.getBlocksize(); i++) {
sum[i] = F(gs[i]);
}
return sum;
}
}