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

Uploaded CPython 3.10Windows x86-64

tenseal-0.3.14-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.14-cp310-cp310-macosx_12_0_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.10macOS 12.0+ x86-64

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

Uploaded CPython 3.10macOS 11.0+ x86-64

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

Uploaded CPython 3.9Windows x86-64

tenseal-0.3.14-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.14-cp39-cp39-macosx_12_0_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.9macOS 12.0+ x86-64

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

Uploaded CPython 3.9macOS 11.0+ x86-64

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

Uploaded CPython 3.8Windows x86-64

tenseal-0.3.14-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.14-cp38-cp38-macosx_12_0_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.8macOS 12.0+ x86-64

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

Uploaded CPython 3.8macOS 11.0+ x86-64

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

Uploaded CPython 3.7mWindows x86-64

tenseal-0.3.14-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.14-cp37-cp37m-macosx_12_0_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.7mmacOS 12.0+ x86-64

tenseal-0.3.14-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.14-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: tenseal-0.3.14-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.2 CPython/3.10.9

File hashes

Hashes for tenseal-0.3.14-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6cd5c1813f579b14195b384fb76cc68d9cb87c16266c389217a48e549b4757e0
MD5 5fda3009567bb9b5453b3c94391e4edd
BLAKE2b-256 ed344814315effdc5d84dd94c8ee8d93aacee7521ddb06078da0b90282f3ef10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dc60a47dc5f8530aca86d6069fbac55d42d5771a7ff774ce44eed57e0168f591
MD5 9d218de3b498f6a9fe68b612b69d2d01
BLAKE2b-256 d6d40f6a8f44fe013f4de3edb85934d18b0ae992f94dcc1d5c02bd33ba5f7151

See more details on using hashes here.

File details

Details for the file tenseal-0.3.14-cp310-cp310-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.14-cp310-cp310-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 1d2eb19af56401fc4a6361098cfd8b3118ee7b4a306b945ce4ba972d5b32bf72
MD5 5f0349caede468345dcd4e6f5d3c9777
BLAKE2b-256 f98b88e3397054f959fc7db4aabf8d4dbc49b7b6b86cc83e18862f80c80ca4a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.14-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 6b15073f162cfd9a13e3a3b4be5db6770ef9d6a501c88876a50f76c751d221f8
MD5 39141e1a5f49694807518169def06680
BLAKE2b-256 dc1d23502e060b623ffe74eb6cc0913f1df7fffca9814eb5843e2caf8c3e4612

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.14-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.2 CPython/3.9.13

File hashes

Hashes for tenseal-0.3.14-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 29d0df0aba3122686756052446f7d2b4852d91aee1aed5fb378300759173a39c
MD5 aceed51367828218af4ffee973daa86a
BLAKE2b-256 56f2c5f5a6144d70f37bf6bf8fa9f531849622873528d8b1c5d4a2e5f0df2948

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.14-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 15992141e0c4627838a99601165a4b3d1726d8d5bc8706ee72e860211b44d4f6
MD5 867325b989030f6764d0ff1336ff7766
BLAKE2b-256 608d824787aedb01307da775fc4c9fc5765b113d8852f04aef5e0f4aaaa478fc

See more details on using hashes here.

File details

Details for the file tenseal-0.3.14-cp39-cp39-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.14-cp39-cp39-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 0f68618a9afeb1ce9387b401caf466283f0742f0bf01c654765668802236d765
MD5 63343c10d3e6ac5e31a9884a78ee6430
BLAKE2b-256 42a3717b920ce2a3277d11df8b1f5fa5253c143fda496d47f5aacbda14efc12d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.14-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 ef9d7a702e8fe621c643ad4b8aa1263fb02e9d7e3e1dc00e89f53354e830e2f2
MD5 b188da7387af595c17fc7045fd151d43
BLAKE2b-256 542466490f629a893e09d7306933fdaae4c8fc0de80eae005deef38ba8f0de4e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for tenseal-0.3.14-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 8fe78c0f1e7e1f54467c2713703c9d538e181ef59cd85a637fd69bdda65c1298
MD5 fbb4774519f134ed38433b8653811dd4
BLAKE2b-256 cbc0f056560c844052369036c727c0897722eb5a54d82a4412a1b50b12382fed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.14-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f4b29990e2be1e39ccf1889e9e8571e441ffa38b17cd611daa3e86ad941db912
MD5 2c33fb71baef5d9bacf84815547ffd17
BLAKE2b-256 dcff89bdfb234864c393d5a5ca03ec8d8826856c1b4e9a4b1a62d3961c569585

See more details on using hashes here.

File details

Details for the file tenseal-0.3.14-cp38-cp38-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.14-cp38-cp38-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 a4d38f5bbe2c06ee922b3c96ed6ddd6cdd1992065a9c0994b55858500a2cc6f5
MD5 8316ec6129cb1c533233f2e456321df1
BLAKE2b-256 21ae43fde621d7b8c16def1ecb223553f052fa30d1641da88390dd893a38e372

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.14-cp38-cp38-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 c763d45dd7b994d87efd242146fd9e40766b1ccfd823fff0e1ae5ecc4642c541
MD5 2a9e32770daa4b36da71d6d28ee86225
BLAKE2b-256 81121e7b02c5e34a635b16f1b0b2e8e8b8c153b9e6d267f40be1d1799b44ddfb

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for tenseal-0.3.14-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 b85fe571b2ad9b86a22cd52748a75547654eeecbece0b943fd68723ef76f69a7
MD5 767f01895eb32be998b67edfe3696885
BLAKE2b-256 d2e54e18d57a31a89a428db7e8173d59f26bb48610f7a98ca9e2be0c31d97ca6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.14-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eac5c4ee2ac589c168d98ca9046b5924e90ac33d396ddda9b0519b8398f42fd7
MD5 c916a110fd50f6400772474c71f9a0d0
BLAKE2b-256 abe35b71563e7035117b8e511ff8ebbe2b10937ccbe18e669f57be19eb95edcf

See more details on using hashes here.

File details

Details for the file tenseal-0.3.14-cp37-cp37m-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.14-cp37-cp37m-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 5df3300ed2070fa0579b974053bca429029a4c52983bc69255d4b83fc134d766
MD5 de0c699bb9b77950a033bea5d45faf7b
BLAKE2b-256 eaa90c227f993e05c51de68e8290bdc37f6e4c73ddaedf8d06b0052ccb323c75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.14-cp37-cp37m-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 2f01008a298489b4668c22347054805fb3cd12ed47ae159cc6a48db20d368b6d
MD5 0e657aec463885af47a8d21111c10a8c
BLAKE2b-256 740034fd453406044fe3add7df0e681996df42435a72376f134f6dfbc14dfb2f

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