Refactoring
							parent
							
								
									deeed4f20f
								
							
						
					
					
						commit
						b9abd847c7
					
				| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +0,0 @@
 | 
			
		|||
package meerkat.crypto.mixnet;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Created by talm on 25/10/15.
 | 
			
		||||
 */
 | 
			
		||||
public class Trustee {
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,7 +0,0 @@
 | 
			
		|||
package meerkat.crypto.mixnet;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Created by talm on 25/10/15.
 | 
			
		||||
 */
 | 
			
		||||
public class Verifier {
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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<RerandomizableEncryptedMessage> 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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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<BulletinBoardAPI.BatchChunk> 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);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<Com
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * convert batch data to meerkat.mixer.mixing output
 | 
			
		||||
     * convert batch data to meerkat.mixer.network output
 | 
			
		||||
     * @throws Exception
 | 
			
		||||
     */
 | 
			
		||||
    private void convertMessage() throws Exception {
 | 
			
		||||
| 
						 | 
				
			
			@ -71,18 +71,18 @@ public class BatchHandler implements AsyncBulletinBoardClient.ClientCallback<Com
 | 
			
		|||
 | 
			
		||||
    /**
 | 
			
		||||
     * call convert message, and if succeed verify the table
 | 
			
		||||
     * @return return true iff the given batch message is valid meerkat.mixer.mixing output
 | 
			
		||||
     * @return return true iff the given batch message is valid meerkat.mixer.network output
 | 
			
		||||
     * @throws Exception
 | 
			
		||||
     */
 | 
			
		||||
    public boolean verifyTable() throws Exception {
 | 
			
		||||
        if (mixerOutput == null) {
 | 
			
		||||
            convertMessage();
 | 
			
		||||
        }
 | 
			
		||||
        return VerifyTable.verifyTable(verifier, mixerOutput);
 | 
			
		||||
        return MixVerifier.verifyTable(verifier, mixerOutput);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * extract input for meerkat.mixer.mixing from previous mixers output
 | 
			
		||||
     * extract input for meerkat.mixer.network from previous mixers output
 | 
			
		||||
     * @return last layer of encrypted votes as list
 | 
			
		||||
     * @throws Throwable in case if failure
 | 
			
		||||
     */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,11 +15,11 @@ import java.util.Random;
 | 
			
		|||
 | 
			
		||||
/**
 | 
			
		||||
 * Created by Tzlil on 12/17/2015.
 | 
			
		||||
 * this class define all the operation meerkat.mixer.mixing party should do:
 | 
			
		||||
 * this class define all the operation meerkat.mixer.network party should do:
 | 
			
		||||
 *  1. receive previous mixers output (re encrypted votes + proofs)
 | 
			
		||||
 *  2. verify its input
 | 
			
		||||
 *  3. mix
 | 
			
		||||
 *  4. send the meerkat.mixer.mixing output
 | 
			
		||||
 *  4. send the meerkat.mixer.network output
 | 
			
		||||
 */
 | 
			
		||||
public class MainMixing {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -86,7 +86,7 @@ public class MainMixing {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * send meerkat.mixer.mixing output to BB
 | 
			
		||||
     * send meerkat.mixer.network output to BB
 | 
			
		||||
     * @param mixerOutput
 | 
			
		||||
     * @param batchId
 | 
			
		||||
     * @param callback
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,132 +0,0 @@
 | 
			
		|||
package meerkat.mixer.mixing;
 | 
			
		||||
 | 
			
		||||
import meerkat.protobuf.Crypto;
 | 
			
		||||
import meerkat.protobuf.Mixing;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.io.FileOutputStream;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Created by Tzlil on 1/18/2016.
 | 
			
		||||
 * implements meerkat.crypto.mixnet.MixerOutput interface
 | 
			
		||||
 * container for meerkat.mixer.mixing.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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * print the output, encrypted messages and proofs, to folder
 | 
			
		||||
     * @param dir - directory
 | 
			
		||||
     * @throws IOException
 | 
			
		||||
     */
 | 
			
		||||
//    public void outToFolder(String dir) throws IOException {
 | 
			
		||||
//
 | 
			
		||||
//        (new File(dir)).mkdirs();
 | 
			
		||||
//        //create files
 | 
			
		||||
//        String proofsDir = dir + "/Proofs";
 | 
			
		||||
//        String encDir = dir + "/EncryptedMessages";
 | 
			
		||||
//        (new File(proofsDir)).mkdir();
 | 
			
		||||
//        (new File(encDir)).mkdir();
 | 
			
		||||
//        for (int layer = 0; layer < layers; layer++){
 | 
			
		||||
//            (new File(proofsDir +"/layer" + layer )).mkdir();
 | 
			
		||||
//            (new File(encDir +"/layer" + layer )).mkdir();
 | 
			
		||||
//        }
 | 
			
		||||
//        (new File(encDir +"/input")).mkdir();
 | 
			
		||||
//
 | 
			
		||||
//
 | 
			
		||||
//        for (int layer = 0; layer < layers; layer++){
 | 
			
		||||
//            for(int i = 0; i < proofs[layer].length; i ++){
 | 
			
		||||
//                writeProofToFile(proofsDir,proofs[layer][i]);
 | 
			
		||||
//            }
 | 
			
		||||
//        }
 | 
			
		||||
//
 | 
			
		||||
//        for (int layer = 0; layer <= layers; layer++){
 | 
			
		||||
//            for(int i = 0; i < encryptedMessages[layer].length; i ++){
 | 
			
		||||
//                writeEncToFile(encDir,layer - 1, i,encryptedMessages[layer][i]);
 | 
			
		||||
//            }
 | 
			
		||||
//        }
 | 
			
		||||
//    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * create new file contains single proof
 | 
			
		||||
     * @param proofsDir
 | 
			
		||||
     * @param proof
 | 
			
		||||
     * @throws IOException
 | 
			
		||||
     */
 | 
			
		||||
//    private void writeProofToFile(String proofsDir, Mixing.Mix2Proof proof) throws IOException {
 | 
			
		||||
//        Mixing.Mix2Proof.Location location = proof.getLocation();
 | 
			
		||||
//        int layer = location.getLayer();
 | 
			
		||||
//        int i = location.getI();
 | 
			
		||||
//        int j = location.getJ();
 | 
			
		||||
//        String fileName = proofsDir+"/layer" + layer +"/" + i +"_" + j;
 | 
			
		||||
//
 | 
			
		||||
//        File file = new File(fileName);
 | 
			
		||||
//        file.createNewFile();
 | 
			
		||||
//        FileOutputStream fos = new FileOutputStream(file);
 | 
			
		||||
//        fos.write(proof.toByteArray());
 | 
			
		||||
//        fos.close();
 | 
			
		||||
//    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * create new file contains single encrypted message
 | 
			
		||||
     * @param encDir
 | 
			
		||||
     * @param layer
 | 
			
		||||
     * @param i
 | 
			
		||||
     * @param enc
 | 
			
		||||
     * @throws IOException
 | 
			
		||||
     */
 | 
			
		||||
    private void writeEncToFile(String encDir,int layer,int i, Crypto.RerandomizableEncryptedMessage enc) throws IOException {
 | 
			
		||||
 | 
			
		||||
        String fileName;
 | 
			
		||||
        if(layer >= 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();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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 +
 | 
			
		||||
                '}';
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
package meerkat.mixer.mixing;
 | 
			
		||||
package meerkat.mixer.network;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -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.
 | 
			
		||||
| 
						 | 
				
			
			@ -1,7 +1,5 @@
 | 
			
		|||
package meerkat.mixer.mixing;
 | 
			
		||||
package meerkat.mixer.network;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Random;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			@ -1,6 +1,4 @@
 | 
			
		|||
package meerkat.mixer.mixing;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
package meerkat.mixer.network;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Generic utilities
 | 
			
		||||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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());
 | 
			
		||||
//        }
 | 
			
		||||
//    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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<Mixing.Mix2Proof.AndProof.FirstMessage, Mixing.Mix2Proof.DlogProof.FirstMessage, Mixing.Mix2Proof.AndProof.FinalMessage, Mixing.Mix2Proof.DlogProof.FinalMessage> {
 | 
			
		||||
 | 
			
		||||
        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<Mixing.Mix2Proof.AndProof.FirstMessage, Mixing.Mix2Proof.DlogProof.FirstMessage, Mixing.Mix2Proof.AndProof.FinalMessage, Mixing.Mix2Proof.DlogProof.FinalMessage> {
 | 
			
		||||
 | 
			
		||||
        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]));
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -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<Mixing.Mix2Proof.FirstMessage, Mixing.Mix2Proof.AndProof.FirstMessage, Mixing.Mix2Proof.FinalMessage, Mixing.Mix2Proof.AndProof.FinalMessage> {
 | 
			
		||||
        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<Mixing.Mix2Proof.FirstMessage, Mixing.Mix2Proof.AndProof.FirstMessage, Mixing.Mix2Proof.FinalMessage, Mixing.Mix2Proof.AndProof.FinalMessage> {
 | 
			
		||||
        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]));
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -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<Mixing.Mix2Proof, Mixing.Mix2Proof.FirstMessage, Mixing.Mix2Proof.FinalMessage> 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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			@ -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<Mixing.Mix2Proof.DlogProof.FirstMessage, Mixing.Mix2Proof.DlogProof.FinalMessage> {
 | 
			
		||||
        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;
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -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<Crypto.RerandomizableEncryptedMessage> 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<Crypto.RerandomizableEncryptedMessage> 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");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<Crypto.RerandomizableEncryptedMessage> 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");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
package meerkat.mixer.mixing;
 | 
			
		||||
package meerkat.mixer.network;
 | 
			
		||||
 | 
			
		||||
import org.junit.Before;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
| 
						 | 
				
			
			@ -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<Crypto.BigInteger, BigInte
 | 
			
		|||
    BigInteger x,y,z;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    void generateRandomTrueStatement() {
 | 
			
		||||
    protected void generateRandomTrueStatement() {
 | 
			
		||||
        x = new BigInteger(100, rand); y = new BigInteger(100, rand); z = x.add(y);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    void generateRandomFalseStatement() {
 | 
			
		||||
    protected void generateRandomFalseStatement() {
 | 
			
		||||
        x = new BigInteger(100, rand);
 | 
			
		||||
        y = new BigInteger(100, rand);
 | 
			
		||||
        z = new BigInteger(100, rand);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
package meerkat.mixer.proofs;
 | 
			
		||||
 | 
			
		||||
import com.google.protobuf.Message;
 | 
			
		||||
import meerkat.mixer.proofs.generic.SigmaFiatShamir;
 | 
			
		||||
import org.factcenter.qilin.primitives.RandomOracle;
 | 
			
		||||
import org.factcenter.qilin.primitives.concrete.DigestOracle;
 | 
			
		||||
import org.factcenter.qilin.util.Pair;
 | 
			
		||||
| 
						 | 
				
			
			@ -18,17 +19,17 @@ import static org.junit.Assert.*;
 | 
			
		|||
abstract public class SigmaProtocolTest<M1 extends Message, M2> {
 | 
			
		||||
    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<M1, M2> getNewProver();
 | 
			
		||||
    abstract protected SigmaProtocol.Verifier<M1, M2> getNewVerifier();
 | 
			
		||||
    abstract protected SigmaProtocol.Simulator<M1, M2> getNewSimulator();
 | 
			
		||||
 | 
			
		||||
    class NIZKConcat implements Concatenator.Pair<Pair<M1,M2>, M1, M2> {
 | 
			
		||||
    public class NIZKConcat implements Concatenator.Pair<Pair<M1,M2>, M1, M2> {
 | 
			
		||||
        @Override
 | 
			
		||||
        public Pair<M1, M2> concatenate(M1 msg1, M2 msg2) { return new Pair<M1, M2>(msg1, msg2);  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -39,7 +40,7 @@ abstract public class SigmaProtocolTest<M1 extends Message, M2> {
 | 
			
		|||
        public M2 getMsg2(Pair<M1,M2> 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<M1 extends Message, M2> {
 | 
			
		|||
    BigInteger challengeModulus;
 | 
			
		||||
    int challengeBits;
 | 
			
		||||
 | 
			
		||||
    Random rand = new Random(1);;
 | 
			
		||||
    protected Random rand = new Random(1);;
 | 
			
		||||
 | 
			
		||||
    @Before
 | 
			
		||||
    public void setup() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<Mixing.Mix2Proof.AndProof.FirstMessage, Mixing.Mix2Proof.AndProof.FinalMessage> {
 | 
			
		||||
    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<ECElGamalMixStatementGenerator.DlogStatement, ECElGamalMixStatementGenerator.DlogStatementWitness> s1w1 = dlogtest.returnRandomTrueStatement();
 | 
			
		||||
    protected void generateRandomTrueStatement() {
 | 
			
		||||
        Pair<Statements.DlogStatement, Statements.DlogStatementWitness> s1w1 = dlogtest.returnRandomTrueStatement();
 | 
			
		||||
        s1 = s1w1.a; w1 = s1w1.b;
 | 
			
		||||
 | 
			
		||||
        Pair<ECElGamalMixStatementGenerator.DlogStatement, ECElGamalMixStatementGenerator.DlogStatementWitness> s2w2 = dlogtest.returnRandomTrueStatement();
 | 
			
		||||
        Pair<Statements.DlogStatement, Statements.DlogStatementWitness> s2w2 = dlogtest.returnRandomTrueStatement();
 | 
			
		||||
        s2 = s2w2.a; w2 = s2w2.b;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    void generateRandomFalseStatement() {
 | 
			
		||||
    protected void generateRandomFalseStatement() {
 | 
			
		||||
        s1 = dlogtest.returnRandomFalseStatement();
 | 
			
		||||
        s2 = dlogtest.returnRandomFalseStatement();
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -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<Mixing.Mix2Proof.FirstMessage, Mixing.Mix2Proof.FinalMessage> {
 | 
			
		||||
    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<Mixing.Mix2Proof
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    void generateRandomTrueStatement() {
 | 
			
		||||
    protected void generateRandomTrueStatement() {
 | 
			
		||||
        trueStatementIndex = rand.nextInt(2);
 | 
			
		||||
        Pair<ECElGamalMixStatementGenerator.DlogStatement, ECElGamalMixStatementGenerator.DlogStatementWitness> s1w1 = dlogtest.returnRandomTrueStatement();
 | 
			
		||||
        Pair<ECElGamalMixStatementGenerator.DlogStatement, ECElGamalMixStatementGenerator.DlogStatementWitness> s2w2 = dlogtest.returnRandomTrueStatement();
 | 
			
		||||
        ECElGamalMixStatementGenerator.AndStatement trueStatement = dlogtest.statementGenerator.new AndStatement(s1w1.a, s2w2.a);
 | 
			
		||||
        Pair<Statements.DlogStatement, Statements.DlogStatementWitness> s1w1 = dlogtest.returnRandomTrueStatement();
 | 
			
		||||
        Pair<Statements.DlogStatement, Statements.DlogStatementWitness> 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);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -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<Mixing.Mix2Proof.DlogProof.FirstMessage, Mixing.Mix2Proof.DlogProof.FinalMessage> {
 | 
			
		||||
 | 
			
		||||
    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<ECElGamalMixStatementGenerator.DlogStatement, ECElGamalMixStatementGenerator.DlogStatementWitness> returnRandomTrueStatement() {
 | 
			
		||||
    Pair<Statements.DlogStatement, Statements.DlogStatementWitness> 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<ECElGamalMixStatementGenerator.DlogStatement, ECElGamalMixStatementGenerator.DlogStatementWitness> sw = returnRandomTrueStatement();
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void generateRandomTrueStatement() {
 | 
			
		||||
        Pair<Statements.DlogStatement, Statements.DlogStatementWitness> sw = returnRandomTrueStatement();
 | 
			
		||||
        this.statement = sw.a;
 | 
			
		||||
        this.witness = sw.b;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void generateRandomFalseStatement() {
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void generateRandomFalseStatement() {
 | 
			
		||||
        witness = null;
 | 
			
		||||
        statement = returnRandomFalseStatement();
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -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){
 | 
			
		||||
| 
						 | 
				
			
			@ -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<<LogVotes) / 2;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue