Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Pull Request

on:
pull_request:
branches:
- '**'

jobs:
job:
name: ${{ github.workflow }}:${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 1
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest]
include:
- os: ubuntu-latest
vcpkgCommitId: '834977918592e4f5d5ec5fe48ba338c608faf9f9'
cmakeGen: '"Unix Makefiles"'
cc: gcc
cxx: g++
tools: echo "skip openmp installation"
platform: linux

- os: macos-latest
vcpkgCommitId: '834977918592e4f5d5ec5fe48ba338c608faf9f9'
cmakeGen: '"Unix Makefiles"'
cc: clang
cxx: clang++
lgflags: -L/opt/homebrew/opt/libomp/lib
cxxflags: -I/opt/homebrew/opt/libomp/include
tools: NONINTERACTIVE=1 brew install libomp
platform: darwin

steps:
- uses: actions/checkout@v3
with:
submodules: true

- uses: lukka/get-cmake@latest
- name: Dump the content of $RUNNER_TEMP
run: find $RUNNER_TEMP
shell: bash
- name: Dump the content of $RUNNER_WORKSPACE
run: find $RUNNER_WORKSPACE
shell: bash

- name: Setup vcpkg
uses: lukka/run-vcpkg@v11
id: runvcpkg
with:
# This specifies the location of vcpkg, where it is going to be restored from cache, or create from scratch.
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
# The Git commit id of vcpkg to be checked out. This is only needed because we are not using a submodule.
vcpkgGitCommitId: '${{ matrix.vcpkgCommitId }}'
# The vcpkg.json file, which will be part of cache key computation.
vcpkgJsonGlob: '**/vcpkg.json'

- name: install tools
run: ${{ matrix.tools }}

- name: Prints output of run-vcpkg's action
run: echo "root='${{ steps.runvcpkg.outputs.RUNVCPKG_VCPKG_ROOT_OUT }}', triplet='${{ steps.runvcpkg.outputs.RUNVCPKG_VCPKG_DEFAULT_TRIPLET_OUT }}'"

- name: Build Info
run: ${{ matrix.cxx }} --version && cmake --version

- name: Release Build - Run CMake with vcpkg.json manifest
env:
VCPKG_ROOT: ${{ steps.runvcpkg.outputs.RUNVCPKG_VCPKG_ROOT_OUT }}
BUILD_TYPE: Release
BIN_DIR: rel
LDFLAGS: ${{matrix.ldflags}}
CPPFLAGS: ${{matrix.cxxflags}}
OpenMP_ROOT: /opt/homebrew/opt/libomp
run: cmake -DCMAKE_CXX_COMPILER=${{matrix.cxx}} -G ${{matrix.cmakeGen}} --preset=base
shell: bash

- name: Release Build - Run build
run: cmake --build .build/rel
shell: bash

- name: Debug Build - Run CMake with vcpkg.json manifest
env:
VCPKG_ROOT: ${{ steps.runvcpkg.outputs.RUNVCPKG_VCPKG_ROOT_OUT }}
BUILD_TYPE: Debug
BIN_DIR: deb
LDFLAGS: ${{matrix.ldflags}}
CPPFLAGS: ${{matrix.cxxflags}}
OpenMP_ROOT: /opt/homebrew/opt/libomp
run: cmake -DCMAKE_CXX_COMPILER=${{matrix.cxx}} -G ${{matrix.cmakeGen}} --preset=base
shell: bash

- name: Debug Build - Run build
run: cmake --build .build/deb
shell: bash
93 changes: 93 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Release

on:
workflow_dispatch:
push:
tags:
- '*'

jobs:
job:
name: ${{ github.workflow }}:${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 1
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest]
include:
- os: ubuntu-latest
vcpkgCommitId: '834977918592e4f5d5ec5fe48ba338c608faf9f9'
cmakeGen: '"Unix Makefiles"'
cc: gcc
cxx: g++
tools: echo "skip openmp installation"
platform: linux

- os: macos-latest
vcpkgCommitId: '834977918592e4f5d5ec5fe48ba338c608faf9f9'
cmakeGen: '"Unix Makefiles"'
cc: clang
cxx: clang++
lgflags: -L/opt/homebrew/opt/libomp/lib
cxxflags: -I/opt/homebrew/opt/libomp/include
tools: NONINTERACTIVE=1 brew install libomp
platform: darwin

