Coder Social home page Coder Social logo

jeffmur / fhel Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 65.75 MB

Fully Homomorphic Encryption Library

Home Page: https://pub.dev/packages/fhel

License: MIT License

Dart 25.93% Dockerfile 0.23% CMake 1.27% Makefile 1.40% C++ 71.13% Kotlin 0.04%
microsoft-seal

fhel's Introduction

Fully Homomorphic Encryption Library

The Fully Homomorphic Encryption Library (fhel) is a powerful encryption library that enables fully homomorphic encryption (FHE) capabilities. It provides a seamless integration with Flutter, allowing developers to perform secure computations on encrypted data on resource constrained devices.

This library aims to expose basic functionalities to Flutter users to generate encryption context, derive keys, encrypt and decrypt data, and perform arithmetic operations on encrypted data. It provides a high-level abstraction for working with plaintext and ciphertext values, as well support for multiple encryption schemes.

With FHEL, developers can leverage the power of fully homomorphic encryption to perform computations on sensitive data while preserving privacy and security. It opens up new possibilities for secure data processing in applications built with Flutter.

For more information, see our wiki

Development ๐Ÿ—๏ธ

Compilation can become difficult when using multiple languages on multiple operating systems.

Makefiles are ๐Ÿ”‘

In general commands denoted with ci should encompass all required action(s), while others should perform a single action.

Compilation ๐Ÿ‘ท

For compiliation, see backend Makefile for library configuration.

From the root of the project:

make build-cmake

Unit Testing ๐Ÿงช

For C++, we have integrated GoogleTest as our testing framework.

From the root of the project:

make ctest

For Dart, the SDK comes out-of-the-box with a comprehensive testing framework.

From the root of the projct:

make dtest

Deployment ๐Ÿš€

Currently configured to be manually deployed via:

dart pub publish

In the future, we may configure an automated publishing.

fhel's People

Contributors

jeffmur avatar renovate[bot] avatar

Watchers

 avatar  avatar

fhel's Issues

Error Handling

Dart cannot natively handle errors, rather 'fails unexpectedly' when C throws any error.

Importance: Flutter must capture errors to alert the user to make changes, so C errors must be converted into Dart

Approach 1: ErrorTranslator ๐Ÿ†
C++ object that is always passed by reference for every function.
It should capture + handle various (if not all) error types.
From Dart, we would try to access data stored in C Memory to retrieve the current "status" of our function call / stack.

Pros:

  • Follows same pattern as Afhe, passed by reference with attributes

Cons:

  • Modifies every existing function

Approach 2: Specialized return types
For objects, create sub-routine .status() returns error message if any
For int or string return types, use -1

Cons:

  • Non-objects are ambiguous, less control for error messages
  • Prone to issues, hard coded values

Division

Division is not directly supported, however CKKS does provide a way to divide/multiply via scalars.

This may be a bit complex, will need to do more research

https://eprint.iacr.org/2016/510

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

dockerfile
Builder.Dockerfile
  • instrumentisto/flutter 3.19.3
  • mcr.microsoft.com/devcontainers/cpp 1-debian-11
github-actions
.github/actions/build-and-push-image/action.yml
  • actions/checkout v4
  • docker/setup-buildx-action v3
  • docker/login-action v3
  • docker/build-push-action v5
.github/workflows/builder.yml
  • actions/checkout v4
  • actions/checkout v4
.github/workflows/feature.yml
  • actions/checkout v4
  • dart-lang/setup-dart v1
  • actions/checkout v4
  • dorny/paths-filter v3
  • actions/checkout v4
  • actions/checkout v4
  • actions/checkout v4
  • actions/checkout v4
.github/workflows/publish.yml
  • actions/checkout v4
  • dart-lang/setup-dart v1
gradle
dart/android/settings.gradle
dart/android/build.gradle
  • com.android.tools.build:gradle 7.4.2
example/android/gradle.properties
example/android/build.gradle
  • com.android.tools.build:gradle 7.4.2
  • org.jetbrains.kotlin:kotlin-gradle-plugin 1.9.23
example/android/app/build.gradle
gradle-wrapper
example/android/gradle/wrapper/gradle-wrapper.properties
  • gradle 8.6
