distributed_keygen.distributed_keygen module
Code for a single player in the Paillier distributed key-generation protocol
- class distributed_keygen.distributed_keygen.DistributedPaillier(public_key, secret_key, precision, pool, index, party_indices, shares, session_id, distributed, **kwargs)[source]
Bases:
Paillier
,SupportsSerialization
Class that acts as one of the parties involved in distributed Paillier secret key generation. The pool represents the network of parties involved in the key generation protocol.
- __eq__(other)[source]
Compare this Distributed Paillier scheme with another to determine (in)equality. Does not take the secret key into account as it might not be known and the public key combined with the precision and the session id.
- Parameters:
other (
object
) – Object to compare this Paillier scheme with.- Return type:
bool
- Returns:
Boolean value representing (in)equality of both objects.
- classmethod asend(pool, handler_name, message, msg_id=None)[source]
Function that sends a message to a certain party in the pool
- Parameters:
pool (
Pool
) – network of involved partieshandler_name (
str
) – receivermessage (
Any
) – python object to be sentmsg_id (
Optional
[str
]) – optional
- Return type:
None
- classmethod broadcast(message, pool, message_id=None, receivers=None)[source]
Function that sends a message to all other parties in the pool
- Parameters:
message (
Any
) – python objectpool (
Pool
) – network of involved partiesmessage_id (
Optional
[str
]) – optional message IDreceivers (
Optional
[List
[str
]]) – optional list of receivers
- Return type:
None
- async classmethod compute_modulus(shares, zero_share, index, pool, prime_list, party_indices, prime_length, shamir_scheme, correct_param_biprime)[source]
Function that starts a protocol to generate candidates for p and q the multiplication of the two is then checked for biprimality to ensure it is a valid modulus. This is run until it succeeds.
- Parameters:
shares (
Shares
) – dictionary that keeps track of shares for parties for certain numberszero_share (
ShamirShares
) – A secret sharing of 0 in a 2t-out-of-n shamir secret sharing schemeindex (
int
) – index of this partypool (
Pool
) – network of involved partiesprime_list (
List
[int
]) – list of prime numbersparty_indices (
Dict
[str
,int
]) – mapping from party names to indicesprime_length (
int
) – desired bit length of p and qshamir_scheme (
ShamirSecretSharingScheme
) – t-out-of-n Shamir secret sharing schemecorrect_param_biprime (
int
) – correctness parameter that affects the certainty that the generated N is a product of two primes
- Return type:
int
- Returns:
modulus N
- async decrypt(ciphertext, apply_encoding=True, receivers=None)[source]
Decrypts the input ciphertext. Starts a protocol between the parties involved to create local decryptions, send them to the other parties and combine them into full decryptions for each party.
- Parameters:
ciphertext (
PaillierCiphertext
) – Ciphertext to be decrypted.apply_encoding (
bool
) – Boolean indicating whether the decrypted ciphertext is decoded before it is returned. Defaults to True.receivers (
Optional
[List
[str
]]) – An optional list specifying the names of the receivers, your own ‘name’ is “self”.
- Return type:
Union
[int
,float
,FixedPoint
,None
]- Returns:
Plaintext decrypted value.
- default_biprime_param = 40
- default_corruption_threshold = 1
- default_key_length = 2048
- default_prime_threshold = 2000
- default_sec_shamir = 40
- static deserialize(json_obj, **_kwargs)[source]
Deserialization function for Distributed Paillier schemes, which will be passed to the communication module
- Parameters:
json_obj (
Dict
[str
,Any
]) – serialization of a distributed paillier scheme._kwargs (
Any
) – optional extra keyword arguments
- Return type:
Union
[DistributedPaillier
,Paillier
]- Returns:
Deserialized DistributedPaillier scheme, local instance thereof, or a regular Paillier scheme in case this party is not part of the distributed session.
- async classmethod from_security_parameter(pool, corruption_threshold=1, key_length=2048, prime_threshold=2000, correct_param_biprime=40, stat_sec_shamir=40, distributed=True, precision=0)[source]
Function that takes security parameters related to secret sharing and Paillier and initiates a protocol to create a shared secret key between the parties in the provided pool.
- Parameters:
precision (
int
) – precision of the fixed point encoding in Paillierpool (
Pool
) – The network of involved partiescorruption_threshold (
int
) – Maximum number of allowed corruptions. we require for the number of parties in the pool and the corruption threshold that number_of_parties >= 2 * corruption_threshold + 1. This is because we need to multiply secret sharings that both use polynomials of degree corruption_threshold. The resulting secret sharing then becomes a polynomial of degree 2*corruption_threshold and it requires at least 2*corruption_threshold+1 evaluation points to reconstruct the secret in that sharing.key_length (
int
) – desired bit length of the modulus \(N\)prime_threshold (
int
) – Upper bound on the number of prime numbers to check during primality testscorrect_param_biprime (
int
) – parameter that affects the certainty of the generated \(N\) to be the product of two primesstat_sec_shamir (
int
) – security parameter for the Shamir secret sharing over the integersdistributed (
bool
) – Whether the different parties are run on different python instancesprecision – precision (number of decimals) to ensure
- Raises:
ValueError – In case the number of parties \(n\) and the corruption threshold \(t\) do not satisfy that \(n \geq 2*t + 1\)
Exception – In case the parties agree on a session id that is already being used.
- Return type:
- Returns:
DistributedPaillier scheme containing a regular Paillier public key and a shared secret key.
Gather all shares with label content
- Parameters:
content (
str
) – string identifying a numberpool (
Pool
) – network of involved partiesshares (
Shares
) – dictionary keeping track of shares of different parties for certain numbersparty_indices (
Dict
[str
,int
]) – mapping from party names to indices
- Raises:
NotImplementedError – In case the given content is not any of the possible values for which we store shares (“p”, “q”, “n”, “biprime”, “lambda_”, “beta”, “secret_key”, “partial_decryption”).
- Return type:
None
- async classmethod generate_keypair(stat_sec_shamir, number_of_players, corruption_threshold, shares, index, zero_share, pool, prime_list, prime_length, party_indices, correct_param_biprime, shamir_scheme)[source]
Function to distributively generate a shared secret key and a corresponding public key
- Parameters:
stat_sec_shamir (
int
) – security parameter for Shamir secret sharing over the integersnumber_of_players (
int
) – number of parties involved in the protocolcorruption_threshold (
int
) – number of parties that are allowed to be corruptedshares (
Shares
) – dictionary that keeps track of shares for parties for certain numbersindex (
int
) – index of this partyzero_share (
ShamirShares
) – A secret sharing of 0 in a 2t-out-of-n shamir secret sharing schemepool (
Pool
) – network of involved partiesprime_list (
List
[int
]) – list of prime numbersprime_length (
int
) – desired bit length of p and qparty_indices (
Dict
[str
,int
]) – mapping from party names to indicescorrect_param_biprime (
int
) – correctness parameter that affects the certainty that the generated N is a product of two primesshamir_scheme (
ShamirSecretSharingScheme
) – t-out-of-n Shamir secret sharing scheme
- Return type:
Tuple
[PaillierPublicKey
,PaillierSharedKey
]- Returns:
regular Paillier public key and a shared secret key
- async classmethod generate_pq(shares, pool, index, prime_length, party_indices, shamir_scheme)[source]
” Function to generate primes p and q
- Parameters:
shares (
Shares
) – dictionary that keeps track of shares for parties for certain numberspool (
Pool
) – network of involved partiesindex (
int
) – index of this partyprime_length (
int
) – desired bit length of p and qparty_indices (
Dict
[str
,int
]) – mapping from party names to indicesshamir_scheme (
ShamirSecretSharingScheme
) – t-out-of-n Shamir secret sharing scheme
- Return type:
Tuple
[ShamirShares
,ShamirShares
]- Returns:
sharings of p and q
Generate a random value between 2^(length-1) and 2^length. the function will ensure that the random value is equal to 3 mod 4 for the fist player, and to 0 mod 4 for all other players. This is necessary to generate additive shares of p and q, or the bi-primality test will not work.
- Parameters:
index (
int
) – index of this partyprime_length (
int
) – desired bit length of primes p and q
- Return type:
int
- Returns:
a random integer of the desired bit length and value modulo 4
- async classmethod generate_secret_key(stat_sec_shamir, number_of_players, corruption_threshold, shares, index, zero_share, pool, prime_list, prime_length, party_indices, correct_param_biprime, shamir_scheme)[source]
Functions that generates the modulus and sets up the sharing of the private key
- Parameters:
stat_sec_shamir (
int
) – security parameter for the Shamir secret sharing over the integersnumber_of_players (
int
) – total number of participants in this session (including self)corruption_threshold (
int
) – Maximum number of allowed corruptionsshares (
Shares
) – dictionary that keeps track of shares for parties for certain numbersindex (
int
) – index of this partyzero_share (
ShamirShares
) – A secret sharing of 0 in a 2t-out-of-n shamir secret sharing schemepool (
Pool
) – network of involved partiesprime_list (
List
[int
]) – list of prime numbersprime_length (
int
) – desired bit length of p and qparty_indices (
Dict
[str
,int
]) – mapping from party names to indicescorrect_param_biprime (
int
) – correctness parameter that affects the certainty that the generated N is a product of two primesshamir_scheme (
ShamirSecretSharingScheme
) – t-out-of-n Shamir secret sharing scheme
- Return type:
- Returns:
shared secret key
- async classmethod get_indices(pool)[source]
Function that initiates a protocol to determine IDs (indices) for each party
- Parameters:
pool (
Pool
) – network of involved parties- Return type:
Tuple
[Dict
[str
,int
],int
]- Returns:
dictionary from party name to index, where the entry “self” contains this party’s index
Create a secret-sharing of the input value, and send each share to the corresponding player, together with the label content
- Parameters:
content (
str
) – string identifying the number to be shared and sentshares (
Shares
) – dictionary keeping track of shares for different parties and numbersint_shamir_scheme (
ShamirSecretSharingIntegers
) – Shamir secret sharing scheme over the integersindex (
int
) – index of this partypool (
Pool
) – network of involved partiesparty_indices (
Dict
[str
,int
]) – mapping from party names to indices
- Raises:
NotImplementedError – In case the given content is not “lambda_” or “beta”.
- Return type:
None
- async classmethod recv(pool, handler_name, msg_id=None)[source]
Function that receives a message from a certain party in the pool
- Parameters:
pool (
Pool
) – network for involved partieshandler_name (
str
) – name of the party that sent the messagemsg_id (
Optional
[str
]) – optional message id of the expected message
- Return type:
Any
- Returns:
python object
- async classmethod recv_all(pool)[source]
Function that retrieves one message for each party
- Parameters:
pool (
Pool
) – network of involved parties- Return type:
Tuple
[Tuple
[str
,Any
]]- Returns:
list of tuples containing the party and their message
- serialize(**kwargs)[source]
Serialization function for Distributed Paillier schemes, which will be passed to the communication module
- Parameters:
kwargs (
Any
) – optional extra keyword arguments- Return type:
Dict
[str
,Any
]- Returns:
Dictionary containing the JSON serialization of this DistributedPaillier scheme.
- classmethod setup_input(pool, key_length, prime_threshold, corruption_threshold)[source]
Function that sets initial variables for the process of creating a shared secret key
- Parameters:
pool (
Pool
) – network of involved partieskey_length (
int
) – desired bit length of the modulus \(N = p \cdot q\)prime_threshold (
int
) – Bound on the number of prime numbers to be checked for primality testscorruption_threshold (
int
) – Number of parties that are allowed to be corrupted
- Return type:
Tuple
[int
,int
,List
[int
],ShamirSecretSharingScheme
,Shares
,List
[str
]]- Returns:
A tuple of initiated variables, containing first the number_of_players, second the length of the primes \(p\) and \(q\), third a list of small primes for the small_prime test (empty if the length of \(p\) and \(q\) is smaller than the prime_threshold), fourth a regular Shamir Sharing scheme, fifth a Shares data structure for holding relevant shares, and last a list of the names of other parties.
- async classmethod setup_protocol(shamir_scheme, other_parties, pool)[source]
Function that initiates a protocol to determine IDs and sets own ID Additionally, the protocol prepares a secret sharing of 0 under a 2t-out-of-n threshold scheme to be used later on.
- Parameters:
shamir_scheme (
ShamirSecretSharingScheme
) – Shamir secret sharing scheme to be used for p and qother_parties (
List
[str
]) – Names of the other parties in the poolpool (
Pool
) – network of involved parties
- Return type:
Tuple
[int
,Dict
[str
,int
],ShamirShares
,int
]- Returns:
This party’s index, a dictionary with indices for the other parties, and a zero-sharing in a 2t-out-of-n thresholds scheme to be used later on, the session id
Create a secret-sharing of the input value, and send each share to the corresponding player, together with the label content
- Parameters:
content (
str
) – string identifying the number to be shared and sentshares (
Shares
) – dictionary keeping track of shares for different parties and numbersshamir_scheme (
ShamirSecretSharingScheme
) – t-out-of-n Shamir secret sharing schemeindex (
int
) – index of this partypool (
Pool
) – network of involved partiesparty_indices (
Dict
[str
,int
]) – mapping from party names to indices
- Raises:
NotImplementedError – In case the given content is not “p” or “q”.
- Return type:
None