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

57 lines
1.6 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 {
private final BigInteger[] commitments;
private final BigInteger g;
2016-01-27 18:47:07 -05:00
public VerifiableSecretSharing(CyclicGroup<BigInteger> group, int t, int n, BigInteger s, Random random) {
super(group, t, n, s, random);
this.g = group.getGenerator();
2016-01-27 06:41:24 -05:00
this.commitments = generateCommitments();
}
private BigInteger[] generateCommitments() {
BigInteger[] coefficients = polynomial.getCoefficients();
BigInteger[] commitments = new BigInteger[coefficients.length];
for (int i = 0 ; i < commitments.length;i++){
2016-01-27 18:47:07 -05:00
commitments[i] = group.multiply(g,coefficients[i]); //(g ^ coeff[i]) % p
2016-01-27 06:41:24 -05:00
}
return commitments;
}
public BigInteger verify(int i) throws Exception {
if(i < 1 || i > n){
throw new Exception();
}
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-27 18:47:07 -05:00
return group.add(group.zero(),v);
2016-01-27 06:41:24 -05:00
}
public BigInteger getG() {
return g;
}
public BigInteger[] getCommitments() {
return Arrays.clone(commitments);
}
}