Skip to main content

TNO PET Lab - secure Multi-Party Computation (MPC) - Encryption Schemes - Shamir

Implementation of the Shamir Secret Sharing scheme.

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.encryption_schemes.shamir 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.encryption_schemes.shamir package can be found here.

Install

Easily install the tno.mpc.encryption_schemes.shamir package using pip:

$ python -m pip install tno.mpc.encryption_schemes.shamir

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

$ python -m pip install -e 'tno.mpc.encryption_schemes.shamir'

If you wish to run the tests you can use:

$ python -m pip install 'tno.mpc.encryption_schemes.shamir[tests]'

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

$ python -m pip install 'tno.mpc.encryption_schemes.shamir[gmpy]'

Usage

The shamir secret sharing module can be used as follows:

from tno.mpc.encryption_schemes.shamir import ShamirSecretSharingScheme, ShamirShares

# Initialize a three-out-of-five secrect sharing scheme with prime 10657
# Note: the polynomial degree is one less than the number of parties needed for reconstruction
shamir_scheme = ShamirSecretSharingScheme(10657, 5, 2)
# Share a secret integer
sharing = shamir_scheme.share_secret(42)
# When receiving shares a reconstructor can be created as follows
reconstructor = ShamirShares(
    shamir_scheme, {1: sharing.shares[1], 2: sharing.shares[2], 3: sharing.shares[3]}
)
# Reconstruct the secret and check if it is the expected result
assert 42 == sharing.reconstruct_secret() == reconstructor.reconstruct_secret()

For the performance it is important to bear in mind the following information: Both ShamirSecretSharingScheme and ShamirSecretSharingIntegers make use of a VanderMonde matrix when sharing a secret. The size of this matrix grows exponentially with the number of parties. This matrix is constructed on-the-fly, which means that the first time the property van_der_monde is called, this matrix is constructed. This generally happens during the secret_share operation. If you would like to initialize this in an earlier stage, you can put the following piece of code wherever you want the initialization to take place:

# scheme is initialized
scheme = ShamirSecretSharingScheme(...)

# VanderMonde matrix is initialized
_ = scheme.van_der_monde

Release files for tno.mpc.encryption-schemes.shamir 1.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tno.mpc.encryption-schemes.shamir 1.3.2
File Size Uploaded
tno_mpc_encryption_schemes_shamir-1.3.2.tar.gz 19.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tno.mpc.encryption-schemes.shamir 1.3.2
File Interpreter ABI Platform
tno.mpc.encryption_schemes.shamir-1.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 38.5 kB

Release files / tno_mpc_encryption_schemes_shamir-1.3.2.tar.gz

Download URL tno_mpc_encryption_schemes_shamir-1.3.2.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f1653d76dbd8fd5353e156acf8ed31c1f204c71b2a8296fc4d83665d77095776
BLAKE2b-256 checksum
How to use checksums
b09ca6d52ae9b04aec61dfc93ce4b535c28f1da545b26f6015015c3278b36483
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / tno.mpc.encryption_schemes.shamir-1.3.2-py3-none-any.whl

Download URL tno.mpc.encryption_schemes.shamir-1.3.2-py3-none-any.whl
Size 19.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7819f86113f364e19a37e3386cb5268ef04d6d7822cd6d6af9bbfb1f3fbfe500
BLAKE2b-256 checksum
How to use checksums
4b169dcc6fa4223a5d070ecc7430ea8c32b9be991696a14f36afb7434b1b7a33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

This release

1.3.2 This release

2 release files

1.1.0

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page