switch secret with share

DKG
tzlil.gon 2016-04-08 15:46:54 +03:00
parent 5d564c834c
commit 3e1f59ec2b
24 changed files with 98 additions and 214 deletions

View File

@ -1,108 +0,0 @@
package meerkat.crypto.concrete.distributed_key_generation.Communication;
import com.google.protobuf.Message;
import meerkat.crypto.utilitis.Channel;
import meerkat.protobuf.DKGMessages;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
/**
* Created by Tzlil on 2/14/2016.
*/
// TODO: Change nane to network
public class ChannelImpl implements Channel {
public static int BROADCAST = 0;
private static ChannelImpl[] channels = null;
protected final Queue<DKGMessages.Mail> mailbox;
protected final int id;
protected final int n;
protected Thread receiverThread;
public ChannelImpl(int id, int n) {
if (channels == null){
channels = new ChannelImpl[n];
}
this.mailbox = new ArrayBlockingQueue<DKGMessages.Mail>( n * n * n);
this.id = id;
this.n = n;
channels[id - 1] = this;
}
public int getId() {
return id;
}
@Override
public void sendMessage(int destUser, DKGMessages.Mail.Type type, Message msg) {
if(destUser < 1 || destUser > n)
return;
ChannelImpl channel = channels[destUser - 1];
if (channel == null)
return;
DKGMessages.Mail mail = DKGMessages.Mail.newBuilder()
.setSender(id)
.setDestination(destUser)
.setIsPrivate(true)
.setType(type)
.setMessage(msg.toByteString())
.build();
synchronized (channel.mailbox) {
channel.mailbox.add(mail);
channel.mailbox.notify();
}
}
@Override
public void broadcastMessage(DKGMessages.Mail.Type type,Message msg) {
ChannelImpl channel;
DKGMessages.Mail mail = DKGMessages.Mail.newBuilder()
.setSender(id)
.setDestination(BROADCAST)
.setIsPrivate(false)
.setType(type)
.setMessage(msg.toByteString())
.build();
for (int i = 0 ; i < n ; i++){
channel = channels[i];
synchronized (channel.mailbox) {
channel.mailbox.add(mail);
channel.mailbox.notify();
}
}
}
@Override
public void registerReceiverCallback(final ReceiverCallback callback) {
try{
receiverThread.interrupt();
}catch (Exception e){
//do nothing
}
receiverThread = new Thread(new Runnable() {
@Override
public void run() {
while (true){
try {
synchronized (mailbox) {
while (!mailbox.isEmpty()) {
callback.receiveMail(mailbox.remove());
}
mailbox.wait();
}
} catch (InterruptedException e) {
//do nothing
}
}
}
});
receiverThread.start();
}
}

View File

