Merge commit '02107450d0c68a372f720974c92fe16acf3961f9' into bump_blsdash_1.3.3

This commit is contained in:
Odysseas Gabrielides 2024-10-09 17:25:19 +03:00
commit c05fdde88d
No known key found for this signature in database
GPG Key ID: 1CE8147DBC487904
17 changed files with 432 additions and 3458 deletions

View File

@ -77,6 +77,8 @@ jobs:
cmake --build . -- -j 6
- name: Build Go bindings
# TODO: macos build is broken. Whoever needs this - please fix it and remove `if` below.
if: startsWith(matrix.os, 'ubuntu')
run: |
cd go-bindings
make

View File

@ -22,7 +22,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ macos-11, ubuntu-20.04 ]
os: [ macos-latest, ubuntu-20.04 ]
builder: [ cmake, autotools ]
compiler:
- cc: gcc
@ -47,7 +47,7 @@ jobs:
run: |
ls -l
export MACOSX_DEPLOYMENT_TARGET=10.14
brew install autoconf automake gmp pkg-config
brew install autoconf automake gmp libtool pkg-config
- name: Build library using CMake
if: startsWith(matrix.builder, 'cmake')

View File

@ -9,9 +9,10 @@ print-%: FORCE
ACLOCAL_AMFLAGS = -I build-aux/m4
.PHONY: deploy FORCE
AM_LDFLAGS = $(LIBTOOL_LDFLAGS) $(HARDENED_LDFLAGS) $(CORE_LDFLAGS) $(GMP_LDFLAGS)
AM_CXXFLAGS = $(LIBTOOL_CXXFLAGS) $(HARDENED_CXXFLAGS) $(CORE_CXXFLAGS) $(PIC_FLAGS) $(PIE_FLAGS)
AM_CPPFLAGS = $(LIBTOOL_CPPFLAGS) $(HARDENED_CPPFLAGS) $(CORE_CPPFLAGS) $(PIC_FLAGS) $(GMP_CPPFLAGS)
AM_LDFLAGS = $(HARDENED_LDFLAGS) $(CORE_LDFLAGS) $(GMP_LDFLAGS)
AM_CFLAGS = $(DEBUG_FLAGS) $(HARDENED_FLAGS) $(CORE_FLAGS) $(WARN_FLAGS) $(NOWARN_FLAGS)
AM_CPPFLAGS = $(CORE_CPPFLAGS) $(GMP_CPPFLAGS)
AM_CXXFLAGS = $(DEBUG_FLAGS) $(HARDENED_FLAGS) $(CORE_FLAGS) $(WARN_FLAGS) $(NOWARN_FLAGS)
PTHREAD_FLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_LIBS)
EXTRA_LIBRARIES =

View File

@ -464,7 +464,7 @@ librelic_la_SOURCES = \
librelic_la_CPPFLAGS = $(AM_CPPFLAGS) $(RELIC_CPPFLAGS) $(RELIC_INCLUDES)
librelic_la_CXXFLAGS = $(AM_CXXFLAGS)
librelic_la_CFLAGS = $(AM_CFLAGS) $(WARN_CFLAGS) $(NOWARN_CFLAGS)
librelic_la_CFLAGS = $(AM_CFLAGS)
librelic_la_LDFLAGS = $(AM_LDFLAGS)
noinst_LTLIBRARIES += $(LIBRELIC)

View File

