Skip to content

Commit

Permalink
Documentation πŸ“š (#35)
Browse files Browse the repository at this point in the history
Closes #33
  • Loading branch information
jeffmur authored Feb 16, 2024
1 parent 1f63668 commit 3f4468d
Show file tree
Hide file tree
Showing 29 changed files with 538 additions and 634 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/feature.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,33 @@ jobs:
filters: |
source:
- Builder.Dockerfile
- name: Image Tag 🏷️
if: ${{ steps.changes.outputs.source == 'true' }}
id: tag
run: echo ::set-output name=TAG::${{ github.sha}}

- name: Build Image 🐳
uses: ./.github/actions/build-and-push-image
if: ${{ steps.tag.outcome == 'success' }}
with:
image_tag: ${{ steps.tag.outputs.IMAGE_TAG }}
token: ${{ secrets.GITHUB_TOKEN }}


docs:
name: Documentation πŸ“š
runs-on: ubuntu-latest
needs: build
container:
image: ghcr.io/jeffmur/fhel:${{ needs.build.outputs.IMAGE_TAG }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: 'true'

- run: make docs

cpp-tests:
name: C++ Test βš™οΈ
runs-on: ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ build-cmake:
.PHONY: build
build: trust-project build-cmake

# Generate html dart api docs
.PHONY: docs
docs:
@cd $(DART_SRC); $(MAKE) docs

# Test Abstract Layer (AFHEL)
.PHONY: ctest
ctest:
Expand Down
222 changes: 28 additions & 194 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,218 +1,52 @@
# FHEL

The FHEL (Fully Homomorphic Encryption Library) 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.
## Fully Homomorphic Encryption Library

At the core of this library is an abstract wrapper around existing FHE Libraries via AFHEL (Abstract FHE Library). The AFHEL exposes basic C functionalities to be consumed by Dart. The Dart adapter layer, FHE, acts as an consumer friendly API interface between Flutter and AFHEL. Using Object Oriented Programming, OOP, the FHE models itself as a library with basic functionalities of the desired backend 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.

```mermaid
---
title: Figure 1 - High Level Data Flow
---
sequenceDiagram
participant Flutter
participant FHE
participant AFHE
participant SEAL
Flutter->>FHE: Instanciate FHE("seal")
FHE->>AFHE: Pointer to Backend
AFHE->>SEAL: Instanciate SEAL
activate SEAL
SEAL->>FHE: Memory Address
Flutter->>FHE: Generate Context
FHE->>AFHE: Validate Parameters
AFHE->>SEAL: Reference SEAL
AFHE->>FHE: sucess: valid
AFHE->>FHE: [afhe_function] error: reason
Flutter->>FHE: FHE.free()
FHE->>SEAL: Free Allocated Memory
deactivate SEAL
```

## FHE: Implementation Layer

Fully Homomorphic Encryption (FHE)

The [adapter](https://refactoring.guru/design-patterns/adapter) design of this library interfaces with the abstraction layer. Using [dart:ffi](https://pub.dev/packages/ffi), Dart can execute C functions, reference memory addresses of C objects, and convert primitive data types.

```mermaid
---
title: Figure 2 - Implementation Class Diagram
---
classDiagram
class Plaintext {
String text
Backend backend
Pointer obj
Plaintext(Backend, String)
Plaintext(Backend, Pointer)
}
For more information, see our [wiki](https://github.com/jeffmur/fhel/wiki)

class Ciphertext {
Backend backend
Pointer library
## Development πŸ—οΈ

Ciphertext(Backend)
}
Compilation can become difficult when using multiple languages on multiple operating systems.

class Backend {
int value
String name
[Makefiles](https://www.gnu.org/software/make/manual/html_node/Introduction.html) are πŸ”‘

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

class Scheme {
int value
String name
### Compilation πŸ‘·

Scheme(String)
}
For compiliation, see backend [Makefile](./src/backend/Makefile) for library configuration.

Plaintext --> FHE
Ciphertext --> FHE
Backend --> FHE
Scheme --> FHE
class FHE {
Backend backend
Scheme scheme
Pointer library
From the root of the project:
```bash
make build-cmake
```

FHE(Backend)
FHE(Backend, Scheme)
### Unit Testing πŸ§ͺ

genContext(Map): void
genKeys()
encrypt(Plaintext): Ciphertext
decrypt(Ciphertext): Plaintext
invariantNoiseBudget(Ciphertext): int
encodeVecInt(List~int~): Plaintext
decodeVecInt(Plaintext, int): List~int~
add(Ciphertext, Ciphertext): Ciphertext
addPlain(Ciphertext, Plaintext): Ciphertext
subtract(Ciphertext, Ciphertext): Ciphertext
subtractPlain(Ciphertext, Plaintext): Ciphertext
}
For C++, we have integrated [GoogleTest](https://github.com/google/googletest) as our testing framework.

From the root of the project:
```bash
make ctest
```

**Legend**:

* `FHE`: Models the desired backend FHE library and encryption schemas. Enables callers execute basic FHE functionalities.

* `Plaintext`: Represents a plaintext value and contains a Pointer with the memory address of AFHE Plaintext.

* `Ciphertext`: Represents an encrypted ciphertext value and contains a Pointer with the memory address of AFHE Ciphertext.

* `Backend`: Contains integer and string value to convert to C Enum backend, for example `backend_t::seal`.

* `Scheme`: Contains integer and string value to convert to C Enum scheme, for example `scheme_t::bfv`.


## AFHE: Abstraction Layer

Abstract Fully Homomorphic Encryption Library (AFHE)

The [bridge](https://refactoring.guru/design-patterns/bridge) design of this library implements an abstraction layer over existing Fully Homomorphic Encryption (FHE) libraries. Through abstraction, we can interface with various backend libraries via the same function calls. The interface layer, FHE, exposes Afhe concrete classes, ex. Aseal, lower level C function to be consumed by the Implementation Layer. Through the use of pointers, we can create/destroy/reference Afhe objects from Dart.

```mermaid
---
title: Figure 3 - Abstraction Class Diagram
---
classDiagram
Afhe <|-- SEAL
class backend_t {
<<Enumeration>>
SEAL
OpenFHE
}
class scheme_t {
<<Enumeration>>
NONE
BFV
BGV
CKKS
}
class Plaintext{
to_string(): String
}
class Ciphertext{
size(): Int
}
scheme_t --> Afhe
Plaintext --> Afhe
Ciphertext --> Afhe
class Afhe {
<<Abstract>>
scheme_t scheme
ContextGen(scheme_t): string
KeyGen(): void
encrypt(Plaintext): void
decrypt(Ciphertext): void
invariant_noise_budget(Ciphertext): int
encode_int(vector~uint64_t~, Plaintext): void
decode_int(Plaintext, vector~uint64~): void
add(Ciphertext, Ciphertext, Ciphertext): void
subtract(Ciphertext, Ciphertext, Ciphertext): void
}
class SEAL~Afhe~{
setPublicKey(seal::PublicKey)
setSecretKey(seal::SecretKey)
}
class FHE {
<<interface>>
backend_t_from_string(String): backend_t
scheme_t_from_string(String): scheme_t
init_backend(backend_t): Afhe
init_plaintext(backend_t): Plaintext
init_ciphertext(backend_t): Ciphertext
generate_context(backend_t, Afhe, scheme_t): String
generate_keys(backend_t, Afhe): void
encrypt(backend_t, Afhe, Plaintext): Ciphertext
decrypt(backend_t, Afhe, Ciphertext): Plaintext
invariant_noise_budget(backend_t, Afhe, Ciphertext): int
encode_int(backend_t, Afhe, uint64_t, int): Plaintext
decode_int(backend_t, Afhe, Plaintext): unint64
add(backend_t, Afhe, Ciphertext, Ciphertext): Ciphertext
add_plain(backend_t, Afhe, Ciphertext, Plaintext): Ciphertext
subtract(backend_t, Afhe, Ciphertext, Ciphertext): Ciphertext
add_subtract(backend_t, Afhe, Ciphertext, Plaintext): Ciphertext
}
Afhe --> FHE
backend_t --> FHE
For Dart, the [SDK](https://dart.dev/tools/sdk) comes out-of-the-box with a comprehensive testing framework.

From the root of the projct:
```bash
make dtest
```

**Legend**:

* `Afhe`: An abstract class representing the main functionality of the library. It has an integer attribute scheme_t that determines the encryption scheme(s) are supported. It provides methods for generating keys, encrypting and decrypting data, and performing addition operations.

* `SEAL`: A concrete, refined abstraction, class that extends Afhe and represents a specific implementation of the library using the SEAL encryption scheme. It provides its own implementations of the encryption, decryption, and addition methods.
## Deployment πŸš€

* `FHE`: An interface that defines a method get_backend for obtaining an instance of Afhe based on a given backend library type, SEAL, that will execute the appropriate function call.

* `Plaintext` & `Ciphertext`: An abstract class representing the basic functionality of text objects. Used as the main interface for backend required parameters.

* `backend_t`: An enumeration class representing different Fully Homomorphic Encryption libraries.
Currently configured to be manually deployed via:
```bash
dart pub publish
```

* `scheme_t`: An enumeration class representing different encryption schemes, including BFV, BGV, and CKKS.
In the future, we may configure an [automated](https://dart.dev/tools/pub/automated-publishing) publishing.
6 changes: 6 additions & 0 deletions dart/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.0.3

Library Restructure
* Afhe: Adapter of fully homomorphic encryption. Exposes Classes
* Seal: Expose end user APIs. Extends Afhe

## 0.0.2

Android Release
Expand Down
4 changes: 4 additions & 0 deletions dart/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ deps:
.PHONY: test
test:
@dart test

.PHONY: docs
docs:
@dart doc
Loading

0 comments on commit 3f4468d

Please sign in to comment.