• Stars
    star
    790
  • Rank 57,622 (Top 2 %)
  • Language
    C++
  • License
    Apache License 2.0
  • Created almost 5 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A library for doing homomorphic encryption operations on tensors


TenSEAL
TenSEAL


A library for doing homomorphic encryption operations on tensors

Tests Linux Package MacOS Package Windows Package

Downloads Version OpenCollective Slack

TenSEAL is a library for doing homomorphic encryption operations on tensors, built on top of Microsoft SEAL. It provides ease of use through a Python API, while preserving efficiency by implementing most of its operations using C++.

Features

  • 🔑 Encryption/Decryption of vectors of integers using BFV
  • 🗝️ Encryption/Decryption of vectors of real numbers using CKKS
  • 🔥 Element-wise addition, subtraction and multiplication of encrypted-encrypted vectors and encrypted-plain vectors
  • 🌀 Dot product and vector-matrix multiplication
  • ⚡ Complete SEAL API under tenseal.sealapi

Usage

We show the basic operations over encrypted data, more advanced usage for machine learning applications can be found on our tutorial section

import tenseal as ts

# Setup TenSEAL context
context = ts.context(
            ts.SCHEME_TYPE.CKKS,
            poly_modulus_degree=8192,
            coeff_mod_bit_sizes=[60, 40, 40, 60]
          )
context.generate_galois_keys()
context.global_scale = 2**40

v1 = [0, 1, 2, 3, 4]
v2 = [4, 3, 2, 1, 0]

# encrypted vectors
enc_v1 = ts.ckks_vector(context, v1)
enc_v2 = ts.ckks_vector(context, v2)

result = enc_v1 + enc_v2
result.decrypt() # ~ [4, 4, 4, 4, 4]

result = enc_v1.dot(enc_v2)
result.decrypt() # ~ [10]

matrix = [
  [73, 0.5, 8],
  [81, -5, 66],
  [-100, -78, -2],
  [0, 9, 17],
  [69, 11 , 10],
]
result = enc_v1.matmul(matrix)
result.decrypt() # ~ [157, -90, 153]

Installation

Using pip

$ pip install tenseal

This installs the last packaged version on pypi. If your platform doesn't have a ready package, please open an issue to let us know.

Build from Source

Supported platforms and their requirements are listed below: (this are only required for building TenSEAL from source)

  • Linux: A modern version of GNU G++ (>= 6.0) or Clang++ (>= 5.0).
  • MacOS: Xcode toolchain (>= 9.3)
  • Windows: Microsoft Visual Studio (>= 10.0.40219.1, Visual Studio 2010 SP1 or later).

