redesigned mail handler
parent
0f7dbe3d50
commit
cc7e138a43
|
@ -1,50 +1,53 @@
|
||||||
package Communication;
|
package Communication;
|
||||||
|
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.google.protobuf.Message;
|
||||||
import meerkat.protobuf.DKGMessages;
|
import meerkat.protobuf.DKGMessages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Tzlil on 2/14/2016.
|
* Created by Tzlil on 2/14/2016.
|
||||||
*/
|
*/
|
||||||
public class MailHandler {
|
public abstract class MailHandler {
|
||||||
|
|
||||||
private MessageHandler messageHandler;
|
private MessageHandler messageHandler;
|
||||||
public MailHandler(MessageHandler messageHandler){
|
public MailHandler(MessageHandler messageHandler){
|
||||||
this.messageHandler = messageHandler;
|
this.messageHandler = messageHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract Message extractMessage(DKGMessages.Mail mail);
|
||||||
|
|
||||||
public void handel(DKGMessages.Mail mail) throws InvalidProtocolBufferException {
|
public void handel(DKGMessages.Mail mail){
|
||||||
switch (mail.getType()){
|
|
||||||
|
Message message = extractMessage(mail);
|
||||||
|
if (message == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (mail.getType()) {
|
||||||
case SECRET:
|
case SECRET:
|
||||||
DKGMessages.SecretMessage secretMessage = DKGMessages.SecretMessage.parseFrom(mail.getMessage());
|
messageHandler.handelSecretMessage(mail.getSender(), mail.getDestination() == Network.BROADCAST
|
||||||
messageHandler.handelSecretMessage(mail.getSender(),mail.getDestination()== Network.BROADCAST,secretMessage);
|
, message);
|
||||||
break;
|
break;
|
||||||
case COMMITMENT:
|
case COMMITMENT:
|
||||||
DKGMessages.CommitmentMessage commitmentMessage = DKGMessages.CommitmentMessage.parseFrom(mail.getMessage());
|
messageHandler.handelCommitmentMessage(mail.getSender(), mail.getDestination() == Network.BROADCAST
|
||||||
messageHandler.handelCommitmentMessage(mail.getSender(),mail.getDestination()== Network.BROADCAST,commitmentMessage);
|
, message);
|
||||||
break;
|
break;
|
||||||
case DONE:
|
case DONE:
|
||||||
DKGMessages.DoneMessage doneMessage = DKGMessages.DoneMessage.parseFrom(mail.getMessage());
|
messageHandler.handelDoneMessage(mail.getSender(), mail.getDestination() == Network.BROADCAST
|
||||||
messageHandler.handelDoneMessage(mail.getSender(),mail.getDestination()== Network.BROADCAST,doneMessage);
|
, message);
|
||||||
break;
|
break;
|
||||||
case COMPLAINT:
|
case COMPLAINT:
|
||||||
DKGMessages.ComplaintMessage complaintMessage = DKGMessages.ComplaintMessage.parseFrom(mail.getMessage());
|
messageHandler.handelComplaintMessage(mail.getSender(), mail.getDestination() == Network.BROADCAST
|
||||||
messageHandler.handelComplaintMessage(mail.getSender(),mail.getDestination()== Network.BROADCAST,complaintMessage);
|
, message);
|
||||||
break;
|
break;
|
||||||
case DOUBLE:
|
case ANSWER:
|
||||||
DKGMessages.DoubleSecretMessage doubleSecretMessage = DKGMessages.DoubleSecretMessage.parseFrom(mail.getMessage());
|
messageHandler.handelAnswerMessage(mail.getSender(), mail.getDestination() == Network.BROADCAST
|
||||||
messageHandler.handelDoubleSecretMessage(mail.getSender(),mail.getDestination()== Network.BROADCAST,doubleSecretMessage);
|
, message);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public MessageHandler getMessageHandler(){
|
|
||||||
return messageHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMessageHandler(MessageHandler messageHandler) {
|
public void setMessageHandler(MessageHandler messageHandler) {
|
||||||
this.messageHandler = messageHandler;
|
this.messageHandler = messageHandler;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package Communication;
|
package Communication;
|
||||||
|
|
||||||
import meerkat.protobuf.DKGMessages;
|
import com.google.protobuf.Message;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Tzlil on 2/14/2016.
|
* Created by Tzlil on 2/14/2016.
|
||||||
*/
|
*/
|
||||||
public interface MessageHandler {
|
public interface MessageHandler {
|
||||||
void handelComplaintMessage(int sender, boolean isBroadcast,DKGMessages.ComplaintMessage complaintMessage);
|
void handelSecretMessage(int sender, boolean isBroadcast, Message message);
|
||||||
void handelDoneMessage(int sender, boolean isBroadcast, DKGMessages.DoneMessage doneMessage);
|
void handelCommitmentMessage(int sender, boolean isBroadcast, Message message);
|
||||||
void handelCommitmentMessage(int sender, boolean isBroadcast,DKGMessages.CommitmentMessage commitmentMessage);
|
void handelComplaintMessage(int sender, boolean isBroadcast, Message message);
|
||||||
void handelSecretMessage(int sender, boolean isBroadcast,DKGMessages.SecretMessage secretMessage);
|
void handelDoneMessage(int sender, boolean isBroadcast, Message message); //will be remove
|
||||||
void handelDoubleSecretMessage(int sender, boolean isBroadcast,DKGMessages.DoubleSecretMessage doubleSecretMessage);
|
void handelAnswerMessage(int sender, boolean isBroadcast, Message message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,11 +28,11 @@ public class Network {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public User connect(MessageHandler messageHandler){
|
public User connect(MailHandler mailHandler){
|
||||||
Integer id = availableIDs.poll();
|
Integer id = availableIDs.poll();
|
||||||
if (id == null)
|
if (id == null)
|
||||||
return null;
|
return null;
|
||||||
users[id - 1] = new User(id,this,new MailHandler(messageHandler));
|
users[id - 1] = new User(id,this,mailHandler);
|
||||||
return users[id - 1];
|
return users[id - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,9 @@ public class User{
|
||||||
public void broadcast(DKGMessages.Mail.Type type, Message message){
|
public void broadcast(DKGMessages.Mail.Type type, Message message){
|
||||||
network.sendBroadcast(this,type,message);
|
network.sendBroadcast(this,type,message);
|
||||||
}
|
}
|
||||||
|
public MailHandler getMailHandler(){
|
||||||
|
return mailHandler;
|
||||||
|
}
|
||||||
public void setMessageHandler(MessageHandler messageHandler) {
|
public void setMessageHandler(MessageHandler messageHandler) {
|
||||||
mailHandler.setMessageHandler(messageHandler);
|
mailHandler.setMessageHandler(messageHandler);
|
||||||
}
|
}
|
||||||
|
@ -48,11 +50,7 @@ public class User{
|
||||||
public void run() {
|
public void run() {
|
||||||
while (true){
|
while (true){
|
||||||
if (!mailbox.isEmpty()){
|
if (!mailbox.isEmpty()){
|
||||||
try {
|
mailHandler.handel(mailbox.poll());
|
||||||
mailHandler.handel(mailbox.poll());
|
|
||||||
} catch (InvalidProtocolBufferException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
try {
|
try {
|
||||||
Thread.sleep(30);
|
Thread.sleep(30);
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class VerifiableSecretSharing extends SecretSharing {
|
||||||
* @param commitments
|
* @param commitments
|
||||||
* @param group
|
* @param group
|
||||||
*
|
*
|
||||||
* @return product of commitmentsArray[j] ^ (i ^ j) == g ^ polynomial(i)
|
* @return product of Aik ^ (j ^ k) == g ^ polynomial(i)
|
||||||
*/
|
*/
|
||||||
public static BigInteger verify(int j,BigInteger[] commitments,Group<BigInteger> group) {
|
public static BigInteger verify(int j,BigInteger[] commitments,Group<BigInteger> group) {
|
||||||
BigInteger v = group.zero();
|
BigInteger v = group.zero();
|
||||||
|
|
|
@ -50,8 +50,13 @@ public class DistributedKeyGeneration extends VerifiableSecretSharing{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendSecret(User user, int j){
|
public void sendSecret(User user, int j){
|
||||||
SecretMessage.Point secret = getShare(j).asMessage();
|
ByteString secret = ByteString.copyFrom(getShare(j).y.toByteArray());
|
||||||
user.send(j, Mail.Type.DOUBLE,SecretMessage.newBuilder().setSecret(secret).build());
|
user.send(j, Mail.Type.SECRET,
|
||||||
|
SecretMessage.newBuilder()
|
||||||
|
.setI(id)
|
||||||
|
.setJ(j)
|
||||||
|
.setSecret(secret)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,13 +71,13 @@ public class DistributedKeyGeneration extends VerifiableSecretSharing{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValidSecret(int j,BigInteger[] commitments,int i){
|
public boolean isValidSecret(int i,BigInteger[] commitments,int j){
|
||||||
Polynomial.Point secret = shares[j - 1];
|
Polynomial.Point secret = shares[i - 1];
|
||||||
return isValidSecret(secret,commitments,i);
|
return isValidSecret(secret,commitments,j);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValidSecret(Polynomial.Point secret, BigInteger[] commitments, int i){
|
public boolean isValidSecret(Polynomial.Point secret, BigInteger[] commitments, int j){
|
||||||
BigInteger v = verify(i,commitments,group);
|
BigInteger v = verify(j,commitments,group);
|
||||||
return group.multiply(g,secret.y).equals(v);
|
return group.multiply(g,secret.y).equals(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,12 +88,12 @@ public class DistributedKeyGeneration extends VerifiableSecretSharing{
|
||||||
*/
|
*/
|
||||||
public void broadcastComplains(User user, BigInteger[][]commitmentsTable){
|
public void broadcastComplains(User user, BigInteger[][]commitmentsTable){
|
||||||
ComplaintMessage complaint;
|
ComplaintMessage complaint;
|
||||||
for (int j = 1; j <= n ; j++ ){
|
for (int i = 1; i <= n ; i++ ){
|
||||||
if(j != id) {
|
if(i != id) {
|
||||||
if (!isValidSecret(j,commitmentsTable[j - 1],id)) {
|
if (!isValidSecret(i,commitmentsTable[i - 1],id)) {
|
||||||
//message = new Message(Type.Complaint, j)
|
//message = new Message(Type.Complaint, j)
|
||||||
complaint = ComplaintMessage.newBuilder()
|
complaint = ComplaintMessage.newBuilder()
|
||||||
.setId(j)
|
.setId(i)
|
||||||
.build();
|
.build();
|
||||||
user.broadcast(Mail.Type.COMPLAINT, complaint);
|
user.broadcast(Mail.Type.COMPLAINT, complaint);
|
||||||
}
|
}
|
||||||
|
@ -98,8 +103,10 @@ public class DistributedKeyGeneration extends VerifiableSecretSharing{
|
||||||
|
|
||||||
|
|
||||||
public void broadcastComplaintAnswer(User user, int j){
|
public void broadcastComplaintAnswer(User user, int j){
|
||||||
user.broadcast(Mail.Type.SECRET, SecretMessage.newBuilder()
|
user.broadcast(Mail.Type.ANSWER, SecretMessage.newBuilder()
|
||||||
.setSecret(getShare(j).asMessage())
|
.setI(id)
|
||||||
|
.setJ(j)
|
||||||
|
.setSecret(ByteString.copyFrom(getShare(j).y.toByteArray()))
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,10 +115,10 @@ public class DistributedKeyGeneration extends VerifiableSecretSharing{
|
||||||
* if more than t players complain against a player Pi he is disqualified.
|
* if more than t players complain against a player Pi he is disqualified.
|
||||||
*/
|
*/
|
||||||
public void answerAllComplainingPlayers(User user, DistributedKeyGenerationUserImpl.ComplainState[] complains){
|
public void answerAllComplainingPlayers(User user, DistributedKeyGenerationUserImpl.ComplainState[] complains){
|
||||||
for (int j = 1; j <= n ; j++) {
|
for (int i = 1; i <= n ; i++) {
|
||||||
switch (complains[j - 1]) {
|
switch (complains[i - 1]) {
|
||||||
case Waiting:
|
case Waiting:
|
||||||
broadcastComplaintAnswer(user,j);
|
broadcastComplaintAnswer(user,i);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
package JointFeldmanProtocol;
|
||||||
|
|
||||||
|
import Communication.MailHandler;
|
||||||
|
import Communication.MessageHandler;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.google.protobuf.Message;
|
||||||
|
import meerkat.protobuf.DKGMessages;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Tzlil on 2/29/2016.
|
||||||
|
*/
|
||||||
|
public class DistributedKeyGenerationMailHandler extends MailHandler {
|
||||||
|
|
||||||
|
public DistributedKeyGenerationMailHandler(MessageHandler messageHandler) {
|
||||||
|
super(messageHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Message extractMessage(DKGMessages.Mail mail) {
|
||||||
|
try {
|
||||||
|
Message message;
|
||||||
|
switch (mail.getType()) {
|
||||||
|
case SECRET:
|
||||||
|
message = DKGMessages.SecretMessage.parseFrom(mail.getMessage());
|
||||||
|
break;
|
||||||
|
case COMMITMENT:
|
||||||
|
message = DKGMessages.CommitmentMessage.parseFrom(mail.getMessage());
|
||||||
|
break;
|
||||||
|
case COMPLAINT:
|
||||||
|
message = DKGMessages.ComplaintMessage.parseFrom(mail.getMessage());
|
||||||
|
break;
|
||||||
|
case DONE:
|
||||||
|
message = DKGMessages.DoneMessage.parseFrom(mail.getMessage());
|
||||||
|
break;
|
||||||
|
case ANSWER:
|
||||||
|
message = DKGMessages.SecretMessage.parseFrom(mail.getMessage());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
} catch (InvalidProtocolBufferException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,12 @@
|
||||||
package JointFeldmanProtocol;
|
package JointFeldmanProtocol;
|
||||||
|
|
||||||
|
import Communication.MailHandler;
|
||||||
import Communication.Network;
|
import Communication.Network;
|
||||||
import Communication.User;
|
import Communication.User;
|
||||||
import ShamirSecretSharing.Polynomial;
|
import ShamirSecretSharing.Polynomial;
|
||||||
import UserInterface.DistributedKeyGenerationUser;
|
import UserInterface.DistributedKeyGenerationUser;
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.Message;
|
||||||
import meerkat.protobuf.DKGMessages;
|
import meerkat.protobuf.DKGMessages;
|
||||||
import org.factcenter.qilin.primitives.Group;
|
import org.factcenter.qilin.primitives.Group;
|
||||||
|
|
||||||
|
@ -39,7 +42,10 @@ public class DistributedKeyGenerationUserImpl implements DistributedKeyGeneratio
|
||||||
protected Polynomial.Point share; // final share of the secrete
|
protected Polynomial.Point share; // final share of the secrete
|
||||||
protected BigInteger y; // final public value
|
protected BigInteger y; // final public value
|
||||||
|
|
||||||
public DistributedKeyGenerationUserImpl(DistributedKeyGeneration dkg, Network network) {
|
public DistributedKeyGenerationUserImpl(DistributedKeyGeneration dkg, Network network){
|
||||||
|
this(dkg,network,new DistributedKeyGenerationMailHandler(null));
|
||||||
|
}
|
||||||
|
public DistributedKeyGenerationUserImpl(DistributedKeyGeneration dkg, Network network, MailHandler mailHandler) {
|
||||||
this.dkg = dkg;
|
this.dkg = dkg;
|
||||||
|
|
||||||
this.g = dkg.getGenerator();
|
this.g = dkg.getGenerator();
|
||||||
|
@ -49,11 +55,12 @@ public class DistributedKeyGenerationUserImpl implements DistributedKeyGeneratio
|
||||||
this.id = dkg.getId();
|
this.id = dkg.getId();
|
||||||
|
|
||||||
this.messageHandler = new MessageHandler();
|
this.messageHandler = new MessageHandler();
|
||||||
|
mailHandler.setMessageHandler(this.messageHandler);
|
||||||
|
this.user = network.connect(mailHandler);
|
||||||
this.shares = new Polynomial.Point[n];
|
this.shares = new Polynomial.Point[n];
|
||||||
this.shares[id - 1] = dkg.getShare(id);
|
this.shares[id - 1] = dkg.getShare(id);
|
||||||
this.commitmentsTable = new BigInteger[n][t + 1];
|
this.commitmentsTable = new BigInteger[n][t + 1];
|
||||||
this.doneFlags = new boolean[n];
|
this.doneFlags = new boolean[n];
|
||||||
this.user = network.connect(messageHandler);
|
|
||||||
this.complaintsTable = new ComplainState[n][n];
|
this.complaintsTable = new ComplainState[n][n];
|
||||||
for (int i = 0; i < n; i++){
|
for (int i = 0; i < n; i++){
|
||||||
Arrays.fill(complaintsTable[i],ComplainState.Non);
|
Arrays.fill(complaintsTable[i],ComplainState.Non);
|
||||||
|
@ -212,75 +219,100 @@ public class DistributedKeyGenerationUserImpl implements DistributedKeyGeneratio
|
||||||
this.commitmentsCounter = 0;
|
this.commitmentsCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected boolean isValidComplaintMessage(int sender, boolean isBroadcast, DKGMessages.ComplaintMessage complaintMessage){
|
||||||
public void handelComplaintMessage(int sender, boolean isBroadcast, DKGMessages.ComplaintMessage complaintMessage) {
|
int i = sender;
|
||||||
if(isBroadcast) {
|
int j = complaintMessage.getId();
|
||||||
int i = sender - 1;
|
return isBroadcast && complaintsTable[i - 1][j - 1].equals( ComplainState.Non);
|
||||||
int j = complaintMessage.getId() - 1;
|
|
||||||
switch (complaintsTable[i][j]) {
|
|
||||||
case Non:
|
|
||||||
complaintsTable[i][j] = ComplainState.Waiting;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handelDoneMessage(int sender, boolean isBroadcast, DKGMessages.DoneMessage doneMessage) {
|
public void handelComplaintMessage(int sender, boolean isBroadcast, Message message) {
|
||||||
if(isBroadcast && !doneFlags[sender - 1]) {
|
DKGMessages.ComplaintMessage complaintMessage = (DKGMessages.ComplaintMessage)message;
|
||||||
|
if(isValidComplaintMessage(sender,isBroadcast,complaintMessage)){
|
||||||
|
int i = sender;
|
||||||
|
int j = complaintMessage.getId();
|
||||||
|
complaintsTable[i - 1][j - 1] = ComplainState.Waiting;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isValidDoneMessage(int sender, boolean isBroadcast){
|
||||||
|
return isBroadcast && !doneFlags[sender - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handelDoneMessage(int sender, boolean isBroadcast,Message message) {
|
||||||
|
if(isValidDoneMessage(sender,isBroadcast)) {
|
||||||
doneFlags[sender - 1] = true;
|
doneFlags[sender - 1] = true;
|
||||||
doneCounter++;
|
doneCounter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isValidCommitmentMessage(int sender, boolean isBroadcast, DKGMessages.CommitmentMessage commitmentMessage){
|
||||||
|
int i = sender - 1;
|
||||||
|
int k = commitmentMessage.getK();
|
||||||
|
return isBroadcast && commitmentsTable[i][k] == null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handelCommitmentMessage(int sender, boolean isBroadcast, DKGMessages.CommitmentMessage commitmentMessage) {
|
public void handelCommitmentMessage(int sender, boolean isBroadcast, Message message) {
|
||||||
if(isBroadcast){
|
DKGMessages.CommitmentMessage commitmentMessage = (DKGMessages.CommitmentMessage) message;
|
||||||
|
if(isValidCommitmentMessage(sender,isBroadcast,commitmentMessage)){
|
||||||
int i = sender - 1;
|
int i = sender - 1;
|
||||||
int k = commitmentMessage.getK();
|
int k = commitmentMessage.getK();
|
||||||
if(commitmentsTable[i][k] == null){
|
commitmentsTable[i][k] = extractCommitment(commitmentMessage);
|
||||||
commitmentsTable[i][k] = extractCommitment(commitmentMessage);
|
commitmentsCounter++;
|
||||||
commitmentsCounter++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isValidSecretMessage(int sender, boolean isBroadcast, DKGMessages.SecretMessage secretMessage){
|
||||||
|
int i = secretMessage.getI();
|
||||||
|
int j = secretMessage.getJ();
|
||||||
|
if(sender != i || isBroadcast)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return shares[i - 1] == null && j == id;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handelSecretMessage(int sender, boolean isBroadcast, DKGMessages.SecretMessage secretMessage) {
|
public void handelSecretMessage(int sender, boolean isBroadcast, Message message) {
|
||||||
Polynomial.Point secret = extractSecret(secretMessage);
|
DKGMessages.SecretMessage secretMessage = (DKGMessages.SecretMessage) message;
|
||||||
if(!isBroadcast){
|
if(isValidSecretMessage(sender,isBroadcast,secretMessage)) {
|
||||||
if(shares[sender - 1] == null) {
|
int i = secretMessage.getI();
|
||||||
shares[sender - 1] = secret;
|
Polynomial.Point secret = extractSecret(i,secretMessage.getSecret());
|
||||||
secretsCounter++;
|
shares[i - 1] = secret;
|
||||||
}
|
secretsCounter++;
|
||||||
}else {
|
|
||||||
int i = sender;
|
|
||||||
int j = secret.x.intValue();
|
|
||||||
switch (complaintsTable[i - 1][j - 1]){
|
|
||||||
case Waiting:
|
|
||||||
if(dkg.isValidSecret(secret,commitmentsTable[i - 1],j)){
|
|
||||||
complaintsTable[i - 1][j - 1] = ComplainState.NonDisqualified;
|
|
||||||
}else{
|
|
||||||
complaintsTable[i - 1][j - 1] = ComplainState.Disqualified;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isValidAnswerMessage(int sender, boolean isBroadcast, DKGMessages.SecretMessage secretMessage){
|
||||||
|
int i = secretMessage.getI();
|
||||||
|
int j = secretMessage.getJ();
|
||||||
|
if(sender != i || !isBroadcast)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return j >= 1 && j <= n && complaintsTable[i - 1][j - 1].equals(ComplainState.Waiting);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handelDoubleSecretMessage(int sender, boolean isBroadcast, DKGMessages.DoubleSecretMessage doubleSecretMessage) {
|
public void handelAnswerMessage(int sender, boolean isBroadcast, Message message) {
|
||||||
|
DKGMessages.SecretMessage secretMessage = (DKGMessages.SecretMessage) message;
|
||||||
|
if(isValidAnswerMessage(sender,isBroadcast,secretMessage)) {
|
||||||
|
int i = secretMessage.getI();
|
||||||
|
int j = secretMessage.getJ();
|
||||||
|
Polynomial.Point secret = extractSecret(i,secretMessage.getSecret());
|
||||||
|
if (dkg.isValidSecret(secret, commitmentsTable[i - 1], j))
|
||||||
|
complaintsTable[i - 1][j - 1] = ComplainState.NonDisqualified;
|
||||||
|
else
|
||||||
|
complaintsTable[i - 1][j - 1] = ComplainState.Disqualified;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Polynomial.Point extractSecret(DKGMessages.SecretMessage secretMessage){
|
public Polynomial.Point extractSecret(int i, ByteString secret){
|
||||||
return new Polynomial.Point(secretMessage.getSecret());
|
BigInteger x = BigInteger.valueOf(i);
|
||||||
|
BigInteger y = new BigInteger(secret.toByteArray());
|
||||||
|
return new Polynomial.Point(x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigInteger extractCommitment(DKGMessages.CommitmentMessage commitmentMessage){
|
public BigInteger extractCommitment(DKGMessages.CommitmentMessage commitmentMessage){
|
||||||
return new BigInteger(commitmentMessage.getCommitment().toByteArray());
|
return new BigInteger(commitmentMessage.getCommitment().toByteArray());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,138 +0,0 @@
|
||||||
package SecureDistributedKeyGeneration;
|
|
||||||
|
|
||||||
import Communication.Network;
|
|
||||||
import JointFeldmanProtocol.DistributedKeyGenerationUserImpl;
|
|
||||||
import ShamirSecretSharing.Polynomial;
|
|
||||||
import meerkat.protobuf.DKGMessages;
|
|
||||||
|
|
||||||
import java.math.BigInteger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Tzlil on 2/22/2016.
|
|
||||||
*/
|
|
||||||
public class SecureDistributedKeyGenerationUserImpl extends DistributedKeyGenerationUserImpl {
|
|
||||||
|
|
||||||
private final SecureDistributedKeyGeneration sdkg;
|
|
||||||
|
|
||||||
private final Polynomial.Point[] sharesT;
|
|
||||||
private final BigInteger[][] verificationValuesTable;
|
|
||||||
|
|
||||||
public SecureDistributedKeyGenerationUserImpl(SecureDistributedKeyGeneration sdkg, Network network) {
|
|
||||||
super(sdkg, network);
|
|
||||||
this.sdkg = sdkg;
|
|
||||||
this.sharesT = new Polynomial.Point[n];
|
|
||||||
this.verificationValuesTable = new BigInteger[n][t + 1];
|
|
||||||
this.messageHandler = new MessageHandler();
|
|
||||||
this.user.setMessageHandler(this.messageHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void stage1() {
|
|
||||||
sdkg.broadcastVerificationValues(user);
|
|
||||||
sdkg.sendSecrets(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void stage2(){
|
|
||||||
sdkg.setShares(shares);
|
|
||||||
sdkg.setSharesT(sharesT);
|
|
||||||
sdkg.broadcastComplains(user,verificationValuesTable);
|
|
||||||
//broadcast done message after all complaints
|
|
||||||
DKGMessages.DoneMessage doneMessage = DKGMessages.DoneMessage.newBuilder().build();
|
|
||||||
user.broadcast(DKGMessages.Mail.Type.DONE,doneMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ys(){
|
|
||||||
sdkg.broadcastCommitments(user);
|
|
||||||
//wait for receive all commitments from all i in QUAL
|
|
||||||
for (int i:QUAL) {
|
|
||||||
for(int k = 0; k <= t; k++) {
|
|
||||||
while (commitmentsTable[i - 1][k] == null) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(300);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sdkg.broadcastComplaints(user,commitmentsTable,true);
|
|
||||||
//do something with complaints' answers
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void stage4() {
|
|
||||||
ys();
|
|
||||||
super.stage4();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class MessageHandler extends DistributedKeyGenerationUserImpl.MessageHandler{
|
|
||||||
|
|
||||||
final int NumberOfCommitmentsInStage1 = n * (t + 1);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handelCommitmentMessage(int sender, boolean isBroadcast, DKGMessages.CommitmentMessage commitmentMessage) {
|
|
||||||
if(isBroadcast){
|
|
||||||
if(commitmentsCounter < NumberOfCommitmentsInStage1){
|
|
||||||
int i = sender - 1;
|
|
||||||
int k = commitmentMessage.getK();
|
|
||||||
if(verificationValuesTable[i][k] == null){
|
|
||||||
verificationValuesTable[i][k] = extractCommitment(commitmentMessage);
|
|
||||||
commitmentsCounter++;
|
|
||||||
}
|
|
||||||
} else{
|
|
||||||
super.handelCommitmentMessage(sender,isBroadcast,commitmentMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handelSecretMessage(int sender, boolean isBroadcast, DKGMessages.SecretMessage secretMessage) {
|
|
||||||
//there is no secret message in this protocol
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handelDoubleSecretMessage(int sender, boolean isBroadcast, DKGMessages.DoubleSecretMessage doubleSecretMessage) {
|
|
||||||
|
|
||||||
Polynomial.Point secret = extractSecret(doubleSecretMessage.getS1());
|
|
||||||
Polynomial.Point secretT = extractSecret(doubleSecretMessage.getS2());
|
|
||||||
if(!isBroadcast){
|
|
||||||
if(shares[sender - 1] == null) {
|
|
||||||
shares[sender - 1] = secret;
|
|
||||||
sharesT[sender - 1] = secretT;
|
|
||||||
secretsCounter++;
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
if(commitmentsCounter <= NumberOfCommitmentsInStage1) {
|
|
||||||
int i = sender;
|
|
||||||
int j = secret.x.intValue();
|
|
||||||
switch (complaintsTable[i - 1][j - 1]) {
|
|
||||||
case Waiting:
|
|
||||||
if (sdkg.isValidSecret(secret,secretT, verificationValuesTable[j - 1], i)) {
|
|
||||||
complaintsTable[i - 1][j - 1] = ComplainState.NonDisqualified;
|
|
||||||
} else {
|
|
||||||
complaintsTable[i - 1][j - 1] = ComplainState.Disqualified;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}else{ // stage4
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,5 @@
|
||||||
package SecureDistributedKeyGeneration;
|
package SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem;
|
||||||
|
|
||||||
import Communication.Network;
|
|
||||||
import Communication.User;
|
import Communication.User;
|
||||||
import FeldmanVerifiableSecretSharing.VerifiableSecretSharing;
|
import FeldmanVerifiableSecretSharing.VerifiableSecretSharing;
|
||||||
import JointFeldmanProtocol.DistributedKeyGeneration;
|
import JointFeldmanProtocol.DistributedKeyGeneration;
|
||||||
|
@ -8,7 +7,6 @@ import ShamirSecretSharing.Polynomial;
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import meerkat.protobuf.DKGMessages;
|
import meerkat.protobuf.DKGMessages;
|
||||||
import org.factcenter.qilin.primitives.Group;
|
import org.factcenter.qilin.primitives.Group;
|
||||||
import org.factcenter.qilin.primitives.concrete.Zpstar;
|
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -32,31 +30,34 @@ public class SecureDistributedKeyGeneration extends DistributedKeyGeneration {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendSecret(User user,int j) {
|
public void sendSecret(User user,int j) {
|
||||||
DKGMessages.SecretMessage.Point secret = getShare(j).asMessage();;
|
Polynomial.Point secret = getShare(j);
|
||||||
DKGMessages.SecretMessage.Point secretT = verifiableSecretSharing.getShare(j).asMessage();;
|
Polynomial.Point secretT = verifiableSecretSharing.getShare(j);
|
||||||
DKGMessages.DoubleSecretMessage doubleSecretMessage = DKGMessages.DoubleSecretMessage.newBuilder()
|
DKGMessages.DoubleSecretMessage doubleSecretMessage = doubleSecretMessage(id,j,secret,secretT);
|
||||||
.setS1(DKGMessages.SecretMessage.newBuilder().setSecret(secret).build())
|
user.send(j, DKGMessages.Mail.Type.SECRET, doubleSecretMessage);
|
||||||
.setS2(DKGMessages.SecretMessage.newBuilder().setSecret(secretT).build())
|
|
||||||
.build();
|
|
||||||
user.send(j, DKGMessages.Mail.Type.DOUBLE, doubleSecretMessage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidSecret(int j, BigInteger[] commitments, int i){
|
public boolean isValidSecret(int i, BigInteger[] commitments, int j){
|
||||||
Polynomial.Point secret = shares[j - 1];
|
Polynomial.Point secret = shares[i - 1];
|
||||||
Polynomial.Point secretT = sharesT[j - 1];
|
Polynomial.Point secretT = sharesT[i - 1];
|
||||||
return isValidSecret(secret,secretT,commitments,i);
|
return isValidSecret(secret,secretT,commitments, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValidSecret(Polynomial.Point secret,Polynomial.Point secretT, BigInteger[] verificationValues, int i){
|
public boolean isValidSecret(Polynomial.Point secret,Polynomial.Point secretT, BigInteger[] verificationValues, int j){
|
||||||
BigInteger v = verify(i,verificationValues,group);
|
BigInteger v = verify(j,verificationValues,group);
|
||||||
BigInteger exp = group.add(group.multiply(g, secret.y),group.multiply(h, secretT.y));
|
BigInteger exp = group.add(group.multiply(g, secret.y),group.multiply(h, secretT.y));
|
||||||
return exp.equals(v);
|
return exp.equals(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValidComplaint(Polynomial.Point secret,Polynomial.Point secretT, BigInteger[] commitments
|
|
||||||
,BigInteger[] verificationValues, int i){
|
public void broadcastComplaint(User user,Polynomial.Point secret,Polynomial.Point secretT,int i){
|
||||||
return isValidSecret(secret,secretT,verificationValues,i) && !isValidSecret(secret,commitments,i);
|
DKGMessages.DoubleSecretMessage complaint = doubleSecretMessage(i,id,secret,secretT);
|
||||||
|
user.broadcast(DKGMessages.Mail.Type.COMPLAINT,complaint);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void broadcastAnswer(User user,Polynomial.Point secret,Polynomial.Point secretT,int i){
|
||||||
|
DKGMessages.DoubleSecretMessage complaint = doubleSecretMessage(i,id,secret,secretT);
|
||||||
|
user.broadcast(DKGMessages.Mail.Type.ANSWER,complaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,10 +68,10 @@ public class SecureDistributedKeyGeneration extends DistributedKeyGeneration {
|
||||||
if(!stage4){
|
if(!stage4){
|
||||||
broadcastComplains(user,commitmentsTable);
|
broadcastComplains(user,commitmentsTable);
|
||||||
}else{
|
}else{
|
||||||
for (int j = 1; j <= n ; j++ ){
|
for (int i = 1; i <= n ; i++ ){
|
||||||
if(j != id) {
|
if(i != id) {
|
||||||
if (!isValidSecret(shares[j - 1],commitmentsTable[j - 1],id)) {
|
if (!isValidSecret(shares[i - 1],commitmentsTable[i - 1],id)) {
|
||||||
broadcastDoubleSecret(user,shares[j - 1],sharesT[j - 1]);
|
broadcastComplaint(user,shares[i - 1],sharesT[i - 1],i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,19 +88,21 @@ public class SecureDistributedKeyGeneration extends DistributedKeyGeneration {
|
||||||
broadcastCommitments(user,verificationValues);
|
broadcastCommitments(user,verificationValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void broadcastDoubleSecret(User user ,Polynomial.Point secret, Polynomial.Point secretT){
|
private DKGMessages.DoubleSecretMessage doubleSecretMessage(int i,int j,Polynomial.Point secret, Polynomial.Point secretT){
|
||||||
DKGMessages.SecretMessage.Point secretMessage = secret.asMessage();
|
|
||||||
DKGMessages.SecretMessage.Point secretTMessage = secretT.asMessage();
|
|
||||||
DKGMessages.DoubleSecretMessage doubleSecretMessage = DKGMessages.DoubleSecretMessage.newBuilder()
|
DKGMessages.DoubleSecretMessage doubleSecretMessage = DKGMessages.DoubleSecretMessage.newBuilder()
|
||||||
.setS1(DKGMessages.SecretMessage.newBuilder().setSecret(secretMessage).build())
|
.setI(i)
|
||||||
.setS1(DKGMessages.SecretMessage.newBuilder().setSecret(secretTMessage).build())
|
.setJ(j)
|
||||||
|
.setSecret(ByteString.copyFrom(secret.y.toByteArray()))
|
||||||
|
.setSecretT(ByteString.copyFrom(secretT.y.toByteArray()))
|
||||||
.build();
|
.build();
|
||||||
user.broadcast(DKGMessages.Mail.Type.DOUBLE, doubleSecretMessage);
|
return doubleSecretMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void broadcastComplaintAnswer(User user, int j) {
|
public void broadcastComplaintAnswer(User user, int j) {
|
||||||
broadcastDoubleSecret(user,getShare(j),verifiableSecretSharing.getShare(j));
|
DKGMessages.DoubleSecretMessage answer = doubleSecretMessage(id,j,getShare(j)
|
||||||
|
,verifiableSecretSharing.getShare(j));
|
||||||
|
user.broadcast(DKGMessages.Mail.Type.ANSWER,answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSharesT(Polynomial.Point[] sharesT) {
|
public void setSharesT(Polynomial.Point[] sharesT) {
|
|
@ -0,0 +1,60 @@
|
||||||
|
package SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem;
|
||||||
|
|
||||||
|
import Communication.MailHandler;
|
||||||
|
import Communication.MessageHandler;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.google.protobuf.Message;
|
||||||
|
import meerkat.protobuf.DKGMessages;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Tzlil on 2/29/2016.
|
||||||
|
*/
|
||||||
|
public class SecureDistributedKeyGenerationMailHandler extends MailHandler {
|
||||||
|
|
||||||
|
private boolean isStage4;
|
||||||
|
|
||||||
|
public SecureDistributedKeyGenerationMailHandler(MessageHandler messageHandler) {
|
||||||
|
super(messageHandler);
|
||||||
|
this.isStage4 = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Message extractMessage(DKGMessages.Mail mail) {
|
||||||
|
try {
|
||||||
|
Message message;
|
||||||
|
switch (mail.getType()) {
|
||||||
|
case SECRET:
|
||||||
|
message = DKGMessages.DoubleSecretMessage.parseFrom(mail.getMessage());
|
||||||
|
break;
|
||||||
|
case COMMITMENT:
|
||||||
|
message = DKGMessages.CommitmentMessage.parseFrom(mail.getMessage());
|
||||||
|
break;
|
||||||
|
case COMPLAINT:
|
||||||
|
if(isStage4)
|
||||||
|
message = DKGMessages.ComplaintMessage.parseFrom(mail.getMessage());
|
||||||
|
else
|
||||||
|
message = DKGMessages.DoubleSecretMessage.parseFrom(mail.getMessage());
|
||||||
|
break;
|
||||||
|
case DONE:
|
||||||
|
message = DKGMessages.DoneMessage.parseFrom(mail.getMessage());
|
||||||
|
break;
|
||||||
|
case ANSWER:
|
||||||
|
message = DKGMessages.DoubleSecretMessage.parseFrom(mail.getMessage());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
} catch (InvalidProtocolBufferException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isStage4() {
|
||||||
|
return isStage4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStage4(boolean stage4) {
|
||||||
|
isStage4 = stage4;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,247 @@
|
||||||
|
package SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem;
|
||||||
|
|
||||||
|
import Communication.Network;
|
||||||
|
import JointFeldmanProtocol.DistributedKeyGenerationUserImpl;
|
||||||
|
import ShamirSecretSharing.Polynomial;
|
||||||
|
import ShamirSecretSharing.SecretSharing;
|
||||||
|
import com.google.protobuf.Message;
|
||||||
|
import meerkat.protobuf.DKGMessages;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Tzlil on 2/22/2016.
|
||||||
|
*/
|
||||||
|
public class SecureDistributedKeyGenerationUserImpl extends DistributedKeyGenerationUserImpl {
|
||||||
|
|
||||||
|
private final SecureDistributedKeyGeneration sdkg;
|
||||||
|
private final Polynomial.Point[] sharesT;
|
||||||
|
private final BigInteger[][] verificationValuesTable;
|
||||||
|
private final Hashtable<Integer,Set<Polynomial.Point>> ysRestoreShares;
|
||||||
|
|
||||||
|
public SecureDistributedKeyGenerationUserImpl(SecureDistributedKeyGeneration sdkg, Network network) {
|
||||||
|
super(sdkg, network,new SecureDistributedKeyGenerationMailHandler(null));
|
||||||
|
this.sdkg = sdkg;
|
||||||
|
this.sharesT = new Polynomial.Point[n];
|
||||||
|
this.verificationValuesTable = new BigInteger[n][t + 1];
|
||||||
|
this.ysRestoreShares = new Hashtable<Integer, Set<Polynomial.Point>>();
|
||||||
|
this.messageHandler = new MessageHandler();
|
||||||
|
this.user.setMessageHandler(this.messageHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void stage1() {
|
||||||
|
sdkg.broadcastVerificationValues(user);
|
||||||
|
sdkg.sendSecrets(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void stage2(){
|
||||||
|
sdkg.setShares(shares);
|
||||||
|
sdkg.setSharesT(sharesT);
|
||||||
|
sdkg.broadcastComplains(user,verificationValuesTable);
|
||||||
|
//broadcast done message after all complaints
|
||||||
|
DKGMessages.DoneMessage doneMessage = DKGMessages.DoneMessage.newBuilder().build();
|
||||||
|
user.broadcast(DKGMessages.Mail.Type.DONE,doneMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ys(){
|
||||||
|
sdkg.broadcastCommitments(user);
|
||||||
|
//wait for receive all commitments from all i in QUAL
|
||||||
|
for (int i:QUAL) {
|
||||||
|
for(int k = 0; k <= t; k++) {
|
||||||
|
while (commitmentsTable[i - 1][k] == null) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(300);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sdkg.broadcastComplaints(user,commitmentsTable,true);
|
||||||
|
//broadcast done message after all complaints
|
||||||
|
DKGMessages.DoneMessage doneMessage = DKGMessages.DoneMessage.newBuilder().build();
|
||||||
|
user.broadcast(DKGMessages.Mail.Type.DONE,doneMessage);
|
||||||
|
|
||||||
|
for (int i:QUAL) {
|
||||||
|
while (doneFlags[i - 1]) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(300);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BigInteger secret;
|
||||||
|
for (Integer i: ysRestoreShares.keySet()) {
|
||||||
|
try {
|
||||||
|
secret = SecretSharing.restoreSecret((Polynomial.Point[])ysRestoreShares.get(i).toArray());
|
||||||
|
//ToDo use restored secret...
|
||||||
|
} catch (Exception e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void stage4() {
|
||||||
|
isStage4 = true;
|
||||||
|
((SecureDistributedKeyGenerationMailHandler)user.getMailHandler()).setStage4(true);
|
||||||
|
ys();
|
||||||
|
super.stage4();
|
||||||
|
}
|
||||||
|
boolean isStage4 = false;
|
||||||
|
private class MessageHandler extends DistributedKeyGenerationUserImpl.MessageHandler{
|
||||||
|
|
||||||
|
final int NumberOfCommitmentsInStage1 = n * (t + 1);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isValidCommitmentMessage(int sender, boolean isBroadcast, DKGMessages.CommitmentMessage commitmentMessage) {
|
||||||
|
if(commitmentsCounter < NumberOfCommitmentsInStage1) {
|
||||||
|
int i = sender - 1;
|
||||||
|
int k = commitmentMessage.getK();
|
||||||
|
return isBroadcast && verificationValuesTable[i][k] == null;
|
||||||
|
}else {
|
||||||
|
return super.isValidCommitmentMessage(sender, isBroadcast, commitmentMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handelCommitmentMessage(int sender, boolean isBroadcast, Message message) {
|
||||||
|
DKGMessages.CommitmentMessage commitmentMessage = ( DKGMessages.CommitmentMessage)message;
|
||||||
|
if(commitmentsCounter < NumberOfCommitmentsInStage1) {
|
||||||
|
if(isValidCommitmentMessage(sender,isBroadcast,commitmentMessage)) {
|
||||||
|
int i = sender - 1;
|
||||||
|
int k = commitmentMessage.getK();
|
||||||
|
verificationValuesTable[i][k] = extractCommitment(commitmentMessage);
|
||||||
|
commitmentsCounter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
super.handelCommitmentMessage(sender,isBroadcast,commitmentMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isValidSecretMessage(int sender, boolean isBroadcast, DKGMessages.DoubleSecretMessage doubleSecretMessage) {
|
||||||
|
DKGMessages.SecretMessage secretMessage = DKGMessages.SecretMessage.newBuilder()
|
||||||
|
.setI(doubleSecretMessage.getI())
|
||||||
|
.setJ(doubleSecretMessage.getJ())
|
||||||
|
.setSecret(doubleSecretMessage.getSecret())
|
||||||
|
.build();
|
||||||
|
return super.isValidSecretMessage(sender,isBroadcast,secretMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handelSecretMessage(int sender, boolean isBroadcast, Message message) {
|
||||||
|
DKGMessages.DoubleSecretMessage doubleSecretMessage = (DKGMessages.DoubleSecretMessage)message;
|
||||||
|
if (isValidSecretMessage(sender,isBroadcast,doubleSecretMessage)) {
|
||||||
|
int i = doubleSecretMessage.getI();
|
||||||
|
|
||||||
|
Polynomial.Point secret = extractSecret(i, doubleSecretMessage.getSecret());
|
||||||
|
Polynomial.Point secretT = extractSecret(i, doubleSecretMessage.getSecretT());
|
||||||
|
shares[i - 1] = secret;
|
||||||
|
sharesT[i - 1] = secretT;
|
||||||
|
secretsCounter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected boolean isValidAnswerMessage(int sender, boolean isBroadcast, DKGMessages.DoubleSecretMessage doubleSecretMessage) {
|
||||||
|
if(!isStage4) {
|
||||||
|
DKGMessages.SecretMessage secretMessage = DKGMessages.SecretMessage.newBuilder()
|
||||||
|
.setI(doubleSecretMessage.getI())
|
||||||
|
.setJ(doubleSecretMessage.getJ())
|
||||||
|
.setSecret(doubleSecretMessage.getSecret())
|
||||||
|
.build();
|
||||||
|
return super.isValidAnswerMessage(sender, isBroadcast, secretMessage);
|
||||||
|
}else{
|
||||||
|
int i = doubleSecretMessage.getI();
|
||||||
|
int j = doubleSecretMessage.getJ();
|
||||||
|
return isBroadcast && j == sender && QUAL.contains(i) && QUAL.contains(j)&& ysRestoreShares.containsKey(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handelAnswerMessage(int sender, boolean isBroadcast, Message message) {
|
||||||
|
DKGMessages.DoubleSecretMessage doubleSecretMessage = (DKGMessages.DoubleSecretMessage)message;
|
||||||
|
if(isValidAnswerMessage(sender,isBroadcast,doubleSecretMessage)) {
|
||||||
|
int i = doubleSecretMessage.getI();
|
||||||
|
int j = doubleSecretMessage.getJ();
|
||||||
|
Polynomial.Point secret = extractSecret(i, doubleSecretMessage.getSecret());
|
||||||
|
Polynomial.Point secretT = extractSecret(i, doubleSecretMessage.getSecretT());
|
||||||
|
if (!isStage4) {
|
||||||
|
if (sdkg.isValidSecret(secret, secretT, verificationValuesTable[j - 1], i)) {
|
||||||
|
complaintsTable[i - 1][j - 1] = ComplainState.NonDisqualified;
|
||||||
|
} else {
|
||||||
|
complaintsTable[i - 1][j - 1] = ComplainState.Disqualified;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (ysRestoreShares.get(i).add(secret) && sender != id) {
|
||||||
|
sdkg.broadcastAnswer(user, secret, secretT, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isValidDoneMessage(int sender, boolean isBroadcast) {
|
||||||
|
if(doneCounter < n) {
|
||||||
|
return super.isValidDoneMessage(sender, isBroadcast);
|
||||||
|
}else{
|
||||||
|
return isBroadcast && doneFlags[sender - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handelDoneMessage(int sender, boolean isBroadcast, Message message) {
|
||||||
|
if(doneCounter < n)
|
||||||
|
super.handelDoneMessage(sender, isBroadcast, message);
|
||||||
|
else{
|
||||||
|
if(isValidDoneMessage(sender,isBroadcast)) {
|
||||||
|
doneFlags[sender - 1] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isValidComplaintMessage(int sender, boolean isBroadcast,
|
||||||
|
DKGMessages.DoubleSecretMessage ysComplaintMessage){
|
||||||
|
int i = ysComplaintMessage.getI();
|
||||||
|
int j = ysComplaintMessage.getJ();
|
||||||
|
return isBroadcast && j == sender && QUAL.contains(i) && QUAL.contains(j)&&!ysRestoreShares.containsKey(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handelComplaintMessage(int sender, boolean isBroadcast, Message message) {
|
||||||
|
if(!isStage4) {
|
||||||
|
super.handelComplaintMessage(sender, isBroadcast, message);
|
||||||
|
}else {
|
||||||
|
DKGMessages.DoubleSecretMessage ysComplaintMessage =(DKGMessages.DoubleSecretMessage)message;
|
||||||
|
if (isValidComplaintMessage(sender,isBroadcast,ysComplaintMessage)) {
|
||||||
|
int i = ysComplaintMessage.getI();
|
||||||
|
int j = ysComplaintMessage.getJ();
|
||||||
|
Polynomial.Point secret = extractSecret(i,ysComplaintMessage.getSecret());
|
||||||
|
Polynomial.Point secretT = extractSecret(i,ysComplaintMessage.getSecretT());
|
||||||
|
if (sdkg.isValidSecret(secret, secretT, verificationValuesTable[i - 1], j)
|
||||||
|
&& !sdkg.isValidSecret(secret, commitmentsTable[i - 1], j)) {
|
||||||
|
ysRestoreShares.put(i, new HashSet<Polynomial.Point>());
|
||||||
|
ysRestoreShares.get(i).add(secret);
|
||||||
|
sdkg.broadcastAnswer(user, secret, secretT, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -199,15 +199,6 @@ public class Polynomial implements Comparable<Polynomial> {
|
||||||
this.y = polynomial.image(x);
|
this.y = polynomial.image(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* constructor - restore point from message
|
|
||||||
* @param pointMessage
|
|
||||||
*/
|
|
||||||
public Point(DKGMessages.SecretMessage.Point pointMessage) {
|
|
||||||
this.x = new BigInteger(pointMessage.getX().toByteArray());
|
|
||||||
this.y = new BigInteger(pointMessage.getY().toByteArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
* @param x
|
* @param x
|
||||||
|
@ -217,14 +208,6 @@ public class Polynomial implements Comparable<Polynomial> {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DKGMessages.SecretMessage.Point asMessage(){
|
|
||||||
return DKGMessages.SecretMessage.Point.newBuilder()
|
|
||||||
.setX(ByteString.copyFrom(x.toByteArray()))
|
|
||||||
.setY(ByteString.copyFrom(y.toByteArray()))
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class SecretSharing{
|
||||||
*
|
*
|
||||||
* @return image of interpolation(shares) at x = 0
|
* @return image of interpolation(shares) at x = 0
|
||||||
*/
|
*/
|
||||||
public static BigInteger restoreSecrete(Polynomial.Point[] shares) throws Exception {
|
public static BigInteger restoreSecret(Polynomial.Point[] shares) throws Exception {
|
||||||
Polynomial polynomial = Polynomial.interpolation(shares);
|
Polynomial polynomial = Polynomial.interpolation(shares);
|
||||||
return polynomial.image(BigInteger.ZERO);
|
return polynomial.image(BigInteger.ZERO);
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class DKGTest {
|
||||||
// index = indexes.remove(random.nextInt(indexes.size()));
|
// index = indexes.remove(random.nextInt(indexes.size()));
|
||||||
// shares[i] = dkgs[index - 1].getShare();
|
// shares[i] = dkgs[index - 1].getShare();
|
||||||
//}
|
//}
|
||||||
BigInteger calculatedSecret = SecretSharing.restoreSecrete(shares).mod(q);
|
BigInteger calculatedSecret = SecretSharing.restoreSecret(shares).mod(q);
|
||||||
assert (calculatedSecret.equals(secret));
|
assert (calculatedSecret.equals(secret));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import Communication.Network;
|
import Communication.Network;
|
||||||
import FeldmanVerifiableSecretSharing.VerifiableSecretSharing;
|
import FeldmanVerifiableSecretSharing.VerifiableSecretSharing;
|
||||||
import SecureDistributedKeyGeneration.SecureDistributedKeyGeneration;
|
import SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem.SecureDistributedKeyGeneration;
|
||||||
import SecureDistributedKeyGeneration.SecureDistributedKeyGenerationUserImpl;
|
import SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem.SecureDistributedKeyGenerationUserImpl;
|
||||||
import ShamirSecretSharing.Polynomial;
|
import ShamirSecretSharing.Polynomial;
|
||||||
import ShamirSecretSharing.SecretSharing;
|
import ShamirSecretSharing.SecretSharing;
|
||||||
import UserInterface.DistributedKeyGenerationUser;
|
import UserInterface.DistributedKeyGenerationUser;
|
||||||
|
@ -99,7 +99,7 @@ public class SDKGTest {
|
||||||
// index = indexes.remove(random.nextInt(indexes.size()));
|
// index = indexes.remove(random.nextInt(indexes.size()));
|
||||||
// shares[i] = dkgs[index - 1].getShare();
|
// shares[i] = dkgs[index - 1].getShare();
|
||||||
//}
|
//}
|
||||||
BigInteger calculatedSecret = SecretSharing.restoreSecrete(shares).mod(q);
|
BigInteger calculatedSecret = SecretSharing.restoreSecret(shares).mod(q);
|
||||||
assert (calculatedSecret.equals(secret));
|
assert (calculatedSecret.equals(secret));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package ShamirSecretSharing;
|
package ShamirSecretSharing;
|
||||||
|
|
||||||
import Communication.Network;
|
|
||||||
import org.factcenter.qilin.primitives.CyclicGroup;
|
import org.factcenter.qilin.primitives.CyclicGroup;
|
||||||
import org.factcenter.qilin.primitives.concrete.Zn;
|
import org.factcenter.qilin.primitives.concrete.Zn;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -50,7 +49,7 @@ public class SecretSharingTest {
|
||||||
for (int i = 0 ; i < shares.length ; i++){
|
for (int i = 0 ; i < shares.length ; i++){
|
||||||
shares[i] = secretSharing.getShare(indexes.remove(random.nextInt(indexes.size())));
|
shares[i] = secretSharing.getShare(indexes.remove(random.nextInt(indexes.size())));
|
||||||
}
|
}
|
||||||
assert(secret.equals(SecretSharing.restoreSecrete(shares)));
|
assert(secret.equals(SecretSharing.restoreSecret(shares)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -8,9 +8,12 @@ message Mail{
|
||||||
enum Type {
|
enum Type {
|
||||||
SECRET = 0;
|
SECRET = 0;
|
||||||
COMMITMENT = 1;
|
COMMITMENT = 1;
|
||||||
DONE = 2;
|
COMPLAINT = 2;
|
||||||
COMPLAINT = 3;
|
DONE = 3;
|
||||||
DOUBLE = 4;
|
ANSWER = 4;
|
||||||
|
YCOMMITMENT = 5;
|
||||||
|
YCOMPLAINT = 6;
|
||||||
|
YANSWER = 7;
|
||||||
}
|
}
|
||||||
int32 sender = 1;
|
int32 sender = 1;
|
||||||
int32 destination = 2;
|
int32 destination = 2;
|
||||||
|
@ -20,16 +23,16 @@ message Mail{
|
||||||
}
|
}
|
||||||
|
|
||||||
message SecretMessage {
|
message SecretMessage {
|
||||||
message Point{
|
int32 i = 1;
|
||||||
bytes x = 1;
|
int32 j = 2;
|
||||||
bytes y = 2;
|
bytes secret = 3;
|
||||||
}
|
|
||||||
Point secret = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message DoubleSecretMessage{
|
message DoubleSecretMessage{
|
||||||
SecretMessage s1 = 1;
|
int32 i = 1;
|
||||||
SecretMessage s2 = 2;
|
int32 j = 2;
|
||||||
|
bytes secret = 3;
|
||||||
|
bytes secretT = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CommitmentMessage{
|
message CommitmentMessage{
|
||||||
|
@ -41,4 +44,4 @@ message DoneMessage{}
|
||||||
|
|
||||||
message ComplaintMessage{
|
message ComplaintMessage{
|
||||||
int32 id = 1;
|
int32 id = 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue