Skip to main content

A Library for Homomorphic Encryption Operations on Tensors

Project description

TenSEAL

Tests Linux Package MacOS Package Windows Package Docker Image

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

Support

For support in using this library, please join the #lib_tenseal Slack channel. If you’d like to follow along with any code changes to the library, please join the #code_tenseal Slack channel. Click here to join our Slack community!

Tutorials

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.0-cp39-cp39-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.9Windows x86-64

tenseal-0.3.0-cp39-cp39-manylinux2014_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.9

tenseal-0.3.0-cp39-cp39-macosx_10_15_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.9macOS 10.15+ x86-64

tenseal-0.3.0-cp38-cp38-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.8Windows x86-64

tenseal-0.3.0-cp38-cp38-manylinux2014_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.8

tenseal-0.3.0-cp38-cp38-macosx_10_15_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.8macOS 10.15+ x86-64

tenseal-0.3.0-cp37-cp37m-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.7mWindows x86-64

tenseal-0.3.0-cp37-cp37m-manylinux2014_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.7m

tenseal-0.3.0-cp37-cp37m-macosx_10_15_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.7mmacOS 10.15+ x86-64

tenseal-0.3.0-cp36-cp36m-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.6mWindows x86-64

tenseal-0.3.0-cp36-cp36m-manylinux2014_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.6m

tenseal-0.3.0-cp36-cp36m-macosx_10_15_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.6mmacOS 10.15+ x86-64

File details

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

File metadata

  • Download URL: tenseal-0.3.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1

File hashes

Hashes for tenseal-0.3.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 882b90f15fd893b26eb2a5734c187ef721aa61d7f2d5ac132d91d068f8de9608
MD5 bd9d2fc4c884b964abdc5488975f9176
BLAKE2b-256 1d0f37afd90416e7a28062f9a7d5e142b3bb15bc1e0c19f855766394d5ac0541

See more details on using hashes here.

File details

Details for the file tenseal-0.3.0-cp39-cp39-manylinux2014_x86_64.whl.

File metadata

  • Download URL: tenseal-0.3.0-cp39-cp39-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 4.5 MB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for tenseal-0.3.0-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8e5b87296a12158920d364201204ce2027a2937d6fd2d5bd65f0f2294020cb38
MD5 256f26843a2b56b1e029e238c6110090
BLAKE2b-256 c86dd3154eee0eea6e0a52ca16bbec2d2b22061137abed1ffb81ee2c9e1fa114

See more details on using hashes here.

File details

Details for the file tenseal-0.3.0-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: tenseal-0.3.0-cp39-cp39-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 3.8 MB
  • Tags: CPython 3.9, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for tenseal-0.3.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 b53a9d48aff24b40b8d788b397928a965ad3ea5f04bcd59a5565d3eb4fa988ab
MD5 8aba41486be38b69879f2de4c8cddb9d
BLAKE2b-256 db0ccc3aa1c29081142d6f12bc48c6877f2e2a972fbd86d24c8d6e7eb58c045a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.7

File hashes

Hashes for tenseal-0.3.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 f7e05e3dd83b631ecce8268ef1aae0b5188fa796398713217d9352c6a7ab7204
MD5 43f2a2c9a342314face005d9310223a0
BLAKE2b-256 cc8dfa6bcceb5e9198b2284efe7ce133c74db099f928f159a5790a34ff11fa95

See more details on using hashes here.

File details

Details for the file tenseal-0.3.0-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: tenseal-0.3.0-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 4.5 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.7

File hashes

Hashes for tenseal-0.3.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fd11095967d702223fd9a13742aa93c01b2ebde0d868297e53af04ad4efcb005
MD5 2c2e0a91f3effcd9923a51266407660a
BLAKE2b-256 180971003caab86b7c0a237de49447909676af04186c2d9c5ea72ea935c3c53c

See more details on using hashes here.

File details

Details for the file tenseal-0.3.0-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: tenseal-0.3.0-cp38-cp38-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 3.8 MB
  • Tags: CPython 3.8, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.7

File hashes

Hashes for tenseal-0.3.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 03aeea6569615a2935674e1bc2687bfd5c3efa8269dc141832f279a75fd675d1
MD5 6fff1ad0843e609f03424f62f483642f
BLAKE2b-256 2dd418d82c7f0d2764694997eab9e7b58bda555c8486f9faa3b452a865a32937

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.7.9

File hashes

Hashes for tenseal-0.3.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 5c8ee78f4ca2bc69bd3960e0e25ca0439152d9fb5643180005f31bb3832af41d
MD5 97eb239a492fa0dc36c366016dfdefdf
BLAKE2b-256 af6e5c76d02d329e4f83e517942b6e564f75a0ff7bee4605a228b1d1abb7266e

See more details on using hashes here.

File details

Details for the file tenseal-0.3.0-cp37-cp37m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: tenseal-0.3.0-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.7.10

File hashes

Hashes for tenseal-0.3.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c7e131a4f90d7626c0ca27325e5ce8dc91025ce056603a72a13f88835bac9fa3
MD5 9acf114959d1983faf0cd20a69972d85
BLAKE2b-256 379cc47f7d2358f2a77c8f0803fd7e70014720f6ecf1030b0e05e351e41c0369

See more details on using hashes here.

File details

Details for the file tenseal-0.3.0-cp37-cp37m-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: tenseal-0.3.0-cp37-cp37m-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 3.7 MB
  • Tags: CPython 3.7m, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.7.9

File hashes

Hashes for tenseal-0.3.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 46ab594726e6db2f043c54c6c8e62f9b2d068dac876af7824db1f95f909adbe5
MD5 7bf500a83e6abce672b11697f4a45b42
BLAKE2b-256 38b2c36514ff451394b96f7808a739a75532cafdf5e8efc41d6ec309a4c49b8c

See more details on using hashes here.

File details

Details for the file tenseal-0.3.0-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: tenseal-0.3.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.6.8

File hashes

Hashes for tenseal-0.3.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 deb8370d30e232c11335ad074606a5dd900609b36de5ef9a35c5ad50c9e2cc2c
MD5 3c83efc05fff10b1a618da8c48899a0f
BLAKE2b-256 fe7b197760eb3ce8c6169fb23c3898f8db76961f3f5aeae6e0146528c247ddac

See more details on using hashes here.

File details

Details for the file tenseal-0.3.0-cp36-cp36m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: tenseal-0.3.0-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.6.13

File hashes

Hashes for tenseal-0.3.0-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cbc0f3870b587ef0f456923948dc4f44e631380a9a8b68385f6f91c7cc24f04f
MD5 7c44016a0750cc4f601abc052222f647
BLAKE2b-256 3520a4106c3eff920eccbe040276ed869193fadd8fbbc52307dd6922a453f085

See more details on using hashes here.

File details

Details for the file tenseal-0.3.0-cp36-cp36m-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: tenseal-0.3.0-cp36-cp36m-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 3.7 MB
  • Tags: CPython 3.6m, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.6.12

File hashes

Hashes for tenseal-0.3.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 fae11ec08dc517398f49b76b13c3659faf8bff5fbd7ab4b70991ddeb4775251d
MD5 5539a9c890031c4be12baaf6e2c13310
BLAKE2b-256 746c5d89c00910f2fbc3fbec9557d38039056ef1ccc27b00b8d945ab8857db50

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