package FeldmanVerifiableSecretSharing; import ShamirSecretSharing.SecretSharing; import org.bouncycastle.util.Arrays; 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(Zpstar zpstar, int t, int n, BigInteger s, Random random) { super(zpstar, t, n, s, random); this.g = BigInteger.ONE; //ToDO zpstar.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] = zpstar.multiply(g,coefficients[i]); } return commitments; } public BigInteger verify(int i) throws Exception { if(i < 1 || i > n){ throw new Exception(); } BigInteger v = BigInteger.ONE; int power = 1; for (int j = 0 ; j < commitments.length ; j ++){ v.multiply(commitments[i].pow(power)); power *=i; } return zpstar.add(BigInteger.ONE,v); } public BigInteger getG() { return g; } public BigInteger[] getCommitments() { return Arrays.clone(commitments); } }