Skip to main content

mpc-secret-shares

A pure-Python library for Secure Multiparty Computation (MPC) over Secret Shares.

Implements the protocols described in:

SoK: Secure Computation over Secret Shares

All protocols operate over a prime finite field Z_p using Shamir's (t,n)-secret sharing: any t out of n parties can reconstruct a secret; fewer than t parties learn nothing.


Installation

pip install mpc-secret-shares

Quick Start

import random
from mpc_secret_shares import share, reconstruct, secure_mult, secure_lt, is_zero

random.seed(42)

# MPC parameters
p = 11   # prime field Z_11
n = 3    # three parties
t = 2    # any 2 shares reconstruct the secret

# Share two secrets
sh_u = share(S=4, n=n, t=t, P=p)
sh_v = share(S=5, n=n, t=t, P=p)

# Secure multiplication: 4 × 5 = 20 ≡ 9 (mod 11)
sh_w = secure_mult(sh_u, sh_v, n=n, t=t, P=p)
print(f"4 × 5 mod 11 = {reconstruct(sh_w[:t], p)}")   # → 9

# Secure comparison: 4 < 5 ?
sh_cmp = secure_lt(sh_u, sh_v, n=n, t=t, p=p)
print(f"4 < 5 → {bool(reconstruct(sh_cmp[:t], p))}")  # → True

# IsZero test
sh_zero = share(S=0, n=n, t=t, P=p)
print(f"is_zero(0) = {reconstruct(is_zero(sh_zero, n=n, t=t, p=p)[:t], p)}")  # → 1

API Reference

v0.2.0 clean names

Clean name Description
share(S, n, t, P) Shamir secret sharing
reconstruct(shares, p) Lagrange interpolation
secure_mult(u, v, n, t, p) Secure multiplication
secure_lt(u, v, n, t, p) Secure 1_{u < v}
less_than_half_p(u, n, t, p) Secure 1_{u < p/2}
lsb(u, n, t, p) Secure least-significant-bit
random_bit(n, t, p) Shared random bit
bitwise_lt(a, b_bits, n, t, p) Bitwise comparison
is_zero(u, n, t, p) Secure equality to zero
secure_inv(u, n, t, p) Secure modular inverse
secure_div(u, v, u_bits, n, t, p) Secure floor division
secure_sqrt(u, u_bits, n, t, p) Secure integer square root
mary_or(bits, n, t, p) Secure m-ary OR
improved_mary_or(bits, n, t, p) Communication-efficient OR
kth_ranked(dataset, M, k) k-th ranked element (cleartext)

Unchanged names

Name Description
protocol_3_rng(n, t, p) Shared random number
protocol_3_1_affine_combination(a, b, c, u, v, p) Local α + β·u + γ·v
binary_long_division(u, v) Cleartext binary long division
algorithm_14_bitwise_sqrt(u) Cleartext integer square root
compute_or_polynomial_coefficients(m, p) OR polynomial coefficients
square_and_multiply(x, c, n) Modular exponentiation
shares_add / sub / scalar / ... Local share arithmetic

Deprecated names (removed in v1.0)

All protocol_N_* and algorithm_N_* names that have a clean alias above still work but emit a DeprecationWarning on every call.

# Old style (works, but warns):
from mpc_secret_shares import protocol_1_share
sh = protocol_1_share(7, n=3, t=2, P=11)
# DeprecationWarning: 'protocol_1_share' is deprecated; use 'share' instead.

# New style:
from mpc_secret_shares import share
sh = share(7, n=3, t=2, P=11)

Running the Tests

cd mpc_project
pip install pytest
pytest tests/ -v

License

MIT — see LICENSE.

Metadata

Release files for mpc-secret-shares 0.3.0

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

Source distribution (sdist)

Source distribution for mpc-secret-shares 0.3.0
File Size Uploaded
mpc_secret_shares-0.3.0.tar.gz 28.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mpc-secret-shares 0.3.0
File Interpreter ABI Platform
mpc_secret_shares-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 61.3 kB

Release files / mpc_secret_shares-0.3.0.tar.gz

Download URL mpc_secret_shares-0.3.0.tar.gz
Size 28.4 kB
Tags Source
SHA-256 checksum
How to use checksums
622a1e34f6a184abf80ec31e64c485b88524dfdfc2af805336450172003eadf7
BLAKE2b-256 checksum
How to use checksums
7da93b71c333d1800a689766e62468c9fb21b2511effaedb546caed8d6b4eced
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.2

Release files / mpc_secret_shares-0.3.0-py3-none-any.whl

Download URL mpc_secret_shares-0.3.0-py3-none-any.whl
Size 32.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
876a2c417888cdd2fbeea0dc860400718a3c5ed2fc5690f0fcaf7a37be57f3fc
BLAKE2b-256 checksum
How to use checksums
628bd92532655402e00e3b291331002d3785c826229c38a2503df87a0e18ff7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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