diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 395c6722a1df9..08d89302b8c81 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -44,6 +44,7 @@ jobs: test/lint/git-subtree-check.sh src/univalue test/lint/git-subtree-check.sh src/leveldb test/lint/git-subtree-check.sh src/crc32c + test/lint/git-subtree-check.sh src/chiabls test/lint/check-doc.py test/lint/logprint-scanner.py test/lint/lint-all.sh @@ -327,8 +328,8 @@ jobs: functional_tests: false no_depends: 1 goal: deploy - cc: $(brew --prefix llvm)/bin/clang - cxx: $(brew --prefix llvm)/bin/clang++ + cc: clang + cxx: clang++ BITCOIN_CONFIG: "--enable-zmq --enable-gui --enable-reduce-exports --enable-werror" steps: diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d83473e36199..87a9aa1628d1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.14) # Search for and use ccache if available to speed up build times find_program(CCACHE_PROGRAM ccache) @@ -148,6 +148,9 @@ set(LEVELDB_BUILD_BENCHMARKS OFF CACHE BOOL "Build LevelDB's benchmarks" FORCE) set(LEVELDB_INSTALL OFF CACHE BOOL "Install LevelDB's header and library" FORCE) add_subdirectory(${CMAKE_SOURCE_DIR}/src/leveldb) +add_subdirectory(${CMAKE_SOURCE_DIR}/src/chiabls) +FetchContent_GetProperties(relic) + file(GLOB HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h) file(GLOB CRYPTO_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/crypto/*.h) file(GLOB PRIMITIVE_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/primitives/*.h) @@ -238,6 +241,9 @@ target_include_directories(SERVER_A PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src/leveldb/include ${CMAKE_CURRENT_SOURCE_DIR}/src/leveldb/helpers/memenv ${CMAKE_CURRENT_SOURCE_DIR}/src/rust/include + ${CMAKE_CURRENT_SOURCE_DIR}/src/chiabls/src + ${relic_SOURCE_DIR}/include + ${relic_BINARY_DIR}/include ${ZMQ_INCLUDE_DIR} ${LIBEVENT_INCLUDE_DIR} ${BerkeleyDB_INCLUDE_DIRS} ) @@ -400,6 +406,9 @@ target_include_directories(COMMON_A PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src/secp256k1/include ${CMAKE_CURRENT_SOURCE_DIR}/src/leveldb/include ${CMAKE_CURRENT_SOURCE_DIR}/src/univalue/include + ${CMAKE_CURRENT_SOURCE_DIR}/src/chiabls/src + ${relic_SOURCE_DIR}/include + ${relic_BINARY_DIR}/include ${BerkeleyDB_INCLUDE_DIRS} ) @@ -478,7 +487,7 @@ if($ENV{target} MATCHES "Windows") list(APPEND pivx-cli_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/pivx-cli-res.rc) endif() add_executable(pivx-cli ${pivx-cli_SOURCES}) -add_dependencies(pivx-cli libunivalue libzcashrust) +add_dependencies(pivx-cli libunivalue libzcashrust bls) target_link_libraries(pivx-cli CLI_A univalue @@ -486,6 +495,7 @@ target_link_libraries(pivx-cli BITCOIN_CRYPTO_A SAPLING_A rustzcash + bls ${Boost_LIBRARIES} ${LIBEVENT_LIB} ${sodium_LIBRARY_RELEASE} -ldl pthread ) if($ENV{target} MATCHES "Windows") @@ -500,7 +510,7 @@ if($ENV{target} MATCHES "Windows") list(APPEND pivx-tx_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/pivx-tx-res.rc) endif() add_executable(pivx-tx ${pivx-tx_SOURCES}) -add_dependencies(pivx-tx libunivalue libsecp256k1 libzcashrust) +add_dependencies(pivx-tx libunivalue libsecp256k1 libzcashrust bls) target_link_libraries(pivx-tx univalue COMMON_A @@ -508,6 +518,7 @@ target_link_libraries(pivx-tx UTIL_A BITCOIN_CRYPTO_A secp256k1 + bls SAPLING_A rustzcash ${Boost_LIBRARIES} ${LIBEVENT_LIB} ${sodium_LIBRARY_RELEASE} ${GMP_LIBRARY} -ldl pthread @@ -524,7 +535,7 @@ if($ENV{target} MATCHES "Windows") list(APPEND pivxd_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/pivxd-res.rc) endif() add_executable(pivxd ${pivxd_SOURCES} ${BitcoinHeaders}) -add_dependencies(pivxd libunivalue libsecp256k1 libzcashrust leveldb crc32c) +add_dependencies(pivxd libunivalue libsecp256k1 libzcashrust leveldb crc32c bls) target_include_directories(pivxd PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src/leveldb ${CMAKE_CURRENT_SOURCE_DIR}/src/leveldb/include @@ -544,6 +555,7 @@ target_link_libraries(pivxd leveldb crc32c secp256k1 + bls rustzcash ${BerkeleyDB_LIBRARIES} ${Boost_LIBRARIES} ${LIBEVENT_LIB} ${GMP_LIBRARY} pthread ) diff --git a/configure.ac b/configure.ac index 87b85e6998c48..85806162b42f3 100644 --- a/configure.ac +++ b/configure.ac @@ -1590,6 +1590,8 @@ if test x$need_bundled_univalue = xyes; then AC_CONFIG_SUBDIRS([src/univalue]) fi +AC_CONFIG_SUBDIRS([src/chiabls]) + ac_configure_args="${ac_configure_args} --disable-shared --with-pic --with-bignum=no --enable-module-recovery --disable-jni" AC_CONFIG_SUBDIRS([src/secp256k1]) @@ -1614,6 +1616,10 @@ case ${OS} in ;; esac +dnl Remove conflicting preprocessor defines from relic configuration header +sed -i.old '/PACKAGE/d' src/chiabls/contrib/relic/include/relic_conf.h +sed -i.old '/#define VERSION/d' src/chiabls/contrib/relic/include/relic_conf.h + echo echo "Options used to compile and link:" echo " with wallet = $enable_wallet" diff --git a/contrib/cmake/FindSodium.cmake b/contrib/cmake/FindSodium.cmake index b38c994e34a7b..a89daae9eb2f3 100644 --- a/contrib/cmake/FindSodium.cmake +++ b/contrib/cmake/FindSodium.cmake @@ -254,7 +254,9 @@ if(sodium_USE_STATIC_LIBS) else() set(_LIB_TYPE SHARED) endif() -add_library(sodium ${_LIB_TYPE} IMPORTED) +if(NOT TARGET sodium) + add_library(sodium ${_LIB_TYPE} IMPORTED) +endif() set_target_properties(sodium PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${sodium_INCLUDE_DIR}" diff --git a/src/Makefile.am b/src/Makefile.am index d8127631bab0d..3301d87f3f0e5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,7 +2,7 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. -DIST_SUBDIRS = secp256k1 univalue +DIST_SUBDIRS = secp256k1 univalue chiabls AM_LDFLAGS = $(PTHREAD_CFLAGS) $(LIBTOOL_LDFLAGS) $(HARDENED_LDFLAGS) $(GPROF_LDFLAGS) $(SANITIZER_LDFLAGS) AM_CXXFLAGS = $(DEBUG_CXXFLAGS) $(HARDENED_CXXFLAGS) $(WARN_CXXFLAGS) $(NOWARN_CXXFLAGS) $(ERROR_CXXFLAGS) $(GPROF_CXXFLAGS) $(SANITIZER_CXXFLAGS) @@ -24,6 +24,8 @@ BITCOIN_INCLUDES=-I$(builddir) -I$(builddir)/obj $(BDB_CPPFLAGS) $(BOOST_CPPFLAG BITCOIN_INCLUDES += -I$(srcdir)/rust/include BITCOIN_INCLUDES += -I$(srcdir)/secp256k1/include +BITCOIN_INCLUDES += -I$(srcdir)/chiabls/src +BITCOIN_INCLUDES += -I$(srcdir)/chiabls/contrib/relic/include BITCOIN_INCLUDES += $(UNIVALUE_CFLAGS) LIBBITCOIN_SERVER=libbitcoin_server.a @@ -35,6 +37,7 @@ LIBBITCOIN_ZEROCOIN=libzerocoin/libbitcoin_zerocoin.a LIBBITCOINQT=qt/libbitcoinqt.a LIBSECP256K1=secp256k1/libsecp256k1.la LIBSAPLING=libsapling.a +LIBCHIABLS=chiabls/libchiabls.la if ENABLE_ONLINE_RUST LIBRUSTZCASH=$(top_builddir)/target/release/librustzcash.a else @@ -51,6 +54,8 @@ if ENABLE_WALLET LIBBITCOIN_WALLET=libbitcoin_wallet.a endif +BLS_LIBS = $(LIBCHIABLS) + RUST_ENV_VARS = RUSTC="$(RUSTC)" TERM=dumb RUST_BUILD_OPTS = --release @@ -96,6 +101,9 @@ endif $(LIBSECP256K1): $(wildcard secp256k1/src/*.h) $(wildcard secp256k1/src/*.c) $(wildcard secp256k1/include/*) $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F) +$(LIBCHIABLS): + $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C chiabls + # Make is not made aware of per-object dependencies to avoid limiting building parallelization # But to build the less dependent modules first, we manually select their order here: EXTRA_LIBRARIES += \ @@ -629,7 +637,7 @@ pivxd_LDADD = \ $(LIBRUSTZCASH) \ $(LIBZCASH_LIBS) -pivxd_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(ZMQ_LIBS) +pivxd_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(ZMQ_LIBS) $(BLS_LIBS) # pivx-cli binary # pivx_cli_SOURCES = pivx-cli.cpp @@ -650,7 +658,7 @@ pivx_cli_LDADD = \ $(LIBRUSTZCASH) \ $(LIBZCASH_LIBS) -pivx_cli_LDADD += $(BOOST_LIBS) $(EVENT_LIBS) +pivx_cli_LDADD += $(BOOST_LIBS) $(EVENT_LIBS) $(BLS_LIBS) # # pivx-tx binary # @@ -674,7 +682,7 @@ pivx_tx_LDADD = \ $(LIBRUSTZCASH) \ $(LIBZCASH_LIBS) -pivx_tx_LDADD += $(BOOST_LIBS) +pivx_tx_LDADD += $(BOOST_LIBS) $(BLS_LIBS) # # bitcoinconsensus library # @@ -702,7 +710,7 @@ if GLIBC_BACK_COMPAT endif libbitcoinconsensus_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS) -libbitcoinconsensus_la_LIBADD = $(LIBSECP256K1) +libbitcoinconsensus_la_LIBADD = $(LIBSECP256K1) $(BLS_LIBS) libbitcoinconsensus_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL libbitcoinconsensus_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) @@ -758,6 +766,7 @@ $(top_srcdir)/$(subdir)/config/pivx-config.h.in: $(am__configure_deps) clean-local: -$(MAKE) -C secp256k1 clean -$(MAKE) -C univalue clean + -$(MAKE) -C chiabls clean -rm -f leveldb/*/*.gcda leveldb/*/*.gcno leveldb/helpers/memenv/*.gcda leveldb/helpers/memenv/*.gcno -rm -f config.h -rm -rf test/__pycache__ diff --git a/src/Makefile.bench.include b/src/Makefile.bench.include index c48539d12a53f..577e408226aed 100644 --- a/src/Makefile.bench.include +++ b/src/Makefile.bench.include @@ -54,7 +54,7 @@ if ENABLE_ZMQ bench_bench_pivx_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS) endif -bench_bench_pivx_LDADD += $(LIBBITCOIN_CONSENSUS) $(BOOST_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) +bench_bench_pivx_LDADD += $(LIBBITCOIN_CONSENSUS) $(BOOST_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(BLS_LIBS) bench_bench_pivx_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) CLEAN_BITCOIN_BENCH = bench/*.gcda bench/*.gcno $(GENERATED_BENCH_FILES) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index d473c0419e86a..29a14521b4fb8 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -648,7 +648,7 @@ qt_pivx_qt_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS) endif qt_pivx_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBBITCOIN_ZEROCOIN) $(LIBSAPLING) $(LIBRUSTZCASH) $(LIBZCASH_LIBS) $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) \ $(BOOST_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(SVG_LIBS) $(CHARTS_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(LIBSECP256K1) \ - $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) + $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(BLS_LIBS) qt_pivx_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) qt_pivx_qt_LIBTOOLFLAGS = $(AM_LIBTOOLFLAGS) --tag CXX diff --git a/src/Makefile.qttest.include b/src/Makefile.qttest.include index fe2be2add0c8c..63dc762c28048 100644 --- a/src/Makefile.qttest.include +++ b/src/Makefile.qttest.include @@ -29,7 +29,7 @@ endif qt_test_test_pivx_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBBITCOIN_ZEROCOIN) $(LIBLEVELDB) $(LIBSAPLING) $(LIBRUSTZCASH) $(LIBZCASH_LIBS) \ $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) $(QT_LIBS) \ $(QR_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(LIBSECP256K1) \ - $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) + $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(BLS_LIBS) qt_test_test_pivx_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) qt_test_test_pivx_qt_CXXFLAGS = $(AM_CXXFLAGS) $(QT_PIE_FLAGS) diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 8874296e4d269..1e49626a9b309 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -187,7 +187,7 @@ test_test_pivx_LDADD += $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMM test_test_pivx_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -test_test_pivx_LDADD += $(LIBRUSTZCASH) $(LIBBITCOIN_CONSENSUS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(LIBZCASH_LIBS) +test_test_pivx_LDADD += $(LIBRUSTZCASH) $(LIBBITCOIN_CONSENSUS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(LIBZCASH_LIBS) $(BLS_LIBS) test_test_pivx_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static if ENABLE_ZMQ @@ -202,7 +202,7 @@ if ENABLE_ZMQ test_test_pivx_fuzzy_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS) endif test_test_pivx_fuzzy_LDADD += $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_ZEROCOIN) $(LIBBITCOIN_UTIL) $(LIBUNIVALUE) \ - $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(LIBSECP256K1) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS) + $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(LIBSECP256K1) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS) $(BLS_LIBS) if ENABLE_WALLET test_test_pivx_fuzzy_LDADD += $(LIBBITCOIN_WALLET) endif @@ -400,6 +400,7 @@ check-standard: $(BITCOIN_TESTS:.cpp=.cpp.test) $(PYTHON) $(top_builddir)/test/util/bitcoin-util-test.py @echo "Running test/util/rpcauth-test.py..." $(PYTHON) $(top_builddir)/test/util/rpcauth-test.py + $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C chiabls check $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C secp256k1 check if EMBEDDED_UNIVALUE $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C univalue check diff --git a/src/chiabls/.clang-format b/src/chiabls/.clang-format new file mode 100644 index 0000000000000..b2a45d8020465 --- /dev/null +++ b/src/chiabls/.clang-format @@ -0,0 +1,17 @@ +BasedOnStyle: Google +UseTab: Never +ColumnLimit: 80 +IndentWidth: 4 +TabWidth: 4 +AllowShortIfStatementsOnASingleLine: false +IndentCaseLabels: false +AccessModifierOffset: -4 +BinPackArguments: false +BinPackParameters: false +AlignAfterOpenBracket: AlwaysBreak +IndentCaseLabels: true +AllowAllParametersOfDeclarationOnNextLine: false +BreakBeforeBraces: Custom +BraceWrapping: + AfterFunction: true +PenaltyReturnTypeOnItsOwnLine: 1000 diff --git a/src/chiabls/.flake8 b/src/chiabls/.flake8 new file mode 100644 index 0000000000000..ccb1530562915 --- /dev/null +++ b/src/chiabls/.flake8 @@ -0,0 +1,4 @@ +[flake8] +max-line-length = 120 +exclude = ./typings/**/* python-impl/fields.py +ignore = E203,W503,E501 diff --git a/src/chiabls/.github/workflows/build-aarch64.yml b/src/chiabls/.github/workflows/build-aarch64.yml new file mode 100644 index 0000000000000..91ee2612eb406 --- /dev/null +++ b/src/chiabls/.github/workflows/build-aarch64.yml @@ -0,0 +1,131 @@ +name: Build ARM64 wheel + +on: [push, pull_request] + +jobs: + build_wheels: + name: Build wheel on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ARM64] + + steps: + - name: Cancel previous runs on the same branch + if: ${{ github.ref != 'refs/heads/main' }} + uses: styfle/cancel-workflow-action@0.7.0 + with: + access_token: ${{ github.token }} + + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Prepare cibuildwheel + run: | + if [ ! -f "venv" ]; then rm -rf venv; fi + sudo apt-get install python3-venv python3-pip -y + python3 -m venv venv + source venv/bin/activate + python -m pip install --upgrade pip + python -m pip install cibuildwheel==1.10.0 + + - name: Lint source with flake8 + run: | + source venv/bin/activate + pip install flake8 + flake8 src setup.py python-bindings python-impl + + - name: Lint source with mypy + run: | + source venv/bin/activate + pip install mypy + mypy --config-file mypi.ini python-bindings python-impl + + - name: Build wheels and test + run: | + source venv/bin/activate + python -m cibuildwheel --output-dir dist + env: + # build python 3.7 and 3.8 + CIBW_BUILD: cp37-* cp38-* cp39-* + CIBW_MANYLINUX_AARCH64_IMAGE: manylinux2014 + CIBW_BUILD_VERBOSITY_LINUX: 0 + CIBW_BEFORE_BUILD_LINUX: > + python -m pip install --upgrade pip + CIBW_BEFORE_ALL_LINUX: > + yum -y install epel-release + && yum -y install cmake3 lzip + && rm -rf /usr/local/bin/cmake + && ln -s /usr/bin/cmake3 /usr/local/bin/cmake + && cmake --version + && curl -L https://gmplib.org/download/gmp/gmp-6.2.1.tar.lz | lzip -dc | tar x + && cd gmp-6.2.1 && ./configure --enable-fat + && make && make install && cd .. && rm -rf gmp-6.2.1 + && curl -L https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable.tar.gz | tar xz + && cd libsodium-stable && ./configure --with-pic="yes" + && make && make install && cd .. && rm -rf libsodium-stable + CIBW_TEST_REQUIRES: pytest + CIBW_TEST_COMMAND: pytest -v {project}/python-bindings/test.py + + - name: Create sha256 wheel hashes + run: | + mkdir hashes + cd ./dist + shasum -a 256 * + shasum -a 256 * > ../hashes/blspy-arm64-wheels-sha256.txt + + - name: Upload hashes + uses: actions/upload-artifact@v2 + with: + name: blspy-arm64-hashes + path: ./hashes + + - name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + name: wheels + path: ./dist + + - name: Test for secrets access + id: check_secrets + shell: bash + run: | + unset HAS_SECRET + if [ -n "$SECRET" ]; then HAS_SECRET='true' ; fi + echo ::set-output name=HAS_SECRET::${HAS_SECRET} + env: + SECRET: "${{ secrets.test_pypi_password }}" + + - name: Install twine + run: | + source venv/bin/activate + pip install twine + + - name: Publish distribution to PyPI + if: startsWith(github.event.ref, 'refs/tags') && steps.check_secrets.outputs.HAS_SECRET + env: + TWINE_USERNAME: __token__ + TWINE_NON_INTERACTIVE: 1 + TWINE_PASSWORD: ${{ secrets.pypi_password }} + run: | + source venv/bin/activate + twine upload --non-interactive --skip-existing --verbose 'dist/*' + + - name: Publish distribution to Test PyPI + if: steps.check_secrets.outputs.HAS_SECRET + env: + TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/ + TWINE_USERNAME: __token__ + TWINE_NON_INTERACTIVE: 1 + TWINE_PASSWORD: ${{ secrets.test_pypi_password }} + run: | + source venv/bin/activate + twine upload --non-interactive --skip-existing --verbose 'dist/*' + + - name: Clean up + run: | + rm -rf venv + rm -rf dist diff --git a/src/chiabls/.github/workflows/build-autotools.yml b/src/chiabls/.github/workflows/build-autotools.yml new file mode 100644 index 0000000000000..1e5692493fc65 --- /dev/null +++ b/src/chiabls/.github/workflows/build-autotools.yml @@ -0,0 +1,90 @@ +name: Autotools build for bls-signatures + +on: [push, pull_request] + +jobs: + build: + name: ${{ matrix.config.name }} + runs-on: ${{ matrix.config.os }} + defaults: + run: + shell: bash + strategy: + fail-fast: false + matrix: + config: + - name: ARM 32-bit + os: ubuntu-18.04 + host: arm-linux-gnueabihf + arch: armhf + apt_get: gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf + arch_packages: libgmp-dev:armhf libsodium-dev:armhf + + - name: ARM 64-bit + os: ubuntu-18.04 + host: aarch64-linux-gnu + arch: arm64 + apt_get: gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + arch_packages: libgmp-dev:arm64 libsodium-dev:arm64 + + #- name: i686 Linux + # os: ubuntu-18.04 + # host: i686-pc-linux-gnu + # arch: armhf + # apt_get: gcc-multilib g++-multilib + # arch_packages: libgmp-dev:i386 libsodium-dev:i386 + + - name: x86_64 Linux + os: ubuntu-18.04 + host: x86_64-unknown-linux-gnu + arch: armhf # dummy arch + apt_get: gcc-multilib g++-multilib + arch_packages: libgmp-dev libsodium-dev + unit_tests: true + + - name: x86_64 MacOS + os: macos-10.15 + host: x86_64-apple-darwin19.6.0 + brew_install: autoconf automake libtool gmp libsodium + cc: clang + cxx: clang++ + unit_tests: true + + steps: + - name: Get Source + uses: actions/checkout@v2 + + - name: Setup Arches + if: matrix.config.arch + uses: ryankurte/action-apt@v0.3.0 + with: + arch: ${{ matrix.config.arch }} + packages: ${{ matrix.config.arch_packages }} + + - name: Setup Environment + run: | + if [[ ${{ matrix.config.os }} = ubuntu* ]]; then + sudo apt-get --yes update + sudo apt-get install --no-install-recommends --no-upgrade -qq ${{ matrix.config.apt_get }} + fi + if [[ ${{ matrix.config.os }} = macos* ]]; then + brew install ${{ matrix.config.brew_install }} + fi + + - name: Build + run: | + if [[ ${{ matrix.config.os }} = macos* ]]; then + CC=${{ matrix.config.cc }} + CXX=${{ matrix.config.cxx }} + export CC + export CXX + fi + + ./autogen.sh + ./configure --host=${{ matrix.config.host }} || ( cat config.log && false) + make -j2 || ( echo "Build failure. Verbose build follows." && make V=1 ; false ) + + if [ "${{ matrix.config.unit_tests }}" = "true" ]; then + make -j2 check + fi + diff --git a/src/chiabls/.github/workflows/build-test.yaml b/src/chiabls/.github/workflows/build-test.yaml new file mode 100644 index 0000000000000..2fe51296cbbf1 --- /dev/null +++ b/src/chiabls/.github/workflows/build-test.yaml @@ -0,0 +1,82 @@ +name: Build and Test C++, Javascript, and Python + +on: [push, pull_request] + +jobs: + build_wheels: + name: Build and Test on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-latest, ubuntu-latest] + + steps: + - name: Cancel previous runs on the same branch + if: ${{ github.ref != 'refs/heads/main' }} + uses: styfle/cancel-workflow-action@0.7.0 + with: + access_token: ${{ github.token }} + + - name: Checkout code + uses: actions/checkout@v2 + + - uses: actions/setup-python@v2 + name: Install Python + with: + python-version: '3.8' + + - name: Ubuntu build C++ and test with valgrind + if: startsWith(matrix.os, 'ubuntu') + run: | + sudo apt-get update + sudo apt-get install valgrind -y + sudo apt-get install snap -y + sudo apt-get remove --purge cmake -y + sudo snap install cmake --classic + hash -r + cmake --version + echo "attempting to curl" + curl -L https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable.tar.gz | tar xz + echo "curl complete." + cd libsodium-stable + ls -l + ./configure --with-pic="yes" + make + sudo make install + cd .. + echo "Setting libsodium to static compile." + export CIBUILDWHEEL=1 + mkdir -p build + cd build + cmake ../ + cmake --build . -- -j 6 + echo "Running ./src/runtest" + ./src/runtest + valgrind --leak-check=full --show-leak-kinds=all --errors-for-leak-kinds=all ./src/runtest + + - name: Mac OS build C++ and test + if: startsWith(matrix.os, 'macos') + run: | + ls -l + export MACOSX_DEPLOYMENT_TARGET=10.14 + mkdir -p build + ls -l build + cd build + cmake ../ + cmake --build . -- -j 6 + echo "Running ./src/runtest" + ./src/runtest + + - name: Test pure python implementation + run: | + python python-impl/impl-test.py + + - name: Install emsdk + uses: mymindstorm/setup-emsdk@v9 + + - name: Test javascript bindings + run: | + emcc -v + sh emsdk_build.sh + sh js_test.sh diff --git a/src/chiabls/.github/workflows/build-wheels.yml b/src/chiabls/.github/workflows/build-wheels.yml new file mode 100644 index 0000000000000..7abf5ca7fb09a --- /dev/null +++ b/src/chiabls/.github/workflows/build-wheels.yml @@ -0,0 +1,175 @@ +name: Build wheels + +on: [push, pull_request] + +jobs: + build_wheels: + name: Build wheel on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-latest, ubuntu-latest, windows-latest] + + steps: + - name: Cancel previous runs on the same branch + if: ${{ github.ref != 'refs/heads/main' }} + uses: styfle/cancel-workflow-action@0.7.0 + with: + access_token: ${{ github.token }} + + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - uses: actions/setup-python@v2 + name: Install Python + with: + python-version: '3.8' + + - name: Lint source with flake8 + run: | + python -m pip install --upgrade pip + pip install flake8 + flake8 src setup.py python-bindings python-impl + + - name: Lint source with mypy + run: | + pip install mypy + mypy --config-file mypi.ini python-bindings python-impl + + - name: Build source distribution with Ubuntu-latest + if: startsWith(matrix.os, 'ubuntu') + run: | + pip install build + python -m build --sdist --outdir dist . + + - name: Build ${{ matrix.os }} wheels and test + uses: joerick/cibuildwheel@v1.10.0 + with: + output-dir: dist + env: + CIBW_BUILD_VERBOSITY_MACOS: 0 + CIBW_BUILD_VERBOSITY_LINUX: 0 + CIBW_BUILD_VERBOSITY_WINDOWS: 0 + # Python 3.7 and 3.8 + CIBW_BUILD: cp37-* cp38-* cp39-* + CIBW_SKIP: '*-manylinux_i686 *-win32' + CIBW_TEST_REQUIRES: pytest + CIBW_MANYLINUX_X86_64_IMAGE: manylinux2010 + CIBW_ENVIRONMENT_LINUX: "PATH=/project/cmake-3.17.3-Linux-`uname -m`/bin:$PATH" + CIBW_BEFORE_ALL_LINUX: > + yum -y install epel-release + && yum -y install lzip + && curl -L https://github.com/Kitware/CMake/releases/download/v3.17.3/cmake-3.17.3-Linux-`uname -m`.sh > cmake.sh + && yes | sh cmake.sh | cat + && rm -f /usr/bin/cmake && hash -r + && which cmake + && cmake --version + && echo "curling GMP 6.2.1" + && curl -L https://gmplib.org/download/gmp/gmp-6.2.1.tar.lz | lzip -dc | tar x + && echo "Patching GMP for lzcnt" + && cp contrib/gmp-patch-6.2.1/longlong.h gmp-6.2.1/ + && cp contrib/gmp-patch-6.2.1/compat.c gmp-6.2.1/ + && echo "Building GMP" + && cd gmp-6.2.1 && ./configure --enable-fat + && make && make install && cd .. && rm -rf gmp-6.2.1 + && curl -L https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable.tar.gz | tar xz + && cd libsodium-stable && ./configure --with-pic="yes" + && make && make install && cd .. && rm -rf libsodium-stable + CIBW_BEFORE_BUID_LINUX: > + python -m pip install --upgrade pip + CIBW_ENVIRONMENT_MACOS: "MACOSX_DEPLOYMENT_TARGET=10.14" + # GH hosted MacOS runner has gmp and libsodium natively + # CIBW_ARCHS_MACOS: x86_64 arm64 universal2 + CIBW_ARCHS_MACOS: x86_64 + CIBW_TEST_SKIP: '*_arm64 *_universal2:arm64' + CIBW_BEFORE_BUILD_MACOS: > + python -m pip install --upgrade pip + CIBW_REPAIR_WHEEL_COMMAND_MACOS: > + pip uninstall -y delocate + && pip install git+https://github.com/Chia-Network/delocate.git + && delocate-listdeps {wheel} + && delocate-wheel -v {wheel} + && cp {wheel} {dest_dir} + CIBW_BEFORE_ALL_WINDOWS: > + curl -L https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable-msvc.zip > libsodium-1.0.18-stable-msvc.zip + && 7z x libsodium-1.0.18-stable-msvc.zip + && git clone https://github.com/Chia-Network/relic_ietf_64.git + && ls -l relic_ietf_64 + && git clone https://github.com/Chia-Network/mpir_gc_x64.git + && ls -l mpir_gc_x64 + CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: > + pip uninstall -y delocate + && pip install git+https://github.com/Chia-Network/delocate.git + && delocate-wheel -v -i mpir_gc_x64/mpir.dll {wheel} + && delocate-wheel -v -i mpir_gc_x64/mpir_gc.dll {wheel} + && delocate-wheel -v -i mpir_gc_x64/mpir_broadwell.dll {wheel} + && delocate-wheel -v -i mpir_gc_x64/mpir_broadwell_avx.dll {wheel} + && delocate-wheel -v -i mpir_gc_x64/mpir_bulldozer.dll {wheel} + && delocate-wheel -v -i mpir_gc_x64/mpir_haswell.dll {wheel} + && delocate-wheel -v -i mpir_gc_x64/mpir_piledriver.dll {wheel} + && delocate-wheel -v -i mpir_gc_x64/mpir_sandybridge.dll {wheel} + && delocate-wheel -v -i mpir_gc_x64/mpir_skylake_avx.dll {wheel} + && cp {wheel} {dest_dir} && ls -l {dest_dir} + # CIBW_ENVIRONMENT_WINDOWS: "" + CIBW_TEST_COMMAND: pytest -v {project}/python-bindings/test.py + + - name: Create sha256 wheel hashes + if: startsWith(runner.os, 'linux') || startsWith(runner.os, 'windows') + run: | + mkdir hashes + cd ./dist + sha256sum * + sha256sum * > ../hashes/wheel-sha256.txt + + - name: Create sha256 wheel hashes - MacOS + if: startsWith(runner.os, 'macos') + run: | + mkdir hashes + cd ./dist + shasum -a 256 * + shasum -a 256 * > ../hashes/blspy-wheels-sha256.txt + + - name: Upload hashes + uses: actions/upload-artifact@v2 + with: + name: blspy-hashes + path: ./hashes + + - name: Upload wheels + uses: actions/upload-artifact@v2 + with: + name: wheels + path: ./dist + + - name: Test for secrets access + id: check_secrets + shell: bash + run: | + unset HAS_SECRET + if [ -n "$SECRET" ]; then HAS_SECRET='true' ; fi + echo ::set-output name=HAS_SECRET::${HAS_SECRET} + env: + SECRET: "${{ secrets.test_pypi_password }}" + + - name: Install twine + run: pip install twine + + - name: Publish distribution to PyPI + if: startsWith(github.event.ref, 'refs/tags') && steps.check_secrets.outputs.HAS_SECRET + env: + TWINE_USERNAME: __token__ + TWINE_NON_INTERACTIVE: 1 + TWINE_PASSWORD: ${{ secrets.pypi_password }} + run: twine upload --non-interactive --skip-existing --verbose 'dist/*' + + - name: Publish distribution to Test PyPI + if: steps.check_secrets.outputs.HAS_SECRET + env: + TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/ + TWINE_USERNAME: __token__ + TWINE_NON_INTERACTIVE: 1 + TWINE_PASSWORD: ${{ secrets.test_pypi_password }} + run: twine upload --non-interactive --skip-existing --verbose 'dist/*' diff --git a/src/chiabls/.github/workflows/relic-nightly.yml b/src/chiabls/.github/workflows/relic-nightly.yml new file mode 100644 index 0000000000000..f991cd14aa4d2 --- /dev/null +++ b/src/chiabls/.github/workflows/relic-nightly.yml @@ -0,0 +1,57 @@ +name: Build and Test C++ with Relic Nightly + +on: + schedule: + - cron: "0 11 * * *" + workflow_dispatch: + +jobs: + build_wheels: + name: Build and Test C++ with Relic Nightly + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + + steps: + - name: Cancel previous runs on the same branch + if: ${{ github.ref != 'refs/heads/main' }} + uses: styfle/cancel-workflow-action@0.7.0 + with: + access_token: ${{ github.token }} + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Ubuntu build C++ and test Relic at origin/main + if: startsWith(matrix.os, 'ubuntu') + run: | + echo "Relic origin/main commit:" + curl -H "application/vnd.github.v3.sha" \ + https://api.github.com/repos/relic-toolkit/relic/commits/main | \ + head -10 + sudo apt-get update + sudo apt-get install snap -y + sudo apt-get remove --purge cmake -y + sudo snap install cmake --classic + hash -r + cmake --version + echo "attempting to curl" + curl -L https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable.tar.gz | tar xz + echo "curl complete." + cd libsodium-stable + ls -l + ./configure --with-pic="yes" + make + sudo make install + cd .. + echo "Setting libsodium to static compile." + export CIBUILDWHEEL=1 + export RELIC_MAIN=1 + mkdir -p build + cd build + cmake ../ + cmake --build . -- -j 6 + echo "Running ./src/runtest" + ./src/runtest diff --git a/src/chiabls/.gitignore b/src/chiabls/.gitignore new file mode 100644 index 0000000000000..0048d5f588dbd --- /dev/null +++ b/src/chiabls/.gitignore @@ -0,0 +1,94 @@ +CMakeCache.txt +CMakeFiles +cmake_install.cmake +cmake-build*/ +Makefile +src/bench +src/test +src/MakefilE +src/cmake_install.cmake +src/CMakeFile +build/* +blspy.egg-info +dist +python-impl/__pycache__/ +blspy.*.so +.mypy_cache/ +.pytest_chache/ + +js_build +node_modules + +main +.o +obj/ +src/*.o +contrib/relic/CTestTestfile.cmake +contrib/relic/bench/CTestTestfile.cmake +contrib/relic/bin +contrib/relic/include/relic_conf.h +contrib/relic/test/CTestTestfile.cmake +contrib/gmp-6.1.2/ +contrib/libsodium-1.0.16/ + +.idea +.vscode +blstest +blstest.* +blsbench +blsbench.* + +.deps +.dirstamp +.libs +.*.swp +*.*~* +*.bak +*.rej +*.orig +*.pyc +*.o +*.o-* +*.patch +*.a +*.pb.cc +*.pb.h +*.Po +*.lo +*.la + +runbench +runtest + +**/.DS_Store + +*.whl +venv +yarn-error.log +/.project + +# autoreconf +Makefile.in +aclocal.m4 +autom4te.cache/ +build-aux/config.guess +build-aux/config.sub +build-aux/depcomp +build-aux/install-sh +build-aux/ltmain.sh +build-aux/m4/libtool.m4 +build-aux/m4/lt~obsolete.m4 +build-aux/m4/ltoptions.m4 +build-aux/m4/ltsugar.m4 +build-aux/m4/ltversion.m4 +build-aux/missing +build-aux/compile +build-aux/test-driver +config.log +config.status +configure +confdefs.h +conftest.cpp +conftest.err +libtool +contrib/relic/include/stamp-h1 diff --git a/src/chiabls/CMakeLists.txt b/src/chiabls/CMakeLists.txt new file mode 100644 index 0000000000000..df0abe13f1ef9 --- /dev/null +++ b/src/chiabls/CMakeLists.txt @@ -0,0 +1,95 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 3.14.0 FATAL_ERROR) +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +IF(NOT CMAKE_BUILD_TYPE) + SET(CMAKE_BUILD_TYPE "RELEASE") +ENDIF() + +project(BLS) + +set(BUILD_BLS_TESTS 1 CACHE INTEGER "") +set(BUILD_BLS_BENCHMARKS 1 CACHE INTEGER "") + +message(STATUS "Build tests: ${BUILD_BLS_TESTS}") +message(STATUS "Build benchmarks: ${BUILD_BLS_BENCHMARKS}") + +# Add path for custom modules +set(CMAKE_MODULE_PATH + ${CMAKE_MODULE_PATH} + ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules +) + +find_package(sodium) +if (SODIUM_FOUND) + message(STATUS "Found libsodium") + message(STATUS "Sodium include dir = ${sodium_INCLUDE_DIR}") + set(BLSALLOC_SODIUM "1" CACHE STRING "") + include_directories(${sodium_INCLUDE_DIR}) +endif() + +find_package(gmp) +if (GMP_FOUND) + message(STATUS "Found libgmp") + include_directories(${GMP_INCLUDE_DIR}) + set(ARITH "gmp" CACHE STRING "") +else() + set(ARITH "easy" CACHE STRING "") +endif() + +if(EMSCRIPTEN) + # emscripten needs arch set to be none since it can't compile assembly + set(ARCH "" CACHE STRING "") + # emscripten is a 32 bit compiler + set(WSIZE 32 CACHE INTEGER "") +else() + set(WSIZE 64 CACHE INTEGER "") +endif() + +set(TIMER "CYCLE" CACHE STRING "") +set(CHECK "off" CACHE STRING "") +set(VERBS "off" CACHE STRING "") +set(ALLOC "AUTO" CACHE STRING "") +set(SHLIB "OFF" CACHE STRING "") +set(MULTI "PTHREAD" CACHE STRING "") +set(DOCUM "off" CACHE STRING "") + +set(FP_PRIME 381 CACHE INTEGER "") + +IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(SEED "UDEV" CACHE STRING "") + set(FP_QNRES "off" CACHE STRING "") +ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Windows") + set(SEED "WCGR" CACHE STRING "") + set(FP_QNRES "on" CACHE STRING "") +ELSE() + set(SEED "UDEV" CACHE STRING "") + set(FP_QNRES "on" CACHE STRING "") +ENDIF() +set(STBIN "OFF" CACHE STRING "") + +set(FP_METHD "INTEG;INTEG;INTEG;MONTY;LOWER;SLIDE" CACHE STRING "") +set(CFLAGS "-O3 -funroll-loops -fomit-frame-pointer" CACHE STRING "") +set(FP_PMERS "off" CACHE STRING "") +set(FPX_METHD "INTEG;INTEG;LAZYR" CACHE STRING "") +set(EP_PLAIN "off" CACHE STRING "") +set(EP_SUPER "off" CACHE STRING "") +# Disable relic tests and benchmarks +set(TESTS 0 CACHE INTEGER "") +set(BENCH 0 CACHE INTEGER "") +set(QUIET 1 CACHE INTEGER "") + +set(PP_EXT "LAZYR" CACHE STRING "") +set(PP_METHD "LAZYR;OATEP" CACHE STRING "") + +add_subdirectory(src) + +if (EMSCRIPTEN) + add_subdirectory(js-bindings) +else() + # emscripten can't build python bindings, it produces only javascript + # add_subdirectory(contrib/pybind11) + if (BUILD_BLS_PYTHON_BINDINGS) + add_subdirectory(python-bindings) + endif() +endif() diff --git a/src/chiabls/LICENSE b/src/chiabls/LICENSE new file mode 100644 index 0000000000000..f433b1a53f5b8 --- /dev/null +++ b/src/chiabls/LICENSE @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/src/chiabls/MANIFEST.in b/src/chiabls/MANIFEST.in new file mode 100644 index 0000000000000..3063e7883b3c4 --- /dev/null +++ b/src/chiabls/MANIFEST.in @@ -0,0 +1,6 @@ +include README.md LICENSE +global-include CMakeLists.txt *.cmake +recursive-include cmake_modules * +recursive-include src * +recursive-include python-bindings * +recursive-include contrib * \ No newline at end of file diff --git a/src/chiabls/Makefile.am b/src/chiabls/Makefile.am new file mode 100644 index 0000000000000..bf89018399f7f --- /dev/null +++ b/src/chiabls/Makefile.am @@ -0,0 +1,460 @@ +ACLOCAL_AMFLAGS = -I build-aux/m4 + +AM_CPPFLAGS = $(GMP_CPPFLAGS) $(SODIUM_CPPFLAGS) +AM_LDFLAGS = $(PTHREAD_CFLAGS) $(LIBTOOL_LDFLAGS) + +LIBRELIC = librelic.la +LIBCHIABLS = libchiabls.la + +noinst_PROGRAMS = +EXTRA_DIST = + +RELIC_INCLUDES = -I$(top_srcdir)/contrib/relic/include -I$(top_srcdir)/contrib/relic/include/low -I$(top_srcdir)/contrib/relic/src/tmpl +CHIABLS_INCLUDES = -I$(builddir) -I$(builddir)/obj -I$(top_srcdir)/src $(RELIC_INCLUDES) + +lib_LTLIBRARIES = $(LIBCHIABLS) +noinst_LTLIBRARIES = $(LIBRELIC) + +RELIC_H = \ + contrib/relic/include/relic.h \ + contrib/relic/include/relic_alloc.h \ + contrib/relic/include/relic_arch.h \ + contrib/relic/include/relic_bc.h \ + contrib/relic/include/relic_bench.h \ + contrib/relic/include/relic_bn.h \ + contrib/relic/include/relic_conf.h \ + contrib/relic/include/relic_core.h \ + contrib/relic/include/relic_cp.h \ + contrib/relic/include/relic_dv.h \ + contrib/relic/include/relic_eb.h \ + contrib/relic/include/relic_ec.h \ + contrib/relic/include/relic_ed.h \ + contrib/relic/include/relic_ep.h \ + contrib/relic/include/relic_epx.h \ + contrib/relic/include/relic_err.h \ + contrib/relic/include/relic_fb.h \ + contrib/relic/include/relic_fbx.h \ + contrib/relic/include/relic_fp.h \ + contrib/relic/include/relic_fpx.h \ + contrib/relic/include/relic_label.h \ + contrib/relic/include/relic_md.h \ + contrib/relic/include/relic_mpc.h \ + contrib/relic/include/relic_multi.h \ + contrib/relic/include/relic_pc.h \ + contrib/relic/include/relic_pp.h \ + contrib/relic/include/relic_rand.h \ + contrib/relic/include/relic_test.h \ + contrib/relic/include/relic_types.h \ + contrib/relic/include/relic_util.h \ + contrib/relic/include/low/relic_bn_low.h \ + contrib/relic/include/low/relic_dv_low.h \ + contrib/relic/include/low/relic_fb_low.h \ + contrib/relic/include/low/relic_fp_low.h \ + contrib/relic/include/low/relic_fpx_low.h \ + contrib/relic/src/arch/lzcnt.inc \ + contrib/relic/src/tmpl/relic_tmpl_map.h + +RELIC_SRCS = \ + contrib/relic/src/relic_err.c \ + contrib/relic/src/relic_core.c \ + contrib/relic/src/relic_conf.c \ + contrib/relic/src/relic_util.c + +BN_SRCS = \ + contrib/relic/src/bn/relic_bn_add.c \ + contrib/relic/src/bn/relic_bn_cmp.c \ + contrib/relic/src/bn/relic_bn_div.c \ + contrib/relic/src/bn/relic_bn_factor.c \ + contrib/relic/src/bn/relic_bn_gcd.c \ + contrib/relic/src/bn/relic_bn_inv.c \ + contrib/relic/src/bn/relic_bn_lcm.c \ + contrib/relic/src/bn/relic_bn_mem.c \ + contrib/relic/src/bn/relic_bn_mod.c \ + contrib/relic/src/bn/relic_bn_mul.c \ + contrib/relic/src/bn/relic_bn_mxp.c \ + contrib/relic/src/bn/relic_bn_prime.c \ + contrib/relic/src/bn/relic_bn_rec.c \ + contrib/relic/src/bn/relic_bn_shift.c \ + contrib/relic/src/bn/relic_bn_smb.c \ + contrib/relic/src/bn/relic_bn_sqr.c \ + contrib/relic/src/bn/relic_bn_srt.c \ + contrib/relic/src/bn/relic_bn_util.c + +FP_SRCS = \ + contrib/relic/src/fp/relic_fp_add.c \ + contrib/relic/src/fp/relic_fp_cmp.c \ + contrib/relic/src/fp/relic_fp_exp.c \ + contrib/relic/src/fp/relic_fp_inv.c \ + contrib/relic/src/fp/relic_fp_mul.c \ + contrib/relic/src/fp/relic_fp_param.c \ + contrib/relic/src/fp/relic_fp_prime.c \ + contrib/relic/src/fp/relic_fp_rdc.c \ + contrib/relic/src/fp/relic_fp_shift.c \ + contrib/relic/src/fp/relic_fp_sqr.c \ + contrib/relic/src/fp/relic_fp_srt.c \ + contrib/relic/src/fp/relic_fp_util.c + +FPX_SRCS = \ + contrib/relic/src/fpx/relic_fp2_mul.c \ + contrib/relic/src/fpx/relic_fp2_sqr.c \ + contrib/relic/src/fpx/relic_fp3_mul.c \ + contrib/relic/src/fpx/relic_fp3_sqr.c \ + contrib/relic/src/fpx/relic_fp4_mul.c \ + contrib/relic/src/fpx/relic_fp4_sqr.c \ + contrib/relic/src/fpx/relic_fp6_mul.c \ + contrib/relic/src/fpx/relic_fp6_sqr.c \ + contrib/relic/src/fpx/relic_fp8_mul.c \ + contrib/relic/src/fpx/relic_fp8_sqr.c \ + contrib/relic/src/fpx/relic_fp9_mul.c \ + contrib/relic/src/fpx/relic_fp9_sqr.c \ + contrib/relic/src/fpx/relic_fp12_mul.c \ + contrib/relic/src/fpx/relic_fp12_sqr.c \ + contrib/relic/src/fpx/relic_fp18_mul.c \ + contrib/relic/src/fpx/relic_fp18_sqr.c \ + contrib/relic/src/fpx/relic_fp24_mul.c \ + contrib/relic/src/fpx/relic_fp24_sqr.c \ + contrib/relic/src/fpx/relic_fp48_mul.c \ + contrib/relic/src/fpx/relic_fp48_sqr.c \ + contrib/relic/src/fpx/relic_fp54_mul.c \ + contrib/relic/src/fpx/relic_fp54_sqr.c \ + contrib/relic/src/fpx/relic_fpx_add.c \ + contrib/relic/src/fpx/relic_fpx_cmp.c \ + contrib/relic/src/fpx/relic_fpx_cyc.c \ + contrib/relic/src/fpx/relic_fpx_exp.c \ + contrib/relic/src/fpx/relic_fpx_field.c \ + contrib/relic/src/fpx/relic_fpx_frb.c \ + contrib/relic/src/fpx/relic_fpx_inv.c \ + contrib/relic/src/fpx/relic_fpx_pck.c \ + contrib/relic/src/fpx/relic_fpx_rdc.c \ + contrib/relic/src/fpx/relic_fpx_srt.c \ + contrib/relic/src/fpx/relic_fpx_util.c + +FB_SRCS = \ + contrib/relic/src/fb/relic_fb_add.c \ + contrib/relic/src/fb/relic_fb_cmp.c \ + contrib/relic/src/fb/relic_fb_exp.c \ + contrib/relic/src/fb/relic_fb_inv.c \ + contrib/relic/src/fb/relic_fb_itr.c \ + contrib/relic/src/fb/relic_fb_mul.c \ + contrib/relic/src/fb/relic_fb_param.c \ + contrib/relic/src/fb/relic_fb_poly.c \ + contrib/relic/src/fb/relic_fb_rdc.c \ + contrib/relic/src/fb/relic_fb_shift.c \ + contrib/relic/src/fb/relic_fb_slv.c \ + contrib/relic/src/fb/relic_fb_sqr.c \ + contrib/relic/src/fb/relic_fb_srt.c \ + contrib/relic/src/fb/relic_fb_trc.c \ + contrib/relic/src/fb/relic_fb_util.c + +EP_SRCS = \ + contrib/relic/src/ep/relic_ep_add.c \ + contrib/relic/src/ep/relic_ep_cmp.c \ + contrib/relic/src/ep/relic_ep_curve.c \ + contrib/relic/src/ep/relic_ep_dbl.c \ + contrib/relic/src/ep/relic_ep_map.c \ + contrib/relic/src/ep/relic_ep_mul.c \ + contrib/relic/src/ep/relic_ep_mul_fix.c \ + contrib/relic/src/ep/relic_ep_mul_sim.c \ + contrib/relic/src/ep/relic_ep_neg.c \ + contrib/relic/src/ep/relic_ep_norm.c \ + contrib/relic/src/ep/relic_ep_param.c \ + contrib/relic/src/ep/relic_ep_pck.c \ + contrib/relic/src/ep/relic_ep_psi.c \ + contrib/relic/src/ep/relic_ep_util.c + +EPX_SRCS = \ + contrib/relic/src/epx/relic_ep2_add.c \ + contrib/relic/src/epx/relic_ep2_cmp.c \ + contrib/relic/src/epx/relic_ep2_curve.c \ + contrib/relic/src/epx/relic_ep2_dbl.c \ + contrib/relic/src/epx/relic_ep2_frb.c \ + contrib/relic/src/epx/relic_ep2_map.c \ + contrib/relic/src/epx/relic_ep2_mul.c \ + contrib/relic/src/epx/relic_ep2_mul_cof.c \ + contrib/relic/src/epx/relic_ep2_mul_fix.c \ + contrib/relic/src/epx/relic_ep2_mul_sim.c \ + contrib/relic/src/epx/relic_ep2_neg.c \ + contrib/relic/src/epx/relic_ep2_norm.c \ + contrib/relic/src/epx/relic_ep2_pck.c \ + contrib/relic/src/epx/relic_ep2_util.c + +EB_SRCS = \ + contrib/relic/src/eb/relic_eb_add.c \ + contrib/relic/src/eb/relic_eb_cmp.c \ + contrib/relic/src/eb/relic_eb_curve.c \ + contrib/relic/src/eb/relic_eb_dbl.c \ + contrib/relic/src/eb/relic_eb_frb.c \ + contrib/relic/src/eb/relic_eb_hlv.c \ + contrib/relic/src/eb/relic_eb_map.c \ + contrib/relic/src/eb/relic_eb_mul.c \ + contrib/relic/src/eb/relic_eb_mul_fix.c \ + contrib/relic/src/eb/relic_eb_mul_sim.c \ + contrib/relic/src/eb/relic_eb_neg.c \ + contrib/relic/src/eb/relic_eb_norm.c \ + contrib/relic/src/eb/relic_eb_param.c \ + contrib/relic/src/eb/relic_eb_pck.c \ + contrib/relic/src/eb/relic_eb_util.c + +ED_SRCS = \ + contrib/relic/src/ed/relic_ed_add.c \ + contrib/relic/src/ed/relic_ed_cmp.c \ + contrib/relic/src/ed/relic_ed_curve.c \ + contrib/relic/src/ed/relic_ed_dbl.c \ + contrib/relic/src/ed/relic_ed_map.c \ + contrib/relic/src/ed/relic_ed_mul.c \ + contrib/relic/src/ed/relic_ed_mul_fix.c \ + contrib/relic/src/ed/relic_ed_mul_sim.c \ + contrib/relic/src/ed/relic_ed_neg.c \ + contrib/relic/src/ed/relic_ed_norm.c \ + contrib/relic/src/ed/relic_ed_param.c \ + contrib/relic/src/ed/relic_ed_pck.c \ + contrib/relic/src/ed/relic_ed_util.c + +PP_SRCS = \ + contrib/relic/src/pp/relic_pp_add_k2.c \ + contrib/relic/src/pp/relic_pp_add_k8.c \ + contrib/relic/src/pp/relic_pp_add_k12.c \ + contrib/relic/src/pp/relic_pp_add_k48.c \ + contrib/relic/src/pp/relic_pp_add_k54.c \ + contrib/relic/src/pp/relic_pp_dbl_k2.c \ + contrib/relic/src/pp/relic_pp_dbl_k8.c \ + contrib/relic/src/pp/relic_pp_dbl_k12.c \ + contrib/relic/src/pp/relic_pp_dbl_k48.c \ + contrib/relic/src/pp/relic_pp_dbl_k54.c \ + contrib/relic/src/pp/relic_pp_exp_k2.c \ + contrib/relic/src/pp/relic_pp_exp_k8.c \ + contrib/relic/src/pp/relic_pp_exp_k12.c \ + contrib/relic/src/pp/relic_pp_exp_k48.c \ + contrib/relic/src/pp/relic_pp_exp_k54.c \ + contrib/relic/src/pp/relic_pp_map.c \ + contrib/relic/src/pp/relic_pp_map_k2.c \ + contrib/relic/src/pp/relic_pp_map_k8.c \ + contrib/relic/src/pp/relic_pp_map_k12.c \ + contrib/relic/src/pp/relic_pp_map_k48.c \ + contrib/relic/src/pp/relic_pp_map_k54.c \ + contrib/relic/src/pp/relic_pp_norm.c + +PC_SRCS = \ + contrib/relic/src/pc/relic_pc_core.c \ + contrib/relic/src/pc/relic_pc_exp.c \ + contrib/relic/src/pc/relic_pc_util.c + +MD_SRCS = \ + contrib/relic/src/md/blake2.h \ + contrib/relic/src/md/blake2-impl.h \ + contrib/relic/src/md/blake2s-ref.c \ + contrib/relic/src/md/relic_md_blake2s.c \ + contrib/relic/src/md/relic_md_hmac.c \ + contrib/relic/src/md/relic_md_kdf.c \ + contrib/relic/src/md/relic_md_mgf.c \ + contrib/relic/src/md/relic_md_sha224.c \ + contrib/relic/src/md/relic_md_sha256.c \ + contrib/relic/src/md/relic_md_sha384.c \ + contrib/relic/src/md/relic_md_sha512.c \ + contrib/relic/src/md/relic_md_xmd.c \ + contrib/relic/src/md/sha.h \ + contrib/relic/src/md/sha224-256.c \ + contrib/relic/src/md/sha384-512.c \ + contrib/relic/src/md/sha_private.h + +EXTRA_DIST += \ + contrib/relic/src/arch/relic_arch_arm.c \ + contrib/relic/src/arch/relic_arch_none.c \ + contrib/relic/src/arch/relic_arch_x64.c \ + contrib/relic/src/arch/relic_arch_x86.c + +RELIC_SRCS += contrib/relic/src/arch/relic_arch_@CPU_ARCH@.c +RELIC_SRCS += contrib/relic/src/rand/relic_rand_core.c +RELIC_SRCS += contrib/relic/src/rand/relic_rand_hashd.c + +if WITH_BN +RELIC_SRCS += $(BN_SRCS) +RELIC_SRCS += contrib/relic/src/low/gmp/relic_bn_add_low.c +RELIC_SRCS += contrib/relic/src/low/gmp/relic_bn_div_low.c +RELIC_SRCS += contrib/relic/src/low/gmp/relic_bn_mod_low.c +RELIC_SRCS += contrib/relic/src/low/gmp/relic_bn_mul_low.c +RELIC_SRCS += contrib/relic/src/low/gmp/relic_bn_shift_low.c +RELIC_SRCS += contrib/relic/src/low/gmp/relic_bn_sqr_low.c +endif + +if WITH_DV +RELIC_SRCS += contrib/relic/src/dv/relic_dv_mem.c +RELIC_SRCS += contrib/relic/src/dv/relic_dv_util.c +endif + +if WITH_FP +RELIC_SRCS += $(FP_SRCS) +RELIC_SRCS += contrib/relic/src/low/gmp/relic_fp_add_low.c +RELIC_SRCS += contrib/relic/src/low/gmp/relic_fp_inv_low.c +RELIC_SRCS += contrib/relic/src/low/gmp/relic_fp_mul_low.c +RELIC_SRCS += contrib/relic/src/low/gmp/relic_fp_rdc_low.c +RELIC_SRCS += contrib/relic/src/low/gmp/relic_fp_shift_low.c +RELIC_SRCS += contrib/relic/src/low/gmp/relic_fp_sqr_low.c +endif + +if WITH_FPX +RELIC_SRCS += $(FPX_SRCS) +RELIC_SRCS += contrib/relic/src/low/easy/relic_fpx_add_low.c +RELIC_SRCS += contrib/relic/src/low/easy/relic_fpx_mul_low.c +RELIC_SRCS += contrib/relic/src/low/easy/relic_fpx_rdc_low.c +RELIC_SRCS += contrib/relic/src/low/easy/relic_fpx_sqr_low.c +endif + +if WITH_FB +RELIC_SRCS += $(FB_SRCS) +RELIC_SRCS += contrib/relic/src/low/gmp/relic_fb_add_low.c +RELIC_SRCS += contrib/relic/src/low/gmp/relic_fb_shift_low.c +RELIC_SRCS += contrib/relic/src/low/easy/relic_fb_inv_low.c +RELIC_SRCS += contrib/relic/src/low/easy/relic_fb_itr_low.c +RELIC_SRCS += contrib/relic/src/low/easy/relic_fb_mul_low.c +RELIC_SRCS += contrib/relic/src/low/easy/relic_fb_rdc_low.c +RELIC_SRCS += contrib/relic/src/low/easy/relic_fb_slv_low.c +RELIC_SRCS += contrib/relic/src/low/easy/relic_fb_sqr_low.c +RELIC_SRCS += contrib/relic/src/low/easy/relic_fb_srt_low.c +RELIC_SRCS += contrib/relic/src/low/easy/relic_fb_trc_low.c +endif + +if WITH_FBX +RELIC_SRCS += contrib/relic/src/fbx/relic_fb2_inv.c +RELIC_SRCS += contrib/relic/src/fbx/relic_fb2_mul.c +RELIC_SRCS += contrib/relic/src/fbx/relic_fb2_slv.c +RELIC_SRCS += contrib/relic/src/fbx/relic_fb2_sqr.c +endif + +if WITH_EP +RELIC_SRCS += $(EP_SRCS) +endif + +if WITH_EPX +RELIC_SRCS += $(EPX_SRCS) +endif + +if WITH_EB +RELIC_SRCS += $(EB_SRCS) +endif + +if WITH_ED +RELIC_SRCS += $(ED_SRCS) +endif + +if WITH_PP +RELIC_SRCS += $(PP_SRCS) +endif + +if WITH_PC +RELIC_SRCS += $(PC_SRCS) +endif + +if WITH_CP +RELIC_SRCS += contrib/relic/src/cp/relic_cp_rsa.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_rabin.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_bdpe.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_ghpe.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_phpe.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_ecdh.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_ecmqv.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_ecies.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_ecdsa.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_ecss.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_vbnn.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_sokaka.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_bgn.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_ibe.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_bls.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_cls.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_pss.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_mpss.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_bbs.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_zss.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_cmlhs.c +RELIC_SRCS += contrib/relic/src/cp/relic_cp_mklhs.c +endif + +if WITH_BC +RELIC_SRCS += contrib/relic/src/bc/relic_bc_aes.c +RELIC_SRCS += contrib/relic/src/bc/rijndael-alg-fst.c +RELIC_SRCS += contrib/relic/src/bc/rijndael-alg-fst.h +RELIC_SRCS += contrib/relic/src/bc/rijndael-api-fst.c +RELIC_SRCS += contrib/relic/src/bc/rijndael-api-fst.h +endif + +if WITH_MD +RELIC_SRCS += $(MD_SRCS) +endif + +if WITH_MPC +RELIC_SRCS += contrib/relic/src/mpc/relic_mt_mpc.c +RELIC_SRCS += contrib/relic/src/mpc/relic_pc_mpc.c +endif + +librelic_la_SOURCES = \ + $(RELIC_SRCS) \ + $(RELIC_H) + +librelic_la_CPPFLAGS = $(AM_CPPFLAGS) $(RELIC_CPPFLAGS) $(RELIC_INCLUDES) +librelic_la_CFLAGS = $(AM_CFLAGS) $(WARN_CFLAGS) $(NOWARN_CFLAGS) + + +# libchiabls.la +BLS_H = \ + src/bls.hpp \ + src/elements.hpp \ + src/hdkeys.hpp \ + src/hkdf.hpp \ + src/privatekey.hpp \ + src/schemes.hpp \ + src/test-utils.hpp \ + src/threshold.hpp \ + src/util.hpp + +libchiabls_la_SOURCES = \ + src/privatekey.cpp \ + src/bls.cpp \ + src/elements.cpp \ + src/schemes.cpp \ + src/threshold.cpp \ + $(BLS_H) \ + $(RELIC_H) + +libchiabls_la_CPPFLAGS = $(AM_CPPFLAGS) $(CHIABLS_INCLUDES) -DBLSALLOC_SODIUM=1 +libchiabls_la_CXXFLAGS = $(AM_CXXFLAGS) + +libchiabls_la_LIBADD = $(LIBRELIC) $(SODIUM_LIBS) $(GMP_LIBS) + + +if USE_BENCH +noinst_PROGRAMS += runbench + +runbench_SOURCES = \ + src/test-bench.cpp \ + src/test-utils.hpp \ + $(RELIC_H) \ + $(BLS_H) + +runbench_CPPFLAGS = $(AM_CPPFLAGS) $(CHIABLS_INCLUDES) +runbench_CXXFLAGS = $(AM_CXXFLAGS) +runbench_LDFLAGS = $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) + +runbench_LDADD = $(LIBCHIABLS) $(SODIUM_LIBS) $(GMP_LIBS) + +endif + +TESTS = +if USE_TESTS +noinst_PROGRAMS += runtest + +runtest_SOURCES = src/test.cpp \ + src/test-utils.hpp \ + contrib/catch/catch.hpp + +runtest_CPPFLAGS = $(AM_CPPFLAGS) $(CHIABLS_INCLUDES) -I$(top_srcdir)/contrib/catch +runtest_CXXFLAGS = $(AM_CXXFLAGS) +runtest_LDFLAGS = $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) + +runtest_LDADD = $(LIBCHIABLS) $(SODIUM_LIBS) $(GMP_LIBS) + +TESTS += runtest + +endif + +CLEANFILES = $(LIBRELIC) $(LIBCHIABLS) diff --git a/src/chiabls/README.md b/src/chiabls/README.md new file mode 100644 index 0000000000000..343ad8d40e7ee --- /dev/null +++ b/src/chiabls/README.md @@ -0,0 +1,301 @@ +# BLS Signatures implementation + +![Build](https://github.com/Chia-Network/bls-signatures/workflows/Build/badge.svg) +![PyPI](https://img.shields.io/pypi/v/blspy?logo=pypi) +![PyPI - Format](https://img.shields.io/pypi/format/blspy?logo=pypi) +![GitHub](https://img.shields.io/github/license/Chia-Network/bls-signatures?logo=Github) + +[![Total alerts](https://img.shields.io/lgtm/alerts/g/Chia-Network/bls-signatures.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Chia-Network/bls-signatures/alerts/) +[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/Chia-Network/bls-signatures.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Chia-Network/bls-signatures/context:javascript) +[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/Chia-Network/bls-signatures.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Chia-Network/bls-signatures/context:python) +[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/Chia-Network/bls-signatures.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Chia-Network/bls-signatures/context:cpp) + +NOTE: THIS LIBRARY IS NOT YET FORMALLY REVIEWED FOR SECURITY + +NOTE: THIS LIBRARY WAS SHIFTED TO THE IETF BLS SPECIFICATION ON 7/16/20 + +Implements BLS signatures with aggregation using [relic toolkit](https://github.com/relic-toolkit/relic) +for cryptographic primitives (pairings, EC, hashing) according to the +[IETF BLS RFC](https://datatracker.ietf.org/doc/draft-irtf-cfrg-bls-signature/) +with [these curve parameters](https://datatracker.ietf.org/doc/draft-irtf-cfrg-pairing-friendly-curves/) +for BLS12-381. + +Features: + +* Non-interactive signature aggregation following IETF specification +* Works on Windows, Mac, Linux, BSD +* Efficient verification using Proof of Posssesion (only one pairing per distinct message) +* Aggregate public keys and private keys +* [EIP-2333](https://eips.ethereum.org/EIPS/eip-2333) key derivation (including unhardened BIP-32-like keys) +* Key and signature serialization +* Batch verification +* [Python bindings](https://github.com/Chia-Network/bls-signatures/tree/main/python-bindings) +* [Pure python bls12-381 and signatures](https://github.com/Chia-Network/bls-signatures/tree/main/python-impl) +* [JavaScript bindings](https://github.com/Chia-Network/bls-signatures/tree/main/js-bindings) + +## Before you start + +This library uses minimum public key sizes (MPL). A G2Element is a signature (96 bytes), and a G1Element is a public key (48 bytes). A private key is a 32 byte integer. There are three schemes: Basic, Augmented, and ProofOfPossession. Augmented should be enough for most use cases, and ProofOfPossession can be used where verification must be fast. + +## Import the library + +```c++ +#include "bls.hpp" +using namespace bls; +``` + +## Creating keys and signatures + +```c++ +// Example seed, used to generate private key. Always use +// a secure RNG with sufficient entropy to generate a seed (at least 32 bytes). +vector seed = {0, 50, 6, 244, 24, 199, 1, 25, 52, 88, 192, + 19, 18, 12, 89, 6, 220, 18, 102, 58, 209, 82, + 12, 62, 89, 110, 182, 9, 44, 20, 254, 22}; + +PrivateKey sk = AugSchemeMPL().KeyGen(seed); +G1Element pk = sk.GetG1Element(); + +vector message = {1, 2, 3, 4, 5}; // Message is passed in as a byte vector +G2Element signature = AugSchemeMPL().Sign(sk, message); + +// Verify the signature +bool ok = AugSchemeMPL().Verify(pk, message, signature)); +``` + +## Serializing keys and signatures to bytes + +```c++ +vector skBytes = sk.Serialize(); +vector pkBytes = pk.Serialize(); +vector signatureBytes = signature.Serialize(); + +cout << Util::HexStr(skBytes) << endl; // 32 bytes printed in hex +cout << Util::HexStr(pkBytes) << endl; // 48 bytes printed in hex +cout << Util::HexStr(signatureBytes) << endl; // 96 bytes printed in hex +``` + +## Loading keys and signatures from bytes + +```c++ +// Takes vector of 32 bytes +PrivateKey skc = PrivateKey::FromByteVector(skBytes); + +// Takes vector of 48 bytes +pk = G1Element::FromByteVector(pkBytes); + +// Takes vector of 96 bytes +signature = G2Element::FromByteVector(signatureBytes); +``` + +## Create aggregate signatures + +```c++ +// Generate some more private keys +seed[0] = 1; +PrivateKey sk1 = AugSchemeMPL().KeyGen(seed); +seed[0] = 2; +PrivateKey sk2 = AugSchemeMPL().KeyGen(seed); +vector message2 = {1, 2, 3, 4, 5, 6, 7}; + +// Generate first sig +G1Element pk1 = sk1.GetG1Element(); +G2Element sig1 = AugSchemeMPL().Sign(sk1, message); + +// Generate second sig +G1Element pk2 = sk2.GetG1Element(); +G2Element sig2 = AugSchemeMPL().Sign(sk2, message2); + +// Signatures can be non-interactively combined by anyone +G2Element aggSig = AugSchemeMPL().Aggregate({sig1, sig2}); + +ok = AugSchemeMPL().AggregateVerify({pk1, pk2}, {message, message2}, aggSig); +``` + +## Arbitrary trees of aggregates + +```c++ +seed[0] = 3; +PrivateKey sk3 = AugSchemeMPL().KeyGen(seed); +G1Element pk3 = sk3.GetG1Element(); +vector message3 = {100, 2, 254, 88, 90, 45, 23}; +G2Element sig3 = AugSchemeMPL().Sign(sk3, message3); + + +G2Element aggSigFinal = AugSchemeMPL().Aggregate({aggSig, sig3}); +ok = AugSchemeMPL().AggregateVerify({pk1, pk2, pk3}, {message, message2, message3}, aggSigFinal); + +``` + +## Very fast verification with Proof of Possession scheme + +```c++ +// If the same message is signed, you can use Proof of Posession (PopScheme) for efficiency +// A proof of possession MUST be passed around with the PK to ensure security. + +G2Element popSig1 = PopSchemeMPL().Sign(sk1, message); +G2Element popSig2 = PopSchemeMPL().Sign(sk2, message); +G2Element popSig3 = PopSchemeMPL().Sign(sk3, message); +G2Element pop1 = PopSchemeMPL().PopProve(sk1); +G2Element pop2 = PopSchemeMPL().PopProve(sk2); +G2Element pop3 = PopSchemeMPL().PopProve(sk3); + +ok = PopSchemeMPL().PopVerify(pk1, pop1); +ok = PopSchemeMPL().PopVerify(pk2, pop2); +ok = PopSchemeMPL().PopVerify(pk3, pop3); +G2Element popSigAgg = PopSchemeMPL().Aggregate({popSig1, popSig2, popSig3}); + +ok = PopSchemeMPL().FastAggregateVerify({pk1, pk2, pk3}, message, popSigAgg); + +// Aggregate public key, indistinguishable from a single public key +G1Element popAggPk = pk1 + pk2 + pk3; +ok = PopSchemeMPL().Verify(popAggPk, message, popSigAgg); + +// Aggregate private keys +PrivateKey aggSk = PrivateKey::Aggregate({sk1, sk2, sk3}); +ok = (PopSchemeMPL().Sign(aggSk, message) == popSigAgg); +``` + +## HD keys using [EIP-2333](https://github.com/ethereum/EIPs/pull/2333) + +```c++ +// You can derive 'child' keys from any key, to create arbitrary trees. 4 byte indeces are used. +// Hardened (more secure, but no parent pk -> child pk) +PrivateKey masterSk = AugSchemeMPL().KeyGen(seed); +PrivateKey child = AugSchemeMPL().DeriveChildSk(masterSk, 152); +PrivateKey grandChild = AugSchemeMPL().DeriveChildSk(child, 952) + +// Unhardened (less secure, but can go from parent pk -> child pk), BIP32 style +G1Element masterPk = masterSk.GetG1Element(); +PrivateKey childU = AugSchemeMPL().DeriveChildSkUnhardened(masterSk, 22); +PrivateKey grandchildU = AugSchemeMPL().DeriveChildSkUnhardened(childU, 0); + +G1Element childUPk = AugSchemeMPL().DeriveChildPkUnhardened(masterPk, 22); +G1Element grandchildUPk = AugSchemeMPL().DeriveChildPkUnhardened(childUPk, 0); + +ok = (grandchildUPk == grandchildU.GetG1Element(); +``` + +## Build + +Cmake 3.14+, a c++ compiler, and python3 (for bindings) are required for building. + +```bash +mkdir build +cd build +cmake ../ +cmake --build . -- -j 6 +``` + +### Run tests + +```bash +./build/src/runtest +``` + +### Run benchmarks + +```bash +./build/src/runbench +``` + +On a 3.5 GHz i7 Mac, verification takes about 1.1ms per signature, and signing takes 1.3ms. + +### Link the library to use it + +```bash +g++ -Wl,-no_pie -std=c++11 -Ibls-signatures/build/_deps/relic-src/include -Ibls-signatures/build/_deps/relic-build/include -Ibls-signatures/src -L./bls-signatures/build/ -l bls yourapp.cpp +``` + +## Notes on dependencies + +Libsodium and GMP are optional dependencies: libsodium gives secure memory +allocation, and GMP speeds up the library by ~ 3x. MPIR is used on Windows via +GitHub Actions instead. To install them, either download them from github and +follow the instructions for each repo, or use a package manager like APT or +brew. You can follow the recipe used to build python wheels for multiple +platforms in `.github/workflows/`. libsodium is dynamically linked unless +the environment variable $CIBUILDWHEEL is set which will then cause +libsodium to statically link. + +## Discussion + +Discussion about this library and other Chia related development is in the #dev +channel of Chia's [public Keybase channels](https://keybase.io/team/chia_network.public). + +## Code style + +* Always use vector for bytes +* Use size_t for size variables +* Uppercase method names +* Prefer static constructors +* Avoid using templates +* Objects allocate and free their own memory +* Use cpplint with default rules +* Use SecAlloc and SecFree when handling secrets + +## ci Building + +The primary build process for this repository is to use GitHub Actions to +build binary wheels for MacOS, Linux (x64 and aarch64), and Windows and publish +them with a source wheel on PyPi. MacOS ARM64 is supported but not automated +due to a lack of M1 CI runners. See `.github/workflows/build.yml`. CMake uses +[FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) +to download [pybind11](https://github.com/pybind/pybind11) for the Python +bindings and relic from a chia relic forked repository for Windows. Building +is then managed by [cibuildwheel](https://github.com/joerick/cibuildwheel). +Further installation is then available via `pip install blspy` e.g. The ci +builds include GMP and a statically linked libsodium. + +## Contributing and workflow + +Contributions are welcome and more details are available in chia-blockchain's +[CONTRIBUTING.md](https://github.com/Chia-Network/chia-blockchain/blob/main/CONTRIBUTING.md). + +The main branch is usually the currently released latest version on PyPI. +Note that at times bls-signatures/blspy will be ahead of the release version +that chia-blockchain requires in it's main/release version in preparation +for a new chia-blockchain release. Please branch or fork main and then create +a pull request to the main branch. Linear merging is enforced on main and +merging requires a completed review. PRs will kick off a GitHub actions ci +build and analysis of bls-signatures at +[lgtm.com](https://lgtm.com/projects/g/Chia-Network/bls-signatures/?mode=list). +Please make sure your build is passing and that it does not increase alerts +at lgtm. + +## Specification and test vectors + +The [IETF bls draft](https://datatracker.ietf.org/doc/draft-irtf-cfrg-hash-to-curve/) +is followed. Test vectors can also be seen in the python and cpp test files. + +## Libsodium license + +The libsodium static library is licensed under the ISC license which requires +the following copyright notice. + +>ISC License +> +>Copyright (c) 2013-2020 +>Frank Denis \ +> +>Permission to use, copy, modify, and/or distribute this software for any +>purpose with or without fee is hereby granted, provided that the above +>copyright notice and this permission notice appear in all copies. +> +>THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +>WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +>MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +>ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +>WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +>ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +>OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +## GMP license + +GMP is distributed under the +[GNU LGPL v3 license](https://www.gnu.org/licenses/lgpl-3.0.html) + +## Relic license + +Relic is used with the +[Apache 2.0 license](https://github.com/relic-toolkit/relic/blob/master/LICENSE.Apache-2.0) diff --git a/src/chiabls/autogen.sh b/src/chiabls/autogen.sh new file mode 100755 index 0000000000000..6aeeddf1c1b26 --- /dev/null +++ b/src/chiabls/autogen.sh @@ -0,0 +1,9 @@ +#!/bin/sh +set -e +srcdir="$(dirname $0)" +cd "$srcdir" +if [ -z ${LIBTOOLIZE} ] && GLIBTOOLIZE="`which glibtoolize 2>/dev/null`"; then + LIBTOOLIZE="${GLIBTOOLIZE}" + export LIBTOOLIZE +fi +autoreconf --install --force --warnings=all \ No newline at end of file diff --git a/src/chiabls/build-aux/m4/ax_check_compile_flag.m4 b/src/chiabls/build-aux/m4/ax_check_compile_flag.m4 new file mode 100644 index 0000000000000..ca3639715e724 --- /dev/null +++ b/src/chiabls/build-aux/m4/ax_check_compile_flag.m4 @@ -0,0 +1,74 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) +# +# DESCRIPTION +# +# Check whether the given FLAG works with the current language's compiler +# or gives an error. (Warnings, however, are ignored) +# +# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on +# success/failure. +# +# If EXTRA-FLAGS is defined, it is added to the current language's default +# flags (e.g. CFLAGS) when the check is done. The check is thus made with +# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to +# force the compiler to issue an error when a bad flag is given. +# +# INPUT gives an alternative input source to AC_COMPILE_IFELSE. +# +# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this +# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. +# +# LICENSE +# +# Copyright (c) 2008 Guido U. Draheim +# Copyright (c) 2011 Maarten Bosmans +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or (at your +# option) any later version. +# +# This program 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 a copy of the GNU General Public License along +# with this program. If not, see . +# +# As a special exception, the respective Autoconf Macro's copyright owner +# gives unlimited permission to copy, distribute and modify the configure +# scripts that are the output of Autoconf when processing the Macro. You +# need not follow the terms of the GNU General Public License when using +# or distributing such scripts, even though portions of the text of the +# Macro appear in them. The GNU General Public License (GPL) does govern +# all other use of the material that constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the Autoconf +# Macro released by the Autoconf Archive. When you make and distribute a +# modified version of the Autoconf Macro, you may extend this special +# exception to the GPL to apply to your modified version as well. + +#serial 4 + +AC_DEFUN([AX_CHECK_COMPILE_FLAG], +[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF +AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl +AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ + ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS + _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" + AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], + [AS_VAR_SET(CACHEVAR,[yes])], + [AS_VAR_SET(CACHEVAR,[no])]) + _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) +AS_VAR_IF(CACHEVAR,yes, + [m4_default([$2], :)], + [m4_default([$3], :)]) +AS_VAR_POPDEF([CACHEVAR])dnl +])dnl AX_CHECK_COMPILE_FLAGS diff --git a/src/chiabls/build-aux/m4/ax_cxx_compile_stdcxx.m4 b/src/chiabls/build-aux/m4/ax_cxx_compile_stdcxx.m4 new file mode 100644 index 0000000000000..f147cee3b117f --- /dev/null +++ b/src/chiabls/build-aux/m4/ax_cxx_compile_stdcxx.m4 @@ -0,0 +1,568 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional]) +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the specified +# version of the C++ standard. If necessary, add switches to CXX and +# CXXCPP to enable support. VERSION may be '11' (for the C++11 standard) +# or '14' (for the C++14 standard). +# +# The second argument, if specified, indicates whether you insist on an +# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. +# -std=c++11). If neither is specified, you get whatever works, with +# preference for an extended mode. +# +# The third argument, if specified 'mandatory' or if left unspecified, +# indicates that baseline support for the specified C++ standard is +# required and that the macro should error out if no mode with that +# support is found. If specified 'optional', then configuration proceeds +# regardless, after defining HAVE_CXX${VERSION} if and only if a +# supporting mode is found. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik +# Copyright (c) 2012 Zack Weinberg +# Copyright (c) 2013 Roy Stogner +# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov +# Copyright (c) 2015 Paul Norman +# Copyright (c) 2015 Moritz Klammler +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 4 + +dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro +dnl (serial version number 13). + +AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl + m4_if([$1], [11], [], + [$1], [14], [], + [$1], [17], [m4_fatal([support for C++17 not yet implemented in AX_CXX_COMPILE_STDCXX])], + [m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl + m4_if([$2], [], [], + [$2], [ext], [], + [$2], [noext], [], + [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX])])dnl + m4_if([$3], [], [ax_cxx_compile_cxx$1_required=true], + [$3], [mandatory], [ax_cxx_compile_cxx$1_required=true], + [$3], [optional], [ax_cxx_compile_cxx$1_required=false], + [m4_fatal([invalid third argument `$3' to AX_CXX_COMPILE_STDCXX])]) + m4_if([$4], [], [ax_cxx_compile_cxx$1_try_default=true], + [$4], [default], [ax_cxx_compile_cxx$1_try_default=true], + [$4], [nodefault], [ax_cxx_compile_cxx$1_try_default=false], + [m4_fatal([invalid fourth argument `$4' to AX_CXX_COMPILE_STDCXX])]) + AC_LANG_PUSH([C++])dnl + ac_success=no + + m4_if([$4], [nodefault], [], [dnl + AC_CACHE_CHECK(whether $CXX supports C++$1 features by default, + ax_cv_cxx_compile_cxx$1, + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], + [ax_cv_cxx_compile_cxx$1=yes], + [ax_cv_cxx_compile_cxx$1=no])]) + if test x$ax_cv_cxx_compile_cxx$1 = xyes; then + ac_success=yes + fi]) + + m4_if([$2], [noext], [], [dnl + if test x$ac_success = xno; then + for switch in -std=gnu++$1 -std=gnu++0x; do + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, + $cachevar, + [ac_save_CXX="$CXX" + CXX="$CXX $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXX="$ac_save_CXX"]) + if eval test x\$$cachevar = xyes; then + CXX="$CXX $switch" + if test -n "$CXXCPP" ; then + CXXCPP="$CXXCPP $switch" + fi + ac_success=yes + break + fi + done + fi]) + + m4_if([$2], [ext], [], [dnl + if test x$ac_success = xno; then + dnl HP's aCC needs +std=c++11 according to: + dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf + dnl Cray's crayCC needs "-h std=c++11" + for switch in -std=c++$1 -std=c++0x +std=c++$1 "-h std=c++$1"; do + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, + $cachevar, + [ac_save_CXX="$CXX" + CXX="$CXX $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXX="$ac_save_CXX"]) + if eval test x\$$cachevar = xyes; then + CXX="$CXX $switch" + if test -n "$CXXCPP" ; then + CXXCPP="$CXXCPP $switch" + fi + ac_success=yes + break + fi + done + fi]) + AC_LANG_POP([C++]) + if test x$ax_cxx_compile_cxx$1_required = xtrue; then + if test x$ac_success = xno; then + AC_MSG_ERROR([*** A compiler with support for C++$1 language features is required.]) + fi + fi + if test x$ac_success = xno; then + HAVE_CXX$1=0 + AC_MSG_NOTICE([No compiler with C++$1 support was found]) + else + HAVE_CXX$1=1 + AC_DEFINE(HAVE_CXX$1,1, + [define if the compiler supports basic C++$1 syntax]) + fi + AC_SUBST(HAVE_CXX$1) +]) + + +dnl Test body for checking C++11 support + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11], + _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 +) + + +dnl Test body for checking C++14 support + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14], + _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 + _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 +) + + +dnl Tests for new features in C++11 + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[ + +// If the compiler admits that it is not ready for C++11, why torture it? +// Hopefully, this will speed up the test. + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +#elif __cplusplus < 201103L + +#error "This is not a C++11 compiler" + +#else + +namespace cxx11 +{ + + namespace test_static_assert + { + + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + } + + namespace test_final_override + { + + struct Base + { + virtual void f() {} + }; + + struct Derived : public Base + { + virtual void f() override {} + }; + + } + + namespace test_double_right_angle_brackets + { + + template < typename T > + struct check {}; + + typedef check single_type; + typedef check> double_type; + typedef check>> triple_type; + typedef check>>> quadruple_type; + + } + + namespace test_decltype + { + + int + f() + { + int a = 1; + decltype(a) b = 2; + return a + b; + } + + } + + namespace test_type_deduction + { + + template < typename T1, typename T2 > + struct is_same + { + static const bool value = false; + }; + + template < typename T > + struct is_same + { + static const bool value = true; + }; + + template < typename T1, typename T2 > + auto + add(T1 a1, T2 a2) -> decltype(a1 + a2) + { + return a1 + a2; + } + + int + test(const int c, volatile int v) + { + static_assert(is_same::value == true, ""); + static_assert(is_same::value == false, ""); + static_assert(is_same::value == false, ""); + auto ac = c; + auto av = v; + auto sumi = ac + av + 'x'; + auto sumf = ac + av + 1.0; + static_assert(is_same::value == true, ""); + static_assert(is_same::value == true, ""); + static_assert(is_same::value == true, ""); + static_assert(is_same::value == false, ""); + static_assert(is_same::value == true, ""); + return (sumf > 0.0) ? sumi : add(c, v); + } + + } + + namespace test_noexcept + { + + int f() { return 0; } + int g() noexcept { return 0; } + + static_assert(noexcept(f()) == false, ""); + static_assert(noexcept(g()) == true, ""); + + } + + namespace test_constexpr + { + + template < typename CharT > + unsigned long constexpr + strlen_c_r(const CharT *const s, const unsigned long acc) noexcept + { + return *s ? strlen_c_r(s + 1, acc + 1) : acc; + } + + template < typename CharT > + unsigned long constexpr + strlen_c(const CharT *const s) noexcept + { + return strlen_c_r(s, 0UL); + } + + static_assert(strlen_c("") == 0UL, ""); + static_assert(strlen_c("1") == 1UL, ""); + static_assert(strlen_c("example") == 7UL, ""); + static_assert(strlen_c("another\0example") == 7UL, ""); + + } + + namespace test_rvalue_references + { + + template < int N > + struct answer + { + static constexpr int value = N; + }; + + answer<1> f(int&) { return answer<1>(); } + answer<2> f(const int&) { return answer<2>(); } + answer<3> f(int&&) { return answer<3>(); } + + void + test() + { + int i = 0; + const int c = 0; + static_assert(decltype(f(i))::value == 1, ""); + static_assert(decltype(f(c))::value == 2, ""); + static_assert(decltype(f(0))::value == 3, ""); + } + + } + + namespace test_uniform_initialization + { + + struct test + { + static const int zero {}; + static const int one {1}; + }; + + static_assert(test::zero == 0, ""); + static_assert(test::one == 1, ""); + + } + + namespace test_lambdas + { + + void + test1() + { + auto lambda1 = [](){}; + auto lambda2 = lambda1; + lambda1(); + lambda2(); + } + + int + test2() + { + auto a = [](int i, int j){ return i + j; }(1, 2); + auto b = []() -> int { return '0'; }(); + auto c = [=](){ return a + b; }(); + auto d = [&](){ return c; }(); + auto e = [a, &b](int x) mutable { + const auto identity = [](int y){ return y; }; + for (auto i = 0; i < a; ++i) + a += b--; + return x + identity(a + b); + }(0); + return a + b + c + d + e; + } + + int + test3() + { + const auto nullary = [](){ return 0; }; + const auto unary = [](int x){ return x; }; + using nullary_t = decltype(nullary); + using unary_t = decltype(unary); + const auto higher1st = [](nullary_t f){ return f(); }; + const auto higher2nd = [unary](nullary_t f1){ + return [unary, f1](unary_t f2){ return f2(unary(f1())); }; + }; + return higher1st(nullary) + higher2nd(nullary)(unary); + } + + } + + namespace test_variadic_templates + { + + template + struct sum; + + template + struct sum + { + static constexpr auto value = N0 + sum::value; + }; + + template <> + struct sum<> + { + static constexpr auto value = 0; + }; + + static_assert(sum<>::value == 0, ""); + static_assert(sum<1>::value == 1, ""); + static_assert(sum<23>::value == 23, ""); + static_assert(sum<1, 2>::value == 3, ""); + static_assert(sum<5, 5, 11>::value == 21, ""); + static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, ""); + + } + + // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae + // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function + // because of this. + namespace test_template_alias_sfinae + { + + struct foo {}; + + template + using member = typename T::member_type; + + template + void func(...) {} + + template + void func(member*) {} + + void test(); + + void test() { func(0); } + + } + +} // namespace cxx11 + +#endif // __cplusplus >= 201103L + +]]) + + +dnl Tests for new features in C++14 + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[ + +// If the compiler admits that it is not ready for C++14, why torture it? +// Hopefully, this will speed up the test. + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +#elif __cplusplus < 201402L + +#error "This is not a C++14 compiler" + +#else + +namespace cxx14 +{ + + namespace test_polymorphic_lambdas + { + + int + test() + { + const auto lambda = [](auto&&... args){ + const auto istiny = [](auto x){ + return (sizeof(x) == 1UL) ? 1 : 0; + }; + const int aretiny[] = { istiny(args)... }; + return aretiny[0]; + }; + return lambda(1, 1L, 1.0f, '1'); + } + + } + + namespace test_binary_literals + { + + constexpr auto ivii = 0b0000000000101010; + static_assert(ivii == 42, "wrong value"); + + } + + namespace test_generalized_constexpr + { + + template < typename CharT > + constexpr unsigned long + strlen_c(const CharT *const s) noexcept + { + auto length = 0UL; + for (auto p = s; *p; ++p) + ++length; + return length; + } + + static_assert(strlen_c("") == 0UL, ""); + static_assert(strlen_c("x") == 1UL, ""); + static_assert(strlen_c("test") == 4UL, ""); + static_assert(strlen_c("another\0test") == 7UL, ""); + + } + + namespace test_lambda_init_capture + { + + int + test() + { + auto x = 0; + const auto lambda1 = [a = x](int b){ return a + b; }; + const auto lambda2 = [a = lambda1(x)](){ return a; }; + return lambda2(); + } + + } + + namespace test_digit_seperators + { + + constexpr auto ten_million = 100'000'000; + static_assert(ten_million == 100000000, ""); + + } + + namespace test_return_type_deduction + { + + auto f(int& x) { return x; } + decltype(auto) g(int& x) { return x; } + + template < typename T1, typename T2 > + struct is_same + { + static constexpr auto value = false; + }; + + template < typename T > + struct is_same + { + static constexpr auto value = true; + }; + + int + test() + { + auto x = 0; + static_assert(is_same::value, ""); + static_assert(is_same::value, ""); + return x; + } + + } + +} // namespace cxx14 + +#endif // __cplusplus >= 201402L + +]]) diff --git a/src/chiabls/build-aux/m4/ax_pthread.m4 b/src/chiabls/build-aux/m4/ax_pthread.m4 new file mode 100644 index 0000000000000..4c4051ea376f7 --- /dev/null +++ b/src/chiabls/build-aux/m4/ax_pthread.m4 @@ -0,0 +1,485 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_pthread.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) +# +# DESCRIPTION +# +# This macro figures out how to build C programs using POSIX threads. It +# sets the PTHREAD_LIBS output variable to the threads library and linker +# flags, and the PTHREAD_CFLAGS output variable to any special C compiler +# flags that are needed. (The user can also force certain compiler +# flags/libs to be tested by setting these environment variables.) +# +# Also sets PTHREAD_CC to any special C compiler that is needed for +# multi-threaded programs (defaults to the value of CC otherwise). (This +# is necessary on AIX to use the special cc_r compiler alias.) +# +# NOTE: You are assumed to not only compile your program with these flags, +# but also to link with them as well. For example, you might link with +# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS +# +# If you are only building threaded programs, you may wish to use these +# variables in your default LIBS, CFLAGS, and CC: +# +# LIBS="$PTHREAD_LIBS $LIBS" +# CFLAGS="$CFLAGS $PTHREAD_CFLAGS" +# CC="$PTHREAD_CC" +# +# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant +# has a nonstandard name, this macro defines PTHREAD_CREATE_JOINABLE to +# that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX). +# +# Also HAVE_PTHREAD_PRIO_INHERIT is defined if pthread is found and the +# PTHREAD_PRIO_INHERIT symbol is defined when compiling with +# PTHREAD_CFLAGS. +# +# ACTION-IF-FOUND is a list of shell commands to run if a threads library +# is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it +# is not found. If ACTION-IF-FOUND is not specified, the default action +# will define HAVE_PTHREAD. +# +# Please let the authors know if this macro fails on any platform, or if +# you have any other suggestions or comments. This macro was based on work +# by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help +# from M. Frigo), as well as ac_pthread and hb_pthread macros posted by +# Alejandro Forero Cuervo to the autoconf macro repository. We are also +# grateful for the helpful feedback of numerous users. +# +# Updated for Autoconf 2.68 by Daniel Richard G. +# +# LICENSE +# +# Copyright (c) 2008 Steven G. Johnson +# Copyright (c) 2011 Daniel Richard G. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or (at your +# option) any later version. +# +# This program 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 a copy of the GNU General Public License along +# with this program. If not, see . +# +# As a special exception, the respective Autoconf Macro's copyright owner +# gives unlimited permission to copy, distribute and modify the configure +# scripts that are the output of Autoconf when processing the Macro. You +# need not follow the terms of the GNU General Public License when using +# or distributing such scripts, even though portions of the text of the +# Macro appear in them. The GNU General Public License (GPL) does govern +# all other use of the material that constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the Autoconf +# Macro released by the Autoconf Archive. When you make and distribute a +# modified version of the Autoconf Macro, you may extend this special +# exception to the GPL to apply to your modified version as well. + +#serial 23 + +AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD]) +AC_DEFUN([AX_PTHREAD], [ +AC_REQUIRE([AC_CANONICAL_HOST]) +AC_REQUIRE([AC_PROG_CC]) +AC_REQUIRE([AC_PROG_SED]) +AC_LANG_PUSH([C]) +ax_pthread_ok=no + +# We used to check for pthread.h first, but this fails if pthread.h +# requires special compiler flags (e.g. on Tru64 or Sequent). +# It gets checked for in the link test anyway. + +# First of all, check if the user has set any of the PTHREAD_LIBS, +# etcetera environment variables, and if threads linking works using +# them: +if test "x$PTHREAD_CFLAGS$PTHREAD_LIBS" != "x"; then + ax_pthread_save_CC="$CC" + ax_pthread_save_CFLAGS="$CFLAGS" + ax_pthread_save_LIBS="$LIBS" + AS_IF([test "x$PTHREAD_CC" != "x"], [CC="$PTHREAD_CC"]) + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + AC_MSG_CHECKING([for pthread_join using $CC $PTHREAD_CFLAGS $PTHREAD_LIBS]) + AC_LINK_IFELSE([AC_LANG_CALL([], [pthread_join])], [ax_pthread_ok=yes]) + AC_MSG_RESULT([$ax_pthread_ok]) + if test "x$ax_pthread_ok" = "xno"; then + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" + fi + CC="$ax_pthread_save_CC" + CFLAGS="$ax_pthread_save_CFLAGS" + LIBS="$ax_pthread_save_LIBS" +fi + +# We must check for the threads library under a number of different +# names; the ordering is very important because some systems +# (e.g. DEC) have both -lpthread and -lpthreads, where one of the +# libraries is broken (non-POSIX). + +# Create a list of thread flags to try. Items starting with a "-" are +# C compiler flags, and other items are library names, except for "none" +# which indicates that we try without any flags at all, and "pthread-config" +# which is a program returning the flags for the Pth emulation library. + +ax_pthread_flags="pthreads none -Kthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" + +# The ordering *is* (sometimes) important. Some notes on the +# individual items follow: + +# pthreads: AIX (must check this before -lpthread) +# none: in case threads are in libc; should be tried before -Kthread and +# other compiler flags to prevent continual compiler warnings +# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) +# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads), Tru64 +# (Note: HP C rejects this with "bad form for `-t' option") +# -pthreads: Solaris/gcc (Note: HP C also rejects) +# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it +# doesn't hurt to check since this sometimes defines pthreads and +# -D_REENTRANT too), HP C (must be checked before -lpthread, which +# is present but should not be used directly; and before -mthreads, +# because the compiler interprets this as "-mt" + "-hreads") +# -mthreads: Mingw32/gcc, Lynx/gcc +# pthread: Linux, etcetera +# --thread-safe: KAI C++ +# pthread-config: use pthread-config program (for GNU Pth library) + +case $host_os in + + freebsd*) + + # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) + # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) + + ax_pthread_flags="-kthread lthread $ax_pthread_flags" + ;; + + hpux*) + + # From the cc(1) man page: "[-mt] Sets various -D flags to enable + # multi-threading and also sets -lpthread." + + ax_pthread_flags="-mt -pthread pthread $ax_pthread_flags" + ;; + + openedition*) + + # IBM z/OS requires a feature-test macro to be defined in order to + # enable POSIX threads at all, so give the user a hint if this is + # not set. (We don't define these ourselves, as they can affect + # other portions of the system API in unpredictable ways.) + + AC_EGREP_CPP([AX_PTHREAD_ZOS_MISSING], + [ +# if !defined(_OPEN_THREADS) && !defined(_UNIX03_THREADS) + AX_PTHREAD_ZOS_MISSING +# endif + ], + [AC_MSG_WARN([IBM z/OS requires -D_OPEN_THREADS or -D_UNIX03_THREADS to enable pthreads support.])]) + ;; + + solaris*) + + # On Solaris (at least, for some versions), libc contains stubbed + # (non-functional) versions of the pthreads routines, so link-based + # tests will erroneously succeed. (N.B.: The stubs are missing + # pthread_cleanup_push, or rather a function called by this macro, + # so we could check for that, but who knows whether they'll stub + # that too in a future libc.) So we'll check first for the + # standard Solaris way of linking pthreads (-mt -lpthread). + + ax_pthread_flags="-mt,pthread pthread $ax_pthread_flags" + ;; +esac + +# GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC) + +AS_IF([test "x$GCC" = "xyes"], + [ax_pthread_flags="-pthread -pthreads $ax_pthread_flags"]) + +# The presence of a feature test macro requesting re-entrant function +# definitions is, on some systems, a strong hint that pthreads support is +# correctly enabled + +case $host_os in + darwin* | hpux* | linux* | osf* | solaris*) + ax_pthread_check_macro="_REENTRANT" + ;; + + aix*) + ax_pthread_check_macro="_THREAD_SAFE" + ;; + + *) + ax_pthread_check_macro="--" + ;; +esac +AS_IF([test "x$ax_pthread_check_macro" = "x--"], + [ax_pthread_check_cond=0], + [ax_pthread_check_cond="!defined($ax_pthread_check_macro)"]) + +# Are we compiling with Clang? + +AC_CACHE_CHECK([whether $CC is Clang], + [ax_cv_PTHREAD_CLANG], + [ax_cv_PTHREAD_CLANG=no + # Note that Autoconf sets GCC=yes for Clang as well as GCC + if test "x$GCC" = "xyes"; then + AC_EGREP_CPP([AX_PTHREAD_CC_IS_CLANG], + [/* Note: Clang 2.7 lacks __clang_[a-z]+__ */ +# if defined(__clang__) && defined(__llvm__) + AX_PTHREAD_CC_IS_CLANG +# endif + ], + [ax_cv_PTHREAD_CLANG=yes]) + fi + ]) +ax_pthread_clang="$ax_cv_PTHREAD_CLANG" + +ax_pthread_clang_warning=no + +# Clang needs special handling, because older versions handle the -pthread +# option in a rather... idiosyncratic way + +if test "x$ax_pthread_clang" = "xyes"; then + + # Clang takes -pthread; it has never supported any other flag + + # (Note 1: This will need to be revisited if a system that Clang + # supports has POSIX threads in a separate library. This tends not + # to be the way of modern systems, but it's conceivable.) + + # (Note 2: On some systems, notably Darwin, -pthread is not needed + # to get POSIX threads support; the API is always present and + # active. We could reasonably leave PTHREAD_CFLAGS empty. But + # -pthread does define _REENTRANT, and while the Darwin headers + # ignore this macro, third-party headers might not.) + + PTHREAD_CFLAGS="-pthread" + PTHREAD_LIBS= + + ax_pthread_ok=yes + + # However, older versions of Clang make a point of warning the user + # that, in an invocation where only linking and no compilation is + # taking place, the -pthread option has no effect ("argument unused + # during compilation"). They expect -pthread to be passed in only + # when source code is being compiled. + # + # Problem is, this is at odds with the way Automake and most other + # C build frameworks function, which is that the same flags used in + # compilation (CFLAGS) are also used in linking. Many systems + # supported by AX_PTHREAD require exactly this for POSIX threads + # support, and in fact it is often not straightforward to specify a + # flag that is used only in the compilation phase and not in + # linking. Such a scenario is extremely rare in practice. + # + # Even though use of the -pthread flag in linking would only print + # a warning, this can be a nuisance for well-run software projects + # that build with -Werror. So if the active version of Clang has + # this misfeature, we search for an option to squash it. + + AC_CACHE_CHECK([whether Clang needs flag to prevent "argument unused" warning when linking with -pthread], + [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG], + [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG=unknown + # Create an alternate version of $ac_link that compiles and + # links in two steps (.c -> .o, .o -> exe) instead of one + # (.c -> exe), because the warning occurs only in the second + # step + ax_pthread_save_ac_link="$ac_link" + ax_pthread_sed='s/conftest\.\$ac_ext/conftest.$ac_objext/g' + ax_pthread_link_step=`$as_echo "$ac_link" | sed "$ax_pthread_sed"` + ax_pthread_2step_ac_link="($ac_compile) && (echo ==== >&5) && ($ax_pthread_link_step)" + ax_pthread_save_CFLAGS="$CFLAGS" + for ax_pthread_try in '' -Qunused-arguments -Wno-unused-command-line-argument unknown; do + AS_IF([test "x$ax_pthread_try" = "xunknown"], [break]) + CFLAGS="-Werror -Wunknown-warning-option $ax_pthread_try -pthread $ax_pthread_save_CFLAGS" + ac_link="$ax_pthread_save_ac_link" + AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])], + [ac_link="$ax_pthread_2step_ac_link" + AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])], + [break]) + ]) + done + ac_link="$ax_pthread_save_ac_link" + CFLAGS="$ax_pthread_save_CFLAGS" + AS_IF([test "x$ax_pthread_try" = "x"], [ax_pthread_try=no]) + ax_cv_PTHREAD_CLANG_NO_WARN_FLAG="$ax_pthread_try" + ]) + + case "$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG" in + no | unknown) ;; + *) PTHREAD_CFLAGS="$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG $PTHREAD_CFLAGS" ;; + esac + +fi # $ax_pthread_clang = yes + +if test "x$ax_pthread_ok" = "xno"; then +for ax_pthread_try_flag in $ax_pthread_flags; do + + case $ax_pthread_try_flag in + none) + AC_MSG_CHECKING([whether pthreads work without any flags]) + ;; + + -mt,pthread) + AC_MSG_CHECKING([whether pthreads work with -mt -lpthread]) + PTHREAD_CFLAGS="-mt" + PTHREAD_LIBS="-lpthread" + ;; + + -*) + AC_MSG_CHECKING([whether pthreads work with $ax_pthread_try_flag]) + PTHREAD_CFLAGS="$ax_pthread_try_flag" + ;; + + pthread-config) + AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no]) + AS_IF([test "x$ax_pthread_config" = "xno"], [continue]) + PTHREAD_CFLAGS="`pthread-config --cflags`" + PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" + ;; + + *) + AC_MSG_CHECKING([for the pthreads library -l$ax_pthread_try_flag]) + PTHREAD_LIBS="-l$ax_pthread_try_flag" + ;; + esac + + ax_pthread_save_CFLAGS="$CFLAGS" + ax_pthread_save_LIBS="$LIBS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + + # Check for various functions. We must include pthread.h, + # since some functions may be macros. (On the Sequent, we + # need a special flag -Kthread to make this header compile.) + # We check for pthread_join because it is in -lpthread on IRIX + # while pthread_create is in libc. We check for pthread_attr_init + # due to DEC craziness with -lpthreads. We check for + # pthread_cleanup_push because it is one of the few pthread + # functions on Solaris that doesn't have a non-functional libc stub. + # We try pthread_create on general principles. + + AC_LINK_IFELSE([AC_LANG_PROGRAM([#include +# if $ax_pthread_check_cond +# error "$ax_pthread_check_macro must be defined" +# endif + static void routine(void *a) { a = 0; } + static void *start_routine(void *a) { return a; }], + [pthread_t th; pthread_attr_t attr; + pthread_create(&th, 0, start_routine, 0); + pthread_join(th, 0); + pthread_attr_init(&attr); + pthread_cleanup_push(routine, 0); + pthread_cleanup_pop(0) /* ; */])], + [ax_pthread_ok=yes], + []) + + CFLAGS="$ax_pthread_save_CFLAGS" + LIBS="$ax_pthread_save_LIBS" + + AC_MSG_RESULT([$ax_pthread_ok]) + AS_IF([test "x$ax_pthread_ok" = "xyes"], [break]) + + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" +done +fi + +# Various other checks: +if test "x$ax_pthread_ok" = "xyes"; then + ax_pthread_save_CFLAGS="$CFLAGS" + ax_pthread_save_LIBS="$LIBS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + + # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. + AC_CACHE_CHECK([for joinable pthread attribute], + [ax_cv_PTHREAD_JOINABLE_ATTR], + [ax_cv_PTHREAD_JOINABLE_ATTR=unknown + for ax_pthread_attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do + AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ], + [int attr = $ax_pthread_attr; return attr /* ; */])], + [ax_cv_PTHREAD_JOINABLE_ATTR=$ax_pthread_attr; break], + []) + done + ]) + AS_IF([test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xunknown" && \ + test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xPTHREAD_CREATE_JOINABLE" && \ + test "x$ax_pthread_joinable_attr_defined" != "xyes"], + [AC_DEFINE_UNQUOTED([PTHREAD_CREATE_JOINABLE], + [$ax_cv_PTHREAD_JOINABLE_ATTR], + [Define to necessary symbol if this constant + uses a non-standard name on your system.]) + ax_pthread_joinable_attr_defined=yes + ]) + + AC_CACHE_CHECK([whether more special flags are required for pthreads], + [ax_cv_PTHREAD_SPECIAL_FLAGS], + [ax_cv_PTHREAD_SPECIAL_FLAGS=no + case $host_os in + solaris*) + ax_cv_PTHREAD_SPECIAL_FLAGS="-D_POSIX_PTHREAD_SEMANTICS" + ;; + esac + ]) + AS_IF([test "x$ax_cv_PTHREAD_SPECIAL_FLAGS" != "xno" && \ + test "x$ax_pthread_special_flags_added" != "xyes"], + [PTHREAD_CFLAGS="$ax_cv_PTHREAD_SPECIAL_FLAGS $PTHREAD_CFLAGS" + ax_pthread_special_flags_added=yes]) + + AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT], + [ax_cv_PTHREAD_PRIO_INHERIT], + [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], + [[int i = PTHREAD_PRIO_INHERIT;]])], + [ax_cv_PTHREAD_PRIO_INHERIT=yes], + [ax_cv_PTHREAD_PRIO_INHERIT=no]) + ]) + AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes" && \ + test "x$ax_pthread_prio_inherit_defined" != "xyes"], + [AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], [1], [Have PTHREAD_PRIO_INHERIT.]) + ax_pthread_prio_inherit_defined=yes + ]) + + CFLAGS="$ax_pthread_save_CFLAGS" + LIBS="$ax_pthread_save_LIBS" + + # More AIX lossage: compile with *_r variant + if test "x$GCC" != "xyes"; then + case $host_os in + aix*) + AS_CASE(["x/$CC"], + [x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6], + [#handle absolute path differently from PATH based program lookup + AS_CASE(["x$CC"], + [x/*], + [AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"])], + [AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC])])]) + ;; + esac + fi +fi + +test -n "$PTHREAD_CC" || PTHREAD_CC="$CC" + +AC_SUBST([PTHREAD_LIBS]) +AC_SUBST([PTHREAD_CFLAGS]) +AC_SUBST([PTHREAD_CC]) + +# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: +if test "x$ax_pthread_ok" = "xyes"; then + ifelse([$1],,[AC_DEFINE([HAVE_PTHREAD],[1],[Define if you have POSIX threads libraries and header files.])],[$1]) + : +else + ax_pthread_ok=no + $2 +fi +AC_LANG_POP +])dnl AX_PTHREAD diff --git a/src/chiabls/cmake_modules/Findgmp.cmake b/src/chiabls/cmake_modules/Findgmp.cmake new file mode 100644 index 0000000000000..49e1aadabe8ba --- /dev/null +++ b/src/chiabls/cmake_modules/Findgmp.cmake @@ -0,0 +1,76 @@ +# Try to find the GMP library +# https://gmplib.org/ +# +# This module supports requiring a minimum version, e.g. you can do +# find_package(GMP 6.0.0) +# to require version 6.0.0 to newer of GMP. +# +# Once done this will define +# +# GMP_FOUND - system has GMP lib with correct version +# GMP_INCLUDES - the GMP include directory +# GMP_LIBRARIES - the GMP library +# GMP_VERSION - GMP version +# +# Copyright (c) 2016 Jack Poulson, +# Redistribution and use is allowed according to the terms of the BSD license. + +find_path(GMP_INCLUDES NAMES gmp.h PATHS $ENV{GMPDIR} ${INCLUDE_INSTALL_DIR}) + +# Set GMP_FIND_VERSION to 5.1.0 if no minimum version is specified +if(NOT GMP_FIND_VERSION) + if(NOT GMP_FIND_VERSION_MAJOR) + set(GMP_FIND_VERSION_MAJOR 5) + endif() + if(NOT GMP_FIND_VERSION_MINOR) + set(GMP_FIND_VERSION_MINOR 1) + endif() + if(NOT GMP_FIND_VERSION_PATCH) + set(GMP_FIND_VERSION_PATCH 0) + endif() + set(GMP_FIND_VERSION + "${GMP_FIND_VERSION_MAJOR}.${GMP_FIND_VERSION_MINOR}.${GMP_FIND_VERSION_PATCH}") +endif() + +message("GMP_INCLUDES=${GMP_INCLUDES}") +if(GMP_INCLUDES) + # Since the GMP version macros may be in a file included by gmp.h of the form + # gmp-.*[_]?.*.h (e.g., gmp-x86_64.h), we search each of them. + file(GLOB GMP_HEADERS "${GMP_INCLUDES}/gmp.h" "${GMP_INCLUDES}/gmp-*.h") + foreach(gmp_header_filename ${GMP_HEADERS}) + file(READ "${gmp_header_filename}" _gmp_version_header) + string(REGEX MATCH + "define[ \t]+__GNU_MP_VERSION[ \t]+([0-9]+)" _gmp_major_version_match + "${_gmp_version_header}") + if(_gmp_major_version_match) + set(GMP_MAJOR_VERSION "${CMAKE_MATCH_1}") + string(REGEX MATCH "define[ \t]+__GNU_MP_VERSION_MINOR[ \t]+([0-9]+)" + _gmp_minor_version_match "${_gmp_version_header}") + set(GMP_MINOR_VERSION "${CMAKE_MATCH_1}") + string(REGEX MATCH "define[ \t]+__GNU_MP_VERSION_PATCHLEVEL[ \t]+([0-9]+)" + _gmp_patchlevel_version_match "${_gmp_version_header}") + set(GMP_PATCHLEVEL_VERSION "${CMAKE_MATCH_1}") + set(GMP_VERSION + ${GMP_MAJOR_VERSION}.${GMP_MINOR_VERSION}.${GMP_PATCHLEVEL_VERSION}) + endif() + endforeach() + + # Check whether found version exists and exceeds the minimum requirement + if(NOT GMP_VERSION) + set(GMP_VERSION_OK FALSE) + message(STATUS "GMP version was not detected") + elseif(${GMP_VERSION} VERSION_LESS ${GMP_FIND_VERSION}) + set(GMP_VERSION_OK FALSE) + message(STATUS "GMP version ${GMP_VERSION} found in ${GMP_INCLUDES}, " + "but at least version ${GMP_FIND_VERSION} is required") + else() + set(GMP_VERSION_OK TRUE) + endif() +endif() + +find_library(GMP_LIBRARIES gmp PATHS $ENV{GMPDIR} ${LIB_INSTALL_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(gmp DEFAULT_MSG + GMP_INCLUDES GMP_LIBRARIES GMP_VERSION_OK) +mark_as_advanced(GMP_INCLUDES GMP_LIBRARIES) diff --git a/src/chiabls/cmake_modules/Findsodium.cmake b/src/chiabls/cmake_modules/Findsodium.cmake new file mode 100644 index 0000000000000..2bd83b120cdaa --- /dev/null +++ b/src/chiabls/cmake_modules/Findsodium.cmake @@ -0,0 +1,296 @@ +# Written in 2016 by Henrik Steffen Gaßmann +# +# To the extent possible under law, the author(s) have dedicated all +# copyright and related and neighboring rights to this software to the +# public domain worldwide. This software is distributed without any warranty. +# +# You should have received a copy of the CC0 Public Domain Dedication +# along with this software. If not, see +# +# http://creativecommons.org/publicdomain/zero/1.0/ +# +######################################################################## +# Tries to find the local libsodium installation. +# +# On Windows the sodium_DIR environment variable is used as a default +# hint which can be overridden by setting the corresponding cmake variable. +# +# Once done the following variables will be defined: +# +# sodium_FOUND +# sodium_INCLUDE_DIR +# sodium_LIBRARY_DEBUG +# sodium_LIBRARY_RELEASE +# +# +# Furthermore an imported "sodium" target is created. +# + +if (CMAKE_C_COMPILER_ID STREQUAL "GNU" + OR CMAKE_C_COMPILER_ID STREQUAL "Clang") + set(_GCC_COMPATIBLE 1) +endif() + +# static library option +if (NOT DEFINED sodium_USE_STATIC_LIBS) + option(sodium_USE_STATIC_LIBS "enable to statically link against sodium" OFF) +endif() +if(NOT (sodium_USE_STATIC_LIBS EQUAL sodium_USE_STATIC_LIBS_LAST)) + unset(sodium_LIBRARY CACHE) + unset(sodium_LIBRARY_DEBUG CACHE) + unset(sodium_LIBRARY_RELEASE CACHE) + unset(sodium_DLL_DEBUG CACHE) + unset(sodium_DLL_RELEASE CACHE) + set(sodium_USE_STATIC_LIBS_LAST ${sodium_USE_STATIC_LIBS} CACHE INTERNAL "internal change tracking variable") +endif() + + +######################################################################## +# UNIX +if (UNIX) + # import pkg-config + find_package(PkgConfig QUIET) + if (PKG_CONFIG_FOUND) + pkg_check_modules(sodium_PKG QUIET libsodium) + endif() + + if(sodium_USE_STATIC_LIBS) + foreach(_libname ${sodium_PKG_STATIC_LIBRARIES}) + if (NOT _libname MATCHES "^lib.*\\.a$") # ignore strings already ending with .a + list(INSERT sodium_PKG_STATIC_LIBRARIES 0 "lib${_libname}.a") + endif() + endforeach() + list(REMOVE_DUPLICATES sodium_PKG_STATIC_LIBRARIES) + + # if pkgconfig for libsodium doesn't provide + # static lib info, then override PKG_STATIC here.. + if (NOT sodium_PKG_STATIC_FOUND) + set(sodium_PKG_STATIC_LIBRARIES libsodium.a) + endif() + + set(XPREFIX sodium_PKG_STATIC) + else() + if (NOT sodium_PKG_FOUND) + set(sodium_PKG_LIBRARIES sodium) + endif() + + set(XPREFIX sodium_PKG) + endif() + + find_path(sodium_INCLUDE_DIR sodium.h + HINTS ${${XPREFIX}_INCLUDE_DIRS} + ) + find_library(sodium_LIBRARY_DEBUG NAMES ${${XPREFIX}_LIBRARIES} + HINTS ${${XPREFIX}_LIBRARY_DIRS} + ) + find_library(sodium_LIBRARY_RELEASE NAMES ${${XPREFIX}_LIBRARIES} + HINTS ${${XPREFIX}_LIBRARY_DIRS} + ) + + +######################################################################## +# Windows +elseif (WIN32) + set(sodium_DIR "$ENV{sodium_DIR}" CACHE FILEPATH "sodium install directory") + mark_as_advanced(sodium_DIR) + + find_path(sodium_INCLUDE_DIR sodium.h + HINTS ${sodium_DIR} + PATH_SUFFIXES include + ) + + if (MSVC) + # detect target architecture + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/arch.cpp" [=[ + #if defined _M_IX86 + #error ARCH_VALUE x86_32 + #elif defined _M_X64 + #error ARCH_VALUE x86_64 + #endif + #error ARCH_VALUE unknown + ]=]) + try_compile(_UNUSED_VAR "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/arch.cpp" + OUTPUT_VARIABLE _COMPILATION_LOG + ) + string(REGEX REPLACE ".*ARCH_VALUE ([a-zA-Z0-9_]+).*" "\\1" _TARGET_ARCH "${_COMPILATION_LOG}") + + # construct library path + if (_TARGET_ARCH STREQUAL "x86_32") + string(APPEND _PLATFORM_PATH "Win32") + elseif(_TARGET_ARCH STREQUAL "x86_64") + string(APPEND _PLATFORM_PATH "x64") + else() + message(FATAL_ERROR "the ${_TARGET_ARCH} architecture is not supported by Findsodium.cmake.") + endif() + string(APPEND _PLATFORM_PATH "/$$CONFIG$$") + + if (MSVC_VERSION LESS 1900) + math(EXPR _VS_VERSION "${MSVC_VERSION} / 10 - 60") + else() + math(EXPR _VS_VERSION "${MSVC_VERSION} / 10 - 50") + endif() + string(APPEND _PLATFORM_PATH "/v${_VS_VERSION}") + + if (sodium_USE_STATIC_LIBS) + string(APPEND _PLATFORM_PATH "/static") + else() + string(APPEND _PLATFORM_PATH "/dynamic") + endif() + + string(REPLACE "$$CONFIG$$" "Debug" _DEBUG_PATH_SUFFIX "${_PLATFORM_PATH}") + string(REPLACE "$$CONFIG$$" "Release" _RELEASE_PATH_SUFFIX "${_PLATFORM_PATH}") + + find_library(sodium_LIBRARY_DEBUG libsodium.lib + HINTS ${sodium_DIR} + PATH_SUFFIXES ${_DEBUG_PATH_SUFFIX} + ) + find_library(sodium_LIBRARY_RELEASE libsodium.lib + HINTS ${sodium_DIR} + PATH_SUFFIXES ${_RELEASE_PATH_SUFFIX} + ) + if (NOT sodium_USE_STATIC_LIBS) + set(CMAKE_FIND_LIBRARY_SUFFIXES_BCK ${CMAKE_FIND_LIBRARY_SUFFIXES}) + set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll") + find_library(sodium_DLL_DEBUG libsodium + HINTS ${sodium_DIR} + PATH_SUFFIXES ${_DEBUG_PATH_SUFFIX} + ) + find_library(sodium_DLL_RELEASE libsodium + HINTS ${sodium_DIR} + PATH_SUFFIXES ${_RELEASE_PATH_SUFFIX} + ) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_BCK}) + endif() + + elseif(_GCC_COMPATIBLE) + if (sodium_USE_STATIC_LIBS) + find_library(sodium_LIBRARY_DEBUG libsodium.a + HINTS ${sodium_DIR} + PATH_SUFFIXES lib + ) + find_library(sodium_LIBRARY_RELEASE libsodium.a + HINTS ${sodium_DIR} + PATH_SUFFIXES lib + ) + else() + find_library(sodium_LIBRARY_DEBUG libsodium.dll.a + HINTS ${sodium_DIR} + PATH_SUFFIXES lib + ) + find_library(sodium_LIBRARY_RELEASE libsodium.dll.a + HINTS ${sodium_DIR} + PATH_SUFFIXES lib + ) + + file(GLOB _DLL + LIST_DIRECTORIES false + RELATIVE "${sodium_DIR}/bin" + "${sodium_DIR}/bin/libsodium*.dll" + ) + find_library(sodium_DLL_DEBUG ${_DLL} libsodium + HINTS ${sodium_DIR} + PATH_SUFFIXES bin + ) + find_library(sodium_DLL_RELEASE ${_DLL} libsodium + HINTS ${sodium_DIR} + PATH_SUFFIXES bin + ) + endif() + else() + message(FATAL_ERROR "this platform is not supported by FindSodium.cmake") + endif() + + +######################################################################## +# unsupported +else() + message(FATAL_ERROR "this platform is not supported by FindSodium.cmake") +endif() + + +######################################################################## +# common stuff + +# extract sodium version +if (sodium_INCLUDE_DIR) + set(_VERSION_HEADER "${_INCLUDE_DIR}/sodium/version.h") + if (EXISTS _VERSION_HEADER) + file(READ "${_VERSION_HEADER}" _VERSION_HEADER_CONTENT) + string(REGEX REPLACE ".*#[ \t]*define[ \t]*SODIUM_VERSION_STRING[ \t]*\"([^\n]*)\".*" "\\1" + sodium_VERSION "${_VERSION_HEADER_CONTENT}") + set(sodium_VERSION "${sodium_VERSION}" PARENT_SCOPE) + endif() +endif() + +# communicate results +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + sodium # The name must be either uppercase or match the filename case. + REQUIRED_VARS + sodium_LIBRARY_RELEASE + sodium_LIBRARY_DEBUG + sodium_INCLUDE_DIR + VERSION_VAR + sodium_VERSION +) + +if(Sodium_FOUND) + set(sodium_LIBRARIES + optimized ${sodium_LIBRARY_RELEASE} debug ${sodium_LIBRARY_DEBUG}) +endif() + +# mark file paths as advanced +mark_as_advanced(sodium_INCLUDE_DIR) +mark_as_advanced(sodium_LIBRARY_DEBUG) +mark_as_advanced(sodium_LIBRARY_RELEASE) +if (WIN32) + mark_as_advanced(sodium_DLL_DEBUG) + mark_as_advanced(sodium_DLL_RELEASE) +endif() + +# create imported target +if(sodium_USE_STATIC_LIBS) + set(_LIB_TYPE STATIC) +else() + set(_LIB_TYPE SHARED) +endif() +if(NOT TARGET sodium) + add_library(sodium ${_LIB_TYPE} IMPORTED) +endif() + +set_target_properties(sodium PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${sodium_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" +) + +if (sodium_USE_STATIC_LIBS) + set_target_properties(sodium PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "SODIUM_STATIC" + IMPORTED_LOCATION "${sodium_LIBRARY_RELEASE}" + IMPORTED_LOCATION_DEBUG "${sodium_LIBRARY_DEBUG}" + ) +else() + if (UNIX) + set_target_properties(sodium PROPERTIES + IMPORTED_LOCATION "${sodium_LIBRARY_RELEASE}" + IMPORTED_LOCATION_DEBUG "${sodium_LIBRARY_DEBUG}" + ) + elseif (WIN32) + set_target_properties(sodium PROPERTIES + IMPORTED_IMPLIB "${sodium_LIBRARY_RELEASE}" + IMPORTED_IMPLIB_DEBUG "${sodium_LIBRARY_DEBUG}" + ) + if (NOT (sodium_DLL_DEBUG MATCHES ".*-NOTFOUND")) + set_target_properties(sodium PROPERTIES + IMPORTED_LOCATION_DEBUG "${sodium_DLL_DEBUG}" + ) + endif() + if (NOT (sodium_DLL_RELEASE MATCHES ".*-NOTFOUND")) + set_target_properties(sodium PROPERTIES + IMPORTED_LOCATION_RELWITHDEBINFO "${sodium_DLL_RELEASE}" + IMPORTED_LOCATION_MINSIZEREL "${sodium_DLL_RELEASE}" + IMPORTED_LOCATION_RELEASE "${sodium_DLL_RELEASE}" + ) + endif() + endif() +endif() diff --git a/src/chiabls/configure.ac b/src/chiabls/configure.ac new file mode 100644 index 0000000000000..f15182b11c54b --- /dev/null +++ b/src/chiabls/configure.ac @@ -0,0 +1,466 @@ +AC_PREREQ([2.60]) +AC_INIT([libchiabls],[0.1]) +AC_CONFIG_AUX_DIR([build-aux]) +AC_CONFIG_MACRO_DIR([build-aux/m4]) + +dnl Unless the user specified ARFLAGS, force it to be cr +AC_ARG_VAR(ARFLAGS, [Flags for the archiver, defaults to if not set]) +if test "x${ARFLAGS+set}" != "xset"; then + ARFLAGS="qc" +fi + +AC_CANONICAL_HOST + +AH_TOP([#ifndef RLC_CONF_H]) +AH_TOP([#define RLC_CONF_H]) +AH_BOTTOM([#endif /*RLC_CONF_H*/]) +AM_INIT_AUTOMAKE([foreign subdir-objects]) + +dnl faketime messes with timestamps and causes configure to be re-run. +dnl --disable-maintainer-mode can be used to bypass this. +AM_MAINTAINER_MODE([enable]) + +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${CXXFLAGS+set}" = "xset"; then + CXXFLAGS_overridden=yes +else + CXXFLAGS_overridden=no +fi +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. +case $host in + *mingw*) + lt_cv_deplibs_check_method="pass_all" + ;; +esac +dnl Require C++14 compiler (no GNU extensions) +AX_CXX_COMPILE_STDCXX([14], [noext], [mandatory], [nodefault]) + +dnl Libtool init checks. +LT_INIT([pic-only]) + +AC_PATH_TOOL(AR, ar) +AC_PATH_TOOL(RANLIB, ranlib) +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)]), + [use_tests=$enableval], + [use_tests=yes]) + +AC_ARG_ENABLE(bench, + AS_HELP_STRING([--disable-bench],[do not compile benchmarks (default is to compile)]), + [use_bench=$enableval], + [use_bench=yes]) + + +dnl Define enum mappings for relic config +AC_DEFINE([RLC_VERSION], ["0.5.0"], [Relic Version]) +AC_DEFINE([AVR], [1], [Atmel AVR ATMega128 8-bit architecture.]) +AC_DEFINE([MSP], [2], [MSP430 16-bit architecture.]) +AC_DEFINE([ARM], [3], [ARM 32-bit architecture.]) +AC_DEFINE([X86], [4], [Intel x86-compatible 32-bit architecture.]) +AC_DEFINE([X64], [5], [AMD64-compatible 64-bit architecture.]) +AC_DEFINE([EASY], [1], [Easy C-only backend.]) +AC_DEFINE([GMP], [2], [GMP backend.]) +AC_DEFINE([GMP_SEC], [3], [GMP constant-time backend.]) +AC_DEFINE([SINGLE], [0], [A multiple precision integer can store w words.]) +AC_DEFINE([CARRY], [1], [A multiple precision integer can store the result of an addition.]) +AC_DEFINE([DOUBLE], [2], [A multiple precision integer can store the result of a multiplication.]) +AC_DEFINE([BASIC], [1], [Basic method.]) +AC_DEFINE([PRIME], [1], [Prime curves.]) +AC_DEFINE([TATEP], [1], [Tate pairing.]) +AC_DEFINE([AUTO], [1], [Automatic memory allocation.]) +AC_DEFINE([HASHD], [1], [NIST HASH-DRBG generator.]) +AC_DEFINE([LIBC], [1], [Standard C library generator.]) +AC_DEFINE([OPENMP], [1], [OpenMP multithreading support.]) +AC_DEFINE([LINUX], [1], [GNU/Linux operating system.]) +AC_DEFINE([HREAL], [1], [Per-process high-resolution timer.]) +AC_DEFINE([COMBA], [2], [Comba method.]) +AC_DEFINE([LEHME], [2], [Lehmer's fast GCD Algorithm.]) +AC_DEFINE([SAFEP], [2], [Safe prime generation.]) +AC_DEFINE([QUICK], [2], [Fast reduction modulo special form prime.]) +AC_DEFINE([BINAR], [2], [Binary inversion.]) +AC_DEFINE([LAZYR], [2], [Lazy-reduced extension field arithmetic.]) +AC_DEFINE([LODAH], [2], [Lopez-Dahab multiplication.]) +AC_DEFINE([SLIDE], [2], [Sliding window modular exponentiation.]) +AC_DEFINE([PROJC], [2], [Projective coordinates.]) +AC_DEFINE([COMBS], [2], [Single-table comb method.]) +AC_DEFINE([TRICK], [2], [Shamir's trick.]) +AC_DEFINE([CHAR2], [2], [Binary curves.]) +AC_DEFINE([WEILP], [2], [Weil pairing.]) +AC_DEFINE([SH224], [2], [SHA-224 hash function.]) +AC_DEFINE([PKCS1], [2], [RSA PKCS#1 v1.5 padding.]) +AC_DEFINE([DYNAMIC], [2], [Dynamic memory allocation.]) +AC_DEFINE([RDRND], [2], [Intel RdRand instruction.]) +AC_DEFINE([FREEBSD], [2], [FreeBSD operating system.]) +AC_DEFINE([PTHREAD], [2], [POSIX multithreading support.]) +AC_DEFINE([HPROC], [2], [Per-process high-resolution timer.]) +AC_DEFINE([MONTY], [3], [Montgomery method.]) +AC_DEFINE([STEIN], [3], [Stein's binary GCD Algorithm.]) +AC_DEFINE([STRON], [3], [Strong prime generation.]) +AC_DEFINE([INTEG], [3], [Integrated modular addtion.]) +AC_DEFINE([INTER], [3], [Interleaving of w-(T)NAFs.]) +AC_DEFINE([ALMOS], [3], [Almost inverse algorithm.]) +AC_DEFINE([JACOB], [3], [Jacobian coordinates.]) +AC_DEFINE([COMBD], [3], [Double-table comb method.]) +AC_DEFINE([HALVE], [3], [Halving.]) +AC_DEFINE([EDDIE], [3], [Edwards curves.]) +AC_DEFINE([EXTND], [3], [Extended projective twisted Edwards coordinates.]) +AC_DEFINE([OATEP], [3], [Optimal ate pairing.]) +AC_DEFINE([SH256], [3], [SHA-256 hash function.]) +AC_DEFINE([PKCS2], [3], [RSA PKCS#1 v2.1 padding.]) +AC_DEFINE([UDEV], [3], [Operating system underlying generator.]) +AC_DEFINE([MACOSX], [3], [MacOS operating system.]) +AC_DEFINE([HTHRD], [3], [Per-thread high-resolution timer.]) +AC_DEFINE([PMERS], [4], [Pseudo-Mersenne method.]) +AC_DEFINE([MULTP], [4], [Reuse multiplication for squaring.]) +AC_DEFINE([EXGCD], [4], [Extended Euclidean algorithm.]) +AC_DEFINE([LWNAF], [4], [Left-to-right Width-w NAF.]) +AC_DEFINE([JOINT], [4], [Joint sparse form.]) +AC_DEFINE([SH384], [4], [SHA-384 hash function.]) +AC_DEFINE([CALL], [4], [Override library generator with the callback.]) +AC_DEFINE([WCGR], [4], [Use Windows' CryptGenRandom.]) +AC_DEFINE([WINDOWS], [4], [Windows operating system.]) +AC_DEFINE([POSIX], [4], [POSIX-compatible timer.]) +AC_DEFINE([DIVST], [5], [Constant-time inversion by Bernstein-Yang division steps.]) +AC_DEFINE([ITOHT], [5], [Itoh-Tsuji inversion.]) +AC_DEFINE([LWREG], [5], [Left-to-right Width-w NAF.]) +AC_DEFINE([SH512], [5], [SHA-512 hash function.]) +AC_DEFINE([DROID], [5], [Android operating system.]) +AC_DEFINE([ANSI], [5], [ANSI-compatible timer.]) +AC_DEFINE([BRUCH], [6], [Hardware-friendly inversion by Brunner-Curiger-Hofstetter.]) +AC_DEFINE([B2S160], [6], [BLAKE2s-160 hash function.]) +AC_DEFINE([DUINO], [6], [Arduino platform.]) +AC_DEFINE([CYCLE], [6], [Cycle-counting timer.]) +AC_DEFINE([CTAIA], [7], [Constant-time version of almost inverse.]) +AC_DEFINE([B2S256], [7], [BLAKE2s-256 hash function.]) +AC_DEFINE([OPENBSD], [7], [OpenBSD operating system.]) +AC_DEFINE([PERF], [7], [Performance monitoring framework.]) +AC_DEFINE([LOWER], [8], [Use implementation provided by the lower layer.]) + +use_pkgconfig=yes +case $host in + *darwin*) + CPU_ARCH="x64" + AC_DEFINE([ARCH], [X64], [Architecture.]) + AC_DEFINE([WSIZE], [64], [Size of word in this architecture.]) + AC_DEFINE([SEED], [UDEV], [Chosen random generator seeder.]) + AC_DEFINE([FP_QNRES], [], [Use -1 as quadratic non-residue.]) + AC_DEFINE([OPSYS], [MACOSX], [Detected operation system.]) + if test x$cross_compiling != xyes; then + AC_PATH_PROG([BREW],brew,) + if test x$BREW != x; then + dnl These Homebrew packages may be keg-only, meaning that they won't be found + dnl in expected paths because they may conflict with system files. Ask + dnl 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_LIBS="-L$gmp_prefix/lib" + fi + fi + fi + ;; + *linux*) + AC_DEFINE([SEED], [UDEV], [Chosen random generator seeder.]) + AC_DEFINE([FP_QNRES], [], [Use -1 as quadratic non-residue.]) + AC_DEFINE([OPSYS], [LINUX], [Detected operation system.]) + RELIC_CPPFLAGS="-D_GNU_SOURCE" + case $host_cpu in + x86_64) + CPU_ARCH="x64" + AC_DEFINE([ARCH], [X64], [Architecture.]) + AC_DEFINE([WSIZE], [64], [Size of word in this architecture.]) + ;; + i?86) + CPU_ARCH="x86" + AC_DEFINE([ARCH], [X86], [Architecture.]) + AC_DEFINE([WSIZE], [32], [Size of word in this architecture.]) + ;; + arm*) + CPU_ARCH="arm" + AC_DEFINE([ARCH], [ARM], [Architecture.]) + AC_DEFINE([WSIZE], [32], [Size of word in this architecture.]) + ;; + aarch*) + dnl Relic doesn't support aarch64 yet, set CPU_ARCH to none. + CPU_ARCH="none" + AC_DEFINE([ARCH], [ARM], [Architecture.]) + AC_DEFINE([WSIZE], [64], [Size of word in this architecture.]) + ;; + *) + CPU_ARCH="none" + AC_DEFINE([WSIZE], [64], [Size of word in this architecture.]) + ;; + esac + ;; + *mingw*) + use_pkgconfig=no + CPU_ARCH="x64" + AC_DEFINE([ARCH], [X64], [Architecture.]) + AC_DEFINE([WSIZE], [64], [Size of word in this architecture.]) + AC_DEFINE([SEED], [WCGR], [Chosen random generator seeder.]) + AC_DEFINE([OPSYS], [WINDOWS], [Detected operation system.]) + LIBTOOL_APP_LDFLAGS="$LIBTOOL_APP_LDFLAGS -all-static" + + dnl libtool insists upon adding -nostdlib and a list of objects/libs to link against. + dnl That breaks our ability to build dll's with static libgcc/libstdc++/libssp. Override + dnl its command here, with the predeps/postdeps removed, and -static inserted. Postdeps are + dnl also overridden to prevent their insertion later. + dnl This should only affect dll's. + archive_cmds_CXX="\$CC -shared \$libobjs \$deplibs \$compiler_flags -static -o \$output_objdir/\$soname \${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker \$lib" + postdeps_CXX= + ;; +esac + +if test x$use_pkgconfig = xyes; then + m4_ifndef([PKG_PROG_PKG_CONFIG], [AC_MSG_ERROR(PKG_PROG_PKG_CONFIG macro not found. Please install pkg-config and re-run autogen.sh.)]) + m4_ifdef([PKG_PROG_PKG_CONFIG], [ + PKG_PROG_PKG_CONFIG + if test x"$PKG_CONFIG" = "x"; then + AC_MSG_ERROR(pkg-config not found.) + fi + ]) +fi + +saved_CFLAGS="$CFLAGS" +CFLAGS="$CFLAGS -pipe" +AC_MSG_CHECKING([if ${CC} supports -pipe]) +AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])], + [ AC_MSG_RESULT([yes]) ], + [ AC_MSG_RESULT([no]) + CFLAGS="$saved_CFLAGS" + ]) + +saved_CFLAGS="$CFLAGS" +CFLAGS="$CFLAGS -fomit-frame-pointer" +AC_MSG_CHECKING([if ${CC} supports -fomit-frame-pointer]) +AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])], + [ AC_MSG_RESULT([yes]) ], + [ AC_MSG_RESULT([no]) + 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]) + +dnl set default settings for relic +AC_DEFINE([ALIGN], [1], [Byte boundary to align digit vectors.]) + +AC_DEFINE(WITH_BN,, Build multiple precision integer module.) +AC_DEFINE(WITH_DV,, Temporary double-precision digit vectors.) +AC_DEFINE(WITH_FP,, Build prime field module.) +AC_DEFINE(WITH_FPX,, Build prime field extension module.) +AC_DEFINE(WITH_FB,, Build binary field module.) +AC_DEFINE(WITH_FBX,, Build binary field extension module.) +AC_DEFINE(WITH_EP,, Build prime elliptic curve module.) +AC_DEFINE(WITH_EPX,, Build prime field extension elliptic curve module.) +AC_DEFINE(WITH_EB,, Build binary elliptic curve module.) +AC_DEFINE(WITH_ED,, Build elliptic Edwards curve module.) +AC_DEFINE(WITH_EC,, Build elliptic curve cryptography module.) +AC_DEFINE(WITH_PP,, Build pairings over prime curves module.) +AC_DEFINE(WITH_PC,, Build pairing-based cryptography module.) +AC_DEFINE(WITH_BC,, Build block ciphers.) +AC_DEFINE(WITH_MD,, Build hash functions.) +AC_DEFINE(WITH_CP,, Build cryptographic protocols.) +AC_DEFINE(WITH_MPC,, Build Multi-party computation primitives.) + +AC_DEFINE(BN_PRECI, 1024, Required precision in bits.) +AC_DEFINE(BN_KARAT, 0, Number of Karatsuba steps.) +AC_DEFINE(BN_MAGNI, [DOUBLE], Effective size of a multiple precision integer.) + +AC_DEFINE(BN_METHD, "COMBA;COMBA;MONTY;SLIDE;BASIC;BASIC", Multiple precision arithmetic method.) +AC_DEFINE(BN_MUL, COMBA, Chosen multiple precision multiplication method.) +AC_DEFINE(BN_SQR, COMBA, Chosen multiple precision multiplication method.) +AC_DEFINE(BN_MOD, MONTY, Chosen multiple precision modular reduction method.) +AC_DEFINE(BN_MXP, SLIDE, Chosen multiple precision modular exponentiation method.) +AC_DEFINE(BN_GCD, BASIC, Chosen multiple precision greatest common divisor method.) +AC_DEFINE(BN_GEN, BASIC, Chosen prime generation algorithm.) + +AC_DEFINE(FP_PRIME, 381, Prime field size in bits.) +AC_DEFINE(FP_METHD, "INTEG;INTEG;INTEG;MONTY;LOWER;SLIDE", Prime field arithmetic method.) +AC_DEFINE(FP_KARAT, 0, Number of Karatsuba steps.) +AC_DEFINE(FP_WIDTH, 4, Width of window processing for exponentiation methods.) +AC_DEFINE(FP_ADD, INTEG, Chosen prime field multiplication method.) +AC_DEFINE(FP_MUL, INTEG, Chosen prime field multiplication method.) +AC_DEFINE(FP_SQR, INTEG, Chosen prime field multiplication method.) +AC_DEFINE(FP_RDC, MONTY, Chosen prime field reduction method.) +AC_DEFINE(FP_INV, LOWER, Chosen prime field inversion method.) +AC_DEFINE(FP_EXP, SLIDE, Chosen multiple precision modular exponentiation method.) + +AC_DEFINE(FPX_METHD, "INTEG;INTEG;LAZYR", Prime extension field arithmetic method.) +AC_DEFINE(FPX_QDR, INTEG, Chosen extension field arithmetic method.) +AC_DEFINE(FPX_CBC, INTEG, Chosen extension field arithmetic method.) +AC_DEFINE(FPX_RDC, LAZYR, Chosen extension field arithmetic method.) + +AC_DEFINE(FB_METHD, "LODAH;QUICK;QUICK;QUICK;QUICK;QUICK;EXGCD;SLIDE;QUICK", Binary field arithmetic method) +AC_DEFINE(FB_POLYN, 283, Irreducible polynomial size in bits.) +AC_DEFINE(FB_KARAT, 0, Number of Karatsuba levels.) +AC_DEFINE(FB_TRINO,, Prefer trinomials over pentanomials.) +AC_DEFINE(FB_PRECO,, Precompute multiplication table for sqrt(z).) +AC_DEFINE(FB_WIDTH, 4, Width of window processing for exponentiation methods.) +AC_DEFINE(FB_MUL, LODAH, Chosen binary field multiplication method.) +AC_DEFINE(FB_SQR, QUICK, Chosen binary field squaring method.) +AC_DEFINE(FB_RDC, QUICK, Chosen binary field modular reduction method.) +AC_DEFINE(FB_SRT, QUICK, Chosen binary field modular reduction method.) +AC_DEFINE(FB_TRC, QUICK, Chosen trace computation method.) +AC_DEFINE(FB_SLV, QUICK, Chosen method to solve a quadratic equation.) +AC_DEFINE(FB_INV, EXGCD, Chosen binary field inversion method.) +AC_DEFINE(FB_EXP, SLIDE, Chosen multiple precision modular exponentiation method.) +AC_DEFINE(FB_ITR, QUICK, Chosen method to solve a quadratic equation.) + +AC_DEFINE(EP_METHD, "PROJC;LWNAF;COMBS;INTER", Prime elliptic curve arithmetic method.) +AC_DEFINE(EP_ENDOM,, Support for prime curves with efficient endormorphisms.) +AC_DEFINE(EP_MIXED,, Use mixed coordinates.) +AC_DEFINE(EP_PRECO,, Build precomputation table for generator.) +AC_DEFINE(EP_CTMAP,, Enable isogeny map for SSWU map-to-curve.) +AC_DEFINE(EP_DEPTH, 4, Width of precomputation table for fixed point methods.) +AC_DEFINE(EP_WIDTH, 4, Width of window processing for unknown point methods.) +AC_DEFINE(EP_ADD, PROJC, Chosen prime elliptic curve coordinate method.) +AC_DEFINE(EP_MUL, LWNAF, Chosen prime elliptic curve point multiplication method.) +AC_DEFINE(EP_FIX, COMBS, Chosen prime elliptic curve point multiplication method.) +AC_DEFINE(EP_SIM, INTER, Chosen prime elliptic curve simulteanous point multiplication method.) + +AC_DEFINE(EB_METHD, "PROJC;LWNAF;COMBS;INTER", Binary elliptic curve arithmetic method.) +AC_DEFINE(EB_PLAIN,, Support for ordinary curves without endormorphisms.) +AC_DEFINE(EB_KBLTZ,, Support for Koblitz anomalous binary curves.) +AC_DEFINE(EB_MIXED,, Use mixed coordinates.) +AC_DEFINE(EB_PRECO,, Build precomputation table for generator.) +AC_DEFINE(EB_DEPTH, 4, Width of precomputation table for fixed point methods.) +AC_DEFINE(EB_WIDTH, 4, Width of window processing for unknown point methods.) +AC_DEFINE(EB_ADD, PROJC, Chosen binary elliptic curve coordinate method.) +AC_DEFINE(EB_MUL, LWNAF, Chosen binary elliptic curve point multiplication method.) +AC_DEFINE(EB_FIX, COMBS, Chosen binary elliptic curve point multiplication method.) +AC_DEFINE(EB_SIM, INTER, Chosen binary elliptic curve simulteanous point multiplication method.) + +AC_DEFINE(ED_METHD, "PROJC;LWNAF;COMBS;INTER", Edwards elliptic curve arithmetic method.) +AC_DEFINE(ED_PRECO,, Build precomputation table for generator.) +AC_DEFINE(ED_DEPTH, 4, Width of precomputation table for fixed point methods.) +AC_DEFINE(ED_WIDTH, 4, Width of window processing for unknown point methods.) +AC_DEFINE(ED_ADD, PROJC, Chosen binary elliptic curve coordinate method.) +AC_DEFINE(ED_MUL, LWNAF, Chosen prime elliptic twisted Edwards curve point multiplication method.) +AC_DEFINE(ED_FIX, COMBS, Chosen prime elliptic twisted Edwards curve point multiplication method.) +AC_DEFINE(ED_SIM, INTER, Chosen prime elliptic curve simulteanous point multiplication method.) + +AC_DEFINE(EC_METHD, "PRIME", Chosen elliptic curve cryptography method.) +AC_DEFINE(EC_CUR, PRIME, Chosen elliptic curve type.) + +AC_DEFINE(PP_METHD, "LAZYR;OATEP", Bilinear pairing method.) +AC_DEFINE(PP_EXT, LAZYR, Chosen extension field arithmetic method.) +AC_DEFINE(PP_MAP, OATEP, Chosen pairing method over prime elliptic curves.) + +AC_DEFINE(MD_METHD, "SH256", Choice of hash function.) +AC_DEFINE(MD_MAP, SH256, Chosen hash function.) + +AC_DEFINE(CP_CRT,, Support for faster CRT-based exponentiation in factoring-based cryptosystems.) +AC_DEFINE(CP_RSAPD, PKCS2, Chosen RSA padding method.) + +AC_DEFINE(ALLOC, AUTO, Chosen memory allocation policy.) +AC_DEFINE(RAND, HASHD, Chosen random generator.) +AC_DEFINE(MULTI, PTHREAD, Chosen multithreading API.) +AC_DEFINE(TIMER, CYCLE, Chosen timer.) + + +AC_CHECK_HEADER(gmp.h,[AC_CHECK_LIB(gmp, __gmpz_init,[has_gmp=yes; GMP_LIBS=-lgmp;])], AC_MSG_ERROR(gmp headers missing),) + +if test x$has_gmp = xyes; then + AC_DEFINE(ARITH, GMP, Arithmetic backend.) +fi + +if test x$use_pkgconfig = xyes; then + : dnl + m4_ifdef( + [PKG_CHECK_MODULES], + [ + PKG_CHECK_MODULES([SODIUM], [libsodium],, [AC_MSG_ERROR(libsodium not found.)]) + ] + ) +else + AC_CHECK_HEADER([sodium/core.h],, AC_MSG_ERROR(libsodium headers missing),) + AC_CHECK_LIB([sodium],[main],SODIUM_LIBS=-lsodium, AC_MSG_ERROR(libsodium missing)) +fi + +dnl Check for pthread compile/link requirements +AX_PTHREAD + +AC_SEARCH_LIBS([clock_gettime],[rt]) + +AC_MSG_CHECKING([whether to build runtest]) +if test x$use_tests = xyes; then + AC_MSG_RESULT([yes]) + BUILD_TEST="yes" +else + AC_MSG_RESULT([no]) + BUILD_TEST="" +fi + +AC_MSG_CHECKING([whether to build runbench]) +if test x$use_bench = xyes; then + AC_MSG_RESULT([yes]) + BUILD_BENCH="yes" +else + AC_MSG_RESULT([no]) + BUILD_BENCH="" +fi + +AM_CONDITIONAL(WITH_BN, test 1 -eq 1) +AM_CONDITIONAL(WITH_FP, test 1 -eq 1) +AM_CONDITIONAL(WITH_FPX, test 1 -eq 1) +AM_CONDITIONAL(WITH_FB, test 1 -eq 1) +AM_CONDITIONAL(WITH_EP, test 1 -eq 1) +AM_CONDITIONAL(WITH_EPX, test 1 -eq 1) +AM_CONDITIONAL(WITH_EB, test 1 -eq 1) +AM_CONDITIONAL(WITH_ED, test 1 -eq 1) +AM_CONDITIONAL(WITH_EC, test 1 -eq 1) +AM_CONDITIONAL(WITH_PP, test 1 -eq 1) +AM_CONDITIONAL(WITH_PC, test 1 -eq 1) +AM_CONDITIONAL(WITH_BC, test 1 -eq 1) +AM_CONDITIONAL(WITH_MD, test 1 -eq 1) +AM_CONDITIONAL(WITH_CP, test 1 -eq 1) +AM_CONDITIONAL(WITH_MPC, test 1 -eq 1) +AM_CONDITIONAL(WITH_DV, test 1 -eq 1) +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]) +AC_SUBST(CPU_ARCH) +AC_SUBST(RAND_PATH, hashd) +AC_SUBST(SODIUM_CPPFLAGS) +AC_SUBST(SODIUM_LIBS) +AC_SUBST(GMP_CPPFLAGS) +AC_SUBST(GMP_LIBS) +AC_SUBST(RELIC_CPPFLAGS) +AC_SUBST(WARN_CFLAGS) +AC_SUBST(NOWARN_CFLAGS) +AC_SUBST(LIBTOOL_APP_LDFLAGS) + + +AC_CONFIG_HEADERS([contrib/relic/include/relic_conf.h]) +AC_CONFIG_FILES([Makefile]) + +AC_OUTPUT \ No newline at end of file diff --git a/src/chiabls/contrib/catch/catch.hpp b/src/chiabls/contrib/catch/catch.hpp new file mode 100644 index 0000000000000..0384171ae4a78 --- /dev/null +++ b/src/chiabls/contrib/catch/catch.hpp @@ -0,0 +1,17881 @@ +/* + * Catch v2.13.4 + * Generated: 2020-12-29 14:48:00.116107 + * ---------------------------------------------------------- + * This file has been merged from multiple headers. Please don't edit it directly + * Copyright (c) 2020 Two Blue Cubes Ltd. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ +#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED +#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED +// start catch.hpp + + +#define CATCH_VERSION_MAJOR 2 +#define CATCH_VERSION_MINOR 13 +#define CATCH_VERSION_PATCH 4 + +#ifdef __clang__ +# pragma clang system_header +#elif defined __GNUC__ +# pragma GCC system_header +#endif + +// start catch_suppress_warnings.h + +#ifdef __clang__ +# ifdef __ICC // icpc defines the __clang__ macro +# pragma warning(push) +# pragma warning(disable: 161 1682) +# else // __ICC +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wpadded" +# pragma clang diagnostic ignored "-Wswitch-enum" +# pragma clang diagnostic ignored "-Wcovered-switch-default" +# endif +#elif defined __GNUC__ + // Because REQUIREs trigger GCC's -Wparentheses, and because still + // supported version of g++ have only buggy support for _Pragmas, + // Wparentheses have to be suppressed globally. +# pragma GCC diagnostic ignored "-Wparentheses" // See #674 for details + +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wunused-variable" +# pragma GCC diagnostic ignored "-Wpadded" +#endif +// end catch_suppress_warnings.h +#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER) +# define CATCH_IMPL +# define CATCH_CONFIG_ALL_PARTS +#endif + +// In the impl file, we want to have access to all parts of the headers +// Can also be used to sanely support PCHs +#if defined(CATCH_CONFIG_ALL_PARTS) +# define CATCH_CONFIG_EXTERNAL_INTERFACES +# if defined(CATCH_CONFIG_DISABLE_MATCHERS) +# undef CATCH_CONFIG_DISABLE_MATCHERS +# endif +# if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) +# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER +# endif +#endif + +#if !defined(CATCH_CONFIG_IMPL_ONLY) +// start catch_platform.h + +#ifdef __APPLE__ +# include +# if TARGET_OS_OSX == 1 +# define CATCH_PLATFORM_MAC +# elif TARGET_OS_IPHONE == 1 +# define CATCH_PLATFORM_IPHONE +# endif + +#elif defined(linux) || defined(__linux) || defined(__linux__) +# define CATCH_PLATFORM_LINUX + +#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__) +# define CATCH_PLATFORM_WINDOWS +#endif + +// end catch_platform.h + +#ifdef CATCH_IMPL +# ifndef CLARA_CONFIG_MAIN +# define CLARA_CONFIG_MAIN_NOT_DEFINED +# define CLARA_CONFIG_MAIN +# endif +#endif + +// start catch_user_interfaces.h + +namespace Catch { + unsigned int rngSeed(); +} + +// end catch_user_interfaces.h +// start catch_tag_alias_autoregistrar.h + +// start catch_common.h + +// start catch_compiler_capabilities.h + +// Detect a number of compiler features - by compiler +// The following features are defined: +// +// CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported? +// CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported? +// CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported? +// CATCH_CONFIG_DISABLE_EXCEPTIONS : Are exceptions enabled? +// **************** +// Note to maintainers: if new toggles are added please document them +// in configuration.md, too +// **************** + +// In general each macro has a _NO_ form +// (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature. +// Many features, at point of detection, define an _INTERNAL_ macro, so they +// can be combined, en-mass, with the _NO_ forms later. + +#ifdef __cplusplus + +# if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) +# define CATCH_CPP14_OR_GREATER +# endif + +# if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) +# define CATCH_CPP17_OR_GREATER +# endif + +#endif + +// We have to avoid both ICC and Clang, because they try to mask themselves +// as gcc, and we want only GCC in this block +#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && !defined(__CUDACC__) +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" ) + +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) + +#endif + +#if defined(__clang__) + +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" ) + +// As of this writing, IBM XL's implementation of __builtin_constant_p has a bug +// which results in calls to destructors being emitted for each temporary, +// without a matching initialization. In practice, this can result in something +// like `std::string::~string` being called on an uninitialized value. +// +// For example, this code will likely segfault under IBM XL: +// ``` +// REQUIRE(std::string("12") + "34" == "1234") +// ``` +// +// Therefore, `CATCH_INTERNAL_IGNORE_BUT_WARN` is not implemented. +# if !defined(__ibmxl__) && !defined(__CUDACC__) +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) /* NOLINT(cppcoreguidelines-pro-type-vararg, hicpp-vararg) */ +# endif + +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \ + _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"") + +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) + +# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" ) + +# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" ) + +# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wunused-template\"" ) + +#endif // __clang__ + +//////////////////////////////////////////////////////////////////////////////// +// Assume that non-Windows platforms support posix signals by default +#if !defined(CATCH_PLATFORM_WINDOWS) + #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS +#endif + +//////////////////////////////////////////////////////////////////////////////// +// We know some environments not to support full POSIX signals +#if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__) + #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS +#endif + +#ifdef __OS400__ +# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS +# define CATCH_CONFIG_COLOUR_NONE +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Android somehow still does not support std::to_string +#if defined(__ANDROID__) +# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING +# define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Not all Windows environments support SEH properly +#if defined(__MINGW32__) +# define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH +#endif + +//////////////////////////////////////////////////////////////////////////////// +// PS4 +#if defined(__ORBIS__) +# define CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Cygwin +#ifdef __CYGWIN__ + +// Required for some versions of Cygwin to declare gettimeofday +// see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin +# define _BSD_SOURCE +// some versions of cygwin (most) do not support std::to_string. Use the libstd check. +// https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813 +# if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \ + && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)) + +# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING + +# endif +#endif // __CYGWIN__ + +//////////////////////////////////////////////////////////////////////////////// +// Visual C++ +#if defined(_MSC_VER) + +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION __pragma( warning(push) ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION __pragma( warning(pop) ) + +// Universal Windows platform does not support SEH +// Or console colours (or console at all...) +# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) +# define CATCH_CONFIG_COLOUR_NONE +# else +# define CATCH_INTERNAL_CONFIG_WINDOWS_SEH +# endif + +// MSVC traditional preprocessor needs some workaround for __VA_ARGS__ +// _MSVC_TRADITIONAL == 0 means new conformant preprocessor +// _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor +# if !defined(__clang__) // Handle Clang masquerading for msvc +# if !defined(_MSVC_TRADITIONAL) || (defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL) +# define CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +# endif // MSVC_TRADITIONAL +# endif // __clang__ + +#endif // _MSC_VER + +#if defined(_REENTRANT) || defined(_MSC_VER) +// Enable async processing, as -pthread is specified or no additional linking is required +# define CATCH_INTERNAL_CONFIG_USE_ASYNC +#endif // _MSC_VER + +//////////////////////////////////////////////////////////////////////////////// +// Check if we are compiled with -fno-exceptions or equivalent +#if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND) +# define CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED +#endif + +//////////////////////////////////////////////////////////////////////////////// +// DJGPP +#ifdef __DJGPP__ +# define CATCH_INTERNAL_CONFIG_NO_WCHAR +#endif // __DJGPP__ + +//////////////////////////////////////////////////////////////////////////////// +// Embarcadero C++Build +#if defined(__BORLANDC__) + #define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN +#endif + +//////////////////////////////////////////////////////////////////////////////// + +// Use of __COUNTER__ is suppressed during code analysis in +// CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly +// handled by it. +// Otherwise all supported compilers support COUNTER macro, +// but user still might want to turn it off +#if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L ) + #define CATCH_INTERNAL_CONFIG_COUNTER +#endif + +//////////////////////////////////////////////////////////////////////////////// + +// RTX is a special version of Windows that is real time. +// This means that it is detected as Windows, but does not provide +// the same set of capabilities as real Windows does. +#if defined(UNDER_RTSS) || defined(RTX64_BUILD) + #define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH + #define CATCH_INTERNAL_CONFIG_NO_ASYNC + #define CATCH_CONFIG_COLOUR_NONE +#endif + +#if !defined(_GLIBCXX_USE_C99_MATH_TR1) +#define CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER +#endif + +// Various stdlib support checks that require __has_include +#if defined(__has_include) + // Check if string_view is available and usable + #if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW + #endif + + // Check if optional is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) + + // Check if byte is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # include + # if __cpp_lib_byte > 0 + # define CATCH_INTERNAL_CONFIG_CPP17_BYTE + # endif + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) + + // Check if variant is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # if defined(__clang__) && (__clang_major__ < 8) + // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852 + // fix should be in clang 8, workaround in libstdc++ 8.2 + # include + # if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) + # define CATCH_CONFIG_NO_CPP17_VARIANT + # else + # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT + # endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) + # else + # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT + # endif // defined(__clang__) && (__clang_major__ < 8) + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) +#endif // defined(__has_include) + +#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) +# define CATCH_CONFIG_COUNTER +#endif +#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) && !defined(CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH) +# define CATCH_CONFIG_WINDOWS_SEH +#endif +// This is set by default, because we assume that unix compilers are posix-signal-compatible by default. +#if defined(CATCH_INTERNAL_CONFIG_POSIX_SIGNALS) && !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) +# define CATCH_CONFIG_POSIX_SIGNALS +#endif +// This is set by default, because we assume that compilers with no wchar_t support are just rare exceptions. +#if !defined(CATCH_INTERNAL_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_WCHAR) +# define CATCH_CONFIG_WCHAR +#endif + +#if !defined(CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_CPP11_TO_STRING) +# define CATCH_CONFIG_CPP11_TO_STRING +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL) +# define CATCH_CONFIG_CPP17_OPTIONAL +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW) +# define CATCH_CONFIG_CPP17_STRING_VIEW +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT) +# define CATCH_CONFIG_CPP17_VARIANT +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_BYTE) && !defined(CATCH_CONFIG_NO_CPP17_BYTE) && !defined(CATCH_CONFIG_CPP17_BYTE) +# define CATCH_CONFIG_CPP17_BYTE +#endif + +#if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT) +# define CATCH_INTERNAL_CONFIG_NEW_CAPTURE +#endif + +#if defined(CATCH_INTERNAL_CONFIG_NEW_CAPTURE) && !defined(CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NEW_CAPTURE) +# define CATCH_CONFIG_NEW_CAPTURE +#endif + +#if !defined(CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) +# define CATCH_CONFIG_DISABLE_EXCEPTIONS +#endif + +#if defined(CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_NO_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_POLYFILL_ISNAN) +# define CATCH_CONFIG_POLYFILL_ISNAN +#endif + +#if defined(CATCH_INTERNAL_CONFIG_USE_ASYNC) && !defined(CATCH_INTERNAL_CONFIG_NO_ASYNC) && !defined(CATCH_CONFIG_NO_USE_ASYNC) && !defined(CATCH_CONFIG_USE_ASYNC) +# define CATCH_CONFIG_USE_ASYNC +#endif + +#if defined(CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_NO_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_ANDROID_LOGWRITE) +# define CATCH_CONFIG_ANDROID_LOGWRITE +#endif + +#if defined(CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_NO_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_GLOBAL_NEXTAFTER) +# define CATCH_CONFIG_GLOBAL_NEXTAFTER +#endif + +// Even if we do not think the compiler has that warning, we still have +// to provide a macro that can be used by the code. +#if !defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION) +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION +#endif +#if !defined(CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS +#endif + +// The goal of this macro is to avoid evaluation of the arguments, but +// still have the compiler warn on problems inside... +#if !defined(CATCH_INTERNAL_IGNORE_BUT_WARN) +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) +#endif + +#if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10) +# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS +#elif defined(__clang__) && (__clang_major__ < 5) +# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS +#endif + +#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS +#endif + +#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) +#define CATCH_TRY if ((true)) +#define CATCH_CATCH_ALL if ((false)) +#define CATCH_CATCH_ANON(type) if ((false)) +#else +#define CATCH_TRY try +#define CATCH_CATCH_ALL catch (...) +#define CATCH_CATCH_ANON(type) catch (type) +#endif + +#if defined(CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_NO_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) +#define CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#endif + +// end catch_compiler_capabilities.h +#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line +#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) +#ifdef CATCH_CONFIG_COUNTER +# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ ) +#else +# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) +#endif + +#include +#include +#include + +// We need a dummy global operator<< so we can bring it into Catch namespace later +struct Catch_global_namespace_dummy {}; +std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy); + +namespace Catch { + + struct CaseSensitive { enum Choice { + Yes, + No + }; }; + + class NonCopyable { + NonCopyable( NonCopyable const& ) = delete; + NonCopyable( NonCopyable && ) = delete; + NonCopyable& operator = ( NonCopyable const& ) = delete; + NonCopyable& operator = ( NonCopyable && ) = delete; + + protected: + NonCopyable(); + virtual ~NonCopyable(); + }; + + struct SourceLineInfo { + + SourceLineInfo() = delete; + SourceLineInfo( char const* _file, std::size_t _line ) noexcept + : file( _file ), + line( _line ) + {} + + SourceLineInfo( SourceLineInfo const& other ) = default; + SourceLineInfo& operator = ( SourceLineInfo const& ) = default; + SourceLineInfo( SourceLineInfo&& ) noexcept = default; + SourceLineInfo& operator = ( SourceLineInfo&& ) noexcept = default; + + bool empty() const noexcept { return file[0] == '\0'; } + bool operator == ( SourceLineInfo const& other ) const noexcept; + bool operator < ( SourceLineInfo const& other ) const noexcept; + + char const* file; + std::size_t line; + }; + + std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); + + // Bring in operator<< from global namespace into Catch namespace + // This is necessary because the overload of operator<< above makes + // lookup stop at namespace Catch + using ::operator<<; + + // Use this in variadic streaming macros to allow + // >> +StreamEndStop + // as well as + // >> stuff +StreamEndStop + struct StreamEndStop { + std::string operator+() const; + }; + template + T const& operator + ( T const& value, StreamEndStop ) { + return value; + } +} + +#define CATCH_INTERNAL_LINEINFO \ + ::Catch::SourceLineInfo( __FILE__, static_cast( __LINE__ ) ) + +// end catch_common.h +namespace Catch { + + struct RegistrarForTagAliases { + RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); + }; + +} // end namespace Catch + +#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \ + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ + CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION + +// end catch_tag_alias_autoregistrar.h +// start catch_test_registry.h + +// start catch_interfaces_testcase.h + +#include + +namespace Catch { + + class TestSpec; + + struct ITestInvoker { + virtual void invoke () const = 0; + virtual ~ITestInvoker(); + }; + + class TestCase; + struct IConfig; + + struct ITestCaseRegistry { + virtual ~ITestCaseRegistry(); + virtual std::vector const& getAllTests() const = 0; + virtual std::vector const& getAllTestsSorted( IConfig const& config ) const = 0; + }; + + bool isThrowSafe( TestCase const& testCase, IConfig const& config ); + bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); + std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ); + std::vector const& getAllTestCasesSorted( IConfig const& config ); + +} + +// end catch_interfaces_testcase.h +// start catch_stringref.h + +#include +#include +#include +#include + +namespace Catch { + + /// A non-owning string class (similar to the forthcoming std::string_view) + /// Note that, because a StringRef may be a substring of another string, + /// it may not be null terminated. + class StringRef { + public: + using size_type = std::size_t; + using const_iterator = const char*; + + private: + static constexpr char const* const s_empty = ""; + + char const* m_start = s_empty; + size_type m_size = 0; + + public: // construction + constexpr StringRef() noexcept = default; + + StringRef( char const* rawChars ) noexcept; + + constexpr StringRef( char const* rawChars, size_type size ) noexcept + : m_start( rawChars ), + m_size( size ) + {} + + StringRef( std::string const& stdString ) noexcept + : m_start( stdString.c_str() ), + m_size( stdString.size() ) + {} + + explicit operator std::string() const { + return std::string(m_start, m_size); + } + + public: // operators + auto operator == ( StringRef const& other ) const noexcept -> bool; + auto operator != (StringRef const& other) const noexcept -> bool { + return !(*this == other); + } + + auto operator[] ( size_type index ) const noexcept -> char { + assert(index < m_size); + return m_start[index]; + } + + public: // named queries + constexpr auto empty() const noexcept -> bool { + return m_size == 0; + } + constexpr auto size() const noexcept -> size_type { + return m_size; + } + + // Returns the current start pointer. If the StringRef is not + // null-terminated, throws std::domain_exception + auto c_str() const -> char const*; + + public: // substrings and searches + // Returns a substring of [start, start + length). + // If start + length > size(), then the substring is [start, size()). + // If start > size(), then the substring is empty. + auto substr( size_type start, size_type length ) const noexcept -> StringRef; + + // Returns the current start pointer. May not be null-terminated. + auto data() const noexcept -> char const*; + + constexpr auto isNullTerminated() const noexcept -> bool { + return m_start[m_size] == '\0'; + } + + public: // iterators + constexpr const_iterator begin() const { return m_start; } + constexpr const_iterator end() const { return m_start + m_size; } + }; + + auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&; + auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&; + + constexpr auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef { + return StringRef( rawChars, size ); + } +} // namespace Catch + +constexpr auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef { + return Catch::StringRef( rawChars, size ); +} + +// end catch_stringref.h +// start catch_preprocessor.hpp + + +#define CATCH_RECURSION_LEVEL0(...) __VA_ARGS__ +#define CATCH_RECURSION_LEVEL1(...) CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL2(...) CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL3(...) CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL4(...) CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL5(...) CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(__VA_ARGS__))) + +#ifdef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_EXPAND_VARGS(...) __VA_ARGS__ +// MSVC needs more evaluations +#define CATCH_RECURSION_LEVEL6(...) CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(__VA_ARGS__))) +#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL6(CATCH_RECURSION_LEVEL6(__VA_ARGS__)) +#else +#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL5(__VA_ARGS__) +#endif + +#define CATCH_REC_END(...) +#define CATCH_REC_OUT + +#define CATCH_EMPTY() +#define CATCH_DEFER(id) id CATCH_EMPTY() + +#define CATCH_REC_GET_END2() 0, CATCH_REC_END +#define CATCH_REC_GET_END1(...) CATCH_REC_GET_END2 +#define CATCH_REC_GET_END(...) CATCH_REC_GET_END1 +#define CATCH_REC_NEXT0(test, next, ...) next CATCH_REC_OUT +#define CATCH_REC_NEXT1(test, next) CATCH_DEFER ( CATCH_REC_NEXT0 ) ( test, next, 0) +#define CATCH_REC_NEXT(test, next) CATCH_REC_NEXT1(CATCH_REC_GET_END test, next) + +#define CATCH_REC_LIST0(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST1(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0) ) ( f, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST2(f, x, peek, ...) f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) + +#define CATCH_REC_LIST0_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST1_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0_UD) ) ( f, userdata, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST2_UD(f, userdata, x, peek, ...) f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) + +// Applies the function macro `f` to each of the remaining parameters, inserts commas between the results, +// and passes userdata as the first parameter to each invocation, +// e.g. CATCH_REC_LIST_UD(f, x, a, b, c) evaluates to f(x, a), f(x, b), f(x, c) +#define CATCH_REC_LIST_UD(f, userdata, ...) CATCH_RECURSE(CATCH_REC_LIST2_UD(f, userdata, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) + +#define CATCH_REC_LIST(f, ...) CATCH_RECURSE(CATCH_REC_LIST2(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) + +#define INTERNAL_CATCH_EXPAND1(param) INTERNAL_CATCH_EXPAND2(param) +#define INTERNAL_CATCH_EXPAND2(...) INTERNAL_CATCH_NO## __VA_ARGS__ +#define INTERNAL_CATCH_DEF(...) INTERNAL_CATCH_DEF __VA_ARGS__ +#define INTERNAL_CATCH_NOINTERNAL_CATCH_DEF +#define INTERNAL_CATCH_STRINGIZE(...) INTERNAL_CATCH_STRINGIZE2(__VA_ARGS__) +#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_STRINGIZE2(...) #__VA_ARGS__ +#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) +#else +// MSVC is adding extra space and needs another indirection to expand INTERNAL_CATCH_NOINTERNAL_CATCH_DEF +#define INTERNAL_CATCH_STRINGIZE2(...) INTERNAL_CATCH_STRINGIZE3(__VA_ARGS__) +#define INTERNAL_CATCH_STRINGIZE3(...) #__VA_ARGS__ +#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) (INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) + 1) +#endif + +#define INTERNAL_CATCH_MAKE_NAMESPACE2(...) ns_##__VA_ARGS__ +#define INTERNAL_CATCH_MAKE_NAMESPACE(name) INTERNAL_CATCH_MAKE_NAMESPACE2(name) + +#define INTERNAL_CATCH_REMOVE_PARENS(...) INTERNAL_CATCH_EXPAND1(INTERNAL_CATCH_DEF __VA_ARGS__) + +#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper()) +#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__)) +#else +#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper())) +#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__))) +#endif + +#define INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(...)\ + CATCH_REC_LIST(INTERNAL_CATCH_MAKE_TYPE_LIST,__VA_ARGS__) + +#define INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_0) INTERNAL_CATCH_REMOVE_PARENS(_0) +#define INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_0, _1) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_1) +#define INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_0, _1, _2) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_1, _2) +#define INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_0, _1, _2, _3) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_1, _2, _3) +#define INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_0, _1, _2, _3, _4) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_1, _2, _3, _4) +#define INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_0, _1, _2, _3, _4, _5) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_1, _2, _3, _4, _5) +#define INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_0, _1, _2, _3, _4, _5, _6) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_1, _2, _3, _4, _5, _6) +#define INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_0, _1, _2, _3, _4, _5, _6, _7) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_1, _2, _3, _4, _5, _6, _7) +#define INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_1, _2, _3, _4, _5, _6, _7, _8) +#define INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9) +#define INTERNAL_CATCH_REMOVE_PARENS_11_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) + +#define INTERNAL_CATCH_VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N + +#define INTERNAL_CATCH_TYPE_GEN\ + template struct TypeList {};\ + template\ + constexpr auto get_wrapper() noexcept -> TypeList { return {}; }\ + template class...> struct TemplateTypeList{};\ + template class...Cs>\ + constexpr auto get_wrapper() noexcept -> TemplateTypeList { return {}; }\ + template\ + struct append;\ + template\ + struct rewrap;\ + template class, typename...>\ + struct create;\ + template class, typename>\ + struct convert;\ + \ + template \ + struct append { using type = T; };\ + template< template class L1, typename...E1, template class L2, typename...E2, typename...Rest>\ + struct append, L2, Rest...> { using type = typename append, Rest...>::type; };\ + template< template class L1, typename...E1, typename...Rest>\ + struct append, TypeList, Rest...> { using type = L1; };\ + \ + template< template class Container, template class List, typename...elems>\ + struct rewrap, List> { using type = TypeList>; };\ + template< template class Container, template class List, class...Elems, typename...Elements>\ + struct rewrap, List, Elements...> { using type = typename append>, typename rewrap, Elements...>::type>::type; };\ + \ + template