GithubHelp home page GithubHelp logo

tempbottle / rust-paillier-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mortendahl/rust-paillier

0.0 1.0 0.0 243 KB

A pure-Rust implementation of the Paillier encryption scheme

License: Other

Rust 100.00%

rust-paillier-1's Introduction

Paillier

Build Status Latest version License: MIT/Apache2

Efficient pure-Rust library for the Paillier partially homomorphic encryption scheme, offering encoding of both scalars and vectors (for encrypting several values together). Supports several underlying arbitrary precision libraries, including RAMP (default), GMP, and num.

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.

extern crate paillier;
use paillier::*;

fn main() {

  // generate a fresh keypair and extract encryption and decryption keys
  let (ek, dk) = Paillier::keypair().keys();

  // select integral coding
  let code = integral::Code::default();

  // pair keys with coding
  let eek = ek.with_code(&code);
  let ddk = dk.with_code(&code);

  // encrypt four values
  let c1 = Paillier::encrypt(&eek, &10);
  let c2 = Paillier::encrypt(&eek, &20);
  let c3 = Paillier::encrypt(&eek, &30);
  let c4 = Paillier::encrypt(&eek, &40);

  // add all of them together
  let c = Paillier::add(&eek,
    &Paillier::add(&eek, &c1, &c2),
    &Paillier::add(&eek, &c3, &c4)
  );

  // multiply the sum by 2
  let d = Paillier::mul(&eek, &c, &2);

  // decrypt final result
  let m: u64 = Paillier::decrypt(&ddk, &d);
  println!("decrypted total sum is {}", m);

}

Installation

Note that some functionality is not included by default; see the Building section for more details.

GitHub

git clone https://github.com/snipsco/rust-paillier
cd rust-paillier
cargo build --release

Cargo

[dependencies]
paillier = { version="0.1" }

Building

The nightly toolchain is currently needed in order to build the library. For performance reasons we strongly encourage building and testing in release mode.

Arithmetic

The library supports the use of different arithmetic libraries, currently defaulting to RAMP for portability with good performance.

For RAMP-only compilation use cargo parameters

--no-default-features --features "inclramp defaultramp keygen"

For num-only compilation use

--no-default-features --features "inclnum defaultnum"

For GMP-only compilation use

--no-default-features --features "inclgmp defaultgmp keygen"

Finally, use

--no-default-features --features "inclramp inclnum inclgmp defaultramp"

to have one or more available, using one of them as the default (useful for e.g. performance tests).

Key generation

Key generation is optional as it is currently only implemented when using RAMP or GMP as the underlying arithmetic library.

While included by default it may be excluded using parameter

--no-default-features

in which case one or more arithmetic libraries must be specified as well as a default one, e.g.

--features "inclramp inclgmp defaultramp"

as shown in above .

Performance

Several benches are included, testing both the underlying arithmetic libraries as well as the operations of the scheme. All may be run using

cargo bench

and including either several arithmetic libraries and key generation as discussed above.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. ย 

rust-paillier-1's People

Contributors

kali avatar mcornejo avatar mortendahl avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.