Skip to main content


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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tenseal-0.3.17.tar.gz (78.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tenseal-0.3.17-cp314-cp314-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.14Windows x86-64

tenseal-0.3.17-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

tenseal-0.3.17-cp314-cp314-macosx_14_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

tenseal-0.3.17-cp313-cp313-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.13Windows x86-64

tenseal-0.3.17-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

tenseal-0.3.17-cp313-cp313-macosx_14_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

tenseal-0.3.17-cp312-cp312-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.12Windows x86-64

tenseal-0.3.17-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

tenseal-0.3.17-cp312-cp312-macosx_14_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

tenseal-0.3.17-cp311-cp311-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.11Windows x86-64

tenseal-0.3.17-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

tenseal-0.3.17-cp311-cp311-macosx_14_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

File details

Details for the file tenseal-0.3.17.tar.gz.

File metadata

  • Download URL: tenseal-0.3.17.tar.gz
  • Upload date:
  • Size: 78.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tenseal-0.3.17.tar.gz
Algorithm Hash digest
SHA256 3b444150bd400392e2672bdbb36f4df455178f4193bd0a00f9cb267400dd6f4f
MD5 f41fd29c2b694e6b9318f299437fa79c
BLAKE2b-256 4eb3b0851cae661ec992201451996fcd95b7f27534981891e297fbeb9e97567e

See more details on using hashes here.

File details

Details for the file tenseal-0.3.17-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: tenseal-0.3.17-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tenseal-0.3.17-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 03586cb6e2bf40cedb6a0e19d48dcd744179b8f469061e153871192f067706d3
MD5 391ccf573558a0f38bde2ef1da47f0d9
BLAKE2b-256 4b7f7b39beea04c9c51ed2a221cf4920dc3dc35e6b37a76d7fd8ee522fa11843

See more details on using hashes here.

File details

Details for the file tenseal-0.3.17-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.17-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 637ac101c433f5d23cf12bebaab85c8c53d9f906fe7482265010748f48ec47e3
MD5 e4b2a8bbeedc8f53fa9636b95f94deb6
BLAKE2b-256 6f561cad0c5ccc8a1f1c6b14247f046a7dc98c434576acd89f90c4c28ea33d2e

See more details on using hashes here.

File details

Details for the file tenseal-0.3.17-cp314-cp314-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.17-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 397a2b456cd44c37a3cd9cf6d8385423223081e782dd010e4a0e1fea59228cf7
MD5 503108dd84ddf5f8a1b0d5c1915b8daf
BLAKE2b-256 2865f9942bd5abb397a5b71b801daa7e5cbd66f9c2e7b24f1692a4ae7a82771e

See more details on using hashes here.

File details

Details for the file tenseal-0.3.17-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: tenseal-0.3.17-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tenseal-0.3.17-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 170177c99e4c9df64ef976ac4d4cd17aef50fc8f1f78d4eac88643ff1053feb1
MD5 79848ba2111de4071b425e2b8c4917fb
BLAKE2b-256 e5a9ab34dd53c5cd702bb066d2df703aacf59805ebdd2c5d0407dd2f0738f451

See more details on using hashes here.

File details

Details for the file tenseal-0.3.17-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.17-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 71a5623154d7c1327e93aa1bb056e97117f3e5474996e017ade2aaf18c57fb1c
MD5 5d6606389a6e916cd978cee0d549d290
BLAKE2b-256 37ad3be759d3c3e936484690b233185c4bc36e5e9ca60442ec14376b1433bae3

See more details on using hashes here.

File details

Details for the file tenseal-0.3.17-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.17-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 6ae0720bdd3dad01280676ecb9a904af7627fc03f625bc89d8375e6e0cf3cb67
MD5 1d3843aede35c43f5f7c08d69d6a79e2
BLAKE2b-256 14c4dc943e0d3ee0fb41905c8c301871e4d5a7d0d8dd1a9304ac14817742e3ed

See more details on using hashes here.

File details

Details for the file tenseal-0.3.17-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: tenseal-0.3.17-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tenseal-0.3.17-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e6ec5e5abba2f46286b16f3379b8239d779c1b9c1568f371bbb5dc3974782c89
MD5 86dc88f9641516d42c218d7349682127
BLAKE2b-256 332f73c8d34bddd1978436098ff179de795b1bd2166562e83c4f3e60f2404bc5

See more details on using hashes here.

File details

Details for the file tenseal-0.3.17-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.17-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 47499064d79a8b5159d93ae4b2118f12a22795d6e1cc962a64bda0d36ba26334
MD5 59fbba2fc67552f4accd1793a973126f
BLAKE2b-256 c27ef82c8da65ea724eea99abdeab35931611b721669bc8793de62be6438c373

See more details on using hashes here.

File details

Details for the file tenseal-0.3.17-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.17-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 1018706a75e5ba781f0867dbeb5c327d16d305773b27807cff63fd761e9dcb9c
MD5 1750e757164256d1091921cc87c5e811
BLAKE2b-256 3df90c92ce8b48b52e42beedd2a7cf8d8cce1431b78c2a65bed13987c38743b3

See more details on using hashes here.

File details

Details for the file tenseal-0.3.17-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: tenseal-0.3.17-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tenseal-0.3.17-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 92764cb5fd74932136f04f00078c7d2256e16dabb009976e65889ae324f1b81b
MD5 3afeeeb583b03c6db2d3356a73d0c654
BLAKE2b-256 33785f8a107f8839c129a06239678e23f0a4042c93655a9a9e2c1110d52c0e24

See more details on using hashes here.

File details

Details for the file tenseal-0.3.17-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.17-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d1cc2fa8ca7ea8c44813cac60534bff0eea7ada234a472f899c0a8734afc82b4
MD5 e937d17e8066245b39492fabfb983d62
BLAKE2b-256 5667151cbbc12805352a4570b0149212774ea6e3ba3cae654df6b649f019f26d

See more details on using hashes here.

File details

Details for the file tenseal-0.3.17-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.17-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 df9725f111265303b3c739dd8a9656e354b3ecddba8ade8e907f28e6c7cc07cb
MD5 d88d2ad4a9b88b7676a694b7527c5466
BLAKE2b-256 fe45cf3664c1843f65ff0170f05cec6a39a4336bdefedab93fc07e74db492d65

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