secure_comparison.keyholder module
Party that holds the secret keys. Bob; B in the paper.
- class secure_comparison.keyholder.KeyHolder(l_maximum_bit_length, communicator=None, other_party='', scheme_paillier=None, scheme_dgk=None, session_id=0)[source]
Bases:
object
Player Bob in the secure comparison protocol, holds the keys.
- __init__(l_maximum_bit_length, communicator=None, other_party='', scheme_paillier=None, scheme_dgk=None, session_id=0)[source]
- Parameters:
l_maximum_bit_length (
int
) – maximum bit length used to constrain variables (\(l\)).communicator (
Optional
[Communicator
]) – object for handling communication with the Initiator during the protocol.other_party (
str
) – identifier of the other partyscheme_paillier (
Optional
[Paillier
]) – Paillier encryption scheme (including secret key) used to produce \([[x]]\) and \([[y]]\), Alice’s input.scheme_dgk (
Optional
[DGK
]) – DGK encryption scheme (including secret key).session_id (
int
) – keeps track of the session.
- async make_and_send_encryption_schemes(session_id=1, key_length_paillier=2048, v_bits_dgk=160, n_bits_dgk=2048)[source]
Initialize Paillier and DGK encryption schemes if they don’t already exist and sends public keys to Alice.
- Parameters:
session_id (
int
) – integer to distinguish between sessionkey_length_paillier (
int
) – key length paillierv_bits_dgk (
int
) – number of bits DGK private keys \(v_p\) and \(v_q\)n_bits_dgk (
int
) – number of bits DGK public key \(n\)
- Raises:
ValueError – raised when communicator is not propertly configured.
- Return type:
None
- async perform_secure_comparison()[source]
Performs the secure comparison secure comparison for Bob. Including required communication with Alice.
- Raises:
ValueError – raised when communicator is not properly configured.
- Return type:
None
- static step_2(z_enc, l, scheme_paillier)[source]
\(B\) decrypts \([[z]]\), and computes \(\beta = z \mod 2^l\).
- Parameters:
z_enc (
PaillierCiphertext
) – Encrypted value of \(z\): \([[z]]\).l (
int
) – Fixed value, such that \(0 \leq x,y < 2^l\), for any \(x, y\) that will be given as input to this method.scheme_paillier (
Paillier
) – Paillier encryption scheme.
- Return type:
Tuple
[int
,int
]- Returns:
Tuple containing as first entry the plaintext value of \(z\). The second entry is the value \(\beta = z \mod 2^l\).
- static step_4a(z, scheme_dgk, scheme_paillier, l)[source]
\(B\) computes the encrypted bit \([d]\) where \(d = (z < (N - 1)/2)\) is the bit informing \(A\) whether a carryover has occurred.
- Parameters:
z (
int
) – Plaintext value of \(z\).scheme_dgk (
DGK
) – DGK encryption scheme.scheme_paillier (
Paillier
) – Paillier encryption scheme.
- Return type:
DGKCiphertext
- Returns:
Encrypted value of the bit \(d = (z < (N - 1)/2)\): \([d]\).
- static step_4b(beta, l, scheme_dgk)[source]
\(B\) computes the encrypted bits \([\beta_i], 0 \leq i < l\) to \(A\).
- Parameters:
beta (
int
) – The value \(\beta\) from step 2.l (
int
) – Fixed value, such that \(0 \leq x,y < 2^l\), for any \(x, y\) that will be given as input to this method.scheme_dgk (
DGK
) – DGK encryption scheme.
- Return type:
List
[DGKCiphertext
]- Returns:
List containing the encrypted values of the bits \(\beta_i\): \([\beta_i], 0 \leq i < l\) to \(A\).
- static step_4j(c_is_enc, scheme_dgk)[source]
\(B\) checks whether one of the numbers \(c_i\) is decrypted to zero. If he finds one, \(\delta_B \leftarrow 1\), else \(\delta_B \leftarrow 0\).
- Parameters:
c_is_enc (
List
[DGKCiphertext
]) – List containing the encrypted values of the bits \(c_i\): \([c_i], 0 \leq i < l\).scheme_dgk (
DGK
) – DGK encryption scheme.
- Return type:
int
- Returns:
Value \(\delta_B\).
- static step_5(z, l, delta_b, scheme_paillier)[source]
\(B\) computes \(\zeta_1 = z \div 2^l\) and encrypts it to \([[\zeta_1]]\) and computes \(\zeta_2 = (z + N) \div 2^l\) and encrypts it to \([[\zeta_2]]\). \(B\) also encrypts \(\delta_B\) to \([[\delta_B]]\).
- Parameters:
z (
int
) – Plaintext value of \(z\).l (
int
) – Fixed value, such that \(0 \leq x,y < 2^l\), for any \(x, y\) that will be given as input to this method.delta_b (
int
) – The value \(\delta_B\) from step 4j.scheme_paillier (
Paillier
) – Paillier encryption scheme.
- Return type:
Tuple
[PaillierCiphertext
,PaillierCiphertext
,PaillierCiphertext
]- Returns:
A tuple with the first entry being the encrypted value of \(\zeta_1\): \([[\zeta_1]]\). The second entry is the encrypted value of \(\zeta_2\): \([[\zeta_2]]\). The third entry is the encrypted value of \(\delta_B\): \([[\delta_B]]\).