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

tenseal-0.3.16-cp313-cp313-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.13Windows x86-64

tenseal-0.3.16-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.8 MB view details)

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

tenseal-0.3.16-cp313-cp313-macosx_14_0_arm64.whl (3.4 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

tenseal-0.3.16-cp313-cp313-macosx_13_0_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64

tenseal-0.3.16-cp312-cp312-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.12Windows x86-64

tenseal-0.3.16-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.8 MB view details)

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

tenseal-0.3.16-cp312-cp312-macosx_14_0_arm64.whl (3.4 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

tenseal-0.3.16-cp312-cp312-macosx_13_0_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.12macOS 13.0+ x86-64

tenseal-0.3.16-cp311-cp311-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.11Windows x86-64

tenseal-0.3.16-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.8 MB view details)

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

tenseal-0.3.16-cp311-cp311-macosx_14_0_arm64.whl (3.4 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

tenseal-0.3.16-cp311-cp311-macosx_13_0_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.11macOS 13.0+ x86-64

tenseal-0.3.16-cp310-cp310-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.10Windows x86-64

tenseal-0.3.16-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.8 MB view details)

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

tenseal-0.3.16-cp310-cp310-macosx_14_0_arm64.whl (3.4 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

tenseal-0.3.16-cp310-cp310-macosx_13_0_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.10macOS 13.0+ x86-64

tenseal-0.3.16-cp39-cp39-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.9Windows x86-64

tenseal-0.3.16-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.8 MB view details)

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

tenseal-0.3.16-cp39-cp39-macosx_14_0_arm64.whl (3.4 MB view details)

Uploaded CPython 3.9macOS 14.0+ ARM64

tenseal-0.3.16-cp39-cp39-macosx_13_0_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.9macOS 13.0+ x86-64

File details

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

File metadata

  • Download URL: tenseal-0.3.16-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for tenseal-0.3.16-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 490c76b5d081e9dec17c88003b045b43d30db738b8031cc1620a29f118504fb8
MD5 23cff879820f58ad7b1649c2fdb2a911
BLAKE2b-256 e49ffe14dc2a1b1d5ddbbae18d3e9e17fb661339f369c895285533dfd2e70134

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.16-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4d3941cafb9ded865ac1d7080304788c8789865bf68e6d229486872e5340fc82
MD5 730236000573c402c215ede2ecc8a974
BLAKE2b-256 ec7f507c250da88824434636733d53c4464c8e9f210450493f634b9052b0ec58

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.16-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 1cee5bf1acc69ddf23be2983e7dcfde1f7f7032dd51451dae8ea49f18e158321
MD5 9ead1935e3ebf0ea1a61941a38ed8c79
BLAKE2b-256 c304babe107997408b967d6259ce61a068f3c8aa50a022f1f337c96eb1cec6dc

See more details on using hashes here.

File details

Details for the file tenseal-0.3.16-cp313-cp313-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.16-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 884350410577ce355394e3bc557524b55689b47830d4aaf41d48295f5399ee84
MD5 fdb866e0c42e3f50a1165264833ae5f5
BLAKE2b-256 05377b45b3458d203486a9efad3b67c5f02085aa01554ee2a3cddbb47b0281a6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.16-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for tenseal-0.3.16-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f77c3931eaca88364895c20144d22242a4eea7e20ae6623d1694cde5f45205dc
MD5 bce0b11e24edf242c7edc71a97281ae1
BLAKE2b-256 0acc3817db86afaf61c6b7da458a3551ee270338f444dae5b2b8d50efaca0863

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.16-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 20b52be596b0c3b6c77df021b91eafd8eda6ef79a2358748aec0ec32e77778cf
MD5 a84e3081b1d81cf717cfb37a17e7b789
BLAKE2b-256 e188759a9170828cea917d560f08b53698c3e2e735614193447630317d328f67

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.16-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d5f0cce84f7a4c27324507867ff3c1495164f100570e88b62d72d4698560cd20
MD5 9fb29b6543ab4172a362827e2e5fbc70
BLAKE2b-256 3d3438eabf9e6362abd008e24a411a4baa2f7baf2f2b337e5d7cc68c87e7f4f1

See more details on using hashes here.

File details