@ -1,5 +1,6 @@
#!/bin/sh
set -x
set -e
# "x86_64-apple-ios"
# "aarch64-apple-ios"
# "aarch64-apple-ios-sim"
@ -51,22 +52,20 @@ version_min_flag() {
prepare() {
download_gmp() {
GMP_VERSION="6.2.1"
GMP_VERSION="6.3.0"
CURRENT_DIR=$(pwd)
echo "$CURRENT_DIR"
# shellcheck disable=SC2039,SC2164
pushd ${BUILD}
mkdir -p "contrib"
if [ ! -s "contrib/gmp-${GMP_VERSION}.tar.bz2" ]; then
curl -L -o "contrib/gmp-${GMP_VERSION}.tar.bz2" https://gmplib.org/download/gmp/gmp-${GMP_VERSION}.tar.bz2
curl -L -o "contrib/gmp-${GMP_VERSION}.tar.bz2" https://ftp.gnu.org/gnu/gmp/gmp-${GMP_VERSION}.tar.bz2
fi
rm -rf "contrib/gmp"
# shellcheck disable=SC2039,SC2164
pushd contrib
tar xfj "gmp-${GMP_VERSION}.tar.bz2"
mv gmp-${GMP_VERSION} gmp
rm gmp/compat.c && cp ../../contrib/gmp-patch-6.2.1/compat.c gmp/compat.c
rm gmp/longlong.h && cp ../../contrib/gmp-patch-6.2.1/longlong.h gmp/longlong.h
# shellcheck disable=SC2039,SC2164
popd #contrib
# shellcheck disable=SC2039,SC2164
@ -88,10 +87,10 @@ prepare() {
download_relic() {
CURRENT_DIR=$(pwd)
echo "$CURRENT_DIR"
mkdir -p "${CURRENT_DIR}/${BUILD}/contrib"
if [ ! -s "${CURRENT_DIR}/${BUILD}/contrib/relic" ]; then
mkdir -p "${CURRENT_DIR}/${BUILD}/depends"
if [ ! -s "${CURRENT_DIR}/${BUILD}/depends/relic" ]; then
# shellcheck disable=SC2039,SC2164
pushd "${CURRENT_DIR}/${BUILD}/contrib"
pushd "${CURRENT_DIR}/${BUILD}/depends"
git clone --depth 1 --branch "feat/ios-support" https://github.com/pankcuf/relic
# shellcheck disable=SC2039,SC2164
pushd relic
@ -100,7 +99,7 @@ prepare() {
# shellcheck disable=SC2039,SC2164
popd #relic
# shellcheck disable=SC2039,SC2164
popd #contrib
popd #depends
fi
}
rm -rf ${BUILD}
@ -115,7 +114,7 @@ build_gmp_arch() {
ARCH=$2
PFX=${PLATFORM}-${ARCH}
# why this works with this host only?
HOST=arm-apple-darwin
HOST=aarch64-apple-darwin
# shellcheck disable=SC2039,SC2164
pushd ${BUILD}
SDK=$(xcrun --sdk "$PLATFORM" --show-sdk-path)
@ -143,7 +142,7 @@ CC="$CLANG" CFLAGS="$CFLAGS" CPPFLAGS="$CFLAGS" LDFLAGS="$CFLAGS" \
--host=${HOST} --prefix="${CURRENT_DIR}/gmplib-${PFX}" \
--disable-shared --enable-static --disable-assembly -v
EOF
chmod a+x "$CONFIGURESCRIPT"
sh "$CONFIGURESCRIPT"
rm "$CONFIGURESCRIPT"
@ -154,6 +153,8 @@ EOF
make -j "$LOGICALCPU_MAX" &> "${CURRENT_DIR}"/log/gmplib-"${PFX}"-build.log
# shellcheck disable=SC2039
make install &> "${CURRENT_DIR}"/log/gmplib-"${PFX}"-install.log
#make check
#exit 1
# shellcheck disable=SC2039,SC2164
popd # gmp
# shellcheck disable=SC2039,SC2164
@ -258,15 +259,15 @@ build_relic_arch() {
EXTRA_ARGS+=" -DARCH=X86"
elif [[ $ARCH = "x86_64" ]]; then
EXTRA_ARGS+=" -DARCH=X64"
else
EXTRA_ARGS+=" -DARCH=ARM"
if [[ $ARCH = "armv7s" ]]; then
EXTRA_ARGS+=" -DIOS_ARCH=armv7s"
elif [[ $ARCH = "armv7k" ]]; then
EXTRA_ARGS+=" -DIOS_ARCH=armv7k"
elif [[ $ARCH = "arm64_32" ]]; then
EXTRA_ARGS+=" -DIOS_ARCH=arm64_32"
fi
elif [[ $ARCH = "arm64" ]]; then
# Relic doesn't support aarch64 yet, "ARCH=ARM" is for ARM 32-bit architecture only
EXTRA_ARGS+=" -DIOS_ARCH=arm64 -DARCH="
elif [[ $ARCH = "armv7s" ]]; then
EXTRA_ARGS+=" -DIOS_ARCH=armv7s -DARCH=ARM"
elif [[ $ARCH = "armv7k" ]]; then
EXTRA_ARGS+=" -DIOS_ARCH=armv7k -DARCH=ARM"
elif [[ $ARCH = "arm64_32" ]]; then
EXTRA_ARGS+=" -DIOS_ARCH=arm64_32 -DARCH=ARM"
fi
CURRENT_DIR=$(pwd)
@ -281,7 +282,7 @@ build_relic_arch() {
# shellcheck disable=SC2039,SC2164
popd # "$BUILDDIR"
# shellcheck disable=SC2039,SC2164
popd # contrib/relic
popd # depends/relic
}
build_bls_arch() {
@ -311,7 +312,7 @@ build_bls_arch() {
clang -I"../contrib/relic/include" \
-I"../../depends/relic/include" \
-I"../../include/dashbls" \
-I"../relic-${PFX}/_deps/relic-build/include" \
-I"../relic-${PFX}/depends/relic/include" \
-I"../../src/" \
-I"../gmplib-${PFX}/include" \
-x c++ -std=c++14 -stdlib=libc++ -fembed-bitcode -arch "${ARCH}" -isysroot "${SDK}" "${EXTRA_ARGS}" \
@ -360,8 +361,8 @@ build_target() {
rm -rf "build/artefacts/${BUILD_IN}"
mkdir -p "build/artefacts/${BUILD_IN}"
cp "build/gmplib-${PFX}/lib/libgmp.a" "build/artefacts/${BUILD_IN}"
cp "build/relic-${PFX}/_deps/relic-build/lib/librelic_s.a" "build/artefacts/${BUILD_IN}"
cp "build/relic-${PFX}/_deps/sodium-build/libsodium.a" "build/artefacts/${BUILD_IN}"
cp "build/relic-${PFX}/depends/relic/lib/librelic_s.a" "build/artefacts/${BUILD_IN}"
# cp "build/relic-${PFX}/depends/sodium/libsodium.a" "build/artefacts/${BUILD_IN}"
cp "build/bls-${PFX}/libbls.a" "build/artefacts/${BUILD_IN}"
# cp -rf build/bls-"${PFX}"/*.o build/artefacts/"${BUILD_IN}"/include
# cp -rf src/*.hpp build/artefacts/"${BUILD_IN}"/include

View File

@ -1,458 +0,0 @@
#!/bin/sh
set -x
git submodule update --init
MIN_IOS="13.0"
MIN_WATCHOS="5.0"
MIN_TVOS=$MIN_IOS
MIN_MACOS="10.15"
IPHONEOS=iphoneos
IPHONESIMULATOR=iphonesimulator
WATCHOS=watchos
WATCHSIMULATOR=watchsimulator
TVOS=appletvos
TVSIMULATOR=appletvsimulator
MACOS=macosx
LOGICALCPU_MAX=$(sysctl -n hw.logicalcpu_max)
BUILD=build
version_min_flag() {
PLATFORM=$1
FLAG=""
# shellcheck disable=SC2039
# shellcheck disable=SC2053
if [[ $PLATFORM = $IPHONEOS ]]; then
FLAG="-miphoneos-version-min=${MIN_IOS}"
elif [[ $PLATFORM = $IPHONESIMULATOR ]]; then
FLAG="-mios-simulator-version-min=${MIN_IOS}"
elif [[ $PLATFORM = $WATCHOS ]]; then
FLAG="-mwatchos-version-min=${MIN_WATCHOS}"
elif [[ $PLATFORM = $WATCHSIMULATOR ]]; then
FLAG="-mwatchos-simulator-version-min=${MIN_WATCHOS}"
elif [[ $PLATFORM = $TVOS ]]; then
FLAG="-mtvos-version-min=${MIN_TVOS}"
elif [[ $PLATFORM = $TVSIMULATOR ]]; then
FLAG="-mtvos-simulator-version-min=${MIN_TVOS}"
elif [[ $PLATFORM = $MACOS ]]; then
FLAG="-mmacosx-version-min=${MIN_MACOS}"
fi
echo $FLAG
}
prepare() {
download_gmp() {
GMP_VERSION="6.2.1"
CURRENT_DIR=$(pwd)
echo "$CURRENT_DIR"
# shellcheck disable=SC2039,SC2164
pushd ${BUILD}
mkdir -p "contrib"
if [ ! -s "contrib/gmp-${GMP_VERSION}.tar.bz2" ]; then
curl -L -o "contrib/gmp-${GMP_VERSION}.tar.bz2" https://gmplib.org/download/gmp/gmp-${GMP_VERSION}.tar.bz2
fi
rm -rf "contrib/gmp"
# shellcheck disable=SC2039,SC2164
pushd contrib
tar xfj "gmp-${GMP_VERSION}.tar.bz2"
mv gmp-${GMP_VERSION} gmp
rm gmp/compat.c && cp ../../contrib/gmp-patch-6.2.1/compat.c gmp/compat.c
rm gmp/longlong.h && cp ../../contrib/gmp-patch-6.2.1/longlong.h gmp/longlong.h
# shellcheck disable=SC2039,SC2164
popd #contrib
# shellcheck disable=SC2039,SC2164
popd #build
}
download_cmake_toolchain() {
if [ ! -s "${BUILD}/ios.toolchain.cmake" ]; then
SHA256_HASH="d02857ff6bd64f1d7109ca59c3e4f3b2f89d0663c412146e6977c679801b3243"
curl -o "${BUILD}/ios.toolchain.cmake" https://raw.githubusercontent.com/leetal/ios-cmake/c55677a4445b138c9ef2650d3c21f22cc78c2357/ios.toolchain.cmake
DOWNLOADED_HASH=$(shasum -a 256 ${BUILD}/ios.toolchain.cmake | cut -f 1 -d " ")
if [ $SHA256_HASH != "$DOWNLOADED_HASH" ]; then
echo "Error: sha256 checksum of ios.toolchain.cmake mismatch" >&2
exit 1
fi
fi
}
download_relic() {
CURRENT_DIR=$(pwd)
echo "$CURRENT_DIR"
mkdir -p "${CURRENT_DIR}/${BUILD}/contrib"
if [ ! -s "${CURRENT_DIR}/${BUILD}/contrib/relic" ]; then
# shellcheck disable=SC2039,SC2164
pushd "${CURRENT_DIR}/${BUILD}/contrib"
git clone --depth 1 --branch "feat/ios-support" https://github.com/pankcuf/relic
# shellcheck disable=SC2039,SC2164
pushd relic
git fetch --depth 1 origin 19fb6d79a77ade4ae8cd70d2b0ef7aab8720d1ae
git checkout 19fb6d79a77ade4ae8cd70d2b0ef7aab8720d1ae
# shellcheck disable=SC2039,SC2164
popd #relic
# shellcheck disable=SC2039,SC2164
popd #contrib
fi
}
rm -rf ${BUILD}
mkdir -p ${BUILD}
download_relic
download_gmp
download_cmake_toolchain
mkdir -p ${BUILD}/artefacts/include
}
build_gmp_arch() {
PLATFORM=$1
ARCH=$2
PFX=${PLATFORM}-${ARCH}
# why this works with this host only?
HOST=arm-apple-darwin
# shellcheck disable=SC2039,SC2164
pushd ${BUILD}
SDK=$(xcrun --sdk "$PLATFORM" --show-sdk-path)
PLATFORM_PATH=$(xcrun --sdk "$PLATFORM" --show-sdk-platform-path)
CLANG=$(xcrun --sdk "$PLATFORM" --find clang)
DEVELOPER=$(xcode-select --print-path)
CURRENT_DIR=$(pwd)
export PATH="${PLATFORM_PATH}/Developer/usr/bin:${DEVELOPER}/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin"
mkdir gmplib-"${PLATFORM}"-"${ARCH}"
CFLAGS="-Wno-unused-value -fembed-bitcode -arch ${ARCH} --sysroot=${SDK} $(version_min_flag "$PLATFORM")"
CONFIGURESCRIPT="gmp_configure_script.sh"
# shellcheck disable=SC2039,SC2164
pushd contrib
# shellcheck disable=SC2039,SC2164
pushd gmp
make clean || true
make distclean || true
echo "HOST: $HOST"
echo "PREFIX: ${CURRENT_DIR}/gmplib-${PFX}"
cat >"$CONFIGURESCRIPT" << EOF
#!/bin/sh
./configure \
CC="$CLANG" CFLAGS="$CFLAGS" CPPFLAGS="$CFLAGS" LDFLAGS="$CFLAGS" \
--host=${HOST} --prefix="${CURRENT_DIR}/gmplib-${PFX}" \
--disable-shared --enable-static --disable-assembly -v
EOF
chmod a+x "$CONFIGURESCRIPT"
sh "$CONFIGURESCRIPT"
rm "$CONFIGURESCRIPT"
# shellcheck disable=SC2039
mkdir -p "${CURRENT_DIR}/log"
# shellcheck disable=SC2039
make -j "$LOGICALCPU_MAX" &> "${CURRENT_DIR}"/log/gmplib-"${PFX}"-build.log
# shellcheck disable=SC2039
make install &> "${CURRENT_DIR}"/log/gmplib-"${PFX}"-install.log
# shellcheck disable=SC2039,SC2164
popd # gmp
# shellcheck disable=SC2039,SC2164
popd # contrib
# shellcheck disable=SC2039,SC2164
popd # build
}
build_relic_arch() {
PLATFORM=$1
ARCH=$2
PFX=${PLATFORM}-${ARCH}
# shellcheck disable=SC2039,SC2164
pushd ${BUILD}
SDK=$(xcrun --sdk "$PLATFORM" --show-sdk-path)
BUILDDIR=relic-"${PFX}"
TOOLCHAIN=$(pwd)/ios.toolchain.cmake
GMP_PFX=$(pwd)/gmplib-${PFX}
rm -rf "$BUILDDIR"
mkdir "$BUILDDIR"
# shellcheck disable=SC2039,SC2164
pushd "$BUILDDIR"
unset CC
# shellcheck disable=SC2155
export CC=$(xcrun --sdk "${PLATFORM}" --find clang)
WSIZE=0
IOS_PLATFORM=""
OPTIMIZATIONFLAGS=""
DEPLOYMENT_TARGET=""
# shellcheck disable=SC2039
# shellcheck disable=SC2053
if [[ $PLATFORM = $IPHONEOS ]]; then
if [[ $ARCH = "arm64" ]] || [[ $ARCH = "arm64e" ]]; then
IOS_PLATFORM=OS64
DEPLOYMENT_TARGET=$MIN_IOS
WSIZE=64
OPTIMIZATIONFLAGS=-fomit-frame-pointer
else
IOS_PLATFORM=OS
WSIZE=32
fi
elif [[ $PLATFORM = $IPHONESIMULATOR ]]; then
if [[ $ARCH = "x86_64" ]]; then
IOS_PLATFORM=SIMULATOR64
DEPLOYMENT_TARGET=$MIN_IOS
WSIZE=64
OPTIMIZATIONFLAGS=-fomit-frame-pointer
elif [[ $ARCH = "arm64" ]]; then
IOS_PLATFORM=SIMULATORARM64
DEPLOYMENT_TARGET=$MIN_IOS
WSIZE=64
else
IOS_PLATFORM=SIMULATOR
WSIZE=32
fi
elif [[ $PLATFORM = $WATCHOS ]]; then
IOS_PLATFORM=WATCHOS
DEPLOYMENT_TARGET=$MIN_WATCHOS
WSIZE=32
elif [[ $PLATFORM = $WATCHSIMULATOR ]]; then
IOS_PLATFORM=SIMULATOR_WATCHOS
DEPLOYMENT_TARGET=$MIN_WATCHOS
WSIZE=32
elif [[ $PLATFORM = $TVOS ]]; then
IOS_PLATFORM=TVOS
DEPLOYMENT_TARGET=$MIN_TVOS
WSIZE=64
OPTIMIZATIONFLAGS=-fomit-frame-pointer
elif [[ $PLATFORM = $TVSIMULATOR ]]; then
IOS_PLATFORM=SIMULATOR_TVOS
#TODO
if [[ $ARCH = "arm64" ]]
then
IOS_PLATFORM=OS64
fi
DEPLOYMENT_TARGET=$MIN_TVOS
WSIZE=64
OPTIMIZATIONFLAGS=-fomit-frame-pointer
elif [[ $PLATFORM = $MACOS ]]; then
WSIZE=64
IOS_PLATFORM=MAC
if [[ $ARCH = "arm64" ]]
then
IOS_PLATFORM=MAC_ARM64
fi
DEPLOYMENT_TARGET=$MIN_MACOS
OPTIMIZATIONFLAGS=-fomit-frame-pointer
fi
COMPILER_ARGS="$(version_min_flag "$PLATFORM") -Wno-unused-functions"
EXTRA_ARGS="-DOPSYS=NONE -DPLATFORM=$IOS_PLATFORM -DDEPLOYMENT_TARGET=$DEPLOYMENT_TARGET -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN"
# shellcheck disable=SC2039
if [[ $ARCH = "i386" ]]; then
EXTRA_ARGS+=" -DARCH=X86"
elif [[ $ARCH = "x86_64" ]]; then
EXTRA_ARGS+=" -DARCH=X64"
else
EXTRA_ARGS+=" -DARCH=ARM"
if [[ $ARCH = "armv7s" ]]; then
EXTRA_ARGS+=" -DIOS_ARCH=armv7s"
elif [[ $ARCH = "armv7k" ]]; then
EXTRA_ARGS+=" -DIOS_ARCH=armv7k"
elif [[ $ARCH = "arm64_32" ]]; then
EXTRA_ARGS+=" -DIOS_ARCH=arm64_32"
fi
fi
CURRENT_DIR=$(pwd)
cmake -DCMAKE_PREFIX_PATH:PATH="${GMP_PFX}" -DTESTS=0 -DBENCH=0 -DBUILD_BLS_JS_BINDINGS=0 -DBUILD_BLS_PYTHON_BINDINGS=0 \
-DBUILD_BLS_BENCHMARKS=0 -DBUILD_BLS_TESTS=0 -DCHECK=off -DARITH=gmp -DTIMER=HPROC -DFP_PRIME=381 -DMULTI=PTHREAD \
-DFP_QNRES=on -DFP_METHD="INTEG;INTEG;INTEG;MONTY;EXGCD;SLIDE" -DFPX_METHD="INTEG;INTEG;LAZYR" -DPP_METHD="LAZYR;OATEP" \
-DCOMP_FLAGS="-pipe -std=c99 -O3 -funroll-loops $OPTIMIZATIONFLAGS -isysroot $SDK -arch $ARCH -fembed-bitcode ${COMPILER_ARGS}" \
-DWSIZE=$WSIZE -DVERBS=off -DSHLIB=off -DALLOC="AUTO" -DEP_PLAIN=off -DEP_SUPER=off -DPP_EXT="LAZYR" \
-DWITH="DV;BN;MD;FP;EP;FPX;EPX;PP;PC;CP" -DBN_METHD="COMBA;COMBA;MONTY;SLIDE;STEIN;BASIC" ${EXTRA_ARGS} ../../
make -j "$LOGICALCPU_MAX"
# shellcheck disable=SC2039,SC2164
popd # "$BUILDDIR"
# shellcheck disable=SC2039,SC2164
popd # contrib/relic
}
build_bls_arch() {
# shellcheck disable=SC2039
BLS_FILES=( "bls" "chaincode" "elements" "extendedprivatekey" "extendedpublickey" "legacy" "privatekey" "schemes" "threshold" )
# shellcheck disable=SC2039
ALL_BLS_OBJ_FILES=$(printf "%s.o " "${BLS_FILES[@]}")
PLATFORM=$1
ARCH=$2
PFX=${PLATFORM}-${ARCH}
SDK=$(xcrun --sdk "$PLATFORM" --show-sdk-path)
BUILDDIR=${BUILD}/bls-"${PFX}"
rm -rf "$BUILDDIR"
mkdir "$BUILDDIR"
# shellcheck disable=SC2039,SC2164
pushd "$BUILDDIR"
EXTRA_ARGS="$(version_min_flag "$PLATFORM")"
CURRENT_DIR=$(pwd)
# shellcheck disable=SC2039
for F in "${BLS_FILES[@]}"
do
clang -I"../contrib/relic/include" \
-I"../relic-${PFX}/_deps/relic-build/include" \
-I"../../src/" \
-I"../gmplib-${PFX}/include" \
-x c++ -std=c++14 -stdlib=libc++ -fembed-bitcode -arch "${ARCH}" -isysroot "${SDK}" "${EXTRA_ARGS}" \
-c "../../src/${F}.cpp" -o "${F}.o"
done
# shellcheck disable=SC2086
xcrun -sdk "$PLATFORM" ar -cvq libbls.a $ALL_BLS_OBJ_FILES
# shellcheck disable=SC2039,SC2164
popd # "$BUILDDIR"
}
build_all_arch() {
PLATFORM=$1
ARCH=$2
build_gmp_arch "$PLATFORM" "$ARCH"
build_relic_arch "$PLATFORM" "$ARCH"
build_bls_arch "$PLATFORM" "$ARCH"
}
build_all() {
BUILD_IN=$1
TARGET_DIR=build/artefacts
# shellcheck disable=SC2039
IFS='|' read -ra BUILD_PAIRS <<< "$BUILD_IN"
# shellcheck disable=SC2039
for BUILD_PAIR in "${BUILD_PAIRS[@]}"
do
# shellcheck disable=SC2039
IFS=';' read -ra PARSED_PAIR <<< "$BUILD_PAIR"
# shellcheck disable=SC2039
PLATFORM=${PARSED_PAIR[0]}
# shellcheck disable=SC2039
ARCH=${PARSED_PAIR[1]}
GMP_LIPOARGS=""
RELIC_LIPOARGS=""
BLS_LIPOARGS=""
# shellcheck disable=SC2039
local NEED_LIPO=0
# shellcheck disable=SC2039
IFS='+' read -ra ARCHS <<< "$ARCH"
# shellcheck disable=SC2039
for i in "${!ARCHS[@]}"
do
# shellcheck disable=SC2039
local SINGLEARCH=${ARCHS[i]}
# build for every platform+arch
build_all_arch "$PLATFORM" "$SINGLEARCH"
PFX="${PLATFORM}"-"${SINGLEARCH}"
ARCH_TARGET_DIR=${TARGET_DIR}/${PFX}
rm -rf "${ARCH_TARGET_DIR}"
mkdir -p "${ARCH_TARGET_DIR}"
#mv "${BUILD}/gmplib-${PFX}/lib/libgmp.a" "${ARCH_TARGET_DIR}/libgmp.a"
#mv "${BUILD}/relic-${PFX}/_deps/relic-build/lib/librelic_s.a" "${ARCH_TARGET_DIR}/librelic.a"
#mv "${BUILD}/bls-${PFX}/libbls.a" "${ARCH_TARGET_DIR}/libbls.a"
libtool -static -o "${ARCH_TARGET_DIR}/libbls.a" \
"${BUILD}/gmplib-${PFX}/lib/libgmp.a" \
"${BUILD}/relic-${PFX}/_deps/relic-build/lib/librelic_s.a" \
"${BUILD}/bls-${PFX}/libbls.a"
# shellcheck disable=SC2039
GMP_LIPOARGS+="${ARCH_TARGET_DIR}/libgmp.a "
# shellcheck disable=SC2039
RELIC_LIPOARGS+="${ARCH_TARGET_DIR}/librelic.a "
# shellcheck disable=SC2039
BLS_LIPOARGS+="${ARCH_TARGET_DIR}/libbls.a "
NEED_LIPO=i
done
# Do lipo if we need https://developer.apple.com/forums/thread/666335?answerId=645963022#645963022
# if [[ $NEED_LIPO -gt 0 ]]
# then
# FAT_TARGET_DIR=${TARGET_DIR}/${PLATFORM}-fat
# rm -rf "${FAT_TARGET_DIR}"
# mkdir -p "${FAT_TARGET_DIR}"
# # shellcheck disable=SC2086
# xcrun lipo $GMP_LIPOARGS -create -output "${FAT_TARGET_DIR}/libgmp.a"
# # shellcheck disable=SC2086
# xcrun lipo $RELIC_LIPOARGS -create -output "${FAT_TARGET_DIR}/librelic.a"
# # shellcheck disable=SC2086
# xcrun lipo $BLS_LIPOARGS -create -output "${FAT_TARGET_DIR}/libbls.a"
# libtool -static -o "${FAT_TARGET_DIR}/libbls_combined.a" "${FAT_TARGET_DIR}/libgmp.a" "${FAT_TARGET_DIR}/librelic.a" "${FAT_TARGET_DIR}/libbls.a"
# rm "${FAT_TARGET_DIR}/libgmp.a"
# rm "${FAT_TARGET_DIR}/librelic.a"
# rm "${FAT_TARGET_DIR}/libbls.a"
# mv "${FAT_TARGET_DIR}/libbls_combined.a" "${FAT_TARGET_DIR}/libbls.a"
# # clean up
# # shellcheck disable=SC2039
# for i in "${!ARCHS[@]}"
# do
# local SINGLEARCH=${ARCHS[i]}
# rm -rf "${TARGET_DIR}-${SINGLEARCH}"
# done
# fi
done
}
#make_relic_headers_universal() {
# RELIC_TARGET_DIR=relic-iphoneos-arm64
# perl -p -e 's/#define WSIZE.*/#ifdef __LP64__\n#define WSIZE 64\n#else\n#define WSIZE 32\n#endif/' \
# "build/contrib/relic/${RELIC_TARGET_DIR}/include/relic_conf.h" \
# > "build/contrib/relic/${RELIC_TARGET_DIR}/include/relic_conf.h.new"
#
# rm "build/contrib/relic/${RELIC_TARGET_DIR}/include/relic_conf.h"
# mv "build/contrib/relic/${RELIC_TARGET_DIR}/include/relic_conf.h.new" "build/contrib/relic/${RELIC_TARGET_DIR}/include/relic_conf.h"
#}
#copy_headers() {
# mkdir build/artefacts/include
# # Copy all headers we will need
# cp -rf src/*.hpp build/artefacts/include
# cp -rf build/gmp/include/gmp.h build/artefacts/include
# cp -rf build/contrib/relic/include/*.h build/artefacts/include
# cp -rf build/contrib/relic/include/low/*.h build/artefacts/include
# cp -rf build/contrib/relic/relic-iphoneos-arm64/include/*.h build/artefacts/include
# rm -rf build/artefacts/include/test-utils.hpp
#}
#function make_fat_binary()
#{
# pushd artefacts
#
# XCFRAMEWORK_ARGS=""
#
# for dir in */; do
# if [ -d "$dir" ]; then
# if [[ "$dir" != "include/" ]]; then
# libtool -static -o "${dir}libbls_combined.a" "${dir}libgmp.a" "${dir}librelic.a" "${dir}libbls.a"
#
# XCFRAMEWORK_ARGS+="-library ${dir}libbls_combined.a -headers include "
# fi
# fi
# done
#
# #xcodebuild -create-xcframework $XCFRAMEWORK_ARGS -output "libbls.xcframework"
#}
prepare
build_all "${MACOS};x86_64+arm64"
build_all "${IPHONEOS};arm64|${IPHONESIMULATOR};arm64+x86_64"
#make_relic_headers_universal
#copy_headers
#make_fat_binary

View File

@ -1,404 +0,0 @@
#!/bin/sh
set -x
# "x86_64-apple-ios"
# "x86_64-apple-ios-sim"
# "aarch64-apple-ios"
# "aarch64-apple-ios-sim"
# "x86_64-apple-darwin"
# "aarch64-apple-darwin"
# TODO: it's probably needs to be optimized in order to increase better build velocity
# TODO: so we need to combine multiple targets
TARGET=$1
git submodule update --init
MIN_IOS="13.0"
MIN_WATCHOS="5.0"
MIN_TVOS=$MIN_IOS
MIN_MACOS="10.15"
IPHONEOS=iphoneos
IPHONESIMULATOR=iphonesimulator
WATCHOS=watchos
WATCHSIMULATOR=watchsimulator
TVOS=appletvos
TVSIMULATOR=appletvsimulator
MACOS=macosx
LOGICALCPU_MAX=$(sysctl -n hw.logicalcpu_max)
BUILD=build
version_min_flag() {
PLATFORM=$1
FLAG=""
# shellcheck disable=SC2039
# shellcheck disable=SC2053
if [[ $PLATFORM = $IPHONEOS ]]; then
FLAG="-miphoneos-version-min=${MIN_IOS}"
elif [[ $PLATFORM = $IPHONESIMULATOR ]]; then
FLAG="-mios-simulator-version-min=${MIN_IOS}"
elif [[ $PLATFORM = $WATCHOS ]]; then
FLAG="-mwatchos-version-min=${MIN_WATCHOS}"
elif [[ $PLATFORM = $WATCHSIMULATOR ]]; then
FLAG="-mwatchos-simulator-version-min=${MIN_WATCHOS}"
elif [[ $PLATFORM = $TVOS ]]; then
FLAG="-mtvos-version-min=${MIN_TVOS}"
elif [[ $PLATFORM = $TVSIMULATOR ]]; then
FLAG="-mtvos-simulator-version-min=${MIN_TVOS}"
elif [[ $PLATFORM = $MACOS ]]; then
FLAG="-mmacosx-version-min=${MIN_MACOS}"
fi
echo $FLAG
}
prepare() {
download_gmp() {
GMP_VERSION="6.2.1"
CURRENT_DIR=$(pwd)
echo "$CURRENT_DIR"
# shellcheck disable=SC2039,SC2164
pushd ${BUILD}
mkdir -p "contrib"
if [ ! -s "contrib/gmp-${GMP_VERSION}.tar.bz2" ]; then
curl -L -o "contrib/gmp-${GMP_VERSION}.tar.bz2" https://gmplib.org/download/gmp/gmp-${GMP_VERSION}.tar.bz2
fi
rm -rf "contrib/gmp"
# shellcheck disable=SC2039,SC2164
pushd contrib
tar xfj "gmp-${GMP_VERSION}.tar.bz2"
mv gmp-${GMP_VERSION} gmp
rm gmp/compat.c && cp ../../contrib/gmp-patch-6.2.1/compat.c gmp/compat.c
rm gmp/longlong.h && cp ../../contrib/gmp-patch-6.2.1/longlong.h gmp/longlong.h
# shellcheck disable=SC2039,SC2164
popd #contrib
# shellcheck disable=SC2039,SC2164
popd #build
}
download_cmake_toolchain() {
if [ ! -s "${BUILD}/ios.toolchain.cmake" ]; then
SHA256_HASH="d02857ff6bd64f1d7109ca59c3e4f3b2f89d0663c412146e6977c679801b3243"
curl -o "${BUILD}/ios.toolchain.cmake" https://raw.githubusercontent.com/leetal/ios-cmake/c55677a4445b138c9ef2650d3c21f22cc78c2357/ios.toolchain.cmake
DOWNLOADED_HASH=$(shasum -a 256 ${BUILD}/ios.toolchain.cmake | cut -f 1 -d " ")
if [ $SHA256_HASH != "$DOWNLOADED_HASH" ]; then
echo "Error: sha256 checksum of ios.toolchain.cmake mismatch" >&2
exit 1
fi
fi
}
download_relic() {
CURRENT_DIR=$(pwd)
echo "$CURRENT_DIR"
mkdir -p "${CURRENT_DIR}/${BUILD}/contrib"
if [ ! -s "${CURRENT_DIR}/${BUILD}/contrib/relic" ]; then
# shellcheck disable=SC2039,SC2164
pushd "${CURRENT_DIR}/${BUILD}/contrib"
git clone --depth 1 --branch "feat/ios-support" https://github.com/pankcuf/relic
# shellcheck disable=SC2039,SC2164
pushd relic
git fetch --depth 1 origin 19fb6d79a77ade4ae8cd70d2b0ef7aab8720d1ae
git checkout 19fb6d79a77ade4ae8cd70d2b0ef7aab8720d1ae
# shellcheck disable=SC2039,SC2164
popd #relic
# shellcheck disable=SC2039,SC2164
popd #contrib
fi
}
rm -rf ${BUILD}
mkdir -p ${BUILD}
download_relic
download_gmp
download_cmake_toolchain
}
build_gmp_arch() {
PLATFORM=$1
ARCH=$2
PFX=${PLATFORM}-${ARCH}
# why this works with this host only?
HOST=arm-apple-darwin
# shellcheck disable=SC2039,SC2164
pushd ${BUILD}
SDK=$(xcrun --sdk "$PLATFORM" --show-sdk-path)
PLATFORM_PATH=$(xcrun --sdk "$PLATFORM" --show-sdk-platform-path)
CLANG=$(xcrun --sdk "$PLATFORM" --find clang)
DEVELOPER=$(xcode-select --print-path)
CURRENT_DIR=$(pwd)
export PATH="${PLATFORM_PATH}/Developer/usr/bin:${DEVELOPER}/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin"
mkdir gmplib-"${PLATFORM}"-"${ARCH}"
CFLAGS="-Wno-unused-value -fembed-bitcode -arch ${ARCH} --sysroot=${SDK} $(version_min_flag "$PLATFORM")"
CONFIGURESCRIPT="gmp_configure_script.sh"
# shellcheck disable=SC2039,SC2164
pushd contrib
# shellcheck disable=SC2039,SC2164
pushd gmp
make clean || true
make distclean || true
echo "HOST: $HOST"
echo "PREFIX: ${CURRENT_DIR}/gmplib-${PFX}"
cat >"$CONFIGURESCRIPT" << EOF
#!/bin/sh
./configure \
CC="$CLANG" CFLAGS="$CFLAGS" CPPFLAGS="$CFLAGS" LDFLAGS="$CFLAGS" \
--host=${HOST} --prefix="${CURRENT_DIR}/gmplib-${PFX}" \
--disable-shared --enable-static --disable-assembly -v
EOF
chmod a+x "$CONFIGURESCRIPT"
sh "$CONFIGURESCRIPT"
rm "$CONFIGURESCRIPT"
# shellcheck disable=SC2039
mkdir -p "${CURRENT_DIR}/log"
# shellcheck disable=SC2039
make -j "$LOGICALCPU_MAX" &> "${CURRENT_DIR}"/log/gmplib-"${PFX}"-build.log
# shellcheck disable=SC2039
make install &> "${CURRENT_DIR}"/log/gmplib-"${PFX}"-install.log
# shellcheck disable=SC2039,SC2164
popd # gmp
# shellcheck disable=SC2039,SC2164
popd # contrib
# shellcheck disable=SC2039,SC2164
popd # build
}
build_relic_arch() {
PLATFORM=$1
ARCH=$2
PFX=${PLATFORM}-${ARCH}
# shellcheck disable=SC2039,SC2164
pushd ${BUILD}
SDK=$(xcrun --sdk "$PLATFORM" --show-sdk-path)
BUILDDIR=relic-"${PFX}"
TOOLCHAIN=$(pwd)/ios.toolchain.cmake
GMP_PFX=$(pwd)/gmplib-${PFX}
rm -rf "$BUILDDIR"
mkdir "$BUILDDIR"
# shellcheck disable=SC2039,SC2164
pushd "$BUILDDIR"
unset CC
# shellcheck disable=SC2155
export CC=$(xcrun --sdk "${PLATFORM}" --find clang)
WSIZE=0
IOS_PLATFORM=""
OPTIMIZATIONFLAGS=""
DEPLOYMENT_TARGET=""
# shellcheck disable=SC2039
# shellcheck disable=SC2053
if [[ $PLATFORM = $IPHONEOS ]]; then
if [[ $ARCH = "arm64" ]] || [[ $ARCH = "arm64e" ]]; then
IOS_PLATFORM=OS64
DEPLOYMENT_TARGET=$MIN_IOS
WSIZE=64
OPTIMIZATIONFLAGS=-fomit-frame-pointer
else
IOS_PLATFORM=OS
WSIZE=32
fi
elif [[ $PLATFORM = $IPHONESIMULATOR ]]; then
if [[ $ARCH = "x86_64" ]]; then
IOS_PLATFORM=SIMULATOR64
DEPLOYMENT_TARGET=$MIN_IOS
WSIZE=64
OPTIMIZATIONFLAGS=-fomit-frame-pointer
elif [[ $ARCH = "arm64" ]]; then
IOS_PLATFORM=SIMULATORARM64
DEPLOYMENT_TARGET=$MIN_IOS
WSIZE=64
else
IOS_PLATFORM=SIMULATOR
WSIZE=32
fi
elif [[ $PLATFORM = $WATCHOS ]]; then
IOS_PLATFORM=WATCHOS
DEPLOYMENT_TARGET=$MIN_WATCHOS
WSIZE=32
elif [[ $PLATFORM = $WATCHSIMULATOR ]]; then
IOS_PLATFORM=SIMULATOR_WATCHOS
DEPLOYMENT_TARGET=$MIN_WATCHOS
WSIZE=32
elif [[ $PLATFORM = $TVOS ]]; then
IOS_PLATFORM=TVOS
DEPLOYMENT_TARGET=$MIN_TVOS
WSIZE=64
OPTIMIZATIONFLAGS=-fomit-frame-pointer
elif [[ $PLATFORM = $TVSIMULATOR ]]; then
IOS_PLATFORM=SIMULATOR_TVOS
#TODO
if [[ $ARCH = "arm64" ]]
then
IOS_PLATFORM=OS64
fi
DEPLOYMENT_TARGET=$MIN_TVOS
WSIZE=64
OPTIMIZATIONFLAGS=-fomit-frame-pointer
elif [[ $PLATFORM = $MACOS ]]; then
WSIZE=64
IOS_PLATFORM=MAC
if [[ $ARCH = "arm64" ]]
then
IOS_PLATFORM=MAC_ARM64
fi
DEPLOYMENT_TARGET=$MIN_MACOS
OPTIMIZATIONFLAGS=-fomit-frame-pointer
fi
COMPILER_ARGS="$(version_min_flag "$PLATFORM") -Wno-unused-functions"
EXTRA_ARGS="-DOPSYS=NONE -DPLATFORM=$IOS_PLATFORM -DDEPLOYMENT_TARGET=$DEPLOYMENT_TARGET -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN"
# shellcheck disable=SC2039
if [[ $ARCH = "i386" ]]; then
EXTRA_ARGS+=" -DARCH=X86"
elif [[ $ARCH = "x86_64" ]]; then
EXTRA_ARGS+=" -DARCH=X64"
else
EXTRA_ARGS+=" -DARCH=ARM"
if [[ $ARCH = "armv7s" ]]; then
EXTRA_ARGS+=" -DIOS_ARCH=armv7s"
elif [[ $ARCH = "armv7k" ]]; then
EXTRA_ARGS+=" -DIOS_ARCH=armv7k"
elif [[ $ARCH = "arm64_32" ]]; then
EXTRA_ARGS+=" -DIOS_ARCH=arm64_32"
fi
fi
CURRENT_DIR=$(pwd)
cmake -DCMAKE_PREFIX_PATH:PATH="${GMP_PFX}" -DTESTS=0 -DBENCH=0 -DBUILD_BLS_JS_BINDINGS=0 -DBUILD_BLS_PYTHON_BINDINGS=0 \
-DBUILD_BLS_BENCHMARKS=0 -DBUILD_BLS_TESTS=0 -DCHECK=off -DARITH=gmp -DTIMER=HPROC -DFP_PRIME=381 -DMULTI=PTHREAD \
-DFP_QNRES=on -DFP_METHD="INTEG;INTEG;INTEG;MONTY;EXGCD;SLIDE" -DFPX_METHD="INTEG;INTEG;LAZYR" -DPP_METHD="LAZYR;OATEP" \
-DCOMP_FLAGS="-pipe -std=c99 -O3 -funroll-loops $OPTIMIZATIONFLAGS -isysroot $SDK -arch $ARCH -fembed-bitcode ${COMPILER_ARGS}" \
-DWSIZE=$WSIZE -DVERBS=off -DSHLIB=off -DALLOC="AUTO" -DEP_PLAIN=off -DEP_SUPER=off -DPP_EXT="LAZYR" \
-DWITH="DV;BN;MD;FP;EP;FPX;EPX;PP;PC;CP" -DBN_METHD="COMBA;COMBA;MONTY;SLIDE;STEIN;BASIC" ${EXTRA_ARGS} ../../
make -j "$LOGICALCPU_MAX"
# shellcheck disable=SC2039,SC2164
popd # "$BUILDDIR"
# shellcheck disable=SC2039,SC2164
popd # contrib/relic
}
build_bls_arch() {
# shellcheck disable=SC2039
BLS_FILES=( "bls" "chaincode" "elements" "extendedprivatekey" "extendedpublickey" "legacy" "privatekey" "schemes" "threshold" )
# shellcheck disable=SC2039
ALL_BLS_OBJ_FILES=$(printf "%s.o " "${BLS_FILES[@]}")
PLATFORM=$1
ARCH=$2
PFX=${PLATFORM}-${ARCH}
SDK=$(xcrun --sdk "$PLATFORM" --show-sdk-path)
BUILDDIR=${BUILD}/bls-"${PFX}"
rm -rf "$BUILDDIR"
mkdir "$BUILDDIR"
# shellcheck disable=SC2039,SC2164
pushd "$BUILDDIR"
EXTRA_ARGS="$(version_min_flag "$PLATFORM")"
CURRENT_DIR=$(pwd)
# shellcheck disable=SC2039
for F in "${BLS_FILES[@]}"
do
clang -I"../contrib/relic/include" \
-I"../relic-${PFX}/_deps/relic-build/include" \
-I"../../src/" \
-I"../gmplib-${PFX}/include" \
-x c++ -std=c++14 -stdlib=libc++ -fembed-bitcode -arch "${ARCH}" -isysroot "${SDK}" "${EXTRA_ARGS}" \
-c "../../src/${F}.cpp" -o "${F}.o"
done
# shellcheck disable=SC2086
xcrun -sdk "$PLATFORM" ar -cvq libbls.a $ALL_BLS_OBJ_FILES
# shellcheck disable=SC2039,SC2164
popd # "$BUILDDIR"
}
build_all_arch() {
PLATFORM=$1
ARCH=$2
build_gmp_arch "$PLATFORM" "$ARCH"
build_relic_arch "$PLATFORM" "$ARCH"
build_bls_arch "$PLATFORM" "$ARCH"
}
build_target() {
BUILD_IN=$1
echo "Build target: $BUILD_IN"
ARCH=""
PLATFORM=""
# shellcheck disable=SC2039
if [[ $BUILD_IN = "x86_64-apple-ios" ]]; then
ARCH=x86_64
PLATFORM=$IPHONESIMULATOR
elif [[ $BUILD_IN = "aarch64-apple-ios" ]]; then
ARCH=arm64
PLATFORM=$IPHONEOS
elif [[ $BUILD_IN = "aarch64-apple-ios-sim" ]]; then
ARCH=arm64
PLATFORM=$IPHONESIMULATOR
elif [[ $BUILD_IN = "x86_64-apple-darwin" ]]; then
ARCH=x86_64
PLATFORM=$MACOS
elif [[ $BUILD_IN = "aarch64-apple-darwin" ]]; then
ARCH=arm64
PLATFORM=$MACOS
fi
build_all_arch "$PLATFORM" "$ARCH"
PFX="${PLATFORM}"-"${ARCH}"
rm -rf "build/artefacts/${BUILD_IN}"
mkdir -p "build/artefacts/${BUILD_IN}/include"
# libtool -static -o "build/artefacts/${BUILD_IN}/libbls.a" \
# "build/gmplib-${PFX}/lib/libgmp.a" \
# "build/relic-${PFX}/_deps/relic-build/lib/librelic_s.a" \
# "build/bls-${PFX}/libbls.a"
cp "build/gmplib-${PFX}/lib/libgmp.a" "build/artefacts/${BUILD_IN}"
cp "build/relic-${PFX}/_deps/relic-build/lib/librelic_s.a" "build/artefacts/${BUILD_IN}"
cp "build/relic-${PFX}/_deps/sodium-build/libsodium.a" "build/artefacts/${BUILD_IN}"
cp "build/bls-${PFX}/libbls.a" "build/artefacts/${BUILD_IN}"
cp -rf build/bls-"${PFX}"/*.o build/artefacts/"${BUILD_IN}"/include
cp -rf src/*.hpp build/artefacts/"${BUILD_IN}"/include
cp -rf build/gmplib-"${PFX}"/include/gmp.h build/artefacts/"${BUILD_IN}"/include
cp -rf build/relic-"${PFX}"/_deps/relic-build/include/*.h build/artefacts/"${BUILD_IN}"/include
}
#make_relic_headers_universal() {
# RELIC_TARGET_DIR=relic-iphoneos-arm64
# perl -p -e 's/#define WSIZE.*/#ifdef __LP64__\n#define WSIZE 64\n#else\n#define WSIZE 32\n#endif/' \
# "build/contrib/relic/${RELIC_TARGET_DIR}/include/relic_conf.h" \
# > "build/contrib/relic/${RELIC_TARGET_DIR}/include/relic_conf.h.new"
#
# rm "build/contrib/relic/${RELIC_TARGET_DIR}/include/relic_conf.h"
# mv "build/contrib/relic/${RELIC_TARGET_DIR}/include/relic_conf.h.new" "build/contrib/relic/${RELIC_TARGET_DIR}/include/relic_conf.h"
#}
#
#copy_headers() {
## mkdir build/artefacts/include
# # Copy all headers we will need
# cp -rf src/*.hpp ${BUILD}/artefacts/include
# cp -rf ${BUILD}/contrib/gmp/include/gmp.h ${BUILD}/artefacts/include
# cp -rf ${BUILD}/contrib/relic/include/*.h ${BUILD}/artefacts/include
# cp -rf ${BUILD}/contrib/relic/include/low/*.h ${BUILD}/artefacts/include
# #cp -rf ${BUILD}/contrib/relic/relic-iphoneos-arm64/include/*.h ${BUILD}/artefacts/include
# rm -rf ${BUILD}/artefacts/include/test-utils.hpp
#}
prepare
build_target "$TARGET"
#copy_headers
#build_all "${MACOS};x86_64+arm64"
#build_all "${IPHONEOS};arm64|${IPHONESIMULATOR};arm64+x86_64"
#make_relic_headers_universal
#copy_headers
#make_fat_binary

View File

@ -1,5 +1,5 @@
AC_PREREQ([2.60])
AC_INIT([libdashbls],[1.3.0])
AC_INIT([libdashbls],[1.3.3])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([build-aux/m4])
@ -24,20 +24,21 @@ dnl make the compilation flags quiet unless V=1 is used
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
dnl Compiler checks (here before libtool).
if test "x${CFLAGS+set}" = "xset"; then
CFLAGS_overridden=yes
else
CFLAGS_overridden=no
fi
if test "x${CXXFLAGS+set}" = "xset"; then
CXXFLAGS_overridden=yes
else
CXXFLAGS_overridden=no
fi
AC_PROG_CC
AC_PROG_CXX
AM_PROG_CC_C_O
AC_PROG_CC_C99
if test x"$ac_cv_prog_cc_c99" = x"no"; then
AC_MSG_ERROR([c99 compiler support required])
fi
dnl By default, libtool for mingw refuses to link static libs into a dll for
dnl fear of mixing pic/non-pic objects, and import/export complications. Since
dnl we have those under control, re-enable that functionality.
@ -58,24 +59,76 @@ AC_PATH_TOOL(STRIP, strip)
AM_PROG_AS
AC_ARG_ENABLE(tests,
[AS_HELP_STRING([--disable-tests],
[do not compile tests (default is to compile)])],
AC_ARG_ENABLE([tests],
[AS_HELP_STRING([--enable-tests],
[Compile with tests [default=yes]])],
[use_tests=$enableval],
[use_tests=yes])
AC_ARG_ENABLE(bench,
[AS_HELP_STRING([--disable-bench],
[do not compile benchmarks (default is to compile)])],
AC_ARG_ENABLE([bench],
[AS_HELP_STRING([--enable-bench],
[Compile with benchmarks [default=yes]])],
[use_bench=$enableval],
[use_bench=yes])
AC_ARG_ENABLE([hardening],
[AS_HELP_STRING([--disable-hardening],
[do not attempt to harden the resulting executables (default is to harden when possible)])],
[AS_HELP_STRING([--enable-hardening],
[Enable hardening flags and arguments [default=auto]])],
[use_hardening=$enableval],
[use_hardening=auto])
AC_ARG_ENABLE([optimizations],
[AS_HELP_STRING([--enable-optimizations],
[Enable compiler and library optimizations [default=yes]])],
[use_optimizations=$enableval],
[use_optimizations=yes])
AC_ARG_ENABLE([debug],
[AS_HELP_STRING([--enable-debug],
[Build with debugging support [default=no]])],
[use_debug=$enableval],
[use_debug=no])
AC_LANG_PUSH([C])
dnl Check for a flag to turn compiler warnings into errors. This is helpful for checks which may
dnl appear to succeed because by default they merely emit warnings when they fail.
dnl
dnl Note that this is not necessarily a check to see if -Werror is supported, but rather to see if
dnl a compile with -Werror can succeed. This is important because the compiler may already be
dnl warning about something unrelated, for example about some path issue. If that is the case,
dnl -Werror cannot be used because all of those warnings would be turned into errors.
AX_CHECK_COMPILE_FLAG([-Werror], [FLAG_WERROR="-Werror"], [FLAG_WERROR=""])
if [[[ "$use_debug" == "yes" || "$use_optimizations" == "no" ]]]; then
dnl Clear default -g -O2 flags
if test x"$CFLAGS_overridden" = x"no"; then
CFLAGS=""
fi
if test x"$CXXFLAGS_overridden" = x"no"; then
CXXFLAGS=""
fi
dnl Disable optimizations
AX_CHECK_COMPILE_FLAG([-O0], [[DEBUG_FLAGS="$DEBUG_FLAGS -O0"]], [], [[$FLAG_WERROR]])
if [[[ "$use_debug" == "yes" ]]]; then
dnl Prefer -g3, fall back to -g if that is unavailable.
AX_CHECK_COMPILE_FLAG(
[-g3],
[[DEBUG_FLAGS="$DEBUG_FLAGS -g3"]],
[AX_CHECK_COMPILE_FLAG([-g],[[DEBUG_FLAGS="$DEBUG_FLAGS -g"]])], [[$FLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-ftrapv],[DEBUG_FLAGS="$DEBUG_FLAGS -ftrapv"], [], [[$FLAG_WERROR]])
else
dnl Reintroduce -g flag deleted during C(XX)FLAGS reset
AX_CHECK_COMPILE_FLAG([-g],[[DEBUG_FLAGS="$DEBUG_FLAGS -g"]], [], [[$FLAG_WERROR]])
dnl -ftrapv and -fwrapv conflict, so we only set this if use_debug=no
AX_CHECK_COMPILE_FLAG([-fwrapv],[DEBUG_FLAGS="$DEBUG_FLAGS -fwrapv"], [], [[$FLAG_WERROR]])
fi
fi
dnl Define enum mappings for relic config
AC_DEFINE([RLC_VERSION], ["0.5.0"], [Relic Version])
@ -95,15 +148,56 @@ AC_DEFINE([GMP], [2], [Backend based on GNU Multiple Precision library.])
AC_DEFINE([GMP_SEC], [3], [Backend based on GNU Multiple Precision library, but using constant-time code.])
AC_DEFUN([GMP_CHECK],[
if test x"$has_gmp" != x"yes"; then
AC_REQUIRE([AC_PROG_CC])
CPPFLAGS_TEMP="$CPPFLAGS"
CPPFLAGS="$GMP_CPPFLAGS $CPPFLAGS"
LIBS_TEMP="$LIBS"
LIBS="$GMP_LDFLAGS $LIBS"
AC_CHECK_HEADER(gmp.h,[AC_CHECK_LIB(gmp, __gmpz_init,[has_gmp=yes; GMP_LIBS="-lgmp";])])
AC_CHECK_HEADER(
gmp.h,
[AC_CHECK_LIB(gmp, __gmpz_init, [], [gmp_fail_reason="libgmp not found or unusable"; has_gmp=no;])],
[gmp_fail_reason="gmp header not found"; has_gmp=no;]
)
if test x"$has_gmp" != x"no"; then
# Proper support for macOS aarch64 was introduced in 6.3.0, but LTS distros
# like Ubuntu 20.04 (focal) use 6.2.0, so, the minimum supported version is
# determined by platform and architecture.
case $host in
*darwin*)
case $host_cpu in
aarch*)
gmp_major_version=6
gmp_minor_version=3
;;
esac
;;
*)
gmp_major_version=6
gmp_minor_version=2
;;
esac
AC_MSG_CHECKING([gmp version >= $gmp_major_version.$gmp_minor_version])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[@%:@include <gmp.h>]],
[[
@%:@if __GNU_MP_VERSION < $gmp_major_version || __GNU_MP_VERSION_MINOR < $gmp_minor_version
@%:@error Unsupported GMP version
@%:@endif]])],
[AC_MSG_RESULT([yes]); GMP_LIBS="-lgmp"; has_gmp=yes;],
[AC_MSG_RESULT([no]); gmp_fail_reason="unsupported gmp version"; has_gmp=no;]
)
fi
if test x"$want_backend" = x"gmp" && test x"$has_gmp" = x"no"; then
AC_MSG_ERROR([$gmp_fail_reason])
fi
CPPFLAGS="$CPPFLAGS_TEMP"
LIBS="$LIBS_TEMP"
fi
])
AC_ARG_WITH([backend],
@ -113,34 +207,38 @@ AC_ARG_WITH([backend],
[want_backend=auto]
)
case $host in
*darwin*)
AC_PATH_PROG([BREW],brew,)
if test x$BREW != x; then
# These Homebrew packages may be keg-only, meaning that they won't be found
# in expected paths because they may conflict with system files. Ask
# Homebrew where each one is located, then adjust paths accordingly.
gmp_prefix=`$BREW --prefix gmp 2>/dev/null`
if test x$gmp_prefix != x; then
GMP_CPPFLAGS="-I$gmp_prefix/include"
GMP_LDFLAGS="-L$gmp_prefix/lib"
fi
fi
;;
esac
if test x"$want_backend" = x"auto"; then
GMP_CHECK
if test x"$has_gmp" = x"yes"; then
case $host in
*darwin*)
case $host_cpu in
aarch*)
want_backend=easy
;;
*)
want_backend=gmp
;;
esac
;;
*)
want_backend=gmp
;;
esac
else
if test x"$use_optimizations" = x"no"; then
want_backend=easy
else
GMP_CHECK
if test x"$has_gmp" = x"yes"; then
want_backend=gmp
else
want_backend=easy
fi
fi
else
case $want_backend in
gmp)
dnl GMP_CHECK will report the reason if and why the backend cannot be used.
GMP_CHECK
if test x"$has_gmp" != x"yes"; then
AC_MSG_ERROR([gmp backend explicitly requested but libgmp not available])
fi
;;
easy)
;;
@ -257,20 +355,14 @@ AC_DEFINE([BRUCH], [6], [Hardware-friendly inversion by Brunner-Curiger-Hofste
AC_DEFINE([CTAIA], [7], [Constant-time version of almost inverse.])
AC_DEFINE([LOWER], [8], [Use implementation provided by the lower layer.])
dnl Define relic switches
AC_ARG_ENABLE([debug],
[AS_HELP_STRING([--enable-debug],
[Build with debugging support (default is no)])],
[use_debug=$enableval],
[use_debug=no])
if test x$use_debug = xyes; then
if test x"$use_debug" = x"yes"; then
AC_DEFINE([DEBUG], [1], [Define this symbol if debugging support is enabled])
fi
dnl Define relic switches
AC_ARG_ENABLE([profiling],
[AS_HELP_STRING([--enable-profiling],
[Build with profiling support (default is no)])],
[Build with profiling support [default=no]])],
[use_profiling=$enableval],
[use_profiling=no])
@ -280,7 +372,7 @@ fi
AC_ARG_ENABLE([check],
[AS_HELP_STRING([--enable-check],
[Build with error-checking support (default is no)])],
[Build with error-checking support [default=no]])],
[use_check=$enableval],
[use_check=no])
@ -290,7 +382,7 @@ fi
AC_ARG_ENABLE([verbs],
[AS_HELP_STRING([--enable-verbs],
[Build with detailed error messages (default is no)])],
[Build with detailed error messages [default=no]])],
[use_verbs=$enableval],
[use_verbs=no])
@ -300,7 +392,7 @@ fi
AC_ARG_ENABLE([overhead],
[AS_HELP_STRING([--enable-overhead],
[Build with overhead estimation (default is no)])],
[Build with overhead estimation [default=no]])],
[use_overhead=$enableval],
[use_overhead=no])
@ -310,7 +402,7 @@ fi
AC_ARG_ENABLE([quiet],
[AS_HELP_STRING([--enable-quiet],
[Build with printing disabled (default is yes)])],
[Build with printing disabled [default=yes]])],
[use_quiet=$enableval],
[use_quiet=yes])
@ -320,7 +412,7 @@ fi
AC_ARG_ENABLE([color],
[AS_HELP_STRING([--enable-color],
[Build with colored output support (default is yes)])],
[Build with colored output support [default=yes]])],
[use_color=$enableval],
[use_color=yes])
@ -330,7 +422,7 @@ fi
AC_ARG_ENABLE([big_endian],
[AS_HELP_STRING([--enable-big-endian],
[Build with big-endian support (default is no)])],
[Build with big-endian support [default=no]])],
[use_big_endian=$enableval],
[use_big_endian=no])
@ -340,63 +432,46 @@ fi
use_pkgconfig=yes
case $host_cpu in
x86_64)
dnl Support for AMD64 (also known as x86_64 on some platforms) processors
CPU_ARCH="x64"
AC_DEFINE([ARCH], [X64], [Architecture.])
AC_DEFINE([WSIZE], [64], [Size of word in this architecture.])
;;
aarch*)
dnl Relic doesn't support aarch64 yet, set CPU_ARCH to none.
dnl Support for 64-bit ARM processors
CPU_ARCH="none"
AC_DEFINE([ARCH], [ARM], [Architecture.])
AC_DEFINE([WSIZE], [64], [Size of word in this architecture.])
;;
i?86)
dnl Support for Intel x86 processors
CPU_ARCH="x86"
AC_DEFINE([ARCH], [X86], [Architecture.])
AC_DEFINE([WSIZE], [32], [Size of word in this architecture.])
;;
arm*)
dnl Support for 32-bit native ARM processors
CPU_ARCH="arm"
AC_DEFINE([ARCH], [ARM], [Architecture.])
AC_DEFINE([WSIZE], [32], [Size of word in this architecture.])
;;
*32*)
dnl Support for an undefined 32-bit architecture
CPU_ARCH="none"
AC_DEFINE([ARCH], [RELIC_NONE], [Architecture.])
AC_DEFINE([WSIZE], [32], [Size of word in this architecture.])
;;
*64*)
dnl Support for an undefined 64-bit architecture
CPU_ARCH="none"
AC_DEFINE([ARCH], [RELIC_NONE], [Architecture.])
AC_DEFINE([WSIZE], [64], [Size of word in this architecture.])
;;
*)
AC_MSG_ERROR([Unable to determine host architecture, may not be supported!])
;;
esac
if [[[ "$host_cpu" == x86_64 && "$use_optimizations" == "yes" ]]]; then
dnl Support for AMD64 (also known as x86_64 on some platforms) processors
CPU_ARCH="x64"
AC_DEFINE([ARCH], [X64], [Architecture.])
AC_DEFINE([WSIZE], [64], [Size of word in this architecture.])
elif [[[ "$host_cpu" == aarch* && "$use_optimizations" == "yes" ]]]; then
dnl Support for 64-bit ARM processors
dnl Relic doesn't support aarch64 yet, set CPU_ARCH to none and ARCH to RELIC_NONE.
CPU_ARCH="none"
AC_DEFINE([ARCH], [RELIC_NONE], [Architecture.])
AC_DEFINE([WSIZE], [64], [Size of word in this architecture.])
elif [[[ "$host_cpu" == i?86 && "$use_optimizations" == "yes" ]]]; then
dnl Support for Intel x86 processors
CPU_ARCH="x86"
AC_DEFINE([ARCH], [X86], [Architecture.])
AC_DEFINE([WSIZE], [32], [Size of word in this architecture.])
elif [[[ "$host_cpu" == arm* && "$use_optimizations" == "yes" ]]]; then
dnl Support for 32-bit native ARM processors
CPU_ARCH="arm"
AC_DEFINE([ARCH], [ARM], [Architecture.])
AC_DEFINE([WSIZE], [32], [Size of word in this architecture.])
elif [[[ "$host_cpu" == *64* ]]]; then
dnl Support for an undefined 64-bit architecture
CPU_ARCH="none"
AC_DEFINE([ARCH], [RELIC_NONE], [Architecture.])
AC_DEFINE([WSIZE], [64], [Size of word in this architecture.])
elif [[[ "$host_cpu" == *32* || "$host_cpu" == arm* || "$host_cpu" == i?86 ]]]; then
dnl Support for an undefined 32-bit architecture
CPU_ARCH="none"
AC_DEFINE([ARCH], [RELIC_NONE], [Architecture.])
AC_DEFINE([WSIZE], [32], [Size of word in this architecture.])
else
AC_MSG_ERROR([Unable to determine host architecture, may not be supported!])
fi
case $host in
*darwin*)
AC_DEFINE([OPSYS], [MACOSX], [Detected operation system.])
AC_PATH_PROG([BREW],brew,)
if test x$BREW != x; then
# These Homebrew packages may be keg-only, meaning that they won't be found
# in expected paths because they may conflict with system files. Ask
# Homebrew where each one is located, then adjust paths accordingly.
gmp_prefix=`$BREW --prefix gmp 2>/dev/null`
if test x$gmp_prefix != x; then
GMP_CPPFLAGS="-I$gmp_prefix/include"
GMP_LDFLAGS="-L$gmp_prefix/lib"
fi
else
if test x$BREW = x; then
AC_PATH_PROG([PORT],port,)
# If homebrew isn't installed and macports is, add the macports default paths
# as a last resort.
@ -480,17 +555,20 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
CFLAGS="$saved_CFLAGS"
])
AC_LANG_PUSH([C])
AX_CHECK_COMPILE_FLAG([-Wall],[WARN_CFLAGS="$WARN_CFLAGS -Wall"],,)
AX_CHECK_COMPILE_FLAG([-Wextra],[WARN_CFLAGS="$WARN_CFLAGS -Wextra"],,)
AX_CHECK_COMPILE_FLAG([-Wcast-align],[WARN_CFLAGS="$WARN_CFLAGS -Wcast-align"],,)
AX_CHECK_COMPILE_FLAG([-Wunused-parameter],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-unused-parameter"],,)
AX_CHECK_COMPILE_FLAG([-Wshadow],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-shadow"],,)
AX_CHECK_COMPILE_FLAG([-Wsign-compare],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-sign-compare"],,)
AX_CHECK_COMPILE_FLAG([-Wstrict-prototypes],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-strict-prototypes"],,)
AX_CHECK_COMPILE_FLAG([-Wunused-function],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-unused-function"],,)
AX_CHECK_COMPILE_FLAG([-Wlong-long],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-long-long"],,)
AC_LANG_POP([C])
if [[[ "$CFLAGS_overridden" == "no" && "$CXXFLAGS_overridden" == "no" ]]]; then
dnl Enable warnings
AX_CHECK_COMPILE_FLAG([-Wall],[WARN_FLAGS="$WARN_FLAGS -Wall"], [], [[$FLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wcast-align],[WARN_FLAGS="$WARN_FLAGS -Wcast-align"], [], [[$FLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wextra],[WARN_FLAGS="$WARN_FLAGS -Wextra"], [], [[$FLAG_WERROR]])
dnl Exclude known warnings
AX_CHECK_COMPILE_FLAG([-Wlong-long],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-long-long"], [], [[$FLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wshadow],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-shadow"], [], [[$FLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wsign-compare],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-sign-compare"], [], [[$FLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wstrict-prototypes],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-strict-prototypes"], [], [[$FLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wunused-function],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-unused-function"], [], [[$FLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wunused-parameter],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-unused-parameter"], [], [[$FLAG_WERROR]])
fi
dnl set default settings for relic
AC_DEFINE([ALIGN], [1], [Byte boundary to align digit vectors.])
@ -615,19 +693,19 @@ AC_SEARCH_LIBS([clock_gettime],[rt])
if test "$TARGET_OS" != "windows"; then
dnl All windows code is PIC, forcing it on just adds useless compile warnings
AX_CHECK_COMPILE_FLAG([-fPIC], [PIC_FLAGS="-fPIC"])
AX_CHECK_COMPILE_FLAG([-fPIC], [HARDENED_FLAGS="$HARDENED_FLAGS -fPIC"], [], [[$FLAG_WERROR]])
fi
dnl All versions of gcc that we commonly use for building are subject to bug
dnl https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348. To work around that, set
dnl -fstack-reuse=none for all gcc builds. (Only gcc understands this flag)
AX_CHECK_COMPILE_FLAG([-fstack-reuse=none], [HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-reuse=none"])
AX_CHECK_COMPILE_FLAG([-fstack-reuse=none], [HARDENED_FLAGS="$HARDENED_FLAGS -fstack-reuse=none"], [], [[$FLAG_WERROR]])
if test "$use_hardening" != "no"; then
use_hardening=yes
AX_CHECK_COMPILE_FLAG([-Wstack-protector], [HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -Wstack-protector"])
AX_CHECK_COMPILE_FLAG([-fstack-protector-all], [HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-protector-all"])
AX_CHECK_COMPILE_FLAG([-Wstack-protector], [HARDENED_FLAGS="$HARDENED_FLAGS -Wstack-protector"])
AX_CHECK_COMPILE_FLAG([-fstack-protector-all], [HARDENED_FLAGS="$HARDENED_FLAGS -fstack-protector-all"], [], [[$FLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-fcf-protection=full], [HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fcf-protection=full"])
AX_CHECK_COMPILE_FLAG([-fcf-protection=full], [HARDENED_FLAGS="$HARDENED_FLAGS -fcf-protection=full"], [], [[$FLAG_WERROR]])
case $host in
*mingw*)
@ -635,10 +713,16 @@ if test "$use_hardening" != "no"; then
dnl See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90458 for more details.
;;
*)
AX_CHECK_COMPILE_FLAG([-fstack-clash-protection], [HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-clash-protection"], [], [])
AX_CHECK_COMPILE_FLAG([-fstack-clash-protection], [HARDENED_FLAGS="$HARDENED_FLAGS -fstack-clash-protection"], [], [[$FLAG_WERROR]])
;;
esac
case $host in
*aarch64*)
AX_CHECK_COMPILE_FLAG([-mbranch-protection=bti], [HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -mbranch-protection=bti"], [], [[$CXXFLAG_WERROR]])
;;
esac
AX_CHECK_LINK_FLAG([-Wl,--enable-reloc-section], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--enable-reloc-section"], [], [])
AX_CHECK_LINK_FLAG([-Wl,--dynamicbase], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--dynamicbase"], [], [])
AX_CHECK_LINK_FLAG([-Wl,--nxcompat], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--nxcompat"], [], [])
@ -646,7 +730,7 @@ if test "$use_hardening" != "no"; then
AX_CHECK_LINK_FLAG([-Wl,-z,relro], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"], [], [])
AX_CHECK_LINK_FLAG([-Wl,-z,now], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"], [], [])
AX_CHECK_LINK_FLAG([-Wl,-z,separate-code], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,separate-code"], [], [])
AX_CHECK_LINK_FLAG([-fPIE -pie], [PIE_FLAGS="-fPIE"; HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"], [], [])
AX_CHECK_LINK_FLAG([-fPIE -pie], [HARDENED_FLAGS="$HARDENED_FLAGS -fPIE"; HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"], [], [])
case $host in
*mingw*)
@ -708,7 +792,9 @@ if test "$TARGET_OS" = "darwin"; then
fi
dnl Don't allow extended (non-ASCII) symbols in identifiers. This is easier for code review.
AX_CHECK_COMPILE_FLAG([-fno-extended-identifiers], [CORE_CXXFLAGS="$CORE_CXXFLAGS -fno-extended-identifiers"], [], [])
AX_CHECK_COMPILE_FLAG([-fno-extended-identifiers], [CORE_FLAGS="$CORE_FLAGS -fno-extended-identifiers"], [], [[$FLAG_WERROR]])
AC_LANG_POP([C])
AC_MSG_CHECKING([whether to build runtest])
if test x$use_tests = xyes; then
@ -753,24 +839,23 @@ AM_CONDITIONAL(WITH_FBX, test 1 -eq 1)
AM_CONDITIONAL([USE_TESTS], [test x$BUILD_TEST = xyes])
AM_CONDITIONAL([USE_BENCH], [test x$BUILD_BENCH = xyes])
AM_CONDITIONAL([HARDEN], [test "$use_hardening" = "yes"])
AM_CONDITIONAL([OPTIMIZE], [test "$use_optimizations" = "yes"])
AM_CONDITIONAL([ARITH_EASY], [test "$want_backend" = "easy"])
AM_CONDITIONAL([ARITH_GMP], [test "$want_backend" = "gmp"])
AC_SUBST(CPU_ARCH)
AC_SUBST(DEBUG_FLAGS)
AC_SUBST(RAND_PATH, hashd)
AC_SUBST(RELIC_CPPFLAGS)
AC_SUBST(WARN_CFLAGS)
AC_SUBST(NOWARN_CFLAGS)
AC_SUBST(WARN_FLAGS)
AC_SUBST(NOWARN_FLAGS)
AC_SUBST(LIBTOOL_APP_LDFLAGS)
AC_SUBST(HARDENED_CXXFLAGS)
AC_SUBST(HARDENED_CPPFLAGS)
AC_SUBST(HARDENED_FLAGS)
AC_SUBST(HARDENED_LDFLAGS)
AC_SUBST(PIC_FLAGS)
AC_SUBST(PIE_FLAGS)
AC_SUBST(CORE_LDFLAGS)
AC_SUBST(CORE_CPPFLAGS)
AC_SUBST(CORE_CXXFLAGS)
AC_SUBST(CORE_FLAGS)
AC_SUBST(GMP_LDFLAGS)
AC_SUBST(GMP_CPPFLAGS)
@ -784,3 +869,20 @@ AC_OUTPUT
dnl Peplace conflict-prone PACKAGE-prefixed macros with DASHBLS
sed -i.old 's/PACKAGE/DASHBLS/g' depends/relic/include/relic_conf.h
sed -i.old 's/PACKAGE/DASHBLS/g' config.status
echo
echo "Options used to compile and link:"
echo " target os = $TARGET_OS"
echo " backend = $want_backend"
echo " build bench = $BUILD_BENCH"
echo " build test = $BUILD_TEST"
echo " use debug = $use_debug"
echo " use hardening = $use_hardening"
echo " use optimizations = $use_optimizations"
echo
echo " LDFLAGS = $HARDENED_LDFLAGS $CORE_LDFLAGS $GMP_LDFLAGS"
echo " CFLAGS = $DEBUG_FLAGS $HARDENED_FLAGS $CORE_FLAGS $WARN_FLAGS $NOWARN_FLAGS"
echo " CPPFLAGS = $CORE_CPPFLAGS $GMP_CPPFLAGS"
echo " CXXFLAGS = $DEBUG_FLAGS $HARDENED_FLAGS $CORE_FLAGS $WARN_FLAGS $NOWARN_FLAGS"
echo " PTHREAD_FLAGS = $PTHREAD_CFLAGS $PTHREAD_LIBS"
echo

View File

@ -1,65 +0,0 @@
/* Old function entrypoints retained for binary compatibility.
Copyright 2000, 2001 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any
later version.
or both in parallel, as here.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received copies of the GNU General Public License and the
GNU Lesser General Public License along with the GNU MP Library. If not,
see https://www.gnu.org/licenses/. */
#include <stdio.h>
#include "gmp-impl.h"
/* RUNTIMECPUID */
int bCheckedBMI = 0;
int bBMI1 = 0;
int bBMI2 = 0;
int bCheckedLZCNT = 0;
int bLZCNT = 0;
/* mpn_divexact_by3 was a function in gmp 3.0.1, but as of gmp 3.1 it's a
macro calling mpn_divexact_by3c. */
mp_limb_t
__MPN (divexact_by3) (mp_ptr dst, mp_srcptr src, mp_size_t size)
{
return mpn_divexact_by3 (dst, src, size);
}
/* mpn_divmod_1 was a function in gmp 3.0.1 and earlier, but marked obsolete
in both gmp 2 and 3. As of gmp 3.1 it's a macro calling mpn_divrem_1. */
mp_limb_t
__MPN (divmod_1) (mp_ptr dst, mp_srcptr src, mp_size_t size, mp_limb_t divisor)
{
return mpn_divmod_1 (dst, src, size, divisor);
}
/* mpz_legendre was a separate function in gmp 3.1.1 and earlier, but as of
4.0 it's a #define alias for mpz_jacobi. */
int
__gmpz_legendre (mpz_srcptr a, mpz_srcptr b)
{
return mpz_jacobi (a, b);
}

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@ include(FetchContent)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v2.10.0
GIT_TAG v2.13.6
)
FetchContent_MakeAvailable(pybind11)

View File

@ -32,6 +32,7 @@ fn handle_command_output(output: Output) {
#[cfg(not(feature = "apple"))]
fn main() {
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
// TODO: fix build for wasm32 on MacOS
// errors with `error: linking with `rust-lld` failed: exit status: 1`
@ -39,6 +40,7 @@ fn main() {
println!("Build for wasm32 is not fully supported");
return;
}
println!("cargo:warning=Building bls-signatures for non-Apple target: {}", target_arch);
let root_path = Path::new("../..")
.canonicalize()
@ -63,12 +65,48 @@ fn main() {
fs::create_dir_all(&bls_dash_build_path).expect("can't create build directory");
let cmake_output = create_cross_cmake_command()
let cmake_command_binding = create_cross_cmake_command();
let mut cmake_command = cmake_command_binding;
cmake_command
.current_dir(&bls_dash_build_path)
.arg("-DBUILD_BLS_PYTHON_BINDINGS=0")
.arg("-DBUILD_BLS_TESTS=0")
.arg("-DBUILD_BLS_BENCHMARKS=0")
.arg("-DBUILD_BLS_JS_BINDINGS=0")
.arg("-DBUILD_BLS_JS_BINDINGS=0");
// configure CMake for Android
if target_os.eq("android") {
let cmake_toolchain_path = env::var("CMAKE_TOOLCHAIN_FILE")
.or_else(|_| env::var("CARGO_NDK_CMAKE_TOOLCHAIN_PATH"))
.expect("Neither CMAKE_TOOLCHAIN_FILE nor CARGO_NDK_CMAKE_TOOLCHAIN_PATH environment variables are set");
let ndk_target = match env::var("CARGO_NDK_TARGET_ARCH") {
Ok(value) => value, // If set, use the value directly.
Err(_) => {
match target_arch.as_str() {
"aarch64" => "arm64-v8a".to_string(),
"arm" => "armeabi-v7a".to_string(),
"x86" => "x86".to_string(),
"x86_64" => "x86_64".to_string(),
_ => panic!("Unsupported target architecture for Android: {}", target_arch),
}
}
};
// Default to android-24 if ANDROID_PLATFORM is not specified
let android_abi = env::var("ANDROID_PLATFORM")
.or_else(|_| env::var("CARGO_NDK_ANDROID_PLATFORM"))
.unwrap_or_else(|_| "android-24".to_string());
cmake_command
.arg(format!("-DANDROID_PLATFORM={}", android_abi))
.arg(format!("-DANDROID_ABI={}", ndk_target))
.arg(format!("-DCMAKE_TOOLCHAIN_FILE={}", cmake_toolchain_path));
}
let cmake_output = cmake_command
.arg("..")
.output()
.expect("can't run cmake");
@ -100,8 +138,8 @@ fn main() {
.collect();
include_paths.extend([
bls_dash_build_path.join("_deps/relic-src/include"),
bls_dash_build_path.join("_deps/relic-build/include"),
bls_dash_build_path.join("depends/relic-src/include"),
bls_dash_build_path.join("depends/relic/include"),
bls_dash_build_path.join("src"),
root_path.join("include/dashbls"),
bls_dash_build_path.join("depends/relic/include"),
@ -127,7 +165,8 @@ fn main() {
cc.files(cpp_files)
.includes(&include_paths)
.cpp(true)
.flag_if_supported("-std=c++14");
.flag_if_supported("-std=c++14")
.target(&env::var("TARGET").unwrap());
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
@ -196,6 +235,7 @@ fn main() {
println!("cargo:rustc-link-lib=static=gmp");
}
println!("cargo:warning=########## bls_dash_build_path:{}", bls_dash_build_path.display());
// Generate rust code for c binding to src/lib.rs
// println!("Generate C binding for rust:");
@ -290,7 +330,7 @@ fn main() {
let target = env::var("TARGET").unwrap();
println!("Building bls-signatures for apple target: {}", target);
println!("cargo:warning=Building bls-signatures for Apple target: {}", target);
let root_path = Path::new("../..")
.canonicalize()
.expect("can't get abs path");
@ -305,6 +345,32 @@ fn main() {
fs::remove_dir_all(&bls_dash_build_path).expect("can't clean build directory");
}
fs::create_dir_all(&bls_dash_build_path).expect("can't create build directory");
let cc_path_output = Command::new("xcrun")
.arg("--sdk")
.arg("iphoneos")
.arg("--find")
.arg("clang")
.output()
.expect("Failed to find clang");
let cc_path = String::from_utf8_lossy(&cc_path_output.stdout).trim().to_string();
let cxx_path_output = Command::new("xcrun")
.arg("--sdk")
.arg("iphoneos")
.arg("--find")
.arg("clang++")
.output()
.expect("Failed to find clang++");
let cxx_path = String::from_utf8_lossy(&cxx_path_output.stdout).trim().to_string();
// Print the paths for clang and clang++
println!("cargo:warning=CC path: {}", cc_path);
println!("cargo:warning=CXX path: {}", cxx_path);
std::env::set_var("CC", cc_path);
std::env::set_var("CXX", cxx_path);
let output = Command::new("sh")
.current_dir(&root_path)
.arg(script)
@ -312,6 +378,7 @@ fn main() {
.output()
.expect("Failed to execute the shell script");
handle_command_output(output);
let (arch, platform) = match target.as_str() {
"x86_64-apple-ios" => ("x86_64", "iphonesimulator"),
"aarch64-apple-ios" => ("arm64", "iphoneos"),
@ -335,8 +402,8 @@ fn main() {
.collect();
include_paths.extend([
bls_dash_build_path.join(format!("relic-{}-{}/_deps/relic-src/include", platform, arch)),
bls_dash_build_path.join(format!("relic-{}-{}/_deps/relic-build/include", platform, arch)),
bls_dash_build_path.join(format!("relic-{}-{}/depends/relic-src/include", platform, arch)),
bls_dash_build_path.join(format!("relic-{}-{}/depends/relic/include", platform, arch)),
bls_dash_build_path.join("contrib/relic/src"),
root_path.join("src"),
root_path.join("include/dashbls"),
@ -365,8 +432,10 @@ fn main() {
println!("cargo:rustc-link-search={}", target_path.display());
println!("cargo:rustc-link-lib=static=gmp");
// println!("cargo:rustc-link-lib=static=sodium");
// println!("cargo:rustc-link-lib=static=relic_s");
//println!("cargo:rustc-link-lib=c++");
//println!("cargo:rustc-link-lib=c");
//println!("cargo:rustc-link-lib=static=sodium");
println!("cargo:rustc-link-lib=static=relic_s");
println!("cargo:rustc-link-lib=static=bls");
println!("cargo:rustc-link-search={}", bls_dash_src_path.display());
println!("cargo:rustc-link-lib=static=dashbls");

View File

@ -16,3 +16,4 @@ apple = ["bls-dash-sys/apple"]
bls-dash-sys = { path = "../bls-dash-sys" }
serde = { version= "1.0.160", features = ["derive"], optional = true}
rand = { version= "0.8.5", optional = true}
hex = { version = "0.4.3"}

View File

@ -1,4 +1,6 @@
use std::ffi::c_void;
use std::fmt::Debug;
use std::fmt::Formatter;
use bls_dash_sys::{CoreMPLDeriveChildPkUnhardened, G1ElementFree, G1ElementFromBytes, G1ElementGenerator, G1ElementGetFingerprint, G1ElementIsEqual, G1ElementSerialize, G1ElementCopy, G2ElementCopy, G2ElementFree, G2ElementFromBytes, G2ElementIsEqual, G2ElementSerialize, ThresholdPublicKeyRecover, ThresholdSignatureRecover};
#[cfg(feature = "use_serde")]
@ -17,17 +19,28 @@ pub type PublicKey = G1Element;
#[cfg(feature = "dash_helpers")]
pub type Signature = G2Element;
#[derive(Debug)]
pub struct G1Element {
pub(crate) c_element: *mut c_void,
}
// G1Element is immutable and thread safe
unsafe impl Send for G1Element {}
unsafe impl Sync for G1Element {}
impl PartialEq for G1Element {
fn eq(&self, other: &Self) -> bool {
unsafe { G1ElementIsEqual(self.c_element, other.c_element) }
}
}
impl Debug for G1Element {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let g1_hex = hex::encode(self.to_bytes().as_slice());
write!(f, "G1Element({:?})", g1_hex)
}
}
impl Eq for G1Element {}
impl G1Element {
@ -181,17 +194,28 @@ impl Drop for G1Element {
}
}
#[derive(Debug)]
pub struct G2Element {
pub(crate) c_element: *mut c_void,
}
// G2Element is immutable and thread safe
unsafe impl Send for G2Element {}
unsafe impl Sync for G2Element {}
impl PartialEq for G2Element {
fn eq(&self, other: &Self) -> bool {
unsafe { G2ElementIsEqual(self.c_element, other.c_element) }
}
}
impl Debug for G2Element {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let g2_hex = hex::encode(self.to_bytes().as_slice());
write!(f, "G2Element({:?})", g2_hex)
}
}
impl Eq for G2Element {}
impl G2Element {
@ -311,6 +335,7 @@ impl Drop for G2Element {
#[cfg(test)]
mod tests {
use std::thread;
use super::*;
use crate::{
schemes::{AugSchemeMPL, Scheme},
@ -365,4 +390,22 @@ mod tests {
assert_eq!(g1_element.fingerprint(), 2093959050);
}
#[test]
fn should_be_thread_safe() {
let bytes = [
151, 241, 211, 167, 49, 151, 215, 148, 38, 149, 99, 140, 79, 169, 172, 15, 195, 104,
140, 79, 151, 116, 185, 5, 161, 78, 58, 63, 23, 27, 172, 88, 108, 85, 232, 63, 249,
122, 26, 239, 251, 58, 240, 10, 219, 34, 198, 187,
];
let g1_element =
G1Element::from_bytes(&bytes).expect("should create g1 element from bytes");
let test_thread = thread::spawn(move|| {
assert_eq!(g1_element.fingerprint(), 2093959050);
});
test_thread.join().unwrap();
}
}

View File

@ -5,6 +5,10 @@ impl G1Element {
self.to_bytes_with_legacy_flag(true)
}
pub fn serialize(&self) -> Box<[u8; G1_ELEMENT_SIZE]> {
self.to_bytes_with_legacy_flag(false)
}
pub fn from_bytes_legacy(bytes: &[u8]) -> Result<Self, BlsError> {
Self::from_bytes_with_legacy_flag(bytes, true)
}
@ -22,4 +26,8 @@ impl G2Element {
pub fn serialize_legacy(&self) -> Box<[u8; G2_ELEMENT_SIZE]> {
self.to_bytes_with_legacy_flag(true)
}
pub fn serialize(&self) -> Box<[u8; G2_ELEMENT_SIZE]> {
self.to_bytes_with_legacy_flag(false)
}
}

View File

@ -101,4 +101,26 @@ mod tests {
grandchild_sk_u.g1_element().expect("cannot get public key")
);
}
#[test]
fn test_bls_public_key() {
let seed = b"seedweedseedweedseedweedseedweed";
let scheme = LegacySchemeMPL::new();
let private_key = PrivateKey::key_gen(&scheme, seed).expect("unable to generate private key");
let public_key = private_key.g1_element().expect("unable to get public key");
let expected_priv_key = vec![92, 116, 13, 32, 66, 150, 74, 240, 121, 255, 94, 222, 127, 180, 19, 10, 244, 212, 173, 51, 91, 198, 162, 132, 230, 105, 134, 255, 125, 191, 198, 223];
let expected_pub_key = vec![129, 171, 183, 152, 50, 52, 28, 18, 241, 75, 118, 255, 58, 136, 184, 52, 247, 229, 14, 221, 40, 117, 194, 142, 2, 208, 193, 215, 131, 17, 234, 195, 229, 23, 249, 239, 139, 176, 18, 187, 102, 55, 162, 76, 48, 88, 228, 150];
assert_eq!(
private_key.to_bytes().as_slice(),
expected_priv_key
);
assert_eq!(
public_key.to_bytes().as_slice(),
expected_pub_key
);
}
}

View File

@ -1,4 +1,5 @@
use std::{ffi::c_void, ops::Mul};
use std::fmt::{Debug, Formatter};
use bls_dash_sys::{
CoreMPLDeriveChildSk, CoreMPLDeriveChildSkUnhardened, CoreMPLKeyGen, G1ElementMul,
@ -13,7 +14,6 @@ use crate::{schemes::Scheme, utils::{c_err_to_result, SecureBox}, BasicSchemeMPL
pub const PRIVATE_KEY_SIZE: usize = 32; // TODO somehow extract it from bls library
#[derive(Debug)]
pub struct PrivateKey {
pub(crate) c_private_key: *mut c_void,
}
@ -26,6 +26,13 @@ impl PartialEq for PrivateKey {
impl Eq for PrivateKey {}
impl Debug for PrivateKey {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let private_key_hex = hex::encode(self.to_bytes().as_slice());
write!(f, "PrivateKey({:?})", private_key_hex)
}
}
impl Mul<G1Element> for PrivateKey {
type Output = Result<G1Element, BlsError>;