redesigned mail handler
parent
0f7dbe3d50
commit
cc7e138a43
|
@ -1,50 +1,53 @@
|
|||
package Communication;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.google.protobuf.Message;
|
||||
import meerkat.protobuf.DKGMessages;
|
||||
|
||||
/**
|
||||
* Created by Tzlil on 2/14/2016.
|
||||
*/
|
||||
public class MailHandler {
|
||||
public abstract class MailHandler {
|
||||
|
||||
private MessageHandler messageHandler;
|
||||
public MailHandler(MessageHandler messageHandler){
|
||||
this.messageHandler = messageHandler;
|
||||
}
|
||||
|
||||
public abstract Message extractMessage(DKGMessages.Mail mail);
|
||||
|
||||
public void handel(DKGMessages.Mail mail) throws InvalidProtocolBufferException {
|
||||
switch (mail.getType()){
|
||||
public void handel(DKGMessages.Mail mail){
|
||||
|
||||
Message message = extractMessage(mail);
|
||||
if (message == null)
|
||||
return;
|
||||
|
||||
switch (mail.getType()) {
|
||||
case SECRET:
|
||||
DKGMessages.SecretMessage secretMessage = DKGMessages.SecretMessage.parseFrom(mail.getMessage());
|
||||
messageHandler.handelSecretMessage(mail.getSender(),mail.getDestination()== Network.BROADCAST,secretMessage);
|
||||
messageHandler.handelSecretMessage(mail.getSender(), mail.getDestination() == Network.BROADCAST
|
||||
, message);
|
||||
break;
|
||||
case COMMITMENT:
|
||||
DKGMessages.CommitmentMessage commitmentMessage = DKGMessages.CommitmentMessage.parseFrom(mail.getMessage());
|
||||
messageHandler.handelCommitmentMessage(mail.getSender(),mail.getDestination()== Network.BROADCAST,commitmentMessage);
|
||||
messageHandler.handelCommitmentMessage(mail.getSender(), mail.getDestination() == Network.BROADCAST
|
||||
, message);
|
||||
break;
|
||||
case DONE:
|
||||
DKGMessages.DoneMessage doneMessage = DKGMessages.DoneMessage.parseFrom(mail.getMessage());
|
||||
messageHandler.handelDoneMessage(mail.getSender(),mail.getDestination()== Network.BROADCAST,doneMessage);
|
||||
messageHandler.handelDoneMessage(mail.getSender(), mail.getDestination() == Network.BROADCAST
|
||||
, message);
|
||||
break;
|
||||
case COMPLAINT:
|
||||
DKGMessages.ComplaintMessage complaintMessage = DKGMessages.ComplaintMessage.parseFrom(mail.getMessage());
|
||||
messageHandler.handelComplaintMessage(mail.getSender(),mail.getDestination()== Network.BROADCAST,complaintMessage);
|
||||
messageHandler.handelComplaintMessage(mail.getSender(), mail.getDestination() == Network.BROADCAST
|
||||
, message);
|
||||
break;
|
||||
case DOUBLE:
|
||||
DKGMessages.DoubleSecretMessage doubleSecretMessage = DKGMessages.DoubleSecretMessage.parseFrom(mail.getMessage());
|
||||
messageHandler.handelDoubleSecretMessage(mail.getSender(),mail.getDestination()== Network.BROADCAST,doubleSecretMessage);
|
||||
case ANSWER:
|
||||
messageHandler.handelAnswerMessage(mail.getSender(), mail.getDestination() == Network.BROADCAST
|
||||
, message);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public MessageHandler getMessageHandler(){
|
||||
return messageHandler;
|
||||
}
|
||||
|
||||
public void setMessageHandler(MessageHandler messageHandler) {
|
||||
this.messageHandler = messageHandler;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package Communication;
|
||||
|
||||
import meerkat.protobuf.DKGMessages;
|
||||
import com.google.protobuf.Message;
|
||||
|
||||
/**
|
||||
* Created by Tzlil on 2/14/2016.
|
||||
*/
|
||||
public interface MessageHandler {
|
||||
void handelComplaintMessage(int sender, boolean isBroadcast,DKGMessages.ComplaintMessage complaintMessage);
|
||||
void handelDoneMessage(int sender, boolean isBroadcast, DKGMessages.DoneMessage doneMessage);
|
||||
void handelCommitmentMessage(int sender, boolean isBroadcast,DKGMessages.CommitmentMessage commitmentMessage);
|
||||
void handelSecretMessage(int sender, boolean isBroadcast,DKGMessages.SecretMessage secretMessage);
|
||||
void handelDoubleSecretMessage(int sender, boolean isBroadcast,DKGMessages.DoubleSecretMessage doubleSecretMessage);
|
||||
void handelSecretMessage(int sender, boolean isBroadcast, Message message);
|
||||
void handelCommitmentMessage(int sender, boolean isBroadcast, Message message);
|
||||
void handelComplaintMessage(int sender, boolean isBroadcast, Message message);
|
||||
void handelDoneMessage(int sender, boolean isBroadcast, Message message); //will be remove
|
||||
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();
|
||||
if (id == 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];
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,9 @@ public class User{
|
|||
public void broadcast(DKGMessages.Mail.Type type, Message message){
|
||||
network.sendBroadcast(this,type,message);
|
||||
}
|
||||
|
||||
public MailHandler getMailHandler(){
|
||||
return mailHandler;
|
||||
}
|
||||
public void setMessageHandler(MessageHandler messageHandler) {
|
||||
mailHandler.setMessageHandler(messageHandler);
|
||||
}
|
||||
|
@ -48,11 +50,7 @@ public class User{
|
|||
public void run() {
|
||||
while (true){
|
||||
if (!mailbox.isEmpty()){
|
||||
try {
|
||||
mailHandler.handel(mailbox.poll());
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mailHandler.handel(mailbox.poll());
|
||||
}else{
|
||||
try {
|
||||
Thread.sleep(30);
|
||||
|
|
|
@ -58,7 +58,7 @@ public class VerifiableSecretSharing extends SecretSharing {
|
|||
* @param commitments
|
||||
* @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) {
|
||||
BigInteger v = group.zero();
|
||||
|
|
|
@ -50,8 +50,13 @@ public class DistributedKeyGeneration extends VerifiableSecretSharing{
|
|||
}
|
||||
|
||||
public void sendSecret(User user, int j){
|
||||
SecretMessage.Point secret = getShare(j).asMessage();
|
||||
user.send(j, Mail.Type.DOUBLE,SecretMessage.newBuilder().setSecret(secret).build());
|
||||
ByteString secret = ByteString.copyFrom(getShare(j).y.toByteArray());
|
||||
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){
|
||||
Polynomial.Point secret = shares[j - 1];
|
||||
return isValidSecret(secret,commitments,i);
|
||||
public boolean isValidSecret(int i,BigInteger[] commitments,int j){
|
||||
Polynomial.Point secret = shares[i - 1];
|
||||
return isValidSecret(secret,commitments,j);
|
||||
}
|
||||
|
||||
public boolean isValidSecret(Polynomial.Point secret, BigInteger[] commitments, int i){
|
||||
BigInteger v = verify(i,commitments,group);
|
||||
public boolean isValidSecret(Polynomial.Point secret, BigInteger[] commitments, int j){
|
||||
BigInteger v = verify(j,commitments,group);
|
||||
return group.multiply(g,secret.y).equals(v);
|
||||
}
|
||||
|
||||
|
@ -83,12 +88,12 @@ public class DistributedKeyGeneration extends VerifiableSecretSharing{
|
|||
*/
|
||||
public void broadcastComplains(User user, BigInteger[][]commitmentsTable){
|
||||
ComplaintMessage complaint;
|
||||
for (int j = 1; j <= n ; j++ ){
|
||||
if(j != id) {
|
||||
if (!isValidSecret(j,commitmentsTable[j - 1],id)) {
|
||||
for (int i = 1; i <= n ; i++ ){
|
||||
if(i != id) {
|
||||
if (!isValidSecret(i,commitmentsTable[i - 1],id)) {
|
||||
//message = new Message(Type.Complaint, j)
|
||||
complaint = ComplaintMessage.newBuilder()
|
||||
.setId(j)
|
||||
.setId(i)
|
||||
.build();
|
||||
user.broadcast(Mail.Type.COMPLAINT, complaint);
|
||||
}
|
||||
|
@ -98,8 +103,10 @@ public class DistributedKeyGeneration extends VerifiableSecretSharing{
|
|||
|
||||
|
||||
public void broadcastComplaintAnswer(User user, int j){
|
||||
user.broadcast(Mail.Type.SECRET, SecretMessage.newBuilder()
|
||||
.setSecret(getShare(j).asMessage())
|
||||
user.broadcast(Mail.Type.ANSWER, SecretMessage.newBuilder()
|
||||
.setI(id)
|
||||
.setJ(j)
|
||||
.setSecret(ByteString.copyFrom(getShare(j).y.toByteArray()))
|
||||
.build());
|
||||
}
|
||||
|
||||
|
@ -108,10 +115,10 @@ public class DistributedKeyGeneration extends VerifiableSecretSharing{
|
|||
* if more than t players complain against a player Pi he is disqualified.
|
||||
*/
|
||||
public void answerAllComplainingPlayers(User user, DistributedKeyGenerationUserImpl.ComplainState[] complains){
|
||||
for (int j = 1; j <= n ; j++) {
|
||||
switch (complains[j - 1]) {
|
||||
for (int i = 1; i <= n ; i++) {
|
||||
switch (complains[i - 1]) {
|
||||
case Waiting:
|
||||
broadcastComplaintAnswer(user,j);
|
||||
broadcastComplaintAnswer(user,i);
|
||||
break;
|
||||
default:
|
||||
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;
|
||||
|
||||
import Communication.MailHandler;
|
||||
import Communication.Network;
|
||||
import Communication.User;
|
||||
import ShamirSecretSharing.Polynomial;
|
||||
import UserInterface.DistributedKeyGenerationUser;
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.Message;
|
||||
import meerkat.protobuf.DKGMessages;
|
||||
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 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.g = dkg.getGenerator();
|
||||
|
@ -49,11 +55,12 @@ public class DistributedKeyGenerationUserImpl implements DistributedKeyGeneratio
|
|||
this.id = dkg.getId();
|
||||
|
||||
this.messageHandler = new MessageHandler();
|
||||
mailHandler.setMessageHandler(this.messageHandler);
|
||||
this.user = network.connect(mailHandler);
|
||||
this.shares = new Polynomial.Point[n];
|
||||
this.shares[id - 1] = dkg.getShare(id);
|
||||
this.commitmentsTable = new BigInteger[n][t + 1];
|
||||
this.doneFlags = new boolean[n];
|
||||
this.user = network.connect(messageHandler);
|
||||
this.complaintsTable = new ComplainState[n][n];
|
||||
for (int i = 0; i < n; i++){
|
||||
Arrays.fill(complaintsTable[i],ComplainState.Non);
|
||||
|
@ -212,75 +219,100 @@ public class DistributedKeyGenerationUserImpl implements DistributedKeyGeneratio
|
|||
this.commitmentsCounter = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handelComplaintMessage(int sender, boolean isBroadcast, DKGMessages.ComplaintMessage complaintMessage) {
|
||||
if(isBroadcast) {
|
||||
int i = sender - 1;
|
||||
int j = complaintMessage.getId() - 1;
|
||||
switch (complaintsTable[i][j]) {
|
||||
case Non:
|
||||
complaintsTable[i][j] = ComplainState.Waiting;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
protected boolean isValidComplaintMessage(int sender, boolean isBroadcast, DKGMessages.ComplaintMessage complaintMessage){
|
||||
int i = sender;
|
||||
int j = complaintMessage.getId();
|
||||
return isBroadcast && complaintsTable[i - 1][j - 1].equals( ComplainState.Non);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handelDoneMessage(int sender, boolean isBroadcast, DKGMessages.DoneMessage doneMessage) {
|
||||
if(isBroadcast && !doneFlags[sender - 1]) {
|
||||
public void handelComplaintMessage(int sender, boolean isBroadcast, Message message) {
|
||||
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;
|
||||
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
|
||||
public void handelCommitmentMessage(int sender, boolean isBroadcast, DKGMessages.CommitmentMessage commitmentMessage) {
|
||||
if(isBroadcast){
|
||||
public void handelCommitmentMessage(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();
|
||||
if(commitmentsTable[i][k] == null){
|
||||
commitmentsTable[i][k] = extractCommitment(commitmentMessage);
|
||||
commitmentsCounter++;
|
||||
}
|
||||
commitmentsTable[i][k] = extractCommitment(commitmentMessage);
|
||||
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
|
||||
public void handelSecretMessage(int sender, boolean isBroadcast, DKGMessages.SecretMessage secretMessage) {
|
||||
Polynomial.Point secret = extractSecret(secretMessage);
|
||||
if(!isBroadcast){
|
||||
if(shares[sender - 1] == null) {
|
||||
shares[sender - 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;
|
||||
}
|
||||
public void handelSecretMessage(int sender, boolean isBroadcast, Message message) {
|
||||
DKGMessages.SecretMessage secretMessage = (DKGMessages.SecretMessage) message;
|
||||
if(isValidSecretMessage(sender,isBroadcast,secretMessage)) {
|
||||
int i = secretMessage.getI();
|
||||
Polynomial.Point secret = extractSecret(i,secretMessage.getSecret());
|
||||
shares[i - 1] = secret;
|
||||
secretsCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
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){
|
||||
return new Polynomial.Point(secretMessage.getSecret());
|
||||
public Polynomial.Point extractSecret(int i, ByteString secret){
|
||||
BigInteger x = BigInteger.valueOf(i);
|
||||
BigInteger y = new BigInteger(secret.toByteArray());
|
||||
return new Polynomial.Point(x,y);
|
||||
}
|
||||
|
||||
public BigInteger extractCommitment(DKGMessages.CommitmentMessage commitmentMessage){
|
||||
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 FeldmanVerifiableSecretSharing.VerifiableSecretSharing;
|
||||
import JointFeldmanProtocol.DistributedKeyGeneration;
|
||||
|
@ -8,7 +7,6 @@ import ShamirSecretSharing.Polynomial;
|
|||
import com.google.protobuf.ByteString;
|
||||
import meerkat.protobuf.DKGMessages;
|
||||
import org.factcenter.qilin.primitives.Group;
|
||||
import org.factcenter.qilin.primitives.concrete.Zpstar;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Random;
|
||||
|
@ -32,31 +30,34 @@ public class SecureDistributedKeyGeneration extends DistributedKeyGeneration {
|
|||
|
||||
@Override
|
||||
public void sendSecret(User user,int j) {
|
||||
DKGMessages.SecretMessage.Point secret = getShare(j).asMessage();;
|
||||
DKGMessages.SecretMessage.Point secretT = verifiableSecretSharing.getShare(j).asMessage();;
|
||||
DKGMessages.DoubleSecretMessage doubleSecretMessage = DKGMessages.DoubleSecretMessage.newBuilder()
|
||||
.setS1(DKGMessages.SecretMessage.newBuilder().setSecret(secret).build())
|
||||
.setS2(DKGMessages.SecretMessage.newBuilder().setSecret(secretT).build())
|
||||
.build();
|
||||
user.send(j, DKGMessages.Mail.Type.DOUBLE, doubleSecretMessage);
|
||||
Polynomial.Point secret = getShare(j);
|
||||
Polynomial.Point secretT = verifiableSecretSharing.getShare(j);
|
||||
DKGMessages.DoubleSecretMessage doubleSecretMessage = doubleSecretMessage(id,j,secret,secretT);
|
||||
user.send(j, DKGMessages.Mail.Type.SECRET, doubleSecretMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidSecret(int j, BigInteger[] commitments, int i){
|
||||
Polynomial.Point secret = shares[j - 1];
|
||||
Polynomial.Point secretT = sharesT[j - 1];
|
||||
return isValidSecret(secret,secretT,commitments,i);
|
||||
public boolean isValidSecret(int i, BigInteger[] commitments, int j){
|
||||
Polynomial.Point secret = shares[i - 1];
|
||||
Polynomial.Point secretT = sharesT[i - 1];
|
||||
return isValidSecret(secret,secretT,commitments, j);
|
||||
}
|
||||
|
||||
public boolean isValidSecret(Polynomial.Point secret,Polynomial.Point secretT, BigInteger[] verificationValues, int i){
|
||||
BigInteger v = verify(i,verificationValues,group);
|
||||
public boolean isValidSecret(Polynomial.Point secret,Polynomial.Point secretT, BigInteger[] verificationValues, int j){
|
||||
BigInteger v = verify(j,verificationValues,group);
|
||||
BigInteger exp = group.add(group.multiply(g, secret.y),group.multiply(h, secretT.y));
|
||||
return exp.equals(v);
|
||||
}
|
||||
|
||||
public boolean isValidComplaint(Polynomial.Point secret,Polynomial.Point secretT, BigInteger[] commitments
|
||||
,BigInteger[] verificationValues, int i){
|
||||
return isValidSecret(secret,secretT,verificationValues,i) && !isValidSecret(secret,commitments,i);
|
||||
|
||||
public void broadcastComplaint(User user,Polynomial.Point secret,Polynomial.Point secretT,int 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){
|
||||
broadcastComplains(user,commitmentsTable);
|
||||
}else{
|
||||
for (int j = 1; j <= n ; j++ ){
|
||||
if(j != id) {
|
||||
if (!isValidSecret(shares[j - 1],commitmentsTable[j - 1],id)) {
|
||||
broadcastDoubleSecret(user,shares[j - 1],sharesT[j - 1]);
|
||||
for (int i = 1; i <= n ; i++ ){
|
||||
if(i != id) {
|
||||
if (!isValidSecret(shares[i - 1],commitmentsTable[i - 1],id)) {
|
||||
broadcastComplaint(user,shares[i - 1],sharesT[i - 1],i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,19 +88,21 @@ public class SecureDistributedKeyGeneration extends DistributedKeyGeneration {
|
|||
broadcastCommitments(user,verificationValues);
|
||||
}
|
||||
|
||||
private void broadcastDoubleSecret(User user ,Polynomial.Point secret, Polynomial.Point secretT){
|
||||
DKGMessages.SecretMessage.Point secretMessage = secret.asMessage();
|
||||
DKGMessages.SecretMessage.Point secretTMessage = secretT.asMessage();
|
||||
private DKGMessages.DoubleSecretMessage doubleSecretMessage(int i,int j,Polynomial.Point secret, Polynomial.Point secretT){
|
||||
DKGMessages.DoubleSecretMessage doubleSecretMessage = DKGMessages.DoubleSecretMessage.newBuilder()
|
||||
.setS1(DKGMessages.SecretMessage.newBuilder().setSecret(secretMessage).build())
|
||||
.setS1(DKGMessages.SecretMessage.newBuilder().setSecret(secretTMessage).build())
|
||||
.setI(i)
|
||||
.setJ(j)
|
||||
.setSecret(ByteString.copyFrom(secret.y.toByteArray()))
|
||||
.setSecretT(ByteString.copyFrom(secretT.y.toByteArray()))
|
||||
.build();
|
||||
user.broadcast(DKGMessages.Mail.Type.DOUBLE, doubleSecretMessage);
|
||||
return doubleSecretMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
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) {
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param x
|
||||
|
@ -217,14 +208,6 @@ public class Polynomial implements Comparable<Polynomial> {
|
|||
this.x = x;
|
||||
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
|
||||
*/
|
||||
public static BigInteger restoreSecrete(Polynomial.Point[] shares) throws Exception {
|
||||
public static BigInteger restoreSecret(Polynomial.Point[] shares) throws Exception {
|
||||
Polynomial polynomial = Polynomial.interpolation(shares);
|
||||
return polynomial.image(BigInteger.ZERO);
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ public class DKGTest {
|
|||
// index = indexes.remove(random.nextInt(indexes.size()));
|
||||
// shares[i] = dkgs[index - 1].getShare();
|
||||
//}
|
||||
BigInteger calculatedSecret = SecretSharing.restoreSecrete(shares).mod(q);
|
||||
BigInteger calculatedSecret = SecretSharing.restoreSecret(shares).mod(q);
|
||||
assert (calculatedSecret.equals(secret));
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import Communication.Network;
|
||||
import FeldmanVerifiableSecretSharing.VerifiableSecretSharing;
|
||||
import SecureDistributedKeyGeneration.SecureDistributedKeyGeneration;
|
||||
import SecureDistributedKeyGeneration.SecureDistributedKeyGenerationUserImpl;
|
||||
import SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem.SecureDistributedKeyGeneration;
|
||||
import SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem.SecureDistributedKeyGenerationUserImpl;
|
||||
import ShamirSecretSharing.Polynomial;
|
||||
import ShamirSecretSharing.SecretSharing;
|
||||
import UserInterface.DistributedKeyGenerationUser;
|
||||
|
@ -99,7 +99,7 @@ public class SDKGTest {
|
|||
// index = indexes.remove(random.nextInt(indexes.size()));
|
||||
// shares[i] = dkgs[index - 1].getShare();
|
||||
//}
|
||||
BigInteger calculatedSecret = SecretSharing.restoreSecrete(shares).mod(q);
|
||||
BigInteger calculatedSecret = SecretSharing.restoreSecret(shares).mod(q);
|
||||
assert (calculatedSecret.equals(secret));
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package ShamirSecretSharing;
|
||||
|
||||
import Communication.Network;
|
||||
import org.factcenter.qilin.primitives.CyclicGroup;
|
||||
import org.factcenter.qilin.primitives.concrete.Zn;
|
||||
import org.junit.Before;
|
||||
|
@ -50,7 +49,7 @@ public class SecretSharingTest {
|
|||
for (int i = 0 ; i < shares.length ; i++){
|
||||
shares[i] = secretSharing.getShare(indexes.remove(random.nextInt(indexes.size())));
|
||||
}
|
||||
assert(secret.equals(SecretSharing.restoreSecrete(shares)));
|
||||
assert(secret.equals(SecretSharing.restoreSecret(shares)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -8,9 +8,12 @@ message Mail{
|
|||
enum Type {
|
||||
SECRET = 0;
|
||||
COMMITMENT = 1;
|
||||
DONE = 2;
|
||||
COMPLAINT = 3;
|
||||
DOUBLE = 4;
|
||||
COMPLAINT = 2;
|
||||
DONE = 3;
|
||||
ANSWER = 4;
|
||||
YCOMMITMENT = 5;
|
||||
YCOMPLAINT = 6;
|
||||
YANSWER = 7;
|
||||
}
|
||||
int32 sender = 1;
|
||||
int32 destination = 2;
|
||||
|
@ -20,16 +23,16 @@ message Mail{
|
|||
}
|
||||
|
||||
message SecretMessage {
|
||||
message Point{
|
||||
bytes x = 1;
|
||||
bytes y = 2;
|
||||
}
|
||||
Point secret = 1;
|
||||
int32 i = 1;
|
||||
int32 j = 2;
|
||||
bytes secret = 3;
|
||||
}
|
||||
|
||||
message DoubleSecretMessage{
|
||||
SecretMessage s1 = 1;
|
||||
SecretMessage s2 = 2;
|
||||
int32 i = 1;
|
||||
int32 j = 2;
|
||||
bytes secret = 3;
|
||||
bytes secretT = 4;
|
||||
}
|
||||
|
||||
message CommitmentMessage{
|
||||
|
|
Loading…
Reference in New Issue