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.2.0.tar.gz (24.7 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.2.0-py3-none-any.whl (30.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mpc_secret_shares-0.2.0.tar.gz
  • Upload date:
  • Size: 24.7 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.2.0.tar.gz
Algorithm Hash digest
SHA256 9d422101c6717aad630c4ea519fe9fdb6a6a14a21a4dfb4c99425cd024e4b5f8
MD5 89effe5c2af8b6a8a77bc79dd120a38d
BLAKE2b-256 96773fb31d643462ccf3c521b0178582870d8b6c0ee65bdc489106238d0ca4d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mpc_secret_shares-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 712e2805cc35a6642fecdfa49ea57e5a08f0e06becce57f5e3b666bd404777ec
MD5 0bb6a43edfc47d366b050c2984d8de8c
BLAKE2b-256 23626c2b234fd06f5aaea1c90e49dcef21667f60673b96472ffaaece1debe4ca

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