tno.mpc.protocols.secure-comparison

TNO PET Lab - secure Multi-Party Computation (MPC) - Protocols - Secure Comparison

https://github.com/tno-mpc/protocols.secure_comparison

Science Score: 57.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 6 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.6%) to scientific vocabulary

Keywords

homomorphic-encryption mpc mpc-lab multi-party-computation paillier-cryptosystem pet-lab protocols secure-comparison tno
Last synced: 6 months ago · JSON representation ·

Repository

TNO PET Lab - secure Multi-Party Computation (MPC) - Protocols - Secure Comparison

Basic Info
Statistics
  • Stars: 3
  • Watchers: 2
  • Forks: 1
  • Open Issues: 0
  • Releases: 0
Topics
homomorphic-encryption mpc mpc-lab multi-party-computation paillier-cryptosystem pet-lab protocols secure-comparison tno
Created almost 5 years ago · Last pushed about 1 year ago
Metadata Files
Readme License Citation

README.md

TNO PET Lab - secure Multi-Party Computation (MPC) - Protocols - Secure Comparison

Implementation of a secure comparison protocol based on the DGK encryption scheme. The implementation follows the description of the paper Improving the DGK comparison protocol, a paper by Thijs Veugen improving upon the secure comparison protocol by Damgård, Geisler, and Krøigaard.

Note that a correction was published in Correction to "Improving the DGK comparison protocol", which is incorporated in the implementation.

PET Lab

The TNO PET Lab consists of generic software components, procedures, and functionalities developed and maintained on a regular basis to facilitate and aid in the development of PET solutions. The lab is a cross-project initiative allowing us to integrate and reuse previously developed PET functionalities to boost the development of new protocols and solutions.

The package tno.mpc.protocols.secure_comparison is part of the TNO Python Toolbox.

Limitations in (end-)use: the content of this software package may solely be used for applications that comply with international export control laws.
This implementation of cryptographic software has not been audited. Use at your own risk.

Documentation

Documentation of the tno.mpc.protocols.secure_comparison package can be found here.

Install

Easily install the tno.mpc.protocols.secure_comparison package using pip:

console $ python -m pip install tno.mpc.protocols.secure_comparison

Note: If you are cloning the repository and wish to edit the source code, be sure to install the package in editable mode:

console $ python -m pip install -e 'tno.mpc.protocols.secure_comparison'

If you wish to run the tests you can use:

console $ python -m pip install 'tno.mpc.protocols.secure_comparison[tests]'

Note: A significant performance improvement can be achieved by installing the GMPY2 library.

console $ python -m pip install 'tno.mpc.protocols.secure_comparison[gmpy]'

Usage

Usage example:

```python import asyncio

from tno.mpc.communication import Pool from tno.mpc.encryptionschemes.dgk import DGK from tno.mpc.encryptionschemes.paillier import Paillier from tno.mpc.encryptionschemes.utils import nextprime

from tno.mpc.protocols.secure_comparison import Initiator, KeyHolder

async def runprotocol() -> None: taskA = asyncio.createtask(alice.performsecurecomparison(xenc, yenc)) taskB = asyncio.createtask(bob.performsecure_comparison())

x_leq_y_enc, _ = await asyncio.gather(*[taskA, taskB])
x_leq_y = scheme_paillier.decrypt(x_leq_y_enc)
assert x_leq_y == 1

if name == "main": # Set maximum bit length l = 16 # Setup the Paillier scheme schemepaillier = Paillier.fromsecurityparameter(keylength=2048) # Setup the DGK scheme. This may take up to a minute. u = nextprime((1 << (l + 2))) schemedgk = DGK.fromsecurityparameter( vbits=160, nbits=2048, u=u, full_decryption=False )

# Setup communication pools
pool_alice = Pool()
pool_alice.add_http_server(8040)
pool_alice.add_http_client("keyholder", "localhost", 8041)
pool_bob = Pool()
pool_bob.add_http_server(8041)
pool_bob.add_http_client("initiator", "localhost", 8040)

# Encrypt two numbers (x,y) for the protocol and set the maximum bit_length (l)
x = 23
y = 42
x_enc = scheme_paillier.unsafe_encrypt(x)
y_enc = scheme_paillier.unsafe_encrypt(y)

alice = Initiator(l, communicator=pool_alice, other_party="keyholder")
bob = KeyHolder(
    l,
    communicator=pool_bob,
    other_party="initiator",
    scheme_paillier=scheme_paillier,
    scheme_dgk=scheme_dgk,
)

# Run entire protocol interactively:
loop = asyncio.get_event_loop()
loop.run_until_complete(run_protocol())

# Or execute the protocol steps without interaction
z_enc, r = alice.step_1(x_enc, y_enc, l, scheme_paillier)
z, beta = bob.step_2(z_enc, l, scheme_paillier)
alpha = alice.step_3(r, l)
d_enc = bob.step_4a(z, scheme_dgk, scheme_paillier, l)
beta_is_enc = bob.step_4b(beta, l, scheme_dgk)
d_enc = alice.step_4c(d_enc, r, scheme_dgk, scheme_paillier)
alpha_is_xor_beta_is_enc = alice.step_4d(alpha, beta_is_enc)
w_is_enc, alpha_tilde = alice.step_4e(
    r, alpha, alpha_is_xor_beta_is_enc, d_enc, scheme_paillier
)
w_is_enc = alice.step_4f(w_is_enc)
s, delta_a = alice.step_4g()
c_is_enc = alice.step_4h(
    s, alpha, alpha_tilde, d_enc, beta_is_enc, w_is_enc, delta_a, scheme_dgk
)
c_is_enc = alice.step_4i(c_is_enc, scheme_dgk)
delta_b = bob.step_4j(c_is_enc, scheme_dgk)
zeta_1_enc, zeta_2_enc, delta_b_enc = bob.step_5(z, l, delta_b, scheme_paillier)
beta_lt_alpha_enc = alice.step_6(delta_a, delta_b_enc)
x_leq_y_enc = alice.step_7(
    zeta_1_enc, zeta_2_enc, r, l, beta_lt_alpha_enc, scheme_paillier
)
x_leq_y = scheme_paillier.decrypt(x_leq_y_enc)
assert x_leq_y == 1

# Shut down encryption schemes (optional but recommended)
alice.scheme_paillier.shut_down()
alice.scheme_dgk.shut_down()
bob.scheme_paillier.shut_down()
bob.scheme_dgk.shut_down()

```

The communicator object is required only when the protocol is ran through perform_secure_comparison. In that case, one may choose to pass any communicator object that adheres to the tno.mpc.protocols.secure_comparison.Communicator protocol. An example can be found in the unit tests.

! SAFETY NOTICE ! ENSURE CIPHERTEXTS ARE RANDOMIZED

Since version 2.0.0 of tno.mpc.encryption_schemes.paillier and tno.mpc.encryption_schemes.dgk, it is possible to (potentially) make protocols more efficient by delaying randomization of ciphertexts. This library always operates in this 'expert' mode and therefore several protocol steps yield non-randomized ciphertext outputs. As a consequence, if the user chooses to perform the secure comparison steps manually, she needs to make sure that the resulting ciphertexts are randomized before they are communicated. If the tno.mpc.communication library is used (or more specifically, the Paillier and DGK serialize methods), then this will be done automatically for you (but warnings might be raised).

Owner

  • Name: TNO - MPC Lab
  • Login: TNO-MPC
  • Kind: organization
  • Email: mpclab@tno.nl
  • Location: Anna van Buerenplein 1, 2595 DA Den Haag, The Netherlands

TNO - MPC Lab

Citation (CITATION.cff)

cff-version: 1.2.0
license: Apache-2.0
message: If you use this software, please cite it using these metadata.
authors:
  - name: TNO PET Lab
    city: The Hague
    country: NL
    email: petlab@tno.nl
    website: https://pet.tno.nl
type: software
url: https://pet.tno.nl
contact:
  - name: TNO PET Lab
    city: The Hague
    country: NL
    email: petlab@tno.nl
    website: https://pet.tno.nl
repository-code: https://github.com/TNO-MPC/protocols.secure_comparison
repository-artifact: https://pypi.org/project/tno.mpc.protocols.secure_comparison
title: TNO PET Lab - secure Multi-Party Computation (MPC) - Protocols - Secure Comparison
version: 4.4.0
date-released: 2024-12-10

GitHub Events

Total
  • Push event: 2
Last Year
  • Push event: 2

Committers

Last synced: almost 3 years ago

All Time
  • Total Commits: 4
  • Total Committers: 1
  • Avg Commits per committer: 4.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Thomas Rooijakkers t****s@t****l 4
Committer Domains (Top 20 + Academic)
tno.nl: 1

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 0
  • Total pull requests: 1
  • Average time to close issues: N/A
  • Average time to close pull requests: about 4 hours
  • Total issue authors: 0
  • Total pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 3.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
  • b-kamphorst (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 77 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 6
  • Total maintainers: 1
pypi.org: tno.mpc.protocols.secure-comparison

Implementation of secure comparison protocol as given in https://eprint.iacr.org/2018/1100.pdf

  • Versions: 6
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 77 Last month
Rankings
Dependent packages count: 6.6%
Downloads: 18.7%
Average: 22.9%
Stargazers count: 28.2%
Forks count: 30.5%
Dependent repos count: 30.6%
Maintainers (1)
Last synced: 6 months ago

Dependencies

pyproject.toml pypi
  • tno.mpc.communication ~=4.8
  • tno.mpc.encryption_schemes.dgk ~=3.0
  • tno.mpc.encryption_schemes.paillier ~=3.0
  • tno.mpc.encryption_schemes.templates ~=4.1,>=4.1.3
  • tno.mpc.encryption_schemes.utils ~=0.10