steps:
- uses: actions/checkout@v3
with:
submodules: true

- uses: lukka/get-cmake@latest
- name: Dump the content of $RUNNER_TEMP
run: find $RUNNER_TEMP
shell: bash
- name: Dump the content of $RUNNER_WORKSPACE
run: find $RUNNER_WORKSPACE
shell: bash

- name: Setup vcpkg
uses: lukka/run-vcpkg@v11
id: runvcpkg
with:
# This specifies the location of vcpkg, where it is going to be restored from cache, or create from scratch.
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
# The Git commit id of vcpkg to be checked out. This is only needed because we are not using a submodule.
vcpkgGitCommitId: '${{ matrix.vcpkgCommitId }}'
# The vcpkg.json file, which will be part of cache key computation.
vcpkgJsonGlob: '**/vcpkg.json'

- name: install tools
run: ${{ matrix.tools }}

- name: Prints output of run-vcpkg's action
run: echo "root='${{ steps.runvcpkg.outputs.RUNVCPKG_VCPKG_ROOT_OUT }}', triplet='${{ steps.runvcpkg.outputs.RUNVCPKG_VCPKG_DEFAULT_TRIPLET_OUT }}'"

- name: Build Info
run: ${{ matrix.cxx }} --version && cmake --version

- name: Run CMake with vcpkg.json manifest
env:
VCPKG_ROOT: ${{ steps.runvcpkg.outputs.RUNVCPKG_VCPKG_ROOT_OUT }}
BUILD_TYPE: Release
BIN_DIR: rel
LDFLAGS: ${{matrix.ldflags}}
CPPFLAGS: ${{matrix.cxxflags}}
OpenMP_ROOT: /opt/homebrew/opt/libomp
run: cmake -DCMAKE_CXX_COMPILER=${{matrix.cxx}} -G ${{matrix.cmakeGen}} --preset=base
shell: bash

- name: Run build
run: cmake --build .build/rel
shell: bash

- name: Run install
run: cmake --install .build/rel
shell: bash

- name: 'Upload Artifact'
uses: actions/upload-artifact@v4
with:
name: fairmath-keygen-${{matrix.platform}}
path: .build/install
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
BUILD
.build
CMakeUserPresets.json
47 changes: 32 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
cmake_minimum_required(VERSION 3.22)

project(fairmathCli CXX)
project(fairmath-keygen CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "\${ORIGIN}/lib")

find_package(OpenMP)
find_package(Boost REQUIRED COMPONENTS program_options)
find_package(OpenFHE CONFIG REQUIRED)
find_path(NLOHMANN_JSON_INCLUDE_DIRS "nlohmann/adl_serializer.hpp")

if (OpenFHE_FOUND)
message(STATUS "FOUND PACKAGE OpenFHE")
Expand All @@ -16,23 +23,33 @@ else()
message(FATAL_ERROR "PACKAGE OpenFHE NOT FOUND")
endif()

set(CMAKE_CXX_FLAGS ${OpenFHE_CXX_FLAGS})
include_directories(
${OpenFHE_INCLUDE}
${OpenFHE_INCLUDE}/core
${OpenFHE_INCLUDE}/pke
${OpenFHE_INCLUDE}/binfhe
${NLOHMANN_JSON_INCLUDE_DIRS}
)

include_directories(${OPENMP_INCLUDES})
include_directories(${OpenFHE_INCLUDE})
include_directories(${OpenFHE_INCLUDE}/third-party/include)
include_directories(${OpenFHE_INCLUDE}/core)
include_directories(${OpenFHE_INCLUDE}/pke)
include_directories(${OpenFHE_INCLUDE}/binfhe)
set(SOURCES
src/fairmathCli.cpp
)

link_directories(${OpenFHE_LIBDIR})
link_directories(${OPENMP_LIBRARIES})
add_executable(fairmath-keygen ${SOURCES})

set(CMAKE_EXE_LINKER_FLAGS ${OpenFHE_EXE_LINKER_FLAGS})
link_libraries(${OpenFHE_SHARED_LIBRARIES})
if (OpenMP_CXX_FOUND)
message(STATUS "FOUND OpenMP: ${OpenMP_CXX_LIBRARIES}")
message(STATUS "FOUND OpenMP Dir: ${OpenMP_libomp_LIBRARY}")

