simple rerandomize test

mixer
tzlil.gon 2016-03-20 16:15:43 +02:00
parent efde36d869
commit b7e543e5e8
4 changed files with 104 additions and 7 deletions

View File

@ -1,4 +1,4 @@
#Sun Dec 27 09:28:01 IST 2015
#Sun Mar 20 15:13:00 IST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

View File

@ -68,7 +68,7 @@ public class CreateTestVector {
}
return result;
}
//@Test
//@SimpleRerandomizeTest
public void createValidTest() throws IOException {
List<Crypto.RerandomizableEncryptedMessage> mixerInput = generateMixerInput();
@ -81,7 +81,7 @@ public class CreateTestVector {
System.out.println("all done");
}
//@Test
//@SimpleRerandomizeTest
public void createInvalidTest() throws IOException {
//Mix2ZeroKnowledgeVerifier corruptedVerifier = new Verifier(encryptor,randomOracle,true);

View File

@ -62,10 +62,18 @@ public class RerandomizeTest {
ConcreteCrypto.ElGamalCiphertext eElGamal = ECElGamalEncryption.RerandomizableEncryptedMessage2ElGamalCiphertext(e);
ConcreteCrypto.ElGamalCiphertext eNewElGamal = ECElGamalEncryption.RerandomizableEncryptedMessage2ElGamalCiphertext(eNew);
assert (g.multiply(new BigInteger(r.getData().toByteArray())).equals(
group.add(convert2ECPoint(eNewElGamal.getC1()),group.negate(convert2ECPoint(eElGamal.getC1())))));
assert(h.multiply(new BigInteger(r.getData().toByteArray())).equals(
group.add(convert2ECPoint(eNewElGamal.getC2()), group.negate(convert2ECPoint(eElGamal.getC2())))));
ECPoint expected1 = g.multiply(new BigInteger(r.getData().toByteArray()));
ECPoint result1 = group.add(convert2ECPoint(eNewElGamal.getC1()),group.negate(convert2ECPoint(eElGamal.getC1())));
expected1.normalize();
result1.normalize();
assert (expected1.equals(result1));
ECPoint expected2 = h.multiply(new BigInteger(r.getData().toByteArray()));
ECPoint result2 = group.add(convert2ECPoint(eNewElGamal.getC2()), group.negate(convert2ECPoint(eElGamal.getC2())));
expected2.normalize();
result2.normalize();
assert (expected2.equals(result2));
}
@Test

View File

@ -0,0 +1,89 @@
package mixer;
import org.bouncycastle.math.ec.ECPoint;
import org.junit.Before;
import qilin.primitives.concrete.ECGroup;
import java.math.BigInteger;
import java.util.Random;
/**
* Created by Tzlil on 3/20/2016.
*/
public class SimpleRerandomizeTest {
Random rand;
ECGroup group;
ECPoint g ;
ECPoint h ;
BigInteger sk;
@Before
public void setup() throws Exception {
rand = new Random();
group = new ECGroup("secp256k1");
g = group.getGenerator();
sk = random();
h = g.multiply(sk);
}
public BigInteger random(){
return new BigInteger(256,rand).mod(group.orderUpperBound());
}
public ECPoint randomMessage(){
return group.sample(rand);
}
public Encryption encrypt(ECPoint message,BigInteger randomness){
return new Encryption(g.multiply(randomness), message.add(h.multiply(randomness)));
}
public Encryption rerandomize(Encryption encryption,BigInteger randomness){
return new Encryption(encryption.a.add(g.multiply(randomness)),encryption.b.add(h.multiply(randomness)));
}
public ECPoint decrypt(Encryption encryption){
return encryption.a.multiply(sk).negate().add(encryption.b);
}
public class Encryption{
ECPoint a,b;
Encryption(ECPoint a, ECPoint b){
this.a = a;
this.b = b;
}
}
public void oneRerandomizeTest(){
ECPoint message = randomMessage();
Encryption e = encrypt(message,random());
BigInteger r = random();
Encryption eNew = rerandomize(e,r);
assert (decrypt(e).equals(message));
assert (decrypt(eNew).equals(message));
ECPoint expected1 = g.multiply(r);
ECPoint result1 = group.add(eNew.a,e.a.negate());
expected1.normalize();
result1.normalize();
assert (expected1.equals(result1));
ECPoint expected2 = h.multiply(r);
ECPoint result2 = group.add(eNew.b,e.b.negate());
expected2.normalize();
result2.normalize();
assert (expected2.equals(result2));
}
@org.junit.Test
public void rerandomizeTest(){
int tests = 1000;
for (int i = 0; i < tests; i ++){
System.out.println("rerandomize test #" + i);
oneRerandomizeTest();
}
}
}