simple rerandomize test
parent
efde36d869
commit
b7e543e5e8
|
@ -1,4 +1,4 @@
|
||||||
#Sun Dec 27 09:28:01 IST 2015
|
#Sun Mar 20 15:13:00 IST 2016
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class CreateTestVector {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
//@Test
|
//@SimpleRerandomizeTest
|
||||||
public void createValidTest() throws IOException {
|
public void createValidTest() throws IOException {
|
||||||
|
|
||||||
List<Crypto.RerandomizableEncryptedMessage> mixerInput = generateMixerInput();
|
List<Crypto.RerandomizableEncryptedMessage> mixerInput = generateMixerInput();
|
||||||
|
@ -81,7 +81,7 @@ public class CreateTestVector {
|
||||||
System.out.println("all done");
|
System.out.println("all done");
|
||||||
}
|
}
|
||||||
|
|
||||||
//@Test
|
//@SimpleRerandomizeTest
|
||||||
public void createInvalidTest() throws IOException {
|
public void createInvalidTest() throws IOException {
|
||||||
|
|
||||||
//Mix2ZeroKnowledgeVerifier corruptedVerifier = new Verifier(encryptor,randomOracle,true);
|
//Mix2ZeroKnowledgeVerifier corruptedVerifier = new Verifier(encryptor,randomOracle,true);
|
||||||
|
|
|
@ -62,10 +62,18 @@ public class RerandomizeTest {
|
||||||
ConcreteCrypto.ElGamalCiphertext eElGamal = ECElGamalEncryption.RerandomizableEncryptedMessage2ElGamalCiphertext(e);
|
ConcreteCrypto.ElGamalCiphertext eElGamal = ECElGamalEncryption.RerandomizableEncryptedMessage2ElGamalCiphertext(e);
|
||||||
ConcreteCrypto.ElGamalCiphertext eNewElGamal = ECElGamalEncryption.RerandomizableEncryptedMessage2ElGamalCiphertext(eNew);
|
ConcreteCrypto.ElGamalCiphertext eNewElGamal = ECElGamalEncryption.RerandomizableEncryptedMessage2ElGamalCiphertext(eNew);
|
||||||
|
|
||||||
assert (g.multiply(new BigInteger(r.getData().toByteArray())).equals(
|
ECPoint expected1 = g.multiply(new BigInteger(r.getData().toByteArray()));
|
||||||
group.add(convert2ECPoint(eNewElGamal.getC1()),group.negate(convert2ECPoint(eElGamal.getC1())))));
|
ECPoint result1 = group.add(convert2ECPoint(eNewElGamal.getC1()),group.negate(convert2ECPoint(eElGamal.getC1())));
|
||||||
assert(h.multiply(new BigInteger(r.getData().toByteArray())).equals(
|
expected1.normalize();
|
||||||
group.add(convert2ECPoint(eNewElGamal.getC2()), group.negate(convert2ECPoint(eElGamal.getC2())))));
|
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
|
@Test
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue