TNO Protocols¶
Implementation of the secure comparison protocol.
This building block is included in the TNO MPC Python Toolbox.
Note:¶
A significant performance improvement for some algorithms can be achieved by installing the GMPY2 library. The protocol currently only uses Paillier, instead of Paillier and DGK.
Install¶
Install the tno.mpc.protocols package using one of the following options.
Personal access token
Deploy tokens
Cloning this repo (developer mode)
Personal access token¶
Generate a personal access token with
read_api
scope. Instruction are found here.Install
python -m pip install tno.mpc.protocols.secure_comparison --extra-index-url https://__token__:<personal_access_token>@ci.tno.nl/gitlab/api/v4/projects/7468/packages/pypi/simple
Deploy tokens¶
Generate a deploy token with
read_package_registry
scope. Instruction are found here.Install
python -m pip install tno.mpc.protocols.secure_comparison --extra-index-url https://<GITLAB_DEPLOY_TOKEN>:<GITLAB_DEPLOY_PASSWORD>@ci.tno.nl/gitlab/api/v4/projects/7468/packages/pypi/simple
Dockerfile¶
FROM python:3.8
ARG GITLAB_DEPLOY_TOKEN
ARG GITLAB_DEPLOY_PASSWORD
RUN python -m pip install tno.mpc.protocols.secure_comparison --extra-index-url https://$GITLAB_DEPLOY_TOKEN:$GITLAB_DEPLOY_PASSWORD@ci.tno.nl/gitlab/api/v4/projects/7468/packages/pypi/simple
Usage¶
Usage (examples/example.py
):
from tno.mpc.protocols.secure_comparison.secure_comparison import *
from tno.mpc.encryption_schemes.paillier import Paillier
if __name__ == "__main__":
# Setup the paillier scheme
scheme = Paillier.from_security_parameter(key_length=2048)
# Encrypt two numbers (x,y) for the protocol and set the maximum bit_length (l)
x = 23
y = 42
x_enc = scheme.encrypt(x)
y_enc = scheme.encrypt(y)
l = 10
# Execute the protocol steps (Note: a real implementation still needs to take care of the
# communication.
z_enc, r = step_1(x_enc, y_enc, l)
z, beta = step_2(z_enc, l)
alpha = step_3(r, l)
d_enc = step_4a(z, scheme)
beta_is_enc = step_4b(beta, l, scheme)
d_enc = step_4c(d_enc, r)
alpha_is_xor_beta_is_enc = step_4d(alpha, beta_is_enc)
w_is_enc, alpha_tilde = step_4e(r, alpha, alpha_is_xor_beta_is_enc, d_enc)
w_is_enc = step_4f(w_is_enc)
s, delta_a = step_4g()
c_is_enc = step_4h(s, alpha, alpha_tilde, d_enc, beta_is_enc, w_is_enc, delta_a)
c_is_enc = step_4i(c_is_enc)
c_is_enc = shuffle(c_is_enc) # do a random shuffle of c_is_enc
delta_b = step_4j(c_is_enc)
zeta_1_enc, zeta_2_enc, delta_b_enc = step_5(z, l, delta_b, scheme)
beta_lt_alpha_enc = step_6(delta_a, delta_b_enc)
x_leq_y_enc = step_7(zeta_1_enc, zeta_2_enc, r, l, beta_lt_alpha_enc)
x_leq_y = scheme.decrypt(x_leq_y_enc)
assert x_leq_y == 1