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

Or install directly from source:

git clone https://github.com/yourusername/mpc-secret-shares.git
cd mpc-secret-shares/mpc_project
pip install .

Quick Start

import random
from mpc_secret_shares import (
    protocol_1_share,
    protocol_2_reconstruct,
    protocol_4_secure_mult,
    protocol_5_secure_compare,
    protocol_10_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 ---
shares_u = protocol_1_share(S=4, n=n, t=t, P=p)
shares_v = protocol_1_share(S=5, n=n, t=t, P=p)

# --- Secure multiplication: 4 * 5 = 20 ≡ 9 (mod 11) ---
shares_w = protocol_4_secure_mult(shares_u, shares_v, n=n, t=t, P=p)
w = protocol_2_reconstruct(shares_w[:t], p)
print(f"4 × 5 mod 11 = {w}")   # → 9

# --- Secure comparison: 4 < 5 ? ---
shares_cmp = protocol_5_secure_compare(shares_u, shares_v, n=n, t=t, p=p)
cmp_result = protocol_2_reconstruct(shares_cmp[:t], p)
print(f"4 < 5 → {bool(cmp_result)}")   # → True

# --- IsZero test ---
shares_zero = protocol_1_share(S=0, n=n, t=t, P=p)
shares_iz = protocol_10_is_zero(shares_zero, n=n, t=t, p=p)
print(f"IsZero(0) = {protocol_2_reconstruct(shares_iz[:t], p)}")  # → 1

Implemented Protocols

Module Protocol Description
protocol1 Share Shamir secret sharing
protocol2 Reconstruct Lagrange interpolation
protocol3 RNG Shared random number generation
protocol4 SecureMult Secure multiplication
protocol5_secure_compare SecureCompare Secure 1_{u < v}
protocol6_less_than_half_p LessThan_Half_P Secure 1_{a < p/2}
protocol7_lsb LSB Secure least-significant-bit extraction
protocol8_gen_rnd_bit_sharing GenRndBitSharing Random bit generation
protocol9_bitwise_less_than Bitwise_LessThan Bitwise comparison
protocol10 IsZero Secure equality to zero
protocol12 BinaryLongDiv Cleartext binary long division
protocol13_secure_division SecureDivision Secure floor division
algorithm14_bitwise_sqrt BitwiseSqrt Cleartext integer square root
protocol15_secure_sqrt SecureSqrt Secure integer square root
protocol16_mary_or m-ary OR Secure OR via polynomial evaluation
protocol17_improved_mary_or Improved OR Communication-efficient OR
algorithm18_kth_ranked KthRanked Cleartext k-th ranked element
affine_combinations AffineCombo Local α + β·u + γ·v
share_utils Local share arithmetic helpers
secure_inv SecureInv Secure modular inverse

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.1.0.tar.gz (23.1 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.1.0-py3-none-any.whl (29.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mpc_secret_shares-0.1.0.tar.gz
  • Upload date:
  • Size: 23.1 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.1.0.tar.gz
Algorithm Hash digest
SHA256 8ef21aa47123f83f50aa9ba76bc249e197ca58b5364124d7a30981254c1dbdf4
MD5 67a3f499eae95978ebfa6ce4b68ae3d2
BLAKE2b-256 e1900ab6cb41626ee99cb2f504307d2682890d4dadb3bf17a5eee0602d02b0ec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mpc_secret_shares-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9dd3edd7ed69b34d95c0df6a7c851747b2727d6c251eb092bf054a03c8c7c7f3
MD5 7a6b23bbdf1f9a72c14d68eb9dc35420
BLAKE2b-256 5cd0323185cf5b436f8223ecdcbeb2ad041e13bd5cdba4a7e2c3a672dfc0b7e4

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