57 lines
1.6 KiB
Java
57 lines
1.6 KiB
Java
package FeldmanVerifiableSecretSharing;
|
|
|
|
import ShamirSecretSharing.SecretSharing;
|
|
import org.bouncycastle.util.Arrays;
|
|
import org.factcenter.qilin.primitives.CyclicGroup;
|
|
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;
|
|
|
|
public VerifiableSecretSharing(CyclicGroup<BigInteger> group, int t, int n, BigInteger s, Random random) {
|
|
super(group, t, n, s, random);
|
|
this.g = group.getGenerator();
|
|
this.commitments = generateCommitments();
|
|
}
|
|
|
|
private BigInteger[] generateCommitments() {
|
|
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]); //(g ^ coeff[i]) % p
|
|
}
|
|
return commitments;
|
|
}
|
|
|
|
public BigInteger verify(int i) throws Exception {
|
|
if(i < 1 || i > n){
|
|
throw new Exception();
|
|
}
|
|
BigInteger v = group.zero();
|
|
int power = 1;
|
|
for (int j = 0 ; j < commitments.length ; j ++){
|
|
v = group.add(v,commitments[i].pow(power));
|
|
power *=i;
|
|
}
|
|
|
|
return group.add(group.zero(),v);
|
|
}
|
|
|
|
|
|
public BigInteger getG() {
|
|
return g;
|
|
}
|
|
|
|
public BigInteger[] getCommitments() {
|
|
return Arrays.clone(commitments);
|
|
}
|
|
}
|