Details for the file tenseal-0.3.16-cp312-cp312-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.16-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 634911a38d90ca89f33f81088c83ccd62b7fe441e0d6f84ab801e411e3060915
MD5 fa20c488e9d85f8ea273c243987a38be
BLAKE2b-256 f95913078c5a6c22d5604f1a266d1b3b8d94e441b8b8c3ec1999b721047b3dfb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.16-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for tenseal-0.3.16-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b89fd126d429b8cd2aa614e3bb5cf8c59199d739d5e22f5b534f651a05d20bed
MD5 1a9e278d442e1aab992dd10abd2b39bd
BLAKE2b-256 a5a90c8d89a05764acdcbe732d60c7285c157b32c25eb055b3e1a607da218712

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.16-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2815023756cb666369547d02cc6c4ec6fbe9971effa99015a4b0c0b8086669da
MD5 7fb0ef98daf6293ee5f44691f013dbe5
BLAKE2b-256 4dab545fbcc136d2e35f333966837697349262f7d29cc5e5ebc2ee63abfd3724

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tenseal-0.3.16-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0599fe98793084ccb2a2f10a9648d3aa2a199d86540e85de5a6693e48833d87d
MD5 146cfa87999f9b35f6154331f2953d90
BLAKE2b-256 d4a5d78f2bb1c11526874bd3759af03eaed0cbf402e436a0611e0bd4adaf49a1

See more details on using hashes here.

File details

Details for the file tenseal-0.3.16-cp311-cp311-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.16-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 794b27425a8d46dd918119ee10ee8a1d06e4d48b155d7011807343dc8055871f
MD5 f89f188fdfdff0d7d9c949b45d1b32af
BLAKE2b-256 8e39b9460e0545ddb17193515581aaf77d672aa3c9b57a41107a40cb6479c357

See more details on using hashes here.

File details

Details for the file tenseal-0.3.16-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: tenseal-0.3.16-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for tenseal-0.3.16-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b7326397dae981fdb6efa471a81e341c2987cc1f5639c659b9f6a78dcfd4c8f5
MD5 7e5b6cf7aa70b520778414dc18b0e7f8
BLAKE2b-256 16d036dc66bbbe3b448d86b54a34beb60db830936cdcf62f8432fb664bac4152

See more details on using hashes here.

File details

Details for the file tenseal-0.3.16-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.16-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7add306c52ba1a2c7cd8307601fb8e1d04c520c9caec998a34d5bb6d4c5e1bcf
MD5 b069335b026c5579b5779692a413155c
BLAKE2b-256 74cb4efda8aac9dd69840c3eb6e7f2d5ad73211e96e27041ce9f99762a952c5a

See more details on using hashes here.

File details

Details for the file tenseal-0.3.16-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.16-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 da46b413add8fc2413cd874d22095fefe8672d4c397956787ccbdeea058b5011
MD5 96e7b7d808cc675fab8d775b6fe41d1a
BLAKE2b-256 7bdb10c48438b02b967beec213af16c244633ef46c973cf333a4aa0d396f2eed

See more details on using hashes here.

File details

Details for the file tenseal-0.3.16-cp310-cp310-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.16-cp310-cp310-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 f382f7ca733d6e47444aa693be5e7c55effd56d756bbd2337dd23bb371def9e9
MD5 06d8605ca5dc8865533f166b8f30ee91
BLAKE2b-256 296ede653e6b83ec53afc56522960207088f353d7010ea3ad024abd6279706d7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tenseal-0.3.16-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for tenseal-0.3.16-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 fe8a547d14f5da3fa6bb117e23d6aa3c4b2a943313868cec5fe9b783598dd50e
MD5 3f67c43f1c9b33ce2cc08d9038bdf268
BLAKE2b-256 a865ef0d865948184fa0208fb6c5a8118ca53f2ef899aa8e5fc1c2d04e6e0505

See more details on using hashes here.

File details

Details for the file tenseal-0.3.16-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.16-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cfa5efcfa535f9a89d97eb5dcd6c16ae4eec21728a2f9361c6812ba1a497036f
MD5 de91a5718f3e5db636d1f9a432b3e826
BLAKE2b-256 f67ac06e66c48f3bc264f5948bf9d4dc65cd1ccc838900b4082c78db7bef5d9c

See more details on using hashes here.

File details

Details for the file tenseal-0.3.16-cp39-cp39-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.16-cp39-cp39-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 62f8516da04069b2dccc6328fc828bb1762400f08df6b51663a42e16a6120af3
MD5 675a69297cdba9bc526c15719e961d78
BLAKE2b-256 712c1aeeae2a18d0effa3f7ad6460458c308ece06504347deea4519bb02389df

See more details on using hashes here.

File details

Details for the file tenseal-0.3.16-cp39-cp39-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for tenseal-0.3.16-cp39-cp39-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 854e89c8159a6b059bba68901659cde74a1549b768dfcc54169fe4bec49c7857
MD5 62b55f3676eec9bed4dd301845a9c3d2
BLAKE2b-256 81725a4e48f88aec77abaa7070aa5443bfd6b41011c00a2e8f8fba65220ef4c8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page