Git Product home page Git Product logo

tfhe's Introduction

TFHE

Continuous Integration

TFHE is a Rust port of the C++ library TFHE. Check out the overview paper for a more in-depth explanation of the scheme.

Usage

Add this to your Cargo.toml:

[dependencies]
tfhe = { git = "https://github.com/IsakSundeSingh/tfhe" }

Documentation

To generate and open the user-documentation for the crate in your browser, clone the repository and run the following:

cargo doc --all-features --open

If you wish to contribute to the code and want internal documentation for implementation details, run the following:

cargo doc --all-features --document-private-items --open

Crate Features

TFHE is built with these features enabled by default:

  • fft enables FFT for polynomial multiplication, improving speeds. No reason to disable this unless you wish to remove a transitive dependency and allow drastically lower performance.

Optionally, the following features can be enabled:

  • bootstrapping enables gate-bootstrapping, so that the bootstrapping procedure is performed after each gate. A user may wish to have this disabled to use circuit bootstrapping manually.

Testing

Tests can be run using cargo test.

Benchmarking

Benchmarks can be run using cargo bench.

Some benchmarks require specific features to be enabled. Required features are found in Cargo.toml under each specific benchmark's section, [[bench]].

Disclaimer

It is a very rough port and not all of the code is idiomatic Rust. Few of the optimizations of the original library are implemented, such as FFT on Lagrange complex polynomials, however may be added in the future.

This is developed as a research project, so I would not recommend to use this for anything more than experimental use.

I am not a cryptologist.

Contributions

Contributions both in terms of issues and pull requests are welcome. Please use the issue templates when filling out an issue. Do note that the project is experimental and has the scars from this as well.

License

This project is a Rust port of the C++ library TFHE, and is licensed under the Apache 2.0 License.

tfhe's People

Contributors

isaksundesingh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

tfhe's Issues

Increase developer-friendliness

Feature request โšก

Is your feature request related to a problem? ๐Ÿ˜ง

Creating circuits using functions for boolean gates is difficult and manual labour. There could easily be APIs for parsing some DSL and creating circuits for you. At least some prebuilt circuits such as an 8-bit adder. Additionally, common types represented as ciphertexts could be created, such as Uint8.

Describe the solution you'd like ๐Ÿ˜„

Some sort of easier way of creating programs using the library. Some functionality to parse a binary circuit language would be helpful. A compiler for converting Rust or LLVM to circuits would be even better.

Describe alternatives ๐Ÿคทโ€โ™‚๏ธ

Possible solutions could be:

  • A parser for converting binary circuit formats to the encrypted form. E.g. some subset of Verilog or similar.
  • A compiler for converting Rust to circuits
  • A DSL for writing circuits.
  • Some predefined built-in primitive types. E.g. Uint8, Int8, etc. with associated common methods / structures, e.g. 8-bit adder, encrypted comparison circuit, etc.

Clean up public API

Feature request โšก

Is your feature request related to a problem? ๐Ÿ˜ง

As of now, the public API is a bit of a mess. Many things that should not be public are public, and all modules are public. Functions, methods, types, traits, etc. should be at the lowest visibility level unless required to be public.

Additionally, there is no good structure to the API. Encryption, decryption and key generation is in the bootstrapping-module instead of some encryption module or preferably as part of the prelude or exposed at the root-level.

Describe the solution you'd like ๐Ÿ˜„

An expected public API structure could look something like:

  • tfhe - Exposes encrypt, decrypt, generate_keys
    • encryption - Contains definitions for and exposes encrypt, decrypt and generate_keys
    • bootstrapping - Exposes the bootstrap-method (currently named tfhe_bootstrap which is unnecessary`
    • gates - Exposing all homomorphic gates, which should be named xor instead of boots_xor unless there are any name conflicts. Alternatively, gates could contain all gates without bootstrapping applied, and another module called bootstrapped_gates or perhaps in bootstrapping could contain gates which are bootstrapped. To give the user flexibility to choose between bootstrapped gates and bootstrapped circuits.

That's it. It does not need to be any more than that.

Describe alternatives ๐Ÿคทโ€โ™‚๏ธ

There are probably alternatives to this structure. Some say that https://github.com/dalek-cryptography/curve25519-dalek has a nice API, but I am unsure how this relates to this kind of a library which has more functionality.

The bootstrapping functionality could be done more elegant than feature flags. Currently, the bootstrapping function is exposed even when the bootstrapping-feature is disabled, which is confusing. It would at least make sense to only expose it when the feature is enabled, but a better approach would be something like the structure described in the previous section.

Allow different bit-security

Feature request โšก

Allow other security levels.

Is your feature request related to a problem? ๐Ÿ˜ง

Currently, a single parameter-set is returned when creating encryption parameters. There should be different security levels available.

Describe the solution you'd like ๐Ÿ˜„

A way to create a different parameter set, if only discrete sets are allowed, the following would be satisfactory:

use tfhe::{Parameters, SecurityLevel, generate_keys};
let default_parameters = Parameters::default(); // Standard security level (highest possible)
let bit128_parameters = Parameters::with(SecurityLevel::Bit128); // 128-bit security
let bit80_parameters = Parameters::with(SecurityLevel::Bit80); // A lower, 80-bit security level
let keys = generate_keys(bit80_parameters);
...

Improve tests

Feature request โšก

Is your feature request related to a problem? ๐Ÿ˜ง

The tests need cleanup, some tests can be merged, and performance can be improved by caching generated keys (as long as the key generation is tested properly).

Describe the solution you'd like ๐Ÿ˜„

These two tests can be merged as key generation happens twice, without any need for it. They also test the same functionality:

#[test]
fn test_encrypt_decrypt_true_is_true() {
let message = true;
let security = 128;
let params = bootstrapping_parameters(security);
let (secret_key, _cloud_key) = generate_keys(&params);
let encrypted = encrypt(message, &secret_key);
let decrypted = decrypt(&encrypted, &secret_key);
assert_eq!(message, decrypted);
}
#[test]
fn test_encrypt_decrypt_false_is_false() {
let message = false;
let security = 128;
let params = bootstrapping_parameters(security);
let (secret_key, _cloud_key) = generate_keys(&params);
let encrypted = encrypt(message, &secret_key);
let decrypted = decrypt(&encrypted, &secret_key);
assert_eq!(message, decrypted);
}

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.