Skip to main content

A Library for Homomorphic Encryption Operations on Tensors

Project description


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

  • :key: Encryption/Decryption of vectors of integers using BFV
  • :old_key: Encryption/Decryption of vectors of real numbers using CKKS
  • :fire: Element-wise addition, substraction and multiplication of encrypted-encrypted vectors and encrypted-plain vectors
  • :cyclone: Dot product and vector-matrix multiplication
  • :zap: 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.12 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tenseal-0.3.7-cp39-cp39-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.9Windows x86-64

tenseal-0.3.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

tenseal-0.3.7-cp39-cp39-macosx_11_0_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.9macOS 11.0+ x86-64

tenseal-0.3.7-cp38-cp38-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.8Windows x86-64

tenseal-0.3.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

tenseal-0.3.7-cp38-cp38-macosx_11_0_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.8macOS 11.0+ x86-64

tenseal-0.3.7-cp37-cp37m-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.7mWindows x86-64

tenseal-0.3.7-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

tenseal-0.3.7-cp37-cp37m-macosx_11_0_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.7mmacOS 11.0+ x86-64

File details

Details for the file tenseal-0.3.7-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: tenseal-0.3.7-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for tenseal-0.3.7-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 2a6ba68cddf8781b3b4c02278812e1c15c0d977e192bf8ee2ec4412208c94dd9
MD5 470c2f3585ea0265f82672f45ee51baf
BLAKE2b-256 3ee6561e8a2acdf8052fda01b415a12530820c9891baaacb138b0eb48e1af669

See more details on using hashes here.

File details

Details for the file tenseal-0.3.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f4b9c9d28389140626dcbecd703485b633e520710249b8c976d619cab08a0978
MD5 cc6fa7f5eafbd24e21ba293b0603d2ca
BLAKE2b-256 9ee62cda2681aef567cc4524eea0227ec11c0cbebc2b3b4a6bebbef1c4b1581d

See more details on using hashes here.

File details

Details for the file tenseal-0.3.7-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: tenseal-0.3.7-cp39-cp39-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 4.3 MB
  • Tags: CPython 3.9, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for tenseal-0.3.7-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 e03313c68570a14e77ce0108e2e5f1025dc852a31c8d5d983acbc9a3ae163adc
MD5 d057db19ab6380a886deb502f967c12b
BLAKE2b-256 6da65444915a1f1a2fab69c197946ce07f61c8d7f86d47673787436fc52159c4

See more details on using hashes here.

File details

Details for the file tenseal-0.3.7-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: tenseal-0.3.7-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for tenseal-0.3.7-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 3e6fc4c8596991b4079fbeefa20c6bcd3e79b4a0b2832aa6eba8387ecce37c1d
MD5 4305cc1ff379eeca301c1f6e8f70de2b
BLAKE2b-256 dd4dc6accb141a24ec4d3f6d640ed4e1d6331797d03de8ac6cbd004aa34e3607

See more details on using hashes here.

File details

Details for the file tenseal-0.3.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 215cf0040ed5d2763b306a3a91dcb52cf0a43a40afcdfe9c45a12522c3aba620
MD5 3f6c189487aeaafcc8f7517f5fa8fe91
BLAKE2b-256 ff45befce7e3045c6f1e169076e08a58780eacc29ceadf4dc46cbc35bf0cb273

See more details on using hashes here.

File details

Details for the file tenseal-0.3.7-cp38-cp38-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: tenseal-0.3.7-cp38-cp38-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 4.3 MB
  • Tags: CPython 3.8, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for tenseal-0.3.7-cp38-cp38-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 75bcc1a1b5c27981ff164e6f6a185c45d2084146c942c18d8779cba4bba4c4e1
MD5 a841f4de61bda77ebe033e5b2fa6c998
BLAKE2b-256 3b98db1306a5b2c725eeee75e16902c9737ca42934da4c583a7b7e3e266e8ae9

See more details on using hashes here.

File details

Details for the file tenseal-0.3.7-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: tenseal-0.3.7-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.2.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.9

File hashes

Hashes for tenseal-0.3.7-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 ccf1f1c944130b926170058e48be536123cfa748293009152bca1e5ff42ae24a
MD5 2de3c3d5cc64e8dc5181ac783d76658e
BLAKE2b-256 a9c4143951bda127eb71a889893a9e462756f92097e027ce7f1207d96e9acda3

See more details on using hashes here.

File details

Details for the file tenseal-0.3.7-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.7-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 39bace676f168fad1fc3dfb52adb51fad3d10ad264c40881f1536ce6f63e59a8
MD5 9fdabdfea71b19413ce4d8ad3c08aa76
BLAKE2b-256 bb50ab795be67e681b5336b2ee06b5e7bfa2c494171d3c91636922db02ad35d6

See more details on using hashes here.

File details

Details for the file tenseal-0.3.7-cp37-cp37m-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: tenseal-0.3.7-cp37-cp37m-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: CPython 3.7m, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.2.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12

File hashes

Hashes for tenseal-0.3.7-cp37-cp37m-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 5c545f53a9729edefc353b059f338911f5f4ccf28f6264f43b63593fb0a443c7
MD5 55077d486b53a018226b78709159ee79
BLAKE2b-256 033776091213abc0fcc6a1eb07ba65f789a2e420876173303785ec1e38b532e9

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