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.5.0.tar.gz (115.2 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.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (524.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pypaillier-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (524.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pypaillier-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (525.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pypaillier-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (525.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pypaillier-0.5.0.tar.gz
Algorithm Hash digest
SHA256 f082e9abe5f66dfb38c591618f8c5b481522022cf9b067fa1f490df191a03005
MD5 0b14efe0198d3695a000b1812afe48e8
BLAKE2b-256 8306aa370a22cc975305ed43ccc1f3abfcaccd99d0a0a299a8629d865dbd6451

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypaillier-0.5.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.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pypaillier-0.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 35bc76e05ab4dc86ca0b01db553ab6cdedb5ba8dd93ad4c2224be2822cb79ca0
MD5 ceb94ccb566d3f56e52562432e2a1943
BLAKE2b-256 14c0ea29cb2fba22359b013c130657661bdb02fae43ebaf014a539cf2399be14

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypaillier-0.5.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.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pypaillier-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 64f1f8e474eedf9270cc8ca1b6eeb5f3e363194cc2a3c03d54c925b5c400ca30
MD5 c74ebe0ccbd020a15ae843e1dde41347
BLAKE2b-256 58f6bca2b139cfd5f6cafe3b70401c166a427ea3a1fd3327a4f55d5c07a9bf3a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypaillier-0.5.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.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pypaillier-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 674ba80038d8013bdb71b753bd29da7e2c4b2471bab00acdd35a8ef4da155e9b
MD5 bb84f1bc9fba747616e645d7e1df2f5b
BLAKE2b-256 6ccb1ae8261b383366b52be8e7c39dc7853c2a9e7878fb25a0733b0f249944eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypaillier-0.5.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.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pypaillier-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 edbd859463870aa1b754a1d02a3d47ecb37a0bbd34165cdc4e87aceaa652e67a
MD5 b8c3ad8fb2ba876aae2f16a9ede686aa
BLAKE2b-256 4b4fa6e580ba94bb2ccc2da018301f5b0fa34c6302518a629a9153dccc090d21

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypaillier-0.5.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

0.7.0

5 files

0.6.0

5 files

This release

0.5.0 This release

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