diff --git a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/Communication/ChannelImpl.java b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/Communication/ChannelImpl.java deleted file mode 100644 index 04fa4ef..0000000 --- a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/Communication/ChannelImpl.java +++ /dev/null @@ -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 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( 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(); - } - - - -} diff --git a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/Communication/MailHandler.java b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/Communication/MailHandler.java index b01801f..c646a5a 100644 --- a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/Communication/MailHandler.java +++ b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/Communication/MailHandler.java @@ -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 meerkat.crypto.utilitis.Channel; @@ -9,13 +9,19 @@ import meerkat.protobuf.DKGMessages; */ public abstract class MailHandler implements Channel.ReceiverCallback{ + public static final int BROADCAST = 0; private MessageHandler messageHandler; + public MailHandler(MessageHandler messageHandler){ this.messageHandler = messageHandler; } public abstract Message extractMessage(DKGMessages.Mail mail); + public boolean isBroadcast(DKGMessages.Mail mail){ + return mail.getDestination() == BROADCAST; + } + public void receiveMail(DKGMessages.Mail mail){ Message message = extractMessage(mail); @@ -24,28 +30,22 @@ public abstract class MailHandler implements Channel.ReceiverCallback{ switch (mail.getType()) { case SHARE: - messageHandler.handleSecretMessage(mail.getSender(), mail.getDestination() == ChannelImpl.BROADCAST - , message); + messageHandler.handleSecretMessage(mail.getSender(), isBroadcast(mail),message); break; case COMMITMENT: - messageHandler.handleCommitmentMessage(mail.getSender(), mail.getDestination() == ChannelImpl.BROADCAST - , message); + messageHandler.handleCommitmentMessage(mail.getSender(), isBroadcast(mail),message); break; case DONE: - messageHandler.handleDoneMessage(mail.getSender(), mail.getDestination() == ChannelImpl.BROADCAST - , message); + messageHandler.handleDoneMessage(mail.getSender(), isBroadcast(mail),message); break; case COMPLAINT: - messageHandler.handleComplaintMessage(mail.getSender(), mail.getDestination() == ChannelImpl.BROADCAST - , message); + messageHandler.handleComplaintMessage(mail.getSender(), isBroadcast(mail),message); break; case ANSWER: - messageHandler.handleAnswerMessage(mail.getSender(), mail.getDestination() == ChannelImpl.BROADCAST - , message); + messageHandler.handleAnswerMessage(mail.getSender(), isBroadcast(mail),message); break; case ABORT: - messageHandler.handleAbortMessage(mail.getSender(), mail.getDestination() == ChannelImpl.BROADCAST - , message); + messageHandler.handleAbortMessage(mail.getSender(), isBroadcast(mail),message); break; default: break; diff --git a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/Communication/MessageHandler.java b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/Communication/MessageHandler.java index 74b453a..a58cbcc 100644 --- a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/Communication/MessageHandler.java +++ b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/Communication/MessageHandler.java @@ -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; diff --git a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/MailHandler.java b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/MailHandler.java index 4683f04..c35fe6c 100644 --- a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/MailHandler.java +++ b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/MailHandler.java @@ -1,15 +1,14 @@ 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.Message; +import meerkat.crypto.concrete.distributed_key_generation.communication.MessageHandler; import meerkat.protobuf.DKGMessages; /** * 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; diff --git a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/Party.java b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/Party.java index 82ebba8..c0ee63a 100644 --- a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/Party.java +++ b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/Party.java @@ -1,6 +1,5 @@ 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 java.util.ArrayList; @@ -14,7 +13,7 @@ import java.util.Set; * contains all relevant information on specific party during * the run of the safe protocol */ -public class Party extends DistributedKeyGenerationParty { +public class Party extends meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.Party { public Polynomial.Point shareT; public boolean ysDoneFlag; public ArrayList verifiableValues; diff --git a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/Protocol.java b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/Protocol.java index db0cc56..13ff0e6 100644 --- a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/Protocol.java +++ b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/Protocol.java @@ -1,7 +1,6 @@ package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol; 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 com.google.protobuf.ByteString; import meerkat.protobuf.DKGMessages; @@ -137,8 +136,8 @@ public class Protocol extends meerkat.crypto.concrete.distributed_key_generat DKGMessages.DoubleShareMessage doubleShareMessage = DKGMessages.DoubleShareMessage.newBuilder() .setI(i) .setJ(j) - .setSecret(ByteString.copyFrom(share.y.toByteArray())) - .setSecretT(ByteString.copyFrom(shareT.y.toByteArray())) + .setShare(ByteString.copyFrom(share.y.toByteArray())) + .setShareT(ByteString.copyFrom(shareT.y.toByteArray())) .build(); return doubleShareMessage; } diff --git a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/User.java b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/User.java index ac99b6e..f976ff9 100644 --- a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/User.java +++ b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/User.java @@ -3,7 +3,6 @@ package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol; import meerkat.crypto.utilitis.Arithmetic; import meerkat.crypto.utilitis.concrete.Fp; 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.SecretSharing; import com.google.protobuf.Message; @@ -22,7 +21,7 @@ public class User extends meerkat.crypto.concrete.distributed_key_generation. private Arithmetic arithmetic; private boolean isStage4; - public User(Protocol sdkg, Channel channel) { + public User(Protocol sdkg, Channel channel) { super(sdkg, channel); this.sdkg = sdkg; this.parties = sdkg.getParties(); @@ -176,7 +175,7 @@ public class User extends meerkat.crypto.concrete.distributed_key_generation. DKGMessages.ShareMessage secretMessage = DKGMessages.ShareMessage.newBuilder() .setI(doubleSecretMessage.getI()) .setJ(doubleSecretMessage.getJ()) - .setSecret(doubleSecretMessage.getSecret()) + .setShare(doubleSecretMessage.getShare()) .build(); return super.isValidSecretMessage(sender,isBroadcast,secretMessage); } @@ -190,8 +189,8 @@ public class User extends meerkat.crypto.concrete.distributed_key_generation. if (isValidSecretMessage(sender,isBroadcast,doubleSecretMessage)) { int i = doubleSecretMessage.getI(); synchronized (parties[i - 1]) { - parties[i - 1].share = extractShare(id, doubleSecretMessage.getSecret()); - parties[i - 1].shareT = extractShare(id, doubleSecretMessage.getSecretT()); + parties[i - 1].share = extractShare(id, doubleSecretMessage.getShare()); + parties[i - 1].shareT = extractShare(id, doubleSecretMessage.getShareT()); parties[i - 1].notify(); } } @@ -209,7 +208,7 @@ public class User extends meerkat.crypto.concrete.distributed_key_generation. DKGMessages.ShareMessage secretMessage = DKGMessages.ShareMessage.newBuilder() .setI(doubleSecretMessage.getI()) .setJ(doubleSecretMessage.getJ()) - .setSecret(doubleSecretMessage.getSecret()) + .setShare(doubleSecretMessage.getShare()) .build(); return super.isValidAnswerMessage(sender, isBroadcast, secretMessage); }else{ @@ -230,8 +229,8 @@ public class User extends meerkat.crypto.concrete.distributed_key_generation. if(isValidAnswerMessage(sender,isBroadcast,doubleSecretMessage)) { int i = doubleSecretMessage.getI(); int j = doubleSecretMessage.getJ(); - Polynomial.Point secret = extractShare(j, doubleSecretMessage.getSecret()); - Polynomial.Point secretT = extractShare(j, doubleSecretMessage.getSecretT()); + Polynomial.Point secret = extractShare(j, doubleSecretMessage.getShare()); + Polynomial.Point secretT = extractShare(j, doubleSecretMessage.getShareT()); synchronized (parties[i - 1]) { if (!isStage4) { if (sdkg.isValidShare(secret, secretT, parties[j - 1].verifiableValues, i)) { @@ -310,8 +309,8 @@ public class User extends meerkat.crypto.concrete.distributed_key_generation. if (isValidComplaintMessage(sender,isBroadcast,ysComplaintMessage)) { int i = ysComplaintMessage.getI(); int j = ysComplaintMessage.getJ(); - Polynomial.Point secret = extractShare(i,ysComplaintMessage.getSecret()); - Polynomial.Point secretT = extractShare(i,ysComplaintMessage.getSecretT()); + Polynomial.Point secret = extractShare(i,ysComplaintMessage.getShare()); + Polynomial.Point secretT = extractShare(i,ysComplaintMessage.getShareT()); if (sdkg.isValidShare(secret, secretT, parties[i - 1].verifiableValues, j) && !dkg.isValidShare(secret,parties[i - 1].commitments, j)) { synchronized (parties[i - 1]) { diff --git a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/MailHandler.java b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/MailHandler.java index 19c279e..8f971fc 100644 --- a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/MailHandler.java +++ b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/MailHandler.java @@ -1,15 +1,14 @@ 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.Message; +import meerkat.crypto.concrete.distributed_key_generation.communication.MessageHandler; import meerkat.protobuf.DKGMessages; /** * 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) { super(messageHandler); diff --git a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/Party.java b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/Party.java index b45d5b5..c30ca97 100644 --- a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/Party.java +++ b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/Party.java @@ -11,21 +11,20 @@ import java.util.Arrays; * contains all relevant information on specific party during * the run of Joint Feldamn protocol */ -// TODO: comments for every field. public class Party { public final int id; public Polynomial.Point share; public ArrayList commitments; public boolean doneFlag; - public DistributedKeyGeneration.ComplaintState[] complaints; + public Protocol.ComplaintState[] complaints; public boolean aborted; public Party(int id, int n, int t) { this.id = id; this.share = null; this.doneFlag = false; - this.complaints = new DistributedKeyGeneration.ComplaintState[n]; - Arrays.fill(this.complaints, DistributedKeyGeneration.ComplaintState.OK); + this.complaints = new Protocol.ComplaintState[n]; + Arrays.fill(this.complaints, Protocol.ComplaintState.OK); this.commitments = new ArrayList(t + 1); for (int i = 0; i <= t ; i++){ commitments.add(null); diff --git a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/Protocol.java b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/Protocol.java index ba0a77b..79a3f9c 100644 --- a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/Protocol.java +++ b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/Protocol.java @@ -146,7 +146,7 @@ public class Protocol extends VerifiableSecretSharing { DKGMessages.ShareMessage.newBuilder() .setI(id) .setJ(j) - .setSecret(secret) + .setShare(secret) .build()); } @@ -221,7 +221,7 @@ public class Protocol extends VerifiableSecretSharing { channel.broadcastMessage(DKGMessages.Mail.Type.ANSWER, DKGMessages.ShareMessage.newBuilder() .setI(id) .setJ(j) - .setSecret(ByteString.copyFrom(getShare(j).y.toByteArray())) + .setShare(ByteString.copyFrom(getShare(j).y.toByteArray())) .build()); } diff --git a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/User.java b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/User.java index f225d59..8475aef 100644 --- a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/User.java +++ b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/User.java @@ -1,7 +1,6 @@ package meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol; import meerkat.crypto.utilitis.Channel; -import Communication.MailHandler; import meerkat.crypto.concrete.secret_shring.shamir.Polynomial; import com.google.protobuf.ByteString; import com.google.protobuf.Message; @@ -11,7 +10,6 @@ import org.factcenter.qilin.primitives.Group; import java.math.BigInteger; import java.util.ArrayList; import java.util.Set; -import meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.DistributedKeyGeneration.ComplaintState; /** * Created by Tzlil on 3/14/2016. @@ -20,14 +18,14 @@ import meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol */ public class User implements Runnable{ - protected final DistributedKeyGeneration dkg; + protected final Protocol dkg; protected final T g; protected final Group group; protected final int n; protected final int t; protected final int id; - protected MailHandler mailHandler; + protected meerkat.crypto.concrete.distributed_key_generation.communication.MailHandler mailHandler; protected final Channel channel; protected final Party[] parties; @@ -36,7 +34,7 @@ public class User implements Runnable{ protected ArrayList commitments; // public verification values protected T y; // final public value - public User(DistributedKeyGeneration dkg, Channel channel) { + public User(Protocol dkg, Channel channel) { this.dkg = dkg; this.g = dkg.getGenerator(); @@ -61,7 +59,7 @@ public class User implements Runnable{ * create MailHandler and register it as ReceiverCallback */ protected void registerReceiverCallback(){ - this.mailHandler = new DistributedKeyGenerationMailHandler(new MessageHandler()); + this.mailHandler = new MailHandler(new MessageHandler()); channel.registerReceiverCallback(mailHandler); } @@ -148,7 +146,7 @@ public class User implements Runnable{ for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ 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 { parties[i].wait(); } catch (InterruptedException e) { @@ -263,7 +261,7 @@ public class User implements Runnable{ } - public class MessageHandler implements Communication.MessageHandler{ + public class MessageHandler implements meerkat.crypto.concrete.distributed_key_generation.communication.MessageHandler{ public MessageHandler(){ @@ -320,7 +318,7 @@ public class User implements Runnable{ DKGMessages.ShareMessage secretMessage = (DKGMessages.ShareMessage) message; if(isValidSecretMessage(sender,isBroadcast,secretMessage)) { int i = secretMessage.getI(); - Polynomial.Point secret = extractShare(id,secretMessage.getSecret()); + Polynomial.Point secret = extractShare(id,secretMessage.getShare()); synchronized (parties[i -1]) { parties[i - 1].share = secret; parties[i - 1].notify(); @@ -358,7 +356,7 @@ public class User implements Runnable{ protected boolean isValidComplaintMessage(int sender, boolean isBroadcast, DKGMessages.IDMessage complaintMessage){ int i = sender; 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 implements Runnable{ int i = sender; int j = complaintMessage.getId(); 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(); } } @@ -390,7 +388,7 @@ public class User implements Runnable{ if(sender != i || !isBroadcast) return false; 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 implements Runnable{ if(isValidAnswerMessage(sender,isBroadcast,secretMessage)) { int i = secretMessage.getI(); int j = secretMessage.getJ(); - Polynomial.Point secret = extractShare(j,secretMessage.getSecret()); + Polynomial.Point secret = extractShare(j,secretMessage.getShare()); synchronized (parties[i - 1]) { 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 { - parties[i - 1].complaints[j - 1] = ComplaintState.Disqualified; + parties[i - 1].complaints[j - 1] = Protocol.ComplaintState.Disqualified; } if (j == id) { parties[i - 1].share = secret; diff --git a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/secret_shring/feldman_verifiable/VerifiableSecretSharing.java b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/secret_shring/feldman_verifiable/VerifiableSecretSharing.java index a15f0e2..6f3638b 100644 --- a/destributed-key-generation/src/main/java/meerkat/crypto/concrete/secret_shring/feldman_verifiable/VerifiableSecretSharing.java +++ b/destributed-key-generation/src/main/java/meerkat/crypto/concrete/secret_shring/feldman_verifiable/VerifiableSecretSharing.java @@ -1,8 +1,7 @@ package meerkat.crypto.concrete.secret_shring.feldman_verifiable; -import meerkat.crypto.concrete.secret_shring.ShamirSecretSharing.Polynomial; -import meerkat.crypto.concrete.secret_shring.ShamirSecretSharing.SecretSharing; - +import meerkat.crypto.concrete.secret_shring.shamir.Polynomial; +import meerkat.crypto.concrete.secret_shring.shamir.SecretSharing; import org.factcenter.qilin.primitives.Group; import java.util.ArrayList; diff --git a/destributed-key-generation/src/test/java/Utils/GenerateRandomPolynomial.java b/destributed-key-generation/src/test/java/Utils/GenerateRandomPolynomial.java index 4ca7b6a..4521fcd 100644 --- a/destributed-key-generation/src/test/java/Utils/GenerateRandomPolynomial.java +++ b/destributed-key-generation/src/test/java/Utils/GenerateRandomPolynomial.java @@ -1,8 +1,8 @@ package Utils; -import Arithmetics.Arithmetic; -import Arithmetics.Fp; -import ShamirSecretSharing.Polynomial; +import meerkat.crypto.concrete.secret_shring.shamir.Polynomial; +import meerkat.crypto.utilitis.Arithmetic; +import meerkat.crypto.utilitis.concrete.Fp; import java.math.BigInteger; import java.util.Random; @@ -12,7 +12,7 @@ import java.util.Random; */ public class GenerateRandomPolynomial { - public static Polynomial generateRandomPolynomial(int degree, int bits, Random random,Arithmetic arithmetic) { + public static Polynomial generateRandomPolynomial(int degree, int bits, Random random, Arithmetic arithmetic) { BigInteger[] coefficients = new BigInteger[degree + 1]; for (int i = 0 ; i <= degree; i++ ){ diff --git a/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/SDKGMaliciousUserImpl.java b/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/SDKGMaliciousUserImpl.java index e4adfc6..34bd672 100644 --- a/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/SDKGMaliciousUserImpl.java +++ b/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/SDKGMaliciousUserImpl.java @@ -1,7 +1,7 @@ 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.concrete.distributed_key_generation.joint_feldman_protocol.DistributedKeyGeneration; import java.math.BigInteger; import java.util.Random; @@ -10,11 +10,11 @@ import java.util.Set; /** * Created by Tzlil on 3/29/2016. */ -public class SDKGMaliciousUserImpl extends SecureDistributedKeyGenerationUser { +public class SDKGMaliciousUserImpl extends User { - private final DistributedKeyGeneration maliciousSDKG; + private final Protocol maliciousSDKG; private final Set falls; - public SDKGMaliciousUserImpl(SecureDistributedKeyGeneration sdkg, SecureDistributedKeyGeneration maliciousSDKG + public SDKGMaliciousUserImpl(Protocol sdkg, Protocol maliciousSDKG , Channel channel, Set falls) { super(sdkg, channel); this.falls = falls; @@ -22,10 +22,10 @@ public class SDKGMaliciousUserImpl extends SecureDistributedKeyGenerationUser { maliciousSDKG.setParties(parties); } - public static SecureDistributedKeyGeneration generateMaliciousSDKG(SecureDistributedKeyGeneration sdkg,Channel channel,Random random){ + public static Protocol generateMaliciousSDKG(Protocol sdkg,Channel channel,Random random){ BigInteger q = sdkg.getQ(); BigInteger zi = new BigInteger(q.bitLength(), random).mod(q); - SecureDistributedKeyGeneration malicious = new SecureDistributedKeyGeneration(sdkg.getT(),sdkg.getN(),zi,random,sdkg.getQ() + Protocol malicious = new Protocol(sdkg.getT(),sdkg.getN(),zi,random,sdkg.getQ() ,sdkg.getGenerator(),sdkg.getH(),sdkg.getGroup(),sdkg.getId(),sdkg.getEncoder()); malicious.setChannel(channel); return malicious; diff --git a/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/SDKGTest.java b/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/SDKGTest.java index 6e44252..5fc7e04 100644 --- a/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/SDKGTest.java +++ b/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/SDKGTest.java @@ -1,9 +1,9 @@ package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol; +import Utils.ChannelImpl; import meerkat.crypto.utilitis.Arithmetic; import meerkat.crypto.utilitis.concrete.Fp; import meerkat.crypto.utilitis.Channel; -import Communication.ChannelImpl; import meerkat.crypto.concrete.secret_shring.feldman_verifiable.VerifiableSecretSharing; import meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.DKGMaliciousUser; import meerkat.crypto.concrete.secret_shring.shamir.Polynomial; @@ -95,14 +95,14 @@ public class SDKGTest { Set QUAL; Set aborted; Set malicious; - SecureDistributedKeyGenerationUser[] sdkgs; + User[] sdkgs; Thread[] threads; BigInteger g; BigInteger h; BigInteger secret; public Testable(Random random) { - this.sdkgs = new SecureDistributedKeyGenerationUser[n]; + this.sdkgs = new User[n]; this.valids = new HashSet(); this.QUAL = new HashSet(); this.aborted = new HashSet(); @@ -117,14 +117,14 @@ public class SDKGTest { int id; BigInteger s; Channel channel; - SecureDistributedKeyGeneration sdkg; + Protocol sdkg; this.secret = BigInteger.ZERO; ByteEncoder encoder = new BigIntegerByteEncoder(); while (!ids.isEmpty()) { id = ids.remove(random.nextInt(ids.size())); s = randomIntModQ(random); channel = new ChannelImpl(id,n); - sdkg = new SecureDistributedKeyGeneration(t, n, s, random, q, g , h, group, id,encoder); + sdkg = new Protocol(t, n, s, random, q, g , h, group, id,encoder); sdkgs[id - 1] = randomSDKGUser(id,channel,sdkg,random); threads[id - 1] = new Thread(sdkgs[id - 1]); if(QUAL.contains(id)){ @@ -134,18 +134,18 @@ public class SDKGTest { } - public SecureDistributedKeyGenerationUser randomSDKGUser(int id, Channel channel, SecureDistributedKeyGeneration sdkg, Random random){ + public User randomSDKGUser(int id, Channel channel, Protocol sdkg, Random random){ if (QUAL.size() <= t) { valids.add(id); QUAL.add(id); - return new SecureDistributedKeyGenerationUser(sdkg,channel); + return new User(sdkg,channel); }else{ int type = random.nextInt(3); switch (type){ case 0:// regular valids.add(id); QUAL.add(id); - return new SecureDistributedKeyGenerationUser(sdkg,channel); + return new User(sdkg,channel); case 1:// abort int abortStage = random.nextInt(3) + 1; // 1 or 2 or 3 aborted.add(id); @@ -156,7 +156,7 @@ public class SDKGTest { case 2:// malicious malicious.add(id); Set falls = DKGMaliciousUser.selectFallsRandomly(valids,random); - SecureDistributedKeyGeneration maliciousSDKG = SDKGMaliciousUserImpl.generateMaliciousSDKG(sdkg,channel,random); + Protocol maliciousSDKG = SDKGMaliciousUserImpl.generateMaliciousSDKG(sdkg,channel,random); return new SDKGMaliciousUserImpl(sdkg,maliciousSDKG,channel,falls); default: return null; diff --git a/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/SDKGUserImplAbort.java b/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/SDKGUserImplAbort.java index 2690048..0a7bb12 100644 --- a/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/SDKGUserImplAbort.java +++ b/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/gjkr_secure_protocol/SDKGUserImplAbort.java @@ -6,11 +6,11 @@ import meerkat.protobuf.DKGMessages; /** * Created by Tzlil on 3/14/2016. */ -public class SDKGUserImplAbort extends SecureDistributedKeyGenerationUser { +public class SDKGUserImplAbort extends User { final int abortStage; int stage; - public SDKGUserImplAbort(SecureDistributedKeyGeneration sdkg, Channel channel, int abortStage) { + public SDKGUserImplAbort(Protocol sdkg, Channel channel, int abortStage) { super(sdkg, channel); this.abortStage = abortStage;// 1 - 4 this.stage = 1; diff --git a/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/DKGMaliciousUser.java b/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/DKGMaliciousUser.java index 2c7bea2..f20076d 100644 --- a/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/DKGMaliciousUser.java +++ b/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/DKGMaliciousUser.java @@ -8,11 +8,11 @@ import java.util.*; /** * Created by Tzlil on 3/21/2016. */ -public class DKGMaliciousUser extends DistributedKeyGenerationUser { +public class DKGMaliciousUser extends User { - private final DistributedKeyGeneration maliciousDkg; + private final Protocol maliciousDkg; private final Set falls; - public DKGMaliciousUser(DistributedKeyGeneration dkg, DistributedKeyGeneration maliciousDKG, Channel channel, Set falls) { + public DKGMaliciousUser(Protocol dkg, Protocol maliciousDKG, Channel channel, Set falls) { super(dkg, channel); this.falls = falls; this.maliciousDkg = maliciousDKG; @@ -32,10 +32,10 @@ public class DKGMaliciousUser extends DistributedKeyGenerationUser { return falls; } - public static DistributedKeyGeneration generateMaliciousDKG(DistributedKeyGeneration dkg,Channel channel,Random random){ + public static Protocol generateMaliciousDKG(Protocol dkg,Channel channel,Random random){ BigInteger q = dkg.getQ(); BigInteger zi = new BigInteger(q.bitLength(), random).mod(q); - DistributedKeyGeneration malicious = new DistributedKeyGeneration(dkg.getT(),dkg.getN(),zi,random,dkg.getQ() + Protocol malicious = new Protocol(dkg.getT(),dkg.getN(),zi,random,dkg.getQ() ,dkg.getGenerator(),dkg.getGroup(),dkg.getId(),dkg.getEncoder()); malicious.setChannel(channel); return malicious; diff --git a/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/DKGTest.java b/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/DKGTest.java index f4b2780..19693f5 100644 --- a/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/DKGTest.java +++ b/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/DKGTest.java @@ -1,14 +1,15 @@ package meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol; +import Utils.ChannelImpl; import meerkat.crypto.utilitis.Arithmetic; import meerkat.crypto.utilitis.concrete.Fp; import meerkat.crypto.utilitis.Channel; -import Communication.ChannelImpl; import meerkat.crypto.concrete.secret_shring.feldman_verifiable.VerifiableSecretSharing; import meerkat.crypto.concrete.secret_shring.shamir.Polynomial; import meerkat.crypto.concrete.secret_shring.shamir.SecretSharing; import Utils.BigIntegerByteEncoder; import Utils.GenerateRandomPrime; +import meerkat.protobuf.Crypto; import org.factcenter.qilin.primitives.Group; import org.factcenter.qilin.primitives.concrete.Zpstar; import org.factcenter.qilin.util.ByteEncoder; @@ -95,13 +96,13 @@ public class DKGTest { Set QUAL; Set aborted; Set malicious; - DistributedKeyGenerationUser[] dkgs; + User[] dkgs; Thread[] threads; BigInteger g; BigInteger secret; public Testable(Random random) { - this.dkgs = new DistributedKeyGenerationUser[n]; + this.dkgs = new User[n]; this.valids = new HashSet(); this.QUAL = new HashSet(); this.aborted = new HashSet(); @@ -114,7 +115,7 @@ public class DKGTest { } int id; BigInteger s; - DistributedKeyGeneration dkg; + Protocol dkg; this.secret = BigInteger.ZERO; Channel channel; ByteEncoder byteEncoder = new BigIntegerByteEncoder(); @@ -122,7 +123,7 @@ public class DKGTest { id = ids.remove(random.nextInt(ids.size())); channel = new ChannelImpl(id,n); 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(t, n, s, random, q, g, group, id,byteEncoder); dkgs[id - 1] = randomDKGUser(id,channel,dkg,random); threads[id - 1] = new Thread(dkgs[id - 1]); if(QUAL.contains(id)){ @@ -132,18 +133,18 @@ public class DKGTest { } - public DistributedKeyGenerationUser randomDKGUser(int id, Channel channel, DistributedKeyGeneration dkg, Random random){ + public User randomDKGUser(int id, Channel channel, Protocol dkg, Random random){ if (QUAL.size() <= t) { valids.add(id); QUAL.add(id); - return new DistributedKeyGenerationUser(dkg,channel); + return new User(dkg,channel); }else{ int type = random.nextInt(3); switch (type){ case 0:// regular valids.add(id); QUAL.add(id); - return new DistributedKeyGenerationUser(dkg,channel); + return new User(dkg,channel); case 1:// abort int abortStage = random.nextInt(2) + 1; // 1 or 2 aborted.add(id); @@ -154,7 +155,7 @@ public class DKGTest { case 2:// malicious malicious.add(id); Set falls = DKGMaliciousUser.selectFallsRandomly(valids,random); - DistributedKeyGeneration maliciousDKG = DKGMaliciousUser.generateMaliciousDKG(dkg,channel,random); + Protocol maliciousDKG = DKGMaliciousUser.generateMaliciousDKG(dkg,channel,random); return new DKGMaliciousUser(dkg,maliciousDKG,channel,falls); default: return null; diff --git a/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/DKGUserImplAbort.java b/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/DKGUserImplAbort.java index 88a0847..2e42299 100644 --- a/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/DKGUserImplAbort.java +++ b/destributed-key-generation/src/test/java/meerkat/crypto/concrete/distributed_key_generation/joint_feldman_protocol/DKGUserImplAbort.java @@ -6,11 +6,11 @@ import meerkat.protobuf.DKGMessages; /** * Created by Tzlil on 3/14/2016. */ -public class DKGUserImplAbort extends DistributedKeyGenerationUser { +public class DKGUserImplAbort extends User { final int abortStage; int stage; - public DKGUserImplAbort(DistributedKeyGeneration dkg, Channel channel, int abortStage) { + public DKGUserImplAbort(Protocol dkg, Channel channel, int abortStage) { super(dkg, channel); this.abortStage = abortStage;// 1 - 2 this.stage = 1; diff --git a/destributed-key-generation/src/test/java/meerkat/crypto/concrete/secret_shring/feldman_verifiable/VerifiableSecretSharingTest.java b/destributed-key-generation/src/test/java/meerkat/crypto/concrete/secret_shring/feldman_verifiable/VerifiableSecretSharingTest.java index f7d3a39..f106584 100644 --- a/destributed-key-generation/src/test/java/meerkat/crypto/concrete/secret_shring/feldman_verifiable/VerifiableSecretSharingTest.java +++ b/destributed-key-generation/src/test/java/meerkat/crypto/concrete/secret_shring/feldman_verifiable/VerifiableSecretSharingTest.java @@ -1,6 +1,6 @@ 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.concrete.Zpstar; import org.junit.Before; diff --git a/destributed-key-generation/src/test/java/meerkat/crypto/concrete/secret_shring/shamir/PolynomialTests/AddTest.java b/destributed-key-generation/src/test/java/meerkat/crypto/concrete/secret_shring/shamir/PolynomialTests/AddTest.java index 2c78b03..326b0bf 100644 --- a/destributed-key-generation/src/test/java/meerkat/crypto/concrete/secret_shring/shamir/PolynomialTests/AddTest.java +++ b/destributed-key-generation/src/test/java/meerkat/crypto/concrete/secret_shring/shamir/PolynomialTests/AddTest.java @@ -1,6 +1,6 @@ package meerkat.crypto.concrete.secret_shring.shamir.PolynomialTests; -import Arithmetics.Z; import Utils.GenerateRandomPolynomial; +import Utils.Z; import meerkat.crypto.concrete.secret_shring.shamir.Polynomial; import org.junit.Before; import org.junit.Test; diff --git a/destributed-key-generation/src/test/java/meerkat/crypto/concrete/secret_shring/shamir/PolynomialTests/MulByConstTest.java b/destributed-key-generation/src/test/java/meerkat/crypto/concrete/secret_shring/shamir/PolynomialTests/MulByConstTest.java index 30e2082..36c42ad 100644 --- a/destributed-key-generation/src/test/java/meerkat/crypto/concrete/secret_shring/shamir/PolynomialTests/MulByConstTest.java +++ b/destributed-key-generation/src/test/java/meerkat/crypto/concrete/secret_shring/shamir/PolynomialTests/MulByConstTest.java @@ -1,7 +1,7 @@ package meerkat.crypto.concrete.secret_shring.shamir.PolynomialTests; -import Arithmetics.Z; import Utils.GenerateRandomPolynomial; +import Utils.Z; import meerkat.crypto.concrete.secret_shring.shamir.Polynomial; import org.junit.Before; import org.junit.Test; diff --git a/destributed-key-generation/src/test/java/meerkat/crypto/concrete/secret_shring/shamir/PolynomialTests/MulTest.java b/destributed-key-generation/src/test/java/meerkat/crypto/concrete/secret_shring/shamir/PolynomialTests/MulTest.java index 8af27ab..1a83f50 100644 --- a/destributed-key-generation/src/test/java/meerkat/crypto/concrete/secret_shring/shamir/PolynomialTests/MulTest.java +++ b/destributed-key-generation/src/test/java/meerkat/crypto/concrete/secret_shring/shamir/PolynomialTests/MulTest.java @@ -1,7 +1,7 @@ package meerkat.crypto.concrete.secret_shring.shamir.PolynomialTests; -import Arithmetics.Z; import Utils.GenerateRandomPolynomial; +import Utils.Z; import meerkat.crypto.concrete.secret_shring.shamir.Polynomial; import org.junit.Before; import org.junit.Test; diff --git a/meerkat-common/src/main/proto/meerkat/DKGMessages.proto b/meerkat-common/src/main/proto/meerkat/DKGMessages.proto index 81072e9..046f586 100644 --- a/meerkat-common/src/main/proto/meerkat/DKGMessages.proto +++ b/meerkat-common/src/main/proto/meerkat/DKGMessages.proto @@ -6,7 +6,7 @@ option java_package = "meerkat.protobuf"; message Mail{ enum Type { - SECRET = 0; + SHARE = 0; COMMITMENT = 1; COMPLAINT = 2; DONE = 3; @@ -23,17 +23,17 @@ message Mail{ bytes message = 5; } -message SecretMessage { +message ShareMessage { int32 i = 1; int32 j = 2; - bytes secret = 3; + bytes share = 3; } -message DoubleSecretMessage{ +message DoubleShareMessage{ int32 i = 1; int32 j = 2; - bytes secret = 3; - bytes secretT = 4; + bytes share = 3; + bytes shareT = 4; } message CommitmentMessage{