{"id":13995239,"url":"https://github.com/snipsco/rust-paillier","last_synced_at":"2025-07-16T12:44:21.729Z","repository":{"id":66892016,"uuid":"69575339","full_name":"snipsco/rust-paillier","owner":"snipsco","description":"A pure-Rust implementation of the Paillier encryption scheme","archived":false,"fork":false,"pushed_at":"2018-05-25T10:54:06.000Z","size":146,"stargazers_count":79,"open_issues_count":10,"forks_count":12,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-08-10T14:18:49.548Z","etag":null,"topics":["cryptography","homomorphic-encryption","paillier","rust","secure-computation"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/snipsco.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-09-29T14:26:31.000Z","updated_at":"2024-06-24T15:36:31.000Z","dependencies_parsed_at":"2023-05-19T05:30:15.560Z","dependency_job_id":null,"html_url":"https://github.com/snipsco/rust-paillier","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snipsco%2Frust-paillier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snipsco%2Frust-paillier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snipsco%2Frust-paillier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snipsco%2Frust-paillier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/snipsco","download_url":"https://codeload.github.com/snipsco/rust-paillier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227177859,"owners_count":17743186,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cryptography","homomorphic-encryption","paillier","rust","secure-computation"],"created_at":"2024-08-09T14:03:19.106Z","updated_at":"2024-11-29T17:31:20.566Z","avatar_url":"https://github.com/snipsco.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# Paillier\n\n[![Build Status](https://travis-ci.org/snipsco/rust-paillier.svg)](https://travis-ci.org/snipsco/rust-paillier)\n[![Latest version](https://img.shields.io/crates/v/paillier.svg)](https://img.shields.io/crates/v/paillier.svg)\n[![License: MIT/Apache2](https://img.shields.io/badge/license-MIT%2fApache2-blue.svg)](https://img.shields.io/badge/license-MIT%2fApache2-blue.svg)\n\nEfficient pure-Rust library for the [Paillier](https://en.wikipedia.org/wiki/Paillier_cryptosystem) partially homomorphic encryption scheme, offering encoding of both scalars and vectors (for encrypting several values together).\nSupports several underlying arbitrary precision libraries, including [RAMP](https://github.com/Aatch/ramp) (default), [GMP](https://github.com/fizyk20/rust-gmp), and [num](https://github.com/rust-num/num).\n\n**Important**: while we have followed recommendations regarding the scheme itself, this library should currently be seen as an experimental implementation. In particular, no particular efforts have so far been made to harden it against non-cryptographic attacks, including side-channel attacks.\n\n\n```rust\nextern crate paillier;\nuse paillier::*;\n\nfn main() {\n\n  // generate a fresh keypair and extract encryption and decryption keys\n  let (ek, dk) = Paillier::keypair().keys();\n\n  // select integral coding\n  let code = integral::Code::default();\n\n  // pair keys with coding\n  let eek = ek.with_code(\u0026code);\n  let ddk = dk.with_code(\u0026code);\n\n  // encrypt four values\n  let c1 = Paillier::encrypt(\u0026eek, \u002610);\n  let c2 = Paillier::encrypt(\u0026eek, \u002620);\n  let c3 = Paillier::encrypt(\u0026eek, \u002630);\n  let c4 = Paillier::encrypt(\u0026eek, \u002640);\n\n  // add all of them together\n  let c = Paillier::add(\u0026eek,\n    \u0026Paillier::add(\u0026eek, \u0026c1, \u0026c2),\n    \u0026Paillier::add(\u0026eek, \u0026c3, \u0026c4)\n  );\n\n  // multiply the sum by 2\n  let d = Paillier::mul(\u0026eek, \u0026c, \u00262);\n\n  // decrypt final result\n  let m: u64 = Paillier::decrypt(\u0026ddk, \u0026d);\n  println!(\"decrypted total sum is {}\", m);\n\n}\n```\n\n\n# Installation\n\nNote that some functionality is *not* included by default; see the [Building](#building) section for more details.\n\n## GitHub\n```bash\ngit clone https://github.com/snipsco/rust-paillier\ncd rust-paillier\ncargo build --release\n```\n\n## Cargo\n```toml\n[dependencies]\npaillier = { version=\"0.1\" }\n```\n\n\n## Building\n\nThe nightly toolchain is currently needed in order to build the library. For performance reasons we strongly encourage building and testing in release mode.\n\n### Arithmetic\n\nThe library supports the use of different arithmetic libraries, currently defaulting to [RAMP](https://github.com/Aatch/ramp) for portability with good performance.\n\nFor [RAMP](https://github.com/Aatch/ramp)-only compilation use `cargo` parameters\n```\n--no-default-features --features \"inclramp defaultramp keygen\"\n```\n\nFor [num](https://github.com/rust-num/num)-only compilation use\n```\n--no-default-features --features \"inclnum defaultnum\"\n```\n\nFor [GMP](https://github.com/fizyk20/rust-gmp)-only compilation use\n```\n--no-default-features --features \"inclgmp defaultgmp keygen\"\n```\n\nFinally, use\n```\n--no-default-features --features \"inclramp inclnum inclgmp defaultramp\"\n```\nto have one or more available, using one of them as the default (useful for e.g. performance tests).\n\n### Key generation\n\nKey generation is optional as it is currently only implemented when using [RAMP](https://github.com/Aatch/ramp) or [GMP](https://github.com/fizyk20/rust-gmp) as the underlying arithmetic library.\n\nWhile included by default it may be excluded using parameter\n```\n--no-default-features\n```\nin which case one or more arithmetic libraries must be specified as well as a default one, e.g.\n```\n--features \"inclramp inclgmp defaultramp\"\n```\nas shown in [above](#arithmetic) .\n\n\n\n\n# Performance\n\nSeveral benches are included, testing both the underlying arithmetic libraries as well as the operations of the scheme. All may be run using\n```\ncargo bench\n```\nand including either several arithmetic libraries and key generation as discussed [above](#building).\n\n# License\n\nLicensed under either of\n\n * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n## Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall\nbe dual licensed as above, without any additional terms or conditions.\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnipsco%2Frust-paillier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsnipsco%2Frust-paillier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnipsco%2Frust-paillier/lists"}