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.6.0.tar.gz (125.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.6.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (529.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pypaillier-0.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (529.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pypaillier-0.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (529.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pypaillier-0.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (529.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: pypaillier-0.6.0.tar.gz
  • Upload date:
  • Size: 125.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.6.0.tar.gz
Algorithm Hash digest
SHA256 972c9a6a1d40e452df03757caa4a7c4b9e786d8034cb75279fff151eb4982333
MD5 7bc1c0a18d100690f2a14f7e2bb8e283
BLAKE2b-256 123a7ce105287b6991a9edc6301b4e4334d8598a62406fc13978d896a707eb64

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypaillier-0.6.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a33e014952d654e8c9971cee54546570e46e2fde0402c3a2439ba6389899322b
MD5 7cedc3a6f4220a71a958aa84b4d52857
BLAKE2b-256 5bbc6889b06e987b1a8040a1bca9886a16dc288e5c80c502c28c44e64f9b383c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypaillier-0.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 34757aa3dd7e5426ae6f4b68bfcf26dcb34f8c8b058f09b771a3f96fdce48320
MD5 6630913fe7447b027b7e55e27fc90c76
BLAKE2b-256 45088d0069c436c28e43a7a9f875c84710ed55eadbf57862584e129b26a83d40

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypaillier-0.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a550ba40a191827ce513b415c9f84a1488fdc993db0e8b6903a1eb225bd5b942
MD5 7877cbf66cfe613843491fe61a7ad305
BLAKE2b-256 db550f05eba9b54efa3317d81fa74bd5b667b8ba6391833157cf188c403f1642

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypaillier-0.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b17573caea41e9389d0221733424f5142afa022fc7170c006fbed1f32954fca9
MD5 ef2eec0fda02c274ee0e2233c1509917
BLAKE2b-256 2b4c209f3a054d56bb6a693c28d1a7a922737056da3c5e77b41df695d13a354d

See more details on using hashes here.

Provenance

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

This release

0.6.0 This release

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