Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update cargo.toml curve version #76

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
language: rust
rust:
- nightly
cache: cargo
rust: stable
virt: lxd

before_install:
- rustup component add rustfmt clippy

script:
- cargo build --verbose
- cargo test --verbose
- cargo fmt --all -- --check
- cargo clippy -- -D clippy::all

deploy:
provider: cargo
token:
secure: "ceREbzfOc3S7P0c+n4a7tHGtazS+99YRY17LZ9cVep4b9RmQ6AWjdPubhUxaS0zNVVtvFUhsBltcSyn66XUv4jgalfFn63zRfz80OXSETDuwaNIdRLP2+tJ9Q23Hfs6YuvhuA4bgDwAfHjf5yJPy6s0WDsVnLCyiVbAKQO92SVB5x/+tYvs/IZAgeQX6WSwOAagDjSLUj7dxdAXtUyFbK9y7zEpuq96k1+E9E7yFFsePXhRIoPCfQHg/l0tysTPDXFbUb8o7Fq/6N/tkS/O+5lxGwlEeF0z5aDrT6SxlGgGe/0YcQtmDLdy/Dx6rZmtQQeVk4eJPxd+uR1WrCG9mT379kbXn6JZy0Au/kIwWAsuczJlndrmW/KY3dF8I47PC/+jIF7q4Vw4DK9maZx8qySQlaDpiOFtaaKAvpqi3ZbXP7K7IQyaoEFRwQcd6DbhULazfL+ITjdJJmQBBCGbB3f4+55CZEpQGtJTybptPcEE3sQs16bUXWz3lKtd9pErGEqxm1I2WgvDzRBKhNzdmdujyqOrQEOxw5vy/EHXo8nDBnD/b7q8aPSJmaVjBx+lxYr6TILU/U00jgx8CUcsOgFH6mqZVm7573dMdUAlmAmvXhloXXav486tNeyfqJ1D/tGK/cjx28u0ebs94mGLYC8TWiGSPdHSsLe3yopiFXjM="
on:
tags: true
condition: "$TRAVIS_TAG =~ ^v[0-9.]+$"
71 changes: 27 additions & 44 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,54 +1,25 @@
[package]
name = "paillier"
version = "0.2.1-alpha.0"
authors = [
"Mario Cornejo <[email protected]>",
"Morten Dahl <[email protected]>",
"Mathieu Poumeyrol <[email protected]>"
]
description = "A pure-Rust implementation of the Paillier encryption scheme"
keywords = [
"paillier",
"cryptography",
"homomorphic-encrypt",
"secure-computation",
"zero-knowledge",
]
homepage = "https://github.com/mortendahl/rust-paillier"
repository = "https://github.com/mortendahl/rust-paillier"
documentation = "https://docs.rs/paillier"
license = "MIT/Apache-2.0"
categories = ["cryptography"]

[badges]
travis-ci = { repository = "mortendahl/rust-paillier" }

[features]
default = ["usegmp", "keygen", "proofs"]
keygen = []
proofs = ["ring"]
useramp = ["ramp"]
useframp = ["framp"]
usegmp = ["rust-gmp"]
gmp_nonsec = []
name = "kzen-paillier"
version = "0.4.2"
edition = "2018"
description = "Efficient pure-Rust library for the Paillier partially homomorphic encryption scheme"
license = "MIT OR Apache-2.0"
repository = "https://github.com/ZenGo-X/rust-paillier"
categories = ["cryptography", "algorithms"]
keywords = ["paillier", "homomorphic", "encryption", "zero-knowledge", "cryptoagorithms"]

[dependencies]
num-traits = "0.1"
rand = "0.5"
rayon = "1.0"
serde = "1.0"
serde_derive = "1.0"
ramp = { version="0.5", optional=true }
framp = { version="0.3", optional=true }
rust-gmp = { version="0.5", optional=true }
ring = { version="0.13", optional=true }

bit-vec = "0.5"
rayon = "1.1"
serde = { version = "1.0", features = ["derive"] }
curv-kzen = { version = "0.10", default-features = false }

[dev-dependencies]
bencher = "0.1"
# bencher = { git="https://github.com/snipsco-forks/bencher" }
serde_json = "1.0"
rand = "0.6"

[features]
default = ["curv-kzen/rust-gmp-kzen"]

[[bench]]
name = "arith"
Expand All @@ -65,3 +36,15 @@ harness = false
[[bench]]
name = "proof"
harness = false

[[example]]
name = "basic"

[[example]]
name = "core"

[[example]]
name = "packed"

[[example]]
name = "simple-voting"
57 changes: 28 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Paillier

