tested with malicious users
parent
e4a33af4d4
commit
5f45c1f6d6
|
@ -3,7 +3,10 @@ package Communication;
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
import com.google.protobuf.Message;
|
import com.google.protobuf.Message;
|
||||||
import meerkat.protobuf.DKGMessages.*;
|
import meerkat.protobuf.DKGMessages.*;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ArrayBlockingQueue;
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
/**
|
/**
|
||||||
* Created by Tzlil on 2/7/2016.
|
* Created by Tzlil on 2/7/2016.
|
||||||
|
@ -15,23 +18,23 @@ public class Network {
|
||||||
|
|
||||||
protected final User[] users;
|
protected final User[] users;
|
||||||
protected final int n;
|
protected final int n;
|
||||||
protected final Queue<Integer> availableIDs;
|
protected final Set<Integer> availableIDs;
|
||||||
public static final int BROADCAST = 0;
|
public static final int BROADCAST = 0;
|
||||||
|
|
||||||
|
|
||||||
public Network(int n) {
|
public Network(int n) {
|
||||||
this.n = n;
|
this.n = n;
|
||||||
this.users = new User[n];
|
this.users = new User[n];
|
||||||
this.availableIDs = new ArrayBlockingQueue<Integer>(n);
|
this.availableIDs = new HashSet<Integer>();
|
||||||
for (int id = 1; id <= n; id++){
|
for (int id = 1; id <= n; id++){
|
||||||
availableIDs.add(id);
|
availableIDs.add(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public User connect(MailHandler mailHandler){
|
public User connect(MailHandler mailHandler,int id){
|
||||||
Integer id = availableIDs.poll();
|
if (!availableIDs.contains(id))
|
||||||
if (id == null)
|
|
||||||
return null;
|
return null;
|
||||||
|
availableIDs.remove(id);
|
||||||
users[id - 1] = new User(id,this,mailHandler);
|
users[id - 1] = new User(id,this,mailHandler);
|
||||||
return users[id - 1];
|
return users[id - 1];
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class DistributedKeyGenerationUserImpl implements DistributedKeyGeneratio
|
||||||
|
|
||||||
this.messageHandler = new MessageHandler();
|
this.messageHandler = new MessageHandler();
|
||||||
mailHandler.setMessageHandler(this.messageHandler);
|
mailHandler.setMessageHandler(this.messageHandler);
|
||||||
this.user = network.connect(mailHandler);
|
this.user = network.connect(mailHandler,dkg.getId());
|
||||||
this.parties = dkg.getParties();
|
this.parties = dkg.getParties();
|
||||||
|
|
||||||
this.parties[id - 1].share = dkg.getShare(id);
|
this.parties[id - 1].share = dkg.getShare(id);
|
||||||
|
@ -230,7 +230,7 @@ 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[i - 1].complaints[j - 1] = ComplainState.Waiting;
|
parties[j - 1].complaints[i - 1] = ComplainState.Waiting;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package ShamirSecretSharing;
|
package ShamirSecretSharing;
|
||||||
|
|
||||||
import Arithmetics.Arithmetic;
|
import Arithmetics.Arithmetic;
|
||||||
|
import Arithmetics.Fp;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -45,7 +46,7 @@ public class SecretSharing{
|
||||||
for (int i = 1 ; i <= t; i++ ){
|
for (int i = 1 ; i <= t; i++ ){
|
||||||
coefficients[i] = new BigInteger(bits,random).mod(q);
|
coefficients[i] = new BigInteger(bits,random).mod(q);
|
||||||
}
|
}
|
||||||
return new Polynomial(coefficients);
|
return new Polynomial(coefficients,new Fp(q));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,174 @@
|
||||||
|
package JointFeldmanProtocol;
|
||||||
|
|
||||||
|
import Arithmetics.Arithmetic;
|
||||||
|
import Arithmetics.Fp;
|
||||||
|
import Communication.Network;
|
||||||
|
import FeldmanVerifiableSecretSharing.VerifiableSecretSharing;
|
||||||
|
import ShamirSecretSharing.Polynomial;
|
||||||
|
import ShamirSecretSharing.SecretSharing;
|
||||||
|
import UserInterface.DistributedKeyGenerationUser;
|
||||||
|
import org.factcenter.qilin.primitives.Group;
|
||||||
|
import org.factcenter.qilin.primitives.concrete.Zpstar;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Tzlil on 3/21/2016.
|
||||||
|
*/
|
||||||
|
public class DKGDeepTest {
|
||||||
|
|
||||||
|
int tests = 10;
|
||||||
|
BigInteger p = BigInteger.valueOf(2903);
|
||||||
|
BigInteger q = p.subtract(BigInteger.ONE).divide(BigInteger.valueOf(2));
|
||||||
|
Group<BigInteger> group = new Zpstar(p);
|
||||||
|
Arithmetic<BigInteger> arithmetic = new Fp(q);
|
||||||
|
int t = 9;
|
||||||
|
int n = 20;
|
||||||
|
|
||||||
|
Testable[] testables;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void settings(){
|
||||||
|
testables = new Testable[n];
|
||||||
|
for (int i = 0; i < tests; i++){
|
||||||
|
testables[i] = new Testable(new Random());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void oneTest(int test) throws Exception {
|
||||||
|
Testable testable = testables[test];
|
||||||
|
for (int i = 0; i < testable.threads.length ; i++){
|
||||||
|
testable.threads[i].start();
|
||||||
|
}
|
||||||
|
for (int i = 0; i < testable.threads.length ; i++){
|
||||||
|
testable.threads[i].join();
|
||||||
|
}
|
||||||
|
|
||||||
|
// got the right public value
|
||||||
|
BigInteger publicValue = group.multiply(testable.g,testable.secret);
|
||||||
|
for (int i: testable.QUAL){
|
||||||
|
if(!testable.aborted.contains(i))
|
||||||
|
assert (testable.dkgs[i - 1].getPublicValue().equals(publicValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
// assert valid verification values
|
||||||
|
BigInteger expected,verification;
|
||||||
|
for (int i: testable.QUAL){
|
||||||
|
if(!testable.aborted.contains(i)) {
|
||||||
|
expected = group.multiply(testable.g, testable.dkgs[i - 1].getShare().y);
|
||||||
|
verification = VerifiableSecretSharing.verify(i, testable.dkgs[i - 1].getCommitments(), group);
|
||||||
|
assert (expected.equals(verification));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// restore the secret from shares
|
||||||
|
ArrayList<Polynomial.Point> sharesList = new ArrayList<Polynomial.Point>();
|
||||||
|
|
||||||
|
for(int i : testable.QUAL){
|
||||||
|
if(!testable.aborted.contains(i))
|
||||||
|
sharesList.add(testable.dkgs[i - 1].getShare());
|
||||||
|
}
|
||||||
|
Polynomial.Point[] shares = new Polynomial.Point[sharesList.size()];
|
||||||
|
for (int i = 0; i < shares.length; i ++){
|
||||||
|
shares[i] = sharesList.get(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
BigInteger calculatedSecret = SecretSharing.restoreSecret(shares,arithmetic);
|
||||||
|
assert (calculatedSecret.equals(testable.secret));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() throws Exception {
|
||||||
|
for (int i = 0; i < tests; i++){
|
||||||
|
oneTest(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Testable{
|
||||||
|
Set<Integer> QUAL;
|
||||||
|
Set<Integer> aborted;
|
||||||
|
Set<Integer> malicious;
|
||||||
|
DistributedKeyGenerationUser[] dkgs;
|
||||||
|
Thread[] threads;
|
||||||
|
BigInteger g;
|
||||||
|
BigInteger secret;
|
||||||
|
public Testable(Random random) {
|
||||||
|
|
||||||
|
this.dkgs = new DistributedKeyGenerationUserImpl[n];
|
||||||
|
this.QUAL = new HashSet<Integer>();
|
||||||
|
this.aborted = new HashSet<Integer>();
|
||||||
|
this.malicious = new HashSet<Integer>();
|
||||||
|
this.threads = new Thread[n];
|
||||||
|
this.g = sampleGenerator(random);
|
||||||
|
ArrayList<Integer> ids = new ArrayList<Integer>();
|
||||||
|
for (int id = 1; id<= n ; id++){
|
||||||
|
ids.add(id);
|
||||||
|
}
|
||||||
|
Network network = new Network(n);
|
||||||
|
int id;
|
||||||
|
BigInteger s;
|
||||||
|
DistributedKeyGeneration dkg;
|
||||||
|
this.secret = BigInteger.ZERO;
|
||||||
|
while (!ids.isEmpty()) {
|
||||||
|
id = ids.remove(random.nextInt(ids.size()));
|
||||||
|
s = randomIntModQ(random);
|
||||||
|
dkg = new DistributedKeyGeneration(t, n, s, random, q, g, group, id);
|
||||||
|
dkgs[id - 1] = randomDKGUser(id,network,dkg,random);
|
||||||
|
threads[id - 1] = new Thread(dkgs[id - 1]);
|
||||||
|
if(QUAL.contains(id)){
|
||||||
|
this.secret = this.secret.add(s).mod(q);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public DistributedKeyGenerationUser randomDKGUser(int id,Network network, DistributedKeyGeneration dkg,Random random){
|
||||||
|
if (QUAL.size() <= t) {
|
||||||
|
QUAL.add(id);
|
||||||
|
return new DistributedKeyGenerationUserImpl(dkg,network);
|
||||||
|
}else{
|
||||||
|
int type = random.nextInt(3);
|
||||||
|
switch (type){
|
||||||
|
case 0:// regular
|
||||||
|
QUAL.add(id);
|
||||||
|
return new DistributedKeyGenerationUserImpl(dkg,network);
|
||||||
|
case 1:// abort
|
||||||
|
int abortStage = random.nextInt(2) + 1; // 1 or 2
|
||||||
|
aborted.add(id);
|
||||||
|
if (abortStage == 2){
|
||||||
|
QUAL.add(id);
|
||||||
|
}
|
||||||
|
return new DKGUserImplAbort(dkg,network,abortStage);
|
||||||
|
case 2:// malicious
|
||||||
|
malicious.add(id);
|
||||||
|
return new DKGMaliciousUserImpl(dkg,network,random);
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigInteger sampleGenerator(Random random){
|
||||||
|
BigInteger ZERO = group.zero();
|
||||||
|
BigInteger g;
|
||||||
|
do {
|
||||||
|
g = group.sample(random);
|
||||||
|
} while (!g.equals(ZERO) && !group.multiply(g, q).equals(ZERO));
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigInteger randomIntModQ(Random random){
|
||||||
|
return new BigInteger(q.bitLength(), random).mod(q);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
package JointFeldmanProtocol;
|
||||||
|
|
||||||
|
import Communication.MailHandler;
|
||||||
|
import Communication.Network;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Tzlil on 3/21/2016.
|
||||||
|
*/
|
||||||
|
public class DKGMaliciousUserImpl extends DistributedKeyGenerationUserImpl {
|
||||||
|
|
||||||
|
private final DistributedKeyGeneration maliciousDkg;
|
||||||
|
private final Set<Integer> falls;
|
||||||
|
public DKGMaliciousUserImpl(DistributedKeyGeneration dkg, Network network, Random random) {
|
||||||
|
super(dkg, network);
|
||||||
|
this.falls = selectFalls(random);
|
||||||
|
this.maliciousDkg = new DistributedKeyGeneration(t,n,randomInt(random),random,dkg.getQ(),g,group,id);
|
||||||
|
maliciousDkg.setParties(parties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Integer> selectFalls(Random random){
|
||||||
|
ArrayList<Integer> ids = new ArrayList<Integer>();
|
||||||
|
for (int i = 1; i<= n ; i++){
|
||||||
|
if(i!=id) {
|
||||||
|
ids.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Set<Integer> falls = new HashSet<Integer>();
|
||||||
|
int fallsSize = random.nextInt(ids.size()) + 1;// 1 - (n-1)
|
||||||
|
while (falls.size() < fallsSize){
|
||||||
|
falls.add(ids.remove(random.nextInt(ids.size())));
|
||||||
|
}
|
||||||
|
return falls;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stage1() {
|
||||||
|
dkg.broadcastCommitments(user);
|
||||||
|
sendSecrets(); //insteadof dkg.sendSecrets(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stage3() {
|
||||||
|
maliciousDkg.answerAllComplainingPlayers(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stage4(){
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
private BigInteger randomInt(Random random){
|
||||||
|
BigInteger q = dkg.getQ();
|
||||||
|
return new BigInteger(q.bitLength(), random).mod(q);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendSecrets(){
|
||||||
|
for (int j = 1; j <= n ; j++){
|
||||||
|
if(j != id){
|
||||||
|
if(falls.contains(j)){
|
||||||
|
maliciousDkg.sendSecret(user,j);
|
||||||
|
}else {
|
||||||
|
dkg.sendSecret(user, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
package JointFeldmanProtocol;
|
package JointFeldmanProtocol;
|
||||||
|
|
||||||
|
import Arithmetics.Arithmetic;
|
||||||
|
import Arithmetics.Fp;
|
||||||
import Arithmetics.Z;
|
import Arithmetics.Z;
|
||||||
import Communication.Network;
|
import Communication.Network;
|
||||||
import ShamirSecretSharing.Polynomial;
|
import ShamirSecretSharing.Polynomial;
|
||||||
|
@ -27,10 +29,12 @@ public class DKGTest {
|
||||||
BigInteger q = p.subtract(BigInteger.ONE).divide(BigInteger.valueOf(2));
|
BigInteger q = p.subtract(BigInteger.ONE).divide(BigInteger.valueOf(2));
|
||||||
BigInteger[] secrets;
|
BigInteger[] secrets;
|
||||||
Set<Integer> QUAL = new HashSet<Integer>();
|
Set<Integer> QUAL = new HashSet<Integer>();
|
||||||
|
Arithmetic<BigInteger> arithmetic;
|
||||||
@Before
|
@Before
|
||||||
public void settings(){
|
public void settings(){
|
||||||
Zpstar zpstar = new Zpstar(p);
|
Zpstar zpstar = new Zpstar(p);
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
|
arithmetic = new Fp(q);
|
||||||
BigInteger g;
|
BigInteger g;
|
||||||
int t = 9;
|
int t = 9;
|
||||||
int n = 20;
|
int n = 20;
|
||||||
|
@ -39,7 +43,7 @@ public class DKGTest {
|
||||||
threadsArrays = new Thread[tests][n];
|
threadsArrays = new Thread[tests][n];
|
||||||
secrets = new BigInteger[tests];
|
secrets = new BigInteger[tests];
|
||||||
DistributedKeyGeneration dkg;
|
DistributedKeyGeneration dkg;
|
||||||
int abortedStage = 2;
|
int abortedStage = 1;
|
||||||
for (int test = 0; test < tests; test++) {
|
for (int test = 0; test < tests; test++) {
|
||||||
do {
|
do {
|
||||||
g = zpstar.sample(random);
|
g = zpstar.sample(random);
|
||||||
|
@ -51,7 +55,7 @@ public class DKGTest {
|
||||||
dkg = new DistributedKeyGeneration(t,n,secret,random,q,g,zpstar,i);
|
dkg = new DistributedKeyGeneration(t,n,secret,random,q,g,zpstar,i);
|
||||||
|
|
||||||
if(i == n) {
|
if(i == n) {
|
||||||
dkgsArrays[test][i - 1] = new DKGUserImplAbort(dkg, network, abortedStage);
|
dkgsArrays[test][i - 1] = new DKGMaliciousUserImpl(dkg,network,random);//new DKGUserImplAbort(dkg, network, abortedStage);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dkgsArrays[test][i - 1] = new DistributedKeyGenerationUserImpl(dkg, network);
|
dkgsArrays[test][i - 1] = new DistributedKeyGenerationUserImpl(dkg, network);
|
||||||
|
@ -104,7 +108,7 @@ public class DKGTest {
|
||||||
shares[i] = sharesList.get(i);
|
shares[i] = sharesList.get(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
BigInteger calculatedSecret = SecretSharing.restoreSecret(shares,new Z()).mod(q);
|
BigInteger calculatedSecret = SecretSharing.restoreSecret(shares,arithmetic);
|
||||||
assert (calculatedSecret.equals(secret));
|
assert (calculatedSecret.equals(secret));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
|
package SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem;
|
||||||
|
|
||||||
|
import Arithmetics.Arithmetic;
|
||||||
|
import Arithmetics.Fp;
|
||||||
import Arithmetics.Z;
|
import Arithmetics.Z;
|
||||||
import Communication.Network;
|
import Communication.Network;
|
||||||
import FeldmanVerifiableSecretSharing.VerifiableSecretSharing;
|
import FeldmanVerifiableSecretSharing.VerifiableSecretSharing;
|
||||||
import SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem.SecureDistributedKeyGeneration;
|
|
||||||
import SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem.SecureDistributedKeyGenerationUserImpl;
|
|
||||||
import ShamirSecretSharing.Polynomial;
|
import ShamirSecretSharing.Polynomial;
|
||||||
import ShamirSecretSharing.SecretSharing;
|
import ShamirSecretSharing.SecretSharing;
|
||||||
import UserInterface.DistributedKeyGenerationUser;
|
import UserInterface.DistributedKeyGenerationUser;
|
||||||
|
@ -31,10 +33,13 @@ public class SDKGTest {
|
||||||
|
|
||||||
Set<Integer> QUAL = new HashSet<Integer>();
|
Set<Integer> QUAL = new HashSet<Integer>();
|
||||||
|
|
||||||
|
Arithmetic<BigInteger> arithmetic;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void settings(){
|
public void settings(){
|
||||||
Zpstar zpstar = new Zpstar(p);
|
Zpstar zpstar = new Zpstar(p);
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
|
arithmetic = new Fp(q);
|
||||||
BigInteger g,h;
|
BigInteger g,h;
|
||||||
int t = 9;
|
int t = 9;
|
||||||
int n = 20;
|
int n = 20;
|
||||||
|
@ -108,7 +113,7 @@ public class SDKGTest {
|
||||||
shares[i] = sharesList.get(i);
|
shares[i] = sharesList.get(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
BigInteger calculatedSecret = SecretSharing.restoreSecret(shares,new Z()).mod(q);
|
BigInteger calculatedSecret = SecretSharing.restoreSecret(shares,arithmetic);
|
||||||
assert (calculatedSecret.equals(secret));
|
assert (calculatedSecret.equals(secret));
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,3 +1,5 @@
|
||||||
|
package SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem;
|
||||||
|
|
||||||
import Communication.Network;
|
import Communication.Network;
|
||||||
import SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem.SecureDistributedKeyGeneration;
|
import SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem.SecureDistributedKeyGeneration;
|
||||||
import SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem.SecureDistributedKeyGenerationUserImpl;
|
import SecureDistributedKeyGenerationForDiscreteLogBasedCryptosystem.SecureDistributedKeyGenerationUserImpl;
|
Loading…
Reference in New Issue