Hvad fuck er l.
This commit is contained in:
parent
42f0e12429
commit
12bd4864d0
12
pir/pom.xml
12
pir/pom.xml
|
@ -7,6 +7,18 @@
|
|||
<groupId>dk.au.pir</groupId>
|
||||
<artifactId>pir</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
package dk.alexandra.fresco.framework.builder.numeric.field;
|
||||
|
||||
import dk.alexandra.fresco.framework.util.MathUtils;
|
||||
import java.math.BigInteger;
|
||||
|
||||
/**
|
||||
* An element in a field defined by a {@link BigIntegerModulus}.
|
||||
*/
|
||||
final public class BigIntegerFieldElement implements FieldElement {
|
||||
|
||||
private static final long serialVersionUID = -6786266947587799652L;
|
||||
|
||||
private final BigInteger value;
|
||||
|
||||
private final BigIntegerModulus modulus;
|
||||
private BigIntegerFieldElement(BigInteger value, BigIntegerModulus modulus) {
|
||||
this.value = modulus.reduceModThis(value);
|
||||
this.modulus = modulus;
|
||||
}
|
||||
|
||||
private FieldElement create(BigInteger value) {
|
||||
return create(value, this.modulus);
|
||||
}
|
||||
|
||||
static FieldElement create(BigInteger value, BigIntegerModulus modulus) {
|
||||
return new BigIntegerFieldElement(value, modulus);
|
||||
}
|
||||
|
||||
static FieldElement create(long value, BigIntegerModulus modulus) {
|
||||
return create(BigInteger.valueOf(value), modulus);
|
||||
}
|
||||
|
||||
static FieldElement create(String string, BigIntegerModulus modulus) {
|
||||
return create(new BigInteger(string), modulus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldElement add(FieldElement operand) {
|
||||
return create(value.add(extractValue(operand)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldElement subtract(FieldElement operand) {
|
||||
return create(value.subtract(extractValue(operand)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldElement negate() {
|
||||
return create(getModulus().subtract(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldElement multiply(FieldElement operand) {
|
||||
return create(value.multiply(extractValue(operand)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldElement sqrt() {
|
||||
return create(MathUtils.modularSqrt(value, getModulus()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldElement modInverse() {
|
||||
return create(value.modInverse(getModulus()));
|
||||
}
|
||||
|
||||
static BigInteger extractValue(FieldElement element) {
|
||||
return ((BigIntegerFieldElement) element).value;
|
||||
}
|
||||
|
||||
public BigInteger getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
private BigInteger getModulus() {
|
||||
return modulus.getBigInteger();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BigIntegerFieldElement{"
|
||||
+ "value=" + value
|
||||
+ ", modulus=" + modulus
|
||||
+ '}';
|
||||
}
|
||||
}
|
13
pir/src/main/java/dk/au/pir/Driver.java
Normal file
13
pir/src/main/java/dk/au/pir/Driver.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package dk.au.pir;
|
||||
|
||||
import dk.alexandra.fresco.framework.builder.numeric.field.FieldElement;
|
||||
import dk.au.pir.protocols.interpoly.InterPolyClient;
|
||||
|
||||
public class Driver {
|
||||
public static void main(String[] args) {
|
||||
InterPolyClient client = new InterPolyClient();
|
||||
for (FieldElement elem: client.getSRandomFieldElements()) {
|
||||
System.out.println(elem);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,35 @@
|
|||
package dk.au.pir.protocols.interpoly;
|
||||
|
||||
import dk.alexandra.fresco.framework.builder.numeric.field.BigIntegerFieldElement;
|
||||
import dk.alexandra.fresco.framework.builder.numeric.field.FieldElement;
|
||||
import dk.au.pir.settings.PIRSettings;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Random;
|
||||
|
||||
public class InterPolyClient {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Client!");
|
||||
System.out.println(PIRSettings.FIELD_DEFINITION.getBitLength());
|
||||
private final int i;
|
||||
private Random random = new Random();
|
||||
private BigIntegerFieldElement[] fieldElements = new BigIntegerFieldElement[PIRSettings.MOD_BIT_LENGTH];
|
||||
|
||||
public InterPolyClient(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public void generateSRandomFieldElements() {
|
||||
for (int i = 0; i < fieldElements.length; i++) {
|
||||
this.fieldElements[i] = (BigIntegerFieldElement) PIRSettings.FIELD_DEFINITION.createElement(new BigInteger(PIRSettings.MAX_BIT_LENGTH, random));
|
||||
}
|
||||
}
|
||||
|
||||
public FieldElement g(int l, BigIntegerFieldElement z) {
|
||||
String iString = Integer.toBinaryString(i);
|
||||
char lChar = iString.charAt(iString.length() - 1 - l); // lol
|
||||
BigIntegerFieldElement il = (BigIntegerFieldElement) PIRSettings.FIELD_DEFINITION.createElement(Character.toString(lChar));
|
||||
return fieldElements[l].multiply(z).add(il);
|
||||
}
|
||||
|
||||
public FieldElement[] getFieldElements() {
|
||||
return fieldElements;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
package dk.au.pir.protocols.interpoly;
|
||||
|
||||
public class InterPolyServer {
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,12 @@ import dk.alexandra.fresco.framework.builder.numeric.field.BigIntegerFieldDefini
|
|||
import dk.alexandra.fresco.framework.builder.numeric.field.FieldDefinition;
|
||||
import dk.alexandra.fresco.framework.util.ModulusFinder;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class PIRSettings {
|
||||
private static final int MOD_BIT_LENGTH = 16;
|
||||
public static final int MOD_BIT_LENGTH = 16; // s
|
||||
public static final int DATABASE_SIZE = (int) Math.pow(2, MOD_BIT_LENGTH); // n
|
||||
public static final int MAX_BIT_LENGTH = 512;
|
||||
|
||||
public static FieldDefinition FIELD_DEFINITION = new BigIntegerFieldDefinition(ModulusFinder.findSuitableModulus(MOD_BIT_LENGTH));
|
||||
}
|
||||
|
|
10
pir/src/main/java/dk/au/pir/utils/ProtocolUtils.java
Normal file
10
pir/src/main/java/dk/au/pir/utils/ProtocolUtils.java
Normal file
|
@ -0,0 +1,10 @@
|
|||
package dk.au.pir.utils;
|
||||
|
||||
public class ProtocolUtils {
|
||||
public static int kronecker(int i, int j) {
|
||||
if (i == j) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue