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.6-cp39-cp39-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.9Windows x86-64

tenseal-0.3.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

tenseal-0.3.6-cp39-cp39-macosx_10_15_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.9macOS 10.15+ x86-64

tenseal-0.3.6-cp38-cp38-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.8Windows x86-64

tenseal-0.3.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

tenseal-0.3.6-cp38-cp38-macosx_10_15_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.8macOS 10.15+ x86-64

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

Uploaded CPython 3.7mWindows x86-64

tenseal-0.3.6-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.6-cp37-cp37m-macosx_10_15_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.7mmacOS 10.15+ x86-64

tenseal-0.3.6-cp36-cp36m-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.6mWindows x86-64

tenseal-0.3.6-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

tenseal-0.3.6-cp36-cp36m-macosx_10_15_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.6mmacOS 10.15+ x86-64

File details

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

File metadata

  • Download URL: tenseal-0.3.6-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.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for tenseal-0.3.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 462d0b116391d859b37ca0e31536f43cd8d3364c09900856c0d4cff9a8515981
MD5 d6a6cf3ae96a7411ca7a298ad8fad997
BLAKE2b-256 26165fc5b3f7cebce8a1fd7b8e113dc60d69e3ed74b22166cff8b73c319bbbf8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d07f4b1884ba7e4a23d664dff407a48222d4d0bd2da55977ac95dd3316e03a69
MD5 1b2db66af08deab49e6f717d86d3b4c7
BLAKE2b-256 d75a5bba852cdb2c9ce87190291996ad6461880651bc5db77b678dc8761b3498

See more details on using hashes here.

File details

Details for the file tenseal-0.3.6-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: tenseal-0.3.6-cp39-cp39-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 4.3 MB
  • Tags: CPython 3.9, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for tenseal-0.3.6-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 00b6e39f73299177d48859897de50f0622fcf5fa29f6a36e082d8007829aeafc
MD5 279321a2e6616e4e4119fb95a2a81f5c
BLAKE2b-256 3bb105c1fccc050a38ca8daff542f67d0092e93ace76c5e73944304506895159

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.6-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for tenseal-0.3.6-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 6d8285076b70ee5d4f09fc294088b418351085da3ffd99d2cbaf88cb3047f7f4
MD5 8912776a8419da27c8fb66801328e147
BLAKE2b-256 2dddda52119bd03e6a2b8812b49eb680cfcb36b52ab06804afc41fa73f5d4da6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d46307c23599154f85eebe84a4c8d411e85264ec9e9ad020d2f9282aa2da0e40
MD5 1c85d764d39fdd105d7f614a40844cdf
BLAKE2b-256 199a9a64aa9c1cbcf37c5164b9af957f8d9118f4be3f344af2c74cf4c5895c70

See more details on using hashes here.

File details

Details for the file tenseal-0.3.6-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: tenseal-0.3.6-cp38-cp38-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 4.3 MB
  • Tags: CPython 3.8, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for tenseal-0.3.6-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 1c9a491e2596742613df39b36291df8a07ed1b1cb8cf26ee1640262be1ee1a8c
MD5 529c139524c66902161e02bc34b680f6
BLAKE2b-256 e8d65a771a170064596b656b2415221277980b28b021e81a6adcf1b34a951aa7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.6-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.4.2 importlib_metadata/4.2.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.9

File hashes

Hashes for tenseal-0.3.6-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 6901cce42644b2cf683148894c1abc551f378319e26a1621f2f1a26d2bc198e8
MD5 04d3e5bf86b8f0219cfd7ce6d82c98f9
BLAKE2b-256 e20fce165fd0f93d10d9655bc452ebb949fe14f4e9dc62382c7d27d4472c25f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 720c89734a6c51e734b9bff9c1d03c4094eb6bb4810e372b0df5430dab38eef7
MD5 3701d4407275ebdc8dc01ba1b6c9cce1
BLAKE2b-256 b1d69345750f8760d9dfaf2846cf0f65e496de87f3667c5a995fb36a75af72c1

See more details on using hashes here.

File details

Details for the file tenseal-0.3.6-cp37-cp37m-macosx_10_15_x86_64.whl.

File metadata

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

File hashes

Hashes for tenseal-0.3.6-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 22d5daf0442e85e1fbff3cc9cfffa059d9b404bd9503c84a4b19903bb6a1deac
MD5 d0efc63c8f611e82f9ac7341815c50f0
BLAKE2b-256 55026336fcae0136c6da26c05cc55f688a8b7479d3dd2471a9a6be2b5dbaeee4

See more details on using hashes here.

File details

Details for the file tenseal-0.3.6-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: tenseal-0.3.6-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.2.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.8

File hashes

Hashes for tenseal-0.3.6-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 dea508ee864ea26f3eb428ad1e4ad6f79327019c578d066cd43760fa57be8d74
MD5 808fc4686ad3f5e75b5613b458882861
BLAKE2b-256 6350a2bc71af368a9244990491ad311d0b3593ddeed4548baf948c39a58d1cc2

See more details on using hashes here.

File details

Details for the file tenseal-0.3.6-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.6-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 edf8e2a6cf8e06927b4f945ed5864f478200027c45af8cb40a3963b5e768a56e
MD5 aa45011c6a894185d97d6d374487a407
BLAKE2b-256 09859ce491bdd685591c6f9dda7b8a74b690843f3acba2319420d3d151d2b4b9

See more details on using hashes here.

File details

Details for the file tenseal-0.3.6-cp36-cp36m-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: tenseal-0.3.6-cp36-cp36m-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: CPython 3.6m, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.2.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.15

File hashes

Hashes for tenseal-0.3.6-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 9dcbf00d611def462b486aef57bdfe5d4cc3350f0c45ccb0d1e1d76f2512d353
MD5 87641aff92527eb48d1169e5b0bcdfae
BLAKE2b-256 6d6b87b0e684a94ed79da1ee3871fb7cc61b52046de646f1502e8328852bee1e

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