Skip to content
Snippets Groups Projects
Commit c12f38e5 authored by Dmytro Bogatov's avatar Dmytro Bogatov :two_hearts:
Browse files

Restructure and dump cmake.

parent 5237da44
No related branches found
No related tags found
No related merge requests found
BasedOnStyle: Google
Standard: c++17
AllowShortCaseLabelsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
DerivePointerBinding: false
TabWidth: 2
ForEachMacros: ["foreach"]
SpaceBeforeParens: ControlStatementsExceptForEachMacros
SortIncludes: true
IncludeBlocks: Regroup
# Custom order of includes (listed by regex match priority)
IncludeCategories:
# Local libraries
- Regex: '".*'
Priority: 1
# Third party libraries
- Regex: '^[<"](relic_sym|relic_asym|relic).*'
Priority: 2
# C++ STL headers
- Regex: "^<[a-z0-9_]+>.*"
Priority: 3
# System headers
- Regex: '^<.*\.h>.*'
Priority: 4
IncludeIsMainRegex: "(_test)?$"
{
"image": "docker.io/dbogatov/docker-images:relic-latest-multi-arch",
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-vscode.cpptools-extension-pack",
"streetsidesoftware.code-spell-checker",
"cschlosser.doxdocgen",
"editorconfig.editorconfig",
"eamodio.gitlens",
"redhat.vscode-yaml"
]
}
}
}
# Github cmake ignores.
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
# CLion ignores.
*.out
*.o
*.dSYM
*.gcov
*.gcda
*.gcno
*.tmp
*.bin
junit-*.xml
cobertura.xml
coverage-html/
docs/
ipch
ppann/bin/*
!ppann/bin/.gitkeep
ppann/lib/*
!ppann/lib/.gitkeep
ppann/results/*
!ppann/results/.gitkeep
.idea
# CMake
cmake-build-*/
# File-based project format
*.iws
\ No newline at end of file
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Test",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/tests/test_asym_group",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
# Set cmake version.
cmake_minimum_required(VERSION 3.22)
# Project name and language.
project(
PPANN
VERSION 0.1
DESCRIPTION "This project implements the inner product revealing encryption."
LANGUAGES CXX
)
# Set standards and include tests.
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(CMAKE_CXX_STANDARD 17)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
include(CTest)
endif ()
# Find the relic library.
find_library(RELIC_LIB_SYM relic_sym)
find_library(RELIC_LIB_ASYM relic_asym)
# Add desired subdirectories.
add_subdirectory(src)
add_subdirectory(apps)
add_subdirectory(tests)
\ No newline at end of file
FROM ubuntu:23.10
# Set the relic version number in case we may want to update it.
ENV VERSION=0.6.0
# Update libraries.
RUN apt update && apt upgrade -y
# Install needed libraries.
RUN apt install -y wget unzip build-essential libgmp-dev libssl-dev cmake
# Clean up.
RUN apt clean
# Download library and unzip.
RUN wget -P /home https://github.com/relic-toolkit/relic/archive/refs/tags/$VERSION.tar.gz && \
tar -xzf /home/0.6.0.tar.gz -C /home
# Library installation; first install the symmetric curve.
RUN mkdir -p /home/relic-$VERSION/relic-target-sym
WORKDIR "/home/relic-$VERSION/relic-target-sym"
RUN cmake -DLABEL=sym ..
RUN ../preset/gmp-pbc-ss1536.sh ../
RUN make
RUN make install
# Library installation; now install the asymmetric curve.
RUN mkdir -p /home/relic-$VERSION/relic-target-asym
WORKDIR "/home/relic-$VERSION/relic-target-asym"
RUN cmake -DLABEL=asym ..
RUN ../preset/gmp-pbc-bn254.sh ../
RUN make
RUN make install
FROM dbogatov/docker-images:relic-latest-multi-arch
# Copy the files over to working directory.
RUN mkdir -p /home/project/build
......
......
Doxyfile 0 → 100644
This diff is collapsed.
# Privacy-Preserving Approximate Nearest Neighbor
To run the library, one needs to install relic and itialize it with the SS1536 curve. You must also have GMP installed to benefit from the optimizations.
# Call this executable app.
add_executable(app app.cpp)
target_link_libraries(app PRIVATE ppann_lib)
\ No newline at end of file
#include <iostream>
using namespace std;
int main() {
cout << "Testing in the app." << endl;
}
\ No newline at end of file
#pragma once
#include <gmp.h>
extern "C" {
#include "relic_asym/relic.h"
}
// Set specific asym data types.
typedef bn_t asymPoint;
struct asymZp {
asymPoint point{};
asymPoint modular{};
};
namespace asym {
asymZp rand_zp(asymPoint modular);
asymZp zp_zero(asymPoint modular);
asymZp zp_one(asymPoint modular);
asymZp zp_copy(asymZp x);
asymZp zp_from_int(int x, asymPoint modular);
asymZp zp_add(asymZp x, asymZp y);
asymZp zp_neg(asymZp x);
asymZp zp_mul(asymZp x, asymZp y);
asymZp zp_inv(asymZp x);
int zp_cmp(asymZp x, asymZp y);
int zp_cmp_int(asymZp x, int y);
}
#pragma once
#include "asym_field.hpp"
typedef g1_t asymG1;
typedef g2_t asymG2;
typedef gt_t asymGt;
namespace asym {
void g1_gen(asymG1 x);
void g2_gen(asymG2 x);
void g1_mul(asymG1 r, asymG1 x, asymZp y);
void g2_mul(asymG2 r, asymG2 x, asymZp y);
void gt_raise(asymGt r, asymGt x, asymZp y);
void bp_map(asymGt r, asymG1 x, asymG2 y);
}
#pragma once
#include <cstdio>
#include <cstring>
#include <sys/stat.h>
#include "hnsw.h"
#include "ipre.hpp"
float *fvecs_read(const char *file_path, size_t *d_out, size_t *n_out);
int *ivecs_read(const char *file_path, size_t *d_out, size_t *n_out);
int *float_to_int(const float *data, size_t size);
Item *encrypt_data(const int *data, Key key, size_t d, size_t n);
\ No newline at end of file
#pragma once
#include <set>
#include <random>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include "ipre.hpp"
using namespace std;
struct Item {
// The ciphertext as value.
Ct value;
// Compute distance between item with something else.
int dist(Item &other, Key key, int size, int bound) const;
};
struct HNSWGraph {
// Constructor.
HNSWGraph(int NN, int MN, int MNZ, int SN, int ML, Key key, int size, int bound);
/* HNSW related settings. */
// Number of neighbors.
int NN;
// Max number of neighbors in layers >= 1.
int MN;
// Max number of neighbors in layers 0.
int MNZ;
// search numbers in construction (efConstruction).
int SN;
// Max number of layers.
int ML;
// number of items
int numItem;
// enter node id
int enterNode{};
// actual vector of the items
vector<Item> items;
// adjacent edge lists in each layer
vector<unordered_map<int, vector<int>>> layerEdgeLists;
// The default generator.
default_random_engine generator;
/* For the IPRE scheme. */
Key key;
int size;
int bound;
/* Methods. */
void insert(Item &q);
void addEdge(int st, int ed, int lc);
vector<int> search(Item &q, int K);
vector<int> searchLayer(Item &q, int ep, int ef, int lc);
};
#pragma once
#include "sym_vector.hpp"
#include "sym_matrix.hpp"
const int B_SIZE = 6;
struct Key {
symZpMat A;
symZpMat B;
symZpMat Bi;
symG base;
symGt t_base;
bn_t modular;
};
struct Ct {
symGVec ctx;
symGVec ctk;
symGVec ctc;
};
Key setup(int size);
Ct enc(Key key, const int *message, int size);
int eval(Key key, Ct x, Ct y, int size, int bound);
\ No newline at end of file
#pragma once
#include <gmp.h>
extern "C" {
#include "relic_sym/relic.h"
}
// Set specific sym data types.
typedef bn_t symPoint;
struct symZp {
symPoint point{};
symPoint modular{};
};
namespace sym {
symZp zp_rand(symPoint modular);
symZp zp_zero(symPoint modular);
symZp zp_one(symPoint modular);
symZp zp_copy(symZp x);
symZp zp_from_int(int x, symPoint modular);
symZp zp_add(symZp x, symZp y);
symZp zp_neg(symZp x);
symZp zp_mul(symZp x, symZp y);
symZp zp_inv(symZp x);
int zp_cmp(symZp x, symZp y);
int zp_cmp_int(symZp x, int y);
}
#pragma once
#include "sym_field.hpp"
typedef g1_t symG;
typedef gt_t symGt;
namespace sym {
void g_gen(symG x);
void g_mul(symG r, symG x, symZp y);
void gt_raise(symGt r, symGt x, symZp y);
void bp_map(symGt r, symG a, symG b);
}
#pragma once
#include "sym_field.hpp"
typedef symZp *symZpMat;
namespace sym {
symZpMat matrix_zp_from_int(const int *int_mat, int row, int col, symPoint modular);
symZpMat matrix_zp_rand(int row, int col, symPoint modular);
symZpMat matrix_identity(int size, symPoint modular);
int matrix_is_identity(symZpMat x, int size);
symZpMat matrix_transpose(symZpMat x, int row, int col);
symZpMat matrix_merge(symZpMat x, symZpMat y, int row, int col_x, int col_y);
symZpMat matrix_multiply(symZpMat x, symZpMat y, int row_x, int row_y, int col_y, symPoint modular);
symZpMat matrix_inverse(symZpMat x, int size, symPoint modular);
}
#pragma once
#include "sym_field.hpp"
#include "sym_group.hpp"
typedef symZp *symZpVec;
typedef symG *symGVec;
namespace sym {
symZpVec vector_zp_from_int(const int *int_vec, int size, symPoint modular);
symZpVec vector_zp_rand(int size, symPoint modular);
symZpVec vector_merge(symZpVec a, symZpVec b, int size_a, int size_b);
symZpVec vector_add(symZpVec a, symZpVec b, int size);
symGVec vector_raise(symG base, symZpVec x, int size);
void inner_product(symGt r, symGVec a, symGVec b, int size);
}
# definitions
SDIR=src
TDIR=test
HDIR=benchmark
IDIR=include
ODIR=obj
LDIR=lib
BDIR=bin
LDFLAGS=-L $(LDIR)
LDLIBS=-l relic_sym -l relic_asym # libs for main code
LDTESTLIBS=-l gtest -l benchmark # libs for tests and benchmarks
INCLUDES=-I $(IDIR) -I $(LDIR)/include
CPPFLAGS= --std=c++20 -Wall -Wno-unknown-pragmas -fPIC -O3
CC=g++
RM=rm -rf
LIBNAME=ppann
# if you follow the convention that for each class CLASS you have a header in
# $(IDIR)/CLASS.hpp, a code in $(SDIR)/CLASS.cpp and a test in $(TDIR)/test-CLASS.cpp,
# then the rest will magically work - it will compile each class and test and will run the tests.
# CLASS does not even have to be a class in C++.
ENTITIES = asym-field asym-group helper hnsw ipre sym-field sym-group sym-matrix sym-vector
# dependencies - definitions plus header files
_DEPS = $(addsuffix .hpp, $(ENTITIES))
DEPS = $(patsubst %, $(IDIR)/%, $(_DEPS))
_OBJ = $(addsuffix .o, $(ENTITIES))
OBJ = $(patsubst %, $(ODIR)/%, $(_OBJ))
# TODO: here will go executables (what used to be "app")
TARGETS =
TARGETBIN = $(addprefix $(BDIR)/, $(TARGETS))
# Kudos for having a test for every entity!
TESTS = $(ENTITIES)
TESTBIN = $(addprefix $(BDIR)/test-, $(TESTS))
JUNITS= $(foreach test, $(TESTS), bin/test-$(test)?--gtest_output=xml:junit-$(test).xml)
BENCHMARKS =
BENCHMARKSBIN = $(addprefix $(BDIR)/benchmark-, $(BENCHMARKS))
INTEGRATION =
INTEGRATIONBIN = $(addprefix $(BDIR)/test-, $(INTEGRATION))
ENTRYPOINTCC = $(CC) -o $@ $^ $(CPPFLAGS) $(INCLUDES) $(LDFLAGS) $(LDLIBS)
# flags-setting commands
all: shared docs
binaries: LDLIBS += $(LDTESTLIBS)
binaries: $(TARGETBIN) $(TESTBIN) $(INTEGRATIONBIN) $(BENCHMARKSBIN)
cleandebug: clean debug
debug: CPPFLAGS += -g -DTESTING
debug: CPPFLAGS := $(filter-out -O3,$(CPPFLAGS))
debug: binaries
profile: CPPFLAGS += -fprofile-arcs -ftest-coverage -fPIC -O0
profile: clean run-tests-junit
# executables
.SECONDEXPANSION:
$(TARGETBIN): $(OBJ) $$(subst $$(BDIR), $(SDIR), $$@).cpp
$(ENTRYPOINTCC)
.SECONDEXPANSION:
$(TESTBIN): $(OBJ) $$(subst $$(BDIR), $(TDIR), $$@).cpp
$(ENTRYPOINTCC)
.SECONDEXPANSION:
$(BENCHMARKSBIN): $(OBJ) $$(subst $$(BDIR), $(HDIR), $$@).cpp
$(ENTRYPOINTCC)
.SECONDEXPANSION:
$(INTEGRATIONBIN): $(OBJ) $$(subst $$(BDIR), $(TDIR), $$@).cpp
$(ENTRYPOINTCC)
shared: CPPFLAGS += -DSHARED
shared: $(OBJ)
$(CC) -shared $(LDLIBS) $(LDFLAGS) -o $(BDIR)/lib$(LIBNAME).so $(OBJ)
# programs
# # TODO:
# main: bin/main
version:
$(CC) -v
# objects
$(ODIR)/%.o: $(SDIR)/%.cpp $(DEPS)
$(CC) -c -o $@ $< $(CPPFLAGS) $(INCLUDES)
# commands
run-tests-junit: CPPFLAGS += -DTESTING
run-tests-junit: $(TESTBIN)
$(subst ?, ,$(addsuffix &&, $(JUNITS))) echo Tests passed!
run-tests: CPPFLAGS += -DTESTING
run-tests: LDLIBS += $(LDTESTLIBS)
run-tests: $(TESTBIN)
$(addsuffix &&, $(TESTBIN)) echo Tests passed!
run-benchmarks: $(BENCHMARKSBIN)
$(addsuffix &&, $(BENCHMARKSBIN)) echo Benchmarks completed!
run-integration: CPPFLAGS += -DTESTING
run-integration: $(INTEGRATIONBIN)
$(addsuffix &&, $(INTEGRATIONBIN)) echo Tests passed!
coverage: profile
gcovr -r . $(addprefix -f $(SDIR)/, $(addsuffix .cpp, $(ENTITIES))) --exclude-unreachable-branches
mkdir -p coverage-html/
gcovr -r . --html --html-details -o coverage-html/index.html
gcovr -r . -x -o cobertura.xml
docs: clean-docs
doxygen ../doxyfile
clean: clean-docs clean-binaries
$(RM) $(ODIR)/* *~ *.dSYM *.gcov *.gcda *.gcno *.bin coverage-html junit-*.xml cobertura.xml
clean-docs:
$(RM) ../docs
clean-binaries:
$(RM) $(BDIR)/*
# phony
.PHONY: docs clean clean-docs clean-binaries coverage
.PHONY: profile debug cleandebug
.PHONY: binaries all shared
.PHONY: run-tests run-integration run-benchmarks run-shared-lib run-tests-junit
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment