@Test public void testGenerateShares() { int n = 9; int threshold = 5; final BigInteger[] coefficients = Shamir.generateCoefficients(threshold); final BigInteger secret = RandomNumberGenerator.generateRandomInteger(r); coefficients[0] = secret; final ShamirShare[] shares = Shamir.generateShares(coefficients, n); final Set<ShamirShare> shareSet = new HashSet<>(Arrays.asList(shares)); for (int i = 0; i <= n; i++) { if (i == 0) { final BigInteger result = Polynomials.interpolateComplete(shareSet, threshold, i); Assert.assertEquals(secret, result); } else { final BigInteger result = Polynomials.interpolateComplete(shareSet, threshold, i); Assert.assertNotEquals(secret, result); } } }
public static ShamirShare[] generateShares(final BigInteger[] coefficients, final int n) { ShamirShare[] shares = new ShamirShare[n]; for (int i = 0; i < n; i++) { final BigInteger xCoord = BigInteger.valueOf(i + 1); shares[i] = Polynomials.evaluatePolynomial(coefficients, xCoord, r); } return shares; }
Shamir { public static ShamirShare[] generateShares(final BigInteger[] coefficients, final int n) { ShamirShare[] shares = new ShamirShare[n]; for (int i = 0; i < n; i++) { final BigInteger xCoord = BigInteger.valueOf(i + 1); shares[i] = Polynomials.evaluatePolynomial(coefficients, xCoord, r); } return shares; } }
Shamir { public static ShamirShare[] generateShares(final BigInteger[] coefficients, final int n) { ShamirShare[] shares = new ShamirShare[n]; for (int i = 0; i < n; i++) { final BigInteger xCoord = BigInteger.valueOf(i + 1); shares[i] = Polynomials.evaluatePolynomial(coefficients, xCoord, r); } return shares; }  }
Shamir { public static ShamirShare[] generateShares(final BigInteger[] coefficients, final int n) { ShamirShare[] shares = new ShamirShare[n]; for (int i = 0; i < n; i++) { final BigInteger xCoord = BigInteger.valueOf(i + 1); shares[i] = Polynomials.evaluatePolynomial(coefficients, xCoord, r); } return shares; }  static BigInteger[] generateCoefficients(final int threshold); static BigInteger[] generateCoefficients(final int threshold, final int indexOfZero); static EcPoint[] generateFeldmanValues(final BigInteger[] coefficients); static EcPoint[] generateFeldmanValues(final BigInteger[] coefficients, final EcPoint base); static ShamirShare[] generateShares(final BigInteger[] coefficients, final int n); static void verifyShamirShareConsistency(final ShamirShare share, final EcPoint[] feldmanValues); static EcPoint[] computeSharePublicKeys(final EcPoint[] feldmanValues, final int n); static EcPoint computeSharePublicKey(final EcPoint[] feldmanValues, final int xPosition); }
Shamir { public static ShamirShare[] generateShares(final BigInteger[] coefficients, final int n) { ShamirShare[] shares = new ShamirShare[n]; for (int i = 0; i < n; i++) { final BigInteger xCoord = BigInteger.valueOf(i + 1); shares[i] = Polynomials.evaluatePolynomial(coefficients, xCoord, r); } return shares; }  static BigInteger[] generateCoefficients(final int threshold); static BigInteger[] generateCoefficients(final int threshold, final int indexOfZero); static EcPoint[] generateFeldmanValues(final BigInteger[] coefficients); static EcPoint[] generateFeldmanValues(final BigInteger[] coefficients, final EcPoint base); static ShamirShare[] generateShares(final BigInteger[] coefficients, final int n); static void verifyShamirShareConsistency(final ShamirShare share, final EcPoint[] feldmanValues); static EcPoint[] computeSharePublicKeys(final EcPoint[] feldmanValues, final int n); static EcPoint computeSharePublicKey(final EcPoint[] feldmanValues, final int xPosition); final static EcCurve curve; final static BigInteger r; final static EcPoint G; }