More refactoring

mixer
Tal Moran 2017-01-20 23:46:51 +02:00
parent b9abd847c7
commit 273338010d
16 changed files with 80 additions and 121 deletions

View File

@ -1,20 +0,0 @@
package meerkat.crypto.mixnet;
import com.google.protobuf.InvalidProtocolBufferException;
import meerkat.protobuf.Crypto;
import meerkat.protobuf.Mixing;
/**
* Prove in zero knowledge that two ciphertexts are a mix of two original ciphertexts.
*/
public interface Mix2ZeroKnowledgeProver {
public Mixing.Mix2Proof prove(Crypto.RerandomizableEncryptedMessage in1,
Crypto.RerandomizableEncryptedMessage in2,
Crypto.RerandomizableEncryptedMessage out1,
Crypto.RerandomizableEncryptedMessage out2,
boolean switched, int layer, int switchIdx, int out0Idx, int out1Idx, // switch info
Crypto.EncryptionRandomness r1,
Crypto.EncryptionRandomness r2) throws InvalidProtocolBufferException;
}

View File

@ -1,24 +0,0 @@
package meerkat.crypto.mixnet;
import com.google.protobuf.InvalidProtocolBufferException;
import meerkat.protobuf.Crypto;
import meerkat.protobuf.Mixing;
/**
* Verify the two-ciphertext mix proof
*/
public interface Mix2ZeroKnowledgeVerifier {
/**
* Return true iff the proof is valid.
* @param in1
* @param in2
* @param out1
* @param out2
* @return
*/
boolean verify(Crypto.RerandomizableEncryptedMessage in1,
Crypto.RerandomizableEncryptedMessage in2,
Crypto.RerandomizableEncryptedMessage out1,
Crypto.RerandomizableEncryptedMessage out2,
Mixing.Mix2Proof proof) throws InvalidProtocolBufferException;
}

View File

@ -1,15 +0,0 @@
package meerkat.crypto.mixnet;
import com.google.protobuf.InvalidProtocolBufferException;
import meerkat.protobuf.Crypto;
import java.util.List;
import java.util.Random;
/**
* Created by talm on 25/10/15.
*/
public interface Mixer {
public MixerOutput mix(List<Crypto.RerandomizableEncryptedMessage> ciphertexts,Random random)
throws InvalidProtocolBufferException;
}

View File

@ -1,14 +0,0 @@
package meerkat.crypto.mixnet;
import meerkat.protobuf.Crypto;
import meerkat.protobuf.Mixing;
/**
* Created by Tzlil on 1/18/2016.
*/
public interface MixerOutput {
public Mixing.Mix2Proof[][] getProofs();
public Crypto.RerandomizableEncryptedMessage[][] getEncryptedMessages();
public int getLogN();
public int getNumLayers();
}

View File

