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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ x86-64

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

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.9macOS 11.0+ x86-64

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

Uploaded CPython 3.8Windows x86-64

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

Uploaded CPython 3.8macOS 11.0+ x86-64

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

Uploaded CPython 3.7mWindows x86-64

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

Uploaded CPython 3.7mmacOS 11.0+ x86-64

tenseal-0.3.11-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.11-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: tenseal-0.3.11-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.0 CPython/3.10.4

File hashes

Hashes for tenseal-0.3.11-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 12a9059ecc522ed60ced35e5bd5b467a435237e7c7ad1798bebb398372a744dc
MD5 2e52bf35ff536339bb7464859f16613d
BLAKE2b-256 014d318b92c59eefea8fe1409a8cbcc829b1016a50bc444d62ea799299b09746

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.11-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 94ae8ad7203f0604b0889d19d9ae21821962e79e33c7d75610243da1ffb7abef
MD5 8eb5957604b9bacb2ac1f05169a413a7
BLAKE2b-256 555af4679cb593fd09b702c345c80322579385831e8a45126070efb33509a9b9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.11-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.0 CPython/3.9.12

File hashes

Hashes for tenseal-0.3.11-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 d456a3b261b518f68850e102f2febe6a4d71e4f175278b32ae7502b4db55ac2d
MD5 08726327f1c5985fcf7df5c1a745661e
BLAKE2b-256 690d524dc13e8c859fc280096eabd4e76025da5f14da7fb172a2b83163c0fbb6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4979e32ea8e3fa889df16b8944e2ab8dd8da085096f113b42ca1f651bcf2e3cf
MD5 707dc3327991caadacfffb3a8c4fde58
BLAKE2b-256 d938c8d36f99cace824fd0246cfba1581c613ef0322687cf6431187318c71284

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.11-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 ff2721c0682a92dcb4b8dcb5db4873405b69cbc6e7e0597a3ffa38b565f079cd
MD5 29d01a6f6181568c353f85cb94d797cd
BLAKE2b-256 a005b376662a8a758163b68f2af6afd100fa0a91a9bff9423a59796f76eea6c6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.11-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.0 CPython/3.8.10

File hashes

Hashes for tenseal-0.3.11-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 b3c7bd8facfb895b6db6a41ac1bac326dd368fd25bc10deb5c35e213094cc0c3
MD5 f91b6589b7f8be32e5d7e83a463a711b
BLAKE2b-256 e5288b4a77e2b3959ff134629b5cf981434c3c7b9f49abb9912975bf9477fc89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.11-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d7d6553c165f023723ec05f452f6aa1ff6893b0645868e2c0d49a690a6ee9f3d
MD5 2b7b60d3dac457d8965f506e69c9d1be
BLAKE2b-256 104065f6afc0c397731902626a05ab8a46dd6434417125ff76b8bc6fb2ed69ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.11-cp38-cp38-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 0062b6120ce14761ad65bbef4416b8efe7870a22bad66ec1e1959dbab9876a86
MD5 c7b5d3c3902465234c22e59dcfcb2297
BLAKE2b-256 a9a0f6dfdbd8be0f4a6ef76c1a6aff7490af915509df390ac388ec3cc9d72ed3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.11-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.0 CPython/3.7.9

File hashes

Hashes for tenseal-0.3.11-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 0191017527ddc0871831e08a326b08fc25e25dc5500a42a776ae86aae456417d
MD5 f80949f1521ee39de7d330f1d079f863
BLAKE2b-256 f54febeeaf50549737df85b1b9daedc2f54f241b7d57bb55b27fbec91727b4ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.11-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b76a6dbebec0c995fd593cf40e869768e6fe77911435ed70134936cda3265843
MD5 3ebb2278e14d319894108360fe9a23da
BLAKE2b-256 155cc6147671855ed902ab6ee8972fc894f25331c0bfc1e865e812903711967d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.11-cp37-cp37m-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 ff1ec68c108f203b6b7f3304ee92e286f06046c98b74e7a4ad05effcc0e8ac7e
MD5 1c63c2c6aee2f50dcabd11b1b46d9c16
BLAKE2b-256 b2efb3dfdd314c1fd9c8bccbd5a45fd8245e8f60c5d369a7fc5ceff9233a32f9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.11-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.64.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.11-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 757b2265707edab4cba304f900fa03e264110e5b743de7f947759e80c8ea6adb
MD5 508df20e7ec99b2aa5dcaca9a422f976
BLAKE2b-256 042c2aaf5f37e427a65ba13feb178b5fad69dbbaa8cad70c356fe834897daae4

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