Skip to main content

MPC primitives over Shamir secret shares, implemented from the SoK paper

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mpc_secret_shares-0.3.0.tar.gz (28.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mpc_secret_shares-0.3.0-py3-none-any.whl (32.9 kB view details)

Uploaded Python 3

File details

Details for the file mpc_secret_shares-0.3.0.tar.gz.

File metadata

  • Download URL: mpc_secret_shares-0.3.0.tar.gz
  • Upload date:
  • Size: 28.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for mpc_secret_shares-0.3.0.tar.gz
Algorithm Hash digest
SHA256 622a1e34f6a184abf80ec31e64c485b88524dfdfc2af805336450172003eadf7
MD5 a7522bb9eccc9bdc8c50c3d690f2c157
BLAKE2b-256 7da93b71c333d1800a689766e62468c9fb21b2511effaedb546caed8d6b4eced

See more details on using hashes here.

File details

Details for the file mpc_secret_shares-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mpc_secret_shares-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 876a2c417888cdd2fbeea0dc860400718a3c5ed2fc5690f0fcaf7a37be57f3fc
MD5 6befb4351338c17b286b33061777fea4
BLAKE2b-256 628bd92532655402e00e3b291331002d3785c826229c38a2503df87a0e18ff7d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page