Skip to content

Commit

Permalink
[feat]: add ElGamal and other algorithms for cmake project
Browse files Browse the repository at this point in the history
  • Loading branch information
dterazhao committed Oct 24, 2023
1 parent e20d46e commit bcd44dc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ set(CMAKE_CXX_STANDARD 17)

file(GLOB_RECURSE SRCS ${PROJECT_NAME}/library/*.cpp ${PROJECT_NAME}/library/*.cc)
file(GLOB_RECURSE IPCL_SRCS ${PROJECT_NAME}/library/algorithms/paillier_ipcl/*.cc)
#file(GLOB_RECURSE DGK_SRCS ${PROJECT_NAME}/library/algorithms/dgk/*.cc)
#file(GLOB_RECURSE DJ_SRCS ${PROJECT_NAME}/library/algorithms/dj/*.cc)
file(GLOB_RECURSE NP_SRCS ${PROJECT_NAME}/library/numpy/*.cc)
file(GLOB_RECURSE TEST_SRCS ${PROJECT_NAME}/library/*_test.cc)
file(GLOB_RECURSE BENCH_SRCS ${PROJECT_NAME}/library/*_bench.cc)
Expand Down Expand Up @@ -34,10 +36,12 @@ if (APPLE)
list(APPEND EXTRA_LIB benchmark::benchmark gflags)
endif ()

set(ABSL_LIB absl_int128 absl_strings absl_symbolize absl_stacktrace absl_throw_delegate)
# link libraries for the target
add_library(${PROJECT_NAME} SHARED ${SRCS})
#target_sources(${PROJECT_NAME} PRIVATE)
target_link_libraries(${PROJECT_NAME} yacl absl_int128 absl_strings absl_symbolize absl_stacktrace tommath fmt)
target_link_libraries(${PROJECT_NAME} yacl ${ABSL_LIB} # protobuf::libprotobuf protobuf::libprotobuf-lite
tommath fmt ssl crypto blake3 sodium curve25519)
set(EXE_TARGETS)

# Building tests
Expand Down
1 change: 1 addition & 0 deletions heu/library/algorithms/elgamal/key_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void KeyGenerator::Generate(const yacl::crypto::CurveName &curve_name,
}

void KeyGenerator::Generate(size_t key_size, SecretKey *sk, PublicKey *pk) {
if (key_size != 256) key_size = 256;
YACL_ENFORCE(key_size == 256,
"Exponential EC Elgamal only supports 256 key_size now");
// todo: change sm2 to fourq
Expand Down
4 changes: 3 additions & 1 deletion third_party/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
CD=$(cd "$(dirname "$0")" || exit && pwd)
cd "$CD" || exit
echo "Current Directory: $CD"
[ -d src ] || mkdir src

rm -rf include/* lib/*
#rm -rf include/* lib/*
rm -rf lib/*
# build yacl
"$CD"/build_yacl.sh
31 changes: 16 additions & 15 deletions third_party/build_yacl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,31 @@ echo "Current Directory: $CD"
# build yacl
# [ -d yacl ] || https://github.com/dtera/yacl.git
pkg=yacl
rm -rf "$pkg" && tar xvf "$pkg".tar.gz && "$pkg"/third_party/build.sh
[ -f src/"$pkg".tar.gz ] || curl https://github.com/dtera/yacl/releases/download/v1.0.0/"$pkg".tar.gz -L -o src/"$pkg".tar.gz
rm -rf "$pkg" && tar xvf src/"$pkg".tar.gz && "$pkg"/third_party/build.sh
lib=".so"
# [[ "$OSTYPE" == "darwin"* ]] && lib=".dylib"
rm -f "$CD"/$pkg/third_party/lib/libssl"$lib" && \
cp "$CD"/$pkg/third_party/lib/libssl.1.1"$lib" "$CD"/$pkg/third_party/lib/libssl"$lib" && \
rm -f "$CD"/$pkg/third_party/lib/libssl.1.1"$lib"
[ -d "$CD"/lib ] || mkdir -p "$CD"/lib
[ -d "$CD"/include ] || mkdir -p "$CD"/include
if [ "$(uname)" == "Darwin" ]; then
cp -R "$CD"/$pkg/third_party/lib/* "$CD"/lib/
else
cp -dR "$CD"/$pkg/third_party/lib/* "$CD"/lib/
cp -dR "$CD"/$pkg/third_party/lib64/* "$CD"/lib/
fi
cp -R "$CD"/$pkg/third_party/include/* "$CD"/include/
#cp -R "$CD"/$pkg/include/* "$CD"/include/
cd "$CD"/$pkg || exit 0
cp -R "$CD"/$pkg/third_party/lib/* "$CD"/lib/ && cp -R "$CD"/$pkg/third_party/include/* "$CD"/include/

cd "$CD"/"$pkg" || exit 0
# shellcheck disable=SC2044
for path in $(find $pkg -name "*.h"); do
#head_file=${path##*/}
head_path=${path%/*}
head_save_path="$CD"/include/$head_path
mkdir -p "$head_save_path" && cp "$path" "$head_save_path"
done
rm -rf "$CD"/lib/cmake && rm -rf "$CD"/lib/pkgconfig
cd "$CD"/$pkg && mkdir build && cd build || exit

cd "$CD"/$pkg && rm -rf build && mkdir build && cd build || exit
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DCMAKE_CXX_STANDARD=17 -DCMAKE_INSTALL_PREFIX="$CD/" ..
make -j8 yacl
make -j8 "$pkg"

cp "$CD"/$pkg/build/libyacl.* "$CD"/lib/
rm -rf "$CD"/lib/cmake && rm -rf "$CD"/lib/pkgconfig
cp "$CD"/$pkg/build/lib"$pkg".* "$CD"/lib/
cd "$CD" || exit
rm -rf "$pkg"
#rm -rf "$pkg"
Binary file not shown.

0 comments on commit bcd44dc

Please sign in to comment.