This repository contains demonstration code for the TNO PET Lab, showcasing secure multi-party computation (MPC) protocols. It demonstrates three core MPC capabilities: secure communication between parties, homomorphic encryption using the Paillier cryptosystem, and secret sharing using Shamir's scheme.
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.demo.futurepet 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 of the tno.mpc.demo.futurepet package can be found
here.
First, create a Python virtual environment using one of the following methods:
Using the standard Python venv module:
$ python -m venv .venvOr using uv:
$ uv venvActivate the virtual environment:
On Linux/macOS:
$ source .venv/bin/activateOn Windows:
$ .venv\Scripts\activateInstall the package in editable mode with test dependencies:
$ uv pip install -e ".[tests]"Alternatively, if you're not using uv, you can use regular pip:
$ pip install -e ".[tests]"The demo can be run directly using Python:
$ python src/tno/mpc/demo/futurepet/demo.pyThe demo file contains three different demonstrations that can be run by uncommenting the corresponding line in the __main__ block:
-
Communication Demo (
demo_communication()): Demonstrates basic secure message passing between two parties (Alice and Bob). -
Homomorphic Encryption Demo (
demo_homomorphic_encryption()): Shows how parties can perform computations on encrypted data using the Paillier cryptosystem. Alice encrypts her value, Bob performs addition with his encrypted value, and Alice decrypts the result. -
Secret Sharing Demo (
demo_secret_sharing()): Demonstrates Shamir's secret sharing scheme with three parties (Alice, Bob, and Charlie), where each party shares a secret value and they collectively compute the sum without revealing individual values.
By default, the secret sharing demo is enabled. To run a different demo, edit the demo.py file and uncomment the desired demo function.
For hands-on experimentation, a sandbox.py file is provided at the root of the repository. This file contains boilerplate code for setting up three-party communication and clearly marked sections where you can experiment with:
- Homomorphic Encryption: Perform computations on encrypted data using the Paillier cryptosystem
- Secret Sharing: Use Shamir's secret sharing to compute on distributed secrets
To use the sandbox:
$ python sandbox.pyThe file contains detailed comments marking "YOUR CODE HERE" sections where you can:
- Change secret values
- Implement different cryptographic operations
- Experiment with addition, multiplication, and other computations
- See results from all three parties (Alice, Bob, and Charlie)