@ -1,4 +1,4 @@
package meerkat.crypto.concrete.distributed_key_generation.Communication; package meerkat.crypto.concrete.distributed_key_generation.communication;
import com.google.protobuf.Message; import com.google.protobuf.Message;
import meerkat.crypto.utilitis.Channel; import meerkat.crypto.utilitis.Channel;
@ -9,13 +9,19 @@ import meerkat.protobuf.DKGMessages;
*/ */
public abstract class MailHandler implements Channel.ReceiverCallback{ public abstract class MailHandler implements Channel.ReceiverCallback{
public static final int BROADCAST = 0;
private MessageHandler messageHandler; private MessageHandler messageHandler;
public MailHandler(MessageHandler messageHandler){ public MailHandler(MessageHandler messageHandler){
this.messageHandler = messageHandler; this.messageHandler = messageHandler;
} }
public abstract Message extractMessage(DKGMessages.Mail mail); public abstract Message extractMessage(DKGMessages.Mail mail);
public boolean isBroadcast(DKGMessages.Mail mail){
return mail.getDestination() == BROADCAST;
}
public void receiveMail(DKGMessages.Mail mail){ public void receiveMail(DKGMessages.Mail mail){
Message message = extractMessage(mail); Message message = extractMessage(mail);
@ -24,28 +30,22 @@ public abstract class MailHandler implements Channel.ReceiverCallback{
switch (mail.getType()) { switch (mail.getType()) {
case SHARE: case SHARE:
messageHandler.handleSecretMessage(mail.getSender(), mail.getDestination() == ChannelImpl.BROADCAST messageHandler.handleSecretMessage(mail.getSender(), isBroadcast(mail),message);
, message);
break; break;
case COMMITMENT: case COMMITMENT:
messageHandler.handleCommitmentMessage(mail.getSender(), mail.getDestination() == ChannelImpl.BROADCAST messageHandler.handleCommitmentMessage(mail.getSender(), isBroadcast(mail),message);
, message);
break; break;
case DONE: case DONE:
messageHandler.handleDoneMessage(mail.getSender(), mail.getDestination() == ChannelImpl.BROADCAST messageHandler.handleDoneMessage(mail.getSender(), isBroadcast(mail),message);
, message);
break; break;
case COMPLAINT: case COMPLAINT:
messageHandler.handleComplaintMessage(mail.getSender(), mail.getDestination() == ChannelImpl.BROADCAST messageHandler.handleComplaintMessage(mail.getSender(), isBroadcast(mail),message);
, message);
break; break;
case ANSWER: case ANSWER:
messageHandler.handleAnswerMessage(mail.getSender(), mail.getDestination() == ChannelImpl.BROADCAST messageHandler.handleAnswerMessage(mail.getSender(), isBroadcast(mail),message);
, message);
break; break;
case ABORT: case ABORT:
messageHandler.handleAbortMessage(mail.getSender(), mail.getDestination() == ChannelImpl.BROADCAST messageHandler.handleAbortMessage(mail.getSender(), isBroadcast(mail),message);
, message);
break; break;
default: default:
break; break;

View File

@ -1,4 +1,4 @@
package meerkat.crypto.concrete.distributed_key_generation.Communication; package meerkat.crypto.concrete.distributed_key_generation.communication;
import com.google.protobuf.Message; import com.google.protobuf.Message;

View File

@ -1,15 +1,14 @@
package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol; package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol;
import Communication.MailHandler;
import Communication.MessageHandler;
import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Message; import com.google.protobuf.Message;
import meerkat.crypto.concrete.distributed_key_generation.communication.MessageHandler;
import meerkat.protobuf.DKGMessages; import meerkat.protobuf.DKGMessages;
/** /**
* Created by Tzlil on 2/29/2016. * Created by Tzlil on 2/29/2016.
*/ */
public class MailHandler extends Communication.MailHandler { public class MailHandler extends meerkat.crypto.concrete.distributed_key_generation.communication.MailHandler {
private boolean isStage4; private boolean isStage4;

View File

@ -1,6 +1,5 @@
package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol; package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol;
import meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.DistributedKeyGenerationParty;
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial; import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
import java.util.ArrayList; import java.util.ArrayList;
@ -14,7 +13,7 @@ import java.util.Set;
* contains all relevant information on specific party during * contains all relevant information on specific party during
* the run of the safe protocol * the run of the safe protocol
*/ */
public class Party<T> extends DistributedKeyGenerationParty<T> { public class Party<T> extends meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.Party<T> {
public Polynomial.Point shareT; public Polynomial.Point shareT;
public boolean ysDoneFlag; public boolean ysDoneFlag;
public ArrayList<T> verifiableValues; public ArrayList<T> verifiableValues;

View File

@ -1,7 +1,6 @@
package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol; package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol;
import meerkat.crypto.concrete.secret_shring.feldman_verifiable.VerifiableSecretSharing; import meerkat.crypto.concrete.secret_shring.feldman_verifiable.VerifiableSecretSharing;
import meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.Protocol;
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial; import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import meerkat.protobuf.DKGMessages; import meerkat.protobuf.DKGMessages;
@ -137,8 +136,8 @@ public class Protocol<T> extends meerkat.crypto.concrete.distributed_key_generat
DKGMessages.DoubleShareMessage doubleShareMessage = DKGMessages.DoubleShareMessage.newBuilder() DKGMessages.DoubleShareMessage doubleShareMessage = DKGMessages.DoubleShareMessage.newBuilder()
.setI(i) .setI(i)
.setJ(j) .setJ(j)
.setSecret(ByteString.copyFrom(share.y.toByteArray())) .setShare(ByteString.copyFrom(share.y.toByteArray()))
.setSecretT(ByteString.copyFrom(shareT.y.toByteArray())) .setShareT(ByteString.copyFrom(shareT.y.toByteArray()))
.build(); .build();
return doubleShareMessage; return doubleShareMessage;
} }

View File

@ -3,7 +3,6 @@ package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol;
import meerkat.crypto.utilitis.Arithmetic; import meerkat.crypto.utilitis.Arithmetic;
import meerkat.crypto.utilitis.concrete.Fp; import meerkat.crypto.utilitis.concrete.Fp;
import meerkat.crypto.utilitis.Channel; import meerkat.crypto.utilitis.Channel;
import meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.User;
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial; import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
import meerkat.crypto.concrete.secret_shring.shamir.SecretSharing; import meerkat.crypto.concrete.secret_shring.shamir.SecretSharing;
import com.google.protobuf.Message; import com.google.protobuf.Message;
@ -22,7 +21,7 @@ public class User<T> extends meerkat.crypto.concrete.distributed_key_generation.
private Arithmetic<BigInteger> arithmetic; private Arithmetic<BigInteger> arithmetic;
private boolean isStage4; private boolean isStage4;
public User(Protocol sdkg, Channel channel) { public User(Protocol<T> sdkg, Channel channel) {
super(sdkg, channel); super(sdkg, channel);
this.sdkg = sdkg; this.sdkg = sdkg;
this.parties = sdkg.getParties(); this.parties = sdkg.getParties();
@ -176,7 +175,7 @@ public class User<T> extends meerkat.crypto.concrete.distributed_key_generation.
DKGMessages.ShareMessage secretMessage = DKGMessages.ShareMessage.newBuilder() DKGMessages.ShareMessage secretMessage = DKGMessages.ShareMessage.newBuilder()
.setI(doubleSecretMessage.getI()) .setI(doubleSecretMessage.getI())
.setJ(doubleSecretMessage.getJ()) .setJ(doubleSecretMessage.getJ())
.setSecret(doubleSecretMessage.getSecret()) .setShare(doubleSecretMessage.getShare())
.build(); .build();
return super.isValidSecretMessage(sender,isBroadcast,secretMessage); return super.isValidSecretMessage(sender,isBroadcast,secretMessage);
} }
@ -190,8 +189,8 @@ public class User<T> extends meerkat.crypto.concrete.distributed_key_generation.
if (isValidSecretMessage(sender,isBroadcast,doubleSecretMessage)) { if (isValidSecretMessage(sender,isBroadcast,doubleSecretMessage)) {
int i = doubleSecretMessage.getI(); int i = doubleSecretMessage.getI();
synchronized (parties[i - 1]) { synchronized (parties[i - 1]) {
parties[i - 1].share = extractShare(id, doubleSecretMessage.getSecret()); parties[i - 1].share = extractShare(id, doubleSecretMessage.getShare());
parties[i - 1].shareT = extractShare(id, doubleSecretMessage.getSecretT()); parties[i - 1].shareT = extractShare(id, doubleSecretMessage.getShareT());
parties[i - 1].notify(); parties[i - 1].notify();
} }
} }
@ -209,7 +208,7 @@ public class User<T> extends meerkat.crypto.concrete.distributed_key_generation.
DKGMessages.ShareMessage secretMessage = DKGMessages.ShareMessage.newBuilder() DKGMessages.ShareMessage secretMessage = DKGMessages.ShareMessage.newBuilder()
.setI(doubleSecretMessage.getI()) .setI(doubleSecretMessage.getI())
.setJ(doubleSecretMessage.getJ()) .setJ(doubleSecretMessage.getJ())
.setSecret(doubleSecretMessage.getSecret()) .setShare(doubleSecretMessage.getShare())
.build(); .build();
return super.isValidAnswerMessage(sender, isBroadcast, secretMessage); return super.isValidAnswerMessage(sender, isBroadcast, secretMessage);
}else{ }else{
@ -230,8 +229,8 @@ public class User<T> extends meerkat.crypto.concrete.distributed_key_generation.
if(isValidAnswerMessage(sender,isBroadcast,doubleSecretMessage)) { if(isValidAnswerMessage(sender,isBroadcast,doubleSecretMessage)) {
int i = doubleSecretMessage.getI(); int i = doubleSecretMessage.getI();
int j = doubleSecretMessage.getJ(); int j = doubleSecretMessage.getJ();
Polynomial.Point secret = extractShare(j, doubleSecretMessage.getSecret()); Polynomial.Point secret = extractShare(j, doubleSecretMessage.getShare());
Polynomial.Point secretT = extractShare(j, doubleSecretMessage.getSecretT()); Polynomial.Point secretT = extractShare(j, doubleSecretMessage.getShareT());
synchronized (parties[i - 1]) { synchronized (parties[i - 1]) {
if (!isStage4) { if (!isStage4) {
if (sdkg.isValidShare(secret, secretT, parties[j - 1].verifiableValues, i)) { if (sdkg.isValidShare(secret, secretT, parties[j - 1].verifiableValues, i)) {
@ -310,8 +309,8 @@ public class User<T> extends meerkat.crypto.concrete.distributed_key_generation.
if (isValidComplaintMessage(sender,isBroadcast,ysComplaintMessage)) { if (isValidComplaintMessage(sender,isBroadcast,ysComplaintMessage)) {
int i = ysComplaintMessage.getI(); int i = ysComplaintMessage.getI();
int j = ysComplaintMessage.getJ(); int j = ysComplaintMessage.getJ();
Polynomial.Point secret = extractShare(i,ysComplaintMessage.getSecret()); Polynomial.Point secret = extractShare(i,ysComplaintMessage.getShare());
Polynomial.Point secretT = extractShare(i,ysComplaintMessage.getSecretT()); Polynomial.Point secretT = extractShare(i,ysComplaintMessage.getShareT());
if (sdkg.isValidShare(secret, secretT, parties[i - 1].verifiableValues, j) if (sdkg.isValidShare(secret, secretT, parties[i - 1].verifiableValues, j)
&& !dkg.isValidShare(secret,parties[i - 1].commitments, j)) { && !dkg.isValidShare(secret,parties[i - 1].commitments, j)) {
synchronized (parties[i - 1]) { synchronized (parties[i - 1]) {

View File

@ -1,15 +1,14 @@
package meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol; package meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol;
import Communication.MailHandler;
import Communication.MessageHandler;
import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Message; import com.google.protobuf.Message;
import meerkat.crypto.concrete.distributed_key_generation.communication.MessageHandler;
import meerkat.protobuf.DKGMessages; import meerkat.protobuf.DKGMessages;
/** /**
* Created by Tzlil on 2/29/2016. * Created by Tzlil on 2/29/2016.
*/ */
public class MailHandler extends Communication.MailHandler { public class MailHandler extends meerkat.crypto.concrete.distributed_key_generation.communication.MailHandler {
public MailHandler(MessageHandler messageHandler) { public MailHandler(MessageHandler messageHandler) {
super(messageHandler); super(messageHandler);

View File

@ -11,21 +11,20 @@ import java.util.Arrays;
* contains all relevant information on specific party during * contains all relevant information on specific party during
* the run of Joint Feldamn protocol * the run of Joint Feldamn protocol
*/ */
// TODO: comments for every field.
public class Party<T> { public class Party<T> {
public final int id; public final int id;
public Polynomial.Point share; public Polynomial.Point share;
public ArrayList<T> commitments; public ArrayList<T> commitments;
public boolean doneFlag; public boolean doneFlag;
public DistributedKeyGeneration.ComplaintState[] complaints; public Protocol.ComplaintState[] complaints;
public boolean aborted; public boolean aborted;
public Party(int id, int n, int t) { public Party(int id, int n, int t) {
this.id = id; this.id = id;
this.share = null; this.share = null;
this.doneFlag = false; this.doneFlag = false;
this.complaints = new DistributedKeyGeneration.ComplaintState[n]; this.complaints = new Protocol.ComplaintState[n];
Arrays.fill(this.complaints, DistributedKeyGeneration.ComplaintState.OK); Arrays.fill(this.complaints, Protocol.ComplaintState.OK);
this.commitments = new ArrayList<T>(t + 1); this.commitments = new ArrayList<T>(t + 1);
for (int i = 0; i <= t ; i++){ for (int i = 0; i <= t ; i++){
commitments.add(null); commitments.add(null);

View File

@ -146,7 +146,7 @@ public class Protocol<T> extends VerifiableSecretSharing<T> {
DKGMessages.ShareMessage.newBuilder() DKGMessages.ShareMessage.newBuilder()
.setI(id) .setI(id)
.setJ(j) .setJ(j)
.setSecret(secret) .setShare(secret)
.build()); .build());
} }
@ -221,7 +221,7 @@ public class Protocol<T> extends VerifiableSecretSharing<T> {
channel.broadcastMessage(DKGMessages.Mail.Type.ANSWER, DKGMessages.ShareMessage.newBuilder() channel.broadcastMessage(DKGMessages.Mail.Type.ANSWER, DKGMessages.ShareMessage.newBuilder()
.setI(id) .setI(id)
.setJ(j) .setJ(j)
.setSecret(ByteString.copyFrom(getShare(j).y.toByteArray())) .setShare(ByteString.copyFrom(getShare(j).y.toByteArray()))
.build()); .build());
} }

View File

@ -1,7 +1,6 @@
package meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol; package meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol;
import meerkat.crypto.utilitis.Channel; import meerkat.crypto.utilitis.Channel;
import Communication.MailHandler;
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial; import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import com.google.protobuf.Message; import com.google.protobuf.Message;
@ -11,7 +10,6 @@ import org.factcenter.qilin.primitives.Group;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Set; import java.util.Set;
import meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.DistributedKeyGeneration.ComplaintState;
/** /**
* Created by Tzlil on 3/14/2016. * Created by Tzlil on 3/14/2016.
@ -20,14 +18,14 @@ import meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol
*/ */
public class User<T> implements Runnable{ public class User<T> implements Runnable{
protected final DistributedKeyGeneration<T> dkg; protected final Protocol<T> dkg;
protected final T g; protected final T g;
protected final Group<T> group; protected final Group<T> group;
protected final int n; protected final int n;
protected final int t; protected final int t;
protected final int id; protected final int id;
protected MailHandler mailHandler; protected meerkat.crypto.concrete.distributed_key_generation.communication.MailHandler mailHandler;
protected final Channel channel; protected final Channel channel;
protected final Party[] parties; protected final Party[] parties;
@ -36,7 +34,7 @@ public class User<T> implements Runnable{
protected ArrayList<T> commitments; // public verification values protected ArrayList<T> commitments; // public verification values
protected T y; // final public value protected T y; // final public value
public User(DistributedKeyGeneration<T> dkg, Channel channel) { public User(Protocol<T> dkg, Channel channel) {
this.dkg = dkg; this.dkg = dkg;
this.g = dkg.getGenerator(); this.g = dkg.getGenerator();
@ -61,7 +59,7 @@ public class User<T> implements Runnable{
* create MailHandler and register it as ReceiverCallback * create MailHandler and register it as ReceiverCallback
*/ */
protected void registerReceiverCallback(){ protected void registerReceiverCallback(){
this.mailHandler = new DistributedKeyGenerationMailHandler(new MessageHandler()); this.mailHandler = new MailHandler(new MessageHandler());
channel.registerReceiverCallback(mailHandler); channel.registerReceiverCallback(mailHandler);
} }
@ -148,7 +146,7 @@ public class User<T> implements Runnable{
for (int i = 0; i < n; i++){ for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){ for (int j = 0; j < n; j++){
synchronized (parties[i]) { synchronized (parties[i]) {
while (parties[i].complaints[j].equals(ComplaintState.Waiting) && !parties[i].aborted) { while (parties[i].complaints[j].equals(Protocol.ComplaintState.Waiting) && !parties[i].aborted) {
try { try {
parties[i].wait(); parties[i].wait();
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -263,7 +261,7 @@ public class User<T> implements Runnable{
} }
public class MessageHandler implements Communication.MessageHandler{ public class MessageHandler implements meerkat.crypto.concrete.distributed_key_generation.communication.MessageHandler{
public MessageHandler(){ public MessageHandler(){
@ -320,7 +318,7 @@ public class User<T> implements Runnable{
DKGMessages.ShareMessage secretMessage = (DKGMessages.ShareMessage) message; DKGMessages.ShareMessage secretMessage = (DKGMessages.ShareMessage) message;
if(isValidSecretMessage(sender,isBroadcast,secretMessage)) { if(isValidSecretMessage(sender,isBroadcast,secretMessage)) {
int i = secretMessage.getI(); int i = secretMessage.getI();
Polynomial.Point secret = extractShare(id,secretMessage.getSecret()); Polynomial.Point secret = extractShare(id,secretMessage.getShare());
synchronized (parties[i -1]) { synchronized (parties[i -1]) {
parties[i - 1].share = secret; parties[i - 1].share = secret;
parties[i - 1].notify(); parties[i - 1].notify();
@ -358,7 +356,7 @@ public class User<T> implements Runnable{
protected boolean isValidComplaintMessage(int sender, boolean isBroadcast, DKGMessages.IDMessage complaintMessage){ protected boolean isValidComplaintMessage(int sender, boolean isBroadcast, DKGMessages.IDMessage complaintMessage){
int i = sender; int i = sender;
int j = complaintMessage.getId(); int j = complaintMessage.getId();
return isBroadcast && parties[i - 1].complaints[j - 1].equals( ComplaintState.OK); return isBroadcast && parties[i - 1].complaints[j - 1].equals( Protocol.ComplaintState.OK);
} }
/** /**
@ -371,7 +369,7 @@ public class User<T> implements Runnable{
int i = sender; int i = sender;
int j = complaintMessage.getId(); int j = complaintMessage.getId();
synchronized (parties[j - 1]) { synchronized (parties[j - 1]) {
parties[j - 1].complaints[i - 1] = ComplaintState.Waiting; parties[j - 1].complaints[i - 1] = Protocol.ComplaintState.Waiting;
parties[j - 1].notify(); parties[j - 1].notify();
} }
} }
@ -390,7 +388,7 @@ public class User<T> implements Runnable{
if(sender != i || !isBroadcast) if(sender != i || !isBroadcast)
return false; return false;
else else
return j >= 1 && j <= n && parties[i - 1].complaints[j - 1].equals(ComplaintState.Waiting); return j >= 1 && j <= n && parties[i - 1].complaints[j - 1].equals(Protocol.ComplaintState.Waiting);
} }
/** /**
@ -404,12 +402,12 @@ public class User<T> implements Runnable{
if(isValidAnswerMessage(sender,isBroadcast,secretMessage)) { if(isValidAnswerMessage(sender,isBroadcast,secretMessage)) {
int i = secretMessage.getI(); int i = secretMessage.getI();
int j = secretMessage.getJ(); int j = secretMessage.getJ();
Polynomial.Point secret = extractShare(j,secretMessage.getSecret()); Polynomial.Point secret = extractShare(j,secretMessage.getShare());
synchronized (parties[i - 1]) { synchronized (parties[i - 1]) {
if (dkg.isValidShare(secret, parties[i - 1].commitments, j)) { if (dkg.isValidShare(secret, parties[i - 1].commitments, j)) {
parties[i - 1].complaints[j - 1] = ComplaintState.NonDisqualified; parties[i - 1].complaints[j - 1] = Protocol.ComplaintState.NonDisqualified;
} else { } else {
parties[i - 1].complaints[j - 1] = ComplaintState.Disqualified; parties[i - 1].complaints[j - 1] = Protocol.ComplaintState.Disqualified;
} }
if (j == id) { if (j == id) {
parties[i - 1].share = secret; parties[i - 1].share = secret;

View File

@ -1,8 +1,7 @@
package meerkat.crypto.concrete.secret_shring.feldman_verifiable; package meerkat.crypto.concrete.secret_shring.feldman_verifiable;
import meerkat.crypto.concrete.secret_shring.ShamirSecretSharing.Polynomial; import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
import meerkat.crypto.concrete.secret_shring.ShamirSecretSharing.SecretSharing; import meerkat.crypto.concrete.secret_shring.shamir.SecretSharing;
import org.factcenter.qilin.primitives.Group; import org.factcenter.qilin.primitives.Group;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -1,8 +1,8 @@
package Utils; package Utils;
import Arithmetics.Arithmetic; import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
import Arithmetics.Fp; import meerkat.crypto.utilitis.Arithmetic;
import ShamirSecretSharing.Polynomial; import meerkat.crypto.utilitis.concrete.Fp;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Random; import java.util.Random;
@ -12,7 +12,7 @@ import java.util.Random;
*/ */
public class GenerateRandomPolynomial { public class GenerateRandomPolynomial {
public static Polynomial generateRandomPolynomial(int degree, int bits, Random random,Arithmetic<BigInteger> arithmetic) { public static Polynomial generateRandomPolynomial(int degree, int bits, Random random, Arithmetic<BigInteger> arithmetic) {
BigInteger[] coefficients = new BigInteger[degree + 1]; BigInteger[] coefficients = new BigInteger[degree + 1];
for (int i = 0 ; i <= degree; i++ ){ for (int i = 0 ; i <= degree; i++ ){

View File

@ -1,7 +1,7 @@
package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol; package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol;
import meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol.*;
import meerkat.crypto.utilitis.Channel; import meerkat.crypto.utilitis.Channel;
import meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.DistributedKeyGeneration;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Random; import java.util.Random;
@ -10,11 +10,11 @@ import java.util.Set;
/** /**
* Created by Tzlil on 3/29/2016. * Created by Tzlil on 3/29/2016.
*/ */
public class SDKGMaliciousUserImpl extends SecureDistributedKeyGenerationUser { public class SDKGMaliciousUserImpl<T> extends User<T> {
private final DistributedKeyGeneration maliciousSDKG; private final Protocol<T> maliciousSDKG;
private final Set<Integer> falls; private final Set<Integer> falls;
public SDKGMaliciousUserImpl(SecureDistributedKeyGeneration sdkg, SecureDistributedKeyGeneration maliciousSDKG public SDKGMaliciousUserImpl(Protocol<T> sdkg, Protocol<T> maliciousSDKG
, Channel channel, Set<Integer> falls) { , Channel channel, Set<Integer> falls) {
super(sdkg, channel); super(sdkg, channel);
this.falls = falls; this.falls = falls;
@ -22,10 +22,10 @@ public class SDKGMaliciousUserImpl extends SecureDistributedKeyGenerationUser {
maliciousSDKG.setParties(parties); maliciousSDKG.setParties(parties);
} }
public static SecureDistributedKeyGeneration generateMaliciousSDKG(SecureDistributedKeyGeneration sdkg,Channel channel,Random random){ public static<T> Protocol<T> generateMaliciousSDKG(Protocol<T> sdkg,Channel channel,Random random){
BigInteger q = sdkg.getQ(); BigInteger q = sdkg.getQ();
BigInteger zi = new BigInteger(q.bitLength(), random).mod(q); BigInteger zi = new BigInteger(q.bitLength(), random).mod(q);
SecureDistributedKeyGeneration malicious = new SecureDistributedKeyGeneration(sdkg.getT(),sdkg.getN(),zi,random,sdkg.getQ() Protocol<T> malicious = new Protocol<T>(sdkg.getT(),sdkg.getN(),zi,random,sdkg.getQ()
,sdkg.getGenerator(),sdkg.getH(),sdkg.getGroup(),sdkg.getId(),sdkg.getEncoder()); ,sdkg.getGenerator(),sdkg.getH(),sdkg.getGroup(),sdkg.getId(),sdkg.getEncoder());
malicious.setChannel(channel); malicious.setChannel(channel);
return malicious; return malicious;

View File

@ -1,9 +1,9 @@
package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol; package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol;
import Utils.ChannelImpl;
import meerkat.crypto.utilitis.Arithmetic; import meerkat.crypto.utilitis.Arithmetic;
import meerkat.crypto.utilitis.concrete.Fp; import meerkat.crypto.utilitis.concrete.Fp;
import meerkat.crypto.utilitis.Channel; import meerkat.crypto.utilitis.Channel;
import Communication.ChannelImpl;
import meerkat.crypto.concrete.secret_shring.feldman_verifiable.VerifiableSecretSharing; import meerkat.crypto.concrete.secret_shring.feldman_verifiable.VerifiableSecretSharing;
import meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.DKGMaliciousUser; import meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.DKGMaliciousUser;
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial; import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
@ -95,14 +95,14 @@ public class SDKGTest {
Set<Integer> QUAL; Set<Integer> QUAL;
Set<Integer> aborted; Set<Integer> aborted;
Set<Integer> malicious; Set<Integer> malicious;
SecureDistributedKeyGenerationUser[] sdkgs; User<BigInteger>[] sdkgs;
Thread[] threads; Thread[] threads;
BigInteger g; BigInteger g;
BigInteger h; BigInteger h;
BigInteger secret; BigInteger secret;
public Testable(Random random) { public Testable(Random random) {
this.sdkgs = new SecureDistributedKeyGenerationUser[n]; this.sdkgs = new User[n];
this.valids = new HashSet<Integer>(); this.valids = new HashSet<Integer>();
this.QUAL = new HashSet<Integer>(); this.QUAL = new HashSet<Integer>();
this.aborted = new HashSet<Integer>(); this.aborted = new HashSet<Integer>();
@ -117,14 +117,14 @@ public class SDKGTest {
int id; int id;
BigInteger s; BigInteger s;
Channel channel; Channel channel;
SecureDistributedKeyGeneration sdkg; Protocol<BigInteger> sdkg;
this.secret = BigInteger.ZERO; this.secret = BigInteger.ZERO;
ByteEncoder<BigInteger> encoder = new BigIntegerByteEncoder(); ByteEncoder<BigInteger> encoder = new BigIntegerByteEncoder();
while (!ids.isEmpty()) { while (!ids.isEmpty()) {
id = ids.remove(random.nextInt(ids.size())); id = ids.remove(random.nextInt(ids.size()));
s = randomIntModQ(random); s = randomIntModQ(random);
channel = new ChannelImpl(id,n); channel = new ChannelImpl(id,n);
sdkg = new SecureDistributedKeyGeneration(t, n, s, random, q, g , h, group, id,encoder); sdkg = new Protocol<BigInteger>(t, n, s, random, q, g , h, group, id,encoder);
sdkgs[id - 1] = randomSDKGUser(id,channel,sdkg,random); sdkgs[id - 1] = randomSDKGUser(id,channel,sdkg,random);
threads[id - 1] = new Thread(sdkgs[id - 1]); threads[id - 1] = new Thread(sdkgs[id - 1]);
if(QUAL.contains(id)){ if(QUAL.contains(id)){
@ -134,18 +134,18 @@ public class SDKGTest {
} }
public SecureDistributedKeyGenerationUser randomSDKGUser(int id, Channel channel, SecureDistributedKeyGeneration sdkg, Random random){ public User<BigInteger> randomSDKGUser(int id, Channel channel, Protocol<BigInteger> sdkg, Random random){
if (QUAL.size() <= t) { if (QUAL.size() <= t) {
valids.add(id); valids.add(id);
QUAL.add(id); QUAL.add(id);
return new SecureDistributedKeyGenerationUser(sdkg,channel); return new User<BigInteger>(sdkg,channel);
}else{ }else{
int type = random.nextInt(3); int type = random.nextInt(3);
switch (type){ switch (type){
case 0:// regular case 0:// regular
valids.add(id); valids.add(id);
QUAL.add(id); QUAL.add(id);
return new SecureDistributedKeyGenerationUser(sdkg,channel); return new User<BigInteger>(sdkg,channel);
case 1:// abort case 1:// abort
int abortStage = random.nextInt(3) + 1; // 1 or 2 or 3 int abortStage = random.nextInt(3) + 1; // 1 or 2 or 3
aborted.add(id); aborted.add(id);
@ -156,7 +156,7 @@ public class SDKGTest {
case 2:// malicious case 2:// malicious
malicious.add(id); malicious.add(id);
Set<Integer> falls = DKGMaliciousUser.selectFallsRandomly(valids,random); Set<Integer> falls = DKGMaliciousUser.selectFallsRandomly(valids,random);
SecureDistributedKeyGeneration maliciousSDKG = SDKGMaliciousUserImpl.generateMaliciousSDKG(sdkg,channel,random); Protocol<BigInteger> maliciousSDKG = SDKGMaliciousUserImpl.generateMaliciousSDKG(sdkg,channel,random);
return new SDKGMaliciousUserImpl(sdkg,maliciousSDKG,channel,falls); return new SDKGMaliciousUserImpl(sdkg,maliciousSDKG,channel,falls);
default: default:
return null; return null;

View File

@ -6,11 +6,11 @@ import meerkat.protobuf.DKGMessages;
/** /**
* Created by Tzlil on 3/14/2016. * Created by Tzlil on 3/14/2016.
*/ */
public class SDKGUserImplAbort extends SecureDistributedKeyGenerationUser { public class SDKGUserImplAbort<T> extends User<T> {
final int abortStage; final int abortStage;
int stage; int stage;
public SDKGUserImplAbort(SecureDistributedKeyGeneration sdkg, Channel channel, int abortStage) { public SDKGUserImplAbort(Protocol<T> sdkg, Channel channel, int abortStage) {
super(sdkg, channel); super(sdkg, channel);
this.abortStage = abortStage;// 1 - 4 this.abortStage = abortStage;// 1 - 4
this.stage = 1; this.stage = 1;

View File

@ -8,11 +8,11 @@ import java.util.*;
/** /**
* Created by Tzlil on 3/21/2016. * Created by Tzlil on 3/21/2016.
*/ */
public class DKGMaliciousUser extends DistributedKeyGenerationUser { public class DKGMaliciousUser<T> extends User<T> {
private final DistributedKeyGeneration maliciousDkg; private final Protocol<T> maliciousDkg;
private final Set<Integer> falls; private final Set<Integer> falls;
public DKGMaliciousUser(DistributedKeyGeneration dkg, DistributedKeyGeneration maliciousDKG, Channel channel, Set<Integer> falls) { public DKGMaliciousUser(Protocol<T> dkg, Protocol<T> maliciousDKG, Channel channel, Set<Integer> falls) {
super(dkg, channel); super(dkg, channel);
this.falls = falls; this.falls = falls;
this.maliciousDkg = maliciousDKG; this.maliciousDkg = maliciousDKG;
@ -32,10 +32,10 @@ public class DKGMaliciousUser extends DistributedKeyGenerationUser {
return falls; return falls;
} }
public static DistributedKeyGeneration generateMaliciousDKG(DistributedKeyGeneration dkg,Channel channel,Random random){ public static <T> Protocol<T> generateMaliciousDKG(Protocol<T> dkg,Channel channel,Random random){
BigInteger q = dkg.getQ(); BigInteger q = dkg.getQ();
BigInteger zi = new BigInteger(q.bitLength(), random).mod(q); BigInteger zi = new BigInteger(q.bitLength(), random).mod(q);
DistributedKeyGeneration malicious = new DistributedKeyGeneration(dkg.getT(),dkg.getN(),zi,random,dkg.getQ() Protocol<T> malicious = new Protocol<T>(dkg.getT(),dkg.getN(),zi,random,dkg.getQ()
,dkg.getGenerator(),dkg.getGroup(),dkg.getId(),dkg.getEncoder()); ,dkg.getGenerator(),dkg.getGroup(),dkg.getId(),dkg.getEncoder());
malicious.setChannel(channel); malicious.setChannel(channel);
return malicious; return malicious;

View File

@ -1,14 +1,15 @@
package meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol; package meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol;
import Utils.ChannelImpl;
import meerkat.crypto.utilitis.Arithmetic; import meerkat.crypto.utilitis.Arithmetic;
import meerkat.crypto.utilitis.concrete.Fp; import meerkat.crypto.utilitis.concrete.Fp;
import meerkat.crypto.utilitis.Channel; import meerkat.crypto.utilitis.Channel;
import Communication.ChannelImpl;
import meerkat.crypto.concrete.secret_shring.feldman_verifiable.VerifiableSecretSharing; import meerkat.crypto.concrete.secret_shring.feldman_verifiable.VerifiableSecretSharing;
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial; import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
import meerkat.crypto.concrete.secret_shring.shamir.SecretSharing; import meerkat.crypto.concrete.secret_shring.shamir.SecretSharing;
import Utils.BigIntegerByteEncoder; import Utils.BigIntegerByteEncoder;
import Utils.GenerateRandomPrime; import Utils.GenerateRandomPrime;
import meerkat.protobuf.Crypto;
import org.factcenter.qilin.primitives.Group; import org.factcenter.qilin.primitives.Group;
import org.factcenter.qilin.primitives.concrete.Zpstar; import org.factcenter.qilin.primitives.concrete.Zpstar;
import org.factcenter.qilin.util.ByteEncoder; import org.factcenter.qilin.util.ByteEncoder;
@ -95,13 +96,13 @@ public class DKGTest {
Set<Integer> QUAL; Set<Integer> QUAL;
Set<Integer> aborted; Set<Integer> aborted;
Set<Integer> malicious; Set<Integer> malicious;
DistributedKeyGenerationUser[] dkgs; User<BigInteger>[] dkgs;
Thread[] threads; Thread[] threads;
BigInteger g; BigInteger g;
BigInteger secret; BigInteger secret;
public Testable(Random random) { public Testable(Random random) {
this.dkgs = new DistributedKeyGenerationUser[n]; this.dkgs = new User[n];
this.valids = new HashSet<Integer>(); this.valids = new HashSet<Integer>();
this.QUAL = new HashSet<Integer>(); this.QUAL = new HashSet<Integer>();
this.aborted = new HashSet<Integer>(); this.aborted = new HashSet<Integer>();
@ -114,7 +115,7 @@ public class DKGTest {
} }
int id; int id;
BigInteger s; BigInteger s;
DistributedKeyGeneration dkg; Protocol<BigInteger> dkg;
this.secret = BigInteger.ZERO; this.secret = BigInteger.ZERO;
Channel channel; Channel channel;
ByteEncoder<BigInteger> byteEncoder = new BigIntegerByteEncoder(); ByteEncoder<BigInteger> byteEncoder = new BigIntegerByteEncoder();
@ -122,7 +123,7 @@ public class DKGTest {
id = ids.remove(random.nextInt(ids.size())); id = ids.remove(random.nextInt(ids.size()));
channel = new ChannelImpl(id,n); channel = new ChannelImpl(id,n);
s = randomIntModQ(random); s = randomIntModQ(random);
dkg = new DistributedKeyGeneration(t, n, s, random, q, g, group, id,byteEncoder); dkg = new meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.Protocol<BigInteger>(t, n, s, random, q, g, group, id,byteEncoder);
dkgs[id - 1] = randomDKGUser(id,channel,dkg,random); dkgs[id - 1] = randomDKGUser(id,channel,dkg,random);
threads[id - 1] = new Thread(dkgs[id - 1]); threads[id - 1] = new Thread(dkgs[id - 1]);
if(QUAL.contains(id)){ if(QUAL.contains(id)){
@ -132,18 +133,18 @@ public class DKGTest {
} }
public DistributedKeyGenerationUser randomDKGUser(int id, Channel channel, DistributedKeyGeneration dkg, Random random){ public User<BigInteger> randomDKGUser(int id, Channel channel, Protocol<BigInteger> dkg, Random random){
if (QUAL.size() <= t) { if (QUAL.size() <= t) {
valids.add(id); valids.add(id);
QUAL.add(id); QUAL.add(id);
return new DistributedKeyGenerationUser(dkg,channel); return new User<BigInteger>(dkg,channel);
}else{ }else{
int type = random.nextInt(3); int type = random.nextInt(3);
switch (type){ switch (type){
case 0:// regular case 0:// regular
valids.add(id); valids.add(id);
QUAL.add(id); QUAL.add(id);
return new DistributedKeyGenerationUser(dkg,channel); return new User<BigInteger>(dkg,channel);
case 1:// abort case 1:// abort
int abortStage = random.nextInt(2) + 1; // 1 or 2 int abortStage = random.nextInt(2) + 1; // 1 or 2
aborted.add(id); aborted.add(id);
@ -154,7 +155,7 @@ public class DKGTest {
case 2:// malicious case 2:// malicious
malicious.add(id); malicious.add(id);
Set<Integer> falls = DKGMaliciousUser.selectFallsRandomly(valids,random); Set<Integer> falls = DKGMaliciousUser.selectFallsRandomly(valids,random);
DistributedKeyGeneration maliciousDKG = DKGMaliciousUser.generateMaliciousDKG(dkg,channel,random); Protocol<BigInteger> maliciousDKG = DKGMaliciousUser.generateMaliciousDKG(dkg,channel,random);
return new DKGMaliciousUser(dkg,maliciousDKG,channel,falls); return new DKGMaliciousUser(dkg,maliciousDKG,channel,falls);
default: default:
return null; return null;

View File

@ -6,11 +6,11 @@ import meerkat.protobuf.DKGMessages;
/** /**
* Created by Tzlil on 3/14/2016. * Created by Tzlil on 3/14/2016.
*/ */
public class DKGUserImplAbort extends DistributedKeyGenerationUser { public class DKGUserImplAbort<T> extends User<T> {
final int abortStage; final int abortStage;
int stage; int stage;
public DKGUserImplAbort(DistributedKeyGeneration dkg, Channel channel, int abortStage) { public DKGUserImplAbort(Protocol<T> dkg, Channel channel, int abortStage) {
super(dkg, channel); super(dkg, channel);
this.abortStage = abortStage;// 1 - 2 this.abortStage = abortStage;// 1 - 2
this.stage = 1; this.stage = 1;

View File

@ -1,6 +1,6 @@
package meerkat.crypto.concrete.secret_shring.feldman_verifiable; package meerkat.crypto.concrete.secret_shring.feldman_verifiable;
import meerkat.crypto.concrete.secret_shring.ShamirSecretSharing.Polynomial; import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
import org.factcenter.qilin.primitives.Group; import org.factcenter.qilin.primitives.Group;
import org.factcenter.qilin.primitives.concrete.Zpstar; import org.factcenter.qilin.primitives.concrete.Zpstar;
import org.junit.Before; import org.junit.Before;

View File

@ -1,6 +1,6 @@
package meerkat.crypto.concrete.secret_shring.shamir.PolynomialTests; package meerkat.crypto.concrete.secret_shring.shamir.PolynomialTests;
import Arithmetics.Z;
import Utils.GenerateRandomPolynomial; import Utils.GenerateRandomPolynomial;
import Utils.Z;
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial; import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

View File

@ -1,7 +1,7 @@
package meerkat.crypto.concrete.secret_shring.shamir.PolynomialTests; package meerkat.crypto.concrete.secret_shring.shamir.PolynomialTests;
import Arithmetics.Z;
import Utils.GenerateRandomPolynomial; import Utils.GenerateRandomPolynomial;
import Utils.Z;
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial; import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

View File

@ -1,7 +1,7 @@
package meerkat.crypto.concrete.secret_shring.shamir.PolynomialTests; package meerkat.crypto.concrete.secret_shring.shamir.PolynomialTests;
import Arithmetics.Z;
import Utils.GenerateRandomPolynomial; import Utils.GenerateRandomPolynomial;
import Utils.Z;
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial; import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

View File

@ -6,7 +6,7 @@ option java_package = "meerkat.protobuf";
message Mail{ message Mail{
enum Type { enum Type {
SECRET = 0; SHARE = 0;
COMMITMENT = 1; COMMITMENT = 1;
COMPLAINT = 2; COMPLAINT = 2;
DONE = 3; DONE = 3;
@ -23,17 +23,17 @@ message Mail{
bytes message = 5; bytes message = 5;
} }
message SecretMessage { message ShareMessage {
int32 i = 1; int32 i = 1;
int32 j = 2; int32 j = 2;
bytes secret = 3; bytes share = 3;
} }
message DoubleSecretMessage{ message DoubleShareMessage{
int32 i = 1; int32 i = 1;
int32 j = 2; int32 j = 2;
bytes secret = 3; bytes share = 3;
bytes secretT = 4; bytes shareT = 4;
} }
message CommitmentMessage{ message CommitmentMessage{