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

Uploaded CPython 3.10Windows x86-64

tenseal-0.3.10-cp310-cp310-macosx_11_0_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.10macOS 11.0+ x86-64

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

Uploaded CPython 3.9Windows x86-64

tenseal-0.3.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

tenseal-0.3.10-cp39-cp39-macosx_11_0_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.9macOS 11.0+ x86-64

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

Uploaded CPython 3.8Windows x86-64

tenseal-0.3.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

tenseal-0.3.10-cp38-cp38-macosx_11_0_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.8macOS 11.0+ x86-64

tenseal-0.3.10-cp37-cp37m-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.7mWindows x86-64

tenseal-0.3.10-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.7mmacOS 11.0+ x86-64

tenseal-0.3.10-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

File details

Details for the file tenseal-0.3.10-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: tenseal-0.3.10-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for tenseal-0.3.10-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a728e90b994ea112d1ee54a05fb8902b24fa078792f94e816a5f0607fc7aa00f
MD5 fcaa84704b526aa273f403745b2fa288
BLAKE2b-256 4625646f73601ded6db7c0bf924b07cf187d259d16982b2caa08d1578eb5a901

See more details on using hashes here.

File details

Details for the file tenseal-0.3.10-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: tenseal-0.3.10-cp310-cp310-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: CPython 3.10, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for tenseal-0.3.10-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 ea578720adb5f706de4fa6cf80d9055b3b89977e596a3de9412f56ef61ea5b4a
MD5 1bc403d0062b01b5a04838d37db7ffbb
BLAKE2b-256 4cb723b7d5434f5c7bb7749548337de39b5d5e457b077932609a36305dd78439

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.10-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.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for tenseal-0.3.10-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 4751caf4c32b45d8468f7280fcc1ea6d62408c3abe600e6c0b2813373a3c8b00
MD5 934465e124dc41f228b3bdd26d9afa14
BLAKE2b-256 8ce00dfd21eea0b3647a06aabc495fc9951f232179bd77de008393e127682eb7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 4.9 MB
  • Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for tenseal-0.3.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 17d16350a1404b09ddfc12bf9b92dd8212dd10395d1d3f2ec194430194daccb3
MD5 18278b702eabdc2f900dbc58443ad9d1
BLAKE2b-256 086ee7e96d8aa9b5ad0df5f6fc81f05900434b6004f5a3723f091d5cf68c18d1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.10-cp39-cp39-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: CPython 3.9, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for tenseal-0.3.10-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 9825d7c5c021c20fcd04fee05fd7e67a7379fe9a4713452e17093832b241c1ce
MD5 79599cb26be5267072f17e3cb0e77205
BLAKE2b-256 2768df58af723a6af940dce2aee6aee6f3c5cbe4dfa52148e5ca8de6144b0205

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.10-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.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for tenseal-0.3.10-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 8ff0cc663230fb4d80728381980cee62cf94acf218d11182d0ff8cde6bc1e9aa
MD5 1c04e4c300a0f48281bcb8d13d4e19b0
BLAKE2b-256 6aa9187fe506259cb68122e2492cfab19e24cffcb6d5e8226eb8b45b8cf89852

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 4.9 MB
  • Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.13

File hashes

Hashes for tenseal-0.3.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0a35d1f3eb4ce9d6ca949724138f5eb082d9f1c9cea9a4e764dcf350256a58af
MD5 723d402e9f39441f5f3675999c2388b8
BLAKE2b-256 1b958f37c76e78320ada3eb952151829478355f8002fe77bf230a822526667c3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.10-cp38-cp38-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: CPython 3.8, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for tenseal-0.3.10-cp38-cp38-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 a0dad16cc26545e96faa8ab26bd3118c9675261b7c7d4bc2b3bfdff67ce9a3e8
MD5 a10dd01e871a01864ee7891428cafbdc
BLAKE2b-256 e2a3222926b4cc76126d0c4e7c026fd5a4a6b3fa8c24d420f9dfce6597a1405b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.10-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.2.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.9

File hashes

Hashes for tenseal-0.3.10-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 160fc0e9b3918d9bab351859ce030da09a18f6df112d16fe6cb0d7d336fad602
MD5 a0076da9328648b26be18060fc5eea57
BLAKE2b-256 1d17b29f9c42b2274c0001eab87b37b2e3f65d2c4ed9440f248682f3fe55177c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.10-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 4.9 MB
  • Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.13

File hashes

Hashes for tenseal-0.3.10-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f22c708721bdd817c0b9ed687ee5286640472bb4280cc2b74070ed02528221b8
MD5 cf83738fd2a96c25541d81e0f3392355
BLAKE2b-256 0efd924de1b86f698da422e273798e1e2190635eb099bb69bbce063fdac54c05

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.10-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.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.2.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12

File hashes

Hashes for tenseal-0.3.10-cp37-cp37m-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 2625478e1445606c3705dae5cc2631e3777ca2fe4a97ae3a121616721825384b
MD5 9ec4ff4001beca08c11c236f1461bfc5
BLAKE2b-256 1575980453dd495cd76931aa77d5ce13f7b8169999e10e4890fa942d302937a1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.10-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 4.9 MB
  • Tags: CPython 3.6m, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.8

File hashes

Hashes for tenseal-0.3.10-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 041c92b455884580e3c86f81bb9a5fc1451e78b9d9727b5467c6016d50bacf64
MD5 32a1edec49b4af05c95c4a97c917ef24
BLAKE2b-256 105cced63e50c3bc0dfe9c1f3dda28fca9e6bb4e91c04bbef81b825cb196a72c

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