Git Product home page Git Product logo

parmesan's Introduction

Parmesan

Parallel ARithMEticS over ENcrypted data

Parmesan implements selected parallel algorithms for multi-digit arithmetics over TFHE ciphertexts. Namely:

  • addition/subtraction,
  • scalar multiplication (i.e., multiplication by a known integer),
  • multiplication,
  • squaring,
  • signum,
  • maximum of two numbers,
  • rounding, and
  • evaluation of a simple neural network.

Disclaimer: Parmesan is currently an experimental library, which serves as a proof-of-concept for parallelizable arithmetics over encrypted data. Hence neither correct functionality nor any level of code quality is guaranteed.

The Short Story

In the standard integer representation, parallel addition is not possible due to the carry, which can propagate all the way from the LSB to the MSB. However, using, e.g., an alphabet {-1,0,1} for base-2 integer representation, a parallel addition algorithm does exist. Other operations like (scalar) multiplication and squaring benefit from the fast addition, too.

The Long Story

See our full paper on eprint and our preceeding study that compares various approaches for parallel addition (also on eprint).

Use parmesan

Add a dependency to your Cargo.toml file in your Rust project.

[dependencies]
parmesan = { version = "^0.1.5", features = ["measure"] }
colored = "^2.0.0"

N.b., the latest version might be missing at crates.io, then adding github source would be needed:

parmesan = { git = "https://github.com/fakub/parmesan", branch = "master", version = ...

For the best performance, compile with

$ RUSTFLAGS="-C target-cpu=native" cargo build --release

Example

use std::error::Error;

use colored::Colorize;

use parmesan::params;
use parmesan::userovo::*;
use parmesan::ParmesanUserovo;
use parmesan::ParmesanCloudovo;
use parmesan::arithmetics::ParmArithmetics;

pub fn main() -> Result<(), Box<dyn Error>> {

    // =================================
    //  Initialization
    // ---------------------------------
    //  Global Scope
    let par = &params::PAR_TFHE_V0_5__M4_C0;

    // ---------------------------------
    //  Userovo Scope
    let pu = ParmesanUserovo::new(par)?;
    let pub_k = pu.export_pub_keys();
    // ---------------------------------
    //  Cloudovo Scope
    let pc = ParmesanCloudovo::new(par, &pub_k);

    // =================================
    //  U: Encryption
    let a: Vec<i32> = vec![1,0,1,-1,-1,0,-1,1,1,-1,1,1,1,-1,-1,0,0,1,1,0,0,0,0,-1,0,0,0,0,0,-1,0,0,];
    let b: Vec<i32> = vec![-1,0,0,-1,1,1,-1,1,-1,0,0,1,0,1,1,0,0,0,-1,0,0,1,0,0,-1,0,-1,-1,-1,1,1,0,];
    let ca = pu.encrypt_vec(&a)?;
    let cb = pu.encrypt_vec(&b)?;
    // convert to actual numbers
    let a_val = encryption::convert_from_vec(&a)?;
    let b_val = encryption::convert_from_vec(&b)?;
    // print plain inputs
    println!("\nInputs:\n");
    println!("a   = {:12}", a_val);
    println!("b   = {:12}", b_val);

    // =================================
    //  C: Evaluation
    let c_add_a_b = ParmArithmetics::add(&pc, &ca, &cb);

    // =================================
    //  U: Decryption
    let add_a_b = pu.decrypt(&c_add_a_b)?;

    let mut summary_text = format!("\nResults:\n");
    summary_text = format!("{}\nAddition:", summary_text);
    summary_text = format!("{}\na + b         = {:12} :: {} (exp. {})", summary_text,
                            add_a_b,
                            if add_a_b == a_val + b_val {String::from("PASS").bold().green()} else {String::from("FAIL").bold().red()},
                            a_val + b_val
    );

    println!("{}", summary_text);

    println!("\nDemo END\n");

    Ok(())
}

Benchmarks

For benchmarks, we implement an experimental tool bench-parmesan, which also compares Parmesan and tfhe-rs. Results can be found in the whitepaper.

Processor Load

In particular, we measure the processor load; in the graph below, find our results for 32-bit maximum that were measured on a machine with AMD EPYC 7543.

proc load max

An extra graph that shows the processor load during 32-bit multiplication can be found here.

Version Log

  • v0.1.5: upgraded backend to tfhe v0.5
  • v0.1.0-alpha: rewritten using tfhe v0.2 instead of concrete_core.
  • v0.0.20-alpha-4: algorithms for whitepaper.

License

Parmesan is licensed under AGPLv3.

Acknowledgments

This work was supported by the MESRI-BMBF French-German joint project UPCARE (ANR-20-CYAL-0003-01), granted to EURECOM.

EURECOM logo

Computational resources were supplied by the project e-Infrastruktura CZ (e-INFRA CZ LM2018140) supported by the Ministry of Education, Youth and Sports of the Czech Republic.

e-infra logo

parmesan's People

Stargazers

Liang Honglian avatar  avatar  avatar zzt10170 avatar  avatar Alex Quint avatar Alberto Ibarrondo avatar

Watchers

 avatar

Forkers

ibarrond

parmesan's Issues

File not found error on generating keys

Version

parmesan = { version = "^0.1", features = ["measure"] }

Problem

When generating the keys using

ParmesanUserovo::new(par)

It returns a File not found error.

This is due to that the folder keys, does not exist.

Expected Behaviour

The code should generate new keys and return successfully.

Solution

Either create a keys folder in your repository,
Or create the folder at runtime when this folder does not yet exist.
Line: 16 at parmesan/src/userovo/keys.rs

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.