pub
dart/pubspec.yaml
  • ffi ^2.1.0
  • flutter
  • path ^1.8.3
  • flutter_lints ^3.0.0
  • test ^1.24.3
  • dart >=3.1.5 <4.0.0
  • flutter >=1.20.0
example/pubspec.yaml
  • flutter
  • cupertino_icons ^1.0.2
  • flutter_lints ^3.0.0
  • dart >=3.1.5 <4.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

Concurrency > 1 Errors

Continued #39 - TLDR: Solution is not scalable. Should only affect dart test --concurrency 16.

Simple Approach: The ErrorTranslator singleton C class stores an error_message that is set in C and read from Dart.

However, when running dart test, the default concurrency is 16. Meaning that at once, we can have up-to 16 instances of Dart Seal objects.

As a result, we may receive intermittent failures when concurrency > 1. This should not affect users as all C FFI calls are synchronous. If there are multiple instances, they would be invoked sequentially.

Potential Solutions:

  1. For each C function, pass Pointer as parameter.
    This race condition can be solved by creating / managing ErrorTranslator instances for ffi invocation. However this may be overkill.

  2. For each C function, pass string (char*) as parameter:
    Simple, and a bit more transparent. Would require some additional logic to capture errors + return string. May introduce ambiguous complexity

Linux Distribution

Planned: SUMMER 2024

Expected Behavior:

When importing fhel: 0.0.4 from another plugin / flutter app, I would expect all binaries to be packaged on publish.

How does ffi distribution work for linux platforms?

00:01 +0 -1: test/fhe_video_similarity_test.dart: test encrypt [E]                                                                                                                                                                          
  Invalid argument(s): Failed to load dynamic library '/home/jeffmur/build/libfhel.so': /home/jeffmur/build/libfhel.so: cannot open shared object file: No such file or directory
  dart:ffi                                   new DynamicLibrary.open
  package:fhel/ffi.dart 18:27                dylib.<fn>
  package:fhel/ffi.dart 24:2                 dylib
  package:fhel/ffi.dart                      dylib
  package:fhel/afhe/backend.dart 9:56        _c_string_to_backend_type
  package:fhel/afhe/backend.dart             _c_string_to_backend_type
  package:fhel/afhe/backend.dart 32:13       new Backend.set
  package:fhel/afhe.dart 47:23               new Afhe
  package:fhel/seal.dart 13:25               new Seal
  test/fhe_video_similarity_test.dart 24:18  main.<fn>

Current logic escapes 2 nested directories. For Release, this should be configurable somehow.

Issue Filed: flutter/flutter#122499

Approach 1: A little hacky

  • Enter .pub-cache directory, locate package, run make dist
  • Copy dist/ directory into working (new project) directory

Approach 2: Native assets (Experimental)
https://github.com/dart-lang/native/tree/main/pkgs/native_assets_cli

  • Not finalized, requires re-factor
  • Requires dev-channel dart release
  • Using example

Abstraction Layer Outline

STORY

Design an abstraction layer for Fully Homomorphic Encryption

Features:

  1. Support multiple back end libraries
  2. Supports multiple schemes and data types

C/C++ Abstraction Layer, example Afhel

  • Automated Unit Testing
  • Supported Data Types: Vector, Int, Float
  • Supported Back-end libraries: SEAL
  • Supported Schemes: BFV, BGV, CKKS

Dart Package

  • Automated Unit Testing
  • Compilation: C++ and Dart

CPP Unit Testing

Require unit test of FHEL, this should eventually be tested with github actions.

There are three layers in this system:

  1. Back-end Library (Microsoft SEAL, OpenFHE)
  2. Abstract Layer (AFHEL)
  3. Implementation Layer (Dart API)

Each layer should contain good test coverage. This repository is only responsible for maintaining layer 2 and 3, so we must test appropriately.

There are two popular CPP frameworks for testing.

For the purpose of this project

  • Basic Functionality
  • Parameter Validation
  • API Usage

Google Test: https://github.com/google/googletest

  • Supports mock testing
  • Requires additional compilation process (de-coupled from source)

Catch2: https://github.com/catchorg/Catch2

  • Simple unit testing
  • Supports benchmarking

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.