More renaming and refactoring of DKG code
parent
78207532ec
commit
c798e827dc
|
@ -1,8 +1,11 @@
|
|||
package meerkat.crypto.dkg.comm;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.google.protobuf.Message;
|
||||
import meerkat.crypto.utils.Channel;
|
||||
import meerkat.protobuf.DKGMessages;
|
||||
import meerkat.protobuf.DKG;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Created by Tzlil on 2/14/2016.
|
||||
|
@ -10,6 +13,7 @@ import meerkat.protobuf.DKGMessages;
|
|||
* an implementation of ReceiverCallback
|
||||
*/
|
||||
public abstract class MailHandler implements Channel.ReceiverCallback{
|
||||
final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
/**
|
||||
* fixed value for broadcasting
|
||||
|
@ -30,50 +34,20 @@ public abstract class MailHandler implements Channel.ReceiverCallback{
|
|||
}
|
||||
|
||||
/**
|
||||
* extract message from mail
|
||||
* @param mail
|
||||
* @return
|
||||
* Was this broadcastMessage was received by broadcast channel
|
||||
* @param broadcastMessage
|
||||
* @return broadcastMessage user destination == BROADCAST
|
||||
*/
|
||||
public abstract Message extractMessage(DKGMessages.Mail mail);
|
||||
|
||||
/**
|
||||
* is this mail was received by broadcast channel
|
||||
* @param mail
|
||||
* @return mail user destination == BROADCAST
|
||||
*/
|
||||
public boolean isBroadcast(DKGMessages.Mail mail){
|
||||
return mail.getDestination() == BROADCAST;
|
||||
public boolean isBroadcast(DKG.BroadcastMessage broadcastMessage){
|
||||
return broadcastMessage.getDestination() == BROADCAST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveMail(DKGMessages.Mail mail){
|
||||
Message message = extractMessage(mail);
|
||||
if (message == null)
|
||||
return;
|
||||
|
||||
switch (mail.getType()) {
|
||||
case SHARE:
|
||||
messageHandler.handleShareMessage(mail.getSender(), isBroadcast(mail),message);
|
||||
break;
|
||||
case COMMITMENT:
|
||||
messageHandler.handleCommitmentMessage(mail.getSender(), isBroadcast(mail),message);
|
||||
break;
|
||||
case DONE:
|
||||
messageHandler.handleDoneMessage(mail.getSender(), isBroadcast(mail),message);
|
||||
break;
|
||||
case COMPLAINT:
|
||||
messageHandler.handleComplaintMessage(mail.getSender(), isBroadcast(mail),message);
|
||||
break;
|
||||
case ANSWER:
|
||||
messageHandler.handleAnswerMessage(mail.getSender(), isBroadcast(mail),message);
|
||||
break;
|
||||
case ABORT:
|
||||
messageHandler.handleAbortMessage(mail.getSender(), isBroadcast(mail),message);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
public void receiveMail(DKG.BroadcastMessage envelope) {
|
||||
try {
|
||||
messageHandler.handleMessage(envelope);
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
logger.warn("Received invalid protocol buffer from channel", e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,39 +1,50 @@
|
|||
package meerkat.crypto.dkg.comm;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.google.protobuf.Message;
|
||||
import meerkat.protobuf.DKG;
|
||||
|
||||
/**
|
||||
* Created by Tzlil on 2/14/2016.
|
||||
* an interface for handling received messages
|
||||
*/
|
||||
public interface MessageHandler {
|
||||
/**
|
||||
* handle share message
|
||||
*/
|
||||
void handleShareMessage(int sender, boolean isBroadcast, Message message);
|
||||
|
||||
/**
|
||||
* handle commitment message
|
||||
* Handle a broadcast (or unicast) message.
|
||||
* If the message is invalid, the handler can throw an {@link InvalidProtocolBufferException}, in which
|
||||
* case the message will simply be ignored.
|
||||
* @param envelope
|
||||
*/
|
||||
void handleCommitmentMessage(int sender, boolean isBroadcast, Message message);
|
||||
|
||||
/**
|
||||
* handle complaint message
|
||||
*/
|
||||
void handleComplaintMessage(int sender, boolean isBroadcast, Message message);
|
||||
|
||||
/**
|
||||
* handle done message
|
||||
*/
|
||||
void handleDoneMessage(int sender, boolean isBroadcast, Message message);
|
||||
|
||||
/**
|
||||
* handle answer message
|
||||
*/
|
||||
void handleAnswerMessage(int sender, boolean isBroadcast, Message message);
|
||||
|
||||
/**
|
||||
* handle abort message
|
||||
*/
|
||||
void handleAbortMessage(int sender, boolean isBroadcast, Message message);
|
||||
void handleMessage(DKG.BroadcastMessage envelope) throws InvalidProtocolBufferException;
|
||||
//
|
||||
// /**
|
||||
// * handle share message
|
||||
// */
|
||||
// void handleShareMessage(int sender, boolean isBroadcast, Message message);
|
||||
//
|
||||
// /**
|
||||
// * handle commitment message
|
||||
// */
|
||||
// void handleCommitmentMessage(int sender, boolean isBroadcast, Message message);
|
||||
//
|
||||
// /**
|
||||
// * handle complaint message
|
||||
// */
|
||||
// void handleComplaintMessage(int sender, boolean isBroadcast, Message message);
|
||||
//
|
||||
// /**
|
||||
// * handle done message
|
||||
// */
|
||||
// void handleDoneMessage(int sender, boolean isBroadcast, Message message);
|
||||
//
|
||||
// /**
|
||||
// * handle answer message
|
||||
// */
|
||||
// void handleAnswerMessage(int sender, boolean isBroadcast, Message message);
|
||||
//
|
||||
// /**
|
||||
// * handle abort message
|
||||
// */
|
||||
// void handleAbortMessage(int sender, boolean isBroadcast, Message message);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package meerkat.crypto.dkg.comm;
|
||||
|
||||
import meerkat.protobuf.DKG;
|
||||
|
||||
/**
|
||||
* Created by talm on 12/04/16.
|
||||
*/
|
||||
public class MessageUtils {
|
||||
public static DKG.Payload createMessage(DKG.Payload.Type type) {
|
||||
return DKG.Payload.newBuilder().setType(type).build();
|
||||
}
|
||||
|
||||
public static DKG.Payload createMessage(DKG.Payload.Type type, DKG.ShareMessage share) {
|
||||
return DKG.Payload.newBuilder().setType(type).setShare(share).build();
|
||||
}
|
||||
|
||||
public static DKG.Payload createMessage(DKG.Payload.Type type, DKG.ShareMessage.Builder share) {
|
||||
return DKG.Payload.newBuilder().setType(type).setShare(share).build();
|
||||
}
|
||||
|
||||
public static DKG.Payload createMessage(DKG.Payload.Type type, DKG.IDMessage id) {
|
||||
return DKG.Payload.newBuilder().setType(type).setId(id).build();
|
||||
}
|
||||
|
||||
public static DKG.Payload createMessage(DKG.Payload.Type type, DKG.IDMessage.Builder id) {
|
||||
return DKG.Payload.newBuilder().setType(type).setId(id).build();
|
||||
}
|
||||
|
||||
public static DKG.Payload createMessage(DKG.Payload.Type type, DKG.CommitmentMessage commitment) {
|
||||
return DKG.Payload.newBuilder().setType(type).setCommitment(commitment).build();
|
||||
}
|
||||
|
||||
public static DKG.Payload createMessage(DKG.Payload.Type type, DKG.CommitmentMessage.Builder commitment) {
|
||||
return DKG.Payload.newBuilder().setType(type).setCommitment(commitment).build();
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ package meerkat.crypto.dkg.feldman;
|
|||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.google.protobuf.Message;
|
||||
import meerkat.crypto.dkg.comm.MessageHandler;
|
||||
import meerkat.protobuf.DKGMessages;
|
||||
import meerkat.protobuf.DKG;
|
||||
|
||||
/**
|
||||
* Created by Tzlil on 2/29/2016.
|
||||
|
@ -18,36 +18,4 @@ public class MailHandler extends meerkat.crypto.dkg.comm.MailHandler {
|
|||
public MailHandler(MessageHandler messageHandler) {
|
||||
super(messageHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message extractMessage(DKGMessages.Mail mail) {
|
||||
try {
|
||||
Message message;
|
||||
switch (mail.getType()) {
|
||||
case SHARE:
|
||||
message = DKGMessages.ShareMessage.parseFrom(mail.getMessage());
|
||||
break;
|
||||
case COMMITMENT:
|
||||
message = DKGMessages.CommitmentMessage.parseFrom(mail.getMessage());
|
||||
break;
|
||||
case COMPLAINT:
|
||||
message = DKGMessages.IDMessage.parseFrom(mail.getMessage());
|
||||
break;
|
||||
case DONE:
|
||||
message = DKGMessages.EmptyMessage.parseFrom(mail.getMessage());
|
||||
break;
|
||||
case ANSWER:
|
||||
message = DKGMessages.ShareMessage.parseFrom(mail.getMessage());
|
||||
break;
|
||||
case ABORT:
|
||||
message = DKGMessages.EmptyMessage.parseFrom(mail.getMessage());
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return message;
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,13 +4,15 @@ import meerkat.crypto.utils.Channel;
|
|||
import meerkat.crypto.secretsharing.feldman.VerifiableSecretSharing;
|
||||
import meerkat.crypto.secretsharing.shamir.Polynomial;
|
||||
import com.google.protobuf.ByteString;
|
||||
import meerkat.protobuf.DKGMessages;
|
||||
import meerkat.protobuf.DKG;
|
||||
import org.factcenter.qilin.primitives.Group;
|
||||
import org.factcenter.qilin.util.ByteEncoder;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.*;
|
||||
|
||||
import static meerkat.crypto.dkg.comm.MessageUtils.*;
|
||||
|
||||
/**
|
||||
* Created by Tzlil on 3/14/2016.
|
||||
*
|
||||
|
@ -126,13 +128,13 @@ public class Protocol<T> extends VerifiableSecretSharing<T> {
|
|||
* @param commitments
|
||||
*/
|
||||
public void broadcastCommitments(ArrayList<T> commitments){
|
||||
DKGMessages.CommitmentMessage commitmentMessage;
|
||||
DKG.CommitmentMessage commitmentMessage;
|
||||
for (int k = 0; k <= t ; k++){
|
||||
commitmentMessage = DKGMessages.CommitmentMessage.newBuilder()
|
||||
commitmentMessage = DKG.CommitmentMessage.newBuilder()
|
||||
.setCommitment(ByteString.copyFrom(encoder.encode(commitments.get(k))))
|
||||
.setK(k)
|
||||
.build();
|
||||
channel.broadcastMessage(DKGMessages.Mail.Type.COMMITMENT, commitmentMessage);
|
||||
channel.broadcastMessage(createMessage(DKG.Payload.Type.COMMITMENT, commitmentMessage));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,12 +144,12 @@ public class Protocol<T> extends VerifiableSecretSharing<T> {
|
|||
*/
|
||||
public void sendSecret(int j){
|
||||
ByteString secret = ByteString.copyFrom(getShare(j).y.toByteArray());
|
||||
channel.sendMessage(j, DKGMessages.Mail.Type.SHARE,
|
||||
DKGMessages.ShareMessage.newBuilder()
|
||||
channel.sendMessage(j, createMessage(DKG.Payload.Type.SHARE,
|
||||
DKG.ShareMessage.newBuilder()
|
||||
.setI(id)
|
||||
.setJ(j)
|
||||
.setShare(secret)
|
||||
.build());
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -207,10 +209,10 @@ public class Protocol<T> extends VerifiableSecretSharing<T> {
|
|||
*/
|
||||
private void broadcastComplaint(int i){
|
||||
//message = new Message(Type.Complaint, j)
|
||||
DKGMessages.IDMessage complaint = DKGMessages.IDMessage.newBuilder()
|
||||
DKG.IDMessage complaint = DKG.IDMessage.newBuilder()
|
||||
.setId(i)
|
||||
.build();
|
||||
channel.broadcastMessage(DKGMessages.Mail.Type.COMPLAINT, complaint);
|
||||
channel.broadcastMessage(createMessage(DKG.Payload.Type.COMPLAINT, complaint));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -218,11 +220,10 @@ public class Protocol<T> extends VerifiableSecretSharing<T> {
|
|||
* @param j
|
||||
*/
|
||||
public void broadcastComplaintAnswer(int j){
|
||||
channel.broadcastMessage(DKGMessages.Mail.Type.ANSWER, DKGMessages.ShareMessage.newBuilder()
|
||||
channel.broadcastMessage(createMessage(DKG.Payload.Type.ANSWER, DKG.ShareMessage.newBuilder()
|
||||
.setI(id)
|
||||
.setJ(j)
|
||||
.setShare(ByteString.copyFrom(getShare(j).y.toByteArray()))
|
||||
.build());
|
||||
.setShare(ByteString.copyFrom(getShare(j).y.toByteArray()))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
package meerkat.crypto.dkg.feldman;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import meerkat.crypto.utils.Channel;
|
||||
import meerkat.crypto.secretsharing.shamir.Polynomial;
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.Message;
|
||||
import meerkat.protobuf.DKGMessages;
|
||||
import meerkat.protobuf.DKG;
|
||||
import org.factcenter.qilin.primitives.Group;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
import static meerkat.crypto.dkg.comm.MessageUtils.createMessage;
|
||||
|
||||
/**
|
||||
* Created by Tzlil on 3/14/2016.
|
||||
*
|
||||
|
@ -176,11 +179,10 @@ public class User<T> implements Runnable{
|
|||
* if check fails for an index i, Pj broadcasts a complaint against Pi.
|
||||
* Pj broadcasts done message at the end of this stage
|
||||
*/
|
||||
protected void stage2(){
|
||||
protected void stage2() {
|
||||
dkg.broadcastComplaints();
|
||||
//broadcast done message after all complaints
|
||||
DKGMessages.EmptyMessage doneMessage = DKGMessages.EmptyMessage.newBuilder().build();
|
||||
channel.broadcastMessage(DKGMessages.Mail.Type.DONE,doneMessage);
|
||||
channel.broadcastMessage(createMessage(DKG.Payload.Type.DONE));
|
||||
}
|
||||
|
||||
|
||||
|
@ -360,35 +362,19 @@ public class User<T> implements Runnable{
|
|||
/**
|
||||
* an implementation of MessageHandler
|
||||
*/
|
||||
public class MessageHandler implements meerkat.crypto.dkg.comm.MessageHandler{
|
||||
public class MessageHandler implements meerkat.crypto.dkg.comm.MessageHandler {
|
||||
|
||||
/**
|
||||
* commitment message is valid if:
|
||||
* 1. it was received in broadcast chanel
|
||||
* 2. the sender didn't sent this commitment before
|
||||
*/
|
||||
protected boolean isValidCommitmentMessage(int sender, boolean isBroadcast, DKGMessages.CommitmentMessage commitmentMessage){
|
||||
protected boolean isValidCommitmentMessage(int sender, boolean isBroadcast, DKG.CommitmentMessage commitmentMessage){
|
||||
int i = sender - 1;
|
||||
int k = commitmentMessage.getK();
|
||||
return isBroadcast && parties[i].commitments.get(k) == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* saves the commitment
|
||||
*/
|
||||
@Override
|
||||
public void handleCommitmentMessage(int sender, boolean isBroadcast, Message message) {
|
||||
DKGMessages.CommitmentMessage commitmentMessage = (DKGMessages.CommitmentMessage) message;
|
||||
if(isValidCommitmentMessage(sender,isBroadcast,commitmentMessage)){
|
||||
int i = sender - 1;
|
||||
int k = commitmentMessage.getK();
|
||||
synchronized (parties[i]) {
|
||||
parties[i].commitments.set(k, extractCommitment(commitmentMessage));
|
||||
parties[i].notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* secret message is valid if:
|
||||
* 1. it was received in private chanel
|
||||
|
@ -396,7 +382,7 @@ public class User<T> implements Runnable{
|
|||
* 3. secret.i == i
|
||||
* 4. secret.j == id
|
||||
*/
|
||||
protected boolean isValidSecretMessage(int sender, boolean isBroadcast, DKGMessages.ShareMessage secretMessage){
|
||||
protected boolean isValidSecretMessage(int sender, boolean isBroadcast, DKG.ShareMessage secretMessage){
|
||||
int i = secretMessage.getI();
|
||||
int j = secretMessage.getJ();
|
||||
if(sender != i || isBroadcast)
|
||||
|
@ -406,22 +392,6 @@ public class User<T> implements Runnable{
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* saves the secret
|
||||
*/
|
||||
@Override
|
||||
public void handleShareMessage(int sender, boolean isBroadcast, Message message) {
|
||||
DKGMessages.ShareMessage secretMessage = (DKGMessages.ShareMessage) message;
|
||||
if(isValidSecretMessage(sender,isBroadcast,secretMessage)) {
|
||||
int i = secretMessage.getI();
|
||||
Polynomial.Point secret = extractShare(id,secretMessage.getShare());
|
||||
synchronized (parties[i -1]) {
|
||||
parties[i - 1].share = secret;
|
||||
parties[i - 1].notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* done message is valid if:
|
||||
* 1. it was received in broadcast chanel
|
||||
|
@ -431,46 +401,18 @@ public class User<T> implements Runnable{
|
|||
return isBroadcast && !parties[sender - 1].doneFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
* marks that the sender was finished sending all his complaints
|
||||
*/
|
||||
@Override
|
||||
public void handleDoneMessage(int sender, boolean isBroadcast, Message message) {
|
||||
if(isValidDoneMessage(sender,isBroadcast)) {
|
||||
synchronized (parties[sender - 1]) {
|
||||
parties[sender - 1].doneFlag = true;
|
||||
parties[sender - 1].notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* complaint message is valid if:
|
||||
* 1. it was received in broadcast chanel
|
||||
* 2. the sender didn't complained against id before
|
||||
*/
|
||||
protected boolean isValidComplaintMessage(int sender, boolean isBroadcast, DKGMessages.IDMessage complaintMessage){
|
||||
protected boolean isValidComplaintMessage(int sender, boolean isBroadcast, DKG.IDMessage complaintMessage){
|
||||
int i = sender;
|
||||
int j = complaintMessage.getId();
|
||||
return isBroadcast && parties[i - 1].complaints[j - 1].equals( Protocol.ComplaintState.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* marks that the sender was complained against id
|
||||
*/
|
||||
@Override
|
||||
public void handleComplaintMessage(int sender, boolean isBroadcast, Message message) {
|
||||
DKGMessages.IDMessage complaintMessage = (DKGMessages.IDMessage)message;
|
||||
if(isValidComplaintMessage(sender,isBroadcast,complaintMessage)){
|
||||
int i = sender;
|
||||
int j = complaintMessage.getId();
|
||||
synchronized (parties[j - 1]) {
|
||||
parties[j - 1].complaints[i - 1] = Protocol.ComplaintState.Waiting;
|
||||
parties[j - 1].notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* answer message is valid if:
|
||||
* 1. it was received in broadcast chanel
|
||||
|
@ -478,7 +420,7 @@ public class User<T> implements Runnable{
|
|||
* 3. 1 <= secret.j <= n
|
||||
* 4. it is marked that j complained against i and i didn't received
|
||||
*/
|
||||
protected boolean isValidAnswerMessage(int sender, boolean isBroadcast, DKGMessages.ShareMessage secretMessage){
|
||||
protected boolean isValidAnswerMessage(int sender, boolean isBroadcast, DKG.ShareMessage secretMessage){
|
||||
int i = secretMessage.getI();
|
||||
int j = secretMessage.getJ();
|
||||
if(sender != i || !isBroadcast)
|
||||
|
@ -487,40 +429,108 @@ public class User<T> implements Runnable{
|
|||
return j >= 1 && j <= n && parties[i - 1].complaints[j - 1].equals(Protocol.ComplaintState.Waiting);
|
||||
}
|
||||
|
||||
/**
|
||||
* if the secret is valid, marks the complaint as NonDisqualified
|
||||
* else marks it as Disqualified
|
||||
* in case that the complainer is id ( j == id ), saves the secret
|
||||
*/
|
||||
@Override
|
||||
public void handleAnswerMessage(int sender, boolean isBroadcast, Message message) {
|
||||
DKGMessages.ShareMessage secretMessage = (DKGMessages.ShareMessage) message;
|
||||
if(isValidAnswerMessage(sender,isBroadcast,secretMessage)) {
|
||||
int i = secretMessage.getI();
|
||||
int j = secretMessage.getJ();
|
||||
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] = Protocol.ComplaintState.NonDisqualified;
|
||||
} else {
|
||||
parties[i - 1].complaints[j - 1] = Protocol.ComplaintState.Disqualified;
|
||||
}
|
||||
if (j == id) {
|
||||
parties[i - 1].share = secret;
|
||||
}
|
||||
parties[i - 1].notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* marks that the sender was aborted
|
||||
*/
|
||||
@Override
|
||||
public void handleAbortMessage(int sender, boolean isBroadcast, Message message) {
|
||||
synchronized (parties[sender - 1]) {
|
||||
parties[sender - 1].aborted = true;
|
||||
parties[sender - 1].notify();
|
||||
public void handleMessage(DKG.BroadcastMessage envelope) throws InvalidProtocolBufferException {
|
||||
int sender = envelope.getSender();
|
||||
boolean isBroadcast = !envelope.getIsPrivate();
|
||||
DKG.Payload msg = DKG.Payload.parseFrom(envelope.getPayload());
|
||||
|
||||
switch (msg.getType()) {
|
||||
case COMMITMENT:
|
||||
/**
|
||||
* saves the commitment
|
||||
*/
|
||||
DKG.CommitmentMessage commitmentMessage = msg.getCommitment();
|
||||
if (isValidCommitmentMessage(sender, isBroadcast, commitmentMessage)) {
|
||||
int i = sender - 1;
|
||||
int k = commitmentMessage.getK();
|
||||
synchronized (parties[i]) {
|
||||
parties[i].commitments.set(k, extractCommitment(commitmentMessage));
|
||||
parties[i].notify();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case SHARE:
|
||||
/**
|
||||
* saves the secret
|
||||
*/
|
||||
DKG.ShareMessage secretMessage = msg.getShare();
|
||||
if(isValidSecretMessage(sender,isBroadcast,secretMessage)) {
|
||||
int i = secretMessage.getI();
|
||||
Polynomial.Point secret = extractShare(id,secretMessage.getShare());
|
||||
synchronized (parties[i -1]) {
|
||||
parties[i - 1].share = secret;
|
||||
parties[i - 1].notify();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case DONE:
|
||||
|
||||
/**
|
||||
* marks that the sender was finished sending all his complaints
|
||||
*/
|
||||
if(isValidDoneMessage(sender,isBroadcast)) {
|
||||
synchronized (parties[sender - 1]) {
|
||||
parties[sender - 1].doneFlag = true;
|
||||
parties[sender - 1].notify();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case COMPLAINT:
|
||||
/**
|
||||
* marks that the sender was complained against id
|
||||
*/
|
||||
DKG.IDMessage complaintMessage = msg.getId();
|
||||
if(isValidComplaintMessage(sender,isBroadcast,complaintMessage)){
|
||||
int i = sender;
|
||||
int j = complaintMessage.getId();
|
||||
synchronized (parties[j - 1]) {
|
||||
parties[j - 1].complaints[i - 1] = Protocol.ComplaintState.Waiting;
|
||||
parties[j - 1].notify();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ANSWER:
|
||||
/**
|
||||
* if the secret is valid, marks the complaint as NonDisqualified
|
||||
* else marks it as Disqualified
|
||||
* in case that the complainer is id ( j == id ), saves the secret
|
||||
*/
|
||||
secretMessage = msg.getShare();
|
||||
if(isValidAnswerMessage(sender,isBroadcast,secretMessage)) {
|
||||
int i = secretMessage.getI();
|
||||
int j = secretMessage.getJ();
|
||||
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] = Protocol.ComplaintState.NonDisqualified;
|
||||
} else {
|
||||
parties[i - 1].complaints[j - 1] = Protocol.ComplaintState.Disqualified;
|
||||
}
|
||||
if (j == id) {
|
||||
parties[i - 1].share = secret;
|
||||
}
|
||||
parties[i - 1].notify();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ABORT:
|
||||
/**
|
||||
* marks that the sender was aborted
|
||||
*/
|
||||
synchronized (parties[sender - 1]) {
|
||||
parties[sender - 1].aborted = true;
|
||||
parties[sender - 1].notify();
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -541,7 +551,7 @@ public class User<T> implements Runnable{
|
|||
* @param commitmentMessage
|
||||
* @return
|
||||
*/
|
||||
public T extractCommitment(DKGMessages.CommitmentMessage commitmentMessage){
|
||||
public T extractCommitment(DKG.CommitmentMessage commitmentMessage){
|
||||
return dkg.decodeCommitment(commitmentMessage.getCommitment().toByteArray());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package meerkat.crypto.dkg.gjkr;
|
|||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.google.protobuf.Message;
|
||||
import meerkat.crypto.dkg.comm.MessageHandler;
|
||||
import meerkat.protobuf.DKGMessages;
|
||||
import meerkat.protobuf.DKG;
|
||||
|
||||
/**
|
||||
* Created by Tzlil on 2/29/2016.
|
||||
|
@ -26,41 +26,6 @@ public class MailHandler extends meerkat.crypto.dkg.comm.MailHandler {
|
|||
this.isStage4 = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message extractMessage(DKGMessages.Mail mail) {
|
||||
try {
|
||||
Message message;
|
||||
switch (mail.getType()) {
|
||||
case SHARE:
|
||||
message = DKGMessages.DoubleShareMessage.parseFrom(mail.getMessage());
|
||||
break;
|
||||
case COMMITMENT:
|
||||
message = DKGMessages.CommitmentMessage.parseFrom(mail.getMessage());
|
||||
break;
|
||||
case COMPLAINT:
|
||||
if(!isStage4)
|
||||
message = DKGMessages.IDMessage.parseFrom(mail.getMessage());
|
||||
else
|
||||
message = DKGMessages.DoubleShareMessage.parseFrom(mail.getMessage());
|
||||
break;
|
||||
case DONE:
|
||||
message = DKGMessages.EmptyMessage.parseFrom(mail.getMessage());
|
||||
break;
|
||||
case ANSWER:
|
||||
message = DKGMessages.DoubleShareMessage.parseFrom(mail.getMessage());
|
||||
break;
|
||||
case ABORT:
|
||||
message = DKGMessages.EmptyMessage.parseFrom(mail.getMessage());
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return message;
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* setter
|
||||
* @param stage4
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
package meerkat.crypto.dkg.gjkr;
|
||||
|
||||
import meerkat.crypto.dkg.comm.MessageUtils;
|
||||
import meerkat.crypto.secretsharing.feldman.VerifiableSecretSharing;
|
||||
import meerkat.crypto.secretsharing.shamir.Polynomial;
|
||||
import com.google.protobuf.ByteString;
|
||||
import meerkat.protobuf.DKGMessages;
|
||||
import meerkat.protobuf.DKG;
|
||||
import org.factcenter.qilin.primitives.Group;
|
||||
import org.factcenter.qilin.util.ByteEncoder;
|
||||
|
||||
|
@ -52,9 +53,9 @@ public class Protocol<T> extends meerkat.crypto.dkg.feldman.Protocol<T> {
|
|||
public void sendSecret(int j) {
|
||||
Polynomial.Point secret = getShare(j);
|
||||
Polynomial.Point secretT = maskingShares.getShare(j);
|
||||
DKGMessages.DoubleShareMessage doubleSecretMessage = doubleShareMessage(id,j,secret,secretT);
|
||||
DKG.ShareMessage doubleSecretMessage = createShareMessage(id,j,secret,secretT);
|
||||
// TODO: Change SHARE to SHARE
|
||||
channel.sendMessage(j, DKGMessages.Mail.Type.SHARE, doubleSecretMessage);
|
||||
channel.sendMessage(j, MessageUtils.createMessage(DKG.Payload.Type.SHARE, doubleSecretMessage));
|
||||
}
|
||||
|
||||
|
||||
|
@ -90,8 +91,8 @@ public class Protocol<T> extends meerkat.crypto.dkg.feldman.Protocol<T> {
|
|||
* @param i
|
||||
*/
|
||||
private void broadcastComplaint(Polynomial.Point share, Polynomial.Point shareT, int i){
|
||||
DKGMessages.DoubleShareMessage complaint = doubleShareMessage(i,id,share,shareT);
|
||||
channel.broadcastMessage(DKGMessages.Mail.Type.COMPLAINT,complaint);
|
||||
DKG.ShareMessage complaint = createShareMessage(i,id,share,shareT);
|
||||
channel.broadcastMessage(MessageUtils.createMessage(DKG.Payload.Type.COMPLAINT, complaint));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -124,7 +125,7 @@ public class Protocol<T> extends meerkat.crypto.dkg.feldman.Protocol<T> {
|
|||
}
|
||||
|
||||
/**
|
||||
* pack share, shareT i,j to doubleShareMessage
|
||||
* pack share, shareT i,j to createShareMessage
|
||||
* @param i
|
||||
* @param j
|
||||
* @param share
|
||||
|
@ -132,26 +133,26 @@ public class Protocol<T> extends meerkat.crypto.dkg.feldman.Protocol<T> {
|
|||
* @return
|
||||
*/
|
||||
|
||||
private DKGMessages.DoubleShareMessage doubleShareMessage(int i, int j, Polynomial.Point share, Polynomial.Point shareT){
|
||||
DKGMessages.DoubleShareMessage doubleShareMessage = DKGMessages.DoubleShareMessage.newBuilder()
|
||||
private DKG.ShareMessage createShareMessage(int i, int j, Polynomial.Point share, Polynomial.Point shareT){
|
||||
DKG.ShareMessage ShareMessage = DKG.ShareMessage.newBuilder()
|
||||
.setI(i)
|
||||
.setJ(j)
|
||||
.setShare(ByteString.copyFrom(share.y.toByteArray()))
|
||||
.setShareT(ByteString.copyFrom(shareT.y.toByteArray()))
|
||||
.build();
|
||||
return doubleShareMessage;
|
||||
return ShareMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcastComplaintAnswer(int j) {
|
||||
DKGMessages.DoubleShareMessage answer = doubleShareMessage(id,j,getShare(j)
|
||||
DKG.ShareMessage answer = createShareMessage(id,j,getShare(j)
|
||||
, maskingShares.getShare(j));
|
||||
channel.broadcastMessage(DKGMessages.Mail.Type.ANSWER,answer);
|
||||
channel.broadcastMessage(MessageUtils.createMessage(DKG.Payload.Type.ANSWER, answer));
|
||||
}
|
||||
|
||||
public void broadcastAnswer(Polynomial.Point secret, Polynomial.Point secretT, int i){
|
||||
DKGMessages.DoubleShareMessage complaint = doubleShareMessage(i,id,secret,secretT);
|
||||
channel.broadcastMessage(DKGMessages.Mail.Type.ANSWER,complaint);
|
||||
DKG.ShareMessage complaint = createShareMessage(i,id,secret,secretT);
|
||||
channel.broadcastMessage(MessageUtils.createMessage(DKG.Payload.Type.ANSWER,complaint));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,25 +1,28 @@
|
|||
package meerkat.crypto.dkg.gjkr;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import meerkat.crypto.utils.Arithmetic;
|
||||
import meerkat.crypto.utils.concrete.Fp;
|
||||
import meerkat.crypto.utils.Channel;
|
||||
import meerkat.crypto.secretsharing.shamir.Polynomial;
|
||||
import meerkat.crypto.secretsharing.shamir.SecretSharing;
|
||||
import com.google.protobuf.Message;
|
||||
import meerkat.protobuf.DKGMessages;
|
||||
import meerkat.protobuf.DKG;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static meerkat.crypto.dkg.comm.MessageUtils.*;
|
||||
|
||||
/**
|
||||
* Created by Tzlil on 3/16/2016.
|
||||
*
|
||||
* <p/>
|
||||
* implementation of gjkr protocol user.
|
||||
*
|
||||
* this protocol extends joint feldman protocol by splitting the protocol to commitment stage (stages 1,2,3)
|
||||
* and reviling stage (stage 4).
|
||||
*
|
||||
* as in joint feldman, each party in QUAL has his own share of the generated random key.
|
||||
* <p/>
|
||||
* this protocol extends joint Feldman protocol by splitting the protocol to commitment stage (stages 1,2,3)
|
||||
* and revealing stage (stage 4).
|
||||
* <p/>
|
||||
* as in joint Feldman, each party in QUAL has his own share of the generated random key.
|
||||
* this key can be recover by any subset of QUAL of size at least t + 1.
|
||||
*/
|
||||
public class User<T> extends meerkat.crypto.dkg.feldman.User<T> {
|
||||
|
@ -42,7 +45,8 @@ public class User<T> extends meerkat.crypto.dkg.feldman.User<T> {
|
|||
|
||||
/**
|
||||
* constructor
|
||||
* @param sdkg gjkr protocol object
|
||||
*
|
||||
* @param sdkg gjkr protocol object
|
||||
* @param channel channel object
|
||||
*/
|
||||
public User(Protocol<T> sdkg, Channel channel) {
|
||||
|
@ -52,15 +56,16 @@ public class User<T> extends meerkat.crypto.dkg.feldman.User<T> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void registerReceiverCallback(){
|
||||
protected void registerReceiverCallback() {
|
||||
this.messageHandler = new MessageHandler();
|
||||
this.mailHandler = new MailHandler(messageHandler);
|
||||
this.channel.registerReceiverCallback(mailHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* stage1 according to the protocol
|
||||
* 1. Pi broadcasts Cik=Aik*Bik for k = 0,...,t.
|
||||
* 2. Pi computes the shares Sij,Sij' for j = 1,...,n and sends Sij,Sij' secretly to Pj.
|
||||
* 1. Pi broadcasts Cik=Aik*Bik for k = 0,...,t.
|
||||
* 2. Pi computes the shares Sij,Sij' for j = 1,...,n and sends Sij,Sij' secretly to Pj.
|
||||
*/
|
||||
@Override
|
||||
protected void stage1() {
|
||||
|
@ -69,11 +74,11 @@ public class User<T> extends meerkat.crypto.dkg.feldman.User<T> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void waitUntilStageOneCompleted(){
|
||||
protected void waitUntilStageOneCompleted() {
|
||||
super.waitUntilStageOneCompleted();
|
||||
// save the received commitments as verification values
|
||||
ArrayList<T> temp;
|
||||
for (int i = 0 ; i < n; i++){
|
||||
for (int i = 0; i < n; i++) {
|
||||
temp = parties[i].verifiableValues;
|
||||
parties[i].verifiableValues = parties[i].commitments;
|
||||
parties[i].commitments = temp;
|
||||
|
@ -82,26 +87,25 @@ public class User<T> extends meerkat.crypto.dkg.feldman.User<T> {
|
|||
|
||||
/**
|
||||
* stage2 according to the protocol
|
||||
* Pj verifies all the shares,sharesT he received
|
||||
* if check fails for an index i, Pj broadcasts a complaint against Pi.
|
||||
* Pj broadcasts done message at the end of this stage
|
||||
* Pj verifies all the shares,sharesT he received
|
||||
* if check fails for an index i, Pj broadcasts a complaint against Pi.
|
||||
* Pj broadcasts done message at the end of this stage
|
||||
*/
|
||||
@Override
|
||||
protected void stage2(){
|
||||
protected void stage2() {
|
||||
sdkg.broadcastComplaints();
|
||||
//broadcast done message after all complaints
|
||||
DKGMessages.EmptyMessage doneMessage = DKGMessages.EmptyMessage.newBuilder().build();
|
||||
channel.broadcastMessage(DKGMessages.Mail.Type.DONE,doneMessage);
|
||||
channel.broadcastMessage(createMessage(DKG.Payload.Type.DONE));
|
||||
}
|
||||
|
||||
/**
|
||||
* broadcast commitments and recover parties information if necessary
|
||||
*/
|
||||
private void resolveQualifyingPublicKey(){
|
||||
private void resolveQualifyingPublicKey() {
|
||||
sdkg.broadcastCommitments();
|
||||
// wait until all parties in QUAL broadcast their commitments or aborted
|
||||
for (int i:QUAL) {
|
||||
for(int k = 0; k <= t; k++) {
|
||||
for (int i : QUAL) {
|
||||
for (int k = 0; k <= t; k++) {
|
||||
synchronized (parties[i - 1]) {
|
||||
while (parties[i - 1].commitments.get(k) == null && !parties[i - 1].aborted) {
|
||||
try {
|
||||
|
@ -115,11 +119,9 @@ public class User<T> extends meerkat.crypto.dkg.feldman.User<T> {
|
|||
}
|
||||
sdkg.computeAndBroadcastComplaints(QUAL);
|
||||
//broadcast done message after all complaints
|
||||
DKGMessages.EmptyMessage doneMessage = DKGMessages.EmptyMessage.newBuilder().build();
|
||||
channel.broadcastMessage(DKGMessages.Mail.Type.DONE,doneMessage);
|
||||
|
||||
channel.broadcastMessage(createMessage(DKG.Payload.Type.DONE));
|
||||
// wait until all parties in QUAL done or aborted
|
||||
for (int i:QUAL) {
|
||||
for (int i : QUAL) {
|
||||
synchronized ((parties[i - 1])) {
|
||||
while (!parties[i - 1].ysDoneFlag && !parties[i - 1].aborted) {
|
||||
try {
|
||||
|
@ -132,13 +134,13 @@ public class User<T> extends meerkat.crypto.dkg.feldman.User<T> {
|
|||
}
|
||||
|
||||
// broadcast i private secret foreach i in QUAL that aborted
|
||||
for (int i:QUAL) {
|
||||
if(parties[i - 1].aborted){
|
||||
for (int i : QUAL) {
|
||||
if (parties[i - 1].aborted) {
|
||||
sdkg.broadcastAnswer(parties[i - 1].share, parties[i - 1].shareT, i);
|
||||
}
|
||||
}
|
||||
// wait until at least t + 1 secrets will received foreach i in QUAL that aborted
|
||||
for (int i:QUAL) {
|
||||
for (int i : QUAL) {
|
||||
synchronized ((parties[i - 1])) {
|
||||
if (parties[i - 1].aborted) {
|
||||
while (parties[i - 1].recoverSharesSet.size() <= t) {
|
||||
|
@ -153,33 +155,33 @@ public class User<T> extends meerkat.crypto.dkg.feldman.User<T> {
|
|||
}
|
||||
Arithmetic<BigInteger> arithmetic = new Fp(sdkg.getQ());
|
||||
// restore necessary information
|
||||
for (int i = 0; i < n ; i++) {
|
||||
if(parties[i].recoverSharesSet.isEmpty()){
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (parties[i].recoverSharesSet.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
Polynomial.Point[] shares = new Polynomial.Point[t + 1];
|
||||
int j = 0;
|
||||
for (Polynomial.Point share: parties[i].recoverSharesSet){
|
||||
for (Polynomial.Point share : parties[i].recoverSharesSet) {
|
||||
shares[j++] = share;
|
||||
if (j >= shares.length){
|
||||
if (j >= shares.length) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Polynomial polynomial = SecretSharing.recoverPolynomial(shares,arithmetic);
|
||||
Polynomial polynomial = SecretSharing.recoverPolynomial(shares, arithmetic);
|
||||
BigInteger[] coefficients = polynomial.getCoefficients();
|
||||
for (int k = 0 ; k <= t; k++){
|
||||
parties[i].commitments.add(k,group.multiply(g,coefficients[k]));
|
||||
for (int k = 0; k <= t; k++) {
|
||||
parties[i].commitments.add(k, group.multiply(g, coefficients[k]));
|
||||
}
|
||||
parties[i].share = new Polynomial.Point(BigInteger.valueOf(id),polynomial);
|
||||
parties[i].share = new Polynomial.Point(BigInteger.valueOf(id), polynomial);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* notifies mail handler and message handler that stage 4 was started
|
||||
*/
|
||||
protected void setStage4(){
|
||||
protected void setStage4() {
|
||||
this.messageHandler.isStage4 = true;
|
||||
((MailHandler)this.mailHandler).setStage4(true);
|
||||
((MailHandler) this.mailHandler).setStage4(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -193,158 +195,148 @@ public class User<T> extends meerkat.crypto.dkg.feldman.User<T> {
|
|||
private class MessageHandler extends meerkat.crypto.dkg.feldman.User.MessageHandler {
|
||||
|
||||
boolean isStage4;
|
||||
/**
|
||||
* as in super, with extension to double secret message
|
||||
*/
|
||||
protected boolean isValidSecretMessage(int sender, boolean isBroadcast, DKGMessages.DoubleShareMessage doubleSecretMessage) {
|
||||
DKGMessages.ShareMessage secretMessage = DKGMessages.ShareMessage.newBuilder()
|
||||
.setI(doubleSecretMessage.getI())
|
||||
.setJ(doubleSecretMessage.getJ())
|
||||
.setShare(doubleSecretMessage.getShare())
|
||||
.build();
|
||||
return super.isValidSecretMessage(sender,isBroadcast,secretMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* as in super, with extension to double secret message
|
||||
*/
|
||||
@Override
|
||||
public void handleShareMessage(int sender, boolean isBroadcast, Message message) {
|
||||
DKGMessages.DoubleShareMessage doubleSecretMessage = (DKGMessages.DoubleShareMessage)message;
|
||||
if (isValidSecretMessage(sender,isBroadcast,doubleSecretMessage)) {
|
||||
int i = doubleSecretMessage.getI();
|
||||
synchronized (parties[i - 1]) {
|
||||
parties[i - 1].share = extractShare(id, doubleSecretMessage.getShare());
|
||||
parties[i - 1].shareT = extractShare(id, doubleSecretMessage.getShareT());
|
||||
parties[i - 1].notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* if !isStage4 as super, with extension to double secret message
|
||||
* else answer message is valid if:
|
||||
* 1. it was received in broadcast chanel
|
||||
* 2. secret.j == sender
|
||||
* 3. QUAL contains i and j
|
||||
* 1. it was received in broadcast chanel
|
||||
* 2. secret.j == sender
|
||||
* 3. QUAL contains i and j
|
||||
*/
|
||||
protected boolean isValidAnswerMessage(int sender, boolean isBroadcast, DKGMessages.DoubleShareMessage doubleSecretMessage) {
|
||||
if(!isStage4) {
|
||||
DKGMessages.ShareMessage secretMessage = DKGMessages.ShareMessage.newBuilder()
|
||||
.setI(doubleSecretMessage.getI())
|
||||
.setJ(doubleSecretMessage.getJ())
|
||||
.setShare(doubleSecretMessage.getShare())
|
||||
.build();
|
||||
return super.isValidAnswerMessage(sender, isBroadcast, secretMessage);
|
||||
}else{
|
||||
protected boolean isValidAnswerMessage(int sender, boolean isBroadcast, DKG.ShareMessage doubleSecretMessage) {
|
||||
if (!isStage4) {
|
||||
return super.isValidAnswerMessage(sender, isBroadcast, doubleSecretMessage);
|
||||
} else {
|
||||
int i = doubleSecretMessage.getI();
|
||||
int j = doubleSecretMessage.getJ();
|
||||
return isBroadcast && j == sender && parties[i -1].aborted && !parties[j - 1].aborted
|
||||
return isBroadcast && j == sender && parties[i - 1].aborted && !parties[j - 1].aborted
|
||||
&& QUAL.contains(i) && QUAL.contains(j);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* if !isStage4 as super, with extension to double secret message
|
||||
* else saves secret
|
||||
*/
|
||||
@Override
|
||||
public void handleAnswerMessage(int sender, boolean isBroadcast, Message message) {
|
||||
DKGMessages.DoubleShareMessage doubleSecretMessage = (DKGMessages.DoubleShareMessage)message;
|
||||
if(isValidAnswerMessage(sender,isBroadcast,doubleSecretMessage)) {
|
||||
int i = doubleSecretMessage.getI();
|
||||
int j = doubleSecretMessage.getJ();
|
||||
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)) {
|
||||
parties[i - 1].complaints[j - 1] = meerkat.crypto.dkg.feldman.Protocol.ComplaintState.NonDisqualified;
|
||||
|
||||
} else {
|
||||
parties[i - 1].complaints[j - 1] = meerkat.crypto.dkg.feldman.Protocol.ComplaintState.Disqualified;
|
||||
}
|
||||
if (j == id) {
|
||||
parties[i - 1].share = secret;
|
||||
parties[i - 1].shareT = secretT;
|
||||
}
|
||||
} else if (sdkg.isValidShare(secret, secretT, parties[i - 1].verifiableValues, j)) {
|
||||
parties[i - 1].recoverSharesSet.add(secret);
|
||||
}
|
||||
parties[i - 1].notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* as in super with respect to protocol stage
|
||||
*/
|
||||
@Override
|
||||
protected boolean isValidDoneMessage(int sender, boolean isBroadcast) {
|
||||
if(!isStage4) {
|
||||
if (!isStage4) {
|
||||
return super.isValidDoneMessage(sender, isBroadcast);
|
||||
}else{
|
||||
return isBroadcast && !parties[sender - 1].ysDoneFlag;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* as in super with respect to protocol state
|
||||
*/
|
||||
@Override
|
||||
public void handleDoneMessage(int sender, boolean isBroadcast, Message message) {
|
||||
if(!isStage4)
|
||||
super.handleDoneMessage(sender, isBroadcast, message);
|
||||
else{
|
||||
if(isValidDoneMessage(sender,isBroadcast)) {
|
||||
synchronized (parties[sender - 1]) {
|
||||
parties[sender - 1].ysDoneFlag = true;
|
||||
parties[sender - 1].notify();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return isBroadcast && !parties[sender - 1].ysDoneFlag;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* use only in stage4
|
||||
* complaint message is valid if:
|
||||
* 1. it was received in broadcast chanel
|
||||
* 2. secret.j == sender
|
||||
* 3. QUAL contains i and j
|
||||
* 1. it was received in broadcast chanel
|
||||
* 2. secret.j == sender
|
||||
* 3. QUAL contains i and j
|
||||
*/
|
||||
protected boolean isValidComplaintMessage(int sender, boolean isBroadcast,
|
||||
DKGMessages.DoubleShareMessage complaintMessage){
|
||||
DKG.ShareMessage complaintMessage) {
|
||||
int i = complaintMessage.getI();
|
||||
int j = complaintMessage.getJ();
|
||||
return isBroadcast && j == sender && QUAL.contains(i) && QUAL.contains(j);
|
||||
}
|
||||
|
||||
/**
|
||||
* if !isStage4 as in super
|
||||
* else if secret,secretT are valid with respect to verifiableValues but
|
||||
* secret is not valid with respect to commitments then
|
||||
* marks i as aborted
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void handleComplaintMessage(int sender, boolean isBroadcast, Message message) {
|
||||
if(!isStage4) {
|
||||
super.handleComplaintMessage(sender, isBroadcast, message);
|
||||
}else {
|
||||
DKGMessages.DoubleShareMessage ysComplaintMessage =(DKGMessages.DoubleShareMessage)message;
|
||||
if (isValidComplaintMessage(sender,isBroadcast,ysComplaintMessage)) {
|
||||
int i = ysComplaintMessage.getI();
|
||||
int j = ysComplaintMessage.getJ();
|
||||
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)) {
|
||||
public void handleMessage(DKG.BroadcastMessage envelope) throws InvalidProtocolBufferException {
|
||||
int sender = envelope.getSender();
|
||||
boolean isBroadcast = !envelope.getIsPrivate();
|
||||
DKG.Payload msg = DKG.Payload.parseFrom(envelope.getPayload());
|
||||
switch (msg.getType()) {
|
||||
case SHARE:
|
||||
/**
|
||||
* as in super, with extension to double secret message
|
||||
*/
|
||||
DKG.ShareMessage doubleSecretMessage = msg.getShare();
|
||||
if (isValidSecretMessage(sender, isBroadcast, doubleSecretMessage)) {
|
||||
int i = doubleSecretMessage.getI();
|
||||
synchronized (parties[i - 1]) {
|
||||
parties[i - 1].aborted = true;
|
||||
parties[i - 1].share = extractShare(id, doubleSecretMessage.getShare());
|
||||
parties[i - 1].shareT = extractShare(id, doubleSecretMessage.getShareT());
|
||||
parties[i - 1].notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ANSWER:
|
||||
/**
|
||||
* if !isStage4 as super, with extension to double secret message
|
||||
* else saves secret
|
||||
*/
|
||||
doubleSecretMessage = msg.getShare();
|
||||
if (isValidAnswerMessage(sender, isBroadcast, doubleSecretMessage)) {
|
||||
int i = doubleSecretMessage.getI();
|
||||
int j = doubleSecretMessage.getJ();
|
||||
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)) {
|
||||
parties[i - 1].complaints[j - 1] = meerkat.crypto.dkg.feldman.Protocol.ComplaintState.NonDisqualified;
|
||||
|
||||
} else {
|
||||
parties[i - 1].complaints[j - 1] = meerkat.crypto.dkg.feldman.Protocol.ComplaintState.Disqualified;
|
||||
}
|
||||
if (j == id) {
|
||||
parties[i - 1].share = secret;
|
||||
parties[i - 1].shareT = secretT;
|
||||
}
|
||||
} else if (sdkg.isValidShare(secret, secretT, parties[i - 1].verifiableValues, j)) {
|
||||
parties[i - 1].recoverSharesSet.add(secret);
|
||||
}
|
||||
parties[i - 1].notify();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DONE:
|
||||
/**
|
||||
* as in super with respect to protocol state
|
||||
*/
|
||||
if (!isStage4)
|
||||
super.handleMessage(envelope);
|
||||
else {
|
||||
if (isValidDoneMessage(sender, isBroadcast)) {
|
||||
synchronized (parties[sender - 1]) {
|
||||
parties[sender - 1].ysDoneFlag = true;
|
||||
parties[sender - 1].notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case COMPLAINT:
|
||||
/**
|
||||
* if !isStage4 as in super
|
||||
* else if secret,secretT are valid with respect to verifiableValues but
|
||||
* secret is not valid with respect to commitments then
|
||||
* marks i as aborted
|
||||
*/
|
||||
if (!isStage4) {
|
||||
super.handleMessage(envelope);
|
||||
} else {
|
||||
DKG.ShareMessage ysComplaintMessage = msg.getShare();
|
||||
if (isValidComplaintMessage(sender, isBroadcast, ysComplaintMessage)) {
|
||||
int i = ysComplaintMessage.getI();
|
||||
int j = ysComplaintMessage.getJ();
|
||||
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]) {
|
||||
parties[i - 1].aborted = true;
|
||||
parties[i - 1].notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
super.handleMessage(envelope);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,32 +1,36 @@
|
|||
package meerkat.crypto.utils;
|
||||
|
||||
import com.google.protobuf.Message;
|
||||
import meerkat.protobuf.DKGMessages;
|
||||
import meerkat.protobuf.DKG;
|
||||
|
||||
/**
|
||||
* A generic communication channel that supports point-to-point and broadcast operation
|
||||
*/
|
||||
|
||||
public interface Channel {
|
||||
/**
|
||||
* Return the id of the channel's endpoint (this will be used as the source of message sent from the channel).
|
||||
* @return
|
||||
*/
|
||||
public int getSourceId();
|
||||
|
||||
public interface ReceiverCallback {
|
||||
public void receiveMail(DKGMessages.Mail mail);
|
||||
public void receiveMail(DKG.BroadcastMessage envelope);
|
||||
}
|
||||
|
||||
/**
|
||||
* sends a private message
|
||||
* @param destUser destination user's identifier
|
||||
* @param type message type
|
||||
* @param msg message
|
||||
*/
|
||||
public void sendMessage(int destUser, DKGMessages.Mail.Type type, Message msg);
|
||||
public void sendMessage(int destUser, Message msg);
|
||||
|
||||
|
||||
/**
|
||||
* broadcasts a message to all parties (including the sender)
|
||||
* @param type message type
|
||||
* @param msg message
|
||||
*/
|
||||
public void broadcastMessage(DKGMessages.Mail.Type type, Message msg);
|
||||
public void broadcastMessage(Message msg);
|
||||
|
||||
/**
|
||||
* Register a callback to handle received messages.
|
||||
|
|
|
@ -4,7 +4,15 @@ package meerkat;
|
|||
|
||||
option java_package = "meerkat.protobuf";
|
||||
|
||||
message Mail {
|
||||
message BroadcastMessage {
|
||||
int32 sender = 1;
|
||||
int32 destination = 2;
|
||||
bool is_private = 3;
|
||||
|
||||
bytes payload = 5;
|
||||
}
|
||||
|
||||
message Payload {
|
||||
enum Type {
|
||||
SHARE = 0;
|
||||
COMMITMENT = 1;
|
||||
|
@ -16,23 +24,25 @@ message Mail {
|
|||
YANSWER = 7;
|
||||
ABORT = 8;
|
||||
}
|
||||
int32 sender = 1;
|
||||
int32 destination = 2;
|
||||
bool is_private = 3;
|
||||
Type type = 4;
|
||||
bytes message = 5;
|
||||
|
||||
Type type = 1;
|
||||
|
||||
oneof specific {
|
||||
IDMessage id = 5;
|
||||
ShareMessage share = 6;
|
||||
CommitmentMessage commitment = 7;
|
||||
}
|
||||
}
|
||||
|
||||
message IDMessage {
|
||||
int32 id = 1;
|
||||
}
|
||||
|
||||
message ShareMessage {
|
||||
int32 i = 1;
|
||||
int32 j = 2;
|
||||
bytes share = 3;
|
||||
}
|
||||
|
||||
message DoubleShareMessage {
|
||||
int32 i = 1;
|
||||
int32 j = 2;
|
||||
bytes share = 3;
|
||||
// For double shares (used in GJKR protocol)
|
||||
bytes share_t = 4;
|
||||
}
|
||||
|
||||
|
@ -40,9 +50,3 @@ message CommitmentMessage {
|
|||
int32 k = 1;
|
||||
bytes commitment = 2;
|
||||
}
|
||||
|
||||
message EmptyMessage{}
|
||||
|
||||
message IDMessage{
|
||||
int32 id = 1;
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
package meerkat.crypto.dkg.feldman;
|
||||
|
||||
import meerkat.crypto.utils.Channel;
|
||||
import meerkat.protobuf.DKGMessages;
|
||||
import meerkat.protobuf.DKG;
|
||||
|
||||
import static meerkat.crypto.dkg.comm.MessageUtils.createMessage;
|
||||
|
||||
/**
|
||||
* Created by Tzlil on 3/14/2016.
|
||||
|
@ -18,7 +20,7 @@ public class DKGUserImplAbort<T> extends User<T> {
|
|||
|
||||
|
||||
private void sendAbort(){
|
||||
channel.broadcastMessage(DKGMessages.Mail.Type.ABORT,DKGMessages.EmptyMessage.getDefaultInstance());
|
||||
channel.broadcastMessage(createMessage(DKG.Payload.Type.ABORT));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package meerkat.crypto.dkg.gjkr;
|
||||
|
||||
import meerkat.crypto.dkg.comm.MessageUtils;
|
||||
import meerkat.crypto.utils.Channel;
|
||||
import meerkat.protobuf.DKGMessages;
|
||||
import meerkat.protobuf.DKG;
|
||||
|
||||
/**
|
||||
* Created by Tzlil on 3/14/2016.
|
||||
|
@ -18,7 +19,7 @@ public class SDKGUserImplAbort<T> extends User<T> {
|
|||
|
||||
private void abort(){
|
||||
//stopReceiver();
|
||||
channel.broadcastMessage(DKGMessages.Mail.Type.ABORT,DKGMessages.EmptyMessage.getDefaultInstance());
|
||||
channel.broadcastMessage(MessageUtils.createMessage(DKG.Payload.Type.ABORT));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package meerkat.crypto.utils;
|
||||
|
||||
import com.google.protobuf.Message;
|
||||
import meerkat.protobuf.DKGMessages;
|
||||
import meerkat.protobuf.DKG;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
|
@ -16,7 +16,7 @@ public class ChannelImpl implements Channel {
|
|||
public static int BROADCAST = 0;
|
||||
private static ChannelImpl[] channels = null;
|
||||
|
||||
protected final Queue<DKGMessages.Mail> mailbox;
|
||||
protected final Queue<DKG.BroadcastMessage> mailbox;
|
||||
protected final int id;
|
||||
protected final int n;
|
||||
protected Thread receiverThread;
|
||||
|
@ -26,50 +26,50 @@ public class ChannelImpl implements Channel {
|
|||
if (channels == null){
|
||||
channels = new ChannelImpl[n];
|
||||
}
|
||||
this.mailbox = new ArrayBlockingQueue<DKGMessages.Mail>( n * n * n);
|
||||
this.mailbox = new ArrayBlockingQueue<DKG.BroadcastMessage>( n * n * n);
|
||||
this.id = id;
|
||||
this.n = n;
|
||||
channels[id - 1] = this;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
@Override
|
||||
public int getSourceId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendMessage(int destUser, DKGMessages.Mail.Type type, Message msg) {
|
||||
public void sendMessage(int destUser, Message msg) {
|
||||
if(destUser < 1 || destUser > n)
|
||||
return;
|
||||
ChannelImpl channel = channels[destUser - 1];
|
||||
if (channel == null)
|
||||
return;
|
||||
DKGMessages.Mail mail = DKGMessages.Mail.newBuilder()
|
||||
DKG.BroadcastMessage broadcastMessage = DKG.BroadcastMessage.newBuilder()
|
||||
.setSender(id)
|
||||
.setDestination(destUser)
|
||||
.setIsPrivate(true)
|
||||
.setType(type)
|
||||
.setMessage(msg.toByteString())
|
||||
.setPayload(msg.toByteString())
|
||||
.build();
|
||||
synchronized (channel.mailbox) {
|
||||
channel.mailbox.add(mail);
|
||||
channel.mailbox.add(broadcastMessage);
|
||||
channel.mailbox.notify();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcastMessage(DKGMessages.Mail.Type type,Message msg) {
|
||||
public void broadcastMessage(Message msg) {
|
||||
ChannelImpl channel;
|
||||
DKGMessages.Mail mail = DKGMessages.Mail.newBuilder()
|
||||
DKG.BroadcastMessage broadcastMessage = DKG.BroadcastMessage.newBuilder()
|
||||
.setSender(id)
|
||||
.setDestination(BROADCAST)
|
||||
.setIsPrivate(false)
|
||||
.setType(type)
|
||||
.setMessage(msg.toByteString())
|
||||
.setPayload(msg.toByteString())
|
||||
.build();
|
||||
for (int i = 0 ; i < n ; i++){
|
||||
channel = channels[i];
|
||||
synchronized (channel.mailbox) {
|
||||
channel.mailbox.add(mail);
|
||||
channel.mailbox.add(broadcastMessage);
|
||||
channel.mailbox.notify();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue