All Projects → ojroques → garbled-circuit

ojroques / garbled-circuit

Licence: other
A two-party secure function evaluation using Yao's garbled circuit protocol

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to garbled-circuit

MOTION
An efficient, user-friendly, modular, and extensible framework for mixed-protocol secure multi-party computation with two or more parties
Stars: ✭ 59 (+43.9%)
Mutual labels:  secure-computation, garbled-circuits
emp-tool
No description or website provided.
Stars: ✭ 155 (+278.05%)
Mutual labels:  secure-computation, garbled-circuits
BetaVQE.jl
Solving Quantum Statistical Mechanics with Variational Autoregressive Networks and Quantum Circuits
Stars: ✭ 27 (-34.15%)
Mutual labels:  yao
jessica
Jessica - Jessie (secure distributed Javascript) Compiler Architecture
Stars: ✭ 27 (-34.15%)
Mutual labels:  secure-computation
PPML-Resource
Materials about Privacy-Preserving Machine Learning
Stars: ✭ 93 (+126.83%)
Mutual labels:  secure-computation
rust-threshold-secret-sharing
A pure-Rust implementation of various threshold secret sharing schemes
Stars: ✭ 129 (+214.63%)
Mutual labels:  secure-computation
rust-paillier
A pure-Rust implementation of the Paillier encryption scheme
Stars: ✭ 78 (+90.24%)
Mutual labels:  secure-computation
awesome-secure-computation
Awesome list for cryptographic secure computation paper. This repo includes *Lattice*, *DifferentialPrivacy*, *MPC* and also a comprehensive summary for top conferences.
Stars: ✭ 125 (+204.88%)
Mutual labels:  secure-computation
TinyGarble
TinyGarble: Logic Synthesis and Sequential Descriptions for Yao's Garbled Circuits
Stars: ✭ 108 (+163.41%)
Mutual labels:  garbled-circuits
conclave
Query compiler for secure multi-party computation.
Stars: ✭ 86 (+109.76%)
Mutual labels:  secure-computation
Pysyft
A library for answering questions using data you cannot see
Stars: ✭ 7,811 (+18951.22%)
Mutual labels:  secure-computation
ecelgamal
Additive homomorphic EC-ElGamal
Stars: ✭ 19 (-53.66%)
Mutual labels:  secure-computation

Secure Multi-Party Computation

Contents

Introduction

This project implements a two-party secure function evaluation using Yao's garbled circuit protocol. It has been started on November 2018 for the Privacy Engineering course of Imperial College London (CO408) and refactored on November 2020.

In our model, two parties Alice and Bob compute a function on their inputs without sharing the value of their inputs with the opposing party. Alice is the circuit creator (the garbler) while Bob is the circuit evaluator. Alice creates the yao circuit and sends it to Bob along with her encrypted inputs. Bob then computes the results and sends them back to Alice.

Installation

Code is written for Python 3.6+. Dependencies are:

  • ZeroMQ for communications
  • Fernet for encryption of garbled tables
  • SymPy for prime number manipulation

Install all dependencies:

pip3 install --user pyzmq cryptography sympy

Clone this repository wherever you want and follow the instructions in next section.

Usage

Over the network

  1. By default all tests are done on the local network. You can edit the network informations in util.py.
  2. Run the server (Bob): make bob.
  3. In another terminal, run the client (Alice) with one of the json circuit in circuits/: make <circuit-name> e.g. make bool. You can also run make alice to evaluate all circuits in circuits/ at once.

Alice will print the truth table of the circuit for all combination of Alice-Bob inputs. Alice does not know Bob's inputs but for the purpose of printing the truth table only, Alice assumes that Bob's inputs follow a specific order.

The Makefile contains the most useful commands, but you can also directly use the script:

./main.py bob  # Run Bob side
./main.py alice -c <circuit.json>  # Run Alice side
./main.py -h  # See all available options

Local tests

To print the truth table of a circuit:

./main.py local -c <circuit.json>

To print a clear representation of the garbled tables of a circuit:

./main.py local -c <circuit.json> -m table

Architecture