[![Build Status](https://travis-ci.org/mortendahl/rust-paillier.svg)](https://travis-ci.org/mortendahl/rust-paillier)
[![Latest version](https://img.shields.io/crates/v/paillier.svg)](https://img.shields.io/crates/v/paillier.svg)
[![License: MIT/Apache2](https://img.shields.io/badge/license-MIT%2fApache2-blue.svg)](https://img.shields.io/badge/license-MIT%2fApache2-blue.svg)
[![Build Status](https://www.travis-ci.com/ZenGo-X/rust-paillier.svg?branch=master)](https://www.travis-ci.com/ZenGo-X/rust-paillier)
[![Latest version](https://img.shields.io/crates/v/kzen-paillier.svg)](https://crates.io/crates/kzen-paillier)
[![Docs](https://docs.rs/kzen-paillier/badge.svg)](https://docs.rs/kzen-paillier)
[![License: MIT/Apache2](https://img.shields.io/badge/license-MIT%2fApache2-blue.svg)](LICENSE)

Efficient pure-Rust library for the [Paillier](https://en.wikipedia.org/wiki/Paillier_cryptosystem) partially homomorphic encryption scheme, offering also packed encoding for encrypting several values together as well as several zero-knowledge proofs related to typical use-cases.
Supports several underlying arbitrary precision libraries, including [RAMP](https://github.com/Aatch/ramp) and [GMP](https://github.com/fizyk20/rust-gmp).
Supports several underlying arbitrary precision libraries: [GMP](https://github.com/ZenGo-X/rust-gmp) and [num-bigint](https://github.com/rust-num/num-bigint).

Several companies have invested resources in the development of this library, including [Snips](https://snips.ai/) who implemented the [original version](https://github.com/snipsco/rust-paillier) for use in their privacy-preserving analytics system, and [KZen networks](https://github.com/KZen-networks) who contributed with implementations of many zero-knowledge proofs. See [contributions](#contributions) below for more details.

**Important**: while we have followed recommendations regarding the scheme itself, some parts of this library have not yet been harden against non-cryptographic attacks such as side-channel attacks.
**Important**: while we have followed recommendations regarding the scheme itself, some parts of this library have not yet been hardened against non-cryptographic attacks such as side-channel attacks.


```rust
Expand Down Expand Up @@ -45,34 +46,36 @@ fn main() {

# Installation

Some features are optional yet currently included by default. See [Features](#features) below for more details. Note that the nightly toolchain is currently needed to build the library.

## Using cargo
```toml
[dependencies]
paillier = { version="0.2" }
[dependencies.paillier]
package = "kzen-paillier"
version = "0.2"
```

## From source
```bash
git clone https://github.com/mortendahl/rust-paillier
cd rust-paillier
cargo build --release
```
## Underlying arithmetic

## Features
The choice of underlying arithmetic library may be changed using features
`curv/rust-gmp-kzen` (default) and `curv/num-bigint`. GMP generally offers
better performance, but requires GMP shared library to be installed on the
system. `nim-bigint` is pure Rust implementation of big integer and doesn't
require any external dependencies.

The library supports the following features. The default compilation is equivalent to
```
cargo build --release --no-default-features --features "usegmp keygen proofs"
```
using GMP and including both key generation and zero-knowledge proofs.
Only performance is affected by choosing one of arithmetic implementation.
All functionality remains the same.

### Underlying arithmetic
In order to build on `num-bigint` instead, put into Cargo.toml:

The choice of underlying arithmetic library may be changed using features `usegmp` (default) and `useramp`. GMP generally offers [slightly better performance](https://medium.com/snips-ai/benchmarking-paillier-encryption-15631a0b5ad8) but may be unavailable on some platforms or for some applications. Note that `useramp` does currently *not* support proofs, i.e. features `useramp` and `proofs` cannot be used together.
```toml
[dependencies.paillier]
package = "kzen-paillier"
version = "0.2"
default-features = false
features = ["curv/num-bigint"]
```

# Usage

### Key generation
## Key generation

Key generation feature `keygen` is included by default but if unneeded may safely be excluded to avoid extra dependencies.

Expand All @@ -90,10 +93,6 @@ fn main() {
}
```

### Zero-knowledge proofs

Feature `proofs` includes various zero-knowledge proofs related to the typical use of Paillier encryption. Turned on by default but may safely be excluded if unneeded.

# Benchmarks

Several benches are included, testing both the underlying arithmetic libraries as well as the operations of the scheme. All may be run using
Expand Down
27 changes: 12 additions & 15 deletions benches/arith.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
#[macro_use]
extern crate bencher;
extern crate paillier;
use bencher::{benchmark_group, benchmark_main, Bencher};
use curv::arithmetic::traits::*;

use bencher::Bencher;
use paillier::arithimpl::traits::*;
use paillier::*;
use kzen_paillier::*;

mod helpers;
use helpers::*;

pub fn bench_mul(b: &mut Bencher) {
let ref p: BigInt = str::parse(P2048).unwrap();
let ref q: BigInt = str::parse(Q2048).unwrap();
let p: &BigInt = &BigInt::from_str_radix(P2048, 10).unwrap();
let q: &BigInt = &BigInt::from_str_radix(Q2048, 10).unwrap();

b.iter(|| {
let _ = p * q;
});
}

pub fn bench_mulrem(b: &mut Bencher) {
let ref p: BigInt = str::parse(P2048).unwrap();
let ref q: BigInt = str::parse(Q2048).unwrap();
let ref n: BigInt = str::parse(N2048).unwrap();
let p: &BigInt = &BigInt::from_str_radix(P2048, 10).unwrap();
let q: &BigInt = &BigInt::from_str_radix(Q2048, 10).unwrap();
let n: &BigInt = &BigInt::from_str_radix(N2048, 10).unwrap();

b.iter(|| {
let _ = (p * q) % n;
});
}

pub fn bench_modarith(b: &mut Bencher) {
let ref p: BigInt = str::parse(P2048).unwrap();
let ref q: BigInt = str::parse(Q2048).unwrap();
let ref n: BigInt = str::parse(N2048).unwrap();
let p: &BigInt = &BigInt::from_str_radix(P2048, 10).unwrap();
let q: &BigInt = &BigInt::from_str_radix(Q2048, 10).unwrap();
let n: &BigInt = &BigInt::from_str_radix(N2048, 10).unwrap();

b.iter(|| {
let _ = BigInt::modpow(p, q, n);
let _ = BigInt::mod_pow(p, q, n);
});
}

Expand Down
31 changes: 13 additions & 18 deletions benches/encryption.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
#[macro_use]
extern crate bencher;
extern crate num_traits;
extern crate paillier;
use bencher::{benchmark_group, benchmark_main, Bencher};

use bencher::Bencher;
use paillier::encoding::*;
use paillier::*;
use kzen_paillier::*;

mod helpers;
use helpers::*;

pub fn bench_encryption_ek<KS: KeySize>(b: &mut Bencher) {
let ref keypair = KS::keypair();
let ek = EncryptionKey::from(keypair);
let keypair = KS::keypair();
let ek = EncryptionKey::from(&keypair);

b.iter(|| {
let _ = Paillier::encrypt(&ek, 10);
});
}

pub fn bench_encryption_dk<KS: KeySize>(b: &mut Bencher) {
let ref keypair = KS::keypair();
let dk = DecryptionKey::from(keypair);
let keypair = KS::keypair();
let dk = DecryptionKey::from(&keypair);

b.iter(|| {
let _ = Paillier::encrypt(&dk, 10);
});
}

pub fn bench_decryption<KS: KeySize>(b: &mut Bencher) {
let ref keypair = KS::keypair();
let keypair = KS::keypair();
let (ek, dk) = keypair.keys();

let c = Paillier::encrypt(&ek, 10);
Expand All @@ -40,8 +35,8 @@ pub fn bench_decryption<KS: KeySize>(b: &mut Bencher) {
}

pub fn bench_rerandomisation<KS: KeySize>(b: &mut Bencher) {
let ref keypair = KS::keypair();
let ek = EncryptionKey::from(keypair);
let keypair = KS::keypair();
let ek = EncryptionKey::from(&keypair);

let c = Paillier::encrypt(&ek, 10);

Expand All @@ -51,8 +46,8 @@ pub fn bench_rerandomisation<KS: KeySize>(b: &mut Bencher) {
}

pub fn bench_addition<KS: KeySize>(b: &mut Bencher) {
let ref keypair = KS::keypair();
let ek = EncryptionKey::from(keypair);
let keypair = KS::keypair();
let ek = EncryptionKey::from(&keypair);

let c1 = Paillier::encrypt(&ek, 10);
let c2 = Paillier::encrypt(&ek, 20);
Expand All @@ -63,8 +58,8 @@ pub fn bench_addition<KS: KeySize>(b: &mut Bencher) {
}

pub fn bench_multiplication<KS: KeySize>(b: &mut Bencher) {
let ref keypair = KS::keypair();
let ek = EncryptionKey::from(keypair);
let keypair = KS::keypair();
let ek = EncryptionKey::from(&keypair);

let c = Paillier::encrypt(&ek, 10);

Expand Down
Loading