generic group + wait instead of sleep
parent
4f608e813d
commit
0ae9719bc5
|
@ -1,28 +0,0 @@
|
||||||
package Communication;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A generic commmunication channel that supports point-to-point and broadcast operation
|
|
||||||
*/
|
|
||||||
//
|
|
||||||
//public interface Channel {
|
|
||||||
// public interface ReceiverCallback {
|
|
||||||
// public void receiveMessage(UserID fromUser, boolean isBroadcast, Message message);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void sendMessage(UserID destUser, Message msg);
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Block until a message is available (optional).
|
|
||||||
// * @return
|
|
||||||
// */
|
|
||||||
// public Message getNextMessageBlocking(long timeout);
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Register a callback to handle received messages.
|
|
||||||
// * The callback is called in the <b>Channel</b> thread, so no long processing should
|
|
||||||
// * occur in the callback method.
|
|
||||||
// * @param callback
|
|
||||||
// */
|
|
||||||
// public void registerReceiverCallback(ReceiverCallback callback);
|
|
||||||
//}
|
|
|
@ -1,75 +0,0 @@
|
||||||
package Communication;
|
|
||||||
|
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
|
||||||
import com.google.protobuf.Message;
|
|
||||||
import meerkat.protobuf.DKGMessages.*;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Queue;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ArrayBlockingQueue;
|
|
||||||
/**
|
|
||||||
* Created by Tzlil on 2/7/2016.
|
|
||||||
* Joint Feldamn protocol assumes all parties can communicate throw broadcast channel
|
|
||||||
* and private channel (for each pair)
|
|
||||||
* this class simulates it
|
|
||||||
*/
|
|
||||||
// TODO: Delete
|
|
||||||
// TODO: Move this implementation to tests
|
|
||||||
public class Network {
|
|
||||||
|
|
||||||
protected final User[] users;
|
|
||||||
protected final int n;
|
|
||||||
protected final Set<Integer> availableIDs;
|
|
||||||
public static final int BROADCAST = 0;
|
|
||||||
|
|
||||||
|
|
||||||
public Network(int n) {
|
|
||||||
this.n = n;
|
|
||||||
this.users = new User[n];
|
|
||||||
this.availableIDs = new HashSet<Integer>();
|
|
||||||
for (int id = 1; id <= n; id++){
|
|
||||||
availableIDs.add(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public User connect(MailHandler mailHandler,int id){
|
|
||||||
if (!availableIDs.contains(id))
|
|
||||||
return null;
|
|
||||||
availableIDs.remove(id);
|
|
||||||
users[id - 1] = new User(id,this,mailHandler);
|
|
||||||
return users[id - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean sendMessage(User sender,int destination,Mail.Type type,Message message){
|
|
||||||
if(destination < 1 || destination > n)
|
|
||||||
return false;
|
|
||||||
User user = users[destination - 1];
|
|
||||||
if (user == null)
|
|
||||||
return false;
|
|
||||||
Mail mail = Mail.newBuilder()
|
|
||||||
.setSender(sender.getID())
|
|
||||||
.setDestination(destination)
|
|
||||||
.setIsPrivate(true)
|
|
||||||
.setType(type)
|
|
||||||
.setMessage(message.toByteString())
|
|
||||||
.build();
|
|
||||||
return user.mailbox.add(mail);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void sendBroadcast(User sender,Mail.Type type,Message message){
|
|
||||||
User user;
|
|
||||||
Mail mail = Mail.newBuilder()
|
|
||||||
.setSender(sender.getID())
|
|
||||||
.setDestination(BROADCAST)
|
|
||||||
.setIsPrivate(false)
|
|
||||||
.setType(type)
|
|
||||||
.setMessage(message.toByteString())
|
|
||||||
.build();
|
|
||||||
for (int i = 0 ; i < n ; i++){
|
|
||||||
user = users[i];
|
|
||||||
user.mailbox.add(mail);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,74 +0,0 @@
|
||||||
package Communication;
|
|
||||||
|
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
|
||||||
import com.google.protobuf.Message;
|
|
||||||
import meerkat.protobuf.DKGMessages;
|
|
||||||
|
|
||||||
import java.util.Queue;
|
|
||||||
import java.util.concurrent.ArrayBlockingQueue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Tzlil on 2/14/2016.
|
|
||||||
*/
|
|
||||||
// TODO: Change nane to network
|
|
||||||
|
|
||||||
public class User{
|
|
||||||
/*
|
|
||||||
* My view of
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected final MailHandler mailHandler;
|
|
||||||
protected final Queue<DKGMessages.Mail> mailbox;
|
|
||||||
protected final int ID;
|
|
||||||
protected final Thread receiverThread;
|
|
||||||
private final Network network;
|
|
||||||
|
|
||||||
protected User(int ID, Network network, MailHandler mailHandler) {
|
|
||||||
this.mailbox = new ArrayBlockingQueue<DKGMessages.Mail>( network.n * network.n * network.n);
|
|
||||||
this.ID = ID;
|
|
||||||
this.mailHandler = mailHandler;
|
|
||||||
this.receiverThread = new Thread(new Receiver());
|
|
||||||
this.network = network;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean send(int id, DKGMessages.Mail.Type type, Message message){
|
|
||||||
return network.sendMessage(this,id,type,message);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getID() {
|
|
||||||
return ID;
|
|
||||||
}
|
|
||||||
public Thread getReceiverThread(){
|
|
||||||
return receiverThread;
|
|
||||||
}
|
|
||||||
private class Receiver implements Runnable{
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
while (true){
|
|
||||||
if (!mailbox.isEmpty()){
|
|
||||||
mailHandler.handel(mailbox.poll());
|
|
||||||
}else{
|
|
||||||
try {
|
|
||||||
Thread.sleep(30);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,102 +0,0 @@
|
||||||
package FeldmanVerifiableSecretSharing;
|
|
||||||
|
|
||||||
import ShamirSecretSharing.Polynomial;
|
|
||||||
import ShamirSecretSharing.SecretSharing;
|
|
||||||
|
|
||||||
import org.factcenter.qilin.primitives.Group;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Tzlil on 1/27/2016.
|
|
||||||
*
|
|
||||||
* an implementation of Feldman's verifiable secret sharing scheme.
|
|
||||||
*
|
|
||||||
* allows trusted dealer to share a key x among n parties.
|
|
||||||
*
|
|
||||||
* TODO: Add link to paper
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// TODO: Use Group<T> rather than fix to biginteger (allow using EC groups for better comm. complexity)
|
|
||||||
public class VerifiableSecretSharing extends SecretSharing {
|
|
||||||
protected final Group<BigInteger> group;
|
|
||||||
protected final BigInteger g; // public generator of group
|
|
||||||
protected final BigInteger[] commitmentsArray;
|
|
||||||
/**
|
|
||||||
* @param group
|
|
||||||
* @param q a large prime dividing group order.
|
|
||||||
* @param g a generator of cyclic group of order q.
|
|
||||||
* the generated group is a subgroup of the given group.
|
|
||||||
* it must be chosen such that computing discrete logarithms is hard in this group.
|
|
||||||
*/
|
|
||||||
public VerifiableSecretSharing(int t, int n, BigInteger x, Random random, BigInteger q, BigInteger g
|
|
||||||
, Group<BigInteger> group) {
|
|
||||||
super(t, n, x, random,q);
|
|
||||||
this.g = g;
|
|
||||||
this.group = group;
|
|
||||||
assert (this.group.contains(g));
|
|
||||||
this.commitmentsArray = generateCommitments();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: comment
|
|
||||||
* @return commitments[i] = g ^ polynomial.coefficients[i]
|
|
||||||
*/
|
|
||||||
private BigInteger[] generateCommitments() {
|
|
||||||
|
|
||||||
Polynomial polynomial = getPolynomial();
|
|
||||||
BigInteger[] coefficients = polynomial.getCoefficients();
|
|
||||||
BigInteger[] commitments = new BigInteger[coefficients.length];
|
|
||||||
for (int i = 0 ; i < commitments.length;i++){
|
|
||||||
commitments[i] = group.multiply(g,coefficients[i]);
|
|
||||||
}
|
|
||||||
return commitments;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compute verification value (g^{share value}) using coefficient commitments sent by dealer and my share id.
|
|
||||||
* @param j my share holder id
|
|
||||||
* @param commitments commitments to polynomial coefficients of share (received from dealer)
|
|
||||||
* @param group
|
|
||||||
*
|
|
||||||
* @return product of Aik ^ (j ^ k) == g ^ polynomial(i)
|
|
||||||
*/
|
|
||||||
public static BigInteger computeVerificationValue(int j, BigInteger[] commitments, Group<BigInteger> group) {
|
|
||||||
BigInteger v = group.zero();
|
|
||||||
BigInteger power = BigInteger.ONE;
|
|
||||||
BigInteger J = BigInteger.valueOf(j);
|
|
||||||
for (int k = 0 ; k < commitments.length ; k ++){
|
|
||||||
v = group.add(v,group.multiply(commitments[k],power));
|
|
||||||
power = power.multiply(J);
|
|
||||||
}
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Add verify method.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* getter
|
|
||||||
* @return generator of group
|
|
||||||
*/
|
|
||||||
public BigInteger getGenerator() {
|
|
||||||
return g;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* getter
|
|
||||||
* @return group
|
|
||||||
*/
|
|
||||||
public Group<BigInteger> getGroup(){
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* getter
|
|
||||||
* @return copy of commitmentsArray
|
|
||||||
*/
|
|
||||||
public BigInteger[] getCommitmentsArray() {
|
|
||||||
return Arrays.copyOf(commitmentsArray, commitmentsArray.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,141 +0,0 @@
|
||||||
package SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem;
|
|
||||||
|
|
||||||
import Communication.User;
|
|
||||||
import FeldmanVerifiableSecretSharing.VerifiableSecretSharing;
|
|
||||||
import JointFeldmanProtocol.DistributedKeyGeneration;
|
|
||||||
import ShamirSecretSharing.Polynomial;
|
|
||||||
import com.google.protobuf.ByteString;
|
|
||||||
import meerkat.protobuf.DKGMessages;
|
|
||||||
import org.factcenter.qilin.primitives.Group;
|
|
||||||
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Tzlil on 3/16/2016.
|
|
||||||
* TODO: comments
|
|
||||||
* TODO: put Channel (User) in constructor
|
|
||||||
*/
|
|
||||||
public class SecureDistributedKeyGeneration extends DistributedKeyGeneration {
|
|
||||||
|
|
||||||
private VerifiableSecretSharing maskingShares;
|
|
||||||
private final BigInteger h;
|
|
||||||
private SecureDistributedKeyGenerationParty[] parties;
|
|
||||||
|
|
||||||
public SecureDistributedKeyGeneration(int t, int n, BigInteger zi, Random random, BigInteger q, BigInteger g
|
|
||||||
, BigInteger h, Group<BigInteger> group, int id) {
|
|
||||||
super(t, n, zi, random, q, g, group, id);
|
|
||||||
this.h = h;
|
|
||||||
BigInteger r = new BigInteger(q.bitLength(),random).mod(q);
|
|
||||||
this.maskingShares = new VerifiableSecretSharing(t,n,r,random,q,h,group);
|
|
||||||
this.parties = new SecureDistributedKeyGenerationParty[n];
|
|
||||||
for (int i = 1; i <= n ; i++){
|
|
||||||
this.parties[i - 1] = new SecureDistributedKeyGenerationParty(i,n,t);
|
|
||||||
}
|
|
||||||
this.parties[id - 1].share = getShare(id);
|
|
||||||
this.parties[id - 1].shareT = maskingShares.getShare(id);
|
|
||||||
super.setParties(parties);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected SecureDistributedKeyGenerationParty[] getParties(){
|
|
||||||
return parties;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setParties(SecureDistributedKeyGenerationParty[] parties) {
|
|
||||||
super.setParties(parties);
|
|
||||||
this.parties = parties;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendSecret(User user, int j) {
|
|
||||||
Polynomial.Point secret = getShare(j);
|
|
||||||
Polynomial.Point secretT = maskingShares.getShare(j);
|
|
||||||
DKGMessages.DoubleSecretMessage doubleSecretMessage = doubleShareMessage(id,j,secret,secretT);
|
|
||||||
// TODO: Change SECRET to SHARE
|
|
||||||
user.send(j, DKGMessages.Mail.Type.SECRET, doubleSecretMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public boolean isValidShare(int i){
|
|
||||||
SecureDistributedKeyGenerationParty party = parties[i - 1];
|
|
||||||
return isValidShare(party.share, party.shareT, party.verifiableValues, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: comment
|
|
||||||
* @param share
|
|
||||||
* @param shareT
|
|
||||||
* @param verificationValues
|
|
||||||
* @param j
|
|
||||||
* @return computeVerificationValue(j,verificationValues,group) == (g ^ share.y) * (h ^ shareT.y) mod q
|
|
||||||
*/
|
|
||||||
public boolean isValidShare(Polynomial.Point share, Polynomial.Point shareT, BigInteger[] verificationValues, int j){
|
|
||||||
try {
|
|
||||||
BigInteger v = computeVerificationValue(j, verificationValues, group);
|
|
||||||
BigInteger exp = group.add(group.multiply(g, share.y), group.multiply(h, shareT.y));
|
|
||||||
return exp.equals(v);
|
|
||||||
}
|
|
||||||
catch (NullPointerException e){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: comment
|
|
||||||
private void broadcastComplaint(User user,Polynomial.Point share,Polynomial.Point shareT,int i){
|
|
||||||
DKGMessages.DoubleSecretMessage complaint = doubleShareMessage(i,id,share,shareT);
|
|
||||||
user.broadcast(DKGMessages.Mail.Type.COMPLAINT,complaint);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* stage4.3 according to the protocol
|
|
||||||
* if check fails for index i, Pj
|
|
||||||
*/
|
|
||||||
public void computeAndBroadcastComplaints(User user, Set<Integer> QUAL){
|
|
||||||
SecureDistributedKeyGenerationParty party;
|
|
||||||
for (int i : QUAL) {
|
|
||||||
party = parties[i - 1];
|
|
||||||
if (i != id) {
|
|
||||||
if (!super.isValidSecret(party.share, party.commitments, id)) {
|
|
||||||
broadcastComplaint(user, party.share, party.shareT, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void broadcastVerificationValues(User user){
|
|
||||||
BigInteger[] verificationValues = new BigInteger[t + 1];
|
|
||||||
BigInteger[] hBaseCommitments = maskingShares.getCommitmentsArray();
|
|
||||||
for (int k = 0 ; k < verificationValues.length ; k++){
|
|
||||||
verificationValues[k] = group.add(commitmentsArray[k],hBaseCommitments[k]);
|
|
||||||
}
|
|
||||||
broadcastCommitments(user,verificationValues);
|
|
||||||
}
|
|
||||||
|
|
||||||
private DKGMessages.DoubleSecretMessage doubleShareMessage(int i, int j, Polynomial.Point secret, Polynomial.Point secretT){
|
|
||||||
DKGMessages.DoubleSecretMessage doubleSecretMessage = DKGMessages.DoubleSecretMessage.newBuilder()
|
|
||||||
.setI(i)
|
|
||||||
.setJ(j)
|
|
||||||
.setSecret(ByteString.copyFrom(secret.y.toByteArray()))
|
|
||||||
.setSecretT(ByteString.copyFrom(secretT.y.toByteArray()))
|
|
||||||
.build();
|
|
||||||
return doubleSecretMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void broadcastComplaintAnswer(User user, int j) {
|
|
||||||
DKGMessages.DoubleSecretMessage answer = doubleShareMessage(id,j,getShare(j)
|
|
||||||
, maskingShares.getShare(j));
|
|
||||||
user.broadcast(DKGMessages.Mail.Type.ANSWER,answer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void broadcastAnswer(User user,Polynomial.Point secret,Polynomial.Point secretT,int i){
|
|
||||||
DKGMessages.DoubleSecretMessage complaint = doubleShareMessage(i,id,secret,secretT);
|
|
||||||
user.broadcast(DKGMessages.Mail.Type.ANSWER,complaint);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BigInteger getH() {
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
package SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem;
|
|
||||||
|
|
||||||
import JointFeldmanProtocol.DistributedKeyGenerationParty;
|
|
||||||
import ShamirSecretSharing.Polynomial;
|
|
||||||
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Tzlil on 3/16/2016.
|
|
||||||
*
|
|
||||||
* an extension of DistributedKeyGenerationParty
|
|
||||||
* contains all relevant information on specific party during
|
|
||||||
* the run of the safe protocol
|
|
||||||
*/
|
|
||||||
public class SecureDistributedKeyGenerationParty extends DistributedKeyGenerationParty {
|
|
||||||
public Polynomial.Point shareT;
|
|
||||||
public boolean ysDoneFlag;
|
|
||||||
public BigInteger[] verifiableValues;
|
|
||||||
public Set<Polynomial.Point> restoreSharesSet;
|
|
||||||
public SecureDistributedKeyGenerationParty(int id, int n, int t) {
|
|
||||||
super(id, n, t);
|
|
||||||
this.shareT = null;
|
|
||||||
this.ysDoneFlag = false;
|
|
||||||
this.verifiableValues = new BigInteger[t + 1];
|
|
||||||
this.restoreSharesSet = new HashSet<Polynomial.Point>();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
package UserInterface;
|
|
||||||
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Tzlil on 2/21/2016.
|
|
||||||
*/
|
|
||||||
public interface DistributedKeyGenerationUser extends VerifiableSecretSharingUser {
|
|
||||||
|
|
||||||
BigInteger getPublicValue();
|
|
||||||
Set<Integer> getQUAL();
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
package UserInterface;
|
|
||||||
|
|
||||||
import ShamirSecretSharing.Polynomial;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Tzlil on 2/21/2016.
|
|
||||||
*/
|
|
||||||
public interface SecretSharingUser extends Runnable {
|
|
||||||
|
|
||||||
Polynomial.Point getShare();
|
|
||||||
int getID();
|
|
||||||
int getN();
|
|
||||||
int getT();
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package UserInterface;
|
|
||||||
|
|
||||||
import UserInterface.SecretSharingUser;
|
|
||||||
import org.factcenter.qilin.primitives.Group;
|
|
||||||
|
|
||||||
import java.math.BigInteger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Tzlil on 2/21/2016.
|
|
||||||
*/
|
|
||||||
public interface VerifiableSecretSharingUser extends SecretSharingUser {
|
|
||||||
|
|
||||||
BigInteger[] getCommitments();
|
|
||||||
BigInteger getGenerator();
|
|
||||||
Group<BigInteger> getGroup();
|
|
||||||
}
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package meerkat.crypto;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Tzlil on 4/8/2016.
|
||||||
|
*/
|
||||||
|
public interface KeyGeneration<T> {
|
||||||
|
|
||||||
|
T generateKey(Random random);
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package meerkat.crypto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Tzlil on 4/8/2016.
|
||||||
|
*/
|
||||||
|
public class SecretSharing {
|
||||||
|
}
|
|
@ -0,0 +1,108 @@
|
||||||
|
package meerkat.crypto.concrete.distributed_key_generation.Communication;
|
||||||
|
|
||||||
|
import com.google.protobuf.Message;
|
||||||
|
import meerkat.crypto.utilitis.Channel;
|
||||||
|
import meerkat.protobuf.DKGMessages;
|
||||||
|
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Tzlil on 2/14/2016.
|
||||||
|
*/
|
||||||
|
// TODO: Change nane to network
|
||||||
|
|
||||||
|
public class ChannelImpl implements Channel {
|
||||||
|
|
||||||
|
public static int BROADCAST = 0;
|
||||||
|
private static ChannelImpl[] channels = null;
|
||||||
|
|
||||||
|
protected final Queue<DKGMessages.Mail> mailbox;
|
||||||
|
protected final int id;
|
||||||
|
protected final int n;
|
||||||
|
protected Thread receiverThread;
|
||||||
|
|
||||||
|
|
||||||
|
public ChannelImpl(int id, int n) {
|
||||||
|
if (channels == null){
|
||||||
|
channels = new ChannelImpl[n];
|
||||||
|
}
|
||||||
|
this.mailbox = new ArrayBlockingQueue<DKGMessages.Mail>( n * n * n);
|
||||||
|
this.id = id;
|
||||||
|
this.n = n;
|
||||||
|
channels[id - 1] = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(int destUser, DKGMessages.Mail.Type type, Message msg) {
|
||||||
|
if(destUser < 1 || destUser > n)
|
||||||
|
return;
|
||||||
|
ChannelImpl channel = channels[destUser - 1];
|
||||||
|
if (channel == null)
|
||||||
|
return;
|
||||||
|
DKGMessages.Mail mail = DKGMessages.Mail.newBuilder()
|
||||||
|
.setSender(id)
|
||||||
|
.setDestination(destUser)
|
||||||
|
.setIsPrivate(true)
|
||||||
|
.setType(type)
|
||||||
|
.setMessage(msg.toByteString())
|
||||||
|
.build();
|
||||||
|
synchronized (channel.mailbox) {
|
||||||
|
channel.mailbox.add(mail);
|
||||||
|
channel.mailbox.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void broadcastMessage(DKGMessages.Mail.Type type,Message msg) {
|
||||||
|
ChannelImpl channel;
|
||||||
|
DKGMessages.Mail mail = DKGMessages.Mail.newBuilder()
|
||||||
|
.setSender(id)
|
||||||
|
.setDestination(BROADCAST)
|
||||||
|
.setIsPrivate(false)
|
||||||
|
.setType(type)
|
||||||
|
.setMessage(msg.toByteString())
|
||||||
|
.build();
|
||||||
|
for (int i = 0 ; i < n ; i++){
|
||||||
|
channel = channels[i];
|
||||||
|
synchronized (channel.mailbox) {
|
||||||
|
channel.mailbox.add(mail);
|
||||||
|
channel.mailbox.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerReceiverCallback(final ReceiverCallback callback) {
|
||||||
|
try{
|
||||||
|
receiverThread.interrupt();
|
||||||
|
}catch (Exception e){
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
|
receiverThread = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
while (true){
|
||||||
|
try {
|
||||||
|
synchronized (mailbox) {
|
||||||
|
while (!mailbox.isEmpty()) {
|
||||||
|
callback.receiveMail(mailbox.remove());
|
||||||
|
}
|
||||||
|
mailbox.wait();
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
receiverThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,12 +1,13 @@
|
||||||
package Communication;
|
package meerkat.crypto.concrete.distributed_key_generation.Communication;
|
||||||
|
|
||||||
import com.google.protobuf.Message;
|
import com.google.protobuf.Message;
|
||||||
|
import meerkat.crypto.utilitis.Channel;
|
||||||
import meerkat.protobuf.DKGMessages;
|
import meerkat.protobuf.DKGMessages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Tzlil on 2/14/2016.
|
* Created by Tzlil on 2/14/2016.
|
||||||
*/
|
*/
|
||||||
public abstract class MailHandler {
|
public abstract class MailHandler implements Channel.ReceiverCallback{
|
||||||
|
|
||||||
private MessageHandler messageHandler;
|
private MessageHandler messageHandler;
|
||||||
public MailHandler(MessageHandler messageHandler){
|
public MailHandler(MessageHandler messageHandler){
|
||||||
|
@ -15,35 +16,35 @@ public abstract class MailHandler {
|
||||||
|
|
||||||
public abstract Message extractMessage(DKGMessages.Mail mail);
|
public abstract Message extractMessage(DKGMessages.Mail mail);
|
||||||
|
|
||||||
public void handel(DKGMessages.Mail mail){
|
public void receiveMail(DKGMessages.Mail mail){
|
||||||
|
|
||||||
Message message = extractMessage(mail);
|
Message message = extractMessage(mail);
|
||||||
if (message == null)
|
if (message == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch (mail.getType()) {
|
switch (mail.getType()) {
|
||||||
case SECRET:
|
case SHARE:
|
||||||
messageHandler.handleSecretMessage(mail.getSender(), mail.getDestination() == Network.BROADCAST
|
messageHandler.handleSecretMessage(mail.getSender(), mail.getDestination() == ChannelImpl.BROADCAST
|
||||||
, message);
|
, message);
|
||||||
break;
|
break;
|
||||||
case COMMITMENT:
|
case COMMITMENT:
|
||||||
messageHandler.handleCommitmentMessage(mail.getSender(), mail.getDestination() == Network.BROADCAST
|
messageHandler.handleCommitmentMessage(mail.getSender(), mail.getDestination() == ChannelImpl.BROADCAST
|
||||||
, message);
|
, message);
|
||||||
break;
|
break;
|
||||||
case DONE:
|
case DONE:
|
||||||
messageHandler.handleDoneMessage(mail.getSender(), mail.getDestination() == Network.BROADCAST
|
messageHandler.handleDoneMessage(mail.getSender(), mail.getDestination() == ChannelImpl.BROADCAST
|
||||||
, message);
|
, message);
|
||||||
break;
|
break;
|
||||||
case COMPLAINT:
|
case COMPLAINT:
|
||||||
messageHandler.handleComplaintMessage(mail.getSender(), mail.getDestination() == Network.BROADCAST
|
messageHandler.handleComplaintMessage(mail.getSender(), mail.getDestination() == ChannelImpl.BROADCAST
|
||||||
, message);
|
, message);
|
||||||
break;
|
break;
|
||||||
case ANSWER:
|
case ANSWER:
|
||||||
messageHandler.handleAnswerMessage(mail.getSender(), mail.getDestination() == Network.BROADCAST
|
messageHandler.handleAnswerMessage(mail.getSender(), mail.getDestination() == ChannelImpl.BROADCAST
|
||||||
, message);
|
, message);
|
||||||
break;
|
break;
|
||||||
case ABORT:
|
case ABORT:
|
||||||
messageHandler.handleAbortMessage(mail.getSender(), mail.getDestination() == Network.BROADCAST
|
messageHandler.handleAbortMessage(mail.getSender(), mail.getDestination() == ChannelImpl.BROADCAST
|
||||||
, message);
|
, message);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -52,7 +53,4 @@ public abstract class MailHandler {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public void setMessageHandler(MessageHandler messageHandler) {
|
|
||||||
this.messageHandler = messageHandler;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package Communication;
|
package meerkat.crypto.concrete.distributed_key_generation.Communication;
|
||||||
|
|
||||||
import com.google.protobuf.Message;
|
import com.google.protobuf.Message;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem;
|
package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol;
|
||||||
|
|
||||||
import Communication.MailHandler;
|
import Communication.MailHandler;
|
||||||
import Communication.MessageHandler;
|
import Communication.MessageHandler;
|
||||||
|
@ -9,11 +9,11 @@ import meerkat.protobuf.DKGMessages;
|
||||||
/**
|
/**
|
||||||
* Created by Tzlil on 2/29/2016.
|
* Created by Tzlil on 2/29/2016.
|
||||||
*/
|
*/
|
||||||
public class SecureDistributedKeyGenerationMailHandler extends MailHandler {
|
public class MailHandler extends Communication.MailHandler {
|
||||||
|
|
||||||
private boolean isStage4;
|
private boolean isStage4;
|
||||||
|
|
||||||
public SecureDistributedKeyGenerationMailHandler(MessageHandler messageHandler) {
|
public MailHandler(MessageHandler messageHandler) {
|
||||||
super(messageHandler);
|
super(messageHandler);
|
||||||
this.isStage4 = false;
|
this.isStage4 = false;
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,8 @@ public class SecureDistributedKeyGenerationMailHandler extends MailHandler {
|
||||||
try {
|
try {
|
||||||
Message message;
|
Message message;
|
||||||
switch (mail.getType()) {
|
switch (mail.getType()) {
|
||||||
case SECRET:
|
case SHARE:
|
||||||
message = DKGMessages.DoubleSecretMessage.parseFrom(mail.getMessage());
|
message = DKGMessages.DoubleShareMessage.parseFrom(mail.getMessage());
|
||||||
break;
|
break;
|
||||||
case COMMITMENT:
|
case COMMITMENT:
|
||||||
message = DKGMessages.CommitmentMessage.parseFrom(mail.getMessage());
|
message = DKGMessages.CommitmentMessage.parseFrom(mail.getMessage());
|
||||||
|
@ -33,13 +33,13 @@ public class SecureDistributedKeyGenerationMailHandler extends MailHandler {
|
||||||
if(!isStage4)
|
if(!isStage4)
|
||||||
message = DKGMessages.IDMessage.parseFrom(mail.getMessage());
|
message = DKGMessages.IDMessage.parseFrom(mail.getMessage());
|
||||||
else
|
else
|
||||||
message = DKGMessages.DoubleSecretMessage.parseFrom(mail.getMessage());
|
message = DKGMessages.DoubleShareMessage.parseFrom(mail.getMessage());
|
||||||
break;
|
break;
|
||||||
case DONE:
|
case DONE:
|
||||||
message = DKGMessages.EmptyMessage.parseFrom(mail.getMessage());
|
message = DKGMessages.EmptyMessage.parseFrom(mail.getMessage());
|
||||||
break;
|
break;
|
||||||
case ANSWER:
|
case ANSWER:
|
||||||
message = DKGMessages.DoubleSecretMessage.parseFrom(mail.getMessage());
|
message = DKGMessages.DoubleShareMessage.parseFrom(mail.getMessage());
|
||||||
break;
|
break;
|
||||||
case ABORT:
|
case ABORT:
|
||||||
message = DKGMessages.EmptyMessage.parseFrom(mail.getMessage());
|
message = DKGMessages.EmptyMessage.parseFrom(mail.getMessage());
|
|
@ -0,0 +1,29 @@
|
||||||
|
package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol;
|
||||||
|
|
||||||
|
import meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.DistributedKeyGenerationParty;
|
||||||
|
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Tzlil on 3/16/2016.
|
||||||
|
*
|
||||||
|
* an extension of DistributedKeyGenerationParty
|
||||||
|
* contains all relevant information on specific party during
|
||||||
|
* the run of the safe protocol
|
||||||
|
*/
|
||||||
|
public class Party<T> extends DistributedKeyGenerationParty<T> {
|
||||||
|
public Polynomial.Point shareT;
|
||||||
|
public boolean ysDoneFlag;
|
||||||
|
public ArrayList<T> verifiableValues;
|
||||||
|
public Set<Polynomial.Point> recoverSharesSet;
|
||||||
|
public Party(int id, int n, int t) {
|
||||||
|
super(id, n, t);
|
||||||
|
this.shareT = null;
|
||||||
|
this.ysDoneFlag = false;
|
||||||
|
this.verifiableValues = new ArrayList<T>(this.commitments);
|
||||||
|
this.recoverSharesSet = new HashSet<Polynomial.Point>();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,165 @@
|
||||||
|
package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol;
|
||||||
|
|
||||||
|
import meerkat.crypto.concrete.secret_shring.feldman_verifiable.VerifiableSecretSharing;
|
||||||
|
import meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.Protocol;
|
||||||
|
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import meerkat.protobuf.DKGMessages;
|
||||||
|
import org.factcenter.qilin.primitives.Group;
|
||||||
|
import org.factcenter.qilin.util.ByteEncoder;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Tzlil on 3/16/2016.
|
||||||
|
* TODO: comments
|
||||||
|
* TODO: put Channel (ChannelImpl) in constructor
|
||||||
|
*/
|
||||||
|
public class Protocol<T> extends meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.Protocol<T> {
|
||||||
|
|
||||||
|
private VerifiableSecretSharing<T> maskingShares;
|
||||||
|
private final T h;
|
||||||
|
private Party<T>[] parties;
|
||||||
|
|
||||||
|
public Protocol(int t, int n, BigInteger zi, Random random, BigInteger q, T g
|
||||||
|
, T h, Group<T> group, int id, ByteEncoder<T> byteEncoder) {
|
||||||
|
super(t, n, zi, random, q, g, group, id,byteEncoder);
|
||||||
|
this.h = h;
|
||||||
|
BigInteger r = new BigInteger(q.bitLength(),random).mod(q);
|
||||||
|
this.maskingShares = new VerifiableSecretSharing(t,n,r,random,q,h,group);
|
||||||
|
this.parties = new Party[n];
|
||||||
|
for (int i = 1; i <= n ; i++){
|
||||||
|
this.parties[i - 1] = new Party(i,n,t);
|
||||||
|
}
|
||||||
|
this.parties[id - 1].share = getShare(id);
|
||||||
|
this.parties[id - 1].shareT = maskingShares.getShare(id);
|
||||||
|
super.setParties(parties);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Party[] getParties(){
|
||||||
|
return parties;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setParties(Party[] parties) {
|
||||||
|
super.setParties(parties);
|
||||||
|
this.parties = parties;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendSecret(int j) {
|
||||||
|
Polynomial.Point secret = getShare(j);
|
||||||
|
Polynomial.Point secretT = maskingShares.getShare(j);
|
||||||
|
DKGMessages.DoubleShareMessage doubleSecretMessage = doubleShareMessage(id,j,secret,secretT);
|
||||||
|
// TODO: Change SHARE to SHARE
|
||||||
|
channel.sendMessage(j, DKGMessages.Mail.Type.SHARE, doubleSecretMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValidShare(int i){
|
||||||
|
Party party = parties[i - 1];
|
||||||
|
return isValidShare(party.share, party.shareT, party.verifiableValues, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if share, shareT are valid with respect to verificationValues
|
||||||
|
* @param share
|
||||||
|
* @param shareT
|
||||||
|
* @param verificationValues
|
||||||
|
* @param j
|
||||||
|
* @return computeVerificationValue(j,verificationValues,group) == (g ^ share.y) * (h ^ shareT.y) mod q
|
||||||
|
*/
|
||||||
|
public boolean isValidShare(Polynomial.Point share, Polynomial.Point shareT, ArrayList<T> verificationValues, int j){
|
||||||
|
try {
|
||||||
|
T v = computeVerificationValue(j, verificationValues, group);
|
||||||
|
T exp = group.add(group.multiply(g, share.y), group.multiply(h, shareT.y));
|
||||||
|
return exp.equals(v);
|
||||||
|
}
|
||||||
|
catch (NullPointerException e){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create complaint message against i and broadcast it
|
||||||
|
* @param share
|
||||||
|
* @param shareT
|
||||||
|
* @param i
|
||||||
|
*/
|
||||||
|
private void broadcastComplaint(Polynomial.Point share, Polynomial.Point shareT, int i){
|
||||||
|
DKGMessages.DoubleShareMessage complaint = doubleShareMessage(i,id,share,shareT);
|
||||||
|
channel.broadcastMessage(DKGMessages.Mail.Type.COMPLAINT,complaint);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stage4.3 according to the protocol
|
||||||
|
* if check fails for index i, Pj
|
||||||
|
*/
|
||||||
|
public void computeAndBroadcastComplaints(Set<Integer> QUAL){
|
||||||
|
Party party;
|
||||||
|
for (int i : QUAL) {
|
||||||
|
party = parties[i - 1];
|
||||||
|
if (i != id) {
|
||||||
|
if (!super.isValidShare(party.share, party.commitments, id)) {
|
||||||
|
broadcastComplaint(party.share, party.shareT, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* compute verification values and broadcast them
|
||||||
|
* verificationValues[k] = g ^ commitments [k] * h ^ maskingShares.commitments [k]
|
||||||
|
*/
|
||||||
|
public void computeAndBroadcastVerificationValues(){
|
||||||
|
ArrayList<T> verificationValues = new ArrayList<T>(t+1);
|
||||||
|
ArrayList<T> hBaseCommitments = maskingShares.getCommitmentsArrayList();
|
||||||
|
for (int k = 0 ; k <= t ; k++){
|
||||||
|
verificationValues.add(k,group.add(commitmentsArrayList.get(k),hBaseCommitments.get(k)));
|
||||||
|
}
|
||||||
|
broadcastCommitments(verificationValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pack share, shareT i,j to doubleShareMessage
|
||||||
|
* @param i
|
||||||
|
* @param j
|
||||||
|
* @param share
|
||||||
|
* @param shareT
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
private DKGMessages.DoubleShareMessage doubleShareMessage(int i, int j, Polynomial.Point share, Polynomial.Point shareT){
|
||||||
|
DKGMessages.DoubleShareMessage doubleShareMessage = DKGMessages.DoubleShareMessage.newBuilder()
|
||||||
|
.setI(i)
|
||||||
|
.setJ(j)
|
||||||
|
.setSecret(ByteString.copyFrom(share.y.toByteArray()))
|
||||||
|
.setSecretT(ByteString.copyFrom(shareT.y.toByteArray()))
|
||||||
|
.build();
|
||||||
|
return doubleShareMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void broadcastComplaintAnswer(int j) {
|
||||||
|
DKGMessages.DoubleShareMessage answer = doubleShareMessage(id,j,getShare(j)
|
||||||
|
, maskingShares.getShare(j));
|
||||||
|
channel.broadcastMessage(DKGMessages.Mail.Type.ANSWER,answer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void broadcastAnswer(Polynomial.Point secret, Polynomial.Point secretT, int i){
|
||||||
|
DKGMessages.DoubleShareMessage complaint = doubleShareMessage(i,id,secret,secretT);
|
||||||
|
channel.broadcastMessage(DKGMessages.Mail.Type.ANSWER,complaint);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter
|
||||||
|
* @return h
|
||||||
|
*/
|
||||||
|
public T getH() {
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,37 +1,40 @@
|
||||||
package SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem;
|
package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol;
|
||||||
|
|
||||||
import Arithmetics.Arithmetic;
|
import meerkat.crypto.utilitis.Arithmetic;
|
||||||
import Arithmetics.Fp;
|
import meerkat.crypto.utilitis.concrete.Fp;
|
||||||
import Communication.Network;
|
import meerkat.crypto.utilitis.Channel;
|
||||||
import JointFeldmanProtocol.DistributedKeyGeneration;
|
import meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.User;
|
||||||
import JointFeldmanProtocol.DistributedKeyGenerationUserImpl;
|
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
|
||||||
import ShamirSecretSharing.Polynomial;
|
import meerkat.crypto.concrete.secret_shring.shamir.SecretSharing;
|
||||||
import ShamirSecretSharing.SecretSharing;
|
|
||||||
import com.google.protobuf.Message;
|
import com.google.protobuf.Message;
|
||||||
import meerkat.protobuf.DKGMessages;
|
import meerkat.protobuf.DKGMessages;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Tzlil on 3/16/2016.
|
* Created by Tzlil on 3/16/2016.
|
||||||
*/
|
*/
|
||||||
public class SecureDistributedKeyGenerationUserImpl extends DistributedKeyGenerationUserImpl {
|
public class User<T> extends meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.User<T> {
|
||||||
|
|
||||||
protected SecureDistributedKeyGenerationParty[] parties;
|
protected Party<T>[] parties;
|
||||||
protected final SecureDistributedKeyGeneration sdkg;
|
protected final Protocol<T> sdkg;
|
||||||
private Arithmetic<BigInteger> arithmetic;
|
private Arithmetic<BigInteger> arithmetic;
|
||||||
private boolean isStage4;
|
private boolean isStage4;
|
||||||
|
|
||||||
public SecureDistributedKeyGenerationUserImpl(SecureDistributedKeyGeneration sdkg, Network network) {
|
public User(Protocol sdkg, Channel channel) {
|
||||||
super(sdkg, network,new SecureDistributedKeyGenerationMailHandler(null));
|
super(sdkg, channel);
|
||||||
this.sdkg = sdkg;
|
this.sdkg = sdkg;
|
||||||
this.messageHandler = new MessageHandler();
|
|
||||||
this.user.setMessageHandler(this.messageHandler);
|
|
||||||
this.parties = sdkg.getParties();
|
this.parties = sdkg.getParties();
|
||||||
this.arithmetic = new Fp(sdkg.getQ());
|
this.arithmetic = new Fp(sdkg.getQ());
|
||||||
this.isStage4 = false;
|
this.isStage4 = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void registerReceiverCallback(){
|
||||||
|
this.mailHandler = new MailHandler(new MessageHandler());
|
||||||
|
this.channel.registerReceiverCallback(mailHandler);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* stage1 according to the protocol
|
* stage1 according to the protocol
|
||||||
* 1. Pi broadcasts Cik=Aik*Bik for k = 0,...,t.
|
* 1. Pi broadcasts Cik=Aik*Bik for k = 0,...,t.
|
||||||
|
@ -39,15 +42,15 @@ public class SecureDistributedKeyGenerationUserImpl extends DistributedKeyGenera
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void stage1() {
|
protected void stage1() {
|
||||||
sdkg.broadcastVerificationValues(user);
|
sdkg.computeAndBroadcastVerificationValues();
|
||||||
sdkg.sendSecrets(user);
|
sdkg.sendSecrets();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void waitUntilStageOneCompleted(){
|
protected void waitUntilStageOneCompleted(){
|
||||||
super.waitUntilStageOneCompleted();
|
super.waitUntilStageOneCompleted();
|
||||||
// save the received commitments as verification values
|
// save the received commitments as verification values
|
||||||
BigInteger[] temp;
|
ArrayList<T> temp;
|
||||||
for (int i = 0 ; i < n; i++){
|
for (int i = 0 ; i < n; i++){
|
||||||
temp = parties[i].verifiableValues;
|
temp = parties[i].verifiableValues;
|
||||||
parties[i].verifiableValues = parties[i].commitments;
|
parties[i].verifiableValues = parties[i].commitments;
|
||||||
|
@ -63,40 +66,45 @@ public class SecureDistributedKeyGenerationUserImpl extends DistributedKeyGenera
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void stage2(){
|
protected void stage2(){
|
||||||
sdkg.broadcastComplaints(user);
|
sdkg.broadcastComplaints();
|
||||||
//broadcast done message after all complaints
|
//broadcast done message after all complaints
|
||||||
DKGMessages.EmptyMessage doneMessage = DKGMessages.EmptyMessage.newBuilder().build();
|
DKGMessages.EmptyMessage doneMessage = DKGMessages.EmptyMessage.newBuilder().build();
|
||||||
user.broadcast(DKGMessages.Mail.Type.DONE,doneMessage);
|
channel.broadcastMessage(DKGMessages.Mail.Type.DONE,doneMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: ??
|
/**
|
||||||
|
* broadcast commitments and recover parties information if necessary
|
||||||
|
*/
|
||||||
private void resolveQualifyingPublicKey(){
|
private void resolveQualifyingPublicKey(){
|
||||||
sdkg.broadcastCommitments(user);
|
sdkg.broadcastCommitments();
|
||||||
// wait until all parties in QUAL broadcast their commitments or aborted
|
// wait until all parties in QUAL broadcast their commitments or aborted
|
||||||
// TODO: in main run loop
|
|
||||||
for (int i:QUAL) {
|
for (int i:QUAL) {
|
||||||
for(int k = 0; k <= t; k++) {
|
for(int k = 0; k <= t; k++) {
|
||||||
while (parties[i - 1].commitments[k] == null && !parties[i - 1].aborted) {
|
synchronized (parties[i - 1]) {
|
||||||
try {
|
while (parties[i - 1].commitments.get(k) == null && !parties[i - 1].aborted) {
|
||||||
Thread.sleep(SleepTime);
|
try {
|
||||||
} catch (InterruptedException e) {
|
parties[i - 1].wait();
|
||||||
// do nothing
|
} catch (InterruptedException e) {
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sdkg.computeAndBroadcastComplaints(user,QUAL);
|
sdkg.computeAndBroadcastComplaints(QUAL);
|
||||||
//broadcast done message after all complaints
|
//broadcast done message after all complaints
|
||||||
DKGMessages.EmptyMessage doneMessage = DKGMessages.EmptyMessage.newBuilder().build();
|
DKGMessages.EmptyMessage doneMessage = DKGMessages.EmptyMessage.newBuilder().build();
|
||||||
user.broadcast(DKGMessages.Mail.Type.DONE,doneMessage);
|
channel.broadcastMessage(DKGMessages.Mail.Type.DONE,doneMessage);
|
||||||
|
|
||||||
// wait until all parties in QUAL done or aborted
|
// wait until all parties in QUAL done or aborted
|
||||||
for (int i:QUAL) {
|
for (int i:QUAL) {
|
||||||
while (!parties[i - 1].ysDoneFlag && !parties[i - 1].aborted) {
|
synchronized ((parties[i - 1])) {
|
||||||
try {
|
while (!parties[i - 1].ysDoneFlag && !parties[i - 1].aborted) {
|
||||||
Thread.sleep(SleepTime);
|
try {
|
||||||
} catch (InterruptedException e) {
|
parties[i - 1].wait();
|
||||||
// do nothing
|
} catch (InterruptedException e) {
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,17 +112,19 @@ public class SecureDistributedKeyGenerationUserImpl extends DistributedKeyGenera
|
||||||
// broadcast i private secret foreach i in QUAL that aborted
|
// broadcast i private secret foreach i in QUAL that aborted
|
||||||
for (int i:QUAL) {
|
for (int i:QUAL) {
|
||||||
if(parties[i - 1].aborted){
|
if(parties[i - 1].aborted){
|
||||||
sdkg.broadcastAnswer(user, parties[i - 1].share, parties[i - 1].shareT, i);
|
sdkg.broadcastAnswer(parties[i - 1].share, parties[i - 1].shareT, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// wait until at least t + 1 secrets will received foreach i in QUAL that aborted
|
// wait until at least t + 1 secrets will received foreach i in QUAL that aborted
|
||||||
for (int i:QUAL) {
|
for (int i:QUAL) {
|
||||||
if(parties[i - 1].aborted){
|
synchronized ((parties[i - 1])) {
|
||||||
while (parties[i - 1].restoreSharesSet.size() <= t) {
|
if (parties[i - 1].aborted) {
|
||||||
try {
|
while (parties[i - 1].recoverSharesSet.size() <= t) {
|
||||||
Thread.sleep(SleepTime);
|
try {
|
||||||
} catch (InterruptedException e) {
|
parties[i - 1].wait();
|
||||||
// do nothing
|
} catch (InterruptedException e) {
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,12 +132,12 @@ public class SecureDistributedKeyGenerationUserImpl extends DistributedKeyGenera
|
||||||
|
|
||||||
// restore necessary information
|
// restore necessary information
|
||||||
for (int i = 0; i < n ; i++) {
|
for (int i = 0; i < n ; i++) {
|
||||||
if(parties[i].restoreSharesSet.isEmpty()){
|
if(parties[i].recoverSharesSet.isEmpty()){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Polynomial.Point[] shares = new Polynomial.Point[t + 1];
|
Polynomial.Point[] shares = new Polynomial.Point[t + 1];
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for (Polynomial.Point share: parties[i].restoreSharesSet){
|
for (Polynomial.Point share: parties[i].recoverSharesSet){
|
||||||
shares[j++] = share;
|
shares[j++] = share;
|
||||||
if (j >= shares.length){
|
if (j >= shares.length){
|
||||||
break;
|
break;
|
||||||
|
@ -136,7 +146,7 @@ public class SecureDistributedKeyGenerationUserImpl extends DistributedKeyGenera
|
||||||
Polynomial polynomial = SecretSharing.recoverPolynomial(shares,arithmetic);
|
Polynomial polynomial = SecretSharing.recoverPolynomial(shares,arithmetic);
|
||||||
BigInteger[] coefficients = polynomial.getCoefficients();
|
BigInteger[] coefficients = polynomial.getCoefficients();
|
||||||
for (int k = 0 ; k <= t; k++){
|
for (int k = 0 ; k <= t; k++){
|
||||||
parties[i].commitments[k] = group.multiply(g,coefficients[k]);
|
parties[i].commitments.add(k,group.multiply(g,coefficients[k]));
|
||||||
}
|
}
|
||||||
parties[i].share = new Polynomial.Point(BigInteger.valueOf(id),polynomial);
|
parties[i].share = new Polynomial.Point(BigInteger.valueOf(id),polynomial);
|
||||||
}
|
}
|
||||||
|
@ -147,9 +157,7 @@ public class SecureDistributedKeyGenerationUserImpl extends DistributedKeyGenera
|
||||||
*/
|
*/
|
||||||
protected void setStage4(){
|
protected void setStage4(){
|
||||||
this.isStage4 = true;
|
this.isStage4 = true;
|
||||||
SecureDistributedKeyGenerationMailHandler handler =
|
((MailHandler)this.mailHandler).setStage4(true);
|
||||||
(SecureDistributedKeyGenerationMailHandler)user.getMailHandler();
|
|
||||||
handler.setStage4(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -159,13 +167,13 @@ public class SecureDistributedKeyGenerationUserImpl extends DistributedKeyGenera
|
||||||
super.stage4();
|
super.stage4();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MessageHandler extends DistributedKeyGenerationUserImpl.MessageHandler{
|
private class MessageHandler extends meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.User.MessageHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* as in super, with extension to double secret message
|
* as in super, with extension to double secret message
|
||||||
*/
|
*/
|
||||||
protected boolean isValidSecretMessage(int sender, boolean isBroadcast, DKGMessages.DoubleSecretMessage doubleSecretMessage) {
|
protected boolean isValidSecretMessage(int sender, boolean isBroadcast, DKGMessages.DoubleShareMessage doubleSecretMessage) {
|
||||||
DKGMessages.SecretMessage secretMessage = DKGMessages.SecretMessage.newBuilder()
|
DKGMessages.ShareMessage secretMessage = DKGMessages.ShareMessage.newBuilder()
|
||||||
.setI(doubleSecretMessage.getI())
|
.setI(doubleSecretMessage.getI())
|
||||||
.setJ(doubleSecretMessage.getJ())
|
.setJ(doubleSecretMessage.getJ())
|
||||||
.setSecret(doubleSecretMessage.getSecret())
|
.setSecret(doubleSecretMessage.getSecret())
|
||||||
|
@ -178,11 +186,14 @@ public class SecureDistributedKeyGenerationUserImpl extends DistributedKeyGenera
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void handleSecretMessage(int sender, boolean isBroadcast, Message message) {
|
public void handleSecretMessage(int sender, boolean isBroadcast, Message message) {
|
||||||
DKGMessages.DoubleSecretMessage doubleSecretMessage = (DKGMessages.DoubleSecretMessage)message;
|
DKGMessages.DoubleShareMessage doubleSecretMessage = (DKGMessages.DoubleShareMessage)message;
|
||||||
if (isValidSecretMessage(sender,isBroadcast,doubleSecretMessage)) {
|
if (isValidSecretMessage(sender,isBroadcast,doubleSecretMessage)) {
|
||||||
int i = doubleSecretMessage.getI();
|
int i = doubleSecretMessage.getI();
|
||||||
parties[i - 1].share = extractSecret(id, doubleSecretMessage.getSecret());
|
synchronized (parties[i - 1]) {
|
||||||
parties[i - 1].shareT = extractSecret(id, doubleSecretMessage.getSecretT());
|
parties[i - 1].share = extractShare(id, doubleSecretMessage.getSecret());
|
||||||
|
parties[i - 1].shareT = extractShare(id, doubleSecretMessage.getSecretT());
|
||||||
|
parties[i - 1].notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,9 +204,9 @@ public class SecureDistributedKeyGenerationUserImpl extends DistributedKeyGenera
|
||||||
* 2. secret.j == sender
|
* 2. secret.j == sender
|
||||||
* 3. QUAL contains i and j
|
* 3. QUAL contains i and j
|
||||||
*/
|
*/
|
||||||
protected boolean isValidAnswerMessage(int sender, boolean isBroadcast, DKGMessages.DoubleSecretMessage doubleSecretMessage) {
|
protected boolean isValidAnswerMessage(int sender, boolean isBroadcast, DKGMessages.DoubleShareMessage doubleSecretMessage) {
|
||||||
if(!isStage4) {
|
if(!isStage4) {
|
||||||
DKGMessages.SecretMessage secretMessage = DKGMessages.SecretMessage.newBuilder()
|
DKGMessages.ShareMessage secretMessage = DKGMessages.ShareMessage.newBuilder()
|
||||||
.setI(doubleSecretMessage.getI())
|
.setI(doubleSecretMessage.getI())
|
||||||
.setJ(doubleSecretMessage.getJ())
|
.setJ(doubleSecretMessage.getJ())
|
||||||
.setSecret(doubleSecretMessage.getSecret())
|
.setSecret(doubleSecretMessage.getSecret())
|
||||||
|
@ -215,26 +226,28 @@ public class SecureDistributedKeyGenerationUserImpl extends DistributedKeyGenera
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void handleAnswerMessage(int sender, boolean isBroadcast, Message message) {
|
public void handleAnswerMessage(int sender, boolean isBroadcast, Message message) {
|
||||||
DKGMessages.DoubleSecretMessage doubleSecretMessage = (DKGMessages.DoubleSecretMessage)message;
|
DKGMessages.DoubleShareMessage doubleSecretMessage = (DKGMessages.DoubleShareMessage)message;
|
||||||
if(isValidAnswerMessage(sender,isBroadcast,doubleSecretMessage)) {
|
if(isValidAnswerMessage(sender,isBroadcast,doubleSecretMessage)) {
|
||||||
int i = doubleSecretMessage.getI();
|
int i = doubleSecretMessage.getI();
|
||||||
int j = doubleSecretMessage.getJ();
|
int j = doubleSecretMessage.getJ();
|
||||||
Polynomial.Point secret = extractSecret(j, doubleSecretMessage.getSecret());
|
Polynomial.Point secret = extractShare(j, doubleSecretMessage.getSecret());
|
||||||
Polynomial.Point secretT = extractSecret(j, doubleSecretMessage.getSecretT());
|
Polynomial.Point secretT = extractShare(j, doubleSecretMessage.getSecretT());
|
||||||
if (!isStage4) {
|
synchronized (parties[i - 1]) {
|
||||||
if (sdkg.isValidShare(secret, secretT, parties[j - 1].verifiableValues, i)) {
|
if (!isStage4) {
|
||||||
parties[i - 1].complaints[j - 1] = DistributedKeyGeneration.ComplaintState.NonDisqualified;
|
if (sdkg.isValidShare(secret, secretT, parties[j - 1].verifiableValues, i)) {
|
||||||
|
parties[i - 1].complaints[j - 1] = meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.Protocol.ComplaintState.NonDisqualified;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
parties[i - 1].complaints[j - 1] = DistributedKeyGeneration.ComplaintState.Disqualified;
|
parties[i - 1].complaints[j - 1] = meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.Protocol.ComplaintState.Disqualified;
|
||||||
|
}
|
||||||
|
if (j == id) {
|
||||||
|
parties[i - 1].share = secret;
|
||||||
|
parties[i - 1].shareT = secretT;
|
||||||
|
}
|
||||||
|
} else if (sdkg.isValidShare(secret, secretT, parties[i - 1].verifiableValues, j)) {
|
||||||
|
parties[i - 1].recoverSharesSet.add(secret);
|
||||||
}
|
}
|
||||||
if(j == id){
|
parties[i - 1].notify();
|
||||||
parties[i - 1].share = secret;
|
|
||||||
parties[i - 1].shareT = secretT;
|
|
||||||
}
|
|
||||||
} else if (sdkg.isValidShare(secret, secretT, parties[j - 1].verifiableValues, i)) {
|
|
||||||
// TODO: Check that this is ok
|
|
||||||
parties[i - 1].restoreSharesSet.add(secret);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,7 +273,10 @@ public class SecureDistributedKeyGenerationUserImpl extends DistributedKeyGenera
|
||||||
super.handleDoneMessage(sender, isBroadcast, message);
|
super.handleDoneMessage(sender, isBroadcast, message);
|
||||||
else{
|
else{
|
||||||
if(isValidDoneMessage(sender,isBroadcast)) {
|
if(isValidDoneMessage(sender,isBroadcast)) {
|
||||||
parties[sender - 1].ysDoneFlag = true;
|
synchronized (parties[sender - 1]) {
|
||||||
|
parties[sender - 1].ysDoneFlag = true;
|
||||||
|
parties[sender - 1].notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -273,7 +289,7 @@ public class SecureDistributedKeyGenerationUserImpl extends DistributedKeyGenera
|
||||||
* 3. QUAL contains i and j
|
* 3. QUAL contains i and j
|
||||||
*/
|
*/
|
||||||
protected boolean isValidComplaintMessage(int sender, boolean isBroadcast,
|
protected boolean isValidComplaintMessage(int sender, boolean isBroadcast,
|
||||||
DKGMessages.DoubleSecretMessage complaintMessage){
|
DKGMessages.DoubleShareMessage complaintMessage){
|
||||||
int i = complaintMessage.getI();
|
int i = complaintMessage.getI();
|
||||||
int j = complaintMessage.getJ();
|
int j = complaintMessage.getJ();
|
||||||
return isBroadcast && j == sender && QUAL.contains(i) && QUAL.contains(j);
|
return isBroadcast && j == sender && QUAL.contains(i) && QUAL.contains(j);
|
||||||
|
@ -290,15 +306,18 @@ public class SecureDistributedKeyGenerationUserImpl extends DistributedKeyGenera
|
||||||
if(!isStage4) {
|
if(!isStage4) {
|
||||||
super.handleComplaintMessage(sender, isBroadcast, message);
|
super.handleComplaintMessage(sender, isBroadcast, message);
|
||||||
}else {
|
}else {
|
||||||
DKGMessages.DoubleSecretMessage ysComplaintMessage =(DKGMessages.DoubleSecretMessage)message;
|
DKGMessages.DoubleShareMessage ysComplaintMessage =(DKGMessages.DoubleShareMessage)message;
|
||||||
if (isValidComplaintMessage(sender,isBroadcast,ysComplaintMessage)) {
|
if (isValidComplaintMessage(sender,isBroadcast,ysComplaintMessage)) {
|
||||||
int i = ysComplaintMessage.getI();
|
int i = ysComplaintMessage.getI();
|
||||||
int j = ysComplaintMessage.getJ();
|
int j = ysComplaintMessage.getJ();
|
||||||
Polynomial.Point secret = extractSecret(i,ysComplaintMessage.getSecret());
|
Polynomial.Point secret = extractShare(i,ysComplaintMessage.getSecret());
|
||||||
Polynomial.Point secretT = extractSecret(i,ysComplaintMessage.getSecretT());
|
Polynomial.Point secretT = extractShare(i,ysComplaintMessage.getSecretT());
|
||||||
if (sdkg.isValidShare(secret, secretT, parties[i - 1].verifiableValues, j)
|
if (sdkg.isValidShare(secret, secretT, parties[i - 1].verifiableValues, j)
|
||||||
&& !dkg.isValidSecret(secret,parties[i - 1].commitments, j)) {
|
&& !dkg.isValidShare(secret,parties[i - 1].commitments, j)) {
|
||||||
parties[i - 1].aborted = true;
|
synchronized (parties[i - 1]) {
|
||||||
|
parties[i - 1].aborted = true;
|
||||||
|
parties[i - 1].notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package JointFeldmanProtocol;
|
package meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol;
|
||||||
|
|
||||||
import Communication.MailHandler;
|
import Communication.MailHandler;
|
||||||
import Communication.MessageHandler;
|
import Communication.MessageHandler;
|
||||||
|
@ -9,9 +9,9 @@ import meerkat.protobuf.DKGMessages;
|
||||||
/**
|
/**
|
||||||
* Created by Tzlil on 2/29/2016.
|
* Created by Tzlil on 2/29/2016.
|
||||||
*/
|
*/
|
||||||
public class DistributedKeyGenerationMailHandler extends MailHandler {
|
public class MailHandler extends Communication.MailHandler {
|
||||||
|
|
||||||
public DistributedKeyGenerationMailHandler(MessageHandler messageHandler) {
|
public MailHandler(MessageHandler messageHandler) {
|
||||||
super(messageHandler);
|
super(messageHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@ public class DistributedKeyGenerationMailHandler extends MailHandler {
|
||||||
try {
|
try {
|
||||||
Message message;
|
Message message;
|
||||||
switch (mail.getType()) {
|
switch (mail.getType()) {
|
||||||
case SECRET:
|
case SHARE:
|
||||||
message = DKGMessages.SecretMessage.parseFrom(mail.getMessage());
|
message = DKGMessages.ShareMessage.parseFrom(mail.getMessage());
|
||||||
break;
|
break;
|
||||||
case COMMITMENT:
|
case COMMITMENT:
|
||||||
message = DKGMessages.CommitmentMessage.parseFrom(mail.getMessage());
|
message = DKGMessages.CommitmentMessage.parseFrom(mail.getMessage());
|
||||||
|
@ -33,7 +33,7 @@ public class DistributedKeyGenerationMailHandler extends MailHandler {
|
||||||
message = DKGMessages.EmptyMessage.parseFrom(mail.getMessage());
|
message = DKGMessages.EmptyMessage.parseFrom(mail.getMessage());
|
||||||
break;
|
break;
|
||||||
case ANSWER:
|
case ANSWER:
|
||||||
message = DKGMessages.SecretMessage.parseFrom(mail.getMessage());
|
message = DKGMessages.ShareMessage.parseFrom(mail.getMessage());
|
||||||
break;
|
break;
|
||||||
case ABORT:
|
case ABORT:
|
||||||
message = DKGMessages.EmptyMessage.parseFrom(mail.getMessage());
|
message = DKGMessages.EmptyMessage.parseFrom(mail.getMessage());
|
|
@ -1,8 +1,8 @@
|
||||||
package JointFeldmanProtocol;
|
package meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol;
|
||||||
|
|
||||||
import ShamirSecretSharing.Polynomial;
|
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,21 +12,24 @@ import java.util.Arrays;
|
||||||
* the run of Joint Feldamn protocol
|
* the run of Joint Feldamn protocol
|
||||||
*/
|
*/
|
||||||
// TODO: comments for every field.
|
// TODO: comments for every field.
|
||||||
public class DistributedKeyGenerationParty {
|
public class Party<T> {
|
||||||
public final int id;
|
public final int id;
|
||||||
public Polynomial.Point share;
|
public Polynomial.Point share;
|
||||||
public BigInteger[] commitments;
|
public ArrayList<T> commitments;
|
||||||
public boolean doneFlag;
|
public boolean doneFlag;
|
||||||
public DistributedKeyGeneration.ComplaintState[] complaints;
|
public DistributedKeyGeneration.ComplaintState[] complaints;
|
||||||
public boolean aborted;
|
public boolean aborted;
|
||||||
|
|
||||||
public DistributedKeyGenerationParty(int id, int n, int t) {
|
public Party(int id, int n, int t) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.share = null;
|
this.share = null;
|
||||||
this.doneFlag = false;
|
this.doneFlag = false;
|
||||||
this.complaints = new DistributedKeyGeneration.ComplaintState[n];
|
this.complaints = new DistributedKeyGeneration.ComplaintState[n];
|
||||||
Arrays.fill(this.complaints, DistributedKeyGeneration.ComplaintState.OK);
|
Arrays.fill(this.complaints, DistributedKeyGeneration.ComplaintState.OK);
|
||||||
this.commitments = new BigInteger[t + 1];
|
this.commitments = new ArrayList<T>(t + 1);
|
||||||
|
for (int i = 0; i <= t ; i++){
|
||||||
|
commitments.add(null);
|
||||||
|
}
|
||||||
this.aborted = false;
|
this.aborted = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,24 +1,24 @@
|
||||||
package JointFeldmanProtocol;
|
package meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol;
|
||||||
|
|
||||||
import Communication.User;
|
import meerkat.crypto.utilitis.Channel;
|
||||||
import FeldmanVerifiableSecretSharing.VerifiableSecretSharing;
|
import meerkat.crypto.concrete.secret_shring.feldman_verifiable.VerifiableSecretSharing;
|
||||||
import ShamirSecretSharing.Polynomial;
|
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import meerkat.protobuf.DKGMessages;
|
import meerkat.protobuf.DKGMessages;
|
||||||
import org.factcenter.qilin.primitives.Group;
|
import org.factcenter.qilin.primitives.Group;
|
||||||
|
import org.factcenter.qilin.util.ByteEncoder;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Tzlil on 3/14/2016.
|
* Created by Tzlil on 3/14/2016.
|
||||||
|
*
|
||||||
|
* an implementation of JointFeldman distributed key generation protocol.
|
||||||
|
*
|
||||||
|
* allows set of n parties to generate random key with threshold t.
|
||||||
*/
|
*/
|
||||||
// TODO: Lots of comments...
|
public class Protocol<T> extends VerifiableSecretSharing<T> {
|
||||||
// TODO: User Channel instead of User
|
|
||||||
public class DistributedKeyGeneration extends VerifiableSecretSharing {
|
|
||||||
public enum ComplaintState {
|
public enum ComplaintState {
|
||||||
/**
|
/**
|
||||||
* No complaints, no response required at this point.
|
* No complaints, no response required at this point.
|
||||||
|
@ -50,26 +50,66 @@ public class DistributedKeyGeneration extends VerifiableSecretSharing {
|
||||||
* All parties participating in key generation.
|
* All parties participating in key generation.
|
||||||
* parties[id-1] has my info.
|
* parties[id-1] has my info.
|
||||||
*/
|
*/
|
||||||
private DistributedKeyGenerationParty[] parties;
|
private Party<T>[] parties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* communication object
|
||||||
|
*/
|
||||||
|
protected Channel channel;
|
||||||
|
|
||||||
|
|
||||||
// TODO: Copy comment
|
/**
|
||||||
public DistributedKeyGeneration(int t, int n, BigInteger zi, Random random, BigInteger q, BigInteger g
|
* Encode/Decode group elements
|
||||||
, Group<BigInteger> group, int id) {
|
*/
|
||||||
|
protected final ByteEncoder<T> encoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor
|
||||||
|
* @param q a large prime.
|
||||||
|
* @param t threshold. Any t+1 share holders can recover the secret,
|
||||||
|
* but any set of at most t share holders cannot
|
||||||
|
* @param n number of share holders
|
||||||
|
* @param zi secret, chosen from Zq
|
||||||
|
* @param random use for generate random polynomial
|
||||||
|
* @param group
|
||||||
|
* @param q a large prime dividing group order.
|
||||||
|
* @param g a generator of cyclic group of order q.
|
||||||
|
* the generated group is a subgroup of the given group.
|
||||||
|
* it must be chosen such that computing discrete logarithms is hard in this group.
|
||||||
|
*/
|
||||||
|
public Protocol(int t, int n, BigInteger zi, Random random, BigInteger q, T g
|
||||||
|
, Group<T> group, int id, ByteEncoder<T> byteEncoder) {
|
||||||
super(t, n, zi, random, q, g,group);
|
super(t, n, zi, random, q, g,group);
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.parties = new DistributedKeyGenerationParty[n];
|
this.parties = new Party[n];
|
||||||
for (int i = 1; i <= n ; i++){
|
for (int i = 1; i <= n ; i++){
|
||||||
this.parties[i - 1] = new DistributedKeyGenerationParty(i,n,t);
|
this.parties[i - 1] = new Party(i,n,t);
|
||||||
}
|
}
|
||||||
this.parties[id - 1].share = getShare(id);
|
this.parties[id - 1].share = getShare(id);
|
||||||
|
this.encoder = byteEncoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setParties(DistributedKeyGenerationParty[] parties){
|
/**
|
||||||
|
* setter
|
||||||
|
* @param channel
|
||||||
|
*/
|
||||||
|
public void setChannel(Channel channel){
|
||||||
|
this.channel = channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter
|
||||||
|
* @param parties
|
||||||
|
*/
|
||||||
|
protected void setParties(Party[] parties){
|
||||||
this.parties = parties;
|
this.parties = parties;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DistributedKeyGenerationParty[] getParties(){
|
/**
|
||||||
|
* getter
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected Party[] getParties(){
|
||||||
return parties;
|
return parties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,30 +117,33 @@ public class DistributedKeyGeneration extends VerifiableSecretSharing {
|
||||||
* stage1.1 according to the protocol
|
* stage1.1 according to the protocol
|
||||||
* Pi broadcasts Aik for k = 0,...,t.
|
* Pi broadcasts Aik for k = 0,...,t.
|
||||||
*/
|
*/
|
||||||
public void broadcastCommitments(User user){
|
public void broadcastCommitments(){
|
||||||
broadcastCommitments(user,commitmentsArray);
|
broadcastCommitments(commitmentsArrayList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void broadcastCommitments(User user, BigInteger[] commitments){
|
/**
|
||||||
|
* pack commitments as messages and broadcast them
|
||||||
|
* @param commitments
|
||||||
|
*/
|
||||||
|
public void broadcastCommitments(ArrayList<T> commitments){
|
||||||
DKGMessages.CommitmentMessage commitmentMessage;
|
DKGMessages.CommitmentMessage commitmentMessage;
|
||||||
for (int k = 0; k <= t ; k++){
|
for (int k = 0; k <= t ; k++){
|
||||||
commitmentMessage = DKGMessages.CommitmentMessage.newBuilder()
|
commitmentMessage = DKGMessages.CommitmentMessage.newBuilder()
|
||||||
.setCommitment(ByteString.copyFrom(commitments[k].toByteArray()))
|
.setCommitment(ByteString.copyFrom(encoder.encode(commitments.get(k))))
|
||||||
.setK(k)
|
.setK(k)
|
||||||
.build();
|
.build();
|
||||||
user.broadcast(DKGMessages.Mail.Type.COMMITMENT, commitmentMessage);
|
channel.broadcastMessage(DKGMessages.Mail.Type.COMMITMENT, commitmentMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send user j her secret share (of my polynomial)
|
* Send channel j her secret share (of my polynomial)
|
||||||
* @param user
|
|
||||||
* @param j
|
* @param j
|
||||||
*/
|
*/
|
||||||
public void sendSecret(User user, int j){
|
public void sendSecret(int j){
|
||||||
ByteString secret = ByteString.copyFrom(getShare(j).y.toByteArray());
|
ByteString secret = ByteString.copyFrom(getShare(j).y.toByteArray());
|
||||||
user.send(j, DKGMessages.Mail.Type.SECRET,
|
channel.sendMessage(j, DKGMessages.Mail.Type.SHARE,
|
||||||
DKGMessages.SecretMessage.newBuilder()
|
DKGMessages.ShareMessage.newBuilder()
|
||||||
.setI(id)
|
.setI(id)
|
||||||
.setJ(j)
|
.setJ(j)
|
||||||
.setSecret(secret)
|
.setSecret(secret)
|
||||||
|
@ -111,35 +154,34 @@ public class DistributedKeyGeneration extends VerifiableSecretSharing {
|
||||||
* stage1.2 according to the protocol
|
* stage1.2 according to the protocol
|
||||||
* Pi computes the shares Sij for j = 1,...,n and sends Sij secretly to Pj.
|
* Pi computes the shares Sij for j = 1,...,n and sends Sij secretly to Pj.
|
||||||
*/
|
*/
|
||||||
public void sendSecrets(User user){
|
public void sendSecrets(){
|
||||||
for (int j = 1; j <= n ; j++){
|
for (int j = 1; j <= n ; j++){
|
||||||
if(j != id){
|
if(j != id){
|
||||||
sendSecret(user,j);
|
sendSecret(j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: comment
|
*
|
||||||
* @param i
|
* @param i
|
||||||
* @return
|
* @return computeVerificationValue(j,parties[i - 1].commitments,group) == g ^ parties[i - 1].share mod q
|
||||||
*/
|
*/
|
||||||
public boolean isValidSecret(int i){
|
public boolean isValidShare(int i){
|
||||||
DistributedKeyGenerationParty party = parties[i - 1];
|
Party<T> party = parties[i - 1];
|
||||||
return isValidSecret(party.share,party.commitments,id);
|
return isValidShare(party.share,party.commitments,id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Move to VerifiableSecretSharing
|
* @param share
|
||||||
* @param secret
|
|
||||||
* @param commitments
|
* @param commitments
|
||||||
* @param j
|
* @param j
|
||||||
* @return computeVerificationValue(j,commitments,group) == g ^ secret.y mod q
|
* @return computeVerificationValue(j,commitments,group) == g ^ secret.y mod q
|
||||||
*/
|
*/
|
||||||
public boolean isValidSecret(Polynomial.Point secret, BigInteger[] commitments, int j){
|
public boolean isValidShare(Polynomial.Point share, ArrayList<T> commitments, int j){
|
||||||
try{
|
try{
|
||||||
BigInteger v = computeVerificationValue(j,commitments,group);
|
T v = computeVerificationValue(j,commitments,group);
|
||||||
return group.multiply(g,secret.y).equals(v);
|
return group.multiply(g,share.y).equals(v);
|
||||||
}
|
}
|
||||||
catch (NullPointerException e){
|
catch (NullPointerException e){
|
||||||
return false;
|
return false;
|
||||||
|
@ -151,24 +193,32 @@ public class DistributedKeyGeneration extends VerifiableSecretSharing {
|
||||||
* Pj verifies all the shares he received (using isValidShare)
|
* Pj verifies all the shares he received (using isValidShare)
|
||||||
* if check fails for an index i, Pj broadcasts a complaint against Pi.
|
* if check fails for an index i, Pj broadcasts a complaint against Pi.
|
||||||
*/
|
*/
|
||||||
public void broadcastComplaints(User user){
|
public void broadcastComplaints(){
|
||||||
for (int i = 1; i <= n ; i++ ){
|
for (int i = 1; i <= n ; i++ ){
|
||||||
if(i != id && !isValidSecret(i)) {
|
if(i != id && !isValidShare(i)) {
|
||||||
broadcastComplaint(user,i);
|
broadcastComplaint(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void broadcastComplaint(User user, int i){
|
/**
|
||||||
|
* create a complaint message against i and broadcast it
|
||||||
|
* @param i
|
||||||
|
*/
|
||||||
|
private void broadcastComplaint(int i){
|
||||||
//message = new Message(Type.Complaint, j)
|
//message = new Message(Type.Complaint, j)
|
||||||
DKGMessages.IDMessage complaint = DKGMessages.IDMessage.newBuilder()
|
DKGMessages.IDMessage complaint = DKGMessages.IDMessage.newBuilder()
|
||||||
.setId(i)
|
.setId(i)
|
||||||
.build();
|
.build();
|
||||||
user.broadcast(DKGMessages.Mail.Type.COMPLAINT, complaint);
|
channel.broadcastMessage(DKGMessages.Mail.Type.COMPLAINT, complaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void broadcastComplaintAnswer(User user, int j){
|
/**
|
||||||
user.broadcast(DKGMessages.Mail.Type.ANSWER, DKGMessages.SecretMessage.newBuilder()
|
* create an answer message for j and broadcast it
|
||||||
|
* @param j
|
||||||
|
*/
|
||||||
|
public void broadcastComplaintAnswer(int j){
|
||||||
|
channel.broadcastMessage(DKGMessages.Mail.Type.ANSWER, DKGMessages.ShareMessage.newBuilder()
|
||||||
.setI(id)
|
.setI(id)
|
||||||
.setJ(j)
|
.setJ(j)
|
||||||
.setSecret(ByteString.copyFrom(getShare(j).y.toByteArray()))
|
.setSecret(ByteString.copyFrom(getShare(j).y.toByteArray()))
|
||||||
|
@ -179,12 +229,12 @@ public class DistributedKeyGeneration extends VerifiableSecretSharing {
|
||||||
* stage3.1 according to the protocol
|
* stage3.1 according to the protocol
|
||||||
* 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){
|
public void answerAllComplainingPlayers(){
|
||||||
ComplaintState[] complaints = parties[id - 1].complaints;
|
ComplaintState[] complaints = parties[id - 1].complaints;
|
||||||
for (int i = 1; i <= n ; i++) {
|
for (int i = 1; i <= n ; i++) {
|
||||||
switch (complaints[i - 1]) {
|
switch (complaints[i - 1]) {
|
||||||
case Waiting:
|
case Waiting:
|
||||||
broadcastComplaintAnswer(user,i);
|
broadcastComplaintAnswer(i);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -210,7 +260,6 @@ public class DistributedKeyGeneration extends VerifiableSecretSharing {
|
||||||
case OK:
|
case OK:
|
||||||
break;
|
break;
|
||||||
case NonDisqualified:
|
case NonDisqualified:
|
||||||
// TODO: Add test for false complaint
|
|
||||||
counter++;
|
counter++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -232,34 +281,35 @@ public class DistributedKeyGeneration extends VerifiableSecretSharing {
|
||||||
* stage4.1 according to the protocol
|
* stage4.1 according to the protocol
|
||||||
* public value y is computed as y = multiplication of yi mod p for i in QUAL
|
* public value y is computed as y = multiplication of yi mod p for i in QUAL
|
||||||
*/
|
*/
|
||||||
public BigInteger calcY(Set<Integer> QUAL){
|
public T calcY(Set<Integer> QUAL){
|
||||||
BigInteger y = group.zero();
|
T y = group.zero();
|
||||||
for (int i : QUAL) {
|
for (int i : QUAL) {
|
||||||
y = group.add(y , parties[i - 1].commitments[0]);
|
y = group.add(y , parties[i - 1].commitments.get(0));
|
||||||
}
|
}
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: better comment.
|
|
||||||
* stage4.2 according to the protocol
|
* stage4.2 according to the protocol
|
||||||
* public verification values are computed as Ak = multiplication of Aik mod p for i in QUAL for k = 0,...,t
|
* public verification values are computed as Ak = multiplication
|
||||||
|
* of Aik mod p for i in QUAL for k = 0,...,t
|
||||||
*/
|
*/
|
||||||
public BigInteger[] calcCommitments(Set<Integer> QUAL){
|
public ArrayList<T> calcCommitments(Set<Integer> QUAL){
|
||||||
BigInteger[] commitments = new BigInteger[t + 1];
|
ArrayList<T> commitments = new ArrayList<T>(t+1);
|
||||||
Arrays.fill(commitments,group.zero());
|
T value;
|
||||||
for (int i : QUAL) {
|
for (int k = 0; k <= t; k++){
|
||||||
for (int k = 0; k <= t; k++){
|
value = group.zero();
|
||||||
commitments[k] = group.add(commitments[k], parties[i - 1].commitments[k]);
|
for (int i : QUAL) {
|
||||||
|
value = group.add(value, parties[i - 1].commitments.get(k));
|
||||||
}
|
}
|
||||||
|
commitments.add(k,value);
|
||||||
}
|
}
|
||||||
return commitments;
|
return commitments;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: better comment.
|
|
||||||
* stage4.3 according to the protocol
|
* stage4.3 according to the protocol
|
||||||
* Pj sets is share of the secret as xj = sum of Sij mod q for i in QUAL
|
* Pj sets is share of the share as xj = sum of Sij mod q for i in QUAL
|
||||||
*/
|
*/
|
||||||
public Polynomial.Point calcShare(Set<Integer> QUAL){
|
public Polynomial.Point calcShare(Set<Integer> QUAL){
|
||||||
BigInteger xj = BigInteger.ZERO;
|
BigInteger xj = BigInteger.ZERO;
|
||||||
|
@ -269,6 +319,15 @@ public class DistributedKeyGeneration extends VerifiableSecretSharing {
|
||||||
return new Polynomial.Point(BigInteger.valueOf(id) , xj.mod(q));
|
return new Polynomial.Point(BigInteger.valueOf(id) , xj.mod(q));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* decode commitment from arr
|
||||||
|
* @param arr
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public T decodeCommitment(byte[] arr){
|
||||||
|
return encoder.decode(arr);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getter
|
* getter
|
||||||
* @return id
|
* @return id
|
||||||
|
@ -277,4 +336,21 @@ public class DistributedKeyGeneration extends VerifiableSecretSharing {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter
|
||||||
|
* @return channel
|
||||||
|
*/
|
||||||
|
public Channel getChannel() {
|
||||||
|
return channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter
|
||||||
|
* @return encoder
|
||||||
|
*/
|
||||||
|
public ByteEncoder<T> getEncoder() {
|
||||||
|
return encoder;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,50 +1,42 @@
|
||||||
package JointFeldmanProtocol;
|
package meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol;
|
||||||
|
|
||||||
|
import meerkat.crypto.utilitis.Channel;
|
||||||
import Communication.MailHandler;
|
import Communication.MailHandler;
|
||||||
import Communication.Network;
|
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
|
||||||
import Communication.User;
|
|
||||||
import ShamirSecretSharing.Polynomial;
|
|
||||||
import UserInterface.DistributedKeyGenerationUser;
|
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import com.google.protobuf.Message;
|
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;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Arrays;
|
import java.util.ArrayList;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import JointFeldmanProtocol.DistributedKeyGeneration.ComplaintState;
|
import meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.DistributedKeyGeneration.ComplaintState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Tzlil on 3/14/2016.
|
* Created by Tzlil on 3/14/2016.
|
||||||
* TODO: Comments
|
* TODO: Comments
|
||||||
* TODO: Replace polling with monitors/wait/notify (remember synchronization)
|
* TODO: Replace polling with monitors/wait/notify (remember synchronization)
|
||||||
*/
|
*/
|
||||||
public class DistributedKeyGenerationUserImpl implements DistributedKeyGenerationUser {
|
public class User<T> implements Runnable{
|
||||||
|
|
||||||
// TODO: remove
|
protected final DistributedKeyGeneration<T> dkg;
|
||||||
protected final static int SleepTime = 300;
|
|
||||||
|
|
||||||
protected final DistributedKeyGeneration dkg;
|
protected final T g;
|
||||||
|
protected final Group<T> group;
|
||||||
protected final BigInteger g;
|
|
||||||
protected final Group<BigInteger> group;
|
|
||||||
protected final int n;
|
protected final int n;
|
||||||
protected final int t;
|
protected final int t;
|
||||||
protected final int id;
|
protected final int id;
|
||||||
|
protected MailHandler mailHandler;
|
||||||
|
|
||||||
protected MessageHandler messageHandler;
|
protected final Channel channel;
|
||||||
protected final User user;
|
protected final Party[] parties;
|
||||||
protected final DistributedKeyGenerationParty[] parties;
|
|
||||||
protected Set<Integer> QUAL; // set of all non-disqualified parties
|
protected Set<Integer> QUAL; // set of all non-disqualified parties
|
||||||
protected BigInteger[] commitments; // public verification values
|
|
||||||
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 ArrayList<T> commitments; // public verification values
|
||||||
|
protected T y; // final public value
|
||||||
|
|
||||||
public DistributedKeyGenerationUserImpl(DistributedKeyGeneration dkg, Network network){
|
public User(DistributedKeyGeneration<T> dkg, Channel channel) {
|
||||||
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();
|
||||||
|
@ -53,14 +45,24 @@ public class DistributedKeyGenerationUserImpl implements DistributedKeyGeneratio
|
||||||
this.t = dkg.getT();
|
this.t = dkg.getT();
|
||||||
this.id = dkg.getId();
|
this.id = dkg.getId();
|
||||||
|
|
||||||
this.messageHandler = new MessageHandler();
|
this.channel = channel;
|
||||||
mailHandler.setMessageHandler(this.messageHandler);
|
dkg.setChannel(channel);
|
||||||
this.user = network.connect(mailHandler,dkg.getId());
|
registerReceiverCallback();
|
||||||
|
|
||||||
this.parties = dkg.getParties();
|
this.parties = dkg.getParties();
|
||||||
this.QUAL = null;
|
this.QUAL = null;
|
||||||
this.commitments = null;
|
this.commitments = null;
|
||||||
this.share = null;
|
this.share = null;
|
||||||
this.y = null;
|
this.y = null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create MailHandler and register it as ReceiverCallback
|
||||||
|
*/
|
||||||
|
protected void registerReceiverCallback(){
|
||||||
|
this.mailHandler = new DistributedKeyGenerationMailHandler(new MessageHandler());
|
||||||
|
channel.registerReceiverCallback(mailHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,30 +71,34 @@ public class DistributedKeyGenerationUserImpl implements DistributedKeyGeneratio
|
||||||
* 2. Pi computes the shares Sij for j = 1,...,n and sends Sij secretly to Pj.
|
* 2. Pi computes the shares Sij for j = 1,...,n and sends Sij secretly to Pj.
|
||||||
*/
|
*/
|
||||||
protected void stage1() {
|
protected void stage1() {
|
||||||
dkg.broadcastCommitments(user);
|
dkg.broadcastCommitments();
|
||||||
dkg.sendSecrets(user);
|
dkg.sendSecrets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void waitUntilStageOneCompleted(){
|
protected void waitUntilStageOneCompleted(){
|
||||||
// all parties send their share or aborted
|
// all parties send their share or aborted
|
||||||
for (int i = 0 ; i < n ; i++){
|
for (int i = 0 ; i < n ; i++){
|
||||||
while (parties[i].share == null && !parties[i].aborted){
|
synchronized (parties[i]) {
|
||||||
try {
|
while (parties[i].share == null && !parties[i].aborted) {
|
||||||
Thread.sleep(SleepTime);
|
try {
|
||||||
} catch (InterruptedException e) {
|
parties[i].wait();
|
||||||
// do nothing
|
} catch (InterruptedException e) {
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// all parties broadcast their commitments or aborted
|
// all parties broadcast their commitments or aborted
|
||||||
for (int i = 0 ; i < n ; i++){
|
for (int i = 0 ; i < n ; i++){
|
||||||
for (int k = 0 ; k <= t ; k++) {
|
for (int k = 0 ; k <= t ; k++) {
|
||||||
while (parties[i].commitments[k] == null && !parties[i].aborted) {
|
synchronized (parties[i]) {
|
||||||
try {
|
while (parties[i].commitments.get(k) == null && !parties[i].aborted) {
|
||||||
Thread.sleep(SleepTime);
|
try {
|
||||||
} catch (InterruptedException e) {
|
parties[i].wait();
|
||||||
// do nothing
|
} catch (InterruptedException e) {
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,26 +112,29 @@ public class DistributedKeyGenerationUserImpl implements DistributedKeyGeneratio
|
||||||
* Pj broadcasts done message at the end of this stage
|
* Pj broadcasts done message at the end of this stage
|
||||||
*/
|
*/
|
||||||
protected void stage2(){
|
protected void stage2(){
|
||||||
dkg.broadcastComplaints(user);
|
dkg.broadcastComplaints();
|
||||||
//broadcast done message after all complaints
|
//broadcast done message after all complaints
|
||||||
DKGMessages.EmptyMessage doneMessage = DKGMessages.EmptyMessage.newBuilder().build();
|
DKGMessages.EmptyMessage doneMessage = DKGMessages.EmptyMessage.newBuilder().build();
|
||||||
user.broadcast(DKGMessages.Mail.Type.DONE,doneMessage);
|
channel.broadcastMessage(DKGMessages.Mail.Type.DONE,doneMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void waitUntilStageTwoCompleted(){
|
protected void waitUntilStageTwoCompleted(){
|
||||||
// all parties done or aborted
|
// all parties done or aborted
|
||||||
for (int i = 0 ; i < n ; i++){
|
for (int i = 0 ; i < n ; i++){
|
||||||
while (!parties[i].doneFlag && !parties[i].aborted){
|
synchronized (parties[i]) {
|
||||||
try {
|
while (!parties[i].doneFlag && !parties[i].aborted) {
|
||||||
Thread.sleep(SleepTime);
|
try {
|
||||||
} catch (InterruptedException e) {
|
parties[i].wait();
|
||||||
// do nothing
|
} catch (InterruptedException e) {
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* stage3 according to the protocol
|
* stage3 according to the protocol
|
||||||
* 1. if more than t players complain against a player Pi he is disqualified.
|
* 1. if more than t players complain against a player Pi he is disqualified.
|
||||||
|
@ -134,15 +143,17 @@ public class DistributedKeyGenerationUserImpl implements DistributedKeyGeneratio
|
||||||
* set QUAL to be the set of non-disqualified players.
|
* set QUAL to be the set of non-disqualified players.
|
||||||
*/
|
*/
|
||||||
protected void stage3(){
|
protected void stage3(){
|
||||||
dkg.answerAllComplainingPlayers(user);
|
dkg.answerAllComplainingPlayers();
|
||||||
// wait until there is no complaint waiting for answer
|
// wait until there is no complaint waiting for answer
|
||||||
for (int i = 0; i < n; i++){
|
for (int i = 0; i < n; i++){
|
||||||
for (int j = 0; j < n; j++){
|
for (int j = 0; j < n; j++){
|
||||||
while (parties[i].complaints[j].equals(ComplaintState.Waiting) && !parties[i].aborted){
|
synchronized (parties[i]) {
|
||||||
try {
|
while (parties[i].complaints[j].equals(ComplaintState.Waiting) && !parties[i].aborted) {
|
||||||
Thread.sleep(SleepTime);
|
try {
|
||||||
} catch (InterruptedException e) {
|
parties[i].wait();
|
||||||
// do nothing
|
} catch (InterruptedException e) {
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,80 +173,101 @@ public class DistributedKeyGenerationUserImpl implements DistributedKeyGeneratio
|
||||||
this.share = dkg.calcShare(QUAL);
|
this.share = dkg.calcShare(QUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void startReceiver(){
|
|
||||||
user.getReceiverThread().start();
|
|
||||||
}
|
|
||||||
protected void stopReceiver(){
|
|
||||||
user.getReceiverThread().interrupt();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
startReceiver();
|
|
||||||
stage1();
|
stage1();
|
||||||
waitUntilStageOneCompleted();
|
waitUntilStageOneCompleted();
|
||||||
stage2();
|
stage2();
|
||||||
waitUntilStageTwoCompleted();
|
waitUntilStageTwoCompleted();
|
||||||
stage3();
|
stage3();
|
||||||
stage4();
|
stage4();
|
||||||
stopReceiver();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request the current run loop to exit gracefully
|
* Request the current run loop to exit gracefully
|
||||||
*/
|
*/
|
||||||
public void stop() {
|
public void stop() {
|
||||||
// TODO: implement
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public BigInteger[] getCommitments() {
|
* getter
|
||||||
return Arrays.copyOf(commitments, commitments.length);
|
* @return commitments
|
||||||
|
*/
|
||||||
|
public ArrayList<T> getCommitments() {
|
||||||
|
return commitments;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public BigInteger getGenerator() {
|
* getter
|
||||||
|
* @return g
|
||||||
|
*/
|
||||||
|
public T getGenerator() {
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public Group<BigInteger> getGroup() {
|
* getter
|
||||||
|
* @return group
|
||||||
|
*/
|
||||||
|
public Group<T> getGroup() {
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
|
* getter
|
||||||
|
* @return share
|
||||||
|
*/
|
||||||
public Polynomial.Point getShare() {
|
public Polynomial.Point getShare() {
|
||||||
return share;
|
return share;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
|
* getter
|
||||||
|
* @return id
|
||||||
|
*/
|
||||||
public int getID() {
|
public int getID() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
|
* getter
|
||||||
|
* @return n
|
||||||
|
*/
|
||||||
public int getN() {
|
public int getN() {
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
|
* getter
|
||||||
|
* @return t
|
||||||
|
*/
|
||||||
public int getT() {
|
public int getT() {
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public BigInteger getPublicValue() {
|
* getter
|
||||||
|
* @return y
|
||||||
|
*/
|
||||||
|
public T getPublicValue() {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
|
* getter
|
||||||
|
* @return QUAL
|
||||||
|
*/
|
||||||
public Set<Integer> getQUAL() {
|
public Set<Integer> getQUAL() {
|
||||||
return QUAL;
|
return QUAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected class MessageHandler implements Communication.MessageHandler{
|
public class MessageHandler implements Communication.MessageHandler{
|
||||||
|
|
||||||
|
public MessageHandler(){
|
||||||
|
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* commitment message is valid if:
|
* commitment message is valid if:
|
||||||
* 1. it was received in broadcast chanel
|
* 1. it was received in broadcast chanel
|
||||||
|
@ -244,7 +276,7 @@ public class DistributedKeyGenerationUserImpl implements DistributedKeyGeneratio
|
||||||
protected boolean isValidCommitmentMessage(int sender, boolean isBroadcast, DKGMessages.CommitmentMessage commitmentMessage){
|
protected boolean isValidCommitmentMessage(int sender, boolean isBroadcast, DKGMessages.CommitmentMessage commitmentMessage){
|
||||||
int i = sender - 1;
|
int i = sender - 1;
|
||||||
int k = commitmentMessage.getK();
|
int k = commitmentMessage.getK();
|
||||||
return isBroadcast && parties[i].commitments[k] == null;
|
return isBroadcast && parties[i].commitments.get(k) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -256,7 +288,10 @@ public class DistributedKeyGenerationUserImpl implements DistributedKeyGeneratio
|
||||||
if(isValidCommitmentMessage(sender,isBroadcast,commitmentMessage)){
|
if(isValidCommitmentMessage(sender,isBroadcast,commitmentMessage)){
|
||||||
int i = sender - 1;
|
int i = sender - 1;
|
||||||
int k = commitmentMessage.getK();
|
int k = commitmentMessage.getK();
|
||||||
parties[i].commitments[k] = extractCommitment(commitmentMessage);
|
synchronized (parties[i]) {
|
||||||
|
parties[i].commitments.set(k, extractCommitment(commitmentMessage));
|
||||||
|
parties[i].notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +302,7 @@ public class DistributedKeyGenerationUserImpl implements DistributedKeyGeneratio
|
||||||
* 3. secret.i == i
|
* 3. secret.i == i
|
||||||
* 4. secret.j == id
|
* 4. secret.j == id
|
||||||
*/
|
*/
|
||||||
protected boolean isValidSecretMessage(int sender, boolean isBroadcast, DKGMessages.SecretMessage secretMessage){
|
protected boolean isValidSecretMessage(int sender, boolean isBroadcast, DKGMessages.ShareMessage secretMessage){
|
||||||
int i = secretMessage.getI();
|
int i = secretMessage.getI();
|
||||||
int j = secretMessage.getJ();
|
int j = secretMessage.getJ();
|
||||||
if(sender != i || isBroadcast)
|
if(sender != i || isBroadcast)
|
||||||
|
@ -282,11 +317,14 @@ public class DistributedKeyGenerationUserImpl implements DistributedKeyGeneratio
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void handleSecretMessage(int sender, boolean isBroadcast, Message message) {
|
public void handleSecretMessage(int sender, boolean isBroadcast, Message message) {
|
||||||
DKGMessages.SecretMessage secretMessage = (DKGMessages.SecretMessage) message;
|
DKGMessages.ShareMessage secretMessage = (DKGMessages.ShareMessage) message;
|
||||||
if(isValidSecretMessage(sender,isBroadcast,secretMessage)) {
|
if(isValidSecretMessage(sender,isBroadcast,secretMessage)) {
|
||||||
int i = secretMessage.getI();
|
int i = secretMessage.getI();
|
||||||
Polynomial.Point secret = extractSecret(id,secretMessage.getSecret());
|
Polynomial.Point secret = extractShare(id,secretMessage.getSecret());
|
||||||
parties[i - 1].share = secret;
|
synchronized (parties[i -1]) {
|
||||||
|
parties[i - 1].share = secret;
|
||||||
|
parties[i - 1].notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,7 +343,10 @@ public class DistributedKeyGenerationUserImpl implements DistributedKeyGeneratio
|
||||||
@Override
|
@Override
|
||||||
public void handleDoneMessage(int sender, boolean isBroadcast, Message message) {
|
public void handleDoneMessage(int sender, boolean isBroadcast, Message message) {
|
||||||
if(isValidDoneMessage(sender,isBroadcast)) {
|
if(isValidDoneMessage(sender,isBroadcast)) {
|
||||||
parties[sender - 1].doneFlag = true;
|
synchronized (parties[sender - 1]) {
|
||||||
|
parties[sender - 1].doneFlag = true;
|
||||||
|
parties[sender - 1].notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,7 +370,10 @@ public class DistributedKeyGenerationUserImpl implements DistributedKeyGeneratio
|
||||||
if(isValidComplaintMessage(sender,isBroadcast,complaintMessage)){
|
if(isValidComplaintMessage(sender,isBroadcast,complaintMessage)){
|
||||||
int i = sender;
|
int i = sender;
|
||||||
int j = complaintMessage.getId();
|
int j = complaintMessage.getId();
|
||||||
parties[j - 1].complaints[i - 1] = ComplaintState.Waiting;
|
synchronized (parties[j - 1]) {
|
||||||
|
parties[j - 1].complaints[i - 1] = ComplaintState.Waiting;
|
||||||
|
parties[j - 1].notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,7 +384,7 @@ public class DistributedKeyGenerationUserImpl implements DistributedKeyGeneratio
|
||||||
* 3. 1 <= secret.j <= n
|
* 3. 1 <= secret.j <= n
|
||||||
* 4. it is marked that j complained against i and i didn't received
|
* 4. it is marked that j complained against i and i didn't received
|
||||||
*/
|
*/
|
||||||
protected boolean isValidAnswerMessage(int sender, boolean isBroadcast, DKGMessages.SecretMessage secretMessage){
|
protected boolean isValidAnswerMessage(int sender, boolean isBroadcast, DKGMessages.ShareMessage secretMessage){
|
||||||
int i = secretMessage.getI();
|
int i = secretMessage.getI();
|
||||||
int j = secretMessage.getJ();
|
int j = secretMessage.getJ();
|
||||||
if(sender != i || !isBroadcast)
|
if(sender != i || !isBroadcast)
|
||||||
|
@ -356,18 +400,21 @@ public class DistributedKeyGenerationUserImpl implements DistributedKeyGeneratio
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void handleAnswerMessage(int sender, boolean isBroadcast, Message message) {
|
public void handleAnswerMessage(int sender, boolean isBroadcast, Message message) {
|
||||||
DKGMessages.SecretMessage secretMessage = (DKGMessages.SecretMessage) message;
|
DKGMessages.ShareMessage secretMessage = (DKGMessages.ShareMessage) message;
|
||||||
if(isValidAnswerMessage(sender,isBroadcast,secretMessage)) {
|
if(isValidAnswerMessage(sender,isBroadcast,secretMessage)) {
|
||||||
int i = secretMessage.getI();
|
int i = secretMessage.getI();
|
||||||
int j = secretMessage.getJ();
|
int j = secretMessage.getJ();
|
||||||
Polynomial.Point secret = extractSecret(j,secretMessage.getSecret());
|
Polynomial.Point secret = extractShare(j,secretMessage.getSecret());
|
||||||
if (dkg.isValidSecret(secret, parties[i - 1].commitments, j)) {
|
synchronized (parties[i - 1]) {
|
||||||
parties[i - 1].complaints[j - 1] = ComplaintState.NonDisqualified;
|
if (dkg.isValidShare(secret, parties[i - 1].commitments, j)) {
|
||||||
} else {
|
parties[i - 1].complaints[j - 1] = ComplaintState.NonDisqualified;
|
||||||
parties[i - 1].complaints[j - 1] = ComplaintState.Disqualified;
|
} else {
|
||||||
}
|
parties[i - 1].complaints[j - 1] = ComplaintState.Disqualified;
|
||||||
if(j == id){
|
}
|
||||||
parties[i - 1].share = secret;
|
if (j == id) {
|
||||||
|
parties[i - 1].share = secret;
|
||||||
|
}
|
||||||
|
parties[i - 1].notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -377,17 +424,31 @@ public class DistributedKeyGenerationUserImpl implements DistributedKeyGeneratio
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void handleAbortMessage(int sender, boolean isBroadcast, Message message) {
|
public void handleAbortMessage(int sender, boolean isBroadcast, Message message) {
|
||||||
parties[sender - 1].aborted = true;
|
synchronized (parties[sender - 1]) {
|
||||||
|
parties[sender - 1].aborted = true;
|
||||||
|
parties[sender - 1].notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Polynomial.Point extractSecret(int i, ByteString secret){
|
/**
|
||||||
|
* extract share value from ByteString
|
||||||
|
* @param i
|
||||||
|
* @param share
|
||||||
|
* @return new Point (i,share)
|
||||||
|
*/
|
||||||
|
public Polynomial.Point extractShare(int i, ByteString share){
|
||||||
BigInteger x = BigInteger.valueOf(i);
|
BigInteger x = BigInteger.valueOf(i);
|
||||||
BigInteger y = new BigInteger(secret.toByteArray());
|
BigInteger y = new BigInteger(share.toByteArray());
|
||||||
return new Polynomial.Point(x,y);
|
return new Polynomial.Point(x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigInteger extractCommitment(DKGMessages.CommitmentMessage commitmentMessage){
|
/**
|
||||||
return new BigInteger(commitmentMessage.getCommitment().toByteArray());
|
*
|
||||||
|
* @param commitmentMessage
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public T extractCommitment(DKGMessages.CommitmentMessage commitmentMessage){
|
||||||
|
return dkg.decodeCommitment(commitmentMessage.getCommitment().toByteArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,108 @@
|
||||||
|
package meerkat.crypto.concrete.secret_shring.feldman_verifiable;
|
||||||
|
|
||||||
|
import meerkat.crypto.concrete.secret_shring.ShamirSecretSharing.Polynomial;
|
||||||
|
import meerkat.crypto.concrete.secret_shring.ShamirSecretSharing.SecretSharing;
|
||||||
|
|
||||||
|
import org.factcenter.qilin.primitives.Group;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Tzlil on 1/27/2016.
|
||||||
|
*
|
||||||
|
* an implementation of Feldman's verifiable secret sharing scheme.
|
||||||
|
*
|
||||||
|
* allows trusted dealer to share a key x among n parties.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class VerifiableSecretSharing<T> extends SecretSharing {
|
||||||
|
protected final Group<T> group;
|
||||||
|
protected final T g; // public generator of group
|
||||||
|
protected final ArrayList<T> commitmentsArrayList;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor
|
||||||
|
* @param q a large prime.
|
||||||
|
* @param t threshold. Any t+1 share holders can recover the secret,
|
||||||
|
* but any set of at most t share holders cannot
|
||||||
|
* @param n number of share holders
|
||||||
|
* @param zi secret, chosen from Zq
|
||||||
|
* @param random use for generate random polynomial
|
||||||
|
* @param group
|
||||||
|
* @param q a large prime dividing group order.
|
||||||
|
* @param g a generator of cyclic group of order q.
|
||||||
|
* the generated group is a subgroup of the given group.
|
||||||
|
* it must be chosen such that computing discrete logarithms is hard in this group.
|
||||||
|
*/
|
||||||
|
public VerifiableSecretSharing(int t, int n, BigInteger zi, Random random, BigInteger q, T g
|
||||||
|
, Group<T> group) {
|
||||||
|
super(t, n, zi, random,q);
|
||||||
|
this.g = g;
|
||||||
|
this.group = group;
|
||||||
|
assert (this.group.contains(g));
|
||||||
|
this.commitmentsArrayList = generateCommitments();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* commitments[i] = g ^ polynomial.coefficients[i]
|
||||||
|
* @return commitments
|
||||||
|
*/
|
||||||
|
private ArrayList<T> generateCommitments() {
|
||||||
|
|
||||||
|
Polynomial polynomial = getPolynomial();
|
||||||
|
BigInteger[] coefficients = polynomial.getCoefficients();
|
||||||
|
ArrayList<T> commitments = new ArrayList<T>(t + 1);
|
||||||
|
for (int i = 0 ; i <= t;i++){
|
||||||
|
commitments.add(i,group.multiply(g,coefficients[i]));
|
||||||
|
}
|
||||||
|
return commitments;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute verification value (g^{share value}) using coefficient commitments sent by dealer and my share id.
|
||||||
|
* @param j my share holder id
|
||||||
|
* @param commitments commitments to polynomial coefficients of share (received from dealer)
|
||||||
|
* @param group
|
||||||
|
*
|
||||||
|
* @return product of Aik ^ (j ^ k) == g ^ polynomial(i)
|
||||||
|
*/
|
||||||
|
public static <T> T computeVerificationValue(int j, ArrayList<T> commitments, Group<T> group) {
|
||||||
|
T v = group.zero();
|
||||||
|
BigInteger power = BigInteger.ONE;
|
||||||
|
BigInteger J = BigInteger.valueOf(j);
|
||||||
|
for (int k = 0 ; k < commitments.size() ; k ++){
|
||||||
|
v = group.add(v,group.multiply(commitments.get(k),power));
|
||||||
|
power = power.multiply(J);
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter
|
||||||
|
* @return generator of group
|
||||||
|
*/
|
||||||
|
public T getGenerator() {
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter
|
||||||
|
* @return group
|
||||||
|
*/
|
||||||
|
public Group<T> getGroup(){
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter
|
||||||
|
* @return commitmentsArrayList
|
||||||
|
*/
|
||||||
|
public ArrayList<T> getCommitmentsArrayList() {
|
||||||
|
return commitmentsArrayList;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
package ShamirSecretSharing;
|
package meerkat.crypto.concrete.secret_shring.shamir;
|
||||||
|
|
||||||
import Arithmetics.Arithmetic;
|
import meerkat.crypto.utilitis.Arithmetic;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package ShamirSecretSharing;
|
package meerkat.crypto.concrete.secret_shring.shamir;
|
||||||
|
|
||||||
import Arithmetics.Arithmetic;
|
import meerkat.crypto.utilitis.Arithmetic;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -100,7 +100,7 @@ public class Polynomial implements Comparable<Polynomial> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param other
|
* @param other
|
||||||
* @return new ShamirSecretSharing.PolynomialTests of degree max(this degree,other degree) s.t for all x in Z
|
* @return new meerkat.crypto.concrete.secret_shring.shamir.Polynomial of degree max(this degree,other degree) s.t for all x
|
||||||
* new.evaluate(x) = this.evaluate(x) + other.evaluate(x)
|
* new.evaluate(x) = this.evaluate(x) + other.evaluate(x)
|
||||||
*/
|
*/
|
||||||
public Polynomial add(Polynomial other){
|
public Polynomial add(Polynomial other){
|
||||||
|
@ -122,7 +122,7 @@ public class Polynomial implements Comparable<Polynomial> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param constant
|
* @param constant
|
||||||
* @return new Polynomial of degree this.degree s.t for all x in Z
|
* @return new Polynomial of degree this.degree s.t for all x
|
||||||
* new.evaluate(x) = constant * this.evaluate(x)
|
* new.evaluate(x) = constant * this.evaluate(x)
|
||||||
*/
|
*/
|
||||||
public Polynomial mul(BigInteger constant){
|
public Polynomial mul(BigInteger constant){
|
||||||
|
@ -137,7 +137,7 @@ public class Polynomial implements Comparable<Polynomial> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param other
|
* @param other
|
||||||
* @return new Polynomial of degree this degree + other degree + 1 s.t for all x in Z
|
* @return new Polynomial of degree this degree + other degree + 1 s.t for all x
|
||||||
* new.evaluate(x) = this.evaluate(x) * other.evaluate(x)
|
* new.evaluate(x) = this.evaluate(x) * other.evaluate(x)
|
||||||
*/
|
*/
|
||||||
public Polynomial mul(Polynomial other){
|
public Polynomial mul(Polynomial other){
|
|
@ -1,7 +1,7 @@
|
||||||
package ShamirSecretSharing;
|
package meerkat.crypto.concrete.secret_shring.shamir;
|
||||||
|
|
||||||
import Arithmetics.Arithmetic;
|
import meerkat.crypto.utilitis.Arithmetic;
|
||||||
import Arithmetics.Fp;
|
import meerkat.crypto.utilitis.concrete.Fp;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -22,14 +22,14 @@ public class SecretSharing{
|
||||||
* @param t threshold. Any t+1 share holders can recover the secret,
|
* @param t threshold. Any t+1 share holders can recover the secret,
|
||||||
* but any set of at most t share holders cannot
|
* but any set of at most t share holders cannot
|
||||||
* @param n number of share holders
|
* @param n number of share holders
|
||||||
* @param x secret, chosen from Zq
|
* @param zi secret, chosen from Zq
|
||||||
* @param random use for generate random polynomial
|
* @param random use for generate random polynomial
|
||||||
*/
|
*/
|
||||||
public SecretSharing(int t, int n, BigInteger x, Random random, BigInteger q) {
|
public SecretSharing(int t, int n, BigInteger zi, Random random, BigInteger q) {
|
||||||
this.q = q;
|
this.q = q;
|
||||||
this.t = t;
|
this.t = t;
|
||||||
this.n = n;
|
this.n = n;
|
||||||
this.polynomial = generateRandomPolynomial(x,random);
|
this.polynomial = generateRandomPolynomial(zi,random);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,7 +52,7 @@ public class SecretSharing{
|
||||||
/**
|
/**
|
||||||
* @param i in range of [1,...n]
|
* @param i in range of [1,...n]
|
||||||
*
|
*
|
||||||
* @return polynomial.evaluate(i)%q
|
* @return polynomial.evaluate(i)
|
||||||
*/
|
*/
|
||||||
public Polynomial.Point getShare(int i){
|
public Polynomial.Point getShare(int i){
|
||||||
assert (i > 0 && i <= n);
|
assert (i > 0 && i <= n);
|
||||||
|
@ -64,7 +64,7 @@ public class SecretSharing{
|
||||||
*
|
*
|
||||||
* @return evaluate of interpolation(shares) at x = 0
|
* @return evaluate of interpolation(shares) at x = 0
|
||||||
*/
|
*/
|
||||||
public static BigInteger recoverSecret(Polynomial.Point[] shares, Arithmetic<BigInteger> arithmetic) throws Exception {
|
public static BigInteger recoverSecret(Polynomial.Point[] shares, Arithmetic<BigInteger> arithmetic) {
|
||||||
return recoverPolynomial(shares,arithmetic).evaluate(BigInteger.ZERO);
|
return recoverPolynomial(shares,arithmetic).evaluate(BigInteger.ZERO);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
|
@ -1,4 +1,4 @@
|
||||||
package Arithmetics;
|
package meerkat.crypto.utilitis;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Tzlil on 3/17/2016.
|
* Created by Tzlil on 3/17/2016.
|
|
@ -0,0 +1,26 @@
|
||||||
|
package meerkat.crypto.utilitis;
|
||||||
|
|
||||||
|
import com.google.protobuf.Message;
|
||||||
|
import meerkat.protobuf.DKGMessages;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A generic commmunication channel that supports point-to-point and broadcast operation
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface Channel {
|
||||||
|
public interface ReceiverCallback {
|
||||||
|
public void receiveMail(DKGMessages.Mail mail);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendMessage(int destUser, DKGMessages.Mail.Type type, Message msg);
|
||||||
|
|
||||||
|
public void broadcastMessage(DKGMessages.Mail.Type type, Message msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a callback to handle received messages.
|
||||||
|
* The callback is called in the <b>Channel</b> thread, so no long processing should
|
||||||
|
* occur in the callback method.
|
||||||
|
* @param callback
|
||||||
|
*/
|
||||||
|
public void registerReceiverCallback(ReceiverCallback callback);
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package Arithmetics;
|
package meerkat.crypto.utilitis.concrete;
|
||||||
|
|
||||||
|
import meerkat.crypto.utilitis.Arithmetic;
|
||||||
import org.factcenter.qilin.primitives.concrete.Zpstar;
|
import org.factcenter.qilin.primitives.concrete.Zpstar;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
|
@ -0,0 +1,108 @@
|
||||||
|
package Utils;
|
||||||
|
|
||||||
|
import com.google.protobuf.Message;
|
||||||
|
import meerkat.crypto.utilitis.Channel;
|
||||||
|
import meerkat.protobuf.DKGMessages;
|
||||||
|
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Tzlil on 2/14/2016.
|
||||||
|
*/
|
||||||
|
// TODO: Change nane to network
|
||||||
|
|
||||||
|
public class ChannelImpl implements Channel {
|
||||||
|
|
||||||
|
public static int BROADCAST = 0;
|
||||||
|
private static ChannelImpl[] channels = null;
|
||||||
|
|
||||||
|
protected final Queue<DKGMessages.Mail> mailbox;
|
||||||
|
protected final int id;
|
||||||
|
protected final int n;
|
||||||
|
protected Thread receiverThread;
|
||||||
|
|
||||||
|
|
||||||
|
public ChannelImpl(int id, int n) {
|
||||||
|
if (channels == null){
|
||||||
|
channels = new ChannelImpl[n];
|
||||||
|
}
|
||||||
|
this.mailbox = new ArrayBlockingQueue<DKGMessages.Mail>( n * n * n);
|
||||||
|
this.id = id;
|
||||||
|
this.n = n;
|
||||||
|
channels[id - 1] = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(int destUser, DKGMessages.Mail.Type type, Message msg) {
|
||||||
|
if(destUser < 1 || destUser > n)
|
||||||
|
return;
|
||||||
|
ChannelImpl channel = channels[destUser - 1];
|
||||||
|
if (channel == null)
|
||||||
|
return;
|
||||||
|
DKGMessages.Mail mail = DKGMessages.Mail.newBuilder()
|
||||||
|
.setSender(id)
|
||||||
|
.setDestination(destUser)
|
||||||
|
.setIsPrivate(true)
|
||||||
|
.setType(type)
|
||||||
|
.setMessage(msg.toByteString())
|
||||||
|
.build();
|
||||||
|
synchronized (channel.mailbox) {
|
||||||
|
channel.mailbox.add(mail);
|
||||||
|
channel.mailbox.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void broadcastMessage(DKGMessages.Mail.Type type,Message msg) {
|
||||||
|
ChannelImpl channel;
|
||||||
|
DKGMessages.Mail mail = DKGMessages.Mail.newBuilder()
|
||||||
|
.setSender(id)
|
||||||
|
.setDestination(BROADCAST)
|
||||||
|
.setIsPrivate(false)
|
||||||
|
.setType(type)
|
||||||
|
.setMessage(msg.toByteString())
|
||||||
|
.build();
|
||||||
|
for (int i = 0 ; i < n ; i++){
|
||||||
|
channel = channels[i];
|
||||||
|
synchronized (channel.mailbox) {
|
||||||
|
channel.mailbox.add(mail);
|
||||||
|
channel.mailbox.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerReceiverCallback(final ReceiverCallback callback) {
|
||||||
|
try{
|
||||||
|
receiverThread.interrupt();
|
||||||
|
}catch (Exception e){
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
|
receiverThread = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
while (true){
|
||||||
|
try {
|
||||||
|
synchronized (mailbox) {
|
||||||
|
while (!mailbox.isEmpty()) {
|
||||||
|
callback.receiveMail(mailbox.remove());
|
||||||
|
}
|
||||||
|
mailbox.wait();
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
receiverThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,12 +1,13 @@
|
||||||
package Arithmetics;
|
package Utils;
|
||||||
|
|
||||||
|
import meerkat.crypto.utilitis.Arithmetic;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Tzlil on 3/17/2016.
|
* Created by Tzlil on 4/8/2016.
|
||||||
*/
|
*/
|
||||||
public class Z implements Arithmetic<BigInteger> {
|
public class Z implements Arithmetic<BigInteger> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BigInteger add(BigInteger a, BigInteger b) {
|
public BigInteger add(BigInteger a, BigInteger b) {
|
||||||
return a.add(b);
|
return a.add(b);
|
|
@ -1,7 +1,7 @@
|
||||||
package SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem;
|
package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol;
|
||||||
|
|
||||||
import Communication.Network;
|
import meerkat.crypto.utilitis.Channel;
|
||||||
import JointFeldmanProtocol.DistributedKeyGeneration;
|
import meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.DistributedKeyGeneration;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -10,35 +10,36 @@ import java.util.Set;
|
||||||
/**
|
/**
|
||||||
* Created by Tzlil on 3/29/2016.
|
* Created by Tzlil on 3/29/2016.
|
||||||
*/
|
*/
|
||||||
public class SDKGMaliciousUserImpl extends SecureDistributedKeyGenerationUserImpl {
|
public class SDKGMaliciousUserImpl extends SecureDistributedKeyGenerationUser {
|
||||||
|
|
||||||
private final DistributedKeyGeneration maliciousSDKG;
|
private final DistributedKeyGeneration maliciousSDKG;
|
||||||
private final Set<Integer> falls;
|
private final Set<Integer> falls;
|
||||||
public SDKGMaliciousUserImpl(SecureDistributedKeyGeneration sdkg,SecureDistributedKeyGeneration maliciousSDKG
|
public SDKGMaliciousUserImpl(SecureDistributedKeyGeneration sdkg, SecureDistributedKeyGeneration maliciousSDKG
|
||||||
, Network network,Set<Integer> falls) {
|
, Channel channel, Set<Integer> falls) {
|
||||||
super(sdkg, network);
|
super(sdkg, channel);
|
||||||
this.falls = falls;
|
this.falls = falls;
|
||||||
this.maliciousSDKG = maliciousSDKG;
|
this.maliciousSDKG = maliciousSDKG;
|
||||||
maliciousSDKG.setParties(parties);
|
maliciousSDKG.setParties(parties);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SecureDistributedKeyGeneration generateMaliciousSDKG(SecureDistributedKeyGeneration sdkg,Random random){
|
public static SecureDistributedKeyGeneration generateMaliciousSDKG(SecureDistributedKeyGeneration sdkg,Channel channel,Random random){
|
||||||
BigInteger q = sdkg.getQ();
|
BigInteger q = sdkg.getQ();
|
||||||
BigInteger zi = new BigInteger(q.bitLength(), random).mod(q);
|
BigInteger zi = new BigInteger(q.bitLength(), random).mod(q);
|
||||||
return new SecureDistributedKeyGeneration(sdkg.getT(),sdkg.getN(),zi,random,sdkg.getQ()
|
SecureDistributedKeyGeneration malicious = new SecureDistributedKeyGeneration(sdkg.getT(),sdkg.getN(),zi,random,sdkg.getQ()
|
||||||
,sdkg.getGenerator(),sdkg.getH(),sdkg.getGroup(),sdkg.getId());
|
,sdkg.getGenerator(),sdkg.getH(),sdkg.getGroup(),sdkg.getId(),sdkg.getEncoder());
|
||||||
|
malicious.setChannel(channel);
|
||||||
|
return malicious;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stage1() {
|
public void stage1() {
|
||||||
sdkg.broadcastVerificationValues(user);
|
sdkg.computeAndBroadcastVerificationValues();
|
||||||
sendSecrets(); //insteadof dkg.sendSecrets(user);
|
sendSecrets(); //insteadof dkg.sendSecrets(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stage3() {
|
public void stage3() {
|
||||||
stopReceiver();
|
maliciousSDKG.answerAllComplainingPlayers();
|
||||||
maliciousSDKG.answerAllComplainingPlayers(user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,9 +51,9 @@ public class SDKGMaliciousUserImpl extends SecureDistributedKeyGenerationUserImp
|
||||||
for (int j = 1; j <= n ; j++){
|
for (int j = 1; j <= n ; j++){
|
||||||
if(j != id){
|
if(j != id){
|
||||||
if(falls.contains(j)){
|
if(falls.contains(j)){
|
||||||
maliciousSDKG.sendSecret(user,j);
|
maliciousSDKG.sendSecret(j);
|
||||||
}else {
|
}else {
|
||||||
sdkg.sendSecret(user, j);
|
sdkg.sendSecret(j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,16 +1,18 @@
|
||||||
package SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem;
|
package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol;
|
||||||
|
|
||||||
import Arithmetics.Arithmetic;
|
import meerkat.crypto.utilitis.Arithmetic;
|
||||||
import Arithmetics.Fp;
|
import meerkat.crypto.utilitis.concrete.Fp;
|
||||||
import Communication.Network;
|
import meerkat.crypto.utilitis.Channel;
|
||||||
import FeldmanVerifiableSecretSharing.VerifiableSecretSharing;
|
import Communication.ChannelImpl;
|
||||||
import JointFeldmanProtocol.DKGMaliciousUserImpl;
|
import meerkat.crypto.concrete.secret_shring.feldman_verifiable.VerifiableSecretSharing;
|
||||||
import ShamirSecretSharing.Polynomial;
|
import meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol.DKGMaliciousUser;
|
||||||
import ShamirSecretSharing.SecretSharing;
|
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
|
||||||
import UserInterface.DistributedKeyGenerationUser;
|
import meerkat.crypto.concrete.secret_shring.shamir.SecretSharing;
|
||||||
|
import Utils.BigIntegerByteEncoder;
|
||||||
import Utils.GenerateRandomPrime;
|
import Utils.GenerateRandomPrime;
|
||||||
import org.factcenter.qilin.primitives.Group;
|
import org.factcenter.qilin.primitives.Group;
|
||||||
import org.factcenter.qilin.primitives.concrete.Zpstar;
|
import org.factcenter.qilin.primitives.concrete.Zpstar;
|
||||||
|
import org.factcenter.qilin.util.ByteEncoder;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -25,7 +27,7 @@ import java.util.Set;
|
||||||
*/
|
*/
|
||||||
public class SDKGTest {
|
public class SDKGTest {
|
||||||
|
|
||||||
int tests = 10;
|
int tests = 1;
|
||||||
BigInteger p = GenerateRandomPrime.SafePrime100Bits;
|
BigInteger p = GenerateRandomPrime.SafePrime100Bits;
|
||||||
BigInteger q = p.subtract(BigInteger.ONE).divide(BigInteger.valueOf(2));
|
BigInteger q = p.subtract(BigInteger.ONE).divide(BigInteger.valueOf(2));
|
||||||
Group<BigInteger> group = new Zpstar(p);
|
Group<BigInteger> group = new Zpstar(p);
|
||||||
|
@ -93,14 +95,14 @@ public class SDKGTest {
|
||||||
Set<Integer> QUAL;
|
Set<Integer> QUAL;
|
||||||
Set<Integer> aborted;
|
Set<Integer> aborted;
|
||||||
Set<Integer> malicious;
|
Set<Integer> malicious;
|
||||||
DistributedKeyGenerationUser[] sdkgs;
|
SecureDistributedKeyGenerationUser[] sdkgs;
|
||||||
Thread[] threads;
|
Thread[] threads;
|
||||||
BigInteger g;
|
BigInteger g;
|
||||||
BigInteger h;
|
BigInteger h;
|
||||||
BigInteger secret;
|
BigInteger secret;
|
||||||
|
|
||||||
public Testable(Random random) {
|
public Testable(Random random) {
|
||||||
this.sdkgs = new SecureDistributedKeyGenerationUserImpl[n];
|
this.sdkgs = new SecureDistributedKeyGenerationUser[n];
|
||||||
this.valids = new HashSet<Integer>();
|
this.valids = new HashSet<Integer>();
|
||||||
this.QUAL = new HashSet<Integer>();
|
this.QUAL = new HashSet<Integer>();
|
||||||
this.aborted = new HashSet<Integer>();
|
this.aborted = new HashSet<Integer>();
|
||||||
|
@ -112,16 +114,18 @@ public class SDKGTest {
|
||||||
for (int id = 1; id<= n ; id++){
|
for (int id = 1; id<= n ; id++){
|
||||||
ids.add(id);
|
ids.add(id);
|
||||||
}
|
}
|
||||||
Network network = new Network(n);
|
|
||||||
int id;
|
int id;
|
||||||
BigInteger s;
|
BigInteger s;
|
||||||
|
Channel channel;
|
||||||
SecureDistributedKeyGeneration sdkg;
|
SecureDistributedKeyGeneration sdkg;
|
||||||
this.secret = BigInteger.ZERO;
|
this.secret = BigInteger.ZERO;
|
||||||
|
ByteEncoder<BigInteger> encoder = new BigIntegerByteEncoder();
|
||||||
while (!ids.isEmpty()) {
|
while (!ids.isEmpty()) {
|
||||||
id = ids.remove(random.nextInt(ids.size()));
|
id = ids.remove(random.nextInt(ids.size()));
|
||||||
s = randomIntModQ(random);
|
s = randomIntModQ(random);
|
||||||
sdkg = new SecureDistributedKeyGeneration(t, n, s, random, q, g , h, group, id);
|
channel = new ChannelImpl(id,n);
|
||||||
sdkgs[id - 1] = randomSDKGUser(id,network,sdkg,random);
|
sdkg = new SecureDistributedKeyGeneration(t, n, s, random, q, g , h, group, id,encoder);
|
||||||
|
sdkgs[id - 1] = randomSDKGUser(id,channel,sdkg,random);
|
||||||
threads[id - 1] = new Thread(sdkgs[id - 1]);
|
threads[id - 1] = new Thread(sdkgs[id - 1]);
|
||||||
if(QUAL.contains(id)){
|
if(QUAL.contains(id)){
|
||||||
this.secret = this.secret.add(s).mod(q);
|
this.secret = this.secret.add(s).mod(q);
|
||||||
|
@ -130,30 +134,30 @@ public class SDKGTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SecureDistributedKeyGenerationUserImpl randomSDKGUser(int id,Network network, SecureDistributedKeyGeneration sdkg,Random random){
|
public SecureDistributedKeyGenerationUser randomSDKGUser(int id, Channel channel, SecureDistributedKeyGeneration sdkg, Random random){
|
||||||
if (QUAL.size() <= t) {
|
if (QUAL.size() <= t) {
|
||||||
valids.add(id);
|
valids.add(id);
|
||||||
QUAL.add(id);
|
QUAL.add(id);
|
||||||
return new SecureDistributedKeyGenerationUserImpl(sdkg,network);
|
return new SecureDistributedKeyGenerationUser(sdkg,channel);
|
||||||
}else{
|
}else{
|
||||||
int type = random.nextInt(3);
|
int type = random.nextInt(3);
|
||||||
switch (type){
|
switch (type){
|
||||||
case 0:// regular
|
case 0:// regular
|
||||||
valids.add(id);
|
valids.add(id);
|
||||||
QUAL.add(id);
|
QUAL.add(id);
|
||||||
return new SecureDistributedKeyGenerationUserImpl(sdkg,network);
|
return new SecureDistributedKeyGenerationUser(sdkg,channel);
|
||||||
case 1:// abort
|
case 1:// abort
|
||||||
int abortStage = random.nextInt(3) + 1; // 1 or 2 or 3
|
int abortStage = random.nextInt(3) + 1; // 1 or 2 or 3
|
||||||
aborted.add(id);
|
aborted.add(id);
|
||||||
if (abortStage > 1){
|
if (abortStage > 1){
|
||||||
QUAL.add(id);
|
QUAL.add(id);
|
||||||
}
|
}
|
||||||
return new SDKGUserImplAbort(sdkg,network,abortStage);
|
return new SDKGUserImplAbort(sdkg,channel,abortStage);
|
||||||
case 2:// malicious
|
case 2:// malicious
|
||||||
malicious.add(id);
|
malicious.add(id);
|
||||||
Set<Integer> falls = DKGMaliciousUserImpl.selectFallsRandomly(valids,random);
|
Set<Integer> falls = DKGMaliciousUser.selectFallsRandomly(valids,random);
|
||||||
SecureDistributedKeyGeneration maliciousSDKG = SDKGMaliciousUserImpl.generateMaliciousSDKG(sdkg,random);
|
SecureDistributedKeyGeneration maliciousSDKG = SDKGMaliciousUserImpl.generateMaliciousSDKG(sdkg,channel,random);
|
||||||
return new SDKGMaliciousUserImpl(sdkg,maliciousSDKG,network,falls);
|
return new SDKGMaliciousUserImpl(sdkg,maliciousSDKG,channel,falls);
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
|
@ -1,26 +1,24 @@
|
||||||
package SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem;
|
package meerkat.crypto.concrete.distributed_key_generation.gjkr_secure_protocol;
|
||||||
|
|
||||||
import Communication.Network;
|
import meerkat.crypto.utilitis.Channel;
|
||||||
import SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem.SecureDistributedKeyGeneration;
|
|
||||||
import SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem.SecureDistributedKeyGenerationUserImpl;
|
|
||||||
import meerkat.protobuf.DKGMessages;
|
import meerkat.protobuf.DKGMessages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Tzlil on 3/14/2016.
|
* Created by Tzlil on 3/14/2016.
|
||||||
*/
|
*/
|
||||||
public class SDKGUserImplAbort extends SecureDistributedKeyGenerationUserImpl {
|
public class SDKGUserImplAbort extends SecureDistributedKeyGenerationUser {
|
||||||
|
|
||||||
final int abortStage;
|
final int abortStage;
|
||||||
int stage;
|
int stage;
|
||||||
public SDKGUserImplAbort(SecureDistributedKeyGeneration sdkg, Network network, int abortStage) {
|
public SDKGUserImplAbort(SecureDistributedKeyGeneration sdkg, Channel channel, int abortStage) {
|
||||||
super(sdkg, network);
|
super(sdkg, channel);
|
||||||
this.abortStage = abortStage;// 1 - 4
|
this.abortStage = abortStage;// 1 - 4
|
||||||
this.stage = 1;
|
this.stage = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void abort(){
|
private void abort(){
|
||||||
stopReceiver();
|
//stopReceiver();
|
||||||
user.broadcast(DKGMessages.Mail.Type.ABORT,DKGMessages.EmptyMessage.getDefaultInstance());
|
channel.broadcastMessage(DKGMessages.Mail.Type.ABORT,DKGMessages.EmptyMessage.getDefaultInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
|
@ -1,7 +1,6 @@
|
||||||
package JointFeldmanProtocol;
|
package meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol;
|
||||||
|
|
||||||
import Communication.MailHandler;
|
import meerkat.crypto.utilitis.Channel;
|
||||||
import Communication.Network;
|
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -9,12 +8,12 @@ import java.util.*;
|
||||||
/**
|
/**
|
||||||
* Created by Tzlil on 3/21/2016.
|
* Created by Tzlil on 3/21/2016.
|
||||||
*/
|
*/
|
||||||
public class DKGMaliciousUserImpl extends DistributedKeyGenerationUserImpl {
|
public class DKGMaliciousUser extends DistributedKeyGenerationUser {
|
||||||
|
|
||||||
private final DistributedKeyGeneration maliciousDkg;
|
private final DistributedKeyGeneration maliciousDkg;
|
||||||
private final Set<Integer> falls;
|
private final Set<Integer> falls;
|
||||||
public DKGMaliciousUserImpl(DistributedKeyGeneration dkg,DistributedKeyGeneration maliciousDKG, Network network,Set<Integer> falls) {
|
public DKGMaliciousUser(DistributedKeyGeneration dkg, DistributedKeyGeneration maliciousDKG, Channel channel, Set<Integer> falls) {
|
||||||
super(dkg, network);
|
super(dkg, channel);
|
||||||
this.falls = falls;
|
this.falls = falls;
|
||||||
this.maliciousDkg = maliciousDKG;
|
this.maliciousDkg = maliciousDKG;
|
||||||
maliciousDKG.setParties(parties);
|
maliciousDKG.setParties(parties);
|
||||||
|
@ -33,22 +32,24 @@ public class DKGMaliciousUserImpl extends DistributedKeyGenerationUserImpl {
|
||||||
return falls;
|
return falls;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DistributedKeyGeneration generateMaliciousDKG(DistributedKeyGeneration dkg,Random random){
|
public static DistributedKeyGeneration generateMaliciousDKG(DistributedKeyGeneration dkg,Channel channel,Random random){
|
||||||
BigInteger q = dkg.getQ();
|
BigInteger q = dkg.getQ();
|
||||||
BigInteger zi = new BigInteger(q.bitLength(), random).mod(q);
|
BigInteger zi = new BigInteger(q.bitLength(), random).mod(q);
|
||||||
return new DistributedKeyGeneration(dkg.getT(),dkg.getN(),zi,random,dkg.getQ()
|
DistributedKeyGeneration malicious = new DistributedKeyGeneration(dkg.getT(),dkg.getN(),zi,random,dkg.getQ()
|
||||||
,dkg.getGenerator(),dkg.getGroup(),dkg.getId());
|
,dkg.getGenerator(),dkg.getGroup(),dkg.getId(),dkg.getEncoder());
|
||||||
|
malicious.setChannel(channel);
|
||||||
|
return malicious;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stage1() {
|
public void stage1() {
|
||||||
dkg.broadcastCommitments(user);
|
dkg.broadcastCommitments();
|
||||||
sendSecrets(); //insteadof dkg.sendSecrets(user);
|
sendSecrets(); //insteadof dkg.sendSecrets(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stage3() {
|
public void stage3() {
|
||||||
maliciousDkg.answerAllComplainingPlayers(user);
|
maliciousDkg.answerAllComplainingPlayers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,9 +61,9 @@ public class DKGMaliciousUserImpl extends DistributedKeyGenerationUserImpl {
|
||||||
for (int j = 1; j <= n ; j++){
|
for (int j = 1; j <= n ; j++){
|
||||||
if(j != id){
|
if(j != id){
|
||||||
if(falls.contains(j)){
|
if(falls.contains(j)){
|
||||||
maliciousDkg.sendSecret(user,j);
|
maliciousDkg.sendSecret(j);
|
||||||
}else {
|
}else {
|
||||||
dkg.sendSecret(user, j);
|
dkg.sendSecret(j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,15 +1,17 @@
|
||||||
package JointFeldmanProtocol;
|
package meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol;
|
||||||
|
|
||||||
import Arithmetics.Arithmetic;
|
import meerkat.crypto.utilitis.Arithmetic;
|
||||||
import Arithmetics.Fp;
|
import meerkat.crypto.utilitis.concrete.Fp;
|
||||||
import Communication.Network;
|
import meerkat.crypto.utilitis.Channel;
|
||||||
import FeldmanVerifiableSecretSharing.VerifiableSecretSharing;
|
import Communication.ChannelImpl;
|
||||||
import ShamirSecretSharing.Polynomial;
|
import meerkat.crypto.concrete.secret_shring.feldman_verifiable.VerifiableSecretSharing;
|
||||||
import ShamirSecretSharing.SecretSharing;
|
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
|
||||||
import UserInterface.DistributedKeyGenerationUser;
|
import meerkat.crypto.concrete.secret_shring.shamir.SecretSharing;
|
||||||
|
import Utils.BigIntegerByteEncoder;
|
||||||
import Utils.GenerateRandomPrime;
|
import Utils.GenerateRandomPrime;
|
||||||
import org.factcenter.qilin.primitives.Group;
|
import org.factcenter.qilin.primitives.Group;
|
||||||
import org.factcenter.qilin.primitives.concrete.Zpstar;
|
import org.factcenter.qilin.primitives.concrete.Zpstar;
|
||||||
|
import org.factcenter.qilin.util.ByteEncoder;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -24,7 +26,7 @@ import java.util.Set;
|
||||||
*/
|
*/
|
||||||
public class DKGTest {
|
public class DKGTest {
|
||||||
|
|
||||||
int tests = 10;
|
int tests = 1;
|
||||||
BigInteger p = GenerateRandomPrime.SafePrime100Bits;
|
BigInteger p = GenerateRandomPrime.SafePrime100Bits;
|
||||||
BigInteger q = p.subtract(BigInteger.ONE).divide(BigInteger.valueOf(2));
|
BigInteger q = p.subtract(BigInteger.ONE).divide(BigInteger.valueOf(2));
|
||||||
Group<BigInteger> group = new Zpstar(p);
|
Group<BigInteger> group = new Zpstar(p);
|
||||||
|
@ -99,7 +101,7 @@ public class DKGTest {
|
||||||
BigInteger secret;
|
BigInteger secret;
|
||||||
|
|
||||||
public Testable(Random random) {
|
public Testable(Random random) {
|
||||||
this.dkgs = new DistributedKeyGenerationUserImpl[n];
|
this.dkgs = new DistributedKeyGenerationUser[n];
|
||||||
this.valids = new HashSet<Integer>();
|
this.valids = new HashSet<Integer>();
|
||||||
this.QUAL = new HashSet<Integer>();
|
this.QUAL = new HashSet<Integer>();
|
||||||
this.aborted = new HashSet<Integer>();
|
this.aborted = new HashSet<Integer>();
|
||||||
|
@ -110,16 +112,18 @@ public class DKGTest {
|
||||||
for (int id = 1; id<= n ; id++){
|
for (int id = 1; id<= n ; id++){
|
||||||
ids.add(id);
|
ids.add(id);
|
||||||
}
|
}
|
||||||
Network network = new Network(n);
|
|
||||||
int id;
|
int id;
|
||||||
BigInteger s;
|
BigInteger s;
|
||||||
DistributedKeyGeneration dkg;
|
DistributedKeyGeneration dkg;
|
||||||
this.secret = BigInteger.ZERO;
|
this.secret = BigInteger.ZERO;
|
||||||
|
Channel channel;
|
||||||
|
ByteEncoder<BigInteger> byteEncoder = new BigIntegerByteEncoder();
|
||||||
while (!ids.isEmpty()) {
|
while (!ids.isEmpty()) {
|
||||||
id = ids.remove(random.nextInt(ids.size()));
|
id = ids.remove(random.nextInt(ids.size()));
|
||||||
|
channel = new ChannelImpl(id,n);
|
||||||
s = randomIntModQ(random);
|
s = randomIntModQ(random);
|
||||||
dkg = new DistributedKeyGeneration(t, n, s, random, q, g, group, id);
|
dkg = new DistributedKeyGeneration(t, n, s, random, q, g, group, id,byteEncoder);
|
||||||
dkgs[id - 1] = randomDKGUser(id,network,dkg,random);
|
dkgs[id - 1] = randomDKGUser(id,channel,dkg,random);
|
||||||
threads[id - 1] = new Thread(dkgs[id - 1]);
|
threads[id - 1] = new Thread(dkgs[id - 1]);
|
||||||
if(QUAL.contains(id)){
|
if(QUAL.contains(id)){
|
||||||
this.secret = this.secret.add(s).mod(q);
|
this.secret = this.secret.add(s).mod(q);
|
||||||
|
@ -128,30 +132,30 @@ public class DKGTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DistributedKeyGenerationUser randomDKGUser(int id,Network network, DistributedKeyGeneration dkg,Random random){
|
public DistributedKeyGenerationUser randomDKGUser(int id, Channel channel, DistributedKeyGeneration dkg, Random random){
|
||||||
if (QUAL.size() <= t) {
|
if (QUAL.size() <= t) {
|
||||||
valids.add(id);
|
valids.add(id);
|
||||||
QUAL.add(id);
|
QUAL.add(id);
|
||||||
return new DistributedKeyGenerationUserImpl(dkg,network);
|
return new DistributedKeyGenerationUser(dkg,channel);
|
||||||
}else{
|
}else{
|
||||||
int type = random.nextInt(3);
|
int type = random.nextInt(3);
|
||||||
switch (type){
|
switch (type){
|
||||||
case 0:// regular
|
case 0:// regular
|
||||||
valids.add(id);
|
valids.add(id);
|
||||||
QUAL.add(id);
|
QUAL.add(id);
|
||||||
return new DistributedKeyGenerationUserImpl(dkg,network);
|
return new DistributedKeyGenerationUser(dkg,channel);
|
||||||
case 1:// abort
|
case 1:// abort
|
||||||
int abortStage = random.nextInt(2) + 1; // 1 or 2
|
int abortStage = random.nextInt(2) + 1; // 1 or 2
|
||||||
aborted.add(id);
|
aborted.add(id);
|
||||||
if (abortStage == 2){
|
if (abortStage == 2){
|
||||||
QUAL.add(id);
|
QUAL.add(id);
|
||||||
}
|
}
|
||||||
return new DKGUserImplAbort(dkg,network,abortStage);
|
return new DKGUserImplAbort(dkg,channel,abortStage);
|
||||||
case 2:// malicious
|
case 2:// malicious
|
||||||
malicious.add(id);
|
malicious.add(id);
|
||||||
Set<Integer> falls = DKGMaliciousUserImpl.selectFallsRandomly(valids,random);
|
Set<Integer> falls = DKGMaliciousUser.selectFallsRandomly(valids,random);
|
||||||
DistributedKeyGeneration maliciousDKG = DKGMaliciousUserImpl.generateMaliciousDKG(dkg,random);
|
DistributedKeyGeneration maliciousDKG = DKGMaliciousUser.generateMaliciousDKG(dkg,channel,random);
|
||||||
return new DKGMaliciousUserImpl(dkg,maliciousDKG,network,falls);
|
return new DKGMaliciousUser(dkg,maliciousDKG,channel,falls);
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
|
@ -1,24 +1,24 @@
|
||||||
package JointFeldmanProtocol;
|
package meerkat.crypto.concrete.distributed_key_generation.joint_feldman_protocol;
|
||||||
|
|
||||||
import Communication.Network;
|
import meerkat.crypto.utilitis.Channel;
|
||||||
import meerkat.protobuf.DKGMessages;
|
import meerkat.protobuf.DKGMessages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Tzlil on 3/14/2016.
|
* Created by Tzlil on 3/14/2016.
|
||||||
*/
|
*/
|
||||||
public class DKGUserImplAbort extends DistributedKeyGenerationUserImpl {
|
public class DKGUserImplAbort extends DistributedKeyGenerationUser {
|
||||||
|
|
||||||
final int abortStage;
|
final int abortStage;
|
||||||
int stage;
|
int stage;
|
||||||
public DKGUserImplAbort(DistributedKeyGeneration dkg, Network network, int abortStage) {
|
public DKGUserImplAbort(DistributedKeyGeneration dkg, Channel channel, int abortStage) {
|
||||||
super(dkg, network);
|
super(dkg, channel);
|
||||||
this.abortStage = abortStage;// 1 - 2
|
this.abortStage = abortStage;// 1 - 2
|
||||||
this.stage = 1;
|
this.stage = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void sendAbort(){
|
private void sendAbort(){
|
||||||
user.broadcast(DKGMessages.Mail.Type.ABORT,DKGMessages.EmptyMessage.getDefaultInstance());
|
channel.broadcastMessage(DKGMessages.Mail.Type.ABORT,DKGMessages.EmptyMessage.getDefaultInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
|
@ -1,12 +1,13 @@
|
||||||
package FeldmanVerifiableSecretSharing;
|
package meerkat.crypto.concrete.secret_shring.feldman_verifiable;
|
||||||
|
|
||||||
import ShamirSecretSharing.Polynomial;
|
import meerkat.crypto.concrete.secret_shring.ShamirSecretSharing.Polynomial;
|
||||||
import org.factcenter.qilin.primitives.Group;
|
import org.factcenter.qilin.primitives.Group;
|
||||||
import org.factcenter.qilin.primitives.concrete.Zpstar;
|
import org.factcenter.qilin.primitives.concrete.Zpstar;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,12 +40,12 @@ public class VerifiableSecretSharingTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void oneTest(VerifiableSecretSharing verifiableSecretSharing) throws Exception {
|
public void oneTest(VerifiableSecretSharing<BigInteger> verifiableSecretSharing) throws Exception {
|
||||||
int n = verifiableSecretSharing.getN();
|
int n = verifiableSecretSharing.getN();
|
||||||
Group<BigInteger> zpstar = verifiableSecretSharing.getGroup();
|
Group<BigInteger> zpstar = verifiableSecretSharing.getGroup();
|
||||||
BigInteger g = verifiableSecretSharing.getGenerator();
|
BigInteger g = verifiableSecretSharing.getGenerator();
|
||||||
Polynomial.Point[] shares = new Polynomial.Point[n];
|
Polynomial.Point[] shares = new Polynomial.Point[n];
|
||||||
BigInteger[] commitments = verifiableSecretSharing.getCommitmentsArray();
|
ArrayList<BigInteger> commitments = verifiableSecretSharing.getCommitmentsArrayList();
|
||||||
BigInteger[] verifications = new BigInteger[n];
|
BigInteger[] verifications = new BigInteger[n];
|
||||||
for (int i = 1 ; i <= shares.length; i ++){
|
for (int i = 1 ; i <= shares.length; i ++){
|
||||||
shares[i - 1] = verifiableSecretSharing.getShare(i);
|
shares[i - 1] = verifiableSecretSharing.getShare(i);
|
|
@ -1,7 +1,7 @@
|
||||||
package ShamirSecretSharing.PolynomialTests;
|
package meerkat.crypto.concrete.secret_shring.shamir.PolynomialTests;
|
||||||
import Arithmetics.Z;
|
import Arithmetics.Z;
|
||||||
import Utils.GenerateRandomPolynomial;
|
import Utils.GenerateRandomPolynomial;
|
||||||
import ShamirSecretSharing.Polynomial;
|
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package ShamirSecretSharing.PolynomialTests;
|
package meerkat.crypto.concrete.secret_shring.shamir.PolynomialTests;
|
||||||
|
|
||||||
import Arithmetics.Arithmetic;
|
import meerkat.crypto.utilitis.Arithmetic;
|
||||||
import Arithmetics.Fp;
|
import meerkat.crypto.utilitis.concrete.Fp;
|
||||||
import Utils.GenerateRandomPolynomial;
|
import Utils.GenerateRandomPolynomial;
|
||||||
import ShamirSecretSharing.Polynomial;
|
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
|
||||||
import Utils.GenerateRandomPrime;
|
import Utils.GenerateRandomPrime;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -31,11 +31,11 @@ public class InterpolationTest {
|
||||||
random = new Random();
|
random = new Random();
|
||||||
polynomials = new Polynomial[tests];
|
polynomials = new Polynomial[tests];
|
||||||
pointsArrays = new Polynomial.Point[tests][];
|
pointsArrays = new Polynomial.Point[tests][];
|
||||||
|
arithmetic = new Fp(p);
|
||||||
for (int i = 0; i < polynomials.length; i++){
|
for (int i = 0; i < polynomials.length; i++){
|
||||||
polynomials[i] = GenerateRandomPolynomial.generateRandomPolynomial(random.nextInt(maxDegree),bits,random,p);
|
polynomials[i] = GenerateRandomPolynomial.generateRandomPolynomial(random.nextInt(maxDegree),bits,random,p);
|
||||||
pointsArrays[i] = randomPoints(polynomials[i]);
|
pointsArrays[i] = randomPoints(polynomials[i]);
|
||||||
}
|
}
|
||||||
arithmetic = new Fp(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Polynomial.Point[] randomPoints(Polynomial polynomial){
|
public Polynomial.Point[] randomPoints(Polynomial polynomial){
|
|
@ -1,8 +1,8 @@
|
||||||
package ShamirSecretSharing.PolynomialTests;
|
package meerkat.crypto.concrete.secret_shring.shamir.PolynomialTests;
|
||||||
|
|
||||||
import Arithmetics.Z;
|
import Arithmetics.Z;
|
||||||
import Utils.GenerateRandomPolynomial;
|
import Utils.GenerateRandomPolynomial;
|
||||||
import ShamirSecretSharing.Polynomial;
|
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package ShamirSecretSharing.PolynomialTests;
|
package meerkat.crypto.concrete.secret_shring.shamir.PolynomialTests;
|
||||||
|
|
||||||
import Arithmetics.Z;
|
import Arithmetics.Z;
|
||||||
import Utils.GenerateRandomPolynomial;
|
import Utils.GenerateRandomPolynomial;
|
||||||
import ShamirSecretSharing.Polynomial;
|
import meerkat.crypto.concrete.secret_shring.shamir.Polynomial;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package ShamirSecretSharing;
|
package meerkat.crypto.concrete.secret_shring.shamir;
|
||||||
|
|
||||||
import Arithmetics.Z;
|
import meerkat.crypto.utilitis.concrete.Fp;
|
||||||
import Utils.GenerateRandomPrime;
|
import Utils.GenerateRandomPrime;
|
||||||
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;
|
||||||
|
@ -22,12 +22,12 @@ public class SecretSharingTest {
|
||||||
CyclicGroup<BigInteger> group;
|
CyclicGroup<BigInteger> group;
|
||||||
int tests = 1 << 10;
|
int tests = 1 << 10;
|
||||||
Random random;
|
Random random;
|
||||||
|
BigInteger p = GenerateRandomPrime.SafePrime100Bits;
|
||||||
|
BigInteger q = p.subtract(BigInteger.ONE).divide(BigInteger.valueOf(2));
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void settings(){
|
public void settings(){
|
||||||
BigInteger p = GenerateRandomPrime.SafePrime100Bits;
|
group = new Zn(q);
|
||||||
BigInteger q = p.subtract(BigInteger.ONE).divide(BigInteger.valueOf(2));
|
|
||||||
group = new Zn(p);
|
|
||||||
int t = 9;
|
int t = 9;
|
||||||
int n = 20;
|
int n = 20;
|
||||||
random = new Random();
|
random = new Random();
|
||||||
|
@ -51,7 +51,8 @@ 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.recoverSecret(shares,new Z())));
|
BigInteger calculated = SecretSharing.recoverSecret(shares,new Fp(q));
|
||||||
|
assert (secret.equals(calculated));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
Loading…
Reference in New Issue