find_package(Boost REQUIRED COMPONENTS program_options)
add_executable(fairmathCli fairmathCli.cpp)
#workaround for macos github actions
set(lib_openmp_path "${OpenMP_libomp_LIBRARY}")
cmake_path(GET lib_openmp_path PARENT_PATH OMP_LINK_DIR)

target_link_directories(fairmath-keygen PRIVATE ${OMP_LINK_DIR})
endif()

target_link_libraries(fairmathCli -ltcmalloc_minimal -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free ${Boost_PROGRAM_OPTIONS_LIBRARY})
target_include_directories(fairmath-keygen PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
target_link_libraries(fairmath-keygen PRIVATE ${OpenFHE_SHARED_LIBRARIES} Boost::program_options)

install(TARGETS fairmath-keygen DESTINATION install)
install(DIRECTORY ${OpenFHE_LIBDIR} DESTINATION install)
16 changes: 16 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": 2,
"configurePresets": [
{
"name": "base",
"displayName": "Unix Makefiles",
"generator": "Unix Makefiles",
"binaryDir": "${sourceDir}/.build/$env{BIN_DIR}",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"CMAKE_BUILD_TYPE": "$env{BUILD_TYPE}",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/.build"
}
}
]
}
7 changes: 0 additions & 7 deletions build.sh

This file was deleted.

Binary file removed data/output/ciphertext_1
Binary file not shown.
Binary file removed data/output/ciphertext_2
Binary file not shown.
1 change: 0 additions & 1 deletion data/output/config.json

This file was deleted.

Binary file removed data/output/cryptocontext_name
Binary file not shown.
Binary file removed data/output/mult_key_name
Binary file not shown.
Binary file removed data/output/private_key_name
Binary file not shown.
Binary file removed data/output/public_key_name
Binary file not shown.
Binary file removed data/output/rotation_key_name
Binary file not shown.
Binary file removed data/output/sum_key_name
Binary file not shown.
File renamed without changes.
66 changes: 66 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Fairmath KeyGen Application

## Description
This application is supposed to use within the FHE app runner provided by fairmath computer actor. It is responsible for FHE key generation and encryption/decryption of user's data. This application relying on OpenFHE library to generate keys and making encryption.

## How To Build
* Install CMake 3.22(or above), gcc or clang
* Install OpenMP(this is not necessary but highly recommended)
* Clone vcpkg repo and install binary

```shell
$ git clone https://github.com/microsoft/vcpkg.git
$ cd vcpkg && ./bootstrap-vcpkg.sh
```

* Add the following env vars
```shell
$ export VCPKG_ROOT=/path/to/cloned/vcpkg/repo
$ export PATH=$VCPKG_ROOT:$PATH
```

You may also to add these variables to your `.bashrc` file for convenience.
* Clone `fairmath-cli` repository
```shell
$ git clone https://github.com/fairmath/fairmath-cli
```
* Configure cmake and build the project. You should specify vcpkg path, build type and directory for cmake generated file.
```shell
$ VCPKG_ROOT=/path/to/cloned/vcpkg/repo BUILD_TYPE=Release BIN_DIR=rel cmake --preset=base && cmake --build .build/rel
```
All files will be located in `.build` directory. You can omit VCPKG_ROOT variable if the one was defined previously(e.g. in the `.bashrc` file)
Also it is possible to create user defined presets for CMake.
Just create the following file in the root of the repository
CMakeUserPresets.json:
```json
{
"version": 2,
"configurePresets": [
{
"name": "dbg",
"inherits": "base",
"environment": {
"VCPKG_ROOT": "/path/to/cloned/vcpkg/repo",
"BUILD_TYPE": "Debug",
"BIN_DIR": "dbg"
}
},
{
"name": "rel",
"inherits": "base",
"environment": {
"VCPKG_ROOT": "/path/to/cloned/vcpkg/repo",
"BUILD_TYPE": "Release",
"BIN_DIR": "rel"
}
}
]
}
```
Since that you are able to run the following command to build release configuration
```shell
$ cmake --preset=rel && cmake --build .build/rel
```
Change rel to dbg to build a debug configuration.

The very first build could take a time because of vcpkg will build 3rd party libraries for this project. NExt builds will be mush faster since 3rd party libraries will be already built and cached.
7 changes: 0 additions & 7 deletions run.sh

This file was deleted.

Loading
Loading