mixing test passed
parent
b7e543e5e8
commit
e27fddcf0c
|
@ -146,4 +146,8 @@ public class ECElGamalEncryption extends GlobalCryptoSetup implements Encryption
|
|||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public BigInteger extractRandomness(Crypto.EncryptionRandomness encryptionRandomness){
|
||||
return new BigInteger(1,encryptionRandomness.getData().toByteArray());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import meerkat.protobuf.Mixing;
|
|||
* Created by Tzlil on 1/18/2016.
|
||||
*/
|
||||
public interface MixerOutput {
|
||||
public Mixing.ZeroKnowledgeProof[][] gerProofs();
|
||||
public Mixing.ZeroKnowledgeProof[][] getProofs();
|
||||
public Crypto.RerandomizableEncryptedMessage[][] getEncryptedMessages();
|
||||
public int getN();
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public class BatchConverter {
|
|||
.setData(Integer2ByteString(n))
|
||||
.build());
|
||||
|
||||
for (Mixing.ZeroKnowledgeProof[] zkpLayer : mixerOutput.gerProofs()) {
|
||||
for (Mixing.ZeroKnowledgeProof[] zkpLayer : mixerOutput.getProofs()) {
|
||||
for (Mixing.ZeroKnowledgeProof zkp : zkpLayer) {
|
||||
result.add(BulletinBoardAPI.BatchData.newBuilder()
|
||||
.setData(zkp.toByteString())
|
||||
|
|
|
@ -100,11 +100,13 @@ public class Mixer implements meerkat.crypto.mixnet.Mixer {
|
|||
|
||||
protected ZeroKnowledgeProof[][] createZKPTable(int n,int layers,MixNetwork mixNetwork, RerandomizableEncryptedMessage[][] encryptionTable
|
||||
,EncryptionRandomness[][] randomnesses) throws InvalidProtocolBufferException {
|
||||
ZeroKnowledgeProof[][] proofsTable = new ZeroKnowledgeProof[layers][n];
|
||||
Switch[] switchesLayer;
|
||||
int index1,index2;
|
||||
int switchIndex = 0;
|
||||
int nDiv2 = n >> 1;
|
||||
ZeroKnowledgeProof[][] proofsTable = new ZeroKnowledgeProof[layers][nDiv2];
|
||||
|
||||
|
||||
RerandomizableEncryptedMessage e1,e2;
|
||||
EncryptionRandomness r1,r2;
|
||||
for (int layer = 0; layer < layers; layer++)
|
||||
|
@ -132,7 +134,6 @@ public class Mixer implements meerkat.crypto.mixnet.Mixer {
|
|||
public MixerOutput mix(List<RerandomizableEncryptedMessage> ciphertexts) throws InvalidProtocolBufferException {
|
||||
|
||||
int n = ciphertexts.size();
|
||||
int nDiv2 = n >> 1;
|
||||
|
||||
if (!inputBasicCheckSum(n))
|
||||
return null;
|
||||
|
|
|
@ -3,12 +3,9 @@ package mixer;
|
|||
import meerkat.protobuf.Crypto;
|
||||
import meerkat.protobuf.Mixing;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -28,7 +25,7 @@ public class MixerOutput implements meerkat.crypto.mixnet.MixerOutput{
|
|||
}
|
||||
|
||||
public MixerOutput(meerkat.crypto.mixnet.MixerOutput mixerOutput) {
|
||||
this.proofs = mixerOutput.gerProofs();
|
||||
this.proofs = mixerOutput.getProofs();
|
||||
this.encryptedMessages = mixerOutput.getEncryptedMessages();
|
||||
this.n = mixerOutput.getN();
|
||||
this.layers = (int) (2 * Math.log(n) / Math.log(2)) - 1; // layers = 2logn -1;
|
||||
|
@ -36,7 +33,7 @@ public class MixerOutput implements meerkat.crypto.mixnet.MixerOutput{
|
|||
|
||||
|
||||
@Override
|
||||
public Mixing.ZeroKnowledgeProof[][] gerProofs() {
|
||||
public Mixing.ZeroKnowledgeProof[][] getProofs() {
|
||||
return proofs;
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ public class Prover implements Mix2ZeroKnowledgeProver {
|
|||
*/
|
||||
private BigInteger hash(Mixing.ZeroKnowledgeProof.OrProof.ForRandomOracle input) {
|
||||
byte[] arr = input.toByteArray();
|
||||
return new BigInteger(this.randomOracle.hash(arr,arr.length));
|
||||
return new BigInteger(1,this.randomOracle.hash(arr,arr.length));
|
||||
}
|
||||
|
||||
|
||||
|
@ -120,7 +120,7 @@ public class Prover implements Mix2ZeroKnowledgeProver {
|
|||
ECPoint g2Tag = orProofInput.g2Tag;
|
||||
ECPoint h2Tag = orProofInput.h2Tag;
|
||||
|
||||
BigInteger r = new BigInteger(encryptor.generateRandomness(rand).getData().toByteArray()).mod(groupOrderUpperBound);
|
||||
BigInteger r = encryptor.extractRandomness(encryptor.generateRandomness(rand)).mod(groupOrderUpperBound);
|
||||
BigInteger c1,c2,z,zTag;
|
||||
ECPoint u,v,uTag,vTag;
|
||||
Mixing.ZeroKnowledgeProof.OrProof.ForRandomOracle forRandomOracle;
|
||||
|
@ -128,8 +128,8 @@ public class Prover implements Mix2ZeroKnowledgeProver {
|
|||
|
||||
switch (orProofInput.flag) {
|
||||
case left:
|
||||
c2 = new BigInteger(encryptor.generateRandomness(rand).getData().toByteArray()).mod(groupOrderUpperBound);
|
||||
zTag = new BigInteger(encryptor.generateRandomness(rand).getData().toByteArray()).mod(groupOrderUpperBound);
|
||||
c2 = encryptor.extractRandomness(encryptor.generateRandomness(rand)).mod(groupOrderUpperBound);
|
||||
zTag = encryptor.extractRandomness(encryptor.generateRandomness(rand)).mod(groupOrderUpperBound);
|
||||
//step 1
|
||||
u = group.multiply(g1, r);
|
||||
v = group.multiply(g2, r);
|
||||
|
@ -155,11 +155,11 @@ public class Prover implements Mix2ZeroKnowledgeProver {
|
|||
c1 = hash(forRandomOracle).add(group.orderUpperBound().subtract(c2)).mod(groupOrderUpperBound);
|
||||
//step 3
|
||||
//z = (r + c1 * x) % group size;
|
||||
z = r.add(c1.multiply(new BigInteger(orProofInput.x.getData().toByteArray()))).mod(groupOrderUpperBound);
|
||||
z = r.add(c1.multiply(encryptor.extractRandomness(orProofInput.x))).mod(groupOrderUpperBound);
|
||||
break;
|
||||
case right:
|
||||
c1 = new BigInteger(encryptor.generateRandomness(rand).getData().toByteArray()).mod(groupOrderUpperBound);
|
||||
z = new BigInteger(encryptor.generateRandomness(rand).getData().toByteArray()).mod(groupOrderUpperBound);
|
||||
c1 = encryptor.extractRandomness(encryptor.generateRandomness(rand)).mod(groupOrderUpperBound);
|
||||
z = encryptor.extractRandomness(encryptor.generateRandomness(rand)).mod(groupOrderUpperBound);
|
||||
//step 1
|
||||
uTag = group.multiply(g1Tag, r);
|
||||
vTag = group.multiply(g2Tag, r);
|
||||
|
@ -185,7 +185,7 @@ public class Prover implements Mix2ZeroKnowledgeProver {
|
|||
c2 = hash(forRandomOracle).add(group.orderUpperBound().subtract(c1)).mod(groupOrderUpperBound);
|
||||
//step 3
|
||||
//zTag = (r + c2 * x) % group size;
|
||||
zTag = r.add(c2.multiply(new BigInteger(orProofInput.x.getData().toByteArray()))).mod(groupOrderUpperBound);
|
||||
zTag = r.add(c2.multiply(encryptor.extractRandomness(orProofInput.x))).mod(groupOrderUpperBound);
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
|
|
|
@ -37,7 +37,7 @@ public class Verifier implements Mix2ZeroKnowledgeVerifier {
|
|||
|
||||
public BigInteger hash(Mixing.ZeroKnowledgeProof.OrProof.ForRandomOracle input) {
|
||||
byte[] arr = input.toByteArray();
|
||||
return new BigInteger(this.randomOracle.hash(arr,arr.length));
|
||||
return new BigInteger(1,this.randomOracle.hash(arr,arr.length));
|
||||
}
|
||||
/**
|
||||
* @return true iff the proof is valid
|
||||
|
|
|
@ -5,7 +5,6 @@ import meerkat.crypto.mixnet.Mix2ZeroKnowledgeVerifier;
|
|||
import meerkat.crypto.mixnet.MixerOutput;
|
||||
import meerkat.protobuf.Crypto;
|
||||
import meerkat.protobuf.Mixing;
|
||||
import qilin.util.Pair;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
|
@ -30,11 +29,16 @@ public final class VerifyTable {
|
|||
Arrays.fill(locationChecksumLayer,false);
|
||||
}
|
||||
|
||||
Mixing.ZeroKnowledgeProof[][] zeroKnowledgeProofs = mixerOutput.gerProofs();
|
||||
Mixing.ZeroKnowledgeProof[][] zeroKnowledgeProofs = mixerOutput.getProofs();
|
||||
Crypto.RerandomizableEncryptedMessage[][] rerandomizableEncryptedMessages = mixerOutput.getEncryptedMessages();
|
||||
|
||||
for (Mixing.ZeroKnowledgeProof[] zkpLayer: zeroKnowledgeProofs) {
|
||||
for (Mixing.ZeroKnowledgeProof zkp: zkpLayer) {
|
||||
for (int i = 0; i < zeroKnowledgeProofs.length ; i++){
|
||||
for (int j = 0; j < zeroKnowledgeProofs[i].length ; j ++){
|
||||
Mixing.ZeroKnowledgeProof zkp = zeroKnowledgeProofs[i][j];
|
||||
if(zkp == null){
|
||||
int ttt = 1;
|
||||
ttt++;
|
||||
}
|
||||
Mixing.ZeroKnowledgeProof.Location location = zkp.getLocation();
|
||||
index1 = location.getI();
|
||||
index2 = location.getJ();
|
||||
|
|
|
@ -53,7 +53,7 @@ public class MixingText {
|
|||
mixer = new Mixer(randomMixer,prover,encryptor);
|
||||
|
||||
// generate n
|
||||
int logN = 10; // + random.nextInt(8)
|
||||
int logN = 8; // + random.nextInt(8)
|
||||
layers = 2*logN - 1;
|
||||
n = 1 << logN;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import meerkat.protobuf.ConcreteCrypto;
|
|||
import meerkat.protobuf.Crypto;
|
||||
import meerkat.protobuf.Voting;
|
||||
import org.bouncycastle.math.ec.ECPoint;
|
||||
import org.bouncycastle.util.BigIntegers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import qilin.primitives.RandomOracle;
|
||||
|
@ -62,13 +63,13 @@ public class RerandomizeTest {
|
|||
ConcreteCrypto.ElGamalCiphertext eElGamal = ECElGamalEncryption.RerandomizableEncryptedMessage2ElGamalCiphertext(e);
|
||||
ConcreteCrypto.ElGamalCiphertext eNewElGamal = ECElGamalEncryption.RerandomizableEncryptedMessage2ElGamalCiphertext(eNew);
|
||||
|
||||
ECPoint expected1 = g.multiply(new BigInteger(r.getData().toByteArray()));
|
||||
ECPoint expected1 = g.multiply(enc.extractRandomness(r));
|
||||
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 expected2 = h.multiply(enc.extractRandomness(r));
|
||||
ECPoint result2 = group.add(convert2ECPoint(eNewElGamal.getC2()), group.negate(convert2ECPoint(eElGamal.getC2())));
|
||||
expected2.normalize();
|
||||
result2.normalize();
|
||||
|
@ -76,6 +77,7 @@ public class RerandomizeTest {
|
|||
assert (expected2.equals(result2));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void rerandomizeTest() throws InvalidProtocolBufferException {
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import qilin.primitives.generic.ElGamal;
|
|||
import qilin.util.Pair;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.PublicKey;
|
||||
import java.util.Random;
|
||||
|
|
|
@ -76,13 +76,13 @@ public class ZeroKnowledgeProofTest {
|
|||
ConcreteCrypto.ElGamalCiphertext e2TagElGamal = ECElGamalEncryption.RerandomizableEncryptedMessage2ElGamalCiphertext(e2New);
|
||||
|
||||
|
||||
assert (g.multiply(new BigInteger(r1.getData().toByteArray())).equals(
|
||||
assert (g.multiply(enc.extractRandomness(r1)).equals(
|
||||
group.add(convert2ECPoint(e1TagElGamal.getC1()),group.negate(convert2ECPoint(e1ElGamal.getC1())))));
|
||||
assert (h.multiply(new BigInteger(r1.getData().toByteArray())).equals(
|
||||
assert (h.multiply(enc.extractRandomness(r1)).equals(
|
||||
group.add(convert2ECPoint(e1TagElGamal.getC2()),group.negate(convert2ECPoint(e1ElGamal.getC2())))));
|
||||
assert (g.multiply(new BigInteger(r2.getData().toByteArray())).equals(
|
||||
assert (g.multiply(enc.extractRandomness(r2)).equals(
|
||||
group.add(convert2ECPoint(e2TagElGamal.getC1()),group.negate(convert2ECPoint(e2ElGamal.getC1())))));
|
||||
assert (h.multiply(new BigInteger(r2.getData().toByteArray())).equals(
|
||||
assert (h.multiply(enc.extractRandomness(r2)).equals(
|
||||
group.add(convert2ECPoint(e2TagElGamal.getC2()),group.negate(convert2ECPoint(e2ElGamal.getC2())))));
|
||||
|
||||
assert (verifier.verify(e1,e2,e1New,e2New,prover.prove(e1,e2,e1New,e2New,false,0,0,0,r1,r2)));
|
||||
|
|
|
@ -23,7 +23,6 @@ public class AddSub {
|
|||
BigInteger[] randoms;
|
||||
BigInteger[] randoms2;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
Random rand = new Random();
|
||||
tests = 1 << 17;
|
||||
|
@ -47,7 +46,6 @@ public class AddSub {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void AddSubProfiling() throws InvalidProtocolBufferException {
|
||||
|
||||
System.out.println("AddSub");
|
||||
|
|
|
@ -19,7 +19,7 @@ public class GenerateRandomness {
|
|||
int tests;
|
||||
ECElGamalEncryption enc;
|
||||
Random rand;
|
||||
@Before
|
||||
|
||||
public void setup() throws Exception {
|
||||
rand = new Random();
|
||||
ECGroup group = new ECGroup("secp256k1");
|
||||
|
@ -33,7 +33,6 @@ public class GenerateRandomness {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void GenerateRandomnessProfiling() throws InvalidProtocolBufferException {
|
||||
|
||||
System.out.println("GenerateRandomnessProfiling");
|
||||
|
|
|
@ -23,7 +23,6 @@ public class Modulo {
|
|||
BigInteger[] randoms;
|
||||
BigInteger orderUpperBound;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
Random rand = new Random();
|
||||
ECGroup group = new ECGroup("secp256k1");
|
||||
|
@ -41,7 +40,6 @@ public class Modulo {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ModuloProfiling() throws InvalidProtocolBufferException {
|
||||
|
||||
System.out.println("ModuloProfiling");
|
||||
|
|
|
@ -21,7 +21,6 @@ public class Mul {
|
|||
BigInteger[] randoms;
|
||||
BigInteger[] randoms2;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
Random rand = new Random();
|
||||
tests = 1 << 17;
|
||||
|
@ -45,7 +44,6 @@ public class Mul {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void MulProfiling() throws InvalidProtocolBufferException {
|
||||
|
||||
System.out.println("Mul");
|
||||
|
|
|
@ -26,7 +26,6 @@ public class SHA256 {
|
|||
BigInteger[] randoms;
|
||||
RandomOracle randomOracle;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
Random rand = new Random();
|
||||
randomOracle = new DigestOracle();
|
||||
|
@ -40,7 +39,6 @@ public class SHA256 {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void SHA256Profiling() throws InvalidProtocolBufferException {
|
||||
|
||||
System.out.println("SHA256Profiling");
|
||||
|
|
|
@ -28,7 +28,6 @@ public class ByteString2ECPoint {
|
|||
int tests;
|
||||
ConcreteCrypto.ElGamalCiphertext[] encryptedMessage;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
rand = new Random();
|
||||
group = new ECGroup("secp256k1");
|
||||
|
@ -53,7 +52,6 @@ public class ByteString2ECPoint {
|
|||
return group.decode(bs.toByteArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ByteString2ECPointProfiling() throws InvalidProtocolBufferException {
|
||||
|
||||
System.out.println("ByteString2ECPointProfiling");
|
||||
|
|
|
@ -28,7 +28,6 @@ public class RerandomizableEncryptedMessage2ElGamalCiphertext {
|
|||
int tests;
|
||||
Crypto.RerandomizableEncryptedMessage[] encryptedMessage;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
rand = new Random();
|
||||
group = new ECGroup("secp256k1");
|
||||
|
@ -48,7 +47,7 @@ public class RerandomizableEncryptedMessage2ElGamalCiphertext {
|
|||
encryptedMessage[i] = enc.encrypt(msg, enc.generateRandomness(rand));
|
||||
}
|
||||
}
|
||||
@Test
|
||||
|
||||
public void RerandomizableEncryptedMessage2ElGamalCiphertext() throws InvalidProtocolBufferException {
|
||||
|
||||
System.out.println("RerandomizableEncryptedMessage2ElGamalCiphertext");
|
||||
|
|
|
@ -26,7 +26,6 @@ public class Add {
|
|||
List<ECPoint> members1;
|
||||
List<ECPoint> members2;
|
||||
|
||||
@Before
|
||||
public void setup() throws InvalidKeySpecException {
|
||||
// initialization
|
||||
random = new Random();
|
||||
|
@ -46,7 +45,6 @@ public class Add {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addProfiling() throws InvalidProtocolBufferException {
|
||||
System.out.println("AddSub");
|
||||
System.out.println("n is : " + n);
|
||||
|
|
|
@ -25,7 +25,7 @@ public class Encode {
|
|||
private int n;
|
||||
List<ECPoint> members;
|
||||
|
||||
@Before
|
||||
|
||||
public void setup() throws InvalidKeySpecException {
|
||||
// initialization
|
||||
random = new Random();
|
||||
|
@ -41,7 +41,7 @@ public class Encode {
|
|||
members.add(group.sample(random));
|
||||
}
|
||||
}
|
||||
@Test
|
||||
|
||||
public void encodeProfiling() throws InvalidProtocolBufferException {
|
||||
System.out.println("Encode");
|
||||
System.out.println("n is : " + n);
|
||||
|
|
|
@ -26,7 +26,7 @@ public class Mul {
|
|||
private int n;
|
||||
List<ECPoint> members;
|
||||
List<BigInteger> randomnesses;
|
||||
@Before
|
||||
|
||||
public void setup() throws InvalidKeySpecException {
|
||||
// initialization
|
||||
random = new Random();
|
||||
|
@ -48,7 +48,6 @@ public class Mul {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mulProfiling() throws InvalidProtocolBufferException {
|
||||
System.out.println("Multiply");
|
||||
System.out.println("n is : " + n);
|
||||
|
|
|
@ -25,7 +25,6 @@ public class Negate {
|
|||
private int n;
|
||||
List<ECPoint> members;
|
||||
|
||||
@Before
|
||||
public void setup() throws InvalidKeySpecException {
|
||||
// initialization
|
||||
random = new Random();
|
||||
|
@ -41,7 +40,7 @@ public class Negate {
|
|||
members.add(group.sample(random));
|
||||
}
|
||||
}
|
||||
@Test
|
||||
|
||||
public void negProfiling() throws InvalidProtocolBufferException {
|
||||
System.out.println("Neg");
|
||||
System.out.println("n is : " + n);
|
||||
|
|
|
@ -34,7 +34,6 @@ public class Rerandomize {
|
|||
Crypto.EncryptionRandomness[] randomnesses;
|
||||
Crypto.RerandomizableEncryptedMessage[] encryptedMessage;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
rand = new Random();
|
||||
group = new ECGroup("secp256k1");
|
||||
|
@ -58,7 +57,6 @@ public class Rerandomize {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void RerandomizeProfiling() throws InvalidProtocolBufferException {
|
||||
|
||||
System.out.println("Rerandomiz");
|
||||
|
|
|
@ -37,7 +37,7 @@ public class ZeroKnowledgeProof {
|
|||
Crypto.EncryptionRandomness[] randomnesses;
|
||||
Crypto.RerandomizableEncryptedMessage[] encryptedMessage;
|
||||
Crypto.RerandomizableEncryptedMessage[] reencryptedMessage;
|
||||
@Before
|
||||
|
||||
public void setup() throws Exception {
|
||||
rand = new Random();
|
||||
group = new ECGroup("secp256k1");
|
||||
|
@ -70,7 +70,6 @@ public class ZeroKnowledgeProof {
|
|||
return group.decode(bs.toByteArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zeroKnowledgeProofTest() throws InvalidProtocolBufferException {
|
||||
|
||||
System.out.println("Prove");
|
||||
|
|
Loading…
Reference in New Issue