ThresholdElGamal

class threshold_elgamal.elgamal.ThresholdElGamal(k=3, n=5, length=2048)[source]

Threshold scheme for ElGamal cryptosystem.

Parameters
  • k (int) – Threshold.

  • n (int) – Total number of players.

  • length (int) – Length of prime number p.

decrypt(c2, decryption_shares)[source]

Runs a distributed decryption algorithm using the ElGamal cryptosystem.

Parameters
  • c2 (str) – Encryption part c2.

  • decryption_shares (dict) – Decryption shares.

Returns

Decrypted message.

Return type

int

encrypt(pk, message, r=None)[source]

Encrypts given message with given public key using the ElGamal cryptosystem.

Parameters
  • pk (gmpy2.mpz) – Public key.

  • message (int) – Message.

  • r (gmpy2.mpz) – Value r in the encryption algorithm.

Returns

Encryption parts c1 and c2.

Return type

tuple

get_or_generate_params()[source]

Generates parameters for threshold scheme (p, q, g, h) if not already generated, and if so, returns them together with parameters k and n.

Returns

Dictionary of parameters for the scheme.

Return type

dict

threshold_elgamal.elgamal.create_tc_scheme(k, n, length=2048)[source]

Creates an ElGamal threshold scheme.

Parameters
  • length (int) – Length of prime number p used in the scheme.

  • k (int) – Threshold.

  • n (int) – Total number of players.

Returns

Public key, list of players, scheme object.

Return type

tuple

threshold_elgamal.elgamal.run_tc_scheme(k, n, m, length=2048)[source]

Runs an ElGamal threshold scheme.

Parameters
  • length (int) – Length of prime number p used as modulo in the scheme.

  • k (int) – Threshold.

  • n (int) – Total number of players.

  • m (int) – Message.

Returns

The validity of the run scheme.

Return type

bool