@ -2,11 +2,10 @@ package meerkat.mixer;
import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.InvalidProtocolBufferException;
import meerkat.crypto.Encryption; import meerkat.crypto.Encryption;
import meerkat.crypto.mixnet.Mix2ZeroKnowledgeProver;
import meerkat.crypto.mixnet.MixerOutput;
import meerkat.mixer.network.BenesNetwork; import meerkat.mixer.network.BenesNetwork;
import meerkat.mixer.network.PermutationNetwork; import meerkat.mixer.network.PermutationNetwork;
import meerkat.mixer.network.RandomPermutation; import meerkat.mixer.network.RandomPermutation;
import meerkat.mixer.proofs.Mix2nizk;
import meerkat.protobuf.Crypto.EncryptionRandomness; import meerkat.protobuf.Crypto.EncryptionRandomness;
import meerkat.protobuf.Crypto.RerandomizableEncryptedMessage; import meerkat.protobuf.Crypto.RerandomizableEncryptedMessage;
import meerkat.protobuf.Mixing.Mix2Proof; import meerkat.protobuf.Mixing.Mix2Proof;
@ -15,18 +14,17 @@ import java.util.List;
import java.util.Random; import java.util.Random;
/** /**
* an implementation of meerkat.crypto.mixnet.Mixer * Run Abe's permutation network mixing algorithm on set of n encrypted votes:
* meerkat.mixer.network algorithm on set of n encrypted votes: * 0. n is power of two
* 0. asset n is power of two * 1. set switches according to Benes network on random permutation
* 1. set switches according to benes network on random permutation
* 2. re encrypt and mix with respect to switches values (encryptor.rerandomize) * 2. re encrypt and mix with respect to switches values (encryptor.rerandomize)
* 3. generate zero knowledge proof on each re encrypted couple * 3. generate zero knowledge proof on each re encrypted couple
* 4. return proofs table + encryption table * 4. return proofs table + encryption table
* *
*/ */
public class MixGenerator implements meerkat.crypto.mixnet.Mixer { public class MixGenerator {
private final Mix2ZeroKnowledgeProver prover; private final Mix2nizk.Prover prover;
private final Encryption encryptor; private final Encryption encryptor;
/** /**
@ -34,7 +32,7 @@ public class MixGenerator implements meerkat.crypto.mixnet.Mixer {
* @param prover * @param prover
* @param encryptor * @param encryptor
*/ */
public MixGenerator(Mix2ZeroKnowledgeProver prover, Encryption encryptor) { public MixGenerator(Mix2nizk.Prover prover, Encryption encryptor) {
this.prover = prover; this.prover = prover;
this.encryptor = encryptor; this.encryptor = encryptor;
} }

View File

@ -1,8 +1,7 @@
package meerkat.mixer; package meerkat.mixer;
import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.InvalidProtocolBufferException;
import meerkat.crypto.mixnet.Mix2ZeroKnowledgeVerifier; import meerkat.mixer.proofs.Mix2nizk;
import meerkat.crypto.mixnet.MixerOutput;
import meerkat.protobuf.Crypto; import meerkat.protobuf.Crypto;
import meerkat.protobuf.Mixing; import meerkat.protobuf.Mixing;
@ -20,7 +19,7 @@ public final class MixVerifier {
* @return true iff the meerkat.mixer.network output is valid * @return true iff the meerkat.mixer.network output is valid
* @throws InvalidProtocolBufferException * @throws InvalidProtocolBufferException
*/ */
public static boolean verifyTable(Mix2ZeroKnowledgeVerifier verifier, MixerOutput mixerOutput) public static boolean verifyTable(Mix2nizk.Verifier verifier, MixerOutput mixerOutput)
throws InvalidProtocolBufferException { throws InvalidProtocolBufferException {
int out0,out1,layer, switchIdx; int out0,out1,layer, switchIdx;

View File

@ -8,10 +8,9 @@ import java.io.OutputStream;
/** /**
* Created by Tzlil on 1/18/2016. * Created by Tzlil on 1/18/2016.
* implements meerkat.crypto.mixnet.MixerOutput interface
* container for meerkat.mixer.network.mix result. * container for meerkat.mixer.network.mix result.
*/ */
public class MixerOutput implements meerkat.crypto.mixnet.MixerOutput { public class MixerOutput {
private final Mixing.Mix2Proof[][] proofs; private final Mixing.Mix2Proof[][] proofs;
private final Crypto.RerandomizableEncryptedMessage[][] encryptedMessages; private final Crypto.RerandomizableEncryptedMessage[][] encryptedMessages;
private final int logN; private final int logN;
@ -30,22 +29,18 @@ public class MixerOutput implements meerkat.crypto.mixnet.MixerOutput {
this.logN = logN; this.logN = logN;
} }
@Override
public Mixing.Mix2Proof[][] getProofs() { public Mixing.Mix2Proof[][] getProofs() {
return proofs; return proofs;
} }
@Override
public Crypto.RerandomizableEncryptedMessage[][] getEncryptedMessages() { public Crypto.RerandomizableEncryptedMessage[][] getEncryptedMessages() {
return encryptedMessages; return encryptedMessages;
} }
@Override
public int getLogN() { public int getLogN() {
return logN; return logN;
} }
@Override
public int getNumLayers() { public int getNumLayers() {
return 2 * logN - 1; return 2 * logN - 1;
} }

View File

@ -1,6 +1,6 @@
package meerkat.mixer.main; package meerkat.mixer.main;
import meerkat.crypto.mixnet.MixerOutput; import meerkat.mixer.MixerOutput;
import meerkat.protobuf.BulletinBoardAPI; import meerkat.protobuf.BulletinBoardAPI;
import meerkat.protobuf.Crypto; import meerkat.protobuf.Crypto;
import meerkat.protobuf.Mixing; import meerkat.protobuf.Mixing;

View File

@ -1,7 +1,7 @@
package meerkat.mixer.main; package meerkat.mixer.main;
import meerkat.crypto.mixnet.Mix2ZeroKnowledgeVerifier; import meerkat.mixer.MixerOutput;
import meerkat.crypto.mixnet.MixerOutput; import meerkat.mixer.proofs.Mix2nizk;
import meerkat.protobuf.Crypto; import meerkat.protobuf.Crypto;
import meerkat.mixer.necessary.AsyncBulletinBoardClient; import meerkat.mixer.necessary.AsyncBulletinBoardClient;
import meerkat.mixer.necessary.CompleteBatch; import meerkat.mixer.necessary.CompleteBatch;
@ -21,13 +21,13 @@ public class BatchHandler implements AsyncBulletinBoardClient.ClientCallback<Com
private Throwable t; private Throwable t;
private CompleteBatch msg; private CompleteBatch msg;
private final Mix2ZeroKnowledgeVerifier verifier; private final Mix2nizk.Verifier verifier;
/** /**
* constructor * constructor
* @param verifier * @param verifier
*/ */
public BatchHandler(Mix2ZeroKnowledgeVerifier verifier) { public BatchHandler(Mix2nizk.Verifier verifier) {
this.mixerOutput = null; this.mixerOutput = null;
this.msgReceived = false; this.msgReceived = false;
this.t = null; this.t = null;

View File

@ -1,8 +1,8 @@
package meerkat.mixer.main; package meerkat.mixer.main;
import meerkat.crypto.mixnet.Mix2ZeroKnowledgeVerifier; import meerkat.mixer.MixGenerator;
import meerkat.crypto.mixnet.Mixer; import meerkat.mixer.MixerOutput;
import meerkat.crypto.mixnet.MixerOutput; import meerkat.mixer.proofs.Mix2nizk;
import meerkat.protobuf.BulletinBoardAPI; import meerkat.protobuf.BulletinBoardAPI;
import meerkat.protobuf.Crypto; import meerkat.protobuf.Crypto;
import meerkat.mixer.necessary.AsyncBulletinBoardClient; import meerkat.mixer.necessary.AsyncBulletinBoardClient;
@ -23,8 +23,8 @@ import java.util.Random;
*/ */
public class MainMixing { public class MainMixing {
private final Mixer mixer; private final MixGenerator mixer;
private final Mix2ZeroKnowledgeVerifier verifier; private final Mix2nizk.Verifier verifier;
private final AsyncBulletinBoardClient asyncBulletinBoardClient; private final AsyncBulletinBoardClient asyncBulletinBoardClient;
private final byte[] id; private final byte[] id;
@ -36,7 +36,7 @@ public class MainMixing {
* @param asyncBulletinBoardClient * @param asyncBulletinBoardClient
* @param id * @param id
*/ */
public MainMixing(Mixer mixer, Mix2ZeroKnowledgeVerifier verifier, public MainMixing(MixGenerator mixer, Mix2nizk.Verifier verifier,
AsyncBulletinBoardClient asyncBulletinBoardClient, byte[] id) { AsyncBulletinBoardClient asyncBulletinBoardClient, byte[] id) {
this.mixer = mixer; this.mixer = mixer;
this.verifier = verifier; this.verifier = verifier;

View File

@ -0,0 +1,44 @@
package meerkat.mixer.proofs;
import com.google.protobuf.InvalidProtocolBufferException;
import meerkat.protobuf.Crypto;
import meerkat.protobuf.Mixing;
/**
* Created by talm on 20/01/17.
*/
public interface Mix2nizk {
/**
* Prove in zero knowledge that two ciphertexts are a mix of two original ciphertexts.
*/
public interface Prover {
public Mixing.Mix2Proof prove(Crypto.RerandomizableEncryptedMessage in1,
Crypto.RerandomizableEncryptedMessage in2,
Crypto.RerandomizableEncryptedMessage out1,
Crypto.RerandomizableEncryptedMessage out2,
boolean switched, int layer, int switchIdx, int out0Idx, int out1Idx, // switch info
Crypto.EncryptionRandomness r1,
Crypto.EncryptionRandomness r2) throws InvalidProtocolBufferException;
}
/**
* Verify the two-ciphertext mix proof
*/
public interface Verifier {
/**
* Return true iff the proof is valid.
* @param in1
* @param in2
* @param out1
* @param out2
* @return
*/
boolean verify(Crypto.RerandomizableEncryptedMessage in1,
Crypto.RerandomizableEncryptedMessage in2,
Crypto.RerandomizableEncryptedMessage out1,
Crypto.RerandomizableEncryptedMessage out2,
Mixing.Mix2Proof proof) throws InvalidProtocolBufferException;
}
}

View File

@ -2,8 +2,8 @@ package meerkat.mixer.proofs.concrete;
import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.InvalidProtocolBufferException;
import meerkat.crypto.concrete.ECElGamalEncryption; import meerkat.crypto.concrete.ECElGamalEncryption;
import meerkat.crypto.mixnet.Mix2ZeroKnowledgeProver; import meerkat.mixer.proofs.Mix2nizk.Prover;
import meerkat.crypto.mixnet.Mix2ZeroKnowledgeVerifier; import meerkat.mixer.proofs.Mix2nizk.Verifier;
import meerkat.mixer.proofs.generic.SigmaFiatShamir; import meerkat.mixer.proofs.generic.SigmaFiatShamir;
import meerkat.protobuf.Crypto; import meerkat.protobuf.Crypto;
import meerkat.protobuf.Mixing; import meerkat.protobuf.Mixing;
@ -14,10 +14,10 @@ import java.util.Random;
/** /**
* implements of Mix2ZeroKnowledgeProver and Mix2ZeroKnowledgeVerifier interfaces * implements of Prover and Verifier interfaces
* this implementation assumes that each RerandomizableEncryptedMessage is an ElGamalCiphertext * this implementation assumes that each RerandomizableEncryptedMessage is an ElGamalCiphertext
*/ */
public class Mix2nizk implements Mix2ZeroKnowledgeProver, Mix2ZeroKnowledgeVerifier { public class Mix2nizk implements Prover, Verifier {
// //
private final ECGroup group; private final ECGroup group;
private final Random rand; private final Random rand;

View File

@ -1,8 +1,8 @@
//package meerkat.mixer; //package meerkat.mixer;
// //
//import meerkat.crypto.concrete.ECElGamalEncryption; //import meerkat.crypto.concrete.ECElGamalEncryption;
//import meerkat.crypto.mixnet.Mix2ZeroKnowledgeProver; //import meerkat.mixer.proofs.Mix2nizk.Prover;
//import meerkat.crypto.mixnet.Mix2ZeroKnowledgeVerifier; //import meerkat.mixer.proofs.Mix2nizk.Verifier;
//import meerkat.mixer.Mixer; //import meerkat.mixer.Mixer;
//import meerkat.mixer.MixerOutput; //import meerkat.mixer.MixerOutput;
//import meerkat.mixer.proofs.Prover; //import meerkat.mixer.proofs.Prover;
@ -32,8 +32,8 @@
// ECGroup group; // ECGroup group;
// Random random,randomMixer,randomProver; // Random random,randomMixer,randomProver;
// RandomOracle randomOracle; // RandomOracle randomOracle;
// Mix2ZeroKnowledgeVerifier verifier; // Verifier verifier;
// Mix2ZeroKnowledgeProver prover; // Prover prover;
// meerkat.crypto.mixnet.Mixer mixer; // meerkat.crypto.mixnet.Mixer mixer;
// private int layers; // private int layers;
// private int n; // private int n;
@ -84,8 +84,8 @@
// //@SimpleRerandomizeTest // //@SimpleRerandomizeTest
// public void createInvalidTest() throws IOException { // public void createInvalidTest() throws IOException {
// //
// //Mix2ZeroKnowledgeVerifier corruptedVerifier = new Verifier(enc,randomOracle,true); // //Verifier corruptedVerifier = new Verifier(enc,randomOracle,true);
// //Mix2ZeroKnowledgeProver corruptedProver = new Prover(randomProver,enc,randomOracle,true); // //Prover corruptedProver = new Prover(randomProver,enc,randomOracle,true);
// //mixer = new Mixer(randomMixer,corruptedProver,enc,corruptedVerifier); // //mixer = new Mixer(randomMixer,corruptedProver,enc,corruptedVerifier);
// //
// List<Crypto.RerandomizableEncryptedMessage> mixerInput = generateMixerInput(); // List<Crypto.RerandomizableEncryptedMessage> mixerInput = generateMixerInput();

View File

@ -19,7 +19,7 @@ import java.util.Random;
public class MixingTest extends ECParamTestBase { public class MixingTest extends ECParamTestBase {
Random random,randomMixer,randomProver; Random random,randomMixer,randomProver;
Mix2nizk mix2nizk; Mix2nizk mix2nizk;
meerkat.crypto.mixnet.Mixer mixer; MixGenerator mixer;
private int layers; private int layers;
private int n; private int n;
@ -57,7 +57,7 @@ public class MixingTest extends ECParamTestBase {
System.out.println(" start network"); System.out.println(" start network");
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
meerkat.crypto.mixnet.MixerOutput mixerOutput = mixer.mix(mixerInput,randomMixer); MixerOutput mixerOutput = mixer.mix(mixerInput,randomMixer);
long finishTime = System.currentTimeMillis(); long finishTime = System.currentTimeMillis();
System.out.println(" that took: "+(finishTime-startTime)+ " ms"); System.out.println(" that took: "+(finishTime-startTime)+ " ms");

View File

@ -2,11 +2,8 @@ package meerkat.mixer.proofs.concrete;
import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.InvalidProtocolBufferException;
import meerkat.crypto.concrete.ECElGamalEncryption; import meerkat.crypto.concrete.ECElGamalEncryption;
import meerkat.crypto.mixnet.Mix2ZeroKnowledgeProver;
import meerkat.crypto.mixnet.Mix2ZeroKnowledgeVerifier;
import meerkat.mixer.ECParamTestBase; import meerkat.mixer.ECParamTestBase;
import meerkat.mixer.Utils; import meerkat.mixer.Utils;
import meerkat.mixer.proofs.concrete.Mix2nizk;
import meerkat.protobuf.ConcreteCrypto; import meerkat.protobuf.ConcreteCrypto;
import meerkat.protobuf.Crypto; import meerkat.protobuf.Crypto;
import meerkat.protobuf.Mixing; import meerkat.protobuf.Mixing;
@ -23,8 +20,8 @@ import static org.junit.Assert.assertTrue;
*/ */
public class Mix2ProofTest extends ECParamTestBase { public class Mix2ProofTest extends ECParamTestBase {
Mix2nizk nizk; Mix2nizk nizk;
Mix2ZeroKnowledgeVerifier verifier ; meerkat.mixer.proofs.Mix2nizk.Verifier verifier ;
Mix2ZeroKnowledgeProver prover ; meerkat.mixer.proofs.Mix2nizk.Prover prover ;
@Before @Before
public void setup() throws Exception { public void setup() throws Exception {

View File

@ -3,7 +3,6 @@ package profiling;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.InvalidProtocolBufferException;
import meerkat.crypto.concrete.ECElGamalEncryption; import meerkat.crypto.concrete.ECElGamalEncryption;
import meerkat.crypto.mixnet.Mix2ZeroKnowledgeProver;
import meerkat.mixer.proofs.concrete.Mix2nizk; import meerkat.mixer.proofs.concrete.Mix2nizk;
import meerkat.protobuf.ConcreteCrypto; import meerkat.protobuf.ConcreteCrypto;
import meerkat.protobuf.Crypto; import meerkat.protobuf.Crypto;
@ -28,7 +27,7 @@ public class ZeroKnowledgeProof {
ECGroup group; ECGroup group;
ECElGamalEncryption enc; ECElGamalEncryption enc;
ConcreteCrypto.ElGamalPublicKey serializedPk; ConcreteCrypto.ElGamalPublicKey serializedPk;
Mix2ZeroKnowledgeProver prover ; meerkat.mixer.proofs.Mix2nizk.Prover prover ;
int n; int n;
Crypto.EncryptionRandomness[] randomnesses; Crypto.EncryptionRandomness[] randomnesses;
Crypto.RerandomizableEncryptedMessage[] encryptedMessage; Crypto.RerandomizableEncryptedMessage[] encryptedMessage;