The project is composed of 4 python files:

  • main.py implements Alice side, Bob side and local tests.
  • yao.py implements:
    • Encryption and decryption functions.
    • Evaluation function used by Bob to get the results of a yao circuit
    • GarbledCircuit class which generates the keys, p-bits and garbled gates of the circuit.
    • GarbledGate class which generates the garbled table of a gate.
  • ot.py implements the oblivious transfer protocol.
  • util.py implements many functions related to network communications and asymmetric key generation.

A few functions converted to boolean circuits are provided in circuits/.

JSON circuit

A function is represented as a boolean circuit using available gates:

  • NOT (1-input gate)
  • AND
  • OR
  • XOR
  • NAND
  • NOR
  • NXOR

A few assumptions are made:

  • Bob knows the boolean representation of the function. Thus the principle of "No security through obscurity" is respected.
  • All gates have one or two inputs and only one output.
  • The outputs of lower numbered gates will always be wired to higher numbered gates and/or be defined as circuit outputs.
  • The gate id is the id of the gate's output.

Example

smart

Here is the json representation of above circuit:

{
  "name": "smart",
  "circuits": [
    {
      "id": "Smart",
      "alice": [1, 2],
      "bob": [3, 4],
      "out": [7],
      "gates": [
        {"id": 5, "type": "AND", "in": [1, 3]},
        {"id": 6, "type": "XOR", "in": [2, 4]},
        {"id": 7, "type": "OR", "in": [5, 6]}
      ]
    }
  ]
}

Here is the truth table of the previous json circuit:

$ ./main.py local -c circuits/smart.json
======== Smart ========
  Alice[1, 2] = 0 0 Bob[3, 4] = 0 0  Outputs[7] = 0
  Alice[1, 2] = 0 0 Bob[3, 4] = 0 1  Outputs[7] = 1
  Alice[1, 2] = 0 0 Bob[3, 4] = 1 0  Outputs[7] = 0
  Alice[1, 2] = 0 0 Bob[3, 4] = 1 1  Outputs[7] = 1
  Alice[1, 2] = 0 1 Bob[3, 4] = 0 0  Outputs[7] = 1
  Alice[1, 2] = 0 1 Bob[3, 4] = 0 1  Outputs[7] = 0
  Alice[1, 2] = 0 1 Bob[3, 4] = 1 0  Outputs[7] = 1
  Alice[1, 2] = 0 1 Bob[3, 4] = 1 1  Outputs[7] = 0
  Alice[1, 2] = 1 0 Bob[3, 4] = 0 0  Outputs[7] = 0
  Alice[1, 2] = 1 0 Bob[3, 4] = 0 1  Outputs[7] = 1
  Alice[1, 2] = 1 0 Bob[3, 4] = 1 0  Outputs[7] = 1
  Alice[1, 2] = 1 0 Bob[3, 4] = 1 1  Outputs[7] = 1
  Alice[1, 2] = 1 1 Bob[3, 4] = 0 0  Outputs[7] = 1
  Alice[1, 2] = 1 1 Bob[3, 4] = 0 1  Outputs[7] = 0
  Alice[1, 2] = 1 1 Bob[3, 4] = 1 0  Outputs[7] = 1
  Alice[1, 2] = 1 1 Bob[3, 4] = 1 1  Outputs[7] = 1

And here is the clear representation of the garbled gates:

$ ./main.py local -c circuits/smart.json -m table
======== Smart ========
P-BITS: {1: 0, 2: 1, 3: 0, 4: 0, 5: 1, 6: 0, 7: 0}
GATE: 5, TYPE: AND
[0, 0]: [1, 0][3, 0]([5, 0], 1)
[0, 1]: [1, 0][3, 1]([5, 0], 1)
[1, 0]: [1, 1][3, 0]([5, 0], 1)
[1, 1]: [1, 1][3, 1]([5, 1], 0)
GATE: 6, TYPE: XOR
[0, 0]: [2, 1][4, 0]([6, 1], 1)
[0, 1]: [2, 1][4, 1]([6, 0], 0)
[1, 0]: [2, 0][4, 0]([6, 0], 0)
[1, 1]: [2, 0][4, 1]([6, 1], 1)
GATE: 7, TYPE: OR
[0, 0]: [5, 1][6, 0]([7, 1], 1)
[0, 1]: [5, 1][6, 1]([7, 1], 1)
[1, 0]: [5, 0][6, 0]([7, 0], 0)
[1, 1]: [5, 0][6, 1]([7, 1], 1)

Authors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].