From d6c63e5e362aef537c8a0a9db5be40c13cde30ce Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Mon, 14 Sep 2026 00:22:42 +0700 Subject: [PATCH 1/7] depends: add blst 0.3.17 blst (https://github.com/supranational/blst) is the BLS12-381 backend of the upcoming src/dashbls update. The package runs blst's own build.sh and installs libblst.a plus bindings/blst.h and blst_aux.h into the depends prefix. __BLST_PORTABLE__ selects runtime CPU dispatch so the build does not depend on the builder's CPU flags. --- depends/packages/blst.mk | 24 ++++++++++++++++++++++++ depends/packages/packages.mk | 2 +- doc/dependencies.md | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 depends/packages/blst.mk diff --git a/depends/packages/blst.mk b/depends/packages/blst.mk new file mode 100644 index 000000000000..3fd4d7020734 --- /dev/null +++ b/depends/packages/blst.mk @@ -0,0 +1,24 @@ +package=blst +$(package)_version=0.3.17 +$(package)_download_path=https://github.com/supranational/blst/archive/refs/tags +$(package)_download_file=v$($(package)_version).tar.gz +$(package)_file_name=$(package)-$($(package)_version).tar.gz +$(package)_sha256_hash=c3fef37b566b67419703b2bbb648e15176276af9a880c22aa8f5f2e8cecc2e4d + +# build.sh takes CC/AR/RANLIB/CFLAGS from the environment. __BLST_PORTABLE__ +# selects runtime CPU dispatch instead of letting build.sh probe the builder's +# /proc/cpuinfo for ADX, which keeps the build reproducible; build.sh itself +# adds -D__BLST_NO_ASM__ on hosts other than x86_64/aarch64. +define $(package)_set_vars + $(package)_build_env=CC="$($(package)_cc)" AR="$($(package)_ar)" RANLIB="$($(package)_ranlib)" CFLAGS="$($(package)_cflags) $($(package)_cppflags) -fno-builtin -fPIC -D__BLST_PORTABLE__" +endef + +define $(package)_build_cmds + ./build.sh +endef + +define $(package)_stage_cmds + mkdir -p $($(package)_staging_prefix_dir)/include $($(package)_staging_prefix_dir)/lib && \ + install -m 644 bindings/blst.h bindings/blst_aux.h $($(package)_staging_prefix_dir)/include && \ + install -m 644 libblst.a $($(package)_staging_prefix_dir)/lib +endef diff --git a/depends/packages/packages.mk b/depends/packages/packages.mk index 7e0bb2633219..91b14a370e98 100644 --- a/depends/packages/packages.mk +++ b/depends/packages/packages.mk @@ -1,4 +1,4 @@ -packages:=gmp backtrace +packages:=gmp backtrace blst boost_packages = boost diff --git a/doc/dependencies.md b/doc/dependencies.md index a9be6395aaa0..2fb9e671ed7c 100644 --- a/doc/dependencies.md +++ b/doc/dependencies.md @@ -19,6 +19,7 @@ You can find installation instructions in the `build-*.md` file for your platfor | --- | --- | --- | --- | --- | | [Boost](../depends/packages/boost.mk) | [link](https://www.boost.org/users/download/) | 1.81.0 | [1.73.0](https://github.com/bitcoin/bitcoin/pull/29066) | No | | [libevent](../depends/packages/libevent.mk) | [link](https://github.com/libevent/libevent/releases) | [2.1.12-stable](https://github.com/bitcoin/bitcoin/pull/21991) | [2.1.8](https://github.com/bitcoin/bitcoin/pull/24681) | No | +| [blst](../depends/packages/blst.mk) | [link](https://github.com/supranational/blst/releases) | 0.3.17 | | No | | glibc | [link](https://www.gnu.org/software/libc/) | N/A | [2.31](https://github.com/bitcoin/bitcoin/pull/29987) | Yes | | Linux Kernel | [link](https://www.kernel.org/) | N/A | [3.17.0](https://github.com/bitcoin/bitcoin/pull/27699) | Yes | From 163b86212cc47cb1c9ed71369edac1e14114a337 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Tue, 15 Sep 2026 03:35:16 +0700 Subject: [PATCH 2/7] depends: update 'src/dashbls' to dashpay/bls-signatures@fd6a7b5ed4717e65eeebfc56a947d774e8e62761 --- src/dashbls/.flake8 | 4 - .../.github/scripts/build_simple_index.py | 104 ++ src/dashbls/.github/workflows/binds-go.yml | 56 ++ src/dashbls/.github/workflows/binds-js.yml | 94 ++ src/dashbls/.github/workflows/binds-py.yml | 155 +++ src/dashbls/.github/workflows/binds-rs.yml | 49 + src/dashbls/.github/workflows/build-binds.yml | 104 +- src/dashbls/.github/workflows/build-docs.yml | 51 + src/dashbls/.github/workflows/build-test.yaml | 1 - .../.github/workflows/build-wheels.yml | 357 ------- src/dashbls/.github/workflows/js-bindings.yml | 60 -- .../.github/workflows/relic-nightly.yml | 78 -- src/dashbls/.github/workflows/stale-issue.yml | 0 src/dashbls/.gitignore | 90 +- src/dashbls/.python-version | 1 + src/dashbls/.vscode/extensions.json | 7 + src/dashbls/.vscode/settings.json | 8 + src/dashbls/CMakeLists.txt | 118 +-- src/dashbls/MANIFEST.in | 50 +- src/dashbls/Makefile.test.include | 55 +- src/dashbls/NOTICE | 153 +++ src/dashbls/README.md | 342 ++----- src/dashbls/autogen.sh | 1 + src/dashbls/binds/python/CMakeLists.txt | 24 + src/dashbls/binds/python/conftest.py | 15 + .../python}/pythonbindings.cpp | 562 ++++++----- .../python/samples/aggregate_signatures.py | 44 + .../samples/creating_keys_and_signatures.py | 36 + src/dashbls/binds/python/samples/hd_keys.py | 42 + .../python/samples/loading_from_bytes.py | 41 + .../python/samples/proof_of_possession.py | 58 ++ .../python/samples/serializing_to_bytes.py | 36 + .../binds/python/samples/tree_aggregates.py | 51 + src/dashbls/binds/python/test_bench.py | 75 ++ src/dashbls/binds/python/test_unit.py | 440 +++++++++ src/dashbls/cmake_modules/Findgmp.cmake | 103 -- src/dashbls/depends/catch2/CMakeLists.txt | 2 +- .../depends/relic/include/relic_conf.h.in | 717 ++++++++++++++ src/dashbls/include/dashbls/bls.hpp | 2 - src/dashbls/include/dashbls/chaincode.hpp | 14 +- src/dashbls/include/dashbls/elements.hpp | 103 +- .../include/dashbls/extendedprivatekey.hpp | 8 - .../include/dashbls/extendedpublickey.hpp | 8 - src/dashbls/include/dashbls/hdkeys.hpp | 145 ++- src/dashbls/include/dashbls/hkdf.hpp | 12 +- src/dashbls/include/dashbls/legacy.hpp | 25 +- src/dashbls/include/dashbls/privatekey.hpp | 19 +- src/dashbls/include/dashbls/schemes.hpp | 247 ++--- src/dashbls/include/dashbls/test-utils.hpp | 8 +- src/dashbls/include/dashbls/util.hpp | 39 +- src/dashbls/js-bindings/CMakeLists.txt | 4 +- src/dashbls/js-bindings/blsjs.d.ts | 9 - src/dashbls/js-bindings/helpers.cpp | 27 - src/dashbls/js-bindings/helpers.h | 9 - src/dashbls/js-bindings/jsbindings.cpp | 6 - src/dashbls/js-bindings/tests/test.js | 8 - .../js-bindings/wrappers/BignumWrapper.cpp | 48 - .../js-bindings/wrappers/BignumWrapper.h | 42 - .../js-bindings/wrappers/G1ElementWrapper.cpp | 10 - .../js-bindings/wrappers/G1ElementWrapper.h | 3 - .../js-bindings/wrappers/G2ElementWrapper.cpp | 10 - .../js-bindings/wrappers/G2ElementWrapper.h | 3 - src/dashbls/lgtm.yml | 12 - src/dashbls/mypi.ini | 2 - src/dashbls/pyproject.toml | 85 +- src/dashbls/python-bindings/CMakeLists.txt | 17 - src/dashbls/python-bindings/README.md | 149 --- src/dashbls/python-bindings/benchmark.py | 66 -- src/dashbls/python-bindings/test.py | 393 -------- src/dashbls/python-impl/README.md | 12 - src/dashbls/python-impl/bls12381.py | 101 -- src/dashbls/python-impl/ec.py | 586 ----------- src/dashbls/python-impl/fields.py | 763 -------------- src/dashbls/python-impl/hash_to_field.py | 99 -- src/dashbls/python-impl/hd_keys.py | 90 -- src/dashbls/python-impl/hkdf.py | 53 - src/dashbls/python-impl/impl-test.py | 663 ------------- src/dashbls/python-impl/op_swu_g2.py | 214 ---- src/dashbls/python-impl/pairing.py | 136 --- src/dashbls/python-impl/private_key.py | 81 -- src/dashbls/python-impl/schemes.py | 209 ---- src/dashbls/python-impl/util.py | 49 - .../rust-bindings/bls-signatures/Cargo.toml | 10 +- .../bls-signatures/src/private_key.rs | 3 +- src/dashbls/setup.py | 281 ++---- src/dashbls/src/CMakeLists.txt | 75 +- src/dashbls/src/bls.cpp | 36 - src/dashbls/src/chaincode.cpp | 16 +- src/dashbls/src/elements.cpp | 688 ++++++++----- src/dashbls/src/extendedprivatekey.cpp | 21 +- src/dashbls/src/extendedpublickey.cpp | 4 +- src/dashbls/src/legacy.cpp | 603 ++++-------- src/dashbls/src/privatekey.cpp | 194 ++-- src/dashbls/src/schemes.cpp | 507 +++++----- src/dashbls/src/test-bench.cpp | 40 +- src/dashbls/src/test-vectors.hpp | 575 +++++++++++ src/dashbls/src/test.cpp | 927 ++++++++++++------ src/dashbls/src/threshold.cpp | 164 +--- src/dashbls/test-vectors/reference.txt | 324 ++++++ src/dashbls/tools/fuzzgen.cpp | 158 +++ src/dashbls/tools/vectorgen.cpp | 22 + 101 files changed, 6184 insertions(+), 7237 deletions(-) delete mode 100644 src/dashbls/.flake8 create mode 100755 src/dashbls/.github/scripts/build_simple_index.py create mode 100644 src/dashbls/.github/workflows/binds-go.yml create mode 100644 src/dashbls/.github/workflows/binds-js.yml create mode 100644 src/dashbls/.github/workflows/binds-py.yml create mode 100644 src/dashbls/.github/workflows/binds-rs.yml create mode 100644 src/dashbls/.github/workflows/build-docs.yml delete mode 100644 src/dashbls/.github/workflows/build-wheels.yml delete mode 100644 src/dashbls/.github/workflows/js-bindings.yml delete mode 100644 src/dashbls/.github/workflows/relic-nightly.yml mode change 100755 => 100644 src/dashbls/.github/workflows/stale-issue.yml create mode 100644 src/dashbls/.python-version create mode 100644 src/dashbls/.vscode/extensions.json create mode 100644 src/dashbls/.vscode/settings.json create mode 100644 src/dashbls/NOTICE create mode 100644 src/dashbls/binds/python/CMakeLists.txt create mode 100644 src/dashbls/binds/python/conftest.py rename src/dashbls/{python-bindings => binds/python}/pythonbindings.cpp (55%) create mode 100755 src/dashbls/binds/python/samples/aggregate_signatures.py create mode 100755 src/dashbls/binds/python/samples/creating_keys_and_signatures.py create mode 100755 src/dashbls/binds/python/samples/hd_keys.py create mode 100755 src/dashbls/binds/python/samples/loading_from_bytes.py create mode 100755 src/dashbls/binds/python/samples/proof_of_possession.py create mode 100755 src/dashbls/binds/python/samples/serializing_to_bytes.py create mode 100755 src/dashbls/binds/python/samples/tree_aggregates.py create mode 100755 src/dashbls/binds/python/test_bench.py create mode 100755 src/dashbls/binds/python/test_unit.py delete mode 100644 src/dashbls/cmake_modules/Findgmp.cmake create mode 100644 src/dashbls/depends/relic/include/relic_conf.h.in delete mode 100644 src/dashbls/js-bindings/wrappers/BignumWrapper.cpp delete mode 100644 src/dashbls/js-bindings/wrappers/BignumWrapper.h delete mode 100644 src/dashbls/lgtm.yml delete mode 100644 src/dashbls/mypi.ini delete mode 100644 src/dashbls/python-bindings/CMakeLists.txt delete mode 100644 src/dashbls/python-bindings/README.md delete mode 100644 src/dashbls/python-bindings/benchmark.py delete mode 100644 src/dashbls/python-bindings/test.py delete mode 100644 src/dashbls/python-impl/README.md delete mode 100644 src/dashbls/python-impl/bls12381.py delete mode 100644 src/dashbls/python-impl/ec.py delete mode 100644 src/dashbls/python-impl/fields.py delete mode 100644 src/dashbls/python-impl/hash_to_field.py delete mode 100644 src/dashbls/python-impl/hd_keys.py delete mode 100644 src/dashbls/python-impl/hkdf.py delete mode 100644 src/dashbls/python-impl/impl-test.py delete mode 100644 src/dashbls/python-impl/op_swu_g2.py delete mode 100644 src/dashbls/python-impl/pairing.py delete mode 100644 src/dashbls/python-impl/private_key.py delete mode 100644 src/dashbls/python-impl/schemes.py delete mode 100644 src/dashbls/python-impl/util.py create mode 100644 src/dashbls/src/test-vectors.hpp create mode 100644 src/dashbls/test-vectors/reference.txt create mode 100644 src/dashbls/tools/fuzzgen.cpp create mode 100644 src/dashbls/tools/vectorgen.cpp diff --git a/src/dashbls/.flake8 b/src/dashbls/.flake8 deleted file mode 100644 index ccb153056291..000000000000 --- a/src/dashbls/.flake8 +++ /dev/null @@ -1,4 +0,0 @@ -[flake8] -max-line-length = 120 -exclude = ./typings/**/* python-impl/fields.py -ignore = E203,W503,E501 diff --git a/src/dashbls/.github/scripts/build_simple_index.py b/src/dashbls/.github/scripts/build_simple_index.py new file mode 100755 index 000000000000..e5554ed9e9bf --- /dev/null +++ b/src/dashbls/.github/scripts/build_simple_index.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python3 +# coding: latin-1 + +# +# Copyright (c) 2026-present, Microsoft Corporation +# Copyright (c) 2026-present, The Dash Core developers +# SPDX-License-Identifier: MIT +# + +"""Generate a PEP 503 index for released distributions.""" + +import argparse +import json +import os +import re +import subprocess +import sys +from html import escape +from pathlib import Path + +# PEP 503: lowercase, runs of -_. collapsed to a single - +NAME = "dashbls" +NORMALISED = re.sub(r"[-_.]+", "-", NAME).lower() + +# Must match requires-python in pyproject.toml. +REQUIRES_PYTHON = ">=3.10" + + +def releases(repo: str) -> list[dict]: + """Every release of `repo`, each with the name, URL and digest of its assets.""" + out = subprocess.check_output( # noqa: S603 + [ # noqa: S607 + "gh", + "api", + "--paginate", + f"repos/{repo}/releases", + "--jq", + ".[] | select(.draft | not) | {tag: .tag_name, assets: [.assets[] " + "| {name, url: .browser_download_url, digest}]}", + ], + text=True, + ) + return [json.loads(line) for line in out.splitlines() if line.strip()] + + +def anchor(name: str, url: str, digest: str | None) -> str: + """One link, with the hash pip needs to verify what it downloaded. + + The releases API reports a digest as "sha256:", which is the PEP 503 + fragment in all but spelling. Without it pip has no integrity check at all + and --require-hashes has nothing to match against. + """ + if digest and digest.startswith("sha256:"): + url = f"{url}#sha256={digest.removeprefix('sha256:')}" + return ( + f' {escape(name)}
' + ) + + +def main() -> None: + parser = argparse.ArgumentParser() + parser.add_argument("--output", required=True, type=Path) + parser.add_argument( + "--repo", default=os.environ.get("GITHUB_REPOSITORY", "dashpay/bls-signatures") + ) + args = parser.parse_args() + + # Sdists matter as much as wheels here: they are the only thing installable + # on a platform we do not ship a wheel for, and pip will not find one that + # the index does not list. + files = [] + for release in releases(args.repo): + for asset in release["assets"]: + if asset["name"].endswith((".whl", ".tar.gz")): + files.append((asset["name"], asset["url"], asset.get("digest"))) + files.sort() + if not files: + sys.exit("no distributions found on any release; refusing to publish an empty index") + + project = args.output / "pep503" / NORMALISED + project.mkdir(parents=True, exist_ok=True) + + # pypi:repository-version is PEP 629; charset because the filenames are + # written by whatever runner built them. + head = '\n' + anchors = "\n".join(anchor(*dist) for dist in files) + (project / "index.html").write_text( + f"\n{head}\nLinks for {NAME}\n" + f"\n

Links for {NAME}

\n{anchors}\n\n", + encoding="utf-8", + ) + (args.output / "pep503" / "index.html").write_text( + f"\n{head}\nSimple Index\n" + "\n" + f' {NAME}
\n' + "\n", + encoding="utf-8", + ) + print(f"indexed {len(files)} distributions for {NAME}") + + +if __name__ == "__main__": + main() diff --git a/src/dashbls/.github/workflows/binds-go.yml b/src/dashbls/.github/workflows/binds-go.yml new file mode 100644 index 000000000000..ccda3c190131 --- /dev/null +++ b/src/dashbls/.github/workflows/binds-go.yml @@ -0,0 +1,56 @@ +name: Binds (Go) + +on: + workflow_call: + workflow_dispatch: + +permissions: + contents: read + +jobs: + build: + name: ${{ matrix.os }}, Go ${{ matrix.golang }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-latest, ubuntu-24.04-arm] + golang: [ '1.24' ] + + steps: + - name: Checkout code + uses: actions/checkout@v6 + with: + persist-credentials: false + + - name: Install Go + uses: actions/setup-go@v7 + with: + go-version: ^${{ matrix.golang }} + + - name: Prepare build system for Ubuntu + if: startsWith(matrix.os, 'ubuntu') + run: | + sudo apt-get update + sudo apt-get install -qq --yes valgrind libgmp-dev cmake + hash -r + cmake --version + + - name: Prepare build system for macOS + if: startsWith(matrix.os, 'macos') + run: | + brew install gmp + + - name: Build library using CMake + run: | + cores=$(getconf _NPROCESSORS_ONLN) + jobs=$(( cores > 1 ? cores - 1 : 1 )) + mkdir -p build && cd build + cmake .. -DCMAKE_BUILD_TYPE=Debug + cmake --build . --parallel "$jobs" + + - name: Build bindings + run: | + cd go-bindings + make config + make diff --git a/src/dashbls/.github/workflows/binds-js.yml b/src/dashbls/.github/workflows/binds-js.yml new file mode 100644 index 000000000000..fa9bbf15d798 --- /dev/null +++ b/src/dashbls/.github/workflows/binds-js.yml @@ -0,0 +1,94 @@ +name: Binds (Javascript) + +on: + workflow_call: + secrets: + NPM_TOKEN: + description: Token used to publish the package to the npm registry + required: false + workflow_dispatch: + +permissions: + contents: read + +jobs: + build: + name: ${{ matrix.os }}, Javascript + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-latest, ubuntu-24.04-arm] + + steps: + - name: Checkout code + uses: actions/checkout@v6 + with: + persist-credentials: false + + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '21' + + - name: Install Emscripten SDK + uses: mymindstorm/setup-emsdk@v16 + + - name: Build JavaScript bindings + run: | + emcc -v + sh emsdk_build.sh + + - name: Test JavaScript bindings + run: | + sh js_test.sh + + publish: + name: Publish (releases), Javascript + if: startsWith(github.ref, 'refs/tags/') + needs: build + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v6 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '21' + + - name: Install Emscripten SDK + uses: mymindstorm/setup-emsdk@v16 + + - name: Set up Node + uses: actions/setup-node@v6 + with: + node-version: '20' + registry-url: https://registry.npmjs.org + + # emsdk_build.sh copies package.json into js_build/, so the version has to + # be rewritten in the source tree before the build runs. + - name: Update version in package.json + working-directory: js-bindings + env: + RELEASE: ${{ github.ref_name }} + run: | + jq --arg VER "${RELEASE#v}" '.version=$VER' package.json > temp.json + mv temp.json package.json + + - name: Build JavaScript bindings + run: | + emcc -v + sh emsdk_build.sh + + - name: Publish to npm + working-directory: js_build/js-bindings + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: npm publish --access public diff --git a/src/dashbls/.github/workflows/binds-py.yml b/src/dashbls/.github/workflows/binds-py.yml new file mode 100644 index 000000000000..803fb37fa4f2 --- /dev/null +++ b/src/dashbls/.github/workflows/binds-py.yml @@ -0,0 +1,155 @@ +name: Binds (Python) + +on: + workflow_call: + workflow_dispatch: + +permissions: + contents: read + +jobs: + lint: + name: Lint, Python + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v6 + with: + persist-credentials: false + + - name: Install uv + uses: astral-sh/setup-uv@v9.0.0 + + - name: Check lints + run: uvx ruff check --output-format=github . + + - name: Check formatting + run: uvx ruff format --check --diff . + + build: + name: Build (${{ matrix.name }}), Python + needs: lint + runs-on: ${{ matrix.runs-on }} + strategy: + fail-fast: false + matrix: + include: >- + ${{ fromJSON(startsWith(github.ref, 'refs/tags/') + && '[ + {"name": "linux-arm64", "runs-on": "ubuntu-24.04-arm", "archs": "aarch64"}, + {"name": "linux-amd64", "runs-on": "ubuntu-latest", "archs": "x86_64"}, + {"name": "macos-arm64", "runs-on": "macos-latest", "archs": "arm64", "macos-target": "14.0"}, + {"name": "macos-amd64", "runs-on": "macos-15-intel", "archs": "x86_64", "macos-target": "14.0"}, + {"name": "windows-amd64", "runs-on": "windows-latest", "archs": "AMD64"} + ]' + || '[ + {"name": "linux-arm64", "runs-on": "ubuntu-24.04-arm", "archs": "aarch64"}, + {"name": "macos-arm64", "runs-on": "macos-latest", "archs": "arm64", "macos-target": "14.0"}, + {"name": "windows-amd64", "runs-on": "windows-latest", "archs": "AMD64"} + ]') }} + + steps: + - name: Checkout code + uses: actions/checkout@v6 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Install uv + uses: astral-sh/setup-uv@v9.0.0 + with: + enable-cache: false + + - name: Build and test wheels + uses: pypa/cibuildwheel@v4.1.1 + env: + CIBW_ARCHS: ${{ matrix.archs }} + MACOSX_DEPLOYMENT_TARGET: ${{ matrix.macos-target }} + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: wheels-${{ matrix.name }} + path: wheelhouse/*.whl + if-no-files-found: error + + sdist: + name: Build (sdist), Python + needs: lint + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v6 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Install uv + uses: astral-sh/setup-uv@v9.0.0 + + - name: Build the sdist + run: uv build --sdist --out-dir dist + + - name: Prepare build system + run: | + sudo apt-get update + sudo apt-get install -qq --yes libgmp-dev + + - name: Install from the sdist and run the unit tests + run: | + uv venv .venv-sdist + uv pip install --python .venv-sdist --no-binary=dashbls dist/*.tar.gz + uv pip install --python .venv-sdist pytest pytest-benchmark + .venv-sdist/bin/python -m pytest --import-mode=importlib -v binds/python/test_unit.py + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: sdist + path: dist/*.tar.gz + if-no-files-found: error + + publish: + name: Publish (releases), Python + if: startsWith(github.ref, 'refs/tags/') + needs: [build, sdist] + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + pattern: wheels-* + merge-multiple: true + path: dist + + - name: Download the sdist + uses: actions/download-artifact@v4 + with: + name: sdist + path: dist + + - name: Attach the wheels and sdist to the release + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + RELEASE: ${{ github.ref_name }} + run: | + ls -l dist + # Pushing a tag does not create a release, and `upload` will not make one. + gh release view "$RELEASE" >/dev/null 2>&1 \ + || gh release create "$RELEASE" --verify-tag --generate-notes + gh release upload "$RELEASE" dist/*.whl dist/*.tar.gz --clobber + + index: + name: Publish (index), Python + needs: publish + permissions: + contents: read + pages: write + id-token: write + uses: ./.github/workflows/build-docs.yml diff --git a/src/dashbls/.github/workflows/binds-rs.yml b/src/dashbls/.github/workflows/binds-rs.yml new file mode 100644 index 000000000000..8e3db323db12 --- /dev/null +++ b/src/dashbls/.github/workflows/binds-rs.yml @@ -0,0 +1,49 @@ +name: Binds (Rust) + +on: + workflow_call: + workflow_dispatch: + +permissions: + contents: read + +jobs: + build: + name: ${{ matrix.os }}, Rust ${{ matrix.rust }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-latest, ubuntu-24.04-arm] + rust: [ '1.91.0' ] + + steps: + - name: Checkout code + uses: actions/checkout@v6 + with: + persist-credentials: false + + - name: Prepare build system for Ubuntu + if: startsWith(matrix.os, 'ubuntu') + run: | + sudo apt-get update + sudo apt-get install -qq --yes valgrind libgmp-dev cmake + hash -r + cmake --version + + - name: Prepare build system for macOS + if: startsWith(matrix.os, 'macos') + run: | + brew install gmp + + - name: Install Rust + run: | + rustup toolchain install ${{ matrix.rust }} + rustup default ${{ matrix.rust }} + rustc --version + cargo --version + + - name: Build and test Rust bindings + run: | + cd rust-bindings/bls-dash-sys + cargo test diff --git a/src/dashbls/.github/workflows/build-binds.yml b/src/dashbls/.github/workflows/build-binds.yml index 43dc8b212590..fa1f69e17779 100644 --- a/src/dashbls/.github/workflows/build-binds.yml +++ b/src/dashbls/.github/workflows/build-binds.yml @@ -11,86 +11,32 @@ on: - '**' concurrency: - # SHA is added to the end if on `main` to let all main workflows run group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ (github.ref == 'refs/heads/main') && github.sha || '' }} cancel-in-progress: true -jobs: - build: - name: ${{ matrix.os }}, Python ${{ matrix.python }}, Go ${{ matrix.golang }}, Rust ${{ matrix.rust }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [macos-latest, ubuntu-latest] - golang: [ '1.24' ] - python: ['3.10', '3.11', '3.12', '3.13'] - rust: [ '1.91.0' ] - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - uses: chia-network/actions/setup-python@main - with: - python-version: ${{ matrix.python }} - - - name: Test Python implementation - run: | - python python-impl/impl-test.py - - - name: Install Emscripten SDK - uses: mymindstorm/setup-emsdk@v11 - - - name: Build JavaScript bindings - run: | - emcc -v - sh emsdk_build.sh - - - name: Test JavaScript bindings - run: | - sh js_test.sh +permissions: + contents: read - - name: Install Go - uses: actions/setup-go@v2 - with: - go-version: ^${{ matrix.golang }} - - - name: Prepare build system for Ubuntu - if: startsWith(matrix.os, 'ubuntu') - run: | - sudo apt-get update - sudo apt-get install -qq --yes valgrind libgmp-dev cmake - hash -r - cmake --version - - - name: Prepare build system for macOS - if: startsWith(matrix.os, 'macos') - run: | - ls -l - export MACOSX_DEPLOYMENT_TARGET=10.14 - brew install gmp - - - name: Build library using CMake - run: | - mkdir -p build && cd build - cmake .. -DCMAKE_BUILD_TYPE=Debug - cmake --build . -- -j 6 - - - name: Build Go bindings - run: | - cd go-bindings - make config - make - - - name: Install Rust - run: | - rustup toolchain install ${{ matrix.rust }} - rustup default ${{ matrix.rust }} - rustc --version - cargo --version - - - name: Build and test Rust bindings - run: | - cd rust-bindings/bls-dash-sys - cargo test +jobs: + build-go: + name: Go + uses: ./.github/workflows/binds-go.yml + + build-js: + name: JavaScript + uses: ./.github/workflows/binds-js.yml + # Reusable workflows do not inherit secrets; the tagged publish needs this. + secrets: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + build-rs: + name: Rust + uses: ./.github/workflows/binds-rs.yml + + build-py: + name: Python + permissions: + contents: write + pages: write + id-token: write + uses: ./.github/workflows/binds-py.yml diff --git a/src/dashbls/.github/workflows/build-docs.yml b/src/dashbls/.github/workflows/build-docs.yml new file mode 100644 index 000000000000..4a65809772d5 --- /dev/null +++ b/src/dashbls/.github/workflows/build-docs.yml @@ -0,0 +1,51 @@ +name: Build docs + +on: + workflow_call: + workflow_dispatch: + +concurrency: + group: pages + cancel-in-progress: false + +permissions: + contents: read + pages: write + id-token: write + +jobs: + pep503: + name: Generate PEP503 index + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deploy.outputs.page_url }} + + steps: + - name: Checkout code + uses: actions/checkout@v6 + with: + persist-credentials: false + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.10' + + - name: Generate index + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + run: python .github/scripts/build_simple_index.py --output _site + + - name: Configure GitHub Pages + uses: actions/configure-pages@v6 + + - name: Upload index + uses: actions/upload-pages-artifact@v5 + with: + path: _site + + - name: Deploy to GitHub Pages + id: deploy + uses: actions/deploy-pages@v5 diff --git a/src/dashbls/.github/workflows/build-test.yaml b/src/dashbls/.github/workflows/build-test.yaml index 90a550a5e4d2..6f6b319a9c57 100644 --- a/src/dashbls/.github/workflows/build-test.yaml +++ b/src/dashbls/.github/workflows/build-test.yaml @@ -45,7 +45,6 @@ jobs: - name: Prepare build system for macOS if: startsWith(matrix.os, 'macos') run: | - ls -l export MACOSX_DEPLOYMENT_TARGET=10.14 brew install autoconf automake gmp libtool pkg-config diff --git a/src/dashbls/.github/workflows/build-wheels.yml b/src/dashbls/.github/workflows/build-wheels.yml deleted file mode 100644 index 6953beebc5f8..000000000000 --- a/src/dashbls/.github/workflows/build-wheels.yml +++ /dev/null @@ -1,357 +0,0 @@ -name: build - check - upload - -on: - push: - branches: - - main - tags: - - '**' - pull_request: - branches: - - '**' - -concurrency: - # SHA is added to the end if on `main` to let all main workflows run - group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') || startsWith(github.ref, 'refs/heads/long_lived/')) && github.sha || '' }} - cancel-in-progress: true - -jobs: - build-wheels: - name: Wheel - ${{ matrix.os.name }} ${{ matrix.python.major-dot-minor }} ${{ matrix.arch.name }} - runs-on: ${{ matrix.os.runs-on[matrix.arch.matrix] }} - strategy: - fail-fast: false - matrix: - os: - - name: macOS - matrix: macos - runs-on: - arm: [macOS, ARM64] - intel: [macos-latest] - cibw-archs-macos: - arm: arm64 - intel: x86_64 - - name: Ubuntu - matrix: ubuntu - runs-on: - arm: [Linux, ARM64] - intel: [ubuntu-latest] - - name: Windows - matrix: windows - runs-on: - intel: [windows-latest] - python: - - major-dot-minor: '3.7' - cibw-build: 'cp37-*' - manylinux: - arch: manylinux2014 - intel: manylinux2010 - matrix: '3.7' - - major-dot-minor: '3.8' - cibw-build: 'cp38-*' - manylinux: - arch: manylinux2014 - intel: manylinux2010 - matrix: '3.8' - - major-dot-minor: '3.9' - cibw-build: 'cp39-*' - manylinux: - arch: manylinux2014 - intel: manylinux2010 - matrix: '3.9' - - major-dot-minor: '3.10' - cibw-build: 'cp310-*' - manylinux: - arch: manylinux2014 - intel: manylinux2010 - matrix: '3.10' - - major-dot-minor: '3.11' - cibw-build: 'cp311-*' - manylinux: - arch: manylinux2014 - intel: manylinux2014 - matrix: '3.11' - arch: - - name: ARM - matrix: arm - - name: Intel - matrix: intel - exclude: - # Only partial entries are required here by GitHub Actions so generally I - # only specify the `matrix:` entry. The super linter complains so for now - # all entries are included to avoid that. Reported at - # https://github.com/github/super-linter/issues/3016 - - os: - name: Windows - matrix: windows - runs-on: - intel: [windows-latest] - arch: - name: ARM - matrix: arm - - os: - name: macOS - matrix: macos - runs-on: - arm: [macOS, ARM64] - intel: [macos-latest] - python: - major-dot-minor: '3.7' - cibw-build: 'cp37-*' - matrix: '3.7' - arch: - name: ARM - matrix: arm - - os: - name: macOS - matrix: macos - runs-on: - arm: [macOS, ARM64] - intel: [macos-latest] - python: - major-dot-minor: '3.8' - cibw-build: 'cp38-*' - matrix: '3.8' - arch: - name: ARM - matrix: arm - - steps: - - name: Clean workspace - uses: Chia-Network/actions/clean-workspace@main - - - name: Checkout code - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - uses: chia-network/actions/setup-python@main - with: - python-version: ${{ matrix.python.major-dot-minor }} - - - name: Install pipx - run: | - pip install pipx - - - name: Build and test - env: - CIBW_PRERELEASE_PYTHONS: True - CIBW_BUILD_VERBOSITY_MACOS: 0 - CIBW_BUILD_VERBOSITY_LINUX: 0 - CIBW_BUILD_VERBOSITY_WINDOWS: 0 - CIBW_BUILD: ${{ matrix.python.cibw-build }} - CIBW_SKIP: '*-manylinux_i686 *-win32 *-musllinux_*' - CIBW_MANYLINUX_AARCH64_IMAGE: ${{ matrix.python.manylinux['arm'] }} - CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.python.manylinux['intel'] }} - CIBW_ENVIRONMENT_LINUX: "PATH=/project/cmake-3.14.3-Linux-`uname -m`/bin:$PATH" - CIBW_BEFORE_ALL_LINUX: > - yum -y install epel-release - && echo "epel-release installed" - && yum -y install lzip - && echo "lzip installed" - && curl -L https://github.com/Kitware/CMake/releases/download/v3.14.3/cmake-3.14.3-Linux-`uname -m`.sh > cmake.sh - && yes | sh cmake.sh | cat - && rm -f /usr/bin/cmake - && curl -L https://gmplib.org/download/gmp/gmp-6.2.1.tar.lz | tar x --lzip - && 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/ - && cd gmp-6.2.1 && ./configure --enable-fat - && make && make install && cd .. && rm -rf gmp-6.2.1 - && cmake --version - && uname -a - CIBW_BEFORE_BUILD_LINUX: > - python -m pip install --upgrade pip - CIBW_ARCHS_MACOS: ${{ matrix.os.cibw-archs-macos[matrix.arch.matrix] }} - CIBW_BEFORE_ALL_MACOS: > - brew install gmp boost cmake - CIBW_BEFORE_BUILD_MACOS: > - python -m pip install --upgrade pip - CIBW_ENVIRONMENT_MACOS: "MACOSX_DEPLOYMENT_TARGET=10.14" - 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: > - ls -l mpir_gc_x64 && 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} - CIBW_TEST_REQUIRES: pytest - CIBW_TEST_COMMAND: py.test -v {project}/python-bindings/test.py - run: - pipx run --spec='cibuildwheel==2.9.0' cibuildwheel --output-dir dist 2>&1 - - - name: Upload artifacts - uses: actions/upload-artifact@v3 - with: - name: packages - path: ./dist - - build-sdist: - name: sdist - ${{ matrix.os.name }} ${{ matrix.python.major-dot-minor }} ${{ matrix.arch.name }} - runs-on: ${{ matrix.os.runs-on[matrix.arch.matrix] }} - strategy: - fail-fast: false - matrix: - os: - - name: Ubuntu - matrix: ubuntu - runs-on: - arm: [Linux, ARM64] - intel: [ubuntu-latest] - python: - - major-dot-minor: '3.9' - matrix: '3.9' - arch: - - name: Intel - matrix: intel - - steps: - - name: Clean workspace - uses: Chia-Network/actions/clean-workspace@main - - - name: Checkout code - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - uses: Chia-Network/actions/setup-python@main - with: - python-version: ${{ matrix.python.major-dot-minor }} - - - name: Build source distribution - run: | - pip install build - python -m build --sdist --outdir dist . - - name: Upload artifacts - uses: actions/upload-artifact@v3 - with: - name: packages - path: ./dist - - check: - name: Check - ${{ matrix.os.name }} ${{ matrix.python.major-dot-minor }} ${{ matrix.arch.name }} - runs-on: ${{ matrix.os.runs-on[matrix.arch.matrix] }} - strategy: - fail-fast: false - matrix: - os: - - name: Ubuntu - matrix: ubuntu - runs-on: - arm: [Linux, ARM64] - intel: [ubuntu-latest] - python: - - major-dot-minor: '3.9' - matrix: '3.9' - arch: - - name: Intel - matrix: intel - - steps: - - name: Clean workspace - uses: Chia-Network/actions/clean-workspace@main - - - name: Checkout code - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - uses: Chia-Network/actions/setup-python@main - with: - python-version: ${{ matrix.python.major-dot-minor }} - - - name: flake8 - run: | - pip install flake8 - flake8 src setup.py python-bindings python-impl - - name: mypy - run: | - pip install mypy - mypy --config-file mypi.ini python-bindings python-impl - upload: - name: Upload to PyPI - ${{ matrix.os.name }} ${{ matrix.python.major-dot-minor }} ${{ matrix.arch.name }} - runs-on: ${{ matrix.os.runs-on[matrix.arch.matrix] }} - needs: - - build-wheels - - build-sdist - - check - strategy: - fail-fast: false - matrix: - os: - - name: Ubuntu - matrix: ubuntu - runs-on: - arm: [Linux, ARM64] - intel: [ubuntu-latest] - python: - - major-dot-minor: '3.9' - matrix: '3.9' - arch: - - name: Intel - matrix: intel - - steps: - - name: Clean workspace - uses: Chia-Network/actions/clean-workspace@main - - - name: Checkout code - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - uses: Chia-Network/actions/setup-python@main - with: - python-version: ${{ matrix.python.major-dot-minor }} - - - name: Download artifacts - uses: actions/download-artifact@v3 - with: - name: packages - 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/dashbls/.github/workflows/js-bindings.yml b/src/dashbls/.github/workflows/js-bindings.yml deleted file mode 100644 index 887c8df3d628..000000000000 --- a/src/dashbls/.github/workflows/js-bindings.yml +++ /dev/null @@ -1,60 +0,0 @@ -name: Build & Publish JS Bindings - -on: - push: - branches: - - main - tags: - - '**' - pull_request: - branches: - - '**' - -concurrency: - # SHA is added to the end if on `main` to let all main workflows run - group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ (github.ref == 'refs/heads/main') && github.sha || '' }} - cancel-in-progress: true - -jobs: - js_bindings: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - uses: actions/setup-node@v3 - with: - node-version: 16 - - - name: Install emsdk - uses: mymindstorm/setup-emsdk@v11 - - - name: Get the version - id: version_info - run: echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/} - - - name: Update version in package.json - if: startsWith(github.ref, 'refs/tags/') - working-directory: ${{ github.workspace }}/js-bindings - env: - SOURCE_TAG: ${{ steps.version_info.outputs.SOURCE_TAG }} - run: | - jq --arg VER "$SOURCE_TAG" '.version=$VER' package.json > temp.json && mv temp.json package.json - - - name: Build JS - run: ./js_build.sh - - - name: Publish - if: startsWith(github.ref, 'refs/tags/') - working-directory: ${{ github.workspace }}/js_build/js-bindings - env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - run: | - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc - npm publish --access public - - - name: Cleanup - if: always() - run: - rm ${{ github.workspace }}/js_build/js-bindings/.npmrc || true diff --git a/src/dashbls/.github/workflows/relic-nightly.yml b/src/dashbls/.github/workflows/relic-nightly.yml deleted file mode 100644 index 2a9ef67153cc..000000000000 --- a/src/dashbls/.github/workflows/relic-nightly.yml +++ /dev/null @@ -1,78 +0,0 @@ -name: Build and Test with Relic Nightly - -on: - schedule: - - cron: "0 11 * * *" - workflow_dispatch: - -concurrency: - # SHA is added to the end if on `main` to let all main workflows run - group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ (github.ref == 'refs/heads/main') && github.sha || '' }} - cancel-in-progress: true - -jobs: - build_wheels: - name: Build and Test with Relic Nightly - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [macos-latest, ubuntu-latest] - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - 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 - export RELIC_MAIN=1 - mkdir -p build - cd build - cmake ../ - cmake --build . -- -j 6 - echo "Running ./src/runtest" - ./src/runtest - - - name: Mac OS build C++ and test - if: startsWith(matrix.os, 'macos') - run: | - ls -l - export MACOSX_DEPLOYMENT_TARGET=10.14 - export RELIC_MAIN=1 - mkdir -p build - ls -l build - cd build - cmake ../ - cmake --build . -- -j 6 - echo "Running ./src/runtest" - ./src/runtest - - - uses: actions/setup-python@v2 - name: Install Python - with: - python-version: '3.8' - - - name: Test pure python implementation - run: | - python python-impl/impl-test.py - - - name: Install emsdk - uses: mymindstorm/setup-emsdk@v11 - - - name: Test javascript bindings - run: | - emcc -v - export RELIC_MAIN=1 - sh emsdk_build.sh - sh js_test.sh diff --git a/src/dashbls/.github/workflows/stale-issue.yml b/src/dashbls/.github/workflows/stale-issue.yml old mode 100755 new mode 100644 diff --git a/src/dashbls/.gitignore b/src/dashbls/.gitignore index bec3896a5c07..ec8e23435253 100644 --- a/src/dashbls/.gitignore +++ b/src/dashbls/.gitignore @@ -8,13 +8,6 @@ src/MakefilE src/cmake_install.cmake src/CMakeFile build/* -blspy.egg-info -dist -python-impl/__pycache__/ -blspy.*.so -.mypy_cache/ -.pytest_chache/ -.eggs/ cmake-build-debug/ js_build @@ -24,15 +17,6 @@ main .o obj/ src/*.o -depends/relic/CTestTestfile.cmake -depends/relic/bench/CTestTestfile.cmake -depends/relic/bin -depends/relic/include/relic_conf.h -depends/relic/include/relic_conf.h.in -depends/relic/include/relic_conf.h.old -depends/relic/include/stamp-h1 -depends/relic/test/CTestTestfile.cmake -contrib/gmp-6.1.2/ .idea .vscode @@ -48,7 +32,6 @@ runbench.* *.bak *.rej *.orig -*.pyc *.o *.o-* *.patch @@ -115,3 +98,76 @@ autom4te.cache /stamp-h1 /ltmain.sh /texinfo.tex + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[codz] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py.cover +*.lcov +.hypothesis/ +.pytest_cache/ +cover/ + +# Environments +.env +.envrc +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Cython debug symbols +cython_debug/ + +# Temporary file for partial code execution +tempCodeRunnerFile.py + +# Ruff stuff: +.ruff_cache/ + +# PyPI configuration file +.pypirc + +# PEP503 index +_site diff --git a/src/dashbls/.python-version b/src/dashbls/.python-version new file mode 100644 index 000000000000..eae0123defaa --- /dev/null +++ b/src/dashbls/.python-version @@ -0,0 +1 @@ +3.10.19 diff --git a/src/dashbls/.vscode/extensions.json b/src/dashbls/.vscode/extensions.json new file mode 100644 index 000000000000..622b5920a314 --- /dev/null +++ b/src/dashbls/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "charliermarsh.ruff", + "ms-python.python", + "ms-python.vscode-pylance", + ] +} diff --git a/src/dashbls/.vscode/settings.json b/src/dashbls/.vscode/settings.json new file mode 100644 index 000000000000..a4d694f5552d --- /dev/null +++ b/src/dashbls/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "[python]": { + "editor.defaultFormatter": "charliermarsh.ruff", + "editor.formatOnSave": true, + "editor.rulers": [88, 100] + }, + "editor.minimap.enabled": true, +} diff --git a/src/dashbls/CMakeLists.txt b/src/dashbls/CMakeLists.txt index f413f97cc7a9..25f65b875961 100644 --- a/src/dashbls/CMakeLists.txt +++ b/src/dashbls/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.14.0 FATAL_ERROR) +CMAKE_MINIMUM_REQUIRED(VERSION 3.18.0 FATAL_ERROR) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_C_STANDARD 99) @@ -14,10 +14,17 @@ endif() project(BLS) +if(MSVC) + enable_language(ASM_MASM) +else() + enable_language(ASM) +endif() + set(BUILD_BLS_JS_BINDINGS "1" CACHE STRING "") set(BUILD_BLS_PYTHON_BINDINGS "1" CACHE STRING "") set(BUILD_BLS_TESTS "1" CACHE STRING "") set(BUILD_BLS_BENCHMARKS "1" CACHE STRING "") +set(BUILD_SODIUM "0" CACHE STRING "") message(STATUS "Build python bindings: ${BUILD_BLS_PYTHON_BINDINGS}") message(STATUS "Build tests: ${BUILD_BLS_TESTS}") @@ -29,94 +36,41 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules ) -# Relic related options - -set(STBIN "off" CACHE STRING "Relic - Build static binaries") - -find_package(gmp) -if (GMP_FOUND) - message(STATUS "Found libgmp") - set(ARITH "gmp" CACHE STRING "") -else() - set(ARITH "easy" CACHE STRING "") -endif() - -if(CMAKE_SIZEOF_VOID_P EQUAL 4) - set(WSIZE "32" CACHE STRING "Relic - Processor word size") -else() - set(WSIZE "64" CACHE STRING "Relic - Processor word size") -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 STRING "Relic - Processor word size") -endif() - -if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") - set(TIMER "ANSI" CACHE STRING "") - set(MULTI "OPENMP" CACHE STRING "") -else() - set(TIMER "CYCLE" CACHE STRING "") - set(MULTI "PTHREAD" CACHE STRING "") -endif() - -set(CHECK "off" CACHE STRING "") -set(VERBS "off" CACHE STRING "") -set(ALLOC "AUTO" CACHE STRING "") -set(SHLIB "off" CACHE STRING "") -set(DOCUM "off" CACHE STRING "") -set(FP_PRIME "381" CACHE STRING "Relic - Prime modulus size") - -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(FP_METHD "INTEG;INTEG;INTEG;MONTY;LOWER;SLIDE" CACHE STRING "") - -if(MSVC) - set(COMP_FLAGS "" CACHE STRING "") -else() - set(COMP_FLAGS "-O3 -funroll-loops -fomit-frame-pointer" CACHE STRING "") -endif() - -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 STRING "Relic - Number of times each test is ran") -set(BENCH "0" CACHE STRING "Relic - Number of times each benchmark is ran") - -set(QUIET "on" CACHE STRING "Relic - Build with printing disabled") - -set(PP_EXT "LAZYR" CACHE STRING "") -set(PP_METHD "LAZYR;OATEP" CACHE STRING "") - # Disable mimalloc shared libraries and tests, enable secure mode set(MI_SECURE "on" CACHE STRING "") set(MI_BUILD_SHARED "off" CACHE STRING "") set(MI_BUILD_TESTS "off" CACHE STRING "") set(MI_OVERRIDE "off" CACHE STRING "") - -add_subdirectory(depends/relic) add_subdirectory(depends/mimalloc) -#message(STATUS "Patching Relic to make setjmp.h inclusion conditional") -# -#execute_process( -# COMMAND bash -c "git apply ${CMAKE_SOURCE_DIR}/setjmp_patch.diff" -# WORKING_DIRECTORY ${RELIC_SRC} -#) +include(FetchContent) + +if(Sodium) +FetchContent_Declare(Sodium + GIT_REPOSITORY https://github.com/AmineKhaldi/libsodium-cmake.git + + # Latest commit at the moment this was added here + # Anchored to libsodium v1.0.18 + GIT_TAG f73a3fe1afdc4e37ac5fe0ddd401bf521f6bba65 +) +set(SODIUM_PCH "on" CACHE STRING "") +set(SODIUM_DISABLE_TESTS "on" CACHE STRING "") +set(SODIUM_CHIA_MINIMAL "on" CACHE STRING "") +FetchContent_MakeAvailable(Sodium) +endif() + +set(BLST_GIT_TAG "a8cd361c9f671577aeab3f074098443af92a53fc") +set(BLST_REPOSITORY "https://github.com/supranational/blst") + +message(STATUS "blst will be built from: ${BLST_GIT_TAG} and repository ${BLST_REPOSITORY}") + +FetchContent_Declare( + blst + GIT_REPOSITORY ${BLST_REPOSITORY} + GIT_TAG ${BLST_GIT_TAG} +) +FetchContent_MakeAvailable(blst) add_subdirectory(src) @@ -145,6 +99,6 @@ else() # emscripten can't build python bindings, it produces only javascript # add_subdirectory(contrib/pybind11) if(BUILD_BLS_PYTHON_BINDINGS) - add_subdirectory(python-bindings) + add_subdirectory(binds/python) endif() endif() diff --git a/src/dashbls/MANIFEST.in b/src/dashbls/MANIFEST.in index 3063e7883b3c..62cc22eaeea0 100644 --- a/src/dashbls/MANIFEST.in +++ b/src/dashbls/MANIFEST.in @@ -1,6 +1,44 @@ -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 +# Unused sources +exclude src/test.cpp src/test-bench.cpp + +# Foreign languages +prune js-bindings +prune go-bindings +prune rust-bindings +exclude emsdk_*.sh js_*.sh apple.rust.deps.sh + +# Vendored test dependency +prune depends/catch2 + +# Vendored dependency extras +prune depends/mimalloc/doc +prune depends/mimalloc/docs +prune depends/mimalloc/ide +prune depends/mimalloc/test +prune depends/mimalloc/contrib +prune depends/relic/.github +prune depends/relic/art +prune depends/relic/bench +prune depends/relic/demo +prune depends/relic/doc +prune depends/relic/preset +prune depends/relic/test +prune depends/relic/tools + +# Autotools build +prune build-aux +prune autom4te.cache +exclude Makefile.am Makefile.*.include Makefile.in Makefile configure.ac aclocal.m4 autogen.sh + +# dot{dir,file}s +prune .github +prune .vscode +prune .claude +exclude .clang-format .python-version .gitignore + +# Build artifacts +prune build +prune .libs +global-exclude *.o *.a *.lo *.la *.so *.dylib *.dll *.pyc +global-exclude *.orig *.rej *.bak +global-exclude *.egg-info/* diff --git a/src/dashbls/Makefile.test.include b/src/dashbls/Makefile.test.include index a8ec86cb59d1..e3e2a5356a3c 100644 --- a/src/dashbls/Makefile.test.include +++ b/src/dashbls/Makefile.test.include @@ -1,27 +1,28 @@ -# Copyright (c) 2021 The PIVX developers -# Copyright (c) 2022 The Dash Core developers -# Distributed under the MIT software license, see the accompanying -# file COPYING.MIT or http://www.opensource.org/licenses/mit-license.php. - -DASHBLS_RUNTEST = runtest - -RUNTEST_INCLUDES = \ - -I$(top_srcdir)/depends/catch2/include - -RUNTEST_H = \ - depends/catch2/include/catch2/catch.hpp - -runtest_SOURCES = \ - $(DASHBLS_H) \ - $(RELIC_H) \ - $(RUNTEST_H) \ - src/test.cpp \ - src/test-utils.hpp - -runtest_CPPFLAGS = $(AM_CPPFLAGS) $(DASHBLS_INCLUDES) $(RELIC_INCLUDES) $(RUNTEST_INCLUDES) -runtest_CXXFLAGS = $(AM_CXXFLAGS) -runtest_LDFLAGS = -static $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS) - -runtest_LDADD = $(LIBDASHBLS) - -noinst_PROGRAMS += $(DASHBLS_RUNTEST) +# Copyright (c) 2021 The PIVX developers +# Copyright (c) 2022 The Dash Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING.MIT or http://www.opensource.org/licenses/mit-license.php. + +DASHBLS_RUNTEST = runtest + +RUNTEST_INCLUDES = \ + -I$(top_srcdir)/depends/catch2/include + +RUNTEST_H = \ + depends/catch2/include/catch2/catch.hpp + +runtest_SOURCES = \ + $(DASHBLS_H) \ + $(RELIC_H) \ + $(RUNTEST_H) \ + src/test.cpp \ + src/test-utils.hpp \ + src/test-vectors.hpp + +runtest_CPPFLAGS = $(AM_CPPFLAGS) $(DASHBLS_INCLUDES) $(RELIC_INCLUDES) $(RUNTEST_INCLUDES) -DDASHBLS_REFERENCE_VECTORS=\"$(abs_top_srcdir)/test-vectors/reference.txt\" +runtest_CXXFLAGS = $(AM_CXXFLAGS) +runtest_LDFLAGS = -static $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS) + +runtest_LDADD = $(LIBDASHBLS) + +noinst_PROGRAMS += $(DASHBLS_RUNTEST) diff --git a/src/dashbls/NOTICE b/src/dashbls/NOTICE new file mode 100644 index 000000000000..a8f984371607 --- /dev/null +++ b/src/dashbls/NOTICE @@ -0,0 +1,153 @@ +dashbls (https://github.com/dashpay/bls-signatures) + +Copyright (c) 2018-present, Chia Network, Inc. +Copyright (c) 2021-present, The Dash Core developers. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +-------------------------------------------------------------------------- + +relic (https://github.com/relic-toolkit/relic) + +Copyright (c) 2009 RELIC Authors + +RELIC is free software; you can redistribute it and/or modify it under the +terms of the version 2.1 (or later) of the GNU Lesser General Public License +as published by the Free Software Foundation; or version 2.0 of the Apache +License as published by the Apache Software Foundation. See the LICENSE files +for more details. + +RELIC 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 LICENSE files for more details. + +You should have received a copy of the GNU Lesser General Public or the +Apache License along with RELIC. If not, see +or . + +-------------------------------------------------------------------------- + +mimalloc (https://github.com/microsoft/mimalloc) + +MIT License + +Copyright (c) 2018-2025 Microsoft Corporation, Daan Leijen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +-------------------------------------------------------------------------- + +GNU MP (https://gmplib.org/) + +Copyright 1991-present Free Software Foundation, Inc. + +The GNU MP Library is free software; you can redistribute it and/or modify +it under the terms of either: + + * the GNU Lesser General Public License as published by the Free Software + Foundation; either version 3 of the License, or (at your option) any + later version. + +or + + * the GNU General Public License as published by the Free Software + Foundation; either version 2 of the License, or (at your option) any + later version. + +or both in parallel, as here. + +The GNU MP Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License and +the GNU Lesser General Public License for more details. + +You should have received copies of the GNU General Public License and the +GNU Lesser General Public License along with the GNU MP Library. If not, see +https://www.gnu.org/licenses/. + +-------------------------------------------------------------------------- + +pybind11 (https://github.com/pybind/pybind11) + +Copyright (c) 2016 Wenzel Jakob , All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +-------------------------------------------------------------------------- + +Catch2 (https://github.com/catchorg/Catch2) + +Copyright (c) 2022 Two Blue Cubes Ltd. All rights reserved. + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/src/dashbls/README.md b/src/dashbls/README.md index 8460ac818ea7..37a3243c63a6 100644 --- a/src/dashbls/README.md +++ b/src/dashbls/README.md @@ -1,299 +1,123 @@ -# BLS Signatures implementation +[![GitHub License](https://img.shields.io/github/license/dashpay/bls-signatures)](https://github.com/dashpay/bls-signatures/blob/main/LICENSE) +[![Library status](https://img.shields.io/github/actions/workflow/status/dashpay/bls-signatures/build-test.yaml?branch=main&style=flat&logo=github&logoColor=white&label=library)](https://github.com/dashpay/bls-signatures/actions/workflows/build-test.yaml?query=branch%3Amain) +[![Binds status](https://img.shields.io/github/actions/workflow/status/dashpay/bls-signatures/build-binds.yml?branch=main&style=flat&logo=github&logoColor=white&label=binds)](https://github.com/dashpay/bls-signatures/actions/workflows/build-binds.yml?query=branch%3Amain) -[![Build and Test C++, Javascript, and Python](https://github.com/Chia-Network/bls-signatures/actions/workflows/build-test.yaml/badge.svg)](https://github.com/Chia-Network/bls-signatures/actions/workflows/build-test.yaml) -![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); -``` +> [!WARNING] +> +> **This library has not undergone a formal security review.** -## Serializing keys and signatures to bytes +`bls-signatures` is a cross-platform library implementing BLS12-381 primitives for Dash built on +the [`blst library`](https://github.com/supranational/blst.git) toolkit with bindings available in +[Python](./binds/python), [Rust](./rust-bindings/), [Go](./go-bindings/) and [Javascript](./js-bindings). -```c++ -vector skBytes = sk.Serialize(); -vector pkBytes = pk.Serialize(); -vector signatureBytes = signature.Serialize(); +## Dependencies -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 -``` +* A C++17 capable compiler (GCC 9, Clang 7 or higher) +* CMake 3.18 or higher (or Autoconf 2.71 or higher; with libtool and automake) -## Loading keys and signatures from bytes +Additionally, the following dependencies are supplied by the codebase -```c++ -// Takes vector of 32 bytes -PrivateKey skc = PrivateKey::FromByteVector(skBytes); +* [`catch2`](https://github.com/catchorg/Catch2) (for tests) +* [`mimalloc`](https://github.com/microsoft/mimalloc) (for secure memory operations) +* [`blst`](https://github.com/supranational/blst.git) (for cryptographic operations) -// Takes vector of 48 bytes -pk = G1Element::FromByteVector(pkBytes); +## Build library -// Takes vector of 96 bytes -signature = G2Element::FromByteVector(signatureBytes); -``` +> [!NOTE] +> Multi-config generators (like Visual Studio) place the binaries under a per-configuration directory, so on Windows the +> executables are at `src\Release\runtest.exe` and `src\Release\runbench.exe`. -## Create aggregate signatures +```sh +# Create scratchpad directory +mkdir build && cd build -```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}; +# Configure build files +cmake .. -// Generate first sig -G1Element pk1 = sk1.GetG1Element(); -G2Element sig1 = AugSchemeMPL().Sign(sk1, message); +# Build library with 4 threads +cmake --build . --parallel 4 -// Generate second sig -G1Element pk2 = sk2.GetG1Element(); -G2Element sig2 = AugSchemeMPL().Sign(sk2, message2); +# Run tests +./src/runtest -// Signatures can be non-interactively combined by anyone -G2Element aggSig = AugSchemeMPL().Aggregate({sig1, sig2}); - -ok = AugSchemeMPL().AggregateVerify({pk1, pk2}, {message, message2}, aggSig); +# Run benchmarks +./src/runbench ``` -## 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); - +## Install Python binds -G2Element aggSigFinal = AugSchemeMPL().Aggregate({aggSig, sig3}); -ok = AugSchemeMPL().AggregateVerify({pk1, pk2, pk3}, {message, message2, message3}, aggSigFinal); +Releases are published to a [PEP 503](https://peps.python.org/pep-0503/) index hosted on GitHub Pages rather than to +PyPI. +```sh +pip install --extra-index-url https://dashpay.github.io/bls-signatures/pep503/ dashbls ``` -## 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}); +> [!IMPORTANT] +> Use `--extra-index-url`, not `--index-url`. Platforms we do not ship a wheel for fall back to the sdist, and building +> it needs `cmake`, `pybind11`, `setuptools_scm` and `setuptools` from PyPI. `--index-url` would replace PyPI with an +> index that carries only `dashbls`, so the build would fail before it started. -ok = PopSchemeMPL().FastAggregateVerify({pk1, pk2, pk3}, message, popSigAgg); +## Build Python binds -// Aggregate public key, indistinguishable from a single public key -G1Element popAggPk = pk1 + pk2 + pk3; -ok = PopSchemeMPL().Verify(popAggPk, message, popSigAgg); +Our Python binds target Python 3.10 or higher; they depend on the following packages. Sample code is available +at [`binds/python/samples`](binds/python/samples). -// Aggregate private keys -PrivateKey aggSk = PrivateKey::Aggregate({sk1, sk2, sk3}); -ok = (PopSchemeMPL().Sign(aggSk, message) == popSigAgg); -``` +* [`pybind11`](https://github.com/pybind/pybind11) (bridging C++ and Python) +* [`pytest`](https://github.com/pytest-dev/pytest) (benchmarks and unit tests, part of optional `[dev]` dependency group) +* [`ruff`](https://github.com/astral-sh/ruff) (linting, part of optional `[dev]` dependency group) -## HD keys using [EIP-2333](https://github.com/ethereum/EIPs/pull/2333) +> [!NOTE] +> We recommend using programs like [`uv`](https://github.com/astral-sh/uv) to manage your virtualenv (`venv`) to prevent +> cross-contamination with Python-based native packages or other Python projects. -```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) +```sh +# Create a new venv named dashbls +uv venv dashbls -// 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); +# Enter venv +source dashbls/bin/activate -G1Element childUPk = AugSchemeMPL().DeriveChildPkUnhardened(masterPk, 22); -G1Element grandchildUPk = AugSchemeMPL().DeriveChildPkUnhardened(childUPk, 0); +# Install developer dependencies +uv pip install -e ".[dev]" -ok = (grandchildUPk == grandchildU.GetG1Element(); -``` +# Build binds +uv build -## Build +# Run linter and formatter +uv run ruff check +uv run ruff format --check -Cmake 3.14+, a c++ compiler, and python3 (for bindings) are required for building. +# Run unit tests +uv run pytest -v binds/python/test_unit.py -```bash -mkdir build -cd build -cmake ../ -cmake --build . -- -j 6 +# Run benchmarks +uv run pytest -v binds/python/test_bench.py --benchmark-only ``` -### Run tests +## BLST license -```bash -./build/src/runtest -``` +BLST is used with the +[Apache 2.0 license](https://github.com/supranational/blst/blob/master/LICENSE) -### Run benchmarks +## License -```bash -./build/src/runbench -``` +```text +Copyright (c) 2018-present, Chia Network, Inc. +Copyright (c) 2021-present, The Dash Core developers. -On a 3.5 GHz i7 Mac, verification takes about 1.1ms per signature, and signing takes 1.3ms. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at -### Link the library to use it + http://www.apache.org/licenses/LICENSE-2.0 -```bash -g++ -Wl,-no_pie -std=c++11 -Ibls-signatures/depends/relic/include -Ibls-signatures/build/depends/relic/include -Ibls-signatures/src -L./bls-signatures/build/ -l bls yourapp.cpp +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. ``` -## Notes on dependencies - -We use Libsodium and have GMP as an optional dependency: 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/`. - -## 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) +The above license terms are available in [`LICENSE`](./LICENSE) and licensing terms for dependencies are +available in [`NOTICE`](./NOTICE) diff --git a/src/dashbls/autogen.sh b/src/dashbls/autogen.sh index de4600499e09..f3e943e167db 100755 --- a/src/dashbls/autogen.sh +++ b/src/dashbls/autogen.sh @@ -10,3 +10,4 @@ fi command -v autoreconf >/dev/null || \ (echo "configuration failed, please install autoconf first" && exit 1) autoreconf --install --force --warnings=all +autoheader --force --replace-handwritten || autoheader --force diff --git a/src/dashbls/binds/python/CMakeLists.txt b/src/dashbls/binds/python/CMakeLists.txt new file mode 100644 index 000000000000..9117ade8f3cf --- /dev/null +++ b/src/dashbls/binds/python/CMakeLists.txt @@ -0,0 +1,24 @@ +find_package(pybind11 2.13.6 CONFIG QUIET) + +if(NOT pybind11_FOUND) + message(STATUS "pybind11 not found locally; fetching it") + include(FetchContent) + FetchContent_Declare( + pybind11 + GIT_REPOSITORY https://github.com/pybind/pybind11.git + GIT_TAG v2.13.6 + ) + FetchContent_MakeAvailable(pybind11) +endif() + +pybind11_add_module(dashbls_py ${CMAKE_CURRENT_SOURCE_DIR}/pythonbindings.cpp) +set_target_properties(dashbls_py PROPERTIES OUTPUT_NAME dashbls) +target_include_directories(dashbls_py PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../../include +) +target_link_libraries(dashbls_py PRIVATE dashbls) + +if(VERSION_INFO) + target_compile_definitions(dashbls_py PRIVATE VERSION_INFO="${VERSION_INFO}") +endif() diff --git a/src/dashbls/binds/python/conftest.py b/src/dashbls/binds/python/conftest.py new file mode 100644 index 000000000000..d595d6ea8ca8 --- /dev/null +++ b/src/dashbls/binds/python/conftest.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 +# coding: latin-1 + +# +# Copyright (c) 2026-present, The Dash Core developers +# SPDX-License-Identifier: Apache-2.0 +# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 +# + +"""Allow samples to be imported by name.""" + +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).parent / "samples")) diff --git a/src/dashbls/python-bindings/pythonbindings.cpp b/src/dashbls/binds/python/pythonbindings.cpp similarity index 55% rename from src/dashbls/python-bindings/pythonbindings.cpp rename to src/dashbls/binds/python/pythonbindings.cpp index 4ba2acb83a67..0cc223d6e726 100644 --- a/src/dashbls/python-bindings/pythonbindings.cpp +++ b/src/dashbls/binds/python/pythonbindings.cpp @@ -16,6 +16,16 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include #include #include @@ -34,9 +44,107 @@ inline int PyLong_AsByteArray(PyLongObject* obj, uint8_t* buf, Py_ssize_t size, #endif // PY_VERSION_HEX >= 0x030d0000 ); } + +// relic's context is process-wide here (MULTI is unset, see setup.py), so a +// released GIL leaves threads racing on its error code and PRNG state. The +// GIL goes first so a waiter cannot strand the holder that must retake it. +std::mutex &RelicMutex() +{ + static std::mutex mutex; + return mutex; +} + +struct RelicGuard { + RelicGuard() : lock(RelicMutex()) {} + + py::gil_scoped_release release; + std::lock_guard lock; +}; + +// Measure before copying, so an oversized input fails as ValueError instead of +// bad_alloc, and measure the header rather than py::len, because a subclass may +// override __len__ while the copy below still takes the backing payload. +std::string CopyChecked(const py::bytes &b, size_t limit, const char *who, const char *what) +{ + const auto signed_size = PyBytes_Size(b.ptr()); + if (signed_size < 0) { + throw py::error_already_set(); + } + const auto size = static_cast(signed_size); + if (size > limit) { + throw std::invalid_argument( + std::string(who) + ": " + what + " must be at most " + std::to_string(limit) + + " bytes, got " + std::to_string(size)); + } + return std::string(b); +} + +// md_xmd caps a tag at 255 bytes but compares signed, so a tag at or beyond +// 2 GiB truncates negative, slips the guard and is widened back to a huge +// length. +std::string CopyDst(const py::bytes &dst, const char *who) +{ + return CopyChecked(dst, 255, who, "domain separation tag"); +} + +// ep_map_dst takes the message length as an int and md_xmd checks only the +// output and tag lengths, so nothing on relic's side catches a message at or +// beyond 2 GiB narrowing negative on the way in. +std::string CopyMsg(const py::bytes &msg, const char *who) +{ + return CopyChecked(msg, std::numeric_limits::max(), who, "message"); +} + +// The augmented schemes prepend a serialized G1Element and hand the result to +// the same int-typed length, so the message has to leave room for the prefix. +std::string CopyAugMsg(const py::bytes &msg, const char *who) +{ + return CopyChecked( + msg, std::numeric_limits::max() - G1Element::SIZE, who, "message"); +} + +// relic is built ALLOC=AUTO, so md_hmac stages the seed on the stack and a few +// MiB of it takes the process down. Nothing near this cap is a legitimate IKM +// (the spec floor is 32 bytes), so keep it far below any thread's stack. +std::string CopySeed(const py::bytes &seed, const char *who) +{ + return CopyChecked(seed, 64 * 1024, who, "seed"); +} + +std::vector ToVec(const std::string &s) +{ + return std::vector(s.begin(), s.end()); +} + +// Bytes is a pointer and a length, so a strided view has no counterpart to +// mirror; ask CPython for a contiguous one and let it raise, rather than +// reinterpreting info.ptr as contiguous and reading past the caller's view. +template +std::array CopyBuffer(const py::buffer &b, const char *what) +{ + auto *view = new Py_buffer(); + if (PyObject_GetBuffer(b.ptr(), view, PyBUF_C_CONTIGUOUS | PyBUF_FORMAT) != 0) { + delete view; + throw py::error_already_set(); + } + py::buffer_info info(view); + + if (info.format != py::format_descriptor::format() || info.ndim != 1) + throw std::runtime_error("Incompatible buffer format!"); + + if (info.size != static_cast(N)) { + throw std::invalid_argument( + std::string("Length of bytes object not equal to ") + what); + } + + std::array data; + const auto *data_ptr = reinterpret_cast(info.ptr); + std::copy(data_ptr, data_ptr + N, data.data()); + return data; +} } // anonymous namespace -PYBIND11_MODULE(blspy, m) +PYBIND11_MODULE(dashbls, m) { py::class_(m, "PrivateKey") .def_property_readonly_static( @@ -45,19 +153,8 @@ PYBIND11_MODULE(blspy, m) .def( "from_bytes", [](py::buffer const b) { - py::buffer_info info = b.request(); - if (info.format != py::format_descriptor::format() || - info.ndim != 1) - throw std::runtime_error("Incompatible buffer format!"); - - if ((int)info.size != PrivateKey::PRIVATE_KEY_SIZE) { - throw std::invalid_argument( - "Length of bytes object not equal to PrivateKey::SIZE"); - } - auto data_ptr = reinterpret_cast(info.ptr); - std::array data; - std::copy(data_ptr, data_ptr + data.size(), data.data()); - py::gil_scoped_release release; + auto data = CopyBuffer(b, "PrivateKey::SIZE"); + RelicGuard guard; return PrivateKey::FromBytes(data); }) .def( @@ -66,7 +163,7 @@ PYBIND11_MODULE(blspy, m) uint8_t *output = Util::SecAlloc(PrivateKey::PRIVATE_KEY_SIZE); { - py::gil_scoped_release release; + RelicGuard guard; k.Serialize(output); } py::bytes ret = py::bytes( @@ -78,17 +175,18 @@ PYBIND11_MODULE(blspy, m) .def( "__deepcopy__", [](const PrivateKey &k, const py::object &memo) { + RelicGuard guard; return PrivateKey(k); }) .def("get_g1", [](const PrivateKey &k) { - py::gil_scoped_release release; + RelicGuard guard; return k.GetG1Element(); }) - .def("aggregate", &PrivateKey::Aggregate, py::call_guard()) - .def(py::self == py::self) - .def(py::self != py::self) + .def("aggregate", &PrivateKey::Aggregate, py::call_guard()) + .def(py::self == py::self, py::call_guard()) + .def(py::self != py::self, py::call_guard()) .def("__repr__", [](const PrivateKey &k) { - py::gil_scoped_release release; + RelicGuard guard; uint8_t *output = Util::SecAlloc(PrivateKey::PRIVATE_KEY_SIZE); k.Serialize(output); std::string ret = @@ -99,11 +197,11 @@ PYBIND11_MODULE(blspy, m) }); py::class_(m, "Util").def("hash256", [](const py::bytes &message) { - std::string str(message); - const uint8_t *input = reinterpret_cast(str.data()); + // Hash256 takes a size_t but md_map_sh256 narrows it to an int + const auto str = CopyMsg(message, "Util.hash256"); uint8_t output[BLS::MESSAGE_HASH_LEN]; { - py::gil_scoped_release release; + RelicGuard guard; Util::Hash256(output, (const uint8_t *)str.data(), str.size()); } return py::bytes( @@ -112,50 +210,47 @@ PYBIND11_MODULE(blspy, m) py::class_(m, "BasicSchemeMPL") .def("sk_to_g1", [](const PrivateKey &seckey){ - py::gil_scoped_release release; + RelicGuard guard; return BasicSchemeMPL().SkToG1(seckey); }) .def( "key_gen", [](const py::bytes &b) { - std::string str(b); - py::gil_scoped_release release; - const vector inputVec(str.begin(), str.end()); - return BasicSchemeMPL().KeyGen(inputVec); + const auto str = CopySeed(b, "BasicSchemeMPL.key_gen"); + RelicGuard guard; + return BasicSchemeMPL().KeyGen(ToVec(str)); }) .def("derive_child_sk", [](const PrivateKey& sk, uint32_t index){ - py::gil_scoped_release release; + RelicGuard guard; return BasicSchemeMPL().DeriveChildSk(sk, index); }) .def("derive_child_sk_unhardened", [](const PrivateKey& sk, uint32_t index){ - py::gil_scoped_release release; + RelicGuard guard; return BasicSchemeMPL().DeriveChildSkUnhardened(sk, index); }) .def("derive_child_pk_unhardened", [](const G1Element& pk, uint32_t index){ - py::gil_scoped_release release; + RelicGuard guard; return BasicSchemeMPL().DeriveChildPkUnhardened(pk, index); }) .def("aggregate", [](const vector &signatures) { - py::gil_scoped_release release; + RelicGuard guard; return BasicSchemeMPL().Aggregate(signatures); }) .def( "sign", [](const PrivateKey &pk, const py::bytes &msg) { - std::string s(msg); - py::gil_scoped_release release; - vector v(s.begin(), s.end()); - return BasicSchemeMPL().Sign(pk, v); + const auto s = CopyMsg(msg, "BasicSchemeMPL.sign"); + RelicGuard guard; + return BasicSchemeMPL().Sign(pk, ToVec(s)); }) .def( "verify", [](const G1Element &pk, const py::bytes &msg, const G2Element &sig) { - std::string s(msg); - py::gil_scoped_release release; - vector v(s.begin(), s.end()); - return BasicSchemeMPL().Verify(pk, v, sig); + const auto s = CopyMsg(msg, "BasicSchemeMPL.verify"); + RelicGuard guard; + return BasicSchemeMPL().Verify(pk, ToVec(s), sig); }) .def( "aggregate_verify", @@ -163,18 +258,18 @@ PYBIND11_MODULE(blspy, m) const vector &msgs, const G2Element &sig) { vector> vecs(msgs.size()); - for (int i = 0; i < (int)msgs.size(); ++i) { - std::string s(msgs[i]); - vecs[i] = vector(s.begin(), s.end()); + for (size_t i = 0; i < msgs.size(); ++i) { + vecs[i] = ToVec( + CopyMsg(msgs[i], "BasicSchemeMPL.aggregate_verify")); } - py::gil_scoped_release release; + RelicGuard guard; return BasicSchemeMPL().AggregateVerify(pks, vecs, sig); }) .def( "g2_from_message", [](const py::bytes &msg) { - const auto msg_str = std::string(msg); - py::gil_scoped_release release; + const auto msg_str = CopyMsg(msg, "BasicSchemeMPL.g2_from_message"); + RelicGuard guard; const auto msg_bytes = Bytes((const uint8_t *)msg_str.c_str(), msg_str.size()); return G2Element::FromMessage( msg_bytes, @@ -185,60 +280,56 @@ PYBIND11_MODULE(blspy, m) py::class_(m, "AugSchemeMPL") .def("sk_to_g1", [](const PrivateKey &seckey){ - py::gil_scoped_release release; + RelicGuard guard; return AugSchemeMPL().SkToG1(seckey); }) .def( "key_gen", [](const py::bytes &b) { - std::string str(b); - py::gil_scoped_release release; - const vector inputVec(str.begin(), str.end()); - return AugSchemeMPL().KeyGen(inputVec); + const auto str = CopySeed(b, "AugSchemeMPL.key_gen"); + RelicGuard guard; + return AugSchemeMPL().KeyGen(ToVec(str)); }) .def("derive_child_sk", [](const PrivateKey& sk, uint32_t index){ - py::gil_scoped_release release; + RelicGuard guard; return AugSchemeMPL().DeriveChildSk(sk, index); }) .def("derive_child_sk_unhardened", [](const PrivateKey& sk, uint32_t index){ - py::gil_scoped_release release; + RelicGuard guard; return AugSchemeMPL().DeriveChildSkUnhardened(sk, index); }) .def("derive_child_pk_unhardened", [](const G1Element& pk, uint32_t index){ - py::gil_scoped_release release; + RelicGuard guard; return AugSchemeMPL().DeriveChildPkUnhardened(pk, index); }) .def("aggregate", [](const vector& signatures) { - py::gil_scoped_release release; + RelicGuard guard; return AugSchemeMPL().Aggregate(signatures); }) .def( "sign", [](const PrivateKey &pk, const py::bytes &msg) { - std::string s(msg); - py::gil_scoped_release release; - vector v(s.begin(), s.end()); - return AugSchemeMPL().Sign(pk, v); + const auto s = CopyAugMsg(msg, "AugSchemeMPL.sign"); + RelicGuard guard; + return AugSchemeMPL().Sign(pk, ToVec(s)); }) .def( "sign", [](const PrivateKey &pk, const py::bytes &msg, const G1Element &prepend_pk) { - std::string s(msg); - py::gil_scoped_release release; - vector v(s.begin(), s.end()); - return AugSchemeMPL().Sign(pk, v, prepend_pk); + const auto s = CopyAugMsg(msg, "AugSchemeMPL.sign"); + RelicGuard guard; + return AugSchemeMPL().Sign(pk, ToVec(s), prepend_pk); }) .def( "verify", [](const G1Element &pk, const py::bytes &msg, const G2Element &sig) { - std::string s(msg); - py::gil_scoped_release release; - vector v(s.begin(), s.end()); - return AugSchemeMPL().Verify(pk, v, sig); + const auto s = CopyAugMsg(msg, "AugSchemeMPL.verify"); + RelicGuard guard; + return AugSchemeMPL().Verify(pk, ToVec(s), sig); }) .def( "aggregate_verify", @@ -246,18 +337,18 @@ PYBIND11_MODULE(blspy, m) const vector &msgs, const G2Element &sig) { vector> vecs(msgs.size()); - for (int i = 0; i < (int)msgs.size(); ++i) { - std::string s(msgs[i]); - vecs[i] = vector(s.begin(), s.end()); + for (size_t i = 0; i < msgs.size(); ++i) { + vecs[i] = ToVec( + CopyAugMsg(msgs[i], "AugSchemeMPL.aggregate_verify")); } - py::gil_scoped_release release; + RelicGuard guard; return AugSchemeMPL().AggregateVerify(pks, vecs, sig); }) .def( "g2_from_message", [](const py::bytes &msg) { - const auto msg_str = std::string(msg); - py::gil_scoped_release release; + const auto msg_str = CopyMsg(msg, "AugSchemeMPL.g2_from_message"); + RelicGuard guard; const auto msg_bytes = Bytes((const uint8_t *)msg_str.c_str(), msg_str.size()); return G2Element::FromMessage( msg_bytes, @@ -268,50 +359,47 @@ PYBIND11_MODULE(blspy, m) py::class_(m, "PopSchemeMPL") .def("sk_to_g1", [](const PrivateKey &seckey){ - py::gil_scoped_release release; + RelicGuard guard; return PopSchemeMPL().SkToG1(seckey); }) .def( "key_gen", [](const py::bytes &b) { - std::string str(b); - py::gil_scoped_release release; - const vector inputVec(str.begin(), str.end()); - return PopSchemeMPL().KeyGen(inputVec); + const auto str = CopySeed(b, "PopSchemeMPL.key_gen"); + RelicGuard guard; + return PopSchemeMPL().KeyGen(ToVec(str)); }) .def("derive_child_sk", [](const PrivateKey& sk, uint32_t index){ - py::gil_scoped_release release; + RelicGuard guard; return PopSchemeMPL().DeriveChildSk(sk, index); }) .def("derive_child_sk_unhardened", [](const PrivateKey& sk, uint32_t index){ - py::gil_scoped_release release; + RelicGuard guard; return PopSchemeMPL().DeriveChildSkUnhardened(sk, index); }) .def("derive_child_pk_unhardened", [](const G1Element& pk, uint32_t index){ - py::gil_scoped_release release; + RelicGuard guard; return PopSchemeMPL().DeriveChildPkUnhardened(pk, index); }) .def("aggregate", [](const vector& signatures) { - py::gil_scoped_release release; + RelicGuard guard; return PopSchemeMPL().Aggregate(signatures); }) .def( "sign", [](const PrivateKey &pk, const py::bytes &msg) { - std::string s(msg); - py::gil_scoped_release release; - vector v(s.begin(), s.end()); - return PopSchemeMPL().Sign(pk, v); + const auto s = CopyMsg(msg, "PopSchemeMPL.sign"); + RelicGuard guard; + return PopSchemeMPL().Sign(pk, ToVec(s)); }) .def( "verify", [](const G1Element &pk, const py::bytes &msg, const G2Element &sig) { - std::string s(msg); - py::gil_scoped_release release; - vector v(s.begin(), s.end()); - return PopSchemeMPL().Verify(pk, v, sig); + const auto s = CopyMsg(msg, "PopSchemeMPL.verify"); + RelicGuard guard; + return PopSchemeMPL().Verify(pk, ToVec(s), sig); }) .def( "aggregate_verify", @@ -319,18 +407,18 @@ PYBIND11_MODULE(blspy, m) const vector &msgs, const G2Element &sig) { vector> vecs(msgs.size()); - for (int i = 0; i < (int)msgs.size(); ++i) { - std::string s(msgs[i]); - vecs[i] = vector(s.begin(), s.end()); + for (size_t i = 0; i < msgs.size(); ++i) { + vecs[i] = + ToVec(CopyMsg(msgs[i], "PopSchemeMPL.aggregate_verify")); } - py::gil_scoped_release release; + RelicGuard guard; return PopSchemeMPL().AggregateVerify(pks, vecs, sig); }) .def( "g2_from_message", [](const py::bytes &msg) { - const auto msg_str = std::string(msg); - py::gil_scoped_release release; + const auto msg_str = CopyMsg(msg, "PopSchemeMPL.g2_from_message"); + RelicGuard guard; const auto msg_bytes = Bytes((const uint8_t *)msg_str.c_str(), msg_str.size()); return G2Element::FromMessage( msg_bytes, @@ -339,11 +427,11 @@ PYBIND11_MODULE(blspy, m) ); }) .def("pop_prove", [](const PrivateKey& privateKey){ - py::gil_scoped_release release; + RelicGuard guard; return PopSchemeMPL().PopProve(privateKey); }) .def("pop_verify", [](const G1Element& pubkey, const G2Element& signature){ - py::gil_scoped_release release; + RelicGuard guard; return PopSchemeMPL().PopVerify(pubkey, signature); }) .def( @@ -351,20 +439,19 @@ PYBIND11_MODULE(blspy, m) [](const vector &pks, const py::bytes &msg, const G2Element &sig) { - std::string s(msg); - py::gil_scoped_release release; - vector v(s.begin(), s.end()); - return PopSchemeMPL().FastAggregateVerify(pks, v, sig); + const auto s = CopyMsg(msg, "PopSchemeMPL.fast_aggregate_verify"); + RelicGuard guard; + return PopSchemeMPL().FastAggregateVerify(pks, ToVec(s), sig); }); py::class_(m, "G1Element") .def_property_readonly_static( "SIZE", [](py::object self) { return G1Element::SIZE; }) .def(py::init([](){ - py::gil_scoped_release release; + RelicGuard guard; return G1Element(); })) - .def(py::init(&G1Element::FromByteVector), py::call_guard()) + .def(py::init(&G1Element::FromByteVector), py::call_guard()) .def(py::init([](py::int_ pyint) { std::array buffer{}; if (PyLong_AsByteArray( @@ -375,103 +462,72 @@ PYBIND11_MODULE(blspy, m) 0) < 0) { throw std::invalid_argument("Failed to cast int to G1Element"); } - py::gil_scoped_release release; + RelicGuard guard; return G1Element::FromBytes(buffer); })) .def(py::init([](py::buffer const b) { - py::buffer_info info = b.request(); - if (info.format != py::format_descriptor::format() || - info.ndim != 1) - throw std::runtime_error("Incompatible buffer format!"); - - if ((int)info.size != G1Element::SIZE) { - throw std::invalid_argument( - "Length of bytes object not equal to G1Element::SIZE"); - } - auto data_ptr = static_cast(info.ptr); - std::array data; - std::copy(data_ptr, data_ptr + data.size(), data.data()); - py::gil_scoped_release release; + auto data = CopyBuffer(b, "G1Element::SIZE"); + RelicGuard guard; return G1Element::FromBytes(data); })) .def( "from_bytes", [](py::buffer const b) { - py::buffer_info info = b.request(); - if (info.format != py::format_descriptor::format() || - info.ndim != 1) - throw std::runtime_error("Incompatible buffer format!"); - - if ((int)info.size != G1Element::SIZE) { - throw std::invalid_argument( - "Length of bytes object not equal to G1Element::SIZE"); - } - auto data_ptr = reinterpret_cast(info.ptr); - std::array data; - std::copy(data_ptr, data_ptr + data.size(), data.data()); - py::gil_scoped_release release; + auto data = CopyBuffer(b, "G1Element::SIZE"); + RelicGuard guard; return G1Element::FromBytes(data); }) .def( "from_bytes_unchecked", [](py::buffer const b) { - py::buffer_info info = b.request(); - if (info.format != py::format_descriptor::format() || - info.ndim != 1) - throw std::runtime_error("Incompatible buffer format!"); - - if ((int)info.size != G1Element::SIZE) { - throw std::invalid_argument( - "Length of bytes object not equal to G1Element::SIZE"); - } - auto data_ptr = reinterpret_cast(info.ptr); - return G1Element::FromBytesUnchecked({data_ptr, G1Element::SIZE}); - }) - .def("generator", &G1Element::Generator) - .def("from_message", py::overload_cast&, const uint8_t*, int>(&G1Element::FromMessage), py::call_guard()) - .def("pair", &G1Element::Pair, py::call_guard()) - .def("negate", &G1Element::Negate, py::call_guard()) - .def("get_fingerprint", &G1Element::GetFingerprint, py::call_guard()) - - .def(py::self == py::self) - .def(py::self != py::self) + auto data = CopyBuffer(b, "G1Element::SIZE"); + RelicGuard guard; + return G1Element::FromBytesUnchecked(data); + }) + .def("generator", &G1Element::Generator, py::call_guard()) + .def_static( + "from_message", + [](const py::bytes &msg, const py::bytes &dst) { + const auto msg_str = CopyMsg(msg, "G1Element.from_message"); + const auto dst_str = CopyDst(dst, "G1Element.from_message"); + RelicGuard guard; + return G1Element::FromMessage( + Bytes((const uint8_t *)msg_str.c_str(), msg_str.size()), + (const uint8_t *)dst_str.c_str(), + (int)dst_str.size()); + }, + py::arg("msg"), + py::arg("dst")) + .def("pair", &G1Element::Pair, py::call_guard()) + .def("negate", &G1Element::Negate, py::call_guard()) + .def("get_fingerprint", &G1Element::GetFingerprint, py::call_guard()) + + .def(py::self == py::self, py::call_guard()) + .def(py::self != py::self, py::call_guard()) .def( "__deepcopy__", [](const G1Element &g1, const py::object &memo) { + RelicGuard guard; return G1Element(g1); }) .def( "__add__", [](G1Element &self, G1Element &other) { - py::gil_scoped_release release; + RelicGuard guard; return self + other; }, py::is_operator()) - .def( - "__mul__", - [](G1Element &self, bn_t other) { - py::gil_scoped_release release; - return self * (*(bn_t *)&other); - }, - py::is_operator()) - .def( - "__rmul__", - [](G1Element &self, bn_t other) { - py::gil_scoped_release release; - return self * (*(bn_t *)&other); - }, - py::is_operator()) .def( "__and__", [](G1Element &self, G2Element &other) { - py::gil_scoped_release release; + RelicGuard guard; return self & other; }, py::is_operator()) .def( "__repr__", [](const G1Element &ele) { - py::gil_scoped_release release; + RelicGuard guard; std::stringstream s; s << ele; return ""; @@ -479,7 +535,7 @@ PYBIND11_MODULE(blspy, m) .def( "__str__", [](const G1Element &ele) { - py::gil_scoped_release release; + RelicGuard guard; std::stringstream s; s << ele; return s.str(); @@ -489,7 +545,7 @@ PYBIND11_MODULE(blspy, m) [](const G1Element &ele) { vector out; { - py::gil_scoped_release release; + RelicGuard guard; out = ele.Serialize(); } py::bytes ans = py::bytes( @@ -497,6 +553,7 @@ PYBIND11_MODULE(blspy, m) return ans; }) .def("__deepcopy__", [](const G1Element &ele, const py::object &memo) { + RelicGuard guard; return G1Element(ele); }); @@ -504,23 +561,13 @@ PYBIND11_MODULE(blspy, m) .def_property_readonly_static( "SIZE", [](py::object self) { return G2Element::SIZE; }) .def(py::init([](){ + RelicGuard guard; return G2Element(); })) - .def(py::init(&G2Element::FromByteVector), py::call_guard()) + .def(py::init(&G2Element::FromByteVector), py::call_guard()) .def(py::init([](py::buffer const b) { - py::buffer_info info = b.request(); - if (info.format != py::format_descriptor::format() || - info.ndim != 1) - throw std::runtime_error("Incompatible buffer format!"); - - if ((int)info.size != G2Element::SIZE) { - throw std::invalid_argument( - "Length of bytes object not equal to G2Element::SIZE"); - } - auto data_ptr = static_cast(info.ptr); - std::array data; - std::copy(data_ptr, data_ptr + data.size(), data.data()); - py::gil_scoped_release release; + auto data = CopyBuffer(b, "G2Element::SIZE"); + RelicGuard guard; return G2Element::FromBytes(data); })) .def(py::init([](py::int_ pyint) { @@ -533,80 +580,59 @@ PYBIND11_MODULE(blspy, m) 0) < 0) { throw std::invalid_argument("Failed to cast int to G2Element"); } - py::gil_scoped_release release; + RelicGuard guard; return G2Element::FromBytes(buffer); })) .def( "from_bytes", [](py::buffer const b) { - py::buffer_info info = b.request(); - if (info.format != py::format_descriptor::format() || - info.ndim != 1) - throw std::runtime_error("Incompatible buffer format!"); - - if ((int)info.size != G2Element::SIZE) { - throw std::invalid_argument( - "Length of bytes object not equal to G2Element::SIZE"); - } - auto data_ptr = reinterpret_cast(info.ptr); - std::array data; - std::copy(data_ptr, data_ptr + data.size(), data.data()); - py::gil_scoped_release release; + auto data = CopyBuffer(b, "G2Element::SIZE"); + RelicGuard guard; return G2Element::FromBytes(data); }) .def( "from_bytes_unchecked", [](py::buffer const b) { - py::buffer_info info = b.request(); - if (info.format != py::format_descriptor::format() || - info.ndim != 1) - throw std::runtime_error("Incompatible buffer format!"); - - if ((int)info.size != G2Element::SIZE) { - throw std::invalid_argument( - "Length of bytes object not equal to G2Element::SIZE"); - } - auto data_ptr = reinterpret_cast(info.ptr); - return G2Element::FromBytesUnchecked({data_ptr, G2Element::SIZE}); - }) - .def("generator", &G2Element::Generator) - .def("from_message", py::overload_cast&, const uint8_t*, int, bool>(&G2Element::FromMessage), py::call_guard()) - .def("pair", &G2Element::Pair, py::call_guard()) - .def("negate", &G2Element::Negate, py::call_guard()) + auto data = CopyBuffer(b, "G2Element::SIZE"); + RelicGuard guard; + return G2Element::FromBytesUnchecked(data); + }) + .def("generator", &G2Element::Generator, py::call_guard()) + .def_static( + "from_message", + [](const py::bytes &msg, const py::bytes &dst) { + const auto msg_str = CopyMsg(msg, "G2Element.from_message"); + const auto dst_str = CopyDst(dst, "G2Element.from_message"); + RelicGuard guard; + return G2Element::FromMessage( + Bytes((const uint8_t *)msg_str.c_str(), msg_str.size()), + (const uint8_t *)dst_str.c_str(), + (int)dst_str.size()); + }, + py::arg("msg"), + py::arg("dst")) + .def("pair", &G2Element::Pair, py::call_guard()) + .def("negate", &G2Element::Negate, py::call_guard()) .def( "__deepcopy__", [](const G2Element &g2, const py::object &memo) { + RelicGuard guard; return G2Element(g2); }) - .def(py::self == py::self) - .def(py::self != py::self) + .def(py::self == py::self, py::call_guard()) + .def(py::self != py::self, py::call_guard()) .def( "__add__", [](G2Element &self, G2Element &other) { - py::gil_scoped_release release; + RelicGuard guard; return self + other; }, py::is_operator()) - .def( - "__mul__", - [](G2Element &self, bn_t other) { - py::gil_scoped_release release; - return self * (*(bn_t *)&other); - }, - py::is_operator()) - .def( - "__rmul__", - [](G2Element &self, bn_t other) { - py::gil_scoped_release release; - return self * (*(bn_t *)&other); - }, - py::is_operator()) - .def( "__repr__", [](const G2Element &ele) { - py::gil_scoped_release release; + RelicGuard guard; std::stringstream s; s << ele; return ""; @@ -614,7 +640,7 @@ PYBIND11_MODULE(blspy, m) .def( "__str__", [](const G2Element &ele) { - py::gil_scoped_release release; + RelicGuard guard; std::stringstream s; s << ele; return s.str(); @@ -624,7 +650,7 @@ PYBIND11_MODULE(blspy, m) [](const G2Element &ele) { vector out; { - py::gil_scoped_release release; + RelicGuard guard; out = ele.Serialize(); } py::bytes ans = py::bytes( @@ -632,27 +658,17 @@ PYBIND11_MODULE(blspy, m) return ans; }) .def("__deepcopy__", [](const G2Element &ele, const py::object &memo) { + RelicGuard guard; return G2Element(ele); }); py::class_(m, "GTElement") .def_property_readonly_static( "SIZE", [](py::object self) { return GTElement::SIZE; }) - .def(py::init(>Element::FromByteVector), py::call_guard()) + .def(py::init(>Element::FromByteVector), py::call_guard()) .def(py::init([](py::buffer const b) { - py::buffer_info info = b.request(); - if (info.format != py::format_descriptor::format() || - info.ndim != 1) - throw std::runtime_error("Incompatible buffer format!"); - - if ((int)info.size != GTElement::SIZE) { - throw std::invalid_argument( - "Length of bytes object not equal to GTElement::SIZE"); - } - auto data_ptr = static_cast(info.ptr); - std::array data; - std::copy(data_ptr, data_ptr + data.size(), data.data()); - py::gil_scoped_release release; + auto data = CopyBuffer(b, "GTElement::SIZE"); + RelicGuard guard; return GTElement::FromBytes(data); })) .def(py::init([](py::int_ pyint) { @@ -665,57 +681,36 @@ PYBIND11_MODULE(blspy, m) 0) < 0) { throw std::invalid_argument("Failed to cast int to GTElement"); } - py::gil_scoped_release release; + RelicGuard guard; return GTElement::FromBytes(buffer); })) .def( "from_bytes", [](py::buffer const b) { - py::buffer_info info = b.request(); - if (info.format != py::format_descriptor::format() || - info.ndim != 1) - throw std::runtime_error("Incompatible buffer format!"); - - if ((int)info.size != GTElement::SIZE) { - throw std::invalid_argument( - "Length of bytes object not equal to GTElement::SIZE"); - } - auto data_ptr = reinterpret_cast(info.ptr); - std::array data; - std::copy(data_ptr, data_ptr + data.size(), data.data()); - py::gil_scoped_release release; + auto data = CopyBuffer(b, "GTElement::SIZE"); + RelicGuard guard; return GTElement::FromBytes(data); }) .def( "from_bytes_unchecked", [](py::buffer const b) { - py::buffer_info info = b.request(); - if (info.format != py::format_descriptor::format() || - info.ndim != 1) - throw std::runtime_error("Incompatible buffer format!"); - - if ((int)info.size != GTElement::SIZE) { - throw std::invalid_argument( - "Length of bytes object not equal to GTElement::SIZE"); - } - auto data_ptr = reinterpret_cast(info.ptr); - std::array data; - std::copy(data_ptr, data_ptr + data.size(), data.data()); - py::gil_scoped_release release; + auto data = CopyBuffer(b, "GTElement::SIZE"); + RelicGuard guard; return GTElement::FromBytesUnchecked(data); }) - .def("unity", >Element::Unity) - .def(py::self == py::self) - .def(py::self != py::self) + .def("unity", >Element::Unity, py::call_guard()) + .def(py::self == py::self, py::call_guard()) + .def(py::self != py::self, py::call_guard()) .def( "__deepcopy__", [](const GTElement >, const py::object &memo) { + RelicGuard guard; return GTElement(gt); }) .def( "__repr__", [](const GTElement &ele) { - py::gil_scoped_release release; + RelicGuard guard; std::stringstream s; s << ele; return ""; @@ -723,7 +718,7 @@ PYBIND11_MODULE(blspy, m) .def( "__str__", [](const GTElement &ele) { - py::gil_scoped_release release; + RelicGuard guard; std::stringstream s; s << ele; return s.str(); @@ -733,7 +728,7 @@ PYBIND11_MODULE(blspy, m) [](const GTElement &ele) { uint8_t *out = new uint8_t[GTElement::SIZE]; { - py::gil_scoped_release release; + RelicGuard guard; ele.Serialize(out); } py::bytes ans = @@ -744,11 +739,12 @@ PYBIND11_MODULE(blspy, m) .def( "__mul__", [](GTElement &self, GTElement &other) { - py::gil_scoped_release release; + RelicGuard guard; return self * other; }, py::is_operator()) .def("__deepcopy__", [](const GTElement &ele, const py::object &memo) { + RelicGuard guard; return GTElement(ele); }); diff --git a/src/dashbls/binds/python/samples/aggregate_signatures.py b/src/dashbls/binds/python/samples/aggregate_signatures.py new file mode 100755 index 000000000000..014d1fac08c4 --- /dev/null +++ b/src/dashbls/binds/python/samples/aggregate_signatures.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +# coding: latin-1 + +# +# Copyright (c) 2020-present, Chia Network Inc. +# Copyright (c) 2026-present, The Dash Core developers +# SPDX-License-Identifier: Apache-2.0 +# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 +# + +"""Aggregate signatures from multiple keys over multiple messages.""" + +from dashbls import AugSchemeMPL, G1Element, G2Element, PrivateKey + +SEED: bytes = bytes.fromhex("003206f418c701193458c013120c5906dc12663ad1520c3e596eb6092c14fe16") + + +def aggregate_signatures() -> None: + # Two independent signers, each with their own message + sk1: PrivateKey = AugSchemeMPL.key_gen(bytes([1]) + SEED[1:]) + sk2: PrivateKey = AugSchemeMPL.key_gen(bytes([2]) + SEED[1:]) + + message1: bytes = bytes([1, 2, 3, 4, 5]) + message2: bytes = bytes([1, 2, 3, 4, 5, 6, 7]) + + pk1: G1Element = sk1.get_g1() + sig1: G2Element = AugSchemeMPL.sign(sk1, message1) + + pk2: G1Element = sk2.get_g1() + sig2: G2Element = AugSchemeMPL.sign(sk2, message2) + + # Signatures can be non-interactively combined by anyone + agg_sig: G2Element = AugSchemeMPL.aggregate([sig1, sig2]) + + # Verifying an aggregate over distinct messages needs every public key and + # every message, in the order they were signed in + ok = AugSchemeMPL.aggregate_verify([pk1, pk2], [message1, message2], agg_sig) + assert ok + + print(f"aggregate signature: {bytes(agg_sig).hex()}") + + +if __name__ == "__main__": + aggregate_signatures() diff --git a/src/dashbls/binds/python/samples/creating_keys_and_signatures.py b/src/dashbls/binds/python/samples/creating_keys_and_signatures.py new file mode 100755 index 000000000000..8fac6c0a2c4f --- /dev/null +++ b/src/dashbls/binds/python/samples/creating_keys_and_signatures.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +# coding: latin-1 + +# +# Copyright (c) 2020-present, Chia Network Inc. +# Copyright (c) 2026-present, The Dash Core developers +# SPDX-License-Identifier: Apache-2.0 +# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 +# + +"""Generate a keypair and produce/verify a signature.""" + +from dashbls import AugSchemeMPL, G1Element, G2Element, PrivateKey + +SEED: bytes = bytes.fromhex("003206f418c701193458c013120c5906dc12663ad1520c3e596eb6092c14fe16") + + +def creating_keys_and_signatures() -> None: + # Example seed. Always use a secure RNG with sufficient entropy to generate + # a seed (at least 32 bytes). + sk: PrivateKey = AugSchemeMPL.key_gen(SEED) + pk: G1Element = sk.get_g1() + + message: bytes = bytes([1, 2, 3, 4, 5]) + signature: G2Element = AugSchemeMPL.sign(sk, message) + + # Verify the signature + ok: bool = AugSchemeMPL.verify(pk, message, signature) + assert ok + + print(f"public key: {bytes(pk).hex()}") + print(f"signature: {bytes(signature).hex()}") + + +if __name__ == "__main__": + creating_keys_and_signatures() diff --git a/src/dashbls/binds/python/samples/hd_keys.py b/src/dashbls/binds/python/samples/hd_keys.py new file mode 100755 index 000000000000..2e34c00da957 --- /dev/null +++ b/src/dashbls/binds/python/samples/hd_keys.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +# coding: latin-1 + +# +# Copyright (c) 2020-present, Chia Network Inc. +# Copyright (c) 2026-present, The Dash Core developers +# SPDX-License-Identifier: Apache-2.0 +# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 +# + +"""Derive hardened and unhardened HD keys, per EIP-2333.""" + +from dashbls import AugSchemeMPL, G1Element, PrivateKey + +SEED: bytes = bytes.fromhex("003206f418c701193458c013120c5906dc12663ad1520c3e596eb6092c14fe16") + + +def hd_keys() -> None: + master_sk: PrivateKey = AugSchemeMPL.key_gen(SEED) + master_pk: G1Element = master_sk.get_g1() + + # Hardened derivation needs the private key, and the resulting child cannot + # be derived from the public key alone + child: PrivateKey = AugSchemeMPL.derive_child_sk(master_sk, 152) + grandchild: PrivateKey = AugSchemeMPL.derive_child_sk(child, 952) + + # Unhardened derivation can be mirrored on the public side, so a watch-only + # holder of the master public key can compute the same child public keys + child_u: PrivateKey = AugSchemeMPL.derive_child_sk_unhardened(master_sk, 22) + grandchild_u: PrivateKey = AugSchemeMPL.derive_child_sk_unhardened(child_u, 0) + + child_u_pk: G1Element = AugSchemeMPL.derive_child_pk_unhardened(master_pk, 22) + grandchild_u_pk: G1Element = AugSchemeMPL.derive_child_pk_unhardened(child_u_pk, 0) + + assert grandchild_u_pk == grandchild_u.get_g1() + + print(f"hardened grandchild: {bytes(grandchild.get_g1()).hex()}") + print(f"unhardened grandchild: {bytes(grandchild_u_pk).hex()}") + + +if __name__ == "__main__": + hd_keys() diff --git a/src/dashbls/binds/python/samples/loading_from_bytes.py b/src/dashbls/binds/python/samples/loading_from_bytes.py new file mode 100755 index 000000000000..401e1305e146 --- /dev/null +++ b/src/dashbls/binds/python/samples/loading_from_bytes.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +# coding: latin-1 + +# +# Copyright (c) 2020-present, Chia Network Inc. +# Copyright (c) 2026-present, The Dash Core developers +# SPDX-License-Identifier: Apache-2.0 +# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 +# + +"""Deserialize keys and signatures from bytes.""" + +from dashbls import AugSchemeMPL, G1Element, G2Element, PrivateKey + +SEED: bytes = bytes.fromhex("003206f418c701193458c013120c5906dc12663ad1520c3e596eb6092c14fe16") + + +def loading_from_bytes() -> None: + # Stand in for bytes that arrived over the wire or came off disk + original_sk: PrivateKey = AugSchemeMPL.key_gen(SEED) + message: bytes = bytes([1, 2, 3, 4, 5]) + sk_bytes: bytes = bytes(original_sk) + pk_bytes: bytes = bytes(original_sk.get_g1()) + signature_bytes: bytes = bytes(AugSchemeMPL.sign(original_sk, message)) + + # from_bytes validates: it rejects points that are malformed or outside the + # correct subgroup, and raises ValueError rather than returning junk + sk: PrivateKey = PrivateKey.from_bytes(sk_bytes) + pk: G1Element = G1Element.from_bytes(pk_bytes) + signature: G2Element = G2Element.from_bytes(signature_bytes) + + assert sk == original_sk + assert pk == sk.get_g1() + assert AugSchemeMPL.verify(pk, message, signature) + + print(f"public key: {bytes(pk).hex()}") + print(f"signature: {bytes(signature).hex()}") + + +if __name__ == "__main__": + loading_from_bytes() diff --git a/src/dashbls/binds/python/samples/proof_of_possession.py b/src/dashbls/binds/python/samples/proof_of_possession.py new file mode 100755 index 000000000000..e327dcfc959f --- /dev/null +++ b/src/dashbls/binds/python/samples/proof_of_possession.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +# coding: latin-1 + +# +# Copyright (c) 2020-present, Chia Network Inc. +# Copyright (c) 2026-present, The Dash Core developers +# SPDX-License-Identifier: Apache-2.0 +# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 +# + +"""Verify aggregated signatures quickly using the Proof of Possession scheme.""" + +from dashbls import G1Element, PopSchemeMPL, PrivateKey + +SEED: bytes = bytes.fromhex("003206f418c701193458c013120c5906dc12663ad1520c3e596eb6092c14fe16") + + +def proof_of_possession() -> None: + sk1: PrivateKey = PopSchemeMPL.key_gen(bytes([1]) + SEED[1:]) + sk2: PrivateKey = PopSchemeMPL.key_gen(bytes([2]) + SEED[1:]) + sk3: PrivateKey = PopSchemeMPL.key_gen(bytes([3]) + SEED[1:]) + + pk1: G1Element = sk1.get_g1() + pk2: G1Element = sk2.get_g1() + pk3: G1Element = sk3.get_g1() + + message: bytes = bytes([1, 2, 3, 4, 5]) + + # If the same message is signed, you can use Proof of Possession (PopScheme) for efficiency. + # A proof of possession MUST be passed around with the PK to ensure security. + pop_sig1 = PopSchemeMPL.sign(sk1, message) + pop_sig2 = PopSchemeMPL.sign(sk2, message) + pop_sig3 = PopSchemeMPL.sign(sk3, message) + pop1 = PopSchemeMPL.pop_prove(sk1) + pop2 = PopSchemeMPL.pop_prove(sk2) + pop3 = PopSchemeMPL.pop_prove(sk3) + + assert PopSchemeMPL.pop_verify(pk1, pop1) + assert PopSchemeMPL.pop_verify(pk2, pop2) + assert PopSchemeMPL.pop_verify(pk3, pop3) + + pop_sig_agg = PopSchemeMPL.aggregate([pop_sig1, pop_sig2, pop_sig3]) + + assert PopSchemeMPL.fast_aggregate_verify([pk1, pk2, pk3], message, pop_sig_agg) + + # Aggregate public key, indistinguishable from a single public key + pop_agg_pk: G1Element = pk1 + pk2 + pk3 + assert PopSchemeMPL.verify(pop_agg_pk, message, pop_sig_agg) + + # Aggregate private keys + pop_agg_sk: PrivateKey = PrivateKey.aggregate([sk1, sk2, sk3]) + assert PopSchemeMPL.sign(pop_agg_sk, message) == pop_sig_agg + + print(f"aggregate public key: {bytes(pop_agg_pk).hex()}") + + +if __name__ == "__main__": + proof_of_possession() diff --git a/src/dashbls/binds/python/samples/serializing_to_bytes.py b/src/dashbls/binds/python/samples/serializing_to_bytes.py new file mode 100755 index 000000000000..5cb887d58ae1 --- /dev/null +++ b/src/dashbls/binds/python/samples/serializing_to_bytes.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +# coding: latin-1 + +# +# Copyright (c) 2020-present, Chia Network Inc. +# Copyright (c) 2026-present, The Dash Core developers +# SPDX-License-Identifier: Apache-2.0 +# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 +# + +"""Serialize keys and signatures to bytes.""" + +from dashbls import AugSchemeMPL, G1Element, G2Element, PrivateKey + +SEED: bytes = bytes.fromhex("003206f418c701193458c013120c5906dc12663ad1520c3e596eb6092c14fe16") + + +def serializing_to_bytes() -> None: + sk: PrivateKey = AugSchemeMPL.key_gen(SEED) + pk: G1Element = sk.get_g1() + signature: G2Element = AugSchemeMPL.sign(sk, bytes([1, 2, 3, 4, 5])) + + sk_bytes: bytes = bytes(sk) # 32 bytes + pk_bytes: bytes = bytes(pk) # 48 bytes + signature_bytes: bytes = bytes(signature) # 96 bytes + + assert (len(sk_bytes), len(pk_bytes), len(signature_bytes)) == (32, 48, 96) + + # Serialized private keys are secret material; treat them the way you would + # treat the seed they came from, and never log them. + print(f"public key: {pk_bytes.hex()}") + print(f"signature: {signature_bytes.hex()}") + + +if __name__ == "__main__": + serializing_to_bytes() diff --git a/src/dashbls/binds/python/samples/tree_aggregates.py b/src/dashbls/binds/python/samples/tree_aggregates.py new file mode 100755 index 000000000000..6260782d52e4 --- /dev/null +++ b/src/dashbls/binds/python/samples/tree_aggregates.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +# coding: latin-1 + +# +# Copyright (c) 2020-present, Chia Network Inc. +# Copyright (c) 2026-present, The Dash Core developers +# SPDX-License-Identifier: Apache-2.0 +# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 +# + +"""Build an aggregate signature out of an aggregate signature and another signature.""" + +from dashbls import AugSchemeMPL, G1Element, G2Element, PrivateKey + +SEED: bytes = bytes.fromhex("003206f418c701193458c013120c5906dc12663ad1520c3e596eb6092c14fe16") + + +def tree_aggregates() -> None: + sk1: PrivateKey = AugSchemeMPL.key_gen(bytes([1]) + SEED[1:]) + sk2: PrivateKey = AugSchemeMPL.key_gen(bytes([2]) + SEED[1:]) + sk3: PrivateKey = AugSchemeMPL.key_gen(bytes([3]) + SEED[1:]) + + message1: bytes = bytes([1, 2, 3, 4, 5]) + message2: bytes = bytes([1, 2, 3, 4, 5, 6, 7]) + message3: bytes = bytes([100, 2, 254, 88, 90, 45, 23]) + + pk1: G1Element = sk1.get_g1() + pk2: G1Element = sk2.get_g1() + pk3: G1Element = sk3.get_g1() + + # Aggregate the first two signatures on their own... + agg_sig: G2Element = AugSchemeMPL.aggregate( + [AugSchemeMPL.sign(sk1, message1), AugSchemeMPL.sign(sk2, message2)] + ) + + # ...then fold a third signature into that aggregate. Aggregation composes, + # so an aggregate is indistinguishable from a plain signature to the next + # round, and the tree can be built in any shape. + sig3: G2Element = AugSchemeMPL.sign(sk3, message3) + agg_sig_final: G2Element = AugSchemeMPL.aggregate([agg_sig, sig3]) + + ok = AugSchemeMPL.aggregate_verify( + [pk1, pk2, pk3], [message1, message2, message3], agg_sig_final + ) + assert ok + + print(f"tree aggregate: {bytes(agg_sig_final).hex()}") + + +if __name__ == "__main__": + tree_aggregates() diff --git a/src/dashbls/binds/python/test_bench.py b/src/dashbls/binds/python/test_bench.py new file mode 100755 index 000000000000..689d33ab0699 --- /dev/null +++ b/src/dashbls/binds/python/test_bench.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 +# coding: latin-1 + +# +# Copyright (c) 2020-present, Chia Network Inc. +# Copyright (c) 2026-present, The Dash Core developers +# SPDX-License-Identifier: Apache-2.0 +# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 +# + +"""Benchmarks for the dashbls package.""" + +import secrets + +import pytest +from dashbls import ( + AugSchemeMPL, + G1Element, + G2Element, + PrivateKey, +) +from pytest_benchmark.fixture import BenchmarkFixture + +NUM_ITEMS = 1000 +SignedMessages = tuple[list[bytes], list[bytes], list[bytes]] + + +@pytest.fixture(scope="module") +def signed_messages() -> SignedMessages: + pk_bytes = [] + sig_bytes = [] + messages = [] + for i in range(NUM_ITEMS): + message = b"%d" % i + sk: PrivateKey = AugSchemeMPL.key_gen(secrets.token_bytes(32)) + pk: G1Element = sk.get_g1() + sig: G2Element = AugSchemeMPL.sign(sk, message) + + pk_bytes.append(bytes(pk)) + sig_bytes.append(bytes(sig)) + messages.append(message) + return pk_bytes, sig_bytes, messages + + +def test_public_key_validation( + benchmark: BenchmarkFixture, signed_messages: SignedMessages +) -> None: + pk_bytes, _, _ = signed_messages + pks = benchmark(lambda: [G1Element.from_bytes(pk) for pk in pk_bytes]) + assert len(pks) == NUM_ITEMS + + +def test_signature_validation(benchmark: BenchmarkFixture, signed_messages: SignedMessages) -> None: + _, sig_bytes, _ = signed_messages + sigs = benchmark(lambda: [G2Element.from_bytes(sig) for sig in sig_bytes]) + assert len(sigs) == NUM_ITEMS + + +def test_signature_aggregation( + benchmark: BenchmarkFixture, signed_messages: SignedMessages +) -> None: + _, sig_bytes, _ = signed_messages + sigs = [G2Element.from_bytes(sig) for sig in sig_bytes] + agg_sig = benchmark(lambda: AugSchemeMPL.aggregate(sigs)) + assert agg_sig is not None + + +def test_batch_verification(benchmark: BenchmarkFixture, signed_messages: SignedMessages) -> None: + pk_bytes, sig_bytes, messages = signed_messages + pks = [G1Element.from_bytes(pk) for pk in pk_bytes] + sigs = [G2Element.from_bytes(sig) for sig in sig_bytes] + agg_sig = AugSchemeMPL.aggregate(sigs) + + ok = benchmark(lambda: AugSchemeMPL.aggregate_verify(pks, messages, agg_sig)) + assert ok diff --git a/src/dashbls/binds/python/test_unit.py b/src/dashbls/binds/python/test_unit.py new file mode 100755 index 000000000000..2a28c56b3225 --- /dev/null +++ b/src/dashbls/binds/python/test_unit.py @@ -0,0 +1,440 @@ +#!/usr/bin/env python3 +# coding: latin-1 + +# +# Copyright (c) 2020-present, Chia Network Inc. +# Copyright (c) 2026-present, The Dash Core developers +# SPDX-License-Identifier: Apache-2.0 +# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 +# + +"""Unit tests for the dashbls package.""" + +import binascii +import importlib + +import pytest +from dashbls import ( + AugSchemeMPL, + BasicSchemeMPL, + G1Element, + G2Element, + GTElement, + PopSchemeMPL, + PrivateKey, + Util, +) + +# fmt: off +SEED = bytes([ + 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 +]) +# fmt: on +MSG = bytes([100, 2, 254, 88, 90, 45, 23]) +MSG2 = bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + +SCHEMES = (BasicSchemeMPL, AugSchemeMPL, PopSchemeMPL) +SCHEME_IDS = [scheme.__name__ for scheme in SCHEMES] + +G1_DST = b"BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_" +G2_DST = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_" + +# Keeps md_hmac's alloca of the seed off the stack, see CopySeed in the binds +SEED_LIMIT = 64 * 1024 + + +def _derive_two_keypairs() -> tuple[PrivateKey, G1Element, PrivateKey, G1Element]: + seed1 = bytes([1]) + SEED[1:] + sk1 = BasicSchemeMPL.key_gen(seed1) + seed2 = bytes([2]) + seed1[1:] + sk2 = BasicSchemeMPL.key_gen(seed2) + return sk1, sk1.get_g1(), sk2, sk2.get_g1() + + +@pytest.fixture +def keypairs() -> tuple[PrivateKey, G1Element, PrivateKey, G1Element]: + return _derive_two_keypairs() + + +def test_private_key_and_public_key_roundtrip() -> None: + sk = BasicSchemeMPL.key_gen(SEED) + pk = sk.get_g1() + assert sk == PrivateKey.from_bytes(bytes(sk)) + assert pk == G1Element.from_bytes(bytes(pk)) + + +def test_scalar_multiplication_by_private_key() -> None: + """The operators took `bn_t`, which pybind11 has no caster for, so every call + raised TypeError regardless of argument.""" + sk = BasicSchemeMPL.key_gen(SEED) + g1 = G1Element.generator() + assert g1 * sk == sk.get_g1() + assert sk * g1 == sk.get_g1() + + g2 = G2Element.generator() + assert g2 * sk == sk * g2 + assert g2 * sk != G2Element() + + +def test_scalar_multiplication_is_additive( + keypairs: tuple[PrivateKey, G1Element, PrivateKey, G1Element], +) -> None: + sk1, _pk1, sk2, _pk2 = keypairs + g1 = G1Element.generator() + assert (g1 * sk1) + (g1 * sk2) == g1 * PrivateKey.aggregate([sk1, sk2]) + + +@pytest.mark.parametrize("scheme", SCHEMES, ids=SCHEME_IDS) +def test_sign_and_verify_roundtrip(scheme: type) -> None: + sk = BasicSchemeMPL.key_gen(SEED) + pk = sk.get_g1() + sig = scheme.sign(sk, MSG) + assert sig == G2Element.from_bytes(bytes(sig)) + assert scheme.verify(pk, MSG, sig) + + +@pytest.mark.parametrize("scheme", SCHEMES, ids=SCHEME_IDS) +def test_aggregate_verify_same_message( + scheme: type, keypairs: tuple[PrivateKey, G1Element, PrivateKey, G1Element] +) -> None: + sk1, pk1, sk2, pk2 = keypairs + agg_pk = pk1 + pk2 + if scheme is AugSchemeMPL: + sig1 = scheme.sign(sk1, MSG, agg_pk) + sig2 = scheme.sign(sk2, MSG, agg_pk) + else: + sig1 = scheme.sign(sk1, MSG) + sig2 = scheme.sign(sk2, MSG) + agg_sig = scheme.aggregate([sig1, sig2]) + assert scheme.verify(agg_pk, MSG, agg_sig) + + +@pytest.mark.parametrize("scheme", SCHEMES, ids=SCHEME_IDS) +def test_aggregate_verify_different_messages( + scheme: type, keypairs: tuple[PrivateKey, G1Element, PrivateKey, G1Element] +) -> None: + sk1, pk1, sk2, pk2 = keypairs + sig1 = scheme.sign(sk1, MSG) + sig2 = scheme.sign(sk2, MSG2) + agg_sig = scheme.aggregate([sig1, sig2]) + assert scheme.aggregate_verify([pk1, pk2], [MSG, MSG2], agg_sig) + + +@pytest.mark.parametrize("scheme", SCHEMES, ids=SCHEME_IDS) +def test_manual_pairing_matches_aggregate_signature( + scheme: type, keypairs: tuple[PrivateKey, G1Element, PrivateKey, G1Element] +) -> None: + sk1, pk1, sk2, pk2 = keypairs + sig1 = scheme.sign(sk1, MSG) + sig2 = scheme.sign(sk2, MSG2) + agg_sig = scheme.aggregate([sig1, sig2]) + + if scheme is AugSchemeMPL: + # AugSchemeMPL requires prepending the public key to the message + aug_msg1 = bytes(pk1) + MSG + aug_msg2 = bytes(pk2) + MSG2 + else: + aug_msg1 = MSG + aug_msg2 = MSG2 + pair1 = pk1.pair(scheme.g2_from_message(aug_msg1)) + pair2 = pk2.pair(scheme.g2_from_message(aug_msg2)) + pair = pair1 * pair2 + agg_sig_pair = G1Element.generator().pair(agg_sig) + assert pair == agg_sig_pair + + +@pytest.mark.parametrize("scheme", SCHEMES, ids=SCHEME_IDS) +def test_hd_key_derivation_sign_and_verify( + scheme: type, keypairs: tuple[PrivateKey, G1Element, PrivateKey, G1Element] +) -> None: + sk1, pk1, _sk2, _pk2 = keypairs + child = scheme.derive_child_sk(sk1, 123) + child_u = scheme.derive_child_sk_unhardened(sk1, 123) + child_u_pk = scheme.derive_child_pk_unhardened(pk1, 123) + + sig_child = scheme.sign(child, MSG) + assert scheme.verify(child.get_g1(), MSG, sig_child) + + sig_u_child = scheme.sign(child_u, MSG) + assert scheme.verify(child_u_pk, MSG, sig_u_child) + + +# Invalid inputs from https://github.com/algorand/bls_sigs_ref/blob/master/python-impl/serdesZ.py +INVALID_G1_VECTORS = [ + # infinity points: too short + "c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + # infinity points: not all zeros + "c00000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000", + # bad tags + "3a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa", + "7a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa", + "fa0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa", + # wrong length for compresed point + "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa", + "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaaaa", + # invalid x-coord + "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa", + # invalid elm of Fp --- equal to p (must be strictly less) + "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab", +] +INVALID_G2_VECTORS = [ + # infinity points: too short + "c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + # infinity points: not all zeros + "c00000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000", + # bad tags + "3a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "7a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "fa0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + # wrong length for compressed point + "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + # invalid x-coord + "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaa7", + # invalid elm of Fp --- equal to p (must be strictly less) + "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab", +] + + +@pytest.mark.parametrize("hex_str", INVALID_G1_VECTORS) +def test_invalid_g1_vector_rejected(hex_str: str) -> None: + with pytest.raises(ValueError): + G1Element(binascii.unhexlify(hex_str)) + + +@pytest.mark.parametrize("hex_str", INVALID_G2_VECTORS) +def test_invalid_g2_vector_rejected(hex_str: str) -> None: + with pytest.raises(ValueError): + G2Element(binascii.unhexlify(hex_str)) + + +# The following code was used to generate the reference vectors below +""" +from py_ecc.bls import ( + G2Basic, + G2MessageAugmentation as G2MA, + G2ProofOfPossession as G2Pop, +) + +secret1 = bytes([1] * 32) +secret2 = bytes([x * 314159 % 256 for x in range(32)]) +sk1 = int.from_bytes(secret1, 'big') +sk2 = int.from_bytes(secret2, 'big') +msg = bytes([3, 1, 4, 1, 5, 9]) +pk1 = G2Basic.SkToPk(sk1) +pk2 = G2Basic.SkToPk(sk2) + +for Scheme in (G2Basic, G2MA, G2Pop): + sig1 = Scheme.Sign(sk1, msg) + sig2 = Scheme.Sign(sk2, msg) + sig_agg = Scheme.Aggregate([sig1, sig2]) + print(sig1) + print(sig2) + print(sig_agg) +""" + +REFERENCE_VECTORS = { + BasicSchemeMPL: ( + b"\x96\xba4\xfa\xc3<\x7f\x12\x9d`*\x0b\xc8\xa3\xd4?\x9a\xbc\x01N\xce\xaa\xb75\x91F\xb4\xb1P\xe5{\x80\x86Es\x8f5g\x1e\x9e\x10\xe0\xd8b\xa3\x0c\xabp\x07N\xb5\x83\x1d\x13\xe6\xa5\xb1b\xd0\x1e\xeb\xe6\x87\xd0\x16J\xdb\xd0\xa8d7\n|\"*'h\xd7pM\xa2T\xf1\xbf\x18#f[\xc26\x1f\x9d\xd8\xc0\x0e\x99", + b'\xa4\x02y\t2\x13\x0fvj\xf1\x1b\xa7\x16Sf\x83\xd8\xc4\xcf\xa5\x19G\xe4\xf9\x08\x1f\xed\xd6\x92\xd6\xdc\x0c\xac[\x90K\xee^\xa6\xe2Ui\xe3m{\xe4\xcaY\x06\x9a\x96\xe3K\x7fp\x07X\xb7\x16\xf9IJ\xaaY\xa9nt\xd1J;U*\x9ak\xc1)\xe7\x17\x19[\x9d`\x06\xfdm\\\xefGh\xc0"\xe0\xf71j\xbf', + b"\x98|\xfd;\xcdb(\x02\x87\x02t\x83\xf2\x9cU$^\xd81\xf5\x1d\xd6\xbd\x99\x9ao\xf1\xa1\xf1\xf1\xf0\xb6Gw\x8b\x01g5\x9cqPUX\xa7n\x15\x8ef\x18\x1e\xe5\x12Y\x05\xa6B$k\x01\xe7\xfa^\xe5=h\xa4\xfe\x9b\xfb)\xa8\xe2f\x01\xf0\xb9\xadW}\xdd\x18\x87js1|!n\xa6\x1fC\x04\x14\xecQ\xc5", + ), + AugSchemeMPL: ( + b'\x81\x80\xf0,\xcbr\xe9"\xb1R\xfc\xed\xbe\x0e\x1d\x19R\x105Opp6X\xe8\xe0\x8c\xbe\xbf\x11\xd4\x97\x0e\xabj\xc3\xcc\xf7\x15\xf3\xfb\x87m\xf9\xa9yz\xbd\x0c\x1a\xf6\x1a\xae\xad\xc9,,\xfe\\\nV\xc1F\xcc\x8c?qQ\xa0s\xcf_\x16\xdf8$g$\xc4\xae\xd7?\xf3\x0e\xf5\xda\xa6\xaa\xca\xed\x1a&\xec\xaa3k', + b'\x99\x11\x1e\xea\xfbA-\xa6\x1eL7\xd3\xe8\x06\xc6\xfdj\xc9\xf3\x87\x0eT\xda\x92"\xbaNIH"\xc5\xb7eg1\xfazdY4\xd0KU\x9e\x92a\xb8b\x01\xbb\xeeW\x05RP\xa4Y\xa2\xda\x10\xe5\x1f\x9c\x1aiA)\x7f\xfc]\x97\nUr6\xd0\xbd\xeb|\xf8\xff\x18\x80\x0b\x08c8q\xa0\xf0\xa7\xeaB\xf4t\x80', + b"\x8c]\x03\xf9\xda\xe7~\x19\xa5\x94Z\x06\xa2\x14\x83n\xdb\x8e\x03\xb8QR]\x84\xb9\xded@\xe6\x8f\xc0\xcas\x03\xee\xed9\r\x86<\x9bU\xa8\xcfmY\x14\n\x01\xb5\x88G\x88\x1e\xb5\xafgsMD\xb2UVF\xc6al9\xab\x88\xd2S)\x9a\xcc\x1e\xb1\xb1\x9d\xdb\x9b\xfc\xbev\xe2\x8a\xdd\xf6q\xd1\x16\xc0R\xbb\x18G", + ), + PopSchemeMPL: ( + b"\x95P\xfbN\x7f~\x8c\xc4\xa9\x0b\xe8V\n\xb5\xa7\x98\xb0\xb20\x00\xb6\xa5J!\x17R\x02\x10\xf9\x86\xf3\xf2\x81\xb3v\xf2Y\xc0\xb7\x80b\xd1\xeb1\x92\xb3\xd9\xbb\x04\x9fY\xec\xc1\xb0:pI\xebf^\r\xf3d\x94\xaeL\xb5\xf1\x13l\xca\xee\xfc\x99X\xcb0\xc33==C\xf0qH\xc3\x86)\x9a{\x1b\xfc\r\xc5\xcf|", + b"\xa6\x906\xbc\x11\xae^\xfc\xbfa\x80\xaf\xe3\x9a\xdd\xde~'s\x1e\xc4\x02W\xbf\xdc<7\xf1{\x8d\xf6\x83\x06\xa3N\xbd\x10\xe9\xe3*5%7P\xdf\\\x87\xc2\x14/\x82\x07\xe8\xd5eG\x12\xb4\xe5T\xf5\x85\xfbhF\xff8\x04\xe4)\xa9\xf8\xa1\xb4\xc5ku\xd0\x86\x9e\xd6u\x80\xd7\x89\x87\x0b\xab\xe2\xc7\xc8\xa9\xd5\x1e{*", + b"\xa4\xeat+\xcd\xc1U>\x9c\xa4\xe5`\xbe~^ln\xfajd\xdd\xdf\x9c\xa3\xbb(T#=\x85\xa6\xaa\xc1\xb7n\xc7\xd1\x03\xdbN3\x14\x8b\x82\xaf\x99#\xdb\x05\x93Jn\xce\x9aq\x01\xcd\x8a\x9dG\xce'\x97\x80V\xb0\xf5\x90\x00!\x81\x8cEi\x8a\xfd\xd6\xcf\x8ako\x7f\xee\x1f\x0bCqoU\xe4\x13\xd4\xb8z`9", + ), +} + + +@pytest.mark.parametrize("scheme", SCHEMES, ids=SCHEME_IDS) +def test_sign_matches_reference_vectors(scheme: type) -> None: + secret1 = bytes([1] * 32) + secret2 = bytes([x * 314159 % 256 for x in range(32)]) + sk1 = PrivateKey.from_bytes(secret1) + sk2 = PrivateKey.from_bytes(secret2) + msg = bytes([3, 1, 4, 1, 5, 9]) + + sig1 = scheme.sign(sk1, msg) + sig2 = scheme.sign(sk2, msg) + sig_agg = scheme.aggregate([sig1, sig2]) + + ref_sig1, ref_sig2, ref_sig_agg = REFERENCE_VECTORS[scheme] + assert bytes(sig1) == ref_sig1 + assert bytes(sig2) == ref_sig2 + assert bytes(sig_agg) == ref_sig_agg + + +SAMPLES = [ + "aggregate_signatures", + "creating_keys_and_signatures", + "hd_keys", + "loading_from_bytes", + "proof_of_possession", + "serializing_to_bytes", + "tree_aggregates", +] + + +@pytest.mark.parametrize("sample", SAMPLES) +def test_samples(sample: str) -> None: + module = importlib.import_module(sample) + getattr(module, sample)() + + +def test_aggregate_verify_zero_items() -> None: + assert AugSchemeMPL.aggregate_verify([], [], G2Element()) + + +def test_from_message() -> None: + msg = bytes([10]) * 32 + assert G2Element.from_message(msg, G2_DST) == BasicSchemeMPL.g2_from_message(msg) + assert G1Element.from_message(msg, G1_DST) != G1Element() + + +def test_from_message_is_domain_separated() -> None: + """The tag keeps one scheme's hashes off another's, so a different tag over + the same message must land elsewhere.""" + msg = bytes([10]) * 32 + assert G2Element.from_message(msg, G2_DST) != G2Element.from_message(msg, G1_DST) + assert G1Element.from_message(msg, G1_DST) != G1Element.from_message(msg, G2_DST) + + +@pytest.mark.parametrize("element", [G1Element, G2Element]) +@pytest.mark.parametrize("size", [256, 1000]) +def test_from_message_rejects_oversized_dst(element: type, size: int) -> None: + """md_xmd caps the tag at 255 bytes but compares signed, so the length is + checked here rather than reaching relic.""" + with pytest.raises(ValueError): + element.from_message(bytes([10]) * 32, b"x" * size) + + +def test_from_message_accepts_maximum_dst() -> None: + assert G2Element.from_message(bytes([10]) * 32, b"x" * 255) != G2Element() + + +class _LyingBytes(bytes): + """A bytes subclass whose __len__ disagrees with its payload.""" + + def __init__(self, payload: bytes, claimed_len: int) -> None: + del payload + self._claimed_len = claimed_len + + def __new__(cls, payload: bytes, claimed_len: int) -> "_LyingBytes": + del claimed_len + return super().__new__(cls, payload) + + def __len__(self) -> int: + return self._claimed_len + + +@pytest.mark.parametrize("element", [G1Element, G2Element], ids=["G1Element", "G2Element"]) +def test_from_message_measures_the_dst_payload_not_its_len(element: type) -> None: + """The length check has to read the same bytes the copy takes, or a subclass + that understates __len__ walks an oversized tag straight into relic.""" + dst = _LyingBytes(b"x" * 256, 1) + assert len(dst) == 1 + with pytest.raises(ValueError): + element.from_message(bytes([10]) * 32, dst) + + # and the mirror case: a small tag must not be rejected for lying upwards + honest = G1_DST if element is G1Element else G2_DST + assert element.from_message(bytes([10]) * 32, _LyingBytes(honest, 300)) == element.from_message( + bytes([10]) * 32, honest + ) + + +def test_length_checked_paths_use_the_payload_of_a_bytes_subclass() -> None: + """Every entry point that measures a length before copying must agree with + the payload it ends up hashing, whatever __len__ claims.""" + assert Util.hash256(_LyingBytes(b"abc", 1 << 40)) == Util.hash256(b"abc") + + seed = bytes([9]) * 32 + for scheme in (BasicSchemeMPL, AugSchemeMPL, PopSchemeMPL): + sk = scheme.key_gen(_LyingBytes(seed, 1)) + assert sk == scheme.key_gen(seed) + msg = bytes([1, 2, 3]) + assert scheme.sign(sk, _LyingBytes(msg, 1 << 40)) == scheme.sign(sk, msg) + assert scheme.verify(sk.get_g1(), _LyingBytes(msg, 1), scheme.sign(sk, msg)) + + +@pytest.mark.parametrize("scheme", SCHEMES, ids=SCHEME_IDS) +def test_key_gen_rejects_oversized_seeds(scheme: type) -> None: + """relic is built ALLOC=AUTO, so md_hmac stages the seed with alloca and a + seed of a few MiB would take the process down instead of raising.""" + with pytest.raises(ValueError): + scheme.key_gen(b"x" * (SEED_LIMIT + 1)) + # the cap itself has to keep working + assert scheme.key_gen(b"x" * SEED_LIMIT) == scheme.key_gen(b"x" * SEED_LIMIT) + + +def test_from_bytes_and_from_bytes_unchecked_agree_on_valid_point() -> None: + sk1 = BasicSchemeMPL.key_gen(b"1" * 32) + good_point_bytes = bytes(sk1.get_g1()) + assert G1Element.from_bytes(good_point_bytes) == G1Element.from_bytes_unchecked( + good_point_bytes + ) + + +def test_from_bytes_rejects_invalid_g1_point() -> None: + bad_point_hex = "8d5d0fb73b9c92df4eab4216e48c3e358578b4cc30f82c268bd6fef3bd34b558628daf1afef798d4c3b0fcd8b28c8973" # noqa: E501 + with pytest.raises(ValueError): + G1Element.from_bytes(bytes.fromhex(bad_point_hex)) + # from_bytes_unchecked skips subgroup validation and must not raise + G1Element.from_bytes_unchecked(bytes.fromhex(bad_point_hex)) + + +def test_from_bytes_rejects_invalid_g2_point() -> None: + bad_g2_point_hex = "8f2886c94eaeac335c8414cbf14c16681b225380cfee3293becc4531d5b415984b4ea4050d9ecda11fbc21c60627e9d212dfcb17d2b5ae399aa3fbcb099e05baa496b852ad976fb633cc6766b02fca4da549dc063908463b2906ad64e8b310ad" # noqa: E501 + with pytest.raises(ValueError): + G2Element.from_bytes(bytes.fromhex(bad_g2_point_hex)) + + +@pytest.mark.parametrize( + ("cls", "size"), + [ + (PrivateKey, PrivateKey.PRIVATE_KEY_SIZE), + (G1Element, G1Element.SIZE), + (G2Element, G2Element.SIZE), + (GTElement, GTElement.SIZE), + ], + ids=["PrivateKey", "G1Element", "G2Element", "GTElement"], +) +def test_from_bytes_rejects_non_contiguous_buffers(cls: type, size: int) -> None: + # A reversed view points at the last backing byte with a stride of -1, so + # reading it as if it were contiguous runs off the end of the allocation + with pytest.raises(BufferError): + cls.from_bytes(memoryview(bytearray(size))[::-1]) + # A strided view stays in bounds but is not the bytes the caller passed + with pytest.raises(BufferError): + cls.from_bytes(memoryview(bytearray(size * 2))[::2]) + + +@pytest.mark.parametrize( + ("cls", "size"), + [ + (G1Element, G1Element.SIZE), + (G2Element, G2Element.SIZE), + (GTElement, GTElement.SIZE), + ], + ids=["G1Element", "G2Element", "GTElement"], +) +def test_from_bytes_unchecked_rejects_non_contiguous_buffers(cls: type, size: int) -> None: + with pytest.raises(BufferError): + cls.from_bytes_unchecked(memoryview(bytearray(size))[::-1]) + + +@pytest.mark.parametrize("element", [G1Element, G2Element], ids=["G1Element", "G2Element"]) +def test_from_message_accepts_a_large_message(element: type) -> None: + # ep_map_dst takes the message length as an int and relic checks nothing on + # its side, so the binds guard it. Anything under the limit has to keep + # working; the limit itself is not testable without ~2 GiB of memory. + assert element.from_message(b"x" * (1 << 20), G1_DST) != element() diff --git a/src/dashbls/cmake_modules/Findgmp.cmake b/src/dashbls/cmake_modules/Findgmp.cmake deleted file mode 100644 index 3e59ede0a4f3..000000000000 --- a/src/dashbls/cmake_modules/Findgmp.cmake +++ /dev/null @@ -1,103 +0,0 @@ -# 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. - -include(BrewHelper) -find_brew_prefix(_GMP_BREW_HINT gmp) - -find_path(GMP_INCLUDES - NAMES - gmp.h - PATHS - $ENV{GMPDIR} ${INCLUDE_INSTALL_DIR} - PATH_SUFFIXES - include - HINTS - ${_GMP_BREW_HINT} -) - -# 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() - -if(STBIN) - set(_gmp_lib_name libgmp.a) -else() - set(_gmp_lib_name libgmp.so) -endif() - -find_library(GMP_LIBRARIES - NAMES - ${_gmp_lib_name} gmp.lib libgmp-10 libgmp gmp - HINTS - ${_GMP_BREW_HINT} - INCLUDE_DIRS - ${GMP_INCLUDES} - 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/dashbls/depends/catch2/CMakeLists.txt b/src/dashbls/depends/catch2/CMakeLists.txt index 8c26a03af581..efbbe0f7d556 100644 --- a/src/dashbls/depends/catch2/CMakeLists.txt +++ b/src/dashbls/depends/catch2/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.14.0 FATAL_ERROR) +CMAKE_MINIMUM_REQUIRED(VERSION 3.18.0 FATAL_ERROR) set(PROJECT_NAME "catch2") diff --git a/src/dashbls/depends/relic/include/relic_conf.h.in b/src/dashbls/depends/relic/include/relic_conf.h.in new file mode 100644 index 000000000000..7db6f5b509c4 --- /dev/null +++ b/src/dashbls/depends/relic/include/relic_conf.h.in @@ -0,0 +1,717 @@ +/* + * RELIC is an Efficient LIbrary for Cryptography + * Copyright (c) 2009 RELIC Authors + * + * This file is part of RELIC. RELIC is legal property of its developers, + * whose names are not listed here. Please refer to the COPYRIGHT file + * for contact information. + * + * RELIC is free software; you can redistribute it and/or modify it under the + * terms of the version 2.1 (or later) of the GNU Lesser General Public License + * as published by the Free Software Foundation; or version 2.0 of the Apache + * License as published by the Apache Software Foundation. See the LICENSE files + * for more details. + * + * RELIC 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 LICENSE files for more details. + * + * You should have received a copy of the GNU Lesser General Public or the + * Apache License along with RELIC. If not, see + * or . + */ + +/** + * @file + * + * Project configuration. + * + * @version $Id: relic_conf.h.in 45 2009-07-04 23:45:48Z dfaranha $ + * @ingroup relic + */ + +#ifndef RLC_CONF_H +#define RLC_CONF_H + +/** Project version. */ +#define RLC_VERSION "@VERSION@" + +/** Debugging support. */ +#cmakedefine DEBUG +/** Profiling support. */ +#cmakedefine PROFL +/** Error handling support. */ +#cmakedefine CHECK +/** Verbose error messages. */ +#cmakedefine VERBS +/** Build with overhead estimation. */ +#cmakedefine OVERH +/** Build documentation. */ +#cmakedefine DOCUM +/** Build only the selected algorithms. */ +#cmakedefine STRIP +/** Build with printing disabled. */ +#cmakedefine QUIET +/** Build with colored output. */ +#cmakedefine COLOR +/** Build with big-endian support. */ +#cmakedefine BIGED +/** Build shared library. */ +#cmakedefine SHLIB +/** Build static library. */ +#cmakedefine STLIB + +/** Number of times each test is ran. */ +#define TESTS @TESTS@ +/** Number of times each benchmark is ran. */ +#define BENCH @BENCH@ +/** Number of available cores. */ +#define CORES @CORES@ + +/** Atmel AVR ATMega128 8-bit architecture. */ +#define AVR 1 +/** MSP430 16-bit architecture. */ +#define MSP 2 +/** ARM 32-bit architecture. */ +#define ARM 3 +/** Intel x86-compatible 32-bit architecture. */ +#define X86 4 +/** AMD64-compatible 64-bit architecture. */ +#define X64 5 +/** Architecture. */ +#cmakedefine ARCH @ARCH@ + +/** Size of word in this architecture. */ +#define WSIZE @WSIZE@ + +/** Byte boundary to align digit vectors. */ +#define ALIGN @ALIGN@ + +/** Build multiple precision integer module. */ +#cmakedefine WITH_BN +/** Build prime field module. */ +#cmakedefine WITH_FP +/** Build prime field extension module. */ +#cmakedefine WITH_FPX +/** Build binary field module. */ +#cmakedefine WITH_FB +/** Build prime elliptic curve module. */ +#cmakedefine WITH_EP +/** Build prime field extension elliptic curve module. */ +#cmakedefine WITH_EPX +/** Build binary elliptic curve module. */ +#cmakedefine WITH_EB +/** Build elliptic Edwards curve module. */ +#cmakedefine WITH_ED +/** Build elliptic curve cryptography module. */ +#cmakedefine WITH_EC +/** Build pairings over prime curves module. */ +#cmakedefine WITH_PP +/** Build pairing-based cryptography module. */ +#cmakedefine WITH_PC +/** Build block ciphers. */ +#cmakedefine WITH_BC +/** Build hash functions. */ +#cmakedefine WITH_MD +/** Build cryptographic protocols. */ +#cmakedefine WITH_CP +/** Build Multi-party computation primitives. */ +#cmakedefine WITH_MPC + +/** Easy C-only backend. */ +#define EASY 1 +/** GMP backend. */ +#define GMP 2 +/** GMP constant-time backend. */ +#define GMP_SEC 3 +/** Arithmetic backend. */ +#define ARITH @ARITH@ + +/** Required precision in bits. */ +#define BN_PRECI @BN_PRECI@ +/** A multiple precision integer can store w words. */ +#define SINGLE 0 +/** A multiple precision integer can store the result of an addition. */ +#define CARRY 1 +/** A multiple precision integer can store the result of a multiplication. */ +#define DOUBLE 2 +/** Effective size of a multiple precision integer. */ +#define BN_MAGNI @BN_MAGNI@ +/** Number of Karatsuba steps. */ +#define BN_KARAT @BN_KARAT@ + +/** Schoolbook multiplication. */ +#define BASIC 1 +/** Comba multiplication. */ +#define COMBA 2 +/** Chosen multiple precision multiplication method. */ +#define BN_MUL @BN_MUL@ + +/** Schoolbook squaring. */ +#define BASIC 1 +/** Comba squaring. */ +#define COMBA 2 +/** Reuse multiplication for squaring. */ +#define MULTP 4 +/** Chosen multiple precision multiplication method. */ +#define BN_SQR @BN_SQR@ + +/** Division modular reduction. */ +#define BASIC 1 +/** Barrett modular reduction. */ +#define BARRT 2 +/** Montgomery modular reduction. */ +#define MONTY 3 +/** Pseudo-Mersenne modular reduction. */ +#define PMERS 4 +/** Chosen multiple precision modular reduction method. */ +#define BN_MOD @BN_MOD@ + +/** Binary modular exponentiation. */ +#define BASIC 1 +/** Sliding window modular exponentiation. */ +#define SLIDE 2 +/** Montgomery powering ladder. */ +#define MONTY 3 +/** Chosen multiple precision modular exponentiation method. */ +#define BN_MXP @BN_MXP@ + +/** Basic Euclidean GCD Algorithm. */ +#define BASIC 1 +/** Lehmer's fast GCD Algorithm. */ +#define LEHME 2 +/** Stein's binary GCD Algorithm. */ +#define STEIN 3 +/** Chosen multiple precision greatest common divisor method. */ +#define BN_GCD @BN_GCD@ + +/** Basic prime generation. */ +#define BASIC 1 +/** Safe prime generation. */ +#define SAFEP 2 +/** Strong prime generation. */ +#define STRON 3 +/** Chosen prime generation algorithm. */ +#define BN_GEN @BN_GEN@ + +/** Multiple precision arithmetic method */ +#define BN_METHD "@BN_METHD@" + +/** Prime field size in bits. */ +#define FP_PRIME @FP_PRIME@ +/** Number of Karatsuba steps. */ +#define FP_KARAT @FP_KARAT@ +/** Prefer Pseudo-Mersenne primes over random primes. */ +#cmakedefine FP_PMERS +/** Use -1 as quadratic non-residue. */ +#cmakedefine FP_QNRES +/** Width of window processing for exponentiation methods. */ +#define FP_WIDTH @FP_WIDTH@ + +/** Schoolbook addition. */ +#define BASIC 1 +/** Integrated modular addtion. */ +#define INTEG 3 +/** Chosen prime field multiplication method. */ +#define FP_ADD @FP_ADD@ + +/** Schoolbook multiplication. */ +#define BASIC 1 +/** Comba multiplication. */ +#define COMBA 2 +/** Integrated modular multiplication. */ +#define INTEG 3 +/** Chosen prime field multiplication method. */ +#define FP_MUL @FP_MUL@ + +/** Schoolbook squaring. */ +#define BASIC 1 +/** Comba squaring. */ +#define COMBA 2 +/** Integrated modular squaring. */ +#define INTEG 3 +/** Reuse multiplication for squaring. */ +#define MULTP 4 +/** Chosen prime field multiplication method. */ +#define FP_SQR @FP_SQR@ + +/** Division-based reduction. */ +#define BASIC 1 +/** Fast reduction modulo special form prime. */ +#define QUICK 2 +/** Montgomery modular reduction. */ +#define MONTY 3 +/** Chosen prime field reduction method. */ +#define FP_RDC @FP_RDC@ + +/** Inversion by Fermat's Little Theorem. */ +#define BASIC 1 +/** Binary inversion. */ +#define BINAR 2 +/** Integrated modular multiplication. */ +#define MONTY 3 +/** Extended Euclidean algorithm. */ +#define EXGCD 4 +/** Constant-time inversion by Bernstein-Yang division steps. */ +#define DIVST 5 +/** Use implementation provided by the lower layer. */ +#define LOWER 8 +/** Chosen prime field inversion method. */ +#define FP_INV @FP_INV@ + +/** Binary modular exponentiation. */ +#define BASIC 1 +/** Sliding window modular exponentiation. */ +#define SLIDE 2 +/** Constant-time Montgomery powering ladder. */ +#define MONTY 3 +/** Chosen multiple precision modular exponentiation method. */ +#define FP_EXP @FP_EXP@ + +/** Prime field arithmetic method */ +#define FP_METHD "@FP_METHD@" + +/** Basic quadratic extension field arithmetic. */ +#define BASIC 1 +/** Integrated extension field arithmetic. */ +#define INTEG 3 +/* Chosen extension field arithmetic method. */ +#define FPX_QDR @FPX_QDR@ + +/** Basic cubic extension field arithmetic. */ +#define BASIC 1 +/** Integrated extension field arithmetic. */ +#define INTEG 3 +/* Chosen extension field arithmetic method. */ +#define FPX_CBC @FPX_CBC@ + +/** Basic quadratic extension field arithmetic. */ +#define BASIC 1 +/** Lazy-reduced extension field arithmetic. */ +#define LAZYR 2 +/* Chosen extension field arithmetic method. */ +#define FPX_RDC @FPX_RDC@ + +/** Prime extension field arithmetic method */ +#define FPX_METHD "@FPX_METHD@" + +/** Irreducible polynomial size in bits. */ +#define FB_POLYN @FB_POLYN@ +/** Number of Karatsuba steps. */ +#define FB_KARAT @FB_KARAT@ +/** Prefer trinomials over pentanomials. */ +#cmakedefine FB_TRINO +/** Prefer square-root friendly polynomials. */ +#cmakedefine FB_SQRTF +/** Precompute multiplication table for sqrt(z). */ +#cmakedefine FB_PRECO +/** Width of window processing for exponentiation methods. */ +#define FB_WIDTH @FB_WIDTH@ + +/** Shift-and-add multiplication. */ +#define BASIC 1 +/** Lopez-Dahab multiplication. */ +#define LODAH 2 +/** Integrated modular multiplication. */ +#define INTEG 3 +/** Chosen binary field multiplication method. */ +#define FB_MUL @FB_MUL@ + +/** Basic squaring. */ +#define BASIC 1 +/** Table-based squaring. */ +#define QUICK 2 +/** Integrated modular squaring. */ +#define INTEG 3 +/** Chosen binary field squaring method. */ +#define FB_SQR @FB_SQR@ + +/** Shift-and-add modular reduction. */ +#define BASIC 1 +/** Fast reduction modulo a trinomial or pentanomial. */ +#define QUICK 2 +/** Chosen binary field modular reduction method. */ +#define FB_RDC @FB_RDC@ + +/** Square root by repeated squaring. */ +#define BASIC 1 +/** Fast square root extraction. */ +#define QUICK 2 +/** Chosen binary field modular reduction method. */ +#define FB_SRT @FB_SRT@ + +/** Trace by repeated squaring. */ +#define BASIC 1 +/** Fast trace computation. */ +#define QUICK 2 +/** Chosen trace computation method. */ +#define FB_TRC @FB_TRC@ + +/** Solve by half-trace computation. */ +#define BASIC 1 +/** Solve with precomputed half-traces. */ +#define QUICK 2 +/** Chosen method to solve a quadratic equation. */ +#define FB_SLV @FB_SLV@ + +/** Inversion by Fermat's Little Theorem. */ +#define BASIC 1 +/** Binary inversion. */ +#define BINAR 2 +/** Almost inverse algorithm. */ +#define ALMOS 3 +/** Extended Euclidean algorithm. */ +#define EXGCD 4 +/** Itoh-Tsuji inversion. */ +#define ITOHT 5 +/** Hardware-friendly inversion by Brunner-Curiger-Hofstetter.*/ +#define BRUCH 6 +/** Constant-time version of almost inverse. */ +#define CTAIA 7 +/** Use implementation provided by the lower layer. */ +#define LOWER 8 +/** Chosen binary field inversion method. */ +#define FB_INV @FB_INV@ + +/** Binary modular exponentiation. */ +#define BASIC 1 +/** Sliding window modular exponentiation. */ +#define SLIDE 2 +/** Constant-time Montgomery powering ladder. */ +#define MONTY 3 +/** Chosen multiple precision modular exponentiation method. */ +#define FB_EXP @FB_EXP@ + +/** Iterated squaring/square-root by consecutive squaring/square-root. */ +#define BASIC 1 +/** Iterated squaring/square-root by table-based method. */ +#define QUICK 2 +/** Chosen method to solve a quadratic equation. */ +#define FB_ITR @FB_ITR@ + +/** Binary field arithmetic method */ +#define FB_METHD "@FB_METHD@" + +/** Support for ordinary curves. */ +#cmakedefine EP_PLAIN +/** Support for supersingular curves. */ +#cmakedefine EP_SUPER +/** Support for prime curves with efficient endormorphisms. */ +#cmakedefine EP_ENDOM +/** Use mixed coordinates. */ +#cmakedefine EP_MIXED +/** Build precomputation table for generator. */ +#cmakedefine EP_PRECO +/** Enable isogeny map for SSWU map-to-curve. */ +#cmakedefine EP_CTMAP +/** Width of precomputation table for fixed point methods. */ +#define EP_DEPTH @EP_DEPTH@ +/** Width of window processing for unknown point methods. */ +#define EP_WIDTH @EP_WIDTH@ + +/** Affine coordinates. */ +#define BASIC 1 +/** Projective coordinates. */ +#define PROJC 2 +/** Jacobian coordinates. */ +#define JACOB 3 +/** Chosen prime elliptic curve coordinate method. */ +#define EP_ADD @EP_ADD@ + +/** Binary point multiplication. */ +#define BASIC 1 +/** Sliding window. */ +#define SLIDE 2 +/** Montgomery powering ladder. */ +#define MONTY 3 +/** Left-to-right Width-w NAF. */ +#define LWNAF 4 +/** Left-to-right Width-w NAF. */ +#define LWREG 5 +/** Chosen prime elliptic curve point multiplication method. */ +#define EP_MUL @EP_MUL@ + +/** Binary point multiplication. */ +#define BASIC 1 +/** Single-table comb method. */ +#define COMBS 2 +/** Double-table comb method. */ +#define COMBD 3 +/** Left-to-right Width-w NAF. */ +#define LWNAF 4 +/** Chosen prime elliptic curve point multiplication method. */ +#define EP_FIX @EP_FIX@ + +/** Basic simultaneouns point multiplication. */ +#define BASIC 1 +/** Shamir's trick. */ +#define TRICK 2 +/** Interleaving of w-(T)NAFs. */ +#define INTER 3 +/** Joint sparse form. */ +#define JOINT 4 +/** Chosen prime elliptic curve simulteanous point multiplication method. */ +#define EP_SIM @EP_SIM@ + +/** Prime elliptic curve arithmetic method. */ +#define EP_METHD "@EP_METHD@" + +/** Support for ordinary curves without endormorphisms. */ +#cmakedefine EB_PLAIN +/** Support for Koblitz anomalous binary curves. */ +#cmakedefine EB_KBLTZ +/** Use mixed coordinates. */ +#cmakedefine EB_MIXED +/** Build precomputation table for generator. */ +#cmakedefine EB_PRECO +/** Width of precomputation table for fixed point methods. */ +#define EB_DEPTH @EB_DEPTH@ +/** Width of window processing for unknown point methods. */ +#define EB_WIDTH @EB_WIDTH@ + +/** Binary elliptic curve arithmetic method. */ +#define EB_METHD "@EB_METHD@" + +/** Affine coordinates. */ +#define BASIC 1 +/** López-Dahab Projective coordinates. */ +#define PROJC 2 +/** Chosen binary elliptic curve coordinate method. */ +#define EB_ADD @EB_ADD@ + +/** Binary point multiplication. */ +#define BASIC 1 +/** L�pez-Dahab point multiplication. */ +#define LODAH 2 +/** Halving. */ +#define HALVE 3 +/** Left-to-right width-w (T)NAF. */ +#define LWNAF 4 +/** Right-to-left width-w (T)NAF. */ +#define RWNAF 5 +/** Chosen binary elliptic curve point multiplication method. */ +#define EB_MUL @EB_MUL@ + +/** Binary point multiplication. */ +#define BASIC 1 +/** Single-table comb method. */ +#define COMBS 2 +/** Double-table comb method. */ +#define COMBD 3 +/** Left-to-right Width-w NAF. */ +#define LWNAF 4 +/** Chosen binary elliptic curve point multiplication method. */ +#define EB_FIX @EB_FIX@ + +/** Basic simultaneouns point multiplication. */ +#define BASIC 1 +/** Shamir's trick. */ +#define TRICK 2 +/** Interleaving of w-(T)NAFs. */ +#define INTER 3 +/** Joint sparse form. */ +#define JOINT 4 +/** Chosen binary elliptic curve simulteanous point multiplication method. */ +#define EB_SIM @EB_SIM@ + +/** Build precomputation table for generator. */ +#cmakedefine ED_PRECO +/** Width of precomputation table for fixed point methods. */ +#define ED_DEPTH @ED_DEPTH@ +/** Width of window processing for unknown point methods. */ +#define ED_WIDTH @ED_WIDTH@ + +/** Edwards elliptic curve arithmetic method. */ +#define ED_METHD "@ED_METHD@" + +/** Affine coordinates. */ +#define BASIC 1 +/** Simple projective twisted Edwards coordinates */ +#define PROJC 2 +/** Extended projective twisted Edwards coordinates */ +#define EXTND 3 +/** Chosen binary elliptic curve coordinate method. */ +#define ED_ADD @ED_ADD@ + +/** Binary point multiplication. */ +#define BASIC 1 +/** Sliding window. */ +#define SLIDE 2 +/** Montgomery powering ladder. */ +#define MONTY 3 +/** Left-to-right Width-w NAF. */ +#define LWNAF 4 +/** Left-to-right Width-w NAF. */ +#define LWREG 5 +/** Chosen prime elliptic twisted Edwards curve point multiplication method. */ +#define ED_MUL @ED_MUL@ + +/** Binary point multiplication. */ +#define BASIC 1 +/** Single-table comb method. */ +#define COMBS 2 +/** Double-table comb method. */ +#define COMBD 3 +/** Left-to-right Width-w NAF. */ +#define LWNAF 4 +/** Chosen prime elliptic twisted Edwards curve point multiplication method. */ +#define ED_FIX @ED_FIX@ + +/** Basic simultaneouns point multiplication. */ +#define BASIC 1 +/** Shamir's trick. */ +#define TRICK 2 +/** Interleaving of w-(T)NAFs. */ +#define INTER 3 +/** Joint sparse form. */ +#define JOINT 4 +/** Chosen prime elliptic curve simulteanous point multiplication method. */ +#define ED_SIM @ED_SIM@ + +/** Prime curves. */ +#define PRIME 1 +/** Binary curves. */ +#define CHAR2 2 +/** Edwards curves */ +#define EDDIE 3 +/** Chosen elliptic curve type. */ +#define EC_CUR @EC_CUR@ + +/** Chosen elliptic curve cryptography method. */ +#define EC_METHD "@EC_METHD@" +/** Prefer curves with efficient endomorphisms. */ +#cmakedefine EC_ENDOM + +/** Basic quadratic extension field arithmetic. */ +#define BASIC 1 +/** Lazy-reduced extension field arithmetic. */ +#define LAZYR 2 +/* Chosen extension field arithmetic method. */ +#define PP_EXT @PP_EXT@ + +/** Bilinear pairing method. */ +#define PP_METHD "@PP_METHD@" + +/** Tate pairing. */ +#define TATEP 1 +/** Weil pairing. */ +#define WEILP 2 +/** Optimal ate pairing. */ +#define OATEP 3 +/** Chosen pairing method over prime elliptic curves. */ +#define PP_MAP @PP_MAP@ + +/** SHA-224 hash function. */ +#define SH224 2 +/** SHA-256 hash function. */ +#define SH256 3 +/** SHA-384 hash function. */ +#define SH384 4 +/** SHA-512 hash function. */ +#define SH512 5 +/** BLAKE2s-160 hash function. */ +#define B2S160 6 +/** BLAKE2s-256 hash function. */ +#define B2S256 7 +/** Chosen hash function. */ +#define MD_MAP @MD_MAP@ + +/** Choice of hash function. */ +#define MD_METHD "@MD_METHD@" + +/** Chosen RSA method. */ +#cmakedefine CP_CRT +/** RSA without padding. */ +#define BASIC 1 +/** RSA PKCS#1 v1.5 padding. */ +#define PKCS1 2 +/** RSA PKCS#1 v2.1 padding. */ +#define PKCS2 3 +/** Chosen RSA padding method. */ +#define CP_RSAPD @CP_RSAPD@ + +/** Automatic memory allocation. */ +#define AUTO 1 +/** Dynamic memory allocation. */ +#define DYNAMIC 2 +/** Chosen memory allocation policy. */ +#define ALLOC @ALLOC@ + +/** NIST HASH-DRBG generator. */ +#define HASHD 1 +/** Intel RdRand instruction. */ +#define RDRND 2 +/** Operating system underlying generator. */ +#define UDEV 3 +/** Override library generator with the callback. */ +#define CALL 4 +/** Chosen random generator. */ +#define RAND @RAND@ + +/** Standard C library generator. */ +#define LIBC 1 +/** Intel RdRand instruction. */ +#define RDRND 2 +/** Device node generator. */ +#define UDEV 3 +/** Use Windows' CryptGenRandom. */ +#define WCGR 4 +/** Chosen random generator seeder. */ +#cmakedefine SEED @SEED@ + +/** GNU/Linux operating system. */ +#define LINUX 1 +/** FreeBSD operating system. */ +#define FREEBSD 2 +/** Windows operating system. */ +#define MACOSX 3 +/** Windows operating system. */ +#define WINDOWS 4 +/** Android operating system. */ +#define DROID 5 +/** Arduino platform. */ +#define DUINO 6 +/** OpenBSD operating system. */ +#define OPENBSD 7 +/** Detected operation system. */ +#cmakedefine OPSYS @OPSYS@ + +/** OpenMP multithreading support. */ +#define OPENMP 1 +/** POSIX multithreading support. */ +#define PTHREAD 2 +/** Chosen multithreading API. */ +#cmakedefine MULTI @MULTI@ + +/** Per-process high-resolution timer. */ +#define HREAL 1 +/** Per-process high-resolution timer. */ +#define HPROC 2 +/** Per-thread high-resolution timer. */ +#define HTHRD 3 +/** POSIX-compatible timer. */ +#define POSIX 4 +/** ANSI-compatible timer. */ +#define ANSI 5 +/** Cycle-counting timer. */ +#define CYCLE 6 +/** Performance monitoring framework. */ +#define PERF 7 +/** Chosen timer. */ +#cmakedefine TIMER @TIMER@ + +/** Prefix to identity this build of the library. */ +#cmakedefine LABEL @LABEL@ + +#ifndef ASM + +#include "relic_label.h" + +/** + * Prints the project options selected at build time. + */ +void conf_print(void); + +#endif /* ASM */ + +#endif /* !RLC_CONF_H */ diff --git a/src/dashbls/include/dashbls/bls.hpp b/src/dashbls/include/dashbls/bls.hpp index cd6922a58cd6..d9108873511c 100644 --- a/src/dashbls/include/dashbls/bls.hpp +++ b/src/dashbls/include/dashbls/bls.hpp @@ -40,8 +40,6 @@ class BLS { static bool Init(); static void SetSecureAllocator(Util::SecureAllocCallback allocCb, Util::SecureFreeCallback freeCb); - - static void CheckRelicErrors(bool should_throw = true); }; } // end namespace bls diff --git a/src/dashbls/include/dashbls/chaincode.hpp b/src/dashbls/include/dashbls/chaincode.hpp index bd3e57b4d779..ecd5db79fd39 100644 --- a/src/dashbls/include/dashbls/chaincode.hpp +++ b/src/dashbls/include/dashbls/chaincode.hpp @@ -15,19 +15,10 @@ #ifndef SRC_CHAINCODE_HPP_ #define SRC_CHAINCODE_HPP_ +#include #include #include -#include "relic_conf.h" - -#if defined GMP && ARITH == GMP -#include -#endif - - -#include "relic.h" -#include "relic_test.h" - #include "util.hpp" namespace bls { @@ -51,9 +42,8 @@ class ChainCode { ChainCode() {} private: - bn_t chainCode; + std::array chainCode{}; }; } // end namespace bls #endif // SRC_CHAINCODE_HPP_ - diff --git a/src/dashbls/include/dashbls/elements.hpp b/src/dashbls/include/dashbls/elements.hpp index 95937f62dbc6..ddfea23994d9 100644 --- a/src/dashbls/include/dashbls/elements.hpp +++ b/src/dashbls/include/dashbls/elements.hpp @@ -16,17 +16,12 @@ #define SRC_BLSELEMENTS_HPP_ extern "C" { -#include "relic.h" +#include "blst.h" } -#include "relic_conf.h" -#include "util.hpp" - -#if defined GMP && ARITH == GMP -#include -#endif - #include +#include "util.hpp" + namespace bls { class G1Element; class G2Element; @@ -36,25 +31,27 @@ class G1Element { public: static const size_t SIZE = 48; - G1Element() { - g1_set_infty(p); - } - - static G1Element FromBytes(Bytes bytes, bool fLegacy = false); - static G1Element FromBytesUnchecked(Bytes bytes, bool fLegacy = false); - static G1Element FromByteVector(const std::vector &bytevec, bool fLegacy = false); - static G1Element FromNative(const g1_t element); - static G1Element FromMessage(const std::vector &message, - const uint8_t *dst, - int dst_len); - static G1Element FromMessage(Bytes message, - const uint8_t* dst, - int dst_len); + G1Element() { memset(&p, 0x00, sizeof(blst_p1)); } + + static G1Element FromBytes(Bytes bytes, bool legacy_encoding = false); + static G1Element FromBytesUnchecked(Bytes bytes, bool legacy_encoding = false); + static G1Element FromByteVector(const std::vector &bytevec, bool legacy_encoding = false); + static G1Element FromNative(const blst_p1 &element); + static G1Element FromAffine(const blst_p1_affine &element); + static G1Element FromMessage( + const std::vector &message, + const uint8_t *dst, + int dst_len); + static G1Element FromMessage( + Bytes message, + const uint8_t *dst, + int dst_len); static G1Element Generator(); bool IsValid() const; void CheckValid() const; - void ToNative(g1_t output) const; + void ToNative(blst_p1 *output) const; + void ToAffine(blst_p1_affine *output) const; G1Element Negate() const; GTElement Pair(const G2Element &b) const; uint32_t GetFingerprint(bool fLegacy = false) const; @@ -65,41 +62,41 @@ class G1Element { friend bool operator==(const G1Element &a, const G1Element &b); friend bool operator!=(const G1Element &a, const G1Element &b); friend std::ostream &operator<<(std::ostream &os, const G1Element &s); - friend G1Element& operator+=(G1Element& a, const G1Element& b); + friend G1Element &operator+=(G1Element &a, const G1Element &b); friend G1Element operator+(const G1Element &a, const G1Element &b); - friend G1Element operator*(const G1Element &a, const bn_t &k); - friend G1Element operator*(const bn_t &k, const G1Element &a); + friend G1Element operator*(const G1Element &a, const blst_scalar &k); + friend G1Element operator*(const blst_scalar &k, const G1Element &a); friend GTElement operator&(const G1Element &a, const G2Element &b); private: - g1_t p; + blst_p1 p; }; class G2Element { public: static const size_t SIZE = 96; - G2Element() { - g2_set_infty(q); - } - - static G2Element FromBytes(Bytes bytes, bool fLegacy = false); - static G2Element FromBytesUnchecked(Bytes bytes, bool fLegacy = false); - static G2Element FromByteVector(const std::vector &bytevec, bool fLegacy = false); - static G2Element FromNative(const g2_t element); - static G2Element FromMessage(const std::vector& message, - const uint8_t* dst, - int dst_len, - bool fLegacy = false); - static G2Element FromMessage(Bytes message, - const uint8_t* dst, - int dst_len, - bool fLegacy = false); + G2Element() { memset(&q, 0x00, sizeof(blst_p2)); } + + static G2Element FromBytes(Bytes bytes, bool legacy_encoding = false); + static G2Element FromBytesUnchecked(Bytes bytes, bool legacy_encoding = false); + static G2Element FromByteVector(const std::vector &bytevec, bool legacy_encoding = false); + static G2Element FromNative(const blst_p2 &element); + static G2Element FromAffine(const blst_p2_affine &element); + static G2Element FromMessage( + const std::vector &message, + const uint8_t *dst, + int dst_len, bool legacy_encoding = false); + static G2Element FromMessage( + Bytes message, + const uint8_t *dst, + int dst_len, bool legacy_encoding = false); static G2Element Generator(); bool IsValid() const; void CheckValid() const; - void ToNative(g2_t output) const; + void ToNative(blst_p2 *output) const; + void ToAffine(blst_p2_affine *output) const; G2Element Negate() const; GTElement Pair(const G1Element &a) const; std::vector Serialize(bool fLegacy = false) const; @@ -109,22 +106,25 @@ class G2Element { friend bool operator==(G2Element const &a, G2Element const &b); friend bool operator!=(G2Element const &a, G2Element const &b); friend std::ostream &operator<<(std::ostream &os, const G2Element &s); - friend G2Element& operator+=(G2Element& a, const G2Element& b); + friend G2Element &operator+=(G2Element &a, const G2Element &b); friend G2Element operator+(const G2Element &a, const G2Element &b); - friend G2Element operator*(const G2Element &a, const bn_t &k); - friend G2Element operator*(const bn_t &k, const G2Element &a); + friend G2Element operator*(const G2Element &a, const blst_scalar &k); + friend G2Element operator*(const blst_scalar &k, const G2Element &a); private: - g2_t q; + blst_p2 q; }; class GTElement { public: - static const size_t SIZE = 384; + static const size_t SIZE = sizeof(blst_fp12); + static GTElement FromBytes(Bytes bytes); static GTElement FromBytesUnchecked(Bytes bytes); static GTElement FromByteVector(const std::vector &bytevec); - static GTElement FromNative(const gt_t *element); + static GTElement FromNative(const blst_fp12 *element); + static GTElement FromAffine(const blst_p1_affine &element); + static GTElement FromAffine(const blst_p2_affine &element); static GTElement Unity(); // unity void Serialize(uint8_t *buffer) const; @@ -135,10 +135,9 @@ class GTElement { friend bool operator!=(GTElement const &a, GTElement const &b); friend std::ostream &operator<<(std::ostream &os, const GTElement &s); friend GTElement operator*(GTElement &a, GTElement &b); - GTElement &operator=(const GTElement &rhs); private: - gt_t r; + blst_fp12 r; GTElement() {} }; diff --git a/src/dashbls/include/dashbls/extendedprivatekey.hpp b/src/dashbls/include/dashbls/extendedprivatekey.hpp index aefdbf057257..575256ab9425 100644 --- a/src/dashbls/include/dashbls/extendedprivatekey.hpp +++ b/src/dashbls/include/dashbls/extendedprivatekey.hpp @@ -15,21 +15,13 @@ #ifndef SRC_EXTENDEDPRIVATEKEY_HPP_ #define SRC_EXTENDEDPRIVATEKEY_HPP_ -#include "relic_conf.h" - #include -#if defined GMP && ARITH == GMP -#include -#endif - #include "chaincode.hpp" #include "elements.hpp" #include "extendedpublickey.hpp" #include "privatekey.hpp" -#include "relic.h" -#include "relic_test.h" namespace bls { /* diff --git a/src/dashbls/include/dashbls/extendedpublickey.hpp b/src/dashbls/include/dashbls/extendedpublickey.hpp index b44d5c636a3c..c1fbdf7bf0dd 100644 --- a/src/dashbls/include/dashbls/extendedpublickey.hpp +++ b/src/dashbls/include/dashbls/extendedpublickey.hpp @@ -15,20 +15,12 @@ #ifndef SRC_EXTENDEDPUBLICKEY_HPP_ #define SRC_EXTENDEDPUBLICKEY_HPP_ -#include "relic_conf.h" - #include -#if defined GMP && ARITH == GMP -#include -#endif - #include "chaincode.hpp" #include "elements.hpp" -#include "relic.h" -#include "relic_test.h" namespace bls { diff --git a/src/dashbls/include/dashbls/hdkeys.hpp b/src/dashbls/include/dashbls/hdkeys.hpp index 629ec5e3d142..1cadd7423b9c 100644 --- a/src/dashbls/include/dashbls/hdkeys.hpp +++ b/src/dashbls/include/dashbls/hdkeys.hpp @@ -15,16 +15,11 @@ #ifndef SRC_BLSHDKEYS_HPP_ #define SRC_BLSHDKEYS_HPP_ -#include "relic_conf.h" #include -#if defined GMP && ARITH == GMP -#include -#endif - -#include "util.hpp" -#include "privatekey.hpp" #include "hkdf.hpp" +#include "privatekey.hpp" +#include "util.hpp" namespace bls { @@ -32,14 +27,14 @@ class HDKeys { /** * Implements HD keys as specified in EIP2333. **/ - public: +public: static const uint8_t HASH_LEN = 32; static PrivateKey KeyGen(const std::vector& seed) { return KeyGen(Bytes(seed)); } - + static PrivateKey KeyGen(const Bytes& seed) { // KeyGen @@ -56,65 +51,44 @@ class HDKeys { throw std::invalid_argument("Seed size must be at least 32 bytes"); } - // "BLS-SIG-KEYGEN-SALT-" in ascii - const uint8_t saltHkdf[20] = {66, 76, 83, 45, 83, 73, 71, 45, 75, 69, - 89, 71, 69, 78, 45, 83, 65, 76, 84, 45}; + blst_scalar* skBn = Util::SecAlloc(1); + blst_keygen_v3(skBn, seed.begin(), seed.size(), info, infoLen); + uint8_t* skBytes = Util::SecAlloc(32); + blst_bendian_from_scalar(skBytes, skBn); - uint8_t *prk = Util::SecAlloc(32); - uint8_t *ikmHkdf = Util::SecAlloc(seed.size() + 1); - memcpy(ikmHkdf, seed.begin(), seed.size()); - ikmHkdf[seed.size()] = 0; - - const uint8_t L = 48; // `ceil((3 * ceil(log2(r))) / 16)`, where `r` is the - // order of the BLS 12-381 curve - - uint8_t *okmHkdf = Util::SecAlloc(L); - - uint8_t keyInfoHkdf[infoLen + 2]; - memcpy(keyInfoHkdf, info, infoLen); - keyInfoHkdf[infoLen] = 0; // Two bytes for L, 0 and 48 - keyInfoHkdf[infoLen + 1] = L; - - HKDF256::ExtractExpand( - okmHkdf, - L, - ikmHkdf, - seed.size() + 1, - saltHkdf, - 20, - keyInfoHkdf, - infoLen + 2); - - bn_t order; - bn_new(order); - g1_get_ord(order); - - // Make sure private key is less than the curve order - bn_t *skBn = Util::SecAlloc(1); - bn_new(*skBn); - bn_read_bin(*skBn, okmHkdf, L); - bn_mod_basic(*skBn, *skBn, order); - - uint8_t *skBytes = Util::SecAlloc(32); - bn_write_bin(skBytes, 32, *skBn); PrivateKey k = PrivateKey::FromBytes(Bytes(skBytes, 32)); - Util::SecFree(prk); - Util::SecFree(ikmHkdf); Util::SecFree(skBn); - Util::SecFree(okmHkdf); Util::SecFree(skBytes); return k; } - static void IKMToLamportSk(uint8_t* outputLamportSk, const uint8_t* ikm, size_t ikmLen, const uint8_t* salt, size_t saltLen) { + static void IKMToLamportSk( + uint8_t* outputLamportSk, + const uint8_t* ikm, + size_t ikmLen, + const uint8_t* salt, + size_t saltLen) + { // Expands the ikm to 255*HASH_LEN bytes for the lamport sk const uint8_t info[1] = {0}; - HKDF256::ExtractExpand(outputLamportSk, HASH_LEN * 255, ikm, ikmLen, salt, saltLen, info, 0); + HKDF256::ExtractExpand( + outputLamportSk, + HASH_LEN * 255, + ikm, + ikmLen, + salt, + saltLen, + info, + 0); } - static void ParentSkToLamportPK(uint8_t* outputLamportPk, const PrivateKey& parentSk, uint32_t index) { + static void ParentSkToLamportPK( + uint8_t* outputLamportPk, + const PrivateKey& parentSk, + uint32_t index) + { uint8_t* salt = Util::SecAlloc(4); uint8_t* ikm = Util::SecAlloc(HASH_LEN); uint8_t* notIkm = Util::SecAlloc(HASH_LEN); @@ -134,11 +108,15 @@ class HDKeys { uint8_t* lamportPk = Util::SecAlloc(HASH_LEN * 255 * 2); for (size_t i = 0; i < 255; i++) { - Util::Hash256(lamportPk + i * HASH_LEN, lamport0 + i * HASH_LEN, HASH_LEN); + Util::Hash256( + lamportPk + i * HASH_LEN, lamport0 + i * HASH_LEN, HASH_LEN); } - for (size_t i=0; i < 255; i++) { - Util::Hash256(lamportPk + 255 * HASH_LEN + i * HASH_LEN, lamport1 + i * HASH_LEN, HASH_LEN); + for (size_t i = 0; i < 255; i++) { + Util::Hash256( + lamportPk + 255 * HASH_LEN + i * HASH_LEN, + lamport1 + i * HASH_LEN, + HASH_LEN); } Util::Hash256(outputLamportPk, lamportPk, HASH_LEN * 255 * 2); @@ -150,7 +128,8 @@ class HDKeys { Util::SecFree(lamportPk); } - static PrivateKey DeriveChildSk(const PrivateKey& parentSk, uint32_t index) { + static PrivateKey DeriveChildSk(const PrivateKey& parentSk, uint32_t index) + { uint8_t* lamportPk = Util::SecAlloc(HASH_LEN); HDKeys::ParentSkToLamportPK(lamportPk, parentSk, index); std::vector lamportPkVector(lamportPk, lamportPk + HASH_LEN); @@ -159,21 +138,29 @@ class HDKeys { return child; } - static PrivateKey DeriveChildSkUnhardened(const PrivateKey& parentSk, uint32_t index) { + static PrivateKey DeriveChildSkUnhardened( + const PrivateKey& parentSk, + uint32_t index) + { uint8_t* buf = Util::SecAlloc(G1Element::SIZE + 4); uint8_t* digest = Util::SecAlloc(HASH_LEN); - memcpy(buf, parentSk.GetG1Element().Serialize().data(), G1Element::SIZE); + memcpy( + buf, parentSk.GetG1Element().Serialize().data(), G1Element::SIZE); Util::IntToFourBytes(buf + G1Element::SIZE, index); Util::Hash256(digest, buf, G1Element::SIZE + 4); - PrivateKey ret = PrivateKey::Aggregate({parentSk, PrivateKey::FromBytes(Bytes(digest, HASH_LEN), true)}); + PrivateKey ret = PrivateKey::Aggregate( + {parentSk, PrivateKey::FromBytes(Bytes(digest, HASH_LEN), true)}); Util::SecFree(buf); Util::SecFree(digest); return ret; } - static G1Element DeriveChildG1Unhardened(const G1Element& pk, uint32_t index) { + static G1Element DeriveChildG1Unhardened( + const G1Element& pk, + uint32_t index) + { uint8_t* buf = Util::SecAlloc(G1Element::SIZE + 4); uint8_t* digest = Util::SecAlloc(HASH_LEN); memcpy(buf, pk.Serialize().data(), G1Element::SIZE); @@ -181,35 +168,33 @@ class HDKeys { Util::IntToFourBytes(buf + G1Element::SIZE, index); Util::Hash256(digest, buf, G1Element::SIZE + 4); - bn_t nonce, ord; - bn_new(nonce); - bn_zero(nonce); - bn_read_bin(nonce, digest, HASH_LEN); - bn_new(ord); - g1_get_ord(ord); - bn_mod_basic(nonce, nonce, ord); + blst_scalar nonce; + // The digest is big-endian; upstream chia loaded it as little-endian, + // which only worked because operator* reversed the bytes again. + blst_scalar_from_bendian(&nonce, digest); Util::SecFree(buf); Util::SecFree(digest); G1Element gen = G1Element::Generator(); - return pk + gen * nonce; + + return pk + (gen * nonce); } - static G2Element DeriveChildG2Unhardened(const G2Element& pk, uint32_t index) { + static G2Element DeriveChildG2Unhardened( + const G2Element& pk, + uint32_t index) + { uint8_t* buf = Util::SecAlloc(G2Element::SIZE + 4); uint8_t* digest = Util::SecAlloc(HASH_LEN); memcpy(buf, pk.Serialize().data(), G2Element::SIZE); Util::IntToFourBytes(buf + G2Element::SIZE, index); Util::Hash256(digest, buf, G2Element::SIZE + 4); - bn_t nonce, ord; - bn_new(nonce); - bn_zero(nonce); - bn_read_bin(nonce, digest, HASH_LEN); - bn_new(ord); - g1_get_ord(ord); - bn_mod_basic(nonce, nonce, ord); + blst_scalar nonce; + // The digest is big-endian; upstream chia loaded it as little-endian, + // which only worked because operator* reversed the bytes again. + blst_scalar_from_bendian(&nonce, digest); Util::SecFree(buf); Util::SecFree(digest); @@ -218,5 +203,5 @@ class HDKeys { return pk + gen * nonce; } }; -} // end namespace bls +} // end namespace bls #endif // SRC_BLSHDKEYS_HPP_ diff --git a/src/dashbls/include/dashbls/hkdf.hpp b/src/dashbls/include/dashbls/hkdf.hpp index a7ddc863ebab..27b519b983e5 100644 --- a/src/dashbls/include/dashbls/hkdf.hpp +++ b/src/dashbls/include/dashbls/hkdf.hpp @@ -15,13 +15,7 @@ #ifndef SRC_BLSHKDF_HPP_ #define SRC_BLSHKDF_HPP_ -#include "relic_conf.h" #include - -#if defined GMP && ARITH == GMP -#include -#endif - #include #include "util.hpp" @@ -40,7 +34,7 @@ class HKDF256 { // assert(ikm_len == 32); // Used for EIP2333 key derivation // Hash256 used as the hash function (sha256) // PRK Output is 32 bytes (HashLen) - md_hmac(prk_output, ikm, ikm_len, salt, saltLen); + Util::md_hmac(prk_output, ikm, ikm_len, salt, saltLen); } static void Expand(uint8_t* okm, size_t L, const uint8_t* prk, const uint8_t* info, const size_t infoLen) { @@ -59,12 +53,12 @@ class HKDF256 { if (i == 1) { memcpy(hmacInput1, info, infoLen); hmacInput1[infoLen] = i; - md_hmac(T, hmacInput1, infoLen + 1, prk, HASH_LEN); + Util::md_hmac(T, hmacInput1, infoLen + 1, prk, HASH_LEN); } else { memcpy(hmacInput, T, HASH_LEN); memcpy(hmacInput + HASH_LEN, info, infoLen); hmacInput[HASH_LEN + infoLen] = i; - md_hmac(T, hmacInput, HASH_LEN + infoLen + 1, prk, HASH_LEN); + Util::md_hmac(T, hmacInput, HASH_LEN + infoLen + 1, prk, HASH_LEN); } size_t to_write = L - bytesWritten; if (to_write > HASH_LEN) { diff --git a/src/dashbls/include/dashbls/legacy.hpp b/src/dashbls/include/dashbls/legacy.hpp index b3e1ee1345f1..06c3491afdd5 100644 --- a/src/dashbls/include/dashbls/legacy.hpp +++ b/src/dashbls/include/dashbls/legacy.hpp @@ -5,27 +5,24 @@ #ifndef SRC_LEGACY_HPP_ #define SRC_LEGACY_HPP_ -#include - -#include "relic_conf.h" - -#if defined GMP && ARITH == GMP -#include -#endif - extern "C" { -#include "relic.h" +#include "blst.h" } +#include + +namespace bls { /** * Maps a byte array to a point in an elliptic curve over a quadratic extension. * - * Called ep2_map() in old relic version, _legacy prefix is to avoid duplicated symbols + * Called ep2_map() in old relic version. Now reimplemented on blst and must stay + * bit-for-bit compatible: pre-v19 (legacy scheme) consensus depends on it. * - * @param[out] p - the result. - * @param[in] msg - the byte array to map. - * @param[in] len - the array length in bytes. + * @param[out] p - the result. + * @param[in] msg - the byte array to map (must be 32 bytes). + * @param[in] len - the array length in bytes (must be 32). */ -void ep2_map_legacy(ep2_t p, const uint8_t *msg, int len); +void ep2_map_legacy(blst_p2 *p, const uint8_t *msg, int len); +} // namespace bls #endif // #define SRC_LEGACY_HPP_ diff --git a/src/dashbls/include/dashbls/privatekey.hpp b/src/dashbls/include/dashbls/privatekey.hpp index d02a7d292c12..a85051da59b5 100644 --- a/src/dashbls/include/dashbls/privatekey.hpp +++ b/src/dashbls/include/dashbls/privatekey.hpp @@ -15,12 +15,6 @@ #ifndef SRC_BLSPRIVATEKEY_HPP_ #define SRC_BLSPRIVATEKEY_HPP_ -#include "relic_conf.h" - -#if defined GMP && ARITH == GMP -#include -#endif - #include "elements.hpp" namespace bls { @@ -34,9 +28,6 @@ class PrivateKey { // Construct a private key from a BIP32 based seed. static PrivateKey FromSeedBIP32(const Bytes& seed); - // Construct a random private key. - static PrivateKey RandomPrivateKey(); - // Construct a private key from a bytearray. static PrivateKey FromBytes(const Bytes& bytes, bool modOrder = false); @@ -76,13 +67,13 @@ class PrivateKey { friend G2Element operator*(const G2Element &a, const PrivateKey &k); friend G2Element operator*(const PrivateKey &k, const G2Element &a); - friend PrivateKey operator*(const PrivateKey& a, const bn_t& k); - friend PrivateKey operator*(const bn_t& k, const PrivateKey& a); + friend PrivateKey operator*(const PrivateKey& a, const blst_scalar& k); + friend PrivateKey operator*(const blst_scalar& k, const PrivateKey& a); // Serialize the key into bytes void Serialize(uint8_t *buffer) const; - std::vector Serialize(bool fLegacy = false) const; - std::array SerializeToArray(bool fLegacy = false) const; + std::vector Serialize() const; + std::array SerializeToArray() const; G2Element SignG2( const uint8_t *msg, @@ -105,7 +96,7 @@ class PrivateKey { void InvalidateCaches(); // The actual byte data - bn_st* keydata{nullptr}; + blst_scalar* keydata{nullptr}; mutable bool fG1CacheValid{false}; mutable G1Element g1Cache; diff --git a/src/dashbls/include/dashbls/schemes.hpp b/src/dashbls/include/dashbls/schemes.hpp index 1aee61dd346d..536623f17576 100644 --- a/src/dashbls/include/dashbls/schemes.hpp +++ b/src/dashbls/include/dashbls/schemes.hpp @@ -1,14 +1,14 @@ // Copyright 2020 Chia Network Inc // Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in coiance with the License. +// you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or iied. +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. @@ -19,12 +19,6 @@ #include #include -#include "relic_conf.h" - -#if defined GMP && ARITH == GMP -#include -#endif - #include "elements.hpp" #include "privatekey.hpp" @@ -36,7 +30,6 @@ namespace bls { class Bytes; class CoreMPL { - public: CoreMPL() = delete; CoreMPL(const std::string& strId) : strCiphersuiteId(strId) {} @@ -47,31 +40,42 @@ class CoreMPL { virtual PrivateKey KeyGen(const Bytes& seed); // Generates a public key from a secret key - virtual vector SkToPk(const PrivateKey &seckey); + virtual vector SkToPk(const PrivateKey& seckey); - virtual G1Element SkToG1(const PrivateKey &seckey); + virtual G1Element SkToG1(const PrivateKey& seckey); - virtual G2Element Sign(const PrivateKey &seckey, const vector &message); + virtual G2Element Sign( + const PrivateKey& seckey, + const vector& message); virtual G2Element Sign(const PrivateKey& seckey, const Bytes& message); - virtual bool Verify(const vector &pubkey, - const vector &message, - const vector &signature); + virtual bool Verify( + const vector& pubkey, + const vector& message, + const vector& signature); - virtual bool Verify(const Bytes& pubkey, const Bytes& message, const Bytes& signature); + virtual bool Verify( + const Bytes& pubkey, + const Bytes& message, + const Bytes& signature); - virtual bool Verify(const G1Element &pubkey, - const vector &message, - const G2Element &signature); + virtual bool Verify( + const G1Element& pubkey, + const vector& message, + const G2Element& signature); - virtual bool Verify(const G1Element& pubkey, const Bytes& message, const G2Element& signature); + virtual bool Verify( + const G1Element& pubkey, + const Bytes& message, + const G2Element& signature); - virtual std::array Aggregate(const vector> &signatures); + virtual std::array Aggregate( + const vector>& signatures); virtual std::array Aggregate(const vector& signatures); - virtual G2Element Aggregate(const vector &signatures); + virtual G2Element Aggregate(const vector& signatures); - virtual G1Element Aggregate(const vector &publicKeys); + virtual G1Element Aggregate(const vector& publicKeys); virtual G2Element AggregateSecure(const std::vector& vecPublicKeys, const std::vector& vecSignatures, @@ -81,21 +85,25 @@ class CoreMPL { const G2Element& signature, const Bytes& message); - virtual bool AggregateVerify(const vector> &pubkeys, - const vector> &messages, - const vector &signature); + virtual bool AggregateVerify( + const vector>& pubkeys, + const vector>& messages, + const vector& signature); - virtual bool AggregateVerify(const vector& pubkeys, - const vector& messages, - const Bytes& signature); + virtual bool AggregateVerify( + const vector& pubkeys, + const vector& messages, + const Bytes& signature); - virtual bool AggregateVerify(const vector &pubkeys, - const vector> &messages, - const G2Element &signature); + virtual bool AggregateVerify( + const vector& pubkeys, + const vector>& messages, + const G2Element& signature); - virtual bool AggregateVerify(const vector& pubkeys, - const vector& messages, - const G2Element& signature); + virtual bool AggregateVerify( + const vector& pubkeys, + const vector& messages, + const G2Element& signature); PrivateKey DeriveChildSk(const PrivateKey& sk, uint32_t index); PrivateKey DeriveChildSkUnhardened(const PrivateKey& sk, uint32_t index); @@ -103,7 +111,9 @@ class CoreMPL { protected: const std::string& strCiphersuiteId; - bool NativeVerify(g1_t *pubKeys, g2_t *mappedHashes, size_t length); + static bool NativeVerify(const blst_p1_affine* pubKeys, + const blst_p2_affine* mappedHashes, + size_t length); G2Element AggregateSecure(std::vector const &vecPublicKeys, std::vector const &vecSignatures, const Bytes& message, @@ -118,106 +128,123 @@ class BasicSchemeMPL final : public CoreMPL { public: static const std::string CIPHERSUITE_ID; BasicSchemeMPL() : CoreMPL(BasicSchemeMPL::CIPHERSUITE_ID) {} - bool AggregateVerify(const vector> &pubkeys, - const vector> &messages, - const vector &signature) override; - - bool AggregateVerify(const vector& pubkeys, - const vector& messages, - const Bytes& signature) override; - - bool AggregateVerify(const vector &pubkeys, - const vector> &messages, - const G2Element &signature) override; - - bool AggregateVerify(const vector& pubkeys, - const vector& messages, - const G2Element& signature) override; + bool AggregateVerify( + const vector>& pubkeys, + const vector>& messages, + const vector& signature) override; + + bool AggregateVerify( + const vector& pubkeys, + const vector& messages, + const Bytes& signature) override; + + bool AggregateVerify( + const vector& pubkeys, + const vector>& messages, + const G2Element& signature) override; + + bool AggregateVerify( + const vector& pubkeys, + const vector& messages, + const G2Element& signature) override; }; class AugSchemeMPL final : public CoreMPL { - public: static const std::string CIPHERSUITE_ID; AugSchemeMPL() : CoreMPL(AugSchemeMPL::CIPHERSUITE_ID) {} - G2Element Sign(const PrivateKey &seckey, const vector &message) override; + G2Element Sign(const PrivateKey& seckey, const vector& message) + override; G2Element Sign(const PrivateKey& seckey, const Bytes& message) override; // Used for prepending different augMessage - G2Element Sign(const PrivateKey &seckey, - const vector &message, - const G1Element &prepend_pk); + G2Element Sign( + const PrivateKey& seckey, + const vector& message, + const G1Element& prepend_pk); // Used for prepending different augMessage - G2Element Sign(const PrivateKey& seckey, - const Bytes& message, - const G1Element& prepend_pk); - - bool Verify(const vector &pubkey, - const vector &message, - const vector &signature) override; - - bool Verify(const Bytes& pubkey, - const Bytes& message, - const Bytes& signature) override; - - bool Verify(const G1Element &pubkey, - const vector &message, - const G2Element &signature) override; - - bool Verify(const G1Element& pubkey, - const Bytes& message, - const G2Element& signature) override; - - bool AggregateVerify(const vector> &pubkeys, - const vector> &messages, - const vector &signature) override; - - bool AggregateVerify(const vector& pubkeys, - const vector& messages, - const Bytes& signature) override; - - bool AggregateVerify(const vector &pubkeys, - const vector> &messages, - const G2Element &signature) override; - - bool AggregateVerify(const vector& pubkeys, - const vector& messages, - const G2Element& signature) override; + G2Element Sign( + const PrivateKey& seckey, + const Bytes& message, + const G1Element& prepend_pk); + + bool Verify( + const vector& pubkey, + const vector& message, + const vector& signature) override; + + bool Verify( + const Bytes& pubkey, + const Bytes& message, + const Bytes& signature) override; + + bool Verify( + const G1Element& pubkey, + const vector& message, + const G2Element& signature) override; + + bool Verify( + const G1Element& pubkey, + const Bytes& message, + const G2Element& signature) override; + + bool AggregateVerify( + const vector>& pubkeys, + const vector>& messages, + const vector& signature) override; + + bool AggregateVerify( + const vector& pubkeys, + const vector& messages, + const Bytes& signature) override; + + bool AggregateVerify( + const vector& pubkeys, + const vector>& messages, + const G2Element& signature) override; + + bool AggregateVerify( + const vector& pubkeys, + const vector& messages, + const G2Element& signature) override; }; class PopSchemeMPL final : public CoreMPL { - public: static const std::string CIPHERSUITE_ID; static const std::string POP_CIPHERSUITE_ID; PopSchemeMPL() : CoreMPL(PopSchemeMPL::CIPHERSUITE_ID) {} - G2Element PopProve(const PrivateKey &seckey); + G2Element PopProve(const PrivateKey& seckey); - bool PopVerify(const G1Element &pubkey, const G2Element &signature_proof); + bool PopVerify(const G1Element& pubkey, const G2Element& signature_proof); - bool PopVerify(const vector &pubkey, const vector &proof); + bool PopVerify(const vector& pubkey, const vector& proof); bool PopVerify(const Bytes& pubkey, const Bytes& proof); - bool FastAggregateVerify(const vector &pubkeys, - const vector &message, - const G2Element &signature); - - bool FastAggregateVerify(const vector& pubkeys, - const Bytes& message, - const G2Element& signature); - - bool FastAggregateVerify(const vector> &pubkeys, - const vector &message, - const vector &signature); - - bool FastAggregateVerify(const vector& pubkeys, - const Bytes& message, - const Bytes& signature); + bool FastAggregateVerify( + const vector& pubkeys, + const vector& message, + const G2Element& signature); + + bool FastAggregateVerify( + const vector& pubkeys, + const Bytes& message, + const G2Element& signature); + + bool FastAggregateVerify( + const vector>& pubkeys, + const vector& message, + const vector& signature); + + bool FastAggregateVerify( + const vector& pubkeys, + const Bytes& message, + const Bytes& signature); }; /** diff --git a/src/dashbls/include/dashbls/test-utils.hpp b/src/dashbls/include/dashbls/test-utils.hpp index 154079ff4a99..237940c87c1c 100644 --- a/src/dashbls/include/dashbls/test-utils.hpp +++ b/src/dashbls/include/dashbls/test-utils.hpp @@ -47,10 +47,10 @@ void endStopwatch(string testName, std::vector getRandomSeed() { uint8_t buf[32]; - bn_t r; - bn_new(r); - bn_rand(r, RLC_POS, 256); - bn_write_bin(buf, 32, r); + + for (int i = 0; i < 32; i++) + buf[i] = rand (); + std::vector ret(buf, buf + 32); return ret; } diff --git a/src/dashbls/include/dashbls/util.hpp b/src/dashbls/include/dashbls/util.hpp index 37fd8547a983..7fb9758a78bf 100644 --- a/src/dashbls/include/dashbls/util.hpp +++ b/src/dashbls/include/dashbls/util.hpp @@ -19,9 +19,14 @@ #include #include #include +#include #include #include +extern "C" { +#include "blst.h" +} + namespace bls { class BLS; @@ -60,9 +65,41 @@ class Util { public: static void Hash256(uint8_t* output, const uint8_t* message, size_t messageLen) { - md_map_sh256(output, message, messageLen); + blst_sha256(output, message, messageLen); + } + +static void md_hmac(uint8_t *mac, const uint8_t *in, int in_len, const uint8_t *key, + int key_len) { + constexpr int block_size = 64; + constexpr int md_len = 32; + uint8_t opad[block_size + md_len]; + uint8_t *ipad = (uint8_t *)malloc(block_size + in_len); + uint8_t _key[block_size]; + + if (ipad == NULL) + throw std::runtime_error("out of memory"); + + if (key_len > block_size) { + Hash256(_key, key, key_len); + key = _key; + key_len = md_len; } + memcpy(_key, key, key_len); + memset(_key + key_len, 0, block_size - key_len); + key = _key; + + for (int i = 0; i < block_size; i++) { + opad[i] = 0x5C ^ key[i]; + ipad[i] = 0x36 ^ key[i]; + } + memcpy(ipad + block_size, in, in_len); + Hash256(opad + block_size, ipad, block_size + in_len); + Hash256(mac, opad, block_size + md_len); + + free(ipad); +} + static std::string HexStr(const uint8_t* data, size_t len) { std::stringstream s; s << std::hex; diff --git a/src/dashbls/js-bindings/CMakeLists.txt b/src/dashbls/js-bindings/CMakeLists.txt index f053eb2ea05e..86660a01a011 100644 --- a/src/dashbls/js-bindings/CMakeLists.txt +++ b/src/dashbls/js-bindings/CMakeLists.txt @@ -1,12 +1,10 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.14.0 FATAL_ERROR) +CMAKE_MINIMUM_REQUIRED(VERSION 3.18.0 FATAL_ERROR) set(CMAKE_CXX_STANDARD 17) include_directories( ${INCLUDE_DIRECTORIES} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../include - ${CMAKE_CURRENT_SOURCE_DIR}/../depends/relic/include - ${CMAKE_CURRENT_BINARY_DIR}/../depends/relic/include ${CMAKE_CURRENT_SOURCE_DIR}/../depends/catch2/include ) diff --git a/src/dashbls/js-bindings/blsjs.d.ts b/src/dashbls/js-bindings/blsjs.d.ts index 95cb05962ad1..556a2a8edaaf 100644 --- a/src/dashbls/js-bindings/blsjs.d.ts +++ b/src/dashbls/js-bindings/blsjs.d.ts @@ -48,7 +48,6 @@ export declare class G1Element { deepcopy(): G1Element; getFingerprint(): number; add(el: G1Element): G1Element; - mul(bn: Bignum): G1Element; equalTo(el: G1Element): boolean; delete(): void; } @@ -63,7 +62,6 @@ export declare class G2Element { negate(): G2Element; deepcopy(): G2Element; add(el: G2Element): G2Element; - mul(bn: Bignum): G2Element; equalTo(el: G2Element): boolean; delete(): void; } @@ -82,12 +80,6 @@ export declare class PrivateKey { delete(): void; } -export declare class Bignum { - static fromString(s: string, radix: number): Bignum; - toString(radix: number): string; - delete(): void; -} - export declare class Util { static hash256(msg: Uint8Array): Uint8Array; static hexStr(msg: Uint8Array): string; @@ -100,7 +92,6 @@ export interface ModuleInstance { G1Element: typeof G1Element; G2Element: typeof G2Element; PrivateKey: typeof PrivateKey; - Bignum: typeof Bignum; Util: typeof Util; } diff --git a/src/dashbls/js-bindings/helpers.cpp b/src/dashbls/js-bindings/helpers.cpp index e58f5e4909f2..41a92a0a2e41 100644 --- a/src/dashbls/js-bindings/helpers.cpp +++ b/src/dashbls/js-bindings/helpers.cpp @@ -26,12 +26,6 @@ namespace helpers { return buffer; } - val toUint8Array(bn_t bn) { - std::vector vec = toVector(bn); - val buffer = toUint8Array(vec); - return buffer; - } - std::vector toVector(uint8_t *pointer, size_t data_size) { std::vector data; data.reserve(data_size); @@ -48,13 +42,6 @@ namespace helpers { return vec; } - std::vector toVector(bn_t bn) { - uint8_t buf[bn_size_bin(bn)]; - bn_write_bin(buf, bn_size_bin(bn), bn); - std::vector vec = helpers::toVector(buf, bn_size_bin(bn)); - return vec; - } - std::vector> jsBuffersArrayToVector(val buffersArray) { auto l = buffersArray["length"].as(); std::vector> vec; @@ -64,20 +51,6 @@ namespace helpers { return vec; } - std::vector jsBuffersArrayToBnVector(val buffersArray) { - auto l = buffersArray["length"].as(); - std::vector vec; - for (unsigned i = 0; i < l; ++i) { - bn_t data; - bn_new(data); - std::vector bnVec = toVector(buffersArray[i]); - bn_read_bin(data, bnVec.data(), static_cast(bnVec.size())); - bn_t *point = &data; - vec.push_back(point); - } - return vec; - } - val byteArraysVectorToJsBuffersArray(std::vector arraysVector, size_t element_size) { auto vecSize = arraysVector.size(); std::vector valVector; diff --git a/src/dashbls/js-bindings/helpers.h b/src/dashbls/js-bindings/helpers.h index 031df07043dc..faf2976e3e31 100644 --- a/src/dashbls/js-bindings/helpers.h +++ b/src/dashbls/js-bindings/helpers.h @@ -18,9 +18,6 @@ #include #include #include -extern "C" { -#include -} #include using namespace emscripten; @@ -31,14 +28,10 @@ namespace helpers { val toUint8Array(std::vector vec); - val toUint8Array(bn_t bn); - std::vector toVector(uint8_t *pointer, size_t data_size); std::vector toVector(val jsBuffer); - std::vector toVector(bn_t bn); - template inline std::vector toVectorFromJSArray(val jsArray) { auto l = jsArray["length"].as(); @@ -62,8 +55,6 @@ namespace helpers { std::vector> jsBuffersArrayToVector(val buffersArray); - std::vector jsBuffersArrayToBnVector(val buffersArray); - val byteArraysVectorToJsBuffersArray(std::vector arraysVector, size_t element_size); } // namespace helpers diff --git a/src/dashbls/js-bindings/jsbindings.cpp b/src/dashbls/js-bindings/jsbindings.cpp index 81daa4abc74e..6e9d45f1160b 100644 --- a/src/dashbls/js-bindings/jsbindings.cpp +++ b/src/dashbls/js-bindings/jsbindings.cpp @@ -70,7 +70,6 @@ EMSCRIPTEN_BINDINGS(blsjs) { .function("deepcopy", &G1ElementWrapper::Deepcopy) .function("getFingerprint", &G1ElementWrapper::GetFingerprint) .function("add", &G1ElementWrapper::Add) - .function("mul", &G1ElementWrapper::Mul) .function("equalTo", &G1ElementWrapper::EqualTo); class_("G2Element") @@ -84,7 +83,6 @@ EMSCRIPTEN_BINDINGS(blsjs) { .function("negate", &G2ElementWrapper::Negate) .function("deepcopy", &G2ElementWrapper::Deepcopy) .function("add", &G2ElementWrapper::Add) - .function("mul", &G2ElementWrapper::Mul) .function("equalTo", &G2ElementWrapper::EqualTo); class_("PrivateKey") @@ -99,10 +97,6 @@ EMSCRIPTEN_BINDINGS(blsjs) { .function("mulG2", &PrivateKeyWrapper::MulG2) .function("equalTo", &PrivateKeyWrapper::EqualTo); - class_("Bignum") - .class_function("fromString", &BignumWrapper::FromString) - .function("toString", &BignumWrapper::ToString); - class_("Util") .class_function("hash256", &UtilWrapper::Hash256) .class_function("hexStr", &UtilWrapper::HexStr); diff --git a/src/dashbls/js-bindings/tests/test.js b/src/dashbls/js-bindings/tests/test.js index 34671d6546b7..7c1455932f4f 100644 --- a/src/dashbls/js-bindings/tests/test.js +++ b/src/dashbls/js-bindings/tests/test.js @@ -22,7 +22,6 @@ blsjs().then((blsjs) => { const modules = [ 'AugSchemeMPL', 'BasicSchemeMPL', - "Bignum", 'G1Element', 'G2Element', 'PopSchemeMPL', @@ -42,7 +41,6 @@ blsjs().then((blsjs) => { const { AugSchemeMPL, BasicSchemeMPL, - Bignum, G1Element, G2Element, PopSchemeMPL, @@ -380,17 +378,11 @@ blsjs().then((blsjs) => { assert(AugSchemeMPL.aggregateVerify([], [], new G2Element())); } - function testBignum() { - const mersenne = Bignum.fromString('162259276829213363391578010288127', 10); - assert(mersenne.toString(16).toLowerCase() == '7ffffffffffffffffffffffffff'); - } - testSchemes(); testVectorsInvalid(); testVectorsValid(); testReadme(); testAggregateVerifyZeroItems(); - testBignum(); }).then(function() { console.log("\nAll tests passed."); }); diff --git a/src/dashbls/js-bindings/wrappers/BignumWrapper.cpp b/src/dashbls/js-bindings/wrappers/BignumWrapper.cpp deleted file mode 100644 index 26fea069a0ff..000000000000 --- a/src/dashbls/js-bindings/wrappers/BignumWrapper.cpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2020 Chia Network Inc - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include "BignumWrapper.h" - -namespace js_wrappers { -Bignum::Bignum() { - bn_make(&content, 1); -} - -Bignum::~Bignum() { - bn_clean(&content); -} - -Bignum::Bignum(const Bignum &other) { - bn_copy(&content, &other.content); -} - -bn_st *Bignum::operator &() { return &content; } - -BignumWrapper::BignumWrapper(const Bignum &bn) : JSWrapper(bn) {} - -BignumWrapper BignumWrapper::FromString(const std::string &s, int radix) { - Bignum result; - bn_read_str(&result, s.c_str(), s.size(), radix); - return BignumWrapper(result); -} - -std::string BignumWrapper::ToString(int radix) { - auto wrapper = GetWrappedInstance(); - int strsize = bn_size_str(&wrapper, radix); - std::vector strholder(strsize); - bn_write_str(&strholder[0], strsize, &wrapper, radix); - return std::string(&strholder[0], strsize - 1); -} -} // namespace js_wrappers diff --git a/src/dashbls/js-bindings/wrappers/BignumWrapper.h b/src/dashbls/js-bindings/wrappers/BignumWrapper.h deleted file mode 100644 index 337d52702506..000000000000 --- a/src/dashbls/js-bindings/wrappers/BignumWrapper.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2020 Chia Network Inc - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef JS_BINDINGS_WRAPPERS_BIGNUMWRAPPER_H_ -#define JS_BINDINGS_WRAPPERS_BIGNUMWRAPPER_H_ - -#include -#include "JSWrapper.h" - -namespace js_wrappers { -class Bignum { -public: - Bignum(); - ~Bignum(); - Bignum(const Bignum &other); - - bn_st *operator &(); - -private: - bn_st content; -}; - -class BignumWrapper : public JSWrapper { -public: - explicit BignumWrapper(const Bignum &bn); - static BignumWrapper FromString(const std::string &s, int radix); - std::string ToString(int radix); -}; -} // namespace js_wrappers - -#endif // JS_BINDINGS_WRAPPERS_SIGNATUREWRAPPER_H_ diff --git a/src/dashbls/js-bindings/wrappers/G1ElementWrapper.cpp b/src/dashbls/js-bindings/wrappers/G1ElementWrapper.cpp index 0d630514886b..f623a5062173 100644 --- a/src/dashbls/js-bindings/wrappers/G1ElementWrapper.cpp +++ b/src/dashbls/js-bindings/wrappers/G1ElementWrapper.cpp @@ -44,16 +44,6 @@ G1ElementWrapper G1ElementWrapper::Add(const G1ElementWrapper &other) { return G1ElementWrapper(GetWrappedInstance() + other.GetWrappedInstance()); } -G1ElementWrapper G1ElementWrapper::Mul(const BignumWrapper &other) { - bn_t factor; - // Since the type of bn_t is bn_st[0], we can do this dance to make a temporary - // copy of the struct itself to hand to G1ElementWrapper's multiply. The - // type was clearly intended to by by-value in argument lists (degrade to ptr) - // but value semantics in C++ complicates matters. - factor[0] = *(&other.GetWrappedInstance()); - return G1ElementWrapper(GetWrappedInstance() * factor); -} - bool G1ElementWrapper::EqualTo(const G1ElementWrapper &others) { return GetWrappedInstance() == others.GetWrappedInstance(); } diff --git a/src/dashbls/js-bindings/wrappers/G1ElementWrapper.h b/src/dashbls/js-bindings/wrappers/G1ElementWrapper.h index 1b5a0f8282a7..e7185c5237a9 100644 --- a/src/dashbls/js-bindings/wrappers/G1ElementWrapper.h +++ b/src/dashbls/js-bindings/wrappers/G1ElementWrapper.h @@ -17,7 +17,6 @@ #include #include "JSWrapper.h" -#include "BignumWrapper.h" namespace js_wrappers { class G1ElementWrapper : public JSWrapper { @@ -38,8 +37,6 @@ class G1ElementWrapper : public JSWrapper { G1ElementWrapper Add(const G1ElementWrapper &other); - G1ElementWrapper Mul(const BignumWrapper &other); - bool EqualTo(const G1ElementWrapper &others); G1ElementWrapper Negate(); diff --git a/src/dashbls/js-bindings/wrappers/G2ElementWrapper.cpp b/src/dashbls/js-bindings/wrappers/G2ElementWrapper.cpp index 980a7dd8e706..de4a208f5b96 100644 --- a/src/dashbls/js-bindings/wrappers/G2ElementWrapper.cpp +++ b/src/dashbls/js-bindings/wrappers/G2ElementWrapper.cpp @@ -67,16 +67,6 @@ G2ElementWrapper G2ElementWrapper::Add(const G2ElementWrapper& other) { return G2ElementWrapper(GetWrappedInstance() + other.GetWrappedInstance()); } -G2ElementWrapper G2ElementWrapper::Mul(const BignumWrapper& other) { - bn_t factor; - // Since the type of bn_t is bn_st[0], we can do this dance to make a - // temporary copy of the struct itself to hand to G2ElementWrapper's - // multiply. The type was clearly intended to by by-value in argument lists - // (degrade to ptr) but value semantics in C++ complicates matters. - factor[0] = *(&other.GetWrappedInstance()); - return G2ElementWrapper(GetWrappedInstance() * factor); -} - bool G2ElementWrapper::EqualTo(const G2ElementWrapper& others) { return GetWrappedInstance() == others.GetWrappedInstance(); } diff --git a/src/dashbls/js-bindings/wrappers/G2ElementWrapper.h b/src/dashbls/js-bindings/wrappers/G2ElementWrapper.h index 46f23f6ca826..829affd2ab79 100644 --- a/src/dashbls/js-bindings/wrappers/G2ElementWrapper.h +++ b/src/dashbls/js-bindings/wrappers/G2ElementWrapper.h @@ -17,7 +17,6 @@ #include #include "JSWrapper.h" -#include "BignumWrapper.h" namespace js_wrappers { class G2ElementWrapper : public JSWrapper { @@ -46,8 +45,6 @@ class G2ElementWrapper : public JSWrapper { G2ElementWrapper Add(const G2ElementWrapper &other); - G2ElementWrapper Mul(const BignumWrapper &other); - bool EqualTo(const G2ElementWrapper &others); }; } // namespace js_wrappers diff --git a/src/dashbls/lgtm.yml b/src/dashbls/lgtm.yml deleted file mode 100644 index e8d3f8a2045f..000000000000 --- a/src/dashbls/lgtm.yml +++ /dev/null @@ -1,12 +0,0 @@ -extraction: - cpp: - after_prepare: - - "mkdir custom_cmake" - - "wget --quiet -O - \"https://cmake.org/files/v3.16/cmake-3.16.3-Linux-x86_64.tar.gz\"\ - \ | tar --strip-components=1 -xz -C custom_cmake" - - "export PATH=$(pwd)/custom_cmake/bin:${PATH}" - - "cd $LGTM_SRC/" - - "export CMAKE_INCLUDE_PATH=$LGTM_SRC/include:${CMAKE_INCLUDE_PATH}" - - "export CMAKE_LIBRARY_PATH=$LGTM_SRC/lib:${CMAKE_LIBRARY_PATH}" - - "mkdir $LGTM_SRC/_lgtm_build_dir" - - "cd $LGTM_SRC/_lgtm_build_dir" diff --git a/src/dashbls/mypi.ini b/src/dashbls/mypi.ini deleted file mode 100644 index 976ba0294638..000000000000 --- a/src/dashbls/mypi.ini +++ /dev/null @@ -1,2 +0,0 @@ -[mypy] -ignore_missing_imports = True diff --git a/src/dashbls/pyproject.toml b/src/dashbls/pyproject.toml index c320f0e05ccc..c9b5e5526393 100644 --- a/src/dashbls/pyproject.toml +++ b/src/dashbls/pyproject.toml @@ -1,6 +1,89 @@ +[project] +name = "dashbls" +description = "Python 3.x binds for Dash's bls-signatures" +authors = [{ name = "Dash Core Developers" }] +keywords = ["bls", "signatures", "bls12-381", "dash", "cryptography"] +license = "Apache-2.0" +license-files = ["LICENSE", "NOTICE"] +readme = "README.md" +requires-python = ">=3.10" +dynamic = ["version"] + +[project.urls] +Homepage = "https://github.com/dashpay/bls-signatures" +Source = "https://github.com/dashpay/bls-signatures" +Issues = "https://github.com/dashpay/bls-signatures/issues" + +[project.optional-dependencies] +dev = [ + "ruff>=0.9", + "pytest>=8.1", + "pytest-benchmark>=5.1", +] + [build-system] -requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.5.0", "pybind11"] +requires = [ + "cmake>=3.18", + "pybind11>=2.13.6", + "setuptools_scm>=8", + "setuptools>=77", +] build-backend = "setuptools.build_meta" [tool.setuptools_scm] local_scheme = "no-local-version" + +[tool.cibuildwheel] +build-frontend = "uv" +skip = [ + "*-musllinux_*", + "cp*t-*", + "pp*", +] +test-command = "pytest --import-mode=importlib {project}/binds/python/test_unit.py" +test-requires = [ + "pytest>=8.1", + "pytest-benchmark>=5.1", +] + +[tool.cibuildwheel.linux] +before-all = "dnf -y install gmp-devel" +manylinux-aarch64-image = "manylinux_2_28" +manylinux-x86_64-image = "manylinux_2_28" + +[tool.cibuildwheel.macos] +environment = { CMAKE_ARGS = "-DARITH=easy" } + +[tool.pytest.ini_options] +testpaths = ["binds/python"] +addopts = "--benchmark-skip" + +[tool.ruff] +indent-width = 4 +line-length = 100 +target-version = "py310" + +[tool.ruff.lint] +select = [ + "ANN", # flake8-annotations + "B", # flake8-bugbear + "BLE", # flake8-blind-except + "E", # pycodestyle errors + "F", # pyflakes + "I", # isort + "RUF", # ruff + "S", # flake8-bandit + "TC", # flake8-type-checking + "UP", # pyupgrade + "W", # pycodestyle warnings +] + +[tool.ruff.lint.per-file-ignores] +"binds/python/test*.py" = ["S101"] +"binds/python/samples/*.py" = ["S101"] + +[tool.ruff.format] +indent-style = "space" +line-ending = "lf" +quote-style = "double" +skip-magic-trailing-comma = false diff --git a/src/dashbls/python-bindings/CMakeLists.txt b/src/dashbls/python-bindings/CMakeLists.txt deleted file mode 100644 index 2726399ed8cb..000000000000 --- a/src/dashbls/python-bindings/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -include(FetchContent) - -FetchContent_Declare( - pybind11 - GIT_REPOSITORY https://github.com/pybind/pybind11.git - GIT_TAG v2.13.6 -) -FetchContent_MakeAvailable(pybind11) - -include_directories( - ${INCLUDE_DIRECTORIES} - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/../include -) - -pybind11_add_module(blspy ${CMAKE_CURRENT_SOURCE_DIR}/pythonbindings.cpp) -target_link_libraries(blspy PRIVATE dashbls) diff --git a/src/dashbls/python-bindings/README.md b/src/dashbls/python-bindings/README.md deleted file mode 100644 index 0de31c9a8a03..000000000000 --- a/src/dashbls/python-bindings/README.md +++ /dev/null @@ -1,149 +0,0 @@ -# Python bindings - -Use the full power and efficiency of the C++ bls library, but in a few lines of python! - -## Install - -```bash -pip3 install blspy - -``` - -Alternatively, to install from source, run the following, in the project root directory: - -```bash -pip3 install . -``` - -Cmake, a c++ compiler, and a recent version of pip3 (v18) are required for source install. -GMP(speed) is an optional dependency. -Public keys are G1Elements, and signatures are G2Elements. - -Then, to use: - -## Import the library - -```python -from blspy import (PrivateKey, Util, AugSchemeMPL, PopSchemeMPL, - G1Element, G2Element) -``` - -## Creating keys and signatures - -```python -# Example seed, used to generate private key. Always use -# a secure RNG with sufficient entropy to generate a seed (at least 32 bytes). -seed: bytes = bytes([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]) -sk: PrivateKey = AugSchemeMPL.key_gen(seed) -pk: G1Element = sk.get_g1() - -message: bytes = bytes([1, 2, 3, 4, 5]) -signature: G2Element = AugSchemeMPL.sign(sk, message) - -# Verify the signature -ok: bool = AugSchemeMPL.verify(pk, message, signature) -assert ok -``` - -## Serializing keys and signatures to bytes - -```python -sk_bytes: bytes = bytes(sk) # 32 bytes -pk_bytes: bytes = bytes(pk) # 48 bytes -signature_bytes: bytes = bytes(signature) # 96 bytes - -print(sk_bytes.hex(), pk_bytes.hex(), signature_bytes.hex()) -``` - -## Loading keys and signatures from bytes - -```python -sk = PrivateKey.from_bytes(sk_bytes) -pk = G1Element.from_bytes(pk_bytes) -signature = G2Element.from_bytes(signature_bytes) -``` - -## Create aggregate signatures - -```python -# Generate some more private keys -seed = bytes([1]) + seed[1:] -sk1: PrivateKey = AugSchemeMPL.key_gen(seed) -seed = bytes([2]) + seed[1:] -sk2: PrivateKey = AugSchemeMPL.key_gen(seed) -message2: bytes = bytes([1, 2, 3, 4, 5, 6, 7]) - -# Generate first sig -pk1: G1Element = sk1.get_g1() -sig1: G2Element = AugSchemeMPL.sign(sk1, message) - -# Generate second sig -pk2: G1Element = sk2.get_g1() -sig2: G2Element = AugSchemeMPL.sign(sk2, message2) - -# Signatures can be non-interactively combined by anyone -agg_sig: G2Element = AugSchemeMPL.aggregate([sig1, sig2]) - -ok = AugSchemeMPL.aggregate_verify([pk1, pk2], [message, message2], agg_sig) -``` - -## Arbitrary trees of aggregates - -```python -seed = bytes([3]) + seed[1:] -sk3: PrivateKey = AugSchemeMPL.key_gen(seed) -pk3: G1Element = sk3.get_g1() -message3: bytes = bytes([100, 2, 254, 88, 90, 45, 23]) -sig3: G2Element = AugSchemeMPL.sign(sk3, message3) - -agg_sig_final: G2Element = AugSchemeMPL.aggregate([agg_sig, sig3]) -ok = AugSchemeMPL.aggregate_verify([pk1, pk2, pk3], [message, message2, message3], agg_sig_final) -``` - -## Very fast verification with Proof of Possession scheme - -```python -# 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. -pop_sig1: G2Element = PopSchemeMPL.sign(sk1, message) -pop_sig2: G2Element = PopSchemeMPL.sign(sk2, message) -pop_sig3: G2Element = PopSchemeMPL.sign(sk3, message) -pop1: G2Element = PopSchemeMPL.pop_prove(sk1) -pop2: G2Element = PopSchemeMPL.pop_prove(sk2) -pop3: G2Element = PopSchemeMPL.pop_prove(sk3) - -ok = PopSchemeMPL.pop_verify(pk1, pop1) -ok = PopSchemeMPL.pop_verify(pk2, pop2) -ok = PopSchemeMPL.pop_verify(pk3, pop3) - -pop_sig_agg: G2Element = PopSchemeMPL.aggregate([pop_sig1, pop_sig2, pop_sig3]) - -ok = PopSchemeMPL.fast_aggregate_verify([pk1, pk2, pk3], message, pop_sig_agg) - -# Aggregate public key, indistinguishable from a single public key -pop_agg_pk: G1Element = pk1 + pk2 + pk3 -ok = PopSchemeMPL.verify(pop_agg_pk, message, pop_sig_agg) - -# Aggregate private keys -pop_agg_sk: PrivateKey = PrivateKey.aggregate([sk1, sk2, sk3]) -ok = PopSchemeMPL.sign(pop_agg_sk, message) == pop_sig_agg -``` - -## HD keys using [EIP-2333](https://github.com/ethereum/EIPs/pull/2333) - -```python -master_sk: PrivateKey = AugSchemeMPL.key_gen(seed) -child: PrivateKey = AugSchemeMPL.derive_child_sk(master_sk, 152) -grandchild: PrivateKey = AugSchemeMPL.derive_child_sk(child, 952) - -master_pk: G1Element = master_sk.get_g1() -child_u: PrivateKey = AugSchemeMPL.derive_child_sk_unhardened(master_sk, 22) -grandchild_u: PrivateKey = AugSchemeMPL.derive_child_sk_unhardened(child_u, 0) - -child_u_pk: G1Element = AugSchemeMPL.derive_child_pk_unhardened(master_pk, 22) -grandchild_u_pk: G1Element = AugSchemeMPL.derive_child_pk_unhardened(child_u_pk, 0) - -ok = (grandchild_u_pk == grandchild_u.get_g1()) -``` diff --git a/src/dashbls/python-bindings/benchmark.py b/src/dashbls/python-bindings/benchmark.py deleted file mode 100644 index 51feebd05e6e..000000000000 --- a/src/dashbls/python-bindings/benchmark.py +++ /dev/null @@ -1,66 +0,0 @@ -# flake8: noqa: E501 -import time -import secrets - -from blspy import ( - AugSchemeMPL, - G1Element, - G2Element, - PrivateKey, -) - -def startStopwatch(): - return time.perf_counter() - -def endStopwatch(test_name, start, numIters): - end_time = time.perf_counter() - - duration = end_time - start - - print("\n%s\nTotal: %d runs in %0.1f ms\nAvg: %f" - % (test_name, numIters, duration * 1000, duration * 1000 / numIters)) - -def batch_verification(): - - numIters = 100000 - sig_bytes = [] - pk_bytes = [] - ms = [] - - for i in range(numIters): - message = b"%d" % i - sk: PrivateKey = AugSchemeMPL.key_gen(secrets.token_bytes(32)) - pk: G1Element = sk.get_g1() - sig: G2Element = AugSchemeMPL.sign(sk, message) - - sig_bytes.append(bytes(sig)) - pk_bytes.append(bytes(pk)) - ms.append(message) - - pks = [] - - start = startStopwatch(); - for pk in pk_bytes: - pks.append(G1Element.from_bytes(pk)) - - endStopwatch("Public key validation", start, numIters); - - sigs = [] - - start = startStopwatch() - for sig in sig_bytes: - sigs.append(G2Element.from_bytes(sig)) - endStopwatch("Signature validation", start, numIters); - - start = startStopwatch() - aggSig = AugSchemeMPL.aggregate(sigs) - endStopwatch("Aggregation", start, numIters); - - start = startStopwatch() - ok = AugSchemeMPL.aggregate_verify(pks, ms, aggSig); - endStopwatch("Batch verification", start, numIters); - if not ok: - print("aggregate_verification failed!") - sys.exit(1) - -batch_verification() diff --git a/src/dashbls/python-bindings/test.py b/src/dashbls/python-bindings/test.py deleted file mode 100644 index 971d878591bb..000000000000 --- a/src/dashbls/python-bindings/test.py +++ /dev/null @@ -1,393 +0,0 @@ -# flake8: noqa: E501 -import binascii -import time -from copy import deepcopy - -from blspy import ( - AugSchemeMPL, - BasicSchemeMPL, - G1Element, - G2Element, - PopSchemeMPL, - PrivateKey, - Util, -) - - -def test_schemes(): - # fmt: off - seed = bytes([ - 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 - ]) - # fmt: on - msg = bytes([100, 2, 254, 88, 90, 45, 23]) - msg2 = bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) - sk = BasicSchemeMPL.key_gen(seed) - pk = sk.get_g1() - - assert sk == PrivateKey.from_bytes(bytes(sk)) - assert pk == G1Element.from_bytes(bytes(pk)) - - for Scheme in (BasicSchemeMPL, AugSchemeMPL, PopSchemeMPL): - sig = Scheme.sign(sk, msg) - assert sig == G2Element.from_bytes(bytes(sig)) - assert Scheme.verify(pk, msg, sig) - - seed = bytes([1]) + seed[1:] - sk1 = BasicSchemeMPL.key_gen(seed) - pk1 = sk1.get_g1() - seed = bytes([2]) + seed[1:] - sk2 = BasicSchemeMPL.key_gen(seed) - pk2 = sk2.get_g1() - - for Scheme in (BasicSchemeMPL, AugSchemeMPL, PopSchemeMPL): - # Aggregate same message - agg_pk = pk1 + pk2 - if Scheme is AugSchemeMPL: - sig1 = Scheme.sign(sk1, msg, agg_pk) - sig2 = Scheme.sign(sk2, msg, agg_pk) - else: - sig1 = Scheme.sign(sk1, msg) - sig2 = Scheme.sign(sk2, msg) - agg_sig = Scheme.aggregate([sig1, sig2]) - - assert Scheme.verify(agg_pk, msg, agg_sig) - - # Aggregate different message - sig1 = Scheme.sign(sk1, msg) - sig2 = Scheme.sign(sk2, msg2) - agg_sig = Scheme.aggregate([sig1, sig2]) - assert Scheme.aggregate_verify([pk1, pk2], [msg, msg2], agg_sig) - - # Manual pairing calculation and verification - if Scheme is AugSchemeMPL: - # AugSchemeMPL requires prepending the public key to message - aug_msg1 = bytes(pk1) + msg - aug_msg2 = bytes(pk2) + msg2 - else: - aug_msg1 = msg - aug_msg2 = msg2 - pair1 = pk1.pair(Scheme.g2_from_message(aug_msg1)) - pair2 = pk2.pair(Scheme.g2_from_message(aug_msg2)) - pair = pair1 * pair2 - agg_sig_pair = G1Element.generator().pair(agg_sig) - assert pair == agg_sig_pair - - # HD keys - child = Scheme.derive_child_sk(sk1, 123) - childU = Scheme.derive_child_sk_unhardened(sk1, 123) - childUPk = Scheme.derive_child_pk_unhardened(pk1, 123) - - sig_child = Scheme.sign(child, msg) - assert Scheme.verify(child.get_g1(), msg, sig_child) - - sigU_child = Scheme.sign(childU, msg) - assert Scheme.verify(childUPk, msg, sigU_child) - - -def test_vectors_invalid(): - # Invalid inputs from https://github.com/algorand/bls_sigs_ref/blob/master/python-impl/serdesZ.py - invalid_inputs_1 = [ - # infinity points: too short - "c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - # infinity points: not all zeros - "c00000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000", - # bad tags - "3a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa", - "7a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa", - "fa0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa", - # wrong length for compresed point - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa", - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaaaa", - # invalid x-coord - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa", - # invalid elm of Fp --- equal to p (must be strictly less) - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab", - ] - invalid_inputs_2 = [ - # infinity points: too short - "c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - # infinity points: not all zeros - "c00000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000", - # bad tags - "3a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "7a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "fa0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - # wrong length for compressed point - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - # invalid x-coord - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaa7", - # invalid elm of Fp --- equal to p (must be strictly less) - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab", - ] - - for s in invalid_inputs_1: - bytes_ = binascii.unhexlify(s) - try: - g1 = G1Element(bytes_) - assert False, "Failed to disallow creation of G1 element." - except Exception as e: - pass - - for s in invalid_inputs_2: - bytes_ = binascii.unhexlify(s) - try: - g2 = G2Element(bytes_) - assert False, "Failed to disallow creation of G2 element." - except Exception as e: - pass - - -def test_vectors_valid(): - # The following code was used to generate these vectors - """ - from py_ecc.bls import ( - G2Basic, - G2MessageAugmentation as G2MA, - G2ProofOfPossession as G2Pop, - ) - - secret1 = bytes([1] * 32) - secret2 = bytes([x * 314159 % 256 for x in range(32)]) - sk1 = int.from_bytes(secret1, 'big') - sk2 = int.from_bytes(secret2, 'big') - msg = bytes([3, 1, 4, 1, 5, 9]) - pk1 = G2Basic.SkToPk(sk1) - pk2 = G2Basic.SkToPk(sk2) - - for Scheme in (G2Basic, G2MA, G2Pop): - sig1 = Scheme.Sign(sk1, msg) - sig2 = Scheme.Sign(sk2, msg) - sig_agg = Scheme.Aggregate([sig1, sig2]) - print(sig1) - print(sig2) - print(sig_agg) - """ - - ref_sig1Basic = b"\x96\xba4\xfa\xc3<\x7f\x12\x9d`*\x0b\xc8\xa3\xd4?\x9a\xbc\x01N\xce\xaa\xb75\x91F\xb4\xb1P\xe5{\x80\x86Es\x8f5g\x1e\x9e\x10\xe0\xd8b\xa3\x0c\xabp\x07N\xb5\x83\x1d\x13\xe6\xa5\xb1b\xd0\x1e\xeb\xe6\x87\xd0\x16J\xdb\xd0\xa8d7\n|\"*'h\xd7pM\xa2T\xf1\xbf\x18#f[\xc26\x1f\x9d\xd8\xc0\x0e\x99" - ref_sig2Basic = b'\xa4\x02y\t2\x13\x0fvj\xf1\x1b\xa7\x16Sf\x83\xd8\xc4\xcf\xa5\x19G\xe4\xf9\x08\x1f\xed\xd6\x92\xd6\xdc\x0c\xac[\x90K\xee^\xa6\xe2Ui\xe3m{\xe4\xcaY\x06\x9a\x96\xe3K\x7fp\x07X\xb7\x16\xf9IJ\xaaY\xa9nt\xd1J;U*\x9ak\xc1)\xe7\x17\x19[\x9d`\x06\xfdm\\\xefGh\xc0"\xe0\xf71j\xbf' - ref_sigABasic = b"\x98|\xfd;\xcdb(\x02\x87\x02t\x83\xf2\x9cU$^\xd81\xf5\x1d\xd6\xbd\x99\x9ao\xf1\xa1\xf1\xf1\xf0\xb6Gw\x8b\x01g5\x9cqPUX\xa7n\x15\x8ef\x18\x1e\xe5\x12Y\x05\xa6B$k\x01\xe7\xfa^\xe5=h\xa4\xfe\x9b\xfb)\xa8\xe2f\x01\xf0\xb9\xadW}\xdd\x18\x87js1|!n\xa6\x1fC\x04\x14\xecQ\xc5" - ref_sig1Aug = b'\x81\x80\xf0,\xcbr\xe9"\xb1R\xfc\xed\xbe\x0e\x1d\x19R\x105Opp6X\xe8\xe0\x8c\xbe\xbf\x11\xd4\x97\x0e\xabj\xc3\xcc\xf7\x15\xf3\xfb\x87m\xf9\xa9yz\xbd\x0c\x1a\xf6\x1a\xae\xad\xc9,,\xfe\\\nV\xc1F\xcc\x8c?qQ\xa0s\xcf_\x16\xdf8$g$\xc4\xae\xd7?\xf3\x0e\xf5\xda\xa6\xaa\xca\xed\x1a&\xec\xaa3k' - ref_sig2Aug = b'\x99\x11\x1e\xea\xfbA-\xa6\x1eL7\xd3\xe8\x06\xc6\xfdj\xc9\xf3\x87\x0eT\xda\x92"\xbaNIH"\xc5\xb7eg1\xfazdY4\xd0KU\x9e\x92a\xb8b\x01\xbb\xeeW\x05RP\xa4Y\xa2\xda\x10\xe5\x1f\x9c\x1aiA)\x7f\xfc]\x97\nUr6\xd0\xbd\xeb|\xf8\xff\x18\x80\x0b\x08c8q\xa0\xf0\xa7\xeaB\xf4t\x80' - ref_sigAAug = b"\x8c]\x03\xf9\xda\xe7~\x19\xa5\x94Z\x06\xa2\x14\x83n\xdb\x8e\x03\xb8QR]\x84\xb9\xded@\xe6\x8f\xc0\xcas\x03\xee\xed9\r\x86<\x9bU\xa8\xcfmY\x14\n\x01\xb5\x88G\x88\x1e\xb5\xafgsMD\xb2UVF\xc6al9\xab\x88\xd2S)\x9a\xcc\x1e\xb1\xb1\x9d\xdb\x9b\xfc\xbev\xe2\x8a\xdd\xf6q\xd1\x16\xc0R\xbb\x18G" - ref_sig1Pop = b"\x95P\xfbN\x7f~\x8c\xc4\xa9\x0b\xe8V\n\xb5\xa7\x98\xb0\xb20\x00\xb6\xa5J!\x17R\x02\x10\xf9\x86\xf3\xf2\x81\xb3v\xf2Y\xc0\xb7\x80b\xd1\xeb1\x92\xb3\xd9\xbb\x04\x9fY\xec\xc1\xb0:pI\xebf^\r\xf3d\x94\xaeL\xb5\xf1\x13l\xca\xee\xfc\x99X\xcb0\xc33==C\xf0qH\xc3\x86)\x9a{\x1b\xfc\r\xc5\xcf|" - ref_sig2Pop = b"\xa6\x906\xbc\x11\xae^\xfc\xbfa\x80\xaf\xe3\x9a\xdd\xde~'s\x1e\xc4\x02W\xbf\xdc<7\xf1{\x8d\xf6\x83\x06\xa3N\xbd\x10\xe9\xe3*5%7P\xdf\\\x87\xc2\x14/\x82\x07\xe8\xd5eG\x12\xb4\xe5T\xf5\x85\xfbhF\xff8\x04\xe4)\xa9\xf8\xa1\xb4\xc5ku\xd0\x86\x9e\xd6u\x80\xd7\x89\x87\x0b\xab\xe2\xc7\xc8\xa9\xd5\x1e{*" - ref_sigAPop = b"\xa4\xeat+\xcd\xc1U>\x9c\xa4\xe5`\xbe~^ln\xfajd\xdd\xdf\x9c\xa3\xbb(T#=\x85\xa6\xaa\xc1\xb7n\xc7\xd1\x03\xdbN3\x14\x8b\x82\xaf\x99#\xdb\x05\x93Jn\xce\x9aq\x01\xcd\x8a\x9dG\xce'\x97\x80V\xb0\xf5\x90\x00!\x81\x8cEi\x8a\xfd\xd6\xcf\x8ako\x7f\xee\x1f\x0bCqoU\xe4\x13\xd4\xb8z`9" - - secret1 = bytes([1] * 32) - secret2 = bytes([x * 314159 % 256 for x in range(32)]) - sk1 = PrivateKey.from_bytes(secret1) - sk2 = PrivateKey.from_bytes(secret2) - - msg = bytes([3, 1, 4, 1, 5, 9]) - sig1Basic = BasicSchemeMPL.sign(sk1, msg) - sig2Basic = BasicSchemeMPL.sign(sk2, msg) - sigABasic = BasicSchemeMPL.aggregate([sig1Basic, sig2Basic]) - sig1Aug = AugSchemeMPL.sign(sk1, msg) - sig2Aug = AugSchemeMPL.sign(sk2, msg) - sigAAug = AugSchemeMPL.aggregate([sig1Aug, sig2Aug]) - sig1Pop = PopSchemeMPL.sign(sk1, msg) - sig2Pop = PopSchemeMPL.sign(sk2, msg) - sigAPop = PopSchemeMPL.aggregate([sig1Pop, sig2Pop]) - - assert bytes(sig1Basic) == ref_sig1Basic - assert bytes(sig2Basic) == ref_sig2Basic - assert bytes(sigABasic) == ref_sigABasic - assert bytes(sig1Aug) == ref_sig1Aug - assert bytes(sig2Aug) == ref_sig2Aug - assert bytes(sigAAug) == ref_sigAAug - assert bytes(sig1Pop) == ref_sig1Pop - assert bytes(sig2Pop) == ref_sig2Pop - assert bytes(sigAPop) == ref_sigAPop - - -def test_readme(): - seed: bytes = bytes( - [ - 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, - ] - ) - sk: PrivateKey = AugSchemeMPL.key_gen(seed) - pk: G1Element = sk.get_g1() - - message: bytes = bytes([1, 2, 3, 4, 5]) - signature: G2Element = AugSchemeMPL.sign(sk, message) - - ok: bool = AugSchemeMPL.verify(pk, message, signature) - assert ok - - sk_bytes: bytes = bytes(sk) # 32 bytes - pk_bytes: bytes = bytes(pk) # 48 bytes - signature_bytes: bytes = bytes(signature) # 96 bytes - - print(sk_bytes.hex(), pk_bytes.hex(), signature_bytes.hex()) - - sk = PrivateKey.from_bytes(sk_bytes) - pk = G1Element.from_bytes(pk_bytes) - signature = G2Element.from_bytes(signature_bytes) - - seed = bytes([1]) + seed[1:] - sk1: PrivateKey = AugSchemeMPL.key_gen(seed) - seed = bytes([2]) + seed[1:] - sk2: PrivateKey = AugSchemeMPL.key_gen(seed) - message2: bytes = bytes([1, 2, 3, 4, 5, 6, 7]) - - pk1: G1Element = sk1.get_g1() - sig1: G2Element = AugSchemeMPL.sign(sk1, message) - - pk2: G1Element = sk2.get_g1() - sig2: G2Element = AugSchemeMPL.sign(sk2, message2) - - agg_sig: G2Element = AugSchemeMPL.aggregate([sig1, sig2]) - - ok = AugSchemeMPL.aggregate_verify([pk1, pk2], [message, message2], agg_sig) - assert ok - - seed = bytes([3]) + seed[1:] - sk3: PrivateKey = AugSchemeMPL.key_gen(seed) - pk3: G1Element = sk3.get_g1() - message3: bytes = bytes([100, 2, 254, 88, 90, 45, 23]) - sig3: G2Element = AugSchemeMPL.sign(sk3, message3) - - agg_sig_final: G2Element = AugSchemeMPL.aggregate([agg_sig, sig3]) - ok = AugSchemeMPL.aggregate_verify( - [pk1, pk2, pk3], [message, message2, message3], agg_sig_final - ) - assert ok - - pop_sig1: G2Element = PopSchemeMPL.sign(sk1, message) - pop_sig2: G2Element = PopSchemeMPL.sign(sk2, message) - pop_sig3: G2Element = PopSchemeMPL.sign(sk3, message) - pop1: G2Element = PopSchemeMPL.pop_prove(sk1) - pop2: G2Element = PopSchemeMPL.pop_prove(sk2) - pop3: G2Element = PopSchemeMPL.pop_prove(sk3) - - ok = PopSchemeMPL.pop_verify(pk1, pop1) - assert ok - ok = PopSchemeMPL.pop_verify(pk2, pop2) - assert ok - ok = PopSchemeMPL.pop_verify(pk3, pop3) - assert ok - - pop_sig_agg: G2Element = PopSchemeMPL.aggregate([pop_sig1, pop_sig2, pop_sig3]) - - ok = PopSchemeMPL.fast_aggregate_verify([pk1, pk2, pk3], message, pop_sig_agg) - assert ok - - pop_agg_pk: G1Element = pk1 + pk2 + pk3 - ok = PopSchemeMPL.verify(pop_agg_pk, message, pop_sig_agg) - assert ok - - pop_agg_sk: PrivateKey = PrivateKey.aggregate([sk1, sk2, sk3]) - ok = PopSchemeMPL.sign(pop_agg_sk, message) == pop_sig_agg - assert ok - - master_sk: PrivateKey = AugSchemeMPL.key_gen(seed) - child: PrivateKey = AugSchemeMPL.derive_child_sk(master_sk, 152) - grandchild: PrivateKey = AugSchemeMPL.derive_child_sk(child, 952) - - master_pk: G1Element = master_sk.get_g1() - child_u: PrivateKey = AugSchemeMPL.derive_child_sk_unhardened(master_sk, 22) - grandchild_u: PrivateKey = AugSchemeMPL.derive_child_sk_unhardened(child_u, 0) - - child_u_pk: G1Element = AugSchemeMPL.derive_child_pk_unhardened(master_pk, 22) - grandchild_u_pk: G1Element = AugSchemeMPL.derive_child_pk_unhardened(child_u_pk, 0) - - ok = grandchild_u_pk == grandchild_u.get_g1() - assert ok - - -def test_aggregate_verify_zero_items(): - assert AugSchemeMPL.aggregate_verify([], [], G2Element()) - - -def test_invalid_points(): - sk1 = BasicSchemeMPL.key_gen(b"1" *32) - good_point = sk1.get_g1() - good_point_bytes = bytes(good_point) - start = time.time() - for i in range(2000): - gp1 = G1Element.from_bytes(good_point_bytes) - print(f"from_bytes avg: {(time.time() - start) }") - - start = time.time() - for i in range(2000): - gp2 = G1Element.from_bytes_unchecked(good_point_bytes) - print(f"from_bytes_unchecked avg: {(time.time() - start) }") - assert gp1 == gp2 - - bad_point_hex: str = "8d5d0fb73b9c92df4eab4216e48c3e358578b4cc30f82c268bd6fef3bd34b558628daf1afef798d4c3b0fcd8b28c8973"; - try: - G1Element.from_bytes(bytes.fromhex(bad_point_hex)) - assert False - except ValueError: - pass - - p: G1Element = G1Element.from_bytes_unchecked(bytes.fromhex(bad_point_hex)) - - bad_g2_point_hex = "8f2886c94eaeac335c8414cbf14c16681b225380cfee3293becc4531d5b415984b4ea4050d9ecda11fbc21c60627e9d212dfcb17d2b5ae399aa3fbcb099e05baa496b852ad976fb633cc6766b02fca4da549dc063908463b2906ad64e8b310ad" - - try: - G2Element.from_bytes(bytes.fromhex(bad_g2_point_hex)) - assert False - except ValueError: - pass - - - -test_schemes() -test_vectors_invalid() -test_vectors_valid() -test_readme() -test_aggregate_verify_zero_items() -test_invalid_points() - -print("\nAll tests passed.") - -""" -Copyright 2020 Chia Network Inc -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" diff --git a/src/dashbls/python-impl/README.md b/src/dashbls/python-impl/README.md deleted file mode 100644 index 4ee657903a2e..000000000000 --- a/src/dashbls/python-impl/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# BLS12-381 and Signatures in python - -Implements the BLS12 curve and optimal ate pairing, as well -as BLS signatures and aggregation. Use for reference / educational purposes only. - -For an optimized implementation, use the [Python bindings](https://github.com/Chia-Network/bls-signatures/tree/main/python-bindings). - -For a good introduction to pairings, read [Pairings for Beginners](https://static1.squarespace.com/static/5fdbb09f31d71c1227082339/t/5ff394720493bd28278889c6/1609798774687/PairingsForBeginners.pdf) by Craig Costello. - -Map to curve implementation from [Algorand](https://github.com/algorand/bls_sigs_ref/). - -Run the tests with `python impl-test.py`. diff --git a/src/dashbls/python-impl/bls12381.py b/src/dashbls/python-impl/bls12381.py deleted file mode 100644 index c3a16fe2254a..000000000000 --- a/src/dashbls/python-impl/bls12381.py +++ /dev/null @@ -1,101 +0,0 @@ -# flake8: noqa -from fields import Fq, Fq2 - -# BLS parameter used to generate the other parameters -# Spec is found here: https://github.com/zkcrypto/pairing/tree/master/src/bls12_381 -x = -0xD201000000010000 - -# 381 bit prime -# Also see fields:bls12381_q -q = 0x1A0111EA397FE69A4B1BA7B6434BACD764774B84F38512BF6730D2A0F6B0F6241EABFFFEB153FFFFB9FEFFFFFFFFAAAB - -# a,b and a2, b2, define the elliptic curve and twisted curve. -# y^2 = x^3 + 4 -# y^2 = x^3 + 4(u + 1) -a = Fq(q, 0) -b = Fq(q, 4) -a_twist = Fq2(q, 0, 0) -b_twist = Fq2(q, 4, 4) - -# The generators for g1 and g2 -gx = Fq( - q, - 0x17F1D3A73197D7942695638C4FA9AC0FC3688C4F9774B905A14E3A3F171BAC586C55E83FF97A1AEFFB3AF00ADB22C6BB, -) -gy = Fq( - q, - 0x08B3F481E3AAA0F1A09E30ED741D8AE4FCF5E095D5D00AF600DB18CB2C04B3EDD03CC744A2888AE40CAA232946C5E7E1, -) - -g2x = Fq2( - q, - 352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160, - 3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758, -) -g2y = Fq2( - q, - 1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905, - 927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582, -) - -# The order of all three groups (g1, g2, and gt). Note, the elliptic curve E_twist -# actually has more valid points than this. This is relevant when hashing onto the -# curve, where we use a point that is not in g2, and map it into g2. -n = 0x73EDA753299D7D483339D80809A1D80553BDA402FFFE5BFEFFFFFFFF00000001 - -# Cofactor used to generate r torsion points -h = 0x396C8C005555E1568C00AAAB0000AAAB - -# https://tools.ietf.org/html/draft-irtf-cfrg-hash-to-curve-07#section-8.8.2 -h_eff = 0xBC69F08F2EE75B3584C6A0EA91B352888E2A8E9145AD7689986FF031508FFE1329C2F178731DB956D82BF015D1212B02EC0EC69D7477C1AE954CBC06689F6A359894C0ADEBBF6B4E8020005AAA95551 - -# Embedding degree -k = 12 - -# sqrt(-3) mod q -sqrt_n3 = 1586958781458431025242759403266842894121773480562120986020912974854563298150952611241517463240701 - -# (sqrt(-3) - 1) / 2 mod q -sqrt_n3m1o2 = 793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350 - -# This is the normal elliptic curve. G1 points are on here. -def parameters(): - return (q, a, b, gx, gy, g2x, g2y, n, h, x, k, sqrt_n3, sqrt_n3m1o2) - - -# This is the sextic twist used to send elements of G2 from -# coordinates in Fq12 to coordinates in Fq2. It's isomorphic -# to the above elliptic curve. See Page 63 of Costello. -def parameters_twist(): - return ( - q, - a_twist, - b_twist, - gx, - gy, - g2x, - g2y, - n, - h_eff, - x, - k, - sqrt_n3, - sqrt_n3m1o2, - ) - - -""" -Copyright 2020 Chia Network Inc - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" diff --git a/src/dashbls/python-impl/ec.py b/src/dashbls/python-impl/ec.py deleted file mode 100644 index 36f573d11b16..000000000000 --- a/src/dashbls/python-impl/ec.py +++ /dev/null @@ -1,586 +0,0 @@ -from __future__ import annotations - -from collections import namedtuple -from copy import deepcopy -from typing import List, Optional - -import bls12381 -from fields import FieldExtBase, Fq, Fq2, Fq6, Fq12 -from util import hash256 - -# Struct for elliptic curve parameters -EC = namedtuple("EC", "q a b gx gy g2x g2y n h x k sqrt_n3 sqrt_n3m1o2") - -default_ec = EC(*bls12381.parameters()) -default_ec_twist = EC(*bls12381.parameters_twist()) - - -class AffinePoint: - """ - Elliptic curve point, can represent any curve, and use Fq or Fq2 - coordinates. - """ - - def __init__(self, x, y, infinity: bool, ec=default_ec): - if ( - (not isinstance(x, Fq) and not isinstance(x, FieldExtBase)) - or (not isinstance(y, Fq) and not isinstance(y, FieldExtBase)) - or type(x) != type(y) - ): - raise Exception("x,y should be field elements") - self.FE = type(x) - self.x = x - self.y = y - self.infinity = infinity - self.ec = ec - - def is_on_curve(self) -> bool: - """ - Check that y^2 = x^3 + ax + b. - """ - if self.infinity: - return True - left = self.y * self.y - right = self.x * self.x * self.x + self.ec.a * self.x + self.ec.b - - return left == right - - def __add__(self, other: AffinePoint) -> AffinePoint: - if other == 0: - return self - if not isinstance(other, AffinePoint): - raise Exception("Incorrect object") - - return add_points(self, other, self.ec, self.FE) - - def __radd__(self, other: AffinePoint) -> AffinePoint: - return self.__add__(other) - - def __sub__(self, other: AffinePoint) -> AffinePoint: - return self.__add__(other.negate()) - - def __rsub__(self, other: AffinePoint) -> AffinePoint: - return self.negate().__add__(other) - - def __str__(self) -> str: - return ( - "AffinePoint(x=" - + self.x.__str__() - + ", y=" - + self.y.__str__() - + ", i=" - + str(self.infinity) - + ")\n" - ) - - def __repr__(self) -> str: - return ( - "AffinePoint(x=" - + self.x.__repr__() - + ", y=" - + self.y.__repr__() - + ", i=" - + str(self.infinity) - + ")\n" - ) - - def __eq__(self, other) -> bool: - if not isinstance(other, AffinePoint): - return False - return ( - self.x == other.x and self.y == other.y and self.infinity == other.infinity - ) - - def __ne__(self, other) -> bool: - return not self.__eq__(other) - - def __mul__(self, c) -> AffinePoint: - if not isinstance(c, Fq) and not isinstance(c, int): - raise ValueError("Error, must be int or Fq") - return scalar_mult_jacobian(c, self.to_jacobian(), self.ec).to_affine() - - def negate(self) -> AffinePoint: - return AffinePoint(self.x, -self.y, self.infinity, self.ec) - - def __rmul__(self, c: Fq) -> AffinePoint: - return self.__mul__(c) - - def to_jacobian(self) -> JacobianPoint: - return JacobianPoint( - self.x, self.y, self.FE.one(self.ec.q), self.infinity, self.ec - ) - - def __deepcopy__(self, memo) -> AffinePoint: - return AffinePoint( - deepcopy(self.x, memo), deepcopy(self.y, memo), self.infinity, self.ec - ) - - -class JacobianPoint: - """ - Elliptic curve point, can represent any curve, and use Fq or Fq2 - coordinates. Uses Jacobian coordinates so that point addition - does not require slow inversion. - """ - - def __init__(self, x, y, z, infinity: bool, ec=default_ec): - - if ( - not isinstance(x, Fq) - and not isinstance(x, FieldExtBase) - or (not isinstance(y, Fq) and not isinstance(y, FieldExtBase)) - or (not isinstance(z, Fq) and not isinstance(z, FieldExtBase)) - ): - raise Exception("x,y should be field elements") - self.FE = type(x) - self.x = x - self.y = y - self.z = z - self.infinity = infinity - self.ec = ec - - def is_on_curve(self) -> bool: - if self.infinity: - return True - return self.to_affine().is_on_curve() - - def negate(self) -> JacobianPoint: - return self.to_affine().negate().to_jacobian() - - def to_affine(self) -> AffinePoint: - if self.infinity: - return AffinePoint( - Fq.zero(self.ec.q), Fq.zero(self.ec.q), self.infinity, self.ec - ) - new_x = self.x / (self.z ** 2) - new_y = self.y / (self.z ** 3) - return AffinePoint(new_x, new_y, self.infinity, self.ec) - - def check_valid(self) -> None: - assert self.is_on_curve() - assert self * self.ec.n == G2Infinity() - - def get_fingerprint(self) -> int: - ser = bytes(self) - return int.from_bytes(hash256(ser)[:4], "big") - - def __add__(self, other: JacobianPoint) -> JacobianPoint: - if other == 0: - return self - if not isinstance(other, JacobianPoint): - raise ValueError("Incorrect object") - - return add_points_jacobian(self, other, self.ec, self.FE) - - def __radd__(self, other: JacobianPoint) -> JacobianPoint: - return self.__add__(other) - - def __eq__(self, other) -> bool: - if not isinstance(other, JacobianPoint): - return False - return self.to_affine() == other.to_affine() - - def __ne__(self, other) -> bool: - return not self.__eq__(other) - - def __mul__(self, c) -> JacobianPoint: - if not isinstance(c, int) and not isinstance(c, Fq): - raise ValueError("Error, must be int or Fq") - return scalar_mult_jacobian(c, self, self.ec) - - def __rmul__(self, c) -> JacobianPoint: - return self.__mul__(c) - - def __neg__(self) -> JacobianPoint: - return self.to_affine().negate().to_jacobian() - - def __str__(self) -> str: - return ( - "JacobianPoint(x=" - + self.x.__str__() - + ", y=" - + self.y.__str__() - + "z=" - + self.z.__str__() - + ", i=" - + str(self.infinity) - + ")\n" - ) - - def __repr__(self) -> str: - return self.__str__() - - def __bytes__(self) -> bytes: - return point_to_bytes(self, self.ec, self.FE) - - def __deepcopy__(self, memo) -> JacobianPoint: - return JacobianPoint( - deepcopy(self.x, memo), - deepcopy(self.y, memo), - deepcopy(self.z, memo), - self.infinity, - self.ec, - ) - - def __hash__(self) -> int: - return int.from_bytes(bytes(self), "big") - - -def sign_Fq(element, ec=default_ec) -> bool: - return element > Fq(ec.q, ((ec.q - 1) // 2)) - - -def sign_Fq2(element, ec=default_ec_twist) -> bool: - if element[1] == Fq(ec.q, 0): - return sign_Fq(element[0]) - - return element[1] > Fq(ec.q, ((ec.q - 1) // 2)) - - -def point_to_bytes(point_j: JacobianPoint, ec, FE) -> bytes: - # Zcash serialization described in https://datatracker.ietf.org/doc/draft-irtf-cfrg-pairing-friendly-curves/ - point = point_j.to_affine() - output = bytearray(bytes(point.x)) - - # If the y coordinate is the bigger one of the two, set the first - # bit to 1. - if point.infinity: - return bytes([0x40]) + bytes([0] * (len(output) - 1)) - - if FE == Fq: - sign = sign_Fq(point.y, ec) - else: - sign = sign_Fq2(point.y, ec) - - if sign: - output[0] |= 0xA0 - else: - output[0] |= 0x80 - return bytes(output) - - -def bytes_to_point(buffer: bytes, ec, FE) -> JacobianPoint: - # Zcash deserialization described in https://datatracker.ietf.org/doc/draft-irtf-cfrg-pairing-friendly-curves/ - - if FE == Fq: - if len(buffer) != 48: - raise ValueError("G1Elements must be 48 bytes") - elif FE == Fq2: - if len(buffer) != 96: - raise ValueError("G2Elements must be 96 bytes") - else: - raise ValueError("Invalid FE") - - m_byte = buffer[0] & 0xE0 - - if m_byte in [0x20, 0x60, 0xE0]: - raise ValueError("Invalid first three bits") - - C_bit = (m_byte & 0x80) >> 7 # First bit - I_bit = (m_byte & 0x40) >> 6 # Second bit - S_bit = (m_byte & 0x20) >> 5 # Third bit - - if C_bit == 0: - raise ValueError("First bit must be 1 (only compressed points)") - - buffer = bytes([buffer[0] & 0x1F]) + buffer[1:] - - if I_bit == 1: - if any([e != 0 for e in buffer]): - raise ValueError("Point at infinity set, but data not all zeroes") - return AffinePoint(FE.zero(ec.q), FE.zero(ec.q), True, ec).to_jacobian() - - x = FE.from_bytes(buffer, ec.q) - y_value = y_for_x(x, ec, FE) - - if FE == Fq: - sign_fn = sign_Fq - else: - sign_fn = sign_Fq2 - - if sign_fn(y_value, ec) == S_bit: - y = y_value - else: - y = -y_value - - return AffinePoint(x, y, False, ec).to_jacobian() - - -def y_for_x(x, ec=default_ec, FE=Fq): - """ - Solves y = sqrt(x^3 + ax + b) for both valid ys. - """ - if not isinstance(x, FE): - x = FE(ec.q, x) - - u = x * x * x + ec.a * x + ec.b - - y = u.modsqrt() - if y == 0 or not AffinePoint(x, y, False, ec).is_on_curve(): - raise ValueError("No y for point x") - return y - - -def double_point(p1: AffinePoint, ec=default_ec, FE=Fq) -> AffinePoint: - """ - Basic elliptic curve point doubling - """ - x, y = p1.x, p1.y - left = Fq(ec.q, 3) * x * x - left = left + ec.a - s = left / (Fq(ec.q, 2) * y) - new_x = s * s - x - x - new_y = s * (x - new_x) - y - return AffinePoint(new_x, new_y, False, ec) - - -def add_points(p1: AffinePoint, p2: AffinePoint, ec=default_ec, FE=Fq) -> AffinePoint: - """ - Basic elliptic curve point addition. - """ - assert p1.is_on_curve() - assert p2.is_on_curve() - if p1.infinity: - return p2 - if p2.infinity: - return p1 - if p1 == p2: - return double_point(p1, ec, FE) - if p1.x == p2.x: - return AffinePoint(FE.zero(ec.q), FE.zero(ec.q), True, ec) - - x1, y1 = p1.x, p1.y - x2, y2 = p2.x, p2.y - s = (y2 - y1) / (x2 - x1) - new_x = s * s - x1 - x2 - new_y = s * (x1 - new_x) - y1 - return AffinePoint(new_x, new_y, False, ec) - - -def double_point_jacobian(p1: JacobianPoint, ec=default_ec, FE=Fq) -> JacobianPoint: - """ - Jacobian elliptic curve point doubling, see - http://www.hyperelliptic.org/EFD/oldefd/jacobian.html - """ - X, Y, Z = p1.x, p1.y, p1.z - if Y == FE.zero(ec.q) or p1.infinity: - return JacobianPoint(FE.one(ec.q), FE.one(ec.q), FE.zero(ec.q), True, ec) - - # S = 4*X*Y^2 - S = Fq(ec.q, 4) * X * Y * Y - - Z_sq = Z * Z - Z_4th = Z_sq * Z_sq - Y_sq = Y * Y - Y_4th = Y_sq * Y_sq - - # M = 3*X^2 + a*Z^4 - M = Fq(ec.q, 3) * X * X - M += ec.a * Z_4th - - # X' = M^2 - 2*S - X_p = M * M - Fq(ec.q, 2) * S - # Y' = M*(S - X') - 8*Y^4 - Y_p = M * (S - X_p) - Fq(ec.q, 8) * Y_4th - # Z' = 2*Y*Z - Z_p = Fq(ec.q, 2) * Y * Z - return JacobianPoint(X_p, Y_p, Z_p, False, ec) - - -def add_points_jacobian( - p1: JacobianPoint, p2: JacobianPoint, ec=default_ec, FE=Fq -) -> JacobianPoint: - """ - Jacobian elliptic curve point addition, see - http://www.hyperelliptic.org/EFD/oldefd/jacobian.html - """ - if p1.infinity: - return p2 - if p2.infinity: - return p1 - # U1 = X1*Z2^2 - U1 = p1.x * (p2.z ** 2) - # U2 = X2*Z1^2 - U2 = p2.x * (p1.z ** 2) - # S1 = Y1*Z2^3 - S1 = p1.y * (p2.z ** 3) - # S2 = Y2*Z1^3 - S2 = p2.y * (p1.z ** 3) - if U1 == U2: - if S1 != S2: - return JacobianPoint(FE.one(ec.q), FE.one(ec.q), FE.zero(ec.q), True, ec) - else: - return double_point_jacobian(p1, ec, FE) - - # H = U2 - U1 - H = U2 - U1 - # R = S2 - S1 - R = S2 - S1 - H_sq = H * H - H_cu = H * H_sq - # X3 = R^2 - H^3 - 2*U1*H^2 - X3 = R * R - H_cu - Fq(ec.q, 2) * U1 * H_sq - # Y3 = R*(U1*H^2 - X3) - S1*H^3 - Y3 = R * (U1 * H_sq - X3) - S1 * H_cu - # Z3 = H*Z1*Z2 - Z3 = H * p1.z * p2.z - return JacobianPoint(X3, Y3, Z3, False, ec) - - -def scalar_mult(c, p1: AffinePoint, ec=default_ec, FE=Fq) -> AffinePoint: - """ - Double and add, see - https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication - """ - if p1.infinity or c % ec.q == 0: - return AffinePoint(FE.zero(ec.q), FE.zero(ec.q), ec) - result = AffinePoint(FE.zero(ec.q), FE.zero(ec.q), True, ec) - addend = p1 - while c > 0: - if c & 1: - result += addend - - # double point - addend += addend - c = c >> 1 - - return result - - -def scalar_mult_jacobian(c, p1: JacobianPoint, ec=default_ec, FE=Fq) -> JacobianPoint: - """ - Double and add, see - https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication - """ - if isinstance(c, FE): - c = c.value - if p1.infinity or c % ec.q == 0: - return JacobianPoint(FE.one(ec.q), FE.one(ec.q), FE.zero(ec.q), True, ec) - - result = JacobianPoint(FE.one(ec.q), FE.one(ec.q), FE.zero(ec.q), True, ec) - addend = p1 - while c > 0: - if c & 1: - result += addend - # double point - addend += addend - c = c >> 1 - return result - - -def G1Generator(ec=default_ec) -> JacobianPoint: - return AffinePoint(ec.gx, ec.gy, False, ec).to_jacobian() - - -def G2Generator(ec=default_ec_twist) -> JacobianPoint: - return AffinePoint(ec.g2x, ec.g2y, False, ec).to_jacobian() - - -def G1Infinity(ec=default_ec, FE=Fq) -> JacobianPoint: - return JacobianPoint(FE.one(ec.q), FE.one(ec.q), FE.zero(ec.q), True, ec) - - -def G2Infinity(ec=default_ec_twist, FE=Fq2) -> JacobianPoint: - return JacobianPoint(FE.one(ec.q), FE.one(ec.q), FE.zero(ec.q), True, ec) - - -def G1FromBytes(buffer: bytes, ec=default_ec, FE=Fq) -> JacobianPoint: - return bytes_to_point(buffer, ec, FE) - - -def G2FromBytes(buffer: bytes, ec=default_ec_twist, FE=Fq2): - return bytes_to_point(buffer, ec, FE) - - -def untwist(point: AffinePoint, ec=default_ec) -> AffinePoint: - """ - Given a point on G2 on the twisted curve, this converts its - coordinates back from Fq2 to Fq12. See Craig Costello book, look - up twists. - """ - f = Fq12.one(ec.q) - wsq = Fq12(ec.q, f.root, Fq6.zero(ec.q)) - wcu = Fq12(ec.q, Fq6.zero(ec.q), f.root) - return AffinePoint(point.x / wsq, point.y / wcu, False, ec) - - -def twist(point: AffinePoint, ec=default_ec_twist) -> AffinePoint: - """ - Given an untwisted point, this converts it's - coordinates to a point on the twisted curve. See Craig Costello - book, look up twists. - """ - f = Fq12.one(ec.q) - wsq = Fq12(ec.q, f.root, Fq6.zero(ec.q)) - wcu = Fq12(ec.q, Fq6.zero(ec.q), f.root) - new_x = point.x * wsq - new_y = point.y * wcu - return AffinePoint(new_x, new_y, False, ec) - - -# Isogeny map evaluation specified by map_coeffs -# -# map_coeffs should be specified as (xnum, xden, ynum, yden) -# -# This function evaluates the isogeny over Jacobian projective coordinates. -# For details, see Section 4.3 of -# Wahby and Boneh, "Fast and simple constant-time hashing to the BLS12-381 elliptic curve." -# ePrint # 2019/403, https://ia.cr/2019/403. -def eval_iso(P: JacobianPoint, map_coeffs, ec) -> JacobianPoint: - (x, y, z) = (P.x, P.y, P.z) - mapvals: List[Optional[Fq2]] = [None] * 4 - - # Precompute the required powers of Z^2 - maxord = max(len(coeffs) for coeffs in map_coeffs) - zpows: List[Optional[Fq2]] = [None] * maxord - zpows[0] = z ** 0 # type: ignore - zpows[1] = z ** 2 # type: ignore - for idx in range(2, len(zpows)): - assert zpows[idx - 1] is not None - assert zpows[1] is not None - zpows[idx] = zpows[idx - 1] * zpows[1] - - # Compute the numerator and denominator of the X and Y maps via Horner's rule - for (idx, coeffs) in enumerate(map_coeffs): - coeffs_z = [ - zpow * c for (zpow, c) in zip(reversed(coeffs), zpows[: len(coeffs)]) - ] - tmp = coeffs_z[0] - for coeff in coeffs_z[1:]: - tmp *= x - tmp += coeff - mapvals[idx] = tmp - - # xden is of order 1 less than xnum, so one needs to multiply it by an extra factor of Z^2 - assert len(map_coeffs[1]) + 1 == len(map_coeffs[0]) - assert zpows[1] is not None - assert mapvals[1] is not None - mapvals[1] *= zpows[1] - - # Multiply the result of Y map by the y-coordinate y / z^3 - assert mapvals[2] is not None - assert mapvals[3] is not None - mapvals[2] *= y - mapvals[3] *= z ** 3 - - Z = mapvals[1] * mapvals[3] - X = mapvals[0] * mapvals[3] * Z - Y = mapvals[2] * mapvals[1] * Z * Z - return JacobianPoint(X, Y, Z, P.infinity, ec) - - -""" -Copyright 2020 Chia Network Inc - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" diff --git a/src/dashbls/python-impl/fields.py b/src/dashbls/python-impl/fields.py deleted file mode 100644 index 418ce50732c8..000000000000 --- a/src/dashbls/python-impl/fields.py +++ /dev/null @@ -1,763 +0,0 @@ -from __future__ import annotations - -from copy import deepcopy -from typing import Any - - -class Fq: - """ - Represents an element of a finite field mod a prime q. - """ - - value: int - extension: int = 1 - - def __init__(self, Q: int, value: int): - self.Q = Q - self.value = value % Q - - def __neg__(self) -> Fq: - return Fq(self.Q, -self.value) - - def __add__(self, other: Fq) -> Fq: - if not isinstance(other, Fq): - return NotImplemented - return Fq(self.Q, self.value + other.value) - - def __radd__(self, other: Fq) -> Fq: - if not isinstance(other, Fq): - return NotImplemented - return self.__add__(other) - - def __sub__(self, other: Fq) -> Fq: - if not isinstance(other, Fq): - return NotImplemented - return Fq(self.Q, self.value - other.value) - - def __rsub__(self, other: Fq) -> Fq: - if not isinstance(other, Fq): - return NotImplemented - return Fq(self.Q, other.value - self.value) - - def __mul__(self, other: Fq) -> Fq: - if not isinstance(other, Fq): - return NotImplemented - return Fq(self.Q, self.value * other.value) - - def __rmul__(self, other: Fq) -> Fq: - return self.__mul__(other) - - def __eq__(self, other) -> bool: - if not isinstance(other, type(self)): - return False - else: - return self.value == other.value and self.Q == other.Q - - def __lt__(self, other: Fq) -> bool: - return self.value < other.value - - def __gt__(self, other: Fq) -> bool: - return self.value > other.value - - def __le__(self, other: Fq) -> bool: - return self.value <= other.value - - def __ge__(self, other: Fq) -> bool: - return self.value >= other.value - - def __str__(self): - s = hex(self.value) - s2 = s[0:7] + ".." + s[-5:] if len(s) > 10 else s - return "Fq(" + s2 + ")" - - def __repr__(self): - return "Fq(" + hex(self.value) + ")" - - def __bytes__(self): - return self.value.to_bytes(48, "big") - - @staticmethod - def from_bytes(buffer: bytes, q: int): - assert len(buffer) == 48 - return Fq(q, int.from_bytes(buffer, "big")) - - def __pow__(self, other) -> Fq: - if other == 0: - return Fq(self.Q, 1) - elif other == 1: - return Fq(self.Q, self.value) - elif other % 2 == 0: - return Fq(self.Q, self.value * self.value) ** (other // 2) - else: - return Fq(self.Q, self.value * self.value) ** (other // 2) * self - - def qi_power(self, i: int) -> Fq: - return self - - def __invert__(self) -> Fq: - """ - Extended euclidian algorithm for inversion. - """ - x0, x1, y0, y1 = 1, 0, 0, 1 - a = int(self.Q) - b = int(self.value) - while a != 0: - q, b, a = b // a, a, b % a - x0, x1 = x1, x0 - q * x1 - y0, y1 = y1, y0 - q * y1 - return Fq(self.Q, x0) - - def __floordiv__(self, other) -> Fq: - if isinstance(other, int) and not isinstance(other, type(self)): - other = Fq(self.Q, other) - return self * ~other - - __truediv__ = __floordiv__ - - def __iter__(self): - yield self - - def modsqrt(self) -> Fq: - if int(self.value) == 0: - return Fq(self.Q, 0) - if pow(int(self.value), (self.Q - 1) // 2, self.Q) != 1: - raise ValueError("No sqrt exists") - if self.Q % 4 == 3: - return Fq(self.Q, pow(int(self.value), (self.Q + 1) // 4, self.Q)) - if self.Q % 8 == 5: - return Fq(self.Q, pow(int(self.value), (self.Q + 3) // 8, self.Q)) - - # p % 8 == 1. Tonelli Shanks algorithm for finding square root - S = 0 - q = self.Q - 1 - - while q % 2 == 0: - q = q // 2 - S += 1 - - z = 0 - for i in range(self.Q): - euler = pow(i, (self.Q - 1) // 2, self.Q) - if euler == -1 % self.Q: - z = i - break - - M = S - c = pow(z, q, self.Q) - t = pow(self.value, q, self.Q) - R = pow(self.value, (q + 1) // 2, self.Q) - - while True: - if t == 0: - return Fq(self.Q, 0) - if t == 1: - return Fq(self.Q, R) - i = 0 - f = t - while f != 1: - f = pow(f, 2, self.Q) - i += 1 - b = pow(c, pow(2, M - i - 1, self.Q), self.Q) - M = i - c = pow(b, 2, self.Q) - t = (t * c) % self.Q - R = (R * b) % self.Q - - def __deepcopy__(self, memo) -> Fq: - return Fq(self.Q, self.value) - - @classmethod - def zero(cls, Q: int) -> Fq: - return Fq(Q, 0) - - @classmethod - def one(cls, Q: int) -> Fq: - return Fq(Q, 1) - - @classmethod - def from_fq(cls, Q: int, fq: Fq) -> Fq: - return fq - - -class FieldExtBase(tuple): - """ - Represents an extension of a field (or extension of an extension). - The elements of the tuple can be other FieldExtBase or they can be - Fq elements. For example, Fq2 = (Fq, Fq). Fq12 = (Fq6, Fq6), etc. - """ - - root = None - extension: int - embedding: int - basefield: Any - Q: int - - def __new__(cls, Q, *args): - new_args = args[:] - try: - arg_extension = args[0].extension - args[1].extension - except AttributeError: - if len(args) != 2: - raise Exception("Invalid number of arguments") - arg_extension = 1 - new_args = [Fq(Q, a) for a in args] - if arg_extension != 1: - if len(args) != cls.embedding: - raise Exception("Invalid number of arguments") - for arg in new_args: - assert arg.extension == arg_extension - assert all(isinstance(arg, cls.basefield) for arg in new_args) - ret = super().__new__(cls, new_args) - ret.Q = Q - return ret - - def __neg__(self): - cls = type(self) - ret = super().__new__(cls, (-x for x in self)) - ret.Q = self.Q - ret.root = self.root - return ret - - def __add__(self, other): - cls = type(self) - if not isinstance(other, cls): - if type(other) != int and other.extension > self.extension: - return NotImplemented - other_new = [cls.basefield.zero(self.Q) for _ in self] - other_new[0] = other_new[0] + other - else: - other_new = other - - ret = super().__new__(cls, (a + b for a, b in zip(self, other_new))) - ret.Q = self.Q - ret.root = self.root - return ret - - def __radd__(self, other): - return self.__add__(other) - - def __sub__(self, other): - return self + (-other) - - def __rsub__(self, other): - return (-self) + other - - def __mul__(self, other): - cls = type(self) - if isinstance(other, int): - ret = super().__new__(cls, (a * other for a in self)) - ret.Q = self.Q - ret.root = self.root - return ret - if cls.extension < other.extension: - return NotImplemented - - buf = [cls.basefield.zero(self.Q) for _ in self] - - for i, x in enumerate(self): - if cls.extension == other.extension: - for j, y in enumerate(other): - if x and y: - if i + j >= self.embedding: - buf[(i + j) % self.embedding] += x * y * self.root - else: - buf[(i + j) % self.embedding] += x * y - else: - if x: - buf[i] = x * other - ret = super().__new__(cls, buf) - ret.Q = self.Q - ret.root = self.root - return ret - - def __rmul__(self, other): - return self.__mul__(other) - - def __floordiv__(self, other): - return self * ~other - - def __eq__(self, other): - if not isinstance(other, type(self)): - if isinstance(other, FieldExtBase) or isinstance(other, int): - if ( - not isinstance(other, FieldExtBase) - or self.extension > other.extension - ): - for i in range(1, self.embedding): - if self[i] != (type(self.root).zero(self.Q)): - return False - return self[0] == other - return NotImplemented - return NotImplemented - else: - return super().__eq__(other) and self.Q == other.Q - - def __lt__(self, other): - # Reverse the order for comparison (3i + 1 > 2i + 7) - return self[::-1].__lt__(other[::-1]) - - def __gt__(self, other): - return super().__gt__(other) - - def __neq__(self, other): - return not self.__eq__(other) - - def __str__(self): - return ( - "Fq" - + str(self.extension) - + "(" - + ", ".join([a.__str__() for a in self]) - + ")" - ) - - def __repr__(self): - return ( - "Fq" - + str(self.extension) - + "(" - + ", ".join([a.__repr__() for a in self]) - + ")" - ) - - # Returns the concatenated coordinates in big endian bytes - def __bytes__(self): - sum_bytes = bytes([]) - for x in reversed(self): - if type(x) != FieldExtBase and type(x) != Fq: - x = Fq.from_fq(self.Q, x) - sum_bytes += bytes(x) - return sum_bytes - - @classmethod - def from_bytes(cls, buffer: bytes, Q: int): - assert len(buffer) == cls.extension * 48 - embedded_size = 48 * (cls.extension // cls.embedding) - tup = [] - for i in range(cls.embedding): - tup.append(buffer[i * embedded_size : (i + 1) * embedded_size]) - return cls(Q, *[cls.basefield.from_bytes(b, Q) for b in reversed(tup)]) - - __truediv__ = __floordiv__ - - def __pow__(self, e): - assert isinstance(e, int) and e >= 0 - ans = type(self).one(self.Q) - base = self - ans.root = self.root - - while e: - if e & 1: - ans *= base - - base *= base - e >>= 1 - - return ans - - def __bool__(self): - return any(x for x in self) - - def set_root(self, _root): - self.root = _root - - @classmethod - def zero(cls, Q): - return cls.from_fq(Q, Fq(Q, 0)) - - @classmethod - def one(cls, Q): - return cls.from_fq(Q, Fq(Q, 1)) - - @classmethod - def from_fq(cls, Q, fq): - y = cls.basefield.from_fq(Q, fq) - z = cls.basefield.zero(Q) - ret = super().__new__(cls, (z if i else y for i in range(cls.embedding))) - ret.Q = Q - if cls == Fq2: - ret.set_root(Fq(Q, -1)) - elif cls == Fq6: - ret.set_root(Fq2(Q, Fq.one(Q), Fq.one(Q))) - elif cls == Fq12: - r = Fq6(Q, Fq2.zero(Q), Fq2.one(Q), Fq2.zero(Q)) - ret.set_root(r) - return ret - - def __deepcopy__(self, memo): - cls = type(self) - ret = super().__new__(cls, (deepcopy(a, memo) for a in self)) - ret.Q = self.Q - ret.root = self.root - return ret - - def qi_power(self, i): - if self.Q != bls12381_q: - raise NotImplementedError - cls = type(self) - i %= cls.extension - if i == 0: - return self - ret = super().__new__( - cls, - ( - a.qi_power(i) * frob_coeffs[cls.extension, i, j] if j else a.qi_power(i) - for j, a in enumerate(self) - ), - ) - ret.Q = self.Q - ret.root = self.root - return ret - - -class Fq2(FieldExtBase): - # Fq2 is constructed as Fq(u) / (u2 - β) where β = -1 - extension = 2 - embedding = 2 - basefield = Fq - - def __init__(self, Q, *args): - super().set_root(Fq(Q, -1)) - - def __invert__(self) -> Fq2: - a, b = self - factor = ~(a * a + b * b) - ret = Fq2(self.Q, a * factor, -b * factor) - return ret - - def mul_by_nonresidue(self) -> Fq2: - # multiply by u + 1 - a, b = self - return Fq2(self.Q, a - b, a + b) - - def modsqrt(self) -> Fq2: - """ - Using algorithm 8 (complex method) for square roots in - https://eprint.iacr.org/2012/685.pdf - This is necessary for computing y value given an x value. - """ - a0, a1 = self - if a1 == Fq.zero(self.Q): - return a0.modsqrt() - alpha = pow(a0, 2) + pow(a1, 2) - gamma = pow(alpha, (self.Q - 1) // 2) - if gamma == Fq(self.Q, -1): - raise ValueError("No sqrt exists") - alpha = alpha.modsqrt() - delta = (a0 + alpha) * ~Fq(self.Q, 2) - gamma = pow(delta, (self.Q - 1) // 2) - if gamma == Fq(self.Q, -1): - delta = (a0 - alpha) * ~Fq(self.Q, 2) - - x0 = delta.modsqrt() - x1 = a1 * ~(Fq(self.Q, 2) * x0) - return Fq2(self.Q, x0, x1) - - -class Fq6(FieldExtBase): - # Fq6 is constructed as Fq2(v) / (v3 - ξ) where ξ = u + 1 - extension = 6 - embedding = 3 - basefield = Fq2 - - def __init__(self, Q: int, *args): - super().set_root(Fq2(Q, Fq.one(Q), Fq.one(Q))) - - def __invert__(self) -> Fq6: - a, b, c = self - g0 = a * a - b * c.mul_by_nonresidue() - g1 = (c * c).mul_by_nonresidue() - a * b - g2 = b * b - a * c - factor = ~(g0 * a + (g1 * c + g2 * b).mul_by_nonresidue()) - # TODO: no inverse - - return Fq6(self.Q, g0 * factor, g1 * factor, g2 * factor) - - def mul_by_nonresidue(self) -> Fq6: - # multiply by v - a, b, c = self - return Fq6(self.Q, c * self.root, a, b) - - -class Fq12(FieldExtBase): - # Fq12 is constructed as Fq6(w) / (w2 - γ) where γ = v - extension = 12 - embedding = 2 - basefield = Fq6 - - def __init__(self, Q, *args): - super().set_root(Fq6(Q, Fq2.zero(Q), Fq2.one(Q), Fq2.zero(Q))) - - def __invert__(self) -> Fq12: - a, b = self - factor = ~(a * a - (b * b).mul_by_nonresidue()) - return Fq12(self.Q, a * factor, -b * factor) - - -# Because fields aren't done with metaclasses, and we need to -# avoid circular imports, we put a hack here for bls12381 for now. -bls12381_q = ( - q -) = 0x1A0111EA397FE69A4B1BA7B6434BACD764774B84F38512BF6730D2A0F6B0F6241EABFFFEB153FFFFB9FEFFFFFFFFAAAB - -# roots of unity, used for computing square roots in Fq2 -rv1 = 0x6AF0E0437FF400B6831E36D6BD17FFE48395DABC2D3435E77F76E17009241C5EE67992F72EC05F4C81084FBEDE3CC09 -roots_of_unity = (Fq2(q, 1, 0), Fq2(q, 0, 1), Fq2(q, rv1, rv1), Fq2(q, rv1, q - rv1)) -del rv1 - -# Frobenius coefficients for raising elements to q**i -th powers -# These are specific to this given q -frob_coeffs = { - (2, 1, 1): Fq(q, -1), - (6, 1, 1): Fq2( - q, - Fq(q, 0x0), - Fq( - q, - 0x1A0111EA397FE699EC02408663D4DE85AA0D857D89759AD4897D29650FB85F9B409427EB4F49FFFD8BFD00000000AAAC, - ), - ), # noga: E501 - (6, 1, 2): Fq2( - q, - Fq( - q, - 0x1A0111EA397FE699EC02408663D4DE85AA0D857D89759AD4897D29650FB85F9B409427EB4F49FFFD8BFD00000000AAAD, - ), - Fq(q, 0x0), - ), # noga: E501 - (6, 2, 1): Fq2( - q, - Fq( - q, - 0x5F19672FDF76CE51BA69C6076A0F77EADDB3A93BE6F89688DE17D813620A00022E01FFFFFFFEFFFE, - ), - Fq(q, 0x0), - ), # noga: E501 - (6, 2, 2): Fq2( - q, - Fq( - q, - 0x1A0111EA397FE699EC02408663D4DE85AA0D857D89759AD4897D29650FB85F9B409427EB4F49FFFD8BFD00000000AAAC, - ), - Fq(q, 0x0), - ), - (6, 3, 1): Fq2(q, Fq(q, 0x0), Fq(q, 0x1)), - (6, 3, 2): Fq2( - q, - Fq( - q, - 0x1A0111EA397FE69A4B1BA7B6434BACD764774B84F38512BF6730D2A0F6B0F6241EABFFFEB153FFFFB9FEFFFFFFFFAAAA, - ), - Fq(q, 0x0), - ), - (6, 4, 1): Fq2( - q, - Fq( - q, - 0x1A0111EA397FE699EC02408663D4DE85AA0D857D89759AD4897D29650FB85F9B409427EB4F49FFFD8BFD00000000AAAC, - ), - Fq(q, 0x0), - ), - (6, 4, 2): Fq2( - q, - Fq( - q, - 0x5F19672FDF76CE51BA69C6076A0F77EADDB3A93BE6F89688DE17D813620A00022E01FFFFFFFEFFFE, - ), - Fq(q, 0x0), - ), - (6, 5, 1): Fq2( - q, - Fq(q, 0x0), - Fq( - q, - 0x5F19672FDF76CE51BA69C6076A0F77EADDB3A93BE6F89688DE17D813620A00022E01FFFFFFFEFFFE, - ), - ), - (6, 5, 2): Fq2( - q, - Fq( - q, - 0x5F19672FDF76CE51BA69C6076A0F77EADDB3A93BE6F89688DE17D813620A00022E01FFFFFFFEFFFF, - ), - Fq(q, 0x0), - ), - (12, 1, 1): Fq6( - q, - Fq2( - q, - Fq( - q, - 0x1904D3BF02BB0667C231BEB4202C0D1F0FD603FD3CBD5F4F7B2443D784BAB9C4F67EA53D63E7813D8D0775ED92235FB8, - ), - Fq( - q, - 0xFC3E2B36C4E03288E9E902231F9FB854A14787B6C7B36FEC0C8EC971F63C5F282D5AC14D6C7EC22CF78A126DDC4AF3, - ), - ), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - ), - (12, 2, 1): Fq6( - q, - Fq2( - q, - Fq( - q, - 0x5F19672FDF76CE51BA69C6076A0F77EADDB3A93BE6F89688DE17D813620A00022E01FFFFFFFEFFFF, - ), - Fq(q, 0x0), - ), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - ), - (12, 3, 1): Fq6( - q, - Fq2( - q, - Fq( - q, - 0x135203E60180A68EE2E9C448D77A2CD91C3DEDD930B1CF60EF396489F61EB45E304466CF3E67FA0AF1EE7B04121BDEA2, - ), - Fq( - q, - 0x6AF0E0437FF400B6831E36D6BD17FFE48395DABC2D3435E77F76E17009241C5EE67992F72EC05F4C81084FBEDE3CC09, - ), - ), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - ), - (12, 4, 1): Fq6( - q, - Fq2( - q, - Fq( - q, - 0x5F19672FDF76CE51BA69C6076A0F77EADDB3A93BE6F89688DE17D813620A00022E01FFFFFFFEFFFE, - ), - Fq(q, 0x0), - ), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - ), - (12, 5, 1): Fq6( - q, - Fq2( - q, - Fq( - q, - 0x144E4211384586C16BD3AD4AFA99CC9170DF3560E77982D0DB45F3536814F0BD5871C1908BD478CD1EE605167FF82995, - ), - Fq( - q, - 0x5B2CFD9013A5FD8DF47FA6B48B1E045F39816240C0B8FEE8BEADF4D8E9C0566C63A3E6E257F87329B18FAE980078116, - ), - ), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - ), - (12, 6, 1): Fq6( - q, - Fq2( - q, - Fq( - q, - 0x1A0111EA397FE69A4B1BA7B6434BACD764774B84F38512BF6730D2A0F6B0F6241EABFFFEB153FFFFB9FEFFFFFFFFAAAA, - ), - Fq(q, 0x0), - ), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - ), - (12, 7, 1): Fq6( - q, - Fq2( - q, - Fq( - q, - 0xFC3E2B36C4E03288E9E902231F9FB854A14787B6C7B36FEC0C8EC971F63C5F282D5AC14D6C7EC22CF78A126DDC4AF3, - ), - Fq( - q, - 0x1904D3BF02BB0667C231BEB4202C0D1F0FD603FD3CBD5F4F7B2443D784BAB9C4F67EA53D63E7813D8D0775ED92235FB8, - ), - ), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - ), - (12, 8, 1): Fq6( - q, - Fq2( - q, - Fq( - q, - 0x1A0111EA397FE699EC02408663D4DE85AA0D857D89759AD4897D29650FB85F9B409427EB4F49FFFD8BFD00000000AAAC, - ), - Fq(q, 0x0), - ), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - ), - (12, 9, 1): Fq6( - q, - Fq2( - q, - Fq( - q, - 0x6AF0E0437FF400B6831E36D6BD17FFE48395DABC2D3435E77F76E17009241C5EE67992F72EC05F4C81084FBEDE3CC09, - ), - Fq( - q, - 0x135203E60180A68EE2E9C448D77A2CD91C3DEDD930B1CF60EF396489F61EB45E304466CF3E67FA0AF1EE7B04121BDEA2, - ), - ), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - ), - (12, 10, 1): Fq6( - q, - Fq2( - q, - Fq( - q, - 0x1A0111EA397FE699EC02408663D4DE85AA0D857D89759AD4897D29650FB85F9B409427EB4F49FFFD8BFD00000000AAAD, - ), - Fq(q, 0x0), - ), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - ), - (12, 11, 1): Fq6( - q, - Fq2( - q, - Fq( - q, - 0x5B2CFD9013A5FD8DF47FA6B48B1E045F39816240C0B8FEE8BEADF4D8E9C0566C63A3E6E257F87329B18FAE980078116, - ), - Fq( - q, - 0x144E4211384586C16BD3AD4AFA99CC9170DF3560E77982D0DB45F3536814F0BD5871C1908BD478CD1EE605167FF82995, - ), - ), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - Fq2(q, Fq(q, 0x0), Fq(q, 0x0)), - ), -} - -""" -Copyright 2020 Chia Network Inc - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" diff --git a/src/dashbls/python-impl/hash_to_field.py b/src/dashbls/python-impl/hash_to_field.py deleted file mode 100644 index eb417219ea9c..000000000000 --- a/src/dashbls/python-impl/hash_to_field.py +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/python -# -# pure Python implementation of hash-to-field as specified in -# https://github.com/pairingwg/bls_standard/blob/master/minutes/spec-v1.md - -import hashlib - -from bls12381 import q - - -# defined in RFC 3447, section 4.1 -def I2OSP(val, length): - if val < 0 or val >= (1 << (8 * length)): - raise ValueError("bad I2OSP call: val=%d length=%d" % (val, length)) - ret = [0] * length - val_ = val - for idx in reversed(range(0, length)): - ret[idx] = val_ & 0xFF - val_ = val_ >> 8 - ret = bytes(ret) - assert ret == int(val).to_bytes(length, "big"), "oops: %s %s" % ( - str(ret), - str(int(val).to_bytes(length, "big")), - ) - return ret - - -# defined in RFC 3447, section 4.2 -def OS2IP(octets): - ret = 0 - for o in octets: - ret = ret << 8 - ret += o - assert ret == int.from_bytes(octets, "big") - return ret - - -# expand_message_xmd from draft-irtf-cfrg-hash-to-curve-06 -def _strxor(str1, str2): - return bytes(s1 ^ s2 for (s1, s2) in zip(str1, str2)) - - -def expand_message_xmd(msg, DST, len_in_bytes, hash_fn): - # input and output lengths for hash_fn - b_in_bytes = hash_fn().digest_size - r_in_bytes = hash_fn().block_size - - # ell, DST_prime, etc - ell = (len_in_bytes + b_in_bytes - 1) // b_in_bytes - if ell > 255: - raise ValueError("expand_message_xmd: ell=%d out of range" % ell) - DST_prime = DST + I2OSP(len(DST), 1) - Z_pad = I2OSP(0, r_in_bytes) - l_i_b_str = I2OSP(len_in_bytes, 2) - - b_0 = hash_fn(Z_pad + msg + l_i_b_str + I2OSP(0, 1) + DST_prime).digest() - b_vals = [None] * ell - b_vals[0] = hash_fn(b_0 + I2OSP(1, 1) + DST_prime).digest() - for idx in range(1, ell): - b_vals[idx] = hash_fn( - _strxor(b_0, b_vals[idx - 1]) + I2OSP(idx + 1, 1) + DST_prime - ).digest() - pseudo_random_bytes = b"".join(b_vals) - return pseudo_random_bytes[0:len_in_bytes] - - -def expand_message_xof(msg, DST, len_in_bytes, hash_fn): - DST_prime = DST + I2OSP(len(DST), 1) - msg_prime = msg + I2OSP(len_in_bytes, 2) + DST_prime - return hash_fn(msg_prime).digest(len_in_bytes) - - -# hash_to_field from draft-irtf-cfrg-hash-to-curve-06 -def hash_to_field(msg, count, DST, modulus, degree, blen, expand_fn, hash_fn): - # get pseudorandom bytes - len_in_bytes = count * degree * blen - pseudo_random_bytes = expand_fn(msg, DST, len_in_bytes, hash_fn) - - u_vals = [None] * count - for idx in range(0, count): - e_vals = [None] * degree - for jdx in range(0, degree): - elm_offset = blen * (jdx + idx * degree) - tv = pseudo_random_bytes[elm_offset : elm_offset + blen] - e_vals[jdx] = OS2IP(tv) % modulus - u_vals[idx] = e_vals - return u_vals - - -def Hp(msg, count, dst): - if not isinstance(msg, bytes): - raise ValueError("Hp can't hash anything but bytes") - return hash_to_field(msg, count, dst, q, 1, 64, expand_message_xmd, hashlib.sha256) - - -def Hp2(msg, count, dst): - if not isinstance(msg, bytes): - raise ValueError("Hp2 can't hash anything but bytes") - return hash_to_field(msg, count, dst, q, 2, 64, expand_message_xmd, hashlib.sha256) diff --git a/src/dashbls/python-impl/hd_keys.py b/src/dashbls/python-impl/hd_keys.py deleted file mode 100644 index 1acdb311e00a..000000000000 --- a/src/dashbls/python-impl/hd_keys.py +++ /dev/null @@ -1,90 +0,0 @@ -from ec import G1Generator, G2Generator, JacobianPoint, default_ec -from hkdf import extract_expand -from private_key import PrivateKey -from util import hash256 - - -def key_gen(seed: bytes) -> PrivateKey: - # KeyGen - # 1. PRK = HKDF-Extract("BLS-SIG-KEYGEN-SALT-", IKM || I2OSP(0, 1)) - # 2. OKM = HKDF-Expand(PRK, keyInfo || I2OSP(L, 2), L) - # 3. SK = OS2IP(OKM) mod r - # 4. return SK - - L = 48 - # `ceil((3 * ceil(log2(r))) / 16)`, where `r` is the order of the BLS 12-381 curve - okm = extract_expand(L, seed + bytes([0]), b"BLS-SIG-KEYGEN-SALT-", bytes([0, L])) - return PrivateKey(int.from_bytes(okm, "big") % default_ec.n) - - -def ikm_to_lamport_sk(ikm: bytes, salt: bytes) -> bytes: - return extract_expand(32 * 255, ikm, salt, b"") - - -def parent_sk_to_lamport_pk(parent_sk: PrivateKey, index: int) -> bytes: - salt = index.to_bytes(4, "big") - ikm = bytes(parent_sk) - not_ikm = bytes([e ^ 0xFF for e in ikm]) # Flip bits - lamport0 = ikm_to_lamport_sk(ikm, salt) - lamport1 = ikm_to_lamport_sk(not_ikm, salt) - - lamport_pk = bytes() - for i in range(255): - lamport_pk += hash256(lamport0[i * 32 : (i + 1) * 32]) - for i in range(255): - lamport_pk += hash256(lamport1[i * 32 : (i + 1) * 32]) - - return hash256(lamport_pk) - - -def derive_child_sk(parent_sk: PrivateKey, index: int) -> PrivateKey: - """ - Derives a hardened EIP-2333 child private key, from a parent private key, - at the specified index. - """ - lamport_pk = parent_sk_to_lamport_pk(parent_sk, index) - return key_gen(lamport_pk) - - -def derive_child_sk_unhardened(parent_sk: PrivateKey, index: int) -> PrivateKey: - """ - Derives an unhardened BIP-32 child private key, from a parent private key, - at the specified index. WARNING: this key is not as secure as a hardened key. - """ - h = hash256(bytes(parent_sk.get_g1()) + index.to_bytes(4, "big")) - return PrivateKey.aggregate([PrivateKey.from_bytes(h), parent_sk]) - - -def derive_child_g1_unhardened(parent_pk: JacobianPoint, index: int) -> JacobianPoint: - """ - Derives an unhardened BIP-32 child public key, from a parent public key, - at the specified index. WARNING: this key is not as secure as a hardened key. - """ - h = hash256(bytes(parent_pk) + index.to_bytes(4, "big")) - return parent_pk + PrivateKey.from_bytes(h).value * G1Generator() - - -def derive_child_g2_unhardened(parent_pk: JacobianPoint, index: int) -> JacobianPoint: - """ - Derives an unhardened BIP-32 child public key, from a parent public key, - at the specified index. WARNING: this key is not as secure as a hardened key. - """ - h = hash256(bytes(parent_pk) + index.to_bytes(4, "big")) - return parent_pk + PrivateKey.from_bytes(h) * G2Generator() - - -""" -Copyright 2020 Chia Network Inc - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" diff --git a/src/dashbls/python-impl/hkdf.py b/src/dashbls/python-impl/hkdf.py deleted file mode 100644 index 02c21bb4f74e..000000000000 --- a/src/dashbls/python-impl/hkdf.py +++ /dev/null @@ -1,53 +0,0 @@ -import hashlib -import hmac -from math import ceil - -BLOCK_SIZE = 32 - - -def extract(salt: bytes, ikm: bytes) -> bytes: - h = hmac.new(salt, ikm, hashlib.sha256) - return h.digest() - - -def expand(L: int, prk: bytes, info: bytes) -> bytes: - N: int = ceil(L / BLOCK_SIZE) - bytes_written: int = 0 - okm: bytes = b"" - - for i in range(1, N + 1): - if i == 1: - h = hmac.new(prk, info + bytes([1]), hashlib.sha256) - T: bytes = h.digest() - else: - h = hmac.new(prk, T + info + bytes([i]), hashlib.sha256) - T = h.digest() - to_write = L - bytes_written - if to_write > BLOCK_SIZE: - to_write = BLOCK_SIZE - okm += T[:to_write] - bytes_written += to_write - assert bytes_written == L - return okm - - -def extract_expand(L: int, key: bytes, salt: bytes, info: bytes) -> bytes: - prk = extract(salt, key) - return expand(L, prk, info) - - -""" -Copyright 2020 Chia Network Inc - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" diff --git a/src/dashbls/python-impl/impl-test.py b/src/dashbls/python-impl/impl-test.py deleted file mode 100644 index 0b5141075672..000000000000 --- a/src/dashbls/python-impl/impl-test.py +++ /dev/null @@ -1,663 +0,0 @@ -import hashlib -from copy import deepcopy -from secrets import token_bytes - -from ec import (G1FromBytes, G1Generator, G1Infinity, G2FromBytes, G2Generator, - G2Infinity, JacobianPoint, default_ec, default_ec_twist, - sign_Fq2, twist, untwist, y_for_x) -from fields import Fq, Fq2, Fq6, Fq12 -from hash_to_field import expand_message_xmd -from hkdf import expand, extract -from op_swu_g2 import g2_map -from pairing import ate_pairing -from private_key import PrivateKey -from schemes import AugSchemeMPL, BasicSchemeMPL, PopSchemeMPL - -G1Element = JacobianPoint -G2Element = JacobianPoint - - -def test_hkdf(): - def test_one_case( - ikm_hex, salt_hex, info_hex, prk_expected_hex, okm_expected_hex, L - ): - prk = extract(bytes.fromhex(salt_hex), bytes.fromhex(ikm_hex)) - okm = expand(L, prk, bytes.fromhex(info_hex)) - assert len(bytes.fromhex(prk_expected_hex)) == 32 - assert L == len(bytes.fromhex(okm_expected_hex)) - assert prk == bytes.fromhex(prk_expected_hex) - assert okm == bytes.fromhex(okm_expected_hex) - - test_case_1 = ( - "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", - "000102030405060708090a0b0c", - "f0f1f2f3f4f5f6f7f8f9", - "077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5", - "3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865", - 42, - ) - test_case_2 = ( - "000102030405060708090a0b0c0d0e0f" - "101112131415161718191a1b1c1d1e1f" - "202122232425262728292a2b2c2d2e2f" - "303132333435363738393a3b3c3d3e3f" - "404142434445464748494a4b4c4d4e4f", - "606162636465666768696a6b6c6d6e6f" - "707172737475767778797a7b7c7d7e7f" - "808182838485868788898a8b8c8d8e8f" - "909192939495969798999a9b9c9d9e9f" - "a0a1a2a3a4a5a6a7a8a9aaabacadaeaf", - "b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" - "c0c1c2c3c4c5c6c7c8c9cacbcccdcecf" - "d0d1d2d3d4d5d6d7d8d9dadbdcdddedf" - "e0e1e2e3e4e5e6e7e8e9eaebecedeeef" - "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "06a6b88c5853361a06104c9ceb35b45cef760014904671014a193f40c15fc244", - "b11e398dc80327a1c8e7f78c596a4934" - "4f012eda2d4efad8a050cc4c19afa97c" - "59045a99cac7827271cb41c65e590e09" - "da3275600c2f09b8367793a9aca3db71" - "cc30c58179ec3e87c14c01d5c1f3434f" - "1d87", - 82, - ) - test_case_3 = ( - "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", - "", - "", - "19ef24a32c717b167f33a91d6f648bdf96596776afdb6377ac434c1c293ccb04", - "8da4e775a563c18f715f802a063c5a31b8a11f5c5ee1879ec3454e5f3c738d2d9d201395faa4b61a96c8", - 42, - ) - test_case_4 = ( - "8704f9ac024139fe62511375cf9bc534c0507dcf00c41603ac935cd5943ce0b4b88599390de14e743ca2f56a73a04eae13aa3f3b969b39d8701e0d69a6f8d42f", - "53d8e19b", - "", - "eb01c9cd916653df76ffa61b6ab8a74e254ebfd9bfc43e624cc12a72b0373dee", - "8faabea85fc0c64e7ca86217cdc6dcdc88551c3244d56719e630a3521063082c46455c2fd5483811f9520a748f0099c1dfcfa52c54e1c22b5cdf70efb0f3c676", - 64, - ) - - test_one_case(*test_case_1) - test_one_case(*test_case_2) - test_one_case(*test_case_3) - test_one_case(*test_case_4) - - -def test_eip2333(): - def test_one_case(seed_hex, master_sk_hex, child_sk_hex, child_index): - master = BasicSchemeMPL.key_gen(bytes.fromhex(seed_hex)) - child = BasicSchemeMPL.derive_child_sk(master, child_index) - - assert len(bytes(master)) == 32 - assert len(bytes(child)) == 32 - assert bytes(master) == bytes.fromhex(master_sk_hex) - assert bytes(child) == bytes.fromhex(child_sk_hex) - - test_case_1 = ( - "3141592653589793238462643383279502884197169399375105820974944592", - "4ff5e145590ed7b71e577bb04032396d1619ff41cb4e350053ed2dce8d1efd1c", - "5c62dcf9654481292aafa3348f1d1b0017bbfb44d6881d26d2b17836b38f204d", - 3141592653, - ) - test_case_2 = ( - "0099FF991111002299DD7744EE3355BBDD8844115566CC55663355668888CC00", - "1ebd704b86732c3f05f30563dee6189838e73998ebc9c209ccff422adee10c4b", - "1b98db8b24296038eae3f64c25d693a269ef1e4d7ae0f691c572a46cf3c0913c", - 4294967295, - ) - test_case_3 = ( - "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3", - "614d21b10c0e4996ac0608e0e7452d5720d95d20fe03c59a3321000a42432e1a", - "08de7136e4afc56ae3ec03b20517d9c1232705a747f588fd17832f36ae337526", - 42, - ) - test_case_intermediate = ( - "c55257c360c07c72029aebc1b53c05ed0362ada38ead3e3e9efa3708e53495531f09a6987599d18264c1e1c92f2cf141630c7a3c4ab7c81b2f001698e7463b04", - "0befcabff4a664461cc8f190cdd51c05621eb2837c71a1362df5b465a674ecfb", - "1a1de3346883401f1e3b2281be5774080edb8e5ebe6f776b0f7af9fea942553a", - 0, - ) - test_one_case(*test_case_1) - test_one_case(*test_case_2) - test_one_case(*test_case_3) - test_one_case(*test_case_intermediate) - - -def test_fields(): - a = Fq(17, 30) - b = Fq(17, -18) - c = Fq2(17, a, b) - d = Fq2(17, a + a, Fq(17, -5)) - e = c * d - f = e * d - assert f != e - e_sq = e * e - e_sqrt = e_sq.modsqrt() - assert pow(e_sqrt, 2) == e_sq - - a2 = Fq( - 172487123095712930573140951348, - 3012492130751239573498573249085723940848571098237509182375, - ) - b2 = Fq(172487123095712930573140951348, 3432984572394572309458723045723849) - c2 = Fq2(172487123095712930573140951348, a2, b2) - assert b2 != c2 - - g = Fq6(17, c, d, d * d * c) - h = Fq6(17, a + a * c, c * b * a, b * b * d * Fq(17, 21)) - i = Fq12(17, g, h) - assert ~(~i) == i - assert (~(i.root)) * i.root == Fq6.one(17) - x = Fq12(17, Fq6.zero(17), i.root) - assert (~x) * x == Fq12.one(17) - - j = Fq6(17, a + a * c, Fq2.zero(17), Fq2.zero(17)) - j2 = Fq6(17, a + a * c, Fq2.zero(17), Fq2.one(17)) - assert j == (a + a * c) - assert j2 != (a + a * c) - assert j != j2 - - # Test frob_coeffs - one = Fq(default_ec.q, 1) - two = one + one - a = Fq2(default_ec.q, two, two) - b = Fq6(default_ec.q, a, a, a) - c = Fq12(default_ec.q, b, b) - for base in (a, b, c): - for expo in range(1, base.extension): - assert base.qi_power(expo) == pow(base, pow(default_ec.q, expo)) - - -def test_ec(): - q = default_ec.q - g = G1Generator() - - assert g.is_on_curve() - assert 2 * g == g + g - assert (3 * g).is_on_curve() - assert 3 * g == g + g + g - - g2 = G2Generator() - assert g2.x * (Fq(q, 2) * g2.y) == Fq(q, 2) * (g2.x * g2.y) - assert g2.is_on_curve() - s = g2 + g2 - assert untwist(twist(s.to_affine())) == s.to_affine() - assert untwist(5 * twist(s.to_affine())) == (5 * s).to_affine() - assert 5 * twist(s.to_affine()) == twist((5 * s).to_affine()) - assert s.is_on_curve() - assert g2.is_on_curve() - assert g2 + g2 == 2 * g2 - assert g2 * 5 == (g2 * 2) + (2 * g2) + g2 - y = y_for_x(g2.x, default_ec_twist, Fq2) - assert y == g2.y or -y == g2.y - - g_j = G1Generator() - g2_j = G2Generator() - g2_j2 = G2Generator() * 2 - assert g.to_affine().to_jacobian() == g - assert (g_j * 2).to_affine() == g.to_affine() * 2 - assert (g2_j + g2_j2).to_affine() == g2.to_affine() * 3 - - -def test_edge_case_sign_Fq2(): - q = default_ec.q - a = Fq(q, 62323) - test_case_1 = Fq2(q, a, Fq(q, 0)) - test_case_2 = Fq2(q, -a, Fq(q, 0)) - assert sign_Fq2(test_case_1) != sign_Fq2(test_case_2) - - test_case_3 = Fq2(q, Fq(q, 0), a) - test_case_4 = Fq2(q, Fq(q, 0), -a) - - assert sign_Fq2(test_case_3) != sign_Fq2(test_case_4) - - -def test_xmd(): - msg = token_bytes(48) - dst = token_bytes(16) - ress = {} - for length in range(16, 8192): - result = expand_message_xmd(msg, dst, length, hashlib.sha512) - assert length == len(result) - key = result[:16] - ress[key] = ress.get(key, 0) + 1 - assert all(x == 1 for x in ress.values()) - - -def test_swu(): - dst_1 = b"QUUX-V01-CS02-with-BLS12381G2_XMD:SHA-256_SSWU_RO_" - msg_1 = b"abcdef0123456789" - res = g2_map(msg_1, dst_1).to_affine() - assert ( - res.x[0].value - == 0x121982811D2491FDE9BA7ED31EF9CA474F0E1501297F68C298E9F4C0028ADD35AEA8BB83D53C08CFC007C1E005723CD0 - ) - assert ( - res.x[1].value - == 0x190D119345B94FBD15497BCBA94ECF7DB2CBFD1E1FE7DA034D26CBBA169FB3968288B3FAFB265F9EBD380512A71C3F2C - ) - assert ( - res.y[0].value - == 0x05571A0F8D3C08D094576981F4A3B8EDA0A8E771FCDCC8ECCEAF1356A6ACF17574518ACB506E435B639353C2E14827C8 - ) - assert ( - res.y[1].value - == 0x0BB5E7572275C567462D91807DE765611490205A941A5A6AF3B1691BFE596C31225D3AABDF15FAFF860CB4EF17C7C3BE - ) - - -def test_elements(): - i1 = int.from_bytes(bytes([1, 2]), byteorder="big") - i2 = int.from_bytes(bytes([3, 1, 4, 1, 5, 9]), byteorder="big") - b1 = i1 - b2 = i2 - g1 = G1Generator() - g2 = G2Generator() - u1 = G1Infinity() - u2 = G2Infinity() - - x1 = g1 * b1 - x2 = g1 * b2 - y1 = g2 * b1 - y2 = g2 * b2 - - # G1 - assert x1 != x2 - assert x1 * b1 == b1 * x1 - assert x1 * b1 != x1 * b2 - - left = x1 + u1 - right = x1 - - assert left == right - assert x1 + x2 == x2 + x1 - assert x1 + x1.negate() == u1 - assert x1 == G1FromBytes(bytes(x1)) - copy = deepcopy(x1) - assert x1 == copy - x1 += x2 - assert x1 != copy - - # G2 - assert y1 != y2 - assert y1 * b1 == b1 * y1 - assert y1 * b1 != y1 * b2 - assert y1 + u2 == y1 - assert y1 + y2 == y2 + y1 - assert y1 + y1.negate() == u2 - assert y1 == G2FromBytes(bytes(y1)) - copy = deepcopy(y1) - assert y1 == copy - y1 += y2 - assert y1 != copy - - # pairing operation - pair = ate_pairing(x1, y1) - assert pair != ate_pairing(x1, y2) - assert pair != ate_pairing(x2, y1) - copy = deepcopy(pair) - assert pair == copy - pair = None - assert pair != copy - - sk = 728934712938472938472398074 - pk = sk * g1 - Hm = y2 * 12371928312 + y2 * 12903812903891023 - - sig = Hm * sk - - assert ate_pairing(g1, sig) == ate_pairing(pk, Hm) - - -def test_chia_vectors_1(): - seed1: bytes = bytes([0x00] * 32) - seed2: bytes = bytes([0x01] * 32) - msg1: bytes = bytes([7, 8, 9]) - msg2: bytes = bytes([10, 11, 12]) - sk1 = BasicSchemeMPL.key_gen(seed1) - sk2 = BasicSchemeMPL.key_gen(seed2) - assert ( - bytes(sk1).hex() - == "4a353be3dac091a0a7e640620372f5e1e2e4401717c1e79cac6ffba8f6905604" - ) - assert ( - bytes(sk1.get_g1()).hex() - == "85695fcbc06cc4c4c9451f4dce21cbf8de3e5a13bf48f44cdbb18e2038ba7b8bb1632d7911ef1e2e08749bddbf165352" - ) - - sig1 = BasicSchemeMPL.sign(sk1, msg1) - sig2 = BasicSchemeMPL.sign(sk2, msg2) - - assert ( - bytes(sig1).hex() - == "b8faa6d6a3881c9fdbad803b170d70ca5cbf1e6ba5a586262df368c75acd1d1ffa3ab6ee21c71f844494659878f5eb230c958dd576b08b8564aad2ee0992e85a1e565f299cd53a285de729937f70dc176a1f01432129bb2b94d3d5031f8065a1" - ) - assert bytes(sig2).hex() == ( - "a9c4d3e689b82c7ec7e838dac2380cb014f9a08f6cd6ba044c263746e39a8f7a60ffee4afb7" - "8f146c2e421360784d58f0029491e3bd8ab84f0011d258471ba4e87059de295d9aba845c044e" - "e83f6cf2411efd379ef38bf4cf41d5f3c0ae1205d" - ) - - agg_sig_1 = BasicSchemeMPL.aggregate([sig1, sig2]) - - assert bytes(agg_sig_1).hex() == ( - "aee003c8cdaf3531b6b0ca354031b0819f7586b5846796615aee8108fec75ef838d181f9d24" - "4a94d195d7b0231d4afcf06f27f0cc4d3c72162545c240de7d5034a7ef3a2a03c0159de982fb" - "c2e7790aeb455e27beae91d64e077c70b5506dea3" - ) - - assert BasicSchemeMPL.aggregate_verify( - [sk1.get_g1(), sk2.get_g1()], [msg1, msg2], agg_sig_1 - ) - - msg3: bytes = bytes([1, 2, 3]) - msg4: bytes = bytes([1, 2, 3, 4]) - msg5: bytes = bytes([1, 2]) - - sig3 = BasicSchemeMPL.sign(sk1, msg3) - sig4 = BasicSchemeMPL.sign(sk1, msg4) - sig5 = BasicSchemeMPL.sign(sk2, msg5) - - agg_sig_2 = BasicSchemeMPL.aggregate([sig3, sig4, sig5]) - assert BasicSchemeMPL.aggregate_verify( - [sk1.get_g1(), sk1.get_g1(), sk2.get_g1()], [msg3, msg4, msg5], agg_sig_2 - ) - - assert bytes(agg_sig_2).hex() == ( - "a0b1378d518bea4d1100adbc7bdbc4ff64f2c219ed6395cd36fe5d2aa44a4b8e710b607afd9" - "65e505a5ac3283291b75413d09478ab4b5cfbafbeea366de2d0c0bcf61deddaa521f6020460f" - "d547ab37659ae207968b545727beba0a3c5572b9c" - ) - - -def test_chia_vectors_2(): - msg1 = bytes([1, 2, 3, 40]) - msg2 = bytes([5, 6, 70, 201]) - msg3 = bytes([9, 10, 11, 12, 13]) - msg4 = bytes([15, 63, 244, 92, 0, 1]) - - seed1 = bytes([0x02] * 32) - seed2 = bytes([0x03] * 32) - - sk1 = AugSchemeMPL.key_gen(seed1) - sk2 = AugSchemeMPL.key_gen(seed2) - - pk1 = sk1.get_g1() - pk2 = sk2.get_g1() - - sig1 = AugSchemeMPL.sign(sk1, msg1) - sig2 = AugSchemeMPL.sign(sk2, msg2) - sig3 = AugSchemeMPL.sign(sk2, msg1) - sig4 = AugSchemeMPL.sign(sk1, msg3) - sig5 = AugSchemeMPL.sign(sk1, msg1) - sig6 = AugSchemeMPL.sign(sk1, msg4) - - agg_sig_l = AugSchemeMPL.aggregate([sig1, sig2]) - agg_sig_r = AugSchemeMPL.aggregate([sig3, sig4, sig5]) - agg_sig = AugSchemeMPL.aggregate([agg_sig_l, agg_sig_r, sig6]) - - assert AugSchemeMPL.aggregate_verify( - [pk1, pk2, pk2, pk1, pk1, pk1], [msg1, msg2, msg1, msg3, msg1, msg4], agg_sig - ) - - assert bytes(agg_sig).hex() == ( - "a1d5360dcb418d33b29b90b912b4accde535cf0e52caf467a005dc632d9f7af44b6c4e9acd4" - "6eac218b28cdb07a3e3bc087df1cd1e3213aa4e11322a3ff3847bbba0b2fd19ddc25ca964871" - "997b9bceeab37a4c2565876da19382ea32a962200" - ) - - -def test_chia_vectors_3(): - seed1: bytes = bytes([0x04] * 32) - sk1 = PopSchemeMPL.key_gen(seed1) - proof = PopSchemeMPL.pop_prove(sk1) - assert ( - bytes(proof).hex() - == "84f709159435f0dc73b3e8bf6c78d85282d19231555a8ee3b6e2573aaf66872d9203fefa1ef" - "700e34e7c3f3fb28210100558c6871c53f1ef6055b9f06b0d1abe22ad584ad3b957f3018a8f5" - "8227c6c716b1e15791459850f2289168fa0cf9115" - ) - - -def test_pyecc_vectors(): - ref_sig1Basic = b"\x96\xba4\xfa\xc3<\x7f\x12\x9d`*\x0b\xc8\xa3\xd4?\x9a\xbc\x01N\xce\xaa\xb75\x91F\xb4\xb1P\xe5{\x80\x86Es\x8f5g\x1e\x9e\x10\xe0\xd8b\xa3\x0c\xabp\x07N\xb5\x83\x1d\x13\xe6\xa5\xb1b\xd0\x1e\xeb\xe6\x87\xd0\x16J\xdb\xd0\xa8d7\n|\"*'h\xd7pM\xa2T\xf1\xbf\x18#f[\xc26\x1f\x9d\xd8\xc0\x0e\x99" - ref_sig2Basic = b'\xa4\x02y\t2\x13\x0fvj\xf1\x1b\xa7\x16Sf\x83\xd8\xc4\xcf\xa5\x19G\xe4\xf9\x08\x1f\xed\xd6\x92\xd6\xdc\x0c\xac[\x90K\xee^\xa6\xe2Ui\xe3m{\xe4\xcaY\x06\x9a\x96\xe3K\x7fp\x07X\xb7\x16\xf9IJ\xaaY\xa9nt\xd1J;U*\x9ak\xc1)\xe7\x17\x19[\x9d`\x06\xfdm\\\xefGh\xc0"\xe0\xf71j\xbf' - ref_sigABasic = b"\x98|\xfd;\xcdb(\x02\x87\x02t\x83\xf2\x9cU$^\xd81\xf5\x1d\xd6\xbd\x99\x9ao\xf1\xa1\xf1\xf1\xf0\xb6Gw\x8b\x01g5\x9cqPUX\xa7n\x15\x8ef\x18\x1e\xe5\x12Y\x05\xa6B$k\x01\xe7\xfa^\xe5=h\xa4\xfe\x9b\xfb)\xa8\xe2f\x01\xf0\xb9\xadW}\xdd\x18\x87js1|!n\xa6\x1fC\x04\x14\xecQ\xc5" - ref_sig1Aug = b'\x81\x80\xf0,\xcbr\xe9"\xb1R\xfc\xed\xbe\x0e\x1d\x19R\x105Opp6X\xe8\xe0\x8c\xbe\xbf\x11\xd4\x97\x0e\xabj\xc3\xcc\xf7\x15\xf3\xfb\x87m\xf9\xa9yz\xbd\x0c\x1a\xf6\x1a\xae\xad\xc9,,\xfe\\\nV\xc1F\xcc\x8c?qQ\xa0s\xcf_\x16\xdf8$g$\xc4\xae\xd7?\xf3\x0e\xf5\xda\xa6\xaa\xca\xed\x1a&\xec\xaa3k' - ref_sig2Aug = b'\x99\x11\x1e\xea\xfbA-\xa6\x1eL7\xd3\xe8\x06\xc6\xfdj\xc9\xf3\x87\x0eT\xda\x92"\xbaNIH"\xc5\xb7eg1\xfazdY4\xd0KU\x9e\x92a\xb8b\x01\xbb\xeeW\x05RP\xa4Y\xa2\xda\x10\xe5\x1f\x9c\x1aiA)\x7f\xfc]\x97\nUr6\xd0\xbd\xeb|\xf8\xff\x18\x80\x0b\x08c8q\xa0\xf0\xa7\xeaB\xf4t\x80' - ref_sigAAug = b"\x8c]\x03\xf9\xda\xe7~\x19\xa5\x94Z\x06\xa2\x14\x83n\xdb\x8e\x03\xb8QR]\x84\xb9\xded@\xe6\x8f\xc0\xcas\x03\xee\xed9\r\x86<\x9bU\xa8\xcfmY\x14\n\x01\xb5\x88G\x88\x1e\xb5\xafgsMD\xb2UVF\xc6al9\xab\x88\xd2S)\x9a\xcc\x1e\xb1\xb1\x9d\xdb\x9b\xfc\xbev\xe2\x8a\xdd\xf6q\xd1\x16\xc0R\xbb\x18G" - ref_sig1Pop = b"\x95P\xfbN\x7f~\x8c\xc4\xa9\x0b\xe8V\n\xb5\xa7\x98\xb0\xb20\x00\xb6\xa5J!\x17R\x02\x10\xf9\x86\xf3\xf2\x81\xb3v\xf2Y\xc0\xb7\x80b\xd1\xeb1\x92\xb3\xd9\xbb\x04\x9fY\xec\xc1\xb0:pI\xebf^\r\xf3d\x94\xaeL\xb5\xf1\x13l\xca\xee\xfc\x99X\xcb0\xc33==C\xf0qH\xc3\x86)\x9a{\x1b\xfc\r\xc5\xcf|" - ref_sig2Pop = b"\xa6\x906\xbc\x11\xae^\xfc\xbfa\x80\xaf\xe3\x9a\xdd\xde~'s\x1e\xc4\x02W\xbf\xdc<7\xf1{\x8d\xf6\x83\x06\xa3N\xbd\x10\xe9\xe3*5%7P\xdf\\\x87\xc2\x14/\x82\x07\xe8\xd5eG\x12\xb4\xe5T\xf5\x85\xfbhF\xff8\x04\xe4)\xa9\xf8\xa1\xb4\xc5ku\xd0\x86\x9e\xd6u\x80\xd7\x89\x87\x0b\xab\xe2\xc7\xc8\xa9\xd5\x1e{*" - ref_sigAPop = b"\xa4\xeat+\xcd\xc1U>\x9c\xa4\xe5`\xbe~^ln\xfajd\xdd\xdf\x9c\xa3\xbb(T#=\x85\xa6\xaa\xc1\xb7n\xc7\xd1\x03\xdbN3\x14\x8b\x82\xaf\x99#\xdb\x05\x93Jn\xce\x9aq\x01\xcd\x8a\x9dG\xce'\x97\x80V\xb0\xf5\x90\x00!\x81\x8cEi\x8a\xfd\xd6\xcf\x8ako\x7f\xee\x1f\x0bCqoU\xe4\x13\xd4\xb8z`9" - - secret1 = bytes([1] * 32) - secret2 = bytes([x * 314159 % 256 for x in range(32)]) - sk1 = PrivateKey.from_bytes(secret1) - sk2 = PrivateKey.from_bytes(secret2) - - msg = bytes([3, 1, 4, 1, 5, 9]) - sig1Basic = BasicSchemeMPL.sign(sk1, msg) - sig2Basic = BasicSchemeMPL.sign(sk2, msg) - sigABasic = BasicSchemeMPL.aggregate([sig1Basic, sig2Basic]) - sig1Aug = AugSchemeMPL.sign(sk1, msg) - sig2Aug = AugSchemeMPL.sign(sk2, msg) - sigAAug = AugSchemeMPL.aggregate([sig1Aug, sig2Aug]) - sig1Pop = PopSchemeMPL.sign(sk1, msg) - sig2Pop = PopSchemeMPL.sign(sk2, msg) - sigAPop = PopSchemeMPL.aggregate([sig1Pop, sig2Pop]) - - assert bytes(sig1Basic) == ref_sig1Basic - print(bytes(sig1Basic).hex()) - assert bytes(sig2Basic) == ref_sig2Basic - assert bytes(sigABasic) == ref_sigABasic - assert bytes(sig1Aug) == ref_sig1Aug - assert bytes(sig2Aug) == ref_sig2Aug - assert bytes(sigAAug) == ref_sigAAug - assert bytes(sig1Pop) == ref_sig1Pop - assert bytes(sig2Pop) == ref_sig2Pop - assert bytes(sigAPop) == ref_sigAPop - - -def test_vectors_invalid(): - # Invalid inputs from https://github.com/algorand/bls_sigs_ref/blob/master/python-impl/serdesZ.py - invalid_inputs_1 = [ - # infinity points: too short - "c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - # infinity points: not all zeros - "c00000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000", - # bad tags - "3a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa", - "7a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa", - "fa0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa", - # wrong length for compresed point - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa", - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaaaa", - # invalid x-coord - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa", - # invalid elm of Fp --- equal to p (must be strictly less) - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab", - ] - invalid_inputs_2 = [ - # infinity points: too short - "c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - # infinity points: not all zeros - "c00000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000", - # bad tags - "3a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "7a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "fa0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - # wrong length for compressed point - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - # invalid x-coord - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaa7", - # invalid elm of Fp --- equal to p (must be strictly less) - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab", - ] - - for s in invalid_inputs_1: - bytes_ = bytes.fromhex(s) - try: - g1 = G1FromBytes(bytes_) - assert g1 is not None - assert False, "Failed to disallow creation of G1 element." - except Exception: - pass - - for s in invalid_inputs_2: - bytes_ = bytes.fromhex(s) - try: - g2 = G2FromBytes(bytes_) - assert g2 is not None - assert False, "Failed to disallow creation of G2 element." - except Exception: - pass - - -def test_readme(): - seed: bytes = bytes( - [ - 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, - ] - ) - sk: PrivateKey = AugSchemeMPL.key_gen(seed) - pk: G1Element = sk.get_g1() - - message: bytes = bytes([1, 2, 3, 4, 5]) - signature: G2Element = AugSchemeMPL.sign(sk, message) - - ok: bool = AugSchemeMPL.verify(pk, message, signature) - assert ok - - sk_bytes: bytes = bytes(sk) # 32 bytes - pk_bytes: bytes = bytes(pk) # 48 bytes - signature_bytes: bytes = bytes(signature) # 96 bytes - - print(sk_bytes.hex(), pk_bytes.hex(), signature_bytes.hex()) - - sk = PrivateKey.from_bytes(sk_bytes) - assert sk is not None - pk = G1FromBytes(pk_bytes) - assert pk is not None - signature: G2Element = G2FromBytes(signature_bytes) - - seed = bytes([1]) + seed[1:] - sk1: PrivateKey = AugSchemeMPL.key_gen(seed) - seed = bytes([2]) + seed[1:] - sk2: PrivateKey = AugSchemeMPL.key_gen(seed) - message2: bytes = bytes([1, 2, 3, 4, 5, 6, 7]) - - pk1: G1Element = sk1.get_g1() - sig1: G2Element = AugSchemeMPL.sign(sk1, message) - - pk2: G1Element = sk2.get_g1() - sig2: G2Element = AugSchemeMPL.sign(sk2, message2) - - agg_sig: G2Element = AugSchemeMPL.aggregate([sig1, sig2]) - - ok = AugSchemeMPL.aggregate_verify([pk1, pk2], [message, message2], agg_sig) - assert ok - - seed = bytes([3]) + seed[1:] - sk3: PrivateKey = AugSchemeMPL.key_gen(seed) - pk3: G1Element = sk3.get_g1() - message3: bytes = bytes([100, 2, 254, 88, 90, 45, 23]) - sig3: G2Element = AugSchemeMPL.sign(sk3, message3) - - agg_sig_final: G2Element = AugSchemeMPL.aggregate([agg_sig, sig3]) - ok = AugSchemeMPL.aggregate_verify( - [pk1, pk2, pk3], [message, message2, message3], agg_sig_final - ) - assert ok - - pop_sig1: G2Element = PopSchemeMPL.sign(sk1, message) - pop_sig2: G2Element = PopSchemeMPL.sign(sk2, message) - pop_sig3: G2Element = PopSchemeMPL.sign(sk3, message) - pop1: G2Element = PopSchemeMPL.pop_prove(sk1) - pop2: G2Element = PopSchemeMPL.pop_prove(sk2) - pop3: G2Element = PopSchemeMPL.pop_prove(sk3) - - ok = PopSchemeMPL.pop_verify(pk1, pop1) - assert ok - ok = PopSchemeMPL.pop_verify(pk2, pop2) - assert ok - ok = PopSchemeMPL.pop_verify(pk3, pop3) - assert ok - - pop_sig_agg: G2Element = PopSchemeMPL.aggregate([pop_sig1, pop_sig2, pop_sig3]) - - ok = PopSchemeMPL.fast_aggregate_verify([pk1, pk2, pk3], message, pop_sig_agg) - assert ok - - pop_agg_pk: G1Element = pk1 + pk2 + pk3 - ok = PopSchemeMPL.verify(pop_agg_pk, message, pop_sig_agg) - assert ok - - pop_agg_sk: PrivateKey = PrivateKey.aggregate([sk1, sk2, sk3]) - ok = PopSchemeMPL.sign(pop_agg_sk, message) == pop_sig_agg - assert ok - - master_sk: PrivateKey = AugSchemeMPL.key_gen(seed) - child: PrivateKey = AugSchemeMPL.derive_child_sk(master_sk, 152) - grandchild: PrivateKey = AugSchemeMPL.derive_child_sk(child, 952) - assert grandchild is not None - - master_pk: G1Element = master_sk.get_g1() - child_u: PrivateKey = AugSchemeMPL.derive_child_sk_unhardened(master_sk, 22) - grandchild_u: PrivateKey = AugSchemeMPL.derive_child_sk_unhardened(child_u, 0) - - child_u_pk: G1Element = AugSchemeMPL.derive_child_pk_unhardened(master_pk, 22) - grandchild_u_pk: G1Element = AugSchemeMPL.derive_child_pk_unhardened(child_u_pk, 0) - - ok = grandchild_u_pk == grandchild_u.get_g1() - assert ok - - -test_hkdf() -test_eip2333() -test_fields() -test_ec() -test_xmd() -test_swu() -test_edge_case_sign_Fq2() -test_elements() -test_chia_vectors_1() -test_chia_vectors_2() -test_chia_vectors_3() -test_pyecc_vectors() -test_vectors_invalid() -test_readme() diff --git a/src/dashbls/python-impl/op_swu_g2.py b/src/dashbls/python-impl/op_swu_g2.py deleted file mode 100644 index afdb40cf714b..000000000000 --- a/src/dashbls/python-impl/op_swu_g2.py +++ /dev/null @@ -1,214 +0,0 @@ -#!/usr/bin/python -# -# pure Python implementation of optimized simplified SWU map to BLS12-381 G2 -# https://github.com/algorand/bls_sigs_ref -# -# This software is (C) 2019 Algorand, Inc. -# -# Licensed under the MIT license (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://opensource.org/licenses/MIT - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from bls12381 import h_eff, q -from ec import JacobianPoint, default_ec_twist, eval_iso -from fields import Fq, Fq2, roots_of_unity -from hash_to_field import Hp2 -from typing import Union - - -def sgn0(x: Fq2) -> int: - # https://tools.ietf.org/html/draft-irtf-cfrg-hash-to-curve-07#section-4.1 - - sign_0: int = x[0].value % 2 - zero_0: bool = x[0] == 0 - sign_1: int = x[1].value % 2 - return sign_0 or (zero_0 and sign_1) - - -# distinguished non-square in Fp2 for SWU map -xi_2 = Fq2(q, -2, -1) - -# 3-isogenous curve parameters -Ell2p_a = Fq2(q, 0, 240) -Ell2p_b = Fq2(q, 1012, 1012) - - -# eta values, used for computing sqrt(g(X1(t))) -# For details on how to compute, see ../sage-impl/opt_sswu_g2.sage -ev1 = 0x699BE3B8C6870965E5BF892AD5D2CC7B0E85A117402DFD83B7F4A947E02D978498255A2AAEC0AC627B5AFBDF1BF1C90 -ev2 = 0x8157CD83046453F5DD0972B6E3949E4288020B5B8A9CC99CA07E27089A2CE2436D965026ADAD3EF7BABA37F2183E9B5 -ev3 = 0xAB1C2FFDD6C253CA155231EB3E71BA044FD562F6F72BC5BAD5EC46A0B7A3B0247CF08CE6C6317F40EDBC653A72DEE17 -ev4 = 0xAA404866706722864480885D68AD0CCAC1967C7544B447873CC37E0181271E006DF72162A3D3E0287BF597FBF7F8FC1 -etas = (Fq2(q, ev1, ev2), Fq2(q, q - ev2, ev1), Fq2(q, ev3, ev4), Fq2(q, q - ev4, ev3)) -del ev1, ev2, ev3, ev4 - - -# -# Simplified SWU map, optimized and adapted to Ell2' -# -# This function maps an element of Fp^2 to the curve Ell2', 3-isogenous to Ell2. -def osswu2_help(t): - assert isinstance(t, Fq2) - - # first, compute X0(t), detecting and handling exceptional case - num_den_common = xi_2 ** 2 * t ** 4 + xi_2 * t ** 2 - x0_num = Ell2p_b * (num_den_common + Fq(q, 1)) - x0_den = -Ell2p_a * num_den_common - x0_den = Ell2p_a * xi_2 if x0_den == 0 else x0_den - - # compute num and den of g(X0(t)) - gx0_den = pow(x0_den, 3) - gx0_num = Ell2p_b * gx0_den - gx0_num += Ell2p_a * x0_num * pow(x0_den, 2) - gx0_num += pow(x0_num, 3) - - # try taking sqrt of g(X0(t)) - # this uses the trick for combining division and sqrt from Section 5 of - # Bernstein, Duif, Lange, Schwabe, and Yang, "High-speed high-security signatures." - # J Crypt Eng 2(2):77--89, Sept. 2012. http://ed25519.cr.yp.to/ed25519-20110926.pdf - tmp1 = pow(gx0_den, 7) # v^7 - tmp2 = gx0_num * tmp1 # u v^7 - tmp1 = tmp1 * tmp2 * gx0_den # u v^15 - sqrt_candidate = tmp2 * pow(tmp1, (q ** 2 - 9) // 16) - - # check if g(X0(t)) is square and return the sqrt if so - for root in roots_of_unity: - y0 = sqrt_candidate * root - if y0 ** 2 * gx0_den == gx0_num: - # found sqrt(g(X0(t))). force sign of y to equal sign of t - if sgn0(y0) != sgn0(t): - y0 = -y0 - assert sgn0(y0) == sgn0(t) - return JacobianPoint( - x0_num * x0_den, y0 * pow(x0_den, 3), x0_den, False, default_ec_twist - ) - - # if we've gotten here, then g(X0(t)) is not square. convert srqt_candidate to sqrt(g(X1(t))) - (x1_num, x1_den) = (xi_2 * t ** 2 * x0_num, x0_den) - (gx1_num, gx1_den) = (xi_2 ** 3 * t ** 6 * gx0_num, gx0_den) - sqrt_candidate *= t ** 3 - for eta in etas: - y1 = eta * sqrt_candidate - if y1 ** 2 * gx1_den == gx1_num: - # found sqrt(g(X1(t))). force sign of y to equal sign of t - if sgn0(y1) != sgn0(t): - y1 = -y1 - assert sgn0(y1) == sgn0(t) - return JacobianPoint( - x1_num * x1_den, y1 * pow(x1_den, 3), x1_den, False, default_ec_twist - ) - - # if we got here, something is wrong - raise RuntimeError("osswu2_help failed for unknown reasons") - - -# -# 3-Isogeny from Ell2' to Ell2 -# -# coefficients for the 3-isogeny map from Ell2' to Ell2 -xnum = ( - Fq2( - q, - 0x5C759507E8E333EBB5B7A9A47D7ED8532C52D39FD3A042A88B58423C50AE15D5C2638E343D9C71C6238AAAAAAAA97D6, - 0x5C759507E8E333EBB5B7A9A47D7ED8532C52D39FD3A042A88B58423C50AE15D5C2638E343D9C71C6238AAAAAAAA97D6, - ), - Fq2( - q, - 0x0, - 0x11560BF17BAA99BC32126FCED787C88F984F87ADF7AE0C7F9A208C6B4F20A4181472AAA9CB8D555526A9FFFFFFFFC71A, - ), - Fq2( - q, - 0x11560BF17BAA99BC32126FCED787C88F984F87ADF7AE0C7F9A208C6B4F20A4181472AAA9CB8D555526A9FFFFFFFFC71E, - 0x8AB05F8BDD54CDE190937E76BC3E447CC27C3D6FBD7063FCD104635A790520C0A395554E5C6AAAA9354FFFFFFFFE38D, - ), - Fq2( - q, - 0x171D6541FA38CCFAED6DEA691F5FB614CB14B4E7F4E810AA22D6108F142B85757098E38D0F671C7188E2AAAAAAAA5ED1, - 0x0, - ), -) -xden = ( - Fq2( - q, - 0x0, - 0x1A0111EA397FE69A4B1BA7B6434BACD764774B84F38512BF6730D2A0F6B0F6241EABFFFEB153FFFFB9FEFFFFFFFFAA63, - ), - Fq2( - q, - 0xC, - 0x1A0111EA397FE69A4B1BA7B6434BACD764774B84F38512BF6730D2A0F6B0F6241EABFFFEB153FFFFB9FEFFFFFFFFAA9F, - ), - Fq2(q, 0x1, 0x0), -) -ynum = ( - Fq2( - q, - 0x1530477C7AB4113B59A4C18B076D11930F7DA5D4A07F649BF54439D87D27E500FC8C25EBF8C92F6812CFC71C71C6D706, - 0x1530477C7AB4113B59A4C18B076D11930F7DA5D4A07F649BF54439D87D27E500FC8C25EBF8C92F6812CFC71C71C6D706, - ), - Fq2( - q, - 0x0, - 0x5C759507E8E333EBB5B7A9A47D7ED8532C52D39FD3A042A88B58423C50AE15D5C2638E343D9C71C6238AAAAAAAA97BE, - ), - Fq2( - q, - 0x11560BF17BAA99BC32126FCED787C88F984F87ADF7AE0C7F9A208C6B4F20A4181472AAA9CB8D555526A9FFFFFFFFC71C, - 0x8AB05F8BDD54CDE190937E76BC3E447CC27C3D6FBD7063FCD104635A790520C0A395554E5C6AAAA9354FFFFFFFFE38F, - ), - Fq2( - q, - 0x124C9AD43B6CF79BFBF7043DE3811AD0761B0F37A1E26286B0E977C69AA274524E79097A56DC4BD9E1B371C71C718B10, - 0x0, - ), -) -yden = ( - Fq2( - q, - 0x1A0111EA397FE69A4B1BA7B6434BACD764774B84F38512BF6730D2A0F6B0F6241EABFFFEB153FFFFB9FEFFFFFFFFA8FB, - 0x1A0111EA397FE69A4B1BA7B6434BACD764774B84F38512BF6730D2A0F6B0F6241EABFFFEB153FFFFB9FEFFFFFFFFA8FB, - ), - Fq2( - q, - 0x0, - 0x1A0111EA397FE69A4B1BA7B6434BACD764774B84F38512BF6730D2A0F6B0F6241EABFFFEB153FFFFB9FEFFFFFFFFA9D3, - ), - Fq2( - q, - 0x12, - 0x1A0111EA397FE69A4B1BA7B6434BACD764774B84F38512BF6730D2A0F6B0F6241EABFFFEB153FFFFB9FEFFFFFFFFAA99, - ), - Fq2(q, 0x1, 0x0), -) - - -# compute 3-isogeny map from Ell2' to Ell2 -def iso3(P): - return eval_iso(P, (xnum, xden, ynum, yden), default_ec_twist) - - -# -# map from Fq2 element(s) to point in G2 subgroup of Ell2 -# -def opt_swu2_map(t: Fq2, t2: Union[Fq2, None] = None) -> JacobianPoint: - Pp = iso3(osswu2_help(t)) - if t2 is not None: - Pp2 = iso3(osswu2_help(t2)) - Pp = Pp + Pp2 - return Pp * h_eff - - -# -# map from bytes() to point in G2 subgroup of Ell2 -# -def g2_map(alpha: bytes, dst=None): - return opt_swu2_map(*(Fq2(q, *hh) for hh in Hp2(alpha, 2, dst))) diff --git a/src/dashbls/python-impl/pairing.py b/src/dashbls/python-impl/pairing.py deleted file mode 100644 index ca752311e5fc..000000000000 --- a/src/dashbls/python-impl/pairing.py +++ /dev/null @@ -1,136 +0,0 @@ -from collections import namedtuple -from typing import List - -import bls12381 -from ec import AffinePoint, JacobianPoint, untwist -from fields import Fq, Fq12 - -# Struct for elliptic curve parameters -EC = namedtuple("EC", "q a b gx gy g2x g2y n h x k sqrt_n3 sqrt_n3m1o2") - -default_ec = EC(*bls12381.parameters()) -default_ec_twist = EC(*bls12381.parameters()) - - -def int_to_bits(i: int) -> List[int]: - if i < 1: - return [0] - bits = [] - while i != 0: - bits.append(i % 2) - i = i // 2 - return list(reversed(bits)) - - -def double_line_eval(R: AffinePoint, P: AffinePoint, ec=default_ec): - """ - Creates an equation for a line tangent to R, - and evaluates this at the point P. f(x) = y - sv - v. - f(P). - """ - R12 = untwist(R) - - slope = (Fq(ec.q, 3) * (R12.x ** 2) + ec.a) / (Fq(ec.q, 2) * R12.y) - v = R12.y - slope * R12.x - - return P.y - P.x * slope - v - - -def add_line_eval(R: AffinePoint, Q: AffinePoint, P: AffinePoint, ec=default_ec) -> Fq: - """ - Creates an equation for a line between R and Q, - and evaluates this at the point P. f(x) = y - sv - v. - f(P). - """ - R12 = untwist(R) - Q12 = untwist(Q) - - # This is the case of a vertical line, where the denominator - # will be 0. - if R12 == Q12.negate(): - return P.x - R12.x - - slope = (Q12.y - R12.y) / (Q12.x - R12.x) - v = (Q12.y * R12.x - R12.y * Q12.x) / (R12.x - Q12.x) - - return P.y - P.x * slope - v - - -def miller_loop(T: int, P: AffinePoint, Q: AffinePoint, ec=default_ec) -> Fq12: - """ - Performs a double and add algorithm for the ate pairing. This algorithm - is taken from Craig Costello's "Pairing for Beginners". - """ - T_bits = int_to_bits(T) - R = Q - f = Fq12.one(ec.q) # f is an element of Fq12 - for i in range(1, len(T_bits)): - # Compute sloped line lrr - lrr = double_line_eval(R, P, ec) - f = f * f * lrr - - R = Fq(ec.q, 2) * R - if T_bits[i] == 1: - # Compute sloped line lrq - lrq = add_line_eval(R, Q, P, ec) - f = f * lrq - - R = R + Q - return f - - -def final_exponentiation(element: Fq12, ec=default_ec) -> Fq12: - """ - Performs a final exponentiation to map the result of the Miller - loop to a unique element of Fq12. - """ - if ec.k == 12: - ans = element ** ((pow(ec.q, 4) - pow(ec.q, 2) + 1) // ec.n) - ans = ans.qi_power(2) * ans - ans = ans.qi_power(6) / ans - return ans - else: - return element ** ((pow(ec.q, ec.k) - 1) // ec.n) - - -def ate_pairing(P: JacobianPoint, Q: JacobianPoint, ec=default_ec) -> Fq12: - """ - Performs one ate pairing. - """ - t = default_ec.x + 1 - T = abs(t - 1) - element = miller_loop(T, P.to_affine(), Q.to_affine(), ec) - return final_exponentiation(element, ec) - - -def ate_pairing_multi( - Ps: List[JacobianPoint], Qs: List[JacobianPoint], ec=default_ec -) -> Fq12: - """ - Computes multiple pairings at once. This is more efficient, - since we can multiply all the results of the miller loops, - and perform just one final exponentiation. - """ - t = default_ec.x + 1 - T = abs(t - 1) - prod = Fq12.one(ec.q) - for i in range(len(Qs)): - prod *= miller_loop(T, Ps[i].to_affine(), Qs[i].to_affine(), ec) - return final_exponentiation(prod, ec) - - -""" -Copyright 2020 Chia Network Inc - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" diff --git a/src/dashbls/python-impl/private_key.py b/src/dashbls/python-impl/private_key.py deleted file mode 100644 index 200bd6304d12..000000000000 --- a/src/dashbls/python-impl/private_key.py +++ /dev/null @@ -1,81 +0,0 @@ -from __future__ import annotations - -from ec import G1Generator, default_ec -from hkdf import extract_expand - - -class PrivateKey: - """ - Private keys are just random integers between 1 and the group order. - """ - - PRIVATE_KEY_SIZE = 32 - - def __init__(self, value): - assert value < default_ec.n - self.value = value - - @staticmethod - def from_bytes(buffer): - return PrivateKey(int.from_bytes(buffer, "big") % default_ec.n) - - @staticmethod - def from_seed(seed): - L = 48 - # `ceil((3 * ceil(log2(r))) / 16)`, where `r` is the order of the BLS 12-381 curve - okm = extract_expand( - L, seed + bytes([0]), b"BLS-SIG-KEYGEN-SALT-", bytes([0, L]) - ) - return PrivateKey(int.from_bytes(okm, "big") % default_ec.n) - - @staticmethod - def from_int(n: int): - return PrivateKey(n % default_ec.n) - - def get_g1(self): - return self.value * G1Generator() - - def sign(self, m): - pass - - def __eq__(self, other): - return self.value == other.value - - def __hash__(self): - return self.value - - def __bytes__(self): - return self.value.to_bytes(self.PRIVATE_KEY_SIZE, "big") - - def size(self): - return self.PRIVATE_KEY_SIZE - - def __str__(self): - return "PrivateKey(0x" + bytes(self).hex() + ")" - - def __repr__(self): - return "PrivateKey(0x" + bytes(self).hex() + ")" - - @staticmethod - def aggregate(private_keys): - """ - Aggregates private keys together - """ - return PrivateKey(sum(pk.value for pk in private_keys) % default_ec.n) - - -""" -Copyright 2020 Chia Network Inc - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" diff --git a/src/dashbls/python-impl/schemes.py b/src/dashbls/python-impl/schemes.py deleted file mode 100644 index 7b7a1d9730f1..000000000000 --- a/src/dashbls/python-impl/schemes.py +++ /dev/null @@ -1,209 +0,0 @@ -from typing import List - -from ec import G1Generator, JacobianPoint, default_ec -from fields import Fq12 -from hd_keys import (derive_child_g1_unhardened, derive_child_sk, - derive_child_sk_unhardened, key_gen) -from op_swu_g2 import g2_map -from pairing import ate_pairing_multi -from private_key import PrivateKey - -basic_scheme_dst = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_" -aug_scheme_dst = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_AUG_" -pop_scheme_dst = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_" -pop_scheme_pop_dst = b"BLS_POP_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_" - - -def core_sign_mpl(sk: PrivateKey, message: bytes, dst: bytes) -> JacobianPoint: - return sk.value * g2_map(message, dst) - - -def core_verify_mpl( - pk: JacobianPoint, message: bytes, signature: JacobianPoint, dst: bytes -) -> bool: - try: - signature.check_valid() - pk.check_valid() - except AssertionError: - return False - q = g2_map(message, dst) - one = Fq12.one(default_ec.q) - pairing_result = ate_pairing_multi([pk, G1Generator().negate()], [q, signature]) - return pairing_result == one - - -def core_aggregate_mpl(signatures: List[JacobianPoint]) -> JacobianPoint: - if len(signatures) < 1: - raise ValueError("Must aggregate at least 1 signature") - aggregate = signatures[0] - aggregate.check_valid() - for signature in signatures[1:]: - signature.check_valid() - aggregate += signature - return aggregate - - -def core_aggregate_verify( - pks: List[JacobianPoint], ms: List[bytes], signature: JacobianPoint, dst: bytes -) -> bool: - if len(pks) != len(ms) or len(pks) < 1: - return False - try: - signature.check_valid() - qs = [signature] - ps = [G1Generator().negate()] - for i in range(len(pks)): - pks[i].check_valid() - qs.append(g2_map(ms[i], dst)) - ps.append(pks[i]) - return Fq12.one(default_ec.q) == ate_pairing_multi(ps, qs) - - except AssertionError: - return False - - -class BasicSchemeMPL: - @staticmethod - def key_gen(seed: bytes) -> PrivateKey: - return key_gen(seed) - - @staticmethod - def sign(sk: PrivateKey, message: bytes) -> JacobianPoint: - return core_sign_mpl(sk, message, basic_scheme_dst) - - @staticmethod - def verify(pk: JacobianPoint, message: bytes, signature: JacobianPoint) -> bool: - return core_verify_mpl(pk, message, signature, basic_scheme_dst) - - @staticmethod - def aggregate(signatures: List[JacobianPoint]) -> JacobianPoint: - return core_aggregate_mpl(signatures) - - @staticmethod - def aggregate_verify( - pks: List[JacobianPoint], ms: List[bytes], signature: JacobianPoint - ) -> bool: - if len(pks) != len(ms) or len(pks) < 1: - return False - if len(set(ms)) != len(ms): - # Disallow repeated messages - return False - return core_aggregate_verify(pks, ms, signature, basic_scheme_dst) - - @staticmethod - def derive_child_sk(sk: PrivateKey, index: int) -> PrivateKey: - return derive_child_sk(sk, index) - - @staticmethod - def derive_child_sk_unhardened(sk: PrivateKey, index: int) -> PrivateKey: - return derive_child_sk_unhardened(sk, index) - - @staticmethod - def derive_child_pk_unhardened(pk: JacobianPoint, index: int) -> JacobianPoint: - return derive_child_g1_unhardened(pk, index) - - -class AugSchemeMPL: - @staticmethod - def key_gen(seed: bytes) -> PrivateKey: - return key_gen(seed) - - @staticmethod - def sign(sk: PrivateKey, message: bytes) -> JacobianPoint: - pk = sk.get_g1() - return core_sign_mpl(sk, bytes(pk) + message, aug_scheme_dst) - - @staticmethod - def verify(pk: JacobianPoint, message: bytes, signature: JacobianPoint) -> bool: - return core_verify_mpl(pk, bytes(pk) + message, signature, aug_scheme_dst) - - @staticmethod - def aggregate(signatures: List[JacobianPoint]) -> JacobianPoint: - return core_aggregate_mpl(signatures) - - @staticmethod - def aggregate_verify( - pks: List[JacobianPoint], ms: List[bytes], signature: JacobianPoint - ) -> bool: - if len(pks) != len(ms) or len(pks) < 1: - return False - m_primes = [bytes(pks[i]) + ms[i] for i in range(len(pks))] - return core_aggregate_verify(pks, m_primes, signature, aug_scheme_dst) - - @staticmethod - def derive_child_sk(sk: PrivateKey, index: int) -> PrivateKey: - return derive_child_sk(sk, index) - - @staticmethod - def derive_child_sk_unhardened(sk: PrivateKey, index: int) -> PrivateKey: - return derive_child_sk_unhardened(sk, index) - - @staticmethod - def derive_child_pk_unhardened(pk: JacobianPoint, index: int) -> JacobianPoint: - return derive_child_g1_unhardened(pk, index) - - -class PopSchemeMPL: - @staticmethod - def key_gen(seed: bytes) -> PrivateKey: - return key_gen(seed) - - @staticmethod - def sign(sk: PrivateKey, message: bytes) -> JacobianPoint: - return core_sign_mpl(sk, message, pop_scheme_dst) - - @staticmethod - def verify(pk: JacobianPoint, message: bytes, signature: JacobianPoint) -> bool: - return core_verify_mpl(pk, message, signature, pop_scheme_dst) - - @staticmethod - def aggregate(signatures: List[JacobianPoint]) -> JacobianPoint: - return core_aggregate_mpl(signatures) - - @staticmethod - def aggregate_verify( - pks: List[JacobianPoint], ms: List[bytes], signature: JacobianPoint - ) -> bool: - if len(pks) != len(ms) or len(pks) < 1: - return False - return core_aggregate_verify(pks, ms, signature, pop_scheme_dst) - - @staticmethod - def pop_prove(sk: PrivateKey) -> JacobianPoint: - pk: JacobianPoint = sk.get_g1() - return sk.value * g2_map(bytes(pk), pop_scheme_pop_dst) - - @staticmethod - def pop_verify(pk: JacobianPoint, proof: JacobianPoint) -> bool: - try: - proof.check_valid() - pk.check_valid() - q = g2_map(bytes(pk), pop_scheme_pop_dst) - one = Fq12.one(default_ec.q) - pairing_result = ate_pairing_multi([pk, G1Generator().negate()], [q, proof]) - return pairing_result == one - except AssertionError: - return False - - @staticmethod - def fast_aggregate_verify( - pks: List[JacobianPoint], message: bytes, signature: JacobianPoint - ) -> bool: - if len(pks) < 1: - return False - aggregate: JacobianPoint = pks[0] - for pk in pks[1:]: - aggregate += pk - return core_verify_mpl(aggregate, message, signature, pop_scheme_dst) - - @staticmethod - def derive_child_sk(sk: PrivateKey, index: int) -> PrivateKey: - return derive_child_sk(sk, index) - - @staticmethod - def derive_child_sk_unhardened(sk: PrivateKey, index: int) -> PrivateKey: - return derive_child_sk_unhardened(sk, index) - - @staticmethod - def derive_child_pk_unhardened(pk: JacobianPoint, index: int) -> JacobianPoint: - return derive_child_g1_unhardened(pk, index) diff --git a/src/dashbls/python-impl/util.py b/src/dashbls/python-impl/util.py deleted file mode 100644 index 09192fd681f4..000000000000 --- a/src/dashbls/python-impl/util.py +++ /dev/null @@ -1,49 +0,0 @@ -import hashlib - -HMAC_BLOCK_SIZE = 64 - - -def hash256(m): - if type(m) != bytes: - m = m.encode("utf-8") - return hashlib.sha256(m).digest() - - -def hash512(m): - if type(m) != bytes: - m = m.encode("utf-8") - return hash256(m + bytes([0])) + hash256(m + bytes([1])) - - -def hmac256(m, k): - if type(m) != bytes and type(m) != bytearray: - m = m.encode("utf-8") - if type(k) != bytes and type(k) != bytearray: - k = k.encode("utf-8") - k = bytes(k) - if len(k) > HMAC_BLOCK_SIZE: - k = hash256(k) - while len(k) < HMAC_BLOCK_SIZE: - k += bytes([0]) - opad = bytes([0x5C] * HMAC_BLOCK_SIZE) - ipad = bytes([0x36] * HMAC_BLOCK_SIZE) - kopad = bytes([k[i] ^ opad[i] for i in range(HMAC_BLOCK_SIZE)]) - kipad = bytes([k[i] ^ ipad[i] for i in range(HMAC_BLOCK_SIZE)]) - return hash256(kopad + hash256(kipad + m)) - - -""" -Copyright 2020 Chia Network Inc - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" diff --git a/src/dashbls/rust-bindings/bls-signatures/Cargo.toml b/src/dashbls/rust-bindings/bls-signatures/Cargo.toml index 5365ee42737f..c2884a42e4bf 100644 --- a/src/dashbls/rust-bindings/bls-signatures/Cargo.toml +++ b/src/dashbls/rust-bindings/bls-signatures/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bls-signatures" description = "" -version = "1.2.5" +version = "1.3.5" edition = "2021" [features] @@ -9,11 +9,11 @@ legacy = [] bip32 = [] use_serde = ["serde"] dash_helpers = ["rand"] -default = [ "legacy", "bip32", "dash_helpers", "use_serde"] +default = ["legacy", "bip32", "dash_helpers", "use_serde"] apple = ["bls-dash-sys/apple"] [dependencies] bls-dash-sys = { path = "../bls-dash-sys" } -serde = { version= "1.0.160", features = ["derive"], optional = true} -rand = { version= "0.8.5", optional = true} -hex = { version = "0.4.3"} +serde = { version = "1.0.228", features = ["derive"], optional = true } +rand = { version = "0.10.0", optional = true } +hex = { version = "0.4.3" } diff --git a/src/dashbls/rust-bindings/bls-signatures/src/private_key.rs b/src/dashbls/rust-bindings/bls-signatures/src/private_key.rs index 556c968ed2a7..898e59c92edd 100755 --- a/src/dashbls/rust-bindings/bls-signatures/src/private_key.rs +++ b/src/dashbls/rust-bindings/bls-signatures/src/private_key.rs @@ -74,7 +74,8 @@ impl PrivateKey { #[cfg(feature = "dash_helpers")] pub fn generate_dash(rng: &mut StdRng) -> Result { - let seed = rng.gen::<[u8; 32]>(); + let mut seed = [0u8; 32]; + rng.fill_bytes(&mut seed); let scheme = BasicSchemeMPL::new(); Ok(PrivateKey { c_private_key: c_err_to_result(|did_err| unsafe { diff --git a/src/dashbls/setup.py b/src/dashbls/setup.py index 7b4c0bfbbc3c..cb8f9b6b8a56 100644 --- a/src/dashbls/setup.py +++ b/src/dashbls/setup.py @@ -1,219 +1,126 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 +# coding: latin-1 + +# +# Copyright (c) 2020-present, Chia Network Inc. +# Copyright (c) 2026-present, The Dash Core developers +# SPDX-License-Identifier: Apache-2.0 +# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 +# + +"""Build configuration for the dashbls package.""" + import os -import platform import re +import shlex +import shutil import subprocess import sys -from distutils.version import LooseVersion +import sysconfig -from setuptools import Extension, setup, setuptools +from setuptools import Extension, setup from setuptools.command.build_ext import build_ext class CMakeExtension(Extension): - def __init__(self, name, sourcedir=""): - Extension.__init__(self, name, sources=["./"]) + def __init__(self, name: str, sourcedir: str = "") -> None: + super().__init__(name, sources=[]) self.sourcedir = os.path.abspath(sourcedir) class CMakeBuild(build_ext): - def run(self): + CMAKE_MINIMUM = (3, 18, 0) + WINDOWS_GENERATOR_ARCH = ( + ("win-amd64", "x64"), + ("win-arm64", "ARM64"), + ("win32", "Win32"), + ) + + def _cmake(self) -> str: + cmake = shutil.which("cmake") + if cmake is None: + raise RuntimeError("CMake must be installed to build dashbls") + return cmake + + def run(self) -> None: + cmake = self._cmake() try: - out = subprocess.check_output(["cmake", "--version"]) - except OSError: - raise RuntimeError( - "CMake must be installed to build" - + " the following extensions: " - + ", ".join(e.name for e in self.extensions) + out = subprocess.check_output( # noqa: S603 + [cmake, "--version"], encoding="utf-8", errors="replace" ) - - if platform.system() == "Windows": - cmake_version = LooseVersion( - re.search(r"version\s*([\d.]+)", out.decode()).group(1) + except (OSError, subprocess.CalledProcessError) as error: + raise RuntimeError("cannot run cmake --version") from error + found = re.search(r"version\s*([\d.]+)", out) + if found is None: + raise RuntimeError("cannot read a version out of: " + out.strip()) + parts = [int(part) for part in found.group(1).split(".")[:3] if part] + while len(parts) < len(self.CMAKE_MINIMUM): + parts.append(0) + version = tuple(parts) + if version < self.CMAKE_MINIMUM: + raise RuntimeError( + "CMake >= {} is required, found {}".format( + ".".join(str(p) for p in self.CMAKE_MINIMUM), + found.group(1), + ) ) - if cmake_version < "3.1.0": - raise RuntimeError("CMake >= 3.1.0 is required on Windows") - for ext in self.extensions: self.build_extension(ext) - def build_extension(self, ext): + def build_extension(self, ext: CMakeExtension) -> None: extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name))) cmake_args = [ + "-DBUILD_BLS_BENCHMARKS=OFF", + "-DBUILD_BLS_TESTS=OFF", "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + extdir, - "-DPYTHON_EXECUTABLE=" + sys.executable, + "-DMULTI=", + "-DPYBIND11_FINDPYTHON=ON", + "-DPython_EXECUTABLE=" + sys.executable, + "-DVERSION_INFO=" + self.distribution.get_version(), ] + cmake_args += shlex.split(os.environ.get("CMAKE_ARGS", "")) + + try: + import pybind11 + except ImportError: + pass + else: + cmake_args.append("-Dpybind11_DIR=" + pybind11.get_cmake_dir()) + cfg = "Debug" if self.debug else "Release" - build_args = ["--config", cfg] - - if platform.system() == "Windows": - cmake_args += [ - "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}".format(cfg.upper(), extdir) - ] - if sys.maxsize > 2 ** 32: - cmake_args += ["-A", "x64"] - build_args += ["--", "/m"] + build_args = ["--config", cfg, "--parallel", str(os.cpu_count() or 1)] + + if sys.platform == "win32": + target = sysconfig.get_platform() + arch = dict(self.WINDOWS_GENERATOR_ARCH).get(target) + if arch is None: + raise RuntimeError("unsupported windows platform: " + target) + cmake_args.append(f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}") + generator = os.environ.get("CMAKE_GENERATOR", "Visual Studio") + if generator.startswith("Visual Studio"): + cmake_args += ["-A", arch] + build_args += ["--", "/m"] + else: + cmake_args += ["-DCMAKE_BUILD_TYPE=" + cfg] else: cmake_args += ["-DCMAKE_BUILD_TYPE=" + cfg] - build_args += ["--", "-j", "6"] - env = os.environ.copy() - env["CXXFLAGS"] = '{} -DVERSION_INFO=\\"{}\\"'.format( - env.get("CXXFLAGS", ""), self.distribution.get_version() - ) - if not os.path.exists(self.build_temp): - os.makedirs(self.build_temp) - subprocess.check_call( - ["cmake", ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env + os.makedirs(self.build_temp, exist_ok=True) + cmake = self._cmake() + subprocess.check_call( # noqa: S603 + [cmake, ext.sourcedir, *cmake_args], cwd=self.build_temp ) - subprocess.check_call( - ["cmake", "--build", "."] + build_args, cwd=self.build_temp + subprocess.check_call( # noqa: S603 + [cmake, "--build", ".", *build_args], cwd=self.build_temp ) -class get_pybind_include(object): - """Helper class to determine the pybind11 include path - - The purpose of this class is to postpone importing pybind11 - until it is actually installed, so that the ``get_include()`` - method can be invoked.""" - - def __init__(self, user=False): - self.user = user - - def __str__(self): - import pybind11 - - return pybind11.get_include(self.user) - - -ext_modules = [ - Extension( - "blspy", - [ - "src/elements.cpp", - "src/schemes.cpp", - "src/privatekey.cpp", - "src/bls.cpp", - "python-bindings/pythonbindings.cpp", - ], - include_dirs=[ - # Path to pybind11 headers - get_pybind_include(), - get_pybind_include(user=True), - "relic_ietf_64/include", - "mpir_gc_x64", - "libsodium/include", - ], - library_dirs=[ - "relic_ietf_64", - "mpir_gc_x64", - "libsodium/x64/Release/v142/static", - ], - libraries=["relic_s", "Advapi32", "mpir", "libsodium"], - language="c++", - ), -] - - -# As of Python 3.6, CCompiler has a `has_flag` method. -# cf http://bugs.python.org/issue26689 -def has_flag(compiler, flagname): - """Return a boolean indicating whether a flag name is supported on - the specified compiler. - """ - import tempfile - - with tempfile.NamedTemporaryFile("w", suffix=".cpp") as f: - f.write("int main (int argc, char **argv) { return 0; }") - try: - compiler.compile([f.name], extra_postargs=[flagname]) - except setuptools.distutils.errors.CompileError: - return False - return True - - -def cpp_flag(compiler): - """Return the -std=c++[11/14/17] compiler flag. - - The newer version is prefered over c++11 (when it is available). - """ - flags = ["-std=c++17", "-std=c++14", "-std=c++11"] - - for flag in flags: - if has_flag(compiler, flag): - return flag - - raise RuntimeError("Unsupported compiler -- at least C++11 support " "is needed!") - - -class BuildExt(build_ext): - """A custom build extension for adding compiler-specific options.""" - - c_opts = { - "msvc": ["/EHsc", "/std:c++17", "/DBLSALLOC_SODIUM=1", "/DSODIUM_STATIC"], - "unix": [], - } - l_opts = { - "msvc": [], - "unix": [], - } - - if sys.platform == "darwin": - darwin_opts = ["-stdlib=libc++", "-mmacosx-version-min=10.14"] - c_opts["unix"] += darwin_opts - l_opts["unix"] += darwin_opts - - def build_extensions(self): - ct = self.compiler.compiler_type - opts = self.c_opts.get(ct, []) - link_opts = self.l_opts.get(ct, []) - if ct == "unix": - opts.append('-DVERSION_INFO="%s"' % self.distribution.get_version()) - opts.append(cpp_flag(self.compiler)) - if has_flag(self.compiler, "-fvisibility=hidden"): - opts.append("-fvisibility=hidden") - elif ct == "msvc": - if sys.version_info < (3, 9): - ver_flag = '/DVERSION_INFO=\"%s\"' - else: - ver_flag = '-DVERSION_INFO="%s"' - opts.append(ver_flag % self.distribution.get_version()) - for ext in self.extensions: - ext.extra_compile_args = opts - ext.extra_link_args = link_opts - build_ext.build_extensions(self) - - -if platform.system() == "Windows": - setup( - name="blspy", - author="Mariano Sorgente", - author_email="mariano@chia.net", - description="BLS signatures in c++ (with python bindings)", - long_description=open("README.md").read(), - long_description_content_type="text/markdown", - url="https://github.com/Chia-Network/bls-signatures", - python_requires=">=3.7", - setup_requires=["pybind11>=2.10.0"], - install_requires=["pybind11>=2.10.0"], - ext_modules=ext_modules, - cmdclass={"build_ext": BuildExt}, - zip_safe=False, - ) -else: - setup( - name="blspy", - author="Mariano Sorgente", - author_email="mariano@chia.net", - description="BLS signatures in c++ (python bindings)", - python_requires=">=3.7", - install_requires=["wheel"], - long_description=open("README.md").read(), - long_description_content_type="text/markdown", - url="https://github.com/Chia-Network/bls-signatures", - ext_modules=[CMakeExtension("blspy", ".")], - cmdclass=dict(build_ext=CMakeBuild), - zip_safe=False, - ) +setup( + package_dir={"": "binds/python"}, + packages=[], + py_modules=[], + ext_modules=[CMakeExtension("dashbls", os.path.dirname(os.path.abspath(__file__)))], + cmdclass=dict(build_ext=CMakeBuild), + zip_safe=False, +) diff --git a/src/dashbls/src/CMakeLists.txt b/src/dashbls/src/CMakeLists.txt index 5802843a61ed..808c238c0c4e 100644 --- a/src/dashbls/src/CMakeLists.txt +++ b/src/dashbls/src/CMakeLists.txt @@ -1,41 +1,46 @@ -file(GLOB HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/dashbls/*.hpp) +file(GLOB HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp) source_group("SrcHeaders" FILES ${HEADERS}) -add_library(dashbls +list(APPEND bls_sources ${HEADERS} - ${CMAKE_CURRENT_SOURCE_DIR}/privatekey.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/bls.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/chaincode.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/elements.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/extendedprivatekey.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/extendedpublickey.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/legacy.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/schemes.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/threshold.cpp) - -target_include_directories(dashbls - PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR} - $<$:${GMP_INCLUDES}> - ${CMAKE_CURRENT_SOURCE_DIR}/../include/dashbls - ${CMAKE_CURRENT_SOURCE_DIR}/../depends/mimalloc/include - ${CMAKE_CURRENT_SOURCE_DIR}/../depends/relic/include - ${CMAKE_CURRENT_BINARY_DIR}/../depends/relic/include + privatekey.cpp + bls.cpp + chaincode.cpp + elements.cpp + extendedprivatekey.cpp + extendedpublickey.cpp + legacy.cpp + schemes.cpp + threshold.cpp + privatekey.cpp + bls.cpp + elements.cpp + schemes.cpp + ${blst_SOURCE_DIR}/src/server.c ) -target_compile_definitions(dashbls - PRIVATE - BLSALLOC_MIMALLOC=1 -) + list(APPEND bls_sources + ${blst_SOURCE_DIR}/build/assembly.S + ) + add_compile_options(-fno-builtin) + add_compile_options(-fPIC) + add_compile_options(-Wall) + add_compile_options(-Wextra) + if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)") + add_compile_options(-mno-avx) + endif() + +add_library(dashbls ${bls_sources}) +target_include_directories(dashbls PUBLIC ${blst_SOURCE_DIR}/bindings ${PROJECT_SOURCE_DIR}/include/dashbls/) +target_compile_definitions(dashbls PRIVATE __BLST_PORTABLE__ BLSALLOC_MIMALLOC=1) target_link_libraries(dashbls PUBLIC - relic_s mimalloc-static ) -install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../depends/relic/include/ DESTINATION include/dashbls) -install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../depends/relic/include/ DESTINATION include/dashbls) +install(DIRECTORY ${blst_SOURCE_DIR}/include/ DESTINATION include/dashbls) +install(DIRECTORY ${blst_BINARY_DIR}/include/ DESTINATION include/dashbls) install(FILES ${HEADERS} DESTINATION include/dashbls) install(FILES $ DESTINATION lib) @@ -44,8 +49,9 @@ if(BUILD_BLS_TESTS) add_executable(runtest test.cpp) target_link_libraries(runtest - PRIVATE dashbls - PRIVATE catch2) + PRIVATE + dashbls + catch2) if(EMSCRIPTEN) target_link_options(runtest PRIVATE "SHELL:-s MALLOC=emmalloc") @@ -66,3 +72,14 @@ if(BUILD_BLS_BENCHMARKS) endif() endif() endif() + +if(BUILD_BLS_TESTS) + # runtest compares the library against test-vectors/reference.txt; + # vectorgen regenerates that file from whichever library it is built against. + target_compile_definitions(runtest PRIVATE + DASHBLS_REFERENCE_VECTORS="${CMAKE_CURRENT_SOURCE_DIR}/../test-vectors/reference.txt") + + add_executable(vectorgen ${CMAKE_CURRENT_SOURCE_DIR}/../tools/vectorgen.cpp) + target_include_directories(vectorgen PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) + target_link_libraries(vectorgen PRIVATE dashbls) +endif() diff --git a/src/dashbls/src/bls.cpp b/src/dashbls/src/bls.cpp index e0af3a388216..b980a2615a34 100644 --- a/src/dashbls/src/bls.cpp +++ b/src/dashbls/src/bls.cpp @@ -31,24 +31,8 @@ bool BLSInitResult = BLS::Init(); Util::SecureAllocCallback Util::secureAllocCallback; Util::SecureFreeCallback Util::secureFreeCallback; -static void relic_core_initializer(void* ptr) -{ - core_init(); - if (err_get_code() != RLC_OK) { - throw std::runtime_error("core_init() failed"); - } - - const int r = ep_param_set_any_pairf(); - if (r != RLC_OK) { - throw std::runtime_error("ep_param_set_any_pairf() failed"); - } -} - bool BLS::Init() { - if (ALLOC != AUTO) { - throw std::runtime_error("Must have ALLOC == AUTO"); - } #if BLSALLOC_MIMALLOC SetSecureAllocator(mi_malloc, mi_free); #elif BLSALLOC_SODIUM @@ -60,12 +44,6 @@ bool BLS::Init() SetSecureAllocator(malloc, free); #endif -#if MULTI != RELIC_NONE - core_set_thread_initializer(relic_core_initializer, nullptr); -#else - relic_core_initializer(nullptr); -#endif - return true; } @@ -77,18 +55,4 @@ void BLS::SetSecureAllocator( Util::secureFreeCallback = freeCb; } - -void BLS::CheckRelicErrors(bool should_throw) -{ - if (!core_get()) { - throw std::runtime_error("Library not initialized properly. Call BLS::Init()"); - } - if (core_get()->code != RLC_OK) { - core_get()->code = RLC_OK; - if (should_throw) { - throw std::invalid_argument("Relic library error"); - } - } -} - } // end namespace bls diff --git a/src/dashbls/src/chaincode.cpp b/src/dashbls/src/chaincode.cpp index efacdc95ae29..e5a7204703f9 100644 --- a/src/dashbls/src/chaincode.cpp +++ b/src/dashbls/src/chaincode.cpp @@ -14,6 +14,8 @@ #include "bls.hpp" +#include + namespace bls { ChainCode ChainCode::FromBytes(const Bytes& bytes) { @@ -21,21 +23,15 @@ ChainCode ChainCode::FromBytes(const Bytes& bytes) { throw std::invalid_argument("ChainCode::FromBytes: Invalid size"); } ChainCode c = ChainCode(); - bn_new(c.chainCode); - bn_read_bin(c.chainCode, bytes.begin(), ChainCode::SIZE); + memcpy(c.chainCode.data(), bytes.begin(), ChainCode::SIZE); return c; } -ChainCode::ChainCode(const ChainCode &cc) { - uint8_t bytes[ChainCode::SIZE]; - cc.Serialize(bytes); - bn_new(chainCode); - bn_read_bin(chainCode, bytes, ChainCode::SIZE); -} +ChainCode::ChainCode(const ChainCode &cc) : chainCode(cc.chainCode) {} // Comparator implementation. bool operator==(ChainCode const &a, ChainCode const &b) { - return bn_cmp(a.chainCode, b.chainCode) == RLC_EQ; + return a.chainCode == b.chainCode; } bool operator!=(ChainCode const &a, ChainCode const &b) { @@ -49,7 +45,7 @@ std::ostream &operator<<(std::ostream &os, ChainCode const &s) { } void ChainCode::Serialize(uint8_t *buffer) const { - bn_write_bin(buffer, ChainCode::SIZE, chainCode); + memcpy(buffer, chainCode.data(), SIZE); } std::vector ChainCode::Serialize() const { diff --git a/src/dashbls/src/elements.cpp b/src/dashbls/src/elements.cpp index b0c747af823c..37be2f3d4c98 100644 --- a/src/dashbls/src/elements.cpp +++ b/src/dashbls/src/elements.cpp @@ -12,16 +12,194 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + #include #include "bls.hpp" #include "legacy.hpp" +namespace { +// The legacy codec reproduces the byte-level behavior of the relic-based +// implementation exactly, including its handling of malformed input. relic +// was built without CHECK, so its internal errors did not throw: an +// out-of-range field element left the coordinate at zero, and a failed +// square root left y holding its pre-existing raw contents (0, or a raw +// limb 1 when the sign bit had been stored). All of it is consensus-visible +// through re-serialization and is pinned by test-vectors/reference.txt. + +// BLS12-381 base field prime p, big-endian. +static const uint8_t P_BE[48] = { + 0x1a, 0x01, 0x11, 0xea, 0x39, 0x7f, 0xe6, 0x9a, 0x4b, 0x1b, 0xa7, 0xb6, + 0x43, 0x4b, 0xac, 0xd7, 0x64, 0x77, 0x4b, 0x84, 0xf3, 0x85, 0x12, 0xbf, + 0x67, 0x30, 0xd2, 0xa0, 0xf6, 0xb0, 0xf6, 0x24, 0x1e, 0xab, 0xff, 0xfe, + 0xb1, 0x53, 0xff, 0xff, 0xb9, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xaa, 0xab}; + +// (p - 1) / 2, big-endian. The legacy sign convention is y > (p-1)/2 +// ("larger" root), matching relic's ep_pck/ep2_pck for pairing-friendly +// curves. +static const uint8_t HALF_P_BE[48] = { + 0x0d, 0x00, 0x88, 0xf5, 0x1c, 0xbf, 0xf3, 0x4d, 0x25, 0x8d, 0xd3, 0xdb, + 0x21, 0xa5, 0xd6, 0x6b, 0xb2, 0x3b, 0xa5, 0xc2, 0x79, 0xc2, 0x89, 0x5f, + 0xb3, 0x98, 0x69, 0x50, 0x7b, 0x58, 0x7b, 0x12, 0x0f, 0x55, 0xff, 0xff, + 0x58, 0xa9, 0xff, 0xff, 0xdc, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xd5, 0x55}; + +// (2^384)^-1 mod p, big-endian. When relic (built without CHECK) failed to +// find a square root during legacy point decompression with the sign bit +// set, the y coordinate was left holding a raw limb value of 1, which reads +// back from Montgomery form as this constant. Preserved bit-for-bit for +// compatibility with historical consensus data. +static const uint8_t MONT_R_INV_BE[48] = { + 0x14, 0xfe, 0xc7, 0x01, 0xe8, 0xfb, 0x0c, 0xe9, 0xed, 0x5e, 0x64, 0x27, + 0x3c, 0x4f, 0x53, 0x8b, 0x17, 0x97, 0xab, 0x14, 0x58, 0xa8, 0x8d, 0xe9, + 0x34, 0x3e, 0xa9, 0x79, 0x14, 0x95, 0x6d, 0xc8, 0x7f, 0xe1, 0x12, 0x74, + 0xd8, 0x98, 0xfa, 0xfb, 0xf4, 0xd3, 0x82, 0x59, 0x38, 0x0b, 0x48, 0x20}; + +inline void FpFromBE48(blst_fp& out, const uint8_t* be) +{ + blst_fp_from_bendian(&out, be); +} + +// Compares a big-endian 48-byte value against a constant. Returns the +// memcmp sign. +inline int CmpBE48(const uint8_t* a, const uint8_t* b) +{ + return memcmp(a, b, 48); +} + +inline void FpZero(blst_fp& out) { memset(&out, 0x00, sizeof(blst_fp)); } + +inline void FpOneConst(blst_fp& out) +{ + uint8_t be[48] = {0}; + be[47] = 1; + blst_fp_from_bendian(&out, be); +} + +// relic's ep2_upk sign rule (decompression side, with the IETF tie-break): +// sign = c1 > (p-1)/2, but when c1 == 0 the sign of c0 is used instead. +// Note the serialization side (ep2_pck) uses c1 only, with no tie-break. +inline bool Fp2SignUpk(const blst_fp2& y) +{ + uint8_t be[48]; + blst_bendian_from_fp(be, &y.fp[1]); + bool c1Zero = true; + for (int i = 0; i < 48; i++) + if (be[i] != 0) { c1Zero = false; break; } + if (!c1Zero) return CmpBE48(be, HALF_P_BE) > 0; + blst_bendian_from_fp(be, &y.fp[0]); + return CmpBE48(be, HALF_P_BE) > 0; +} + +// The "larger root" test used by both the legacy codec (relic's +// ep_pck/ep2_pck convention) and the legacy hash-to-curve: y > (p-1)/2 on +// the canonical representation. +inline bool FpSignGtHalf(const blst_fp& a) +{ + uint8_t be[48]; + blst_bendian_from_fp(be, &a); + return CmpBE48(be, HALF_P_BE) > 0; +} +} // anon namespace + namespace bls { +static void LegacyDecodeG1( + blst_p1_affine& a, + const uint8_t* bytes, + const bool signBit) +{ + uint8_t xbytes[G1Element::SIZE]; + memcpy(xbytes, bytes, G1Element::SIZE); + // the relic-based G1 codec erased the top three bits of the first byte + // unconditionally, before the sign bit was even examined (unlike G2, + // which only clears the sign bit) + xbytes[0] &= 0x1f; + + if (CmpBE48(xbytes, P_BE) >= 0) { + // relic's fp_read_bin error path: coordinate left untouched (zero) + FpZero(a.x); + } else { + FpFromBE48(a.x, xbytes); + } + + // rhs = x^3 + 4 + blst_fp rhs; + blst_fp_sqr(&rhs, &a.x); + blst_fp_mul(&rhs, &rhs, &a.x); + blst_fp four; + uint8_t fourBytes[48] = {0}; + fourBytes[47] = 4; + FpFromBE48(four, fourBytes); + blst_fp_add(&rhs, &rhs, &four); + + if (blst_fp_sqrt(&a.y, &rhs)) { + if (FpSignGtHalf(a.y) != signBit) { + blst_fp_cneg(&a.y, &a.y, true); + } + } else { + // relic's ep_upk failure: y keeps the raw sign-bit marker + if (signBit) { + FpFromBE48(a.y, MONT_R_INV_BE); + } else { + FpZero(a.y); + } + } +} + +static void LegacyDecodeG2( + blst_p2_affine& a, + const uint8_t* bytes, + const bool signBit) +{ + uint8_t c0[48], c1[48]; + memcpy(c0, bytes, 48); + memcpy(c1, bytes + 48, 48); + if (signBit) { + c0[0] &= 0x7f; + } + + if (CmpBE48(c0, P_BE) >= 0) { + FpZero(a.x.fp[0]); + } else { + FpFromBE48(a.x.fp[0], c0); + } + if (CmpBE48(c1, P_BE) >= 0) { + FpZero(a.x.fp[1]); + } else { + FpFromBE48(a.x.fp[1], c1); + } + + // rhs = x^3 + (4, 4) + blst_fp2 rhs; + blst_fp2_sqr(&rhs, &a.x); + blst_fp2_mul(&rhs, &rhs, &a.x); + blst_fp four; + uint8_t fourBytes[48] = {0}; + fourBytes[47] = 4; + FpFromBE48(four, fourBytes); + blst_fp2 b2; + b2.fp[0] = four; + b2.fp[1] = four; + blst_fp2_add(&rhs, &rhs, &b2); + + if (blst_fp2_sqrt(&a.y, &rhs)) { + if (Fp2SignUpk(a.y) != signBit) { + blst_fp2_cneg(&a.y, &a.y, true); + } + } else { + if (signBit) { + FpFromBE48(a.y.fp[0], MONT_R_INV_BE); + } else { + FpZero(a.y.fp[0]); + } + FpZero(a.y.fp[1]); + } +} const size_t G1Element::SIZE; -G1Element G1Element::FromBytes(Bytes const bytes, bool fLegacy) { +G1Element G1Element::FromBytes(Bytes const bytes, bool fLegacy) +{ G1Element ele = G1Element::FromBytesUnchecked(bytes, fLegacy); if (!fLegacy) { ele.CheckValid(); @@ -35,55 +213,46 @@ G1Element G1Element::FromBytesUnchecked(Bytes const bytes, bool fLegacy) throw std::invalid_argument("G1Element::FromBytes: Invalid size"); } - G1Element ele; - - // convert bytes to relic form - uint8_t buffer[G1Element::SIZE + 1]; - std::memcpy(buffer + 1, bytes.begin(), G1Element::SIZE); - buffer[0] = 0x00; - buffer[1] &= 0x1f; // erase 3 msbs from given input - + // check if the element is canonical + const uint8_t* raw_bytes = bytes.begin(); + bool fZerosOnly = + Util::HasOnlyZeros(Bytes(raw_bytes + 1, bytes.size() - 1)); if ((bytes[0] & 0xc0) == 0xc0) { // representing infinity - buffer[0] = 0x00; - buffer[1] &= 0x1f; // erase 3 msbs from given input - - bool fZerosOnly = Util::HasOnlyZeros(Bytes(buffer, G1Element::SIZE + 1)); // enforce that infinity must be 0xc0000..00 if (bytes[0] != 0xc0 || !fZerosOnly) { - throw std::invalid_argument("Given G1 infinity element must be canonical"); + throw std::invalid_argument( + "Given G1 infinity element must be canonical"); } + return G1Element(); // return infinity element (point all zero) + } + if (fLegacy) { + G1Element ele; + blst_p1_affine a; + LegacyDecodeG1(a, bytes.begin(), (bytes[0] & 0x80) != 0); + // Build the Jacobian point by hand: blst_p1_from_affine maps the + // all-zero affine pair to infinity, but relic kept degenerate + // decodes (e.g. x = 0, y = 0) as ordinary z=1 points, which is + // consensus-visible through re-serialization. + ele.p.x = a.x; + ele.p.y = a.y; + FpOneConst(ele.p.z); return ele; - } else { - if (fLegacy) { - if (bytes[0] & 0x80) { - buffer[0] = 0x03; // Insert extra byte for Y=1 - buffer[1] &= 0x7f; // Remove initial Y bit - } else { - buffer[0] = 0x02; // Insert extra byte for Y=0 - } - } else { - buffer[0] = 0x00; - buffer[1] &= 0x1f; // erase 3 msbs from given input - - bool fZerosOnly = Util::HasOnlyZeros(Bytes(buffer, G1Element::SIZE + 1)); - if ((bytes[0] & 0xc0) != 0x80) { - throw std::invalid_argument( - "Given G1 non-infinity element must start with 0b10"); - } - - if (fZerosOnly) { - throw std::invalid_argument("G1 non-infinity element can't have only zeros"); - } - if (bytes[0] & 0x20) { // sign bit - buffer[0] = 0x03; - } else { - buffer[0] = 0x02; - } - } } - g1_read_bin(ele.p, buffer, G1Element::SIZE + 1); - BLS::CheckRelicErrors(!fLegacy); - return ele; + if ((bytes[0] & 0xc0) != 0x80) { + throw std::invalid_argument( + "Given G1 non-infinity element must start with 0b10"); + } + if (fZerosOnly) { + throw std::invalid_argument( + "G1 non-infinity element can't have only zeros"); + } + + blst_p1_affine a; + BLST_ERROR err = blst_p1_uncompress(&a, bytes.begin()); + if (err != BLST_SUCCESS) + throw std::invalid_argument("G1Element::FromBytes: Invalid bytes"); + + return G1Element::FromAffine(a); } G1Element G1Element::FromByteVector(const std::vector& bytevec, bool fLegacy) @@ -91,35 +260,46 @@ G1Element G1Element::FromByteVector(const std::vector& bytevec, bool fL return G1Element::FromBytes(Bytes(bytevec), fLegacy); } -G1Element G1Element::FromNative(const g1_t element) +G1Element G1Element::FromNative(const blst_p1& element) { G1Element ele; - g1_copy(ele.p, element); + memcpy(&(ele.p), &element, sizeof(blst_p1)); return ele; } -G1Element G1Element::Copy() { +G1Element G1Element::FromAffine(const blst_p1_affine& element) +{ G1Element ele; - g1_copy(ele.p, this->p); - + blst_p1_from_affine(&(ele.p), &element); return ele; } - -G1Element G1Element::FromMessage(const std::vector& message, - const uint8_t* dst, - int dst_len) +G1Element G1Element::FromMessage( + const std::vector& message, + const uint8_t* dst, + int dst_len) { return FromMessage(Bytes(message), dst, dst_len); } -G1Element G1Element::FromMessage(Bytes const message, - const uint8_t* dst, - int dst_len) +G1Element G1Element::FromMessage( + Bytes const message, + const uint8_t* dst, + int dst_len) { G1Element ans; - ep_map_dst(ans.p, message.begin(), (int)message.size(), dst, dst_len); - BLS::CheckRelicErrors(); + const byte* aug = nullptr; + size_t aug_len = 0; + + blst_hash_to_g1( + &(ans.p), + message.begin(), + (int)message.size(), + dst, + dst_len, + aug, + aug_len); + assert(ans.IsValid()); return ans; } @@ -127,35 +307,42 @@ G1Element G1Element::FromMessage(Bytes const message, G1Element G1Element::Generator() { G1Element ele; - g1_get_gen(ele.p); - BLS::CheckRelicErrors(); + ele.p = *(blst_p1_generator()); return ele; } -bool G1Element::IsValid() const { - // Infinity no longer valid in Relic - // https://github.com/relic-toolkit/relic/commit/f3be2babb955cf9f82743e0ae5ef265d3da6c02b - if (g1_is_infty((g1_st*)p) == 1) +bool G1Element::IsValid() const +{ + // Infinity was considered a valid G1Element in older Relic versions + // on which this library was previously based. + // For historical compatibililty this behavior is maintained. + + if (blst_p1_is_inf(&p)) return true; - return g1_is_valid((g1_st*)p); + return blst_p1_in_g1(&p); } -void G1Element::CheckValid() const { +void G1Element::CheckValid() const +{ if (!IsValid()) throw std::invalid_argument("G1 element is invalid"); - BLS::CheckRelicErrors(); } -void G1Element::ToNative(g1_t output) const { - g1_copy(output, p); +void G1Element::ToNative(blst_p1* output) const +{ + memcpy(output, &p, sizeof(blst_p1)); +} + +void G1Element::ToAffine(blst_p1_affine* output) const +{ + blst_p1_to_affine(output, &p); } G1Element G1Element::Negate() const { - G1Element ans; - g1_neg(ans.p, p); - BLS::CheckRelicErrors(); + G1Element ans = G1Element::FromNative(p); + blst_p1_cneg(&(ans.p), true); return ans; } @@ -165,84 +352,83 @@ uint32_t G1Element::GetFingerprint(const bool fLegacy) const { uint8_t buffer[G1Element::SIZE]; uint8_t hash[32]; - memcpy(buffer, Serialize(fLegacy).data(), G1Element::SIZE); + memcpy(buffer, SerializeToArray(fLegacy).data(), G1Element::SIZE); Util::Hash256(hash, buffer, G1Element::SIZE); return Util::FourBytesToInt(hash); } -std::vector G1Element::Serialize(const bool fLegacy) const { - const auto arr = G1Element::SerializeToArray(fLegacy); +std::vector G1Element::Serialize(const bool fLegacy) const +{ + const auto arr = SerializeToArray(fLegacy); return std::vector{arr.begin(), arr.end()}; } -std::array G1Element::SerializeToArray(const bool fLegacy) const { - uint8_t buffer[G1Element::SIZE + 1]; - g1_write_bin(buffer, G1Element::SIZE + 1, p, 1); - +std::array G1Element::SerializeToArray(const bool fLegacy) const +{ std::array result{}; - if (buffer[0] == 0x00) { // infinity - result[0] = 0xc0; + if (!fLegacy) { + blst_p1_compress(result.data(), &p); return result; } - if (buffer[0] == 0x03) { // sign bit set - buffer[1] |= fLegacy ? 0x80 : 0x20; + if (blst_p1_is_inf(&p)) { + result[0] = 0xc0; + return result; } - if (!fLegacy) { - buffer[1] |= 0x80; // indicate compression + blst_p1_affine a; + blst_p1_to_affine(&a, &p); + blst_bendian_from_fp(result.data(), &a.x); + if (FpSignGtHalf(a.y)) { + result[0] |= 0x80; } - - std::copy_n(buffer + 1, G1Element::SIZE, result.begin()); return result; } -bool operator==(const G1Element & a, const G1Element &b) +bool operator==(const G1Element& a, const G1Element& b) { - return g1_cmp(a.p, b.p) == RLC_EQ; + return blst_p1_is_equal(&(a.p), &(b.p)); } -bool operator!=(const G1Element & a, const G1Element & b) { return !(a == b); } +bool operator!=(const G1Element& a, const G1Element& b) { return !(a == b); } -std::ostream& operator<<(std::ostream& os, const G1Element &ele) +std::ostream& operator<<(std::ostream& os, const G1Element& ele) { return os << Util::HexStr(ele.Serialize()); } G1Element& operator+=(G1Element& a, const G1Element& b) { - g1_add(a.p, a.p, b.p); - BLS::CheckRelicErrors(); + blst_p1_add_or_double(&(a.p), &(a.p), &(b.p)); return a; } G1Element operator+(const G1Element& a, const G1Element& b) { G1Element ans; - g1_add(ans.p, a.p, b.p); - BLS::CheckRelicErrors(); + blst_p1_add_or_double(&(ans.p), &(a.p), &(b.p)); return ans; } -G1Element operator*(const G1Element& a, const bn_t& k) +G1Element operator*(const G1Element& a, const blst_scalar& k) { G1Element ans; - g1_mul(ans.p, (g1_st*)a.p, (bn_st*)k); - BLS::CheckRelicErrors(); + byte* bte = Util::SecAlloc(32); + blst_lendian_from_scalar(bte, &k); + blst_p1_mult(&(ans.p), &(a.p), bte, 256); + Util::SecFree(bte); + return ans; } -G1Element operator*(const bn_t& k, const G1Element& a) { return a * k; } - - +G1Element operator*(const blst_scalar& k, const G1Element& a) { return a * k; } // G2Element definitions below - - const size_t G2Element::SIZE; -G2Element G2Element::FromBytes(Bytes const bytes, const bool fLegacy) { +G2Element G2Element::FromBytes(Bytes const bytes, const bool fLegacy) +{ G2Element ele = G2Element::FromBytesUnchecked(bytes, fLegacy); if (!fLegacy) { ele.CheckValid(); @@ -256,59 +442,59 @@ G2Element G2Element::FromBytesUnchecked(Bytes const bytes, const bool fLegacy) throw std::invalid_argument("G2Element::FromBytes: Invalid size"); } - G2Element ele; - uint8_t buffer[G2Element::SIZE + 1]; - if (fLegacy) { - std::memcpy(buffer + 1, bytes.begin(), G2Element::SIZE); - buffer[0] = 0x00; - } else { - std::memcpy(buffer + 1, bytes.begin() + G2Element::SIZE / 2, G2Element::SIZE / 2); - std::memcpy(buffer + 1 + G2Element::SIZE / 2, bytes.begin(), G2Element::SIZE / 2); - buffer[0] = 0x00; - buffer[49] &= 0x1f; // erase 3 msbs from input - if ((bytes[48] & 0xe0) != 0x00) { + // The relic implementation computed its zeros-only check over a + // buffer that still contained the first byte unmasked, so for the + // legacy G2 codec any input with the two top bits set - canonical + // infinity included - was rejected as non-canonical. + if ((bytes[0] & 0xc0) == 0xc0) { throw std::invalid_argument( - "Given G2 element must always have 48th byte start with 0b000"); + "Given G2 infinity element must be canonical"); } + G2Element ele; + blst_p2_affine a; + LegacyDecodeG2(a, bytes.begin(), (bytes[0] & 0x80) != 0); + // See the G1 legacy path: keep degenerate all-zero decodes as + // ordinary z=1 points instead of mapping them to infinity. + ele.q.x = a.x; + ele.q.y = a.y; + FpOneConst(ele.q.z.fp[0]); + FpZero(ele.q.z.fp[1]); + return ele; + } + + if ((bytes[48] & 0xe0) != 0x00) { + throw std::invalid_argument( + "Given G2 element must always have 48th byte start with 0b000"); } - bool fZerosOnly = Util::HasOnlyZeros(Bytes(buffer, G2Element::SIZE + 1)); - if (((bytes[0] & 0xc0) == 0xc0)) { // infinity + + bool fZerosOnly = (bytes[0] & 0x1f) == 0 && + Util::HasOnlyZeros(Bytes(bytes.begin() + 1, bytes.size() - 1)); + if ((bytes[0] & 0xc0) == 0xc0) { // infinity // enforce that infinity must be 0xc0000..00 if (bytes[0] != 0xc0 || !fZerosOnly) { throw std::invalid_argument( "Given G2 infinity element must be canonical"); } - return ele; + return G2Element(); } - if (fLegacy) { - if (bytes[0] & 0x80) { - buffer[0] = 0x03; // Insert extra byte for Y=1 - buffer[1] &= 0x7f; // Remove initial Y bit - } else { - buffer[0] = 0x02; // Insert extra byte for Y=0 - } - } else { - if (((bytes[0] & 0xc0) != 0x80)) { - throw std::invalid_argument( - "G2 non-inf element must have 0th byte start with 0b10"); - } - - if (fZerosOnly) { - throw std::invalid_argument("G2 non-infinity element can't have only zeros"); - } + if ((bytes[0] & 0xc0) != 0x80) { + throw std::invalid_argument( + "G2 non-inf element must have 0th byte start with 0b10"); + } - if (bytes[0] & 0x20) { - buffer[0] = 0x03; - } else { - buffer[0] = 0x02; - } + if (fZerosOnly) { + throw std::invalid_argument( + "G2 non-infinity element can't have only zeros"); } - g2_read_bin(ele.q, buffer, G2Element::SIZE + 1); - BLS::CheckRelicErrors(!fLegacy); - return ele; + blst_p2_affine a; + BLST_ERROR err = blst_p2_uncompress(&a, bytes.begin()); + if (err != BLST_SUCCESS) + throw std::invalid_argument("G2Element::FromBytes: Invalid bytes"); + + return G2Element::FromAffine(a); } G2Element G2Element::FromByteVector(const std::vector& bytevec, bool fLegacy) @@ -316,33 +502,51 @@ G2Element G2Element::FromByteVector(const std::vector& bytevec, bool fL return G2Element::FromBytes(Bytes(bytevec), fLegacy); } -G2Element G2Element::FromNative(const g2_t element) +G2Element G2Element::FromNative(const blst_p2& element) { G2Element ele; - g2_copy(ele.q, (g2_st*)element); + memcpy(&(ele.q), &element, sizeof(blst_p2)); return ele; } -G2Element G2Element::FromMessage(const std::vector& message, - const uint8_t* dst, - int dst_len, - const bool fLegacy) +G2Element G2Element::FromAffine(const blst_p2_affine& element) +{ + G2Element ele; + blst_p2_from_affine(&(ele.q), &element); + return ele; +} + +G2Element G2Element::FromMessage( + const std::vector& message, + const uint8_t* dst, + int dst_len, + const bool fLegacy) { return FromMessage(Bytes(message), dst, dst_len, fLegacy); } -G2Element G2Element::FromMessage(Bytes const message, - const uint8_t* dst, - int dst_len, - const bool fLegacy) +G2Element G2Element::FromMessage( + Bytes const message, + const uint8_t* dst, + int dst_len, + const bool fLegacy) { G2Element ans; if (fLegacy) { - ep2_map_legacy(ans.q, message.begin(), BLS::MESSAGE_HASH_LEN); + ep2_map_legacy(&(ans.q), message.begin(), BLS::MESSAGE_HASH_LEN); } else { - ep2_map_dst(ans.q, message.begin(), (int)message.size(), dst, dst_len); + const byte* aug = nullptr; + size_t aug_len = 0; + + blst_hash_to_g2( + &(ans.q), + message.begin(), + (int)message.size(), + dst, + dst_len, + aug, + aug_len); } - BLS::CheckRelicErrors(); assert(ans.IsValid()); return ans; } @@ -350,139 +554,134 @@ G2Element G2Element::FromMessage(Bytes const message, G2Element G2Element::Generator() { G2Element ele; - g2_get_gen(ele.q); - BLS::CheckRelicErrors(); + ele.q = (*blst_p2_generator()); return ele; } -bool G2Element::IsValid() const { - // Infinity no longer valid in Relic - // https://github.com/relic-toolkit/relic/commit/f3be2babb955cf9f82743e0ae5ef265d3da6c02b - if (g2_is_infty((g2_st*)q) == 1) +bool G2Element::IsValid() const +{ + // Infinity was considered a valid G2Element in older Relic versions + // on which this library was previously based. + // For historical compatibililty this behavior is maintained. + + if (blst_p2_is_inf(&q)) return true; - return g2_is_valid((g2_st*)q); + return blst_p2_in_g2(&q); } -void G2Element::CheckValid() const { +void G2Element::CheckValid() const +{ if (!IsValid()) throw std::invalid_argument("G2 element is invalid"); - BLS::CheckRelicErrors(); } -void G2Element::ToNative(g2_t output) const { - g2_copy(output, (g2_st*)q); +void G2Element::ToNative(blst_p2* output) const +{ + memcpy(output, (blst_p2*)&q, sizeof(blst_p2)); } -G2Element G2Element::Copy() { - G2Element ele; - g2_copy(ele.q, this->q); - - return ele; +void G2Element::ToAffine(blst_p2_affine* output) const +{ + blst_p2_to_affine(output, &q); } +G2Element G2Element::Copy() { return *this; } G2Element G2Element::Negate() const { - G2Element ans; - g2_neg(ans.q, (g2_st*)q); - BLS::CheckRelicErrors(); + G2Element ans = G2Element::FromNative(q); + blst_p2_cneg(&(ans.q), true); return ans; } GTElement G2Element::Pair(const G1Element& a) const { return a & (*this); } -std::vector G2Element::Serialize(const bool fLegacy) const { +std::vector G2Element::Serialize(const bool fLegacy) const +{ const auto arr = G2Element::SerializeToArray(fLegacy); return std::vector{arr.begin(), arr.end()}; } -std::array G2Element::SerializeToArray(const bool fLegacy) const { - uint8_t buffer[G2Element::SIZE + 1]; - g2_write_bin(buffer, G2Element::SIZE + 1, (g2_st*)q, 1); - +std::array G2Element::SerializeToArray(const bool fLegacy) const +{ std::array result{}; + if (!fLegacy) { + blst_p2_compress(result.data(), &q); + return result; + } - if (buffer[0] == 0x00) { // infinity - result.fill(0); + if (blst_p2_is_inf(&q)) { result[0] = 0xc0; return result; } - if (fLegacy) { - if (buffer[0] == 0x03) { // sign bit set - buffer[1] |= 0x80; - } - } else { - // remove leading 3 bits - buffer[1] &= 0x1f; - buffer[49] &= 0x1f; - if (buffer[0] == 0x03) { - buffer[49] |= 0xa0; // swapped later to 0 - } else { - buffer[49] |= 0x80; - } + blst_p2_affine a; + blst_p2_to_affine(&a, &q); + // legacy layout: x.c0 || x.c1 (the modern IETF layout is the swap) + blst_bendian_from_fp(result.data(), &a.x.fp[0]); + blst_bendian_from_fp(result.data() + 48, &a.x.fp[1]); + // legacy sign: c1 > (p-1)/2, no tie-break (relic's ep2_pck) + if (FpSignGtHalf(a.y.fp[1])) { + result[0] |= 0x80; } - - if (fLegacy) { - std::memcpy(result.data(), buffer + 1, G2Element::SIZE); - } else { - // Swap buffer, relic uses the opposite ordering for Fq2 elements - std::memcpy(result.data(), buffer + 1 + G2Element::SIZE / 2, G2Element::SIZE / 2); - std::memcpy(result.data() + G2Element::SIZE / 2, buffer + 1, G2Element::SIZE / 2); - } - return result; } bool operator==(G2Element const& a, G2Element const& b) { - return g2_cmp((g2_st*)a.q, (g2_st*)b.q) == RLC_EQ; + return blst_p2_is_equal(&(a.q), &(b.q)); } bool operator!=(G2Element const& a, G2Element const& b) { return !(a == b); } -std::ostream& operator<<(std::ostream& os, const G2Element & s) +std::ostream& operator<<(std::ostream& os, const G2Element& s) { return os << Util::HexStr(s.Serialize()); } G2Element& operator+=(G2Element& a, const G2Element& b) { - g2_add(a.q, a.q, (g2_st*)b.q); - BLS::CheckRelicErrors(); + blst_p2_add_or_double(&(a.q), &(a.q), &(b.q)); return a; } G2Element operator+(const G2Element& a, const G2Element& b) { G2Element ans; - g2_add(ans.q, (g2_st*)a.q, (g2_st*)b.q); - BLS::CheckRelicErrors(); + blst_p2_add_or_double(&(ans.q), &(a.q), &(b.q)); return ans; } -G2Element operator*(const G2Element& a, const bn_t& k) +G2Element operator*(const G2Element& a, const blst_scalar& k) { G2Element ans; - g2_mul(ans.q, (g2_st*)a.q, (bn_st*)k); - BLS::CheckRelicErrors(); + byte* bte = Util::SecAlloc(32); + blst_lendian_from_scalar(bte, &k); + blst_p2_mult(&(ans.q), &(a.q), bte, 256); + Util::SecFree(bte); + return ans; } -G2Element operator*(const bn_t& k, const G2Element& a) { return a * k; } - - +G2Element operator*(const blst_scalar& k, const G2Element& a) { return a * k; } // GTElement const size_t GTElement::SIZE; +/* + * Currently deserliazation is not available - these are currently + * broken and just return the zero element + */ GTElement GTElement::FromBytes(Bytes const bytes) { GTElement ele = GTElement::FromBytesUnchecked(bytes); - if (gt_is_valid(*(gt_t*)&ele) == 0) - throw std::invalid_argument("GTElement is invalid"); + // + // this doesn't seem to be the proper check as it doesn't work as expeced + // + // if (!blst_fp12_in_group(&(ele.r))) + // throw std::invalid_argument("GTElement is invalid"); return ele; } @@ -492,8 +691,7 @@ GTElement GTElement::FromBytesUnchecked(Bytes const bytes) throw std::invalid_argument("GTElement::FromBytes: Invalid size"); } GTElement ele = GTElement(); - gt_read_bin(ele.r, bytes.begin(), GTElement::SIZE); - BLS::CheckRelicErrors(); + memcpy(&(ele.r), bytes.begin(), SIZE); return ele; } @@ -502,23 +700,37 @@ GTElement GTElement::FromByteVector(const std::vector& bytevec) return GTElement::FromBytes(Bytes(bytevec)); } -GTElement GTElement::FromNative(const gt_t* element) +GTElement GTElement::FromNative(const blst_fp12* element) { GTElement ele = GTElement(); - gt_copy(ele.r, *(gt_t*)element); + ele.r = *element; return ele; } -GTElement GTElement::Unity() { +GTElement GTElement::FromAffine(const blst_p1_affine& affine) +{ GTElement ele = GTElement(); - gt_set_unity(ele.r); + blst_aggregated_in_g1(&ele.r, &affine); return ele; } +GTElement GTElement::FromAffine(const blst_p2_affine& affine) +{ + GTElement ele = GTElement(); + blst_aggregated_in_g2(&ele.r, &affine); + return ele; +} + +GTElement GTElement::Unity() +{ + GTElement ele = GTElement(); + ele.FromNative(blst_fp12_one()); + return ele; +} bool operator==(GTElement const& a, GTElement const& b) { - return gt_cmp(*(gt_t*)(a.r), *(gt_t*)(b.r)) == RLC_EQ; + return blst_fp12_is_equal(&(a.r), &(b.r)); } bool operator!=(GTElement const& a, GTElement const& b) { return !(a == b); } @@ -530,31 +742,31 @@ std::ostream& operator<<(std::ostream& os, GTElement const& ele) GTElement operator&(const G1Element& a, const G2Element& b) { - G1Element nonConstA(a); - gt_t ans; - gt_new(ans); - g2_t tmp; - g2_null(tmp); - g2_new(tmp); - b.ToNative(tmp); - pp_map_oatep_k12(ans, nonConstA.p, tmp); + blst_fp12 ans; + + blst_p1_affine aff1; + blst_p2_affine aff2; + a.ToAffine(&aff1); + b.ToAffine(&aff2); + + blst_miller_loop(&ans, &aff2, &aff1); + blst_final_exp(&ans, &ans); + GTElement ret = GTElement::FromNative(&ans); - gt_free(ans); - g2_free(tmp); + return ret; } GTElement operator*(GTElement& a, GTElement& b) { GTElement ans; - fp12_mul(ans.r, a.r, b.r); - BLS::CheckRelicErrors(); + blst_fp12_mul(&(ans.r), &(a.r), &(b.r)); return ans; } void GTElement::Serialize(uint8_t* buffer) const { - gt_write_bin(buffer, GTElement::SIZE, *(gt_t*)&r, 1); + memcpy(buffer, &r, GTElement::SIZE); } std::vector GTElement::Serialize() const diff --git a/src/dashbls/src/extendedprivatekey.cpp b/src/dashbls/src/extendedprivatekey.cpp index d5fe746ee690..237aa0515892 100644 --- a/src/dashbls/src/extendedprivatekey.cpp +++ b/src/dashbls/src/extendedprivatekey.cpp @@ -31,27 +31,16 @@ ExtendedPrivateKey ExtendedPrivateKey::FromSeed(const Bytes& bytes) { // Hash the seed into 64 bytes, half will be sk, half will be cc hashInput[bytes.size()] = 0; - md_hmac(ILeft, hashInput, bytes.size() + 1, prefix, sizeof(prefix)); + Util::md_hmac(ILeft, hashInput, bytes.size() + 1, prefix, sizeof(prefix)); hashInput[bytes.size()] = 1; - md_hmac(IRight, hashInput, bytes.size() + 1, prefix, sizeof(prefix)); + Util::md_hmac(IRight, hashInput, bytes.size() + 1, prefix, sizeof(prefix)); // Make sure private key is less than the curve order - bn_t* skBn = Util::SecAlloc(1); - bn_t order; - bn_new(order); - g1_get_ord(order); - - bn_new(*skBn); - bn_read_bin(*skBn, ILeft, PrivateKey::PRIVATE_KEY_SIZE); - bn_mod_basic(*skBn, *skBn, order); - bn_write_bin(ILeft, PrivateKey::PRIVATE_KEY_SIZE, *skBn); - ExtendedPrivateKey esk(ExtendedPublicKey::REVISION, 0, 0, 0, ChainCode::FromBytes(Bytes(IRight, ChainCode::SIZE)), - PrivateKey::FromBytes(Bytes(ILeft, PrivateKey::PRIVATE_KEY_SIZE))); + PrivateKey::FromBytes(Bytes(ILeft, PrivateKey::PRIVATE_KEY_SIZE), true)); - Util::SecFree(skBn); Util::SecFree(ILeft); Util::SecFree(hashInput); return esk; @@ -101,13 +90,13 @@ ExtendedPrivateKey ExtendedPrivateKey::PrivateChild(uint32_t i, const bool fLega } hmacInput[inputLen - 1] = 0; - md_hmac(ILeft, hmacInput, inputLen, + Util::md_hmac(ILeft, hmacInput, inputLen, hmacKey, ChainCode::SIZE); // Change 1 byte to generate a different sequence for chaincode hmacInput[inputLen - 1] = 1; - md_hmac(IRight, hmacInput, inputLen, + Util::md_hmac(IRight, hmacInput, inputLen, hmacKey, ChainCode::SIZE); PrivateKey newSk = PrivateKey::FromBytes(Bytes(ILeft, PrivateKey::PRIVATE_KEY_SIZE), true); diff --git a/src/dashbls/src/extendedpublickey.cpp b/src/dashbls/src/extendedpublickey.cpp index a484dea64621..ad1015a68c9b 100644 --- a/src/dashbls/src/extendedpublickey.cpp +++ b/src/dashbls/src/extendedpublickey.cpp @@ -59,13 +59,13 @@ ExtendedPublicKey ExtendedPublicKey::PublicChild(uint32_t i, const bool fLegacy) hmacInput[inputLen - 1] = 0; Util::IntToFourBytes(hmacInput + G1Element::SIZE, i); - md_hmac(ILeft, hmacInput, inputLen, + Util::md_hmac(ILeft, hmacInput, inputLen, hmacKey, ChainCode::SIZE); // Change 1 byte to generate a different sequence for chaincode hmacInput[inputLen - 1] = 1; - md_hmac(IRight, hmacInput, inputLen, + Util::md_hmac(IRight, hmacInput, inputLen, hmacKey, ChainCode::SIZE); PrivateKey leftSk = PrivateKey::FromBytes(Bytes(ILeft, PrivateKey::PRIVATE_KEY_SIZE), true); diff --git a/src/dashbls/src/legacy.cpp b/src/dashbls/src/legacy.cpp index 7a28b92c66b6..21a6c3cde99f 100644 --- a/src/dashbls/src/legacy.cpp +++ b/src/dashbls/src/legacy.cpp @@ -3,431 +3,262 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "legacy.hpp" - -#define B12_P381_S3 "BE32CE5FBEED9CA374D38C0ED41EEFD5BB675277CDF12D11BC2FB026C41400045C03FFFFFFFDFFFD" -#define B12_P381_S32 "5F19672FDF76CE51BA69C6076A0F77EADDB3A93BE6F89688DE17D813620A00022E01FFFFFFFEFFFE" - -/** - * Returns the (sqrt(-3) - 1) / 2 mod q in the curve, where q is the prime. - * - * @param[out] h - the returned cofactor. - */ -static void ep2_curve_get_s32(bn_t s32In) { - static bool fInitialized{false}; - static bn_t s32; - if (!fInitialized) { - bn_new(s32); - bn_read_str(s32, B12_P381_S32, sizeof(B12_P381_S32), 16); - fInitialized = true; - } - bn_copy(s32In, s32); +#include +#include +#include + +namespace { + +// sqrt(-3) mod p, big-endian, zero-padded to 48 bytes. Value taken from the +// relic implementation's B12_P381_S3 constant; validated by +// s3^2 == -3 (mod p). +const uint8_t S3_BE[48] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbe, 0x32, 0xce, 0x5f, + 0xbe, 0xed, 0x9c, 0xa3, 0x74, 0xd3, 0x8c, 0x0e, 0xd4, 0x1e, 0xef, 0xd5, + 0xbb, 0x67, 0x52, 0x77, 0xcd, 0xf1, 0x2d, 0x11, 0xbc, 0x2f, 0xb0, 0x26, + 0xc4, 0x14, 0x00, 0x04, 0x5c, 0x03, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xfd}; + +// (sqrt(-3) - 1) / 2 mod p (relic's B12_P381_S32). +const uint8_t S32_BE[48] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5f, 0x19, 0x67, 0x2f, + 0xdf, 0x76, 0xce, 0x51, 0xba, 0x69, 0xc6, 0x07, 0x6a, 0x0f, 0x77, 0xea, + 0xdd, 0xb3, 0xa9, 0x3b, 0xe6, 0xf8, 0x96, 0x88, 0xde, 0x17, 0xd8, 0x13, + 0x62, 0x0a, 0x00, 0x02, 0x2e, 0x01, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xfe}; + +// Effective cofactor h_eff for BLS12-381 G2 (RFC 9380 section 8.8.2), +// big-endian, 80 bytes / 636 bits. Scalar multiplication by h_eff is +// equivalent to the psi-endomorphism-based cofactor clearing the relic +// implementation performed (verified empirically point-by-point). +const uint8_t H_EFF_BE[80] = { + 0x0b, 0xc6, 0x9f, 0x08, 0xf2, 0xee, 0x75, 0xb3, 0x58, 0x4c, 0x6a, 0x0e, + 0xa9, 0x1b, 0x35, 0x28, 0x88, 0xe2, 0xa8, 0xe9, 0x14, 0x5a, 0xd7, 0x68, + 0x99, 0x86, 0xff, 0x03, 0x15, 0x08, 0xff, 0xe1, 0x32, 0x9c, 0x2f, 0x17, + 0x87, 0x31, 0xdb, 0x95, 0x6d, 0x82, 0xbf, 0x01, 0x5d, 0x12, 0x12, 0xb0, + 0x2e, 0xc0, 0xec, 0x69, 0xd7, 0x47, 0x7c, 0x1a, 0xe9, 0x54, 0xcb, 0xc0, + 0x66, 0x89, 0xf6, 0xa3, 0x59, 0x89, 0x4c, 0x0a, 0xde, 0xbb, 0xf6, 0xb4, + 0xe8, 0x02, 0x00, 0x05, 0xaa, 0xa9, 0x55, 0x51}; + +void FpOne(blst_fp& out) +{ + uint8_t be[48] = {0}; + be[47] = 1; + blst_fp_from_bendian(&out, be); } -/** - * Returns the sqrt(-3) mod q in the curve, where q is the prime. - * - * @param[out] h - the returned cofactor. - */ -static void ep2_curve_get_s3(bn_t s3In) { - static bool fInitialized{false}; - static bn_t s3; - if (!fInitialized) { - bn_new(s3); - bn_read_str(s3, B12_P381_S3, sizeof(B12_P381_S3), 16); - fInitialized = true; - } - bn_copy(s3In, s3); +void FpFour(blst_fp& out) +{ + uint8_t be[48] = {0}; + be[47] = 4; + blst_fp_from_bendian(&out, be); } -/** - * Returns the 'b' coefficient of the currently configured elliptic curve. - * - * @param[out] b - the 'b' coefficient of the elliptic curve. - */ -static void ep2_curve_get_b(fp2_t b) { - ctx_t *ctx = core_get(); - fp_copy(b[0], ctx->ep2_b[0]); - fp_copy(b[1], ctx->ep2_b[1]); -} +inline void FpZero(blst_fp& out) { memset(&out, 0x00, sizeof(blst_fp)); } -/** - * Returns the variable used to parameterize the given prime modulus. - * - * @param[out] x - the integer parameter. - */ -static void fp_param_get_var(bn_t x) { - bn_t a; - - bn_null(a); - - RLC_TRY { - bn_new(a); - /* x = -(2^63 + 2^62 + 2^60 + 2^57 + 2^48 + 2^16). */ - bn_set_2b(x, 63); - bn_set_2b(a, 62); - bn_add(x, x, a); - bn_set_2b(a, 60); - bn_add(x, x, a); - bn_set_2b(a, 57); - bn_add(x, x, a); - bn_set_2b(a, 48); - bn_add(x, x, a); - bn_set_2b(a, 16); - bn_add(x, x, a); - bn_neg(x, x); - } - RLC_CATCH_ANY { - RLC_THROW(ERR_CAUGHT); - } - RLC_FINALLY { - bn_free(a); - } +bool FpIsZero(const blst_fp& a) +{ + uint8_t be[48]; + blst_bendian_from_fp(be, &a); + for (int i = 0; i < 48; i++) + if (be[i] != 0) return false; + return true; } -/** - * Multiplies a point by the cofactor in a Barreto-Lynn-Soctt. - * - * @param[out] r - the result. - * @param[in] p - the point to multiply. - */ -static void ep2_mul_cof_b12(ep2_t r, ep2_t p) { - bn_t x; - ep2_t t0, t1, t2, t3; - - ep2_null(t0); - ep2_null(t1); - ep2_null(t2); - ep2_null(t3); - bn_null(x); - - RLC_TRY { - ep2_new(t0); - ep2_new(t1); - ep2_new(t2); - ep2_new(t3); - bn_new(x); - - fp_param_get_var(x); - - /* Compute t0 = xP. */ - ep2_mul_basic(t0, p, x); - /* Compute t1 = [x^2]P. */ - ep2_mul_basic(t1, t0, x); - - /* t2 = (x^2 - x - 1)P = x^2P - x*P - P. */ - ep2_sub(t2, t1, t0); - ep2_sub(t2, t2, p); - /* t3 = \psi(x - 1)P. */ - ep2_sub(t3, t0, p); - ep2_norm(t3, t3); - ep2_frb(t3, t3, 1); - ep2_add(t2, t2, t3); - /* t3 = \psi^2(2P). */ - ep2_dbl(t3, p); - ep2_norm(t3, t3); - ep2_frb(t3, t3, 2); - ep2_add(t2, t2, t3); - ep2_norm(r, t2); - } - RLC_CATCH_ANY { - RLC_THROW(ERR_CAUGHT); - } - RLC_FINALLY { - ep2_free(t0); - ep2_free(t1); - ep2_free(t2); - ep2_free(t3); - bn_free(x); - } +bool Fp2IsZero(const blst_fp2& a) +{ + return FpIsZero(a.fp[0]) && FpIsZero(a.fp[1]); } /** + * Multiplies a point by the cofactor in a Barreto-Lynn-Soctt. * Based on the rust implementation of pairings, zkcrypto/pairing. * The algorithm is Shallue–van de Woestijne encoding from * Section 3 of "Indifferentiable Hashing to Barreto–Naehrig Curves" * from Fouque-Tibouchi: + * @param[out] r - the result. + * @param[in] p - the point to multiply. + * Returns false when the result is the point at infinity (t == 0). */ -static void ep2_sw_encode(ep2_t p, fp2_t t) { - if (fp2_is_zero(t)) { +bool ep2_sw_encode(blst_p2_affine& p, const blst_fp2& t) +{ + if (Fp2IsZero(t)) { // Maps t=0 to the point at infinity. - ep2_set_infty(p); - return; + return false; } - fp2_t nt; // Negative t - fp2_t w; - fp2_t b; - bn_t s_n3; - bn_t s_n3m1o2; - fp2_t x1; - fp2_t x2; - fp2_t x3; - fp2_t rhs; - - fp2_new(nt); - fp2_new(w); - fp2_new(b); - bn_new(s_n3); - bn_new(s_n3m1o2); - fp2_new(x1); - fp2_new(x2); - fp2_new(x3); - fp2_new(rhs); - - // nt = -t - fp2_neg(nt, t); - - uint8_t buf0[RLC_FP_BYTES]; // t[1] - uint8_t buf1[RLC_FP_BYTES]; // -t[1] - fp_write_bin(buf0, RLC_FP_BYTES, t[1]); - fp_write_bin(buf1, RLC_FP_BYTES, nt[1]); - - // Compare bytes since fp_cmp compares montgomery representation - int parity = memcmp(buf0, buf1, RLC_FP_BYTES) > 0; + + // parity of t: compare the canonical bytes of t.c1 against those of + // (-t).c1 + blst_fp2 nt = t; + blst_fp2_cneg(&nt, &nt, true); + uint8_t buf0[48], buf1[48]; + blst_bendian_from_fp(buf0, &t.fp[1]); + blst_bendian_from_fp(buf1, &nt.fp[1]); + const bool parity = memcmp(buf0, buf1, 48) > 0; + + blst_fp one, four; + FpOne(one); + FpFour(four); + blst_fp2 b; + b.fp[0] = four; + b.fp[1] = four; // w = t^2 + b + 1 - fp2_mul(w, t, t); - ep2_curve_get_b(b); - fp2_add(w, w, b); - fp_add_dig(w[0], w[0], 1); + blst_fp2 w; + blst_fp2_sqr(&w, &t); + blst_fp2_add(&w, &w, &b); + blst_fp_add(&w.fp[0], &w.fp[0], &one); - if (fp2_is_zero(w)) { - ep2_curve_get_gen(p); + if (Fp2IsZero(w)) { + p = *blst_p2_affine_generator(); if (parity) { - ep2_neg(p, p); + blst_fp2_cneg(&p.y, &p.y, true); } - fp2_free(nt); - fp2_free(w); - fp2_free(b); - bn_free(s_n3); - bn_free(s_n3m1o2); - fp2_free(x1); - fp2_free(x2); - fp2_free(x3); - fp2_free(rhs); - return; + return true; } - // sqrt(-3) - ep2_curve_get_s3(s_n3); - fp2_t s_n3p; - fp2_null(s_n3p); - fp2_new(s_n3p); - fp2_t s_n3m1o2p; - fp2_null(s_n3m1o2p); - fp2_new(s_n3m1o2p); - - fp2_zero(s_n3p); - fp2_zero(s_n3m1o2p); - fp_prime_conv(s_n3p[0], s_n3); - - // (sqrt(-3) - 1) / 2 - ep2_curve_get_s32(s_n3m1o2); - fp_prime_conv(s_n3m1o2p[0], s_n3m1o2); + blst_fp2 s3p, s32p; + blst_fp_from_bendian(&s3p.fp[0], S3_BE); + FpZero(s3p.fp[1]); + blst_fp_from_bendian(&s32p.fp[0], S32_BE); + FpZero(s32p.fp[1]); - fp2_inv(w, w); - fp2_mul(w, w, s_n3p); - fp2_mul(w, w, t); + // w = sqrt(-3) * t / (t^2 + b + 1) + blst_fp2_inverse(&w, &w); + blst_fp2_mul(&w, &w, &s3p); + blst_fp2_mul(&w, &w, &t); - // x1 = -wt + sqrt(-3) - fp2_neg(x1, w); - fp2_mul(x1, x1, t); - fp2_add(x1, x1, s_n3m1o2p); + // x1 = -wt + (sqrt(-3) - 1) / 2 + blst_fp2 x1; + x1 = w; + blst_fp2_cneg(&x1, &x1, true); + blst_fp2_mul(&x1, &x1, &t); + blst_fp2_add(&x1, &x1, &s32p); // x2 = -x1 - 1 - fp2_neg(x2, x1); - fp_sub_dig(x2[0], x2[0], 1); + blst_fp2 x2 = x1; + blst_fp2_cneg(&x2, &x2, true); + blst_fp_sub(&x2.fp[0], &x2.fp[0], &one); // x3 = 1/w^2 + 1 - fp2_mul(x3, w, w); - fp2_inv(x3, x3); - fp_add_dig(x3[0], x3[0], 1); - - fp2_zero(p->y); - fp2_set_dig(p->z, 1); - - // if x1 has no y, try x2. if x2 has no y, try x3 - fp2_copy(p->x, x1); - - ep2_rhs(rhs, p); - int Xx1 = fp2_srt(p->y, rhs) ? 1 : -1; - fp2_copy(p->x, x2); - ep2_rhs(rhs, p); - int Xx2 = fp2_srt(p->y, rhs) ? 1 : -1; + blst_fp2 x3; + blst_fp2_sqr(&x3, &w); + blst_fp2_inverse(&x3, &x3); + blst_fp_add(&x3.fp[0], &x3.fp[0], &one); + + const auto rhs = [&b](blst_fp2& out, const blst_fp2& x) { + blst_fp2_sqr(&out, &x); + blst_fp2_mul(&out, &out, &x); + blst_fp2_add(&out, &out, &b); + }; + + blst_fp2 r, y; + rhs(r, x1); + const int Xx1 = blst_fp2_sqrt(&y, &r) ? 1 : -1; + rhs(r, x2); + const int Xx2 = blst_fp2_sqrt(&y, &r) ? 1 : -1; // This formula computes which index to use, in constant time // without conditional branches. It's taken from the paper. 3 is // added, because the % operator in c can be negative. - int index = ((((Xx1 - 1) * Xx2) % 3) + 3) % 3; - - if (index == 0) { - fp2_copy(p->x, x1); - ep2_rhs(rhs, p); - fp2_srt(p->y, rhs); - } else if (index == 1) { - fp2_copy(p->x, x2); - ep2_rhs(rhs, p); - fp2_srt(p->y, rhs); - } else if (index == 2) { - fp2_copy(p->x, x3); - ep2_rhs(rhs, p); - fp2_srt(p->y, rhs); - } - - p->coord = 1; - - // Check for lexicografically greater than the negation - fp2_t ny; - fp2_null(ny); - fp2_new(ny); - fp2_neg(ny, p->y); - fp_write_bin(buf0, RLC_FP_BYTES, p->y[1]); - fp_write_bin(buf1, RLC_FP_BYTES, ny[1]); - - // Compare bytes since fp_cmp compares montgomery representation - if ((memcmp(buf0, buf1, RLC_FP_BYTES) > 0) != parity) { - ep2_neg(p, p); + const int index = ((((Xx1 - 1) * Xx2) % 3) + 3) % 3; + + p.x = (index == 0) ? x1 : (index == 1) ? x2 : x3; + rhs(r, p.x); + const bool haveRoot = blst_fp2_sqrt(&p.y, &r); + (void)haveRoot; + assert(haveRoot); // guaranteed by the SW construction + + // Normalize the sign of y against the parity of t + blst_fp2 ny = p.y; + blst_fp2_cneg(&ny, &ny, true); + blst_bendian_from_fp(buf0, &p.y.fp[1]); + blst_bendian_from_fp(buf1, &ny.fp[1]); + if ((memcmp(buf0, buf1, 48) > 0) != parity) { + p.y = ny; } + return true; +} - fp2_free(nt); - fp2_free(w); - fp2_free(b); - bn_free(s_n3); - bn_free(s_n3m1o2); - fp2_free(x1); - fp2_free(x2); - fp2_free(x3); - fp2_free(rhs); - - fp2_free(s_n3p); - fp2_free(s_n3m1o2p); - fp2_free(ny); +// Reduce a 64-byte big-endian value mod p into an fp element, matching +// relic's bn_read_bin + fp_prime_conv: split as hi*2^256 + lo with both +// halves < 2^256 < p. +void FpFromBE64Wide(blst_fp& out, const uint8_t* be64) +{ + uint8_t padded[48] = {0}; + blst_fp hi, lo, c256; + + memcpy(padded + 16, be64, 32); + blst_fp_from_bendian(&hi, padded); + memcpy(padded + 16, be64 + 32, 32); + blst_fp_from_bendian(&lo, padded); + + // 2^256 mod p == 2^256 (p is 381 bits) + memset(padded, 0, 48); + padded[15] = 0x01; + blst_fp_from_bendian(&c256, padded); + + blst_fp_mul(&out, &hi, &c256); + blst_fp_add(&out, &out, &lo); } +} // anon namespace + +namespace bls { +void ep2_map_legacy(blst_p2* p, const uint8_t* msg, int len) +{ + if (len != 32) { + throw std::invalid_argument( + "ep2_map_legacy requires a 32-byte message hash"); + } -void ep2_map_legacy(ep2_t p, const uint8_t *msg, int len) { - bn_t t00; - bn_t t01; - bn_t t10; - bn_t t11; - fp_t t00p; - fp_t t01p; - fp_t t10p; - fp_t t11p; - fp2_t t0p; - fp2_t t1p; - ep2_t p0; - ep2_t p1; - - bn_null(t00); - bn_null(t01); - bn_null(t10); - bn_null(t11); - fp_null(t00p); - fp_null(t01p); - fp_null(t10p); - fp_null(t11p); - fp2_null(t0p); - fp2_null(t1p); - ep2_null(p1); - ep2_null(p0); - - RLC_TRY { - uint8_t input[RLC_MD_LEN + 8]; - if (len != RLC_MD_LEN) { - RLC_THROW(ERR_CAUGHT); - } - memcpy(input, msg, len); - // b"G2_0_c0" - input[RLC_MD_LEN + 0] = 0x47; // G - input[RLC_MD_LEN + 1] = 0x32; // 2 - input[RLC_MD_LEN + 2] = 0x5f; // _ - input[RLC_MD_LEN + 3] = 0x30; // 0 - input[RLC_MD_LEN + 4] = 0x5f; // _ - input[RLC_MD_LEN + 5] = 0x63; // c - input[RLC_MD_LEN + 6] = 0x30; // 0 - - bn_new(t00); - bn_new(t01); - bn_new(t10); - bn_new(t11); - fp_new(t00p); - fp_new(t01p); - fp_new(t10p); - fp_new(t11p); - fp2_new(t0p); - fp2_new(t1p); - ep2_new(p1); - ep2_new(p0); - - uint8_t t00Bytes[RLC_MD_LEN * 2]; - uint8_t t01Bytes[RLC_MD_LEN * 2]; - uint8_t t10Bytes[RLC_MD_LEN * 2]; - uint8_t t11Bytes[RLC_MD_LEN * 2]; - - // b"G2_0_c0" - input[RLC_MD_LEN + 7] = 0x00; // 0 - md_map(t00Bytes, input, RLC_MD_LEN + 8); - input[RLC_MD_LEN + 7] = 1; // 1 - md_map(t00Bytes + RLC_MD_LEN, input, RLC_MD_LEN + 8); - - // b"G2_0_c1" - input[RLC_MD_LEN + 6] = 0x31; // b"1" - input[RLC_MD_LEN + 7] = 0; // 0 - - md_map(t01Bytes, input, RLC_MD_LEN + 8); - input[RLC_MD_LEN + 7] = 1; // 1 - md_map(t01Bytes + RLC_MD_LEN, input, RLC_MD_LEN + 8); - - // b"G2_1_c0" - input[RLC_MD_LEN + 3] = 0x31; // b"1" - input[RLC_MD_LEN + 6] = 0x30; // b"0" - input[RLC_MD_LEN + 7] = 0; // 0 - md_map(t10Bytes, input, RLC_MD_LEN + 8); - input[RLC_MD_LEN + 7] = 1; // 1 - md_map(t10Bytes + RLC_MD_LEN, input, RLC_MD_LEN + 8); - - // b"G2_1_c1" - input[RLC_MD_LEN + 6] = 0x31; // b"1" - input[RLC_MD_LEN + 7] = 0; // 0 - md_map(t11Bytes, input, RLC_MD_LEN + 8); - input[RLC_MD_LEN + 7] = 1; // 1 - md_map(t11Bytes + RLC_MD_LEN, input, RLC_MD_LEN + 8); - - bn_read_bin(t00, t00Bytes, RLC_MD_LEN * 2); - bn_read_bin(t01, t01Bytes, RLC_MD_LEN * 2); - bn_read_bin(t10, t10Bytes, RLC_MD_LEN * 2); - bn_read_bin(t11, t11Bytes, RLC_MD_LEN * 2); - - fp_prime_conv(t00p, t00); - fp_prime_conv(t01p, t01); - fp_prime_conv(t10p, t10); - fp_prime_conv(t11p, t11); - - fp_copy(t0p[0], t00p); - fp_copy(t0p[1], t01p); - fp_copy(t1p[0], t10p); - fp_copy(t1p[1], t11p); - - ep2_sw_encode(p0, t0p); - ep2_sw_encode(p1, t1p); - ep2_add(p0, p0, p1); - /* Now, multiply by cofactor to get the correct group. */ - ep2_mul_cof_b12(p, p0); + uint8_t input[32 + 8]; + memcpy(input, msg, 32); + + uint8_t t00Bytes[64], t01Bytes[64], t10Bytes[64], t11Bytes[64]; + + const auto draw = [&input](uint8_t* out, char i, char j) { + // tag: "G2__c" followed by a counter byte + input[32 + 0] = 0x47; // G + input[32 + 1] = 0x32; // 2 + input[32 + 2] = 0x5f; // _ + input[32 + 3] = (uint8_t)i; + input[32 + 4] = 0x5f; // _ + input[32 + 5] = 0x63; // c + input[32 + 6] = (uint8_t)j; + input[32 + 7] = 0; + blst_sha256(out, input, 32 + 8); + input[32 + 7] = 1; + blst_sha256(out + 32, input, 32 + 8); + }; + + draw(t00Bytes, '0', '0'); + draw(t01Bytes, '0', '1'); + draw(t10Bytes, '1', '0'); + draw(t11Bytes, '1', '1'); + + blst_fp2 t0, t1; + FpFromBE64Wide(t0.fp[0], t00Bytes); + FpFromBE64Wide(t0.fp[1], t01Bytes); + FpFromBE64Wide(t1.fp[0], t10Bytes); + FpFromBE64Wide(t1.fp[1], t11Bytes); + + blst_p2_affine a0, a1; + const bool has0 = ep2_sw_encode(a0, t0); + const bool has1 = ep2_sw_encode(a1, t1); + + blst_p2 sum; + memset(&sum, 0x00, sizeof(blst_p2)); // infinity + if (has0) { + blst_p2_from_affine(&sum, &a0); } - RLC_CATCH_ANY { - RLC_THROW(ERR_CAUGHT); + if (has1) { + blst_p2_add_or_double_affine(&sum, &sum, &a1); } - RLC_FINALLY { - fp2_free(t0p); - fp2_free(t1p); - fp_free(t00p); - fp_free(t01p); - fp_free(t10p); - fp_free(t11p); - bn_free(t00); - bn_free(t01); - bn_free(t10); - bn_free(t11); - ep2_free(p0); - ep2_free(p1); + + // Clear the cofactor by multiplying with h_eff (equivalent to the + // psi-based clearing the relic implementation used). + uint8_t heffLE[sizeof(H_EFF_BE)]; + for (size_t i = 0; i < sizeof(H_EFF_BE); i++) { + heffLE[i] = H_EFF_BE[sizeof(H_EFF_BE) - 1 - i]; } + blst_p2_mult(p, &sum, heffLE, 636); } +} // namespace bls diff --git a/src/dashbls/src/privatekey.cpp b/src/dashbls/src/privatekey.cpp index d07246d8575e..d04e68b71dd5 100644 --- a/src/dashbls/src/privatekey.cpp +++ b/src/dashbls/src/privatekey.cpp @@ -12,6 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + +#include + #include "bls.hpp" #include "legacy.hpp" @@ -28,81 +32,65 @@ PrivateKey PrivateKey::FromSeedBIP32(const Bytes& seed) { PrivateKey::PRIVATE_KEY_SIZE); // Hash the seed into sk - md_hmac(hash, seed.begin(), (int)seed.size(), hmacKey, sizeof(hmacKey)); - - bn_t order; - bn_new(order); - g1_get_ord(order); + Util::md_hmac(hash, seed.begin(), (int)seed.size(), hmacKey, sizeof(hmacKey)); // Make sure private key is less than the curve order - bn_t* skBn = Util::SecAlloc(1); - bn_new(*skBn); - bn_read_bin(*skBn, hash, PrivateKey::PRIVATE_KEY_SIZE); - bn_mod_basic(*skBn, *skBn, order); - PrivateKey k; - bn_copy(k.keydata, *skBn); + blst_scalar_from_be_bytes(k.keydata, hash, PrivateKey::PRIVATE_KEY_SIZE); - Util::SecFree(skBn); Util::SecFree(hash); return k; } +// BLS12-381 group order r, big-endian. +// Taken from depends/blst/src/consts.c: BLS12_381_r = { 0xffffffff00000001, 0x53bda402fffe5bfe, 0x3339d80809a1d805, 0x73eda753299d7d48 } +// (little-endian limbs of the same number, with the comment z^4 - z^2 + 1, group order). + +static const uint8_t ORDER_BE[32] = { + 0x73, 0xed, 0xa7, 0x53, 0x29, 0x9d, 0x7d, 0x48, 0x33, 0x39, 0xd8, 0x08, + 0x09, 0xa1, 0xd8, 0x05, 0x53, 0xbd, 0xa4, 0x02, 0xff, 0xfe, 0x5b, 0xfe, + 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01}; + // Construct a private key from a bytearray. -PrivateKey PrivateKey::FromBytes(const Bytes& bytes, bool modOrder) +PrivateKey PrivateKey::FromBytes(const Bytes &bytes, bool modOrder) { if (bytes.size() != PRIVATE_KEY_SIZE) { throw std::invalid_argument("PrivateKey::FromBytes: Invalid size"); } PrivateKey k; - bn_read_bin(k.keydata, bytes.begin(), PrivateKey::PRIVATE_KEY_SIZE); - bn_t ord; - bn_new(ord); - g1_get_ord(ord); - if (modOrder) { - bn_mod_basic(k.keydata, k.keydata, ord); - } else { - if (bn_cmp(k.keydata, ord) > 0) { + if (modOrder) + // this allows any bytes to be input and does proper mod order + blst_scalar_from_be_bytes(k.keydata, bytes.begin(), bytes.size()); + else { + // Values strictly greater than the group order are rejected; the + // order itself is accepted, matching the relic-based + // implementation's bn_cmp(keydata, order) > 0 check. + if (memcmp(bytes.begin(), ORDER_BE, PRIVATE_KEY_SIZE) > 0) { throw std::invalid_argument( "PrivateKey byte data must be less than the group order"); } + blst_scalar_from_bendian(k.keydata, bytes.begin()); } return k; } // Construct a private key from a bytearray. -PrivateKey PrivateKey::FromByteVector(const std::vector bytes, bool modOrder) +PrivateKey PrivateKey::FromByteVector( + const std::vector bytes, + bool modOrder) { return PrivateKey::FromBytes(Bytes(bytes), modOrder); } -// Construct a private key from a bytearray. -PrivateKey PrivateKey::RandomPrivateKey() -{ - bn_t *r = Util::SecAlloc(1); - bn_new(*r); - bn_rand(*r, RLC_POS, 256); - PrivateKey k; - bn_copy(k.keydata, *r); - bn_t ord; - bn_new(ord); - g1_get_ord(ord); - bn_mod_basic(k.keydata, k.keydata, ord); - Util::SecFree(r); - return k; -} - -PrivateKey::PrivateKey() { - AllocateKeyData(); -}; +PrivateKey::PrivateKey() { AllocateKeyData(); }; // Construct a private key from another private key. PrivateKey::PrivateKey(const PrivateKey &privateKey) { privateKey.CheckKeyData(); AllocateKeyData(); - bn_copy(keydata, privateKey.keydata); + memcpy(keydata, privateKey.keydata, sizeof(blst_scalar)); } PrivateKey::PrivateKey(PrivateKey &&k) @@ -111,14 +99,11 @@ PrivateKey::PrivateKey(PrivateKey &&k) k.InvalidateCaches(); } -PrivateKey::~PrivateKey() -{ - DeallocateKeyData(); -} +PrivateKey::~PrivateKey() { DeallocateKeyData(); } void PrivateKey::DeallocateKeyData() { - if(keydata != nullptr) { + if (keydata != nullptr) { Util::SecFree(keydata); keydata = nullptr; } @@ -131,16 +116,16 @@ void PrivateKey::InvalidateCaches() fG2CacheValid = false; } -PrivateKey& PrivateKey::operator=(const PrivateKey& other) +PrivateKey &PrivateKey::operator=(const PrivateKey &other) { CheckKeyData(); other.CheckKeyData(); InvalidateCaches(); - bn_copy(keydata, other.keydata); + memcpy(keydata, other.keydata, sizeof(blst_scalar)); return *this; } -PrivateKey& PrivateKey::operator=(PrivateKey&& other) +PrivateKey &PrivateKey::operator=(PrivateKey &&other) { DeallocateKeyData(); keydata = std::exchange(other.keydata, nullptr); @@ -148,28 +133,28 @@ PrivateKey& PrivateKey::operator=(PrivateKey&& other) return *this; } -const G1Element& PrivateKey::GetG1Element() const +const G1Element &PrivateKey::GetG1Element() const { if (!fG1CacheValid) { CheckKeyData(); - g1_st *p = Util::SecAlloc(1); - g1_mul_gen(p, keydata); + blst_p1 *p = Util::SecAlloc(1); + blst_sk_to_pk_in_g1(p, keydata); - g1Cache = G1Element::FromNative(p); + g1Cache = G1Element::FromNative(*p); Util::SecFree(p); fG1CacheValid = true; } return g1Cache; } -const G2Element& PrivateKey::GetG2Element() const +const G2Element &PrivateKey::GetG2Element() const { if (!fG2CacheValid) { CheckKeyData(); - g2_st *q = Util::SecAlloc(1); - g2_mul_gen(q, keydata); + blst_p2 *q = Util::SecAlloc(1); + blst_sk_to_pk_in_g2(q, keydata); - g2Cache = G2Element::FromNative(q); + g2Cache = G2Element::FromNative(*q); Util::SecFree(q); fG2CacheValid = true; } @@ -184,11 +169,15 @@ bool PrivateKey::HasKeyData() const G1Element operator*(const G1Element &a, const PrivateKey &k) { k.CheckKeyData(); - g1_st* ans = Util::SecAlloc(1); + + blst_p1 *ans = Util::SecAlloc(1); a.ToNative(ans); - g1_mul(ans, ans, k.keydata); - G1Element ret = G1Element::FromNative(ans); + byte *bte = Util::SecAlloc(32); + blst_lendian_from_scalar(bte, k.keydata); + blst_p1_mult(ans, ans, bte, 256); + G1Element ret = G1Element::FromNative(*ans); Util::SecFree(ans); + Util::SecFree(bte); return ret; } @@ -197,40 +186,40 @@ G1Element operator*(const PrivateKey &k, const G1Element &a) { return a * k; } G2Element operator*(const G2Element &a, const PrivateKey &k) { k.CheckKeyData(); - g2_st* ans = Util::SecAlloc(1); + blst_p2 *ans = Util::SecAlloc(1); a.ToNative(ans); - g2_mul(ans, ans, k.keydata); - G2Element ret = G2Element::FromNative(ans); + byte *bte = Util::SecAlloc(32); + blst_lendian_from_scalar(bte, k.keydata); + blst_p2_mult(ans, ans, bte, 256); + G2Element ret = G2Element::FromNative(*ans); Util::SecFree(ans); + Util::SecFree(bte); return ret; } G2Element operator*(const PrivateKey &k, const G2Element &a) { return a * k; } -PrivateKey operator*(const PrivateKey& k, const bn_t& a) +PrivateKey operator*(const PrivateKey& k, const blst_scalar& a) { k.CheckKeyData(); - bn_t order; - bn_new(order); - g2_get_ord(order); - PrivateKey ret; - bn_mul_comba(ret.keydata, k.keydata, a); - bn_mod_basic(ret.keydata, ret.keydata, order); + blst_sk_mul_n_check(ret.keydata, k.keydata, &a); return ret; } -PrivateKey operator*(const bn_t& a, const PrivateKey& k) { return a * k; } +PrivateKey operator*(const blst_scalar& a, const PrivateKey& k) { return k * a; } -G2Element PrivateKey::GetG2Power(const G2Element& element) const +G2Element PrivateKey::GetG2Power(const G2Element &element) const { CheckKeyData(); - g2_st* q = Util::SecAlloc(1); + blst_p2 *q = Util::SecAlloc(1); element.ToNative(q); - g2_mul(q, q, keydata); - - const G2Element ret = G2Element::FromNative(q); + byte *bte = Util::SecAlloc(32); + blst_lendian_from_scalar(bte, keydata); + blst_p2_mult(q, q, bte, 255); + const G2Element ret = G2Element::FromNative(*q); Util::SecFree(q); + Util::SecFree(bte); return ret; } @@ -240,30 +229,29 @@ PrivateKey PrivateKey::Aggregate(std::vector const &privateKeys) throw std::length_error("Number of private keys must be at least 1"); } - bn_t order; - bn_new(order); - g1_get_ord(order); - PrivateKey ret; assert(ret.IsZero()); for (size_t i = 0; i < privateKeys.size(); i++) { privateKeys[i].CheckKeyData(); - bn_add(ret.keydata, ret.keydata, privateKeys[i].keydata); - bn_mod_basic(ret.keydata, ret.keydata, order); + blst_sk_add_n_check(ret.keydata, ret.keydata, privateKeys[i].keydata); } return ret; } -bool PrivateKey::IsZero() const { +bool PrivateKey::IsZero() const +{ CheckKeyData(); - return bn_is_zero(keydata); + blst_scalar zro; + memset(&zro, 0x00, sizeof(blst_scalar)); + + return memcmp(keydata, &zro, sizeof(blst_scalar)) == 0; } bool operator==(const PrivateKey &a, const PrivateKey &b) { a.CheckKeyData(); b.CheckKeyData(); - return bn_cmp(a.keydata, b.keydata) == RLC_EQ; + return memcmp(a.keydata, b.keydata, sizeof(blst_scalar)) == 0; } bool operator!=(const PrivateKey &a, const PrivateKey &b) { return !(a == b); } @@ -274,17 +262,21 @@ void PrivateKey::Serialize(uint8_t *buffer) const throw std::runtime_error("PrivateKey::Serialize buffer invalid"); } CheckKeyData(); - bn_write_bin(buffer, PrivateKey::PRIVATE_KEY_SIZE, keydata); + // blst_bendian_from_scalar converts through a temporary limb vector and + // securely wipes it, which costs more than the serialization itself; + // the scalar's native bytes are little-endian, so copy and reverse. + blst_lendian_from_scalar(buffer, keydata); + std::reverse(buffer, buffer + PRIVATE_KEY_SIZE); } -std::vector PrivateKey::Serialize(const bool fLegacy) const +std::vector PrivateKey::Serialize() const { std::vector data(PRIVATE_KEY_SIZE); Serialize(data.data()); return data; } -std::array PrivateKey::SerializeToArray(bool fLegacy) const +std::array PrivateKey::SerializeToArray() const { std::array data{}; Serialize(data.data()); @@ -300,34 +292,32 @@ G2Element PrivateKey::SignG2( { CheckKeyData(); - g2_t pt; - g2_null(pt); - g2_new(pt); - + blst_p2 *pt = Util::SecAlloc(1); if (fLegacy) { + // The relic implementation always mapped exactly + // BLS::MESSAGE_HASH_LEN bytes regardless of len. ep2_map_legacy(pt, msg, BLS::MESSAGE_HASH_LEN); } else { - ep2_map_dst(pt, msg, len, dst, dst_len); + blst_hash_to_g2(pt, msg, len, dst, dst_len, nullptr, 0); } - - g2_mul(pt, pt, keydata); - G2Element ret = G2Element::FromNative(pt); - g2_free(pt); + blst_sign_pk_in_g1(pt, pt, keydata); + G2Element ret = G2Element::FromNative(*pt); + Util::SecFree(pt); return ret; } void PrivateKey::AllocateKeyData() { assert(!keydata); - keydata = Util::SecAlloc(1); - keydata->alloc = RLC_BN_SIZE; - bn_zero(keydata); + keydata = Util::SecAlloc(1); + memset(keydata, 0x00, sizeof(blst_scalar)); } void PrivateKey::CheckKeyData() const { if (keydata == nullptr) { - throw std::runtime_error("PrivateKey::CheckKeyData keydata not initialized"); + throw std::runtime_error( + "PrivateKey::CheckKeyData keydata not initialized"); } } diff --git a/src/dashbls/src/schemes.cpp b/src/dashbls/src/schemes.cpp index c0d7ad294c64..f4436d12cfe1 100644 --- a/src/dashbls/src/schemes.cpp +++ b/src/dashbls/src/schemes.cpp @@ -12,6 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "schemes.hpp" + +#include + #include #include #include @@ -19,7 +23,6 @@ #include "bls.hpp" #include "elements.hpp" -#include "schemes.hpp" #include "hdkeys.hpp" using std::string; @@ -28,12 +31,8 @@ using std::vector; namespace bls { template -static void HashPubKeys(bn_t* computedTs, size_t nPubKeys, GetBytesFn getBytes) +static void HashPubKeys(blst_scalar* computedTs, size_t nPubKeys, GetBytesFn getBytes) { - bn_t order; - bn_new(order); - g2_get_ord(order); - std::vector vecBuffer(nPubKeys * G1Element::SIZE); for (size_t i = 0; i < nPubKeys; i++) { @@ -53,19 +52,19 @@ static void HashPubKeys(bn_t* computedTs, size_t nPubKeys, GetBytesFn getBytes) std::memcpy(buffer + 4, pkHash, 32); Util::Hash256(hash, buffer, 4 + 32); - bn_read_bin(computedTs[i], hash, 32); - bn_mod_basic(computedTs[i], computedTs[i], order); + // reduces the hash mod the group order, like the former + // bn_read_bin + bn_mod + blst_scalar_from_be_bytes(&computedTs[i], hash, 32); } - bn_free(order); } -enum InvariantResult { BAD=false, GOOD=true, CONTINUE }; +enum InvariantResult { BAD = false, GOOD = true, CONTINUE }; // Enforce argument invariants for Agg Sig Verification InvariantResult VerifyAggregateSignatureArguments( const size_t nPubKeys, const size_t nMessages, - const G2Element &signature) + const G2Element& signature) { if (nPubKeys == 0) { return (nMessages == 0 && signature == G2Element() ? GOOD : BAD); @@ -79,77 +78,101 @@ InvariantResult VerifyAggregateSignatureArguments( /* These are all for the min-pubkey-size variant. TODO : analogs for min-signature-size */ -const std::string BasicSchemeMPL::CIPHERSUITE_ID = "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_"; -const std::string AugSchemeMPL::CIPHERSUITE_ID = "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_AUG_"; -const std::string PopSchemeMPL::CIPHERSUITE_ID = "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_"; -const std::string PopSchemeMPL::POP_CIPHERSUITE_ID = "BLS_POP_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_"; +const std::string BasicSchemeMPL::CIPHERSUITE_ID = + "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_"; +const std::string AugSchemeMPL::CIPHERSUITE_ID = + "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_AUG_"; +const std::string PopSchemeMPL::CIPHERSUITE_ID = + "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_"; +const std::string PopSchemeMPL::POP_CIPHERSUITE_ID = + "BLS_POP_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_"; -PrivateKey CoreMPL::KeyGen(const vector& seed) { +PrivateKey CoreMPL::KeyGen(const vector& seed) +{ return HDKeys::KeyGen(seed); } -PrivateKey CoreMPL::KeyGen(const Bytes& seed) { - return HDKeys::KeyGen(seed); -} +PrivateKey CoreMPL::KeyGen(const Bytes& seed) { return HDKeys::KeyGen(seed); } -vector CoreMPL::SkToPk(const PrivateKey &seckey) +vector CoreMPL::SkToPk(const PrivateKey& seckey) { return seckey.GetG1Element().Serialize(); } -G1Element CoreMPL::SkToG1(const PrivateKey &seckey) +G1Element CoreMPL::SkToG1(const PrivateKey& seckey) { return seckey.GetG1Element(); } -G2Element CoreMPL::Sign(const PrivateKey &seckey, const vector &message) +G2Element CoreMPL::Sign( + const PrivateKey& seckey, + const vector& message) { return CoreMPL::Sign(seckey, Bytes(message)); } G2Element CoreMPL::Sign(const PrivateKey& seckey, const Bytes& message) { - return seckey.SignG2(message.begin(), message.size(), (const uint8_t*)strCiphersuiteId.c_str(), strCiphersuiteId.length()); + return seckey.SignG2( + message.begin(), + message.size(), + (const uint8_t*)strCiphersuiteId.c_str(), + strCiphersuiteId.length()); } -bool CoreMPL::Verify(const vector &pubkey, - const vector &message, // unhashed - const vector &signature) +bool CoreMPL::Verify( + const vector& pubkey, + const vector& message, // unhashed + const vector& signature) { - return CoreMPL::Verify(G1Element::FromBytes(Bytes(pubkey)), - Bytes(message), - G2Element::FromBytes(Bytes(signature))); + return CoreMPL::Verify( + G1Element::FromBytes(Bytes(pubkey)), + Bytes(message), + G2Element::FromBytes(Bytes(signature))); } -bool CoreMPL::Verify(const Bytes& pubkey, const Bytes& message, const Bytes& signature) +bool CoreMPL::Verify( + const Bytes& pubkey, + const Bytes& message, + const Bytes& signature) { - return CoreMPL::Verify(G1Element::FromBytes(pubkey), message, G2Element::FromBytes(signature)); + return CoreMPL::Verify( + G1Element::FromBytes(pubkey), message, G2Element::FromBytes(signature)); } -bool CoreMPL::Verify(const G1Element &pubkey, - const vector &message, // unhashed - const G2Element &signature) +bool CoreMPL::Verify( + const G1Element& pubkey, + const vector& message, // unhashed + const G2Element& signature) { return CoreMPL::Verify(pubkey, Bytes(message), signature); } -bool CoreMPL::Verify(const G1Element& pubkey, const Bytes& message, const G2Element& signature) +bool CoreMPL::Verify( + const G1Element& pubkey, + const Bytes& message, + const G2Element& signature) { + // Keep the relic-era semantics rather than blst_core_verify: elements are + // gated by IsValid() (which accepts infinity) and the check is the product + // of pairings, so e.g. an infinity pubkey with an infinity signature + // verifies as it always did. const G2Element hashedPoint = G2Element::FromMessage(message, (const uint8_t*)strCiphersuiteId.c_str(), strCiphersuiteId.length()); - std::array g1s; - std::array g2s; - - G1Element::Generator().Negate().ToNative(g1s[0]); if (!pubkey.IsValid()) { return false; } if (!signature.IsValid()) { return false; } - pubkey.ToNative(g1s[1]); - signature.ToNative(g2s[0]); - hashedPoint.ToNative(g2s[1]); + + std::array g1s; + std::array g2s; + + G1Element::Generator().Negate().ToAffine(&g1s[0]); + pubkey.ToAffine(&g1s[1]); + signature.ToAffine(&g2s[0]); + hashedPoint.ToAffine(&g2s[1]); return CoreMPL::NativeVerify(g1s.data(), g2s.data(), 2); } @@ -174,7 +197,7 @@ std::array CoreMPL::Aggregate(const vector& sig return CoreMPL::Aggregate(elements).SerializeToArray(); } -G2Element CoreMPL::Aggregate(const vector &signatures) +G2Element CoreMPL::Aggregate(const vector& signatures) { G2Element aggregated; for (const G2Element& signature : signatures) { @@ -183,7 +206,7 @@ G2Element CoreMPL::Aggregate(const vector &signatures) return aggregated; } -G1Element CoreMPL::Aggregate(const vector &publicKeys) +G1Element CoreMPL::Aggregate(const vector& publicKeys) { G1Element aggregated; for (const G1Element& publicKey : publicKeys) { @@ -200,17 +223,16 @@ G2Element CoreMPL::AggregateSecure(std::vector const &vecPublicKeys, throw std::invalid_argument("LegacySchemeMPL::AggregateSigs sigs.size() != pubKeys.size()"); } - bn_t* computedTs = new bn_t[vecPublicKeys.size()]; + std::vector computedTs(vecPublicKeys.size()); std::vector, const G2Element*>> vecSorted(vecPublicKeys.size()); for (size_t i = 0; i < vecPublicKeys.size(); i++) { - bn_new(computedTs[i]); vecSorted[i] = std::make_pair(vecPublicKeys[i].SerializeToArray(fLegacy), &vecSignatures[i]); } std::sort(vecSorted.begin(), vecSorted.end(), [](const auto& a, const auto& b) { return std::memcmp(a.first.data(), b.first.data(), G1Element::SIZE) < 0; }); - HashPubKeys(computedTs, vecSorted.size(), + HashPubKeys(computedTs.data(), vecSorted.size(), [&](size_t i) { return vecSorted[i].first.data(); }); // Raise all signatures to power of the corresponding t's and aggregate the results into aggSig @@ -221,14 +243,7 @@ G2Element CoreMPL::AggregateSecure(std::vector const &vecPublicKeys, expSigs.emplace_back(*vecSorted[i].second * computedTs[i]); } - G2Element aggSig = CoreMPL::Aggregate(expSigs); - - for (size_t i = 0; i < vecPublicKeys.size(); i++) { - bn_free(computedTs[i]); - } - delete[] computedTs; - - return aggSig; + return CoreMPL::Aggregate(expSigs); } G2Element CoreMPL::AggregateSecure(std::vector const &vecPublicKeys, @@ -241,17 +256,16 @@ bool CoreMPL::VerifySecure(const std::vector& vecPublicKeys, const G2Element& signature, const Bytes& message, const bool fLegacy) { - bn_t* computedTs = new bn_t[vecPublicKeys.size()]; + std::vector computedTs(vecPublicKeys.size()); std::vector> vecSorted(vecPublicKeys.size()); for (size_t i = 0; i < vecPublicKeys.size(); i++) { - bn_new(computedTs[i]); vecSorted[i] = vecPublicKeys[i].SerializeToArray(fLegacy); } std::sort(vecSorted.begin(), vecSorted.end(), [](const auto& a, const auto& b) -> bool { return std::memcmp(a.data(), b.data(), G1Element::SIZE) < 0; }); - HashPubKeys(computedTs, vecSorted.size(), + HashPubKeys(computedTs.data(), vecSorted.size(), [&](size_t i) { return vecSorted[i].data(); }); G1Element publicKey; @@ -260,11 +274,6 @@ bool CoreMPL::VerifySecure(const std::vector& vecPublicKeys, publicKey += g1 * computedTs[i]; } - for (size_t i = 0; i < vecPublicKeys.size(); i++) { - bn_free(computedTs[i]); - } - delete[] computedTs; - return AggregateVerify({publicKey}, {message}, {signature}); } @@ -274,22 +283,26 @@ bool CoreMPL::VerifySecure(const std::vector& vecPublicKeys, return CoreMPL::VerifySecure(vecPublicKeys, signature, message, false); } -bool CoreMPL::AggregateVerify(const vector> &pubkeys, - const vector> &messages, // unhashed - const vector &signature) +bool CoreMPL::AggregateVerify( + const vector>& pubkeys, + const vector>& messages, // unhashed + const vector& signature) { const std::vector vecPubKeyBytes(pubkeys.begin(), pubkeys.end()); const std::vector vecMessagesBytes(messages.begin(), messages.end()); - return CoreMPL::AggregateVerify(vecPubKeyBytes, vecMessagesBytes, Bytes(signature)); + return CoreMPL::AggregateVerify( + vecPubKeyBytes, vecMessagesBytes, Bytes(signature)); } -bool CoreMPL::AggregateVerify(const vector& pubkeys, - const vector& messages, // unhashed - const Bytes& signature) +bool CoreMPL::AggregateVerify( + const vector& pubkeys, + const vector& messages, // unhashed + const Bytes& signature) { const size_t nPubKeys = pubkeys.size(); const G2Element signatureElement = G2Element::FromBytes(signature); - const auto arg_check = VerifyAggregateSignatureArguments(nPubKeys, messages.size(), signatureElement); + const auto arg_check = VerifyAggregateSignatureArguments( + nPubKeys, messages.size(), signatureElement); if (arg_check != CONTINUE) { return arg_check; } @@ -302,104 +315,118 @@ bool CoreMPL::AggregateVerify(const vector& pubkeys, return CoreMPL::AggregateVerify(pubkeyElements, messages, signatureElement); } -bool CoreMPL::AggregateVerify(const vector &pubkeys, - const vector> &messages, - const G2Element &signature) +bool CoreMPL::AggregateVerify( + const vector& pubkeys, + const vector>& messages, + const G2Element& signature) { - return CoreMPL::AggregateVerify(pubkeys, std::vector(messages.begin(), messages.end()), signature); + return CoreMPL::AggregateVerify( + pubkeys, + std::vector(messages.begin(), messages.end()), + signature); } -bool CoreMPL::AggregateVerify(const vector& pubkeys, - const vector &messages, - const G2Element& signature) +bool CoreMPL::AggregateVerify( + const vector& pubkeys, + const vector& messages, + const G2Element& signature) { const size_t nPubKeys = pubkeys.size(); - const auto arg_check = VerifyAggregateSignatureArguments(nPubKeys, messages.size(), signature); + const auto arg_check = + VerifyAggregateSignatureArguments(nPubKeys, messages.size(), signature); if (arg_check != CONTINUE) { return arg_check; } - std::vector vecG1(nPubKeys + 1); - std::vector vecG2(nPubKeys + 1); - G1Element::Generator().Negate().ToNative(&vecG1[0]); + std::vector vecG1(nPubKeys + 1); + std::vector vecG2(nPubKeys + 1); + G1Element::Generator().Negate().ToAffine(&vecG1[0]); if (!signature.IsValid()) { return false; } - signature.ToNative(&vecG2[0]); + signature.ToAffine(&vecG2[0]); for (size_t i = 0; i < nPubKeys; ++i) { if (!pubkeys[i].IsValid()) { return false; } - pubkeys[i].ToNative(&vecG1[i + 1]); - G2Element::FromMessage(messages[i], (const uint8_t*)strCiphersuiteId.c_str(), strCiphersuiteId.length()).ToNative(&vecG2[i + 1]); + pubkeys[i].ToAffine(&vecG1[i + 1]); + G2Element::FromMessage(messages[i], (const uint8_t*)strCiphersuiteId.c_str(), strCiphersuiteId.length()).ToAffine(&vecG2[i + 1]); } - return CoreMPL::NativeVerify((g1_t*)vecG1.data(), (g2_t*)vecG2.data(), nPubKeys + 1); + return CoreMPL::NativeVerify(vecG1.data(), vecG2.data(), nPubKeys + 1); } -bool CoreMPL::NativeVerify(g1_t *pubkeys, g2_t *mappedHashes, size_t length) +bool CoreMPL::NativeVerify(const blst_p1_affine* pubkeys, + const blst_p2_affine* mappedHashes, + size_t length) { - gt_t target, candidate, tmpPairing; - fp12_zero(target); - fp_set_dig(target[0][0][0], 1); - fp12_zero(candidate); - fp_set_dig(candidate[0][0][0], 1); - - // prod e(pubkey[i], hash[i]) * e(-g1, aggSig) - // Performs pubKeys.size() pairings, 250 at a time + // 1 =? prod e(pubkey[i], hash[i]) + // A pairing with the point at infinity on either side contributes the + // identity, matching relic's pc_map_sim. + blst_fp12 candidate = *blst_fp12_one(); - for (size_t i = 0; i < length; i += 250) { - size_t numPairings = std::min((length - i), (size_t)250); - pc_map_sim(tmpPairing, pubkeys + i, mappedHashes + i, numPairings); - fp12_mul(candidate, candidate, tmpPairing); + for (size_t i = 0; i < length; ++i) { + if (blst_p1_affine_is_inf(&pubkeys[i]) || + blst_p2_affine_is_inf(&mappedHashes[i])) { + continue; + } + blst_fp12 tmpPairing; + blst_miller_loop(&tmpPairing, &mappedHashes[i], &pubkeys[i]); + blst_fp12_mul(&candidate, &candidate, &tmpPairing); } - // 1 =? prod e(pubkey[i], hash[i]) * e(-g1, aggSig) - if (gt_cmp(target, candidate) != RLC_EQ || core_get()->code != RLC_OK) { - core_get()->code = RLC_OK; - return false; - } - BLS::CheckRelicErrors(); - return true; + blst_final_exp(&candidate, &candidate); + return blst_fp12_is_one(&candidate); } -PrivateKey CoreMPL::DeriveChildSk(const PrivateKey& sk, uint32_t index) { +PrivateKey CoreMPL::DeriveChildSk(const PrivateKey& sk, uint32_t index) +{ return HDKeys::DeriveChildSk(sk, index); } -PrivateKey CoreMPL::DeriveChildSkUnhardened(const PrivateKey& sk, uint32_t index) { +PrivateKey CoreMPL::DeriveChildSkUnhardened( + const PrivateKey& sk, + uint32_t index) +{ return HDKeys::DeriveChildSkUnhardened(sk, index); } -G1Element CoreMPL::DeriveChildPkUnhardened(const G1Element& pk, uint32_t index) { +G1Element CoreMPL::DeriveChildPkUnhardened(const G1Element& pk, uint32_t index) +{ return HDKeys::DeriveChildG1Unhardened(pk, index); } -bool BasicSchemeMPL::AggregateVerify(const vector> &pubkeys, - const vector> &messages, - const vector &signature) +bool BasicSchemeMPL::AggregateVerify( + const vector>& pubkeys, + const vector>& messages, + const vector& signature) { const size_t nPubKeys = pubkeys.size(); - auto arg_check = VerifyAggregateSignatureArguments(nPubKeys, messages.size(), G2Element::FromByteVector(signature)); + auto arg_check = VerifyAggregateSignatureArguments( + nPubKeys, messages.size(), G2Element::FromByteVector(signature)); if (arg_check != CONTINUE) { return arg_check; } - const std::set> setMessages(messages.begin(), messages.end()); + const std::set> setMessages( + messages.begin(), messages.end()); if (setMessages.size() != nPubKeys) { return false; } return CoreMPL::AggregateVerify(pubkeys, messages, signature); } -bool BasicSchemeMPL::AggregateVerify(const vector& pubkeys, - const vector& messages, - const Bytes& signature) +bool BasicSchemeMPL::AggregateVerify( + const vector& pubkeys, + const vector& messages, + const Bytes& signature) { const size_t nPubKeys = pubkeys.size(); - const auto arg_check = VerifyAggregateSignatureArguments(nPubKeys, messages.size(), G2Element::FromBytes(signature)); - if (arg_check != CONTINUE) return arg_check; + const auto arg_check = VerifyAggregateSignatureArguments( + nPubKeys, messages.size(), G2Element::FromBytes(signature)); + if (arg_check != CONTINUE) + return arg_check; std::set> setMessages; for (const auto& message : messages) { @@ -411,30 +438,36 @@ bool BasicSchemeMPL::AggregateVerify(const vector& pubkeys, return CoreMPL::AggregateVerify(pubkeys, messages, signature); } -bool BasicSchemeMPL::AggregateVerify(const vector &pubkeys, - const vector> &messages, - const G2Element &signature) +bool BasicSchemeMPL::AggregateVerify( + const vector& pubkeys, + const vector>& messages, + const G2Element& signature) { const size_t nPubKeys = pubkeys.size(); - const auto arg_check = VerifyAggregateSignatureArguments(nPubKeys, messages.size(), signature); + const auto arg_check = + VerifyAggregateSignatureArguments(nPubKeys, messages.size(), signature); if (arg_check != CONTINUE) { return arg_check; } - const std::set> setMessages(messages.begin(), messages.end()); + const std::set> setMessages( + messages.begin(), messages.end()); if (setMessages.size() != nPubKeys) { return false; } return CoreMPL::AggregateVerify(pubkeys, messages, signature); } -bool BasicSchemeMPL::AggregateVerify(const vector& pubkeys, - const vector &messages, - const G2Element& signature) +bool BasicSchemeMPL::AggregateVerify( + const vector& pubkeys, + const vector& messages, + const G2Element& signature) { const size_t nPubKeys = pubkeys.size(); - const auto arg_check = VerifyAggregateSignatureArguments(nPubKeys, messages.size(), signature); - if (arg_check != CONTINUE) return arg_check; + const auto arg_check = + VerifyAggregateSignatureArguments(nPubKeys, messages.size(), signature); + if (arg_check != CONTINUE) + return arg_check; std::set> setMessages; for (const auto& message : messages) { @@ -446,7 +479,9 @@ bool BasicSchemeMPL::AggregateVerify(const vector& pubkeys, return CoreMPL::AggregateVerify(pubkeys, messages, signature); } -G2Element AugSchemeMPL::Sign(const PrivateKey &seckey, const vector &message) +G2Element AugSchemeMPL::Sign( + const PrivateKey& seckey, + const vector& message) { return AugSchemeMPL::Sign(seckey, message, seckey.GetG1Element()); } @@ -457,17 +492,19 @@ G2Element AugSchemeMPL::Sign(const PrivateKey& seckey, const Bytes& message) } // Used for prepending different augMessage -G2Element AugSchemeMPL::Sign(const PrivateKey &seckey, - const vector &message, - const G1Element &prepend_pk) +G2Element AugSchemeMPL::Sign( + const PrivateKey& seckey, + const vector& message, + const G1Element& prepend_pk) { return AugSchemeMPL::Sign(seckey, Bytes(message), prepend_pk); } // Used for prepending different augMessage -G2Element AugSchemeMPL::Sign(const PrivateKey& seckey, - const Bytes& message, - const G1Element& prepend_pk) +G2Element AugSchemeMPL::Sign( + const PrivateKey& seckey, + const Bytes& message, + const G1Element& prepend_pk) { vector augMessage = prepend_pk.Serialize(); augMessage.reserve(augMessage.size() + message.size()); @@ -475,9 +512,10 @@ G2Element AugSchemeMPL::Sign(const PrivateKey& seckey, return CoreMPL::Sign(seckey, augMessage); } -bool AugSchemeMPL::Verify(const vector &pubkey, - const vector &message, - const vector &signature) +bool AugSchemeMPL::Verify( + const vector& pubkey, + const vector& message, + const vector& signature) { vector augMessage(pubkey); augMessage.reserve(augMessage.size() + message.size()); @@ -485,9 +523,10 @@ bool AugSchemeMPL::Verify(const vector &pubkey, return CoreMPL::Verify(pubkey, augMessage, signature); } -bool AugSchemeMPL::Verify(const Bytes& pubkey, - const Bytes& message, - const Bytes& signature) +bool AugSchemeMPL::Verify( + const Bytes& pubkey, + const Bytes& message, + const Bytes& signature) { vector augMessage(pubkey.begin(), pubkey.end()); augMessage.reserve(augMessage.size() + message.size()); @@ -495,16 +534,18 @@ bool AugSchemeMPL::Verify(const Bytes& pubkey, return CoreMPL::Verify(pubkey, Bytes(augMessage), Bytes(signature)); } -bool AugSchemeMPL::Verify(const G1Element &pubkey, - const vector &message, - const G2Element &signature) +bool AugSchemeMPL::Verify( + const G1Element& pubkey, + const vector& message, + const G2Element& signature) { return AugSchemeMPL::Verify(pubkey, Bytes(message), signature); } -bool AugSchemeMPL::Verify(const G1Element& pubkey, - const Bytes& message, - const G2Element& signature) +bool AugSchemeMPL::Verify( + const G1Element& pubkey, + const Bytes& message, + const G2Element& signature) { vector augMessage = pubkey.Serialize(); augMessage.reserve(augMessage.size() + message.size()); @@ -512,21 +553,25 @@ bool AugSchemeMPL::Verify(const G1Element& pubkey, return CoreMPL::Verify(pubkey, augMessage, signature); } -bool AugSchemeMPL::AggregateVerify(const vector> &pubkeys, - const vector> &messages, - const vector &signature) +bool AugSchemeMPL::AggregateVerify( + const vector>& pubkeys, + const vector>& messages, + const vector& signature) { std::vector vecPubKeyBytes(pubkeys.begin(), pubkeys.end()); std::vector vecMessagesBytes(messages.begin(), messages.end()); - return AugSchemeMPL::AggregateVerify(vecPubKeyBytes, vecMessagesBytes, Bytes(signature)); + return AugSchemeMPL::AggregateVerify( + vecPubKeyBytes, vecMessagesBytes, Bytes(signature)); } -bool AugSchemeMPL::AggregateVerify(const vector& pubkeys, - const vector& messages, - const Bytes& signature) +bool AugSchemeMPL::AggregateVerify( + const vector& pubkeys, + const vector& messages, + const Bytes& signature) { size_t nPubKeys = pubkeys.size(); - auto arg_check = VerifyAggregateSignatureArguments(nPubKeys, messages.size(), G2Element::FromBytes(signature)); + auto arg_check = VerifyAggregateSignatureArguments( + nPubKeys, messages.size(), G2Element::FromBytes(signature)); if (arg_check != CONTINUE) { return arg_check; } @@ -539,30 +584,34 @@ bool AugSchemeMPL::AggregateVerify(const vector& pubkeys, aug.insert(aug.end(), messages[i].begin(), messages[i].end()); } - std::vector vecAugMessageBytes(augMessages.begin(), augMessages.end()); + std::vector vecAugMessageBytes( + augMessages.begin(), augMessages.end()); return CoreMPL::AggregateVerify(pubkeys, vecAugMessageBytes, signature); } -bool AugSchemeMPL::AggregateVerify(const vector& pubkeys, - const vector>& messages, - const G2Element& signature) +bool AugSchemeMPL::AggregateVerify( + const vector& pubkeys, + const vector>& messages, + const G2Element& signature) { std::vector vecMessagesBytes(messages.begin(), messages.end()); return AugSchemeMPL::AggregateVerify(pubkeys, vecMessagesBytes, signature); } -bool AugSchemeMPL::AggregateVerify(const vector& pubkeys, - const vector& messages, - const G2Element& signature) +bool AugSchemeMPL::AggregateVerify( + const vector& pubkeys, + const vector& messages, + const G2Element& signature) { size_t nPubKeys = pubkeys.size(); - auto arg_check = VerifyAggregateSignatureArguments(nPubKeys, messages.size(), signature); + auto arg_check = + VerifyAggregateSignatureArguments(nPubKeys, messages.size(), signature); if (arg_check != CONTINUE) { return arg_check; } vector> augMessages(nPubKeys); - for (int i = 0; i < nPubKeys; ++i) { + for (size_t i = 0; i < nPubKeys; ++i) { vector& aug = augMessages[i]; vector&& pubkey = pubkeys[i].Serialize(); aug.reserve(pubkey.size() + messages[i].size()); @@ -573,84 +622,89 @@ bool AugSchemeMPL::AggregateVerify(const vector& pubkeys, return CoreMPL::AggregateVerify(pubkeys, augMessages, signature); } -G2Element PopSchemeMPL::PopProve(const PrivateKey &seckey) +G2Element PopSchemeMPL::PopProve(const PrivateKey& seckey) { - const G1Element& pk = seckey.GetG1Element(); - const G2Element hashedKey = G2Element::FromMessage(pk.SerializeToArray(), (const uint8_t *)POP_CIPHERSUITE_ID.c_str(), POP_CIPHERSUITE_ID.length()); - return seckey.GetG2Power(hashedKey); -} + std::array pubkey_bytes = seckey.GetG1Element().SerializeToArray(); + return seckey.SignG2( + pubkey_bytes.data(), + pubkey_bytes.size(), + (const uint8_t*)POP_CIPHERSUITE_ID.c_str(), + POP_CIPHERSUITE_ID.length()); +} -bool PopSchemeMPL::PopVerify(const G1Element &pubkey, const G2Element &signature_proof) +bool PopSchemeMPL::PopVerify( + const G1Element& pubkey, + const G2Element& signature_proof) { - const G2Element hashedPoint = G2Element::FromMessage(pubkey.SerializeToArray(), (const uint8_t*)POP_CIPHERSUITE_ID.c_str(), POP_CIPHERSUITE_ID.length()); + blst_p1_affine pubkeyAffine; + blst_p2_affine sigAffine; - g1_t g1s[2]; - g2_t g2s[2]; + pubkey.ToAffine(&pubkeyAffine); + signature_proof.ToAffine(&sigAffine); + std::array pubkey_bytes = pubkey.SerializeToArray(); - if (!pubkey.IsValid()) { - return false; - } - if (!signature_proof.IsValid()) { - return false; - } - G1Element::Generator().Negate().ToNative(g1s[0]); - pubkey.ToNative(g1s[1]); - signature_proof.ToNative(g2s[0]); - hashedPoint.ToNative(g2s[1]); + auto err = blst_core_verify_pk_in_g1( + &pubkeyAffine, + &sigAffine, + true, /*hash*/ + pubkey_bytes.data(), + pubkey_bytes.size(), + (const uint8_t*)POP_CIPHERSUITE_ID.c_str(), + POP_CIPHERSUITE_ID.length()); - return CoreMPL::NativeVerify(g1s, g2s, 2); + return err == BLST_SUCCESS; } -bool PopSchemeMPL::PopVerify(const vector &pubkey, const vector &proof) +bool PopSchemeMPL::PopVerify( + const vector& pubkey, + const vector& proof) { return PopSchemeMPL::PopVerify(Bytes(pubkey), Bytes(proof)); } bool PopSchemeMPL::PopVerify(const Bytes& pubkey, const Bytes& proof) { - const G2Element hashedPoint = G2Element::FromMessage(pubkey, (const uint8_t*)POP_CIPHERSUITE_ID.c_str(), POP_CIPHERSUITE_ID.length()); - - g1_t g1s[2]; - g2_t g2s[2]; - - G1Element::Generator().Negate().ToNative(g1s[0]); - G1Element::FromBytes(pubkey).ToNative(g1s[1]); - G2Element::FromBytes(proof).ToNative(g2s[0]); - hashedPoint.ToNative(g2s[1]); - - return CoreMPL::NativeVerify(g1s, g2s, 2); + return PopSchemeMPL::PopVerify( + G1Element::FromBytes(pubkey), G2Element::FromBytes(proof)); } -bool PopSchemeMPL::FastAggregateVerify(const vector &pubkeys, - const vector &message, - const G2Element &signature) +bool PopSchemeMPL::FastAggregateVerify( + const vector& pubkeys, + const vector& message, + const G2Element& signature) { - return PopSchemeMPL::FastAggregateVerify(pubkeys, Bytes(message), signature); + return PopSchemeMPL::FastAggregateVerify( + pubkeys, Bytes(message), signature); } -bool PopSchemeMPL::FastAggregateVerify(const vector& pubkeys, - const Bytes& message, - const G2Element& signature) +bool PopSchemeMPL::FastAggregateVerify( + const vector& pubkeys, + const Bytes& message, + const G2Element& signature) { if (pubkeys.size() == 0) { return false; } - // No VerifyAggregateSignatureArguments checks required here as we have exactly one pubkey and one message. + // No VerifyAggregateSignatureArguments checks required here as we have + // exactly one pubkey and one message. return CoreMPL::Verify(CoreMPL::Aggregate(pubkeys), message, signature); } -bool PopSchemeMPL::FastAggregateVerify(const vector> &pubkeys, - const vector &message, - const vector &signature) +bool PopSchemeMPL::FastAggregateVerify( + const vector>& pubkeys, + const vector& message, + const vector& signature) { const std::vector vecPubKeyBytes(pubkeys.begin(), pubkeys.end()); - return PopSchemeMPL::FastAggregateVerify(vecPubKeyBytes, Bytes(message), Bytes(signature)); + return PopSchemeMPL::FastAggregateVerify( + vecPubKeyBytes, Bytes(message), Bytes(signature)); } -bool PopSchemeMPL::FastAggregateVerify(const vector& pubkeys, - const Bytes& message, - const Bytes& signature) +bool PopSchemeMPL::FastAggregateVerify( + const vector& pubkeys, + const Bytes& message, + const Bytes& signature) { const size_t nPubKeys = pubkeys.size(); if (nPubKeys == 0) { @@ -662,7 +716,8 @@ bool PopSchemeMPL::FastAggregateVerify(const vector& pubkeys, pkelements.push_back(G1Element::FromBytes(pubkeys[i])); } - return PopSchemeMPL::FastAggregateVerify(pkelements, message, G2Element::FromBytes(signature)); + return PopSchemeMPL::FastAggregateVerify( + pkelements, message, G2Element::FromBytes(signature)); } G2Element LegacySchemeMPL::Sign(const PrivateKey& seckey, const Bytes& message) @@ -672,13 +727,13 @@ G2Element LegacySchemeMPL::Sign(const PrivateKey& seckey, const Bytes& message) bool LegacySchemeMPL::Verify(const G1Element &pubkey, const Bytes& message, const G2Element &signature) { - g1_t g1s[2]; - g2_t g2s[2]; + blst_p1_affine g1s[2]; + blst_p2_affine g2s[2]; - G1Element::Generator().Negate().ToNative(g1s[0]); - pubkey.ToNative(g1s[1]); - signature.ToNative(g2s[0]); - G2Element::FromMessage(message, nullptr, 0, true).ToNative(g2s[1]); + G1Element::Generator().Negate().ToAffine(&g1s[0]); + pubkey.ToAffine(&g1s[1]); + signature.ToAffine(&g2s[0]); + G2Element::FromMessage(message, nullptr, 0, true).ToAffine(&g2s[1]); return CoreMPL::NativeVerify(g1s, g2s, 2); } @@ -703,17 +758,17 @@ bool LegacySchemeMPL::AggregateVerify(const vector &pubkeys, const auto arg_check = VerifyAggregateSignatureArguments(nPubKeys, messages.size(), signature); if (arg_check != CONTINUE) return arg_check; - std::vector vecG1(nPubKeys + 1); - std::vector vecG2(nPubKeys + 1); - G1Element::Generator().Negate().ToNative(&vecG1[0]); - signature.ToNative(&vecG2[0]); + std::vector vecG1(nPubKeys + 1); + std::vector vecG2(nPubKeys + 1); + G1Element::Generator().Negate().ToAffine(&vecG1[0]); + signature.ToAffine(&vecG2[0]); for (size_t i = 0; i < nPubKeys; ++i) { - pubkeys[i].ToNative(&vecG1[i + 1]); - G2Element::FromMessage(messages[i], nullptr, 0, true).ToNative(&vecG2[i + 1]); + pubkeys[i].ToAffine(&vecG1[i + 1]); + G2Element::FromMessage(messages[i], nullptr, 0, true).ToAffine(&vecG2[i + 1]); } - return CoreMPL::NativeVerify((g1_t*)vecG1.data(), (g2_t*)vecG2.data(), nPubKeys + 1); + return CoreMPL::NativeVerify(vecG1.data(), vecG2.data(), nPubKeys + 1); } } // end namespace bls diff --git a/src/dashbls/src/test-bench.cpp b/src/dashbls/src/test-bench.cpp index 20bbbb443952..e89ff7e76c8c 100644 --- a/src/dashbls/src/test-bench.cpp +++ b/src/dashbls/src/test-bench.cpp @@ -13,22 +13,27 @@ // limitations under the License. #include + #include "bls.hpp" #include "test-utils.hpp" -extern "C" { -#include "relic.h" -} - using std::string; using std::vector; -using std::cout; -using std::endl; using namespace bls; +std::vector wjbgetRandomSeed() +{ + uint8_t buf[32]; + + for (int i = 0; i < 32; i++) buf[i] = rand(); -void benchSigs() { + std::vector ret(buf, buf + 32); + return ret; +} + +void benchSigs() +{ string testName = "Signing"; const int numIters = 5000; PrivateKey sk = BasicSchemeMPL().KeyGen(getRandomSeed()); @@ -42,21 +47,22 @@ void benchSigs() { endStopwatch(testName, start, numIters); } -void benchVerification() { +void benchVerification() +{ string testName = "Verification"; const int numIters = 1000; PrivateKey sk = BasicSchemeMPL().KeyGen(getRandomSeed()); G1Element pk = sk.GetG1Element(); - std::vector sigs; + vector pkBytes = pk.Serialize(); for (int i = 0; i < numIters; i++) { uint8_t message[4]; Util::IntToFourBytes(message, i); vector messageBytes(message, message + 4); - sigs.push_back(BasicSchemeMPL().Sign(sk, messageBytes)); + G2Element sig = BasicSchemeMPL().Sign(sk, messageBytes); + sigs.push_back(sig); } - auto start = startStopwatch(); for (int i = 0; i < numIters; i++) { uint8_t message[4]; @@ -68,7 +74,8 @@ void benchVerification() { endStopwatch(testName, start, numIters); } -void benchBatchVerification() { +void benchBatchVerification() +{ const int numIters = 10000; vector> sig_bytes; @@ -116,7 +123,8 @@ void benchBatchVerification() { endStopwatch("Batch verification", start, numIters); } -void benchSerialize() { +void benchSerialize() +{ const int numIters = 5000000; PrivateKey sk = BasicSchemeMPL().KeyGen(getRandomSeed()); G1Element pk = sk.GetG1Element(); @@ -142,7 +150,8 @@ void benchSerialize() { endStopwatch("Serialize G2Element", start, numIters); } -void benchSerializeToArray() { +void benchSerializeToArray() +{ const int numIters = 5000000; PrivateKey sk = BasicSchemeMPL().KeyGen(getRandomSeed()); G1Element pk = sk.GetG1Element(); @@ -168,7 +177,8 @@ void benchSerializeToArray() { endStopwatch("SerializeToArray G2Element", start, numIters); } -int main(int argc, char* argv[]) { +int main(int argc, char* argv[]) +{ benchSigs(); benchVerification(); benchBatchVerification(); diff --git a/src/dashbls/src/test-vectors.hpp b/src/dashbls/src/test-vectors.hpp new file mode 100644 index 000000000000..430d7ec877e5 --- /dev/null +++ b/src/dashbls/src/test-vectors.hpp @@ -0,0 +1,575 @@ +// Copyright (c) 2026 The Dash Core developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef SRC_TEST_VECTORS_HPP_ +#define SRC_TEST_VECTORS_HPP_ + +// Reference consensus vectors. +// +// GenerateReferenceVectors() deterministically exercises the public dashbls +// API - legacy and basic serialization (including malformed input), legacy +// signing, secure aggregation, threshold signing, extended keys and the +// private key edge cases - and emits one "name=value" line per result. +// +// test-vectors/reference.txt holds the output of the relic-based library; +// runtest compares the current library against it line by line, and +// tools/vectorgen.cpp regenerates it. Only the public API is used so the +// same code builds against any backend. + +#include +#include +#include +#include +#include +#include + +#include "bls.hpp" + +namespace bls_test_vectors { + +using namespace bls; +using std::vector; + +struct Emitter { + std::vector lines; + + static std::string hex(const uint8_t* p, size_t n) + { + static const char* digits = "0123456789abcdef"; + std::string s; + s.reserve(n * 2); + for (size_t i = 0; i < n; i++) { + s.push_back(digits[p[i] >> 4]); + s.push_back(digits[p[i] & 0x0f]); + } + return s; + } + + void raw(const std::string& line) { lines.push_back(line); } + void dump(const std::string& name, const vector& v) { lines.push_back(name + "=" + hex(v.data(), v.size())); } + template + void dump(const std::string& name, const std::array& v) { lines.push_back(name + "=" + hex(v.data(), N)); } + void dumpb(const std::string& name, bool v) { lines.push_back(name + "=" + (v ? "1" : "0")); } + void dumpu(const std::string& name, uint32_t v) + { + char buf[16]; + snprintf(buf, sizeof(buf), "%08x", v); + lines.push_back(name + "=" + buf); + } + void exc(const std::string& name) { lines.push_back(name + "=EXC"); } +}; + +inline vector seedN(int i) +{ + vector s(32); + for (int j = 0; j < 32; j++) s[j] = (uint8_t)(0x11 * (i + 1) + j * 7); + return s; +} + +inline vector hashN(int i) +{ + vector h(32); + for (int j = 0; j < 32; j++) h[j] = (uint8_t)(0xA5 ^ (i * 31 + j * 13)); + return h; +} + +inline std::string tag(const char* base, int i) +{ + char buf[96]; + snprintf(buf, sizeof(buf), "%s.%d", base, i); + return std::string(buf); +} + +// ---------------------------------------------------------------- section A/B +inline void KeysAndSignatures(Emitter& e) +{ + LegacySchemeMPL legacy; + BasicSchemeMPL basic; + + for (int i = 0; i < 8; i++) { + PrivateKey sk = basic.KeyGen(seedN(i)); + e.dump(tag("A.sk", i), sk.Serialize()); + + G1Element pk = sk.GetG1Element(); + e.dump(tag("A.pk.basic", i), pk.Serialize(false)); + e.dump(tag("A.pk.legacy", i), pk.Serialize(true)); + e.dumpu(tag("A.fp.basic", i), pk.GetFingerprint(false)); + e.dumpu(tag("A.fp.legacy", i), pk.GetFingerprint(true)); + e.dump(tag("A.skG2.basic", i), sk.GetG2Element().Serialize(false)); + e.dump(tag("A.skG2.legacy", i), sk.GetG2Element().Serialize(true)); + + // round-trips through both codecs + e.dump(tag("A.pk.rt.legacy", i), + G1Element::FromBytes(Bytes(pk.Serialize(true)), true).Serialize(true)); + e.dump(tag("A.pk.rt.basic", i), + G1Element::FromBytes(Bytes(pk.Serialize(false)), false).Serialize(false)); + + // legacy sign over a 32-byte hash; serialize under both codecs + vector h = hashN(i); + G2Element lsig = legacy.Sign(sk, Bytes(h)); + e.dump(tag("B.lsig.legacy", i), lsig.Serialize(true)); + e.dump(tag("B.lsig.basic", i), lsig.Serialize(false)); + e.dumpb(tag("B.lverify", i), legacy.Verify(pk, Bytes(h), lsig)); + // wrong message must fail + vector h2 = hashN(i + 100); + e.dumpb(tag("B.lverify.bad", i), legacy.Verify(pk, Bytes(h2), lsig)); + // legacy sig round-trip through legacy codec + e.dump(tag("B.lsig.rt", i), + G2Element::FromBytes(Bytes(lsig.Serialize(true)), true).Serialize(true)); + + // basic scheme (arbitrary-length message) + vector msg = {(uint8_t)i, 1, 2, 3, 200, 255}; + G2Element bsig = basic.Sign(sk, msg); + e.dump(tag("B.bsig.basic", i), bsig.Serialize(false)); + e.dump(tag("B.bsig.legacy", i), bsig.Serialize(true)); + e.dumpb(tag("B.bverify", i), basic.Verify(pk, msg, bsig)); + + // EIP-2333 derivation + e.dump(tag("A.child.hard", i), basic.DeriveChildSk(sk, 0x8000002a).Serialize()); + e.dump(tag("A.child.soft", i), basic.DeriveChildSkUnhardened(sk, 1337).Serialize()); + } +} + +// ---------------------------------------------------------------- section C/D +inline void SecureAggregation(Emitter& e) +{ + LegacySchemeMPL legacy; + BasicSchemeMPL basic; + + for (int n : {1, 2, 3, 10}) { + vector sks; + vector pks; + vector lsigs, bsigs; + vector h = hashN(n); + for (int i = 0; i < n; i++) { + sks.push_back(basic.KeyGen(seedN(200 + n * 16 + i))); + pks.push_back(sks.back().GetG1Element()); + lsigs.push_back(legacy.Sign(sks.back(), Bytes(h))); + bsigs.push_back(basic.Sign(sks.back(), Bytes(h))); + } + G2Element lagg = legacy.AggregateSecure(pks, lsigs, Bytes(h)); + e.dump(tag("C.aggsec.legacy", n), lagg.Serialize(true)); + e.dumpb(tag("C.versec.legacy", n), legacy.VerifySecure(pks, lagg, Bytes(h))); + + G2Element bagg = basic.AggregateSecure(pks, bsigs, Bytes(h)); + e.dump(tag("C.aggsec.basic", n), bagg.Serialize(false)); + e.dumpb(tag("C.versec.basic", n), basic.VerifySecure(pks, bagg, Bytes(h))); + + // cross checks must fail + e.dumpb(tag("C.versec.legacy.bad", n), + legacy.VerifySecure(pks, lagg, Bytes(hashN(n + 50)))); + + // plain aggregation + e.dump(tag("C.agg.G2", n), basic.Aggregate(bsigs).Serialize(false)); + e.dump(tag("C.agg.G1", n), basic.Aggregate(pks).Serialize(false)); + e.dump(tag("C.agg.sk", n), PrivateKey::Aggregate(sks).Serialize()); + } + + // legacy multi-message AggregateVerify + { + int n = 4; + vector sks; + vector pks; + vector sigs; + vector> msgs; + for (int i = 0; i < n; i++) { + sks.push_back(basic.KeyGen(seedN(300 + i))); + pks.push_back(sks.back().GetG1Element()); + msgs.push_back(hashN(300 + i)); + sigs.push_back(legacy.Sign(sks.back(), Bytes(msgs.back()))); + } + G2Element agg = basic.Aggregate(sigs); // plain point sum + vector msgRefs; + for (auto& m : msgs) msgRefs.push_back(Bytes(m)); + e.dump("D.lagg", agg.Serialize(true)); + e.dumpb("D.laggverify", legacy.AggregateVerify(pks, msgRefs, agg)); + vector badRefs; + badRefs.push_back(Bytes(msgs[1])); + for (size_t i = 1; i < msgs.size(); i++) badRefs.push_back(Bytes(msgs[i])); + e.dumpb("D.laggverify.bad", legacy.AggregateVerify(pks, badRefs, agg)); + } +} + +// ------------------------------------------------------------------ section E +inline void ThresholdVectors(Emitter& e) +{ + BasicSchemeMPL basic; + const int m = 3, n = 5; + + // polynomial coefficients (the "master" keys) + vector coeffs; + vector vvec; + vector sigCoeffs; + vector h = hashN(77); + for (int i = 0; i < m; i++) { + coeffs.push_back(basic.KeyGen(seedN(400 + i))); + vvec.push_back(coeffs.back().GetG1Element()); + sigCoeffs.push_back(Threshold::Sign(coeffs[i], Bytes(h))); + } + e.dump("E.mastersig", Threshold::Sign(coeffs[0], Bytes(h)).Serialize(true)); + e.dumpb("E.masterverify", + Threshold::Verify(vvec[0], Bytes(h), Threshold::Sign(coeffs[0], Bytes(h)))); + + vector> ids; + for (int i = 0; i < n; i++) ids.push_back(hashN(500 + i)); + + vector skShares; + vector sigShares; + for (int i = 0; i < n; i++) { + PrivateKey sh = Threshold::PrivateKeyShare(coeffs, Bytes(ids[i])); + skShares.push_back(sh); + e.dump(tag("E.skshare", i), sh.Serialize()); + G1Element pkShare = Threshold::PublicKeyShare(vvec, Bytes(ids[i])); + e.dump(tag("E.pkshare", i), pkShare.Serialize(true)); + e.dumpb(tag("E.sharematch", i), pkShare == sh.GetG1Element()); + G2Element sigShare = Threshold::SignatureShare(sigCoeffs, Bytes(ids[i])); + e.dump(tag("E.sigshare.poly", i), sigShare.Serialize(true)); + G2Element sigShare2 = Threshold::Sign(sh, Bytes(h)); + e.dump(tag("E.sigshare.sign", i), sigShare2.Serialize(true)); + sigShares.push_back(sigShare2); + } + + // recover from first m shares + vector mSk(skShares.begin(), skShares.begin() + m); + vector mSig(sigShares.begin(), sigShares.begin() + m); + vector mIds; + for (int i = 0; i < m; i++) mIds.push_back(Bytes(ids[i])); + + PrivateKey skRec = Threshold::PrivateKeyRecover(mSk, mIds); + e.dump("E.skrecover", skRec.Serialize()); + e.dumpb("E.skrecover.match", skRec == coeffs[0]); + + vector mPk; + for (int i = 0; i < m; i++) mPk.push_back(skShares[i].GetG1Element()); + e.dump("E.pkrecover", Threshold::PublicKeyRecover(mPk, mIds).Serialize(true)); + + G2Element sigRec = Threshold::SignatureRecover(mSig, mIds); + e.dump("E.sigrecover", sigRec.Serialize(true)); + e.dumpb("E.sigrecover.verify", Threshold::Verify(vvec[0], Bytes(h), sigRec)); + + // recovery from a different share subset must give the same signature + vector mSig2(sigShares.begin() + 1, sigShares.begin() + 1 + m); + vector mIds2; + for (int i = 1; i < 1 + m; i++) mIds2.push_back(Bytes(ids[i])); + e.dumpb("E.sigrecover.same", + Threshold::SignatureRecover(mSig2, mIds2) == sigRec); +} + +// ------------------------------------------------------------------ section F +inline void ExtendedKeys(Emitter& e) +{ + vector seed = seedN(600); + ExtendedPrivateKey esk = ExtendedPrivateKey::FromSeed(Bytes(seed)); + e.dump("F.esk", esk.Serialize()); + e.dump("F.esk.pk.legacy", esk.GetPublicKey().Serialize(true)); + e.dump("F.esk.pk.basic", esk.GetPublicKey().Serialize(false)); + e.dump("F.esk.chaincode", esk.GetChainCode().Serialize()); + + // legacy derivation chain (fLegacy defaults true on these APIs) + ExtendedPrivateKey c1l = esk.PrivateChild(1, true); + ExtendedPrivateKey c2l = c1l.PrivateChild(0x8000002a, true); + e.dump("F.child.legacy", c2l.Serialize()); + e.dump("F.child.legacy.sk", c2l.GetPrivateKey().Serialize()); + + // modern derivation chain + ExtendedPrivateKey c1b = esk.PrivateChild(1, false); + ExtendedPrivateKey c2b = c1b.PrivateChild(0x8000002a, false); + e.dump("F.child.basic", c2b.Serialize()); + e.dump("F.child.basic.sk", c2b.GetPrivateKey().Serialize()); + + // extended public keys and public derivation + ExtendedPublicKey epkl = esk.GetExtendedPublicKey(true); + e.dump("F.epk.legacy", epkl.Serialize(true)); + ExtendedPublicKey epkb = esk.GetExtendedPublicKey(false); + e.dump("F.epk.basic", epkb.Serialize(false)); + e.dump("F.epk.child.legacy", epkl.PublicChild(1, true).Serialize(true)); + e.dump("F.epk.child.basic", epkb.PublicChild(1, false).Serialize(false)); + e.dumpb("F.pubpriv.match.legacy", + epkl.PublicChild(1, true).GetPublicKey() == + esk.PrivateChild(1, true).GetPublicKey()); + + // round-trips + e.dump("F.esk.rt", + ExtendedPrivateKey::FromBytes(Bytes(esk.Serialize())).Serialize()); + e.dump("F.epk.rt.legacy", + ExtendedPublicKey::FromBytes(Bytes(epkl.Serialize(true)), true).Serialize(true)); +} + +// ------------------------------------------------------------------ section G +inline void PrivateKeyEdges(Emitter& e) +{ + // in-range key round-trip, both modOrder values + PrivateKey sk = BasicSchemeMPL().KeyGen(seedN(700)); + vector raw = sk.Serialize(); + e.dump("G.inrange.mod0", PrivateKey::FromBytes(Bytes(raw), false).Serialize()); + e.dump("G.inrange.mod1", PrivateKey::FromBytes(Bytes(raw), true).Serialize()); + + // value >= group order: modOrder=true reduces, modOrder=false throws + vector big(32, 0xff); + try { e.dump("G.big.mod1", PrivateKey::FromBytes(Bytes(big), true).Serialize()); } + catch (const std::exception&) { e.exc("G.big.mod1"); } + try { e.dump("G.big.mod0", PrivateKey::FromBytes(Bytes(big), false).Serialize()); } + catch (const std::exception&) { e.exc("G.big.mod0"); } + + // the group order itself, and order-1 + // r = 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001 + vector order = { + 0x73, 0xed, 0xa7, 0x53, 0x29, 0x9d, 0x7d, 0x48, 0x33, 0x39, 0xd8, + 0x08, 0x09, 0xa1, 0xd8, 0x05, 0x53, 0xbd, 0xa4, 0x02, 0xff, 0xfe, + 0x5b, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01}; + try { e.dump("G.order.mod1", PrivateKey::FromBytes(Bytes(order), true).Serialize()); } + catch (const std::exception&) { e.exc("G.order.mod1"); } + try { e.dump("G.order.mod0", PrivateKey::FromBytes(Bytes(order), false).Serialize()); } + catch (const std::exception&) { e.exc("G.order.mod0"); } + vector orderm1 = order; + orderm1[31] = 0x00; + try { e.dump("G.orderm1.mod0", PrivateKey::FromBytes(Bytes(orderm1), false).Serialize()); } + catch (const std::exception&) { e.exc("G.orderm1.mod0"); } + + // zero key + vector zero(32, 0x00); + try { + PrivateKey z = PrivateKey::FromBytes(Bytes(zero), false); + e.dump("G.zero.sk", z.Serialize()); + e.dump("G.zero.pk", z.GetG1Element().Serialize(false)); + } catch (const std::exception&) { e.exc("G.zero.sk"); } + + // FromSeedBIP32 + e.dump("G.bip32seed", PrivateKey::FromSeedBIP32(Bytes(seedN(701))).Serialize()); + + // DH key exchange: sk_a * pk_b == sk_b * pk_a + PrivateKey a = BasicSchemeMPL().KeyGen(seedN(702)); + PrivateKey b = BasicSchemeMPL().KeyGen(seedN(703)); + G1Element dh = a * b.GetG1Element(); + e.dump("G.dh", dh.Serialize(false)); + e.dumpb("G.dh.sym", dh == (b * a.GetG1Element())); +} + +// ------------------------------------------------------------------ section H +// Crafted byte strings through every decode path. For each: either the +// round-trip hex (proving accept + canonical re-encoding) or EXC. +inline void decodeProbe(Emitter& e, const std::string& name, const vector& in, bool fLegacy) +{ + bool isG1 = in.size() == 48; + try { + if (isG1) { + G1Element el = G1Element::FromBytes(Bytes(in), fLegacy); + e.dump(name + ".ser", el.Serialize(fLegacy)); + e.dumpb(name + ".valid", el.IsValid()); + } else { + G2Element el = G2Element::FromBytes(Bytes(in), fLegacy); + e.dump(name + ".ser", el.Serialize(fLegacy)); + e.dumpb(name + ".valid", el.IsValid()); + } + } catch (const std::exception&) { e.exc(name); } +} + +inline void decodeProbeUnchecked(Emitter& e, const std::string& name, const vector& in, bool fLegacy) +{ + bool isG1 = in.size() == 48; + try { + if (isG1) { + G1Element el = G1Element::FromBytesUnchecked(Bytes(in), fLegacy); + e.dump(name + ".ser", el.Serialize(fLegacy)); + e.dumpb(name + ".valid", el.IsValid()); + } else { + G2Element el = G2Element::FromBytesUnchecked(Bytes(in), fLegacy); + e.dump(name + ".ser", el.Serialize(fLegacy)); + e.dumpb(name + ".valid", el.IsValid()); + } + } catch (const std::exception&) { e.exc(name); } +} + +inline vector fromHex(const char* hex) +{ + vector out; + for (size_t i = 0; hex[i] && hex[i + 1]; i += 2) { + auto nyb = [](char c) -> int { + if (c >= '0' && c <= '9') return c - '0'; + if (c >= 'a' && c <= 'f') return c - 'a' + 10; + return c - 'A' + 10; + }; + out.push_back((uint8_t)((nyb(hex[i]) << 4) | nyb(hex[i + 1]))); + } + return out; +} + +inline void EdgeDecodes(Emitter& e) +{ + BasicSchemeMPL basic; + PrivateKey sk = basic.KeyGen(seedN(800)); + G1Element pk = sk.GetG1Element(); + G2Element sig = LegacySchemeMPL().Sign(sk, Bytes(hashN(800))); + + // 1. canonical infinity, both sizes, both modes + vector inf48(48, 0); + inf48[0] = 0xc0; + vector inf96(96, 0); + inf96[0] = 0xc0; + decodeProbe(e, "H.g1.inf.basic", inf48, false); + decodeProbe(e, "H.g1.inf.legacy", inf48, true); + decodeProbe(e, "H.g2.inf.basic", inf96, false); + decodeProbe(e, "H.g2.inf.legacy", inf96, true); + + // 2. non-canonical infinity (0xc0 with a trailing nonzero byte) + vector badInf48 = inf48; + badInf48[47] = 0x01; + vector badInf96 = inf96; + badInf96[95] = 0x01; + decodeProbe(e, "H.g1.badinf.basic", badInf48, false); + decodeProbe(e, "H.g1.badinf.legacy", badInf48, true); + decodeProbe(e, "H.g2.badinf.basic", badInf96, false); + decodeProbe(e, "H.g2.badinf.legacy", badInf96, true); + + // 3. all zeros + decodeProbe(e, "H.g1.zeros.basic", vector(48, 0), false); + decodeProbe(e, "H.g1.zeros.legacy", vector(48, 0), true); + decodeProbe(e, "H.g2.zeros.basic", vector(96, 0), false); + decodeProbe(e, "H.g2.zeros.legacy", vector(96, 0), true); + decodeProbeUnchecked(e, "H.g1.zeros.legacy.unchk", vector(48, 0), true); + decodeProbeUnchecked(e, "H.g2.zeros.legacy.unchk", vector(96, 0), true); + + // 4. x >= field prime (0xff filler), with/without legacy sign bit + vector ff48(48, 0xff); + vector ff96(96, 0xff); + decodeProbe(e, "H.g1.ff.basic", ff48, false); + decodeProbe(e, "H.g1.ff.legacy", ff48, true); + decodeProbe(e, "H.g2.ff.basic", ff96, false); + decodeProbe(e, "H.g2.ff.legacy", ff96, true); + vector ff48low = ff48; + ff48low[0] = 0x1f; // below prime top byte range but x still >= p + decodeProbe(e, "H.g1.fflow.legacy", ff48low, true); + + // 5. legacy bytes fed to the modern decoder and vice versa + decodeProbe(e, "H.g1.legacyAsBasic", pk.Serialize(true), false); + decodeProbe(e, "H.g1.basicAsLegacy", pk.Serialize(false), true); + decodeProbe(e, "H.g2.legacyAsBasic", sig.Serialize(true), false); + decodeProbe(e, "H.g2.basicAsLegacy", sig.Serialize(false), true); + + // 6. valid encodings with flipped sign bit (the negated point) + vector pkl = pk.Serialize(true); + pkl[0] ^= 0x80; + decodeProbe(e, "H.g1.negated.legacy", pkl, true); + vector pkb = pk.Serialize(false); + pkb[0] ^= 0x20; + decodeProbe(e, "H.g1.negated.basic", pkb, false); + + // 7. on-curve but non-subgroup points (found by scanning small x with a + // blst helper; each x satisfies y^2 = x^3 + 4 (+4i) with the point + // outside the r-torsion). Encodings below use y = the "smaller" root + // (sign bit 0), in each codec's byte layout. + // G1: x = 4 -> not in subgroup. + vector nsG1(48, 0); + nsG1[47] = 0x04; + decodeProbe(e, "H.g1.nonsub.legacy", nsG1, true); + decodeProbeUnchecked(e, "H.g1.nonsub.legacy.unchk", nsG1, true); + vector nsG1b = nsG1; + nsG1b[0] |= 0x80; // modern compression flag + decodeProbe(e, "H.g1.nonsub.basic", nsG1b, false); + decodeProbeUnchecked(e, "H.g1.nonsub.basic.unchk", nsG1b, false); + // G2: x = (1, 0) -> not in subgroup (legacy layout: c0 || c1). + vector nsG2(96, 0); + nsG2[47] = 0x01; + decodeProbe(e, "H.g2.nonsub.legacy", nsG2, true); + decodeProbeUnchecked(e, "H.g2.nonsub.legacy.unchk", nsG2, true); + // modern layout: c1 || c0 with flags on byte 0 + vector nsG2b(96, 0); + nsG2b[95] = 0x01; + nsG2b[0] |= 0x80; + decodeProbe(e, "H.g2.nonsub.basic", nsG2b, false); + decodeProbeUnchecked(e, "H.g2.nonsub.basic.unchk", nsG2b, false); + + // 8. x not on curve (no square root exists): x = 1 for G1 + vector noc(48, 0); + noc[47] = 0x01; + decodeProbe(e, "H.g1.nocurve.legacy", noc, true); + vector nocb = noc; + nocb[0] |= 0x80; + decodeProbe(e, "H.g1.nocurve.basic", nocb, false); + + // 9. modern G2 with the reserved top bits of byte 48 set + vector flag48 = sig.Serialize(false); + flag48[48] |= 0xe0; + decodeProbe(e, "H.g2.flag48.basic", flag48, false); + + // 10. wrong length + try { + G1Element::FromBytes(Bytes(vector(47, 0)), false); + e.raw("H.len47=NOEXC"); + } catch (const std::exception&) { e.exc("H.len47"); } + + // 11. legacy sign bit set on degenerate x values (exercises the + // sqrt-failure and x>=p fallback paths with stored sign = 1) + vector s1(48, 0); + s1[0] = 0x80; + s1[47] = 0x01; // x = 1, not on curve + decodeProbe(e, "H.g1.nocurve.sign.legacy", s1, true); + vector sp(48, 0xff); + sp[0] = 0x9f; // sign bit + x = 0x1fff... >= p + decodeProbe(e, "H.g1.overp.sign.legacy", sp, true); + vector g2s(96, 0); + g2s[0] = 0x80; + g2s[47] = 0x02; // x = (2, 0), sign bit set + decodeProbe(e, "H.g2.x2.sign.legacy", g2s, true); + vector g2s3(96, 0); + g2s3[0] = 0x80; + g2s3[47] = 0x03; // x = (3, 0), sign bit set + decodeProbe(e, "H.g2.x3.sign.legacy", g2s3, true); + vector g2nc(96, 0); + g2nc[47] = 0x02; // x = (2, 0), sign bit clear + decodeProbe(e, "H.g2.x2.legacy", g2nc, true); + vector g2sp(96, 0xff); + g2sp[0] = 0x9f; // c0 >= p (sign set), c1 >= p + decodeProbe(e, "H.g2.overp.sign.legacy", g2sp, true); +} + +// ------------------------------------------------------------------ section I +// Verification semantics with infinity elements and empty inputs. +inline void VerifyEdges(Emitter& e) +{ + BasicSchemeMPL basic; + LegacySchemeMPL legacy; + vector msg = {9, 9, 9}; + vector h = hashN(900); + + e.dumpb("I.basic.verify.infinf", basic.Verify(G1Element(), msg, G2Element())); + e.dumpb("I.legacy.verify.infinf", legacy.Verify(G1Element(), Bytes(h), G2Element())); + + PrivateKey sk = basic.KeyGen(seedN(900)); + G2Element sig = basic.Sign(sk, msg); + e.dumpb("I.basic.verify.infpk", basic.Verify(G1Element(), msg, sig)); + e.dumpb("I.basic.verify.infsig", basic.Verify(sk.GetG1Element(), msg, G2Element())); + + // AggregateVerify argument invariants + e.dumpb("I.aggver.empty.infsig", + basic.AggregateVerify(vector{}, vector{}, G2Element())); + e.dumpb("I.aggver.empty.realsig", + basic.AggregateVerify(vector{}, vector{}, sig)); + e.dumpb("I.aggver.mismatch", + basic.AggregateVerify(vector{sk.GetG1Element()}, vector{}, sig)); + + // VerifySecure with an infinity pubkey in the list + vector pks = {sk.GetG1Element(), G1Element()}; + e.dumpb("I.versec.withinf", basic.VerifySecure(pks, sig, Bytes(h))); +} + + +inline std::vector GenerateReferenceVectors() +{ + Emitter e; + e.raw("# dashbls reference vectors v1"); + KeysAndSignatures(e); + SecureAggregation(e); + ThresholdVectors(e); + ExtendedKeys(e); + PrivateKeyEdges(e); + EdgeDecodes(e); + VerifyEdges(e); + e.raw("# end"); + return e.lines; +} + +} // namespace bls_test_vectors + +#endif // SRC_TEST_VECTORS_HPP_ diff --git a/src/dashbls/src/test.cpp b/src/dashbls/src/test.cpp index 7e9d5280b3b5..367df5cc1707 100644 --- a/src/dashbls/src/test.cpp +++ b/src/dashbls/src/test.cpp @@ -19,18 +19,25 @@ #include "bls.hpp" #include -extern "C" { -#include "relic.h" -} #include "test-utils.hpp" -using std::cout; -using std::endl; +#include "test-vectors.hpp" + +#include +#include + using std::string; using std::vector; using namespace bls; -void TestHKDF(string ikm_hex, string salt_hex, string info_hex, string prk_expected_hex, string okm_expected_hex, int L) { +void TestHKDF( + string ikm_hex, + string salt_hex, + string info_hex, + string prk_expected_hex, + string okm_expected_hex, + int L) +{ vector ikm = Util::HexToBytes(ikm_hex); vector salt = Util::HexToBytes(salt_hex); vector info = Util::HexToBytes(info_hex); @@ -42,42 +49,45 @@ void TestHKDF(string ikm_hex, string salt_hex, string info_hex, string prk_expec HKDF256::Expand(okm, L, prk, info.data(), info.size()); REQUIRE(32 == prk_expected.size()); - REQUIRE(L == okm_expected.size()); + REQUIRE(L == (int)okm_expected.size()); - for (size_t i=0; i < 32; i++) { + for (size_t i = 0; i < 32; i++) { REQUIRE(prk[i] == prk_expected[i]); } - for (size_t i=0; i < L; i++) { + for (int i = 0; i < L; i++) { REQUIRE(okm[i] == okm_expected[i]); } delete[] okm; } -TEST_CASE("class PrivateKey") { +TEST_CASE("class PrivateKey") +{ uint8_t buffer[PrivateKey::PRIVATE_KEY_SIZE]; memcpy(buffer, getRandomSeed().data(), PrivateKey::PRIVATE_KEY_SIZE); - SECTION("Copy {constructor|assignment operator}") { - PrivateKey pk1 = PrivateKey::RandomPrivateKey(); - PrivateKey pk2 = PrivateKey::RandomPrivateKey(); + SECTION("Copy {constructor|assignment operator}") + { + PrivateKey pk1 = PrivateKey::FromByteVector(getRandomSeed(), true); + PrivateKey pk2 = PrivateKey::FromByteVector(getRandomSeed(), true); PrivateKey pk3 = PrivateKey(pk2); REQUIRE(!pk1.IsZero()); REQUIRE(!pk2.IsZero()); REQUIRE(!pk3.IsZero()); REQUIRE(pk1 != pk2); REQUIRE(pk3 == pk2); - REQUIRE(pk2.GetG1Element().IsValid()); // cache previous g1 - REQUIRE(pk2.GetG2Element().IsValid()); // cache previous g2 + REQUIRE(pk2.GetG1Element().IsValid()); // cache previous g1 + REQUIRE(pk2.GetG2Element().IsValid()); // cache previous g2 pk2 = pk1; REQUIRE(pk1 == pk2); REQUIRE(pk1.GetG1Element() == pk2.GetG1Element()); REQUIRE(pk1.GetG2Element() == pk2.GetG2Element()); REQUIRE(pk3 != pk2); } - SECTION("Move {constructor|assignment operator}") { - PrivateKey pk1 = PrivateKey::RandomPrivateKey(); + SECTION("Move {constructor|assignment operator}") + { + PrivateKey pk1 = PrivateKey::FromByteVector(getRandomSeed(), true); std::vector vec1 = pk1.Serialize(); - PrivateKey pk2 = PrivateKey::RandomPrivateKey(); + PrivateKey pk2 = PrivateKey::FromByteVector(getRandomSeed(), true); std::vector vec2 = pk2.Serialize(); PrivateKey pk3 = PrivateKey(std::move(pk2)); REQUIRE(!pk1.IsZero()); @@ -94,48 +104,71 @@ TEST_CASE("class PrivateKey") { REQUIRE_THROWS(pk2.IsZero()); REQUIRE_THROWS(pk3.IsZero()); } - SECTION("Equality operators") { - PrivateKey pk1 = PrivateKey::RandomPrivateKey(); - PrivateKey pk2 = PrivateKey::RandomPrivateKey(); + SECTION("Equality operators") + { + PrivateKey pk1 = PrivateKey::FromByteVector(getRandomSeed(), true); + PrivateKey pk2 = PrivateKey::FromByteVector(getRandomSeed(), true); PrivateKey pk3 = pk2; REQUIRE(pk1 != pk2); REQUIRE(pk1 != pk3); REQUIRE(pk2 == pk3); } - SECTION("(De)Serialization") { - PrivateKey pk1 = PrivateKey::RandomPrivateKey(); + SECTION("(De)Serialization") + { + PrivateKey pk1 = PrivateKey::FromByteVector(getRandomSeed(), true); pk1.Serialize(buffer); - REQUIRE(memcmp(buffer, pk1.Serialize().data(), PrivateKey::PRIVATE_KEY_SIZE) == 0); + REQUIRE( + memcmp( + buffer, pk1.Serialize().data(), PrivateKey::PRIVATE_KEY_SIZE) == + 0); PrivateKey pk2 = PrivateKey::FromBytes(Bytes(buffer, PrivateKey::PRIVATE_KEY_SIZE), true); REQUIRE(pk1 == pk2); - REQUIRE_THROWS(PrivateKey::FromBytes(Bytes(buffer, PrivateKey::PRIVATE_KEY_SIZE - 1), true)); - REQUIRE_THROWS(PrivateKey::FromBytes(Bytes(buffer, PrivateKey::PRIVATE_KEY_SIZE + 1), true)); - REQUIRE_NOTHROW(PrivateKey::FromBytes(Bytes(buffer, PrivateKey::PRIVATE_KEY_SIZE), true)); - bn_t order; - bn_new(order); - g1_get_ord(order); - bn_write_bin(buffer, PrivateKey::PRIVATE_KEY_SIZE, order); + REQUIRE_THROWS(PrivateKey::FromBytes( + Bytes(buffer, PrivateKey::PRIVATE_KEY_SIZE - 1), true)); + REQUIRE_THROWS(PrivateKey::FromBytes( + Bytes(buffer, PrivateKey::PRIVATE_KEY_SIZE + 1), true)); + REQUIRE_NOTHROW(PrivateKey::FromBytes( + Bytes(buffer, PrivateKey::PRIVATE_KEY_SIZE), true)); + // the group order r itself is accepted (bn_cmp > 0 semantics) + const vector order = Util::HexToBytes( + "73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001"); + memcpy(buffer, order.data(), PrivateKey::PRIVATE_KEY_SIZE); REQUIRE_NOTHROW(PrivateKey::FromBytes(Bytes(buffer, PrivateKey::PRIVATE_KEY_SIZE), false)); REQUIRE_NOTHROW(PrivateKey::FromBytes(Bytes(buffer, PrivateKey::PRIVATE_KEY_SIZE), true)); - bn_add(order, order, order); - bn_write_bin(buffer, PrivateKey::PRIVATE_KEY_SIZE, order); + // 2 * r is above the order and must be rejected without modOrder + const vector order2 = Util::HexToBytes( + "e7db4ea6533afa906673b0101343b00aa77b4805fffcb7fdfffffffe00000002"); + memcpy(buffer, order2.data(), PrivateKey::PRIVATE_KEY_SIZE); REQUIRE_THROWS(PrivateKey::FromBytes(Bytes(buffer, PrivateKey::PRIVATE_KEY_SIZE), false)); REQUIRE_NOTHROW(PrivateKey::FromBytes(Bytes(buffer, PrivateKey::PRIVATE_KEY_SIZE), true)); + // The hardcoded order must agree with blst's own, which is only + // reachable through blst_scalar_fr_check (true iff below r): r itself + // is not a valid Fr element, r - 1 is. + blst_scalar s; + blst_scalar_from_bendian(&s, order.data()); + REQUIRE(!blst_scalar_fr_check(&s)); + vector orderm1 = order; + orderm1[31] = 0x00; + blst_scalar_from_bendian(&s, orderm1.data()); + REQUIRE(blst_scalar_fr_check(&s)); } SECTION("BIP32 Seed") { uint8_t aliceSeed[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; PrivateKey pk1 = PrivateKey::FromSeedBIP32(Bytes(aliceSeed, 10)); REQUIRE(pk1.HasKeyData()); - vector privateKey = pk1.Serialize(true); + vector privateKey = pk1.Serialize(); vector knownPrivateKey = Util::HexToBytes("46891c2cec49593c81921e473db7480029e0fc1eb933c6b93d81f5370eb19fbd"); REQUIRE(privateKey == knownPrivateKey); G1Element pubKey1 = pk1.GetG1Element(); vector pubKey1Bytes = pubKey1.Serialize(true); + vector pubKey2Bytes = pubKey1.Serialize(false); vector knownPublicKey = Util::HexToBytes("1790635de8740e9a6a6b15fb6b72f3a16afa0973d971979b6ba54761d6e2502c50db76f4d26143f05459a42cfd520d44"); REQUIRE(pubKey1Bytes == knownPublicKey); + REQUIRE(pubKey2Bytes != pubKey1Bytes); } - SECTION("keydata checks") { - PrivateKey pk1 = PrivateKey::RandomPrivateKey(); + SECTION("keydata checks") + { + PrivateKey pk1 = PrivateKey::FromByteVector(getRandomSeed(), true); G1Element g1 = pk1.GetG1Element(); G2Element g2 = pk1.GetG2Element(); PrivateKey pk2 = std::move(pk1); @@ -154,69 +187,86 @@ TEST_CASE("class PrivateKey") { REQUIRE_THROWS(pk1 != pk2); REQUIRE_THROWS(pk1.Serialize(buffer)); REQUIRE_THROWS(pk1.Serialize()); - REQUIRE_THROWS(pk1.SignG2(buffer, sizeof(buffer), buffer, sizeof(buffer))); + REQUIRE_THROWS( + pk1.SignG2(buffer, sizeof(buffer), buffer, sizeof(buffer))); } } -TEST_CASE("HKDF") { +TEST_CASE("HKDF") +{ // https://tools.ietf.org/html/rfc5869 test vectors - SECTION("Test case 2") { - TestHKDF("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", - "000102030405060708090a0b0c", - "f0f1f2f3f4f5f6f7f8f9", - "077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5", - "3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865", - 42 - ); - } - SECTION("Test case 2") { - TestHKDF("000102030405060708090a0b0c0d0e0f" - "101112131415161718191a1b1c1d1e1f" - "202122232425262728292a2b2c2d2e2f" - "303132333435363738393a3b3c3d3e3f" - "404142434445464748494a4b4c4d4e4f", // 80 octets - "0x606162636465666768696a6b6c6d6e6f" - "707172737475767778797a7b7c7d7e7f" - "808182838485868788898a8b8c8d8e8f" - "909192939495969798999a9b9c9d9e9f" - "a0a1a2a3a4a5a6a7a8a9aaabacadaeaf", // 80 octets - "0xb0b1b2b3b4b5b6b7b8b9babbbcbdbebf" - "c0c1c2c3c4c5c6c7c8c9cacbcccdcecf" - "d0d1d2d3d4d5d6d7d8d9dadbdcdddedf" - "e0e1e2e3e4e5e6e7e8e9eaebecedeeef" - "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", // 80 octets - "0x06a6b88c5853361a06104c9ceb35b45cef760014904671014a193f40c15fc244", // 32 octets - "0xb11e398dc80327a1c8e7f78c596a4934" - "4f012eda2d4efad8a050cc4c19afa97c" - "59045a99cac7827271cb41c65e590e09" - "da3275600c2f09b8367793a9aca3db71" - "cc30c58179ec3e87c14c01d5c1f3434f" - "1d87", // 82 octets - 82 - ); - } - SECTION("Test case 3") { - TestHKDF("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", - "", - "", - "19ef24a32c717b167f33a91d6f648bdf96596776afdb6377ac434c1c293ccb04", - "8da4e775a563c18f715f802a063c5a31b8a11f5c5ee1879ec3454e5f3c738d2d9d201395faa4b61a96c8", - 42 - ); - } - SECTION("Works with multiple of 32") { - // This generates exactly 64 bytes. Uses a 32 byte key and 4 byte salt as in EIP2333. - TestHKDF("8704f9ac024139fe62511375cf9bc534c0507dcf00c41603ac935cd5943ce0b4b88599390de14e743ca2f56a73a04eae13aa3f3b969b39d8701e0d69a6f8d42f", - "53d8e19b", - "", - "eb01c9cd916653df76ffa61b6ab8a74e254ebfd9bfc43e624cc12a72b0373dee", - "8faabea85fc0c64e7ca86217cdc6dcdc88551c3244d56719e630a3521063082c46455c2fd5483811f9520a748f0099c1dfcfa52c54e1c22b5cdf70efb0f3c676", - 64 - ); + SECTION("Test case 2") + { + TestHKDF( + "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", + "000102030405060708090a0b0c", + "f0f1f2f3f4f5f6f7f8f9", + "077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5", + "3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34" + "007208d5b887185865", + 42); + } + SECTION("Test case 2") + { + TestHKDF( + "000102030405060708090a0b0c0d0e0f" + "101112131415161718191a1b1c1d1e1f" + "202122232425262728292a2b2c2d2e2f" + "303132333435363738393a3b3c3d3e3f" + "404142434445464748494a4b4c4d4e4f", // 80 octets + "0x606162636465666768696a6b6c6d6e6f" + "707172737475767778797a7b7c7d7e7f" + "808182838485868788898a8b8c8d8e8f" + "909192939495969798999a9b9c9d9e9f" + "a0a1a2a3a4a5a6a7a8a9aaabacadaeaf", // 80 octets + "0xb0b1b2b3b4b5b6b7b8b9babbbcbdbebf" + "c0c1c2c3c4c5c6c7c8c9cacbcccdcecf" + "d0d1d2d3d4d5d6d7d8d9dadbdcdddedf" + "e0e1e2e3e4e5e6e7e8e9eaebecedeeef" + "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", // 80 octets + "0x06a6b88c5853361a06104c9ceb35b45cef760014904671014a193f40c15fc24" + "4", // 32 octets + "0xb11e398dc80327a1c8e7f78c596a4934" + "4f012eda2d4efad8a050cc4c19afa97c" + "59045a99cac7827271cb41c65e590e09" + "da3275600c2f09b8367793a9aca3db71" + "cc30c58179ec3e87c14c01d5c1f3434f" + "1d87", // 82 octets + 82); + } + SECTION("Test case 3") + { + TestHKDF( + "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", + "", + "", + "19ef24a32c717b167f33a91d6f648bdf96596776afdb6377ac434c1c293ccb04", + "8da4e775a563c18f715f802a063c5a31b8a11f5c5ee1879ec3454e5f3c738d2d9d" + "201395faa4b61a96c8", + 42); + } + SECTION("Works with multiple of 32") + { + // This generates exactly 64 bytes. Uses a 32 byte key and 4 byte salt + // as in EIP2333. + TestHKDF( + "8704f9ac024139fe62511375cf9bc534c0507dcf00c41603ac935cd5943ce0b4b8" + "8599390de14e743ca2f56a73a04eae13aa3f3b969b39d8701e0d69a6f8d42f", + "53d8e19b", + "", + "eb01c9cd916653df76ffa61b6ab8a74e254ebfd9bfc43e624cc12a72b0373dee", + "8faabea85fc0c64e7ca86217cdc6dcdc88551c3244d56719e630a3521063082c46" + "455c2fd5483811f9520a748f0099c1dfcfa52c54e1c22b5cdf70efb0f3c676", + 64); } } -void TestEIP2333(string seedHex, string masterSkHex, string childSkHex, uint32_t childIndex) { +void TestEIP2333( + string seedHex, + string masterSkHex, + string childSkHex, + uint32_t childIndex) +{ auto masterSk = Util::HexToBytes(masterSkHex); auto childSk = Util::HexToBytes(childSkHex); @@ -230,60 +280,73 @@ void TestEIP2333(string seedHex, string masterSkHex, string childSkHex, uint32_t REQUIRE(calculatedMaster.size() == 32); REQUIRE(calculatedChild.size() == 32); - for (int i=0; i<32; i++) { + for (int i = 0; i < 32; i++) { REQUIRE(calculatedMaster[i] == masterSk[i]); } - for (int i=0; i<32; i++) { + for (int i = 0; i < 32; i++) { REQUIRE(calculatedChild[i] == childSk[i]); } } -TEST_CASE("EIP-2333 hardened HD keys") { - // The comments in the test cases correspond to integers that are converted to - // bytes using python int.to_bytes(32, "big").hex(), since the EIP spec provides ints, but c++ - // does not support bigint by default - SECTION("EIP-2333 Test case 1"){ - TestEIP2333("3141592653589793238462643383279502884197169399375105820974944592", - // 36167147331491996618072159372207345412841461318189449162487002442599770291484 - "4ff5e145590ed7b71e577bb04032396d1619ff41cb4e350053ed2dce8d1efd1c", - // 41787458189896526028601807066547832426569899195138584349427756863968330588237 - "5c62dcf9654481292aafa3348f1d1b0017bbfb44d6881d26d2b17836b38f204d", - 3141592653 - ); - } - SECTION("EIP-2333 Test case 2"){ - TestEIP2333("0x0099FF991111002299DD7744EE3355BBDD8844115566CC55663355668888CC00", - // 13904094584487173309420026178174172335998687531503061311232927109397516192843 - "1ebd704b86732c3f05f30563dee6189838e73998ebc9c209ccff422adee10c4b", - // 12482522899285304316694838079579801944734479969002030150864436005368716366140 - "1b98db8b24296038eae3f64c25d693a269ef1e4d7ae0f691c572a46cf3c0913c", - 4294967295 - ); - } - SECTION("EIP-2333 Test case 3"){ - TestEIP2333("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3", - // 44010626067374404458092393860968061149521094673473131545188652121635313364506 - "614d21b10c0e4996ac0608e0e7452d5720d95d20fe03c59a3321000a42432e1a", - // 4011524214304750350566588165922015929937602165683407445189263506512578573606 - "08de7136e4afc56ae3ec03b20517d9c1232705a747f588fd17832f36ae337526", - 42 - ); - } - SECTION("EIP-2333 Test vector with intermediate values"){ - TestEIP2333("c55257c360c07c72029aebc1b53c05ed0362ada38ead3e3e9efa3708e53495531f09a6987599d18264c1e1c92f2cf141630c7a3c4ab7c81b2f001698e7463b04", - // 5399117110774477986698372024995405256382522670366369834617409486544348441851 - "0x0befcabff4a664461cc8f190cdd51c05621eb2837c71a1362df5b465a674ecfb", - // 11812940737387919040225825939013910852517748782307378293770044673328955938106 - "1a1de3346883401f1e3b2281be5774080edb8e5ebe6f776b0f7af9fea942553a", - 0 - ); +TEST_CASE("EIP-2333 hardened HD keys") +{ + // The comments in the test cases correspond to integers that are converted + // to bytes using python int.to_bytes(32, "big").hex(), since the EIP spec + // provides ints, but c++ does not support bigint by default + SECTION("EIP-2333 Test case 1") + { + TestEIP2333( + "3141592653589793238462643383279502884197169399375105820974944592", + // 36167147331491996618072159372207345412841461318189449162487002442599770291484 + "4ff5e145590ed7b71e577bb04032396d1619ff41cb4e350053ed2dce8d1efd1c", + // 41787458189896526028601807066547832426569899195138584349427756863968330588237 + "5c62dcf9654481292aafa3348f1d1b0017bbfb44d6881d26d2b17836b38f204d", + 3141592653); + } + SECTION("EIP-2333 Test case 2") + { + TestEIP2333( + "0x0099FF991111002299DD7744EE3355BBDD8844115566CC55663355668888CC0" + "0", + // 13904094584487173309420026178174172335998687531503061311232927109397516192843 + "1ebd704b86732c3f05f30563dee6189838e73998ebc9c209ccff422adee10c4b", + // 12482522899285304316694838079579801944734479969002030150864436005368716366140 + "1b98db8b24296038eae3f64c25d693a269ef1e4d7ae0f691c572a46cf3c0913c", + 4294967295); + } + SECTION("EIP-2333 Test case 3") + { + TestEIP2333( + "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa" + "3", + // 44010626067374404458092393860968061149521094673473131545188652121635313364506 + "614d21b10c0e4996ac0608e0e7452d5720d95d20fe03c59a3321000a42432e1a", + // 4011524214304750350566588165922015929937602165683407445189263506512578573606 + "08de7136e4afc56ae3ec03b20517d9c1232705a747f588fd17832f36ae337526", + 42); + } + SECTION("EIP-2333 Test vector with intermediate values") + { + TestEIP2333( + "c55257c360c07c72029aebc1b53c05ed0362ada38ead3e3e9efa3708e53495531f" + "09a6987599d18264c1e1c92f2cf141630c7a3c4ab7c81b2f001698e7463b04", + // 5399117110774477986698372024995405256382522670366369834617409486544348441851 + "0x0befcabff4a664461cc8f190cdd51c05621eb2837c71a1362df5b465a674ecf" + "b", + // 11812940737387919040225825939013910852517748782307378293770044673328955938106 + "1a1de3346883401f1e3b2281be5774080edb8e5ebe6f776b0f7af9fea942553a", + 0); } } -TEST_CASE("Unhardened HD keys") { - SECTION("Should match derivation through private and public keys"){ - const vector seed = {1, 50, 6, 244, 24, 199, 1, 25, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29}; +TEST_CASE("Unhardened HD keys") +{ + SECTION("Should match derivation through private and public keys") + { + const vector seed = {1, 50, 6, 244, 24, 199, 1, 25, 1, 2, + 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, + 23, 24, 25, 26, 27, 28, 29}; PrivateKey sk = BasicSchemeMPL().KeyGen(seed); G1Element pk = sk.GetG1Element(); @@ -293,15 +356,20 @@ TEST_CASE("Unhardened HD keys") { REQUIRE(childSk.GetG1Element() == childPk); - PrivateKey grandchildSk = BasicSchemeMPL().DeriveChildSkUnhardened(childSk, 12142); - G1Element grandcihldPk = BasicSchemeMPL().DeriveChildPkUnhardened(childPk, 12142); + PrivateKey grandchildSk = + BasicSchemeMPL().DeriveChildSkUnhardened(childSk, 12142); + G1Element grandchildPk = + BasicSchemeMPL().DeriveChildPkUnhardened(childPk, 12142); - REQUIRE(grandchildSk.GetG1Element() == grandcihldPk); + REQUIRE(grandchildSk.GetG1Element() == grandchildPk); } - SECTION("Should derive public child from parent") { - const vector seed = {2, 50, 6, 244, 24, 199, 1, 25, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29}; + SECTION("Should derive public child from parent") + { + const vector seed = {2, 50, 6, 244, 24, 199, 1, 25, 1, 2, + 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, + 23, 24, 25, 26, 27, 28, 29}; PrivateKey sk = BasicSchemeMPL().KeyGen(seed); G1Element pk = sk.GetG1Element(); @@ -316,10 +384,17 @@ TEST_CASE("Unhardened HD keys") { } } -TEST_CASE("IETF test vectors") { - SECTION ("Pyecc vector") { - string sig1BasicHex = "96ba34fac33c7f129d602a0bc8a3d43f9abc014eceaab7359146b4b150e57b808645738f35671e9e10e0d862a30cab70074eb5831d13e6a5b162d01eebe687d0164adbd0a864370a7c222a2768d7704da254f1bf1823665bc2361f9dd8c00e99"; - string sk = "0x0101010101010101010101010101010101010101010101010101010101010101"; +TEST_CASE("IETF test vectors") +{ + SECTION("Pyecc vector") + { + string sig1BasicHex = + "96ba34fac33c7f129d602a0bc8a3d43f9abc014eceaab7359146b4b150e57b8086" + "45738f35671e9e10e0d862a30cab70074eb5831d13e6a5b162d01eebe687d0164a" + "dbd0a864370a7c222a2768d7704da254f1bf1823665bc2361f9dd8c00e99"; + string sk = + "0x010101010101010101010101010101010101010101010101010101010101010" + "1"; vector msg = {3, 1, 4, 1, 5, 9}; auto skobj = PrivateKey::FromBytes(Bytes(Util::HexToBytes(sk))); G2Element sig = BasicSchemeMPL().Sign(skobj, msg); @@ -331,9 +406,10 @@ TEST_CASE("IETF test vectors") { } } - -TEST_CASE("Chia test vectors") { - SECTION("Chia test vectors 1 (Basic)") { +TEST_CASE("Chia test vectors") +{ + SECTION("Chia test vectors 1 (Basic)") + { vector seed1(32, 0x00); // All 0s vector seed2(32, 0x01); // All 1s vector message1 = {7, 8, 9}; @@ -343,7 +419,6 @@ TEST_CASE("Chia test vectors") { G1Element pk1 = sk1.GetG1Element(); G2Element sig1 = BasicSchemeMPL().Sign(sk1, message1); - PrivateKey sk2 = BasicSchemeMPL().KeyGen(seed2); G1Element pk2 = sk2.GetG1Element(); G2Element sig2 = BasicSchemeMPL().Sign(sk2, message2); @@ -366,20 +441,26 @@ TEST_CASE("Chia test vectors") { REQUIRE( Util::HexStr(sig2.Serialize()) == - "a9c4d3e689b82c7ec7e838dac2380cb014f9a08f6cd6ba044c263746e39a8f7a60ffee4afb7" - "8f146c2e421360784d58f0029491e3bd8ab84f0011d258471ba4e87059de295d9aba845c044e" + "a9c4d3e689b82c7ec7e838dac2380cb014f9a08f6cd6ba044c263746e39a8f7a60" + "ffee4afb7" + "8f146c2e421360784d58f0029491e3bd8ab84f0011d258471ba4e87059de295d9a" + "ba845c044e" "e83f6cf2411efd379ef38bf4cf41d5f3c0ae1205d"); G2Element aggSig1 = BasicSchemeMPL().Aggregate({sig1, sig2}); REQUIRE( Util::HexStr(aggSig1.Serialize()) == - "aee003c8cdaf3531b6b0ca354031b0819f7586b5846796615aee8108fec75ef838d181f9d24" - "4a94d195d7b0231d4afcf06f27f0cc4d3c72162545c240de7d5034a7ef3a2a03c0159de982fb" + "aee003c8cdaf3531b6b0ca354031b0819f7586b5846796615aee8108fec75ef838" + "d181f9d24" + "4a94d195d7b0231d4afcf06f27f0cc4d3c72162545c240de7d5034a7ef3a2a03c0" + "159de982fb" "c2e7790aeb455e27beae91d64e077c70b5506dea3"); - REQUIRE(BasicSchemeMPL().AggregateVerify({pk1, pk2}, vector>{message1, message2}, aggSig1)); - REQUIRE(!BasicSchemeMPL().AggregateVerify({pk1, pk2}, vector>{message1, message2}, sig1)); + REQUIRE(BasicSchemeMPL().AggregateVerify( + {pk1, pk2}, vector>{message1, message2}, aggSig1)); + REQUIRE(!BasicSchemeMPL().AggregateVerify( + {pk1, pk2}, vector>{message1, message2}, sig1)); REQUIRE(!BasicSchemeMPL().Verify(pk1, message1, sig2)); REQUIRE(!BasicSchemeMPL().Verify(pk1, message2, sig1)); @@ -393,15 +474,21 @@ TEST_CASE("Chia test vectors") { G2Element aggSig2 = BasicSchemeMPL().Aggregate({sig3, sig4, sig5}); - REQUIRE(BasicSchemeMPL().AggregateVerify({pk1, pk1, pk2}, vector>{message3, message4, message5}, aggSig2)); + REQUIRE(BasicSchemeMPL().AggregateVerify( + {pk1, pk1, pk2}, + vector>{message3, message4, message5}, + aggSig2)); REQUIRE( Util::HexStr(aggSig2.Serialize()) == - "a0b1378d518bea4d1100adbc7bdbc4ff64f2c219ed6395cd36fe5d2aa44a4b8e710b607afd9" - "65e505a5ac3283291b75413d09478ab4b5cfbafbeea366de2d0c0bcf61deddaa521f6020460f" + "a0b1378d518bea4d1100adbc7bdbc4ff64f2c219ed6395cd36fe5d2aa44a4b8e71" + "0b607afd9" + "65e505a5ac3283291b75413d09478ab4b5cfbafbeea366de2d0c0bcf61deddaa52" + "1f6020460f" "d547ab37659ae207968b545727beba0a3c5572b9c"); } - SECTION("Chia test vector 2 (Augmented, aggregate of aggregates)") { + SECTION("Chia test vector 2 (Augmented, aggregate of aggregates)") + { vector message1 = {1, 2, 3, 40}; vector message2 = {5, 6, 70, 201}; vector message3 = {9, 10, 11, 12, 13}; @@ -423,20 +510,26 @@ TEST_CASE("Chia test vectors") { G2Element sig5 = AugSchemeMPL().Sign(sk1, message1); G2Element sig6 = AugSchemeMPL().Sign(sk1, message4); - G2Element aggSigL = AugSchemeMPL().Aggregate({sig1, sig2}); G2Element aggSigR = AugSchemeMPL().Aggregate({sig3, sig4, sig5}); G2Element aggSig = AugSchemeMPL().Aggregate({aggSigL, aggSigR, sig6}); - REQUIRE(AugSchemeMPL().AggregateVerify({pk1, pk2, pk2, pk1, pk1, pk1}, vector>{message1, message2, message1, message3, message1, message4}, aggSig)); + REQUIRE(AugSchemeMPL().AggregateVerify( + {pk1, pk2, pk2, pk1, pk1, pk1}, + vector>{ + message1, message2, message1, message3, message1, message4}, + aggSig)); REQUIRE( Util::HexStr(aggSig.Serialize()) == - "a1d5360dcb418d33b29b90b912b4accde535cf0e52caf467a005dc632d9f7af44b6c4e9acd4" - "6eac218b28cdb07a3e3bc087df1cd1e3213aa4e11322a3ff3847bbba0b2fd19ddc25ca964871" + "a1d5360dcb418d33b29b90b912b4accde535cf0e52caf467a005dc632d9f7af44b" + "6c4e9acd4" + "6eac218b28cdb07a3e3bc087df1cd1e3213aa4e11322a3ff3847bbba0b2fd19ddc" + "25ca964871" "997b9bceeab37a4c2565876da19382ea32a962200"); } - SECTION("Chia test vector 3 (PoP)") { + SECTION("Chia test vector 3 (PoP)") + { vector message1 = {1, 2, 3, 40, 50}; vector seed1(32, 0x04); // All 4s @@ -446,13 +539,16 @@ TEST_CASE("Chia test vectors") { G2Element pop = PopSchemeMPL().PopProve(sk1); REQUIRE(PopSchemeMPL().PopVerify(sk1.GetG1Element(), pop)); - REQUIRE(Util::HexStr(pop.Serialize()) == "84f709159435f0dc73b3e8bf6c78d85282d19231555a8ee3b6e2573aaf66872d9203fefa1ef" - "700e34e7c3f3fb28210100558c6871c53f1ef6055b9f06b0d1abe22ad584ad3b957f3018a8f5" - "8227c6c716b1e15791459850f2289168fa0cf9115"); + REQUIRE( + Util::HexStr(pop.Serialize()) == + "84f709159435f0dc73b3e8bf6c78d85282d19231555a8ee3b6e2573aaf66872d92" + "03fefa1ef" + "700e34e7c3f3fb28210100558c6871c53f1ef6055b9f06b0d1abe22ad584ad3b95" + "7f3018a8f5" + "8227c6c716b1e15791459850f2289168fa0cf9115"); } } - TEST_CASE("Key generation") { SECTION("Should generate a keypair from a seed") @@ -463,12 +559,10 @@ TEST_CASE("Key generation") REQUIRE_THROWS(BasicSchemeMPL().KeyGen(seed1)); PrivateKey sk = BasicSchemeMPL().KeyGen(seed2); G1Element pk = sk.GetG1Element(); - REQUIRE(core_get()->code == RLC_OK); REQUIRE(pk.GetFingerprint() == 0x8ee7ba56); } } - TEST_CASE("Error handling") { SECTION("Should throw on a bad private key") @@ -478,7 +572,8 @@ TEST_CASE("Error handling") uint8_t* skData = Util::SecAlloc(G2Element::SIZE); sk1.Serialize(skData); skData[0] = 255; - REQUIRE_THROWS(PrivateKey::FromBytes(Bytes(skData, PrivateKey::PRIVATE_KEY_SIZE))); + REQUIRE_THROWS( + PrivateKey::FromBytes(Bytes(skData, PrivateKey::PRIVATE_KEY_SIZE))); Util::SecFree(skData); } @@ -487,7 +582,8 @@ TEST_CASE("Error handling") vector buf(G1Element::SIZE, 0); for (int i = 0; i < 0xFF; i++) { buf[0] = (uint8_t)i; - if (i == 0xc0) { // Infinity prefix shouldn't throw here as we have only zero values + if (i == 0xc0) { // Infinity prefix shouldn't throw here as we have + // only zero values REQUIRE_NOTHROW(G1Element::FromByteVector(buf)); } else { REQUIRE_THROWS(G1Element::FromByteVector(buf)); @@ -500,47 +596,20 @@ TEST_CASE("Error handling") vector buf(G2Element::SIZE, 0); for (int i = 0; i < 0xFF; i++) { buf[0] = (uint8_t)i; - if (i == 0xc0) { // Infinity prefix shouldn't throw here as we have only zero values + if (i == 0xc0) { // Infinity prefix shouldn't throw here as we have + // only zero values REQUIRE_NOTHROW(G2Element::FromByteVector(buf)); } else { REQUIRE_THROWS(G2Element::FromByteVector(buf)); } } - // Trigger "G2 element must always have 48th byte start with 0b000" error case + // Trigger "G2 element must always have 48th byte start with 0b000" + // error case buf[48] = 0xFF; REQUIRE_THROWS(G2Element::FromByteVector(buf)); } - - SECTION("Error handling should be thread safe") - { - core_get()->code = 10; - REQUIRE(core_get()->code == 10); - - ctx_t* ctx1 = core_get(); - - // spawn a thread and make sure it uses a different/same context depending on relic's multithreading setup - std::thread([&]() { -#if MULTI != RELIC_NONE - REQUIRE(ctx1 != core_get()); - REQUIRE(core_get()->code == RLC_OK); -#else - REQUIRE(ctx1 == core_get()); - REQUIRE(core_get()->code != RLC_OK); -#endif - core_get()->code = 1; - }).join(); - -#if MULTI != RELIC_NONE - REQUIRE(core_get()->code == 10); -#else - REQUIRE(core_get()->code == 1); -#endif - // reset so that future test cases don't fail - core_get()->code = RLC_OK; - } } - TEST_CASE("Util tests") { SECTION("Should convert an int to four bytes") @@ -558,7 +627,6 @@ TEST_CASE("Util tests") } } - TEST_CASE("Signature tests") { SECTION("Should use copy constructor") @@ -572,7 +640,8 @@ TEST_CASE("Signature tests") uint8_t skBytes[PrivateKey::PRIVATE_KEY_SIZE]; sk2.Serialize(skBytes); - PrivateKey sk4 = PrivateKey::FromBytes(Bytes(skBytes, PrivateKey::PRIVATE_KEY_SIZE)); + PrivateKey sk4 = + PrivateKey::FromBytes(Bytes(skBytes, PrivateKey::PRIVATE_KEY_SIZE)); G1Element pk2 = G1Element(pk1); G2Element sig1 = BasicSchemeMPL().Sign(sk4, message1); @@ -581,7 +650,8 @@ TEST_CASE("Signature tests") REQUIRE(BasicSchemeMPL().Verify(pk2, message1, sig2)); } - SECTION("Should sign with the zero key") { + SECTION("Should sign with the zero key") + { vector sk0(32, 0); PrivateKey sk = PrivateKey::FromByteVector(sk0); REQUIRE(sk.GetG1Element() == G1Element()); // Infinity @@ -632,7 +702,8 @@ TEST_CASE("Signature tests") uint8_t* skData = Util::SecAlloc(G2Element::SIZE); sk1.Serialize(skData); - PrivateKey sk2 = PrivateKey::FromBytes(Bytes(skData, PrivateKey::PRIVATE_KEY_SIZE)); + PrivateKey sk2 = + PrivateKey::FromBytes(Bytes(skData, PrivateKey::PRIVATE_KEY_SIZE)); REQUIRE(sk1 == sk2); auto pkData = pk1.Serialize(); @@ -654,7 +725,6 @@ TEST_CASE("Signature tests") SECTION("Should not verify aggregate with same message under BasicScheme") { vector message = {100, 2, 254, 88, 90, 45, 23}; - uint8_t hash[BLS::MESSAGE_HASH_LEN]; vector seed(32, 0x50); vector seed2(32, 0x70); @@ -669,13 +739,17 @@ TEST_CASE("Signature tests") G2Element sig2 = BasicSchemeMPL().Sign(sk2, message); G2Element aggSig = BasicSchemeMPL().Aggregate({sig1, sig2}); - REQUIRE(BasicSchemeMPL().AggregateVerify({pk1, pk2}, vector>{message, message}, aggSig) == false); + REQUIRE( + BasicSchemeMPL().AggregateVerify( + {pk1, pk2}, + vector>{message, message}, + aggSig) == false); } - SECTION("Should verify aggregate with same message under AugScheme/PopScheme") + SECTION( + "Should verify aggregate with same message under AugScheme/PopScheme") { vector message = {100, 2, 254, 88, 90, 45, 23}; - uint8_t hash[BLS::MESSAGE_HASH_LEN]; vector seed(32, 0x50); vector seed2(32, 0x70); @@ -689,19 +763,21 @@ TEST_CASE("Signature tests") G2Element sig1Aug = AugSchemeMPL().Sign(sk1, message); G2Element sig2Aug = AugSchemeMPL().Sign(sk2, message); G2Element aggSigAug = AugSchemeMPL().Aggregate({sig1Aug, sig2Aug}); - REQUIRE(AugSchemeMPL().AggregateVerify({pk1, pk2}, vector>{message, message}, aggSigAug)); + REQUIRE(AugSchemeMPL().AggregateVerify( + {pk1, pk2}, vector>{message, message}, aggSigAug)); G2Element sig1Pop = PopSchemeMPL().Sign(sk1, message); G2Element sig2Pop = PopSchemeMPL().Sign(sk2, message); G2Element aggSigPop = PopSchemeMPL().Aggregate({sig1Pop, sig2Pop}); - REQUIRE(PopSchemeMPL().AggregateVerify({pk1, pk2}, vector>{message, message}, aggSigPop)); + REQUIRE(PopSchemeMPL().AggregateVerify( + {pk1, pk2}, vector>{message, message}, aggSigPop)); } SECTION("Should Aug aggregate many G2Elements, diff message") { vector pks; vector sigs; - vector > ms; + vector> ms; for (uint8_t i = 0; i < 80; i++) { vector message = {0, 100, 2, 45, 64, 12, 12, 63, i}; @@ -720,8 +796,8 @@ TEST_CASE("Signature tests") SECTION("Aggregate Verification of zero items with infinity should pass") { vector pks_as_g1; - vector > pks_as_bytes; - vector > msgs; + vector> pks_as_bytes; + vector> msgs; vector sigs; sigs.push_back(G2Element()); @@ -731,22 +807,43 @@ TEST_CASE("Signature tests") REQUIRE(aggSig == G2Element()); REQUIRE(AugSchemeMPL().AggregateVerify(pks_as_g1, msgs, aggSig)); - REQUIRE(AugSchemeMPL().AggregateVerify(pks_as_bytes, msgs, aggSig.Serialize())); + REQUIRE(AugSchemeMPL().AggregateVerify( + pks_as_bytes, msgs, aggSig.Serialize())); REQUIRE(BasicSchemeMPL().AggregateVerify(pks_as_g1, msgs, aggSig)); - REQUIRE(BasicSchemeMPL().AggregateVerify(pks_as_bytes, msgs, aggSig.Serialize())); + REQUIRE(BasicSchemeMPL().AggregateVerify( + pks_as_bytes, msgs, aggSig.Serialize())); - // FastAggregateVerify takes one message, and requires at least one key + // FastAggregateVerify takes one message, and requires at least one key vector msg; REQUIRE(pks_as_g1.size() == 0); - REQUIRE(PopSchemeMPL().FastAggregateVerify(pks_as_g1, msg, aggSig) == false); + REQUIRE( + PopSchemeMPL().FastAggregateVerify(pks_as_g1, msg, aggSig) == + false); REQUIRE(pks_as_bytes.size() == 0); - REQUIRE(PopSchemeMPL().FastAggregateVerify(pks_as_bytes, msg, aggSig.Serialize()) == false); + REQUIRE( + PopSchemeMPL().FastAggregateVerify( + pks_as_bytes, msg, aggSig.Serialize()) == false); + } + SECTION("Aggregate same sig element") + { + vector message = {100, 2, 254, 88, 90, 45, 23}; + + vector seed(32, 0x50); + + PrivateKey sk1 = BasicSchemeMPL().KeyGen(seed); + + G1Element pk1 = sk1.GetG1Element(); + G2Element sig1Aug = AugSchemeMPL().Sign(sk1, message); + G2Element aggSigAug = AugSchemeMPL().Aggregate({sig1Aug, sig1Aug}); + REQUIRE(AugSchemeMPL().AggregateVerify( + {pk1, pk1}, vector>{message, message}, aggSigAug)); } } -TEST_CASE("Agg sks") { +TEST_CASE("Agg sks") +{ SECTION("Should create aggregates with agg sk (basic scheme)") { const vector message = {100, 2, 254, 88, 90, 45, 23}; @@ -771,7 +868,6 @@ TEST_CASE("Agg sks") { const G2Element aggSig2 = BasicSchemeMPL().Sign(aggSk, message); - const G2Element aggSig = BasicSchemeMPL().Aggregate({sig1, sig2}); REQUIRE(aggSig == aggSig2); @@ -780,8 +876,16 @@ TEST_CASE("Agg sks") { REQUIRE(BasicSchemeMPL().Verify(aggPubKey, message, aggSig2)); // Verify aggregate with both keys (Fails since not distinct) - REQUIRE(BasicSchemeMPL().AggregateVerify({pk1, pk2}, vector>{message, message}, aggSig) == false); - REQUIRE(BasicSchemeMPL().AggregateVerify({pk1, pk2}, vector>{message, message}, aggSig2) == false); + REQUIRE( + BasicSchemeMPL().AggregateVerify( + {pk1, pk2}, + vector>{message, message}, + aggSig) == false); + REQUIRE( + BasicSchemeMPL().AggregateVerify( + {pk1, pk2}, + vector>{message, message}, + aggSig2) == false); // Try the same with distinct message, and same sk vector message2 = {200, 29, 54, 8, 9, 29, 155, 55}; @@ -803,12 +907,17 @@ TEST_CASE("Agg sks") { REQUIRE(pkFinal != aggPubKey); // Cannot verify with aggPubKey (since we have multiple messages) - REQUIRE(BasicSchemeMPL().AggregateVerify({aggPubKey, pk2}, vector>{message, message2}, aggSigFinal)); + REQUIRE(BasicSchemeMPL().AggregateVerify( + {aggPubKey, pk2}, + vector>{message, message2}, + aggSigFinal)); } } -TEST_CASE("Advanced") { - SECTION("Should aggregate with multiple levels, degenerate") { +TEST_CASE("Advanced") +{ + SECTION("Should aggregate with multiple levels, degenerate") + { vector message1 = {100, 2, 254, 88, 90, 45, 23}; PrivateKey sk1 = AugSchemeMPL().KeyGen(getRandomSeed()); G1Element pk1 = sk1.GetG1Element(); @@ -827,7 +936,8 @@ TEST_CASE("Advanced") { REQUIRE(AugSchemeMPL().AggregateVerify(pks, ms, aggSig)); } - SECTION("Should aggregate with multiple levels, different messages") { + SECTION("Should aggregate with multiple levels, different messages") + { vector message1 = {100, 2, 254, 88, 90, 45, 23}; vector message2 = {192, 29, 2, 0, 0, 45, 23}; vector message3 = {52, 29, 2, 0, 0, 45, 102}; @@ -865,25 +975,24 @@ TEST_CASE("Advanced") { SECTION("README") { // 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}; + // 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 + vector message = { + 1, 2, 3, 4, 5}; // Message is passed in as a byte vector G2Element signature = AugSchemeMPL().Sign(sk, message); vector skBytes = sk.Serialize(); vector pkBytes = pk.Serialize(); vector signatureBytes = signature.Serialize(); - cout << Util::HexStr(skBytes) << endl; // 32 bytes - cout << Util::HexStr(pkBytes) << endl; // 48 bytes - cout << Util::HexStr(signatureBytes) << endl; // 96 bytes - // Takes array of 32 bytes PrivateKey skc = PrivateKey::FromByteVector(skBytes); @@ -913,7 +1022,8 @@ TEST_CASE("Advanced") { // Signatures can be noninteractively combined by anyone G2Element aggSig = AugSchemeMPL().Aggregate({sig1, sig2}); - REQUIRE(AugSchemeMPL().AggregateVerify({pk1, pk2}, vector>{message, message2}, aggSig)); + REQUIRE(AugSchemeMPL().AggregateVerify( + {pk1, pk2}, vector>{message, message2}, aggSig)); seed[0] = 3; PrivateKey sk3 = AugSchemeMPL().KeyGen(seed); @@ -921,14 +1031,17 @@ TEST_CASE("Advanced") { vector message3 = {100, 2, 254, 88, 90, 45, 23}; G2Element sig3 = AugSchemeMPL().Sign(sk3, message3); - // Arbitrary trees of aggregates G2Element aggSigFinal = AugSchemeMPL().Aggregate({aggSig, sig3}); - REQUIRE(AugSchemeMPL().AggregateVerify({pk1, pk2, pk3}, vector>{message, message2, message3}, aggSigFinal)); + REQUIRE(AugSchemeMPL().AggregateVerify( + {pk1, pk2, pk3}, + vector>{message, message2, message3}, + aggSigFinal)); - // 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. + // 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); @@ -940,9 +1053,11 @@ TEST_CASE("Advanced") { REQUIRE(PopSchemeMPL().PopVerify(pk1, pop1)); REQUIRE(PopSchemeMPL().PopVerify(pk2, pop2)); REQUIRE(PopSchemeMPL().PopVerify(pk3, pop3)); - G2Element popSigAgg = PopSchemeMPL().Aggregate({popSig1, popSig2, popSig3}); + G2Element popSigAgg = + PopSchemeMPL().Aggregate({popSig1, popSig2, popSig3}); - REQUIRE(PopSchemeMPL().FastAggregateVerify({pk1, pk2, pk3}, message, popSigAgg)); + REQUIRE(PopSchemeMPL().FastAggregateVerify( + {pk1, pk2, pk3}, message, popSigAgg)); // Aggregate public key, indistinguishable from a single public key G1Element popAggPk = pk1 + pk2 + pk3; @@ -952,17 +1067,20 @@ TEST_CASE("Advanced") { PrivateKey aggSk = PrivateKey::Aggregate({sk1, sk2, sk3}); REQUIRE(PopSchemeMPL().Sign(aggSk, message) == popSigAgg); - PrivateKey masterSk = AugSchemeMPL().KeyGen(seed); PrivateKey child = AugSchemeMPL().DeriveChildSk(masterSk, 152); PrivateKey grandchild = AugSchemeMPL().DeriveChildSk(child, 952); G1Element masterPk = masterSk.GetG1Element(); - PrivateKey childU = AugSchemeMPL().DeriveChildSkUnhardened(masterSk, 22); - PrivateKey grandchildU = AugSchemeMPL().DeriveChildSkUnhardened(childU, 0); + PrivateKey childU = + AugSchemeMPL().DeriveChildSkUnhardened(masterSk, 22); + PrivateKey grandchildU = + AugSchemeMPL().DeriveChildSkUnhardened(childU, 0); - G1Element childUPk = AugSchemeMPL().DeriveChildPkUnhardened(masterPk, 22); - G1Element grandchildUPk = AugSchemeMPL().DeriveChildPkUnhardened(childUPk, 0); + G1Element childUPk = + AugSchemeMPL().DeriveChildPkUnhardened(masterPk, 22); + G1Element grandchildUPk = + AugSchemeMPL().DeriveChildPkUnhardened(childUPk, 0); REQUIRE(grandchildUPk == grandchildU.GetG1Element()); } @@ -984,12 +1102,16 @@ TEST_CASE("Advanced") { G2Element g2Bytes = G2Element::FromBytes(Bytes(vecG2Element)); REQUIRE(g2Vector == g2Bytes); - G1Element g1MessageVector = G1Element::FromMessage(vecHash, vecHash.data(), vecHash.size()); - G1Element g1MessageBytes = G1Element::FromMessage(Bytes(vecHash), vecHash.data(), vecHash.size()); + G1Element g1MessageVector = + G1Element::FromMessage(vecHash, vecHash.data(), vecHash.size()); + G1Element g1MessageBytes = G1Element::FromMessage( + Bytes(vecHash), vecHash.data(), vecHash.size()); REQUIRE(g1MessageVector == g1MessageBytes); - G2Element g2MessageVector = G2Element::FromMessage(vecHash, vecHash.data(), vecHash.size()); - G2Element g2MessageBytes = G2Element::FromMessage(Bytes(vecHash), vecHash.data(), vecHash.size()); + G2Element g2MessageVector = + G2Element::FromMessage(vecHash, vecHash.data(), vecHash.size()); + G2Element g2MessageBytes = G2Element::FromMessage( + Bytes(vecHash), vecHash.data(), vecHash.size()); REQUIRE(g2MessageVector == g2MessageBytes); G1Element g1_1 = pk1.GetG1Element(); @@ -997,29 +1119,41 @@ TEST_CASE("Advanced") { G1Element g1_3 = pk3.GetG1Element(); G2Element g2BasicSignVector1 = BasicSchemeMPL().Sign(pk1, vecHash); - G2Element g2BasicSignBytes1 = BasicSchemeMPL().Sign(pk1, Bytes(vecHash)); + G2Element g2BasicSignBytes1 = + BasicSchemeMPL().Sign(pk1, Bytes(vecHash)); REQUIRE(g2BasicSignVector1 == g2BasicSignBytes1); G2Element g2BasicSign2 = BasicSchemeMPL().Sign(pk2, Bytes(vecHash)); - G2Element g2BasicSign3 = BasicSchemeMPL().Sign(pk3, Bytes(vecG2Element)); + G2Element g2BasicSign3 = + BasicSchemeMPL().Sign(pk3, Bytes(vecG2Element)); REQUIRE(g2BasicSignVector1 != g2BasicSign2); - REQUIRE(BasicSchemeMPL().Verify(Bytes(g1_1.Serialize()), Bytes(vecHash), Bytes(g2BasicSignVector1.Serialize()))); - REQUIRE(BasicSchemeMPL().Verify(g1_1, Bytes(vecHash), g2BasicSignVector1)); + REQUIRE(BasicSchemeMPL().Verify( + Bytes(g1_1.Serialize()), + Bytes(vecHash), + Bytes(g2BasicSignVector1.Serialize()))); + REQUIRE( + BasicSchemeMPL().Verify(g1_1, Bytes(vecHash), g2BasicSignVector1)); - vector> vecG1Vector = {g1_1.Serialize(), g1_3.Serialize()}; - vector> vecG2Vector = {g2BasicSignVector1.Serialize(), g2BasicSign3.Serialize()}; + vector> vecG1Vector = { + g1_1.Serialize(), g1_3.Serialize()}; + vector> vecG2Vector = { + g2BasicSignVector1.Serialize(), g2BasicSign3.Serialize()}; vector> vecHashes = {vecHash, vecG2Element}; auto aggVector = BasicSchemeMPL().Aggregate(vecG2Vector); - auto aggBytes = BasicSchemeMPL().Aggregate(vector{vecG2Vector.begin(), vecG2Vector.end()}); + auto aggBytes = BasicSchemeMPL().Aggregate( + vector{vecG2Vector.begin(), vecG2Vector.end()}); REQUIRE(aggVector == aggBytes); - REQUIRE(BasicSchemeMPL().AggregateVerify(vector{vecG1Vector.begin(), vecG1Vector.end()}, - vector{vecHashes.begin(), vecHashes.end()}, - Bytes(aggVector))); - REQUIRE(BasicSchemeMPL().AggregateVerify({g1_1, g1_3}, - vector{vecHashes.begin(), vecHashes.end()}, - G2Element::FromBytes(aggVector))); + + REQUIRE(BasicSchemeMPL().AggregateVerify( + vector{vecG1Vector.begin(), vecG1Vector.end()}, + vector{vecHashes.begin(), vecHashes.end()}, + Bytes(aggVector))); + REQUIRE(BasicSchemeMPL().AggregateVerify( + {g1_1, g1_3}, + vector{vecHashes.begin(), vecHashes.end()}, + G2Element::FromBytes(aggVector))); G2Element g2AugSignVector1 = AugSchemeMPL().Sign(pk1, vecHash); G2Element g2AugSignBytes1 = AugSchemeMPL().Sign(pk1, Bytes(vecHash)); @@ -1027,40 +1161,53 @@ TEST_CASE("Advanced") { REQUIRE(g2AugSignVector1 == g2AugSignBytes1); REQUIRE(g2AugSignVector1 != g2AugSign2); - REQUIRE(AugSchemeMPL().Verify(Bytes(g1_1.Serialize()), Bytes(vecHash), Bytes(g2AugSignVector1.Serialize()))); + REQUIRE(AugSchemeMPL().Verify( + Bytes(g1_1.Serialize()), + Bytes(vecHash), + Bytes(g2AugSignVector1.Serialize()))); REQUIRE(AugSchemeMPL().Verify(g1_1, Bytes(vecHash), g2AugSignVector1)); - vector> vecG1AugVector = {g1_1.Serialize(), g1_2.Serialize()}; - vector> vecG2AugVector = {g2AugSignVector1.Serialize(), g2AugSign2.Serialize()}; + vector> vecG1AugVector = { + g1_1.Serialize(), g1_2.Serialize()}; + vector> vecG2AugVector = { + g2AugSignVector1.Serialize(), g2AugSign2.Serialize()}; auto aggAugVector = AugSchemeMPL().Aggregate(vecG2AugVector); - auto aggAugBytes = AugSchemeMPL().Aggregate(vector{vecG2AugVector.begin(), vecG2AugVector.end()}); + auto aggAugBytes = AugSchemeMPL().Aggregate( + vector{vecG2AugVector.begin(), vecG2AugVector.end()}); REQUIRE(aggAugVector == aggAugBytes); - REQUIRE(AugSchemeMPL().AggregateVerify(vector{vecG1AugVector.begin(), vecG1AugVector.end()}, - vector{vecHashes.begin(), vecHashes.end()}, - Bytes(aggAugVector))); - REQUIRE(AugSchemeMPL().AggregateVerify({g1_1, g1_2}, - vector{vecHashes.begin(), vecHashes.end()}, - G2Element::FromBytes(aggAugVector))); + REQUIRE(AugSchemeMPL().AggregateVerify( + vector{vecG1AugVector.begin(), vecG1AugVector.end()}, + vector{vecHashes.begin(), vecHashes.end()}, + Bytes(aggAugVector))); + REQUIRE(AugSchemeMPL().AggregateVerify( + {g1_1, g1_2}, + vector{vecHashes.begin(), vecHashes.end()}, + G2Element::FromBytes(aggAugVector))); G2Element proof = PopSchemeMPL().PopProve(pk1); REQUIRE(PopSchemeMPL().PopVerify(g1_1, proof)); - REQUIRE(PopSchemeMPL().PopVerify(Bytes(g1_1.Serialize()), Bytes(proof.Serialize()))); + REQUIRE(PopSchemeMPL().PopVerify( + Bytes(g1_1.Serialize()), Bytes(proof.Serialize()))); G2Element g2Pop1 = PopSchemeMPL().Sign(pk1, vecHash); G2Element g2Pop2 = PopSchemeMPL().Sign(pk2, vecHash); G2Element g2PopAgg = PopSchemeMPL().Aggregate({g2Pop1, g2Pop2}); vecG1Vector = {g1_1.Serialize(), g1_2.Serialize()}; - REQUIRE(PopSchemeMPL().FastAggregateVerify({g1_1, g1_2}, Bytes(vecHash), g2PopAgg)); - REQUIRE(PopSchemeMPL().FastAggregateVerify(vector{vecG1Vector.begin(), vecG1Vector.end()}, - Bytes(vecHash), Bytes(g2PopAgg.Serialize()))); + REQUIRE(PopSchemeMPL().FastAggregateVerify( + {g1_1, g1_2}, Bytes(vecHash), g2PopAgg)); + REQUIRE(PopSchemeMPL().FastAggregateVerify( + vector{vecG1Vector.begin(), vecG1Vector.end()}, + Bytes(vecHash), + Bytes(g2PopAgg.Serialize()))); } } - -TEST_CASE("Schemes") { - SECTION("Basic Scheme") { +TEST_CASE("Schemes") +{ + SECTION("Basic Scheme") + { vector seed1(32, 0x04); vector seed2(32, 0x05); std::array msg1 = {7, 8, 9}; @@ -1073,7 +1220,6 @@ TEST_CASE("Schemes") { G2Element sig1 = BasicSchemeMPL().Sign(sk1, msg1); vector sig1v = BasicSchemeMPL().Sign(sk1, msg1).Serialize(); - REQUIRE(BasicSchemeMPL().Verify(pk1v, msg1, sig1v)); PrivateKey sk2 = BasicSchemeMPL().KeyGen(seed2); @@ -1093,7 +1239,8 @@ TEST_CASE("Schemes") { REQUIRE(BasicSchemeMPL().Verify(pk2v, msg1, sig1v) == false); G2Element aggsig = BasicSchemeMPL().Aggregate({sig1, sig2}); - auto aggsigv = BasicSchemeMPL().Aggregate(vector>{sig1v, sig2v}); + auto aggsigv = + BasicSchemeMPL().Aggregate(vector>{sig1v, sig2v}); REQUIRE(BasicSchemeMPL().AggregateVerify({pk1, pk2}, msgs, aggsig)); REQUIRE(BasicSchemeMPL().AggregateVerify({pk1v, pk2v}, msgs, aggsigv)); } @@ -1132,7 +1279,8 @@ TEST_CASE("Schemes") { REQUIRE(AugSchemeMPL().Verify(pk2v, msg1, sig1v) == false); G2Element aggsig = AugSchemeMPL().Aggregate({sig1, sig2}); - auto aggsigv = AugSchemeMPL().Aggregate(vector>{sig1v, sig2v}); + auto aggsigv = + AugSchemeMPL().Aggregate(vector>{sig1v, sig2v}); REQUIRE(AugSchemeMPL().AggregateVerify({pk1, pk2}, msgs, aggsig)); REQUIRE(AugSchemeMPL().AggregateVerify({pk1v, pk2v}, msgs, Bytes(aggsigv.data(), aggsigv.size()))); } @@ -1171,7 +1319,8 @@ TEST_CASE("Schemes") { REQUIRE(PopSchemeMPL().Verify(pk2v, msg1, sig1v) == false); G2Element aggsig = PopSchemeMPL().Aggregate({sig1, sig2}); - auto aggsigv = PopSchemeMPL().Aggregate(vector>{sig1v, sig2v}); + auto aggsigv = + PopSchemeMPL().Aggregate(vector>{sig1v, sig2v}); REQUIRE(PopSchemeMPL().AggregateVerify({pk1, pk2}, msgs, aggsig)); REQUIRE(PopSchemeMPL().AggregateVerify({pk1v, pk2v}, msgs, Bytes(aggsigv.data(), aggsigv.size()))); @@ -1186,14 +1335,69 @@ TEST_CASE("Schemes") { G2Element sig2_same = PopSchemeMPL().Sign(sk2, msg1); vector sig2v_same = PopSchemeMPL().Sign(sk2, msg1).Serialize(); G2Element aggsig_same = PopSchemeMPL().Aggregate({sig1, sig2_same}); - auto aggsigv_same = - PopSchemeMPL().Aggregate(vector>{sig1v, sig2v_same}); + auto aggsigv_same = PopSchemeMPL().Aggregate( + vector>{sig1v, sig2v_same}); REQUIRE( PopSchemeMPL().FastAggregateVerify({pk1, pk2}, msg1, aggsig_same)); REQUIRE(PopSchemeMPL().FastAggregateVerify( {pk1v, pk2v}, msg1, aggsigv_same)); } + SECTION("Secure aggregation (Basic)") + { + vector seed1(32, 0x11); + vector seed2(32, 0x22); + vector seed3(32, 0x33); + vector msgData{7, 8, 9, 10}; + Bytes message(msgData); + + BasicSchemeMPL basicScheme; + vector basicSk{ + basicScheme.KeyGen(seed1), + basicScheme.KeyGen(seed2), + basicScheme.KeyGen(seed3) + }; + + vector basicPks; + vector basicSigs; + for (const auto& sk : basicSk) { + basicPks.push_back(basicScheme.SkToG1(sk)); + basicSigs.push_back(basicScheme.Sign(sk, message)); + } + + G2Element basicSecureAggSig; + REQUIRE_NOTHROW(basicSecureAggSig = basicScheme.AggregateSecure(basicPks, basicSigs, message)); + REQUIRE(basicScheme.VerifySecure(basicPks, basicSecureAggSig, message)); + } + + SECTION("Secure aggregation (Legacy)") + { + vector seed1(32, 0x11); + vector seed2(32, 0x22); + vector seed3(32, 0x33); + // Legacy scheme uses ep2_map_legacy which reads exactly 32 bytes, + // so the message must be at least BLS::MESSAGE_HASH_LEN (32) bytes. + vector msgData(32, 0xAB); + Bytes message(msgData); + + LegacySchemeMPL legacyScheme; + vector legacySk{ + legacyScheme.KeyGen(seed1), + legacyScheme.KeyGen(seed2), + legacyScheme.KeyGen(seed3) + }; + + vector legacyPks; + vector legacySigs; + for (const auto& sk : legacySk) { + legacyPks.push_back(legacyScheme.SkToG1(sk)); + legacySigs.push_back(legacyScheme.Sign(sk, message)); + } + + G2Element legacySecureAggSig = legacyScheme.AggregateSecure(legacyPks, legacySigs, message); + REQUIRE(legacyScheme.VerifySecure(legacyPks, legacySecureAggSig, message)); + } + SECTION("Legacy scheme") { // Test legacy example data defined in https://gist.github.com/xdustinface/318c2c08c36ab12a2b1963caf1f7815c std::string strSignHash{"b6d8ee31bbd375dfd55d5fb4b02cfccc68709e64f4c5ffcd3895ceb46540311d"}; @@ -1462,7 +1666,8 @@ TEST_CASE("Threshold Signatures") { TEST_CASE("CheckValid") { - SECTION("Valid points should succeed") { + SECTION("Valid points should succeed") + { vector seed(32, 0x05); vector msg1 = {10, 11, 12}; @@ -1484,32 +1689,36 @@ TEST_CASE("CheckValid") G1Element::FromBytes(Bytes(Util::HexToBytes(badPointHex)))); // FromBytesUnchecked does not throw - G1Element pk = + G1Element bad_pk = G1Element::FromBytesUnchecked(Bytes(Util::HexToBytes(badPointHex))); - REQUIRE(pk.IsValid() == false); - REQUIRE_THROWS(pk.CheckValid()); + REQUIRE(bad_pk.IsValid() == false); + REQUIRE_THROWS(bad_pk.CheckValid()); vector seed(32, 0x05); vector msg1 = {10, 11, 12}; PrivateKey sk1 = BasicSchemeMPL().KeyGen(seed); - G1Element pk1 = BasicSchemeMPL().SkToG1(sk1); + G1Element good_pk = BasicSchemeMPL().SkToG1(sk1); + REQUIRE(good_pk.IsValid() == true); G2Element sig1 = AugSchemeMPL().Sign(sk1, msg1); - REQUIRE(AugSchemeMPL().Verify(pk, msg1, sig1) == false); + REQUIRE(AugSchemeMPL().Verify(bad_pk, msg1, sig1) == false); + REQUIRE(AugSchemeMPL().Verify(good_pk, msg1, sig1) == true); } - SECTION("Invalid G2 points should not succeed") { - g2_t point_native; - g2_set_infty(point_native); - fp2_rand(point_native->x); - fp2_rand(point_native->y); - fp2_rand(point_native->z); + SECTION("Invalid G2 points should not succeed") + { + blst_p2 point_native; + memset(&point_native, 0, sizeof(blst_p2)); + + // copy some probably invalid data into the point + memcpy(&(point_native.x), (void*)memcpy, sizeof(point_native.x)); + memcpy(&(point_native.y), (void*)memset, sizeof(point_native.y)); + memcpy(&(point_native.z), (void*)printf, sizeof(point_native.z)); G2Element point = G2Element::FromNative(point_native); REQUIRE(point.IsValid() == false); REQUIRE_THROWS(point.CheckValid()); auto badSer = point.Serialize(); - std::cout < candidates; + if (const char* env = std::getenv("DASHBLS_REFERENCE_VECTORS")) { + candidates.push_back(env); + } +#ifdef DASHBLS_REFERENCE_VECTORS + candidates.push_back(DASHBLS_REFERENCE_VECTORS); +#endif + candidates.push_back("test-vectors/reference.txt"); + candidates.push_back("../test-vectors/reference.txt"); + candidates.push_back("../../test-vectors/reference.txt"); + for (const auto& c : candidates) { + if (std::ifstream(c).good()) return c; + } + std::string tried; + for (const auto& c : candidates) tried += "\n " + c; + FAIL("reference vectors not found; tried:" << tried); + return ""; +} + +TEST_CASE("Reference vectors") +{ + // Every consensus-visible behavior of the library, compared line by line + // against the output of the relic-based implementation. + const std::string path = ReferenceVectorsPath(); + INFO("reference file: " << path); + + std::vector expected; + std::ifstream in(path); + for (std::string line; std::getline(in, line);) { + if (line.empty() || line[0] == '#') continue; + expected.push_back(line); + } + REQUIRE(expected.size() > 300); + + std::vector actual; + for (const auto& line : bls_test_vectors::GenerateReferenceVectors()) { + if (line.empty() || line[0] == '#') continue; + actual.push_back(line); + } + + REQUIRE(actual.size() == expected.size()); + for (size_t i = 0; i < expected.size(); i++) { + INFO("vector " << i + 1 << " of " << expected.size()); + REQUIRE(actual[i] == expected[i]); + } +} + +TEST_CASE("GTElement") +{ + SECTION("GTElement serialization") + { + vector seed(32, 0x05); + blst_p1_affine p1_affine; + + PrivateKey sk1 = BasicSchemeMPL().KeyGen(seed); + G1Element pk1 = BasicSchemeMPL().SkToG1(sk1); + pk1.CheckValid(); + pk1.ToAffine(&p1_affine); + GTElement gt1 = GTElement::FromAffine(p1_affine); + + auto outbuf = gt1.Serialize(); + + auto gt2 = GTElement::FromBytesUnchecked(outbuf); + + REQUIRE(gt1 == gt2); + } + + SECTION("GTElement pairing") + { + vector seed(32, 0x05), seed2(32, 0x06); + vector msg1 = {7, 8, 9}; + vector msg2 = {10, 11, 12}; + + auto sk1 = BasicSchemeMPL().KeyGen(seed); + auto sk2 = BasicSchemeMPL().KeyGen(seed2); + + auto pk1 = sk1.GetG1Element(); + auto pk2 = sk2.GetG1Element(); + + auto sig1 = BasicSchemeMPL().Sign(sk1, msg1); + auto sig2 = BasicSchemeMPL().Sign(sk2, msg2); + + auto aggsig = BasicSchemeMPL().Aggregate({sig1, sig2}); + + REQUIRE(BasicSchemeMPL().AggregateVerify( + {pk1, pk2}, vector>{msg1, msg2}, aggsig)); + + auto pair1 = pk1.Pair(G2Element::FromMessage( + msg1, + (const uint8_t*)BasicSchemeMPL::CIPHERSUITE_ID.c_str(), + BasicSchemeMPL::CIPHERSUITE_ID.length())); + auto pair2 = pk2.Pair(G2Element::FromMessage( + msg2, + (const uint8_t*)BasicSchemeMPL::CIPHERSUITE_ID.c_str(), + BasicSchemeMPL::CIPHERSUITE_ID.length())); + auto pair = pair1 * pair2; + + auto agg_sig_pair = G1Element::Generator().Pair(aggsig); + + REQUIRE(pair == agg_sig_pair); + } +} + int main(int argc, char* argv[]) { int result = Catch::Session().run(argc, argv); diff --git a/src/dashbls/src/threshold.cpp b/src/dashbls/src/threshold.cpp index 73a3023b28da..8526832b7718 100644 --- a/src/dashbls/src/threshold.cpp +++ b/src/dashbls/src/threshold.cpp @@ -8,75 +8,8 @@ #include "schemes.hpp" -#include - static std::unique_ptr pThresholdScheme(new bls::LegacySchemeMPL); -/** - * Inverts a prime field element using the Euclidean Extended Algorithm, - * using bns and a custom prime modulus. - * - * @param[out] c - the result. - * @param[in] a - the prime field element to invert. - * @param[in] p - the custom prime modulus. - */ -static void fp_inv_exgcd_bn(bn_t c, const bn_t u_in, const bn_t p) { - bn_t u, v, g1, g2, q, r; - - bn_null(u); - bn_null(v); - bn_null(g1); - bn_null(g2); - bn_null(q); - bn_null(r); - - RLC_TRY { - bn_new(u); - bn_new(v); - bn_new(g1); - bn_new(g2); - bn_new(q); - bn_new(r); - - /* u = a, v = p, g1 = 1, g2 = 0. */ - bn_copy(u, u_in); - bn_copy(v, p); - bn_set_dig(g1, 1); - bn_zero(g2); - - /* While (u != 1. */ - while (bn_cmp_dig(u, 1) != RLC_EQ) { - /* q = [v/u], r = v mod u. */ - bn_div_rem(q, r, v, u); - /* v = u, u = r. */ - bn_copy(v, u); - bn_copy(u, r); - /* r = g2 - q * g1. */ - bn_mul(r, q, g1); - bn_sub(r, g2, r); - /* g2 = g1, g1 = r. */ - bn_copy(g2, g1); - bn_copy(g1, r); - } - - if (bn_sign(g1) == RLC_NEG) { - bn_add(g1, g1, p); - } - bn_copy(c, g1); - } - RLC_CATCH_ANY { - RLC_THROW(ERR_CAUGHT); - } - RLC_FINALLY { - bn_free(u); - bn_free(v); - bn_free(g1); - bn_free(g2); - bn_free(q); - bn_free(r); - }; -} - namespace bls { namespace Poly { @@ -91,43 +24,32 @@ namespace bls { } // end namespace Poly struct PolyOpsBase { - bn_t order; - bn_t iv; - - PolyOpsBase() { - bn_new(order); - gt_get_ord(order); - bn_new(iv); - } - - ~PolyOpsBase() { - bn_free(iv); - bn_free(order); + static bool IsZero(const blst_scalar& a) { + std::array zero{}; + return memcmp(&a, &zero, sizeof(blst_scalar)) == 0; } - void MulFP(bn_t& r, const bn_t& a, const bn_t& b) { - bn_mul(r, a, b); - ModOrder(r); + void MulFP(blst_scalar& r, const blst_scalar& a, const blst_scalar& b) { + blst_sk_mul_n_check(&r, &a, &b); } - void AddFP(bn_t& r, const bn_t& a, const bn_t& b) { - bn_add(r, a, b); - ModOrder(r); + void AddFP(blst_scalar& r, const blst_scalar& a, const blst_scalar& b) { + blst_sk_add_n_check(&r, &a, &b); } - void SubFP(bn_t& r, const bn_t& a, const bn_t& b) { - bn_sub(r, a, b); - ModOrder(r); + void SubFP(blst_scalar& r, const blst_scalar& a, const blst_scalar& b) { + blst_sk_sub_n_check(&r, &a, &b); } - void DivFP(bn_t& r, const bn_t& a, const bn_t& b) { - fp_inv_exgcd_bn(iv, b, order); - bn_mul(r, a, iv); - ModOrder(r); + void DivFP(blst_scalar& r, const blst_scalar& a, const blst_scalar& b) { + blst_scalar iv; + blst_sk_inverse(&iv, &b); + blst_sk_mul_n_check(&r, &a, &iv); } - void ModOrder(bn_t& r) { - bn_mod(r, r, order); + void ScalarFromBytes(blst_scalar& r, const uint8_t* bytes) { + // reduces mod the group order, like bn_read_bin + bn_mod + blst_scalar_from_be_bytes(&r, bytes, Poly::nIdSize); } }; @@ -140,7 +62,7 @@ namespace bls { return PrivateKey::Aggregate({a, b}); } - PrivateKey Mul(const PrivateKey& a, const bn_t& b) { + PrivateKey Mul(const PrivateKey& a, const blst_scalar& b) { return a * b; } }; @@ -151,7 +73,7 @@ namespace bls { return a + b; } - G1Element Mul(const G1Element& a, const bn_t& b) { + G1Element Mul(const G1Element& a, const blst_scalar& b) { return a * b; } }; @@ -162,7 +84,7 @@ namespace bls { return a + b; } - G2Element Mul(const G2Element& a, bn_t& b) { + G2Element Mul(const G2Element& a, const blst_scalar& b) { return a * b; } }; @@ -175,10 +97,8 @@ namespace bls { throw std::length_error("At least 2 coefficients required"); } - bn_t x; - bn_new(x); - bn_read_bin(x, id.begin(), Poly::nIdSize); - ops.ModOrder(x); + blst_scalar x; + ops.ScalarFromBytes(x, id.begin()); BLSType y = vecIn.back(); for (int i = (int) vecIn.size() - 2; i >= 0; i--) { @@ -186,8 +106,6 @@ namespace bls { y = ops.Add(y, vecIn[i]); } - bn_free(x); - return y; } @@ -209,48 +127,28 @@ namespace bls { */ const size_t k = vec.size(); - bn_t *delta = new bn_t[k]; - bn_t *ids2 = new bn_t[k]; + std::vector delta(k); + std::vector ids2(k); for (size_t i = 0; i < k; i++) { - bn_new(delta[i]); - bn_new(ids2[i]); - bn_read_bin(ids2[i], ids[i].begin(), Poly::nIdSize); - ops.ModOrder(ids2[i]); + ops.ScalarFromBytes(ids2[i], ids[i].begin()); } - bn_t a, b, v; - bn_new(a); - bn_new(b); - bn_new(v); - - auto cleanup = [&](){ - bn_free(a); - bn_free(b); - bn_free(v); - for (size_t i = 0; i < k; i++) { - bn_free(delta[i]); - bn_free(ids2[i]); - } - delete[] delta; - delete[] ids2; - }; + blst_scalar a, b, v; - bn_copy(a, ids2[0]); + a = ids2[0]; for (size_t i = 1; i < k; i++) { ops.MulFP(a, a, ids2[i]); } - if (bn_is_zero(a)) { - cleanup(); + if (PolyOpsBase::IsZero(a)) { throw std::invalid_argument("Zero id"); } for (size_t i = 0; i < k; i++) { - bn_copy(b, ids2[i]); + b = ids2[i]; for (size_t j = 0; j < k; j++) { if (j != i) { ops.SubFP(v, ids2[j], ids2[i]); - if (bn_is_zero(v)) { - cleanup(); + if (PolyOpsBase::IsZero(v)) { throw std::invalid_argument("Duplicate id"); } ops.MulFP(b, b, v); @@ -267,8 +165,6 @@ namespace bls { r = ops.Add(r, ops.Mul(vec[i], delta[i])); } - cleanup(); - return r; } @@ -295,7 +191,7 @@ namespace bls { G2Element Threshold::SignatureRecover(const std::vector& sigs, const std::vector& ids) { return Poly::LagrangeInterpolate(sigs, ids); } - + G2Element Threshold::Sign(const PrivateKey& privateKey, const Bytes& vecMessage) { return pThresholdScheme->Sign(privateKey, vecMessage); } diff --git a/src/dashbls/test-vectors/reference.txt b/src/dashbls/test-vectors/reference.txt new file mode 100644 index 000000000000..0df48a9f9282 --- /dev/null +++ b/src/dashbls/test-vectors/reference.txt @@ -0,0 +1,324 @@ +# dashbls reference vectors v1 +A.sk.0=542b7d7900f6335cba45d5d7a53d59d73f26f230905bfcd6ad91ebb85eaa008a +A.pk.basic.0=9331005927ff67f0bd41be6037dcc07feea679be922e915c9be2a229c38fe5d178527877a6a66126ef4a8619277c58f0 +A.pk.legacy.0=1331005927ff67f0bd41be6037dcc07feea679be922e915c9be2a229c38fe5d178527877a6a66126ef4a8619277c58f0 +A.fp.basic.0=d4ddc775 +A.fp.legacy.0=ca704224 +A.skG2.basic.0=9131d5ad87990f02258898a22680b72d1762a084fd23f793b94477473deb23dbaf5e3a0635aa8bd373136c0bf84d4dbd03d21a5719c4b680b72be4649635262df36794ceeea24865dd55705e4370ef96346efe7795b37f27eb8ae49f134fcad0 +A.skG2.legacy.0=03d21a5719c4b680b72be4649635262df36794ceeea24865dd55705e4370ef96346efe7795b37f27eb8ae49f134fcad01131d5ad87990f02258898a22680b72d1762a084fd23f793b94477473deb23dbaf5e3a0635aa8bd373136c0bf84d4dbd +A.pk.rt.legacy.0=1331005927ff67f0bd41be6037dcc07feea679be922e915c9be2a229c38fe5d178527877a6a66126ef4a8619277c58f0 +A.pk.rt.basic.0=9331005927ff67f0bd41be6037dcc07feea679be922e915c9be2a229c38fe5d178527877a6a66126ef4a8619277c58f0 +B.lsig.legacy.0=8a3b9450bb7620dc07ff10a553ad8e55805aaf1270de68bda5c3ef581945748a3732d0bf6c44e277a92f077b53fb0cc8091006a639d501de9236351b8e6e60da58281ec4a1edab1b26b698e7150c89952ced7dec9d2a95dc492d31f68b6c47ea +B.lsig.basic.0=a91006a639d501de9236351b8e6e60da58281ec4a1edab1b26b698e7150c89952ced7dec9d2a95dc492d31f68b6c47ea0a3b9450bb7620dc07ff10a553ad8e55805aaf1270de68bda5c3ef581945748a3732d0bf6c44e277a92f077b53fb0cc8 +B.lverify.0=1 +B.lverify.bad.0=0 +B.lsig.rt.0=8a3b9450bb7620dc07ff10a553ad8e55805aaf1270de68bda5c3ef581945748a3732d0bf6c44e277a92f077b53fb0cc8091006a639d501de9236351b8e6e60da58281ec4a1edab1b26b698e7150c89952ced7dec9d2a95dc492d31f68b6c47ea +B.bsig.basic.0=8d3631d71a4f57c50f8108adb0cada2be41fba7bb1eced6e2b1757204f4103bbe41b0205cddd12a0c1f723633751eef517dc82561728b2b3482e74a4bbac58ac8851dad5247d11ad9b549690805fd078e02f39a6688e7db82f3a077c2f7dd4ab +B.bsig.legacy.0=17dc82561728b2b3482e74a4bbac58ac8851dad5247d11ad9b549690805fd078e02f39a6688e7db82f3a077c2f7dd4ab0d3631d71a4f57c50f8108adb0cada2be41fba7bb1eced6e2b1757204f4103bbe41b0205cddd12a0c1f723633751eef5 +B.bverify.0=1 +A.child.hard.0=13673dc18365d4d8d67005749ed2fba3c92dac9a259f3dac769288177d2de1ac +A.child.soft.0=43f1ad49de1fac8a337f01f27c48720cf0e453cb48cd8112c4c6aecf191c393b +A.sk.1=0d80059486148cf5dd43d6c2b42d41378e0e2cc354e328089fd5cc1eafb20549 +A.pk.basic.1=b4c69e82f075931025ea1ff15c340a0a0887f8611b7c85d02b9a1e4bcdcb22673d10a26fd3d6018e99777a302a345626 +A.pk.legacy.1=94c69e82f075931025ea1ff15c340a0a0887f8611b7c85d02b9a1e4bcdcb22673d10a26fd3d6018e99777a302a345626 +A.fp.basic.1=68f69bbe +A.fp.legacy.1=00eeb456 +A.skG2.basic.1=91005feee5588ac7887cbd365aff07a2e255cddfaff09016669f7993d68cd9a63793dcade435c0d12e875a683b3cd69a170cff1dd1e7a4e7ce4f7a3538ee76cef7b555524c2e302e4eb8ac2c759b1fa0631395df06e6eae95ca0c3aa82731576 +A.skG2.legacy.1=170cff1dd1e7a4e7ce4f7a3538ee76cef7b555524c2e302e4eb8ac2c759b1fa0631395df06e6eae95ca0c3aa8273157611005feee5588ac7887cbd365aff07a2e255cddfaff09016669f7993d68cd9a63793dcade435c0d12e875a683b3cd69a +A.pk.rt.legacy.1=94c69e82f075931025ea1ff15c340a0a0887f8611b7c85d02b9a1e4bcdcb22673d10a26fd3d6018e99777a302a345626 +A.pk.rt.basic.1=b4c69e82f075931025ea1ff15c340a0a0887f8611b7c85d02b9a1e4bcdcb22673d10a26fd3d6018e99777a302a345626 +B.lsig.legacy.1=103edb2bcadfc658095e04ccbaf682d075612fb86e2be06366fef0d1245a9ff7f87c1c8a3bc8b89a88585d9c568389ea043ae22ef8777d79719cff2cc0c777fcb16277c9f5b3a4ed782b045ecc41421b6302941ee7cfd769e645ecaea359f457 +B.lsig.basic.1=843ae22ef8777d79719cff2cc0c777fcb16277c9f5b3a4ed782b045ecc41421b6302941ee7cfd769e645ecaea359f457103edb2bcadfc658095e04ccbaf682d075612fb86e2be06366fef0d1245a9ff7f87c1c8a3bc8b89a88585d9c568389ea +B.lverify.1=1 +B.lverify.bad.1=0 +B.lsig.rt.1=103edb2bcadfc658095e04ccbaf682d075612fb86e2be06366fef0d1245a9ff7f87c1c8a3bc8b89a88585d9c568389ea043ae22ef8777d79719cff2cc0c777fcb16277c9f5b3a4ed782b045ecc41421b6302941ee7cfd769e645ecaea359f457 +B.bsig.basic.1=80f49f1b340f745c84ab7b51bbb742a6f82fbc04204398683dbcc861ed1f87fa45180c6ba9d5950347fc8d14cae6bc8f105a6d4978bf6c4333b489c656ad1eb3668f7584430a8f9c24349e6199e791e64627bde51a6af2f2905b58c12b121fb6 +B.bsig.legacy.1=105a6d4978bf6c4333b489c656ad1eb3668f7584430a8f9c24349e6199e791e64627bde51a6af2f2905b58c12b121fb600f49f1b340f745c84ab7b51bbb742a6f82fbc04204398683dbcc861ed1f87fa45180c6ba9d5950347fc8d14cae6bc8f +B.bverify.1=1 +A.child.hard.1=35bf9c36f494622db64c5173493cff599df5e765d687742cb6533b1d8c6d886d +A.child.soft.1=39827c4c7749881f819a8e5c1f4d9669d7c25c18166a71d15b633c2f89daf7e8 +A.sk.2=604f88a4ee4198b3668dc38ae604dedeb45464df19e941b57d5957a5372085d1 +A.pk.basic.2=b11bd93b3fa94ee47b60c7628a52f7731005c92dadb73f9421de7fc5ca67e816106f26d121539fbf131545c8242a8d0f +A.pk.legacy.2=911bd93b3fa94ee47b60c7628a52f7731005c92dadb73f9421de7fc5ca67e816106f26d121539fbf131545c8242a8d0f +A.fp.basic.2=919d796a +A.fp.legacy.2=0ef6fc3e +A.skG2.basic.2=835092be4610e6a7e5e131f10f58a53444c0f89fbc37250bf19157e28f0a34f211cfea8022ade9a4b8b53ae090129cf503245c6bb1356ca13f772291319fc284c1a76b396fa469bd6f32d3eccdc549ba6f95e4ca08fb3777087e006cf2caa524 +A.skG2.legacy.2=03245c6bb1356ca13f772291319fc284c1a76b396fa469bd6f32d3eccdc549ba6f95e4ca08fb3777087e006cf2caa524035092be4610e6a7e5e131f10f58a53444c0f89fbc37250bf19157e28f0a34f211cfea8022ade9a4b8b53ae090129cf5 +A.pk.rt.legacy.2=911bd93b3fa94ee47b60c7628a52f7731005c92dadb73f9421de7fc5ca67e816106f26d121539fbf131545c8242a8d0f +A.pk.rt.basic.2=b11bd93b3fa94ee47b60c7628a52f7731005c92dadb73f9421de7fc5ca67e816106f26d121539fbf131545c8242a8d0f +B.lsig.legacy.2=0c5af10db2238f74776e094771cf2d4ee5e78ac8af94a618d106b7702c0b369012e327c943f23346ca461764f48351510726329193ae51b7c98e5c215f1e79d4328d9a107d7449d9a37bc504225d0dd952cc317c36b2ff4e6e270be58583148b +B.lsig.basic.2=8726329193ae51b7c98e5c215f1e79d4328d9a107d7449d9a37bc504225d0dd952cc317c36b2ff4e6e270be58583148b0c5af10db2238f74776e094771cf2d4ee5e78ac8af94a618d106b7702c0b369012e327c943f23346ca461764f4835151 +B.lverify.2=1 +B.lverify.bad.2=0 +B.lsig.rt.2=0c5af10db2238f74776e094771cf2d4ee5e78ac8af94a618d106b7702c0b369012e327c943f23346ca461764f48351510726329193ae51b7c98e5c215f1e79d4328d9a107d7449d9a37bc504225d0dd952cc317c36b2ff4e6e270be58583148b +B.bsig.basic.2=b5a4aaf5174fc68468b7bab3b182ea6e55fb55843d17b1950383f934710cdaa6a77c4494e79ec674dfc3167bfc1d944216d3e13e435a0509da3e670ebc5aeef151f32558891e00b9e8560e47601662a8e4ea893ab20cc5e909640e33bbf41fd3 +B.bsig.legacy.2=96d3e13e435a0509da3e670ebc5aeef151f32558891e00b9e8560e47601662a8e4ea893ab20cc5e909640e33bbf41fd315a4aaf5174fc68468b7bab3b182ea6e55fb55843d17b1950383f934710cdaa6a77c4494e79ec674dfc3167bfc1d9442 +B.bverify.2=1 +A.child.hard.2=140053409896043b8b7434dc29f14d132b3cbbd139677ff397a1c10f8f364616 +A.child.soft.2=525eb8eba7332727e1b0ff22bdf6320eb401d3d5e1caebdd72b0fa8aa2f0e942 +A.sk.3=21160cba355200250e9fad6bca96ed116930dc632dce23081636fedeb106c83b +A.pk.basic.3=982f6be34861d32d8d3e5aae0395ea80bff4e25b46052f41d6453754f51cd1721d44dd9f5fb62a35ca6d367e36218d4b +A.pk.legacy.3=182f6be34861d32d8d3e5aae0395ea80bff4e25b46052f41d6453754f51cd1721d44dd9f5fb62a35ca6d367e36218d4b +A.fp.basic.3=b7fea396 +A.fp.legacy.3=f71bdf44 +A.skG2.basic.3=a9a60b869403189f7abc1abf476d8afc27e4a8502f9a4949227f03393b793050a5a16c9b89d084452ff79741fc684925188c8776bc0b799fff488f0214a3b875d543b626c18a9ac0c8b6447de08c82aa735728727458305f69f77882b9d2098a +A.skG2.legacy.3=988c8776bc0b799fff488f0214a3b875d543b626c18a9ac0c8b6447de08c82aa735728727458305f69f77882b9d2098a09a60b869403189f7abc1abf476d8afc27e4a8502f9a4949227f03393b793050a5a16c9b89d084452ff79741fc684925 +A.pk.rt.legacy.3=182f6be34861d32d8d3e5aae0395ea80bff4e25b46052f41d6453754f51cd1721d44dd9f5fb62a35ca6d367e36218d4b +A.pk.rt.basic.3=982f6be34861d32d8d3e5aae0395ea80bff4e25b46052f41d6453754f51cd1721d44dd9f5fb62a35ca6d367e36218d4b +B.lsig.legacy.3=0d58f53ad17f3877f23884799c7f8dd866e7e6feaba63da933f01e447d39b7c48d941ecab58ff845cd51aa6f1d6ce57207acf6cc920e3310dcfbc3694d8483333e2e78a578be78b645aa1cd037608bb78d05f6a8de4377c5bfa52e7f6e01bdfa +B.lsig.basic.3=87acf6cc920e3310dcfbc3694d8483333e2e78a578be78b645aa1cd037608bb78d05f6a8de4377c5bfa52e7f6e01bdfa0d58f53ad17f3877f23884799c7f8dd866e7e6feaba63da933f01e447d39b7c48d941ecab58ff845cd51aa6f1d6ce572 +B.lverify.3=1 +B.lverify.bad.3=0 +B.lsig.rt.3=0d58f53ad17f3877f23884799c7f8dd866e7e6feaba63da933f01e447d39b7c48d941ecab58ff845cd51aa6f1d6ce57207acf6cc920e3310dcfbc3694d8483333e2e78a578be78b645aa1cd037608bb78d05f6a8de4377c5bfa52e7f6e01bdfa +B.bsig.basic.3=8300e9d700c1d263e5d9caec9a3302aa8984b515bd961f25b913de852168ecc0e0dcea0913a7359bee57071208895ea812bd1ae92601ba7f2e8d6d6809330ef06dde1c8ff633cff5db38a63b5aec867d43a6e3e9bafac7aec876d6625666a5cd +B.bsig.legacy.3=12bd1ae92601ba7f2e8d6d6809330ef06dde1c8ff633cff5db38a63b5aec867d43a6e3e9bafac7aec876d6625666a5cd0300e9d700c1d263e5d9caec9a3302aa8984b515bd961f25b913de852168ecc0e0dcea0913a7359bee57071208895ea8 +B.bverify.3=1 +A.child.hard.3=58a543b659628491544fc0f85d4938820dc19d5591d53f49c8b9d950d433aff7 +A.child.soft.3=0c9bd3c62871a9e36c947f7a7ab764a69b1fdb41f9625b30bd3a5bd91484f5b6 +A.sk.4=0b23c79ec3331dd7a2d4a8708b21263330b9a9d8891a81360744a2a483ea884a +A.pk.basic.4=8564f4d30abe512e9ef8c36f903436b927feebef83329f88f50d4621d6d9b59f16316f859fe5659024cce812d9f91852 +A.pk.legacy.4=0564f4d30abe512e9ef8c36f903436b927feebef83329f88f50d4621d6d9b59f16316f859fe5659024cce812d9f91852 +A.fp.basic.4=228139d6 +A.fp.legacy.4=8710d0bc +A.skG2.basic.4=833682df2e6ae024e5d9bfb5c5dc15cb855d55e945693979abfb2078aed37421438782b7d6b17345bdac09f86563327b04f35a0374e59bc64ef3ee948dc4cd4689c4f55f298c6a5ad9703e823f853d07c958b87aa151a066d31a95cfec1da928 +A.skG2.legacy.4=04f35a0374e59bc64ef3ee948dc4cd4689c4f55f298c6a5ad9703e823f853d07c958b87aa151a066d31a95cfec1da928033682df2e6ae024e5d9bfb5c5dc15cb855d55e945693979abfb2078aed37421438782b7d6b17345bdac09f86563327b +A.pk.rt.legacy.4=0564f4d30abe512e9ef8c36f903436b927feebef83329f88f50d4621d6d9b59f16316f859fe5659024cce812d9f91852 +A.pk.rt.basic.4=8564f4d30abe512e9ef8c36f903436b927feebef83329f88f50d4621d6d9b59f16316f859fe5659024cce812d9f91852 +B.lsig.legacy.4=11fbebe8bab5c35042663c60a32b7fcc3350f2a7a0cff79cb17185def6674c1233e6915545ad43e3043ba9517c283d20198fe3bbba59fc4ed6dc89b7432a7f5188caa47ec7b08631bfe2d3d2a3a745c0ad7bca351bfbdf74e49b2f46532c99f1 +B.lsig.basic.4=998fe3bbba59fc4ed6dc89b7432a7f5188caa47ec7b08631bfe2d3d2a3a745c0ad7bca351bfbdf74e49b2f46532c99f111fbebe8bab5c35042663c60a32b7fcc3350f2a7a0cff79cb17185def6674c1233e6915545ad43e3043ba9517c283d20 +B.lverify.4=1 +B.lverify.bad.4=0 +B.lsig.rt.4=11fbebe8bab5c35042663c60a32b7fcc3350f2a7a0cff79cb17185def6674c1233e6915545ad43e3043ba9517c283d20198fe3bbba59fc4ed6dc89b7432a7f5188caa47ec7b08631bfe2d3d2a3a745c0ad7bca351bfbdf74e49b2f46532c99f1 +B.bsig.basic.4=a57f7ec0d09676c12b4fb525a1d359b7c29cc0f010682905f0a44bafc8764998c85fb885f9affeb2e256cfb3f5558c61180da06bedd87410c1f842ddcf467b04aeed09b4cb8c2eb4dbf5f502cea4683e6c35cf2475208fa3dcd852e5d290faf2 +B.bsig.legacy.4=980da06bedd87410c1f842ddcf467b04aeed09b4cb8c2eb4dbf5f502cea4683e6c35cf2475208fa3dcd852e5d290faf2057f7ec0d09676c12b4fb525a1d359b7c29cc0f010682905f0a44bafc8764998c85fb885f9affeb2e256cfb3f5558c61 +B.bverify.4=1 +A.child.hard.4=1422752ec6e3f867f5f80020bec1d84e6ade884bf4093f4d337f503417e00fdd +A.child.soft.4=10b37a4b07fa1a78786efbe3f116dfd462ba0ce94e7afa742f5a87234c3a868f +A.sk.5=0535569670f3c8c0379aea8c93b3bedf5ef16672417c281da18b957f41398d13 +A.pk.basic.5=b14d33ec70e47c7d9c7895bc4bb6d9979d81118354bb84571aed49b1dd8560a9ddbf71660d6c567bf7f391c51e0e5c45 +A.pk.legacy.5=914d33ec70e47c7d9c7895bc4bb6d9979d81118354bb84571aed49b1dd8560a9ddbf71660d6c567bf7f391c51e0e5c45 +A.fp.basic.5=1c9dbfe5 +A.fp.legacy.5=708cb0c8 +A.skG2.basic.5=8af786a3d660b1305eee25239d7c8f225fa604b23f96287745b9caee6a039ff21733bbe644df10daaf79c0ddc187bf4811d3f20781f42de6cb8fae96a560ed9f42aff7d3fee427f7bb44967dbbaff01e3efdad10b83a33076246b5819d1ef755 +A.skG2.legacy.5=11d3f20781f42de6cb8fae96a560ed9f42aff7d3fee427f7bb44967dbbaff01e3efdad10b83a33076246b5819d1ef7550af786a3d660b1305eee25239d7c8f225fa604b23f96287745b9caee6a039ff21733bbe644df10daaf79c0ddc187bf48 +A.pk.rt.legacy.5=914d33ec70e47c7d9c7895bc4bb6d9979d81118354bb84571aed49b1dd8560a9ddbf71660d6c567bf7f391c51e0e5c45 +A.pk.rt.basic.5=b14d33ec70e47c7d9c7895bc4bb6d9979d81118354bb84571aed49b1dd8560a9ddbf71660d6c567bf7f391c51e0e5c45 +B.lsig.legacy.5=116b3ec371691cdf6b75db98148553ffa14ee11df0ebced3a2e7dfe9e7fb1e4da4f322d1df36d03bf3b75ed60cc6aadc07c0606f8cd2196e6d9a8c146a6c6f2d9d78898110da264e79291c5bf2d5d0567e741bca297c7b3d001cf202185411b5 +B.lsig.basic.5=87c0606f8cd2196e6d9a8c146a6c6f2d9d78898110da264e79291c5bf2d5d0567e741bca297c7b3d001cf202185411b5116b3ec371691cdf6b75db98148553ffa14ee11df0ebced3a2e7dfe9e7fb1e4da4f322d1df36d03bf3b75ed60cc6aadc +B.lverify.5=1 +B.lverify.bad.5=0 +B.lsig.rt.5=116b3ec371691cdf6b75db98148553ffa14ee11df0ebced3a2e7dfe9e7fb1e4da4f322d1df36d03bf3b75ed60cc6aadc07c0606f8cd2196e6d9a8c146a6c6f2d9d78898110da264e79291c5bf2d5d0567e741bca297c7b3d001cf202185411b5 +B.bsig.basic.5=98e09cacf9f860bc131c401c6dc20a96cba00c581a2abf576a58ae4e0edd96d82764f95e1b0a00d6e6ad52db83adb92b16349f9b0675e0b6ffe90ec64203fce107813ae36cfb3a4c98b40580b362d22b27595d57e1f02ab67534b96b186ee2fe +B.bsig.legacy.5=16349f9b0675e0b6ffe90ec64203fce107813ae36cfb3a4c98b40580b362d22b27595d57e1f02ab67534b96b186ee2fe18e09cacf9f860bc131c401c6dc20a96cba00c581a2abf576a58ae4e0edd96d82764f95e1b0a00d6e6ad52db83adb92b +B.bverify.5=1 +A.child.hard.5=186953b6ebeb46b7d6d17f4eb6b55738a8910468d8c7a12773fa4ece4d396e33 +A.child.soft.5=36aae8999b8d557746cb7310a2291c8facd190430c6f769f60193610a5e7f570 +A.sk.6=3e54ca602df6ef98b894e98a87eddca31b87fd052cfcab698477b3ad19c84dfb +A.pk.basic.6=925b01d07a6e175a0b38f66c5bb2263f13f9800f2becbff87a73548c3ec188e08505a3bc17f046f0610b84e3c487ec3f +A.pk.legacy.6=125b01d07a6e175a0b38f66c5bb2263f13f9800f2becbff87a73548c3ec188e08505a3bc17f046f0610b84e3c487ec3f +A.fp.basic.6=910eddce +A.fp.legacy.6=08462c2f +A.skG2.basic.6=ab3a64185b1e43943f8645682b86e13882653beeee52343ced9b87556c6eb39f2b87cd0fffe68276470a4c4afc21445413753b7fee41fa154a0b76495935a97243279fd70a0baff73cd8ae88c2b387ccd358cac5d7c34af4cc7e348c0fea602d +A.skG2.legacy.6=93753b7fee41fa154a0b76495935a97243279fd70a0baff73cd8ae88c2b387ccd358cac5d7c34af4cc7e348c0fea602d0b3a64185b1e43943f8645682b86e13882653beeee52343ced9b87556c6eb39f2b87cd0fffe68276470a4c4afc214454 +A.pk.rt.legacy.6=125b01d07a6e175a0b38f66c5bb2263f13f9800f2becbff87a73548c3ec188e08505a3bc17f046f0610b84e3c487ec3f +A.pk.rt.basic.6=925b01d07a6e175a0b38f66c5bb2263f13f9800f2becbff87a73548c3ec188e08505a3bc17f046f0610b84e3c487ec3f +B.lsig.legacy.6=825a6eb2146a57893682066d783509b342fc5869ae0559330e11cb10ec3a132e9cde762c6869e67c9b83d0de2646ebac09aa2a4d7a08831cab78b6b7a57f57fad48cd1dbe3c3da0d996db69ff13fc060af2626a14bf69092def390acf6320f4d +B.lsig.basic.6=a9aa2a4d7a08831cab78b6b7a57f57fad48cd1dbe3c3da0d996db69ff13fc060af2626a14bf69092def390acf6320f4d025a6eb2146a57893682066d783509b342fc5869ae0559330e11cb10ec3a132e9cde762c6869e67c9b83d0de2646ebac +B.lverify.6=1 +B.lverify.bad.6=0 +B.lsig.rt.6=825a6eb2146a57893682066d783509b342fc5869ae0559330e11cb10ec3a132e9cde762c6869e67c9b83d0de2646ebac09aa2a4d7a08831cab78b6b7a57f57fad48cd1dbe3c3da0d996db69ff13fc060af2626a14bf69092def390acf6320f4d +B.bsig.basic.6=b8801cf2113e290828ae4c2ef629d8cb3d3a34d3b8de7dcd0170f6a070f0787941ca2ed97d561c1b069b688945efb525033f27242eace77e730ce5c0a1200b05be002b47b2a7664445537f0ad10dbf24bbf0cc0f60ccd6992df41f3030f71c2a +B.bsig.legacy.6=833f27242eace77e730ce5c0a1200b05be002b47b2a7664445537f0ad10dbf24bbf0cc0f60ccd6992df41f3030f71c2a18801cf2113e290828ae4c2ef629d8cb3d3a34d3b8de7dcd0170f6a070f0787941ca2ed97d561c1b069b688945efb525 +B.bverify.6=1 +A.child.hard.6=5cec6bb344ecd98a133343f77b84fe620d46b1468a4579c83963cc0d32be15fc +A.child.soft.6=49f50d890fa3b2d475a6ce1bb2c56f9508fe8d2662659146e3434390ddc0e94d +A.sk.7=0e3c506a5cc9be55237397674e0fe32f61e4ecb6e2c761493d89c7a17a6dcc0d +A.pk.basic.7=9661920ea04d278794e28c0767591a11bb1f4678e765354e257887bf5c8e38ad3aaa258d22ac826ecb1f2b31a23a7415 +A.pk.legacy.7=1661920ea04d278794e28c0767591a11bb1f4678e765354e257887bf5c8e38ad3aaa258d22ac826ecb1f2b31a23a7415 +A.fp.basic.7=e141846a +A.fp.legacy.7=c4d6d99d +A.skG2.basic.7=86d69b68a97adf54d024ce7fef27dbc0b3f08b993daec1434b5b8f77b0f09614e0ff35c5e24b4e3b57c378e5370e2f3715847268902520804e69b0c74f7744ccefed304bbf4f06103874fba5468add684faf46d5719fdb2570e398cef37e64cb +A.skG2.legacy.7=15847268902520804e69b0c74f7744ccefed304bbf4f06103874fba5468add684faf46d5719fdb2570e398cef37e64cb06d69b68a97adf54d024ce7fef27dbc0b3f08b993daec1434b5b8f77b0f09614e0ff35c5e24b4e3b57c378e5370e2f37 +A.pk.rt.legacy.7=1661920ea04d278794e28c0767591a11bb1f4678e765354e257887bf5c8e38ad3aaa258d22ac826ecb1f2b31a23a7415 +A.pk.rt.basic.7=9661920ea04d278794e28c0767591a11bb1f4678e765354e257887bf5c8e38ad3aaa258d22ac826ecb1f2b31a23a7415 +B.lsig.legacy.7=946ba1386b9b458466890d857082710507ec67a1e055caa977799a92278fda373155e0b9fefb4fb40ede46112c1ccdf70035ec9fabb85bc7e8493fbc4f892d0cd9ef73ef86656a000bc95eaf980ec76a0db375c4165016bf7fc72a96dcd6ac0f +B.lsig.basic.7=a035ec9fabb85bc7e8493fbc4f892d0cd9ef73ef86656a000bc95eaf980ec76a0db375c4165016bf7fc72a96dcd6ac0f146ba1386b9b458466890d857082710507ec67a1e055caa977799a92278fda373155e0b9fefb4fb40ede46112c1ccdf7 +B.lverify.7=1 +B.lverify.bad.7=0 +B.lsig.rt.7=946ba1386b9b458466890d857082710507ec67a1e055caa977799a92278fda373155e0b9fefb4fb40ede46112c1ccdf70035ec9fabb85bc7e8493fbc4f892d0cd9ef73ef86656a000bc95eaf980ec76a0db375c4165016bf7fc72a96dcd6ac0f +B.bsig.basic.7=ae7378473f2e89255e78676f4ee798ea8e169551dfcc8b78cd564dbdf5d1495c0145e95c7e5d0df191c955a40ba033b805363357f176bd8b84063ae47bf7e3a273a2644ba437a9c496a66761a0693305b3249f588dd1e45feef9d33e1030c076 +B.bsig.legacy.7=85363357f176bd8b84063ae47bf7e3a273a2644ba437a9c496a66761a0693305b3249f588dd1e45feef9d33e1030c0760e7378473f2e89255e78676f4ee798ea8e169551dfcc8b78cd564dbdf5d1495c0145e95c7e5d0df191c955a40ba033b8 +B.bverify.7=1 +A.child.hard.7=6be06280ee13d42a1d9f12b5d3e9b429641ede55b3bad11a27948123e89d8913 +A.child.soft.7=1605a13324f75c0755fe03bfb1a9e9478586c12a54332de98ec4658dc233ce14 +C.aggsec.legacy.1=17b20ce50a20f09a4d807d4c0db622d13be8902380e908a9304d21d03520cb9712e8fb478bd4eb35477298c05ad5069610688edde3431521fa64f24c6e6fad0b38fd77ae2edd71871948273c6a17efad03b2f908fa9717935fc7ae68ca7421ec +C.versec.legacy.1=1 +C.aggsec.basic.1=98103b71225c000a8e08507ac38248bc97ff96c4ef0a0ecb610ba97798df58f741421304b46dbe709d891640bdc797d316e5b1fe117273391a37e981838677ce2185afe88e4f29a51ceb6d7c9a7f22062e8d4029345f2f37a473b2a8055ed848 +C.versec.basic.1=1 +C.versec.legacy.bad.1=0 +C.agg.G2.1=a941eab017de217c825e0724f3ec1bfbfd90ce7628f5d3bbf0806e0efdfa806fa746c178da66fb2a8d9a587ef0bab4c91774469f443f513972a0c59ae55278c32e1caf9c66d52e708e53ef2828c48f5c4b830d256c2ff1b155730588dfc9adeb +C.agg.G1.1=9503c392ceae7db1e2f247fb6148b4211708a74491989916daeec3c34bdd2803a98fc3a43976daaab00903211b1d1c46 +C.agg.sk.1=51542fee7895e4987de3b93ff52af9bb129dc076f0dcb8afe5d93460f2a6c1b7 +C.aggsec.legacy.2=0ca923fd169db16838c09804d7150f2bdde930d17040bc39c553baf9336527b15cbe83aa841b9f902a203521e7bc60220a9c9e1ddf0677564be73f7b8f9ce2a52c28c910eac2baba3ef3310fad7eaa8baf9465bfc9104f0ac08cd9da8b41b70e +C.versec.legacy.2=1 +C.aggsec.basic.2=a165590855562a1437e0d5fce7dfb1373a07fe09bdb33cf5f82b2e8d3b809ce7a8e9ae47eb0602181d474866958d51641816952a467643164dab9aa92567dac5449943f8464d0760740fcbb54bd758cc80e232032f56f3df269460d2cd7b807c +C.versec.basic.2=1 +C.versec.legacy.bad.2=0 +C.agg.G2.2=ab45f84e0c325239430f0584bf220bbabcff667d308d39c1fcd827f8c7f105e8210c20ca619ad9084984914e35fc0d1f082b5675dcfd07041f6ee1564de37b678a4b68ee51db8977bdc79f4ba1c9d49cccef35b1de0b7e8494c9cc5fa233edd0 +C.agg.G1.2=a5425f1689e33cd676a112efdd5aa80df7b137fad1db3c690bb2213745dd9a25c51d35fce39de1eaf5e268ccfdcb9163 +C.agg.sk.2=4e1643205fe0ed6f883f3d803c4742a2db0b7826aa523e5bc62a18c766d698df +C.aggsec.legacy.3=87b142eb28bb97ed9839900dbcefe90a992b4cd63468dd13d3dc8bcef394f0e77715f8da3fd62d3847ab845b2035a880193d116414b1a51a43edce8b2ccc4ee08f4492d35e19f9c35fe76cf73598afc085e62af9a6e52927c8f4d8544f9887f4 +C.versec.legacy.3=1 +C.aggsec.basic.3=8959bdf6c216c1c50eee30aa5ccd21196c058e3e28069cc70d86f4dc1608bbf9b791db866fb23ee816acd9b8ed3d3964174a16f05c9afc9cdc51790e8bf7a4ea0b4aef4645119a041ff97fa8500d6167c0db4743aba27f454853451f7229a287 +C.versec.basic.3=1 +C.versec.legacy.bad.3=0 +C.agg.G2.3=85b735e626a9322824cdb16d704db491330aa37239153a833c212f5404a1028f97d8339d437d7cdf06749330639c6ea21437d0bc3b3e6e1d411ed606e1943576c462abf6d572c9eccabdaec263073748421f84497f775a93631ccb51364f528f +C.agg.G1.3=b45111e7f20ff82bbfce790f2abeefebb885844423ed1fd37b43904b7b47454ff3c30ac47d4969c615af7316b1f41ffb +C.agg.sk.3=1d3b4ed79d0c0001f1bb2ded98523121bedbeaa37ac4fceb0f0bfdf4d8963849 +C.aggsec.legacy.10=0eab90239c026690d3ba0ac74c69f28420931128800ff1cfa7c64668600b99e7f60853e0f2d22b4d6cf07d97428cd0411256b05ad14e7ecae1372673d5c00db1880874016ea8a2ed6eb34655297e7883e6e023f28a6aa206e0fd0294bff532fa +C.versec.legacy.10=1 +C.aggsec.basic.10=a0368e7182619f7569d087c364199db4c5c20ba3e090706a3767ceb5dc054afe66fb4835b487eb17f67f36972b5e2d660c207b224abf7b30bb7db3bd16ebe0d1a87fac41370d82656af3e907293e954a884411765caf76708008ed2dd9b25622 +C.versec.basic.10=1 +C.versec.legacy.bad.10=0 +C.agg.G2.10=82974b5dafcc908dd00b725f120e9fa3ba1ec265019145a898b6ab3ddebb6f0b1a8c02827e04ee33dca6f098799ba76710b0cb5bf3b125ccd295abf5f3eca6fa272be6d727a591b32208b33618212368a15035b7e97edd2e29112e91bf61b651 +C.agg.G1.10=86689658c56d1d945a480cc1a11cb77ec19bce8fd3f8f6f5dbb1db20330aac73e78268a66e512b5ddd98fffc20bc7bbc +C.agg.sk.10=4972fe548df20e3ede53ebe27f0ab0c1bfe742903357d88d48301c6b7c9a77b6 +D.lagg=8acadc114967f7a21953644c19dc9ecbfdbdb0233d484862e2816ef3e6cc94177c85d26a3d8bc10a79ba7fced80226530f01ee9e0f441c83c8b50bf5e03be1f1dbfcc7d660d6d968c738693574f144dc1c5001a221bdf16d7127cb828e58003b +D.laggverify=1 +D.laggverify.bad=0 +E.mastersig=99a667d463e60f2e2b3feecb2a04061692faa66c543bd4eb36c5077794b2bfe24200aa1709fa72408a40a8dfe8a00d8c0d6d35dbce43924eba4354c109b6370a722f67bed82b4d1d984572d7817797477cd34aa415d20c996d573d5ed6043574 +E.masterverify=1 +E.skshare.0=2fe9aa3dc24ee2b902c2632305e5e9f9b667cb721239b1eeaec32775235696ce +E.pkshare.0=93ac3b88ca6f2a31eb5929c590692f415b3e9cb4dabb70bf9493a6858e1fe86d89ed2363f2098d0888e3fc601947fda0 +E.sharematch.0=1 +E.sigshare.poly.0=8c2810b9171817b12be33be0d8caa159785f05c30695aacba1cfac14bd4b6c4a6879ebc91a471c1605f608e2e223ce62044251375a33a8c918177fc950496fbfd4832d22f8ba8c4b391b74113703e82828d60eb468be93e150eee50bf0a0927e +E.sigshare.sign.0=8c2810b9171817b12be33be0d8caa159785f05c30695aacba1cfac14bd4b6c4a6879ebc91a471c1605f608e2e223ce62044251375a33a8c918177fc950496fbfd4832d22f8ba8c4b391b74113703e82828d60eb468be93e150eee50bf0a0927e +E.skshare.1=6d7a99964fe9909c9a713f88392b32af635db3daec83b4538c6fc3228ecdf513 +E.pkshare.1=8e333381aedd9b63aaf2e019e197e6983ca3749b8561e21485bc6b7a4bef92d0ecd50481bf95832d87d3b2bd37d3a141 +E.sharematch.1=1 +E.sigshare.poly.1=860e104d01a3d7c3af84995bdd1574c4292ea7e5373d22ccd590ac33acaa91d2f8d119fb2f4980ca4fee9ec66179f9f10f053bd123ec34abdd0e181d76bbb795459f65c1b1404904aa6d76593561b67b2c3f29d0e965533161a43e1683e4d1ea +E.sigshare.sign.1=860e104d01a3d7c3af84995bdd1574c4292ea7e5373d22ccd590ac33acaa91d2f8d119fb2f4980ca4fee9ec66179f9f10f053bd123ec34abdd0e181d76bbb795459f65c1b1404904aa6d76593561b67b2c3f29d0e965533161a43e1683e4d1ea +E.skshare.2=4a691d73ddb6e5236c82bab66d69ba08c340e25aad705836792c66a8b8b2391f +E.pkshare.2=83ad1776d2dfec1bde34672dd518bd59c3861e92f374fd34e11bfc454a29d7c92536bd0e4c48288ab704211f5053c1c5 +E.sharematch.2=1 +E.sigshare.poly.2=12e5310660dfc34e159a5910db2b2b517936acde9eadd3c954c572c3f7814a07a0350ca68f56cc4277fd9784d78182bd04588688bd1c842992e941f30939f2bc4325237ebf4b30a490473878636f72e7cca9036895141d01ccef721da90fa3ff +E.sigshare.sign.2=12e5310660dfc34e159a5910db2b2b517936acde9eadd3c954c572c3f7814a07a0350ca68f56cc4277fd9784d78182bd04588688bd1c842992e941f30939f2bc4325237ebf4b30a490473878636f72e7cca9036895141d01ccef721da90fa3ff +E.skshare.3=296fdf7a3c8e8d9a1d80009e1e54c95ce84bc381e63236e500729d4a6a5f0d0f +E.pkshare.3=893bbd2c6b4d595cdac30778e438a1b95d16eb1909b8bcc28148848507d07e98793d4c0368d328d45a5355df1f2253da +E.sharematch.3=1 +E.sigshare.poly.3=039b5d75dfad13ce4392deaa7d207a12e0a658dd5f34f66098453e60b07b38fbc7b3271d14697e6bfd56d6053a697237069259997fd43f322cb917f7fed360cbacbe2a8582358c954c5381cdc442f8323394cab23d4ce0c2745ca6e45aa99c8b +E.sigshare.sign.3=039b5d75dfad13ce4392deaa7d207a12e0a658dd5f34f66098453e60b07b38fbc7b3271d14697e6bfd56d6053a697237069259997fd43f322cb917f7fed360cbacbe2a8582358c954c5381cdc442f8323394cab23d4ce0c2745ca6e45aa99c8b +E.skshare.4=57230fd28ec31c1a4c4a5e378c6fa748d6e68772fe83d35477bb6539876fab15 +E.pkshare.4=91edd2ed20fa5ef43bf796785e0ca8ab1d6cdb4ae63aba67ffccc0f6911c1214f81a62e23175f46b767681cf92cb25f1 +E.sharematch.4=1 +E.sigshare.poly.4=97c77544f1db5118e955e892c45d1895724b77e99efd420615f54f4d4d5b7b57f668926fa45be02190d269a2354cfaf30d55b722c035e19354e593015ccf0bd71d2c7e4c35e4cfb951bd6ff5f88008014f877a44f5f9d95d01fd1b1e570a3b15 +E.sigshare.sign.4=97c77544f1db5118e955e892c45d1895724b77e99efd420615f54f4d4d5b7b57f668926fa45be02190d269a2354cfaf30d55b722c035e19354e593015ccf0bd71d2c7e4c35e4cfb951bd6ff5f88008014f877a44f5f9d95d01fd1b1e570a3b15 +E.skrecover=6c04e5af86f2ddeaf6d1d4f8bbd4a1217b29abd4517d4619dada7ec087ed6f6f +E.skrecover.match=1 +E.pkrecover=8d713f7f50fe5d3e2c0335c3d3c0ceb2a1689eb3c2a4436c3a11898b8b797818aae1316825542790d1b0b2cafffb9150 +E.sigrecover=99a667d463e60f2e2b3feecb2a04061692faa66c543bd4eb36c5077794b2bfe24200aa1709fa72408a40a8dfe8a00d8c0d6d35dbce43924eba4354c109b6370a722f67bed82b4d1d984572d7817797477cd34aa415d20c996d573d5ed6043574 +E.sigrecover.verify=1 +E.sigrecover.same=1 +F.esk=000000010000000000000000004c3b08d7413ef3f4d39922793c4b20c0bcfb26db531c9e32a505cf763c2794953757b1115e7110046606404b38e4654adc4c2a52a5337deca0794080d3f92921 +F.esk.pk.legacy=89efc5280e56a745dcfd4571d1e9b06edf0441c5fd8640f5efdf5554bcdcb07e7d1d35e09bf9ebaabe6faad282c838d4 +F.esk.pk.basic=a9efc5280e56a745dcfd4571d1e9b06edf0441c5fd8640f5efdf5554bcdcb07e7d1d35e09bf9ebaabe6faad282c838d4 +F.esk.chaincode=4c3b08d7413ef3f4d39922793c4b20c0bcfb26db531c9e32a505cf763c279495 +F.child.legacy=00000001023e497ad38000002aff185013e7118856e4bcb6e2dc9608cab5219747c8037a889789b1be76feb6df1250aa4f4cb5f7e58f7b5f942eb2f2b99b36eacb3e6e65c4766ce956e628e62a +F.child.legacy.sk=1250aa4f4cb5f7e58f7b5f942eb2f2b99b36eacb3e6e65c4766ce956e628e62a +F.child.basic=000000010203f3628b8000002a447c89f7c80822b8661513be9c7fdf172a91faf71300f68fa39cfdea0ae3740f625c4936e02f4abcee9cfbd59e403428b9937f94bd0908cf676c3f63bc7713e0 +F.child.basic.sk=625c4936e02f4abcee9cfbd59e403428b9937f94bd0908cf676c3f63bc7713e0 +F.epk.legacy=000000010000000000000000004c3b08d7413ef3f4d39922793c4b20c0bcfb26db531c9e32a505cf763c27949589efc5280e56a745dcfd4571d1e9b06edf0441c5fd8640f5efdf5554bcdcb07e7d1d35e09bf9ebaabe6faad282c838d4 +F.epk.basic=000000010000000000000000004c3b08d7413ef3f4d39922793c4b20c0bcfb26db531c9e32a505cf763c279495a9efc5280e56a745dcfd4571d1e9b06edf0441c5fd8640f5efdf5554bcdcb07e7d1d35e09bf9ebaabe6faad282c838d4 +F.epk.child.legacy=00000001010b9a9e8000000001d84919fa70508fefd47576f19b437b3bb2049039740d83de455742dae48c96ab8a9f848f28b295903845d5f860c9031899e4f1a6d092edacdaec28f64a7fd9b94679b3faaf0ecf6b09f70b1d3ed5555f +F.epk.child.basic=00000001010b9a9e80000000012428f63e5f4b2e25871336f34ecebbd6e0e648d8b4a02ec033b575a391dc6b598cf85b6e8d78a797985402debeb2a1b823ab7c98ae20ae1609aaadd70309a4d40ef5cad6a6f93cb9af0ec2045dba96cf +F.pubpriv.match.legacy=1 +F.esk.rt=000000010000000000000000004c3b08d7413ef3f4d39922793c4b20c0bcfb26db531c9e32a505cf763c2794953757b1115e7110046606404b38e4654adc4c2a52a5337deca0794080d3f92921 +F.epk.rt.legacy=000000010000000000000000004c3b08d7413ef3f4d39922793c4b20c0bcfb26db531c9e32a505cf763c27949589efc5280e56a745dcfd4571d1e9b06edf0441c5fd8640f5efdf5554bcdcb07e7d1d35e09bf9ebaabe6faad282c838d4 +G.inrange.mod0=57c1d1f8ef9ad067fef7d0056bdfec87f51c28b65dd56fa3cbcc0f1afc984725 +G.inrange.mod1=57c1d1f8ef9ad067fef7d0056bdfec87f51c28b65dd56fa3cbcc0f1afc984725 +G.big.mod1=1824b159acc5056f998c4fefecbc4ff55884b7fa0003480200000001fffffffd +G.big.mod0=EXC +G.order.mod1=0000000000000000000000000000000000000000000000000000000000000000 +G.order.mod0=73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001 +G.orderm1.mod0=73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000000 +G.zero.sk=0000000000000000000000000000000000000000000000000000000000000000 +G.zero.pk=c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +G.bip32seed=193afdb206c666de5cfba5d5a235477d269b1634ec36cfa1a3167cb47727bf25 +G.dh=a11d215631668626a3396afbfd38d850a2c18ffa90bd589714e40112b2592064c581eb8205fdc7bcd860e23b15e487cf +G.dh.sym=1 +H.g1.inf.basic.ser=c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +H.g1.inf.basic.valid=1 +H.g1.inf.legacy.ser=c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +H.g1.inf.legacy.valid=1 +H.g2.inf.basic.ser=c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +H.g2.inf.basic.valid=1 +H.g2.inf.legacy=EXC +H.g1.badinf.basic=EXC +H.g1.badinf.legacy=EXC +H.g2.badinf.basic=EXC +H.g2.badinf.legacy=EXC +H.g1.zeros.basic=EXC +H.g1.zeros.legacy.ser=000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +H.g1.zeros.legacy.valid=0 +H.g2.zeros.basic=EXC +H.g2.zeros.legacy.ser=000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +H.g2.zeros.legacy.valid=0 +H.g1.zeros.legacy.unchk.ser=000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +H.g1.zeros.legacy.unchk.valid=0 +H.g2.zeros.legacy.unchk.ser=000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +H.g2.zeros.legacy.unchk.valid=0 +H.g1.ff.basic=EXC +H.g1.ff.legacy=EXC +H.g2.ff.basic=EXC +H.g2.ff.legacy=EXC +H.g1.fflow.legacy.ser=000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +H.g1.fflow.legacy.valid=0 +H.g1.legacyAsBasic=EXC +H.g1.basicAsLegacy.ser=98138bb3b9cb34f03c9deac8e0928385873a8fe418a5f371f10cba0b6988a7854d0b48c1ffc50314bddea964b90b6be3 +H.g1.basicAsLegacy.valid=1 +H.g2.legacyAsBasic=EXC +H.g2.basicAsLegacy.ser=801627cb11cf0498af70b04e84ec07a615c01219b0693be59fb93e403f7937ddf26efe486c4b8edffdea8f136203b99e15240cfb56882628ef6d4b2cad852cbe23b882b2aab625f0e82f355ce1a4fe129b589d97ca3e17c5a36e514f93cfff32 +H.g2.basicAsLegacy.valid=0 +H.g1.negated.legacy.ser=98138bb3b9cb34f03c9deac8e0928385873a8fe418a5f371f10cba0b6988a7854d0b48c1ffc50314bddea964b90b6be3 +H.g1.negated.legacy.valid=1 +H.g1.negated.basic.ser=b8138bb3b9cb34f03c9deac8e0928385873a8fe418a5f371f10cba0b6988a7854d0b48c1ffc50314bddea964b90b6be3 +H.g1.negated.basic.valid=1 +H.g1.nonsub.legacy.ser=000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004 +H.g1.nonsub.legacy.valid=0 +H.g1.nonsub.legacy.unchk.ser=000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004 +H.g1.nonsub.legacy.unchk.valid=0 +H.g1.nonsub.basic=EXC +H.g1.nonsub.basic.unchk.ser=800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004 +H.g1.nonsub.basic.unchk.valid=0 +H.g2.nonsub.legacy.ser=000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +H.g2.nonsub.legacy.valid=0 +H.g2.nonsub.legacy.unchk.ser=000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +H.g2.nonsub.legacy.unchk.valid=0 +H.g2.nonsub.basic=EXC +H.g2.nonsub.basic.unchk=EXC +H.g1.nocurve.legacy.ser=000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 +H.g1.nocurve.legacy.valid=0 +H.g1.nocurve.basic=EXC +H.g2.flag48.basic=EXC +H.len47=EXC +H.g1.nocurve.sign.legacy.ser=800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 +H.g1.nocurve.sign.legacy.valid=0 +H.g1.overp.sign.legacy.ser=800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +H.g1.overp.sign.legacy.valid=0 +H.g2.x2.sign.legacy.ser=800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +H.g2.x2.sign.legacy.valid=0 +H.g2.x3.sign.legacy.ser=000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +H.g2.x3.sign.legacy.valid=0 +H.g2.x2.legacy.ser=000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +H.g2.x2.legacy.valid=0 +H.g2.overp.sign.legacy.ser=000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +H.g2.overp.sign.legacy.valid=0 +I.basic.verify.infinf=1 +I.legacy.verify.infinf=1 +I.basic.verify.infpk=0 +I.basic.verify.infsig=0 +I.aggver.empty.infsig=1 +I.aggver.empty.realsig=0 +I.aggver.mismatch=0 +I.versec.withinf=0 +# end diff --git a/src/dashbls/tools/fuzzgen.cpp b/src/dashbls/tools/fuzzgen.cpp new file mode 100644 index 000000000000..0652cc3ea5dc --- /dev/null +++ b/src/dashbls/tools/fuzzgen.cpp @@ -0,0 +1,158 @@ +// Differential fuzz driver for the relic -> blst migration. +// +// Uses only the public dashbls API; compile the same source against the old +// and new libraries, run with the same arguments, and diff the output. +// +// fuzzgen +// +// Covers: random byte-string decoding in every mode (the dominant +// consensus-facing attack surface), decode/re-encode round trips, and +// legacy + basic sign/verify/aggregate cycles on derived keys. + +#include +#include +#include +#include +#include + +#include + +using namespace bls; +using std::vector; + +// xorshift128+ so both builds see identical byte streams with no libc +// dependency +static uint64_t s0, s1; +static uint64_t rng() +{ + uint64_t x = s0; + const uint64_t y = s1; + s0 = y; + x ^= x << 23; + s1 = x ^ y ^ (x >> 17) ^ (y >> 26); + return s1 + y; +} + +static void fill(vector& v) +{ + for (size_t i = 0; i < v.size(); i += 8) { + const uint64_t r = rng(); + for (size_t j = 0; j < 8 && i + j < v.size(); j++) + v[i + j] = (uint8_t)(r >> (8 * j)); + } +} + +static void dump(const vector& v) +{ + for (auto b : v) printf("%02x", b); +} + +static void probeG1(const vector& in, bool fLegacy) +{ + try { + G1Element e = G1Element::FromBytes(Bytes(in), fLegacy); + dump(e.Serialize(fLegacy)); + printf(" v%d", (int)e.IsValid()); + } catch (const std::exception&) { + printf("EXC"); + } + printf(";"); +} + +static void probeG2(const vector& in, bool fLegacy) +{ + try { + G2Element e = G2Element::FromBytes(Bytes(in), fLegacy); + dump(e.Serialize(fLegacy)); + printf(" v%d", (int)e.IsValid()); + } catch (const std::exception&) { + printf("EXC"); + } + printf(";"); +} + +int main(int argc, char** argv) +{ + if (argc != 3) { + fprintf(stderr, "usage: fuzzgen \n"); + return 2; + } + s0 = strtoull(argv[1], nullptr, 0) * 0x9E3779B97F4A7C15ULL + 1; + s1 = s0 ^ 0xD1B54A32D192ED03ULL; + const long iters = strtol(argv[2], nullptr, 0); + + LegacySchemeMPL legacy; + BasicSchemeMPL basic; + + for (long i = 0; i < iters; i++) { + printf("i%ld: ", i); + + // 1. random decodes: fully random, and "plausible" (top bits biased + // into the interesting flag space) + vector b48(48), b96(96); + fill(b48); + fill(b96); + switch (i % 4) { + case 0: break; + case 1: b48[0] &= 0x1f; b96[0] &= 0x1f; break; // no flags + case 2: b48[0] |= 0x80; b96[0] |= 0x80; break; // sign/compress + case 3: b48[0] = (uint8_t)(rng() & 0xe0); b96[0] = b48[0]; break; + } + probeG1(b48, false); + probeG1(b48, true); + probeG2(b96, false); + probeG2(b96, true); + + // 2. valid-point cross-mode round trips + vector seed(32); + fill(seed); + PrivateKey sk = basic.KeyGen(seed); + G1Element pk = sk.GetG1Element(); + probeG1(pk.Serialize(true), true); + probeG1(pk.Serialize(false), true); // modern bytes into legacy codec + + // 3. legacy + basic signing over a random 32-byte hash + vector h(32); + fill(h); + G2Element lsig = legacy.Sign(sk, Bytes(h)); + dump(lsig.Serialize(true)); + printf(" %d", (int)legacy.Verify(pk, Bytes(h), lsig)); + printf(";"); + G2Element bsig = basic.Sign(sk, Bytes(h)); + dump(bsig.Serialize(false)); + printf(" %d", (int)basic.Verify(pk, Bytes(h), bsig)); + printf(";"); + + // 4. secure aggregation with 3 keys + vector sks; + vector pks; + vector lsigs; + for (int k = 0; k < 3; k++) { + vector s2(32); + fill(s2); + sks.push_back(basic.KeyGen(s2)); + pks.push_back(sks.back().GetG1Element()); + lsigs.push_back(legacy.Sign(sks.back(), Bytes(h))); + } + G2Element agg = legacy.AggregateSecure(pks, lsigs, Bytes(h)); + dump(agg.Serialize(true)); + printf(" %d", (int)legacy.VerifySecure(pks, agg, Bytes(h))); + printf(";"); + + // 5. threshold 2-of-3 recovery + vector ids; + vector> idStore(3, vector(32)); + for (auto& id : idStore) fill(id); + PrivateKey sh0 = Threshold::PrivateKeyShare({sks[0], sks[1]}, Bytes(idStore[0])); + PrivateKey sh1 = Threshold::PrivateKeyShare({sks[0], sks[1]}, Bytes(idStore[1])); + try { + PrivateKey rec = Threshold::PrivateKeyRecover( + {sh0, sh1}, {Bytes(idStore[0]), Bytes(idStore[1])}); + dump(rec.Serialize()); + } catch (const std::exception&) { + printf("EXC"); + } + printf("\n"); + } + return 0; +} diff --git a/src/dashbls/tools/vectorgen.cpp b/src/dashbls/tools/vectorgen.cpp new file mode 100644 index 000000000000..ff38ae4a5211 --- /dev/null +++ b/src/dashbls/tools/vectorgen.cpp @@ -0,0 +1,22 @@ +// Regenerates test-vectors/reference.txt. +// +// Build against the library whose behavior is to become the reference (the +// checked-in file was produced by the relic-based implementation) and +// redirect the output: +// +// ./build/src/vectorgen > test-vectors/reference.txt +// +// runtest compares the current library against the file; this tool only +// generates data. + +#include + +#include "test-vectors.hpp" + +int main() +{ + for (const std::string& line : bls_test_vectors::GenerateReferenceVectors()) { + printf("%s\n", line.c_str()); + } + return 0; +} From 34204020a99a05cca045114a0d0c071a5de236c7 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Mon, 14 Sep 2026 00:49:38 +0700 Subject: [PATCH 3/7] build: compile dashbls with Dash's autotools, blst from depends src/dashbls is no longer a configure sub-project. Its library, the vendored mimalloc secure allocator and its Catch2 test binary are built by the new src/Makefile.dashbls.include as libtool convenience libraries, the same way crc32c and leveldb are, and dashbls/runtest (including the relic reference vectors) is part of `make check`. The BLS12-381 backend blst is detected by configure and linked from depends (or the system). The library's PrivateKey::Serialize no longer takes a scheme flag, so CBLSWrapper dispatches on the implementation type; the secure allocator pool is sized for the largest blst object; the relic macro workarounds in bls/bls.h are gone. --- configure.ac | 7 ++- contrib/guix/libexec/build.sh | 2 +- src/Makefile.am | 13 ++-- src/Makefile.dashbls.include | 111 ++++++++++++++++++++++++++++++++++ src/bls/bls.cpp | 2 +- src/bls/bls.h | 18 +++--- 6 files changed, 135 insertions(+), 18 deletions(-) create mode 100644 src/Makefile.dashbls.include diff --git a/configure.ac b/configure.ac index 55b98d06336d..03cdc4abd598 100644 --- a/configure.ac +++ b/configure.ac @@ -1705,6 +1705,10 @@ AC_CHECK_LIB([gmp], [__gmpz_init],GMP_LIBS=-lgmp, AC_MSG_ERROR(libgmp missing)) CPPFLAGS="$TEMP_CPPFLAGS" LDFLAGS="$TEMP_LDFLAGS" +dnl blst (BLS12-381 backend of src/dashbls), provided by depends or the system +AC_CHECK_HEADER([blst.h],, AC_MSG_ERROR([blst headers missing])) +AC_CHECK_LIB([blst], [blst_p1_compress], [BLST_LIBS=-lblst], AC_MSG_ERROR([libblst missing])) + AM_CONDITIONAL([ENABLE_ZMQ], [test "$use_zmq" = "yes"]) dnl libmultiprocess library check @@ -2041,6 +2045,7 @@ AC_SUBST(BACKTRACE_FLAGS) AC_SUBST(BACKTRACE_LDFLAGS) AC_SUBST(BACKTRACE_LIBS) AC_SUBST(GMP_LIBS) +AC_SUBST(BLST_LIBS) AC_SUBST(NATPMP_CPPFLAGS) AC_SUBST(NATPMP_LIBS) AC_SUBST(DSYMUTIL_FLAT) @@ -2081,7 +2086,7 @@ fi dnl The ECDH module is required by the wallet's Platform key provider dnl (DashPay contact request encryption, wallet/platformkeys.cpp). ac_configure_args="${ac_configure_args} --disable-shared --with-pic --enable-benchmark=no --enable-module-recovery --enable-module-ecdh --disable-openssl-tests" -AC_CONFIG_SUBDIRS([src/dashbls src/secp256k1]) +AC_CONFIG_SUBDIRS([src/secp256k1]) AC_OUTPUT diff --git a/contrib/guix/libexec/build.sh b/contrib/guix/libexec/build.sh index 0c9fda7ad11d..942bc0cabd5c 100755 --- a/contrib/guix/libexec/build.sh +++ b/contrib/guix/libexec/build.sh @@ -270,7 +270,7 @@ mkdir -p "$DISTSRC" ${HOST_CXXFLAGS:+CXXFLAGS="${HOST_CXXFLAGS}"} \ ${HOST_LDFLAGS:+LDFLAGS="${HOST_LDFLAGS}"} - sed -i.old 's/-lstdc++ //g' {./,src/dashbls/,src/secp256k1/}{config.status,libtool} + sed -i.old 's/-lstdc++ //g' {./,src/secp256k1/}{config.status,libtool} # Build Dash Core diff --git a/src/Makefile.am b/src/Makefile.am index c5b08a2e17f7..3aa2a26768f6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -46,7 +46,7 @@ endif # ENABLE_CRASH_HOOKS endif # ENABLE_STACKTRACES BITCOIN_INCLUDES=-I$(builddir) -I$(srcdir)/$(MINISKETCH_INCLUDE_DIR_INT) -I$(srcdir)/secp256k1/include -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT) $(LEVELDB_CPPFLAGS) -BITCOIN_INCLUDES+=-isystem$(srcdir)/dashbls/include -isystem$(srcdir)/dashbls/depends/relic/include -isystem$(srcdir)/dashbls/depends/minialloc/include +BITCOIN_INCLUDES+=$(DASHBLS_CPPFLAGS) BITCOIN_INCLUDES+=-isystem$(srcdir)/immer LIBBITCOIN_NODE=libbitcoin_node.a @@ -56,7 +56,6 @@ LIBBITCOIN_CLI=libbitcoin_cli.a LIBBITCOIN_UTIL=libbitcoin_util.a LIBBITCOIN_CRYPTO_BASE=crypto/libbitcoin_crypto_base.la LIBBITCOINQT=qt/libbitcoinqt.a -LIBDASHBLS=dashbls/libdashbls.la LIBSECP256K1=secp256k1/libsecp256k1.la if ENABLE_ZMQ @@ -110,9 +109,6 @@ LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_ARM_SHANI) endif noinst_LTLIBRARIES += $(LIBBITCOIN_CRYPTO) -$(LIBDASHBLS): - $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) - $(LIBSECP256K1): $(wildcard secp256k1/src/*.h) $(wildcard secp256k1/src/*.c) $(wildcard secp256k1/include/*) $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F) @@ -1224,7 +1220,7 @@ lib_LTLIBRARIES += $(LIBBITCOINKERNEL) libdashkernel_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS) $(PTHREAD_FLAGS) libdashkernel_la_LIBADD = $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) $(LIBSECP256K1) $(LIBDASHBLS) $(GMP_LIBS) -libdashkernel_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL -isystem$(srcdir)/dashbls/include -isystem$(srcdir)/dashbls/depends/relic/include -isystem$(srcdir)/dashbls/depends/minialloc/include -isystem$(srcdir)/immer $(BOOST_CPPFLAGS) $(LEVELDB_CPPFLAGS) -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT) +libdashkernel_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL $(DASHBLS_CPPFLAGS) -isystem$(srcdir)/immer $(BOOST_CPPFLAGS) $(LEVELDB_CPPFLAGS) -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT) # libdashkernel requires default symbol visibility, explicitly specify that # here so that things still work even when user configures with @@ -1410,7 +1406,7 @@ libdashconsensus_la_SOURCES = support/cleanse.cpp $(crypto_libbitcoin_crypto_bas libdashconsensus_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS) libdashconsensus_la_LIBADD = $(LIBDASHBLS) $(LIBSECP256K1) $(GMP_LIBS) libdashconsensus_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL -DDISABLE_OPTIMIZED_SHA256 -libdashconsensus_la_CPPFLAGS += -isystem$(srcdir)/dashbls/include -isystem$(srcdir)/dashbls/depends/relic/include -isystem$(srcdir)/dashbls/depends/minialloc/include +libdashconsensus_la_CPPFLAGS += $(DASHBLS_CPPFLAGS) libdashconsensus_la_CPPFLAGS += -isystem$(srcdir)/immer libdashconsensus_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) @@ -1443,6 +1439,7 @@ CLEANFILES += util/*.gcda util/*.gcno CLEANFILES += wallet/*.gcda wallet/*.gcno CLEANFILES += wallet/test/*.gcda wallet/test/*.gcno CLEANFILES += zmq/*.gcda zmq/*.gcno +CLEANFILES += dashbls/src/*.gcda dashbls/src/*.gcno dashbls/depends/mimalloc/src/*.gcda dashbls/depends/mimalloc/src/*.gcno CLEANFILES += obj/build.h IMMER_DIST = immer/immer @@ -1462,7 +1459,6 @@ $(top_srcdir)/$(subdir)/config/bitcoin-config.h.in: $(am__configure_deps) clean-local: - -$(MAKE) -C dashbls clean -$(MAKE) -C secp256k1 clean -rm -f leveldb/*/*.gcda leveldb/*/*.gcno leveldb/helpers/memenv/*.gcda leveldb/helpers/memenv/*.gcno -rm -f config.h @@ -1539,6 +1535,7 @@ include Makefile.minisketch.include include Makefile.crc32c.include include Makefile.leveldb.include +include Makefile.dashbls.include include Makefile.test_util.include include Makefile.test_fuzz.include diff --git a/src/Makefile.dashbls.include b/src/Makefile.dashbls.include new file mode 100644 index 000000000000..33ebfe6db9d6 --- /dev/null +++ b/src/Makefile.dashbls.include @@ -0,0 +1,111 @@ +# Copyright (c) 2026 The Dash Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +LIBDASHBLS_INT = dashbls/libdashbls.la +LIBMIMALLOC_INT = dashbls/libmimalloc-secure.la + +noinst_LTLIBRARIES += $(LIBDASHBLS_INT) +noinst_LTLIBRARIES += $(LIBMIMALLOC_INT) + +# What consumers link, dependents first: dashbls -> mimalloc -> blst (from depends) +LIBDASHBLS = $(LIBDASHBLS_INT) $(LIBMIMALLOC_INT) $(BLST_LIBS) + +# Flags for consumers of the library +DASHBLS_CPPFLAGS = -isystem$(srcdir)/dashbls/include + +# Flags used only when building the library itself. Its headers are treated +# as system headers, as they are for consumers, so that Dash's warning set +# (-Werror in CI) does not apply to the vendored code. +DASHBLS_CPPFLAGS_INT = +DASHBLS_CPPFLAGS_INT += -isystem$(srcdir)/dashbls/include/dashbls +DASHBLS_CPPFLAGS_INT += -isystem$(srcdir)/dashbls/depends/mimalloc/include +DASHBLS_CPPFLAGS_INT += -DBLSALLOC_MIMALLOC=1 + +MIMALLOC_CPPFLAGS_INT = +MIMALLOC_CPPFLAGS_INT += -I$(srcdir)/dashbls/depends/mimalloc/include +MIMALLOC_CPPFLAGS_INT += -I$(srcdir)/dashbls/depends/mimalloc/src +MIMALLOC_CPPFLAGS_INT += -DMI_SECURE=4 +MIMALLOC_CPPFLAGS_INT += -DNDEBUG + +DASHBLS_H = \ + dashbls/include/dashbls/bls.hpp \ + dashbls/include/dashbls/chaincode.hpp \ + dashbls/include/dashbls/elements.hpp \ + dashbls/include/dashbls/extendedprivatekey.hpp \ + dashbls/include/dashbls/extendedpublickey.hpp \ + dashbls/include/dashbls/hdkeys.hpp \ + dashbls/include/dashbls/hkdf.hpp \ + dashbls/include/dashbls/legacy.hpp \ + dashbls/include/dashbls/privatekey.hpp \ + dashbls/include/dashbls/schemes.hpp \ + dashbls/include/dashbls/test-utils.hpp \ + dashbls/include/dashbls/threshold.hpp \ + dashbls/include/dashbls/util.hpp + +dashbls_libdashbls_la_SOURCES = \ + $(DASHBLS_H) \ + dashbls/src/bls.cpp \ + dashbls/src/chaincode.cpp \ + dashbls/src/elements.cpp \ + dashbls/src/extendedprivatekey.cpp \ + dashbls/src/extendedpublickey.cpp \ + dashbls/src/legacy.cpp \ + dashbls/src/privatekey.cpp \ + dashbls/src/schemes.cpp \ + dashbls/src/threshold.cpp + +dashbls_libdashbls_la_CPPFLAGS = $(AM_CPPFLAGS) $(DASHBLS_CPPFLAGS_INT) + +# Specify -static in both CXXFLAGS and LDFLAGS so libtool will only build a +# static version of this library (same as crc32c and leveldb). +dashbls_libdashbls_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -static +dashbls_libdashbls_la_LDFLAGS = $(AM_LDFLAGS) -static + +MIMALLOC_H = \ + dashbls/depends/mimalloc/include/mimalloc-new-delete.h \ + dashbls/depends/mimalloc/include/mimalloc-override.h \ + dashbls/depends/mimalloc/include/mimalloc-stats.h \ + dashbls/depends/mimalloc/include/mimalloc.h \ + dashbls/depends/mimalloc/src/bitmap.h + +dashbls_libmimalloc_secure_la_SOURCES = \ + $(MIMALLOC_H) \ + dashbls/depends/mimalloc/src/alloc-aligned.c \ + dashbls/depends/mimalloc/src/alloc-posix.c \ + dashbls/depends/mimalloc/src/alloc.c \ + dashbls/depends/mimalloc/src/arena-meta.c \ + dashbls/depends/mimalloc/src/arena.c \ + dashbls/depends/mimalloc/src/bitmap.c \ + dashbls/depends/mimalloc/src/heap.c \ + dashbls/depends/mimalloc/src/init.c \ + dashbls/depends/mimalloc/src/libc.c \ + dashbls/depends/mimalloc/src/options.c \ + dashbls/depends/mimalloc/src/os.c \ + dashbls/depends/mimalloc/src/page-map.c \ + dashbls/depends/mimalloc/src/page.c \ + dashbls/depends/mimalloc/src/random.c \ + dashbls/depends/mimalloc/src/stats.c \ + dashbls/depends/mimalloc/src/prim/prim.c + +dashbls_libmimalloc_secure_la_CPPFLAGS = $(AM_CPPFLAGS) $(MIMALLOC_CPPFLAGS_INT) +dashbls_libmimalloc_secure_la_CFLAGS = $(AM_CFLAGS) $(PIE_FLAGS) -static +dashbls_libmimalloc_secure_la_LDFLAGS = $(AM_LDFLAGS) -static + +if ENABLE_TESTS +if !ENABLE_FUZZ +DASHBLS_RUNTEST = dashbls/runtest +TESTS += $(DASHBLS_RUNTEST) +check_PROGRAMS += $(DASHBLS_RUNTEST) + +dashbls_runtest_SOURCES = \ + dashbls/src/test.cpp \ + dashbls/src/test-vectors.hpp \ + dashbls/depends/catch2/include/catch2/catch.hpp +dashbls_runtest_CPPFLAGS = $(AM_CPPFLAGS) $(DASHBLS_CPPFLAGS_INT) -isystem$(srcdir)/dashbls/depends/catch2/include +dashbls_runtest_CPPFLAGS += -DDASHBLS_REFERENCE_VECTORS=\"$(abs_srcdir)/dashbls/test-vectors/reference.txt\" +dashbls_runtest_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) +dashbls_runtest_LDADD = $(LIBDASHBLS) +dashbls_runtest_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS) -static +endif +endif diff --git a/src/bls/bls.cpp b/src/bls/bls.cpp index 8d5b1b83703c..7d8ceefcccef 100644 --- a/src/bls/bls.cpp +++ b/src/bls/bls.cpp @@ -401,7 +401,7 @@ static void create_secure_allocator() // static variable in function scope ensures it's initialized when first accessed // and destroyed before LockedPoolManager - static mt_pooled_secure_allocator a(sizeof(bn_t) + sizeof(size_t)); + static mt_pooled_secure_allocator a(sizeof(blst_p2) + sizeof(size_t)); secure_allocator_instance = &a; } diff --git a/src/bls/bls.h b/src/bls/bls.h index ae2124cd38e1..9e6d57ec27c7 100644 --- a/src/bls/bls.h +++ b/src/bls/bls.h @@ -10,21 +10,17 @@ #include #include -// bls-dash uses relic, which may define DEBUG and ERROR, which leads to many warnings in some build setups -#undef ERROR -#undef DEBUG #include #include #include #include #include -#undef DOUBLE -#undef SEED #include #include #include #include +#include namespace bls { extern std::atomic bls_legacy_scheme; @@ -127,7 +123,11 @@ class CBLSWrapper if (!fValid) { return std::vector(SerSize, 0); } - return impl.Serialize(specificLegacyScheme); + if constexpr (std::is_same_v) { + return impl.Serialize(); + } else { + return impl.Serialize(specificLegacyScheme); + } } std::array ToBytes(const bool specificLegacyScheme) const @@ -135,7 +135,11 @@ class CBLSWrapper if (!fValid) { return std::array{}; } - return impl.SerializeToArray(specificLegacyScheme); + if constexpr (std::is_same_v) { + return impl.SerializeToArray(); + } else { + return impl.SerializeToArray(specificLegacyScheme); + } } const uint256& GetHash() const From 34cd38ba2bc89475d93123a002a951c997e30cfa Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Mon, 14 Sep 2026 00:51:02 +0700 Subject: [PATCH 4/7] depends: drop GMP GMP was only needed by relic, the previous backend of src/dashbls. Remove the depends package and its patch, the configure checks and the GMP_LIBS link entries, and the build documentation that told users to install it. --- configure.ac | 23 - depends/packages/gmp.mk | 33 - depends/packages/packages.mk | 2 +- .../gmp/include_ldflags_in_configure.patch | 621 ------------------ doc/build-freebsd.md | 6 - doc/build-netbsd.md | 2 +- doc/build-openbsd.md | 2 +- doc/build-osx.md | 2 +- doc/build-unix.md | 12 - doc/dependencies.md | 6 - src/Makefile.am | 13 +- src/Makefile.bench.include | 1 - src/Makefile.qt.include | 2 +- src/Makefile.qttest.include | 2 +- src/Makefile.test.include | 3 +- 15 files changed, 13 insertions(+), 717 deletions(-) delete mode 100644 depends/packages/gmp.mk delete mode 100644 depends/patches/gmp/include_ldflags_in_configure.patch diff --git a/configure.ac b/configure.ac index 03cdc4abd598..62383d5faf89 100644 --- a/configure.ac +++ b/configure.ac @@ -883,18 +883,6 @@ case $host in export PKG_CONFIG_PATH="$($BREW --prefix qt@5 2>/dev/null)/lib/pkgconfig:$PKG_CONFIG_PATH" fi - gmp_prefix=$($BREW --prefix gmp 2>/dev/null) - if test "$gmp_prefix" != ""; then - if test "$suppress_external_warnings" != "no"; then - GMP_CPPFLAGS="-isystem $gmp_prefix/include" - else - GMP_CPPFLAGS="-I$gmp_prefix/include" - fi - GMP_LDFLAGS="-L$gmp_prefix/lib" - CORE_CPPFLAGS="$CORE_CPPFLAGS $GMP_CPPFLAGS" - CORE_LDFLAGS="$CORE_LDFLAGS $GMP_LDFLAGS" - fi - case $host in *aarch64*) dnl The preferred Homebrew prefix for Apple Silicon is /opt/homebrew. @@ -1695,16 +1683,6 @@ if test "$use_zmq" = "yes"; then esac fi -dnl check if libgmp is present -TEMP_CPPFLAGS="$CPPFLAGS" -TEMP_LDFLAGS="$LDFLAGS" -CPPFLAGS="$CPPFLAGS $GMP_CPPFLAGS" -LDFLAGS="$LDFLAGS $GMP_LDFLAGS" -AC_CHECK_HEADER([gmp.h],, AC_MSG_ERROR(libgmp headers missing)) -AC_CHECK_LIB([gmp], [__gmpz_init],GMP_LIBS=-lgmp, AC_MSG_ERROR(libgmp missing)) -CPPFLAGS="$TEMP_CPPFLAGS" -LDFLAGS="$TEMP_LDFLAGS" - dnl blst (BLS12-381 backend of src/dashbls), provided by depends or the system AC_CHECK_HEADER([blst.h],, AC_MSG_ERROR([blst headers missing])) AC_CHECK_LIB([blst], [blst_p1_compress], [BLST_LIBS=-lblst], AC_MSG_ERROR([libblst missing])) @@ -2044,7 +2022,6 @@ AC_SUBST(MINIUPNPC_LIBS) AC_SUBST(BACKTRACE_FLAGS) AC_SUBST(BACKTRACE_LDFLAGS) AC_SUBST(BACKTRACE_LIBS) -AC_SUBST(GMP_LIBS) AC_SUBST(BLST_LIBS) AC_SUBST(NATPMP_CPPFLAGS) AC_SUBST(NATPMP_LIBS) diff --git a/depends/packages/gmp.mk b/depends/packages/gmp.mk deleted file mode 100644 index 03ec302caede..000000000000 --- a/depends/packages/gmp.mk +++ /dev/null @@ -1,33 +0,0 @@ -package=gmp -$(package)_version=6.3.0 -$(package)_download_path=https://ftp.gnu.org/gnu/gmp -$(package)_file_name=gmp-$($(package)_version).tar.gz -$(package)_sha256_hash=e56fd59d76810932a0555aa15a14b61c16bed66110d3c75cc2ac49ddaa9ab24c -$(package)_patches=include_ldflags_in_configure.patch - -define $(package)_set_vars -$(package)_config_opts += --disable-shared --enable-cxx --enable-fat -$(package)_cflags_aarch64 += -march=armv8-a -$(package)_cflags_armv7l += -march=armv7-a -$(package)_cflags_x86_64 += -march=x86-64 -endef - -define $(package)_preprocess_cmds - patch -p1 < $($(package)_patch_dir)/include_ldflags_in_configure.patch -endef - -define $(package)_config_cmds - $($(package)_autoconf) -endef - -define $(package)_build_cmds - $(MAKE) -endef - -define $(package)_stage_cmds - $(MAKE) DESTDIR=$($(package)_staging_dir) install -endef - -define $(package)_postprocess_cmds - rm lib/*.la -endef diff --git a/depends/packages/packages.mk b/depends/packages/packages.mk index 91b14a370e98..ec5fcbab8f78 100644 --- a/depends/packages/packages.mk +++ b/depends/packages/packages.mk @@ -1,4 +1,4 @@ -packages:=gmp backtrace blst +packages:=backtrace blst boost_packages = boost diff --git a/depends/patches/gmp/include_ldflags_in_configure.patch b/depends/patches/gmp/include_ldflags_in_configure.patch deleted file mode 100644 index 8ddc304da0ec..000000000000 --- a/depends/patches/gmp/include_ldflags_in_configure.patch +++ /dev/null @@ -1,621 +0,0 @@ -Use LDFLAGS when configure is compiling test programs. - -Needed for macOS cross-compilation support using lld (ld64.lld) as -a linker, done by including '-fuse-ld=lld' in LDFLAGS. Defining it -in CC or CXX will result in unused argument warnings if the compiler -isn't expected to link files. - -diff --git a/acinclude.m4 b/acinclude.m4 -index 9cf9483..99edd43 100644 ---- a/acinclude.m4 -+++ b/acinclude.m4 -@@ -1752,7 +1752,7 @@ AC_CACHE_CHECK([if globals are prefixed by underscore], - cat >conftest.c <conftest.out - if grep "[[ ]]_gurkmacka" conftest.out >/dev/null; then -@@ -1984,7 +1984,7 @@ const int foo[[]] = {1,2,3}; - EOF - echo "Test program:" >&AC_FD_CC - cat conftest.c >&AC_FD_CC --gmp_compile="$CC $CFLAGS $CPPFLAGS -S conftest.c >&AC_FD_CC" -+gmp_compile="$CC $CFLAGS $CPPFLAGS $LDFLAGS -S conftest.c >&AC_FD_CC" - if AC_TRY_EVAL(gmp_compile); then - echo "Compiler output:" >&AC_FD_CC - cat conftest.s >&AC_FD_CC -@@ -2382,7 +2382,7 @@ for tmp_underscore in "" "_"; do - ${tmp_gsym_prefix}main$gmp_cv_asm_label_suffix - addl $ ${tmp_underscore}_GLOBAL_OFFSET_TABLE_, %ebx - EOF -- gmp_compile="$CCAS $CFLAGS $CPPFLAGS $lt_prog_compiler_pic conftest.s >&AC_FD_CC && $CC $CFLAGS $CPPFLAGS $lt_prog_compiler_pic conftest.$OBJEXT >&AC_FD_CC" -+ gmp_compile="$CCAS $CFLAGS $CPPFLAGS $LDFLAGS $lt_prog_compiler_pic conftest.s >&AC_FD_CC && $CC $CFLAGS $CPPFLAGS $LDFLAGS $lt_prog_compiler_pic conftest.$OBJEXT >&AC_FD_CC" - if AC_TRY_EVAL(gmp_compile); then - if test "$tmp_underscore" = "_"; then - gmp_cv_asm_x86_got_underscore=yes -@@ -3019,7 +3019,7 @@ int *bar() { return &foo; } - EOF - echo "Test program:" >&AC_FD_CC - cat conftest.c >&AC_FD_CC --gmp_compile="$CC $CFLAGS $CPPFLAGS -S conftest.c >&AC_FD_CC" -+gmp_compile="$CC $CFLAGS $CPPFLAGS $LDFLAGS -S conftest.c >&AC_FD_CC" - if AC_TRY_EVAL(gmp_compile); then - echo "Compiler output:" >&AC_FD_CC - cat conftest.s >&AC_FD_CC -@@ -3164,7 +3164,7 @@ AC_DEFUN([GMP_C_ATTRIBUTE_MALLOC], - [cat >conftest.c </dev/null; then - gmp_cv_c_attribute_malloc=no -@@ -3279,7 +3279,7 @@ int main(){ - return 0; - }] - EOF --gmp_compile="$CC $CFLAGS $CPPFLAGS conftest.c -o conftest$EXEEXT >&AC_FD_CC 2>&1" -+gmp_compile="$CC $CFLAGS $CPPFLAGS $LDFLAGS conftest.c -o conftest$EXEEXT >&AC_FD_CC 2>&1" - if AC_TRY_EVAL(gmp_compile); then - cat >conftest.awk <<\EOF - [ -diff --git a/configure b/configure -index 7910aa0..15121e2 100755 ---- a/configure -+++ b/configure -@@ -5885,7 +5885,7 @@ for abi in $abilist; do - choke me - #endif - EOF --gmp_compile="$cc -c conftest.c >&5" -+gmp_compile="$cc $LDFLAGS -c conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -5978,7 +5978,7 @@ if test "$gmp_prog_cc_works" = yes; then - int main () { return 0; } - EOF - echo "Test compile: " >&5 -- gmp_compile="$cc $cflags $cppflags conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -6032,7 +6032,7 @@ void *f() { return g(); } - int main () { return 0; } - EOF - echo "Test compile: function pointer return" >&5 -- gmp_compile="$cc $cflags $cppflags conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -6088,7 +6088,7 @@ int cmov () { return (n >= 0 ? n : 0); } - int main () { return 0; } - EOF - echo "Test compile: cmov instruction" >&5 -- gmp_compile="$cc $cflags $cppflags conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -6145,7 +6145,7 @@ unsigned long gcc303 () { return (unsigned long) d; } - int main () { return 0; } - EOF - echo "Test compile: double -> ulong conversion" >&5 -- gmp_compile="$cc $cflags $cppflags conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -6200,7 +6200,7 @@ unsigned long fneg () { return -fneg_data; } - int main () { return 0; } - EOF - echo "Test compile: double negation" >&5 -- gmp_compile="$cc $cflags $cppflags conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -6256,7 +6256,7 @@ float ftod () { return (float) ftod_data; } - int main () { return 0; } - EOF - echo "Test compile: double -> float conversion" >&5 -- gmp_compile="$cc $cflags $cppflags conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -6341,7 +6341,7 @@ param_init () - int main () { return 0; } - EOF - echo "Test compile: gnupro alpha ev6 char spilling" >&5 -- gmp_compile="$cc $cflags $cppflags conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -6392,7 +6392,7 @@ if test "$gmp_prog_cc_works" = yes; then - int k; int foo () { __builtin_alloca (k); } - EOF - echo "Test compile: __builtin_alloca availability" >&5 -- gmp_compile="$cc $cflags $cppflags conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -6438,7 +6438,7 @@ int foo () - int main () { return 0; } - EOF - echo "Test compile: alloca array" >&5 -- gmp_compile="$cc $cflags $cppflags conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -6516,7 +6516,7 @@ int f () - int main () { return 0; } - EOF - echo "Test compile: abs int -> double conversion" >&5 -- gmp_compile="$cc $cflags $cppflags conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -6581,7 +6581,7 @@ int dummy; - int main () { return 0; } - EOF - echo "Test compile: long long reliability test 1" >&5 -- gmp_compile="$cc $cflags $cppflags conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -6642,7 +6642,7 @@ int dummy; - int main () { return 0; } - EOF - echo "Test compile: long long reliability test 2" >&5 -- gmp_compile="$cc $cflags $cppflags conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -6703,7 +6703,7 @@ int dummy; - int main () { return 0; } - EOF - echo "Test compile: freebsd hacked gcc" >&5 -- gmp_compile="$cc $cflags $cppflags conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -6802,7 +6802,7 @@ main () - - EOF - echo "Test compile: mpn_lshift_com optimization" >&5 -- gmp_compile="$cc $cflags $cppflags conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -6911,7 +6911,7 @@ main () - - EOF - echo "Test compile: mpn_lshift_com optimization 2" >&5 -- gmp_compile="$cc $cflags $cppflags conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -6970,7 +6970,7 @@ int foo; - int bar () { return foo; } - EOF - tmp_got_emitted=no --gmp_compile="$cc $cflags $cppflags -fPIC -S conftest.c >&5 2>&1" -+gmp_compile="$cc $cflags $cppflags $LDFLAGS -fPIC -S conftest.c >&5 2>&1" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -7044,7 +7044,7 @@ cat >conftest.s <<\EOF - .byte 254, 220, 186, 152, 118, 84, 50, 16 - EOF - tmp_got_good=yes --gmp_compile="$cc $cflags $cppflags -fPIC -o conftest.o -c conftest.s >&5 2>&1" -+gmp_compile="$cc $cflags $cppflags $LDFLAGS -fPIC -o conftest.o -c conftest.s >&5 2>&1" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -7094,7 +7094,7 @@ long long bar () { return foo; } - int main () { return 0; } - EOF - gmp_prog_cc_works=no --gmp_compile="$cc $cflags $cppflags -c conftest.c >&5" -+gmp_compile="$cc $cflags $cppflags $LDFLAGS -c conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -7221,7 +7221,7 @@ result=no - cat >conftest.s <&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -7256,7 +7256,7 @@ main () - } - EOF - gmp_c_testlist_sizeof=no --gmp_compile="$cc $cflags -c conftest.c >&5" -+gmp_compile="$cc $cflags $LDFLAGS -c conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -7424,7 +7424,7 @@ _main: - xorl %eax, %eax - ret - EOF -- gmp_compile="$cc $cflags $cppflags conftest.s -o conftest >&5" -+ gmp_compile="$cc $cflags $cppflags $LDFLAGS conftest.s -o conftest >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -7489,7 +7489,7 @@ $as_echo_n "checking compiler $cc $cflags -no-cpp-precomp... " >&6; } - cat >conftest.c <&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -7522,7 +7522,7 @@ result=no - cat >conftest.c <&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -7553,7 +7553,7 @@ result=no - cat >conftest.c <&5 --gmp_compile="$cc $cflags $cppflags -c conftest.c >&5 2>&1" -+gmp_compile="$cc $cflags $cppflags $LDFLAGS -c conftest.c >&5 2>&1" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -7561,7 +7561,7 @@ if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - test $ac_status = 0; }; then : ; - else - # empty fails -- gmp_compile="$cc $cflags $cppflags -Wa,-oldas -c conftest.c >&5 2>&1" -+ gmp_compile="$cc $cflags $cppflags $LDFLAGS -Wa,-oldas -c conftest.c >&5 2>&1" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -7597,7 +7597,7 @@ if test "$gmp_prog_cc_works" = yes; then - int main () { return 0; } - EOF - echo "Test compile: " >&5 -- gmp_compile="$cc $cflags $cppflags $flag conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $flag $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -7651,7 +7651,7 @@ void *f() { return g(); } - int main () { return 0; } - EOF - echo "Test compile: function pointer return" >&5 -- gmp_compile="$cc $cflags $cppflags $flag conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $flag $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -7707,7 +7707,7 @@ int cmov () { return (n >= 0 ? n : 0); } - int main () { return 0; } - EOF - echo "Test compile: cmov instruction" >&5 -- gmp_compile="$cc $cflags $cppflags $flag conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $flag $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -7764,7 +7764,7 @@ unsigned long gcc303 () { return (unsigned long) d; } - int main () { return 0; } - EOF - echo "Test compile: double -> ulong conversion" >&5 -- gmp_compile="$cc $cflags $cppflags $flag conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $flag $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -7819,7 +7819,7 @@ unsigned long fneg () { return -fneg_data; } - int main () { return 0; } - EOF - echo "Test compile: double negation" >&5 -- gmp_compile="$cc $cflags $cppflags $flag conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $flag $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -7875,7 +7875,7 @@ float ftod () { return (float) ftod_data; } - int main () { return 0; } - EOF - echo "Test compile: double -> float conversion" >&5 -- gmp_compile="$cc $cflags $cppflags $flag conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $flag $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -7960,7 +7960,7 @@ param_init () - int main () { return 0; } - EOF - echo "Test compile: gnupro alpha ev6 char spilling" >&5 -- gmp_compile="$cc $cflags $cppflags $flag conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $flag $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -8011,7 +8011,7 @@ if test "$gmp_prog_cc_works" = yes; then - int k; int foo () { __builtin_alloca (k); } - EOF - echo "Test compile: __builtin_alloca availability" >&5 -- gmp_compile="$cc $cflags $cppflags $flag conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $flag $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -8057,7 +8057,7 @@ int foo () - int main () { return 0; } - EOF - echo "Test compile: alloca array" >&5 -- gmp_compile="$cc $cflags $cppflags $flag conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $flag $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -8135,7 +8135,7 @@ int f () - int main () { return 0; } - EOF - echo "Test compile: abs int -> double conversion" >&5 -- gmp_compile="$cc $cflags $cppflags $flag conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $flag $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -8200,7 +8200,7 @@ int dummy; - int main () { return 0; } - EOF - echo "Test compile: long long reliability test 1" >&5 -- gmp_compile="$cc $cflags $cppflags $flag conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $flag $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -8261,7 +8261,7 @@ int dummy; - int main () { return 0; } - EOF - echo "Test compile: long long reliability test 2" >&5 -- gmp_compile="$cc $cflags $cppflags $flag conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $flag $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -8322,7 +8322,7 @@ int dummy; - int main () { return 0; } - EOF - echo "Test compile: freebsd hacked gcc" >&5 -- gmp_compile="$cc $cflags $cppflags $flag conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $flag $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -8421,7 +8421,7 @@ main () - - EOF - echo "Test compile: mpn_lshift_com optimization" >&5 -- gmp_compile="$cc $cflags $cppflags $flag conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $flag $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -8530,7 +8530,7 @@ main () - - EOF - echo "Test compile: mpn_lshift_com optimization 2" >&5 -- gmp_compile="$cc $cflags $cppflags $flag conftest.c >&5" -+ gmp_compile="$cc $cflags $cppflags $flag $LDFLAGS conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -8589,7 +8589,7 @@ int foo; - int bar () { return foo; } - EOF - tmp_got_emitted=no --gmp_compile="$cc $cflags $cppflags $flag -fPIC -S conftest.c >&5 2>&1" -+gmp_compile="$cc $cflags $cppflags $flag $LDFLAGS -fPIC -S conftest.c >&5 2>&1" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -8663,7 +8663,7 @@ cat >conftest.s <<\EOF - .byte 254, 220, 186, 152, 118, 84, 50, 16 - EOF - tmp_got_good=yes --gmp_compile="$cc $cflags $cppflags $flag -fPIC -o conftest.o -c conftest.s >&5 2>&1" -+gmp_compile="$cc $cflags $cppflags $flag $LDFLAGS -fPIC -o conftest.o -c conftest.s >&5 2>&1" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -9974,7 +9974,7 @@ main () - return 0; - } - EOF --gmp_compile="$HOST_CC conftest.c" -+gmp_compile="$HOST_CC $LDFLAGS conftest.c" - cc_for_build_works=no - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 -@@ -10027,7 +10027,7 @@ else - fi - - else -- for i in "$CC" "$CC $CFLAGS $CPPFLAGS" cc gcc c89 c99; do -+ for i in "$CC" "$CC $CFLAGS $CPPFLAGS $LDFLAGS" cc gcc c89 c99; do - { $as_echo "$as_me:${as_lineno-$LINENO}: checking build system compiler $i" >&5 - $as_echo_n "checking build system compiler $i... " >&6; } - # remove anything that might look like compiler output to our "||" expression -@@ -10080,7 +10080,7 @@ else - #define FOO BAR - EOF - echo "Test compile: " >&5 -- gmp_cxxcompile="$CXX $CPPFLAGS $CXXFLAGS conftest.cc >&5" -+ gmp_cxxcompile="$CXX $CPPFLAGS $CXXFLAGS $LDFLAGS conftest.cc >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_cxxcompile\""; } >&5 - (eval $gmp_cxxcompile) 2>&5 - ac_status=$? -@@ -10570,7 +10570,7 @@ using namespace foo; - int main (void) { return 0; } - EOF - echo "Test compile: namespace" >&5 -- gmp_cxxcompile="$CXX $CPPFLAGS $CXXFLAGS conftest.cc >&5" -+ gmp_cxxcompile="$CXX $CPPFLAGS $CXXFLAGS $LDFLAGS conftest.cc >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_cxxcompile\""; } >&5 - (eval $gmp_cxxcompile) 2>&5 - ac_status=$? -@@ -10616,7 +10616,7 @@ void someoutput (void) { std::cout << 123; } - int main (void) { return 0; } - EOF - echo "Test compile: std iostream" >&5 -- gmp_cxxcompile="$CXX $CPPFLAGS $CXXFLAGS conftest.cc >&5" -+ gmp_cxxcompile="$CXX $CPPFLAGS $CXXFLAGS $LDFLAGS conftest.cc >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_cxxcompile\""; } >&5 - (eval $gmp_cxxcompile) 2>&5 - ac_status=$? -@@ -23651,7 +23651,7 @@ else - cat >conftest.c <&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -24421,7 +24421,7 @@ int main(){ - return 0; - } - EOF --gmp_compile="$CC $CFLAGS $CPPFLAGS conftest.c -o conftest$EXEEXT >&5 2>&1" -+gmp_compile="$CC $CFLAGS $CPPFLAGS $LDFLAGS conftest.c -o conftest$EXEEXT >&5 2>&1" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -25833,7 +25833,7 @@ else - cat >conftest.c <&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -25914,7 +25914,7 @@ const int foo[] = {1,2,3}; - EOF - echo "Test program:" >&5 - cat conftest.c >&5 --gmp_compile="$CC $CFLAGS $CPPFLAGS -S conftest.c >&5" -+gmp_compile="$CC $CFLAGS $CPPFLAGS $LDFLAGS -S conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -26580,7 +26580,7 @@ int *bar() { return &foo; } - EOF - echo "Test program:" >&5 - cat conftest.c >&5 --gmp_compile="$CC $CFLAGS $CPPFLAGS -S conftest.c >&5" -+gmp_compile="$CC $CFLAGS $CPPFLAGS $LDFLAGS -S conftest.c >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -@@ -27031,7 +27031,7 @@ for tmp_underscore in "" "_"; do - ${tmp_gsym_prefix}main$gmp_cv_asm_label_suffix - addl $ ${tmp_underscore}_GLOBAL_OFFSET_TABLE_, %ebx - EOF -- gmp_compile="$CCAS $CFLAGS $CPPFLAGS $lt_prog_compiler_pic conftest.s >&5 && $CC $CFLAGS $CPPFLAGS $lt_prog_compiler_pic conftest.$OBJEXT >&5" -+ gmp_compile="$CCAS $CFLAGS $CPPFLAGS $LDFLAGS $lt_prog_compiler_pic conftest.s >&5 && $CC $CFLAGS $CPPFLAGS $LDFLAGS $lt_prog_compiler_pic conftest.$OBJEXT >&5" - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5 - (eval $gmp_compile) 2>&5 - ac_status=$? -diff --git a/configure.ac b/configure.ac -index 082077b..f43e1c1 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -2272,14 +2272,14 @@ for abi in $abilist; do - instrument) cflags="$cflags -finstrument-functions" ;; - esac - -- GMP_PROG_CC_WORKS($cc $cflags $cppflags,,continue) -+ GMP_PROG_CC_WORKS($cc $cflags $cppflags $LDFLAGS,,continue) - - # If we're supposed to be using a "long long" for a limb, check that - # it works. - eval limb_chosen=\"\$limb$abi1\" - test -n "$limb_chosen" || eval limb_chosen=\"\$limb$abi2\" - if test "$limb_chosen" = longlong; then -- GMP_PROG_CC_WORKS_LONGLONG($cc $cflags $cppflags,,continue) -+ GMP_PROG_CC_WORKS_LONGLONG($cc $cflags $cppflags $LDFLAGS,,continue) - fi - - # The tests to perform on this $cc, if any -@@ -2294,8 +2294,8 @@ for abi in $abilist; do - hpc-hppa-2-0) GMP_HPC_HPPA_2_0($cc,,testlist_pass=no) ;; - gcc-arm-umodsi) GMP_GCC_ARM_UMODSI($cc,,testlist_pass=no) ;; - gcc-mips-o32) GMP_GCC_MIPS_O32($cc,,testlist_pass=no) ;; -- hppa-level-2.0) GMP_HPPA_LEVEL_20($cc $cflags,,testlist_pass=no) ;; -- sizeof*) GMP_C_TEST_SIZEOF($cc $cflags,$tst,,testlist_pass=no) ;; -+ hppa-level-2.0) GMP_HPPA_LEVEL_20($cc $cflags $LDFLAGS,,testlist_pass=no) ;; -+ sizeof*) GMP_C_TEST_SIZEOF($cc $cflags $LDFLAGS,$tst,,testlist_pass=no) ;; - esac - if test $testlist_pass = no; then break; fi - done -@@ -2415,8 +2415,8 @@ if test $found_compiler = yes; then - # pentium4 case. - # - if test "$abi" = 32; then -- GMP_GCC_PENTIUM4_SSE2($cc $cflags $cppflags,, continue) -- GMP_OS_X86_XMM($cc $cflags $cppflags,, continue) -+ GMP_GCC_PENTIUM4_SSE2($cc $cflags $cppflags $LDFLAGS,, continue) -+ GMP_OS_X86_XMM($cc $cflags $cppflags $LDFLAGS,, continue) - fi - ;; - -no-cpp-precomp) -@@ -2429,19 +2429,19 @@ if test $found_compiler = yes; then - -Wa,-m*) - case $host in - alpha*-*-*) -- GMP_GCC_WA_MCPU($cc $cflags, $flag, , [continue]) -+ GMP_GCC_WA_MCPU($cc $cflags $LDFLAGS, $flag, , [continue]) - ;; - esac - ;; - -Wa,-oldas) -- GMP_GCC_WA_OLDAS($cc $cflags $cppflags, -+ GMP_GCC_WA_OLDAS($cc $cflags $cppflags $LDFLAGS, - [cflags="$cflags $flag" - break], - [continue]) - ;; - esac - -- GMP_PROG_CC_WORKS($cc $cflags $cppflags $flag, -+ GMP_PROG_CC_WORKS($cc $cflags $cppflags $flag $LDFLAGS, - [cflags="$cflags $flag" - break]) - done diff --git a/doc/build-freebsd.md b/doc/build-freebsd.md index d33629b551c8..ebe27d8d2ecb 100644 --- a/doc/build-freebsd.md +++ b/doc/build-freebsd.md @@ -24,12 +24,6 @@ git clone https://github.com/dashpay/dash.git ### 3. Install Optional Dependencies -###### GMP - -```bash -pkg install gmp -``` - It is not necessary to build wallet functionality to run either `dashd` or `dash-qt`. ###### Descriptor Wallet Support diff --git a/doc/build-netbsd.md b/doc/build-netbsd.md index 86f72e1096e4..780a048e2f1a 100644 --- a/doc/build-netbsd.md +++ b/doc/build-netbsd.md @@ -14,7 +14,7 @@ Install the required dependencies the usual way you [install software on NetBSD] The example commands below use `pkgin`. ```bash -pkgin install autoconf automake libtool pkg-config git gmake boost libevent gmp +pkgin install autoconf automake libtool pkg-config git gmake boost libevent ``` diff --git a/doc/build-openbsd.md b/doc/build-openbsd.md index 8b0ee196eb46..f6a371b9cc7e 100644 --- a/doc/build-openbsd.md +++ b/doc/build-openbsd.md @@ -10,7 +10,7 @@ This guide describes how to build dashd, command-line utilities, and GUI on Open Run the following as root to install the base dependencies for building. ```bash -pkg_add bash git gmake gmp libevent libtool boost +pkg_add bash git gmake libevent libtool boost # Select the newest version of the following packages: pkg_add autoconf automake python diff --git a/doc/build-osx.md b/doc/build-osx.md index 87914d09affc..e5e955f683c0 100644 --- a/doc/build-osx.md +++ b/doc/build-osx.md @@ -47,7 +47,7 @@ To install, run the following from your terminal: See [dependencies.md](dependencies.md) for a complete overview. ``` bash -brew install automake libtool boost gmp pkg-config libevent +brew install automake libtool boost pkg-config libevent ``` ### 4. Clone Dash repository diff --git a/doc/build-unix.md b/doc/build-unix.md index 419df8488ab1..01f1ef64bc7b 100644 --- a/doc/build-unix.md +++ b/doc/build-unix.md @@ -76,12 +76,6 @@ ZMQ dependencies (provides ZMQ API): sudo apt-get install libzmq3-dev ``` -GMP dependencies (provides platform-optimized routines): - -```sh -sudo apt-get install libgmp-dev -``` - User-Space, Statically Defined Tracing (USDT) dependencies: ```sh @@ -165,12 +159,6 @@ ZMQ dependencies (provides ZMQ API): sudo dnf install zeromq-devel ``` -GMP dependencies (provides platform-optimized routines): - -```sh -sudo dnf install gmp-devel -``` - User-Space, Statically Defined Tracing (USDT) dependencies: ```sh diff --git a/doc/dependencies.md b/doc/dependencies.md index 2fb9e671ed7c..40e06fe819ae 100644 --- a/doc/dependencies.md +++ b/doc/dependencies.md @@ -25,10 +25,6 @@ You can find installation instructions in the `build-*.md` file for your platfor ## Optional -| Dependency | Releases | Version used | Minimum required | Runtime | -| --- | --- | --- | --- | --- | -| libgmp | [link](https://gmplib.org/download/gmp/)[ \* ](#note1) | 6.3.0 | [6.2.0](https://github.com/dashpay/bls-signatures/pull/92) | No | - ### GUI | Dependency | Releases | Version used | Minimum required | Runtime | | --- | --- | --- | --- | --- | @@ -53,5 +49,3 @@ You can find installation instructions in the `build-*.md` file for your platfor | --- | --- | --- | --- | --- | | [Berkeley DB](../depends/packages/bdb.mk) (legacy wallet) | [link](https://www.oracle.com/technetwork/database/database-technologies/berkeleydb/downloads/index.html) | 4.8.30 | 4.8.x | No | | [SQLite](../depends/packages/sqlite.mk) | [link](https://sqlite.org) | 3.38.5 | [3.7.17](https://github.com/bitcoin/bitcoin/pull/19077) | No | - -Note \* : The minimum supported version on macOS is 6.3.0 diff --git a/src/Makefile.am b/src/Makefile.am index 3aa2a26768f6..d758c7ede38d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1099,7 +1099,7 @@ bitcoin_bin_ldadd = \ $(LIBMEMENV) \ $(LIBSECP256K1) -bitcoin_bin_ldadd += $(BACKTRACE_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(SQLITE_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(ZMQ_LIBS) $(GMP_LIBS) +bitcoin_bin_ldadd += $(BACKTRACE_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(SQLITE_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(ZMQ_LIBS) dashd_SOURCES = $(bitcoin_daemon_sources) init/bitcoind.cpp dashd_CPPFLAGS = $(bitcoin_bin_cppflags) @@ -1129,7 +1129,7 @@ dash_cli_LDADD = \ $(LIBBITCOIN_COMMON) \ $(LIBBITCOIN_UTIL) \ $(LIBBITCOIN_CRYPTO) -dash_cli_LDADD += $(BACKTRACE_LIBS) $(EVENT_LIBS) $(GMP_LIBS) +dash_cli_LDADD += $(BACKTRACE_LIBS) $(EVENT_LIBS) # # dash-tx binary # @@ -1151,7 +1151,7 @@ dash_tx_LDADD = \ $(LIBDASHBLS) \ $(LIBSECP256K1) -dash_tx_LDADD += $(BACKTRACE_LIBS) $(GMP_LIBS) +dash_tx_LDADD += $(BACKTRACE_LIBS) # # dash-wallet binary # @@ -1173,8 +1173,7 @@ dash_wallet_LDADD = \ $(BACKTRACE_LIBS) \ $(BOOST_LIBS) \ $(BDB_LIBS) \ - $(SQLITE_LIBS) \ - $(GMP_LIBS) + $(SQLITE_LIBS) if TARGET_WINDOWS dash_wallet_SOURCES += dash-wallet-res.rc @@ -1219,7 +1218,7 @@ if BUILD_BITCOIN_KERNEL_LIB lib_LTLIBRARIES += $(LIBBITCOINKERNEL) libdashkernel_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS) $(PTHREAD_FLAGS) -libdashkernel_la_LIBADD = $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) $(LIBSECP256K1) $(LIBDASHBLS) $(GMP_LIBS) +libdashkernel_la_LIBADD = $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) $(LIBSECP256K1) $(LIBDASHBLS) libdashkernel_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL $(DASHBLS_CPPFLAGS) -isystem$(srcdir)/immer $(BOOST_CPPFLAGS) $(LEVELDB_CPPFLAGS) -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT) # libdashkernel requires default symbol visibility, explicitly specify that @@ -1404,7 +1403,7 @@ include_HEADERS = script/bitcoinconsensus.h libdashconsensus_la_SOURCES = support/cleanse.cpp $(crypto_libbitcoin_crypto_base_la_SOURCES) $(crypto_libbitcoin_crypto_sph_la_SOURCES) $(libbitcoin_consensus_a_SOURCES) libdashconsensus_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS) -libdashconsensus_la_LIBADD = $(LIBDASHBLS) $(LIBSECP256K1) $(GMP_LIBS) +libdashconsensus_la_LIBADD = $(LIBDASHBLS) $(LIBSECP256K1) libdashconsensus_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL -DDISABLE_OPTIMIZED_SHA256 libdashconsensus_la_CPPFLAGS += $(DASHBLS_CPPFLAGS) libdashconsensus_la_CPPFLAGS += -isystem$(srcdir)/immer diff --git a/src/Makefile.bench.include b/src/Makefile.bench.include index ff20b71822bc..466ade4baa45 100644 --- a/src/Makefile.bench.include +++ b/src/Makefile.bench.include @@ -83,7 +83,6 @@ bench_bench_dash_LDADD = \ $(EVENT_LIBS) \ $(MINIUPNPC_LIBS) \ $(NATPMP_LIBS) \ - $(GMP_LIBS) \ $(BACKTRACE_LIBS) if ENABLE_ZMQ diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 56ddd8a12156..312ba83ffd91 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -475,7 +475,7 @@ bitcoin_qt_ldadd += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS) endif bitcoin_qt_ldadd += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBDASHBLS) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \ $(BACKTRACE_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(SQLITE_LIBS) $(LIBSECP256K1) \ - $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(GMP_LIBS) + $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) bitcoin_qt_ldflags = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS) bitcoin_qt_libtoolflags = $(AM_LIBTOOLFLAGS) --tag CXX diff --git a/src/Makefile.qttest.include b/src/Makefile.qttest.include index 00401c6340d7..819de3fe112e 100644 --- a/src/Makefile.qttest.include +++ b/src/Makefile.qttest.include @@ -70,7 +70,7 @@ endif qt_test_test_dash_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBDASHBLS) $(LIBUNIVALUE) $(LIBLEVELDB) \ $(LIBMEMENV) $(BACKTRACE_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) \ $(QR_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(SQLITE_LIBS) $(LIBSECP256K1) \ - $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(GMP_LIBS) + $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) qt_test_test_dash_qt_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS) qt_test_test_dash_qt_CXXFLAGS = $(AM_CXXFLAGS) $(QT_PIE_FLAGS) diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 63635c7daa66..58fd216761c3 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -59,7 +59,6 @@ FUZZ_SUITE_LD_COMMON = \ $(MINISKETCH_LIBS) \ $(EVENT_LIBS) \ $(EVENT_PTHREADS_LIBS) \ - $(GMP_LIBS) \ $(BACKTRACE_LIBS) if USE_UPNP @@ -276,7 +275,7 @@ test_test_dash_LDADD += $(LIBBITCOIN_NODE) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON $(LIBDASHBLS) $(LIBLEVELDB) $(LIBMEMENV) $(BACKTRACE_LIBS) $(LIBSECP256K1) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS) $(MINISKETCH_LIBS) test_test_dash_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -test_test_dash_LDADD += $(BDB_LIBS) $(MINIUPNPC_LIBS) $(SQLITE_LIBS) $(NATPMP_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(GMP_LIBS) +test_test_dash_LDADD += $(BDB_LIBS) $(MINIUPNPC_LIBS) $(SQLITE_LIBS) $(NATPMP_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) test_test_dash_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS) -static if ENABLE_ZMQ From cfd06b0ea4a38521b614227fbd8998e2257563af Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Mon, 14 Sep 2026 00:51:53 +0700 Subject: [PATCH 5/7] dashbls: remove relic, bindings and standalone build files Everything that only served the standalone library build or the relic backend goes: the relic tree, the CMake and autotools files, the Go/Rust/JS/Python bindings and their helper scripts, the relic differential fuzzer and the library benchmark. What stays is what Dash Core builds and tests: the library sources and headers, the Catch2 test with its relic reference vectors (plus the generator that produced them), mimalloc, LICENSE, NOTICE and README. NOTICE now lists blst instead of relic, GMP and pybind11, and contrib/debian/copyright gains entries for dashbls and mimalloc. --- .gitignore | 1 + contrib/debian/copyright | 11 + .../.github/scripts/build_simple_index.py | 104 - src/dashbls/.github/workflows/binds-go.yml | 56 - src/dashbls/.github/workflows/binds-js.yml | 94 - src/dashbls/.github/workflows/binds-py.yml | 155 - src/dashbls/.github/workflows/binds-rs.yml | 49 - src/dashbls/.github/workflows/build-binds.yml | 42 - src/dashbls/.github/workflows/build-docs.yml | 51 - src/dashbls/.github/workflows/build-test.yaml | 71 - src/dashbls/.github/workflows/stale-issue.yml | 35 - src/dashbls/.gitignore | 173 - src/dashbls/.python-version | 1 - src/dashbls/.vscode/extensions.json | 7 - src/dashbls/.vscode/settings.json | 8 - src/dashbls/CMakeLists.txt | 104 - src/dashbls/MANIFEST.in | 44 - src/dashbls/Makefile.am | 39 - src/dashbls/Makefile.bench.include | 22 - src/dashbls/Makefile.bls.include | 66 - src/dashbls/Makefile.mimalloc.include | 46 - src/dashbls/Makefile.relic.include | 470 - src/dashbls/Makefile.test.include | 28 - src/dashbls/NOTICE | 85 +- src/dashbls/README.md | 6 + src/dashbls/apple.rust.deps.sh | 374 - src/dashbls/autogen.sh | 13 - src/dashbls/binds/python/CMakeLists.txt | 24 - src/dashbls/binds/python/conftest.py | 15 - src/dashbls/binds/python/pythonbindings.cpp | 759 -- .../python/samples/aggregate_signatures.py | 44 - .../samples/creating_keys_and_signatures.py | 36 - src/dashbls/binds/python/samples/hd_keys.py | 42 - .../python/samples/loading_from_bytes.py | 41 - .../python/samples/proof_of_possession.py | 58 - .../python/samples/serializing_to_bytes.py | 36 - .../binds/python/samples/tree_aggregates.py | 51 - src/dashbls/binds/python/test_bench.py | 75 - src/dashbls/binds/python/test_unit.py | 440 - .../build-aux/m4/ax_check_compile_flag.m4 | 53 - .../build-aux/m4/ax_check_link_flag.m4 | 53 - .../build-aux/m4/ax_cxx_compile_stdcxx.m4 | 1005 --- src/dashbls/build-aux/m4/ax_pthread.m4 | 522 -- src/dashbls/cmake_modules/BrewHelper.cmake | 21 - src/dashbls/cmake_modules/Findsodium.cmake | 294 - src/dashbls/configure.ac | 913 -- src/dashbls/depends/catch2/CMakeLists.txt | 37 - src/dashbls/depends/relic/.editorconfig | 7 - .../depends/relic/.github/workflows/16bit.yml | 48 - .../depends/relic/.github/workflows/32bit.yml | 97 - .../depends/relic/.github/workflows/8bit.yml | 48 - .../relic/.github/workflows/bls12-381.yml | 91 - .../depends/relic/.github/workflows/easy.yml | 97 - .../relic/.github/workflows/gmp-sec.yml | 88 - .../depends/relic/.github/workflows/gmp.yml | 88 - src/dashbls/depends/relic/.gitignore | 31 - src/dashbls/depends/relic/.indent.pro | 64 - src/dashbls/depends/relic/.travis.yml | 33 - src/dashbls/depends/relic/CMakeLists.txt | 339 - src/dashbls/depends/relic/COPYRIGHT | 11 - src/dashbls/depends/relic/LICENSE | 1 - src/dashbls/depends/relic/LICENSE.Apache-2.0 | 202 - src/dashbls/depends/relic/LICENSE.LGPL-2.1 | 520 -- src/dashbls/depends/relic/README.md | 66 - src/dashbls/depends/relic/art/rlc_logo.png | Bin 6322 -> 0 bytes src/dashbls/depends/relic/art/rlc_logo.svg | 1694 ---- .../depends/relic/bench/CMakeLists.txt | 80 - src/dashbls/depends/relic/bench/bench_bn.c | 943 -- src/dashbls/depends/relic/bench/bench_cp.c | 1809 ---- src/dashbls/depends/relic/bench/bench_dv.c | 111 - src/dashbls/depends/relic/bench/bench_eb.c | 660 -- src/dashbls/depends/relic/bench/bench_ec.c | 317 - src/dashbls/depends/relic/bench/bench_ed.c | 679 -- src/dashbls/depends/relic/bench/bench_ep.c | 651 -- src/dashbls/depends/relic/bench/bench_epx.c | 1108 --- src/dashbls/depends/relic/bench/bench_err.c | 76 - src/dashbls/depends/relic/bench/bench_fb.c | 569 -- src/dashbls/depends/relic/bench/bench_fbx.c | 165 - src/dashbls/depends/relic/bench/bench_fp.c | 632 -- src/dashbls/depends/relic/bench/bench_fpx.c | 3340 ------- src/dashbls/depends/relic/bench/bench_md.c | 63 - src/dashbls/depends/relic/bench/bench_mpc.c | 311 - src/dashbls/depends/relic/bench/bench_pc.c | 802 -- src/dashbls/depends/relic/bench/bench_pp.c | 794 -- src/dashbls/depends/relic/bench/bench_rand.c | 109 - src/dashbls/depends/relic/cmake/arch.cmake | 52 - src/dashbls/depends/relic/cmake/bn.cmake | 75 - src/dashbls/depends/relic/cmake/cp.cmake | 16 - src/dashbls/depends/relic/cmake/doxygen.cmake | 39 - src/dashbls/depends/relic/cmake/eb.cmake | 64 - src/dashbls/depends/relic/cmake/ec.cmake | 23 - src/dashbls/depends/relic/cmake/ed.cmake | 58 - src/dashbls/depends/relic/cmake/ep.cmake | 68 - src/dashbls/depends/relic/cmake/err.cmake | 9 - src/dashbls/depends/relic/cmake/fb.cmake | 99 - src/dashbls/depends/relic/cmake/fiat.cmake | 39 - src/dashbls/depends/relic/cmake/fp.cmake | 81 - src/dashbls/depends/relic/cmake/fpx.cmake | 29 - src/dashbls/depends/relic/cmake/gmp.cmake | 56 - src/dashbls/depends/relic/cmake/ios.cmake | 443 - src/dashbls/depends/relic/cmake/md.cmake | 21 - src/dashbls/depends/relic/cmake/pp.cmake | 25 - src/dashbls/depends/relic/cmake/rand.cmake | 29 - .../depends/relic/cmake/relic-config.cmake | 10 - src/dashbls/depends/relic/cmake/with.cmake | 130 - .../depends/relic/demo/cert-input/Makefile | 13 - .../relic/demo/cert-input/test-bench.c | 471 - .../depends/relic/demo/ers-etrs/Makefile | 13 - .../depends/relic/demo/ers-etrs/test-bench.c | 226 - .../relic/demo/general-paillier/Makefile | 13 - .../relic/demo/general-paillier/test.c | 92 - .../depends/relic/demo/link-test/Makefile | 17 - .../depends/relic/demo/link-test/test.c | 4 - .../depends/relic/demo/link-test/test1.c | 37 - .../depends/relic/demo/link-test/test2.c | 37 - .../depends/relic/demo/public-stats/Makefile | 20 - .../depends/relic/demo/public-stats/csv.c | 153 - .../depends/relic/demo/public-stats/csv.h | 12 - .../depends/relic/demo/public-stats/main.c | 349 - .../depends/relic/demo/tweedledum/Makefile | 13 - .../depends/relic/demo/tweedledum/main.c | 88 - .../depends/relic/doc/relic.doxygen.in | 2309 ----- .../depends/relic/include/low/relic_bn_low.h | 285 - .../depends/relic/include/low/relic_dv_low.h | 82 - .../depends/relic/include/low/relic_fb_low.h | 270 - .../depends/relic/include/low/relic_fp_low.h | 326 - .../depends/relic/include/low/relic_fpx_low.h | 390 - src/dashbls/depends/relic/include/relic.h | 106 - .../depends/relic/include/relic_alloc.h | 91 - .../depends/relic/include/relic_arch.h | 111 - src/dashbls/depends/relic/include/relic_bc.h | 84 - .../depends/relic/include/relic_bench.h | 219 - src/dashbls/depends/relic/include/relic_bn.h | 1391 --- .../depends/relic/include/relic_conf.h.in | 717 -- .../depends/relic/include/relic_core.h | 482 - src/dashbls/depends/relic/include/relic_cp.h | 2356 ----- src/dashbls/depends/relic/include/relic_dv.h | 247 - src/dashbls/depends/relic/include/relic_eb.h | 950 -- src/dashbls/depends/relic/include/relic_ec.h | 463 - src/dashbls/depends/relic/include/relic_ed.h | 910 -- src/dashbls/depends/relic/include/relic_ep.h | 1250 --- src/dashbls/depends/relic/include/relic_epx.h | 1819 ---- src/dashbls/depends/relic/include/relic_err.h | 353 - src/dashbls/depends/relic/include/relic_fb.h | 988 -- src/dashbls/depends/relic/include/relic_fbx.h | 204 - src/dashbls/depends/relic/include/relic_fp.h | 1089 --- src/dashbls/depends/relic/include/relic_fpx.h | 4703 ---------- .../depends/relic/include/relic_label.h | 2720 ------ src/dashbls/depends/relic/include/relic_md.h | 274 - src/dashbls/depends/relic/include/relic_mpc.h | 387 - .../depends/relic/include/relic_multi.h | 82 - src/dashbls/depends/relic/include/relic_pc.h | 1031 --- src/dashbls/depends/relic/include/relic_pp.h | 1027 --- .../depends/relic/include/relic_rand.h | 128 - .../depends/relic/include/relic_test.h | 104 - .../depends/relic/include/relic_types.h | 211 - .../depends/relic/include/relic_util.h | 310 - .../depends/relic/preset/ardue-pbc-bn254.sh | 3 - .../depends/relic/preset/arm-pbc-bn254.sh | 3 - .../relic/preset/armdroid-pbc-bn254.sh | 13 - .../depends/relic/preset/armduino-ecc-128k.sh | 3 - .../depends/relic/preset/armega-pbc-bn254.sh | 3 - .../depends/relic/preset/armios-pbc-bn254.sh | 12 - .../depends/relic/preset/avr-ecc-80k-sim.sh | 2 - .../depends/relic/preset/avr-ecc-80k.sh | 2 - .../depends/relic/preset/avr-pbc-80.sh | 2 - .../relic/preset/curve2251-clmul-gcc.sh | 2 - .../relic/preset/curve2251-clmul-icc.sh | 2 - .../relic/preset/curve2251-ssse3-gcc.sh | 2 - .../relic/preset/curve2251-ssse3-icc.sh | 2 - .../depends/relic/preset/fiat-pbc-bls381.sh | 2 - .../depends/relic/preset/gmp-ecc-128.sh | 2 - .../relic/preset/gmp-ecc-tweedledum.sh | 2 - .../depends/relic/preset/gmp-paillier-4096.sh | 2 - .../depends/relic/preset/gmp-pbc-bls381.sh | 2 - .../depends/relic/preset/gmp-pbc-bn254.sh | 2 - .../depends/relic/preset/gmp-pbc-ss1536.sh | 2 - .../depends/relic/preset/msp-ecc-128.sh | 2 - .../depends/relic/preset/msp-ecc-128k.sh | 2 - .../depends/relic/preset/msp-ecc-80.sh | 2 - .../depends/relic/preset/msp-ecc-80k.sh | 2 - .../depends/relic/preset/msp-pbc-bn158.sh | 2 - .../depends/relic/preset/msp-pbc-bn254.sh | 2 - .../depends/relic/preset/valgrind-debug.sh | 2 - .../depends/relic/preset/x64-ecc-128.sh | 2 - .../depends/relic/preset/x64-pbc-bls12-381.sh | 2 - .../depends/relic/preset/x64-pbc-bls12-446.sh | 2 - .../depends/relic/preset/x64-pbc-bls12-455.sh | 2 - .../depends/relic/preset/x64-pbc-bls12-638.sh | 2 - .../depends/relic/preset/x64-pbc-bls24-509.sh | 2 - .../depends/relic/preset/x64-pbc-bls48-575.sh | 2 - .../depends/relic/preset/x64-pbc-bn254.sh | 2 - .../depends/relic/preset/x64-pbc-bn382.sh | 2 - .../depends/relic/preset/x64-pbc-bn446.sh | 2 - src/dashbls/depends/relic/src/CMakeLists.txt | 231 - src/dashbls/depends/relic/src/arch/lzcnt.inc | 431 - .../depends/relic/src/arch/relic_arch_arm.c | 113 - .../depends/relic/src/arch/relic_arch_avr.c | 64 - .../depends/relic/src/arch/relic_arch_msp.c | 121 - .../depends/relic/src/arch/relic_arch_none.c | 89 - .../depends/relic/src/arch/relic_arch_x64.c | 109 - .../depends/relic/src/arch/relic_arch_x86.c | 79 - .../depends/relic/src/bc/relic_bc_aes.c | 87 - .../depends/relic/src/bc/rijndael-alg-fst.c | 1401 --- .../depends/relic/src/bc/rijndael-alg-fst.h | 47 - .../depends/relic/src/bc/rijndael-api-fst.c | 555 -- .../depends/relic/src/bc/rijndael-api-fst.h | 115 - .../depends/relic/src/bn/relic_bn_add.c | 245 - .../depends/relic/src/bn/relic_bn_cmp.c | 92 - .../depends/relic/src/bn/relic_bn_div.c | 230 - .../depends/relic/src/bn/relic_bn_factor.c | 106 - .../depends/relic/src/bn/relic_bn_gcd.c | 1036 --- .../depends/relic/src/bn/relic_bn_inv.c | 65 - .../depends/relic/src/bn/relic_bn_lcm.c | 66 - .../depends/relic/src/bn/relic_bn_mem.c | 152 - .../depends/relic/src/bn/relic_bn_mod.c | 341 - .../depends/relic/src/bn/relic_bn_mul.c | 249 - .../depends/relic/src/bn/relic_bn_mxp.c | 387 - .../depends/relic/src/bn/relic_bn_prime.c | 525 -- .../depends/relic/src/bn/relic_bn_rec.c | 1019 --- .../depends/relic/src/bn/relic_bn_shift.c | 129 - .../depends/relic/src/bn/relic_bn_smb.c | 150 - .../depends/relic/src/bn/relic_bn_sqr.c | 215 - .../depends/relic/src/bn/relic_bn_srt.c | 90 - .../depends/relic/src/bn/relic_bn_util.c | 534 -- .../depends/relic/src/cp/relic_cp_bbs.c | 165 - .../depends/relic/src/cp/relic_cp_bdpe.c | 205 - .../depends/relic/src/cp/relic_cp_bgn.c | 371 - .../depends/relic/src/cp/relic_cp_bls.c | 121 - .../depends/relic/src/cp/relic_cp_cls.c | 502 -- .../depends/relic/src/cp/relic_cp_cmlhs.c | 381 - .../depends/relic/src/cp/relic_cp_ecdh.c | 100 - .../depends/relic/src/cp/relic_cp_ecdsa.c | 198 - .../depends/relic/src/cp/relic_cp_ecies.c | 159 - .../depends/relic/src/cp/relic_cp_ecmqv.c | 118 - .../depends/relic/src/cp/relic_cp_ecss.c | 189 - .../depends/relic/src/cp/relic_cp_ers.c | 195 - .../depends/relic/src/cp/relic_cp_etrs.c | 394 - .../depends/relic/src/cp/relic_cp_ghpe.c | 216 - .../depends/relic/src/cp/relic_cp_ibe.c | 193 - .../depends/relic/src/cp/relic_cp_mklhs.c | 368 - .../depends/relic/src/cp/relic_cp_mpss.c | 438 - .../depends/relic/src/cp/relic_cp_pcdel.c | 461 - .../depends/relic/src/cp/relic_cp_phpe.c | 215 - .../depends/relic/src/cp/relic_cp_pok.c | 265 - .../depends/relic/src/cp/relic_cp_pss.c | 255 - .../depends/relic/src/cp/relic_cp_rabin.c | 271 - .../depends/relic/src/cp/relic_cp_rsa.c | 1052 --- .../depends/relic/src/cp/relic_cp_sok.c | 310 - .../depends/relic/src/cp/relic_cp_sokaka.c | 144 - .../depends/relic/src/cp/relic_cp_vbnn.c | 275 - .../depends/relic/src/cp/relic_cp_zss.c | 161 - .../depends/relic/src/dv/relic_dv_mem.c | 85 - .../depends/relic/src/dv/relic_dv_util.c | 151 - .../depends/relic/src/eb/relic_eb_add.c | 484 - .../depends/relic/src/eb/relic_eb_cmp.c | 89 - .../depends/relic/src/eb/relic_eb_curve.c | 158 - .../depends/relic/src/eb/relic_eb_dbl.c | 227 - .../depends/relic/src/eb/relic_eb_frb.c | 58 - .../depends/relic/src/eb/relic_eb_hlv.c | 100 - .../depends/relic/src/eb/relic_eb_map.c | 101 - .../depends/relic/src/eb/relic_eb_mul.c | 1119 --- .../depends/relic/src/eb/relic_eb_mul_fix.c | 425 - .../depends/relic/src/eb/relic_eb_mul_sim.c | 558 -- .../depends/relic/src/eb/relic_eb_neg.c | 104 - .../depends/relic/src/eb/relic_eb_norm.c | 152 - .../depends/relic/src/eb/relic_eb_param.c | 492 - .../depends/relic/src/eb/relic_eb_pck.c | 97 - .../depends/relic/src/eb/relic_eb_util.c | 597 -- .../depends/relic/src/ed/relic_ed_add.c | 320 - .../depends/relic/src/ed/relic_ed_cmp.c | 94 - .../depends/relic/src/ed/relic_ed_curve.c | 81 - .../depends/relic/src/ed/relic_ed_dbl.c | 232 - .../depends/relic/src/ed/relic_ed_map.c | 259 - .../depends/relic/src/ed/relic_ed_mul.c | 452 - .../depends/relic/src/ed/relic_ed_mul_fix.c | 370 - .../depends/relic/src/ed/relic_ed_mul_sim.c | 398 - .../depends/relic/src/ed/relic_ed_neg.c | 72 - .../depends/relic/src/ed/relic_ed_norm.c | 127 - .../depends/relic/src/ed/relic_ed_param.c | 200 - .../depends/relic/src/ed/relic_ed_pck.c | 87 - .../depends/relic/src/ed/relic_ed_util.c | 341 - .../depends/relic/src/ep/relic_ep_add.c | 797 -- .../depends/relic/src/ep/relic_ep_cmp.c | 103 - .../depends/relic/src/ep/relic_ep_curve.c | 501 -- .../depends/relic/src/ep/relic_ep_dbl.c | 532 -- .../depends/relic/src/ep/relic_ep_map.c | 210 - .../depends/relic/src/ep/relic_ep_mul.c | 786 -- .../depends/relic/src/ep/relic_ep_mul_fix.c | 567 -- .../depends/relic/src/ep/relic_ep_mul_sim.c | 972 -- .../depends/relic/src/ep/relic_ep_neg.c | 52 - .../depends/relic/src/ep/relic_ep_norm.c | 149 - .../depends/relic/src/ep/relic_ep_param.c | 1581 ---- .../depends/relic/src/ep/relic_ep_pck.c | 136 - .../depends/relic/src/ep/relic_ep_psi.c | 58 - .../depends/relic/src/ep/relic_ep_util.c | 332 - .../depends/relic/src/epx/relic_ep2_add.c | 434 - .../depends/relic/src/epx/relic_ep2_cmp.c | 82 - .../depends/relic/src/epx/relic_ep2_curve.c | 903 -- .../depends/relic/src/epx/relic_ep2_dbl.c | 273 - .../depends/relic/src/epx/relic_ep2_frb.c | 50 - .../depends/relic/src/epx/relic_ep2_map.c | 193 - .../depends/relic/src/epx/relic_ep2_mul.c | 429 - .../depends/relic/src/epx/relic_ep2_mul_cof.c | 181 - .../depends/relic/src/epx/relic_ep2_mul_fix.c | 393 - .../depends/relic/src/epx/relic_ep2_mul_sim.c | 723 -- .../depends/relic/src/epx/relic_ep2_neg.c | 53 - .../depends/relic/src/epx/relic_ep2_norm.c | 138 - .../depends/relic/src/epx/relic_ep2_pck.c | 132 - .../depends/relic/src/epx/relic_ep2_util.c | 339 - .../depends/relic/src/epx/relic_ep4_add.c | 434 - .../depends/relic/src/epx/relic_ep4_cmp.c | 82 - .../depends/relic/src/epx/relic_ep4_curve.c | 377 - .../depends/relic/src/epx/relic_ep4_dbl.c | 276 - .../depends/relic/src/epx/relic_ep4_frb.c | 48 - .../depends/relic/src/epx/relic_ep4_map.c | 79 - .../depends/relic/src/epx/relic_ep4_mul.c | 449 - .../depends/relic/src/epx/relic_ep4_mul_cof.c | 93 - .../depends/relic/src/epx/relic_ep4_mul_fix.c | 393 - .../depends/relic/src/epx/relic_ep4_mul_sim.c | 628 -- .../depends/relic/src/epx/relic_ep4_neg.c | 53 - .../depends/relic/src/epx/relic_ep4_norm.c | 138 - .../depends/relic/src/epx/relic_ep4_util.c | 318 - .../depends/relic/src/fb/relic_fb_add.c | 50 - .../depends/relic/src/fb/relic_fb_cmp.c | 52 - .../depends/relic/src/fb/relic_fb_exp.c | 196 - .../depends/relic/src/fb/relic_fb_inv.c | 702 -- .../depends/relic/src/fb/relic_fb_itr.c | 95 - .../depends/relic/src/fb/relic_fb_mul.c | 308 - .../depends/relic/src/fb/relic_fb_param.c | 249 - .../depends/relic/src/fb/relic_fb_poly.c | 499 -- .../depends/relic/src/fb/relic_fb_rdc.c | 104 - .../depends/relic/src/fb/relic_fb_shift.c | 89 - .../depends/relic/src/fb/relic_fb_slv.c | 83 - .../depends/relic/src/fb/relic_fb_sqr.c | 95 - .../depends/relic/src/fb/relic_fb_srt.c | 64 - .../depends/relic/src/fb/relic_fb_trc.c | 73 - .../depends/relic/src/fb/relic_fb_util.c | 341 - .../depends/relic/src/fbx/relic_fb2_inv.c | 68 - .../depends/relic/src/fbx/relic_fb2_mul.c | 87 - .../depends/relic/src/fbx/relic_fb2_slv.c | 51 - .../depends/relic/src/fbx/relic_fb2_sqr.c | 43 - .../depends/relic/src/fp/relic_fp_add.c | 206 - .../depends/relic/src/fp/relic_fp_cmp.c | 59 - .../depends/relic/src/fp/relic_fp_exp.c | 191 - .../depends/relic/src/fp/relic_fp_inv.c | 565 -- .../depends/relic/src/fp/relic_fp_mul.c | 269 - .../depends/relic/src/fp/relic_fp_param.c | 670 -- .../depends/relic/src/fp/relic_fp_prime.c | 573 -- .../depends/relic/src/fp/relic_fp_rdc.c | 108 - .../depends/relic/src/fp/relic_fp_shift.c | 88 - .../depends/relic/src/fp/relic_fp_sqr.c | 251 - .../depends/relic/src/fp/relic_fp_srt.c | 137 - .../depends/relic/src/fp/relic_fp_util.c | 289 - .../depends/relic/src/fpx/relic_fp12_mul.c | 441 - .../depends/relic/src/fpx/relic_fp12_sqr.c | 528 -- .../depends/relic/src/fpx/relic_fp18_mul.c | 225 - .../depends/relic/src/fpx/relic_fp18_sqr.c | 145 - .../depends/relic/src/fpx/relic_fp24_mul.c | 291 - .../depends/relic/src/fpx/relic_fp24_sqr.c | 410 - .../depends/relic/src/fpx/relic_fp2_mul.c | 255 - .../depends/relic/src/fpx/relic_fp2_sqr.c | 110 - .../depends/relic/src/fpx/relic_fp3_mul.c | 211 - .../depends/relic/src/fpx/relic_fp3_sqr.c | 130 - .../depends/relic/src/fpx/relic_fp48_mul.c | 174 - .../depends/relic/src/fpx/relic_fp48_sqr.c | 421 - .../depends/relic/src/fpx/relic_fp4_mul.c | 194 - .../depends/relic/src/fpx/relic_fp4_sqr.c | 127 - .../depends/relic/src/fpx/relic_fp54_mul.c | 202 - .../depends/relic/src/fpx/relic_fp54_sqr.c | 372 - .../depends/relic/src/fpx/relic_fp6_mul.c | 299 - .../depends/relic/src/fpx/relic_fp6_sqr.c | 233 - .../depends/relic/src/fpx/relic_fp8_mul.c | 275 - .../depends/relic/src/fpx/relic_fp8_sqr.c | 168 - .../depends/relic/src/fpx/relic_fp9_mul.c | 280 - .../depends/relic/src/fpx/relic_fp9_sqr.c | 222 - .../depends/relic/src/fpx/relic_fpx_add.c | 330 - .../depends/relic/src/fpx/relic_fpx_cmp.c | 147 - .../depends/relic/src/fpx/relic_fpx_cyc.c | 2155 ----- .../depends/relic/src/fpx/relic_fpx_exp.c | 714 -- .../depends/relic/src/fpx/relic_fpx_field.c | 253 - .../depends/relic/src/fpx/relic_fpx_frb.c | 207 - .../depends/relic/src/fpx/relic_fpx_inv.c | 808 -- .../depends/relic/src/fpx/relic_fpx_pck.c | 222 - .../depends/relic/src/fpx/relic_fpx_rdc.c | 72 - .../depends/relic/src/fpx/relic_fpx_srt.c | 299 - .../depends/relic/src/fpx/relic_fpx_util.c | 846 -- .../src/low/arm-asm-254/relic_fp_add_low.c | 154 - .../src/low/arm-asm-254/relic_fp_add_low.s | 717 -- .../src/low/arm-asm-254/relic_fp_mul_low.c | 102 - .../src/low/arm-asm-254/relic_fp_mul_low.s | 634 -- .../src/low/arm-asm-254/relic_fp_rdc_low.c | 101 - .../src/low/arm-asm-254/relic_fp_rdc_low.s | 857 -- .../src/low/avr-asm-158/relic_bn_add_low.s | 153 - .../src/low/avr-asm-158/relic_bn_shift_low.c | 81 - .../src/low/avr-asm-158/relic_bn_shift_low.s | 81 - .../src/low/avr-asm-158/relic_fp_add_low.c | 181 - .../src/low/avr-asm-158/relic_fp_add_low.s | 167 - .../src/low/avr-asm-158/relic_fp_mul_low.c | 102 - .../src/low/avr-asm-158/relic_fp_mul_low.s | 2076 ----- .../src/low/avr-asm-158/relic_fp_rdc_low.c | 52 - .../src/low/avr-asm-158/relic_fp_rdc_low.s | 1749 ---- .../src/low/avr-asm-158/relic_fp_shift_low.c | 77 - .../src/low/avr-asm-158/relic_fp_shift_low.s | 88 - .../src/low/avr-asm-158/relic_fp_sqr_low.c | 85 - .../src/low/avr-asm-158/relic_fp_sqr_low.s | 1769 ---- .../src/low/avr-asm-163/relic_bn_add_low.s | 153 - .../src/low/avr-asm-163/relic_bn_shift_low.c | 77 - .../src/low/avr-asm-163/relic_bn_shift_low.s | 79 - .../src/low/avr-asm-163/relic_fb_add_low.c | 40 - .../src/low/avr-asm-163/relic_fb_add_low.s | 113 - .../src/low/avr-asm-163/relic_fb_mul_low.c | 61 - .../src/low/avr-asm-163/relic_fb_mul_low.s | 622 -- .../src/low/avr-asm-163/relic_fb_shift_low.c | 155 - .../src/low/avr-asm-163/relic_fb_shift_low.s | 315 - .../src/low/avr-asm-163/relic_fb_sqr_low.c | 47 - .../src/low/avr-asm-163/relic_fb_sqr_low.s | 305 - .../src/low/curve2251-sse/CMakeLists.txt | 6 - .../relic/src/low/curve2251-sse/macros.h | 96 - .../src/low/curve2251-sse/relic_fb_add_low.c | 75 - .../src/low/curve2251-sse/relic_fb_inv_low.c | 98 - .../src/low/curve2251-sse/relic_fb_itr_low.c | 70 - .../src/low/curve2251-sse/relic_fb_mul_low.c | 122 - .../low/curve2251-sse/relic_fb_mul_low_cl.c | 259 - .../low/curve2251-sse/relic_fb_mul_low_ld.c | 485 - .../low/curve2251-sse/relic_fb_mul_low_sf.c | 366 - .../src/low/curve2251-sse/relic_fb_rdc_low.c | 158 - .../src/low/curve2251-sse/relic_fb_slv_low.c | 203 - .../src/low/curve2251-sse/relic_fb_sqr_low.c | 253 - .../src/low/curve2251-sse/relic_fb_srt_low.c | 183 - .../src/low/curve2251-sse/relic_fb_trc_low.c | 41 - .../relic/src/low/easy/relic_bn_add_low.c | 101 - .../relic/src/low/easy/relic_bn_div_low.c | 139 - .../relic/src/low/easy/relic_bn_mod_low.c | 87 - .../relic/src/low/easy/relic_bn_mul_low.c | 140 - .../relic/src/low/easy/relic_bn_shift_low.c | 128 - .../relic/src/low/easy/relic_bn_sqr_low.c | 149 - .../relic/src/low/easy/relic_fb_add_low.c | 65 - .../relic/src/low/easy/relic_fb_inv_low.c | 130 - .../relic/src/low/easy/relic_fb_itr_low.c | 59 - .../relic/src/low/easy/relic_fb_mul_low.c | 231 - .../relic/src/low/easy/relic_fb_rdc_low.c | 335 - .../relic/src/low/easy/relic_fb_shift_low.c | 137 - .../relic/src/low/easy/relic_fb_slv_low.c | 91 - .../relic/src/low/easy/relic_fb_sqr_low.c | 164 - .../relic/src/low/easy/relic_fb_srt_low.c | 260 - .../relic/src/low/easy/relic_fb_trc_low.c | 64 - .../relic/src/low/easy/relic_fp_add_low.c | 253 - .../relic/src/low/easy/relic_fp_inv_low.c | 58 - .../relic/src/low/easy/relic_fp_mul_low.c | 105 - .../relic/src/low/easy/relic_fp_rdc_low.c | 155 - .../relic/src/low/easy/relic_fp_shift_low.c | 113 - .../relic/src/low/easy/relic_fp_sqr_low.c | 87 - .../relic/src/low/easy/relic_fpx_add_low.c | 310 - .../relic/src/low/easy/relic_fpx_mul_low.c | 224 - .../relic/src/low/easy/relic_fpx_rdc_low.c | 60 - .../relic/src/low/easy/relic_fpx_sqr_low.c | 208 - .../depends/relic/src/low/fiat/CMakeLists.txt | 12 - .../relic/src/low/fiat/relic_fp_add_low.tmpl | 138 - .../relic/src/low/fiat/relic_fp_mul_low.tmpl | 57 - .../relic/src/low/fiat/relic_fp_sqr_low.tmpl | 49 - .../relic/src/low/gmp-sec/relic_bn_add_low.c | 63 - .../relic/src/low/gmp-sec/relic_bn_div_low.c | 57 - .../relic/src/low/gmp-sec/relic_bn_mod_low.c | 58 - .../relic/src/low/gmp-sec/relic_bn_mul_low.c | 70 - .../src/low/gmp-sec/relic_bn_shift_low.c | 58 - .../relic/src/low/gmp-sec/relic_bn_sqr_low.c | 62 - .../relic/src/low/gmp-sec/relic_fp_add_low.c | 129 - .../relic/src/low/gmp-sec/relic_fp_inv_low.c | 68 - .../relic/src/low/gmp-sec/relic_fp_mul_low.c | 60 - .../relic/src/low/gmp-sec/relic_fp_rdc_low.c | 124 - .../src/low/gmp-sec/relic_fp_shift_low.c | 55 - .../relic/src/low/gmp-sec/relic_fp_sqr_low.c | 52 - .../relic/src/low/gmp/relic_bn_add_low.c | 56 - .../relic/src/low/gmp/relic_bn_div_low.c | 47 - .../relic/src/low/gmp/relic_bn_mod_low.c | 64 - .../relic/src/low/gmp/relic_bn_mul_low.c | 60 - .../relic/src/low/gmp/relic_bn_shift_low.c | 58 - .../relic/src/low/gmp/relic_bn_sqr_low.c | 57 - .../relic/src/low/gmp/relic_fb_add_low.c | 58 - .../relic/src/low/gmp/relic_fb_shift_low.c | 79 - .../relic/src/low/gmp/relic_fp_add_low.c | 148 - .../relic/src/low/gmp/relic_fp_inv_low.c | 69 - .../relic/src/low/gmp/relic_fp_mul_low.c | 58 - .../relic/src/low/gmp/relic_fp_rdc_low.c | 124 - .../relic/src/low/gmp/relic_fp_shift_low.c | 55 - .../relic/src/low/gmp/relic_fp_sqr_low.c | 50 - .../relic/src/low/msp-asm/fb_mul_163_ld.inc | 2344 ----- .../relic/src/low/msp-asm/fb_mul_271_ld.inc | 6416 ------------- .../src/low/msp-asm/fb_mul_271_ld_k2.inc | 1884 ---- .../relic/src/low/msp-asm/fb_mul_283_ld.inc | 6776 -------------- .../src/low/msp-asm/fb_mul_353_ld_k2.inc | 2698 ------ .../src/low/msp-asm/fb_mul_353_ld_k3.inc | 1603 ---- .../src/low/msp-asm/fb_srt_271_penta.inc | 498 -- .../src/low/msp-asm/fb_srt_353_trino.inc | 667 -- .../src/low/msp-asm/fp_mul32_160_comba.inc | 376 - .../src/low/msp-asm/fp_mul32_256_comba.inc | 817 -- .../src/low/msp-asm/fp_mul_128_comba.inc | 623 -- .../src/low/msp-asm/fp_mul_160_comba.inc | 919 -- .../fp_rdc32_160_montgomery_sparse.inc | 471 - .../fp_rdc32_256_montgomery_sparse.inc | 998 --- .../msp-asm/fp_rdc_160_montgomery_sparse.inc | 946 -- .../msp-asm/fp_rdc_256_montgomery_sparse.inc | 1960 ---- .../relic/src/low/msp-asm/fp_rdc_256p1.inc | 675 -- .../src/low/msp-asm/fp_sqr32_160_comba.inc | 245 - .../src/low/msp-asm/fp_sqr32_256_comba.inc | 509 -- .../src/low/msp-asm/fp_sqr_128_comba.inc | 353 - .../src/low/msp-asm/fp_sqr_160_comba.inc | 510 -- .../relic/src/low/msp-asm/relic_bn_add_low.c | 100 - .../relic/src/low/msp-asm/relic_bn_add_low.s | 66 - .../src/low/msp-asm/relic_bn_shift_low.c | 111 - .../src/low/msp-asm/relic_bn_shift_low.s | 38 - .../relic/src/low/msp-asm/relic_fb_add_low.c | 54 - .../relic/src/low/msp-asm/relic_fb_add_low.s | 115 - .../relic/src/low/msp-asm/relic_fb_mul_low.c | 232 - .../relic/src/low/msp-asm/relic_fb_mul_low.s | 37 - .../src/low/msp-asm/relic_fb_mul_low_163.s | 341 - .../src/low/msp-asm/relic_fb_mul_low_271.s | 349 - .../src/low/msp-asm/relic_fb_mul_low_283.s | 379 - .../src/low/msp-asm/relic_fb_mul_low_353.s | 503 -- .../src/low/msp-asm/relic_fb_mul_low_353_k3.s | 487 - .../relic/src/low/msp-asm/relic_fb_rdc_low.c | 133 - .../relic/src/low/msp-asm/relic_fb_rdc_low.s | 51 - .../src/low/msp-asm/relic_fb_rdc_low_163.s | 104 - .../src/low/msp-asm/relic_fb_rdc_low_271.s | 194 - .../src/low/msp-asm/relic_fb_rdc_low_283.s | 175 - .../src/low/msp-asm/relic_fb_rdc_low_353.s | 170 - .../src/low/msp-asm/relic_fb_shift_low.c | 158 - .../src/low/msp-asm/relic_fb_shift_low.s | 278 - .../relic/src/low/msp-asm/relic_fb_sqr_low.c | 70 - .../relic/src/low/msp-asm/relic_fb_sqr_low.s | 90 - .../relic/src/low/msp-asm/relic_fb_srt_low.c | 306 - .../relic/src/low/msp-asm/relic_fb_srt_low.s | 98 - .../relic/src/low/msp-asm/relic_fp_add_low.c | 83 - .../relic/src/low/msp-asm/relic_fp_add_low.s | 474 - .../relic/src/low/msp-asm/relic_fp_inv_low.c | 86 - .../relic/src/low/msp-asm/relic_fp_mul_low.c | 71 - .../relic/src/low/msp-asm/relic_fp_mul_low.s | 58 - .../src/low/msp-asm/relic_fp_mul_low_160.s | 32 - .../src/low/msp-asm/relic_fp_mul_low_256.s | 340 - .../relic/src/low/msp-asm/relic_fp_rdc_low.s | 214 - .../src/low/msp-asm/relic_fp_rdc_low_160k1.s | 234 - .../src/low/msp-asm/relic_fp_rdc_low_160p1.s | 210 - .../src/low/msp-asm/relic_fp_rdc_low_256k1.s | 350 - .../src/low/msp-asm/relic_fp_rdc_low_256p1.s | 134 - .../relic/src/low/msp-asm/relic_fp_sqr_low.s | 66 - .../src/low/msp-asm/relic_fp_sqr_low_160.s | 33 - .../src/low/msp-asm/relic_fp_sqr_low_256.s | 170 - .../relic/src/low/msp-asm/relic_fpx_add_low.c | 223 - .../relic/src/low/x64-asm-446/CMakeLists.txt | 6 - .../depends/relic/src/low/x64-asm-446/macro.s | 267 - .../src/low/x64-asm-446/relic_fp_add_low.s | 605 -- .../src/low/x64-asm-446/relic_fp_inv_low.c | 70 - .../src/low/x64-asm-446/relic_fp_inv_low.s | 292 - .../src/low/x64-asm-446/relic_fp_mul_low.c | 48 - .../src/low/x64-asm-446/relic_fp_mul_low.s | 68 - .../src/low/x64-asm-446/relic_fp_rdc_low.c | 108 - .../src/low/x64-asm-446/relic_fp_rdc_low.s | 62 - .../src/low/x64-asm-446/relic_fp_shift_low.c | 47 - .../src/low/x64-asm-446/relic_fp_shift_low.s | 87 - .../src/low/x64-asm-446/relic_fp_sqr_low.c | 48 - .../relic/src/low/x64-asm-455/CMakeLists.txt | 6 - .../depends/relic/src/low/x64-asm-455/macro.s | 266 - .../src/low/x64-asm-455/relic_fp_add_low.s | 789 -- .../src/low/x64-asm-455/relic_fp_inv_low.c | 70 - .../src/low/x64-asm-455/relic_fp_inv_low.s | 296 - .../src/low/x64-asm-455/relic_fp_mul_low.c | 48 - .../src/low/x64-asm-455/relic_fp_mul_low.s | 68 - .../src/low/x64-asm-455/relic_fp_rdc_low.c | 108 - .../src/low/x64-asm-455/relic_fp_rdc_low.s | 62 - .../src/low/x64-asm-455/relic_fp_shift_low.c | 47 - .../src/low/x64-asm-455/relic_fp_shift_low.s | 93 - .../src/low/x64-asm-455/relic_fp_sqr_low.c | 48 - .../relic/src/low/x64-asm-4l/CMakeLists.txt | 6 - .../depends/relic/src/low/x64-asm-4l/macro.s | 536 -- .../src/low/x64-asm-4l/relic_fp_add_low.s | 447 - .../src/low/x64-asm-4l/relic_fp_inv_low.c | 70 - .../src/low/x64-asm-4l/relic_fp_mul_low.c | 47 - .../src/low/x64-asm-4l/relic_fp_mul_low.s | 51 - .../src/low/x64-asm-4l/relic_fp_rdc_low.c | 111 - .../src/low/x64-asm-4l/relic_fp_rdc_low.s | 55 - .../src/low/x64-asm-4l/relic_fp_shift_low.c | 47 - .../src/low/x64-asm-4l/relic_fp_shift_low.s | 61 - .../src/low/x64-asm-4l/relic_fp_sqr_low.c | 44 - .../src/low/x64-asm-4l/relic_fp_sqr_low.s | 136 - .../src/low/x64-asm-4l/relic_fpx_add_low.c | 121 - .../src/low/x64-asm-4l/relic_fpx_add_low.s | 913 -- .../src/low/x64-asm-4l/relic_fpx_mul_low.c | 128 - .../src/low/x64-asm-4l/relic_fpx_mul_low.s | 418 - .../src/low/x64-asm-4l/relic_fpx_rdc_low.c | 49 - .../src/low/x64-asm-4l/relic_fpx_rdc_low.s | 43 - .../src/low/x64-asm-4l/relic_fpx_sqr_low.c | 120 - .../src/low/x64-asm-4l/relic_fpx_sqr_low.s | 193 - .../relic/src/low/x64-asm-544/CMakeLists.txt | 6 - .../depends/relic/src/low/x64-asm-544/macro.s | 290 - .../src/low/x64-asm-544/relic_fp_add_low.s | 804 -- .../src/low/x64-asm-544/relic_fp_mul_low.c | 47 - .../src/low/x64-asm-544/relic_fp_mul_low.s | 68 - .../src/low/x64-asm-544/relic_fp_rdc_low.c | 111 - .../src/low/x64-asm-544/relic_fp_rdc_low.s | 62 - .../src/low/x64-asm-544/relic_fp_sqr_low.c | 48 - .../src/low/x64-asm-544/relic_fpx_add_low.c | 226 - .../src/low/x64-asm-544/relic_fpx_mul_low.c | 184 - .../src/low/x64-asm-544/relic_fpx_rdc_low.c | 50 - .../src/low/x64-asm-544/relic_fpx_rdc_low.s | 65 - .../src/low/x64-asm-544/relic_fpx_sqr_low.c | 172 - .../relic/src/low/x64-asm-638/CMakeLists.txt | 6 - .../depends/relic/src/low/x64-asm-638/macro.s | 308 - .../src/low/x64-asm-638/relic_fp_add_low.s | 827 -- .../src/low/x64-asm-638/relic_fp_mul_low.c | 47 - .../src/low/x64-asm-638/relic_fp_mul_low.s | 68 - .../src/low/x64-asm-638/relic_fp_rdc_low.c | 111 - .../src/low/x64-asm-638/relic_fp_rdc_low.s | 62 - .../src/low/x64-asm-638/relic_fp_sqr_low.c | 48 - .../src/low/x64-asm-638/relic_fpx_rdc_low.c | 50 - .../src/low/x64-asm-638/relic_fpx_rdc_low.s | 65 - .../relic/src/low/x64-asm-6l/CMakeLists.txt | 6 - .../depends/relic/src/low/x64-asm-6l/macro.s | 262 - .../src/low/x64-asm-6l/relic_fp_add_low.s | 595 -- .../src/low/x64-asm-6l/relic_fp_inv_low.c | 70 - .../src/low/x64-asm-6l/relic_fp_mul_low.c | 47 - .../src/low/x64-asm-6l/relic_fp_mul_low.s | 69 - .../src/low/x64-asm-6l/relic_fp_rdc_low.c | 108 - .../src/low/x64-asm-6l/relic_fp_rdc_low.s | 63 - .../src/low/x64-asm-6l/relic_fp_shift_low.c | 47 - .../src/low/x64-asm-6l/relic_fp_shift_low.s | 81 - .../src/low/x64-asm-6l/relic_fp_sqr_low.c | 48 - .../relic/src/low/x64-asm-8l/CMakeLists.txt | 6 - .../depends/relic/src/low/x64-asm-8l/macro.s | 278 - .../src/low/x64-asm-8l/relic_fp_add_low.s | 789 -- .../src/low/x64-asm-8l/relic_fp_inv_low.c | 70 - .../src/low/x64-asm-8l/relic_fp_inv_low.s | 296 - .../src/low/x64-asm-8l/relic_fp_mul_low.c | 48 - .../src/low/x64-asm-8l/relic_fp_mul_low.s | 68 - .../src/low/x64-asm-8l/relic_fp_rdc_low.c | 108 - .../src/low/x64-asm-8l/relic_fp_rdc_low.s | 62 - .../src/low/x64-asm-8l/relic_fp_shift_low.c | 47 - .../src/low/x64-asm-8l/relic_fp_shift_low.s | 93 - .../src/low/x64-asm-8l/relic_fp_sqr_low.c | 48 - .../relic/src/low/x64-asm-9l/CMakeLists.txt | 6 - .../depends/relic/src/low/x64-asm-9l/macro.s | 295 - .../src/low/x64-asm-9l/relic_fp_add_low.s | 774 -- .../src/low/x64-asm-9l/relic_fp_mul_low.c | 47 - .../src/low/x64-asm-9l/relic_fp_mul_low.s | 68 - .../src/low/x64-asm-9l/relic_fp_rdc_low.c | 111 - .../src/low/x64-asm-9l/relic_fp_rdc_low.s | 62 - .../src/low/x64-asm-9l/relic_fp_sqr_low.c | 48 - .../src/low/x64-asm-9l/relic_fpx_rdc_low.c | 50 - .../src/low/x64-asm-9l/relic_fpx_rdc_low.s | 65 - .../relic/src/low/x64-fiat-381/CMakeLists.txt | 6 - .../src/low/x64-fiat-381/bls12_381_q_64.c | 2920 ------ .../src/low/x64-fiat-381/relic_fp_add_low.c | 138 - .../src/low/x64-fiat-381/relic_fp_inv_low.c | 78 - .../src/low/x64-fiat-381/relic_fp_mul_low.c | 57 - .../src/low/x64-fiat-381/relic_fp_sqr_low.c | 49 - .../depends/relic/src/md/blake2-impl.h | 160 - src/dashbls/depends/relic/src/md/blake2.h | 195 - .../depends/relic/src/md/blake2_COPYING | 121 - .../depends/relic/src/md/blake2s-ref.c | 367 - .../depends/relic/src/md/relic_md_blake2s.c | 60 - .../depends/relic/src/md/relic_md_hmac.c | 78 - .../depends/relic/src/md/relic_md_kdf.c | 69 - .../depends/relic/src/md/relic_md_mgf.c | 70 - .../depends/relic/src/md/relic_md_sha224.c | 60 - .../depends/relic/src/md/relic_md_sha256.c | 60 - .../depends/relic/src/md/relic_md_sha384.c | 60 - .../depends/relic/src/md/relic_md_sha512.c | 60 - .../depends/relic/src/md/relic_md_xmd.c | 132 - src/dashbls/depends/relic/src/md/sha.h | 195 - src/dashbls/depends/relic/src/md/sha224-256.c | 592 -- src/dashbls/depends/relic/src/md/sha384-512.c | 1042 --- .../depends/relic/src/md/sha_private.h | 31 - .../depends/relic/src/mpc/relic_mt_mpc.c | 133 - .../depends/relic/src/mpc/relic_pc_mpc.c | 363 - .../depends/relic/src/pc/relic_pc_core.c | 77 - .../depends/relic/src/pc/relic_pc_exp.c | 253 - .../depends/relic/src/pc/relic_pc_util.c | 376 - .../depends/relic/src/pp/relic_pp_add_k12.c | 322 - .../depends/relic/src/pp/relic_pp_add_k2.c | 245 - .../depends/relic/src/pp/relic_pp_add_k24.c | 160 - .../depends/relic/src/pp/relic_pp_add_k48.c | 240 - .../depends/relic/src/pp/relic_pp_add_k54.c | 243 - .../depends/relic/src/pp/relic_pp_add_k8.c | 269 - .../depends/relic/src/pp/relic_pp_dbl_k12.c | 488 - .../depends/relic/src/pp/relic_pp_dbl_k2.c | 260 - .../depends/relic/src/pp/relic_pp_dbl_k24.c | 177 - .../depends/relic/src/pp/relic_pp_dbl_k48.c | 250 - .../depends/relic/src/pp/relic_pp_dbl_k54.c | 253 - .../depends/relic/src/pp/relic_pp_dbl_k8.c | 453 - .../depends/relic/src/pp/relic_pp_exp_k12.c | 229 - .../depends/relic/src/pp/relic_pp_exp_k2.c | 65 - .../depends/relic/src/pp/relic_pp_exp_k24.c | 107 - .../depends/relic/src/pp/relic_pp_exp_k48.c | 176 - .../depends/relic/src/pp/relic_pp_exp_k54.c | 267 - .../depends/relic/src/pp/relic_pp_exp_k8.c | 132 - .../depends/relic/src/pp/relic_pp_map.c | 48 - .../depends/relic/src/pp/relic_pp_map_k12.c | 601 -- .../depends/relic/src/pp/relic_pp_map_k2.c | 382 - .../depends/relic/src/pp/relic_pp_map_k24.c | 249 - .../depends/relic/src/pp/relic_pp_map_k48.c | 135 - .../depends/relic/src/pp/relic_pp_map_k54.c | 192 - .../depends/relic/src/pp/relic_pp_map_k8.c | 164 - .../depends/relic/src/pp/relic_pp_norm.c | 102 - .../depends/relic/src/rand/relic_rand_call.c | 98 - .../depends/relic/src/rand/relic_rand_core.c | 218 - .../depends/relic/src/rand/relic_rand_hashd.c | 215 - .../depends/relic/src/rand/relic_rand_rdrnd.c | 66 - .../depends/relic/src/rand/relic_rand_udev.c | 73 - src/dashbls/depends/relic/src/relic_bench.c | 250 - src/dashbls/depends/relic/src/relic_conf.c | 149 - src/dashbls/depends/relic/src/relic_core.c | 215 - src/dashbls/depends/relic/src/relic_err.c | 106 - src/dashbls/depends/relic/src/relic_test.c | 152 - src/dashbls/depends/relic/src/relic_util.c | 216 - .../depends/relic/src/tmpl/relic_tmpl_map.h | 324 - src/dashbls/depends/relic/test/CMakeLists.txt | 82 - src/dashbls/depends/relic/test/test_bn.c | 2247 ----- src/dashbls/depends/relic/test/test_core.c | 171 - src/dashbls/depends/relic/test/test_cp.c | 2137 ----- src/dashbls/depends/relic/test/test_dv.c | 235 - src/dashbls/depends/relic/test/test_eb.c | 1347 --- src/dashbls/depends/relic/test/test_ec.c | 727 -- src/dashbls/depends/relic/test/test_ed.c | 1278 --- src/dashbls/depends/relic/test/test_ep.c | 1465 --- src/dashbls/depends/relic/test/test_epx.c | 2277 ----- src/dashbls/depends/relic/test/test_err.c | 168 - src/dashbls/depends/relic/test/test_fb.c | 1136 --- src/dashbls/depends/relic/test/test_fbx.c | 420 - src/dashbls/depends/relic/test/test_fp.c | 1169 --- src/dashbls/depends/relic/test/test_fpx.c | 7949 ----------------- src/dashbls/depends/relic/test/test_md.c | 585 -- src/dashbls/depends/relic/test/test_mpc.c | 418 - src/dashbls/depends/relic/test/test_pc.c | 1836 ---- src/dashbls/depends/relic/test/test_pp.c | 2580 ------ src/dashbls/depends/relic/test/test_rand.c | 449 - .../depends/relic/tools/git-creation-date.sh | 10 - .../depends/relic/tools/relic_gen_label.sh | 254 - src/dashbls/emsdk_build.sh | 10 - src/dashbls/go-bindings/.gitignore | 1 - src/dashbls/go-bindings/Makefile | 97 - src/dashbls/go-bindings/README.md | 195 - src/dashbls/go-bindings/blschia.cpp | 54 - src/dashbls/go-bindings/blschia.h | 46 - src/dashbls/go-bindings/elements.cpp | 154 - src/dashbls/go-bindings/elements.go | 191 - src/dashbls/go-bindings/elements.h | 56 - src/dashbls/go-bindings/error.go | 23 - src/dashbls/go-bindings/error.h | 21 - src/dashbls/go-bindings/go.mod | 5 - src/dashbls/go-bindings/go.sum | 11 - src/dashbls/go-bindings/privatekey.cpp | 113 - src/dashbls/go-bindings/privatekey.go | 130 - src/dashbls/go-bindings/privatekey.h | 39 - src/dashbls/go-bindings/schemes.cpp | 229 - src/dashbls/go-bindings/schemes.go | 414 - src/dashbls/go-bindings/schemes.h | 100 - src/dashbls/go-bindings/schemes_test.go | 661 -- src/dashbls/go-bindings/threshold.cpp | 168 - src/dashbls/go-bindings/threshold.go | 231 - src/dashbls/go-bindings/threshold.h | 55 - src/dashbls/go-bindings/threshold_test.go | 135 - src/dashbls/go-bindings/util.go | 56 - src/dashbls/go-bindings/util_test.go | 49 - src/dashbls/go-bindings/utils.cpp | 40 - src/dashbls/go-bindings/utils.hpp | 34 - src/dashbls/js-bindings/CMakeLists.txt | 49 - src/dashbls/js-bindings/README.md | 178 - src/dashbls/js-bindings/blsjs.d.ts | 98 - .../js-bindings/bundle_wasm_for_web.js | 37 - src/dashbls/js-bindings/helpers.cpp | 63 - src/dashbls/js-bindings/helpers.h | 61 - src/dashbls/js-bindings/jsbindings.cpp | 104 - src/dashbls/js-bindings/package-lock.json | 7366 --------------- src/dashbls/js-bindings/package.json | 65 - .../js-bindings/tests/PrivateKey.spec.js | 128 - .../js-bindings/tests/PublicKey.spec.js | 85 - .../js-bindings/tests/Signature.spec.js | 162 - src/dashbls/js-bindings/tests/karma.conf.js | 65 - src/dashbls/js-bindings/tests/karma.test.js | 5 - src/dashbls/js-bindings/tests/test.js | 401 - src/dashbls/js-bindings/tests/typings.spec.ts | 109 - .../js-bindings/tests/webpack.config.js | 19 - src/dashbls/js-bindings/tests/yarn.lock | 300 - .../js-bindings/wrappers/G1ElementWrapper.cpp | 66 - .../js-bindings/wrappers/G1ElementWrapper.h | 50 - .../js-bindings/wrappers/G2ElementWrapper.cpp | 73 - .../js-bindings/wrappers/G2ElementWrapper.h | 52 - src/dashbls/js-bindings/wrappers/JSWrapper.h | 32 - .../wrappers/PrivateKeyWrapper.cpp | 79 - .../js-bindings/wrappers/PrivateKeyWrapper.h | 55 - .../js-bindings/wrappers/SchemeMPLWrapper.cpp | 21 - .../js-bindings/wrappers/SchemeMPLWrapper.h | 128 - .../js-bindings/wrappers/UtilWrapper.cpp | 28 - .../js-bindings/wrappers/UtilWrapper.h | 29 - src/dashbls/js_build.sh | 9 - src/dashbls/js_build_docker.sh | 18 - src/dashbls/js_test.sh | 15 - src/dashbls/pyproject.toml | 89 - src/dashbls/rust-bindings/.gitignore | 2 - .../rust-bindings/bls-dash-sys/.rustfmt.toml | 17 - .../rust-bindings/bls-dash-sys/Cargo.toml | 15 - .../rust-bindings/bls-dash-sys/bindings.rs | 440 - .../rust-bindings/bls-dash-sys/build.rs | 445 - .../c-bindings/bip32/chaincode.cpp | 25 - .../bls-dash-sys/c-bindings/bip32/chaincode.h | 21 - .../c-bindings/bip32/extendedprivatekey.cpp | 128 - .../c-bindings/bip32/extendedprivatekey.h | 49 - .../c-bindings/bip32/extendedpublickey.cpp | 73 - .../c-bindings/bip32/extendedpublickey.h | 39 - .../bls-dash-sys/c-bindings/blschia.cpp | 56 - .../bls-dash-sys/c-bindings/blschia.h | 46 - .../bls-dash-sys/c-bindings/elements.cpp | 162 - .../bls-dash-sys/c-bindings/elements.h | 58 - .../bls-dash-sys/c-bindings/error.h | 21 - .../bls-dash-sys/c-bindings/privatekey.cpp | 120 - .../bls-dash-sys/c-bindings/privatekey.h | 40 - .../bls-dash-sys/c-bindings/schemes.cpp | 388 - .../bls-dash-sys/c-bindings/schemes.h | 184 - .../bls-dash-sys/c-bindings/threshold.cpp | 168 - .../bls-dash-sys/c-bindings/threshold.h | 55 - .../bls-dash-sys/c-bindings/utils.cpp | 40 - .../bls-dash-sys/c-bindings/utils.hpp | 34 - .../rust-bindings/bls-dash-sys/include.h | 8 - .../rust-bindings/bls-dash-sys/src/lib.rs | 6 - .../bls-dash-sys/tests/sign_and_verify.rs | 79 - .../bls-signatures/.rustfmt.toml | 17 - .../rust-bindings/bls-signatures/Cargo.toml | 19 - .../bls-signatures/src/bip32/chain_code.rs | 33 - .../bls-signatures/src/bip32/mod.rs | 7 - .../bls-signatures/src/bip32/private_key.rs | 205 - .../bls-signatures/src/bip32/public_key.rs | 119 - .../bls-signatures/src/elements.rs | 411 - .../bls-signatures/src/legacy/bip32/mod.rs | 2 - .../src/legacy/bip32/private_key.rs | 58 - .../src/legacy/bip32/public_key.rs | 40 - .../bls-signatures/src/legacy/elements.rs | 33 - .../bls-signatures/src/legacy/mod.rs | 2 - .../rust-bindings/bls-signatures/src/lib.rs | 126 - .../bls-signatures/src/private_key.rs | 323 - .../bls-signatures/src/schemes.rs | 434 - .../rust-bindings/bls-signatures/src/utils.rs | 71 - src/dashbls/rust-bindings/example/Cargo.toml | 7 - src/dashbls/rust-bindings/example/src/main.rs | 51 - src/dashbls/setjmp_patch.diff | 41 - src/dashbls/setup.py | 126 - src/dashbls/src/CMakeLists.txt | 85 - src/dashbls/src/test-bench.cpp | 187 - src/dashbls/tools/fuzzgen.cpp | 158 - 848 files changed, 29 insertions(+), 251284 deletions(-) delete mode 100755 src/dashbls/.github/scripts/build_simple_index.py delete mode 100644 src/dashbls/.github/workflows/binds-go.yml delete mode 100644 src/dashbls/.github/workflows/binds-js.yml delete mode 100644 src/dashbls/.github/workflows/binds-py.yml delete mode 100644 src/dashbls/.github/workflows/binds-rs.yml delete mode 100644 src/dashbls/.github/workflows/build-binds.yml delete mode 100644 src/dashbls/.github/workflows/build-docs.yml delete mode 100644 src/dashbls/.github/workflows/build-test.yaml delete mode 100644 src/dashbls/.github/workflows/stale-issue.yml delete mode 100644 src/dashbls/.gitignore delete mode 100644 src/dashbls/.python-version delete mode 100644 src/dashbls/.vscode/extensions.json delete mode 100644 src/dashbls/.vscode/settings.json delete mode 100644 src/dashbls/CMakeLists.txt delete mode 100644 src/dashbls/MANIFEST.in delete mode 100644 src/dashbls/Makefile.am delete mode 100644 src/dashbls/Makefile.bench.include delete mode 100644 src/dashbls/Makefile.bls.include delete mode 100644 src/dashbls/Makefile.mimalloc.include delete mode 100644 src/dashbls/Makefile.relic.include delete mode 100644 src/dashbls/Makefile.test.include delete mode 100755 src/dashbls/apple.rust.deps.sh delete mode 100755 src/dashbls/autogen.sh delete mode 100644 src/dashbls/binds/python/CMakeLists.txt delete mode 100644 src/dashbls/binds/python/conftest.py delete mode 100644 src/dashbls/binds/python/pythonbindings.cpp delete mode 100755 src/dashbls/binds/python/samples/aggregate_signatures.py delete mode 100755 src/dashbls/binds/python/samples/creating_keys_and_signatures.py delete mode 100755 src/dashbls/binds/python/samples/hd_keys.py delete mode 100755 src/dashbls/binds/python/samples/loading_from_bytes.py delete mode 100755 src/dashbls/binds/python/samples/proof_of_possession.py delete mode 100755 src/dashbls/binds/python/samples/serializing_to_bytes.py delete mode 100755 src/dashbls/binds/python/samples/tree_aggregates.py delete mode 100755 src/dashbls/binds/python/test_bench.py delete mode 100755 src/dashbls/binds/python/test_unit.py delete mode 100644 src/dashbls/build-aux/m4/ax_check_compile_flag.m4 delete mode 100644 src/dashbls/build-aux/m4/ax_check_link_flag.m4 delete mode 100644 src/dashbls/build-aux/m4/ax_cxx_compile_stdcxx.m4 delete mode 100644 src/dashbls/build-aux/m4/ax_pthread.m4 delete mode 100644 src/dashbls/cmake_modules/BrewHelper.cmake delete mode 100644 src/dashbls/cmake_modules/Findsodium.cmake delete mode 100644 src/dashbls/configure.ac delete mode 100644 src/dashbls/depends/catch2/CMakeLists.txt delete mode 100644 src/dashbls/depends/relic/.editorconfig delete mode 100644 src/dashbls/depends/relic/.github/workflows/16bit.yml delete mode 100644 src/dashbls/depends/relic/.github/workflows/32bit.yml delete mode 100644 src/dashbls/depends/relic/.github/workflows/8bit.yml delete mode 100644 src/dashbls/depends/relic/.github/workflows/bls12-381.yml delete mode 100644 src/dashbls/depends/relic/.github/workflows/easy.yml delete mode 100644 src/dashbls/depends/relic/.github/workflows/gmp-sec.yml delete mode 100644 src/dashbls/depends/relic/.github/workflows/gmp.yml delete mode 100644 src/dashbls/depends/relic/.gitignore delete mode 100644 src/dashbls/depends/relic/.indent.pro delete mode 100644 src/dashbls/depends/relic/.travis.yml delete mode 100644 src/dashbls/depends/relic/CMakeLists.txt delete mode 100644 src/dashbls/depends/relic/COPYRIGHT delete mode 100644 src/dashbls/depends/relic/LICENSE delete mode 100644 src/dashbls/depends/relic/LICENSE.Apache-2.0 delete mode 100644 src/dashbls/depends/relic/LICENSE.LGPL-2.1 delete mode 100644 src/dashbls/depends/relic/README.md delete mode 100755 src/dashbls/depends/relic/art/rlc_logo.png delete mode 100644 src/dashbls/depends/relic/art/rlc_logo.svg delete mode 100644 src/dashbls/depends/relic/bench/CMakeLists.txt delete mode 100644 src/dashbls/depends/relic/bench/bench_bn.c delete mode 100644 src/dashbls/depends/relic/bench/bench_cp.c delete mode 100644 src/dashbls/depends/relic/bench/bench_dv.c delete mode 100644 src/dashbls/depends/relic/bench/bench_eb.c delete mode 100644 src/dashbls/depends/relic/bench/bench_ec.c delete mode 100644 src/dashbls/depends/relic/bench/bench_ed.c delete mode 100644 src/dashbls/depends/relic/bench/bench_ep.c delete mode 100644 src/dashbls/depends/relic/bench/bench_epx.c delete mode 100644 src/dashbls/depends/relic/bench/bench_err.c delete mode 100644 src/dashbls/depends/relic/bench/bench_fb.c delete mode 100644 src/dashbls/depends/relic/bench/bench_fbx.c delete mode 100644 src/dashbls/depends/relic/bench/bench_fp.c delete mode 100644 src/dashbls/depends/relic/bench/bench_fpx.c delete mode 100644 src/dashbls/depends/relic/bench/bench_md.c delete mode 100644 src/dashbls/depends/relic/bench/bench_mpc.c delete mode 100755 src/dashbls/depends/relic/bench/bench_pc.c delete mode 100644 src/dashbls/depends/relic/bench/bench_pp.c delete mode 100644 src/dashbls/depends/relic/bench/bench_rand.c delete mode 100644 src/dashbls/depends/relic/cmake/arch.cmake delete mode 100644 src/dashbls/depends/relic/cmake/bn.cmake delete mode 100644 src/dashbls/depends/relic/cmake/cp.cmake delete mode 100644 src/dashbls/depends/relic/cmake/doxygen.cmake delete mode 100644 src/dashbls/depends/relic/cmake/eb.cmake delete mode 100644 src/dashbls/depends/relic/cmake/ec.cmake delete mode 100644 src/dashbls/depends/relic/cmake/ed.cmake delete mode 100644 src/dashbls/depends/relic/cmake/ep.cmake delete mode 100644 src/dashbls/depends/relic/cmake/err.cmake delete mode 100644 src/dashbls/depends/relic/cmake/fb.cmake delete mode 100644 src/dashbls/depends/relic/cmake/fiat.cmake delete mode 100644 src/dashbls/depends/relic/cmake/fp.cmake delete mode 100644 src/dashbls/depends/relic/cmake/fpx.cmake delete mode 100644 src/dashbls/depends/relic/cmake/gmp.cmake delete mode 100644 src/dashbls/depends/relic/cmake/ios.cmake delete mode 100644 src/dashbls/depends/relic/cmake/md.cmake delete mode 100644 src/dashbls/depends/relic/cmake/pp.cmake delete mode 100644 src/dashbls/depends/relic/cmake/rand.cmake delete mode 100644 src/dashbls/depends/relic/cmake/relic-config.cmake delete mode 100644 src/dashbls/depends/relic/cmake/with.cmake delete mode 100644 src/dashbls/depends/relic/demo/cert-input/Makefile delete mode 100644 src/dashbls/depends/relic/demo/cert-input/test-bench.c delete mode 100644 src/dashbls/depends/relic/demo/ers-etrs/Makefile delete mode 100644 src/dashbls/depends/relic/demo/ers-etrs/test-bench.c delete mode 100644 src/dashbls/depends/relic/demo/general-paillier/Makefile delete mode 100644 src/dashbls/depends/relic/demo/general-paillier/test.c delete mode 100644 src/dashbls/depends/relic/demo/link-test/Makefile delete mode 100644 src/dashbls/depends/relic/demo/link-test/test.c delete mode 100644 src/dashbls/depends/relic/demo/link-test/test1.c delete mode 100644 src/dashbls/depends/relic/demo/link-test/test2.c delete mode 100644 src/dashbls/depends/relic/demo/public-stats/Makefile delete mode 100644 src/dashbls/depends/relic/demo/public-stats/csv.c delete mode 100644 src/dashbls/depends/relic/demo/public-stats/csv.h delete mode 100644 src/dashbls/depends/relic/demo/public-stats/main.c delete mode 100644 src/dashbls/depends/relic/demo/tweedledum/Makefile delete mode 100644 src/dashbls/depends/relic/demo/tweedledum/main.c delete mode 100644 src/dashbls/depends/relic/doc/relic.doxygen.in delete mode 100644 src/dashbls/depends/relic/include/low/relic_bn_low.h delete mode 100644 src/dashbls/depends/relic/include/low/relic_dv_low.h delete mode 100644 src/dashbls/depends/relic/include/low/relic_fb_low.h delete mode 100644 src/dashbls/depends/relic/include/low/relic_fp_low.h delete mode 100644 src/dashbls/depends/relic/include/low/relic_fpx_low.h delete mode 100644 src/dashbls/depends/relic/include/relic.h delete mode 100644 src/dashbls/depends/relic/include/relic_alloc.h delete mode 100644 src/dashbls/depends/relic/include/relic_arch.h delete mode 100644 src/dashbls/depends/relic/include/relic_bc.h delete mode 100644 src/dashbls/depends/relic/include/relic_bench.h delete mode 100644 src/dashbls/depends/relic/include/relic_bn.h delete mode 100644 src/dashbls/depends/relic/include/relic_conf.h.in delete mode 100644 src/dashbls/depends/relic/include/relic_core.h delete mode 100644 src/dashbls/depends/relic/include/relic_cp.h delete mode 100644 src/dashbls/depends/relic/include/relic_dv.h delete mode 100644 src/dashbls/depends/relic/include/relic_eb.h delete mode 100644 src/dashbls/depends/relic/include/relic_ec.h delete mode 100644 src/dashbls/depends/relic/include/relic_ed.h delete mode 100644 src/dashbls/depends/relic/include/relic_ep.h delete mode 100644 src/dashbls/depends/relic/include/relic_epx.h delete mode 100644 src/dashbls/depends/relic/include/relic_err.h delete mode 100644 src/dashbls/depends/relic/include/relic_fb.h delete mode 100644 src/dashbls/depends/relic/include/relic_fbx.h delete mode 100644 src/dashbls/depends/relic/include/relic_fp.h delete mode 100644 src/dashbls/depends/relic/include/relic_fpx.h delete mode 100644 src/dashbls/depends/relic/include/relic_label.h delete mode 100644 src/dashbls/depends/relic/include/relic_md.h delete mode 100644 src/dashbls/depends/relic/include/relic_mpc.h delete mode 100644 src/dashbls/depends/relic/include/relic_multi.h delete mode 100644 src/dashbls/depends/relic/include/relic_pc.h delete mode 100644 src/dashbls/depends/relic/include/relic_pp.h delete mode 100644 src/dashbls/depends/relic/include/relic_rand.h delete mode 100644 src/dashbls/depends/relic/include/relic_test.h delete mode 100644 src/dashbls/depends/relic/include/relic_types.h delete mode 100644 src/dashbls/depends/relic/include/relic_util.h delete mode 100755 src/dashbls/depends/relic/preset/ardue-pbc-bn254.sh delete mode 100755 src/dashbls/depends/relic/preset/arm-pbc-bn254.sh delete mode 100755 src/dashbls/depends/relic/preset/armdroid-pbc-bn254.sh delete mode 100755 src/dashbls/depends/relic/preset/armduino-ecc-128k.sh delete mode 100755 src/dashbls/depends/relic/preset/armega-pbc-bn254.sh delete mode 100755 src/dashbls/depends/relic/preset/armios-pbc-bn254.sh delete mode 100755 src/dashbls/depends/relic/preset/avr-ecc-80k-sim.sh delete mode 100755 src/dashbls/depends/relic/preset/avr-ecc-80k.sh delete mode 100755 src/dashbls/depends/relic/preset/avr-pbc-80.sh delete mode 100755 src/dashbls/depends/relic/preset/curve2251-clmul-gcc.sh delete mode 100755 src/dashbls/depends/relic/preset/curve2251-clmul-icc.sh delete mode 100755 src/dashbls/depends/relic/preset/curve2251-ssse3-gcc.sh delete mode 100755 src/dashbls/depends/relic/preset/curve2251-ssse3-icc.sh delete mode 100755 src/dashbls/depends/relic/preset/fiat-pbc-bls381.sh delete mode 100755 src/dashbls/depends/relic/preset/gmp-ecc-128.sh delete mode 100755 src/dashbls/depends/relic/preset/gmp-ecc-tweedledum.sh delete mode 100755 src/dashbls/depends/relic/preset/gmp-paillier-4096.sh delete mode 100755 src/dashbls/depends/relic/preset/gmp-pbc-bls381.sh delete mode 100755 src/dashbls/depends/relic/preset/gmp-pbc-bn254.sh delete mode 100755 src/dashbls/depends/relic/preset/gmp-pbc-ss1536.sh delete mode 100755 src/dashbls/depends/relic/preset/msp-ecc-128.sh delete mode 100755 src/dashbls/depends/relic/preset/msp-ecc-128k.sh delete mode 100755 src/dashbls/depends/relic/preset/msp-ecc-80.sh delete mode 100755 src/dashbls/depends/relic/preset/msp-ecc-80k.sh delete mode 100755 src/dashbls/depends/relic/preset/msp-pbc-bn158.sh delete mode 100755 src/dashbls/depends/relic/preset/msp-pbc-bn254.sh delete mode 100755 src/dashbls/depends/relic/preset/valgrind-debug.sh delete mode 100755 src/dashbls/depends/relic/preset/x64-ecc-128.sh delete mode 100755 src/dashbls/depends/relic/preset/x64-pbc-bls12-381.sh delete mode 100755 src/dashbls/depends/relic/preset/x64-pbc-bls12-446.sh delete mode 100755 src/dashbls/depends/relic/preset/x64-pbc-bls12-455.sh delete mode 100755 src/dashbls/depends/relic/preset/x64-pbc-bls12-638.sh delete mode 100755 src/dashbls/depends/relic/preset/x64-pbc-bls24-509.sh delete mode 100755 src/dashbls/depends/relic/preset/x64-pbc-bls48-575.sh delete mode 100755 src/dashbls/depends/relic/preset/x64-pbc-bn254.sh delete mode 100755 src/dashbls/depends/relic/preset/x64-pbc-bn382.sh delete mode 100755 src/dashbls/depends/relic/preset/x64-pbc-bn446.sh delete mode 100644 src/dashbls/depends/relic/src/CMakeLists.txt delete mode 100644 src/dashbls/depends/relic/src/arch/lzcnt.inc delete mode 100644 src/dashbls/depends/relic/src/arch/relic_arch_arm.c delete mode 100644 src/dashbls/depends/relic/src/arch/relic_arch_avr.c delete mode 100644 src/dashbls/depends/relic/src/arch/relic_arch_msp.c delete mode 100644 src/dashbls/depends/relic/src/arch/relic_arch_none.c delete mode 100644 src/dashbls/depends/relic/src/arch/relic_arch_x64.c delete mode 100644 src/dashbls/depends/relic/src/arch/relic_arch_x86.c delete mode 100644 src/dashbls/depends/relic/src/bc/relic_bc_aes.c delete mode 100644 src/dashbls/depends/relic/src/bc/rijndael-alg-fst.c delete mode 100644 src/dashbls/depends/relic/src/bc/rijndael-alg-fst.h delete mode 100644 src/dashbls/depends/relic/src/bc/rijndael-api-fst.c delete mode 100644 src/dashbls/depends/relic/src/bc/rijndael-api-fst.h delete mode 100644 src/dashbls/depends/relic/src/bn/relic_bn_add.c delete mode 100644 src/dashbls/depends/relic/src/bn/relic_bn_cmp.c delete mode 100644 src/dashbls/depends/relic/src/bn/relic_bn_div.c delete mode 100644 src/dashbls/depends/relic/src/bn/relic_bn_factor.c delete mode 100644 src/dashbls/depends/relic/src/bn/relic_bn_gcd.c delete mode 100644 src/dashbls/depends/relic/src/bn/relic_bn_inv.c delete mode 100644 src/dashbls/depends/relic/src/bn/relic_bn_lcm.c delete mode 100644 src/dashbls/depends/relic/src/bn/relic_bn_mem.c delete mode 100644 src/dashbls/depends/relic/src/bn/relic_bn_mod.c delete mode 100644 src/dashbls/depends/relic/src/bn/relic_bn_mul.c delete mode 100644 src/dashbls/depends/relic/src/bn/relic_bn_mxp.c delete mode 100644 src/dashbls/depends/relic/src/bn/relic_bn_prime.c delete mode 100644 src/dashbls/depends/relic/src/bn/relic_bn_rec.c delete mode 100644 src/dashbls/depends/relic/src/bn/relic_bn_shift.c delete mode 100644 src/dashbls/depends/relic/src/bn/relic_bn_smb.c delete mode 100644 src/dashbls/depends/relic/src/bn/relic_bn_sqr.c delete mode 100644 src/dashbls/depends/relic/src/bn/relic_bn_srt.c delete mode 100644 src/dashbls/depends/relic/src/bn/relic_bn_util.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_bbs.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_bdpe.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_bgn.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_bls.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_cls.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_cmlhs.c delete mode 100755 src/dashbls/depends/relic/src/cp/relic_cp_ecdh.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_ecdsa.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_ecies.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_ecmqv.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_ecss.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_ers.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_etrs.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_ghpe.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_ibe.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_mklhs.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_mpss.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_pcdel.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_phpe.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_pok.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_pss.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_rabin.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_rsa.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_sok.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_sokaka.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_vbnn.c delete mode 100644 src/dashbls/depends/relic/src/cp/relic_cp_zss.c delete mode 100644 src/dashbls/depends/relic/src/dv/relic_dv_mem.c delete mode 100644 src/dashbls/depends/relic/src/dv/relic_dv_util.c delete mode 100644 src/dashbls/depends/relic/src/eb/relic_eb_add.c delete mode 100644 src/dashbls/depends/relic/src/eb/relic_eb_cmp.c delete mode 100644 src/dashbls/depends/relic/src/eb/relic_eb_curve.c delete mode 100644 src/dashbls/depends/relic/src/eb/relic_eb_dbl.c delete mode 100644 src/dashbls/depends/relic/src/eb/relic_eb_frb.c delete mode 100644 src/dashbls/depends/relic/src/eb/relic_eb_hlv.c delete mode 100644 src/dashbls/depends/relic/src/eb/relic_eb_map.c delete mode 100644 src/dashbls/depends/relic/src/eb/relic_eb_mul.c delete mode 100644 src/dashbls/depends/relic/src/eb/relic_eb_mul_fix.c delete mode 100644 src/dashbls/depends/relic/src/eb/relic_eb_mul_sim.c delete mode 100644 src/dashbls/depends/relic/src/eb/relic_eb_neg.c delete mode 100644 src/dashbls/depends/relic/src/eb/relic_eb_norm.c delete mode 100644 src/dashbls/depends/relic/src/eb/relic_eb_param.c delete mode 100644 src/dashbls/depends/relic/src/eb/relic_eb_pck.c delete mode 100644 src/dashbls/depends/relic/src/eb/relic_eb_util.c delete mode 100644 src/dashbls/depends/relic/src/ed/relic_ed_add.c delete mode 100644 src/dashbls/depends/relic/src/ed/relic_ed_cmp.c delete mode 100644 src/dashbls/depends/relic/src/ed/relic_ed_curve.c delete mode 100644 src/dashbls/depends/relic/src/ed/relic_ed_dbl.c delete mode 100644 src/dashbls/depends/relic/src/ed/relic_ed_map.c delete mode 100644 src/dashbls/depends/relic/src/ed/relic_ed_mul.c delete mode 100644 src/dashbls/depends/relic/src/ed/relic_ed_mul_fix.c delete mode 100644 src/dashbls/depends/relic/src/ed/relic_ed_mul_sim.c delete mode 100644 src/dashbls/depends/relic/src/ed/relic_ed_neg.c delete mode 100644 src/dashbls/depends/relic/src/ed/relic_ed_norm.c delete mode 100644 src/dashbls/depends/relic/src/ed/relic_ed_param.c delete mode 100644 src/dashbls/depends/relic/src/ed/relic_ed_pck.c delete mode 100644 src/dashbls/depends/relic/src/ed/relic_ed_util.c delete mode 100644 src/dashbls/depends/relic/src/ep/relic_ep_add.c delete mode 100644 src/dashbls/depends/relic/src/ep/relic_ep_cmp.c delete mode 100644 src/dashbls/depends/relic/src/ep/relic_ep_curve.c delete mode 100644 src/dashbls/depends/relic/src/ep/relic_ep_dbl.c delete mode 100644 src/dashbls/depends/relic/src/ep/relic_ep_map.c delete mode 100644 src/dashbls/depends/relic/src/ep/relic_ep_mul.c delete mode 100644 src/dashbls/depends/relic/src/ep/relic_ep_mul_fix.c delete mode 100644 src/dashbls/depends/relic/src/ep/relic_ep_mul_sim.c delete mode 100644 src/dashbls/depends/relic/src/ep/relic_ep_neg.c delete mode 100644 src/dashbls/depends/relic/src/ep/relic_ep_norm.c delete mode 100644 src/dashbls/depends/relic/src/ep/relic_ep_param.c delete mode 100644 src/dashbls/depends/relic/src/ep/relic_ep_pck.c delete mode 100644 src/dashbls/depends/relic/src/ep/relic_ep_psi.c delete mode 100644 src/dashbls/depends/relic/src/ep/relic_ep_util.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep2_add.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep2_cmp.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep2_curve.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep2_dbl.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep2_frb.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep2_map.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep2_mul.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep2_mul_cof.c delete mode 100755 src/dashbls/depends/relic/src/epx/relic_ep2_mul_fix.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep2_mul_sim.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep2_neg.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep2_norm.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep2_pck.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep2_util.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep4_add.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep4_cmp.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep4_curve.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep4_dbl.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep4_frb.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep4_map.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep4_mul.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep4_mul_cof.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep4_mul_fix.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep4_mul_sim.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep4_neg.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep4_norm.c delete mode 100644 src/dashbls/depends/relic/src/epx/relic_ep4_util.c delete mode 100644 src/dashbls/depends/relic/src/fb/relic_fb_add.c delete mode 100644 src/dashbls/depends/relic/src/fb/relic_fb_cmp.c delete mode 100644 src/dashbls/depends/relic/src/fb/relic_fb_exp.c delete mode 100644 src/dashbls/depends/relic/src/fb/relic_fb_inv.c delete mode 100644 src/dashbls/depends/relic/src/fb/relic_fb_itr.c delete mode 100644 src/dashbls/depends/relic/src/fb/relic_fb_mul.c delete mode 100644 src/dashbls/depends/relic/src/fb/relic_fb_param.c delete mode 100644 src/dashbls/depends/relic/src/fb/relic_fb_poly.c delete mode 100644 src/dashbls/depends/relic/src/fb/relic_fb_rdc.c delete mode 100644 src/dashbls/depends/relic/src/fb/relic_fb_shift.c delete mode 100644 src/dashbls/depends/relic/src/fb/relic_fb_slv.c delete mode 100644 src/dashbls/depends/relic/src/fb/relic_fb_sqr.c delete mode 100644 src/dashbls/depends/relic/src/fb/relic_fb_srt.c delete mode 100644 src/dashbls/depends/relic/src/fb/relic_fb_trc.c delete mode 100644 src/dashbls/depends/relic/src/fb/relic_fb_util.c delete mode 100644 src/dashbls/depends/relic/src/fbx/relic_fb2_inv.c delete mode 100644 src/dashbls/depends/relic/src/fbx/relic_fb2_mul.c delete mode 100644 src/dashbls/depends/relic/src/fbx/relic_fb2_slv.c delete mode 100644 src/dashbls/depends/relic/src/fbx/relic_fb2_sqr.c delete mode 100644 src/dashbls/depends/relic/src/fp/relic_fp_add.c delete mode 100644 src/dashbls/depends/relic/src/fp/relic_fp_cmp.c delete mode 100644 src/dashbls/depends/relic/src/fp/relic_fp_exp.c delete mode 100644 src/dashbls/depends/relic/src/fp/relic_fp_inv.c delete mode 100644 src/dashbls/depends/relic/src/fp/relic_fp_mul.c delete mode 100644 src/dashbls/depends/relic/src/fp/relic_fp_param.c delete mode 100644 src/dashbls/depends/relic/src/fp/relic_fp_prime.c delete mode 100644 src/dashbls/depends/relic/src/fp/relic_fp_rdc.c delete mode 100644 src/dashbls/depends/relic/src/fp/relic_fp_shift.c delete mode 100644 src/dashbls/depends/relic/src/fp/relic_fp_sqr.c delete mode 100644 src/dashbls/depends/relic/src/fp/relic_fp_srt.c delete mode 100644 src/dashbls/depends/relic/src/fp/relic_fp_util.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp12_mul.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp12_sqr.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp18_mul.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp18_sqr.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp24_mul.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp24_sqr.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp2_mul.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp2_sqr.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp3_mul.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp3_sqr.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp48_mul.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp48_sqr.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp4_mul.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp4_sqr.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp54_mul.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp54_sqr.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp6_mul.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp6_sqr.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp8_mul.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp8_sqr.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp9_mul.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fp9_sqr.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fpx_add.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fpx_cmp.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fpx_cyc.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fpx_exp.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fpx_field.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fpx_frb.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fpx_inv.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fpx_pck.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fpx_rdc.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fpx_srt.c delete mode 100644 src/dashbls/depends/relic/src/fpx/relic_fpx_util.c delete mode 100644 src/dashbls/depends/relic/src/low/arm-asm-254/relic_fp_add_low.c delete mode 100644 src/dashbls/depends/relic/src/low/arm-asm-254/relic_fp_add_low.s delete mode 100644 src/dashbls/depends/relic/src/low/arm-asm-254/relic_fp_mul_low.c delete mode 100644 src/dashbls/depends/relic/src/low/arm-asm-254/relic_fp_mul_low.s delete mode 100644 src/dashbls/depends/relic/src/low/arm-asm-254/relic_fp_rdc_low.c delete mode 100644 src/dashbls/depends/relic/src/low/arm-asm-254/relic_fp_rdc_low.s delete mode 100755 src/dashbls/depends/relic/src/low/avr-asm-158/relic_bn_add_low.s delete mode 100755 src/dashbls/depends/relic/src/low/avr-asm-158/relic_bn_shift_low.c delete mode 100755 src/dashbls/depends/relic/src/low/avr-asm-158/relic_bn_shift_low.s delete mode 100644 src/dashbls/depends/relic/src/low/avr-asm-158/relic_fp_add_low.c delete mode 100755 src/dashbls/depends/relic/src/low/avr-asm-158/relic_fp_add_low.s delete mode 100644 src/dashbls/depends/relic/src/low/avr-asm-158/relic_fp_mul_low.c delete mode 100755 src/dashbls/depends/relic/src/low/avr-asm-158/relic_fp_mul_low.s delete mode 100644 src/dashbls/depends/relic/src/low/avr-asm-158/relic_fp_rdc_low.c delete mode 100755 src/dashbls/depends/relic/src/low/avr-asm-158/relic_fp_rdc_low.s delete mode 100755 src/dashbls/depends/relic/src/low/avr-asm-158/relic_fp_shift_low.c delete mode 100755 src/dashbls/depends/relic/src/low/avr-asm-158/relic_fp_shift_low.s delete mode 100644 src/dashbls/depends/relic/src/low/avr-asm-158/relic_fp_sqr_low.c delete mode 100755 src/dashbls/depends/relic/src/low/avr-asm-158/relic_fp_sqr_low.s delete mode 100755 src/dashbls/depends/relic/src/low/avr-asm-163/relic_bn_add_low.s delete mode 100755 src/dashbls/depends/relic/src/low/avr-asm-163/relic_bn_shift_low.c delete mode 100755 src/dashbls/depends/relic/src/low/avr-asm-163/relic_bn_shift_low.s delete mode 100755 src/dashbls/depends/relic/src/low/avr-asm-163/relic_fb_add_low.c delete mode 100755 src/dashbls/depends/relic/src/low/avr-asm-163/relic_fb_add_low.s delete mode 100755 src/dashbls/depends/relic/src/low/avr-asm-163/relic_fb_mul_low.c delete mode 100755 src/dashbls/depends/relic/src/low/avr-asm-163/relic_fb_mul_low.s delete mode 100755 src/dashbls/depends/relic/src/low/avr-asm-163/relic_fb_shift_low.c delete mode 100755 src/dashbls/depends/relic/src/low/avr-asm-163/relic_fb_shift_low.s delete mode 100755 src/dashbls/depends/relic/src/low/avr-asm-163/relic_fb_sqr_low.c delete mode 100755 src/dashbls/depends/relic/src/low/avr-asm-163/relic_fb_sqr_low.s delete mode 100644 src/dashbls/depends/relic/src/low/curve2251-sse/CMakeLists.txt delete mode 100755 src/dashbls/depends/relic/src/low/curve2251-sse/macros.h delete mode 100755 src/dashbls/depends/relic/src/low/curve2251-sse/relic_fb_add_low.c delete mode 100755 src/dashbls/depends/relic/src/low/curve2251-sse/relic_fb_inv_low.c delete mode 100644 src/dashbls/depends/relic/src/low/curve2251-sse/relic_fb_itr_low.c delete mode 100755 src/dashbls/depends/relic/src/low/curve2251-sse/relic_fb_mul_low.c delete mode 100755 src/dashbls/depends/relic/src/low/curve2251-sse/relic_fb_mul_low_cl.c delete mode 100755 src/dashbls/depends/relic/src/low/curve2251-sse/relic_fb_mul_low_ld.c delete mode 100755 src/dashbls/depends/relic/src/low/curve2251-sse/relic_fb_mul_low_sf.c delete mode 100755 src/dashbls/depends/relic/src/low/curve2251-sse/relic_fb_rdc_low.c delete mode 100755 src/dashbls/depends/relic/src/low/curve2251-sse/relic_fb_slv_low.c delete mode 100755 src/dashbls/depends/relic/src/low/curve2251-sse/relic_fb_sqr_low.c delete mode 100755 src/dashbls/depends/relic/src/low/curve2251-sse/relic_fb_srt_low.c delete mode 100644 src/dashbls/depends/relic/src/low/curve2251-sse/relic_fb_trc_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_bn_add_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_bn_div_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_bn_mod_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_bn_mul_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_bn_shift_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_bn_sqr_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_fb_add_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_fb_inv_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_fb_itr_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_fb_mul_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_fb_rdc_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_fb_shift_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_fb_slv_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_fb_sqr_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_fb_srt_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_fb_trc_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_fp_add_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_fp_inv_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_fp_mul_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_fp_rdc_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_fp_shift_low.c delete mode 100644 src/dashbls/depends/relic/src/low/easy/relic_fp_sqr_low.c delete mode 100755 src/dashbls/depends/relic/src/low/easy/relic_fpx_add_low.c delete mode 100755 src/dashbls/depends/relic/src/low/easy/relic_fpx_mul_low.c delete mode 100755 src/dashbls/depends/relic/src/low/easy/relic_fpx_rdc_low.c delete mode 100755 src/dashbls/depends/relic/src/low/easy/relic_fpx_sqr_low.c delete mode 100644 src/dashbls/depends/relic/src/low/fiat/CMakeLists.txt delete mode 100644 src/dashbls/depends/relic/src/low/fiat/relic_fp_add_low.tmpl delete mode 100644 src/dashbls/depends/relic/src/low/fiat/relic_fp_mul_low.tmpl delete mode 100644 src/dashbls/depends/relic/src/low/fiat/relic_fp_sqr_low.tmpl delete mode 100644 src/dashbls/depends/relic/src/low/gmp-sec/relic_bn_add_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp-sec/relic_bn_div_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp-sec/relic_bn_mod_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp-sec/relic_bn_mul_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp-sec/relic_bn_shift_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp-sec/relic_bn_sqr_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp-sec/relic_fp_add_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp-sec/relic_fp_inv_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp-sec/relic_fp_mul_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp-sec/relic_fp_rdc_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp-sec/relic_fp_shift_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp-sec/relic_fp_sqr_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp/relic_bn_add_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp/relic_bn_div_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp/relic_bn_mod_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp/relic_bn_mul_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp/relic_bn_shift_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp/relic_bn_sqr_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp/relic_fb_add_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp/relic_fb_shift_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp/relic_fp_add_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp/relic_fp_inv_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp/relic_fp_mul_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp/relic_fp_rdc_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp/relic_fp_shift_low.c delete mode 100644 src/dashbls/depends/relic/src/low/gmp/relic_fp_sqr_low.c delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fb_mul_163_ld.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fb_mul_271_ld.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fb_mul_271_ld_k2.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fb_mul_283_ld.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fb_mul_353_ld_k2.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fb_mul_353_ld_k3.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fb_srt_271_penta.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fb_srt_353_trino.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fp_mul32_160_comba.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fp_mul32_256_comba.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fp_mul_128_comba.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fp_mul_160_comba.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fp_rdc32_160_montgomery_sparse.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fp_rdc32_256_montgomery_sparse.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fp_rdc_160_montgomery_sparse.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fp_rdc_256_montgomery_sparse.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fp_rdc_256p1.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fp_sqr32_160_comba.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fp_sqr32_256_comba.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fp_sqr_128_comba.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/fp_sqr_160_comba.inc delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_bn_add_low.c delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_bn_add_low.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_bn_shift_low.c delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_bn_shift_low.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_add_low.c delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_add_low.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_mul_low.c delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_mul_low.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_mul_low_163.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_mul_low_271.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_mul_low_283.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_mul_low_353.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_mul_low_353_k3.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_rdc_low.c delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_rdc_low.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_rdc_low_163.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_rdc_low_271.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_rdc_low_283.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_rdc_low_353.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_shift_low.c delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_shift_low.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_sqr_low.c delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_sqr_low.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_srt_low.c delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fb_srt_low.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fp_add_low.c delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fp_add_low.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fp_inv_low.c delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fp_mul_low.c delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fp_mul_low.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fp_mul_low_160.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fp_mul_low_256.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fp_rdc_low.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fp_rdc_low_160k1.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fp_rdc_low_160p1.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fp_rdc_low_256k1.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fp_rdc_low_256p1.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fp_sqr_low.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fp_sqr_low_160.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fp_sqr_low_256.s delete mode 100644 src/dashbls/depends/relic/src/low/msp-asm/relic_fpx_add_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-446/CMakeLists.txt delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-446/macro.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-446/relic_fp_add_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-446/relic_fp_inv_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-446/relic_fp_inv_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-446/relic_fp_mul_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-446/relic_fp_mul_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-446/relic_fp_rdc_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-446/relic_fp_rdc_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-446/relic_fp_shift_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-446/relic_fp_shift_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-446/relic_fp_sqr_low.c delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-455/CMakeLists.txt delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-455/macro.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-455/relic_fp_add_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-455/relic_fp_inv_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-455/relic_fp_inv_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-455/relic_fp_mul_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-455/relic_fp_mul_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-455/relic_fp_rdc_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-455/relic_fp_rdc_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-455/relic_fp_shift_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-455/relic_fp_shift_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-455/relic_fp_sqr_low.c delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-4l/CMakeLists.txt delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-4l/macro.s delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-4l/relic_fp_add_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-4l/relic_fp_inv_low.c delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-4l/relic_fp_mul_low.c delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-4l/relic_fp_mul_low.s delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-4l/relic_fp_rdc_low.c delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-4l/relic_fp_rdc_low.s delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-4l/relic_fp_shift_low.c delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-4l/relic_fp_shift_low.s delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-4l/relic_fp_sqr_low.c delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-4l/relic_fp_sqr_low.s delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-4l/relic_fpx_add_low.c delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-4l/relic_fpx_add_low.s delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-4l/relic_fpx_mul_low.c delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-4l/relic_fpx_mul_low.s delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-4l/relic_fpx_rdc_low.c delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-4l/relic_fpx_rdc_low.s delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-4l/relic_fpx_sqr_low.c delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-4l/relic_fpx_sqr_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-544/CMakeLists.txt delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-544/macro.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-544/relic_fp_add_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-544/relic_fp_mul_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-544/relic_fp_mul_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-544/relic_fp_rdc_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-544/relic_fp_rdc_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-544/relic_fp_sqr_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-544/relic_fpx_add_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-544/relic_fpx_mul_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-544/relic_fpx_rdc_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-544/relic_fpx_rdc_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-544/relic_fpx_sqr_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-638/CMakeLists.txt delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-638/macro.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-638/relic_fp_add_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-638/relic_fp_mul_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-638/relic_fp_mul_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-638/relic_fp_rdc_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-638/relic_fp_rdc_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-638/relic_fp_sqr_low.c delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-638/relic_fpx_rdc_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-638/relic_fpx_rdc_low.s delete mode 100755 src/dashbls/depends/relic/src/low/x64-asm-6l/CMakeLists.txt delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-6l/macro.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-6l/relic_fp_add_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-6l/relic_fp_inv_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-6l/relic_fp_mul_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-6l/relic_fp_mul_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-6l/relic_fp_rdc_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-6l/relic_fp_rdc_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-6l/relic_fp_shift_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-6l/relic_fp_shift_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-6l/relic_fp_sqr_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-8l/CMakeLists.txt delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-8l/macro.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-8l/relic_fp_add_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-8l/relic_fp_inv_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-8l/relic_fp_inv_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-8l/relic_fp_mul_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-8l/relic_fp_mul_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-8l/relic_fp_rdc_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-8l/relic_fp_rdc_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-8l/relic_fp_shift_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-8l/relic_fp_shift_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-8l/relic_fp_sqr_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-9l/CMakeLists.txt delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-9l/macro.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-9l/relic_fp_add_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-9l/relic_fp_mul_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-9l/relic_fp_mul_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-9l/relic_fp_rdc_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-9l/relic_fp_rdc_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-9l/relic_fp_sqr_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-9l/relic_fpx_rdc_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-asm-9l/relic_fpx_rdc_low.s delete mode 100644 src/dashbls/depends/relic/src/low/x64-fiat-381/CMakeLists.txt delete mode 100644 src/dashbls/depends/relic/src/low/x64-fiat-381/bls12_381_q_64.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-fiat-381/relic_fp_add_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-fiat-381/relic_fp_inv_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-fiat-381/relic_fp_mul_low.c delete mode 100644 src/dashbls/depends/relic/src/low/x64-fiat-381/relic_fp_sqr_low.c delete mode 100644 src/dashbls/depends/relic/src/md/blake2-impl.h delete mode 100644 src/dashbls/depends/relic/src/md/blake2.h delete mode 100644 src/dashbls/depends/relic/src/md/blake2_COPYING delete mode 100644 src/dashbls/depends/relic/src/md/blake2s-ref.c delete mode 100644 src/dashbls/depends/relic/src/md/relic_md_blake2s.c delete mode 100644 src/dashbls/depends/relic/src/md/relic_md_hmac.c delete mode 100644 src/dashbls/depends/relic/src/md/relic_md_kdf.c delete mode 100644 src/dashbls/depends/relic/src/md/relic_md_mgf.c delete mode 100644 src/dashbls/depends/relic/src/md/relic_md_sha224.c delete mode 100644 src/dashbls/depends/relic/src/md/relic_md_sha256.c delete mode 100644 src/dashbls/depends/relic/src/md/relic_md_sha384.c delete mode 100644 src/dashbls/depends/relic/src/md/relic_md_sha512.c delete mode 100644 src/dashbls/depends/relic/src/md/relic_md_xmd.c delete mode 100644 src/dashbls/depends/relic/src/md/sha.h delete mode 100644 src/dashbls/depends/relic/src/md/sha224-256.c delete mode 100644 src/dashbls/depends/relic/src/md/sha384-512.c delete mode 100644 src/dashbls/depends/relic/src/md/sha_private.h delete mode 100644 src/dashbls/depends/relic/src/mpc/relic_mt_mpc.c delete mode 100644 src/dashbls/depends/relic/src/mpc/relic_pc_mpc.c delete mode 100644 src/dashbls/depends/relic/src/pc/relic_pc_core.c delete mode 100644 src/dashbls/depends/relic/src/pc/relic_pc_exp.c delete mode 100644 src/dashbls/depends/relic/src/pc/relic_pc_util.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_add_k12.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_add_k2.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_add_k24.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_add_k48.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_add_k54.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_add_k8.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_dbl_k12.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_dbl_k2.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_dbl_k24.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_dbl_k48.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_dbl_k54.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_dbl_k8.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_exp_k12.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_exp_k2.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_exp_k24.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_exp_k48.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_exp_k54.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_exp_k8.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_map.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_map_k12.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_map_k2.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_map_k24.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_map_k48.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_map_k54.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_map_k8.c delete mode 100644 src/dashbls/depends/relic/src/pp/relic_pp_norm.c delete mode 100644 src/dashbls/depends/relic/src/rand/relic_rand_call.c delete mode 100644 src/dashbls/depends/relic/src/rand/relic_rand_core.c delete mode 100644 src/dashbls/depends/relic/src/rand/relic_rand_hashd.c delete mode 100644 src/dashbls/depends/relic/src/rand/relic_rand_rdrnd.c delete mode 100644 src/dashbls/depends/relic/src/rand/relic_rand_udev.c delete mode 100644 src/dashbls/depends/relic/src/relic_bench.c delete mode 100644 src/dashbls/depends/relic/src/relic_conf.c delete mode 100644 src/dashbls/depends/relic/src/relic_core.c delete mode 100644 src/dashbls/depends/relic/src/relic_err.c delete mode 100644 src/dashbls/depends/relic/src/relic_test.c delete mode 100644 src/dashbls/depends/relic/src/relic_util.c delete mode 100644 src/dashbls/depends/relic/src/tmpl/relic_tmpl_map.h delete mode 100644 src/dashbls/depends/relic/test/CMakeLists.txt delete mode 100644 src/dashbls/depends/relic/test/test_bn.c delete mode 100644 src/dashbls/depends/relic/test/test_core.c delete mode 100644 src/dashbls/depends/relic/test/test_cp.c delete mode 100644 src/dashbls/depends/relic/test/test_dv.c delete mode 100644 src/dashbls/depends/relic/test/test_eb.c delete mode 100644 src/dashbls/depends/relic/test/test_ec.c delete mode 100644 src/dashbls/depends/relic/test/test_ed.c delete mode 100644 src/dashbls/depends/relic/test/test_ep.c delete mode 100644 src/dashbls/depends/relic/test/test_epx.c delete mode 100644 src/dashbls/depends/relic/test/test_err.c delete mode 100644 src/dashbls/depends/relic/test/test_fb.c delete mode 100644 src/dashbls/depends/relic/test/test_fbx.c delete mode 100644 src/dashbls/depends/relic/test/test_fp.c delete mode 100644 src/dashbls/depends/relic/test/test_fpx.c delete mode 100644 src/dashbls/depends/relic/test/test_md.c delete mode 100644 src/dashbls/depends/relic/test/test_mpc.c delete mode 100644 src/dashbls/depends/relic/test/test_pc.c delete mode 100644 src/dashbls/depends/relic/test/test_pp.c delete mode 100644 src/dashbls/depends/relic/test/test_rand.c delete mode 100755 src/dashbls/depends/relic/tools/git-creation-date.sh delete mode 100755 src/dashbls/depends/relic/tools/relic_gen_label.sh delete mode 100755 src/dashbls/emsdk_build.sh delete mode 100644 src/dashbls/go-bindings/.gitignore delete mode 100644 src/dashbls/go-bindings/Makefile delete mode 100644 src/dashbls/go-bindings/README.md delete mode 100644 src/dashbls/go-bindings/blschia.cpp delete mode 100644 src/dashbls/go-bindings/blschia.h delete mode 100644 src/dashbls/go-bindings/elements.cpp delete mode 100644 src/dashbls/go-bindings/elements.go delete mode 100644 src/dashbls/go-bindings/elements.h delete mode 100644 src/dashbls/go-bindings/error.go delete mode 100644 src/dashbls/go-bindings/error.h delete mode 100644 src/dashbls/go-bindings/go.mod delete mode 100644 src/dashbls/go-bindings/go.sum delete mode 100644 src/dashbls/go-bindings/privatekey.cpp delete mode 100644 src/dashbls/go-bindings/privatekey.go delete mode 100644 src/dashbls/go-bindings/privatekey.h delete mode 100644 src/dashbls/go-bindings/schemes.cpp delete mode 100644 src/dashbls/go-bindings/schemes.go delete mode 100644 src/dashbls/go-bindings/schemes.h delete mode 100644 src/dashbls/go-bindings/schemes_test.go delete mode 100644 src/dashbls/go-bindings/threshold.cpp delete mode 100644 src/dashbls/go-bindings/threshold.go delete mode 100644 src/dashbls/go-bindings/threshold.h delete mode 100644 src/dashbls/go-bindings/threshold_test.go delete mode 100644 src/dashbls/go-bindings/util.go delete mode 100644 src/dashbls/go-bindings/util_test.go delete mode 100644 src/dashbls/go-bindings/utils.cpp delete mode 100644 src/dashbls/go-bindings/utils.hpp delete mode 100644 src/dashbls/js-bindings/CMakeLists.txt delete mode 100644 src/dashbls/js-bindings/README.md delete mode 100644 src/dashbls/js-bindings/blsjs.d.ts delete mode 100644 src/dashbls/js-bindings/bundle_wasm_for_web.js delete mode 100644 src/dashbls/js-bindings/helpers.cpp delete mode 100644 src/dashbls/js-bindings/helpers.h delete mode 100644 src/dashbls/js-bindings/jsbindings.cpp delete mode 100644 src/dashbls/js-bindings/package-lock.json delete mode 100644 src/dashbls/js-bindings/package.json delete mode 100644 src/dashbls/js-bindings/tests/PrivateKey.spec.js delete mode 100644 src/dashbls/js-bindings/tests/PublicKey.spec.js delete mode 100644 src/dashbls/js-bindings/tests/Signature.spec.js delete mode 100644 src/dashbls/js-bindings/tests/karma.conf.js delete mode 100644 src/dashbls/js-bindings/tests/karma.test.js delete mode 100644 src/dashbls/js-bindings/tests/test.js delete mode 100644 src/dashbls/js-bindings/tests/typings.spec.ts delete mode 100644 src/dashbls/js-bindings/tests/webpack.config.js delete mode 100644 src/dashbls/js-bindings/tests/yarn.lock delete mode 100644 src/dashbls/js-bindings/wrappers/G1ElementWrapper.cpp delete mode 100644 src/dashbls/js-bindings/wrappers/G1ElementWrapper.h delete mode 100644 src/dashbls/js-bindings/wrappers/G2ElementWrapper.cpp delete mode 100644 src/dashbls/js-bindings/wrappers/G2ElementWrapper.h delete mode 100644 src/dashbls/js-bindings/wrappers/JSWrapper.h delete mode 100644 src/dashbls/js-bindings/wrappers/PrivateKeyWrapper.cpp delete mode 100644 src/dashbls/js-bindings/wrappers/PrivateKeyWrapper.h delete mode 100644 src/dashbls/js-bindings/wrappers/SchemeMPLWrapper.cpp delete mode 100644 src/dashbls/js-bindings/wrappers/SchemeMPLWrapper.h delete mode 100644 src/dashbls/js-bindings/wrappers/UtilWrapper.cpp delete mode 100644 src/dashbls/js-bindings/wrappers/UtilWrapper.h delete mode 100755 src/dashbls/js_build.sh delete mode 100755 src/dashbls/js_build_docker.sh delete mode 100755 src/dashbls/js_test.sh delete mode 100644 src/dashbls/pyproject.toml delete mode 100644 src/dashbls/rust-bindings/.gitignore delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/.rustfmt.toml delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/Cargo.toml delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/bindings.rs delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/build.rs delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/c-bindings/bip32/chaincode.cpp delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/c-bindings/bip32/chaincode.h delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/c-bindings/bip32/extendedprivatekey.cpp delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/c-bindings/bip32/extendedprivatekey.h delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/c-bindings/bip32/extendedpublickey.cpp delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/c-bindings/bip32/extendedpublickey.h delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/c-bindings/blschia.cpp delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/c-bindings/blschia.h delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/c-bindings/elements.cpp delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/c-bindings/elements.h delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/c-bindings/error.h delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/c-bindings/privatekey.cpp delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/c-bindings/privatekey.h delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/c-bindings/schemes.cpp delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/c-bindings/schemes.h delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/c-bindings/threshold.cpp delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/c-bindings/threshold.h delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/c-bindings/utils.cpp delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/c-bindings/utils.hpp delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/include.h delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/src/lib.rs delete mode 100644 src/dashbls/rust-bindings/bls-dash-sys/tests/sign_and_verify.rs delete mode 100644 src/dashbls/rust-bindings/bls-signatures/.rustfmt.toml delete mode 100644 src/dashbls/rust-bindings/bls-signatures/Cargo.toml delete mode 100644 src/dashbls/rust-bindings/bls-signatures/src/bip32/chain_code.rs delete mode 100644 src/dashbls/rust-bindings/bls-signatures/src/bip32/mod.rs delete mode 100644 src/dashbls/rust-bindings/bls-signatures/src/bip32/private_key.rs delete mode 100644 src/dashbls/rust-bindings/bls-signatures/src/bip32/public_key.rs delete mode 100644 src/dashbls/rust-bindings/bls-signatures/src/elements.rs delete mode 100644 src/dashbls/rust-bindings/bls-signatures/src/legacy/bip32/mod.rs delete mode 100644 src/dashbls/rust-bindings/bls-signatures/src/legacy/bip32/private_key.rs delete mode 100644 src/dashbls/rust-bindings/bls-signatures/src/legacy/bip32/public_key.rs delete mode 100644 src/dashbls/rust-bindings/bls-signatures/src/legacy/elements.rs delete mode 100644 src/dashbls/rust-bindings/bls-signatures/src/legacy/mod.rs delete mode 100644 src/dashbls/rust-bindings/bls-signatures/src/lib.rs delete mode 100755 src/dashbls/rust-bindings/bls-signatures/src/private_key.rs delete mode 100644 src/dashbls/rust-bindings/bls-signatures/src/schemes.rs delete mode 100644 src/dashbls/rust-bindings/bls-signatures/src/utils.rs delete mode 100644 src/dashbls/rust-bindings/example/Cargo.toml delete mode 100644 src/dashbls/rust-bindings/example/src/main.rs delete mode 100644 src/dashbls/setjmp_patch.diff delete mode 100644 src/dashbls/setup.py delete mode 100644 src/dashbls/src/CMakeLists.txt delete mode 100644 src/dashbls/src/test-bench.cpp delete mode 100644 src/dashbls/tools/fuzzgen.cpp diff --git a/.gitignore b/.gitignore index eab9f3f83ec1..92498def678c 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ src/dash-chainstate src/dash-wallet src/test/fuzz/fuzz src/test/test_dash +src/dashbls/runtest src/qt/test/test_dash-qt src/qt/res/css/colors/* src/bench/bench_dash diff --git a/contrib/debian/copyright b/contrib/debian/copyright index 19302d80a525..b013ca8168dc 100644 --- a/contrib/debian/copyright +++ b/contrib/debian/copyright @@ -27,6 +27,17 @@ Files: src/qt/res/fonts/RobotoMono-Bold.ttf License: Apache-2.0 Comment: Site: https://fonts.google.com/specimen/Roboto+Mono +Files: src/dashbls/* +Copyright: 2018-present Chia Network Inc. + 2021-present The Dash Core developers +License: Apache-2.0 +Comment: Site: https://github.com/dashpay/bls-signatures + +Files: src/dashbls/depends/mimalloc/* +Copyright: 2018-2025 Microsoft Corporation, Daan Leijen +License: Expat +Comment: Site: https://github.com/microsoft/mimalloc + License: Expat Permission is hereby granted, free of charge, to any person obtaining a diff --git a/src/dashbls/.github/scripts/build_simple_index.py b/src/dashbls/.github/scripts/build_simple_index.py deleted file mode 100755 index e5554ed9e9bf..000000000000 --- a/src/dashbls/.github/scripts/build_simple_index.py +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env python3 -# coding: latin-1 - -# -# Copyright (c) 2026-present, Microsoft Corporation -# Copyright (c) 2026-present, The Dash Core developers -# SPDX-License-Identifier: MIT -# - -"""Generate a PEP 503 index for released distributions.""" - -import argparse -import json -import os -import re -import subprocess -import sys -from html import escape -from pathlib import Path - -# PEP 503: lowercase, runs of -_. collapsed to a single - -NAME = "dashbls" -NORMALISED = re.sub(r"[-_.]+", "-", NAME).lower() - -# Must match requires-python in pyproject.toml. -REQUIRES_PYTHON = ">=3.10" - - -def releases(repo: str) -> list[dict]: - """Every release of `repo`, each with the name, URL and digest of its assets.""" - out = subprocess.check_output( # noqa: S603 - [ # noqa: S607 - "gh", - "api", - "--paginate", - f"repos/{repo}/releases", - "--jq", - ".[] | select(.draft | not) | {tag: .tag_name, assets: [.assets[] " - "| {name, url: .browser_download_url, digest}]}", - ], - text=True, - ) - return [json.loads(line) for line in out.splitlines() if line.strip()] - - -def anchor(name: str, url: str, digest: str | None) -> str: - """One link, with the hash pip needs to verify what it downloaded. - - The releases API reports a digest as "sha256:", which is the PEP 503 - fragment in all but spelling. Without it pip has no integrity check at all - and --require-hashes has nothing to match against. - """ - if digest and digest.startswith("sha256:"): - url = f"{url}#sha256={digest.removeprefix('sha256:')}" - return ( - f' {escape(name)}
' - ) - - -def main() -> None: - parser = argparse.ArgumentParser() - parser.add_argument("--output", required=True, type=Path) - parser.add_argument( - "--repo", default=os.environ.get("GITHUB_REPOSITORY", "dashpay/bls-signatures") - ) - args = parser.parse_args() - - # Sdists matter as much as wheels here: they are the only thing installable - # on a platform we do not ship a wheel for, and pip will not find one that - # the index does not list. - files = [] - for release in releases(args.repo): - for asset in release["assets"]: - if asset["name"].endswith((".whl", ".tar.gz")): - files.append((asset["name"], asset["url"], asset.get("digest"))) - files.sort() - if not files: - sys.exit("no distributions found on any release; refusing to publish an empty index") - - project = args.output / "pep503" / NORMALISED - project.mkdir(parents=True, exist_ok=True) - - # pypi:repository-version is PEP 629; charset because the filenames are - # written by whatever runner built them. - head = '\n' - anchors = "\n".join(anchor(*dist) for dist in files) - (project / "index.html").write_text( - f"\n{head}\nLinks for {NAME}\n" - f"\n

Links for {NAME}

\n{anchors}\n\n", - encoding="utf-8", - ) - (args.output / "pep503" / "index.html").write_text( - f"\n{head}\nSimple Index\n" - "\n" - f' {NAME}
\n' - "\n", - encoding="utf-8", - ) - print(f"indexed {len(files)} distributions for {NAME}") - - -if __name__ == "__main__": - main() diff --git a/src/dashbls/.github/workflows/binds-go.yml b/src/dashbls/.github/workflows/binds-go.yml deleted file mode 100644 index ccda3c190131..000000000000 --- a/src/dashbls/.github/workflows/binds-go.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: Binds (Go) - -on: - workflow_call: - workflow_dispatch: - -permissions: - contents: read - -jobs: - build: - name: ${{ matrix.os }}, Go ${{ matrix.golang }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [macos-latest, ubuntu-24.04-arm] - golang: [ '1.24' ] - - steps: - - name: Checkout code - uses: actions/checkout@v6 - with: - persist-credentials: false - - - name: Install Go - uses: actions/setup-go@v7 - with: - go-version: ^${{ matrix.golang }} - - - name: Prepare build system for Ubuntu - if: startsWith(matrix.os, 'ubuntu') - run: | - sudo apt-get update - sudo apt-get install -qq --yes valgrind libgmp-dev cmake - hash -r - cmake --version - - - name: Prepare build system for macOS - if: startsWith(matrix.os, 'macos') - run: | - brew install gmp - - - name: Build library using CMake - run: | - cores=$(getconf _NPROCESSORS_ONLN) - jobs=$(( cores > 1 ? cores - 1 : 1 )) - mkdir -p build && cd build - cmake .. -DCMAKE_BUILD_TYPE=Debug - cmake --build . --parallel "$jobs" - - - name: Build bindings - run: | - cd go-bindings - make config - make diff --git a/src/dashbls/.github/workflows/binds-js.yml b/src/dashbls/.github/workflows/binds-js.yml deleted file mode 100644 index fa9bbf15d798..000000000000 --- a/src/dashbls/.github/workflows/binds-js.yml +++ /dev/null @@ -1,94 +0,0 @@ -name: Binds (Javascript) - -on: - workflow_call: - secrets: - NPM_TOKEN: - description: Token used to publish the package to the npm registry - required: false - workflow_dispatch: - -permissions: - contents: read - -jobs: - build: - name: ${{ matrix.os }}, Javascript - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [macos-latest, ubuntu-24.04-arm] - - steps: - - name: Checkout code - uses: actions/checkout@v6 - with: - persist-credentials: false - - - name: Set up JDK - uses: actions/setup-java@v4 - with: - distribution: temurin - java-version: '21' - - - name: Install Emscripten SDK - uses: mymindstorm/setup-emsdk@v16 - - - name: Build JavaScript bindings - run: | - emcc -v - sh emsdk_build.sh - - - name: Test JavaScript bindings - run: | - sh js_test.sh - - publish: - name: Publish (releases), Javascript - if: startsWith(github.ref, 'refs/tags/') - needs: build - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v6 - with: - fetch-depth: 0 - persist-credentials: false - - - name: Set up JDK - uses: actions/setup-java@v4 - with: - distribution: temurin - java-version: '21' - - - name: Install Emscripten SDK - uses: mymindstorm/setup-emsdk@v16 - - - name: Set up Node - uses: actions/setup-node@v6 - with: - node-version: '20' - registry-url: https://registry.npmjs.org - - # emsdk_build.sh copies package.json into js_build/, so the version has to - # be rewritten in the source tree before the build runs. - - name: Update version in package.json - working-directory: js-bindings - env: - RELEASE: ${{ github.ref_name }} - run: | - jq --arg VER "${RELEASE#v}" '.version=$VER' package.json > temp.json - mv temp.json package.json - - - name: Build JavaScript bindings - run: | - emcc -v - sh emsdk_build.sh - - - name: Publish to npm - working-directory: js_build/js-bindings - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - run: npm publish --access public diff --git a/src/dashbls/.github/workflows/binds-py.yml b/src/dashbls/.github/workflows/binds-py.yml deleted file mode 100644 index 803fb37fa4f2..000000000000 --- a/src/dashbls/.github/workflows/binds-py.yml +++ /dev/null @@ -1,155 +0,0 @@ -name: Binds (Python) - -on: - workflow_call: - workflow_dispatch: - -permissions: - contents: read - -jobs: - lint: - name: Lint, Python - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v6 - with: - persist-credentials: false - - - name: Install uv - uses: astral-sh/setup-uv@v9.0.0 - - - name: Check lints - run: uvx ruff check --output-format=github . - - - name: Check formatting - run: uvx ruff format --check --diff . - - build: - name: Build (${{ matrix.name }}), Python - needs: lint - runs-on: ${{ matrix.runs-on }} - strategy: - fail-fast: false - matrix: - include: >- - ${{ fromJSON(startsWith(github.ref, 'refs/tags/') - && '[ - {"name": "linux-arm64", "runs-on": "ubuntu-24.04-arm", "archs": "aarch64"}, - {"name": "linux-amd64", "runs-on": "ubuntu-latest", "archs": "x86_64"}, - {"name": "macos-arm64", "runs-on": "macos-latest", "archs": "arm64", "macos-target": "14.0"}, - {"name": "macos-amd64", "runs-on": "macos-15-intel", "archs": "x86_64", "macos-target": "14.0"}, - {"name": "windows-amd64", "runs-on": "windows-latest", "archs": "AMD64"} - ]' - || '[ - {"name": "linux-arm64", "runs-on": "ubuntu-24.04-arm", "archs": "aarch64"}, - {"name": "macos-arm64", "runs-on": "macos-latest", "archs": "arm64", "macos-target": "14.0"}, - {"name": "windows-amd64", "runs-on": "windows-latest", "archs": "AMD64"} - ]') }} - - steps: - - name: Checkout code - uses: actions/checkout@v6 - with: - fetch-depth: 0 - persist-credentials: false - - - name: Install uv - uses: astral-sh/setup-uv@v9.0.0 - with: - enable-cache: false - - - name: Build and test wheels - uses: pypa/cibuildwheel@v4.1.1 - env: - CIBW_ARCHS: ${{ matrix.archs }} - MACOSX_DEPLOYMENT_TARGET: ${{ matrix.macos-target }} - - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: wheels-${{ matrix.name }} - path: wheelhouse/*.whl - if-no-files-found: error - - sdist: - name: Build (sdist), Python - needs: lint - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v6 - with: - fetch-depth: 0 - persist-credentials: false - - - name: Install uv - uses: astral-sh/setup-uv@v9.0.0 - - - name: Build the sdist - run: uv build --sdist --out-dir dist - - - name: Prepare build system - run: | - sudo apt-get update - sudo apt-get install -qq --yes libgmp-dev - - - name: Install from the sdist and run the unit tests - run: | - uv venv .venv-sdist - uv pip install --python .venv-sdist --no-binary=dashbls dist/*.tar.gz - uv pip install --python .venv-sdist pytest pytest-benchmark - .venv-sdist/bin/python -m pytest --import-mode=importlib -v binds/python/test_unit.py - - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: sdist - path: dist/*.tar.gz - if-no-files-found: error - - publish: - name: Publish (releases), Python - if: startsWith(github.ref, 'refs/tags/') - needs: [build, sdist] - runs-on: ubuntu-latest - permissions: - contents: write - - steps: - - name: Download artifacts - uses: actions/download-artifact@v4 - with: - pattern: wheels-* - merge-multiple: true - path: dist - - - name: Download the sdist - uses: actions/download-artifact@v4 - with: - name: sdist - path: dist - - - name: Attach the wheels and sdist to the release - env: - GH_TOKEN: ${{ github.token }} - GH_REPO: ${{ github.repository }} - RELEASE: ${{ github.ref_name }} - run: | - ls -l dist - # Pushing a tag does not create a release, and `upload` will not make one. - gh release view "$RELEASE" >/dev/null 2>&1 \ - || gh release create "$RELEASE" --verify-tag --generate-notes - gh release upload "$RELEASE" dist/*.whl dist/*.tar.gz --clobber - - index: - name: Publish (index), Python - needs: publish - permissions: - contents: read - pages: write - id-token: write - uses: ./.github/workflows/build-docs.yml diff --git a/src/dashbls/.github/workflows/binds-rs.yml b/src/dashbls/.github/workflows/binds-rs.yml deleted file mode 100644 index 8e3db323db12..000000000000 --- a/src/dashbls/.github/workflows/binds-rs.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Binds (Rust) - -on: - workflow_call: - workflow_dispatch: - -permissions: - contents: read - -jobs: - build: - name: ${{ matrix.os }}, Rust ${{ matrix.rust }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [macos-latest, ubuntu-24.04-arm] - rust: [ '1.91.0' ] - - steps: - - name: Checkout code - uses: actions/checkout@v6 - with: - persist-credentials: false - - - name: Prepare build system for Ubuntu - if: startsWith(matrix.os, 'ubuntu') - run: | - sudo apt-get update - sudo apt-get install -qq --yes valgrind libgmp-dev cmake - hash -r - cmake --version - - - name: Prepare build system for macOS - if: startsWith(matrix.os, 'macos') - run: | - brew install gmp - - - name: Install Rust - run: | - rustup toolchain install ${{ matrix.rust }} - rustup default ${{ matrix.rust }} - rustc --version - cargo --version - - - name: Build and test Rust bindings - run: | - cd rust-bindings/bls-dash-sys - cargo test diff --git a/src/dashbls/.github/workflows/build-binds.yml b/src/dashbls/.github/workflows/build-binds.yml deleted file mode 100644 index fa1f69e17779..000000000000 --- a/src/dashbls/.github/workflows/build-binds.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Build and test binds - -on: - push: - branches: - - main - tags: - - '**' - pull_request: - branches: - - '**' - -concurrency: - group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ (github.ref == 'refs/heads/main') && github.sha || '' }} - cancel-in-progress: true - -permissions: - contents: read - -jobs: - build-go: - name: Go - uses: ./.github/workflows/binds-go.yml - - build-js: - name: JavaScript - uses: ./.github/workflows/binds-js.yml - # Reusable workflows do not inherit secrets; the tagged publish needs this. - secrets: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - - build-rs: - name: Rust - uses: ./.github/workflows/binds-rs.yml - - build-py: - name: Python - permissions: - contents: write - pages: write - id-token: write - uses: ./.github/workflows/binds-py.yml diff --git a/src/dashbls/.github/workflows/build-docs.yml b/src/dashbls/.github/workflows/build-docs.yml deleted file mode 100644 index 4a65809772d5..000000000000 --- a/src/dashbls/.github/workflows/build-docs.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: Build docs - -on: - workflow_call: - workflow_dispatch: - -concurrency: - group: pages - cancel-in-progress: false - -permissions: - contents: read - pages: write - id-token: write - -jobs: - pep503: - name: Generate PEP503 index - runs-on: ubuntu-latest - environment: - name: github-pages - url: ${{ steps.deploy.outputs.page_url }} - - steps: - - name: Checkout code - uses: actions/checkout@v6 - with: - persist-credentials: false - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.10' - - - name: Generate index - env: - GH_TOKEN: ${{ github.token }} - GH_REPO: ${{ github.repository }} - run: python .github/scripts/build_simple_index.py --output _site - - - name: Configure GitHub Pages - uses: actions/configure-pages@v6 - - - name: Upload index - uses: actions/upload-pages-artifact@v5 - with: - path: _site - - - name: Deploy to GitHub Pages - id: deploy - uses: actions/deploy-pages@v5 diff --git a/src/dashbls/.github/workflows/build-test.yaml b/src/dashbls/.github/workflows/build-test.yaml deleted file mode 100644 index 6f6b319a9c57..000000000000 --- a/src/dashbls/.github/workflows/build-test.yaml +++ /dev/null @@ -1,71 +0,0 @@ -name: Build and test library - -on: - push: - branches: - - main - tags: - - '**' - pull_request: - branches: - - '**' - -concurrency: - # SHA is added to the end if on `main` to let all main workflows run - group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ (github.ref == 'refs/heads/main') && github.sha || '' }} - cancel-in-progress: true - -jobs: - build: - name: ${{ matrix.os }}, ${{ matrix.builder }}, ${{ matrix.compiler.cc }}, ${{ matrix.backend }} backend - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ macos-latest, ubuntu-latest ] - builder: [ cmake, autotools ] - compiler: - - cc: gcc - cxx: g++ - - cc: clang - cxx: clang++ - backend: [ easy, gmp ] - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Prepare build system for Ubuntu - if: startsWith(matrix.os, 'ubuntu') - run: | - sudo apt-get update - sudo apt-get install -qq --yes valgrind libgmp-dev cmake - hash -r - cmake --version - - - name: Prepare build system for macOS - if: startsWith(matrix.os, 'macos') - run: | - export MACOSX_DEPLOYMENT_TARGET=10.14 - brew install autoconf automake gmp libtool pkg-config - - - name: Build library using CMake - if: startsWith(matrix.builder, 'cmake') - run: | - mkdir -p build && cd build - CC=${{ matrix.compiler.cc }} CXX=${{ matrix.compiler.cxx }} cmake .. -DARITH=${{ matrix.backend }} -DBUILD_BLS_PYTHON_BINDINGS=0 -DCMAKE_BUILD_TYPE=Debug - cmake --build . -- -j 6 - mv src/runtest .. - - - name: Build library using GNU Autotools - if: startsWith(matrix.builder, 'autotools') - run: | - ./autogen.sh - CC=${{ matrix.compiler.cc }} CXX=${{ matrix.compiler.cxx }} ./configure --with-backend=${{ matrix.backend }} - make -j8 - - - name: Run tests - run: ./runtest - - - name: Run valgrind on Ubuntu - if: startsWith(matrix.os, 'ubuntu') - run: valgrind --leak-check=full --show-leak-kinds=all --errors-for-leak-kinds=all ./runtest diff --git a/src/dashbls/.github/workflows/stale-issue.yml b/src/dashbls/.github/workflows/stale-issue.yml deleted file mode 100644 index e3668dba6984..000000000000 --- a/src/dashbls/.github/workflows/stale-issue.yml +++ /dev/null @@ -1,35 +0,0 @@ ---- -name: 'Close stale issues' -on: - schedule: - - cron: '0 11 * * *' - -jobs: - stale: - runs-on: ubuntu-latest - steps: - - uses: chia-network/stale@main - with: - operations-per-run: 10000 - ascending: true - days-before-issue-stale: 14 - days-before-issue-close: 7 - days-before-pr-stale: 60 - days-before-pr-close: -1 - exempt-all-pr-milestones: true - exempt-all-issue-milestones: true - exempt-all-assignees: true - stale-issue-label: stale-issue - stale-pr-label: stale-pr - remove-stale-when-updated: true - stale-issue-message: > - 'This issue has been flagged as stale as there has been no - activity on it in 14 days. If this issue is still affecting you - and in need of review, please update it to keep it open.' - close-issue-message: > - 'This issue was automatically closed because it has been flagged - as stale and subsequently passed 7 days with no further activity.' - stale-pr-message: > - 'This PR has been flagged as stale due to no activity for over 60 - days. It will not be automatically closed, but it has been given - a stale-pr label and should be manually reviewed.' diff --git a/src/dashbls/.gitignore b/src/dashbls/.gitignore deleted file mode 100644 index ec8e23435253..000000000000 --- a/src/dashbls/.gitignore +++ /dev/null @@ -1,173 +0,0 @@ -CMakeCache.txt -CMakeFiles -cmake_install.cmake -Makefile -src/bench -src/test -src/MakefilE -src/cmake_install.cmake -src/CMakeFile -build/* -cmake-build-debug/ - -js_build -node_modules - -main -.o -obj/ -src/*.o - -.idea -.vscode -runtest -runtest.* -runbench -runbench.* - -.dirstamp -.libs -.*.swp -*.*~* -*.bak -*.rej -*.orig -*.o -*.o-* -*.patch -*.a -*.pb.cc -*.pb.h -*.lo -*.la - -**/.DS_Store - -*.whl -venv -env/ -yarn-error.log - -.vs/ -out/ - -target - -Makefile.in -/ar-lib -/mdate-sh -/py-compile -/test-driver -/ylwrap -.deps/ -.dirstamp -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 -configure -libtool - -autom4te.cache -/autoscan.log -/autoscan-*.log -/aclocal.m4 -/compile -/config.cache -/config.guess -/config.h.in -/config.log -/config.status -/config.sub -/configure -/configure.scan -/depcomp -/install-sh -/missing -/stamp-h1 -/ltmain.sh -/texinfo.tex - -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[codz] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py.cover -*.lcov -.hypothesis/ -.pytest_cache/ -cover/ - -# Environments -.env -.envrc -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Cython debug symbols -cython_debug/ - -# Temporary file for partial code execution -tempCodeRunnerFile.py - -# Ruff stuff: -.ruff_cache/ - -# PyPI configuration file -.pypirc - -# PEP503 index -_site diff --git a/src/dashbls/.python-version b/src/dashbls/.python-version deleted file mode 100644 index eae0123defaa..000000000000 --- a/src/dashbls/.python-version +++ /dev/null @@ -1 +0,0 @@ -3.10.19 diff --git a/src/dashbls/.vscode/extensions.json b/src/dashbls/.vscode/extensions.json deleted file mode 100644 index 622b5920a314..000000000000 --- a/src/dashbls/.vscode/extensions.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "recommendations": [ - "charliermarsh.ruff", - "ms-python.python", - "ms-python.vscode-pylance", - ] -} diff --git a/src/dashbls/.vscode/settings.json b/src/dashbls/.vscode/settings.json deleted file mode 100644 index a4d694f5552d..000000000000 --- a/src/dashbls/.vscode/settings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "[python]": { - "editor.defaultFormatter": "charliermarsh.ruff", - "editor.formatOnSave": true, - "editor.rulers": [88, 100] - }, - "editor.minimap.enabled": true, -} diff --git a/src/dashbls/CMakeLists.txt b/src/dashbls/CMakeLists.txt deleted file mode 100644 index 25f65b875961..000000000000 --- a/src/dashbls/CMakeLists.txt +++ /dev/null @@ -1,104 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.18.0 FATAL_ERROR) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_C_STANDARD 99) - -set(CMAKE_POSITION_INDEPENDENT_CODE ON) - -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Release" - CACHE STRING "Possible values are empty, Debug, Release, RelWithDebInfo, MinSizeRel, ..." - FORCE - ) -endif() - -project(BLS) - -if(MSVC) - enable_language(ASM_MASM) -else() - enable_language(ASM) -endif() - -set(BUILD_BLS_JS_BINDINGS "1" CACHE STRING "") -set(BUILD_BLS_PYTHON_BINDINGS "1" CACHE STRING "") -set(BUILD_BLS_TESTS "1" CACHE STRING "") -set(BUILD_BLS_BENCHMARKS "1" CACHE STRING "") -set(BUILD_SODIUM "0" CACHE STRING "") - -message(STATUS "Build python bindings: ${BUILD_BLS_PYTHON_BINDINGS}") -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 -) - -# Disable mimalloc shared libraries and tests, enable secure mode -set(MI_SECURE "on" CACHE STRING "") - -set(MI_BUILD_SHARED "off" CACHE STRING "") -set(MI_BUILD_TESTS "off" CACHE STRING "") -set(MI_OVERRIDE "off" CACHE STRING "") -add_subdirectory(depends/mimalloc) - -include(FetchContent) - -if(Sodium) -FetchContent_Declare(Sodium - GIT_REPOSITORY https://github.com/AmineKhaldi/libsodium-cmake.git - - # Latest commit at the moment this was added here - # Anchored to libsodium v1.0.18 - GIT_TAG f73a3fe1afdc4e37ac5fe0ddd401bf521f6bba65 -) -set(SODIUM_PCH "on" CACHE STRING "") -set(SODIUM_DISABLE_TESTS "on" CACHE STRING "") -set(SODIUM_CHIA_MINIMAL "on" CACHE STRING "") -FetchContent_MakeAvailable(Sodium) -endif() - -set(BLST_GIT_TAG "a8cd361c9f671577aeab3f074098443af92a53fc") -set(BLST_REPOSITORY "https://github.com/supranational/blst") - -message(STATUS "blst will be built from: ${BLST_GIT_TAG} and repository ${BLST_REPOSITORY}") - -FetchContent_Declare( - blst - GIT_REPOSITORY ${BLST_REPOSITORY} - GIT_TAG ${BLST_GIT_TAG} -) -FetchContent_MakeAvailable(blst) - -add_subdirectory(src) - - -# Write include paths for rust binding -if(EMSCRIPTEN) - file(APPEND "${CMAKE_CURRENT_LIST_DIR}/build/include_paths.txt" "${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}/c++/v1/;") -endif() - -file(APPEND "${CMAKE_CURRENT_LIST_DIR}/build/include_paths.txt" "${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES};") - -if(GMP_INCLUDES) - file(APPEND "${CMAKE_CURRENT_LIST_DIR}/build/include_paths.txt" "${GMP_INCLUDES};") -endif() - -# Write gmp library path for rust binding -if(GMP_LIBRARIES) - file(APPEND "${CMAKE_CURRENT_LIST_DIR}/build/gmp_libraries.txt" "${GMP_LIBRARIES}") -endif() - -if(EMSCRIPTEN) - if(BUILD_BLS_JS_BINDINGS) - add_subdirectory(js-bindings) - endif() -else() - # emscripten can't build python bindings, it produces only javascript - # add_subdirectory(contrib/pybind11) - if(BUILD_BLS_PYTHON_BINDINGS) - add_subdirectory(binds/python) - endif() -endif() diff --git a/src/dashbls/MANIFEST.in b/src/dashbls/MANIFEST.in deleted file mode 100644 index 62cc22eaeea0..000000000000 --- a/src/dashbls/MANIFEST.in +++ /dev/null @@ -1,44 +0,0 @@ -# Unused sources -exclude src/test.cpp src/test-bench.cpp - -# Foreign languages -prune js-bindings -prune go-bindings -prune rust-bindings -exclude emsdk_*.sh js_*.sh apple.rust.deps.sh - -# Vendored test dependency -prune depends/catch2 - -# Vendored dependency extras -prune depends/mimalloc/doc -prune depends/mimalloc/docs -prune depends/mimalloc/ide -prune depends/mimalloc/test -prune depends/mimalloc/contrib -prune depends/relic/.github -prune depends/relic/art -prune depends/relic/bench -prune depends/relic/demo -prune depends/relic/doc -prune depends/relic/preset -prune depends/relic/test -prune depends/relic/tools - -# Autotools build -prune build-aux -prune autom4te.cache -exclude Makefile.am Makefile.*.include Makefile.in Makefile configure.ac aclocal.m4 autogen.sh - -# dot{dir,file}s -prune .github -prune .vscode -prune .claude -exclude .clang-format .python-version .gitignore - -# Build artifacts -prune build -prune .libs -global-exclude *.o *.a *.lo *.la *.so *.dylib *.dll *.pyc -global-exclude *.orig *.rej *.bak -global-exclude *.egg-info/* diff --git a/src/dashbls/Makefile.am b/src/dashbls/Makefile.am deleted file mode 100644 index 1c1e5d19d594..000000000000 --- a/src/dashbls/Makefile.am +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright (c) 2013-2016 The Bitcoin Core developers -# Copyright (c) 2022 The Dash Core developers -# Distributed under the MIT software license, see the accompanying -# file COPYING.MIT or http://www.opensource.org/licenses/mit-license.php. - -print-%: FORCE - @echo '$*'='$($*)' - -ACLOCAL_AMFLAGS = -I build-aux/m4 -.PHONY: deploy FORCE - -AM_LDFLAGS = $(HARDENED_LDFLAGS) $(CORE_LDFLAGS) $(GMP_LDFLAGS) -AM_CFLAGS = $(DEBUG_FLAGS) $(HARDENED_FLAGS) $(CORE_FLAGS) $(WARN_FLAGS) $(NOWARN_FLAGS) -AM_CPPFLAGS = $(CORE_CPPFLAGS) $(GMP_CPPFLAGS) -AM_CXXFLAGS = $(DEBUG_FLAGS) $(HARDENED_FLAGS) $(CORE_FLAGS) $(WARN_FLAGS) $(NOWARN_FLAGS) -PTHREAD_FLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) - -EXTRA_LIBRARIES = - -lib_LTLIBRARIES = -noinst_LTLIBRARIES = - -bin_PROGRAMS = -noinst_PROGRAMS = -EXTRA_DIST = - -CLEANFILES = - -include Makefile.bls.include - -CLEANFILES += $(LIBRELIC) $(LIBDASHBLS) $(LIBMIMALLOC) - -if USE_TESTS -CLEANFILES += $(DASHBLS_RUNTEST) -endif - -if USE_BENCH -CLEANFILES += $(DASHBLS_RUNBENCH) -endif diff --git a/src/dashbls/Makefile.bench.include b/src/dashbls/Makefile.bench.include deleted file mode 100644 index f584102a3294..000000000000 --- a/src/dashbls/Makefile.bench.include +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (c) 2021 The PIVX developers -# Copyright (c) 2022 The Dash Core developers -# Distributed under the MIT software license, see the accompanying -# file COPYING.MIT or http://www.opensource.org/licenses/mit-license.php. - -DASHBLS_RUNBENCH = runbench - -runbench_SOURCES = \ - src/test-bench.cpp \ - src/test-utils.hpp - -runbench_SOURCES += \ - $(RELIC_H) \ - $(DASHBLS_H) - -runbench_CPPFLAGS = $(AM_CPPFLAGS) $(DASHBLS_INCLUDES) $(RELIC_INCLUDES) -runbench_CXXFLAGS = $(AM_CXXFLAGS) -runbench_LDFLAGS = -static $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS) - -runbench_LDADD = $(LIBDASHBLS) - -noinst_PROGRAMS += $(DASHBLS_RUNBENCH) diff --git a/src/dashbls/Makefile.bls.include b/src/dashbls/Makefile.bls.include deleted file mode 100644 index 7c35b3ced764..000000000000 --- a/src/dashbls/Makefile.bls.include +++ /dev/null @@ -1,66 +0,0 @@ -# Copyright (c) 2021 The PIVX developers -# Copyright (c) 2022 The Dash Core developers -# Distributed under the MIT software license, see the accompanying -# file COPYING.MIT or http://www.opensource.org/licenses/mit-license.php. - -LIBDASHBLS = libdashbls.la - -DASHBLS_CPPFLAGS = -DBLSALLOC_MIMALLOC=1 - -DASHBLS_INCLUDES = \ - -I$(builddir) \ - -I$(builddir)/obj \ - -I$(top_srcdir)/include/dashbls - -DASHBLS_H = \ - src/bls.hpp \ - src/chaincode.hpp \ - src/elements.hpp \ - src/extendedprivatekey.hpp \ - src/extendedpublickey.hpp \ - src/hdkeys.hpp \ - src/hkdf.hpp \ - src/legacy.hpp \ - src/privatekey.hpp \ - src/schemes.hpp \ - src/test-utils.hpp \ - src/threshold.hpp \ - src/util.hpp - -libdashbls_la_SOURCES = \ - src/bls.cpp \ - src/chaincode.cpp \ - src/elements.cpp \ - src/extendedprivatekey.cpp \ - src/extendedpublickey.cpp \ - src/legacy.cpp \ - src/privatekey.cpp \ - src/schemes.cpp \ - src/threshold.cpp - -libdashbls_la_SOURCES += \ - $(DASHBLS_H) \ - $(MIMALLOC_H) \ - $(RELIC_H) - -libdashbls_la_LIBADD = \ - $(LIBMIMALLOC) \ - $(LIBRELIC) \ - $(GMP_LIBS) - -libdashbls_la_CPPFLAGS = $(AM_CPPFLAGS) $(RELIC_INCLUDES) $(MIMALLOC_INCLUDES) $(DASHBLS_INCLUDES) $(DASHBLS_CPPFLAGS) -libdashbls_la_CXXFLAGS = $(AM_CXXFLAGS) -libdashbls_la_LDFLAGS = $(AM_LDFLAGS) - -include Makefile.mimalloc.include -include Makefile.relic.include - -if USE_TESTS -include Makefile.test.include -endif - -if USE_BENCH -include Makefile.bench.include -endif - -lib_LTLIBRARIES += $(LIBDASHBLS) diff --git a/src/dashbls/Makefile.mimalloc.include b/src/dashbls/Makefile.mimalloc.include deleted file mode 100644 index fada5fe32819..000000000000 --- a/src/dashbls/Makefile.mimalloc.include +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright (c) 2022-2025 The Dash Core developers -# Distributed under the MIT software license, see the accompanying -# file COPYING.MIT or http://www.opensource.org/licenses/mit-license.php. - -LIBMIMALLOC = libmimalloc-secure.la - -MIMALLOC_CPPFLAGS = \ - -DMI_SECURE=4 \ - -DNDEBUG - -MIMALLOC_INCLUDES = \ - -I$(top_srcdir)/depends/mimalloc/include \ - -I$(top_srcdir)/depends/mimalloc/src - -MIMALLOC_H = \ - depends/mimalloc/include/mimalloc-new-delete.h \ - depends/mimalloc/include/mimalloc-override.h \ - depends/mimalloc/include/mimalloc-stats.h \ - depends/mimalloc/include/mimalloc.h \ - depends/mimalloc/src/bitmap.h - -libmimalloc_secure_la_SOURCES = \ - $(MIMALLOC_H) \ - depends/mimalloc/src/alloc-aligned.c \ - depends/mimalloc/src/alloc-posix.c \ - depends/mimalloc/src/alloc.c \ - depends/mimalloc/src/arena-meta.c \ - depends/mimalloc/src/arena.c \ - depends/mimalloc/src/bitmap.c \ - depends/mimalloc/src/heap.c \ - depends/mimalloc/src/init.c \ - depends/mimalloc/src/libc.c \ - depends/mimalloc/src/options.c \ - depends/mimalloc/src/os.c \ - depends/mimalloc/src/page-map.c \ - depends/mimalloc/src/page.c \ - depends/mimalloc/src/random.c \ - depends/mimalloc/src/stats.c \ - depends/mimalloc/src/prim/prim.c - -libmimalloc_secure_la_CPPFLAGS = $(AM_CPPFLAGS) $(MIMALLOC_CPPFLAGS) $(MIMALLOC_INCLUDES) -libmimalloc_secure_la_CXXFLAGS = $(AM_CXXFLAGS) -libmimalloc_secure_la_CFLAGS = $(AM_CFLAGS) -libmimalloc_secure_la_LDFLAGS = $(AM_LDFLAGS) - -noinst_LTLIBRARIES += $(LIBMIMALLOC) diff --git a/src/dashbls/Makefile.relic.include b/src/dashbls/Makefile.relic.include deleted file mode 100644 index 92bd7c7e8f5b..000000000000 --- a/src/dashbls/Makefile.relic.include +++ /dev/null @@ -1,470 +0,0 @@ -# Copyright (c) 2021 The PIVX developers -# Copyright (c) 2022 The Dash Core developers -# Distributed under the MIT software license, see the accompanying -# file COPYING.MIT or http://www.opensource.org/licenses/mit-license.php. - -LIBRELIC = librelic.la - -RELIC_INCLUDES = \ - -I$(top_srcdir)/depends/relic/include \ - -I$(top_srcdir)/depends/relic/include/low \ - -I$(top_srcdir)/depends/relic/src/tmpl - -RELIC_H = \ - depends/relic/include/relic.h \ - depends/relic/include/relic_alloc.h \ - depends/relic/include/relic_arch.h \ - depends/relic/include/relic_bc.h \ - depends/relic/include/relic_bench.h \ - depends/relic/include/relic_bn.h \ - depends/relic/include/relic_conf.h \ - depends/relic/include/relic_core.h \ - depends/relic/include/relic_cp.h \ - depends/relic/include/relic_dv.h \ - depends/relic/include/relic_eb.h \ - depends/relic/include/relic_ec.h \ - depends/relic/include/relic_ed.h \ - depends/relic/include/relic_ep.h \ - depends/relic/include/relic_epx.h \ - depends/relic/include/relic_err.h \ - depends/relic/include/relic_fb.h \ - depends/relic/include/relic_fbx.h \ - depends/relic/include/relic_fp.h \ - depends/relic/include/relic_fpx.h \ - depends/relic/include/relic_label.h \ - depends/relic/include/relic_md.h \ - depends/relic/include/relic_mpc.h \ - depends/relic/include/relic_multi.h \ - depends/relic/include/relic_pc.h \ - depends/relic/include/relic_pp.h \ - depends/relic/include/relic_rand.h \ - depends/relic/include/relic_test.h \ - depends/relic/include/relic_types.h \ - depends/relic/include/relic_util.h \ - depends/relic/include/low/relic_bn_low.h \ - depends/relic/include/low/relic_dv_low.h \ - depends/relic/include/low/relic_fb_low.h \ - depends/relic/include/low/relic_fp_low.h \ - depends/relic/include/low/relic_fpx_low.h \ - depends/relic/src/arch/lzcnt.inc \ - depends/relic/src/tmpl/relic_tmpl_map.h - -RELIC_SOURCES = \ - depends/relic/src/relic_err.c \ - depends/relic/src/relic_core.c \ - depends/relic/src/relic_conf.c \ - depends/relic/src/relic_util.c - -BN_SOURCES = \ - depends/relic/src/bn/relic_bn_add.c \ - depends/relic/src/bn/relic_bn_cmp.c \ - depends/relic/src/bn/relic_bn_div.c \ - depends/relic/src/bn/relic_bn_factor.c \ - depends/relic/src/bn/relic_bn_gcd.c \ - depends/relic/src/bn/relic_bn_inv.c \ - depends/relic/src/bn/relic_bn_lcm.c \ - depends/relic/src/bn/relic_bn_mem.c \ - depends/relic/src/bn/relic_bn_mod.c \ - depends/relic/src/bn/relic_bn_mul.c \ - depends/relic/src/bn/relic_bn_mxp.c \ - depends/relic/src/bn/relic_bn_prime.c \ - depends/relic/src/bn/relic_bn_rec.c \ - depends/relic/src/bn/relic_bn_shift.c \ - depends/relic/src/bn/relic_bn_smb.c \ - depends/relic/src/bn/relic_bn_sqr.c \ - depends/relic/src/bn/relic_bn_srt.c \ - depends/relic/src/bn/relic_bn_util.c - -FP_SOURCES = \ - depends/relic/src/fp/relic_fp_add.c \ - depends/relic/src/fp/relic_fp_cmp.c \ - depends/relic/src/fp/relic_fp_exp.c \ - depends/relic/src/fp/relic_fp_inv.c \ - depends/relic/src/fp/relic_fp_mul.c \ - depends/relic/src/fp/relic_fp_param.c \ - depends/relic/src/fp/relic_fp_prime.c \ - depends/relic/src/fp/relic_fp_rdc.c \ - depends/relic/src/fp/relic_fp_shift.c \ - depends/relic/src/fp/relic_fp_sqr.c \ - depends/relic/src/fp/relic_fp_srt.c \ - depends/relic/src/fp/relic_fp_util.c - -FPX_SOURCES = \ - depends/relic/src/fpx/relic_fp2_mul.c \ - depends/relic/src/fpx/relic_fp2_sqr.c \ - depends/relic/src/fpx/relic_fp3_mul.c \ - depends/relic/src/fpx/relic_fp3_sqr.c \ - depends/relic/src/fpx/relic_fp4_mul.c \ - depends/relic/src/fpx/relic_fp4_sqr.c \ - depends/relic/src/fpx/relic_fp6_mul.c \ - depends/relic/src/fpx/relic_fp6_sqr.c \ - depends/relic/src/fpx/relic_fp8_mul.c \ - depends/relic/src/fpx/relic_fp8_sqr.c \ - depends/relic/src/fpx/relic_fp9_mul.c \ - depends/relic/src/fpx/relic_fp9_sqr.c \ - depends/relic/src/fpx/relic_fp12_mul.c \ - depends/relic/src/fpx/relic_fp12_sqr.c \ - depends/relic/src/fpx/relic_fp18_mul.c \ - depends/relic/src/fpx/relic_fp18_sqr.c \ - depends/relic/src/fpx/relic_fp24_mul.c \ - depends/relic/src/fpx/relic_fp24_sqr.c \ - depends/relic/src/fpx/relic_fp48_mul.c \ - depends/relic/src/fpx/relic_fp48_sqr.c \ - depends/relic/src/fpx/relic_fp54_mul.c \ - depends/relic/src/fpx/relic_fp54_sqr.c \ - depends/relic/src/fpx/relic_fpx_add.c \ - depends/relic/src/fpx/relic_fpx_cmp.c \ - depends/relic/src/fpx/relic_fpx_cyc.c \ - depends/relic/src/fpx/relic_fpx_exp.c \ - depends/relic/src/fpx/relic_fpx_field.c \ - depends/relic/src/fpx/relic_fpx_frb.c \ - depends/relic/src/fpx/relic_fpx_inv.c \ - depends/relic/src/fpx/relic_fpx_pck.c \ - depends/relic/src/fpx/relic_fpx_rdc.c \ - depends/relic/src/fpx/relic_fpx_srt.c \ - depends/relic/src/fpx/relic_fpx_util.c - -FB_SOURCES = \ - depends/relic/src/fb/relic_fb_add.c \ - depends/relic/src/fb/relic_fb_cmp.c \ - depends/relic/src/fb/relic_fb_exp.c \ - depends/relic/src/fb/relic_fb_inv.c \ - depends/relic/src/fb/relic_fb_itr.c \ - depends/relic/src/fb/relic_fb_mul.c \ - depends/relic/src/fb/relic_fb_param.c \ - depends/relic/src/fb/relic_fb_poly.c \ - depends/relic/src/fb/relic_fb_rdc.c \ - depends/relic/src/fb/relic_fb_shift.c \ - depends/relic/src/fb/relic_fb_slv.c \ - depends/relic/src/fb/relic_fb_sqr.c \ - depends/relic/src/fb/relic_fb_srt.c \ - depends/relic/src/fb/relic_fb_trc.c \ - depends/relic/src/fb/relic_fb_util.c - -EP_SOURCES = \ - depends/relic/src/ep/relic_ep_add.c \ - depends/relic/src/ep/relic_ep_cmp.c \ - depends/relic/src/ep/relic_ep_curve.c \ - depends/relic/src/ep/relic_ep_dbl.c \ - depends/relic/src/ep/relic_ep_map.c \ - depends/relic/src/ep/relic_ep_mul.c \ - depends/relic/src/ep/relic_ep_mul_fix.c \ - depends/relic/src/ep/relic_ep_mul_sim.c \ - depends/relic/src/ep/relic_ep_neg.c \ - depends/relic/src/ep/relic_ep_norm.c \ - depends/relic/src/ep/relic_ep_param.c \ - depends/relic/src/ep/relic_ep_pck.c \ - depends/relic/src/ep/relic_ep_psi.c \ - depends/relic/src/ep/relic_ep_util.c - -EPX_SOURCES = \ - depends/relic/src/epx/relic_ep2_add.c \ - depends/relic/src/epx/relic_ep2_cmp.c \ - depends/relic/src/epx/relic_ep2_curve.c \ - depends/relic/src/epx/relic_ep2_dbl.c \ - depends/relic/src/epx/relic_ep2_frb.c \ - depends/relic/src/epx/relic_ep2_map.c \ - depends/relic/src/epx/relic_ep2_mul.c \ - depends/relic/src/epx/relic_ep2_mul_cof.c \ - depends/relic/src/epx/relic_ep2_mul_fix.c \ - depends/relic/src/epx/relic_ep2_mul_sim.c \ - depends/relic/src/epx/relic_ep2_neg.c \ - depends/relic/src/epx/relic_ep2_norm.c \ - depends/relic/src/epx/relic_ep2_pck.c \ - depends/relic/src/epx/relic_ep2_util.c \ - depends/relic/src/epx/relic_ep4_add.c \ - depends/relic/src/epx/relic_ep4_cmp.c \ - depends/relic/src/epx/relic_ep4_curve.c \ - depends/relic/src/epx/relic_ep4_dbl.c \ - depends/relic/src/epx/relic_ep4_frb.c \ - depends/relic/src/epx/relic_ep4_map.c \ - depends/relic/src/epx/relic_ep4_mul.c \ - depends/relic/src/epx/relic_ep4_mul_cof.c \ - depends/relic/src/epx/relic_ep4_mul_fix.c \ - depends/relic/src/epx/relic_ep4_mul_sim.c \ - depends/relic/src/epx/relic_ep4_neg.c \ - depends/relic/src/epx/relic_ep4_norm.c \ - depends/relic/src/epx/relic_ep4_util.c - -EB_SOURCES = \ - depends/relic/src/eb/relic_eb_add.c \ - depends/relic/src/eb/relic_eb_cmp.c \ - depends/relic/src/eb/relic_eb_curve.c \ - depends/relic/src/eb/relic_eb_dbl.c \ - depends/relic/src/eb/relic_eb_frb.c \ - depends/relic/src/eb/relic_eb_hlv.c \ - depends/relic/src/eb/relic_eb_map.c \ - depends/relic/src/eb/relic_eb_mul.c \ - depends/relic/src/eb/relic_eb_mul_fix.c \ - depends/relic/src/eb/relic_eb_mul_sim.c \ - depends/relic/src/eb/relic_eb_neg.c \ - depends/relic/src/eb/relic_eb_norm.c \ - depends/relic/src/eb/relic_eb_param.c \ - depends/relic/src/eb/relic_eb_pck.c \ - depends/relic/src/eb/relic_eb_util.c - -ED_SOURCES = \ - depends/relic/src/ed/relic_ed_add.c \ - depends/relic/src/ed/relic_ed_cmp.c \ - depends/relic/src/ed/relic_ed_curve.c \ - depends/relic/src/ed/relic_ed_dbl.c \ - depends/relic/src/ed/relic_ed_map.c \ - depends/relic/src/ed/relic_ed_mul.c \ - depends/relic/src/ed/relic_ed_mul_fix.c \ - depends/relic/src/ed/relic_ed_mul_sim.c \ - depends/relic/src/ed/relic_ed_neg.c \ - depends/relic/src/ed/relic_ed_norm.c \ - depends/relic/src/ed/relic_ed_param.c \ - depends/relic/src/ed/relic_ed_pck.c \ - depends/relic/src/ed/relic_ed_util.c - -PP_SOURCES = \ - depends/relic/src/pp/relic_pp_add_k2.c \ - depends/relic/src/pp/relic_pp_add_k8.c \ - depends/relic/src/pp/relic_pp_add_k12.c \ - depends/relic/src/pp/relic_pp_add_k24.c \ - depends/relic/src/pp/relic_pp_add_k48.c \ - depends/relic/src/pp/relic_pp_add_k54.c \ - depends/relic/src/pp/relic_pp_dbl_k2.c \ - depends/relic/src/pp/relic_pp_dbl_k8.c \ - depends/relic/src/pp/relic_pp_dbl_k12.c \ - depends/relic/src/pp/relic_pp_dbl_k24.c \ - depends/relic/src/pp/relic_pp_dbl_k48.c \ - depends/relic/src/pp/relic_pp_dbl_k54.c \ - depends/relic/src/pp/relic_pp_exp_k2.c \ - depends/relic/src/pp/relic_pp_exp_k8.c \ - depends/relic/src/pp/relic_pp_exp_k12.c \ - depends/relic/src/pp/relic_pp_exp_k24.c \ - depends/relic/src/pp/relic_pp_exp_k48.c \ - depends/relic/src/pp/relic_pp_exp_k54.c \ - depends/relic/src/pp/relic_pp_map.c \ - depends/relic/src/pp/relic_pp_map_k2.c \ - depends/relic/src/pp/relic_pp_map_k8.c \ - depends/relic/src/pp/relic_pp_map_k12.c \ - depends/relic/src/pp/relic_pp_map_k24.c \ - depends/relic/src/pp/relic_pp_map_k48.c \ - depends/relic/src/pp/relic_pp_map_k54.c \ - depends/relic/src/pp/relic_pp_norm.c - -PC_SOURCES = \ - depends/relic/src/pc/relic_pc_core.c \ - depends/relic/src/pc/relic_pc_exp.c \ - depends/relic/src/pc/relic_pc_util.c - -MD_SOURCES = \ - depends/relic/src/md/blake2.h \ - depends/relic/src/md/blake2-impl.h \ - depends/relic/src/md/blake2s-ref.c \ - depends/relic/src/md/relic_md_blake2s.c \ - depends/relic/src/md/relic_md_hmac.c \ - depends/relic/src/md/relic_md_kdf.c \ - depends/relic/src/md/relic_md_mgf.c \ - depends/relic/src/md/relic_md_sha224.c \ - depends/relic/src/md/relic_md_sha256.c \ - depends/relic/src/md/relic_md_sha384.c \ - depends/relic/src/md/relic_md_sha512.c \ - depends/relic/src/md/relic_md_xmd.c \ - depends/relic/src/md/sha.h \ - depends/relic/src/md/sha224-256.c \ - depends/relic/src/md/sha384-512.c \ - depends/relic/src/md/sha_private.h - -EXTRA_DIST += \ - depends/relic/src/arch/relic_arch_arm.c \ - depends/relic/src/arch/relic_arch_none.c \ - depends/relic/src/arch/relic_arch_x64.c \ - depends/relic/src/arch/relic_arch_x86.c - -RELIC_SOURCES += \ - depends/relic/src/arch/relic_arch_@CPU_ARCH@.c \ - depends/relic/src/rand/relic_rand_call.c \ - depends/relic/src/rand/relic_rand_core.c \ - depends/relic/src/rand/relic_rand_hashd.c \ - depends/relic/src/rand/relic_rand_udev.c - -if WITH_DV -RELIC_SOURCES += \ - depends/relic/src/dv/relic_dv_mem.c \ - depends/relic/src/dv/relic_dv_util.c -endif - -if ARITH_EASY -if WITH_BN -RELIC_SOURCES += $(BN_SOURCES) \ - depends/relic/src/low/easy/relic_bn_add_low.c \ - depends/relic/src/low/easy/relic_bn_div_low.c \ - depends/relic/src/low/easy/relic_bn_mod_low.c \ - depends/relic/src/low/easy/relic_bn_mul_low.c \ - depends/relic/src/low/easy/relic_bn_shift_low.c \ - depends/relic/src/low/easy/relic_bn_sqr_low.c -endif - -if WITH_FP -RELIC_SOURCES += $(FP_SOURCES) \ - depends/relic/src/low/easy/relic_fp_add_low.c \ - depends/relic/src/low/easy/relic_fp_inv_low.c \ - depends/relic/src/low/easy/relic_fp_mul_low.c \ - depends/relic/src/low/easy/relic_fp_rdc_low.c \ - depends/relic/src/low/easy/relic_fp_shift_low.c \ - depends/relic/src/low/easy/relic_fp_sqr_low.c -endif - -if WITH_FPX -RELIC_SOURCES += $(FPX_SOURCES) \ - depends/relic/src/low/easy/relic_fpx_add_low.c \ - depends/relic/src/low/easy/relic_fpx_mul_low.c \ - depends/relic/src/low/easy/relic_fpx_rdc_low.c \ - depends/relic/src/low/easy/relic_fpx_sqr_low.c -endif - -if WITH_FB -RELIC_SOURCES += $(FB_SOURCES) \ - depends/relic/src/low/easy/relic_fb_add_low.c \ - depends/relic/src/low/easy/relic_fb_inv_low.c \ - depends/relic/src/low/easy/relic_fb_itr_low.c \ - depends/relic/src/low/easy/relic_fb_mul_low.c \ - depends/relic/src/low/easy/relic_fb_rdc_low.c \ - depends/relic/src/low/easy/relic_fb_shift_low.c \ - depends/relic/src/low/easy/relic_fb_slv_low.c \ - depends/relic/src/low/easy/relic_fb_sqr_low.c \ - depends/relic/src/low/easy/relic_fb_srt_low.c \ - depends/relic/src/low/easy/relic_fb_trc_low.c -endif -endif - -if ARITH_GMP -if WITH_BN -RELIC_SOURCES += $(BN_SOURCES) \ - depends/relic/src/low/gmp/relic_bn_add_low.c \ - depends/relic/src/low/gmp/relic_bn_div_low.c \ - depends/relic/src/low/gmp/relic_bn_mod_low.c \ - depends/relic/src/low/gmp/relic_bn_mul_low.c \ - depends/relic/src/low/gmp/relic_bn_shift_low.c \ - depends/relic/src/low/gmp/relic_bn_sqr_low.c -endif - -if WITH_FP -RELIC_SOURCES += $(FP_SOURCES) \ - depends/relic/src/low/gmp/relic_fp_add_low.c \ - depends/relic/src/low/gmp/relic_fp_inv_low.c \ - depends/relic/src/low/gmp/relic_fp_mul_low.c \ - depends/relic/src/low/gmp/relic_fp_rdc_low.c \ - depends/relic/src/low/gmp/relic_fp_shift_low.c \ - depends/relic/src/low/gmp/relic_fp_sqr_low.c -endif - -if WITH_FPX -RELIC_SOURCES += $(FPX_SOURCES) \ - depends/relic/src/low/easy/relic_fpx_add_low.c \ - depends/relic/src/low/easy/relic_fpx_mul_low.c \ - depends/relic/src/low/easy/relic_fpx_rdc_low.c \ - depends/relic/src/low/easy/relic_fpx_sqr_low.c -endif - -if WITH_FB -RELIC_SOURCES += $(FB_SOURCES) \ - depends/relic/src/low/gmp/relic_fb_add_low.c \ - depends/relic/src/low/easy/relic_fb_inv_low.c \ - depends/relic/src/low/easy/relic_fb_itr_low.c \ - depends/relic/src/low/easy/relic_fb_mul_low.c \ - depends/relic/src/low/easy/relic_fb_rdc_low.c \ - depends/relic/src/low/gmp/relic_fb_shift_low.c \ - depends/relic/src/low/easy/relic_fb_slv_low.c \ - depends/relic/src/low/easy/relic_fb_sqr_low.c \ - depends/relic/src/low/easy/relic_fb_srt_low.c \ - depends/relic/src/low/easy/relic_fb_trc_low.c -endif -endif - -if WITH_FBX -RELIC_SOURCES += \ - depends/relic/src/fbx/relic_fb2_inv.c \ - depends/relic/src/fbx/relic_fb2_mul.c \ - depends/relic/src/fbx/relic_fb2_slv.c \ - depends/relic/src/fbx/relic_fb2_sqr.c -endif - -if WITH_EP -RELIC_SOURCES += $(EP_SOURCES) -endif - -if WITH_EPX -RELIC_SOURCES += $(EPX_SOURCES) -endif - -if WITH_EB -RELIC_SOURCES += $(EB_SOURCES) -endif - -if WITH_ED -RELIC_SOURCES += $(ED_SOURCES) -endif - -if WITH_PP -RELIC_SOURCES += $(PP_SOURCES) -endif - -if WITH_PC -RELIC_SOURCES += $(PC_SOURCES) -endif - -if WITH_CP -RELIC_SOURCES += \ - depends/relic/src/cp/relic_cp_bbs.c \ - depends/relic/src/cp/relic_cp_bdpe.c \ - depends/relic/src/cp/relic_cp_bgn.c \ - depends/relic/src/cp/relic_cp_bls.c \ - depends/relic/src/cp/relic_cp_cls.c \ - depends/relic/src/cp/relic_cp_cmlhs.c \ - depends/relic/src/cp/relic_cp_ecdh.c \ - depends/relic/src/cp/relic_cp_ecdsa.c \ - depends/relic/src/cp/relic_cp_ecies.c \ - depends/relic/src/cp/relic_cp_ecmqv.c \ - depends/relic/src/cp/relic_cp_ecss.c \ - depends/relic/src/cp/relic_cp_ers.c \ - depends/relic/src/cp/relic_cp_etrs.c \ - depends/relic/src/cp/relic_cp_ghpe.c \ - depends/relic/src/cp/relic_cp_ibe.c \ - depends/relic/src/cp/relic_cp_mklhs.c \ - depends/relic/src/cp/relic_cp_mpss.c \ - depends/relic/src/cp/relic_cp_pcdel.c \ - depends/relic/src/cp/relic_cp_phpe.c \ - depends/relic/src/cp/relic_cp_pok.c \ - depends/relic/src/cp/relic_cp_pss.c \ - depends/relic/src/cp/relic_cp_rabin.c \ - depends/relic/src/cp/relic_cp_rsa.c \ - depends/relic/src/cp/relic_cp_sok.c \ - depends/relic/src/cp/relic_cp_sokaka.c \ - depends/relic/src/cp/relic_cp_vbnn.c \ - depends/relic/src/cp/relic_cp_zss.c -endif - -if WITH_BC -RELIC_SOURCES += \ - depends/relic/src/bc/relic_bc_aes.c \ - depends/relic/src/bc/rijndael-alg-fst.c \ - depends/relic/src/bc/rijndael-alg-fst.h \ - depends/relic/src/bc/rijndael-api-fst.c \ - depends/relic/src/bc/rijndael-api-fst.h -endif - -if WITH_MD -RELIC_SOURCES += $(MD_SOURCES) -endif - -if WITH_MPC -RELIC_SOURCES += \ - depends/relic/src/mpc/relic_mt_mpc.c \ - depends/relic/src/mpc/relic_pc_mpc.c -endif - -librelic_la_SOURCES = \ - $(RELIC_SOURCES) \ - $(RELIC_H) - -librelic_la_CPPFLAGS = $(AM_CPPFLAGS) $(RELIC_CPPFLAGS) $(RELIC_INCLUDES) -librelic_la_CXXFLAGS = $(AM_CXXFLAGS) -librelic_la_CFLAGS = $(AM_CFLAGS) -librelic_la_LDFLAGS = $(AM_LDFLAGS) - -noinst_LTLIBRARIES += $(LIBRELIC) diff --git a/src/dashbls/Makefile.test.include b/src/dashbls/Makefile.test.include deleted file mode 100644 index e3e2a5356a3c..000000000000 --- a/src/dashbls/Makefile.test.include +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright (c) 2021 The PIVX developers -# Copyright (c) 2022 The Dash Core developers -# Distributed under the MIT software license, see the accompanying -# file COPYING.MIT or http://www.opensource.org/licenses/mit-license.php. - -DASHBLS_RUNTEST = runtest - -RUNTEST_INCLUDES = \ - -I$(top_srcdir)/depends/catch2/include - -RUNTEST_H = \ - depends/catch2/include/catch2/catch.hpp - -runtest_SOURCES = \ - $(DASHBLS_H) \ - $(RELIC_H) \ - $(RUNTEST_H) \ - src/test.cpp \ - src/test-utils.hpp \ - src/test-vectors.hpp - -runtest_CPPFLAGS = $(AM_CPPFLAGS) $(DASHBLS_INCLUDES) $(RELIC_INCLUDES) $(RUNTEST_INCLUDES) -DDASHBLS_REFERENCE_VECTORS=\"$(abs_top_srcdir)/test-vectors/reference.txt\" -runtest_CXXFLAGS = $(AM_CXXFLAGS) -runtest_LDFLAGS = -static $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS) - -runtest_LDADD = $(LIBDASHBLS) - -noinst_PROGRAMS += $(DASHBLS_RUNTEST) diff --git a/src/dashbls/NOTICE b/src/dashbls/NOTICE index a8f984371607..6cef8c41562a 100644 --- a/src/dashbls/NOTICE +++ b/src/dashbls/NOTICE @@ -17,23 +17,21 @@ limitations under the License. -------------------------------------------------------------------------- -relic (https://github.com/relic-toolkit/relic) +blst (https://github.com/supranational/blst) -Copyright (c) 2009 RELIC Authors +Copyright Supranational LLC -RELIC is free software; you can redistribute it and/or modify it under the -terms of the version 2.1 (or later) of the GNU Lesser General Public License -as published by the Free Software Foundation; or version 2.0 of the Apache -License as published by the Apache Software Foundation. See the LICENSE files -for more details. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at -RELIC 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 LICENSE files for more details. + http://www.apache.org/licenses/LICENSE-2.0 -You should have received a copy of the GNU Lesser General Public or the -Apache License along with RELIC. If not, see -or . +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. -------------------------------------------------------------------------- @@ -63,67 +61,6 @@ SOFTWARE. -------------------------------------------------------------------------- -GNU MP (https://gmplib.org/) - -Copyright 1991-present Free Software Foundation, Inc. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of either: - - * the GNU Lesser General Public License as published by the Free Software - Foundation; either version 3 of the License, or (at your option) any - later version. - -or - - * the GNU General Public License as published by the Free Software - Foundation; either version 2 of the License, or (at your option) any - later version. - -or both in parallel, as here. - -The GNU MP Library is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License and -the GNU Lesser General Public License for more details. - -You should have received copies of the GNU General Public License and the -GNU Lesser General Public License along with the GNU MP Library. If not, see -https://www.gnu.org/licenses/. - --------------------------------------------------------------------------- - -pybind11 (https://github.com/pybind/pybind11) - -Copyright (c) 2016 Wenzel Jakob , All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - --------------------------------------------------------------------------- - Catch2 (https://github.com/catchorg/Catch2) Copyright (c) 2022 Two Blue Cubes Ltd. All rights reserved. diff --git a/src/dashbls/README.md b/src/dashbls/README.md index 37a3243c63a6..adf24e64aee5 100644 --- a/src/dashbls/README.md +++ b/src/dashbls/README.md @@ -1,3 +1,9 @@ +> [!NOTE] +> +> Inside Dash Core this directory is built by `src/Makefile.dashbls.include` +> and blst is provided by `depends/packages/blst.mk`. The build instructions +> below describe the standalone upstream repository. + [![GitHub License](https://img.shields.io/github/license/dashpay/bls-signatures)](https://github.com/dashpay/bls-signatures/blob/main/LICENSE) [![Library status](https://img.shields.io/github/actions/workflow/status/dashpay/bls-signatures/build-test.yaml?branch=main&style=flat&logo=github&logoColor=white&label=library)](https://github.com/dashpay/bls-signatures/actions/workflows/build-test.yaml?query=branch%3Amain) [![Binds status](https://img.shields.io/github/actions/workflow/status/dashpay/bls-signatures/build-binds.yml?branch=main&style=flat&logo=github&logoColor=white&label=binds)](https://github.com/dashpay/bls-signatures/actions/workflows/build-binds.yml?query=branch%3Amain) diff --git a/src/dashbls/apple.rust.deps.sh b/src/dashbls/apple.rust.deps.sh deleted file mode 100755 index b2ebc41a4ff2..000000000000 --- a/src/dashbls/apple.rust.deps.sh +++ /dev/null @@ -1,374 +0,0 @@ -#!/bin/sh -set -x -set -e -# "x86_64-apple-ios" -# "aarch64-apple-ios" -# "aarch64-apple-ios-sim" -# "x86_64-apple-darwin" -# "aarch64-apple-darwin" -# TODO: it's probably needs to be optimized in order to increase better build velocity -# TODO: so we need to combine multiple targets -TARGET=$1 -git submodule update --init -MIN_IOS="13.0" -MIN_WATCHOS="5.0" -MIN_TVOS=$MIN_IOS -MIN_MACOS="10.15" - -IPHONEOS=iphoneos -IPHONESIMULATOR=iphonesimulator -WATCHOS=watchos -WATCHSIMULATOR=watchsimulator -TVOS=appletvos -TVSIMULATOR=appletvsimulator -MACOS=macosx - -LOGICALCPU_MAX=$(sysctl -n hw.logicalcpu_max) -BUILD=build - -version_min_flag() { - PLATFORM=$1 - FLAG="" - # shellcheck disable=SC2039 - # shellcheck disable=SC2053 - if [[ $PLATFORM = $IPHONEOS ]]; then - FLAG="-miphoneos-version-min=${MIN_IOS}" - elif [[ $PLATFORM = $IPHONESIMULATOR ]]; then - FLAG="-mios-simulator-version-min=${MIN_IOS}" - elif [[ $PLATFORM = $WATCHOS ]]; then - FLAG="-mwatchos-version-min=${MIN_WATCHOS}" - elif [[ $PLATFORM = $WATCHSIMULATOR ]]; then - FLAG="-mwatchos-simulator-version-min=${MIN_WATCHOS}" - elif [[ $PLATFORM = $TVOS ]]; then - FLAG="-mtvos-version-min=${MIN_TVOS}" - elif [[ $PLATFORM = $TVSIMULATOR ]]; then - FLAG="-mtvos-simulator-version-min=${MIN_TVOS}" - elif [[ $PLATFORM = $MACOS ]]; then - FLAG="-mmacosx-version-min=${MIN_MACOS}" - fi - echo $FLAG -} - - -prepare() { - download_gmp() { - GMP_VERSION="6.3.0" - CURRENT_DIR=$(pwd) - echo "$CURRENT_DIR" - # shellcheck disable=SC2039,SC2164 - pushd ${BUILD} - mkdir -p "contrib" - if [ ! -s "contrib/gmp-${GMP_VERSION}.tar.bz2" ]; then - curl -L -o "contrib/gmp-${GMP_VERSION}.tar.bz2" https://ftp.gnu.org/gnu/gmp/gmp-${GMP_VERSION}.tar.bz2 - fi - rm -rf "contrib/gmp" - # shellcheck disable=SC2039,SC2164 - pushd contrib - tar xfj "gmp-${GMP_VERSION}.tar.bz2" - mv gmp-${GMP_VERSION} gmp - # shellcheck disable=SC2039,SC2164 - popd #contrib - # shellcheck disable=SC2039,SC2164 - popd #build - } - - download_cmake_toolchain() { - if [ ! -s "${BUILD}/ios.toolchain.cmake" ]; then - SHA256_HASH="d02857ff6bd64f1d7109ca59c3e4f3b2f89d0663c412146e6977c679801b3243" - curl -o "${BUILD}/ios.toolchain.cmake" https://raw.githubusercontent.com/leetal/ios-cmake/c55677a4445b138c9ef2650d3c21f22cc78c2357/ios.toolchain.cmake - DOWNLOADED_HASH=$(shasum -a 256 ${BUILD}/ios.toolchain.cmake | cut -f 1 -d " ") - if [ $SHA256_HASH != "$DOWNLOADED_HASH" ]; then - echo "Error: sha256 checksum of ios.toolchain.cmake mismatch" >&2 - exit 1 - fi - fi - } - - download_relic() { - CURRENT_DIR=$(pwd) - echo "$CURRENT_DIR" - mkdir -p "${CURRENT_DIR}/${BUILD}/depends" - if [ ! -s "${CURRENT_DIR}/${BUILD}/depends/relic" ]; then - # shellcheck disable=SC2039,SC2164 - pushd "${CURRENT_DIR}/${BUILD}/depends" - git clone --depth 1 --branch "feat/ios-support" https://github.com/pankcuf/relic - # shellcheck disable=SC2039,SC2164 - pushd relic - git fetch --depth 1 origin 19fb6d79a77ade4ae8cd70d2b0ef7aab8720d1ae - git checkout 19fb6d79a77ade4ae8cd70d2b0ef7aab8720d1ae - # shellcheck disable=SC2039,SC2164 - popd #relic - # shellcheck disable=SC2039,SC2164 - popd #depends - fi - } - rm -rf ${BUILD} - mkdir -p ${BUILD} - download_relic - download_gmp - download_cmake_toolchain -} - -build_gmp_arch() { - PLATFORM=$1 - ARCH=$2 - PFX=${PLATFORM}-${ARCH} - # why this works with this host only? - HOST=aarch64-apple-darwin - # shellcheck disable=SC2039,SC2164 - pushd ${BUILD} - SDK=$(xcrun --sdk "$PLATFORM" --show-sdk-path) - PLATFORM_PATH=$(xcrun --sdk "$PLATFORM" --show-sdk-platform-path) - CLANG=$(xcrun --sdk "$PLATFORM" --find clang) - DEVELOPER=$(xcode-select --print-path) - CURRENT_DIR=$(pwd) - export PATH="${PLATFORM_PATH}/Developer/usr/bin:${DEVELOPER}/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin" - mkdir gmplib-"${PLATFORM}"-"${ARCH}" - CFLAGS="-Wno-unused-value -fembed-bitcode -arch ${ARCH} --sysroot=${SDK} $(version_min_flag "$PLATFORM")" - CONFIGURESCRIPT="gmp_configure_script.sh" - # shellcheck disable=SC2039,SC2164 - pushd contrib - # shellcheck disable=SC2039,SC2164 - pushd gmp - make clean || true - make distclean || true - echo "HOST: $HOST" - echo "PREFIX: ${CURRENT_DIR}/gmplib-${PFX}" - - cat >"$CONFIGURESCRIPT" << EOF -#!/bin/sh -./configure \ -CC="$CLANG" CFLAGS="$CFLAGS" CPPFLAGS="$CFLAGS" LDFLAGS="$CFLAGS" \ ---host=${HOST} --prefix="${CURRENT_DIR}/gmplib-${PFX}" \ ---disable-shared --enable-static --disable-assembly -v -EOF - - chmod a+x "$CONFIGURESCRIPT" - sh "$CONFIGURESCRIPT" - rm "$CONFIGURESCRIPT" - - # shellcheck disable=SC2039 - mkdir -p "${CURRENT_DIR}/log" - # shellcheck disable=SC2039 - make -j "$LOGICALCPU_MAX" &> "${CURRENT_DIR}"/log/gmplib-"${PFX}"-build.log - # shellcheck disable=SC2039 - make install &> "${CURRENT_DIR}"/log/gmplib-"${PFX}"-install.log - #make check - #exit 1 - # shellcheck disable=SC2039,SC2164 - popd # gmp - # shellcheck disable=SC2039,SC2164 - popd # contrib - # shellcheck disable=SC2039,SC2164 - popd # build -} - -build_relic_arch() { - PLATFORM=$1 - ARCH=$2 - PFX=${PLATFORM}-${ARCH} - - # shellcheck disable=SC2039,SC2164 - pushd ${BUILD} - - SDK=$(xcrun --sdk "$PLATFORM" --show-sdk-path) - - BUILDDIR=relic-"${PFX}" - TOOLCHAIN=$(pwd)/ios.toolchain.cmake - GMP_PFX=$(pwd)/gmplib-${PFX} - rm -rf "$BUILDDIR" - mkdir "$BUILDDIR" - # shellcheck disable=SC2039,SC2164 - pushd "$BUILDDIR" - - unset CC - # shellcheck disable=SC2155 - export CC=$(xcrun --sdk "${PLATFORM}" --find clang) - - WSIZE=0 - IOS_PLATFORM="" - OPTIMIZATIONFLAGS="" - DEPLOYMENT_TARGET="" - - # shellcheck disable=SC2039 - # shellcheck disable=SC2053 - if [[ $PLATFORM = $IPHONEOS ]]; then - if [[ $ARCH = "arm64" ]] || [[ $ARCH = "arm64e" ]]; then - IOS_PLATFORM=OS64 - DEPLOYMENT_TARGET=$MIN_IOS - WSIZE=64 - OPTIMIZATIONFLAGS=-fomit-frame-pointer - else - IOS_PLATFORM=OS - WSIZE=32 - fi - elif [[ $PLATFORM = $IPHONESIMULATOR ]]; then - if [[ $ARCH = "x86_64" ]]; then - IOS_PLATFORM=SIMULATOR64 - DEPLOYMENT_TARGET=$MIN_IOS - WSIZE=64 - OPTIMIZATIONFLAGS=-fomit-frame-pointer - elif [[ $ARCH = "arm64" ]]; then - IOS_PLATFORM=SIMULATORARM64 - DEPLOYMENT_TARGET=$MIN_IOS - WSIZE=64 - else - IOS_PLATFORM=SIMULATOR - WSIZE=32 - fi - elif [[ $PLATFORM = $WATCHOS ]]; then - IOS_PLATFORM=WATCHOS - DEPLOYMENT_TARGET=$MIN_WATCHOS - WSIZE=32 - elif [[ $PLATFORM = $WATCHSIMULATOR ]]; then - IOS_PLATFORM=SIMULATOR_WATCHOS - DEPLOYMENT_TARGET=$MIN_WATCHOS - WSIZE=32 - elif [[ $PLATFORM = $TVOS ]]; then - IOS_PLATFORM=TVOS - DEPLOYMENT_TARGET=$MIN_TVOS - WSIZE=64 - OPTIMIZATIONFLAGS=-fomit-frame-pointer - elif [[ $PLATFORM = $TVSIMULATOR ]]; then - IOS_PLATFORM=SIMULATOR_TVOS - #TODO - if [[ $ARCH = "arm64" ]] - then - IOS_PLATFORM=OS64 - fi - DEPLOYMENT_TARGET=$MIN_TVOS - WSIZE=64 - OPTIMIZATIONFLAGS=-fomit-frame-pointer - elif [[ $PLATFORM = $MACOS ]]; then - WSIZE=64 - IOS_PLATFORM=MAC - if [[ $ARCH = "arm64" ]] - then - IOS_PLATFORM=MAC_ARM64 - fi - DEPLOYMENT_TARGET=$MIN_MACOS - OPTIMIZATIONFLAGS=-fomit-frame-pointer - fi - - COMPILER_ARGS="$(version_min_flag "$PLATFORM") -Wno-unused-functions" - - EXTRA_ARGS="-DOPSYS=NONE -DPLATFORM=$IOS_PLATFORM -DDEPLOYMENT_TARGET=$DEPLOYMENT_TARGET -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN" - - # shellcheck disable=SC2039 - if [[ $ARCH = "i386" ]]; then - EXTRA_ARGS+=" -DARCH=X86" - elif [[ $ARCH = "x86_64" ]]; then - EXTRA_ARGS+=" -DARCH=X64" - elif [[ $ARCH = "arm64" ]]; then - # Relic doesn't support aarch64 yet, "ARCH=ARM" is for ARM 32-bit architecture only - EXTRA_ARGS+=" -DIOS_ARCH=arm64 -DARCH=" - elif [[ $ARCH = "armv7s" ]]; then - EXTRA_ARGS+=" -DIOS_ARCH=armv7s -DARCH=ARM" - elif [[ $ARCH = "armv7k" ]]; then - EXTRA_ARGS+=" -DIOS_ARCH=armv7k -DARCH=ARM" - elif [[ $ARCH = "arm64_32" ]]; then - EXTRA_ARGS+=" -DIOS_ARCH=arm64_32 -DARCH=ARM" - fi - - CURRENT_DIR=$(pwd) - cmake -DCMAKE_PREFIX_PATH:PATH="${GMP_PFX}" -DTESTS=0 -DBENCH=0 -DBUILD_BLS_JS_BINDINGS=0 -DBUILD_BLS_PYTHON_BINDINGS=0 \ - -DBUILD_BLS_BENCHMARKS=0 -DBUILD_BLS_TESTS=0 -DCHECK=off -DARITH=gmp -DTIMER=HPROC -DFP_PRIME=381 -DMULTI=PTHREAD \ - -DFP_QNRES=on -DFP_METHD="INTEG;INTEG;INTEG;MONTY;EXGCD;SLIDE" -DFPX_METHD="INTEG;INTEG;LAZYR" -DPP_METHD="LAZYR;OATEP" \ - -DCOMP_FLAGS="-pipe -std=c99 -O3 -funroll-loops $OPTIMIZATIONFLAGS -isysroot $SDK -arch $ARCH -fembed-bitcode ${COMPILER_ARGS}" \ - -DWSIZE=$WSIZE -DVERBS=off -DSHLIB=off -DALLOC="AUTO" -DEP_PLAIN=off -DEP_SUPER=off -DPP_EXT="LAZYR" \ - -DWITH="DV;BN;MD;FP;EP;FPX;EPX;PP;PC;CP" -DBN_METHD="COMBA;COMBA;MONTY;SLIDE;STEIN;BASIC" ${EXTRA_ARGS} ../../ - - make -j "$LOGICALCPU_MAX" - # shellcheck disable=SC2039,SC2164 - popd # "$BUILDDIR" - # shellcheck disable=SC2039,SC2164 - popd # depends/relic -} - -build_bls_arch() { - # shellcheck disable=SC2039 - BLS_FILES=( "bls" "chaincode" "elements" "extendedprivatekey" "extendedpublickey" "legacy" "privatekey" "schemes" "threshold" ) - # shellcheck disable=SC2039 - ALL_BLS_OBJ_FILES=$(printf "%s.o " "${BLS_FILES[@]}") - - PLATFORM=$1 - ARCH=$2 - PFX=${PLATFORM}-${ARCH} - SDK=$(xcrun --sdk "$PLATFORM" --show-sdk-path) - - BUILDDIR=${BUILD}/bls-"${PFX}" - rm -rf "$BUILDDIR" - mkdir "$BUILDDIR" - # shellcheck disable=SC2039,SC2164 - pushd "$BUILDDIR" - - EXTRA_ARGS="$(version_min_flag "$PLATFORM")" - - CURRENT_DIR=$(pwd) - - # shellcheck disable=SC2039 - for F in "${BLS_FILES[@]}" - do - clang -I"../contrib/relic/include" \ - -I"../../depends/relic/include" \ - -I"../../include/dashbls" \ - -I"../relic-${PFX}/depends/relic/include" \ - -I"../../src/" \ - -I"../gmplib-${PFX}/include" \ - -x c++ -std=c++14 -stdlib=libc++ -fembed-bitcode -arch "${ARCH}" -isysroot "${SDK}" "${EXTRA_ARGS}" \ - -c "../../src/${F}.cpp" -o "${F}.o" - done - - # shellcheck disable=SC2086 - xcrun -sdk "$PLATFORM" ar -cvq libbls.a $ALL_BLS_OBJ_FILES - - # shellcheck disable=SC2039,SC2164 - popd # "$BUILDDIR" -} - -build_all_arch() { - PLATFORM=$1 - ARCH=$2 - build_gmp_arch "$PLATFORM" "$ARCH" - build_relic_arch "$PLATFORM" "$ARCH" - build_bls_arch "$PLATFORM" "$ARCH" -} - -build_target() { - BUILD_IN=$1 - echo "Build target: $BUILD_IN" - ARCH="" - PLATFORM="" - # shellcheck disable=SC2039 - if [[ $BUILD_IN = "x86_64-apple-ios" ]]; then - ARCH=x86_64 - PLATFORM=$IPHONESIMULATOR - elif [[ $BUILD_IN = "aarch64-apple-ios" ]]; then - ARCH=arm64 - PLATFORM=$IPHONEOS - elif [[ $BUILD_IN = "aarch64-apple-ios-sim" ]]; then - ARCH=arm64 - PLATFORM=$IPHONESIMULATOR - elif [[ $BUILD_IN = "x86_64-apple-darwin" ]]; then - ARCH=x86_64 - PLATFORM=$MACOS - elif [[ $BUILD_IN = "aarch64-apple-darwin" ]]; then - ARCH=arm64 - PLATFORM=$MACOS - fi - build_all_arch "$PLATFORM" "$ARCH" - PFX="${PLATFORM}"-"${ARCH}" - rm -rf "build/artefacts/${BUILD_IN}" - mkdir -p "build/artefacts/${BUILD_IN}" - cp "build/gmplib-${PFX}/lib/libgmp.a" "build/artefacts/${BUILD_IN}" - cp "build/relic-${PFX}/depends/relic/lib/librelic_s.a" "build/artefacts/${BUILD_IN}" -# cp "build/relic-${PFX}/depends/sodium/libsodium.a" "build/artefacts/${BUILD_IN}" - cp "build/bls-${PFX}/libbls.a" "build/artefacts/${BUILD_IN}" -# cp -rf build/bls-"${PFX}"/*.o build/artefacts/"${BUILD_IN}"/include -# cp -rf src/*.hpp build/artefacts/"${BUILD_IN}"/include -# cp -rf build/gmplib-"${PFX}"/include/gmp.h build/artefacts/"${BUILD_IN}"/include -# cp -rf build/relic-"${PFX}"/_deps/relic-build/include/*.h build/artefacts/"${BUILD_IN}"/include -} - -prepare -build_target "$TARGET" diff --git a/src/dashbls/autogen.sh b/src/dashbls/autogen.sh deleted file mode 100755 index f3e943e167db..000000000000 --- a/src/dashbls/autogen.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh -export LC_ALL=C -set -e -srcdir="$(dirname "$0")" -cd "$srcdir" -if [ -z "${LIBTOOLIZE}" ] && GLIBTOOLIZE="$(command -v glibtoolize)"; then - LIBTOOLIZE="${GLIBTOOLIZE}" - export LIBTOOLIZE -fi -command -v autoreconf >/dev/null || \ - (echo "configuration failed, please install autoconf first" && exit 1) -autoreconf --install --force --warnings=all -autoheader --force --replace-handwritten || autoheader --force diff --git a/src/dashbls/binds/python/CMakeLists.txt b/src/dashbls/binds/python/CMakeLists.txt deleted file mode 100644 index 9117ade8f3cf..000000000000 --- a/src/dashbls/binds/python/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -find_package(pybind11 2.13.6 CONFIG QUIET) - -if(NOT pybind11_FOUND) - message(STATUS "pybind11 not found locally; fetching it") - include(FetchContent) - FetchContent_Declare( - pybind11 - GIT_REPOSITORY https://github.com/pybind/pybind11.git - GIT_TAG v2.13.6 - ) - FetchContent_MakeAvailable(pybind11) -endif() - -pybind11_add_module(dashbls_py ${CMAKE_CURRENT_SOURCE_DIR}/pythonbindings.cpp) -set_target_properties(dashbls_py PROPERTIES OUTPUT_NAME dashbls) -target_include_directories(dashbls_py PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/../../include -) -target_link_libraries(dashbls_py PRIVATE dashbls) - -if(VERSION_INFO) - target_compile_definitions(dashbls_py PRIVATE VERSION_INFO="${VERSION_INFO}") -endif() diff --git a/src/dashbls/binds/python/conftest.py b/src/dashbls/binds/python/conftest.py deleted file mode 100644 index d595d6ea8ca8..000000000000 --- a/src/dashbls/binds/python/conftest.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env python3 -# coding: latin-1 - -# -# Copyright (c) 2026-present, The Dash Core developers -# SPDX-License-Identifier: Apache-2.0 -# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 -# - -"""Allow samples to be imported by name.""" - -import sys -from pathlib import Path - -sys.path.insert(0, str(Path(__file__).parent / "samples")) diff --git a/src/dashbls/binds/python/pythonbindings.cpp b/src/dashbls/binds/python/pythonbindings.cpp deleted file mode 100644 index 0cc223d6e726..000000000000 --- a/src/dashbls/binds/python/pythonbindings.cpp +++ /dev/null @@ -1,759 +0,0 @@ -// Copyright 2020 Chia Network Inc - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace py = pybind11; -using namespace bls; - -namespace { -inline int PyLong_AsByteArray(PyLongObject* obj, uint8_t* buf, Py_ssize_t size, bool is_le, bool is_signed) -{ - return _PyLong_AsByteArray(obj, buf, size, is_le, is_signed -#if PY_VERSION_HEX >= 0x030d0000 - , /*with_exceptions=*/true -#endif // PY_VERSION_HEX >= 0x030d0000 - ); -} - -// relic's context is process-wide here (MULTI is unset, see setup.py), so a -// released GIL leaves threads racing on its error code and PRNG state. The -// GIL goes first so a waiter cannot strand the holder that must retake it. -std::mutex &RelicMutex() -{ - static std::mutex mutex; - return mutex; -} - -struct RelicGuard { - RelicGuard() : lock(RelicMutex()) {} - - py::gil_scoped_release release; - std::lock_guard lock; -}; - -// Measure before copying, so an oversized input fails as ValueError instead of -// bad_alloc, and measure the header rather than py::len, because a subclass may -// override __len__ while the copy below still takes the backing payload. -std::string CopyChecked(const py::bytes &b, size_t limit, const char *who, const char *what) -{ - const auto signed_size = PyBytes_Size(b.ptr()); - if (signed_size < 0) { - throw py::error_already_set(); - } - const auto size = static_cast(signed_size); - if (size > limit) { - throw std::invalid_argument( - std::string(who) + ": " + what + " must be at most " + std::to_string(limit) + - " bytes, got " + std::to_string(size)); - } - return std::string(b); -} - -// md_xmd caps a tag at 255 bytes but compares signed, so a tag at or beyond -// 2 GiB truncates negative, slips the guard and is widened back to a huge -// length. -std::string CopyDst(const py::bytes &dst, const char *who) -{ - return CopyChecked(dst, 255, who, "domain separation tag"); -} - -// ep_map_dst takes the message length as an int and md_xmd checks only the -// output and tag lengths, so nothing on relic's side catches a message at or -// beyond 2 GiB narrowing negative on the way in. -std::string CopyMsg(const py::bytes &msg, const char *who) -{ - return CopyChecked(msg, std::numeric_limits::max(), who, "message"); -} - -// The augmented schemes prepend a serialized G1Element and hand the result to -// the same int-typed length, so the message has to leave room for the prefix. -std::string CopyAugMsg(const py::bytes &msg, const char *who) -{ - return CopyChecked( - msg, std::numeric_limits::max() - G1Element::SIZE, who, "message"); -} - -// relic is built ALLOC=AUTO, so md_hmac stages the seed on the stack and a few -// MiB of it takes the process down. Nothing near this cap is a legitimate IKM -// (the spec floor is 32 bytes), so keep it far below any thread's stack. -std::string CopySeed(const py::bytes &seed, const char *who) -{ - return CopyChecked(seed, 64 * 1024, who, "seed"); -} - -std::vector ToVec(const std::string &s) -{ - return std::vector(s.begin(), s.end()); -} - -// Bytes is a pointer and a length, so a strided view has no counterpart to -// mirror; ask CPython for a contiguous one and let it raise, rather than -// reinterpreting info.ptr as contiguous and reading past the caller's view. -template -std::array CopyBuffer(const py::buffer &b, const char *what) -{ - auto *view = new Py_buffer(); - if (PyObject_GetBuffer(b.ptr(), view, PyBUF_C_CONTIGUOUS | PyBUF_FORMAT) != 0) { - delete view; - throw py::error_already_set(); - } - py::buffer_info info(view); - - if (info.format != py::format_descriptor::format() || info.ndim != 1) - throw std::runtime_error("Incompatible buffer format!"); - - if (info.size != static_cast(N)) { - throw std::invalid_argument( - std::string("Length of bytes object not equal to ") + what); - } - - std::array data; - const auto *data_ptr = reinterpret_cast(info.ptr); - std::copy(data_ptr, data_ptr + N, data.data()); - return data; -} -} // anonymous namespace - -PYBIND11_MODULE(dashbls, m) -{ - py::class_(m, "PrivateKey") - .def_property_readonly_static( - "PRIVATE_KEY_SIZE", - [](py::object self) { return PrivateKey::PRIVATE_KEY_SIZE; }) - .def( - "from_bytes", - [](py::buffer const b) { - auto data = CopyBuffer(b, "PrivateKey::SIZE"); - RelicGuard guard; - return PrivateKey::FromBytes(data); - }) - .def( - "__bytes__", - [](const PrivateKey &k) { - uint8_t *output = - Util::SecAlloc(PrivateKey::PRIVATE_KEY_SIZE); - { - RelicGuard guard; - k.Serialize(output); - } - py::bytes ret = py::bytes( - reinterpret_cast(output), - PrivateKey::PRIVATE_KEY_SIZE); - Util::SecFree(output); - return ret; - }) - .def( - "__deepcopy__", - [](const PrivateKey &k, const py::object &memo) { - RelicGuard guard; - return PrivateKey(k); - }) - .def("get_g1", [](const PrivateKey &k) { - RelicGuard guard; - return k.GetG1Element(); - }) - .def("aggregate", &PrivateKey::Aggregate, py::call_guard()) - .def(py::self == py::self, py::call_guard()) - .def(py::self != py::self, py::call_guard()) - .def("__repr__", [](const PrivateKey &k) { - RelicGuard guard; - uint8_t *output = Util::SecAlloc(PrivateKey::PRIVATE_KEY_SIZE); - k.Serialize(output); - std::string ret = - ""; - Util::SecFree(output); - return ret; - }); - - py::class_(m, "Util").def("hash256", [](const py::bytes &message) { - // Hash256 takes a size_t but md_map_sh256 narrows it to an int - const auto str = CopyMsg(message, "Util.hash256"); - uint8_t output[BLS::MESSAGE_HASH_LEN]; - { - RelicGuard guard; - Util::Hash256(output, (const uint8_t *)str.data(), str.size()); - } - return py::bytes( - reinterpret_cast(output), BLS::MESSAGE_HASH_LEN); - }); - - py::class_(m, "BasicSchemeMPL") - .def("sk_to_g1", [](const PrivateKey &seckey){ - RelicGuard guard; - return BasicSchemeMPL().SkToG1(seckey); - }) - .def( - "key_gen", - [](const py::bytes &b) { - const auto str = CopySeed(b, "BasicSchemeMPL.key_gen"); - RelicGuard guard; - return BasicSchemeMPL().KeyGen(ToVec(str)); - }) - .def("derive_child_sk", [](const PrivateKey& sk, uint32_t index){ - RelicGuard guard; - return BasicSchemeMPL().DeriveChildSk(sk, index); - }) - .def("derive_child_sk_unhardened", [](const PrivateKey& sk, uint32_t index){ - RelicGuard guard; - return BasicSchemeMPL().DeriveChildSkUnhardened(sk, index); - }) - .def("derive_child_pk_unhardened", [](const G1Element& pk, uint32_t index){ - RelicGuard guard; - return BasicSchemeMPL().DeriveChildPkUnhardened(pk, index); - }) - .def("aggregate", [](const vector &signatures) { - RelicGuard guard; - return BasicSchemeMPL().Aggregate(signatures); - }) - .def( - "sign", - [](const PrivateKey &pk, const py::bytes &msg) { - const auto s = CopyMsg(msg, "BasicSchemeMPL.sign"); - RelicGuard guard; - return BasicSchemeMPL().Sign(pk, ToVec(s)); - }) - .def( - "verify", - [](const G1Element &pk, - const py::bytes &msg, - const G2Element &sig) { - const auto s = CopyMsg(msg, "BasicSchemeMPL.verify"); - RelicGuard guard; - return BasicSchemeMPL().Verify(pk, ToVec(s), sig); - }) - .def( - "aggregate_verify", - [](const vector &pks, - const vector &msgs, - const G2Element &sig) { - vector> vecs(msgs.size()); - for (size_t i = 0; i < msgs.size(); ++i) { - vecs[i] = ToVec( - CopyMsg(msgs[i], "BasicSchemeMPL.aggregate_verify")); - } - RelicGuard guard; - return BasicSchemeMPL().AggregateVerify(pks, vecs, sig); - }) - .def( - "g2_from_message", - [](const py::bytes &msg) { - const auto msg_str = CopyMsg(msg, "BasicSchemeMPL.g2_from_message"); - RelicGuard guard; - const auto msg_bytes = Bytes((const uint8_t *)msg_str.c_str(), msg_str.size()); - return G2Element::FromMessage( - msg_bytes, - (const uint8_t *)BasicSchemeMPL::CIPHERSUITE_ID.c_str(), - BasicSchemeMPL::CIPHERSUITE_ID.size() - ); - }); - - py::class_(m, "AugSchemeMPL") - .def("sk_to_g1", [](const PrivateKey &seckey){ - RelicGuard guard; - return AugSchemeMPL().SkToG1(seckey); - }) - .def( - "key_gen", - [](const py::bytes &b) { - const auto str = CopySeed(b, "AugSchemeMPL.key_gen"); - RelicGuard guard; - return AugSchemeMPL().KeyGen(ToVec(str)); - }) - .def("derive_child_sk", [](const PrivateKey& sk, uint32_t index){ - RelicGuard guard; - return AugSchemeMPL().DeriveChildSk(sk, index); - }) - .def("derive_child_sk_unhardened", [](const PrivateKey& sk, uint32_t index){ - RelicGuard guard; - return AugSchemeMPL().DeriveChildSkUnhardened(sk, index); - }) - .def("derive_child_pk_unhardened", [](const G1Element& pk, uint32_t index){ - RelicGuard guard; - return AugSchemeMPL().DeriveChildPkUnhardened(pk, index); - }) - .def("aggregate", [](const vector& signatures) { - RelicGuard guard; - return AugSchemeMPL().Aggregate(signatures); - }) - .def( - "sign", - [](const PrivateKey &pk, const py::bytes &msg) { - const auto s = CopyAugMsg(msg, "AugSchemeMPL.sign"); - RelicGuard guard; - return AugSchemeMPL().Sign(pk, ToVec(s)); - }) - .def( - "sign", - [](const PrivateKey &pk, - const py::bytes &msg, - const G1Element &prepend_pk) { - const auto s = CopyAugMsg(msg, "AugSchemeMPL.sign"); - RelicGuard guard; - return AugSchemeMPL().Sign(pk, ToVec(s), prepend_pk); - }) - .def( - "verify", - [](const G1Element &pk, - const py::bytes &msg, - const G2Element &sig) { - const auto s = CopyAugMsg(msg, "AugSchemeMPL.verify"); - RelicGuard guard; - return AugSchemeMPL().Verify(pk, ToVec(s), sig); - }) - .def( - "aggregate_verify", - [](const vector &pks, - const vector &msgs, - const G2Element &sig) { - vector> vecs(msgs.size()); - for (size_t i = 0; i < msgs.size(); ++i) { - vecs[i] = ToVec( - CopyAugMsg(msgs[i], "AugSchemeMPL.aggregate_verify")); - } - RelicGuard guard; - return AugSchemeMPL().AggregateVerify(pks, vecs, sig); - }) - .def( - "g2_from_message", - [](const py::bytes &msg) { - const auto msg_str = CopyMsg(msg, "AugSchemeMPL.g2_from_message"); - RelicGuard guard; - const auto msg_bytes = Bytes((const uint8_t *)msg_str.c_str(), msg_str.size()); - return G2Element::FromMessage( - msg_bytes, - (const uint8_t *)AugSchemeMPL::CIPHERSUITE_ID.c_str(), - AugSchemeMPL::CIPHERSUITE_ID.size() - ); - }); - - py::class_(m, "PopSchemeMPL") - .def("sk_to_g1", [](const PrivateKey &seckey){ - RelicGuard guard; - return PopSchemeMPL().SkToG1(seckey); - }) - .def( - "key_gen", - [](const py::bytes &b) { - const auto str = CopySeed(b, "PopSchemeMPL.key_gen"); - RelicGuard guard; - return PopSchemeMPL().KeyGen(ToVec(str)); - }) - .def("derive_child_sk", [](const PrivateKey& sk, uint32_t index){ - RelicGuard guard; - return PopSchemeMPL().DeriveChildSk(sk, index); - }) - .def("derive_child_sk_unhardened", [](const PrivateKey& sk, uint32_t index){ - RelicGuard guard; - return PopSchemeMPL().DeriveChildSkUnhardened(sk, index); - }) - .def("derive_child_pk_unhardened", [](const G1Element& pk, uint32_t index){ - RelicGuard guard; - return PopSchemeMPL().DeriveChildPkUnhardened(pk, index); - }) - .def("aggregate", [](const vector& signatures) { - RelicGuard guard; - return PopSchemeMPL().Aggregate(signatures); - }) - .def( - "sign", - [](const PrivateKey &pk, const py::bytes &msg) { - const auto s = CopyMsg(msg, "PopSchemeMPL.sign"); - RelicGuard guard; - return PopSchemeMPL().Sign(pk, ToVec(s)); - }) - .def( - "verify", - [](const G1Element &pk, - const py::bytes &msg, - const G2Element &sig) { - const auto s = CopyMsg(msg, "PopSchemeMPL.verify"); - RelicGuard guard; - return PopSchemeMPL().Verify(pk, ToVec(s), sig); - }) - .def( - "aggregate_verify", - [](const vector &pks, - const vector &msgs, - const G2Element &sig) { - vector> vecs(msgs.size()); - for (size_t i = 0; i < msgs.size(); ++i) { - vecs[i] = - ToVec(CopyMsg(msgs[i], "PopSchemeMPL.aggregate_verify")); - } - RelicGuard guard; - return PopSchemeMPL().AggregateVerify(pks, vecs, sig); - }) - .def( - "g2_from_message", - [](const py::bytes &msg) { - const auto msg_str = CopyMsg(msg, "PopSchemeMPL.g2_from_message"); - RelicGuard guard; - const auto msg_bytes = Bytes((const uint8_t *)msg_str.c_str(), msg_str.size()); - return G2Element::FromMessage( - msg_bytes, - (const uint8_t *)PopSchemeMPL::CIPHERSUITE_ID.c_str(), - PopSchemeMPL::CIPHERSUITE_ID.size() - ); - }) - .def("pop_prove", [](const PrivateKey& privateKey){ - RelicGuard guard; - return PopSchemeMPL().PopProve(privateKey); - }) - .def("pop_verify", [](const G1Element& pubkey, const G2Element& signature){ - RelicGuard guard; - return PopSchemeMPL().PopVerify(pubkey, signature); - }) - .def( - "fast_aggregate_verify", - [](const vector &pks, - const py::bytes &msg, - const G2Element &sig) { - const auto s = CopyMsg(msg, "PopSchemeMPL.fast_aggregate_verify"); - RelicGuard guard; - return PopSchemeMPL().FastAggregateVerify(pks, ToVec(s), sig); - }); - - py::class_(m, "G1Element") - .def_property_readonly_static( - "SIZE", [](py::object self) { return G1Element::SIZE; }) - .def(py::init([](){ - RelicGuard guard; - return G1Element(); - })) - .def(py::init(&G1Element::FromByteVector), py::call_guard()) - .def(py::init([](py::int_ pyint) { - std::array buffer{}; - if (PyLong_AsByteArray( - (PyLongObject *)pyint.ptr(), - buffer.data(), - buffer.size(), - 0, - 0) < 0) { - throw std::invalid_argument("Failed to cast int to G1Element"); - } - RelicGuard guard; - return G1Element::FromBytes(buffer); - })) - .def(py::init([](py::buffer const b) { - auto data = CopyBuffer(b, "G1Element::SIZE"); - RelicGuard guard; - return G1Element::FromBytes(data); - })) - .def( - "from_bytes", - [](py::buffer const b) { - auto data = CopyBuffer(b, "G1Element::SIZE"); - RelicGuard guard; - return G1Element::FromBytes(data); - }) - .def( - "from_bytes_unchecked", - [](py::buffer const b) { - auto data = CopyBuffer(b, "G1Element::SIZE"); - RelicGuard guard; - return G1Element::FromBytesUnchecked(data); - }) - .def("generator", &G1Element::Generator, py::call_guard()) - .def_static( - "from_message", - [](const py::bytes &msg, const py::bytes &dst) { - const auto msg_str = CopyMsg(msg, "G1Element.from_message"); - const auto dst_str = CopyDst(dst, "G1Element.from_message"); - RelicGuard guard; - return G1Element::FromMessage( - Bytes((const uint8_t *)msg_str.c_str(), msg_str.size()), - (const uint8_t *)dst_str.c_str(), - (int)dst_str.size()); - }, - py::arg("msg"), - py::arg("dst")) - .def("pair", &G1Element::Pair, py::call_guard()) - .def("negate", &G1Element::Negate, py::call_guard()) - .def("get_fingerprint", &G1Element::GetFingerprint, py::call_guard()) - - .def(py::self == py::self, py::call_guard()) - .def(py::self != py::self, py::call_guard()) - .def( - "__deepcopy__", - [](const G1Element &g1, const py::object &memo) { - RelicGuard guard; - return G1Element(g1); - }) - .def( - "__add__", - [](G1Element &self, G1Element &other) { - RelicGuard guard; - return self + other; - }, - py::is_operator()) - .def( - "__and__", - [](G1Element &self, G2Element &other) { - RelicGuard guard; - return self & other; - }, - py::is_operator()) - .def( - "__repr__", - [](const G1Element &ele) { - RelicGuard guard; - std::stringstream s; - s << ele; - return ""; - }) - .def( - "__str__", - [](const G1Element &ele) { - RelicGuard guard; - std::stringstream s; - s << ele; - return s.str(); - }) - .def( - "__bytes__", - [](const G1Element &ele) { - vector out; - { - RelicGuard guard; - out = ele.Serialize(); - } - py::bytes ans = py::bytes( - reinterpret_cast(out.data()), G1Element::SIZE); - return ans; - }) - .def("__deepcopy__", [](const G1Element &ele, const py::object &memo) { - RelicGuard guard; - return G1Element(ele); - }); - - py::class_(m, "G2Element") - .def_property_readonly_static( - "SIZE", [](py::object self) { return G2Element::SIZE; }) - .def(py::init([](){ - RelicGuard guard; - return G2Element(); - })) - .def(py::init(&G2Element::FromByteVector), py::call_guard()) - .def(py::init([](py::buffer const b) { - auto data = CopyBuffer(b, "G2Element::SIZE"); - RelicGuard guard; - return G2Element::FromBytes(data); - })) - .def(py::init([](py::int_ pyint) { - std::array buffer{}; - if (PyLong_AsByteArray( - (PyLongObject *)pyint.ptr(), - buffer.data(), - buffer.size(), - 0, - 0) < 0) { - throw std::invalid_argument("Failed to cast int to G2Element"); - } - RelicGuard guard; - return G2Element::FromBytes(buffer); - })) - .def( - "from_bytes", - [](py::buffer const b) { - auto data = CopyBuffer(b, "G2Element::SIZE"); - RelicGuard guard; - return G2Element::FromBytes(data); - }) - .def( - "from_bytes_unchecked", - [](py::buffer const b) { - auto data = CopyBuffer(b, "G2Element::SIZE"); - RelicGuard guard; - return G2Element::FromBytesUnchecked(data); - }) - .def("generator", &G2Element::Generator, py::call_guard()) - .def_static( - "from_message", - [](const py::bytes &msg, const py::bytes &dst) { - const auto msg_str = CopyMsg(msg, "G2Element.from_message"); - const auto dst_str = CopyDst(dst, "G2Element.from_message"); - RelicGuard guard; - return G2Element::FromMessage( - Bytes((const uint8_t *)msg_str.c_str(), msg_str.size()), - (const uint8_t *)dst_str.c_str(), - (int)dst_str.size()); - }, - py::arg("msg"), - py::arg("dst")) - .def("pair", &G2Element::Pair, py::call_guard()) - .def("negate", &G2Element::Negate, py::call_guard()) - .def( - "__deepcopy__", - [](const G2Element &g2, const py::object &memo) { - RelicGuard guard; - return G2Element(g2); - }) - .def(py::self == py::self, py::call_guard()) - .def(py::self != py::self, py::call_guard()) - - .def( - "__add__", - [](G2Element &self, G2Element &other) { - RelicGuard guard; - return self + other; - }, - py::is_operator()) - .def( - "__repr__", - [](const G2Element &ele) { - RelicGuard guard; - std::stringstream s; - s << ele; - return ""; - }) - .def( - "__str__", - [](const G2Element &ele) { - RelicGuard guard; - std::stringstream s; - s << ele; - return s.str(); - }) - .def( - "__bytes__", - [](const G2Element &ele) { - vector out; - { - RelicGuard guard; - out = ele.Serialize(); - } - py::bytes ans = py::bytes( - reinterpret_cast(out.data()), G2Element::SIZE); - return ans; - }) - .def("__deepcopy__", [](const G2Element &ele, const py::object &memo) { - RelicGuard guard; - return G2Element(ele); - }); - - py::class_(m, "GTElement") - .def_property_readonly_static( - "SIZE", [](py::object self) { return GTElement::SIZE; }) - .def(py::init(>Element::FromByteVector), py::call_guard()) - .def(py::init([](py::buffer const b) { - auto data = CopyBuffer(b, "GTElement::SIZE"); - RelicGuard guard; - return GTElement::FromBytes(data); - })) - .def(py::init([](py::int_ pyint) { - std::array buffer{}; - if (PyLong_AsByteArray( - (PyLongObject *)pyint.ptr(), - buffer.data(), - buffer.size(), - 0, - 0) < 0) { - throw std::invalid_argument("Failed to cast int to GTElement"); - } - RelicGuard guard; - return GTElement::FromBytes(buffer); - })) - .def( - "from_bytes", - [](py::buffer const b) { - auto data = CopyBuffer(b, "GTElement::SIZE"); - RelicGuard guard; - return GTElement::FromBytes(data); - }) - .def( - "from_bytes_unchecked", - [](py::buffer const b) { - auto data = CopyBuffer(b, "GTElement::SIZE"); - RelicGuard guard; - return GTElement::FromBytesUnchecked(data); - }) - .def("unity", >Element::Unity, py::call_guard()) - .def(py::self == py::self, py::call_guard()) - .def(py::self != py::self, py::call_guard()) - .def( - "__deepcopy__", - [](const GTElement >, const py::object &memo) { - RelicGuard guard; - return GTElement(gt); - }) - .def( - "__repr__", - [](const GTElement &ele) { - RelicGuard guard; - std::stringstream s; - s << ele; - return ""; - }) - .def( - "__str__", - [](const GTElement &ele) { - RelicGuard guard; - std::stringstream s; - s << ele; - return s.str(); - }) - .def( - "__bytes__", - [](const GTElement &ele) { - uint8_t *out = new uint8_t[GTElement::SIZE]; - { - RelicGuard guard; - ele.Serialize(out); - } - py::bytes ans = - py::bytes(reinterpret_cast(out), GTElement::SIZE); - delete[] out; - return ans; - }) - .def( - "__mul__", - [](GTElement &self, GTElement &other) { - RelicGuard guard; - return self * other; - }, - py::is_operator()) - .def("__deepcopy__", [](const GTElement &ele, const py::object &memo) { - RelicGuard guard; - return GTElement(ele); - }); - - m.attr("PublicKeyMPL") = m.attr("G1Element"); - m.attr("SignatureMPL") = m.attr("G2Element"); - -#ifdef VERSION_INFO - m.attr("__version__") = VERSION_INFO; -#else - m.attr("__version__") = "dev"; -#endif -} diff --git a/src/dashbls/binds/python/samples/aggregate_signatures.py b/src/dashbls/binds/python/samples/aggregate_signatures.py deleted file mode 100755 index 014d1fac08c4..000000000000 --- a/src/dashbls/binds/python/samples/aggregate_signatures.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python3 -# coding: latin-1 - -# -# Copyright (c) 2020-present, Chia Network Inc. -# Copyright (c) 2026-present, The Dash Core developers -# SPDX-License-Identifier: Apache-2.0 -# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 -# - -"""Aggregate signatures from multiple keys over multiple messages.""" - -from dashbls import AugSchemeMPL, G1Element, G2Element, PrivateKey - -SEED: bytes = bytes.fromhex("003206f418c701193458c013120c5906dc12663ad1520c3e596eb6092c14fe16") - - -def aggregate_signatures() -> None: - # Two independent signers, each with their own message - sk1: PrivateKey = AugSchemeMPL.key_gen(bytes([1]) + SEED[1:]) - sk2: PrivateKey = AugSchemeMPL.key_gen(bytes([2]) + SEED[1:]) - - message1: bytes = bytes([1, 2, 3, 4, 5]) - message2: bytes = bytes([1, 2, 3, 4, 5, 6, 7]) - - pk1: G1Element = sk1.get_g1() - sig1: G2Element = AugSchemeMPL.sign(sk1, message1) - - pk2: G1Element = sk2.get_g1() - sig2: G2Element = AugSchemeMPL.sign(sk2, message2) - - # Signatures can be non-interactively combined by anyone - agg_sig: G2Element = AugSchemeMPL.aggregate([sig1, sig2]) - - # Verifying an aggregate over distinct messages needs every public key and - # every message, in the order they were signed in - ok = AugSchemeMPL.aggregate_verify([pk1, pk2], [message1, message2], agg_sig) - assert ok - - print(f"aggregate signature: {bytes(agg_sig).hex()}") - - -if __name__ == "__main__": - aggregate_signatures() diff --git a/src/dashbls/binds/python/samples/creating_keys_and_signatures.py b/src/dashbls/binds/python/samples/creating_keys_and_signatures.py deleted file mode 100755 index 8fac6c0a2c4f..000000000000 --- a/src/dashbls/binds/python/samples/creating_keys_and_signatures.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env python3 -# coding: latin-1 - -# -# Copyright (c) 2020-present, Chia Network Inc. -# Copyright (c) 2026-present, The Dash Core developers -# SPDX-License-Identifier: Apache-2.0 -# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 -# - -"""Generate a keypair and produce/verify a signature.""" - -from dashbls import AugSchemeMPL, G1Element, G2Element, PrivateKey - -SEED: bytes = bytes.fromhex("003206f418c701193458c013120c5906dc12663ad1520c3e596eb6092c14fe16") - - -def creating_keys_and_signatures() -> None: - # Example seed. Always use a secure RNG with sufficient entropy to generate - # a seed (at least 32 bytes). - sk: PrivateKey = AugSchemeMPL.key_gen(SEED) - pk: G1Element = sk.get_g1() - - message: bytes = bytes([1, 2, 3, 4, 5]) - signature: G2Element = AugSchemeMPL.sign(sk, message) - - # Verify the signature - ok: bool = AugSchemeMPL.verify(pk, message, signature) - assert ok - - print(f"public key: {bytes(pk).hex()}") - print(f"signature: {bytes(signature).hex()}") - - -if __name__ == "__main__": - creating_keys_and_signatures() diff --git a/src/dashbls/binds/python/samples/hd_keys.py b/src/dashbls/binds/python/samples/hd_keys.py deleted file mode 100755 index 2e34c00da957..000000000000 --- a/src/dashbls/binds/python/samples/hd_keys.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python3 -# coding: latin-1 - -# -# Copyright (c) 2020-present, Chia Network Inc. -# Copyright (c) 2026-present, The Dash Core developers -# SPDX-License-Identifier: Apache-2.0 -# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 -# - -"""Derive hardened and unhardened HD keys, per EIP-2333.""" - -from dashbls import AugSchemeMPL, G1Element, PrivateKey - -SEED: bytes = bytes.fromhex("003206f418c701193458c013120c5906dc12663ad1520c3e596eb6092c14fe16") - - -def hd_keys() -> None: - master_sk: PrivateKey = AugSchemeMPL.key_gen(SEED) - master_pk: G1Element = master_sk.get_g1() - - # Hardened derivation needs the private key, and the resulting child cannot - # be derived from the public key alone - child: PrivateKey = AugSchemeMPL.derive_child_sk(master_sk, 152) - grandchild: PrivateKey = AugSchemeMPL.derive_child_sk(child, 952) - - # Unhardened derivation can be mirrored on the public side, so a watch-only - # holder of the master public key can compute the same child public keys - child_u: PrivateKey = AugSchemeMPL.derive_child_sk_unhardened(master_sk, 22) - grandchild_u: PrivateKey = AugSchemeMPL.derive_child_sk_unhardened(child_u, 0) - - child_u_pk: G1Element = AugSchemeMPL.derive_child_pk_unhardened(master_pk, 22) - grandchild_u_pk: G1Element = AugSchemeMPL.derive_child_pk_unhardened(child_u_pk, 0) - - assert grandchild_u_pk == grandchild_u.get_g1() - - print(f"hardened grandchild: {bytes(grandchild.get_g1()).hex()}") - print(f"unhardened grandchild: {bytes(grandchild_u_pk).hex()}") - - -if __name__ == "__main__": - hd_keys() diff --git a/src/dashbls/binds/python/samples/loading_from_bytes.py b/src/dashbls/binds/python/samples/loading_from_bytes.py deleted file mode 100755 index 401e1305e146..000000000000 --- a/src/dashbls/binds/python/samples/loading_from_bytes.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env python3 -# coding: latin-1 - -# -# Copyright (c) 2020-present, Chia Network Inc. -# Copyright (c) 2026-present, The Dash Core developers -# SPDX-License-Identifier: Apache-2.0 -# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 -# - -"""Deserialize keys and signatures from bytes.""" - -from dashbls import AugSchemeMPL, G1Element, G2Element, PrivateKey - -SEED: bytes = bytes.fromhex("003206f418c701193458c013120c5906dc12663ad1520c3e596eb6092c14fe16") - - -def loading_from_bytes() -> None: - # Stand in for bytes that arrived over the wire or came off disk - original_sk: PrivateKey = AugSchemeMPL.key_gen(SEED) - message: bytes = bytes([1, 2, 3, 4, 5]) - sk_bytes: bytes = bytes(original_sk) - pk_bytes: bytes = bytes(original_sk.get_g1()) - signature_bytes: bytes = bytes(AugSchemeMPL.sign(original_sk, message)) - - # from_bytes validates: it rejects points that are malformed or outside the - # correct subgroup, and raises ValueError rather than returning junk - sk: PrivateKey = PrivateKey.from_bytes(sk_bytes) - pk: G1Element = G1Element.from_bytes(pk_bytes) - signature: G2Element = G2Element.from_bytes(signature_bytes) - - assert sk == original_sk - assert pk == sk.get_g1() - assert AugSchemeMPL.verify(pk, message, signature) - - print(f"public key: {bytes(pk).hex()}") - print(f"signature: {bytes(signature).hex()}") - - -if __name__ == "__main__": - loading_from_bytes() diff --git a/src/dashbls/binds/python/samples/proof_of_possession.py b/src/dashbls/binds/python/samples/proof_of_possession.py deleted file mode 100755 index e327dcfc959f..000000000000 --- a/src/dashbls/binds/python/samples/proof_of_possession.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python3 -# coding: latin-1 - -# -# Copyright (c) 2020-present, Chia Network Inc. -# Copyright (c) 2026-present, The Dash Core developers -# SPDX-License-Identifier: Apache-2.0 -# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 -# - -"""Verify aggregated signatures quickly using the Proof of Possession scheme.""" - -from dashbls import G1Element, PopSchemeMPL, PrivateKey - -SEED: bytes = bytes.fromhex("003206f418c701193458c013120c5906dc12663ad1520c3e596eb6092c14fe16") - - -def proof_of_possession() -> None: - sk1: PrivateKey = PopSchemeMPL.key_gen(bytes([1]) + SEED[1:]) - sk2: PrivateKey = PopSchemeMPL.key_gen(bytes([2]) + SEED[1:]) - sk3: PrivateKey = PopSchemeMPL.key_gen(bytes([3]) + SEED[1:]) - - pk1: G1Element = sk1.get_g1() - pk2: G1Element = sk2.get_g1() - pk3: G1Element = sk3.get_g1() - - message: bytes = bytes([1, 2, 3, 4, 5]) - - # If the same message is signed, you can use Proof of Possession (PopScheme) for efficiency. - # A proof of possession MUST be passed around with the PK to ensure security. - pop_sig1 = PopSchemeMPL.sign(sk1, message) - pop_sig2 = PopSchemeMPL.sign(sk2, message) - pop_sig3 = PopSchemeMPL.sign(sk3, message) - pop1 = PopSchemeMPL.pop_prove(sk1) - pop2 = PopSchemeMPL.pop_prove(sk2) - pop3 = PopSchemeMPL.pop_prove(sk3) - - assert PopSchemeMPL.pop_verify(pk1, pop1) - assert PopSchemeMPL.pop_verify(pk2, pop2) - assert PopSchemeMPL.pop_verify(pk3, pop3) - - pop_sig_agg = PopSchemeMPL.aggregate([pop_sig1, pop_sig2, pop_sig3]) - - assert PopSchemeMPL.fast_aggregate_verify([pk1, pk2, pk3], message, pop_sig_agg) - - # Aggregate public key, indistinguishable from a single public key - pop_agg_pk: G1Element = pk1 + pk2 + pk3 - assert PopSchemeMPL.verify(pop_agg_pk, message, pop_sig_agg) - - # Aggregate private keys - pop_agg_sk: PrivateKey = PrivateKey.aggregate([sk1, sk2, sk3]) - assert PopSchemeMPL.sign(pop_agg_sk, message) == pop_sig_agg - - print(f"aggregate public key: {bytes(pop_agg_pk).hex()}") - - -if __name__ == "__main__": - proof_of_possession() diff --git a/src/dashbls/binds/python/samples/serializing_to_bytes.py b/src/dashbls/binds/python/samples/serializing_to_bytes.py deleted file mode 100755 index 5cb887d58ae1..000000000000 --- a/src/dashbls/binds/python/samples/serializing_to_bytes.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env python3 -# coding: latin-1 - -# -# Copyright (c) 2020-present, Chia Network Inc. -# Copyright (c) 2026-present, The Dash Core developers -# SPDX-License-Identifier: Apache-2.0 -# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 -# - -"""Serialize keys and signatures to bytes.""" - -from dashbls import AugSchemeMPL, G1Element, G2Element, PrivateKey - -SEED: bytes = bytes.fromhex("003206f418c701193458c013120c5906dc12663ad1520c3e596eb6092c14fe16") - - -def serializing_to_bytes() -> None: - sk: PrivateKey = AugSchemeMPL.key_gen(SEED) - pk: G1Element = sk.get_g1() - signature: G2Element = AugSchemeMPL.sign(sk, bytes([1, 2, 3, 4, 5])) - - sk_bytes: bytes = bytes(sk) # 32 bytes - pk_bytes: bytes = bytes(pk) # 48 bytes - signature_bytes: bytes = bytes(signature) # 96 bytes - - assert (len(sk_bytes), len(pk_bytes), len(signature_bytes)) == (32, 48, 96) - - # Serialized private keys are secret material; treat them the way you would - # treat the seed they came from, and never log them. - print(f"public key: {pk_bytes.hex()}") - print(f"signature: {signature_bytes.hex()}") - - -if __name__ == "__main__": - serializing_to_bytes() diff --git a/src/dashbls/binds/python/samples/tree_aggregates.py b/src/dashbls/binds/python/samples/tree_aggregates.py deleted file mode 100755 index 6260782d52e4..000000000000 --- a/src/dashbls/binds/python/samples/tree_aggregates.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python3 -# coding: latin-1 - -# -# Copyright (c) 2020-present, Chia Network Inc. -# Copyright (c) 2026-present, The Dash Core developers -# SPDX-License-Identifier: Apache-2.0 -# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 -# - -"""Build an aggregate signature out of an aggregate signature and another signature.""" - -from dashbls import AugSchemeMPL, G1Element, G2Element, PrivateKey - -SEED: bytes = bytes.fromhex("003206f418c701193458c013120c5906dc12663ad1520c3e596eb6092c14fe16") - - -def tree_aggregates() -> None: - sk1: PrivateKey = AugSchemeMPL.key_gen(bytes([1]) + SEED[1:]) - sk2: PrivateKey = AugSchemeMPL.key_gen(bytes([2]) + SEED[1:]) - sk3: PrivateKey = AugSchemeMPL.key_gen(bytes([3]) + SEED[1:]) - - message1: bytes = bytes([1, 2, 3, 4, 5]) - message2: bytes = bytes([1, 2, 3, 4, 5, 6, 7]) - message3: bytes = bytes([100, 2, 254, 88, 90, 45, 23]) - - pk1: G1Element = sk1.get_g1() - pk2: G1Element = sk2.get_g1() - pk3: G1Element = sk3.get_g1() - - # Aggregate the first two signatures on their own... - agg_sig: G2Element = AugSchemeMPL.aggregate( - [AugSchemeMPL.sign(sk1, message1), AugSchemeMPL.sign(sk2, message2)] - ) - - # ...then fold a third signature into that aggregate. Aggregation composes, - # so an aggregate is indistinguishable from a plain signature to the next - # round, and the tree can be built in any shape. - sig3: G2Element = AugSchemeMPL.sign(sk3, message3) - agg_sig_final: G2Element = AugSchemeMPL.aggregate([agg_sig, sig3]) - - ok = AugSchemeMPL.aggregate_verify( - [pk1, pk2, pk3], [message1, message2, message3], agg_sig_final - ) - assert ok - - print(f"tree aggregate: {bytes(agg_sig_final).hex()}") - - -if __name__ == "__main__": - tree_aggregates() diff --git a/src/dashbls/binds/python/test_bench.py b/src/dashbls/binds/python/test_bench.py deleted file mode 100755 index 689d33ab0699..000000000000 --- a/src/dashbls/binds/python/test_bench.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env python3 -# coding: latin-1 - -# -# Copyright (c) 2020-present, Chia Network Inc. -# Copyright (c) 2026-present, The Dash Core developers -# SPDX-License-Identifier: Apache-2.0 -# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 -# - -"""Benchmarks for the dashbls package.""" - -import secrets - -import pytest -from dashbls import ( - AugSchemeMPL, - G1Element, - G2Element, - PrivateKey, -) -from pytest_benchmark.fixture import BenchmarkFixture - -NUM_ITEMS = 1000 -SignedMessages = tuple[list[bytes], list[bytes], list[bytes]] - - -@pytest.fixture(scope="module") -def signed_messages() -> SignedMessages: - pk_bytes = [] - sig_bytes = [] - messages = [] - for i in range(NUM_ITEMS): - message = b"%d" % i - sk: PrivateKey = AugSchemeMPL.key_gen(secrets.token_bytes(32)) - pk: G1Element = sk.get_g1() - sig: G2Element = AugSchemeMPL.sign(sk, message) - - pk_bytes.append(bytes(pk)) - sig_bytes.append(bytes(sig)) - messages.append(message) - return pk_bytes, sig_bytes, messages - - -def test_public_key_validation( - benchmark: BenchmarkFixture, signed_messages: SignedMessages -) -> None: - pk_bytes, _, _ = signed_messages - pks = benchmark(lambda: [G1Element.from_bytes(pk) for pk in pk_bytes]) - assert len(pks) == NUM_ITEMS - - -def test_signature_validation(benchmark: BenchmarkFixture, signed_messages: SignedMessages) -> None: - _, sig_bytes, _ = signed_messages - sigs = benchmark(lambda: [G2Element.from_bytes(sig) for sig in sig_bytes]) - assert len(sigs) == NUM_ITEMS - - -def test_signature_aggregation( - benchmark: BenchmarkFixture, signed_messages: SignedMessages -) -> None: - _, sig_bytes, _ = signed_messages - sigs = [G2Element.from_bytes(sig) for sig in sig_bytes] - agg_sig = benchmark(lambda: AugSchemeMPL.aggregate(sigs)) - assert agg_sig is not None - - -def test_batch_verification(benchmark: BenchmarkFixture, signed_messages: SignedMessages) -> None: - pk_bytes, sig_bytes, messages = signed_messages - pks = [G1Element.from_bytes(pk) for pk in pk_bytes] - sigs = [G2Element.from_bytes(sig) for sig in sig_bytes] - agg_sig = AugSchemeMPL.aggregate(sigs) - - ok = benchmark(lambda: AugSchemeMPL.aggregate_verify(pks, messages, agg_sig)) - assert ok diff --git a/src/dashbls/binds/python/test_unit.py b/src/dashbls/binds/python/test_unit.py deleted file mode 100755 index 2a28c56b3225..000000000000 --- a/src/dashbls/binds/python/test_unit.py +++ /dev/null @@ -1,440 +0,0 @@ -#!/usr/bin/env python3 -# coding: latin-1 - -# -# Copyright (c) 2020-present, Chia Network Inc. -# Copyright (c) 2026-present, The Dash Core developers -# SPDX-License-Identifier: Apache-2.0 -# See the accompanying file LICENSE or https://opensource.org/licenses/Apache-2.0 -# - -"""Unit tests for the dashbls package.""" - -import binascii -import importlib - -import pytest -from dashbls import ( - AugSchemeMPL, - BasicSchemeMPL, - G1Element, - G2Element, - GTElement, - PopSchemeMPL, - PrivateKey, - Util, -) - -# fmt: off -SEED = bytes([ - 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 -]) -# fmt: on -MSG = bytes([100, 2, 254, 88, 90, 45, 23]) -MSG2 = bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) - -SCHEMES = (BasicSchemeMPL, AugSchemeMPL, PopSchemeMPL) -SCHEME_IDS = [scheme.__name__ for scheme in SCHEMES] - -G1_DST = b"BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_" -G2_DST = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_" - -# Keeps md_hmac's alloca of the seed off the stack, see CopySeed in the binds -SEED_LIMIT = 64 * 1024 - - -def _derive_two_keypairs() -> tuple[PrivateKey, G1Element, PrivateKey, G1Element]: - seed1 = bytes([1]) + SEED[1:] - sk1 = BasicSchemeMPL.key_gen(seed1) - seed2 = bytes([2]) + seed1[1:] - sk2 = BasicSchemeMPL.key_gen(seed2) - return sk1, sk1.get_g1(), sk2, sk2.get_g1() - - -@pytest.fixture -def keypairs() -> tuple[PrivateKey, G1Element, PrivateKey, G1Element]: - return _derive_two_keypairs() - - -def test_private_key_and_public_key_roundtrip() -> None: - sk = BasicSchemeMPL.key_gen(SEED) - pk = sk.get_g1() - assert sk == PrivateKey.from_bytes(bytes(sk)) - assert pk == G1Element.from_bytes(bytes(pk)) - - -def test_scalar_multiplication_by_private_key() -> None: - """The operators took `bn_t`, which pybind11 has no caster for, so every call - raised TypeError regardless of argument.""" - sk = BasicSchemeMPL.key_gen(SEED) - g1 = G1Element.generator() - assert g1 * sk == sk.get_g1() - assert sk * g1 == sk.get_g1() - - g2 = G2Element.generator() - assert g2 * sk == sk * g2 - assert g2 * sk != G2Element() - - -def test_scalar_multiplication_is_additive( - keypairs: tuple[PrivateKey, G1Element, PrivateKey, G1Element], -) -> None: - sk1, _pk1, sk2, _pk2 = keypairs - g1 = G1Element.generator() - assert (g1 * sk1) + (g1 * sk2) == g1 * PrivateKey.aggregate([sk1, sk2]) - - -@pytest.mark.parametrize("scheme", SCHEMES, ids=SCHEME_IDS) -def test_sign_and_verify_roundtrip(scheme: type) -> None: - sk = BasicSchemeMPL.key_gen(SEED) - pk = sk.get_g1() - sig = scheme.sign(sk, MSG) - assert sig == G2Element.from_bytes(bytes(sig)) - assert scheme.verify(pk, MSG, sig) - - -@pytest.mark.parametrize("scheme", SCHEMES, ids=SCHEME_IDS) -def test_aggregate_verify_same_message( - scheme: type, keypairs: tuple[PrivateKey, G1Element, PrivateKey, G1Element] -) -> None: - sk1, pk1, sk2, pk2 = keypairs - agg_pk = pk1 + pk2 - if scheme is AugSchemeMPL: - sig1 = scheme.sign(sk1, MSG, agg_pk) - sig2 = scheme.sign(sk2, MSG, agg_pk) - else: - sig1 = scheme.sign(sk1, MSG) - sig2 = scheme.sign(sk2, MSG) - agg_sig = scheme.aggregate([sig1, sig2]) - assert scheme.verify(agg_pk, MSG, agg_sig) - - -@pytest.mark.parametrize("scheme", SCHEMES, ids=SCHEME_IDS) -def test_aggregate_verify_different_messages( - scheme: type, keypairs: tuple[PrivateKey, G1Element, PrivateKey, G1Element] -) -> None: - sk1, pk1, sk2, pk2 = keypairs - sig1 = scheme.sign(sk1, MSG) - sig2 = scheme.sign(sk2, MSG2) - agg_sig = scheme.aggregate([sig1, sig2]) - assert scheme.aggregate_verify([pk1, pk2], [MSG, MSG2], agg_sig) - - -@pytest.mark.parametrize("scheme", SCHEMES, ids=SCHEME_IDS) -def test_manual_pairing_matches_aggregate_signature( - scheme: type, keypairs: tuple[PrivateKey, G1Element, PrivateKey, G1Element] -) -> None: - sk1, pk1, sk2, pk2 = keypairs - sig1 = scheme.sign(sk1, MSG) - sig2 = scheme.sign(sk2, MSG2) - agg_sig = scheme.aggregate([sig1, sig2]) - - if scheme is AugSchemeMPL: - # AugSchemeMPL requires prepending the public key to the message - aug_msg1 = bytes(pk1) + MSG - aug_msg2 = bytes(pk2) + MSG2 - else: - aug_msg1 = MSG - aug_msg2 = MSG2 - pair1 = pk1.pair(scheme.g2_from_message(aug_msg1)) - pair2 = pk2.pair(scheme.g2_from_message(aug_msg2)) - pair = pair1 * pair2 - agg_sig_pair = G1Element.generator().pair(agg_sig) - assert pair == agg_sig_pair - - -@pytest.mark.parametrize("scheme", SCHEMES, ids=SCHEME_IDS) -def test_hd_key_derivation_sign_and_verify( - scheme: type, keypairs: tuple[PrivateKey, G1Element, PrivateKey, G1Element] -) -> None: - sk1, pk1, _sk2, _pk2 = keypairs - child = scheme.derive_child_sk(sk1, 123) - child_u = scheme.derive_child_sk_unhardened(sk1, 123) - child_u_pk = scheme.derive_child_pk_unhardened(pk1, 123) - - sig_child = scheme.sign(child, MSG) - assert scheme.verify(child.get_g1(), MSG, sig_child) - - sig_u_child = scheme.sign(child_u, MSG) - assert scheme.verify(child_u_pk, MSG, sig_u_child) - - -# Invalid inputs from https://github.com/algorand/bls_sigs_ref/blob/master/python-impl/serdesZ.py -INVALID_G1_VECTORS = [ - # infinity points: too short - "c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - # infinity points: not all zeros - "c00000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000", - # bad tags - "3a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa", - "7a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa", - "fa0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa", - # wrong length for compresed point - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa", - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaaaa", - # invalid x-coord - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa", - # invalid elm of Fp --- equal to p (must be strictly less) - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab", -] -INVALID_G2_VECTORS = [ - # infinity points: too short - "c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - # infinity points: not all zeros - "c00000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000", - # bad tags - "3a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "7a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "fa0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - # wrong length for compressed point - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - # invalid x-coord - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaa7", - # invalid elm of Fp --- equal to p (must be strictly less) - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab", -] - - -@pytest.mark.parametrize("hex_str", INVALID_G1_VECTORS) -def test_invalid_g1_vector_rejected(hex_str: str) -> None: - with pytest.raises(ValueError): - G1Element(binascii.unhexlify(hex_str)) - - -@pytest.mark.parametrize("hex_str", INVALID_G2_VECTORS) -def test_invalid_g2_vector_rejected(hex_str: str) -> None: - with pytest.raises(ValueError): - G2Element(binascii.unhexlify(hex_str)) - - -# The following code was used to generate the reference vectors below -""" -from py_ecc.bls import ( - G2Basic, - G2MessageAugmentation as G2MA, - G2ProofOfPossession as G2Pop, -) - -secret1 = bytes([1] * 32) -secret2 = bytes([x * 314159 % 256 for x in range(32)]) -sk1 = int.from_bytes(secret1, 'big') -sk2 = int.from_bytes(secret2, 'big') -msg = bytes([3, 1, 4, 1, 5, 9]) -pk1 = G2Basic.SkToPk(sk1) -pk2 = G2Basic.SkToPk(sk2) - -for Scheme in (G2Basic, G2MA, G2Pop): - sig1 = Scheme.Sign(sk1, msg) - sig2 = Scheme.Sign(sk2, msg) - sig_agg = Scheme.Aggregate([sig1, sig2]) - print(sig1) - print(sig2) - print(sig_agg) -""" - -REFERENCE_VECTORS = { - BasicSchemeMPL: ( - b"\x96\xba4\xfa\xc3<\x7f\x12\x9d`*\x0b\xc8\xa3\xd4?\x9a\xbc\x01N\xce\xaa\xb75\x91F\xb4\xb1P\xe5{\x80\x86Es\x8f5g\x1e\x9e\x10\xe0\xd8b\xa3\x0c\xabp\x07N\xb5\x83\x1d\x13\xe6\xa5\xb1b\xd0\x1e\xeb\xe6\x87\xd0\x16J\xdb\xd0\xa8d7\n|\"*'h\xd7pM\xa2T\xf1\xbf\x18#f[\xc26\x1f\x9d\xd8\xc0\x0e\x99", - b'\xa4\x02y\t2\x13\x0fvj\xf1\x1b\xa7\x16Sf\x83\xd8\xc4\xcf\xa5\x19G\xe4\xf9\x08\x1f\xed\xd6\x92\xd6\xdc\x0c\xac[\x90K\xee^\xa6\xe2Ui\xe3m{\xe4\xcaY\x06\x9a\x96\xe3K\x7fp\x07X\xb7\x16\xf9IJ\xaaY\xa9nt\xd1J;U*\x9ak\xc1)\xe7\x17\x19[\x9d`\x06\xfdm\\\xefGh\xc0"\xe0\xf71j\xbf', - b"\x98|\xfd;\xcdb(\x02\x87\x02t\x83\xf2\x9cU$^\xd81\xf5\x1d\xd6\xbd\x99\x9ao\xf1\xa1\xf1\xf1\xf0\xb6Gw\x8b\x01g5\x9cqPUX\xa7n\x15\x8ef\x18\x1e\xe5\x12Y\x05\xa6B$k\x01\xe7\xfa^\xe5=h\xa4\xfe\x9b\xfb)\xa8\xe2f\x01\xf0\xb9\xadW}\xdd\x18\x87js1|!n\xa6\x1fC\x04\x14\xecQ\xc5", - ), - AugSchemeMPL: ( - b'\x81\x80\xf0,\xcbr\xe9"\xb1R\xfc\xed\xbe\x0e\x1d\x19R\x105Opp6X\xe8\xe0\x8c\xbe\xbf\x11\xd4\x97\x0e\xabj\xc3\xcc\xf7\x15\xf3\xfb\x87m\xf9\xa9yz\xbd\x0c\x1a\xf6\x1a\xae\xad\xc9,,\xfe\\\nV\xc1F\xcc\x8c?qQ\xa0s\xcf_\x16\xdf8$g$\xc4\xae\xd7?\xf3\x0e\xf5\xda\xa6\xaa\xca\xed\x1a&\xec\xaa3k', - b'\x99\x11\x1e\xea\xfbA-\xa6\x1eL7\xd3\xe8\x06\xc6\xfdj\xc9\xf3\x87\x0eT\xda\x92"\xbaNIH"\xc5\xb7eg1\xfazdY4\xd0KU\x9e\x92a\xb8b\x01\xbb\xeeW\x05RP\xa4Y\xa2\xda\x10\xe5\x1f\x9c\x1aiA)\x7f\xfc]\x97\nUr6\xd0\xbd\xeb|\xf8\xff\x18\x80\x0b\x08c8q\xa0\xf0\xa7\xeaB\xf4t\x80', - b"\x8c]\x03\xf9\xda\xe7~\x19\xa5\x94Z\x06\xa2\x14\x83n\xdb\x8e\x03\xb8QR]\x84\xb9\xded@\xe6\x8f\xc0\xcas\x03\xee\xed9\r\x86<\x9bU\xa8\xcfmY\x14\n\x01\xb5\x88G\x88\x1e\xb5\xafgsMD\xb2UVF\xc6al9\xab\x88\xd2S)\x9a\xcc\x1e\xb1\xb1\x9d\xdb\x9b\xfc\xbev\xe2\x8a\xdd\xf6q\xd1\x16\xc0R\xbb\x18G", - ), - PopSchemeMPL: ( - b"\x95P\xfbN\x7f~\x8c\xc4\xa9\x0b\xe8V\n\xb5\xa7\x98\xb0\xb20\x00\xb6\xa5J!\x17R\x02\x10\xf9\x86\xf3\xf2\x81\xb3v\xf2Y\xc0\xb7\x80b\xd1\xeb1\x92\xb3\xd9\xbb\x04\x9fY\xec\xc1\xb0:pI\xebf^\r\xf3d\x94\xaeL\xb5\xf1\x13l\xca\xee\xfc\x99X\xcb0\xc33==C\xf0qH\xc3\x86)\x9a{\x1b\xfc\r\xc5\xcf|", - b"\xa6\x906\xbc\x11\xae^\xfc\xbfa\x80\xaf\xe3\x9a\xdd\xde~'s\x1e\xc4\x02W\xbf\xdc<7\xf1{\x8d\xf6\x83\x06\xa3N\xbd\x10\xe9\xe3*5%7P\xdf\\\x87\xc2\x14/\x82\x07\xe8\xd5eG\x12\xb4\xe5T\xf5\x85\xfbhF\xff8\x04\xe4)\xa9\xf8\xa1\xb4\xc5ku\xd0\x86\x9e\xd6u\x80\xd7\x89\x87\x0b\xab\xe2\xc7\xc8\xa9\xd5\x1e{*", - b"\xa4\xeat+\xcd\xc1U>\x9c\xa4\xe5`\xbe~^ln\xfajd\xdd\xdf\x9c\xa3\xbb(T#=\x85\xa6\xaa\xc1\xb7n\xc7\xd1\x03\xdbN3\x14\x8b\x82\xaf\x99#\xdb\x05\x93Jn\xce\x9aq\x01\xcd\x8a\x9dG\xce'\x97\x80V\xb0\xf5\x90\x00!\x81\x8cEi\x8a\xfd\xd6\xcf\x8ako\x7f\xee\x1f\x0bCqoU\xe4\x13\xd4\xb8z`9", - ), -} - - -@pytest.mark.parametrize("scheme", SCHEMES, ids=SCHEME_IDS) -def test_sign_matches_reference_vectors(scheme: type) -> None: - secret1 = bytes([1] * 32) - secret2 = bytes([x * 314159 % 256 for x in range(32)]) - sk1 = PrivateKey.from_bytes(secret1) - sk2 = PrivateKey.from_bytes(secret2) - msg = bytes([3, 1, 4, 1, 5, 9]) - - sig1 = scheme.sign(sk1, msg) - sig2 = scheme.sign(sk2, msg) - sig_agg = scheme.aggregate([sig1, sig2]) - - ref_sig1, ref_sig2, ref_sig_agg = REFERENCE_VECTORS[scheme] - assert bytes(sig1) == ref_sig1 - assert bytes(sig2) == ref_sig2 - assert bytes(sig_agg) == ref_sig_agg - - -SAMPLES = [ - "aggregate_signatures", - "creating_keys_and_signatures", - "hd_keys", - "loading_from_bytes", - "proof_of_possession", - "serializing_to_bytes", - "tree_aggregates", -] - - -@pytest.mark.parametrize("sample", SAMPLES) -def test_samples(sample: str) -> None: - module = importlib.import_module(sample) - getattr(module, sample)() - - -def test_aggregate_verify_zero_items() -> None: - assert AugSchemeMPL.aggregate_verify([], [], G2Element()) - - -def test_from_message() -> None: - msg = bytes([10]) * 32 - assert G2Element.from_message(msg, G2_DST) == BasicSchemeMPL.g2_from_message(msg) - assert G1Element.from_message(msg, G1_DST) != G1Element() - - -def test_from_message_is_domain_separated() -> None: - """The tag keeps one scheme's hashes off another's, so a different tag over - the same message must land elsewhere.""" - msg = bytes([10]) * 32 - assert G2Element.from_message(msg, G2_DST) != G2Element.from_message(msg, G1_DST) - assert G1Element.from_message(msg, G1_DST) != G1Element.from_message(msg, G2_DST) - - -@pytest.mark.parametrize("element", [G1Element, G2Element]) -@pytest.mark.parametrize("size", [256, 1000]) -def test_from_message_rejects_oversized_dst(element: type, size: int) -> None: - """md_xmd caps the tag at 255 bytes but compares signed, so the length is - checked here rather than reaching relic.""" - with pytest.raises(ValueError): - element.from_message(bytes([10]) * 32, b"x" * size) - - -def test_from_message_accepts_maximum_dst() -> None: - assert G2Element.from_message(bytes([10]) * 32, b"x" * 255) != G2Element() - - -class _LyingBytes(bytes): - """A bytes subclass whose __len__ disagrees with its payload.""" - - def __init__(self, payload: bytes, claimed_len: int) -> None: - del payload - self._claimed_len = claimed_len - - def __new__(cls, payload: bytes, claimed_len: int) -> "_LyingBytes": - del claimed_len - return super().__new__(cls, payload) - - def __len__(self) -> int: - return self._claimed_len - - -@pytest.mark.parametrize("element", [G1Element, G2Element], ids=["G1Element", "G2Element"]) -def test_from_message_measures_the_dst_payload_not_its_len(element: type) -> None: - """The length check has to read the same bytes the copy takes, or a subclass - that understates __len__ walks an oversized tag straight into relic.""" - dst = _LyingBytes(b"x" * 256, 1) - assert len(dst) == 1 - with pytest.raises(ValueError): - element.from_message(bytes([10]) * 32, dst) - - # and the mirror case: a small tag must not be rejected for lying upwards - honest = G1_DST if element is G1Element else G2_DST - assert element.from_message(bytes([10]) * 32, _LyingBytes(honest, 300)) == element.from_message( - bytes([10]) * 32, honest - ) - - -def test_length_checked_paths_use_the_payload_of_a_bytes_subclass() -> None: - """Every entry point that measures a length before copying must agree with - the payload it ends up hashing, whatever __len__ claims.""" - assert Util.hash256(_LyingBytes(b"abc", 1 << 40)) == Util.hash256(b"abc") - - seed = bytes([9]) * 32 - for scheme in (BasicSchemeMPL, AugSchemeMPL, PopSchemeMPL): - sk = scheme.key_gen(_LyingBytes(seed, 1)) - assert sk == scheme.key_gen(seed) - msg = bytes([1, 2, 3]) - assert scheme.sign(sk, _LyingBytes(msg, 1 << 40)) == scheme.sign(sk, msg) - assert scheme.verify(sk.get_g1(), _LyingBytes(msg, 1), scheme.sign(sk, msg)) - - -@pytest.mark.parametrize("scheme", SCHEMES, ids=SCHEME_IDS) -def test_key_gen_rejects_oversized_seeds(scheme: type) -> None: - """relic is built ALLOC=AUTO, so md_hmac stages the seed with alloca and a - seed of a few MiB would take the process down instead of raising.""" - with pytest.raises(ValueError): - scheme.key_gen(b"x" * (SEED_LIMIT + 1)) - # the cap itself has to keep working - assert scheme.key_gen(b"x" * SEED_LIMIT) == scheme.key_gen(b"x" * SEED_LIMIT) - - -def test_from_bytes_and_from_bytes_unchecked_agree_on_valid_point() -> None: - sk1 = BasicSchemeMPL.key_gen(b"1" * 32) - good_point_bytes = bytes(sk1.get_g1()) - assert G1Element.from_bytes(good_point_bytes) == G1Element.from_bytes_unchecked( - good_point_bytes - ) - - -def test_from_bytes_rejects_invalid_g1_point() -> None: - bad_point_hex = "8d5d0fb73b9c92df4eab4216e48c3e358578b4cc30f82c268bd6fef3bd34b558628daf1afef798d4c3b0fcd8b28c8973" # noqa: E501 - with pytest.raises(ValueError): - G1Element.from_bytes(bytes.fromhex(bad_point_hex)) - # from_bytes_unchecked skips subgroup validation and must not raise - G1Element.from_bytes_unchecked(bytes.fromhex(bad_point_hex)) - - -def test_from_bytes_rejects_invalid_g2_point() -> None: - bad_g2_point_hex = "8f2886c94eaeac335c8414cbf14c16681b225380cfee3293becc4531d5b415984b4ea4050d9ecda11fbc21c60627e9d212dfcb17d2b5ae399aa3fbcb099e05baa496b852ad976fb633cc6766b02fca4da549dc063908463b2906ad64e8b310ad" # noqa: E501 - with pytest.raises(ValueError): - G2Element.from_bytes(bytes.fromhex(bad_g2_point_hex)) - - -@pytest.mark.parametrize( - ("cls", "size"), - [ - (PrivateKey, PrivateKey.PRIVATE_KEY_SIZE), - (G1Element, G1Element.SIZE), - (G2Element, G2Element.SIZE), - (GTElement, GTElement.SIZE), - ], - ids=["PrivateKey", "G1Element", "G2Element", "GTElement"], -) -def test_from_bytes_rejects_non_contiguous_buffers(cls: type, size: int) -> None: - # A reversed view points at the last backing byte with a stride of -1, so - # reading it as if it were contiguous runs off the end of the allocation - with pytest.raises(BufferError): - cls.from_bytes(memoryview(bytearray(size))[::-1]) - # A strided view stays in bounds but is not the bytes the caller passed - with pytest.raises(BufferError): - cls.from_bytes(memoryview(bytearray(size * 2))[::2]) - - -@pytest.mark.parametrize( - ("cls", "size"), - [ - (G1Element, G1Element.SIZE), - (G2Element, G2Element.SIZE), - (GTElement, GTElement.SIZE), - ], - ids=["G1Element", "G2Element", "GTElement"], -) -def test_from_bytes_unchecked_rejects_non_contiguous_buffers(cls: type, size: int) -> None: - with pytest.raises(BufferError): - cls.from_bytes_unchecked(memoryview(bytearray(size))[::-1]) - - -@pytest.mark.parametrize("element", [G1Element, G2Element], ids=["G1Element", "G2Element"]) -def test_from_message_accepts_a_large_message(element: type) -> None: - # ep_map_dst takes the message length as an int and relic checks nothing on - # its side, so the binds guard it. Anything under the limit has to keep - # working; the limit itself is not testable without ~2 GiB of memory. - assert element.from_message(b"x" * (1 << 20), G1_DST) != element() diff --git a/src/dashbls/build-aux/m4/ax_check_compile_flag.m4 b/src/dashbls/build-aux/m4/ax_check_compile_flag.m4 deleted file mode 100644 index bd753b34d7dc..000000000000 --- a/src/dashbls/build-aux/m4/ax_check_compile_flag.m4 +++ /dev/null @@ -1,53 +0,0 @@ -# =========================================================================== -# https://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 -# -# 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 6 - -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/dashbls/build-aux/m4/ax_check_link_flag.m4 b/src/dashbls/build-aux/m4/ax_check_link_flag.m4 deleted file mode 100644 index 03a30ce4c739..000000000000 --- a/src/dashbls/build-aux/m4/ax_check_link_flag.m4 +++ /dev/null @@ -1,53 +0,0 @@ -# =========================================================================== -# https://www.gnu.org/software/autoconf-archive/ax_check_link_flag.html -# =========================================================================== -# -# SYNOPSIS -# -# AX_CHECK_LINK_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) -# -# DESCRIPTION -# -# Check whether the given FLAG works with the linker 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 linker's default flags -# when the check is done. The check is thus made with the flags: "LDFLAGS -# EXTRA-FLAGS FLAG". This can for example be used to force the linker to -# issue an error when a bad flag is given. -# -# INPUT gives an alternative input source to AC_LINK_IFELSE. -# -# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this -# macro in sync with AX_CHECK_{PREPROC,COMPILE}_FLAG. -# -# LICENSE -# -# Copyright (c) 2008 Guido U. Draheim -# Copyright (c) 2011 Maarten Bosmans -# -# 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 6 - -AC_DEFUN([AX_CHECK_LINK_FLAG], -[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF -AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_ldflags_$4_$1])dnl -AC_CACHE_CHECK([whether the linker accepts $1], CACHEVAR, [ - ax_check_save_flags=$LDFLAGS - LDFLAGS="$LDFLAGS $4 $1" - AC_LINK_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], - [AS_VAR_SET(CACHEVAR,[yes])], - [AS_VAR_SET(CACHEVAR,[no])]) - LDFLAGS=$ax_check_save_flags]) -AS_VAR_IF(CACHEVAR,yes, - [m4_default([$2], :)], - [m4_default([$3], :)]) -AS_VAR_POPDEF([CACHEVAR])dnl -])dnl AX_CHECK_LINK_FLAGS diff --git a/src/dashbls/build-aux/m4/ax_cxx_compile_stdcxx.m4 b/src/dashbls/build-aux/m4/ax_cxx_compile_stdcxx.m4 deleted file mode 100644 index 51a35054d08c..000000000000 --- a/src/dashbls/build-aux/m4/ax_cxx_compile_stdcxx.m4 +++ /dev/null @@ -1,1005 +0,0 @@ -# =========================================================================== -# https://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', '14', '17', or '20' for -# the respective C++ standard version. -# -# 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 no added switch, and then 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 -# Copyright (c) 2016, 2018 Krzesimir Nowak -# Copyright (c) 2019 Enji Cooper -# Copyright (c) 2020 Jason Merrill -# Copyright (c) 2021 Jörn Heusipp -# -# 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 14 - -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], [ax_cxx_compile_alternatives="11 0x"], - [$1], [14], [ax_cxx_compile_alternatives="14 1y"], - [$1], [17], [ax_cxx_compile_alternatives="17 1z"], - [$1], [20], [ax_cxx_compile_alternatives="20"], - [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])]) - AC_LANG_PUSH([C++])dnl - ac_success=no - - m4_if([$2], [], [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 alternative in ${ax_cxx_compile_alternatives}; do - switch="-std=gnu++${alternative}" - 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 alternative in ${ax_cxx_compile_alternatives}; do - for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; 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 - if test x$ac_success = xyes; then - 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 Test body for checking C++17 support - -m4_define([_AX_CXX_COMPILE_STDCXX_testbody_17], - _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 - _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 - _AX_CXX_COMPILE_STDCXX_testbody_new_in_17 -) - -dnl Test body for checking C++20 support - -m4_define([_AX_CXX_COMPILE_STDCXX_testbody_20], - _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 - _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 - _AX_CXX_COMPILE_STDCXX_testbody_new_in_17 - _AX_CXX_COMPILE_STDCXX_testbody_new_in_20 -) - - -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 ~Base() {} - virtual void f() {} - }; - - struct Derived : public Base - { - virtual ~Derived() override {} - 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_separators - { - - 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 - -]]) - - -dnl Tests for new features in C++17 - -m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[ - -// If the compiler admits that it is not ready for C++17, why torture it? -// Hopefully, this will speed up the test. - -#ifndef __cplusplus - -#error "This is not a C++ compiler" - -#elif __cplusplus < 201703L - -#error "This is not a C++17 compiler" - -#else - -#include -#include -#include - -namespace cxx17 -{ - - namespace test_constexpr_lambdas - { - - constexpr int foo = [](){return 42;}(); - - } - - namespace test::nested_namespace::definitions - { - - } - - namespace test_fold_expression - { - - template - int multiply(Args... args) - { - return (args * ... * 1); - } - - template - bool all(Args... args) - { - return (args && ...); - } - - } - - namespace test_extended_static_assert - { - - static_assert (true); - - } - - namespace test_auto_brace_init_list - { - - auto foo = {5}; - auto bar {5}; - - static_assert(std::is_same, decltype(foo)>::value); - static_assert(std::is_same::value); - } - - namespace test_typename_in_template_template_parameter - { - - template typename X> struct D; - - } - - namespace test_fallthrough_nodiscard_maybe_unused_attributes - { - - int f1() - { - return 42; - } - - [[nodiscard]] int f2() - { - [[maybe_unused]] auto unused = f1(); - - switch (f1()) - { - case 17: - f1(); - [[fallthrough]]; - case 42: - f1(); - } - return f1(); - } - - } - - namespace test_extended_aggregate_initialization - { - - struct base1 - { - int b1, b2 = 42; - }; - - struct base2 - { - base2() { - b3 = 42; - } - int b3; - }; - - struct derived : base1, base2 - { - int d; - }; - - derived d1 {{1, 2}, {}, 4}; // full initialization - derived d2 {{}, {}, 4}; // value-initialized bases - - } - - namespace test_general_range_based_for_loop - { - - struct iter - { - int i; - - int& operator* () - { - return i; - } - - const int& operator* () const - { - return i; - } - - iter& operator++() - { - ++i; - return *this; - } - }; - - struct sentinel - { - int i; - }; - - bool operator== (const iter& i, const sentinel& s) - { - return i.i == s.i; - } - - bool operator!= (const iter& i, const sentinel& s) - { - return !(i == s); - } - - struct range - { - iter begin() const - { - return {0}; - } - - sentinel end() const - { - return {5}; - } - }; - - void f() - { - range r {}; - - for (auto i : r) - { - [[maybe_unused]] auto v = i; - } - } - - } - - namespace test_lambda_capture_asterisk_this_by_value - { - - struct t - { - int i; - int foo() - { - return [*this]() - { - return i; - }(); - } - }; - - } - - namespace test_enum_class_construction - { - - enum class byte : unsigned char - {}; - - byte foo {42}; - - } - - namespace test_constexpr_if - { - - template - int f () - { - if constexpr(cond) - { - return 13; - } - else - { - return 42; - } - } - - } - - namespace test_selection_statement_with_initializer - { - - int f() - { - return 13; - } - - int f2() - { - if (auto i = f(); i > 0) - { - return 3; - } - - switch (auto i = f(); i + 4) - { - case 17: - return 2; - - default: - return 1; - } - } - - } - - namespace test_template_argument_deduction_for_class_templates - { - - template - struct pair - { - pair (T1 p1, T2 p2) - : m1 {p1}, - m2 {p2} - {} - - T1 m1; - T2 m2; - }; - - void f() - { - [[maybe_unused]] auto p = pair{13, 42u}; - } - - } - - namespace test_non_type_auto_template_parameters - { - - template - struct B - {}; - - B<5> b1; - B<'a'> b2; - - } - - namespace test_structured_bindings - { - - int arr[2] = { 1, 2 }; - std::pair pr = { 1, 2 }; - - auto f1() -> int(&)[2] - { - return arr; - } - - auto f2() -> std::pair& - { - return pr; - } - - struct S - { - int x1 : 2; - volatile double y1; - }; - - S f3() - { - return {}; - } - - auto [ x1, y1 ] = f1(); - auto& [ xr1, yr1 ] = f1(); - auto [ x2, y2 ] = f2(); - auto& [ xr2, yr2 ] = f2(); - const auto [ x3, y3 ] = f3(); - - } - - namespace test_exception_spec_type_system - { - - struct Good {}; - struct Bad {}; - - void g1() noexcept; - void g2(); - - template - Bad - f(T*, T*); - - template - Good - f(T1*, T2*); - - static_assert (std::is_same_v); - - } - - namespace test_inline_variables - { - - template void f(T) - {} - - template inline T g(T) - { - return T{}; - } - - template<> inline void f<>(int) - {} - - template<> int g<>(int) - { - return 5; - } - - } - -} // namespace cxx17 - -#endif // __cplusplus < 201703L - -]]) - - -dnl Tests for new features in C++20 - -m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_20], [[ - -#ifndef __cplusplus - -#error "This is not a C++ compiler" - -#elif __cplusplus < 202002L - -#error "This is not a C++20 compiler" - -#else - -#include - -namespace cxx20 -{ - -// As C++20 supports feature test macros in the standard, there is no -// immediate need to actually test for feature availability on the -// Autoconf side. - -} // namespace cxx20 - -#endif // __cplusplus < 202002L - -]]) diff --git a/src/dashbls/build-aux/m4/ax_pthread.m4 b/src/dashbls/build-aux/m4/ax_pthread.m4 deleted file mode 100644 index 9f35d139149f..000000000000 --- a/src/dashbls/build-aux/m4/ax_pthread.m4 +++ /dev/null @@ -1,522 +0,0 @@ -# =========================================================================== -# https://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 and PTHREAD_CXX to any special C compiler that is -# needed for multi-threaded programs (defaults to the value of CC -# respectively CXX otherwise). (This is necessary on e.g. AIX to use the -# special cc_r/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 -# $PTHREAD_CXX $CXXFLAGS $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" -# CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS" -# CC="$PTHREAD_CC" -# CXX="$PTHREAD_CXX" -# -# 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. -# Copyright (c) 2019 Marc Stevens -# -# 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 31 - -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"]) - AS_IF([test "x$PTHREAD_CXX" != "x"], [CXX="$PTHREAD_CXX"]) - 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 with a "," contain both -# C compiler flags (before ",") and linker flags (after ","). Other items -# starting with a "-" are C compiler flags, and remaining 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,-lpthread pthread $ax_pthread_flags" - ;; -esac - -# 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" - - -# GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC) - -# Note that for GCC and Clang -pthread generally implies -lpthread, -# except when -nostdlib is passed. -# This is problematic using libtool to build C++ shared libraries with pthread: -# [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25460 -# [2] https://bugzilla.redhat.com/show_bug.cgi?id=661333 -# [3] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=468555 -# To solve this, first try -pthread together with -lpthread for GCC - -AS_IF([test "x$GCC" = "xyes"], - [ax_pthread_flags="-pthread,-lpthread -pthread -pthreads $ax_pthread_flags"]) - -# Clang takes -pthread (never supported any other flag), but we'll try with -lpthread first - -AS_IF([test "x$ax_pthread_clang" = "xyes"], - [ax_pthread_flags="-pthread,-lpthread -pthread"]) - - -# 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)"]) - - -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]) - ;; - - *,*) - PTHREAD_CFLAGS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\1/"` - PTHREAD_LIBS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\2/"` - AC_MSG_CHECKING([whether pthreads work with "$PTHREAD_CFLAGS" and "$PTHREAD_LIBS"]) - ;; - - -*) - 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 *some_global = NULL; - static void routine(void *a) - { - /* To avoid any unused-parameter or - unused-but-set-parameter warning. */ - some_global = a; - } - 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 - - -# 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.) - - # 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 - - - -# 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; - return i;]])], - [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"]) - AS_IF([test "x${CXX}" != "x"], [AS_IF([AS_EXECUTABLE_P([${CXX}_r])],[PTHREAD_CXX="${CXX}_r"])]) - ], - [ - AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC]) - AS_IF([test "x${CXX}" != "x"], [AC_CHECK_PROGS([PTHREAD_CXX],[${CXX}_r],[$CXX])]) - ] - ) - ]) - ;; - esac - fi -fi - -test -n "$PTHREAD_CC" || PTHREAD_CC="$CC" -test -n "$PTHREAD_CXX" || PTHREAD_CXX="$CXX" - -AC_SUBST([PTHREAD_LIBS]) -AC_SUBST([PTHREAD_CFLAGS]) -AC_SUBST([PTHREAD_CC]) -AC_SUBST([PTHREAD_CXX]) - -# 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/dashbls/cmake_modules/BrewHelper.cmake b/src/dashbls/cmake_modules/BrewHelper.cmake deleted file mode 100644 index 6a1738fa1c17..000000000000 --- a/src/dashbls/cmake_modules/BrewHelper.cmake +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright (c) 2018 The Bitcoin developers - -find_program(BREW brew) - -function(find_brew_prefix VAR NAME) - if(NOT BREW) - return() - endif() - - if(DEFINED ${VAR}) - return() - endif() - - execute_process( - COMMAND ${BREW} --prefix ${NAME} - OUTPUT_VARIABLE PREFIX - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - set(${VAR} ${PREFIX} PARENT_SCOPE) -endfunction() diff --git a/src/dashbls/cmake_modules/Findsodium.cmake b/src/dashbls/cmake_modules/Findsodium.cmake deleted file mode 100644 index 0350b67fce9b..000000000000 --- a/src/dashbls/cmake_modules/Findsodium.cmake +++ /dev/null @@ -1,294 +0,0 @@ -# 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() -add_library(sodium ${_LIB_TYPE} IMPORTED) - -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/dashbls/configure.ac b/src/dashbls/configure.ac deleted file mode 100644 index 56b8a78339e0..000000000000 --- a/src/dashbls/configure.ac +++ /dev/null @@ -1,913 +0,0 @@ -AC_PREREQ([2.60]) -AC_INIT([libdashbls],[2.0]) -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 no-define 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${CFLAGS+set}" = "xset"; then - CFLAGS_overridden=yes -else - CFLAGS_overridden=no -fi -if test "x${CXXFLAGS+set}" = "xset"; then - CXXFLAGS_overridden=yes -else - CXXFLAGS_overridden=no -fi - -AC_PROG_CC - -AC_PROG_CXX - -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([--enable-tests], - [Compile with tests [default=yes]])], - [use_tests=$enableval], - [use_tests=yes]) - -AC_ARG_ENABLE([bench], - [AS_HELP_STRING([--enable-bench], - [Compile with benchmarks [default=yes]])], - [use_bench=$enableval], - [use_bench=yes]) - -AC_ARG_ENABLE([hardening], - [AS_HELP_STRING([--enable-hardening], - [Enable hardening flags and arguments [default=auto]])], - [use_hardening=$enableval], - [use_hardening=auto]) - -AC_ARG_ENABLE([optimizations], - [AS_HELP_STRING([--enable-optimizations], - [Enable compiler and library optimizations [default=yes]])], - [use_optimizations=$enableval], - [use_optimizations=yes]) - -AC_ARG_ENABLE([debug], - [AS_HELP_STRING([--enable-debug], - [Build with debugging support [default=no]])], - [use_debug=$enableval], - [use_debug=no]) - -AC_LANG_PUSH([C]) - -dnl Check for a flag to turn compiler warnings into errors. This is helpful for checks which may -dnl appear to succeed because by default they merely emit warnings when they fail. -dnl -dnl Note that this is not necessarily a check to see if -Werror is supported, but rather to see if -dnl a compile with -Werror can succeed. This is important because the compiler may already be -dnl warning about something unrelated, for example about some path issue. If that is the case, -dnl -Werror cannot be used because all of those warnings would be turned into errors. -AX_CHECK_COMPILE_FLAG([-Werror], [FLAG_WERROR="-Werror"], [FLAG_WERROR=""]) - -if test x"$use_debug" = x"yes" -o x"$use_optimizations" = x"no"; then - dnl Clear default -g -O2 flags - if test x"$CFLAGS_overridden" = x"no"; then - CFLAGS="" - fi - if test x"$CXXFLAGS_overridden" = x"no"; then - CXXFLAGS="" - fi - - dnl Disable optimizations - AX_CHECK_COMPILE_FLAG([-O0], [[DEBUG_FLAGS="$DEBUG_FLAGS -O0"]], [], [[$FLAG_WERROR]]) - - if test x"$use_debug" = x"yes"; then - dnl Prefer -g3, fall back to -g if that is unavailable. - AX_CHECK_COMPILE_FLAG( - [-g3], - [[DEBUG_FLAGS="$DEBUG_FLAGS -g3"]], - [AX_CHECK_COMPILE_FLAG([-g],[[DEBUG_FLAGS="$DEBUG_FLAGS -g"]])], [[$FLAG_WERROR]]) - - AX_CHECK_COMPILE_FLAG([-ftrapv],[DEBUG_FLAGS="$DEBUG_FLAGS -ftrapv"], [], [[$FLAG_WERROR]]) - else - dnl Reintroduce -g flag deleted during C(XX)FLAGS reset - AX_CHECK_COMPILE_FLAG([-g],[[DEBUG_FLAGS="$DEBUG_FLAGS -g"]], [], [[$FLAG_WERROR]]) - - dnl -ftrapv and -fwrapv conflict, so we only set this if use_debug=no - AX_CHECK_COMPILE_FLAG([-fwrapv],[DEBUG_FLAGS="$DEBUG_FLAGS -fwrapv"], [], [[$FLAG_WERROR]]) - fi -fi - -dnl Define enum mappings for relic config -AC_DEFINE([RLC_VERSION], ["0.5.0"], [Relic Version]) - -dnl dashbls: Library processor architecture -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.]) - -dnl Relic: Generic options -AC_DEFINE([RELIC_NONE], [0], [Unknown or unrecognized parameter.]) - -dnl Relic: Arithmetic backends -AC_DEFINE([EASY], [1], [Easy C-only backend.]) -AC_DEFINE([GMP], [2], [Backend based on GNU Multiple Precision library.]) -AC_DEFINE([GMP_SEC], [3], [Backend based on GNU Multiple Precision library, but using constant-time code.]) - -AC_DEFUN([GMP_CHECK],[ - AC_REQUIRE([AC_PROG_CC]) - - CPPFLAGS_TEMP="$CPPFLAGS" - CPPFLAGS="$GMP_CPPFLAGS $CPPFLAGS" - LIBS_TEMP="$LIBS" - LIBS="$GMP_LDFLAGS $LIBS" - - AC_CHECK_HEADER( - gmp.h, - [AC_CHECK_LIB(gmp, __gmpz_init, [], [gmp_fail_reason="libgmp not found or unusable"; has_gmp=no;])], - [gmp_fail_reason="gmp header not found"; has_gmp=no;] - ) - - if test x"$has_gmp" != x"no"; then - # Proper support for macOS aarch64 was introduced in 6.3.0, but LTS distros - # like Ubuntu 20.04 (focal) use 6.2.0, so, the minimum supported version is - # determined by platform and architecture. - case $host in - *darwin*) - case $host_cpu in - aarch*) - gmp_major_version=6 - gmp_minor_version=3 - ;; - esac - ;; - *) - gmp_major_version=6 - gmp_minor_version=2 - ;; - esac - AC_MSG_CHECKING([gmp version >= $gmp_major_version.$gmp_minor_version]) - AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM( - [[@%:@include ]], - [[ - @%:@if __GNU_MP_VERSION < $gmp_major_version || __GNU_MP_VERSION_MINOR < $gmp_minor_version - @%:@error Unsupported GMP version - @%:@endif]])], - [AC_MSG_RESULT([yes]); GMP_LIBS="-lgmp"; has_gmp=yes;], - [AC_MSG_RESULT([no]); gmp_fail_reason="unsupported gmp version"; has_gmp=no;] - ) - fi - - if test x"$want_backend" = x"gmp" && test x"$has_gmp" = x"no"; then - AC_MSG_ERROR([$gmp_fail_reason]) - fi - - CPPFLAGS="$CPPFLAGS_TEMP" - LIBS="$LIBS_TEMP" -]) - -AC_ARG_WITH([backend], - [AS_HELP_STRING([--with-backend=auto|easy|gmp], - [backend implementation to use [default=auto]])], - [want_backend=$withval], - [want_backend=auto] -) - -case $host in - *darwin*) - AC_PATH_PROG([BREW],brew,) - if test x$BREW != x; then - # These Homebrew packages may be keg-only, meaning that they won't be found - # in expected paths because they may conflict with system files. Ask - # Homebrew where each one is located, then adjust paths accordingly. - gmp_prefix=`$BREW --prefix gmp 2>/dev/null` - if test x$gmp_prefix != x; then - GMP_CPPFLAGS="-I$gmp_prefix/include" - GMP_LDFLAGS="-L$gmp_prefix/lib" - fi - fi - ;; - *freebsd*) - GMP_CPPFLAGS="-I/usr/local/include" - GMP_LDFLAGS="-L/usr/local/lib" - ;; -esac - -if test x"$want_backend" = x"auto"; then - if test x"$use_optimizations" = x"no"; then - want_backend=easy - else - GMP_CHECK - if test x"$has_gmp" = x"yes"; then - want_backend=gmp - else - want_backend=easy - fi - fi -else - case $want_backend in - gmp) - dnl GMP_CHECK will report the reason if and why the backend cannot be used. - GMP_CHECK - ;; - easy) - ;; - *) - AC_MSG_ERROR([invalid backend explicitly requested]) - ;; - esac -fi - -case $want_backend in -gmp) - AC_DEFINE(ARITH, GMP, [Define if GNU MP backend is requested]) - ;; -easy) - AC_DEFINE(ARITH, EASY, [Define if C-only backend is requested].) - ;; -*) - AC_MSG_ERROR([invalid backend explicitly requested]) - ;; -esac - -dnl Relic: Multithreading APIs -AC_DEFINE([OPENMP], [1], [OpenMP multithreading support.]) -AC_DEFINE([PTHREAD], [2], [POSIX multithreading support.]) - -dnl Relic: Supported operating systems -AC_DEFINE([LINUX], [1], [GNU/Linux operating system.]) -AC_DEFINE([FREEBSD], [2], [FreeBSD operating system.]) -AC_DEFINE([MACOSX], [3], [MacOS operating system.]) -AC_DEFINE([WINDOWS], [4], [Windows operating system.]) -AC_DEFINE([DROID], [5], [Android operating system.]) -AC_DEFINE([DUINO], [6], [Arduino platform.]) -dnl AC_DEFINE([OPENBSD], [7], [OpenBSD operating system.]) - -dnl Relic: Supported timers -AC_DEFINE([HREAL], [1], [Per-process high-resolution timer.]) -AC_DEFINE([HPROC], [2], [Per-process high-resolution timer.]) -AC_DEFINE([HTHRD], [3], [Per-thread high-resolution timer.]) -AC_DEFINE([ANSI], [5], [ANSI-compatible timer.]) -AC_DEFINE([POSIX], [4], [POSIX-compatible timer.]) -AC_DEFINE([CYCLE], [6], [Cycle-counting timer.]) -AC_DEFINE([PERF], [7], [Performance monitoring framework.]) - -dnl Relic: Memory-allocation policies -AC_DEFINE([AUTO], [1], [Automatic memory allocation.]) -AC_DEFINE([DYNAMIC], [2], [Dynamic memory allocation.]) - -dnl Relic (CP): Support for faster CRT-based exponentiation in factoring-based cryptosystems -AC_DEFINE([PKCS1], [2], [RSA PKCS#1 v1.5 padding.]) -AC_DEFINE([PKCS2], [3], [RSA PKCS#1 v2.1 padding.]) - -dnl Relic (MD): Available hash functions -AC_DEFINE([SH224], [2], [SHA-224 hash function.]) -AC_DEFINE([SH256], [3], [SHA-256 hash function.]) -AC_DEFINE([SH384], [4], [SHA-384 hash function.]) -AC_DEFINE([SH512], [5], [SHA-512 hash function.]) -AC_DEFINE([B2S160], [6], [BLAKE2s-160 hash function.]) -AC_DEFINE([B2S256], [7], [BLAKE2s-256 hash function.]) - -dnl Relic (RAND): Available pseudo-random number generators -AC_DEFINE([HASHD], [1], [NIST HASH-DRBG generator.]) -AC_DEFINE([RDRND], [2], [Intel RdRand instruction.]) -AC_DEFINE([UDEV], [3], [Operating system underlying generator.]) -AC_DEFINE([CALL], [4], [Override library generator with the callback.]) - -dnl Relic (RAND): Available random number generator seeders -AC_DEFINE([LIBC], [1], [Standard C library generator.]) -dnl AC_DEFINE([RDRND], [2], [Intel RdRand instruction.]) -dnl AC_DEFINE([UDEV], [3], [Operating system underlying generator.]) -AC_DEFINE([WCGR], [4], [Use Windows' CryptGenRandom.]) - -dnl Relic (BN): Options for the multiple precision -AC_DEFINE([SINGLE], [1], [A multiple precision integer can store w words.]) -AC_DEFINE([CARRY], [2], [A multiple precision integer can store the result of an addition.]) -AC_DEFINE([DOUBLE], [3], [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([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([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([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([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([BRUCH], [6], [Hardware-friendly inversion by Brunner-Curiger-Hofstetter.]) -AC_DEFINE([CTAIA], [7], [Constant-time version of almost inverse.]) -AC_DEFINE([LOWER], [8], [Use implementation provided by the lower layer.]) - -if test x"$use_debug" = x"yes"; then - AC_DEFINE([DEBUG], [1], [Define this symbol if debugging support is enabled]) -fi - -dnl Define relic switches -AC_ARG_ENABLE([profiling], - [AS_HELP_STRING([--enable-profiling], - [Build with profiling support [default=no]])], - [use_profiling=$enableval], - [use_profiling=no]) - -if test x$use_profiling = xyes; then - AC_DEFINE([PROFL], [1], [Define this symbol if profiling support is enabled]) -fi - -AC_ARG_ENABLE([check], - [AS_HELP_STRING([--enable-check], - [Build with error-checking support [default=no]])], - [use_check=$enableval], - [use_check=no]) - -if test x$use_check = xyes; then - AC_DEFINE([CHECK], [1], [Define this symbol if error-checking support is enabled]) -fi - -AC_ARG_ENABLE([verbs], - [AS_HELP_STRING([--enable-verbs], - [Build with detailed error messages [default=no]])], - [use_verbs=$enableval], - [use_verbs=no]) - -if test x$use_verbs = xyes; then - AC_DEFINE([VERBS], [1], [Define this symbol if detailed error messages are enabled]) -fi - -AC_ARG_ENABLE([overhead], - [AS_HELP_STRING([--enable-overhead], - [Build with overhead estimation [default=no]])], - [use_overhead=$enableval], - [use_overhead=no]) - -if test x$use_overhead = xyes; then - AC_DEFINE([OVERH], [1], [Define this symbol if overhead estimation is enabled]) -fi - -AC_ARG_ENABLE([quiet], - [AS_HELP_STRING([--enable-quiet], - [Build with printing disabled [default=yes]])], - [use_quiet=$enableval], - [use_quiet=yes]) - -if test x$use_quiet = xyes; then - AC_DEFINE([QUIET], [1], [Define this symbol if printing is disabled]) -fi - -AC_ARG_ENABLE([color], - [AS_HELP_STRING([--enable-color], - [Build with colored output support [default=yes]])], - [use_color=$enableval], - [use_color=yes]) - -if test x$use_color = xyes; then - AC_DEFINE([COLOR], [1], [Define this symbol if colored output is enabled]) -fi - -AC_ARG_ENABLE([big_endian], - [AS_HELP_STRING([--enable-big-endian], - [Build with big-endian support [default=no]])], - [use_big_endian=$enableval], - [use_big_endian=no]) - -if test x$use_big_endian = xyes; then - AC_DEFINE([BIGED], [1], [Define this symbol if big-endian support is enabled]) -fi - -use_pkgconfig=yes - -if test x"$use_optimizations" = x"yes"; then - case $host_cpu in - amd64 | x86_64) - dnl Support for AMD64 (also known as x86_64 on some platforms) processors - CPU_ARCH="x64" - AC_DEFINE([ARCH], [X64], [Architecture.]) - AC_DEFINE([WSIZE], [64], [Size of word in this architecture.]) - ;; - aarch*) - dnl Support for 64-bit ARM processors - dnl Relic does not support aarch64 yet, set CPU_ARCH to none and ARCH to RELIC_NONE. - CPU_ARCH="none" - AC_DEFINE([ARCH], [RELIC_NONE], [Architecture.]) - AC_DEFINE([WSIZE], [64], [Size of word in this architecture.]) - ;; - i?86) - dnl Support for Intel x86 processors - CPU_ARCH="x86" - AC_DEFINE([ARCH], [X86], [Architecture.]) - AC_DEFINE([WSIZE], [32], [Size of word in this architecture.]) - ;; - arm*) - dnl Support for 32-bit native ARM processors - CPU_ARCH="arm" - AC_DEFINE([ARCH], [ARM], [Architecture.]) - AC_DEFINE([WSIZE], [32], [Size of word in this architecture.]) - ;; - *64*) - dnl Support for an undefined 64-bit architecture - CPU_ARCH="none" - AC_DEFINE([ARCH], [RELIC_NONE], [Architecture.]) - AC_DEFINE([WSIZE], [64], [Size of word in this architecture.]) - ;; - *32*) - dnl Support for an undefined 32-bit architecture - CPU_ARCH="none" - AC_DEFINE([ARCH], [RELIC_NONE], [Architecture.]) - AC_DEFINE([WSIZE], [32], [Size of word in this architecture.]) - ;; - *) - AC_MSG_ERROR([Unable to determine host architecture, may not be supported!]) - ;; - esac -else - case $host_cpu in - *64*) - dnl Support for an undefined 64-bit architecture - CPU_ARCH="none" - AC_DEFINE([ARCH], [RELIC_NONE], [Architecture.]) - AC_DEFINE([WSIZE], [64], [Size of word in this architecture.]) - ;; - *32* | arm* | i?86) - dnl Support for an undefined 32-bit architecture - CPU_ARCH="none" - AC_DEFINE([ARCH], [RELIC_NONE], [Architecture.]) - AC_DEFINE([WSIZE], [32], [Size of word in this architecture.]) - ;; - *) - AC_MSG_ERROR([Unable to determine host architecture, may not be supported!]) - ;; - esac -fi - -case $host in - *darwin*) - AC_DEFINE([OPSYS], [MACOSX], [Detected operation system.]) - TARGET_OS=darwin - - AC_PATH_PROG([BREW],brew,) - if test x$BREW = x; then - AC_PATH_PROG([PORT],port,) - # If homebrew isn't installed and macports is, add the macports default paths - # as a last resort. - if test x$PORT != x; then - CPPFLAGS="$CPPFLAGS -isystem /opt/local/include" - LDFLAGS="$LDFLAGS -L/opt/local/lib" - fi - fi - ;; - *mingw*) - AC_DEFINE([OPSYS], [WINDOWS], [Detected operation system.]) - TARGET_OS=windows - - use_pkgconfig=no - 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= - ;; - *linux*) - AC_DEFINE([OPSYS], [LINUX], [Detected operation system.]) - TARGET_OS=linux - - RELIC_CPPFLAGS="-D_GNU_SOURCE" - ;; - *android*) - AC_DEFINE([OPSYS], [DROID], [Detected operation system.]) - TARGET_OS=android - ;; - *freebsd*) - AC_DEFINE([OPSYS], [FREEBSD], [Detected operation system.]) - TARGET_OS=freebsd - ;; - *netbsd*) - AC_DEFINE([OPSYS], [NETBSD], [Detected operation system.]) - TARGET_OS=netbsd - ;; - *) - AC_DEFINE([OPSYS], [RELIC_NONE], [Detected operation system.]) - ;; -esac - -case $host in - *darwin*) - dnl Relic: Don't define FP_QNRES on Darwin - AC_DEFINE([SEED], [UDEV], [Chosen random generator seeder.]) - ;; - *mingw*) - AC_DEFINE([FP_QNRES], [], [Use -1 as quadratic non-residue.]) - AC_DEFINE([SEED], [WCGR], [Chosen random generator seeder.]) - ;; - *) - AC_DEFINE([FP_QNRES], [], [Use -1 as quadratic non-residue.]) - AC_DEFINE([SEED], [UDEV], [Chosen random generator seeder.]) - ;; -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" - ]) - -if test x"$CFLAGS_overridden" = x"no" -a x"$CXXFLAGS_overridden" = x"no"; then - dnl Enable warnings - AX_CHECK_COMPILE_FLAG([-Wall],[WARN_FLAGS="$WARN_FLAGS -Wall"], [], [[$FLAG_WERROR]]) - AX_CHECK_COMPILE_FLAG([-Wcast-align],[WARN_FLAGS="$WARN_FLAGS -Wcast-align"], [], [[$FLAG_WERROR]]) - AX_CHECK_COMPILE_FLAG([-Wextra],[WARN_FLAGS="$WARN_FLAGS -Wextra"], [], [[$FLAG_WERROR]]) - - dnl Exclude known warnings - AX_CHECK_COMPILE_FLAG([-Wlong-long],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-long-long"], [], [[$FLAG_WERROR]]) - AX_CHECK_COMPILE_FLAG([-Wshadow],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-shadow"], [], [[$FLAG_WERROR]]) - AX_CHECK_COMPILE_FLAG([-Wsign-compare],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-sign-compare"], [], [[$FLAG_WERROR]]) - AX_CHECK_COMPILE_FLAG([-Wstrict-prototypes],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-strict-prototypes"], [], [[$FLAG_WERROR]]) - AX_CHECK_COMPILE_FLAG([-Wunused-function],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-unused-function"], [], [[$FLAG_WERROR]]) - AX_CHECK_COMPILE_FLAG([-Wunused-parameter],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-unused-parameter"], [], [[$FLAG_WERROR]]) -fi - -dnl set default settings for relic -AC_DEFINE([ALIGN], [1], [Byte boundary to align digit vectors.]) - -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.) - -dnl Check for pthread compile/link requirements -AX_PTHREAD - -AC_SEARCH_LIBS([clock_gettime],[rt]) - -if test "$TARGET_OS" != "windows"; then - dnl All windows code is PIC, forcing it on just adds useless compile warnings - AX_CHECK_COMPILE_FLAG([-fPIC], [HARDENED_FLAGS="$HARDENED_FLAGS -fPIC"], [], [[$FLAG_WERROR]]) -fi - -dnl All versions of gcc that we commonly use for building are subject to bug -dnl https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348. To work around that, set -dnl -fstack-reuse=none for all gcc builds. (Only gcc understands this flag) -AX_CHECK_COMPILE_FLAG([-fstack-reuse=none], [HARDENED_FLAGS="$HARDENED_FLAGS -fstack-reuse=none"], [], [[$FLAG_WERROR]]) -if test "$use_hardening" != "no"; then - use_hardening=yes - AX_CHECK_COMPILE_FLAG([-Wstack-protector], [HARDENED_FLAGS="$HARDENED_FLAGS -Wstack-protector"]) - AX_CHECK_COMPILE_FLAG([-fstack-protector-all], [HARDENED_FLAGS="$HARDENED_FLAGS -fstack-protector-all"], [], [[$FLAG_WERROR]]) - - AX_CHECK_COMPILE_FLAG([-fcf-protection=full], [HARDENED_FLAGS="$HARDENED_FLAGS -fcf-protection=full"], [], [[$FLAG_WERROR]]) - - case $host in - *mingw*) - dnl stack-clash-protection doesn't currently work, and likely should just be skipped for Windows. - dnl See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90458 for more details. - ;; - *) - AX_CHECK_COMPILE_FLAG([-fstack-clash-protection], [HARDENED_FLAGS="$HARDENED_FLAGS -fstack-clash-protection"], [], [[$FLAG_WERROR]]) - ;; - esac - - case $host in - *aarch64*) - AX_CHECK_COMPILE_FLAG([-mbranch-protection=bti], [HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -mbranch-protection=bti"], [], [[$CXXFLAG_WERROR]]) - ;; - esac - - AX_CHECK_LINK_FLAG([-Wl,--enable-reloc-section], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--enable-reloc-section"], [], []) - AX_CHECK_LINK_FLAG([-Wl,--dynamicbase], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--dynamicbase"], [], []) - AX_CHECK_LINK_FLAG([-Wl,--nxcompat], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--nxcompat"], [], []) - AX_CHECK_LINK_FLAG([-Wl,--high-entropy-va], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--high-entropy-va"], [], []) - AX_CHECK_LINK_FLAG([-Wl,-z,relro], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"], [], []) - AX_CHECK_LINK_FLAG([-Wl,-z,now], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"], [], []) - AX_CHECK_LINK_FLAG([-Wl,-z,separate-code], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,separate-code"], [], []) - AX_CHECK_LINK_FLAG([-fPIE -pie], [HARDENED_FLAGS="$HARDENED_FLAGS -fPIE"; HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"], [], []) -fi - -CORE_CPPFLAGS="$CORE_CPPFLAGS -DHAVE_BUILD_INFO" - -case $host in - *mingw*) - AC_CHECK_LIB([user32], [main], [], [AC_MSG_ERROR([libuser32 missing])]) - AC_CHECK_LIB([shell32], [SHGetSpecialFolderPathW], [], [AC_MSG_ERROR([libshell32 missing])]) - AC_CHECK_LIB([advapi32], [CryptAcquireContextW], [], [AC_MSG_ERROR([libadvapi32 missing])]) - AC_CHECK_LIB([psapi], [GetProcessMemoryInfo], [], [AC_MSG_ERROR([libpsapi missing])]) - AC_CHECK_LIB([bcrypt], [main], [], [AC_MSG_ERROR([libbcrypt missing])]) - - dnl -static is interpreted by libtool, where it has a different meaning. - dnl In libtool-speak, it's -all-static. - AX_CHECK_LINK_FLAG([-static], [LIBTOOL_APP_LDFLAGS="$LIBTOOL_APP_LDFLAGS -all-static"]) - - CORE_CPPFLAGS="$CORE_CPPFLAGS -D_MT -DWIN32 -D_WINDOWS -D_WIN32_WINNT=0x0601 -D_WIN32_IE=0x0501 -DWIN32_LEAN_AND_MEAN" - dnl Prevent the definition of min/max macros. - dnl We always want to use the standard library. - CORE_CPPFLAGS="$CORE_CPPFLAGS -DNOMINMAX" - - 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= - - dnl We require Windows 7 (NT 6.1) or later - AX_CHECK_LINK_FLAG([-Wl,--major-subsystem-version -Wl,6 -Wl,--minor-subsystem-version -Wl,1], [CORE_LDFLAGS="$CORE_LDFLAGS -Wl,--major-subsystem-version -Wl,6 -Wl,--minor-subsystem-version -Wl,1"], [], []) - ;; - *darwin*) - AX_CHECK_LINK_FLAG([-Wl,-headerpad_max_install_names], [CORE_LDFLAGS="$CORE_LDFLAGS -Wl,-headerpad_max_install_names"], [], []) - CORE_CPPFLAGS="$CORE_CPPFLAGS -DMAC_OSX -DOBJC_OLD_DISPATCH_PROTOTYPES=0" - OBJCXXFLAGS="$CXXFLAGS" - ;; -esac - -dnl These flags are specific to ld64, and may cause issues with other linkers. -dnl For example: GNU ld will interpret -dead_strip as -de and then try and use -dnl "ad_strip" as the symbol for the entry point. -if test "$TARGET_OS" = "darwin"; then - AX_CHECK_LINK_FLAG([-Wl,-dead_strip], [CORE_LDFLAGS="$CORE_LDFLAGS -Wl,-dead_strip"], [], []) - AX_CHECK_LINK_FLAG([-Wl,-dead_strip_dylibs], [CORE_LDFLAGS="$CORE_LDFLAGS -Wl,-dead_strip_dylibs"], [], []) - AX_CHECK_LINK_FLAG([-Wl,-bind_at_load], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-bind_at_load"], [], []) -fi - -dnl Don't allow extended (non-ASCII) symbols in identifiers. This is easier for code review. -AX_CHECK_COMPILE_FLAG([-fno-extended-identifiers], [CORE_FLAGS="$CORE_FLAGS -fno-extended-identifiers"], [], [[$FLAG_WERROR]]) - -AC_LANG_POP([C]) - -AC_MSG_CHECKING([whether to build runtest]) -if test x$use_tests = xyes; then - AC_MSG_RESULT([yes]) -else - AC_MSG_RESULT([no]) -fi - -AC_MSG_CHECKING([whether to build runbench]) -if test x$use_bench = xyes; then - AC_MSG_RESULT([yes]) -else - AC_MSG_RESULT([no]) -fi - -AM_CONDITIONAL([TARGET_DARWIN], [test "$TARGET_OS" = "darwin"]) -AM_CONDITIONAL([TARGET_LINUX], [test "$TARGET_OS" = "linux"]) -AM_CONDITIONAL([TARGET_WINDOWS], [test "$TARGET_OS" = "windows"]) - -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"$use_tests" = x"yes"]) -AM_CONDITIONAL([USE_BENCH], [test x"$use_bench" = x"yes"]) -AM_CONDITIONAL([HARDEN], [test "$use_hardening" = "yes"]) -AM_CONDITIONAL([OPTIMIZE], [test "$use_optimizations" = "yes"]) - -AM_CONDITIONAL([ARITH_EASY], [test "$want_backend" = "easy"]) -AM_CONDITIONAL([ARITH_GMP], [test "$want_backend" = "gmp"]) - -AC_SUBST(CPU_ARCH) -AC_SUBST(DEBUG_FLAGS) -AC_SUBST(RAND_PATH, hashd) -AC_SUBST(RELIC_CPPFLAGS) -AC_SUBST(WARN_FLAGS) -AC_SUBST(NOWARN_FLAGS) -AC_SUBST(LIBTOOL_APP_LDFLAGS) -AC_SUBST(HARDENED_FLAGS) -AC_SUBST(HARDENED_LDFLAGS) -AC_SUBST(CORE_LDFLAGS) -AC_SUBST(CORE_CPPFLAGS) -AC_SUBST(CORE_FLAGS) - -AC_SUBST(GMP_LDFLAGS) -AC_SUBST(GMP_CPPFLAGS) -AC_SUBST(GMP_LIBS) - -AC_CONFIG_HEADERS([depends/relic/include/relic_conf.h]) -AC_CONFIG_FILES([Makefile]) - -AC_OUTPUT - -dnl Peplace conflict-prone PACKAGE-prefixed macros with DASHBLS -sed -i.old 's/PACKAGE/DASHBLS/g' depends/relic/include/relic_conf.h -sed -i.old 's/PACKAGE/DASHBLS/g' config.status - -echo -echo "Options used to compile and link:" -echo " target os = $TARGET_OS" -echo " backend = $want_backend" -echo " build bench = $use_tests" -echo " build test = $use_bench" -echo " use debug = $use_debug" -echo " use hardening = $use_hardening" -echo " use optimizations = $use_optimizations" -echo -echo " LDFLAGS = $HARDENED_LDFLAGS $CORE_LDFLAGS $GMP_LDFLAGS" -echo " CFLAGS = $DEBUG_FLAGS $HARDENED_FLAGS $CORE_FLAGS $WARN_FLAGS $NOWARN_FLAGS" -echo " CPPFLAGS = $CORE_CPPFLAGS $GMP_CPPFLAGS" -echo " CXXFLAGS = $DEBUG_FLAGS $HARDENED_FLAGS $CORE_FLAGS $WARN_FLAGS $NOWARN_FLAGS" -echo " PTHREAD_FLAGS = $PTHREAD_CFLAGS $PTHREAD_LIBS" -echo diff --git a/src/dashbls/depends/catch2/CMakeLists.txt b/src/dashbls/depends/catch2/CMakeLists.txt deleted file mode 100644 index efbbe0f7d556..000000000000 --- a/src/dashbls/depends/catch2/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.18.0 FATAL_ERROR) - -set(PROJECT_NAME "catch2") - -project( - ${PROJECT_NAME} - VERSION 2.13 - LANGUAGES CXX -) - -set( - ${PROJECT_NAME}_HEADERS - catch2/catch.hpp -) - -list( - TRANSFORM ${PROJECT_NAME}_HEADERS - PREPEND "${CMAKE_CURRENT_LIST_DIR}/include/" -) - -add_library( - ${PROJECT_NAME} - INTERFACE -) - -target_sources( - ${PROJECT_NAME} - INTERFACE - "${${PROJECT_NAME}_HEADERS}" -) - -target_include_directories( - ${PROJECT_NAME} - INTERFACE - "$" - "$" -) diff --git a/src/dashbls/depends/relic/.editorconfig b/src/dashbls/depends/relic/.editorconfig deleted file mode 100644 index bdc049fe5f28..000000000000 --- a/src/dashbls/depends/relic/.editorconfig +++ /dev/null @@ -1,7 +0,0 @@ -# top-most EditorConfig file -root = true - -# 4 space indentation -[*.{cmake,c,h}] -indent_style = tab -indent_size = 4 diff --git a/src/dashbls/depends/relic/.github/workflows/16bit.yml b/src/dashbls/depends/relic/.github/workflows/16bit.yml deleted file mode 100644 index 8633cd322672..000000000000 --- a/src/dashbls/depends/relic/.github/workflows/16bit.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Basic configuration (16 bits) - -on: - push: - branches: - - '**' # all branches - pull_request: - branches: - - '**' # all branches - -jobs: - build: - name: ${{ matrix.config.name }} - runs-on: ${{ matrix.config.os }} - strategy: - fail-fast: false - matrix: - config: - - { - name: "Ubuntu Latest - GCC", - artifact: "linux-gcc.tar.xz", - os: ubuntu-latest, - cc: "gcc", - } - - { - name: "Ubuntu Latest - Clang", - artifact: "linux-clang.tar.xz", - os: ubuntu-latest, - cc: "clang", - } - steps: - - uses: actions/checkout@v2 - - - name: Run CMake (standard) - if: ${{ !(runner.os == 'Windows') }} - shell: bash - run: | - mkdir build - cd build - cmake -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DWSIZE=16 -DSEED= -DBENCH=0 -DTESTS=10 .. - - - name: CMake Build - run: cmake --build build - - - name: CMake Test - run: | - cd build - ctest --verbose . diff --git a/src/dashbls/depends/relic/.github/workflows/32bit.yml b/src/dashbls/depends/relic/.github/workflows/32bit.yml deleted file mode 100644 index bb225ab8083c..000000000000 --- a/src/dashbls/depends/relic/.github/workflows/32bit.yml +++ /dev/null @@ -1,97 +0,0 @@ -name: Basic configuration (32 bits) - -on: - push: - branches: - - '**' # all branches - pull_request: - branches: - - '**' # all branches - -jobs: - build: - name: ${{ matrix.config.name }} - runs-on: ${{ matrix.config.os }} - strategy: - fail-fast: false - matrix: - config: - - { - name: "Windows Latest - MSVC", - artifact: "windows-msvc.tar.xz", - os: windows-latest, - cc: "cl", - } - - { - name: "Windows Latest - MinGW", - artifact: "windows-mingw.tar.xz", - os: windows-latest, - cc: "gcc" - } - - { - name: "Ubuntu Latest - GCC", - artifact: "linux-gcc.tar.xz", - os: ubuntu-latest, - cc: "gcc", - } - - { - name: "Ubuntu Latest - Clang", - artifact: "linux-clang.tar.xz", - os: ubuntu-latest, - cc: "clang", - } - - { - name: "MacOS Latest", - os: macos-latest, - cc: "clang", - } - steps: - - uses: actions/checkout@v2 - - - name: Set Windows enviroment - if: ${{ (runner.os == 'Windows') && (matrix.config.cc == 'cl') }} - uses: ilammy/msvc-dev-cmd@v1 - - - name: Set MinGW enviroment - if: ${{ (runner.os == 'Windows') && (matrix.config.cc == 'gcc') }} - uses: msys2/setup-msys2@v2 - with: - msystem: MINGW64 - install: >- - git - base-devel - gcc - cmake - update: true - - - name: Run CMake (Win) - if: ${{ (runner.os == 'Windows') && (matrix.config.cc == 'cl') }} - shell: bash - run: | - mkdir build - cd build - cmake -DWSIZE=32 -DSEED= -DBENCH=0 -G "NMake Makefiles" .. - - - name: Run CMake (MingW) - if: ${{ (runner.os == 'Windows') && (matrix.config.cc == 'gcc') }} - shell: bash - run: | - mkdir build - cd build - cmake -DWSIZE=32 -DSEED= -DBENCH=0 -G "MinGW Makefiles" .. - - - name: Run CMake (standard) - if: ${{ !(runner.os == 'Windows') }} - shell: bash - run: | - mkdir build - cd build - cmake -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DWSIZE=32 -DSEED= -DBENCH=0 .. - - - name: CMake Build - run: cmake --build build - - - name: CMake Test - run: | - cd build - ctest --verbose . diff --git a/src/dashbls/depends/relic/.github/workflows/8bit.yml b/src/dashbls/depends/relic/.github/workflows/8bit.yml deleted file mode 100644 index 0765607ec9c7..000000000000 --- a/src/dashbls/depends/relic/.github/workflows/8bit.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Basic configuration (8 bits) - -on: - push: - branches: - - '**' # all branches - pull_request: - branches: - - '**' # all branches - -jobs: - build: - name: ${{ matrix.config.name }} - runs-on: ${{ matrix.config.os }} - strategy: - fail-fast: false - matrix: - config: - - { - name: "Ubuntu Latest - GCC", - artifact: "linux-gcc.tar.xz", - os: ubuntu-latest, - cc: "gcc", - } - - { - name: "Ubuntu Latest - Clang", - artifact: "linux-clang.tar.xz", - os: ubuntu-latest, - cc: "clang", - } - steps: - - uses: actions/checkout@v2 - - - name: Run CMake (standard) - if: ${{ !(runner.os == 'Windows') }} - shell: bash - run: | - mkdir build - cd build - cmake -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DWSIZE=8 -DSEED= -DBENCH=0 -DTESTS=10 .. - - - name: CMake Build - run: cmake --build build - - - name: CMake Test - run: | - cd build - ctest --verbose . diff --git a/src/dashbls/depends/relic/.github/workflows/bls12-381.yml b/src/dashbls/depends/relic/.github/workflows/bls12-381.yml deleted file mode 100644 index dc518a02b94d..000000000000 --- a/src/dashbls/depends/relic/.github/workflows/bls12-381.yml +++ /dev/null @@ -1,91 +0,0 @@ -name: BLS12-381 configuration (ASM) - -on: - push: - branches: - - '**' # all branches - pull_request: - branches: - - '**' # all branches - -jobs: - build: - name: ${{ matrix.config.name }} - runs-on: ${{ matrix.config.os }} - strategy: - fail-fast: false - matrix: - config: - #- { - #name: "Windows Latest - MinGW", - #artifact: "windows-mingw.tar.xz", - #os: windows-latest, - #cc: "gcc" - #} - - { - name: "Ubuntu Latest - GCC", - artifact: "linux-gcc.tar.xz", - os: ubuntu-latest, - cc: "gcc", - } - - { - name: "Ubuntu Latest - Clang", - artifact: "linux-clang.tar.xz", - os: ubuntu-latest, - cc: "clang", - } - - { - name: "MacOS Latest", - os: macos-latest, - cc: "clang", - } - steps: - - uses: actions/checkout@v2 - - - name: Install Linux Dependencies - if: runner.os == 'Linux' - run: sudo apt install libgmp-dev - - - name: Install MacOS Dependencies - if: runner.os == 'MacOS' - run: brew install gmp - - - name: Set MinGW enviroment - if: ${{ (runner.os == 'Windows') && (matrix.config.cc == 'gcc') }} - uses: msys2/setup-msys2@v2 - with: - msystem: MINGW64 - install: >- - git - base-devel - gcc - cmake - gmp - update: true - - - name: Run CMake (MingW) - if: ${{ (runner.os == 'Windows') && (matrix.config.cc == 'gcc') }} - shell: bash - run: | - mkdir build - cd build - cmake -G "MinGW Makefiles" .. - ../preset/x64-pbc-bls12-381.sh . - cmake -DSEED= -DBENCH=0 -DSTBIN=off -DRAND=HASHD . - - - name: Run CMake (standard) - if: ${{ !(runner.os == 'Windows') }} - shell: bash - run: | - mkdir build - cd build - ../preset/x64-pbc-bls12-381.sh ../ - cmake -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DSEED= -DBENCH=0 . - - - name: CMake Build - run: cmake --build build - - - name: CMake Test - run: | - cd build - ctest --verbose . diff --git a/src/dashbls/depends/relic/.github/workflows/easy.yml b/src/dashbls/depends/relic/.github/workflows/easy.yml deleted file mode 100644 index 761f07f33ca5..000000000000 --- a/src/dashbls/depends/relic/.github/workflows/easy.yml +++ /dev/null @@ -1,97 +0,0 @@ -name: Basic configuration - -on: - push: - branches: - - '**' # all branches - pull_request: - branches: - - '**' # all branches - -jobs: - build: - name: ${{ matrix.config.name }} - runs-on: ${{ matrix.config.os }} - strategy: - fail-fast: false - matrix: - config: - - { - name: "Windows Latest - MSVC", - artifact: "windows-msvc.tar.xz", - os: windows-latest, - cc: "cl", - } - - { - name: "Windows Latest - MinGW", - artifact: "windows-mingw.tar.xz", - os: windows-latest, - cc: "gcc" - } - - { - name: "Ubuntu Latest - GCC", - artifact: "linux-gcc.tar.xz", - os: ubuntu-latest, - cc: "gcc", - } - - { - name: "Ubuntu Latest - Clang", - artifact: "linux-clang.tar.xz", - os: ubuntu-latest, - cc: "clang", - } - - { - name: "MacOS Latest", - os: macos-latest, - cc: "clang", - } - steps: - - uses: actions/checkout@v2 - - - name: Set Windows enviroment - if: ${{ (runner.os == 'Windows') && (matrix.config.cc == 'cl') }} - uses: ilammy/msvc-dev-cmd@v1 - - - name: Set MinGW enviroment - if: ${{ (runner.os == 'Windows') && (matrix.config.cc == 'gcc') }} - uses: msys2/setup-msys2@v2 - with: - msystem: MINGW64 - install: >- - git - base-devel - gcc - cmake - update: true - - - name: Run CMake (Win) - if: ${{ (runner.os == 'Windows') && (matrix.config.cc == 'cl') }} - shell: bash - run: | - mkdir build - cd build - cmake -DSEED= -DBENCH=0 -G "NMake Makefiles" .. - - - name: Run CMake (MingW) - if: ${{ (runner.os == 'Windows') && (matrix.config.cc == 'gcc') }} - shell: bash - run: | - mkdir build - cd build - cmake -DSEED= -DBENCH=0 -G "MinGW Makefiles" .. - - - name: Run CMake (standard) - if: ${{ !(runner.os == 'Windows') }} - shell: bash - run: | - mkdir build - cd build - cmake -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DSEED= -DBENCH=0 .. - - - name: CMake Build - run: cmake --build build - - - name: CMake Test - run: | - cd build - ctest --verbose . diff --git a/src/dashbls/depends/relic/.github/workflows/gmp-sec.yml b/src/dashbls/depends/relic/.github/workflows/gmp-sec.yml deleted file mode 100644 index 2cd342099ab3..000000000000 --- a/src/dashbls/depends/relic/.github/workflows/gmp-sec.yml +++ /dev/null @@ -1,88 +0,0 @@ -name: Faster configuration (constant-time GMP) - -on: - push: - branches: - - '**' # all branches - pull_request: - branches: - - '**' # all branches - -jobs: - build: - name: ${{ matrix.config.name }} - runs-on: ${{ matrix.config.os }} - strategy: - fail-fast: false - matrix: - config: - - { - name: "Windows Latest - MinGW", - artifact: "windows-mingw.tar.xz", - os: windows-latest, - cc: "gcc" - } - - { - name: "Ubuntu Latest - GCC", - artifact: "linux-gcc.tar.xz", - os: ubuntu-latest, - cc: "gcc", - } - - { - name: "Ubuntu Latest - Clang", - artifact: "linux-clang.tar.xz", - os: ubuntu-latest, - cc: "clang", - } - - { - name: "MacOS Latest", - os: macos-latest, - cc: "clang", - } - steps: - - uses: actions/checkout@v2 - - - name: Install Linux Dependencies - if: runner.os == 'Linux' - run: sudo apt install libgmp-dev - - - name: Install MacOS Dependencies - if: runner.os == 'MacOS' - run: brew install gmp - - - name: Set MinGW enviroment - if: ${{ (runner.os == 'Windows') && (matrix.config.cc == 'gcc') }} - uses: msys2/setup-msys2@v2 - with: - msystem: MINGW64 - install: >- - git - base-devel - gcc - cmake - gmp - update: true - - - name: Run CMake (MingW) - if: ${{ (runner.os == 'Windows') && (matrix.config.cc == 'gcc') }} - shell: bash - run: | - mkdir build - cd build - cmake -DSEED= -DBENCH=0 -DARITH=gmp-sec -G "MinGW Makefiles" .. - - - name: Run CMake (standard) - if: ${{ !(runner.os == 'Windows') }} - shell: bash - run: | - mkdir build - cd build - cmake -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DSEED= -DBENCH=0 -DARITH=gmp-sec .. - - - name: CMake Build - run: cmake --build build - - - name: CMake Test - run: | - cd build - ctest --verbose . diff --git a/src/dashbls/depends/relic/.github/workflows/gmp.yml b/src/dashbls/depends/relic/.github/workflows/gmp.yml deleted file mode 100644 index 618e05da3078..000000000000 --- a/src/dashbls/depends/relic/.github/workflows/gmp.yml +++ /dev/null @@ -1,88 +0,0 @@ -name: Faster configuration (GMP) - -on: - push: - branches: - - '**' # all branches - pull_request: - branches: - - '**' # all branches - -jobs: - build: - name: ${{ matrix.config.name }} - runs-on: ${{ matrix.config.os }} - strategy: - fail-fast: false - matrix: - config: - - { - name: "Windows Latest - MinGW", - artifact: "windows-mingw.tar.xz", - os: windows-latest, - cc: "gcc" - } - - { - name: "Ubuntu Latest - GCC", - artifact: "linux-gcc.tar.xz", - os: ubuntu-latest, - cc: "gcc", - } - - { - name: "Ubuntu Latest - Clang", - artifact: "linux-clang.tar.xz", - os: ubuntu-latest, - cc: "clang", - } - - { - name: "MacOS Latest", - os: macos-latest, - cc: "clang", - } - steps: - - uses: actions/checkout@v2 - - - name: Install Linux Dependencies - if: runner.os == 'Linux' - run: sudo apt install libgmp-dev - - - name: Install MacOS Dependencies - if: runner.os == 'MacOS' - run: brew install gmp - - - name: Set MinGW enviroment - if: ${{ (runner.os == 'Windows') && (matrix.config.cc == 'gcc') }} - uses: msys2/setup-msys2@v2 - with: - msystem: MINGW64 - install: >- - git - base-devel - gcc - cmake - gmp - update: true - - - name: Run CMake (MingW) - if: ${{ (runner.os == 'Windows') && (matrix.config.cc == 'gcc') }} - shell: bash - run: | - mkdir build - cd build - cmake -DSEED= -DBENCH=0 -DARITH=gmp -G "MinGW Makefiles" .. - - - name: Run CMake (standard) - if: ${{ !(runner.os == 'Windows') }} - shell: bash - run: | - mkdir build - cd build - cmake -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DSEED= -DBENCH=0 -DARITH=gmp .. - - - name: CMake Build - run: cmake --build build - - - name: CMake Test - run: | - cd build - ctest --verbose . diff --git a/src/dashbls/depends/relic/.gitignore b/src/dashbls/depends/relic/.gitignore deleted file mode 100644 index d73f86704276..000000000000 --- a/src/dashbls/depends/relic/.gitignore +++ /dev/null @@ -1,31 +0,0 @@ -relic-all.c -target* -*.o - -*/x64/ -*.vcxproj* -.vs/ -*.sln -*.dir/ -x64/ - -*/win32/ -win32/ - -*/CMakeCache.txt -CMakeCache.txt - -*/Makefile -Makefile -*/CMakeFiles -CMakeFiles - -lib/ -bin/ - -CMakeSettings.json -Testing/ -include/relic_conf.h -install_manifest.txt - -src/low/fiat/*.c diff --git a/src/dashbls/depends/relic/.indent.pro b/src/dashbls/depends/relic/.indent.pro deleted file mode 100644 index 3fa50ae4f126..000000000000 --- a/src/dashbls/depends/relic/.indent.pro +++ /dev/null @@ -1,64 +0,0 @@ --nbap --no-blank-lines-after-procedures --brf --braces-on-func-def-line --br --braces-on-if-line --brs --braces-on-struct-decl-line --cd1 --declaration-comment-column1 --ncdb --no-comment-delimiters-on-blank-lines --ce --cuddle-else --ci8 --continuation-indentation8 --cli4 --case-indentation4 --cp1 --else-endif-column1 --di1 --declaration-indentation1 --fc1 --format-first-column-comments --hnl --honour-newlines --i4 --indent-level4 --ip0 --parameter-indentation0 --l80 --line-length80 --lc80 --comment-line-length80 --lps --leave-preprocessor-space --nbbo --break-after-boolean-operator --nbad --no-blank-lines-after-declarations --nbbo --break-after-boolean-operator --ncs --no-space-after-casts --npcs --no-space-after-function-call-names --nprs --no-space-after-parentheses --npsl --dont-break-procedure-type --nlp --dont-line-up-parentheses --pmt --preserve-mtime --saf --space-after-for --sai --space-after-if --saw --space-after-while --sc --start-left-side-of-comments --ss --space-special-semicolon --ut --use-tabs --ts4 --tab-size4 --T int8_t --T uint8_t --T FILE --T bn_t --T dv_t --T dv2_t --T dv3_t --T dv6_t --T ft_t --T fb_t --T fb2_t --T fb4_t --T fp_t --T fp2_t --T fp3_t --T fp6_t --T fp12_t --T fp18_t --T eb_t --T ep_t --T ep2_t --T ep3_t --T err_t --T ctx_t --T state_t --T dig_t --T dbl_t --T dis_t --T rsa_pub_t --T rsa_prv_t diff --git a/src/dashbls/depends/relic/.travis.yml b/src/dashbls/depends/relic/.travis.yml deleted file mode 100644 index 330d9929917d..000000000000 --- a/src/dashbls/depends/relic/.travis.yml +++ /dev/null @@ -1,33 +0,0 @@ -language: cpp - -addons: - apt: - packages: - - cmake - - cmake-data - -compiler: - - clang - - gcc - -env: - # Automatic allocation - - CONFIG="-DSEED= -DBENCH=0" TEST="" - # Dynamic allocation - - CONFIG="-DALLOC=DYNAMIC -DSEED= -DBENCH=0" TEST="" - # Jacobian coordinates - - CONFIG="-DSEED= -DBENCH=0 -DEP_METHD='JACOB;LWNAF;COMBS;INTER'" TEST="" - # Build for Edwards curves - - CONFIG="-DSEED= -DBENCH=0 -DFP_PRIME=255 -FP_QNRES=off -DEC_METHD=EDDIE -DED_METHD='PROJC;LWNAF;LWNAF;BASIC' -DWITH='BN;DV;MD;FP;ED,EC;CP'" TEST="-E test_fpx" - # Build Supersingular curves - - CONFIG="-DSEED= -DBENCH=0 -DBN_PRECI=1536 -DFP_PRIME=1536 -DFP_QNRES=on" TEST="-E test_fpx" - # Build BLS12-381 - - CONFIG="-DWSIZE=64 -DARITH=x64-asm-6l -DFP_PRIME=381 -DFP_PMERS=off -DFP_QNRES=on" - - # Build with Address Sanityzer - - CONFIG="-DAUSAN=on -DSEED= -DBENCH=0" TEST="" - -script: - - mkdir build && cd build - - cmake $CONFIG .. && make -j && ctest -V $TEST - - cd .. && rm -rf build diff --git a/src/dashbls/depends/relic/CMakeLists.txt b/src/dashbls/depends/relic/CMakeLists.txt deleted file mode 100644 index db36c9bb7d46..000000000000 --- a/src/dashbls/depends/relic/CMakeLists.txt +++ /dev/null @@ -1,339 +0,0 @@ -cmake_minimum_required(VERSION 3.18) -cmake_policy(SET CMP0054 NEW) - -project(RELIC C CXX) -set(PROJECT_VERSION_MAJOR "0") -set(PROJECT_VERSION_MINOR "5") -set(PROJECT_VERSION_PATCH "0") -set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") -set(VERSION ${PROJECT_VERSION}) - -set(INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include/low ${CMAKE_CURRENT_SOURCE_DIR}/src/tmpl) -include_directories(${INCLUDE}) - -set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) -set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) - -set(WFLAGS "-Wall") - -message("\n-- Configuring ${PROJECT_NAME} ${PROJECT_VERSION}...\n") - -message(STATUS "Available switches (default = CHECK, VERBS, DOCUM):\n") - -message(" DEBUG=[off|on] Build with debugging support.") -message(" PROFL=[off|on] Build with profiling support.") -message(" CHECK=[off|on] Build with error-checking support.") -message(" VERBS=[off|on] Build with detailed error messages.") -message(" OVERH=[off|on] Build with overhead estimation.") -message(" DOCUM=[off|on] Build documentation.") -message(" STRIP=[off|on] Build only selected algorithms.") -message(" QUIET=[off|on] Build with printing disabled.") -message(" COLOR=[off|on] Build with colored output.") -message(" BIGED=[off|on] Build with big-endian support.") -message(" SHLIB=[off|on] Build shared library.") -message(" STLIB=[off|on] Build static library.") -message(" STBIN=[off|on] Build static binaries.") -message(" AMALG=[off|on] Build amalgamation for better performance.") -message(" AUSAN=[off|on] Build with ASan and UBSan (gcc/clang only).\n") - -option(DEBUG "Build with debugging support" off) -option(PROFL "Build with profiling support" off) -option(CHECK "Build with error-checking support" on) -option(VERBS "Build with detailed error messages" on) -option(OVERH "Build with overhead estimation" off) -option(DOCUM "Build documentation" on) -option(STRIP "Build only the selected algorithms" off) -option(QUIET "Build with printing disabled" off) -option(COLOR "Build with colored output" on) -option(BIGED "Build with big-endian support" off) -option(SHLIB "Build shared library" on) -option(STLIB "Build static library" on) -option(STBIN "Build static binaries" off) -option(AMALG "Build amalgamation" off) -option(AUSAN "Build with ASan and UBSan (gcc/clang only)" off) - -message(STATUS "Number of times each test or benchmark is ran (default = 50, 1000):\n") - -message(" TESTS=n If n > 0, build automated tests and run them n times.") -message(" BENCH=n If n > 0, build automated benchmarks and run them n * n times.\n") - -message(STATUS "Number of available processor cores (default = 1):\n") - -message(" CORES=n If n > 1, enable multithreading support.\n") - -message(STATUS "Available modules (default = ALL)\n") - -message(" WITH=BN Multiple precision arithmetic.") -message(" WITH=DV Temporary double-precision digit vectors.") -message(" WITH=FP Prime field arithmetic.") -message(" WITH=FPX Prime extension field arithmetic.") -message(" WITH=FB Binary field arithmetic.") -message(" WITH=EP Elliptic curves over prime fields.") -message(" WITH=EPX Elliptic curves over quadratic extensions of prime fields.") -message(" WITH=EB Elliptic curves over binary fields.") -message(" WITH=ED Elliptic Edwards curves over prime fields.") -message(" WTTH=EC Elliptic curve cryptography.") -message(" WITH=PB Pairings over binary elliptic curves.") -message(" WITH=PP Pairings over prime elliptic curves.") -message(" WTTH=PC Pairing-based cryptography.") -message(" WITH=BC Block ciphers (symmetric encryption).") -message(" WITH=MD Message digests (hash functions).") -message(" WITH=CP Cryptographic protocols.") -message(" WITH=MPC Multi-party computation primitives.") -message(" WITH=ALL All of the above.") -message(" Note: the programmer is responsible for not using unselected modules.\n") - -message(STATUS "Available arithmetic backends (default = easy):\n") - -message(" ARITH=easy Easy-to-understand and portable, but slow backend.") -message(" ARITH=fiat Backend based on code generated from Fiat-Crypto.") -message(" ARITH=gmp Backend based on GNU Multiple Precision library.\n") -message(" ARITH=gmp-sec Same as above, but using constant-time code.\n") - -message(STATUS "Available memory-allocation policies (default = AUTO):\n") - -message(" ALLOC=AUTO All memory is automatically allocated.") -message(" ALLOC=DYNAMIC All memory is allocated dynamically on demand.\n") - -message(STATUS "Supported operating systems (default = LINUX):\n") - -message(" OPSYS= Undefined/No specific operating system.") -message(" OPSYS=LINUX GNU/Linux operating system.") -message(" OPSYS=FREEBSD FreeBSD operating system.") -message(" OPSYS=NETBSD NetBSD operating system.") -message(" OPSYS=MACOSX Mac OS X operating system.") -message(" OPSYS=WINDOWS Windows operating system.") -message(" OPSYS=DROID Android operating system.") -message(" OPSYS=DUINO Arduino platform.\n") - -message(STATUS "Supported multithreading APIs (default = UNDEF):\n") - -message(" MULTI= No multithreading support.") -message(" MULTI=OPENMP Open Multi-Processing.") -message(" MULTI=PTHREAD POSIX threads.\n") - -message(STATUS "Supported timers (default = HREAL):\n") - -message(" TIMER= No timer.") -message(" TIMER=HREAL GNU/Linux realtime high-resolution timer.") -message(" TIMER=HPROC GNU/Linux per-process high-resolution timer.") -message(" TIMER=HTHRD GNU/Linux per-thread high-resolution timer.") -message(" TIMER=ANSI ANSI-compatible timer.") -message(" TIMER=POSIX POSIX-compatible timer.") -message(" TIMER=CYCLE Cycle-counting timer. (architecture-dependant)") -message(" TIMER=PERF GNU/Linux performance monitoring framework.\n") - -message(STATUS "Prefix to identify this build of the library (default = \"\"):\n") - -message(" LABEL=relic\n") - -include(cmake/arch.cmake) -include(cmake/err.cmake) -include(cmake/bn.cmake) -include(cmake/fp.cmake) -include(cmake/fpx.cmake) -include(cmake/fb.cmake) -include(cmake/ep.cmake) -include(cmake/eb.cmake) -include(cmake/ed.cmake) -include(cmake/ec.cmake) -include(cmake/pp.cmake) -include(cmake/md.cmake) -include(cmake/cp.cmake) -include(cmake/rand.cmake) -include(cmake/with.cmake) - -# Number of tests and benchmarks -set(BENCH "100" CACHE STRING "Number of times each benchmark is ran.") -set(TESTS "100" CACHE STRING "Number of times each test is ran.") - -# Number of cores. -set(CORES "1" CACHE STRING "Number of available processor cores.") - -# Choose the arithmetic backend. -set(ARITH "easy" CACHE STRING "Arithmetic backend") - -# Choose the memory-allocation policy. -set(ALLOC "AUTO" CACHE STRING "Allocation policy") - -# Simulator of the target platform. -set(SIMUL "$ENV{SIMUL}" CACHE STRING "Path to call a simulator of the target platform.") -set(SIMAR "$ENV{SIMAR}" CACHE STRING "Arguments to call a simulator of the target platform.") -string(REPLACE " " ";" SIMAR "${SIMAR}") - -# Linker flags. -string(TOLOWER ${ARITH} LFLAGS) -set(LFLAGS "-L${CMAKE_CURRENT_SOURCE_DIR}/src/low/${LFLAGS}/") -set(LFLAGS "${LFLAGS} $ENV{LDFLAGS}") - -if(STBIN) - set(LFLAGS "${LFLAGS} -static") - set(CMAKE_LINK_SEARCH_START_STATIC ON) - set(CMAKE_LINK_SEARCH_END_STATIC ON) -endif() - -# Discover the operating system. -if(CMAKE_SYSTEM_NAME STREQUAL Linux) - set(OPSYS "LINUX" CACHE STRING "Operating system") -else() - if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD) - set(OPSYS "FREEBSD" CACHE STRING "Operating system") - else() - if(CMAKE_SYSTEM_NAME STREQUAL Darwin) - set(OPSYS "MACOSX" CACHE STRING "Operating system") - else() - if(CMAKE_SYSTEM_NAME STREQUAL NetBSD) - set(OPSYS "NETBSD" CACHE STRING "Operating system") - else() - if(CMAKE_SYSTEM_NAME STREQUAL Windows) - set(OPSYS "WINDOWS" CACHE STRING "Operating system") - endif() - endif() - endif() - endif() -endif() -if(OPSYS STREQUAL LINUX) - add_definitions(-D_GNU_SOURCE) -endif() -message(STATUS "Configured operating system: ${OPSYS}") - -if(OPSYS STREQUAL LINUX) - set(TIMER "HREAL" CACHE STRING "Timer") -else() - set(TIMER "ANSI" CACHE STRING "Timer") -endif() - -if(MSVC) - #defaults to the DLL runtime library. - set(RUNTIME "MD" CACHE STRING "MSVC runtime libraries") - message(STATUS "Supported MSVC runtime libraries (default = MD):\n") - message(" RUNTIME=MD DLL runtime library (/MD,/MDd).") - message(" RUNTIME=MT Static runtime library (/MT,/MTd).\n") - - #loop over the compile flags to swap /MD and /MT. - set(CompilerFlags - CMAKE_C_FLAGS_DEBUG - CMAKE_C_FLAGS_RELEASE - CMAKE_C_FLAGS_RELWITHDEBINFO - CMAKE_C_FLAGS_MINSIZEREL) - foreach(CompilerFlag ${CompilerFlags}) - if(RUNTIME STREQUAL MT) - string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") - else() - string(REPLACE "/MT" "/MD" ${CompilerFlag} "${${CompilerFlag}}") - endif() - endforeach() -endif() - -if("$ENV{CFLAGS}" STREQUAL "") - # If the user did not specify compile flags, we use sane defaults. - if(DEBUG) - if (MSVC) - set(CFLAGS "/Od" CACHE STRING "Default compiler flags.") - else() - # Turn off all optimizations. - set(CFLAGS "-pipe -std=c99 -O0 -fno-omit-frame-pointer" CACHE STRING "Default compiler flags.") - set(DFLAGS "-ggdb") - endif() - else() - if (MSVC) - set(CFLAGS "/O2" CACHE STRING "Default compiler flags.") - else() - set(CFLAGS "-pipe -std=c99 -O2 -funroll-loops -fomit-frame-pointer" CACHE STRING "Default compiler flags.") - endif() - endif() -else() - # Turn on debugging symbols with custom flags. - if(DEBUG) - if (MSVC) - set(DFLAGS "/Z7") - else () - set(DFLAGS "-ggdb") - endif() - endif() - set(CFLAGS "$ENV{CFLAGS}" CACHE STRING "User-chosen compiler flags.") -endif() - -if(AUSAN) - set(DFLAGS "${DFLAGS} -ggdb -fsanitize=address -fsanitize=undefined") -endif() - -if(MULTI STREQUAL OPENMP) - if (MSVC) - set(CFLAGS "${CFLAGS} /openmp") - else () - find_package(OpenMP REQUIRED) - set(CFLAGS "${CFLAGS} -fopenmp") - endif () - set(MULTI "OPENMP" CACHE STRING "Multithreading interface") -else() - if(MULTI STREQUAL PTHREAD) - find_package(Threads REQUIRED) - set(CFLAGS "${CFLAGS} -pthread") - set(MULTI "PTHREAD" CACHE STRING "Multithreading interface") - endif() -endif() - -if(PROFL) - set(PFLAGS "-pg -fno-omit-frame-pointer") -else() - set(PFLAGS "") -endif() - -if(ARITH STREQUAL "gmp" OR ARITH STREQUAL "gmp-sec") - include(cmake/gmp.cmake) - if(GMP_FOUND) - include_directories(${GMP_INCLUDE_DIR}) - set(ARITH_LIBS ${GMP_LIBRARIES}) - endif() -endif() - -if(ARITH STREQUAL "fiat") - message(STATUS "Configured Fiat-Crypto: After build completes, set FIAT_CRYPTO to root folder and run: make fiat; cmake; make.") -endif() - -set(CMAKE_C_FLAGS "${AFLAGS} ${WFLAGS} ${DFLAGS} ${PFLAGS} ${CFLAGS}") -set(CMAKE_EXE_LINKER_FLAGS "${LFLAGS}") - -message(STATUS "Compiler flags: ${CMAKE_C_FLAGS}") -message(STATUS "Linker flags: ${CMAKE_EXE_LINKER_FLAGS}") - -string(TOUPPER ${ARITH} ARITH) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/relic_conf.h.in - ${CMAKE_CURRENT_BINARY_DIR}/include/relic_conf.h @ONLY) -message(STATUS "Configured ${CMAKE_CURRENT_SOURCE_DIR}/include/relic_conf.h.in") -string(TOLOWER ${ARITH} ARITH) - -if (LABEL) - set(RELIC "relic_${LABEL}") - set(RELIC_S "relic_s_${LABEL}") -else() - set(RELIC "relic") - set(RELIC_S "relic_s") -endif() - -# Choose the arithmetic backend. -set(LABEL "" CACHE STRING "Build label") - -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src) - -file(GLOB includes "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h") -install(FILES ${includes} DESTINATION include/${RELIC}) -file(GLOB includes "${CMAKE_CURRENT_SOURCE_DIR}/include/low/*.h") -install(FILES ${includes} DESTINATION include/${RELIC}/low) -install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include/" DESTINATION include/${RELIC}) - -install(FILES cmake/relic-config.cmake DESTINATION cmake/) - -if(DOCUM) - include(cmake/doxygen.cmake) -endif() - -if(TESTS GREATER 0) - enable_testing() - add_subdirectory(test) -endif(TESTS GREATER 0) - -if(BENCH GREATER 0) - add_subdirectory(bench) -endif(BENCH GREATER 0) diff --git a/src/dashbls/depends/relic/COPYRIGHT b/src/dashbls/depends/relic/COPYRIGHT deleted file mode 100644 index bf950c2b0ad3..000000000000 --- a/src/dashbls/depends/relic/COPYRIGHT +++ /dev/null @@ -1,11 +0,0 @@ -RELIC Authors: - -Diego de Freitas Aranha dfaranha at gmail com -Conrado Porto Lopes Gouvêa conradoplg at gmail com -Tobias Markmann tmarkmann at gmail com -Riad S. Wahby rsw at cs stanford edu -Kevin Liao kevliao at mit edu - -RELIC logo: - -Fernanda Alcântara Andaló fernanda@andalo.net.br diff --git a/src/dashbls/depends/relic/LICENSE b/src/dashbls/depends/relic/LICENSE deleted file mode 100644 index d5e3877071e9..000000000000 --- a/src/dashbls/depends/relic/LICENSE +++ /dev/null @@ -1 +0,0 @@ -Apache-2.0 OR LGPL-2.1 diff --git a/src/dashbls/depends/relic/LICENSE.Apache-2.0 b/src/dashbls/depends/relic/LICENSE.Apache-2.0 deleted file mode 100644 index d64569567334..000000000000 --- a/src/dashbls/depends/relic/LICENSE.Apache-2.0 +++ /dev/null @@ -1,202 +0,0 @@ - - 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 - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/src/dashbls/depends/relic/LICENSE.LGPL-2.1 b/src/dashbls/depends/relic/LICENSE.LGPL-2.1 deleted file mode 100644 index e8555423924e..000000000000 --- a/src/dashbls/depends/relic/LICENSE.LGPL-2.1 +++ /dev/null @@ -1,520 +0,0 @@ -RELIC is licensed under the GNU Lesser General Public License (LGPL), with -the following exceptions/clarifications: - - 1. Making modifications to RELIC configuration files, build scripts and - configuration headers such as "relic_conf.h" in order to create a - customized build setup of RELIC with the otherwise unmodified source code, - does not constitute a derived work. - 2. Statically linking the RELIC library into a user application does not - make the user application a derived work, and therefore does not require - the user to distribute the source code or object code of their own - application. The RELIC source code with all modifications must still be - passed on in the same way as using RELIC as a shared library. - 3. Using source code obfuscation on the RELIC source code when distributing - it is not permitted. - -These exceptions/clarifications shall be deemed to amend the base LGPL text, -as reproduced below. - - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! diff --git a/src/dashbls/depends/relic/README.md b/src/dashbls/depends/relic/README.md deleted file mode 100644 index 9fa6d01b2756..000000000000 --- a/src/dashbls/depends/relic/README.md +++ /dev/null @@ -1,66 +0,0 @@ -![](https://github.com/relic-toolkit/relic/blob/master/art/rlc_logo.png) -===== - -[![Project stats](https://www.openhub.net/p/relic-toolkit/widgets/project_thin_badge.gif)](https://www.openhub.net/p/relic-toolkit) -[![Code Quality: Cpp](https://img.shields.io/lgtm/grade/cpp/g/relic-toolkit/relic.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/relic-toolkit/relic/context:cpp) -[![Total Alerts](https://img.shields.io/lgtm/alerts/g/relic-toolkit/relic.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/relic-toolkit/relic/alerts) - -[![Travis Status](https://travis-ci.org/relic-toolkit/relic.svg?branch=main)](https://travis-ci.org/relic-toolkit/relic) -[![GHA Status](https://github.com/relic-toolkit/relic/actions/workflows/easy.yml/badge.svg)](https://github.com/relic-toolkit/relic/actions/workflows/easy.yml) -[![GHA Status](https://github.com/relic-toolkit/relic/actions/workflows/gmp.yml/badge.svg)](https://github.com/relic-toolkit/relic/actions/workflows/gmp.yml) -[![GHA Status](https://github.com/relic-toolkit/relic/actions/workflows/bls12-381.yml/badge.svg)](https://github.com/relic-toolkit/relic/actions/workflows/bls12-381.yml) - - -RELIC is a modern research-oriented cryptographic meta-toolkit with emphasis on efficiency and flexibility. RELIC can be used to build efficient and usable cryptographic toolkits tailored for specific security levels and algorithmic choices. - -### Goals - -RELIC is an ongoing project and features will be added on demand. The focus is to provide: - - * Ease of portability and inclusion of architecture-dependent code - * Simple experimentation with alternative implementations - * Tests and benchmarks for every implemented function - * Flexible configuration - * Maximum efficiency - -### Algorithms - -RELIC implements to date: - - * Multiple-precision integer arithmetic - * Prime and Binary field arithmetic - * Elliptic curves over prime and binary fields (NIST curves and pairing-friendly curves) - * Bilinear maps and related extension fields - * Cryptographic protocols (RSA, Rabin, ECDSA, ECMQV, ECSS (Schnorr), ECIES, Sakai-Ohgishi-Kasahara ID-based authenticated key agreement, Boneh-Lynn-Schacham and Boneh-Boyen short signatures, Paillier and Benaloh homomorphic encryption systems) - -### Citing - -If you use RELIC, please cite using the template below: - - @misc{relic-toolkit, - author = {D. F. Aranha and C. P. L. Gouvêa and T. Markmann and R. S. Wahby and K. Liao}, - title = {{RELIC is an Efficient LIbrary for Cryptography}}, - howpublished = {\url{https://github.com/relic-toolkit/relic}}, - } - -### Build instructions - -Instructions for building the library can be found in the [Wiki](https://github.com/relic-toolkit/relic/wiki/Building). - -### Support - -You can probably get some help over the official mailing list at `relic-discuss@googlegroups.com` - -If you like the library, please consider supporting development through [Paypal](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=R7D6ZE3BLMTF2&lc=BR&item_name=RELIC%20Development¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted). - -### Licensing - -This work is dual-licensed under Apache 2.0 and LGPL 2.1-or-above to encourage collaboration with other research groups and contributions from the industry. You can choose between one of them if you use this work. - -`SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1` - -Starting from version 0.3.3, static linking and changes in the configuration or build system are explicitly exempted from representing derived works. Please refer to the LICENSE files for additional details. - -### Disclaimer - -RELIC is at most alpha-quality software. Implementations may not be correct or secure and may include patented algorithms. There are *many* configuration options which make the library horribly insecure. Backward API compatibility with early versions may not necessarily be maintained. Use at your own risk. diff --git a/src/dashbls/depends/relic/art/rlc_logo.png b/src/dashbls/depends/relic/art/rlc_logo.png deleted file mode 100755 index 4f481be964f9149dc099da88aadcf9e317c1a1ac..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6322 zcmV;j7)|GiP)JIdd-WIq&cNUw;4pd&Z4(Qs&H^ z!?{}4e6WVQE!{)h90Zn%Ebe5{kVQ+^-CWRaGg+F*a-Dv*VB2lrbz`7WfO(K5FnMZn zO#lAT;^vx0yKyR&%2Z!pf1<9gF8|c&Q`uX$ZY>}`)c|z20oRRy zMga!R75w50FV5EKbaM%~Lb~dWR905zoIij5e^$T0`YWE0V|JzacA(AX zuHs_2*|-sG_kWbg*fC?55Dlgi{+|7FJy(3Ki7T!*xvb$)ep*iFt>&WqJ#X4xQBiU5 z(@#IuAIm?MPgWb-ddRfHe5X#GI$o>Q_L8Yh&0bz!4c~nGO~KKlM@y*|Z6Hf?XLKlS za}UzyarWA*R;x|!?(Rp{tXY#!+Gcho(9||S7Cdj>ycdQI9kxISE@MeGx8Zzsm(pbZ zY898#&yUlG2NK|ExWK@`QFG?Z*|&G!-q~BWY}rZf=b9Y=1PzHCl5xi!cMNvqxkhK`7(nfTbsEo^Wm2lygVD)tust%S>0)FU-9Zz+b2gD_)nsB0Z2de zEoBO7NZX(>8ap#m7n)ADd+xa>YRu>{|BaR6`X(+e_dKsLx|8g`a*ZDx*|Gh2jWaW4 z<_Gg%p8p_uxE1yuYGqRkf4to5K=kTz-fZi`19-so=+WZ|!wN%~{ssL6IoE8jG@5F; z^VNAae`fAnT!-sz&ZEWfcu&IPj@so*9zC;{I zAfNB7?gla;2$&hg113@P6wbo`b%^PPCXL#Eme+_7PfyQZEnB)Q3zv5_vF-2gKZJn{ z;_dByS6EosGs#nvw?7#F;CN`c&S)dkXsU>ah+mKfJdPD(Nfq})bz{3u+}}%0oOFNZ zs0!j2BJgMr(9!t_5)dHVdFP!kkWHI9Qp3Q#fCb2o4dWwW;=3g*dS%fYZ@=^QYn+8x zcAX#FP|BUIIKXSafp_4XOa`S|z@m@r|&ha_l9fY$&k+ZjOfczD9Y$!sIj2F^x- zLQ~?b;2da2djb#~ZyX*14RiO588c!xY}oK+M@C;57_bC+WBc>>-nVbxdA}b2YasiK ztGF!qaDOY%bB)cl{Q5WNjofeUO5-AXPrzUZn>}mxjK5_4AOGYmDJzHM z%|ShHT8ICNphN08VVnMVIe%UFh~vkPfA;I$UoYrrjbTf6ozAd=jLARFWbm5JQ|$|F z{{RgZsyjoY`T6_#58)#(CpvT(iNFjIL0nufZ)->B3(B}JO6#09d+1zfMVu2F0_GeY z=%_gb*l`Zxq>rTjh{Mir`rw{6H743B1#ldL!9q;bWMGwCx7HO}t-SuU^md}@`uRs; zF!TT=(-}UR+u*^2`&c`Mj8sR=BpxWt9P_OVg_UHfXm=oi4g|Pxe)xJ=Kqa7a!JEkj z8quf#nwy&&97Yc%A0FBkpiyxzNKhj1G4VSIuKMcr`uhzAL$-JyQ7VZoEu4ZWE?d-X;hu~g{z~x4<;q~gGSL3vv+5sB1ra!i$ePv~3-&R#sK~1d}rLsty{*Ew!Rm>=)^z$Aeu>j-e$p$f{#$Id-_ z_xzJQv(rgWC9Sgfl>V(uXkOI~7ld?<4j?C;2yNgq@wXF4L`O$23j}?n8$TeLz;frzERG0;eCo*zvMmysrk|Y((gj*56AnmHq^Jje?9PcPCGt z96xl((AngE(LP`CImw{lKUclC>JkB+@nG&jP&sGe|Jnka>=6#SV%zmg>EG_x_8F>WkQbEP+%6%EW9@WSWs9NB&}Q`r>sH zCr-@n)vMRTQXmtNt-)l!X(XW7_10T&WkNY}PSpPaTnYF5kPbDLyWKOV6G?ACUr?P{;rZC6V(>JN%iz~88@Wc zUC0@uLU{kn;>Y>5n+|b6(An;ZrIkHDpZi$hnG=vi77iCRRG0Z&m z)KkBS8ymMCkuuu|EqMCs0lsZQKM%+ECT+ZrfEFeg0mZ%d-n;6Zx8Hf_l|`@2Bw)KD z)@*7==?X?Qz=XO|U@np97q+pzbcj7Mo6XF3=`k&NS|R~Wpx8_b2dLF-s8l1zj2ZJZ z(_kz=X)ASvj>Q5H0(27wrt!e@^76VrF)?w+xpU`UqHSrn5Wi48Icf4kqfD+?AZ1oU-8M1qPy>USyFrf)%mE^|~<-gM)*IGmt?`e0=Pg zHuIBW&|!ZZ2l3Q;4*LBwzc-kgOZ;cFSmO=oZO!Mu)&>Yfna^EeQ(?8;#{Aa+w4|QqKldj935` zaRew=*l}>~iQjgYQuj1w^q7fc5O^?<0XWW3C@hLKnM}1tqcM{cWnk>udQ>z>JxB&b zXuQsH#D@u-ZmDZ_W;v6kx}`*tlt$acK!dq-7Gy%O;XF!;R;%SfcKFg}r$DA9)^^h1 zKU&w19Xs~ivHW9soTw~I?QDm`5obUv9zTE|+0JGH;j zMJ7@;V?tgFks&$_6a;)ETb&NAGkw@PMenb{RLgx+Vzdb));>O(CMFeaW2PS<^Q6IP zVNv1657&OU9g5ANV89m0(8+j^tSkm}2mCoiqwtlK?0nEFEV^XGF#I1}6YT)M*3se! zeS;v0WlDt6rIb&`v;iVZF&%-3PM8cA`fLCq>v$#P2+?NZ>#*oIiA1NK0+yp6HQ&&H zs0Lweud1p#zHHgDH_6u;DK5<+n+KC%j0(1b3>pO;4S+%LfRUFR=BJ3C$`iCWA3z4D zJLPC8_xPcU{B^Mou&pQU=_+Cgp!!HU%u*85FQpa8m>|kTv?(P3nvx>bKKNZikX^ri zy`i+U)HvwaU7Jn+hilP3;InM{X)hLH-8SthHruD*qNL6s>3 z2>g_U5FY|S$Ne@TIcy8CxE?f|g*)@-r~Ww$Y^6k8k0vyCw)iM#L@xCpi$1Y22$*TE ztFJ30AbTFog@d1ylk=0-Lt8g#(xgm)t+23glLh6fGP1`-v312Dz&F69bLa|+Q?ZSi(23jnYI*w7{&6^Ps%i8u2a++ICecNV72 zDk>`Wl8=i7MEt{@Gk4C_-FtR_5*ivhe8h+m3Cl8V|vy3cVrR%SIDfJJjXIH+r@G)tlV3t)4jOTu<~~e4Gm>JK0e`Uwfd%qJZR9Mw^L@M6dE@e zcM-5PJ4A2fRX5yZI#xsk$<6>Uph@KbZC;H$1)y?TONTd}0G zRQmutw2xh1tJU@<11pk&4CyqG#}H_@`|i7MZA?rI3TP#h{i?S7tdygrH<<}!0OZtu zS!oF;eIy3ZxSrm20fs;Y`As3n5U_M$Itt--RcUGIAy$vZ0w-Gnt_-G9EFejdkVc2W zRDsyVC)TkYos9%H6VjpA7p5&tT=eRq8RXg*l)531!&>*&gBn_R9Rd5kqSbucumE76 z5db0`2L27iEyTmaBXr8-Dcj&}N!6sO>^a&(u)$yBqdNjPkf~CFh?DtR&Q^Lb^9jI8 zfg0NYcmPc3m)VPo6_!R?Z!b&Yb5CENwK#HZ zIp#B_pR~V-!GLlgv<(XYCZuJui&tB@K%(^qFU?rGo|7nmv}+6bs4lmJ??fTs;IJ2s zYYjMN?ig5{5ojYR^LYbc16oCb*k8B1sLPcxF@Z0J`IOEG{3U1;NN{lQF#M={SVCDi4^Ezqaf`!NuXdD6>^EX)9M@)eLaPW^^(mW9N?b6%`dtNlAPT(+ji)7P)f<1fczK<0l(u9zTBk7$=%5>ad*` zzsv-n!#Y@U)b6v0Q%M29aDLDT9R)JR-9a-eeVm`4U&a3Y`#&lyEG(WibJiQgv zsIBS^v79+`=C7H{Gt&`gk!66;_Y+MtX=SdNHk1?#8BvjQAm^i++L|k5Fr@YB)oY-v zW2q3+d#$**c*nbcdUr8dJ;fKtveJ<+H&jg+z}&CARCm@K=eOrG*sWMt$t0=SWFhTV;g zWtT5s{`=1V-TCMI{Cs|XsI7P9Ivu$%uo)tQZpt$v5zbe?62A?z*&TU(fi)0_3bEF_ zL7NFd20$x3rLH{xcz&9_7Z0o4R4w(_>W>Rdf~@1%3yV3+Y;H4gkV`-M_#;pNUy!A5 za&mHXXh`V2?4Byz~F!tV-?B16kc#8%f-U%Fg+Iq&n$pZ}YzqGaY8XJ@uL z-filhl9DnrdSvuko+QmJaX1+*1_FE*B%OJ)LVP+$0t0}P9gDWWT($>f!V>Vg^X3MT zkDrAPMDRx)a;C3Y|2V^eFo!e2v0uH2{)6{-vryk91G^+E?|GEVT2S~}}EiQ`$Pb=tKZxCZ-& zns(>&6q~*Tu<4JNSpmmKA++4u)@z?yo6H+!;;dYVKL^o@UGa_Jw?)3Fl{^{zF-AY| z@5QKZ;(-I|1Jw*|l^LxNXfGVYD2+}`DgD2b<+)>_5io11a(?Xo$I1Fw7!$H&ll8?C z`{Q-`#pJgioY83Jn(CSwr5Z2Hj|vO_;NaUz#*1eTbp*)p=M$WZ|J0$Y2>}dVSB1zo zK(M*3NEo0rIBPo1TefaFZtY|*jUr%^%#TKeNKzT%nL|qEE%7%#l6b#=F^sk&Rj%p8D6eX0Y$)^8diKVjG;BEE{uZ(PD4PQcfjJdZ9*oKm zf=tPj5__eT$z;M^HFW2Hz9XHAm*FMQ)daF0N3_yP`r8cp8?+NL@aa@zanvLNAUe)M z_!{JxKYCmoJzq98t2iESIoGpCO!j+|p0mncFi>4xWvTs;TWlytr1GN(4A{I+B+7-E z1f@ZSdNtya7 z_34>rDHd#F-*xnNTff;7Jw47~Pg6O>qtX1-#iK`$u4Y;dbc2$@QdUCE)=?ni!y_7C zK$~s;eDmwj+PCOG6ITk%Dku70OnV{^RnW%fI6x9Uf@2 zT)Vws1GpfdK{^6tNQp7u?CjaI>kc0|eDW5eHY%C#MSU~o{HFjE6c{PguR2RX6Ga_+ zrmZTO57)*uQm9rl+5vbRjf7KW0gaCK3mZ3XoL^H@!@tY}#H)Cgwh~|ixZHN0RGjSx zRf1|?W-`mm%m0zNJag$Srp>ksfRaEpQ;I-)RZ`$FA1s~jivYk(O=g@ulSutJ1C4G| zZTO3M^!({|G~~@mS(-@o3J(t-J#X&3wLNcy?xsmf%Zjk!Avqh_WB#I zKf_t3^S5xfr9HHYe|vqkR@r|Bwz~)39X);e^rb;TLBABz4|r({(n)whuq(@_E!2gU zpOObkMwo>tDk}PT>9VDZZiB4rh-8@w1si&50AcQkl%Rf)Pyhe`07*qoM6N<$g5-uE!T - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - toolkit - - - - - - - - - elic - - elic - - elic - - - - R - - R - - R - - - - - elic - elic - - - R - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - toolkit - - - - - - - - - elic - - elic - - elic - - - - R - - R - - R - - - - - elic - elic - - - R - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/dashbls/depends/relic/bench/CMakeLists.txt b/src/dashbls/depends/relic/bench/CMakeLists.txt deleted file mode 100644 index d9e6a46e1375..000000000000 --- a/src/dashbls/depends/relic/bench/CMakeLists.txt +++ /dev/null @@ -1,80 +0,0 @@ -macro(ADD_MODULE MODULE) - add_executable(bench_${MODULE} bench_${MODULE}.c) - if (STLIB) - target_link_libraries(bench_${MODULE} ${RELIC_S}) - else(STLIB) - if (SHLIB) - target_link_libraries(bench_${MODULE} ${RELIC}) - endif(SHLIB) - endif(STLIB) -endmacro(ADD_MODULE) - -if (CHECK) - ADD_MODULE(err) -endif(CHECK) - -if (WITH_BN) - ADD_MODULE(bn) -endif(WITH_BN) - -if (WITH_DV) - ADD_MODULE(dv) -endif(WITH_DV) - -if (WITH_FP) - ADD_MODULE(fp) -endif(WITH_FP) - -if (WITH_FPX) - ADD_MODULE(fpx) -endif(WITH_FPX) - -if (WITH_FB) - ADD_MODULE(fb) -endif(WITH_FB) - -if (WITH_FBX) - ADD_MODULE(fbx) -endif(WITH_FBX) - -if (WITH_EP) - ADD_MODULE(ep) -endif(WITH_EP) - -if (WITH_EPX) - ADD_MODULE(epx) -endif(WITH_EPX) - -if (WITH_EB) - ADD_MODULE(eb) -endif(WITH_EB) - -if (WITH_ED) - ADD_MODULE(ed) -endif (WITH_ED) - -if (WITH_EC) - ADD_MODULE(ec) -endif(WITH_EC) - -if (WITH_PP) - ADD_MODULE(pp) -endif(WITH_PP) - -if (WITH_PC) - ADD_MODULE(pc) -endif(WITH_PC) - -if (WITH_MD) - ADD_MODULE(md) -endif(WITH_MD) - -if (WITH_CP) - ADD_MODULE(cp) -endif(WITH_CP) - -if (WITH_MPC) - ADD_MODULE(mpc) -endif(WITH_MPC) - -ADD_MODULE(rand) diff --git a/src/dashbls/depends/relic/bench/bench_bn.c b/src/dashbls/depends/relic/bench/bench_bn.c deleted file mode 100644 index 5747351ebd67..000000000000 --- a/src/dashbls/depends/relic/bench/bench_bn.c +++ /dev/null @@ -1,943 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2009 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for multiple precision integer arithmetic. - * - * @ingroup bench - */ - -#include "relic.h" -#include "relic_bench.h" - -static void memory(void) { - bn_t a[BENCH]; - - BENCH_FEW("bn_null", bn_null(a[i]), 1); - - BENCH_FEW("bn_new", bn_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - bn_free(a[i]); - } - - BENCH_FEW("bn_new_size", bn_new_size(a[i], 2 * RLC_BN_DIGS), 1); - for (int i = 0; i < BENCH; i++) { - bn_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - bn_new(a[i]); - bn_clean(a[i]); - } - BENCH_FEW("bn_make", bn_make(a[i], RLC_BN_DIGS), 1); - for (int i = 0; i < BENCH; i++) { - bn_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - bn_new(a[i]); - } - BENCH_FEW("bn_clean", bn_clean(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - bn_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - bn_new(a[i]); - } - BENCH_FEW("bn_grow", bn_grow(a[i], 2 * RLC_BN_DIGS), 1); - for (int i = 0; i < BENCH; i++) { - bn_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - bn_new(a[i]); - bn_grow(a[i], 2 * RLC_BN_DIGS); - } - BENCH_FEW("bn_trim", bn_trim(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - bn_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - bn_new(a[i]); - } - BENCH_FEW("bn_free", bn_free(a[i]), 1); - - for (int i = 0; i < BENCH; i++) { - bn_new_size(a[i], 2 * RLC_BN_DIGS); - } - BENCH_FEW("bn_free (size)", bn_free(a[i]), 1); -} - -static void util(void) { - dig_t digit; - char str[RLC_CEIL(RLC_BN_BITS, 8) * 3 + 1]; - uint8_t bin[RLC_CEIL(RLC_BN_BITS, 8)]; - dig_t raw[RLC_BN_DIGS]; - bn_t a, b; - - bn_null(a); - bn_null(b); - - bn_new(a); - bn_new(b); - - bn_rand(b, RLC_POS, RLC_BN_BITS); - - BENCH_RUN("bn_copy") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_copy(b, a)); - } - BENCH_END; - - BENCH_RUN("bn_abs") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_abs(b, a)); - } - BENCH_END; - - BENCH_RUN("bn_neg") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_neg(b, a)); - } - BENCH_END; - - BENCH_RUN("bn_sign") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_sign(a)); - } - BENCH_END; - - BENCH_RUN("bn_zero") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_zero(b)); - } - BENCH_END; - - BENCH_RUN("bn_is_zero") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_is_zero(a)); - } - BENCH_END; - - BENCH_RUN("bn_is_even") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_is_even(a)); - } - BENCH_END; - - BENCH_RUN("bn_bits") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_bits(a)); - } - BENCH_END; - - BENCH_RUN("bn_get_bit") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_get_bit(a, RLC_BN_BITS / 2)); - } - BENCH_END; - - BENCH_RUN("bn_set_bit") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_set_bit(a, RLC_BN_BITS / 2, 1)); - } - BENCH_END; - - BENCH_RUN("bn_ham") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_ham(a)); - } - BENCH_END; - - BENCH_RUN("bn_get_dig") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_get_dig(&digit, a)); - } - BENCH_END; - - BENCH_RUN("bn_set_dig") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_set_dig(a, 1)); - } - BENCH_END; - - BENCH_RUN("bn_set_2b") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_set_2b(a, RLC_BN_BITS / 2)); - } - BENCH_END; - - BENCH_RUN("bn_rand") { - BENCH_ADD(bn_rand(a, RLC_POS, RLC_BN_BITS)); - } - BENCH_END; - - BENCH_RUN("bn_rand_mod") { - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_rand_mod(a, b)); - } - BENCH_END; - - BENCH_RUN("bn_size_str") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_size_str(a, 10)); - } - BENCH_END; - - BENCH_RUN("bn_write_str") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_write_str(str, sizeof(str), a, 10)); - } - BENCH_END; - - BENCH_RUN("bn_read_str") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_read_str(a, str, sizeof(str), 10)); - } - BENCH_END; - - BENCH_RUN("bn_size_bin") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_size_bin(a)); - } - BENCH_END; - - BENCH_RUN("bn_write_bin") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_write_bin(bin, bn_size_bin(a), a)); - } - BENCH_END; - - BENCH_RUN("bn_read_bin") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_read_bin(a, bin, bn_size_bin(a))); - } - BENCH_END; - - BENCH_RUN("bn_size_raw") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_size_raw(a)); - } - BENCH_END; - - BENCH_RUN("bn_write_raw") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_write_raw(raw, bn_size_raw(a), a)); - } - BENCH_END; - - BENCH_RUN("bn_read_raw") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_read_raw(a, raw, bn_size_raw(a))); - } - BENCH_END; - - BENCH_RUN("bn_cmp_abs") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_cmp_abs(b, a)); - } - BENCH_END; - - BENCH_RUN("bn_cmp_dig") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_cmp_dig(a, (dig_t)0)); - } - BENCH_END; - - BENCH_RUN("bn_cmp") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_cmp(b, a)); - } - BENCH_END; - - bn_free(a); - bn_free(b); -} - -static void arith(void) { - bn_t a, b, c, d, e; - dig_t f; - int len; - - bn_null(a); - bn_null(b); - bn_null(c); - bn_null(d); - bn_null(e); - - bn_new(a); - bn_new(b); - bn_new(c); - bn_new(d); - bn_new(e); - - BENCH_RUN("bn_add") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_add(c, a, b)); - } - BENCH_END; - - BENCH_RUN("bn_add_dig") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - bn_get_dig(&f, b); - BENCH_ADD(bn_add_dig(c, a, f)); - } - BENCH_END; - - BENCH_RUN("bn_sub") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_sub(c, a, b)); - } - BENCH_END; - - BENCH_RUN("bn_sub_dig") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - bn_get_dig(&f, b); - BENCH_ADD(bn_sub_dig(c, a, f)); - } - BENCH_END; - - BENCH_RUN("bn_mul") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_mul(c, a, b)); - } - BENCH_END; - - BENCH_RUN("bn_mul_dig") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - bn_get_dig(&f, b); - BENCH_ADD(bn_mul_dig(c, a, f)); - } - BENCH_END; - -#if BN_MUL == BASIC || !defined(STRIP) - BENCH_RUN("bn_mul_basic") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_mul_basic(c, a, b)); - } - BENCH_END; -#endif - -#if BN_MUL == COMBA || !defined(STRIP) - BENCH_RUN("bn_mul_comba") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_mul_comba(c, a, b)); - } - BENCH_END; -#endif - -#if BN_KARAT > 0 || !defined(STRIP) - BENCH_RUN("bn_mul_karat") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_mul_karat(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("bn_sqr") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_sqr(c, a)); - } - BENCH_END; - -#if BN_SQR == BASIC || !defined(STRIP) - BENCH_RUN("bn_sqr_basic") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_sqr_basic(c, a)); - } - BENCH_END; -#endif - -#if BN_SQR == COMBA || !defined(STRIP) - BENCH_RUN("bn_sqr_comba") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_sqr_comba(c, a)); - } - BENCH_END; -#endif - -#if BN_KARAT > 0 || !defined(STRIP) - BENCH_RUN("bn_sqr_karat") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_sqr_karat(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("bn_dbl") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_dbl(c, a)); - } - BENCH_END; - - BENCH_RUN("bn_hlv") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_hlv(c, a)); - } - BENCH_END; - - BENCH_RUN("bn_lsh") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_lsh(c, a, RLC_BN_BITS / 2 + RLC_DIG / 2)); - } - BENCH_END; - - BENCH_RUN("bn_rsh") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_rsh(c, a, RLC_BN_BITS / 2 + RLC_DIG / 2)); - } - BENCH_END; - - BENCH_RUN("bn_div") { - bn_rand(a, RLC_POS, 2 * RLC_BN_BITS - RLC_DIG / 2); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_div(c, a, b)); - } - BENCH_END; - - BENCH_RUN("bn_div_rem") { - bn_rand(a, RLC_POS, 2 * RLC_BN_BITS - RLC_DIG / 2); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_div_rem(c, d, a, b)); - } - BENCH_END; - - BENCH_RUN("bn_div_dig") { - bn_rand(a, RLC_POS, 2 * RLC_BN_BITS - RLC_DIG / 2); - do { - bn_rand(b, RLC_POS, RLC_DIG); - } while (bn_is_zero(b)); - BENCH_ADD(bn_div_dig(c, a, b->dp[0])); - } - BENCH_END; - - BENCH_RUN("bn_div_rem_dig") { - bn_rand(a, RLC_POS, 2 * RLC_BN_BITS - RLC_DIG / 2); - do { - bn_rand(b, RLC_POS, RLC_DIG); - } while (bn_is_zero(b)); - BENCH_ADD(bn_div_rem_dig(c, &f, a, b->dp[0])); - } - BENCH_END; - - BENCH_RUN("bn_mod_2b") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_mod_2b(c, a, RLC_BN_BITS / 2)); - } - BENCH_END; - - BENCH_RUN("bn_mod_dig") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - do { - bn_rand(b, RLC_POS, RLC_DIG); - } while (bn_is_zero(b)); - BENCH_ADD(bn_mod_dig(&f, a, b->dp[0])); - } - BENCH_END; - - BENCH_RUN("bn_mod") { -#if BN_MOD == PMERS - bn_rand(a, RLC_POS, 2 * RLC_BN_BITS - RLC_DIG / 2); - bn_set_2b(b, RLC_BN_BITS); - bn_rand(c, RLC_POS, RLC_DIG); - bn_sub(b, b, c); - bn_mod_pre(d, b); -#else - bn_rand(a, RLC_POS, 2 * RLC_BN_BITS - RLC_DIG / 2); - bn_rand(b, RLC_POS, RLC_BN_BITS); - if (bn_is_even(b)) { - bn_add_dig(b, b, 1); - } - bn_mod_pre(d, b); -#endif - BENCH_ADD(bn_mod(c, a, b, d)); - } - BENCH_END; - -#if BN_MOD == BASIC || !defined(STRIP) - BENCH_RUN("bn_mod_basic") { - bn_rand(a, RLC_POS, 2 * RLC_BN_BITS - RLC_DIG / 2); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_mod_basic(c, a, b)); - } - BENCH_END; -#endif - -#if BN_MOD == BARRT || !defined(STRIP) - BENCH_RUN("bn_mod_pre_barrt") { - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_mod_pre_barrt(d, b)); - } - BENCH_END; -#endif - -#if BN_MOD == BARRT || !defined(STRIP) - BENCH_RUN("bn_mod_barrt") { - bn_rand(a, RLC_POS, 2 * RLC_BN_BITS - RLC_DIG / 2); - bn_rand(b, RLC_POS, RLC_BN_BITS); - bn_mod_pre_barrt(d, b); - BENCH_ADD(bn_mod_barrt(c, a, b, d)); - } - BENCH_END; -#endif - -#if BN_MOD == MONTY || !defined(STRIP) - BENCH_RUN("bn_mod_pre_monty") { - bn_rand(b, RLC_POS, RLC_BN_BITS); - if (bn_is_even(b)) { - bn_add_dig(b, b, 1); - } - BENCH_ADD(bn_mod_pre_monty(d, b)); - } - BENCH_END; - - BENCH_RUN("bn_mod_monty_conv") { - bn_rand(a, RLC_POS, 2 * RLC_BN_BITS - RLC_DIG / 2); - bn_rand(b, RLC_POS, RLC_BN_BITS); - if (bn_is_even(b)) { - bn_add_dig(b, b, 1); - } - bn_mod(a, a, b); - BENCH_ADD(bn_mod_monty_conv(a, a, b)); - } - BENCH_END; - - BENCH_RUN("bn_mod_monty") { - bn_rand(a, RLC_POS, 2 * RLC_BN_BITS - RLC_DIG / 2); - bn_rand(b, RLC_POS, RLC_BN_BITS); - if (bn_is_even(b)) { - bn_add_dig(b, b, 1); - } - bn_mod(a, a, b); - bn_mod_pre_monty(d, b); - BENCH_ADD(bn_mod_monty(c, a, b, d)); - } - BENCH_END; - -#if BN_MUL == BASIC || !defined(STRIP) - BENCH_RUN("bn_mod_monty_basic") { - bn_rand(a, RLC_POS, 2 * RLC_BN_BITS - RLC_DIG / 2); - bn_rand(b, RLC_POS, RLC_BN_BITS); - if (bn_is_even(b)) { - bn_add_dig(b, b, 1); - } - bn_mod(a, a, b); - bn_mod_pre_monty(d, b); - BENCH_ADD(bn_mod_monty_basic(c, a, b, d)); - } - BENCH_END; -#endif - -#if BN_MUL == COMBA || !defined(STRIP) - BENCH_RUN("bn_mod_monty_comba") { - bn_rand(a, RLC_POS, 2 * RLC_BN_BITS - RLC_DIG / 2); - bn_rand(b, RLC_POS, RLC_BN_BITS); - if (bn_is_even(b)) { - bn_add_dig(b, b, 1); - } - bn_mod(a, a, b); - bn_mod_pre_monty(d, b); - BENCH_ADD(bn_mod_monty_comba(c, a, b, d)); - } - BENCH_END; -#endif - - BENCH_RUN("bn_mod_monty_back") { - bn_rand(a, RLC_POS, 2 * RLC_BN_BITS - RLC_DIG / 2); - bn_rand(b, RLC_POS, RLC_BN_BITS); - if (bn_is_even(b)) { - bn_add_dig(b, b, 1); - } - bn_mod(a, a, b); - bn_mod_pre_monty(d, b); - BENCH_ADD(bn_mod_monty_back(c, c, b)); - } - BENCH_END; -#endif - -#if BN_MOD == PMERS || !defined(STRIP) - BENCH_RUN("bn_mod_pre_pmers") { - bn_rand(a, RLC_POS, 2 * RLC_BN_BITS - RLC_DIG / 2); - bn_set_2b(b, RLC_BN_BITS); - bn_rand(c, RLC_POS, RLC_DIG); - bn_sub(b, b, c); - BENCH_ADD(bn_mod_pre_pmers(d, b)); - } - BENCH_END; - - BENCH_RUN("bn_mod_pmers") { - bn_rand(a, RLC_POS, 2 * RLC_BN_BITS - RLC_DIG / 2); - bn_set_2b(b, RLC_BN_BITS); - bn_rand(c, RLC_POS, RLC_DIG); - bn_sub(b, b, c); - bn_mod_pre_pmers(d, b); - BENCH_ADD(bn_mod_pmers(c, a, b, d)); - } - BENCH_END; -#endif - - BENCH_RUN("bn_mxp") { - bn_rand(a, RLC_POS, 2 * RLC_BN_BITS - RLC_DIG / 2); - bn_rand(b, RLC_POS, RLC_BN_BITS); -#if BN_MOD != PMERS - if (bn_is_even(b)) { - bn_add_dig(b, b, 1); - } -#else - bn_set_2b(b, RLC_BN_BITS); - bn_rand(c, RLC_POS, RLC_DIG); - bn_sub(b, b, c); -#endif - bn_mod(a, a, b); - BENCH_ADD(bn_mxp(c, a, b, b)); - } - BENCH_END; - -#if BN_MXP == BASIC || !defined(STRIP) - BENCH_RUN("bn_mxp_basic") { - bn_mod(a, a, b); - BENCH_ADD(bn_mxp_basic(c, a, b, b)); - } - BENCH_END; -#endif - -#if BN_MXP == SLIDE || !defined(STRIP) - BENCH_RUN("bn_mxp_slide") { - bn_rand(a, RLC_POS, 2 * RLC_BN_BITS - RLC_DIG / 2); - bn_mod(a, a, b); - BENCH_ADD(bn_mxp_slide(c, a, b, b)); - } - BENCH_END; -#endif - -#if BN_MXP == CONST || !defined(STRIP) - BENCH_RUN("bn_mxp_monty") { - bn_rand(a, RLC_POS, 2 * RLC_BN_BITS - RLC_DIG / 2); - bn_mod(a, a, b); - BENCH_ADD(bn_mxp_monty(c, a, b, b)); - } - BENCH_END; -#endif - - BENCH_RUN("bn_mxp_dig") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(d, RLC_POS, RLC_DIG); - bn_get_dig(&f, d); - BENCH_ADD(bn_mxp_dig(c, a, f, b)); - } - BENCH_END; - - BENCH_RUN("bn_srt") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_srt(b, a)); - } - BENCH_END; - - BENCH_RUN("bn_gcd") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_gcd(c, a, b)); - } - BENCH_END; - -#if BN_GCD == BASIC || !defined(STRIP) - BENCH_RUN("bn_gcd_basic") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_gcd_basic(c, a, b)); - } - BENCH_END; -#endif - -#if BN_GCD == LEHME || !defined(STRIP) - BENCH_RUN("bn_gcd_lehme") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_gcd_lehme(c, a, b)); - } - BENCH_END; -#endif - -#if BN_GCD == STEIN || !defined(STRIP) - BENCH_RUN("bn_gcd_stein") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_gcd_stein(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("bn_gcd_dig") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_DIG); - bn_get_dig(&f, b); - BENCH_ADD(bn_gcd_dig(c, a, f)); - } - BENCH_END; - - BENCH_RUN("bn_gcd_ext") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_gcd_ext(c, d, e, a, b)); - } - BENCH_END; - -#if BN_GCD == BASIC || !defined(STRIP) - BENCH_RUN("bn_gcd_ext_basic") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_gcd_ext_basic(c, d, e, a, b)); - } - BENCH_END; -#endif - -#if BN_GCD == LEHME || !defined(STRIP) - BENCH_RUN("bn_gcd_ext_lehme") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_gcd_ext_lehme(c, d, e, a, b)); - } - BENCH_END; -#endif - -#if BN_GCD == STEIN || !defined(STRIP) - BENCH_RUN("bn_gcd_ext_stein") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_gcd_ext_stein(c, d, e, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("bn_gcd_ext_mid") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_gcd_ext_mid(c, c, d, d, a, b)); - } - BENCH_END; - - BENCH_RUN("bn_gcd_ext_dig") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_DIG); - BENCH_ADD(bn_gcd_ext_dig(c, d, e, a, b->dp[0])); - } - BENCH_END; - - BENCH_RUN("bn_lcm") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_lcm(c, a, b)); - } - BENCH_END; - - bn_gen_prime(b, RLC_BN_BITS); - - BENCH_RUN("bn_smb_leg") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_smb_leg(c, a, b)); - } - BENCH_END; - - BENCH_RUN("bn_smb_jac") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - if (bn_is_even(b)) { - bn_add_dig(b, b, 1); - } - BENCH_ADD(bn_smb_jac(c, a, b)); - } - BENCH_END; - - BENCH_ONE("bn_gen_prime", bn_gen_prime(a, RLC_BN_BITS), 1); - -#if BN_GEN == BASIC || !defined(STRIP) - BENCH_ONE("bn_gen_prime_basic", bn_gen_prime_basic(a, RLC_BN_BITS), 1); -#endif - -#if BN_GEN == SAFEP || !defined(STRIP) - BENCH_ONE("bn_gen_prime_safep", bn_gen_prime_safep(a, RLC_BN_BITS), 1); -#endif - -#if BN_GEN == STRON || !defined(STRIP) - BENCH_ONE("bn_gen_prime_stron", bn_gen_prime_stron(a, RLC_BN_BITS), 1); -#endif - - BENCH_ONE("bn_is_prime", bn_is_prime(a), 1); - - BENCH_ONE("bn_is_prime_basic", bn_is_prime_basic(a), 1); - - BENCH_ONE("bn_is_prime_rabin", bn_is_prime_rabin(a), 1); - - BENCH_ONE("bn_is_prime_solov", bn_is_prime_solov(a), 1); - - /* It should be the case that a is prime here. */ - BENCH_RUN("bn_mod_inv") { - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_mod_inv(c, b, a)); - } - BENCH_END; - - bn_rand(a, RLC_POS, RLC_BN_BITS); - - BENCH_ONE("bn_factor", bn_factor(c, a), 1); - - BENCH_RUN("bn_is_factor") { - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD(bn_is_factor(b, a)); - } - BENCH_END; - - BENCH_RUN("bn_rec_win") { - uint8_t win[RLC_BN_BITS + 1]; - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD((len = RLC_BN_BITS + 1, bn_rec_win(win, &len, a, 4))); - } - BENCH_END; - - BENCH_RUN("bn_rec_slw") { - uint8_t win[RLC_BN_BITS + 1]; - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD((len = RLC_BN_BITS + 1, bn_rec_slw(win, &len, a, 4))); - } - BENCH_END; - - BENCH_RUN("bn_rec_naf") { - int8_t naf[RLC_BN_BITS + 1]; - int len; - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD((len = RLC_BN_BITS + 1, bn_rec_naf(naf, &len, a, 4))); - } - BENCH_END; - -#if defined(WITH_EB) && defined(EB_KBLTZ) && (EB_MUL == LWNAF || EB_MUL == RWNAF || EB_FIX == LWNAF || EB_SIM == INTER || !defined(STRIP)) - if (eb_param_set_any_kbltz() == RLC_OK) { - BENCH_RUN("bn_rec_tnaf") { - int8_t tnaf[RLC_FB_BITS + 8]; - int len = RLC_BN_BITS + 1; - eb_curve_get_ord(e); - bn_rand_mod(a, e); - if (eb_curve_opt_a() == RLC_ZERO) { - BENCH_ADD((len = RLC_FB_BITS + 8, bn_rec_tnaf(tnaf, &len, a, -1, RLC_FB_BITS, 4))); - } else { - BENCH_ADD((len = RLC_FB_BITS + 8, bn_rec_tnaf(tnaf, &len, a, 1, RLC_FB_BITS, 4))); - } - } - BENCH_END; - - BENCH_RUN("bn_rec_rtnaf") { - int8_t tnaf[RLC_FB_BITS + 8]; - eb_curve_get_ord(e); - bn_rand_mod(a, e); - if (eb_curve_opt_a() == RLC_ZERO) { - BENCH_ADD((len = RLC_FB_BITS + 8, bn_rec_rtnaf(tnaf, &len, a, -1, RLC_FB_BITS, 4))); - } else { - BENCH_ADD((len = RLC_FB_BITS + 8, bn_rec_rtnaf(tnaf, &len, a, 1, RLC_FB_BITS, 4))); - } - } - BENCH_END; - } -#endif - - BENCH_RUN("bn_rec_reg") { - int8_t naf[RLC_BN_BITS + 1]; - int len = RLC_BN_BITS + 1; - bn_rand(a, RLC_POS, RLC_BN_BITS); - BENCH_ADD((len = RLC_BN_BITS + 1, bn_rec_reg(naf, &len, a, RLC_BN_BITS, 4))); - } - BENCH_END; - - BENCH_RUN("bn_rec_jsf") { - int8_t jsf[2 * (RLC_BN_BITS + 1)]; - bn_rand(a, RLC_POS, RLC_BN_BITS); - bn_rand(b, RLC_POS, RLC_BN_BITS); - BENCH_ADD((len = 2 * (RLC_BN_BITS + 1), bn_rec_jsf(jsf, &len, a, b))); - } - BENCH_END; - -#if defined(WITH_EP) && defined(EP_ENDOM) && (EP_MUL == LWNAF || EP_FIX == COMBS || EP_FIX == LWNAF || EP_SIM == INTER || !defined(STRIP)) - if (ep_param_set_any_endom() == RLC_OK) { - bn_t v1[3], v2[3]; - - for (int j = 0; j < 3; j++) { - bn_new(v1[j]); - bn_new(v2[j]); - } - - BENCH_RUN("bn_rec_glv") { - bn_rand(a, RLC_POS, RLC_FP_BITS); - ep_curve_get_v1(v1); - ep_curve_get_v2(v2); - ep_curve_get_ord(e); - bn_rand_mod(a, e); - BENCH_ADD(bn_rec_glv(b, c, a, e, (const bn_t *)v1, - (const bn_t *)v2)); - } - BENCH_END; - - for (int j = 0; j < 3; j++) { - bn_free(v1[j]); - bn_free(v2[j]); - } - } -#endif /* WITH_EP && EP_KBLTZ */ - - bn_free(a); - bn_free(b); - bn_free(c); - bn_free(d); - bn_free(e); -} - -int main(void) { - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - conf_print(); - util_banner("Benchmarks for the BN module:", 0); - util_banner("Utilities:", 1); - memory(); - util(); - util_banner("Arithmetic:", 1); - arith(); - - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/bench/bench_cp.c b/src/dashbls/depends/relic/bench/bench_cp.c deleted file mode 100644 index 621df803f316..000000000000 --- a/src/dashbls/depends/relic/bench/bench_cp.c +++ /dev/null @@ -1,1809 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2009 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for cryptographic protocols. - * - * @version $Id$ - * @ingroup bench - */ - -#include - -#include "relic.h" -#include "relic_bench.h" - -#if defined(WITH_BN) - -static void rsa(void) { - rsa_t pub, prv; - uint8_t in[10], new[10], h[RLC_MD_LEN], out[RLC_BN_BITS / 8 + 1]; - int out_len, new_len; - - rsa_null(pub); - rsa_null(prv); - - rsa_new(pub); - rsa_new(prv); - - BENCH_ONE("cp_rsa_gen", cp_rsa_gen(pub, prv, RLC_BN_BITS), 1); - - BENCH_RUN("cp_rsa_enc") { - out_len = RLC_BN_BITS / 8 + 1; - new_len = out_len; - rand_bytes(in, sizeof(in)); - BENCH_ADD(cp_rsa_enc(out, &out_len, in, sizeof(in), pub)); - cp_rsa_dec(new, &new_len, out, out_len, prv); - } BENCH_END; - - BENCH_RUN("cp_rsa_dec") { - out_len = RLC_BN_BITS / 8 + 1; - new_len = out_len; - rand_bytes(in, sizeof(in)); - cp_rsa_enc(out, &out_len, in, sizeof(in), pub); - BENCH_ADD(cp_rsa_dec(new, &new_len, out, out_len, prv)); - } BENCH_END; - - BENCH_RUN("cp_rsa_sig (h = 0)") { - out_len = RLC_BN_BITS / 8 + 1; - new_len = out_len; - rand_bytes(in, sizeof(in)); - BENCH_ADD(cp_rsa_sig(out, &out_len, in, sizeof(in), 0, prv)); - } BENCH_END; - - BENCH_RUN("cp_rsa_sig (h = 1)") { - out_len = RLC_BN_BITS / 8 + 1; - new_len = out_len; - rand_bytes(in, sizeof(in)); - md_map(h, in, sizeof(in)); - BENCH_ADD(cp_rsa_sig(out, &out_len, h, RLC_MD_LEN, 1, prv)); - } BENCH_END; - - BENCH_RUN("cp_rsa_ver (h = 0)") { - out_len = RLC_BN_BITS / 8 + 1; - new_len = out_len; - rand_bytes(in, sizeof(in)); - cp_rsa_sig(out, &out_len, in, sizeof(in), 0, prv); - BENCH_ADD(cp_rsa_ver(out, out_len, in, sizeof(in), 0, pub)); - } BENCH_END; - - BENCH_RUN("cp_rsa_ver (h = 1)") { - out_len = RLC_BN_BITS / 8 + 1; - new_len = out_len; - rand_bytes(in, sizeof(in)); - md_map(h, in, sizeof(in)); - cp_rsa_sig(out, &out_len, h, RLC_MD_LEN, 1, prv); - BENCH_ADD(cp_rsa_ver(out, out_len, h, RLC_MD_LEN, 1, pub)); - } BENCH_END; - - rsa_free(pub); - rsa_free(prv); -} - -static void rabin(void) { - rabin_t pub, prv; - uint8_t in[1000], new[1000], out[RLC_BN_BITS / 8 + 1]; - int in_len, out_len, new_len; - - rabin_null(pub); - rabin_null(prv); - - rabin_new(pub); - rabin_new(prv); - - BENCH_ONE("cp_rabin_gen", cp_rabin_gen(pub, prv, RLC_BN_BITS), 1); - - BENCH_RUN("cp_rabin_enc") { - in_len = bn_size_bin(pub->n) - 9; - out_len = RLC_BN_BITS / 8 + 1; - rand_bytes(in, in_len); - BENCH_ADD(cp_rabin_enc(out, &out_len, in, in_len, pub)); - cp_rabin_dec(new, &new_len, out, out_len, prv); - } BENCH_END; - - BENCH_RUN("cp_rabin_dec") { - in_len = bn_size_bin(pub->n) - 9; - new_len = in_len; - out_len = RLC_BN_BITS / 8 + 1; - rand_bytes(in, in_len); - cp_rabin_enc(out, &out_len, in, in_len, pub); - BENCH_ADD(cp_rabin_dec(new, &new_len, out, out_len, prv)); - } BENCH_END; - - rabin_free(pub); - rabin_free(prv); -} - -static void benaloh(void) { - bdpe_t pub, prv; - dig_t in, new; - uint8_t out[RLC_BN_BITS / 8 + 1]; - int out_len; - - bdpe_null(pub); - bdpe_null(prv); - - bdpe_new(pub); - bdpe_new(prv); - - BENCH_ONE("cp_bdpe_gen", cp_bdpe_gen(pub, prv, bn_get_prime(47), - RLC_BN_BITS), 1); - - BENCH_RUN("cp_bdpe_enc") { - out_len = RLC_BN_BITS / 8 + 1; - rand_bytes(out, 1); - in = out[0] % bn_get_prime(47); - BENCH_ADD(cp_bdpe_enc(out, &out_len, in, pub)); - cp_bdpe_dec(&new, out, out_len, prv); - } BENCH_END; - - BENCH_RUN("cp_bdpe_dec") { - out_len = RLC_BN_BITS / 8 + 1; - rand_bytes(out, 1); - in = out[0] % bn_get_prime(47); - cp_bdpe_enc(out, &out_len, in, pub); - BENCH_ADD(cp_bdpe_dec(&new, out, out_len, prv)); - } BENCH_END; - - bdpe_free(pub); - bdpe_free(prv); -} - -static void paillier(void) { - bn_t c, m, pub; - phpe_t prv; - - bn_null(c); - bn_null(m); - bn_null(pub); - phpe_null(prv); - - bn_new(c); - bn_new(m); - bn_new(pub); - phpe_new(prv); - - BENCH_ONE("cp_phpe_gen", cp_phpe_gen(pub, prv, RLC_BN_BITS / 2), 1); - - BENCH_RUN("cp_phpe_enc") { - bn_rand_mod(m, pub); - BENCH_ADD(cp_phpe_enc(c, m, pub)); - } BENCH_END; - - BENCH_RUN("cp_phpe_dec") { - bn_rand_mod(m, pub); - cp_phpe_enc(c, m, pub); - BENCH_ADD(cp_phpe_dec(m, c, prv)); - } BENCH_END; - - BENCH_ONE("cp_ghpe_gen", cp_ghpe_gen(pub, prv->n, RLC_BN_BITS / 2), 1); - - BENCH_RUN("cp_ghpe_enc (1)") { - bn_rand_mod(m, pub); - BENCH_ADD(cp_ghpe_enc(c, m, pub, 1)); - } BENCH_END; - - BENCH_RUN("cp_ghpe_dec (1)") { - bn_rand_mod(m, pub); - cp_ghpe_enc(m, c, pub, 1); - BENCH_ADD(cp_ghpe_dec(c, m, pub, prv->n, 1)); - } BENCH_END; - - BENCH_ONE("cp_ghpe_gen", cp_ghpe_gen(pub, prv->n, RLC_BN_BITS / 4), 1); - - BENCH_RUN("cp_ghpe_enc (2)") { - bn_rand(m, RLC_POS, 2 * bn_bits(pub) - 1); - BENCH_ADD(cp_ghpe_enc(m, c, pub, 2)); - } BENCH_END; - - BENCH_RUN("cp_ghpe_dec (2)") { - bn_rand(m, RLC_POS, 2 * bn_bits(pub) - 1); - cp_ghpe_enc(m, c, pub, 2); - BENCH_ADD(cp_ghpe_dec(c, m, pub, prv->n, 2)); - } BENCH_END; - - bn_free(c); - bn_free(m); - bn_free(pub); - phpe_free(prv); -} - -#endif - -#if defined(WITH_EC) - -static void ecdh(void) { - bn_t d; - ec_t p; - uint8_t key[RLC_MD_LEN]; - - bn_null(d); - ec_null(p); - - bn_new(d); - ec_new(p); - - BENCH_RUN("cp_ecdh_gen") { - BENCH_ADD(cp_ecdh_gen(d, p)); - } - BENCH_END; - - BENCH_RUN("cp_ecdh_key") { - BENCH_ADD(cp_ecdh_key(key, RLC_MD_LEN, d, p)); - } - BENCH_END; - - bn_free(d); - ec_free(p); -} - -static void ecmqv(void) { - bn_t d1, d2; - ec_t p1, p2; - uint8_t key[RLC_MD_LEN]; - - bn_null(d1); - bn_null(d2); - ec_null(p1); - ec_null(p2); - - bn_new(d1); - bn_new(d2); - ec_new(p1); - ec_new(p2); - - BENCH_RUN("cp_ecmqv_gen") { - BENCH_ADD(cp_ecmqv_gen(d1, p1)); - } - BENCH_END; - - cp_ecmqv_gen(d2, p2); - - BENCH_RUN("cp_ecmqv_key") { - BENCH_ADD(cp_ecmqv_key(key, RLC_MD_LEN, d1, d2, p1, p1, p2)); - } - BENCH_END; - - bn_free(d1); - bn_free(d2); - ec_free(p1); - ec_free(p2); -} - -static void ecies(void) { - ec_t q, r; - bn_t d; - uint8_t in[10], out[16 + RLC_MD_LEN]; - int in_len, out_len; - - bn_null(d); - ec_null(q); - ec_null(r); - - ec_new(q); - ec_new(r); - bn_new(d); - - BENCH_RUN("cp_ecies_gen") { - BENCH_ADD(cp_ecies_gen(d, q)); - } - BENCH_END; - - BENCH_RUN("cp_ecies_enc") { - in_len = sizeof(in); - out_len = sizeof(out); - rand_bytes(in, sizeof(in)); - BENCH_ADD(cp_ecies_enc(r, out, &out_len, in, in_len, q)); - cp_ecies_dec(out, &out_len, r, out, out_len, d); - } - BENCH_END; - - BENCH_RUN("cp_ecies_dec") { - in_len = sizeof(in); - out_len = sizeof(out); - rand_bytes(in, sizeof(in)); - cp_ecies_enc(r, out, &out_len, in, in_len, q); - BENCH_ADD(cp_ecies_dec(in, &in_len, r, out, out_len, d)); - } - BENCH_END; - - ec_free(q); - ec_free(r); - bn_free(d); -} - -static void ecdsa(void) { - uint8_t msg[5] = { 0, 1, 2, 3, 4 }, h[RLC_MD_LEN]; - bn_t r, s, d; - ec_t p; - - bn_null(r); - bn_null(s); - bn_null(d); - ec_null(p); - - bn_new(r); - bn_new(s); - bn_new(d); - ec_new(p); - - BENCH_RUN("cp_ecdsa_gen") { - BENCH_ADD(cp_ecdsa_gen(d, p)); - } - BENCH_END; - - BENCH_RUN("cp_ecdsa_sign (h = 0)") { - BENCH_ADD(cp_ecdsa_sig(r, s, msg, 5, 0, d)); - } - BENCH_END; - - BENCH_RUN("cp_ecdsa_sign (h = 1)") { - md_map(h, msg, 5); - BENCH_ADD(cp_ecdsa_sig(r, s, h, RLC_MD_LEN, 1, d)); - } - BENCH_END; - - BENCH_RUN("cp_ecdsa_ver (h = 0)") { - BENCH_ADD(cp_ecdsa_ver(r, s, msg, 5, 0, p)); - } - BENCH_END; - - BENCH_RUN("cp_ecdsa_ver (h = 1)") { - md_map(h, msg, 5); - BENCH_ADD(cp_ecdsa_ver(r, s, h, RLC_MD_LEN, 1, p)); - } - BENCH_END; - - bn_free(r); - bn_free(s); - bn_free(d); - ec_free(p); -} - -static void ecss(void) { - uint8_t msg[5] = { 0, 1, 2, 3, 4 }; - bn_t r, s, d; - ec_t p; - - bn_null(r); - bn_null(s); - bn_null(d); - ec_null(p); - - bn_new(r); - bn_new(s); - bn_new(d); - ec_new(p); - - BENCH_RUN("cp_ecss_gen") { - BENCH_ADD(cp_ecss_gen(d, p)); - } - BENCH_END; - - BENCH_RUN("cp_ecss_sign") { - BENCH_ADD(cp_ecss_sig(r, s, msg, 5, d)); - } - BENCH_END; - - BENCH_RUN("cp_ecss_ver") { - BENCH_ADD(cp_ecss_ver(r, s, msg, 5, p)); - } - BENCH_END; - - bn_free(r); - bn_free(s); - bn_free(d); - ec_free(p); -} - -static void vbnn(void) { - uint8_t ida[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - uint8_t idb[] = { 5, 6, 7, 8, 9, 0, 1, 2, 3, 4 }; - bn_t msk, ska, skb; - ec_t mpk, pka, pkb; - - uint8_t m[] = "Thrice the brinded cat hath mew'd."; - - ec_t r; - bn_t z; - bn_t h; - - bn_null(z); - bn_null(h); - bn_null(msk); - bn_null(ska); - bn_null(skb); - ec_null(r); - ec_null(mpk); - bn_null(pka); - bn_null(pkb); - - bn_new(z); - bn_new(h); - bn_new(msk); - bn_new(ska); - bn_new(skb); - ec_new(r); - ec_new(mpk); - ec_new(pka); - ec_new(pkb); - - BENCH_RUN("cp_vbnn_gen") { - BENCH_ADD(cp_vbnn_gen(msk, mpk)); - } - BENCH_END; - - BENCH_RUN("cp_vbnn_gen_prv") { - BENCH_ADD(cp_vbnn_gen_prv(ska, pka, msk, ida, sizeof(ida))); - } - BENCH_END; - - cp_vbnn_gen_prv(skb, pkb, msk, idb, sizeof(idb)); - - BENCH_RUN("cp_vbnn_sig") { - BENCH_ADD(cp_vbnn_sig(r, z, h, ida, sizeof(ida), m, sizeof(m), ska, pka)); - } - BENCH_END; - - BENCH_RUN("cp_vbnn_ver") { - BENCH_ADD(cp_vbnn_ver(r, z, h, ida, sizeof(ida), m, sizeof(m), mpk)); - } - BENCH_END; - - bn_free(z); - bn_free(h); - bn_free(msk); - bn_free(ska); - bn_free(skb); - ec_free(r); - ec_free(mpk); - ec_free(pka); - ec_free(pkb); -} - -#define MAX_KEYS RLC_MAX(BENCH, 16) -#define MIN_KEYS RLC_MIN(BENCH, 16) - -static void ers(void) { - int size; - ec_t pp, pk[MAX_KEYS + 1]; - bn_t sk[MAX_KEYS + 1], td; - ers_t ring[MAX_KEYS + 1]; - uint8_t m[5] = { 0, 1, 2, 3, 4 }; - - bn_null(td); - ec_null(pp); - - bn_new(td); - ec_new(pp); - for (int i = 0; i <= MAX_KEYS; i++) { - bn_null(sk[i]); - bn_new(sk[i]); - ec_null(pk[i]); - ec_new(pk[i]); - ers_null(ring[i]); - ers_new(ring[i]); - cp_ers_gen_key(sk[i], pk[i]); - } - - cp_ers_gen(pp); - - BENCH_RUN("cp_ers_sig") { - BENCH_ADD(cp_ers_sig(td, ring[0], m, 5, sk[0], pk[0], pp)); - } BENCH_END; - - BENCH_RUN("cp_ers_ver") { - BENCH_ADD(cp_ers_ver(td, ring, 1, m, 5, pp)); - } BENCH_END; - - size = 1; - BENCH_FEW("cp_ers_ext", cp_ers_ext(td, ring, &size, m, 5, pk[size], pp), 1); - - size = 1; - cp_ers_sig(td, ring[0], m, 5, sk[0], pk[0], pp); - for (int j = 1; j < MAX_KEYS && size < BENCH; j = j << 1) { - for (int k = 0; k < j && size < BENCH; k++) { - cp_ers_ext(td, ring, &size, m, 5, pk[size], pp); - } - cp_ers_ver(td, ring, size, m, 5, pp); - util_print("(%2d exts) ", j); - BENCH_FEW("cp_ers_ver", cp_ers_ver(td, ring, size, m, 5, pp), 1); - } - - bn_free(td); - ec_free(pp); - for (int i = 0; i <= MAX_KEYS; i++) { - bn_free(sk[i]); - ec_free(pk[i]); - ers_free(ring[i]) - } -} - -static void etrs(void) { - int size; - ec_t pp, pk[MAX_KEYS + 1]; - bn_t sk[MAX_KEYS + 1], td[MAX_KEYS + 1], y[MAX_KEYS + 1]; - etrs_t ring[MAX_KEYS + 1]; - uint8_t m[5] = { 0, 1, 2, 3, 4 }; - - ec_null(pp); - ec_new(pp); - for (int i = 0; i <= MAX_KEYS; i++) { - bn_null(td[i]); - bn_new(td[i]); - bn_null(y[i]); - bn_new(y[i]); - bn_null(sk[i]); - bn_new(sk[i]); - ec_null(pk[i]); - ec_new(pk[i]); - etrs_null(ring[i]); - etrs_new(ring[i]); - ec_curve_get_ord(sk[i]); - bn_rand_mod(td[i], sk[i]); - bn_rand_mod(y[i], sk[i]); - cp_etrs_gen_key(sk[i], pk[i]); - } - - cp_etrs_gen(pp); - - BENCH_FEW("cp_etrs_sig", cp_etrs_sig(td, y, MIN_KEYS, ring[0], m, 5, sk[0], pk[0], pp), 1); - - BENCH_FEW("cp_etrs_ver", cp_etrs_ver(1, td, y, MIN_KEYS, ring, 1, m, 5, pp), 1); - - size = 1; - BENCH_FEW("cp_etrs_ext", (size = 1, cp_etrs_ext(td, y, MIN_KEYS, ring, &size, m, 5, pk[size], pp)), 1); - - size = 1; - cp_etrs_sig(td, y, MIN_KEYS, ring[0], m, 5, sk[0], pk[0], pp); - BENCH_FEW("cp_etrs_uni", cp_etrs_uni(1, td, y, MIN_KEYS, ring, &size, m, 5, sk[size], pk[size], pp), 1); - - size = 1; - cp_etrs_sig(td, y, MIN_KEYS, ring[0], m, 5, sk[0], pk[0], pp); - for (int j = 1; j < MIN_KEYS && size < MIN_KEYS; j = j << 1) { - for (int k = 0; k < j && size < MIN_KEYS; k++) { - cp_etrs_ext(td, y, MIN_KEYS, ring, &size, m, 5, pk[size], pp); - } - cp_etrs_ver(1, td+size-1, y+size-1, MIN_KEYS-size+1, ring, size, m, 5, pp); - util_print("(%2d exts) ", j); - BENCH_FEW("cp_etrs_ver", cp_etrs_ver(1, td+size-1, y+size-1, MIN_KEYS-size+1, ring, size, m, 5, pp), 1); - } - - ec_free(pp); - for (int i = 0; i <= MAX_KEYS; i++) { - bn_free(td[i]); - bn_free(y[i]); - bn_free(sk[i]); - ec_free(pk[i]); - etrs_free(ring[i]) - } -} - -#endif /* WITH_EC */ - -#if defined(WITH_PC) - -static void pdpub(void) { - bn_t r1, r2; - g1_t p, u1, v1; - g2_t q, u2, v2, w2; - gt_t e, r, g[3]; - - bn_null(r1); - bn_null(r2); - g1_null(p); - g1_null(u1); - g1_null(v1); - g2_null(q); - g2_null(u2); - g2_null(v2); - g2_null(w2); - gt_null(e); - gt_null(r); - gt_null(g[0]); - gt_null(g[1]); - gt_null(g[2]); - - bn_new(r1); - bn_new(r2); - g1_new(p); - g1_new(u1); - g1_new(v1); - g2_new(q); - g2_new(u2); - g2_new(v2); - g2_new(w2); - gt_new(e); - gt_new(r); - gt_new(g[0]); - gt_new(g[1]); - gt_new(g[2]); - - BENCH_RUN("cp_pdpub_gen") { - BENCH_ADD(cp_pdpub_gen(r1, r2, u1, u2, v2, e)); - } BENCH_END; - - BENCH_RUN("cp_pdpub_ask") { - g1_rand(p); - g2_rand(q); - BENCH_ADD(cp_pdpub_ask(v1, w2, p, q, r1, r2, u1, u2, v2)); - } BENCH_END; - - BENCH_RUN("cp_pdpub_ans") { - g1_rand(p); - g2_rand(q); - BENCH_ADD(cp_pdpub_ans(g, p, q, v1, v2, w2)); - } BENCH_END; - - BENCH_RUN("cp_pdpub_ver") { - g1_rand(p); - g2_rand(q); - pc_map(e, p, q); - BENCH_ADD(cp_pdpub_ver(r, g, r1, e)); - } BENCH_END; - - BENCH_RUN("cp_lvpub_gen") { - BENCH_ADD(cp_lvpub_gen(r2, u1, u2, v2, e)); - } BENCH_END; - - BENCH_RUN("cp_lvpub_ask") { - g1_rand(p); - g2_rand(q); - BENCH_ADD(cp_lvpub_ask(r1, v1, w2, p, q, r2, u1, u2, v2)); - } BENCH_END; - - BENCH_RUN("cp_lvpub_ans") { - g1_rand(p); - g2_rand(q); - BENCH_ADD(cp_lvpub_ans(g, p, q, v1, v2, w2)); - } BENCH_END; - - BENCH_RUN("cp_lvpub_ver") { - g1_rand(p); - g2_rand(q); - pc_map(e, p, q); - BENCH_ADD(cp_lvpub_ver(r, g, r1, e)); - } BENCH_END; - - bn_free(r1); - bn_free(r2); - g1_free(p); - g1_free(u1); - g1_free(v1); - g2_free(q); - g2_free(u2); - g2_free(v2); - g2_free(w2); - gt_free(e); - gt_free(r); - gt_free(g[0]); - gt_free(g[1]); - gt_free(g[2]); -} - -static void pdprv(void) { - bn_t r1, r2[3]; - g1_t p, u1[2], v1[3]; - g2_t q, u2[2], v2[4], w2[4]; - gt_t e[2], r, g[4]; - - bn_null(r1); - g1_null(p); - g2_null(q); - gt_null(r); - for (int i = 0; i < 2; i++) { - g1_null(u1[i]); - g2_null(u2[i]); - gt_null(e[i]); - } - for (int i = 0; i < 3; i++) { - g1_null(v1[i]); - bn_null(r2[i]); - } - for (int i = 0; i < 4; i++) { - g2_null(v2[i]); - g2_null(w2[i]); - gt_null(g[i]); - } - - bn_new(r1); - g1_new(p); - g2_new(q); - gt_new(r); - for (int i = 0; i < 2; i++) { - g1_new(u1[i]); - g2_new(u2[i]); - gt_new(e[i]); - } - for (int i = 0; i < 3; i++) { - g1_new(v1[i]); - bn_new(r2[i]); - } - for (int i = 0; i < 4; i++) { - g2_new(v2[i]); - g2_new(w2[i]); - gt_new(g[i]); - } - - BENCH_RUN("cp_pdprv_gen") { - BENCH_ADD(cp_pdprv_gen(r1, r2, u1, u2, v2, e)); - } BENCH_END; - - BENCH_RUN("cp_pdprv_ask") { - g1_rand(p); - g2_rand(q); - BENCH_ADD(cp_pdprv_ask(v1, w2, p, q, r1, r2, u1, u2, v2)); - } BENCH_END; - - BENCH_RUN("cp_pdprv_ans") { - g1_rand(p); - g2_rand(q); - BENCH_ADD(cp_pdprv_ans(g, v1, w2)); - } BENCH_END; - - BENCH_RUN("cp_pdprv_ver") { - g1_rand(p); - g2_rand(q); - BENCH_ADD(cp_pdprv_ver(r, g, r1, e)); - } BENCH_END; - - BENCH_RUN("cp_lvprv_gen") { - BENCH_ADD(cp_lvprv_gen(r1, r2, u1, u2, v2, e)); - } BENCH_END; - - BENCH_RUN("cp_lvprv_ask") { - g1_rand(p); - g2_rand(q); - BENCH_ADD(cp_lvprv_ask(v1, w2, p, q, r1, r2, u1, u2, v2)); - } BENCH_END; - - BENCH_RUN("cp_lvprv_ans") { - g1_rand(p); - g2_rand(q); - BENCH_ADD(cp_lvprv_ans(g, v1, w2)); - } BENCH_END; - - BENCH_RUN("cp_lvprv_ver") { - g1_rand(p); - g2_rand(q); - BENCH_ADD(cp_lvprv_ver(r, g, r1, e)); - } BENCH_END; - - bn_free(r1); - g1_free(p); - g2_free(q); - gt_free(r); - for (int i = 0; i < 2; i++) { - g1_free(u1[i]); - g2_free(u2[i]); - gt_free(e[i]); - } - for (int i = 0; i < 3; i++) { - g1_free(v1[i]); - bn_free(r2[i]); - } - for (int i = 0; i < 4; i++) { - g2_free(v2[i]); - g2_free(w2[i]); - gt_free(g[i]); - } -} - -static void sokaka(void) { - sokaka_t k; - bn_t s; - uint8_t key1[RLC_MD_LEN]; - char *id_a = "Alice"; - char *id_b = "Bob"; - - sokaka_null(k); - - sokaka_new(k); - bn_new(s); - - BENCH_RUN("cp_sokaka_gen") { - BENCH_ADD(cp_sokaka_gen(s)); - } - BENCH_END; - - BENCH_RUN("cp_sokaka_gen_prv") { - BENCH_ADD(cp_sokaka_gen_prv(k, id_b, s)); - } - BENCH_END; - - BENCH_RUN("cp_sokaka_key (g1)") { - BENCH_ADD(cp_sokaka_key(key1, RLC_MD_LEN, id_b, k, id_a)); - } - BENCH_END; - - if (pc_map_is_type3()) { - cp_sokaka_gen_prv(k, id_a, s); - - BENCH_RUN("cp_sokaka_key (g2)") { - BENCH_ADD(cp_sokaka_key(key1, RLC_MD_LEN, id_a, k, id_b)); - } - BENCH_END; - } - - sokaka_free(k); - bn_free(s); -} - -static void ibe(void) { - bn_t s; - g1_t pub; - g2_t prv; - uint8_t in[10], out[10 + 2 * RLC_FP_BYTES + 1]; - char *id = "Alice"; - int in_len, out_len; - - bn_null(s); - g1_null(pub); - g2_null(prv); - - bn_new(s); - g1_new(pub); - g2_new(prv); - - rand_bytes(in, sizeof(in)); - - BENCH_RUN("cp_ibe_gen") { - BENCH_ADD(cp_ibe_gen(s, pub)); - } - BENCH_END; - - BENCH_RUN("cp_ibe_gen_prv") { - BENCH_ADD(cp_ibe_gen_prv(prv, id, s)); - } - BENCH_END; - - BENCH_RUN("cp_ibe_enc") { - in_len = sizeof(in); - out_len = in_len + 2 * RLC_FP_BYTES + 1; - rand_bytes(in, sizeof(in)); - BENCH_ADD(cp_ibe_enc(out, &out_len, in, in_len, id, pub)); - cp_ibe_dec(out, &out_len, out, out_len, prv); - } - BENCH_END; - - BENCH_RUN("cp_ibe_dec") { - in_len = sizeof(in); - out_len = in_len + 2 * RLC_FP_BYTES + 1; - rand_bytes(in, sizeof(in)); - cp_ibe_enc(out, &out_len, in, in_len, id, pub); - BENCH_ADD(cp_ibe_dec(out, &out_len, out, out_len, prv)); - } - BENCH_END; - - bn_free(s); - g1_free(pub); - g2_free(prv); -} - -static void bgn(void) { - g1_t c[2]; - g2_t d[2]; - gt_t e[4]; - bgn_t pub, prv; - dig_t in; - - g1_null(c[0]); - g1_null(c[1]); - g2_null(d[0]); - g2_null(d[1]); - bgn_null(pub); - bgn_null(prv); - - g1_new(c[0]); - g1_new(c[1]); - g2_new(d[0]); - g2_new(d[1]); - bgn_new(pub); - bgn_new(prv); - for (int i = 0; i < 4; i++) { - gt_null(e[i]); - gt_new(e[i]); - } - - BENCH_RUN("cp_bgn_gen") { - BENCH_ADD(cp_bgn_gen(pub, prv)); - } BENCH_END; - - in = 10; - - BENCH_RUN("cp_bgn_enc1") { - BENCH_ADD(cp_bgn_enc1(c, in, pub)); - cp_bgn_dec1(&in, c, prv); - } BENCH_END; - - BENCH_RUN("cp_bgn_dec1 (10)") { - cp_bgn_enc1(c, in, pub); - BENCH_ADD(cp_bgn_dec1(&in, c, prv)); - } BENCH_END; - - BENCH_RUN("cp_bgn_enc2") { - BENCH_ADD(cp_bgn_enc2(d, in, pub)); - cp_bgn_dec2(&in, d, prv); - } BENCH_END; - - BENCH_RUN("cp_bgn_dec2 (10)") { - cp_bgn_enc2(d, in, pub); - BENCH_ADD(cp_bgn_dec2(&in, d, prv)); - } BENCH_END; - - BENCH_RUN("cp_bgn_mul") { - BENCH_ADD(cp_bgn_mul(e, c, d)); - } BENCH_END; - - BENCH_RUN("cp_bgn_dec (100)") { - BENCH_ADD(cp_bgn_dec(&in, e, prv)); - } BENCH_END; - - BENCH_RUN("cp_bgn_add") { - BENCH_ADD(cp_bgn_add(e, e, e)); - } BENCH_END; - - g1_free(c[0]); - g1_free(c[1]); - g2_free(d[0]); - g2_free(d[1]); - bgn_free(pub); - bgn_free(prv); - for (int i = 0; i < 4; i++) { - gt_free(e[i]); - } -} - -static void bls(void) { - uint8_t msg[5] = { 0, 1, 2, 3, 4 }; - g1_t s; - g2_t p; - bn_t d; - - g1_null(s); - g2_null(p); - bn_null(d); - - g1_new(s); - g2_new(p); - bn_new(d); - - BENCH_RUN("cp_bls_gen") { - BENCH_ADD(cp_bls_gen(d, p)); - } - BENCH_END; - - BENCH_RUN("cp_bls_sign") { - BENCH_ADD(cp_bls_sig(s, msg, 5, d)); - } - BENCH_END; - - BENCH_RUN("cp_bls_ver") { - BENCH_ADD(cp_bls_ver(s, msg, 5, p)); - } - BENCH_END; - - g1_free(s); - bn_free(d); - g2_free(p); -} - -static void bbs(void) { - uint8_t msg[5] = { 0, 1, 2, 3, 4 }, h[RLC_MD_LEN]; - g1_t s; - g2_t p; - gt_t z; - bn_t d; - - g1_null(s); - g2_null(p); - gt_null(z); - bn_null(d); - - g1_new(s); - g2_new(p); - gt_new(z); - bn_new(d); - - BENCH_RUN("cp_bbs_gen") { - BENCH_ADD(cp_bbs_gen(d, p, z)); - } - BENCH_END; - - BENCH_RUN("cp_bbs_sign (h = 0)") { - BENCH_ADD(cp_bbs_sig(s, msg, 5, 0, d)); - } - BENCH_END; - - BENCH_RUN("cp_bbs_sign (h = 1)") { - md_map(h, msg, 5); - BENCH_ADD(cp_bbs_sig(s, h, RLC_MD_LEN, 1, d)); - } - BENCH_END; - - BENCH_RUN("cp_bbs_ver (h = 0)") { - BENCH_ADD(cp_bbs_ver(s, msg, 5, 0, p, z)); - } - BENCH_END; - - BENCH_RUN("cp_bbs_ver (h = 1)") { - md_map(h, msg, 5); - BENCH_ADD(cp_bbs_ver(s, h, RLC_MD_LEN, 1, p, z)); - } - BENCH_END; - - g1_free(s); - bn_free(d); - g2_free(p); -} - -static int cls(void) { - int i, code = RLC_ERR; - bn_t r, t, u, v, _v[4]; - g1_t a, A, b, B, c, _A[4], _B[4]; - g2_t x, y, z, _z[4]; - uint8_t m[5] = { 0, 1, 2, 3, 4 }; - uint8_t *msgs[5] = {m, m, m, m, m}; - int lens[5] = {sizeof(m), sizeof(m), sizeof(m), sizeof(m), sizeof(m)}; - - bn_null(r); - bn_null(t); - bn_null(u); - bn_null(v); - g1_null(a); - g1_null(A); - g1_null(b); - g1_null(B); - g1_null(c); - g2_null(x); - g2_null(y); - g2_null(z); - for (i = 0; i < 4; i++) { - bn_null(_v[i]); - g1_null(_A[i]); - g1_null(_B[i]); - g2_null(_z[i]); - } - - bn_new(r); - bn_new(t); - bn_new(u); - bn_new(v); - g1_new(a); - g1_new(A); - g1_new(b); - g1_new(B); - g1_new(c); - g2_new(x); - g2_new(y); - g2_new(z); - for (i = 0; i < 4; i++) { - bn_new(_v[i]); - g1_new(_A[i]); - g1_new(_B[i]); - g2_new(_z[i]); - } - - BENCH_RUN("cp_cls_gen") { - BENCH_ADD(cp_cls_gen(u, v, x, y)); - } BENCH_END; - - BENCH_RUN("cp_cls_sig") { - BENCH_ADD(cp_cls_sig(a, b, c, m, sizeof(m), u, v)); - } BENCH_END; - - BENCH_RUN("cp_cls_ver") { - BENCH_ADD(cp_cls_ver(a, b, c, m, sizeof(m), x, y)); - } BENCH_END; - - BENCH_RUN("cp_cli_gen") { - BENCH_ADD(cp_cli_gen(t, u, v, x, y, z)); - } BENCH_END; - - bn_rand(r, RLC_POS, 2 * pc_param_level()); - BENCH_RUN("cp_cli_sig") { - BENCH_ADD(cp_cli_sig(a, A, b, B, c, m, sizeof(m), r, t, u, v)); - } BENCH_END; - - BENCH_RUN("cp_cli_ver") { - BENCH_ADD(cp_cli_ver(a, A, b, B, c, m, sizeof(m), r, x, y, z)); - } BENCH_END; - - BENCH_RUN("cp_clb_gen (5)") { - BENCH_ADD(cp_clb_gen(t, u, _v, x, y, _z, 5)); - } BENCH_END; - - BENCH_RUN("cp_clb_sig (5)") { - BENCH_ADD(cp_clb_sig(a, _A, b, _B, c, msgs, lens, t, u, _v, 5)); - } BENCH_END; - - BENCH_RUN("cp_clb_ver (5)") { - BENCH_ADD(cp_clb_ver(a, _A, b, _B, c, msgs, lens, x, y, _z, 5)); - } BENCH_END; - - bn_free(r); - bn_free(t); - bn_free(u); - bn_free(v); - g1_free(a); - g1_free(A); - g1_free(b); - g1_free(B); - g1_free(c); - g2_free(x); - g2_free(y); - g2_free(z); - for (i = 0; i < 4; i++) { - bn_free(_v[i]); - g1_free(_A[i]); - g1_free(_B[i]); - g2_free(_z[i]); - } - return code; -} - -static void pss(void) { - bn_t ms[10], n, u, v, _v[10]; - g1_t a, b; - g2_t g, x, y, _y[10]; - - bn_null(n); - bn_null(u); - bn_null(v); - g1_null(a); - g1_null(b); - g2_null(g); - g2_null(x); - g2_null(y); - bn_new(n); - bn_new(u); - bn_new(v); - g1_new(a); - g1_new(b); - g2_new(g); - g2_new(x); - g2_new(y); - - g1_get_ord(n); - for (int i = 0; i < 10; i++) { - bn_null(ms[i]); - bn_null(_v[i]); - g2_null(_y[i]); - bn_new(ms[i]); - bn_rand_mod(ms[i], n); - bn_new(_v[i]); - g2_new(_y[i]); - } - - BENCH_RUN("cp_pss_gen") { - BENCH_ADD(cp_pss_gen(u, v, g, x, y)); - } BENCH_END; - - BENCH_RUN("cp_pss_sig") { - BENCH_ADD(cp_pss_sig(a, b, ms[0], u, v)); - } BENCH_END; - - BENCH_RUN("cp_pss_ver") { - BENCH_ADD(cp_pss_ver(a, b, ms[0], g, x, y)); - } BENCH_END; - - BENCH_RUN("cp_psb_gen (10)") { - BENCH_ADD(cp_psb_gen(u, _v, g, x, _y, 10)); - } BENCH_END; - - BENCH_RUN("cp_psb_sig (10)") { - BENCH_ADD(cp_psb_sig(a, b, ms, u, _v, 10)); - } BENCH_END; - - BENCH_RUN("cp_psb_ver (10)") { - BENCH_ADD(cp_psb_ver(a, b, ms, g, x, _y, 10)); - } BENCH_END; - - bn_free(u); - bn_free(v); - g1_free(a); - g1_free(b); - g2_free(g); - g2_free(x); - g2_free(y); - for (int i = 0; i < 10; i++) { - bn_free(ms[i]); - bn_free(_v[i]); - g1_free(_y[i]); - } -} - -#ifdef WITH_MPC - -static void mpss(void) { - bn_t m[2], n, u[2], v[2], ms[10][2], _v[10][2]; - g1_t g, s[2]; - g2_t h, x[2], y[2], _y[10][2]; - gt_t r[2]; - mt_t tri[3][2]; - pt_t t[2]; - - bn_null(n); - g1_null(g); - g2_null(h); - - bn_new(n); - g1_new(g); - g2_new(h); - for (int i = 0; i < 2; i++) { - bn_null(m[i]); - bn_null(u[i]); - bn_null(v[i]); - g1_null(s[i]); - g2_null(x[i]); - g2_null(y[i]); - gt_null(r[i]); - mt_null(tri[0][i]); - mt_null(tri[1][i]); - mt_null(tri[2][i]); - pt_null(t[i]); - bn_new(m[i]); - bn_new(u[i]); - bn_new(v[i]); - g1_new(s[i]); - g2_new(x[i]); - g2_new(y[i]); - gt_new(r[i]); - mt_new(tri[0][i]); - mt_new(tri[1][i]); - mt_new(tri[2][i]); - pt_new(t[i]); - - g1_get_ord(n); - for (int j = 0; j < 10; j++) { - bn_null(ms[j][i]); - bn_null(_v[j][i]); - g2_null(_y[j][i]); - bn_new(ms[j][i]); - bn_rand_mod(ms[j][i], n); - bn_new(_v[j][i]); - g2_new(_y[j][i]); - } - } - - pc_map_tri(t); - mt_gen(tri[0], n); - mt_gen(tri[1], n); - mt_gen(tri[2], n); - - bn_rand_mod(m[0], n); - bn_rand_mod(m[1], n); - bn_sub(m[0], m[1], m[0]); - if (bn_sign(m[0]) == RLC_NEG) { - bn_add(m[0], m[0], n); - } - gt_exp_gen(r[0], tri[2][0]->c); - gt_exp_gen(r[1], tri[2][1]->c); - tri[2][0]->bt = &r[0]; - tri[2][1]->bt = &r[1]; - tri[2][0]->ct = &r[0]; - tri[2][1]->ct = &r[1]; - - BENCH_RUN("cp_mpss_gen") { - BENCH_ADD(cp_mpss_gen(u, v, h, x, y)); - } BENCH_END; - - BENCH_RUN("cp_mpss_bct") { - BENCH_ADD(cp_mpss_bct(x, y)); - } BENCH_END; - - BENCH_RUN("cp_mpss_sig") { - BENCH_ADD(cp_mpss_sig(g, s, m, u, v, tri[0], tri[1])); - } BENCH_DIV(2); - - BENCH_RUN("cp_mpss_ver") { - BENCH_ADD(cp_mpss_ver(r[0], g, s, m, h, x[0], y[0], tri[2], t)); - } BENCH_DIV(2); - - g1_get_ord(n); - pc_map_tri(t); - mt_gen(tri[0], n); - mt_gen(tri[1], n); - mt_gen(tri[2], n); - - BENCH_RUN("cp_mpsb_gen (10)") { - BENCH_ADD(cp_mpsb_gen(u, _v, h, x, _y, 10)); - } BENCH_END; - - BENCH_RUN("cp_mpsb_bct (10)") { - BENCH_ADD(cp_mpsb_bct(x, _y, 10)); - } BENCH_END; - - BENCH_RUN("cp_mpsb_sig (10)") { - BENCH_ADD(cp_mpsb_sig(g, s, ms, u, _v, tri[0], tri[1], 10)); - } BENCH_DIV(2); - - BENCH_RUN("cp_mpsb_ver (10)") { - BENCH_ADD(cp_mpsb_ver(r[1], g, s, ms, h, x[0], _y, NULL, tri[2], t, 10)); - } BENCH_DIV(2); - - BENCH_RUN("cp_mpsb_ver (10,sk)") { - BENCH_ADD(cp_mpsb_ver(r[1], g, s, ms, h, x[0], _y, _v, tri[2], t, 10)); - } BENCH_DIV(2); - - bn_free(n); - g1_free(g); - g2_free(h); - for (int i = 0; i < 2; i++) { - bn_free(m[i]); - bn_free(u[i]); - bn_free(v[i]); - g1_free(s[i]); - g2_free(x[i]); - g2_free(y[i]); - gt_null(r[i]); - mt_free(tri[0][i]); - mt_free(tri[1][i]); - mt_free(tri[2][i]); - pt_free(t[i]); - for (int j = 0; j < 10; j++) { - bn_free(ms[j][i]); - bn_free(_v[j][i]); - g2_free(_y[j][i]); - } - } -} - -#endif - -static void zss(void) { - uint8_t msg[5] = { 0, 1, 2, 3, 4 }, h[RLC_MD_LEN]; - g1_t p; - g2_t s; - gt_t z; - bn_t d; - - bn_null(d); - g1_null(p); - g2_null(s); - gt_null(z); - - g1_new(p); - g2_new(s); - gt_new(z); - bn_new(d); - - BENCH_RUN("cp_zss_gen") { - BENCH_ADD(cp_zss_gen(d, p, z)); - } - BENCH_END; - - BENCH_RUN("cp_zss_sign (h = 0)") { - BENCH_ADD(cp_zss_sig(s, msg, 5, 0, d)); - } - BENCH_END; - - BENCH_RUN("cp_zss_sign (h = 1)") { - md_map(h, msg, 5); - BENCH_ADD(cp_zss_sig(s, h, RLC_MD_LEN, 1, d)); - } - BENCH_END; - - BENCH_RUN("cp_zss_ver (h = 0)") { - BENCH_ADD(cp_zss_ver(s, msg, 5, 0, p, z)); - } - BENCH_END; - - BENCH_RUN("cp_zss_ver (h = 1)") { - md_map(h, msg, 5); - BENCH_ADD(cp_zss_ver(s, h, RLC_MD_LEN, 1, p, z)); - } - BENCH_END; - - bn_free(d); - g1_free(p); - g2_free(s); -} - -/* Size of the dataset for benchmarking. */ -#define S 10 /* Number of signers. */ -#define L 16 /* Number of labels, must be <= RLC_TERMS. */ -#define K RLC_MD_LEN /* Size of PRF key. */ -//#define BENCH_LHS /* Uncomment for fine-grained benchmarking. */ - -static void lhs(void) { - uint8_t k[S][K]; - bn_t m, n, msg[L], sk[S], d[S], x[S][L]; - g1_t _r, h, as[S], cs[S], sig[S]; - g1_t a[S][L], c[S][L], r[S][L]; - g2_t _s, s[S][L], pk[S], y[S], z[S]; - gt_t *hs[S], vk; - char *data = "id"; - char *id[S] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}; - dig_t ft[S]; - dig_t *f[S]; - int flen[S]; - - bn_null(m); - bn_null(n); - g1_null(h); - g1_null(_r); - g2_null(_s); - gt_null(vk); - - bn_new(m); - bn_new(n); - g1_new(h); - g1_new(_r); - g2_new(_s); - gt_new(vk); - - pc_get_ord(n); - for (int i = 0; i < L; i++) { - bn_null(msg[i]); - bn_new(msg[i]); - bn_rand_mod(msg[i], n); - } - for (int i = 0; i < S; i++) { - hs[i] = RLC_ALLOCA(gt_t, RLC_TERMS); - for (int j = 0; j < RLC_TERMS; j++) { - gt_null(hs[i][j]); - gt_new(hs[i][j]); - } - for (int j = 0; j < L; j++) { - bn_null(x[i][j]); - g1_null(a[i][j]); - g1_null(c[i][j]); - g1_null(r[i][j]); - g2_null(s[i][j]); - bn_new(x[i][j]); - g1_new(a[i][j]); - g1_new(c[i][j]); - g1_new(r[i][j]); - g2_new(s[i][j]); - } - bn_null(sk[i]); - bn_null(d[i]); - g1_null(sig[i]); - g1_null(as[i]); - g1_null(cs[i]); - g2_null(y[i]); - g2_null(z[i]); - g2_null(pk[i]); - - bn_new(sk[i]); - bn_new(d[i]); - g1_new(sig[i]); - g1_new(as[i]); - g1_new(cs[i]); - g2_new(y[i]); - g2_new(z[i]); - g2_new(pk[i]); - } - - /* Define linear function. */ - for (int i = 0; i < S; i++) { - f[i] = RLC_ALLOCA(dig_t, RLC_TERMS); - for (int j = 0; j < RLC_TERMS; j++) { - uint32_t t; - rand_bytes((uint8_t *)&t, sizeof(uint32_t)); - f[i][j] = t; - } - flen[i] = L; - } - - /* Initialize scheme for messages of single components. */ - cp_cmlhs_init(h); - - BENCH_ONE("cp_cmlhs_gen", - for (int j = 0; j < S; j++) { - BENCH_ADD(cp_cmlhs_gen(x[j], hs[j], L, k[j], K, sk[j], pk[j], d[j], y[j])); - }, - S); - - int label[L]; - - BENCH_FEW("cp_cmlhs_sig", - /* Compute all signatures. */ - for (int j = 0; j < S; j++) { - for (int l = 0; l < L; l++) { - label[l] = l; - bn_mod(msg[l], msg[l], n); - BENCH_ADD(cp_cmlhs_sig(sig[j], z[j], a[j][l], c[j][l], r[j][l], - s[j][l], msg[l], data, label[l], x[j][l], h, k[j], K, d[j], sk[j])); - } - }, - S * L); - - BENCH_RUN("cp_cmlhs_fun") { - for (int j = 0; j < S; j++) { - BENCH_ADD(cp_cmlhs_fun(as[j], cs[j], a[j], c[j], f[j], L)); - } - } BENCH_DIV(S); - - BENCH_RUN("cp_cmlhs_evl") { - cp_cmlhs_evl(_r, _s, r[0], s[0], f[0], L); - for (int j = 1; j < S; j++) { - BENCH_ADD(cp_cmlhs_evl(r[0][0], s[0][0], r[j], s[j], f[j], L)); - g1_add(_r, _r, r[0][0]); - g2_add(_s, _s, s[0][0]); - } - g1_norm(_r, _r); - g2_norm(_s, _s); - } BENCH_DIV(S); - - bn_zero(m); - for (int j = 0; j < L; j++) { - dig_t sum = 0; - for (int l = 0; l < S; l++) { - sum += f[l][j]; - } - bn_mul_dig(msg[j], msg[j], sum); - bn_add(m, m, msg[j]); - bn_mod(m, m, n); - } - - BENCH_RUN("cp_cmlhs_ver") { - BENCH_ADD(cp_cmlhs_ver(_r, _s, sig, z, as, cs, m, data, h, label, hs, - f, flen, y, pk, S)); - } BENCH_DIV(S); - - BENCH_RUN("cp_cmlhs_off") { - BENCH_ADD(cp_cmlhs_off(vk, h, label, hs, f, flen, y, pk, S)); - } BENCH_DIV(S); - - BENCH_RUN("cp_cmlhs_onv") { - BENCH_ADD(cp_cmlhs_onv(_r, _s, sig, z, as, cs, m, data, h, vk, y, - pk, S)); - } BENCH_DIV(S); - -#ifdef BENCH_LHS - for (int t = 1; t <= S; t++) { - util_print("(%2d ids) ", t); - BENCH_RUN("cp_cmlhs_ver") { - BENCH_ADD(cp_cmlhs_ver(_r, _s, sig, z, as, cs, m, data, h, label, - hs, f, flen, y, pk, t)); - } BENCH_END; - - util_print("(%2d ids) ", t); - BENCH_RUN("cp_cmlhs_off") { - BENCH_ADD(cp_cmlhs_off(vk, h, label, hs, f, flen, y, pk, t)); - } BENCH_END; - - util_print("(%2d ids) ", t); - BENCH_RUN("cp_cmlhs_onv") { - BENCH_ADD(cp_cmlhs_onv(_r, _s, sig, z, as, cs, m, data, h, vk, y, - pk, t)); - } BENCH_END; - } - - for (int t = 1; t <= L; t++) { - util_print("(%2d lbs) ", t); - for (int u = 0; u < S; u++) { - flen[u] = t; - } - BENCH_RUN("cp_cmlhs_ver") { - BENCH_ADD(cp_cmlhs_ver(_r, _s, sig, z, as, cs, m, data, h, label, - hs, f, flen, y, pk, S)); - } BENCH_END; - - util_print("(%2d lbs) ", t); - BENCH_RUN("cp_cmlhs_off") { - BENCH_ADD(cp_cmlhs_off(vk, h, label, hs, f, flen, y, pk, t)); - } BENCH_END; - - util_print("(%2d lbs) ", t); - BENCH_RUN("cp_cmlhs_onv") { - BENCH_ADD(cp_cmlhs_onv(_r, _s, sig, z, as, cs, m, data, h, vk, y, - pk, t)); - } BENCH_END; - } -#endif /* BENCH_LHS */ - - char *ls[L]; - - BENCH_RUN("cp_mklhs_gen") { - for (int j = 0; j < S; j++) { - BENCH_ADD(cp_mklhs_gen(sk[j], pk[j])); - } - } BENCH_DIV(S); - - BENCH_RUN("cp_mklhs_sig") { - for (int j = 0; j < S; j++) { - for (int l = 0; l < L; l++) { - ls[l] = "l"; - bn_mod(msg[l], msg[l], n); - BENCH_ADD(cp_mklhs_sig(a[j][l], msg[l], data, - id[j], ls[l], sk[j])); - } - } - } BENCH_DIV(S * L); - - BENCH_RUN("cp_mklhs_fun") { - for (int j = 0; j < S; j++) { - bn_zero(d[j]); - BENCH_ADD(cp_mklhs_fun(d[j], msg, f[j], L)); - } - } - BENCH_DIV(S); - - BENCH_RUN("cp_mklhs_evl") { - g1_set_infty(_r); - for (int j = 0; j < S; j++) { - BENCH_ADD(cp_mklhs_evl(r[0][j], a[j], f[j], L)); - g1_add(_r, _r, r[0][j]); - } - g1_norm(_r, _r); - } - BENCH_DIV(S); - - bn_zero(m); - for (int j = 0; j < L; j++) { - dig_t sum = 0; - for (int l = 0; l < S; l++) { - sum += f[l][j]; - } - bn_mul_dig(msg[j], msg[j], sum); - bn_add(m, m, msg[j]); - bn_mod(m, m, n); - } - - BENCH_RUN("cp_mklhs_ver") { - BENCH_ADD(cp_mklhs_ver(_r, m, d, data, id, ls, f, flen, pk, S)); - } BENCH_DIV(S); - - BENCH_RUN("cp_mklhs_off") { - BENCH_ADD(cp_mklhs_off(cs, ft, id, ls, f, flen, S)); - } BENCH_DIV(S); - - BENCH_RUN("cp_mklhs_onv") { - BENCH_ADD(cp_mklhs_onv(_r, m, d, data, id, cs, ft, pk, S)); - } BENCH_DIV(S); - -#ifdef BENCH_LHS - for (int t = 1; t <= S; t++) { - util_print("(%2d ids) ", t); - BENCH_RUN("cp_mklhs_ver") { - BENCH_ADD(cp_mklhs_ver(_r, m, d, data, id, ls, f, flen, pk, t)); - } BENCH_END; - - util_print("(%2d ids) ", t); - BENCH_RUN("cp_mklhs_off") { - BENCH_ADD(cp_mklhs_off(cs, ft, id, ls, f, flen, t)); - } BENCH_END; - - util_print("(%2d ids) ", t); - BENCH_RUN("cp_mklhs_onv") { - BENCH_ADD(cp_mklhs_onv(_r, m, d, data, id, cs, ft, pk, t)); - } BENCH_END; - } - - for (int t = 1; t <= L; t++) { - util_print("(%2d lbs) ", t); - for (int u = 0; u < S; u++) { - flen[u] = t; - } - BENCH_RUN("cp_mklhs_ver") { - BENCH_ADD(cp_mklhs_ver(_r, m, d, data, id, ls, f, flen, pk, S)); - } BENCH_END; - - util_print("(%2d lbs) ", t); - BENCH_RUN("cp_mklhs_off") { - BENCH_ADD(cp_mklhs_off(cs, ft, id, ls, f, flen, S)); - } BENCH_END; - - util_print("(%2d lbs) ", t); - BENCH_RUN("cp_mklhs_onv") { - BENCH_ADD(cp_mklhs_onv(_r, m, d, data, id, cs, ft, pk, S)); - } BENCH_END; - } -#endif /* BENCH_LHS */ - - bn_free(n); - bn_free(m); - g1_free(h); - g1_free(_r); - g2_free(_s); - gt_free(vk); - - for (int i = 0; i < L; i++) { - bn_free(msg[i]); - } - for (int i = 0; i < S; i++) { - RLC_FREE(f[i]); - for (int j = 0; j < RLC_TERMS; j++) { - gt_free(hs[i][j]); - } - RLC_FREE(hs[i]); - for (int j = 0; j < L; j++) { - bn_free(x[i][j]); - g1_free(a[i][j]); - g1_free(c[i][j]); - g1_free(r[i][j]); - g2_free(s[i][j]); - } - bn_free(sk[i]); - bn_free(d[i]); - g1_free(sig[i]); - g1_free(as[i]); - g1_free(cs[i]); - g2_free(y[i]); - g2_free(z[i]); - g2_free(pk[i]); - } -} - -#endif /* WITH_PC */ - -int main(void) { - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - conf_print(); - - util_banner("Benchmarks for the CP module:", 0); - -#if defined(WITH_BN) - util_banner("Protocols based on integer factorization:\n", 0); - rsa(); - rabin(); - benaloh(); - paillier(); -#endif - -#if defined(WITH_EC) - if (ec_param_set_any() == RLC_OK) { - util_banner("Protocols based on elliptic curves:\n", 0); - ecdh(); - ecmqv(); - ecies(); - ecdsa(); - ecss(); - vbnn(); - ers(); - etrs(); - } -#endif - -#if defined(WITH_PC) - if (pc_param_set_any() == RLC_OK) { - util_banner("Protocols based on pairings:\n", 0); - pdpub(); - pdprv(); - sokaka(); - ibe(); - bgn(); - bls(); - bbs(); - cls(); - pss(); -#if defined(WITH_MPC) - mpss(); -#endif - zss(); - lhs(); - } -#endif - - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/bench/bench_dv.c b/src/dashbls/depends/relic/bench/bench_dv.c deleted file mode 100644 index 7f1584619770..000000000000 --- a/src/dashbls/depends/relic/bench/bench_dv.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2009 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for manipulating temporary double-precision digit vectors. - * - * @ingroup bench - */ - -#include - -#include "relic.h" -#include "relic_bench.h" - -static void memory(void) { - dv_t a[BENCH]; - - BENCH_FEW("dv_null", dv_null(a[i]), 1); - - BENCH_FEW("dv_new", dv_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - dv_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - dv_new(a[i]); - } - BENCH_FEW("dv_free", dv_free(a[i]), 1); - - (void)a; -} - -static void copy(void) { - dv_t a, b; - - dv_null(a); - dv_null(b); - - dv_new(a); - dv_new(b); - - BENCH_RUN("dv_copy") { - rand_bytes((uint8_t *)a, RLC_DV_DIGS * sizeof(dig_t)); - rand_bytes((uint8_t *)b, RLC_DV_DIGS * sizeof(dig_t)); - BENCH_ADD(dv_copy(a, b, RLC_DV_DIGS)); - } BENCH_END; - - BENCH_RUN("dv_copy_cond") { - rand_bytes((uint8_t *)a, RLC_DV_DIGS * sizeof(dig_t)); - rand_bytes((uint8_t *)b, RLC_DV_DIGS * sizeof(dig_t)); - BENCH_ADD(dv_copy_cond(a, b, RLC_DV_DIGS, 1)); - } BENCH_END; - - BENCH_RUN("dv_swap_cond") { - rand_bytes((uint8_t *)a, RLC_DV_DIGS * sizeof(dig_t)); - rand_bytes((uint8_t *)b, RLC_DV_DIGS * sizeof(dig_t)); - BENCH_ADD(dv_swap_cond(a, b, RLC_DV_DIGS, 1)); - } BENCH_END; - - BENCH_RUN("dv_cmp") { - rand_bytes((uint8_t *)a, RLC_DV_DIGS * sizeof(dig_t)); - rand_bytes((uint8_t *)b, RLC_DV_DIGS * sizeof(dig_t)); - BENCH_ADD(dv_cmp(a, b, RLC_DV_DIGS)); - } BENCH_END; - - BENCH_RUN("dv_cmp_const") { - rand_bytes((uint8_t *)a, RLC_DV_DIGS * sizeof(dig_t)); - rand_bytes((uint8_t *)b, RLC_DV_DIGS * sizeof(dig_t)); - BENCH_ADD(dv_cmp_const(a, b, RLC_DV_DIGS)); - } BENCH_END; - - dv_free(a); - dv_free(b); -} - -int main(void) { - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - conf_print(); - util_banner("Benchmarks for the DV module:", 0); - util_banner("Utilities:\n", 0); - memory(); - copy(); - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/bench/bench_eb.c b/src/dashbls/depends/relic/bench/bench_eb.c deleted file mode 100644 index 1bd9d94d333b..000000000000 --- a/src/dashbls/depends/relic/bench/bench_eb.c +++ /dev/null @@ -1,660 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2009 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for arithmetic on binary elliptic curves. - * - * @ingroup bench - */ - -#include - -#include "relic.h" -#include "relic_bench.h" - -static void memory(void) { - eb_t a[BENCH]; - - BENCH_FEW("eb_null", eb_null(a[i]), 1); - - BENCH_FEW("eb_new", eb_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - eb_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - eb_new(a[i]); - } - BENCH_FEW("eb_free", eb_free(a[i]), 1); - - (void)a; -} - -static void util(void) { - eb_t p, q, t[4]; - uint8_t bin[2 * RLC_FB_BYTES + 1]; - int l; - - eb_null(p); - eb_null(q); - for (int j= 0; j < 4; j++) { - eb_null(t[j]); - } - - eb_new(p); - eb_new(q); - for (int j= 0; j < 4; j++) { - eb_new(t[j]); - } - - BENCH_RUN("eb_is_infty") { - eb_rand(p); - BENCH_ADD(eb_is_infty(p)); - } BENCH_END; - - BENCH_RUN("eb_set_infty") { - eb_rand(p); - BENCH_ADD(eb_set_infty(p)); - } BENCH_END; - - BENCH_RUN("eb_copy") { - eb_rand(p); - eb_rand(q); - BENCH_ADD(eb_copy(p, q)); - } BENCH_END; - - BENCH_RUN("eb_cmp") { - eb_rand(p); - eb_dbl(p, p); - eb_rand(q); - eb_dbl(q, q); - BENCH_ADD(eb_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("eb_cmp (1 norm)") { - eb_rand(p); - eb_dbl(p, p); - eb_rand(q); - BENCH_ADD(eb_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("eb_cmp (2 norm)") { - eb_rand(p); - eb_rand(q); - BENCH_ADD(eb_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("eb_rand") { - BENCH_ADD(eb_rand(p)); - } BENCH_END; - - BENCH_RUN("eb_blind") { - BENCH_ADD(eb_blind(p, p)); - } BENCH_END; - - BENCH_RUN("eb_rhs") { - eb_rand(p); - BENCH_ADD(eb_rhs(q->x, p)); - } BENCH_END; - - BENCH_RUN("eb_tab (4)") { - eb_rand(p); - BENCH_ADD(eb_tab(t, p, 4)); - } BENCH_END; - - BENCH_RUN("eb_on_curve") { - eb_rand(p); - BENCH_ADD(eb_on_curve(p)); - } BENCH_END; - - BENCH_RUN("eb_size_bin (0)") { - eb_rand(p); - BENCH_ADD(eb_size_bin(p, 0)); - } BENCH_END; - - BENCH_RUN("eb_size_bin (1)") { - eb_rand(p); - BENCH_ADD(eb_size_bin(p, 1)); - } BENCH_END; - - BENCH_RUN("eb_write_bin (0)") { - eb_rand(p); - l = eb_size_bin(p, 0); - BENCH_ADD(eb_write_bin(bin, l, p, 0)); - } BENCH_END; - - BENCH_RUN("eb_write_bin (1)") { - eb_rand(p); - l = eb_size_bin(p, 1); - BENCH_ADD(eb_write_bin(bin, l, p, 1)); - } BENCH_END; - - BENCH_RUN("eb_read_bin (0)") { - eb_rand(p); - l = eb_size_bin(p, 0); - eb_write_bin(bin, l, p, 0); - BENCH_ADD(eb_read_bin(p, bin, l)); - } BENCH_END; - - BENCH_RUN("eb_read_bin (1)") { - eb_rand(p); - l = eb_size_bin(p, 1); - eb_write_bin(bin, l, p, 1); - BENCH_ADD(eb_read_bin(p, bin, l)); - } BENCH_END; - - eb_free(p); - eb_free(q); - for (int j = 0; j < 4; j++) { - eb_free(t[j]); - } -} - -static void arith(void) { - eb_t p, q, r, t[RLC_EB_TABLE_MAX]; - bn_t k, l, n; - - eb_null(p); - eb_null(q); - eb_null(r); - for (int i = 0; i < RLC_EB_TABLE_MAX; i++) { - eb_null(t[i]); - } bn_null(k); - bn_null(l); - bn_null(n); - - eb_new(p); - eb_new(q); - eb_new(r); - bn_new(k); - bn_new(n); - bn_new(l); - - eb_curve_get_ord(n); - - BENCH_RUN("eb_add") { - eb_rand(p); - eb_rand(q); - eb_add(p, p, q); - eb_rand(q); - eb_rand(p); - eb_add(q, q, p); - BENCH_ADD(eb_add(r, p, q)); - } BENCH_END; - -#if EB_ADD == BASIC || !defined(STRIP) - BENCH_RUN("eb_add_basic") { - eb_rand(p); - eb_rand(q); - BENCH_ADD(eb_add_basic(r, p, q)); - } BENCH_END; -#endif - -#if EB_ADD == PROJC || !defined(STRIP) - BENCH_RUN("eb_add_projc") { - eb_rand(p); - eb_rand(q); - eb_add_projc(p, p, q); - eb_rand(q); - eb_rand(p); - eb_add_projc(q, q, p); - BENCH_ADD(eb_add_projc(r, p, q)); - } BENCH_END; - - BENCH_RUN("eb_add_projc (z2 = 1)") { - eb_rand(p); - eb_rand(q); - eb_add_projc(p, p, q); - eb_rand(q); - eb_norm(q, q); - BENCH_ADD(eb_add_projc(r, p, q)); - } BENCH_END; - - BENCH_RUN("eb_add_projc (z1,z2 = 1)") { - eb_rand(p); - eb_norm(p, p); - eb_rand(q); - eb_norm(q, q); - BENCH_ADD(eb_add_projc(r, p, q)); - } BENCH_END; -#endif - - BENCH_RUN("eb_sub") { - eb_rand(p); - eb_rand(q); - eb_add(p, p, q); - eb_rand(q); - eb_rand(p); - eb_add(q, q, p); - BENCH_ADD(eb_sub(r, p, q)); - } BENCH_END; - -#if EB_ADD == BASIC || !defined(STRIP) - BENCH_RUN("eb_sub_basic") { - eb_rand(p); - eb_rand(q); - BENCH_ADD(eb_sub_basic(r, p, q)); - } BENCH_END; -#endif - -#if EB_ADD == PROJC || !defined(STRIP) - BENCH_RUN("eb_sub_projc") { - eb_rand(p); - eb_rand(q); - eb_add_projc(p, p, q); - eb_rand(q); - eb_rand(p); - eb_add_projc(q, q, p); - BENCH_ADD(eb_sub_projc(r, p, q)); - } BENCH_END; - - BENCH_RUN("eb_sub_projc (z2 = 1)") { - eb_rand(p); - eb_rand(q); - eb_add_projc(p, p, q); - eb_rand(q); - eb_norm(q, q); - BENCH_ADD(eb_sub_projc(r, p, q)); - } BENCH_END; - - BENCH_RUN("eb_sub_projc (z1,z2 = 1)") { - eb_rand(p); - eb_norm(p, p); - eb_rand(q); - eb_norm(q, q); - BENCH_ADD(eb_sub_projc(r, p, q)); - } BENCH_END; -#endif - - BENCH_RUN("eb_dbl") { - eb_rand(p); - eb_rand(q); - eb_add(p, p, q); - BENCH_ADD(eb_dbl(r, p)); - } BENCH_END; - -#if EB_ADD == BASIC || !defined(STRIP) - BENCH_RUN("eb_dbl_basic") { - eb_rand(p); - BENCH_ADD(eb_dbl_basic(r, p)); - } BENCH_END; -#endif - -#if EB_ADD == PROJC || !defined(STRIP) - BENCH_RUN("eb_dbl_projc") { - eb_rand(p); - eb_rand(q); - eb_add_projc(p, p, q); - BENCH_ADD(eb_dbl_projc(r, p)); - } BENCH_END; - - BENCH_RUN("eb_dbl_projc (z1 = 1)") { - eb_rand(p); - eb_norm(p, p); - BENCH_ADD(eb_dbl_projc(r, p)); - } BENCH_END; -#endif - - BENCH_RUN("eb_hlv") { - eb_rand(p); - BENCH_ADD(eb_hlv(r, p)); - } - BENCH_END; -#if defined(EB_KBLTZ) - if (eb_curve_is_kbltz()) { - BENCH_RUN("eb_frb") { - eb_rand(p); - eb_rand(q); - eb_add_projc(p, p, q); - BENCH_ADD(eb_frb(r, p)); - } - BENCH_END; - } - -#if EB_ADD == BASIC || !defined(STRIP) - if (eb_curve_is_kbltz()) { - BENCH_RUN("eb_frb (z = 1)") { - eb_rand(p); - BENCH_ADD(eb_frb(r, p)); - } - BENCH_END; - } -#endif - -#endif /* EB_KBLTZ */ - - BENCH_RUN("eb_neg") { - eb_rand(p); - eb_rand(q); - eb_add(p, p, q); - BENCH_ADD(eb_neg(r, p)); - } - BENCH_END; - -#if EB_ADD == BASIC || !defined(STRIP) - BENCH_RUN("eb_neg_basic") { - eb_rand(p); - BENCH_ADD(eb_neg_basic(r, p)); - } - BENCH_END; -#endif - -#if EB_ADD == PROJC || !defined(STRIP) - BENCH_RUN("eb_neg_projc") { - eb_rand(p); - eb_rand(q); - eb_add_projc(p, p, q); - BENCH_ADD(eb_neg_projc(r, p)); - } - BENCH_END; -#endif - - BENCH_RUN("eb_mul") { - bn_rand_mod(k, n); - eb_rand(p); - eb_rand(q); - BENCH_ADD(eb_mul(q, p, k)); - } - BENCH_END; - -#if EB_MUL == BASIC || !defined(STRIP) - BENCH_RUN("eb_mul_basic") { - bn_rand_mod(k, n); - eb_rand(p); - BENCH_ADD(eb_mul_basic(q, p, k)); - } - BENCH_END; -#endif - -#if EB_MUL == LODAH || !defined(STRIP) - BENCH_RUN("eb_mul_lodah") { - bn_rand_mod(k, n); - eb_rand(p); - BENCH_ADD(eb_mul_lodah(q, p, k)); - } - BENCH_END; -#endif - -#if EB_MUL == LWNAF || !defined(STRIP) - BENCH_RUN("eb_mul_lwnaf") { - bn_rand_mod(k, n); - eb_rand(p); - BENCH_ADD(eb_mul_lwnaf(q, p, k)); - } - BENCH_END; -#endif - -#if EB_MUL == RWNAF || !defined(STRIP) - BENCH_RUN("eb_mul_rwnaf") { - bn_rand_mod(k, n); - eb_rand(p); - BENCH_ADD(eb_mul_rwnaf(q, p, k)); - } - BENCH_END; -#endif - -#if EB_MUL == HALVE || !defined(STRIP) - BENCH_RUN("eb_mul_halve") { - bn_rand_mod(k, n); - eb_rand(p); - BENCH_ADD(eb_mul_halve(q, p, k)); - } - BENCH_END; -#endif - - BENCH_RUN("eb_mul_gen") { - bn_rand_mod(k, n); - BENCH_ADD(eb_mul_gen(q, k)); - } - BENCH_END; - - BENCH_RUN("eb_mul_dig") { - bn_rand(k, RLC_POS, RLC_DIG); - bn_rand_mod(k, n); - BENCH_ADD(eb_mul_dig(p, q, k->dp[0])); - } - BENCH_END; - - for (int i = 0; i < RLC_EB_TABLE; i++) { - eb_new(t[i]); - } - - BENCH_RUN("eb_mul_pre") { - eb_rand(p); - BENCH_ADD(eb_mul_pre(t, p)); - } BENCH_END; - - BENCH_RUN("eb_mul_fix") { - bn_rand_mod(k, n); - eb_rand(p); - eb_mul_pre(t, p); - BENCH_ADD(eb_mul_fix(q, (const eb_t *)t, k)); - } BENCH_END; - - for (int i = 0; i < RLC_EB_TABLE; i++) { - eb_free(t[i]); - } - -#if EB_FIX == BASIC || !defined(STRIP) - for (int i = 0; i < RLC_EB_TABLE_BASIC; i++) { - eb_new(t[i]); - } - BENCH_RUN("eb_mul_pre_basic") { - eb_rand(p); - BENCH_ADD(eb_mul_pre_basic(t, p)); - } BENCH_END; - - BENCH_RUN("eb_mul_fix_basic") { - bn_rand_mod(k, n); - eb_rand(p); - eb_mul_pre_basic(t, p); - BENCH_ADD(eb_mul_fix_basic(q, (const eb_t *)t, k)); - } BENCH_END; - for (int i = 0; i < RLC_EB_TABLE_BASIC; i++) { - eb_free(t[i]); - } -#endif - -#if EB_FIX == COMBS || !defined(STRIP) - for (int i = 0; i < RLC_EB_TABLE_COMBS; i++) { - eb_new(t[i]); - } - BENCH_RUN("eb_mul_pre_combs") { - eb_rand(p); - BENCH_ADD(eb_mul_pre_combs(t, p)); - } BENCH_END; - - BENCH_RUN("eb_mul_fix_combs") { - bn_rand_mod(k, n); - eb_rand(p); - eb_mul_pre_combs(t, p); - BENCH_ADD(eb_mul_fix_combs(q, (const eb_t *)t, k)); - } BENCH_END; - for (int i = 0; i < RLC_EB_TABLE_COMBS; i++) { - eb_free(t[i]); - } -#endif - -#if EB_FIX == COMBD || !defined(STRIP) - for (int i = 0; i < RLC_EB_TABLE_COMBD; i++) { - eb_new(t[i]); - } - BENCH_RUN("eb_mul_pre_combd") { - eb_rand(p); - BENCH_ADD(eb_mul_pre_combd(t, p)); - } BENCH_END; - - BENCH_RUN("eb_mul_fix_combd") { - bn_rand_mod(k, n); - eb_rand(p); - eb_mul_pre_combd(t, p); - BENCH_ADD(eb_mul_fix_combd(q, (const eb_t *)t, k)); - } BENCH_END; - for (int i = 0; i < RLC_EB_TABLE_COMBD; i++) { - eb_free(t[i]); - } -#endif - -#if EB_FIX == LWNAF || !defined(STRIP) - for (int i = 0; i < RLC_EB_TABLE_LWNAF; i++) { - eb_new(t[i]); - } - BENCH_RUN("eb_mul_pre_lwnaf") { - eb_rand(p); - BENCH_ADD(eb_mul_pre_lwnaf(t, p)); - } BENCH_END; - - BENCH_RUN("eb_mul_fix_lwnaf") { - bn_rand_mod(k, n); - eb_rand(p); - eb_mul_pre_lwnaf(t, p); - BENCH_ADD(eb_mul_fix_lwnaf(q, (const eb_t *)t, k)); - } BENCH_END; - for (int i = 0; i < RLC_EB_TABLE_LWNAF; i++) { - eb_free(t[i]); - } -#endif - - BENCH_RUN("eb_mul_sim") { - bn_rand_mod(k, n); - bn_rand_mod(l, n); - eb_rand(p); - eb_rand(q); - BENCH_ADD(eb_mul_sim(r, p, k, q, l)); - } BENCH_END; - -#if EB_SIM == BASIC || !defined(STRIP) - BENCH_RUN("eb_mul_sim_basic") { - bn_rand_mod(k, n); - bn_rand_mod(l, n); - eb_rand(p); - eb_rand(q); - BENCH_ADD(eb_mul_sim_basic(r, p, k, q, l)); - } BENCH_END; -#endif - -#if EB_SIM == TRICK || !defined(STRIP) - BENCH_RUN("eb_mul_sim_trick") { - bn_rand_mod(k, n); - bn_rand_mod(l, n); - eb_rand(p); - eb_rand(q); - BENCH_ADD(eb_mul_sim_trick(r, p, k, q, l)); - } BENCH_END; -#endif - -#if EB_SIM == INTER || !defined(STRIP) - BENCH_RUN("eb_mul_sim_inter") { - bn_rand_mod(k, n); - bn_rand_mod(l, n); - eb_rand(p); - eb_rand(q); - BENCH_ADD(eb_mul_sim_inter(r, p, k, q, l)); - } BENCH_END; -#endif - -#if EB_SIM == JOINT || !defined(STRIP) - BENCH_RUN("eb_mul_sim_joint") { - bn_rand_mod(k, n); - bn_rand_mod(l, n); - eb_rand(p); - eb_rand(q); - BENCH_ADD(eb_mul_sim_joint(r, p, k, q, l)); - } BENCH_END; -#endif - - BENCH_RUN("eb_mul_sim_gen") { - bn_rand_mod(k, n); - bn_rand_mod(l, n); - eb_rand(q); - BENCH_ADD(eb_mul_sim_gen(r, k, q, l)); - } BENCH_END; - - BENCH_RUN("eb_map") { - uint8_t msg[5]; - rand_bytes(msg, 5); - BENCH_ADD(eb_map(p, msg, 5)); - } BENCH_END; - - BENCH_RUN("eb_pck") { - eb_rand(p); - BENCH_ADD(eb_pck(q, p)); - } BENCH_END; - - BENCH_RUN("eb_upk") { - eb_rand(p); - BENCH_ADD(eb_upk(q, p)); - } BENCH_END; - - eb_free(p); - eb_free(q); - bn_free(k); - bn_free(l); - bn_free(n); -} - -static void bench(void) { - eb_param_print(); - util_banner("Utilities:", 1); - memory(); - util(); - util_banner("Arithmetic:", 1); - arith(); -} - -int main(void) { - int r0 = RLC_ERR, r1 = RLC_ERR; - - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - conf_print(); - util_banner("Benchmarks for the EB module:", 0); - -#if defined(EB_PLAIN) - r0 = eb_param_set_any_plain(); - if (r0 == RLC_OK) { - bench(); - } -#endif - -#if defined(EB_KBLTZ) - r1 = eb_param_set_any_kbltz(); - if (r1 == RLC_OK) { - bench(); - } -#endif - - if (r0 == RLC_ERR && r1 == RLC_ERR) { - if (eb_param_set_any() == RLC_ERR) { - RLC_THROW(ERR_NO_CURVE); - } - } - - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/bench/bench_ec.c b/src/dashbls/depends/relic/bench/bench_ec.c deleted file mode 100644 index 1926a987a951..000000000000 --- a/src/dashbls/depends/relic/bench/bench_ec.c +++ /dev/null @@ -1,317 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2009 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for Elliptic Curve Cryptography. - * - * @ingroup bench - */ - -#include - -#include "relic.h" -#include "relic_bench.h" - -static void memory(void) { - ec_t a[BENCH]; - - BENCH_FEW("ec_null", ec_null(a[i]), 1); - - BENCH_FEW("ec_new", ec_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - ec_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - ec_new(a[i]); - } - BENCH_FEW("ec_free", ec_free(a[i]), 1); - - (void)a; -} - -static void util(void) { - ec_t p, q; - uint8_t bin[2 * RLC_FC_BYTES + 1]; - int l; - - ec_null(p); - ec_null(q); - - ec_new(p); - ec_new(q); - - BENCH_RUN("ec_is_infty") { - ec_rand(p); - BENCH_ADD(ec_is_infty(p)); - } - BENCH_END; - - BENCH_RUN("ec_set_infty") { - ec_rand(p); - BENCH_ADD(ec_set_infty(p)); - } - BENCH_END; - - BENCH_RUN("ec_copy") { - ec_rand(p); - ec_rand(q); - BENCH_ADD(ec_copy(p, q)); - } - BENCH_END; - - BENCH_RUN("ec_cmp") { - ec_rand(p); - ec_dbl(p, p); - ec_rand(q); - ec_dbl(q, q); - BENCH_ADD(ec_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("ec_cmp (1 norm)") { - ec_rand(p); - ec_dbl(p, p); - ec_rand(q); - BENCH_ADD(ec_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("ec_cmp (2 norm)") { - ec_rand(p); - ec_rand(q); - BENCH_ADD(ec_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("ec_rand") { - BENCH_ADD(ec_rand(p)); - } - BENCH_END; - - BENCH_RUN("ec_blind") { - BENCH_ADD(ec_blind(p, p)); - } - BENCH_END; - - BENCH_RUN("ec_on_curve") { - ec_rand(p); - BENCH_ADD(ec_on_curve(p)); - } BENCH_END; - - BENCH_RUN("ec_size_bin (0)") { - ec_rand(p); - BENCH_ADD(ec_size_bin(p, 0)); - } BENCH_END; - - BENCH_RUN("ec_size_bin (1)") { - ec_rand(p); - BENCH_ADD(ec_size_bin(p, 1)); - } BENCH_END; - - BENCH_RUN("ec_write_bin (0)") { - ec_rand(p); - l = ec_size_bin(p, 0); - BENCH_ADD(ec_write_bin(bin, l, p, 0)); - } BENCH_END; - - BENCH_RUN("ec_write_bin (1)") { - ec_rand(p); - l = ec_size_bin(p, 1); - BENCH_ADD(ec_write_bin(bin, l, p, 1)); - } BENCH_END; - - BENCH_RUN("ec_read_bin (0)") { - ec_rand(p); - l = ec_size_bin(p, 0); - ec_write_bin(bin, l, p, 0); - BENCH_ADD(ec_read_bin(p, bin, l)); - } BENCH_END; - - BENCH_RUN("ec_read_bin (1)") { - ec_rand(p); - l = ec_size_bin(p, 1); - ec_write_bin(bin, l, p, 1); - BENCH_ADD(ec_read_bin(p, bin, l)); - } BENCH_END; - - ec_free(p); - ec_free(q); -} - -static void arith(void) { - ec_t p, q, r, t[RLC_EC_TABLE]; - bn_t k, l, n; - - ec_null(p); - ec_null(q); - ec_null(r); - for (int i = 0; i < RLC_EC_TABLE; i++) { - ec_null(t[i]); - } - - ec_new(p); - ec_new(q); - ec_new(r); - bn_new(k); - bn_new(n); - bn_new(l); - - ec_curve_get_ord(n); - - BENCH_RUN("ec_add") { - ec_rand(p); - ec_rand(q); - ec_add(p, p, q); - ec_rand(q); - ec_rand(p); - ec_add(q, q, p); - BENCH_ADD(ec_add(r, p, q)); - } - BENCH_END; - - BENCH_RUN("ec_sub") { - ec_rand(p); - ec_rand(q); - ec_add(p, p, q); - ec_rand(q); - ec_rand(p); - ec_add(q, q, p); - BENCH_ADD(ec_sub(r, p, q)); - } - BENCH_END; - - BENCH_RUN("ec_dbl") { - ec_rand(p); - ec_rand(q); - ec_add(p, p, q); - BENCH_ADD(ec_dbl(r, p)); - } - BENCH_END; - - BENCH_RUN("ec_neg") { - ec_rand(p); - ec_rand(q); - ec_add(p, p, q); - BENCH_ADD(ec_neg(r, p)); - } - BENCH_END; - - BENCH_RUN("ec_mul") { - bn_rand_mod(k, n); - ec_rand(p); - BENCH_ADD(ec_mul(q, p, k)); - } - BENCH_END; - - BENCH_RUN("ec_mul_gen") { - bn_rand_mod(k, n); - BENCH_ADD(ec_mul_gen(q, k)); - } - BENCH_END; - - for (int i = 0; i < RLC_EC_TABLE; i++) { - ec_new(t[i]); - } - - BENCH_RUN("ec_mul_pre") { - BENCH_ADD(ec_mul_pre(t, p)); - } - BENCH_END; - - BENCH_RUN("ec_mul_fix") { - bn_rand_mod(k, n); - ec_mul_pre(t, p); - BENCH_ADD(ec_mul_fix(q, (const ec_t *)t, k)); - } - BENCH_END; - - BENCH_RUN("ec_mul_sim") { - bn_rand_mod(k, n); - bn_rand_mod(l, n); - ec_rand(p); - ec_rand(q); - BENCH_ADD(ec_mul_sim(r, p, k, q, l)); - } - BENCH_END; - - BENCH_RUN("ec_mul_sim_gen") { - bn_rand_mod(k, n); - bn_rand_mod(l, n); - ec_rand(q); - BENCH_ADD(ec_mul_sim_gen(r, k, q, l)); - } - BENCH_END; - - BENCH_RUN("ec_map") { - uint8_t msg[5]; - rand_bytes(msg, 5); - BENCH_ADD(ec_map(p, msg, 5)); - } BENCH_END; - - BENCH_RUN("ec_pck") { - ec_rand(p); - BENCH_ADD(ec_pck(q, p)); - } BENCH_END; - - BENCH_RUN("ec_upk") { - ec_rand(p); - BENCH_ADD(ec_upk(q, p)); - } BENCH_END; - - ec_free(p); - ec_free(q); - bn_free(k); - bn_free(l); - bn_free(n); - for (int i = 0; i < RLC_EC_TABLE; i++) { - ec_free(t[i]); - } -} - -int main(void) { - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - conf_print(); - util_banner("Benchmarks for the EC module:", 0); - - if (ec_param_set_any() != RLC_OK) { - RLC_THROW(ERR_NO_CURVE); - core_clean(); - return 0; - } - - ec_param_print(); - - util_banner("Utilities:", 1); - memory(); - util(); - - util_banner("Arithmetic:", 1); - arith(); - - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/bench/bench_ed.c b/src/dashbls/depends/relic/bench/bench_ed.c deleted file mode 100644 index 7dfa39424cab..000000000000 --- a/src/dashbls/depends/relic/bench/bench_ed.c +++ /dev/null @@ -1,679 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2014 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for arithmetic on Edwards elliptic curves. - * - * @ingroup bench - */ - -#include - -#include "relic.h" -#include "relic_bench.h" - -static void memory(void) { - ed_t a[BENCH]; - - BENCH_FEW("ed_null", ed_null(a[i]), 1); - - BENCH_FEW("ed_new", ed_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - ed_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - ed_new(a[i]); - } - BENCH_FEW("ed_free", ed_free(a[i]), 1); - - (void)a; -} - -static void util(void) { - ed_t p, q, t[4]; - uint8_t bin[2 * RLC_FP_BYTES + 1]; - int l; - - ed_null(p); - ed_null(q); - for (int j = 0; j < 4; j++) { - ed_null(t[j]); - } - - ed_new(p); - ed_new(q); - for (int j = 0; j < 4; j++) { - ed_new(t[j]); - } - - BENCH_RUN("ed_is_infty") { - ed_rand(p); - BENCH_ADD(ed_is_infty(p)); - } BENCH_END; - - BENCH_RUN("ed_set_infty") { - ed_rand(p); - BENCH_ADD(ed_set_infty(p)); - } BENCH_END; - - BENCH_RUN("ed_copy") { - ed_rand(p); - ed_rand(q); - BENCH_ADD(ed_copy(p, q)); - } BENCH_END; - - BENCH_RUN("ed_cmp") { - ed_rand(p); - ed_dbl(p, p); - ed_rand(q); - ed_dbl(q, q); - BENCH_ADD(ed_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("ed_cmp (1 norm)") { - ed_rand(p); - ed_dbl(p, p); - ed_rand(q); - BENCH_ADD(ed_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("ed_cmp (2 norm)") { - ed_rand(p); - ed_rand(q); - BENCH_ADD(ed_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("ed_rand") { - BENCH_ADD(ed_rand(p)); - } BENCH_END; - - BENCH_RUN("ed_blind") { - BENCH_ADD(ed_blind(p, p)); - } BENCH_END; - - BENCH_RUN("ed_rhs") { - ed_rand(p); - BENCH_ADD(ed_rhs(q->x, p)); - } BENCH_END; - - BENCH_RUN("ed_tab (4)") { - ed_rand(p); - BENCH_ADD(ed_tab(t, p, 4)); - } BENCH_END; - - BENCH_RUN("ed_on_curve") { - ed_rand(p); - BENCH_ADD(ed_on_curve(p)); - } BENCH_END; - - BENCH_RUN("ed_size_bin (0)") { - ed_rand(p); - BENCH_ADD(ed_size_bin(p, 0)); - } BENCH_END; - - BENCH_RUN("ed_size_bin (1)") { - ed_rand(p); - BENCH_ADD(ed_size_bin(p, 1)); - } BENCH_END; - - BENCH_RUN("ed_write_bin (0)") { - ed_rand(p); - l = ed_size_bin(p, 0); - BENCH_ADD(ed_write_bin(bin, l, p, 0)); - } BENCH_END; - - BENCH_RUN("ed_write_bin (1)") { - ed_rand(p); - l = ed_size_bin(p, 1); - BENCH_ADD(ed_write_bin(bin, l, p, 1)); - } BENCH_END; - - BENCH_RUN("ed_read_bin (0)") { - ed_rand(p); - l = ed_size_bin(p, 0); - ed_write_bin(bin, l, p, 0); - BENCH_ADD(ed_read_bin(p, bin, l)); - } BENCH_END; - - BENCH_RUN("ed_read_bin (1)") { - ed_rand(p); - l = ed_size_bin(p, 1); - ed_write_bin(bin, l, p, 1); - BENCH_ADD(ed_read_bin(p, bin, l)); - } BENCH_END; - - ed_free(p); - ed_free(q); - for (int j = 0; j < 4; j++) { - ed_free(t[j]); - } -} - -static void arith(void) { - ed_t p, q, r, t[RLC_ED_TABLE_MAX]; - bn_t k, l, n; - - ed_null(p); - ed_null(q); - ed_null(r); - for (int i = 0; i < RLC_ED_TABLE_MAX; i++) { - ed_null(t[i]); - } - - ed_new(p); - ed_new(q); - ed_new(r); - bn_new(k); - bn_new(n); - bn_new(l); - - ed_curve_get_ord(n); - - BENCH_RUN("ed_add") { - ed_rand(p); - ed_rand(q); - ed_add(p, p, q); - ed_rand(q); - ed_rand(p); - ed_add(q, q, p); - BENCH_ADD(ed_add(r, p, q)); - } BENCH_END; - -#if ED_ADD == BASIC || !defined(STRIP) - BENCH_RUN("ed_add_basic") { - ed_rand(p); - ed_rand(q); - BENCH_ADD(ed_add_basic(r, p, q)); - } BENCH_END; -#endif - -#if ED_ADD == PROJC || !defined(STRIP) - BENCH_RUN("ed_add_projc") { - ed_rand(p); - ed_rand(q); - ed_add_projc(p, p, q); - ed_rand(q); - ed_rand(p); - ed_add_projc(q, q, p); - BENCH_ADD(ed_add_projc(r, p, q)); - } BENCH_END; - - BENCH_RUN("ed_add_projc (z2 = 1)") { - ed_rand(p); - ed_rand(q); - ed_add_projc(p, p, q); - ed_rand(q); - ed_norm(q, q); - BENCH_ADD(ed_add_projc(r, p, q)); - } BENCH_END; - - BENCH_RUN("ed_add_projc (z1,z2 = 1)") { - ed_rand(p); - ed_norm(p, p); - ed_rand(q); - ed_norm(q, q); - BENCH_ADD(ed_add_projc(r, p, q)); - } BENCH_END; -#endif - -#if ED_ADD == EXTND || !defined(STRIP) - BENCH_RUN("ed_add_extnd") { - ed_rand(p); - ed_rand(q); - ed_add_extnd(p, p, q); - ed_rand(q); - ed_rand(p); - ed_add_extnd(q, q, p); - BENCH_ADD(ed_add_extnd(r, p, q)); - } BENCH_END; - - BENCH_RUN("ed_add_extnd (z2 = 1)") { - ed_rand(p); - ed_rand(q); - ed_add_extnd(p, p, q); - ed_rand(q); - ed_norm(q, q); - BENCH_ADD(ed_add_extnd(r, p, q)); - } BENCH_END; - - BENCH_RUN("ed_add_extnd (z1,z2 = 1)") { - ed_rand(p); - ed_norm(p, p); - ed_rand(q); - ed_norm(q, q); - BENCH_ADD(ed_add_extnd(r, p, q)); - } BENCH_END; -#endif - - BENCH_RUN("ed_sub") { - ed_rand(p); - ed_rand(q); - ed_add(p, p, q); - ed_rand(q); - ed_rand(p); - ed_add(q, q, p); - BENCH_ADD(ed_sub(r, p, q)); - } BENCH_END; - -#if ED_ADD == BASIC || !defined(STRIP) - BENCH_RUN("ed_sub_basic") { - ed_rand(p); - ed_rand(q); - BENCH_ADD(ed_sub_basic(r, p, q)); - } BENCH_END; -#endif - -#if ED_ADD == PROJC || !defined(STRIP) - BENCH_RUN("ed_sub_projc") { - ed_rand(p); - ed_rand(q); - ed_add_projc(p, p, q); - ed_rand(q); - ed_rand(p); - ed_add_projc(q, q, p); - BENCH_ADD(ed_sub_projc(r, p, q)); - } BENCH_END; - - BENCH_RUN("ed_sub_projc (z2 = 1)") { - ed_rand(p); - ed_rand(q); - ed_add_projc(p, p, q); - ed_rand(q); - ed_norm(q, q); - BENCH_ADD(ed_sub_projc(r, p, q)); - } BENCH_END; - - BENCH_RUN("ed_sub_projc (z1,z2 = 1)") { - ed_rand(p); - ed_norm(p, p); - ed_rand(q); - ed_norm(q, q); - BENCH_ADD(ed_sub_projc(r, p, q)); - } BENCH_END; -#endif - -#if ED_ADD == EXTND || !defined(STRIP) - BENCH_RUN("ed_sub_extnd") { - ed_rand(p); - ed_rand(q); - ed_add_extnd(p, p, q); - ed_rand(q); - ed_rand(p); - ed_add_extnd(q, q, p); - BENCH_ADD(ed_sub_extnd(r, p, q)); - } BENCH_END; - - BENCH_RUN("ed_sub_projc (z2 = 1)") { - ed_rand(p); - ed_rand(q); - ed_add_extnd(p, p, q); - ed_rand(q); - ed_norm(q, q); - BENCH_ADD(ed_sub_extnd(r, p, q)); - } BENCH_END; - - BENCH_RUN("ed_sub_projc (z1,z2 = 1)") { - ed_rand(p); - ed_norm(p, p); - ed_rand(q); - ed_norm(q, q); - BENCH_ADD(ed_sub_projc(r, p, q)); - } BENCH_END; -#endif - - BENCH_RUN("ed_dbl") { - ed_rand(p); - ed_rand(q); - ed_add(p, p, q); - BENCH_ADD(ed_dbl(r, p)); - } BENCH_END; - -#if ED_ADD == BASIC || !defined(STRIP) - BENCH_RUN("ed_dbl_basic") { - ed_rand(p); - BENCH_ADD(ed_dbl_basic(r, p)); - } BENCH_END; -#endif - -#if ED_ADD == PROJC || !defined(STRIP) - BENCH_RUN("ed_dbl_projc") { - ed_rand(p); - ed_rand(q); - ed_add_projc(p, p, q); - BENCH_ADD(ed_dbl_projc(r, p)); - } BENCH_END; - - BENCH_RUN("ed_dbl_projc (z1 = 1)") { - ed_rand(p); - ed_norm(p, p); - BENCH_ADD(ed_dbl_projc(r, p)); - } BENCH_END; -#endif - -#if ED_ADD == PROJC || !defined(STRIP) - BENCH_RUN("ed_dbl_extnd") { - ed_rand(p); - ed_rand(q); - ed_add_extnd(p, p, q); - BENCH_ADD(ed_dbl_extnd(r, p)); - } BENCH_END; - - BENCH_RUN("ed_dbl_extnd (z1 = 1)") { - ed_rand(p); - ed_norm(p, p); - BENCH_ADD(ed_dbl_extnd(r, p)); - } BENCH_END; -#endif - - BENCH_RUN("ed_neg") { - ed_rand(p); - ed_rand(q); - ed_add(p, p, q); - BENCH_ADD(ed_neg(r, p)); - } BENCH_END; - -#if ED_ADD == BASIC || !defined(STRIP) - BENCH_RUN("ed_neg_basic") { - ed_rand(p); - BENCH_ADD(ed_neg_basic(r, p)); - } BENCH_END; -#endif - -#if ED_ADD == PROJC || !defined(STRIP) - BENCH_RUN("ed_neg_projc") { - ed_rand(p); - ed_rand(q); - ed_add_projc(p, p, q); - BENCH_ADD(ed_neg_projc(r, p)); - } BENCH_END; -#endif - - BENCH_RUN("ed_mul") { - bn_rand_mod(k, n); - ed_rand(p); - BENCH_ADD(ed_mul(q, p, k)); - } BENCH_END; - -#if ED_MUL == BASIC || !defined(STRIP) - BENCH_RUN("ed_mul_basic") { - bn_rand_mod(k, n); - BENCH_ADD(ed_mul_basic(q, p, k)); - } BENCH_END; -#endif - -#if ED_MUL == SLIDE || !defined(STRIP) - BENCH_RUN("ed_mul_slide") { - bn_rand_mod(k, n); - ed_rand(p); - BENCH_ADD(ed_mul_slide(q, p, k)); - } BENCH_END; -#endif - -#if ED_MUL == MONTY || !defined(STRIP) - BENCH_RUN("ed_mul_monty") { - bn_rand_mod(k, n); - ed_rand(p); - BENCH_ADD(ed_mul_monty(q, p, k)); - } BENCH_END; -#endif - -#if ED_MUL == LWNAF || !defined(STRIP) - BENCH_RUN("ed_mul_lwnaf") { - bn_rand_mod(k, n); - ed_rand(p); - BENCH_ADD(ed_mul_lwnaf(q, p, k)); - } BENCH_END; -#endif - -#if ED_MUL == LWREG || !defined(STRIP) - BENCH_RUN("ed_mul_lwreg") { - bn_rand_mod(k, n); - ed_rand(p); - BENCH_ADD(ed_mul_lwreg(q, p, k)); - } BENCH_END; -#endif - - BENCH_RUN("ed_mul_gen") { - bn_rand_mod(k, n); - BENCH_ADD(ed_mul_gen(q, k)); - } BENCH_END; - - BENCH_RUN("ed_mul_dig") { - bn_rand(k, RLC_POS, RLC_DIG); - bn_rand_mod(k, n); - BENCH_ADD(ed_mul_dig(p, q, k->dp[0])); - } - BENCH_END; - - for (int i = 0; i < RLC_ED_TABLE; i++) { - ed_new(t[i]); - } - - BENCH_RUN("ed_mul_pre") { - ed_rand(p); - BENCH_ADD(ed_mul_pre(t, p)); - } BENCH_END; - - BENCH_RUN("ed_mul_fix") { - bn_rand_mod(k, n); - ed_rand(p); - ed_mul_pre(t, p); - BENCH_ADD(ed_mul_fix(q, (const ed_t *)t, k)); - } BENCH_END; - - for (int i = 0; i < RLC_ED_TABLE; i++) { - ed_free(t[i]); - } - -#if ED_FIX == BASIC || !defined(STRIP) - for (int i = 0; i < RLC_ED_TABLE_BASIC; i++) { - ed_new(t[i]); - } - BENCH_RUN("ed_mul_pre_basic") { - ed_rand(p); - BENCH_ADD(ed_mul_pre_basic(t, p)); - } BENCH_END; - - BENCH_RUN("ed_mul_fix_basic") { - bn_rand_mod(k, n); - ed_rand(p); - ed_mul_pre_basic(t, p); - BENCH_ADD(ed_mul_fix_basic(q, (const ed_t *)t, k)); - } BENCH_END; - for (int i = 0; i < RLC_ED_TABLE_BASIC; i++) { - ed_free(t[i]); - } -#endif - -#if ED_FIX == COMBS || !defined(STRIP) - for (int i = 0; i < RLC_ED_TABLE_COMBS; i++) { - ed_new(t[i]); - } - BENCH_RUN("ed_mul_pre_combs") { - ed_rand(p); - BENCH_ADD(ed_mul_pre_combs(t, p)); - } BENCH_END; - - BENCH_RUN("ed_mul_fix_combs") { - bn_rand_mod(k, n); - ed_rand(p); - ed_mul_pre_combs(t, p); - BENCH_ADD(ed_mul_fix_combs(q, (const ed_t *)t, k)); - } BENCH_END; - for (int i = 0; i < RLC_ED_TABLE_COMBS; i++) { - ed_free(t[i]); - } -#endif - -#if ED_FIX == COMBD || !defined(STRIP) - for (int i = 0; i < RLC_ED_TABLE_COMBD; i++) { - ed_new(t[i]); - } - BENCH_RUN("ed_mul_pre_combd") { - BENCH_ADD(ed_mul_pre_combd(t, p)); - } BENCH_END; - - BENCH_RUN("ed_mul_fix_combd") { - bn_rand_mod(k, n); - ed_mul_pre_combd(t, p); - BENCH_ADD(ed_mul_fix_combd(q, (const ed_t *)t, k)); - } BENCH_END; - for (int i = 0; i < RLC_ED_TABLE_COMBD; i++) { - ed_free(t[i]); - } -#endif - -#if ED_FIX == LWNAF || !defined(STRIP) - for (int i = 0; i < RLC_ED_TABLE_LWNAF; i++) { - ed_new(t[i]); - } - BENCH_RUN("ed_mul_pre_lwnaf") { - ed_rand(p); - BENCH_ADD(ed_mul_pre_lwnaf(t, p)); - } BENCH_END; - - BENCH_RUN("ed_mul_fix_lwnaf") { - bn_rand_mod(k, n); - ed_rand(p); - ed_mul_pre_lwnaf(t, p); - BENCH_ADD(ed_mul_fix_lwnaf(q, (const ed_t *)t, k)); - } BENCH_END; - for (int i = 0; i < RLC_ED_TABLE_LWNAF; i++) { - ed_free(t[i]); - } -#endif - BENCH_RUN("ed_mul_sim") { - bn_rand_mod(k, n); - bn_rand_mod(l, n); - ed_rand(p); - ed_rand(q); - BENCH_ADD(ed_mul_sim(r, p, k, q, l)); - } BENCH_END; - -#if ED_SIM == BASIC || !defined(STRIP) - BENCH_RUN("ed_mul_sim_basic") { - bn_rand_mod(k, n); - bn_rand_mod(l, n); - ed_rand(p); - ed_rand(q); - BENCH_ADD(ed_mul_sim_basic(r, p, k, q, l)); - } BENCH_END; -#endif - -#if ED_SIM == TRICK || !defined(STRIP) - BENCH_RUN("ed_mul_sim_trick") { - bn_rand_mod(k, n); - bn_rand_mod(l, n); - ed_rand(p); - ed_rand(q); - BENCH_ADD(ed_mul_sim_trick(r, p, k, q, l)); - } BENCH_END; -#endif - -#if ED_SIM == INTER || !defined(STRIP) - BENCH_RUN("ed_mul_sim_inter") { - bn_rand_mod(k, n); - bn_rand_mod(l, n); - ed_rand(p); - ed_rand(q); - BENCH_ADD(ed_mul_sim_inter(r, p, k, q, l)); - } BENCH_END; -#endif - -#if ED_SIM == JOINT || !defined(STRIP) - BENCH_RUN("ed_mul_sim_joint") { - bn_rand_mod(k, n); - bn_rand_mod(l, n); - ed_rand(p); - ed_rand(q); - BENCH_ADD(ed_mul_sim_joint(r, p, k, q, l)); - } BENCH_END; -#endif - - BENCH_RUN("ed_mul_sim_gen") { - bn_rand_mod(k, n); - bn_rand_mod(l, n); - ed_rand(q); - BENCH_ADD(ed_mul_sim_gen(r, k, q, l)); - } BENCH_END; - - BENCH_RUN("ed_map") { - uint8_t msg[5]; - rand_bytes(msg, 5); - BENCH_ADD(ed_map(p, msg, 5)); - } BENCH_END; - - BENCH_RUN("ed_pck") { - ed_rand(p); - BENCH_ADD(ed_pck(q, p)); - } BENCH_END; - - BENCH_RUN("ed_upk") { - ed_rand(p); - BENCH_ADD(ed_upk(q, p)); - } BENCH_END; - - ed_free(p); - ed_free(q); - ed_free(r); - bn_free(k); - bn_free(l); - bn_free(n); -} - -static void bench(void) { - ed_param_print(); - util_banner("Utilities:", 1); - memory(); - util(); - util_banner("Arithmetic:", 1); - arith(); -} - -int main(void) { - int r0 = RLC_ERR; - - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - conf_print(); - util_banner("Benchmarks for the ED module:", 0); - r0 = ed_param_set_any(); - if (r0 == RLC_OK) { - bench(); - } - - if (r0 == RLC_ERR) { - if (ed_param_set_any() == RLC_ERR) { - RLC_THROW(ERR_NO_CURVE); - } - } - - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/bench/bench_ep.c b/src/dashbls/depends/relic/bench/bench_ep.c deleted file mode 100644 index 04ccdfc835ff..000000000000 --- a/src/dashbls/depends/relic/bench/bench_ep.c +++ /dev/null @@ -1,651 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2009 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for arithmetic on prime elliptic curves. - * - * @ingroup bench - */ - -#include - -#include "relic.h" -#include "relic_bench.h" - -static void memory(void) { - ep_t a[BENCH]; - - BENCH_FEW("ep_null", ep_null(a[i]), 1); - - BENCH_FEW("ep_new", ep_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - ep_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - ep_new(a[i]); - } - BENCH_FEW("ep_free", ep_free(a[i]), 1); - - (void)a; -} - -static void util(void) { - ep_t p, q, t[4]; - uint8_t bin[2 * RLC_FP_BYTES + 1]; - int l; - - ep_null(p); - ep_null(q); - for (int j = 0; j < 4; j++) { - ep_null(t[j]); - } - - ep_new(p); - ep_new(q); - for (int j = 0; j < 4; j++) { - ep_new(t[j]); - } - - BENCH_RUN("ep_is_infty") { - ep_rand(p); - BENCH_ADD(ep_is_infty(p)); - } BENCH_END; - - BENCH_RUN("ep_set_infty") { - ep_rand(p); - BENCH_ADD(ep_set_infty(p)); - } BENCH_END; - - BENCH_RUN("ep_copy") { - ep_rand(p); - ep_rand(q); - BENCH_ADD(ep_copy(p, q)); - } BENCH_END; - - BENCH_RUN("ep_norm") { - ep_rand(p); - ep_dbl(p, p); - BENCH_ADD(ep_norm(p, p)); - } BENCH_END; - - BENCH_RUN("ep_norm_sim (2)") { - ep_rand(t[0]); - ep_rand(t[1]); - ep_dbl(t[0], t[0]); - ep_dbl(t[1], t[1]); - BENCH_ADD(ep_norm_sim(t, t, 2)); - } BENCH_END; - - BENCH_RUN("ep_cmp") { - ep_rand(p); - ep_dbl(p, p); - ep_rand(q); - ep_dbl(q, q); - BENCH_ADD(ep_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("ep_cmp (1 norm)") { - ep_rand(p); - ep_dbl(p, p); - ep_rand(q); - BENCH_ADD(ep_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("ep_cmp (2 norm)") { - ep_rand(p); - ep_rand(q); - BENCH_ADD(ep_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("ep_rand") { - BENCH_ADD(ep_rand(p)); - } BENCH_END; - - BENCH_RUN("ep_blind") { - BENCH_ADD(ep_blind(p, p)); - } BENCH_END; - - BENCH_RUN("ep_rhs") { - ep_rand(p); - BENCH_ADD(ep_rhs(q->x, p)); - } BENCH_END; - - BENCH_RUN("ep_tab (4)") { - ep_rand(p); - BENCH_ADD(ep_tab(t, p, 4)); - } BENCH_END; - - BENCH_RUN("ep_on_curve") { - ep_rand(p); - BENCH_ADD(ep_on_curve(p)); - } BENCH_END; - - BENCH_RUN("ep_size_bin (0)") { - ep_rand(p); - BENCH_ADD(ep_size_bin(p, 0)); - } BENCH_END; - - BENCH_RUN("ep_size_bin (1)") { - ep_rand(p); - BENCH_ADD(ep_size_bin(p, 1)); - } BENCH_END; - - BENCH_RUN("ep_write_bin (0)") { - ep_rand(p); - l = ep_size_bin(p, 0); - BENCH_ADD(ep_write_bin(bin, l, p, 0)); - } BENCH_END; - - BENCH_RUN("ep_write_bin (1)") { - ep_rand(p); - l = ep_size_bin(p, 1); - BENCH_ADD(ep_write_bin(bin, l, p, 1)); - } BENCH_END; - - BENCH_RUN("ep_read_bin (0)") { - ep_rand(p); - l = ep_size_bin(p, 0); - ep_write_bin(bin, l, p, 0); - BENCH_ADD(ep_read_bin(p, bin, l)); - } BENCH_END; - - BENCH_RUN("ep_read_bin (1)") { - ep_rand(p); - l = ep_size_bin(p, 1); - ep_write_bin(bin, l, p, 1); - BENCH_ADD(ep_read_bin(p, bin, l)); - } BENCH_END; - - ep_free(p); - ep_free(q); - for (int j = 0; j < 4; j++) { - ep_free(t[j]); - } -} - -static void arith(void) { - ep_t p, q, r, t[RLC_EP_TABLE_MAX]; - bn_t k, l[2], n; - - ep_null(p); - ep_null(q); - ep_null(r); - for (int i = 0; i < RLC_EP_TABLE_MAX; i++) { - ep_null(t[i]); - } - - ep_new(p); - ep_new(q); - ep_new(r); - bn_new(k); - bn_new(n); - bn_new(l[0]); - bn_new(l[1]); - - ep_curve_get_ord(n); - - BENCH_RUN("ep_add") { - ep_rand(p); - ep_rand(q); - ep_add(p, p, q); - ep_rand(q); - ep_rand(p); - ep_add(q, q, p); - BENCH_ADD(ep_add(r, p, q)); - } BENCH_END; - -#if EP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("ep_add_basic") { - ep_rand(p); - ep_rand(q); - BENCH_ADD(ep_add_basic(r, p, q)); - } BENCH_END; -#endif - -#if EP_ADD == PROJC || !defined(STRIP) - BENCH_RUN("ep_add_projc") { - ep_rand(p); - ep_rand(q); - ep_add_projc(p, p, q); - ep_rand(q); - ep_rand(p); - ep_add_projc(q, q, p); - BENCH_ADD(ep_add_projc(r, p, q)); - } BENCH_END; - - BENCH_RUN("ep_add_projc (z2 = 1)") { - ep_rand(p); - ep_rand(q); - ep_add_projc(p, p, q); - ep_rand(q); - ep_norm(q, q); - BENCH_ADD(ep_add_projc(r, p, q)); - } BENCH_END; - - BENCH_RUN("ep_add_projc (z1,z2 = 1)") { - ep_rand(p); - ep_norm(p, p); - ep_rand(q); - ep_norm(q, q); - BENCH_ADD(ep_add_projc(r, p, q)); - } BENCH_END; -#endif - -#if EP_ADD == JACOB || !defined(STRIP) - BENCH_RUN("ep_add_jacob") { - ep_rand(p); - ep_rand(q); - ep_add_jacob(p, p, q); - ep_rand(q); - ep_rand(p); - ep_add_jacob(q, q, p); - BENCH_ADD(ep_add_jacob(r, p, q)); - } BENCH_END; - - BENCH_RUN("ep_add_jacob (z2 = 1)") { - ep_rand(p); - ep_rand(q); - ep_add_jacob(p, p, q); - ep_rand(q); - ep_norm(q, q); - BENCH_ADD(ep_add_jacob(r, p, q)); - } BENCH_END; - - BENCH_RUN("ep_add_jacob (z1,z2 = 1)") { - ep_rand(p); - ep_norm(p, p); - ep_rand(q); - ep_norm(q, q); - BENCH_ADD(ep_add_jacob(r, p, q)); - } BENCH_END; -#endif - - BENCH_RUN("ep_sub") { - ep_rand(p); - ep_rand(q); - ep_add(p, p, q); - ep_rand(q); - ep_rand(p); - ep_add(q, q, p); - BENCH_ADD(ep_sub(r, p, q)); - } BENCH_END; - - BENCH_RUN("ep_dbl") { - ep_rand(p); - ep_rand(q); - ep_add(p, p, q); - BENCH_ADD(ep_dbl(r, p)); - } BENCH_END; - -#if EP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("ep_dbl_basic") { - ep_rand(p); - BENCH_ADD(ep_dbl_basic(r, p)); - } BENCH_END; -#endif - -#if EP_ADD == PROJC || !defined(STRIP) - BENCH_RUN("ep_dbl_projc") { - ep_rand(p); - ep_rand(q); - ep_add_projc(p, p, q); - BENCH_ADD(ep_dbl_projc(r, p)); - } BENCH_END; - - BENCH_RUN("ep_dbl_projc (z1 = 1)") { - ep_rand(p); - ep_norm(p, p); - BENCH_ADD(ep_dbl_projc(r, p)); - } BENCH_END; -#endif - -#if EP_ADD == JACOB || !defined(STRIP) - BENCH_RUN("ep_dbl_jacob") { - ep_rand(p); - ep_rand(q); - ep_add_jacob(p, p, q); - BENCH_ADD(ep_dbl_jacob(r, p)); - } BENCH_END; - - BENCH_RUN("ep_dbl_jacob (z1 = 1)") { - ep_rand(p); - ep_norm(p, p); - BENCH_ADD(ep_dbl_jacob(r, p)); - } BENCH_END; -#endif - - BENCH_RUN("ep_neg") { - ep_rand(p); - ep_rand(q); - ep_add(p, p, q); - BENCH_ADD(ep_neg(r, p)); - } BENCH_END; - - BENCH_RUN("ep_mul") { - bn_rand_mod(k, n); - ep_rand(p); - BENCH_ADD(ep_mul(q, p, k)); - } BENCH_END; - -#if EP_MUL == BASIC || !defined(STRIP) - BENCH_RUN("ep_mul_basic") { - bn_rand_mod(k, n); - BENCH_ADD(ep_mul_basic(q, p, k)); - } BENCH_END; -#endif - -#if EP_MUL == SLIDE || !defined(STRIP) - BENCH_RUN("ep_mul_slide") { - bn_rand_mod(k, n); - ep_rand(p); - BENCH_ADD(ep_mul_slide(q, p, k)); - } BENCH_END; -#endif - -#if EP_MUL == MONTY || !defined(STRIP) - BENCH_RUN("ep_mul_monty") { - bn_rand_mod(k, n); - ep_rand(p); - BENCH_ADD(ep_mul_monty(q, p, k)); - } BENCH_END; -#endif - -#if EP_MUL == LWNAF || !defined(STRIP) - BENCH_RUN("ep_mul_lwnaf") { - bn_rand_mod(k, n); - ep_rand(p); - BENCH_ADD(ep_mul_lwnaf(q, p, k)); - } BENCH_END; -#endif - -#if EP_MUL == LWREG || !defined(STRIP) - BENCH_RUN("ep_mul_lwreg") { - bn_rand_mod(k, n); - ep_rand(p); - BENCH_ADD(ep_mul_lwreg(q, p, k)); - } BENCH_END; -#endif - - BENCH_RUN("ep_mul_gen") { - bn_rand_mod(k, n); - BENCH_ADD(ep_mul_gen(q, k)); - } BENCH_END; - - BENCH_RUN("ep_mul_dig") { - bn_rand(k, RLC_POS, RLC_DIG); - bn_rand_mod(k, n); - BENCH_ADD(ep_mul_dig(p, q, k->dp[0])); - } - BENCH_END; - - for (int i = 0; i < RLC_EP_TABLE; i++) { - ep_new(t[i]); - } - - BENCH_RUN("ep_mul_pre") { - ep_rand(p); - BENCH_ADD(ep_mul_pre(t, p)); - } BENCH_END; - - BENCH_RUN("ep_mul_fix") { - bn_rand_mod(k, n); - ep_rand(p); - ep_mul_pre(t, p); - BENCH_ADD(ep_mul_fix(q, (const ep_t *)t, k)); - } BENCH_END; - - for (int i = 0; i < RLC_EP_TABLE; i++) { - ep_free(t[i]); - } - -#if EP_FIX == BASIC || !defined(STRIP) - for (int i = 0; i < RLC_EP_TABLE_BASIC; i++) { - ep_new(t[i]); - } - BENCH_RUN("ep_mul_pre_basic") { - ep_rand(p); - BENCH_ADD(ep_mul_pre_basic(t, p)); - } BENCH_END; - - BENCH_RUN("ep_mul_fix_basic") { - bn_rand_mod(k, n); - ep_rand(p); - ep_mul_pre_basic(t, p); - BENCH_ADD(ep_mul_fix_basic(q, (const ep_t *)t, k)); - } BENCH_END; - for (int i = 0; i < RLC_EP_TABLE_BASIC; i++) { - ep_free(t[i]); - } -#endif - -#if EP_FIX == COMBS || !defined(STRIP) - for (int i = 0; i < RLC_EP_TABLE_COMBS; i++) { - ep_new(t[i]); - } - BENCH_RUN("ep_mul_pre_combs") { - ep_rand(p); - BENCH_ADD(ep_mul_pre_combs(t, p)); - } BENCH_END; - - BENCH_RUN("ep_mul_fix_combs") { - bn_rand_mod(k, n); - ep_rand(p); - ep_mul_pre_combs(t, p); - BENCH_ADD(ep_mul_fix_combs(q, (const ep_t *)t, k)); - } BENCH_END; - for (int i = 0; i < RLC_EP_TABLE_COMBS; i++) { - ep_free(t[i]); - } -#endif - -#if EP_FIX == COMBD || !defined(STRIP) - for (int i = 0; i < RLC_EP_TABLE_COMBD; i++) { - ep_new(t[i]); - } - BENCH_RUN("ep_mul_pre_combd") { - BENCH_ADD(ep_mul_pre_combd(t, p)); - } BENCH_END; - - BENCH_RUN("ep_mul_fix_combd") { - bn_rand_mod(k, n); - ep_mul_pre_combd(t, p); - BENCH_ADD(ep_mul_fix_combd(q, (const ep_t *)t, k)); - } BENCH_END; - for (int i = 0; i < RLC_EP_TABLE_COMBD; i++) { - ep_free(t[i]); - } -#endif - -#if EP_FIX == LWNAF || !defined(STRIP) - for (int i = 0; i < RLC_EP_TABLE_LWNAF; i++) { - ep_new(t[i]); - } - BENCH_RUN("ep_mul_pre_lwnaf") { - ep_rand(p); - BENCH_ADD(ep_mul_pre_lwnaf(t, p)); - } BENCH_END; - - BENCH_RUN("ep_mul_fix_lwnaf") { - bn_rand_mod(k, n); - ep_rand(p); - ep_mul_pre_lwnaf(t, p); - BENCH_ADD(ep_mul_fix_lwnaf(q, (const ep_t *)t, k)); - } BENCH_END; - for (int i = 0; i < RLC_EP_TABLE_LWNAF; i++) { - ep_free(t[i]); - } -#endif - BENCH_RUN("ep_mul_sim") { - bn_rand_mod(l[0], n); - bn_rand_mod(l[1], n); - ep_rand(p); - ep_rand(q); - BENCH_ADD(ep_mul_sim(r, p, l[0], q, l[1])); - } BENCH_END; - -#if EP_SIM == BASIC || !defined(STRIP) - BENCH_RUN("ep_mul_sim_basic") { - bn_rand_mod(l[0], n); - bn_rand_mod(l[1], n); - ep_rand(p); - ep_rand(q); - BENCH_ADD(ep_mul_sim_basic(r, p, l[0], q, l[1])); - } BENCH_END; -#endif - -#if EP_SIM == TRICK || !defined(STRIP) - BENCH_RUN("ep_mul_sim_trick") { - bn_rand_mod(l[0], n); - bn_rand_mod(l[1], n); - ep_rand(p); - ep_rand(q); - BENCH_ADD(ep_mul_sim_trick(r, p, l[0], q, l[1])); - } BENCH_END; -#endif - -#if EP_SIM == INTER || !defined(STRIP) - BENCH_RUN("ep_mul_sim_inter") { - bn_rand_mod(l[0], n); - bn_rand_mod(l[1], n); - ep_rand(p); - ep_rand(q); - BENCH_ADD(ep_mul_sim_inter(r, p, l[0], q, l[1])); - } BENCH_END; -#endif - -#if EP_SIM == JOINT || !defined(STRIP) - BENCH_RUN("ep_mul_sim_joint") { - bn_rand_mod(l[0], n); - bn_rand_mod(l[1], n); - ep_rand(p); - ep_rand(q); - BENCH_ADD(ep_mul_sim_joint(r, p, l[0], q, l[1])); - } BENCH_END; -#endif - - BENCH_RUN("ep_mul_sim_gen") { - bn_rand_mod(l[0], n); - bn_rand_mod(l[1], n); - ep_rand(q); - BENCH_ADD(ep_mul_sim_gen(r, l[0], q, l[1])); - } BENCH_END; - - for (int i = 0; i < 2; i++) { - ep_new(t[i]); - } - - BENCH_RUN("ep_mul_sim_lot (2)") { - bn_rand_mod(l[0], n); - bn_rand_mod(l[1], n); - ep_rand(t[0]); - ep_rand(t[1]); - BENCH_ADD(ep_mul_sim_lot(r, t, l, 2)); - } BENCH_END; - - for (int i = 0; i < 2; i++) { - ep_free(t[i]); - } - - BENCH_RUN("ep_map") { - uint8_t msg[5]; - rand_bytes(msg, 5); - BENCH_ADD(ep_map(p, msg, 5)); - } BENCH_END; - - BENCH_RUN("ep_pck") { - ep_rand(p); - BENCH_ADD(ep_pck(q, p)); - } BENCH_END; - - BENCH_RUN("ep_upk") { - ep_rand(p); - BENCH_ADD(ep_upk(q, p)); - } BENCH_END; - - ep_free(p); - ep_free(q); - ep_free(r); - bn_free(k); - bn_free(l[0]); - bn_free(l[1]); - bn_free(n); -} - -static void bench(void) { - ep_param_print(); - util_banner("Utilities:", 1); - memory(); - util(); - util_banner("Arithmetic:", 1); - arith(); -} - -int main(void) { - int r0 = RLC_ERR, r1 = RLC_ERR, r2 = RLC_ERR, r3 = RLC_ERR;; - - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - conf_print(); - util_banner("Benchmarks for the EP module:", 0); - -#if defined(EP_PLAIN) - r0 = ep_param_set_any_plain(); - if (r0 == RLC_OK) { - bench(); - } -#endif - -#if defined(EP_ENDOM) - r1 = ep_param_set_any_endom(); - if (r1 == RLC_OK) { - bench(); - } -#endif - - r2 = ep_param_set_any_pairf(); - if (r2 == RLC_OK) { - bench(); - } - -#if defined(EP_SUPER) - r3 = ep_param_set_any_super(); - if (r3 == RLC_OK) { - bench(); - } -#endif - - if (r0 == RLC_ERR && r1 == RLC_ERR && r2 == RLC_ERR && r3 == RLC_ERR) { - if (ep_param_set_any() == RLC_ERR) { - RLC_THROW(ERR_NO_CURVE); - } - } - - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/bench/bench_epx.c b/src/dashbls/depends/relic/bench/bench_epx.c deleted file mode 100644 index 487d3dad675c..000000000000 --- a/src/dashbls/depends/relic/bench/bench_epx.c +++ /dev/null @@ -1,1108 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2012 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for elliptic curves defined over extensions of prime fields. - * - * @ingroup bench - */ - -#include - -#include "relic.h" -#include "relic_bench.h" - -static void memory2(void) { - ep4_t a[BENCH]; - - BENCH_FEW("ep4_null", ep4_null(a[i]), 1); - - BENCH_FEW("ep4_new", ep4_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - ep4_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - ep4_new(a[i]); - } - BENCH_FEW("ep4_free", ep4_free(a[i]), 1); - - (void)a; -} - -static void util2(void) { - ep2_t p, q, t[2]; - uint8_t bin[4 * RLC_FP_BYTES + 1]; - int l; - - ep2_null(p); - ep2_null(q); - ep2_null(t[0]); - ep2_null(t[1]); - - ep2_new(p); - ep2_new(q); - ep2_new(t[0]); - ep2_new(t[1]); - - BENCH_RUN("ep2_is_infty") { - ep2_rand(p); - BENCH_ADD(ep2_is_infty(p)); - } - BENCH_END; - - BENCH_RUN("ep2_set_infty") { - ep2_rand(p); - BENCH_ADD(ep2_set_infty(p)); - } - BENCH_END; - - BENCH_RUN("ep2_copy") { - ep2_rand(p); - ep2_rand(q); - BENCH_ADD(ep2_copy(p, q)); - } - BENCH_END; - - BENCH_RUN("ep2_cmp") { - ep2_rand(p); - ep2_dbl(p, p); - ep2_rand(q); - ep2_dbl(q, q); - BENCH_ADD(ep2_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("ep2_norm") { - ep2_rand(p); - ep2_dbl(p, p); - BENCH_ADD(ep2_norm(p, p)); - } BENCH_END; - - BENCH_RUN("ep2_norm_sim (2)") { - ep2_rand(t[0]); - ep2_rand(t[1]); - ep2_dbl(t[0], t[0]); - ep2_dbl(t[1], t[1]); - BENCH_ADD(ep2_norm_sim(t, t, 2)); - } BENCH_END; - - BENCH_RUN("ep2_cmp (1 norm)") { - ep2_rand(p); - ep2_dbl(p, p); - ep2_rand(q); - BENCH_ADD(ep2_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("ep2_cmp (2 norm)") { - ep2_rand(p); - ep2_rand(q); - BENCH_ADD(ep2_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("ep2_rand") { - BENCH_ADD(ep2_rand(p)); - } - BENCH_END; - - BENCH_RUN("ep2_blind") { - BENCH_ADD(ep2_blind(p, p)); - } - BENCH_END; - - BENCH_RUN("ep2_on_curve") { - ep2_rand(p); - BENCH_ADD(ep2_on_curve(p)); - } BENCH_END; - - BENCH_RUN("ep2_size_bin (0)") { - ep2_rand(p); - BENCH_ADD(ep2_size_bin(p, 0)); - } BENCH_END; - - BENCH_RUN("ep2_size_bin (1)") { - ep2_rand(p); - BENCH_ADD(ep2_size_bin(p, 1)); - } BENCH_END; - - BENCH_RUN("ep2_write_bin (0)") { - ep2_rand(p); - l = ep2_size_bin(p, 0); - BENCH_ADD(ep2_write_bin(bin, l, p, 0)); - } BENCH_END; - - BENCH_RUN("ep2_write_bin (1)") { - ep2_rand(p); - l = ep2_size_bin(p, 1); - BENCH_ADD(ep2_write_bin(bin, l, p, 1)); - } BENCH_END; - - BENCH_RUN("ep2_read_bin (0)") { - ep2_rand(p); - l = ep2_size_bin(p, 0); - ep2_write_bin(bin, l, p, 0); - BENCH_ADD(ep2_read_bin(p, bin, l)); - } BENCH_END; - - BENCH_RUN("ep2_read_bin (1)") { - ep2_rand(p); - l = ep2_size_bin(p, 1); - ep2_write_bin(bin, l, p, 1); - BENCH_ADD(ep2_read_bin(p, bin, l)); - } BENCH_END; - - ep2_free(p); - ep2_free(q); - ep2_free(t[0]); - ep2_free(t[1]); -} - -static void arith2(void) { - ep2_t p, q, r, t[RLC_EPX_TABLE_MAX]; - bn_t k, n, l[2]; - fp2_t s; - - ep2_null(p); - ep2_null(q); - ep2_null(r); - bn_null(k); - bn_null(n); - fp2_null(s); - for (int i = 0; i < RLC_EPX_TABLE_MAX; i++) { - ep2_null(t[i]); - } - - ep2_new(p); - ep2_new(q); - ep2_new(r); - bn_new(k); - bn_new(n); - bn_new(l[0]); - bn_new(l[1]); - fp2_new(s); - - ep2_curve_get_ord(n); - - BENCH_RUN("ep2_add") { - ep2_rand(p); - ep2_rand(q); - ep2_add(p, p, q); - ep2_rand(q); - ep2_rand(p); - ep2_add(q, q, p); - BENCH_ADD(ep2_add(r, p, q)); - } - BENCH_END; - -#if EP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("ep2_add_basic") { - ep2_rand(p); - ep2_rand(q); - BENCH_ADD(ep2_add_basic(r, p, q)); - } - BENCH_END; - - BENCH_RUN("ep2_add_slp_basic") { - ep2_rand(p); - ep2_rand(q); - BENCH_ADD(ep2_add_slp_basic(r, s, p, q)); - } - BENCH_END; -#endif - -#if EP_ADD == PROJC || !defined(STRIP) - BENCH_RUN("ep2_add_projc") { - ep2_rand(p); - ep2_rand(q); - ep2_add_projc(p, p, q); - ep2_rand(q); - ep2_rand(p); - ep2_add_projc(q, q, p); - BENCH_ADD(ep2_add_projc(r, p, q)); - } - BENCH_END; - - BENCH_RUN("ep2_add_projc (z2 = 1)") { - ep2_rand(p); - ep2_rand(q); - ep2_add_projc(p, p, q); - ep2_rand(q); - ep2_norm(q, q); - BENCH_ADD(ep2_add_projc(r, p, q)); - } - BENCH_END; - - BENCH_RUN("ep2_add_projc (z1,z2 = 1)") { - ep2_rand(p); - ep2_norm(p, p); - ep2_rand(q); - ep2_norm(q, q); - BENCH_ADD(ep2_add_projc(r, p, q)); - } - BENCH_END; -#endif - - BENCH_RUN("ep2_sub") { - ep2_rand(p); - ep2_rand(q); - ep2_add(p, p, q); - ep2_rand(q); - ep2_rand(p); - ep2_add(q, q, p); - BENCH_ADD(ep2_sub(r, p, q)); - } - BENCH_END; - - BENCH_RUN("ep2_dbl") { - ep2_rand(p); - ep2_rand(q); - ep2_add(p, p, q); - BENCH_ADD(ep2_dbl(r, p)); - } - BENCH_END; - -#if EP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("ep2_dbl_basic") { - ep2_rand(p); - BENCH_ADD(ep2_dbl_basic(r, p)); - } - BENCH_END; - - BENCH_RUN("ep2_dbl_slp_basic") { - ep2_rand(p); - BENCH_ADD(ep2_dbl_slp_basic(r, s, p)); - } - BENCH_END; -#endif - -#if EP_ADD == PROJC || !defined(STRIP) - BENCH_RUN("ep2_dbl_projc") { - ep2_rand(p); - ep2_rand(q); - ep2_add_projc(p, p, q); - BENCH_ADD(ep2_dbl_projc(r, p)); - } - BENCH_END; - - BENCH_RUN("ep2_dbl_projc (z1 = 1)") { - ep2_rand(p); - ep2_norm(p, p); - BENCH_ADD(ep2_dbl_projc(r, p)); - } - BENCH_END; -#endif - - BENCH_RUN("ep2_neg") { - ep2_rand(p); - ep2_rand(q); - ep2_add(p, p, q); - BENCH_ADD(ep2_neg(r, p)); - } - BENCH_END; - - BENCH_RUN("ep2_mul") { - bn_rand_mod(k, n); - BENCH_ADD(ep2_mul(q, p, k)); - } BENCH_END; - -#if EP_MUL == BASIC || !defined(STRIP) - BENCH_RUN("ep2_mul_basic") { - bn_rand_mod(k, n); - BENCH_ADD(ep2_mul_basic(q, p, k)); - } BENCH_END; -#endif - -#if EP_MUL == SLIDE || !defined(STRIP) - BENCH_RUN("ep2_mul_slide") { - bn_rand_mod(k, n); - ep2_rand(p); - BENCH_ADD(ep2_mul_slide(q, p, k)); - } BENCH_END; -#endif - -#if EP_MUL == MONTY || !defined(STRIP) - BENCH_RUN("ep2_mul_monty") { - bn_rand_mod(k, n); - ep2_rand(p); - BENCH_ADD(ep2_mul_monty(q, p, k)); - } BENCH_END; -#endif - -#if EP_MUL == LWNAF || !defined(STRIP) - BENCH_RUN("ep2_mul_lwnaf") { - bn_rand_mod(k, n); - ep2_rand(p); - BENCH_ADD(ep2_mul_lwnaf(q, p, k)); - } BENCH_END; -#endif - - BENCH_RUN("ep2_mul_gen") { - bn_rand_mod(k, n); - BENCH_ADD(ep2_mul_gen(q, k)); - } BENCH_END; - - BENCH_RUN("ep2_mul_dig") { - bn_rand(k, RLC_POS, RLC_DIG); - bn_rand_mod(k, n); - BENCH_ADD(ep2_mul_dig(p, q, k->dp[0])); - } - BENCH_END; - - for (int i = 0; i < RLC_EPX_TABLE_MAX; i++) { - ep2_new(t[i]); - } - - BENCH_RUN("ep2_mul_pre") { - ep2_rand(p); - BENCH_ADD(ep2_mul_pre(t, p)); - } BENCH_END; - - BENCH_RUN("ep2_mul_fix") { - bn_rand_mod(k, n); - ep2_rand(p); - ep2_mul_pre(t, p); - BENCH_ADD(ep2_mul_fix(q, t, k)); - } BENCH_END; - - for (int i = 0; i < RLC_EPX_TABLE_MAX; i++) { - ep2_free(t[i]); - } - -#if EP_FIX == BASIC || !defined(STRIP) - for (int i = 0; i < RLC_EPX_TABLE_BASIC; i++) { - ep2_new(t[i]); - } - BENCH_RUN("ep2_mul_pre_basic") { - ep2_rand(p); - BENCH_ADD(ep2_mul_pre_basic(t, p)); - } BENCH_END; - - BENCH_RUN("ep2_mul_fix_basic") { - bn_rand_mod(k, n); - ep2_rand(p); - ep2_mul_pre_basic(t, p); - BENCH_ADD(ep2_mul_fix_basic(q, t, k)); - } BENCH_END; - for (int i = 0; i < RLC_EPX_TABLE_BASIC; i++) { - ep2_free(t[i]); - } -#endif - -#if EP_FIX == COMBS || !defined(STRIP) - for (int i = 0; i < RLC_EPX_TABLE_COMBS; i++) { - ep2_new(t[i]); - } - BENCH_RUN("ep2_mul_pre_combs") { - ep2_rand(p); - BENCH_ADD(ep2_mul_pre_combs(t, p)); - } BENCH_END; - - BENCH_RUN("ep2_mul_fix_combs") { - bn_rand_mod(k, n); - ep2_rand(p); - ep2_mul_pre_combs(t, p); - BENCH_ADD(ep2_mul_fix_combs(q, t, k)); - } BENCH_END; - for (int i = 0; i < RLC_EPX_TABLE_COMBS; i++) { - ep2_free(t[i]); - } -#endif - -#if EP_FIX == COMBD || !defined(STRIP) - for (int i = 0; i < RLC_EPX_TABLE_COMBD; i++) { - ep2_new(t[i]); - } - BENCH_RUN("ep2_mul_pre_combd") { - BENCH_ADD(ep2_mul_pre_combd(t, p)); - } BENCH_END; - - BENCH_RUN("ep2_mul_fix_combd") { - bn_rand_mod(k, n); - ep2_mul_pre_combd(t, p); - BENCH_ADD(ep2_mul_fix_combd(q, t, k)); - } BENCH_END; - for (int i = 0; i < RLC_EPX_TABLE_COMBD; i++) { - ep2_free(t[i]); - } -#endif - -#if EP_FIX == LWNAF || !defined(STRIP) - for (int i = 0; i < RLC_EPX_TABLE_LWNAF; i++) { - ep2_new(t[i]); - } - BENCH_RUN("ep2_mul_pre_lwnaf") { - ep2_rand(p); - BENCH_ADD(ep2_mul_pre_lwnaf(t, p)); - } BENCH_END; - - BENCH_RUN("ep2_mul_fix_lwnaf") { - bn_rand_mod(k, n); - ep2_rand(p); - ep2_mul_pre_lwnaf(t, p); - BENCH_ADD(ep2_mul_fix_lwnaf(q, t, k)); - } BENCH_END; - for (int i = 0; i < RLC_EPX_TABLE_LWNAF; i++) { - ep2_free(t[i]); - } -#endif - - BENCH_RUN("ep2_mul_sim") { - bn_rand_mod(l[0], n); - bn_rand_mod(l[1], n); - ep2_rand(p); - ep2_rand(q); - BENCH_ADD(ep2_mul_sim(r, p, l[0], q, l[1])); - } BENCH_END; - -#if EP_SIM == BASIC || !defined(STRIP) - BENCH_RUN("ep2_mul_sim_basic") { - bn_rand_mod(l[0], n); - bn_rand_mod(l[1], n); - ep2_rand(p); - ep2_rand(q); - BENCH_ADD(ep2_mul_sim_basic(r, p, l[0], q, l[1])); - } BENCH_END; -#endif - -#if EP_SIM == TRICK || !defined(STRIP) - BENCH_RUN("ep2_mul_sim_trick") { - bn_rand_mod(l[0], n); - bn_rand_mod(l[1], n); - ep2_rand(p); - ep2_rand(q); - BENCH_ADD(ep2_mul_sim_trick(r, p, l[0], q, l[1])); - } BENCH_END; -#endif - -#if EP_SIM == INTER || !defined(STRIP) - BENCH_RUN("ep2_mul_sim_inter") { - bn_rand_mod(l[0], n); - bn_rand_mod(l[1], n); - ep2_rand(p); - ep2_rand(q); - BENCH_ADD(ep2_mul_sim_inter(r, p, l[0], q, l[1])); - } BENCH_END; -#endif - -#if EP_SIM == JOINT || !defined(STRIP) - BENCH_RUN("ep2_mul_sim_joint") { - bn_rand_mod(l[0], n); - bn_rand_mod(l[1], n); - ep2_rand(p); - ep2_rand(q); - BENCH_ADD(ep2_mul_sim_joint(r, p, l[0], q, l[1])); - } BENCH_END; -#endif - - BENCH_RUN("ep2_mul_sim_gen") { - bn_rand_mod(l[0], n); - bn_rand_mod(l[1], n); - ep2_rand(q); - BENCH_ADD(ep2_mul_sim_gen(r, l[0], q, l[1])); - } BENCH_END; - - for (int i = 0; i < 2; i++) { - ep2_new(t[i]); - } - - BENCH_RUN("ep2_mul_sim_lot (2)") { - bn_rand_mod(l[0], n); - bn_rand_mod(l[1], n); - ep2_rand(t[0]); - ep2_rand(t[1]); - BENCH_ADD(ep2_mul_sim_lot(r, t, l, 2)); - } BENCH_END; - - for (int i = 0; i < 2; i++) { - ep2_free(t[i]); - } - - BENCH_RUN("ep2_frb") { - ep2_rand(q); - BENCH_ADD(ep2_frb(r, q, 1)); - } BENCH_END; - - BENCH_RUN("ep2_map") { - uint8_t msg[5]; - rand_bytes(msg, 5); - BENCH_ADD(ep2_map(p, msg, 5)); - } BENCH_END; - - BENCH_RUN("ep2_pck") { - ep2_rand(p); - BENCH_ADD(ep2_pck(q, p)); - } BENCH_END; - - BENCH_RUN("ep2_upk") { - ep2_rand(p); - BENCH_ADD(ep2_upk(q, p)); - } BENCH_END; - - ep2_free(p); - ep2_free(q); - ep2_free(r); - bn_free(k); - bn_free(n); - bn_free(l[0]); - bn_free(l[1]); - fp2_free(s); -} - -static void memory4(void) { - ep4_t a[BENCH]; - - BENCH_FEW("ep4_null", ep4_null(a[i]), 1); - - BENCH_FEW("ep4_new", ep4_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - ep4_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - ep4_new(a[i]); - } - BENCH_FEW("ep4_free", ep4_free(a[i]), 1); - - (void)a; -} - -static void util4(void) { - ep4_t p, q, t[2]; - uint8_t bin[8 * RLC_FP_BYTES + 1]; - int l; - - ep4_null(p); - ep4_null(q); - ep4_null(t[0]); - ep4_null(t[1]); - - ep4_new(p); - ep4_new(q); - ep4_new(t[0]); - ep4_new(t[1]); - - BENCH_RUN("ep4_is_infty") { - ep4_rand(p); - BENCH_ADD(ep4_is_infty(p)); - } - BENCH_END; - - BENCH_RUN("ep4_set_infty") { - ep4_rand(p); - BENCH_ADD(ep4_set_infty(p)); - } - BENCH_END; - - BENCH_RUN("ep4_copy") { - ep4_rand(p); - ep4_rand(q); - BENCH_ADD(ep4_copy(p, q)); - } - BENCH_END; - - BENCH_RUN("ep4_cmp") { - ep4_rand(p); - ep4_dbl(p, p); - ep4_rand(q); - ep4_dbl(q, q); - BENCH_ADD(ep4_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("ep4_norm") { - ep4_rand(p); - ep4_dbl(p, p); - BENCH_ADD(ep4_norm(p, p)); - } BENCH_END; - - BENCH_RUN("ep4_norm_sim (2)") { - ep4_rand(t[0]); - ep4_rand(t[1]); - ep4_dbl(t[0], t[0]); - ep4_dbl(t[1], t[1]); - BENCH_ADD(ep4_norm_sim(t, t, 2)); - } BENCH_END; - - BENCH_RUN("ep4_cmp (1 norm)") { - ep4_rand(p); - ep4_dbl(p, p); - ep4_rand(q); - BENCH_ADD(ep4_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("ep4_cmp (2 norm)") { - ep4_rand(p); - ep4_rand(q); - BENCH_ADD(ep4_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("ep4_rand") { - BENCH_ADD(ep4_rand(p)); - } - BENCH_END; - - BENCH_RUN("ep4_blind") { - BENCH_ADD(ep4_blind(p, p)); - } - BENCH_END; - - BENCH_RUN("ep4_on_curve") { - ep4_rand(p); - BENCH_ADD(ep4_on_curve(p)); - } BENCH_END; - - BENCH_RUN("ep4_size_bin") { - ep4_rand(p); - BENCH_ADD(ep4_size_bin(p, 0)); - } BENCH_END; - - BENCH_RUN("ep4_write_bin") { - ep4_rand(p); - l = ep4_size_bin(p, 0); - BENCH_ADD(ep4_write_bin(bin, l, p, 0)); - } BENCH_END; - - BENCH_RUN("ep4_read_bin") { - ep4_rand(p); - l = ep4_size_bin(p, 0); - ep4_write_bin(bin, l, p, 0); - BENCH_ADD(ep4_read_bin(p, bin, l)); - } BENCH_END; - - ep4_free(p); - ep4_free(q); - ep4_free(t[0]); - ep4_free(t[1]); -} - -static void arith4(void) { - ep4_t p, q, r, t[RLC_EPX_TABLE_MAX]; - bn_t k, n, l; - fp4_t s; - - ep4_null(p); - ep4_null(q); - ep4_null(r); - bn_null(k); - bn_null(n); - fp4_null(s); - for (int i = 0; i < RLC_EPX_TABLE_MAX; i++) { - ep4_null(t[i]); - } - - ep4_new(p); - ep4_new(q); - ep4_new(r); - bn_new(k); - bn_new(n); - bn_new(l); - fp4_new(s); - - ep4_curve_get_ord(n); - - BENCH_RUN("ep4_add") { - ep4_rand(p); - ep4_rand(q); - ep4_add(p, p, q); - ep4_rand(q); - ep4_rand(p); - ep4_add(q, q, p); - BENCH_ADD(ep4_add(r, p, q)); - } - BENCH_END; - -#if EP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("ep4_add_basic") { - ep4_rand(p); - ep4_rand(q); - BENCH_ADD(ep4_add_basic(r, p, q)); - } - BENCH_END; - - BENCH_RUN("ep4_add_slp_basic") { - ep4_rand(p); - ep4_rand(q); - BENCH_ADD(ep4_add_slp_basic(r, s, p, q)); - } - BENCH_END; -#endif - -#if EP_ADD == PROJC || !defined(STRIP) - BENCH_RUN("ep4_add_projc") { - ep4_rand(p); - ep4_rand(q); - ep4_add_projc(p, p, q); - ep4_rand(q); - ep4_rand(p); - ep4_add_projc(q, q, p); - BENCH_ADD(ep4_add_projc(r, p, q)); - } - BENCH_END; - - BENCH_RUN("ep4_add_projc (z2 = 1)") { - ep4_rand(p); - ep4_rand(q); - ep4_add_projc(p, p, q); - ep4_rand(q); - ep4_norm(q, q); - BENCH_ADD(ep4_add_projc(r, p, q)); - } - BENCH_END; - - BENCH_RUN("ep4_add_projc (z1,z2 = 1)") { - ep4_rand(p); - ep4_norm(p, p); - ep4_rand(q); - ep4_norm(q, q); - BENCH_ADD(ep4_add_projc(r, p, q)); - } - BENCH_END; -#endif - - BENCH_RUN("ep4_sub") { - ep4_rand(p); - ep4_rand(q); - ep4_add(p, p, q); - ep4_rand(q); - ep4_rand(p); - ep4_add(q, q, p); - BENCH_ADD(ep4_sub(r, p, q)); - } - BENCH_END; - - BENCH_RUN("ep4_dbl") { - ep4_rand(p); - ep4_rand(q); - ep4_add(p, p, q); - BENCH_ADD(ep4_dbl(r, p)); - } - BENCH_END; - -#if EP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("ep4_dbl_basic") { - ep4_rand(p); - BENCH_ADD(ep4_dbl_basic(r, p)); - } - BENCH_END; - - BENCH_RUN("ep4_dbl_slp_basic") { - ep4_rand(p); - BENCH_ADD(ep4_dbl_slp_basic(r, s, p)); - } - BENCH_END; -#endif - -#if EP_ADD == PROJC || !defined(STRIP) - BENCH_RUN("ep4_dbl_projc") { - ep4_rand(p); - ep4_rand(q); - ep4_add_projc(p, p, q); - BENCH_ADD(ep4_dbl_projc(r, p)); - } - BENCH_END; - - BENCH_RUN("ep4_dbl_projc (z1 = 1)") { - ep4_rand(p); - ep4_norm(p, p); - BENCH_ADD(ep4_dbl_projc(r, p)); - } - BENCH_END; -#endif - - BENCH_RUN("ep4_neg") { - ep4_rand(p); - ep4_rand(q); - ep4_add(p, p, q); - BENCH_ADD(ep4_neg(r, p)); - } - BENCH_END; - - BENCH_RUN("ep4_mul") { - bn_rand_mod(k, n); - BENCH_ADD(ep4_mul(q, p, k)); - } BENCH_END; - -#if EP_MUL == BASIC || !defined(STRIP) - BENCH_RUN("ep4_mul_basic") { - bn_rand_mod(k, n); - BENCH_ADD(ep4_mul_basic(q, p, k)); - } BENCH_END; -#endif - -#if EP_MUL == SLIDE || !defined(STRIP) - BENCH_RUN("ep4_mul_slide") { - bn_rand_mod(k, n); - ep4_rand(p); - BENCH_ADD(ep4_mul_slide(q, p, k)); - } BENCH_END; -#endif - -#if EP_MUL == MONTY || !defined(STRIP) - BENCH_RUN("ep4_mul_monty") { - bn_rand_mod(k, n); - ep4_rand(p); - BENCH_ADD(ep4_mul_monty(q, p, k)); - } BENCH_END; -#endif - -#if EP_MUL == LWNAF || !defined(STRIP) - BENCH_RUN("ep4_mul_lwnaf") { - bn_rand_mod(k, n); - ep4_rand(p); - BENCH_ADD(ep4_mul_lwnaf(q, p, k)); - } BENCH_END; -#endif - - BENCH_RUN("ep4_mul_gen") { - bn_rand_mod(k, n); - BENCH_ADD(ep4_mul_gen(q, k)); - } BENCH_END; - - BENCH_RUN("ep4_mul_dig") { - bn_rand(k, RLC_POS, RLC_DIG); - bn_rand_mod(k, n); - BENCH_ADD(ep4_mul_dig(p, q, k->dp[0])); - } - BENCH_END; - - for (int i = 0; i < RLC_EPX_TABLE_MAX; i++) { - ep4_new(t[i]); - } - - BENCH_RUN("ep4_mul_pre") { - ep4_rand(p); - BENCH_ADD(ep4_mul_pre(t, p)); - } BENCH_END; - - BENCH_RUN("ep4_mul_fix") { - bn_rand_mod(k, n); - ep4_rand(p); - ep4_mul_pre(t, p); - BENCH_ADD(ep4_mul_fix(q, t, k)); - } BENCH_END; - - for (int i = 0; i < RLC_EPX_TABLE_MAX; i++) { - ep4_free(t[i]); - } - -#if EP_FIX == BASIC || !defined(STRIP) - for (int i = 0; i < RLC_EPX_TABLE_BASIC; i++) { - ep4_new(t[i]); - } - BENCH_RUN("ep4_mul_pre_basic") { - ep4_rand(p); - BENCH_ADD(ep4_mul_pre_basic(t, p)); - } BENCH_END; - - BENCH_RUN("ep4_mul_fix_basic") { - bn_rand_mod(k, n); - ep4_rand(p); - ep4_mul_pre_basic(t, p); - BENCH_ADD(ep4_mul_fix_basic(q, t, k)); - } BENCH_END; - for (int i = 0; i < RLC_EPX_TABLE_BASIC; i++) { - ep4_free(t[i]); - } -#endif - -#if EP_FIX == COMBS || !defined(STRIP) - for (int i = 0; i < RLC_EPX_TABLE_COMBS; i++) { - ep4_new(t[i]); - } - BENCH_RUN("ep4_mul_pre_combs") { - ep4_rand(p); - BENCH_ADD(ep4_mul_pre_combs(t, p)); - } BENCH_END; - - BENCH_RUN("ep4_mul_fix_combs") { - bn_rand_mod(k, n); - ep4_rand(p); - ep4_mul_pre_combs(t, p); - BENCH_ADD(ep4_mul_fix_combs(q, t, k)); - } BENCH_END; - for (int i = 0; i < RLC_EPX_TABLE_COMBS; i++) { - ep4_free(t[i]); - } -#endif - -#if EP_FIX == COMBD || !defined(STRIP) - for (int i = 0; i < RLC_EPX_TABLE_COMBD; i++) { - ep4_new(t[i]); - } - BENCH_RUN("ep4_mul_pre_combd") { - BENCH_ADD(ep4_mul_pre_combd(t, p)); - } BENCH_END; - - BENCH_RUN("ep4_mul_fix_combd") { - bn_rand_mod(k, n); - ep4_mul_pre_combd(t, p); - BENCH_ADD(ep4_mul_fix_combd(q, t, k)); - } BENCH_END; - for (int i = 0; i < RLC_EPX_TABLE_COMBD; i++) { - ep4_free(t[i]); - } -#endif - -#if EP_FIX == LWNAF || !defined(STRIP) - for (int i = 0; i < RLC_EPX_TABLE_LWNAF; i++) { - ep4_new(t[i]); - } - BENCH_RUN("ep4_mul_pre_lwnaf") { - ep4_rand(p); - BENCH_ADD(ep4_mul_pre_lwnaf(t, p)); - } BENCH_END; - - BENCH_RUN("ep4_mul_fix_lwnaf") { - bn_rand_mod(k, n); - ep4_rand(p); - ep4_mul_pre_lwnaf(t, p); - BENCH_ADD(ep4_mul_fix_lwnaf(q, t, k)); - } BENCH_END; - for (int i = 0; i < RLC_EPX_TABLE_LWNAF; i++) { - ep4_free(t[i]); - } -#endif - - BENCH_RUN("ep4_mul_sim") { - bn_rand_mod(k, n); - bn_rand_mod(l, n); - ep4_rand(p); - ep4_rand(q); - BENCH_ADD(ep4_mul_sim(r, p, k, q, l)); - } BENCH_END; - -#if EP_SIM == BASIC || !defined(STRIP) - BENCH_RUN("ep4_mul_sim_basic") { - bn_rand_mod(k, n); - bn_rand_mod(l, n); - ep4_rand(p); - ep4_rand(q); - BENCH_ADD(ep4_mul_sim_basic(r, p, k, q, l)); - } BENCH_END; -#endif - -#if EP_SIM == TRICK || !defined(STRIP) - BENCH_RUN("ep4_mul_sim_trick") { - bn_rand_mod(k, n); - bn_rand_mod(l, n); - ep4_rand(p); - ep4_rand(q); - BENCH_ADD(ep4_mul_sim_trick(r, p, k, q, l)); - } BENCH_END; -#endif - -#if EP_SIM == INTER || !defined(STRIP) - BENCH_RUN("ep4_mul_sim_inter") { - bn_rand_mod(k, n); - bn_rand_mod(l, n); - ep4_rand(p); - ep4_rand(q); - BENCH_ADD(ep4_mul_sim_inter(r, p, k, q, l)); - } BENCH_END; -#endif - -#if EP_SIM == JOINT || !defined(STRIP) - BENCH_RUN("ep4_mul_sim_joint") { - bn_rand_mod(k, n); - bn_rand_mod(l, n); - ep4_rand(p); - ep4_rand(q); - BENCH_ADD(ep4_mul_sim_joint(r, p, k, q, l)); - } BENCH_END; -#endif - - BENCH_RUN("ep4_mul_sim_gen") { - bn_rand_mod(k, n); - bn_rand_mod(l, n); - ep4_rand(q); - BENCH_ADD(ep4_mul_sim_gen(r, k, q, l)); - } BENCH_END; - - BENCH_RUN("ep4_frb") { - ep4_rand(q); - BENCH_ADD(ep4_frb(r, q, 1)); - } BENCH_END; - - BENCH_RUN("ep4_map") { - uint8_t msg[5]; - rand_bytes(msg, 5); - BENCH_ADD(ep4_map(p, msg, 5)); - } BENCH_END; - - ep4_free(p); - ep4_free(q); - ep4_free(r); - bn_free(k); - bn_free(n); - bn_free(l); - fp4_free(s); -} - -int main(void) { - int r0, r1; - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - conf_print(); - - util_banner("Benchmarks for the EPX module:", 0); - - if (ep_param_set_any_pairf() != RLC_OK) { - RLC_THROW(ERR_NO_CURVE); - core_clean(); - return 0; - } - - if ((r0 = ep2_curve_is_twist())) { - ep_param_print(); - - util_banner("Utilities:", 1); - memory2(); - util2(); - - util_banner("Arithmetic:", 1); - arith2(); - } - - if ((r1 = ep4_curve_is_twist())) { - ep_param_print(); - - util_banner("Utilities:", 1); - memory4(); - util4(); - - util_banner("Arithmetic:", 1); - arith4(); - } - - if (!r0 && !r1) { - RLC_THROW(ERR_NO_CURVE); - core_clean(); - return 0; - } - - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/bench/bench_err.c b/src/dashbls/depends/relic/bench/bench_err.c deleted file mode 100644 index bb99e94edefd..000000000000 --- a/src/dashbls/depends/relic/bench/bench_err.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2009 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for error-management routines. - * - * @ingroup bench - */ - -#include - -#include "relic.h" -#include "relic_bench.h" - -static void dummy2(void) { - -} - -static void dummy(void) { - RLC_TRY { - /* Empty block just to test overhead of error triggering mechanism. */ - } - RLC_CATCH_ANY { - /* Exceptions are thrown here. */ - } - RLC_FINALLY { - /* This is executed after exception handling. */ - } -} - -static void error(void) { - BENCH_RUN("empty function") { - BENCH_ADD(dummy2()); - } - BENCH_END; - - BENCH_RUN("try-catch-finnaly") { - BENCH_ADD(dummy()); - } - BENCH_END; -} - -int main(void) { - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - conf_print(); - util_banner("Benchmarks for the ERR module:\n", 0); - error(); - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/bench/bench_fb.c b/src/dashbls/depends/relic/bench/bench_fb.c deleted file mode 100644 index 41fbb026ed02..000000000000 --- a/src/dashbls/depends/relic/bench/bench_fb.c +++ /dev/null @@ -1,569 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2009 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for binary field arithmetic. - * - * @ingroup bench - */ - -#include - -#include "relic.h" -#include "relic_bench.h" - -static void memory(void) { - fb_t a[BENCH]; - - BENCH_FEW("fb_null", fb_null(a[i]), 1); - - BENCH_FEW("fb_new", fb_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - fb_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - fb_new(a[i]); - } - BENCH_FEW("fb_free", fb_free(a[i]), 1); - - (void)a; -} - -static void util(void) { - char str[2 * RLC_FB_BYTES + 1]; - uint8_t bin[RLC_FB_BYTES]; - fb_t a, b; - - fb_null(a); - fb_null(b); - - fb_new(a); - fb_new(b); - - BENCH_RUN("fb_copy") { - fb_rand(a); - BENCH_ADD(fb_copy(b, a)); - } - BENCH_END; - - BENCH_RUN("fb_zero") { - fb_rand(a); - BENCH_ADD(fb_zero(a)); - } - BENCH_END; - - BENCH_RUN("fb_is_zero") { - fb_rand(a); - BENCH_ADD(fb_is_zero(a)); - } - BENCH_END; - - BENCH_RUN("fb_get_bit") { - fb_rand(a); - BENCH_ADD(fb_get_bit(a, RLC_DIG / 2)); - } - BENCH_END; - - BENCH_RUN("fb_set_bit") { - fb_rand(a); - BENCH_ADD(fb_set_bit(a, RLC_DIG / 2, 1)); - } - BENCH_END; - - BENCH_RUN("fb_set_dig") { - fb_rand(a); - fb_rand(b); - BENCH_ADD(fb_set_dig(a, b[0])); - } - BENCH_END; - - BENCH_RUN("fb_bits") { - fb_rand(a); - BENCH_ADD(fb_bits(a)); - } - BENCH_END; - - BENCH_RUN("fb_rand") { - BENCH_ADD(fb_rand(a)); - } - BENCH_END; - - BENCH_RUN("fb_size_str (16)") { - fb_rand(a); - BENCH_ADD(fb_size_str(a, 16)); - } - BENCH_END; - - BENCH_RUN("fb_write_str (16)") { - fb_rand(a); - BENCH_ADD(fb_write_str(str, sizeof(str), a, 16)); - } - BENCH_END; - - BENCH_RUN("fb_read_str (16)") { - fb_rand(a); - fb_write_str(str, sizeof(str), a, 16); - BENCH_ADD(fb_read_str(a, str, sizeof(str), 16)); - } - BENCH_END; - - BENCH_RUN("fb_write_bin") { - fb_rand(a); - BENCH_ADD(fb_write_bin(bin, sizeof(bin), a)); - } - BENCH_END; - - BENCH_RUN("fb_read_bin") { - fb_rand(a); - fb_write_bin(bin, sizeof(bin), a); - BENCH_ADD(fb_read_bin(a, bin, sizeof(bin))); - } - BENCH_END; - - BENCH_RUN("fb_cmp_dig") { - fb_rand(a); - BENCH_ADD(fb_cmp_dig(a, (dig_t)0)); - } - BENCH_END; - - BENCH_RUN("fb_cmp") { - fb_rand(a); - fb_rand(b); - BENCH_ADD(fb_cmp(b, a)); - } - BENCH_END; - - fb_free(a); - fb_free(b); -} - -static void arith(void) { - fb_t a, b, c, d[2]; - fb_st t[RLC_FB_TABLE_MAX]; - dv_t e; - bn_t f; - int bits; - - fb_null(a); - fb_null(b); - fb_null(c); - fb_null(d[0]); - fb_null(d[1]); - dv_null(e); - bn_null(f); - - fb_new(a); - fb_new(b); - fb_new(c); - fb_new(d[0]); - fb_new(d[1]); - dv_new(e); - dv_zero(e, 2 * RLC_FB_DIGS); - bn_new(f); - - BENCH_RUN("fb_add") { - fb_rand(a); - fb_rand(b); - BENCH_ADD(fb_add(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fb_add_dig") { - fb_rand(a); - fb_rand(b); - BENCH_ADD(fb_add_dig(c, a, b[0])); - } - BENCH_END; - - BENCH_RUN("fb_poly_add") { - fb_rand(a); - BENCH_ADD(fb_poly_add(c, a)); - } - BENCH_END; - - BENCH_RUN("fb_mul") { - fb_rand(a); - fb_rand(b); - BENCH_ADD(fb_mul(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fb_mul_dig") { - fb_rand(a); - fb_rand(b); - BENCH_ADD(fb_mul_dig(c, a, b[0])); - } - BENCH_END; - -#if FB_MUL == BASIC || !defined(STRIP) - BENCH_RUN("fb_mul_basic") { - fb_rand(a); - fb_rand(b); - BENCH_ADD(fb_mul_basic(c, a, b)); - } - BENCH_END; -#endif - -#if FB_MUL == INTEG || !defined(STRIP) - BENCH_RUN("fb_mul_integ") { - fb_rand(a); - fb_rand(b); - BENCH_ADD(fb_mul_integ(c, a, b)); - } - BENCH_END; -#endif - -#if FB_MUL == LODAH || !defined(STRIP) - BENCH_RUN("fb_mul_lodah") { - fb_rand(a); - fb_rand(b); - BENCH_ADD(fb_mul_lodah(c, a, b)); - } - BENCH_END; -#endif - -#if FB_KARAT > 0 || !defined(STRIP) - BENCH_RUN("fb_mul_karat") { - fb_rand(a); - fb_rand(b); - BENCH_ADD(fb_mul_karat(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("fb_sqr") { - fb_rand(a); - BENCH_ADD(fb_sqr(c, a)); - } - BENCH_END; - -#if FB_SQR == BASIC || !defined(STRIP) - BENCH_RUN("fb_sqr_basic") { - fb_rand(a); - BENCH_ADD(fb_sqr_basic(c, a)); - } - BENCH_END; -#endif - -#if FB_SQR == INTEG || !defined(STRIP) - BENCH_RUN("fb_sqr_integ") { - fb_rand(a); - BENCH_ADD(fb_sqr_integ(c, a)); - } - BENCH_END; -#endif - -#if FB_SQR == QUICK || !defined(STRIP) - BENCH_RUN("fb_sqr_quick") { - fb_rand(a); - BENCH_ADD(fb_sqr_quick(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fb_lsh") { - fb_rand(a); - a[RLC_FB_DIGS - 1] = 0; - bits = a[0] & RLC_MASK(RLC_DIG_LOG); - BENCH_ADD(fb_lsh(c, a, bits)); - } - BENCH_END; - - BENCH_RUN("fb_rsh") { - fb_rand(a); - a[RLC_FB_DIGS - 1] = 0; - bits = a[0] & RLC_MASK(RLC_DIG_LOG); - BENCH_ADD(fb_rsh(c, a, bits)); - - } - BENCH_END; - - BENCH_RUN("fb_rdc") { - fb_rand(a); - fb_lsh(e, a, RLC_FB_BITS); - fb_rand(e); - BENCH_ADD(fb_rdc(c, e)); - } - BENCH_END; - -#if FB_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fb_rdc_basic") { - fb_rand(a); - fb_lsh(e, a, RLC_FB_BITS); - fb_rand(e); - BENCH_ADD(fb_rdc_basic(c, e)); - } - BENCH_END; -#endif - -#if FB_RDC == QUICK || !defined(STRIP) - BENCH_RUN("fb_rdc_quick") { - fb_rand(a); - fb_lsh(e, a, RLC_FB_BITS); - fb_rand(e); - BENCH_ADD(fb_rdc_quick(c, e)); - } - BENCH_END; -#endif - - BENCH_RUN("fb_srt") { - fb_rand(a); - fb_sqr(e, a); - BENCH_ADD(fb_srt(c, e)); - } - BENCH_END; - -#if FB_SRT == BASIC || !defined(STRIP) - BENCH_RUN("fb_srt_basic") { - fb_rand(a); - fb_sqr(e, a); - BENCH_ADD(fb_srt_basic(c, e)); - } - BENCH_END; -#endif - -#if FB_SRT == QUICK || !defined(STRIP) - BENCH_RUN("fb_srt_quick") { - fb_rand(a); - fb_sqr(e, a); - BENCH_ADD(fb_srt_quick(c, e)); - } - BENCH_END; -#endif - - BENCH_RUN("fb_trc") { - fb_rand(a); - BENCH_ADD(fb_trc(a)); - } - BENCH_END; - -#if FB_TRC == BASIC || !defined(STRIP) - BENCH_RUN("fb_trc_basic") { - fb_rand(a); - BENCH_ADD(fb_trc_basic(a)); - } - BENCH_END; -#endif - -#if FB_TRC == QUICK || !defined(STRIP) - BENCH_RUN("fb_trc_quick") { - fb_rand(a); - BENCH_ADD(fb_trc_quick(a)); - } - BENCH_END; -#endif - - if (RLC_FB_BITS % 2 != 0) { - BENCH_RUN("fb_slv") { - fb_rand(a); - BENCH_ADD(fb_slv(c, a)); - } - BENCH_END; - -#if FB_SLV == BASIC || !defined(STRIP) - BENCH_RUN("fb_slv_basic") { - fb_rand(a); - BENCH_ADD(fb_slv_basic(c, a)); - } - BENCH_END; -#endif - -#if FB_SLV == QUICK || !defined(STRIP) - BENCH_RUN("fb_slv_quick") { - fb_rand(a); - BENCH_ADD(fb_slv_quick(c, a)); - } - BENCH_END; -#endif - } - - BENCH_RUN("fb_inv") { - fb_rand(a); - BENCH_ADD(fb_inv(c, a)); - } - BENCH_END; - -#if FB_INV == BASIC || !defined(STRIP) - BENCH_RUN("fb_inv_basic") { - fb_rand(a); - BENCH_ADD(fb_inv_basic(c, a)); - } - BENCH_END; -#endif - -#if FB_INV == BINAR || !defined(STRIP) - BENCH_RUN("fb_inv_binar") { - fb_rand(a); - BENCH_ADD(fb_inv_binar(c, a)); - } - BENCH_END; -#endif - -#if FB_INV == ALMOS || !defined(STRIP) - BENCH_RUN("fb_inv_almos") { - fb_rand(a); - BENCH_ADD(fb_inv_almos(c, a)); - } - BENCH_END; -#endif - -#if FB_INV == EXGCD || !defined(STRIP) - BENCH_RUN("fb_inv_exgcd") { - fb_rand(a); - BENCH_ADD(fb_inv_exgcd(c, a)); - } - BENCH_END; -#endif - -#if FB_INV == BRUCH || !defined(STRIP) - BENCH_RUN("fb_inv_bruch") { - fb_rand(a); - BENCH_ADD(fb_inv_bruch(c, a)); - } - BENCH_END; -#endif - -#if FB_INV == ITOHT || !defined(STRIP) - BENCH_RUN("fb_inv_itoht") { - fb_rand(a); - BENCH_ADD(fb_inv_itoht(c, a)); - } - BENCH_END; -#endif - -#if FB_INV == CTAIA || !defined(STRIP) - BENCH_RUN("fb_inv_ctaia") { - fb_rand(a); - BENCH_ADD(fb_inv_ctaia(c, a)); - } - BENCH_END; -#endif - -#if FB_INV == LOWER || !defined(STRIP) - BENCH_RUN("fb_inv_lower") { - fb_rand(a); - BENCH_ADD(fb_inv_lower(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fb_inv_sim (2)") { - fb_rand(d[0]); - fb_rand(d[1]); - BENCH_ADD(fb_inv_sim(d, (const fb_t *)d, 2)); - } - BENCH_END; - - BENCH_RUN("fb_exp") { - fb_rand(a); - bn_rand(f, RLC_POS, RLC_FB_BITS); - BENCH_ADD(fb_exp(c, a, f)); - } - BENCH_END; - -#if FB_EXP == BASIC || !defined(STRIP) - BENCH_RUN("fb_exp_basic") { - fb_rand(a); - bn_rand(f, RLC_POS, RLC_FB_BITS); - BENCH_ADD(fb_exp_basic(c, a, f)); - } - BENCH_END; -#endif - -#if FB_EXP == SLIDE || !defined(STRIP) - BENCH_RUN("fb_exp_slide") { - fb_rand(a); - bn_rand(f, RLC_POS, RLC_FB_BITS); - BENCH_ADD(fb_exp_slide(c, a, f)); - } - BENCH_END; -#endif - -#if FB_EXP == MONTY || !defined(STRIP) - BENCH_RUN("fb_exp_monty") { - fb_rand(a); - bn_rand(f, RLC_POS, RLC_FB_BITS); - BENCH_ADD(fb_exp_monty(c, a, f)); - } - BENCH_END; -#endif - - BENCH_RUN("fb_itr") { - fb_rand(a); - bn_rand(f, RLC_POS, 8); - fb_itr_pre(t, f->dp[0]); - BENCH_ADD(fb_itr(c, a, f->dp[0], t)); - } - BENCH_END; - -#if FB_ITR == BASIC || !defined(STRIP) - BENCH_RUN("fb_itr_basic") { - fb_rand(a); - bn_rand(f, RLC_POS, 8); - BENCH_ADD(fb_itr_basic(c, a, f->dp[0])); - } - BENCH_END; -#endif - -#if FB_ITR == QUICK || !defined(STRIP) - BENCH_RUN("fb_itr_quick") { - fb_rand(a); - bn_rand(f, RLC_POS, 8); - fb_itr_pre_quick(t, f->dp[0]); - BENCH_ADD(fb_itr_quick(c, a, t)); - } - BENCH_END; -#endif - - fb_free(a); - fb_free(b); - fb_free(c); - fb_free(d[0]); - fb_free(d[1]); - dv_free(e); - bn_free(f); -} - -int main(void) { - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - conf_print(); - util_banner("Benchmarks for the FB module:", 0); - - fb_param_set_any(); - fb_param_print(); - util_banner("Utilities:\n", 0); - memory(); - util(); - util_banner("Arithmetic:\n", 0); - arith(); - - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/bench/bench_fbx.c b/src/dashbls/depends/relic/bench/bench_fbx.c deleted file mode 100644 index d3c9f59761da..000000000000 --- a/src/dashbls/depends/relic/bench/bench_fbx.c +++ /dev/null @@ -1,165 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2012 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for extensions defined over binary fields. - * - * @ingroup bench - */ - -#include - -#include "relic.h" -#include "relic_bench.h" - -static void memory2(void) { - fb2_t a[BENCH]; - - BENCH_FEW("fb2_null", fb2_null(a[i]), 1); - - BENCH_FEW("fb2_new", fb2_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - fb2_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - fb2_new(a[i]); - } - BENCH_FEW("fb2_free", fb2_free(a[i]), 1); - - (void)a; -} - -static void util2(void) { - fb2_t a, b; - - fb2_null(a); - fb2_null(b); - - fb2_new(a); - fb2_new(b); - - BENCH_RUN("fb2_copy") { - fb2_rand(a); - BENCH_ADD(fb2_copy(b, a)); - } - BENCH_END; - - BENCH_RUN("fb2_zero") { - fb2_rand(a); - BENCH_ADD(fb2_zero(a)); - } - BENCH_END; - - BENCH_RUN("fb2_is_zero") { - fb2_rand(a); - BENCH_ADD((void)fb2_is_zero(a)); - } - BENCH_END; - - BENCH_RUN("fb2_rand") { - BENCH_ADD(fb2_rand(a)); - } - BENCH_END; - - BENCH_RUN("fb2_cmp") { - fb2_rand(a); - fb2_rand(b); - BENCH_ADD((void)fb2_cmp(b, a)); - } - BENCH_END; - - fb2_free(a); - fb2_free(b); -} - -static void arith2(void) { - fb2_t a, b, c; - - fb2_new(a); - fb2_new(b); - fb2_new(c); - - BENCH_RUN("fb2_add") { - fb2_rand(a); - fb2_rand(b); - BENCH_ADD(fb2_add(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fb2_mul") { - fb2_rand(a); - fb2_rand(b); - BENCH_ADD(fb2_mul(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fb2_sqr") { - fb2_rand(a); - BENCH_ADD(fb2_sqr(c, a)); - } - BENCH_END; - - BENCH_RUN("fb2_slv") { - fb2_rand(a); - BENCH_ADD(fb2_slv(c, a)); - } - BENCH_END; - - BENCH_RUN("fb2_inv") { - fb2_rand(a); - BENCH_ADD(fb2_inv(c, a)); - } - BENCH_END; - - fb2_free(a); - fb2_free(b); - fb2_free(c); -} - -int main(void) { - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - conf_print(); - - util_banner("Benchmarks for the FBX module:", 0); - - fb_param_set_any(); - fb_param_print(); - - util_banner("Quadratic extension:", 0); - util_banner("Utilities:", 1); - memory2(); - util2(); - - util_banner("Arithmetic:", 1); - arith2(); - - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/bench/bench_fp.c b/src/dashbls/depends/relic/bench/bench_fp.c deleted file mode 100644 index c2887f650f7c..000000000000 --- a/src/dashbls/depends/relic/bench/bench_fp.c +++ /dev/null @@ -1,632 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2009 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for prime field arithmetic. - * - * @ingroup bench - */ - -#include - -#include "relic.h" -#include "relic_bench.h" - -static void memory(void) { - fp_t a[BENCH]; - - BENCH_FEW("fp_null", fp_null(a[i]), 1); - - BENCH_FEW("fp_new", fp_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - fp_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - fp_new(a[i]); - } - BENCH_FEW("fp_free", fp_free(a[i]), 1); - - (void)a; -} - -static void util(void) { - char str[2 * RLC_FP_BYTES + 1]; - uint8_t bin[RLC_FP_BYTES]; - fp_t a, b; - - fp_null(a); - fp_null(b); - - fp_new(a); - fp_new(b); - - BENCH_RUN("fp_copy") { - fp_rand(a); - BENCH_ADD(fp_copy(b, a)); - } - BENCH_END; - - BENCH_RUN("fp_zero") { - fp_rand(a); - BENCH_ADD(fp_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp_is_zero") { - fp_rand(a); - BENCH_ADD(fp_is_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp_get_bit") { - fp_rand(a); - BENCH_ADD(fp_get_bit(a, RLC_DIG / 2)); - } - BENCH_END; - - BENCH_RUN("fp_set_bit") { - fp_rand(a); - BENCH_ADD(fp_set_bit(a, RLC_DIG / 2, 1)); - } - BENCH_END; - - BENCH_RUN("fp_set_dig (1)") { - fp_rand(a); - BENCH_ADD(fp_set_dig(a, 1)); - } - BENCH_END; - - BENCH_RUN("fp_set_dig") { - fp_rand(a); - BENCH_ADD(fp_set_dig(a, a[0])); - } - BENCH_END; - - BENCH_RUN("fp_bits") { - fp_rand(a); - BENCH_ADD(fp_bits(a)); - } - BENCH_END; - - BENCH_RUN("fp_rand") { - BENCH_ADD(fp_rand(a)); - } - BENCH_END; - - BENCH_RUN("fp_size_str (16)") { - fp_rand(a); - BENCH_ADD(fp_size_str(a, 16)); - } - BENCH_END; - - BENCH_RUN("fp_write_str (16)") { - fp_rand(a); - BENCH_ADD(fp_write_str(str, sizeof(str), a, 16)); - } - BENCH_END; - - BENCH_RUN("fp_read_str (16)") { - fp_rand(a); - fp_write_str(str, sizeof(str), a, 16); - BENCH_ADD(fp_read_str(a, str, sizeof(str), 16)); - } - BENCH_END; - - BENCH_RUN("fp_write_bin") { - fp_rand(a); - BENCH_ADD(fp_write_bin(bin, sizeof(bin), a)); - } - BENCH_END; - - BENCH_RUN("fp_read_bin") { - fp_rand(a); - fp_write_bin(bin, sizeof(bin), a); - BENCH_ADD(fp_read_bin(a, bin, sizeof(bin))); - } - BENCH_END; - - BENCH_RUN("fp_cmp") { - fp_rand(a); - fp_rand(b); - BENCH_ADD(fp_cmp(b, a)); - } - BENCH_END; - - BENCH_RUN("fp_cmp_dig") { - fp_rand(a); - BENCH_ADD(fp_cmp_dig(a, (dig_t)0)); - } - BENCH_END; - - fp_free(a); - fp_free(b); -} - -static void arith(void) { - fp_t a, b, c, f[2]; - dv_t d; - bn_t e; - - fp_null(a); - fp_null(b); - fp_null(c); - dv_null(d); - bn_null(e); - fp_null(f[0]); - fp_null(f[1]); - - fp_new(a); - fp_new(b); - fp_new(c); - dv_new(d); - bn_new(e); - fp_new(f[0]); - fp_new(f[1]); - - dv_zero(d, RLC_DV_DIGS); - - BENCH_RUN("fp_add") { - fp_rand(a); - fp_rand(b); - BENCH_ADD(fp_add(c, a, b)); - } - BENCH_END; - -#if FP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("fp_add_basic") { - fp_rand(a); - fp_rand(b); - BENCH_ADD(fp_add_basic(c, a, b)); - } - BENCH_END; -#endif - -#if FP_ADD == INTEG || !defined(STRIP) - BENCH_RUN("fp_add_integ") { - fp_rand(a); - fp_rand(b); - BENCH_ADD(fp_add_integ(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("fp_add_dig (1)") { - fp_rand(a); - fp_rand(b); - BENCH_ADD(fp_add_dig(c, a, 1)); - } - BENCH_END; - - BENCH_RUN("fp_add_dig") { - fp_rand(a); - fp_rand(b); - BENCH_ADD(fp_add_dig(c, a, b[0])); - } - BENCH_END; - - BENCH_RUN("fp_sub") { - fp_rand(a); - fp_rand(b); - BENCH_ADD(fp_sub(c, a, b)); - } - BENCH_END; - -#if FP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("fp_sub_basic") { - fp_rand(a); - fp_rand(b); - BENCH_ADD(fp_sub_basic(c, a, b)); - } - BENCH_END; -#endif - -#if FP_ADD == INTEG || !defined(STRIP) - BENCH_RUN("fp_sub_integ") { - fp_rand(a); - fp_rand(b); - BENCH_ADD(fp_sub_integ(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("fp_sub_dig (1)") { - fp_rand(a); - fp_rand(b); - BENCH_ADD(fp_sub_dig(c, a, 1)); - } - BENCH_END; - - BENCH_RUN("fp_sub_dig") { - fp_rand(a); - fp_rand(b); - BENCH_ADD(fp_sub_dig(c, a, b[0])); - } - BENCH_END; - - BENCH_RUN("fp_neg") { - fp_rand(a); - BENCH_ADD(fp_neg(b, a)); - } - BENCH_END; - -#if FP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("fp_neg_basic") { - fp_rand(a); - BENCH_ADD(fp_neg_basic(c, a)); - } - BENCH_END; -#endif - -#if FP_ADD == INTEG || !defined(STRIP) - BENCH_RUN("fp_neg_integ") { - fp_rand(a); - BENCH_ADD(fp_neg_integ(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp_mul") { - fp_rand(a); - fp_rand(b); - BENCH_ADD(fp_mul(c, a, b)); - } - BENCH_END; - -#if FP_MUL == BASIC || !defined(STRIP) - BENCH_RUN("fp_mul_basic") { - fp_rand(a); - fp_rand(b); - BENCH_ADD(fp_mul_basic(c, a, b)); - } - BENCH_END; -#endif - -#if FP_MUL == INTEG || !defined(STRIP) - BENCH_RUN("fp_mul_integ") { - fp_rand(a); - fp_rand(b); - BENCH_ADD(fp_mul_integ(c, a, b)); - } - BENCH_END; -#endif - -#if FP_MUL == COMBA || !defined(STRIP) - BENCH_RUN("fp_mul_comba") { - fp_rand(a); - fp_rand(b); - BENCH_ADD(fp_mul_comba(c, a, b)); - } - BENCH_END; -#endif - -#if FP_KARAT > 0 || !defined(STRIP) - BENCH_RUN("fp_mul_karat") { - fp_rand(a); - fp_rand(b); - BENCH_ADD(fp_mul_karat(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("fp_mul_dig") { - fp_rand(a); - fp_rand(b); - BENCH_ADD(fp_mul_dig(c, a, b[0])); - } - BENCH_END; - - BENCH_RUN("fp_sqr") { - fp_rand(a); - BENCH_ADD(fp_sqr(c, a)); - } - BENCH_END; - -#if FP_SQR == BASIC || !defined(STRIP) - BENCH_RUN("fp_sqr_basic") { - fp_rand(a); - BENCH_ADD(fp_sqr_basic(c, a)); - } - BENCH_END; -#endif - -#if FP_SQR == INTEG || !defined(STRIP) - BENCH_RUN("fp_sqr_integ") { - fp_rand(a); - BENCH_ADD(fp_sqr_integ(c, a)); - } - BENCH_END; -#endif - -#if FP_SQR == COMBA || !defined(STRIP) - BENCH_RUN("fp_sqr_comba") { - fp_rand(a); - BENCH_ADD(fp_sqr_comba(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp_dbl") { - fp_rand(a); - BENCH_ADD(fp_dbl(c, a)); - } - BENCH_END; - -#if FP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("fp_dbl_basic") { - fp_rand(a); - BENCH_ADD(fp_dbl_basic(c, a)); - } - BENCH_END; -#endif - -#if FP_ADD == INTEG || !defined(STRIP) - BENCH_RUN("fp_dbl_integ") { - fp_rand(a); - BENCH_ADD(fp_dbl_integ(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp_hlv") { - fp_rand(a); - BENCH_ADD(fp_hlv(c, a)); - } - BENCH_END; - -#if FP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("fp_hlv_basic") { - fp_rand(a); - BENCH_ADD(fp_hlv_basic(c, a)); - } - BENCH_END; -#endif - -#if FP_ADD == INTEG || !defined(STRIP) - BENCH_RUN("fp_hlv_integ") { - fp_rand(a); - BENCH_ADD(fp_hlv_integ(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp_lsh") { - fp_rand(a); - a[RLC_FP_DIGS - 1] = 0; - BENCH_ADD(fp_lsh(c, a, RLC_DIG / 2)); - } - BENCH_END; - - BENCH_RUN("fp_rsh") { - fp_rand(a); - a[RLC_FP_DIGS - 1] = 0; - BENCH_ADD(fp_rsh(c, a, RLC_FP_BITS / 2)); - } - BENCH_END; - - BENCH_RUN("fp_rdc") { - fp_rand(a); - fp_lsh(d, a, RLC_FP_BITS); - BENCH_ADD(fp_rdc(c, d)); - } - BENCH_END; - -#if FP_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp_rdc_basic") { - fp_rand(a); - fp_lsh(d, a, RLC_FP_BITS); - BENCH_ADD(fp_rdc_basic(c, d)); - } - BENCH_END; -#endif - -#if FP_RDC == MONTY || !defined(STRIP) - BENCH_RUN("fp_rdc_monty") { - fp_rand(a); - fp_lsh(d, a, RLC_FP_BITS); - BENCH_ADD(fp_rdc_monty(c, d)); - } - BENCH_END; - -#if FP_MUL == BASIC || !defined(STRIP) - BENCH_RUN("fp_rdc_monty_basic") { - fp_rand(a); - fp_lsh(d, a, RLC_FP_BITS); - BENCH_ADD(fp_rdc_monty_basic(c, d)); - } - BENCH_END; -#endif - -#if FP_MUL == COMBA || !defined(STRIP) - BENCH_RUN("fp_rdc_monty_comba") { - fp_rand(a); - fp_lsh(d, a, RLC_FP_BITS); - BENCH_ADD(fp_rdc_monty_comba(c, d)); - } - BENCH_END; -#endif -#endif - -#if FP_RDC == QICK || !defined(STRIP) - if (fp_prime_get_sps(NULL) != NULL) { - BENCH_RUN("fp_rdc_quick") { - fp_rand(a); - fp_lsh(d, a, RLC_FP_BITS); - BENCH_ADD(fp_rdc_quick(c, d)); - } - BENCH_END; - } -#endif - - BENCH_RUN("fp_inv") { - fp_rand(a); - BENCH_ADD(fp_inv(c, a)); - } - BENCH_END; - -#if FP_INV == BASIC || !defined(STRIP) - BENCH_RUN("fp_inv_basic") { - fp_rand(a); - BENCH_ADD(fp_inv_basic(c, a)); - } - BENCH_END; -#endif - -#if FP_INV == BINAR || !defined(STRIP) - BENCH_RUN("fp_inv_binar") { - fp_rand(a); - BENCH_ADD(fp_inv_binar(c, a)); - } - BENCH_END; -#endif - -#if FP_INV == MONTY || !defined(STRIP) - BENCH_RUN("fp_inv_monty") { - fp_rand(a); - BENCH_ADD(fp_inv_monty(c, a)); - } - BENCH_END; -#endif - -#if FP_INV == EXGCD || !defined(STRIP) - BENCH_RUN("fp_inv_exgcd") { - fp_rand(a); - BENCH_ADD(fp_inv_exgcd(c, a)); - } - BENCH_END; -#endif - -#if FP_INV == DIVST || !defined(STRIP) - BENCH_RUN("fp_inv_divst") { - fp_rand(a); - BENCH_ADD(fp_inv_divst(c, a)); - } - BENCH_END; -#endif - -#if FP_INV == LOWER || !defined(STRIP) - BENCH_RUN("fp_inv_lower") { - fp_rand(a); - BENCH_ADD(fp_inv_lower(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp_inv_sim (2)") { - fp_rand(f[0]); - fp_rand(f[1]); - BENCH_ADD(fp_inv_sim(f, (const fp_t *)f, 2)); - } - BENCH_END; - - BENCH_RUN("fp_exp") { - fp_rand(a); - bn_rand(e, RLC_POS, RLC_FP_BITS); - BENCH_ADD(fp_exp(c, a, e)); - } - BENCH_END; - -#if FP_EXP == BASIC || !defined(STRIP) - BENCH_RUN("fp_exp_basic") { - fp_rand(a); - bn_rand(e, RLC_POS, RLC_FP_BITS); - BENCH_ADD(fp_exp_basic(c, a, e)); - } - BENCH_END; -#endif - -#if FP_EXP == SLIDE || !defined(STRIP) - BENCH_RUN("fp_exp_slide") { - fp_rand(a); - bn_rand(e, RLC_POS, RLC_FP_BITS); - BENCH_ADD(fp_exp_slide(c, a, e)); - } - BENCH_END; -#endif - -#if FP_EXP == MONTY || !defined(STRIP) - BENCH_RUN("fp_exp_monty") { - fp_rand(a); - bn_rand(e, RLC_POS, RLC_FP_BITS); - BENCH_ADD(fp_exp_monty(c, a, e)); - } - BENCH_END; -#endif - - BENCH_RUN("fp_srt") { - fp_rand(a); - fp_sqr(a, a); - BENCH_ADD(fp_srt(c, a)); - } - BENCH_END; - - BENCH_RUN("fp_prime_conv") { - bn_rand(e, RLC_POS, RLC_FP_BITS); - BENCH_ADD(fp_prime_conv(a, e)); - } - BENCH_END; - - BENCH_RUN("fp_prime_conv_dig") { - bn_rand(e, RLC_POS, RLC_FP_BITS); - BENCH_ADD(fp_prime_conv_dig(a, e->dp[0])); - } - BENCH_END; - - BENCH_RUN("fp_prime_back") { - fp_rand(c); - BENCH_ADD(fp_prime_back(e, c)); - } - BENCH_END; - - fp_free(a); - fp_free(b); - fp_free(c); - dv_free(d); - bn_free(e); - fp_free(f[0]); - fp_free(f[1]); -} - -int main(void) { - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - conf_print(); - util_banner("Benchmarks for the FP module:", 0); - - fp_param_set_any(); - fp_param_print(); - - util_banner("Utilities:\n", 0); - memory(); - util(); - util_banner("Arithmetic:\n", 0); - arith(); - - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/bench/bench_fpx.c b/src/dashbls/depends/relic/bench/bench_fpx.c deleted file mode 100644 index 62ee13cc37cb..000000000000 --- a/src/dashbls/depends/relic/bench/bench_fpx.c +++ /dev/null @@ -1,3340 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2012 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for extensions of prime fields - * - * @ingroup bench - */ - -#include "relic.h" -#include "relic_bench.h" - -static void memory2(void) { - fp2_t a[BENCH]; - - BENCH_FEW("fp2_null", fp2_null(a[i]), 1); - - BENCH_FEW("fp2_new", fp2_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - fp2_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - fp2_new(a[i]); - } - BENCH_FEW("fp2_free", fp2_free(a[i]), 1); - - (void)a; -} - -static void util2(void) { - uint8_t bin[2 * RLC_FP_BYTES]; - fp2_t a, b; - - fp2_null(a); - fp2_null(b); - - fp2_new(a); - fp2_new(b); - - BENCH_RUN("fp2_copy") { - fp2_rand(a); - BENCH_ADD(fp2_copy(b, a)); - } - BENCH_END; - - BENCH_RUN("fp2_neg") { - fp2_rand(a); - BENCH_ADD(fp2_neg(b, a)); - } - BENCH_END; - - BENCH_RUN("fp2_zero") { - fp2_rand(a); - BENCH_ADD(fp2_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp2_is_zero") { - fp2_rand(a); - BENCH_ADD((void)fp2_is_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp2_set_dig (1)") { - fp2_rand(a); - BENCH_ADD(fp2_set_dig(a, 1)); - } - BENCH_END; - - BENCH_RUN("fp2_set_dig") { - fp2_rand(a); - BENCH_ADD(fp2_set_dig(a, a[0][0])); - } - BENCH_END; - - BENCH_RUN("fp2_rand") { - BENCH_ADD(fp2_rand(a)); - } - BENCH_END; - - BENCH_RUN("fp2_size_bin (0)") { - fp2_rand(a); - BENCH_ADD(fp2_size_bin(a, 0)); - } - BENCH_END; - - BENCH_RUN("fp2_size_bin (1)") { - fp2_rand(a); - fp2_conv_cyc(a, a); - BENCH_ADD(fp2_size_bin(a, 1)); - } - BENCH_END; - - BENCH_RUN("fp2_write_bin (0)") { - fp2_rand(a); - BENCH_ADD(fp2_write_bin(bin, sizeof(bin), a, 0)); - } - BENCH_END; - - BENCH_RUN("fp2_write_bin (1)") { - fp2_rand(a); - fp2_conv_cyc(a, a); - BENCH_ADD(fp2_write_bin(bin, sizeof(bin), a, 1)); - } - BENCH_END; - - BENCH_RUN("fp2_read_bin (0)") { - fp2_rand(a); - fp2_write_bin(bin, sizeof(bin), a, 0); - BENCH_ADD(fp2_read_bin(a, bin, sizeof(bin))); - } - BENCH_END; - - BENCH_RUN("fp2_read_bin") { - fp2_rand(a); - fp2_conv_cyc(a, a); - fp2_write_bin(bin, sizeof(bin), a, 1); - BENCH_ADD(fp2_read_bin(a, bin, sizeof(bin))); - } - BENCH_END; - - BENCH_RUN("fp2_cmp") { - fp2_rand(a); - fp2_rand(b); - BENCH_ADD(fp2_cmp(b, a)); - } - BENCH_END; - - BENCH_RUN("fp2_cmp_dig") { - fp2_rand(a); - BENCH_ADD(fp2_cmp_dig(a, (dig_t)0)); - } - BENCH_END; - - fp2_free(a); - fp2_free(b); -} - -static void arith2(void) { - fp2_t a, b, c, d[2]; - bn_t e; - - fp2_new(a); - fp2_new(b); - fp2_new(c); - fp2_new(d[0]); - fp2_new(d[1]); - bn_new(e); - - BENCH_RUN("fp2_add") { - fp2_rand(a); - fp2_rand(b); - BENCH_ADD(fp2_add(c, a, b)); - } - BENCH_END; - -#if PP_QDR == BASIC || !defined(STRIP) - BENCH_RUN("fp2_add_basic") { - fp2_rand(a); - fp2_rand(b); - BENCH_ADD(fp2_add_basic(c, a, b)); - } - BENCH_END; -#endif - -#if PP_QDR == INTEG || !defined(STRIP) - BENCH_RUN("fp2_add_integ") { - fp2_rand(a); - fp2_rand(b); - BENCH_ADD(fp2_add_integ(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("fp2_sub") { - fp2_rand(a); - fp2_rand(b); - BENCH_ADD(fp2_sub(c, a, b)); - } - BENCH_END; - -#if PP_QDR == BASIC || !defined(STRIP) - BENCH_RUN("fp2_sub_basic") { - fp2_rand(a); - fp2_rand(b); - BENCH_ADD(fp2_sub_basic(c, a, b)); - } - BENCH_END; -#endif - -#if PP_QDR == INTEG || !defined(STRIP) - BENCH_RUN("fp2_sub_integ") { - fp2_rand(a); - fp2_rand(b); - BENCH_ADD(fp2_sub_integ(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("fp2_dbl") { - fp2_rand(a); - BENCH_ADD(fp2_dbl(c, a)); - } - BENCH_END; - -#if PP_QDR == BASIC || !defined(STRIP) - BENCH_RUN("fp2_dbl_basic") { - fp2_rand(a); - BENCH_ADD(fp2_dbl_basic(c, a)); - } - BENCH_END; -#endif - -#if PP_QDR == INTEG || !defined(STRIP) - BENCH_RUN("fp2_dbl_integ") { - fp2_rand(a); - BENCH_ADD(fp2_dbl_integ(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp2_mul") { - fp2_rand(a); - fp2_rand(b); - BENCH_ADD(fp2_mul(c, a, b)); - } - BENCH_END; - -#if PP_QDR == BASIC || !defined(STRIP) - BENCH_RUN("fp2_mul_basic") { - fp2_rand(a); - fp2_rand(b); - BENCH_ADD(fp2_mul_basic(c, a, b)); - } - BENCH_END; -#endif - -#if PP_QDR == INTEG || !defined(STRIP) - BENCH_RUN("fp2_mul_integ") { - fp2_rand(a); - fp2_rand(b); - BENCH_ADD(fp2_mul_integ(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("fp2_mul_art") { - fp2_rand(a); - BENCH_ADD(fp2_mul_art(c, a)); - } - BENCH_END; - - BENCH_RUN("fp2_mul_nor") { - fp2_rand(a); - BENCH_ADD(fp2_mul_nor(c, a)); - } - BENCH_END; - -#if PP_QDR == BASIC || !defined(STRIP) - BENCH_RUN("fp2_mul_nor_basic") { - fp2_rand(a); - BENCH_ADD(fp2_mul_nor_basic(c, a)); - } - BENCH_END; -#endif - -#if PP_QDR == INTEG || !defined(STRIP) - BENCH_RUN("fp2_mul_nor_integ") { - fp2_rand(a); - BENCH_ADD(fp2_mul_nor_integ(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp2_sqr") { - fp2_rand(a); - BENCH_ADD(fp2_sqr(c, a)); - } - BENCH_END; - -#if PP_QDR == BASIC || !defined(STRIP) - BENCH_RUN("fp2_sqr_basic") { - fp2_rand(a); - BENCH_ADD(fp2_sqr_basic(c, a)); - } - BENCH_END; -#endif - -#if PP_QDR == INTEG || !defined(STRIP) - BENCH_RUN("fp2_sqr_integ") { - fp2_rand(a); - BENCH_ADD(fp2_sqr_integ(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp2_test_cyc") { - fp2_rand(a); - fp2_conv_cyc(a, a); - BENCH_ADD(fp2_test_cyc(a)); - } - BENCH_END; - - BENCH_RUN("fp2_conv_cyc") { - fp2_rand(a); - BENCH_ADD(fp2_conv_cyc(c, a)); - } - BENCH_END; - - BENCH_RUN("fp2_inv") { - fp2_rand(a); - BENCH_ADD(fp2_inv(c, a)); - } - BENCH_END; - - BENCH_RUN("fp2_inv_cyc") { - fp2_rand(a); - BENCH_ADD(fp2_inv_cyc(c, a)); - } - BENCH_END; - - BENCH_RUN("fp2_inv_sim (2)") { - fp2_rand(d[0]); - fp2_rand(d[1]); - BENCH_ADD(fp2_inv_sim(d, d, 2)); - } - BENCH_END; - - BENCH_RUN("fp2_exp") { - fp2_rand(a); - e->used = RLC_FP_DIGS; - dv_copy(e->dp, fp_prime_get(), RLC_FP_DIGS); - BENCH_ADD(fp2_exp(c, a, e)); - } - BENCH_END; - - BENCH_RUN("fp2_exp_dig") { - fp2_rand(a); - bn_rand(e, RLC_POS, RLC_DIG); - BENCH_ADD(fp2_exp_dig(c, a, e->dp[0])); - } - BENCH_END; - - BENCH_RUN("fp2_exp_cyc") { - fp2_rand(a); - e->used = RLC_FP_DIGS; - dv_copy(e->dp, fp_prime_get(), RLC_FP_DIGS); - BENCH_ADD(fp2_exp_cyc(c, a, e)); - } - BENCH_END; - - BENCH_RUN("fp2_frb") { - fp2_rand(a); - BENCH_ADD(fp2_frb(c, a, 1)); - } - BENCH_END; - - BENCH_RUN("fp2_mul_frb") { - fp2_rand(a); - BENCH_ADD(fp2_mul_frb(c, a, 1, 0)); - } - BENCH_END; - - BENCH_RUN("fp2_srt") { - fp2_rand(a); - fp2_sqr(a, a); - BENCH_ADD(fp2_srt(c, a)); - } - BENCH_END; - - BENCH_RUN("fp2_pck") { - fp2_rand(a); - fp2_conv_cyc(a, a); - BENCH_ADD(fp2_pck(c, a)); - } - BENCH_END; - - BENCH_RUN("fp2_upk") { - fp2_rand(a); - fp2_conv_cyc(a, a); - fp2_pck(a, a); - BENCH_ADD(fp2_upk(c, a)); - } - BENCH_END; - - fp2_free(a); - fp2_free(b); - fp2_free(c); - fp2_free(d[0]); - fp2_free(d[1]); - bn_free(e); -} - -static void memory3(void) { - fp3_t a[BENCH]; - - BENCH_FEW("fp3_null", fp3_null(a[i]), 1); - - BENCH_FEW("fp3_new", fp3_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - fp3_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - fp3_new(a[i]); - } - BENCH_FEW("fp3_free", fp3_free(a[i]), 1); - - (void)a; -} - -static void util3(void) { - uint8_t bin[3 * RLC_FP_BYTES]; - fp3_t a, b; - - fp3_null(a); - fp3_null(b); - - fp3_new(a); - fp3_new(b); - - BENCH_RUN("fp3_copy") { - fp3_rand(a); - BENCH_ADD(fp3_copy(b, a)); - } - BENCH_END; - - BENCH_RUN("fp3_neg") { - fp3_rand(a); - BENCH_ADD(fp3_neg(b, a)); - } - BENCH_END; - - BENCH_RUN("fp3_zero") { - fp3_rand(a); - BENCH_ADD(fp3_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp3_is_zero") { - fp3_rand(a); - BENCH_ADD((void)fp3_is_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp3_set_dig (1)") { - fp3_rand(a); - BENCH_ADD(fp3_set_dig(a, 1)); - } - BENCH_END; - - BENCH_RUN("fp3_set_dig") { - fp3_rand(a); - BENCH_ADD(fp3_set_dig(a, a[0][0])); - } - BENCH_END; - - BENCH_RUN("fp3_rand") { - BENCH_ADD(fp3_rand(a)); - } - BENCH_END; - - BENCH_RUN("fp3_size_bin") { - fp3_rand(a); - BENCH_ADD(fp3_size_bin(a)); - } - BENCH_END; - - BENCH_RUN("fp3_write_bin") { - fp3_rand(a); - BENCH_ADD(fp3_write_bin(bin, sizeof(bin), a)); - } - BENCH_END; - - BENCH_RUN("fp3_read_bin") { - fp3_rand(a); - fp3_write_bin(bin, sizeof(bin), a); - BENCH_ADD(fp3_read_bin(a, bin, sizeof(bin))); - } - BENCH_END; - - BENCH_RUN("fp3_cmp") { - fp3_rand(a); - fp3_rand(b); - BENCH_ADD(fp3_cmp(b, a)); - } - BENCH_END; - - BENCH_RUN("fp3_cmp_dig") { - fp3_rand(a); - BENCH_ADD(fp3_cmp_dig(a, (dig_t)0)); - } - BENCH_END; - - fp3_free(a); - fp3_free(b); -} - -static void arith3(void) { - fp3_t a, b, c, d[2]; - bn_t e; - - fp3_new(a); - fp3_new(b); - fp3_new(c); - fp3_new(d[0]); - fp3_new(d[1]); - bn_new(e); - - BENCH_RUN("fp3_add") { - fp3_rand(a); - fp3_rand(b); - BENCH_ADD(fp3_add(c, a, b)); - } - BENCH_END; - -#if PP_CBC == BASIC || !defined(STRIP) - BENCH_RUN("fp3_add_basic") { - fp3_rand(a); - fp3_rand(b); - BENCH_ADD(fp3_add_basic(c, a, b)); - } - BENCH_END; -#endif - -#if PP_CBC == INTEG || !defined(STRIP) - BENCH_RUN("fp3_add_integ") { - fp3_rand(a); - fp3_rand(b); - BENCH_ADD(fp3_add_integ(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("fp3_sub") { - fp3_rand(a); - fp3_rand(b); - BENCH_ADD(fp3_sub(c, a, b)); - } - BENCH_END; - -#if PP_CBC == BASIC || !defined(STRIP) - BENCH_RUN("fp3_sub_basic") { - fp3_rand(a); - fp3_rand(b); - BENCH_ADD(fp3_sub_basic(c, a, b)); - } - BENCH_END; -#endif - -#if PP_CBC == INTEG || !defined(STRIP) - BENCH_RUN("fp3_sub_integ") { - fp3_rand(a); - fp3_rand(b); - BENCH_ADD(fp3_sub_integ(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("fp3_dbl") { - fp3_rand(a); - BENCH_ADD(fp3_dbl(c, a)); - } - BENCH_END; - -#if PP_CBC == BASIC || !defined(STRIP) - BENCH_RUN("fp3_dbl_basic") { - fp3_rand(a); - BENCH_ADD(fp3_dbl_basic(c, a)); - } - BENCH_END; -#endif - -#if PP_CBC == INTEG || !defined(STRIP) - BENCH_RUN("fp3_dbl_integ") { - fp3_rand(a); - BENCH_ADD(fp3_dbl_integ(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp3_mul") { - fp3_rand(a); - fp3_rand(b); - BENCH_ADD(fp3_mul(c, a, b)); - } - BENCH_END; - -#if PP_CBC == BASIC || !defined(STRIP) - BENCH_RUN("fp3_mul_basic") { - fp3_rand(a); - fp3_rand(b); - BENCH_ADD(fp3_mul_basic(c, a, b)); - } - BENCH_END; -#endif - -#if PP_CBC == INTEG || !defined(STRIP) - BENCH_RUN("fp3_mul_integ") { - fp3_rand(a); - fp3_rand(b); - BENCH_ADD(fp3_mul_integ(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("fp3_mul_nor") { - fp3_rand(a); - BENCH_ADD(fp3_mul_nor(c, a)); - } - BENCH_END; - - BENCH_RUN("fp3_sqr") { - fp3_rand(a); - BENCH_ADD(fp3_sqr(c, a)); - } - BENCH_END; - -#if PP_CBC == BASIC || !defined(STRIP) - BENCH_RUN("fp3_sqr_basic") { - fp3_rand(a); - BENCH_ADD(fp3_sqr_basic(c, a)); - } - BENCH_END; -#endif - -#if PP_CBC == INTEG || !defined(STRIP) - BENCH_RUN("fp3_sqr_integ") { - fp3_rand(a); - BENCH_ADD(fp3_sqr_integ(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp3_inv") { - fp3_rand(a); - BENCH_ADD(fp3_inv(c, a)); - } - BENCH_END; - - BENCH_RUN("fp3_inv_sim (2)") { - fp3_rand(d[0]); - fp3_rand(d[1]); - BENCH_ADD(fp3_inv_sim(d, d, 2)); - } - BENCH_END; - - BENCH_RUN("fp3_exp") { - fp3_rand(a); - e->used = RLC_FP_DIGS; - dv_copy(e->dp, fp_prime_get(), RLC_FP_DIGS); - BENCH_ADD(fp3_exp(c, a, e)); - } - BENCH_END; - - BENCH_RUN("fp3_frb") { - fp3_rand(a); - BENCH_ADD(fp3_frb(c, a, 1)); - } - BENCH_END; - - BENCH_RUN("fp3_mul_frb (0,1)") { - fp3_rand(a); - BENCH_ADD(fp3_mul_frb(c, a, 0, 1)); - } - BENCH_END; - - BENCH_RUN("fp3_mul_frb (1,1)") { - fp3_rand(a); - BENCH_ADD(fp3_mul_frb(c, a, 1, 1)); - } - BENCH_END; - - fp3_free(a); - fp3_free(b); - fp3_free(c); - fp3_free(d[0]); - fp3_free(d[1]); - bn_free(e); -} - -static void memory4(void) { - fp4_t a[BENCH]; - - BENCH_FEW("fp4_null", fp4_null(a[i]), 1); - - BENCH_FEW("fp4_new", fp4_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - fp4_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - fp4_new(a[i]); - } - BENCH_FEW("fp4_free", fp4_free(a[i]), 1); - - (void)a; -} - -static void util4(void) { - uint8_t bin[4 * RLC_FP_BYTES]; - fp4_t a, b; - - fp4_null(a); - fp4_null(b); - - fp4_new(a); - fp4_new(b); - - BENCH_RUN("fp4_copy") { - fp4_rand(a); - BENCH_ADD(fp4_copy(b, a)); - } - BENCH_END; - - BENCH_RUN("fp4_neg") { - fp4_rand(a); - BENCH_ADD(fp4_neg(b, a)); - } - BENCH_END; - - BENCH_RUN("fp4_zero") { - fp4_rand(a); - BENCH_ADD(fp4_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp4_is_zero") { - fp4_rand(a); - BENCH_ADD((void)fp4_is_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp4_set_dig (1)") { - fp4_rand(a); - BENCH_ADD(fp4_set_dig(a, 1)); - } - BENCH_END; - - BENCH_RUN("fp4_set_dig") { - fp4_rand(a); - BENCH_ADD(fp4_set_dig(a, a[0][0][0])); - } - BENCH_END; - - BENCH_RUN("fp4_rand") { - BENCH_ADD(fp4_rand(a)); - } - BENCH_END; - - BENCH_RUN("fp4_size_bin") { - fp4_rand(a); - BENCH_ADD(fp4_size_bin(a)); - } - BENCH_END; - - BENCH_RUN("fp4_write_bin") { - fp4_rand(a); - BENCH_ADD(fp4_write_bin(bin, sizeof(bin), a)); - } - BENCH_END; - - BENCH_RUN("fp4_read_bin") { - fp4_rand(a); - fp4_write_bin(bin, sizeof(bin), a); - BENCH_ADD(fp4_read_bin(a, bin, sizeof(bin))); - } - BENCH_END; - - BENCH_RUN("fp4_cmp") { - fp4_rand(a); - fp4_rand(b); - BENCH_ADD(fp4_cmp(b, a)); - } - BENCH_END; - - BENCH_RUN("fp4_cmp_dig") { - fp4_rand(a); - BENCH_ADD(fp4_cmp_dig(a, (dig_t)0)); - } - BENCH_END; - - fp4_free(a); - fp4_free(b); -} - -static void arith4(void) { - fp4_t a, b, c; - bn_t d; - - fp4_new(a); - fp4_new(b); - fp4_new(c); - bn_new(d); - - BENCH_RUN("fp4_add") { - fp4_rand(a); - fp4_rand(b); - BENCH_ADD(fp4_add(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp4_sub") { - fp4_rand(a); - fp4_rand(b); - BENCH_ADD(fp4_sub(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp4_dbl") { - fp4_rand(a); - BENCH_ADD(fp4_dbl(c, a)); - } - BENCH_END; - - BENCH_RUN("fp4_mul") { - fp4_rand(a); - fp4_rand(b); - BENCH_ADD(fp4_mul(c, a, b)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp4_mul_basic") { - fp4_rand(a); - fp4_rand(b); - BENCH_ADD(fp4_mul_basic(c, a, b)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp4_mul_lazyr") { - fp4_rand(a); - fp4_rand(b); - BENCH_ADD(fp4_mul_lazyr(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("fp4_mul_art") { - fp4_rand(a); - BENCH_ADD(fp4_mul_art(c, a)); - } - BENCH_END; - - BENCH_RUN("fp4_sqr") { - fp4_rand(a); - BENCH_ADD(fp4_sqr(c, a)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp4_sqr_basic") { - fp4_rand(a); - BENCH_ADD(fp4_sqr_basic(c, a)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp4_sqr_lazyr") { - fp4_rand(a); - BENCH_ADD(fp4_sqr_lazyr(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp4_inv") { - fp4_rand(a); - BENCH_ADD(fp4_inv(c, a)); - } - BENCH_END; - - BENCH_RUN("fp4_exp") { - fp4_rand(a); - d->used = RLC_FP_DIGS; - dv_copy(d->dp, fp_prime_get(), RLC_FP_DIGS); - BENCH_ADD(fp4_exp(c, a, d)); - } - BENCH_END; - - BENCH_RUN("fp4_frb") { - fp4_rand(a); - BENCH_ADD(fp4_frb(c, a, 1)); - } - BENCH_END; - - BENCH_RUN("fp4_srt") { - fp4_rand(a); - fp4_sqr(a, a); - BENCH_ADD(fp4_srt(c, a)); - } - BENCH_END; - - fp4_free(a); - fp4_free(b); - fp4_free(c); - bn_free(d); -} - -static void memory6(void) { - fp6_t a[BENCH]; - - BENCH_FEW("fp6_null", fp6_null(a[i]), 1); - - BENCH_FEW("fp6_new", fp6_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - fp6_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - fp6_new(a[i]); - } - BENCH_FEW("fp6_free", fp6_free(a[i]), 1); - - (void)a; -} - -static void util6(void) { - uint8_t bin[6 * RLC_FP_BYTES]; - fp6_t a, b; - - fp6_null(a); - fp6_null(b); - - fp6_new(a); - fp6_new(b); - - BENCH_RUN("fp6_copy") { - fp6_rand(a); - BENCH_ADD(fp6_copy(b, a)); - } - BENCH_END; - - BENCH_RUN("fp6_neg") { - fp6_rand(a); - BENCH_ADD(fp6_neg(b, a)); - } - BENCH_END; - - BENCH_RUN("fp6_zero") { - fp6_rand(a); - BENCH_ADD(fp6_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp6_is_zero") { - fp6_rand(a); - BENCH_ADD((void)fp6_is_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp6_set_dig (1)") { - fp6_rand(a); - BENCH_ADD(fp6_set_dig(a, 1)); - } - BENCH_END; - - BENCH_RUN("fp6_set_dig") { - fp6_rand(a); - BENCH_ADD(fp6_set_dig(a, a[0][0][0])); - } - BENCH_END; - - BENCH_RUN("fp6_rand") { - BENCH_ADD(fp6_rand(a)); - } - BENCH_END; - - BENCH_RUN("fp6_size_bin") { - fp6_rand(a); - BENCH_ADD(fp6_size_bin(a)); - } - BENCH_END; - - BENCH_RUN("fp6_write_bin") { - fp6_rand(a); - BENCH_ADD(fp6_write_bin(bin, sizeof(bin), a)); - } - BENCH_END; - - BENCH_RUN("fp6_read_bin") { - fp6_rand(a); - fp6_write_bin(bin, sizeof(bin), a); - BENCH_ADD(fp6_read_bin(a, bin, sizeof(bin))); - } - BENCH_END; - - BENCH_RUN("fp6_cmp") { - fp6_rand(a); - fp6_rand(b); - BENCH_ADD(fp6_cmp(b, a)); - } - BENCH_END; - - BENCH_RUN("fp6_cmp_dig") { - fp6_rand(a); - BENCH_ADD(fp6_cmp_dig(a, (dig_t)0)); - } - BENCH_END; - - fp6_free(a); - fp6_free(b); -} - -static void arith6(void) { - fp6_t a, b, c; - bn_t d; - - fp6_new(a); - fp6_new(b); - fp6_new(c); - bn_new(d); - - BENCH_RUN("fp6_add") { - fp6_rand(a); - fp6_rand(b); - BENCH_ADD(fp6_add(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp6_sub") { - fp6_rand(a); - fp6_rand(b); - BENCH_ADD(fp6_sub(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp6_dbl") { - fp6_rand(a); - BENCH_ADD(fp6_dbl(c, a)); - } - BENCH_END; - - BENCH_RUN("fp6_mul") { - fp6_rand(a); - fp6_rand(b); - BENCH_ADD(fp6_mul(c, a, b)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp6_mul_basic") { - fp6_rand(a); - fp6_rand(b); - BENCH_ADD(fp6_mul_basic(c, a, b)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp6_mul_lazyr") { - fp6_rand(a); - fp6_rand(b); - BENCH_ADD(fp6_mul_lazyr(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("fp6_mul_art") { - fp6_rand(a); - BENCH_ADD(fp6_mul_art(c, a)); - } - BENCH_END; - - BENCH_RUN("fp6_sqr") { - fp6_rand(a); - BENCH_ADD(fp6_sqr(c, a)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp6_sqr_basic") { - fp6_rand(a); - BENCH_ADD(fp6_sqr_basic(c, a)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp6_sqr_lazyr") { - fp6_rand(a); - BENCH_ADD(fp6_sqr_lazyr(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp6_inv") { - fp6_rand(a); - BENCH_ADD(fp6_inv(c, a)); - } - BENCH_END; - - BENCH_RUN("fp6_exp") { - fp6_rand(a); - d->used = RLC_FP_DIGS; - dv_copy(d->dp, fp_prime_get(), RLC_FP_DIGS); - BENCH_ADD(fp6_exp(c, a, d)); - } - BENCH_END; - - BENCH_RUN("fp6_frb") { - fp6_rand(a); - BENCH_ADD(fp6_frb(c, a, 1)); - } - BENCH_END; - - fp6_free(a); - fp6_free(b); - fp6_free(c); -} - -static void memory8(void) { - fp8_t a[BENCH]; - - BENCH_FEW("fp8_null", fp8_null(a[i]), 1); - - BENCH_FEW("fp8_new", fp8_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - fp8_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - fp8_new(a[i]); - } - BENCH_FEW("fp8_free", fp8_free(a[i]), 1); - - (void)a; -} - -static void util8(void) { - fp8_t a, b; - uint8_t bin[8 * RLC_FP_BYTES]; - - fp8_null(a); - fp8_null(b); - - fp8_new(a); - fp8_new(b); - - BENCH_RUN("fp8_copy") { - fp8_rand(a); - BENCH_ADD(fp8_copy(b, a)); - } - BENCH_END; - - BENCH_RUN("fp8_neg") { - fp8_rand(a); - BENCH_ADD(fp8_neg(b, a)); - } - BENCH_END; - - BENCH_RUN("fp8_zero") { - fp8_rand(a); - BENCH_ADD(fp8_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp8_is_zero") { - fp8_rand(a); - BENCH_ADD((void)fp8_is_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp8_set_dig (1)") { - fp8_rand(a); - BENCH_ADD(fp8_set_dig(a, 1)); - } - BENCH_END; - - BENCH_RUN("fp8_set_dig") { - fp8_rand(a); - BENCH_ADD(fp8_set_dig(a, a[0][0][0][0])); - } - BENCH_END; - - BENCH_RUN("fp8_rand") { - BENCH_ADD(fp8_rand(a)); - } - BENCH_END; - - BENCH_RUN("fp8_size_bin (0)") { - fp8_rand(a); - BENCH_ADD(fp8_size_bin(a, 0)); - } - BENCH_END; - - BENCH_RUN("fp8_size_bin (1)") { - fp8_rand(a); - fp8_conv_cyc(a, a); - BENCH_ADD(fp8_size_bin(a, 1)); - } - BENCH_END; - - BENCH_RUN("fp8_write_bin") { - fp8_rand(a); - BENCH_ADD(fp8_write_bin(bin, sizeof(bin), a)); - } - BENCH_END; - - BENCH_RUN("fp8_read_bin") { - fp8_rand(a); - fp8_write_bin(bin, sizeof(bin), a); - BENCH_ADD(fp8_read_bin(a, bin, sizeof(bin))); - } - BENCH_END; - - BENCH_RUN("fp8_cmp") { - fp8_rand(a); - fp8_rand(b); - BENCH_ADD(fp8_cmp(b, a)); - } - BENCH_END; - - BENCH_RUN("fp8_cmp_dig") { - fp8_rand(a); - BENCH_ADD(fp8_cmp_dig(a, (dig_t)0)); - } - BENCH_END; - - fp8_free(a); - fp8_free(b); -} - -static void arith8(void) { - fp8_t a, b, c, d[2]; - bn_t e; - - fp8_new(a); - fp8_new(b); - fp8_new(c); - fp8_new(d[0]); - fp8_new(d[1]); - bn_new(e); - - BENCH_RUN("fp8_add") { - fp8_rand(a); - fp8_rand(b); - BENCH_ADD(fp8_add(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp8_sub") { - fp8_rand(a); - fp8_rand(b); - BENCH_ADD(fp8_sub(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp8_mul") { - fp8_rand(a); - fp8_rand(b); - BENCH_ADD(fp8_mul(c, a, b)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp8_mul_basic") { - fp8_rand(a); - fp8_rand(b); - BENCH_ADD(fp8_mul_basic(c, a, b)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp8_mul_lazyr") { - fp8_rand(a); - fp8_rand(b); - BENCH_ADD(fp8_mul_lazyr(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("fp8_mul_dxs") { - fp8_rand(a); - fp8_rand(b); - BENCH_ADD(fp8_mul_dxs(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp8_sqr") { - fp8_rand(a); - BENCH_ADD(fp8_sqr(c, a)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp8_sqr_basic") { - fp8_rand(a); - BENCH_ADD(fp8_sqr_basic(c, a)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp8_sqr_lazyr") { - fp8_rand(a); - BENCH_ADD(fp8_sqr_lazyr(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp8_sqr_cyc") { - fp8_rand(a); - BENCH_ADD(fp8_sqr_cyc(c, a)); - } - BENCH_END; - - BENCH_RUN("fp8_test_cyc") { - fp8_rand(a); - fp8_conv_cyc(a, a); - BENCH_ADD(fp8_test_cyc(a)); - } - BENCH_END; - - BENCH_RUN("fp8_conv_cyc") { - fp8_rand(a); - BENCH_ADD(fp8_conv_cyc(c, a)); - } - BENCH_END; - - BENCH_RUN("fp8_inv") { - fp8_rand(a); - BENCH_ADD(fp8_inv(c, a)); - } - BENCH_END; - - BENCH_RUN("fp8_inv_sim (2)") { - fp8_rand(d[0]); - fp8_rand(d[1]); - BENCH_ADD(fp8_inv_sim(d, d, 2)); - } - BENCH_END; - - BENCH_RUN("fp8_inv_sim (2)") { - fp8_rand(d[0]); - fp8_rand(d[1]); - BENCH_ADD(fp8_inv_sim(d, d, 2)); - } - BENCH_END; - - BENCH_RUN("fp8_inv_cyc") { - fp8_rand(a); - BENCH_ADD(fp8_inv_cyc(c, a)); - } - BENCH_END; - - BENCH_RUN("fp8_exp") { - fp8_rand(a); - bn_rand(e, RLC_POS, RLC_FP_BITS); - BENCH_ADD(fp8_exp(c, a, e)); - } - BENCH_END; - - BENCH_RUN("fp8_exp (cyc)") { - fp8_rand(a); - fp8_conv_cyc(a, a); - bn_rand(e, RLC_POS, RLC_FP_BITS); - BENCH_ADD(fp8_exp(c, a, e)); - } - BENCH_END; - - BENCH_RUN("fp8_exp_cyc (param or sparse)") { - fp8_rand(a); - fp8_conv_cyc(a, a); - bn_zero(e); - fp_prime_get_par(e); - if (bn_is_zero(e)) { - bn_set_2b(e, RLC_FP_BITS - 1); - bn_set_bit(e, RLC_FP_BITS / 2, 1); - bn_set_bit(e, 0, 1); - } - BENCH_ADD(fp8_exp_cyc(c, a, e)); - } - BENCH_END; - - BENCH_RUN("fp8_frb") { - fp8_rand(a); - BENCH_ADD(fp8_frb(c, a, 1)); - } - BENCH_END; - - fp8_free(a); - fp8_free(b); - fp8_free(c); - fp8_free(d[0]); - fp8_free(d[1]); - bn_free(e); -} - -static void memory9(void) { - fp9_t a[BENCH]; - - BENCH_FEW("fp9_null", fp9_null(a[i]), 1); - - BENCH_FEW("fp9_new", fp9_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - fp9_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - fp9_new(a[i]); - } - BENCH_FEW("fp9_free", fp9_free(a[i]), 1); - - (void)a; -} - -static void util9(void) { - uint8_t bin[9 * RLC_FP_BYTES]; - fp9_t a, b; - - fp9_null(a); - fp9_null(b); - - fp9_new(a); - fp9_new(b); - - BENCH_RUN("fp9_copy") { - fp9_rand(a); - BENCH_ADD(fp9_copy(b, a)); - } - BENCH_END; - - BENCH_RUN("fp9_neg") { - fp9_rand(a); - BENCH_ADD(fp9_neg(b, a)); - } - BENCH_END; - - BENCH_RUN("fp9_zero") { - fp9_rand(a); - BENCH_ADD(fp9_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp9_is_zero") { - fp9_rand(a); - BENCH_ADD((void)fp9_is_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp9_set_dig (1)") { - fp9_rand(a); - BENCH_ADD(fp9_set_dig(a, 1)); - } - BENCH_END; - - BENCH_RUN("fp9_set_dig") { - fp9_rand(a); - BENCH_ADD(fp9_set_dig(a, a[0][0][0])); - } - BENCH_END; - - BENCH_RUN("fp9_rand") { - BENCH_ADD(fp9_rand(a)); - } - BENCH_END; - - BENCH_RUN("fp9_size_bin") { - fp9_rand(a); - BENCH_ADD(fp9_size_bin(a)); - } - BENCH_END; - - BENCH_RUN("fp9_write_bin") { - fp9_rand(a); - BENCH_ADD(fp9_write_bin(bin, sizeof(bin), a)); - } - BENCH_END; - - BENCH_RUN("fp9_read_bin") { - fp9_rand(a); - fp9_write_bin(bin, sizeof(bin), a); - BENCH_ADD(fp9_read_bin(a, bin, sizeof(bin))); - } - BENCH_END; - - BENCH_RUN("fp9_cmp") { - fp9_rand(a); - fp9_rand(b); - BENCH_ADD(fp9_cmp(b, a)); - } - BENCH_END; - - BENCH_RUN("fp9_cmp_dig") { - fp9_rand(a); - BENCH_ADD(fp9_cmp_dig(a, (dig_t)0)); - } - BENCH_END; - - fp9_free(a); - fp9_free(b); -} - -static void arith9(void) { - fp9_t a, b, c; - bn_t d; - - fp9_new(a); - fp9_new(b); - fp9_new(c); - bn_new(d); - - BENCH_RUN("fp9_add") { - fp9_rand(a); - fp9_rand(b); - BENCH_ADD(fp9_add(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp9_sub") { - fp9_rand(a); - fp9_rand(b); - BENCH_ADD(fp9_sub(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp9_dbl") { - fp9_rand(a); - BENCH_ADD(fp9_dbl(c, a)); - } - BENCH_END; - - BENCH_RUN("fp9_mul") { - fp9_rand(a); - fp9_rand(b); - BENCH_ADD(fp9_mul(c, a, b)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp9_mul_basic") { - fp9_rand(a); - fp9_rand(b); - BENCH_ADD(fp9_mul_basic(c, a, b)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp9_mul_lazyr") { - fp9_rand(a); - fp9_rand(b); - BENCH_ADD(fp9_mul_lazyr(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("fp9_mul_art") { - fp9_rand(a); - BENCH_ADD(fp9_mul_art(c, a)); - } - BENCH_END; - - BENCH_RUN("fp9_sqr") { - fp9_rand(a); - BENCH_ADD(fp9_sqr(c, a)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp9_sqr_basic") { - fp9_rand(a); - BENCH_ADD(fp9_sqr_basic(c, a)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp9_sqr_lazyr") { - fp9_rand(a); - BENCH_ADD(fp9_sqr_lazyr(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp9_inv") { - fp9_rand(a); - BENCH_ADD(fp9_inv(c, a)); - } - BENCH_END; - - BENCH_RUN("fp9_exp") { - fp9_rand(a); - d->used = RLC_FP_DIGS; - dv_copy(d->dp, fp_prime_get(), RLC_FP_DIGS); - BENCH_ADD(fp9_exp(c, a, d)); - } - BENCH_END; - - BENCH_RUN("fp9_frb") { - fp9_rand(a); - BENCH_ADD(fp9_frb(c, a, 1)); - } - BENCH_END; - - fp9_free(a); - fp9_free(b); - fp9_free(c); -} - -static void memory12(void) { - fp12_t a[BENCH]; - - BENCH_FEW("fp12_null", fp12_null(a[i]), 1); - - BENCH_FEW("fp12_new", fp12_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - fp12_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - fp12_new(a[i]); - } - BENCH_FEW("fp12_free", fp12_free(a[i]), 1); - - (void)a; -} - -static void util12(void) { - fp12_t a, b; - uint8_t bin[12 * RLC_FP_BYTES]; - - fp12_null(a); - fp12_null(b); - - fp12_new(a); - fp12_new(b); - - BENCH_RUN("fp12_copy") { - fp12_rand(a); - BENCH_ADD(fp12_copy(b, a)); - } - BENCH_END; - - BENCH_RUN("fp12_neg") { - fp12_rand(a); - BENCH_ADD(fp12_neg(b, a)); - } - BENCH_END; - - BENCH_RUN("fp12_zero") { - fp12_rand(a); - BENCH_ADD(fp12_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp12_is_zero") { - fp12_rand(a); - BENCH_ADD((void)fp12_is_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp12_set_dig (1)") { - fp12_rand(a); - BENCH_ADD(fp12_set_dig(a, 1)); - } - BENCH_END; - - BENCH_RUN("fp12_set_dig") { - fp12_rand(a); - BENCH_ADD(fp12_set_dig(a, a[0][0][0][0])); - } - BENCH_END; - - BENCH_RUN("fp12_rand") { - BENCH_ADD(fp12_rand(a)); - } - BENCH_END; - - BENCH_RUN("fp12_size_bin (0)") { - fp12_rand(a); - BENCH_ADD(fp12_size_bin(a, 0)); - } - BENCH_END; - - BENCH_RUN("fp12_size_bin (1)") { - fp12_rand(a); - fp12_conv_cyc(a, a); - BENCH_ADD(fp12_size_bin(a, 1)); - } - BENCH_END; - - BENCH_RUN("fp12_write_bin (0)") { - fp12_rand(a); - BENCH_ADD(fp12_write_bin(bin, sizeof(bin), a, 0)); - } - BENCH_END; - - BENCH_RUN("fp12_write_bin (1)") { - fp12_rand(a); - fp12_conv_cyc(a, a); - BENCH_ADD(fp12_write_bin(bin, 8 * RLC_FP_BYTES, a, 1)); - } - BENCH_END; - - BENCH_RUN("fp12_read_bin (0)") { - fp12_rand(a); - fp12_write_bin(bin, sizeof(bin), a, 0); - BENCH_ADD(fp12_read_bin(a, bin, sizeof(bin))); - } - BENCH_END; - - BENCH_RUN("fp12_read_bin (1)") { - fp12_rand(a); - fp12_conv_cyc(a, a); - fp12_write_bin(bin, fp12_size_bin(a, 1), a, 1); - BENCH_ADD(fp12_read_bin(a, bin, 8 * RLC_FP_BYTES)); - } - BENCH_END; - - BENCH_RUN("fp12_cmp") { - fp12_rand(a); - fp12_rand(b); - BENCH_ADD(fp12_cmp(b, a)); - } - BENCH_END; - - BENCH_RUN("fp12_cmp_dig") { - fp12_rand(a); - BENCH_ADD(fp12_cmp_dig(a, (dig_t)0)); - } - BENCH_END; - - fp12_free(a); - fp12_free(b); -} - -static void arith12(void) { - fp12_t a, b, c, d[2]; - bn_t e; - - fp12_new(a); - fp12_new(b); - fp12_new(c); - fp12_new(d[0]); - fp12_new(d[1]); - bn_new(e); - - BENCH_RUN("fp12_add") { - fp12_rand(a); - fp12_rand(b); - BENCH_ADD(fp12_add(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp12_sub") { - fp12_rand(a); - fp12_rand(b); - BENCH_ADD(fp12_sub(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp12_mul") { - fp12_rand(a); - fp12_rand(b); - BENCH_ADD(fp12_mul(c, a, b)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp12_mul_basic") { - fp12_rand(a); - fp12_rand(b); - BENCH_ADD(fp12_mul_basic(c, a, b)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp12_mul_lazyr") { - fp12_rand(a); - fp12_rand(b); - BENCH_ADD(fp12_mul_lazyr(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("fp12_mul_dxs") { - fp12_rand(a); - fp12_rand(b); - BENCH_ADD(fp12_mul_dxs(c, a, b)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp12_mul_dxs_basic") { - fp12_rand(a); - fp12_rand(b); - BENCH_ADD(fp12_mul_dxs_basic(c, a, b)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp12_mul_dxs_lazyr") { - fp12_rand(a); - fp12_rand(b); - BENCH_ADD(fp12_mul_dxs_lazyr(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("fp12_sqr") { - fp12_rand(a); - BENCH_ADD(fp12_sqr(c, a)); - } - BENCH_END; - - BENCH_RUN("fp12_sqr_cyc") { - fp12_rand(a); - BENCH_ADD(fp12_sqr_cyc(c, a)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp12_sqr_cyc_basic") { - fp12_rand(a); - fp12_rand(b); - BENCH_ADD(fp12_sqr_cyc_basic(c, a)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp12_sqr_cyc_lazyr") { - fp12_rand(a); - fp12_rand(b); - BENCH_ADD(fp12_sqr_cyc_lazyr(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp12_sqr_pck") { - fp12_rand(a); - BENCH_ADD(fp12_sqr_pck(c, a)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp12_sqr_pck_basic") { - fp12_rand(a); - fp12_rand(b); - BENCH_ADD(fp12_sqr_pck_basic(c, a)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp12_sqr_pck_lazyr") { - fp12_rand(a); - fp12_rand(b); - BENCH_ADD(fp12_sqr_pck_lazyr(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp12_test_cyc") { - fp12_rand(a); - fp12_conv_cyc(a, a); - BENCH_ADD(fp12_test_cyc(a)); - } - BENCH_END; - - BENCH_RUN("fp12_conv_cyc") { - fp12_rand(a); - BENCH_ADD(fp12_conv_cyc(c, a)); - } - BENCH_END; - - BENCH_RUN("fp12_back_cyc") { - fp12_rand(a); - BENCH_ADD(fp12_back_cyc(c, a)); - } - BENCH_END; - - BENCH_RUN("fp12_back_cyc (2)") { - fp12_rand(d[0]); - fp12_rand(d[1]); - BENCH_ADD(fp12_back_cyc_sim(d, d, 2)); - } - BENCH_END; - - BENCH_RUN("fp12_conv_cyc") { - fp12_rand(a); - BENCH_ADD(fp12_conv_cyc(c, a)); - } - BENCH_END; - - BENCH_RUN("fp12_inv") { - fp12_rand(a); - BENCH_ADD(fp12_inv(c, a)); - } - BENCH_END; - - BENCH_RUN("fp12_inv_cyc") { - fp12_rand(a); - BENCH_ADD(fp12_inv_cyc(c, a)); - } - BENCH_END; - - BENCH_RUN("fp12_exp") { - fp12_rand(a); - bn_rand(e, RLC_POS, RLC_FP_BITS); - BENCH_ADD(fp12_exp(c, a, e)); - } - BENCH_END; - - BENCH_RUN("fp12_exp (cyc)") { - fp12_rand(a); - fp12_conv_cyc(a, a); - bn_rand(e, RLC_POS, RLC_FP_BITS); - BENCH_ADD(fp12_exp(c, a, e)); - } - BENCH_END; - - BENCH_RUN("fp12_exp_cyc (param or sparse)") { - fp12_rand(a); - fp12_conv_cyc(a, a); - bn_zero(e); - fp_prime_get_par(e); - if (bn_is_zero(e)) { - bn_set_2b(e, RLC_FP_BITS - 1); - bn_set_bit(e, RLC_FP_BITS / 2, 1); - bn_set_bit(e, 0, 1); - } - BENCH_ADD(fp12_exp_cyc(c, a, e)); - } - BENCH_END; - - BENCH_RUN("fp12_exp_cyc_sps (param)") { - const int *k; - int l; - k = fp_prime_get_par_sps(&l); - fp12_rand(a); - BENCH_ADD(fp12_exp_cyc_sps(c, a, k, l, RLC_POS)); - } - BENCH_END; - - BENCH_RUN("fp12_exp_dig") { - fp12_rand(a); - bn_rand(e, RLC_POS, RLC_DIG); - BENCH_ADD(fp12_exp_dig(c, a, e->dp[0])); - } - BENCH_END; - - BENCH_RUN("fp12_frb") { - fp12_rand(a); - BENCH_ADD(fp12_frb(c, a, 1)); - } - BENCH_END; - - BENCH_RUN("fp12_pck") { - fp12_rand(a); - fp12_conv_cyc(a, a); - BENCH_ADD(fp12_pck(c, a)); - } - BENCH_END; - - BENCH_RUN("fp12_upk") { - fp12_rand(a); - fp12_conv_cyc(a, a); - fp12_pck(a, a); - BENCH_ADD(fp12_upk(c, a)); - } - BENCH_END; - - BENCH_RUN("fp12_pck_max") { - fp12_rand(a); - fp12_conv_cyc(a, a); - BENCH_ADD(fp12_pck_max(c, a)); - } - BENCH_END; - - BENCH_RUN("fp12_upk_max") { - fp12_rand(a); - fp12_conv_cyc(a, a); - fp12_pck_max(a, a); - BENCH_ADD(fp12_upk_max(c, a)); - } - BENCH_END; - - fp12_free(a); - fp12_free(b); - fp12_free(c); - fp12_free(d[0]); - fp12_free(d[1]); - bn_free(e); -} - -static void memory18(void) { - fp18_t a[BENCH]; - - BENCH_FEW("fp18_null", fp18_null(a[i]), 1); - - BENCH_FEW("fp18_new", fp18_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - fp18_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - fp18_new(a[i]); - } - BENCH_FEW("fp18_free", fp18_free(a[i]), 1); - - (void)a; -} - -static void util18(void) { - fp18_t a, b; - - fp18_null(a); - fp18_null(b); - - fp18_new(a); - fp18_new(b); - - BENCH_RUN("fp18_copy") { - fp18_rand(a); - BENCH_ADD(fp18_copy(b, a)); - } - BENCH_END; - - BENCH_RUN("fp18_neg") { - fp18_rand(a); - BENCH_ADD(fp18_neg(b, a)); - } - BENCH_END; - - BENCH_RUN("fp18_zero") { - fp18_rand(a); - BENCH_ADD(fp18_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp18_is_zero") { - fp18_rand(a); - BENCH_ADD((void)fp18_is_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp18_set_dig (1)") { - fp18_rand(a); - BENCH_ADD(fp18_set_dig(a, 1)); - } - BENCH_END; - - BENCH_RUN("fp18_set_dig") { - fp18_rand(a); - BENCH_ADD(fp18_set_dig(a, a[0][0][0][0])); - } - BENCH_END; - - BENCH_RUN("fp18_rand") { - BENCH_ADD(fp18_rand(a)); - } - BENCH_END; - - BENCH_RUN("fp18_cmp") { - fp18_rand(a); - fp18_rand(b); - BENCH_ADD(fp18_cmp(b, a)); - } - BENCH_END; - - BENCH_RUN("fp18_cmp_dig") { - fp18_rand(a); - BENCH_ADD(fp18_cmp_dig(a, (dig_t)0)); - } - BENCH_END; - - fp18_free(a); - fp18_free(b); -} - -static void arith18(void) { - fp18_t a, b, c; - bn_t e; - - fp18_new(a); - fp18_new(b); - fp18_new(c); - bn_new(e); - - BENCH_RUN("fp18_add") { - fp18_rand(a); - fp18_rand(b); - BENCH_ADD(fp18_add(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp18_sub") { - fp18_rand(a); - fp18_rand(b); - BENCH_ADD(fp18_sub(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp18_mul") { - fp18_rand(a); - fp18_rand(b); - BENCH_ADD(fp18_mul(c, a, b)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp18_mul_basic") { - fp18_rand(a); - fp18_rand(b); - BENCH_ADD(fp18_mul_basic(c, a, b)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp18_mul_lazyr") { - fp18_rand(a); - fp18_rand(b); - BENCH_ADD(fp18_mul_lazyr(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("fp18_sqr") { - fp18_rand(a); - BENCH_ADD(fp18_sqr(c, a)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp18_sqr_basic") { - fp18_rand(a); - BENCH_ADD(fp18_sqr_basic(c, a)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp18_sqr_lazyr") { - fp18_rand(a); - BENCH_ADD(fp18_sqr_lazyr(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp18_inv") { - fp18_rand(a); - BENCH_ADD(fp18_inv(c, a)); - } - BENCH_END; - - BENCH_RUN("fp18_exp") { - fp18_rand(a); - e->used = RLC_FP_DIGS; - dv_copy(e->dp, fp_prime_get(), RLC_FP_DIGS); - BENCH_ADD(fp18_exp(c, a, e)); - } - BENCH_END; - - BENCH_RUN("fp18_frb") { - fp18_rand(a); - BENCH_ADD(fp18_frb(c, a, 1)); - } - BENCH_END; - - fp18_free(a); - fp18_free(b); - fp18_free(c); - bn_free(e); -} - -static void memory24(void) { - fp24_t a[BENCH]; - - BENCH_FEW("fp24_null", fp24_null(a[i]), 1); - - BENCH_FEW("fp24_new", fp24_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - fp24_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - fp24_new(a[i]); - } - BENCH_FEW("fp24_free", fp24_free(a[i]), 1); - - (void)a; -} - -static void util24(void) { - fp24_t a, b; - uint8_t bin[24 * RLC_FP_BYTES]; - - fp24_null(a); - fp24_null(b); - - fp24_new(a); - fp24_new(b); - - BENCH_RUN("fp24_copy") { - fp24_rand(a); - BENCH_ADD(fp24_copy(b, a)); - } - BENCH_END; - - BENCH_RUN("fp24_neg") { - fp24_rand(a); - BENCH_ADD(fp24_neg(b, a)); - } - BENCH_END; - - BENCH_RUN("fp24_zero") { - fp24_rand(a); - BENCH_ADD(fp24_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp24_is_zero") { - fp24_rand(a); - BENCH_ADD((void)fp24_is_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp24_set_dig (1)") { - fp24_rand(a); - BENCH_ADD(fp24_set_dig(a, 1)); - } - BENCH_END; - - BENCH_RUN("fp24_set_dig") { - fp24_rand(a); - BENCH_ADD(fp24_set_dig(a, a[0][0][0][0][0])); - } - BENCH_END; - - BENCH_RUN("fp24_rand") { - BENCH_ADD(fp24_rand(a)); - } - BENCH_END; - - BENCH_RUN("fp24_size_bin (0)") { - fp24_rand(a); - BENCH_ADD(fp24_size_bin(a, 0)); - } - BENCH_END; - - BENCH_RUN("fp24_size_bin (1)") { - fp24_rand(a); - fp24_conv_cyc(a, a); - BENCH_ADD(fp24_size_bin(a, 1)); - } - BENCH_END; - - BENCH_RUN("fp24_write_bin (0)") { - fp24_rand(a); - BENCH_ADD(fp24_write_bin(bin, sizeof(bin), a, 0)); - } - BENCH_END; - - BENCH_RUN("fp24_write_bin (1)") { - fp24_rand(a); - fp24_conv_cyc(a, a); - BENCH_ADD(fp24_write_bin(bin, 32 * RLC_FP_BYTES, a, 1)); - } - BENCH_END; - - BENCH_RUN("fp24_read_bin (0)") { - fp24_rand(a); - fp24_write_bin(bin, sizeof(bin), a, 0); - BENCH_ADD(fp24_read_bin(a, bin, sizeof(bin))); - } - BENCH_END; - - BENCH_RUN("fp24_read_bin (1)") { - fp24_rand(a); - fp24_conv_cyc(a, a); - fp24_write_bin(bin, fp24_size_bin(a, 1), a, 1); - BENCH_ADD(fp24_read_bin(a, bin, 32 * RLC_FP_BYTES)); - } - BENCH_END; - - BENCH_RUN("fp24_cmp") { - fp24_rand(a); - fp24_rand(b); - BENCH_ADD(fp24_cmp(b, a)); - } - BENCH_END; - - BENCH_RUN("fp24_cmp_dig") { - fp24_rand(a); - BENCH_ADD(fp24_cmp_dig(a, (dig_t)0)); - } - BENCH_END; - - fp24_free(a); - fp24_free(b); -} - -static void arith24(void) { - fp24_t a, b, c, d[2]; - bn_t e; - - fp24_new(a); - fp24_new(b); - fp24_new(c); - fp24_new(d[0]); - fp24_new(d[1]); - bn_new(e); - - BENCH_RUN("fp24_add") { - fp24_rand(a); - fp24_rand(b); - BENCH_ADD(fp24_add(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp24_sub") { - fp24_rand(a); - fp24_rand(b); - BENCH_ADD(fp24_sub(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp24_mul") { - fp24_rand(a); - fp24_rand(b); - BENCH_ADD(fp24_mul(c, a, b)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp24_mul_basic") { - fp24_rand(a); - fp24_rand(b); - BENCH_ADD(fp24_mul_basic(c, a, b)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp24_mul_lazyr") { - fp24_rand(a); - fp24_rand(b); - BENCH_ADD(fp24_mul_lazyr(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("fp24_sqr") { - fp24_rand(a); - BENCH_ADD(fp24_sqr(c, a)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp24_sqr_basic") { - fp24_rand(a); - BENCH_ADD(fp24_sqr_basic(c, a)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp24_sqr_lazyr") { - fp24_rand(a); - BENCH_ADD(fp24_sqr_lazyr(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp24_test_cyc") { - fp24_rand(a); - fp24_conv_cyc(a, a); - BENCH_ADD(fp24_test_cyc(a)); - } - BENCH_END; - - BENCH_RUN("fp24_conv_cyc") { - fp24_rand(a); - BENCH_ADD(fp24_conv_cyc(c, a)); - } - BENCH_END; - - BENCH_RUN("fp24_back_cyc") { - fp24_rand(a); - BENCH_ADD(fp24_back_cyc(c, a)); - } - BENCH_END; - - BENCH_RUN("fp24_back_cyc (2)") { - fp24_rand(d[0]); - fp24_rand(d[1]); - BENCH_ADD(fp24_back_cyc_sim(d, d, 2)); - } - BENCH_END; - - BENCH_RUN("fp24_conv_cyc") { - fp24_rand(a); - BENCH_ADD(fp24_conv_cyc(c, a)); - } - BENCH_END; - - BENCH_RUN("fp24_inv") { - fp24_rand(a); - BENCH_ADD(fp24_inv(c, a)); - } - BENCH_END; - - BENCH_RUN("fp24_exp") { - fp24_rand(a); - bn_rand(e, RLC_POS, RLC_FP_BITS); - BENCH_ADD(fp24_exp(c, a, e)); - } - BENCH_END; - - BENCH_RUN("fp24_exp (cyc)") { - fp24_rand(a); - fp24_conv_cyc(a, a); - bn_rand(e, RLC_POS, RLC_FP_BITS); - BENCH_ADD(fp24_exp(c, a, e)); - } - BENCH_END; - - BENCH_RUN("fp24_exp_cyc (param or sparse)") { - fp24_rand(a); - fp24_conv_cyc(a, a); - bn_zero(e); - fp_prime_get_par(e); - if (bn_is_zero(e)) { - bn_set_2b(e, RLC_FP_BITS - 1); - bn_set_bit(e, RLC_FP_BITS / 2, 1); - bn_set_bit(e, 0, 1); - } - BENCH_ADD(fp24_exp_cyc(c, a, e)); - } - BENCH_END; - - BENCH_RUN("fp24_exp_cyc_sps (param)") { - const int *k; - int l; - k = fp_prime_get_par_sps(&l); - fp24_rand(a); - BENCH_ADD(fp24_exp_cyc_sps(c, a, k, l, RLC_POS)); - } - BENCH_END; - - BENCH_RUN("fp24_exp_dig") { - fp24_rand(a); - bn_rand(e, RLC_POS, RLC_DIG); - BENCH_ADD(fp24_exp_dig(c, a, e->dp[0])); - } - BENCH_END; - - BENCH_RUN("fp24_frb") { - fp24_rand(a); - BENCH_ADD(fp24_frb(c, a, 1)); - } - BENCH_END; - - BENCH_RUN("fp24_pck") { - fp24_rand(a); - fp24_conv_cyc(a, a); - BENCH_ADD(fp24_pck(c, a)); - } - BENCH_END; - - BENCH_RUN("fp24_upk") { - fp24_rand(a); - fp24_conv_cyc(a, a); - fp24_pck(a, a); - BENCH_ADD(fp24_upk(c, a)); - } - BENCH_END; - - fp24_free(a); - fp24_free(b); - fp24_free(c); - fp24_free(d[0]); - fp24_free(d[1]); - bn_free(e); -} - -static void memory48(void) { - fp48_t a[BENCH]; - - BENCH_FEW("fp48_null", fp48_null(a[i]), 1); - - BENCH_FEW("fp48_new", fp48_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - fp48_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - fp48_new(a[i]); - } - BENCH_FEW("fp48_free", fp48_free(a[i]), 1); - - (void)a; -} - -static void util48(void) { - fp48_t a, b; - uint8_t bin[48 * RLC_FP_BYTES]; - - fp48_null(a); - fp48_null(b); - - fp48_new(a); - fp48_new(b); - - BENCH_RUN("fp48_copy") { - fp48_rand(a); - BENCH_ADD(fp48_copy(b, a)); - } - BENCH_END; - - BENCH_RUN("fp48_neg") { - fp48_rand(a); - BENCH_ADD(fp48_neg(b, a)); - } - BENCH_END; - - BENCH_RUN("fp48_zero") { - fp48_rand(a); - BENCH_ADD(fp48_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp48_is_zero") { - fp48_rand(a); - BENCH_ADD((void)fp48_is_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp48_set_dig (1)") { - fp48_rand(a); - BENCH_ADD(fp48_set_dig(a, 1)); - } - BENCH_END; - - BENCH_RUN("fp48_set_dig") { - fp48_rand(a); - BENCH_ADD(fp48_set_dig(a, a[0][0][0][0][0][0])); - } - BENCH_END; - - BENCH_RUN("fp48_rand") { - BENCH_ADD(fp48_rand(a)); - } - BENCH_END; - - BENCH_RUN("fp48_size_bin (0)") { - fp48_rand(a); - BENCH_ADD(fp48_size_bin(a, 0)); - } - BENCH_END; - - BENCH_RUN("fp48_size_bin (1)") { - fp48_rand(a); - fp48_conv_cyc(a, a); - BENCH_ADD(fp48_size_bin(a, 1)); - } - BENCH_END; - - BENCH_RUN("fp48_write_bin (0)") { - fp48_rand(a); - BENCH_ADD(fp48_write_bin(bin, sizeof(bin), a, 0)); - } - BENCH_END; - - BENCH_RUN("fp48_write_bin (1)") { - fp48_rand(a); - fp48_conv_cyc(a, a); - BENCH_ADD(fp48_write_bin(bin, 32 * RLC_FP_BYTES, a, 1)); - } - BENCH_END; - - BENCH_RUN("fp48_read_bin (0)") { - fp48_rand(a); - fp48_write_bin(bin, sizeof(bin), a, 0); - BENCH_ADD(fp48_read_bin(a, bin, sizeof(bin))); - } - BENCH_END; - - BENCH_RUN("fp48_read_bin (1)") { - fp48_rand(a); - fp48_conv_cyc(a, a); - fp48_write_bin(bin, fp48_size_bin(a, 1), a, 1); - BENCH_ADD(fp48_read_bin(a, bin, 32 * RLC_FP_BYTES)); - } - BENCH_END; - - BENCH_RUN("fp48_cmp") { - fp48_rand(a); - fp48_rand(b); - BENCH_ADD(fp48_cmp(b, a)); - } - BENCH_END; - - BENCH_RUN("fp48_cmp_dig") { - fp48_rand(a); - BENCH_ADD(fp48_cmp_dig(a, (dig_t)0)); - } - BENCH_END; - - fp48_free(a); - fp48_free(b); -} - -static void arith48(void) { - fp48_t a, b, c, d[2]; - bn_t e; - - fp48_new(a); - fp48_new(b); - fp48_new(c); - fp48_new(d[0]); - fp48_new(d[1]); - bn_new(e); - - BENCH_RUN("fp48_add") { - fp48_rand(a); - fp48_rand(b); - BENCH_ADD(fp48_add(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp48_sub") { - fp48_rand(a); - fp48_rand(b); - BENCH_ADD(fp48_sub(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp48_mul") { - fp48_rand(a); - fp48_rand(b); - BENCH_ADD(fp48_mul(c, a, b)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp48_mul_basic") { - fp48_rand(a); - fp48_rand(b); - BENCH_ADD(fp48_mul_basic(c, a, b)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp48_mul_lazyr") { - fp48_rand(a); - fp48_rand(b); - BENCH_ADD(fp48_mul_lazyr(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("fp48_mul_dxs") { - fp48_rand(a); - fp48_rand(b); - BENCH_ADD(fp48_mul_dxs(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp48_sqr") { - fp48_rand(a); - BENCH_ADD(fp48_sqr(c, a)); - } - BENCH_END; - - BENCH_RUN("fp48_sqr_cyc") { - fp48_rand(a); - BENCH_ADD(fp48_sqr_cyc(c, a)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp48_sqr_cyc_basic") { - fp48_rand(a); - fp48_rand(b); - BENCH_ADD(fp48_sqr_cyc_basic(c, a)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp48_sqr_cyc_lazyr") { - fp48_rand(a); - fp48_rand(b); - BENCH_ADD(fp48_sqr_cyc_lazyr(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp48_sqr_pck") { - fp48_rand(a); - BENCH_ADD(fp48_sqr_pck(c, a)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp48_sqr_pck_basic") { - fp48_rand(a); - fp48_rand(b); - BENCH_ADD(fp48_sqr_pck_basic(c, a)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp48_sqr_pck_lazyr") { - fp48_rand(a); - fp48_rand(b); - BENCH_ADD(fp48_sqr_pck_lazyr(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp48_test_cyc") { - fp48_rand(a); - fp48_conv_cyc(a, a); - BENCH_ADD(fp48_test_cyc(a)); - } - BENCH_END; - - BENCH_RUN("fp48_conv_cyc") { - fp48_rand(a); - BENCH_ADD(fp48_conv_cyc(c, a)); - } - BENCH_END; - - BENCH_RUN("fp48_back_cyc") { - fp48_rand(a); - BENCH_ADD(fp48_back_cyc(c, a)); - } - BENCH_END; - - BENCH_RUN("fp48_back_cyc (2)") { - fp48_rand(d[0]); - fp48_rand(d[1]); - BENCH_ADD(fp48_back_cyc_sim(d, d, 2)); - } - BENCH_END; - - BENCH_RUN("fp48_conv_cyc") { - fp48_rand(a); - BENCH_ADD(fp48_conv_cyc(c, a)); - } - BENCH_END; - - BENCH_RUN("fp48_inv") { - fp48_rand(a); - BENCH_ADD(fp48_inv(c, a)); - } - BENCH_END; - - BENCH_RUN("fp48_inv_cyc") { - fp48_rand(a); - BENCH_ADD(fp48_inv_cyc(c, a)); - } - BENCH_END; - - BENCH_RUN("fp48_exp") { - fp48_rand(a); - bn_rand(e, RLC_POS, RLC_FP_BITS); - BENCH_ADD(fp48_exp(c, a, e)); - } - BENCH_END; - - BENCH_RUN("fp48_exp (cyc)") { - fp48_rand(a); - fp48_conv_cyc(a, a); - bn_rand(e, RLC_POS, RLC_FP_BITS); - BENCH_ADD(fp48_exp(c, a, e)); - } - BENCH_END; - - BENCH_RUN("fp48_exp_cyc (param or sparse)") { - fp48_rand(a); - fp48_conv_cyc(a, a); - bn_zero(e); - fp_prime_get_par(e); - if (bn_is_zero(e)) { - bn_set_2b(e, RLC_FP_BITS - 1); - bn_set_bit(e, RLC_FP_BITS / 2, 1); - bn_set_bit(e, 0, 1); - } - BENCH_ADD(fp48_exp_cyc(c, a, e)); - } - BENCH_END; - - BENCH_RUN("fp48_exp_cyc_sps (param)") { - const int *k; - int l; - k = fp_prime_get_par_sps(&l); - fp48_rand(a); - BENCH_ADD(fp48_exp_cyc_sps(c, a, k, l, RLC_POS)); - } - BENCH_END; - - BENCH_RUN("fp48_exp_dig") { - fp48_rand(a); - bn_rand(e, RLC_POS, RLC_DIG); - BENCH_ADD(fp48_exp_dig(c, a, e->dp[0])); - } - BENCH_END; - - BENCH_RUN("fp48_frb") { - fp48_rand(a); - BENCH_ADD(fp48_frb(c, a, 1)); - } - BENCH_END; - - BENCH_RUN("fp48_pck") { - fp48_rand(a); - fp48_conv_cyc(a, a); - BENCH_ADD(fp48_pck(c, a)); - } - BENCH_END; - - BENCH_RUN("fp48_upk") { - fp48_rand(a); - fp48_conv_cyc(a, a); - fp48_pck(a, a); - BENCH_ADD(fp48_upk(c, a)); - } - BENCH_END; - - fp48_free(a); - fp48_free(b); - fp48_free(c); - fp48_free(d[0]); - fp48_free(d[1]); - bn_free(e); -} - -static void memory54(void) { - fp54_t a[BENCH]; - - BENCH_FEW("fp54_null", fp54_null(a[i]), 1); - - BENCH_FEW("fp54_new", fp54_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - fp54_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - fp54_new(a[i]); - } - BENCH_FEW("fp54_free", fp54_free(a[i]), 1); - - (void)a; -} - -static void util54(void) { - fp54_t a, b; - uint8_t bin[54 * RLC_FP_BYTES]; - - fp54_null(a); - fp54_null(b); - - fp54_new(a); - fp54_new(b); - - BENCH_RUN("fp54_copy") { - fp54_rand(a); - BENCH_ADD(fp54_copy(b, a)); - } - BENCH_END; - - BENCH_RUN("fp54_neg") { - fp54_rand(a); - BENCH_ADD(fp54_neg(b, a)); - } - BENCH_END; - - BENCH_RUN("fp54_zero") { - fp54_rand(a); - BENCH_ADD(fp54_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp54_is_zero") { - fp54_rand(a); - BENCH_ADD((void)fp54_is_zero(a)); - } - BENCH_END; - - BENCH_RUN("fp54_set_dig (1)") { - fp54_rand(a); - BENCH_ADD(fp54_set_dig(a, 1)); - } - BENCH_END; - - BENCH_RUN("fp54_set_dig") { - fp54_rand(a); - BENCH_ADD(fp54_set_dig(a, a[0][0][0][0][0])); - } - BENCH_END; - - BENCH_RUN("fp54_rand") { - BENCH_ADD(fp54_rand(a)); - } - BENCH_END; - - BENCH_RUN("fp54_size_bin (0)") { - fp54_rand(a); - BENCH_ADD(fp54_size_bin(a, 0)); - } - BENCH_END; - - BENCH_RUN("fp54_size_bin (1)") { - fp54_rand(a); - fp54_conv_cyc(a, a); - BENCH_ADD(fp54_size_bin(a, 1)); - } - BENCH_END; - - BENCH_RUN("fp54_write_bin (0)") { - fp54_rand(a); - BENCH_ADD(fp54_write_bin(bin, sizeof(bin), a, 0)); - } - BENCH_END; - - BENCH_RUN("fp54_write_bin (1)") { - fp54_rand(a); - fp54_conv_cyc(a, a); - BENCH_ADD(fp54_write_bin(bin, 32 * RLC_FP_BYTES, a, 1)); - } - BENCH_END; - - BENCH_RUN("fp54_read_bin (0)") { - fp54_rand(a); - fp54_write_bin(bin, sizeof(bin), a, 0); - BENCH_ADD(fp54_read_bin(a, bin, sizeof(bin))); - } - BENCH_END; - - BENCH_RUN("fp54_read_bin (1)") { - fp54_rand(a); - fp54_conv_cyc(a, a); - fp54_write_bin(bin, fp54_size_bin(a, 1), a, 1); - BENCH_ADD(fp54_read_bin(a, bin, 32 * RLC_FP_BYTES)); - } - BENCH_END; - - BENCH_RUN("fp54_cmp") { - fp54_rand(a); - fp54_rand(b); - BENCH_ADD(fp54_cmp(b, a)); - } - BENCH_END; - - BENCH_RUN("fp54_cmp_dig") { - fp54_rand(a); - BENCH_ADD(fp54_cmp_dig(a, (dig_t)0)); - } - BENCH_END; - - fp54_free(a); - fp54_free(b); -} - -static void arith54(void) { - fp54_t a, b, c, d[2]; - bn_t e; - - fp54_new(a); - fp54_new(b); - fp54_new(c); - fp54_new(d[0]); - fp54_new(d[1]); - bn_new(e); - - BENCH_RUN("fp54_add") { - fp54_rand(a); - fp54_rand(b); - BENCH_ADD(fp54_add(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp54_sub") { - fp54_rand(a); - fp54_rand(b); - BENCH_ADD(fp54_sub(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp54_mul") { - fp54_rand(a); - fp54_rand(b); - BENCH_ADD(fp54_mul(c, a, b)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp54_mul_basic") { - fp54_rand(a); - fp54_rand(b); - BENCH_ADD(fp54_mul_basic(c, a, b)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp54_mul_lazyr") { - fp54_rand(a); - fp54_rand(b); - BENCH_ADD(fp54_mul_lazyr(c, a, b)); - } - BENCH_END; -#endif - - BENCH_RUN("fp54_mul_dxs") { - fp54_rand(a); - fp54_rand(b); - BENCH_ADD(fp54_mul_dxs(c, a, b)); - } - BENCH_END; - - BENCH_RUN("fp54_sqr") { - fp54_rand(a); - BENCH_ADD(fp54_sqr(c, a)); - } - BENCH_END; - - BENCH_RUN("fp54_sqr_cyc") { - fp54_rand(a); - BENCH_ADD(fp54_sqr_cyc(c, a)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp54_sqr_cyc_basic") { - fp54_rand(a); - fp54_rand(b); - BENCH_ADD(fp54_sqr_cyc_basic(c, a)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp54_sqr_cyc_lazyr") { - fp54_rand(a); - fp54_rand(b); - BENCH_ADD(fp54_sqr_cyc_lazyr(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp54_sqr_pck") { - fp54_rand(a); - BENCH_ADD(fp54_sqr_pck(c, a)); - } - BENCH_END; - -#if FPX_RDC == BASIC || !defined(STRIP) - BENCH_RUN("fp54_sqr_pck_basic") { - fp54_rand(a); - fp54_rand(b); - BENCH_ADD(fp54_sqr_pck_basic(c, a)); - } - BENCH_END; -#endif - -#if FPX_RDC == LAZYR || !defined(STRIP) - BENCH_RUN("fp54_sqr_pck_lazyr") { - fp54_rand(a); - fp54_rand(b); - BENCH_ADD(fp54_sqr_pck_lazyr(c, a)); - } - BENCH_END; -#endif - - BENCH_RUN("fp54_test_cyc") { - fp54_rand(a); - fp54_conv_cyc(a, a); - BENCH_ADD(fp54_test_cyc(a)); - } - BENCH_END; - - BENCH_RUN("fp54_conv_cyc") { - fp54_rand(a); - BENCH_ADD(fp54_conv_cyc(c, a)); - } - BENCH_END; - - BENCH_RUN("fp54_back_cyc") { - fp54_rand(a); - BENCH_ADD(fp54_back_cyc(c, a)); - } - BENCH_END; - - BENCH_RUN("fp54_back_cyc (2)") { - fp54_rand(d[0]); - fp54_rand(d[1]); - BENCH_ADD(fp54_back_cyc_sim(d, d, 2)); - } - BENCH_END; - - BENCH_RUN("fp54_conv_cyc") { - fp54_rand(a); - BENCH_ADD(fp54_conv_cyc(c, a)); - } - BENCH_END; - - BENCH_RUN("fp54_inv") { - fp54_rand(a); - BENCH_ADD(fp54_inv(c, a)); - } - BENCH_END; - - BENCH_RUN("fp54_inv_cyc") { - fp54_rand(a); - BENCH_ADD(fp54_inv_cyc(c, a)); - } - BENCH_END; - - BENCH_RUN("fp54_exp") { - fp54_rand(a); - bn_rand(e, RLC_POS, RLC_FP_BITS); - BENCH_ADD(fp54_exp(c, a, e)); - } - BENCH_END; - - BENCH_RUN("fp54_exp (cyc)") { - fp54_rand(a); - fp54_conv_cyc(a, a); - bn_rand(e, RLC_POS, RLC_FP_BITS); - BENCH_ADD(fp54_exp(c, a, e)); - } - BENCH_END; - - BENCH_RUN("fp54_exp_cyc (param or sparse)") { - fp54_rand(a); - fp54_conv_cyc(a, a); - bn_zero(e); - fp_prime_get_par(e); - if (bn_is_zero(e)) { - bn_set_2b(e, RLC_FP_BITS - 1); - bn_set_bit(e, RLC_FP_BITS / 2, 1); - bn_set_bit(e, 0, 1); - } - BENCH_ADD(fp54_exp_cyc(c, a, e)); - } - BENCH_END; - - BENCH_RUN("fp54_exp_cyc_sps (param)") { - const int *k; - int l; - k = fp_prime_get_par_sps(&l); - fp54_rand(a); - BENCH_ADD(fp54_exp_cyc_sps(c, a, k, l, RLC_POS)); - } - BENCH_END; - - BENCH_RUN("fp54_exp_dig") { - fp54_rand(a); - bn_rand(e, RLC_POS, RLC_DIG); - BENCH_ADD(fp54_exp_dig(c, a, e->dp[0])); - } - BENCH_END; - - BENCH_RUN("fp54_frb") { - fp54_rand(a); - BENCH_ADD(fp54_frb(c, a, 1)); - } - BENCH_END; - - BENCH_RUN("fp54_pck") { - fp54_rand(a); - fp54_conv_cyc(a, a); - BENCH_ADD(fp54_pck(c, a)); - } - BENCH_END; - - BENCH_RUN("fp54_upk") { - fp54_rand(a); - fp54_conv_cyc(a, a); - fp54_pck(a, a); - BENCH_ADD(fp54_upk(c, a)); - } - BENCH_END; - - fp54_free(a); - fp54_free(b); - fp54_free(c); - fp54_free(d[0]); - fp54_free(d[1]); - bn_free(e); -} - -int main(void) { - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - conf_print(); - - util_banner("Benchmarks for the FPX module:", 0); - - /* Try using a pairing-friendly curve for faster exponentiation method. */ - if (pc_param_set_any() != RLC_OK) { - /* If it does not work, try a tower-friendly field. */ - if (fp_param_set_any_tower() == RLC_ERR) { - RLC_THROW(ERR_NO_FIELD); - core_clean(); - return 0; - } - } - - fp_param_print(); - - if (fp_prime_get_qnr()) { - util_banner("Quadratic extension:", 0); - util_banner("Utilities:", 1); - memory2(); - util2(); - - util_banner("Arithmetic:", 1); - arith2(); - } - - if (fp_prime_get_cnr()) { - util_banner("Cubic extension:", 0); - util_banner("Utilities:", 1); - memory3(); - util3(); - util_banner("Arithmetic:", 1); - arith3(); - } - - if (fp_prime_get_qnr()) { - util_banner("Quartic extension:", 0); - util_banner("Utilities:", 1); - memory4(); - util4(); - util_banner("Arithmetic:", 1); - arith4(); - - util_banner("Sextic extension:", 0); - util_banner("Utilities:", 1); - memory6(); - util6(); - util_banner("Arithmetic:", 1); - arith6(); - - util_banner("Octic extension:", 0); - util_banner("Utilities:", 1); - memory8(); - util8(); - util_banner("Arithmetic:", 1); - arith8(); - } - - if (fp_prime_get_cnr()) { - util_banner("Nonic extension:", 0); - util_banner("Utilities:", 1); - memory9(); - util9(); - util_banner("Arithmetic:", 1); - arith9(); - } - - if (fp_prime_get_qnr()) { - util_banner("Dodecic extension:", 0); - util_banner("Utilities:", 1); - memory12(); - util12(); - util_banner("Arithmetic:", 1); - arith12(); - } - - if (fp_prime_get_cnr()) { - util_banner("Octodecic extension:", 0); - util_banner("Utilities:", 1); - memory18(); - util18(); - - util_banner("Arithmetic:", 1); - arith18(); - } - - if (fp_prime_get_qnr()) { - util_banner("Extension of degree 24:", 0); - util_banner("Utilities:", 1); - memory24(); - util24(); - util_banner("Arithmetic:", 1); - arith24(); - - util_banner("Extension of degree 48:", 0); - util_banner("Utilities:", 1); - memory48(); - util48(); - util_banner("Arithmetic:", 1); - arith48(); - } - - if (fp_prime_get_cnr()) { - util_banner("Extension of degree 54:", 0); - util_banner("Utilities:", 1); - memory54(); - util54(); - util_banner("Arithmetic:", 1); - arith54(); - } - - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/bench/bench_md.c b/src/dashbls/depends/relic/bench/bench_md.c deleted file mode 100644 index 118afc0c4d20..000000000000 --- a/src/dashbls/depends/relic/bench/bench_md.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2021 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for hash functions. - * - * @ingroup md - */ - -#include - -#include "relic.h" -#include "relic_bench.h" - -static void hash(void) { - uint8_t hash[RLC_MD_LEN], buf[256]; - const uint8_t *dst = (const uint8_t *)"RELIC"; - - BENCH_RUN("md_map (256)") { - rand_bytes(buf, sizeof(buf)); - BENCH_ADD(md_map(hash, buf, sizeof(buf))); - } BENCH_END; - - BENCH_RUN("md_xmd (256)") { - rand_bytes(buf, sizeof(buf)); - BENCH_ADD(md_xmd(buf, sizeof(buf), buf, sizeof(buf), dst, 5)); - } BENCH_END; -} - -int main(void) { - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - conf_print(); - util_banner("Benchmarks for the MD module:\n", 0); - hash(); - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/bench/bench_mpc.c b/src/dashbls/depends/relic/bench/bench_mpc.c deleted file mode 100644 index 31cd1035948d..000000000000 --- a/src/dashbls/depends/relic/bench/bench_mpc.c +++ /dev/null @@ -1,311 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2020 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for random number generation. - * - * @ingroup rand - */ - -#include - -#include "relic.h" -#include "relic_bench.h" - -static void mul_triple(void) { - bn_t order, d[2], e[2], x[2], y[2]; - mt_t tri[2]; - - bn_null(order); - mt_null(tri[0]); - mt_null(tri[1]); - - bn_new(order); - mt_new(tri[0]); - mt_new(tri[1]); - for (int j = 0; j < 2; j++) { - bn_null(d[j]); - bn_null(e[j]); - bn_null(x[j]); - bn_null(y[j]); - bn_new(d[j]); - bn_new(e[j]); - bn_new(x[j]); - bn_new(y[j]); - } - - bn_gen_prime(order, RLC_BN_BITS); - - BENCH_RUN("mt_gen") { - BENCH_ADD(mt_gen(tri, order)); - } BENCH_END; - - BENCH_RUN("mt_mul_lcl") { - BENCH_ADD(mt_mul_lcl(d[0], e[0], x[0], y[0], order, tri[0])); - BENCH_ADD(mt_mul_lcl(d[1], e[1], x[1], y[1], order, tri[1])); - } BENCH_DIV(2); - - BENCH_RUN("mt_mul_bct") { - BENCH_ADD(mt_mul_bct(d, e, order);); - } BENCH_END; - - BENCH_RUN("mt_mul_mpc") { - BENCH_ADD(mt_mul_mpc(d[0], d[0], e[0], order, tri[0], 0);); - BENCH_ADD(mt_mul_mpc(d[1], d[1], e[1], order, tri[1], 1);); - } BENCH_DIV(2); - - bn_free(order); - mt_free(tri[0]); - mt_free(tri[1]); - for (int j = 0; j < 2; j++) { - bn_free(d[j]); - bn_free(e[j]); - bn_free(x[j]); - bn_free(y[j]); - } -} - -static void pair_triple(void) { - g1_t d[2], p[2], _p; - g2_t e[2], q[2], _q; - gt_t f[2], r[2], _r; - bn_t k[2], l[2], n; - mt_t tri[2]; - pt_t t[2]; - - g1_null(_p); - g2_null(_q); - gt_null(_r); - bn_null(n); - - g1_new(_p); - g2_new(_q); - gt_new(_r); - bn_new(n); - for (int j = 0; j < 2; j++) { - g1_null(d[j]); - g2_null(e[j]); - bn_null(k[j]); - bn_null(l[j]); - g1_null(p[j]); - g2_null(q[j]); - gt_null(r[j]); - mt_null(tri[j]); - pt_null(t[j]); - g1_new(d[j]); - g2_new(e[j]); - bn_new(k[j]); - bn_new(l[j]); - g1_new(p[j]); - g2_new(q[j]); - gt_new(r[j]); - gt_new(f[j]); - mt_new(tri[j]); - pt_new(t[j]); - } - - g1_get_ord(n); - - mt_gen(tri, n); - BENCH_RUN("g1_mul") { - /* Generate random inputs. */ - g1_rand(p[0]); - bn_rand_mod(k[0], n); - BENCH_ADD(g1_mul(_p, p[0], k[0])); - } BENCH_END; - - /* Secret share inputs. */ - g1_rand(p[1]); - g1_sub(p[0], p[0], p[1]); - g1_norm(p[0], p[0]); - bn_rand_mod(k[1], n); - bn_sub(k[0], k[0], k[1]); - if (bn_sign(k[0]) == RLC_NEG) { - bn_add(k[0], k[0], n); - } - bn_mod(k[0], k[0], n); - tri[0]->b1 = tri[0]->c1 = &p[0]; - tri[1]->b1 = tri[1]->c1 = &p[1]; - - BENCH_RUN("g1_mul_lcl") { - BENCH_ADD(g1_mul_lcl(l[0], d[0], k[0], p[0], tri[0])); - BENCH_ADD(g1_mul_lcl(l[1], d[1], k[1], p[1], tri[1])) - } BENCH_DIV(2); - - BENCH_RUN("g1_mul_bct") { - BENCH_ADD(g1_mul_bct(l, d)); - } BENCH_END; - - BENCH_RUN("g1_mul_mpc") { - BENCH_ADD(g1_mul_mpc(d[0], l[0], d[0], tri[0], 0)); - BENCH_ADD(g1_mul_mpc(d[1], l[1], d[1], tri[1], 1)); - } BENCH_DIV(2); - - mt_gen(tri, n); - BENCH_RUN("g2_mul") { - /* Generate random inputs. */ - g2_rand(q[0]); - bn_rand_mod(k[0], n); - BENCH_ADD(g2_mul(_q, q[0], k[0])); - } BENCH_END; - /* Secret share inputs. */ - g2_rand(q[1]); - g2_sub(q[0], q[0], q[1]); - g2_norm(q[0], q[0]); - bn_rand_mod(k[1], n); - bn_sub(k[0], k[0], k[1]); - if (bn_sign(k[0]) == RLC_NEG) { - bn_add(k[0], k[0], n); - } - bn_mod(k[0], k[0], n); - tri[0]->b2 = tri[0]->c2 = &q[0]; - tri[1]->b2 = tri[1]->c2 = &q[1]; - - BENCH_RUN("g2_mul_lcl") { - BENCH_ADD(g2_mul_lcl(l[0], e[0], k[0], q[0], tri[0])); - BENCH_ADD(g2_mul_lcl(l[1], e[1], k[1], q[1], tri[1])); - } BENCH_DIV(2); - - BENCH_RUN("g2_mul_bct") { - BENCH_ADD(g2_mul_bct(l, e)); - } BENCH_END; - - BENCH_RUN("g2_mul_mpc") { - BENCH_ADD(g2_mul_mpc(e[0], l[0], e[0], tri[0], 0)); - BENCH_ADD(g2_mul_mpc(e[1], l[1], e[1], tri[1], 1)); - } BENCH_DIV(2); - - mt_gen(tri, n); - BENCH_RUN("gt_exp") { - /* Generate random inputs. */ - gt_rand(r[0]); - bn_rand_mod(k[0], n); - BENCH_ADD(gt_exp(_r, r[0], k[0])); - } BENCH_END; - /* Secret share inputs. */ - gt_rand(r[1]); - gt_mul(r[0], r[0], r[1]); - gt_inv(r[1], r[1]); - bn_rand_mod(k[1], n); - bn_sub(k[0], k[0], k[1]); - if (bn_sign(k[0]) == RLC_NEG) { - bn_add(k[0], k[0], n); - } - bn_mod(k[0], k[0], n); - tri[0]->bt = tri[0]->ct = &r[0]; - tri[1]->bt = tri[1]->ct = &r[1]; - - BENCH_RUN("gt_exp_lcl") { - BENCH_ADD(gt_exp_lcl(l[0], f[0], k[0], r[0], tri[0])); - BENCH_ADD(gt_exp_lcl(l[1], f[1], k[1], r[1], tri[1])); - } BENCH_DIV(2); - - BENCH_RUN("gt_exp_bct") { - BENCH_ADD(gt_exp_bct(l, f)); - } BENCH_END; - - BENCH_RUN("gt_exp_mpc") { - BENCH_ADD(gt_exp_mpc(f[0], l[0], f[0], tri[0], 0)); - BENCH_ADD(gt_exp_mpc(f[1], l[1], f[1], tri[1], 1)); - } BENCH_DIV(2); - - /* Generate random inputs and triple. */ - pc_map_tri(t); - BENCH_RUN("pc_map") { - g1_rand(p[0]); - g2_rand(q[0]); - BENCH_ADD(pc_map(r[0], p[0], q[0])); - } BENCH_END; - /* Secret share inputs. */ - g1_rand(p[1]); - g1_sub(p[0], p[0], p[1]); - g1_norm(p[0], p[0]); - g2_rand(q[1]); - g2_sub(q[0], q[0], q[1]); - g2_norm(q[0], q[0]); - - BENCH_RUN("pc_map_lcl") { - BENCH_ADD(pc_map_lcl(d[0], e[0], p[0], q[0], t[0])); - BENCH_ADD(pc_map_lcl(d[1], e[1], p[1], q[1], t[1])); - } BENCH_DIV(2); - - BENCH_RUN("pc_map_bct") { - BENCH_ADD(pc_map_bct(d, e)); - } BENCH_END; - - BENCH_RUN("pc_map_mpc") { - BENCH_ADD(pc_map_mpc(r[0], d[0], e[0], t[0], 0)); - BENCH_ADD(pc_map_mpc(r[1], d[1], e[1], t[1], 1)); - } BENCH_DIV(2); - - g1_free(_p); - g2_free(_q); - gt_free(_r); - bn_free(n); - for (int j = 0; j < 2; j++) { - g1_free(d[j]); - g2_free(e[j]); - bn_free(k[j]); - bn_free(l[j]); - g1_free(p[j]); - g2_free(q[j]); - gt_free(r[j]); - gt_free(f[j]); - pt_free(t[j]); - mt_free(tri[j]); - } -} - -int main(void) { - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - conf_print(); - util_banner("Benchmarks for the MPC module:", 0); - util_banner("Utilities:\n", 0); - -#if defined(WITH_BN) - mul_triple(); -#endif - -#if defined(WITH_PC) - if (pc_param_set_any() != RLC_OK) { - RLC_THROW(ERR_NO_CURVE); - core_clean(); - return 0; - } - - pc_param_print(); - - util_banner("Arithmetic:", 1); - - pair_triple(); -#endif - - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/bench/bench_pc.c b/src/dashbls/depends/relic/bench/bench_pc.c deleted file mode 100755 index ed805a95394d..000000000000 --- a/src/dashbls/depends/relic/bench/bench_pc.c +++ /dev/null @@ -1,802 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2010 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for Pairing-Based Cryptography. - * - * @ingroup bench - */ - -#include - -#include "relic.h" -#include "relic_bench.h" - -static void memory1(void) { - g1_t a[BENCH]; - - BENCH_FEW("g1_null", g1_null(a[i]), 1); - - BENCH_FEW("g1_new", g1_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - g1_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - g1_new(a[i]); - } - BENCH_FEW("g1_free", g1_free(a[i]), 1); - - (void)a; -} - -static void util1(void) { - g1_t p, q; - uint8_t bin[2 * RLC_PC_BYTES + 1]; - int l; - - g1_null(p); - g1_null(q); - - g1_new(p); - g1_new(q); - - BENCH_RUN("g1_is_infty") { - g1_rand(p); - BENCH_ADD(g1_is_infty(p)); - } - BENCH_END; - - BENCH_RUN("g1_set_infty") { - g1_rand(p); - BENCH_ADD(g1_set_infty(p)); - } - BENCH_END; - - BENCH_RUN("g1_copy") { - g1_rand(p); - g1_rand(q); - BENCH_ADD(g1_copy(p, q)); - } - BENCH_END; - - BENCH_RUN("g1_cmp") { - g1_rand(p); - g1_dbl(p, p); - g1_rand(q); - g1_dbl(q, q); - BENCH_ADD(g1_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("g1_cmp (1 norm)") { - g1_rand(p); - g1_dbl(p, p); - g1_rand(q); - BENCH_ADD(g1_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("g1_cmp (2 norm)") { - g1_rand(p); - g1_rand(q); - BENCH_ADD(g1_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("g1_rand") { - BENCH_ADD(g1_rand(p)); - } - BENCH_END; - - BENCH_RUN("g1_is_valid") { - g1_rand(p); - BENCH_ADD(g1_is_valid(p)); - } BENCH_END; - - BENCH_RUN("g1_size_bin (0)") { - g1_rand(p); - BENCH_ADD(g1_size_bin(p, 0)); - } BENCH_END; - - BENCH_RUN("g1_size_bin (1)") { - g1_rand(p); - BENCH_ADD(g1_size_bin(p, 1)); - } BENCH_END; - - BENCH_RUN("g1_write_bin (0)") { - g1_rand(p); - l = g1_size_bin(p, 0); - BENCH_ADD(g1_write_bin(bin, l, p, 0)); - } BENCH_END; - - BENCH_RUN("g1_write_bin (1)") { - g1_rand(p); - l = g1_size_bin(p, 1); - BENCH_ADD(g1_write_bin(bin, l, p, 1)); - } BENCH_END; - - BENCH_RUN("g1_read_bin (0)") { - g1_rand(p); - l = g1_size_bin(p, 0); - g1_write_bin(bin, l, p, 0); - BENCH_ADD(g1_read_bin(p, bin, l)); - } BENCH_END; - - BENCH_RUN("g1_read_bin (1)") { - g1_rand(p); - l = g1_size_bin(p, 1); - g1_write_bin(bin, l, p, 1); - BENCH_ADD(g1_read_bin(p, bin, l)); - } BENCH_END; -} - -static void arith1(void) { - g1_t p, q, r, t[RLC_G1_TABLE]; - bn_t k, l, n; - - g1_null(p); - g1_null(q); - g1_null(r); - for (int i = 0; i < RLC_G1_TABLE; i++) { - g1_null(t[i]); - } - - g1_new(p); - g1_new(q); - g1_new(r); - bn_new(k); - bn_new(n); - bn_new(l); - - pc_get_ord(n); - - BENCH_RUN("g1_add") { - g1_rand(p); - g1_rand(q); - g1_add(p, p, q); - g1_rand(q); - g1_rand(p); - g1_add(q, q, p); - BENCH_ADD(g1_add(r, p, q)); - } - BENCH_END; - - BENCH_RUN("g1_sub") { - g1_rand(p); - g1_rand(q); - g1_add(p, p, q); - g1_rand(q); - g1_rand(p); - g1_add(q, q, p); - BENCH_ADD(g1_sub(r, p, q)); - } - BENCH_END; - - BENCH_RUN("g1_dbl") { - g1_rand(p); - g1_rand(q); - g1_add(p, p, q); - BENCH_ADD(g1_dbl(r, p)); - } - BENCH_END; - - BENCH_RUN("g1_neg") { - g1_rand(p); - g1_rand(q); - g1_add(p, p, q); - BENCH_ADD(g1_neg(r, p)); - } - BENCH_END; - - BENCH_RUN("g1_mul") { - bn_rand(k, RLC_POS, bn_bits(n)); - bn_rand_mod(k, n); - g1_rand(p); - BENCH_ADD(g1_mul(q, p, k)); - } - BENCH_END; - - BENCH_RUN("g1_mul_gen") { - bn_rand(k, RLC_POS, bn_bits(n)); - bn_rand_mod(k, n); - BENCH_ADD(g1_mul_gen(q, k)); - } - BENCH_END; - - for (int i = 0; i < RLC_G1_TABLE; i++) { - g1_new(t[i]); - } - - BENCH_RUN("g1_mul_pre") { - BENCH_ADD(g1_mul_pre(t, p)); - } - BENCH_END; - - BENCH_RUN("g1_mul_fix") { - bn_rand(k, RLC_POS, bn_bits(n)); - bn_rand_mod(k, n); - g1_mul_pre(t, p); - BENCH_ADD(g1_mul_fix(q, (const g1_t *)t, k)); - } - BENCH_END; - - BENCH_RUN("g1_mul_sim") { - bn_rand(k, RLC_POS, bn_bits(n)); - bn_rand_mod(k, n); - bn_rand_mod(l, n); - g1_rand(p); - g1_rand(q); - BENCH_ADD(g1_mul_sim(r, p, k, q, l)); - } - BENCH_END; - - BENCH_RUN("g1_mul_sim_gen") { - bn_rand(k, RLC_POS, bn_bits(n)); - bn_rand_mod(k, n); - bn_rand_mod(l, n); - g1_rand(q); - BENCH_ADD(g1_mul_sim_gen(r, k, q, l)); - } - BENCH_END; - - BENCH_RUN("g1_mul_dig") { - bn_rand(k, RLC_POS, bn_bits(n)); - bn_rand_mod(k, n); - g1_rand(p); - BENCH_ADD(g1_mul_dig(q, p, k->dp[0])); - } - BENCH_END; - - BENCH_RUN("g1_map") { - uint8_t msg[5]; - rand_bytes(msg, 5); - BENCH_ADD(g1_map(p, msg, 5)); - } BENCH_END; - - g1_free(p); - g1_free(q); - bn_free(k); - bn_free(l); - bn_free(n); - for (int i = 0; i < RLC_G1_TABLE; i++) { - g1_free(t[i]); - } -} - -static void memory2(void) { - g2_t a[BENCH]; - - BENCH_FEW("g2_null", g2_null(a[i]), 1); - - BENCH_FEW("g2_new", g2_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - g2_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - g2_new(a[i]); - } - BENCH_FEW("g2_free", g2_free(a[i]), 1); - - (void)a; -} - -static void util2(void) { - g2_t p, q; - uint8_t bin[8 * RLC_PC_BYTES + 1]; - int l; - - g2_null(p); - g2_null(q); - - g2_new(p); - g2_new(q); - - BENCH_RUN("g2_is_infty") { - g2_rand(p); - BENCH_ADD(g2_is_infty(p)); - } - BENCH_END; - - BENCH_RUN("g2_set_infty") { - g2_rand(p); - BENCH_ADD(g2_set_infty(p)); - } - BENCH_END; - - BENCH_RUN("g2_copy") { - g2_rand(p); - g2_rand(q); - BENCH_ADD(g2_copy(p, q)); - } - BENCH_END; - - BENCH_RUN("g2_cmp") { - g2_rand(p); - g2_dbl(p, p); - g2_rand(q); - g2_dbl(q, q); - BENCH_ADD(g2_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("g2_cmp (1 norm)") { - g2_rand(p); - g2_dbl(p, p); - g2_rand(q); - BENCH_ADD(g2_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("g2_cmp (2 norm)") { - g2_rand(p); - g2_rand(q); - BENCH_ADD(g2_cmp(p, q)); - } BENCH_END; - - BENCH_RUN("g2_rand") { - BENCH_ADD(g2_rand(p)); - } - BENCH_END; - - BENCH_RUN("g2_is_valid") { - BENCH_ADD(g2_is_valid(p)); - } - BENCH_END; - - BENCH_RUN("g2_size_bin (0)") { - g2_rand(p); - BENCH_ADD(g2_size_bin(p, 0)); - } BENCH_END; - - BENCH_RUN("g2_size_bin (1)") { - g2_rand(p); - BENCH_ADD(g2_size_bin(p, 1)); - } BENCH_END; - - BENCH_RUN("g2_write_bin (0)") { - g2_rand(p); - l = g2_size_bin(p, 0); - BENCH_ADD(g2_write_bin(bin, l, p, 0)); - } BENCH_END; - - BENCH_RUN("g2_write_bin (1)") { - g2_rand(p); - l = g2_size_bin(p, 1); - BENCH_ADD(g2_write_bin(bin, l, p, 1)); - } BENCH_END; - - BENCH_RUN("g2_read_bin (0)") { - g2_rand(p); - l = g2_size_bin(p, 0); - g2_write_bin(bin, l, p, 0); - BENCH_ADD(g2_read_bin(p, bin, l)); - } BENCH_END; - - BENCH_RUN("g2_read_bin (1)") { - g2_rand(p); - l = g2_size_bin(p, 1); - g2_write_bin(bin, l, p, 1); - BENCH_ADD(g2_read_bin(p, bin, l)); - } BENCH_END; - - g2_free(p) - g2_free(q); -} - -static void arith2(void) { - g2_t p, q, r, t[RLC_G2_TABLE]; - bn_t k, l, n; - - g2_null(p); - g2_null(q); - g2_null(r); - for (int i = 0; i < RLC_G2_TABLE; i++) { - g2_null(t[i]); - } - - g2_new(p); - g2_new(q); - g2_new(r); - bn_new(k); - bn_new(n); - bn_new(l); - - pc_get_ord(n); - - BENCH_RUN("g2_add") { - g2_rand(p); - g2_rand(q); - g2_add(p, p, q); - g2_rand(q); - g2_rand(p); - g2_add(q, q, p); - BENCH_ADD(g2_add(r, p, q)); - } - BENCH_END; - - BENCH_RUN("g2_sub") { - g2_rand(p); - g2_rand(q); - g2_add(p, p, q); - g2_rand(q); - g2_rand(p); - g2_add(q, q, p); - BENCH_ADD(g2_sub(r, p, q)); - } - BENCH_END; - - BENCH_RUN("g2_dbl") { - g2_rand(p); - g2_rand(q); - g2_add(p, p, q); - BENCH_ADD(g2_dbl(r, p)); - } - BENCH_END; - - BENCH_RUN("g2_neg") { - g2_rand(p); - g2_rand(q); - g2_add(p, p, q); - BENCH_ADD(g2_neg(r, p)); - } - BENCH_END; - - BENCH_RUN("g2_mul") { - bn_rand(k, RLC_POS, bn_bits(n)); - bn_rand_mod(k, n); - g2_rand(p); - BENCH_ADD(g2_mul(q, p, k)); - } - BENCH_END; - - BENCH_RUN("g2_mul_gen") { - bn_rand(k, RLC_POS, bn_bits(n)); - bn_rand_mod(k, n); - BENCH_ADD(g2_mul_gen(q, k)); - } - BENCH_END; - - for (int i = 0; i < RLC_G1_TABLE; i++) { - g2_new(t[i]); - } - - BENCH_RUN("g2_mul_pre") { - BENCH_ADD(g2_mul_pre(t, p)); - } - BENCH_END; - - BENCH_RUN("g2_mul_fix") { - bn_rand(k, RLC_POS, bn_bits(n)); - bn_rand_mod(k, n); - g2_mul_pre(t, p); - BENCH_ADD(g2_mul_fix(q, t, k)); - } - BENCH_END; - - BENCH_RUN("g2_mul_sim") { - bn_rand(k, RLC_POS, bn_bits(n)); - bn_rand_mod(k, n); - bn_rand_mod(l, n); - g2_rand(p); - g2_rand(q); - BENCH_ADD(g2_mul_sim(r, p, k, q, l)); - } - BENCH_END; - - BENCH_RUN("g2_mul_sim_gen") { - bn_rand(k, RLC_POS, bn_bits(n)); - bn_rand_mod(k, n); - bn_rand_mod(l, n); - g2_rand(q); - BENCH_ADD(g2_mul_sim_gen(r, k, q, l)); - } - BENCH_END; - - BENCH_RUN("g2_mul_dig") { - bn_rand(k, RLC_POS, bn_bits(n)); - bn_rand_mod(k, n); - g2_rand(p); - BENCH_ADD(g2_mul_dig(q, p, k->dp[0])); - } - BENCH_END; - -#if FP_PRIME != 509 - BENCH_RUN("g2_map") { - uint8_t msg[5]; - rand_bytes(msg, 5); - BENCH_ADD(g2_map(p, msg, 5)); - } BENCH_END; -#endif - - g2_free(p); - g2_free(q); - bn_free(k); - bn_free(l); - bn_free(n); - for (int i = 0; i < RLC_G1_TABLE; i++) { - g2_free(t[i]); - } -} - -static void memory(void) { - gt_t a[BENCH]; - - BENCH_FEW("gt_null", gt_null(a[i]), 1); - - BENCH_FEW("gt_new", gt_new(a[i]), 1); - for (int i = 0; i < BENCH; i++) { - gt_free(a[i]); - } - - for (int i = 0; i < BENCH; i++) { - gt_new(a[i]); - } - BENCH_FEW("gt_free", gt_free(a[i]), 1); - - (void)a; -} - -static void util(void) { - gt_t a, b; - uint8_t bin[12 * RLC_PC_BYTES]; - int l; - - gt_null(a); - gt_null(b); - - gt_new(a); - gt_new(b); - - BENCH_RUN("gt_copy") { - gt_rand(a); - BENCH_ADD(gt_copy(b, a)); - } - BENCH_END; - - BENCH_RUN("gt_zero") { - gt_rand(a); - BENCH_ADD(gt_zero(a)); - } - BENCH_END; - - BENCH_RUN("gt_set_unity") { - gt_rand(a); - BENCH_ADD(gt_set_unity(a)); - } - BENCH_END; - - BENCH_RUN("gt_is_unity") { - gt_rand(a); - BENCH_ADD((void)gt_is_unity(a)); - } - BENCH_END; - - BENCH_RUN("gt_rand") { - BENCH_ADD(gt_rand(a)); - } - BENCH_END; - - BENCH_RUN("gt_cmp") { - gt_rand(a); - gt_rand(b); - BENCH_ADD(gt_cmp(b, a)); - } - BENCH_END; - - BENCH_RUN("gt_size_bin (0)") { - gt_rand(a); - BENCH_ADD(gt_size_bin(a, 0)); - } BENCH_END; - - BENCH_RUN("gt_write_bin (0)") { - gt_rand(a); - l = gt_size_bin(a, 0); - BENCH_ADD(gt_write_bin(bin, l, a, 0)); - } BENCH_END; - - BENCH_RUN("gt_read_bin (0)") { - gt_rand(a); - l = gt_size_bin(a, 0); - gt_write_bin(bin, l, a, 0); - BENCH_ADD(gt_read_bin(a, bin, l)); - } BENCH_END; - - if (ep_param_embed() == 12) { - BENCH_RUN("gt_size_bin (1)") { - gt_rand(a); - BENCH_ADD(gt_size_bin(a, 1)); - } BENCH_END; - - BENCH_RUN("gt_write_bin (1)") { - gt_rand(a); - l = gt_size_bin(a, 1); - BENCH_ADD(gt_write_bin(bin, l, a, 1)); - } BENCH_END; - - BENCH_RUN("gt_read_bin (1)") { - gt_rand(a); - l = gt_size_bin(a, 1); - gt_write_bin(bin, l, a, 1); - BENCH_ADD(gt_read_bin(a, bin, l)); - } BENCH_END; - } - - BENCH_RUN("gt_is_valid") { - gt_rand(a); - BENCH_ADD(gt_is_valid(a)); - } BENCH_END; - - gt_free(a); - gt_free(b); -} - -static void arith(void) { - gt_t a, b, c; - bn_t d, e, f; - - gt_new(a); - gt_new(b); - gt_new(c); - bn_new(d); - bn_new(e); - bn_new(f); - - BENCH_RUN("gt_mul") { - gt_rand(a); - gt_rand(b); - BENCH_ADD(gt_mul(c, a, b)); - } - BENCH_END; - - BENCH_RUN("gt_sqr") { - gt_rand(a); - gt_rand(b); - BENCH_ADD(gt_sqr(c, a)); - } - BENCH_END; - - BENCH_RUN("gt_inv") { - gt_rand(a); - BENCH_ADD(gt_inv(c, a)); - } - BENCH_END; - - BENCH_RUN("gt_exp") { - gt_rand(a); - pc_get_ord(d); - bn_rand_mod(e, d); - BENCH_ADD(gt_exp(c, a, e)); - } - BENCH_END; - - BENCH_RUN("gt_exp_sim") { - gt_rand(a); - gt_rand(b); - gt_get_ord(d); - bn_rand_mod(e, d); - bn_rand_mod(f, d); - BENCH_ADD(gt_exp_sim(c, a, e, b, f)); - } - BENCH_END; - - BENCH_RUN("gt_exp_dig") { - gt_rand(a); - pc_get_ord(d); - bn_rand(e, RLC_POS, bn_bits(d)); - BENCH_ADD(gt_exp_dig(c, a, e->dp[0])); - } - BENCH_END; - - gt_free(a); - gt_free(b); - gt_free(c); - bn_free(d); - bn_free(e); - bn_free(f); -} - -static void pairing(void) { - g1_t p[2]; - g2_t q[2]; - gt_t r; - - g1_new(p[0]); - g2_new(q[0]); - g1_new(p[1]); - g2_new(q[1]); - gt_new(r); - - BENCH_RUN("pc_map") { - g1_rand(p[0]); - g2_rand(q[0]); - BENCH_ADD(pc_map(r, p[0], q[0])); - } - BENCH_END; - - BENCH_RUN("pc_exp") { - gt_rand(r); - BENCH_ADD(pc_exp(r, r)); - } - BENCH_END; - - BENCH_RUN("pc_map_sim (2)") { - g1_rand(p[1]); - g2_rand(q[1]); - BENCH_ADD(pc_map_sim(r, p, q, 2)); - } - BENCH_END; - - g1_free(p[0]); - g2_free(q[0]); - g1_free(p[1]); - g2_free(q[1]); - gt_free(r); -} - -int main(void) { - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - conf_print(); - util_banner("Benchmarks for the PC module:", 0); - - if (pc_param_set_any() != RLC_OK) { - RLC_THROW(ERR_NO_CURVE); - core_clean(); - return 0; - } - - pc_param_print(); - - util_banner("Group G_1:", 0); - util_banner("Utilities:", 1); - memory1(); - util1(); - - util_banner("Arithmetic:", 1); - arith1(); - - util_banner("Group G_2:", 0); - util_banner("Utilities:", 1); - memory2(); - util2(); - - util_banner("Arithmetic:", 1); - arith2(); - - util_banner("Group G_T:", 0); - util_banner("Utilities:", 1); - memory(); - util(); - - util_banner("Arithmetic:", 1); - arith(); - - util_banner("Pairing:", 0); - util_banner("Arithmetic:", 1); - pairing(); - - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/bench/bench_pp.c b/src/dashbls/depends/relic/bench/bench_pp.c deleted file mode 100644 index 01bb27e77abc..000000000000 --- a/src/dashbls/depends/relic/bench/bench_pp.c +++ /dev/null @@ -1,794 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2010 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for pairings defined over prime elliptic curves. - * - * @ingroup bench - */ - -#include - -#include "relic.h" -#include "relic_bench.h" - -static void pairing2(void) { - bn_t k, n, l; - ep_t p[2], q[2]; - fp2_t e; - int j; - - bn_null(k); - bn_null(n); - bn_null(l); - fp2_null(e); - - bn_new(k); - bn_new(n); - bn_new(l); - fp2_new(e); - - for (j = 0; j < 2; j++) { - ep_null(p[j]); - ep_null(q[j]); - ep_new(p[0]); - ep_new(q[0]); - } - - ep_curve_get_ord(n); - - BENCH_RUN("pp_add_k2") { - ep_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_add_k2(e, p[0], p[0], q[0])); - } - BENCH_END; - -#if EP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("pp_add_k2_basic") { - ep_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_add_k2_basic(e, p[0], p[0], q[0])); - } - BENCH_END; -#endif - -#if EP_ADD == PROJC || !defined(STRIP) - - BENCH_RUN("pp_add_k2_projc") { - ep_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_add_k2_projc(e, p[0], p[0], q[0])); - } - BENCH_END; - -#if PP_EXT == BASIC || !defined(STRIP) - BENCH_RUN("pp_add_k2_projc_basic") { - ep_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_add_k2_projc_basic(e, p[0], p[0], q[0])); - } - BENCH_END; -#endif - -#if PP_EXT == LAZYR || !defined(STRIP) - BENCH_RUN("pp_add_k2_projc_lazyr") { - ep_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_add_k2_projc_lazyr(e, p[0], p[0], q[0])); - } - BENCH_END; -#endif - -#endif - - BENCH_RUN("pp_dbl_k2") { - ep_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_dbl_k2(e, p[0], p[0], q[0])); - } - BENCH_END; - -#if EP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("pp_dbl_k2_basic") { - ep_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_dbl_k2_basic(e, p[0], p[0], q[0])); - } - BENCH_END; -#endif - -#if EP_ADD == PROJC || !defined(STRIP) - - BENCH_RUN("pp_dbl_k2_projc") { - ep_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_dbl_k2_projc(e, p[0], p[0], q[0])); - } - BENCH_END; - -#if PP_EXT == BASIC || !defined(STRIP) - BENCH_RUN("pp_dbl_k2_projc_basic") { - ep_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_dbl_k2_projc_basic(e, p[0], p[0], q[0])); - } - BENCH_END; -#endif - -#if PP_EXT == LAZYR || !defined(STRIP) - BENCH_RUN("pp_dbl_k2_projc_lazyr") { - ep_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_dbl_k2_projc_lazyr(e, p[0], p[0], q[0])); - } - BENCH_END; -#endif - -#endif - BENCH_RUN("pp_exp_k2") { - fp2_rand(e); - BENCH_ADD(pp_exp_k2(e, e)); - } - BENCH_END; - - BENCH_RUN("pp_map_k2") { - ep_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_map_k2(e, q[0], p[0])); - } - BENCH_END; - -#if PP_MAP == TATEP || PP_MAP == OATEP || !defined(STRIP) - BENCH_RUN("pp_map_tatep_k2") { - ep_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_map_tatep_k2(e, q[0], p[0])); - } - BENCH_END; - - BENCH_RUN("pp_map_tatep_sim_k12 (2)") { - ep_rand(p[0]); - ep_rand(q[0]); - ep_rand(p[1]); - ep_rand(q[1]); - BENCH_ADD(pp_map_sim_tatep_k2(e, q, p, 2)); - } - BENCH_END; -#endif - -#if PP_MAP == WEILP || !defined(STRIP) - BENCH_RUN("pp_map_weilp_k2") { - ep_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_map_weilp_k2(e, q[0], p[0])); - } - BENCH_END; - - BENCH_RUN("pp_map_weilp_sim_k12 (2)") { - ep_rand(p[0]); - ep_rand(q[0]); - ep_rand(p[1]); - ep_rand(q[1]); - BENCH_ADD(pp_map_sim_weilp_k2(e, q, p, 2)); - } - BENCH_END; -#endif - - bn_free(k); - bn_free(n); - bn_free(l); - fp2_free(e); - for (j = 0; j < 2; j++) { - ep_free(p[j]); - ep_free(q[j]); - } -} - -static void pairing8(void) { - bn_t k, n, l; - ep2_t p[2], r; - ep_t q[2]; - fp8_t e; - int j; - - bn_null(k); - bn_null(n); - bn_null(l); - ep2_null(r); - fp8_null(e); - - bn_new(k); - bn_new(n); - bn_new(l); - ep2_new(r); - fp8_new(e); - - for (j = 0; j < 2; j++) { - ep2_null(p[j]); - ep_null(q[j]); - ep2_new(p[0]); - ep_new(q[0]); - } - - ep2_curve_get_ord(n); - - BENCH_RUN("pp_add_k8") { - ep2_rand(p[0]); - ep2_dbl(r, p[0]); - ep2_norm(r, r); - ep_rand(q[0]); - BENCH_ADD(pp_add_k8(e, r, p[0], q[0])); - } - BENCH_END; - -#if EP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("pp_add_k8_basic") { - ep2_rand(p[0]); - ep2_dbl(r, p[0]); - ep2_norm(r, r); - ep_rand(q[0]); - BENCH_ADD(pp_add_k8_basic(e, r, p[0], q[0])); - } - BENCH_END; -#endif - -#if EP_ADD == PROJC || !defined(STRIP) - BENCH_RUN("pp_add_k8_projc") { - ep2_rand(p[0]); - ep2_dbl(r, p[0]); - ep2_norm(r, r); - ep_rand(q[0]); - BENCH_ADD(pp_add_k8_projc(e, r, p[0], q[0])); - } - BENCH_END; -#endif - - BENCH_RUN("pp_dbl_k8") { - ep2_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_dbl_k8(e, p[0], p[0], q[0])); - } - BENCH_END; - -#if EP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("pp_dbl_k8_basic") { - ep2_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_dbl_k8_basic(e, p[0], p[0], q[0])); - } - BENCH_END; -#endif - -#if EP_ADD == PROJC || !defined(STRIP) - BENCH_RUN("pp_dbl_k8_projc") { - ep2_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_dbl_k8_projc(e, p[0], p[0], q[0])); - } - BENCH_END; - - #if PP_EXT == BASIC || !defined(STRIP) - BENCH_RUN("pp_dbl_k8_projc_basic") { - ep2_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_dbl_k8_projc_basic(e, p[0], p[0], q[0])); - } - BENCH_END; - #endif - - #if PP_EXT == LAZYR || !defined(STRIP) - BENCH_RUN("pp_dbl_k8_projc_lazyr") { - ep2_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_dbl_k8_projc_lazyr(e, p[0], p[0], q[0])); - } - BENCH_END; - #endif -#endif - - BENCH_RUN("pp_exp_k8") { - fp8_rand(e); - BENCH_ADD(pp_exp_k8(e, e)); - } - BENCH_END; - - BENCH_RUN("pp_map_oate_k8") { - ep2_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_map_oatep_k8(e, q[0], p[0])); - } - BENCH_END; - - bn_free(k); - bn_free(n); - bn_free(l); - fp8_free(e); - ep2_free(r); - for (j = 0; j < 2; j++) { - ep2_free(p[j]); - ep_free(q[j]); - } -} - -static void pairing12(void) { - bn_t k, n, l; - ep2_t p[2], r; - ep_t q[2]; - fp12_t e; - int j; - - bn_null(k); - bn_null(n); - bn_null(l); - ep2_null(r); - fp12_null(e); - - bn_new(k); - bn_new(n); - bn_new(l); - ep2_new(r); - fp12_new(e); - - for (j = 0; j < 2; j++) { - ep2_null(p[j]); - ep_null(q[j]); - ep2_new(p[j]); - ep_new(q[j]); - } - - ep2_curve_get_ord(n); - - BENCH_RUN("pp_add_k12") { - ep2_rand(p[0]); - ep2_dbl(r, p[0]); - ep2_norm(r, r); - ep_rand(q[0]); - BENCH_ADD(pp_add_k12(e, r, p[0], q[0])); - } - BENCH_END; - -#if EP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("pp_add_k12_basic") { - ep2_rand(p[0]); - ep2_dbl(r, p[0]); - ep2_norm(r, r); - ep_rand(q[0]); - BENCH_ADD(pp_add_k12_basic(e, r, p[0], q[0])); - } - BENCH_END; -#endif - -#if EP_ADD == PROJC || !defined(STRIP) - - BENCH_RUN("pp_add_k12_projc") { - ep2_rand(p[0]); - ep2_dbl(r, p[0]); - ep2_norm(r, r); - ep_rand(q[0]); - BENCH_ADD(pp_add_k12_projc(e, r, p[0], q[0])); - } - BENCH_END; - -#if PP_EXT == BASIC || !defined(STRIP) - BENCH_RUN("pp_add_k12_projc_basic") { - ep2_rand(p[0]); - ep2_dbl(r, p[0]); - ep2_norm(r, r); - ep_rand(q[0]); - BENCH_ADD(pp_add_k12_projc_basic(e, r, p[0], q[0])); - } - BENCH_END; -#endif - -#if PP_EXT == LAZYR || !defined(STRIP) - BENCH_RUN("pp_add_k12_projc_lazyr") { - ep2_rand(p[0]); - ep2_dbl(r, p[0]); - ep2_norm(r, r); - ep_rand(q[0]); - BENCH_ADD(pp_add_k12_projc_lazyr(e, r, p[0], q[0])); - } - BENCH_END; -#endif - -#endif - - BENCH_RUN("pp_dbl_k12") { - ep2_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_dbl_k12(e, p[0], p[0], q[0])); - } - BENCH_END; - -#if EP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("pp_dbl_k12_basic") { - ep2_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_dbl_k12_basic(e, p[0], p[0], q[0])); - } - BENCH_END; -#endif - -#if EP_ADD == PROJC || !defined(STRIP) - - BENCH_RUN("pp_dbl_k12_projc") { - ep2_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_dbl_k12_projc(e, p[0], p[0], q[0])); - } - BENCH_END; - -#if PP_EXT == BASIC || !defined(STRIP) - BENCH_RUN("pp_dbl_k12_projc_basic") { - ep2_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_dbl_k12_projc_basic(e, p[0], p[0], q[0])); - } - BENCH_END; -#endif - -#if PP_EXT == LAZYR || !defined(STRIP) - BENCH_RUN("pp_dbl_k12_projc_lazyr") { - ep2_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_dbl_k12_projc_lazyr(e, p[0], p[0], q[0])); - } - BENCH_END; -#endif - -#endif - - BENCH_RUN("pp_exp_k12") { - fp12_rand(e); - BENCH_ADD(pp_exp_k12(e, e)); - } - BENCH_END; - - BENCH_RUN("pp_map_k12") { - ep2_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_map_k12(e, q[0], p[0])); - } - BENCH_END; - - BENCH_RUN("pp_map_sim_k12 (2)") { - ep2_rand(p[0]); - ep_rand(q[0]); - ep2_rand(p[1]); - ep_rand(q[1]); - BENCH_ADD(pp_map_sim_k12(e, q, p, 2)); - } - BENCH_END; - -#if PP_MAP == TATEP || !defined(STRIP) - BENCH_RUN("pp_map_tatep_k12") { - ep2_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_map_tatep_k12(e, q[0], p[0])); - } - BENCH_END; - - BENCH_RUN("pp_map_tatep_sim_k12 (2)") { - ep2_rand(p[0]); - ep_rand(q[0]); - ep2_rand(p[1]); - ep_rand(q[1]); - BENCH_ADD(pp_map_sim_tatep_k12(e, q, p, 2)); - } - BENCH_END; -#endif - -#if PP_MAP == WEILP || !defined(STRIP) - BENCH_RUN("pp_map_weilp_k12") { - ep2_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_map_weilp_k12(e, q[0], p[0])); - } - BENCH_END; - - BENCH_RUN("pp_map_weilp_sim_k12 (2)") { - ep2_rand(p[0]); - ep_rand(q[0]); - ep2_rand(p[1]); - ep_rand(q[1]); - BENCH_ADD(pp_map_sim_weilp_k12(e, q, p, 2)); - } - BENCH_END; -#endif - -#if PP_MAP == OATEP || !defined(STRIP) - BENCH_RUN("pp_map_oatep_k12") { - ep2_rand(p[0]); - ep_rand(q[0]); - BENCH_ADD(pp_map_oatep_k12(e, q[0], p[0])); - } - BENCH_END; -#endif - -#if PP_MAP == OATEP || !defined(STRIP) - BENCH_RUN("pp_map_sim_oatep_k12 (2)") { - ep2_rand(p[0]); - ep_rand(q[0]); - ep2_rand(p[1]); - ep_rand(q[1]); - BENCH_ADD(pp_map_sim_oatep_k12(e, q, p, 2)); - } - BENCH_END; -#endif - - bn_free(k); - bn_free(n); - bn_free(l); - fp12_free(e); - ep2_free(r); - for (j = 0; j < 2; j++) { - ep2_free(p[j]); - ep_free(q[j]); - } -} - -static void pairing48(void) { - ep_t p; - fp8_t qx, qy, qz; - fp48_t e; - - ep_null(p); - fp8_null(qx); - fp8_null(qy); - fp8_null(qz); - fp48_null(e); - - ep_new(p); - fp8_new(qx); - fp8_new(qy); - fp8_new(qz); - fp48_new(e); - - BENCH_RUN("pp_add_k48") { - fp8_rand(qx); - fp8_rand(qy); - fp8_rand(qz); - ep_rand(p); - BENCH_ADD(pp_add_k48(e, qx, qy, qz, qy, qx, p)); - } - BENCH_END; - -#if EP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("pp_add_k48_basic") { - fp8_rand(qx); - fp8_rand(qy); - fp8_rand(qz); - ep_rand(p); - BENCH_ADD(pp_add_k48_basic(e, qx, qy, qy, qx, p)); - } - BENCH_END; -#endif - -#if EP_ADD == PROJC || !defined(STRIP) - BENCH_RUN("pp_add_k48_projc") { - fp8_rand(qx); - fp8_rand(qy); - fp8_rand(qz); - ep_rand(p); - BENCH_ADD(pp_add_k48_projc(e, qx, qy, qz, qx, qy, p)); - } - BENCH_END; -#endif - - BENCH_RUN("pp_dbl_k48") { - fp8_rand(qx); - fp8_rand(qy); - fp8_rand(qz); - ep_rand(p); - BENCH_ADD(pp_dbl_k48(e, qx, qy, qz, p)); - } - BENCH_END; - - #if EP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("pp_dbl_k48_basic") { - fp8_rand(qx); - fp8_rand(qy); - ep_rand(p); - BENCH_ADD(pp_dbl_k48_basic(e, qx, qy, p)); - } - BENCH_END; - #endif - - #if EP_ADD == PROJC || !defined(STRIP) - BENCH_RUN("pp_dbl_k48_projc") { - fp8_rand(qx); - fp8_rand(qy); - fp8_rand(qz); - ep_rand(p); - BENCH_ADD(pp_dbl_k48_projc(e, qx, qy, qz, p)); - } - BENCH_END; - #endif - - BENCH_RUN("pp_exp_k48") { - fp48_rand(e); - BENCH_ADD(pp_exp_k48(e, e)); - } - BENCH_END; - - BENCH_RUN("pp_map_k48") { - fp8_rand(qx); - fp8_rand(qy); - fp8_rand(qz); - ep_rand(p); - BENCH_ADD(pp_map_k48(e, p, qx, qy)); - } - BENCH_END; - - ep_free(p); - fp8_free(qx); - fp8_free(qy); - fp8_free(qz); - fp48_free(e); -} - -static void pairing54(void) { - ep_t p; - fp9_t qx, qy, qz; - fp54_t e; - - ep_null(p); - fp9_null(qx); - fp9_null(qy); - fp9_null(qz); - fp54_null(e); - - ep_new(p); - fp9_new(qx); - fp9_new(qy); - fp9_new(qz); - fp54_new(e); - - BENCH_RUN("pp_add_k54") { - fp9_rand(qx); - fp9_rand(qy); - fp9_rand(qz); - ep_rand(p); - BENCH_ADD(pp_add_k54(e, qx, qy, qz, qy, qx, p)); - } - BENCH_END; - -#if EP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("pp_add_k54_basic") { - fp9_rand(qx); - fp9_rand(qy); - fp9_rand(qz); - ep_rand(p); - BENCH_ADD(pp_add_k54_basic(e, qx, qy, qy, qx, p)); - } - BENCH_END; -#endif - -#if EP_ADD == PROJC || !defined(STRIP) - BENCH_RUN("pp_add_k54_projc") { - fp9_rand(qx); - fp9_rand(qy); - fp9_rand(qz); - ep_rand(p); - BENCH_ADD(pp_add_k54_projc(e, qx, qy, qz, qx, qy, p)); - } - BENCH_END; -#endif - - BENCH_RUN("pp_dbl_k54") { - fp9_rand(qx); - fp9_rand(qy); - fp9_rand(qz); - ep_rand(p); - BENCH_ADD(pp_dbl_k54(e, qx, qy, qz, p)); - } - BENCH_END; - - #if EP_ADD == BASIC || !defined(STRIP) - BENCH_RUN("pp_dbl_k54_basic") { - fp9_rand(qx); - fp9_rand(qy); - ep_rand(p); - BENCH_ADD(pp_dbl_k54_basic(e, qx, qy, p)); - } - BENCH_END; - #endif - - #if EP_ADD == PROJC || !defined(STRIP) - BENCH_RUN("pp_dbl_k54_projc") { - fp9_rand(qx); - fp9_rand(qy); - fp9_rand(qz); - ep_rand(p); - BENCH_ADD(pp_dbl_k54_projc(e, qx, qy, qz, p)); - } - BENCH_END; - #endif - - BENCH_RUN("pp_exp_k54") { - fp54_rand(e); - BENCH_ADD(pp_exp_k54(e, e)); - } - BENCH_END; - - BENCH_RUN("pp_map_k54") { - fp9_rand(qx); - fp9_rand(qy); - fp9_rand(qz); - ep_rand(p); - BENCH_ADD(pp_map_k54(e, p, qx, qy)); - } - BENCH_END; - - ep_free(p); - fp9_free(qx); - fp9_free(qy); - fp9_free(qz); - fp54_free(e); -} - -int main(void) { - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - conf_print(); - - util_banner("Benchmarks for the PP module:", 0); - - if (ep_param_set_any_pairf() != RLC_OK) { - RLC_THROW(ERR_NO_CURVE); - core_clean(); - return 0; - } - - ep_param_print(); - util_banner("Arithmetic:", 1); - - if (ep_param_embed() == 2) { - pairing2(); - } - - if (ep_param_embed() == 8) { - pairing8(); - } - - if (ep_param_embed() == 12) { - pairing12(); - } - - if (ep_param_embed() == 48) { - pairing48(); - } - - if (ep_param_embed() == 54) { - pairing54(); - } - - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/bench/bench_rand.c b/src/dashbls/depends/relic/bench/bench_rand.c deleted file mode 100644 index 4fd7625371ca..000000000000 --- a/src/dashbls/depends/relic/bench/bench_rand.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2014 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for random number generation. - * - * @ingroup rand - */ - -#include - -#include "relic.h" -#include "relic_bench.h" - -#if RAND == CALL - -#include -#include -#include - -static void test_bytes(uint8_t *buf, int size, void *args) { - int c, l, fd = *(int *)args; - - if (fd == -1) { - RLC_THROW(ERR_NO_FILE); - } - - l = 0; - do { - c = read(fd, buf + l, size - l); - l += c; - if (c == -1) { - RLC_THROW(ERR_NO_READ); - } - } while (l < size); -} - -static void rng(void) { - uint8_t buffer[64]; - int fd = open("/dev/urandom", O_RDONLY); - - BENCH_RUN("rand_seed") { - rand_bytes(buffer, k); - BENCH_ADD(rand_seed(&test_bytes, (void *)&fd)); - } BENCH_END; - - for (int k = 1; k <= sizeof(buffer); k *= 2) { - BENCH_RUN("rand_bytes (from 1 to 256)") { - BENCH_ADD(rand_bytes(buffer, k)); - } BENCH_END; - } - - close(fd); -} - -#else - -static void rng(void) { - uint8_t buffer[256]; - - BENCH_RUN("rand_seed (20)") { - rand_bytes(buffer, 20); - BENCH_ADD(rand_seed(buffer, 20)); - } BENCH_END; - - for (int k = 1; k <= sizeof(buffer); k *= 2) { - BENCH_RUN("rand_bytes (from 1 to 256)") { - BENCH_ADD(rand_bytes(buffer, k)); - } BENCH_END; - } -} - -#endif - -int main(void) { - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - conf_print(); - util_banner("Benchmarks for the RAND module:", 0); - util_banner("Utilities:\n", 0); - rng(); - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/cmake/arch.cmake b/src/dashbls/depends/relic/cmake/arch.cmake deleted file mode 100644 index 0b9df7e280a9..000000000000 --- a/src/dashbls/depends/relic/cmake/arch.cmake +++ /dev/null @@ -1,52 +0,0 @@ -message(STATUS "Available architectures (default = X64):\n") - -message(" ARCH= No specific architecture (disable some features).") -message(" ARCH=AVR Atmel AVR ATMega128 8-bit architecture.") -message(" ARCH=MSP TI MSP430 16-bit architecture.") -message(" ARCH=ARM ARM 32-bit architecture.") -message(" ARCH=X86 Intel x86-compatible 32-bit architecture.") -message(" ARCH=X64 AMD x86_64-compatible 64-bit architecture.\n") - -message(STATUS "Available word sizes (default = 64):\n") - -message(" WSIZE=8 Build a 8-bit library.") -message(" WSIZE=16 Build a 16-bit library.") -message(" WSIZE=32 Build a 32-bit library.") -message(" WSIZE=64 Build a 64-bit library.\n") - -message(STATUS "Byte boundary to align digit vectors (default = 1):\n") - -message(" ALIGN=1 Do not align digit vectors.") -message(" ALIGN=2 Align digit vectors into 16-bit boundaries.") -message(" ALIGN=8 Align digit vectors into 64-bit boundaries.") -message(" ALIGN=16 Align digit vectors into 128-bit boundaries.\n") - -# Architecture and memory layout. -if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86") - set(ARCH "X86" CACHE STRING "Architecture") -endif() -if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") - set(ARCH "X64" CACHE STRING "Architecture") -endif() - -if(WORD AND NOT WSIZE) - message(FATAL_ERROR "WORD has been replaced with WSIZE. Please update your configuration") -endif() - -if(NOT WSIZE) - if(ARCH STREQUAL X86) - set(AFLAGS "-m32") - set(WSIZE 32) - endif() - if(ARCH STREQUAL X64) - set(AFLAGS "-m64") - set(WSIZE 64) - endif() -endif() - -set(WSIZE ${WSIZE} CACHE STRING "Processor word size") - -if(NOT ALIGN) - set(ALIGN 1) -endif(NOT ALIGN) -set(ALIGN ${ALIGN} CACHE STRING "Boundary to align digit vectors") diff --git a/src/dashbls/depends/relic/cmake/bn.cmake b/src/dashbls/depends/relic/cmake/bn.cmake deleted file mode 100644 index 793027ac447d..000000000000 --- a/src/dashbls/depends/relic/cmake/bn.cmake +++ /dev/null @@ -1,75 +0,0 @@ -message(STATUS "Multiple precision arithmetic configuration (BN module):\n") - -message(" ** Options for the multiple precision module (default = 1024,DOUBLE,0):\n") - -message(" BN_PRECI=n The base precision in bits. Let w be n in words.") -message(" BN_MAGNI=DOUBLE A multiple precision integer can store 2w words.") -message(" BN_MAGNI=CARRY A multiple precision integer can store w+1 words.") -message(" BN_MAGNI=SINGLE A multiple precision integer can store w words.") -message(" BN_KARAT=n The number of Karatsuba steps.\n") - -message(" ** Available multiple precision arithmetic methods (default = COMBA;COMBA;MONTY;SLIDE;BASIC;BASIC):\n") - -message(" Integer multiplication:") -message(" BN_METHD=BASIC Schoolbook multiplication.") -message(" BN_METHD=COMBA Comba multiplication.\n") - -message(" Integer squaring:") -message(" BN_METHD=BASIC Schoolbook squaring.") -message(" BN_METHD=COMBA Comba squaring.") -message(" BN_METHD=MULTP Reuse multiplication for squaring.\n") - -message(" Modular reduction:") -message(" BN_METHD=BASIC Division-based modular reduction.") -message(" BN_METHD=BARRT Barrett modular reduction.") -message(" BN_METHD=MONTY Montgomery modular reduction.") -message(" BN_METHD=RADIX Diminished radix modular reduction.\n") - -message(" Modular exponentiation:") -message(" BN_METHD=BASIC Binary modular exponentiation.") -message(" BN_METHD=MONTY Montgomery powering ladder.") -message(" BN_METHD=SLIDE Sliding window modular exponentiation.\n") - -message(" Greatest Common Divisor:") -message(" BN_METHD=BASIC Euclid's standard GCD algorithm.") -message(" BN_METHD=LEHME Lehmer's fast GCD algorithm.") -message(" BN_METHD=STEIN Stein's binary GCD algorithm.\n") - -message(" Prime generation:") -message(" BN_METHD=BASIC Basic prime generation.") -message(" BN_METHD=SAFEP Safe prime generation.") -message(" BN_METHD=STRON Strong prime generation.\n") - -# Choose the arithmetic precision. -if (NOT BN_PRECI) - set(BN_PRECI 1024) -endif(NOT BN_PRECI) -set(BN_PRECI ${BN_PRECI} CACHE STRING "Arithmetic precision in bits") - -# Fix the number of Karatsuba instances -if (NOT BN_KARAT) - set(BN_KARAT 0) -endif(NOT BN_KARAT) -set(BN_KARAT ${BN_KARAT} CACHE STRING "Number of Karatsuba levels.") - -if (NOT BN_MAGNI) - set(BN_MAGNI "DOUBLE") -endif(NOT BN_MAGNI) -set(BN_MAGNI ${BN_MAGNI} CACHE STRING "Effective size in words") - -# Choose the arithmetic methods. -if (NOT BN_METHD) - set(BN_METHD "COMBA;COMBA;MONTY;SLIDE;BASIC;BASIC") -endif(NOT BN_METHD) -list(LENGTH BN_METHD BN_LEN) -if (BN_LEN LESS 6) - message(FATAL_ERROR "Incomplete BN_METHD specification: ${BN_METHD}") -endif(BN_LEN LESS 6) - -list(GET BN_METHD 0 BN_MUL) -list(GET BN_METHD 1 BN_SQR) -list(GET BN_METHD 2 BN_MOD) -list(GET BN_METHD 3 BN_MXP) -list(GET BN_METHD 4 BN_GCD) -list(GET BN_METHD 5 BN_GEN) -set(BN_METHD ${BN_METHD} CACHE STRING "Method for multiple precision arithmetic.") diff --git a/src/dashbls/depends/relic/cmake/cp.cmake b/src/dashbls/depends/relic/cmake/cp.cmake deleted file mode 100644 index a665f680096d..000000000000 --- a/src/dashbls/depends/relic/cmake/cp.cmake +++ /dev/null @@ -1,16 +0,0 @@ -message(STATUS "Cryptographic protocols configuration (CP module):\n") - -message(" ** Options for the cryptographic protocols module (default = on, PKCS2):\n") - -message(" CP_CRT=[off|on] Support for faster CRT-based exponentiation in factoring-based cryptosystems.\n") - -message(" CP_RSAPD=BASIC RSA with basic padding.") -message(" CP_RSAPD=PKCS1 RSA with PKCS#1 v1.5 padding.") -message(" CP_RSAPD=PKCS2 RSA with PKCS#1 v2.1 padding.\n") - -if (NOT CP_RSAPD) - set(CP_RSAPD "PKCS2") -endif(NOT CP_RSAPD) -set(CP_RSAPD ${CP_RSAPD} CACHE STRING "RSA padding") - -option(CP_CRT "Support for faster CRT-based exponentiation in factoring-based cryptosystems." on) diff --git a/src/dashbls/depends/relic/cmake/doxygen.cmake b/src/dashbls/depends/relic/cmake/doxygen.cmake deleted file mode 100644 index f940bdeadb40..000000000000 --- a/src/dashbls/depends/relic/cmake/doxygen.cmake +++ /dev/null @@ -1,39 +0,0 @@ -# Helper macro to add a "doc" target with CMake build system. -# and configure doxy.config.in to doxy.config -# -# Please note, that the tools, e.g.: -# doxygen, dot, latex, dvips, makeindex, gswin32, etc. -# must be in path. -# -# adapted from work of Jan Woetzel 2004-2006 -# www.mip.informatik.uni-kiel.de/~jw - -find_package(Doxygen) - -if (DOXYGEN_FOUND) - if (OPSYS STREQUAL "MACOSX") - set(GENERATE_DOCSET "YES") - else (OPSYS STREQUAL "MACOSX") - set(GENERATE_DOCSET "NO") - endif (OPSYS STREQUAL "MACOSX") - if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doc/relic.doxygen.in") - message(STATUS "Configured ${CMAKE_CURRENT_SOURCE_DIR}/doc/relic.doxygen.in") - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/relic.doxygen.in - ${CMAKE_CURRENT_BINARY_DIR}/doc/relic.doxygen @ONLY ) - # use config from BUILD tree - set(DOXY_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/doc/relic.doxygen") - else (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doc/relic.doxygen.in") - # use config from SOURCE tree - if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doc/relic.doxygen") - message(STATUS "Using existing ${CMAKE_CURRENT_SOURCE_DIR}/doc/relic.doxygen") - set(DOXY_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/doc/relic.doxygen") - else (exists "${CMAKE_CURRENT_SOURCE_DIR}/doc/relic.doxygen") - # failed completely... - message(SEND_ERROR "Please create ${CMAKE_CURRENT_SOURCE_DIR}/doxy.config.in (or doxy.config as fallback)") - endif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doc/relic.doxygen") - - endif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doc/relic.doxygen.in") - - add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${DOXY_CONFIG}) - -endif(DOXYGEN_FOUND) diff --git a/src/dashbls/depends/relic/cmake/eb.cmake b/src/dashbls/depends/relic/cmake/eb.cmake deleted file mode 100644 index 70c543c1409e..000000000000 --- a/src/dashbls/depends/relic/cmake/eb.cmake +++ /dev/null @@ -1,64 +0,0 @@ -message(STATUS "Binary elliptic curve arithmetic configuration (EB module):\n") - -message(" ** Options for the binary elliptic curve module (default = on, w = 4):\n") - -message(" EB_PLAIN=[off|on] Support for ordinary curves without endomorphisms.") -message(" EB_KBLTZ=[off|on] Support for Koblitz anomalous binary curves.") -message(" EB_MIXED=[off|on] Use mixed coordinates.") -message(" EB_PRECO=[off|on] Build precomputation table for generator.") -message(" EB_DEPTH=w Width w in [2,8] of precomputation table for fixed point methods.") -message(" EB_WIDTH=w Width w in [2,6] of window processing for unknown point methods.\n") - -message(" ** Available binary elliptic curve methods (default = PROJC;LWNAF;COMBS;INTER):\n") - -message(" Point representation:") -message(" EB_METHD=BASIC Affine coordinates.") -message(" EB_METHD=PROJC Projective coordinates (L�pez-Dahab for ordinary curves).\n") - -message(" Variable-base scalar multiplication:") -message(" EB_METHD=BASIC Binary double-and-add method.") -message(" EB_METHD=LODAH Lopez-Dahab constant-time point multiplication.") -message(" EB_METHD=LWNAF Left-to-right window (T)NAF method.") -message(" EB_METHD=RWNAF Right-to-left window (T)NAF method.") -message(" EB_METHD=HALVE Halving method.\n") - -message(" Fixed-base scalar multiplication:") -message(" EB_METHD=BASIC Binary method for fixed point multiplication.") -message(" EB_METHD=COMBS Single-table Comb method for fixed point multiplication.") -message(" EB_METHD=COMBD Double-table Comb method for fixed point multiplication.") -message(" EB_METHD=LWNAF Left-to-right window (T)NAF method.\n") - -message(" Variable-base simultaneous scalar multiplication:") -message(" EB_METHD=BASIC Multiplication-and-addition simultaneous multiplication.") -message(" EB_METHD=TRICK Shamir's trick for simultaneous multiplication.") -message(" EB_METHD=INTER Interleaving of window (T)NAFs.") -message(" EB_METHD=JOINT Joint sparse form.\n") - -if (NOT EB_DEPTH) - set(EB_DEPTH 4) -endif(NOT EB_DEPTH) -if (NOT EB_WIDTH) - set(EB_WIDTH 4) -endif(NOT EB_WIDTH) -set(EB_DEPTH "${EB_DEPTH}" CACHE STRING "Width of precomputation table for fixed point methods.") -set(EB_WIDTH "${EB_WIDTH}" CACHE STRING "Width of window processing for unknown point methods.") - -option(EB_PLAIN "Support for ordinary curves without endomorphisms" on) -option(EB_KBLTZ "Support for Koblitz anomalous binary curves" on) -option(EB_MIXED "Use mixed coordinates" on) -option(EB_PRECO "Build precomputation table for generator" on) - -# Choose the arithmetic methods. -if (NOT EB_METHD) - set(EB_METHD "PROJC;LWNAF;COMBS;INTER") -endif(NOT EB_METHD) -list(LENGTH EB_METHD EB_LEN) -if (EB_LEN LESS 4) - message(FATAL_ERROR "Incomplete EB_METHD specification: ${EB_METHD}") -endif(EB_LEN LESS 4) - -list(GET EB_METHD 0 EB_ADD) -list(GET EB_METHD 1 EB_MUL) -list(GET EB_METHD 2 EB_FIX) -list(GET EB_METHD 3 EB_SIM) -set(EB_METHD ${EB_METHD} CACHE STRING "Method for binary elliptic curve arithmetic.") diff --git a/src/dashbls/depends/relic/cmake/ec.cmake b/src/dashbls/depends/relic/cmake/ec.cmake deleted file mode 100644 index 9e9035478da0..000000000000 --- a/src/dashbls/depends/relic/cmake/ec.cmake +++ /dev/null @@ -1,23 +0,0 @@ -message(STATUS "Elliptic curve cryptography configuration (EC module):\n") - -message(" ** Options for the binary elliptic curve module (default = on):\n") -message(" EC_ENDOM=[off|on] Prefer (prime or binary) curves with endomorphisms.\n") - -message(" ** Available elliptic curve methods (default = PRIME):\n") -message(" EC_METHD=PRIME Use prime curves.") -message(" EC_METHD=CHAR2 Use binary curves.") -message(" EC_METHD=EDDIE Use prime Edwards curves.\n") - -option(EC_ENDOM "Prefer (prime or binary) curves with endomorphisms" off) - -# Choose the arithmetic methods. -if (NOT EC_METHD) - set(EC_METHD "PRIME") -endif(NOT EC_METHD) -list(LENGTH EC_METHD EC_LEN) -if (EC_LEN LESS 1) - message(FATAL_ERROR "Incomplete EC_METHD specification: ${EC_METHD}") -endif(EC_LEN LESS 1) - -list(GET EC_METHD 0 EC_CUR) -set(EC_METHD ${EC_METHD} CACHE STRING "Method for Elliptic Curve Cryptography.") diff --git a/src/dashbls/depends/relic/cmake/ed.cmake b/src/dashbls/depends/relic/cmake/ed.cmake deleted file mode 100644 index fb22da2a844c..000000000000 --- a/src/dashbls/depends/relic/cmake/ed.cmake +++ /dev/null @@ -1,58 +0,0 @@ -message(STATUS "Elliptic Edwards curve over prime fields arithmetic configuration (ED module):\n") - -message(" ** Options for the prime elliptic Edwards curve module (default = all on):") -message(" ED_PRECO=[off|on] Build precomputation table for generator.") -message(" ED_DEPTH=w Width w in [2,6] of precomputation table for fixed point methods.") -message(" ED_WIDTH=w Width w in [2,6] of window processing for unknown point methods.\n") - -message(" ** Available prime elliptic Edwards curve methods (default = PROJC;LWNAF;COMBS;INTER):") -message(" ED_METHD=BASIC Affine coordinates.") -message(" EP_METHD=PROJC Simple projective twisted Edwards coordinates.") -message(" EP_METHD=EXTND Extended projective twisted Edwards coordinates.\n") - -message(" *** variable-base multiplication method ***") -message(" ED_METHD=BASIC Binary method.") -message(" ED_METHD=SLIDE Sliding window method.") -message(" ED_METHD=MONTY Montgomery ladder method.") -message(" ED_METHD=LWNAF Left-to-right window NAF method.") -message(" EP_METHD=LWREG Left-to-right regular recoding method (GLV for curves with endomorphisms).\n") - -message(" *** fixed-base multiplication method ***") -message(" ED_METHD=BASIC Binary method for fixed point multiplication.") -message(" ED_METHD=COMBS Single-table Comb method for fixed point multiplication.") -message(" ED_METHD=COMBD Double-table Comb method for fixed point multiplication.") -message(" ED_METHD=LWNAF Left-to-right window NAF method.\n") - -message(" *** variable-base simultaneous multiplication method ***") -message(" ED_METHD=BASIC Multiplication-and-addition simultaneous multiplication.") -message(" ED_METHD=TRICK Shamir's trick for simultaneous multiplication.") -message(" ED_METHD=INTER Interleaving of window NAFs (GLV for Koblitz curves).") -message(" ED_METHD=JOINT Joint sparse form.\n") - -message(" Note: these methods must be given in order. Ex: ED_METHD=\"EXTND;LWNAF;COMBD;TRICK\"\n") - -if (NOT ED_DEPTH) - set(ED_DEPTH 4) -endif(NOT ED_DEPTH) -if (NOT ED_WIDTH) - set(ED_WIDTH 4) -endif(NOT ED_WIDTH) -set(ED_DEPTH "${ED_DEPTH}" CACHE STRING "Width of precomputation table for fixed point methods.") -set(ED_WIDTH "${ED_WIDTH}" CACHE STRING "Width of window processing for unknown point methods.") - -option(ED_PRECO "Build precomputation table for generator" on) - -# Choose the arithmetic methods. -if (NOT ED_METHD) - set(ED_METHD "PROJC;LWNAF;COMBS;INTER") -endif(NOT ED_METHD) -list(LENGTH ED_METHD ED_LEN) -if (ED_LEN LESS 4) - message(FATAL_ERROR "Incomplete ED_METHD specification: ${ED_METHD}") -endif(ED_LEN LESS 4) - -list(GET ED_METHD 0 ED_ADD) -list(GET ED_METHD 1 ED_MUL) -list(GET ED_METHD 2 ED_FIX) -list(GET ED_METHD 3 ED_SIM) -set(ED_METHD ${ED_METHD} CACHE STRING "Method for prime elliptic Edwards curve arithmetic.") diff --git a/src/dashbls/depends/relic/cmake/ep.cmake b/src/dashbls/depends/relic/cmake/ep.cmake deleted file mode 100644 index ec7670804a4f..000000000000 --- a/src/dashbls/depends/relic/cmake/ep.cmake +++ /dev/null @@ -1,68 +0,0 @@ -message(STATUS "Prime elliptic curve arithmetic configuration (EP module):\n") - -message(" ** Options for the prime elliptic curve module (default = all on):\n") - -message(" EP_PLAIN=[off|on] Support for ordinary curves without endomorphisms.") -message(" EP_SUPER=[off|on] Support for supersingular curves.") -message(" EP_ENDOM=[off|on] Support for ordinary curves with endomorphisms.") -message(" EP_MIXED=[off|on] Use mixed coordinates.") -message(" EP_CTMAP=[off|on] Use contant-time SSWU and isogeny map for hashing.\n") - -message(" EP_PRECO=[off|on] Build precomputation table for generator.") -message(" EP_DEPTH=w Width w in [2,8] of precomputation table for fixed point methods.") -message(" EP_WIDTH=w Width w in [2,6] of window processing for unknown point methods.\n") - -message(" ** Available prime elliptic curve methods (default = PROJC;LWNAF;COMBS;INTER):\n") - -message(" Point representation:") -message(" EP_METHD=BASIC Affine coordinates.") -message(" EP_METHD=PROJC Homogeneous projective coordinates (complete formula).") -message(" EP_METHD=JACOB Jacobian projective coordinates.\n") - -message(" Variable-base scalar multiplication:") -message(" EP_METHD=BASIC Binary method.") -message(" EP_METHD=LWNAF Left-to-right window NAF method (GLV for Koblitz curves).\n") - -message(" Fixed-base scalar multiplication:") -message(" EP_METHD=BASIC Binary method for fixed point multiplication.") -message(" EP_METHD=COMBS Single-table Comb method for fixed point multiplication.") -message(" EP_METHD=COMBD Double-table Comb method for fixed point multiplication.") -message(" EP_METHD=LWNAF Left-to-right window NAF method (GLV for curves with endomorphisms).") -message(" EP_METHD=LWREG Left-to-right regular recoding method (GLV for curves with endomorphisms).\n") - -message(" Variable-base simultaneous scalar multiplication:") -message(" EP_METHD=BASIC Multiplication-and-addition simultaneous multiplication.") -message(" EP_METHD=TRICK Shamir's trick for simultaneous multiplication.") -message(" EP_METHD=INTER Interleaving of window NAFs (GLV for Koblitz curves).") -message(" EP_METHD=JOINT Joint sparse form.\n") - -if (NOT EP_DEPTH) - set(EP_DEPTH 4) -endif(NOT EP_DEPTH) -if (NOT EP_WIDTH) - set(EP_WIDTH 4) -endif(NOT EP_WIDTH) -set(EP_DEPTH "${EP_DEPTH}" CACHE STRING "Width of precomputation table for fixed point methods.") -set(EP_WIDTH "${EP_WIDTH}" CACHE STRING "Width of window processing for unknown point methods.") - -option(EP_PLAIN "Support for ordinary curves without endomorphisms" on) -option(EP_SUPER "Support for supersingular curves" on) -option(EP_MIXED "Use mixed coordinates" on) -option(EP_ENDOM "Support for ordinary curves with endomorphisms" on) -option(EP_PRECO "Build precomputation table for generator" on) -option(EP_CTMAP "Use contant-time SSWU and isogeny map for hashing" on) - -# Choose the arithmetic methods. -if (NOT EP_METHD) - set(EP_METHD "PROJC;LWNAF;COMBS;INTER") -endif(NOT EP_METHD) -list(LENGTH EP_METHD EP_LEN) -if (EP_LEN LESS 4) - message(FATAL_ERROR "Incomplete EP_METHD specification: ${EP_METHD}") -endif(EP_LEN LESS 4) - -list(GET EP_METHD 0 EP_ADD) -list(GET EP_METHD 1 EP_MUL) -list(GET EP_METHD 2 EP_FIX) -list(GET EP_METHD 3 EP_SIM) -set(EP_METHD ${EP_METHD} CACHE STRING "Method for prime elliptic curve arithmetic.") diff --git a/src/dashbls/depends/relic/cmake/err.cmake b/src/dashbls/depends/relic/cmake/err.cmake deleted file mode 100644 index 725be3334776..000000000000 --- a/src/dashbls/depends/relic/cmake/err.cmake +++ /dev/null @@ -1,9 +0,0 @@ -include(CheckFunctionExists) -include(CheckIncludeFiles) - -# Test for headers -check_include_files(execinfo.h HAVE_EXECINFO_H) - -# Test for functions -check_function_exists(backtrace HAVE_BACKTRACE) -check_function_exists(backtrace_symbols HAVE_BACKTRACE_SYMBOLS) diff --git a/src/dashbls/depends/relic/cmake/fb.cmake b/src/dashbls/depends/relic/cmake/fb.cmake deleted file mode 100644 index a29536eadc19..000000000000 --- a/src/dashbls/depends/relic/cmake/fb.cmake +++ /dev/null @@ -1,99 +0,0 @@ -message(STATUS "Binary field arithmetic configuration (FB module):\n") - -message(" ** Options for the binary elliptic curve module (default = 283,0,on,on,on):\n") - -message(" FB_POLYN=n The irreducible polynomial size in bits.") -message(" FB_KARAT=n The number of Karatsuba levels.") -message(" FB_TRINO=[off|on] Prefer trinomials.") -message(" FB_SQRTF=[off|on] Prefer square-root friendly polynomials.") -message(" FB_PRECO=[off|on] Precompute multiplication table for sqrt(z).") -message(" FB_WIDTH=w Width w in [2,6] of window processing for exponentiation methods.\n") - -message(" ** Available binary field arithmetic methods (default = LODAH;QUICK;QUICK;BASIC;QUICK;QUICK;EXGCD;SLIDE;QUICK):\n") - -message(" Field multiplication:") -message(" FB_METHD=BASIC Right-to-left shift-and-add multiplication.") -message(" FB_METHD=INTEG Integrated modular multiplication.") -message(" FB_METHD=LODAH L�pez-Dahab comb multiplication with window of width 4.\n") - -message(" Field squaring:") -message(" FB_METHD=BASIC Bit manipulation squaring.") -message(" FB_METHD=INTEG Integrated modular squaring.") -message(" FB_METHD=QUICK Table-based squaring.\n") - -message(" Modular reduction:") -message(" FB_METHD=BASIC Shift-and-add modular reduction.") -message(" FB_METHD=QUICK Fast reduction modulo a trinomial or pentanomial.\n") - -message(" Field square root:") -message(" FB_METHD=BASIC Square root by repeated squaring.") -message(" FB_METHD=QUICK Fast square root extraction.\n") - -message(" Trace computation:") -message(" FB_METHD=BASIC Trace computation by repeated squaring.") -message(" FB_METHD=QUICK Fast trace computation.\n") - -message(" Quadratic equation solver:") -message(" FB_METHD=BASIC Solve a quadratic equation by half-trace computation.") -message(" FB_METHD=QUICK Fast solving with precomputed half-traces.\n") - -message(" Field inversion:") -message(" FB_METHD=BASIC Inversion by Fermat's Little Theorem.") -message(" FB_METHD=BINAR Binary Inversion algorithm.") -message(" FB_METHD=ALMOS Inversion by the Amost inverse algorithm.") -message(" FB_METHD=EXGCD Inversion by the Extended Euclidean algorithm.") -message(" FB_METHD=ITOHT Inversion by Itoh-Tsuji.") -message(" FB_METHD=CTAIA Constant-time almost inversion algorithm.") -message(" FB_METHD=BRUCH Hardware-friendly inversion by Brunner et al.") -message(" FB_METHD=LOWER Pass inversion to the lower level.\n") - -message(" Field exponentiation:") -message(" FB_METHD=BASIC Binary exponentiation.") -message(" FB_METHD=SLIDE Sliding window exponentiation.") -message(" FB_METHD=MONTY Constant-time Montgomery powering ladder.\n") - -message(" Iterated squaring/square-root:") -message(" FB_METHD=BASIC Iterated squaring/square-root by consecutive squaring/square-root.") -message(" FB_METHD=QUICK Iterated squaring/square-root by table-based method.\n") - -# Choose the polynomial size. -if (NOT FB_POLYN) - set(FB_POLYN 283) -endif(NOT FB_POLYN) -set(FB_POLYN ${FB_POLYN} CACHE STRING "Irreducible polynomial size in bits.") - -# Fix the number of Karatsuba instances -if (NOT FB_KARAT) - set(FB_KARAT 0) -endif(NOT FB_KARAT) -set(FB_KARAT ${FB_KARAT} CACHE STRING "Number of Karatsuba levels.") - -if (NOT FB_WIDTH) - set(FB_WIDTH 4) -endif(NOT FB_WIDTH) -set(FB_WIDTH ${FB_WIDTH} CACHE STRING "Width of window processing for exponentiation methods.") - -option(FB_TRINO "Prefer trinomials." on) -option(FB_SQRTF "Prefer square-root friendly polynomials." off) -option(FB_PRECO "Precompute multiplication table for sqrt(z)." on) - -# Choose the arithmetic methods. -if (NOT FB_METHD) - set(FB_METHD "LODAH;QUICK;QUICK;QUICK;QUICK;QUICK;EXGCD;SLIDE;QUICK") -endif(NOT FB_METHD) -list(LENGTH FB_METHD FB_LEN) -if (FB_LEN LESS 9) - message(FATAL_ERROR "Incomplete FB_METHD specification: ${FB_METHD}") -endif(FB_LEN LESS 9) - -list(GET FB_METHD 0 FB_MUL) -list(GET FB_METHD 1 FB_SQR) -list(GET FB_METHD 2 FB_RDC) -list(GET FB_METHD 3 FB_SRT) -list(GET FB_METHD 4 FB_TRC) -list(GET FB_METHD 5 FB_SLV) -list(GET FB_METHD 6 FB_INV) -list(GET FB_METHD 7 FB_EXP) -list(GET FB_METHD 8 FB_ITR) - -set(FB_METHD ${FB_METHD} CACHE STRING "Method for binary field arithmetic.") diff --git a/src/dashbls/depends/relic/cmake/fiat.cmake b/src/dashbls/depends/relic/cmake/fiat.cmake deleted file mode 100644 index b0f45adcb49a..000000000000 --- a/src/dashbls/depends/relic/cmake/fiat.cmake +++ /dev/null @@ -1,39 +0,0 @@ -set(TEST_FP "${CMAKE_BINARY_DIR}/bin/test_fp") -set(FIAT_TXT "${CMAKE_BINARY_DIR}/test_fp.txt") -set(FIAT_LOW "${CMAKE_SOURCE_DIR}/src/low/fiat/") -set(FIAT_FP "${FIAT_LOW}/fiat_fp.c") -set(MONT "src/ExtractionOCaml/word_by_word_montgomery") - -message(STATUS "Running test_fp to discover prime modulus.") -execute_process(COMMAND ${TEST_FP} OUTPUT_FILE ${FIAT_TXT}) -file(READ ${FIAT_TXT} OUTPUT_CONTENT) -string(REGEX MATCHALL "[(0-9)|(A-F)]+[ \n]" MATCHES ${OUTPUT_CONTENT}) - -set(LONGEST "0") -foreach(MATCH ${MATCHES}) - STRING(STRIP "${MATCH}" MATCH) - STRING(LENGTH "${MATCH}" LEN) - if (${LEN} GREATER_EQUAL ${LONGEST}) - set(LONGEST ${LEN}) - endif() -endforeach() - -math(EXPR WSIZE "4 * ${LONGEST}") - -foreach(MATCH ${MATCHES}) - STRING(STRIP "${MATCH}" MATCH) - STRING(LENGTH "${MATCH}" LEN) - if (${LEN} EQUAL ${LONGEST}) - set(PRIME "${PRIME}${MATCH}") - endif() -endforeach() - -execute_process(COMMAND $ENV{FIAT_CRYPTO}/${MONT} fp 64 "0x${PRIME}" OUTPUT_FILE ${FIAT_FP}) - -file(READ ${FIAT_FP} OUTPUT_CONTENT) -string(REPLACE "void" "static void" OUTPUT_FIXED "${OUTPUT_CONTENT}") -file(WRITE ${FIAT_FP} "${OUTPUT_FIXED}") - -configure_file(${FIAT_LOW}/relic_fp_add_low.tmpl ${FIAT_LOW}/relic_fp_add_low.c COPYONLY) -configure_file(${FIAT_LOW}/relic_fp_mul_low.tmpl ${FIAT_LOW}/relic_fp_mul_low.c COPYONLY) -configure_file(${FIAT_LOW}/relic_fp_sqr_low.tmpl ${FIAT_LOW}/relic_fp_sqr_low.c COPYONLY) diff --git a/src/dashbls/depends/relic/cmake/fp.cmake b/src/dashbls/depends/relic/cmake/fp.cmake deleted file mode 100644 index 781e9363569b..000000000000 --- a/src/dashbls/depends/relic/cmake/fp.cmake +++ /dev/null @@ -1,81 +0,0 @@ -message(STATUS "Prime field arithmetic configuration (FP module):\n") - -message(" ** Arithmetic precision of the prime field module (default = 256,0,off,off):\n") - -message(" FP_PRIME=n The prime modulus size in bits.") -message(" FP_KARAT=n The number of Karatsuba levels.") -message(" FP_PMERS=[off|on] Prefer Pseudo-Mersenne primes over random primes.") -message(" FP_QNRES=[off|on] Use -1 as quadratic non-residue (make sure that p = 3 mod 8).") -message(" FP_WIDTH=w Width w in [2,6] of window processing for exponentiation methods.\n") - -message(" ** Available prime field arithmetic methods (default = BASIC;COMBA;COMBA;MONTY;MONTY;SLIDE):") - -message(" Field addition") -message(" FP_METHD=BASIC Schoolbook addition.") -message(" FP_METHD=INTEG Integrated modular addition.\n") - -message(" Field multiplication") -message(" FP_METHD=BASIC Schoolbook multiplication.") -message(" FP_METHD=INTEG Integrated modular multiplication.") -message(" FP_METHD=COMBA Comba multiplication.\n") - -message(" Field squaring") -message(" FP_METHD=BASIC Schoolbook squaring.") -message(" FP_METHD=INTEG Integrated modular squaring.") -message(" FP_METHD=COMBA Comba squaring.") -message(" FP_METHD=MULTP Reuse multiplication for squaring.\n") - -message(" Modular reduction") -message(" FP_METHD=BASIC Division-based reduction.") -message(" FP_METHD=QUICK Fast reduction modulo special form prime (2^t - c, c > 0).") -message(" FP_METHD=MONTY Montgomery modular reduction.\n") - -message(" Field inversion") -message(" FP_METHD=BASIC Inversion by Fermat's Little Theorem.") -message(" FP_METHD=BINAR Binary Inversion algorithm.") -message(" FP_METHD=MONTY Montgomery inversion.") -message(" FP_METHD=EXGCD Inversion by the Extended Euclidean algorithm.") -message(" FP_METHD=DIVST Constant-time inversion by division steps.") -message(" FP_METHD=LOWER Pass inversion to the lower level.\n") - -message(" Field exponentiation") -message(" FP_METHD=BASIC Binary exponentiation.") -message(" FP_METHD=SLIDE Sliding window exponentiation.") -message(" FP_METHD=MONTY Constant-time Montgomery powering ladder.\n") - -# Choose the prime field size. -if (NOT FP_PRIME) - set(FP_PRIME 256) -endif(NOT FP_PRIME) -set(FP_PRIME ${FP_PRIME} CACHE STRING "Prime modulus size") - -# Fix the number of Karatsuba instances -if (NOT FP_KARAT) - set(FP_KARAT 0) -endif(NOT FP_KARAT) -set(FP_KARAT ${FP_KARAT} CACHE STRING "Number of Karatsuba levels.") - -if (NOT FP_WIDTH) - set(FP_WIDTH 4) -endif(NOT FP_WIDTH) -set(FP_WIDTH ${FP_WIDTH} CACHE STRING "Width of window processing for exponentiation methods.") - -option(FP_PMERS "Prefer special form primes over random primes." off) -option(FP_QNRES "Use -1 as quadratic non-residue." off) - -# Choose the arithmetic methods. -if (NOT FP_METHD) - set(FP_METHD "INTEG;INTEG;INTEG;MONTY;MONTY;SLIDE") -endif(NOT FP_METHD) -list(LENGTH FP_METHD FP_LEN) -if (FP_LEN LESS 6) - message(FATAL_ERROR "Incomplete FP_METHD specification: ${FP_METHD}") -endif(FP_LEN LESS 6) - -list(GET FP_METHD 0 FP_ADD) -list(GET FP_METHD 1 FP_MUL) -list(GET FP_METHD 2 FP_SQR) -list(GET FP_METHD 3 FP_RDC) -list(GET FP_METHD 4 FP_INV) -list(GET FP_METHD 5 FP_EXP) -set(FP_METHD ${FP_METHD} CACHE STRING "Method for prime field arithmetic.") diff --git a/src/dashbls/depends/relic/cmake/fpx.cmake b/src/dashbls/depends/relic/cmake/fpx.cmake deleted file mode 100644 index 07e2ad662c61..000000000000 --- a/src/dashbls/depends/relic/cmake/fpx.cmake +++ /dev/null @@ -1,29 +0,0 @@ -message(STATUS "Prime extension field arithmetic configuration (FPX module):\n") - -message(" ** Available bilinear pairing methods (default = BASIC;BASIC;BASIC):") - -message(" Quadratic extension arithmetic:") -message(" FPX_METHD=BASIC Basic quadratic extension field arithmetic.") -message(" FPX_METHD=INTEG Quadratic extension field arithmetic with embedded modular reduction.\n") - -message(" Cubic extension arithmetic:") -message(" FPX_METHD=BASIC Basic cubic extension field arithmetic.") -message(" FPX_METHD=INTEG Cubic extension field arithmetic with embedded modular reduction.\n") - -message(" Extension field arithmetic:") -message(" FPX_METHD=BASIC Basic extension field arithmetic.") -message(" FPX_METHD=LAZYR Lazy-reduced extension field arithmetic.\n") - -# Choose the arithmetic methods. -if (NOT FPX_METHD) - set(FPX_METHD "INTEG;INTEG;LAZYR") -endif(NOT FPX_METHD) -list(LENGTH FPX_METHD FPX_LEN) -if (FPX_LEN LESS 3) - message(FATAL_ERROR "Incomplete FPX_METHD specification: ${FPX_METHD}") -endif(FPX_LEN LESS 3) - -list(GET FPX_METHD 0 FPX_QDR) -list(GET FPX_METHD 1 FPX_CBC) -list(GET FPX_METHD 2 FPX_RDC) -set(FPX_METHD ${FPX_METHD} CACHE STRING "Method for prime extension field arithmetic.") diff --git a/src/dashbls/depends/relic/cmake/gmp.cmake b/src/dashbls/depends/relic/cmake/gmp.cmake deleted file mode 100644 index abb00c44c2ea..000000000000 --- a/src/dashbls/depends/relic/cmake/gmp.cmake +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright (c) 2006, Laurent Montel, -# Copyright (c) 2007, Francesco Biscani, - -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. The name of the author may not be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ------------------------------------------------------------------------------------------ - -# Try to find the GMP libraries: -# GMP_FOUND - System has GMP lib -# GMP_INCLUDE_DIR - The GMP include directory -# GMP_LIBRARIES - Libraries needed to use GMP - -if (GMP_INCLUDE_DIR AND GMP_LIBRARIES) - # Force search at every time, in case configuration changes - unset(GMP_INCLUDE_DIR CACHE) - unset(GMP_LIBRARIES CACHE) -endif (GMP_INCLUDE_DIR AND GMP_LIBRARIES) - -find_path(GMP_INCLUDE_DIR NAMES gmp.h) -if(STBIN) - find_library(GMP_LIBRARIES NAMES libgmp.a gmp.lib libgmp-10 libgmp gmp) -else(STBIN) - find_library(GMP_LIBRARIES NAMES libgmp.so gmp.lib libgmp-10 libgmp gmp) -endif(STBIN) - -if(GMP_INCLUDE_DIR AND GMP_LIBRARIES) - set(GMP_FOUND TRUE) -endif() - -if(GMP_FOUND) - message(STATUS "Configured GMP: -I${GMP_INCLUDE_DIR} -L${GMP_LIBRARIES}") -else(GMP_FOUND) - message(STATUS "Could NOT find GMP") -endif(GMP_FOUND) - -mark_as_advanced(GMP_INCLUDE_DIR GMP_LIBRARIES) diff --git a/src/dashbls/depends/relic/cmake/ios.cmake b/src/dashbls/depends/relic/cmake/ios.cmake deleted file mode 100644 index 68f13b4db2c3..000000000000 --- a/src/dashbls/depends/relic/cmake/ios.cmake +++ /dev/null @@ -1,443 +0,0 @@ -# https://github.com/leetal/ios-cmake -# -# This file is part of the ios-cmake project. It was retrieved from -# https://github.com/cristeab/ios-cmake.git, which is a fork of -# https://code.google.com/p/ios-cmake/. Which in turn is based off of -# the Platform/Darwin.cmake and Platform/UnixPaths.cmake files which -# are included with CMake 2.8.4 -# -# The ios-cmake project is licensed under the new BSD license. -# -# Copyright (c) 2014, Bogdan Cristea and LTE Engineering Software, -# Kitware, Inc., Insight Software Consortium. All rights reserved. -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -# This file is based off of the Platform/Darwin.cmake and -# Platform/UnixPaths.cmake files which are included with CMake 2.8.4 -# It has been altered for iOS development. -# -# Updated by Alex Stewart (alexs.mac@gmail.com) -# -# ***************************************************************************** -# Now maintained by Alexander Widerberg (widerbergaren [at] gmail.com) -# under the BSD-3-Clause license -# https://github.com/leetal/ios-cmake -# ***************************************************************************** -# -# INFORMATION / HELP -# -# The following variables control the behaviour of this toolchain: -# -# IOS_PLATFORM: OS (default) or SIMULATOR or SIMULATOR64 or TVOS or SIMULATOR_TVOS -# OS = Build for iPhoneOS. -# SIMULATOR = Build for x86 i386 iPhone Simulator. -# SIMULATOR64 = Build for x86_64 iPhone Simulator. -# TVOS = Build for AppleTVOS. -# SIMULATOR_TVOS = Build for x86_64 AppleTV Simulator. -# CMAKE_OSX_SYSROOT: Path to the iOS SDK to use. By default this is -# automatically determined from IOS_PLATFORM and xcodebuild, but -# can also be manually specified (although this should not be required). -# CMAKE_IOS_DEVELOPER_ROOT: Path to the Developer directory for the iOS platform -# being compiled for. By default this is automatically determined from -# CMAKE_OSX_SYSROOT, but can also be manually specified (although this should -# not be required). -# ENABLE_BITCODE: (1|0) Enables or disables bitcode support. Default 1 (true) -# ENABLE_ARC: (1|0) Enables or disables ARC support. Default 1 (true, ARC enabled by default) -# ENABLE_VISIBILITY: (1|0) Enables or disables symbol visibility support. Default 0 (false, visibility hidden by default) -# IOS_ARCH: (armv7 armv7s arm64 i386 x86_64) If specified, will override the default architectures for the given IOS_PLATFORM -# OS = armv7 armv7s arm64 -# SIMULATOR = i386 -# SIMULATOR64 = x86_64 -# TVOS = arm64 -# SIMULATOR_TVOS = x86_64 -# -# This toolchain defines the following variables for use externally: -# -# XCODE_VERSION: Version number (not including Build version) of Xcode detected. -# IOS_SDK_VERSION: Version of iOS SDK being used. -# CMAKE_OSX_ARCHITECTURES: Architectures being compiled for (generated from -# IOS_PLATFORM). -# -# This toolchain defines the following macros for use externally: -# -# set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE XCODE_VARIANT) -# A convenience macro for setting xcode specific properties on targets. -# Available variants are: All, Release, RelWithDebInfo, Debug, MinSizeRel -# example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1" "all"). -# -# find_host_package (PROGRAM ARGS) -# A macro used to find executable programs on the host system, not within the -# iOS environment. Thanks to the android-cmake project for providing the -# command. - -# Fix for PThread library not in path -set(CMAKE_THREAD_LIBS_INIT "-lpthread") -set(CMAKE_HAVE_THREADS_LIBRARY 1) -set(CMAKE_USE_WIN32_THREADS_INIT 0) -set(CMAKE_USE_PTHREADS_INIT 1) - -# Get the Xcode version being used. -execute_process(COMMAND xcodebuild -version - OUTPUT_VARIABLE XCODE_VERSION - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) -string(REGEX MATCH "Xcode [0-9\\.]+" XCODE_VERSION "${XCODE_VERSION}") -string(REGEX REPLACE "Xcode ([0-9\\.]+)" "\\1" XCODE_VERSION "${XCODE_VERSION}") -message(STATUS "Building with Xcode version: ${XCODE_VERSION}") -# Default to building for iPhoneOS if not specified otherwise, and we cannot -# determine the platform from the CMAKE_OSX_ARCHITECTURES variable. The use -# of CMAKE_OSX_ARCHITECTURES is such that try_compile() projects can correctly -# determine the value of IOS_PLATFORM from the root project, as -# CMAKE_OSX_ARCHITECTURES is propagated to them by CMake. -if (NOT DEFINED IOS_PLATFORM) - if (CMAKE_OSX_ARCHITECTURES) - if (CMAKE_OSX_ARCHITECTURES MATCHES ".*arm.*") - set(IOS_PLATFORM "OS") - elseif (CMAKE_OSX_ARCHITECTURES MATCHES "i386") - set(IOS_PLATFORM "SIMULATOR") - elseif (CMAKE_OSX_ARCHITECTURES MATCHES "x86_64") - set(IOS_PLATFORM "SIMULATOR64") - endif() - endif() - if (NOT IOS_PLATFORM) - set(IOS_PLATFORM "OS") - endif() -endif() -set(IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING - "Type of iOS platform for which to build.") -# Determine the platform name and architectures for use in xcodebuild commands -# from the specified IOS_PLATFORM name. -if (IOS_PLATFORM STREQUAL "OS") - set(XCODE_IOS_PLATFORM iphoneos) - if(NOT IOS_ARCH) - set(IOS_ARCH armv7 armv7s arm64) - endif() - elseif (IOS_PLATFORM STREQUAL "OS64") - set(XCODE_IOS_PLATFORM iphoneos) - if(NOT IOS_ARCH) - set(IOS_ARCH arm64) - endif() -elseif (IOS_PLATFORM STREQUAL "SIMULATOR") - set(XCODE_IOS_PLATFORM iphonesimulator) - if(NOT IOS_ARCH) - set(IOS_ARCH i386) - endif() -elseif(IOS_PLATFORM STREQUAL "SIMULATOR64") - set(XCODE_IOS_PLATFORM iphonesimulator) - if(NOT IOS_ARCH) - set(IOS_ARCH x86_64) - endif() -elseif (IOS_PLATFORM STREQUAL "TVOS") - set(XCODE_IOS_PLATFORM appletvos) - if(NOT IOS_ARCH) - set(IOS_ARCH arm64) - endif() -elseif (IOS_PLATFORM STREQUAL "SIMULATOR_TVOS") - set(XCODE_IOS_PLATFORM appletvsimulator) - if(NOT IOS_ARCH) - set(IOS_ARCH x86_64) - endif() -else() - message(FATAL_ERROR "Invalid IOS_PLATFORM: ${IOS_PLATFORM}") -endif() -message(STATUS "Configuring iOS build for platform: ${IOS_PLATFORM}, " - "architecture(s): ${IOS_ARCH}") -# If user did not specify the SDK root to use, then query xcodebuild for it. -if (NOT CMAKE_OSX_SYSROOT) - execute_process(COMMAND xcodebuild -version -sdk ${XCODE_IOS_PLATFORM} Path - OUTPUT_VARIABLE CMAKE_OSX_SYSROOT - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - message(STATUS "Using SDK: ${CMAKE_OSX_SYSROOT} for platform: ${IOS_PLATFORM}") -endif() -if (NOT EXISTS ${CMAKE_OSX_SYSROOT}) - message(SEND_ERROR "Please make sure that Xcode is installed and that the toolchain" - "is pointing to the correct path. Please run:" - "sudo xcode-select -s /Applications/Xcode.app/Contents/Developer" - "and see if that fixes the problem for you.") - message(FATAL_ERROR "Invalid CMAKE_OSX_SYSROOT: ${CMAKE_OSX_SYSROOT} " - "does not exist.") -endif() -# Specify minimum version of deployment target. -if (NOT DEFINED IOS_DEPLOYMENT_TARGET) - # Unless specified, SDK version 8.0 is used by default as minimum target version. - set(IOS_DEPLOYMENT_TARGET "8.0" - CACHE STRING "Minimum iOS version to build for." ) - message(STATUS "Using the default min-version since IOS_DEPLOYMENT_TARGET not provided!") -endif() -# Use bitcode or not -if (NOT DEFINED ENABLE_BITCODE AND NOT IOS_ARCH MATCHES "((^|, )(i386|x86_64))+") - # Unless specified, enable bitcode support by default - set(ENABLE_BITCODE TRUE CACHE BOOL "Whether or not to enable bitcode") - message(STATUS "Enabling bitcode support by default. ENABLE_BITCODE not provided!") -endif() -if (NOT DEFINED ENABLE_BITCODE) - message(STATUS "Disabling bitcode support by default on simulators. ENABLE_BITCODE not provided for override!") -endif() -# Use ARC or not -if (NOT DEFINED ENABLE_ARC) - # Unless specified, enable ARC support by default - set(ENABLE_ARC TRUE CACHE BOOL "Whether or not to enable ARC") - message(STATUS "Enabling ARC support by default. ENABLE_ARC not provided!") -endif() -# Use hidden visibility or not -if (NOT DEFINED ENABLE_VISIBILITY) - # Unless specified, disable symbols visibility by default - set(ENABLE_VISIBILITY FALSE CACHE BOOL "Whether or not to hide symbols (-fvisibility=hidden)") - message(STATUS "Hiding symbols visibility by default. ENABLE_VISIBILITY not provided!") -endif() -# Get the SDK version information. -execute_process(COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT} -version SDKVersion - OUTPUT_VARIABLE IOS_SDK_VERSION - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) -# Find the Developer root for the specific iOS platform being compiled for -# from CMAKE_OSX_SYSROOT. Should be ../../ from SDK specified in -# CMAKE_OSX_SYSROOT. There does not appear to be a direct way to obtain -# this information from xcrun or xcodebuild. -if (NOT CMAKE_IOS_DEVELOPER_ROOT) - get_filename_component(IOS_PLATFORM_SDK_DIR ${CMAKE_OSX_SYSROOT} PATH) - get_filename_component(CMAKE_IOS_DEVELOPER_ROOT ${IOS_PLATFORM_SDK_DIR} PATH) -endif() -if (NOT EXISTS ${CMAKE_IOS_DEVELOPER_ROOT}) - message(FATAL_ERROR "Invalid CMAKE_IOS_DEVELOPER_ROOT: " - "${CMAKE_IOS_DEVELOPER_ROOT} does not exist.") -endif() -# Find the C & C++ compilers for the specified SDK. -if (NOT CMAKE_C_COMPILER) - execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find clang - OUTPUT_VARIABLE CMAKE_C_COMPILER - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - message(STATUS "Using C compiler: ${CMAKE_C_COMPILER}") -endif() -if (NOT CMAKE_CXX_COMPILER) - execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find clang++ - OUTPUT_VARIABLE CMAKE_CXX_COMPILER - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - message(STATUS "Using CXX compiler: ${CMAKE_CXX_COMPILER}") -endif() -# Find (Apple's) libtool. -execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find libtool - OUTPUT_VARIABLE IOS_LIBTOOL - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) -message(STATUS "Using libtool: ${IOS_LIBTOOL}") -# Configure libtool to be used instead of ar + ranlib to build static libraries. -# This is required on Xcode 7+, but should also work on previous versions of -# Xcode. -set(CMAKE_C_CREATE_STATIC_LIBRARY - "${IOS_LIBTOOL} -static -o ") -set(CMAKE_CXX_CREATE_STATIC_LIBRARY - "${IOS_LIBTOOL} -static -o ") -# Get the version of Darwin (OS X) of the host. -execute_process(COMMAND uname -r - OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) -# Standard settings. -set(CMAKE_SYSTEM_NAME Darwin CACHE INTERNAL "") -set(CMAKE_SYSTEM_VERSION ${IOS_SDK_VERSION} CACHE INTERNAL "") -set(UNIX TRUE CACHE BOOL "") -set(APPLE TRUE CACHE BOOL "") -set(IOS TRUE CACHE BOOL "") -set(CMAKE_AR ar CACHE FILEPATH "" FORCE) -set(CMAKE_RANLIB ranlib CACHE FILEPATH "" FORCE) -# Force unset of OS X-specific deployment target (otherwise autopopulated), -# required as of cmake 2.8.10. -set(CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING - "Must be empty for iOS builds." FORCE) -# Set the architectures for which to build. -set(CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE STRING "Build architecture for iOS") -# Change the type of target generated for try_compile() so it'll work when cross-compiling -set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) -# Skip the platform compiler checks for cross compiling. -set(CMAKE_CXX_COMPILER_FORCED TRUE) -set(CMAKE_CXX_COMPILER_WORKS TRUE) -set(CMAKE_C_COMPILER_FORCED TRUE) -set(CMAKE_C_COMPILER_WORKS TRUE) -# All iOS/Darwin specific settings - some may be redundant. -set(CMAKE_SHARED_LIBRARY_PREFIX "lib") -set(CMAKE_SHARED_LIBRARY_SUFFIX ".dylib") -set(CMAKE_SHARED_MODULE_PREFIX "lib") -set(CMAKE_SHARED_MODULE_SUFFIX ".so") -set(CMAKE_C_COMPILER_ABI ELF) -set(CMAKE_CXX_COMPILER_ABI ELF) -set(CMAKE_C_HAS_ISYSROOT 1) -set(CMAKE_CXX_HAS_ISYSROOT 1) -set(CMAKE_MODULE_EXISTS 1) -set(CMAKE_DL_LIBS "") -set(CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ") -set(CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ") -set(CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}") -set(CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}") - -if(IOS_ARCH MATCHES "((^|, )(arm64|x86_64))+") - set(CMAKE_C_SIZEOF_DATA_PTR 8) - set(CMAKE_CXX_SIZEOF_DATA_PTR 8) - message(STATUS "Using a data_ptr size of 8") -else() - set(CMAKE_C_SIZEOF_DATA_PTR 4) - set(CMAKE_CXX_SIZEOF_DATA_PTR 4) - message(STATUS "Using a data_ptr size of 4") -endif() - -message(STATUS "Building for minimum iOS version: ${IOS_DEPLOYMENT_TARGET}" - " (SDK version: ${IOS_SDK_VERSION})") -# Note that only Xcode 7+ supports the newer more specific: -# -m${XCODE_IOS_PLATFORM}-version-min flags, older versions of Xcode use: -# -m(ios/ios-simulator)-version-min instead. -if (IOS_PLATFORM STREQUAL "OS") - if (XCODE_VERSION VERSION_LESS 7.0) - set(XCODE_IOS_PLATFORM_VERSION_FLAGS - "-mios-version-min=${IOS_DEPLOYMENT_TARGET}") - else() - # Xcode 7.0+ uses flags we can build directly from XCODE_IOS_PLATFORM. - set(XCODE_IOS_PLATFORM_VERSION_FLAGS - "-m${XCODE_IOS_PLATFORM}-version-min=${IOS_DEPLOYMENT_TARGET}") - endif() -elseif (IOS_PLATFORM STREQUAL "TVOS") - set(XCODE_IOS_PLATFORM_VERSION_FLAGS - "-mtvos-version-min=${IOS_DEPLOYMENT_TARGET}") -elseif (IOS_PLATFORM STREQUAL "SIMULATOR_TVOS") - set(XCODE_IOS_PLATFORM_VERSION_FLAGS - "-mtvos-simulator-version-min=${IOS_DEPLOYMENT_TARGET}") -else() - # SIMULATOR or SIMULATOR64 both use -mios-simulator-version-min. - set(XCODE_IOS_PLATFORM_VERSION_FLAGS - "-mios-simulator-version-min=${IOS_DEPLOYMENT_TARGET}") -endif() -message(STATUS "Version flags set to: ${XCODE_IOS_PLATFORM_VERSION_FLAGS}") - -if (ENABLE_BITCODE) - set(BITCODE "-fembed-bitcode") - set(HEADER_PAD "") - message(STATUS "Enabling bitcode support.") -else() - set(BITCODE "") - set(HEADER_PAD "-headerpad_max_install_names") - message(STATUS "Disabling bitcode support.") -endif() - -if (ENABLE_ARC) - set(FOBJC_ARC "-fobjc-arc") - message(STATUS "Enabling ARC support.") -else() - set(FOBJC_ARC "-fno-objc-arc") - message(STATUS "Disabling ARC support.") -endif() - -if (NOT ENABLE_VISIBILITY) - set(VISIBILITY "-fvisibility=hidden") - message(STATUS "Hiding symbols (-fvisibility=hidden).") -else() - set(VISIBILITY "") -endif() - -set(CMAKE_C_FLAGS -"${XCODE_IOS_PLATFORM_VERSION_FLAGS} ${BITCODE} -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_C_FLAGS}") -# Hidden visibilty is required for C++ on iOS. -set(CMAKE_CXX_FLAGS -"${XCODE_IOS_PLATFORM_VERSION_FLAGS} ${BITCODE} ${VISIBILITY} -fvisibility-inlines-hidden -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_CXX_FLAGS}") -set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -DNDEBUG -Os -ffast-math ${BITCODE} ${CMAKE_CXX_FLAGS_MINSIZEREL}") -set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -DNDEBUG -O2 -g -ffast-math ${BITCODE} ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DNDEBUG -O3 -ffast-math ${BITCODE} ${CMAKE_CXX_FLAGS_RELEASE}") -set(CMAKE_C_LINK_FLAGS "${XCODE_IOS_PLATFORM_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}") -set(CMAKE_CXX_LINK_FLAGS "${XCODE_IOS_PLATFORM_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}") - -# In order to ensure that the updated compiler flags are used in try_compile() -# tests, we have to forcibly set them in the CMake cache, not merely set them -# in the local scope. -list(APPEND VARS_TO_FORCE_IN_CACHE - CMAKE_C_FLAGS - CMAKE_CXX_FLAGS - CMAKE_CXX_FLAGS_RELWITHDEBINFO - CMAKE_CXX_FLAGS_MINSIZEREL - CMAKE_CXX_FLAGS_RELEASE - CMAKE_C_LINK_FLAGS - CMAKE_CXX_LINK_FLAGS) -foreach(VAR_TO_FORCE ${VARS_TO_FORCE_IN_CACHE}) - set(${VAR_TO_FORCE} "${${VAR_TO_FORCE}}" CACHE STRING "" FORCE) -endforeach() - -set(CMAKE_PLATFORM_HAS_INSTALLNAME 1) -set (CMAKE_SHARED_LINKER_FLAGS "-rpath @executable_path/Frameworks -rpath @loader_path/Frameworks") -set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib ${HEADER_PAD}") -set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle ${HEADER_PAD}") -set(CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,") -set(CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,") -set(CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a") - -# Hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old -# build tree (where install_name_tool was hardcoded) and where -# CMAKE_INSTALL_NAME_TOOL isn't in the cache and still cmake didn't fail in -# CMakeFindBinUtils.cmake (because it isn't rerun) hardcode -# CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did -# before, Alex. -if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL) - find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool) -endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL) - -# Set the find root to the iOS developer roots and to user defined paths. -set(CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_OSX_SYSROOT} - ${CMAKE_PREFIX_PATH} CACHE string "iOS find search path root" FORCE) -# Default to searching for frameworks first. -set(CMAKE_FIND_FRAMEWORK FIRST) -# Set up the default search directories for frameworks. -set(CMAKE_SYSTEM_FRAMEWORK_PATH - ${CMAKE_OSX_SYSROOT}/System/Library/Frameworks - ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks - ${CMAKE_OSX_SYSROOT}/Developer/Library/Frameworks) -# Only search the specified iOS SDK, not the remainder of the host filesystem. -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -# This little macro lets you set any XCode specific property. -macro(set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE XCODE_RELVERSION) - set(XCODE_RELVERSION_I "${XCODE_RELVERSION}") - if (XCODE_RELVERSION_I STREQUAL "All") - set_property(TARGET ${TARGET} PROPERTY - XCODE_ATTRIBUTE_${XCODE_PROPERTY} "${XCODE_VALUE}") - else() - set_property(TARGET ${TARGET} PROPERTY - XCODE_ATTRIBUTE_${XCODE_PROPERTY}[variant=${XCODE_RELVERSION_I}] "${XCODE_VALUE}") - endif() -endmacro(set_xcode_property) -# This macro lets you find executable programs on the host system. -macro(find_host_package) - set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) - set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) - set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) - set(IOS FALSE) - find_package(${ARGN}) - set(IOS TRUE) - set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) - set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) - set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -endmacro(find_host_package) \ No newline at end of file diff --git a/src/dashbls/depends/relic/cmake/md.cmake b/src/dashbls/depends/relic/cmake/md.cmake deleted file mode 100644 index 6eb167008929..000000000000 --- a/src/dashbls/depends/relic/cmake/md.cmake +++ /dev/null @@ -1,21 +0,0 @@ -message(STATUS "Message digest configuration (MD module):\n") - -message(" ** Available hash functions (default = SH256):\n") -message(" MD_METHD=SH224 SHA-224 hash function.") -message(" MD_METHD=SH256 SHA-256 hash function.") -message(" MD_METHD=SH384 SHA-384 hash function.") -message(" MD_METHD=SH512 SHA-512 hash function.") -message(" MD_METHD=B2S160 BLAKE2s-160 hash function.") -message(" MD_METHD=B2S256 BLAKE2s-256 hash function.\n") - -# Choose the arithmetic methods. -if (NOT MD_METHD) - set(MD_METHD "SH256") -endif(NOT MD_METHD) -list(LENGTH MD_METHD MD_LEN) -if (MD_LEN LESS 1) - message(FATAL_ERROR "Incomplete MD_METHD specification: ${MD_METHD}") -endif(MD_LEN LESS 1) - -list(GET MD_METHD 0 MD_MAP) -set(MD_METHD ${MD_METHD} CACHE STRING "Method for hash functions.") diff --git a/src/dashbls/depends/relic/cmake/pp.cmake b/src/dashbls/depends/relic/cmake/pp.cmake deleted file mode 100644 index d1ae4dbc11e5..000000000000 --- a/src/dashbls/depends/relic/cmake/pp.cmake +++ /dev/null @@ -1,25 +0,0 @@ -message(STATUS "Bilinear pairings arithmetic configuration (PP module):\n") - -message(" ** Available bilinear pairing methods (default = BASIC;OATEP):\n") - -message(" Extension field arithmetic:") -message(" PP_METHD=BASIC Basic extension field arithmetic.") -message(" PP_METHD=LAZYR Lazy reduced extension field arithmetic.\n") - -message(" Pairing computation:") -message(" PP_METHD=TATEP Tate pairing.") -message(" PP_METHD=WEILP Weil pairing.") -message(" PP_METHD=OATEP Optimal ate pairing.\n") - -# Choose the arithmetic methods. -if (NOT PP_METHD) - set(PP_METHD "LAZYR;OATEP") -endif(NOT PP_METHD) -list(LENGTH PP_METHD PP_LEN) -if (PP_LEN LESS 1) - message(FATAL_ERROR "Incomplete PP_METHD specification: ${PP_METHD}") -endif(PP_LEN LESS 1) - -list(GET PP_METHD 0 PP_EXT) -list(GET PP_METHD 1 PP_MAP) -set(PP_METHD ${PP_METHD} CACHE STRING "Method for pairing over prime curves.") diff --git a/src/dashbls/depends/relic/cmake/rand.cmake b/src/dashbls/depends/relic/cmake/rand.cmake deleted file mode 100644 index ed90c7691cbf..000000000000 --- a/src/dashbls/depends/relic/cmake/rand.cmake +++ /dev/null @@ -1,29 +0,0 @@ -message(STATUS "Available pseudo-random number generators (default = HASHD):\n") - -message(" RAND=HASHD Use the HASH-DRBG generator. (recommended)") -message(" RAND=RDRND Use Intel RdRand instruction directly.") -message(" RAND=UDEV Use the operating system underlying generator.") -message(" RAND=CALL Override the generator with a callback.\n") - -message(STATUS "Available random number generator seeders (default = UDEV):\n") - -message(" SEED= Use a zero seed. (horribly insecure!)") -message(" SEED=LIBC Use rand()/random() functions. (insecure!)") -message(" SEED=RDRND Use Intel RdRand instruction directly.") -message(" SEED=UDEV Use non-blocking /dev/urandom. (recommended)") -message(" SEED=WCGR Use Windows' CryptGenRandom. (recommended)\n") - -# Choose the pseudo-random number generator. -set(RAND "HASHD" CACHE STRING "Pseudo-random number generator") - -if(MSVC) - - # Choose the pseudo-random number generator. - set(SEED "WCGR" CACHE STRING "Random number generator seeder") - -else() - - # Choose the pseudo-random number generator. - set(SEED "UDEV" CACHE STRING "Random number generator seeder") - -endif() diff --git a/src/dashbls/depends/relic/cmake/relic-config.cmake b/src/dashbls/depends/relic/cmake/relic-config.cmake deleted file mode 100644 index 0b2db20dd78c..000000000000 --- a/src/dashbls/depends/relic/cmake/relic-config.cmake +++ /dev/null @@ -1,10 +0,0 @@ -find_path(RLC_INCLUDE_DIR relic/relic.h) -find_library(RLC_LIBRARY NAMES relic) - -include (FindPackageHandleStandardArgs) -find_package_handle_standard_args(RELIC DEFAULT_MSG RLC_INCLUDE_DIR RLC_LIBRARY) - -if(RLC_FOUND) - set(RLC_LIBRARIES ${RLC_LIBRARY}) - set(RLC_INCLUDE_DIRS ${RLC_INCLUDE_DIR}) -endif() diff --git a/src/dashbls/depends/relic/cmake/with.cmake b/src/dashbls/depends/relic/cmake/with.cmake deleted file mode 100644 index f4edd4522f3e..000000000000 --- a/src/dashbls/depends/relic/cmake/with.cmake +++ /dev/null @@ -1,130 +0,0 @@ -# Default modules. -set(WITH "ALL" CACHE STRING "Selected modules") -LIST(FIND WITH "ALL" TEMP) -if(TEMP GREATER -1) - set(WITH_BN 1) - set(WITH_DV 1) - set(WITH_FP 1) - set(WITH_FPX 1) - set(WITH_FB 1) - set(WITH_FBX 1) - set(WITH_EP 1) - set(WITH_EPX 1) - set(WITH_EB 1) - set(WITH_ED 1) - set(WITH_EC 1) - set(WITH_PP 1) - set(WITH_PC 1) - set(WITH_BC 1) - set(WITH_MD 1) - set(WITH_CP 1) - set(WITH_MPC 1) -endif(TEMP GREATER -1) - -# Check if multiple precision integer arithmetic is required. -list(FIND WITH "BN" TEMP) -if(TEMP GREATER -1) - set(WITH_BN 1) -endif(TEMP GREATER -1) - -# Check if temporary vectors are required. -list(FIND WITH "DV" TEMP) -if(TEMP GREATER -1) - set(WITH_DV 1) -endif(TEMP GREATER -1) - -# Check if prime field arithmetic is required. -list(FIND WITH "FP" TEMP) -if(TEMP GREATER -1) - set(WITH_FP 1) -endif(TEMP GREATER -1) - -# Check if prime extension field arithmetic is required. -list(FIND WITH "FPX" TEMP) -if(TEMP GREATER -1) - set(WITH_FPX 1) -endif(TEMP GREATER -1) - -# Check if binary field arithmetic is required. -list(FIND WITH "FB" TEMP) -if(TEMP GREATER -1) - set(WITH_FB 1) -endif(TEMP GREATER -1) - -# Check if binary extension field arithmetic is required. -list(FIND WITH "FBX" TEMP) -if(TEMP GREATER -1) - set(WITH_FBX 1) -endif(TEMP GREATER -1) - -# Check if prime elliptic curve support is required. -list(FIND WITH "EP" TEMP) -if(TEMP GREATER -1) - set(WITH_EP 1) -endif(TEMP GREATER -1) - -#Check if support for elliptic curves defined over prime field extensions is required. -list(FIND WITH "EPX" TEMP) -if (TEMP GREATER -1) - set(WITH_EPX 1) -endif(TEMP GREATER -1) - -# Check if binary elliptic curve support is required. -list(FIND WITH "EB" TEMP) -if(TEMP GREATER -1) - set(WITH_EB 1) -endif(TEMP GREATER -1) - -# Check if binary elliptic curve support is required. -list(FIND WITH "ED" TEMP) -if(TEMP GREATER -1) - set(WITH_ED 1) -endif(TEMP GREATER -1) - -# Check if elliptic curve cryptography support is required. -list(FIND WITH "EC" TEMP) -if(TEMP GREATER -1) - set(WITH_EC 1) -endif(TEMP GREATER -1) - -# Check if support for pairings over prime curves is required. -list(FIND WITH "PP" TEMP) -if(TEMP GREATER -1) - set(WITH_PP 1) -endif(TEMP GREATER -1) - -# Check if support for pairings over binary curves is required. -list(FIND WITH "PB" TEMP) -if(TEMP GREATER -1) - set(WITH_PB 1) -endif(TEMP GREATER -1) - -# Check if elliptic curve cryptography support is required. -list(FIND WITH "PC" TEMP) -if(TEMP GREATER -1) - set(WITH_PC 1) -endif(TEMP GREATER -1) - -# Check if support for block ciphers is required. -list(FIND WITH "BC" TEMP) -if(TEMP GREATER -1) - set(WITH_BC 1) -endif(TEMP GREATER -1) - -# Check if support for hash functions is required. -list(FIND WITH "MD" TEMP) -if(TEMP GREATER -1) - set(WITH_MD 1) -endif(TEMP GREATER -1) - -# Check if support for cryptographic protocols is required. -list(FIND WITH "CP" TEMP) -if(TEMP GREATER -1) - set(WITH_CP 1) -endif(TEMP GREATER -1) - -# Check if support for cryptographic protocols is required. -list(FIND WITH "MPC" TEMP) -if(TEMP GREATER -1) - set(WITH_MPC 1) -endif(TEMP GREATER -1) diff --git a/src/dashbls/depends/relic/demo/cert-input/Makefile b/src/dashbls/depends/relic/demo/cert-input/Makefile deleted file mode 100644 index 25f24241c159..000000000000 --- a/src/dashbls/depends/relic/demo/cert-input/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -CFLAGS=-O3 -march=native -mtune=native -ggdb -RELIC_ROOT = ../.. - -all: lib - gcc ${CFLAGS} -c test-bench.c -o test-bench.o -I ${RELIC_ROOT}/include -I target/include - gcc ${CFLAGS} -o test-bench test-bench.o target/lib/librelic_s.a -lgmp - -lib: - mkdir -p target - cd target; ${RELIC_ROOT}/../preset/x64-pbc-bls12-381.sh ${RELIC_ROOT}/../; cmake -DEP_METHD='JACOB;LWNAF;COMBS;INTER' .; make - -clean: - rm -rf target *.o test-bench diff --git a/src/dashbls/depends/relic/demo/cert-input/test-bench.c b/src/dashbls/depends/relic/demo/cert-input/test-bench.c deleted file mode 100644 index a90a0381a360..000000000000 --- a/src/dashbls/depends/relic/demo/cert-input/test-bench.c +++ /dev/null @@ -1,471 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2020 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for cryptographic protocols. - * - * @version $Id$ - * @ingroup bench - */ - -#include -#include - -#include "relic.h" -#include "relic_test.h" -#include "relic_bench.h" - -#define MSGS 10000 - -static int test_pss(void) { - int i, code = RLC_ERR; - bn_t ms[MSGS], n, u, v, _v[MSGS]; - g1_t a, b; - g2_t g, x, y, _y[MSGS]; - - bn_null(n); - bn_null(u); - bn_null(v); - g1_null(a); - g1_null(b); - g2_null(g); - g2_null(x); - g2_null(y); - - RLC_TRY { - bn_new(n); - bn_new(u); - bn_new(v); - g1_new(a); - g1_new(b); - g2_new(g); - g2_new(x); - g2_new(y); - - g1_get_ord(n); - - for (i = 0; i < MSGS; i++) { - bn_null(ms[i]); - bn_null(_v[i]); - g2_null(_y[i]); - bn_new(ms[i]); - bn_rand_mod(ms[i], n); - bn_new(_v[i]); - g2_new(_y[i]); - } - - TEST_CASE("pointcheval-sanders simple signature is correct") { - TEST_ASSERT(cp_pss_gen(u, v, g, x, y) == RLC_OK, end); - TEST_ASSERT(cp_pss_sig(a, b, ms[0], u, v) == RLC_OK, end); - TEST_ASSERT(cp_pss_ver(a, b, ms[0], g, x, y) == 1, end); - /* Check adversarial signature. */ - g1_set_infty(a); - g1_set_infty(b); - TEST_ASSERT(cp_pss_ver(a, b, ms[0], g, x, y) == 0, end); - } - TEST_END; - - TEST_CASE("pointcheval-sanders block signature is correct") { - TEST_ASSERT(cp_psb_gen(u, _v, g, x, _y, MSGS) == RLC_OK, end); - TEST_ASSERT(cp_psb_sig(a, b, ms, u, _v, MSGS) == RLC_OK, end); - TEST_ASSERT(cp_psb_ver(a, b, ms, g, x, _y, MSGS) == 1, end); - } - TEST_END; - } - RLC_CATCH_ANY { - RLC_ERROR(end); - } - code = RLC_OK; - - end: - bn_free(n); - bn_free(u); - bn_free(v); - g1_free(a); - g1_free(b); - g2_free(g); - g2_free(x); - g2_free(y); - for (i = 0; i < MSGS; i++) { - bn_free(ms[i]); - bn_free(_v[i]); - g2_free(_y[i]); - } - return code; -} - -static int test_mpss(void) { - int i, j, code = RLC_ERR; - bn_t m[2], n, u[2], v[2], ms[MSGS][2], _v[MSGS][2]; - g1_t g, s[2]; - g2_t h, x[2], y[2], _y[MSGS][2]; - gt_t e; - mt_t tri[3][2]; - pt_t t[2]; - - bn_null(n); - g1_null(g); - g2_null(h); - gt_null(e); - - RLC_TRY { - bn_new(n); - g1_new(g); - g2_new(h); - gt_new(e); - g1_get_ord(n); - for (i = 0; i < 2; i++) { - bn_null(m[i]); - bn_null(u[i]); - bn_null(v[i]); - g1_null(s[i]); - g2_null(x[i]); - g2_null(y[i]); - mt_null(tri[0][i]); - mt_null(tri[1][i]); - mt_null(tri[2][i]); - pt_null(t[i]); - bn_new(m[i]); - bn_rand_mod(m[i], n); - bn_new(u[i]); - bn_new(v[i]); - g1_new(s[i]); - g2_new(x[i]); - g2_new(y[i]); - mt_new(tri[0][i]); - mt_new(tri[1][i]); - mt_new(tri[2][i]); - pt_new(t[i]); - for (j = 0; j < MSGS; j++) { - bn_null(ms[j][i]); - bn_null(_v[j][i]); - g2_null(_y[j][i]); - bn_new(ms[j][i]); - bn_rand_mod(ms[j][i], n); - bn_new(_v[j][i]); - g2_new(_y[j][i]); - } - } - - TEST_CASE("multi-party pointcheval-sanders simple signature is correct") { - pc_map_tri(t); - mt_gen(tri[0], n); - mt_gen(tri[1], n); - mt_gen(tri[2], n); - TEST_ASSERT(cp_mpss_gen(u, v, h, x, y) == RLC_OK, end); - TEST_ASSERT(cp_mpss_bct(x, y) == RLC_OK, end); - /* Compute signature in MPC. */ - TEST_ASSERT(cp_mpss_sig(g, s, m, u, v, tri[0], tri[1]) == RLC_OK, end); - /* Verify signature in MPC. */ - cp_mpss_ver(e, g, s, m, h, x[0], y[0], tri[2], t); - TEST_ASSERT(gt_is_unity(e) == 1, end); - /* Check that signature is also valid for conventional scheme. */ - bn_add(m[0], m[0], m[1]); - bn_mod(m[0], m[0], n); - g1_add(s[0], s[0], s[1]); - g1_norm(s[0], s[0]); - TEST_ASSERT(cp_pss_ver(g, s[0], m[0], h, x[0], y[0]) == 1, end); - } - TEST_END; - - TEST_CASE("multi-party pointcheval-sanders block signature is correct") { - g1_get_ord(n); - pc_map_tri(t); - mt_gen(tri[0], n); - mt_gen(tri[1], n); - mt_gen(tri[2], n); - TEST_ASSERT(cp_mpsb_gen(u, _v, h, x, _y, MSGS) == RLC_OK, end); - TEST_ASSERT(cp_mpsb_bct(x, _y, MSGS) == RLC_OK, end); - /* Compute signature in MPC. */ - TEST_ASSERT(cp_mpsb_sig(g, s, ms, u, _v, tri[0], tri[1], MSGS) == RLC_OK, end); - /* Verify signature in MPC. */ - cp_mpsb_ver(e, g, s, ms, h, x[0], _y, NULL, tri[2], t, MSGS); - TEST_ASSERT(gt_is_unity(e) == 1, end); - cp_mpsb_ver(e, g, s, ms, h, x[0], _y, _v, tri[2], t, MSGS); - TEST_ASSERT(gt_is_unity(e) == 1, end); - bn_sub_dig(ms[0][0], ms[0][0], 1); - cp_mpsb_ver(e, g, s, ms, h, x[0], _y, _v, tri[2], t, MSGS); - TEST_ASSERT(gt_is_unity(e) == 0, end); - } - TEST_END; - } - RLC_CATCH_ANY { - RLC_ERROR(end); - } - code = RLC_OK; - - end: - bn_free(n); - g1_free(g); - g2_free(h); - gt_free(e); - for (i = 0; i < 2; i++) { - bn_free(m[i]); - bn_free(u[i]); - bn_free(v[i]); - g1_free(s[i]); - g2_free(x[i]); - g2_free(y[i]); - mt_free(tri[0][i]); - mt_free(tri[1][i]); - mt_free(tri[2][i]); - pt_free(t[i]); - for (j = 0; j < MSGS; j++) { - bn_free(ms[j][i]); - bn_free(_v[j][i]); - g2_free(_y[j][i]); - } - } - return code; -} - -static void bench_pss(void) { - bn_t ms[MSGS], n, u, v, _v[MSGS]; - g1_t a, b; - g2_t g, x, y, _y[MSGS]; - - bn_null(n); - bn_null(u); - bn_null(v); - g1_null(a); - g1_null(b); - g2_null(g); - g2_null(x); - g2_null(y); - bn_new(n); - bn_new(u); - bn_new(v); - g1_new(a); - g1_new(b); - g2_new(g); - g2_new(x); - g2_new(y); - - g1_get_ord(n); - for (int i = 0; i < MSGS; i++) { - bn_null(ms[i]); - bn_null(_v[i]); - g2_null(_y[i]); - bn_new(ms[i]); - bn_rand_mod(ms[i], n); - bn_new(_v[i]); - g2_new(_y[i]); - } - - BENCH_RUN("cp_pss_gen") { - BENCH_ADD(cp_pss_gen(u, v, g, x, y)); - } BENCH_END; - - BENCH_RUN("cp_pss_sig") { - BENCH_ADD(cp_pss_sig(a, b, ms[0], u, v)); - } BENCH_END; - - BENCH_RUN("cp_pss_ver") { - BENCH_ADD(cp_pss_ver(a, b, ms[0], g, x, y)); - } BENCH_END; - - BENCH_RUN("cp_psb_gen") { - BENCH_ADD(cp_psb_gen(u, _v, g, x, _y, MSGS)); - } BENCH_END; - - BENCH_RUN("cp_psb_sig") { - BENCH_ADD(cp_psb_sig(a, b, ms, u, _v, MSGS)); - } BENCH_END; - - BENCH_RUN("cp_psb_ver") { - BENCH_ADD(cp_psb_ver(a, b, ms, g, x, _y, MSGS)); - } BENCH_END; - - bn_free(u); - bn_free(v); - g1_free(a); - g1_free(b); - g2_free(g); - g2_free(x); - g2_free(y); - for (int i = 0; i < MSGS; i++) { - bn_free(ms[i]); - bn_free(_v[i]); - g1_free(_y[i]); - } -} - -static void bench_mpss(void) { - bn_t m[2], n, u[2], v[2], ms[MSGS][2], _v[MSGS][2]; - g1_t g, s[2]; - g2_t h, x[2], y[2], _y[MSGS][2]; - gt_t r; - mt_t tri[3][2]; - pt_t t[2]; - - bn_null(n); - g1_null(g); - g2_null(h); - gt_null(r); - - bn_new(n); - g1_new(g); - g2_new(h); - gt_new(r); - for (int i = 0; i < 2; i++) { - bn_null(m[i]); - bn_null(u[i]); - bn_null(v[i]); - g1_null(s[i]); - g2_null(x[i]); - g2_null(y[i]); - mt_null(tri[0][i]); - mt_null(tri[1][i]); - mt_null(tri[2][i]); - pt_null(t[i]); - bn_new(m[i]); - bn_new(u[i]); - bn_new(v[i]); - g1_new(s[i]); - g2_new(x[i]); - g2_new(y[i]); - mt_new(tri[0][i]); - mt_new(tri[1][i]); - mt_new(tri[2][i]); - pt_new(t[i]); - - g1_get_ord(n); - for (int j = 0; j < MSGS; j++) { - bn_null(ms[j][i]); - bn_null(_v[j][i]); - g2_null(_y[j][i]); - bn_new(ms[j][i]); - bn_rand_mod(ms[j][i], n); - bn_new(_v[j][i]); - g2_new(_y[j][i]); - } - } - - pc_map_tri(t); - mt_gen(tri[0], n); - mt_gen(tri[1], n); - mt_gen(tri[2], n); - - bn_rand_mod(m[0], n); - bn_rand_mod(m[1], n); - bn_sub(m[0], m[1], m[0]); - if (bn_sign(m[0]) == RLC_NEG) { - bn_add(m[0], m[0], n); - } - - BENCH_RUN("cp_mpss_gen") { - BENCH_ADD(cp_mpss_gen(u, v, h, x, y)); - } BENCH_END; - - BENCH_RUN("cp_mpss_bct") { - BENCH_ADD(cp_mpss_bct(x, y)); - } BENCH_END; - - BENCH_RUN("cp_mpss_sig") { - BENCH_ADD(cp_mpss_sig(g, s, m, u, v, tri[0], tri[1])); - } BENCH_DIV(2); - - BENCH_RUN("cp_mpss_ver") { - BENCH_ADD(cp_mpss_ver(r, g, s, m, h, x[0], y[0], tri[2], t)); - } BENCH_DIV(2); - - g1_get_ord(n); - pc_map_tri(t); - mt_gen(tri[0], n); - mt_gen(tri[1], n); - mt_gen(tri[2], n); - - BENCH_RUN("cp_mpsb_gen") { - BENCH_ADD(cp_mpsb_gen(u, _v, h, x, _y, MSGS)); - } BENCH_END; - - BENCH_RUN("cp_mpsb_bct") { - BENCH_ADD(cp_mpsb_bct(x, _y, MSGS)); - } BENCH_END; - - BENCH_RUN("cp_mpsb_sig") { - BENCH_ADD(cp_mpsb_sig(g, s, ms, u, _v, tri[0], tri[1], MSGS)); - } BENCH_DIV(2); - - BENCH_RUN("cp_mpsb_ver") { - BENCH_ADD(cp_mpsb_ver(r, g, s, ms, h, x[0], _y, NULL, tri[2], t, MSGS)); - } BENCH_DIV(2); - - BENCH_RUN("cp_mpsb_ver (sk)") { - BENCH_ADD(cp_mpsb_ver(r, g, s, ms, h, x[0], _y, _v, tri[2], t, MSGS)); - } BENCH_DIV(2); - - bn_free(n); - g1_free(g); - g2_free(h); - gt_free(r); - for (int i = 0; i < 2; i++) { - bn_free(m[i]); - bn_free(u[i]); - bn_free(v[i]); - g1_free(s[i]); - g2_free(x[i]); - g2_free(y[i]); - mt_free(tri[0][i]); - mt_free(tri[1][i]); - mt_free(tri[2][i]); - pt_free(t[i]); - for (int j = 0; j < MSGS; j++) { - bn_free(ms[j][i]); - bn_free(_v[j][i]); - g2_free(_y[j][i]); - } - } -} - - -int main(void) { - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - conf_print(); - - util_banner("Note: If you get a SIGSEGV, try to increase the stack size with ulimit.", 1); - -#if defined(WITH_PC) - if (pc_param_set_any() == RLC_OK) { -#if defined(WITH_MPC) - util_banner("Tests for the PS signature and two-party PS protocol:\n", 0); - test_pss(); - test_mpss(); - util_banner("Benchmarks for the PS signature and two-party PS protocol:\n", 0); - bench_pss(); - bench_mpss(); -#endif - } else { - RLC_THROW(ERR_NO_CURVE); - } -#endif - - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/demo/ers-etrs/Makefile b/src/dashbls/depends/relic/demo/ers-etrs/Makefile deleted file mode 100644 index 7d02f50aabd5..000000000000 --- a/src/dashbls/depends/relic/demo/ers-etrs/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -CFLAGS=-O3 -march=native -mtune=native -ggdb -RELIC_ROOT = ../.. - -all: lib - gcc ${CFLAGS} -c test-bench.c -o test-bench.o -I ${RELIC_ROOT}/include -I target/include - gcc ${CFLAGS} -o test-bench test-bench.o target/lib/librelic_s.a -lgmp - -lib: - mkdir -p target - cd target; ${RELIC_ROOT}/../preset/x64-ecc-128.sh ${RELIC_ROOT}/../; cmake -DEP_METHD='JACOB;LWNAF;COMBS;INTER' -DBN_METHD=' COMBA;COMBA;MONTY;SLIDE;LEHME;BASIC' .; make - -clean: - rm -rf target *.o test-bench diff --git a/src/dashbls/depends/relic/demo/ers-etrs/test-bench.c b/src/dashbls/depends/relic/demo/ers-etrs/test-bench.c deleted file mode 100644 index 22ea4c4612c9..000000000000 --- a/src/dashbls/depends/relic/demo/ers-etrs/test-bench.c +++ /dev/null @@ -1,226 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2009 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for cryptographic protocols. - * - * @version $Id$ - * @ingroup bench - */ - -#include - -#include "relic.h" -#include "relic_bench.h" - -#define MAX_KEYS 2048 - -#include "assert.h" - -static void ers(void) { - int size; - ec_t pp, pk[MAX_KEYS], *ptr; - bn_t sk[MAX_KEYS], td; - ers_t ring[MAX_KEYS]; - uint8_t m[5] = { 0, 1, 2, 3, 4 }; - - bn_null(td); - ec_null(pp); - - bn_new(td); - ec_new(pp); - for (int i = 0; i < MAX_KEYS; i++) { - bn_null(sk[i]); - bn_new(sk[i]); - ec_null(pk[i]); - ec_new(pk[i]); - ers_null(ring[i]); - ers_new(ring[i]); - cp_ers_gen_key(sk[i], pk[i]); - } - - cp_ers_gen(pp); - - bench_reset(); - for (int j = 0; j < BENCH; j++) { - BENCH_ADD(cp_ers_sig(td, ring[0], m, 5, sk[0], pk[0], pp)); - } - bench_compute(BENCH * BENCH); - util_print("{\"1\": {\"time\": %lf, \"size\": null}", bench_total()/(double)1000000); - - for (int j = 1; j < MAX_KEYS; j = j << 1) { - size = j; - bench_before(); - for (int k = 0; k < j; k++) { - cp_ers_ext(td, ring, &size, m, 5, pk[size], pp); - } - bench_after(); - bench_compute(1); - util_print(", \"%d\": {\"time\": %lf, \"size\": null}", size, bench_total()/(double)1000000); - assert(cp_ers_ver(td, ring, size, m, 5, pp)); - } - util_print("}\n\n"); - - /* Recompute the signature for verification. */ - cp_ers_sig(td, ring[0], m, 5, sk[0], pk[0], pp); - bench_reset(); - for (int j = 0; j < BENCH; j++) { - BENCH_ADD(assert(cp_ers_ver(td, ring, 1, m, 5, pp))); - } - bench_compute(BENCH * BENCH); - util_print("{\"1\": {\"time\": %lf, \"size\": %d}", bench_total()/(double)1000000, 9 * RLC_FP_BYTES); - - for (int j = 1; j < MAX_KEYS; j = j << 1) { - size = j; - /* Recompute the signatures for verification. */ - for (int k = 0; k < j; k++) { - assert(cp_ers_ext(td, ring, &size, m, 5, pk[size], pp) == RLC_OK); - } - assert(cp_ers_ver(td, ring, size, m, 5, pp)); - bench_reset(); - for (int i = 0; i < BENCH; i++) { - BENCH_ADD(cp_ers_ver(td, ring, size, m, 5, pp)); - } - bench_compute(BENCH * BENCH); - util_print(", \"%d\": {\"time\": %lf, \"size\": %d}", size, bench_total()/(double)1000000, size * 9 * RLC_FP_BYTES); - } - util_print("}"); - - bn_free(td); - ec_free(pp); - for (int i = 0; i < MAX_KEYS; i++) { - bn_free(sk[i]); - ec_free(pk[i]); - ers_free(ring[i]) - } -} - -#undef MAX_KEYS -#define MAX_KEYS 2048 -#define MIN_KEYS 64 - -static void etrs(void) { - int size; - ec_t pp, pk[MAX_KEYS], *ptr; - bn_t sk[MAX_KEYS], td[MAX_KEYS], y[MAX_KEYS]; - etrs_t ring[MAX_KEYS]; - uint8_t m[5] = { 0, 1, 2, 3, 4 }; - - ec_null(pp); - ec_new(pp); - for (int i = 0; i < MAX_KEYS; i++) { - bn_null(y[i]); - bn_new(y[i]); - bn_null(td[i]); - bn_new(td[i]); - bn_null(sk[i]); - bn_new(sk[i]); - ec_null(pk[i]); - ec_new(pk[i]); - ers_null(ring[i]); - ers_new(ring[i]); - cp_etrs_gen_key(sk[i], pk[i]); - } - - cp_ers_gen(pp); - - util_print("{"); - for (int j = 1; j <= MAX_KEYS; j = j << 1) { - bench_reset(); - bench_before(); - for (int i = 0; i < BENCH; i++) { - cp_etrs_sig(td, y, j, ring[0], m, 5, sk[0], pk[0], pp); - } - bench_after(); - bench_compute(BENCH); - util_print("\"%d\": {\"time\": %lf, \"size\": null}, ", j, bench_total()/(double)1000000); - assert(cp_etrs_ver(1, td, y, j, ring, 1, m, 5, pp)); - } - util_print("}\n\n"); - - for (int l = 2; l <= 8; l = l << 1) { - for (int j = l; j <= MAX_KEYS; j = j << 1) { - bench_reset(); - bench_before(); - size = 1; - cp_etrs_sig(td, y, j, ring[0], m, 5, sk[0], pk[0], pp); - for (int k = 1; k < j; k++) { - cp_etrs_ext(td, y, j, ring, &size, m, 5, pk[size], pp); - } - bench_after(); - bench_compute(1); - util_print("\"%d\": {\"time\": %lf, \"size\": null}, ", j, bench_total()/(double)1000000); - assert(cp_etrs_ver(1, td+size-1, y+size-1, j-size+1, ring, size, m, 5, pp)); - } - util_print("}\n\n"); - } - - for (int l = 1; l <= 8; l = l << 1) { - for (int j = l; j <= MAX_KEYS; j = j << 1) { - size = 1; - cp_etrs_sig(td, y, j, ring[0], m, 5, sk[0], pk[0], pp); - for (int k = 0; k < l; k++) { - cp_etrs_ext(td, y, j, ring, &size, m, 5, pk[size], pp); - } - bench_reset(); - bench_before(); - for (int i = 0; i < BENCH; i++) { - cp_etrs_ver(1, td+size-1, y+size-1, j-size+1, ring, size, m, 5, pp); - } - bench_after(); - bench_compute(BENCH); - util_print(", \"%d\": {\"time\": %lf, \"size\": null}", j, bench_total()/(double)1000000); - } - util_print("}\n\n"); - } - - ec_free(pp); - for (int i = 0; i < MAX_KEYS; i++) { - bn_free(td[i]); - bn_free(y[i]); - bn_free(sk[i]); - ec_free(pk[i]); - etrs_free(ring[i]) - } -} - -int main(void) { - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - conf_print(); - - if (ec_param_set_any() == RLC_OK) { - etrs(); - ers(); - } else { - RLC_THROW(ERR_NO_CURVE); - } - - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/demo/general-paillier/Makefile b/src/dashbls/depends/relic/demo/general-paillier/Makefile deleted file mode 100644 index dbbd14f19524..000000000000 --- a/src/dashbls/depends/relic/demo/general-paillier/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -CFLAGS=-O3 -march=native -mtune=native -ggdb -RELIC_ROOT = ../.. - -all: lib - gcc ${CFLAGS} -c test.c -o test.o -I ${RELIC_ROOT}/include -I target-gmp/include - gcc ${CFLAGS} -o test test.o target-gmp/lib/librelic_s.a -lgmp - -lib: - mkdir -p target-gmp - cd target-gmp; ${RELIC_ROOT}/../preset/gmp-paillier-4096.sh ${RELIC_ROOT}/../; make - -clean: - rm -rf target-gmp *.o test diff --git a/src/dashbls/depends/relic/demo/general-paillier/test.c b/src/dashbls/depends/relic/demo/general-paillier/test.c deleted file mode 100644 index d4bc201cc216..000000000000 --- a/src/dashbls/depends/relic/demo/general-paillier/test.c +++ /dev/null @@ -1,92 +0,0 @@ -#include -#include - -#include "relic.h" -#include "relic_test.h" - -static int paillier(void) { - int code = RLC_ERR; - bn_t a, b, c, d, s, pub, prv; - int result; - - bn_null(a); - bn_null(b); - bn_null(c); - bn_null(d); - - bn_null(pub); - bn_null(prv); - - RLC_TRY { - bn_new(a); - bn_new(b); - bn_new(c); - bn_new(d); - - bn_new(pub); - bn_new(prv); - - /* Generate 2048-bit public and private keys (both integers). */ - result = cp_ghpe_gen(pub, prv, 2048); - assert(result == RLC_OK); - - printf("Public key:\n"); - bn_print(pub); - printf("Private key:\n"); - bn_print(prv); - - for (int s = 1; s <= 2; s++) { - util_print("Testing generalized paillier for (s = %d)\n", s); - /* Generate plaintext smaller than n^s. */ - bn_rand(a, RLC_POS, s * (bn_bits(pub) - 1)); - /* Encrypt, decrypt and check if the result is the same. */ - assert(cp_ghpe_enc(c, a, pub, s) == RLC_OK); - assert(cp_ghpe_dec(b, c, pub, prv, s) == RLC_OK); - assert(bn_cmp(a, b) == RLC_EQ); - - /* Generate new plaintexts smaller than n^s. */ - bn_rand(a, RLC_POS, s * (bn_bits(pub) - 1)); - bn_rand(b, RLC_POS, s * (bn_bits(pub) - 1)); - /* Encrypt both plaintexts using the same public key. */ - assert(cp_ghpe_enc(c, a, pub, s) == RLC_OK); - assert(cp_ghpe_enc(d, b, pub, s) == RLC_OK); - - /* Now compute c = (b * c) mod n^(s + 1). */ - bn_mul(c, c, d); - bn_sqr(d, pub); - if (s == 2) { - bn_mul(d, d, pub); - } - bn_mod(c, c, d); - /* Decrypt and check if result is (a + b) mod n^s. */ - assert(cp_ghpe_dec(c, c, pub, prv, s) == RLC_OK); - bn_add(a, a, b); - bn_copy(d, pub); - if (s == 2) { - bn_mul(d, d, pub); - } - bn_mod(a, a, d); - assert(bn_cmp(a, c) == RLC_EQ); - } - } - RLC_CATCH_ANY { - RLC_ERROR(end); - } - code = RLC_OK; - - end: - bn_free(a); - bn_free(b); - bn_free(c); - bn_free(d); - - bn_free(prv); - bn_free(pub); - return code; -} - -int main(int argc, char *argv[]) { - core_init(); - paillier(); - core_clean(); -} diff --git a/src/dashbls/depends/relic/demo/link-test/Makefile b/src/dashbls/depends/relic/demo/link-test/Makefile deleted file mode 100644 index da9ef8a4155d..000000000000 --- a/src/dashbls/depends/relic/demo/link-test/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -RELIC_ROOT = ../../.. - -all: type1 type3 - gcc -c test1.c -o test1.o -I /usr/local/include/relic_type1 - gcc -c test2.c -o test2.o -I /usr/local/include/relic_type3 - gcc -o test test.c test1.o test2.o /usr/local/lib/librelic_s_*.a -lgmp - -type1: - mkdir -p target-type1 - cd target-type1; cmake -DLABEL=type1 ${RELIC_ROOT}; ${RELIC_ROOT}/preset/gmp-pbc-ss1536.sh ${RELIC_ROOT}; make && make install - -type3: - mkdir -p target-type3 - cd target-type3; cmake -DLABEL=type3 ${RELIC_ROOT}; ${RELIC_ROOT}/preset/x64-pbc-bls12-381.sh ${RELIC_ROOT}; make && make install - -clean: - rm -rf target-* *.o test diff --git a/src/dashbls/depends/relic/demo/link-test/test.c b/src/dashbls/depends/relic/demo/link-test/test.c deleted file mode 100644 index edfd8e224c5e..000000000000 --- a/src/dashbls/depends/relic/demo/link-test/test.c +++ /dev/null @@ -1,4 +0,0 @@ -int main() { - function1(); - function2(); -} diff --git a/src/dashbls/depends/relic/demo/link-test/test1.c b/src/dashbls/depends/relic/demo/link-test/test1.c deleted file mode 100644 index f6e77f2a0592..000000000000 --- a/src/dashbls/depends/relic/demo/link-test/test1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include - -void function1() { - g1_t p; - g2_t q; - gt_t e; - - g1_null(p); - g2_null(q); - gt_null(e); - - core_init(); - - RLC_TRY { - core_init(); - pc_param_set_any(); - pc_param_print(); - - g1_new(p); - g2_new(q); - gt_new(e); - - g1_rand(p); - g2_rand(q); - pc_map(e, p, q); - - gt_print(e); - printf("Is pairing symmetric? %d\n", pc_map_is_type1() == 1); - printf("Is pairing asymmetric? %d\n", pc_map_is_type3() == 1); - } RLC_CATCH_ANY { - } RLC_FINALLY { - g1_free(p); - g2_free(q); - gt_free(e); - } - core_clean(); -} diff --git a/src/dashbls/depends/relic/demo/link-test/test2.c b/src/dashbls/depends/relic/demo/link-test/test2.c deleted file mode 100644 index f15a6891b12d..000000000000 --- a/src/dashbls/depends/relic/demo/link-test/test2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include - -void function2() { - g1_t p; - g2_t q; - gt_t e; - - g1_null(p); - g2_null(q); - gt_null(e); - - core_init(); - - RLC_TRY { - core_init(); - pc_param_set_any(); - pc_param_print(); - - g1_new(p); - g2_new(q); - gt_new(e); - - g1_rand(p); - g2_rand(q); - pc_map(e, p, q); - - gt_print(e); - printf("Is pairing symmetric? %d\n", pc_map_is_type1() == 1); - printf("Is pairing asymmetric? %d\n", pc_map_is_type3() == 1); - } RLC_CATCH_ANY { - } RLC_FINALLY { - g1_free(p); - g2_free(q); - gt_free(e); - } - core_clean(); -} diff --git a/src/dashbls/depends/relic/demo/public-stats/Makefile b/src/dashbls/depends/relic/demo/public-stats/Makefile deleted file mode 100644 index 81a4b72d5619..000000000000 --- a/src/dashbls/depends/relic/demo/public-stats/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -CFLAGS=-O3 -march=native -mtune=native -ggdb -RELIC_ROOT = ../.. - -all: lib data.csv - gcc ${CFLAGS} -c main.c -o main.o -I ${RELIC_ROOT}/include -I target/include - gcc ${CFLAGS} -c csv.c -o csv.o -I ${RELIC_ROOT}/include -I target/include - gcc ${CFLAGS} -o main csv.o main.o target/lib/librelic_s.a -lgmp - -lib: - mkdir -p target - cd target; ${RELIC_ROOT}/../preset/x64-pbc-bls12-381.sh ${RELIC_ROOT}/../; cmake -DEP_METHD='JACOB;LWNAF;COMBS;INTER' .; make - -data.csv: - wget -c https://raw.githubusercontent.com/TheEconomist/covid-19-excess-deaths-tracker/master/source-data/spain/archive/spain_total_source_2020_04_13.csv - mv spain_total_source_2020_04_13.csv data_04_13.csv - wget -c https://momo.isciii.es/public/momo/data - mv data data.csv - -clean: - rm -rf target *.o main diff --git a/src/dashbls/depends/relic/demo/public-stats/csv.c b/src/dashbls/depends/relic/demo/public-stats/csv.c deleted file mode 100644 index 801201e26cea..000000000000 --- a/src/dashbls/depends/relic/demo/public-stats/csv.c +++ /dev/null @@ -1,153 +0,0 @@ -/* -Copyright 2015 Samuel Alexander - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#include -#include - -void free_csv_line( char **parsed ) { - char **ptr; - - for ( ptr = parsed; *ptr; ptr++ ) { - free( *ptr ); - } - - free( parsed ); -} - -static int count_fields( const char *line ) { - const char *ptr; - int cnt, fQuote; - - for ( cnt = 1, fQuote = 0, ptr = line; *ptr; ptr++ ) { - if ( fQuote ) { - if ( *ptr == '\"' ) { - if ( ptr[1] == '\"' ) { - ptr++; - continue; - } - fQuote = 0; - } - continue; - } - - switch( *ptr ) { - case '\"': - fQuote = 1; - continue; - case ',': - cnt++; - continue; - default: - continue; - } - } - - if ( fQuote ) { - return -1; - } - - return cnt; -} - -/* - * Given a string containing no linebreaks, or containing line breaks - * which are escaped by "double quotes", extract a NULL-terminated - * array of strings, one for every cell in the row. - */ -char **parse_csv( const char *line ) { - char **buf, **bptr, *tmp, *tptr; - const char *ptr; - int fieldcnt, fQuote, fEnd; - - fieldcnt = count_fields( line ); - - if ( fieldcnt == -1 ) { - return NULL; - } - - buf = malloc( sizeof(char*) * (fieldcnt+1) ); - - if ( !buf ) { - return NULL; - } - - tmp = malloc( strlen(line) + 1 ); - - if ( !tmp ) { - free( buf ); - return NULL; - } - - bptr = buf; - - for ( ptr = line, fQuote = 0, *tmp = '\0', tptr = tmp, fEnd = 0; ; ptr++ ) { - if ( fQuote ) { - if ( !*ptr ) { - break; - } - - if ( *ptr == '\"' ) { - if ( ptr[1] == '\"' ) { - *tptr++ = '\"'; - ptr++; - continue; - } - fQuote = 0; - } - else { - *tptr++ = *ptr; - } - - continue; - } - - switch( *ptr ) { - case '\"': - fQuote = 1; - continue; - case '\0': - fEnd = 1; - case ',': - *tptr = '\0'; - *bptr = strdup( tmp ); - - if ( !*bptr ) { - for ( bptr--; bptr >= buf; bptr-- ) { - free( *bptr ); - } - free( buf ); - free( tmp ); - - return NULL; - } - - bptr++; - tptr = tmp; - - if ( fEnd ) { - break; - } else { - continue; - } - - default: - *tptr++ = *ptr; - continue; - } - - if ( fEnd ) { - break; - } - } - - *bptr = NULL; - free( tmp ); - return buf; -} diff --git a/src/dashbls/depends/relic/demo/public-stats/csv.h b/src/dashbls/depends/relic/demo/public-stats/csv.h deleted file mode 100644 index 18327eea9fb9..000000000000 --- a/src/dashbls/depends/relic/demo/public-stats/csv.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef CSV_DOT_H_INCLUDE_GUARD -#define CSV_DOT_H_INCLUDE_GUARD - -#define CSV_ERR_LONGLINE 0 -#define CSV_ERR_NO_MEMORY 1 - -char **parse_csv( const char *line ); -void free_csv_line( char **parsed ); -char **split_on_unescaped_newlines(const char *txt); -char *fread_csv_line(FILE *fp, int max_line_size, int *done, int *err); - -#endif diff --git a/src/dashbls/depends/relic/demo/public-stats/main.c b/src/dashbls/depends/relic/demo/public-stats/main.c deleted file mode 100644 index ae75fa1d7b68..000000000000 --- a/src/dashbls/depends/relic/demo/public-stats/main.c +++ /dev/null @@ -1,349 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2020 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Benchmarks for cryptographic protocols. - * - * @version $Id$ - * @ingroup bench - */ - -#include - -#include "relic.h" -#include "csv.h" - -#include -#include -#include -#include -#include - -#define STATES 19 -#define GROUPS 3 -#define DAYS 90 -#define FACTOR (1000000) -#define FIXED ((uint64_t)100000) -#define DATABASE "COVID19-Spain" -#define BEG_2018 "27/03/2018" -#define END_2018 "25/06/2018" -#define BEG_2019 "27/03/2019" -#define END_2019 "25/06/2019" -#define BEG_2020 "2020-03-27" -#define END_2020 "2020-06-25" - -/* First value is population in each of the autonomous communities in 2020. */ -uint64_t populations[STATES] = { - 8405294, 1316064, 1024381, 1176627, 2188626, 580997, 2410819, - 2030807, 7516544, 4948411, 1067272, 2699299, 6587711, 1479098, 646197, - 2172591, 312719, 84913, 84667 -}; - -/* Total population per age group in 2019. */ -uint64_t pyramid[GROUPS] = { 37643844, 4482743, 4566276 }; - -char *acronyms[STATES] = { - "AN", "AR", "AS", "IB", "CN", "CB", "CL", "CM", "CT", "VC", - "EX", "GA", "MD", "MC", "NC", "PV", "RI", "CE", "ML" -}; - -char *acs[STATES] = { - "Andalusia", "Aragón", "Asturias", "Balearics", "Canary Islands", - "Cantabria", "Castile & León", "Castile-La Mancha", "Catalonia", - "Valencia", "Extremadura", "Galicia", "Madrid", "Murcia", - "Navarre", "Basque Country", "La Rioja", "Ceuta", "Melilla" -}; - -/* Population pyramids for autonomous communities, taken from countryeconomy.com */ -double pyramids[STATES][GROUPS] = { - {15.86 + 66.98, 9.06, 17.16 - 9.06}, - {14.12 + 64.23, 10.26, 21.65 - 10.26}, - {10.97 + 63.37, 12.82, 25.66 - 12.82}, - {14.89 + 69.29, 8.62, 15.82 - 8.62}, - {13.20 + 70.57, 8.91, 16.22 - 8.91}, - {13.29 + 64.81, 11.11, 21.90 - 11.11}, - {11.94 + 62.83, 11.41, 25.23 - 11.41}, - {15.11 + 65.91, 8.80, 18.99 - 8.80}, - {15.53 + 65.36, 9.69, 19.12 - 9.69}, - {14.87 + 65.62, 10.15, 19.51 - 10.15}, - {13.66 + 65.70, 9.78, 20.64 - 9.78}, - {11.87 + 62.96, 11.90, 25.16 - 11.90}, - {15.48 + 66.66, 9.13, 18.86 - 9.13}, - {17.18 + 67.04, 8.19, 15.78 - 8.19}, - {15.51 + 64.69, 9.88, 19.80 - 9.88}, - {13.20 + 70.57, 8.91, 16.22 - 8.91}, - {11.87 + 62.96, 11.90, 25.16 - 11.90}, - {20.42 + 67.57, 6.58, 12.02 - 6.58}, - {15.48 + 66.66, 9.13, 17.86 - 9.13}, - //{80.55, 9.59, 9.77} //Spain -}; - -/* Read data from CSV in a given time interval. */ -void read_region(g1_t s[], char *l[], bn_t m[], int *counter, - uint64_t metric[3], const char *file, int region, char *start, - char *end, bn_t sk) { - FILE *stream = fopen(file, "r"); - int found = 0; - char line[1024]; - char str[3]; - char label[100] = { 0 }; - dig_t n; - - found = 0; - sprintf(str, "%d", region); - while (fgets(line, 1024, stream)) { - if (strstr(line, start) != NULL) { - found = 1; - } - if (strstr(line, end) != NULL) { - found = 0; - } - char **tmp = parse_csv(line); - char **ptr = tmp; - - if (found && !strcmp(ptr[2], str) && !strcmp(ptr[5], "todos") && - strcmp(ptr[7], "todos")) { - n = atoi(ptr[9]); - //printf("%s\n", line); - if (strcmp(ptr[6], "menos_65") == 0) { - //printf("< 65 = %s\n", ptr[9]); - metric[0] += n; - } - if (strcmp(ptr[6], "65_74") == 0) { - //printf("65-74 = %s\n", ptr[9]); - metric[1] += n; - } - if (strcmp(ptr[6], "mas_74") == 0) { - //printf("> 74 = %s\n", ptr[9]); - metric[2] += n; - } - - bn_set_dig(m[*counter], n); - l[*counter] = strdup(ptr[8]); - cp_mklhs_sig(s[*counter], m[*counter], DATABASE, acs[region - 1], - l[*counter], sk); - (*counter)++; - } - - free_csv_line(tmp); - } - fclose(stream); -} - -int main(int argc, char *argv[]) { - uint64_t baseline[GROUPS] = { 0, 0, 0 }; - uint64_t mortality[GROUPS] = { 0, 0, 0 }; - uint64_t expected[GROUPS] = { 0, 0, 0 }; - uint64_t observed[STATES][GROUPS]; - uint64_t ratios[STATES][GROUPS]; - dig_t ft[STATES]; - bn_t res, t[STATES], sk[STATES], m[STATES][3 * GROUPS * DAYS]; - g1_t u, sig, sigs[STATES][3 * GROUPS * DAYS], cs[STATES]; - g2_t pk[STATES]; - char *l[STATES][3 * GROUPS * DAYS]; - dig_t *f[STATES]; - int flen[STATES]; - int counter; - uint64_t total; - uint64_t excess; - - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - if (pc_param_set_any() != RLC_OK) { - core_clean; - return 1; - } - - RLC_TRY { - /* Initialize and generate keys for signers. */ - bn_null(res); - bn_new(res); - g1_null(u); - g1_new(u); - g1_null(sig); - g1_new(sig); - for (int i = 0; i < STATES; i++) { - f[i] = RLC_ALLOCA(dig_t, 2 * GROUPS * DAYS); - bn_null(t[i]); - bn_new(t[i]); - bn_null(sk[i]); - bn_new(sk[i]); - g1_null(cs[i]); - g1_new(cs[i]); - g2_null(sk[i]); - g2_new(sk[i]); - cp_mklhs_gen(sk[i], pk[i]); - for (int j = 0; j < GROUPS; j++) { - for (int k = 0; k < 3 * DAYS; k++) { - bn_null(m[i][j * 3 * DAYS + k]); - bn_new(m[i][j * 3 * DAYS + k]); - g1_null(sigs[i][j * 3 * DAYS + k]); - g1_new(sigs[i][j * 3 * DAYS + k]); - l[i][j * 3 * DAYS + k] = NULL; - } - } - } - - /* Compute current population of every age group in each autonomous community. */ - for (int i = 0; i < STATES; i++) { - for (int j = 0; j < GROUPS; j++) { - ratios[i][j] = pyramids[i][j] / 100.0 * populations[i]; - } - } - - for (int i = 0; i < STATES; i++) { - counter = 0; - observed[i][0] = observed[i][1] = observed[i][2] = 0; - read_region(sigs[i], l[i], m[i], &counter, baseline, - "data_04_13.csv", i + 1, BEG_2018, END_2018, sk[i]); - read_region(sigs[i], l[i], m[i], &counter, baseline, - "data_04_13.csv", i + 1, BEG_2019, END_2019, sk[i]); - read_region(sigs[i], l[i], m[i], &counter, observed[i], "data.csv", - i + 1, BEG_2020, END_2020, sk[i]); - } - - for (int j = 0; j < GROUPS; j++) { - mortality[j] = FIXED * FACTOR / (2 * pyramid[j]) * baseline[j]; - } - - total = excess = 0; - for (int i = 0; i < STATES; i++) { - printf("%s -- %s:\n", acronyms[i], acs[i]); - - for (int j = 0; j < GROUPS; j++) { - //expected[j] = (FIXED * ratios[i][j]/(2*pyramid[j])) * baseline[j]; - expected[j] = mortality[j] * ratios[i][j] / (FIXED * FACTOR); - } - - printf("\texpected : %lu %lu %lu\n", expected[0], expected[1], - expected[2]); - printf("\tobserved : %lu %lu %lu\n", observed[i][0], observed[i][1], - observed[i][2]); - - printf("\ttotal expected: %lu\n", - (expected[0] + expected[1] + expected[2]) / FIXED); - printf("\ttotal observed: %lu\n", - observed[i][0] + observed[i][1] + observed[i][2]); - - total += (expected[0] + expected[1] + expected[2]); - excess += (observed[i][0] + observed[i][1] + observed[i][2]); - } - - util_banner("Plaintext computation:", 1); - - printf("Baseline : %6lu %6lu %6lu\n", baseline[0] / 2, baseline[1] / 2, - baseline[2] / 2); - printf("Demograph: %6lu %6lu %6lu\n", pyramid[0] / FACTOR, - pyramid[1] / FACTOR, pyramid[2] / FACTOR); - printf("Mortality: %6lu %6lu %6lu\n", mortality[0] / FIXED, - mortality[1] / FIXED, mortality[2] / FIXED); - printf("Total Expected: %6lu\n", total); - printf("Total Observed: %6lu\n", excess); - - util_banner("Authenticated computation:", 1); - - bn_zero(res); - g1_set_infty(u); - g1_set_infty(sig); - for (int i = 0; i < STATES; i++) { - flen[i] = 2 * GROUPS * DAYS; - for (int j = 0; j < GROUPS; j++) { - total = 0; - for (int k = 0; k < STATES; k++) { - total += FIXED * ratios[k][j] / (2 * pyramid[j]); - } - for (int k = 0; k < DAYS; k++) { - f[i][j * DAYS + k] = f[i][j * DAYS + GROUPS * DAYS + k] = - total; - } - } - cp_mklhs_fun(t[i], m[i], f[i], 2 * GROUPS * DAYS); - cp_mklhs_evl(u, sigs[i], f[i], 2 * GROUPS * DAYS); - bn_add(res, res, t[i]); - g1_add(sig, sig, u); - } - g1_norm(sig, sig); - assert(cp_mklhs_ver(sig, res, t, DATABASE, acs, l[0], f, flen, - pk, STATES)); - - printf("Total Expected: %6lu\n", res->dp[0] / FIXED); - - bn_zero(res); - g1_set_infty(u); - g1_set_infty(sig); - for (int i = 0; i < STATES; i++) { - flen[i] = GROUPS * DAYS; - for (int j = 0; j < GROUPS; j++) { - for (int k = 0; k < DAYS; k++) { - f[i][j * DAYS + k] = 1; - } - } - cp_mklhs_fun(t[i], &m[i][2 * GROUPS * DAYS], f[i], GROUPS * DAYS); - cp_mklhs_evl(u, &sigs[i][2 * GROUPS * DAYS], f[i], GROUPS * DAYS); - bn_add(res, res, t[i]); - g1_add(sig, sig, u); - } - g1_norm(sig, sig); - - printf("Total Observed: %6lu\n", res->dp[0]); - - assert(cp_mklhs_ver(sig, res, t, DATABASE, acs, - &l[0][2 * GROUPS * DAYS], f, flen, pk, STATES)); - BENCH_ONE("Time elapsed", cp_mklhs_ver(sig, res, t, DATABASE, acs, - &l[0][2 * GROUPS * DAYS], f, flen, pk, STATES)); - - cp_mklhs_off(cs, ft, acs, &l[0][2 * GROUPS * DAYS], f, flen, STATES); - assert(cp_mklhs_onv(sig, res, t, DATABASE, acs, cs, ft, pk, STATES)); - BENCH_ONE("Time with precomputation", cp_mklhs_onv(sig, res, t, - DATABASE, acs, cs, ft, pk, STATES)); - - } RLC_CATCH_ANY { - RLC_THROW(ERR_CAUGHT); - } RLC_FINALLY { - bn_free(res); - g1_free(u); - g1_free(sig); - for (int i = 0; i < STATES; i++) { - RLC_FREE(f[i]); - bn_free(t[i]); - bn_free(sk[i]); - g1_free(cs[i]); - g2_free(pk[i]); - for (int j = 0; j < GROUPS; j++) { - for (int k = 0; k < 3 * DAYS; k++) { - bn_free(m[i][j * 3 * DAYS + k]); - g1_free(sigs[i][j * 3 * DAYS + k]); - free(l[i][j * 3 * DAYS + k]); - } - } - } - } - - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/demo/tweedledum/Makefile b/src/dashbls/depends/relic/demo/tweedledum/Makefile deleted file mode 100644 index c5e31f030311..000000000000 --- a/src/dashbls/depends/relic/demo/tweedledum/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -CFLAGS=-O3 -march=native -mtune=native -ggdb -RELIC_ROOT = ../.. - -all: lib - gcc ${CFLAGS} -c main.c -o main.o -I ${RELIC_ROOT}/include -I target/include - gcc ${CFLAGS} -o main main.o target/lib/librelic_s.a -lgmp - -lib: - mkdir -p target - cd target; ${RELIC_ROOT}/../preset/gmp-ecc-tweedledum.sh ${RELIC_ROOT}/../; cmake -DEP_METHD='JACOB;LWNAF;COMBS;INTER' .; make - -clean: - rm -rf target *.o main diff --git a/src/dashbls/depends/relic/demo/tweedledum/main.c b/src/dashbls/depends/relic/demo/tweedledum/main.c deleted file mode 100644 index 5d60db7e71a2..000000000000 --- a/src/dashbls/depends/relic/demo/tweedledum/main.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * RELIC is an Efficient LIbrary for Cryptography - * Copyright (c) 2020 RELIC Authors - * - * This file is part of RELIC. RELIC is legal property of its developers, - * whose names are not listed here. Please refer to the COPYRIGHT file - * for contact information. - * - * RELIC is free software; you can redistribute it and/or modify it under the - * terms of the version 2.1 (or later) of the GNU Lesser General Public License - * as published by the Free Software Foundation; or version 2.0 of the Apache - * License as published by the Apache Software Foundation. See the LICENSE files - * for more details. - * - * RELIC 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 LICENSE files for more details. - * - * You should have received a copy of the GNU Lesser General Public or the - * Apache License along with RELIC. If not, see - * or . - */ - -/** - * @file - * - * Tests for the Elliptic Curve Cryptography module. - * - * @ingroup test - */ - -#include -#include - -#include "relic.h" -#include "relic_test.h" - -int main(void) { - ec_t g, a, b; - bn_t l, r; - - /* Initialize points. */ - ec_new(g); - ec_new(a); - ec_new(b); - bn_new(l); - bn_new(r); - - if (core_init() != RLC_OK) { - core_clean(); - return 1; - } - - util_banner("Tests for the EC module:", 0); - - /* Ask for curve to get Tweedledum. */ - if (ec_param_set_any() == RLC_ERR) { - RLC_THROW(ERR_NO_CURVE); - core_clean(); - return 0; - } - - /* Print curve name to make sure it is the right one. */ - ec_param_print(); - - /* Check that generator has the right order. */ - ec_curve_get_gen(g); - ec_curve_get_ord(r); - ec_mul(g, g, r); - assert(ec_is_infty(g)); - - /* Generate some random point and exponents to illustrate scalar mult. */ - ec_rand(a); - ec_rand(b); - bn_rand_mod(l, r); - ec_mul(a, a, l); - ec_print(a); - - util_banner("All tests have passed.\n", 0); - - ec_free(g); - ec_free(a); - ec_free(b); - bn_free(l); - bn_free(r); - core_clean(); - return 0; -} diff --git a/src/dashbls/depends/relic/doc/relic.doxygen.in b/src/dashbls/depends/relic/doc/relic.doxygen.in deleted file mode 100644 index 09e39fa30a0d..000000000000 --- a/src/dashbls/depends/relic/doc/relic.doxygen.in +++ /dev/null @@ -1,2309 +0,0 @@ -# Doxyfile 1.8.6 - -# This file describes the settings to be used by the documentation system -# doxygen (www.doxygen.org) for a project. -# -# All text after a double hash (##) is considered a comment and is placed in -# front of the TAG it is preceding. -# -# All text after a single hash (#) is considered a comment and will be ignored. -# The format is: -# TAG = value [value, ...] -# For lists, items can also be appended using: -# TAG += value [value, ...] -# Values that contain spaces should be placed between quotes (\" \"). - -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- - -# This tag specifies the encoding used for all characters in the config file -# that follow. The default is UTF-8 which is also the encoding used for all text -# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv -# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv -# for the list of possible encodings. -# The default value is: UTF-8. - -DOXYFILE_ENCODING = UTF-8 - -# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by -# double-quotes, unless you are using Doxywizard) that should identify the -# project for which the documentation is generated. This name is used in the -# title of most generated pages and in a few other places. -# The default value is: My Project. - -PROJECT_NAME = "@PROJECT_NAME@" - -# The PROJECT_NUMBER tag can be used to enter a project or revision number. This -# could be handy for archiving the generated documentation or if some version -# control system is used. - -PROJECT_NUMBER = @PROJECT_VERSION@ - -# Using the PROJECT_BRIEF tag one can provide an optional one line description -# for a project that appears at the top of each page and should give viewer a -# quick idea about the purpose of the project. Keep the description short. - -PROJECT_BRIEF = - -# With the PROJECT_LOGO tag one can specify an logo or icon that is included in -# the documentation. The maximum height of the logo should not exceed 55 pixels -# and the maximum width should not exceed 200 pixels. Doxygen will copy the logo -# to the output directory. - -PROJECT_LOGO = @CMAKE_CURRENT_SOURCE_DIR@/art/logo.png - -# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path -# into which the generated documentation will be written. If a relative path is -# entered, it will be relative to the location where doxygen was started. If -# left blank the current directory will be used. - -OUTPUT_DIRECTORY = ./doc - -# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 4096 sub- -# directories (in 2 levels) under the output directory of each output format and -# will distribute the generated files over these directories. Enabling this -# option can be useful when feeding doxygen a huge amount of source files, where -# putting all generated files in the same directory would otherwise causes -# performance problems for the file system. -# The default value is: NO. - -CREATE_SUBDIRS = YES - -# The OUTPUT_LANGUAGE tag is used to specify the language in which all -# documentation generated by doxygen is written. Doxygen will use this -# information to generate all constant output in the proper language. -# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, -# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), -# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, -# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), -# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, -# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, -# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, -# Ukrainian and Vietnamese. -# The default value is: English. - -OUTPUT_LANGUAGE = English - -# If the BRIEF_MEMBER_DESC tag is set to YES doxygen will include brief member -# descriptions after the members that are listed in the file and class -# documentation (similar to Javadoc). Set to NO to disable this. -# The default value is: YES. - -BRIEF_MEMBER_DESC = YES - -# If the REPEAT_BRIEF tag is set to YES doxygen will prepend the brief -# description of a member or function before the detailed description -# -# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the -# brief descriptions will be completely suppressed. -# The default value is: YES. - -REPEAT_BRIEF = YES - -# This tag implements a quasi-intelligent brief description abbreviator that is -# used to form the text in various listings. Each string in this list, if found -# as the leading text of the brief description, will be stripped from the text -# and the result, after processing the whole list, is used as the annotated -# text. Otherwise, the brief description is used as-is. If left blank, the -# following values are used ($name is automatically replaced with the name of -# the entity):The $name class, The $name widget, The $name file, is, provides, -# specifies, contains, represents, a, an and the. - -ABBREVIATE_BRIEF = - -# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then -# doxygen will generate a detailed section even if there is only a brief -# description. -# The default value is: NO. - -ALWAYS_DETAILED_SEC = NO - -# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all -# inherited members of a class in the documentation of that class as if those -# members were ordinary class members. Constructors, destructors and assignment -# operators of the base classes will not be shown. -# The default value is: NO. - -INLINE_INHERITED_MEMB = NO - -# If the FULL_PATH_NAMES tag is set to YES doxygen will prepend the full path -# before files name in the file list and in the header files. If set to NO the -# shortest path that makes the file name unique will be used -# The default value is: YES. - -FULL_PATH_NAMES = YES - -# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. -# Stripping is only done if one of the specified strings matches the left-hand -# part of the path. The tag can be used to show relative paths in the file list. -# If left blank the directory from which doxygen is run is used as the path to -# strip. -# -# Note that you can specify absolute paths here, but also relative paths, which -# will be relative from the directory where doxygen is started. -# This tag requires that the tag FULL_PATH_NAMES is set to YES. - -STRIP_FROM_PATH = @CMAKE_CURRENT_BINARY_DIR@/ \ - @CMAKE_CURRENT_SOURCE_DIR@/ - -# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the -# path mentioned in the documentation of a class, which tells the reader which -# header file to include in order to use a class. If left blank only the name of -# the header file containing the class definition is used. Otherwise one should -# specify the list of include paths that are normally passed to the compiler -# using the -I flag. - -STRIP_FROM_INC_PATH = @CMAKE_CURRENT_BINARY_DIR@/ \ - @CMAKE_CURRENT_SOURCE_DIR@/ - -# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but -# less readable) file names. This can be useful is your file systems doesn't -# support long names like on DOS, Mac, or CD-ROM. -# The default value is: NO. - -SHORT_NAMES = NO - -# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the -# first line (until the first dot) of a Javadoc-style comment as the brief -# description. If set to NO, the Javadoc-style will behave just like regular Qt- -# style comments (thus requiring an explicit @brief command for a brief -# description.) -# The default value is: NO. - -JAVADOC_AUTOBRIEF = NO - -# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first -# line (until the first dot) of a Qt-style comment as the brief description. If -# set to NO, the Qt-style will behave just like regular Qt-style comments (thus -# requiring an explicit \brief command for a brief description.) -# The default value is: NO. - -QT_AUTOBRIEF = NO - -# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a -# multi-line C++ special comment block (i.e. a block of //! or /// comments) as -# a brief description. This used to be the default behavior. The new default is -# to treat a multi-line C++ comment block as a detailed description. Set this -# tag to YES if you prefer the old behavior instead. -# -# Note that setting this tag to YES also means that rational rose comments are -# not recognized any more. -# The default value is: NO. - -MULTILINE_CPP_IS_BRIEF = NO - -# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the -# documentation from any documented member that it re-implements. -# The default value is: YES. - -INHERIT_DOCS = NO - -# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce a -# new page for each member. If set to NO, the documentation of a member will be -# part of the file/class/namespace that contains it. -# The default value is: NO. - -SEPARATE_MEMBER_PAGES = NO - -# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen -# uses this value to replace tabs by spaces in code fragments. -# Minimum value: 1, maximum value: 16, default value: 4. - -TAB_SIZE = 4 - -# This tag can be used to specify a number of aliases that act as commands in -# the documentation. An alias has the form: -# name=value -# For example adding -# "sideeffect=@par Side Effects:\n" -# will allow you to put the command \sideeffect (or @sideeffect) in the -# documentation, which will result in a user-defined paragraph with heading -# "Side Effects:". You can put \n's in the value part of an alias to insert -# newlines. - -ALIASES = - -# This tag can be used to specify a number of word-keyword mappings (TCL only). -# A mapping has the form "name=value". For example adding "class=itcl::class" -# will allow you to use the command class in the itcl::class meaning. - -TCL_SUBST = - -# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources -# only. Doxygen will then generate output that is more tailored for C. For -# instance, some of the names that are used will be different. The list of all -# members will be omitted, etc. -# The default value is: NO. - -OPTIMIZE_OUTPUT_FOR_C = YES - -# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or -# Python sources only. Doxygen will then generate output that is more tailored -# for that language. For instance, namespaces will be presented as packages, -# qualified scopes will look different, etc. -# The default value is: NO. - -OPTIMIZE_OUTPUT_JAVA = NO - -# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran -# sources. Doxygen will then generate output that is tailored for Fortran. -# The default value is: NO. - -OPTIMIZE_FOR_FORTRAN = NO - -# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL -# sources. Doxygen will then generate output that is tailored for VHDL. -# The default value is: NO. - -OPTIMIZE_OUTPUT_VHDL = NO - -# Doxygen selects the parser to use depending on the extension of the files it -# parses. With this tag you can assign which parser to use for a given -# extension. Doxygen has a built-in mapping, but you can override or extend it -# using this tag. The format is ext=language, where ext is a file extension, and -# language is one of the parsers supported by doxygen: IDL, Java, Javascript, -# C#, C, C++, D, PHP, Objective-C, Python, Fortran, VHDL. For instance to make -# doxygen treat .inc files as Fortran files (default is PHP), and .f files as C -# (default is Fortran), use: inc=Fortran f=C. -# -# Note For files without extension you can use no_extension as a placeholder. -# -# Note that for custom extensions you also need to set FILE_PATTERNS otherwise -# the files are not read by doxygen. - -EXTENSION_MAPPING = - -# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments -# according to the Markdown format, which allows for more readable -# documentation. See http://daringfireball.net/projects/markdown/ for details. -# The output of markdown processing is further processed by doxygen, so you can -# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in -# case of backward compatibilities issues. -# The default value is: YES. - -MARKDOWN_SUPPORT = YES - -# When enabled doxygen tries to link words that correspond to documented -# classes, or namespaces to their corresponding documentation. Such a link can -# be prevented in individual cases by by putting a % sign in front of the word -# or globally by setting AUTOLINK_SUPPORT to NO. -# The default value is: YES. - -AUTOLINK_SUPPORT = YES - -# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want -# to include (a tag file for) the STL sources as input, then you should set this -# tag to YES in order to let doxygen match functions declarations and -# definitions whose arguments contain STL classes (e.g. func(std::string); -# versus func(std::string) {}). This also make the inheritance and collaboration -# diagrams that involve STL classes more complete and accurate. -# The default value is: NO. - -BUILTIN_STL_SUPPORT = NO - -# If you use Microsoft's C++/CLI language, you should set this option to YES to -# enable parsing support. -# The default value is: NO. - -CPP_CLI_SUPPORT = NO - -# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: -# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen -# will parse them like normal C++ but will assume all classes use public instead -# of private inheritance when no explicit protection keyword is present. -# The default value is: NO. - -SIP_SUPPORT = NO - -# For Microsoft's IDL there are propget and propput attributes to indicate -# getter and setter methods for a property. Setting this option to YES will make -# doxygen to replace the get and set methods by a property in the documentation. -# This will only work if the methods are indeed getting or setting a simple -# type. If this is not the case, or you want to show the methods anyway, you -# should set this option to NO. -# The default value is: YES. - -IDL_PROPERTY_SUPPORT = YES - -# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC -# tag is set to YES, then doxygen will reuse the documentation of the first -# member in the group (if any) for the other members of the group. By default -# all members of a group must be documented explicitly. -# The default value is: NO. - -DISTRIBUTE_GROUP_DOC = YES - -# Set the SUBGROUPING tag to YES to allow class member groups of the same type -# (for instance a group of public functions) to be put as a subgroup of that -# type (e.g. under the Public Functions section). Set it to NO to prevent -# subgrouping. Alternatively, this can be done per class using the -# \nosubgrouping command. -# The default value is: YES. - -SUBGROUPING = YES - -# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions -# are shown inside the group in which they are included (e.g. using \ingroup) -# instead of on a separate page (for HTML and Man pages) or section (for LaTeX -# and RTF). -# -# Note that this feature does not work in combination with -# SEPARATE_MEMBER_PAGES. -# The default value is: NO. - -INLINE_GROUPED_CLASSES = NO - -# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions -# with only public data fields or simple typedef fields will be shown inline in -# the documentation of the scope in which they are defined (i.e. file, -# namespace, or group documentation), provided this scope is documented. If set -# to NO, structs, classes, and unions are shown on a separate page (for HTML and -# Man pages) or section (for LaTeX and RTF). -# The default value is: NO. - -INLINE_SIMPLE_STRUCTS = NO - -# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or -# enum is documented as struct, union, or enum with the name of the typedef. So -# typedef struct TypeS {} TypeT, will appear in the documentation as a struct -# with name TypeT. When disabled the typedef will appear as a member of a file, -# namespace, or class. And the struct will be named TypeS. This can typically be -# useful for C code in case the coding convention dictates that all compound -# types are typedef'ed and only the typedef is referenced, never the tag name. -# The default value is: NO. - -TYPEDEF_HIDES_STRUCT = NO - -# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This -# cache is used to resolve symbols given their name and scope. Since this can be -# an expensive process and often the same symbol appears multiple times in the -# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small -# doxygen will become slower. If the cache is too large, memory is wasted. The -# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range -# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 -# symbols. At the end of a run doxygen will report the cache usage and suggest -# the optimal cache size from a speed point of view. -# Minimum value: 0, maximum value: 9, default value: 0. - -LOOKUP_CACHE_SIZE = 0 - -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- - -# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in -# documentation are documented, even if no documentation was available. Private -# class members and static file members will be hidden unless the -# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. -# Note: This will also disable the warnings about undocumented members that are -# normally produced when WARNINGS is set to YES. -# The default value is: NO. - -EXTRACT_ALL = YES - -# If the EXTRACT_PRIVATE tag is set to YES all private members of a class will -# be included in the documentation. -# The default value is: NO. - -EXTRACT_PRIVATE = NO - -# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal -# scope will be included in the documentation. -# The default value is: NO. - -EXTRACT_PACKAGE = NO - -# If the EXTRACT_STATIC tag is set to YES all static members of a file will be -# included in the documentation. -# The default value is: NO. - -EXTRACT_STATIC = YES - -# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) defined -# locally in source files will be included in the documentation. If set to NO -# only classes defined in header files are included. Does not have any effect -# for Java sources. -# The default value is: YES. - -EXTRACT_LOCAL_CLASSES = YES - -# This flag is only useful for Objective-C code. When set to YES local methods, -# which are defined in the implementation section but not in the interface are -# included in the documentation. If set to NO only methods in the interface are -# included. -# The default value is: NO. - -EXTRACT_LOCAL_METHODS = NO - -# If this flag is set to YES, the members of anonymous namespaces will be -# extracted and appear in the documentation as a namespace called -# 'anonymous_namespace{file}', where file will be replaced with the base name of -# the file that contains the anonymous namespace. By default anonymous namespace -# are hidden. -# The default value is: NO. - -EXTRACT_ANON_NSPACES = NO - -# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all -# undocumented members inside documented classes or files. If set to NO these -# members will be included in the various overviews, but no documentation -# section is generated. This option has no effect if EXTRACT_ALL is enabled. -# The default value is: NO. - -HIDE_UNDOC_MEMBERS = NO - -# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all -# undocumented classes that are normally visible in the class hierarchy. If set -# to NO these classes will be included in the various overviews. This option has -# no effect if EXTRACT_ALL is enabled. -# The default value is: NO. - -HIDE_UNDOC_CLASSES = NO - -# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend -# (class|struct|union) declarations. If set to NO these declarations will be -# included in the documentation. -# The default value is: NO. - -HIDE_FRIEND_COMPOUNDS = NO - -# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any -# documentation blocks found inside the body of a function. If set to NO these -# blocks will be appended to the function's detailed documentation block. -# The default value is: NO. - -HIDE_IN_BODY_DOCS = NO - -# The INTERNAL_DOCS tag determines if documentation that is typed after a -# \internal command is included. If the tag is set to NO then the documentation -# will be excluded. Set it to YES to include the internal documentation. -# The default value is: NO. - -INTERNAL_DOCS = NO - -# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file -# names in lower-case letters. If set to YES upper-case letters are also -# allowed. This is useful if you have classes or files whose names only differ -# in case and if your file system supports case sensitive file names. Windows -# and Mac users are advised to set this option to NO. -# The default value is: system dependent. - -CASE_SENSE_NAMES = YES - -# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with -# their full class and namespace scopes in the documentation. If set to YES the -# scope will be hidden. -# The default value is: NO. - -HIDE_SCOPE_NAMES = NO - -# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of -# the files that are included by a file in the documentation of that file. -# The default value is: YES. - -SHOW_INCLUDE_FILES = YES - -# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each -# grouped member an include statement to the documentation, telling the reader -# which file to include in order to use the member. -# The default value is: NO. - -SHOW_GROUPED_MEMB_INC = NO - -# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include -# files with double quotes in the documentation rather than with sharp brackets. -# The default value is: NO. - -FORCE_LOCAL_INCLUDES = NO - -# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the -# documentation for inline members. -# The default value is: YES. - -INLINE_INFO = YES - -# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the -# (detailed) documentation of file and class members alphabetically by member -# name. If set to NO the members will appear in declaration order. -# The default value is: YES. - -SORT_MEMBER_DOCS = NO - -# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief -# descriptions of file, namespace and class members alphabetically by member -# name. If set to NO the members will appear in declaration order. Note that -# this will also influence the order of the classes in the class list. -# The default value is: NO. - -SORT_BRIEF_DOCS = NO - -# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the -# (brief and detailed) documentation of class members so that constructors and -# destructors are listed first. If set to NO the constructors will appear in the -# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. -# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief -# member documentation. -# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting -# detailed member documentation. -# The default value is: NO. - -SORT_MEMBERS_CTORS_1ST = NO - -# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy -# of group names into alphabetical order. If set to NO the group names will -# appear in their defined order. -# The default value is: NO. - -SORT_GROUP_NAMES = NO - -# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by -# fully-qualified names, including namespaces. If set to NO, the class list will -# be sorted only by class name, not including the namespace part. -# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. -# Note: This option applies only to the class list, not to the alphabetical -# list. -# The default value is: NO. - -SORT_BY_SCOPE_NAME = NO - -# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper -# type resolution of all parameters of a function it will reject a match between -# the prototype and the implementation of a member function even if there is -# only one candidate or it is obvious which candidate to choose by doing a -# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still -# accept a match between prototype and implementation in such cases. -# The default value is: NO. - -STRICT_PROTO_MATCHING = NO - -# The GENERATE_TODOLIST tag can be used to enable ( YES) or disable ( NO) the -# todo list. This list is created by putting \todo commands in the -# documentation. -# The default value is: YES. - -GENERATE_TODOLIST = YES - -# The GENERATE_TESTLIST tag can be used to enable ( YES) or disable ( NO) the -# test list. This list is created by putting \test commands in the -# documentation. -# The default value is: YES. - -GENERATE_TESTLIST = YES - -# The GENERATE_BUGLIST tag can be used to enable ( YES) or disable ( NO) the bug -# list. This list is created by putting \bug commands in the documentation. -# The default value is: YES. - -GENERATE_BUGLIST = YES - -# The GENERATE_DEPRECATEDLIST tag can be used to enable ( YES) or disable ( NO) -# the deprecated list. This list is created by putting \deprecated commands in -# the documentation. -# The default value is: YES. - -GENERATE_DEPRECATEDLIST= YES - -# The ENABLED_SECTIONS tag can be used to enable conditional documentation -# sections, marked by \if ... \endif and \cond -# ... \endcond blocks. - -ENABLED_SECTIONS = - -# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the -# initial value of a variable or macro / define can have for it to appear in the -# documentation. If the initializer consists of more lines than specified here -# it will be hidden. Use a value of 0 to hide initializers completely. The -# appearance of the value of individual variables and macros / defines can be -# controlled using \showinitializer or \hideinitializer command in the -# documentation regardless of this setting. -# Minimum value: 0, maximum value: 10000, default value: 30. - -MAX_INITIALIZER_LINES = 30 - -# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at -# the bottom of the documentation of classes and structs. If set to YES the list -# will mention the files that were used to generate the documentation. -# The default value is: YES. - -SHOW_USED_FILES = YES - -# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This -# will remove the Files entry from the Quick Index and from the Folder Tree View -# (if specified). -# The default value is: YES. - -SHOW_FILES = YES - -# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces -# page. This will remove the Namespaces entry from the Quick Index and from the -# Folder Tree View (if specified). -# The default value is: YES. - -SHOW_NAMESPACES = YES - -# The FILE_VERSION_FILTER tag can be used to specify a program or script that -# doxygen should invoke to get the current version for each file (typically from -# the version control system). Doxygen will invoke the program by executing (via -# popen()) the command command input-file, where command is the value of the -# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided -# by doxygen. Whatever the program writes to standard output is used as the file -# version. For an example see the documentation. - -FILE_VERSION_FILTER = - -# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed -# by doxygen. The layout file controls the global structure of the generated -# output files in an output format independent way. To create the layout file -# that represents doxygen's defaults, run doxygen with the -l option. You can -# optionally specify a file name after the option, if omitted DoxygenLayout.xml -# will be used as the name of the layout file. -# -# Note that if you run doxygen from a directory containing a file called -# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE -# tag is left empty. - -LAYOUT_FILE = - -# The CITE_BIB_FILES tag can be used to specify one or more bib files containing -# the reference definitions. This must be a list of .bib files. The .bib -# extension is automatically appended if omitted. This requires the bibtex tool -# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. -# For LaTeX the style of the bibliography can be controlled using -# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the -# search path. Do not use file names with spaces, bibtex cannot handle them. See -# also \cite for info how to create references. - -CITE_BIB_FILES = - -#--------------------------------------------------------------------------- -# Configuration options related to warning and progress messages -#--------------------------------------------------------------------------- - -# The QUIET tag can be used to turn on/off the messages that are generated to -# standard output by doxygen. If QUIET is set to YES this implies that the -# messages are off. -# The default value is: NO. - -QUIET = NO - -# The WARNINGS tag can be used to turn on/off the warning messages that are -# generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES -# this implies that the warnings are on. -# -# Tip: Turn warnings on while writing the documentation. -# The default value is: YES. - -WARNINGS = YES - -# If the WARN_IF_UNDOCUMENTED tag is set to YES, then doxygen will generate -# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag -# will automatically be disabled. -# The default value is: YES. - -WARN_IF_UNDOCUMENTED = YES - -# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for -# potential errors in the documentation, such as not documenting some parameters -# in a documented function, or documenting parameters that don't exist or using -# markup commands wrongly. -# The default value is: YES. - -WARN_IF_DOC_ERROR = YES - -# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that -# are documented, but have no documentation for their parameters or return -# value. If set to NO doxygen will only warn about wrong or incomplete parameter -# documentation, but not about the absence of documentation. -# The default value is: NO. - -WARN_NO_PARAMDOC = YES - -# The WARN_FORMAT tag determines the format of the warning messages that doxygen -# can produce. The string should contain the $file, $line, and $text tags, which -# will be replaced by the file and line number from which the warning originated -# and the warning text. Optionally the format may contain $version, which will -# be replaced by the version of the file (if it could be obtained via -# FILE_VERSION_FILTER) -# The default value is: $file:$line: $text. - -WARN_FORMAT = "$file:$line: $text " - -# The WARN_LOGFILE tag can be used to specify a file to which warning and error -# messages should be written. If left blank the output is written to standard -# error (stderr). - -WARN_LOGFILE = doxygen.log - -#--------------------------------------------------------------------------- -# Configuration options related to the input files -#--------------------------------------------------------------------------- - -# The INPUT tag is used to specify the files and/or directories that contain -# documented source files. You may enter file names like myfile.cpp or -# directories like /usr/src/myproject. Separate the files or directories with -# spaces. -# Note: If this tag is empty the current directory is searched. - -INPUT = @CMAKE_CURRENT_SOURCE_DIR@/src \ - @CMAKE_CURRENT_SOURCE_DIR@/include \ - @CMAKE_CURRENT_BINARY_DIR@/include - -# This tag can be used to specify the character encoding of the source files -# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses -# libiconv (or the iconv built into libc) for the transcoding. See the libiconv -# documentation (see: http://www.gnu.org/software/libiconv) for the list of -# possible encodings. -# The default value is: UTF-8. - -INPUT_ENCODING = UTF-8 - -# If the value of the INPUT tag contains directories, you can use the -# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and -# *.h) to filter out the source-files in the directories. If left blank the -# following patterns are tested:*.c, *.cc, *.cxx, *.cpp, *.c++, *.java, *.ii, -# *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp, -# *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown, -# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf, -# *.qsf, *.as and *.js. - -FILE_PATTERNS = *.c \ - *.h - -# The RECURSIVE tag can be used to specify whether or not subdirectories should -# be searched for input files as well. -# The default value is: NO. - -RECURSIVE = YES - -# The EXCLUDE tag can be used to specify files and/or directories that should be -# excluded from the INPUT source files. This way you can easily exclude a -# subdirectory from a directory tree whose root is specified with the INPUT tag. -# -# Note that relative paths are relative to the directory from which doxygen is -# run. - -EXCLUDE = @CMAKE_CURRENT_SOURCE_DIR@/src/low - -# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or -# directories that are symbolic links (a Unix file system feature) are excluded -# from the input. -# The default value is: NO. - -EXCLUDE_SYMLINKS = NO - -# If the value of the INPUT tag contains directories, you can use the -# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude -# certain files from those directories. -# -# Note that the wildcards are matched against the file with absolute path, so to -# exclude all test directories for example use the pattern */test/* - -EXCLUDE_PATTERNS = - -# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names -# (namespaces, classes, functions, etc.) that should be excluded from the -# output. The symbol name can be a fully qualified name, a word, or if the -# wildcard * is used, a substring. Examples: ANamespace, AClass, -# AClass::ANamespace, ANamespace::*Test -# -# Note that the wildcards are matched against the file with absolute path, so to -# exclude all test directories use the pattern */test/* - -EXCLUDE_SYMBOLS = - -# The EXAMPLE_PATH tag can be used to specify one or more files or directories -# that contain example code fragments that are included (see the \include -# command). - -EXAMPLE_PATH = - -# If the value of the EXAMPLE_PATH tag contains directories, you can use the -# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and -# *.h) to filter out the source-files in the directories. If left blank all -# files are included. - -EXAMPLE_PATTERNS = - -# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be -# searched for input files to be used with the \include or \dontinclude commands -# irrespective of the value of the RECURSIVE tag. -# The default value is: NO. - -EXAMPLE_RECURSIVE = NO - -# The IMAGE_PATH tag can be used to specify one or more files or directories -# that contain images that are to be included in the documentation (see the -# \image command). - -IMAGE_PATH = - -# The INPUT_FILTER tag can be used to specify a program that doxygen should -# invoke to filter for each input file. Doxygen will invoke the filter program -# by executing (via popen()) the command: -# -# -# -# where is the value of the INPUT_FILTER tag, and is the -# name of an input file. Doxygen will then use the output that the filter -# program writes to standard output. If FILTER_PATTERNS is specified, this tag -# will be ignored. -# -# Note that the filter must not add or remove lines; it is applied before the -# code is scanned, but not when the output code is generated. If lines are added -# or removed, the anchors will not be placed correctly. - -INPUT_FILTER = - -# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern -# basis. Doxygen will compare the file name with each pattern and apply the -# filter if there is a match. The filters are a list of the form: pattern=filter -# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how -# filters are used. If the FILTER_PATTERNS tag is empty or if none of the -# patterns match the file name, INPUT_FILTER is applied. - -FILTER_PATTERNS = - -# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using -# INPUT_FILTER ) will also be used to filter the input files that are used for -# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). -# The default value is: NO. - -FILTER_SOURCE_FILES = NO - -# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file -# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and -# it is also possible to disable source filtering for a specific pattern using -# *.ext= (so without naming a filter). -# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. - -FILTER_SOURCE_PATTERNS = - -# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that -# is part of the input, its contents will be placed on the main page -# (index.html). This can be useful if you have a project on for instance GitHub -# and want to reuse the introduction page also for the doxygen output. - -USE_MDFILE_AS_MAINPAGE = - -#--------------------------------------------------------------------------- -# Configuration options related to source browsing -#--------------------------------------------------------------------------- - -# If the SOURCE_BROWSER tag is set to YES then a list of source files will be -# generated. Documented entities will be cross-referenced with these sources. -# -# Note: To get rid of all source code in the generated output, make sure that -# also VERBATIM_HEADERS is set to NO. -# The default value is: NO. - -SOURCE_BROWSER = YES - -# Setting the INLINE_SOURCES tag to YES will include the body of functions, -# classes and enums directly into the documentation. -# The default value is: NO. - -INLINE_SOURCES = NO - -# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any -# special comment blocks from generated source code fragments. Normal C, C++ and -# Fortran comments will always remain visible. -# The default value is: YES. - -STRIP_CODE_COMMENTS = YES - -# If the REFERENCED_BY_RELATION tag is set to YES then for each documented -# function all documented functions referencing it will be listed. -# The default value is: NO. - -REFERENCED_BY_RELATION = YES - -# If the REFERENCES_RELATION tag is set to YES then for each documented function -# all documented entities called/used by that function will be listed. -# The default value is: NO. - -REFERENCES_RELATION = YES - -# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set -# to YES, then the hyperlinks from functions in REFERENCES_RELATION and -# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will -# link to the documentation. -# The default value is: YES. - -REFERENCES_LINK_SOURCE = YES - -# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the -# source code will show a tooltip with additional information such as prototype, -# brief description and links to the definition and documentation. Since this -# will make the HTML file larger and loading of large files a bit slower, you -# can opt to disable this feature. -# The default value is: YES. -# This tag requires that the tag SOURCE_BROWSER is set to YES. - -SOURCE_TOOLTIPS = YES - -# If the USE_HTAGS tag is set to YES then the references to source code will -# point to the HTML generated by the htags(1) tool instead of doxygen built-in -# source browser. The htags tool is part of GNU's global source tagging system -# (see http://www.gnu.org/software/global/global.html). You will need version -# 4.8.6 or higher. -# -# To use it do the following: -# - Install the latest version of global -# - Enable SOURCE_BROWSER and USE_HTAGS in the config file -# - Make sure the INPUT points to the root of the source tree -# - Run doxygen as normal -# -# Doxygen will invoke htags (and that will in turn invoke gtags), so these -# tools must be available from the command line (i.e. in the search path). -# -# The result: instead of the source browser generated by doxygen, the links to -# source code will now point to the output of htags. -# The default value is: NO. -# This tag requires that the tag SOURCE_BROWSER is set to YES. - -USE_HTAGS = NO - -# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a -# verbatim copy of the header file for each class for which an include is -# specified. Set to NO to disable this. -# See also: Section \class. -# The default value is: YES. - -VERBATIM_HEADERS = YES - -#--------------------------------------------------------------------------- -# Configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- - -# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all -# compounds will be generated. Enable this if the project contains a lot of -# classes, structs, unions or interfaces. -# The default value is: YES. - -ALPHABETICAL_INDEX = NO - -# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in -# which the alphabetical index list will be split. -# Minimum value: 1, maximum value: 20, default value: 5. -# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. - -COLS_IN_ALPHA_INDEX = 5 - -# In case all classes in a project start with a common prefix, all classes will -# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag -# can be used to specify a prefix (or a list of prefixes) that should be ignored -# while generating the index headers. -# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. - -IGNORE_PREFIX = - -#--------------------------------------------------------------------------- -# Configuration options related to the HTML output -#--------------------------------------------------------------------------- - -# If the GENERATE_HTML tag is set to YES doxygen will generate HTML output -# The default value is: YES. - -GENERATE_HTML = YES - -# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a -# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of -# it. -# The default directory is: html. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_OUTPUT = html - -# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each -# generated HTML page (for example: .htm, .php, .asp). -# The default value is: .html. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_FILE_EXTENSION = .html - -# The HTML_HEADER tag can be used to specify a user-defined HTML header file for -# each generated HTML page. If the tag is left blank doxygen will generate a -# standard header. -# -# To get valid HTML the header file that includes any scripts and style sheets -# that doxygen needs, which is dependent on the configuration options used (e.g. -# the setting GENERATE_TREEVIEW). It is highly recommended to start with a -# default header using -# doxygen -w html new_header.html new_footer.html new_stylesheet.css -# YourConfigFile -# and then modify the file new_header.html. See also section "Doxygen usage" -# for information on how to generate the default header that doxygen normally -# uses. -# Note: The header is subject to change so you typically have to regenerate the -# default header when upgrading to a newer version of doxygen. For a description -# of the possible markers and block names see the documentation. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_HEADER = - -# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each -# generated HTML page. If the tag is left blank doxygen will generate a standard -# footer. See HTML_HEADER for more information on how to generate a default -# footer and what special commands can be used inside the footer. See also -# section "Doxygen usage" for information on how to generate the default footer -# that doxygen normally uses. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_FOOTER = - -# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style -# sheet that is used by each HTML page. It can be used to fine-tune the look of -# the HTML output. If left blank doxygen will generate a default style sheet. -# See also section "Doxygen usage" for information on how to generate the style -# sheet that doxygen normally uses. -# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as -# it is more robust and this tag (HTML_STYLESHEET) will in the future become -# obsolete. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_STYLESHEET = - -# The HTML_EXTRA_STYLESHEET tag can be used to specify an additional user- -# defined cascading style sheet that is included after the standard style sheets -# created by doxygen. Using this option one can overrule certain style aspects. -# This is preferred over using HTML_STYLESHEET since it does not replace the -# standard style sheet and is therefor more robust against future updates. -# Doxygen will copy the style sheet file to the output directory. For an example -# see the documentation. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_EXTRA_STYLESHEET = - -# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or -# other source files which should be copied to the HTML output directory. Note -# that these files will be copied to the base HTML output directory. Use the -# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these -# files. In the HTML_STYLESHEET file, use the file name only. Also note that the -# files will be copied as-is; there are no commands or markers available. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_EXTRA_FILES = - -# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen -# will adjust the colors in the stylesheet and background images according to -# this color. Hue is specified as an angle on a colorwheel, see -# http://en.wikipedia.org/wiki/Hue for more information. For instance the value -# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 -# purple, and 360 is red again. -# Minimum value: 0, maximum value: 359, default value: 220. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_HUE = 220 - -# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors -# in the HTML output. For a value of 0 the output will use grayscales only. A -# value of 255 will produce the most vivid colors. -# Minimum value: 0, maximum value: 255, default value: 100. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_SAT = 100 - -# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the -# luminance component of the colors in the HTML output. Values below 100 -# gradually make the output lighter, whereas values above 100 make the output -# darker. The value divided by 100 is the actual gamma applied, so 80 represents -# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not -# change the gamma. -# Minimum value: 40, maximum value: 240, default value: 80. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_GAMMA = 80 - -# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML -# page will contain the date and time when the page was generated. Setting this -# to NO can help when comparing the output of multiple runs. -# The default value is: YES. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_TIMESTAMP = YES - -# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML -# documentation will contain sections that can be hidden and shown after the -# page has loaded. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_DYNAMIC_SECTIONS = NO - -# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries -# shown in the various tree structured indices initially; the user can expand -# and collapse entries dynamically later on. Doxygen will expand the tree to -# such a level that at most the specified number of entries are visible (unless -# a fully collapsed tree already exceeds this amount). So setting the number of -# entries 1 will produce a full collapsed tree by default. 0 is a special value -# representing an infinite number of entries and will result in a full expanded -# tree by default. -# Minimum value: 0, maximum value: 9999, default value: 100. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_INDEX_NUM_ENTRIES = 100 - -# If the GENERATE_DOCSET tag is set to YES, additional index files will be -# generated that can be used as input for Apple's Xcode 3 integrated development -# environment (see: http://developer.apple.com/tools/xcode/), introduced with -# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a -# Makefile in the HTML output directory. Running make will produce the docset in -# that directory and running make install will install the docset in -# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at -# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html -# for more information. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_DOCSET = @GENERATE_DOCSET@ - -# This tag determines the name of the docset feed. A documentation feed provides -# an umbrella under which multiple documentation sets from a single provider -# (such as a company or product suite) can be grouped. -# The default value is: Doxygen generated docs. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_FEEDNAME = "Doxygen generated docs" - -# This tag specifies a string that should uniquely identify the documentation -# set bundle. This should be a reverse domain-name style string, e.g. -# com.mycompany.MyDocSet. Doxygen will append .docset to the name. -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_BUNDLE_ID = org.doxygen.Project - -# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify -# the documentation publisher. This should be a reverse domain-name style -# string, e.g. com.mycompany.MyDocSet.documentation. -# The default value is: org.doxygen.Publisher. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_PUBLISHER_ID = org.doxygen.Publisher - -# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. -# The default value is: Publisher. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_PUBLISHER_NAME = Publisher - -# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three -# additional HTML index files: index.hhp, index.hhc, and index.hhk. The -# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop -# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on -# Windows. -# -# The HTML Help Workshop contains a compiler that can convert all HTML output -# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML -# files are now used as the Windows 98 help format, and will replace the old -# Windows help format (.hlp) on all Windows platforms in the future. Compressed -# HTML files also contain an index, a table of contents, and you can search for -# words in the documentation. The HTML workshop also contains a viewer for -# compressed HTML files. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_HTMLHELP = NO - -# The CHM_FILE tag can be used to specify the file name of the resulting .chm -# file. You can add a path in front of the file if the result should not be -# written to the html output directory. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -CHM_FILE = - -# The HHC_LOCATION tag can be used to specify the location (absolute path -# including file name) of the HTML help compiler ( hhc.exe). If non-empty -# doxygen will try to run the HTML help compiler on the generated index.hhp. -# The file has to be specified with full path. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -HHC_LOCATION = - -# The GENERATE_CHI flag controls if a separate .chi index file is generated ( -# YES) or that it should be included in the master .chm file ( NO). -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -GENERATE_CHI = NO - -# The CHM_INDEX_ENCODING is used to encode HtmlHelp index ( hhk), content ( hhc) -# and project file content. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -CHM_INDEX_ENCODING = - -# The BINARY_TOC flag controls whether a binary table of contents is generated ( -# YES) or a normal table of contents ( NO) in the .chm file. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -BINARY_TOC = NO - -# The TOC_EXPAND flag can be set to YES to add extra items for group members to -# the table of contents of the HTML help documentation and to the tree view. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -TOC_EXPAND = NO - -# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and -# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that -# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help -# (.qch) of the generated HTML documentation. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_QHP = NO - -# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify -# the file name of the resulting .qch file. The path specified is relative to -# the HTML output folder. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QCH_FILE = - -# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help -# Project output. For more information please see Qt Help Project / Namespace -# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_NAMESPACE = org.doxygen.Project - -# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt -# Help Project output. For more information please see Qt Help Project / Virtual -# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- -# folders). -# The default value is: doc. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_VIRTUAL_FOLDER = doc - -# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom -# filter to add. For more information please see Qt Help Project / Custom -# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- -# filters). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_CUST_FILTER_NAME = - -# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the -# custom filter to add. For more information please see Qt Help Project / Custom -# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- -# filters). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_CUST_FILTER_ATTRS = - -# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this -# project's filter section matches. Qt Help Project / Filter Attributes (see: -# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_SECT_FILTER_ATTRS = - -# The QHG_LOCATION tag can be used to specify the location of Qt's -# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the -# generated .qhp file. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHG_LOCATION = - -# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be -# generated, together with the HTML files, they form an Eclipse help plugin. To -# install this plugin and make it available under the help contents menu in -# Eclipse, the contents of the directory containing the HTML and XML files needs -# to be copied into the plugins directory of eclipse. The name of the directory -# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. -# After copying Eclipse needs to be restarted before the help appears. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_ECLIPSEHELP = NO - -# A unique identifier for the Eclipse help plugin. When installing the plugin -# the directory name containing the HTML and XML files should also have this -# name. Each documentation set should have its own identifier. -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. - -ECLIPSE_DOC_ID = org.doxygen.Project - -# If you want full control over the layout of the generated HTML pages it might -# be necessary to disable the index and replace it with your own. The -# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top -# of each HTML page. A value of NO enables the index and the value YES disables -# it. Since the tabs in the index contain the same information as the navigation -# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -DISABLE_INDEX = NO - -# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index -# structure should be generated to display hierarchical information. If the tag -# value is set to YES, a side panel will be generated containing a tree-like -# index structure (just like the one that is generated for HTML Help). For this -# to work a browser that supports JavaScript, DHTML, CSS and frames is required -# (i.e. any modern browser). Windows users are probably better off using the -# HTML help feature. Via custom stylesheets (see HTML_EXTRA_STYLESHEET) one can -# further fine-tune the look of the index. As an example, the default style -# sheet generated by doxygen has an example that shows how to put an image at -# the root of the tree instead of the PROJECT_NAME. Since the tree basically has -# the same information as the tab index, you could consider setting -# DISABLE_INDEX to YES when enabling this option. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_TREEVIEW = NO - -# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that -# doxygen will group on one line in the generated HTML documentation. -# -# Note that a value of 0 will completely suppress the enum values from appearing -# in the overview section. -# Minimum value: 0, maximum value: 20, default value: 4. -# This tag requires that the tag GENERATE_HTML is set to YES. - -ENUM_VALUES_PER_LINE = 4 - -# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used -# to set the initial width (in pixels) of the frame in which the tree is shown. -# Minimum value: 0, maximum value: 1500, default value: 250. -# This tag requires that the tag GENERATE_HTML is set to YES. - -TREEVIEW_WIDTH = 250 - -# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open links to -# external symbols imported via tag files in a separate window. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -EXT_LINKS_IN_WINDOW = NO - -# Use this tag to change the font size of LaTeX formulas included as images in -# the HTML documentation. When you change the font size after a successful -# doxygen run you need to manually remove any form_*.png images from the HTML -# output directory to force them to be regenerated. -# Minimum value: 8, maximum value: 50, default value: 10. -# This tag requires that the tag GENERATE_HTML is set to YES. - -FORMULA_FONTSIZE = 10 - -# Use the FORMULA_TRANPARENT tag to determine whether or not the images -# generated for formulas are transparent PNGs. Transparent PNGs are not -# supported properly for IE 6.0, but are supported on all modern browsers. -# -# Note that when changing this option you need to delete any form_*.png files in -# the HTML output directory before the changes have effect. -# The default value is: YES. -# This tag requires that the tag GENERATE_HTML is set to YES. - -FORMULA_TRANSPARENT = YES - -# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see -# http://www.mathjax.org) which uses client side Javascript for the rendering -# instead of using prerendered bitmaps. Use this if you do not have LaTeX -# installed or if you want to formulas look prettier in the HTML output. When -# enabled you may also need to install MathJax separately and configure the path -# to it using the MATHJAX_RELPATH option. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -USE_MATHJAX = NO - -# When MathJax is enabled you can set the default output format to be used for -# the MathJax output. See the MathJax site (see: -# http://docs.mathjax.org/en/latest/output.html) for more details. -# Possible values are: HTML-CSS (which is slower, but has the best -# compatibility), NativeMML (i.e. MathML) and SVG. -# The default value is: HTML-CSS. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_FORMAT = HTML-CSS - -# When MathJax is enabled you need to specify the location relative to the HTML -# output directory using the MATHJAX_RELPATH option. The destination directory -# should contain the MathJax.js script. For instance, if the mathjax directory -# is located at the same level as the HTML output directory, then -# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax -# Content Delivery Network so you can quickly see the result without installing -# MathJax. However, it is strongly recommended to install a local copy of -# MathJax from http://www.mathjax.org before deployment. -# The default value is: http://cdn.mathjax.org/mathjax/latest. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest - -# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax -# extension names that should be enabled during MathJax rendering. For example -# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_EXTENSIONS = - -# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces -# of code that will be used on startup of the MathJax code. See the MathJax site -# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an -# example see the documentation. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_CODEFILE = - -# When the SEARCHENGINE tag is enabled doxygen will generate a search box for -# the HTML output. The underlying search engine uses javascript and DHTML and -# should work on any modern browser. Note that when using HTML help -# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) -# there is already a search function so this one should typically be disabled. -# For large projects the javascript based search engine can be slow, then -# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to -# search using the keyboard; to jump to the search box use + S -# (what the is depends on the OS and browser, but it is typically -# , /