Skip to main content

pypaillier

Additively homomorphic Paillier encryption: a Rust implementation on top of GMP, bound to Python through pyo3.

Add encrypted numbers without decrypting them:

import paillier

pub, sec = paillier.generate_keypair(2048)

blobs = [bytes(b) for b in paillier.encrypt_many(pub, [1.5, 2.25, -0.75])]
total = paillier.add_many(pub, blobs)      # adding CIPHERTEXTS

paillier.decrypt(sec, total)               # 3.0

Whoever does the adding never sees the terms. Whoever holds the private key sees only the sum.

pip install pypaillier

Wheels for CPython 3.10–3.13, manylinux_2_17. No compiler and no system GMP required. The distribution is pypaillier; the import name is paillier.

📖 Documentation

Before you use it

This is not textbook Paillier. The scheme is the Damgård–Jurik variant with a short exponent, c = (1 + m·n) · hs^r mod n². Ciphertext indistinguishability therefore rests on an additional short-exponent assumption, not on DCRA alone.

Constant time is not claimed as a whole-library property. The three timing channels found in encryption are closed: two are guarded by tests that measure a slope against the secret, and the third — the cache address — cannot be, because it changes neither the answer nor the time measurably; it is guarded by a check on the shape of the code. Key generation is a prime search and is not constant time at all.

Both are explained in full, with the measurements, in the documentation.

Numbers

2048-bit key, medians:

operation cost
encryption, all cores 6800+ ops/s
encryption, one core 1066 ops/s
addition 7.1 µs per term
decryption 3.9 ms
key generation 2.2–3.3 s
ciphertext 512–513 B

Reproduce with python benches/measure.py.

Accuracy

Fixed point, rounding to nearest. The scale is configurable and travels inside the ciphertext, so decryption reads it from there and addition refuses a batch that mixes scales:

blobs = paillier.encrypt_many(pub, values, scale_pow10=12)

The default is 10^8. See Encoding and scale.

Building from source

pip install maturin
maturin build --release

Needs stable Rust. GMP is built and linked statically.

Licences

The sources are MIT OR Apache-2.0, at your option.

The built wheels additionally contain GMP, statically linked through rug, and therefore fall under LGPL-3.0+ as a whole. For a binary with no LGPL code inside, build from the source distribution against your own GMP: pip install --no-binary pypaillier pypaillier.

Full breakdown, including how the LGPL §4 conditions are met: NOTICE.md.

Download files

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

Source Distribution

pypaillier-0.7.0.tar.gz (132.5 kB view details)

Uploaded Source

Built Distributions

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

pypaillier-0.7.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (545.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pypaillier-0.7.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (545.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pypaillier-0.7.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (545.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pypaillier-0.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (545.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

File details

Details for the file pypaillier-0.7.0.tar.gz.

File metadata

  • Download URL: pypaillier-0.7.0.tar.gz
  • Upload date:
  • Size: 132.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pypaillier-0.7.0.tar.gz
Algorithm Hash digest
SHA256 01586add0973e1973d029030d0db56e4ba393c3e95b7723688c2500ac0f1266b
MD5 563f2a3311ad0dc0d943fe74a591a715
BLAKE2b-256 a8f08469a1309ffef797be6f9b60036d1f0d18461797682af5d3ce144fc3dbcf

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypaillier-0.7.0.tar.gz:

Publisher: publish.yml on veryviolet/paillier

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypaillier-0.7.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pypaillier-0.7.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c824290e47378ac390ed2f3de78731b29682e276c621383884bef319da49bafe
MD5 f811ea26489c56c9ba52806f94c52d7d
BLAKE2b-256 d077b61317c450dc9dd0a98a9b53c9a64ad99ccb3cc6e80eec7539160d12c5c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypaillier-0.7.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on veryviolet/paillier

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypaillier-0.7.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pypaillier-0.7.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 31094970680519fa43b39bc0f6f516ffbf05014ddccc59c0f5361271131433f5
MD5 27a3da18ad5781fc5d4c5dc9a5256e52
BLAKE2b-256 bdb9ce33289da9a3df2735f60c9ee72656ab5dc947b2613df07a61846a3dc071

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypaillier-0.7.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on veryviolet/paillier

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypaillier-0.7.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pypaillier-0.7.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9cd61094293c3531611e935cee10bbf87a7cec81395691e9202c02f640dd4562
MD5 6caf8fe2ee97916cf4865842615a36f1
BLAKE2b-256 771647b7bb4c284bfccf54d36d288af358e527cc79d6f5ae6ea4b6a719420584

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypaillier-0.7.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on veryviolet/paillier

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypaillier-0.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pypaillier-0.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8ba31cd882a47b306add22cd385e86684b301bf6c4d37da60167e6d743f4b5fa
MD5 e437d09fef892318e6ce5d042abfe970
BLAKE2b-256 6d29b3d23f91a7b92fd5518085b5d21d6a21aa96b3d4ef4b534fff9e000d416a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypaillier-0.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on veryviolet/paillier

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.7.0 This release

5 files

0.6.0

5 files

0.5.0

5 files

0.4.0

5 files

0.3.0

5 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page