If you want to install tenseal from the repository, you should first make sure to have the requirements for your platform (listed above) and CMake (3.14 or higher) installed, then get the third party libraries (if you didn't already) by running the following command from the root directory of the project

$ git submodule init
$ git submodule update

TenSEAL uses Protocol Buffers for serialization, and you will need the protocol buffer compiler too.

If you are on Windows, you will first need to build SEAL library using Visual Studio, you should use the solution file SEAL.sln in third_party/SEAL to build the project native\src\SEAL.vcxproj with Configuration=Release and Platform=x64. For more details check the instructions in Building Microsoft SEAL

You can then trigger the build and the installation

$ pip install .

Use Docker

You can use our Docker image for a ready to use environment with TenSEAL installed

$ docker container run --interactive --tty openmined/tenseal

Note: openmined/tenseal points to the image from the last release, use openmined/tenseal:dev for the image built from the master branch.

You can also build your custom image, this might be handy for developers working on the project

$ docker build -t tenseal -f docker-images/Dockerfile-py38 .

To interactively run this docker image as a container after it has been built you can run

$ docker container run -it tenseal

Using Bazel

To use this library in another Bazel project, add the following in your WORKSPACE file:


git_repository(
   name = "org_openmined_tenseal",
   remote = "https://github.com/OpenMined/TenSEAL",
   branch = "master",
   init_submodules = True,
)

load("@org_openmined_tenseal//tenseal:preload.bzl", "tenseal_preload")

tenseal_preload()

load("@org_openmined_tenseal//tenseal:deps.bzl", "tenseal_deps")

tenseal_deps()

Benchmarks

You can benchmark the implementation at any point by running

$ bazel run -c opt --spawn_strategy=standalone //tests/cpp/benchmarks:benchmark

The benchmarks from every PR merge are uploaded here.

Tutorials

Publications

A. Benaissa, B. Retiat, B. Cebere, A.E. Belfedhal, "TenSEAL: A Library for Encrypted Tensor Operations Using Homomorphic Encryption", ICLR 2021 Workshop on Distributed and Private Machine Learning (DPML 2021).

@misc{tenseal2021,
    title={TenSEAL: A Library for Encrypted Tensor Operations Using Homomorphic Encryption}, 
    author={Ayoub Benaissa and Bilal Retiat and Bogdan Cebere and Alaa Eddine Belfedhal},
    year={2021},
    eprint={2104.03152},
    archivePrefix={arXiv},
    primaryClass={cs.CR}
}

Support

For support in using this library, please join the #support Slack channel. Click here to join our Slack community!

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

Apache License 2.0

More Repositories

1

PySyft

Perform data science on data that remains in someone else's server
Python
9,477
star
2

PyGrid-deprecated---see-PySyft-

A Peer-to-peer Platform for Secure, Privacy-preserving, Decentralized Data Science
Python
614
star
3

PyDP

The Python Differential Privacy Library. Built on top of: https://github.com/google/differential-privacy
Python
486
star
4

private-ai-resources

SOON TO BE DEPRECATED - Private machine learning progress
469
star
5

PipelineDP

PipelineDP is a Python framework for applying differentially private aggregations to large datasets using batch processing systems such as Apache Spark, Apache Beam, and more.
Python
274
star
6

PyVertical

Privacy Preserving Vertical Federated Learning
Python
213
star
7

SyferText

A privacy preserving NLP framework
Python
196
star
8

courses

A place where our community can discuss OpenMined Courses, including posting questions, sharing feedback, or providing comments for discussion!
168
star
9

syft.js

The official Syft worker for Web and Node, built in Javascript
JavaScript
147
star
10

Roadmap

This repository contains OpenMined's official development and community roadmap.
131
star
11

PSI

Private Set Intersection Cardinality protocol based on ECDH and Bloom Filters
C++
128
star
12

SyMPC

A SMPC companion library for Syft
Python
96
star
13

KotlinSyft

The official Syft worker for secure on-device machine learning
Kotlin
83
star
14

PyDentity

A repository for leveraging Self-Sovereign Identity in applications
Jupyter Notebook
65
star
15

PySyft-TensorFlow

SOON TO BE DEPRECATED - The TensorFlow bindings for PySyft
Python
57
star
16

Threepio

A multi-language library for translating commands between PyTorch, TensorFlow, and TensorFlow.js
Python
56
star
17

sycret

Function Secret Sharing library for Python and Rust with hardware acceleration
Rust
50
star
18

SwiftSyft

The official Syft worker for iOS, built in Swift
Swift
47
star
19

openmined-website

The OpenMined website...
JavaScript
43
star
20

covid-alert

A privacy-preserving app for comparing last-known locations of coronavirus patients
JavaScript
43
star
21

PyFE

A library for running Functional Encryption on tensors
Python
41
star
22

PIR

Private Information Retrieval protocol
C++
41
star
23

PyZPK

Python wrapper for open source Zero Proof Knowledge Library
C++
27
star
24

openmined

OpenMined courses application
TypeScript
25
star
25

opus

Python
22
star
26

PyAriesFL

Federated Learning on HyperLedger Aries
Python
21
star
27

syft-proto

Defines types for all Serde encoding across languages
JavaScript
20
star
28

datasets

Jupyter Notebook
16
star
29

pygrid-admin

The user interface for PyGrid!
TypeScript
13
star
30

JavaDP

Differential privacy implementation in the Java family of languages (Java, Kotlin, Scala etc...)
11
star
31

aries-did.js

A repo for exploring the use of Hyperledger Aries to facilitate decentralised identity services.
TypeScript
11
star
32

syft_experimental

Deliberate experimental Rust implementation of Syft
Rust
11
star
33

SwiftDP

Swift wrapper for Google's Differential Privacy Project
Objective-C++
11
star
34

writing

11
star
35

sgx-experiments

Trusted execution experiments with Intel SGX
Makefile
11
star
36

omui

The OpenMined UI component system for usage in all our web applications and Framer prototyping
TypeScript
10
star
37

design

This is the main hub for those interested in design in the OpenMined community
Jupyter Notebook
10
star
38

CampX

Tensor Based Environment Framework for Training RL Agents - Pre Alpha
Python
8
star
39

.github

All our community health files
7
star
40

design-assets

All OpenMined design assets
7
star
41

Bootcamps

7
star
42

serverless-website-api

SOON TO BE DEPRECATED - A Github statistics fetcher, running on a cron job, with permanent storage to DynamoDB, for the OpenMined community.
JavaScript
7
star
43

privacy-conference

The website for our 2020 privacy conference
JavaScript
6
star
44

PyDPValidator

Validation assets for core OpenMined libraries
Jupyter Notebook
6
star
45

X-PenTest

Repository for carrying out Pentesting on OM Infrastructure
6
star
46

NetworkRegistry

5
star
47

miner

A collection of web scraping technologies focused around making it easy for users to download their data.
5
star
48

paillier.js

A pure javascript implementation of paillier - runnable in browser, node, or react native
TypeScript
5
star
49

research

5
star
50

Hackathon-DSA

Jupyter Notebook
4
star
51

openmined-ghost-theme

SOON TO BE DEPRECATED - The theme for the OpenMined and Weekly Digs blogs.
SCSS
4
star
52

GridMonitor

SOON TO BE DEPRECATED - A user interface for monitoring a network router for PyGrid Platform
CSS
3
star
53

daa.js

A javascript wrapper around https://github.com/xaptum/ecdaa
3
star
54

diffPrivR

R implementation of google's differential privacy library
3
star
55

syft-enclave

Python
3
star
56

syft.cpp

SOON TO BE DEPRECATED - A library for encrypted, privacy preserving machine learning
C++
3
star
57

OpenGridNodes

1
star
58

KotlinPSI

A Kotlin library for private set intersection
1
star
59

clojure-dp

Clojure
1
star
60

trasterisk

kwarger is a Flake8 plugin which enforces named kwargs or trasterisks in your function arguments
Python
1
star
61

SwiftPSI

A Swift library for private set intersection
1
star