meerkat-java/destributed-key-generation/src/main/java/FeldmanVerifiableSecretSharing/VerifiableSecretSharing.java

78 lines
2.2 KiB
Java
Raw Normal View History

2016-01-27 06:41:24 -05:00
package FeldmanVerifiableSecretSharing;
import ShamirSecretSharing.SecretSharing;
import org.bouncycastle.util.Arrays;
2016-01-27 18:47:07 -05:00
import org.factcenter.qilin.primitives.CyclicGroup;
2016-01-27 06:41:24 -05:00
import org.factcenter.qilin.primitives.concrete.Zpstar;
import java.math.BigInteger;
import java.util.Random;
/**
* Created by Tzlil on 1/27/2016.
*/
public class VerifiableSecretSharing extends SecretSharing {
2016-01-28 06:57:47 -05:00
private final CyclicGroup<BigInteger> group;
private final BigInteger g; // public generator of group
2016-01-27 06:41:24 -05:00
private final BigInteger[] commitments;
2016-01-28 06:57:47 -05:00
/**
* @param group a cyclic group of prime order p.
* it must be chosen such that computing discrete logarithms is hard in this group.
*/
2016-01-27 18:47:07 -05:00
public VerifiableSecretSharing(CyclicGroup<BigInteger> group, int t, int n, BigInteger s, Random random) {
2016-01-28 06:57:47 -05:00
super(group.orderUpperBound(), t, n, s, random);
this.group = group;
2016-01-27 18:47:07 -05:00
this.g = group.getGenerator();
2016-01-27 06:41:24 -05:00
this.commitments = generateCommitments();
}
2016-01-28 06:57:47 -05:00
/**
* @return commitments[i] = g ^ polynomial.coefficients[i]
*/
2016-01-27 06:41:24 -05:00
private BigInteger[] generateCommitments() {
BigInteger[] coefficients = polynomial.getCoefficients();
BigInteger[] commitments = new BigInteger[coefficients.length];
for (int i = 0 ; i < commitments.length;i++){
2016-01-28 06:57:47 -05:00
commitments[i] = group.multiply(g,coefficients[i]);
2016-01-27 06:41:24 -05:00
}
return commitments;
}
2016-01-28 06:57:47 -05:00
/**
* @param i share holder id
* @param commitments
* @param group
*
* @return product of commitments[j] ^ (i ^ j) == g ^ polynomial(i)
*/
public static BigInteger verify(int i,BigInteger[] commitments,CyclicGroup<BigInteger> group) {
2016-01-27 18:47:07 -05:00
BigInteger v = group.zero();
2016-01-27 06:41:24 -05:00
int power = 1;
for (int j = 0 ; j < commitments.length ; j ++){
2016-01-27 18:47:07 -05:00
v = group.add(v,commitments[i].pow(power));
2016-01-27 06:41:24 -05:00
power *=i;
}
2016-01-28 06:57:47 -05:00
return v;
2016-01-27 06:41:24 -05:00
}
2016-01-28 06:57:47 -05:00
/**
* getter
* @return generator of group
*/
public BigInteger getGenerator() {
2016-01-27 06:41:24 -05:00
return g;
}
2016-01-28 06:57:47 -05:00
/**
* getter
* @return copy of commitments
*/
2016-01-27 06:41:24 -05:00
public BigInteger[] getCommitments() {
return Arrays.clone(commitments);
}
}