kennysong / tinysmpc

A tiny, educational library for secure multi-party computation (in pure Python).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TinySMPC 🛡️

A tiny library for secure multi-party computation, in pure Python!

This code is intended for educational rather than practical purposes. It exposes a simple API, and the underlying implementation is written to be understandable and minimalistic.

Get Started

Read the short tutorial notebook, or run it in your browser with Deepnote:

Overview

The goal is to allow multiple users/computers to collaboratively compute a function over their secret data (e.g. average, equality, logistic regression), while not exposing anyone's secret data.

Create a few VirtualMachines (think: separate computers that can communicate to each other).

alice = VirtualMachine('alice')
bob = VirtualMachine('bob')
charlie = VirtualMachine('charlie')

Create secret numbers on Alice, Bob, and Charlie's machines.

a = PrivateScalar(25, alice)
b = PrivateScalar(50, bob)
c = PrivateScalar(10, charlie)

Distribute an encrypted fraction of each number to each machine (this is secret sharing!).

shared_a = a.share([alice, bob, charlie])
shared_b = b.share([alice, bob, charlie])
shared_c = c.share([alice, bob, charlie])

Compute some arithmetic function directly on the encrypted shares.

shared_output = (shared_a * shared_b) - 5 * (shared_a + shared_c)

Decrypt the function's output by sending all encrypted shares to Charlie (or anyone).

shared_output.reconstruct(charlie)
>>> PrivateScalar(1075, 'charlie')

Alice, Bob, and Charlie have jointly computed a function on their data, without seeing anyone else's secret data!

Implementation

TinySMPC implements additive secret sharing for creating encrypted shares on private data.

On top of additive secret sharing, we implement several SMPC protocols, which allow us to directly perform computations on encrypted data.

Here's a summary of the encrypted operations that TinySMPC supports.

Supported? Implementation
Addition SPDZ algorithm.
See shared_addition.py
Subtraction In terms of addition and multiplication.
Multiplication SPDZ algorithm.
See shared_multiplication.py
Division ❌ (too complicated) Possible with SecureNN.
Exponentiation ✅ (public integer only) In terms of multiplication.
Greater Than ✅ (public integer only) SecureNN algorithm.
See shared_comparison.py

Repo Structure

Top-level:

  1. tutorial.ipynb: An easy tutorial notebook for SMPC and TinySMPC.
  2. tests.ipynb: Test notebook to verify that our SMPC protocols work correctly.

In the tinysmpc directory:

  1. tinysmpc.py: The top-level module with the user-facing API (VirtualMachine, PrivateScalar, SharedScalar).
  2. finite_ring.py: Useful functions for operating on integers in a finite ring.
  3. fixed_point.py: Fixed-point encoding for floats, so we can do SMPC on floats.
  4. secret_sharing.py: The additive secret sharing protocol.
  5. shared_addition.py: The SPDZ protocol for addition of SharedScalars.
  6. shared_multiplication.py: The SPDZ protocol for multiplication of SharedScalars.
  7. shared_comparison.py: The SecureNN protocol for comparison of a SharedScalar and a public integer.

About

A tiny, educational library for secure multi-party computation (in pure Python).


Languages

Language:Jupyter Notebook 68.3%Language:Python 31.7%