2015-12-31 11:58:25 -05:00
|
|
|
package verifier;
|
|
|
|
|
|
|
|
import com.google.protobuf.InvalidProtocolBufferException;
|
|
|
|
import meerkat.crypto.mixnet.Mix2ZeroKnowledgeVerifier;
|
2016-01-20 05:14:15 -05:00
|
|
|
import meerkat.crypto.mixnet.MixerOutput;
|
2015-12-31 11:58:25 -05:00
|
|
|
import meerkat.protobuf.Crypto;
|
|
|
|
import meerkat.protobuf.Mixing;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Tzlil on 12/30/2015.
|
|
|
|
*/
|
|
|
|
public final class VerifyTable {
|
|
|
|
|
2016-01-20 05:14:15 -05:00
|
|
|
public static boolean verifyTable(Mix2ZeroKnowledgeVerifier verifier,int n,MixerOutput mixerOutput)
|
|
|
|
throws InvalidProtocolBufferException {
|
2015-12-31 11:58:25 -05:00
|
|
|
int index1,index2,layer;
|
|
|
|
|
|
|
|
//assert n = 2^k
|
|
|
|
if ( (n &(n-1)) != 0)
|
|
|
|
throw new IllegalArgumentException("n");
|
|
|
|
|
|
|
|
int layers = 2*(int)(Math.log(n) / Math.log(2)) - 1;
|
|
|
|
//initialize locationChecksum table
|
|
|
|
// use for check BeneshNet validity
|
|
|
|
boolean[][] locationChecksum = new boolean[layers][n];
|
|
|
|
for (boolean[] locationChecksumLayer: locationChecksum) {
|
|
|
|
Arrays.fill(locationChecksumLayer,false);
|
|
|
|
}
|
|
|
|
|
2016-03-20 13:18:23 -04:00
|
|
|
Mixing.ZeroKnowledgeProof[][] zeroKnowledgeProofs = mixerOutput.getProofs();
|
2016-01-20 05:14:15 -05:00
|
|
|
Crypto.RerandomizableEncryptedMessage[][] rerandomizableEncryptedMessages = mixerOutput.getEncryptedMessages();
|
2015-12-31 11:58:25 -05:00
|
|
|
|
2016-03-20 13:18:23 -04:00
|
|
|
for (int i = 0; i < zeroKnowledgeProofs.length ; i++){
|
|
|
|
for (int j = 0; j < zeroKnowledgeProofs[i].length ; j ++){
|
|
|
|
Mixing.ZeroKnowledgeProof zkp = zeroKnowledgeProofs[i][j];
|
|
|
|
if(zkp == null){
|
|
|
|
int ttt = 1;
|
|
|
|
ttt++;
|
|
|
|
}
|
2015-12-31 11:58:25 -05:00
|
|
|
Mixing.ZeroKnowledgeProof.Location location = zkp.getLocation();
|
|
|
|
index1 = location.getI();
|
|
|
|
index2 = location.getJ();
|
|
|
|
layer = location.getLayer();
|
|
|
|
|
|
|
|
// check location validity
|
|
|
|
if (layer > layers >> 1) {
|
|
|
|
if (index2 - index1 != n >> (layers - layer))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if (index2 - index1 != n >> (layer + 1))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// mark location in table
|
|
|
|
locationChecksum[layer][index1] = true;
|
|
|
|
locationChecksum[layer][index2] = true;
|
|
|
|
|
|
|
|
// verify proof
|
|
|
|
if(!verifier.verify(rerandomizableEncryptedMessages[layer][index1],
|
|
|
|
rerandomizableEncryptedMessages[layer][index2],
|
|
|
|
rerandomizableEncryptedMessages[layer + 1][index1],
|
|
|
|
rerandomizableEncryptedMessages[layer + 1][index2],
|
|
|
|
zkp)) {
|
|
|
|
|
|
|
|
verifier.verify(rerandomizableEncryptedMessages[layer][index1],
|
|
|
|
rerandomizableEncryptedMessages[layer][index2],
|
|
|
|
rerandomizableEncryptedMessages[layer + 1][index1],
|
|
|
|
rerandomizableEncryptedMessages[layer + 1][index2],
|
|
|
|
zkp);
|
|
|
|
System.out.print("\n\n\nlayer " + layer + " i , j " + index1 + " , " + index2 + "\n\n\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// verify all necessary locations for BeneshNet were proved
|
|
|
|
for (boolean[] checksumLayer: locationChecksum) {
|
|
|
|
for (boolean locationBoolean: checksumLayer) {
|
|
|
|
if (!locationBoolean)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|