{"id":16582811,"url":"https://github.com/ojroques/garbled-circuit","last_synced_at":"2025-10-25T03:34:09.585Z","repository":{"id":56164745,"uuid":"161946028","full_name":"ojroques/garbled-circuit","owner":"ojroques","description":"A two-party secure function evaluation using Yao's garbled circuit protocol","archived":false,"fork":false,"pushed_at":"2024-06-12T13:31:47.000Z","size":3971,"stargazers_count":77,"open_issues_count":0,"forks_count":27,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-14T18:51:42.855Z","etag":null,"topics":["garbled-circuits","secure-computation","yao"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ojroques.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-15T21:42:01.000Z","updated_at":"2025-08-04T02:22:44.000Z","dependencies_parsed_at":"2024-06-12T19:19:02.320Z","dependency_job_id":"1f5f93ca-833d-411e-a4c5-fa805f40a31d","html_url":"https://github.com/ojroques/garbled-circuit","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ojroques/garbled-circuit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ojroques%2Fgarbled-circuit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ojroques%2Fgarbled-circuit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ojroques%2Fgarbled-circuit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ojroques%2Fgarbled-circuit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ojroques","download_url":"https://codeload.github.com/ojroques/garbled-circuit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ojroques%2Fgarbled-circuit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270816063,"owners_count":24650748,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["garbled-circuits","secure-computation","yao"],"created_at":"2024-10-11T22:34:17.130Z","updated_at":"2025-10-25T03:34:04.567Z","avatar_url":"https://github.com/ojroques.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Secure Multi-Party Computation\n\n## Contents\n* [Introduction](#introduction)\n* [Installation](#installation)\n* [Usage](#usage)\n* [Architecture](#architecture)\n* [JSON circuit](#json-circuit)\n* [Example](#example)\n* [Authors](#authors)\n\n## Introduction\nThis project implements a\n[two-party secure function evaluation](https://en.wikipedia.org/wiki/Secure_two-party_computation)\nusing\n[Yao's garbled circuit](https://en.wikipedia.org/wiki/Garbled_circuit)\nprotocol. It has been started on November 2018 for the Privacy Engineering\ncourse of Imperial College London (CO408) and refactored on November 2020.\n\nIn our model, two parties Alice and Bob compute a function on their inputs\nwithout sharing the value of their inputs with the opposing party. Alice is\nthe circuit creator (the *garbler*) while Bob is the circuit evaluator. Alice\ncreates the yao circuit and sends it to Bob along with her encrypted inputs.\nBob then computes the results and sends them back to Alice.\n\n## Installation\nCode is written for **Python 3.6+**. Dependencies are:\n* **ZeroMQ** for communications\n* **Fernet** for encryption of garbled tables\n* **SymPy** for prime number manipulation\n\nInstall all dependencies:\n```sh\npip3 install --user pyzmq cryptography sympy\n```\n\nClone this repository wherever you want and follow the instructions in next\nsection.\n\n## Usage\n\n#### Over the network\n1. By default all tests are done on the local network.\n  You can edit the network informations in **util.py**.\n2. Run the server (Bob): `make bob`.\n3. In another terminal, run the client (Alice) with one of the json circuit\n  in *circuits/*: `make \u003ccircuit-name\u003e` e.g. `make bool`. You can also run\n  `make alice` to evaluate all circuits in *circuits/* at once.\n\nAlice will print the truth table of the circuit for all combination of\nAlice-Bob inputs. Alice does not know Bob's inputs but for the purpose of\nprinting the truth table only, Alice assumes that Bob's inputs follow a\nspecific order.\n\nThe Makefile contains the most useful commands, but you can also directly use\nthe script:\n```sh\n./main.py bob  # Run Bob side\n./main.py alice -c \u003ccircuit.json\u003e  # Run Alice side\n./main.py -h  # See all available options\n```\n\n#### Local tests\nTo print the truth table of a circuit:\n```sh\n./main.py local -c \u003ccircuit.json\u003e\n```\n\nTo print a clear representation of the garbled tables of a circuit:\n```sh\n./main.py local -c \u003ccircuit.json\u003e -m table\n```\n\n## Architecture\nThe project is composed of 4 python files:\n* **main.py** implements Alice side, Bob side and local tests.\n* **yao.py** implements:\n    * Encryption and decryption functions.\n    * Evaluation function used by Bob to get the results of a yao circuit\n    * `GarbledCircuit` class which generates the keys, p-bits and garbled\n      gates of the circuit.\n    * `GarbledGate` class which generates the garbled table of a gate.\n* **ot.py** implements the oblivious transfer protocol.\n* **util.py** implements many functions related to network communications and\n  asymmetric key generation.\n\nA few functions converted to boolean circuits are provided in **circuits/**.\n\n## JSON circuit\nA function is represented as a boolean circuit using available gates:\n* NOT (1-input gate)\n* AND\n* OR\n* XOR\n* NAND\n* NOR\n* NXOR\n\nA few assumptions are made:\n* Bob knows the boolean representation of the function. Thus the principle of\n  \"No security through obscurity\" is respected.\n* All gates have one or two inputs and only one output.\n* The outputs of lower numbered gates will always be wired to higher numbered\n  gates and/or be defined as circuit outputs.\n* The gate id is the id of the gate's output.\n\n## Example\n![smart](./figures/smart.png)\n\nHere is the json representation of above circuit:\n```json\n{\n  \"name\": \"smart\",\n  \"circuits\": [\n    {\n      \"id\": \"Smart\",\n      \"alice\": [1, 2],\n      \"bob\": [3, 4],\n      \"out\": [7],\n      \"gates\": [\n        {\"id\": 5, \"type\": \"AND\", \"in\": [1, 3]},\n        {\"id\": 6, \"type\": \"XOR\", \"in\": [2, 4]},\n        {\"id\": 7, \"type\": \"OR\", \"in\": [5, 6]}\n      ]\n    }\n  ]\n}\n```\n\nHere is the truth table of the previous json circuit:\n```sh\n$ ./main.py local -c circuits/smart.json\n======== Smart ========\n  Alice[1, 2] = 0 0 Bob[3, 4] = 0 0  Outputs[7] = 0\n  Alice[1, 2] = 0 0 Bob[3, 4] = 0 1  Outputs[7] = 1\n  Alice[1, 2] = 0 0 Bob[3, 4] = 1 0  Outputs[7] = 0\n  Alice[1, 2] = 0 0 Bob[3, 4] = 1 1  Outputs[7] = 1\n  Alice[1, 2] = 0 1 Bob[3, 4] = 0 0  Outputs[7] = 1\n  Alice[1, 2] = 0 1 Bob[3, 4] = 0 1  Outputs[7] = 0\n  Alice[1, 2] = 0 1 Bob[3, 4] = 1 0  Outputs[7] = 1\n  Alice[1, 2] = 0 1 Bob[3, 4] = 1 1  Outputs[7] = 0\n  Alice[1, 2] = 1 0 Bob[3, 4] = 0 0  Outputs[7] = 0\n  Alice[1, 2] = 1 0 Bob[3, 4] = 0 1  Outputs[7] = 1\n  Alice[1, 2] = 1 0 Bob[3, 4] = 1 0  Outputs[7] = 1\n  Alice[1, 2] = 1 0 Bob[3, 4] = 1 1  Outputs[7] = 1\n  Alice[1, 2] = 1 1 Bob[3, 4] = 0 0  Outputs[7] = 1\n  Alice[1, 2] = 1 1 Bob[3, 4] = 0 1  Outputs[7] = 0\n  Alice[1, 2] = 1 1 Bob[3, 4] = 1 0  Outputs[7] = 1\n  Alice[1, 2] = 1 1 Bob[3, 4] = 1 1  Outputs[7] = 1\n```\n\nAnd here is the clear representation of the garbled gates:\n```sh\n$ ./main.py local -c circuits/smart.json -m table\n======== Smart ========\nP-BITS: {1: 0, 2: 1, 3: 0, 4: 0, 5: 1, 6: 0, 7: 0}\nGATE: 5, TYPE: AND\n[0, 0]: [1, 0][3, 0]([5, 0], 1)\n[0, 1]: [1, 0][3, 1]([5, 0], 1)\n[1, 0]: [1, 1][3, 0]([5, 0], 1)\n[1, 1]: [1, 1][3, 1]([5, 1], 0)\nGATE: 6, TYPE: XOR\n[0, 0]: [2, 1][4, 0]([6, 1], 1)\n[0, 1]: [2, 1][4, 1]([6, 0], 0)\n[1, 0]: [2, 0][4, 0]([6, 0], 0)\n[1, 1]: [2, 0][4, 1]([6, 1], 1)\nGATE: 7, TYPE: OR\n[0, 0]: [5, 1][6, 0]([7, 1], 1)\n[0, 1]: [5, 1][6, 1]([7, 1], 1)\n[1, 0]: [5, 0][6, 0]([7, 0], 0)\n[1, 1]: [5, 0][6, 1]([7, 1], 1)\n```\n\n## Authors\n* Olivier Roques: \u003colivier@oroques.dev\u003e\n* Emmanuelle Risson: \u003cear3218@imperial.ac.uk\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fojroques%2Fgarbled-circuit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fojroques%2Fgarbled-circuit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fojroques%2Fgarbled-circuit/lists"}