Commit b13eb58f authored by Gijs Van Laer's avatar Gijs Van Laer
Browse files

initial commit

parents
.DS_Store
.idea/
target/
*.iml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.jhu.isi</groupId>
<artifactId>CLSign</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.2.0.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>it.unisa.dia.gas</groupId>
<artifactId>jpbc-api</artifactId>
<version>2.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jpbc/jpbc-api-2.0.0.jar</systemPath>
</dependency>
<dependency>
<groupId>it.unisa.dia.gas</groupId>
<artifactId>jpbc-plaf</artifactId>
<version>2.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jpbc/jpbc-plaf-2.0.0.jar</systemPath>
</dependency>
<dependency>
<groupId>it.unisa.dia.gas</groupId>
<artifactId>jpbc-pbc</artifactId>
<version>2.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jpbc/jpbc-pbc-2.0.0.jar</systemPath>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>.</directory>
<includes>
<include>lib/**/*.*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package edu.jhu.isi.CLSign;
import edu.jhu.isi.CLSign.entities.KeyPair;
import edu.jhu.isi.CLSign.entities.PublicKey;
import edu.jhu.isi.CLSign.entities.SecretKey;
import edu.jhu.isi.CLSign.entities.Signature;
import it.unisa.dia.gas.jpbc.Element;
import it.unisa.dia.gas.jpbc.Pairing;
import it.unisa.dia.gas.jpbc.PairingParameters;
import it.unisa.dia.gas.plaf.jpbc.field.z.ZrElement;
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory;
import it.unisa.dia.gas.plaf.jpbc.pairing.a.TypeACurveGenerator;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class CLSign {
public static KeyPair keyGen(final int messageSize) {
final Pairing pairing = createPairing();
final SecretKey sk = createSecretKey(pairing, messageSize);
final PublicKey pk = createPublicKey(pairing, sk);
return new KeyPair(pk, sk);
}
private static PublicKey createPublicKey(final Pairing pairing, final SecretKey sk) {
final Element generator = pairing.getG1().newRandomElement();
final Element generatorT = pairing.getGT().newRandomElement();
final List<Element> Z = sk.getZ().stream()
.map(generator::powZn).collect(Collectors.toList());
return new PublicKey(pairing, generator, generatorT,
generator.powZn(sk.getX()), generator.powZn(sk.getY()), Z);
}
private static SecretKey createSecretKey(final Pairing pairing, final int messageSize) {
final ZrElement[] z = new ZrElement[messageSize];
for (int i = 0; i < messageSize; i++) {
z[i] = (ZrElement) pairing.getZr().newZeroElement();
}
return new SecretKey((ZrElement) pairing.getZr().newRandomElement(),
(ZrElement) pairing.getZr().newRandomElement(), z);
}
private static Pairing createPairing() {
int rBits = 160;
int qBits = 512;
final TypeACurveGenerator pairingGenerator = new TypeACurveGenerator(rBits, qBits);
final PairingParameters params = pairingGenerator.generate();
return PairingFactory.getPairing(params);
}
public static Signature sign(final List<ZrElement> messages, final SecretKey sk, final PublicKey pk) {
final Element a = pk.getPairing().getG1().newRandomElement();
final List<Element> A = sk.getZ().stream().map(a::powZn).collect(Collectors.toCollection(ArrayList::new));
final Element b = a.powZn(sk.getY());
final List<Element> B = A.stream().map(Ai -> Ai.powZn(sk.getY())).collect(Collectors.toCollection(ArrayList::new));
final Element cPart = pk.getPairing().getG1().newOneElement();
final ZrElement xTimesY = sk.getX().mul(sk.getY());
for (int i = 1; i < messages.size(); i++) {
cPart.mul(A.get(i).powZn(xTimesY.mul(messages.get(i))));
}
final Element c = a.powZn(sk.getX().add(xTimesY.mul(messages.get(0)))).mul(cPart);
return new Signature(a, b, c, A, B);
}
public static boolean verify(final List<ZrElement> messages, final Signature sigma, final PublicKey pk) {
return false;
}
}
package edu.jhu.isi.CLSign.entities;
public class KeyPair {
private PublicKey pk;
private SecretKey sk;
public KeyPair(final PublicKey pk, final SecretKey sk) {
this.pk = pk;
this.sk = sk;
}
public PublicKey getPk() {
return pk;
}
public SecretKey getSk() {
return sk;
}
}
package edu.jhu.isi.CLSign.entities;
import it.unisa.dia.gas.jpbc.Element;
import it.unisa.dia.gas.jpbc.Pairing;
import java.util.ArrayList;
import java.util.List;
public class PublicKey {
private Pairing pairing;
private Element generator;
private Element generatorT;
private Element X;
private Element Y;
private List<Element> Z = new ArrayList<>();
public PublicKey(final Pairing pairing, final Element generator, final Element generatorT, final Element x, final Element y, final List<Element> z) {
this.pairing = pairing;
this.generator = generator;
this.generatorT = generatorT;
X = x;
Y = y;
Z = z;
}
public Pairing getPairing() {
return pairing;
}
public Element getGenerator() {
return generator;
}
public Element getGeneratorT() {
return generatorT;
}
public Element getX() {
return X;
}
public Element getY() {
return Y;
}
public Element getZ(final int index) {
return Z.get(index);
}
public List<Element> getZ() {
return Z;
}
}
package edu.jhu.isi.CLSign.entities;
import it.unisa.dia.gas.plaf.jpbc.field.z.ZrElement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class SecretKey {
private ZrElement x;
private ZrElement y;
private List<ZrElement> z = new ArrayList<ZrElement>();
public SecretKey(final ZrElement x, final ZrElement y, final ZrElement... z) {
this.x = x;
this.y = y;
this.z = Arrays.asList(z);
}
public ZrElement getX() {
return x;
}
public ZrElement getY() {
return y;
}
public ZrElement getZ(final int index) {
return z.get(index);
}
public List<ZrElement> getZ() {
return z;
}
}
package edu.jhu.isi.CLSign.entities;
import it.unisa.dia.gas.jpbc.Element;
import java.util.ArrayList;
import java.util.List;
public class Signature {
private Element a;
private Element b;
private Element c;
private List<Element> A = new ArrayList<>();
private List<Element> B = new ArrayList<>();
public Signature(final Element a, final Element b, final Element c, final List<Element> a1, final List<Element> b1) {
this.a = a;
this.b = b;
this.c = c;
A = a1;
B = b1;
}
public Element getA() {
return a;
}
public Element getB() {
return b;
}
public Element getC() {
return c;
}
public Element getA(final int index) {
return A.get(index);
}
public Element getB(final int index) {
return B.get(index);
}
}
package edu.jhu.isi.CLSign;
import edu.jhu.isi.CLSign.entities.KeyPair;
import edu.jhu.isi.CLSign.entities.PublicKey;
import edu.jhu.isi.CLSign.entities.SecretKey;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class CLSignTest {
@Test
public void testKeyGen() throws Exception {
final int messageSize = 5;
final KeyPair keyPair = CLSign.keyGen(messageSize);
final PublicKey pk = keyPair.getPk();
final SecretKey sk = keyPair.getSk();
assertNotNull(pk);
assertNotNull(sk);
assertEquals(messageSize, sk.getZ().size());
assertEquals(messageSize, pk.getZ().size());
assertEquals(pk.getGenerator().powZn(sk.getX()), pk.getX());
assertEquals(pk.getGenerator().powZn(sk.getY()), pk.getY());
for (int i = 0; i < messageSize; i++) {
assertEquals(pk.getGenerator().powZn(sk.getZ(i)), pk.getZ(i));
}
assertEquals(pk.getPairing().getG1(), pk.getPairing().getG2());
}
@Test
public void testSign() throws Exception {
}
@Test
public void testVerify() throws Exception {
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment