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.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

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

Uploaded CPython 3.10Windows x86-64

tenseal-0.3.12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.10macOS 11.0+ x86-64

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

Uploaded CPython 3.9Windows x86-64

tenseal-0.3.12-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.12-cp39-cp39-macosx_11_0_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.9macOS 11.0+ x86-64

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

Uploaded CPython 3.8Windows x86-64

tenseal-0.3.12-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.12-cp38-cp38-macosx_11_0_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.8macOS 11.0+ x86-64

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

Uploaded CPython 3.7mWindows x86-64

tenseal-0.3.12-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.12-cp37-cp37m-macosx_11_0_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.7mmacOS 11.0+ x86-64

tenseal-0.3.12-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.12-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: tenseal-0.3.12-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/4.0.1 CPython/3.10.6

File hashes

Hashes for tenseal-0.3.12-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 75c32bd151df6d6ab3356615cab2333e50248b5d3a448b29f26a0c6ffd67b0cb
MD5 d04b6bf3f83fa6387bd9343ec6b84f34
BLAKE2b-256 dd26ad1b129bc46f896b59a74cbdce18c8fc576c8a1655c6ff543a669bed6c9b

See more details on using hashes here.

File details

Details for the file tenseal-0.3.12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cdd9c6e525c366a2ad56a2ae958a94e0edbad625df449e990dcc195ba747f150
MD5 5aaa61435dac98555223f4fee2944ef3
BLAKE2b-256 14995548d846804a60986a9487d8d56b698a46ba29b0a7a57fffb3c8facc326e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.12-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 4f961c5e45792336ae666875b68be39c5fd92b889da328ad74df3daa5d8a97de
MD5 ac7811243cc0b38bb3ab66c99bb1fbd0
BLAKE2b-256 00125891f4ba8a8c304897630313316af6af62bfdeafb5a9eaf111683f9292d4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.12-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/4.0.1 CPython/3.9.13

File hashes

Hashes for tenseal-0.3.12-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ef480d79d929bb14e5c69199d43e76f2afa2e9bd16cf0d67cb1b65aa5374ab4c
MD5 4b737d0c7c1006fda6ff3fc419a2019a
BLAKE2b-256 f82202128b857d485b00efc033706eec970389efa35e1f47ba01ac71db8048aa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.12-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e1b8badbd7a9a68897d8bb24732651ed7661f31de6a69a5c3027bb1b81d0e872
MD5 bc48b6db716c7b9c9ff32ad09386d03a
BLAKE2b-256 394403aa2ec65e0de2890b413be1ec9f08e12768f7663a719f2c5a6d3bda7ff4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.12-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 c4dc7a7d750065e61e4992d9f8729a705401cc7ee0c40de20dae2b9883eb2700
MD5 ae1ca21eebd91f573aede7581391b66e
BLAKE2b-256 80c46ebf03a4ea821753b1ff5b40f55a97f03bba1416077daec0b261a1e660aa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.12-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/4.0.1 CPython/3.8.10

File hashes

Hashes for tenseal-0.3.12-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 9246515e535c9d2de7d8d75e7f8e0ded2d8daf93d7d473f9c89cc45ae76d491b
MD5 5155a898ae01dbfcfa9a31ca30a978bc
BLAKE2b-256 02fcfc86d8989a86d235ff250af4f60f4786a868c5ec62f4caa4c4b8bd485bf7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.12-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d3a59f6fd1835d4d84000a97b56ce51794bab6a10b14c0fa7ecd971ef74fec86
MD5 c8b036f5e2ad27a0d4d072122005ed52
BLAKE2b-256 e1dedf62c8a4940cab48ca7145d0a0af8037aa7cfb0165e376b49cc079b2a5f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.12-cp38-cp38-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 0a00bce4bf78507c18644471215cf246ba22c3fbc56256c5bd0e2b6ad1602ddc
MD5 7ba285fe5985b334dbdb8a7292370e37
BLAKE2b-256 599a29c089b24e197dfc2a89af0939e67823f1ce0c97ac4f9820c280e51f9cb0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.12-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/4.0.1 CPython/3.7.9

File hashes

Hashes for tenseal-0.3.12-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 0d6afe06b6b1fc76534bbe9273701622d9fbcaf40ae71fe195bb46f66f340cf9
MD5 02cf55efb9c02bc347bebe1f7f2b51fd
BLAKE2b-256 c89d2045012ec124872d914812297ff0410bfb5f4da31239a52712694aef0730

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.12-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d4c2d9763ed5c879f7407aa3b9909c3510f1f48151f40ab2d27d3b60addb4dc7
MD5 270f8dda1e14760424754588a1c616c8
BLAKE2b-256 58cae7e627c2ad96595f44b87486459f8bfeecebdc7e8a10ffe5fdbdc5d45b62

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.12-cp37-cp37m-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 4d2d756245803689d313139884f56894a231ae6d607d96fa1ad18350470b4f85
MD5 1e4761f3a0d5b59d76feb1bb06c2fb3c
BLAKE2b-256 3c9809c7bb77fd1321cf934c20a1190eb7426f4ca95a5abe7a5e40d2a82661b8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.12-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.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.11 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.8

File hashes

Hashes for tenseal-0.3.12-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f957ce1cae8014d9b8f915b38d9331152fe144bbf82dce7d034400f5d65a464d
MD5 f1e68f71e979f8b04eb5e0d42555b885
BLAKE2b-256 bed8169cec46f6658875fdac4022088a4bc3ce36a9ea13bcad2df456fabd1004

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