diff --git a/meerkat-common/src/main/proto/meerkat/voting.proto b/meerkat-common/src/main/proto/meerkat/voting.proto index 6e03a5b..0907adc 100644 --- a/meerkat-common/src/main/proto/meerkat/voting.proto +++ b/meerkat-common/src/main/proto/meerkat/voting.proto @@ -123,7 +123,7 @@ message ElectionParams { // Verification keys for valid mixers. repeated SignatureVerificationKey mixerVerificationKeys = 4; - // How many mixers must participate for the mixing to be considered valid + // How many mixers must participate for the network to be considered valid uint32 mixerThreshold = 5; // questions to first indicate the voter's channel diff --git a/mixer/src/main/java/meerkat/crypto/mixnet/Trustee.java b/mixer/src/main/java/meerkat/crypto/mixnet/Trustee.java deleted file mode 100644 index e8044cd..0000000 --- a/mixer/src/main/java/meerkat/crypto/mixnet/Trustee.java +++ /dev/null @@ -1,7 +0,0 @@ -package meerkat.crypto.mixnet; - -/** - * Created by talm on 25/10/15. - */ -public class Trustee { -} diff --git a/mixer/src/main/java/meerkat/crypto/mixnet/Verifier.java b/mixer/src/main/java/meerkat/crypto/mixnet/Verifier.java deleted file mode 100644 index b733317..0000000 --- a/mixer/src/main/java/meerkat/crypto/mixnet/Verifier.java +++ /dev/null @@ -1,7 +0,0 @@ -package meerkat.crypto.mixnet; - -/** - * Created by talm on 25/10/15. - */ -public class Verifier { -} diff --git a/mixer/src/main/java/meerkat/mixer/mixing/Mixer.java b/mixer/src/main/java/meerkat/mixer/MixGenerator.java similarity index 90% rename from mixer/src/main/java/meerkat/mixer/mixing/Mixer.java rename to mixer/src/main/java/meerkat/mixer/MixGenerator.java index 5f013e3..e4787d6 100644 --- a/mixer/src/main/java/meerkat/mixer/mixing/Mixer.java +++ b/mixer/src/main/java/meerkat/mixer/MixGenerator.java @@ -1,9 +1,12 @@ -package meerkat.mixer.mixing; +package meerkat.mixer; import com.google.protobuf.InvalidProtocolBufferException; import meerkat.crypto.Encryption; import meerkat.crypto.mixnet.Mix2ZeroKnowledgeProver; import meerkat.crypto.mixnet.MixerOutput; +import meerkat.mixer.network.BenesNetwork; +import meerkat.mixer.network.PermutationNetwork; +import meerkat.mixer.network.RandomPermutation; import meerkat.protobuf.Crypto.EncryptionRandomness; import meerkat.protobuf.Crypto.RerandomizableEncryptedMessage; import meerkat.protobuf.Mixing.Mix2Proof; @@ -13,7 +16,7 @@ import java.util.Random; /** * an implementation of meerkat.crypto.mixnet.Mixer - * meerkat.mixer.mixing algorithm on set of n encrypted votes: + * meerkat.mixer.network algorithm on set of n encrypted votes: * 0. asset n is power of two * 1. set switches according to benes network on random permutation * 2. re encrypt and mix with respect to switches values (encryptor.rerandomize) @@ -21,7 +24,7 @@ import java.util.Random; * 4. return proofs table + encryption table * */ -public class Mixer implements meerkat.crypto.mixnet.Mixer { +public class MixGenerator implements meerkat.crypto.mixnet.Mixer { private final Mix2ZeroKnowledgeProver prover; private final Encryption encryptor; @@ -31,7 +34,7 @@ public class Mixer implements meerkat.crypto.mixnet.Mixer { * @param prover * @param encryptor */ - public Mixer(Mix2ZeroKnowledgeProver prover, Encryption encryptor) { + public MixGenerator(Mix2ZeroKnowledgeProver prover, Encryption encryptor) { this.prover = prover; this.encryptor = encryptor; } @@ -99,10 +102,9 @@ public class Mixer implements meerkat.crypto.mixnet.Mixer { * @param randomnesses an initialized randomness table of size layers * n, use for rerandomize operations * @throws InvalidProtocolBufferException */ - private void rerandomize(PermutationNetwork mixNetwork, RerandomizableEncryptedMessage[][] encryptionTable - ,EncryptionRandomness[][] randomnesses) throws InvalidProtocolBufferException { - Switch[] switchesLayer; - int index1,index2; + private void rerandomize(PermutationNetwork mixNetwork, + RerandomizableEncryptedMessage[][] encryptionTable, + EncryptionRandomness[][] randomnesses) throws InvalidProtocolBufferException { RerandomizableEncryptedMessage a,b; EncryptionRandomness r1,r2; int layers = mixNetwork.getNumLayers(); @@ -176,7 +178,7 @@ public class Mixer implements meerkat.crypto.mixnet.Mixer { * mix given encrypted votes using random * @param ciphertexts encrypted votes * @param random - * @return meerkat.mixer.mixing result + * @return meerkat.mixer.network result * @throws InvalidProtocolBufferException */ public MixerOutput mix(List ciphertexts,Random random) throws InvalidProtocolBufferException { @@ -195,7 +197,7 @@ public class Mixer implements meerkat.crypto.mixnet.Mixer { rerandomize(net,encryptionTable,randomnesses); Mix2Proof[][] proofsTable = generateMix2ProofTable(net,encryptionTable,randomnesses); - return new meerkat.mixer.mixing.MixerOutput(logN, proofsTable, encryptionTable); + return new meerkat.mixer.MixerOutput(logN, proofsTable, encryptionTable); } } \ No newline at end of file diff --git a/mixer/src/main/java/meerkat/mixer/proofs/VerifyTable.java b/mixer/src/main/java/meerkat/mixer/MixVerifier.java similarity index 93% rename from mixer/src/main/java/meerkat/mixer/proofs/VerifyTable.java rename to mixer/src/main/java/meerkat/mixer/MixVerifier.java index 4d58fee..8ddd956 100644 --- a/mixer/src/main/java/meerkat/mixer/proofs/VerifyTable.java +++ b/mixer/src/main/java/meerkat/mixer/MixVerifier.java @@ -1,4 +1,4 @@ -package meerkat.mixer.proofs; +package meerkat.mixer; import com.google.protobuf.InvalidProtocolBufferException; import meerkat.crypto.mixnet.Mix2ZeroKnowledgeVerifier; @@ -10,14 +10,14 @@ import java.util.Arrays; /** * Created by Tzlil on 12/30/2015. - * provide one operation - verify meerkat.mixer.mixing output + * provide one operation - verify meerkat.mixer.network output */ -public final class VerifyTable { +public final class MixVerifier { /** * constructor * @param verifier * @param mixerOutput - * @return true iff the meerkat.mixer.mixing output is valid + * @return true iff the meerkat.mixer.network output is valid * @throws InvalidProtocolBufferException */ public static boolean verifyTable(Mix2ZeroKnowledgeVerifier verifier, MixerOutput mixerOutput) diff --git a/mixer/src/main/java/meerkat/mixer/MixerOutput.java b/mixer/src/main/java/meerkat/mixer/MixerOutput.java new file mode 100644 index 0000000..356bc05 --- /dev/null +++ b/mixer/src/main/java/meerkat/mixer/MixerOutput.java @@ -0,0 +1,52 @@ +package meerkat.mixer; + +import meerkat.protobuf.Crypto; +import meerkat.protobuf.Mixing; + +import java.io.OutputStream; + + +/** + * Created by Tzlil on 1/18/2016. + * implements meerkat.crypto.mixnet.MixerOutput interface + * container for meerkat.mixer.network.mix result. + */ +public class MixerOutput implements meerkat.crypto.mixnet.MixerOutput { + private final Mixing.Mix2Proof[][] proofs; + private final Crypto.RerandomizableEncryptedMessage[][] encryptedMessages; + private final int logN; + + /** + * constructor + * @param logN log (base 2) of the number of votes + * @param encryptedMessages at level 0 , contains the original encrypted votes + * at each other level contains the re encrypted votes + * @param proofs in each cell (level,switch) contains the match zero knowledge proof + */ + public MixerOutput(int logN, Mixing.Mix2Proof[][] proofs, + Crypto.RerandomizableEncryptedMessage[][] encryptedMessages) { + this.proofs = proofs; + this.encryptedMessages = encryptedMessages; + this.logN = logN; + } + + @Override + public Mixing.Mix2Proof[][] getProofs() { + return proofs; + } + + @Override + public Crypto.RerandomizableEncryptedMessage[][] getEncryptedMessages() { + return encryptedMessages; + } + + @Override + public int getLogN() { + return logN; + } + + @Override + public int getNumLayers() { + return 2 * logN - 1; + } +} diff --git a/mixer/src/main/java/meerkat/mixer/main/BatchConverter.java b/mixer/src/main/java/meerkat/mixer/main/BatchConverter.java index b61c4c5..a611b22 100644 --- a/mixer/src/main/java/meerkat/mixer/main/BatchConverter.java +++ b/mixer/src/main/java/meerkat/mixer/main/BatchConverter.java @@ -1,24 +1,22 @@ package meerkat.mixer.main; -import com.google.protobuf.ByteString; import meerkat.crypto.mixnet.MixerOutput; import meerkat.protobuf.BulletinBoardAPI; import meerkat.protobuf.Crypto; import meerkat.protobuf.Mixing; -import java.math.BigInteger; import java.util.ArrayList; import java.util.List; /** * Created by Tzlil on 12/17/2015. - * provide convert operation from batch data to meerkat.mixer.mixing output and backwards + * provide convert operation from batch data to meerkat.mixer.network output and backwards */ public class BatchConverter { /** - * convert meerkat.mixer.mixing output to batch data + * convert meerkat.mixer.network output to batch data * @param mixerOutput - * @return meerkat.mixer.mixing output as list of batch data + * @return meerkat.mixer.network output as list of batch data */ public List MixerOutput2BatchChunk(MixerOutput mixerOutput) { @@ -51,7 +49,7 @@ public class BatchConverter { } /** - * convert batch data list to meerkat.mixer.mixing output + * convert batch data list to meerkat.mixer.network output * @param batchChunkList * @return batch data list as MixerOutput * @throws Exception @@ -85,7 +83,7 @@ public class BatchConverter { } } - return new meerkat.mixer.mixing.MixerOutput(logN, proofs,encryptions); + return new meerkat.mixer.MixerOutput(logN, proofs,encryptions); } diff --git a/mixer/src/main/java/meerkat/mixer/main/BatchHandler.java b/mixer/src/main/java/meerkat/mixer/main/BatchHandler.java index c9d72d9..4aeb582 100644 --- a/mixer/src/main/java/meerkat/mixer/main/BatchHandler.java +++ b/mixer/src/main/java/meerkat/mixer/main/BatchHandler.java @@ -5,7 +5,7 @@ import meerkat.crypto.mixnet.MixerOutput; import meerkat.protobuf.Crypto; import meerkat.mixer.necessary.AsyncBulletinBoardClient; import meerkat.mixer.necessary.CompleteBatch; -import meerkat.mixer.proofs.VerifyTable; +import meerkat.mixer.MixVerifier; import java.util.Arrays; import java.util.List; @@ -61,7 +61,7 @@ public class BatchHandler implements AsyncBulletinBoardClient.ClientCallback= 0) - fileName = encDir+"/layer" + layer +"/" + i; - else - fileName = encDir+"/input/" + i; - - File file = new File(fileName); - file.createNewFile(); - FileOutputStream fos = new FileOutputStream(file); - fos.write(enc.toByteArray()); - fos.close(); - } -} diff --git a/mixer/src/main/java/meerkat/mixer/mixing/Switch.java b/mixer/src/main/java/meerkat/mixer/mixing/Switch.java deleted file mode 100644 index 5de522e..0000000 --- a/mixer/src/main/java/meerkat/mixer/mixing/Switch.java +++ /dev/null @@ -1,36 +0,0 @@ -package meerkat.mixer.mixing; - -/** - * Created by Tzlil on 12/15/2015. - * container for switch - */ -public class Switch{ - - public final int i, j, layer; - public final boolean value; - - /** - * constructor - * @param i - * @param j - * @param layer - * @param value the switch is on or off - */ - public Switch(int i, int j, int layer, boolean value) { - this.i = i; - this.j = j; - this.layer = layer; - this.value = value; - } - - - @Override - public String toString() { - return "Switch{" + - "i=" + i + - ", j=" + j + - ", layer=" + layer + - ", value=" + value + - '}'; - } -} diff --git a/mixer/src/main/java/meerkat/mixer/mixing/BenesNetwork.java b/mixer/src/main/java/meerkat/mixer/network/BenesNetwork.java similarity index 99% rename from mixer/src/main/java/meerkat/mixer/mixing/BenesNetwork.java rename to mixer/src/main/java/meerkat/mixer/network/BenesNetwork.java index ded8997..e467fd8 100644 --- a/mixer/src/main/java/meerkat/mixer/mixing/BenesNetwork.java +++ b/mixer/src/main/java/meerkat/mixer/network/BenesNetwork.java @@ -1,4 +1,4 @@ -package meerkat.mixer.mixing; +package meerkat.mixer.network; import java.util.*; diff --git a/mixer/src/main/java/meerkat/mixer/mixing/PermutationNetwork.java b/mixer/src/main/java/meerkat/mixer/network/PermutationNetwork.java similarity index 96% rename from mixer/src/main/java/meerkat/mixer/mixing/PermutationNetwork.java rename to mixer/src/main/java/meerkat/mixer/network/PermutationNetwork.java index 4dc1e0e..c4cad88 100644 --- a/mixer/src/main/java/meerkat/mixer/mixing/PermutationNetwork.java +++ b/mixer/src/main/java/meerkat/mixer/network/PermutationNetwork.java @@ -1,6 +1,4 @@ -package meerkat.mixer.mixing; - -import java.util.ArrayList; +package meerkat.mixer.network; /** * A generic permutation network composed of 2-input switches. diff --git a/mixer/src/main/java/meerkat/mixer/mixing/RandomPermutation.java b/mixer/src/main/java/meerkat/mixer/network/RandomPermutation.java similarity index 94% rename from mixer/src/main/java/meerkat/mixer/mixing/RandomPermutation.java rename to mixer/src/main/java/meerkat/mixer/network/RandomPermutation.java index 537fae2..55a491d 100644 --- a/mixer/src/main/java/meerkat/mixer/mixing/RandomPermutation.java +++ b/mixer/src/main/java/meerkat/mixer/network/RandomPermutation.java @@ -1,7 +1,5 @@ -package meerkat.mixer.mixing; +package meerkat.mixer.network; -import java.util.ArrayList; -import java.util.List; import java.util.Random; /** diff --git a/mixer/src/main/java/meerkat/mixer/mixing/Util.java b/mixer/src/main/java/meerkat/mixer/network/Util.java similarity index 96% rename from mixer/src/main/java/meerkat/mixer/mixing/Util.java rename to mixer/src/main/java/meerkat/mixer/network/Util.java index 26437ae..90bae97 100644 --- a/mixer/src/main/java/meerkat/mixer/mixing/Util.java +++ b/mixer/src/main/java/meerkat/mixer/network/Util.java @@ -1,6 +1,4 @@ -package meerkat.mixer.mixing; - -import java.util.ArrayList; +package meerkat.mixer.network; /** * Generic utilities diff --git a/mixer/src/main/java/meerkat/mixer/proofs/Verifier.java b/mixer/src/main/java/meerkat/mixer/proofs/Verifier.java deleted file mode 100644 index 0331cce..0000000 --- a/mixer/src/main/java/meerkat/mixer/proofs/Verifier.java +++ /dev/null @@ -1,67 +0,0 @@ -package meerkat.mixer.proofs; - -import com.google.protobuf.InvalidProtocolBufferException; -import meerkat.crypto.concrete.ECElGamalEncryption; -import meerkat.crypto.mixnet.Mix2ZeroKnowledgeVerifier; -import meerkat.protobuf.Crypto; -import meerkat.protobuf.Mixing; -import org.bouncycastle.math.ec.ECPoint; -import org.factcenter.qilin.primitives.RandomOracle; -import org.factcenter.qilin.primitives.concrete.ECGroup; - -/** - * implements Mix2ZeroKnowledgeVerifier - */ -public class Verifier implements Mix2ZeroKnowledgeVerifier { - - - private final ECElGamalEncryption encryptor; - private final ECGroup group; - private final RandomOracle randomOracle; - private final ECPoint g,h; - private final ECElGamalMixStatementGenerator mixParams; - final SigmaFiatShamir mix2NIZK; - - -// private final ZeroKnowledgeOrProofParser parser; - - /** - * constructor - * @param encryptor should be as the encryptor used by meerkat.mixer.proofs - * @param randomOracle should be as the random oracle used by meerkat.mixer.proofs - */ - public Verifier(ECElGamalEncryption encryptor, RandomOracle randomOracle) { - this.encryptor = encryptor; - this.group = encryptor.getGroup(); - this.g = group.getGenerator(); - this.h = encryptor.getElGamalPK().getPK(); - this.randomOracle = randomOracle; - this.mixParams = new ECElGamalMixStatementGenerator(encryptor); - this.mix2NIZK = new SigmaFiatShamir(ProtobufConcatenators.concatNIZK, randomOracle); -// this.parser = new ZeroKnowledgeOrProofParser(group); - } - - /** - * verify zero knowledge proof - * @param in1 - * @param in2 - * @param out1 - * @param out2 - * @param proof out1 = rerandomize(in1) && out2 = rerandomize(in2) - * || - * out1 = rerandomize(in2) && out2 = rerandomize(in1) - * @return true iff all 4 or proofs are valid - * @throws InvalidProtocolBufferException - */ - public boolean verify(Crypto.RerandomizableEncryptedMessage in1, - Crypto.RerandomizableEncryptedMessage in2, - Crypto.RerandomizableEncryptedMessage out1, - Crypto.RerandomizableEncryptedMessage out2, - Mixing.Mix2Proof proof) throws InvalidProtocolBufferException { - - ECElGamalMixStatementGenerator.Mix2Statement statement = mixParams.createStatement(in1,in2,out1,out2); - Mix2.Verifier verifier = new Mix2.Verifier(encryptor, statement); - - return mix2NIZK.verifyNizk(proof, verifier); - } -} diff --git a/mixer/src/main/java/meerkat/mixer/proofs/ZeroKnowledgeOrProofParser.java b/mixer/src/main/java/meerkat/mixer/proofs/ZeroKnowledgeOrProofParser.java deleted file mode 100644 index 5c3d6c8..0000000 --- a/mixer/src/main/java/meerkat/mixer/proofs/ZeroKnowledgeOrProofParser.java +++ /dev/null @@ -1,87 +0,0 @@ -package meerkat.mixer.proofs; - -import meerkat.crypto.concrete.ECElGamalEncryption; -import meerkat.crypto.concrete.Util; -import meerkat.protobuf.Mixing; -import org.bouncycastle.math.ec.ECPoint; -import org.factcenter.qilin.primitives.concrete.ECGroup; - -import java.math.BigInteger; - -/** - * Created by Tzlil on 1/25/2016. - * zero knowledge proof parser - */ -public class ZeroKnowledgeOrProofParser { -// -// private final ECGroup group; -// -// /** -// * parse or proof message and return the result in zero knowledge or proof container -// * @param orProof -// * @return zero knowledge or proof container -// */ -// public ZeroKnowledgeOrProofContainer parseOrProof(Mixing.Mix2Proof.OrProof orProof){ -// return new ZeroKnowledgeOrProofContainer(orProof); -// } -// -// /** -// * getter -// * @param group -// */ -// public ZeroKnowledgeOrProofParser(ECGroup group) { -// this.group = group; -// } -// -// -// /** -// * inner class -// * container for parsed zero knowledge or proof -// * constructor is private, can be construct using ZeroKnowledgeOrProofParser.parseOrProof -// */ -// public class ZeroKnowledgeOrProofContainer{ -// public final ECPoint g1,g2,h1,h2; -// public final ECPoint g1Tag,g2Tag,h1Tag,h2Tag; -// public final ECPoint u,v,uTag,vTag; -// public final BigInteger c1,c2,z,zTag; -// public final Mixing.Mix2Proof.OrProof.FirstMessage firstMessage; -// -// /** -// * constructor -// * @param orProof -// */ -// private ZeroKnowledgeOrProofContainer(Mixing.Mix2Proof.OrProof orProof){ -// this.firstMessage = -// Mixing.Mix2Proof.OrProof.FirstMessage.newBuilder() -// .setG1(orProof.getG1()) -// .setH1(orProof.getH1()) -// .setG2(orProof.getG2()) -// .setH2(orProof.getH2()) -// .setG1Tag(orProof.getG1Tag()) -// .setH1Tag(orProof.getH1Tag()) -// .setG2Tag(orProof.getG2Tag()) -// .setH2Tag(orProof.getH2Tag()) -// .setU(orProof.getU()) -// .setV(orProof.getV()) -// .setUTag(orProof.getUTag()) -// .setVTag(orProof.getVTag()) -// .build(); -// this.g1 = ECElGamalEncryption.decodeElement(group, orProof.getG1()); -// this.g2 = ECElGamalEncryption.decodeElement(group, orProof.getG2()); -// this.h1 = ECElGamalEncryption.decodeElement(group, orProof.getH1()); -// this.h2 = ECElGamalEncryption.decodeElement(group, orProof.getH2()); -// this.g1Tag = ECElGamalEncryption.decodeElement(group, orProof.getG1Tag()); -// this.g2Tag = ECElGamalEncryption.decodeElement(group, orProof.getG2Tag()); -// this.h1Tag = ECElGamalEncryption.decodeElement(group, orProof.getH1Tag()); -// this.h2Tag = ECElGamalEncryption.decodeElement(group, orProof.getH2Tag()); -// this.u = ECElGamalEncryption.decodeElement(group, orProof.getU()); -// this.v = ECElGamalEncryption.decodeElement(group, orProof.getV()); -// this.uTag = ECElGamalEncryption.decodeElement(group, orProof.getUTag()); -// this.vTag = ECElGamalEncryption.decodeElement(group, orProof.getVTag()); -// this.c1 = Util.decodeBigInteger(orProof.getC1()); -// this.c2 = Util.decodeBigInteger(orProof.getC2()); -// this.z = Util.decodeBigInteger(orProof.getZ()); -// this.zTag = Util.decodeBigInteger(orProof.getZTag()); -// } -// } -} diff --git a/mixer/src/main/java/meerkat/mixer/proofs/DlogConjunction.java b/mixer/src/main/java/meerkat/mixer/proofs/concrete/DlogConjunction.java similarity index 83% rename from mixer/src/main/java/meerkat/mixer/proofs/DlogConjunction.java rename to mixer/src/main/java/meerkat/mixer/proofs/concrete/DlogConjunction.java index 57afa34..d2487b5 100644 --- a/mixer/src/main/java/meerkat/mixer/proofs/DlogConjunction.java +++ b/mixer/src/main/java/meerkat/mixer/proofs/concrete/DlogConjunction.java @@ -1,6 +1,7 @@ -package meerkat.mixer.proofs; +package meerkat.mixer.proofs.concrete; import meerkat.crypto.concrete.ECElGamalEncryption; +import meerkat.mixer.proofs.generic.SigmaProtocolAnd2; import meerkat.protobuf.Mixing; import java.util.Random; @@ -13,8 +14,8 @@ public class DlogConjunction { public static class Prover extends SigmaProtocolAnd2.Prover { - public Prover(ECElGamalEncryption encryptor, Random rand, ECElGamalMixStatementGenerator.AndStatement statement, - ECElGamalMixStatementGenerator.AndStatementWitness witness) { + public Prover(ECElGamalEncryption encryptor, Random rand, Statements.AndStatement statement, + Statements.AndStatementWitness witness) { super(ProtobufConcatenators.concatAnd1, ProtobufConcatenators.concatAnd2, new SchnorrDlogEquivalence.Prover(encryptor, rand, statement.clauses[0], witness.witnesses[0]), new SchnorrDlogEquivalence.Prover(encryptor, rand, statement.clauses[1], witness.witnesses[1])); @@ -22,7 +23,7 @@ public class DlogConjunction { } public static class Simulator extends SigmaProtocolAnd2.Simulator { - public Simulator(ECElGamalEncryption encryptor, Random rand, ECElGamalMixStatementGenerator.AndStatement statement) { + public Simulator(ECElGamalEncryption encryptor, Random rand, Statements.AndStatement statement) { super(ProtobufConcatenators.concatAnd1, ProtobufConcatenators.concatAnd2, new SchnorrDlogEquivalence.Simulator(encryptor, rand, statement.clauses[0]), new SchnorrDlogEquivalence.Simulator(encryptor, rand, statement.clauses[1])); } @@ -31,7 +32,7 @@ public class DlogConjunction { public static class Verifier extends SigmaProtocolAnd2.Verifier { - public Verifier(ECElGamalEncryption encryptor, ECElGamalMixStatementGenerator.AndStatement statement) { + public Verifier(ECElGamalEncryption encryptor, Statements.AndStatement statement) { super(ProtobufConcatenators.concatAnd1, ProtobufConcatenators.concatAnd2, new SchnorrDlogEquivalence.Verifier(encryptor, statement.clauses[0]), new SchnorrDlogEquivalence.Verifier(encryptor, statement.clauses[1])); } diff --git a/mixer/src/main/java/meerkat/mixer/proofs/Mix2.java b/mixer/src/main/java/meerkat/mixer/proofs/concrete/Mix2.java similarity index 88% rename from mixer/src/main/java/meerkat/mixer/proofs/Mix2.java rename to mixer/src/main/java/meerkat/mixer/proofs/concrete/Mix2.java index 9884e36..10ea69a 100644 --- a/mixer/src/main/java/meerkat/mixer/proofs/Mix2.java +++ b/mixer/src/main/java/meerkat/mixer/proofs/concrete/Mix2.java @@ -1,6 +1,7 @@ -package meerkat.mixer.proofs; +package meerkat.mixer.proofs.concrete; import meerkat.crypto.concrete.ECElGamalEncryption; +import meerkat.mixer.proofs.generic.SigmaProtocolOr2; import meerkat.protobuf.Mixing; import org.factcenter.qilin.primitives.concrete.ECGroup; @@ -30,7 +31,7 @@ public class Mix2 { } public static class Prover extends SigmaProtocolOr2.Prover { - public Prover(ECElGamalEncryption encryptor, Random rand, ECElGamalMixStatementGenerator.Mix2Statement statement, ECElGamalMixStatementGenerator.Mix2StatementWitness witness) { + public Prover(ECElGamalEncryption encryptor, Random rand, Statements.Mix2Statement statement, Statements.Mix2StatementWitness witness) { super(ProtobufConcatenators.concatMix1, ProtobufConcatenators.concatMix2, new ChallengeGenerator(encryptor, rand), new DlogConjunction.Prover(encryptor, rand, statement.clauses[witness.trueClauseIndex], witness.witness), new DlogConjunction.Simulator(encryptor, rand, statement.clauses[1 - witness.trueClauseIndex]), @@ -39,7 +40,7 @@ public class Mix2 { } public static class Verifier extends SigmaProtocolOr2.Verifier { - public Verifier(ECElGamalEncryption encryptor, ECElGamalMixStatementGenerator.Mix2Statement statement) { + public Verifier(ECElGamalEncryption encryptor, Statements.Mix2Statement statement) { super(ProtobufConcatenators.concatMix1, ProtobufConcatenators.concatMix2, new ChallengeGenerator(encryptor, null), new DlogConjunction.Verifier(encryptor, statement.clauses[0]), new DlogConjunction.Verifier(encryptor, statement.clauses[1])); } diff --git a/mixer/src/main/java/meerkat/mixer/proofs/Prover.java b/mixer/src/main/java/meerkat/mixer/proofs/concrete/Mix2nizk.java similarity index 59% rename from mixer/src/main/java/meerkat/mixer/proofs/Prover.java rename to mixer/src/main/java/meerkat/mixer/proofs/concrete/Mix2nizk.java index 2710f0c..83b80f8 100644 --- a/mixer/src/main/java/meerkat/mixer/proofs/Prover.java +++ b/mixer/src/main/java/meerkat/mixer/proofs/concrete/Mix2nizk.java @@ -1,31 +1,28 @@ -package meerkat.mixer.proofs; +package meerkat.mixer.proofs.concrete; import com.google.protobuf.InvalidProtocolBufferException; import meerkat.crypto.concrete.ECElGamalEncryption; import meerkat.crypto.mixnet.Mix2ZeroKnowledgeProver; +import meerkat.crypto.mixnet.Mix2ZeroKnowledgeVerifier; +import meerkat.mixer.proofs.generic.SigmaFiatShamir; import meerkat.protobuf.Crypto; import meerkat.protobuf.Mixing; -import org.bouncycastle.math.ec.ECPoint; import org.factcenter.qilin.primitives.RandomOracle; import org.factcenter.qilin.primitives.concrete.ECGroup; -import java.math.BigInteger; import java.util.Random; /** - * implements of Mix2ZeroKnowledgeProver interface - * this implementation assumes that each RerandomizableEncryptedMessage is ElGamalCiphertext + * implements of Mix2ZeroKnowledgeProver and Mix2ZeroKnowledgeVerifier interfaces + * this implementation assumes that each RerandomizableEncryptedMessage is an ElGamalCiphertext */ -public class Prover implements Mix2ZeroKnowledgeProver { +public class Mix2nizk implements Mix2ZeroKnowledgeProver, Mix2ZeroKnowledgeVerifier { // private final ECGroup group; - private final RandomOracle randomOracle; private final Random rand; private final ECElGamalEncryption encryptor; - private final ECPoint g,h; - private final BigInteger groupOrderUpperBound; - private final ECElGamalMixStatementGenerator mixParams; + private final Statements mixParams; final SigmaFiatShamir mix2NIZK; /** @@ -33,16 +30,12 @@ public class Prover implements Mix2ZeroKnowledgeProver { * @param encryptor * @param randomOracle - use for Fiat–Shamir heuristic */ - public Prover(Random rand, ECElGamalEncryption encryptor, RandomOracle randomOracle) { + public Mix2nizk(Random rand, ECElGamalEncryption encryptor, RandomOracle randomOracle) { this.rand = rand; this.encryptor = encryptor; - this.randomOracle = randomOracle; this.group = this.encryptor.getGroup(); - this.g = group.getGenerator(); - this.h = this.encryptor.getElGamalPK().getPK(); - this.mixParams = new ECElGamalMixStatementGenerator(encryptor); - this.groupOrderUpperBound = group.orderUpperBound(); + this.mixParams = new Statements(encryptor); this.mix2NIZK = new SigmaFiatShamir(ProtobufConcatenators.concatNIZK, randomOracle); } @@ -68,8 +61,8 @@ public class Prover implements Mix2ZeroKnowledgeProver { Crypto.EncryptionRandomness r2) throws InvalidProtocolBufferException { - ECElGamalMixStatementGenerator.Mix2Statement statement = mixParams.createStatement(a, b, c, d); - ECElGamalMixStatementGenerator.Mix2StatementWitness witness = mixParams.createMix2Witness(r1, r2, switched); + Statements.Mix2Statement statement = mixParams.createStatement(a, b, c, d); + Statements.Mix2StatementWitness witness = mixParams.createMix2Witness(r1, r2, switched); Mix2.Prover prover = new Mix2.Prover(encryptor, rand, statement, witness); @@ -82,5 +75,28 @@ public class Prover implements Mix2ZeroKnowledgeProver { return mix2NIZK.generateNizk(prover).toBuilder().setLocation(location).build(); } + /** + * verify zero knowledge proof + * @param in1 + * @param in2 + * @param out1 + * @param out2 + * @param proof out1 = rerandomize(in1) && out2 = rerandomize(in2) + * || + * out1 = rerandomize(in2) && out2 = rerandomize(in1) + * @return true iff all 4 or proofs are valid + * @throws InvalidProtocolBufferException + */ + public boolean verify(Crypto.RerandomizableEncryptedMessage in1, + Crypto.RerandomizableEncryptedMessage in2, + Crypto.RerandomizableEncryptedMessage out1, + Crypto.RerandomizableEncryptedMessage out2, + Mixing.Mix2Proof proof) throws InvalidProtocolBufferException { + + Statements.Mix2Statement statement = mixParams.createStatement(in1,in2,out1,out2); + Mix2.Verifier verifier = new Mix2.Verifier(encryptor, statement); + + return mix2NIZK.verifyNizk(proof, verifier); + } } diff --git a/mixer/src/main/java/meerkat/mixer/proofs/ProtobufConcatenators.java b/mixer/src/main/java/meerkat/mixer/proofs/concrete/ProtobufConcatenators.java similarity index 98% rename from mixer/src/main/java/meerkat/mixer/proofs/ProtobufConcatenators.java rename to mixer/src/main/java/meerkat/mixer/proofs/concrete/ProtobufConcatenators.java index 98c74ef..5a2d833 100644 --- a/mixer/src/main/java/meerkat/mixer/proofs/ProtobufConcatenators.java +++ b/mixer/src/main/java/meerkat/mixer/proofs/concrete/ProtobufConcatenators.java @@ -1,6 +1,7 @@ -package meerkat.mixer.proofs; +package meerkat.mixer.proofs.concrete; import meerkat.crypto.concrete.Util; +import meerkat.mixer.proofs.Concatenator; import meerkat.protobuf.Mixing; import java.math.BigInteger; diff --git a/mixer/src/main/java/meerkat/mixer/proofs/SchnorrDlogEquivalence.java b/mixer/src/main/java/meerkat/mixer/proofs/concrete/SchnorrDlogEquivalence.java similarity index 87% rename from mixer/src/main/java/meerkat/mixer/proofs/SchnorrDlogEquivalence.java rename to mixer/src/main/java/meerkat/mixer/proofs/concrete/SchnorrDlogEquivalence.java index 49d615f..4aec718 100644 --- a/mixer/src/main/java/meerkat/mixer/proofs/SchnorrDlogEquivalence.java +++ b/mixer/src/main/java/meerkat/mixer/proofs/concrete/SchnorrDlogEquivalence.java @@ -1,7 +1,8 @@ -package meerkat.mixer.proofs; +package meerkat.mixer.proofs.concrete; import meerkat.crypto.concrete.ECElGamalEncryption; import meerkat.crypto.concrete.Util; +import meerkat.mixer.proofs.SigmaProtocol; import meerkat.protobuf.ConcreteCrypto; import meerkat.protobuf.Mixing; import org.bouncycastle.math.ec.ECPoint; @@ -18,9 +19,9 @@ public class SchnorrDlogEquivalence { public static class Verifier implements SigmaProtocol.Verifier { ECElGamalEncryption encryptor; ECGroup group; - final ECElGamalMixStatementGenerator.DlogStatement statement; + final Statements.DlogStatement statement; - public Verifier(ECElGamalEncryption encryptor, ECElGamalMixStatementGenerator.DlogStatement statement) { + public Verifier(ECElGamalEncryption encryptor, Statements.DlogStatement statement) { this.encryptor = encryptor; group = encryptor.getGroup(); this.statement = statement; @@ -49,10 +50,10 @@ public class SchnorrDlogEquivalence { ECGroup group; Random rand; - ECElGamalMixStatementGenerator.DlogStatement statement; + Statements.DlogStatement statement; BigInteger response = null; - public Simulator(ECElGamalEncryption encryptor, Random rand, ECElGamalMixStatementGenerator.DlogStatement statement) { + public Simulator(ECElGamalEncryption encryptor, Random rand, Statements.DlogStatement statement) { this.encryptor = encryptor; group = encryptor.getGroup(); this.rand = rand; @@ -84,13 +85,13 @@ public class SchnorrDlogEquivalence { ECElGamalEncryption encryptor; ECGroup group; Random rand; - ECElGamalMixStatementGenerator.DlogStatement statement; - ECElGamalMixStatementGenerator.DlogStatementWitness witness; + Statements.DlogStatement statement; + Statements.DlogStatementWitness witness; BigInteger r = null; public Prover(ECElGamalEncryption encryptor, Random rand, - ECElGamalMixStatementGenerator.DlogStatement statement, ECElGamalMixStatementGenerator.DlogStatementWitness witness) { + Statements.DlogStatement statement, Statements.DlogStatementWitness witness) { this.encryptor = encryptor; group = encryptor.getGroup(); this.rand = rand; diff --git a/mixer/src/main/java/meerkat/mixer/proofs/ECElGamalMixStatementGenerator.java b/mixer/src/main/java/meerkat/mixer/proofs/concrete/Statements.java similarity index 91% rename from mixer/src/main/java/meerkat/mixer/proofs/ECElGamalMixStatementGenerator.java rename to mixer/src/main/java/meerkat/mixer/proofs/concrete/Statements.java index 8f43dff..92c8ba7 100644 --- a/mixer/src/main/java/meerkat/mixer/proofs/ECElGamalMixStatementGenerator.java +++ b/mixer/src/main/java/meerkat/mixer/proofs/concrete/Statements.java @@ -1,9 +1,8 @@ -package meerkat.mixer.proofs; +package meerkat.mixer.proofs.concrete; import com.google.protobuf.InvalidProtocolBufferException; import meerkat.crypto.concrete.ECElGamalEncryption; import meerkat.protobuf.ConcreteCrypto.ElGamalCiphertext; -import meerkat.protobuf.ConcreteCrypto.GroupElement; import meerkat.protobuf.Crypto; import meerkat.protobuf.Crypto.EncryptionRandomness; import org.bouncycastle.math.ec.ECPoint; @@ -16,28 +15,22 @@ import java.math.BigInteger; * * both meerkat.mixer.proofs and meerkat.mixer.verifier implementation use it */ -public class ECElGamalMixStatementGenerator { +public class Statements { - final ECElGamalEncryption encryptor; - final ECGroup group; - final ECPoint g; - final ECPoint h; - - // Cache encoded formats to save multiple re-encodings - private final GroupElement gEncoded; - private final GroupElement hEncoded; + final public ECElGamalEncryption encryptor; + final public ECGroup group; + final public ECPoint g; + final public ECPoint h; /** * @param encryptor encryptor used for encoding/decoding serialized ciphertexts. The group, default generator and * second base (h) are taken from the encryptor (second base is the public key) */ - public ECElGamalMixStatementGenerator(ECElGamalEncryption encryptor){ + public Statements(ECElGamalEncryption encryptor){ this.encryptor = encryptor; this.group = encryptor.getGroup(); this.g = group.getGenerator(); this.h = encryptor.getElGamalPK().getPK(); - this.gEncoded = encryptor.encodeElement(g); - this.hEncoded = encryptor.encodeElement(h); } /** @@ -175,9 +168,9 @@ public class ECElGamalMixStatementGenerator { DlogStatement(ECPoint a, ECPoint b) { - this.g = ECElGamalMixStatementGenerator.this.g; + this.g = Statements.this.g; this.a = a; - this.h = ECElGamalMixStatementGenerator.this.h; + this.h = Statements.this.h; this.b = b; } } diff --git a/mixer/src/main/java/meerkat/mixer/proofs/SigmaFiatShamir.java b/mixer/src/main/java/meerkat/mixer/proofs/generic/SigmaFiatShamir.java similarity index 93% rename from mixer/src/main/java/meerkat/mixer/proofs/SigmaFiatShamir.java rename to mixer/src/main/java/meerkat/mixer/proofs/generic/SigmaFiatShamir.java index 409ea02..80085c0 100644 --- a/mixer/src/main/java/meerkat/mixer/proofs/SigmaFiatShamir.java +++ b/mixer/src/main/java/meerkat/mixer/proofs/generic/SigmaFiatShamir.java @@ -1,6 +1,8 @@ -package meerkat.mixer.proofs; +package meerkat.mixer.proofs.generic; import com.google.protobuf.Message; +import meerkat.mixer.proofs.Concatenator; +import meerkat.mixer.proofs.SigmaProtocol; import org.factcenter.qilin.primitives.RandomOracle; import java.math.BigInteger; diff --git a/mixer/src/main/java/meerkat/mixer/proofs/SigmaProtocolAnd2.java b/mixer/src/main/java/meerkat/mixer/proofs/generic/SigmaProtocolAnd2.java similarity index 96% rename from mixer/src/main/java/meerkat/mixer/proofs/SigmaProtocolAnd2.java rename to mixer/src/main/java/meerkat/mixer/proofs/generic/SigmaProtocolAnd2.java index 31a0151..3e14edd 100644 --- a/mixer/src/main/java/meerkat/mixer/proofs/SigmaProtocolAnd2.java +++ b/mixer/src/main/java/meerkat/mixer/proofs/generic/SigmaProtocolAnd2.java @@ -1,4 +1,7 @@ -package meerkat.mixer.proofs; +package meerkat.mixer.proofs.generic; + +import meerkat.mixer.proofs.Concatenator; +import meerkat.mixer.proofs.SigmaProtocol; import java.math.BigInteger; diff --git a/mixer/src/main/java/meerkat/mixer/proofs/SigmaProtocolOr2.java b/mixer/src/main/java/meerkat/mixer/proofs/generic/SigmaProtocolOr2.java similarity index 98% rename from mixer/src/main/java/meerkat/mixer/proofs/SigmaProtocolOr2.java rename to mixer/src/main/java/meerkat/mixer/proofs/generic/SigmaProtocolOr2.java index 9cbc473..097d2a8 100644 --- a/mixer/src/main/java/meerkat/mixer/proofs/SigmaProtocolOr2.java +++ b/mixer/src/main/java/meerkat/mixer/proofs/generic/SigmaProtocolOr2.java @@ -1,4 +1,7 @@ -package meerkat.mixer.proofs; +package meerkat.mixer.proofs.generic; + +import meerkat.mixer.proofs.Concatenator; +import meerkat.mixer.proofs.SigmaProtocol; import java.math.BigInteger; diff --git a/mixer/src/test/java/meerkat/mixer/CreateTestVector.java b/mixer/src/test/java/meerkat/mixer/CreateTestVector.java index 0893a71..328a9e4 100644 --- a/mixer/src/test/java/meerkat/mixer/CreateTestVector.java +++ b/mixer/src/test/java/meerkat/mixer/CreateTestVector.java @@ -3,11 +3,11 @@ //import meerkat.crypto.concrete.ECElGamalEncryption; //import meerkat.crypto.mixnet.Mix2ZeroKnowledgeProver; //import meerkat.crypto.mixnet.Mix2ZeroKnowledgeVerifier; -//import meerkat.mixer.mixing.Mixer; -//import meerkat.mixer.mixing.MixerOutput; +//import meerkat.mixer.Mixer; +//import meerkat.mixer.MixerOutput; //import meerkat.mixer.proofs.Prover; //import meerkat.mixer.proofs.Verifier; -//import meerkat.mixer.proofs.VerifyTable; +//import meerkat.mixer.VerifyTable; //import meerkat.protobuf.Crypto; //import meerkat.protobuf.Voting; //import org.factcenter.qilin.primitives.RandomOracle; @@ -72,9 +72,9 @@ // public void createValidTest() throws IOException { // // List mixerInput = generateMixerInput(); -// System.out.println("start mixing"); +// System.out.println("start network"); // MixerOutput mixerOutput = (MixerOutput)mixer.mix(mixerInput,randomMixer); -// System.out.println("mixing ended, start verification"); +// System.out.println("network ended, start verification"); // assert (VerifyTable.verifyTable(verifier,n,mixerOutput)); // System.out.println("verification ended, start printing"); // mixerOutput.outToFolder("C:\\Users\\Tzlil\\Desktop\\TestVector\\Test3"); @@ -89,9 +89,9 @@ // //mixer = new Mixer(randomMixer,corruptedProver,enc,corruptedVerifier); // // List mixerInput = generateMixerInput(); -// System.out.println("start mixing"); +// System.out.println("start network"); // MixerOutput mixerOutput = (MixerOutput)mixer.mix(mixerInput,random); -// System.out.println("mixing ended, start negative verification"); +// System.out.println("network ended, start negative verification"); // assert (!VerifyTable.verifyTable(verifier,n,mixerOutput)); // System.out.println("verification ended, start printing"); // mixerOutput.outToFolder("C:\\Users\\Tzlil\\Desktop\\TestVector\\Test5"); diff --git a/mixer/src/test/java/meerkat/mixer/ECParamTestBase.java b/mixer/src/test/java/meerkat/mixer/ECParamTestBase.java index 98c11aa..927aff5 100644 --- a/mixer/src/test/java/meerkat/mixer/ECParamTestBase.java +++ b/mixer/src/test/java/meerkat/mixer/ECParamTestBase.java @@ -1,10 +1,6 @@ package meerkat.mixer; import meerkat.crypto.concrete.ECElGamalEncryption; -import meerkat.crypto.mixnet.Mix2ZeroKnowledgeProver; -import meerkat.crypto.mixnet.Mix2ZeroKnowledgeVerifier; -import meerkat.mixer.proofs.Prover; -import meerkat.mixer.proofs.Verifier; import meerkat.protobuf.ConcreteCrypto; import org.factcenter.qilin.primitives.RandomOracle; import org.factcenter.qilin.primitives.concrete.DigestOracle; diff --git a/mixer/src/test/java/meerkat/mixer/MixingTest.java b/mixer/src/test/java/meerkat/mixer/MixingTest.java index 693baee..05c8c90 100644 --- a/mixer/src/test/java/meerkat/mixer/MixingTest.java +++ b/mixer/src/test/java/meerkat/mixer/MixingTest.java @@ -5,18 +5,9 @@ package meerkat.mixer; */ import com.google.protobuf.InvalidProtocolBufferException; -import meerkat.crypto.concrete.ECElGamalEncryption; -import meerkat.crypto.mixnet.Mix2ZeroKnowledgeVerifier; -import meerkat.mixer.mixing.Mixer; -import meerkat.mixer.proofs.Prover; -import meerkat.mixer.proofs.Verifier; -import meerkat.mixer.proofs.VerifyTable; +import meerkat.mixer.proofs.concrete.Mix2nizk; import meerkat.protobuf.Crypto; import meerkat.protobuf.Voting; -import org.factcenter.qilin.primitives.RandomOracle; -import org.factcenter.qilin.primitives.concrete.DigestOracle; -import org.factcenter.qilin.primitives.concrete.ECElGamal; -import org.factcenter.qilin.primitives.concrete.ECGroup; import org.junit.Before; import org.junit.Test; @@ -27,8 +18,7 @@ import java.util.Random; public class MixingTest extends ECParamTestBase { Random random,randomMixer,randomProver; - Mix2ZeroKnowledgeVerifier verifier; - Prover prover; + Mix2nizk mix2nizk; meerkat.crypto.mixnet.Mixer mixer; private int layers; private int n; @@ -40,9 +30,8 @@ public class MixingTest extends ECParamTestBase { random = new Random(1); randomMixer = new Random(2); randomProver = new Random(3); - verifier = new Verifier(enc,randomOracle); - prover = new Prover(randomProver, enc,randomOracle); - mixer = new Mixer(prover, enc); + mix2nizk = new Mix2nizk(randomProver, enc,randomOracle); + mixer = new MixGenerator(mix2nizk, enc); // generate n int logN = 5; // + random.nextInt(8) @@ -65,7 +54,7 @@ public class MixingTest extends ECParamTestBase { System.out.println("n is : " + n); System.out.println(" generating input"); List mixerInput = generateMixerInput(); - System.out.println(" start mixing"); + System.out.println(" start network"); long startTime = System.currentTimeMillis(); meerkat.crypto.mixnet.MixerOutput mixerOutput = mixer.mix(mixerInput,randomMixer); @@ -76,7 +65,7 @@ public class MixingTest extends ECParamTestBase { System.out.println("start verification"); startTime = System.currentTimeMillis(); - assert (VerifyTable.verifyTable(verifier,mixerOutput)); + assert (MixVerifier.verifyTable(mix2nizk, mixerOutput)); finishTime = System.currentTimeMillis(); System.out.println(" that took: "+(finishTime-startTime)+ " ms"); diff --git a/mixer/src/test/java/meerkat/mixer/mixing/BenesNetworkTest.java b/mixer/src/test/java/meerkat/mixer/network/BenesNetworkTest.java similarity index 64% rename from mixer/src/test/java/meerkat/mixer/mixing/BenesNetworkTest.java rename to mixer/src/test/java/meerkat/mixer/network/BenesNetworkTest.java index 3114e9e..84178af 100644 --- a/mixer/src/test/java/meerkat/mixer/mixing/BenesNetworkTest.java +++ b/mixer/src/test/java/meerkat/mixer/network/BenesNetworkTest.java @@ -1,11 +1,4 @@ -package meerkat.mixer.mixing; - -import org.junit.Test; - -import java.util.Set; -import java.util.TreeSet; - -import static org.junit.Assert.*; +package meerkat.mixer.network; /** * Tests for Benes Network topology diff --git a/mixer/src/test/java/meerkat/mixer/mixing/PermutationNetworkTest.java b/mixer/src/test/java/meerkat/mixer/network/PermutationNetworkTest.java similarity index 98% rename from mixer/src/test/java/meerkat/mixer/mixing/PermutationNetworkTest.java rename to mixer/src/test/java/meerkat/mixer/network/PermutationNetworkTest.java index 2c3aa25..f3e143d 100644 --- a/mixer/src/test/java/meerkat/mixer/mixing/PermutationNetworkTest.java +++ b/mixer/src/test/java/meerkat/mixer/network/PermutationNetworkTest.java @@ -1,4 +1,4 @@ -package meerkat.mixer.mixing; +package meerkat.mixer.network; import org.junit.Before; import org.junit.Test; diff --git a/mixer/src/test/java/meerkat/mixer/proofs/DummySigmaTest.java b/mixer/src/test/java/meerkat/mixer/proofs/DummySigmaTest.java index 3c62570..ffcd495 100644 --- a/mixer/src/test/java/meerkat/mixer/proofs/DummySigmaTest.java +++ b/mixer/src/test/java/meerkat/mixer/proofs/DummySigmaTest.java @@ -1,11 +1,8 @@ package meerkat.mixer.proofs; import meerkat.protobuf.Crypto; -import org.factcenter.qilin.primitives.RandomOracle; -import org.factcenter.qilin.primitives.concrete.DigestOracle; import java.math.BigInteger; -import java.util.Random; /** * Created by talm on 14/01/17. @@ -15,12 +12,12 @@ public class DummySigmaTest extends SigmaProtocolTest { public final int NUM_REPEAT = 10; - final RandomOracle randomOracle = new DigestOracle(); + final protected RandomOracle randomOracle = new DigestOracle(); - abstract void generateRandomTrueStatement(); + abstract protected void generateRandomTrueStatement(); - abstract void generateRandomFalseStatement(); + abstract protected void generateRandomFalseStatement(); abstract protected SigmaProtocol.Prover getNewProver(); abstract protected SigmaProtocol.Verifier getNewVerifier(); abstract protected SigmaProtocol.Simulator getNewSimulator(); - class NIZKConcat implements Concatenator.Pair, M1, M2> { + public class NIZKConcat implements Concatenator.Pair, M1, M2> { @Override public Pair concatenate(M1 msg1, M2 msg2) { return new Pair(msg1, msg2); } @@ -39,7 +40,7 @@ abstract public class SigmaProtocolTest { public M2 getMsg2(Pair msg) { return msg.b; } } - final NIZKConcat nizkConcat = new NIZKConcat(); + final protected NIZKConcat nizkConcat = new NIZKConcat(); abstract protected BigInteger getChallengeModulus(); @@ -49,7 +50,7 @@ abstract public class SigmaProtocolTest { BigInteger challengeModulus; int challengeBits; - Random rand = new Random(1);; + protected Random rand = new Random(1);; @Before public void setup() { diff --git a/mixer/src/test/java/meerkat/mixer/proofs/DlogAndStatementSigmaTest.java b/mixer/src/test/java/meerkat/mixer/proofs/concrete/DlogAndStatementSigmaTest.java similarity index 77% rename from mixer/src/test/java/meerkat/mixer/proofs/DlogAndStatementSigmaTest.java rename to mixer/src/test/java/meerkat/mixer/proofs/concrete/DlogAndStatementSigmaTest.java index 562cac6..3a8dad4 100644 --- a/mixer/src/test/java/meerkat/mixer/proofs/DlogAndStatementSigmaTest.java +++ b/mixer/src/test/java/meerkat/mixer/proofs/concrete/DlogAndStatementSigmaTest.java @@ -1,5 +1,8 @@ -package meerkat.mixer.proofs; +package meerkat.mixer.proofs.concrete; +import meerkat.mixer.proofs.SigmaProtocol; +import meerkat.mixer.proofs.SigmaProtocolTest; +import meerkat.mixer.proofs.generic.SigmaProtocolAnd2; import meerkat.protobuf.Mixing; import org.factcenter.qilin.util.Pair; @@ -11,24 +14,24 @@ import java.math.BigInteger; public class DlogAndStatementSigmaTest extends SigmaProtocolTest { final DlogStatementSchnorrSigmaTest dlogtest; - ECElGamalMixStatementGenerator.DlogStatement s1, s2; - ECElGamalMixStatementGenerator.DlogStatementWitness w1, w2; + Statements.DlogStatement s1, s2; + Statements.DlogStatementWitness w1, w2; public DlogAndStatementSigmaTest() { this.dlogtest = new DlogStatementSchnorrSigmaTest(); } @Override - void generateRandomTrueStatement() { - Pair s1w1 = dlogtest.returnRandomTrueStatement(); + protected void generateRandomTrueStatement() { + Pair s1w1 = dlogtest.returnRandomTrueStatement(); s1 = s1w1.a; w1 = s1w1.b; - Pair s2w2 = dlogtest.returnRandomTrueStatement(); + Pair s2w2 = dlogtest.returnRandomTrueStatement(); s2 = s2w2.a; w2 = s2w2.b; } @Override - void generateRandomFalseStatement() { + protected void generateRandomFalseStatement() { s1 = dlogtest.returnRandomFalseStatement(); s2 = dlogtest.returnRandomFalseStatement(); } diff --git a/mixer/src/test/java/meerkat/mixer/proofs/DlogOrStatementSigmaTest.java b/mixer/src/test/java/meerkat/mixer/proofs/concrete/DlogOrStatementSigmaTest.java similarity index 71% rename from mixer/src/test/java/meerkat/mixer/proofs/DlogOrStatementSigmaTest.java rename to mixer/src/test/java/meerkat/mixer/proofs/concrete/DlogOrStatementSigmaTest.java index d305b87..91eca64 100644 --- a/mixer/src/test/java/meerkat/mixer/proofs/DlogOrStatementSigmaTest.java +++ b/mixer/src/test/java/meerkat/mixer/proofs/concrete/DlogOrStatementSigmaTest.java @@ -1,5 +1,8 @@ -package meerkat.mixer.proofs; +package meerkat.mixer.proofs.concrete; +import meerkat.mixer.proofs.SigmaProtocol; +import meerkat.mixer.proofs.SigmaProtocolTest; +import meerkat.mixer.proofs.generic.SigmaProtocolOr2; import meerkat.protobuf.Mixing; import org.factcenter.qilin.util.Pair; @@ -11,8 +14,8 @@ import java.math.BigInteger; public class DlogOrStatementSigmaTest extends SigmaProtocolTest { final DlogStatementSchnorrSigmaTest dlogtest; - final ECElGamalMixStatementGenerator.AndStatement[] statements = new ECElGamalMixStatementGenerator.AndStatement[2]; - ECElGamalMixStatementGenerator.AndStatementWitness w; + final Statements.AndStatement[] statements = new Statements.AndStatement[2]; + Statements.AndStatementWitness w; int trueStatementIndex; @@ -21,26 +24,26 @@ public class DlogOrStatementSigmaTest extends SigmaProtocolTest s1w1 = dlogtest.returnRandomTrueStatement(); - Pair s2w2 = dlogtest.returnRandomTrueStatement(); - ECElGamalMixStatementGenerator.AndStatement trueStatement = dlogtest.statementGenerator.new AndStatement(s1w1.a, s2w2.a); + Pair s1w1 = dlogtest.returnRandomTrueStatement(); + Pair s2w2 = dlogtest.returnRandomTrueStatement(); + Statements.AndStatement trueStatement = dlogtest.statementGenerator.new AndStatement(s1w1.a, s2w2.a); w = dlogtest.statementGenerator.new AndStatementWitness(s1w1.b, s2w2.b); statements[trueStatementIndex] = trueStatement; - ECElGamalMixStatementGenerator.DlogStatement f1 = dlogtest.returnRandomFalseStatement(); - ECElGamalMixStatementGenerator.DlogStatement f2 = dlogtest.returnRandomFalseStatement(); + Statements.DlogStatement f1 = dlogtest.returnRandomFalseStatement(); + Statements.DlogStatement f2 = dlogtest.returnRandomFalseStatement(); - ECElGamalMixStatementGenerator.AndStatement falseStatement = dlogtest.statementGenerator.new AndStatement(f1, f2); + Statements.AndStatement falseStatement = dlogtest.statementGenerator.new AndStatement(f1, f2); statements[1 - trueStatementIndex] = falseStatement; } @Override - void generateRandomFalseStatement() { - ECElGamalMixStatementGenerator.DlogStatement f1 = dlogtest.returnRandomFalseStatement(); - ECElGamalMixStatementGenerator.DlogStatement f2 = dlogtest.returnRandomFalseStatement(); + protected void generateRandomFalseStatement() { + Statements.DlogStatement f1 = dlogtest.returnRandomFalseStatement(); + Statements.DlogStatement f2 = dlogtest.returnRandomFalseStatement(); statements[0] = dlogtest.statementGenerator.new AndStatement(f1, f2); diff --git a/mixer/src/test/java/meerkat/mixer/proofs/DlogStatementSchnorrSigmaTest.java b/mixer/src/test/java/meerkat/mixer/proofs/concrete/DlogStatementSchnorrSigmaTest.java similarity index 69% rename from mixer/src/test/java/meerkat/mixer/proofs/DlogStatementSchnorrSigmaTest.java rename to mixer/src/test/java/meerkat/mixer/proofs/concrete/DlogStatementSchnorrSigmaTest.java index 1da4e21..2e5ebe5 100644 --- a/mixer/src/test/java/meerkat/mixer/proofs/DlogStatementSchnorrSigmaTest.java +++ b/mixer/src/test/java/meerkat/mixer/proofs/concrete/DlogStatementSchnorrSigmaTest.java @@ -1,7 +1,11 @@ -package meerkat.mixer.proofs; +package meerkat.mixer.proofs.concrete; import meerkat.crypto.concrete.ECElGamalEncryption; import meerkat.mixer.ECParamTestBase; +import meerkat.mixer.proofs.SigmaProtocol; +import meerkat.mixer.proofs.SigmaProtocolTest; +import meerkat.mixer.proofs.concrete.SchnorrDlogEquivalence; +import meerkat.mixer.proofs.concrete.Statements; import meerkat.protobuf.Mixing; import org.bouncycastle.math.ec.ECPoint; import org.factcenter.qilin.primitives.concrete.ECGroup; @@ -16,12 +20,12 @@ public class DlogStatementSchnorrSigmaTest extends SigmaProtocolTest { ECParamTestBase ecParams; - ECElGamalMixStatementGenerator statementGenerator; + Statements statementGenerator; ECElGamalEncryption encryptor; ECGroup group; - ECElGamalMixStatementGenerator.DlogStatement statement; - ECElGamalMixStatementGenerator.DlogStatementWitness witness; + Statements.DlogStatement statement; + Statements.DlogStatementWitness witness; SchnorrDlogEquivalence.Prover prover; SchnorrDlogEquivalence.Verifier verifier; SchnorrDlogEquivalence.Simulator simulator; @@ -30,34 +34,36 @@ public class DlogStatementSchnorrSigmaTest extends ecParams = new ECParamTestBase(); encryptor = ecParams.enc; group = encryptor.getGroup(); - this.statementGenerator = new ECElGamalMixStatementGenerator(ecParams.enc); + this.statementGenerator = new Statements(ecParams.enc); } - Pair returnRandomTrueStatement() { + Pair returnRandomTrueStatement() { BigInteger x = encryptor.generateRandomExponent(rand); ECPoint a = group.multiply(statementGenerator.g, x); ECPoint b = group.multiply(statementGenerator.h, x); - ECElGamalMixStatementGenerator.DlogStatement statement = statementGenerator.new DlogStatement(a, b); - ECElGamalMixStatementGenerator.DlogStatementWitness witness = statementGenerator.new DlogStatementWitness(x); + Statements.DlogStatement statement = statementGenerator.new DlogStatement(a, b); + Statements.DlogStatementWitness witness = statementGenerator.new DlogStatementWitness(x); return new Pair<>(statement, witness); } - ECElGamalMixStatementGenerator.DlogStatement returnRandomFalseStatement() { + Statements.DlogStatement returnRandomFalseStatement() { ECPoint a = group.sample(rand); ECPoint b = group.sample(rand); return statementGenerator.new DlogStatement(a, b); } - void generateRandomTrueStatement() { - Pair sw = returnRandomTrueStatement(); + @Override + protected void generateRandomTrueStatement() { + Pair sw = returnRandomTrueStatement(); this.statement = sw.a; this.witness = sw.b; } - void generateRandomFalseStatement() { + @Override + protected void generateRandomFalseStatement() { witness = null; statement = returnRandomFalseStatement(); } diff --git a/mixer/src/test/java/meerkat/mixer/Mix2ProofTest.java b/mixer/src/test/java/meerkat/mixer/proofs/concrete/Mix2ProofTest.java similarity index 87% rename from mixer/src/test/java/meerkat/mixer/Mix2ProofTest.java rename to mixer/src/test/java/meerkat/mixer/proofs/concrete/Mix2ProofTest.java index 710b8fc..4a9c28f 100644 --- a/mixer/src/test/java/meerkat/mixer/Mix2ProofTest.java +++ b/mixer/src/test/java/meerkat/mixer/proofs/concrete/Mix2ProofTest.java @@ -1,41 +1,36 @@ -package meerkat.mixer; +package meerkat.mixer.proofs.concrete; -import com.google.protobuf.ByteString; import com.google.protobuf.InvalidProtocolBufferException; import meerkat.crypto.concrete.ECElGamalEncryption; import meerkat.crypto.mixnet.Mix2ZeroKnowledgeProver; import meerkat.crypto.mixnet.Mix2ZeroKnowledgeVerifier; -import meerkat.mixer.proofs.Prover; -import meerkat.mixer.proofs.Verifier; +import meerkat.mixer.ECParamTestBase; +import meerkat.mixer.Utils; +import meerkat.mixer.proofs.concrete.Mix2nizk; import meerkat.protobuf.ConcreteCrypto; import meerkat.protobuf.Crypto; import meerkat.protobuf.Mixing; import meerkat.protobuf.Voting; //import meerkat.protobuf.Voting.PlaintextBallot; import org.bouncycastle.math.ec.ECPoint; -import org.factcenter.qilin.primitives.RandomOracle; -import org.factcenter.qilin.primitives.concrete.DigestOracle; -import org.factcenter.qilin.primitives.concrete.ECElGamal; -import org.factcenter.qilin.primitives.concrete.ECGroup; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import java.math.BigInteger; -import java.util.Random; - /** * Created by Tzlil on 12/31/2015. */ public class Mix2ProofTest extends ECParamTestBase { + Mix2nizk nizk; Mix2ZeroKnowledgeVerifier verifier ; Mix2ZeroKnowledgeProver prover ; @Before public void setup() throws Exception { - verifier = new Verifier(enc,randomOracle); - prover = new Prover(new Random(),enc,randomOracle); + nizk = new Mix2nizk(rand, enc, randomOracle); + verifier = nizk; + prover = nizk; } private ECPoint convert2ECPoint(ConcreteCrypto.GroupElement bs){ diff --git a/mixer/src/test/java/profiling/ZeroKnowledgeProof.java b/mixer/src/test/java/profiling/ZeroKnowledgeProof.java index 85015f4..e390486 100644 --- a/mixer/src/test/java/profiling/ZeroKnowledgeProof.java +++ b/mixer/src/test/java/profiling/ZeroKnowledgeProof.java @@ -4,7 +4,7 @@ import com.google.protobuf.ByteString; import com.google.protobuf.InvalidProtocolBufferException; import meerkat.crypto.concrete.ECElGamalEncryption; import meerkat.crypto.mixnet.Mix2ZeroKnowledgeProver; -import meerkat.mixer.proofs.Prover; +import meerkat.mixer.proofs.concrete.Mix2nizk; import meerkat.protobuf.ConcreteCrypto; import meerkat.protobuf.Crypto; import meerkat.protobuf.Voting; @@ -43,7 +43,7 @@ public class ZeroKnowledgeProof { enc = new ECElGamalEncryption(); enc.init(serializedPk); RandomOracle randomOracle = new DigestOracle(); - prover = new Prover(new Random(),enc,randomOracle); + prover = new Mix2nizk(new Random(),enc,randomOracle); int LogVotes = 12; int layers = 2*LogVotes - 1; n = layers * (1<