Util

threshold_elgamal.util.get_new_params(length=2048)[source]

Generates new parameters for a threshold scheme. Fetches p, q, and g from a predefined list of groups. Then generates h by calculating g^(random number) mod p.

Parameters

length (int) – Length of prime number p.

Returns

(p, q, g, h) parameters for the scheme.

Return type

tuple

threshold_elgamal.util.calculate_lagrange_coeff(i, idxs, q)[source]

Calculates Lagrange coefficients.

Parameters
  • i (int) – Index of the player.

  • idxs (list) – Indexes of all players taking part in calculating the coefficient.

  • q (int) – Modulo.

Returns

Lagrange coefficient.

Return type

int

threshold_elgamal.util.construct_random_polynomial(t, q)[source]

Returns a list of random coefficients for a polynomial of degree t modulo q.

Parameters
  • t (int) – Degree of the polynomial.

  • q (int) – Modulo.

Returns

Coefficients of the random polynomial.

Return type

list

threshold_elgamal.util.polynomial(coeffs, x, q)[source]

Returns a y coordinate for a polynomial with given coefficients over field q.

Parameters
  • coeffs (list) – Coefficients of the polynomial.

  • x (gmpy2.mpz) – x coordinate of the point on the polynomial.

  • q (gmpy2.mpz) – Modulo.

Returns

y coordinate of the point on the polynomial.

Return type

gmpy2.mpz

threshold_elgamal.util.reconstruct_polynomial(points, t, q)[source]

Reconstructs coefficients of a polynomial given a list of points, degree k and modulo q.

Parameters
  • points (list) – Points on the polynomial.

  • q (gmpy2.mpz) – Modulo.

  • t (int) – Degree of the polynomial.

Returns

Constant coefficient of the polynomial.

Return type

gmpy2.mpz