diff --git a/Cargo.toml b/Cargo.toml index d70be090..91c51ae8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "secp256k1-zkp" -version = "0.10.1" +version = "0.11.0" authors = [ "Dawid Ciężarkiewicz ", "Andrew Poelstra ", "Lucas Soriano ", @@ -34,7 +34,7 @@ rand = ["actual-rand", "secp256k1/rand"] actual-serde = { package = "serde", version = "1.0", default-features = false, optional = true } actual-rand = { package = "rand", version = "0.8", default-features = false, optional = true } secp256k1 = "0.29.0" -secp256k1-zkp-sys = { version = "0.9.0", default-features = false, path = "./secp256k1-zkp-sys" } +secp256k1-zkp-sys = { version = "0.10.0", default-features = false, path = "./secp256k1-zkp-sys" } internals = { package = "bitcoin-private", version = "0.1.0" } [dev-dependencies] diff --git a/secp256k1-zkp-sys/Cargo.toml b/secp256k1-zkp-sys/Cargo.toml index 7d312ce6..fc00ef88 100644 --- a/secp256k1-zkp-sys/Cargo.toml +++ b/secp256k1-zkp-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "secp256k1-zkp-sys" -version = "0.9.1" +version = "0.10.0" authors = [ "Dawid Ciężarkiewicz ", "Andrew Poelstra ", "Steven Roose ", @@ -13,7 +13,7 @@ description = "FFI for `libsecp256k1-zkp` library." keywords = [ "secp256k1", "libsecp256k1-zkp", "ffi" ] readme = "README.md" build = "build.rs" -links = "rustsecp256k1zkp_v0_8_0" +links = "rustsecp256k1zkp_v0_10_0" # Should make docs.rs show all functions, even those behind non-default features [package.metadata.docs.rs] diff --git a/secp256k1-zkp-sys/depend/secp256k1-HEAD-revision.txt b/secp256k1-zkp-sys/depend/secp256k1-HEAD-revision.txt index 076dc9cd..3cc9fed5 100644 --- a/secp256k1-zkp-sys/depend/secp256k1-HEAD-revision.txt +++ b/secp256k1-zkp-sys/depend/secp256k1-HEAD-revision.txt @@ -1,2 +1,2 @@ # This file was automatically created by vendor-libsecp.sh -1d256089004a19bdbead7c5676e52c8e07b09fce +6152622613fdf1c5af6f31f74c427c4e9ee120ce diff --git a/secp256k1-zkp-sys/depend/secp256k1/.cirrus.yml b/secp256k1-zkp-sys/depend/secp256k1/.cirrus.yml index 48c9be8c..04aa8f24 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/.cirrus.yml +++ b/secp256k1-zkp-sys/depend/secp256k1/.cirrus.yml @@ -1,6 +1,9 @@ env: + ### cirrus config + CIRRUS_CLONE_DEPTH: 1 ### compiler options HOST: + WRAPPER_CMD: # Specific warnings can be disabled with -Wno-error=foo. # -pedantic-errors is not equivalent to -Werror=pedantic and thus not implied by -Werror according to the GCC manual. WERROR_CFLAGS: -Werror -pedantic-errors @@ -14,21 +17,16 @@ env: WITH_VALGRIND: yes EXTRAFLAGS: ### secp256k1 modules + EXPERIMENTAL: no ECDH: no RECOVERY: no SCHNORRSIG: no - ECDSA_S2C: no - GENERATOR: no - RANGEPROOF: no - WHITELIST: no - MUSIG: no - ECDSAADAPTOR: no - BPPP: no + ELLSWIFT: no ### test options SECP256K1_TEST_ITERS: BENCH: yes SECP256K1_BENCH_ITERS: 2 - CTIMETEST: yes + CTIMETESTS: yes # Compile and run the tests EXAMPLES: yes @@ -36,13 +34,14 @@ cat_logs_snippet: &CAT_LOGS always: cat_tests_log_script: - cat tests.log || true + cat_noverify_tests_log_script: + - cat noverify_tests.log || true cat_exhaustive_tests_log_script: - cat exhaustive_tests.log || true - cat_valgrind_ctime_test_log_script: - - cat valgrind_ctime_test.log || true + cat_ctime_tests_log_script: + - cat ctime_tests.log || true cat_bench_log_script: - cat bench.log || true - on_failure: cat_config_log_script: - cat config.log || true cat_test_env_script: @@ -50,276 +49,47 @@ cat_logs_snippet: &CAT_LOGS cat_ci_env_script: - env -merge_base_script_snippet: &MERGE_BASE - merge_base_script: - - if [ "$CIRRUS_PR" = "" ]; then exit 0; fi - - git fetch $CIRRUS_REPO_CLONE_URL $CIRRUS_BASE_BRANCH - - git config --global user.email "ci@ci.ci" - - git config --global user.name "ci" - - git merge FETCH_HEAD # Merge base to detect silent merge conflicts - -linux_container_snippet: &LINUX_CONTAINER - container: - dockerfile: ci/linux-debian.Dockerfile - # Reduce number of CPUs to be able to do more builds in parallel. - cpu: 1 - # Gives us more CPUs for free if they're available. - greedy: true - # More than enough for our scripts. - memory: 1G - -task: - name: "x86_64: Linux (Debian stable)" - << : *LINUX_CONTAINER - matrix: &ENV_MATRIX - - env: {WIDEMUL: int64, RECOVERY: yes} - - env: {WIDEMUL: int64, ECDH: yes, SCHNORRSIG: yes, EXPERIMENTAL: yes, ECDSA_S2C: yes, RANGEPROOF: yes, WHITELIST: yes, GENERATOR: yes, MUSIG: yes, ECDSAADAPTOR: yes, BPPP: yes} - - env: {WIDEMUL: int128} - - env: {WIDEMUL: int128, RECOVERY: yes, SCHNORRSIG: yes} - - env: {WIDEMUL: int128, ECDH: yes, SCHNORRSIG: yes, EXPERIMENTAL: yes, ECDSA_S2C: yes, RANGEPROOF: yes, WHITELIST: yes, GENERATOR: yes, MUSIG: yes, ECDSAADAPTOR: yes, BPPP: yes} - - env: {WIDEMUL: int128, ASM: x86_64} - - env: { RECOVERY: yes, SCHNORRSIG: yes, EXPERIMENTAL: yes, ECDSA_S2C: yes, RANGEPROOF: yes, WHITELIST: yes, GENERATOR: yes, MUSIG: yes, ECDSAADAPTOR: yes, BPPP: yes} - - env: {BUILD: distcheck, WITH_VALGRIND: no, CTIMETEST: no, BENCH: no} - - env: {CPPFLAGS: -DDETERMINISTIC} - - env: {CFLAGS: -O0, CTIMETEST: no} - - env: { ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 } - - env: { ECMULTGENPRECISION: 8, ECMULTWINDOW: 4 } - matrix: - - env: - CC: gcc - - env: - CC: clang - << : *MERGE_BASE +linux_arm64_container_snippet: &LINUX_ARM64_CONTAINER + env_script: + - env | tee /tmp/env + build_script: + - DOCKER_BUILDKIT=1 docker build --file "ci/linux-debian.Dockerfile" --tag="ci_secp256k1_arm" + - docker image prune --force # Cleanup stale layers test_script: - - ./ci/cirrus.sh - << : *CAT_LOGS + - docker run --rm --mount "type=bind,src=./,dst=/ci_secp256k1" --env-file /tmp/env --replace --name "ci_secp256k1_arm" "ci_secp256k1_arm" bash -c "cd /ci_secp256k1/ && ./ci/ci.sh" task: - name: "i686: Linux (Debian stable)" - << : *LINUX_CONTAINER + name: "ARM64: Linux (Debian stable)" + persistent_worker: + labels: + type: arm64 env: - HOST: i686-linux-gnu ECDH: yes RECOVERY: yes SCHNORRSIG: yes - EXPERIMENTAL: yes - ECDSA_S2C: yes - RANGEPROOF: yes - WHITELIST: yes - GENERATOR: yes - MUSIG: yes - ECDSAADAPTOR: yes - BPPP: yes - matrix: - - env: - CC: i686-linux-gnu-gcc - - env: - CC: clang --target=i686-pc-linux-gnu -isystem /usr/i686-linux-gnu/include - << : *MERGE_BASE - test_script: - - ./ci/cirrus.sh - << : *CAT_LOGS - -task: - name: "arm64: macOS Ventura" - macos_instance: - image: ghcr.io/cirruslabs/macos-ventura-base:latest - # tasks with valgrind enabled take about 90 minutes - timeout_in: 120m - env: - HOMEBREW_NO_AUTO_UPDATE: 1 - HOMEBREW_NO_INSTALL_CLEANUP: 1 - # Cirrus gives us a fixed number of 4 virtual CPUs. Not that we even have that many jobs at the moment... - MAKEFLAGS: -j5 + ELLSWIFT: yes matrix: - << : *ENV_MATRIX - env: - ASM: no - WITH_VALGRIND: no - CTIMETEST: no - matrix: - - env: - CC: gcc - - env: - CC: clang - brew_script: - - brew install automake libtool gcc - << : *MERGE_BASE - test_script: - - ./ci/cirrus.sh + # Currently only gcc-snapshot, the other compilers are tested on GHA with QEMU + - env: { CC: 'gcc-snapshot' } + << : *LINUX_ARM64_CONTAINER << : *CAT_LOGS task: - name: "s390x (big-endian): Linux (Debian stable, QEMU)" - << : *LINUX_CONTAINER + name: "ARM64: Linux (Debian stable), Valgrind" + persistent_worker: + labels: + type: arm64 env: - WRAPPER_CMD: qemu-s390x - SECP256K1_TEST_ITERS: 16 - HOST: s390x-linux-gnu - WITH_VALGRIND: no ECDH: yes RECOVERY: yes SCHNORRSIG: yes - EXPERIMENTAL: yes - ECDSA_S2C: yes - RANGEPROOF: yes - WHITELIST: yes - GENERATOR: yes - MUSIG: yes - ECDSAADAPTOR: yes - BPPP: yes - CTIMETEST: no - << : *MERGE_BASE - test_script: - # https://sourceware.org/bugzilla/show_bug.cgi?id=27008 - - rm /etc/ld.so.cache - - ./ci/cirrus.sh - << : *CAT_LOGS - -task: - name: "ARM32: Linux (Debian stable, QEMU)" - << : *LINUX_CONTAINER - env: - WRAPPER_CMD: qemu-arm - SECP256K1_TEST_ITERS: 16 - HOST: arm-linux-gnueabihf - WITH_VALGRIND: no - ECDH: yes - RECOVERY: yes - SCHNORRSIG: yes - CTIMETEST: no + ELLSWIFT: yes + WRAPPER_CMD: 'valgrind --error-exitcode=42' + SECP256K1_TEST_ITERS: 2 matrix: - - env: {} - - env: {EXPERIMENTAL: yes, ASM: arm} - << : *MERGE_BASE - test_script: - - ./ci/cirrus.sh + - env: { CC: 'gcc' } + - env: { CC: 'clang' } + - env: { CC: 'gcc-snapshot' } + - env: { CC: 'clang-snapshot' } + << : *LINUX_ARM64_CONTAINER << : *CAT_LOGS - -task: - name: "ARM64: Linux (Debian stable, QEMU)" - << : *LINUX_CONTAINER - env: - WRAPPER_CMD: qemu-aarch64 - SECP256K1_TEST_ITERS: 16 - HOST: aarch64-linux-gnu - WITH_VALGRIND: no - ECDH: yes - RECOVERY: yes - SCHNORRSIG: yes - CTIMETEST: no - << : *MERGE_BASE - test_script: - - ./ci/cirrus.sh - << : *CAT_LOGS - -task: - name: "ppc64le: Linux (Debian stable, QEMU)" - << : *LINUX_CONTAINER - env: - WRAPPER_CMD: qemu-ppc64le - SECP256K1_TEST_ITERS: 16 - HOST: powerpc64le-linux-gnu - WITH_VALGRIND: no - ECDH: yes - RECOVERY: yes - SCHNORRSIG: yes - CTIMETEST: no - << : *MERGE_BASE - test_script: - - ./ci/cirrus.sh - << : *CAT_LOGS - -task: - name: "x86_64 (mingw32-w64): Windows (Debian stable, Wine)" - << : *LINUX_CONTAINER - env: - WRAPPER_CMD: wine64-stable - SECP256K1_TEST_ITERS: 16 - HOST: x86_64-w64-mingw32 - WITH_VALGRIND: no - ECDH: yes - RECOVERY: yes - SCHNORRSIG: yes - CTIMETEST: no - << : *MERGE_BASE - test_script: - - ./ci/cirrus.sh - << : *CAT_LOGS - -# Sanitizers -task: - timeout_in: 120m - << : *LINUX_CONTAINER - env: - ECDH: yes - RECOVERY: yes - SCHNORRSIG: yes - EXPERIMENTAL: yes - ECDSA_S2C: yes - RANGEPROOF: yes - WHITELIST: yes - GENERATOR: yes - MUSIG: yes - ECDSAADAPTOR: yes - BPPP: yes - CTIMETEST: no - matrix: - - name: "Valgrind (memcheck)" - container: - cpu: 2 - env: - # The `--error-exitcode` is required to make the test fail if valgrind found errors, otherwise it'll return 0 (https://www.valgrind.org/docs/manual/manual-core.html) - WRAPPER_CMD: "valgrind --error-exitcode=42" - SECP256K1_TEST_ITERS: 2 - - name: "UBSan, ASan, LSan" - container: - memory: 2G - env: - CFLAGS: "-fsanitize=undefined,address -g" - UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1" - ASAN_OPTIONS: "strict_string_checks=1:detect_stack_use_after_return=1:detect_leaks=1" - LSAN_OPTIONS: "use_unaligned=1" - SECP256K1_TEST_ITERS: 32 - # Try to cover many configurations with just a tiny matrix. - matrix: - - env: - ASM: auto - - env: - ASM: no - ECMULTGENPRECISION: 2 - ECMULTWINDOW: 2 - matrix: - - env: - CC: clang - - env: - HOST: i686-linux-gnu - CC: i686-linux-gnu-gcc - << : *MERGE_BASE - test_script: - - ./ci/cirrus.sh - << : *CAT_LOGS - -task: - name: "C++ -fpermissive" - << : *LINUX_CONTAINER - env: - # ./configure correctly errors out when given CC=g++. - # We hack around this by passing CC=g++ only to make. - CC: gcc - MAKEFLAGS: -j4 CC=g++ CFLAGS=-fpermissive\ -g - WERROR_CFLAGS: - ECDH: yes - RECOVERY: yes - SCHNORRSIG: yes - << : *MERGE_BASE - test_script: - - ./ci/cirrus.sh - << : *CAT_LOGS - -task: - name: "sage prover" - << : *LINUX_CONTAINER - test_script: - - cd sage - - sage prove_group_implementations.sage diff --git a/secp256k1-zkp-sys/depend/secp256k1/.github/actions/install-homebrew-valgrind/action.yml b/secp256k1-zkp-sys/depend/secp256k1/.github/actions/install-homebrew-valgrind/action.yml new file mode 100644 index 00000000..094ff891 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/.github/actions/install-homebrew-valgrind/action.yml @@ -0,0 +1,33 @@ +name: "Install Valgrind" +description: "Install Homebrew's Valgrind package and cache it." +runs: + using: "composite" + steps: + - run: | + brew tap LouisBrunner/valgrind + brew fetch --HEAD LouisBrunner/valgrind/valgrind + echo "CI_HOMEBREW_CELLAR_VALGRIND=$(brew --cellar valgrind)" >> "$GITHUB_ENV" + shell: bash + + - run: | + sw_vers > valgrind_fingerprint + brew --version >> valgrind_fingerprint + git -C "$(brew --cache)/valgrind--git" rev-parse HEAD >> valgrind_fingerprint + cat valgrind_fingerprint + shell: bash + + - uses: actions/cache@v3 + id: cache + with: + path: ${{ env.CI_HOMEBREW_CELLAR_VALGRIND }} + key: ${{ github.job }}-valgrind-${{ hashFiles('valgrind_fingerprint') }} + + - if: steps.cache.outputs.cache-hit != 'true' + run: | + brew install --HEAD LouisBrunner/valgrind/valgrind + shell: bash + + - if: steps.cache.outputs.cache-hit == 'true' + run: | + brew link valgrind + shell: bash diff --git a/secp256k1-zkp-sys/depend/secp256k1/.github/actions/run-in-docker-action/action.yml b/secp256k1-zkp-sys/depend/secp256k1/.github/actions/run-in-docker-action/action.yml new file mode 100644 index 00000000..dbfaa4fe --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/.github/actions/run-in-docker-action/action.yml @@ -0,0 +1,49 @@ +name: 'Run in Docker with environment' +description: 'Run a command in a Docker container, while passing explicitly set environment variables into the container.' +inputs: + dockerfile: + description: 'A Dockerfile that defines an image' + required: true + tag: + description: 'A tag of an image' + required: true + command: + description: 'A command to run in a container' + required: false + default: ./ci/ci.sh +runs: + using: "composite" + steps: + - uses: docker/setup-buildx-action@v3 + + - uses: docker/build-push-action@v5 + id: main_builder + continue-on-error: true + with: + context: . + file: ${{ inputs.dockerfile }} + tags: ${{ inputs.tag }} + load: true + cache-from: type=gha + + - uses: docker/build-push-action@v5 + id: retry_builder + if: steps.main_builder.outcome == 'failure' + with: + context: . + file: ${{ inputs.dockerfile }} + tags: ${{ inputs.tag }} + load: true + cache-from: type=gha + + - # Tell Docker to pass environment variables in `env` into the container. + run: > + docker run \ + $(echo '${{ toJSON(env) }}' | jq -r 'keys[] | "--env \(.) "') \ + --volume ${{ github.workspace }}:${{ github.workspace }} \ + --workdir ${{ github.workspace }} \ + ${{ inputs.tag }} bash -c " + git config --global --add safe.directory ${{ github.workspace }} + ${{ inputs.command }} + " + shell: bash diff --git a/secp256k1-zkp-sys/depend/secp256k1/.github/workflows/ci.yml b/secp256k1-zkp-sys/depend/secp256k1/.github/workflows/ci.yml new file mode 100644 index 00000000..36293f13 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/.github/workflows/ci.yml @@ -0,0 +1,904 @@ +name: CI +on: + pull_request: + push: + branches: + - '**' + tags-ignore: + - '**' + +concurrency: + group: ${{ github.event_name != 'pull_request' && github.run_id || github.ref }} + cancel-in-progress: true + +env: + ### compiler options + HOST: + WRAPPER_CMD: + # Specific warnings can be disabled with -Wno-error=foo. + # -pedantic-errors is not equivalent to -Werror=pedantic and thus not implied by -Werror according to the GCC manual. + WERROR_CFLAGS: '-Werror -pedantic-errors' + MAKEFLAGS: '-j4' + BUILD: 'check' + ### secp256k1 config + ECMULTWINDOW: 'auto' + ECMULTGENPRECISION: 'auto' + ASM: 'no' + WIDEMUL: 'auto' + WITH_VALGRIND: 'yes' + EXTRAFLAGS: + ### secp256k1 modules + EXPERIMENTAL: 'no' + ECDH: 'no' + RECOVERY: 'no' + SCHNORRSIG: 'no' + ELLSWIFT: 'no' + ECDSA_S2C: 'no' + GENERATOR: 'no' + RANGEPROOF: 'no' + WHITELIST: 'no' + MUSIG: 'no' + ECDSAADAPTOR: 'no' + BPPP: 'no' + SCHNORRSIG_HALFAGG: 'no' + ### test options + SECP256K1_TEST_ITERS: + BENCH: 'yes' + SECP256K1_BENCH_ITERS: 2 + CTIMETESTS: 'yes' + # Compile and run the examples. + EXAMPLES: 'yes' + +jobs: + docker_cache: + name: "Build Docker image" + runs-on: ubuntu-latest + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + # See: https://github.com/moby/buildkit/issues/3969. + driver-opts: | + network=host + + - name: Build container + uses: docker/build-push-action@v5 + with: + file: ./ci/linux-debian.Dockerfile + tags: linux-debian-image + cache-from: type=gha + cache-to: type=gha,mode=min + + linux_debian: + name: "x86_64: Linux (Debian stable)" + runs-on: ubuntu-latest + needs: docker_cache + + strategy: + fail-fast: false + matrix: + configuration: + - env_vars: { WIDEMUL: 'int64', RECOVERY: 'yes' } + - env_vars: { WIDEMUL: 'int64', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', SCHNORRSIG_HALFAGG: 'yes'} + - env_vars: { WIDEMUL: 'int128' } + - env_vars: { WIDEMUL: 'int128_struct', ELLSWIFT: 'yes' } + - env_vars: { WIDEMUL: 'int128', RECOVERY: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes' } + - env_vars: { WIDEMUL: 'int128', ECDH: 'yes', SCHNORRSIG: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', SCHNORRSIG_HALFAGG: 'yes'} + - env_vars: { WIDEMUL: 'int128', ASM: 'x86_64', ELLSWIFT: 'yes' } + - env_vars: { RECOVERY: 'yes', SCHNORRSIG: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', SCHNORRSIG_HALFAGG: 'yes'} + - env_vars: { CTIMETESTS: 'no', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', SCHNORRSIG_HALFAGG: 'yes', CPPFLAGS: '-DVERIFY' } + - env_vars: { BUILD: 'distcheck', WITH_VALGRIND: 'no', CTIMETESTS: 'no', BENCH: 'no' } + - env_vars: { CPPFLAGS: '-DDETERMINISTIC' } + - env_vars: { CFLAGS: '-O0', CTIMETESTS: 'no' } + - env_vars: { CFLAGS: '-O1', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes' } + - env_vars: { ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 } + - env_vars: { ECMULTGENPRECISION: 8, ECMULTWINDOW: 4 } + cc: + - 'gcc' + - 'clang' + - 'gcc-snapshot' + - 'clang-snapshot' + + env: + CC: ${{ matrix.cc }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: CI script + env: ${{ matrix.configuration.env_vars }} + uses: ./.github/actions/run-in-docker-action + with: + dockerfile: ./ci/linux-debian.Dockerfile + tag: linux-debian-image + + - run: cat tests.log || true + if: ${{ always() }} + - run: cat noverify_tests.log || true + if: ${{ always() }} + - run: cat exhaustive_tests.log || true + if: ${{ always() }} + - run: cat ctime_tests.log || true + if: ${{ always() }} + - run: cat bench.log || true + if: ${{ always() }} + - run: cat config.log || true + if: ${{ always() }} + - run: cat test_env.log || true + if: ${{ always() }} + - name: CI env + run: env + if: ${{ always() }} + + i686_debian: + name: "i686: Linux (Debian stable)" + runs-on: ubuntu-latest + needs: docker_cache + + strategy: + fail-fast: false + matrix: + cc: + - 'i686-linux-gnu-gcc' + - 'clang --target=i686-pc-linux-gnu -isystem /usr/i686-linux-gnu/include' + + env: + HOST: 'i686-linux-gnu' + ECDH: 'yes' + RECOVERY: 'yes' + SCHNORRSIG: 'yes' + ELLSWIFT: 'yes' + EXPERIMENTAL: 'yes' + ECDSA_S2C: 'yes' + RANGEPROOF: 'yes' + WHITELIST: 'yes' + GENERATOR: 'yes' + MUSIG: 'yes' + ECDSAADAPTOR: 'yes' + BPPP: 'yes' + SCHNORRSIG_HALFAGG: 'yes' + CC: ${{ matrix.cc }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: CI script + uses: ./.github/actions/run-in-docker-action + with: + dockerfile: ./ci/linux-debian.Dockerfile + tag: linux-debian-image + + - run: cat tests.log || true + if: ${{ always() }} + - run: cat noverify_tests.log || true + if: ${{ always() }} + - run: cat exhaustive_tests.log || true + if: ${{ always() }} + - run: cat ctime_tests.log || true + if: ${{ always() }} + - run: cat bench.log || true + if: ${{ always() }} + - run: cat config.log || true + if: ${{ always() }} + - run: cat test_env.log || true + if: ${{ always() }} + - name: CI env + run: env + if: ${{ always() }} + + s390x_debian: + name: "s390x (big-endian): Linux (Debian stable, QEMU)" + runs-on: ubuntu-latest + needs: docker_cache + + env: + WRAPPER_CMD: 'qemu-s390x' + SECP256K1_TEST_ITERS: 16 + HOST: 's390x-linux-gnu' + WITH_VALGRIND: 'no' + ECDH: 'yes' + RECOVERY: 'yes' + SCHNORRSIG: 'yes' + ELLSWIFT: 'yes' + EXPERIMENTAL: 'yes' + ECDSA_S2C: 'yes' + RANGEPROOF: 'yes' + WHITELIST: 'yes' + GENERATOR: 'yes' + MUSIG: 'yes' + ECDSAADAPTOR: 'yes' + BPPP: 'yes' + SCHNORRSIG_HALFAGG: 'yes' + CTIMETESTS: 'no' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: CI script + uses: ./.github/actions/run-in-docker-action + with: + dockerfile: ./ci/linux-debian.Dockerfile + tag: linux-debian-image + + - run: cat tests.log || true + if: ${{ always() }} + - run: cat noverify_tests.log || true + if: ${{ always() }} + - run: cat exhaustive_tests.log || true + if: ${{ always() }} + - run: cat ctime_tests.log || true + if: ${{ always() }} + - run: cat bench.log || true + if: ${{ always() }} + - run: cat config.log || true + if: ${{ always() }} + - run: cat test_env.log || true + if: ${{ always() }} + - name: CI env + run: env + if: ${{ always() }} + + arm32_debian: + name: "ARM32: Linux (Debian stable, QEMU)" + runs-on: ubuntu-latest + needs: docker_cache + + strategy: + fail-fast: false + matrix: + configuration: + - env_vars: {} + - env_vars: { EXPERIMENTAL: 'yes', ASM: 'arm32' } + + env: + WRAPPER_CMD: 'qemu-arm' + SECP256K1_TEST_ITERS: 16 + HOST: 'arm-linux-gnueabihf' + WITH_VALGRIND: 'no' + ECDH: 'yes' + RECOVERY: 'yes' + SCHNORRSIG: 'yes' + ELLSWIFT: 'yes' + EXPERIMENTAL: 'yes' + ECDSA_S2C: 'yes' + GENERATOR: 'yes' + RANGEPROOF: 'yes' + WHITELIST: 'yes' + MUSIG: 'yes' + ECDSAADAPTOR: 'yes' + BPPP: 'yes' + SCHNORRSIG_HALFAGG: 'yes' + CTIMETESTS: 'no' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: CI script + env: ${{ matrix.configuration.env_vars }} + uses: ./.github/actions/run-in-docker-action + with: + dockerfile: ./ci/linux-debian.Dockerfile + tag: linux-debian-image + + - run: cat tests.log || true + if: ${{ always() }} + - run: cat noverify_tests.log || true + if: ${{ always() }} + - run: cat exhaustive_tests.log || true + if: ${{ always() }} + - run: cat ctime_tests.log || true + if: ${{ always() }} + - run: cat bench.log || true + if: ${{ always() }} + - run: cat config.log || true + if: ${{ always() }} + - run: cat test_env.log || true + if: ${{ always() }} + - name: CI env + run: env + if: ${{ always() }} + + arm64_debian: + name: "ARM64: Linux (Debian stable, QEMU)" + runs-on: ubuntu-latest + needs: docker_cache + + env: + WRAPPER_CMD: 'qemu-aarch64' + SECP256K1_TEST_ITERS: 16 + HOST: 'aarch64-linux-gnu' + WITH_VALGRIND: 'no' + ECDH: 'yes' + RECOVERY: 'yes' + SCHNORRSIG: 'yes' + ELLSWIFT: 'yes' + EXPERIMENTAL: 'yes' + ECDSA_S2C: 'yes' + GENERATOR: 'yes' + RANGEPROOF: 'yes' + WHITELIST: 'yes' + MUSIG: 'yes' + ECDSAADAPTOR: 'yes' + BPPP: 'yes' + SCHNORRSIG_HALFAGG: 'yes' + CTIMETESTS: 'no' + + strategy: + fail-fast: false + matrix: + configuration: + - env_vars: { } # gcc + - env_vars: # clang + CC: 'clang --target=aarch64-linux-gnu' + - env_vars: # clang-snapshot + CC: 'clang-snapshot --target=aarch64-linux-gnu' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: CI script + env: ${{ matrix.configuration.env_vars }} + uses: ./.github/actions/run-in-docker-action + with: + dockerfile: ./ci/linux-debian.Dockerfile + tag: linux-debian-image + + - run: cat tests.log || true + if: ${{ always() }} + - run: cat noverify_tests.log || true + if: ${{ always() }} + - run: cat exhaustive_tests.log || true + if: ${{ always() }} + - run: cat ctime_tests.log || true + if: ${{ always() }} + - run: cat bench.log || true + if: ${{ always() }} + - run: cat config.log || true + if: ${{ always() }} + - run: cat test_env.log || true + if: ${{ always() }} + - name: CI env + run: env + if: ${{ always() }} + + ppc64le_debian: + name: "ppc64le: Linux (Debian stable, QEMU)" + runs-on: ubuntu-latest + needs: docker_cache + + env: + WRAPPER_CMD: 'qemu-ppc64le' + SECP256K1_TEST_ITERS: 16 + HOST: 'powerpc64le-linux-gnu' + WITH_VALGRIND: 'no' + ECDH: 'yes' + RECOVERY: 'yes' + SCHNORRSIG: 'yes' + ELLSWIFT: 'yes' + EXPERIMENTAL: 'yes' + ECDSA_S2C: 'yes' + GENERATOR: 'yes' + RANGEPROOF: 'yes' + WHITELIST: 'yes' + MUSIG: 'yes' + ECDSAADAPTOR: 'yes' + BPPP: 'yes' + SCHNORRSIG_HALFAGG: 'yes' + CTIMETESTS: 'no' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: CI script + uses: ./.github/actions/run-in-docker-action + with: + dockerfile: ./ci/linux-debian.Dockerfile + tag: linux-debian-image + + - run: cat tests.log || true + if: ${{ always() }} + - run: cat noverify_tests.log || true + if: ${{ always() }} + - run: cat exhaustive_tests.log || true + if: ${{ always() }} + - run: cat ctime_tests.log || true + if: ${{ always() }} + - run: cat bench.log || true + if: ${{ always() }} + - run: cat config.log || true + if: ${{ always() }} + - run: cat test_env.log || true + if: ${{ always() }} + - name: CI env + run: env + if: ${{ always() }} + + valgrind_debian: + name: "Valgrind (memcheck)" + runs-on: ubuntu-latest + needs: docker_cache + + strategy: + fail-fast: false + matrix: + configuration: + - env_vars: { CC: 'clang', ASM: 'auto' } + - env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'auto' } + - env_vars: { CC: 'clang', ASM: 'no', ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 } + - env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'no', ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 } + + env: + # The `--error-exitcode` is required to make the test fail if valgrind found errors, + # otherwise it will return 0 (https://www.valgrind.org/docs/manual/manual-core.html). + WRAPPER_CMD: 'valgrind --error-exitcode=42' + ECDH: 'yes' + RECOVERY: 'yes' + SCHNORRSIG: 'yes' + ELLSWIFT: 'yes' + EXPERIMENTAL: 'yes' + ECDSA_S2C: 'yes' + GENERATOR: 'yes' + RANGEPROOF: 'yes' + WHITELIST: 'yes' + MUSIG: 'yes' + ECDSAADAPTOR: 'yes' + BPPP: 'yes' + SCHNORRSIG_HALFAGG: 'yes' + CTIMETESTS: 'no' + SECP256K1_TEST_ITERS: 2 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: CI script + env: ${{ matrix.configuration.env_vars }} + uses: ./.github/actions/run-in-docker-action + with: + dockerfile: ./ci/linux-debian.Dockerfile + tag: linux-debian-image + + - run: cat tests.log || true + if: ${{ always() }} + - run: cat noverify_tests.log || true + if: ${{ always() }} + - run: cat exhaustive_tests.log || true + if: ${{ always() }} + - run: cat ctime_tests.log || true + if: ${{ always() }} + - run: cat bench.log || true + if: ${{ always() }} + - run: cat config.log || true + if: ${{ always() }} + - run: cat test_env.log || true + if: ${{ always() }} + - name: CI env + run: env + if: ${{ always() }} + + sanitizers_debian: + name: "UBSan, ASan, LSan" + runs-on: ubuntu-latest + needs: docker_cache + + strategy: + fail-fast: false + matrix: + configuration: + - env_vars: { CC: 'clang', ASM: 'auto' } + - env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'auto' } + - env_vars: { CC: 'clang', ASM: 'no', ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 } + - env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'no', ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 } + + env: + ECDH: 'yes' + RECOVERY: 'yes' + SCHNORRSIG: 'yes' + ELLSWIFT: 'yes' + EXPERIMENTAL: 'yes' + ECDSA_S2C: 'yes' + GENERATOR: 'yes' + RANGEPROOF: 'yes' + WHITELIST: 'yes' + MUSIG: 'yes' + ECDSAADAPTOR: 'yes' + BPPP: 'yes' + SCHNORRSIG_HALFAGG: 'yes' + CTIMETESTS: 'no' + CFLAGS: '-fsanitize=undefined,address -g' + UBSAN_OPTIONS: 'print_stacktrace=1:halt_on_error=1' + ASAN_OPTIONS: 'strict_string_checks=1:detect_stack_use_after_return=1:detect_leaks=1' + LSAN_OPTIONS: 'use_unaligned=1' + SECP256K1_TEST_ITERS: 32 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: CI script + env: ${{ matrix.configuration.env_vars }} + uses: ./.github/actions/run-in-docker-action + with: + dockerfile: ./ci/linux-debian.Dockerfile + tag: linux-debian-image + + - run: cat tests.log || true + if: ${{ always() }} + - run: cat noverify_tests.log || true + if: ${{ always() }} + - run: cat exhaustive_tests.log || true + if: ${{ always() }} + - run: cat ctime_tests.log || true + if: ${{ always() }} + - run: cat bench.log || true + if: ${{ always() }} + - run: cat config.log || true + if: ${{ always() }} + - run: cat test_env.log || true + if: ${{ always() }} + - name: CI env + run: env + if: ${{ always() }} + + msan_debian: + name: "MSan" + runs-on: ubuntu-latest + needs: docker_cache + + strategy: + fail-fast: false + matrix: + configuration: + - env_vars: + CFLAGS: '-fsanitize=memory -fsanitize-recover=memory -g' + - env_vars: + ECMULTGENPRECISION: 2 + ECMULTWINDOW: 2 + CFLAGS: '-fsanitize=memory -fsanitize-recover=memory -g -O3' + + env: + ECDH: 'yes' + RECOVERY: 'yes' + SCHNORRSIG: 'yes' + ELLSWIFT: 'yes' + EXPERIMENTAL: 'yes' + ECDSA_S2C: 'yes' + GENERATOR: 'yes' + RANGEPROOF: 'yes' + WHITELIST: 'yes' + MUSIG: 'yes' + ECDSAADAPTOR: 'yes' + BPPP: 'yes' + SCHNORRSIG_HALFAGG: 'yes' + CTIMETESTS: 'yes' + CC: 'clang' + SECP256K1_TEST_ITERS: 32 + ASM: 'no' + WITH_VALGRIND: 'no' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: CI script + env: ${{ matrix.configuration.env_vars }} + uses: ./.github/actions/run-in-docker-action + with: + dockerfile: ./ci/linux-debian.Dockerfile + tag: linux-debian-image + + - run: cat tests.log || true + if: ${{ always() }} + - run: cat noverify_tests.log || true + if: ${{ always() }} + - run: cat exhaustive_tests.log || true + if: ${{ always() }} + - run: cat ctime_tests.log || true + if: ${{ always() }} + - run: cat bench.log || true + if: ${{ always() }} + - run: cat config.log || true + if: ${{ always() }} + - run: cat test_env.log || true + if: ${{ always() }} + - name: CI env + run: env + if: ${{ always() }} + + mingw_debian: + name: ${{ matrix.configuration.job_name }} + runs-on: ubuntu-latest + needs: docker_cache + + env: + WRAPPER_CMD: 'wine' + WITH_VALGRIND: 'no' + ECDH: 'yes' + RECOVERY: 'yes' + SCHNORRSIG: 'yes' + ELLSWIFT: 'yes' + EXPERIMENTAL: 'yes' + ECDSA_S2C: 'yes' + GENERATOR: 'yes' + RANGEPROOF: 'yes' + WHITELIST: 'yes' + MUSIG: 'yes' + ECDSAADAPTOR: 'yes' + BPPP: 'yes' + SCHNORRSIG_HALFAGG: 'yes' + CTIMETESTS: 'no' + + strategy: + fail-fast: false + matrix: + configuration: + - job_name: 'x86_64 (mingw32-w64): Windows (Debian stable, Wine)' + env_vars: + HOST: 'x86_64-w64-mingw32' + - job_name: 'i686 (mingw32-w64): Windows (Debian stable, Wine)' + env_vars: + HOST: 'i686-w64-mingw32' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: CI script + env: ${{ matrix.configuration.env_vars }} + uses: ./.github/actions/run-in-docker-action + with: + dockerfile: ./ci/linux-debian.Dockerfile + tag: linux-debian-image + + - run: cat tests.log || true + if: ${{ always() }} + - run: cat noverify_tests.log || true + if: ${{ always() }} + - run: cat exhaustive_tests.log || true + if: ${{ always() }} + - run: cat ctime_tests.log || true + if: ${{ always() }} + - run: cat bench.log || true + if: ${{ always() }} + - run: cat config.log || true + if: ${{ always() }} + - run: cat test_env.log || true + if: ${{ always() }} + - name: CI env + run: env + if: ${{ always() }} + + macos-native: + name: "x86_64: macOS Monterey" + # See: https://github.com/actions/runner-images#available-images. + runs-on: macos-12 # Use M1 once available https://github.com/github/roadmap/issues/528 + + env: + CC: 'clang' + HOMEBREW_NO_AUTO_UPDATE: 1 + HOMEBREW_NO_INSTALL_CLEANUP: 1 + + strategy: + fail-fast: false + matrix: + env_vars: + - { WIDEMUL: 'int64', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', SCHNORRSIG_HALFAGG: 'yes' } + - { WIDEMUL: 'int128_struct', ECMULTGENPRECISION: 2, ECMULTWINDOW: 4 } + - { WIDEMUL: 'int128', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', SCHNORRSIG_HALFAGG: 'yes' } + - { WIDEMUL: 'int128', RECOVERY: 'yes' } + - { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', SCHNORRSIG_HALFAGG: 'yes' } + - { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', SCHNORRSIG_HALFAGG: 'yes', CC: 'gcc' } + - { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', SCHNORRSIG_HALFAGG: 'yes', WRAPPER_CMD: 'valgrind --error-exitcode=42', SECP256K1_TEST_ITERS: 2 } + - { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', SCHNORRSIG_HALFAGG: 'yes', CC: 'gcc', WRAPPER_CMD: 'valgrind --error-exitcode=42', SECP256K1_TEST_ITERS: 2 } + - { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', SCHNORRSIG_HALFAGG: 'yes', CPPFLAGS: '-DVERIFY', CTIMETESTS: 'no' } + - BUILD: 'distcheck' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Homebrew packages + run: | + brew install automake libtool gcc + ln -s $(brew --prefix gcc)/bin/gcc-?? /usr/local/bin/gcc + + - name: Install and cache Valgrind + uses: ./.github/actions/install-homebrew-valgrind + + - name: CI script + env: ${{ matrix.env_vars }} + run: ./ci/ci.sh + + - run: cat tests.log || true + if: ${{ always() }} + - run: cat noverify_tests.log || true + if: ${{ always() }} + - run: cat exhaustive_tests.log || true + if: ${{ always() }} + - run: cat ctime_tests.log || true + if: ${{ always() }} + - run: cat bench.log || true + if: ${{ always() }} + - run: cat config.log || true + if: ${{ always() }} + - run: cat test_env.log || true + if: ${{ always() }} + - name: CI env + run: env + if: ${{ always() }} + + win64-native: + name: ${{ matrix.configuration.job_name }} + # See: https://github.com/actions/runner-images#available-images. + runs-on: windows-2022 + + strategy: + fail-fast: false + matrix: + configuration: + - job_name: 'x64 (MSVC): Windows (VS 2022, shared)' + cmake_options: '-A x64 -DBUILD_SHARED_LIBS=ON' + - job_name: 'x64 (MSVC): Windows (VS 2022, static)' + cmake_options: '-A x64 -DBUILD_SHARED_LIBS=OFF' + - job_name: 'x64 (MSVC): Windows (VS 2022, int128_struct)' + cmake_options: '-A x64 -DSECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY=int128_struct' + - job_name: 'x64 (MSVC): Windows (VS 2022, int128_struct with __(u)mulh)' + cmake_options: '-A x64 -DSECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY=int128_struct' + cpp_flags: '/DSECP256K1_MSVC_MULH_TEST_OVERRIDE' + - job_name: 'x86 (MSVC): Windows (VS 2022)' + cmake_options: '-A Win32' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Generate buildsystem + run: cmake -E env CFLAGS="/WX ${{ matrix.configuration.cpp_flags }}" cmake -B build -DSECP256K1_ENABLE_MODULE_RECOVERY=ON -DSECP256K1_BUILD_EXAMPLES=ON ${{ matrix.configuration.cmake_options }} + + - name: Build + run: cmake --build build --config RelWithDebInfo -- /p:UseMultiToolTask=true /maxCpuCount + + - name: Binaries info + # Use the bash shell included with Git for Windows. + shell: bash + run: | + cd build/src/RelWithDebInfo && file *tests.exe bench*.exe libsecp256k1-*.dll || true + + - name: Check + run: | + ctest -C RelWithDebInfo --test-dir build -j ([int]$env:NUMBER_OF_PROCESSORS + 1) + build\src\RelWithDebInfo\bench_ecmult.exe + build\src\RelWithDebInfo\bench_internal.exe + build\src\RelWithDebInfo\bench.exe + + win64-native-headers: + name: "x64 (MSVC): C++ (public headers)" + # See: https://github.com/actions/runner-images#available-images. + runs-on: windows-2022 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Add cl.exe to PATH + uses: ilammy/msvc-dev-cmd@v1 + + - name: C++ (public headers) + run: | + cl.exe -c -WX -TP include/*.h + + cxx_fpermissive_debian: + name: "C++ -fpermissive (entire project)" + runs-on: ubuntu-latest + needs: docker_cache + + env: + CC: 'g++' + CFLAGS: '-fpermissive -g' + CPPFLAGS: '-DSECP256K1_CPLUSPLUS_TEST_OVERRIDE' + WERROR_CFLAGS: + ECDH: 'yes' + RECOVERY: 'yes' + SCHNORRSIG: 'yes' + ELLSWIFT: 'yes' + EXPERIMENTAL: 'yes' + ECDSA_S2C: 'yes' + GENERATOR: 'yes' + RANGEPROOF: 'yes' + WHITELIST: 'yes' + MUSIG: 'yes' + ECDSAADAPTOR: 'yes' + BPPP: 'yes' + SCHNORRSIG_HALFAGG: 'yes' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: CI script + uses: ./.github/actions/run-in-docker-action + with: + dockerfile: ./ci/linux-debian.Dockerfile + tag: linux-debian-image + + - run: cat tests.log || true + if: ${{ always() }} + - run: cat noverify_tests.log || true + if: ${{ always() }} + - run: cat exhaustive_tests.log || true + if: ${{ always() }} + - run: cat ctime_tests.log || true + if: ${{ always() }} + - run: cat bench.log || true + if: ${{ always() }} + - run: cat config.log || true + if: ${{ always() }} + - run: cat test_env.log || true + if: ${{ always() }} + - name: CI env + run: env + if: ${{ always() }} + + cxx_headers_debian: + name: "C++ (public headers)" + runs-on: ubuntu-latest + needs: docker_cache + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: CI script + uses: ./.github/actions/run-in-docker-action + with: + dockerfile: ./ci/linux-debian.Dockerfile + tag: linux-debian-image + command: | + g++ -Werror include/*.h + clang -Werror -x c++-header include/*.h + + sage: + name: "SageMath prover" + runs-on: ubuntu-latest + container: + image: sagemath/sagemath:latest + options: --user root + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: CI script + run: | + cd sage + sage prove_group_implementations.sage + + release: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - run: ./autogen.sh && ./configure --enable-dev-mode && make distcheck + + - name: Check installation with Autotools + env: + CI_INSTALL: ${{ runner.temp }}/${{ github.run_id }}${{ github.action }}/install + run: | + ./autogen.sh && ./configure --prefix=${{ env.CI_INSTALL }} && make clean && make install && ls -RlAh ${{ env.CI_INSTALL }} + gcc -o ecdsa examples/ecdsa.c $(PKG_CONFIG_PATH=${{ env.CI_INSTALL }}/lib/pkgconfig pkg-config --cflags --libs libsecp256k1) -Wl,-rpath,"${{ env.CI_INSTALL }}/lib" && ./ecdsa + + - name: Check installation with CMake + env: + CI_BUILD: ${{ runner.temp }}/${{ github.run_id }}${{ github.action }}/build + CI_INSTALL: ${{ runner.temp }}/${{ github.run_id }}${{ github.action }}/install + run: | + cmake -B ${{ env.CI_BUILD }} -DCMAKE_INSTALL_PREFIX=${{ env.CI_INSTALL }} && cmake --build ${{ env.CI_BUILD }} --target install && ls -RlAh ${{ env.CI_INSTALL }} + gcc -o ecdsa examples/ecdsa.c -I ${{ env.CI_INSTALL }}/include -L ${{ env.CI_INSTALL }}/lib*/ -l secp256k1 -Wl,-rpath,"${{ env.CI_INSTALL }}/lib",-rpath,"${{ env.CI_INSTALL }}/lib64" && ./ecdsa diff --git a/secp256k1-zkp-sys/depend/secp256k1/.gitignore b/secp256k1-zkp-sys/depend/secp256k1/.gitignore index 9be37772..b3ae618d 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/.gitignore +++ b/secp256k1-zkp-sys/depend/secp256k1/.gitignore @@ -5,12 +5,13 @@ bench_generator bench_rangeproof bench_internal bench_whitelist +noverify_tests tests example_musig exhaustive_tests precompute_ecmult_gen precompute_ecmult -valgrind_ctime_test +ctime_tests ecdh_example ecdsa_example schnorr_example @@ -18,9 +19,9 @@ schnorr_example *.so *.a *.csv -!.gitignore *.log *.trs +*.sage.py Makefile configure @@ -39,8 +40,6 @@ libtool *.lo *.o *~ -*.log -*.trs coverage/ coverage.html @@ -49,8 +48,6 @@ coverage.*.html *.gcno *.gcov -src/libsecp256k1-config.h -src/libsecp256k1-config.h.in build-aux/ar-lib build-aux/config.guess build-aux/config.sub @@ -65,8 +62,12 @@ build-aux/m4/ltversion.m4 build-aux/missing build-aux/compile build-aux/test-driver -src/stamp-h1 libsecp256k1.pc contrib/gh-pr-create.sh musig_example + +### CMake +/CMakeUserPresets.json +# Default CMake build directory. +/build diff --git a/secp256k1-zkp-sys/depend/secp256k1/CHANGELOG.md b/secp256k1-zkp-sys/depend/secp256k1/CHANGELOG.md new file mode 100644 index 00000000..cdfe06bc --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/CHANGELOG.md @@ -0,0 +1,128 @@ +**This changelog is not the libsecp256k1-zkp's changelog.** +Instead, it is the changelog of the upstream library [libsecp256k1](https://github.com/bitcoin-core/secp256k1). + +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +## [0.4.1] - 2023-12-21 + +#### Changed + - The point multiplication algorithm used for ECDH operations (module `ecdh`) was replaced with a slightly faster one. + - Optional handwritten x86_64 assembly for field operations was removed because modern C compilers are able to output more efficient assembly. This change results in a significant speedup of some library functions when handwritten x86_64 assembly is enabled (`--with-asm=x86_64` in GNU Autotools, `-DSECP256K1_ASM=x86_64` in CMake), which is the default on x86_64. Benchmarks with GCC 10.5.0 show a 10% speedup for `secp256k1_ecdsa_verify` and `secp256k1_schnorrsig_verify`. + +#### ABI Compatibility +The ABI is backward compatible with versions 0.4.0 and 0.3.x. + +## [0.4.0] - 2023-09-04 + +#### Added + - New module `ellswift` implements ElligatorSwift encoding for public keys and x-only Diffie-Hellman key exchange for them. + ElligatorSwift permits representing secp256k1 public keys as 64-byte arrays which cannot be distinguished from uniformly random. See: + - Header file `include/secp256k1_ellswift.h` which defines the new API. + - Document `doc/ellswift.md` which explains the mathematical background of the scheme. + - The [paper](https://eprint.iacr.org/2022/759) on which the scheme is based. + - We now test the library with unreleased development snapshots of GCC and Clang. This gives us an early chance to catch miscompilations and constant-time issues introduced by the compiler (such as those that led to the previous two releases). + +#### Fixed + - Fixed symbol visibility in Windows DLL builds, where three internal library symbols were wrongly exported. + +#### Changed + - When consuming libsecp256k1 as a static library on Windows, the user must now define the `SECP256K1_STATIC` macro before including `secp256k1.h`. + +#### ABI Compatibility +This release is backward compatible with the ABI of 0.3.0, 0.3.1, and 0.3.2. Symbol visibility is now believed to be handled properly on supported platforms and is now considered to be part of the ABI. Please report any improperly exported symbols as a bug. + +## [0.3.2] - 2023-05-13 +We strongly recommend updating to 0.3.2 if you use or plan to use GCC >=13 to compile libsecp256k1. When in doubt, check the GCC version using `gcc -v`. + +#### Security + - Module `ecdh`: Fix "constant-timeness" issue with GCC 13.1 (and potentially future versions of GCC) that could leave applications using libsecp256k1's ECDH module vulnerable to a timing side-channel attack. The fix avoids secret-dependent control flow during ECDH computations when libsecp256k1 is compiled with GCC 13.1. + +#### Fixed + - Fixed an old bug that permitted compilers to potentially output bad assembly code on x86_64. In theory, it could lead to a crash or a read of unrelated memory, but this has never been observed on any compilers so far. + +#### Changed + - Various improvements and changes to CMake builds. CMake builds remain experimental. + - Made API versioning consistent with GNU Autotools builds. + - Switched to `BUILD_SHARED_LIBS` variable for controlling whether to build a static or a shared library. + - Added `SECP256K1_INSTALL` variable for the controlling whether to install the build artefacts. + - Renamed asm build option `arm` to `arm32`. Use `--with-asm=arm32` instead of `--with-asm=arm` (GNU Autotools), and `-DSECP256K1_ASM=arm32` instead of `-DSECP256K1_ASM=arm` (CMake). + +#### ABI Compatibility +The ABI is compatible with versions 0.3.0 and 0.3.1. + +## [0.3.1] - 2023-04-10 +We strongly recommend updating to 0.3.1 if you use or plan to use Clang >=14 to compile libsecp256k1, e.g., Xcode >=14 on macOS has Clang >=14. When in doubt, check the Clang version using `clang -v`. + +#### Security + - Fix "constant-timeness" issue with Clang >=14 that could leave applications using libsecp256k1 vulnerable to a timing side-channel attack. The fix avoids secret-dependent control flow and secret-dependent memory accesses in conditional moves of memory objects when libsecp256k1 is compiled with Clang >=14. + +#### Added + - Added tests against [Project Wycheproof's](https://github.com/google/wycheproof/) set of ECDSA test vectors (Bitcoin "low-S" variant), a fixed set of test cases designed to trigger various edge cases. + +#### Changed + - Increased minimum required CMake version to 3.13. CMake builds remain experimental. + +#### ABI Compatibility +The ABI is compatible with version 0.3.0. + +## [0.3.0] - 2023-03-08 + +#### Added + - Added experimental support for CMake builds. Traditional GNU Autotools builds (`./configure` and `make`) remain fully supported. + - Usage examples: Added a recommended method for securely clearing sensitive data, e.g., secret keys, from memory. + - Tests: Added a new test binary `noverify_tests`. This binary runs the tests without some additional checks present in the ordinary `tests` binary and is thereby closer to production binaries. The `noverify_tests` binary is automatically run as part of the `make check` target. + +#### Fixed + - Fixed declarations of API variables for MSVC (`__declspec(dllimport)`). This fixes MSVC builds of programs which link against a libsecp256k1 DLL dynamically and use API variables (and not only API functions). Unfortunately, the MSVC linker now will emit warning `LNK4217` when trying to link against libsecp256k1 statically. Pass `/ignore:4217` to the linker to suppress this warning. + +#### Changed + - Forbade cloning or destroying `secp256k1_context_static`. Create a new context instead of cloning the static context. (If this change breaks your code, your code is probably wrong.) + - Forbade randomizing (copies of) `secp256k1_context_static`. Randomizing a copy of `secp256k1_context_static` did not have any effect and did not provide defense-in-depth protection against side-channel attacks. Create a new context if you want to benefit from randomization. + +#### Removed + - Removed the configuration header `src/libsecp256k1-config.h`. We recommend passing flags to `./configure` or `cmake` to set configuration options (see `./configure --help` or `cmake -LH`). If you cannot or do not want to use one of the supported build systems, pass configuration flags such as `-DSECP256K1_ENABLE_MODULE_SCHNORRSIG` manually to the compiler (see the file `configure.ac` for supported flags). + +#### ABI Compatibility +Due to changes in the API regarding `secp256k1_context_static` described above, the ABI is *not* compatible with previous versions. + +## [0.2.0] - 2022-12-12 + +#### Added + - Added usage examples for common use cases in a new `examples/` directory. + - Added `secp256k1_selftest`, to be used in conjunction with `secp256k1_context_static`. + - Added support for 128-bit wide multiplication on MSVC for x86_64 and arm64, giving roughly a 20% speedup on those platforms. + +#### Changed + - Enabled modules `schnorrsig`, `extrakeys` and `ecdh` by default in `./configure`. + - The `secp256k1_nonce_function_rfc6979` nonce function, used by default by `secp256k1_ecdsa_sign`, now reduces the message hash modulo the group order to match the specification. This only affects improper use of ECDSA signing API. + +#### Deprecated + - Deprecated context flags `SECP256K1_CONTEXT_VERIFY` and `SECP256K1_CONTEXT_SIGN`. Use `SECP256K1_CONTEXT_NONE` instead. + - Renamed `secp256k1_context_no_precomp` to `secp256k1_context_static`. + - Module `schnorrsig`: renamed `secp256k1_schnorrsig_sign` to `secp256k1_schnorrsig_sign32`. + +#### ABI Compatibility +Since this is the first release, we do not compare application binary interfaces. +However, there are earlier unreleased versions of libsecp256k1 that are *not* ABI compatible with this version. + +## [0.1.0] - 2013-03-05 to 2021-12-25 + +This version was in fact never released. +The number was given by the build system since the introduction of autotools in Jan 2014 (ea0fe5a5bf0c04f9cc955b2966b614f5f378c6f6). +Therefore, this version number does not uniquely identify a set of source files. + +[unreleased]: https://github.com/bitcoin-core/secp256k1/compare/v0.4.1...HEAD +[0.4.1]: https://github.com/bitcoin-core/secp256k1/compare/v0.4.0...v0.4.1 +[0.4.0]: https://github.com/bitcoin-core/secp256k1/compare/v0.3.2...v0.4.0 +[0.3.2]: https://github.com/bitcoin-core/secp256k1/compare/v0.3.1...v0.3.2 +[0.3.1]: https://github.com/bitcoin-core/secp256k1/compare/v0.3.0...v0.3.1 +[0.3.0]: https://github.com/bitcoin-core/secp256k1/compare/v0.2.0...v0.3.0 +[0.2.0]: https://github.com/bitcoin-core/secp256k1/compare/423b6d19d373f1224fd671a982584d7e7900bc93..v0.2.0 +[0.1.0]: https://github.com/bitcoin-core/secp256k1/commit/423b6d19d373f1224fd671a982584d7e7900bc93 diff --git a/secp256k1-zkp-sys/depend/secp256k1/CMakePresets.json b/secp256k1-zkp-sys/depend/secp256k1/CMakePresets.json new file mode 100644 index 00000000..b35cd805 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/CMakePresets.json @@ -0,0 +1,19 @@ +{ + "cmakeMinimumRequired": {"major": 3, "minor": 21, "patch": 0}, + "version": 3, + "configurePresets": [ + { + "name": "dev-mode", + "displayName": "Development mode (intended only for developers of the library)", + "cacheVariables": { + "SECP256K1_EXPERIMENTAL": "ON", + "SECP256K1_ENABLE_MODULE_RECOVERY": "ON", + "SECP256K1_BUILD_EXAMPLES": "ON" + }, + "warnings": { + "dev": true, + "uninitialized": true + } + } + ] +} diff --git a/secp256k1-zkp-sys/depend/secp256k1/CONTRIBUTING.md b/secp256k1-zkp-sys/depend/secp256k1/CONTRIBUTING.md new file mode 100644 index 00000000..67076011 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/CONTRIBUTING.md @@ -0,0 +1,107 @@ +# Contributing to libsecp256k1 + +## Scope + +libsecp256k1 is a library for elliptic curve cryptography on the curve secp256k1, not a general-purpose cryptography library. +The library primarily serves the needs of the Bitcoin Core project but provides additional functionality for the benefit of the wider Bitcoin ecosystem. + +## Adding new functionality or modules + +The libsecp256k1 project welcomes contributions in the form of new functionality or modules, provided they are within the project's scope. + +It is the responsibility of the contributors to convince the maintainers that the proposed functionality is within the project's scope, high-quality and maintainable. +Contributors are recommended to provide the following in addition to the new code: + +* **Specification:** + A specification can help significantly in reviewing the new code as it provides documentation and context. + It may justify various design decisions, give a motivation and outline security goals. + If the specification contains pseudocode, a reference implementation or test vectors, these can be used to compare with the proposed libsecp256k1 code. +* **Security Arguments:** + In addition to a defining the security goals, it should be argued that the new functionality meets these goals. + Depending on the nature of the new functionality, a wide range of security arguments are acceptable, ranging from being "obviously secure" to rigorous proofs of security. +* **Relevance Arguments:** + The relevance of the new functionality for the Bitcoin ecosystem should be argued by outlining clear use cases. + +These are not the only factors taken into account when considering to add new functionality. +The proposed new libsecp256k1 code must be of high quality, including API documentation and tests, as well as featuring a misuse-resistant API design. + +We recommend reaching out to other contributors (see [Communication Channels](#communication-channels)) and get feedback before implementing new functionality. + +## Communication channels + +Most communication about libsecp256k1 occurs on the GitHub repository: in issues, pull request or on the discussion board. + +Additionally, there is an IRC channel dedicated to libsecp256k1, with biweekly meetings (see channel topic). +The channel is `#secp256k1` on Libera Chat. +The easiest way to participate on IRC is with the web client, [web.libera.chat](https://web.libera.chat/#secp256k1). +Chat history logs can be found at https://gnusha.org/secp256k1/. + +## Contributor workflow & peer review + +The Contributor Workflow & Peer Review in libsecp256k1 are similar to Bitcoin Core's workflow and review processes described in its [CONTRIBUTING.md](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md). + +### Coding conventions + +In addition, libsecp256k1 tries to maintain the following coding conventions: + +* No runtime heap allocation (e.g., no `malloc`) unless explicitly requested by the caller (via `rustsecp256k1zkp_v0_10_0_context_create` or `rustsecp256k1zkp_v0_10_0_scratch_space_create`, for example). Moreover, it should be possible to use the library without any heap allocations. +* The tests should cover all lines and branches of the library (see [Test coverage](#coverage)). +* Operations involving secret data should be tested for being constant time with respect to the secrets (see [src/ctime_tests.c](src/ctime_tests.c)). +* Local variables containing secret data should be cleared explicitly to try to delete secrets from memory. +* Use `rustsecp256k1zkp_v0_10_0_memcmp_var` instead of `memcmp` (see [#823](https://github.com/bitcoin-core/secp256k1/issues/823)). + +#### Style conventions + +* Commits should be atomic and diffs should be easy to read. For this reason, do not mix any formatting fixes or code moves with actual code changes. Make sure each individual commit is hygienic: that it builds successfully on its own without warnings, errors, regressions, or test failures. +* New code should adhere to the style of existing, in particular surrounding, code. Other than that, we do not enforce strict rules for code formatting. +* The code conforms to C89. Most notably, that means that only `/* ... */` comments are allowed (no `//` line comments). Moreover, any declarations in a `{ ... }` block (e.g., a function) must appear at the beginning of the block before any statements. When you would like to declare a variable in the middle of a block, you can open a new block: + ```C + void secp256k_foo(void) { + unsigned int x; /* declaration */ + int y = 2*x; /* declaration */ + x = 17; /* statement */ + { + int a, b; /* declaration */ + a = x + y; /* statement */ + secp256k_bar(x, &b); /* statement */ + } + } + ``` +* Use `unsigned int` instead of just `unsigned`. +* Use `void *ptr` instead of `void* ptr`. +* Arguments of the publicly-facing API must have a specific order defined in [include/secp256k1.h](include/secp256k1.h). +* User-facing comment lines in headers should be limited to 80 chars if possible. +* All identifiers in file scope should start with `rustsecp256k1zkp_v0_10_0_`. +* Avoid trailing whitespace. + +### Tests + +#### Coverage + +This library aims to have full coverage of reachable lines and branches. + +To create a test coverage report, configure with `--enable-coverage` (use of GCC is necessary): + + $ ./configure --enable-coverage + +Run the tests: + + $ make check + +To create a report, `gcovr` is recommended, as it includes branch coverage reporting: + + $ gcovr --exclude 'src/bench*' --print-summary + +To create a HTML report with coloured and annotated source code: + + $ mkdir -p coverage + $ gcovr --exclude 'src/bench*' --html --html-details -o coverage/coverage.html + +#### Exhaustive tests + +There are tests of several functions in which a small group replaces secp256k1. +These tests are *exhaustive* since they provide all elements and scalars of the small group as input arguments (see [src/tests_exhaustive.c](src/tests_exhaustive.c)). + +### Benchmarks + +See `src/bench*.c` for examples of benchmarks. diff --git a/secp256k1-zkp-sys/depend/secp256k1/Makefile.am b/secp256k1-zkp-sys/depend/secp256k1/Makefile.am index a129ea01..764fe917 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/Makefile.am +++ b/secp256k1-zkp-sys/depend/secp256k1/Makefile.am @@ -1,5 +1,3 @@ -.PHONY: clean-precomp precomp - ACLOCAL_AMFLAGS = -I build-aux/m4 # AM_CFLAGS will be automatically prepended to CFLAGS by Automake when compiling some foo @@ -8,7 +6,7 @@ AM_CFLAGS = $(SECP_CFLAGS) lib_LTLIBRARIES = libsecp256k1.la include_HEADERS = include/secp256k1.h -include_HEADERS += include/rustsecp256k1zkp_v0_8_0_preallocated.h +include_HEADERS += include/rustsecp256k1zkp_v0_10_0_preallocated.h noinst_HEADERS = noinst_HEADERS += src/scalar.h noinst_HEADERS += src/scalar_4x64.h @@ -41,7 +39,6 @@ noinst_HEADERS += src/field_10x26_impl.h noinst_HEADERS += src/field_5x52.h noinst_HEADERS += src/field_5x52_impl.h noinst_HEADERS += src/field_5x52_int128_impl.h -noinst_HEADERS += src/field_5x52_asm_impl.h noinst_HEADERS += src/modinv32.h noinst_HEADERS += src/modinv32_impl.h noinst_HEADERS += src/modinv64.h @@ -49,7 +46,15 @@ noinst_HEADERS += src/modinv64_impl.h noinst_HEADERS += src/precomputed_ecmult.h noinst_HEADERS += src/precomputed_ecmult_gen.h noinst_HEADERS += src/assumptions.h +noinst_HEADERS += src/checkmem.h +noinst_HEADERS += src/testutil.h noinst_HEADERS += src/util.h +noinst_HEADERS += src/int128.h +noinst_HEADERS += src/int128_impl.h +noinst_HEADERS += src/int128_native.h +noinst_HEADERS += src/int128_native_impl.h +noinst_HEADERS += src/int128_struct.h +noinst_HEADERS += src/int128_struct_impl.h noinst_HEADERS += src/scratch.h noinst_HEADERS += src/scratch_impl.h noinst_HEADERS += src/selftest.h @@ -60,20 +65,22 @@ noinst_HEADERS += src/hash_impl.h noinst_HEADERS += src/field.h noinst_HEADERS += src/field_impl.h noinst_HEADERS += src/bench.h -noinst_HEADERS += src/basic-config.h +noinst_HEADERS += src/wycheproof/ecdsa_rustsecp256k1zkp_v0_10_0_sha256_bitcoin_test.h noinst_HEADERS += contrib/lax_der_parsing.h noinst_HEADERS += contrib/lax_der_parsing.c noinst_HEADERS += contrib/lax_der_privatekey_parsing.h noinst_HEADERS += contrib/lax_der_privatekey_parsing.c -noinst_HEADERS += examples/random.h +noinst_HEADERS += examples/examples_util.h -PRECOMPUTED_LIB = librustsecp256k1zkp_v0_8_0_precomputed.la +PRECOMPUTED_LIB = librustsecp256k1zkp_v0_10_0_precomputed.la noinst_LTLIBRARIES = $(PRECOMPUTED_LIB) -librustsecp256k1zkp_v0_8_0_precomputed_la_SOURCES = src/precomputed_ecmult.c src/precomputed_ecmult_gen.c -librustsecp256k1zkp_v0_8_0_precomputed_la_CPPFLAGS = $(SECP_INCLUDES) +librustsecp256k1zkp_v0_10_0_precomputed_la_SOURCES = src/precomputed_ecmult.c src/precomputed_ecmult_gen.c +# We need `-I$(top_srcdir)/src` in VPATH builds if librustsecp256k1zkp_v0_10_0_precomputed_la_SOURCES have been recreated in the build tree. +# This helps users and packagers who insist on recreating the precomputed files (e.g., Gentoo). +librustsecp256k1zkp_v0_10_0_precomputed_la_CPPFLAGS = -I$(top_srcdir)/src $(SECP_CONFIG_DEFINES) if USE_EXTERNAL_ASM -COMMON_LIB = librustsecp256k1zkp_v0_8_0_common.la +COMMON_LIB = librustsecp256k1zkp_v0_10_0_common.la else COMMON_LIB = endif @@ -84,60 +91,63 @@ pkgconfig_DATA = libsecp256k1.pc if USE_EXTERNAL_ASM if USE_ASM_ARM -librustsecp256k1zkp_v0_8_0_common_la_SOURCES = src/asm/field_10x26_arm.s +librustsecp256k1zkp_v0_10_0_common_la_SOURCES = src/asm/field_10x26_arm.s endif endif -librustsecp256k1zkp_v0_8_0_la_SOURCES = src/secp256k1.c -librustsecp256k1zkp_v0_8_0_la_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src $(SECP_INCLUDES) -librustsecp256k1zkp_v0_8_0_la_LIBADD = $(SECP_LIBS) $(COMMON_LIB) $(PRECOMPUTED_LIB) -librustsecp256k1zkp_v0_8_0_la_LDFLAGS = -no-undefined -version-info $(LIB_VERSION_CURRENT):$(LIB_VERSION_REVISION):$(LIB_VERSION_AGE) - -if VALGRIND_ENABLED -librustsecp256k1zkp_v0_8_0_la_CPPFLAGS += -DVALGRIND -endif +librustsecp256k1zkp_v0_10_0_la_SOURCES = src/secp256k1.c +librustsecp256k1zkp_v0_10_0_la_CPPFLAGS = $(SECP_CONFIG_DEFINES) +librustsecp256k1zkp_v0_10_0_la_LIBADD = $(COMMON_LIB) $(PRECOMPUTED_LIB) +librustsecp256k1zkp_v0_10_0_la_LDFLAGS = -no-undefined -version-info $(LIB_VERSION_CURRENT):$(LIB_VERSION_REVISION):$(LIB_VERSION_AGE) noinst_PROGRAMS = if USE_BENCHMARK noinst_PROGRAMS += bench bench_internal bench_ecmult bench_SOURCES = src/bench.c -bench_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB) +bench_LDADD = libsecp256k1.la +bench_CPPFLAGS = $(SECP_CONFIG_DEFINES) bench_internal_SOURCES = src/bench_internal.c -bench_internal_LDADD = $(SECP_LIBS) $(COMMON_LIB) $(PRECOMPUTED_LIB) -bench_internal_CPPFLAGS = $(SECP_INCLUDES) +bench_internal_LDADD = $(COMMON_LIB) $(PRECOMPUTED_LIB) +bench_internal_CPPFLAGS = $(SECP_CONFIG_DEFINES) bench_ecmult_SOURCES = src/bench_ecmult.c -bench_ecmult_LDADD = $(SECP_LIBS) $(COMMON_LIB) $(PRECOMPUTED_LIB) -bench_ecmult_CPPFLAGS = $(SECP_INCLUDES) +bench_ecmult_LDADD = $(COMMON_LIB) $(PRECOMPUTED_LIB) +bench_ecmult_CPPFLAGS = $(SECP_CONFIG_DEFINES) endif TESTS = if USE_TESTS +TESTS += noverify_tests +noinst_PROGRAMS += noverify_tests +noverify_tests_SOURCES = src/tests.c +noverify_tests_CPPFLAGS = $(SECP_CONFIG_DEFINES) +noverify_tests_LDADD = $(COMMON_LIB) $(PRECOMPUTED_LIB) +noverify_tests_LDFLAGS = -static +if !ENABLE_COVERAGE +TESTS += tests noinst_PROGRAMS += tests -tests_SOURCES = src/tests.c -tests_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include $(SECP_INCLUDES) $(SECP_TEST_INCLUDES) -if VALGRIND_ENABLED -tests_CPPFLAGS += -DVALGRIND -noinst_PROGRAMS += valgrind_ctime_test -valgrind_ctime_test_SOURCES = src/valgrind_ctime_test.c -valgrind_ctime_test_LDADD = libsecp256k1.la $(SECP_LIBS) $(COMMON_LIB) +tests_SOURCES = $(noverify_tests_SOURCES) +tests_CPPFLAGS = $(noverify_tests_CPPFLAGS) -DVERIFY +tests_LDADD = $(noverify_tests_LDADD) +tests_LDFLAGS = $(noverify_tests_LDFLAGS) endif -if !ENABLE_COVERAGE -tests_CPPFLAGS += -DVERIFY endif -tests_LDADD = $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB) $(PRECOMPUTED_LIB) -tests_LDFLAGS = -static -TESTS += tests + +if USE_CTIME_TESTS +noinst_PROGRAMS += ctime_tests +ctime_tests_SOURCES = src/ctime_tests.c +ctime_tests_LDADD = libsecp256k1.la +ctime_tests_CPPFLAGS = $(SECP_CONFIG_DEFINES) endif if USE_EXHAUSTIVE_TESTS noinst_PROGRAMS += exhaustive_tests exhaustive_tests_SOURCES = src/tests_exhaustive.c -exhaustive_tests_CPPFLAGS = $(SECP_INCLUDES) +exhaustive_tests_CPPFLAGS = $(SECP_CONFIG_DEFINES) if !ENABLE_COVERAGE exhaustive_tests_CPPFLAGS += -DVERIFY endif # Note: do not include $(PRECOMPUTED_LIB) in exhaustive_tests (it uses runtime-generated tables). -exhaustive_tests_LDADD = $(SECP_LIBS) $(COMMON_LIB) +exhaustive_tests_LDADD = $(COMMON_LIB) exhaustive_tests_LDFLAGS = -static TESTS += exhaustive_tests endif @@ -145,7 +155,7 @@ endif if USE_EXAMPLES noinst_PROGRAMS += ecdsa_example ecdsa_example_SOURCES = examples/ecdsa.c -ecdsa_example_CPPFLAGS = -I$(top_srcdir)/include +ecdsa_example_CPPFLAGS = -I$(top_srcdir)/include -DSECP256K1_STATIC ecdsa_example_LDADD = libsecp256k1.la ecdsa_example_LDFLAGS = -static if BUILD_WINDOWS @@ -155,7 +165,7 @@ TESTS += ecdsa_example if ENABLE_MODULE_ECDH noinst_PROGRAMS += ecdh_example ecdh_example_SOURCES = examples/ecdh.c -ecdh_example_CPPFLAGS = -I$(top_srcdir)/include +ecdh_example_CPPFLAGS = -I$(top_srcdir)/include -DSECP256K1_STATIC ecdh_example_LDADD = libsecp256k1.la ecdh_example_LDFLAGS = -static if BUILD_WINDOWS @@ -166,7 +176,7 @@ endif if ENABLE_MODULE_SCHNORRSIG noinst_PROGRAMS += schnorr_example schnorr_example_SOURCES = examples/schnorr.c -schnorr_example_CPPFLAGS = -I$(top_srcdir)/include +schnorr_example_CPPFLAGS = -I$(top_srcdir)/include -DSECP256K1_STATIC schnorr_example_LDADD = libsecp256k1.la schnorr_example_LDFLAGS = -static if BUILD_WINDOWS @@ -177,7 +187,7 @@ endif if ENABLE_MODULE_MUSIG noinst_PROGRAMS += musig_example musig_example_SOURCES = examples/musig.c -musig_example_CPPFLAGS = -I$(top_srcdir)/include +musig_example_CPPFLAGS = -I$(top_srcdir)/include -DSECP256K1_STATIC musig_example_LDADD = libsecp256k1.la musig_example_LDFLAGS = -static if BUILD_WINDOWS @@ -192,19 +202,19 @@ EXTRA_PROGRAMS = precompute_ecmult precompute_ecmult_gen CLEANFILES = $(EXTRA_PROGRAMS) precompute_ecmult_SOURCES = src/precompute_ecmult.c -precompute_ecmult_CPPFLAGS = $(SECP_INCLUDES) -precompute_ecmult_LDADD = $(SECP_LIBS) $(COMMON_LIB) +precompute_ecmult_CPPFLAGS = $(SECP_CONFIG_DEFINES) -DVERIFY +precompute_ecmult_LDADD = $(COMMON_LIB) precompute_ecmult_gen_SOURCES = src/precompute_ecmult_gen.c -precompute_ecmult_gen_CPPFLAGS = $(SECP_INCLUDES) -precompute_ecmult_gen_LDADD = $(SECP_LIBS) $(COMMON_LIB) +precompute_ecmult_gen_CPPFLAGS = $(SECP_CONFIG_DEFINES) -DVERIFY +precompute_ecmult_gen_LDADD = $(COMMON_LIB) # See Automake manual, Section "Errors with distclean". # We don't list any dependencies for the prebuilt files here because # otherwise make's decision whether to rebuild them (even in the first # build by a normal user) depends on mtimes, and thus is very fragile. # This means that rebuilds of the prebuilt files always need to be -# forced by deleting them, e.g., by invoking `make clean-precomp`. +# forced by deleting them. src/precomputed_ecmult.c: $(MAKE) $(AM_MAKEFLAGS) precompute_ecmult$(EXEEXT) ./precompute_ecmult$(EXEEXT) @@ -219,12 +229,45 @@ precomp: $(PRECOMP) # e.g., after `make maintainer-clean`). BUILT_SOURCES = $(PRECOMP) -maintainer-clean-local: clean-precomp - +.PHONY: clean-precomp clean-precomp: rm -f $(PRECOMP) +maintainer-clean-local: clean-precomp -EXTRA_DIST = autogen.sh SECURITY.md +### Pregenerated test vectors +### (see the comments in the previous section for detailed rationale) +TESTVECTORS = src/wycheproof/ecdsa_rustsecp256k1zkp_v0_10_0_sha256_bitcoin_test.h + +src/wycheproof/ecdsa_rustsecp256k1zkp_v0_10_0_sha256_bitcoin_test.h: + mkdir -p $(@D) + python3 $(top_srcdir)/tools/tests_wycheproof_generate.py $(top_srcdir)/src/wycheproof/ecdsa_rustsecp256k1zkp_v0_10_0_sha256_bitcoin_test.json > $@ + +testvectors: $(TESTVECTORS) + +BUILT_SOURCES += $(TESTVECTORS) + +.PHONY: clean-testvectors +clean-testvectors: + rm -f $(TESTVECTORS) +maintainer-clean-local: clean-testvectors + +### Additional files to distribute +EXTRA_DIST = autogen.sh CHANGELOG.md SECURITY.md +EXTRA_DIST += doc/release-process.md doc/safegcd_implementation.md +EXTRA_DIST += examples/EXAMPLES_COPYING +EXTRA_DIST += sage/gen_exhaustive_groups.sage +EXTRA_DIST += sage/gen_split_lambda_constants.sage +EXTRA_DIST += sage/group_prover.sage +EXTRA_DIST += sage/prove_group_implementations.sage +EXTRA_DIST += sage/rustsecp256k1zkp_v0_10_0_params.sage +EXTRA_DIST += sage/weierstrass_prover.sage +EXTRA_DIST += src/wycheproof/WYCHEPROOF_COPYING +EXTRA_DIST += src/wycheproof/ecdsa_rustsecp256k1zkp_v0_10_0_sha256_bitcoin_test.json +EXTRA_DIST += tools/tests_wycheproof_generate.py + +if ENABLE_MODULE_SCHNORRSIG_HALFAGG +include src/modules/schnorrsig_halfagg/Makefile.am.include +endif if ENABLE_MODULE_BPPP include src/modules/bppp/Makefile.am.include @@ -266,6 +309,10 @@ if ENABLE_MODULE_SCHNORRSIG include src/modules/schnorrsig/Makefile.am.include endif +if ENABLE_MODULE_ELLSWIFT +include src/modules/ellswift/Makefile.am.include +endif + if ENABLE_MODULE_ECDSA_S2C include src/modules/ecdsa_s2c/Makefile.am.include endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/README.md b/secp256k1-zkp-sys/depend/secp256k1/README.md index 7ac1e0a0..88bdb2ba 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/README.md +++ b/secp256k1-zkp-sys/depend/secp256k1/README.md @@ -1,69 +1,25 @@ -libsecp256k1 -============ - -[![Build Status](https://api.cirrus-ci.com/github/bitcoin-core/secp256k1.svg?branch=master)](https://cirrus-ci.com/github/bitcoin-core/secp256k1) - -Optimized C library for ECDSA signatures and secret/public key operations on curve secp256k1. - -This library is intended to be the highest quality publicly available library for cryptography on the secp256k1 curve. However, the primary focus of its development has been for usage in the Bitcoin system and usage unlike Bitcoin's may be less well tested, verified, or suffer from a less well thought out interface. Correct usage requires some care and consideration that the library is fit for your application's purpose. - -Features: -* secp256k1 ECDSA signing/verification and key generation. -* Additive and multiplicative tweaking of secret/public keys. -* Serialization/parsing of secret keys, public keys, signatures. -* Constant time, constant memory access signing and public key generation. -* Derandomized ECDSA (via RFC6979 or with a caller provided function.) -* Very efficient implementation. -* Suitable for embedded systems. -* Optional module for public key recovery. -* Optional module for ECDH key exchange. -* Optional module for Schnorr signatures according to [BIP-340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki). -* Optional module for ECDSA adaptor signatures (experimental). - -Experimental features have not received enough scrutiny to satisfy the standard of quality of this library but are made available for testing and review by the community. The APIs of these features should not be considered stable. - -Implementation details ----------------------- - -* General - * No runtime heap allocation. - * Extensive testing infrastructure. - * Structured to facilitate review and analysis. - * Intended to be portable to any system with a C89 compiler and uint64_t support. - * No use of floating types. - * Expose only higher level interfaces to minimize the API surface and improve application security. ("Be difficult to use insecurely.") -* Field operations - * Optimized implementation of arithmetic modulo the curve's field size (2^256 - 0x1000003D1). - * Using 5 52-bit limbs (including hand-optimized assembly for x86_64, by Diederik Huys). - * Using 10 26-bit limbs (including hand-optimized assembly for 32-bit ARM, by Wladimir J. van der Laan). - * This is an experimental feature that has not received enough scrutiny to satisfy the standard of quality of this library but is made available for testing and review by the community. -* Scalar operations - * Optimized implementation without data-dependent branches of arithmetic modulo the curve's order. - * Using 4 64-bit limbs (relying on __int128 support in the compiler). - * Using 8 32-bit limbs. -* Modular inverses (both field elements and scalars) based on [safegcd](https://gcd.cr.yp.to/index.html) with some modifications, and a variable-time variant (by Peter Dettman). -* Group operations - * Point addition formula specifically simplified for the curve equation (y^2 = x^3 + 7). - * Use addition between points in Jacobian and affine coordinates where possible. - * Use a unified addition/doubling formula where necessary to avoid data-dependent branches. - * Point/x comparison without a field inversion by comparison in the Jacobian coordinate space. -* Point multiplication for verification (a*P + b*G). - * Use wNAF notation for point multiplicands. - * Use a much larger window for multiples of G, using precomputed multiples. - * Use Shamir's trick to do the multiplication with the public key and the generator simultaneously. - * Use secp256k1's efficiently-computable endomorphism to split the P multiplicand into 2 half-sized ones. -* Point multiplication for signing - * Use a precomputed table of multiples of powers of 16 multiplied with the generator, so general multiplication becomes a series of additions. - * Intended to be completely free of timing sidechannels for secret-key operations (on reasonable hardware/toolchains) - * Access the table with branch-free conditional moves so memory access is uniform. - * No data-dependent branches - * Optional runtime blinding which attempts to frustrate differential power analysis. - * The precomputed tables add and eventually subtract points for which no known scalar (secret key) is known, preventing even an attacker with control over the secret key used to control the data internally. +libsecp256k1-zkp +================ + +![Dependencies: None](https://img.shields.io/badge/dependencies-none-success) + +A fork of [libsecp256k1](https://github.com/bitcoin-core/secp256k1) with support for advanced and experimental features such as Confidential Assets and MuSig2 + +Added features: +* Experimental module for ECDSA adaptor signatures. +* Experimental module for ECDSA sign-to-contract. +* Experimental module for [MuSig2](src/modules/musig/musig.md). +* Experimental module for Confidential Assets (Pedersen commitments, range proofs, and [surjection proofs](src/modules/surjection/surjection.md)). +* Experimental module for Bulletproofs++ range proofs. +* Experimental module for [address whitelisting](src/modules/whitelist/whitelist.md). + +Experimental features are made available for testing and review by the community. The APIs of these features should not be considered stable. Build steps ----------- -libsecp256k1 is built using autotools: +Building with Autotools +----------------------- $ ./autogen.sh $ ./configure @@ -71,41 +27,59 @@ libsecp256k1 is built using autotools: $ make check # run the test suite $ sudo make install # optional -To compile optional modules (such as Schnorr signatures), you need to run `./configure` with additional flags (such as `--enable-module-schnorrsig`). Run `./configure --help` to see the full list of available flags. +To compile optional modules (such as Schnorr signatures), you need to run `./configure` with additional flags (such as `--enable-module-schnorrsig`). Run `./configure --help` to see the full list of available flags. For experimental modules, you will also need `--enable-experimental` as well as a flag for each individual module, e.g. `--enable-module-musig`. -Usage examples ------------ - Usage examples can be found in the [examples](examples) directory. To compile them you need to configure with `--enable-examples`. - * [ECDSA example](examples/ecdsa.c) - * [Schnorr signatures example](examples/schnorr.c) - * [Deriving a shared secret (ECDH) example](examples/ecdh.c) - To compile the Schnorr signature and ECDH examples, you also need to configure with `--enable-module-schnorrsig` and `--enable-module-ecdh`. +Building with CMake (experimental) +---------------------------------- -Test coverage ------------ +To maintain a pristine source tree, CMake encourages to perform an out-of-source build by using a separate dedicated build tree. + +### Building on POSIX systems + + $ mkdir build && cd build + $ cmake .. + $ cmake --build . + $ ctest # run the test suite + $ sudo cmake --build . --target install # optional + +To compile optional modules (such as Schnorr signatures), you need to run `cmake` with additional flags (such as `-DSECP256K1_ENABLE_MODULE_SCHNORRSIG=ON`). Run `cmake .. -LH` to see the full list of available flags. -This library aims to have full coverage of the reachable lines and branches. +### Cross compiling -To create a test coverage report, configure with `--enable-coverage` (use of GCC is necessary): +To alleviate issues with cross compiling, preconfigured toolchain files are available in the `cmake` directory. +For example, to cross compile for Windows: - $ ./configure --enable-coverage + $ cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/x86_64-w64-mingw32.toolchain.cmake -Run the tests: +To cross compile for Android with [NDK](https://developer.android.com/ndk/guides/cmake) (using NDK's toolchain file, and assuming the `ANDROID_NDK_ROOT` environment variable has been set): - $ make check + $ cmake .. -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake" -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=28 -To create a report, `gcovr` is recommended, as it includes branch coverage reporting: +### Building on Windows - $ gcovr --exclude 'src/bench*' --print-summary +To build on Windows with Visual Studio, a proper [generator](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#visual-studio-generators) must be specified for a new build tree. -To create a HTML report with coloured and annotated source code: +The following example assumes using of Visual Studio 2022 and CMake v3.21+. - $ mkdir -p coverage - $ gcovr --exclude 'src/bench*' --html --html-details -o coverage/coverage.html +In "Developer Command Prompt for VS 2022": + + >cmake -G "Visual Studio 17 2022" -A x64 -S . -B build + >cmake --build build --config RelWithDebInfo + +Usage examples +----------- + +Usage examples can be found in the [examples](examples) directory. To compile them you need to configure with `--enable-examples`. + * [ECDSA example](examples/ecdsa.c) + * [Schnorr signatures example](examples/schnorr.c) + * [Deriving a shared secret (ECDH) example](examples/ecdh.c) + * [MuSig example](examples/musig.c) + +To compile the Schnorr signature, ECDH and MuSig examples, you need to enable the corresponding module by providing a flag to the `configure` script, for example `--enable-module-schnorrsig`. Benchmark ------------ -If configured with `--enable-benchmark` (which is the default), binaries for benchmarking the libsecp256k1 functions will be present in the root directory after the build. +If configured with `--enable-benchmark` (which is the default), binaries for benchmarking the libsecp256k1-zkp functions will be present in the root directory after the build. To print the benchmark result to the command line: @@ -119,3 +93,8 @@ Reporting a vulnerability ------------ See [SECURITY.md](SECURITY.md) + +Contributing to libsecp256k1 +------------ + +See [CONTRIBUTING.md](CONTRIBUTING.md) diff --git a/secp256k1-zkp-sys/depend/secp256k1/build-aux/m4/bitcoin_secp.m4 b/secp256k1-zkp-sys/depend/secp256k1/build-aux/m4/bitcoin_secp.m4 index dda770e0..11adef4f 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/build-aux/m4/bitcoin_secp.m4 +++ b/secp256k1-zkp-sys/depend/secp256k1/build-aux/m4/bitcoin_secp.m4 @@ -1,15 +1,35 @@ dnl escape "$0x" below using the m4 quadrigaph @S|@, and escape it again with a \ for the shell. -AC_DEFUN([SECP_64BIT_ASM_CHECK],[ +AC_DEFUN([SECP_X86_64_ASM_CHECK],[ AC_MSG_CHECKING(for x86_64 assembly availability) -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include ]],[[ uint64_t a = 11, tmp; __asm__ __volatile__("movq \@S|@0x100000000,%1; mulq %%rsi" : "+a"(a) : "S"(tmp) : "cc", "%rdx"); - ]])],[has_64bit_asm=yes],[has_64bit_asm=no]) -AC_MSG_RESULT([$has_64bit_asm]) + ]])], [has_x86_64_asm=yes], [has_x86_64_asm=no]) +AC_MSG_RESULT([$has_x86_64_asm]) +]) + +AC_DEFUN([SECP_ARM32_ASM_CHECK], [ + AC_MSG_CHECKING(for ARM32 assembly availability) + SECP_ARM32_ASM_CHECK_CFLAGS_saved_CFLAGS="$CFLAGS" + CFLAGS="-x assembler" + AC_LINK_IFELSE([AC_LANG_SOURCE([[ + .syntax unified + .eabi_attribute 24, 1 + .eabi_attribute 25, 1 + .text + .global main + main: + ldr r0, =0x002A + mov r7, #1 + swi 0 + ]])], [has_arm32_asm=yes], [has_arm32_asm=no]) + AC_MSG_RESULT([$has_arm32_asm]) + CFLAGS="$SECP_ARM32_ASM_CHECK_CFLAGS_saved_CFLAGS" ]) AC_DEFUN([SECP_VALGRIND_CHECK],[ +AC_MSG_CHECKING([for valgrind support]) if test x"$has_valgrind" != x"yes"; then CPPFLAGS_TEMP="$CPPFLAGS" CPPFLAGS="$VALGRIND_CPPFLAGS $CPPFLAGS" @@ -19,8 +39,10 @@ if test x"$has_valgrind" != x"yes"; then #if defined(NVALGRIND) # error "Valgrind does not support this platform." #endif - ]])], [has_valgrind=yes; AC_DEFINE(HAVE_VALGRIND,1,[Define this symbol if valgrind is installed, and it supports the host platform])]) + ]])], [has_valgrind=yes]) + CPPFLAGS="$CPPFLAGS_TEMP" fi +AC_MSG_RESULT($has_valgrind) ]) dnl SECP_TRY_APPEND_CFLAGS(flags, VAR) diff --git a/secp256k1-zkp-sys/depend/secp256k1/ci/ci.sh b/secp256k1-zkp-sys/depend/secp256k1/ci/ci.sh new file mode 100755 index 00000000..47c4ae67 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/ci/ci.sh @@ -0,0 +1,156 @@ +#!/bin/sh + +set -eux + +export LC_ALL=C + +# Print commit and relevant CI environment to allow reproducing the job outside of CI. +git show --no-patch +print_environment() { + # Turn off -x because it messes up the output + set +x + # There are many ways to print variable names and their content. This one + # does not rely on bash. + for var in WERROR_CFLAGS MAKEFLAGS BUILD \ + ECMULTWINDOW ECMULTGENPRECISION ASM WIDEMUL WITH_VALGRIND EXTRAFLAGS \ + EXPERIMENTAL ECDH RECOVERY SCHNORRSIG SCHNORRSIG_HALFAGG ELLSWIFT \ + ECDSA_S2C GENERATOR RANGEPROOF WHITELIST MUSIG ECDSAADAPTOR BPPP \ + SECP256K1_TEST_ITERS BENCH SECP256K1_BENCH_ITERS CTIMETESTS\ + EXAMPLES \ + HOST WRAPPER_CMD \ + CC CFLAGS CPPFLAGS AR NM + do + eval "isset=\${$var+x}" + if [ -n "$isset" ]; then + eval "val=\${$var}" + # shellcheck disable=SC2154 + printf '%s="%s" ' "$var" "$val" + fi + done + echo "$0" + set -x +} +print_environment + +env >> test_env.log + +# If gcc is requested, assert that it's in fact gcc (and not some symlinked Apple clang). +case "${CC:-undefined}" in + *gcc*) + $CC -v 2>&1 | grep -q "gcc version" || exit 1; + ;; +esac + +if [ -n "${CC+x}" ]; then + # The MSVC compiler "cl" doesn't understand "-v" + $CC -v || true +fi +if [ "$WITH_VALGRIND" = "yes" ]; then + valgrind --version +fi +if [ -n "$WRAPPER_CMD" ]; then + $WRAPPER_CMD --version +fi + +# Workaround for https://bugs.kde.org/show_bug.cgi?id=452758 (fixed in valgrind 3.20.0). +case "${CC:-undefined}" in + clang*) + if [ "$CTIMETESTS" = "yes" ] && [ "$WITH_VALGRIND" = "yes" ] + then + export CFLAGS="${CFLAGS:+$CFLAGS }-gdwarf-4" + else + case "$WRAPPER_CMD" in + valgrind*) + export CFLAGS="${CFLAGS:+$CFLAGS }-gdwarf-4" + ;; + esac + fi + ;; +esac + +./autogen.sh + +./configure \ + --enable-experimental="$EXPERIMENTAL" \ + --with-test-override-wide-multiply="$WIDEMUL" --with-asm="$ASM" \ + --with-ecmult-window="$ECMULTWINDOW" \ + --with-ecmult-gen-precision="$ECMULTGENPRECISION" \ + --enable-module-ecdh="$ECDH" --enable-module-recovery="$RECOVERY" \ + --enable-module-ellswift="$ELLSWIFT" \ + --enable-module-ecdsa-s2c="$ECDSA_S2C" \ + --enable-module-bppp="$BPPP" \ + --enable-module-rangeproof="$RANGEPROOF" --enable-module-whitelist="$WHITELIST" --enable-module-generator="$GENERATOR" \ + --enable-module-schnorrsig="$SCHNORRSIG" --enable-module-musig="$MUSIG" --enable-module-ecdsa-adaptor="$ECDSAADAPTOR" \ + --enable-module-schnorrsig="$SCHNORRSIG" \ + --enable-module-schnorrsig-halfagg="$SCHNORRSIG_HALFAGG" \ + --enable-examples="$EXAMPLES" \ + --enable-ctime-tests="$CTIMETESTS" \ + --with-valgrind="$WITH_VALGRIND" \ + --host="$HOST" $EXTRAFLAGS + +# We have set "-j" in MAKEFLAGS. +build_exit_code=0 +make > make.log 2>&1 || build_exit_code=$? +cat make.log +if [ $build_exit_code -ne 0 ]; then + case "${CC:-undefined}" in + *snapshot*) + # Ignore internal compiler errors in gcc-snapshot and clang-snapshot + grep -e "internal compiler error:" -e "PLEASE submit a bug report" make.log + return $?; + ;; + *) + return 1; + ;; + esac +fi + +# Print information about binaries so that we can see that the architecture is correct +file *tests* || true +file bench* || true +file .libs/* || true + +# This tells `make check` to wrap test invocations. +export LOG_COMPILER="$WRAPPER_CMD" + +make "$BUILD" + +# Using the local `libtool` because on macOS the system's libtool has nothing to do with GNU libtool +EXEC='./libtool --mode=execute' +if [ -n "$WRAPPER_CMD" ] +then + EXEC="$EXEC $WRAPPER_CMD" +fi + +if [ "$BENCH" = "yes" ] +then + { + $EXEC ./bench_ecmult + $EXEC ./bench_internal + $EXEC ./bench + if [ "$BPPP" = "yes" ] + then + $EXEC ./bench_bppp + fi + } >> bench.log 2>&1 +fi + +if [ "$CTIMETESTS" = "yes" ] +then + if [ "$WITH_VALGRIND" = "yes" ]; then + ./libtool --mode=execute valgrind --error-exitcode=42 ./ctime_tests > ctime_tests.log 2>&1 + else + $EXEC ./ctime_tests > ctime_tests.log 2>&1 + fi +fi + +# Rebuild precomputed files (if not cross-compiling). +if [ -z "$HOST" ] +then + make clean-precomp clean-testvectors + make precomp testvectors +fi + +# Check that no repo files have been modified by the build. +# (This fails for example if the precomp files need to be updated in the repo.) +git diff --exit-code diff --git a/secp256k1-zkp-sys/depend/secp256k1/ci/cirrus.sh b/secp256k1-zkp-sys/depend/secp256k1/ci/cirrus.sh deleted file mode 100755 index 14c8dbe9..00000000 --- a/secp256k1-zkp-sys/depend/secp256k1/ci/cirrus.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/sh - -set -e -set -x - -export LC_ALL=C - -env >> test_env.log - -$CC -v || true -valgrind --version || true - -./autogen.sh - -./configure \ - --enable-experimental="$EXPERIMENTAL" \ - --with-test-override-wide-multiply="$WIDEMUL" --with-asm="$ASM" \ - --with-ecmult-window="$ECMULTWINDOW" \ - --with-ecmult-gen-precision="$ECMULTGENPRECISION" \ - --enable-module-ecdh="$ECDH" --enable-module-recovery="$RECOVERY" \ - --enable-module-ecdsa-s2c="$ECDSA_S2C" \ - --enable-module-bppp="$BPPP" \ - --enable-module-rangeproof="$RANGEPROOF" --enable-module-whitelist="$WHITELIST" --enable-module-generator="$GENERATOR" \ - --enable-module-schnorrsig="$SCHNORRSIG" --enable-module-musig="$MUSIG" --enable-module-ecdsa-adaptor="$ECDSAADAPTOR" \ - --enable-module-schnorrsig="$SCHNORRSIG" \ - --enable-examples="$EXAMPLES" \ - --with-valgrind="$WITH_VALGRIND" \ - --host="$HOST" $EXTRAFLAGS - -# We have set "-j" in MAKEFLAGS. -make - -# Print information about binaries so that we can see that the architecture is correct -file *tests* || true -file bench* || true -file .libs/* || true - -# This tells `make check` to wrap test invocations. -export LOG_COMPILER="$WRAPPER_CMD" - -make "$BUILD" - -if [ "$BENCH" = "yes" ] -then - # Using the local `libtool` because on macOS the system's libtool has nothing to do with GNU libtool - EXEC='./libtool --mode=execute' - if [ -n "$WRAPPER_CMD" ] - then - EXEC="$EXEC $WRAPPER_CMD" - fi - { - $EXEC ./bench_ecmult - $EXEC ./bench_internal - $EXEC ./bench - if [ "$BPPP" = "yes" ] - then - $EXEC ./bench_bppp - fi - } >> bench.log 2>&1 -fi - -if [ "$CTIMETEST" = "yes" ] -then - ./libtool --mode=execute valgrind --error-exitcode=42 ./valgrind_ctime_test > valgrind_ctime_test.log 2>&1 -fi - -# Rebuild precomputed files (if not cross-compiling). -if [ -z "$HOST" ] -then - make clean-precomp - make precomp -fi - -# Check that no repo files have been modified by the build. -# (This fails for example if the precomp files need to be updated in the repo.) -git diff --exit-code diff --git a/secp256k1-zkp-sys/depend/secp256k1/ci/linux-debian.Dockerfile b/secp256k1-zkp-sys/depend/secp256k1/ci/linux-debian.Dockerfile index 5cccbb55..5ce715b4 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/ci/linux-debian.Dockerfile +++ b/secp256k1-zkp-sys/depend/secp256k1/ci/linux-debian.Dockerfile @@ -1,26 +1,79 @@ -FROM debian:stable +FROM debian:stable-slim -RUN dpkg --add-architecture i386 -RUN dpkg --add-architecture s390x -RUN dpkg --add-architecture armhf -RUN dpkg --add-architecture arm64 -RUN dpkg --add-architecture ppc64el -RUN apt-get update +SHELL ["/bin/bash", "-c"] + +WORKDIR /root + +# A too high maximum number of file descriptors (with the default value +# inherited from the docker host) can cause issues with some of our tools: +# - sanitizers hanging: https://github.com/google/sanitizers/issues/1662 +# - valgrind crashing: https://stackoverflow.com/a/75293014 +# This is not be a problem on our CI hosts, but developers who run the image +# on their machines may run into this (e.g., on Arch Linux), so warn them. +# (Note that .bashrc is only executed in interactive bash shells.) +RUN echo 'if [[ $(ulimit -n) -gt 200000 ]]; then echo "WARNING: Very high value reported by \"ulimit -n\". Consider passing \"--ulimit nofile=32768\" to \"docker run\"."; fi' >> /root/.bashrc + +RUN dpkg --add-architecture i386 && \ + dpkg --add-architecture s390x && \ + dpkg --add-architecture armhf && \ + dpkg --add-architecture arm64 && \ + dpkg --add-architecture ppc64el # dkpg-dev: to make pkg-config work in cross-builds # llvm: for llvm-symbolizer, which is used by clang's UBSan for symbolized stack traces -RUN apt-get install --no-install-recommends --no-upgrade -y \ +RUN apt-get update && apt-get install --no-install-recommends -y \ git ca-certificates \ make automake libtool pkg-config dpkg-dev valgrind qemu-user \ - gcc clang llvm libc6-dbg \ + gcc clang llvm libclang-rt-dev libc6-dbg \ g++ \ - gcc-i686-linux-gnu libc6-dev-i386-cross libc6-dbg:i386 libubsan1:i386 libasan6:i386 \ + gcc-i686-linux-gnu libc6-dev-i386-cross libc6-dbg:i386 libubsan1:i386 libasan8:i386 \ gcc-s390x-linux-gnu libc6-dev-s390x-cross libc6-dbg:s390x \ gcc-arm-linux-gnueabihf libc6-dev-armhf-cross libc6-dbg:armhf \ - gcc-aarch64-linux-gnu libc6-dev-arm64-cross libc6-dbg:arm64 \ gcc-powerpc64le-linux-gnu libc6-dev-ppc64el-cross libc6-dbg:ppc64el \ - wine gcc-mingw-w64-x86-64 \ - sagemath + gcc-mingw-w64-x86-64-win32 wine64 wine \ + gcc-mingw-w64-i686-win32 wine32 \ + python3 && \ + if ! ( dpkg --print-architecture | grep --quiet "arm64" ) ; then \ + apt-get install --no-install-recommends -y \ + gcc-aarch64-linux-gnu libc6-dev-arm64-cross libc6-dbg:arm64 ;\ + fi && \ + apt-get clean && rm -rf /var/lib/apt/lists/* + +# Build and install gcc snapshot +ARG GCC_SNAPSHOT_MAJOR=14 +RUN apt-get update && apt-get install --no-install-recommends -y wget libgmp-dev libmpfr-dev libmpc-dev flex && \ + mkdir gcc && cd gcc && \ + wget --progress=dot:giga --https-only --recursive --accept '*.tar.xz' --level 1 --no-directories "https://gcc.gnu.org/pub/gcc/snapshots/LATEST-${GCC_SNAPSHOT_MAJOR}" && \ + wget "https://gcc.gnu.org/pub/gcc/snapshots/LATEST-${GCC_SNAPSHOT_MAJOR}/sha512.sum" && \ + sha512sum --check --ignore-missing sha512.sum && \ + # We should have downloaded exactly one tar.xz file + ls && \ + [ $(ls *.tar.xz | wc -l) -eq "1" ] && \ + tar xf *.tar.xz && \ + mkdir gcc-build && cd gcc-build && \ + ../*/configure --prefix=/opt/gcc-snapshot --enable-languages=c --disable-bootstrap --disable-multilib --without-isl && \ + make -j $(nproc) && \ + make install && \ + cd ../.. && rm -rf gcc && \ + ln -s /opt/gcc-snapshot/bin/gcc /usr/bin/gcc-snapshot && \ + apt-get autoremove -y wget libgmp-dev libmpfr-dev libmpc-dev flex && \ + apt-get clean && rm -rf /var/lib/apt/lists/* + +# Install clang snapshot, see https://apt.llvm.org/ +RUN \ + # Setup GPG keys of LLVM repository + apt-get update && apt-get install --no-install-recommends -y wget && \ + wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc && \ + # Add repository for this Debian release + . /etc/os-release && echo "deb http://apt.llvm.org/${VERSION_CODENAME} llvm-toolchain-${VERSION_CODENAME} main" >> /etc/apt/sources.list && \ + apt-get update && \ + # Determine the version number of the LLVM development branch + LLVM_VERSION=$(apt-cache search --names-only '^clang-[0-9]+$' | sort -V | tail -1 | cut -f1 -d" " | cut -f2 -d"-" ) && \ + # Install + apt-get install --no-install-recommends -y "clang-${LLVM_VERSION}" && \ + # Create symlink + ln -s "/usr/bin/clang-${LLVM_VERSION}" /usr/bin/clang-snapshot && \ + # Clean up + apt-get autoremove -y wget && \ + apt-get clean && rm -rf /var/lib/apt/lists/* -# Run a dummy command in wine to make it set up configuration -RUN wine64-stable xcopy || true diff --git a/secp256k1-zkp-sys/depend/secp256k1/cmake/AllTargetsCompileOptions.cmake b/secp256k1-zkp-sys/depend/secp256k1/cmake/AllTargetsCompileOptions.cmake new file mode 100644 index 00000000..6e420e0f --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/cmake/AllTargetsCompileOptions.cmake @@ -0,0 +1,12 @@ +# Add compile options to all targets added in the subdirectory. +function(all_targets_compile_options dir options) + get_directory_property(targets DIRECTORY ${dir} BUILDSYSTEM_TARGETS) + separate_arguments(options) + set(compiled_target_types STATIC_LIBRARY SHARED_LIBRARY OBJECT_LIBRARY EXECUTABLE) + foreach(target ${targets}) + get_target_property(type ${target} TYPE) + if(type IN_LIST compiled_target_types) + target_compile_options(${target} PRIVATE ${options}) + endif() + endforeach() +endfunction() diff --git a/secp256k1-zkp-sys/depend/secp256k1/cmake/CheckArm32Assembly.cmake b/secp256k1-zkp-sys/depend/secp256k1/cmake/CheckArm32Assembly.cmake new file mode 100644 index 00000000..15c44b24 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/cmake/CheckArm32Assembly.cmake @@ -0,0 +1,6 @@ +function(check_arm32_assembly) + try_compile(HAVE_ARM32_ASM + ${CMAKE_BINARY_DIR}/check_arm32_assembly + SOURCES ${CMAKE_SOURCE_DIR}/cmake/source_arm32.s + ) +endfunction() diff --git a/secp256k1-zkp-sys/depend/secp256k1/cmake/CheckStringOptionValue.cmake b/secp256k1-zkp-sys/depend/secp256k1/cmake/CheckStringOptionValue.cmake new file mode 100644 index 00000000..5a4d939b --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/cmake/CheckStringOptionValue.cmake @@ -0,0 +1,10 @@ +function(check_string_option_value option) + get_property(expected_values CACHE ${option} PROPERTY STRINGS) + if(expected_values) + if(${option} IN_LIST expected_values) + return() + endif() + message(FATAL_ERROR "${option} value is \"${${option}}\", but must be one of ${expected_values}.") + endif() + message(AUTHOR_WARNING "The STRINGS property must be set before invoking `check_string_option_value' function.") +endfunction() diff --git a/secp256k1-zkp-sys/depend/secp256k1/cmake/CheckX86_64Assembly.cmake b/secp256k1-zkp-sys/depend/secp256k1/cmake/CheckX86_64Assembly.cmake new file mode 100644 index 00000000..ae82cd47 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/cmake/CheckX86_64Assembly.cmake @@ -0,0 +1,14 @@ +include(CheckCSourceCompiles) + +function(check_x86_64_assembly) + check_c_source_compiles(" + #include + + int main() + { + uint64_t a = 11, tmp; + __asm__ __volatile__(\"movq $0x100000000,%1; mulq %%rsi\" : \"+a\"(a) : \"S\"(tmp) : \"cc\", \"%rdx\"); + } + " HAVE_X86_64_ASM) + set(HAVE_X86_64_ASM ${HAVE_X86_64_ASM} PARENT_SCOPE) +endfunction() diff --git a/secp256k1-zkp-sys/depend/secp256k1/cmake/FindValgrind.cmake b/secp256k1-zkp-sys/depend/secp256k1/cmake/FindValgrind.cmake new file mode 100644 index 00000000..3af5e691 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/cmake/FindValgrind.cmake @@ -0,0 +1,41 @@ +if(CMAKE_HOST_APPLE) + find_program(BREW_COMMAND brew) + execute_process( + COMMAND ${BREW_COMMAND} --prefix valgrind + OUTPUT_VARIABLE valgrind_brew_prefix + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +endif() + +set(hints_paths) +if(valgrind_brew_prefix) + set(hints_paths ${valgrind_brew_prefix}/include) +endif() + +find_path(Valgrind_INCLUDE_DIR + NAMES valgrind/memcheck.h + HINTS ${hints_paths} +) + +if(Valgrind_INCLUDE_DIR) + include(CheckCSourceCompiles) + set(CMAKE_REQUIRED_INCLUDES ${Valgrind_INCLUDE_DIR}) + check_c_source_compiles(" + #include + #if defined(NVALGRIND) + # error \"Valgrind does not support this platform.\" + #endif + + int main() {} + " Valgrind_WORKS) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Valgrind + REQUIRED_VARS Valgrind_INCLUDE_DIR Valgrind_WORKS +) + +mark_as_advanced( + Valgrind_INCLUDE_DIR +) diff --git a/secp256k1-zkp-sys/depend/secp256k1/cmake/GeneratePkgConfigFile.cmake b/secp256k1-zkp-sys/depend/secp256k1/cmake/GeneratePkgConfigFile.cmake new file mode 100644 index 00000000..9c1d7f1d --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/cmake/GeneratePkgConfigFile.cmake @@ -0,0 +1,8 @@ +function(generate_pkg_config_file in_file) + set(prefix ${CMAKE_INSTALL_PREFIX}) + set(exec_prefix \${prefix}) + set(libdir \${exec_prefix}/${CMAKE_INSTALL_LIBDIR}) + set(includedir \${prefix}/${CMAKE_INSTALL_INCLUDEDIR}) + set(PACKAGE_VERSION ${PROJECT_VERSION}) + configure_file(${in_file} ${PROJECT_NAME}.pc @ONLY) +endfunction() diff --git a/secp256k1-zkp-sys/depend/secp256k1/cmake/TryAppendCFlags.cmake b/secp256k1-zkp-sys/depend/secp256k1/cmake/TryAppendCFlags.cmake new file mode 100644 index 00000000..bdda0a34 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/cmake/TryAppendCFlags.cmake @@ -0,0 +1,24 @@ +include(CheckCCompilerFlag) + +function(rustsecp256k1zkp_v0_10_0_check_c_flags_internal flags output) + string(MAKE_C_IDENTIFIER "${flags}" result) + string(TOUPPER "${result}" result) + set(result "C_SUPPORTS_${result}") + if(NOT MSVC) + set(CMAKE_REQUIRED_FLAGS "-Werror") + endif() + + # This avoids running a linker. + set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + check_c_compiler_flag("${flags}" ${result}) + + set(${output} ${${result}} PARENT_SCOPE) +endfunction() + +# Append flags to the COMPILE_OPTIONS directory property if CC accepts them. +macro(try_append_c_flags) + rustsecp256k1zkp_v0_10_0_check_c_flags_internal("${ARGV}" result) + if(result) + add_compile_options(${ARGV}) + endif() +endmacro() diff --git a/secp256k1-zkp-sys/depend/secp256k1/cmake/arm-linux-gnueabihf.toolchain.cmake b/secp256k1-zkp-sys/depend/secp256k1/cmake/arm-linux-gnueabihf.toolchain.cmake new file mode 100644 index 00000000..0d91912b --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/cmake/arm-linux-gnueabihf.toolchain.cmake @@ -0,0 +1,3 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR arm) +set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc) diff --git a/secp256k1-zkp-sys/depend/secp256k1/cmake/config.cmake.in b/secp256k1-zkp-sys/depend/secp256k1/cmake/config.cmake.in new file mode 100644 index 00000000..46b180ab --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/cmake/config.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake") + +check_required_components(@PROJECT_NAME@) diff --git a/secp256k1-zkp-sys/depend/secp256k1/cmake/source_arm32.s b/secp256k1-zkp-sys/depend/secp256k1/cmake/source_arm32.s new file mode 100644 index 00000000..d3d93470 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/cmake/source_arm32.s @@ -0,0 +1,9 @@ +.syntax unified +.eabi_attribute 24, 1 +.eabi_attribute 25, 1 +.text +.global main +main: + ldr r0, =0x002A + mov r7, #1 + swi 0 diff --git a/secp256k1-zkp-sys/depend/secp256k1/cmake/x86_64-w64-mingw32.toolchain.cmake b/secp256k1-zkp-sys/depend/secp256k1/cmake/x86_64-w64-mingw32.toolchain.cmake new file mode 100644 index 00000000..96119b72 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/cmake/x86_64-w64-mingw32.toolchain.cmake @@ -0,0 +1,3 @@ +set(CMAKE_SYSTEM_NAME Windows) +set(CMAKE_SYSTEM_PROCESSOR x86_64) +set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) diff --git a/secp256k1-zkp-sys/depend/secp256k1/configure.ac b/secp256k1-zkp-sys/depend/secp256k1/configure.ac index c168694c..4d2a6e67 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/configure.ac +++ b/secp256k1-zkp-sys/depend/secp256k1/configure.ac @@ -5,7 +5,7 @@ AC_PREREQ([2.60]) # backwards-compatible and therefore at most increase the minor version. define(_PKG_VERSION_MAJOR, 0) define(_PKG_VERSION_MINOR, 1) -define(_PKG_VERSION_BUILD, 0) +define(_PKG_VERSION_PATCH, 0) define(_PKG_VERSION_IS_RELEASE, false) # The library version is based on libtool versioning of the ABI. The set of @@ -17,14 +17,11 @@ define(_LIB_VERSION_CURRENT, 0) define(_LIB_VERSION_REVISION, 0) define(_LIB_VERSION_AGE, 0) -AC_INIT([libsecp256k1],m4_join([.], _PKG_VERSION_MAJOR, _PKG_VERSION_MINOR, _PKG_VERSION_BUILD)m4_if(_PKG_VERSION_IS_RELEASE, [true], [], [-pre]),[https://github.com/bitcoin-core/secp256k1/issues],[libsecp256k1],[https://github.com/bitcoin-core/secp256k1]) +AC_INIT([libsecp256k1],m4_join([.], _PKG_VERSION_MAJOR, _PKG_VERSION_MINOR, _PKG_VERSION_PATCH)m4_if(_PKG_VERSION_IS_RELEASE, [true], [], [-dev]),[https://github.com/bitcoin-core/secp256k1/issues],[libsecp256k1],[https://github.com/bitcoin-core/secp256k1]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([build-aux/m4]) AC_CANONICAL_HOST -AH_TOP([#ifndef LIBSECP256K1_CONFIG_H]) -AH_TOP([#define LIBSECP256K1_CONFIG_H]) -AH_BOTTOM([#endif /*LIBSECP256K1_CONFIG_H*/]) # Require Automake 1.11.2 for AM_PROG_AR AM_INIT_AUTOMAKE([1.11.2 foreign subdir-objects]) @@ -32,13 +29,20 @@ AM_INIT_AUTOMAKE([1.11.2 foreign subdir-objects]) # Make the compilation flags quiet unless V=1 is used. m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) -AC_PROG_CC -if test x"$ac_cv_prog_cc_c89" = x"no"; then - AC_MSG_ERROR([c89 compiler support required]) +if test "${CFLAGS+set}" = "set"; then + CFLAGS_overridden=yes +else + CFLAGS_overridden=no fi +AC_PROG_CC AM_PROG_AS AM_PROG_AR +# Clear some cache variables as a workaround for a bug that appears due to a bad +# interaction between AM_PROG_AR and LT_INIT when combining MSVC's archiver lib.exe. +# https://debbugs.gnu.org/cgi/bugreport.cgi?bug=54421 +AS_UNSET(ac_cv_prog_AR) +AS_UNSET(ac_cv_prog_ac_ct_AR) LT_INIT([win32-dll]) build_windows=no @@ -87,23 +91,43 @@ esac # # TODO We should analogously not touch CPPFLAGS and LDFLAGS but currently there are no issues. AC_DEFUN([SECP_TRY_APPEND_DEFAULT_CFLAGS], [ - # Try to append -Werror=unknown-warning-option to CFLAGS temporarily. Otherwise clang will - # not error out if it gets unknown warning flags and the checks here will always succeed - # no matter if clang knows the flag or not. - SECP_TRY_APPEND_DEFAULT_CFLAGS_saved_CFLAGS="$CFLAGS" - SECP_TRY_APPEND_CFLAGS([-Werror=unknown-warning-option], CFLAGS) - - SECP_TRY_APPEND_CFLAGS([-std=c89 -pedantic -Wno-long-long -Wnested-externs -Wshadow -Wstrict-prototypes -Wundef], $1) # GCC >= 3.0, -Wlong-long is implied by -pedantic. - SECP_TRY_APPEND_CFLAGS([-Wno-overlength-strings], $1) # GCC >= 4.2, -Woverlength-strings is implied by -pedantic. - SECP_TRY_APPEND_CFLAGS([-Wall], $1) # GCC >= 2.95 and probably many other compilers - SECP_TRY_APPEND_CFLAGS([-Wno-unused-function], $1) # GCC >= 3.0, -Wunused-function is implied by -Wall. - SECP_TRY_APPEND_CFLAGS([-Wextra], $1) # GCC >= 3.4, this is the newer name of -W, which we don't use because older GCCs will warn about unused functions. - SECP_TRY_APPEND_CFLAGS([-Wcast-align], $1) # GCC >= 2.95 - SECP_TRY_APPEND_CFLAGS([-Wcast-align=strict], $1) # GCC >= 8.0 - SECP_TRY_APPEND_CFLAGS([-Wconditional-uninitialized], $1) # Clang >= 3.0 only - SECP_TRY_APPEND_CFLAGS([-fvisibility=hidden], $1) # GCC >= 4.0 - - CFLAGS="$SECP_TRY_APPEND_DEFAULT_CFLAGS_saved_CFLAGS" + # GCC and compatible (incl. clang) + if test "x$GCC" = "xyes"; then + # Try to append -Werror to CFLAGS temporarily. Otherwise checks for some unsupported + # flags will succeed. + # Note that failure to append -Werror does not necessarily mean that -Werror is not + # supported. The compiler may already be warning about something unrelated, for example + # about some path issue. If that is the case, -Werror cannot be used because all + # of those warnings would be turned into errors. + SECP_TRY_APPEND_DEFAULT_CFLAGS_saved_CFLAGS="$CFLAGS" + SECP_TRY_APPEND_CFLAGS([-Werror], CFLAGS) + + SECP_TRY_APPEND_CFLAGS([-std=c89 -pedantic -Wno-long-long -Wnested-externs -Wshadow -Wstrict-prototypes -Wundef], $1) # GCC >= 3.0, -Wlong-long is implied by -pedantic. + SECP_TRY_APPEND_CFLAGS([-Wno-overlength-strings], $1) # GCC >= 4.2, -Woverlength-strings is implied by -pedantic. + SECP_TRY_APPEND_CFLAGS([-Wall], $1) # GCC >= 2.95 and probably many other compilers + SECP_TRY_APPEND_CFLAGS([-Wno-unused-function], $1) # GCC >= 3.0, -Wunused-function is implied by -Wall. + SECP_TRY_APPEND_CFLAGS([-Wextra], $1) # GCC >= 3.4, this is the newer name of -W, which we don't use because older GCCs will warn about unused functions. + SECP_TRY_APPEND_CFLAGS([-Wcast-align], $1) # GCC >= 2.95 + SECP_TRY_APPEND_CFLAGS([-Wcast-align=strict], $1) # GCC >= 8.0 + SECP_TRY_APPEND_CFLAGS([-Wconditional-uninitialized], $1) # Clang >= 3.0 only + SECP_TRY_APPEND_CFLAGS([-Wreserved-identifier], $1) # Clang >= 13.0 only + SECP_TRY_APPEND_CFLAGS([-fvisibility=hidden], $1) # GCC >= 4.0 + + CFLAGS="$SECP_TRY_APPEND_DEFAULT_CFLAGS_saved_CFLAGS" + fi + + # MSVC + # Assume MSVC if we're building for Windows but not with GCC or compatible; + # libtool makes the same assumption internally. + # Note that "/opt" and "-opt" are equivalent for MSVC; we use "-opt" because "/opt" looks like a path. + if test x"$GCC" != x"yes" && test x"$build_windows" = x"yes"; then + SECP_TRY_APPEND_CFLAGS([-W3], $1) # Production quality warning level. + SECP_TRY_APPEND_CFLAGS([-wd4146], $1) # Disable warning C4146 "unary minus operator applied to unsigned type, result still unsigned". + SECP_TRY_APPEND_CFLAGS([-wd4244], $1) # Disable warning C4244 "'conversion' conversion from 'type1' to 'type2', possible loss of data". + SECP_TRY_APPEND_CFLAGS([-wd4267], $1) # Disable warning C4267 "'var' : conversion from 'size_t' to 'type', possible loss of data". + # Eliminate deprecation warnings for the older, less secure functions. + CPPFLAGS="-D_CRT_SECURE_NO_WARNINGS $CPPFLAGS" + fi ]) SECP_TRY_APPEND_DEFAULT_CFLAGS(SECP_CFLAGS) @@ -128,6 +152,10 @@ AC_ARG_ENABLE(tests, AS_HELP_STRING([--enable-tests],[compile tests [default=yes]]), [], [SECP_SET_DEFAULT([enable_tests], [yes], [yes])]) +AC_ARG_ENABLE(ctime_tests, + AS_HELP_STRING([--enable-ctime-tests],[compile constant-time tests [default=yes if valgrind enabled]]), [], + [SECP_SET_DEFAULT([enable_ctime_tests], [auto], [auto])]) + AC_ARG_ENABLE(experimental, AS_HELP_STRING([--enable-experimental],[allow experimental configure options [default=no]]), [], [SECP_SET_DEFAULT([enable_experimental], [no], [yes])]) @@ -140,24 +168,30 @@ AC_ARG_ENABLE(examples, AS_HELP_STRING([--enable-examples],[compile the examples [default=no]]), [], [SECP_SET_DEFAULT([enable_examples], [no], [yes])]) -AC_ARG_ENABLE(module_bppp, - AS_HELP_STRING([--enable-module-bppp],[enable Bulletproofs++ module (experimental)]), - [], - [SECP_SET_DEFAULT([enable_module_bppp], [no], [yes])]) - AC_ARG_ENABLE(module_ecdh, - AS_HELP_STRING([--enable-module-ecdh],[enable ECDH module [default=no]]), [], - [SECP_SET_DEFAULT([enable_module_ecdh], [no], [yes])]) - -AC_ARG_ENABLE(module_musig, - AS_HELP_STRING([--enable-module-musig],[enable MuSig module (experimental)]), - [], - [SECP_SET_DEFAULT([enable_module_musig], [no], [yes])]) + AS_HELP_STRING([--enable-module-ecdh],[enable ECDH module [default=yes]]), [], + [SECP_SET_DEFAULT([enable_module_ecdh], [yes], [yes])]) AC_ARG_ENABLE(module_recovery, AS_HELP_STRING([--enable-module-recovery],[enable ECDSA pubkey recovery module [default=no]]), [], [SECP_SET_DEFAULT([enable_module_recovery], [no], [yes])]) +AC_ARG_ENABLE(module_extrakeys, + AS_HELP_STRING([--enable-module-extrakeys],[enable extrakeys module [default=yes]]), [], + [SECP_SET_DEFAULT([enable_module_extrakeys], [yes], [yes])]) + +AC_ARG_ENABLE(module_schnorrsig, + AS_HELP_STRING([--enable-module-schnorrsig],[enable schnorrsig module [default=yes]]), [], + [SECP_SET_DEFAULT([enable_module_schnorrsig], [yes], [yes])]) + +AC_ARG_ENABLE(module_schnorrsig_halfagg, + AS_HELP_STRING([--enable-module-schnorrsig-halfagg],[enable schnorrsig half-aggregation module (experimental) [default=no]]), [], + [SECP_SET_DEFAULT([enable_module_schnorrsig_halfagg], [no], [yes])]) + +AC_ARG_ENABLE(module_ellswift, + AS_HELP_STRING([--enable-module-ellswift],[enable ElligatorSwift module [default=yes]]), [], + [SECP_SET_DEFAULT([enable_module_ellswift], [yes], [yes])]) + AC_ARG_ENABLE(module_generator, AS_HELP_STRING([--enable-module-generator],[enable NUMS generator module [default=no]]), [], @@ -168,24 +202,35 @@ AC_ARG_ENABLE(module_rangeproof, [], [SECP_SET_DEFAULT([enable_module_rangeproof], [no], [yes])]) +AC_ARG_ENABLE(module_surjectionproof, + AS_HELP_STRING([--enable-module-surjectionproof],[enable surjection proof module [default=no]]), + [], + [SECP_SET_DEFAULT([enable_module_surjectionproof], [no], [yes])]) +AC_ARG_ENABLE(reduced_surjection_proof_size, + AS_HELP_STRING([--enable-reduced-surjection-proof-size],[use reduced surjection proof size (disabling parsing and verification) [default=no]]), + [], + [SECP_SET_DEFAULT([enable_reduced_surjection_proof_size], [no], [no])]) + AC_ARG_ENABLE(module_whitelist, AS_HELP_STRING([--enable-module-whitelist],[enable key whitelisting module [default=no]]), [], [SECP_SET_DEFAULT([enable_module_whitelist], [no], [yes])]) -AC_ARG_ENABLE(module_extrakeys, - AS_HELP_STRING([--enable-module-extrakeys],[enable extrakeys module [default=no]]), [], - [SECP_SET_DEFAULT([enable_module_extrakeys], [no], [yes])]) - -AC_ARG_ENABLE(module_schnorrsig, - AS_HELP_STRING([--enable-module-schnorrsig],[enable schnorrsig module [default=no]]), [], - [SECP_SET_DEFAULT([enable_module_schnorrsig], [no], [yes])]) +AC_ARG_ENABLE(module_musig, + AS_HELP_STRING([--enable-module-musig],[enable MuSig module (experimental)]), + [], + [SECP_SET_DEFAULT([enable_module_musig], [no], [yes])]) AC_ARG_ENABLE(module_ecdsa_s2c, AS_HELP_STRING([--enable-module-ecdsa-s2c],[enable ECDSA sign-to-contract module [default=no]]), [], [SECP_SET_DEFAULT([enable_module_ecdsa_s2c], [no], [yes])]) +AC_ARG_ENABLE(module_bppp, + AS_HELP_STRING([--enable-module-bppp],[enable Bulletproofs++ module (experimental)]), + [], + [SECP_SET_DEFAULT([enable_module_bppp], [no], [yes])]) + AC_ARG_ENABLE(module_ecdsa-adaptor, AS_HELP_STRING([--enable-module-ecdsa-adaptor],[enable ECDSA adaptor module [default=no]]), [], @@ -195,22 +240,16 @@ AC_ARG_ENABLE(external_default_callbacks, AS_HELP_STRING([--enable-external-default-callbacks],[enable external default callback functions [default=no]]), [], [SECP_SET_DEFAULT([enable_external_default_callbacks], [no], [no])]) -AC_ARG_ENABLE(module_surjectionproof, - AS_HELP_STRING([--enable-module-surjectionproof],[enable surjection proof module [default=no]]), - [], - [SECP_SET_DEFAULT([enable_module_surjectionproof], [no], [yes])]) - -AC_ARG_ENABLE(reduced_surjection_proof_size, - AS_HELP_STRING([--enable-reduced-surjection-proof-size],[use reduced surjection proof size (disabling parsing and verification) [default=no]]), - [], - [SECP_SET_DEFAULT([use_reduced_surjection_proof_size], [no], [no])]) - # Test-only override of the (autodetected by the C code) "widemul" setting. -# Legal values are int64 (for [u]int64_t), int128 (for [unsigned] __int128), and auto (the default). +# Legal values are: +# * int64 (for [u]int64_t), +# * int128 (for [unsigned] __int128), +# * int128_struct (for int128 implemented as a structure), +# * and auto (the default). AC_ARG_WITH([test-override-wide-multiply], [] ,[set_widemul=$withval], [set_widemul=auto]) -AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|arm|no|auto], -[assembly optimizations to use (experimental: arm) [default=auto]])],[req_asm=$withval], [req_asm=auto]) +AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|arm32|no|auto], +[assembly to use (experimental: arm32) [default=auto]])],[req_asm=$withval], [req_asm=auto]) AC_ARG_WITH([ecmult-window], [AS_HELP_STRING([--with-ecmult-window=SIZE|auto], [window size for ecmult precomputation for verification, specified as integer in range [2..24].] @@ -252,11 +291,20 @@ else enable_valgrind=yes fi fi -AM_CONDITIONAL([VALGRIND_ENABLED],[test "$enable_valgrind" = "yes"]) + +if test x"$enable_ctime_tests" = x"auto"; then + enable_ctime_tests=$enable_valgrind +fi if test x"$enable_coverage" = x"yes"; then - AC_DEFINE(COVERAGE, 1, [Define this symbol to compile out all VERIFY code]) + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DCOVERAGE=1" SECP_CFLAGS="-O0 --coverage $SECP_CFLAGS" + # If coverage is enabled, and the user has not overridden CFLAGS, + # override Autoconf's value "-g -O2" with "-g". Otherwise we'd end up + # with "-O0 --coverage -g -O2". + if test "$CFLAGS_overridden" = "no"; then + CFLAGS="-g" + fi LDFLAGS="--coverage $LDFLAGS" else # Most likely the CFLAGS already contain -O2 because that is autoconf's default. @@ -267,19 +315,19 @@ fi AC_MSG_CHECKING([for __builtin_popcount]) AC_LINK_IFELSE([AC_LANG_SOURCE([[void myfunc() {__builtin_popcount(0);}]])], - [ AC_MSG_RESULT([yes]);AC_DEFINE(HAVE_BUILTIN_POPCOUNT,1,[Define this symbol if __builtin_popcount is available]) ], + [ AC_MSG_RESULT([yes]); SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DHAVE_BUILTIN_POPCOUNT=1"], [ AC_MSG_RESULT([no]) ]) AC_MSG_CHECKING([for __builtin_clzll]) AC_LINK_IFELSE([AC_LANG_SOURCE([[void myfunc() { __builtin_clzll(1);}]])], - [ AC_MSG_RESULT([yes]);AC_DEFINE(HAVE_BUILTIN_CLZLL,1,[Define this symbol if __builtin_clzll is available]) ], + [ AC_MSG_RESULT([yes]); SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DHAVE_BUILTIN_CLZLL=1"], [ AC_MSG_RESULT([no]) ]) if test x"$req_asm" = x"auto"; then - SECP_64BIT_ASM_CHECK - if test x"$has_64bit_asm" = x"yes"; then + SECP_X86_64_ASM_CHECK + if test x"$has_x86_64_asm" = x"yes"; then set_asm=x86_64 fi if test x"$set_asm" = x; then @@ -289,50 +337,57 @@ else set_asm=$req_asm case $set_asm in x86_64) - SECP_64BIT_ASM_CHECK - if test x"$has_64bit_asm" != x"yes"; then - AC_MSG_ERROR([x86_64 assembly optimization requested but not available]) + SECP_X86_64_ASM_CHECK + if test x"$has_x86_64_asm" != x"yes"; then + AC_MSG_ERROR([x86_64 assembly requested but not available]) fi ;; - arm) + arm32) + SECP_ARM32_ASM_CHECK + if test x"$has_arm32_asm" != x"yes"; then + AC_MSG_ERROR([ARM32 assembly requested but not available]) + fi ;; no) ;; *) - AC_MSG_ERROR([invalid assembly optimization selection]) + AC_MSG_ERROR([invalid assembly selection]) ;; esac fi -# Select assembly optimization +# Select assembly enable_external_asm=no case $set_asm in x86_64) - AC_DEFINE(USE_ASM_X86_64, 1, [Define this symbol to enable x86_64 assembly optimizations]) + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_ASM_X86_64=1" ;; -arm) +arm32) enable_external_asm=yes ;; no) ;; *) - AC_MSG_ERROR([invalid assembly optimizations]) + AC_MSG_ERROR([invalid assembly selection]) ;; esac if test x"$enable_external_asm" = x"yes"; then - AC_DEFINE(USE_EXTERNAL_ASM, 1, [Define this symbol if an external (non-inline) assembly implementation is used]) + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_EXTERNAL_ASM=1" fi # Select wide multiplication implementation case $set_widemul in +int128_struct) + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_FORCE_WIDEMUL_INT128_STRUCT=1" + ;; int128) - AC_DEFINE(USE_FORCE_WIDEMUL_INT128, 1, [Define this symbol to force the use of the (unsigned) __int128 based wide multiplication implementation]) + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_FORCE_WIDEMUL_INT128=1" ;; int64) - AC_DEFINE(USE_FORCE_WIDEMUL_INT64, 1, [Define this symbol to force the use of the (u)int64_t based wide multiplication implementation]) + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_FORCE_WIDEMUL_INT64=1" ;; auto) ;; @@ -359,7 +414,7 @@ case $set_ecmult_window in # not in range AC_MSG_ERROR($error_window_size) fi - AC_DEFINE_UNQUOTED(ECMULT_WINDOW_SIZE, $set_ecmult_window, [Set window size for ecmult precomputation]) + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DECMULT_WINDOW_SIZE=$set_ecmult_window" ;; esac @@ -372,7 +427,7 @@ fi case $set_ecmult_gen_precision in 2|4|8) - AC_DEFINE_UNQUOTED(ECMULT_GEN_PREC_BITS, $set_ecmult_gen_precision, [Set ecmult gen precision bits]) + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DECMULT_GEN_PREC_BITS=$set_ecmult_gen_precision" ;; *) AC_MSG_ERROR(['ecmult gen precision not 2, 4, 8 or "auto"']) @@ -380,80 +435,107 @@ case $set_ecmult_gen_precision in esac if test x"$enable_valgrind" = x"yes"; then - SECP_INCLUDES="$SECP_INCLUDES $VALGRIND_CPPFLAGS" + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES $VALGRIND_CPPFLAGS -DVALGRIND" fi -# Add -Werror and similar flags passed from the outside (for testing, e.g., in CI) +# Add -Werror and similar flags passed from the outside (for testing, e.g., in CI). +# We don't want to set the user variable CFLAGS in CI because this would disable +# autoconf's logic for setting default CFLAGS, which we would like to test in CI. SECP_CFLAGS="$SECP_CFLAGS $WERROR_CFLAGS" ### ### Handle module options ### -# Besides testing whether modules are enabled, the following code also enables -# module dependencies. The order of the tests matters: the dependency must be -# tested first. +# Processing must be done in a reverse topological sorting of the dependency graph +# (dependent module first). +if test x"$enable_module_schnorrsig_halfagg" = x"yes"; then + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_SCHNORRSIG_HALFAGG=1" + enable_module_schnorrsig=yes +fi -if test x"$enable_module_ecdh" = x"yes"; then - AC_DEFINE(ENABLE_MODULE_ECDH, 1, [Define this symbol to enable the ECDH module]) +if test x"$enable_module_bppp" = x"yes"; then + if test x"$enable_module_generator" = x"no"; then + AC_MSG_ERROR([Module dependency error: You have disabled the generator module explicitly, but it is required by the bppp module.]) + fi + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_BPPP=1" + enable_module_generator=yes fi -if test x"$enable_module_musig" = x"yes"; then - AC_DEFINE(ENABLE_MODULE_MUSIG, 1, [Define this symbol to enable the MuSig module]) - enable_module_schnorrsig=yes +if test x"$enable_module_ecdsa_s2c" = x"yes"; then + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ECDSA_S2C=1" fi -if test x"$enable_module_recovery" = x"yes"; then - AC_DEFINE(ENABLE_MODULE_RECOVERY, 1, [Define this symbol to enable the ECDSA pubkey recovery module]) +if test x"$enable_module_ecdsa_adaptor" = x"yes"; then + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ECDSA_ADAPTOR=1" +fi + +if test x"$enable_module_musig" = x"yes"; then + if test x"$enable_module_schnorrsig" = x"no"; then + AC_MSG_ERROR([Module dependency error: You have disabled the schnorrsig module explicitly, but it is required by the musig module.]) + fi + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_MUSIG=1" + enable_module_schnorrsig=yes fi if test x"$enable_module_whitelist" = x"yes"; then + if test x"$enable_module_rangeproof" = x"no"; then + AC_MSG_ERROR([Module dependency error: You have disabled the rangeproof module explicitly, but it is required by the whitelist module.]) + fi + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_WHITELIST=1" enable_module_rangeproof=yes - AC_DEFINE(ENABLE_MODULE_WHITELIST, 1, [Define this symbol to enable the key whitelisting module]) fi if test x"$enable_module_surjectionproof" = x"yes"; then + if test x"$enable_module_rangeproof" = x"no"; then + AC_MSG_ERROR([Module dependency error: You have disabled the rangeproof module explicitly, but it is required by the surjectionproof module.]) + fi + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_SURJECTIONPROOF=1" enable_module_rangeproof=yes - AC_DEFINE(ENABLE_MODULE_SURJECTIONPROOF, 1, [Define this symbol to enable the surjection proof module]) fi if test x"$enable_module_rangeproof" = x"yes"; then + if test x"$enable_module_generator" = x"no"; then + AC_MSG_ERROR([Module dependency error: You have disabled the generator module explicitly, but it is required by the rangeproof module.]) + fi + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_RANGEPROOF=1" enable_module_generator=yes - AC_DEFINE(ENABLE_MODULE_RANGEPROOF, 1, [Define this symbol to enable the Pedersen / zero knowledge range proof module]) fi -if test x"$enable_module_bppp" = x"yes"; then - enable_module_generator=yes - AC_DEFINE(ENABLE_MODULE_BPPP, 1, [Define this symbol to enable the Bulletproofs++ module]) +if test x"$enable_module_generator" = x"yes"; then + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_GENERATOR=1" fi -if test x"$enable_module_generator" = x"yes"; then - AC_DEFINE(ENABLE_MODULE_GENERATOR, 1, [Define this symbol to enable the NUMS generator module]) +if test x"$enable_module_ellswift" = x"yes"; then + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ELLSWIFT=1" fi if test x"$enable_module_schnorrsig" = x"yes"; then - AC_DEFINE(ENABLE_MODULE_SCHNORRSIG, 1, [Define this symbol to enable the schnorrsig module]) + if test x"$enable_module_extrakeys" = x"no"; then + AC_MSG_ERROR([Module dependency error: You have disabled the extrakeys module explicitly, but it is required by the schnorrsig module.]) + fi enable_module_extrakeys=yes + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_SCHNORRSIG=1" fi if test x"$enable_module_extrakeys" = x"yes"; then - AC_DEFINE(ENABLE_MODULE_EXTRAKEYS, 1, [Define this symbol to enable the extrakeys module]) + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_EXTRAKEYS=1" fi -if test x"$enable_module_ecdsa_s2c" = x"yes"; then - AC_DEFINE(ENABLE_MODULE_ECDSA_S2C, 1, [Define this symbol to enable the ECDSA sign-to-contract module]) +if test x"$enable_module_recovery" = x"yes"; then + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_RECOVERY=1" fi -if test x"$enable_external_default_callbacks" = x"yes"; then - AC_DEFINE(USE_EXTERNAL_DEFAULT_CALLBACKS, 1, [Define this symbol if an external implementation of the default callbacks is used]) +if test x"$enable_module_ecdh" = x"yes"; then + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ECDH=1" fi -if test x"$use_reduced_surjection_proof_size" = x"yes"; then - AC_DEFINE(USE_REDUCED_SURJECTION_PROOF_SIZE, 1, [Define this symbol to reduce SECP256K1_SURJECTIONPROOF_MAX_N_INPUTS to 16, disabling parsing and verification]) +if test x"$enable_external_default_callbacks" = x"yes"; then + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" fi -if test x"$enable_module_ecdsa_adaptor" = x"yes"; then - AC_DEFINE(ENABLE_MODULE_ECDSA_ADAPTOR, 1, [Define this symbol to enable the ECDSA adaptor module]) +if test x"$enable_reduced_surjection_proof_size" = x"yes"; then + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_REDUCED_SURJECTION_PROOF_SIZE=1" fi ### @@ -470,9 +552,21 @@ else # module (which automatically enables the module dependencies) we want to # print an error for the dependent module, not the module dependency. Hence, # we first test dependent modules. + if test x"$enable_module_schnorrsig_halfagg" = x"yes"; then + AC_MSG_ERROR([Schnorrsig Half-Aggregation module is experimental. Use --enable-experimental to allow.]) + fi if test x"$enable_module_bppp" = x"yes"; then AC_MSG_ERROR([Bulletproofs++ module is experimental. Use --enable-experimental to allow.]) fi + if test x"$enable_module_ecdsa_adaptor" = x"yes"; then + AC_MSG_ERROR([ecdsa adaptor signatures module is experimental. Use --enable-experimental to allow.]) + fi + if test x"$enable_module_ecdsa_s2c" = x"yes"; then + AC_MSG_ERROR([ECDSA sign-to-contract module module is experimental. Use --enable-experimental to allow.]) + fi + if test x"$enable_module_musig" = x"yes"; then + AC_MSG_ERROR([MuSig module is experimental. Use --enable-experimental to allow.]) + fi if test x"$enable_module_whitelist" = x"yes"; then AC_MSG_ERROR([Key whitelisting module is experimental. Use --enable-experimental to allow.]) fi @@ -485,17 +579,8 @@ else if test x"$enable_module_generator" = x"yes"; then AC_MSG_ERROR([NUMS generator module is experimental. Use --enable-experimental to allow.]) fi - if test x"$enable_module_musig" = x"yes"; then - AC_MSG_ERROR([MuSig module is experimental. Use --enable-experimental to allow.]) - fi - if test x"$enable_module_ecdsa_s2c" = x"yes"; then - AC_MSG_ERROR([ECDSA sign-to-contract module module is experimental. Use --enable-experimental to allow.]) - fi - if test x"$enable_module_ecdsa_adaptor" = x"yes"; then - AC_MSG_ERROR([ecdsa adaptor signatures module is experimental. Use --enable-experimental to allow.]) - fi - if test x"$set_asm" = x"arm"; then - AC_MSG_ERROR([ARM assembly optimization is experimental. Use --enable-experimental to allow.]) + if test x"$set_asm" = x"arm32"; then + AC_MSG_ERROR([ARM32 assembly is experimental. Use --enable-experimental to allow.]) fi fi @@ -503,33 +588,32 @@ fi ### Generate output ### -AC_CONFIG_HEADERS([src/libsecp256k1-config.h]) AC_CONFIG_FILES([Makefile libsecp256k1.pc]) -AC_SUBST(SECP_INCLUDES) -AC_SUBST(SECP_LIBS) -AC_SUBST(SECP_TEST_LIBS) -AC_SUBST(SECP_TEST_INCLUDES) AC_SUBST(SECP_CFLAGS) +AC_SUBST(SECP_CONFIG_DEFINES) AM_CONDITIONAL([ENABLE_COVERAGE], [test x"$enable_coverage" = x"yes"]) AM_CONDITIONAL([USE_TESTS], [test x"$enable_tests" != x"no"]) +AM_CONDITIONAL([USE_CTIME_TESTS], [test x"$enable_ctime_tests" = x"yes"]) AM_CONDITIONAL([USE_EXHAUSTIVE_TESTS], [test x"$enable_exhaustive_tests" != x"no"]) AM_CONDITIONAL([USE_EXAMPLES], [test x"$enable_examples" != x"no"]) AM_CONDITIONAL([USE_BENCHMARK], [test x"$enable_benchmark" = x"yes"]) -AM_CONDITIONAL([ENABLE_MODULE_BPPP], [test x"$enable_module_bppp" = x"yes"]) AM_CONDITIONAL([ENABLE_MODULE_ECDH], [test x"$enable_module_ecdh" = x"yes"]) -AM_CONDITIONAL([ENABLE_MODULE_MUSIG], [test x"$enable_module_musig" = x"yes"]) AM_CONDITIONAL([ENABLE_MODULE_RECOVERY], [test x"$enable_module_recovery" = x"yes"]) +AM_CONDITIONAL([ENABLE_MODULE_EXTRAKEYS], [test x"$enable_module_extrakeys" = x"yes"]) +AM_CONDITIONAL([ENABLE_MODULE_SCHNORRSIG], [test x"$enable_module_schnorrsig" = x"yes"]) +AM_CONDITIONAL([ENABLE_MODULE_ELLSWIFT], [test x"$enable_module_ellswift" = x"yes"]) AM_CONDITIONAL([ENABLE_MODULE_GENERATOR], [test x"$enable_module_generator" = x"yes"]) AM_CONDITIONAL([ENABLE_MODULE_RANGEPROOF], [test x"$enable_module_rangeproof" = x"yes"]) +AM_CONDITIONAL([ENABLE_MODULE_SURJECTIONPROOF], [test x"$enable_module_surjectionproof" = x"yes"]) AM_CONDITIONAL([ENABLE_MODULE_WHITELIST], [test x"$enable_module_whitelist" = x"yes"]) -AM_CONDITIONAL([ENABLE_MODULE_EXTRAKEYS], [test x"$enable_module_extrakeys" = x"yes"]) -AM_CONDITIONAL([ENABLE_MODULE_SCHNORRSIG], [test x"$enable_module_schnorrsig" = x"yes"]) +AM_CONDITIONAL([ENABLE_MODULE_MUSIG], [test x"$enable_module_musig" = x"yes"]) AM_CONDITIONAL([ENABLE_MODULE_ECDSA_S2C], [test x"$enable_module_ecdsa_s2c" = x"yes"]) AM_CONDITIONAL([ENABLE_MODULE_ECDSA_ADAPTOR], [test x"$enable_module_ecdsa_adaptor" = x"yes"]) -AM_CONDITIONAL([USE_EXTERNAL_ASM], [test x"$enable_external_asm" = x"yes"]) -AM_CONDITIONAL([USE_ASM_ARM], [test x"$set_asm" = x"arm"]) -AM_CONDITIONAL([ENABLE_MODULE_SURJECTIONPROOF], [test x"$enable_module_surjectionproof" = x"yes"]) +AM_CONDITIONAL([ENABLE_MODULE_BPPP], [test x"$enable_module_bppp" = x"yes"]) +AM_CONDITIONAL([ENABLE_MODULE_SCHNORRSIG_HALFAGG], [test x"$enable_module_schnorrsig_halfagg" = x"yes"]) AM_CONDITIONAL([USE_REDUCED_SURJECTION_PROOF_SIZE], [test x"$use_reduced_surjection_proof_size" = x"yes"]) +AM_CONDITIONAL([USE_EXTERNAL_ASM], [test x"$enable_external_asm" = x"yes"]) +AM_CONDITIONAL([USE_ASM_ARM], [test x"$set_asm" = x"arm32"]) AM_CONDITIONAL([BUILD_WINDOWS], [test "$build_windows" = "yes"]) AC_SUBST(LIB_VERSION_CURRENT, _LIB_VERSION_CURRENT) AC_SUBST(LIB_VERSION_REVISION, _LIB_VERSION_REVISION) @@ -537,37 +621,48 @@ AC_SUBST(LIB_VERSION_AGE, _LIB_VERSION_AGE) AC_OUTPUT +# The order in which all modules are listed here should be considered the +# canonical order. This order (or, when appropriate, its reserve) should be used +# everywhere we list or process modules, i.e., here and in other build system +# files and docs. echo echo "Build Options:" echo " with external callbacks = $enable_external_default_callbacks" echo " with benchmarks = $enable_benchmark" echo " with tests = $enable_tests" +echo " with ctime tests = $enable_ctime_tests" echo " with coverage = $enable_coverage" echo " with examples = $enable_examples" echo " module ecdh = $enable_module_ecdh" echo " module recovery = $enable_module_recovery" echo " module extrakeys = $enable_module_extrakeys" echo " module schnorrsig = $enable_module_schnorrsig" +echo " module ellswift = $enable_module_ellswift" +# libsecp256k1-zkp modules, in the order they were added to the libsecp256k1-zkp echo " module generator = $enable_module_generator" echo " module rangeproof = $enable_module_rangeproof" echo " module surjectionproof = $enable_module_surjectionproof" +if test x"$enable_module_surjectionproof" = x"yes" && test x"$enable_reduced_surjection_proof_size" = x"yes"; then +echo " reduced proof size = $enable_reduced_surjection_proof_size" +fi echo " module whitelist = $enable_module_whitelist" echo " module musig = $enable_module_musig" echo " module ecdsa-s2c = $enable_module_ecdsa_s2c" echo " module ecdsa-adaptor = $enable_module_ecdsa_adaptor" echo " module bppp = $enable_module_bppp" +echo " module schnorrsig-halfagg = $enable_module_schnorrsig_halfagg" echo -echo " asm = $set_asm" -echo " ecmult window size = $set_ecmult_window" -echo " ecmult gen prec. bits = $set_ecmult_gen_precision" +echo " asm = $set_asm" +echo " ecmult window size = $set_ecmult_window" +echo " ecmult gen prec. bits = $set_ecmult_gen_precision" # Hide test-only options unless they're used. if test x"$set_widemul" != xauto; then -echo " wide multiplication = $set_widemul" +echo " wide multiplication = $set_widemul" fi echo -echo " valgrind = $enable_valgrind" -echo " CC = $CC" -echo " CPPFLAGS = $CPPFLAGS" -echo " SECP_CFLAGS = $SECP_CFLAGS" -echo " CFLAGS = $CFLAGS" -echo " LDFLAGS = $LDFLAGS" +echo " valgrind = $enable_valgrind" +echo " CC = $CC" +echo " CPPFLAGS = $CPPFLAGS" +echo " SECP_CFLAGS = $SECP_CFLAGS" +echo " CFLAGS = $CFLAGS" +echo " LDFLAGS = $LDFLAGS" diff --git a/secp256k1-zkp-sys/depend/secp256k1/contrib/lax_der_parsing.c b/secp256k1-zkp-sys/depend/secp256k1/contrib/lax_der_parsing.c index f3ac2927..ac138836 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/contrib/lax_der_parsing.c +++ b/secp256k1-zkp-sys/depend/secp256k1/contrib/lax_der_parsing.c @@ -8,7 +8,7 @@ #include "lax_der_parsing.h" -int rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der_lax(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) { +int rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der_lax(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) { size_t rpos, rlen, spos, slen; size_t pos = 0; size_t lenbyte; @@ -16,7 +16,7 @@ int rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der_lax(const rustsecp256k1zkp int overflow = 0; /* Hack to initialize sig with a correctly-parsed but invalid signature. */ - rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_compact(ctx, sig, tmpsig); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_compact(ctx, sig, tmpsig); /* Sequence tag byte */ if (pos == inputlen || input[pos] != 0x30) { @@ -137,11 +137,11 @@ int rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der_lax(const rustsecp256k1zkp } if (!overflow) { - overflow = !rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_compact(ctx, sig, tmpsig); + overflow = !rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_compact(ctx, sig, tmpsig); } if (overflow) { memset(tmpsig, 0, 64); - rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_compact(ctx, sig, tmpsig); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_compact(ctx, sig, tmpsig); } return 1; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/contrib/lax_der_parsing.h b/secp256k1-zkp-sys/depend/secp256k1/contrib/lax_der_parsing.h index 315650aa..fb09234c 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/contrib/lax_der_parsing.h +++ b/secp256k1-zkp-sys/depend/secp256k1/contrib/lax_der_parsing.h @@ -26,8 +26,8 @@ * certain violations are easily supported. You may need to adapt it. * * Do not use this for new systems. Use well-defined DER or compact signatures - * instead if you have the choice (see rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der and - * rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_compact). + * instead if you have the choice (see rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der and + * rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_compact). * * The supported violations are: * - All numbers are parsed as nonnegative integers, even though X.609-0207 @@ -67,8 +67,8 @@ extern "C" { * * Returns: 1 when the signature could be parsed, 0 otherwise. * Args: ctx: a secp256k1 context object - * Out: sig: a pointer to a signature object - * In: input: a pointer to the signature to be parsed + * Out: sig: pointer to a signature object + * In: input: pointer to the signature to be parsed * inputlen: the length of the array pointed to be input * * This function will accept any valid DER encoded signature, even if the @@ -83,9 +83,9 @@ extern "C" { * encoded numbers are out of range, signature validation with it is * guaranteed to fail for every message and public key. */ -int rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der_lax( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig, +int rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der_lax( + const rustsecp256k1zkp_v0_10_0_context* ctx, + rustsecp256k1zkp_v0_10_0_ecdsa_signature* sig, const unsigned char *input, size_t inputlen ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); diff --git a/secp256k1-zkp-sys/depend/secp256k1/contrib/lax_der_privatekey_parsing.c b/secp256k1-zkp-sys/depend/secp256k1/contrib/lax_der_privatekey_parsing.c index ebdeb11d..7152c32e 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/contrib/lax_der_privatekey_parsing.c +++ b/secp256k1-zkp-sys/depend/secp256k1/contrib/lax_der_privatekey_parsing.c @@ -8,7 +8,7 @@ #include "lax_der_privatekey_parsing.h" -int ec_privkey_import_der(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *out32, const unsigned char *privkey, size_t privkeylen) { +int ec_privkey_import_der(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *out32, const unsigned char *privkey, size_t privkeylen) { const unsigned char *end = privkey + privkeylen; int lenb = 0; int len = 0; @@ -45,17 +45,17 @@ int ec_privkey_import_der(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned c return 0; } if (privkey[1]) memcpy(out32 + 32 - privkey[1], privkey + 2, privkey[1]); - if (!rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, out32)) { + if (!rustsecp256k1zkp_v0_10_0_ec_seckey_verify(ctx, out32)) { memset(out32, 0, 32); return 0; } return 1; } -int ec_privkey_export_der(const rustsecp256k1zkp_v0_8_0_context *ctx, unsigned char *privkey, size_t *privkeylen, const unsigned char *key32, int compressed) { - rustsecp256k1zkp_v0_8_0_pubkey pubkey; +int ec_privkey_export_der(const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *privkey, size_t *privkeylen, const unsigned char *key32, int compressed) { + rustsecp256k1zkp_v0_10_0_pubkey pubkey; size_t pubkeylen = 0; - if (!rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey, key32)) { + if (!rustsecp256k1zkp_v0_10_0_ec_pubkey_create(ctx, &pubkey, key32)) { *privkeylen = 0; return 0; } @@ -79,7 +79,7 @@ int ec_privkey_export_der(const rustsecp256k1zkp_v0_8_0_context *ctx, unsigned c memcpy(ptr, key32, 32); ptr += 32; memcpy(ptr, middle, sizeof(middle)); ptr += sizeof(middle); pubkeylen = 33; - rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED); + rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED); ptr += pubkeylen; *privkeylen = ptr - privkey; } else { @@ -104,7 +104,7 @@ int ec_privkey_export_der(const rustsecp256k1zkp_v0_8_0_context *ctx, unsigned c memcpy(ptr, key32, 32); ptr += 32; memcpy(ptr, middle, sizeof(middle)); ptr += sizeof(middle); pubkeylen = 65; - rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_UNCOMPRESSED); + rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_UNCOMPRESSED); ptr += pubkeylen; *privkeylen = ptr - privkey; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/contrib/lax_der_privatekey_parsing.h b/secp256k1-zkp-sys/depend/secp256k1/contrib/lax_der_privatekey_parsing.h index c9363778..8fdea1e5 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/contrib/lax_der_privatekey_parsing.h +++ b/secp256k1-zkp-sys/depend/secp256k1/contrib/lax_der_privatekey_parsing.h @@ -43,8 +43,7 @@ extern "C" { /** Export a private key in DER format. * * Returns: 1 if the private key was valid. - * Args: ctx: pointer to a context object, initialized for signing (cannot - * be NULL) + * Args: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static). * Out: privkey: pointer to an array for storing the private key in BER. * Should have space for 279 bytes, and cannot be NULL. * privkeylen: Pointer to an int where the length of the private key in @@ -58,10 +57,10 @@ extern "C" { * simple 32-byte private keys are sufficient. * * Note that this function does not guarantee correct DER output. It is - * guaranteed to be parsable by rustsecp256k1zkp_v0_8_0_ec_privkey_import_der + * guaranteed to be parsable by rustsecp256k1zkp_v0_10_0_ec_privkey_import_der */ SECP256K1_WARN_UNUSED_RESULT int ec_privkey_export_der( - const rustsecp256k1zkp_v0_8_0_context* ctx, + const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *privkey, size_t *privkeylen, const unsigned char *seckey, @@ -83,7 +82,7 @@ SECP256K1_WARN_UNUSED_RESULT int ec_privkey_export_der( * key. */ SECP256K1_WARN_UNUSED_RESULT int ec_privkey_import_der( - const rustsecp256k1zkp_v0_8_0_context* ctx, + const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *seckey, const unsigned char *privkey, size_t privkeylen diff --git a/secp256k1-zkp-sys/depend/secp256k1/contrib/musig2-vectors.py b/secp256k1-zkp-sys/depend/secp256k1/contrib/musig2-vectors.py index 8df3870f..97424419 100755 --- a/secp256k1-zkp-sys/depend/secp256k1/contrib/musig2-vectors.py +++ b/secp256k1-zkp-sys/depend/secp256k1/contrib/musig2-vectors.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import sys import json diff --git a/secp256k1-zkp-sys/depend/secp256k1/contrib/sync-upstream.sh b/secp256k1-zkp-sys/depend/secp256k1/contrib/sync-upstream.sh index f4ccc449..b910a599 100755 --- a/secp256k1-zkp-sys/depend/secp256k1/contrib/sync-upstream.sh +++ b/secp256k1-zkp-sys/depend/secp256k1/contrib/sync-upstream.sh @@ -3,12 +3,13 @@ set -eou pipefail help() { - echo "$0 range [end]" - echo " merges every merge commit present in upstream and missing locally." + echo "$0 [-b ] range [end]" + echo " merges every merge commit present in upstream and missing in (default: master)." echo " If the optional [end] commit is provided, only merges up to [end]." + echo " If the optional [-b branch] provided, then ." echo - echo "$0 select ... " - echo " merges every selected merge commit" + echo "$0 [-b ] select ... " + echo " merges every selected merge commit into (default: master)" echo echo "This tool creates a branch and a script that can be executed to create the" echo "PR automatically. The script requires the github-cli tool (aka gh)." @@ -17,12 +18,9 @@ help() { exit 1 } -if [ "$#" -lt 1 ]; then - help -fi - REMOTE=upstream REMOTE_BRANCH="$REMOTE/master" +LOCAL_BRANCH="master" # Makes sure you have a remote "upstream" that is up-to-date setup() { ret=0 @@ -41,7 +39,7 @@ setup() { } range() { - RANGESTART_COMMIT=$(git merge-base "$REMOTE_BRANCH" master) + RANGESTART_COMMIT=$(git merge-base "$REMOTE_BRANCH" "$LOCAL_BRANCH") RANGEEND_COMMIT=$(git rev-parse "$REMOTE_BRANCH") if [ "$#" = 1 ]; then RANGEEND_COMMIT=$1 @@ -57,18 +55,37 @@ range() { esac } +# Process -b argument +while getopts "b:" opt; do + case $opt in + b) + LOCAL_BRANCH=$OPTARG + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + ;; + esac +done + +# Shift off the processed options +shift $((OPTIND -1)) + +if [ "$#" -lt 1 ]; then + help +fi + case $1 in range) shift setup range "$@" - REPRODUCE_COMMAND="$0 range $RANGEEND_COMMIT" + REPRODUCE_COMMAND="$0 -b $LOCAL_BRANCH range $RANGEEND_COMMIT" ;; select) shift setup COMMITS=$* - REPRODUCE_COMMAND="$0 select $@" + REPRODUCE_COMMAND="$0 -b $LOCAL_BRANCH select $@" ;; help) help @@ -87,8 +104,7 @@ do done # Remove trailing "," TITLE=${TITLE%?} - -BODY=$(printf "%s\n\n%s" "$BODY" "This PR can be recreated with \`$REPRODUCE_COMMAND\`.") +BODY=$(printf "%s\n\n%s\n%s" "$BODY" "This PR can be recreated with \`$REPRODUCE_COMMAND\`." "Tip: Use \`git show --remerge-diff\` to show the changes manually added to the merge commit.") echo "-----------------------------------" echo "$TITLE" @@ -96,8 +112,8 @@ echo "-----------------------------------" echo "$BODY" echo "-----------------------------------" # Create branch from PR commit and create PR -git checkout master -git pull +git checkout "$LOCAL_BRANCH" +git pull --autostash git checkout -b temp-merge-"$PRNUM" # Escape single quote @@ -115,7 +131,7 @@ cat < "$FNAME" #!/bin/sh gh pr create -t '$TITLE' -b '$BODY' --web # Remove temporary branch -git checkout master +git checkout "$LOCAL_BRANCH" git branch -D temp-merge-"$PRNUM" EOT chmod +x "$FNAME" diff --git a/secp256k1-zkp-sys/depend/secp256k1/doc/CHANGELOG.md b/secp256k1-zkp-sys/depend/secp256k1/doc/CHANGELOG.md deleted file mode 100644 index 3c4c2e45..00000000 --- a/secp256k1-zkp-sys/depend/secp256k1/doc/CHANGELOG.md +++ /dev/null @@ -1,12 +0,0 @@ -# Changelog - -This file is currently only a template for future use. - -Each change falls into one of the following categories: Added, Changed, Deprecated, Removed, Fixed or Security. - -## [Unreleased] - -## [MAJOR.MINOR.PATCH] - YYYY-MM-DD - -### Added/Changed/Deprecated/Removed/Fixed/Security -- [Title with link to Pull Request](https://link-to-pr) diff --git a/secp256k1-zkp-sys/depend/secp256k1/doc/ellswift.md b/secp256k1-zkp-sys/depend/secp256k1/doc/ellswift.md new file mode 100644 index 00000000..7dec7b90 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/doc/ellswift.md @@ -0,0 +1,483 @@ +# ElligatorSwift for secp256k1 explained + +In this document we explain how the `ellswift` module implementation is related to the +construction in the +["SwiftEC: Shallue–van de Woestijne Indifferentiable Function To Elliptic Curves"](https://eprint.iacr.org/2022/759) +paper by Jorge Chávez-Saab, Francisco Rodríguez-Henríquez, and Mehdi Tibouchi. + +* [1. Introduction](#1-introduction) +* [2. The decoding function](#2-the-decoding-function) + + [2.1 Decoding for `secp256k1`](#21-decoding-for-secp256k1) +* [3. The encoding function](#3-the-encoding-function) + + [3.1 Switching to *v, w* coordinates](#31-switching-to-v-w-coordinates) + + [3.2 Avoiding computing all inverses](#32-avoiding-computing-all-inverses) + + [3.3 Finding the inverse](#33-finding-the-inverse) + + [3.4 Dealing with special cases](#34-dealing-with-special-cases) + + [3.5 Encoding for `secp256k1`](#35-encoding-for-secp256k1) +* [4. Encoding and decoding full *(x, y)* coordinates](#4-encoding-and-decoding-full-x-y-coordinates) + + [4.1 Full *(x, y)* coordinates for `secp256k1`](#41-full-x-y-coordinates-for-secp256k1) + +## 1. Introduction + +The `ellswift` module effectively introduces a new 64-byte public key format, with the property +that (uniformly random) public keys can be encoded as 64-byte arrays which are computationally +indistinguishable from uniform byte arrays. The module provides functions to convert public keys +from and to this format, as well as convenience functions for key generation and ECDH that operate +directly on ellswift-encoded keys. + +The encoding consists of the concatenation of two (32-byte big endian) encoded field elements $u$ +and $t.$ Together they encode an x-coordinate on the curve $x$, or (see further) a full point $(x, y)$ on +the curve. + +**Decoding** consists of decoding the field elements $u$ and $t$ (values above the field size $p$ +are taken modulo $p$), and then evaluating $F_u(t)$, which for every $u$ and $t$ results in a valid +x-coordinate on the curve. The functions $F_u$ will be defined in [Section 2](#2-the-decoding-function). + +**Encoding** a given $x$ coordinate is conceptually done as follows: +* Loop: + * Pick a uniformly random field element $u.$ + * Compute the set $L = F_u^{-1}(x)$ of $t$ values for which $F_u(t) = x$, which may have up to *8* elements. + * With probability $1 - \dfrac{\\#L}{8}$, restart the loop. + * Select a uniformly random $t \in L$ and return $(u, t).$ + +This is the *ElligatorSwift* algorithm, here given for just x-coordinates. An extension to full +$(x, y)$ points will be given in [Section 4](#4-encoding-and-decoding-full-x-y-coordinates). +The algorithm finds a uniformly random $(u, t)$ among (almost all) those +for which $F_u(t) = x.$ Section 3.2 in the paper proves that the number of such encodings for +almost all x-coordinates on the curve (all but at most 39) is close to two times the field size +(specifically, it lies in the range $2q \pm (22\sqrt{q} + O(1))$, where $q$ is the size of the field). + +## 2. The decoding function + +First some definitions: +* $\mathbb{F}$ is the finite field of size $q$, of characteristic 5 or more, and $q \equiv 1 \mod 3.$ + * For `secp256k1`, $q = 2^{256} - 2^{32} - 977$, which satisfies that requirement. +* Let $E$ be the elliptic curve of points $(x, y) \in \mathbb{F}^2$ for which $y^2 = x^3 + ax + b$, with $a$ and $b$ + public constants, for which $\Delta_E = -16(4a^3 + 27b^2)$ is a square, and at least one of $(-b \pm \sqrt{-3 \Delta_E} / 36)/2$ is a square. + This implies that the order of $E$ is either odd, or a multiple of *4*. + If $a=0$, this condition is always fulfilled. + * For `secp256k1`, $a=0$ and $b=7.$ +* Let the function $g(x) = x^3 + ax + b$, so the $E$ curve equation is also $y^2 = g(x).$ +* Let the function $h(x) = 3x^3 + 4a.$ +* Define $V$ as the set of solutions $(x_1, x_2, x_3, z)$ to $z^2 = g(x_1)g(x_2)g(x_3).$ +* Define $S_u$ as the set of solutions $(X, Y)$ to $X^2 + h(u)Y^2 = -g(u)$ and $Y \neq 0.$ +* $P_u$ is a function from $\mathbb{F}$ to $S_u$ that will be defined below. +* $\psi_u$ is a function from $S_u$ to $V$ that will be defined below. + +**Note**: In the paper: +* $F_u$ corresponds to $F_{0,u}$ there. +* $P_u(t)$ is called $P$ there. +* All $S_u$ sets together correspond to $S$ there. +* All $\psi_u$ functions together (operating on elements of $S$) correspond to $\psi$ there. + +Note that for $V$, the left hand side of the equation $z^2$ is square, and thus the right +hand must also be square. As multiplying non-squares results in a square in $\mathbb{F}$, +out of the three right-hand side factors an even number must be non-squares. +This implies that exactly *1* or exactly *3* out of +$\\{g(x_1), g(x_2), g(x_3)\\}$ must be square, and thus that for any $(x_1,x_2,x_3,z) \in V$, +at least one of $\\{x_1, x_2, x_3\\}$ must be a valid x-coordinate on $E.$ There is one exception +to this, namely when $z=0$, but even then one of the three values is a valid x-coordinate. + +**Define** the decoding function $F_u(t)$ as: +* Let $(x_1, x_2, x_3, z) = \psi_u(P_u(t)).$ +* Return the first element $x$ of $(x_3, x_2, x_1)$ which is a valid x-coordinate on $E$ (i.e., $g(x)$ is square). + +$P_u(t) = (X(u, t), Y(u, t))$, where: + +$$ +\begin{array}{lcl} +X(u, t) & = & \left\\{\begin{array}{ll} + \dfrac{g(u) - t^2}{2t} & a = 0 \\ + \dfrac{g(u) + h(u)(Y_0(u) - X_0(u)t)^2}{X_0(u)(1 + h(u)t^2)} & a \neq 0 +\end{array}\right. \\ +Y(u, t) & = & \left\\{\begin{array}{ll} + \dfrac{X(u, t) + t}{u \sqrt{-3}} = \dfrac{g(u) + t^2}{2tu\sqrt{-3}} & a = 0 \\ + Y_0(u) + t(X(u, t) - X_0(u)) & a \neq 0 +\end{array}\right. +\end{array} +$$ + +$P_u(t)$ is defined: +* For $a=0$, unless: + * $u = 0$ or $t = 0$ (division by zero) + * $g(u) = -t^2$ (would give $Y=0$). +* For $a \neq 0$, unless: + * $X_0(u) = 0$ or $h(u)t^2 = -1$ (division by zero) + * $Y_0(u) (1 - h(u)t^2) = 2X_0(u)t$ (would give $Y=0$). + +The functions $X_0(u)$ and $Y_0(u)$ are defined in Appendix A of the paper, and depend on various properties of $E.$ + +The function $\psi_u$ is the same for all curves: $\psi_u(X, Y) = (x_1, x_2, x_3, z)$, where: + +$$ +\begin{array}{lcl} + x_1 & = & \dfrac{X}{2Y} - \dfrac{u}{2} && \\ + x_2 & = & -\dfrac{X}{2Y} - \dfrac{u}{2} && \\ + x_3 & = & u + 4Y^2 && \\ + z & = & \dfrac{g(x_3)}{2Y}(u^2 + ux_1 + x_1^2 + a) = \dfrac{-g(u)g(x_3)}{8Y^3} +\end{array} +$$ + +### 2.1 Decoding for `secp256k1` + +Put together and specialized for $a=0$ curves, decoding $(u, t)$ to an x-coordinate is: + +**Define** $F_u(t)$ as: +* Let $X = \dfrac{u^3 + b - t^2}{2t}.$ +* Let $Y = \dfrac{X + t}{u\sqrt{-3}}.$ +* Return the first $x$ in $(u + 4Y^2, \dfrac{-X}{2Y} - \dfrac{u}{2}, \dfrac{X}{2Y} - \dfrac{u}{2})$ for which $g(x)$ is square. + +To make sure that every input decodes to a valid x-coordinate, we remap the inputs in case +$P_u$ is not defined (when $u=0$, $t=0$, or $g(u) = -t^2$): + +**Define** $F_u(t)$ as: +* Let $u'=u$ if $u \neq 0$; $1$ otherwise (guaranteeing $u' \neq 0$). +* Let $t'=t$ if $t \neq 0$; $1$ otherwise (guaranteeing $t' \neq 0$). +* Let $t''=t'$ if $g(u') \neq -t'^2$; $2t'$ otherwise (guaranteeing $t'' \neq 0$ and $g(u') \neq -t''^2$). +* Let $X = \dfrac{u'^3 + b - t''^2}{2t''}.$ +* Let $Y = \dfrac{X + t''}{u'\sqrt{-3}}.$ +* Return the first $x$ in $(u' + 4Y^2, \dfrac{-X}{2Y} - \dfrac{u'}{2}, \dfrac{X}{2Y} - \dfrac{u'}{2})$ for which $x^3 + b$ is square. + +The choices here are not strictly necessary. Just returning a fixed constant in any of the undefined cases would suffice, +but the approach here is simple enough and gives fairly uniform output even in these cases. + +**Note**: in the paper these conditions result in $\infty$ as output, due to the use of projective coordinates there. +We wish to avoid the need for callers to deal with this special case. + +This is implemented in `rustsecp256k1zkp_v0_10_0_ellswift_xswiftec_frac_var` (which decodes to an x-coordinate represented as a fraction), and +in `rustsecp256k1zkp_v0_10_0_ellswift_xswiftec_var` (which outputs the actual x-coordinate). + +## 3. The encoding function + +To implement $F_u^{-1}(x)$, the function to find the set of inverses $t$ for which $F_u(t) = x$, we have to reverse the process: +* Find all the $(X, Y) \in S_u$ that could have given rise to $x$, through the $x_1$, $x_2$, or $x_3$ formulas in $\psi_u.$ +* Map those $(X, Y)$ solutions to $t$ values using $P_u^{-1}(X, Y).$ +* For each of the found $t$ values, verify that $F_u(t) = x.$ +* Return the remaining $t$ values. + +The function $P_u^{-1}$, which finds $t$ given $(X, Y) \in S_u$, is significantly simpler than $P_u:$ + +$$ +P_u^{-1}(X, Y) = \left\\{\begin{array}{ll} +Yu\sqrt{-3} - X & a = 0 \\ +\dfrac{Y-Y_0(u)}{X-X_0(u)} & a \neq 0 \land X \neq X_0(u) \\ +\dfrac{-X_0(u)}{h(u)Y_0(u)} & a \neq 0 \land X = X_0(u) \land Y = Y_0(u) +\end{array}\right. +$$ + +The third step above, verifying that $F_u(t) = x$, is necessary because for the $(X, Y)$ values found through the $x_1$ and $x_2$ expressions, +it is possible that decoding through $\psi_u(X, Y)$ yields a valid $x_3$ on the curve, which would take precedence over the +$x_1$ or $x_2$ decoding. These $(X, Y)$ solutions must be rejected. + +Since we know that exactly one or exactly three out of $\\{x_1, x_2, x_3\\}$ are valid x-coordinates for any $t$, +the case where either $x_1$ or $x_2$ is valid and in addition also $x_3$ is valid must mean that all three are valid. +This means that instead of checking whether $x_3$ is on the curve, it is also possible to check whether the other one out of +$x_1$ and $x_2$ is on the curve. This is significantly simpler, as it turns out. + +Observe that $\psi_u$ guarantees that $x_1 + x_2 = -u.$ So given either $x = x_1$ or $x = x_2$, the other one of the two can be computed as +$-u - x.$ Thus, when encoding $x$ through the $x_1$ or $x_2$ expressions, one can simply check whether $g(-u-x)$ is a square, +and if so, not include the corresponding $t$ values in the returned set. As this does not need $X$, $Y$, or $t$, this condition can be determined +before those values are computed. + +It is not possible that an encoding found through the $x_1$ expression decodes to a different valid x-coordinate using $x_2$ (which would +take precedence), for the same reason: if both $x_1$ and $x_2$ decodings were valid, $x_3$ would be valid as well, and thus take +precedence over both. Because of this, the $g(-u-x)$ being square test for $x_1$ and $x_2$ is the only test necessary to guarantee the found $t$ +values round-trip back to the input $x$ correctly. This is the reason for choosing the $(x_3, x_2, x_1)$ precedence order in the decoder; +any order which does not place $x_3$ first requires more complicated round-trip checks in the encoder. + +### 3.1 Switching to *v, w* coordinates + +Before working out the formulas for all this, we switch to different variables for $S_u.$ Let $v = (X/Y - u)/2$, and +$w = 2Y.$ Or in the other direction, $X = w(u/2 + v)$ and $Y = w/2:$ +* $S_u'$ becomes the set of $(v, w)$ for which $w^2 (u^2 + uv + v^2 + a) = -g(u)$ and $w \neq 0.$ +* For $a=0$ curves, $P_u^{-1}$ can be stated for $(v,w)$ as $P_u^{'-1}(v, w) = w\left(\frac{\sqrt{-3}-1}{2}u - v\right).$ +* $\psi_u$ can be stated for $(v, w)$ as $\psi_u'(v, w) = (x_1, x_2, x_3, z)$, where + +$$ +\begin{array}{lcl} + x_1 & = & v \\ + x_2 & = & -u - v \\ + x_3 & = & u + w^2 \\ + z & = & \dfrac{g(x_3)}{w}(u^2 + uv + v^2 + a) = \dfrac{-g(u)g(x_3)}{w^3} +\end{array} +$$ + +We can now write the expressions for finding $(v, w)$ given $x$ explicitly, by solving each of the $\\{x_1, x_2, x_3\\}$ +expressions for $v$ or $w$, and using the $S_u'$ equation to find the other variable: +* Assuming $x = x_1$, we find $v = x$ and $w = \pm\sqrt{-g(u)/(u^2 + uv + v^2 + a)}$ (two solutions). +* Assuming $x = x_2$, we find $v = -u-x$ and $w = \pm\sqrt{-g(u)/(u^2 + uv + v^2 + a)}$ (two solutions). +* Assuming $x = x_3$, we find $w = \pm\sqrt{x-u}$ and $v = -u/2 \pm \sqrt{-w^2(4g(u) + w^2h(u))}/(2w^2)$ (four solutions). + +### 3.2 Avoiding computing all inverses + +The *ElligatorSwift* algorithm as stated in Section 1 requires the computation of $L = F_u^{-1}(x)$ (the +set of all $t$ such that $(u, t)$ decode to $x$) in full. This is unnecessary. + +Observe that the procedure of restarting with probability $(1 - \frac{\\#L}{8})$ and otherwise returning a +uniformly random element from $L$ is actually equivalent to always padding $L$ with $\bot$ values up to length 8, +picking a uniformly random element from that, restarting whenever $\bot$ is picked: + +**Define** *ElligatorSwift(x)* as: +* Loop: + * Pick a uniformly random field element $u.$ + * Compute the set $L = F_u^{-1}(x).$ + * Let $T$ be the 8-element vector consisting of the elements of $L$, plus $8 - \\#L$ times $\\{\bot\\}.$ + * Select a uniformly random $t \in T.$ + * If $t \neq \bot$, return $(u, t)$; restart loop otherwise. + +Now notice that the order of elements in $T$ does not matter, as all we do is pick a uniformly +random element in it, so we do not need to have all $\bot$ values at the end. +As we have 8 distinct formulas for finding $(v, w)$ (taking the variants due to $\pm$ into account), +we can associate every index in $T$ with exactly one of those formulas, making sure that: +* Formulas that yield no solutions (due to division by zero or non-existing square roots) or invalid solutions are made to return $\bot.$ +* For the $x_1$ and $x_2$ cases, if $g(-u-x)$ is a square, $\bot$ is returned instead (the round-trip check). +* In case multiple formulas would return the same non- $\bot$ result, all but one of those must be turned into $\bot$ to avoid biasing those. + +The last condition above only occurs with negligible probability for cryptographically-sized curves, but is interesting +to take into account as it allows exhaustive testing in small groups. See [Section 3.4](#34-dealing-with-special-cases) +for an analysis of all the negligible cases. + +If we define $T = (G_{0,u}(x), G_{1,u}(x), \ldots, G_{7,u}(x))$, with each $G_{i,u}$ matching one of the formulas, +the loop can be simplified to only compute one of the inverses instead of all of them: + +**Define** *ElligatorSwift(x)* as: +* Loop: + * Pick a uniformly random field element $u.$ + * Pick a uniformly random integer $c$ in $[0,8).$ + * Let $t = G_{c,u}(x).$ + * If $t \neq \bot$, return $(u, t)$; restart loop otherwise. + +This is implemented in `rustsecp256k1zkp_v0_10_0_ellswift_xelligatorswift_var`. + +### 3.3 Finding the inverse + +To implement $G_{c,u}$, we map $c=0$ to the $x_1$ formula, $c=1$ to the $x_2$ formula, and $c=2$ and $c=3$ to the $x_3$ formula. +Those are then repeated as $c=4$ through $c=7$ for the other sign of $w$ (noting that in each formula, $w$ is a square root of some expression). +Ignoring the negligible cases, we get: + +**Define** $G_{c,u}(x)$ as: +* If $c \in \\{0, 1, 4, 5\\}$ (for $x_1$ and $x_2$ formulas): + * If $g(-u-x)$ is square, return $\bot$ (as $x_3$ would be valid and take precedence). + * If $c \in \\{0, 4\\}$ (the $x_1$ formula) let $v = x$, otherwise let $v = -u-x$ (the $x_2$ formula) + * Let $s = -g(u)/(u^2 + uv + v^2 + a)$ (using $s = w^2$ in what follows). +* Otherwise, when $c \in \\{2, 3, 6, 7\\}$ (for $x_3$ formulas): + * Let $s = x-u.$ + * Let $r = \sqrt{-s(4g(u) + sh(u))}.$ + * Let $v = (r/s - u)/2$ if $c \in \\{3, 7\\}$; $(-r/s - u)/2$ otherwise. +* Let $w = \sqrt{s}.$ +* Depending on $c:$ + * If $c \in \\{0, 1, 2, 3\\}:$ return $P_u^{'-1}(v, w).$ + * If $c \in \\{4, 5, 6, 7\\}:$ return $P_u^{'-1}(v, -w).$ + +Whenever a square root of a non-square is taken, $\bot$ is returned; for both square roots this happens with roughly +50% on random inputs. Similarly, when a division by 0 would occur, $\bot$ is returned as well; this will only happen +with negligible probability. A division by 0 in the first branch in fact cannot occur at all, because $u^2 + uv + v^2 + a = 0$ +implies $g(-u-x) = g(x)$ which would mean the $g(-u-x)$ is square condition has triggered +and $\bot$ would have been returned already. + +**Note**: In the paper, the $case$ variable corresponds roughly to the $c$ above, but only takes on 4 possible values (1 to 4). +The conditional negation of $w$ at the end is done randomly, which is equivalent, but makes testing harder. We choose to +have the $G_{c,u}$ be deterministic, and capture all choices in $c.$ + +Now observe that the $c \in \\{1, 5\\}$ and $c \in \\{3, 7\\}$ conditions effectively perform the same $v \rightarrow -u-v$ +transformation. Furthermore, that transformation has no effect on $s$ in the first branch +as $u^2 + ux + x^2 + a = u^2 + u(-u-x) + (-u-x)^2 + a.$ Thus we can extract it out and move it down: + +**Define** $G_{c,u}(x)$ as: +* If $c \in \\{0, 1, 4, 5\\}:$ + * If $g(-u-x)$ is square, return $\bot.$ + * Let $s = -g(u)/(u^2 + ux + x^2 + a).$ + * Let $v = x.$ +* Otherwise, when $c \in \\{2, 3, 6, 7\\}:$ + * Let $s = x-u.$ + * Let $r = \sqrt{-s(4g(u) + sh(u))}.$ + * Let $v = (r/s - u)/2.$ +* Let $w = \sqrt{s}.$ +* Depending on $c:$ + * If $c \in \\{0, 2\\}:$ return $P_u^{'-1}(v, w).$ + * If $c \in \\{1, 3\\}:$ return $P_u^{'-1}(-u-v, w).$ + * If $c \in \\{4, 6\\}:$ return $P_u^{'-1}(v, -w).$ + * If $c \in \\{5, 7\\}:$ return $P_u^{'-1}(-u-v, -w).$ + +This shows there will always be exactly 0, 4, or 8 $t$ values for a given $(u, x)$ input. +There can be 0, 1, or 2 $(v, w)$ pairs before invoking $P_u^{'-1}$, and each results in 4 distinct $t$ values. + +### 3.4 Dealing with special cases + +As mentioned before there are a few cases to deal with which only happen in a negligibly small subset of inputs. +For cryptographically sized fields, if only random inputs are going to be considered, it is unnecessary to deal with these. Still, for completeness +we analyse them here. They generally fall into two categories: cases in which the encoder would produce $t$ values that +do not decode back to $x$ (or at least cannot guarantee that they do), and cases in which the encoder might produce the same +$t$ value for multiple $c$ inputs (thereby biasing that encoding): + +* In the branch for $x_1$ and $x_2$ (where $c \in \\{0, 1, 4, 5\\}$): + * When $g(u) = 0$, we would have $s=w=Y=0$, which is not on $S_u.$ This is only possible on even-ordered curves. + Excluding this also removes the one condition under which the simplified check for $x_3$ on the curve + fails (namely when $g(x_1)=g(x_2)=0$ but $g(x_3)$ is not square). + This does exclude some valid encodings: when both $g(u)=0$ and $u^2+ux+x^2+a=0$ (also implying $g(x)=0$), + the $S_u'$ equation degenerates to $0 = 0$, and many valid $t$ values may exist. Yet, these cannot be targeted uniformly by the + encoder anyway as there will generally be more than 8. + * When $g(x) = 0$, the same $t$ would be produced as in the $x_3$ branch (where $c \in \\{2, 3, 6, 7\\}$) which we give precedence + as it can deal with $g(u)=0$. + This is again only possible on even-ordered curves. +* In the branch for $x_3$ (where $c \in \\{2, 3, 6, 7\\}$): + * When $s=0$, a division by zero would occur. + * When $v = -u-v$ and $c \in \\{3, 7\\}$, the same $t$ would be returned as in the $c \in \\{2, 6\\}$ cases. + It is equivalent to checking whether $r=0$. + This cannot occur in the $x_1$ or $x_2$ branches, as it would trigger the $g(-u-x)$ is square condition. + A similar concern for $w = -w$ does not exist, as $w=0$ is already impossible in both branches: in the first + it requires $g(u)=0$ which is already outlawed on even-ordered curves and impossible on others; in the second it would trigger division by zero. +* Curve-specific special cases also exist that need to be rejected, because they result in $(u,t)$ which is invalid to the decoder, or because of division by zero in the encoder: + * For $a=0$ curves, when $u=0$ or when $t=0$. The latter can only be reached by the encoder when $g(u)=0$, which requires an even-ordered curve. + * For $a \neq 0$ curves, when $X_0(u)=0$, when $h(u)t^2 = -1$, or when $w(u + 2v) = 2X_0(u)$ while also either $w \neq 2Y_0(u)$ or $h(u)=0$. + +**Define** a version of $G_{c,u}(x)$ which deals with all these cases: +* If $a=0$ and $u=0$, return $\bot.$ +* If $a \neq 0$ and $X_0(u)=0$, return $\bot.$ +* If $c \in \\{0, 1, 4, 5\\}:$ + * If $g(u) = 0$ or $g(x) = 0$, return $\bot$ (even curves only). + * If $g(-u-x)$ is square, return $\bot.$ + * Let $s = -g(u)/(u^2 + ux + x^2 + a)$ (cannot cause division by zero). + * Let $v = x.$ +* Otherwise, when $c \in \\{2, 3, 6, 7\\}:$ + * Let $s = x-u.$ + * Let $r = \sqrt{-s(4g(u) + sh(u))}$; return $\bot$ if not square. + * If $c \in \\{3, 7\\}$ and $r=0$, return $\bot.$ + * If $s = 0$, return $\bot.$ + * Let $v = (r/s - u)/2.$ +* Let $w = \sqrt{s}$; return $\bot$ if not square. +* If $a \neq 0$ and $w(u+2v) = 2X_0(u)$ and either $w \neq 2Y_0(u)$ or $h(u) = 0$, return $\bot.$ +* Depending on $c:$ + * If $c \in \\{0, 2\\}$, let $t = P_u^{'-1}(v, w).$ + * If $c \in \\{1, 3\\}$, let $t = P_u^{'-1}(-u-v, w).$ + * If $c \in \\{4, 6\\}$, let $t = P_u^{'-1}(v, -w).$ + * If $c \in \\{5, 7\\}$, let $t = P_u^{'-1}(-u-v, -w).$ +* If $a=0$ and $t=0$, return $\bot$ (even curves only). +* If $a \neq 0$ and $h(u)t^2 = -1$, return $\bot.$ +* Return $t.$ + +Given any $u$, using this algorithm over all $x$ and $c$ values, every $t$ value will be reached exactly once, +for an $x$ for which $F_u(t) = x$ holds, except for these cases that will not be reached: +* All cases where $P_u(t)$ is not defined: + * For $a=0$ curves, when $u=0$, $t=0$, or $g(u) = -t^2.$ + * For $a \neq 0$ curves, when $h(u)t^2 = -1$, $X_0(u) = 0$, or $Y_0(u) (1 - h(u) t^2) = 2X_0(u)t.$ +* When $g(u)=0$, the potentially many $t$ values that decode to an $x$ satisfying $g(x)=0$ using the $x_2$ formula. These were excluded by the $g(u)=0$ condition in the $c \in \\{0, 1, 4, 5\\}$ branch. + +These cases form a negligible subset of all $(u, t)$ for cryptographically sized curves. + +### 3.5 Encoding for `secp256k1` + +Specialized for odd-ordered $a=0$ curves: + +**Define** $G_{c,u}(x)$ as: +* If $u=0$, return $\bot.$ +* If $c \in \\{0, 1, 4, 5\\}:$ + * If $(-u-x)^3 + b$ is square, return $\bot$ + * Let $s = -(u^3 + b)/(u^2 + ux + x^2)$ (cannot cause division by 0). + * Let $v = x.$ +* Otherwise, when $c \in \\{2, 3, 6, 7\\}:$ + * Let $s = x-u.$ + * Let $r = \sqrt{-s(4(u^3 + b) + 3su^2)}$; return $\bot$ if not square. + * If $c \in \\{3, 7\\}$ and $r=0$, return $\bot.$ + * If $s = 0$, return $\bot.$ + * Let $v = (r/s - u)/2.$ +* Let $w = \sqrt{s}$; return $\bot$ if not square. +* Depending on $c:$ + * If $c \in \\{0, 2\\}:$ return $w(\frac{\sqrt{-3}-1}{2}u - v).$ + * If $c \in \\{1, 3\\}:$ return $w(\frac{\sqrt{-3}+1}{2}u + v).$ + * If $c \in \\{4, 6\\}:$ return $w(\frac{-\sqrt{-3}+1}{2}u + v).$ + * If $c \in \\{5, 7\\}:$ return $w(\frac{-\sqrt{-3}-1}{2}u - v).$ + +This is implemented in `rustsecp256k1zkp_v0_10_0_ellswift_xswiftec_inv_var`. + +And the x-only ElligatorSwift encoding algorithm is still: + +**Define** *ElligatorSwift(x)* as: +* Loop: + * Pick a uniformly random field element $u.$ + * Pick a uniformly random integer $c$ in $[0,8).$ + * Let $t = G_{c,u}(x).$ + * If $t \neq \bot$, return $(u, t)$; restart loop otherwise. + +Note that this logic does not take the remapped $u=0$, $t=0$, and $g(u) = -t^2$ cases into account; it just avoids them. +While it is not impossible to make the encoder target them, this would increase the maximum number of $t$ values for a given $(u, x)$ +combination beyond 8, and thereby slow down the ElligatorSwift loop proportionally, for a negligible gain in uniformity. + +## 4. Encoding and decoding full *(x, y)* coordinates + +So far we have only addressed encoding and decoding x-coordinates, but in some cases an encoding +for full points with $(x, y)$ coordinates is desirable. It is possible to encode this information +in $t$ as well. + +Note that for any $(X, Y) \in S_u$, $(\pm X, \pm Y)$ are all on $S_u.$ Moreover, all of these are +mapped to the same x-coordinate. Negating $X$ or negating $Y$ just results in $x_1$ and $x_2$ +being swapped, and does not affect $x_3.$ This will not change the outcome x-coordinate as the order +of $x_1$ and $x_2$ only matters if both were to be valid, and in that case $x_3$ would be used instead. + +Still, these four $(X, Y)$ combinations all correspond to distinct $t$ values, so we can encode +the sign of the y-coordinate in the sign of $X$ or the sign of $Y.$ They correspond to the +four distinct $P_u^{'-1}$ calls in the definition of $G_{u,c}.$ + +**Note**: In the paper, the sign of the y coordinate is encoded in a separately-coded bit. + +To encode the sign of $y$ in the sign of $Y:$ + +**Define** *Decode(u, t)* for full $(x, y)$ as: +* Let $(X, Y) = P_u(t).$ +* Let $x$ be the first value in $(u + 4Y^2, \frac{-X}{2Y} - \frac{u}{2}, \frac{X}{2Y} - \frac{u}{2})$ for which $g(x)$ is square. +* Let $y = \sqrt{g(x)}.$ +* If $sign(y) = sign(Y)$, return $(x, y)$; otherwise return $(x, -y).$ + +And encoding would be done using a $G_{c,u}(x, y)$ function defined as: + +**Define** $G_{c,u}(x, y)$ as: +* If $c \in \\{0, 1\\}:$ + * If $g(u) = 0$ or $g(x) = 0$, return $\bot$ (even curves only). + * If $g(-u-x)$ is square, return $\bot.$ + * Let $s = -g(u)/(u^2 + ux + x^2 + a)$ (cannot cause division by zero). + * Let $v = x.$ +* Otherwise, when $c \in \\{2, 3\\}:$ + * Let $s = x-u.$ + * Let $r = \sqrt{-s(4g(u) + sh(u))}$; return $\bot$ if not square. + * If $c = 3$ and $r = 0$, return $\bot.$ + * Let $v = (r/s - u)/2.$ +* Let $w = \sqrt{s}$; return $\bot$ if not square. +* Let $w' = w$ if $sign(w/2) = sign(y)$; $-w$ otherwise. +* Depending on $c:$ + * If $c \in \\{0, 2\\}:$ return $P_u^{'-1}(v, w').$ + * If $c \in \\{1, 3\\}:$ return $P_u^{'-1}(-u-v, w').$ + +Note that $c$ now only ranges $[0,4)$, as the sign of $w'$ is decided based on that of $y$, rather than on $c.$ +This change makes some valid encodings unreachable: when $y = 0$ and $sign(Y) \neq sign(0)$. + +In the above logic, $sign$ can be implemented in several ways, such as parity of the integer representation +of the input field element (for prime-sized fields) or the quadratic residuosity (for fields where +$-1$ is not square). The choice does not matter, as long as it only takes on two possible values, and for $x \neq 0$ it holds that $sign(x) \neq sign(-x)$. + +### 4.1 Full *(x, y)* coordinates for `secp256k1` + +For $a=0$ curves, there is another option. Note that for those, +the $P_u(t)$ function translates negations of $t$ to negations of (both) $X$ and $Y.$ Thus, we can use $sign(t)$ to +encode the y-coordinate directly. Combined with the earlier remapping to guarantee all inputs land on the curve, we get +as decoder: + +**Define** *Decode(u, t)* as: +* Let $u'=u$ if $u \neq 0$; $1$ otherwise. +* Let $t'=t$ if $t \neq 0$; $1$ otherwise. +* Let $t''=t'$ if $u'^3 + b + t'^2 \neq 0$; $2t'$ otherwise. +* Let $X = \dfrac{u'^3 + b - t''^2}{2t''}.$ +* Let $Y = \dfrac{X + t''}{u'\sqrt{-3}}.$ +* Let $x$ be the first element of $(u' + 4Y^2, \frac{-X}{2Y} - \frac{u'}{2}, \frac{X}{2Y} - \frac{u'}{2})$ for which $g(x)$ is square. +* Let $y = \sqrt{g(x)}.$ +* Return $(x, y)$ if $sign(y) = sign(t)$; $(x, -y)$ otherwise. + +This is implemented in `rustsecp256k1zkp_v0_10_0_ellswift_swiftec_var`. The used $sign(x)$ function is the parity of $x$ when represented as in integer in $[0,q).$ + +The corresponding encoder would invoke the x-only one, but negating the output $t$ if $sign(t) \neq sign(y).$ + +This is implemented in `rustsecp256k1zkp_v0_10_0_ellswift_elligatorswift_var`. + +Note that this is only intended for encoding points where both the x-coordinate and y-coordinate are unpredictable. When encoding x-only points +where the y-coordinate is implicitly even (or implicitly square, or implicitly in $[0,q/2]$), the encoder in +[Section 3.5](#35-encoding-for-secp256k1) must be used, or a bias is reintroduced that undoes all the benefit of using ElligatorSwift +in the first place. diff --git a/secp256k1-zkp-sys/depend/secp256k1/doc/release-process.md b/secp256k1-zkp-sys/depend/secp256k1/doc/release-process.md index a35b8a9d..cdf62430 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/doc/release-process.md +++ b/secp256k1-zkp-sys/depend/secp256k1/doc/release-process.md @@ -1,14 +1,93 @@ -# Release Process - -1. Open PR to master that - 1. adds release notes to `doc/CHANGELOG.md` and - 2. if this is **not** a patch release, updates `_PKG_VERSION_{MAJOR,MINOR}` and `_LIB_VERSIONS_*` in `configure.ac` -2. After the PR is merged, - * if this is **not** a patch release, create a release branch with name `MAJOR.MINOR`. - Make sure that the branch contains the right commits. - Create commit on the release branch that sets `_PKG_VERSION_IS_RELEASE` in `configure.ac` to `true`. - * if this **is** a patch release, open a pull request with the bugfixes to the `MAJOR.MINOR` branch. - Also include the release note commit bump `_PKG_VERSION_BUILD` and `_LIB_VERSIONS_*` in `configure.ac`. -4. Tag the commit with `git tag -s vMAJOR.MINOR.PATCH`. -5. Push branch and tag with `git push origin --tags`. -6. Create a new GitHub release with a link to the corresponding entry in `doc/CHANGELOG.md`. +# Release process + +This document outlines the process for releasing versions of the form `$MAJOR.$MINOR.$PATCH`. + +We distinguish between two types of releases: *regular* and *maintenance* releases. +Regular releases are releases of a new major or minor version as well as patches of the most recent release. +Maintenance releases, on the other hand, are required for patches of older releases. + +You should coordinate with the other maintainers on the release date, if possible. +This date will be part of the release entry in [CHANGELOG.md](../CHANGELOG.md) and it should match the dates of the remaining steps in the release process (including the date of the tag and the GitHub release). +It is best if the maintainers are present during the release, so they can help ensure that the process is followed correctly and, in the case of a regular release, they are aware that they should not modify the master branch between merging the PR in step 1 and the PR in step 3. + +This process also assumes that there will be no minor releases for old major releases. + +We aim to cut a regular release every 3-4 months, approximately twice as frequent as major Bitcoin Core releases. Every second release should be published one month before the feature freeze of the next major Bitcoin Core release, allowing sufficient time to update the library in Core. + +## Sanity checks +Perform these checks when reviewing the release PR (see below): + +1. Ensure `make distcheck` doesn't fail. + ```shell + ./autogen.sh && ./configure --enable-dev-mode && make distcheck + ``` +2. Check installation with autotools: + ```shell + dir=$(mktemp -d) + ./autogen.sh && ./configure --prefix=$dir && make clean && make install && ls -RlAh $dir + gcc -o ecdsa examples/ecdsa.c $(PKG_CONFIG_PATH=$dir/lib/pkgconfig pkg-config --cflags --libs libsecp256k1) -Wl,-rpath,"$dir/lib" && ./ecdsa + ``` +3. Check installation with CMake: + ```shell + dir=$(mktemp -d) + build=$(mktemp -d) + cmake -B $build -DCMAKE_INSTALL_PREFIX=$dir && cmake --build $build --target install && ls -RlAh $dir + gcc -o ecdsa examples/ecdsa.c -I $dir/include -L $dir/lib*/ -l secp256k1 -Wl,-rpath,"$dir/lib",-rpath,"$dir/lib64" && ./ecdsa + ``` +4. Use the [`check-abi.sh`](/tools/check-abi.sh) tool to verify that there are no unexpected ABI incompatibilities and that the version number and the release notes accurately reflect all potential ABI changes. To run this tool, the `abi-dumper` and `abi-compliance-checker` packages are required. + ```shell + tools/check-abi.sh + ``` + +## Regular release + +1. Open a PR to the master branch with a commit (using message `"release: prepare for $MAJOR.$MINOR.$PATCH"`, for example) that + * finalizes the release notes in [CHANGELOG.md](../CHANGELOG.md) by + * adding a section for the release (make sure that the version number is a link to a diff between the previous and new version), + * removing the `[Unreleased]` section header, and + * including an entry for `### ABI Compatibility` if it doesn't exist, + * sets `_PKG_VERSION_IS_RELEASE` to `true` in `configure.ac`, and, + * if this is not a patch release, + * updates `_PKG_VERSION_*` and `_LIB_VERSION_*` in `configure.ac`, and + * updates `project(libsecp256k1 VERSION ...)` and `${PROJECT_NAME}_LIB_VERSION_*` in `CMakeLists.txt`. +2. Perform the [sanity checks](#sanity-checks) on the PR branch. +3. After the PR is merged, tag the commit, and push the tag: + ``` + RELEASE_COMMIT= + git tag -s v$MAJOR.$MINOR.$PATCH -m "libsecp256k1 $MAJOR.$MINOR.$PATCH" $RELEASE_COMMIT + git push git@github.com:bitcoin-core/secp256k1.git v$MAJOR.$MINOR.$PATCH + ``` +4. Open a PR to the master branch with a commit (using message `"release cleanup: bump version after $MAJOR.$MINOR.$PATCH"`, for example) that + * sets `_PKG_VERSION_IS_RELEASE` to `false` and increments `_PKG_VERSION_PATCH` and `_LIB_VERSION_REVISION` in `configure.ac`, + * increments the `$PATCH` component of `project(libsecp256k1 VERSION ...)` and `${PROJECT_NAME}_LIB_VERSION_REVISION` in `CMakeLists.txt`, and + * adds an `[Unreleased]` section header to the [CHANGELOG.md](../CHANGELOG.md). + + If other maintainers are not present to approve the PR, it can be merged without ACKs. +5. Create a new GitHub release with a link to the corresponding entry in [CHANGELOG.md](../CHANGELOG.md). +6. Send an announcement email to the bitcoin-dev mailing list. + +## Maintenance release + +Note that bug fixes need to be backported only to releases for which no compatible release without the bug exists. + +1. If there's no maintenance branch `$MAJOR.$MINOR`, create one: + ``` + git checkout -b $MAJOR.$MINOR v$MAJOR.$MINOR.$((PATCH - 1)) + git push git@github.com:bitcoin-core/secp256k1.git $MAJOR.$MINOR + ``` +2. Open a pull request to the `$MAJOR.$MINOR` branch that + * includes the bug fixes, + * finalizes the release notes similar to a regular release, + * increments `_PKG_VERSION_PATCH` and `_LIB_VERSION_REVISION` in `configure.ac` + and the `$PATCH` component of `project(libsecp256k1 VERSION ...)` and `${PROJECT_NAME}_LIB_VERSION_REVISION` in `CMakeLists.txt` + (with commit message `"release: bump versions for $MAJOR.$MINOR.$PATCH"`, for example). +3. Perform the [sanity checks](#sanity-checks) on the PR branch. +4. After the PRs are merged, update the release branch, tag the commit, and push the tag: + ``` + git checkout $MAJOR.$MINOR && git pull + git tag -s v$MAJOR.$MINOR.$PATCH -m "libsecp256k1 $MAJOR.$MINOR.$PATCH" + git push git@github.com:bitcoin-core/secp256k1.git v$MAJOR.$MINOR.$PATCH + ``` +6. Create a new GitHub release with a link to the corresponding entry in [CHANGELOG.md](../CHANGELOG.md). +7. Send an announcement email to the bitcoin-dev mailing list. +8. Open PR to the master branch that includes a commit (with commit message `"release notes: add $MAJOR.$MINOR.$PATCH"`, for example) that adds release notes to [CHANGELOG.md](../CHANGELOG.md). diff --git a/secp256k1-zkp-sys/depend/secp256k1/doc/safegcd_implementation.md b/secp256k1-zkp-sys/depend/secp256k1/doc/safegcd_implementation.md index 063aa8ef..5dbbb7bb 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/doc/safegcd_implementation.md +++ b/secp256k1-zkp-sys/depend/secp256k1/doc/safegcd_implementation.md @@ -1,7 +1,7 @@ # The safegcd implementation in libsecp256k1 explained -This document explains the modular inverse implementation in the `src/modinv*.h` files. It is based -on the paper +This document explains the modular inverse and Jacobi symbol implementations in the `src/modinv*.h` files. +It is based on the paper ["Fast constant-time gcd computation and modular inversion"](https://gcd.cr.yp.to/papers.html#safegcd) by Daniel J. Bernstein and Bo-Yin Yang. The references below are for the Date: 2019.04.13 version. @@ -410,7 +410,7 @@ sufficient even. Given that every loop iteration performs *N* divsteps, it will To deal with the branches in `divsteps_n_matrix` we will replace them with constant-time bitwise operations (and hope the C compiler isn't smart enough to turn them back into branches; see -`valgrind_ctime_test.c` for automated tests that this isn't the case). To do so, observe that a +`ctime_tests.c` for automated tests that this isn't the case). To do so, observe that a divstep can be written instead as (compare to the inner loop of `gcd` in section 1). ```python @@ -769,3 +769,51 @@ def modinv_var(M, Mi, x): d, e = update_de(d, e, t, M, Mi) return normalize(f, d, Mi) ``` + +## 8. From GCDs to Jacobi symbol + +We can also use a similar approach to calculate Jacobi symbol *(x | M)* by keeping track of an +extra variable *j*, for which at every step *(x | M) = j (g | f)*. As we update *f* and *g*, we +make corresponding updates to *j* using +[properties of the Jacobi symbol](https://en.wikipedia.org/wiki/Jacobi_symbol#Properties): +* *((g/2) | f)* is either *(g | f)* or *-(g | f)*, depending on the value of *f mod 8* (negating if it's *3* or *5*). +* *(f | g)* is either *(g | f)* or *-(g | f)*, depending on *f mod 4* and *g mod 4* (negating if both are *3*). + +These updates depend only on the values of *f* and *g* modulo *4* or *8*, and can thus be applied +very quickly, as long as we keep track of a few additional bits of *f* and *g*. Overall, this +calculation is slightly simpler than the one for the modular inverse because we no longer need to +keep track of *d* and *e*. + +However, one difficulty of this approach is that the Jacobi symbol *(a | n)* is only defined for +positive odd integers *n*, whereas in the original safegcd algorithm, *f, g* can take negative +values. We resolve this by using the following modified steps: + +```python + # Before + if delta > 0 and g & 1: + delta, f, g = 1 - delta, g, (g - f) // 2 + + # After + if delta > 0 and g & 1: + delta, f, g = 1 - delta, g, (g + f) // 2 +``` + +The algorithm is still correct, since the changed divstep, called a "posdivstep" (see section 8.4 +and E.5 in the paper) preserves *gcd(f, g)*. However, there's no proof that the modified algorithm +will converge. The justification for posdivsteps is completely empirical: in practice, it appears +that the vast majority of nonzero inputs converge to *f=g=gcd(f0, g0)* in a +number of steps proportional to their logarithm. + +Note that: +- We require inputs to satisfy *gcd(x, M) = 1*, as otherwise *f=1* is not reached. +- We require inputs *x &neq; 0*, because applying posdivstep with *g=0* has no effect. +- We need to update the termination condition from *g=0* to *f=1*. + +We account for the possibility of nonconvergence by only performing a bounded number of +posdivsteps, and then falling back to square-root based Jacobi calculation if a solution has not +yet been found. + +The optimizations in sections 3-7 above are described in the context of the original divsteps, but +in the C implementation we also adapt most of them (not including "avoiding modulus operations", +since it's not necessary to track *d, e*, and "constant-time operation", since we never calculate +Jacobi symbols for secret data) to the posdivsteps version. diff --git a/secp256k1-zkp-sys/depend/secp256k1/examples/ecdh.c b/secp256k1-zkp-sys/depend/secp256k1/examples/ecdh.c index b8637e69..d36eee75 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/examples/ecdh.c +++ b/secp256k1-zkp-sys/depend/secp256k1/examples/ecdh.c @@ -14,8 +14,7 @@ #include #include -#include "random.h" - +#include "examples_util.h" int main(void) { unsigned char seckey1[32]; @@ -27,23 +26,19 @@ int main(void) { unsigned char randomize[32]; int return_val; size_t len; - rustsecp256k1zkp_v0_8_0_pubkey pubkey1; - rustsecp256k1zkp_v0_8_0_pubkey pubkey2; - - /* The specification in secp256k1.h states that `rustsecp256k1zkp_v0_8_0_ec_pubkey_create` - * needs a context object initialized for signing, which is why we create - * a context with the SECP256K1_CONTEXT_SIGN flag. - * (The docs for `rustsecp256k1zkp_v0_8_0_ecdh` don't require any special context, just - * some initialized context) */ - rustsecp256k1zkp_v0_8_0_context* ctx = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN); + rustsecp256k1zkp_v0_10_0_pubkey pubkey1; + rustsecp256k1zkp_v0_10_0_pubkey pubkey2; + + /* Before we can call actual API functions, we need to create a "context". */ + rustsecp256k1zkp_v0_10_0_context* ctx = rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_CONTEXT_NONE); if (!fill_random(randomize, sizeof(randomize))) { printf("Failed to generate randomness\n"); return 1; } /* Randomizing the context is recommended to protect against side-channel - * leakage See `rustsecp256k1zkp_v0_8_0_context_randomize` in secp256k1.h for more + * leakage See `rustsecp256k1zkp_v0_10_0_context_randomize` in secp256k1.h for more * information about it. This should never fail. */ - return_val = rustsecp256k1zkp_v0_8_0_context_randomize(ctx, randomize); + return_val = rustsecp256k1zkp_v0_10_0_context_randomize(ctx, randomize); assert(return_val); /*** Key Generation ***/ @@ -56,27 +51,27 @@ int main(void) { printf("Failed to generate randomness\n"); return 1; } - if (rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, seckey1) && rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, seckey2)) { + if (rustsecp256k1zkp_v0_10_0_ec_seckey_verify(ctx, seckey1) && rustsecp256k1zkp_v0_10_0_ec_seckey_verify(ctx, seckey2)) { break; } } /* Public key creation using a valid context with a verified secret key should never fail */ - return_val = rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey1, seckey1); + return_val = rustsecp256k1zkp_v0_10_0_ec_pubkey_create(ctx, &pubkey1, seckey1); assert(return_val); - return_val = rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey2, seckey2); + return_val = rustsecp256k1zkp_v0_10_0_ec_pubkey_create(ctx, &pubkey2, seckey2); assert(return_val); /* Serialize pubkey1 in a compressed form (33 bytes), should always return 1 */ len = sizeof(compressed_pubkey1); - return_val = rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, compressed_pubkey1, &len, &pubkey1, SECP256K1_EC_COMPRESSED); + return_val = rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(ctx, compressed_pubkey1, &len, &pubkey1, SECP256K1_EC_COMPRESSED); assert(return_val); /* Should be the same size as the size of the output, because we passed a 33 byte array. */ assert(len == sizeof(compressed_pubkey1)); /* Serialize pubkey2 in a compressed form (33 bytes) */ len = sizeof(compressed_pubkey2); - return_val = rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, compressed_pubkey2, &len, &pubkey2, SECP256K1_EC_COMPRESSED); + return_val = rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(ctx, compressed_pubkey2, &len, &pubkey2, SECP256K1_EC_COMPRESSED); assert(return_val); /* Should be the same size as the size of the output, because we passed a 33 byte array. */ assert(len == sizeof(compressed_pubkey2)); @@ -85,12 +80,12 @@ int main(void) { /* Perform ECDH with seckey1 and pubkey2. Should never fail with a verified * seckey and valid pubkey */ - return_val = rustsecp256k1zkp_v0_8_0_ecdh(ctx, shared_secret1, &pubkey2, seckey1, NULL, NULL); + return_val = rustsecp256k1zkp_v0_10_0_ecdh(ctx, shared_secret1, &pubkey2, seckey1, NULL, NULL); assert(return_val); /* Perform ECDH with seckey2 and pubkey1. Should never fail with a verified * seckey and valid pubkey */ - return_val = rustsecp256k1zkp_v0_8_0_ecdh(ctx, shared_secret2, &pubkey1, seckey2, NULL, NULL); + return_val = rustsecp256k1zkp_v0_10_0_ecdh(ctx, shared_secret2, &pubkey1, seckey2, NULL, NULL); assert(return_val); /* Both parties should end up with the same shared secret */ @@ -109,19 +104,19 @@ int main(void) { print_hex(shared_secret1, sizeof(shared_secret1)); /* This will clear everything from the context and free the memory */ - rustsecp256k1zkp_v0_8_0_context_destroy(ctx); + rustsecp256k1zkp_v0_10_0_context_destroy(ctx); /* It's best practice to try to clear secrets from memory after using them. * This is done because some bugs can allow an attacker to leak memory, for * example through "out of bounds" array access (see Heartbleed), Or the OS * swapping them to disk. Hence, we overwrite the secret key buffer with zeros. * - * TODO: Prevent these writes from being optimized out, as any good compiler + * Here we are preventing these writes from being optimized out, as any good compiler * will remove any writes that aren't used. */ - memset(seckey1, 0, sizeof(seckey1)); - memset(seckey2, 0, sizeof(seckey2)); - memset(shared_secret1, 0, sizeof(shared_secret1)); - memset(shared_secret2, 0, sizeof(shared_secret2)); + secure_erase(seckey1, sizeof(seckey1)); + secure_erase(seckey2, sizeof(seckey2)); + secure_erase(shared_secret1, sizeof(shared_secret1)); + secure_erase(shared_secret2, sizeof(shared_secret2)); return 0; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/examples/ecdsa.c b/secp256k1-zkp-sys/depend/secp256k1/examples/ecdsa.c index 1d80c276..479d0503 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/examples/ecdsa.c +++ b/secp256k1-zkp-sys/depend/secp256k1/examples/ecdsa.c @@ -13,9 +13,7 @@ #include -#include "random.h" - - +#include "examples_util.h" int main(void) { /* Instead of signing the message directly, we must sign a 32-byte hash. @@ -34,24 +32,20 @@ int main(void) { unsigned char compressed_pubkey[33]; unsigned char serialized_signature[64]; size_t len; - int is_signature_valid; + int is_signature_valid, is_signature_valid2; int return_val; - rustsecp256k1zkp_v0_8_0_pubkey pubkey; - rustsecp256k1zkp_v0_8_0_ecdsa_signature sig; - /* The specification in secp256k1.h states that `rustsecp256k1zkp_v0_8_0_ec_pubkey_create` needs - * a context object initialized for signing and `rustsecp256k1zkp_v0_8_0_ecdsa_verify` needs - * a context initialized for verification, which is why we create a context - * for both signing and verification with the SECP256K1_CONTEXT_SIGN and - * SECP256K1_CONTEXT_VERIFY flags. */ - rustsecp256k1zkp_v0_8_0_context* ctx = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); + rustsecp256k1zkp_v0_10_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_ecdsa_signature sig; + /* Before we can call actual API functions, we need to create a "context". */ + rustsecp256k1zkp_v0_10_0_context* ctx = rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_CONTEXT_NONE); if (!fill_random(randomize, sizeof(randomize))) { printf("Failed to generate randomness\n"); return 1; } /* Randomizing the context is recommended to protect against side-channel - * leakage See `rustsecp256k1zkp_v0_8_0_context_randomize` in secp256k1.h for more + * leakage See `rustsecp256k1zkp_v0_10_0_context_randomize` in secp256k1.h for more * information about it. This should never fail. */ - return_val = rustsecp256k1zkp_v0_8_0_context_randomize(ctx, randomize); + return_val = rustsecp256k1zkp_v0_10_0_context_randomize(ctx, randomize); assert(return_val); /*** Key Generation ***/ @@ -64,18 +58,18 @@ int main(void) { printf("Failed to generate randomness\n"); return 1; } - if (rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, seckey)) { + if (rustsecp256k1zkp_v0_10_0_ec_seckey_verify(ctx, seckey)) { break; } } /* Public key creation using a valid context with a verified secret key should never fail */ - return_val = rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey, seckey); + return_val = rustsecp256k1zkp_v0_10_0_ec_pubkey_create(ctx, &pubkey, seckey); assert(return_val); /* Serialize the pubkey in a compressed form(33 bytes). Should always return 1. */ len = sizeof(compressed_pubkey); - return_val = rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, compressed_pubkey, &len, &pubkey, SECP256K1_EC_COMPRESSED); + return_val = rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(ctx, compressed_pubkey, &len, &pubkey, SECP256K1_EC_COMPRESSED); assert(return_val); /* Should be the same size as the size of the output, because we passed a 33 byte array. */ assert(len == sizeof(compressed_pubkey)); @@ -86,31 +80,31 @@ int main(void) { * custom nonce function, passing `NULL` will use the RFC-6979 safe default. * Signing with a valid context, verified secret key * and the default nonce function should never fail. */ - return_val = rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &sig, msg_hash, seckey, NULL, NULL); + return_val = rustsecp256k1zkp_v0_10_0_ecdsa_sign(ctx, &sig, msg_hash, seckey, NULL, NULL); assert(return_val); /* Serialize the signature in a compact form. Should always return 1 * according to the documentation in secp256k1.h. */ - return_val = rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_compact(ctx, serialized_signature, &sig); + return_val = rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_compact(ctx, serialized_signature, &sig); assert(return_val); /*** Verification ***/ /* Deserialize the signature. This will return 0 if the signature can't be parsed correctly. */ - if (!rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_compact(ctx, &sig, serialized_signature)) { + if (!rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_compact(ctx, &sig, serialized_signature)) { printf("Failed parsing the signature\n"); return 1; } /* Deserialize the public key. This will return 0 if the public key can't be parsed correctly. */ - if (!rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pubkey, compressed_pubkey, sizeof(compressed_pubkey))) { + if (!rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(ctx, &pubkey, compressed_pubkey, sizeof(compressed_pubkey))) { printf("Failed parsing the public key\n"); return 1; } /* Verify a signature. This will return 1 if it's valid and 0 if it's not. */ - is_signature_valid = rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &sig, msg_hash, &pubkey); + is_signature_valid = rustsecp256k1zkp_v0_10_0_ecdsa_verify(ctx, &sig, msg_hash, &pubkey); printf("Is the signature valid? %s\n", is_signature_valid ? "true" : "false"); printf("Secret Key: "); @@ -120,18 +114,26 @@ int main(void) { printf("Signature: "); print_hex(serialized_signature, sizeof(serialized_signature)); - /* This will clear everything from the context and free the memory */ - rustsecp256k1zkp_v0_8_0_context_destroy(ctx); + rustsecp256k1zkp_v0_10_0_context_destroy(ctx); + + /* Bonus example: if all we need is signature verification (and no key + generation or signing), we don't need to use a context created via + rustsecp256k1zkp_v0_10_0_context_create(). We can simply use the static (i.e., global) + context rustsecp256k1zkp_v0_10_0_context_static. See its description in + include/secp256k1.h for details. */ + is_signature_valid2 = rustsecp256k1zkp_v0_10_0_ecdsa_verify(rustsecp256k1zkp_v0_10_0_context_static, + &sig, msg_hash, &pubkey); + assert(is_signature_valid2 == is_signature_valid); /* It's best practice to try to clear secrets from memory after using them. * This is done because some bugs can allow an attacker to leak memory, for * example through "out of bounds" array access (see Heartbleed), Or the OS * swapping them to disk. Hence, we overwrite the secret key buffer with zeros. * - * TODO: Prevent these writes from being optimized out, as any good compiler + * Here we are preventing these writes from being optimized out, as any good compiler * will remove any writes that aren't used. */ - memset(seckey, 0, sizeof(seckey)); + secure_erase(seckey, sizeof(seckey)); return 0; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/examples/random.h b/secp256k1-zkp-sys/depend/secp256k1/examples/examples_util.h similarity index 66% rename from secp256k1-zkp-sys/depend/secp256k1/examples/random.h rename to secp256k1-zkp-sys/depend/secp256k1/examples/examples_util.h index 439226f0..3293b640 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/examples/random.h +++ b/secp256k1-zkp-sys/depend/secp256k1/examples/examples_util.h @@ -17,7 +17,13 @@ */ #if defined(_WIN32) +/* + * The defined WIN32_NO_STATUS macro disables return code definitions in + * windows.h, which avoids "macro redefinition" MSVC warnings in ntstatus.h. + */ +#define WIN32_NO_STATUS #include +#undef WIN32_NO_STATUS #include #include #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) @@ -71,3 +77,32 @@ static void print_hex(unsigned char* data, size_t size) { } printf("\n"); } + +#if defined(_MSC_VER) +// For SecureZeroMemory +#include +#endif +/* Cleanses memory to prevent leaking sensitive info. Won't be optimized out. */ +static void secure_erase(void *ptr, size_t len) { +#if defined(_MSC_VER) + /* SecureZeroMemory is guaranteed not to be optimized out by MSVC. */ + SecureZeroMemory(ptr, len); +#elif defined(__GNUC__) + /* We use a memory barrier that scares the compiler away from optimizing out the memset. + * + * Quoting Adam Langley in commit ad1907fe73334d6c696c8539646c21b11178f20f + * in BoringSSL (ISC License): + * As best as we can tell, this is sufficient to break any optimisations that + * might try to eliminate "superfluous" memsets. + * This method used in memzero_explicit() the Linux kernel, too. Its advantage is that it is + * pretty efficient, because the compiler can still implement the memset() efficiently, + * just not remove it entirely. See "Dead Store Elimination (Still) Considered Harmful" by + * Yang et al. (USENIX Security 2017) for more background. + */ + memset(ptr, 0, len); + __asm__ __volatile__("" : : "r"(ptr) : "memory"); +#else + void *(*volatile const volatile_memset)(void *, int, size_t) = memset; + volatile_memset(ptr, 0, len); +#endif +} diff --git a/secp256k1-zkp-sys/depend/secp256k1/examples/musig.c b/secp256k1-zkp-sys/depend/secp256k1/examples/musig.c index b901669f..ff6beb4e 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/examples/musig.c +++ b/secp256k1-zkp-sys/depend/secp256k1/examples/musig.c @@ -9,43 +9,45 @@ /** This file demonstrates how to use the MuSig module to create a * 3-of-3 multisignature. Additionally, see the documentation in - * include/rustsecp256k1zkp_v0_8_0_musig.h and src/modules/musig/musig.md. + * include/rustsecp256k1zkp_v0_10_0_musig.h and src/modules/musig/musig.md. */ #include #include +#include + #include #include #include -#include "random.h" +#include "examples_util.h" struct signer_secrets { - rustsecp256k1zkp_v0_8_0_keypair keypair; - rustsecp256k1zkp_v0_8_0_musig_secnonce secnonce; + rustsecp256k1zkp_v0_10_0_keypair keypair; + rustsecp256k1zkp_v0_10_0_musig_secnonce secnonce; }; struct signer { - rustsecp256k1zkp_v0_8_0_pubkey pubkey; - rustsecp256k1zkp_v0_8_0_musig_pubnonce pubnonce; - rustsecp256k1zkp_v0_8_0_musig_partial_sig partial_sig; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_musig_pubnonce pubnonce; + rustsecp256k1zkp_v0_10_0_musig_partial_sig partial_sig; }; /* Number of public keys involved in creating the aggregate signature */ #define N_SIGNERS 3 /* Create a key pair, store it in signer_secrets->keypair and signer->pubkey */ -int create_keypair(const rustsecp256k1zkp_v0_8_0_context* ctx, struct signer_secrets *signer_secrets, struct signer *signer) { +static int create_keypair(const rustsecp256k1zkp_v0_10_0_context* ctx, struct signer_secrets *signer_secrets, struct signer *signer) { unsigned char seckey[32]; while (1) { if (!fill_random(seckey, sizeof(seckey))) { printf("Failed to generate randomness\n"); return 1; } - if (rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &signer_secrets->keypair, seckey)) { + if (rustsecp256k1zkp_v0_10_0_keypair_create(ctx, &signer_secrets->keypair, seckey)) { break; } } - if (!rustsecp256k1zkp_v0_8_0_keypair_pub(ctx, &signer->pubkey, &signer_secrets->keypair)) { + if (!rustsecp256k1zkp_v0_10_0_keypair_pub(ctx, &signer->pubkey, &signer_secrets->keypair)) { return 0; } return 1; @@ -53,66 +55,66 @@ int create_keypair(const rustsecp256k1zkp_v0_8_0_context* ctx, struct signer_sec /* Tweak the pubkey corresponding to the provided keyagg cache, update the cache * and return the tweaked aggregate pk. */ -int tweak(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_xonly_pubkey *agg_pk, rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *cache) { - rustsecp256k1zkp_v0_8_0_pubkey output_pk; +static int tweak(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_xonly_pubkey *agg_pk, rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *cache) { + rustsecp256k1zkp_v0_10_0_pubkey output_pk; unsigned char plain_tweak[32] = "this could be a BIP32 tweak...."; unsigned char xonly_tweak[32] = "this could be a taproot tweak.."; /* Plain tweaking which, for example, allows deriving multiple child * public keys from a single aggregate key using BIP32 */ - if (!rustsecp256k1zkp_v0_8_0_musig_pubkey_ec_tweak_add(ctx, NULL, cache, plain_tweak)) { + if (!rustsecp256k1zkp_v0_10_0_musig_pubkey_ec_tweak_add(ctx, NULL, cache, plain_tweak)) { return 0; } /* Note that we did not provided an output_pk argument, because the * resulting pk is also saved in the cache and so if one is just interested * in signing the output_pk argument is unnecessary. On the other hand, if * one is not interested in signing, the same output_pk can be obtained by - * calling `rustsecp256k1zkp_v0_8_0_musig_pubkey_get` right after key aggregation to get - * the full pubkey and then call `rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add`. */ + * calling `rustsecp256k1zkp_v0_10_0_musig_pubkey_get` right after key aggregation to get + * the full pubkey and then call `rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add`. */ /* Xonly tweaking which, for example, allows creating taproot commitments */ - if (!rustsecp256k1zkp_v0_8_0_musig_pubkey_xonly_tweak_add(ctx, &output_pk, cache, xonly_tweak)) { + if (!rustsecp256k1zkp_v0_10_0_musig_pubkey_xonly_tweak_add(ctx, &output_pk, cache, xonly_tweak)) { return 0; } /* Note that if we wouldn't care about signing, we can arrive at the same * output_pk by providing the untweaked public key to - * `rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add` (after converting it to an xonly pubkey - * if necessary with `rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey`). */ + * `rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add` (after converting it to an xonly pubkey + * if necessary with `rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey`). */ /* Now we convert the output_pk to an xonly pubkey to allow to later verify * the Schnorr signature against it. For this purpose we can ignore the * `pk_parity` output argument; we would need it if we would have to open * the taproot commitment. */ - if (!rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(ctx, agg_pk, NULL, &output_pk)) { + if (!rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(ctx, agg_pk, NULL, &output_pk)) { return 0; } return 1; } /* Sign a message hash with the given key pairs and store the result in sig */ -int sign(const rustsecp256k1zkp_v0_8_0_context* ctx, struct signer_secrets *signer_secrets, struct signer *signer, const rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *cache, const unsigned char *msg32, unsigned char *sig64) { +static int sign(const rustsecp256k1zkp_v0_10_0_context* ctx, struct signer_secrets *signer_secrets, struct signer *signer, const rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *cache, const unsigned char *msg32, unsigned char *sig64) { int i; - const rustsecp256k1zkp_v0_8_0_musig_pubnonce *pubnonces[N_SIGNERS]; - const rustsecp256k1zkp_v0_8_0_musig_partial_sig *partial_sigs[N_SIGNERS]; + const rustsecp256k1zkp_v0_10_0_musig_pubnonce *pubnonces[N_SIGNERS]; + const rustsecp256k1zkp_v0_10_0_musig_partial_sig *partial_sigs[N_SIGNERS]; /* The same for all signers */ - rustsecp256k1zkp_v0_8_0_musig_session session; + rustsecp256k1zkp_v0_10_0_musig_session session; for (i = 0; i < N_SIGNERS; i++) { unsigned char seckey[32]; unsigned char session_id[32]; /* Create random session ID. It is absolutely necessary that the session ID - * is unique for every call of rustsecp256k1zkp_v0_8_0_musig_nonce_gen. Otherwise + * is unique for every call of rustsecp256k1zkp_v0_10_0_musig_nonce_gen. Otherwise * it's trivial for an attacker to extract the secret key! */ if (!fill_random(session_id, sizeof(session_id))) { return 0; } - if (!rustsecp256k1zkp_v0_8_0_keypair_sec(ctx, seckey, &signer_secrets[i].keypair)) { + if (!rustsecp256k1zkp_v0_10_0_keypair_sec(ctx, seckey, &signer_secrets[i].keypair)) { return 0; } /* Initialize session and create secret nonce for signing and public * nonce to send to the other signers. */ - if (!rustsecp256k1zkp_v0_8_0_musig_nonce_gen(ctx, &signer_secrets[i].secnonce, &signer[i].pubnonce, session_id, seckey, &signer[i].pubkey, msg32, NULL, NULL)) { + if (!rustsecp256k1zkp_v0_10_0_musig_nonce_gen(ctx, &signer_secrets[i].secnonce, &signer[i].pubnonce, session_id, seckey, &signer[i].pubkey, msg32, NULL, NULL)) { return 0; } pubnonces[i] = &signer[i].pubnonce; @@ -120,20 +122,20 @@ int sign(const rustsecp256k1zkp_v0_8_0_context* ctx, struct signer_secrets *sign /* Communication round 1: A production system would exchange public nonces * here before moving on. */ for (i = 0; i < N_SIGNERS; i++) { - rustsecp256k1zkp_v0_8_0_musig_aggnonce agg_pubnonce; + rustsecp256k1zkp_v0_10_0_musig_aggnonce agg_pubnonce; /* Create aggregate nonce and initialize the session */ - if (!rustsecp256k1zkp_v0_8_0_musig_nonce_agg(ctx, &agg_pubnonce, pubnonces, N_SIGNERS)) { + if (!rustsecp256k1zkp_v0_10_0_musig_nonce_agg(ctx, &agg_pubnonce, pubnonces, N_SIGNERS)) { return 0; } - if (!rustsecp256k1zkp_v0_8_0_musig_nonce_process(ctx, &session, &agg_pubnonce, msg32, cache, NULL)) { + if (!rustsecp256k1zkp_v0_10_0_musig_nonce_process(ctx, &session, &agg_pubnonce, msg32, cache, NULL)) { return 0; } /* partial_sign will clear the secnonce by setting it to 0. That's because * you must _never_ reuse the secnonce (or use the same session_id to * create a secnonce). If you do, you effectively reuse the nonce and * leak the secret key. */ - if (!rustsecp256k1zkp_v0_8_0_musig_partial_sign(ctx, &signer[i].partial_sig, &signer_secrets[i].secnonce, &signer_secrets[i].keypair, cache, &session)) { + if (!rustsecp256k1zkp_v0_10_0_musig_partial_sign(ctx, &signer[i].partial_sig, &signer_secrets[i].secnonce, &signer_secrets[i].keypair, cache, &session)) { return 0; } partial_sigs[i] = &signer[i].partial_sig; @@ -143,7 +145,7 @@ int sign(const rustsecp256k1zkp_v0_8_0_context* ctx, struct signer_secrets *sign for (i = 0; i < N_SIGNERS; i++) { /* To check whether signing was successful, it suffices to either verify * the aggregate signature with the aggregate public key using - * rustsecp256k1zkp_v0_8_0_schnorrsig_verify, or verify all partial signatures of all + * rustsecp256k1zkp_v0_10_0_schnorrsig_verify, or verify all partial signatures of all * signers individually. Verifying the aggregate signature is cheaper but * verifying the individual partial signatures has the advantage that it * can be used to determine which of the partial signatures are invalid @@ -152,26 +154,26 @@ int sign(const rustsecp256k1zkp_v0_8_0_context* ctx, struct signer_secrets *sign * fine to first verify the aggregate sig, and only verify the individual * sigs if it does not work. */ - if (!rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(ctx, &signer[i].partial_sig, &signer[i].pubnonce, &signer[i].pubkey, cache, &session)) { + if (!rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(ctx, &signer[i].partial_sig, &signer[i].pubnonce, &signer[i].pubkey, cache, &session)) { return 0; } } - return rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg(ctx, sig64, &session, partial_sigs, N_SIGNERS); + return rustsecp256k1zkp_v0_10_0_musig_partial_sig_agg(ctx, sig64, &session, partial_sigs, N_SIGNERS); } int main(void) { - rustsecp256k1zkp_v0_8_0_context* ctx; + rustsecp256k1zkp_v0_10_0_context* ctx; int i; struct signer_secrets signer_secrets[N_SIGNERS]; struct signer signers[N_SIGNERS]; - const rustsecp256k1zkp_v0_8_0_pubkey *pubkeys_ptr[N_SIGNERS]; - rustsecp256k1zkp_v0_8_0_xonly_pubkey agg_pk; - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache cache; + const rustsecp256k1zkp_v0_10_0_pubkey *pubkeys_ptr[N_SIGNERS]; + rustsecp256k1zkp_v0_10_0_xonly_pubkey agg_pk; + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache cache; unsigned char msg[32] = "this_could_be_the_hash_of_a_msg!"; unsigned char sig[64]; - /* Create a context for signing and verification */ - ctx = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); + /* Create a secp256k1 context */ + ctx = rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_CONTEXT_NONE); printf("Creating key pairs......"); for (i = 0; i < N_SIGNERS; i++) { if (!create_keypair(ctx, &signer_secrets[i], &signers[i])) { @@ -183,7 +185,7 @@ int sign(const rustsecp256k1zkp_v0_8_0_context* ctx, struct signer_secrets *sign printf("ok\n"); printf("Combining public keys..."); /* If you just want to aggregate and not sign the cache can be NULL */ - if (!rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(ctx, NULL, &agg_pk, &cache, pubkeys_ptr, N_SIGNERS)) { + if (!rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(ctx, NULL, &agg_pk, &cache, pubkeys_ptr, N_SIGNERS)) { printf("FAILED\n"); return 1; } @@ -202,11 +204,11 @@ int sign(const rustsecp256k1zkp_v0_8_0_context* ctx, struct signer_secrets *sign } printf("ok\n"); printf("Verifying signature....."); - if (!rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, sig, msg, 32, &agg_pk)) { + if (!rustsecp256k1zkp_v0_10_0_schnorrsig_verify(ctx, sig, msg, 32, &agg_pk)) { printf("FAILED\n"); return 1; } printf("ok\n"); - rustsecp256k1zkp_v0_8_0_context_destroy(ctx); + rustsecp256k1zkp_v0_10_0_context_destroy(ctx); return 0; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/examples/schnorr.c b/secp256k1-zkp-sys/depend/secp256k1/examples/schnorr.c index be2f4d3a..93db74e7 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/examples/schnorr.c +++ b/secp256k1-zkp-sys/depend/secp256k1/examples/schnorr.c @@ -15,7 +15,7 @@ #include #include -#include "random.h" +#include "examples_util.h" int main(void) { unsigned char msg[12] = "Hello World!"; @@ -26,24 +26,20 @@ int main(void) { unsigned char auxiliary_rand[32]; unsigned char serialized_pubkey[32]; unsigned char signature[64]; - int is_signature_valid; + int is_signature_valid, is_signature_valid2; int return_val; - rustsecp256k1zkp_v0_8_0_xonly_pubkey pubkey; - rustsecp256k1zkp_v0_8_0_keypair keypair; - /* The specification in rustsecp256k1zkp_v0_8_0_extrakeys.h states that `rustsecp256k1zkp_v0_8_0_keypair_create` - * needs a context object initialized for signing. And in rustsecp256k1zkp_v0_8_0_schnorrsig.h - * they state that `rustsecp256k1zkp_v0_8_0_schnorrsig_verify` needs a context initialized for - * verification, which is why we create a context for both signing and verification - * with the SECP256K1_CONTEXT_SIGN and SECP256K1_CONTEXT_VERIFY flags. */ - rustsecp256k1zkp_v0_8_0_context* ctx = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); + rustsecp256k1zkp_v0_10_0_xonly_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_keypair keypair; + /* Before we can call actual API functions, we need to create a "context". */ + rustsecp256k1zkp_v0_10_0_context* ctx = rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_CONTEXT_NONE); if (!fill_random(randomize, sizeof(randomize))) { printf("Failed to generate randomness\n"); return 1; } /* Randomizing the context is recommended to protect against side-channel - * leakage See `rustsecp256k1zkp_v0_8_0_context_randomize` in secp256k1.h for more + * leakage See `rustsecp256k1zkp_v0_10_0_context_randomize` in secp256k1.h for more * information about it. This should never fail. */ - return_val = rustsecp256k1zkp_v0_8_0_context_randomize(ctx, randomize); + return_val = rustsecp256k1zkp_v0_10_0_context_randomize(ctx, randomize); assert(return_val); /*** Key Generation ***/ @@ -58,21 +54,21 @@ int main(void) { } /* Try to create a keypair with a valid context, it should only fail if * the secret key is zero or out of range. */ - if (rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, seckey)) { + if (rustsecp256k1zkp_v0_10_0_keypair_create(ctx, &keypair, seckey)) { break; } } /* Extract the X-only public key from the keypair. We pass NULL for * `pk_parity` as the parity isn't needed for signing or verification. - * `rustsecp256k1zkp_v0_8_0_keypair_xonly_pub` supports returning the parity for + * `rustsecp256k1zkp_v0_10_0_keypair_xonly_pub` supports returning the parity for * other use cases such as tests or verifying Taproot tweaks. * This should never fail with a valid context and public key. */ - return_val = rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(ctx, &pubkey, NULL, &keypair); + return_val = rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(ctx, &pubkey, NULL, &keypair); assert(return_val); /* Serialize the public key. Should always return 1 for a valid public key. */ - return_val = rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(ctx, serialized_pubkey, &pubkey); + return_val = rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(ctx, serialized_pubkey, &pubkey); assert(return_val); /*** Signing ***/ @@ -80,7 +76,7 @@ int main(void) { /* Instead of signing (possibly very long) messages directly, we sign a * 32-byte hash of the message in this example. * - * We use rustsecp256k1zkp_v0_8_0_tagged_sha256 to create this hash. This function expects + * We use rustsecp256k1zkp_v0_10_0_tagged_sha256 to create this hash. This function expects * a context-specific "tag", which restricts the context in which the signed * messages should be considered valid. For example, if protocol A mandates * to use the tag "my_fancy_protocol" and protocol B mandates to use the tag @@ -91,7 +87,7 @@ int main(void) { * message that has intended consequences in the intended context (e.g., * protocol A) but would have unintended consequences if it were valid in * some other context (e.g., protocol B). */ - return_val = rustsecp256k1zkp_v0_8_0_tagged_sha256(ctx, msg_hash, tag, sizeof(tag), msg, sizeof(msg)); + return_val = rustsecp256k1zkp_v0_10_0_tagged_sha256(ctx, msg_hash, tag, sizeof(tag), msg, sizeof(msg)); assert(return_val); /* Generate 32 bytes of randomness to use with BIP-340 schnorr signing. */ @@ -102,30 +98,30 @@ int main(void) { /* Generate a Schnorr signature. * - * We use the rustsecp256k1zkp_v0_8_0_schnorrsig_sign32 function that provides a simple + * We use the rustsecp256k1zkp_v0_10_0_schnorrsig_sign32 function that provides a simple * interface for signing 32-byte messages (which in our case is a hash of * the actual message). BIP-340 recommends passing 32 bytes of randomness * to the signing function to improve security against side-channel attacks. * Signing with a valid context, a 32-byte message, a verified keypair, and * any 32 bytes of auxiliary random data should never fail. */ - return_val = rustsecp256k1zkp_v0_8_0_schnorrsig_sign32(ctx, signature, msg_hash, &keypair, auxiliary_rand); + return_val = rustsecp256k1zkp_v0_10_0_schnorrsig_sign32(ctx, signature, msg_hash, &keypair, auxiliary_rand); assert(return_val); /*** Verification ***/ /* Deserialize the public key. This will return 0 if the public key can't * be parsed correctly */ - if (!rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(ctx, &pubkey, serialized_pubkey)) { + if (!rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(ctx, &pubkey, serialized_pubkey)) { printf("Failed parsing the public key\n"); return 1; } /* Compute the tagged hash on the received messages using the same tag as the signer. */ - return_val = rustsecp256k1zkp_v0_8_0_tagged_sha256(ctx, msg_hash, tag, sizeof(tag), msg, sizeof(msg)); + return_val = rustsecp256k1zkp_v0_10_0_tagged_sha256(ctx, msg_hash, tag, sizeof(tag), msg, sizeof(msg)); assert(return_val); /* Verify a signature. This will return 1 if it's valid and 0 if it's not. */ - is_signature_valid = rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, signature, msg_hash, 32, &pubkey); + is_signature_valid = rustsecp256k1zkp_v0_10_0_schnorrsig_verify(ctx, signature, msg_hash, 32, &pubkey); printf("Is the signature valid? %s\n", is_signature_valid ? "true" : "false"); @@ -137,16 +133,24 @@ int main(void) { print_hex(signature, sizeof(signature)); /* This will clear everything from the context and free the memory */ - rustsecp256k1zkp_v0_8_0_context_destroy(ctx); + rustsecp256k1zkp_v0_10_0_context_destroy(ctx); + + /* Bonus example: if all we need is signature verification (and no key + generation or signing), we don't need to use a context created via + rustsecp256k1zkp_v0_10_0_context_create(). We can simply use the static (i.e., global) + context rustsecp256k1zkp_v0_10_0_context_static. See its description in + include/secp256k1.h for details. */ + is_signature_valid2 = rustsecp256k1zkp_v0_10_0_schnorrsig_verify(rustsecp256k1zkp_v0_10_0_context_static, + signature, msg_hash, 32, &pubkey); + assert(is_signature_valid2 == is_signature_valid); /* It's best practice to try to clear secrets from memory after using them. * This is done because some bugs can allow an attacker to leak memory, for * example through "out of bounds" array access (see Heartbleed), Or the OS * swapping them to disk. Hence, we overwrite the secret key buffer with zeros. * - * TODO: Prevent these writes from being optimized out, as any good compiler + * Here we are preventing these writes from being optimized out, as any good compiler * will remove any writes that aren't used. */ - memset(seckey, 0, sizeof(seckey)); - + secure_erase(seckey, sizeof(seckey)); return 0; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1.h b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1.h index c09ffbdf..3cca2c75 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1.h +++ b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1.h @@ -7,7 +7,7 @@ extern "C" { #include -/* Unless explicitly stated all pointer arguments must not be NULL. +/** Unless explicitly stated all pointer arguments must not be NULL. * * The following rules specify the order of arguments in API calls: * @@ -24,28 +24,32 @@ extern "C" { * 5. Opaque data pointers follow the function pointer they are to be passed to. */ -/** Opaque data structure that holds context information (precomputed tables etc.). +/** Opaque data structure that holds context information * - * The purpose of context structures is to cache large precomputed data tables - * that are expensive to construct, and also to maintain the randomization data - * for blinding. + * The primary purpose of context objects is to store randomization data for + * enhanced protection against side-channel leakage. This protection is only + * effective if the context is randomized after its creation. See + * rustsecp256k1zkp_v0_10_0_context_create for creation of contexts and + * rustsecp256k1zkp_v0_10_0_context_randomize for randomization. * - * Do not create a new context object for each operation, as construction is - * far slower than all other API calls (~100 times slower than an ECDSA - * verification). + * A secondary purpose of context objects is to store pointers to callback + * functions that the library will call when certain error states arise. See + * rustsecp256k1zkp_v0_10_0_context_set_error_callback as well as + * rustsecp256k1zkp_v0_10_0_context_set_illegal_callback for details. Future library versions + * may use context objects for additional purposes. * * A constructed context can safely be used from multiple threads * simultaneously, but API calls that take a non-const pointer to a context * need exclusive access to it. In particular this is the case for - * rustsecp256k1zkp_v0_8_0_context_destroy, rustsecp256k1zkp_v0_8_0_context_preallocated_destroy, - * and rustsecp256k1zkp_v0_8_0_context_randomize. + * rustsecp256k1zkp_v0_10_0_context_destroy, rustsecp256k1zkp_v0_10_0_context_preallocated_destroy, + * and rustsecp256k1zkp_v0_10_0_context_randomize. * * Regarding randomization, either do it once at creation time (in which case * you do not need any locking for the other calls), or use a read-write lock. */ -typedef struct rustsecp256k1zkp_v0_8_0_context_struct rustsecp256k1zkp_v0_8_0_context; +typedef struct rustsecp256k1zkp_v0_10_0_context_struct rustsecp256k1zkp_v0_10_0_context; -/** Opaque data structure that holds rewriteable "scratch space" +/** Opaque data structure that holds rewritable "scratch space" * * The purpose of this structure is to replace dynamic memory allocations, * because we target architectures where this may not be available. It is @@ -56,7 +60,7 @@ typedef struct rustsecp256k1zkp_v0_8_0_context_struct rustsecp256k1zkp_v0_8_0_co * Unlike the context object, this cannot safely be shared between threads * without additional synchronization logic. */ -typedef struct rustsecp256k1zkp_v0_8_0_scratch_space_struct rustsecp256k1zkp_v0_8_0_scratch_space; +typedef struct rustsecp256k1zkp_v0_10_0_scratch_space_struct rustsecp256k1zkp_v0_10_0_scratch_space; /** Opaque data structure that holds a parsed and valid public key. * @@ -64,12 +68,12 @@ typedef struct rustsecp256k1zkp_v0_8_0_scratch_space_struct rustsecp256k1zkp_v0_ * guaranteed to be portable between different platforms or versions. It is * however guaranteed to be 64 bytes in size, and can be safely copied/moved. * If you need to convert to a format suitable for storage or transmission, - * use rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize and rustsecp256k1zkp_v0_8_0_ec_pubkey_parse. To - * compare keys, use rustsecp256k1zkp_v0_8_0_ec_pubkey_cmp. + * use rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize and rustsecp256k1zkp_v0_10_0_ec_pubkey_parse. To + * compare keys, use rustsecp256k1zkp_v0_10_0_ec_pubkey_cmp. */ typedef struct { unsigned char data[64]; -} rustsecp256k1zkp_v0_8_0_pubkey; +} rustsecp256k1zkp_v0_10_0_pubkey; /** Opaque data structured that holds a parsed ECDSA signature. * @@ -77,12 +81,12 @@ typedef struct { * guaranteed to be portable between different platforms or versions. It is * however guaranteed to be 64 bytes in size, and can be safely copied/moved. * If you need to convert to a format suitable for storage, transmission, or - * comparison, use the rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_* and - * rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_* functions. + * comparison, use the rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_* and + * rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_* functions. */ typedef struct { unsigned char data[64]; -} rustsecp256k1zkp_v0_8_0_ecdsa_signature; +} rustsecp256k1zkp_v0_10_0_ecdsa_signature; /** A pointer to a function to deterministically generate a nonce. * @@ -100,7 +104,7 @@ typedef struct { * Except for test cases, this function should compute some cryptographic hash of * the message, the algorithm, the key and the attempt. */ -typedef int (*rustsecp256k1zkp_v0_8_0_nonce_function)( +typedef int (*rustsecp256k1zkp_v0_10_0_nonce_function)( unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, @@ -118,19 +122,7 @@ typedef int (*rustsecp256k1zkp_v0_8_0_nonce_function)( # endif # endif -# if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) ) -# if SECP256K1_GNUC_PREREQ(2,7) -# define SECP256K1_INLINE __inline__ -# elif (defined(_MSC_VER)) -# define SECP256K1_INLINE __inline -# else -# define SECP256K1_INLINE -# endif -# else -# define SECP256K1_INLINE inline -# endif - -/** When this header is used at build-time the SECP256K1_BUILD define needs to be set +/* When this header is used at build-time the SECP256K1_BUILD define needs to be set * to correctly setup export attributes and nullness checks. This is normally done * by secp256k1.c but to guard against this header being included before secp256k1.c * has had a chance to set the define (e.g. via test harnesses that just includes @@ -141,23 +133,41 @@ typedef int (*rustsecp256k1zkp_v0_8_0_nonce_function)( # define SECP256K1_NO_BUILD #endif -#ifndef SECP256K1_API -# if defined(_WIN32) -# ifdef SECP256K1_BUILD -# define SECP256K1_API __declspec(dllexport) -# else -# define SECP256K1_API +/* Symbol visibility. */ +#if defined(_WIN32) + /* GCC for Windows (e.g., MinGW) accepts the __declspec syntax + * for MSVC compatibility. A __declspec declaration implies (but is not + * exactly equivalent to) __attribute__ ((visibility("default"))), and so we + * actually want __declspec even on GCC, see "Microsoft Windows Function + * Attributes" in the GCC manual and the recommendations in + * https://gcc.gnu.org/wiki/Visibility. */ +# if defined(SECP256K1_BUILD) +# if defined(DLL_EXPORT) || defined(SECP256K1_DLL_EXPORT) + /* Building libsecp256k1 as a DLL. + * 1. If using Libtool, it defines DLL_EXPORT automatically. + * 2. In other cases, SECP256K1_DLL_EXPORT must be defined. */ +# define SECP256K1_API extern __declspec (dllexport) # endif -# elif defined(__GNUC__) && (__GNUC__ >= 4) && defined(SECP256K1_BUILD) -# define SECP256K1_API __attribute__ ((visibility ("default"))) + /* The user must define SECP256K1_STATIC when consuming libsecp256k1 as a static + * library on Windows. */ +# elif !defined(SECP256K1_STATIC) + /* Consuming libsecp256k1 as a DLL. */ +# define SECP256K1_API extern __declspec (dllimport) +# endif +#endif +#ifndef SECP256K1_API +# if defined(__GNUC__) && (__GNUC__ >= 4) && defined(SECP256K1_BUILD) + /* Building libsecp256k1 on non-Windows using GCC or compatible. */ +# define SECP256K1_API extern __attribute__ ((visibility ("default"))) # else -# define SECP256K1_API + /* All cases not captured above. */ +# define SECP256K1_API extern # endif #endif -/**Warning attributes - * NONNULL is not used if SECP256K1_BUILD is set to avoid the compiler optimizing out - * some paranoid null checks. */ +/* Warning attributes + * NONNULL is not used if SECP256K1_BUILD is set to avoid the compiler optimizing out + * some paranoid null checks. */ # if defined(__GNUC__) && SECP256K1_GNUC_PREREQ(3, 4) # define SECP256K1_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__)) # else @@ -169,7 +179,7 @@ typedef int (*rustsecp256k1zkp_v0_8_0_nonce_function)( # define SECP256K1_ARG_NONNULL(_x) # endif -/** Attribute for marking functions, types, and variables as deprecated */ +/* Attribute for marking functions, types, and variables as deprecated */ #if !defined(SECP256K1_BUILD) && defined(__has_attribute) # if __has_attribute(__deprecated__) # define SECP256K1_DEPRECATED(_msg) __attribute__ ((__deprecated__(_msg))) @@ -180,24 +190,28 @@ typedef int (*rustsecp256k1zkp_v0_8_0_nonce_function)( # define SECP256K1_DEPRECATED(_msg) #endif -/** All flags' lower 8 bits indicate what they're for. Do not use directly. */ +/* All flags' lower 8 bits indicate what they're for. Do not use directly. */ #define SECP256K1_FLAGS_TYPE_MASK ((1 << 8) - 1) #define SECP256K1_FLAGS_TYPE_CONTEXT (1 << 0) #define SECP256K1_FLAGS_TYPE_COMPRESSION (1 << 1) -/** The higher bits contain the actual data. Do not use directly. */ +/* The higher bits contain the actual data. Do not use directly. */ #define SECP256K1_FLAGS_BIT_CONTEXT_VERIFY (1 << 8) #define SECP256K1_FLAGS_BIT_CONTEXT_SIGN (1 << 9) #define SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY (1 << 10) #define SECP256K1_FLAGS_BIT_COMPRESSION (1 << 8) -/** Flags to pass to rustsecp256k1zkp_v0_8_0_context_create, rustsecp256k1zkp_v0_8_0_context_preallocated_size, and - * rustsecp256k1zkp_v0_8_0_context_preallocated_create. */ +/** Context flags to pass to rustsecp256k1zkp_v0_10_0_context_create, rustsecp256k1zkp_v0_10_0_context_preallocated_size, and + * rustsecp256k1zkp_v0_10_0_context_preallocated_create. */ +#define SECP256K1_CONTEXT_NONE (SECP256K1_FLAGS_TYPE_CONTEXT) + +/** Deprecated context flags. These flags are treated equivalent to SECP256K1_CONTEXT_NONE. */ #define SECP256K1_CONTEXT_VERIFY (SECP256K1_FLAGS_TYPE_CONTEXT | SECP256K1_FLAGS_BIT_CONTEXT_VERIFY) #define SECP256K1_CONTEXT_SIGN (SECP256K1_FLAGS_TYPE_CONTEXT | SECP256K1_FLAGS_BIT_CONTEXT_SIGN) + +/* Testing flag. Do not use. */ #define SECP256K1_CONTEXT_DECLASSIFY (SECP256K1_FLAGS_TYPE_CONTEXT | SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY) -#define SECP256K1_CONTEXT_NONE (SECP256K1_FLAGS_TYPE_CONTEXT) -/** Flag to pass to rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize. */ +/** Flag to pass to rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize. */ #define SECP256K1_EC_COMPRESSED (SECP256K1_FLAGS_TYPE_COMPRESSION | SECP256K1_FLAGS_BIT_COMPRESSION) #define SECP256K1_EC_UNCOMPRESSED (SECP256K1_FLAGS_TYPE_COMPRESSION) @@ -208,48 +222,40 @@ typedef int (*rustsecp256k1zkp_v0_8_0_nonce_function)( #define SECP256K1_TAG_PUBKEY_HYBRID_EVEN 0x06 #define SECP256K1_TAG_PUBKEY_HYBRID_ODD 0x07 -/** A simple secp256k1 context object with no precomputed tables. These are useful for - * type serialization/parsing functions which require a context object to maintain - * API consistency, but currently do not require expensive precomputations or dynamic - * allocations. - */ -SECP256K1_API extern const rustsecp256k1zkp_v0_8_0_context *rustsecp256k1zkp_v0_8_0_context_no_precomp; - -/** Create a secp256k1 context object (in dynamically allocated memory). +/** A built-in constant secp256k1 context object with static storage duration, to be + * used in conjunction with rustsecp256k1zkp_v0_10_0_selftest. * - * This function uses malloc to allocate memory. It is guaranteed that malloc is - * called at most once for every call of this function. If you need to avoid dynamic - * memory allocation entirely, see the functions in rustsecp256k1zkp_v0_8_0_preallocated.h. + * This context object offers *only limited functionality* , i.e., it cannot be used + * for API functions that perform computations involving secret keys, e.g., signing + * and public key generation. If this restriction applies to a specific API function, + * it is mentioned in its documentation. See rustsecp256k1zkp_v0_10_0_context_create if you need a + * full context object that supports all functionality offered by the library. * - * Returns: a newly created context object. - * In: flags: which parts of the context to initialize. - * - * See also rustsecp256k1zkp_v0_8_0_context_randomize. + * It is highly recommended to call rustsecp256k1zkp_v0_10_0_selftest before using this context. */ +SECP256K1_API const rustsecp256k1zkp_v0_10_0_context *rustsecp256k1zkp_v0_10_0_context_static; -/** Copy a secp256k1 context object (into dynamically allocated memory). - * - * This function uses malloc to allocate memory. It is guaranteed that malloc is - * called at most once for every call of this function. If you need to avoid dynamic - * memory allocation entirely, see the functions in rustsecp256k1zkp_v0_8_0_preallocated.h. - * - * Returns: a newly created context object. - * Args: ctx: an existing context to copy - */ +/** Deprecated alias for rustsecp256k1zkp_v0_10_0_context_static. */ +SECP256K1_API const rustsecp256k1zkp_v0_10_0_context *rustsecp256k1zkp_v0_10_0_context_no_precomp +SECP256K1_DEPRECATED("Use rustsecp256k1zkp_v0_10_0_context_static instead"); -/** Destroy a secp256k1 context object (created in dynamically allocated memory). +/** Perform basic self tests (to be used in conjunction with rustsecp256k1zkp_v0_10_0_context_static) * - * The context pointer may not be used afterwards. + * This function performs self tests that detect some serious usage errors and + * similar conditions, e.g., when the library is compiled for the wrong endianness. + * This is a last resort measure to be used in production. The performed tests are + * very rudimentary and are not intended as a replacement for running the test + * binaries. * - * The context to destroy must have been created using rustsecp256k1zkp_v0_8_0_context_create - * or rustsecp256k1zkp_v0_8_0_context_clone. If the context has instead been created using - * rustsecp256k1zkp_v0_8_0_context_preallocated_create or rustsecp256k1zkp_v0_8_0_context_preallocated_clone, the - * behaviour is undefined. In that case, rustsecp256k1zkp_v0_8_0_context_preallocated_destroy must - * be used instead. + * It is highly recommended to call this before using rustsecp256k1zkp_v0_10_0_context_static. + * It is not necessary to call this function before using a context created with + * rustsecp256k1zkp_v0_10_0_context_create (or rustsecp256k1zkp_v0_10_0_context_preallocated_create), which will + * take care of performing the self tests. * - * Args: ctx: an existing context to destroy, constructed using - * rustsecp256k1zkp_v0_8_0_context_create or rustsecp256k1zkp_v0_8_0_context_clone + * If the tests fail, this function will call the default error handler to abort the + * program (see rustsecp256k1zkp_v0_10_0_context_set_error_callback). */ +SECP256K1_API void rustsecp256k1zkp_v0_10_0_selftest(void); /** Set a callback function to be called when an illegal argument is passed to * an API call. It will only trigger for violations that are mentioned @@ -272,73 +278,61 @@ SECP256K1_API extern const rustsecp256k1zkp_v0_8_0_context *rustsecp256k1zkp_v0_ * USE_EXTERNAL_DEFAULT_CALLBACKS is defined, which is the case if the build * has been configured with --enable-external-default-callbacks. Then the * following two symbols must be provided to link against: - * - void rustsecp256k1zkp_v0_8_0_default_illegal_callback_fn(const char* message, void* data); - * - void rustsecp256k1zkp_v0_8_0_default_error_callback_fn(const char* message, void* data); + * - void rustsecp256k1zkp_v0_10_0_default_illegal_callback_fn(const char *message, void *data); + * - void rustsecp256k1zkp_v0_10_0_default_error_callback_fn(const char *message, void *data); * The library can call these default handlers even before a proper callback data - * pointer could have been set using rustsecp256k1zkp_v0_8_0_context_set_illegal_callback or - * rustsecp256k1zkp_v0_8_0_context_set_error_callback, e.g., when the creation of a context + * pointer could have been set using rustsecp256k1zkp_v0_10_0_context_set_illegal_callback or + * rustsecp256k1zkp_v0_10_0_context_set_error_callback, e.g., when the creation of a context * fails. In this case, the corresponding default handler will be called with * the data pointer argument set to NULL. * - * Args: ctx: an existing context object. - * In: fun: a pointer to a function to call when an illegal argument is + * Args: ctx: pointer to a context object. + * In: fun: pointer to a function to call when an illegal argument is * passed to the API, taking a message and an opaque pointer. * (NULL restores the default handler.) * data: the opaque pointer to pass to fun above, must be NULL for the default handler. * - * See also rustsecp256k1zkp_v0_8_0_context_set_error_callback. + * See also rustsecp256k1zkp_v0_10_0_context_set_error_callback. */ -SECP256K1_API void rustsecp256k1zkp_v0_8_0_context_set_illegal_callback( - rustsecp256k1zkp_v0_8_0_context* ctx, - void (*fun)(const char* message, void* data), - const void* data +SECP256K1_API void rustsecp256k1zkp_v0_10_0_context_set_illegal_callback( + rustsecp256k1zkp_v0_10_0_context *ctx, + void (*fun)(const char *message, void *data), + const void *data ) SECP256K1_ARG_NONNULL(1); /** Set a callback function to be called when an internal consistency check - * fails. The default is crashing. + * fails. + * + * The default callback writes an error message to stderr and calls abort + * to abort the program. * * This can only trigger in case of a hardware failure, miscompilation, * memory corruption, serious bug in the library, or other error would can * otherwise result in undefined behaviour. It will not trigger due to mere - * incorrect usage of the API (see rustsecp256k1zkp_v0_8_0_context_set_illegal_callback + * incorrect usage of the API (see rustsecp256k1zkp_v0_10_0_context_set_illegal_callback * for that). After this callback returns, anything may happen, including * crashing. * - * Args: ctx: an existing context object. - * In: fun: a pointer to a function to call when an internal error occurs, + * Args: ctx: pointer to a context object. + * In: fun: pointer to a function to call when an internal error occurs, * taking a message and an opaque pointer (NULL restores the - * default handler, see rustsecp256k1zkp_v0_8_0_context_set_illegal_callback + * default handler, see rustsecp256k1zkp_v0_10_0_context_set_illegal_callback * for details). * data: the opaque pointer to pass to fun above, must be NULL for the default handler. * - * See also rustsecp256k1zkp_v0_8_0_context_set_illegal_callback. + * See also rustsecp256k1zkp_v0_10_0_context_set_illegal_callback. */ -SECP256K1_API void rustsecp256k1zkp_v0_8_0_context_set_error_callback( - rustsecp256k1zkp_v0_8_0_context* ctx, - void (*fun)(const char* message, void* data), - const void* data +SECP256K1_API void rustsecp256k1zkp_v0_10_0_context_set_error_callback( + rustsecp256k1zkp_v0_10_0_context *ctx, + void (*fun)(const char *message, void *data), + const void *data ) SECP256K1_ARG_NONNULL(1); -/** Create a secp256k1 scratch space object. - * - * Returns: a newly created scratch space. - * Args: ctx: an existing context object. - * In: size: amount of memory to be available as scratch space. Some extra - * (<100 bytes) will be allocated for extra accounting. - */ - -/** Destroy a secp256k1 scratch space. - * - * The pointer may not be used afterwards. - * Args: ctx: a secp256k1 context object. - * scratch: space to destroy - */ - /** Parse a variable-length public key into the pubkey object. * * Returns: 1 if the public key was fully valid. * 0 if the public key could not be parsed or is invalid. - * Args: ctx: a secp256k1 context object. + * Args: ctx: pointer to a context object. * Out: pubkey: pointer to a pubkey object. If 1 is returned, it is set to a * parsed version of input. If not, its value is undefined. * In: input: pointer to a serialized public key @@ -348,9 +342,9 @@ SECP256K1_API void rustsecp256k1zkp_v0_8_0_context_set_error_callback( * 0x03), uncompressed (65 bytes, header byte 0x04), or hybrid (65 bytes, header * byte 0x06 or 0x07) format public keys. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_pubkey_parse( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_pubkey* pubkey, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ec_pubkey_parse( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_pubkey *pubkey, const unsigned char *input, size_t inputlen ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); @@ -358,23 +352,23 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_pubkey /** Serialize a pubkey object into a serialized byte sequence. * * Returns: 1 always. - * Args: ctx: a secp256k1 context object. - * Out: output: a pointer to a 65-byte (if compressed==0) or 33-byte (if + * Args: ctx: pointer to a context object. + * Out: output: pointer to a 65-byte (if compressed==0) or 33-byte (if * compressed==1) byte array to place the serialized key * in. - * In/Out: outputlen: a pointer to an integer which is initially set to the + * In/Out: outputlen: pointer to an integer which is initially set to the * size of output, and is overwritten with the written * size. - * In: pubkey: a pointer to a rustsecp256k1zkp_v0_8_0_pubkey containing an + * In: pubkey: pointer to a rustsecp256k1zkp_v0_10_0_pubkey containing an * initialized public key. * flags: SECP256K1_EC_COMPRESSED if serialization should be in * compressed format, otherwise SECP256K1_EC_UNCOMPRESSED. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *output, size_t *outputlen, - const rustsecp256k1zkp_v0_8_0_pubkey* pubkey, + const rustsecp256k1zkp_v0_10_0_pubkey *pubkey, unsigned int flags ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); @@ -383,55 +377,55 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize( * Returns: <0 if the first public key is less than the second * >0 if the first public key is greater than the second * 0 if the two public keys are equal - * Args: ctx: a secp256k1 context object. + * Args: ctx: pointer to a context object * In: pubkey1: first public key to compare * pubkey2: second public key to compare */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_pubkey_cmp( - const rustsecp256k1zkp_v0_8_0_context* ctx, - const rustsecp256k1zkp_v0_8_0_pubkey* pubkey1, - const rustsecp256k1zkp_v0_8_0_pubkey* pubkey2 +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ec_pubkey_cmp( + const rustsecp256k1zkp_v0_10_0_context *ctx, + const rustsecp256k1zkp_v0_10_0_pubkey *pubkey1, + const rustsecp256k1zkp_v0_10_0_pubkey *pubkey2 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Parse an ECDSA signature in compact (64 bytes) format. * * Returns: 1 when the signature could be parsed, 0 otherwise. - * Args: ctx: a secp256k1 context object - * Out: sig: a pointer to a signature object - * In: input64: a pointer to the 64-byte array to parse + * Args: ctx: pointer to a context object + * Out: sig: pointer to a signature object + * In: input64: pointer to the 64-byte array to parse * * The signature must consist of a 32-byte big endian R value, followed by a * 32-byte big endian S value. If R or S fall outside of [0..order-1], the * encoding is invalid. R and S with value 0 are allowed in the encoding. * * After the call, sig will always be initialized. If parsing failed or R or - * S are zero, the resulting sig value is guaranteed to fail validation for any - * message and public key. + * S are zero, the resulting sig value is guaranteed to fail verification for + * any message and public key. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_compact( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_compact( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_ecdsa_signature *sig, const unsigned char *input64 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Parse a DER ECDSA signature. * * Returns: 1 when the signature could be parsed, 0 otherwise. - * Args: ctx: a secp256k1 context object - * Out: sig: a pointer to a signature object - * In: input: a pointer to the signature to be parsed + * Args: ctx: pointer to a context object + * Out: sig: pointer to a signature object + * In: input: pointer to the signature to be parsed * inputlen: the length of the array pointed to be input * * This function will accept any valid DER encoded signature, even if the * encoded numbers are out of range. * * After the call, sig will always be initialized. If parsing failed or the - * encoded numbers are out of range, signature validation with it is + * encoded numbers are out of range, signature verification with it is * guaranteed to fail for every message and public key. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_ecdsa_signature *sig, const unsigned char *input, size_t inputlen ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); @@ -439,41 +433,41 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der( /** Serialize an ECDSA signature in DER format. * * Returns: 1 if enough space was available to serialize, 0 otherwise - * Args: ctx: a secp256k1 context object - * Out: output: a pointer to an array to store the DER serialization - * In/Out: outputlen: a pointer to a length integer. Initially, this integer + * Args: ctx: pointer to a context object + * Out: output: pointer to an array to store the DER serialization + * In/Out: outputlen: pointer to a length integer. Initially, this integer * should be set to the length of output. After the call * it will be set to the length of the serialization (even * if 0 was returned). - * In: sig: a pointer to an initialized signature object + * In: sig: pointer to an initialized signature object */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_der( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_der( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *output, size_t *outputlen, - const rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig + const rustsecp256k1zkp_v0_10_0_ecdsa_signature *sig ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); /** Serialize an ECDSA signature in compact (64 byte) format. * * Returns: 1 - * Args: ctx: a secp256k1 context object - * Out: output64: a pointer to a 64-byte array to store the compact serialization - * In: sig: a pointer to an initialized signature object + * Args: ctx: pointer to a context object + * Out: output64: pointer to a 64-byte array to store the compact serialization + * In: sig: pointer to an initialized signature object * - * See rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_compact for details about the encoding. + * See rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_compact for details about the encoding. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_compact( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_compact( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *output64, - const rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig + const rustsecp256k1zkp_v0_10_0_ecdsa_signature *sig ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Verify an ECDSA signature. * * Returns: 1: correct signature * 0: incorrect or unparseable signature - * Args: ctx: a secp256k1 context object, initialized for verification. + * Args: ctx: pointer to a context object * In: sig: the signature being verified. * msghash32: the 32-byte message hash being verified. * The verifier must make sure to apply a cryptographic @@ -489,27 +483,27 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_compact( * form are accepted. * * If you need to accept ECDSA signatures from sources that do not obey this - * rule, apply rustsecp256k1zkp_v0_8_0_ecdsa_signature_normalize to the signature prior to - * validation, but be aware that doing so results in malleable signatures. + * rule, apply rustsecp256k1zkp_v0_10_0_ecdsa_signature_normalize to the signature prior to + * verification, but be aware that doing so results in malleable signatures. * * For details, see the comments for that function. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ecdsa_verify( - const rustsecp256k1zkp_v0_8_0_context* ctx, - const rustsecp256k1zkp_v0_8_0_ecdsa_signature *sig, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ecdsa_verify( + const rustsecp256k1zkp_v0_10_0_context *ctx, + const rustsecp256k1zkp_v0_10_0_ecdsa_signature *sig, const unsigned char *msghash32, - const rustsecp256k1zkp_v0_8_0_pubkey *pubkey + const rustsecp256k1zkp_v0_10_0_pubkey *pubkey ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); /** Convert a signature to a normalized lower-S form. * * Returns: 1 if sigin was not normalized, 0 if it already was. - * Args: ctx: a secp256k1 context object - * Out: sigout: a pointer to a signature to fill with the normalized form, + * Args: ctx: pointer to a context object + * Out: sigout: pointer to a signature to fill with the normalized form, * or copy if the input was already normalized. (can be NULL if * you're only interested in whether the input was already * normalized). - * In: sigin: a pointer to a signature to check/normalize (can be identical to sigout) + * In: sigin: pointer to a signature to check/normalize (can be identical to sigout) * * With ECDSA a third-party can forge a second distinct signature of the same * message, given a single initial signature, but without knowing the key. This @@ -537,50 +531,50 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ecdsa_ver * accept various non-unique encodings, so care should be taken when this * property is required for an application. * - * The rustsecp256k1zkp_v0_8_0_ecdsa_sign function will by default create signatures in the - * lower-S form, and rustsecp256k1zkp_v0_8_0_ecdsa_verify will not accept others. In case + * The rustsecp256k1zkp_v0_10_0_ecdsa_sign function will by default create signatures in the + * lower-S form, and rustsecp256k1zkp_v0_10_0_ecdsa_verify will not accept others. In case * signatures come from a system that cannot enforce this property, - * rustsecp256k1zkp_v0_8_0_ecdsa_signature_normalize must be called before verification. + * rustsecp256k1zkp_v0_10_0_ecdsa_signature_normalize must be called before verification. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_signature_normalize( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_ecdsa_signature *sigout, - const rustsecp256k1zkp_v0_8_0_ecdsa_signature *sigin +SECP256K1_API int rustsecp256k1zkp_v0_10_0_ecdsa_signature_normalize( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_ecdsa_signature *sigout, + const rustsecp256k1zkp_v0_10_0_ecdsa_signature *sigin ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(3); /** An implementation of RFC6979 (using HMAC-SHA256) as nonce generation function. * If a data pointer is passed, it is assumed to be a pointer to 32 bytes of * extra entropy. */ -SECP256K1_API extern const rustsecp256k1zkp_v0_8_0_nonce_function rustsecp256k1zkp_v0_8_0_nonce_function_rfc6979; +SECP256K1_API const rustsecp256k1zkp_v0_10_0_nonce_function rustsecp256k1zkp_v0_10_0_nonce_function_rfc6979; -/** A default safe nonce generation function (currently equal to rustsecp256k1zkp_v0_8_0_nonce_function_rfc6979). */ -SECP256K1_API extern const rustsecp256k1zkp_v0_8_0_nonce_function rustsecp256k1zkp_v0_8_0_nonce_function_default; +/** A default safe nonce generation function (currently equal to rustsecp256k1zkp_v0_10_0_nonce_function_rfc6979). */ +SECP256K1_API const rustsecp256k1zkp_v0_10_0_nonce_function rustsecp256k1zkp_v0_10_0_nonce_function_default; /** Create an ECDSA signature. * * Returns: 1: signature created * 0: the nonce generation function failed, or the secret key was invalid. - * Args: ctx: pointer to a context object, initialized for signing. + * Args: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static). * Out: sig: pointer to an array where the signature will be placed. * In: msghash32: the 32-byte message hash being signed. * seckey: pointer to a 32-byte secret key. * noncefp: pointer to a nonce generation function. If NULL, - * rustsecp256k1zkp_v0_8_0_nonce_function_default is used. + * rustsecp256k1zkp_v0_10_0_nonce_function_default is used. * ndata: pointer to arbitrary data used by the nonce generation function * (can be NULL). If it is non-NULL and - * rustsecp256k1zkp_v0_8_0_nonce_function_default is used, then ndata must be a + * rustsecp256k1zkp_v0_10_0_nonce_function_default is used, then ndata must be a * pointer to 32-bytes of additional data. * * The created signature is always in lower-S form. See - * rustsecp256k1zkp_v0_8_0_ecdsa_signature_normalize for more details. + * rustsecp256k1zkp_v0_10_0_ecdsa_signature_normalize for more details. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_sign( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_ecdsa_signature *sig, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_ecdsa_sign( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_ecdsa_signature *sig, const unsigned char *msghash32, const unsigned char *seckey, - rustsecp256k1zkp_v0_8_0_nonce_function noncefp, + rustsecp256k1zkp_v0_10_0_nonce_function noncefp, const void *ndata ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); @@ -596,8 +590,8 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_sign( * Args: ctx: pointer to a context object. * In: seckey: pointer to a 32-byte secret key. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_seckey_verify( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ec_seckey_verify( + const rustsecp256k1zkp_v0_10_0_context *ctx, const unsigned char *seckey ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2); @@ -605,38 +599,38 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_seckey * * Returns: 1: secret was valid, public key stores. * 0: secret was invalid, try again. - * Args: ctx: pointer to a context object, initialized for signing. + * Args: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static). * Out: pubkey: pointer to the created public key. * In: seckey: pointer to a 32-byte secret key. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_pubkey_create( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_pubkey *pubkey, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ec_pubkey_create( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_pubkey *pubkey, const unsigned char *seckey ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Negates a secret key in place. * * Returns: 0 if the given secret key is invalid according to - * rustsecp256k1zkp_v0_8_0_ec_seckey_verify. 1 otherwise + * rustsecp256k1zkp_v0_10_0_ec_seckey_verify. 1 otherwise * Args: ctx: pointer to a context object * In/Out: seckey: pointer to the 32-byte secret key to be negated. If the * secret key is invalid according to - * rustsecp256k1zkp_v0_8_0_ec_seckey_verify, this function returns 0 and + * rustsecp256k1zkp_v0_10_0_ec_seckey_verify, this function returns 0 and * seckey will be set to some unspecified value. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_seckey_negate( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ec_seckey_negate( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *seckey ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2); -/** Same as rustsecp256k1zkp_v0_8_0_ec_seckey_negate, but DEPRECATED. Will be removed in +/** Same as rustsecp256k1zkp_v0_10_0_ec_seckey_negate, but DEPRECATED. Will be removed in * future versions. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_privkey_negate( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ec_privkey_negate( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *seckey ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) - SECP256K1_DEPRECATED("Use rustsecp256k1zkp_v0_8_0_ec_seckey_negate instead"); + SECP256K1_DEPRECATED("Use rustsecp256k1zkp_v0_10_0_ec_seckey_negate instead"); /** Negates a public key in place. * @@ -644,9 +638,9 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_privke * Args: ctx: pointer to a context object * In/Out: pubkey: pointer to the public key to be negated. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_pubkey_negate( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_pubkey *pubkey +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ec_pubkey_negate( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_pubkey *pubkey ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2); /** Tweak a secret key by adding tweak to it. @@ -656,45 +650,45 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_pubkey * otherwise. * Args: ctx: pointer to a context object. * In/Out: seckey: pointer to a 32-byte secret key. If the secret key is - * invalid according to rustsecp256k1zkp_v0_8_0_ec_seckey_verify, this + * invalid according to rustsecp256k1zkp_v0_10_0_ec_seckey_verify, this * function returns 0. seckey will be set to some unspecified * value if this function returns 0. - * In: tweak32: pointer to a 32-byte tweak. If the tweak is invalid according to - * rustsecp256k1zkp_v0_8_0_ec_seckey_verify, this function returns 0. For - * uniformly random 32-byte arrays the chance of being invalid - * is negligible (around 1 in 2^128). + * In: tweak32: pointer to a 32-byte tweak, which must be valid according to + * rustsecp256k1zkp_v0_10_0_ec_seckey_verify or 32 zero bytes. For uniformly + * random 32-byte tweaks, the chance of being invalid is + * negligible (around 1 in 2^128). */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *seckey, const unsigned char *tweak32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); -/** Same as rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add, but DEPRECATED. Will be removed in +/** Same as rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add, but DEPRECATED. Will be removed in * future versions. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_privkey_tweak_add( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ec_privkey_tweak_add( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *seckey, const unsigned char *tweak32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) - SECP256K1_DEPRECATED("Use rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add instead"); + SECP256K1_DEPRECATED("Use rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add instead"); /** Tweak a public key by adding tweak times the generator to it. * * Returns: 0 if the arguments are invalid or the resulting public key would be * invalid (only when the tweak is the negation of the corresponding * secret key). 1 otherwise. - * Args: ctx: pointer to a context object initialized for validation. + * Args: ctx: pointer to a context object. * In/Out: pubkey: pointer to a public key object. pubkey will be set to an * invalid value if this function returns 0. - * In: tweak32: pointer to a 32-byte tweak. If the tweak is invalid according to - * rustsecp256k1zkp_v0_8_0_ec_seckey_verify, this function returns 0. For - * uniformly random 32-byte arrays the chance of being invalid - * is negligible (around 1 in 2^128). - */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_pubkey *pubkey, + * In: tweak32: pointer to a 32-byte tweak, which must be valid according to + * rustsecp256k1zkp_v0_10_0_ec_seckey_verify or 32 zero bytes. For uniformly + * random 32-byte tweaks, the chance of being invalid is + * negligible (around 1 in 2^128). + */ +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_pubkey *pubkey, const unsigned char *tweak32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); @@ -703,73 +697,80 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_pubkey * Returns: 0 if the arguments are invalid. 1 otherwise. * Args: ctx: pointer to a context object. * In/Out: seckey: pointer to a 32-byte secret key. If the secret key is - * invalid according to rustsecp256k1zkp_v0_8_0_ec_seckey_verify, this + * invalid according to rustsecp256k1zkp_v0_10_0_ec_seckey_verify, this * function returns 0. seckey will be set to some unspecified * value if this function returns 0. * In: tweak32: pointer to a 32-byte tweak. If the tweak is invalid according to - * rustsecp256k1zkp_v0_8_0_ec_seckey_verify, this function returns 0. For + * rustsecp256k1zkp_v0_10_0_ec_seckey_verify, this function returns 0. For * uniformly random 32-byte arrays the chance of being invalid * is negligible (around 1 in 2^128). */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_mul( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_mul( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *seckey, const unsigned char *tweak32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); -/** Same as rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_mul, but DEPRECATED. Will be removed in +/** Same as rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_mul, but DEPRECATED. Will be removed in * future versions. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_privkey_tweak_mul( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ec_privkey_tweak_mul( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *seckey, const unsigned char *tweak32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) - SECP256K1_DEPRECATED("Use rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_mul instead"); + SECP256K1_DEPRECATED("Use rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_mul instead"); /** Tweak a public key by multiplying it by a tweak value. * * Returns: 0 if the arguments are invalid. 1 otherwise. - * Args: ctx: pointer to a context object initialized for validation. + * Args: ctx: pointer to a context object. * In/Out: pubkey: pointer to a public key object. pubkey will be set to an * invalid value if this function returns 0. * In: tweak32: pointer to a 32-byte tweak. If the tweak is invalid according to - * rustsecp256k1zkp_v0_8_0_ec_seckey_verify, this function returns 0. For + * rustsecp256k1zkp_v0_10_0_ec_seckey_verify, this function returns 0. For * uniformly random 32-byte arrays the chance of being invalid * is negligible (around 1 in 2^128). */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_mul( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_pubkey *pubkey, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_mul( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_pubkey *pubkey, const unsigned char *tweak32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); -/** Updates the context randomization to protect against side-channel leakage. - * Returns: 1: randomization successfully updated or nothing to randomize +/** Randomizes the context to provide enhanced protection against side-channel leakage. + * + * Returns: 1: randomization successful * 0: error - * Args: ctx: pointer to a context object. - * In: seed32: pointer to a 32-byte random seed (NULL resets to initial state) + * Args: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static). + * In: seed32: pointer to a 32-byte random seed (NULL resets to initial state). * - * While secp256k1 code is written to be constant-time no matter what secret - * values are, it's possible that a future compiler may output code which isn't, + * While secp256k1 code is written and tested to be constant-time no matter what + * secret values are, it is possible that a compiler may output code which is not, * and also that the CPU may not emit the same radio frequencies or draw the same - * amount power for all values. - * - * This function provides a seed which is combined into the blinding value: that - * blinding value is added before each multiplication (and removed afterwards) so - * that it does not affect function results, but shields against attacks which - * rely on any input-dependent behaviour. - * - * This function has currently an effect only on contexts initialized for signing - * because randomization is currently used only for signing. However, this is not - * guaranteed and may change in the future. It is safe to call this function on - * contexts not initialized for signing; then it will have no effect and return 1. - * - * You should call this after rustsecp256k1zkp_v0_8_0_context_create or - * rustsecp256k1zkp_v0_8_0_context_clone (and rustsecp256k1zkp_v0_8_0_context_preallocated_create or - * rustsecp256k1zkp_v0_8_0_context_clone, resp.), and you may call this repeatedly afterwards. - */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_context_randomize( - rustsecp256k1zkp_v0_8_0_context* ctx, + * amount of power for all values. Randomization of the context shields against + * side-channel observations which aim to exploit secret-dependent behaviour in + * certain computations which involve secret keys. + * + * It is highly recommended to call this function on contexts returned from + * rustsecp256k1zkp_v0_10_0_context_create or rustsecp256k1zkp_v0_10_0_context_clone (or from the corresponding + * functions in rustsecp256k1zkp_v0_10_0_preallocated.h) before using these contexts to call API + * functions that perform computations involving secret keys, e.g., signing and + * public key generation. It is possible to call this function more than once on + * the same context, and doing so before every few computations involving secret + * keys is recommended as a defense-in-depth measure. Randomization of the static + * context rustsecp256k1zkp_v0_10_0_context_static is not supported. + * + * Currently, the random seed is mainly used for blinding multiplications of a + * secret scalar with the elliptic curve base point. Multiplications of this + * kind are performed by exactly those API functions which are documented to + * require a context that is not rustsecp256k1zkp_v0_10_0_context_static. As a rule of thumb, + * these are all functions which take a secret key (or a keypair) as an input. + * A notable exception to that rule is the ECDH module, which relies on a different + * kind of elliptic curve point multiplication and thus does not benefit from + * enhanced protection against side-channel leakage currently. + */ +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_context_randomize( + rustsecp256k1zkp_v0_10_0_context *ctx, const unsigned char *seed32 ) SECP256K1_ARG_NONNULL(1); @@ -782,10 +783,10 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_context_r * In: ins: pointer to array of pointers to public keys. * n: the number of public keys to add together (must be at least 1). */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_pubkey_combine( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_pubkey *out, - const rustsecp256k1zkp_v0_8_0_pubkey * const * ins, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ec_pubkey_combine( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_pubkey *out, + const rustsecp256k1zkp_v0_10_0_pubkey * const *ins, size_t n ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); @@ -805,8 +806,8 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_pubkey * msg: pointer to an array containing the message * msglen: length of the message array */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_tagged_sha256( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_tagged_sha256( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *hash32, const unsigned char *tag, size_t taglen, diff --git a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1.h.orig b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1.h.orig deleted file mode 100644 index 09cc839b..00000000 --- a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1.h.orig +++ /dev/null @@ -1,838 +0,0 @@ -#ifndef SECP256K1_H -#define SECP256K1_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -/* Unless explicitly stated all pointer arguments must not be NULL. - * - * The following rules specify the order of arguments in API calls: - * - * 1. Context pointers go first, followed by output arguments, combined - * output/input arguments, and finally input-only arguments. - * 2. Array lengths always immediately follow the argument whose length - * they describe, even if this violates rule 1. - * 3. Within the OUT/OUTIN/IN groups, pointers to data that is typically generated - * later go first. This means: signatures, public nonces, secret nonces, - * messages, public keys, secret keys, tweaks. - * 4. Arguments that are not data pointers go last, from more complex to less - * complex: function pointers, algorithm names, messages, void pointers, - * counts, flags, booleans. - * 5. Opaque data pointers follow the function pointer they are to be passed to. - */ - -/** Opaque data structure that holds context information (precomputed tables etc.). - * - * The purpose of context structures is to cache large precomputed data tables - * that are expensive to construct, and also to maintain the randomization data - * for blinding. - * - * Do not create a new context object for each operation, as construction is - * far slower than all other API calls (~100 times slower than an ECDSA - * verification). - * - * A constructed context can safely be used from multiple threads - * simultaneously, but API calls that take a non-const pointer to a context - * need exclusive access to it. In particular this is the case for - * rustsecp256k1zkp_v0_8_0_context_destroy, rustsecp256k1zkp_v0_8_0_context_preallocated_destroy, - * and rustsecp256k1zkp_v0_8_0_context_randomize. - * - * Regarding randomization, either do it once at creation time (in which case - * you do not need any locking for the other calls), or use a read-write lock. - */ -typedef struct rustsecp256k1zkp_v0_8_0_context_struct rustsecp256k1zkp_v0_8_0_context; - -/** Opaque data structure that holds rewriteable "scratch space" - * - * The purpose of this structure is to replace dynamic memory allocations, - * because we target architectures where this may not be available. It is - * essentially a resizable (within specified parameters) block of bytes, - * which is initially created either by memory allocation or TODO as a pointer - * into some fixed rewritable space. - * - * Unlike the context object, this cannot safely be shared between threads - * without additional synchronization logic. - */ -typedef struct rustsecp256k1zkp_v0_8_0_scratch_space_struct rustsecp256k1zkp_v0_8_0_scratch_space; - -/** Opaque data structure that holds a parsed and valid public key. - * - * The exact representation of data inside is implementation defined and not - * guaranteed to be portable between different platforms or versions. It is - * however guaranteed to be 64 bytes in size, and can be safely copied/moved. - * If you need to convert to a format suitable for storage or transmission, - * use rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize and rustsecp256k1zkp_v0_8_0_ec_pubkey_parse. To - * compare keys, use rustsecp256k1zkp_v0_8_0_ec_pubkey_cmp. - */ -typedef struct { - unsigned char data[64]; -} rustsecp256k1zkp_v0_8_0_pubkey; - -/** Opaque data structured that holds a parsed ECDSA signature. - * - * The exact representation of data inside is implementation defined and not - * guaranteed to be portable between different platforms or versions. It is - * however guaranteed to be 64 bytes in size, and can be safely copied/moved. - * If you need to convert to a format suitable for storage, transmission, or - * comparison, use the rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_* and - * rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_* functions. - */ -typedef struct { - unsigned char data[64]; -} rustsecp256k1zkp_v0_8_0_ecdsa_signature; - -/** A pointer to a function to deterministically generate a nonce. - * - * Returns: 1 if a nonce was successfully generated. 0 will cause signing to fail. - * Out: nonce32: pointer to a 32-byte array to be filled by the function. - * In: msg32: the 32-byte message hash being verified (will not be NULL) - * key32: pointer to a 32-byte secret key (will not be NULL) - * algo16: pointer to a 16-byte array describing the signature - * algorithm (will be NULL for ECDSA for compatibility). - * data: Arbitrary data pointer that is passed through. - * attempt: how many iterations we have tried to find a nonce. - * This will almost always be 0, but different attempt values - * are required to result in a different nonce. - * - * Except for test cases, this function should compute some cryptographic hash of - * the message, the algorithm, the key and the attempt. - */ -typedef int (*rustsecp256k1zkp_v0_8_0_nonce_function)( - unsigned char *nonce32, - const unsigned char *msg32, - const unsigned char *key32, - const unsigned char *algo16, - void *data, - unsigned int attempt -); - -# if !defined(SECP256K1_GNUC_PREREQ) -# if defined(__GNUC__)&&defined(__GNUC_MINOR__) -# define SECP256K1_GNUC_PREREQ(_maj,_min) \ - ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min)) -# else -# define SECP256K1_GNUC_PREREQ(_maj,_min) 0 -# endif -# endif - -# if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) ) -# if SECP256K1_GNUC_PREREQ(2,7) -# define SECP256K1_INLINE __inline__ -# elif (defined(_MSC_VER)) -# define SECP256K1_INLINE __inline -# else -# define SECP256K1_INLINE -# endif -# else -# define SECP256K1_INLINE inline -# endif - -/** When this header is used at build-time the SECP256K1_BUILD define needs to be set - * to correctly setup export attributes and nullness checks. This is normally done - * by secp256k1.c but to guard against this header being included before secp256k1.c - * has had a chance to set the define (e.g. via test harnesses that just includes - * secp256k1.c) we set SECP256K1_NO_BUILD when this header is processed without the - * BUILD define so this condition can be caught. - */ -#ifndef SECP256K1_BUILD -# define SECP256K1_NO_BUILD -#endif - -#ifndef SECP256K1_API -# if defined(_WIN32) -# ifdef SECP256K1_BUILD -# define SECP256K1_API __declspec(dllexport) -# else -# define SECP256K1_API -# endif -# elif defined(__GNUC__) && (__GNUC__ >= 4) && defined(SECP256K1_BUILD) -# define SECP256K1_API __attribute__ ((visibility ("default"))) -# else -# define SECP256K1_API -# endif -#endif - -/**Warning attributes - * NONNULL is not used if SECP256K1_BUILD is set to avoid the compiler optimizing out - * some paranoid null checks. */ -# if defined(__GNUC__) && SECP256K1_GNUC_PREREQ(3, 4) -# define SECP256K1_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__)) -# else -# define SECP256K1_WARN_UNUSED_RESULT -# endif -# if !defined(SECP256K1_BUILD) && defined(__GNUC__) && SECP256K1_GNUC_PREREQ(3, 4) -# define SECP256K1_ARG_NONNULL(_x) __attribute__ ((__nonnull__(_x))) -# else -# define SECP256K1_ARG_NONNULL(_x) -# endif - -/** Attribute for marking functions, types, and variables as deprecated */ -#if !defined(SECP256K1_BUILD) && defined(__has_attribute) -# if __has_attribute(__deprecated__) -# define SECP256K1_DEPRECATED(_msg) __attribute__ ((__deprecated__(_msg))) -# else -# define SECP256K1_DEPRECATED(_msg) -# endif -#else -# define SECP256K1_DEPRECATED(_msg) -#endif - -/** All flags' lower 8 bits indicate what they're for. Do not use directly. */ -#define SECP256K1_FLAGS_TYPE_MASK ((1 << 8) - 1) -#define SECP256K1_FLAGS_TYPE_CONTEXT (1 << 0) -#define SECP256K1_FLAGS_TYPE_COMPRESSION (1 << 1) -/** The higher bits contain the actual data. Do not use directly. */ -#define SECP256K1_FLAGS_BIT_CONTEXT_VERIFY (1 << 8) -#define SECP256K1_FLAGS_BIT_CONTEXT_SIGN (1 << 9) -#define SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY (1 << 10) -#define SECP256K1_FLAGS_BIT_COMPRESSION (1 << 8) - -/** Flags to pass to rustsecp256k1zkp_v0_8_0_context_create, rustsecp256k1zkp_v0_8_0_context_preallocated_size, and - * rustsecp256k1zkp_v0_8_0_context_preallocated_create. */ -#define SECP256K1_CONTEXT_VERIFY (SECP256K1_FLAGS_TYPE_CONTEXT | SECP256K1_FLAGS_BIT_CONTEXT_VERIFY) -#define SECP256K1_CONTEXT_SIGN (SECP256K1_FLAGS_TYPE_CONTEXT | SECP256K1_FLAGS_BIT_CONTEXT_SIGN) -#define SECP256K1_CONTEXT_DECLASSIFY (SECP256K1_FLAGS_TYPE_CONTEXT | SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY) -#define SECP256K1_CONTEXT_NONE (SECP256K1_FLAGS_TYPE_CONTEXT) - -/** Flag to pass to rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize. */ -#define SECP256K1_EC_COMPRESSED (SECP256K1_FLAGS_TYPE_COMPRESSION | SECP256K1_FLAGS_BIT_COMPRESSION) -#define SECP256K1_EC_UNCOMPRESSED (SECP256K1_FLAGS_TYPE_COMPRESSION) - -/** Prefix byte used to tag various encoded curvepoints for specific purposes */ -#define SECP256K1_TAG_PUBKEY_EVEN 0x02 -#define SECP256K1_TAG_PUBKEY_ODD 0x03 -#define SECP256K1_TAG_PUBKEY_UNCOMPRESSED 0x04 -#define SECP256K1_TAG_PUBKEY_HYBRID_EVEN 0x06 -#define SECP256K1_TAG_PUBKEY_HYBRID_ODD 0x07 - -/** A simple secp256k1 context object with no precomputed tables. These are useful for - * type serialization/parsing functions which require a context object to maintain - * API consistency, but currently do not require expensive precomputations or dynamic - * allocations. - */ -SECP256K1_API extern const rustsecp256k1zkp_v0_8_0_context *rustsecp256k1zkp_v0_8_0_context_no_precomp; - -/** Create a secp256k1 context object (in dynamically allocated memory). - * - * This function uses malloc to allocate memory. It is guaranteed that malloc is - * called at most once for every call of this function. If you need to avoid dynamic - * memory allocation entirely, see the functions in rustsecp256k1zkp_v0_8_0_preallocated.h. - * - * Returns: a newly created context object. - * In: flags: which parts of the context to initialize. - * - * See also rustsecp256k1zkp_v0_8_0_context_randomize. - */ -SECP256K1_API rustsecp256k1zkp_v0_8_0_context* rustsecp256k1zkp_v0_8_0_context_create( - unsigned int flags -) SECP256K1_WARN_UNUSED_RESULT; - -/** Copy a secp256k1 context object (into dynamically allocated memory). - * - * This function uses malloc to allocate memory. It is guaranteed that malloc is - * called at most once for every call of this function. If you need to avoid dynamic - * memory allocation entirely, see the functions in rustsecp256k1zkp_v0_8_0_preallocated.h. - * - * Returns: a newly created context object. - * Args: ctx: an existing context to copy - */ -SECP256K1_API rustsecp256k1zkp_v0_8_0_context* rustsecp256k1zkp_v0_8_0_context_clone( - const rustsecp256k1zkp_v0_8_0_context* ctx -) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT; - -/** Destroy a secp256k1 context object (created in dynamically allocated memory). - * - * The context pointer may not be used afterwards. - * - * The context to destroy must have been created using rustsecp256k1zkp_v0_8_0_context_create - * or rustsecp256k1zkp_v0_8_0_context_clone. If the context has instead been created using - * rustsecp256k1zkp_v0_8_0_context_preallocated_create or rustsecp256k1zkp_v0_8_0_context_preallocated_clone, the - * behaviour is undefined. In that case, rustsecp256k1zkp_v0_8_0_context_preallocated_destroy must - * be used instead. - * - * Args: ctx: an existing context to destroy, constructed using - * rustsecp256k1zkp_v0_8_0_context_create or rustsecp256k1zkp_v0_8_0_context_clone - */ -SECP256K1_API void rustsecp256k1zkp_v0_8_0_context_destroy( - rustsecp256k1zkp_v0_8_0_context* ctx -) SECP256K1_ARG_NONNULL(1); - -/** Set a callback function to be called when an illegal argument is passed to - * an API call. It will only trigger for violations that are mentioned - * explicitly in the header. - * - * The philosophy is that these shouldn't be dealt with through a - * specific return value, as calling code should not have branches to deal with - * the case that this code itself is broken. - * - * On the other hand, during debug stage, one would want to be informed about - * such mistakes, and the default (crashing) may be inadvisable. - * When this callback is triggered, the API function called is guaranteed not - * to cause a crash, though its return value and output arguments are - * undefined. - * - * When this function has not been called (or called with fn==NULL), then the - * default handler will be used. The library provides a default handler which - * writes the message to stderr and calls abort. This default handler can be - * replaced at link time if the preprocessor macro - * USE_EXTERNAL_DEFAULT_CALLBACKS is defined, which is the case if the build - * has been configured with --enable-external-default-callbacks. Then the - * following two symbols must be provided to link against: - * - void rustsecp256k1zkp_v0_8_0_default_illegal_callback_fn(const char* message, void* data); - * - void rustsecp256k1zkp_v0_8_0_default_error_callback_fn(const char* message, void* data); - * The library can call these default handlers even before a proper callback data - * pointer could have been set using rustsecp256k1zkp_v0_8_0_context_set_illegal_callback or - * rustsecp256k1zkp_v0_8_0_context_set_error_callback, e.g., when the creation of a context - * fails. In this case, the corresponding default handler will be called with - * the data pointer argument set to NULL. - * - * Args: ctx: an existing context object. - * In: fun: a pointer to a function to call when an illegal argument is - * passed to the API, taking a message and an opaque pointer. - * (NULL restores the default handler.) - * data: the opaque pointer to pass to fun above, must be NULL for the default handler. - * - * See also rustsecp256k1zkp_v0_8_0_context_set_error_callback. - */ -SECP256K1_API void rustsecp256k1zkp_v0_8_0_context_set_illegal_callback( - rustsecp256k1zkp_v0_8_0_context* ctx, - void (*fun)(const char* message, void* data), - const void* data -) SECP256K1_ARG_NONNULL(1); - -/** Set a callback function to be called when an internal consistency check - * fails. The default is crashing. - * - * This can only trigger in case of a hardware failure, miscompilation, - * memory corruption, serious bug in the library, or other error would can - * otherwise result in undefined behaviour. It will not trigger due to mere - * incorrect usage of the API (see rustsecp256k1zkp_v0_8_0_context_set_illegal_callback - * for that). After this callback returns, anything may happen, including - * crashing. - * - * Args: ctx: an existing context object. - * In: fun: a pointer to a function to call when an internal error occurs, - * taking a message and an opaque pointer (NULL restores the - * default handler, see rustsecp256k1zkp_v0_8_0_context_set_illegal_callback - * for details). - * data: the opaque pointer to pass to fun above, must be NULL for the default handler. - * - * See also rustsecp256k1zkp_v0_8_0_context_set_illegal_callback. - */ -SECP256K1_API void rustsecp256k1zkp_v0_8_0_context_set_error_callback( - rustsecp256k1zkp_v0_8_0_context* ctx, - void (*fun)(const char* message, void* data), - const void* data -) SECP256K1_ARG_NONNULL(1); - -/** Create a secp256k1 scratch space object. - * - * Returns: a newly created scratch space. - * Args: ctx: an existing context object. - * In: size: amount of memory to be available as scratch space. Some extra - * (<100 bytes) will be allocated for extra accounting. - */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT rustsecp256k1zkp_v0_8_0_scratch_space* rustsecp256k1zkp_v0_8_0_scratch_space_create( - const rustsecp256k1zkp_v0_8_0_context* ctx, - size_t size -) SECP256K1_ARG_NONNULL(1); - -/** Destroy a secp256k1 scratch space. - * - * The pointer may not be used afterwards. - * Args: ctx: a secp256k1 context object. - * scratch: space to destroy - */ -SECP256K1_API void rustsecp256k1zkp_v0_8_0_scratch_space_destroy( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_scratch_space* scratch -) SECP256K1_ARG_NONNULL(1); - -/** Parse a variable-length public key into the pubkey object. - * - * Returns: 1 if the public key was fully valid. - * 0 if the public key could not be parsed or is invalid. - * Args: ctx: a secp256k1 context object. - * Out: pubkey: pointer to a pubkey object. If 1 is returned, it is set to a - * parsed version of input. If not, its value is undefined. - * In: input: pointer to a serialized public key - * inputlen: length of the array pointed to by input - * - * This function supports parsing compressed (33 bytes, header byte 0x02 or - * 0x03), uncompressed (65 bytes, header byte 0x04), or hybrid (65 bytes, header - * byte 0x06 or 0x07) format public keys. - */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_pubkey_parse( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_pubkey* pubkey, - const unsigned char *input, - size_t inputlen -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); - -/** Serialize a pubkey object into a serialized byte sequence. - * - * Returns: 1 always. - * Args: ctx: a secp256k1 context object. - * Out: output: a pointer to a 65-byte (if compressed==0) or 33-byte (if - * compressed==1) byte array to place the serialized key - * in. - * In/Out: outputlen: a pointer to an integer which is initially set to the - * size of output, and is overwritten with the written - * size. - * In: pubkey: a pointer to a rustsecp256k1zkp_v0_8_0_pubkey containing an - * initialized public key. - * flags: SECP256K1_EC_COMPRESSED if serialization should be in - * compressed format, otherwise SECP256K1_EC_UNCOMPRESSED. - */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize( - const rustsecp256k1zkp_v0_8_0_context* ctx, - unsigned char *output, - size_t *outputlen, - const rustsecp256k1zkp_v0_8_0_pubkey* pubkey, - unsigned int flags -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); - -/** Compare two public keys using lexicographic (of compressed serialization) order - * - * Returns: <0 if the first public key is less than the second - * >0 if the first public key is greater than the second - * 0 if the two public keys are equal - * Args: ctx: a secp256k1 context object. - * In: pubkey1: first public key to compare - * pubkey2: second public key to compare - */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_pubkey_cmp( - const rustsecp256k1zkp_v0_8_0_context* ctx, - const rustsecp256k1zkp_v0_8_0_pubkey* pubkey1, - const rustsecp256k1zkp_v0_8_0_pubkey* pubkey2 -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); - -/** Parse an ECDSA signature in compact (64 bytes) format. - * - * Returns: 1 when the signature could be parsed, 0 otherwise. - * Args: ctx: a secp256k1 context object - * Out: sig: a pointer to a signature object - * In: input64: a pointer to the 64-byte array to parse - * - * The signature must consist of a 32-byte big endian R value, followed by a - * 32-byte big endian S value. If R or S fall outside of [0..order-1], the - * encoding is invalid. R and S with value 0 are allowed in the encoding. - * - * After the call, sig will always be initialized. If parsing failed or R or - * S are zero, the resulting sig value is guaranteed to fail validation for any - * message and public key. - */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_compact( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig, - const unsigned char *input64 -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); - -/** Parse a DER ECDSA signature. - * - * Returns: 1 when the signature could be parsed, 0 otherwise. - * Args: ctx: a secp256k1 context object - * Out: sig: a pointer to a signature object - * In: input: a pointer to the signature to be parsed - * inputlen: the length of the array pointed to be input - * - * This function will accept any valid DER encoded signature, even if the - * encoded numbers are out of range. - * - * After the call, sig will always be initialized. If parsing failed or the - * encoded numbers are out of range, signature validation with it is - * guaranteed to fail for every message and public key. - */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig, - const unsigned char *input, - size_t inputlen -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); - -/** Serialize an ECDSA signature in DER format. - * - * Returns: 1 if enough space was available to serialize, 0 otherwise - * Args: ctx: a secp256k1 context object - * Out: output: a pointer to an array to store the DER serialization - * In/Out: outputlen: a pointer to a length integer. Initially, this integer - * should be set to the length of output. After the call - * it will be set to the length of the serialization (even - * if 0 was returned). - * In: sig: a pointer to an initialized signature object - */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_der( - const rustsecp256k1zkp_v0_8_0_context* ctx, - unsigned char *output, - size_t *outputlen, - const rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); - -/** Serialize an ECDSA signature in compact (64 byte) format. - * - * Returns: 1 - * Args: ctx: a secp256k1 context object - * Out: output64: a pointer to a 64-byte array to store the compact serialization - * In: sig: a pointer to an initialized signature object - * - * See rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_compact for details about the encoding. - */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_compact( - const rustsecp256k1zkp_v0_8_0_context* ctx, - unsigned char *output64, - const rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); - -/** Verify an ECDSA signature. - * - * Returns: 1: correct signature - * 0: incorrect or unparseable signature - * Args: ctx: a secp256k1 context object, initialized for verification. - * In: sig: the signature being verified. - * msghash32: the 32-byte message hash being verified. - * The verifier must make sure to apply a cryptographic - * hash function to the message by itself and not accept an - * msghash32 value directly. Otherwise, it would be easy to - * create a "valid" signature without knowledge of the - * secret key. See also - * https://bitcoin.stackexchange.com/a/81116/35586 for more - * background on this topic. - * pubkey: pointer to an initialized public key to verify with. - * - * To avoid accepting malleable signatures, only ECDSA signatures in lower-S - * form are accepted. - * - * If you need to accept ECDSA signatures from sources that do not obey this - * rule, apply rustsecp256k1zkp_v0_8_0_ecdsa_signature_normalize to the signature prior to - * validation, but be aware that doing so results in malleable signatures. - * - * For details, see the comments for that function. - */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ecdsa_verify( - const rustsecp256k1zkp_v0_8_0_context* ctx, - const rustsecp256k1zkp_v0_8_0_ecdsa_signature *sig, - const unsigned char *msghash32, - const rustsecp256k1zkp_v0_8_0_pubkey *pubkey -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); - -/** Convert a signature to a normalized lower-S form. - * - * Returns: 1 if sigin was not normalized, 0 if it already was. - * Args: ctx: a secp256k1 context object - * Out: sigout: a pointer to a signature to fill with the normalized form, - * or copy if the input was already normalized. (can be NULL if - * you're only interested in whether the input was already - * normalized). - * In: sigin: a pointer to a signature to check/normalize (can be identical to sigout) - * - * With ECDSA a third-party can forge a second distinct signature of the same - * message, given a single initial signature, but without knowing the key. This - * is done by negating the S value modulo the order of the curve, 'flipping' - * the sign of the random point R which is not included in the signature. - * - * Forgery of the same message isn't universally problematic, but in systems - * where message malleability or uniqueness of signatures is important this can - * cause issues. This forgery can be blocked by all verifiers forcing signers - * to use a normalized form. - * - * The lower-S form reduces the size of signatures slightly on average when - * variable length encodings (such as DER) are used and is cheap to verify, - * making it a good choice. Security of always using lower-S is assured because - * anyone can trivially modify a signature after the fact to enforce this - * property anyway. - * - * The lower S value is always between 0x1 and - * 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, - * inclusive. - * - * No other forms of ECDSA malleability are known and none seem likely, but - * there is no formal proof that ECDSA, even with this additional restriction, - * is free of other malleability. Commonly used serialization schemes will also - * accept various non-unique encodings, so care should be taken when this - * property is required for an application. - * - * The rustsecp256k1zkp_v0_8_0_ecdsa_sign function will by default create signatures in the - * lower-S form, and rustsecp256k1zkp_v0_8_0_ecdsa_verify will not accept others. In case - * signatures come from a system that cannot enforce this property, - * rustsecp256k1zkp_v0_8_0_ecdsa_signature_normalize must be called before verification. - */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_signature_normalize( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_ecdsa_signature *sigout, - const rustsecp256k1zkp_v0_8_0_ecdsa_signature *sigin -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(3); - -/** An implementation of RFC6979 (using HMAC-SHA256) as nonce generation function. - * If a data pointer is passed, it is assumed to be a pointer to 32 bytes of - * extra entropy. - */ -SECP256K1_API extern const rustsecp256k1zkp_v0_8_0_nonce_function rustsecp256k1zkp_v0_8_0_nonce_function_rfc6979; - -/** A default safe nonce generation function (currently equal to rustsecp256k1zkp_v0_8_0_nonce_function_rfc6979). */ -SECP256K1_API extern const rustsecp256k1zkp_v0_8_0_nonce_function rustsecp256k1zkp_v0_8_0_nonce_function_default; - -/** Create an ECDSA signature. - * - * Returns: 1: signature created - * 0: the nonce generation function failed, or the secret key was invalid. - * Args: ctx: pointer to a context object, initialized for signing. - * Out: sig: pointer to an array where the signature will be placed. - * In: msghash32: the 32-byte message hash being signed. - * seckey: pointer to a 32-byte secret key. - * noncefp: pointer to a nonce generation function. If NULL, - * rustsecp256k1zkp_v0_8_0_nonce_function_default is used. - * ndata: pointer to arbitrary data used by the nonce generation function - * (can be NULL). If it is non-NULL and - * rustsecp256k1zkp_v0_8_0_nonce_function_default is used, then ndata must be a - * pointer to 32-bytes of additional data. - * - * The created signature is always in lower-S form. See - * rustsecp256k1zkp_v0_8_0_ecdsa_signature_normalize for more details. - */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_sign( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_ecdsa_signature *sig, - const unsigned char *msghash32, - const unsigned char *seckey, - rustsecp256k1zkp_v0_8_0_nonce_function noncefp, - const void *ndata -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); - -/** Verify an ECDSA secret key. - * - * A secret key is valid if it is not 0 and less than the secp256k1 curve order - * when interpreted as an integer (most significant byte first). The - * probability of choosing a 32-byte string uniformly at random which is an - * invalid secret key is negligible. - * - * Returns: 1: secret key is valid - * 0: secret key is invalid - * Args: ctx: pointer to a context object. - * In: seckey: pointer to a 32-byte secret key. - */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_seckey_verify( - const rustsecp256k1zkp_v0_8_0_context* ctx, - const unsigned char *seckey -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2); - -/** Compute the public key for a secret key. - * - * Returns: 1: secret was valid, public key stores. - * 0: secret was invalid, try again. - * Args: ctx: pointer to a context object, initialized for signing. - * Out: pubkey: pointer to the created public key. - * In: seckey: pointer to a 32-byte secret key. - */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_pubkey_create( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_pubkey *pubkey, - const unsigned char *seckey -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); - -/** Negates a secret key in place. - * - * Returns: 0 if the given secret key is invalid according to - * rustsecp256k1zkp_v0_8_0_ec_seckey_verify. 1 otherwise - * Args: ctx: pointer to a context object - * In/Out: seckey: pointer to the 32-byte secret key to be negated. If the - * secret key is invalid according to - * rustsecp256k1zkp_v0_8_0_ec_seckey_verify, this function returns 0 and - * seckey will be set to some unspecified value. - */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_seckey_negate( - const rustsecp256k1zkp_v0_8_0_context* ctx, - unsigned char *seckey -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2); - -/** Same as rustsecp256k1zkp_v0_8_0_ec_seckey_negate, but DEPRECATED. Will be removed in - * future versions. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_privkey_negate( - const rustsecp256k1zkp_v0_8_0_context* ctx, - unsigned char *seckey -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) - SECP256K1_DEPRECATED("Use rustsecp256k1zkp_v0_8_0_ec_seckey_negate instead"); - -/** Negates a public key in place. - * - * Returns: 1 always - * Args: ctx: pointer to a context object - * In/Out: pubkey: pointer to the public key to be negated. - */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_pubkey_negate( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_pubkey *pubkey -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2); - -/** Tweak a secret key by adding tweak to it. - * - * Returns: 0 if the arguments are invalid or the resulting secret key would be - * invalid (only when the tweak is the negation of the secret key). 1 - * otherwise. - * Args: ctx: pointer to a context object. - * In/Out: seckey: pointer to a 32-byte secret key. If the secret key is - * invalid according to rustsecp256k1zkp_v0_8_0_ec_seckey_verify, this - * function returns 0. seckey will be set to some unspecified - * value if this function returns 0. - * In: tweak32: pointer to a 32-byte tweak. If the tweak is invalid according to - * rustsecp256k1zkp_v0_8_0_ec_seckey_verify, this function returns 0. For - * uniformly random 32-byte arrays the chance of being invalid - * is negligible (around 1 in 2^128). - */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add( - const rustsecp256k1zkp_v0_8_0_context* ctx, - unsigned char *seckey, - const unsigned char *tweak32 -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); - -/** Same as rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add, but DEPRECATED. Will be removed in - * future versions. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_privkey_tweak_add( - const rustsecp256k1zkp_v0_8_0_context* ctx, - unsigned char *seckey, - const unsigned char *tweak32 -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) - SECP256K1_DEPRECATED("Use rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add instead"); - -/** Tweak a public key by adding tweak times the generator to it. - * - * Returns: 0 if the arguments are invalid or the resulting public key would be - * invalid (only when the tweak is the negation of the corresponding - * secret key). 1 otherwise. - * Args: ctx: pointer to a context object initialized for validation. - * In/Out: pubkey: pointer to a public key object. pubkey will be set to an - * invalid value if this function returns 0. - * In: tweak32: pointer to a 32-byte tweak. If the tweak is invalid according to - * rustsecp256k1zkp_v0_8_0_ec_seckey_verify, this function returns 0. For - * uniformly random 32-byte arrays the chance of being invalid - * is negligible (around 1 in 2^128). - */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_pubkey *pubkey, - const unsigned char *tweak32 -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); - -/** Tweak a secret key by multiplying it by a tweak. - * - * Returns: 0 if the arguments are invalid. 1 otherwise. - * Args: ctx: pointer to a context object. - * In/Out: seckey: pointer to a 32-byte secret key. If the secret key is - * invalid according to rustsecp256k1zkp_v0_8_0_ec_seckey_verify, this - * function returns 0. seckey will be set to some unspecified - * value if this function returns 0. - * In: tweak32: pointer to a 32-byte tweak. If the tweak is invalid according to - * rustsecp256k1zkp_v0_8_0_ec_seckey_verify, this function returns 0. For - * uniformly random 32-byte arrays the chance of being invalid - * is negligible (around 1 in 2^128). - */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_mul( - const rustsecp256k1zkp_v0_8_0_context* ctx, - unsigned char *seckey, - const unsigned char *tweak32 -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); - -/** Same as rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_mul, but DEPRECATED. Will be removed in - * future versions. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_privkey_tweak_mul( - const rustsecp256k1zkp_v0_8_0_context* ctx, - unsigned char *seckey, - const unsigned char *tweak32 -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) - SECP256K1_DEPRECATED("Use rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_mul instead"); - -/** Tweak a public key by multiplying it by a tweak value. - * - * Returns: 0 if the arguments are invalid. 1 otherwise. - * Args: ctx: pointer to a context object initialized for validation. - * In/Out: pubkey: pointer to a public key object. pubkey will be set to an - * invalid value if this function returns 0. - * In: tweak32: pointer to a 32-byte tweak. If the tweak is invalid according to - * rustsecp256k1zkp_v0_8_0_ec_seckey_verify, this function returns 0. For - * uniformly random 32-byte arrays the chance of being invalid - * is negligible (around 1 in 2^128). - */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_mul( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_pubkey *pubkey, - const unsigned char *tweak32 -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); - -/** Updates the context randomization to protect against side-channel leakage. - * Returns: 1: randomization successfully updated or nothing to randomize - * 0: error - * Args: ctx: pointer to a context object. - * In: seed32: pointer to a 32-byte random seed (NULL resets to initial state) - * - * While secp256k1 code is written to be constant-time no matter what secret - * values are, it's possible that a future compiler may output code which isn't, - * and also that the CPU may not emit the same radio frequencies or draw the same - * amount power for all values. - * - * This function provides a seed which is combined into the blinding value: that - * blinding value is added before each multiplication (and removed afterwards) so - * that it does not affect function results, but shields against attacks which - * rely on any input-dependent behaviour. - * - * This function has currently an effect only on contexts initialized for signing - * because randomization is currently used only for signing. However, this is not - * guaranteed and may change in the future. It is safe to call this function on - * contexts not initialized for signing; then it will have no effect and return 1. - * - * You should call this after rustsecp256k1zkp_v0_8_0_context_create or - * rustsecp256k1zkp_v0_8_0_context_clone (and rustsecp256k1zkp_v0_8_0_context_preallocated_create or - * rustsecp256k1zkp_v0_8_0_context_clone, resp.), and you may call this repeatedly afterwards. - */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_context_randomize( - rustsecp256k1zkp_v0_8_0_context* ctx, - const unsigned char *seed32 -) SECP256K1_ARG_NONNULL(1); - -/** Add a number of public keys together. - * - * Returns: 1: the sum of the public keys is valid. - * 0: the sum of the public keys is not valid. - * Args: ctx: pointer to a context object. - * Out: out: pointer to a public key object for placing the resulting public key. - * In: ins: pointer to array of pointers to public keys. - * n: the number of public keys to add together (must be at least 1). - */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ec_pubkey_combine( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_pubkey *out, - const rustsecp256k1zkp_v0_8_0_pubkey * const * ins, - size_t n -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); - -/** Compute a tagged hash as defined in BIP-340. - * - * This is useful for creating a message hash and achieving domain separation - * through an application-specific tag. This function returns - * SHA256(SHA256(tag)||SHA256(tag)||msg). Therefore, tagged hash - * implementations optimized for a specific tag can precompute the SHA256 state - * after hashing the tag hashes. - * - * Returns: 1 always. - * Args: ctx: pointer to a context object - * Out: hash32: pointer to a 32-byte array to store the resulting hash - * In: tag: pointer to an array containing the tag - * taglen: length of the tag array - * msg: pointer to an array containing the message - * msglen: length of the message array - */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_tagged_sha256( - const rustsecp256k1zkp_v0_8_0_context* ctx, - unsigned char *hash32, - const unsigned char *tag, - size_t taglen, - const unsigned char *msg, - size_t msglen -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(5); - -#ifdef __cplusplus -} -#endif - -#endif /* SECP256K1_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_bppp.h b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_bppp.h index ede04ae3..3405551e 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_bppp.h +++ b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_bppp.h @@ -1,5 +1,5 @@ -#ifndef _SECP256K1_BPPP_ -# define _SECP256K1_BPPP_ +#ifndef SECP256K1_BPPP_H +# define SECP256K1_BPPP_H #include "secp256k1.h" @@ -10,7 +10,7 @@ extern "C" { #include /** Opaque structure representing a large number of NUMS generators */ -typedef struct rustsecp256k1zkp_v0_8_0_bppp_generators rustsecp256k1zkp_v0_8_0_bppp_generators; +typedef struct rustsecp256k1zkp_v0_10_0_bppp_generators rustsecp256k1zkp_v0_10_0_bppp_generators; /** Allocates and initializes a list of NUMS generators. * Returns a list of generators, or calls the error callback if the allocation fails. @@ -21,20 +21,20 @@ typedef struct rustsecp256k1zkp_v0_8_0_bppp_generators rustsecp256k1zkp_v0_8_0_b * points. We will later use G = H0(required for compatibility with pedersen_commitment DS) * in a separate commit to make review easier. */ -SECP256K1_API rustsecp256k1zkp_v0_8_0_bppp_generators *rustsecp256k1zkp_v0_8_0_bppp_generators_create( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API rustsecp256k1zkp_v0_10_0_bppp_generators *rustsecp256k1zkp_v0_10_0_bppp_generators_create( + const rustsecp256k1zkp_v0_10_0_context *ctx, size_t n ) SECP256K1_ARG_NONNULL(1); /** Allocates a list of generators from a static array * Returns a list of generators or NULL in case of failure. * Args: ctx: pointer to a context object - * In: data: data that came from `rustsecp256k1zkp_v0_8_0_bppp_generators_serialize` + * In: data: data that came from `rustsecp256k1zkp_v0_10_0_bppp_generators_serialize` * data_len: the length of the `data` buffer */ -SECP256K1_API rustsecp256k1zkp_v0_8_0_bppp_generators* rustsecp256k1zkp_v0_8_0_bppp_generators_parse( - const rustsecp256k1zkp_v0_8_0_context* ctx, - const unsigned char* data, +SECP256K1_API rustsecp256k1zkp_v0_10_0_bppp_generators *rustsecp256k1zkp_v0_10_0_bppp_generators_parse( + const rustsecp256k1zkp_v0_10_0_context *ctx, + const unsigned char *data, size_t data_len ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2); @@ -49,10 +49,10 @@ SECP256K1_API rustsecp256k1zkp_v0_8_0_bppp_generators* rustsecp256k1zkp_v0_8_0_b * TODO: For ease of review, this setting G = H0 is not included in this commit. We will * add it in the follow-up rangeproof PR. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_bppp_generators_serialize( - const rustsecp256k1zkp_v0_8_0_context* ctx, - const rustsecp256k1zkp_v0_8_0_bppp_generators* gen, - unsigned char* data, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_bppp_generators_serialize( + const rustsecp256k1zkp_v0_10_0_context *ctx, + const rustsecp256k1zkp_v0_10_0_bppp_generators *gen, + unsigned char *data, size_t *data_len ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); @@ -61,9 +61,9 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_bppp_generators_serialize( * gen: pointer to the generator set to be destroyed * (can be NULL, in which case this function is a no-op) */ -SECP256K1_API void rustsecp256k1zkp_v0_8_0_bppp_generators_destroy( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_bppp_generators* gen +SECP256K1_API void rustsecp256k1zkp_v0_10_0_bppp_generators_destroy( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_bppp_generators *gen ) SECP256K1_ARG_NONNULL(1); # ifdef __cplusplus diff --git a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_ecdh.h b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_ecdh.h index aff6e9ae..0d2942fe 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_ecdh.h +++ b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_ecdh.h @@ -10,15 +10,15 @@ extern "C" { /** A pointer to a function that hashes an EC point to obtain an ECDH secret * * Returns: 1 if the point was successfully hashed. - * 0 will cause rustsecp256k1zkp_v0_8_0_ecdh to fail and return 0. + * 0 will cause rustsecp256k1zkp_v0_10_0_ecdh to fail and return 0. * Other return values are not allowed, and the behaviour of - * rustsecp256k1zkp_v0_8_0_ecdh is undefined for other return values. + * rustsecp256k1zkp_v0_10_0_ecdh is undefined for other return values. * Out: output: pointer to an array to be filled by the function * In: x32: pointer to a 32-byte x coordinate * y32: pointer to a 32-byte y coordinate * data: arbitrary data pointer that is passed through */ -typedef int (*rustsecp256k1zkp_v0_8_0_ecdh_hash_function)( +typedef int (*rustsecp256k1zkp_v0_10_0_ecdh_hash_function)( unsigned char *output, const unsigned char *x32, const unsigned char *y32, @@ -27,11 +27,11 @@ typedef int (*rustsecp256k1zkp_v0_8_0_ecdh_hash_function)( /** An implementation of SHA256 hash function that applies to compressed public key. * Populates the output parameter with 32 bytes. */ -SECP256K1_API extern const rustsecp256k1zkp_v0_8_0_ecdh_hash_function rustsecp256k1zkp_v0_8_0_ecdh_hash_function_sha256; +SECP256K1_API const rustsecp256k1zkp_v0_10_0_ecdh_hash_function rustsecp256k1zkp_v0_10_0_ecdh_hash_function_sha256; -/** A default ECDH hash function (currently equal to rustsecp256k1zkp_v0_8_0_ecdh_hash_function_sha256). +/** A default ECDH hash function (currently equal to rustsecp256k1zkp_v0_10_0_ecdh_hash_function_sha256). * Populates the output parameter with 32 bytes. */ -SECP256K1_API extern const rustsecp256k1zkp_v0_8_0_ecdh_hash_function rustsecp256k1zkp_v0_8_0_ecdh_hash_function_default; +SECP256K1_API const rustsecp256k1zkp_v0_10_0_ecdh_hash_function rustsecp256k1zkp_v0_10_0_ecdh_hash_function_default; /** Compute an EC Diffie-Hellman secret in constant time * @@ -39,20 +39,20 @@ SECP256K1_API extern const rustsecp256k1zkp_v0_8_0_ecdh_hash_function rustsecp25 * 0: scalar was invalid (zero or overflow) or hashfp returned 0 * Args: ctx: pointer to a context object. * Out: output: pointer to an array to be filled by hashfp. - * In: pubkey: a pointer to a rustsecp256k1zkp_v0_8_0_pubkey containing an initialized public key. + * In: pubkey: pointer to a rustsecp256k1zkp_v0_10_0_pubkey containing an initialized public key. * seckey: a 32-byte scalar with which to multiply the point. * hashfp: pointer to a hash function. If NULL, - * rustsecp256k1zkp_v0_8_0_ecdh_hash_function_sha256 is used + * rustsecp256k1zkp_v0_10_0_ecdh_hash_function_sha256 is used * (in which case, 32 bytes will be written to output). * data: arbitrary data pointer that is passed through to hashfp - * (can be NULL for rustsecp256k1zkp_v0_8_0_ecdh_hash_function_sha256). + * (can be NULL for rustsecp256k1zkp_v0_10_0_ecdh_hash_function_sha256). */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ecdh( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ecdh( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *output, - const rustsecp256k1zkp_v0_8_0_pubkey *pubkey, + const rustsecp256k1zkp_v0_10_0_pubkey *pubkey, const unsigned char *seckey, - rustsecp256k1zkp_v0_8_0_ecdh_hash_function hashfp, + rustsecp256k1zkp_v0_10_0_ecdh_hash_function hashfp, void *data ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); diff --git a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_ecdsa_adaptor.h b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_ecdsa_adaptor.h index d836bf6f..4bb9d54d 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_ecdsa_adaptor.h +++ b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_ecdsa_adaptor.h @@ -5,6 +5,8 @@ extern "C" { #endif +#include "secp256k1.h" + /** This module implements single signer ECDSA adaptor signatures following * "One-Time Verifiably Encrypted Signatures A.K.A. Adaptor Signatures" by * Lloyd Fournier @@ -29,7 +31,7 @@ extern "C" { /** A pointer to a function to deterministically generate a nonce. * - * Same as rustsecp256k1zkp_v0_8_0_nonce_function_hardened with the exception of using the + * Same as rustsecp256k1zkp_v0_10_0_nonce_function_hardened with the exception of using the * compressed 33-byte encoding for the pubkey argument. * * Returns: 1 if a nonce was successfully generated. 0 will cause signing to @@ -45,7 +47,7 @@ extern "C" { * Except for test cases, this function should compute some cryptographic hash of * the message, the key, the pubkey, the algorithm description, and data. */ -typedef int (*rustsecp256k1zkp_v0_8_0_nonce_function_hardened_ecdsa_adaptor)( +typedef int (*rustsecp256k1zkp_v0_10_0_nonce_function_hardened_ecdsa_adaptor)( unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, @@ -59,7 +61,7 @@ typedef int (*rustsecp256k1zkp_v0_8_0_nonce_function_hardened_ecdsa_adaptor)( * assumed to be a pointer to 32 bytes of auxiliary random data as defined in BIP-340. * The hash will be tagged with algo after removing all terminating null bytes. */ -SECP256K1_API extern const rustsecp256k1zkp_v0_8_0_nonce_function_hardened_ecdsa_adaptor rustsecp256k1zkp_v0_8_0_nonce_function_ecdsa_adaptor; +SECP256K1_API const rustsecp256k1zkp_v0_10_0_nonce_function_hardened_ecdsa_adaptor rustsecp256k1zkp_v0_10_0_nonce_function_ecdsa_adaptor; /** Encrypted Signing * @@ -69,27 +71,27 @@ SECP256K1_API extern const rustsecp256k1zkp_v0_8_0_nonce_function_hardened_ecdsa * this file and applied the suggested countermeasures. * * Returns: 1 on success, 0 on failure - * Args: ctx: a secp256k1 context object, initialized for signing + * Args: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static) * Out: adaptor_sig162: pointer to 162 byte to store the returned signature * In: seckey32: pointer to 32 byte secret key that will be used for * signing * enckey: pointer to the encryption public key * msg32: pointer to the 32-byte message hash to sign * noncefp: pointer to a nonce generation function. If NULL, - * rustsecp256k1zkp_v0_8_0_nonce_function_ecdsa_adaptor is used + * rustsecp256k1zkp_v0_10_0_nonce_function_ecdsa_adaptor is used * ndata: pointer to arbitrary data used by the nonce generation * function (can be NULL). If it is non-NULL and - * rustsecp256k1zkp_v0_8_0_nonce_function_ecdsa_adaptor is used, then + * rustsecp256k1zkp_v0_10_0_nonce_function_ecdsa_adaptor is used, then * ndata must be a pointer to 32-byte auxiliary randomness * as per BIP-340. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_encrypt( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *adaptor_sig162, unsigned char *seckey32, - const rustsecp256k1zkp_v0_8_0_pubkey *enckey, + const rustsecp256k1zkp_v0_10_0_pubkey *enckey, const unsigned char *msg32, - rustsecp256k1zkp_v0_8_0_nonce_function_hardened_ecdsa_adaptor noncefp, + rustsecp256k1zkp_v0_10_0_nonce_function_hardened_ecdsa_adaptor noncefp, void *ndata ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5); @@ -99,19 +101,19 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt( * and the completed ECDSA signature. * * Returns: 1 on success, 0 on failure - * Args: ctx: a secp256k1 context object, initialized for verification + * Args: ctx: pointer to a context object * In: adaptor_sig162: pointer to 162-byte signature to verify * pubkey: pointer to the public key corresponding to the secret key * used for signing * msg32: pointer to the 32-byte message hash being verified * enckey: pointer to the adaptor encryption public key */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_verify( + const rustsecp256k1zkp_v0_10_0_context *ctx, const unsigned char *adaptor_sig162, - const rustsecp256k1zkp_v0_8_0_pubkey *pubkey, + const rustsecp256k1zkp_v0_10_0_pubkey *pubkey, const unsigned char *msg32, - const rustsecp256k1zkp_v0_8_0_pubkey *enckey + const rustsecp256k1zkp_v0_10_0_pubkey *enckey ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5); /** Signature Decryption @@ -119,15 +121,15 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify( * Derives an ECDSA signature from an adaptor signature and an adaptor decryption key. * * Returns: 1 on success, 0 on failure - * Args: ctx: a secp256k1 context object + * Args: ctx: pointer to a context object * Out: sig: pointer to the ECDSA signature to create * In: deckey32: pointer to 32-byte decryption secret key for the adaptor * encryption public key * adaptor_sig162: pointer to 162-byte adaptor sig */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_decrypt( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_ecdsa_signature *sig, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_decrypt( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_ecdsa_signature *sig, const unsigned char *deckey32, const unsigned char *adaptor_sig162 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); @@ -138,7 +140,7 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_decrypt( * signature. * * Returns: 1 on success, 0 on failure - * Args: ctx: a secp256k1 context object, initialized for signing + * Args: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static) * Out: deckey32: pointer to 32-byte adaptor decryption key for the adaptor * encryption public key * In: sig: pointer to ECDSA signature to recover the adaptor decryption @@ -147,12 +149,12 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_decrypt( * decryption key from * enckey: pointer to the adaptor encryption public key */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_recover( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_recover( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *deckey32, - const rustsecp256k1zkp_v0_8_0_ecdsa_signature *sig, + const rustsecp256k1zkp_v0_10_0_ecdsa_signature *sig, const unsigned char *adaptor_sig162, - const rustsecp256k1zkp_v0_8_0_pubkey *enckey + const rustsecp256k1zkp_v0_10_0_pubkey *enckey ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5); #ifdef __cplusplus diff --git a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_ecdsa_s2c.h b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_ecdsa_s2c.h index 08d51f23..d9083afe 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_ecdsa_s2c.h +++ b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_ecdsa_s2c.h @@ -23,60 +23,60 @@ extern "C" { * guaranteed to be portable between different platforms or versions. It is * however guaranteed to be 64 bytes in size, and can be safely copied/moved. * If you need to convert to a format suitable for storage, transmission, or - * comparison, use rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_serialize and rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_parse. + * comparison, use rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_serialize and rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_parse. */ typedef struct { unsigned char data[64]; -} rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening; +} rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening; /** Parse a sign-to-contract opening. * * Returns: 1 if the opening could be parsed * 0 if the opening could not be parsed - * Args: ctx: a secp256k1 context object. + * Args: ctx: pointer to a context object * Out: opening: pointer to an opening object. If 1 is returned, it is set to a * parsed version of input. If not, its value is unspecified. * In: input33: pointer to 33-byte array with a serialized opening * */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_parse( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening* opening, - const unsigned char* input33 +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_parse( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening *opening, + const unsigned char *input33 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Serialize a sign-to-contract opening into a byte sequence. * * Returns: 1 if the opening was successfully serialized. * 0 if the opening could not be serialized - * Args: ctx: a secp256k1 context object + * Args: ctx: pointer to a context object * Out: output33: pointer to a 33-byte array to place the serialized opening in - * In: opening: a pointer to an initialized `rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening` + * In: opening: pointer to an initialized `rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening` */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_serialize( - const rustsecp256k1zkp_v0_8_0_context* ctx, - unsigned char* output33, - const rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening* opening +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_serialize( + const rustsecp256k1zkp_v0_10_0_context *ctx, + unsigned char *output33, + const rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening *opening ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); -/** Same as rustsecp256k1zkp_v0_8_0_ecdsa_sign, but s2c_data32 is committed to inside the nonce +/** Same as rustsecp256k1zkp_v0_10_0_ecdsa_sign, but s2c_data32 is committed to inside the nonce * * Returns: 1: signature created * 0: the nonce generation function failed, or the private key was invalid. - * Args: ctx: pointer to a context object, initialized for signing (cannot be NULL) - * Out: sig: pointer to an array where the signature will be placed (cannot be NULL) - * s2c_opening: if non-NULL, pointer to an rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening structure to populate + * Args: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static) + * Out: sig: pointer to an array where the signature will be placed (cannot be NULL) + * s2c_opening: if non-NULL, pointer to an rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening structure to populate * In: msg32: the 32-byte message hash being signed (cannot be NULL) * seckey: pointer to a 32-byte secret key (cannot be NULL) * s2c_data32: pointer to a 32-byte data to commit to in the nonce (cannot be NULL) */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig, - rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening* s2c_opening, - const unsigned char* msg32, - const unsigned char* seckey, - const unsigned char* s2c_data32 +SECP256K1_API int rustsecp256k1zkp_v0_10_0_ecdsa_s2c_sign( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_ecdsa_signature *sig, + rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening *s2c_opening, + const unsigned char *msg32, + const unsigned char *seckey, + const unsigned char *s2c_data32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6); /** Verify a sign-to-contract commitment. @@ -84,16 +84,16 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign( * Returns: 1: the signature contains a commitment to data32 (though it does * not necessarily need to be a valid siganture!) * 0: incorrect opening - * Args: ctx: a secp256k1 context object, initialized for verification. + * Args: ctx: pointer to a context object * In: sig: the signature containing the sign-to-contract commitment (cannot be NULL) * data32: the 32-byte data that was committed to (cannot be NULL) * opening: pointer to the opening created during signing (cannot be NULL) */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ecdsa_s2c_verify_commit( - const rustsecp256k1zkp_v0_8_0_context* ctx, - const rustsecp256k1zkp_v0_8_0_ecdsa_signature *sig, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ecdsa_s2c_verify_commit( + const rustsecp256k1zkp_v0_10_0_context *ctx, + const rustsecp256k1zkp_v0_10_0_ecdsa_signature *sig, const unsigned char *data32, - const rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening *opening + const rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening *opening ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); @@ -113,9 +113,9 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ecdsa_s2c * keys, or the signing device to bias the nonce despite the host's contributions, * the host and client must engage in a commit-reveal protocol as follows: * 1. The host draws randomness `rho` and computes a sha256 commitment to it using - * `rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_host_commit`. It sends this to the signing device. + * `rustsecp256k1zkp_v0_10_0_ecdsa_anti_exfil_host_commit`. It sends this to the signing device. * 2. The signing device computes a public nonce `R` using the host's commitment - * as auxiliary randomness, using `rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_signer_commit`. + * as auxiliary randomness, using `rustsecp256k1zkp_v0_10_0_ecdsa_anti_exfil_signer_commit`. * The signing device sends the resulting `R` to the host as a s2c_opening. * * If, at any point from this step onward, the hardware device fails, it is @@ -135,10 +135,10 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ecdsa_s2c * EVER, they should change hardware vendors and perhaps sweep their coins. * * 3. The host replies with `rho` generated in step 1. - * 4. The device signs with `rustsecp256k1zkp_v0_8_0_anti_exfil_sign`, using `rho` as `host_data32`, + * 4. The device signs with `rustsecp256k1zkp_v0_10_0_anti_exfil_sign`, using `rho` as `host_data32`, * and sends the signature to the host. * 5. The host verifies that the signature's public nonce matches the opening from - * step 2 and its original randomness `rho`, using `rustsecp256k1zkp_v0_8_0_anti_exfil_host_verify`. + * step 2 and its original randomness `rho`, using `rustsecp256k1zkp_v0_10_0_anti_exfil_host_verify`. * * Rationale: * - The reason for having a host commitment is to allow the signing device to @@ -164,67 +164,67 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ecdsa_s2c * be revealed to the client until after the host has received the client * commitment. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_host_commit( - const rustsecp256k1zkp_v0_8_0_context* ctx, - unsigned char* rand_commitment32, - const unsigned char* rand32 +SECP256K1_API int rustsecp256k1zkp_v0_10_0_ecdsa_anti_exfil_host_commit( + const rustsecp256k1zkp_v0_10_0_context *ctx, + unsigned char *rand_commitment32, + const unsigned char *rand32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Compute signer's original nonce. Part of the ECDSA Anti-Exfil Protocol. * * Returns 1 on success, 0 on failure. - * Args: ctx: pointer to a context object, initialized for signing (cannot be NULL) + * Args: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static) * Out: s2c_opening: pointer to an s2c_opening where the signer's public nonce will be * placed. (cannot be NULL) * In: msg32: the 32-byte message hash to be signed (cannot be NULL) * seckey32: the 32-byte secret key used for signing (cannot be NULL) * rand_commitment32: the 32-byte randomness commitment from the host (cannot be NULL) */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_signer_commit( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening* s2c_opening, - const unsigned char* msg32, - const unsigned char* seckey32, - const unsigned char* rand_commitment32 +SECP256K1_API int rustsecp256k1zkp_v0_10_0_ecdsa_anti_exfil_signer_commit( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening *s2c_opening, + const unsigned char *msg32, + const unsigned char *seckey32, + const unsigned char *rand_commitment32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5); -/** Same as rustsecp256k1zkp_v0_8_0_ecdsa_sign, but commits to host randomness in the nonce. Part of the +/** Same as rustsecp256k1zkp_v0_10_0_ecdsa_sign, but commits to host randomness in the nonce. Part of the * ECDSA Anti-Exfil Protocol. * * Returns: 1: signature created * 0: the nonce generation function failed, or the private key was invalid. - * Args: ctx: pointer to a context object, initialized for signing (cannot be NULL) - * Out: sig: pointer to an array where the signature will be placed (cannot be NULL) + * Args: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static) + * Out: sig: pointer to an array where the signature will be placed (cannot be NULL) * In: msg32: the 32-byte message hash being signed (cannot be NULL) * seckey: pointer to a 32-byte secret key (cannot be NULL) * host_data32: pointer to 32-byte host-provided randomness (cannot be NULL) */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_anti_exfil_sign( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig, - const unsigned char* msg32, - const unsigned char* seckey, - const unsigned char* host_data32 +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_anti_exfil_sign( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_ecdsa_signature *sig, + const unsigned char *msg32, + const unsigned char *seckey, + const unsigned char *host_data32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5); /** Verify a signature was correctly constructed using the ECDSA Anti-Exfil Protocol. * * Returns: 1: the signature is valid and contains a commitment to host_data32 * 0: incorrect opening - * Args: ctx: a secp256k1 context object, initialized for verification. + * Args: ctx: pointer to a context object * In: sig: the signature produced by the signer (cannot be NULL) * msghash32: the 32-byte message hash being verified (cannot be NULL) * pubkey: pointer to the signer's public key (cannot be NULL) * host_data32: the 32-byte data provided by the host (cannot be NULL) * opening: the s2c opening provided by the signer (cannot be NULL) */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_anti_exfil_host_verify( - const rustsecp256k1zkp_v0_8_0_context* ctx, - const rustsecp256k1zkp_v0_8_0_ecdsa_signature *sig, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_anti_exfil_host_verify( + const rustsecp256k1zkp_v0_10_0_context *ctx, + const rustsecp256k1zkp_v0_10_0_ecdsa_signature *sig, const unsigned char *msg32, - const rustsecp256k1zkp_v0_8_0_pubkey *pubkey, + const rustsecp256k1zkp_v0_10_0_pubkey *pubkey, const unsigned char *host_data32, - const rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening *opening + const rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening *opening ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6); #ifdef __cplusplus diff --git a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_ellswift.h b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_ellswift.h new file mode 100644 index 00000000..346ffece --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_ellswift.h @@ -0,0 +1,200 @@ +#ifndef SECP256K1_ELLSWIFT_H +#define SECP256K1_ELLSWIFT_H + +#include "secp256k1.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* This module provides an implementation of ElligatorSwift as well as a + * version of x-only ECDH using it (including compatibility with BIP324). + * + * ElligatorSwift is described in https://eprint.iacr.org/2022/759 by + * Chavez-Saab, Rodriguez-Henriquez, and Tibouchi. It permits encoding + * uniformly chosen public keys as 64-byte arrays which are indistinguishable + * from uniformly random arrays. + * + * Let f be the function from pairs of field elements to point X coordinates, + * defined as follows (all operations modulo p = 2^256 - 2^32 - 977) + * f(u,t): + * - Let C = 0xa2d2ba93507f1df233770c2a797962cc61f6d15da14ecd47d8d27ae1cd5f852, + * a square root of -3. + * - If u=0, set u=1 instead. + * - If t=0, set t=1 instead. + * - If u^3 + t^2 + 7 = 0, multiply t by 2. + * - Let X = (u^3 + 7 - t^2) / (2 * t) + * - Let Y = (X + t) / (C * u) + * - Return the first in [u + 4 * Y^2, (-X/Y - u) / 2, (X/Y - u) / 2] that is an + * X coordinate on the curve (at least one of them is, for any u and t). + * + * Then an ElligatorSwift encoding of x consists of the 32-byte big-endian + * encodings of field elements u and t concatenated, where f(u,t) = x. + * The encoding algorithm is described in the paper, and effectively picks a + * uniformly random pair (u,t) among those which encode x. + * + * If the Y coordinate is relevant, it is given the same parity as t. + * + * Changes w.r.t. the the paper: + * - The u=0, t=0, and u^3+t^2+7=0 conditions result in decoding to the point + * at infinity in the paper. Here they are remapped to finite points. + * - The paper uses an additional encoding bit for the parity of y. Here the + * parity of t is used (negating t does not affect the decoded x coordinate, + * so this is possible). + * + * For mathematical background about the scheme, see the doc/ellswift.md file. + */ + +/** A pointer to a function used by rustsecp256k1zkp_v0_10_0_ellswift_xdh to hash the shared X + * coordinate along with the encoded public keys to a uniform shared secret. + * + * Returns: 1 if a shared secret was successfully computed. + * 0 will cause rustsecp256k1zkp_v0_10_0_ellswift_xdh to fail and return 0. + * Other return values are not allowed, and the behaviour of + * rustsecp256k1zkp_v0_10_0_ellswift_xdh is undefined for other return values. + * Out: output: pointer to an array to be filled by the function + * In: x32: pointer to the 32-byte serialized X coordinate + * of the resulting shared point (will not be NULL) + * ell_a64: pointer to the 64-byte encoded public key of party A + * (will not be NULL) + * ell_b64: pointer to the 64-byte encoded public key of party B + * (will not be NULL) + * data: arbitrary data pointer that is passed through + */ +typedef int (*rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function)( + unsigned char *output, + const unsigned char *x32, + const unsigned char *ell_a64, + const unsigned char *ell_b64, + void *data +); + +/** An implementation of an rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function which uses + * SHA256(prefix64 || ell_a64 || ell_b64 || x32), where prefix64 is the 64-byte + * array pointed to by data. */ +SECP256K1_API const rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function_prefix; + +/** An implementation of an rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function compatible with + * BIP324. It returns H_tag(ell_a64 || ell_b64 || x32), where H_tag is the + * BIP340 tagged hash function with tag "bip324_ellswift_xonly_ecdh". Equivalent + * to rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function_prefix with prefix64 set to + * SHA256("bip324_ellswift_xonly_ecdh")||SHA256("bip324_ellswift_xonly_ecdh"). + * The data argument is ignored. */ +SECP256K1_API const rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function_bip324; + +/** Construct a 64-byte ElligatorSwift encoding of a given pubkey. + * + * Returns: 1 always. + * Args: ctx: pointer to a context object + * Out: ell64: pointer to a 64-byte array to be filled + * In: pubkey: pointer to a rustsecp256k1zkp_v0_10_0_pubkey containing an + * initialized public key + * rnd32: pointer to 32 bytes of randomness + * + * It is recommended that rnd32 consists of 32 uniformly random bytes, not + * known to any adversary trying to detect whether public keys are being + * encoded, though 16 bytes of randomness (padded to an array of 32 bytes, + * e.g., with zeros) suffice to make the result indistinguishable from + * uniform. The randomness in rnd32 must not be a deterministic function of + * the pubkey (it can be derived from the private key, though). + * + * It is not guaranteed that the computed encoding is stable across versions + * of the library, even if all arguments to this function (including rnd32) + * are the same. + * + * This function runs in variable time. + */ +SECP256K1_API int rustsecp256k1zkp_v0_10_0_ellswift_encode( + const rustsecp256k1zkp_v0_10_0_context *ctx, + unsigned char *ell64, + const rustsecp256k1zkp_v0_10_0_pubkey *pubkey, + const unsigned char *rnd32 +) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); + +/** Decode a 64-bytes ElligatorSwift encoded public key. + * + * Returns: always 1 + * Args: ctx: pointer to a context object + * Out: pubkey: pointer to a rustsecp256k1zkp_v0_10_0_pubkey that will be filled + * In: ell64: pointer to a 64-byte array to decode + * + * This function runs in variable time. + */ +SECP256K1_API int rustsecp256k1zkp_v0_10_0_ellswift_decode( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_pubkey *pubkey, + const unsigned char *ell64 +) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); + +/** Compute an ElligatorSwift public key for a secret key. + * + * Returns: 1: secret was valid, public key was stored. + * 0: secret was invalid, try again. + * Args: ctx: pointer to a context object + * Out: ell64: pointer to a 64-byte array to receive the ElligatorSwift + * public key + * In: seckey32: pointer to a 32-byte secret key + * auxrnd32: (optional) pointer to 32 bytes of randomness + * + * Constant time in seckey and auxrnd32, but not in the resulting public key. + * + * It is recommended that auxrnd32 contains 32 uniformly random bytes, though + * it is optional (and does result in encodings that are indistinguishable from + * uniform even without any auxrnd32). It differs from the (mandatory) rnd32 + * argument to rustsecp256k1zkp_v0_10_0_ellswift_encode in this regard. + * + * This function can be used instead of calling rustsecp256k1zkp_v0_10_0_ec_pubkey_create + * followed by rustsecp256k1zkp_v0_10_0_ellswift_encode. It is safer, as it uses the secret + * key as entropy for the encoding (supplemented with auxrnd32, if provided). + * + * Like rustsecp256k1zkp_v0_10_0_ellswift_encode, this function does not guarantee that the + * computed encoding is stable across versions of the library, even if all + * arguments (including auxrnd32) are the same. + */ +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ellswift_create( + const rustsecp256k1zkp_v0_10_0_context *ctx, + unsigned char *ell64, + const unsigned char *seckey32, + const unsigned char *auxrnd32 +) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); + +/** Given a private key, and ElligatorSwift public keys sent in both directions, + * compute a shared secret using x-only Elliptic Curve Diffie-Hellman (ECDH). + * + * Returns: 1: shared secret was successfully computed + * 0: secret was invalid or hashfp returned 0 + * Args: ctx: pointer to a context object. + * Out: output: pointer to an array to be filled by hashfp. + * In: ell_a64: pointer to the 64-byte encoded public key of party A + * (will not be NULL) + * ell_b64: pointer to the 64-byte encoded public key of party B + * (will not be NULL) + * seckey32: pointer to our 32-byte secret key + * party: boolean indicating which party we are: zero if we are + * party A, non-zero if we are party B. seckey32 must be + * the private key corresponding to that party's ell_?64. + * This correspondence is not checked. + * hashfp: pointer to a hash function. + * data: arbitrary data pointer passed through to hashfp. + * + * Constant time in seckey32. + * + * This function is more efficient than decoding the public keys, and performing + * ECDH on them. + */ +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ellswift_xdh( + const rustsecp256k1zkp_v0_10_0_context *ctx, + unsigned char *output, + const unsigned char *ell_a64, + const unsigned char *ell_b64, + const unsigned char *seckey32, + int party, + rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function hashfp, + void *data +) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(7); + +#ifdef __cplusplus +} +#endif + +#endif /* SECP256K1_ELLSWIFT_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_extrakeys.h b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_extrakeys.h index b5b7c138..b1e483bf 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_extrakeys.h +++ b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_extrakeys.h @@ -16,12 +16,12 @@ extern "C" { * guaranteed to be portable between different platforms or versions. It is * however guaranteed to be 64 bytes in size, and can be safely copied/moved. * If you need to convert to a format suitable for storage, transmission, use - * use rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize and rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse. To - * compare keys, use rustsecp256k1zkp_v0_8_0_xonly_pubkey_cmp. + * use rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize and rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse. To + * compare keys, use rustsecp256k1zkp_v0_10_0_xonly_pubkey_cmp. */ typedef struct { unsigned char data[64]; -} rustsecp256k1zkp_v0_8_0_xonly_pubkey; +} rustsecp256k1zkp_v0_10_0_xonly_pubkey; /** Opaque data structure that holds a keypair consisting of a secret and a * public key. @@ -32,21 +32,21 @@ typedef struct { */ typedef struct { unsigned char data[96]; -} rustsecp256k1zkp_v0_8_0_keypair; +} rustsecp256k1zkp_v0_10_0_keypair; /** Parse a 32-byte sequence into a xonly_pubkey object. * * Returns: 1 if the public key was fully valid. * 0 if the public key could not be parsed or is invalid. * - * Args: ctx: a secp256k1 context object. + * Args: ctx: pointer to a context object. * Out: pubkey: pointer to a pubkey object. If 1 is returned, it is set to a * parsed version of input. If not, it's set to an invalid value. * In: input32: pointer to a serialized xonly_pubkey. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_xonly_pubkey* pubkey, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_xonly_pubkey *pubkey, const unsigned char *input32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); @@ -54,14 +54,14 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_xonly_pub * * Returns: 1 always. * - * Args: ctx: a secp256k1 context object. - * Out: output32: a pointer to a 32-byte array to place the serialized key in. - * In: pubkey: a pointer to a rustsecp256k1zkp_v0_8_0_xonly_pubkey containing an initialized public key. + * Args: ctx: pointer to a context object. + * Out: output32: pointer to a 32-byte array to place the serialized key in. + * In: pubkey: pointer to a rustsecp256k1zkp_v0_10_0_xonly_pubkey containing an initialized public key. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *output32, - const rustsecp256k1zkp_v0_8_0_xonly_pubkey* pubkey + const rustsecp256k1zkp_v0_10_0_xonly_pubkey *pubkey ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Compare two x-only public keys using lexicographic order @@ -69,17 +69,17 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize( * Returns: <0 if the first public key is less than the second * >0 if the first public key is greater than the second * 0 if the two public keys are equal - * Args: ctx: a secp256k1 context object. + * Args: ctx: pointer to a context object. * In: pubkey1: first public key to compare * pubkey2: second public key to compare */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_xonly_pubkey_cmp( - const rustsecp256k1zkp_v0_8_0_context* ctx, - const rustsecp256k1zkp_v0_8_0_xonly_pubkey* pk1, - const rustsecp256k1zkp_v0_8_0_xonly_pubkey* pk2 +SECP256K1_API int rustsecp256k1zkp_v0_10_0_xonly_pubkey_cmp( + const rustsecp256k1zkp_v0_10_0_context *ctx, + const rustsecp256k1zkp_v0_10_0_xonly_pubkey *pk1, + const rustsecp256k1zkp_v0_10_0_xonly_pubkey *pk2 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); -/** Converts a rustsecp256k1zkp_v0_8_0_pubkey into a rustsecp256k1zkp_v0_8_0_xonly_pubkey. +/** Converts a rustsecp256k1zkp_v0_10_0_pubkey into a rustsecp256k1zkp_v0_10_0_xonly_pubkey. * * Returns: 1 always. * @@ -90,11 +90,11 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_xonly_pubkey_cmp( * the negation of the pubkey and set to 0 otherwise. * In: pubkey: pointer to a public key that is converted. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_xonly_pubkey *xonly_pubkey, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_xonly_pubkey *xonly_pubkey, int *pk_parity, - const rustsecp256k1zkp_v0_8_0_pubkey *pubkey + const rustsecp256k1zkp_v0_10_0_pubkey *pubkey ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(4); /** Tweak an x-only public key by adding the generator multiplied with tweak32 @@ -102,34 +102,34 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_xonly_pub * * Note that the resulting point can not in general be represented by an x-only * pubkey because it may have an odd Y coordinate. Instead, the output_pubkey - * is a normal rustsecp256k1zkp_v0_8_0_pubkey. + * is a normal rustsecp256k1zkp_v0_10_0_pubkey. * * Returns: 0 if the arguments are invalid or the resulting public key would be * invalid (only when the tweak is the negation of the corresponding * secret key). 1 otherwise. * - * Args: ctx: pointer to a context object initialized for verification. + * Args: ctx: pointer to a context object. * Out: output_pubkey: pointer to a public key to store the result. Will be set * to an invalid value if this function returns 0. * In: internal_pubkey: pointer to an x-only pubkey to apply the tweak to. - * tweak32: pointer to a 32-byte tweak. If the tweak is invalid - * according to rustsecp256k1zkp_v0_8_0_ec_seckey_verify, this function - * returns 0. For uniformly random 32-byte arrays the - * chance of being invalid is negligible (around 1 in 2^128). + * tweak32: pointer to a 32-byte tweak, which must be valid + * according to rustsecp256k1zkp_v0_10_0_ec_seckey_verify or 32 zero + * bytes. For uniformly random 32-byte tweaks, the chance of + * being invalid is negligible (around 1 in 2^128). */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_pubkey *output_pubkey, - const rustsecp256k1zkp_v0_8_0_xonly_pubkey *internal_pubkey, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_pubkey *output_pubkey, + const rustsecp256k1zkp_v0_10_0_xonly_pubkey *internal_pubkey, const unsigned char *tweak32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); /** Checks that a tweaked pubkey is the result of calling - * rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add with internal_pubkey and tweak32. + * rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add with internal_pubkey and tweak32. * * The tweaked pubkey is represented by its 32-byte x-only serialization and * its pk_parity, which can both be obtained by converting the result of - * tweak_add to a rustsecp256k1zkp_v0_8_0_xonly_pubkey. + * tweak_add to a rustsecp256k1zkp_v0_10_0_xonly_pubkey. * * Note that this alone does _not_ verify that the tweaked pubkey is a * commitment. If the tweak is not chosen in a specific way, the tweaked pubkey @@ -137,21 +137,21 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_xonly_pub * * Returns: 0 if the arguments are invalid or the tweaked pubkey is not the * result of tweaking the internal_pubkey with tweak32. 1 otherwise. - * Args: ctx: pointer to a context object initialized for verification. + * Args: ctx: pointer to a context object. * In: tweaked_pubkey32: pointer to a serialized xonly_pubkey. * tweaked_pk_parity: the parity of the tweaked pubkey (whose serialization * is passed in as tweaked_pubkey32). This must match the * pk_parity value that is returned when calling - * rustsecp256k1zkp_v0_8_0_xonly_pubkey with the tweaked pubkey, or + * rustsecp256k1zkp_v0_10_0_xonly_pubkey with the tweaked pubkey, or * this function will fail. * internal_pubkey: pointer to an x-only public key object to apply the tweak to. * tweak32: pointer to a 32-byte tweak. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add_check( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add_check( + const rustsecp256k1zkp_v0_10_0_context *ctx, const unsigned char *tweaked_pubkey32, int tweaked_pk_parity, - const rustsecp256k1zkp_v0_8_0_xonly_pubkey *internal_pubkey, + const rustsecp256k1zkp_v0_10_0_xonly_pubkey *internal_pubkey, const unsigned char *tweak32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5); @@ -159,13 +159,13 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_xonly_pub * * Returns: 1: secret was valid, keypair is ready to use * 0: secret was invalid, try again with a different secret - * Args: ctx: pointer to a context object, initialized for signing. + * Args: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static). * Out: keypair: pointer to the created keypair. * In: seckey: pointer to a 32-byte secret key. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_keypair_create( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_keypair *keypair, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_keypair_create( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_keypair *keypair, const unsigned char *seckey ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); @@ -176,88 +176,72 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_keypair_c * Out: seckey: pointer to a 32-byte buffer for the secret key. * In: keypair: pointer to a keypair. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_keypair_sec( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_keypair_sec( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *seckey, - const rustsecp256k1zkp_v0_8_0_keypair *keypair + const rustsecp256k1zkp_v0_10_0_keypair *keypair ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Get the public key from a keypair. * * Returns: 1 always. - * Args: ctx: pointer to a context object. - * Out: pubkey: pointer to a pubkey object. If 1 is returned, it is set to - * the keypair public key. If not, it's set to an invalid value. + * Args: ctx: pointer to a context object. + * Out: pubkey: pointer to a pubkey object, set to the keypair public key. * In: keypair: pointer to a keypair. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_keypair_pub( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_pubkey *pubkey, - const rustsecp256k1zkp_v0_8_0_keypair *keypair +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_keypair_pub( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_pubkey *pubkey, + const rustsecp256k1zkp_v0_10_0_keypair *keypair ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Get the x-only public key from a keypair. * - * This is the same as calling rustsecp256k1zkp_v0_8_0_keypair_pub and then - * rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey. + * This is the same as calling rustsecp256k1zkp_v0_10_0_keypair_pub and then + * rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey. * * Returns: 1 always. * Args: ctx: pointer to a context object. - * Out: pubkey: pointer to an xonly_pubkey object. If 1 is returned, it is set - * to the keypair public key after converting it to an - * xonly_pubkey. If not, it's set to an invalid value. + * Out: pubkey: pointer to an xonly_pubkey object, set to the keypair + * public key after converting it to an xonly_pubkey. * pk_parity: Ignored if NULL. Otherwise, pointer to an integer that will be set to the - * pk_parity argument of rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey. + * pk_parity argument of rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey. * In: keypair: pointer to a keypair. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_keypair_xonly_pub( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_xonly_pubkey *pubkey, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_keypair_xonly_pub( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_xonly_pubkey *pubkey, int *pk_parity, - const rustsecp256k1zkp_v0_8_0_keypair *keypair + const rustsecp256k1zkp_v0_10_0_keypair *keypair ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(4); /** Tweak a keypair by adding tweak32 to the secret key and updating the public * key accordingly. * - * Calling this function and then rustsecp256k1zkp_v0_8_0_keypair_pub results in the same - * public key as calling rustsecp256k1zkp_v0_8_0_keypair_xonly_pub and then - * rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add. + * Calling this function and then rustsecp256k1zkp_v0_10_0_keypair_pub results in the same + * public key as calling rustsecp256k1zkp_v0_10_0_keypair_xonly_pub and then + * rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add. * * Returns: 0 if the arguments are invalid or the resulting keypair would be * invalid (only when the tweak is the negation of the keypair's * secret key). 1 otherwise. * - * Args: ctx: pointer to a context object initialized for verification. + * Args: ctx: pointer to a context object. * In/Out: keypair: pointer to a keypair to apply the tweak to. Will be set to * an invalid value if this function returns 0. - * In: tweak32: pointer to a 32-byte tweak. If the tweak is invalid according - * to rustsecp256k1zkp_v0_8_0_ec_seckey_verify, this function returns 0. For - * uniformly random 32-byte arrays the chance of being invalid - * is negligible (around 1 in 2^128). + * In: tweak32: pointer to a 32-byte tweak, which must be valid according to + * rustsecp256k1zkp_v0_10_0_ec_seckey_verify or 32 zero bytes. For uniformly + * random 32-byte tweaks, the chance of being invalid is + * negligible (around 1 in 2^128). */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_keypair_xonly_tweak_add( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_keypair *keypair, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_keypair_xonly_tweak_add( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_keypair *keypair, const unsigned char *tweak32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); -/** Compare two public keys using lexicographic order - * - * Returns: <0 if the first public key is less than the second - * >0 if the first public key is greater than the second - * 0 if the two public keys are equal - * Args: ctx: a secp256k1 context object. - * In: pubkey1: first public key to compare - * pubkey2: second public key to compare - */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_pubkey_cmp( - const rustsecp256k1zkp_v0_8_0_context* ctx, - const rustsecp256k1zkp_v0_8_0_pubkey* pk1, - const rustsecp256k1zkp_v0_8_0_pubkey* pk2 -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); - -/** Sorts public keys using lexicographic order +/** Sort public keys using lexicographic order of their compressed + * serialization. * * Returns: 0 if the arguments are invalid. 1 otherwise. * @@ -265,9 +249,9 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_pubkey_cmp( * In: pubkeys: array of pointers to pubkeys to sort * n_pubkeys: number of elements in the pubkeys array */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_pubkey_sort( - const rustsecp256k1zkp_v0_8_0_context* ctx, - const rustsecp256k1zkp_v0_8_0_pubkey **pubkeys, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_pubkey_sort( + const rustsecp256k1zkp_v0_10_0_context *ctx, + const rustsecp256k1zkp_v0_10_0_pubkey **pubkeys, size_t n_pubkeys ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2); diff --git a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_generator.h b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_generator.h index e0f72bc7..afa2c0b1 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_generator.h +++ b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_generator.h @@ -1,5 +1,5 @@ -#ifndef _SECP256K1_GENERATOR_ -# define _SECP256K1_GENERATOR_ +#ifndef SECP256K1_GENERATOR_H +# define SECP256K1_GENERATOR_H #include "secp256k1.h" @@ -15,59 +15,59 @@ extern "C" { * guaranteed to be portable between different platforms or versions. It is * however guaranteed to be 64 bytes in size, and can be safely copied/moved. * If you need to convert to a format suitable for storage, transmission, or - * comparison, use rustsecp256k1zkp_v0_8_0_generator_serialize and rustsecp256k1zkp_v0_8_0_generator_parse. + * comparison, use rustsecp256k1zkp_v0_10_0_generator_serialize and rustsecp256k1zkp_v0_10_0_generator_parse. */ typedef struct { unsigned char data[64]; -} rustsecp256k1zkp_v0_8_0_generator; +} rustsecp256k1zkp_v0_10_0_generator; /** * Static constant generator 'h' maintained for historical reasons. */ -SECP256K1_API extern const rustsecp256k1zkp_v0_8_0_generator *rustsecp256k1zkp_v0_8_0_generator_h; +SECP256K1_API const rustsecp256k1zkp_v0_10_0_generator *rustsecp256k1zkp_v0_10_0_generator_h; /** Parse a 33-byte generator byte sequence into a generator object. * * Returns: 1 if input contains a valid generator. - * Args: ctx: a secp256k1 context object. + * Args: ctx: pointer to a context object * Out: gen: pointer to the output generator object * In: input: pointer to a 33-byte serialized generator */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_generator_parse( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_generator* gen, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_generator_parse( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_generator *gen, const unsigned char *input ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Serialize a 33-byte generator into a serialized byte sequence. * * Returns: 1 always. - * Args: ctx: a secp256k1 context object. - * Out: output: a pointer to a 33-byte byte array - * In: gen: a pointer to a generator + * Args: ctx: pointer to a context object + * Out: output: pointer to a 33-byte byte array + * In: gen: pointer to a generator object */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_generator_serialize( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_generator_serialize( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *output, - const rustsecp256k1zkp_v0_8_0_generator* gen + const rustsecp256k1zkp_v0_10_0_generator *gen ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Generate a generator for the curve. * * Returns: 0 in the highly unlikely case the seed is not acceptable, * 1 otherwise. - * Args: ctx: a secp256k1 context object - * Out: gen: a generator object - * In: seed32: a 32-byte seed + * Args: ctx: pointer to a context object + * Out: gen: pointer to a the new generator object + * In: seed32: 32-byte seed * * If successful a valid generator will be placed in gen. The produced * generators are distributed uniformly over the curve, and will not have a * known discrete logarithm with respect to any other generator produced, * or to the base generator G. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_generator_generate( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_generator* gen, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_generator_generate( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_generator *gen, const unsigned char *seed32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); @@ -75,18 +75,18 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_generator * * Returns: 0 in the highly unlikely case the seed is not acceptable or when * blind is out of range. 1 otherwise. - * Args: ctx: a secp256k1 context object, initialized for signing - * Out: gen: a generator object - * In: seed32: a 32-byte seed - * blind32: a 32-byte secret value to blind the generator with. + * Args: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static) + * Out: gen: pointer to a generator object + * In: seed32: 32-byte seed + * blind32: 32-byte secret value to blind the generator with. * - * The result is equivalent to first calling rustsecp256k1zkp_v0_8_0_generator_generate, - * converting the result to a public key, calling rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add, + * The result is equivalent to first calling rustsecp256k1zkp_v0_10_0_generator_generate, + * converting the result to a public key, calling rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add, * and then converting back to generator form. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_generator_generate_blinded( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_generator* gen, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_generator_generate_blinded( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_generator *gen, const unsigned char *seed32, const unsigned char *blind32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); @@ -97,38 +97,38 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_generator * guaranteed to be portable between different platforms or versions. It is * however guaranteed to be 64 bytes in size, and can be safely copied/moved. * If you need to convert to a format suitable for storage, transmission, or - * comparison, use rustsecp256k1zkp_v0_8_0_pedersen_commitment_serialize and - * rustsecp256k1zkp_v0_8_0_pedersen_commitment_parse. + * comparison, use rustsecp256k1zkp_v0_10_0_pedersen_commitment_serialize and + * rustsecp256k1zkp_v0_10_0_pedersen_commitment_parse. */ typedef struct { unsigned char data[64]; -} rustsecp256k1zkp_v0_8_0_pedersen_commitment; +} rustsecp256k1zkp_v0_10_0_pedersen_commitment; /** Parse a 33-byte commitment into a commitment object. * * Returns: 1 if input contains a valid commitment. - * Args: ctx: a secp256k1 context object. + * Args: ctx: pointer to a context object * Out: commit: pointer to the output commitment object * In: input: pointer to a 33-byte serialized commitment key */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_pedersen_commitment_parse( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_pedersen_commitment* commit, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_pedersen_commitment_parse( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_pedersen_commitment *commit, const unsigned char *input ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Serialize a commitment object into a serialized byte sequence. * * Returns: 1 always. - * Args: ctx: a secp256k1 context object. - * Out: output: a pointer to a 33-byte byte array - * In: commit: a pointer to a rustsecp256k1zkp_v0_8_0_pedersen_commitment containing an + * Args: ctx: pointer to a context object + * Out: output: pointer to a 33-byte byte array + * In: commit: pointer to a rustsecp256k1zkp_v0_10_0_pedersen_commitment containing an * initialized commitment */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_pedersen_commitment_serialize( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_pedersen_commitment_serialize( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *output, - const rustsecp256k1zkp_v0_8_0_pedersen_commitment* commit + const rustsecp256k1zkp_v0_10_0_pedersen_commitment *commit ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Generate a pedersen commitment. @@ -136,7 +136,7 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_pedersen_commitment_serialize( * 0: Error. The blinding factor is larger than the group order * (probability for random 32 byte number < 2^-127) or results in the * point at infinity. Retry with a different factor. - * In: ctx: pointer to a context object, initialized for signing and Pedersen commitment (cannot be NULL) + * In: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static) * blind: pointer to a 32-byte blinding factor (cannot be NULL) * value: unsigned 64-bit integer value to commit to. * gen: additional generator 'h' @@ -144,12 +144,12 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_pedersen_commitment_serialize( * * Blinding factors can be generated and verified in the same way as secp256k1 private keys for ECDSA. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_pedersen_commit( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_pedersen_commitment *commit, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_pedersen_commit( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_pedersen_commitment *commit, const unsigned char *blind, uint64_t value, - const rustsecp256k1zkp_v0_8_0_generator *gen + const rustsecp256k1zkp_v0_10_0_generator *gen ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(5); /** Computes the sum of multiple positive and negative blinding factors. @@ -163,8 +163,8 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_pedersen_ * npositive: how many of the initial factors should be treated with a positive sign. * Out: blind_out: pointer to a 32-byte array for the sum (cannot be NULL) */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_pedersen_blind_sum( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_pedersen_blind_sum( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *blind_out, const unsigned char * const *blinds, size_t n, @@ -187,11 +187,11 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_pedersen_ * A all blinding factors and all values must sum to zero. * */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_pedersen_verify_tally( - const rustsecp256k1zkp_v0_8_0_context* ctx, - const rustsecp256k1zkp_v0_8_0_pedersen_commitment * const* commits, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_pedersen_verify_tally( + const rustsecp256k1zkp_v0_10_0_context *ctx, + const rustsecp256k1zkp_v0_10_0_pedersen_commitment * const *commits, size_t pcnt, - const rustsecp256k1zkp_v0_8_0_pedersen_commitment * const* ncommits, + const rustsecp256k1zkp_v0_10_0_pedersen_commitment * const *ncommits, size_t ncnt ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(4); @@ -225,11 +225,11 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_pedersen_ * May not be NULL unless `n_total` is 0. * the last value will be modified to get the total sum to zero. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_pedersen_blind_generator_blind_sum( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_pedersen_blind_generator_blind_sum( + const rustsecp256k1zkp_v0_10_0_context *ctx, const uint64_t *value, - const unsigned char* const* generator_blind, - unsigned char* const* blinding_factor, + const unsigned char * const *generator_blind, + unsigned char * const *blinding_factor, size_t n_total, size_t n_inputs ); diff --git a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_musig.h b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_musig.h index 9b3e3938..7e244817 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_musig.h +++ b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_musig.h @@ -9,9 +9,11 @@ extern "C" { #include -/** This module implements BIP MuSig2 v1.0.0-rc.3, a multi-signature scheme - * compatible with BIP-340 ("Schnorr"). You can find an example demonstrating - * the musig module in examples/musig.c. +/** This module implements BIP 327 "MuSig2 for BIP340-compatible + * Multi-Signatures" + * (https://github.com/bitcoin/bips/blob/master/bip-0327.mediawiki) + * v1.0.0. You can find an example demonstrating the musig module in + * examples/musig.c. * * The module also supports BIP-341 ("Taproot") public key tweaking and adaptor * signatures as described in @@ -39,7 +41,7 @@ extern "C" { */ typedef struct { unsigned char data[197]; -} rustsecp256k1zkp_v0_8_0_musig_keyagg_cache; +} rustsecp256k1zkp_v0_10_0_musig_keyagg_cache; /** Opaque data structure that holds a signer's _secret_ nonce. * @@ -58,7 +60,7 @@ typedef struct { */ typedef struct { unsigned char data[132]; -} rustsecp256k1zkp_v0_8_0_musig_secnonce; +} rustsecp256k1zkp_v0_10_0_musig_secnonce; /** Opaque data structure that holds a signer's public nonce. * @@ -67,7 +69,7 @@ typedef struct { */ typedef struct { unsigned char data[132]; -} rustsecp256k1zkp_v0_8_0_musig_pubnonce; +} rustsecp256k1zkp_v0_10_0_musig_pubnonce; /** Opaque data structure that holds an aggregate public nonce. * @@ -77,7 +79,7 @@ typedef struct { */ typedef struct { unsigned char data[132]; -} rustsecp256k1zkp_v0_8_0_musig_aggnonce; +} rustsecp256k1zkp_v0_10_0_musig_aggnonce; /** Opaque data structure that holds a MuSig session. * @@ -87,7 +89,7 @@ typedef struct { */ typedef struct { unsigned char data[133]; -} rustsecp256k1zkp_v0_8_0_musig_session; +} rustsecp256k1zkp_v0_10_0_musig_session; /** Opaque data structure that holds a partial MuSig signature. * @@ -96,77 +98,77 @@ typedef struct { */ typedef struct { unsigned char data[36]; -} rustsecp256k1zkp_v0_8_0_musig_partial_sig; +} rustsecp256k1zkp_v0_10_0_musig_partial_sig; /** Parse a signer's public nonce. * * Returns: 1 when the nonce could be parsed, 0 otherwise. - * Args: ctx: a secp256k1 context object + * Args: ctx: pointer to a context object * Out: nonce: pointer to a nonce object * In: in66: pointer to the 66-byte nonce to be parsed */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_pubnonce_parse( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_musig_pubnonce* nonce, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_musig_pubnonce_parse( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_musig_pubnonce *nonce, const unsigned char *in66 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Serialize a signer's public nonce * * Returns: 1 when the nonce could be serialized, 0 otherwise - * Args: ctx: a secp256k1 context object + * Args: ctx: pointer to a context object * Out: out66: pointer to a 66-byte array to store the serialized nonce * In: nonce: pointer to the nonce */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_pubnonce_serialize( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_musig_pubnonce_serialize( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *out66, - const rustsecp256k1zkp_v0_8_0_musig_pubnonce* nonce + const rustsecp256k1zkp_v0_10_0_musig_pubnonce *nonce ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Parse an aggregate public nonce. * * Returns: 1 when the nonce could be parsed, 0 otherwise. - * Args: ctx: a secp256k1 context object + * Args: ctx: pointer to a context object * Out: nonce: pointer to a nonce object * In: in66: pointer to the 66-byte nonce to be parsed */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_aggnonce_parse( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_musig_aggnonce* nonce, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_musig_aggnonce_parse( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_musig_aggnonce *nonce, const unsigned char *in66 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Serialize an aggregate public nonce * * Returns: 1 when the nonce could be serialized, 0 otherwise - * Args: ctx: a secp256k1 context object + * Args: ctx: pointer to a context object * Out: out66: pointer to a 66-byte array to store the serialized nonce * In: nonce: pointer to the nonce */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_aggnonce_serialize( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_musig_aggnonce_serialize( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *out66, - const rustsecp256k1zkp_v0_8_0_musig_aggnonce* nonce + const rustsecp256k1zkp_v0_10_0_musig_aggnonce *nonce ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Serialize a MuSig partial signature * * Returns: 1 when the signature could be serialized, 0 otherwise - * Args: ctx: a secp256k1 context object + * Args: ctx: pointer to a context object * Out: out32: pointer to a 32-byte array to store the serialized signature * In: sig: pointer to the signature */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_partial_sig_serialize( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_musig_partial_sig_serialize( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *out32, - const rustsecp256k1zkp_v0_8_0_musig_partial_sig* sig + const rustsecp256k1zkp_v0_10_0_musig_partial_sig *sig ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Parse a MuSig partial signature. * * Returns: 1 when the signature could be parsed, 0 otherwise. - * Args: ctx: a secp256k1 context object + * Args: ctx: pointer to a context object * Out: sig: pointer to a signature object * In: in32: pointer to the 32-byte signature to be parsed * @@ -174,9 +176,9 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_partial_sig_serialize( * encoded numbers are out of range, signature verification with it is * guaranteed to fail for every message and public key. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_partial_sig_parse( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_musig_partial_sig* sig, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_musig_partial_sig_parse( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_musig_partial_sig *sig, const unsigned char *in32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); @@ -184,13 +186,13 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_partial_sig_parse( * * Different orders of `pubkeys` result in different `agg_pk`s. * - * Before aggregating, the pubkeys can be sorted with `rustsecp256k1zkp_v0_8_0_pubkey_sort` + * Before aggregating, the pubkeys can be sorted with `rustsecp256k1zkp_v0_10_0_pubkey_sort` * which ensures the same `agg_pk` result for the same multiset of pubkeys. * This is useful to do before `pubkey_agg`, such that the order of pubkeys * does not affect the aggregate public key. * * Returns: 0 if the arguments are invalid, 1 otherwise - * Args: ctx: pointer to a context object initialized for verification + * Args: ctx: pointer to a context object * scratch: should be NULL because it is not yet implemented. If it * was implemented then the scratch space would be used to * compute the aggregate pubkey by multiexponentiation. @@ -208,12 +210,12 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_partial_sig_parse( * aggregate public key. * n_pubkeys: length of pubkeys array. Must be greater than 0. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_pubkey_agg( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_scratch_space *scratch, - rustsecp256k1zkp_v0_8_0_xonly_pubkey *agg_pk, - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache, - const rustsecp256k1zkp_v0_8_0_pubkey * const* pubkeys, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_musig_pubkey_agg( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_scratch_space *scratch, + rustsecp256k1zkp_v0_10_0_xonly_pubkey *agg_pk, + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache, + const rustsecp256k1zkp_v0_10_0_pubkey * const *pubkeys, size_t n_pubkeys ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(5); @@ -229,51 +231,51 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_pubkey_agg( * In: keyagg_cache: pointer to a `musig_keyagg_cache` struct initialized by * `musig_pubkey_agg` */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_musig_pubkey_get( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_pubkey *agg_pk, - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_musig_pubkey_get( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_pubkey *agg_pk, + const rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Apply plain "EC" tweaking to a public key in a given keyagg_cache by * adding the generator multiplied with `tweak32` to it. This is useful for * deriving child keys from an aggregate public key via BIP32. * - * The tweaking method is the same as `rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add`. So after + * The tweaking method is the same as `rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add`. So after * the following pseudocode buf and buf2 have identical contents (absent * earlier failures). * - * rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(..., keyagg_cache, pubkeys, ...) - * rustsecp256k1zkp_v0_8_0_musig_pubkey_get(..., agg_pk, keyagg_cache) - * rustsecp256k1zkp_v0_8_0_musig_pubkey_ec_tweak_add(..., output_pk, tweak32, keyagg_cache) - * rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(..., buf, output_pk) - * rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add(..., agg_pk, tweak32) - * rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(..., buf2, agg_pk) + * rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(..., keyagg_cache, pubkeys, ...) + * rustsecp256k1zkp_v0_10_0_musig_pubkey_get(..., agg_pk, keyagg_cache) + * rustsecp256k1zkp_v0_10_0_musig_pubkey_ec_tweak_add(..., output_pk, tweak32, keyagg_cache) + * rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(..., buf, output_pk) + * rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add(..., agg_pk, tweak32) + * rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(..., buf2, agg_pk) * * This function is required if you want to _sign_ for a tweaked aggregate key. * On the other hand, if you are only computing a public key, but not intending * to create a signature for it, you can just use - * `rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add`. + * `rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add`. * * Returns: 0 if the arguments are invalid or the resulting public key would be * invalid (only when the tweak is the negation of the corresponding * secret key). 1 otherwise. - * Args: ctx: pointer to a context object initialized for verification + * Args: ctx: pointer to a context object * Out: output_pubkey: pointer to a public key to store the result. Will be set * to an invalid value if this function returns 0. If you * do not need it, this arg can be NULL. * In/Out: keyagg_cache: pointer to a `musig_keyagg_cache` struct initialized by * `musig_pubkey_agg` * In: tweak32: pointer to a 32-byte tweak. If the tweak is invalid - * according to `rustsecp256k1zkp_v0_8_0_ec_seckey_verify`, this function + * according to `rustsecp256k1zkp_v0_10_0_ec_seckey_verify`, this function * returns 0. For uniformly random 32-byte arrays the * chance of being invalid is negligible (around 1 in * 2^128). */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_musig_pubkey_ec_tweak_add( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_pubkey *output_pubkey, - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_musig_pubkey_ec_tweak_add( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_pubkey *output_pubkey, + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache, const unsigned char *tweak32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); @@ -281,39 +283,39 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_musig_pub * generator multiplied with `tweak32` to it. This is useful for creating * Taproot outputs. * - * The tweaking method is the same as `rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add`. So in + * The tweaking method is the same as `rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add`. So in * the following pseudocode xonly_pubkey_tweak_add_check (absent earlier * failures) returns 1. * - * rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(..., agg_pk, keyagg_cache, pubkeys, ...) - * rustsecp256k1zkp_v0_8_0_musig_pubkey_xonly_tweak_add(..., output_pk, tweak32, keyagg_cache) - * rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(..., buf, output_pk) - * rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add_check(..., buf, ..., agg_pk, tweak32) + * rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(..., agg_pk, keyagg_cache, pubkeys, ...) + * rustsecp256k1zkp_v0_10_0_musig_pubkey_xonly_tweak_add(..., output_pk, tweak32, keyagg_cache) + * rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(..., buf, output_pk) + * rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add_check(..., buf, ..., agg_pk, tweak32) * * This function is required if you want to _sign_ for a tweaked aggregate key. * On the other hand, if you are only computing a public key, but not intending * to create a signature for it, you can just use - * `rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add`. + * `rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add`. * * Returns: 0 if the arguments are invalid or the resulting public key would be * invalid (only when the tweak is the negation of the corresponding * secret key). 1 otherwise. - * Args: ctx: pointer to a context object initialized for verification + * Args: ctx: pointer to a context object * Out: output_pubkey: pointer to a public key to store the result. Will be set * to an invalid value if this function returns 0. If you * do not need it, this arg can be NULL. * In/Out: keyagg_cache: pointer to a `musig_keyagg_cache` struct initialized by * `musig_pubkey_agg` * In: tweak32: pointer to a 32-byte tweak. If the tweak is invalid - * according to rustsecp256k1zkp_v0_8_0_ec_seckey_verify, this function + * according to rustsecp256k1zkp_v0_10_0_ec_seckey_verify, this function * returns 0. For uniformly random 32-byte arrays the * chance of being invalid is negligible (around 1 in * 2^128). */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_musig_pubkey_xonly_tweak_add( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_pubkey *output_pubkey, - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_musig_pubkey_xonly_tweak_add( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_pubkey *output_pubkey, + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache, const unsigned char *tweak32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); @@ -343,11 +345,11 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_musig_pub * Note that using the same seckey for multiple MuSig sessions is fine. * * Returns: 0 if the arguments are invalid and 1 otherwise - * Args: ctx: pointer to a context object, initialized for signing + * Args: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static) * Out: secnonce: pointer to a structure to store the secret nonce * pubnonce: pointer to a structure to store the public nonce * In: session_id32: a 32-byte session_id32 as explained above. Must be unique to this - * call to rustsecp256k1zkp_v0_8_0_musig_nonce_gen and must be uniformly random + * call to rustsecp256k1zkp_v0_10_0_musig_nonce_gen and must be uniformly random * unless you really know what you are doing. * seckey: the 32-byte secret key that will later be used for signing, if * already known (can be NULL) @@ -362,15 +364,15 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_musig_pub * extra_input32: an optional 32-byte array that is input to the nonce * derivation function (can be NULL) */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_nonce_gen( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_musig_secnonce *secnonce, - rustsecp256k1zkp_v0_8_0_musig_pubnonce *pubnonce, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_musig_nonce_gen( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_musig_secnonce *secnonce, + rustsecp256k1zkp_v0_10_0_musig_pubnonce *pubnonce, const unsigned char *session_id32, const unsigned char *seckey, - const rustsecp256k1zkp_v0_8_0_pubkey *pubkey, + const rustsecp256k1zkp_v0_10_0_pubkey *pubkey, const unsigned char *msg32, - const rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache, + const rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache, const unsigned char *extra_input32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(6); @@ -390,10 +392,10 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_nonce_gen( * n_pubnonces: number of elements in the pubnonces array. Must be * greater than 0. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_nonce_agg( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_musig_aggnonce *aggnonce, - const rustsecp256k1zkp_v0_8_0_musig_pubnonce * const* pubnonces, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_musig_nonce_agg( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_musig_aggnonce *aggnonce, + const rustsecp256k1zkp_v0_10_0_musig_pubnonce * const *pubnonces, size_t n_pubnonces ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); @@ -407,7 +409,7 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_nonce_agg( * * Returns: 0 if the arguments are invalid or if some signer sent invalid * pubnonces, 1 otherwise - * Args: ctx: pointer to a context object, initialized for verification + * Args: ctx: pointer to a context object * Out: session: pointer to a struct to store the session * In: aggnonce: pointer to an aggregate public nonce object that is the * output of musig_nonce_agg @@ -418,13 +420,13 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_nonce_agg( * key if this signing session is part of an adaptor * signature protocol (can be NULL) */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_musig_nonce_process( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_musig_session *session, - const rustsecp256k1zkp_v0_8_0_musig_aggnonce *aggnonce, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_musig_nonce_process( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_musig_session *session, + const rustsecp256k1zkp_v0_10_0_musig_aggnonce *aggnonce, const unsigned char *msg32, - const rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache, - const rustsecp256k1zkp_v0_8_0_pubkey *adaptor + const rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache, + const rustsecp256k1zkp_v0_10_0_pubkey *adaptor ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5); /** Produces a partial signature @@ -440,6 +442,11 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_musig_non * created by calling musig_nonce_gen with that pubkey. Otherwise, the * illegal_callback is called. * + * This function does not verify the output partial signature, deviating from + * the BIP 327 specification. It is recommended to verify the output partial + * signature with `rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify` to prevent random or + * adversarially provoked computation errors. + * * Returns: 0 if the arguments are invalid or the provided secnonce has already * been used for signing, 1 otherwise * Args: ctx: pointer to a context object @@ -454,13 +461,13 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_musig_non * session: pointer to the session that was created with * musig_nonce_process */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_partial_sign( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_musig_partial_sig *partial_sig, - rustsecp256k1zkp_v0_8_0_musig_secnonce *secnonce, - const rustsecp256k1zkp_v0_8_0_keypair *keypair, - const rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache, - const rustsecp256k1zkp_v0_8_0_musig_session *session +SECP256K1_API int rustsecp256k1zkp_v0_10_0_musig_partial_sign( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_musig_partial_sig *partial_sig, + rustsecp256k1zkp_v0_10_0_musig_secnonce *secnonce, + const rustsecp256k1zkp_v0_10_0_keypair *keypair, + const rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache, + const rustsecp256k1zkp_v0_10_0_musig_session *session ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6); /** Verifies an individual signer's partial signature @@ -485,7 +492,7 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_partial_sign( * * Returns: 0 if the arguments are invalid or the partial signature does not * verify, 1 otherwise - * Args ctx: pointer to a context object, initialized for verification + * Args ctx: pointer to a context object * In: partial_sig: pointer to partial signature to verify, sent by * the signer associated with `pubnonce` and `pubkey` * pubnonce: public nonce of the signer in the signing session @@ -495,13 +502,13 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_partial_sign( * session: pointer to the session that was created with * `musig_nonce_process` */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify( - const rustsecp256k1zkp_v0_8_0_context* ctx, - const rustsecp256k1zkp_v0_8_0_musig_partial_sig *partial_sig, - const rustsecp256k1zkp_v0_8_0_musig_pubnonce *pubnonce, - const rustsecp256k1zkp_v0_8_0_pubkey *pubkey, - const rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache, - const rustsecp256k1zkp_v0_8_0_musig_session *session +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify( + const rustsecp256k1zkp_v0_10_0_context *ctx, + const rustsecp256k1zkp_v0_10_0_musig_partial_sig *partial_sig, + const rustsecp256k1zkp_v0_10_0_musig_pubnonce *pubnonce, + const rustsecp256k1zkp_v0_10_0_pubkey *pubkey, + const rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache, + const rustsecp256k1zkp_v0_10_0_musig_session *session ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6); /** Aggregates partial signatures @@ -516,11 +523,11 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_musig_par * n_sigs: number of elements in the partial_sigs array. Must be * greater than 0. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_musig_partial_sig_agg( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *sig64, - const rustsecp256k1zkp_v0_8_0_musig_session *session, - const rustsecp256k1zkp_v0_8_0_musig_partial_sig * const* partial_sigs, + const rustsecp256k1zkp_v0_10_0_musig_session *session, + const rustsecp256k1zkp_v0_10_0_musig_partial_sig * const *partial_sigs, size_t n_sigs ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); @@ -536,10 +543,10 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg( * In: session: pointer to the session that was created with * musig_nonce_process */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_nonce_parity( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_musig_nonce_parity( + const rustsecp256k1zkp_v0_10_0_context *ctx, int *nonce_parity, - const rustsecp256k1zkp_v0_8_0_musig_session *session + const rustsecp256k1zkp_v0_10_0_musig_session *session ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Creates a signature from a pre-signature and an adaptor. @@ -558,8 +565,8 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_musig_nonce_parity( * nonce_parity: the output of `musig_nonce_parity` called with the * session used for producing the pre-signature */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_musig_adapt( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_musig_adapt( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *sig64, const unsigned char *pre_sig64, const unsigned char *sec_adaptor32, @@ -587,8 +594,8 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_musig_ada * nonce_parity: the output of `musig_nonce_parity` called with the * session used for producing sig64 */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_musig_extract_adaptor( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_musig_extract_adaptor( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *sec_adaptor32, const unsigned char *sig64, const unsigned char *pre_sig64, diff --git a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_preallocated.h b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_preallocated.h index de77ee15..9809ccf0 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_preallocated.h +++ b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_preallocated.h @@ -16,8 +16,8 @@ extern "C" { * objects created by functions in secp256k1.h, i.e., they can be passed to any * API function that expects a context object (see secp256k1.h for details). The * only exception is that context objects created by functions in this module - * must be destroyed using rustsecp256k1zkp_v0_8_0_context_preallocated_destroy (in this - * module) instead of rustsecp256k1zkp_v0_8_0_context_destroy (in secp256k1.h). + * must be destroyed using rustsecp256k1zkp_v0_10_0_context_preallocated_destroy (in this + * module) instead of rustsecp256k1zkp_v0_10_0_context_destroy (in secp256k1.h). * * It is guaranteed that functions in this module will not call malloc or its * friends realloc, calloc, and free. @@ -27,24 +27,24 @@ extern "C" { * caller-provided memory. * * The purpose of this function is to determine how much memory must be provided - * to rustsecp256k1zkp_v0_8_0_context_preallocated_create. + * to rustsecp256k1zkp_v0_10_0_context_preallocated_create. * * Returns: the required size of the caller-provided memory block * In: flags: which parts of the context to initialize. */ -SECP256K1_API size_t rustsecp256k1zkp_v0_8_0_context_preallocated_size( +SECP256K1_API size_t rustsecp256k1zkp_v0_10_0_context_preallocated_size( unsigned int flags ) SECP256K1_WARN_UNUSED_RESULT; /** Create a secp256k1 context object in caller-provided memory. * * The caller must provide a pointer to a rewritable contiguous block of memory - * of size at least rustsecp256k1zkp_v0_8_0_context_preallocated_size(flags) bytes, suitably + * of size at least rustsecp256k1zkp_v0_10_0_context_preallocated_size(flags) bytes, suitably * aligned to hold an object of any type. * * The block of memory is exclusively owned by the created context object during * the lifetime of this context object, which begins with the call to this - * function and ends when a call to rustsecp256k1zkp_v0_8_0_context_preallocated_destroy + * function and ends when a call to rustsecp256k1zkp_v0_10_0_context_preallocated_destroy * (which destroys the context object again) returns. During the lifetime of the * context object, the caller is obligated not to access this block of memory, * i.e., the caller may not read or write the memory, e.g., by copying the memory @@ -52,17 +52,19 @@ SECP256K1_API size_t rustsecp256k1zkp_v0_8_0_context_preallocated_size( * in the memory. In simpler words, the prealloc pointer (or any pointer derived * from it) should not be used during the lifetime of the context object. * - * Returns: a newly created context object. - * In: prealloc: a pointer to a rewritable contiguous block of memory of - * size at least rustsecp256k1zkp_v0_8_0_context_preallocated_size(flags) + * Returns: pointer to newly created context object. + * In: prealloc: pointer to a rewritable contiguous block of memory of + * size at least rustsecp256k1zkp_v0_10_0_context_preallocated_size(flags) * bytes, as detailed above. * flags: which parts of the context to initialize. * - * See also rustsecp256k1zkp_v0_8_0_context_randomize (in secp256k1.h) - * and rustsecp256k1zkp_v0_8_0_context_preallocated_destroy. + * See rustsecp256k1zkp_v0_10_0_context_create (in secp256k1.h) for further details. + * + * See also rustsecp256k1zkp_v0_10_0_context_randomize (in secp256k1.h) + * and rustsecp256k1zkp_v0_10_0_context_preallocated_destroy. */ -SECP256K1_API rustsecp256k1zkp_v0_8_0_context* rustsecp256k1zkp_v0_8_0_context_preallocated_create( - void* prealloc, +SECP256K1_API rustsecp256k1zkp_v0_10_0_context *rustsecp256k1zkp_v0_10_0_context_preallocated_create( + void *prealloc, unsigned int flags ) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT; @@ -70,31 +72,34 @@ SECP256K1_API rustsecp256k1zkp_v0_8_0_context* rustsecp256k1zkp_v0_8_0_context_p * caller-provided memory. * * Returns: the required size of the caller-provided memory block. - * In: ctx: an existing context to copy. + * In: ctx: pointer to a context to copy. */ -SECP256K1_API size_t rustsecp256k1zkp_v0_8_0_context_preallocated_clone_size( - const rustsecp256k1zkp_v0_8_0_context* ctx +SECP256K1_API size_t rustsecp256k1zkp_v0_10_0_context_preallocated_clone_size( + const rustsecp256k1zkp_v0_10_0_context *ctx ) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT; /** Copy a secp256k1 context object into caller-provided memory. * * The caller must provide a pointer to a rewritable contiguous block of memory - * of size at least rustsecp256k1zkp_v0_8_0_context_preallocated_size(flags) bytes, suitably + * of size at least rustsecp256k1zkp_v0_10_0_context_preallocated_size(flags) bytes, suitably * aligned to hold an object of any type. * * The block of memory is exclusively owned by the created context object during * the lifetime of this context object, see the description of - * rustsecp256k1zkp_v0_8_0_context_preallocated_create for details. + * rustsecp256k1zkp_v0_10_0_context_preallocated_create for details. + * + * Cloning rustsecp256k1zkp_v0_10_0_context_static is not possible, and should not be emulated by + * the caller (e.g., using memcpy). Create a new context instead. * - * Returns: a newly created context object. - * Args: ctx: an existing context to copy. - * In: prealloc: a pointer to a rewritable contiguous block of memory of - * size at least rustsecp256k1zkp_v0_8_0_context_preallocated_size(flags) + * Returns: pointer to a newly created context object. + * Args: ctx: pointer to a context to copy (not rustsecp256k1zkp_v0_10_0_context_static). + * In: prealloc: pointer to a rewritable contiguous block of memory of + * size at least rustsecp256k1zkp_v0_10_0_context_preallocated_size(flags) * bytes, as detailed above. */ -SECP256K1_API rustsecp256k1zkp_v0_8_0_context* rustsecp256k1zkp_v0_8_0_context_preallocated_clone( - const rustsecp256k1zkp_v0_8_0_context* ctx, - void* prealloc +SECP256K1_API rustsecp256k1zkp_v0_10_0_context *rustsecp256k1zkp_v0_10_0_context_preallocated_clone( + const rustsecp256k1zkp_v0_10_0_context *ctx, + void *prealloc ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_WARN_UNUSED_RESULT; /** Destroy a secp256k1 context object that has been created in @@ -103,22 +108,23 @@ SECP256K1_API rustsecp256k1zkp_v0_8_0_context* rustsecp256k1zkp_v0_8_0_context_p * The context pointer may not be used afterwards. * * The context to destroy must have been created using - * rustsecp256k1zkp_v0_8_0_context_preallocated_create or rustsecp256k1zkp_v0_8_0_context_preallocated_clone. - * If the context has instead been created using rustsecp256k1zkp_v0_8_0_context_create or - * rustsecp256k1zkp_v0_8_0_context_clone, the behaviour is undefined. In that case, - * rustsecp256k1zkp_v0_8_0_context_destroy must be used instead. + * rustsecp256k1zkp_v0_10_0_context_preallocated_create or rustsecp256k1zkp_v0_10_0_context_preallocated_clone. + * If the context has instead been created using rustsecp256k1zkp_v0_10_0_context_create or + * rustsecp256k1zkp_v0_10_0_context_clone, the behaviour is undefined. In that case, + * rustsecp256k1zkp_v0_10_0_context_destroy must be used instead. * * If required, it is the responsibility of the caller to deallocate the block * of memory properly after this function returns, e.g., by calling free on the - * preallocated pointer given to rustsecp256k1zkp_v0_8_0_context_preallocated_create or - * rustsecp256k1zkp_v0_8_0_context_preallocated_clone. + * preallocated pointer given to rustsecp256k1zkp_v0_10_0_context_preallocated_create or + * rustsecp256k1zkp_v0_10_0_context_preallocated_clone. * - * Args: ctx: an existing context to destroy, constructed using - * rustsecp256k1zkp_v0_8_0_context_preallocated_create or - * rustsecp256k1zkp_v0_8_0_context_preallocated_clone. + * Args: ctx: pointer to a context to destroy, constructed using + * rustsecp256k1zkp_v0_10_0_context_preallocated_create or + * rustsecp256k1zkp_v0_10_0_context_preallocated_clone + * (i.e., not rustsecp256k1zkp_v0_10_0_context_static). */ -SECP256K1_API void rustsecp256k1zkp_v0_8_0_context_preallocated_destroy( - rustsecp256k1zkp_v0_8_0_context* ctx +SECP256K1_API void rustsecp256k1zkp_v0_10_0_context_preallocated_destroy( + rustsecp256k1zkp_v0_10_0_context *ctx ) SECP256K1_ARG_NONNULL(1); #ifdef __cplusplus diff --git a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_rangeproof.h b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_rangeproof.h index bfaf5320..9a24e184 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_rangeproof.h +++ b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_rangeproof.h @@ -1,5 +1,5 @@ -#ifndef _SECP256K1_RANGEPROOF_ -# define _SECP256K1_RANGEPROOF_ +#ifndef SECP256K1_RANGEPROOF_H +# define SECP256K1_RANGEPROOF_H #include "secp256k1.h" #include "secp256k1_generator.h" @@ -22,7 +22,7 @@ extern "C" { /** Verify a proof that a committed value is within a range. * Returns 1: Value is within the range [0..2^64), the specifically proven range is in the min/max value outputs. * 0: Proof failed or other error. - * In: ctx: pointer to a context object, initialized for range-proof and commitment (cannot be NULL) + * In: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static) * commit: the commitment being proved. (cannot be NULL) * proof: pointer to character array with the proof. (cannot be NULL) * plen: length of proof in bytes. @@ -32,22 +32,22 @@ extern "C" { * Out: min_value: pointer to a unsigned int64 which will be updated with the minimum value that commit could have. (cannot be NULL) * max_value: pointer to a unsigned int64 which will be updated with the maximum value that commit could have. (cannot be NULL) */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_rangeproof_verify( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_rangeproof_verify( + const rustsecp256k1zkp_v0_10_0_context *ctx, uint64_t *min_value, uint64_t *max_value, - const rustsecp256k1zkp_v0_8_0_pedersen_commitment *commit, + const rustsecp256k1zkp_v0_10_0_pedersen_commitment *commit, const unsigned char *proof, size_t plen, const unsigned char *extra_commit, size_t extra_commit_len, - const rustsecp256k1zkp_v0_8_0_generator* gen + const rustsecp256k1zkp_v0_10_0_generator *gen ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(9); /** Verify a range proof proof and rewind the proof to recover information sent by its author. * Returns 1: Value is within the range [0..2^64), the specifically proven range is in the min/max value outputs, and the value and blinding were recovered. * 0: Proof failed, rewind failed, or other error. - * In: ctx: pointer to a context object, initialized for range-proof and Pedersen commitment (cannot be NULL) + * In: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static) * commit: the commitment being proved. (cannot be NULL) * proof: pointer to character array with the proof. (cannot be NULL) * plen: length of proof in bytes. @@ -64,8 +64,8 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_rangeproo * min_value: pointer to an unsigned int64 which will be updated with the minimum value that commit could have. (cannot be NULL) * max_value: pointer to an unsigned int64 which will be updated with the maximum value that commit could have. (cannot be NULL) */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_rangeproof_rewind( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_rangeproof_rewind( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *blind_out, uint64_t *value_out, unsigned char *message_out, @@ -73,18 +73,18 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_rangeproo const unsigned char *nonce, uint64_t *min_value, uint64_t *max_value, - const rustsecp256k1zkp_v0_8_0_pedersen_commitment *commit, + const rustsecp256k1zkp_v0_10_0_pedersen_commitment *commit, const unsigned char *proof, size_t plen, const unsigned char *extra_commit, size_t extra_commit_len, - const rustsecp256k1zkp_v0_8_0_generator *gen + const rustsecp256k1zkp_v0_10_0_generator *gen ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(6) SECP256K1_ARG_NONNULL(7) SECP256K1_ARG_NONNULL(8) SECP256K1_ARG_NONNULL(9) SECP256K1_ARG_NONNULL(10) SECP256K1_ARG_NONNULL(14); /** Author a proof that a committed value is within a range. * Returns 1: Proof successfully created. * 0: Error - * In: ctx: pointer to a context object, initialized for range-proof, signing, and Pedersen commitment (cannot be NULL) + * In: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static) * proof: pointer to array to receive the proof, can be up to 5134 bytes. (cannot be NULL) * min_value: constructs a proof where the verifer can tell the minimum value is at least the specified amount. * commit: the commitment being proved. @@ -109,12 +109,12 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_rangeproo * This can randomly fail with probability around one in 2^100. If this happens, buy a lottery ticket and retry with a different nonce or blinding. * */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_rangeproof_sign( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_rangeproof_sign( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *proof, size_t *plen, uint64_t min_value, - const rustsecp256k1zkp_v0_8_0_pedersen_commitment *commit, + const rustsecp256k1zkp_v0_10_0_pedersen_commitment *commit, const unsigned char *blind, const unsigned char *nonce, int exp, @@ -124,7 +124,7 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_rangeproo size_t msg_len, const unsigned char *extra_commit, size_t extra_commit_len, - const rustsecp256k1zkp_v0_8_0_generator *gen + const rustsecp256k1zkp_v0_10_0_generator *gen ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6) SECP256K1_ARG_NONNULL(7) SECP256K1_ARG_NONNULL(15); /** Extract some basic information from a range-proof. @@ -138,8 +138,8 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_rangeproo * min_value: pointer to an unsigned int64 which will be updated with the minimum value that commit could have. (cannot be NULL) * max_value: pointer to an unsigned int64 which will be updated with the maximum value that commit could have. (cannot be NULL) */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_rangeproof_info( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_rangeproof_info( + const rustsecp256k1zkp_v0_10_0_context *ctx, int *exp, int *mantissa, uint64_t *min_value, @@ -152,7 +152,7 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_rangeproo * * An actual rangeproof may be smaller, for example if the actual value * is less than both the provided `max_value` and 2^`min_bits`, or if - * the `exp` parameter to `rustsecp256k1zkp_v0_8_0_rangeproof_sign` is set such that + * the `exp` parameter to `rustsecp256k1zkp_v0_10_0_rangeproof_sign` is set such that * the proven range is compressed. In particular this function will always * overestimate the size of single-value proofs. Also, if `min_value` * is set to 0 in the proof, the result will usually, but not always, @@ -169,8 +169,8 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_rangeproo * max_value: the maximum value that might be passed for `value` for the proof. * min_bits: the value that will be passed as `min_bits` for the proof. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT size_t rustsecp256k1zkp_v0_8_0_rangeproof_max_size( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT size_t rustsecp256k1zkp_v0_10_0_rangeproof_max_size( + const rustsecp256k1zkp_v0_10_0_context *ctx, uint64_t max_value, int min_bits ) SECP256K1_ARG_NONNULL(1); diff --git a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_recovery.h b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_recovery.h index c409a002..deed80b7 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_recovery.h +++ b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_recovery.h @@ -14,8 +14,8 @@ extern "C" { * guaranteed to be portable between different platforms or versions. It is * however guaranteed to be 65 bytes in size, and can be safely copied/moved. * If you need to convert to a format suitable for storage or transmission, use - * the rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_* and - * rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_* functions. + * the rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_* and + * rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_* functions. * * Furthermore, it is guaranteed that identical signatures (including their * recoverability) will have identical representation, so they can be @@ -23,19 +23,19 @@ extern "C" { */ typedef struct { unsigned char data[65]; -} rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature; +} rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature; /** Parse a compact ECDSA signature (64 bytes + recovery id). * * Returns: 1 when the signature could be parsed, 0 otherwise - * Args: ctx: a secp256k1 context object - * Out: sig: a pointer to a signature object - * In: input64: a pointer to a 64-byte compact signature + * Args: ctx: pointer to a context object + * Out: sig: pointer to a signature object + * In: input64: pointer to a 64-byte compact signature * recid: the recovery id (0, 1, 2 or 3) */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature* sig, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_parse_compact( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature *sig, const unsigned char *input64, int recid ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); @@ -43,50 +43,50 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_comp /** Convert a recoverable signature into a normal signature. * * Returns: 1 - * Args: ctx: a secp256k1 context object. - * Out: sig: a pointer to a normal signature. - * In: sigin: a pointer to a recoverable signature. + * Args: ctx: pointer to a context object. + * Out: sig: pointer to a normal signature. + * In: sigin: pointer to a recoverable signature. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_convert( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig, - const rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature* sigin +SECP256K1_API int rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_convert( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_ecdsa_signature *sig, + const rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature *sigin ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); /** Serialize an ECDSA signature in compact format (64 bytes + recovery id). * * Returns: 1 - * Args: ctx: a secp256k1 context object. - * Out: output64: a pointer to a 64-byte array of the compact signature. - * recid: a pointer to an integer to hold the recovery id. - * In: sig: a pointer to an initialized signature object. + * Args: ctx: pointer to a context object. + * Out: output64: pointer to a 64-byte array of the compact signature. + * recid: pointer to an integer to hold the recovery id. + * In: sig: pointer to an initialized signature object. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_serialize_compact( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_serialize_compact( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *output64, int *recid, - const rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature* sig + const rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature *sig ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); /** Create a recoverable ECDSA signature. * * Returns: 1: signature created * 0: the nonce generation function failed, or the secret key was invalid. - * Args: ctx: pointer to a context object, initialized for signing. + * Args: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static). * Out: sig: pointer to an array where the signature will be placed. * In: msghash32: the 32-byte message hash being signed. * seckey: pointer to a 32-byte secret key. * noncefp: pointer to a nonce generation function. If NULL, - * rustsecp256k1zkp_v0_8_0_nonce_function_default is used. + * rustsecp256k1zkp_v0_10_0_nonce_function_default is used. * ndata: pointer to arbitrary data used by the nonce generation function - * (can be NULL for rustsecp256k1zkp_v0_8_0_nonce_function_default). + * (can be NULL for rustsecp256k1zkp_v0_10_0_nonce_function_default). */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature *sig, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_ecdsa_sign_recoverable( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature *sig, const unsigned char *msghash32, const unsigned char *seckey, - rustsecp256k1zkp_v0_8_0_nonce_function noncefp, + rustsecp256k1zkp_v0_10_0_nonce_function noncefp, const void *ndata ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); @@ -94,15 +94,15 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable( * * Returns: 1: public key successfully recovered (which guarantees a correct signature). * 0: otherwise. - * Args: ctx: pointer to a context object, initialized for verification. + * Args: ctx: pointer to a context object. * Out: pubkey: pointer to the recovered public key. * In: sig: pointer to initialized signature that supports pubkey recovery. * msghash32: the 32-byte message hash assumed to be signed. */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_ecdsa_recover( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_pubkey *pubkey, - const rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature *sig, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_ecdsa_recover( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_pubkey *pubkey, + const rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature *sig, const unsigned char *msghash32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); diff --git a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_schnorrsig.h b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_schnorrsig.h index 149a7c04..d10ce0dd 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_schnorrsig.h +++ b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_schnorrsig.h @@ -15,7 +15,7 @@ extern "C" { /** A pointer to a function to deterministically generate a nonce. * - * Same as rustsecp256k1zkp_v0_8_0_nonce function with the exception of accepting an + * Same as rustsecp256k1zkp_v0_10_0_nonce function with the exception of accepting an * additional pubkey argument and not requiring an attempt argument. The pubkey * argument can protect signature schemes with key-prefixed challenge hash * inputs against reusing the nonce when signing with the wrong precomputed @@ -38,7 +38,7 @@ extern "C" { * Except for test cases, this function should compute some cryptographic hash of * the message, the key, the pubkey, the algorithm description, and data. */ -typedef int (*rustsecp256k1zkp_v0_8_0_nonce_function_hardened)( +typedef int (*rustsecp256k1zkp_v0_10_0_nonce_function_hardened)( unsigned char *nonce32, const unsigned char *msg, size_t msglen, @@ -61,7 +61,7 @@ typedef int (*rustsecp256k1zkp_v0_8_0_nonce_function_hardened)( * Therefore, to create BIP-340 compliant signatures, algo must be set to * "BIP0340/nonce" and algolen to 13. */ -SECP256K1_API extern const rustsecp256k1zkp_v0_8_0_nonce_function_hardened rustsecp256k1zkp_v0_8_0_nonce_function_bip340; +SECP256K1_API const rustsecp256k1zkp_v0_10_0_nonce_function_hardened rustsecp256k1zkp_v0_10_0_nonce_function_bip340; /** Data structure that contains additional arguments for schnorrsig_sign_custom. * @@ -73,17 +73,17 @@ SECP256K1_API extern const rustsecp256k1zkp_v0_8_0_nonce_function_hardened rusts * and has no other function than making sure the object is * initialized. * noncefp: pointer to a nonce generation function. If NULL, - * rustsecp256k1zkp_v0_8_0_nonce_function_bip340 is used + * rustsecp256k1zkp_v0_10_0_nonce_function_bip340 is used * ndata: pointer to arbitrary data used by the nonce generation function * (can be NULL). If it is non-NULL and - * rustsecp256k1zkp_v0_8_0_nonce_function_bip340 is used, then ndata must be a + * rustsecp256k1zkp_v0_10_0_nonce_function_bip340 is used, then ndata must be a * pointer to 32-byte auxiliary randomness as per BIP-340. */ typedef struct { unsigned char magic[4]; - rustsecp256k1zkp_v0_8_0_nonce_function_hardened noncefp; - void* ndata; -} rustsecp256k1zkp_v0_8_0_schnorrsig_extraparams; + rustsecp256k1zkp_v0_10_0_nonce_function_hardened noncefp; + void *ndata; +} rustsecp256k1zkp_v0_10_0_schnorrsig_extraparams; #define SECP256K1_SCHNORRSIG_EXTRAPARAMS_MAGIC { 0xda, 0x6f, 0xb3, 0x8c } #define SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT {\ @@ -95,18 +95,18 @@ typedef struct { /** Create a Schnorr signature. * * Does _not_ strictly follow BIP-340 because it does not verify the resulting - * signature. Instead, you can manually use rustsecp256k1zkp_v0_8_0_schnorrsig_verify and + * signature. Instead, you can manually use rustsecp256k1zkp_v0_10_0_schnorrsig_verify and * abort if it fails. * * This function only signs 32-byte messages. If you have messages of a * different size (or the same size but without a context-specific tag * prefix), it is recommended to create a 32-byte message hash with - * rustsecp256k1zkp_v0_8_0_tagged_sha256 and then sign the hash. Tagged hashing allows + * rustsecp256k1zkp_v0_10_0_tagged_sha256 and then sign the hash. Tagged hashing allows * providing an context-specific tag for domain separation. This prevents * signatures from being valid in multiple contexts by accident. * * Returns 1 on success, 0 on failure. - * Args: ctx: pointer to a context object, initialized for signing. + * Args: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static). * Out: sig64: pointer to a 64-byte array to store the serialized signature. * In: msg32: the 32-byte message being signed. * keypair: pointer to an initialized keypair. @@ -116,63 +116,71 @@ typedef struct { * BIP-340 "Default Signing" for a full explanation of this * argument and for guidance if randomness is expensive. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_schnorrsig_sign32( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_schnorrsig_sign32( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *sig64, const unsigned char *msg32, - const rustsecp256k1zkp_v0_8_0_keypair *keypair, + const rustsecp256k1zkp_v0_10_0_keypair *keypair, const unsigned char *aux_rand32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); -/** Same as rustsecp256k1zkp_v0_8_0_schnorrsig_sign32, but DEPRECATED. Will be removed in +/** Same as rustsecp256k1zkp_v0_10_0_schnorrsig_sign32, but DEPRECATED. Will be removed in * future versions. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_schnorrsig_sign( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_schnorrsig_sign( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *sig64, const unsigned char *msg32, - const rustsecp256k1zkp_v0_8_0_keypair *keypair, + const rustsecp256k1zkp_v0_10_0_keypair *keypair, const unsigned char *aux_rand32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) - SECP256K1_DEPRECATED("Use rustsecp256k1zkp_v0_8_0_schnorrsig_sign32 instead"); + SECP256K1_DEPRECATED("Use rustsecp256k1zkp_v0_10_0_schnorrsig_sign32 instead"); /** Create a Schnorr signature with a more flexible API. * - * Same arguments as rustsecp256k1zkp_v0_8_0_schnorrsig_sign except that it allows signing + * Same arguments as rustsecp256k1zkp_v0_10_0_schnorrsig_sign except that it allows signing * variable length messages and accepts a pointer to an extraparams object that * allows customizing signing by passing additional arguments. * - * Creates the same signatures as schnorrsig_sign if msglen is 32 and the - * extraparams.ndata is the same as aux_rand32. + * Equivalent to rustsecp256k1zkp_v0_10_0_schnorrsig_sign32(..., aux_rand32) if msglen is 32 + * and extraparams is initialized as follows: + * ``` + * rustsecp256k1zkp_v0_10_0_schnorrsig_extraparams extraparams = SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT; + * extraparams.ndata = (unsigned char*)aux_rand32; + * ``` * + * Returns 1 on success, 0 on failure. + * Args: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static). + * Out: sig64: pointer to a 64-byte array to store the serialized signature. * In: msg: the message being signed. Can only be NULL if msglen is 0. - * msglen: length of the message - * extraparams: pointer to a extraparams object (can be NULL) + * msglen: length of the message. + * keypair: pointer to an initialized keypair. + * extraparams: pointer to an extraparams object (can be NULL). */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *sig64, const unsigned char *msg, size_t msglen, - const rustsecp256k1zkp_v0_8_0_keypair *keypair, - rustsecp256k1zkp_v0_8_0_schnorrsig_extraparams *extraparams + const rustsecp256k1zkp_v0_10_0_keypair *keypair, + rustsecp256k1zkp_v0_10_0_schnorrsig_extraparams *extraparams ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(5); /** Verify a Schnorr signature. * * Returns: 1: correct signature * 0: incorrect signature - * Args: ctx: a secp256k1 context object, initialized for verification. + * Args: ctx: pointer to a context object. * In: sig64: pointer to the 64-byte signature to verify. * msg: the message being verified. Can only be NULL if msglen is 0. * msglen: length of the message - * pubkey: pointer to an x-only public key to verify with (cannot be NULL) + * pubkey: pointer to an x-only public key to verify with */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_schnorrsig_verify( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_schnorrsig_verify( + const rustsecp256k1zkp_v0_10_0_context *ctx, const unsigned char *sig64, const unsigned char *msg, size_t msglen, - const rustsecp256k1zkp_v0_8_0_xonly_pubkey *pubkey + const rustsecp256k1zkp_v0_10_0_xonly_pubkey *pubkey ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(5); #ifdef __cplusplus diff --git a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_schnorrsig_halfagg.h b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_schnorrsig_halfagg.h new file mode 100644 index 00000000..8e4b42b1 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_schnorrsig_halfagg.h @@ -0,0 +1,107 @@ +#ifndef SECP256K1_SCHNORRSIG_HALFAGG_H +#define SECP256K1_SCHNORRSIG_HALFAGG_H + +#include "secp256k1.h" +#include "secp256k1_extrakeys.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** Incrementally (Half-)Aggregate a sequence of Schnorr + * signatures to an existing half-aggregate signature. + * + * Returns 1 on success, 0 on failure. + * Args: ctx: a secp256k1 context object. + * In/Out: aggsig: pointer to the serialized aggregate signature + * that is input. The first 32*(n_before+1) of this + * array should hold the input aggsig. It will be + * overwritten by the new serialized aggregate signature. + * It should be large enough for that, see aggsig_len. + * aggsig_len: size of aggsig array in bytes. + * Should be large enough to hold the new + * serialized aggregate signature, i.e., + * should satisfy aggsig_size >= 32*(n_before+n_new+1). + * It will be overwritten to be the exact size of the + * resulting aggsig. + * In: all_pubkeys: Array of (n_before + n_new) many x-only public keys, + * including both the ones for the already aggregated signature + * and the ones for the signatures that should be added. + * Can only be NULL if n_before + n_new is 0. + * all_msgs32: Array of (n_before + n_new) many 32-byte messages, + * including both the ones for the already aggregated signature + * and the ones for the signatures that should be added. + * Can only be NULL if n_before + n_new is 0. + * new_sigs64: Array of n_new many 64-byte signatures, containing the new + * signatures that should be added. Can only be NULL if n_new is 0. + * n_before: Number of signatures that have already been aggregated + * in the input aggregate signature. + * n_new: Number of signatures that should now be added + * to the aggregate signature. + */ +SECP256K1_API int rustsecp256k1zkp_v0_10_0_schnorrsig_inc_aggregate( + const rustsecp256k1zkp_v0_10_0_context *ctx, + unsigned char *aggsig, + size_t *aggsig_len, + const rustsecp256k1zkp_v0_10_0_xonly_pubkey* all_pubkeys, + const unsigned char *all_msgs32, + const unsigned char *new_sigs64, + size_t n_before, + size_t n_new +) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); + +/** (Half-)Aggregate a sequence of Schnorr signatures. + * + * Returns 1 on success, 0 on failure. + * Args: ctx: a secp256k1 context object. + * Out: aggsig: pointer to an array of aggsig_len many bytes to + * store the serialized aggregate signature. + * In/Out: aggsig_len: size of the aggsig array that is passed in bytes; + * will be overwritten to be the exact size of aggsig. + * In: pubkeys: Array of n many x-only public keys. + * Can only be NULL if n is 0. + * msgs32: Array of n many 32-byte messages. + * Can only be NULL if n is 0. + * sigs64: Array of n many 64-byte signatures. + * Can only be NULL if n is 0. + * n: number of signatures to be aggregated. + */ +SECP256K1_API int rustsecp256k1zkp_v0_10_0_schnorrsig_aggregate( + const rustsecp256k1zkp_v0_10_0_context *ctx, + unsigned char *aggsig, + size_t *aggsig_len, + const rustsecp256k1zkp_v0_10_0_xonly_pubkey *pubkeys, + const unsigned char *msgs32, + const unsigned char *sigs64, + size_t n +) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); + +/** Verify a (Half-)aggregate Schnorr signature. + * + * Returns: 1: correct signature. + * 0: incorrect signature. + * Args: ctx: a secp256k1 context object. + * In: pubkeys: Array of n many x-only public keys. Can only be NULL if n is 0. + * msgs32: Array of n many 32-byte messages. Can only be NULL if n is 0. + * n: number of signatures to that have been aggregated. + * aggsig: Pointer to an array of aggsig_size many bytes + * containing the serialized aggregate + * signature to be verified. + * aggsig_len: Size of the aggregate signature in bytes. + * Should be aggsig_len = 32*(n+1) + */ +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_schnorrsig_aggverify( + const rustsecp256k1zkp_v0_10_0_context *ctx, + const rustsecp256k1zkp_v0_10_0_xonly_pubkey *pubkeys, + const unsigned char *msgs32, + size_t n, + const unsigned char *aggsig, + size_t aggsig_len +) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(5); + +#ifdef __cplusplus +} +#endif + +#endif /* SECP256K1_SCHNORRSIG_HALFAGG_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_surjectionproof.h b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_surjectionproof.h index 2e3fa34c..a9fc20f5 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_surjectionproof.h +++ b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_surjectionproof.h @@ -1,5 +1,5 @@ -#ifndef _SECP256K1_SURJECTIONPROOF_ -#define _SECP256K1_SURJECTIONPROOF_ +#ifndef SECP256K1_SURJECTIONPROOF_H +#define SECP256K1_SURJECTIONPROOF_H #include "secp256k1.h" #include "secp256k1_rangeproof.h" @@ -32,8 +32,8 @@ extern "C" { * will have identical representation. (That is, memcmp may return nonzero * even for identical proofs.) * - * To obtain these properties, instead use rustsecp256k1zkp_v0_8_0_surjectionproof_parse - * and rustsecp256k1zkp_v0_8_0_surjectionproof_serialize to encode/decode proofs into a + * To obtain these properties, instead use rustsecp256k1zkp_v0_10_0_surjectionproof_parse + * and rustsecp256k1zkp_v0_10_0_surjectionproof_serialize to encode/decode proofs into a * well-defined format. * * The representation is exposed to allow creation of these objects on the @@ -41,7 +41,7 @@ extern "C" { */ typedef struct { #ifdef VERIFY - /** Mark whether this proof has gone through `rustsecp256k1zkp_v0_8_0_surjectionproof_initialize` */ + /** Mark whether this proof has gone through `rustsecp256k1zkp_v0_10_0_surjectionproof_initialize` */ int initialized; #endif /** Total number of input asset tags */ @@ -50,15 +50,15 @@ typedef struct { unsigned char used_inputs[SECP256K1_SURJECTIONPROOF_MAX_N_INPUTS / 8]; /** Borromean signature: e0, scalars */ unsigned char data[32 * (1 + SECP256K1_SURJECTIONPROOF_MAX_USED_INPUTS)]; -} rustsecp256k1zkp_v0_8_0_surjectionproof; +} rustsecp256k1zkp_v0_10_0_surjectionproof; #ifndef USE_REDUCED_SURJECTION_PROOF_SIZE /** Parse a surjection proof * * Returns: 1 when the proof could be parsed, 0 otherwise. - * Args: ctx: a secp256k1 context object - * Out: proof: a pointer to a proof object - * In: input: a pointer to the array to parse + * Args: ctx: pointer to a context object + * Out: proof: pointer to a proof object + * In: input: pointer to the array to parse * inputlen: length of the array pointed to by input * * The proof must consist of: @@ -68,9 +68,9 @@ typedef struct { * - `m` big-endian 32-byte borromean signature s values, where `m` * is the number of set bits in the bitmap */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_surjectionproof_parse( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_surjectionproof *proof, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_surjectionproof_parse( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_surjectionproof *proof, const unsigned char *input, size_t inputlen ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); @@ -79,20 +79,19 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_surjectionproof_parse( /** Serialize a surjection proof * * Returns: 1 if enough space was available to serialize, 0 otherwise - * Args: ctx: a secp256k1 context object - * Out: output: a pointer to an array to store the serialization - * In/Out: outputlen: a pointer to an integer which is initially set to the - * size of output, and is overwritten with the written - * size. - * In: proof: a pointer to an initialized proof object + * Args: ctx: pointer to a context object + * Out: output: pointer to an array to store the serialization + * In/Out: outputlen: pointer to an integer which is initially set to the size + * of output, and is overwritten with the written size. + * In: proof: pointer to an initialized proof object * - * See rustsecp256k1zkp_v0_8_0_surjectionproof_parse for details about the encoding. + * See rustsecp256k1zkp_v0_10_0_surjectionproof_parse for details about the encoding. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_surjectionproof_serialize( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_surjectionproof_serialize( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *output, size_t *outputlen, - const rustsecp256k1zkp_v0_8_0_surjectionproof *proof + const rustsecp256k1zkp_v0_10_0_surjectionproof *proof ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); /** Data structure that holds a fixed asset tag. @@ -103,43 +102,43 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_surjectionproof_serialize( */ typedef struct { unsigned char data[32]; -} rustsecp256k1zkp_v0_8_0_fixed_asset_tag; +} rustsecp256k1zkp_v0_10_0_fixed_asset_tag; /** Returns the total number of inputs a proof expects to be over. * * Returns: the number of inputs for the given proof * In: ctx: pointer to a context object - * proof: a pointer to a proof object + * proof: pointer to a proof object */ -SECP256K1_API size_t rustsecp256k1zkp_v0_8_0_surjectionproof_n_total_inputs( - const rustsecp256k1zkp_v0_8_0_context* ctx, - const rustsecp256k1zkp_v0_8_0_surjectionproof* proof +SECP256K1_API size_t rustsecp256k1zkp_v0_10_0_surjectionproof_n_total_inputs( + const rustsecp256k1zkp_v0_10_0_context *ctx, + const rustsecp256k1zkp_v0_10_0_surjectionproof *proof ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2); /** Returns the actual number of inputs that a proof uses * * Returns: the number of inputs for the given proof * In: ctx: pointer to a context object - * proof: a pointer to a proof object + * proof: pointer to a proof object */ -SECP256K1_API size_t rustsecp256k1zkp_v0_8_0_surjectionproof_n_used_inputs( - const rustsecp256k1zkp_v0_8_0_context* ctx, - const rustsecp256k1zkp_v0_8_0_surjectionproof* proof +SECP256K1_API size_t rustsecp256k1zkp_v0_10_0_surjectionproof_n_used_inputs( + const rustsecp256k1zkp_v0_10_0_context *ctx, + const rustsecp256k1zkp_v0_10_0_surjectionproof *proof ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2); /** Returns the total size this proof would take, in bytes, when serialized * * Returns: the total size * In: ctx: pointer to a context object - * proof: a pointer to a proof object + * proof: pointer to a proof object */ -SECP256K1_API size_t rustsecp256k1zkp_v0_8_0_surjectionproof_serialized_size( - const rustsecp256k1zkp_v0_8_0_context* ctx, - const rustsecp256k1zkp_v0_8_0_surjectionproof* proof +SECP256K1_API size_t rustsecp256k1zkp_v0_10_0_surjectionproof_serialized_size( + const rustsecp256k1zkp_v0_10_0_context *ctx, + const rustsecp256k1zkp_v0_10_0_surjectionproof *proof ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2); /** Surjection proof initialization function; decides on inputs to use - * To be used to initialize stack-allocated rustsecp256k1zkp_v0_8_0_surjectionproof struct + * To be used to initialize stack-allocated rustsecp256k1zkp_v0_10_0_surjectionproof struct * Returns 0: inputs could not be selected * n: inputs were selected after n iterations of random selection * @@ -156,19 +155,19 @@ SECP256K1_API size_t rustsecp256k1zkp_v0_8_0_surjectionproof_serialized_size( * limited to 256 the probability of giving up is smaller than * (255/256)^(n_input_tags_to_use*max_n_iterations). * - * random_seed32: a random seed to be used for input selection + * random_seed32: random seed to be used for input selection * Out: proof: The proof whose bitvector will be initialized. In case of failure, * the state of the proof is undefined. * input_index: The index of the actual input that is secretly mapped to the output */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_surjectionproof_initialize( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_surjectionproof* proof, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_surjectionproof_initialize( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_surjectionproof *proof, size_t *input_index, - const rustsecp256k1zkp_v0_8_0_fixed_asset_tag* fixed_input_tags, + const rustsecp256k1zkp_v0_10_0_fixed_asset_tag *fixed_input_tags, const size_t n_input_tags, const size_t n_input_tags_to_use, - const rustsecp256k1zkp_v0_8_0_fixed_asset_tag* fixed_output_tag, + const rustsecp256k1zkp_v0_10_0_fixed_asset_tag *fixed_output_tag, const size_t n_max_iterations, const unsigned char *random_seed32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(7); @@ -179,8 +178,8 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_surjectio * n: inputs were selected after n iterations of random selection * * In: ctx: pointer to a context object - * proof_out_p: a pointer to a pointer to `rustsecp256k1zkp_v0_8_0_surjectionproof*`. - * the newly-allocated struct pointer will be saved here. + * proof_out_p: pointer to a pointer to `rustsecp256k1zkp_v0_10_0_surjectionproof*`. + * The newly-allocated struct pointer will be saved here. * fixed_input_tags: fixed input tags `A_i` for all inputs. (If the fixed tag is not known, * e.g. in a coinjoin with others' inputs, an ephemeral tag can be given; * this won't match the output tag but might be used in the anonymity set.) @@ -192,51 +191,51 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_surjectio * limited to 256 the probability of giving up is smaller than * (255/256)^(n_input_tags_to_use*max_n_iterations). * - * random_seed32: a random seed to be used for input selection - * Out: proof_out_p: The pointer to newly-allocated proof whose bitvector will be initialized. + * random_seed32: random seed to be used for input selection + * Out: proof_out_p: pointer to newly-allocated proof whose bitvector will be initialized. * In case of failure, the pointer will be NULL. * input_index: The index of the actual input that is secretly mapped to the output */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_surjectionproof_allocate_initialized( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_surjectionproof** proof_out_p, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_surjectionproof_allocate_initialized( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_surjectionproof **proof_out_p, size_t *input_index, - const rustsecp256k1zkp_v0_8_0_fixed_asset_tag* fixed_input_tags, + const rustsecp256k1zkp_v0_10_0_fixed_asset_tag *fixed_input_tags, const size_t n_input_tags, const size_t n_input_tags_to_use, - const rustsecp256k1zkp_v0_8_0_fixed_asset_tag* fixed_output_tag, + const rustsecp256k1zkp_v0_10_0_fixed_asset_tag *fixed_output_tag, const size_t n_max_iterations, const unsigned char *random_seed32 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(7); /** Surjection proof destroy function - * deallocates the struct that was allocated with rustsecp256k1zkp_v0_8_0_surjectionproof_allocate_initialized + * deallocates the struct that was allocated with rustsecp256k1zkp_v0_10_0_surjectionproof_allocate_initialized * - * In: proof: pointer to rustsecp256k1zkp_v0_8_0_surjectionproof struct + * In: proof: pointer to rustsecp256k1zkp_v0_10_0_surjectionproof struct */ -SECP256K1_API void rustsecp256k1zkp_v0_8_0_surjectionproof_destroy( - rustsecp256k1zkp_v0_8_0_surjectionproof* proof +SECP256K1_API void rustsecp256k1zkp_v0_10_0_surjectionproof_destroy( + rustsecp256k1zkp_v0_10_0_surjectionproof *proof ) SECP256K1_ARG_NONNULL(1); /** Surjection proof generation function * Returns 0: proof could not be created * 1: proof was successfully created * - * In: ctx: pointer to a context object, initialized for signing and verification + * In: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static) * ephemeral_input_tags: the ephemeral asset tag of all inputs * n_ephemeral_input_tags: the number of entries in the ephemeral_input_tags array * ephemeral_output_tag: the ephemeral asset tag of the output * input_index: the index of the input that actually maps to the output * input_blinding_key: the blinding key of the input * output_blinding_key: the blinding key of the output - * In/Out: proof: The produced surjection proof. Must have already gone through `rustsecp256k1zkp_v0_8_0_surjectionproof_initialize` + * In/Out: proof: The produced surjection proof. Must have already gone through `rustsecp256k1zkp_v0_10_0_surjectionproof_initialize` */ -SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_surjectionproof_generate( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_surjectionproof* proof, - const rustsecp256k1zkp_v0_8_0_generator* ephemeral_input_tags, +SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_10_0_surjectionproof_generate( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_surjectionproof *proof, + const rustsecp256k1zkp_v0_10_0_generator *ephemeral_input_tags, size_t n_ephemeral_input_tags, - const rustsecp256k1zkp_v0_8_0_generator* ephemeral_output_tag, + const rustsecp256k1zkp_v0_10_0_generator *ephemeral_output_tag, size_t input_index, const unsigned char *input_blinding_key, const unsigned char *output_blinding_key @@ -248,18 +247,18 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int rustsecp256k1zkp_v0_8_0_surjectio * Returns 0: proof was invalid * 1: proof was valid * - * In: ctx: pointer to a context object, initialized for signing and verification + * In: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static) * proof: proof to be verified * ephemeral_input_tags: the ephemeral asset tag of all inputs * n_ephemeral_input_tags: the number of entries in the ephemeral_input_tags array * ephemeral_output_tag: the ephemeral asset tag of the output */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_surjectionproof_verify( - const rustsecp256k1zkp_v0_8_0_context* ctx, - const rustsecp256k1zkp_v0_8_0_surjectionproof* proof, - const rustsecp256k1zkp_v0_8_0_generator* ephemeral_input_tags, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_surjectionproof_verify( + const rustsecp256k1zkp_v0_10_0_context *ctx, + const rustsecp256k1zkp_v0_10_0_surjectionproof *proof, + const rustsecp256k1zkp_v0_10_0_generator *ephemeral_input_tags, size_t n_ephemeral_input_tags, - const rustsecp256k1zkp_v0_8_0_generator* ephemeral_output_tag + const rustsecp256k1zkp_v0_10_0_generator *ephemeral_output_tag ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(5); #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_whitelist.h b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_whitelist.h index 2031cb31..e12be56e 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_whitelist.h +++ b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1_whitelist.h @@ -4,8 +4,8 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef _SECP256K1_WHITELIST_ -#define _SECP256K1_WHITELIST_ +#ifndef SECP256K1_WHITELIST_H +#define SECP256K1_WHITELIST_H #include "secp256k1.h" @@ -23,26 +23,26 @@ extern "C" { * will have identical representation. (That is, memcmp may return nonzero * even for identical signatures.) * - * To obtain these properties, instead use rustsecp256k1zkp_v0_8_0_whitelist_signature_parse - * and rustsecp256k1zkp_v0_8_0_whitelist_signature_serialize to encode/decode signatures + * To obtain these properties, instead use rustsecp256k1zkp_v0_10_0_whitelist_signature_parse + * and rustsecp256k1zkp_v0_10_0_whitelist_signature_serialize to encode/decode signatures * into a well-defined format. * * The representation is exposed to allow creation of these objects on the * stack; please *do not* use these internals directly. To learn the number - * of keys for a signature, use `rustsecp256k1zkp_v0_8_0_whitelist_signature_n_keys`. + * of keys for a signature, use `rustsecp256k1zkp_v0_10_0_whitelist_signature_n_keys`. */ typedef struct { size_t n_keys; /* e0, scalars */ unsigned char data[32 * (1 + SECP256K1_WHITELIST_MAX_N_KEYS)]; -} rustsecp256k1zkp_v0_8_0_whitelist_signature; +} rustsecp256k1zkp_v0_10_0_whitelist_signature; /** Parse a whitelist signature * * Returns: 1 when the signature could be parsed, 0 otherwise. - * Args: ctx: a secp256k1 context object - * Out: sig: a pointer to a signature object - * In: input: a pointer to the array to parse + * Args: ctx: pointer to a context object + * Out: sig: pointer to a signature object + * In: input: pointer to the array to parse * input_len: the length of the above array * * The signature must consist of a 1-byte n_keys value, followed by a 32-byte @@ -57,9 +57,9 @@ typedef struct { * scalar values overflow or are zero, the resulting sig value is guaranteed * to fail validation for any set of keys. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_whitelist_signature_parse( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_whitelist_signature *sig, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_whitelist_signature_parse( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_whitelist_signature *sig, const unsigned char *input, size_t input_len ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); @@ -67,33 +67,33 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_whitelist_signature_parse( /** Returns the number of keys a signature expects to have. * * Returns: the number of keys for the given signature - * In: sig: a pointer to a signature object + * In: sig: pointer to a signature object */ -SECP256K1_API size_t rustsecp256k1zkp_v0_8_0_whitelist_signature_n_keys( - const rustsecp256k1zkp_v0_8_0_whitelist_signature *sig +SECP256K1_API size_t rustsecp256k1zkp_v0_10_0_whitelist_signature_n_keys( + const rustsecp256k1zkp_v0_10_0_whitelist_signature *sig ) SECP256K1_ARG_NONNULL(1); /** Serialize a whitelist signature * * Returns: 1 - * Args: ctx: a secp256k1 context object - * Out: output64: a pointer to an array to store the serialization + * Args: ctx: pointer to a context object + * Out: output64: pointer to an array to store the serialization * In/Out: output_len: length of the above array, updated with the actual serialized length - * In: sig: a pointer to an initialized signature object + * In: sig: pointer to an initialized signature object * - * See rustsecp256k1zkp_v0_8_0_whitelist_signature_parse for details about the encoding. + * See rustsecp256k1zkp_v0_10_0_whitelist_signature_parse for details about the encoding. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_whitelist_signature_serialize( - const rustsecp256k1zkp_v0_8_0_context* ctx, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_whitelist_signature_serialize( + const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *output, size_t *output_len, - const rustsecp256k1zkp_v0_8_0_whitelist_signature *sig + const rustsecp256k1zkp_v0_10_0_whitelist_signature *sig ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); /** Compute a whitelist signature * Returns 1: signature was successfully created * 0: signature was not successfully created - * In: ctx: pointer to a context object, initialized for signing and verification + * In: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static) * online_pubkeys: list of all online pubkeys * offline_pubkeys: list of all offline pubkeys * n_keys: the number of entries in each of the above two arrays @@ -110,13 +110,13 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_whitelist_signature_serialize( * for each public key pair (offline_i, offline_i). Here H means sha256 of the * compressed serialization of the key. */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_whitelist_sign( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_whitelist_signature *sig, - const rustsecp256k1zkp_v0_8_0_pubkey *online_pubkeys, - const rustsecp256k1zkp_v0_8_0_pubkey *offline_pubkeys, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_whitelist_sign( + const rustsecp256k1zkp_v0_10_0_context *ctx, + rustsecp256k1zkp_v0_10_0_whitelist_signature *sig, + const rustsecp256k1zkp_v0_10_0_pubkey *online_pubkeys, + const rustsecp256k1zkp_v0_10_0_pubkey *offline_pubkeys, const size_t n_keys, - const rustsecp256k1zkp_v0_8_0_pubkey *sub_pubkey, + const rustsecp256k1zkp_v0_10_0_pubkey *sub_pubkey, const unsigned char *online_seckey, const unsigned char *summed_seckeyx, const size_t index @@ -125,20 +125,20 @@ SECP256K1_API int rustsecp256k1zkp_v0_8_0_whitelist_sign( /** Verify a whitelist signature * Returns 1: signature is valid * 0: signature is not valid - * In: ctx: pointer to a context object, initialized for signing and verification + * In: ctx: pointer to a context object (not rustsecp256k1zkp_v0_10_0_context_static) * sig: the signature to be verified * online_pubkeys: list of all online pubkeys * offline_pubkeys: list of all offline pubkeys * n_keys: the number of entries in each of the above two arrays * sub_pubkey: the key to be whitelisted */ -SECP256K1_API int rustsecp256k1zkp_v0_8_0_whitelist_verify( - const rustsecp256k1zkp_v0_8_0_context* ctx, - const rustsecp256k1zkp_v0_8_0_whitelist_signature *sig, - const rustsecp256k1zkp_v0_8_0_pubkey *online_pubkeys, - const rustsecp256k1zkp_v0_8_0_pubkey *offline_pubkeys, +SECP256K1_API int rustsecp256k1zkp_v0_10_0_whitelist_verify( + const rustsecp256k1zkp_v0_10_0_context *ctx, + const rustsecp256k1zkp_v0_10_0_whitelist_signature *sig, + const rustsecp256k1zkp_v0_10_0_pubkey *online_pubkeys, + const rustsecp256k1zkp_v0_10_0_pubkey *offline_pubkeys, const size_t n_keys, - const rustsecp256k1zkp_v0_8_0_pubkey *sub_pubkey + const rustsecp256k1zkp_v0_10_0_pubkey *sub_pubkey ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(6); #ifdef __cplusplus diff --git a/secp256k1-zkp-sys/depend/secp256k1/libsecp256k1.pc.in b/secp256k1-zkp-sys/depend/secp256k1/libsecp256k1.pc.in index 694e98ee..0fb6f48a 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/libsecp256k1.pc.in +++ b/secp256k1-zkp-sys/depend/secp256k1/libsecp256k1.pc.in @@ -9,5 +9,4 @@ URL: https://github.com/bitcoin-core/secp256k1 Version: @PACKAGE_VERSION@ Cflags: -I${includedir} Libs: -L${libdir} -lsecp256k1 -Libs.private: @SECP_LIBS@ diff --git a/secp256k1-zkp-sys/depend/secp256k1/sage/gen_exhaustive_groups.sage b/secp256k1-zkp-sys/depend/secp256k1/sage/gen_exhaustive_groups.sage index 682e487e..d2826076 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/sage/gen_exhaustive_groups.sage +++ b/secp256k1-zkp-sys/depend/secp256k1/sage/gen_exhaustive_groups.sage @@ -1,124 +1,156 @@ -load("rustsecp256k1zkp_v0_8_0_params.sage") +load("rustsecp256k1zkp_v0_10_0_params.sage") +MAX_ORDER = 1000 + +# Set of (curve) orders we have encountered so far. orders_done = set() -results = {} -first = True + +# Map from (subgroup) orders to [b, int(gen.x), int(gen.y), gen, lambda] for those subgroups. +solutions = {} + +# Iterate over curves of the form y^2 = x^3 + B. for b in range(1, P): - # There are only 6 curves (up to isomorphism) of the form y^2=x^3+B. Stop once we have tried all. + # There are only 6 curves (up to isomorphism) of the form y^2 = x^3 + B. Stop once we have tried all. if len(orders_done) == 6: break E = EllipticCurve(F, [0, b]) print("Analyzing curve y^2 = x^3 + %i" % b) n = E.order() + # Skip curves with an order we've already tried if n in orders_done: print("- Isomorphic to earlier curve") + print() continue orders_done.add(n) + # Skip curves isomorphic to the real secp256k1 if n.is_pseudoprime(): - print(" - Isomorphic to secp256k1") + assert E.is_isomorphic(C) + print("- Isomorphic to secp256k1") + print() continue - print("- Finding subgroups") - - # Find what prime subgroups exist - for f, _ in n.factor(): - print("- Analyzing subgroup of order %i" % f) - # Skip subgroups of order >1000 - if f < 4 or f > 1000: - print(" - Bad size") - continue - - # Iterate over X coordinates until we find one that is on the curve, has order f, - # and for which curve isomorphism exists that maps it to X coordinate 1. - for x in range(1, P): - # Skip X coordinates not on the curve, and construct the full point otherwise. - if not E.is_x_coord(x): - continue - G = E.lift_x(F(x)) + print("- Finding prime subgroups") - print(" - Analyzing (multiples of) point with X=%i" % x) + # Map from group_order to a set of independent generators for that order. + curve_gens = {} - # Skip points whose order is not a multiple of f. Project the point to have - # order f otherwise. - if (G.order() % f): - print(" - Bad order") + for g in E.gens(): + # Find what prime subgroups of group generated by g exist. + g_order = g.order() + for f, _ in g.order().factor(): + # Skip subgroups that have bad size. + if f < 4: + print(f" - Subgroup of size {f}: too small") + continue + if f > MAX_ORDER: + print(f" - Subgroup of size {f}: too large") continue - G = G * (G.order() // f) + + # Construct a generator for that subgroup. + gen = g * (g_order // f) + assert(gen.order() == f) + + # Add to set the minimal multiple of gen. + curve_gens.setdefault(f, set()).add(min([j*gen for j in range(1, f)])) + print(f" - Subgroup of size {f}: ok") + + for f in sorted(curve_gens.keys()): + print(f"- Constructing group of order {f}") + cbrts = sorted([int(c) for c in Integers(f)(1).nth_root(3, all=true) if c != 1]) + gens = list(curve_gens[f]) + sol_count = 0 + no_endo_count = 0 + + # Consider all non-zero linear combinations of the independent generators. + for j in range(1, f**len(gens)): + gen = sum(gens[k] * ((j // f**k) % f) for k in range(len(gens))) + assert not gen.is_zero() + assert (f*gen).is_zero() # Find lambda for endomorphism. Skip if none can be found. lam = None - for l in Integers(f)(1).nth_root(3, all=True): - if int(l)*G == E(BETA*G[0], G[1]): - lam = int(l) + for l in cbrts: + if l*gen == E(BETA*gen[0], gen[1]): + lam = l break + if lam is None: - print(" - No endomorphism for this subgroup") - break - - # Now look for an isomorphism of the curve that gives this point an X - # coordinate equal to 1. - # If (x,y) is on y^2 = x^3 + b, then (a^2*x, a^3*y) is on y^2 = x^3 + a^6*b. - # So look for m=a^2=1/x. - m = F(1)/G[0] - if not m.is_square(): - print(" - No curve isomorphism maps it to a point with X=1") - continue - a = m.sqrt() - rb = a^6*b - RE = EllipticCurve(F, [0, rb]) - - # Use as generator twice the image of G under the above isormorphism. - # This means that generator*(1/2 mod f) will have X coordinate 1. - RG = RE(1, a^3*G[1]) * 2 - # And even Y coordinate. - if int(RG[1]) % 2: - RG = -RG - assert(RG.order() == f) - assert(lam*RG == RE(BETA*RG[0], RG[1])) - - # We have found curve RE:y^2=x^3+rb with generator RG of order f. Remember it - results[f] = {"b": rb, "G": RG, "lambda": lam} - print(" - Found solution") - break - - print("") - -print("") -print("") -print("/* To be put in src/group_impl.h: */") + no_endo_count += 1 + else: + sol_count += 1 + solutions.setdefault(f, []).append((b, int(gen[0]), int(gen[1]), gen, lam)) + + print(f" - Found {sol_count} generators (plus {no_endo_count} without endomorphism)") + + print() + +def output_generator(g, name): + print(f"#define {name} SECP256K1_GE_CONST(\\") + print(" 0x%08x, 0x%08x, 0x%08x, 0x%08x,\\" % tuple((int(g[0]) >> (32 * (7 - i))) & 0xffffffff for i in range(4))) + print(" 0x%08x, 0x%08x, 0x%08x, 0x%08x,\\" % tuple((int(g[0]) >> (32 * (7 - i))) & 0xffffffff for i in range(4, 8))) + print(" 0x%08x, 0x%08x, 0x%08x, 0x%08x,\\" % tuple((int(g[1]) >> (32 * (7 - i))) & 0xffffffff for i in range(4))) + print(" 0x%08x, 0x%08x, 0x%08x, 0x%08x\\" % tuple((int(g[1]) >> (32 * (7 - i))) & 0xffffffff for i in range(4, 8))) + print(")") + +def output_b(b): + print(f"#define SECP256K1_B {int(b)}") + +print() +print("To be put in src/group_impl.h:") +print() +print("/* Begin of section generated by sage/gen_exhaustive_groups.sage. */") +for f in sorted(solutions.keys()): + # Use as generator/2 the one with lowest b, and lowest (x, y) generator (interpreted as non-negative integers). + b, _, _, HALF_G, lam = min(solutions[f]) + output_generator(2 * HALF_G, f"SECP256K1_G_ORDER_{f}") +print("/** Generator for secp256k1, value 'g' defined in") +print(" * \"Standards for Efficient Cryptography\" (SEC2) 2.7.1.") +print(" */") +output_generator(G, "SECP256K1_G") +print("/* These exhaustive group test orders and generators are chosen such that:") +print(" * - The field size is equal to that of secp256k1, so field code is the same.") +print(" * - The curve equation is of the form y^2=x^3+B for some small constant B.") +print(" * - The subgroup has a generator 2*P, where P.x is as small as possible.") +print(f" * - The subgroup has size less than {MAX_ORDER} to permit exhaustive testing.") +print(" * - The subgroup admits an endomorphism of the form lambda*(x,y) == (beta*x,y).") +print(" */") +print("#if defined(EXHAUSTIVE_TEST_ORDER)") first = True -for f in sorted(results.keys()): - b = results[f]["b"] - G = results[f]["G"] - print("# %s EXHAUSTIVE_TEST_ORDER == %i" % ("if" if first else "elif", f)) +for f in sorted(solutions.keys()): + b, _, _, _, lam = min(solutions[f]) + print(f"# {'if' if first else 'elif'} EXHAUSTIVE_TEST_ORDER == {f}") first = False - print("static const rustsecp256k1zkp_v0_8_0_ge rustsecp256k1zkp_v0_8_0_ge_const_g = SECP256K1_GE_CONST(") - print(" 0x%08x, 0x%08x, 0x%08x, 0x%08x," % tuple((int(G[0]) >> (32 * (7 - i))) & 0xffffffff for i in range(4))) - print(" 0x%08x, 0x%08x, 0x%08x, 0x%08x," % tuple((int(G[0]) >> (32 * (7 - i))) & 0xffffffff for i in range(4, 8))) - print(" 0x%08x, 0x%08x, 0x%08x, 0x%08x," % tuple((int(G[1]) >> (32 * (7 - i))) & 0xffffffff for i in range(4))) - print(" 0x%08x, 0x%08x, 0x%08x, 0x%08x" % tuple((int(G[1]) >> (32 * (7 - i))) & 0xffffffff for i in range(4, 8))) - print(");") - print("static const rustsecp256k1zkp_v0_8_0_fe rustsecp256k1zkp_v0_8_0_fe_const_b = SECP256K1_FE_CONST(") - print(" 0x%08x, 0x%08x, 0x%08x, 0x%08x," % tuple((int(b) >> (32 * (7 - i))) & 0xffffffff for i in range(4))) - print(" 0x%08x, 0x%08x, 0x%08x, 0x%08x" % tuple((int(b) >> (32 * (7 - i))) & 0xffffffff for i in range(4, 8))) - print(");") + print() + print(f"static const rustsecp256k1zkp_v0_10_0_ge rustsecp256k1zkp_v0_10_0_ge_const_g = SECP256K1_G_ORDER_{f};") + output_b(b) + print() print("# else") print("# error No known generator for the specified exhaustive test group order.") print("# endif") +print("#else") +print() +print("static const rustsecp256k1zkp_v0_10_0_ge rustsecp256k1zkp_v0_10_0_ge_const_g = SECP256K1_G;") +output_b(7) +print() +print("#endif") +print("/* End of section generated by sage/gen_exhaustive_groups.sage. */") + -print("") -print("") -print("/* To be put in src/scalar_impl.h: */") +print() +print() +print("To be put in src/scalar_impl.h:") +print() +print("/* Begin of section generated by sage/gen_exhaustive_groups.sage. */") first = True -for f in sorted(results.keys()): - lam = results[f]["lambda"] +for f in sorted(solutions.keys()): + _, _, _, _, lam = min(solutions[f]) print("# %s EXHAUSTIVE_TEST_ORDER == %i" % ("if" if first else "elif", f)) first = False print("# define EXHAUSTIVE_TEST_LAMBDA %i" % lam) print("# else") print("# error No known lambda for the specified exhaustive test group order.") print("# endif") -print("") +print("/* End of section generated by sage/gen_exhaustive_groups.sage. */") diff --git a/secp256k1-zkp-sys/depend/secp256k1/sage/gen_split_lambda_constants.sage b/secp256k1-zkp-sys/depend/secp256k1/sage/gen_split_lambda_constants.sage index 5ef1b877..69715250 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/sage/gen_split_lambda_constants.sage +++ b/secp256k1-zkp-sys/depend/secp256k1/sage/gen_split_lambda_constants.sage @@ -1,9 +1,9 @@ -""" Generates the constants used in rustsecp256k1zkp_v0_8_0_scalar_split_lambda. +""" Generates the constants used in rustsecp256k1zkp_v0_10_0_scalar_split_lambda. -See the comments for rustsecp256k1zkp_v0_8_0_scalar_split_lambda in src/scalar_impl.h for detailed explanations. +See the comments for rustsecp256k1zkp_v0_10_0_scalar_split_lambda in src/scalar_impl.h for detailed explanations. """ -load("rustsecp256k1zkp_v0_8_0_params.sage") +load("rustsecp256k1zkp_v0_10_0_params.sage") def inf_norm(v): """Returns the infinity norm of a vector.""" @@ -24,17 +24,17 @@ def gauss_reduction(i1, i2): v2[1] -= m*v1[1] def find_split_constants_gauss(): - """Find constants for rustsecp256k1zkp_v0_8_0_scalar_split_lamdba using gauss reduction.""" + """Find constants for rustsecp256k1zkp_v0_10_0_scalar_split_lamdba using gauss reduction.""" (v11, v12), (v21, v22) = gauss_reduction([0, N], [1, int(LAMBDA)]) - # We use related vectors in rustsecp256k1zkp_v0_8_0_scalar_split_lambda. + # We use related vectors in rustsecp256k1zkp_v0_10_0_scalar_split_lambda. A1, B1 = -v21, -v11 A2, B2 = v22, -v21 return A1, B1, A2, B2 def find_split_constants_explicit_tof(): - """Find constants for rustsecp256k1zkp_v0_8_0_scalar_split_lamdba using the trace of Frobenius. + """Find constants for rustsecp256k1zkp_v0_10_0_scalar_split_lamdba using the trace of Frobenius. See Benjamin Smith: "Easy scalar decompositions for efficient scalar multiplication on elliptic curves and genus 2 Jacobians" (https://eprint.iacr.org/2013/672), Example 2 @@ -51,7 +51,7 @@ def find_split_constants_explicit_tof(): A2 = Integer((t + c)/2 - 1) B2 = Integer(1 - (t - c)/2) - # We use a negated b values in rustsecp256k1zkp_v0_8_0_scalar_split_lambda. + # We use a negated b values in rustsecp256k1zkp_v0_10_0_scalar_split_lambda. B1, B2 = -B1, -B2 return A1, B1, A2, B2 @@ -90,7 +90,7 @@ def rnddiv2(v): return v >> 1 def scalar_lambda_split(k): - """Equivalent to rustsecp256k1zkp_v0_8_0_scalar_lambda_split().""" + """Equivalent to rustsecp256k1zkp_v0_10_0_scalar_lambda_split().""" c1 = rnddiv2((k * G1) >> 383) c2 = rnddiv2((k * G2) >> 383) c1 = (c1 * -B1) % N diff --git a/secp256k1-zkp-sys/depend/secp256k1/sage/group_prover.sage b/secp256k1-zkp-sys/depend/secp256k1/sage/group_prover.sage index 9305c215..bb092953 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/sage/group_prover.sage +++ b/secp256k1-zkp-sys/depend/secp256k1/sage/group_prover.sage @@ -198,7 +198,7 @@ def normalize_factor(p): (8) * (-bx + ax)^3 ``` """ - # Assert p is not 0 and that its non-zero coeffients are coprime. + # Assert p is not 0 and that its non-zero coefficients are coprime. # (We could just work with the primitive part p/p.content() but we want to be # aware if factor() does not return a primitive part in future sage versions.) assert p.content() == 1 diff --git a/secp256k1-zkp-sys/depend/secp256k1/sage/prove_group_implementations.sage b/secp256k1-zkp-sys/depend/secp256k1/sage/prove_group_implementations.sage index 5f12a318..89419b80 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/sage/prove_group_implementations.sage +++ b/secp256k1-zkp-sys/depend/secp256k1/sage/prove_group_implementations.sage @@ -5,8 +5,8 @@ import sys load("group_prover.sage") load("weierstrass_prover.sage") -def formula_rustsecp256k1zkp_v0_8_0_gej_double_var(a): - """libsecp256k1's rustsecp256k1zkp_v0_8_0_gej_double_var, used by various addition functions""" +def formula_rustsecp256k1zkp_v0_10_0_gej_double_var(a): + """libsecp256k1's rustsecp256k1zkp_v0_10_0_gej_double_var, used by various addition functions""" rz = a.Z * a.Y s = a.Y^2 l = a.X^2 @@ -24,8 +24,8 @@ def formula_rustsecp256k1zkp_v0_8_0_gej_double_var(a): ry = -ry return jacobianpoint(rx, ry, rz) -def formula_rustsecp256k1zkp_v0_8_0_gej_add_var(branch, a, b): - """libsecp256k1's rustsecp256k1zkp_v0_8_0_gej_add_var""" +def formula_rustsecp256k1zkp_v0_10_0_gej_add_var(branch, a, b): + """libsecp256k1's rustsecp256k1zkp_v0_10_0_gej_add_var""" if branch == 0: return (constraints(), constraints(nonzero={a.Infinity : 'a_infinite'}), b) if branch == 1: @@ -40,34 +40,31 @@ def formula_rustsecp256k1zkp_v0_8_0_gej_add_var(branch, a, b): s2 = s2 * a.Z h = -u1 h = h + u2 - i = -s1 - i = i + s2 + i = -s2 + i = i + s1 if branch == 2: - r = formula_rustsecp256k1zkp_v0_8_0_gej_double_var(a) + r = formula_rustsecp256k1zkp_v0_10_0_gej_double_var(a) return (constraints(), constraints(zero={h : 'h=0', i : 'i=0', a.Infinity : 'a_finite', b.Infinity : 'b_finite'}), r) if branch == 3: return (constraints(), constraints(zero={h : 'h=0', a.Infinity : 'a_finite', b.Infinity : 'b_finite'}, nonzero={i : 'i!=0'}), point_at_infinity()) - i2 = i^2 + t = h * b.Z + rz = a.Z * t h2 = h^2 + h2 = -h2 h3 = h2 * h - h = h * b.Z - rz = a.Z * h t = u1 * h2 - rx = t - rx = rx * 2 + rx = i^2 rx = rx + h3 - rx = -rx - rx = rx + i2 - ry = -rx - ry = ry + t - ry = ry * i + rx = rx + t + rx = rx + t + t = t + rx + ry = t * i h3 = h3 * s1 - h3 = -h3 ry = ry + h3 return (constraints(), constraints(zero={a.Infinity : 'a_finite', b.Infinity : 'b_finite'}, nonzero={h : 'h!=0'}), jacobianpoint(rx, ry, rz)) -def formula_rustsecp256k1zkp_v0_8_0_gej_add_ge_var(branch, a, b): - """libsecp256k1's rustsecp256k1zkp_v0_8_0_gej_add_ge_var, which assume bz==1""" +def formula_rustsecp256k1zkp_v0_10_0_gej_add_ge_var(branch, a, b): + """libsecp256k1's rustsecp256k1zkp_v0_10_0_gej_add_ge_var, which assume bz==1""" if branch == 0: return (constraints(zero={b.Z - 1 : 'b.z=1'}), constraints(nonzero={a.Infinity : 'a_infinite'}), b) if branch == 1: @@ -80,43 +77,41 @@ def formula_rustsecp256k1zkp_v0_8_0_gej_add_ge_var(branch, a, b): s2 = s2 * a.Z h = -u1 h = h + u2 - i = -s1 - i = i + s2 + i = -s2 + i = i + s1 if (branch == 2): - r = formula_rustsecp256k1zkp_v0_8_0_gej_double_var(a) + r = formula_rustsecp256k1zkp_v0_10_0_gej_double_var(a) return (constraints(zero={b.Z - 1 : 'b.z=1'}), constraints(zero={a.Infinity : 'a_finite', b.Infinity : 'b_finite', h : 'h=0', i : 'i=0'}), r) if (branch == 3): return (constraints(zero={b.Z - 1 : 'b.z=1'}), constraints(zero={a.Infinity : 'a_finite', b.Infinity : 'b_finite', h : 'h=0'}, nonzero={i : 'i!=0'}), point_at_infinity()) - i2 = i^2 - h2 = h^2 - h3 = h * h2 rz = a.Z * h + h2 = h^2 + h2 = -h2 + h3 = h2 * h t = u1 * h2 - rx = t - rx = rx * 2 + rx = i^2 rx = rx + h3 - rx = -rx - rx = rx + i2 - ry = -rx - ry = ry + t - ry = ry * i + rx = rx + t + rx = rx + t + t = t + rx + ry = t * i h3 = h3 * s1 - h3 = -h3 ry = ry + h3 return (constraints(zero={b.Z - 1 : 'b.z=1'}), constraints(zero={a.Infinity : 'a_finite', b.Infinity : 'b_finite'}, nonzero={h : 'h!=0'}), jacobianpoint(rx, ry, rz)) -def formula_rustsecp256k1zkp_v0_8_0_gej_add_zinv_var(branch, a, b): - """libsecp256k1's rustsecp256k1zkp_v0_8_0_gej_add_zinv_var""" +def formula_rustsecp256k1zkp_v0_10_0_gej_add_zinv_var(branch, a, b): + """libsecp256k1's rustsecp256k1zkp_v0_10_0_gej_add_zinv_var""" bzinv = b.Z^(-1) if branch == 0: - return (constraints(), constraints(nonzero={b.Infinity : 'b_infinite'}), a) - if branch == 1: + rinf = b.Infinity bzinv2 = bzinv^2 bzinv3 = bzinv2 * bzinv rx = b.X * bzinv2 ry = b.Y * bzinv3 rz = 1 - return (constraints(), constraints(zero={b.Infinity : 'b_finite'}, nonzero={a.Infinity : 'a_infinite'}), jacobianpoint(rx, ry, rz)) + return (constraints(), constraints(nonzero={a.Infinity : 'a_infinite'}), jacobianpoint(rx, ry, rz, rinf)) + if branch == 1: + return (constraints(), constraints(zero={a.Infinity : 'a_finite'}, nonzero={b.Infinity : 'b_infinite'}), a) azz = a.Z * bzinv z12 = azz^2 u1 = a.X @@ -126,38 +121,34 @@ def formula_rustsecp256k1zkp_v0_8_0_gej_add_zinv_var(branch, a, b): s2 = s2 * azz h = -u1 h = h + u2 - i = -s1 - i = i + s2 + i = -s2 + i = i + s1 if branch == 2: - r = formula_rustsecp256k1zkp_v0_8_0_gej_double_var(a) + r = formula_rustsecp256k1zkp_v0_10_0_gej_double_var(a) return (constraints(), constraints(zero={a.Infinity : 'a_finite', b.Infinity : 'b_finite', h : 'h=0', i : 'i=0'}), r) if branch == 3: return (constraints(), constraints(zero={a.Infinity : 'a_finite', b.Infinity : 'b_finite', h : 'h=0'}, nonzero={i : 'i!=0'}), point_at_infinity()) - i2 = i^2 + rz = a.Z * h h2 = h^2 - h3 = h * h2 - rz = a.Z - rz = rz * h + h2 = -h2 + h3 = h2 * h t = u1 * h2 - rx = t - rx = rx * 2 + rx = i^2 rx = rx + h3 - rx = -rx - rx = rx + i2 - ry = -rx - ry = ry + t - ry = ry * i + rx = rx + t + rx = rx + t + t = t + rx + ry = t * i h3 = h3 * s1 - h3 = -h3 ry = ry + h3 return (constraints(), constraints(zero={a.Infinity : 'a_finite', b.Infinity : 'b_finite'}, nonzero={h : 'h!=0'}), jacobianpoint(rx, ry, rz)) -def formula_rustsecp256k1zkp_v0_8_0_gej_add_ge(branch, a, b): - """libsecp256k1's rustsecp256k1zkp_v0_8_0_gej_add_ge""" +def formula_rustsecp256k1zkp_v0_10_0_gej_add_ge(branch, a, b): + """libsecp256k1's rustsecp256k1zkp_v0_10_0_gej_add_ge""" zeroes = {} nonzeroes = {} a_infinity = False - if (branch & 4) != 0: + if (branch & 2) != 0: nonzeroes.update({a.Infinity : 'a_infinite'}) a_infinity = True else: @@ -176,15 +167,11 @@ def formula_rustsecp256k1zkp_v0_8_0_gej_add_ge(branch, a, b): m_alt = -u2 tt = u1 * m_alt rr = rr + tt - degenerate = (branch & 3) == 3 - if (branch & 1) != 0: + degenerate = (branch & 1) != 0 + if degenerate: zeroes.update({m : 'm_zero'}) else: nonzeroes.update({m : 'm_nonzero'}) - if (branch & 2) != 0: - zeroes.update({rr : 'rr_zero'}) - else: - nonzeroes.update({rr : 'rr_nonzero'}) rr_alt = s1 rr_alt = rr_alt * 2 m_alt = m_alt + u1 @@ -199,13 +186,6 @@ def formula_rustsecp256k1zkp_v0_8_0_gej_add_ge(branch, a, b): n = m t = rr_alt^2 rz = a.Z * m_alt - infinity = False - if (branch & 8) != 0: - if not a_infinity: - infinity = True - zeroes.update({rz : 'r.z=0'}) - else: - nonzeroes.update({rz : 'r.z!=0'}) t = t + q rx = t t = t * 2 @@ -218,12 +198,15 @@ def formula_rustsecp256k1zkp_v0_8_0_gej_add_ge(branch, a, b): rx = b.X ry = b.Y rz = 1 - if infinity: + if (branch & 4) != 0: + zeroes.update({rz : 'r.z = 0'}) return (constraints(zero={b.Z - 1 : 'b.z=1', b.Infinity : 'b_finite'}), constraints(zero=zeroes, nonzero=nonzeroes), point_at_infinity()) + else: + nonzeroes.update({rz : 'r.z != 0'}) return (constraints(zero={b.Z - 1 : 'b.z=1', b.Infinity : 'b_finite'}), constraints(zero=zeroes, nonzero=nonzeroes), jacobianpoint(rx, ry, rz)) -def formula_rustsecp256k1zkp_v0_8_0_gej_add_ge_old(branch, a, b): - """libsecp256k1's old rustsecp256k1zkp_v0_8_0_gej_add_ge, which fails when ay+by=0 but ax!=bx""" +def formula_rustsecp256k1zkp_v0_10_0_gej_add_ge_old(branch, a, b): + """libsecp256k1's old rustsecp256k1zkp_v0_10_0_gej_add_ge, which fails when ay+by=0 but ax!=bx""" a_infinity = (branch & 1) != 0 zero = {} nonzero = {} @@ -286,17 +269,17 @@ def formula_rustsecp256k1zkp_v0_8_0_gej_add_ge_old(branch, a, b): if __name__ == "__main__": success = True - success = success & check_symbolic_jacobian_weierstrass("rustsecp256k1zkp_v0_8_0_gej_add_var", 0, 7, 5, formula_rustsecp256k1zkp_v0_8_0_gej_add_var) - success = success & check_symbolic_jacobian_weierstrass("rustsecp256k1zkp_v0_8_0_gej_add_ge_var", 0, 7, 5, formula_rustsecp256k1zkp_v0_8_0_gej_add_ge_var) - success = success & check_symbolic_jacobian_weierstrass("rustsecp256k1zkp_v0_8_0_gej_add_zinv_var", 0, 7, 5, formula_rustsecp256k1zkp_v0_8_0_gej_add_zinv_var) - success = success & check_symbolic_jacobian_weierstrass("rustsecp256k1zkp_v0_8_0_gej_add_ge", 0, 7, 16, formula_rustsecp256k1zkp_v0_8_0_gej_add_ge) - success = success & (not check_symbolic_jacobian_weierstrass("rustsecp256k1zkp_v0_8_0_gej_add_ge_old [should fail]", 0, 7, 4, formula_rustsecp256k1zkp_v0_8_0_gej_add_ge_old)) + success = success & check_symbolic_jacobian_weierstrass("rustsecp256k1zkp_v0_10_0_gej_add_var", 0, 7, 5, formula_rustsecp256k1zkp_v0_10_0_gej_add_var) + success = success & check_symbolic_jacobian_weierstrass("rustsecp256k1zkp_v0_10_0_gej_add_ge_var", 0, 7, 5, formula_rustsecp256k1zkp_v0_10_0_gej_add_ge_var) + success = success & check_symbolic_jacobian_weierstrass("rustsecp256k1zkp_v0_10_0_gej_add_zinv_var", 0, 7, 5, formula_rustsecp256k1zkp_v0_10_0_gej_add_zinv_var) + success = success & check_symbolic_jacobian_weierstrass("rustsecp256k1zkp_v0_10_0_gej_add_ge", 0, 7, 8, formula_rustsecp256k1zkp_v0_10_0_gej_add_ge) + success = success & (not check_symbolic_jacobian_weierstrass("rustsecp256k1zkp_v0_10_0_gej_add_ge_old [should fail]", 0, 7, 4, formula_rustsecp256k1zkp_v0_10_0_gej_add_ge_old)) if len(sys.argv) >= 2 and sys.argv[1] == "--exhaustive": - success = success & check_exhaustive_jacobian_weierstrass("rustsecp256k1zkp_v0_8_0_gej_add_var", 0, 7, 5, formula_rustsecp256k1zkp_v0_8_0_gej_add_var, 43) - success = success & check_exhaustive_jacobian_weierstrass("rustsecp256k1zkp_v0_8_0_gej_add_ge_var", 0, 7, 5, formula_rustsecp256k1zkp_v0_8_0_gej_add_ge_var, 43) - success = success & check_exhaustive_jacobian_weierstrass("rustsecp256k1zkp_v0_8_0_gej_add_zinv_var", 0, 7, 5, formula_rustsecp256k1zkp_v0_8_0_gej_add_zinv_var, 43) - success = success & check_exhaustive_jacobian_weierstrass("rustsecp256k1zkp_v0_8_0_gej_add_ge", 0, 7, 16, formula_rustsecp256k1zkp_v0_8_0_gej_add_ge, 43) - success = success & (not check_exhaustive_jacobian_weierstrass("rustsecp256k1zkp_v0_8_0_gej_add_ge_old [should fail]", 0, 7, 4, formula_rustsecp256k1zkp_v0_8_0_gej_add_ge_old, 43)) + success = success & check_exhaustive_jacobian_weierstrass("rustsecp256k1zkp_v0_10_0_gej_add_var", 0, 7, 5, formula_rustsecp256k1zkp_v0_10_0_gej_add_var, 43) + success = success & check_exhaustive_jacobian_weierstrass("rustsecp256k1zkp_v0_10_0_gej_add_ge_var", 0, 7, 5, formula_rustsecp256k1zkp_v0_10_0_gej_add_ge_var, 43) + success = success & check_exhaustive_jacobian_weierstrass("rustsecp256k1zkp_v0_10_0_gej_add_zinv_var", 0, 7, 5, formula_rustsecp256k1zkp_v0_10_0_gej_add_zinv_var, 43) + success = success & check_exhaustive_jacobian_weierstrass("rustsecp256k1zkp_v0_10_0_gej_add_ge", 0, 7, 8, formula_rustsecp256k1zkp_v0_10_0_gej_add_ge, 43) + success = success & (not check_exhaustive_jacobian_weierstrass("rustsecp256k1zkp_v0_10_0_gej_add_ge_old [should fail]", 0, 7, 4, formula_rustsecp256k1zkp_v0_10_0_gej_add_ge_old, 43)) sys.exit(int(not success)) diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/asm/field_10x26_arm.s b/secp256k1-zkp-sys/depend/secp256k1/src/asm/field_10x26_arm.s index c80043e8..e6e7b24e 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/asm/field_10x26_arm.s +++ b/secp256k1-zkp-sys/depend/secp256k1/src/asm/field_10x26_arm.s @@ -27,8 +27,9 @@ Note: .set field_not_M, 0xfc000000 @ ~M = ~0x3ffffff .align 2 - .global rustsecp256k1zkp_v0_8_0_fe_mul_inner - .type rustsecp256k1zkp_v0_8_0_fe_mul_inner, %function + .global rustsecp256k1zkp_v0_10_0_fe_mul_inner + .type rustsecp256k1zkp_v0_10_0_fe_mul_inner, %function + .hidden rustsecp256k1zkp_v0_10_0_fe_mul_inner @ Arguments: @ r0 r Restrict: can overlap with a, not with b @ r1 a @@ -36,7 +37,7 @@ Note: @ Stack (total 4+10*4 = 44) @ sp + #0 saved 'r' pointer @ sp + #4 + 4*X t0,t1,t2,t3,t4,t5,t6,t7,u8,t9 -rustsecp256k1zkp_v0_8_0_fe_mul_inner: +rustsecp256k1zkp_v0_10_0_fe_mul_inner: stmfd sp!, {r4, r5, r6, r7, r8, r9, r10, r11, r14} sub sp, sp, #48 @ frame=44 + alignment str r0, [sp, #0] @ save result address, we need it only at the end @@ -511,18 +512,19 @@ rustsecp256k1zkp_v0_8_0_fe_mul_inner: add sp, sp, #48 ldmfd sp!, {r4, r5, r6, r7, r8, r9, r10, r11, pc} - .size rustsecp256k1zkp_v0_8_0_fe_mul_inner, .-rustsecp256k1zkp_v0_8_0_fe_mul_inner + .size rustsecp256k1zkp_v0_10_0_fe_mul_inner, .-rustsecp256k1zkp_v0_10_0_fe_mul_inner .align 2 - .global rustsecp256k1zkp_v0_8_0_fe_sqr_inner - .type rustsecp256k1zkp_v0_8_0_fe_sqr_inner, %function + .global rustsecp256k1zkp_v0_10_0_fe_sqr_inner + .type rustsecp256k1zkp_v0_10_0_fe_sqr_inner, %function + .hidden rustsecp256k1zkp_v0_10_0_fe_sqr_inner @ Arguments: @ r0 r Can overlap with a @ r1 a @ Stack (total 4+10*4 = 44) @ sp + #0 saved 'r' pointer @ sp + #4 + 4*X t0,t1,t2,t3,t4,t5,t6,t7,u8,t9 -rustsecp256k1zkp_v0_8_0_fe_sqr_inner: +rustsecp256k1zkp_v0_10_0_fe_sqr_inner: stmfd sp!, {r4, r5, r6, r7, r8, r9, r10, r11, r14} sub sp, sp, #48 @ frame=44 + alignment str r0, [sp, #0] @ save result address, we need it only at the end @@ -909,5 +911,6 @@ rustsecp256k1zkp_v0_8_0_fe_sqr_inner: add sp, sp, #48 ldmfd sp!, {r4, r5, r6, r7, r8, r9, r10, r11, pc} - .size rustsecp256k1zkp_v0_8_0_fe_sqr_inner, .-rustsecp256k1zkp_v0_8_0_fe_sqr_inner + .size rustsecp256k1zkp_v0_10_0_fe_sqr_inner, .-rustsecp256k1zkp_v0_10_0_fe_sqr_inner + .section .note.GNU-stack,"",%progbits diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/assumptions.h b/secp256k1-zkp-sys/depend/secp256k1/src/assumptions.h index 083c8059..754041a0 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/assumptions.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/assumptions.h @@ -10,71 +10,78 @@ #include #include "util.h" +#if defined(SECP256K1_INT128_NATIVE) +#include "int128_native.h" +#endif /* This library, like most software, relies on a number of compiler implementation defined (but not undefined) behaviours. Although the behaviours we require are essentially universal we test them specifically here to reduce the odds of experiencing an unwelcome surprise. */ -struct rustsecp256k1zkp_v0_8_0_assumption_checker { - /* This uses a trick to implement a static assertion in C89: a type with an array of negative size is not - allowed. */ - int dummy_array[( - /* Bytes are 8 bits. */ - (CHAR_BIT == 8) && +#if defined(__has_attribute) +# if __has_attribute(__unavailable__) +__attribute__((__unavailable__("Don't call this function. It only exists because STATIC_ASSERT cannot be used outside a function."))) +# endif +#endif +static void rustsecp256k1zkp_v0_10_0_assumption_checker(void) { + /* Bytes are 8 bits. */ + STATIC_ASSERT(CHAR_BIT == 8); - /* No integer promotion for uint32_t. This ensures that we can multiply uintXX_t values where XX >= 32 - without signed overflow, which would be undefined behaviour. */ - (UINT_MAX <= UINT32_MAX) && + /* No integer promotion for uint32_t. This ensures that we can multiply uintXX_t values where XX >= 32 + without signed overflow, which would be undefined behaviour. */ + STATIC_ASSERT(UINT_MAX <= UINT32_MAX); - /* Conversions from unsigned to signed outside of the bounds of the signed type are - implementation-defined. Verify that they function as reinterpreting the lower - bits of the input in two's complement notation. Do this for conversions: - - from uint(N)_t to int(N)_t with negative result - - from uint(2N)_t to int(N)_t with negative result - - from int(2N)_t to int(N)_t with negative result - - from int(2N)_t to int(N)_t with positive result */ + /* Conversions from unsigned to signed outside of the bounds of the signed type are + implementation-defined. Verify that they function as reinterpreting the lower + bits of the input in two's complement notation. Do this for conversions: + - from uint(N)_t to int(N)_t with negative result + - from uint(2N)_t to int(N)_t with negative result + - from int(2N)_t to int(N)_t with negative result + - from int(2N)_t to int(N)_t with positive result */ - /* To int8_t. */ - ((int8_t)(uint8_t)0xAB == (int8_t)-(int8_t)0x55) && - ((int8_t)(uint16_t)0xABCD == (int8_t)-(int8_t)0x33) && - ((int8_t)(int16_t)(uint16_t)0xCDEF == (int8_t)(uint8_t)0xEF) && - ((int8_t)(int16_t)(uint16_t)0x9234 == (int8_t)(uint8_t)0x34) && + /* To int8_t. */ + STATIC_ASSERT(((int8_t)(uint8_t)0xAB == (int8_t)-(int8_t)0x55)); + STATIC_ASSERT((int8_t)(uint16_t)0xABCD == (int8_t)-(int8_t)0x33); + STATIC_ASSERT((int8_t)(int16_t)(uint16_t)0xCDEF == (int8_t)(uint8_t)0xEF); + STATIC_ASSERT((int8_t)(int16_t)(uint16_t)0x9234 == (int8_t)(uint8_t)0x34); - /* To int16_t. */ - ((int16_t)(uint16_t)0xBCDE == (int16_t)-(int16_t)0x4322) && - ((int16_t)(uint32_t)0xA1B2C3D4 == (int16_t)-(int16_t)0x3C2C) && - ((int16_t)(int32_t)(uint32_t)0xC1D2E3F4 == (int16_t)(uint16_t)0xE3F4) && - ((int16_t)(int32_t)(uint32_t)0x92345678 == (int16_t)(uint16_t)0x5678) && + /* To int16_t. */ + STATIC_ASSERT((int16_t)(uint16_t)0xBCDE == (int16_t)-(int16_t)0x4322); + STATIC_ASSERT((int16_t)(uint32_t)0xA1B2C3D4 == (int16_t)-(int16_t)0x3C2C); + STATIC_ASSERT((int16_t)(int32_t)(uint32_t)0xC1D2E3F4 == (int16_t)(uint16_t)0xE3F4); + STATIC_ASSERT((int16_t)(int32_t)(uint32_t)0x92345678 == (int16_t)(uint16_t)0x5678); - /* To int32_t. */ - ((int32_t)(uint32_t)0xB2C3D4E5 == (int32_t)-(int32_t)0x4D3C2B1B) && - ((int32_t)(uint64_t)0xA123B456C789D012ULL == (int32_t)-(int32_t)0x38762FEE) && - ((int32_t)(int64_t)(uint64_t)0xC1D2E3F4A5B6C7D8ULL == (int32_t)(uint32_t)0xA5B6C7D8) && - ((int32_t)(int64_t)(uint64_t)0xABCDEF0123456789ULL == (int32_t)(uint32_t)0x23456789) && + /* To int32_t. */ + STATIC_ASSERT((int32_t)(uint32_t)0xB2C3D4E5 == (int32_t)-(int32_t)0x4D3C2B1B); + STATIC_ASSERT((int32_t)(uint64_t)0xA123B456C789D012ULL == (int32_t)-(int32_t)0x38762FEE); + STATIC_ASSERT((int32_t)(int64_t)(uint64_t)0xC1D2E3F4A5B6C7D8ULL == (int32_t)(uint32_t)0xA5B6C7D8); + STATIC_ASSERT((int32_t)(int64_t)(uint64_t)0xABCDEF0123456789ULL == (int32_t)(uint32_t)0x23456789); - /* To int64_t. */ - ((int64_t)(uint64_t)0xB123C456D789E012ULL == (int64_t)-(int64_t)0x4EDC3BA928761FEEULL) && -#if defined(SECP256K1_WIDEMUL_INT128) - ((int64_t)(((uint128_t)0xA1234567B8901234ULL << 64) + 0xC5678901D2345678ULL) == (int64_t)-(int64_t)0x3A9876FE2DCBA988ULL) && - (((int64_t)(int128_t)(((uint128_t)0xB1C2D3E4F5A6B7C8ULL << 64) + 0xD9E0F1A2B3C4D5E6ULL)) == (int64_t)(uint64_t)0xD9E0F1A2B3C4D5E6ULL) && - (((int64_t)(int128_t)(((uint128_t)0xABCDEF0123456789ULL << 64) + 0x0123456789ABCDEFULL)) == (int64_t)(uint64_t)0x0123456789ABCDEFULL) && + /* To int64_t. */ + STATIC_ASSERT((int64_t)(uint64_t)0xB123C456D789E012ULL == (int64_t)-(int64_t)0x4EDC3BA928761FEEULL); +#if defined(SECP256K1_INT128_NATIVE) + STATIC_ASSERT((int64_t)(((uint128_t)0xA1234567B8901234ULL << 64) + 0xC5678901D2345678ULL) == (int64_t)-(int64_t)0x3A9876FE2DCBA988ULL); + STATIC_ASSERT(((int64_t)(int128_t)(((uint128_t)0xB1C2D3E4F5A6B7C8ULL << 64) + 0xD9E0F1A2B3C4D5E6ULL)) == (int64_t)(uint64_t)0xD9E0F1A2B3C4D5E6ULL); + STATIC_ASSERT(((int64_t)(int128_t)(((uint128_t)0xABCDEF0123456789ULL << 64) + 0x0123456789ABCDEFULL)) == (int64_t)(uint64_t)0x0123456789ABCDEFULL); - /* To int128_t. */ - ((int128_t)(((uint128_t)0xB1234567C8901234ULL << 64) + 0xD5678901E2345678ULL) == (int128_t)(-(int128_t)0x8E1648B3F50E80DCULL * 0x8E1648B3F50E80DDULL + 0x5EA688D5482F9464ULL)) && + /* To int128_t. */ + STATIC_ASSERT((int128_t)(((uint128_t)0xB1234567C8901234ULL << 64) + 0xD5678901E2345678ULL) == (int128_t)(-(int128_t)0x8E1648B3F50E80DCULL * 0x8E1648B3F50E80DDULL + 0x5EA688D5482F9464ULL)); #endif - /* Right shift on negative signed values is implementation defined. Verify that it - acts as a right shift in two's complement with sign extension (i.e duplicating - the top bit into newly added bits). */ - ((((int8_t)0xE8) >> 2) == (int8_t)(uint8_t)0xFA) && - ((((int16_t)0xE9AC) >> 4) == (int16_t)(uint16_t)0xFE9A) && - ((((int32_t)0x937C918A) >> 9) == (int32_t)(uint32_t)0xFFC9BE48) && - ((((int64_t)0xA8B72231DF9CF4B9ULL) >> 19) == (int64_t)(uint64_t)0xFFFFF516E4463BF3ULL) && -#if defined(SECP256K1_WIDEMUL_INT128) - ((((int128_t)(((uint128_t)0xCD833A65684A0DBCULL << 64) + 0xB349312F71EA7637ULL)) >> 39) == (int128_t)(((uint128_t)0xFFFFFFFFFF9B0674ULL << 64) + 0xCAD0941B79669262ULL)) && + /* Right shift on negative signed values is implementation defined. Verify that it + acts as a right shift in two's complement with sign extension (i.e duplicating + the top bit into newly added bits). */ + STATIC_ASSERT((((int8_t)0xE8) >> 2) == (int8_t)(uint8_t)0xFA); + STATIC_ASSERT((((int16_t)0xE9AC) >> 4) == (int16_t)(uint16_t)0xFE9A); + STATIC_ASSERT((((int32_t)0x937C918A) >> 9) == (int32_t)(uint32_t)0xFFC9BE48); + STATIC_ASSERT((((int64_t)0xA8B72231DF9CF4B9ULL) >> 19) == (int64_t)(uint64_t)0xFFFFF516E4463BF3ULL); +#if defined(SECP256K1_INT128_NATIVE) + STATIC_ASSERT((((int128_t)(((uint128_t)0xCD833A65684A0DBCULL << 64) + 0xB349312F71EA7637ULL)) >> 39) == (int128_t)(((uint128_t)0xFFFFFFFFFF9B0674ULL << 64) + 0xCAD0941B79669262ULL)); #endif - 1) * 2 - 1]; -}; + + /* This function is not supposed to be called. */ + VERIFY_CHECK(0); +} #endif /* SECP256K1_ASSUMPTIONS_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/basic-config.h b/secp256k1-zkp-sys/depend/secp256k1/src/basic-config.h deleted file mode 100644 index 6f7693cb..00000000 --- a/secp256k1-zkp-sys/depend/secp256k1/src/basic-config.h +++ /dev/null @@ -1,17 +0,0 @@ -/*********************************************************************** - * Copyright (c) 2013, 2014 Pieter Wuille * - * Distributed under the MIT software license, see the accompanying * - * file COPYING or https://www.opensource.org/licenses/mit-license.php.* - ***********************************************************************/ - -#ifndef SECP256K1_BASIC_CONFIG_H -#define SECP256K1_BASIC_CONFIG_H - -#ifdef USE_BASIC_CONFIG - -#define ECMULT_WINDOW_SIZE 15 -#define ECMULT_GEN_PREC_BITS 4 - -#endif /* USE_BASIC_CONFIG */ - -#endif /* SECP256K1_BASIC_CONFIG_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/bench.c b/secp256k1-zkp-sys/depend/secp256k1/src/bench.c index 42fb1309..1014c344 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/bench.c +++ b/secp256k1-zkp-sys/depend/secp256k1/src/bench.c @@ -11,7 +11,7 @@ #include "util.h" #include "bench.h" -void help(int default_iters) { +static void help(int default_iters) { printf("Benchmarks the following algorithms:\n"); printf(" - ECDSA signing/verification\n"); @@ -38,6 +38,8 @@ void help(int default_iters) { printf(" ecdsa : all ECDSA algorithms--sign, verify, recovery (if enabled)\n"); printf(" ecdsa_sign : ECDSA siging algorithm\n"); printf(" ecdsa_verify : ECDSA verification algorithm\n"); + printf(" ec : all EC public key algorithms (keygen)\n"); + printf(" ec_keygen : EC public key generation\n"); #ifdef ENABLE_MODULE_RECOVERY printf(" ecdsa_recover : ECDSA public key recovery algorithm\n"); @@ -53,47 +55,49 @@ void help(int default_iters) { printf(" schnorrsig_verify : Schnorr verification algorithm\n"); #endif +#ifdef ENABLE_MODULE_ELLSWIFT + printf(" ellswift : all ElligatorSwift benchmarks (encode, decode, keygen, ecdh)\n"); + printf(" ellswift_encode : ElligatorSwift encoding\n"); + printf(" ellswift_decode : ElligatorSwift decoding\n"); + printf(" ellswift_keygen : ElligatorSwift key generation\n"); + printf(" ellswift_ecdh : ECDH on ElligatorSwift keys\n"); +#endif + printf("\n"); } typedef struct { - rustsecp256k1zkp_v0_8_0_context *ctx; + rustsecp256k1zkp_v0_10_0_context *ctx; unsigned char msg[32]; unsigned char key[32]; unsigned char sig[72]; size_t siglen; unsigned char pubkey[33]; size_t pubkeylen; -} bench_verify_data; +} bench_data; static void bench_verify(void* arg, int iters) { int i; - bench_verify_data* data = (bench_verify_data*)arg; + bench_data* data = (bench_data*)arg; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_pubkey pubkey; - rustsecp256k1zkp_v0_8_0_ecdsa_signature sig; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_ecdsa_signature sig; data->sig[data->siglen - 1] ^= (i & 0xFF); data->sig[data->siglen - 2] ^= ((i >> 8) & 0xFF); data->sig[data->siglen - 3] ^= ((i >> 16) & 0xFF); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(data->ctx, &pubkey, data->pubkey, data->pubkeylen) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(data->ctx, &sig, data->sig, data->siglen) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(data->ctx, &sig, data->msg, &pubkey) == (i == 0)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(data->ctx, &pubkey, data->pubkey, data->pubkeylen) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(data->ctx, &sig, data->sig, data->siglen) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(data->ctx, &sig, data->msg, &pubkey) == (i == 0)); data->sig[data->siglen - 1] ^= (i & 0xFF); data->sig[data->siglen - 2] ^= ((i >> 8) & 0xFF); data->sig[data->siglen - 3] ^= ((i >> 16) & 0xFF); } } -typedef struct { - rustsecp256k1zkp_v0_8_0_context* ctx; - unsigned char msg[32]; - unsigned char key[32]; -} bench_sign_data; - static void bench_sign_setup(void* arg) { int i; - bench_sign_data *data = (bench_sign_data*)arg; + bench_data *data = (bench_data*)arg; for (i = 0; i < 32; i++) { data->msg[i] = i + 1; @@ -105,15 +109,15 @@ static void bench_sign_setup(void* arg) { static void bench_sign_run(void* arg, int iters) { int i; - bench_sign_data *data = (bench_sign_data*)arg; + bench_data *data = (bench_data*)arg; unsigned char sig[74]; for (i = 0; i < iters; i++) { size_t siglen = 74; int j; - rustsecp256k1zkp_v0_8_0_ecdsa_signature signature; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(data->ctx, &signature, data->msg, data->key, NULL, NULL)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_der(data->ctx, sig, &siglen, &signature)); + rustsecp256k1zkp_v0_10_0_ecdsa_signature signature; + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(data->ctx, &signature, data->msg, data->key, NULL, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_der(data->ctx, sig, &siglen, &signature)); for (j = 0; j < 32; j++) { data->msg[j] = sig[j]; data->key[j] = sig[j + 32]; @@ -121,6 +125,30 @@ static void bench_sign_run(void* arg, int iters) { } } +static void bench_keygen_setup(void* arg) { + int i; + bench_data *data = (bench_data*)arg; + + for (i = 0; i < 32; i++) { + data->key[i] = i + 65; + } +} + +static void bench_keygen_run(void *arg, int iters) { + int i; + bench_data *data = (bench_data*)arg; + + for (i = 0; i < iters; i++) { + unsigned char pub33[33]; + size_t len = 33; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(data->ctx, &pubkey, data->key)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(data->ctx, pub33, &len, &pubkey, SECP256K1_EC_COMPRESSED)); + memcpy(data->key, pub33 + 1, 32); + } +} + + #ifdef ENABLE_MODULE_ECDH #include "modules/ecdh/bench_impl.h" #endif @@ -133,11 +161,15 @@ static void bench_sign_run(void* arg, int iters) { #include "modules/schnorrsig/bench_impl.h" #endif +#ifdef ENABLE_MODULE_ELLSWIFT +#include "modules/ellswift/bench_impl.h" +#endif + int main(int argc, char** argv) { int i; - rustsecp256k1zkp_v0_8_0_pubkey pubkey; - rustsecp256k1zkp_v0_8_0_ecdsa_signature sig; - bench_verify_data data; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_ecdsa_signature sig; + bench_data data; int d = argc == 1; int default_iters = 20000; @@ -145,7 +177,9 @@ int main(int argc, char** argv) { /* Check for invalid user arguments */ char* valid_args[] = {"ecdsa", "verify", "ecdsa_verify", "sign", "ecdsa_sign", "ecdh", "recover", - "ecdsa_recover", "schnorrsig", "schnorrsig_verify", "schnorrsig_sign"}; + "ecdsa_recover", "schnorrsig", "schnorrsig_verify", "schnorrsig_sign", "ec", + "keygen", "ec_keygen", "ellswift", "encode", "ellswift_encode", "decode", + "ellswift_decode", "ellswift_keygen", "ellswift_ecdh"}; size_t valid_args_size = sizeof(valid_args)/sizeof(valid_args[0]); int invalid_args = have_invalid_args(argc, argv, valid_args, valid_args_size); @@ -164,7 +198,7 @@ int main(int argc, char** argv) { /* Check if the user tries to benchmark optional module without building it */ #ifndef ENABLE_MODULE_ECDH - if (have_flag(argc, argv, "ecdh")) { + if (have_flag(argc, argv, "ecdh")) { fprintf(stderr, "./bench: ECDH module not enabled.\n"); fprintf(stderr, "Use ./configure --enable-module-ecdh.\n\n"); return 1; @@ -172,7 +206,7 @@ int main(int argc, char** argv) { #endif #ifndef ENABLE_MODULE_RECOVERY - if (have_flag(argc, argv, "recover") || have_flag(argc, argv, "ecdsa_recover")) { + if (have_flag(argc, argv, "recover") || have_flag(argc, argv, "ecdsa_recover")) { fprintf(stderr, "./bench: Public key recovery module not enabled.\n"); fprintf(stderr, "Use ./configure --enable-module-recovery.\n\n"); return 1; @@ -180,15 +214,25 @@ int main(int argc, char** argv) { #endif #ifndef ENABLE_MODULE_SCHNORRSIG - if (have_flag(argc, argv, "schnorrsig") || have_flag(argc, argv, "schnorrsig_sign") || have_flag(argc, argv, "schnorrsig_verify")) { + if (have_flag(argc, argv, "schnorrsig") || have_flag(argc, argv, "schnorrsig_sign") || have_flag(argc, argv, "schnorrsig_verify")) { fprintf(stderr, "./bench: Schnorr signatures module not enabled.\n"); fprintf(stderr, "Use ./configure --enable-module-schnorrsig.\n\n"); return 1; } #endif - /* ECDSA verification benchmark */ - data.ctx = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); +#ifndef ENABLE_MODULE_ELLSWIFT + if (have_flag(argc, argv, "ellswift") || have_flag(argc, argv, "ellswift_encode") || have_flag(argc, argv, "ellswift_decode") || + have_flag(argc, argv, "encode") || have_flag(argc, argv, "decode") || have_flag(argc, argv, "ellswift_keygen") || + have_flag(argc, argv, "ellswift_ecdh")) { + fprintf(stderr, "./bench: ElligatorSwift module not enabled.\n"); + fprintf(stderr, "Use ./configure --enable-module-ellswift.\n\n"); + return 1; + } +#endif + + /* ECDSA benchmark */ + data.ctx = rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_CONTEXT_NONE); for (i = 0; i < 32; i++) { data.msg[i] = 1 + i; @@ -197,23 +241,19 @@ int main(int argc, char** argv) { data.key[i] = 33 + i; } data.siglen = 72; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(data.ctx, &sig, data.msg, data.key, NULL, NULL)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_der(data.ctx, data.sig, &data.siglen, &sig)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(data.ctx, &pubkey, data.key)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(data.ctx, &sig, data.msg, data.key, NULL, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_der(data.ctx, data.sig, &data.siglen, &sig)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(data.ctx, &pubkey, data.key)); data.pubkeylen = 33; - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(data.ctx, data.pubkey, &data.pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(data.ctx, data.pubkey, &data.pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED) == 1); print_output_table_header_row(); if (d || have_flag(argc, argv, "ecdsa") || have_flag(argc, argv, "verify") || have_flag(argc, argv, "ecdsa_verify")) run_benchmark("ecdsa_verify", bench_verify, NULL, NULL, &data, 10, iters); - rustsecp256k1zkp_v0_8_0_context_destroy(data.ctx); - - /* ECDSA signing benchmark */ - data.ctx = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN); - if (d || have_flag(argc, argv, "ecdsa") || have_flag(argc, argv, "sign") || have_flag(argc, argv, "ecdsa_sign")) run_benchmark("ecdsa_sign", bench_sign_run, bench_sign_setup, NULL, &data, 10, iters); + if (d || have_flag(argc, argv, "ec") || have_flag(argc, argv, "keygen") || have_flag(argc, argv, "ec_keygen")) run_benchmark("ec_keygen", bench_keygen_run, bench_keygen_setup, NULL, &data, 10, iters); - rustsecp256k1zkp_v0_8_0_context_destroy(data.ctx); + rustsecp256k1zkp_v0_10_0_context_destroy(data.ctx); #ifdef ENABLE_MODULE_ECDH /* ECDH benchmarks */ @@ -230,5 +270,10 @@ int main(int argc, char** argv) { run_schnorrsig_bench(iters, argc, argv); #endif +#ifdef ENABLE_MODULE_ELLSWIFT + /* ElligatorSwift benchmarks */ + run_ellswift_bench(iters, argc, argv); +#endif + return 0; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/bench.h b/secp256k1-zkp-sys/depend/secp256k1/src/bench.h index aa275fe9..1564b1a1 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/bench.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/bench.h @@ -7,22 +7,38 @@ #ifndef SECP256K1_BENCH_H #define SECP256K1_BENCH_H +#include #include #include #include -#include "sys/time.h" + +#if (defined(_MSC_VER) && _MSC_VER >= 1900) +# include +#else +# include +#endif static int64_t gettime_i64(void) { +#if (defined(_MSC_VER) && _MSC_VER >= 1900) + /* C11 way to get wallclock time */ + struct timespec tv; + if (!timespec_get(&tv, TIME_UTC)) { + fputs("timespec_get failed!", stderr); + exit(1); + } + return (int64_t)tv.tv_nsec / 1000 + (int64_t)tv.tv_sec * 1000000LL; +#else struct timeval tv; gettimeofday(&tv, NULL); return (int64_t)tv.tv_usec + (int64_t)tv.tv_sec * 1000000LL; +#endif } #define FP_EXP (6) #define FP_MULT (1000000LL) /* Format fixed point number. */ -void print_number(const int64_t x) { +static void print_number(const int64_t x) { int64_t x_abs, y; int c, i, rounding, g; /* g = integer part size, c = fractional part size */ size_t ptr; @@ -79,7 +95,7 @@ void print_number(const int64_t x) { printf("%-*s", FP_EXP, &buffer[ptr + g]); /* Prints fractional part */ } -void run_benchmark(char *name, void (*benchmark)(void*, int), void (*setup)(void*), void (*teardown)(void*, int), void* data, int count, int iter) { +static void run_benchmark(char *name, void (*benchmark)(void*, int), void (*setup)(void*), void (*teardown)(void*, int), void* data, int count, int iter) { int i; int64_t min = INT64_MAX; int64_t sum = 0; @@ -113,7 +129,7 @@ void run_benchmark(char *name, void (*benchmark)(void*, int), void (*setup)(void printf("\n"); } -int have_flag(int argc, char** argv, char *flag) { +static int have_flag(int argc, char** argv, char *flag) { char** argm = argv + argc; argv++; while (argv != argm) { @@ -129,7 +145,7 @@ int have_flag(int argc, char** argv, char *flag) { returns: - 1 if the user entered an invalid argument - 0 if all the user entered arguments are valid */ -int have_invalid_args(int argc, char** argv, char** valid_args, size_t n) { +static int have_invalid_args(int argc, char** argv, char** valid_args, size_t n) { size_t i; int found_valid; char** argm = argv + argc; @@ -151,7 +167,7 @@ int have_invalid_args(int argc, char** argv, char** valid_args, size_t n) { return 0; } -int get_iters(int default_iters) { +static int get_iters(int default_iters) { char* env = getenv("SECP256K1_BENCH_ITERS"); if (env) { return strtol(env, NULL, 0); @@ -160,7 +176,7 @@ int get_iters(int default_iters) { } } -void print_output_table_header_row(void) { +static void print_output_table_header_row(void) { char* bench_str = "Benchmark"; /* left justified */ char* min_str = " Min(us) "; /* center alignment */ char* avg_str = " Avg(us) "; diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/bench_bppp.c b/secp256k1-zkp-sys/depend/secp256k1/src/bench_bppp.c index b696bfb5..b17951c1 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/bench_bppp.c +++ b/secp256k1-zkp-sys/depend/secp256k1/src/bench_bppp.c @@ -6,12 +6,12 @@ #include -#include "include/secp256k1_bppp.h" +#include "../include/secp256k1_bppp.h" #include "util.h" #include "bench.h" typedef struct { - rustsecp256k1zkp_v0_8_0_context* ctx; + rustsecp256k1zkp_v0_10_0_context* ctx; } bench_bppp_data; static void bench_bppp_setup(void* arg) { @@ -29,10 +29,10 @@ int main(void) { bench_bppp_data data; int iters = get_iters(32); - data.ctx = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); + data.ctx = rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_CONTEXT_NONE); run_benchmark("bppp_verify_bit", bench_bppp, bench_bppp_setup, NULL, &data, 10, iters); - rustsecp256k1zkp_v0_8_0_context_destroy(data.ctx); + rustsecp256k1zkp_v0_10_0_context_destroy(data.ctx); return 0; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/bench_ecmult.c b/secp256k1-zkp-sys/depend/secp256k1/src/bench_ecmult.c index b6353cee..d4b9fdfa 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/bench_ecmult.c +++ b/secp256k1-zkp-sys/depend/secp256k1/src/bench_ecmult.c @@ -18,7 +18,7 @@ #define POINTS 32768 -void help(char **argv) { +static void help(char **argv) { printf("Benchmark EC multiplication algorithms\n"); printf("\n"); printf("Usage: %s \n", argv[0]); @@ -35,14 +35,14 @@ void help(char **argv) { typedef struct { /* Setup once in advance */ - rustsecp256k1zkp_v0_8_0_context* ctx; - rustsecp256k1zkp_v0_8_0_scratch_space* scratch; - rustsecp256k1zkp_v0_8_0_scalar* scalars; - rustsecp256k1zkp_v0_8_0_ge* pubkeys; - rustsecp256k1zkp_v0_8_0_gej* pubkeys_gej; - rustsecp256k1zkp_v0_8_0_scalar* seckeys; - rustsecp256k1zkp_v0_8_0_gej* expected_output; - rustsecp256k1zkp_v0_8_0_ecmult_multi_func ecmult_multi; + rustsecp256k1zkp_v0_10_0_context* ctx; + rustsecp256k1zkp_v0_10_0_scratch_space* scratch; + rustsecp256k1zkp_v0_10_0_scalar* scalars; + rustsecp256k1zkp_v0_10_0_ge* pubkeys; + rustsecp256k1zkp_v0_10_0_gej* pubkeys_gej; + rustsecp256k1zkp_v0_10_0_scalar* seckeys; + rustsecp256k1zkp_v0_10_0_gej* expected_output; + rustsecp256k1zkp_v0_10_0_ecmult_multi_func ecmult_multi; /* Changes per benchmark */ size_t count; @@ -54,7 +54,7 @@ typedef struct { size_t offset2; /* Benchmark output. */ - rustsecp256k1zkp_v0_8_0_gej* output; + rustsecp256k1zkp_v0_10_0_gej* output; } bench_data; /* Hashes x into [0, POINTS) twice and store the result in offset1 and offset2. */ @@ -67,26 +67,24 @@ static void hash_into_offset(bench_data* data, size_t x) { * sum(outputs) ?= (sum(scalars_gen) + sum(seckeys)*sum(scalars))*G */ static void bench_ecmult_teardown_helper(bench_data* data, size_t* seckey_offset, size_t* scalar_offset, size_t* scalar_gen_offset, int iters) { int i; - rustsecp256k1zkp_v0_8_0_gej sum_output, tmp; - rustsecp256k1zkp_v0_8_0_scalar sum_scalars; + rustsecp256k1zkp_v0_10_0_gej sum_output, tmp; + rustsecp256k1zkp_v0_10_0_scalar sum_scalars; - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&sum_output); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sum_scalars); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&sum_output); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sum_scalars); for (i = 0; i < iters; ++i) { - rustsecp256k1zkp_v0_8_0_gej_add_var(&sum_output, &sum_output, &data->output[i], NULL); + rustsecp256k1zkp_v0_10_0_gej_add_var(&sum_output, &sum_output, &data->output[i], NULL); if (scalar_gen_offset != NULL) { - rustsecp256k1zkp_v0_8_0_scalar_add(&sum_scalars, &sum_scalars, &data->scalars[(*scalar_gen_offset+i) % POINTS]); + rustsecp256k1zkp_v0_10_0_scalar_add(&sum_scalars, &sum_scalars, &data->scalars[(*scalar_gen_offset+i) % POINTS]); } if (seckey_offset != NULL) { - rustsecp256k1zkp_v0_8_0_scalar s = data->seckeys[(*seckey_offset+i) % POINTS]; - rustsecp256k1zkp_v0_8_0_scalar_mul(&s, &s, &data->scalars[(*scalar_offset+i) % POINTS]); - rustsecp256k1zkp_v0_8_0_scalar_add(&sum_scalars, &sum_scalars, &s); + rustsecp256k1zkp_v0_10_0_scalar s = data->seckeys[(*seckey_offset+i) % POINTS]; + rustsecp256k1zkp_v0_10_0_scalar_mul(&s, &s, &data->scalars[(*scalar_offset+i) % POINTS]); + rustsecp256k1zkp_v0_10_0_scalar_add(&sum_scalars, &sum_scalars, &s); } } - rustsecp256k1zkp_v0_8_0_ecmult_gen(&data->ctx->ecmult_gen_ctx, &tmp, &sum_scalars); - rustsecp256k1zkp_v0_8_0_gej_neg(&tmp, &tmp); - rustsecp256k1zkp_v0_8_0_gej_add_var(&tmp, &tmp, &sum_output, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&tmp)); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&data->ctx->ecmult_gen_ctx, &tmp, &sum_scalars); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_var(&tmp, &sum_output)); } static void bench_ecmult_setup(void* arg) { @@ -101,7 +99,7 @@ static void bench_ecmult_gen(void* arg, int iters) { int i; for (i = 0; i < iters; ++i) { - rustsecp256k1zkp_v0_8_0_ecmult_gen(&data->ctx->ecmult_gen_ctx, &data->output[i], &data->scalars[(data->offset1+i) % POINTS]); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&data->ctx->ecmult_gen_ctx, &data->output[i], &data->scalars[(data->offset1+i) % POINTS]); } } @@ -115,7 +113,7 @@ static void bench_ecmult_const(void* arg, int iters) { int i; for (i = 0; i < iters; ++i) { - rustsecp256k1zkp_v0_8_0_ecmult_const(&data->output[i], &data->pubkeys[(data->offset1+i) % POINTS], &data->scalars[(data->offset2+i) % POINTS], 256); + rustsecp256k1zkp_v0_10_0_ecmult_const(&data->output[i], &data->pubkeys[(data->offset1+i) % POINTS], &data->scalars[(data->offset2+i) % POINTS]); } } @@ -129,7 +127,7 @@ static void bench_ecmult_1p(void* arg, int iters) { int i; for (i = 0; i < iters; ++i) { - rustsecp256k1zkp_v0_8_0_ecmult(&data->output[i], &data->pubkeys_gej[(data->offset1+i) % POINTS], &data->scalars[(data->offset2+i) % POINTS], NULL); + rustsecp256k1zkp_v0_10_0_ecmult(&data->output[i], &data->pubkeys_gej[(data->offset1+i) % POINTS], &data->scalars[(data->offset2+i) % POINTS], NULL); } } @@ -140,12 +138,10 @@ static void bench_ecmult_1p_teardown(void* arg, int iters) { static void bench_ecmult_0p_g(void* arg, int iters) { bench_data* data = (bench_data*)arg; - rustsecp256k1zkp_v0_8_0_scalar zero; int i; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&zero, 0); for (i = 0; i < iters; ++i) { - rustsecp256k1zkp_v0_8_0_ecmult(&data->output[i], NULL, &zero, &data->scalars[(data->offset1+i) % POINTS]); + rustsecp256k1zkp_v0_10_0_ecmult(&data->output[i], NULL, &rustsecp256k1zkp_v0_10_0_scalar_zero, &data->scalars[(data->offset1+i) % POINTS]); } } @@ -159,7 +155,7 @@ static void bench_ecmult_1p_g(void* arg, int iters) { int i; for (i = 0; i < iters/2; ++i) { - rustsecp256k1zkp_v0_8_0_ecmult(&data->output[i], &data->pubkeys_gej[(data->offset1+i) % POINTS], &data->scalars[(data->offset2+i) % POINTS], &data->scalars[(data->offset1+i) % POINTS]); + rustsecp256k1zkp_v0_10_0_ecmult(&data->output[i], &data->pubkeys_gej[(data->offset1+i) % POINTS], &data->scalars[(data->offset2+i) % POINTS], &data->scalars[(data->offset1+i) % POINTS]); } } @@ -185,12 +181,12 @@ static void run_ecmult_bench(bench_data* data, int iters) { run_benchmark(str, bench_ecmult_1p_g, bench_ecmult_setup, bench_ecmult_1p_g_teardown, data, 10, 2*iters); } -static int bench_ecmult_multi_callback(rustsecp256k1zkp_v0_8_0_scalar* sc, rustsecp256k1zkp_v0_8_0_ge* ge, size_t idx, void* arg) { +static int bench_ecmult_multi_callback(rustsecp256k1zkp_v0_10_0_scalar* sc, rustsecp256k1zkp_v0_10_0_ge* ge, size_t idx, void* arg) { bench_data* data = (bench_data*)arg; if (data->includes_g) ++idx; if (idx == 0) { *sc = data->scalars[data->offset1]; - *ge = rustsecp256k1zkp_v0_8_0_ge_const_g; + *ge = rustsecp256k1zkp_v0_10_0_ge_const_g; } else { *sc = data->scalars[(data->offset1 + idx) % POINTS]; *ge = data->pubkeys[(data->offset2 + idx - 1) % POINTS]; @@ -224,14 +220,14 @@ static void bench_ecmult_multi_teardown(void* arg, int iters) { iters = iters / data->count; /* Verify the results in teardown, to avoid doing comparisons while benchmarking. */ for (iter = 0; iter < iters; ++iter) { - rustsecp256k1zkp_v0_8_0_gej tmp; - rustsecp256k1zkp_v0_8_0_gej_add_var(&tmp, &data->output[iter], &data->expected_output[iter], NULL); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&tmp)); + rustsecp256k1zkp_v0_10_0_gej tmp; + rustsecp256k1zkp_v0_10_0_gej_add_var(&tmp, &data->output[iter], &data->expected_output[iter], NULL); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&tmp)); } } -static void generate_scalar(uint32_t num, rustsecp256k1zkp_v0_8_0_scalar* scalar) { - rustsecp256k1zkp_v0_8_0_sha256 sha256; +static void generate_scalar(uint32_t num, rustsecp256k1zkp_v0_10_0_scalar* scalar) { + rustsecp256k1zkp_v0_10_0_sha256 sha256; unsigned char c[10] = {'e', 'c', 'm', 'u', 'l', 't', 0, 0, 0, 0}; unsigned char buf[32]; int overflow = 0; @@ -239,16 +235,15 @@ static void generate_scalar(uint32_t num, rustsecp256k1zkp_v0_8_0_scalar* scalar c[7] = num >> 8; c[8] = num >> 16; c[9] = num >> 24; - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha256); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256, c, sizeof(c)); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha256, buf); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(scalar, buf, &overflow); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha256); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256, c, sizeof(c)); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha256, buf); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(scalar, buf, &overflow); CHECK(!overflow); } static void run_ecmult_multi_bench(bench_data* data, size_t count, int includes_g, int num_iters) { char str[32]; - static const rustsecp256k1zkp_v0_8_0_scalar zero = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0); size_t iters = 1 + num_iters / count; size_t iter; @@ -258,15 +253,15 @@ static void run_ecmult_multi_bench(bench_data* data, size_t count, int includes_ /* Compute (the negation of) the expected results directly. */ hash_into_offset(data, data->count); for (iter = 0; iter < iters; ++iter) { - rustsecp256k1zkp_v0_8_0_scalar tmp; - rustsecp256k1zkp_v0_8_0_scalar total = data->scalars[(data->offset1++) % POINTS]; + rustsecp256k1zkp_v0_10_0_scalar tmp; + rustsecp256k1zkp_v0_10_0_scalar total = data->scalars[(data->offset1++) % POINTS]; size_t i = 0; for (i = 0; i + 1 < count; ++i) { - rustsecp256k1zkp_v0_8_0_scalar_mul(&tmp, &data->seckeys[(data->offset2++) % POINTS], &data->scalars[(data->offset1++) % POINTS]); - rustsecp256k1zkp_v0_8_0_scalar_add(&total, &total, &tmp); + rustsecp256k1zkp_v0_10_0_scalar_mul(&tmp, &data->seckeys[(data->offset2++) % POINTS], &data->scalars[(data->offset1++) % POINTS]); + rustsecp256k1zkp_v0_10_0_scalar_add(&total, &total, &tmp); } - rustsecp256k1zkp_v0_8_0_scalar_negate(&total, &total); - rustsecp256k1zkp_v0_8_0_ecmult(&data->expected_output[iter], NULL, &zero, &total); + rustsecp256k1zkp_v0_10_0_scalar_negate(&total, &total); + rustsecp256k1zkp_v0_10_0_ecmult(&data->expected_output[iter], NULL, &rustsecp256k1zkp_v0_10_0_scalar_zero, &total); } /* Run the benchmark. */ @@ -285,7 +280,7 @@ int main(int argc, char **argv) { int iters = get_iters(10000); - data.ecmult_multi = rustsecp256k1zkp_v0_8_0_ecmult_multi_var; + data.ecmult_multi = rustsecp256k1zkp_v0_10_0_ecmult_multi_var; if (argc > 1) { if(have_flag(argc, argv, "-h") @@ -295,10 +290,10 @@ int main(int argc, char **argv) { return 0; } else if(have_flag(argc, argv, "pippenger_wnaf")) { printf("Using pippenger_wnaf:\n"); - data.ecmult_multi = rustsecp256k1zkp_v0_8_0_ecmult_pippenger_batch_single; + data.ecmult_multi = rustsecp256k1zkp_v0_10_0_ecmult_pippenger_batch_single; } else if(have_flag(argc, argv, "strauss_wnaf")) { printf("Using strauss_wnaf:\n"); - data.ecmult_multi = rustsecp256k1zkp_v0_8_0_ecmult_strauss_batch_single; + data.ecmult_multi = rustsecp256k1zkp_v0_10_0_ecmult_strauss_batch_single; } else if(have_flag(argc, argv, "simple")) { printf("Using simple algorithm:\n"); } else { @@ -308,33 +303,33 @@ int main(int argc, char **argv) { } } - data.ctx = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); - scratch_size = rustsecp256k1zkp_v0_8_0_strauss_scratch_size(POINTS) + STRAUSS_SCRATCH_OBJECTS*16; + data.ctx = rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_CONTEXT_NONE); + scratch_size = rustsecp256k1zkp_v0_10_0_strauss_scratch_size(POINTS) + STRAUSS_SCRATCH_OBJECTS*16; if (!have_flag(argc, argv, "simple")) { - data.scratch = rustsecp256k1zkp_v0_8_0_scratch_space_create(data.ctx, scratch_size); + data.scratch = rustsecp256k1zkp_v0_10_0_scratch_space_create(data.ctx, scratch_size); } else { data.scratch = NULL; } /* Allocate stuff */ - data.scalars = malloc(sizeof(rustsecp256k1zkp_v0_8_0_scalar) * POINTS); - data.seckeys = malloc(sizeof(rustsecp256k1zkp_v0_8_0_scalar) * POINTS); - data.pubkeys = malloc(sizeof(rustsecp256k1zkp_v0_8_0_ge) * POINTS); - data.pubkeys_gej = malloc(sizeof(rustsecp256k1zkp_v0_8_0_gej) * POINTS); - data.expected_output = malloc(sizeof(rustsecp256k1zkp_v0_8_0_gej) * (iters + 1)); - data.output = malloc(sizeof(rustsecp256k1zkp_v0_8_0_gej) * (iters + 1)); + data.scalars = malloc(sizeof(rustsecp256k1zkp_v0_10_0_scalar) * POINTS); + data.seckeys = malloc(sizeof(rustsecp256k1zkp_v0_10_0_scalar) * POINTS); + data.pubkeys = malloc(sizeof(rustsecp256k1zkp_v0_10_0_ge) * POINTS); + data.pubkeys_gej = malloc(sizeof(rustsecp256k1zkp_v0_10_0_gej) * POINTS); + data.expected_output = malloc(sizeof(rustsecp256k1zkp_v0_10_0_gej) * (iters + 1)); + data.output = malloc(sizeof(rustsecp256k1zkp_v0_10_0_gej) * (iters + 1)); /* Generate a set of scalars, and private/public keypairs. */ - rustsecp256k1zkp_v0_8_0_gej_set_ge(&data.pubkeys_gej[0], &rustsecp256k1zkp_v0_8_0_ge_const_g); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&data.seckeys[0], 1); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&data.pubkeys_gej[0], &rustsecp256k1zkp_v0_10_0_ge_const_g); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&data.seckeys[0], 1); for (i = 0; i < POINTS; ++i) { generate_scalar(i, &data.scalars[i]); if (i) { - rustsecp256k1zkp_v0_8_0_gej_double_var(&data.pubkeys_gej[i], &data.pubkeys_gej[i - 1], NULL); - rustsecp256k1zkp_v0_8_0_scalar_add(&data.seckeys[i], &data.seckeys[i - 1], &data.seckeys[i - 1]); + rustsecp256k1zkp_v0_10_0_gej_double_var(&data.pubkeys_gej[i], &data.pubkeys_gej[i - 1], NULL); + rustsecp256k1zkp_v0_10_0_scalar_add(&data.seckeys[i], &data.seckeys[i - 1], &data.seckeys[i - 1]); } } - rustsecp256k1zkp_v0_8_0_ge_set_all_gej_var(data.pubkeys, data.pubkeys_gej, POINTS); + rustsecp256k1zkp_v0_10_0_ge_set_all_gej_var(data.pubkeys, data.pubkeys_gej, POINTS); print_output_table_header_row(); @@ -358,9 +353,9 @@ int main(int argc, char **argv) { } if (data.scratch != NULL) { - rustsecp256k1zkp_v0_8_0_scratch_space_destroy(data.ctx, data.scratch); + rustsecp256k1zkp_v0_10_0_scratch_space_destroy(data.ctx, data.scratch); } - rustsecp256k1zkp_v0_8_0_context_destroy(data.ctx); + rustsecp256k1zkp_v0_10_0_context_destroy(data.ctx); free(data.scalars); free(data.pubkeys); free(data.pubkeys_gej); diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/bench_generator.c b/secp256k1-zkp-sys/depend/secp256k1/src/bench_generator.c index a2c2dc83..b3f873db 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/bench_generator.c +++ b/secp256k1-zkp-sys/depend/secp256k1/src/bench_generator.c @@ -7,12 +7,12 @@ #include #include -#include "include/secp256k1_generator.h" +#include "../include/secp256k1_generator.h" #include "util.h" #include "bench.h" typedef struct { - rustsecp256k1zkp_v0_8_0_context* ctx; + rustsecp256k1zkp_v0_10_0_context* ctx; unsigned char key[32]; unsigned char blind[32]; } bench_generator_t; @@ -28,8 +28,8 @@ static void bench_generator_generate(void* arg, int iters) { bench_generator_t *data = (bench_generator_t*)arg; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_generator gen; - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate(data->ctx, &gen, data->key)); + rustsecp256k1zkp_v0_10_0_generator gen; + CHECK(rustsecp256k1zkp_v0_10_0_generator_generate(data->ctx, &gen, data->key)); data->key[i & 31]++; } } @@ -39,8 +39,8 @@ static void bench_generator_generate_blinded(void* arg, int iters) { bench_generator_t *data = (bench_generator_t*)arg; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_generator gen; - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate_blinded(data->ctx, &gen, data->key, data->blind)); + rustsecp256k1zkp_v0_10_0_generator gen; + CHECK(rustsecp256k1zkp_v0_10_0_generator_generate_blinded(data->ctx, &gen, data->key, data->blind)); data->key[1 + (i & 30)]++; data->blind[1 + (i & 30)]++; } @@ -50,11 +50,11 @@ int main(void) { bench_generator_t data; int iters = get_iters(20000); - data.ctx = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); + data.ctx = rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_CONTEXT_NONE); run_benchmark("generator_generate", bench_generator_generate, bench_generator_setup, NULL, &data, 10, iters); run_benchmark("generator_generate_blinded", bench_generator_generate_blinded, bench_generator_setup, NULL, &data, 10, iters); - rustsecp256k1zkp_v0_8_0_context_destroy(data.ctx); + rustsecp256k1zkp_v0_10_0_context_destroy(data.ctx); return 0; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/bench_internal.c b/secp256k1-zkp-sys/depend/secp256k1/src/bench_internal.c index 4f6a4e53..81ba113a 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/bench_internal.c +++ b/secp256k1-zkp-sys/depend/secp256k1/src/bench_internal.c @@ -14,20 +14,38 @@ #include "field_impl.h" #include "group_impl.h" #include "scalar_impl.h" -#include "ecmult_const_impl.h" #include "ecmult_impl.h" #include "bench.h" +static void help(int default_iters) { + printf("Benchmarks various internal routines.\n"); + printf("\n"); + printf("The default number of iterations for each benchmark is %d. This can be\n", default_iters); + printf("customized using the SECP256K1_BENCH_ITERS environment variable.\n"); + printf("\n"); + printf("Usage: ./bench_internal [args]\n"); + printf("By default, all benchmarks will be run.\n"); + printf("args:\n"); + printf(" help : display this help and exit\n"); + printf(" scalar : all scalar operations (add, half, inverse, mul, negate, split)\n"); + printf(" field : all field operations (half, inverse, issquare, mul, normalize, sqr, sqrt)\n"); + printf(" group : all group operations (add, double, to_affine)\n"); + printf(" ecmult : all point multiplication operations (ecmult_wnaf) \n"); + printf(" hash : all hash algorithms (hmac, rng6979, sha256)\n"); + printf(" context : all context object operations (context_create)\n"); + printf("\n"); +} + typedef struct { - rustsecp256k1zkp_v0_8_0_scalar scalar[2]; - rustsecp256k1zkp_v0_8_0_fe fe[4]; - rustsecp256k1zkp_v0_8_0_ge ge[2]; - rustsecp256k1zkp_v0_8_0_gej gej[2]; + rustsecp256k1zkp_v0_10_0_scalar scalar[2]; + rustsecp256k1zkp_v0_10_0_fe fe[4]; + rustsecp256k1zkp_v0_10_0_ge ge[2]; + rustsecp256k1zkp_v0_10_0_gej gej[2]; unsigned char data[64]; int wnaf[256]; } bench_inv; -void bench_setup(void* arg) { +static void bench_setup(void* arg) { bench_inv *data = (bench_inv*)arg; static const unsigned char init[4][32] = { @@ -63,326 +81,352 @@ void bench_setup(void* arg) { } }; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&data->scalar[0], init[0], NULL); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&data->scalar[1], init[1], NULL); - rustsecp256k1zkp_v0_8_0_fe_set_b32(&data->fe[0], init[0]); - rustsecp256k1zkp_v0_8_0_fe_set_b32(&data->fe[1], init[1]); - rustsecp256k1zkp_v0_8_0_fe_set_b32(&data->fe[2], init[2]); - rustsecp256k1zkp_v0_8_0_fe_set_b32(&data->fe[3], init[3]); - CHECK(rustsecp256k1zkp_v0_8_0_ge_set_xo_var(&data->ge[0], &data->fe[0], 0)); - CHECK(rustsecp256k1zkp_v0_8_0_ge_set_xo_var(&data->ge[1], &data->fe[1], 1)); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&data->gej[0], &data->ge[0]); - rustsecp256k1zkp_v0_8_0_gej_rescale(&data->gej[0], &data->fe[2]); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&data->gej[1], &data->ge[1]); - rustsecp256k1zkp_v0_8_0_gej_rescale(&data->gej[1], &data->fe[3]); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&data->scalar[0], init[0], NULL); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&data->scalar[1], init[1], NULL); + rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&data->fe[0], init[0]); + rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&data->fe[1], init[1]); + rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&data->fe[2], init[2]); + rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&data->fe[3], init[3]); + CHECK(rustsecp256k1zkp_v0_10_0_ge_set_xo_var(&data->ge[0], &data->fe[0], 0)); + CHECK(rustsecp256k1zkp_v0_10_0_ge_set_xo_var(&data->ge[1], &data->fe[1], 1)); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&data->gej[0], &data->ge[0]); + rustsecp256k1zkp_v0_10_0_gej_rescale(&data->gej[0], &data->fe[2]); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&data->gej[1], &data->ge[1]); + rustsecp256k1zkp_v0_10_0_gej_rescale(&data->gej[1], &data->fe[3]); memcpy(data->data, init[0], 32); memcpy(data->data + 32, init[1], 32); } -void bench_scalar_add(void* arg, int iters) { +static void bench_scalar_add(void* arg, int iters) { int i, j = 0; bench_inv *data = (bench_inv*)arg; for (i = 0; i < iters; i++) { - j += rustsecp256k1zkp_v0_8_0_scalar_add(&data->scalar[0], &data->scalar[0], &data->scalar[1]); + j += rustsecp256k1zkp_v0_10_0_scalar_add(&data->scalar[0], &data->scalar[0], &data->scalar[1]); } CHECK(j <= iters); } -void bench_scalar_negate(void* arg, int iters) { +static void bench_scalar_negate(void* arg, int iters) { int i; bench_inv *data = (bench_inv*)arg; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_scalar_negate(&data->scalar[0], &data->scalar[0]); + rustsecp256k1zkp_v0_10_0_scalar_negate(&data->scalar[0], &data->scalar[0]); } } -void bench_scalar_sqr(void* arg, int iters) { +static void bench_scalar_sqr(void* arg, int iters) { int i; bench_inv *data = (bench_inv*)arg; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_scalar_sqr(&data->scalar[0], &data->scalar[0]); + rustsecp256k1zkp_v0_10_0_scalar_sqr(&data->scalar[0], &data->scalar[0]); } } -void bench_scalar_mul(void* arg, int iters) { +static void bench_scalar_half(void* arg, int iters) { int i; bench_inv *data = (bench_inv*)arg; + rustsecp256k1zkp_v0_10_0_scalar s = data->scalar[0]; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_scalar_mul(&data->scalar[0], &data->scalar[0], &data->scalar[1]); + rustsecp256k1zkp_v0_10_0_scalar_half(&s, &s); } + + data->scalar[0] = s; } -void bench_scalar_split(void* arg, int iters) { +static void bench_scalar_mul(void* arg, int iters) { + int i; + bench_inv *data = (bench_inv*)arg; + + for (i = 0; i < iters; i++) { + rustsecp256k1zkp_v0_10_0_scalar_mul(&data->scalar[0], &data->scalar[0], &data->scalar[1]); + } +} + +static void bench_scalar_split(void* arg, int iters) { int i, j = 0; bench_inv *data = (bench_inv*)arg; + rustsecp256k1zkp_v0_10_0_scalar tmp; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_scalar_split_lambda(&data->scalar[0], &data->scalar[1], &data->scalar[0]); - j += rustsecp256k1zkp_v0_8_0_scalar_add(&data->scalar[0], &data->scalar[0], &data->scalar[1]); + rustsecp256k1zkp_v0_10_0_scalar_split_lambda(&tmp, &data->scalar[1], &data->scalar[0]); + j += rustsecp256k1zkp_v0_10_0_scalar_add(&data->scalar[0], &tmp, &data->scalar[1]); } CHECK(j <= iters); } -void bench_scalar_inverse(void* arg, int iters) { +static void bench_scalar_inverse(void* arg, int iters) { int i, j = 0; bench_inv *data = (bench_inv*)arg; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_scalar_inverse(&data->scalar[0], &data->scalar[0]); - j += rustsecp256k1zkp_v0_8_0_scalar_add(&data->scalar[0], &data->scalar[0], &data->scalar[1]); + rustsecp256k1zkp_v0_10_0_scalar_inverse(&data->scalar[0], &data->scalar[0]); + j += rustsecp256k1zkp_v0_10_0_scalar_add(&data->scalar[0], &data->scalar[0], &data->scalar[1]); } CHECK(j <= iters); } -void bench_scalar_inverse_var(void* arg, int iters) { +static void bench_scalar_inverse_var(void* arg, int iters) { int i, j = 0; bench_inv *data = (bench_inv*)arg; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_scalar_inverse_var(&data->scalar[0], &data->scalar[0]); - j += rustsecp256k1zkp_v0_8_0_scalar_add(&data->scalar[0], &data->scalar[0], &data->scalar[1]); + rustsecp256k1zkp_v0_10_0_scalar_inverse_var(&data->scalar[0], &data->scalar[0]); + j += rustsecp256k1zkp_v0_10_0_scalar_add(&data->scalar[0], &data->scalar[0], &data->scalar[1]); } CHECK(j <= iters); } -void bench_field_half(void* arg, int iters) { +static void bench_field_half(void* arg, int iters) { int i; bench_inv *data = (bench_inv*)arg; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_fe_half(&data->fe[0]); + rustsecp256k1zkp_v0_10_0_fe_half(&data->fe[0]); } } -void bench_field_normalize(void* arg, int iters) { +static void bench_field_normalize(void* arg, int iters) { int i; bench_inv *data = (bench_inv*)arg; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_fe_normalize(&data->fe[0]); + rustsecp256k1zkp_v0_10_0_fe_normalize(&data->fe[0]); } } -void bench_field_normalize_weak(void* arg, int iters) { +static void bench_field_normalize_weak(void* arg, int iters) { int i; bench_inv *data = (bench_inv*)arg; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&data->fe[0]); + rustsecp256k1zkp_v0_10_0_fe_normalize_weak(&data->fe[0]); } } -void bench_field_mul(void* arg, int iters) { +static void bench_field_mul(void* arg, int iters) { int i; bench_inv *data = (bench_inv*)arg; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_fe_mul(&data->fe[0], &data->fe[0], &data->fe[1]); + rustsecp256k1zkp_v0_10_0_fe_mul(&data->fe[0], &data->fe[0], &data->fe[1]); } } -void bench_field_sqr(void* arg, int iters) { +static void bench_field_sqr(void* arg, int iters) { int i; bench_inv *data = (bench_inv*)arg; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_fe_sqr(&data->fe[0], &data->fe[0]); + rustsecp256k1zkp_v0_10_0_fe_sqr(&data->fe[0], &data->fe[0]); } } -void bench_field_inverse(void* arg, int iters) { +static void bench_field_inverse(void* arg, int iters) { int i; bench_inv *data = (bench_inv*)arg; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_fe_inv(&data->fe[0], &data->fe[0]); - rustsecp256k1zkp_v0_8_0_fe_add(&data->fe[0], &data->fe[1]); + rustsecp256k1zkp_v0_10_0_fe_inv(&data->fe[0], &data->fe[0]); + rustsecp256k1zkp_v0_10_0_fe_add(&data->fe[0], &data->fe[1]); } } -void bench_field_inverse_var(void* arg, int iters) { +static void bench_field_inverse_var(void* arg, int iters) { int i; bench_inv *data = (bench_inv*)arg; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_fe_inv_var(&data->fe[0], &data->fe[0]); - rustsecp256k1zkp_v0_8_0_fe_add(&data->fe[0], &data->fe[1]); + rustsecp256k1zkp_v0_10_0_fe_inv_var(&data->fe[0], &data->fe[0]); + rustsecp256k1zkp_v0_10_0_fe_add(&data->fe[0], &data->fe[1]); } } -void bench_field_sqrt(void* arg, int iters) { +static void bench_field_sqrt(void* arg, int iters) { int i, j = 0; bench_inv *data = (bench_inv*)arg; - rustsecp256k1zkp_v0_8_0_fe t; + rustsecp256k1zkp_v0_10_0_fe t; for (i = 0; i < iters; i++) { t = data->fe[0]; - j += rustsecp256k1zkp_v0_8_0_fe_sqrt(&data->fe[0], &t); - rustsecp256k1zkp_v0_8_0_fe_add(&data->fe[0], &data->fe[1]); + j += rustsecp256k1zkp_v0_10_0_fe_sqrt(&data->fe[0], &t); + rustsecp256k1zkp_v0_10_0_fe_add(&data->fe[0], &data->fe[1]); + } + CHECK(j <= iters); +} + +static void bench_field_is_square_var(void* arg, int iters) { + int i, j = 0; + bench_inv *data = (bench_inv*)arg; + rustsecp256k1zkp_v0_10_0_fe t = data->fe[0]; + + for (i = 0; i < iters; i++) { + j += rustsecp256k1zkp_v0_10_0_fe_is_square_var(&t); + rustsecp256k1zkp_v0_10_0_fe_add(&t, &data->fe[1]); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&t); } CHECK(j <= iters); } -void bench_group_double_var(void* arg, int iters) { +static void bench_group_double_var(void* arg, int iters) { int i; bench_inv *data = (bench_inv*)arg; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_gej_double_var(&data->gej[0], &data->gej[0], NULL); + rustsecp256k1zkp_v0_10_0_gej_double_var(&data->gej[0], &data->gej[0], NULL); } } -void bench_group_add_var(void* arg, int iters) { +static void bench_group_add_var(void* arg, int iters) { int i; bench_inv *data = (bench_inv*)arg; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_gej_add_var(&data->gej[0], &data->gej[0], &data->gej[1], NULL); + rustsecp256k1zkp_v0_10_0_gej_add_var(&data->gej[0], &data->gej[0], &data->gej[1], NULL); } } -void bench_group_add_affine(void* arg, int iters) { +static void bench_group_add_affine(void* arg, int iters) { int i; bench_inv *data = (bench_inv*)arg; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_gej_add_ge(&data->gej[0], &data->gej[0], &data->ge[1]); + rustsecp256k1zkp_v0_10_0_gej_add_ge(&data->gej[0], &data->gej[0], &data->ge[1]); } } -void bench_group_add_affine_var(void* arg, int iters) { +static void bench_group_add_affine_var(void* arg, int iters) { int i; bench_inv *data = (bench_inv*)arg; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&data->gej[0], &data->gej[0], &data->ge[1], NULL); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&data->gej[0], &data->gej[0], &data->ge[1], NULL); } } -void bench_group_jacobi_var(void* arg, int iters) { +static void bench_group_jacobi_var(void* arg, int iters) { int i, j = 0; bench_inv *data = (bench_inv*)arg; for (i = 0; i < iters; i++) { - j += rustsecp256k1zkp_v0_8_0_gej_has_quad_y_var(&data->gej[0]); + j += rustsecp256k1zkp_v0_10_0_gej_has_quad_y_var(&data->gej[0]); /* Vary the Y and Z coordinates of the input (the X coordinate doesn't matter to - rustsecp256k1zkp_v0_8_0_gej_has_quad_y_var). Note that the resulting coordinates will + rustsecp256k1zkp_v0_10_0_gej_has_quad_y_var). Note that the resulting coordinates will generally not correspond to a point on the curve, but this is not a problem for the code being benchmarked here. Adding and normalizing have less overhead than EC operations (which could guarantee the point remains on the curve). */ - rustsecp256k1zkp_v0_8_0_fe_add(&data->gej[0].y, &data->fe[1]); - rustsecp256k1zkp_v0_8_0_fe_add(&data->gej[0].z, &data->fe[2]); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&data->gej[0].y); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&data->gej[0].z); + rustsecp256k1zkp_v0_10_0_fe_add(&data->gej[0].y, &data->fe[1]); + rustsecp256k1zkp_v0_10_0_fe_add(&data->gej[0].z, &data->fe[2]); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&data->gej[0].y); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&data->gej[0].z); } CHECK(j <= iters); } -void bench_group_to_affine_var(void* arg, int iters) { +static void bench_group_add_zinv_var(void* arg, int iters) { int i; bench_inv *data = (bench_inv*)arg; - for (i = 0; i < iters; ++i) { - rustsecp256k1zkp_v0_8_0_ge_set_gej_var(&data->ge[1], &data->gej[0]); - /* Use the output affine X/Y coordinates to vary the input X/Y/Z coordinates. - Similar to bench_group_jacobi_var, this approach does not result in - coordinates of points on the curve. */ - rustsecp256k1zkp_v0_8_0_fe_add(&data->gej[0].x, &data->ge[1].y); - rustsecp256k1zkp_v0_8_0_fe_add(&data->gej[0].y, &data->fe[2]); - rustsecp256k1zkp_v0_8_0_fe_add(&data->gej[0].z, &data->ge[1].x); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&data->gej[0].x); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&data->gej[0].y); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&data->gej[0].z); + for (i = 0; i < iters; i++) { + rustsecp256k1zkp_v0_10_0_gej_add_zinv_var(&data->gej[0], &data->gej[0], &data->ge[1], &data->gej[0].y); } } -void bench_ecmult_wnaf(void* arg, int iters) { - int i, bits = 0, overflow = 0; +static void bench_group_to_affine_var(void* arg, int iters) { + int i; bench_inv *data = (bench_inv*)arg; - for (i = 0; i < iters; i++) { - bits += rustsecp256k1zkp_v0_8_0_ecmult_wnaf(data->wnaf, 256, &data->scalar[0], WINDOW_A); - overflow += rustsecp256k1zkp_v0_8_0_scalar_add(&data->scalar[0], &data->scalar[0], &data->scalar[1]); + for (i = 0; i < iters; ++i) { + rustsecp256k1zkp_v0_10_0_ge_set_gej_var(&data->ge[1], &data->gej[0]); + /* Use the output affine X/Y coordinates to vary the input X/Y/Z coordinates. + Similar to bench_group_jacobi_var, this approach does not result in + coordinates of points on the curve. */ + rustsecp256k1zkp_v0_10_0_fe_add(&data->gej[0].x, &data->ge[1].y); + rustsecp256k1zkp_v0_10_0_fe_add(&data->gej[0].y, &data->fe[2]); + rustsecp256k1zkp_v0_10_0_fe_add(&data->gej[0].z, &data->ge[1].x); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&data->gej[0].x); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&data->gej[0].y); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&data->gej[0].z); } - CHECK(overflow >= 0); - CHECK(bits <= 256*iters); } -void bench_wnaf_const(void* arg, int iters) { +static void bench_ecmult_wnaf(void* arg, int iters) { int i, bits = 0, overflow = 0; bench_inv *data = (bench_inv*)arg; for (i = 0; i < iters; i++) { - bits += rustsecp256k1zkp_v0_8_0_wnaf_const(data->wnaf, &data->scalar[0], WINDOW_A, 256); - overflow += rustsecp256k1zkp_v0_8_0_scalar_add(&data->scalar[0], &data->scalar[0], &data->scalar[1]); + bits += rustsecp256k1zkp_v0_10_0_ecmult_wnaf(data->wnaf, 256, &data->scalar[0], WINDOW_A); + overflow += rustsecp256k1zkp_v0_10_0_scalar_add(&data->scalar[0], &data->scalar[0], &data->scalar[1]); } CHECK(overflow >= 0); CHECK(bits <= 256*iters); } - -void bench_sha256(void* arg, int iters) { +static void bench_sha256(void* arg, int iters) { int i; bench_inv *data = (bench_inv*)arg; - rustsecp256k1zkp_v0_8_0_sha256 sha; + rustsecp256k1zkp_v0_10_0_sha256 sha; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, data->data, 32); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, data->data); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, data->data, 32); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, data->data); } } -void bench_hmac_sha256(void* arg, int iters) { +static void bench_hmac_sha256(void* arg, int iters) { int i; bench_inv *data = (bench_inv*)arg; - rustsecp256k1zkp_v0_8_0_hmac_sha256 hmac; + rustsecp256k1zkp_v0_10_0_hmac_sha256 hmac; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_hmac_sha256_initialize(&hmac, data->data, 32); - rustsecp256k1zkp_v0_8_0_hmac_sha256_write(&hmac, data->data, 32); - rustsecp256k1zkp_v0_8_0_hmac_sha256_finalize(&hmac, data->data); + rustsecp256k1zkp_v0_10_0_hmac_sha256_initialize(&hmac, data->data, 32); + rustsecp256k1zkp_v0_10_0_hmac_sha256_write(&hmac, data->data, 32); + rustsecp256k1zkp_v0_10_0_hmac_sha256_finalize(&hmac, data->data); } } -void bench_rfc6979_hmac_sha256(void* arg, int iters) { +static void bench_rfc6979_hmac_sha256(void* arg, int iters) { int i; bench_inv *data = (bench_inv*)arg; - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256 rng; + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256 rng; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_initialize(&rng, data->data, 64); - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_generate(&rng, data->data, 32); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_initialize(&rng, data->data, 64); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_generate(&rng, data->data, 32); } } -void bench_context_verify(void* arg, int iters) { +static void bench_context(void* arg, int iters) { int i; (void)arg; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_context_destroy(rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_VERIFY)); - } -} - -void bench_context_sign(void* arg, int iters) { - int i; - (void)arg; - for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_context_destroy(rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN)); + rustsecp256k1zkp_v0_10_0_context_destroy(rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_CONTEXT_NONE)); } } int main(int argc, char **argv) { bench_inv data; - int iters = get_iters(20000); + int default_iters = 20000; + int iters = get_iters(default_iters); int d = argc == 1; /* default */ + + if (argc > 1) { + if (have_flag(argc, argv, "-h") + || have_flag(argc, argv, "--help") + || have_flag(argc, argv, "help")) { + help(default_iters); + return 0; + } + } + print_output_table_header_row(); + if (d || have_flag(argc, argv, "scalar") || have_flag(argc, argv, "half")) run_benchmark("scalar_half", bench_scalar_half, bench_setup, NULL, &data, 10, iters*100); if (d || have_flag(argc, argv, "scalar") || have_flag(argc, argv, "add")) run_benchmark("scalar_add", bench_scalar_add, bench_setup, NULL, &data, 10, iters*100); if (d || have_flag(argc, argv, "scalar") || have_flag(argc, argv, "negate")) run_benchmark("scalar_negate", bench_scalar_negate, bench_setup, NULL, &data, 10, iters*100); if (d || have_flag(argc, argv, "scalar") || have_flag(argc, argv, "sqr")) run_benchmark("scalar_sqr", bench_scalar_sqr, bench_setup, NULL, &data, 10, iters*10); @@ -398,6 +442,7 @@ int main(int argc, char **argv) { if (d || have_flag(argc, argv, "field") || have_flag(argc, argv, "mul")) run_benchmark("field_mul", bench_field_mul, bench_setup, NULL, &data, 10, iters*10); if (d || have_flag(argc, argv, "field") || have_flag(argc, argv, "inverse")) run_benchmark("field_inverse", bench_field_inverse, bench_setup, NULL, &data, 10, iters); if (d || have_flag(argc, argv, "field") || have_flag(argc, argv, "inverse")) run_benchmark("field_inverse_var", bench_field_inverse_var, bench_setup, NULL, &data, 10, iters); + if (d || have_flag(argc, argv, "field") || have_flag(argc, argv, "issquare")) run_benchmark("field_is_square_var", bench_field_is_square_var, bench_setup, NULL, &data, 10, iters); if (d || have_flag(argc, argv, "field") || have_flag(argc, argv, "sqrt")) run_benchmark("field_sqrt", bench_field_sqrt, bench_setup, NULL, &data, 10, iters); if (d || have_flag(argc, argv, "group") || have_flag(argc, argv, "double")) run_benchmark("group_double_var", bench_group_double_var, bench_setup, NULL, &data, 10, iters*10); @@ -405,17 +450,16 @@ int main(int argc, char **argv) { if (d || have_flag(argc, argv, "group") || have_flag(argc, argv, "add")) run_benchmark("group_add_affine", bench_group_add_affine, bench_setup, NULL, &data, 10, iters*10); if (d || have_flag(argc, argv, "group") || have_flag(argc, argv, "add")) run_benchmark("group_add_affine_var", bench_group_add_affine_var, bench_setup, NULL, &data, 10, iters*10); if (d || have_flag(argc, argv, "group") || have_flag(argc, argv, "jacobi")) run_benchmark("group_jacobi_var", bench_group_jacobi_var, bench_setup, NULL, &data, 10, iters); + if (d || have_flag(argc, argv, "group") || have_flag(argc, argv, "add")) run_benchmark("group_add_zinv_var", bench_group_add_zinv_var, bench_setup, NULL, &data, 10, iters*10); if (d || have_flag(argc, argv, "group") || have_flag(argc, argv, "to_affine")) run_benchmark("group_to_affine_var", bench_group_to_affine_var, bench_setup, NULL, &data, 10, iters); - if (d || have_flag(argc, argv, "ecmult") || have_flag(argc, argv, "wnaf")) run_benchmark("wnaf_const", bench_wnaf_const, bench_setup, NULL, &data, 10, iters); if (d || have_flag(argc, argv, "ecmult") || have_flag(argc, argv, "wnaf")) run_benchmark("ecmult_wnaf", bench_ecmult_wnaf, bench_setup, NULL, &data, 10, iters); if (d || have_flag(argc, argv, "hash") || have_flag(argc, argv, "sha256")) run_benchmark("hash_sha256", bench_sha256, bench_setup, NULL, &data, 10, iters); if (d || have_flag(argc, argv, "hash") || have_flag(argc, argv, "hmac")) run_benchmark("hash_hmac_sha256", bench_hmac_sha256, bench_setup, NULL, &data, 10, iters); if (d || have_flag(argc, argv, "hash") || have_flag(argc, argv, "rng6979")) run_benchmark("hash_rfc6979_hmac_sha256", bench_rfc6979_hmac_sha256, bench_setup, NULL, &data, 10, iters); - if (d || have_flag(argc, argv, "context") || have_flag(argc, argv, "verify")) run_benchmark("context_verify", bench_context_verify, bench_setup, NULL, &data, 10, 1 + iters/1000); - if (d || have_flag(argc, argv, "context") || have_flag(argc, argv, "sign")) run_benchmark("context_sign", bench_context_sign, bench_setup, NULL, &data, 10, 1 + iters/100); + if (d || have_flag(argc, argv, "context")) run_benchmark("context_create", bench_context, bench_setup, NULL, &data, 10, iters); return 0; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/bench_rangeproof.c b/secp256k1-zkp-sys/depend/secp256k1/src/bench_rangeproof.c index fd38dc36..a40e6b1b 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/bench_rangeproof.c +++ b/secp256k1-zkp-sys/depend/secp256k1/src/bench_rangeproof.c @@ -6,13 +6,13 @@ #include -#include "include/secp256k1_rangeproof.h" +#include "../include/secp256k1_rangeproof.h" #include "util.h" #include "bench.h" typedef struct { - rustsecp256k1zkp_v0_8_0_context* ctx; - rustsecp256k1zkp_v0_8_0_pedersen_commitment commit; + rustsecp256k1zkp_v0_10_0_context* ctx; + rustsecp256k1zkp_v0_10_0_pedersen_commitment commit; unsigned char proof[5134]; unsigned char blind[32]; size_t len; @@ -28,10 +28,10 @@ static void bench_rangeproof_setup(void* arg) { data->v = 0; for (i = 0; i < 32; i++) data->blind[i] = i + 1; - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(data->ctx, &data->commit, data->blind, data->v, rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commit(data->ctx, &data->commit, data->blind, data->v, rustsecp256k1zkp_v0_10_0_generator_h)); data->len = 5134; - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(data->ctx, data->proof, &data->len, 0, &data->commit, data->blind, (const unsigned char*)&data->commit, 0, data->min_bits, data->v, NULL, 0, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify(data->ctx, &minv, &maxv, &data->commit, data->proof, data->len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_sign(data->ctx, data->proof, &data->len, 0, &data->commit, data->blind, (const unsigned char*)&data->commit, 0, data->min_bits, data->v, NULL, 0, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_verify(data->ctx, &minv, &maxv, &data->commit, data->proof, data->len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); } static void bench_rangeproof(void* arg, int iters) { @@ -42,7 +42,7 @@ static void bench_rangeproof(void* arg, int iters) { int j; uint64_t minv; uint64_t maxv; - j = rustsecp256k1zkp_v0_8_0_rangeproof_verify(data->ctx, &minv, &maxv, &data->commit, data->proof, data->len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h); + j = rustsecp256k1zkp_v0_10_0_rangeproof_verify(data->ctx, &minv, &maxv, &data->commit, data->proof, data->len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h); for (j = 0; j < 4; j++) { data->proof[j + 2 + 32 *((data->min_bits + 1) >> 1) - 4] = (i >> 8)&255; } @@ -53,13 +53,13 @@ int main(void) { bench_rangeproof_t data; int iters; - data.ctx = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); + data.ctx = rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_CONTEXT_NONE); data.min_bits = 32; iters = data.min_bits*get_iters(32); run_benchmark("rangeproof_verify_bit", bench_rangeproof, bench_rangeproof_setup, NULL, &data, 10, iters); - rustsecp256k1zkp_v0_8_0_context_destroy(data.ctx); + rustsecp256k1zkp_v0_10_0_context_destroy(data.ctx); return 0; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/bench_whitelist.c b/secp256k1-zkp-sys/depend/secp256k1/src/bench_whitelist.c index e729c1a7..b27839fe 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/bench_whitelist.c +++ b/secp256k1-zkp-sys/depend/secp256k1/src/bench_whitelist.c @@ -5,26 +5,27 @@ **********************************************************************/ #include -#include "include/secp256k1.h" +#include "../include/secp256k1.h" -#include "include/secp256k1_whitelist.h" +#include "../include/secp256k1_whitelist.h" #include "util.h" #include "bench.h" #include "hash_impl.h" +#include "int128_impl.h" #include "scalar_impl.h" #include "testrand_impl.h" #define MAX_N_KEYS 30 typedef struct { - rustsecp256k1zkp_v0_8_0_context* ctx; + rustsecp256k1zkp_v0_10_0_context* ctx; unsigned char online_seckey[MAX_N_KEYS][32]; unsigned char summed_seckey[MAX_N_KEYS][32]; - rustsecp256k1zkp_v0_8_0_pubkey online_pubkeys[MAX_N_KEYS]; - rustsecp256k1zkp_v0_8_0_pubkey offline_pubkeys[MAX_N_KEYS]; + rustsecp256k1zkp_v0_10_0_pubkey online_pubkeys[MAX_N_KEYS]; + rustsecp256k1zkp_v0_10_0_pubkey offline_pubkeys[MAX_N_KEYS]; unsigned char csub[32]; - rustsecp256k1zkp_v0_8_0_pubkey sub_pubkey; - rustsecp256k1zkp_v0_8_0_whitelist_signature sig; + rustsecp256k1zkp_v0_10_0_pubkey sub_pubkey; + rustsecp256k1zkp_v0_10_0_whitelist_signature sig; size_t n_keys; } bench_data; @@ -32,14 +33,14 @@ static void bench_whitelist(void* arg, int iters) { bench_data* data = (bench_data*)arg; int i; for (i = 0; i < iters; i++) { - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_verify(data->ctx, &data->sig, data->online_pubkeys, data->offline_pubkeys, data->n_keys, &data->sub_pubkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_verify(data->ctx, &data->sig, data->online_pubkeys, data->offline_pubkeys, data->n_keys, &data->sub_pubkey) == 1); } } static void bench_whitelist_setup(void* arg) { bench_data* data = (bench_data*)arg; int i = 0; - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_sign(data->ctx, &data->sig, data->online_pubkeys, data->offline_pubkeys, data->n_keys, &data->sub_pubkey, data->online_seckey[i], data->summed_seckey[i], i)); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_sign(data->ctx, &data->sig, data->online_pubkeys, data->offline_pubkeys, data->n_keys, &data->sub_pubkey, data->online_seckey[i], data->summed_seckey[i], i)); } static void run_test(bench_data* data, int iters) { @@ -48,13 +49,13 @@ static void run_test(bench_data* data, int iters) { run_benchmark(str, bench_whitelist, bench_whitelist_setup, NULL, data, 100, iters); } -void random_scalar_order(rustsecp256k1zkp_v0_8_0_scalar *num) { +static void random_scalar_order(rustsecp256k1zkp_v0_10_0_scalar *num) { do { unsigned char b32[32]; int overflow = 0; - rustsecp256k1zkp_v0_8_0_testrand256(b32); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(num, b32, &overflow); - if (overflow || rustsecp256k1zkp_v0_8_0_scalar_is_zero(num)) { + rustsecp256k1zkp_v0_10_0_testrand256(b32); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(num, b32, &overflow); + if (overflow || rustsecp256k1zkp_v0_10_0_scalar_is_zero(num)) { continue; } break; @@ -65,35 +66,35 @@ int main(void) { bench_data data; size_t i; size_t n_keys = 30; - rustsecp256k1zkp_v0_8_0_scalar ssub; + rustsecp256k1zkp_v0_10_0_scalar ssub; int iters = get_iters(5); - data.ctx = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); + data.ctx = rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_CONTEXT_NONE); /* Start with subkey */ random_scalar_order(&ssub); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(data.csub, &ssub); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(data.ctx, data.csub) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(data.ctx, &data.sub_pubkey, data.csub) == 1); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(data.csub, &ssub); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_verify(data.ctx, data.csub) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(data.ctx, &data.sub_pubkey, data.csub) == 1); /* Then offline and online whitelist keys */ for (i = 0; i < n_keys; i++) { - rustsecp256k1zkp_v0_8_0_scalar son, soff; + rustsecp256k1zkp_v0_10_0_scalar son, soff; /* Create two keys */ random_scalar_order(&son); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(data.online_seckey[i], &son); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(data.ctx, data.online_seckey[i]) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(data.ctx, &data.online_pubkeys[i], data.online_seckey[i]) == 1); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(data.online_seckey[i], &son); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_verify(data.ctx, data.online_seckey[i]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(data.ctx, &data.online_pubkeys[i], data.online_seckey[i]) == 1); random_scalar_order(&soff); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(data.summed_seckey[i], &soff); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(data.ctx, data.summed_seckey[i]) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(data.ctx, &data.offline_pubkeys[i], data.summed_seckey[i]) == 1); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(data.summed_seckey[i], &soff); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_verify(data.ctx, data.summed_seckey[i]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(data.ctx, &data.offline_pubkeys[i], data.summed_seckey[i]) == 1); /* Make summed_seckey correspond to the sum of offline_pubkey and sub_pubkey */ - rustsecp256k1zkp_v0_8_0_scalar_add(&soff, &soff, &ssub); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(data.summed_seckey[i], &soff); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(data.ctx, data.summed_seckey[i]) == 1); + rustsecp256k1zkp_v0_10_0_scalar_add(&soff, &soff, &ssub); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(data.summed_seckey[i], &soff); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_verify(data.ctx, data.summed_seckey[i]) == 1); } /* Run test */ @@ -102,6 +103,6 @@ int main(void) { run_test(&data, iters); } - rustsecp256k1zkp_v0_8_0_context_destroy(data.ctx); + rustsecp256k1zkp_v0_10_0_context_destroy(data.ctx); return(0); } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/checkmem.h b/secp256k1-zkp-sys/depend/secp256k1/src/checkmem.h new file mode 100644 index 00000000..f2169dec --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/checkmem.h @@ -0,0 +1,95 @@ +/*********************************************************************** + * Copyright (c) 2022 Pieter Wuille * + * Distributed under the MIT software license, see the accompanying * + * file COPYING or https://www.opensource.org/licenses/mit-license.php.* + ***********************************************************************/ + +/* The code here is inspired by Kris Kwiatkowski's approach in + * https://github.com/kriskwiatkowski/pqc/blob/main/src/common/ct_check.h + * to provide a general interface for memory-checking mechanisms, primarily + * for constant-time checking. + */ + +/* These macros are defined by this header file: + * + * - SECP256K1_CHECKMEM_ENABLED: + * - 1 if memory-checking integration is available, 0 otherwise. + * This is just a compile-time macro. Use the next macro to check it is actually + * available at runtime. + * - SECP256K1_CHECKMEM_RUNNING(): + * - Acts like a function call, returning 1 if memory checking is available + * at runtime. + * - SECP256K1_CHECKMEM_CHECK(p, len): + * - Assert or otherwise fail in case the len-byte memory block pointed to by p is + * not considered entirely defined. + * - SECP256K1_CHECKMEM_CHECK_VERIFY(p, len): + * - Like SECP256K1_CHECKMEM_CHECK, but only works in VERIFY mode. + * - SECP256K1_CHECKMEM_UNDEFINE(p, len): + * - marks the len-byte memory block pointed to by p as undefined data (secret data, + * in the context of constant-time checking). + * - SECP256K1_CHECKMEM_DEFINE(p, len): + * - marks the len-byte memory pointed to by p as defined data (public data, in the + * context of constant-time checking). + * + */ + +#ifndef SECP256K1_CHECKMEM_H +#define SECP256K1_CHECKMEM_H + +/* Define a statement-like macro that ignores the arguments. */ +#define SECP256K1_CHECKMEM_NOOP(p, len) do { (void)(p); (void)(len); } while(0) + +/* If compiling under msan, map the SECP256K1_CHECKMEM_* functionality to msan. + * Choose this preferentially, even when VALGRIND is defined, as msan-compiled + * binaries can't be run under valgrind anyway. */ +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) +# include +# define SECP256K1_CHECKMEM_ENABLED 1 +# define SECP256K1_CHECKMEM_UNDEFINE(p, len) __msan_allocated_memory((p), (len)) +# define SECP256K1_CHECKMEM_DEFINE(p, len) __msan_unpoison((p), (len)) +# define SECP256K1_CHECKMEM_CHECK(p, len) __msan_check_mem_is_initialized((p), (len)) +# define SECP256K1_CHECKMEM_RUNNING() (1) +# endif +#endif + +/* If valgrind integration is desired (through the VALGRIND define), implement the + * SECP256K1_CHECKMEM_* macros using valgrind. */ +#if !defined SECP256K1_CHECKMEM_ENABLED +# if defined VALGRIND +# include +# if defined(__clang__) && defined(__APPLE__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wreserved-identifier" +# endif +# include +# if defined(__clang__) && defined(__APPLE__) +# pragma clang diagnostic pop +# endif +# define SECP256K1_CHECKMEM_ENABLED 1 +# define SECP256K1_CHECKMEM_UNDEFINE(p, len) VALGRIND_MAKE_MEM_UNDEFINED((p), (len)) +# define SECP256K1_CHECKMEM_DEFINE(p, len) VALGRIND_MAKE_MEM_DEFINED((p), (len)) +# define SECP256K1_CHECKMEM_CHECK(p, len) VALGRIND_CHECK_MEM_IS_DEFINED((p), (len)) + /* VALGRIND_MAKE_MEM_DEFINED returns 0 iff not running on memcheck. + * This is more precise than the RUNNING_ON_VALGRIND macro, which + * checks for valgrind in general instead of memcheck specifically. */ +# define SECP256K1_CHECKMEM_RUNNING() (VALGRIND_MAKE_MEM_DEFINED(NULL, 0) != 0) +# endif +#endif + +/* As a fall-back, map these macros to dummy statements. */ +#if !defined SECP256K1_CHECKMEM_ENABLED +# define SECP256K1_CHECKMEM_ENABLED 0 +# define SECP256K1_CHECKMEM_UNDEFINE(p, len) SECP256K1_CHECKMEM_NOOP((p), (len)) +# define SECP256K1_CHECKMEM_DEFINE(p, len) SECP256K1_CHECKMEM_NOOP((p), (len)) +# define SECP256K1_CHECKMEM_CHECK(p, len) SECP256K1_CHECKMEM_NOOP((p), (len)) +# define SECP256K1_CHECKMEM_RUNNING() (0) +#endif + +#if defined VERIFY +#define SECP256K1_CHECKMEM_CHECK_VERIFY(p, len) SECP256K1_CHECKMEM_CHECK((p), (len)) +#else +#define SECP256K1_CHECKMEM_CHECK_VERIFY(p, len) SECP256K1_CHECKMEM_NOOP((p), (len)) +#endif + +#endif /* SECP256K1_CHECKMEM_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/ctime_tests.c b/secp256k1-zkp-sys/depend/secp256k1/src/ctime_tests.c new file mode 100644 index 00000000..0b9cccc4 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/ctime_tests.c @@ -0,0 +1,352 @@ +/*********************************************************************** + * Copyright (c) 2020 Gregory Maxwell * + * Distributed under the MIT software license, see the accompanying * + * file COPYING or https://www.opensource.org/licenses/mit-license.php.* + ***********************************************************************/ + +#include +#include + +#include "../include/secp256k1.h" +#include "assumptions.h" +#include "checkmem.h" + +#if !SECP256K1_CHECKMEM_ENABLED +# error "This tool cannot be compiled without memory-checking interface (valgrind or msan)" +#endif + +#ifdef ENABLE_MODULE_ECDH +#include "../include/secp256k1_ecdh.h" +#endif + +#ifdef ENABLE_MODULE_RECOVERY +#include "../include/secp256k1_recovery.h" +#endif + +#ifdef ENABLE_MODULE_EXTRAKEYS +#include "../include/secp256k1_extrakeys.h" +#endif + +#ifdef ENABLE_MODULE_SCHNORRSIG +#include "../include/secp256k1_schnorrsig.h" +#endif + +#ifdef ENABLE_MODULE_ELLSWIFT +#include "../include/secp256k1_ellswift.h" +#endif + +#ifdef ENABLE_MODULE_ECDSA_S2C +#include "../include/secp256k1_ecdsa_s2c.h" +#endif + +#ifdef ENABLE_MODULE_ECDSA_ADAPTOR +#include "../include/secp256k1_ecdsa_adaptor.h" +#endif + +#ifdef ENABLE_MODULE_MUSIG +#include "../include/secp256k1_musig.h" +#endif + +static void run_tests(rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *key); + +int main(void) { + rustsecp256k1zkp_v0_10_0_context* ctx; + unsigned char key[32]; + int ret, i; + + if (!SECP256K1_CHECKMEM_RUNNING()) { + fprintf(stderr, "This test can only usefully be run inside valgrind because it was not compiled under msan.\n"); + fprintf(stderr, "Usage: libtool --mode=execute valgrind ./ctime_tests\n"); + return 1; + } + ctx = rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_CONTEXT_DECLASSIFY); + /** In theory, testing with a single secret input should be sufficient: + * If control flow depended on secrets the tool would generate an error. + */ + for (i = 0; i < 32; i++) { + key[i] = i + 65; + } + + run_tests(ctx, key); + + /* Test context randomisation. Do this last because it leaves the context + * tainted. */ + SECP256K1_CHECKMEM_UNDEFINE(key, 32); + ret = rustsecp256k1zkp_v0_10_0_context_randomize(ctx, key); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret); + + rustsecp256k1zkp_v0_10_0_context_destroy(ctx); + return 0; +} + +static void run_tests(rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *key) { + rustsecp256k1zkp_v0_10_0_ecdsa_signature signature; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; + size_t siglen = 74; + size_t outputlen = 33; + int i; + int ret; + unsigned char msg[32]; + unsigned char sig[74]; + unsigned char spubkey[33]; +#ifdef ENABLE_MODULE_RECOVERY + rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature recoverable_signature; + int recid; +#endif +#ifdef ENABLE_MODULE_EXTRAKEYS + rustsecp256k1zkp_v0_10_0_keypair keypair; +#endif +#ifdef ENABLE_MODULE_ELLSWIFT + unsigned char ellswift[64]; + static const unsigned char prefix[64] = {'t', 'e', 's', 't'}; +#endif + + for (i = 0; i < 32; i++) { + msg[i] = i + 1; + } + + /* Test keygen. */ + SECP256K1_CHECKMEM_UNDEFINE(key, 32); + ret = rustsecp256k1zkp_v0_10_0_ec_pubkey_create(ctx, &pubkey, key); + SECP256K1_CHECKMEM_DEFINE(&pubkey, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(ctx, spubkey, &outputlen, &pubkey, SECP256K1_EC_COMPRESSED) == 1); + + /* Test signing. */ + SECP256K1_CHECKMEM_UNDEFINE(key, 32); + ret = rustsecp256k1zkp_v0_10_0_ecdsa_sign(ctx, &signature, msg, key, NULL, NULL); + SECP256K1_CHECKMEM_DEFINE(&signature, sizeof(rustsecp256k1zkp_v0_10_0_ecdsa_signature)); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_der(ctx, sig, &siglen, &signature)); + +#ifdef ENABLE_MODULE_ECDH + /* Test ECDH. */ + SECP256K1_CHECKMEM_UNDEFINE(key, 32); + ret = rustsecp256k1zkp_v0_10_0_ecdh(ctx, msg, &pubkey, key, NULL, NULL); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); +#endif + +#ifdef ENABLE_MODULE_RECOVERY + /* Test signing a recoverable signature. */ + SECP256K1_CHECKMEM_UNDEFINE(key, 32); + ret = rustsecp256k1zkp_v0_10_0_ecdsa_sign_recoverable(ctx, &recoverable_signature, msg, key, NULL, NULL); + SECP256K1_CHECKMEM_DEFINE(&recoverable_signature, sizeof(recoverable_signature)); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_serialize_compact(ctx, sig, &recid, &recoverable_signature)); + CHECK(recid >= 0 && recid <= 3); +#endif + + SECP256K1_CHECKMEM_UNDEFINE(key, 32); + ret = rustsecp256k1zkp_v0_10_0_ec_seckey_verify(ctx, key); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + + SECP256K1_CHECKMEM_UNDEFINE(key, 32); + ret = rustsecp256k1zkp_v0_10_0_ec_seckey_negate(ctx, key); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + + SECP256K1_CHECKMEM_UNDEFINE(key, 32); + SECP256K1_CHECKMEM_UNDEFINE(msg, 32); + ret = rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add(ctx, key, msg); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + + SECP256K1_CHECKMEM_UNDEFINE(key, 32); + SECP256K1_CHECKMEM_UNDEFINE(msg, 32); + ret = rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_mul(ctx, key, msg); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + + /* Test keypair_create and keypair_xonly_tweak_add. */ +#ifdef ENABLE_MODULE_EXTRAKEYS + SECP256K1_CHECKMEM_UNDEFINE(key, 32); + ret = rustsecp256k1zkp_v0_10_0_keypair_create(ctx, &keypair, key); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + + /* The tweak is not treated as a secret in keypair_tweak_add */ + SECP256K1_CHECKMEM_DEFINE(msg, 32); + ret = rustsecp256k1zkp_v0_10_0_keypair_xonly_tweak_add(ctx, &keypair, msg); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + + SECP256K1_CHECKMEM_UNDEFINE(key, 32); + SECP256K1_CHECKMEM_UNDEFINE(&keypair, sizeof(keypair)); + ret = rustsecp256k1zkp_v0_10_0_keypair_sec(ctx, key, &keypair); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); +#endif + +#ifdef ENABLE_MODULE_SCHNORRSIG + SECP256K1_CHECKMEM_UNDEFINE(key, 32); + ret = rustsecp256k1zkp_v0_10_0_keypair_create(ctx, &keypair, key); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + ret = rustsecp256k1zkp_v0_10_0_schnorrsig_sign32(ctx, sig, msg, &keypair, NULL); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); +#endif + +#ifdef ENABLE_MODULE_ELLSWIFT + SECP256K1_CHECKMEM_UNDEFINE(key, 32); + ret = rustsecp256k1zkp_v0_10_0_ellswift_create(ctx, ellswift, key, NULL); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + + SECP256K1_CHECKMEM_UNDEFINE(key, 32); + ret = rustsecp256k1zkp_v0_10_0_ellswift_create(ctx, ellswift, key, ellswift); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + + for (i = 0; i < 2; i++) { + SECP256K1_CHECKMEM_UNDEFINE(key, 32); + SECP256K1_CHECKMEM_DEFINE(&ellswift, sizeof(ellswift)); + ret = rustsecp256k1zkp_v0_10_0_ellswift_xdh(ctx, msg, ellswift, ellswift, key, i, rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function_bip324, NULL); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + + SECP256K1_CHECKMEM_UNDEFINE(key, 32); + SECP256K1_CHECKMEM_DEFINE(&ellswift, sizeof(ellswift)); + ret = rustsecp256k1zkp_v0_10_0_ellswift_xdh(ctx, msg, ellswift, ellswift, key, i, rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function_prefix, (void *)prefix); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + } +#endif + +#ifdef ENABLE_MODULE_ECDSA_S2C + { + unsigned char s2c_data[32] = {0}; + unsigned char s2c_data_comm[32] = {0}; + rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening s2c_opening; + + SECP256K1_CHECKMEM_UNDEFINE(key, 32); + SECP256K1_CHECKMEM_UNDEFINE(s2c_data, 32); + ret = rustsecp256k1zkp_v0_10_0_ecdsa_s2c_sign(ctx, &signature, &s2c_opening, msg, key, s2c_data); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + + SECP256K1_CHECKMEM_UNDEFINE(s2c_data, 32); + ret = rustsecp256k1zkp_v0_10_0_ecdsa_anti_exfil_host_commit(ctx, s2c_data_comm, s2c_data); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + + SECP256K1_CHECKMEM_UNDEFINE(key, 32); + SECP256K1_CHECKMEM_UNDEFINE(s2c_data, 32); + ret = rustsecp256k1zkp_v0_10_0_ecdsa_anti_exfil_signer_commit(ctx, &s2c_opening, msg, key, s2c_data); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + } +#endif + +#ifdef ENABLE_MODULE_ECDSA_ADAPTOR + { + unsigned char adaptor_sig[162]; + unsigned char deckey[32]; + unsigned char expected_deckey[32]; + rustsecp256k1zkp_v0_10_0_pubkey enckey; + + for (i = 0; i < 32; i++) { + deckey[i] = i + 2; + } + + ret = rustsecp256k1zkp_v0_10_0_ec_pubkey_create(ctx, &enckey, deckey); + CHECK(ret == 1); + + SECP256K1_CHECKMEM_UNDEFINE(key, 32); + ret = rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_encrypt(ctx, adaptor_sig, key, &enckey, msg, NULL, NULL); + SECP256K1_CHECKMEM_DEFINE(adaptor_sig, sizeof(adaptor_sig)); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + + SECP256K1_CHECKMEM_UNDEFINE(deckey, 32); + ret = rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_decrypt(ctx, &signature, deckey, adaptor_sig); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + + SECP256K1_CHECKMEM_UNDEFINE(&signature, 32); + ret = rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_recover(ctx, expected_deckey, &signature, adaptor_sig, &enckey); + SECP256K1_CHECKMEM_DEFINE(expected_deckey, sizeof(expected_deckey)); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + + SECP256K1_CHECKMEM_DEFINE(deckey, sizeof(deckey)); + ret = rustsecp256k1zkp_v0_10_0_memcmp_var(deckey, expected_deckey, sizeof(expected_deckey)); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 0); + } +#endif + +#ifdef ENABLE_MODULE_MUSIG + { + rustsecp256k1zkp_v0_10_0_pubkey pk; + const rustsecp256k1zkp_v0_10_0_pubkey *pk_ptr[1]; + rustsecp256k1zkp_v0_10_0_xonly_pubkey agg_pk; + unsigned char session_id[32]; + rustsecp256k1zkp_v0_10_0_musig_secnonce secnonce; + rustsecp256k1zkp_v0_10_0_musig_pubnonce pubnonce; + const rustsecp256k1zkp_v0_10_0_musig_pubnonce *pubnonce_ptr[1]; + rustsecp256k1zkp_v0_10_0_musig_aggnonce aggnonce; + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache cache; + rustsecp256k1zkp_v0_10_0_musig_session session; + rustsecp256k1zkp_v0_10_0_musig_partial_sig partial_sig; + const rustsecp256k1zkp_v0_10_0_musig_partial_sig *partial_sig_ptr[1]; + unsigned char extra_input[32]; + unsigned char sec_adaptor[32]; + rustsecp256k1zkp_v0_10_0_pubkey adaptor; + unsigned char pre_sig[64]; + int nonce_parity; + + pk_ptr[0] = &pk; + pubnonce_ptr[0] = &pubnonce; + SECP256K1_CHECKMEM_DEFINE(key, 32); + memcpy(session_id, key, sizeof(session_id)); + session_id[0] = session_id[0] + 1; + memcpy(extra_input, key, sizeof(extra_input)); + extra_input[0] = extra_input[0] + 2; + memcpy(sec_adaptor, key, sizeof(sec_adaptor)); + sec_adaptor[0] = extra_input[0] + 3; + partial_sig_ptr[0] = &partial_sig; + + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(ctx, &keypair, key)); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_pub(ctx, &pk, &keypair)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(ctx, NULL, &agg_pk, &cache, pk_ptr, 1)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(ctx, &adaptor, sec_adaptor)); + SECP256K1_CHECKMEM_UNDEFINE(key, 32); + SECP256K1_CHECKMEM_UNDEFINE(session_id, sizeof(session_id)); + SECP256K1_CHECKMEM_UNDEFINE(extra_input, sizeof(extra_input)); + SECP256K1_CHECKMEM_UNDEFINE(sec_adaptor, sizeof(sec_adaptor)); + ret = rustsecp256k1zkp_v0_10_0_musig_nonce_gen(ctx, &secnonce, &pubnonce, session_id, key, &pk, msg, &cache, extra_input); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_agg(ctx, &aggnonce, pubnonce_ptr, 1)); + /* Make sure that previous tests don't undefine msg. It's not used as a secret here. */ + SECP256K1_CHECKMEM_DEFINE(msg, sizeof(msg)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_process(ctx, &session, &aggnonce, msg, &cache, &adaptor) == 1); + + ret = rustsecp256k1zkp_v0_10_0_keypair_create(ctx, &keypair, key); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + ret = rustsecp256k1zkp_v0_10_0_musig_partial_sign(ctx, &partial_sig, &secnonce, &keypair, &cache, &session); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + + SECP256K1_CHECKMEM_DEFINE(&partial_sig, sizeof(partial_sig)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_agg(ctx, pre_sig, &session, partial_sig_ptr, 1)); + SECP256K1_CHECKMEM_DEFINE(pre_sig, sizeof(pre_sig)); + + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_parity(ctx, &nonce_parity, &session)); + ret = rustsecp256k1zkp_v0_10_0_musig_adapt(ctx, sig, pre_sig, sec_adaptor, nonce_parity); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + ret = rustsecp256k1zkp_v0_10_0_musig_extract_adaptor(ctx, sec_adaptor, sig, pre_sig, nonce_parity); + SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); + CHECK(ret == 1); + } +#endif +} diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/eccommit.h b/secp256k1-zkp-sys/depend/secp256k1/src/eccommit.h index 68b184db..332f0a9c 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/eccommit.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/eccommit.h @@ -8,21 +8,21 @@ #define SECP256K1_ECCOMMIT_H /** Helper function to add a 32-byte value to a scalar */ -static int rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add_helper(rustsecp256k1zkp_v0_8_0_scalar *sec, const unsigned char *tweak); +static int rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add_helper(rustsecp256k1zkp_v0_10_0_scalar *sec, const unsigned char *tweak); /** Helper function to add a 32-byte value, times G, to an EC point */ -static int rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add_helper(const rustsecp256k1zkp_v0_8_0_ecmult_context* ecmult_ctx, rustsecp256k1zkp_v0_8_0_ge *p, const unsigned char *tweak); +static int rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add_helper(const rustsecp256k1zkp_v0_10_0_ecmult_context* ecmult_ctx, rustsecp256k1zkp_v0_10_0_ge *p, const unsigned char *tweak); /** Serializes elem as a 33 byte array. This is non-constant time with respect to * whether pubp is the point at infinity. Thus, you may need to declassify * pubp->infinity before calling this function. */ -static int rustsecp256k1zkp_v0_8_0_ec_commit_pubkey_serialize_const(rustsecp256k1zkp_v0_8_0_ge *pubp, unsigned char *buf33); +static int rustsecp256k1zkp_v0_10_0_ec_commit_pubkey_serialize_const(rustsecp256k1zkp_v0_10_0_ge *pubp, unsigned char *buf33); /** Compute an ec commitment tweak as hash(pubkey, data). */ -static int rustsecp256k1zkp_v0_8_0_ec_commit_tweak(unsigned char *tweak32, rustsecp256k1zkp_v0_8_0_ge* pubp, rustsecp256k1zkp_v0_8_0_sha256* sha, const unsigned char *data, size_t data_size); +static int rustsecp256k1zkp_v0_10_0_ec_commit_tweak(unsigned char *tweak32, rustsecp256k1zkp_v0_10_0_ge* pubp, rustsecp256k1zkp_v0_10_0_sha256* sha, const unsigned char *data, size_t data_size); /** Compute an ec commitment as pubkey + hash(pubkey, data)*G. */ -static int rustsecp256k1zkp_v0_8_0_ec_commit(const rustsecp256k1zkp_v0_8_0_ecmult_context* ecmult_ctx, rustsecp256k1zkp_v0_8_0_ge* commitp, const rustsecp256k1zkp_v0_8_0_ge* pubp, rustsecp256k1zkp_v0_8_0_sha256* sha, const unsigned char *data, size_t data_size); +static int rustsecp256k1zkp_v0_10_0_ec_commit(const rustsecp256k1zkp_v0_10_0_ecmult_context* ecmult_ctx, rustsecp256k1zkp_v0_10_0_ge* commitp, const rustsecp256k1zkp_v0_10_0_ge* pubp, rustsecp256k1zkp_v0_10_0_sha256* sha, const unsigned char *data, size_t data_size); /** Compute a secret key commitment as seckey + hash(pubkey, data). */ -static int rustsecp256k1zkp_v0_8_0_ec_commit_seckey(const rustsecp256k1zkp_v0_8_0_ecmult_gen_context* ecmult_gen_ctx, rustsecp256k1zkp_v0_8_0_scalar* seckey, rustsecp256k1zkp_v0_8_0_ge* pubp, rustsecp256k1zkp_v0_8_0_sha256* sha, const unsigned char *data, size_t data_size); +static int rustsecp256k1zkp_v0_10_0_ec_commit_seckey(const rustsecp256k1zkp_v0_10_0_ecmult_gen_context* ecmult_gen_ctx, rustsecp256k1zkp_v0_10_0_scalar* seckey, rustsecp256k1zkp_v0_10_0_ge* pubp, rustsecp256k1zkp_v0_10_0_sha256* sha, const unsigned char *data, size_t data_size); /** Verify an ec commitment as pubkey + hash(pubkey, data)*G ?= commitment. */ -static int rustsecp256k1zkp_v0_8_0_ec_commit_verify(const rustsecp256k1zkp_v0_8_0_ecmult_context* ecmult_ctx, const rustsecp256k1zkp_v0_8_0_ge* commitp, const rustsecp256k1zkp_v0_8_0_ge* pubp, rustsecp256k1zkp_v0_8_0_sha256* sha, const unsigned char *data, size_t data_size); +static int rustsecp256k1zkp_v0_10_0_ec_commit_verify(const rustsecp256k1zkp_v0_10_0_ecmult_context* ecmult_ctx, const rustsecp256k1zkp_v0_10_0_ge* commitp, const rustsecp256k1zkp_v0_10_0_ge* pubp, rustsecp256k1zkp_v0_10_0_sha256* sha, const unsigned char *data, size_t data_size); #endif /* SECP256K1_ECCOMMIT_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/eccommit_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/eccommit_impl.h index 8d88b419..c9b5fc57 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/eccommit_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/eccommit_impl.h @@ -10,64 +10,64 @@ #include "hash.h" /* from secp256k1.c */ -static int rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add_helper(rustsecp256k1zkp_v0_8_0_scalar *sec, const unsigned char *tweak); -static int rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add_helper(rustsecp256k1zkp_v0_8_0_ge *pubp, const unsigned char *tweak); +static int rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add_helper(rustsecp256k1zkp_v0_10_0_scalar *sec, const unsigned char *tweak); +static int rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add_helper(rustsecp256k1zkp_v0_10_0_ge *pubp, const unsigned char *tweak); -static int rustsecp256k1zkp_v0_8_0_ec_commit_pubkey_serialize_const(rustsecp256k1zkp_v0_8_0_ge *pubp, unsigned char *buf33) { - if (rustsecp256k1zkp_v0_8_0_ge_is_infinity(pubp)) { +static int rustsecp256k1zkp_v0_10_0_ec_commit_pubkey_serialize_const(rustsecp256k1zkp_v0_10_0_ge *pubp, unsigned char *buf33) { + if (rustsecp256k1zkp_v0_10_0_ge_is_infinity(pubp)) { return 0; } - rustsecp256k1zkp_v0_8_0_fe_normalize(&pubp->x); - rustsecp256k1zkp_v0_8_0_fe_normalize(&pubp->y); - rustsecp256k1zkp_v0_8_0_fe_get_b32(&buf33[1], &pubp->x); - buf33[0] = rustsecp256k1zkp_v0_8_0_fe_is_odd(&pubp->y) ? SECP256K1_TAG_PUBKEY_ODD : SECP256K1_TAG_PUBKEY_EVEN; + rustsecp256k1zkp_v0_10_0_fe_normalize(&pubp->x); + rustsecp256k1zkp_v0_10_0_fe_normalize(&pubp->y); + rustsecp256k1zkp_v0_10_0_fe_get_b32(&buf33[1], &pubp->x); + buf33[0] = rustsecp256k1zkp_v0_10_0_fe_is_odd(&pubp->y) ? SECP256K1_TAG_PUBKEY_ODD : SECP256K1_TAG_PUBKEY_EVEN; return 1; } /* Compute an ec commitment tweak as hash(pubp, data). */ -static int rustsecp256k1zkp_v0_8_0_ec_commit_tweak(unsigned char *tweak32, rustsecp256k1zkp_v0_8_0_ge* pubp, rustsecp256k1zkp_v0_8_0_sha256* sha, const unsigned char *data, size_t data_size) +static int rustsecp256k1zkp_v0_10_0_ec_commit_tweak(unsigned char *tweak32, rustsecp256k1zkp_v0_10_0_ge* pubp, rustsecp256k1zkp_v0_10_0_sha256* sha, const unsigned char *data, size_t data_size) { unsigned char rbuf[33]; - if (!rustsecp256k1zkp_v0_8_0_ec_commit_pubkey_serialize_const(pubp, rbuf)) { + if (!rustsecp256k1zkp_v0_10_0_ec_commit_pubkey_serialize_const(pubp, rbuf)) { return 0; } - rustsecp256k1zkp_v0_8_0_sha256_write(sha, rbuf, sizeof(rbuf)); - rustsecp256k1zkp_v0_8_0_sha256_write(sha, data, data_size); - rustsecp256k1zkp_v0_8_0_sha256_finalize(sha, tweak32); + rustsecp256k1zkp_v0_10_0_sha256_write(sha, rbuf, sizeof(rbuf)); + rustsecp256k1zkp_v0_10_0_sha256_write(sha, data, data_size); + rustsecp256k1zkp_v0_10_0_sha256_finalize(sha, tweak32); return 1; } /* Compute an ec commitment as pubp + hash(pubp, data)*G. */ -static int rustsecp256k1zkp_v0_8_0_ec_commit(rustsecp256k1zkp_v0_8_0_ge* commitp, const rustsecp256k1zkp_v0_8_0_ge* pubp, rustsecp256k1zkp_v0_8_0_sha256* sha, const unsigned char *data, size_t data_size) { +static int rustsecp256k1zkp_v0_10_0_ec_commit(rustsecp256k1zkp_v0_10_0_ge* commitp, const rustsecp256k1zkp_v0_10_0_ge* pubp, rustsecp256k1zkp_v0_10_0_sha256* sha, const unsigned char *data, size_t data_size) { unsigned char tweak[32]; *commitp = *pubp; - return rustsecp256k1zkp_v0_8_0_ec_commit_tweak(tweak, commitp, sha, data, data_size) - && rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add_helper(commitp, tweak); + return rustsecp256k1zkp_v0_10_0_ec_commit_tweak(tweak, commitp, sha, data, data_size) + && rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add_helper(commitp, tweak); } /* Compute the seckey of an ec commitment from the original secret key of the pubkey as seckey + * hash(pubp, data). */ -static int rustsecp256k1zkp_v0_8_0_ec_commit_seckey(rustsecp256k1zkp_v0_8_0_scalar* seckey, rustsecp256k1zkp_v0_8_0_ge* pubp, rustsecp256k1zkp_v0_8_0_sha256* sha, const unsigned char *data, size_t data_size) { +static int rustsecp256k1zkp_v0_10_0_ec_commit_seckey(rustsecp256k1zkp_v0_10_0_scalar* seckey, rustsecp256k1zkp_v0_10_0_ge* pubp, rustsecp256k1zkp_v0_10_0_sha256* sha, const unsigned char *data, size_t data_size) { unsigned char tweak[32]; - return rustsecp256k1zkp_v0_8_0_ec_commit_tweak(tweak, pubp, sha, data, data_size) - && rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add_helper(seckey, tweak); + return rustsecp256k1zkp_v0_10_0_ec_commit_tweak(tweak, pubp, sha, data, data_size) + && rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add_helper(seckey, tweak); } /* Verify an ec commitment as pubp + hash(pubp, data)*G ?= commitment. */ -static int rustsecp256k1zkp_v0_8_0_ec_commit_verify(const rustsecp256k1zkp_v0_8_0_ge* commitp, const rustsecp256k1zkp_v0_8_0_ge* pubp, rustsecp256k1zkp_v0_8_0_sha256* sha, const unsigned char *data, size_t data_size) { - rustsecp256k1zkp_v0_8_0_gej pj; - rustsecp256k1zkp_v0_8_0_ge p; +static int rustsecp256k1zkp_v0_10_0_ec_commit_verify(const rustsecp256k1zkp_v0_10_0_ge* commitp, const rustsecp256k1zkp_v0_10_0_ge* pubp, rustsecp256k1zkp_v0_10_0_sha256* sha, const unsigned char *data, size_t data_size) { + rustsecp256k1zkp_v0_10_0_gej pj; + rustsecp256k1zkp_v0_10_0_ge p; - if (!rustsecp256k1zkp_v0_8_0_ec_commit(&p, pubp, sha, data, data_size)) { + if (!rustsecp256k1zkp_v0_10_0_ec_commit(&p, pubp, sha, data, data_size)) { return 0; } /* Return p == commitp */ - rustsecp256k1zkp_v0_8_0_ge_neg(&p, &p); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&pj, &p); - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&pj, &pj, commitp, NULL); - return rustsecp256k1zkp_v0_8_0_gej_is_infinity(&pj); + rustsecp256k1zkp_v0_10_0_ge_neg(&p, &p); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&pj, &p); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&pj, &pj, commitp, NULL); + return rustsecp256k1zkp_v0_10_0_gej_is_infinity(&pj); } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/ecdsa.h b/secp256k1-zkp-sys/depend/secp256k1/src/ecdsa.h index 50eefda8..f7376280 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/ecdsa.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/ecdsa.h @@ -13,9 +13,9 @@ #include "group.h" #include "ecmult.h" -static int rustsecp256k1zkp_v0_8_0_ecdsa_sig_parse(rustsecp256k1zkp_v0_8_0_scalar *r, rustsecp256k1zkp_v0_8_0_scalar *s, const unsigned char *sig, size_t size); -static int rustsecp256k1zkp_v0_8_0_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *s); -static int rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(const rustsecp256k1zkp_v0_8_0_scalar* r, const rustsecp256k1zkp_v0_8_0_scalar* s, const rustsecp256k1zkp_v0_8_0_ge *pubkey, const rustsecp256k1zkp_v0_8_0_scalar *message); -static int rustsecp256k1zkp_v0_8_0_ecdsa_sig_sign(const rustsecp256k1zkp_v0_8_0_ecmult_gen_context *ctx, rustsecp256k1zkp_v0_8_0_scalar* r, rustsecp256k1zkp_v0_8_0_scalar* s, const rustsecp256k1zkp_v0_8_0_scalar *seckey, const rustsecp256k1zkp_v0_8_0_scalar *message, const rustsecp256k1zkp_v0_8_0_scalar *nonce, int *recid); +static int rustsecp256k1zkp_v0_10_0_ecdsa_sig_parse(rustsecp256k1zkp_v0_10_0_scalar *r, rustsecp256k1zkp_v0_10_0_scalar *s, const unsigned char *sig, size_t size); +static int rustsecp256k1zkp_v0_10_0_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *s); +static int rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(const rustsecp256k1zkp_v0_10_0_scalar* r, const rustsecp256k1zkp_v0_10_0_scalar* s, const rustsecp256k1zkp_v0_10_0_ge *pubkey, const rustsecp256k1zkp_v0_10_0_scalar *message); +static int rustsecp256k1zkp_v0_10_0_ecdsa_sig_sign(const rustsecp256k1zkp_v0_10_0_ecmult_gen_context *ctx, rustsecp256k1zkp_v0_10_0_scalar* r, rustsecp256k1zkp_v0_10_0_scalar* s, const rustsecp256k1zkp_v0_10_0_scalar *seckey, const rustsecp256k1zkp_v0_10_0_scalar *message, const rustsecp256k1zkp_v0_10_0_scalar *nonce, int *recid); #endif /* SECP256K1_ECDSA_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/ecdsa_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/ecdsa_impl.h index bda3f1f6..46366f3a 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/ecdsa_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/ecdsa_impl.h @@ -16,37 +16,24 @@ #include "ecdsa.h" /** Group order for secp256k1 defined as 'n' in "Standards for Efficient Cryptography" (SEC2) 2.7.1 - * sage: for t in xrange(1023, -1, -1): - * .. p = 2**256 - 2**32 - t - * .. if p.is_prime(): - * .. print '%x'%p - * .. break - * 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f' - * sage: a = 0 - * sage: b = 7 - * sage: F = FiniteField (p) - * sage: '%x' % (EllipticCurve ([F (a), F (b)]).order()) - * 'fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141' + * $ sage -c 'load("rustsecp256k1zkp_v0_10_0_params.sage"); print(hex(N))' + * 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 */ -static const rustsecp256k1zkp_v0_8_0_fe rustsecp256k1zkp_v0_8_0_ecdsa_const_order_as_fe = SECP256K1_FE_CONST( +static const rustsecp256k1zkp_v0_10_0_fe rustsecp256k1zkp_v0_10_0_ecdsa_const_order_as_fe = SECP256K1_FE_CONST( 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFEUL, 0xBAAEDCE6UL, 0xAF48A03BUL, 0xBFD25E8CUL, 0xD0364141UL ); /** Difference between field and order, values 'p' and 'n' values defined in * "Standards for Efficient Cryptography" (SEC2) 2.7.1. - * sage: p = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F - * sage: a = 0 - * sage: b = 7 - * sage: F = FiniteField (p) - * sage: '%x' % (p - EllipticCurve ([F (a), F (b)]).order()) - * '14551231950b75fc4402da1722fc9baee' + * $ sage -c 'load("rustsecp256k1zkp_v0_10_0_params.sage"); print(hex(P-N))' + * 0x14551231950b75fc4402da1722fc9baee */ -static const rustsecp256k1zkp_v0_8_0_fe rustsecp256k1zkp_v0_8_0_ecdsa_const_p_minus_order = SECP256K1_FE_CONST( +static const rustsecp256k1zkp_v0_10_0_fe rustsecp256k1zkp_v0_10_0_ecdsa_const_p_minus_order = SECP256K1_FE_CONST( 0, 0, 0, 1, 0x45512319UL, 0x50B75FC4UL, 0x402DA172UL, 0x2FC9BAEEUL ); -static int rustsecp256k1zkp_v0_8_0_der_read_len(size_t *len, const unsigned char **sigp, const unsigned char *sigend) { +static int rustsecp256k1zkp_v0_10_0_der_read_len(size_t *len, const unsigned char **sigp, const unsigned char *sigend) { size_t lenleft; unsigned char b1; VERIFY_CHECK(len != NULL); @@ -79,8 +66,7 @@ static int rustsecp256k1zkp_v0_8_0_der_read_len(size_t *len, const unsigned char } if (lenleft > sizeof(size_t)) { /* The resulting length would exceed the range of a size_t, so - * certainly longer than the passed array size. - */ + * it is certainly longer than the passed array size. */ return 0; } while (lenleft > 0) { @@ -89,7 +75,9 @@ static int rustsecp256k1zkp_v0_8_0_der_read_len(size_t *len, const unsigned char lenleft--; } if (*len > (size_t)(sigend - *sigp)) { - /* Result exceeds the length of the passed array. */ + /* Result exceeds the length of the passed array. + (Checking this is the responsibility of the caller but it + can't hurt do it here, too.) */ return 0; } if (*len < 128) { @@ -99,7 +87,7 @@ static int rustsecp256k1zkp_v0_8_0_der_read_len(size_t *len, const unsigned char return 1; } -static int rustsecp256k1zkp_v0_8_0_der_parse_integer(rustsecp256k1zkp_v0_8_0_scalar *r, const unsigned char **sig, const unsigned char *sigend) { +static int rustsecp256k1zkp_v0_10_0_der_parse_integer(rustsecp256k1zkp_v0_10_0_scalar *r, const unsigned char **sig, const unsigned char *sigend) { int overflow = 0; unsigned char ra[32] = {0}; size_t rlen; @@ -109,7 +97,7 @@ static int rustsecp256k1zkp_v0_8_0_der_parse_integer(rustsecp256k1zkp_v0_8_0_sca return 0; } (*sig)++; - if (rustsecp256k1zkp_v0_8_0_der_read_len(&rlen, sig, sigend) == 0) { + if (rustsecp256k1zkp_v0_10_0_der_read_len(&rlen, sig, sigend) == 0) { return 0; } if (rlen == 0 || rlen > (size_t)(sigend - *sig)) { @@ -141,23 +129,23 @@ static int rustsecp256k1zkp_v0_8_0_der_parse_integer(rustsecp256k1zkp_v0_8_0_sca } if (!overflow) { if (rlen) memcpy(ra + 32 - rlen, *sig, rlen); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(r, ra, &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(r, ra, &overflow); } if (overflow) { - rustsecp256k1zkp_v0_8_0_scalar_set_int(r, 0); + rustsecp256k1zkp_v0_10_0_scalar_set_int(r, 0); } (*sig) += rlen; return 1; } -static int rustsecp256k1zkp_v0_8_0_ecdsa_sig_parse(rustsecp256k1zkp_v0_8_0_scalar *rr, rustsecp256k1zkp_v0_8_0_scalar *rs, const unsigned char *sig, size_t size) { +static int rustsecp256k1zkp_v0_10_0_ecdsa_sig_parse(rustsecp256k1zkp_v0_10_0_scalar *rr, rustsecp256k1zkp_v0_10_0_scalar *rs, const unsigned char *sig, size_t size) { const unsigned char *sigend = sig + size; size_t rlen; if (sig == sigend || *(sig++) != 0x30) { /* The encoding doesn't start with a constructed sequence (X.690-0207 8.9.1). */ return 0; } - if (rustsecp256k1zkp_v0_8_0_der_read_len(&rlen, &sig, sigend) == 0) { + if (rustsecp256k1zkp_v0_10_0_der_read_len(&rlen, &sig, sigend) == 0) { return 0; } if (rlen != (size_t)(sigend - sig)) { @@ -165,10 +153,10 @@ static int rustsecp256k1zkp_v0_8_0_ecdsa_sig_parse(rustsecp256k1zkp_v0_8_0_scala return 0; } - if (!rustsecp256k1zkp_v0_8_0_der_parse_integer(rr, &sig, sigend)) { + if (!rustsecp256k1zkp_v0_10_0_der_parse_integer(rr, &sig, sigend)) { return 0; } - if (!rustsecp256k1zkp_v0_8_0_der_parse_integer(rs, &sig, sigend)) { + if (!rustsecp256k1zkp_v0_10_0_der_parse_integer(rs, &sig, sigend)) { return 0; } @@ -180,12 +168,12 @@ static int rustsecp256k1zkp_v0_8_0_ecdsa_sig_parse(rustsecp256k1zkp_v0_8_0_scala return 1; } -static int rustsecp256k1zkp_v0_8_0_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const rustsecp256k1zkp_v0_8_0_scalar* ar, const rustsecp256k1zkp_v0_8_0_scalar* as) { +static int rustsecp256k1zkp_v0_10_0_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const rustsecp256k1zkp_v0_10_0_scalar* ar, const rustsecp256k1zkp_v0_10_0_scalar* as) { unsigned char r[33] = {0}, s[33] = {0}; unsigned char *rp = r, *sp = s; size_t lenR = 33, lenS = 33; - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&r[1], ar); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&s[1], as); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&r[1], ar); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&s[1], as); while (lenR > 1 && rp[0] == 0 && rp[1] < 0x80) { lenR--; rp++; } while (lenS > 1 && sp[0] == 0 && sp[1] < 0x80) { lenS--; sp++; } if (*size < 6+lenS+lenR) { @@ -204,42 +192,43 @@ static int rustsecp256k1zkp_v0_8_0_ecdsa_sig_serialize(unsigned char *sig, size_ return 1; } -static int rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(const rustsecp256k1zkp_v0_8_0_scalar *sigr, const rustsecp256k1zkp_v0_8_0_scalar *sigs, const rustsecp256k1zkp_v0_8_0_ge *pubkey, const rustsecp256k1zkp_v0_8_0_scalar *message) { +static int rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(const rustsecp256k1zkp_v0_10_0_scalar *sigr, const rustsecp256k1zkp_v0_10_0_scalar *sigs, const rustsecp256k1zkp_v0_10_0_ge *pubkey, const rustsecp256k1zkp_v0_10_0_scalar *message) { unsigned char c[32]; - rustsecp256k1zkp_v0_8_0_scalar sn, u1, u2; + rustsecp256k1zkp_v0_10_0_scalar sn, u1, u2; #if !defined(EXHAUSTIVE_TEST_ORDER) - rustsecp256k1zkp_v0_8_0_fe xr; + rustsecp256k1zkp_v0_10_0_fe xr; #endif - rustsecp256k1zkp_v0_8_0_gej pubkeyj; - rustsecp256k1zkp_v0_8_0_gej pr; + rustsecp256k1zkp_v0_10_0_gej pubkeyj; + rustsecp256k1zkp_v0_10_0_gej pr; - if (rustsecp256k1zkp_v0_8_0_scalar_is_zero(sigr) || rustsecp256k1zkp_v0_8_0_scalar_is_zero(sigs)) { + if (rustsecp256k1zkp_v0_10_0_scalar_is_zero(sigr) || rustsecp256k1zkp_v0_10_0_scalar_is_zero(sigs)) { return 0; } - rustsecp256k1zkp_v0_8_0_scalar_inverse_var(&sn, sigs); - rustsecp256k1zkp_v0_8_0_scalar_mul(&u1, &sn, message); - rustsecp256k1zkp_v0_8_0_scalar_mul(&u2, &sn, sigr); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&pubkeyj, pubkey); - rustsecp256k1zkp_v0_8_0_ecmult(&pr, &pubkeyj, &u2, &u1); - if (rustsecp256k1zkp_v0_8_0_gej_is_infinity(&pr)) { + rustsecp256k1zkp_v0_10_0_scalar_inverse_var(&sn, sigs); + rustsecp256k1zkp_v0_10_0_scalar_mul(&u1, &sn, message); + rustsecp256k1zkp_v0_10_0_scalar_mul(&u2, &sn, sigr); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&pubkeyj, pubkey); + rustsecp256k1zkp_v0_10_0_ecmult(&pr, &pubkeyj, &u2, &u1); + if (rustsecp256k1zkp_v0_10_0_gej_is_infinity(&pr)) { return 0; } #if defined(EXHAUSTIVE_TEST_ORDER) { - rustsecp256k1zkp_v0_8_0_scalar computed_r; - rustsecp256k1zkp_v0_8_0_ge pr_ge; - rustsecp256k1zkp_v0_8_0_ge_set_gej(&pr_ge, &pr); - rustsecp256k1zkp_v0_8_0_fe_normalize(&pr_ge.x); + rustsecp256k1zkp_v0_10_0_scalar computed_r; + rustsecp256k1zkp_v0_10_0_ge pr_ge; + rustsecp256k1zkp_v0_10_0_ge_set_gej(&pr_ge, &pr); + rustsecp256k1zkp_v0_10_0_fe_normalize(&pr_ge.x); - rustsecp256k1zkp_v0_8_0_fe_get_b32(c, &pr_ge.x); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&computed_r, c, NULL); - return rustsecp256k1zkp_v0_8_0_scalar_eq(sigr, &computed_r); + rustsecp256k1zkp_v0_10_0_fe_get_b32(c, &pr_ge.x); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&computed_r, c, NULL); + return rustsecp256k1zkp_v0_10_0_scalar_eq(sigr, &computed_r); } #else - rustsecp256k1zkp_v0_8_0_scalar_get_b32(c, sigr); - rustsecp256k1zkp_v0_8_0_fe_set_b32(&xr, c); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(c, sigr); + /* we can ignore the fe_set_b32_limit return value, because we know the input is in range */ + (void)rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&xr, c); /** We now have the recomputed R point in pr, and its claimed x coordinate (modulo n) * in xr. Naively, we would extract the x coordinate from pr (requiring a inversion modulo p), @@ -255,18 +244,18 @@ static int rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(const rustsecp256k1zkp_v0_8_ * <=> (xr * pr.z^2 mod p == pr.x) || (xr + n < p && (xr + n) * pr.z^2 mod p == pr.x) * * Thus, we can avoid the inversion, but we have to check both cases separately. - * rustsecp256k1zkp_v0_8_0_gej_eq_x implements the (xr * pr.z^2 mod p == pr.x) test. + * rustsecp256k1zkp_v0_10_0_gej_eq_x implements the (xr * pr.z^2 mod p == pr.x) test. */ - if (rustsecp256k1zkp_v0_8_0_gej_eq_x_var(&xr, &pr)) { + if (rustsecp256k1zkp_v0_10_0_gej_eq_x_var(&xr, &pr)) { /* xr * pr.z^2 mod p == pr.x, so the signature is valid. */ return 1; } - if (rustsecp256k1zkp_v0_8_0_fe_cmp_var(&xr, &rustsecp256k1zkp_v0_8_0_ecdsa_const_p_minus_order) >= 0) { + if (rustsecp256k1zkp_v0_10_0_fe_cmp_var(&xr, &rustsecp256k1zkp_v0_10_0_ecdsa_const_p_minus_order) >= 0) { /* xr + n >= p, so we can skip testing the second case. */ return 0; } - rustsecp256k1zkp_v0_8_0_fe_add(&xr, &rustsecp256k1zkp_v0_8_0_ecdsa_const_order_as_fe); - if (rustsecp256k1zkp_v0_8_0_gej_eq_x_var(&xr, &pr)) { + rustsecp256k1zkp_v0_10_0_fe_add(&xr, &rustsecp256k1zkp_v0_10_0_ecdsa_const_order_as_fe); + if (rustsecp256k1zkp_v0_10_0_gej_eq_x_var(&xr, &pr)) { /* (xr + n) * pr.z^2 mod p == pr.x, so the signature is valid. */ return 1; } @@ -274,42 +263,42 @@ static int rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(const rustsecp256k1zkp_v0_8_ #endif } -static int rustsecp256k1zkp_v0_8_0_ecdsa_sig_sign(const rustsecp256k1zkp_v0_8_0_ecmult_gen_context *ctx, rustsecp256k1zkp_v0_8_0_scalar *sigr, rustsecp256k1zkp_v0_8_0_scalar *sigs, const rustsecp256k1zkp_v0_8_0_scalar *seckey, const rustsecp256k1zkp_v0_8_0_scalar *message, const rustsecp256k1zkp_v0_8_0_scalar *nonce, int *recid) { +static int rustsecp256k1zkp_v0_10_0_ecdsa_sig_sign(const rustsecp256k1zkp_v0_10_0_ecmult_gen_context *ctx, rustsecp256k1zkp_v0_10_0_scalar *sigr, rustsecp256k1zkp_v0_10_0_scalar *sigs, const rustsecp256k1zkp_v0_10_0_scalar *seckey, const rustsecp256k1zkp_v0_10_0_scalar *message, const rustsecp256k1zkp_v0_10_0_scalar *nonce, int *recid) { unsigned char b[32]; - rustsecp256k1zkp_v0_8_0_gej rp; - rustsecp256k1zkp_v0_8_0_ge r; - rustsecp256k1zkp_v0_8_0_scalar n; + rustsecp256k1zkp_v0_10_0_gej rp; + rustsecp256k1zkp_v0_10_0_ge r; + rustsecp256k1zkp_v0_10_0_scalar n; int overflow = 0; int high; - rustsecp256k1zkp_v0_8_0_ecmult_gen(ctx, &rp, nonce); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&r, &rp); - rustsecp256k1zkp_v0_8_0_fe_normalize(&r.x); - rustsecp256k1zkp_v0_8_0_fe_normalize(&r.y); - rustsecp256k1zkp_v0_8_0_fe_get_b32(b, &r.x); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(sigr, b, &overflow); + rustsecp256k1zkp_v0_10_0_ecmult_gen(ctx, &rp, nonce); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&r, &rp); + rustsecp256k1zkp_v0_10_0_fe_normalize(&r.x); + rustsecp256k1zkp_v0_10_0_fe_normalize(&r.y); + rustsecp256k1zkp_v0_10_0_fe_get_b32(b, &r.x); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(sigr, b, &overflow); if (recid) { /* The overflow condition is cryptographically unreachable as hitting it requires finding the discrete log * of some P where P.x >= order, and only 1 in about 2^127 points meet this criteria. */ - *recid = (overflow << 1) | rustsecp256k1zkp_v0_8_0_fe_is_odd(&r.y); - } - rustsecp256k1zkp_v0_8_0_scalar_mul(&n, sigr, seckey); - rustsecp256k1zkp_v0_8_0_scalar_add(&n, &n, message); - rustsecp256k1zkp_v0_8_0_scalar_inverse(sigs, nonce); - rustsecp256k1zkp_v0_8_0_scalar_mul(sigs, sigs, &n); - rustsecp256k1zkp_v0_8_0_scalar_clear(&n); - rustsecp256k1zkp_v0_8_0_gej_clear(&rp); - rustsecp256k1zkp_v0_8_0_ge_clear(&r); - high = rustsecp256k1zkp_v0_8_0_scalar_is_high(sigs); - rustsecp256k1zkp_v0_8_0_scalar_cond_negate(sigs, high); + *recid = (overflow << 1) | rustsecp256k1zkp_v0_10_0_fe_is_odd(&r.y); + } + rustsecp256k1zkp_v0_10_0_scalar_mul(&n, sigr, seckey); + rustsecp256k1zkp_v0_10_0_scalar_add(&n, &n, message); + rustsecp256k1zkp_v0_10_0_scalar_inverse(sigs, nonce); + rustsecp256k1zkp_v0_10_0_scalar_mul(sigs, sigs, &n); + rustsecp256k1zkp_v0_10_0_scalar_clear(&n); + rustsecp256k1zkp_v0_10_0_gej_clear(&rp); + rustsecp256k1zkp_v0_10_0_ge_clear(&r); + high = rustsecp256k1zkp_v0_10_0_scalar_is_high(sigs); + rustsecp256k1zkp_v0_10_0_scalar_cond_negate(sigs, high); if (recid) { *recid ^= high; } /* P.x = order is on the curve, so technically sig->r could end up being zero, which would be an invalid signature. * This is cryptographically unreachable as hitting it requires finding the discrete log of P.x = N. */ - return (int)(!rustsecp256k1zkp_v0_8_0_scalar_is_zero(sigr)) & (int)(!rustsecp256k1zkp_v0_8_0_scalar_is_zero(sigs)); + return (int)(!rustsecp256k1zkp_v0_10_0_scalar_is_zero(sigr)) & (int)(!rustsecp256k1zkp_v0_10_0_scalar_is_zero(sigs)); } #endif /* SECP256K1_ECDSA_IMPL_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/eckey.h b/secp256k1-zkp-sys/depend/secp256k1/src/eckey.h index cc18fe9e..4bad71af 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/eckey.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/eckey.h @@ -14,12 +14,12 @@ #include "ecmult.h" #include "ecmult_gen.h" -static int rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(rustsecp256k1zkp_v0_8_0_ge *elem, const unsigned char *pub, size_t size); -static int rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(rustsecp256k1zkp_v0_8_0_ge *elem, unsigned char *pub, size_t *size, int compressed); +static int rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(rustsecp256k1zkp_v0_10_0_ge *elem, const unsigned char *pub, size_t size); +static int rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(rustsecp256k1zkp_v0_10_0_ge *elem, unsigned char *pub, size_t *size, int compressed); -static int rustsecp256k1zkp_v0_8_0_eckey_privkey_tweak_add(rustsecp256k1zkp_v0_8_0_scalar *key, const rustsecp256k1zkp_v0_8_0_scalar *tweak); -static int rustsecp256k1zkp_v0_8_0_eckey_pubkey_tweak_add(rustsecp256k1zkp_v0_8_0_ge *key, const rustsecp256k1zkp_v0_8_0_scalar *tweak); -static int rustsecp256k1zkp_v0_8_0_eckey_privkey_tweak_mul(rustsecp256k1zkp_v0_8_0_scalar *key, const rustsecp256k1zkp_v0_8_0_scalar *tweak); -static int rustsecp256k1zkp_v0_8_0_eckey_pubkey_tweak_mul(rustsecp256k1zkp_v0_8_0_ge *key, const rustsecp256k1zkp_v0_8_0_scalar *tweak); +static int rustsecp256k1zkp_v0_10_0_eckey_privkey_tweak_add(rustsecp256k1zkp_v0_10_0_scalar *key, const rustsecp256k1zkp_v0_10_0_scalar *tweak); +static int rustsecp256k1zkp_v0_10_0_eckey_pubkey_tweak_add(rustsecp256k1zkp_v0_10_0_ge *key, const rustsecp256k1zkp_v0_10_0_scalar *tweak); +static int rustsecp256k1zkp_v0_10_0_eckey_privkey_tweak_mul(rustsecp256k1zkp_v0_10_0_scalar *key, const rustsecp256k1zkp_v0_10_0_scalar *tweak); +static int rustsecp256k1zkp_v0_10_0_eckey_pubkey_tweak_mul(rustsecp256k1zkp_v0_10_0_ge *key, const rustsecp256k1zkp_v0_10_0_scalar *tweak); #endif /* SECP256K1_ECKEY_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/eckey_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/eckey_impl.h index 91ec7a12..04913ff8 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/eckey_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/eckey_impl.h @@ -14,82 +14,78 @@ #include "group.h" #include "ecmult_gen.h" -static int rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(rustsecp256k1zkp_v0_8_0_ge *elem, const unsigned char *pub, size_t size) { +static int rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(rustsecp256k1zkp_v0_10_0_ge *elem, const unsigned char *pub, size_t size) { if (size == 33 && (pub[0] == SECP256K1_TAG_PUBKEY_EVEN || pub[0] == SECP256K1_TAG_PUBKEY_ODD)) { - rustsecp256k1zkp_v0_8_0_fe x; - return rustsecp256k1zkp_v0_8_0_fe_set_b32(&x, pub+1) && rustsecp256k1zkp_v0_8_0_ge_set_xo_var(elem, &x, pub[0] == SECP256K1_TAG_PUBKEY_ODD); + rustsecp256k1zkp_v0_10_0_fe x; + return rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&x, pub+1) && rustsecp256k1zkp_v0_10_0_ge_set_xo_var(elem, &x, pub[0] == SECP256K1_TAG_PUBKEY_ODD); } else if (size == 65 && (pub[0] == SECP256K1_TAG_PUBKEY_UNCOMPRESSED || pub[0] == SECP256K1_TAG_PUBKEY_HYBRID_EVEN || pub[0] == SECP256K1_TAG_PUBKEY_HYBRID_ODD)) { - rustsecp256k1zkp_v0_8_0_fe x, y; - if (!rustsecp256k1zkp_v0_8_0_fe_set_b32(&x, pub+1) || !rustsecp256k1zkp_v0_8_0_fe_set_b32(&y, pub+33)) { + rustsecp256k1zkp_v0_10_0_fe x, y; + if (!rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&x, pub+1) || !rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&y, pub+33)) { return 0; } - rustsecp256k1zkp_v0_8_0_ge_set_xy(elem, &x, &y); + rustsecp256k1zkp_v0_10_0_ge_set_xy(elem, &x, &y); if ((pub[0] == SECP256K1_TAG_PUBKEY_HYBRID_EVEN || pub[0] == SECP256K1_TAG_PUBKEY_HYBRID_ODD) && - rustsecp256k1zkp_v0_8_0_fe_is_odd(&y) != (pub[0] == SECP256K1_TAG_PUBKEY_HYBRID_ODD)) { + rustsecp256k1zkp_v0_10_0_fe_is_odd(&y) != (pub[0] == SECP256K1_TAG_PUBKEY_HYBRID_ODD)) { return 0; } - return rustsecp256k1zkp_v0_8_0_ge_is_valid_var(elem); + return rustsecp256k1zkp_v0_10_0_ge_is_valid_var(elem); } else { return 0; } } -static int rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(rustsecp256k1zkp_v0_8_0_ge *elem, unsigned char *pub, size_t *size, int compressed) { - if (rustsecp256k1zkp_v0_8_0_ge_is_infinity(elem)) { +static int rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(rustsecp256k1zkp_v0_10_0_ge *elem, unsigned char *pub, size_t *size, int compressed) { + if (rustsecp256k1zkp_v0_10_0_ge_is_infinity(elem)) { return 0; } - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&elem->x); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&elem->y); - rustsecp256k1zkp_v0_8_0_fe_get_b32(&pub[1], &elem->x); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&elem->x); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&elem->y); + rustsecp256k1zkp_v0_10_0_fe_get_b32(&pub[1], &elem->x); if (compressed) { *size = 33; - pub[0] = rustsecp256k1zkp_v0_8_0_fe_is_odd(&elem->y) ? SECP256K1_TAG_PUBKEY_ODD : SECP256K1_TAG_PUBKEY_EVEN; + pub[0] = rustsecp256k1zkp_v0_10_0_fe_is_odd(&elem->y) ? SECP256K1_TAG_PUBKEY_ODD : SECP256K1_TAG_PUBKEY_EVEN; } else { *size = 65; pub[0] = SECP256K1_TAG_PUBKEY_UNCOMPRESSED; - rustsecp256k1zkp_v0_8_0_fe_get_b32(&pub[33], &elem->y); + rustsecp256k1zkp_v0_10_0_fe_get_b32(&pub[33], &elem->y); } return 1; } -static int rustsecp256k1zkp_v0_8_0_eckey_privkey_tweak_add(rustsecp256k1zkp_v0_8_0_scalar *key, const rustsecp256k1zkp_v0_8_0_scalar *tweak) { - rustsecp256k1zkp_v0_8_0_scalar_add(key, key, tweak); - return !rustsecp256k1zkp_v0_8_0_scalar_is_zero(key); +static int rustsecp256k1zkp_v0_10_0_eckey_privkey_tweak_add(rustsecp256k1zkp_v0_10_0_scalar *key, const rustsecp256k1zkp_v0_10_0_scalar *tweak) { + rustsecp256k1zkp_v0_10_0_scalar_add(key, key, tweak); + return !rustsecp256k1zkp_v0_10_0_scalar_is_zero(key); } -static int rustsecp256k1zkp_v0_8_0_eckey_pubkey_tweak_add(rustsecp256k1zkp_v0_8_0_ge *key, const rustsecp256k1zkp_v0_8_0_scalar *tweak) { - rustsecp256k1zkp_v0_8_0_gej pt; - rustsecp256k1zkp_v0_8_0_scalar one; - rustsecp256k1zkp_v0_8_0_gej_set_ge(&pt, key); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&one, 1); - rustsecp256k1zkp_v0_8_0_ecmult(&pt, &pt, &one, tweak); +static int rustsecp256k1zkp_v0_10_0_eckey_pubkey_tweak_add(rustsecp256k1zkp_v0_10_0_ge *key, const rustsecp256k1zkp_v0_10_0_scalar *tweak) { + rustsecp256k1zkp_v0_10_0_gej pt; + rustsecp256k1zkp_v0_10_0_gej_set_ge(&pt, key); + rustsecp256k1zkp_v0_10_0_ecmult(&pt, &pt, &rustsecp256k1zkp_v0_10_0_scalar_one, tweak); - if (rustsecp256k1zkp_v0_8_0_gej_is_infinity(&pt)) { + if (rustsecp256k1zkp_v0_10_0_gej_is_infinity(&pt)) { return 0; } - rustsecp256k1zkp_v0_8_0_ge_set_gej(key, &pt); + rustsecp256k1zkp_v0_10_0_ge_set_gej(key, &pt); return 1; } -static int rustsecp256k1zkp_v0_8_0_eckey_privkey_tweak_mul(rustsecp256k1zkp_v0_8_0_scalar *key, const rustsecp256k1zkp_v0_8_0_scalar *tweak) { +static int rustsecp256k1zkp_v0_10_0_eckey_privkey_tweak_mul(rustsecp256k1zkp_v0_10_0_scalar *key, const rustsecp256k1zkp_v0_10_0_scalar *tweak) { int ret; - ret = !rustsecp256k1zkp_v0_8_0_scalar_is_zero(tweak); + ret = !rustsecp256k1zkp_v0_10_0_scalar_is_zero(tweak); - rustsecp256k1zkp_v0_8_0_scalar_mul(key, key, tweak); + rustsecp256k1zkp_v0_10_0_scalar_mul(key, key, tweak); return ret; } -static int rustsecp256k1zkp_v0_8_0_eckey_pubkey_tweak_mul(rustsecp256k1zkp_v0_8_0_ge *key, const rustsecp256k1zkp_v0_8_0_scalar *tweak) { - rustsecp256k1zkp_v0_8_0_scalar zero; - rustsecp256k1zkp_v0_8_0_gej pt; - if (rustsecp256k1zkp_v0_8_0_scalar_is_zero(tweak)) { +static int rustsecp256k1zkp_v0_10_0_eckey_pubkey_tweak_mul(rustsecp256k1zkp_v0_10_0_ge *key, const rustsecp256k1zkp_v0_10_0_scalar *tweak) { + rustsecp256k1zkp_v0_10_0_gej pt; + if (rustsecp256k1zkp_v0_10_0_scalar_is_zero(tweak)) { return 0; } - rustsecp256k1zkp_v0_8_0_scalar_set_int(&zero, 0); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&pt, key); - rustsecp256k1zkp_v0_8_0_ecmult(&pt, &pt, tweak, &zero); - rustsecp256k1zkp_v0_8_0_ge_set_gej(key, &pt); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&pt, key); + rustsecp256k1zkp_v0_10_0_ecmult(&pt, &pt, tweak, &rustsecp256k1zkp_v0_10_0_scalar_zero); + rustsecp256k1zkp_v0_10_0_ge_set_gej(key, &pt); return 1; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/ecmult.h b/secp256k1-zkp-sys/depend/secp256k1/src/ecmult.h index 6c8c5077..c2578eda 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/ecmult.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/ecmult.h @@ -11,7 +11,18 @@ #include "scalar.h" #include "scratch.h" -/* Noone will ever need more than a window size of 24. The code might +#ifndef ECMULT_WINDOW_SIZE +# define ECMULT_WINDOW_SIZE 15 +# ifdef DEBUG_CONFIG +# pragma message DEBUG_CONFIG_MSG("ECMULT_WINDOW_SIZE undefined, assuming default value") +# endif +#endif + +#ifdef DEBUG_CONFIG +# pragma message DEBUG_CONFIG_DEF(ECMULT_WINDOW_SIZE) +#endif + +/* No one will ever need more than a window size of 24. The code might * be correct for larger values of ECMULT_WINDOW_SIZE but this is not * tested. * @@ -30,9 +41,9 @@ #define ECMULT_TABLE_SIZE(w) (1L << ((w)-2)) /** Double multiply: R = na*A + ng*G */ -static void rustsecp256k1zkp_v0_8_0_ecmult(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_gej *a, const rustsecp256k1zkp_v0_8_0_scalar *na, const rustsecp256k1zkp_v0_8_0_scalar *ng); +static void rustsecp256k1zkp_v0_10_0_ecmult(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_gej *a, const rustsecp256k1zkp_v0_10_0_scalar *na, const rustsecp256k1zkp_v0_10_0_scalar *ng); -typedef int (rustsecp256k1zkp_v0_8_0_ecmult_multi_callback)(rustsecp256k1zkp_v0_8_0_scalar *sc, rustsecp256k1zkp_v0_8_0_ge *pt, size_t idx, void *data); +typedef int (rustsecp256k1zkp_v0_10_0_ecmult_multi_callback)(rustsecp256k1zkp_v0_10_0_scalar *sc, rustsecp256k1zkp_v0_10_0_ge *pt, size_t idx, void *data); /** * Multi-multiply: R = inp_g_sc * G + sum_i ni * Ai. @@ -45,6 +56,6 @@ typedef int (rustsecp256k1zkp_v0_8_0_ecmult_multi_callback)(rustsecp256k1zkp_v0_ * 0 if there is not enough scratch space for a single point or * callback returns 0 */ -static int rustsecp256k1zkp_v0_8_0_ecmult_multi_var(const rustsecp256k1zkp_v0_8_0_callback* error_callback, rustsecp256k1zkp_v0_8_0_scratch *scratch, rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_scalar *inp_g_sc, rustsecp256k1zkp_v0_8_0_ecmult_multi_callback cb, void *cbdata, size_t n); +static int rustsecp256k1zkp_v0_10_0_ecmult_multi_var(const rustsecp256k1zkp_v0_10_0_callback* error_callback, rustsecp256k1zkp_v0_10_0_scratch *scratch, rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_scalar *inp_g_sc, rustsecp256k1zkp_v0_10_0_ecmult_multi_callback cb, void *cbdata, size_t n); #endif /* SECP256K1_ECMULT_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_compute_table.h b/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_compute_table.h index 33cef0be..278eff9e 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_compute_table.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_compute_table.h @@ -8,9 +8,9 @@ #define SECP256K1_ECMULT_COMPUTE_TABLE_H /* Construct table of all odd multiples of gen in range 1..(2**(window_g-1)-1). */ -static void rustsecp256k1zkp_v0_8_0_ecmult_compute_table(rustsecp256k1zkp_v0_8_0_ge_storage* table, int window_g, const rustsecp256k1zkp_v0_8_0_gej* gen); +static void rustsecp256k1zkp_v0_10_0_ecmult_compute_table(rustsecp256k1zkp_v0_10_0_ge_storage* table, int window_g, const rustsecp256k1zkp_v0_10_0_gej* gen); -/* Like rustsecp256k1zkp_v0_8_0_ecmult_compute_table, but one for both gen and gen*2^128. */ -static void rustsecp256k1zkp_v0_8_0_ecmult_compute_two_tables(rustsecp256k1zkp_v0_8_0_ge_storage* table, rustsecp256k1zkp_v0_8_0_ge_storage* table_128, int window_g, const rustsecp256k1zkp_v0_8_0_ge* gen); +/* Like rustsecp256k1zkp_v0_10_0_ecmult_compute_table, but one for both gen and gen*2^128. */ +static void rustsecp256k1zkp_v0_10_0_ecmult_compute_two_tables(rustsecp256k1zkp_v0_10_0_ge_storage* table, rustsecp256k1zkp_v0_10_0_ge_storage* table_128, int window_g, const rustsecp256k1zkp_v0_10_0_ge* gen); #endif /* SECP256K1_ECMULT_COMPUTE_TABLE_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_compute_table_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_compute_table_impl.h index 46fee9e5..2e096bfd 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_compute_table_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_compute_table_impl.h @@ -13,37 +13,37 @@ #include "ecmult.h" #include "util.h" -static void rustsecp256k1zkp_v0_8_0_ecmult_compute_table(rustsecp256k1zkp_v0_8_0_ge_storage* table, int window_g, const rustsecp256k1zkp_v0_8_0_gej* gen) { - rustsecp256k1zkp_v0_8_0_gej gj; - rustsecp256k1zkp_v0_8_0_ge ge, dgen; +static void rustsecp256k1zkp_v0_10_0_ecmult_compute_table(rustsecp256k1zkp_v0_10_0_ge_storage* table, int window_g, const rustsecp256k1zkp_v0_10_0_gej* gen) { + rustsecp256k1zkp_v0_10_0_gej gj; + rustsecp256k1zkp_v0_10_0_ge ge, dgen; int j; gj = *gen; - rustsecp256k1zkp_v0_8_0_ge_set_gej_var(&ge, &gj); - rustsecp256k1zkp_v0_8_0_ge_to_storage(&table[0], &ge); + rustsecp256k1zkp_v0_10_0_ge_set_gej_var(&ge, &gj); + rustsecp256k1zkp_v0_10_0_ge_to_storage(&table[0], &ge); - rustsecp256k1zkp_v0_8_0_gej_double_var(&gj, gen, NULL); - rustsecp256k1zkp_v0_8_0_ge_set_gej_var(&dgen, &gj); + rustsecp256k1zkp_v0_10_0_gej_double_var(&gj, gen, NULL); + rustsecp256k1zkp_v0_10_0_ge_set_gej_var(&dgen, &gj); for (j = 1; j < ECMULT_TABLE_SIZE(window_g); ++j) { - rustsecp256k1zkp_v0_8_0_gej_set_ge(&gj, &ge); - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&gj, &gj, &dgen, NULL); - rustsecp256k1zkp_v0_8_0_ge_set_gej_var(&ge, &gj); - rustsecp256k1zkp_v0_8_0_ge_to_storage(&table[j], &ge); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&gj, &ge); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&gj, &gj, &dgen, NULL); + rustsecp256k1zkp_v0_10_0_ge_set_gej_var(&ge, &gj); + rustsecp256k1zkp_v0_10_0_ge_to_storage(&table[j], &ge); } } -/* Like rustsecp256k1zkp_v0_8_0_ecmult_compute_table, but one for both gen and gen*2^128. */ -static void rustsecp256k1zkp_v0_8_0_ecmult_compute_two_tables(rustsecp256k1zkp_v0_8_0_ge_storage* table, rustsecp256k1zkp_v0_8_0_ge_storage* table_128, int window_g, const rustsecp256k1zkp_v0_8_0_ge* gen) { - rustsecp256k1zkp_v0_8_0_gej gj; +/* Like rustsecp256k1zkp_v0_10_0_ecmult_compute_table, but one for both gen and gen*2^128. */ +static void rustsecp256k1zkp_v0_10_0_ecmult_compute_two_tables(rustsecp256k1zkp_v0_10_0_ge_storage* table, rustsecp256k1zkp_v0_10_0_ge_storage* table_128, int window_g, const rustsecp256k1zkp_v0_10_0_ge* gen) { + rustsecp256k1zkp_v0_10_0_gej gj; int i; - rustsecp256k1zkp_v0_8_0_gej_set_ge(&gj, gen); - rustsecp256k1zkp_v0_8_0_ecmult_compute_table(table, window_g, &gj); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&gj, gen); + rustsecp256k1zkp_v0_10_0_ecmult_compute_table(table, window_g, &gj); for (i = 0; i < 128; ++i) { - rustsecp256k1zkp_v0_8_0_gej_double_var(&gj, &gj, NULL); + rustsecp256k1zkp_v0_10_0_gej_double_var(&gj, &gj, NULL); } - rustsecp256k1zkp_v0_8_0_ecmult_compute_table(table_128, window_g, &gj); + rustsecp256k1zkp_v0_10_0_ecmult_compute_table(table_128, window_g, &gj); } #endif /* SECP256K1_ECMULT_COMPUTE_TABLE_IMPL_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_const.h b/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_const.h index 5202c956..383ec56a 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_const.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_const.h @@ -11,11 +11,28 @@ #include "group.h" /** - * Multiply: R = q*A (in constant-time) - * Here `bits` should be set to the maximum bitlength of the _absolute value_ of `q`, plus - * one because we internally sometimes add 2 to the number during the WNAF conversion. - * A must not be infinity. + * Multiply: R = q*A (in constant-time for q) */ -static void rustsecp256k1zkp_v0_8_0_ecmult_const(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_ge *a, const rustsecp256k1zkp_v0_8_0_scalar *q, int bits); +static void rustsecp256k1zkp_v0_10_0_ecmult_const(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_ge *a, const rustsecp256k1zkp_v0_10_0_scalar *q); + +/** + * Same as rustsecp256k1zkp_v0_10_0_ecmult_const, but takes in an x coordinate of the base point + * only, specified as fraction n/d (numerator/denominator). Only the x coordinate of the result is + * returned. + * + * If known_on_curve is 0, a verification is performed that n/d is a valid X + * coordinate, and 0 is returned if not. Otherwise, 1 is returned. + * + * d being NULL is interpreted as d=1. If non-NULL, d must not be zero. q must not be zero. + * + * Constant time in the value of q, but not any other inputs. + */ +static int rustsecp256k1zkp_v0_10_0_ecmult_const_xonly( + rustsecp256k1zkp_v0_10_0_fe *r, + const rustsecp256k1zkp_v0_10_0_fe *n, + const rustsecp256k1zkp_v0_10_0_fe *d, + const rustsecp256k1zkp_v0_10_0_scalar *q, + int known_on_curve +); #endif /* SECP256K1_ECMULT_CONST_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_const_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_const_impl.h index 7e7ad75b..bd57dbda 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_const_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_const_impl.h @@ -1,5 +1,5 @@ /*********************************************************************** - * Copyright (c) 2015 Pieter Wuille, Andrew Poelstra * + * Copyright (c) 2015, 2022 Pieter Wuille, Andrew Poelstra * * Distributed under the MIT software license, see the accompanying * * file COPYING or https://www.opensource.org/licenses/mit-license.php.* ***********************************************************************/ @@ -12,220 +12,388 @@ #include "ecmult_const.h" #include "ecmult_impl.h" +#if defined(EXHAUSTIVE_TEST_ORDER) +/* We need 2^ECMULT_CONST_GROUP_SIZE - 1 to be less than EXHAUSTIVE_TEST_ORDER, because + * the tables cannot have infinities in them (this breaks the effective-affine technique's + * z-ratio tracking) */ +# if EXHAUSTIVE_TEST_ORDER == 199 +# define ECMULT_CONST_GROUP_SIZE 4 +# elif EXHAUSTIVE_TEST_ORDER == 13 +# define ECMULT_CONST_GROUP_SIZE 3 +# elif EXHAUSTIVE_TEST_ORDER == 7 +# define ECMULT_CONST_GROUP_SIZE 2 +# else +# error "Unknown EXHAUSTIVE_TEST_ORDER" +# endif +#else +/* Group size 4 or 5 appears optimal. */ +# define ECMULT_CONST_GROUP_SIZE 5 +#endif + +#define ECMULT_CONST_TABLE_SIZE (1L << (ECMULT_CONST_GROUP_SIZE - 1)) +#define ECMULT_CONST_GROUPS ((129 + ECMULT_CONST_GROUP_SIZE - 1) / ECMULT_CONST_GROUP_SIZE) +#define ECMULT_CONST_BITS (ECMULT_CONST_GROUPS * ECMULT_CONST_GROUP_SIZE) + /** Fill a table 'pre' with precomputed odd multiples of a. * * The resulting point set is brought to a single constant Z denominator, stores the X and Y - * coordinates as ge_storage points in pre, and stores the global Z in globalz. - * It only operates on tables sized for WINDOW_A wnaf multiples. + * coordinates as ge points in pre, and stores the global Z in globalz. + * + * 'pre' must be an array of size ECMULT_CONST_TABLE_SIZE. */ -static void rustsecp256k1zkp_v0_8_0_ecmult_odd_multiples_table_globalz_windowa(rustsecp256k1zkp_v0_8_0_ge *pre, rustsecp256k1zkp_v0_8_0_fe *globalz, const rustsecp256k1zkp_v0_8_0_gej *a) { - rustsecp256k1zkp_v0_8_0_fe zr[ECMULT_TABLE_SIZE(WINDOW_A)]; +static void rustsecp256k1zkp_v0_10_0_ecmult_const_odd_multiples_table_globalz(rustsecp256k1zkp_v0_10_0_ge *pre, rustsecp256k1zkp_v0_10_0_fe *globalz, const rustsecp256k1zkp_v0_10_0_gej *a) { + rustsecp256k1zkp_v0_10_0_fe zr[ECMULT_CONST_TABLE_SIZE]; - rustsecp256k1zkp_v0_8_0_ecmult_odd_multiples_table(ECMULT_TABLE_SIZE(WINDOW_A), pre, zr, globalz, a); - rustsecp256k1zkp_v0_8_0_ge_table_set_globalz(ECMULT_TABLE_SIZE(WINDOW_A), pre, zr); + rustsecp256k1zkp_v0_10_0_ecmult_odd_multiples_table(ECMULT_CONST_TABLE_SIZE, pre, zr, globalz, a); + rustsecp256k1zkp_v0_10_0_ge_table_set_globalz(ECMULT_CONST_TABLE_SIZE, pre, zr); } -/* This is like `ECMULT_TABLE_GET_GE` but is constant time */ -#define ECMULT_CONST_TABLE_GET_GE(r,pre,n,w) do { \ - int m = 0; \ - /* Extract the sign-bit for a constant time absolute-value. */ \ - int mask = (n) >> (sizeof(n) * CHAR_BIT - 1); \ - int abs_n = ((n) + mask) ^ mask; \ - int idx_n = abs_n >> 1; \ - rustsecp256k1zkp_v0_8_0_fe neg_y; \ - VERIFY_CHECK(((n) & 1) == 1); \ - VERIFY_CHECK((n) >= -((1 << ((w)-1)) - 1)); \ - VERIFY_CHECK((n) <= ((1 << ((w)-1)) - 1)); \ - VERIFY_SETUP(rustsecp256k1zkp_v0_8_0_fe_clear(&(r)->x)); \ - VERIFY_SETUP(rustsecp256k1zkp_v0_8_0_fe_clear(&(r)->y)); \ - /* Unconditionally set r->x = (pre)[m].x. r->y = (pre)[m].y. because it's either the correct one \ +/* Given a table 'pre' with odd multiples of a point, put in r the signed-bit multiplication of n with that point. + * + * For example, if ECMULT_CONST_GROUP_SIZE is 4, then pre is expected to contain 8 entries: + * [1*P, 3*P, 5*P, 7*P, 9*P, 11*P, 13*P, 15*P]. n is then expected to be a 4-bit integer (range 0-15), and its + * bits are interpreted as signs of powers of two to look up. + * + * For example, if n=4, which is 0100 in binary, which is interpreted as [- + - -], so the looked up value is + * [ -(2^3) + (2^2) - (2^1) - (2^0) ]*P = -7*P. Every valid n translates to an odd number in range [-15,15], + * which means we just need to look up one of the precomputed values, and optionally negate it. + */ +#define ECMULT_CONST_TABLE_GET_GE(r,pre,n) do { \ + unsigned int m = 0; \ + /* If the top bit of n is 0, we want the negation. */ \ + volatile unsigned int negative = ((n) >> (ECMULT_CONST_GROUP_SIZE - 1)) ^ 1; \ + /* Let n[i] be the i-th bit of n, then the index is + * sum(cnot(n[i]) * 2^i, i=0..l-2) + * where cnot(b) = b if n[l-1] = 1 and 1 - b otherwise. + * For example, if n = 4, in binary 0100, the index is 3, in binary 011. + * + * Proof: + * Let + * x = sum((2*n[i] - 1)*2^i, i=0..l-1) + * = 2*sum(n[i] * 2^i, i=0..l-1) - 2^l + 1 + * be the value represented by n. + * The index is (x - 1)/2 if x > 0 and -(x + 1)/2 otherwise. + * Case x > 0: + * n[l-1] = 1 + * index = sum(n[i] * 2^i, i=0..l-1) - 2^(l-1) + * = sum(n[i] * 2^i, i=0..l-2) + * Case x <= 0: + * n[l-1] = 0 + * index = -(2*sum(n[i] * 2^i, i=0..l-1) - 2^l + 2)/2 + * = 2^(l-1) - 1 - sum(n[i] * 2^i, i=0..l-1) + * = sum((1 - n[i]) * 2^i, i=0..l-2) + */ \ + unsigned int index = ((unsigned int)(-negative) ^ n) & ((1U << (ECMULT_CONST_GROUP_SIZE - 1)) - 1U); \ + rustsecp256k1zkp_v0_10_0_fe neg_y; \ + VERIFY_CHECK((n) < (1U << ECMULT_CONST_GROUP_SIZE)); \ + VERIFY_CHECK(index < (1U << (ECMULT_CONST_GROUP_SIZE - 1))); \ + /* Unconditionally set r->x = (pre)[m].x. r->y = (pre)[m].y. because it's either the correct one * or will get replaced in the later iterations, this is needed to make sure `r` is initialized. */ \ (r)->x = (pre)[m].x; \ (r)->y = (pre)[m].y; \ - for (m = 1; m < ECMULT_TABLE_SIZE(w); m++) { \ + for (m = 1; m < ECMULT_CONST_TABLE_SIZE; m++) { \ /* This loop is used to avoid secret data in array indices. See * the comment in ecmult_gen_impl.h for rationale. */ \ - rustsecp256k1zkp_v0_8_0_fe_cmov(&(r)->x, &(pre)[m].x, m == idx_n); \ - rustsecp256k1zkp_v0_8_0_fe_cmov(&(r)->y, &(pre)[m].y, m == idx_n); \ + rustsecp256k1zkp_v0_10_0_fe_cmov(&(r)->x, &(pre)[m].x, m == index); \ + rustsecp256k1zkp_v0_10_0_fe_cmov(&(r)->y, &(pre)[m].y, m == index); \ } \ (r)->infinity = 0; \ - rustsecp256k1zkp_v0_8_0_fe_negate(&neg_y, &(r)->y, 1); \ - rustsecp256k1zkp_v0_8_0_fe_cmov(&(r)->y, &neg_y, (n) != abs_n); \ + rustsecp256k1zkp_v0_10_0_fe_negate(&neg_y, &(r)->y, 1); \ + rustsecp256k1zkp_v0_10_0_fe_cmov(&(r)->y, &neg_y, negative); \ } while(0) -/** Convert a number to WNAF notation. - * The number becomes represented by sum(2^{wi} * wnaf[i], i=0..WNAF_SIZE(w)+1) - return_val. - * It has the following guarantees: - * - each wnaf[i] an odd integer between -(1 << w) and (1 << w) - * - each wnaf[i] is nonzero - * - the number of words set is always WNAF_SIZE(w) + 1 - * - * Adapted from `The Width-w NAF Method Provides Small Memory and Fast Elliptic Scalar - * Multiplications Secure against Side Channel Attacks`, Okeya and Tagaki. M. Joye (Ed.) - * CT-RSA 2003, LNCS 2612, pp. 328-443, 2003. Springer-Verlag Berlin Heidelberg 2003 - * - * Numbers reference steps of `Algorithm SPA-resistant Width-w NAF with Odd Scalar` on pp. 335 - */ -static int rustsecp256k1zkp_v0_8_0_wnaf_const(int *wnaf, const rustsecp256k1zkp_v0_8_0_scalar *scalar, int w, int size) { - int global_sign; - int skew; - int word = 0; - - /* 1 2 3 */ - int u_last; - int u; - - int flip; - rustsecp256k1zkp_v0_8_0_scalar s = *scalar; - - VERIFY_CHECK(w > 0); - VERIFY_CHECK(size > 0); - - /* Note that we cannot handle even numbers by negating them to be odd, as is - * done in other implementations, since if our scalars were specified to have - * width < 256 for performance reasons, their negations would have width 256 - * and we'd lose any performance benefit. Instead, we use a variation of a - * technique from Section 4.2 of the Okeya/Tagaki paper, which is to add 1 to the - * number we are encoding when it is even, returning a skew value indicating - * this, and having the caller compensate after doing the multiplication. - * - * In fact, we _do_ want to negate numbers to minimize their bit-lengths (and in - * particular, to ensure that the outputs from the endomorphism-split fit into - * 128 bits). If we negate, the parity of our number flips, affecting whether - * we want to add to the scalar to ensure that it's odd. */ - flip = rustsecp256k1zkp_v0_8_0_scalar_is_high(&s); - skew = flip ^ rustsecp256k1zkp_v0_8_0_scalar_is_even(&s); - rustsecp256k1zkp_v0_8_0_scalar_cadd_bit(&s, 0, skew); - global_sign = rustsecp256k1zkp_v0_8_0_scalar_cond_negate(&s, flip); - - /* 4 */ - u_last = rustsecp256k1zkp_v0_8_0_scalar_shr_int(&s, w); - do { - int even; - - /* 4.1 4.4 */ - u = rustsecp256k1zkp_v0_8_0_scalar_shr_int(&s, w); - /* 4.2 */ - even = ((u & 1) == 0); - /* In contrast to the original algorithm, u_last is always > 0 and - * therefore we do not need to check its sign. In particular, it's easy - * to see that u_last is never < 0 because u is never < 0. Moreover, - * u_last is never = 0 because u is never even after a loop - * iteration. The same holds analogously for the initial value of - * u_last (in the first loop iteration). */ - VERIFY_CHECK(u_last > 0); - VERIFY_CHECK((u_last & 1) == 1); - u += even; - u_last -= even * (1 << w); - - /* 4.3, adapted for global sign change */ - wnaf[word++] = u_last * global_sign; - - u_last = u; - } while (word * w < size); - wnaf[word] = u * global_sign; - - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_scalar_is_zero(&s)); - VERIFY_CHECK(word == WNAF_SIZE_BITS(size, w)); - return skew; -} +/* For K as defined in the comment of rustsecp256k1zkp_v0_10_0_ecmult_const, we have several precomputed + * formulas/constants. + * - in exhaustive test mode, we give an explicit expression to compute it at compile time: */ +#ifdef EXHAUSTIVE_TEST_ORDER +static const rustsecp256k1zkp_v0_10_0_scalar rustsecp256k1zkp_v0_10_0_ecmult_const_K = ((SECP256K1_SCALAR_CONST(0, 0, 0, (1U << (ECMULT_CONST_BITS - 128)) - 2U, 0, 0, 0, 0) + EXHAUSTIVE_TEST_ORDER - 1U) * (1U + EXHAUSTIVE_TEST_LAMBDA)) % EXHAUSTIVE_TEST_ORDER; +/* - for the real secp256k1 group we have constants for various ECMULT_CONST_BITS values. */ +#elif ECMULT_CONST_BITS == 129 +/* For GROUP_SIZE = 1,3. */ +static const rustsecp256k1zkp_v0_10_0_scalar rustsecp256k1zkp_v0_10_0_ecmult_const_K = SECP256K1_SCALAR_CONST(0xac9c52b3ul, 0x3fa3cf1ful, 0x5ad9e3fdul, 0x77ed9ba4ul, 0xa880b9fcul, 0x8ec739c2ul, 0xe0cfc810ul, 0xb51283ceul); +#elif ECMULT_CONST_BITS == 130 +/* For GROUP_SIZE = 2,5. */ +static const rustsecp256k1zkp_v0_10_0_scalar rustsecp256k1zkp_v0_10_0_ecmult_const_K = SECP256K1_SCALAR_CONST(0xa4e88a7dul, 0xcb13034eul, 0xc2bdd6bful, 0x7c118d6bul, 0x589ae848ul, 0x26ba29e4ul, 0xb5c2c1dcul, 0xde9798d9ul); +#elif ECMULT_CONST_BITS == 132 +/* For GROUP_SIZE = 4,6 */ +static const rustsecp256k1zkp_v0_10_0_scalar rustsecp256k1zkp_v0_10_0_ecmult_const_K = SECP256K1_SCALAR_CONST(0x76b1d93dul, 0x0fae3c6bul, 0x3215874bul, 0x94e93813ul, 0x7937fe0dul, 0xb66bcaaful, 0xb3749ca5ul, 0xd7b6171bul); +#else +# error "Unknown ECMULT_CONST_BITS" +#endif -static void rustsecp256k1zkp_v0_8_0_ecmult_const(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_ge *a, const rustsecp256k1zkp_v0_8_0_scalar *scalar, int size) { - rustsecp256k1zkp_v0_8_0_ge pre_a[ECMULT_TABLE_SIZE(WINDOW_A)]; - rustsecp256k1zkp_v0_8_0_ge tmpa; - rustsecp256k1zkp_v0_8_0_fe Z; - - int skew_1; - rustsecp256k1zkp_v0_8_0_ge pre_a_lam[ECMULT_TABLE_SIZE(WINDOW_A)]; - int wnaf_lam[1 + WNAF_SIZE(WINDOW_A - 1)]; - int skew_lam; - rustsecp256k1zkp_v0_8_0_scalar q_1, q_lam; - int wnaf_1[1 + WNAF_SIZE(WINDOW_A - 1)]; - - int i; - - /* build wnaf representation for q. */ - int rsize = size; - if (size > 128) { - rsize = 128; - /* split q into q_1 and q_lam (where q = q_1 + q_lam*lambda, and q_1 and q_lam are ~128 bit) */ - rustsecp256k1zkp_v0_8_0_scalar_split_lambda(&q_1, &q_lam, scalar); - skew_1 = rustsecp256k1zkp_v0_8_0_wnaf_const(wnaf_1, &q_1, WINDOW_A - 1, 128); - skew_lam = rustsecp256k1zkp_v0_8_0_wnaf_const(wnaf_lam, &q_lam, WINDOW_A - 1, 128); - } else - { - skew_1 = rustsecp256k1zkp_v0_8_0_wnaf_const(wnaf_1, scalar, WINDOW_A - 1, size); - skew_lam = 0; +static void rustsecp256k1zkp_v0_10_0_ecmult_const(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_ge *a, const rustsecp256k1zkp_v0_10_0_scalar *q) { + /* The approach below combines the signed-digit logic from Mike Hamburg's + * "Fast and compact elliptic-curve cryptography" (https://eprint.iacr.org/2012/309) + * Section 3.3, with the GLV endomorphism. + * + * The idea there is to interpret the bits of a scalar as signs (1 = +, 0 = -), and compute a + * point multiplication in that fashion. Let v be an n-bit non-negative integer (0 <= v < 2^n), + * and v[i] its i'th bit (so v = sum(v[i] * 2^i, i=0..n-1)). Then define: + * + * C_l(v, A) = sum((2*v[i] - 1) * 2^i*A, i=0..l-1) + * + * Then it holds that C_l(v, A) = sum((2*v[i] - 1) * 2^i*A, i=0..l-1) + * = (2*sum(v[i] * 2^i, i=0..l-1) + 1 - 2^l) * A + * = (2*v + 1 - 2^l) * A + * + * Thus, one can compute q*A as C_256((q + 2^256 - 1) / 2, A). This is the basis for the + * paper's signed-digit multi-comb algorithm for multiplication using a precomputed table. + * + * It is appealing to try to combine this with the GLV optimization: the idea that a scalar + * s can be written as s1 + lambda*s2, where lambda is a curve-specific constant such that + * lambda*A is easy to compute, and where s1 and s2 are small. In particular we have the + * rustsecp256k1zkp_v0_10_0_scalar_split_lambda function which performs such a split with the resulting s1 + * and s2 in range (-2^128, 2^128) mod n. This does work, but is uninteresting: + * + * To compute q*A: + * - Let s1, s2 = split_lambda(q) + * - Let R1 = C_256((s1 + 2^256 - 1) / 2, A) + * - Let R2 = C_256((s2 + 2^256 - 1) / 2, lambda*A) + * - Return R1 + R2 + * + * The issue is that while s1 and s2 are small-range numbers, (s1 + 2^256 - 1) / 2 (mod n) + * and (s2 + 2^256 - 1) / 2 (mod n) are not, undoing the benefit of the splitting. + * + * To make it work, we want to modify the input scalar q first, before splitting, and then only + * add a 2^128 offset of the split results (so that they end up in the single 129-bit range + * [0,2^129]). A slightly smaller offset would work due to the bounds on the split, but we pick + * 2^128 for simplicity. Let s be the scalar fed to split_lambda, and f(q) the function to + * compute it from q: + * + * To compute q*A: + * - Compute s = f(q) + * - Let s1, s2 = split_lambda(s) + * - Let v1 = s1 + 2^128 (mod n) + * - Let v2 = s2 + 2^128 (mod n) + * - Let R1 = C_l(v1, A) + * - Let R2 = C_l(v2, lambda*A) + * - Return R1 + R2 + * + * l will thus need to be at least 129, but we may overshoot by a few bits (see + * further), so keep it as a variable. + * + * To solve for s, we reason: + * q*A = R1 + R2 + * <=> q*A = C_l(s1 + 2^128, A) + C_l(s2 + 2^128, lambda*A) + * <=> q*A = (2*(s1 + 2^128) + 1 - 2^l) * A + (2*(s2 + 2^128) + 1 - 2^l) * lambda*A + * <=> q*A = (2*(s1 + s2*lambda) + (2^129 + 1 - 2^l) * (1 + lambda)) * A + * <=> q = 2*(s1 + s2*lambda) + (2^129 + 1 - 2^l) * (1 + lambda) (mod n) + * <=> q = 2*s + (2^129 + 1 - 2^l) * (1 + lambda) (mod n) + * <=> s = (q + (2^l - 2^129 - 1) * (1 + lambda)) / 2 (mod n) + * <=> f(q) = (q + K) / 2 (mod n) + * where K = (2^l - 2^129 - 1)*(1 + lambda) (mod n) + * + * We will process the computation of C_l(v1, A) and C_l(v2, lambda*A) in groups of + * ECMULT_CONST_GROUP_SIZE, so we set l to the smallest multiple of ECMULT_CONST_GROUP_SIZE + * that is not less than 129; this equals ECMULT_CONST_BITS. + */ + + /* The offset to add to s1 and s2 to make them non-negative. Equal to 2^128. */ + static const rustsecp256k1zkp_v0_10_0_scalar S_OFFSET = SECP256K1_SCALAR_CONST(0, 0, 0, 1, 0, 0, 0, 0); + rustsecp256k1zkp_v0_10_0_scalar s, v1, v2; + rustsecp256k1zkp_v0_10_0_ge pre_a[ECMULT_CONST_TABLE_SIZE]; + rustsecp256k1zkp_v0_10_0_ge pre_a_lam[ECMULT_CONST_TABLE_SIZE]; + rustsecp256k1zkp_v0_10_0_fe global_z; + int group, i; + + /* We're allowed to be non-constant time in the point, and the code below (in particular, + * rustsecp256k1zkp_v0_10_0_ecmult_const_odd_multiples_table_globalz) cannot deal with infinity in a + * constant-time manner anyway. */ + if (rustsecp256k1zkp_v0_10_0_ge_is_infinity(a)) { + rustsecp256k1zkp_v0_10_0_gej_set_infinity(r); + return; } - /* Calculate odd multiples of a. + /* Compute v1 and v2. */ + rustsecp256k1zkp_v0_10_0_scalar_add(&s, q, &rustsecp256k1zkp_v0_10_0_ecmult_const_K); + rustsecp256k1zkp_v0_10_0_scalar_half(&s, &s); + rustsecp256k1zkp_v0_10_0_scalar_split_lambda(&v1, &v2, &s); + rustsecp256k1zkp_v0_10_0_scalar_add(&v1, &v1, &S_OFFSET); + rustsecp256k1zkp_v0_10_0_scalar_add(&v2, &v2, &S_OFFSET); + +#ifdef VERIFY + /* Verify that v1 and v2 are in range [0, 2^129-1]. */ + for (i = 129; i < 256; ++i) { + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_scalar_get_bits(&v1, i, 1) == 0); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_scalar_get_bits(&v2, i, 1) == 0); + } +#endif + + /* Calculate odd multiples of A and A*lambda. * All multiples are brought to the same Z 'denominator', which is stored - * in Z. Due to secp256k1' isomorphism we can do all operations pretending + * in global_z. Due to secp256k1' isomorphism we can do all operations pretending * that the Z coordinate was 1, use affine addition formulae, and correct * the Z coordinate of the result once at the end. */ - VERIFY_CHECK(!a->infinity); - rustsecp256k1zkp_v0_8_0_gej_set_ge(r, a); - rustsecp256k1zkp_v0_8_0_ecmult_odd_multiples_table_globalz_windowa(pre_a, &Z, r); - for (i = 0; i < ECMULT_TABLE_SIZE(WINDOW_A); i++) { - rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&pre_a[i].y); + rustsecp256k1zkp_v0_10_0_gej_set_ge(r, a); + rustsecp256k1zkp_v0_10_0_ecmult_const_odd_multiples_table_globalz(pre_a, &global_z, r); + for (i = 0; i < ECMULT_CONST_TABLE_SIZE; i++) { + rustsecp256k1zkp_v0_10_0_ge_mul_lambda(&pre_a_lam[i], &pre_a[i]); } - if (size > 128) { - for (i = 0; i < ECMULT_TABLE_SIZE(WINDOW_A); i++) { - rustsecp256k1zkp_v0_8_0_ge_mul_lambda(&pre_a_lam[i], &pre_a[i]); - } - } - - /* first loop iteration (separated out so we can directly set r, rather - * than having it start at infinity, get doubled several times, then have - * its new value added to it) */ - i = wnaf_1[WNAF_SIZE_BITS(rsize, WINDOW_A - 1)]; - VERIFY_CHECK(i != 0); - ECMULT_CONST_TABLE_GET_GE(&tmpa, pre_a, i, WINDOW_A); - rustsecp256k1zkp_v0_8_0_gej_set_ge(r, &tmpa); - if (size > 128) { - i = wnaf_lam[WNAF_SIZE_BITS(rsize, WINDOW_A - 1)]; - VERIFY_CHECK(i != 0); - ECMULT_CONST_TABLE_GET_GE(&tmpa, pre_a_lam, i, WINDOW_A); - rustsecp256k1zkp_v0_8_0_gej_add_ge(r, r, &tmpa); - } - /* remaining loop iterations */ - for (i = WNAF_SIZE_BITS(rsize, WINDOW_A - 1) - 1; i >= 0; i--) { - int n; + /* Next, we compute r = C_l(v1, A) + C_l(v2, lambda*A). + * + * We proceed in groups of ECMULT_CONST_GROUP_SIZE bits, operating on that many bits + * at a time, from high in v1, v2 to low. Call these bits1 (from v1) and bits2 (from v2). + * + * Now note that ECMULT_CONST_TABLE_GET_GE(&t, pre_a, bits1) loads into t a point equal + * to C_{ECMULT_CONST_GROUP_SIZE}(bits1, A), and analogously for pre_lam_a / bits2. + * This means that all we need to do is add these looked up values together, multiplied + * by 2^(ECMULT_GROUP_SIZE * group). + */ + for (group = ECMULT_CONST_GROUPS - 1; group >= 0; --group) { + /* Using the _var get_bits function is ok here, since it's only variable in offset and count, not in the scalar. */ + unsigned int bits1 = rustsecp256k1zkp_v0_10_0_scalar_get_bits_var(&v1, group * ECMULT_CONST_GROUP_SIZE, ECMULT_CONST_GROUP_SIZE); + unsigned int bits2 = rustsecp256k1zkp_v0_10_0_scalar_get_bits_var(&v2, group * ECMULT_CONST_GROUP_SIZE, ECMULT_CONST_GROUP_SIZE); + rustsecp256k1zkp_v0_10_0_ge t; int j; - for (j = 0; j < WINDOW_A - 1; ++j) { - rustsecp256k1zkp_v0_8_0_gej_double(r, r); - } - n = wnaf_1[i]; - ECMULT_CONST_TABLE_GET_GE(&tmpa, pre_a, n, WINDOW_A); - VERIFY_CHECK(n != 0); - rustsecp256k1zkp_v0_8_0_gej_add_ge(r, r, &tmpa); - if (size > 128) { - n = wnaf_lam[i]; - ECMULT_CONST_TABLE_GET_GE(&tmpa, pre_a_lam, n, WINDOW_A); - VERIFY_CHECK(n != 0); - rustsecp256k1zkp_v0_8_0_gej_add_ge(r, r, &tmpa); + ECMULT_CONST_TABLE_GET_GE(&t, pre_a, bits1); + if (group == ECMULT_CONST_GROUPS - 1) { + /* Directly set r in the first iteration. */ + rustsecp256k1zkp_v0_10_0_gej_set_ge(r, &t); + } else { + /* Shift the result so far up. */ + for (j = 0; j < ECMULT_CONST_GROUP_SIZE; ++j) { + rustsecp256k1zkp_v0_10_0_gej_double(r, r); + } + rustsecp256k1zkp_v0_10_0_gej_add_ge(r, r, &t); } + ECMULT_CONST_TABLE_GET_GE(&t, pre_a_lam, bits2); + rustsecp256k1zkp_v0_10_0_gej_add_ge(r, r, &t); } - { - /* Correct for wNAF skew */ - rustsecp256k1zkp_v0_8_0_gej tmpj; + /* Map the result back to the secp256k1 curve from the isomorphic curve. */ + rustsecp256k1zkp_v0_10_0_fe_mul(&r->z, &r->z, &global_z); +} + +static int rustsecp256k1zkp_v0_10_0_ecmult_const_xonly(rustsecp256k1zkp_v0_10_0_fe* r, const rustsecp256k1zkp_v0_10_0_fe *n, const rustsecp256k1zkp_v0_10_0_fe *d, const rustsecp256k1zkp_v0_10_0_scalar *q, int known_on_curve) { + + /* This algorithm is a generalization of Peter Dettman's technique for + * avoiding the square root in a random-basepoint x-only multiplication + * on a Weierstrass curve: + * https://mailarchive.ietf.org/arch/msg/cfrg/7DyYY6gg32wDgHAhgSb6XxMDlJA/ + * + * + * === Background: the effective affine technique === + * + * Let phi_u be the isomorphism that maps (x, y) on secp256k1 curve y^2 = x^3 + 7 to + * x' = u^2*x, y' = u^3*y on curve y'^2 = x'^3 + u^6*7. This new curve has the same order as + * the original (it is isomorphic), but moreover, has the same addition/doubling formulas, as + * the curve b=7 coefficient does not appear in those formulas (or at least does not appear in + * the formulas implemented in this codebase, both affine and Jacobian). See also Example 9.5.2 + * in https://www.math.auckland.ac.nz/~sgal018/crypto-book/ch9.pdf. + * + * This means any linear combination of secp256k1 points can be computed by applying phi_u + * (with non-zero u) on all input points (including the generator, if used), computing the + * linear combination on the isomorphic curve (using the same group laws), and then applying + * phi_u^{-1} to get back to secp256k1. + * + * Switching to Jacobian coordinates, note that phi_u applied to (X, Y, Z) is simply + * (X, Y, Z/u). Thus, if we want to compute (X1, Y1, Z) + (X2, Y2, Z), with identical Z + * coordinates, we can use phi_Z to transform it to (X1, Y1, 1) + (X2, Y2, 1) on an isomorphic + * curve where the affine addition formula can be used instead. + * If (X3, Y3, Z3) = (X1, Y1) + (X2, Y2) on that curve, then our answer on secp256k1 is + * (X3, Y3, Z3*Z). + * + * This is the effective affine technique: if we have a linear combination of group elements + * to compute, and all those group elements have the same Z coordinate, we can simply pretend + * that all those Z coordinates are 1, perform the computation that way, and then multiply the + * original Z coordinate back in. + * + * The technique works on any a=0 short Weierstrass curve. It is possible to generalize it to + * other curves too, but there the isomorphic curves will have different 'a' coefficients, + * which typically does affect the group laws. + * + * + * === Avoiding the square root for x-only point multiplication === + * + * In this function, we want to compute the X coordinate of q*(n/d, y), for + * y = sqrt((n/d)^3 + 7). Its negation would also be a valid Y coordinate, but by convention + * we pick whatever sqrt returns (which we assume to be a deterministic function). + * + * Let g = y^2*d^3 = n^3 + 7*d^3. This also means y = sqrt(g/d^3). + * Further let v = sqrt(d*g), which must exist as d*g = y^2*d^4 = (y*d^2)^2. + * + * The input point (n/d, y) also has Jacobian coordinates: + * + * (n/d, y, 1) + * = (n/d * v^2, y * v^3, v) + * = (n/d * d*g, y * sqrt(d^3*g^3), v) + * = (n/d * d*g, sqrt(y^2 * d^3*g^3), v) + * = (n*g, sqrt(g/d^3 * d^3*g^3), v) + * = (n*g, sqrt(g^4), v) + * = (n*g, g^2, v) + * + * It is easy to verify that both (n*g, g^2, v) and its negation (n*g, -g^2, v) have affine X + * coordinate n/d, and this holds even when the square root function doesn't have a + * deterministic sign. We choose the (n*g, g^2, v) version. + * + * Now switch to the effective affine curve using phi_v, where the input point has coordinates + * (n*g, g^2). Compute (X, Y, Z) = q * (n*g, g^2) there. + * + * Back on secp256k1, that means q * (n*g, g^2, v) = (X, Y, v*Z). This last point has affine X + * coordinate X / (v^2*Z^2) = X / (d*g*Z^2). Determining the affine Y coordinate would involve + * a square root, but as long as we only care about the resulting X coordinate, no square root + * is needed anywhere in this computation. + */ - rustsecp256k1zkp_v0_8_0_ge_neg(&tmpa, &pre_a[0]); - rustsecp256k1zkp_v0_8_0_gej_add_ge(&tmpj, r, &tmpa); - rustsecp256k1zkp_v0_8_0_gej_cmov(r, &tmpj, skew_1); + rustsecp256k1zkp_v0_10_0_fe g, i; + rustsecp256k1zkp_v0_10_0_ge p; + rustsecp256k1zkp_v0_10_0_gej rj; - if (size > 128) { - rustsecp256k1zkp_v0_8_0_ge_neg(&tmpa, &pre_a_lam[0]); - rustsecp256k1zkp_v0_8_0_gej_add_ge(&tmpj, r, &tmpa); - rustsecp256k1zkp_v0_8_0_gej_cmov(r, &tmpj, skew_lam); + /* Compute g = (n^3 + B*d^3). */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&g, n); + rustsecp256k1zkp_v0_10_0_fe_mul(&g, &g, n); + if (d) { + rustsecp256k1zkp_v0_10_0_fe b; + VERIFY_CHECK(!rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero(d)); + rustsecp256k1zkp_v0_10_0_fe_sqr(&b, d); + VERIFY_CHECK(SECP256K1_B <= 8); /* magnitude of b will be <= 8 after the next call */ + rustsecp256k1zkp_v0_10_0_fe_mul_int(&b, SECP256K1_B); + rustsecp256k1zkp_v0_10_0_fe_mul(&b, &b, d); + rustsecp256k1zkp_v0_10_0_fe_add(&g, &b); + if (!known_on_curve) { + /* We need to determine whether (n/d)^3 + 7 is square. + * + * is_square((n/d)^3 + 7) + * <=> is_square(((n/d)^3 + 7) * d^4) + * <=> is_square((n^3 + 7*d^3) * d) + * <=> is_square(g * d) + */ + rustsecp256k1zkp_v0_10_0_fe c; + rustsecp256k1zkp_v0_10_0_fe_mul(&c, &g, d); + if (!rustsecp256k1zkp_v0_10_0_fe_is_square_var(&c)) return 0; + } + } else { + rustsecp256k1zkp_v0_10_0_fe_add_int(&g, SECP256K1_B); + if (!known_on_curve) { + /* g at this point equals x^3 + 7. Test if it is square. */ + if (!rustsecp256k1zkp_v0_10_0_fe_is_square_var(&g)) return 0; } } - rustsecp256k1zkp_v0_8_0_fe_mul(&r->z, &r->z, &Z); + /* Compute base point P = (n*g, g^2), the effective affine version of (n*g, g^2, v), which has + * corresponding affine X coordinate n/d. */ + rustsecp256k1zkp_v0_10_0_fe_mul(&p.x, &g, n); + rustsecp256k1zkp_v0_10_0_fe_sqr(&p.y, &g); + p.infinity = 0; + + /* Perform x-only EC multiplication of P with q. */ + VERIFY_CHECK(!rustsecp256k1zkp_v0_10_0_scalar_is_zero(q)); + rustsecp256k1zkp_v0_10_0_ecmult_const(&rj, &p, q); + VERIFY_CHECK(!rustsecp256k1zkp_v0_10_0_gej_is_infinity(&rj)); + + /* The resulting (X, Y, Z) point on the effective-affine isomorphic curve corresponds to + * (X, Y, Z*v) on the secp256k1 curve. The affine version of that has X coordinate + * (X / (Z^2*d*g)). */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&i, &rj.z); + rustsecp256k1zkp_v0_10_0_fe_mul(&i, &i, &g); + if (d) rustsecp256k1zkp_v0_10_0_fe_mul(&i, &i, d); + rustsecp256k1zkp_v0_10_0_fe_inv(&i, &i); + rustsecp256k1zkp_v0_10_0_fe_mul(r, &rj.x, &i); + + return 1; } #endif /* SECP256K1_ECMULT_CONST_IMPL_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_gen.h b/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_gen.h index d8f5cd7a..830cad93 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_gen.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_gen.h @@ -10,9 +10,21 @@ #include "scalar.h" #include "group.h" +#ifndef ECMULT_GEN_PREC_BITS +# define ECMULT_GEN_PREC_BITS 4 +# ifdef DEBUG_CONFIG +# pragma message DEBUG_CONFIG_MSG("ECMULT_GEN_PREC_BITS undefined, assuming default value") +# endif +#endif + +#ifdef DEBUG_CONFIG +# pragma message DEBUG_CONFIG_DEF(ECMULT_GEN_PREC_BITS) +#endif + #if ECMULT_GEN_PREC_BITS != 2 && ECMULT_GEN_PREC_BITS != 4 && ECMULT_GEN_PREC_BITS != 8 # error "Set ECMULT_GEN_PREC_BITS to 2, 4 or 8." #endif + #define ECMULT_GEN_PREC_G(bits) (1 << bits) #define ECMULT_GEN_PREC_N(bits) (256 / bits) @@ -21,16 +33,16 @@ typedef struct { int built; /* Blinding values used when computing (n-b)G + bG. */ - rustsecp256k1zkp_v0_8_0_scalar blind; /* -b */ - rustsecp256k1zkp_v0_8_0_gej initial; /* bG */ -} rustsecp256k1zkp_v0_8_0_ecmult_gen_context; + rustsecp256k1zkp_v0_10_0_scalar blind; /* -b */ + rustsecp256k1zkp_v0_10_0_gej initial; /* bG */ +} rustsecp256k1zkp_v0_10_0_ecmult_gen_context; -static void rustsecp256k1zkp_v0_8_0_ecmult_gen_context_build(rustsecp256k1zkp_v0_8_0_ecmult_gen_context* ctx); -static void rustsecp256k1zkp_v0_8_0_ecmult_gen_context_clear(rustsecp256k1zkp_v0_8_0_ecmult_gen_context* ctx); +static void rustsecp256k1zkp_v0_10_0_ecmult_gen_context_build(rustsecp256k1zkp_v0_10_0_ecmult_gen_context* ctx); +static void rustsecp256k1zkp_v0_10_0_ecmult_gen_context_clear(rustsecp256k1zkp_v0_10_0_ecmult_gen_context* ctx); /** Multiply with the generator: R = a*G */ -static void rustsecp256k1zkp_v0_8_0_ecmult_gen(const rustsecp256k1zkp_v0_8_0_ecmult_gen_context* ctx, rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_scalar *a); +static void rustsecp256k1zkp_v0_10_0_ecmult_gen(const rustsecp256k1zkp_v0_10_0_ecmult_gen_context* ctx, rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_scalar *a); -static void rustsecp256k1zkp_v0_8_0_ecmult_gen_blind(rustsecp256k1zkp_v0_8_0_ecmult_gen_context *ctx, const unsigned char *seed32); +static void rustsecp256k1zkp_v0_10_0_ecmult_gen_blind(rustsecp256k1zkp_v0_10_0_ecmult_gen_context *ctx, const unsigned char *seed32); #endif /* SECP256K1_ECMULT_GEN_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_gen_compute_table.h b/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_gen_compute_table.h index 25d21afb..cffbaebb 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_gen_compute_table.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_gen_compute_table.h @@ -9,6 +9,6 @@ #include "ecmult_gen.h" -static void rustsecp256k1zkp_v0_8_0_ecmult_gen_compute_table(rustsecp256k1zkp_v0_8_0_ge_storage* table, const rustsecp256k1zkp_v0_8_0_ge* gen, int bits); +static void rustsecp256k1zkp_v0_10_0_ecmult_gen_compute_table(rustsecp256k1zkp_v0_10_0_ge_storage* table, const rustsecp256k1zkp_v0_10_0_ge* gen, int bits); #endif /* SECP256K1_ECMULT_GEN_COMPUTE_TABLE_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_gen_compute_table_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_gen_compute_table_impl.h index a21d2060..13ca3109 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_gen_compute_table_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_gen_compute_table_impl.h @@ -13,66 +13,69 @@ #include "ecmult_gen.h" #include "util.h" -static void rustsecp256k1zkp_v0_8_0_ecmult_gen_compute_table(rustsecp256k1zkp_v0_8_0_ge_storage* table, const rustsecp256k1zkp_v0_8_0_ge* gen, int bits) { +static void rustsecp256k1zkp_v0_10_0_ecmult_gen_compute_table(rustsecp256k1zkp_v0_10_0_ge_storage* table, const rustsecp256k1zkp_v0_10_0_ge* gen, int bits) { int g = ECMULT_GEN_PREC_G(bits); int n = ECMULT_GEN_PREC_N(bits); - rustsecp256k1zkp_v0_8_0_ge* prec = checked_malloc(&default_error_callback, n * g * sizeof(*prec)); - rustsecp256k1zkp_v0_8_0_gej gj; - rustsecp256k1zkp_v0_8_0_gej nums_gej; + rustsecp256k1zkp_v0_10_0_ge* prec = checked_malloc(&default_error_callback, n * g * sizeof(*prec)); + rustsecp256k1zkp_v0_10_0_gej gj; + rustsecp256k1zkp_v0_10_0_gej nums_gej; int i, j; + VERIFY_CHECK(g > 0); + VERIFY_CHECK(n > 0); + /* get the generator */ - rustsecp256k1zkp_v0_8_0_gej_set_ge(&gj, gen); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&gj, gen); /* Construct a group element with no known corresponding scalar (nothing up my sleeve). */ { static const unsigned char nums_b32[33] = "The scalar for this x is unknown"; - rustsecp256k1zkp_v0_8_0_fe nums_x; - rustsecp256k1zkp_v0_8_0_ge nums_ge; + rustsecp256k1zkp_v0_10_0_fe nums_x; + rustsecp256k1zkp_v0_10_0_ge nums_ge; int r; - r = rustsecp256k1zkp_v0_8_0_fe_set_b32(&nums_x, nums_b32); + r = rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&nums_x, nums_b32); (void)r; VERIFY_CHECK(r); - r = rustsecp256k1zkp_v0_8_0_ge_set_xo_var(&nums_ge, &nums_x, 0); + r = rustsecp256k1zkp_v0_10_0_ge_set_xo_var(&nums_ge, &nums_x, 0); (void)r; VERIFY_CHECK(r); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&nums_gej, &nums_ge); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&nums_gej, &nums_ge); /* Add G to make the bits in x uniformly distributed. */ - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&nums_gej, &nums_gej, gen, NULL); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&nums_gej, &nums_gej, gen, NULL); } /* compute prec. */ { - rustsecp256k1zkp_v0_8_0_gej gbase; - rustsecp256k1zkp_v0_8_0_gej numsbase; - rustsecp256k1zkp_v0_8_0_gej* precj = checked_malloc(&default_error_callback, n * g * sizeof(*precj)); /* Jacobian versions of prec. */ + rustsecp256k1zkp_v0_10_0_gej gbase; + rustsecp256k1zkp_v0_10_0_gej numsbase; + rustsecp256k1zkp_v0_10_0_gej* precj = checked_malloc(&default_error_callback, n * g * sizeof(*precj)); /* Jacobian versions of prec. */ gbase = gj; /* PREC_G^j * G */ numsbase = nums_gej; /* 2^j * nums. */ for (j = 0; j < n; j++) { /* Set precj[j*PREC_G .. j*PREC_G+(PREC_G-1)] to (numsbase, numsbase + gbase, ..., numsbase + (PREC_G-1)*gbase). */ precj[j*g] = numsbase; for (i = 1; i < g; i++) { - rustsecp256k1zkp_v0_8_0_gej_add_var(&precj[j*g + i], &precj[j*g + i - 1], &gbase, NULL); + rustsecp256k1zkp_v0_10_0_gej_add_var(&precj[j*g + i], &precj[j*g + i - 1], &gbase, NULL); } /* Multiply gbase by PREC_G. */ for (i = 0; i < bits; i++) { - rustsecp256k1zkp_v0_8_0_gej_double_var(&gbase, &gbase, NULL); + rustsecp256k1zkp_v0_10_0_gej_double_var(&gbase, &gbase, NULL); } /* Multiply numbase by 2. */ - rustsecp256k1zkp_v0_8_0_gej_double_var(&numsbase, &numsbase, NULL); + rustsecp256k1zkp_v0_10_0_gej_double_var(&numsbase, &numsbase, NULL); if (j == n - 2) { /* In the last iteration, numsbase is (1 - 2^j) * nums instead. */ - rustsecp256k1zkp_v0_8_0_gej_neg(&numsbase, &numsbase); - rustsecp256k1zkp_v0_8_0_gej_add_var(&numsbase, &numsbase, &nums_gej, NULL); + rustsecp256k1zkp_v0_10_0_gej_neg(&numsbase, &numsbase); + rustsecp256k1zkp_v0_10_0_gej_add_var(&numsbase, &numsbase, &nums_gej, NULL); } } - rustsecp256k1zkp_v0_8_0_ge_set_all_gej_var(prec, precj, n * g); + rustsecp256k1zkp_v0_10_0_ge_set_all_gej_var(prec, precj, n * g); free(precj); } for (j = 0; j < n; j++) { for (i = 0; i < g; i++) { - rustsecp256k1zkp_v0_8_0_ge_to_storage(&table[j*g + i], &prec[j*g + i]); + rustsecp256k1zkp_v0_10_0_ge_to_storage(&table[j*g + i], &prec[j*g + i]); } } free(prec); diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_gen_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_gen_impl.h index 324d300c..f013a773 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_gen_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_gen_impl.h @@ -14,19 +14,19 @@ #include "hash_impl.h" #include "precomputed_ecmult_gen.h" -static void rustsecp256k1zkp_v0_8_0_ecmult_gen_context_build(rustsecp256k1zkp_v0_8_0_ecmult_gen_context *ctx) { - rustsecp256k1zkp_v0_8_0_ecmult_gen_blind(ctx, NULL); +static void rustsecp256k1zkp_v0_10_0_ecmult_gen_context_build(rustsecp256k1zkp_v0_10_0_ecmult_gen_context *ctx) { + rustsecp256k1zkp_v0_10_0_ecmult_gen_blind(ctx, NULL); ctx->built = 1; } -static int rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(const rustsecp256k1zkp_v0_8_0_ecmult_gen_context* ctx) { +static int rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(const rustsecp256k1zkp_v0_10_0_ecmult_gen_context* ctx) { return ctx->built; } -static void rustsecp256k1zkp_v0_8_0_ecmult_gen_context_clear(rustsecp256k1zkp_v0_8_0_ecmult_gen_context *ctx) { +static void rustsecp256k1zkp_v0_10_0_ecmult_gen_context_clear(rustsecp256k1zkp_v0_10_0_ecmult_gen_context *ctx) { ctx->built = 0; - rustsecp256k1zkp_v0_8_0_scalar_clear(&ctx->blind); - rustsecp256k1zkp_v0_8_0_gej_clear(&ctx->initial); + rustsecp256k1zkp_v0_10_0_scalar_clear(&ctx->blind); + rustsecp256k1zkp_v0_10_0_gej_clear(&ctx->initial); } /* For accelerating the computation of a*G: @@ -40,25 +40,25 @@ static void rustsecp256k1zkp_v0_8_0_ecmult_gen_context_clear(rustsecp256k1zkp_v0 * precomputed (call it prec(i, n_i)). The formula now becomes sum(prec(i, n_i), i=0 ... PREC_N-1). * None of the resulting prec group elements have a known scalar, and neither do any of * the intermediate sums while computing a*G. - * The prec values are stored in rustsecp256k1zkp_v0_8_0_ecmult_gen_prec_table[i][n_i] = n_i * (PREC_G)^i * G + U_i. + * The prec values are stored in rustsecp256k1zkp_v0_10_0_ecmult_gen_prec_table[i][n_i] = n_i * (PREC_G)^i * G + U_i. */ -static void rustsecp256k1zkp_v0_8_0_ecmult_gen(const rustsecp256k1zkp_v0_8_0_ecmult_gen_context *ctx, rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_scalar *gn) { +static void rustsecp256k1zkp_v0_10_0_ecmult_gen(const rustsecp256k1zkp_v0_10_0_ecmult_gen_context *ctx, rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_scalar *gn) { int bits = ECMULT_GEN_PREC_BITS; int g = ECMULT_GEN_PREC_G(bits); int n = ECMULT_GEN_PREC_N(bits); - rustsecp256k1zkp_v0_8_0_ge add; - rustsecp256k1zkp_v0_8_0_ge_storage adds; - rustsecp256k1zkp_v0_8_0_scalar gnb; + rustsecp256k1zkp_v0_10_0_ge add; + rustsecp256k1zkp_v0_10_0_ge_storage adds; + rustsecp256k1zkp_v0_10_0_scalar gnb; int i, j, n_i; memset(&adds, 0, sizeof(adds)); *r = ctx->initial; /* Blind scalar/point multiplication by computing (n-b)G + bG instead of nG. */ - rustsecp256k1zkp_v0_8_0_scalar_add(&gnb, gn, &ctx->blind); + rustsecp256k1zkp_v0_10_0_scalar_add(&gnb, gn, &ctx->blind); add.infinity = 0; for (i = 0; i < n; i++) { - n_i = rustsecp256k1zkp_v0_8_0_scalar_get_bits(&gnb, i * bits, bits); + n_i = rustsecp256k1zkp_v0_10_0_scalar_get_bits(&gnb, i * bits, bits); for (j = 0; j < g; j++) { /** This uses a conditional move to avoid any secret data in array indexes. * _Any_ use of secret indexes has been demonstrated to result in timing @@ -70,63 +70,61 @@ static void rustsecp256k1zkp_v0_8_0_ecmult_gen(const rustsecp256k1zkp_v0_8_0_ecm * by Dag Arne Osvik, Adi Shamir, and Eran Tromer * (https://www.tau.ac.il/~tromer/papers/cache.pdf) */ - rustsecp256k1zkp_v0_8_0_ge_storage_cmov(&adds, &rustsecp256k1zkp_v0_8_0_ecmult_gen_prec_table[i][j], j == n_i); + rustsecp256k1zkp_v0_10_0_ge_storage_cmov(&adds, &rustsecp256k1zkp_v0_10_0_ecmult_gen_prec_table[i][j], j == n_i); } - rustsecp256k1zkp_v0_8_0_ge_from_storage(&add, &adds); - rustsecp256k1zkp_v0_8_0_gej_add_ge(r, r, &add); + rustsecp256k1zkp_v0_10_0_ge_from_storage(&add, &adds); + rustsecp256k1zkp_v0_10_0_gej_add_ge(r, r, &add); } n_i = 0; - rustsecp256k1zkp_v0_8_0_ge_clear(&add); - rustsecp256k1zkp_v0_8_0_scalar_clear(&gnb); + rustsecp256k1zkp_v0_10_0_ge_clear(&add); + rustsecp256k1zkp_v0_10_0_scalar_clear(&gnb); } -/* Setup blinding values for rustsecp256k1zkp_v0_8_0_ecmult_gen. */ -static void rustsecp256k1zkp_v0_8_0_ecmult_gen_blind(rustsecp256k1zkp_v0_8_0_ecmult_gen_context *ctx, const unsigned char *seed32) { - rustsecp256k1zkp_v0_8_0_scalar b; - rustsecp256k1zkp_v0_8_0_gej gb; - rustsecp256k1zkp_v0_8_0_fe s; +/* Setup blinding values for rustsecp256k1zkp_v0_10_0_ecmult_gen. */ +static void rustsecp256k1zkp_v0_10_0_ecmult_gen_blind(rustsecp256k1zkp_v0_10_0_ecmult_gen_context *ctx, const unsigned char *seed32) { + rustsecp256k1zkp_v0_10_0_scalar b; + rustsecp256k1zkp_v0_10_0_gej gb; + rustsecp256k1zkp_v0_10_0_fe s; unsigned char nonce32[32]; - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256 rng; - int overflow; - unsigned char keydata[64] = {0}; + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256 rng; + unsigned char keydata[64]; if (seed32 == NULL) { /* When seed is NULL, reset the initial point and blinding value. */ - rustsecp256k1zkp_v0_8_0_gej_set_ge(&ctx->initial, &rustsecp256k1zkp_v0_8_0_ge_const_g); - rustsecp256k1zkp_v0_8_0_gej_neg(&ctx->initial, &ctx->initial); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&ctx->blind, 1); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&ctx->initial, &rustsecp256k1zkp_v0_10_0_ge_const_g); + rustsecp256k1zkp_v0_10_0_gej_neg(&ctx->initial, &ctx->initial); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&ctx->blind, 1); + return; } /* The prior blinding value (if not reset) is chained forward by including it in the hash. */ - rustsecp256k1zkp_v0_8_0_scalar_get_b32(nonce32, &ctx->blind); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(keydata, &ctx->blind); /** Using a CSPRNG allows a failure free interface, avoids needing large amounts of random data, * and guards against weak or adversarial seeds. This is a simpler and safer interface than * asking the caller for blinding values directly and expecting them to retry on failure. */ - memcpy(keydata, nonce32, 32); - if (seed32 != NULL) { - memcpy(keydata + 32, seed32, 32); - } - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_initialize(&rng, keydata, seed32 ? 64 : 32); + VERIFY_CHECK(seed32 != NULL); + memcpy(keydata + 32, seed32, 32); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_initialize(&rng, keydata, 64); memset(keydata, 0, sizeof(keydata)); - /* Accept unobservably small non-uniformity. */ - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_generate(&rng, nonce32, 32); - overflow = !rustsecp256k1zkp_v0_8_0_fe_set_b32(&s, nonce32); - overflow |= rustsecp256k1zkp_v0_8_0_fe_is_zero(&s); - rustsecp256k1zkp_v0_8_0_fe_cmov(&s, &rustsecp256k1zkp_v0_8_0_fe_one, overflow); - /* Randomize the projection to defend against multiplier sidechannels. */ - rustsecp256k1zkp_v0_8_0_gej_rescale(&ctx->initial, &s); - rustsecp256k1zkp_v0_8_0_fe_clear(&s); - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_generate(&rng, nonce32, 32); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&b, nonce32, NULL); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_generate(&rng, nonce32, 32); + rustsecp256k1zkp_v0_10_0_fe_set_b32_mod(&s, nonce32); + rustsecp256k1zkp_v0_10_0_fe_cmov(&s, &rustsecp256k1zkp_v0_10_0_fe_one, rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero(&s)); + /* Randomize the projection to defend against multiplier sidechannels. + Do this before our own call to rustsecp256k1zkp_v0_10_0_ecmult_gen below. */ + rustsecp256k1zkp_v0_10_0_gej_rescale(&ctx->initial, &s); + rustsecp256k1zkp_v0_10_0_fe_clear(&s); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_generate(&rng, nonce32, 32); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&b, nonce32, NULL); /* A blinding value of 0 works, but would undermine the projection hardening. */ - rustsecp256k1zkp_v0_8_0_scalar_cmov(&b, &rustsecp256k1zkp_v0_8_0_scalar_one, rustsecp256k1zkp_v0_8_0_scalar_is_zero(&b)); - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_finalize(&rng); + rustsecp256k1zkp_v0_10_0_scalar_cmov(&b, &rustsecp256k1zkp_v0_10_0_scalar_one, rustsecp256k1zkp_v0_10_0_scalar_is_zero(&b)); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_finalize(&rng); memset(nonce32, 0, 32); - rustsecp256k1zkp_v0_8_0_ecmult_gen(ctx, &gb, &b); - rustsecp256k1zkp_v0_8_0_scalar_negate(&b, &b); + /* The random projection in ctx->initial ensures that gb will have a random projection. */ + rustsecp256k1zkp_v0_10_0_ecmult_gen(ctx, &gb, &b); + rustsecp256k1zkp_v0_10_0_scalar_negate(&b, &b); ctx->blind = b; ctx->initial = gb; - rustsecp256k1zkp_v0_8_0_scalar_clear(&b); - rustsecp256k1zkp_v0_8_0_gej_clear(&gb); + rustsecp256k1zkp_v0_10_0_scalar_clear(&b); + rustsecp256k1zkp_v0_10_0_gej_clear(&gb); } #endif /* SECP256K1_ECMULT_GEN_IMPL_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_impl.h index a5565d78..d65a2c8a 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/ecmult_impl.h @@ -33,8 +33,8 @@ /** Larger values for ECMULT_WINDOW_SIZE result in possibly better * performance at the cost of an exponentially larger precomputed * table. The exact table size is - * (1 << (WINDOW_G - 2)) * sizeof(rustsecp256k1zkp_v0_8_0_ge_storage) bytes, - * where sizeof(rustsecp256k1zkp_v0_8_0_ge_storage) is typically 64 bytes but can + * (1 << (WINDOW_G - 2)) * sizeof(rustsecp256k1zkp_v0_10_0_ge_storage) bytes, + * where sizeof(rustsecp256k1zkp_v0_10_0_ge_storage) is typically 64 bytes but can * be larger due to platform-specific padding and alignment. * Two tables of this size are used (due to the endomorphism * optimization). @@ -70,14 +70,14 @@ * Lastly the zr[0] value, which isn't used above, is set so that: * - a.z = z(pre_a[0]) / zr[0] */ -static void rustsecp256k1zkp_v0_8_0_ecmult_odd_multiples_table(int n, rustsecp256k1zkp_v0_8_0_ge *pre_a, rustsecp256k1zkp_v0_8_0_fe *zr, rustsecp256k1zkp_v0_8_0_fe *z, const rustsecp256k1zkp_v0_8_0_gej *a) { - rustsecp256k1zkp_v0_8_0_gej d, ai; - rustsecp256k1zkp_v0_8_0_ge d_ge; +static void rustsecp256k1zkp_v0_10_0_ecmult_odd_multiples_table(int n, rustsecp256k1zkp_v0_10_0_ge *pre_a, rustsecp256k1zkp_v0_10_0_fe *zr, rustsecp256k1zkp_v0_10_0_fe *z, const rustsecp256k1zkp_v0_10_0_gej *a) { + rustsecp256k1zkp_v0_10_0_gej d, ai; + rustsecp256k1zkp_v0_10_0_ge d_ge; int i; VERIFY_CHECK(!a->infinity); - rustsecp256k1zkp_v0_8_0_gej_double_var(&d, a, NULL); + rustsecp256k1zkp_v0_10_0_gej_double_var(&d, a, NULL); /* * Perform the additions using an isomorphic curve Y^2 = X^3 + 7*C^6 where C := d.z. @@ -90,62 +90,65 @@ static void rustsecp256k1zkp_v0_8_0_ecmult_odd_multiples_table(int n, rustsecp25 * * The group addition functions work correctly on these isomorphic curves. * In particular phi(d) is easy to represent in affine coordinates under this isomorphism. - * This lets us use the faster rustsecp256k1zkp_v0_8_0_gej_add_ge_var group addition function that we wouldn't be able to use otherwise. + * This lets us use the faster rustsecp256k1zkp_v0_10_0_gej_add_ge_var group addition function that we wouldn't be able to use otherwise. */ - rustsecp256k1zkp_v0_8_0_ge_set_xy(&d_ge, &d.x, &d.y); - rustsecp256k1zkp_v0_8_0_ge_set_gej_zinv(&pre_a[0], a, &d.z); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&ai, &pre_a[0]); + rustsecp256k1zkp_v0_10_0_ge_set_xy(&d_ge, &d.x, &d.y); + rustsecp256k1zkp_v0_10_0_ge_set_gej_zinv(&pre_a[0], a, &d.z); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&ai, &pre_a[0]); ai.z = a->z; - /* pre_a[0] is the point (a.x*C^2, a.y*C^3, a.z*C) which is equvalent to a. + /* pre_a[0] is the point (a.x*C^2, a.y*C^3, a.z*C) which is equivalent to a. * Set zr[0] to C, which is the ratio between the omitted z(pre_a[0]) value and a.z. */ zr[0] = d.z; for (i = 1; i < n; i++) { - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&ai, &ai, &d_ge, &zr[i]); - rustsecp256k1zkp_v0_8_0_ge_set_xy(&pre_a[i], &ai.x, &ai.y); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&ai, &ai, &d_ge, &zr[i]); + rustsecp256k1zkp_v0_10_0_ge_set_xy(&pre_a[i], &ai.x, &ai.y); } /* Multiply the last z-coordinate by C to undo the isomorphism. * Since the z-coordinates of the pre_a values are implied by the zr array of z-coordinate ratios, * undoing the isomorphism here undoes the isomorphism for all pre_a values. */ - rustsecp256k1zkp_v0_8_0_fe_mul(z, &ai.z, &d.z); + rustsecp256k1zkp_v0_10_0_fe_mul(z, &ai.z, &d.z); } -#define SECP256K1_ECMULT_TABLE_VERIFY(n,w) \ - VERIFY_CHECK(((n) & 1) == 1); \ - VERIFY_CHECK((n) >= -((1 << ((w)-1)) - 1)); \ +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_ecmult_table_verify(int n, int w) { + (void)n; + (void)w; + VERIFY_CHECK(((n) & 1) == 1); + VERIFY_CHECK((n) >= -((1 << ((w)-1)) - 1)); VERIFY_CHECK((n) <= ((1 << ((w)-1)) - 1)); +} -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_ecmult_table_get_ge(rustsecp256k1zkp_v0_8_0_ge *r, const rustsecp256k1zkp_v0_8_0_ge *pre, int n, int w) { - SECP256K1_ECMULT_TABLE_VERIFY(n,w) +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_ecmult_table_get_ge(rustsecp256k1zkp_v0_10_0_ge *r, const rustsecp256k1zkp_v0_10_0_ge *pre, int n, int w) { + rustsecp256k1zkp_v0_10_0_ecmult_table_verify(n,w); if (n > 0) { *r = pre[(n-1)/2]; } else { *r = pre[(-n-1)/2]; - rustsecp256k1zkp_v0_8_0_fe_negate(&(r->y), &(r->y), 1); + rustsecp256k1zkp_v0_10_0_fe_negate(&(r->y), &(r->y), 1); } } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_ecmult_table_get_ge_lambda(rustsecp256k1zkp_v0_8_0_ge *r, const rustsecp256k1zkp_v0_8_0_ge *pre, const rustsecp256k1zkp_v0_8_0_fe *x, int n, int w) { - SECP256K1_ECMULT_TABLE_VERIFY(n,w) +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_ecmult_table_get_ge_lambda(rustsecp256k1zkp_v0_10_0_ge *r, const rustsecp256k1zkp_v0_10_0_ge *pre, const rustsecp256k1zkp_v0_10_0_fe *x, int n, int w) { + rustsecp256k1zkp_v0_10_0_ecmult_table_verify(n,w); if (n > 0) { - rustsecp256k1zkp_v0_8_0_ge_set_xy(r, &x[(n-1)/2], &pre[(n-1)/2].y); + rustsecp256k1zkp_v0_10_0_ge_set_xy(r, &x[(n-1)/2], &pre[(n-1)/2].y); } else { - rustsecp256k1zkp_v0_8_0_ge_set_xy(r, &x[(-n-1)/2], &pre[(-n-1)/2].y); - rustsecp256k1zkp_v0_8_0_fe_negate(&(r->y), &(r->y), 1); + rustsecp256k1zkp_v0_10_0_ge_set_xy(r, &x[(-n-1)/2], &pre[(-n-1)/2].y); + rustsecp256k1zkp_v0_10_0_fe_negate(&(r->y), &(r->y), 1); } } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_ecmult_table_get_ge_storage(rustsecp256k1zkp_v0_8_0_ge *r, const rustsecp256k1zkp_v0_8_0_ge_storage *pre, int n, int w) { - SECP256K1_ECMULT_TABLE_VERIFY(n,w) +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_ecmult_table_get_ge_storage(rustsecp256k1zkp_v0_10_0_ge *r, const rustsecp256k1zkp_v0_10_0_ge_storage *pre, int n, int w) { + rustsecp256k1zkp_v0_10_0_ecmult_table_verify(n,w); if (n > 0) { - rustsecp256k1zkp_v0_8_0_ge_from_storage(r, &pre[(n-1)/2]); + rustsecp256k1zkp_v0_10_0_ge_from_storage(r, &pre[(n-1)/2]); } else { - rustsecp256k1zkp_v0_8_0_ge_from_storage(r, &pre[(-n-1)/2]); - rustsecp256k1zkp_v0_8_0_fe_negate(&(r->y), &(r->y), 1); + rustsecp256k1zkp_v0_10_0_ge_from_storage(r, &pre[(-n-1)/2]); + rustsecp256k1zkp_v0_10_0_fe_negate(&(r->y), &(r->y), 1); } } @@ -156,8 +159,8 @@ SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_ecmult_table_get_ge_storage * - the number of set values in wnaf is returned. This number is at most 256, and at most one more * than the number of bits in the (absolute value) of the input. */ -static int rustsecp256k1zkp_v0_8_0_ecmult_wnaf(int *wnaf, int len, const rustsecp256k1zkp_v0_8_0_scalar *a, int w) { - rustsecp256k1zkp_v0_8_0_scalar s; +static int rustsecp256k1zkp_v0_10_0_ecmult_wnaf(int *wnaf, int len, const rustsecp256k1zkp_v0_10_0_scalar *a, int w) { + rustsecp256k1zkp_v0_10_0_scalar s; int last_set_bit = -1; int bit = 0; int sign = 1; @@ -171,15 +174,15 @@ static int rustsecp256k1zkp_v0_8_0_ecmult_wnaf(int *wnaf, int len, const rustsec memset(wnaf, 0, len * sizeof(wnaf[0])); s = *a; - if (rustsecp256k1zkp_v0_8_0_scalar_get_bits(&s, 255, 1)) { - rustsecp256k1zkp_v0_8_0_scalar_negate(&s, &s); + if (rustsecp256k1zkp_v0_10_0_scalar_get_bits(&s, 255, 1)) { + rustsecp256k1zkp_v0_10_0_scalar_negate(&s, &s); sign = -1; } while (bit < len) { int now; int word; - if (rustsecp256k1zkp_v0_8_0_scalar_get_bits(&s, bit, 1) == (unsigned int)carry) { + if (rustsecp256k1zkp_v0_10_0_scalar_get_bits(&s, bit, 1) == (unsigned int)carry) { bit++; continue; } @@ -189,7 +192,7 @@ static int rustsecp256k1zkp_v0_8_0_ecmult_wnaf(int *wnaf, int len, const rustsec now = len - bit; } - word = rustsecp256k1zkp_v0_8_0_scalar_get_bits_var(&s, bit, now) + carry; + word = rustsecp256k1zkp_v0_10_0_scalar_get_bits_var(&s, bit, now) + carry; carry = (word >> (w-1)) & 1; word -= carry << w; @@ -200,33 +203,39 @@ static int rustsecp256k1zkp_v0_8_0_ecmult_wnaf(int *wnaf, int len, const rustsec bit += now; } #ifdef VERIFY - CHECK(carry == 0); - while (bit < 256) { - CHECK(rustsecp256k1zkp_v0_8_0_scalar_get_bits(&s, bit++, 1) == 0); + { + int verify_bit = bit; + + VERIFY_CHECK(carry == 0); + + while (verify_bit < 256) { + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_scalar_get_bits(&s, verify_bit, 1) == 0); + verify_bit++; + } } #endif return last_set_bit + 1; } -struct rustsecp256k1zkp_v0_8_0_strauss_point_state { +struct rustsecp256k1zkp_v0_10_0_strauss_point_state { int wnaf_na_1[129]; int wnaf_na_lam[129]; int bits_na_1; int bits_na_lam; }; -struct rustsecp256k1zkp_v0_8_0_strauss_state { +struct rustsecp256k1zkp_v0_10_0_strauss_state { /* aux is used to hold z-ratios, and then used to hold pre_a[i].x * BETA values. */ - rustsecp256k1zkp_v0_8_0_fe* aux; - rustsecp256k1zkp_v0_8_0_ge* pre_a; - struct rustsecp256k1zkp_v0_8_0_strauss_point_state* ps; + rustsecp256k1zkp_v0_10_0_fe* aux; + rustsecp256k1zkp_v0_10_0_ge* pre_a; + struct rustsecp256k1zkp_v0_10_0_strauss_point_state* ps; }; -static void rustsecp256k1zkp_v0_8_0_ecmult_strauss_wnaf(const struct rustsecp256k1zkp_v0_8_0_strauss_state *state, rustsecp256k1zkp_v0_8_0_gej *r, size_t num, const rustsecp256k1zkp_v0_8_0_gej *a, const rustsecp256k1zkp_v0_8_0_scalar *na, const rustsecp256k1zkp_v0_8_0_scalar *ng) { - rustsecp256k1zkp_v0_8_0_ge tmpa; - rustsecp256k1zkp_v0_8_0_fe Z; +static void rustsecp256k1zkp_v0_10_0_ecmult_strauss_wnaf(const struct rustsecp256k1zkp_v0_10_0_strauss_state *state, rustsecp256k1zkp_v0_10_0_gej *r, size_t num, const rustsecp256k1zkp_v0_10_0_gej *a, const rustsecp256k1zkp_v0_10_0_scalar *na, const rustsecp256k1zkp_v0_10_0_scalar *ng) { + rustsecp256k1zkp_v0_10_0_ge tmpa; + rustsecp256k1zkp_v0_10_0_fe Z; /* Split G factors. */ - rustsecp256k1zkp_v0_8_0_scalar ng_1, ng_128; + rustsecp256k1zkp_v0_10_0_scalar ng_1, ng_128; int wnaf_ng_1[129]; int bits_ng_1 = 0; int wnaf_ng_128[129]; @@ -236,19 +245,19 @@ static void rustsecp256k1zkp_v0_8_0_ecmult_strauss_wnaf(const struct rustsecp256 size_t np; size_t no = 0; - rustsecp256k1zkp_v0_8_0_fe_set_int(&Z, 1); + rustsecp256k1zkp_v0_10_0_fe_set_int(&Z, 1); for (np = 0; np < num; ++np) { - rustsecp256k1zkp_v0_8_0_gej tmp; - rustsecp256k1zkp_v0_8_0_scalar na_1, na_lam; - if (rustsecp256k1zkp_v0_8_0_scalar_is_zero(&na[np]) || rustsecp256k1zkp_v0_8_0_gej_is_infinity(&a[np])) { + rustsecp256k1zkp_v0_10_0_gej tmp; + rustsecp256k1zkp_v0_10_0_scalar na_1, na_lam; + if (rustsecp256k1zkp_v0_10_0_scalar_is_zero(&na[np]) || rustsecp256k1zkp_v0_10_0_gej_is_infinity(&a[np])) { continue; } /* split na into na_1 and na_lam (where na = na_1 + na_lam*lambda, and na_1 and na_lam are ~128 bit) */ - rustsecp256k1zkp_v0_8_0_scalar_split_lambda(&na_1, &na_lam, &na[np]); + rustsecp256k1zkp_v0_10_0_scalar_split_lambda(&na_1, &na_lam, &na[np]); /* build wnaf representation for na_1 and na_lam. */ - state->ps[no].bits_na_1 = rustsecp256k1zkp_v0_8_0_ecmult_wnaf(state->ps[no].wnaf_na_1, 129, &na_1, WINDOW_A); - state->ps[no].bits_na_lam = rustsecp256k1zkp_v0_8_0_ecmult_wnaf(state->ps[no].wnaf_na_lam, 129, &na_lam, WINDOW_A); + state->ps[no].bits_na_1 = rustsecp256k1zkp_v0_10_0_ecmult_wnaf(state->ps[no].wnaf_na_1, 129, &na_1, WINDOW_A); + state->ps[no].bits_na_lam = rustsecp256k1zkp_v0_10_0_ecmult_wnaf(state->ps[no].wnaf_na_lam, 129, &na_lam, WINDOW_A); VERIFY_CHECK(state->ps[no].bits_na_1 <= 129); VERIFY_CHECK(state->ps[no].bits_na_lam <= 129); if (state->ps[no].bits_na_1 > bits) { @@ -265,38 +274,37 @@ static void rustsecp256k1zkp_v0_8_0_ecmult_strauss_wnaf(const struct rustsecp256 * the Z coordinate of the result once at the end. * The exception is the precomputed G table points, which are actually * affine. Compared to the base used for other points, they have a Z ratio - * of 1/Z, so we can use rustsecp256k1zkp_v0_8_0_gej_add_zinv_var, which uses the same + * of 1/Z, so we can use rustsecp256k1zkp_v0_10_0_gej_add_zinv_var, which uses the same * isomorphism to efficiently add with a known Z inverse. */ tmp = a[np]; if (no) { -#ifdef VERIFY - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&Z); -#endif - rustsecp256k1zkp_v0_8_0_gej_rescale(&tmp, &Z); + rustsecp256k1zkp_v0_10_0_gej_rescale(&tmp, &Z); } - rustsecp256k1zkp_v0_8_0_ecmult_odd_multiples_table(ECMULT_TABLE_SIZE(WINDOW_A), state->pre_a + no * ECMULT_TABLE_SIZE(WINDOW_A), state->aux + no * ECMULT_TABLE_SIZE(WINDOW_A), &Z, &tmp); - if (no) rustsecp256k1zkp_v0_8_0_fe_mul(state->aux + no * ECMULT_TABLE_SIZE(WINDOW_A), state->aux + no * ECMULT_TABLE_SIZE(WINDOW_A), &(a[np].z)); + rustsecp256k1zkp_v0_10_0_ecmult_odd_multiples_table(ECMULT_TABLE_SIZE(WINDOW_A), state->pre_a + no * ECMULT_TABLE_SIZE(WINDOW_A), state->aux + no * ECMULT_TABLE_SIZE(WINDOW_A), &Z, &tmp); + if (no) rustsecp256k1zkp_v0_10_0_fe_mul(state->aux + no * ECMULT_TABLE_SIZE(WINDOW_A), state->aux + no * ECMULT_TABLE_SIZE(WINDOW_A), &(a[np].z)); ++no; } /* Bring them to the same Z denominator. */ - rustsecp256k1zkp_v0_8_0_ge_table_set_globalz(ECMULT_TABLE_SIZE(WINDOW_A) * no, state->pre_a, state->aux); + if (no) { + rustsecp256k1zkp_v0_10_0_ge_table_set_globalz(ECMULT_TABLE_SIZE(WINDOW_A) * no, state->pre_a, state->aux); + } for (np = 0; np < no; ++np) { for (i = 0; i < ECMULT_TABLE_SIZE(WINDOW_A); i++) { - rustsecp256k1zkp_v0_8_0_fe_mul(&state->aux[np * ECMULT_TABLE_SIZE(WINDOW_A) + i], &state->pre_a[np * ECMULT_TABLE_SIZE(WINDOW_A) + i].x, &rustsecp256k1zkp_v0_8_0_const_beta); + rustsecp256k1zkp_v0_10_0_fe_mul(&state->aux[np * ECMULT_TABLE_SIZE(WINDOW_A) + i], &state->pre_a[np * ECMULT_TABLE_SIZE(WINDOW_A) + i].x, &rustsecp256k1zkp_v0_10_0_const_beta); } } if (ng) { /* split ng into ng_1 and ng_128 (where gn = gn_1 + gn_128*2^128, and gn_1 and gn_128 are ~128 bit) */ - rustsecp256k1zkp_v0_8_0_scalar_split_128(&ng_1, &ng_128, ng); + rustsecp256k1zkp_v0_10_0_scalar_split_128(&ng_1, &ng_128, ng); /* Build wnaf representation for ng_1 and ng_128 */ - bits_ng_1 = rustsecp256k1zkp_v0_8_0_ecmult_wnaf(wnaf_ng_1, 129, &ng_1, WINDOW_G); - bits_ng_128 = rustsecp256k1zkp_v0_8_0_ecmult_wnaf(wnaf_ng_128, 129, &ng_128, WINDOW_G); + bits_ng_1 = rustsecp256k1zkp_v0_10_0_ecmult_wnaf(wnaf_ng_1, 129, &ng_1, WINDOW_G); + bits_ng_128 = rustsecp256k1zkp_v0_10_0_ecmult_wnaf(wnaf_ng_128, 129, &ng_128, WINDOW_G); if (bits_ng_1 > bits) { bits = bits_ng_1; } @@ -305,61 +313,61 @@ static void rustsecp256k1zkp_v0_8_0_ecmult_strauss_wnaf(const struct rustsecp256 } } - rustsecp256k1zkp_v0_8_0_gej_set_infinity(r); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(r); for (i = bits - 1; i >= 0; i--) { int n; - rustsecp256k1zkp_v0_8_0_gej_double_var(r, r, NULL); + rustsecp256k1zkp_v0_10_0_gej_double_var(r, r, NULL); for (np = 0; np < no; ++np) { if (i < state->ps[np].bits_na_1 && (n = state->ps[np].wnaf_na_1[i])) { - rustsecp256k1zkp_v0_8_0_ecmult_table_get_ge(&tmpa, state->pre_a + np * ECMULT_TABLE_SIZE(WINDOW_A), n, WINDOW_A); - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(r, r, &tmpa, NULL); + rustsecp256k1zkp_v0_10_0_ecmult_table_get_ge(&tmpa, state->pre_a + np * ECMULT_TABLE_SIZE(WINDOW_A), n, WINDOW_A); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(r, r, &tmpa, NULL); } if (i < state->ps[np].bits_na_lam && (n = state->ps[np].wnaf_na_lam[i])) { - rustsecp256k1zkp_v0_8_0_ecmult_table_get_ge_lambda(&tmpa, state->pre_a + np * ECMULT_TABLE_SIZE(WINDOW_A), state->aux + np * ECMULT_TABLE_SIZE(WINDOW_A), n, WINDOW_A); - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(r, r, &tmpa, NULL); + rustsecp256k1zkp_v0_10_0_ecmult_table_get_ge_lambda(&tmpa, state->pre_a + np * ECMULT_TABLE_SIZE(WINDOW_A), state->aux + np * ECMULT_TABLE_SIZE(WINDOW_A), n, WINDOW_A); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(r, r, &tmpa, NULL); } } if (i < bits_ng_1 && (n = wnaf_ng_1[i])) { - rustsecp256k1zkp_v0_8_0_ecmult_table_get_ge_storage(&tmpa, rustsecp256k1zkp_v0_8_0_pre_g, n, WINDOW_G); - rustsecp256k1zkp_v0_8_0_gej_add_zinv_var(r, r, &tmpa, &Z); + rustsecp256k1zkp_v0_10_0_ecmult_table_get_ge_storage(&tmpa, rustsecp256k1zkp_v0_10_0_pre_g, n, WINDOW_G); + rustsecp256k1zkp_v0_10_0_gej_add_zinv_var(r, r, &tmpa, &Z); } if (i < bits_ng_128 && (n = wnaf_ng_128[i])) { - rustsecp256k1zkp_v0_8_0_ecmult_table_get_ge_storage(&tmpa, rustsecp256k1zkp_v0_8_0_pre_g_128, n, WINDOW_G); - rustsecp256k1zkp_v0_8_0_gej_add_zinv_var(r, r, &tmpa, &Z); + rustsecp256k1zkp_v0_10_0_ecmult_table_get_ge_storage(&tmpa, rustsecp256k1zkp_v0_10_0_pre_g_128, n, WINDOW_G); + rustsecp256k1zkp_v0_10_0_gej_add_zinv_var(r, r, &tmpa, &Z); } } if (!r->infinity) { - rustsecp256k1zkp_v0_8_0_fe_mul(&r->z, &r->z, &Z); + rustsecp256k1zkp_v0_10_0_fe_mul(&r->z, &r->z, &Z); } } -static void rustsecp256k1zkp_v0_8_0_ecmult(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_gej *a, const rustsecp256k1zkp_v0_8_0_scalar *na, const rustsecp256k1zkp_v0_8_0_scalar *ng) { - rustsecp256k1zkp_v0_8_0_fe aux[ECMULT_TABLE_SIZE(WINDOW_A)]; - rustsecp256k1zkp_v0_8_0_ge pre_a[ECMULT_TABLE_SIZE(WINDOW_A)]; - struct rustsecp256k1zkp_v0_8_0_strauss_point_state ps[1]; - struct rustsecp256k1zkp_v0_8_0_strauss_state state; +static void rustsecp256k1zkp_v0_10_0_ecmult(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_gej *a, const rustsecp256k1zkp_v0_10_0_scalar *na, const rustsecp256k1zkp_v0_10_0_scalar *ng) { + rustsecp256k1zkp_v0_10_0_fe aux[ECMULT_TABLE_SIZE(WINDOW_A)]; + rustsecp256k1zkp_v0_10_0_ge pre_a[ECMULT_TABLE_SIZE(WINDOW_A)]; + struct rustsecp256k1zkp_v0_10_0_strauss_point_state ps[1]; + struct rustsecp256k1zkp_v0_10_0_strauss_state state; state.aux = aux; state.pre_a = pre_a; state.ps = ps; - rustsecp256k1zkp_v0_8_0_ecmult_strauss_wnaf(&state, r, 1, a, na, ng); + rustsecp256k1zkp_v0_10_0_ecmult_strauss_wnaf(&state, r, 1, a, na, ng); } -static size_t rustsecp256k1zkp_v0_8_0_strauss_scratch_size(size_t n_points) { - static const size_t point_size = (sizeof(rustsecp256k1zkp_v0_8_0_ge) + sizeof(rustsecp256k1zkp_v0_8_0_fe)) * ECMULT_TABLE_SIZE(WINDOW_A) + sizeof(struct rustsecp256k1zkp_v0_8_0_strauss_point_state) + sizeof(rustsecp256k1zkp_v0_8_0_gej) + sizeof(rustsecp256k1zkp_v0_8_0_scalar); +static size_t rustsecp256k1zkp_v0_10_0_strauss_scratch_size(size_t n_points) { + static const size_t point_size = (sizeof(rustsecp256k1zkp_v0_10_0_ge) + sizeof(rustsecp256k1zkp_v0_10_0_fe)) * ECMULT_TABLE_SIZE(WINDOW_A) + sizeof(struct rustsecp256k1zkp_v0_10_0_strauss_point_state) + sizeof(rustsecp256k1zkp_v0_10_0_gej) + sizeof(rustsecp256k1zkp_v0_10_0_scalar); return n_points*point_size; } -static int rustsecp256k1zkp_v0_8_0_ecmult_strauss_batch(const rustsecp256k1zkp_v0_8_0_callback* error_callback, rustsecp256k1zkp_v0_8_0_scratch *scratch, rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_scalar *inp_g_sc, rustsecp256k1zkp_v0_8_0_ecmult_multi_callback cb, void *cbdata, size_t n_points, size_t cb_offset) { - rustsecp256k1zkp_v0_8_0_gej* points; - rustsecp256k1zkp_v0_8_0_scalar* scalars; - struct rustsecp256k1zkp_v0_8_0_strauss_state state; +static int rustsecp256k1zkp_v0_10_0_ecmult_strauss_batch(const rustsecp256k1zkp_v0_10_0_callback* error_callback, rustsecp256k1zkp_v0_10_0_scratch *scratch, rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_scalar *inp_g_sc, rustsecp256k1zkp_v0_10_0_ecmult_multi_callback cb, void *cbdata, size_t n_points, size_t cb_offset) { + rustsecp256k1zkp_v0_10_0_gej* points; + rustsecp256k1zkp_v0_10_0_scalar* scalars; + struct rustsecp256k1zkp_v0_10_0_strauss_state state; size_t i; - const size_t scratch_checkpoint = rustsecp256k1zkp_v0_8_0_scratch_checkpoint(error_callback, scratch); + const size_t scratch_checkpoint = rustsecp256k1zkp_v0_10_0_scratch_checkpoint(error_callback, scratch); - rustsecp256k1zkp_v0_8_0_gej_set_infinity(r); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(r); if (inp_g_sc == NULL && n_points == 0) { return 1; } @@ -367,37 +375,37 @@ static int rustsecp256k1zkp_v0_8_0_ecmult_strauss_batch(const rustsecp256k1zkp_v /* We allocate STRAUSS_SCRATCH_OBJECTS objects on the scratch space. If these * allocations change, make sure to update the STRAUSS_SCRATCH_OBJECTS * constant and strauss_scratch_size accordingly. */ - points = (rustsecp256k1zkp_v0_8_0_gej*)rustsecp256k1zkp_v0_8_0_scratch_alloc(error_callback, scratch, n_points * sizeof(rustsecp256k1zkp_v0_8_0_gej)); - scalars = (rustsecp256k1zkp_v0_8_0_scalar*)rustsecp256k1zkp_v0_8_0_scratch_alloc(error_callback, scratch, n_points * sizeof(rustsecp256k1zkp_v0_8_0_scalar)); - state.aux = (rustsecp256k1zkp_v0_8_0_fe*)rustsecp256k1zkp_v0_8_0_scratch_alloc(error_callback, scratch, n_points * ECMULT_TABLE_SIZE(WINDOW_A) * sizeof(rustsecp256k1zkp_v0_8_0_fe)); - state.pre_a = (rustsecp256k1zkp_v0_8_0_ge*)rustsecp256k1zkp_v0_8_0_scratch_alloc(error_callback, scratch, n_points * ECMULT_TABLE_SIZE(WINDOW_A) * sizeof(rustsecp256k1zkp_v0_8_0_ge)); - state.ps = (struct rustsecp256k1zkp_v0_8_0_strauss_point_state*)rustsecp256k1zkp_v0_8_0_scratch_alloc(error_callback, scratch, n_points * sizeof(struct rustsecp256k1zkp_v0_8_0_strauss_point_state)); + points = (rustsecp256k1zkp_v0_10_0_gej*)rustsecp256k1zkp_v0_10_0_scratch_alloc(error_callback, scratch, n_points * sizeof(rustsecp256k1zkp_v0_10_0_gej)); + scalars = (rustsecp256k1zkp_v0_10_0_scalar*)rustsecp256k1zkp_v0_10_0_scratch_alloc(error_callback, scratch, n_points * sizeof(rustsecp256k1zkp_v0_10_0_scalar)); + state.aux = (rustsecp256k1zkp_v0_10_0_fe*)rustsecp256k1zkp_v0_10_0_scratch_alloc(error_callback, scratch, n_points * ECMULT_TABLE_SIZE(WINDOW_A) * sizeof(rustsecp256k1zkp_v0_10_0_fe)); + state.pre_a = (rustsecp256k1zkp_v0_10_0_ge*)rustsecp256k1zkp_v0_10_0_scratch_alloc(error_callback, scratch, n_points * ECMULT_TABLE_SIZE(WINDOW_A) * sizeof(rustsecp256k1zkp_v0_10_0_ge)); + state.ps = (struct rustsecp256k1zkp_v0_10_0_strauss_point_state*)rustsecp256k1zkp_v0_10_0_scratch_alloc(error_callback, scratch, n_points * sizeof(struct rustsecp256k1zkp_v0_10_0_strauss_point_state)); if (points == NULL || scalars == NULL || state.aux == NULL || state.pre_a == NULL || state.ps == NULL) { - rustsecp256k1zkp_v0_8_0_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint); + rustsecp256k1zkp_v0_10_0_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint); return 0; } for (i = 0; i < n_points; i++) { - rustsecp256k1zkp_v0_8_0_ge point; + rustsecp256k1zkp_v0_10_0_ge point; if (!cb(&scalars[i], &point, i+cb_offset, cbdata)) { - rustsecp256k1zkp_v0_8_0_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint); + rustsecp256k1zkp_v0_10_0_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint); return 0; } - rustsecp256k1zkp_v0_8_0_gej_set_ge(&points[i], &point); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&points[i], &point); } - rustsecp256k1zkp_v0_8_0_ecmult_strauss_wnaf(&state, r, n_points, points, scalars, inp_g_sc); - rustsecp256k1zkp_v0_8_0_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint); + rustsecp256k1zkp_v0_10_0_ecmult_strauss_wnaf(&state, r, n_points, points, scalars, inp_g_sc); + rustsecp256k1zkp_v0_10_0_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint); return 1; } -/* Wrapper for rustsecp256k1zkp_v0_8_0_ecmult_multi_func interface */ -static int rustsecp256k1zkp_v0_8_0_ecmult_strauss_batch_single(const rustsecp256k1zkp_v0_8_0_callback* error_callback, rustsecp256k1zkp_v0_8_0_scratch *scratch, rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_scalar *inp_g_sc, rustsecp256k1zkp_v0_8_0_ecmult_multi_callback cb, void *cbdata, size_t n) { - return rustsecp256k1zkp_v0_8_0_ecmult_strauss_batch(error_callback, scratch, r, inp_g_sc, cb, cbdata, n, 0); +/* Wrapper for rustsecp256k1zkp_v0_10_0_ecmult_multi_func interface */ +static int rustsecp256k1zkp_v0_10_0_ecmult_strauss_batch_single(const rustsecp256k1zkp_v0_10_0_callback* error_callback, rustsecp256k1zkp_v0_10_0_scratch *scratch, rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_scalar *inp_g_sc, rustsecp256k1zkp_v0_10_0_ecmult_multi_callback cb, void *cbdata, size_t n) { + return rustsecp256k1zkp_v0_10_0_ecmult_strauss_batch(error_callback, scratch, r, inp_g_sc, cb, cbdata, n, 0); } -static size_t rustsecp256k1zkp_v0_8_0_strauss_max_points(const rustsecp256k1zkp_v0_8_0_callback* error_callback, rustsecp256k1zkp_v0_8_0_scratch *scratch) { - return rustsecp256k1zkp_v0_8_0_scratch_max_allocation(error_callback, scratch, STRAUSS_SCRATCH_OBJECTS) / rustsecp256k1zkp_v0_8_0_strauss_scratch_size(1); +static size_t rustsecp256k1zkp_v0_10_0_strauss_max_points(const rustsecp256k1zkp_v0_10_0_callback* error_callback, rustsecp256k1zkp_v0_10_0_scratch *scratch) { + return rustsecp256k1zkp_v0_10_0_scratch_max_allocation(error_callback, scratch, STRAUSS_SCRATCH_OBJECTS) / rustsecp256k1zkp_v0_10_0_strauss_scratch_size(1); } /** Convert a number to WNAF notation. @@ -407,25 +415,25 @@ static size_t rustsecp256k1zkp_v0_8_0_strauss_max_points(const rustsecp256k1zkp_ * - the number of words set is always WNAF_SIZE(w) * - the returned skew is 0 or 1 */ -static int rustsecp256k1zkp_v0_8_0_wnaf_fixed(int *wnaf, const rustsecp256k1zkp_v0_8_0_scalar *s, int w) { +static int rustsecp256k1zkp_v0_10_0_wnaf_fixed(int *wnaf, const rustsecp256k1zkp_v0_10_0_scalar *s, int w) { int skew = 0; int pos; int max_pos; int last_w; - const rustsecp256k1zkp_v0_8_0_scalar *work = s; + const rustsecp256k1zkp_v0_10_0_scalar *work = s; - if (rustsecp256k1zkp_v0_8_0_scalar_is_zero(s)) { + if (rustsecp256k1zkp_v0_10_0_scalar_is_zero(s)) { for (pos = 0; pos < WNAF_SIZE(w); pos++) { wnaf[pos] = 0; } return 0; } - if (rustsecp256k1zkp_v0_8_0_scalar_is_even(s)) { + if (rustsecp256k1zkp_v0_10_0_scalar_is_even(s)) { skew = 1; } - wnaf[0] = rustsecp256k1zkp_v0_8_0_scalar_get_bits_var(work, 0, w) + skew; + wnaf[0] = rustsecp256k1zkp_v0_10_0_scalar_get_bits_var(work, 0, w) + skew; /* Compute last window size. Relevant when window size doesn't divide the * number of bits in the scalar */ last_w = WNAF_BITS - (WNAF_SIZE(w) - 1) * w; @@ -433,7 +441,7 @@ static int rustsecp256k1zkp_v0_8_0_wnaf_fixed(int *wnaf, const rustsecp256k1zkp_ /* Store the position of the first nonzero word in max_pos to allow * skipping leading zeros when calculating the wnaf. */ for (pos = WNAF_SIZE(w) - 1; pos > 0; pos--) { - int val = rustsecp256k1zkp_v0_8_0_scalar_get_bits_var(work, pos * w, pos == WNAF_SIZE(w)-1 ? last_w : w); + int val = rustsecp256k1zkp_v0_10_0_scalar_get_bits_var(work, pos * w, pos == WNAF_SIZE(w)-1 ? last_w : w); if(val != 0) { break; } @@ -443,7 +451,7 @@ static int rustsecp256k1zkp_v0_8_0_wnaf_fixed(int *wnaf, const rustsecp256k1zkp_ pos = 1; while (pos <= max_pos) { - int val = rustsecp256k1zkp_v0_8_0_scalar_get_bits_var(work, pos * w, pos == WNAF_SIZE(w)-1 ? last_w : w); + int val = rustsecp256k1zkp_v0_10_0_scalar_get_bits_var(work, pos * w, pos == WNAF_SIZE(w)-1 ? last_w : w); if ((val & 1) == 0) { wnaf[pos - 1] -= (1 << w); wnaf[pos] = (val + 1); @@ -469,14 +477,14 @@ static int rustsecp256k1zkp_v0_8_0_wnaf_fixed(int *wnaf, const rustsecp256k1zkp_ return skew; } -struct rustsecp256k1zkp_v0_8_0_pippenger_point_state { +struct rustsecp256k1zkp_v0_10_0_pippenger_point_state { int skew_na; size_t input_pos; }; -struct rustsecp256k1zkp_v0_8_0_pippenger_state { +struct rustsecp256k1zkp_v0_10_0_pippenger_state { int *wnaf_na; - struct rustsecp256k1zkp_v0_8_0_pippenger_point_state* ps; + struct rustsecp256k1zkp_v0_10_0_pippenger_point_state* ps; }; /* @@ -486,7 +494,7 @@ struct rustsecp256k1zkp_v0_8_0_pippenger_state { * to the point's wnaf[i]. Second, the buckets are added together such that * r += 1*bucket[0] + 3*bucket[1] + 5*bucket[2] + ... */ -static int rustsecp256k1zkp_v0_8_0_ecmult_pippenger_wnaf(rustsecp256k1zkp_v0_8_0_gej *buckets, int bucket_window, struct rustsecp256k1zkp_v0_8_0_pippenger_state *state, rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_scalar *sc, const rustsecp256k1zkp_v0_8_0_ge *pt, size_t num) { +static int rustsecp256k1zkp_v0_10_0_ecmult_pippenger_wnaf(rustsecp256k1zkp_v0_10_0_gej *buckets, int bucket_window, struct rustsecp256k1zkp_v0_10_0_pippenger_state *state, rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_scalar *sc, const rustsecp256k1zkp_v0_10_0_ge *pt, size_t num) { size_t n_wnaf = WNAF_SIZE(bucket_window+1); size_t np; size_t no = 0; @@ -494,55 +502,55 @@ static int rustsecp256k1zkp_v0_8_0_ecmult_pippenger_wnaf(rustsecp256k1zkp_v0_8_0 int j; for (np = 0; np < num; ++np) { - if (rustsecp256k1zkp_v0_8_0_scalar_is_zero(&sc[np]) || rustsecp256k1zkp_v0_8_0_ge_is_infinity(&pt[np])) { + if (rustsecp256k1zkp_v0_10_0_scalar_is_zero(&sc[np]) || rustsecp256k1zkp_v0_10_0_ge_is_infinity(&pt[np])) { continue; } state->ps[no].input_pos = np; - state->ps[no].skew_na = rustsecp256k1zkp_v0_8_0_wnaf_fixed(&state->wnaf_na[no*n_wnaf], &sc[np], bucket_window+1); + state->ps[no].skew_na = rustsecp256k1zkp_v0_10_0_wnaf_fixed(&state->wnaf_na[no*n_wnaf], &sc[np], bucket_window+1); no++; } - rustsecp256k1zkp_v0_8_0_gej_set_infinity(r); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(r); if (no == 0) { return 1; } for (i = n_wnaf - 1; i >= 0; i--) { - rustsecp256k1zkp_v0_8_0_gej running_sum; + rustsecp256k1zkp_v0_10_0_gej running_sum; for(j = 0; j < ECMULT_TABLE_SIZE(bucket_window+2); j++) { - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&buckets[j]); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&buckets[j]); } for (np = 0; np < no; ++np) { int n = state->wnaf_na[np*n_wnaf + i]; - struct rustsecp256k1zkp_v0_8_0_pippenger_point_state point_state = state->ps[np]; - rustsecp256k1zkp_v0_8_0_ge tmp; + struct rustsecp256k1zkp_v0_10_0_pippenger_point_state point_state = state->ps[np]; + rustsecp256k1zkp_v0_10_0_ge tmp; int idx; if (i == 0) { /* correct for wnaf skew */ int skew = point_state.skew_na; if (skew) { - rustsecp256k1zkp_v0_8_0_ge_neg(&tmp, &pt[point_state.input_pos]); - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&buckets[0], &buckets[0], &tmp, NULL); + rustsecp256k1zkp_v0_10_0_ge_neg(&tmp, &pt[point_state.input_pos]); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&buckets[0], &buckets[0], &tmp, NULL); } } if (n > 0) { idx = (n - 1)/2; - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&buckets[idx], &buckets[idx], &pt[point_state.input_pos], NULL); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&buckets[idx], &buckets[idx], &pt[point_state.input_pos], NULL); } else if (n < 0) { idx = -(n + 1)/2; - rustsecp256k1zkp_v0_8_0_ge_neg(&tmp, &pt[point_state.input_pos]); - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&buckets[idx], &buckets[idx], &tmp, NULL); + rustsecp256k1zkp_v0_10_0_ge_neg(&tmp, &pt[point_state.input_pos]); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&buckets[idx], &buckets[idx], &tmp, NULL); } } for(j = 0; j < bucket_window; j++) { - rustsecp256k1zkp_v0_8_0_gej_double_var(r, r, NULL); + rustsecp256k1zkp_v0_10_0_gej_double_var(r, r, NULL); } - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&running_sum); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&running_sum); /* Accumulate the sum: bucket[0] + 3*bucket[1] + 5*bucket[2] + 7*bucket[3] + ... * = bucket[0] + bucket[1] + bucket[2] + bucket[3] + ... * + 2 * (bucket[1] + 2*bucket[2] + 3*bucket[3] + ...) @@ -552,13 +560,13 @@ static int rustsecp256k1zkp_v0_8_0_ecmult_pippenger_wnaf(rustsecp256k1zkp_v0_8_0 * The doubling is done implicitly by deferring the final window doubling (of 'r'). */ for(j = ECMULT_TABLE_SIZE(bucket_window+2) - 1; j > 0; j--) { - rustsecp256k1zkp_v0_8_0_gej_add_var(&running_sum, &running_sum, &buckets[j], NULL); - rustsecp256k1zkp_v0_8_0_gej_add_var(r, r, &running_sum, NULL); + rustsecp256k1zkp_v0_10_0_gej_add_var(&running_sum, &running_sum, &buckets[j], NULL); + rustsecp256k1zkp_v0_10_0_gej_add_var(r, r, &running_sum, NULL); } - rustsecp256k1zkp_v0_8_0_gej_add_var(&running_sum, &running_sum, &buckets[0], NULL); - rustsecp256k1zkp_v0_8_0_gej_double_var(r, r, NULL); - rustsecp256k1zkp_v0_8_0_gej_add_var(r, r, &running_sum, NULL); + rustsecp256k1zkp_v0_10_0_gej_add_var(&running_sum, &running_sum, &buckets[0], NULL); + rustsecp256k1zkp_v0_10_0_gej_double_var(r, r, NULL); + rustsecp256k1zkp_v0_10_0_gej_add_var(r, r, &running_sum, NULL); } return 1; } @@ -567,7 +575,7 @@ static int rustsecp256k1zkp_v0_8_0_ecmult_pippenger_wnaf(rustsecp256k1zkp_v0_8_0 * Returns optimal bucket_window (number of bits of a scalar represented by a * set of buckets) for a given number of points. */ -static int rustsecp256k1zkp_v0_8_0_pippenger_bucket_window(size_t n) { +static int rustsecp256k1zkp_v0_10_0_pippenger_bucket_window(size_t n) { if (n <= 1) { return 1; } else if (n <= 4) { @@ -596,7 +604,7 @@ static int rustsecp256k1zkp_v0_8_0_pippenger_bucket_window(size_t n) { /** * Returns the maximum optimal number of points for a bucket_window. */ -static size_t rustsecp256k1zkp_v0_8_0_pippenger_bucket_window_inv(int bucket_window) { +static size_t rustsecp256k1zkp_v0_10_0_pippenger_bucket_window_inv(int bucket_window) { switch(bucket_window) { case 1: return 1; case 2: return 4; @@ -615,18 +623,18 @@ static size_t rustsecp256k1zkp_v0_8_0_pippenger_bucket_window_inv(int bucket_win } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_ecmult_endo_split(rustsecp256k1zkp_v0_8_0_scalar *s1, rustsecp256k1zkp_v0_8_0_scalar *s2, rustsecp256k1zkp_v0_8_0_ge *p1, rustsecp256k1zkp_v0_8_0_ge *p2) { - rustsecp256k1zkp_v0_8_0_scalar tmp = *s1; - rustsecp256k1zkp_v0_8_0_scalar_split_lambda(s1, s2, &tmp); - rustsecp256k1zkp_v0_8_0_ge_mul_lambda(p2, p1); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_ecmult_endo_split(rustsecp256k1zkp_v0_10_0_scalar *s1, rustsecp256k1zkp_v0_10_0_scalar *s2, rustsecp256k1zkp_v0_10_0_ge *p1, rustsecp256k1zkp_v0_10_0_ge *p2) { + rustsecp256k1zkp_v0_10_0_scalar tmp = *s1; + rustsecp256k1zkp_v0_10_0_scalar_split_lambda(s1, s2, &tmp); + rustsecp256k1zkp_v0_10_0_ge_mul_lambda(p2, p1); - if (rustsecp256k1zkp_v0_8_0_scalar_is_high(s1)) { - rustsecp256k1zkp_v0_8_0_scalar_negate(s1, s1); - rustsecp256k1zkp_v0_8_0_ge_neg(p1, p1); + if (rustsecp256k1zkp_v0_10_0_scalar_is_high(s1)) { + rustsecp256k1zkp_v0_10_0_scalar_negate(s1, s1); + rustsecp256k1zkp_v0_10_0_ge_neg(p1, p1); } - if (rustsecp256k1zkp_v0_8_0_scalar_is_high(s2)) { - rustsecp256k1zkp_v0_8_0_scalar_negate(s2, s2); - rustsecp256k1zkp_v0_8_0_ge_neg(p2, p2); + if (rustsecp256k1zkp_v0_10_0_scalar_is_high(s2)) { + rustsecp256k1zkp_v0_10_0_scalar_negate(s2, s2); + rustsecp256k1zkp_v0_10_0_ge_neg(p2, p2); } } @@ -634,91 +642,91 @@ SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_ecmult_endo_split(rustsecp2 * Returns the scratch size required for a given number of points (excluding * base point G) without considering alignment. */ -static size_t rustsecp256k1zkp_v0_8_0_pippenger_scratch_size(size_t n_points, int bucket_window) { +static size_t rustsecp256k1zkp_v0_10_0_pippenger_scratch_size(size_t n_points, int bucket_window) { size_t entries = 2*n_points + 2; - size_t entry_size = sizeof(rustsecp256k1zkp_v0_8_0_ge) + sizeof(rustsecp256k1zkp_v0_8_0_scalar) + sizeof(struct rustsecp256k1zkp_v0_8_0_pippenger_point_state) + (WNAF_SIZE(bucket_window+1)+1)*sizeof(int); - return (sizeof(rustsecp256k1zkp_v0_8_0_gej) << bucket_window) + sizeof(struct rustsecp256k1zkp_v0_8_0_pippenger_state) + entries * entry_size; + size_t entry_size = sizeof(rustsecp256k1zkp_v0_10_0_ge) + sizeof(rustsecp256k1zkp_v0_10_0_scalar) + sizeof(struct rustsecp256k1zkp_v0_10_0_pippenger_point_state) + (WNAF_SIZE(bucket_window+1)+1)*sizeof(int); + return (sizeof(rustsecp256k1zkp_v0_10_0_gej) << bucket_window) + sizeof(struct rustsecp256k1zkp_v0_10_0_pippenger_state) + entries * entry_size; } -static int rustsecp256k1zkp_v0_8_0_ecmult_pippenger_batch(const rustsecp256k1zkp_v0_8_0_callback* error_callback, rustsecp256k1zkp_v0_8_0_scratch *scratch, rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_scalar *inp_g_sc, rustsecp256k1zkp_v0_8_0_ecmult_multi_callback cb, void *cbdata, size_t n_points, size_t cb_offset) { - const size_t scratch_checkpoint = rustsecp256k1zkp_v0_8_0_scratch_checkpoint(error_callback, scratch); +static int rustsecp256k1zkp_v0_10_0_ecmult_pippenger_batch(const rustsecp256k1zkp_v0_10_0_callback* error_callback, rustsecp256k1zkp_v0_10_0_scratch *scratch, rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_scalar *inp_g_sc, rustsecp256k1zkp_v0_10_0_ecmult_multi_callback cb, void *cbdata, size_t n_points, size_t cb_offset) { + const size_t scratch_checkpoint = rustsecp256k1zkp_v0_10_0_scratch_checkpoint(error_callback, scratch); /* Use 2(n+1) with the endomorphism, when calculating batch * sizes. The reason for +1 is that we add the G scalar to the list of * other scalars. */ size_t entries = 2*n_points + 2; - rustsecp256k1zkp_v0_8_0_ge *points; - rustsecp256k1zkp_v0_8_0_scalar *scalars; - rustsecp256k1zkp_v0_8_0_gej *buckets; - struct rustsecp256k1zkp_v0_8_0_pippenger_state *state_space; + rustsecp256k1zkp_v0_10_0_ge *points; + rustsecp256k1zkp_v0_10_0_scalar *scalars; + rustsecp256k1zkp_v0_10_0_gej *buckets; + struct rustsecp256k1zkp_v0_10_0_pippenger_state *state_space; size_t idx = 0; size_t point_idx = 0; int i, j; int bucket_window; - rustsecp256k1zkp_v0_8_0_gej_set_infinity(r); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(r); if (inp_g_sc == NULL && n_points == 0) { return 1; } - bucket_window = rustsecp256k1zkp_v0_8_0_pippenger_bucket_window(n_points); + bucket_window = rustsecp256k1zkp_v0_10_0_pippenger_bucket_window(n_points); /* We allocate PIPPENGER_SCRATCH_OBJECTS objects on the scratch space. If * these allocations change, make sure to update the * PIPPENGER_SCRATCH_OBJECTS constant and pippenger_scratch_size * accordingly. */ - points = (rustsecp256k1zkp_v0_8_0_ge *) rustsecp256k1zkp_v0_8_0_scratch_alloc(error_callback, scratch, entries * sizeof(*points)); - scalars = (rustsecp256k1zkp_v0_8_0_scalar *) rustsecp256k1zkp_v0_8_0_scratch_alloc(error_callback, scratch, entries * sizeof(*scalars)); - state_space = (struct rustsecp256k1zkp_v0_8_0_pippenger_state *) rustsecp256k1zkp_v0_8_0_scratch_alloc(error_callback, scratch, sizeof(*state_space)); + points = (rustsecp256k1zkp_v0_10_0_ge *) rustsecp256k1zkp_v0_10_0_scratch_alloc(error_callback, scratch, entries * sizeof(*points)); + scalars = (rustsecp256k1zkp_v0_10_0_scalar *) rustsecp256k1zkp_v0_10_0_scratch_alloc(error_callback, scratch, entries * sizeof(*scalars)); + state_space = (struct rustsecp256k1zkp_v0_10_0_pippenger_state *) rustsecp256k1zkp_v0_10_0_scratch_alloc(error_callback, scratch, sizeof(*state_space)); if (points == NULL || scalars == NULL || state_space == NULL) { - rustsecp256k1zkp_v0_8_0_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint); + rustsecp256k1zkp_v0_10_0_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint); return 0; } - state_space->ps = (struct rustsecp256k1zkp_v0_8_0_pippenger_point_state *) rustsecp256k1zkp_v0_8_0_scratch_alloc(error_callback, scratch, entries * sizeof(*state_space->ps)); - state_space->wnaf_na = (int *) rustsecp256k1zkp_v0_8_0_scratch_alloc(error_callback, scratch, entries*(WNAF_SIZE(bucket_window+1)) * sizeof(int)); - buckets = (rustsecp256k1zkp_v0_8_0_gej *) rustsecp256k1zkp_v0_8_0_scratch_alloc(error_callback, scratch, (1<ps = (struct rustsecp256k1zkp_v0_10_0_pippenger_point_state *) rustsecp256k1zkp_v0_10_0_scratch_alloc(error_callback, scratch, entries * sizeof(*state_space->ps)); + state_space->wnaf_na = (int *) rustsecp256k1zkp_v0_10_0_scratch_alloc(error_callback, scratch, entries*(WNAF_SIZE(bucket_window+1)) * sizeof(int)); + buckets = (rustsecp256k1zkp_v0_10_0_gej *) rustsecp256k1zkp_v0_10_0_scratch_alloc(error_callback, scratch, ((size_t)1 << bucket_window) * sizeof(*buckets)); if (state_space->ps == NULL || state_space->wnaf_na == NULL || buckets == NULL) { - rustsecp256k1zkp_v0_8_0_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint); + rustsecp256k1zkp_v0_10_0_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint); return 0; } if (inp_g_sc != NULL) { scalars[0] = *inp_g_sc; - points[0] = rustsecp256k1zkp_v0_8_0_ge_const_g; + points[0] = rustsecp256k1zkp_v0_10_0_ge_const_g; idx++; - rustsecp256k1zkp_v0_8_0_ecmult_endo_split(&scalars[0], &scalars[1], &points[0], &points[1]); + rustsecp256k1zkp_v0_10_0_ecmult_endo_split(&scalars[0], &scalars[1], &points[0], &points[1]); idx++; } while (point_idx < n_points) { if (!cb(&scalars[idx], &points[idx], point_idx + cb_offset, cbdata)) { - rustsecp256k1zkp_v0_8_0_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint); + rustsecp256k1zkp_v0_10_0_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint); return 0; } idx++; - rustsecp256k1zkp_v0_8_0_ecmult_endo_split(&scalars[idx - 1], &scalars[idx], &points[idx - 1], &points[idx]); + rustsecp256k1zkp_v0_10_0_ecmult_endo_split(&scalars[idx - 1], &scalars[idx], &points[idx - 1], &points[idx]); idx++; point_idx++; } - rustsecp256k1zkp_v0_8_0_ecmult_pippenger_wnaf(buckets, bucket_window, state_space, r, scalars, points, idx); + rustsecp256k1zkp_v0_10_0_ecmult_pippenger_wnaf(buckets, bucket_window, state_space, r, scalars, points, idx); /* Clear data */ for(i = 0; (size_t)i < idx; i++) { - rustsecp256k1zkp_v0_8_0_scalar_clear(&scalars[i]); + rustsecp256k1zkp_v0_10_0_scalar_clear(&scalars[i]); state_space->ps[i].skew_na = 0; for(j = 0; j < WNAF_SIZE(bucket_window+1); j++) { state_space->wnaf_na[i * WNAF_SIZE(bucket_window+1) + j] = 0; } } for(i = 0; i < 1< max_alloc) { break; } @@ -762,34 +770,32 @@ static size_t rustsecp256k1zkp_v0_8_0_pippenger_max_points(const rustsecp256k1zk /* Computes ecmult_multi by simply multiplying and adding each point. Does not * require a scratch space */ -static int rustsecp256k1zkp_v0_8_0_ecmult_multi_simple_var(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_scalar *inp_g_sc, rustsecp256k1zkp_v0_8_0_ecmult_multi_callback cb, void *cbdata, size_t n_points) { +static int rustsecp256k1zkp_v0_10_0_ecmult_multi_simple_var(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_scalar *inp_g_sc, rustsecp256k1zkp_v0_10_0_ecmult_multi_callback cb, void *cbdata, size_t n_points) { size_t point_idx; - rustsecp256k1zkp_v0_8_0_scalar szero; - rustsecp256k1zkp_v0_8_0_gej tmpj; + rustsecp256k1zkp_v0_10_0_gej tmpj; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&szero, 0); - rustsecp256k1zkp_v0_8_0_gej_set_infinity(r); - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&tmpj); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(r); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&tmpj); /* r = inp_g_sc*G */ - rustsecp256k1zkp_v0_8_0_ecmult(r, &tmpj, &szero, inp_g_sc); + rustsecp256k1zkp_v0_10_0_ecmult(r, &tmpj, &rustsecp256k1zkp_v0_10_0_scalar_zero, inp_g_sc); for (point_idx = 0; point_idx < n_points; point_idx++) { - rustsecp256k1zkp_v0_8_0_ge point; - rustsecp256k1zkp_v0_8_0_gej pointj; - rustsecp256k1zkp_v0_8_0_scalar scalar; + rustsecp256k1zkp_v0_10_0_ge point; + rustsecp256k1zkp_v0_10_0_gej pointj; + rustsecp256k1zkp_v0_10_0_scalar scalar; if (!cb(&scalar, &point, point_idx, cbdata)) { return 0; } /* r += scalar*point */ - rustsecp256k1zkp_v0_8_0_gej_set_ge(&pointj, &point); - rustsecp256k1zkp_v0_8_0_ecmult(&tmpj, &pointj, &scalar, NULL); - rustsecp256k1zkp_v0_8_0_gej_add_var(r, r, &tmpj, NULL); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&pointj, &point); + rustsecp256k1zkp_v0_10_0_ecmult(&tmpj, &pointj, &scalar, NULL); + rustsecp256k1zkp_v0_10_0_gej_add_var(r, r, &tmpj, NULL); } return 1; } /* Compute the number of batches and the batch size given the maximum batch size and the * total number of points */ -static int rustsecp256k1zkp_v0_8_0_ecmult_multi_batch_size_helper(size_t *n_batches, size_t *n_batch_points, size_t max_n_batch_points, size_t n) { +static int rustsecp256k1zkp_v0_10_0_ecmult_multi_batch_size_helper(size_t *n_batches, size_t *n_batch_points, size_t max_n_batch_points, size_t n) { if (max_n_batch_points == 0) { return 0; } @@ -807,50 +813,48 @@ static int rustsecp256k1zkp_v0_8_0_ecmult_multi_batch_size_helper(size_t *n_batc return 1; } -typedef int (*rustsecp256k1zkp_v0_8_0_ecmult_multi_func)(const rustsecp256k1zkp_v0_8_0_callback* error_callback, rustsecp256k1zkp_v0_8_0_scratch*, rustsecp256k1zkp_v0_8_0_gej*, const rustsecp256k1zkp_v0_8_0_scalar*, rustsecp256k1zkp_v0_8_0_ecmult_multi_callback cb, void*, size_t); -static int rustsecp256k1zkp_v0_8_0_ecmult_multi_var(const rustsecp256k1zkp_v0_8_0_callback* error_callback, rustsecp256k1zkp_v0_8_0_scratch *scratch, rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_scalar *inp_g_sc, rustsecp256k1zkp_v0_8_0_ecmult_multi_callback cb, void *cbdata, size_t n) { +typedef int (*rustsecp256k1zkp_v0_10_0_ecmult_multi_func)(const rustsecp256k1zkp_v0_10_0_callback* error_callback, rustsecp256k1zkp_v0_10_0_scratch*, rustsecp256k1zkp_v0_10_0_gej*, const rustsecp256k1zkp_v0_10_0_scalar*, rustsecp256k1zkp_v0_10_0_ecmult_multi_callback cb, void*, size_t); +static int rustsecp256k1zkp_v0_10_0_ecmult_multi_var(const rustsecp256k1zkp_v0_10_0_callback* error_callback, rustsecp256k1zkp_v0_10_0_scratch *scratch, rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_scalar *inp_g_sc, rustsecp256k1zkp_v0_10_0_ecmult_multi_callback cb, void *cbdata, size_t n) { size_t i; - int (*f)(const rustsecp256k1zkp_v0_8_0_callback* error_callback, rustsecp256k1zkp_v0_8_0_scratch*, rustsecp256k1zkp_v0_8_0_gej*, const rustsecp256k1zkp_v0_8_0_scalar*, rustsecp256k1zkp_v0_8_0_ecmult_multi_callback cb, void*, size_t, size_t); + int (*f)(const rustsecp256k1zkp_v0_10_0_callback* error_callback, rustsecp256k1zkp_v0_10_0_scratch*, rustsecp256k1zkp_v0_10_0_gej*, const rustsecp256k1zkp_v0_10_0_scalar*, rustsecp256k1zkp_v0_10_0_ecmult_multi_callback cb, void*, size_t, size_t); size_t n_batches; size_t n_batch_points; - rustsecp256k1zkp_v0_8_0_gej_set_infinity(r); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(r); if (inp_g_sc == NULL && n == 0) { return 1; } else if (n == 0) { - rustsecp256k1zkp_v0_8_0_scalar szero; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&szero, 0); - rustsecp256k1zkp_v0_8_0_ecmult(r, r, &szero, inp_g_sc); + rustsecp256k1zkp_v0_10_0_ecmult(r, r, &rustsecp256k1zkp_v0_10_0_scalar_zero, inp_g_sc); return 1; } if (scratch == NULL) { - return rustsecp256k1zkp_v0_8_0_ecmult_multi_simple_var(r, inp_g_sc, cb, cbdata, n); + return rustsecp256k1zkp_v0_10_0_ecmult_multi_simple_var(r, inp_g_sc, cb, cbdata, n); } /* Compute the batch sizes for Pippenger's algorithm given a scratch space. If it's greater than * a threshold use Pippenger's algorithm. Otherwise use Strauss' algorithm. * As a first step check if there's enough space for Pippenger's algo (which requires less space * than Strauss' algo) and if not, use the simple algorithm. */ - if (!rustsecp256k1zkp_v0_8_0_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, rustsecp256k1zkp_v0_8_0_pippenger_max_points(error_callback, scratch), n)) { - return rustsecp256k1zkp_v0_8_0_ecmult_multi_simple_var(r, inp_g_sc, cb, cbdata, n); + if (!rustsecp256k1zkp_v0_10_0_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, rustsecp256k1zkp_v0_10_0_pippenger_max_points(error_callback, scratch), n)) { + return rustsecp256k1zkp_v0_10_0_ecmult_multi_simple_var(r, inp_g_sc, cb, cbdata, n); } if (n_batch_points >= ECMULT_PIPPENGER_THRESHOLD) { - f = rustsecp256k1zkp_v0_8_0_ecmult_pippenger_batch; + f = rustsecp256k1zkp_v0_10_0_ecmult_pippenger_batch; } else { - if (!rustsecp256k1zkp_v0_8_0_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, rustsecp256k1zkp_v0_8_0_strauss_max_points(error_callback, scratch), n)) { - return rustsecp256k1zkp_v0_8_0_ecmult_multi_simple_var(r, inp_g_sc, cb, cbdata, n); + if (!rustsecp256k1zkp_v0_10_0_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, rustsecp256k1zkp_v0_10_0_strauss_max_points(error_callback, scratch), n)) { + return rustsecp256k1zkp_v0_10_0_ecmult_multi_simple_var(r, inp_g_sc, cb, cbdata, n); } - f = rustsecp256k1zkp_v0_8_0_ecmult_strauss_batch; + f = rustsecp256k1zkp_v0_10_0_ecmult_strauss_batch; } for(i = 0; i < n_batches; i++) { size_t nbp = n < n_batch_points ? n : n_batch_points; size_t offset = n_batch_points*i; - rustsecp256k1zkp_v0_8_0_gej tmp; + rustsecp256k1zkp_v0_10_0_gej tmp; if (!f(error_callback, scratch, &tmp, i == 0 ? inp_g_sc : NULL, cb, cbdata, nbp, offset)) { return 0; } - rustsecp256k1zkp_v0_8_0_gej_add_var(r, r, &tmp, NULL); + rustsecp256k1zkp_v0_10_0_gej_add_var(r, r, &tmp, NULL); n -= nbp; } return 1; diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/field.h b/secp256k1-zkp-sys/depend/secp256k1/src/field.h index 0717afdd..914684e8 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/field.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/field.h @@ -7,23 +7,36 @@ #ifndef SECP256K1_FIELD_H #define SECP256K1_FIELD_H -/** Field element module. - * - * Field elements can be represented in several ways, but code accessing - * it (and implementations) need to take certain properties into account: - * - Each field element can be normalized or not. - * - Each field element has a magnitude, which represents how far away - * its representation is away from normalization. Normalized elements - * always have a magnitude of 0 or 1, but a magnitude of 1 doesn't - * imply normality. - */ +#include "util.h" -#if defined HAVE_CONFIG_H -#include "libsecp256k1-config.h" +/* This file defines the generic interface for working with rustsecp256k1zkp_v0_10_0_fe + * objects, which represent field elements (integers modulo 2^256 - 2^32 - 977). + * + * The actual definition of the rustsecp256k1zkp_v0_10_0_fe type depends on the chosen field + * implementation; see the field_5x52.h and field_10x26.h files for details. + * + * All rustsecp256k1zkp_v0_10_0_fe objects have implicit properties that determine what + * operations are permitted on it. These are purely a function of what + * rustsecp256k1zkp_v0_10_0_fe_ operations are applied on it, generally (implicitly) fixed at + * compile time, and do not depend on the chosen field implementation. Despite + * that, what these properties actually entail for the field representation + * values depends on the chosen field implementation. These properties are: + * - magnitude: an integer in [0,32] + * - normalized: 0 or 1; normalized=1 implies magnitude <= 1. + * + * In VERIFY mode, they are materialized explicitly as fields in the struct, + * allowing run-time verification of these properties. In that case, the field + * implementation also provides a rustsecp256k1zkp_v0_10_0_fe_verify routine to verify that + * these fields match the run-time value and perform internal consistency + * checks. */ +#ifdef VERIFY +# define SECP256K1_FE_VERIFY_FIELDS \ + int magnitude; \ + int normalized; +#else +# define SECP256K1_FE_VERIFY_FIELDS #endif -#include "util.h" - #if defined(SECP256K1_WIDEMUL_INT128) #include "field_5x52.h" #elif defined(SECP256K1_WIDEMUL_INT64) @@ -32,114 +45,311 @@ #error "Please select wide multiplication implementation" #endif -static const rustsecp256k1zkp_v0_8_0_fe rustsecp256k1zkp_v0_8_0_fe_one = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 1); -static const rustsecp256k1zkp_v0_8_0_fe rustsecp256k1zkp_v0_8_0_const_beta = SECP256K1_FE_CONST( +#ifdef VERIFY +/* Magnitude and normalized value for constants. */ +#define SECP256K1_FE_VERIFY_CONST(d7, d6, d5, d4, d3, d2, d1, d0) \ + /* Magnitude is 0 for constant 0; 1 otherwise. */ \ + , (((d7) | (d6) | (d5) | (d4) | (d3) | (d2) | (d1) | (d0)) != 0) \ + /* Normalized is 1 unless sum(d_i<<(32*i) for i=0..7) exceeds field modulus. */ \ + , (!(((d7) & (d6) & (d5) & (d4) & (d3) & (d2)) == 0xfffffffful && ((d1) == 0xfffffffful || ((d1) == 0xfffffffe && (d0 >= 0xfffffc2f))))) +#else +#define SECP256K1_FE_VERIFY_CONST(d7, d6, d5, d4, d3, d2, d1, d0) +#endif + +/** This expands to an initializer for a rustsecp256k1zkp_v0_10_0_fe valued sum((i*32) * d_i, i=0..7) mod p. + * + * It has magnitude 1, unless d_i are all 0, in which case the magnitude is 0. + * It is normalized, unless sum(2^(i*32) * d_i, i=0..7) >= p. + * + * SECP256K1_FE_CONST_INNER is provided by the implementation. + */ +#define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0)) SECP256K1_FE_VERIFY_CONST((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0)) } + +static const rustsecp256k1zkp_v0_10_0_fe rustsecp256k1zkp_v0_10_0_fe_one = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 1); +static const rustsecp256k1zkp_v0_10_0_fe rustsecp256k1zkp_v0_10_0_const_beta = SECP256K1_FE_CONST( 0x7ae96a2bul, 0x657c0710ul, 0x6e64479eul, 0xac3434e9ul, 0x9cf04975ul, 0x12f58995ul, 0xc1396c28ul, 0x719501eeul ); -/** Normalize a field element. This brings the field element to a canonical representation, reduces - * its magnitude to 1, and reduces it modulo field size `p`. +#ifndef VERIFY +/* In non-VERIFY mode, we #define the fe operations to be identical to their + * internal field implementation, to avoid the potential overhead of a + * function call (even though presumably inlinable). */ +# define rustsecp256k1zkp_v0_10_0_fe_normalize rustsecp256k1zkp_v0_10_0_fe_impl_normalize +# define rustsecp256k1zkp_v0_10_0_fe_normalize_weak rustsecp256k1zkp_v0_10_0_fe_impl_normalize_weak +# define rustsecp256k1zkp_v0_10_0_fe_normalize_var rustsecp256k1zkp_v0_10_0_fe_impl_normalize_var +# define rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero rustsecp256k1zkp_v0_10_0_fe_impl_normalizes_to_zero +# define rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var rustsecp256k1zkp_v0_10_0_fe_impl_normalizes_to_zero_var +# define rustsecp256k1zkp_v0_10_0_fe_set_int rustsecp256k1zkp_v0_10_0_fe_impl_set_int +# define rustsecp256k1zkp_v0_10_0_fe_clear rustsecp256k1zkp_v0_10_0_fe_impl_clear +# define rustsecp256k1zkp_v0_10_0_fe_is_zero rustsecp256k1zkp_v0_10_0_fe_impl_is_zero +# define rustsecp256k1zkp_v0_10_0_fe_is_odd rustsecp256k1zkp_v0_10_0_fe_impl_is_odd +# define rustsecp256k1zkp_v0_10_0_fe_cmp_var rustsecp256k1zkp_v0_10_0_fe_impl_cmp_var +# define rustsecp256k1zkp_v0_10_0_fe_set_b32_mod rustsecp256k1zkp_v0_10_0_fe_impl_set_b32_mod +# define rustsecp256k1zkp_v0_10_0_fe_set_b32_limit rustsecp256k1zkp_v0_10_0_fe_impl_set_b32_limit +# define rustsecp256k1zkp_v0_10_0_fe_get_b32 rustsecp256k1zkp_v0_10_0_fe_impl_get_b32 +# define rustsecp256k1zkp_v0_10_0_fe_negate_unchecked rustsecp256k1zkp_v0_10_0_fe_impl_negate_unchecked +# define rustsecp256k1zkp_v0_10_0_fe_mul_int_unchecked rustsecp256k1zkp_v0_10_0_fe_impl_mul_int_unchecked +# define rustsecp256k1zkp_v0_10_0_fe_add rustsecp256k1zkp_v0_10_0_fe_impl_add +# define rustsecp256k1zkp_v0_10_0_fe_mul rustsecp256k1zkp_v0_10_0_fe_impl_mul +# define rustsecp256k1zkp_v0_10_0_fe_sqr rustsecp256k1zkp_v0_10_0_fe_impl_sqr +# define rustsecp256k1zkp_v0_10_0_fe_cmov rustsecp256k1zkp_v0_10_0_fe_impl_cmov +# define rustsecp256k1zkp_v0_10_0_fe_to_storage rustsecp256k1zkp_v0_10_0_fe_impl_to_storage +# define rustsecp256k1zkp_v0_10_0_fe_from_storage rustsecp256k1zkp_v0_10_0_fe_impl_from_storage +# define rustsecp256k1zkp_v0_10_0_fe_inv rustsecp256k1zkp_v0_10_0_fe_impl_inv +# define rustsecp256k1zkp_v0_10_0_fe_inv_var rustsecp256k1zkp_v0_10_0_fe_impl_inv_var +# define rustsecp256k1zkp_v0_10_0_fe_get_bounds rustsecp256k1zkp_v0_10_0_fe_impl_get_bounds +# define rustsecp256k1zkp_v0_10_0_fe_half rustsecp256k1zkp_v0_10_0_fe_impl_half +# define rustsecp256k1zkp_v0_10_0_fe_add_int rustsecp256k1zkp_v0_10_0_fe_impl_add_int +# define rustsecp256k1zkp_v0_10_0_fe_is_square_var rustsecp256k1zkp_v0_10_0_fe_impl_is_square_var +#endif /* !defined(VERIFY) */ + +/** Normalize a field element. + * + * On input, r must be a valid field element. + * On output, r represents the same value but has normalized=1 and magnitude=1. + */ +static void rustsecp256k1zkp_v0_10_0_fe_normalize(rustsecp256k1zkp_v0_10_0_fe *r); + +/** Give a field element magnitude 1. + * + * On input, r must be a valid field element. + * On output, r represents the same value but has magnitude=1. Normalized is unchanged. + */ +static void rustsecp256k1zkp_v0_10_0_fe_normalize_weak(rustsecp256k1zkp_v0_10_0_fe *r); + +/** Normalize a field element, without constant-time guarantee. + * + * Identical in behavior to rustsecp256k1zkp_v0_10_0_fe_normalize, but not constant time in r. */ -static void rustsecp256k1zkp_v0_8_0_fe_normalize(rustsecp256k1zkp_v0_8_0_fe *r); +static void rustsecp256k1zkp_v0_10_0_fe_normalize_var(rustsecp256k1zkp_v0_10_0_fe *r); -/** Weakly normalize a field element: reduce its magnitude to 1, but don't fully normalize. */ -static void rustsecp256k1zkp_v0_8_0_fe_normalize_weak(rustsecp256k1zkp_v0_8_0_fe *r); +/** Determine whether r represents field element 0. + * + * On input, r must be a valid field element. + * Returns whether r = 0 (mod p). + */ +static int rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero(const rustsecp256k1zkp_v0_10_0_fe *r); -/** Normalize a field element, without constant-time guarantee. */ -static void rustsecp256k1zkp_v0_8_0_fe_normalize_var(rustsecp256k1zkp_v0_8_0_fe *r); +/** Determine whether r represents field element 0, without constant-time guarantee. + * + * Identical in behavior to rustsecp256k1zkp_v0_10_0_normalizes_to_zero, but not constant time in r. + */ +static int rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(const rustsecp256k1zkp_v0_10_0_fe *r); -/** Verify whether a field element represents zero i.e. would normalize to a zero value. */ -static int rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero(const rustsecp256k1zkp_v0_8_0_fe *r); +/** Set a field element to an integer in range [0,0x7FFF]. + * + * On input, r does not need to be initialized, a must be in [0,0x7FFF]. + * On output, r represents value a, is normalized and has magnitude (a!=0). + */ +static void rustsecp256k1zkp_v0_10_0_fe_set_int(rustsecp256k1zkp_v0_10_0_fe *r, int a); -/** Verify whether a field element represents zero i.e. would normalize to a zero value, - * without constant-time guarantee. */ -static int rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero_var(const rustsecp256k1zkp_v0_8_0_fe *r); +/** Set a field element to 0. + * + * On input, a does not need to be initialized. + * On output, a represents 0, is normalized and has magnitude 0. + */ +static void rustsecp256k1zkp_v0_10_0_fe_clear(rustsecp256k1zkp_v0_10_0_fe *a); -/** Set a field element equal to a small (not greater than 0x7FFF), non-negative integer. - * Resulting field element is normalized; it has magnitude 0 if a == 0, and magnitude 1 otherwise. +/** Determine whether a represents field element 0. + * + * On input, a must be a valid normalized field element. + * Returns whether a = 0 (mod p). + * + * This behaves identical to rustsecp256k1zkp_v0_10_0_normalizes_to_zero{,_var}, but requires + * normalized input (and is much faster). */ -static void rustsecp256k1zkp_v0_8_0_fe_set_int(rustsecp256k1zkp_v0_8_0_fe *r, int a); +static int rustsecp256k1zkp_v0_10_0_fe_is_zero(const rustsecp256k1zkp_v0_10_0_fe *a); -/** Sets a field element equal to zero, initializing all fields. */ -static void rustsecp256k1zkp_v0_8_0_fe_clear(rustsecp256k1zkp_v0_8_0_fe *a); +/** Determine whether a (mod p) is odd. + * + * On input, a must be a valid normalized field element. + * Returns (int(a) mod p) & 1. + */ +static int rustsecp256k1zkp_v0_10_0_fe_is_odd(const rustsecp256k1zkp_v0_10_0_fe *a); -/** Verify whether a field element is zero. Requires the input to be normalized. */ -static int rustsecp256k1zkp_v0_8_0_fe_is_zero(const rustsecp256k1zkp_v0_8_0_fe *a); +/** Determine whether two field elements are equal. + * + * On input, a and b must be valid field elements with magnitudes not exceeding + * 1 and 31, respectively. + * Returns a = b (mod p). + */ +static int rustsecp256k1zkp_v0_10_0_fe_equal(const rustsecp256k1zkp_v0_10_0_fe *a, const rustsecp256k1zkp_v0_10_0_fe *b); -/** Check the "oddness" of a field element. Requires the input to be normalized. */ -static int rustsecp256k1zkp_v0_8_0_fe_is_odd(const rustsecp256k1zkp_v0_8_0_fe *a); +/** Compare the values represented by 2 field elements, without constant-time guarantee. + * + * On input, a and b must be valid normalized field elements. + * Returns 1 if a > b, -1 if a < b, and 0 if a = b (comparisons are done as integers + * in range 0..p-1). + */ +static int rustsecp256k1zkp_v0_10_0_fe_cmp_var(const rustsecp256k1zkp_v0_10_0_fe *a, const rustsecp256k1zkp_v0_10_0_fe *b); -/** Compare two field elements. Requires magnitude-1 inputs. */ -static int rustsecp256k1zkp_v0_8_0_fe_equal(const rustsecp256k1zkp_v0_8_0_fe *a, const rustsecp256k1zkp_v0_8_0_fe *b); +/** Set a field element equal to the element represented by a provided 32-byte big endian value + * interpreted modulo p. + * + * On input, r does not need to be initialized. a must be a pointer to an initialized 32-byte array. + * On output, r = a (mod p). It will have magnitude 1, and not be normalized. + */ +static void rustsecp256k1zkp_v0_10_0_fe_set_b32_mod(rustsecp256k1zkp_v0_10_0_fe *r, const unsigned char *a); -/** Same as rustsecp256k1zkp_v0_8_0_fe_equal, but may be variable time. */ -static int rustsecp256k1zkp_v0_8_0_fe_equal_var(const rustsecp256k1zkp_v0_8_0_fe *a, const rustsecp256k1zkp_v0_8_0_fe *b); +/** Set a field element equal to a provided 32-byte big endian value, checking for overflow. + * + * On input, r does not need to be initialized. a must be a pointer to an initialized 32-byte array. + * On output, r = a if (a < p), it will be normalized with magnitude 1, and 1 is returned. + * If a >= p, 0 is returned, and r will be made invalid (and must not be used without overwriting). + */ +static int rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(rustsecp256k1zkp_v0_10_0_fe *r, const unsigned char *a); -/** Compare two field elements. Requires both inputs to be normalized */ -static int rustsecp256k1zkp_v0_8_0_fe_cmp_var(const rustsecp256k1zkp_v0_8_0_fe *a, const rustsecp256k1zkp_v0_8_0_fe *b); +/** Convert a field element to 32-byte big endian byte array. + * On input, a must be a valid normalized field element, and r a pointer to a 32-byte array. + * On output, r = a (mod p). + */ +static void rustsecp256k1zkp_v0_10_0_fe_get_b32(unsigned char *r, const rustsecp256k1zkp_v0_10_0_fe *a); -/** Set a field element equal to 32-byte big endian value. If successful, the resulting field element is normalized. */ -static int rustsecp256k1zkp_v0_8_0_fe_set_b32(rustsecp256k1zkp_v0_8_0_fe *r, const unsigned char *a); +/** Negate a field element. + * + * On input, r does not need to be initialized. a must be a valid field element with + * magnitude not exceeding m. m must be an integer constant expression in [0,31]. + * Performs {r = -a}. + * On output, r will not be normalized, and will have magnitude m+1. + */ +#define rustsecp256k1zkp_v0_10_0_fe_negate(r, a, m) ASSERT_INT_CONST_AND_DO(m, rustsecp256k1zkp_v0_10_0_fe_negate_unchecked(r, a, m)) -/** Convert a field element to a 32-byte big endian value. Requires the input to be normalized */ -static void rustsecp256k1zkp_v0_8_0_fe_get_b32(unsigned char *r, const rustsecp256k1zkp_v0_8_0_fe *a); +/** Like rustsecp256k1zkp_v0_10_0_fe_negate_unchecked but m is not checked to be an integer constant expression. + * + * Should not be called directly outside of tests. + */ +static void rustsecp256k1zkp_v0_10_0_fe_negate_unchecked(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a, int m); -/** Set a field element equal to the additive inverse of another. Takes a maximum magnitude of the input - * as an argument. The magnitude of the output is one higher. */ -static void rustsecp256k1zkp_v0_8_0_fe_negate(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *a, int m); +/** Add a small integer to a field element. + * + * Performs {r += a}. The magnitude of r increases by 1, and normalized is cleared. + * a must be in range [0,0x7FFF]. + */ +static void rustsecp256k1zkp_v0_10_0_fe_add_int(rustsecp256k1zkp_v0_10_0_fe *r, int a); -/** Multiplies the passed field element with a small integer constant. Multiplies the magnitude by that - * small integer. */ -static void rustsecp256k1zkp_v0_8_0_fe_mul_int(rustsecp256k1zkp_v0_8_0_fe *r, int a); +/** Multiply a field element with a small integer. + * + * On input, r must be a valid field element. a must be an integer constant expression in [0,32]. + * The magnitude of r times a must not exceed 32. + * Performs {r *= a}. + * On output, r's magnitude is multiplied by a, and r will not be normalized. + */ +#define rustsecp256k1zkp_v0_10_0_fe_mul_int(r, a) ASSERT_INT_CONST_AND_DO(a, rustsecp256k1zkp_v0_10_0_fe_mul_int_unchecked(r, a)) -/** Adds a field element to another. The result has the sum of the inputs' magnitudes as magnitude. */ -static void rustsecp256k1zkp_v0_8_0_fe_add(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *a); +/** Like rustsecp256k1zkp_v0_10_0_fe_mul_int but a is not checked to be an integer constant expression. + * + * Should not be called directly outside of tests. + */ +static void rustsecp256k1zkp_v0_10_0_fe_mul_int_unchecked(rustsecp256k1zkp_v0_10_0_fe *r, int a); -/** Sets a field element to be the product of two others. Requires the inputs' magnitudes to be at most 8. - * The output magnitude is 1 (but not guaranteed to be normalized). */ -static void rustsecp256k1zkp_v0_8_0_fe_mul(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *a, const rustsecp256k1zkp_v0_8_0_fe * SECP256K1_RESTRICT b); +/** Increment a field element by another. + * + * On input, r and a must be valid field elements, not necessarily normalized. + * The sum of their magnitudes must not exceed 32. + * Performs {r += a}. + * On output, r will not be normalized, and will have magnitude incremented by a's. + */ +static void rustsecp256k1zkp_v0_10_0_fe_add(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a); -/** Sets a field element to be the square of another. Requires the input's magnitude to be at most 8. - * The output magnitude is 1 (but not guaranteed to be normalized). */ -static void rustsecp256k1zkp_v0_8_0_fe_sqr(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *a); +/** Multiply two field elements. + * + * On input, a and b must be valid field elements; r does not need to be initialized. + * r and a may point to the same object, but neither can be equal to b. The magnitudes + * of a and b must not exceed 8. + * Performs {r = a * b} + * On output, r will have magnitude 1, but won't be normalized. + */ +static void rustsecp256k1zkp_v0_10_0_fe_mul(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a, const rustsecp256k1zkp_v0_10_0_fe * SECP256K1_RESTRICT b); -/** If a has a square root, it is computed in r and 1 is returned. If a does not - * have a square root, the root of its negation is computed and 0 is returned. - * The input's magnitude can be at most 8. The output magnitude is 1 (but not - * guaranteed to be normalized). The result in r will always be a square - * itself. */ -static int rustsecp256k1zkp_v0_8_0_fe_sqrt(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *a); +/** Square a field element. + * + * On input, a must be a valid field element; r does not need to be initialized. The magnitude + * of a must not exceed 8. + * Performs {r = a**2} + * On output, r will have magnitude 1, but won't be normalized. + */ +static void rustsecp256k1zkp_v0_10_0_fe_sqr(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a); -/** Checks whether a field element is a quadratic residue. */ -static int rustsecp256k1zkp_v0_8_0_fe_is_quad_var(const rustsecp256k1zkp_v0_8_0_fe *a); +/** Compute a square root of a field element. + * + * On input, a must be a valid field element with magnitude<=8; r need not be initialized. + * If sqrt(a) exists, performs {r = sqrt(a)} and returns 1. + * Otherwise, sqrt(-a) exists. The function performs {r = sqrt(-a)} and returns 0. + * The resulting value represented by r will be a square itself. + * Variables r and a must not point to the same object. + * On output, r will have magnitude 1 but will not be normalized. + */ +static int rustsecp256k1zkp_v0_10_0_fe_sqrt(rustsecp256k1zkp_v0_10_0_fe * SECP256K1_RESTRICT r, const rustsecp256k1zkp_v0_10_0_fe * SECP256K1_RESTRICT a); -/** Sets a field element to be the (modular) inverse of another. Requires the input's magnitude to be - * at most 8. The output magnitude is 1 (but not guaranteed to be normalized). */ -static void rustsecp256k1zkp_v0_8_0_fe_inv(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *a); +/** Compute the modular inverse of a field element. + * + * On input, a must be a valid field element; r need not be initialized. + * Performs {r = a**(p-2)} (which maps 0 to 0, and every other element to its + * inverse). + * On output, r will have magnitude (a.magnitude != 0) and be normalized. + */ +static void rustsecp256k1zkp_v0_10_0_fe_inv(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a); -/** Potentially faster version of rustsecp256k1zkp_v0_8_0_fe_inv, without constant-time guarantee. */ -static void rustsecp256k1zkp_v0_8_0_fe_inv_var(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *a); +/** Compute the modular inverse of a field element, without constant-time guarantee. + * + * Behaves identically to rustsecp256k1zkp_v0_10_0_fe_inv, but is not constant-time in a. + */ +static void rustsecp256k1zkp_v0_10_0_fe_inv_var(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a); -/** Convert a field element to the storage type. */ -static void rustsecp256k1zkp_v0_8_0_fe_to_storage(rustsecp256k1zkp_v0_8_0_fe_storage *r, const rustsecp256k1zkp_v0_8_0_fe *a); +/** Convert a field element to rustsecp256k1zkp_v0_10_0_fe_storage. + * + * On input, a must be a valid normalized field element. + * Performs {r = a}. + */ +static void rustsecp256k1zkp_v0_10_0_fe_to_storage(rustsecp256k1zkp_v0_10_0_fe_storage *r, const rustsecp256k1zkp_v0_10_0_fe *a); -/** Convert a field element back from the storage type. */ -static void rustsecp256k1zkp_v0_8_0_fe_from_storage(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe_storage *a); +/** Convert a field element back from rustsecp256k1zkp_v0_10_0_fe_storage. + * + * On input, r need not be initialized. + * Performs {r = a}. + * On output, r will be normalized and will have magnitude 1. + */ +static void rustsecp256k1zkp_v0_10_0_fe_from_storage(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe_storage *a); /** If flag is true, set *r equal to *a; otherwise leave it. Constant-time. Both *r and *a must be initialized.*/ -static void rustsecp256k1zkp_v0_8_0_fe_storage_cmov(rustsecp256k1zkp_v0_8_0_fe_storage *r, const rustsecp256k1zkp_v0_8_0_fe_storage *a, int flag); +static void rustsecp256k1zkp_v0_10_0_fe_storage_cmov(rustsecp256k1zkp_v0_10_0_fe_storage *r, const rustsecp256k1zkp_v0_10_0_fe_storage *a, int flag); -/** If flag is true, set *r equal to *a; otherwise leave it. Constant-time. Both *r and *a must be initialized.*/ -static void rustsecp256k1zkp_v0_8_0_fe_cmov(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *a, int flag); +/** Conditionally move a field element in constant time. + * + * On input, both r and a must be valid field elements. Flag must be 0 or 1. + * Performs {r = flag ? a : r}. + * + * On output, r's magnitude will be the maximum of both input magnitudes. + * It will be normalized if and only if both inputs were normalized. + */ +static void rustsecp256k1zkp_v0_10_0_fe_cmov(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a, int flag); + +/** Halve the value of a field element modulo the field prime in constant-time. + * + * On input, r must be a valid field element. + * On output, r will be normalized and have magnitude floor(m/2) + 1 where m is + * the magnitude of r on input. + */ +static void rustsecp256k1zkp_v0_10_0_fe_half(rustsecp256k1zkp_v0_10_0_fe *r); + +/** Sets r to a field element with magnitude m, normalized if (and only if) m==0. + * The value is chosen so that it is likely to trigger edge cases related to + * internal overflows. */ +static void rustsecp256k1zkp_v0_10_0_fe_get_bounds(rustsecp256k1zkp_v0_10_0_fe *r, int m); + +/** Determine whether a is a square (modulo p). + * + * On input, a must be a valid field element. + */ +static int rustsecp256k1zkp_v0_10_0_fe_is_square_var(const rustsecp256k1zkp_v0_10_0_fe *a); -/** Halves the value of a field element modulo the field prime. Constant-time. - * For an input magnitude 'm', the output magnitude is set to 'floor(m/2) + 1'. - * The output is not guaranteed to be normalized, regardless of the input. */ -static void rustsecp256k1zkp_v0_8_0_fe_half(rustsecp256k1zkp_v0_8_0_fe *r); +/** Check invariants on a field element (no-op unless VERIFY is enabled). */ +static void rustsecp256k1zkp_v0_10_0_fe_verify(const rustsecp256k1zkp_v0_10_0_fe *a); +#define SECP256K1_FE_VERIFY(a) rustsecp256k1zkp_v0_10_0_fe_verify(a) -/** Sets each limb of 'r' to its upper bound at magnitude 'm'. The output will also have its - * magnitude set to 'm' and is normalized if (and only if) 'm' is zero. */ -static void rustsecp256k1zkp_v0_8_0_fe_get_bounds(rustsecp256k1zkp_v0_8_0_fe *r, int m); +/** Check that magnitude of a is at most m (no-op unless VERIFY is enabled). */ +static void rustsecp256k1zkp_v0_10_0_fe_verify_magnitude(const rustsecp256k1zkp_v0_10_0_fe *a, int m); +#define SECP256K1_FE_VERIFY_MAGNITUDE(a, m) rustsecp256k1zkp_v0_10_0_fe_verify_magnitude(a, m) #endif /* SECP256K1_FIELD_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/field_10x26.h b/secp256k1-zkp-sys/depend/secp256k1/src/field_10x26.h index 088a237a..31456d7b 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/field_10x26.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/field_10x26.h @@ -9,16 +9,29 @@ #include +/** This field implementation represents the value as 10 uint32_t limbs in base + * 2^26. */ typedef struct { - /* X = sum(i=0..9, n[i]*2^(i*26)) mod p - * where p = 2^256 - 0x1000003D1 - */ + /* A field element f represents the sum(i=0..9, f.n[i] << (i*26)) mod p, + * where p is the field modulus, 2^256 - 2^32 - 977. + * + * The individual limbs f.n[i] can exceed 2^26; the field's magnitude roughly + * corresponds to how much excess is allowed. The value + * sum(i=0..9, f.n[i] << (i*26)) may exceed p, unless the field element is + * normalized. */ uint32_t n[10]; -#ifdef VERIFY - int magnitude; - int normalized; -#endif -} rustsecp256k1zkp_v0_8_0_fe; + /* + * Magnitude m requires: + * n[i] <= 2 * m * (2^26 - 1) for i=0..8 + * n[9] <= 2 * m * (2^22 - 1) + * + * Normalized requires: + * n[i] <= (2^26 - 1) for i=0..8 + * sum(i=0..9, n[i] << (i*26)) < p + * (together these imply n[9] <= 2^22 - 1) + */ + SECP256K1_FE_VERIFY_FIELDS +} rustsecp256k1zkp_v0_10_0_fe; /* Unpacks a constant into a overlapping multi-limbed FE element. */ #define SECP256K1_FE_CONST_INNER(d7, d6, d5, d4, d3, d2, d1, d0) { \ @@ -34,15 +47,9 @@ typedef struct { (((uint32_t)d7) >> 10) \ } -#ifdef VERIFY -#define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0)), 1, 1} -#else -#define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0))} -#endif - typedef struct { uint32_t n[8]; -} rustsecp256k1zkp_v0_8_0_fe_storage; +} rustsecp256k1zkp_v0_10_0_fe_storage; #define SECP256K1_FE_STORAGE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{ (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }} #define SECP256K1_FE_STORAGE_CONST_GET(d) d.n[7], d.n[6], d.n[5], d.n[4],d.n[3], d.n[2], d.n[1], d.n[0] diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/field_10x26_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/field_10x26_impl.h index 404fe6db..eb56ed1f 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/field_10x26_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/field_10x26_impl.h @@ -7,51 +7,37 @@ #ifndef SECP256K1_FIELD_REPR_IMPL_H #define SECP256K1_FIELD_REPR_IMPL_H +#include "checkmem.h" #include "util.h" #include "field.h" #include "modinv32_impl.h" -/** See the comment at the top of field_5x52_impl.h for more details. - * - * Here, we represent field elements as 10 uint32_t's in base 2^26, least significant first, - * where limbs can contain >26 bits. - * A magnitude M means: - * - 2*M*(2^22-1) is the max (inclusive) of the most significant limb - * - 2*M*(2^26-1) is the max (inclusive) of the remaining limbs - */ - #ifdef VERIFY -static void rustsecp256k1zkp_v0_8_0_fe_verify(const rustsecp256k1zkp_v0_8_0_fe *a) { +static void rustsecp256k1zkp_v0_10_0_fe_impl_verify(const rustsecp256k1zkp_v0_10_0_fe *a) { const uint32_t *d = a->n; - int m = a->normalized ? 1 : 2 * a->magnitude, r = 1; - r &= (d[0] <= 0x3FFFFFFUL * m); - r &= (d[1] <= 0x3FFFFFFUL * m); - r &= (d[2] <= 0x3FFFFFFUL * m); - r &= (d[3] <= 0x3FFFFFFUL * m); - r &= (d[4] <= 0x3FFFFFFUL * m); - r &= (d[5] <= 0x3FFFFFFUL * m); - r &= (d[6] <= 0x3FFFFFFUL * m); - r &= (d[7] <= 0x3FFFFFFUL * m); - r &= (d[8] <= 0x3FFFFFFUL * m); - r &= (d[9] <= 0x03FFFFFUL * m); - r &= (a->magnitude >= 0); - r &= (a->magnitude <= 32); + int m = a->normalized ? 1 : 2 * a->magnitude; + VERIFY_CHECK(d[0] <= 0x3FFFFFFUL * m); + VERIFY_CHECK(d[1] <= 0x3FFFFFFUL * m); + VERIFY_CHECK(d[2] <= 0x3FFFFFFUL * m); + VERIFY_CHECK(d[3] <= 0x3FFFFFFUL * m); + VERIFY_CHECK(d[4] <= 0x3FFFFFFUL * m); + VERIFY_CHECK(d[5] <= 0x3FFFFFFUL * m); + VERIFY_CHECK(d[6] <= 0x3FFFFFFUL * m); + VERIFY_CHECK(d[7] <= 0x3FFFFFFUL * m); + VERIFY_CHECK(d[8] <= 0x3FFFFFFUL * m); + VERIFY_CHECK(d[9] <= 0x03FFFFFUL * m); if (a->normalized) { - r &= (a->magnitude <= 1); - if (r && (d[9] == 0x03FFFFFUL)) { + if (d[9] == 0x03FFFFFUL) { uint32_t mid = d[8] & d[7] & d[6] & d[5] & d[4] & d[3] & d[2]; if (mid == 0x3FFFFFFUL) { - r &= ((d[1] + 0x40UL + ((d[0] + 0x3D1UL) >> 26)) <= 0x3FFFFFFUL); + VERIFY_CHECK((d[1] + 0x40UL + ((d[0] + 0x3D1UL) >> 26)) <= 0x3FFFFFFUL); } } } - VERIFY_CHECK(r == 1); } #endif -static void rustsecp256k1zkp_v0_8_0_fe_get_bounds(rustsecp256k1zkp_v0_8_0_fe *r, int m) { - VERIFY_CHECK(m >= 0); - VERIFY_CHECK(m <= 2048); +static void rustsecp256k1zkp_v0_10_0_fe_impl_get_bounds(rustsecp256k1zkp_v0_10_0_fe *r, int m) { r->n[0] = 0x3FFFFFFUL * 2 * m; r->n[1] = 0x3FFFFFFUL * 2 * m; r->n[2] = 0x3FFFFFFUL * 2 * m; @@ -62,14 +48,9 @@ static void rustsecp256k1zkp_v0_8_0_fe_get_bounds(rustsecp256k1zkp_v0_8_0_fe *r, r->n[7] = 0x3FFFFFFUL * 2 * m; r->n[8] = 0x3FFFFFFUL * 2 * m; r->n[9] = 0x03FFFFFUL * 2 * m; -#ifdef VERIFY - r->magnitude = m; - r->normalized = (m == 0); - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -static void rustsecp256k1zkp_v0_8_0_fe_normalize(rustsecp256k1zkp_v0_8_0_fe *r) { +static void rustsecp256k1zkp_v0_10_0_fe_impl_normalize(rustsecp256k1zkp_v0_10_0_fe *r) { uint32_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4], t5 = r->n[5], t6 = r->n[6], t7 = r->n[7], t8 = r->n[8], t9 = r->n[9]; @@ -116,15 +97,9 @@ static void rustsecp256k1zkp_v0_8_0_fe_normalize(rustsecp256k1zkp_v0_8_0_fe *r) r->n[0] = t0; r->n[1] = t1; r->n[2] = t2; r->n[3] = t3; r->n[4] = t4; r->n[5] = t5; r->n[6] = t6; r->n[7] = t7; r->n[8] = t8; r->n[9] = t9; - -#ifdef VERIFY - r->magnitude = 1; - r->normalized = 1; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -static void rustsecp256k1zkp_v0_8_0_fe_normalize_weak(rustsecp256k1zkp_v0_8_0_fe *r) { +static void rustsecp256k1zkp_v0_10_0_fe_impl_normalize_weak(rustsecp256k1zkp_v0_10_0_fe *r) { uint32_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4], t5 = r->n[5], t6 = r->n[6], t7 = r->n[7], t8 = r->n[8], t9 = r->n[9]; @@ -148,14 +123,9 @@ static void rustsecp256k1zkp_v0_8_0_fe_normalize_weak(rustsecp256k1zkp_v0_8_0_fe r->n[0] = t0; r->n[1] = t1; r->n[2] = t2; r->n[3] = t3; r->n[4] = t4; r->n[5] = t5; r->n[6] = t6; r->n[7] = t7; r->n[8] = t8; r->n[9] = t9; - -#ifdef VERIFY - r->magnitude = 1; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -static void rustsecp256k1zkp_v0_8_0_fe_normalize_var(rustsecp256k1zkp_v0_8_0_fe *r) { +static void rustsecp256k1zkp_v0_10_0_fe_impl_normalize_var(rustsecp256k1zkp_v0_10_0_fe *r) { uint32_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4], t5 = r->n[5], t6 = r->n[6], t7 = r->n[7], t8 = r->n[8], t9 = r->n[9]; @@ -203,15 +173,9 @@ static void rustsecp256k1zkp_v0_8_0_fe_normalize_var(rustsecp256k1zkp_v0_8_0_fe r->n[0] = t0; r->n[1] = t1; r->n[2] = t2; r->n[3] = t3; r->n[4] = t4; r->n[5] = t5; r->n[6] = t6; r->n[7] = t7; r->n[8] = t8; r->n[9] = t9; - -#ifdef VERIFY - r->magnitude = 1; - r->normalized = 1; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -static int rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero(const rustsecp256k1zkp_v0_8_0_fe *r) { +static int rustsecp256k1zkp_v0_10_0_fe_impl_normalizes_to_zero(const rustsecp256k1zkp_v0_10_0_fe *r) { uint32_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4], t5 = r->n[5], t6 = r->n[6], t7 = r->n[7], t8 = r->n[8], t9 = r->n[9]; @@ -240,7 +204,7 @@ static int rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero(const rustsecp256k1zkp_ return (z0 == 0) | (z1 == 0x3FFFFFFUL); } -static int rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero_var(const rustsecp256k1zkp_v0_8_0_fe *r) { +static int rustsecp256k1zkp_v0_10_0_fe_impl_normalizes_to_zero_var(const rustsecp256k1zkp_v0_10_0_fe *r) { uint32_t t0, t1, t2, t3, t4, t5, t6, t7, t8, t9; uint32_t z0, z1; uint32_t x; @@ -292,53 +256,29 @@ static int rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero_var(const rustsecp256k1 return (z0 == 0) | (z1 == 0x3FFFFFFUL); } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_set_int(rustsecp256k1zkp_v0_8_0_fe *r, int a) { - VERIFY_CHECK(0 <= a && a <= 0x7FFF); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_impl_set_int(rustsecp256k1zkp_v0_10_0_fe *r, int a) { r->n[0] = a; r->n[1] = r->n[2] = r->n[3] = r->n[4] = r->n[5] = r->n[6] = r->n[7] = r->n[8] = r->n[9] = 0; -#ifdef VERIFY - r->magnitude = (a != 0); - r->normalized = 1; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_fe_is_zero(const rustsecp256k1zkp_v0_8_0_fe *a) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_fe_impl_is_zero(const rustsecp256k1zkp_v0_10_0_fe *a) { const uint32_t *t = a->n; -#ifdef VERIFY - VERIFY_CHECK(a->normalized); - rustsecp256k1zkp_v0_8_0_fe_verify(a); -#endif return (t[0] | t[1] | t[2] | t[3] | t[4] | t[5] | t[6] | t[7] | t[8] | t[9]) == 0; } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_fe_is_odd(const rustsecp256k1zkp_v0_8_0_fe *a) { -#ifdef VERIFY - VERIFY_CHECK(a->normalized); - rustsecp256k1zkp_v0_8_0_fe_verify(a); -#endif +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_fe_impl_is_odd(const rustsecp256k1zkp_v0_10_0_fe *a) { return a->n[0] & 1; } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_clear(rustsecp256k1zkp_v0_8_0_fe *a) { +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_impl_clear(rustsecp256k1zkp_v0_10_0_fe *a) { int i; -#ifdef VERIFY - a->magnitude = 0; - a->normalized = 1; -#endif for (i=0; i<10; i++) { a->n[i] = 0; } } -static int rustsecp256k1zkp_v0_8_0_fe_cmp_var(const rustsecp256k1zkp_v0_8_0_fe *a, const rustsecp256k1zkp_v0_8_0_fe *b) { +static int rustsecp256k1zkp_v0_10_0_fe_impl_cmp_var(const rustsecp256k1zkp_v0_10_0_fe *a, const rustsecp256k1zkp_v0_10_0_fe *b) { int i; -#ifdef VERIFY - VERIFY_CHECK(a->normalized); - VERIFY_CHECK(b->normalized); - rustsecp256k1zkp_v0_8_0_fe_verify(a); - rustsecp256k1zkp_v0_8_0_fe_verify(b); -#endif for (i = 9; i >= 0; i--) { if (a->n[i] > b->n[i]) { return 1; @@ -350,8 +290,7 @@ static int rustsecp256k1zkp_v0_8_0_fe_cmp_var(const rustsecp256k1zkp_v0_8_0_fe * return 0; } -static int rustsecp256k1zkp_v0_8_0_fe_set_b32(rustsecp256k1zkp_v0_8_0_fe *r, const unsigned char *a) { - int ret; +static void rustsecp256k1zkp_v0_10_0_fe_impl_set_b32_mod(rustsecp256k1zkp_v0_10_0_fe *r, const unsigned char *a) { r->n[0] = (uint32_t)a[31] | ((uint32_t)a[30] << 8) | ((uint32_t)a[29] << 16) | ((uint32_t)(a[28] & 0x3) << 24); r->n[1] = (uint32_t)((a[28] >> 2) & 0x3f) | ((uint32_t)a[27] << 6) | ((uint32_t)a[26] << 14) | ((uint32_t)(a[25] & 0xf) << 22); r->n[2] = (uint32_t)((a[25] >> 4) & 0xf) | ((uint32_t)a[24] << 4) | ((uint32_t)a[23] << 12) | ((uint32_t)(a[22] & 0x3f) << 20); @@ -362,26 +301,15 @@ static int rustsecp256k1zkp_v0_8_0_fe_set_b32(rustsecp256k1zkp_v0_8_0_fe *r, con r->n[7] = (uint32_t)((a[9] >> 6) & 0x3) | ((uint32_t)a[8] << 2) | ((uint32_t)a[7] << 10) | ((uint32_t)a[6] << 18); r->n[8] = (uint32_t)a[5] | ((uint32_t)a[4] << 8) | ((uint32_t)a[3] << 16) | ((uint32_t)(a[2] & 0x3) << 24); r->n[9] = (uint32_t)((a[2] >> 2) & 0x3f) | ((uint32_t)a[1] << 6) | ((uint32_t)a[0] << 14); +} - ret = !((r->n[9] == 0x3FFFFFUL) & ((r->n[8] & r->n[7] & r->n[6] & r->n[5] & r->n[4] & r->n[3] & r->n[2]) == 0x3FFFFFFUL) & ((r->n[1] + 0x40UL + ((r->n[0] + 0x3D1UL) >> 26)) > 0x3FFFFFFUL)); -#ifdef VERIFY - r->magnitude = 1; - if (ret) { - r->normalized = 1; - rustsecp256k1zkp_v0_8_0_fe_verify(r); - } else { - r->normalized = 0; - } -#endif - return ret; +static int rustsecp256k1zkp_v0_10_0_fe_impl_set_b32_limit(rustsecp256k1zkp_v0_10_0_fe *r, const unsigned char *a) { + rustsecp256k1zkp_v0_10_0_fe_impl_set_b32_mod(r, a); + return !((r->n[9] == 0x3FFFFFUL) & ((r->n[8] & r->n[7] & r->n[6] & r->n[5] & r->n[4] & r->n[3] & r->n[2]) == 0x3FFFFFFUL) & ((r->n[1] + 0x40UL + ((r->n[0] + 0x3D1UL) >> 26)) > 0x3FFFFFFUL)); } /** Convert a field element to a 32-byte big endian value. Requires the input to be normalized */ -static void rustsecp256k1zkp_v0_8_0_fe_get_b32(unsigned char *r, const rustsecp256k1zkp_v0_8_0_fe *a) { -#ifdef VERIFY - VERIFY_CHECK(a->normalized); - rustsecp256k1zkp_v0_8_0_fe_verify(a); -#endif +static void rustsecp256k1zkp_v0_10_0_fe_impl_get_b32(unsigned char *r, const rustsecp256k1zkp_v0_10_0_fe *a) { r[0] = (a->n[9] >> 14) & 0xff; r[1] = (a->n[9] >> 6) & 0xff; r[2] = ((a->n[9] & 0x3F) << 2) | ((a->n[8] >> 24) & 0x3); @@ -416,15 +344,15 @@ static void rustsecp256k1zkp_v0_8_0_fe_get_b32(unsigned char *r, const rustsecp2 r[31] = a->n[0] & 0xff; } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_negate(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *a, int m) { -#ifdef VERIFY - VERIFY_CHECK(a->magnitude <= m); - rustsecp256k1zkp_v0_8_0_fe_verify(a); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_impl_negate_unchecked(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a, int m) { + /* For all legal values of m (0..31), the following properties hold: */ VERIFY_CHECK(0x3FFFC2FUL * 2 * (m + 1) >= 0x3FFFFFFUL * 2 * m); VERIFY_CHECK(0x3FFFFBFUL * 2 * (m + 1) >= 0x3FFFFFFUL * 2 * m); VERIFY_CHECK(0x3FFFFFFUL * 2 * (m + 1) >= 0x3FFFFFFUL * 2 * m); VERIFY_CHECK(0x03FFFFFUL * 2 * (m + 1) >= 0x03FFFFFUL * 2 * m); -#endif + + /* Due to the properties above, the left hand in the subtractions below is never less than + * the right hand. */ r->n[0] = 0x3FFFC2FUL * 2 * (m + 1) - a->n[0]; r->n[1] = 0x3FFFFBFUL * 2 * (m + 1) - a->n[1]; r->n[2] = 0x3FFFFFFUL * 2 * (m + 1) - a->n[2]; @@ -435,14 +363,9 @@ SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_negate(rustsecp256k1zkp_ r->n[7] = 0x3FFFFFFUL * 2 * (m + 1) - a->n[7]; r->n[8] = 0x3FFFFFFUL * 2 * (m + 1) - a->n[8]; r->n[9] = 0x03FFFFFUL * 2 * (m + 1) - a->n[9]; -#ifdef VERIFY - r->magnitude = m + 1; - r->normalized = 0; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_mul_int(rustsecp256k1zkp_v0_8_0_fe *r, int a) { +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_impl_mul_int_unchecked(rustsecp256k1zkp_v0_10_0_fe *r, int a) { r->n[0] *= a; r->n[1] *= a; r->n[2] *= a; @@ -453,17 +376,9 @@ SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_mul_int(rustsecp256k1zkp r->n[7] *= a; r->n[8] *= a; r->n[9] *= a; -#ifdef VERIFY - r->magnitude *= a; - r->normalized = 0; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_add(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *a) { -#ifdef VERIFY - rustsecp256k1zkp_v0_8_0_fe_verify(a); -#endif +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_impl_add(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a) { r->n[0] += a->n[0]; r->n[1] += a->n[1]; r->n[2] += a->n[2]; @@ -474,28 +389,23 @@ SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_add(rustsecp256k1zkp_v0_ r->n[7] += a->n[7]; r->n[8] += a->n[8]; r->n[9] += a->n[9]; -#ifdef VERIFY - r->magnitude += a->magnitude; - r->normalized = 0; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif +} + +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_impl_add_int(rustsecp256k1zkp_v0_10_0_fe *r, int a) { + r->n[0] += a; } #if defined(USE_EXTERNAL_ASM) /* External assembler implementation */ -void rustsecp256k1zkp_v0_8_0_fe_mul_inner(uint32_t *r, const uint32_t *a, const uint32_t * SECP256K1_RESTRICT b); -void rustsecp256k1zkp_v0_8_0_fe_sqr_inner(uint32_t *r, const uint32_t *a); +void rustsecp256k1zkp_v0_10_0_fe_mul_inner(uint32_t *r, const uint32_t *a, const uint32_t * SECP256K1_RESTRICT b); +void rustsecp256k1zkp_v0_10_0_fe_sqr_inner(uint32_t *r, const uint32_t *a); #else -#ifdef VERIFY #define VERIFY_BITS(x, n) VERIFY_CHECK(((x) >> (n)) == 0) -#else -#define VERIFY_BITS(x, n) do { } while(0) -#endif -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_mul_inner(uint32_t *r, const uint32_t *a, const uint32_t * SECP256K1_RESTRICT b) { +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_mul_inner(uint32_t *r, const uint32_t *a, const uint32_t * SECP256K1_RESTRICT b) { uint64_t c, d; uint64_t u0, u1, u2, u3, u4, u5, u6, u7, u8; uint32_t t9, t1, t0, t2, t3, t4, t5, t6, t7; @@ -825,7 +735,7 @@ SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_mul_inner(uint32_t *r, c /* [r9 r8 r7 r6 r5 r4 r3 r2 r1 r0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */ } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_sqr_inner(uint32_t *r, const uint32_t *a) { +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_sqr_inner(uint32_t *r, const uint32_t *a) { uint64_t c, d; uint64_t u0, u1, u2, u3, u4, u5, u6, u7, u8; uint32_t t9, t0, t1, t2, t3, t4, t5, t6, t7; @@ -1100,40 +1010,19 @@ SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_sqr_inner(uint32_t *r, c } #endif -static void rustsecp256k1zkp_v0_8_0_fe_mul(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *a, const rustsecp256k1zkp_v0_8_0_fe * SECP256K1_RESTRICT b) { -#ifdef VERIFY - VERIFY_CHECK(a->magnitude <= 8); - VERIFY_CHECK(b->magnitude <= 8); - rustsecp256k1zkp_v0_8_0_fe_verify(a); - rustsecp256k1zkp_v0_8_0_fe_verify(b); - VERIFY_CHECK(r != b); - VERIFY_CHECK(a != b); -#endif - rustsecp256k1zkp_v0_8_0_fe_mul_inner(r->n, a->n, b->n); -#ifdef VERIFY - r->magnitude = 1; - r->normalized = 0; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_impl_mul(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a, const rustsecp256k1zkp_v0_10_0_fe * SECP256K1_RESTRICT b) { + rustsecp256k1zkp_v0_10_0_fe_mul_inner(r->n, a->n, b->n); } -static void rustsecp256k1zkp_v0_8_0_fe_sqr(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *a) { -#ifdef VERIFY - VERIFY_CHECK(a->magnitude <= 8); - rustsecp256k1zkp_v0_8_0_fe_verify(a); -#endif - rustsecp256k1zkp_v0_8_0_fe_sqr_inner(r->n, a->n); -#ifdef VERIFY - r->magnitude = 1; - r->normalized = 0; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_impl_sqr(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a) { + rustsecp256k1zkp_v0_10_0_fe_sqr_inner(r->n, a->n); } -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_fe_cmov(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *a, int flag) { +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_impl_cmov(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a, int flag) { uint32_t mask0, mask1; - VG_CHECK_VERIFY(r->n, sizeof(r->n)); - mask0 = flag + ~((uint32_t)0); + volatile int vflag = flag; + SECP256K1_CHECKMEM_CHECK_VERIFY(r->n, sizeof(r->n)); + mask0 = vflag + ~((uint32_t)0); mask1 = ~mask0; r->n[0] = (r->n[0] & mask0) | (a->n[0] & mask1); r->n[1] = (r->n[1] & mask0) | (a->n[1] & mask1); @@ -1145,25 +1034,14 @@ static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_fe_cmov(rustsecp256k1zkp_v0 r->n[7] = (r->n[7] & mask0) | (a->n[7] & mask1); r->n[8] = (r->n[8] & mask0) | (a->n[8] & mask1); r->n[9] = (r->n[9] & mask0) | (a->n[9] & mask1); -#ifdef VERIFY - if (flag) { - r->magnitude = a->magnitude; - r->normalized = a->normalized; - } -#endif } -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_fe_half(rustsecp256k1zkp_v0_8_0_fe *r) { +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_fe_impl_half(rustsecp256k1zkp_v0_10_0_fe *r) { uint32_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4], t5 = r->n[5], t6 = r->n[6], t7 = r->n[7], t8 = r->n[8], t9 = r->n[9]; uint32_t one = (uint32_t)1; uint32_t mask = -(t0 & one) >> 6; -#ifdef VERIFY - rustsecp256k1zkp_v0_8_0_fe_verify(r); - VERIFY_CHECK(r->magnitude < 32); -#endif - /* Bounds analysis (over the rationals). * * Let m = r->magnitude @@ -1210,10 +1088,8 @@ static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_fe_half(rustsecp256k1zkp_v0 * * Current bounds: t0..t8 <= C * (m/2 + 1/2) * t9 <= D * (m/2 + 1/4) - */ - -#ifdef VERIFY - /* Therefore the output magnitude (M) has to be set such that: + * + * Therefore the output magnitude (M) has to be set such that: * t0..t8: C * M >= C * (m/2 + 1/2) * t9: D * M >= D * (m/2 + 1/4) * @@ -1223,16 +1099,13 @@ static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_fe_half(rustsecp256k1zkp_v0 * and since we want the smallest such integer value for M: * M == floor(m/2) + 1 */ - r->magnitude = (r->magnitude >> 1) + 1; - r->normalized = 0; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_fe_storage_cmov(rustsecp256k1zkp_v0_8_0_fe_storage *r, const rustsecp256k1zkp_v0_8_0_fe_storage *a, int flag) { +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_fe_storage_cmov(rustsecp256k1zkp_v0_10_0_fe_storage *r, const rustsecp256k1zkp_v0_10_0_fe_storage *a, int flag) { uint32_t mask0, mask1; - VG_CHECK_VERIFY(r->n, sizeof(r->n)); - mask0 = flag + ~((uint32_t)0); + volatile int vflag = flag; + SECP256K1_CHECKMEM_CHECK_VERIFY(r->n, sizeof(r->n)); + mask0 = vflag + ~((uint32_t)0); mask1 = ~mask0; r->n[0] = (r->n[0] & mask0) | (a->n[0] & mask1); r->n[1] = (r->n[1] & mask0) | (a->n[1] & mask1); @@ -1244,10 +1117,7 @@ static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_fe_storage_cmov(rustsecp256 r->n[7] = (r->n[7] & mask0) | (a->n[7] & mask1); } -static void rustsecp256k1zkp_v0_8_0_fe_to_storage(rustsecp256k1zkp_v0_8_0_fe_storage *r, const rustsecp256k1zkp_v0_8_0_fe *a) { -#ifdef VERIFY - VERIFY_CHECK(a->normalized); -#endif +static void rustsecp256k1zkp_v0_10_0_fe_impl_to_storage(rustsecp256k1zkp_v0_10_0_fe_storage *r, const rustsecp256k1zkp_v0_10_0_fe *a) { r->n[0] = a->n[0] | a->n[1] << 26; r->n[1] = a->n[1] >> 6 | a->n[2] << 20; r->n[2] = a->n[2] >> 12 | a->n[3] << 14; @@ -1258,7 +1128,7 @@ static void rustsecp256k1zkp_v0_8_0_fe_to_storage(rustsecp256k1zkp_v0_8_0_fe_sto r->n[7] = a->n[8] >> 16 | a->n[9] << 10; } -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_fe_from_storage(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe_storage *a) { +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_fe_impl_from_storage(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe_storage *a) { r->n[0] = a->n[0] & 0x3FFFFFFUL; r->n[1] = a->n[0] >> 26 | ((a->n[1] << 6) & 0x3FFFFFFUL); r->n[2] = a->n[1] >> 20 | ((a->n[2] << 12) & 0x3FFFFFFUL); @@ -1269,19 +1139,14 @@ static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_fe_from_storage(rustsecp256 r->n[7] = a->n[5] >> 22 | ((a->n[6] << 10) & 0x3FFFFFFUL); r->n[8] = a->n[6] >> 16 | ((a->n[7] << 16) & 0x3FFFFFFUL); r->n[9] = a->n[7] >> 10; -#ifdef VERIFY - r->magnitude = 1; - r->normalized = 1; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -static void rustsecp256k1zkp_v0_8_0_fe_from_signed30(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_modinv32_signed30 *a) { +static void rustsecp256k1zkp_v0_10_0_fe_from_signed30(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_modinv32_signed30 *a) { const uint32_t M26 = UINT32_MAX >> 6; const uint32_t a0 = a->v[0], a1 = a->v[1], a2 = a->v[2], a3 = a->v[3], a4 = a->v[4], a5 = a->v[5], a6 = a->v[6], a7 = a->v[7], a8 = a->v[8]; - /* The output from rustsecp256k1zkp_v0_8_0_modinv32{_var} should be normalized to range [0,modulus), and + /* The output from rustsecp256k1zkp_v0_10_0_modinv32{_var} should be normalized to range [0,modulus), and * have limbs in [0,2^30). The modulus is < 2^256, so the top limb must be below 2^(256-30*8). */ VERIFY_CHECK(a0 >> 30 == 0); @@ -1304,23 +1169,13 @@ static void rustsecp256k1zkp_v0_8_0_fe_from_signed30(rustsecp256k1zkp_v0_8_0_fe r->n[7] = (a6 >> 2 ) & M26; r->n[8] = (a6 >> 28 | a7 << 2) & M26; r->n[9] = (a7 >> 24 | a8 << 6); - -#ifdef VERIFY - r->magnitude = 1; - r->normalized = 1; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -static void rustsecp256k1zkp_v0_8_0_fe_to_signed30(rustsecp256k1zkp_v0_8_0_modinv32_signed30 *r, const rustsecp256k1zkp_v0_8_0_fe *a) { +static void rustsecp256k1zkp_v0_10_0_fe_to_signed30(rustsecp256k1zkp_v0_10_0_modinv32_signed30 *r, const rustsecp256k1zkp_v0_10_0_fe *a) { const uint32_t M30 = UINT32_MAX >> 2; const uint64_t a0 = a->n[0], a1 = a->n[1], a2 = a->n[2], a3 = a->n[3], a4 = a->n[4], a5 = a->n[5], a6 = a->n[6], a7 = a->n[7], a8 = a->n[8], a9 = a->n[9]; -#ifdef VERIFY - VERIFY_CHECK(a->normalized); -#endif - r->v[0] = (a0 | a1 << 26) & M30; r->v[1] = (a1 >> 4 | a2 << 22) & M30; r->v[2] = (a2 >> 8 | a3 << 18) & M30; @@ -1333,35 +1188,52 @@ static void rustsecp256k1zkp_v0_8_0_fe_to_signed30(rustsecp256k1zkp_v0_8_0_modin r->v[8] = a9 >> 6; } -static const rustsecp256k1zkp_v0_8_0_modinv32_modinfo rustsecp256k1zkp_v0_8_0_const_modinfo_fe = { +static const rustsecp256k1zkp_v0_10_0_modinv32_modinfo rustsecp256k1zkp_v0_10_0_const_modinfo_fe = { {{-0x3D1, -4, 0, 0, 0, 0, 0, 0, 65536}}, 0x2DDACACFL }; -static void rustsecp256k1zkp_v0_8_0_fe_inv(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *x) { - rustsecp256k1zkp_v0_8_0_fe tmp; - rustsecp256k1zkp_v0_8_0_modinv32_signed30 s; +static void rustsecp256k1zkp_v0_10_0_fe_impl_inv(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *x) { + rustsecp256k1zkp_v0_10_0_fe tmp = *x; + rustsecp256k1zkp_v0_10_0_modinv32_signed30 s; - tmp = *x; - rustsecp256k1zkp_v0_8_0_fe_normalize(&tmp); - rustsecp256k1zkp_v0_8_0_fe_to_signed30(&s, &tmp); - rustsecp256k1zkp_v0_8_0_modinv32(&s, &rustsecp256k1zkp_v0_8_0_const_modinfo_fe); - rustsecp256k1zkp_v0_8_0_fe_from_signed30(r, &s); + rustsecp256k1zkp_v0_10_0_fe_normalize(&tmp); + rustsecp256k1zkp_v0_10_0_fe_to_signed30(&s, &tmp); + rustsecp256k1zkp_v0_10_0_modinv32(&s, &rustsecp256k1zkp_v0_10_0_const_modinfo_fe); + rustsecp256k1zkp_v0_10_0_fe_from_signed30(r, &s); +} - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero(r) == rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero(&tmp)); +static void rustsecp256k1zkp_v0_10_0_fe_impl_inv_var(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *x) { + rustsecp256k1zkp_v0_10_0_fe tmp = *x; + rustsecp256k1zkp_v0_10_0_modinv32_signed30 s; + + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&tmp); + rustsecp256k1zkp_v0_10_0_fe_to_signed30(&s, &tmp); + rustsecp256k1zkp_v0_10_0_modinv32_var(&s, &rustsecp256k1zkp_v0_10_0_const_modinfo_fe); + rustsecp256k1zkp_v0_10_0_fe_from_signed30(r, &s); } -static void rustsecp256k1zkp_v0_8_0_fe_inv_var(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *x) { - rustsecp256k1zkp_v0_8_0_fe tmp; - rustsecp256k1zkp_v0_8_0_modinv32_signed30 s; +static int rustsecp256k1zkp_v0_10_0_fe_impl_is_square_var(const rustsecp256k1zkp_v0_10_0_fe *x) { + rustsecp256k1zkp_v0_10_0_fe tmp; + rustsecp256k1zkp_v0_10_0_modinv32_signed30 s; + int jac, ret; tmp = *x; - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&tmp); - rustsecp256k1zkp_v0_8_0_fe_to_signed30(&s, &tmp); - rustsecp256k1zkp_v0_8_0_modinv32_var(&s, &rustsecp256k1zkp_v0_8_0_const_modinfo_fe); - rustsecp256k1zkp_v0_8_0_fe_from_signed30(r, &s); - - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero(r) == rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero(&tmp)); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&tmp); + /* rustsecp256k1zkp_v0_10_0_jacobi32_maybe_var cannot deal with input 0. */ + if (rustsecp256k1zkp_v0_10_0_fe_is_zero(&tmp)) return 1; + rustsecp256k1zkp_v0_10_0_fe_to_signed30(&s, &tmp); + jac = rustsecp256k1zkp_v0_10_0_jacobi32_maybe_var(&s, &rustsecp256k1zkp_v0_10_0_const_modinfo_fe); + if (jac == 0) { + /* rustsecp256k1zkp_v0_10_0_jacobi32_maybe_var failed to compute the Jacobi symbol. Fall back + * to computing a square root. This should be extremely rare with random + * input (except in VERIFY mode, where a lower iteration count is used). */ + rustsecp256k1zkp_v0_10_0_fe dummy; + ret = rustsecp256k1zkp_v0_10_0_fe_sqrt(&dummy, &tmp); + } else { + ret = jac >= 0; + } + return ret; } #endif /* SECP256K1_FIELD_REPR_IMPL_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/field_5x52.h b/secp256k1-zkp-sys/depend/secp256k1/src/field_5x52.h index 8a01767b..12ba05e5 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/field_5x52.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/field_5x52.h @@ -9,16 +9,29 @@ #include +/** This field implementation represents the value as 5 uint64_t limbs in base + * 2^52. */ typedef struct { - /* X = sum(i=0..4, n[i]*2^(i*52)) mod p - * where p = 2^256 - 0x1000003D1 - */ + /* A field element f represents the sum(i=0..4, f.n[i] << (i*52)) mod p, + * where p is the field modulus, 2^256 - 2^32 - 977. + * + * The individual limbs f.n[i] can exceed 2^52; the field's magnitude roughly + * corresponds to how much excess is allowed. The value + * sum(i=0..4, f.n[i] << (i*52)) may exceed p, unless the field element is + * normalized. */ uint64_t n[5]; -#ifdef VERIFY - int magnitude; - int normalized; -#endif -} rustsecp256k1zkp_v0_8_0_fe; + /* + * Magnitude m requires: + * n[i] <= 2 * m * (2^52 - 1) for i=0..3 + * n[4] <= 2 * m * (2^48 - 1) + * + * Normalized requires: + * n[i] <= (2^52 - 1) for i=0..3 + * sum(i=0..4, n[i] << (i*52)) < p + * (together these imply n[4] <= 2^48 - 1) + */ + SECP256K1_FE_VERIFY_FIELDS +} rustsecp256k1zkp_v0_10_0_fe; /* Unpacks a constant into a overlapping multi-limbed FE element. */ #define SECP256K1_FE_CONST_INNER(d7, d6, d5, d4, d3, d2, d1, d0) { \ @@ -29,15 +42,9 @@ typedef struct { ((uint64_t)(d6) >> 16) | (((uint64_t)(d7)) << 16) \ } -#ifdef VERIFY -#define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0)), 1, 1} -#else -#define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0))} -#endif - typedef struct { uint64_t n[4]; -} rustsecp256k1zkp_v0_8_0_fe_storage; +} rustsecp256k1zkp_v0_10_0_fe_storage; #define SECP256K1_FE_STORAGE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{ \ (d0) | (((uint64_t)(d1)) << 32), \ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/field_5x52_asm_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/field_5x52_asm_impl.h deleted file mode 100644 index 74c8e597..00000000 --- a/secp256k1-zkp-sys/depend/secp256k1/src/field_5x52_asm_impl.h +++ /dev/null @@ -1,502 +0,0 @@ -/*********************************************************************** - * Copyright (c) 2013-2014 Diederik Huys, Pieter Wuille * - * Distributed under the MIT software license, see the accompanying * - * file COPYING or https://www.opensource.org/licenses/mit-license.php.* - ***********************************************************************/ - -/** - * Changelog: - * - March 2013, Diederik Huys: original version - * - November 2014, Pieter Wuille: updated to use Peter Dettman's parallel multiplication algorithm - * - December 2014, Pieter Wuille: converted from YASM to GCC inline assembly - */ - -#ifndef SECP256K1_FIELD_INNER5X52_IMPL_H -#define SECP256K1_FIELD_INNER5X52_IMPL_H - -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_mul_inner(uint64_t *r, const uint64_t *a, const uint64_t * SECP256K1_RESTRICT b) { -/** - * Registers: rdx:rax = multiplication accumulator - * r9:r8 = c - * r15:rcx = d - * r10-r14 = a0-a4 - * rbx = b - * rdi = r - * rsi = a / t? - */ - uint64_t tmp1, tmp2, tmp3; -__asm__ __volatile__( - "movq 0(%%rsi),%%r10\n" - "movq 8(%%rsi),%%r11\n" - "movq 16(%%rsi),%%r12\n" - "movq 24(%%rsi),%%r13\n" - "movq 32(%%rsi),%%r14\n" - - /* d += a3 * b0 */ - "movq 0(%%rbx),%%rax\n" - "mulq %%r13\n" - "movq %%rax,%%rcx\n" - "movq %%rdx,%%r15\n" - /* d += a2 * b1 */ - "movq 8(%%rbx),%%rax\n" - "mulq %%r12\n" - "addq %%rax,%%rcx\n" - "adcq %%rdx,%%r15\n" - /* d += a1 * b2 */ - "movq 16(%%rbx),%%rax\n" - "mulq %%r11\n" - "addq %%rax,%%rcx\n" - "adcq %%rdx,%%r15\n" - /* d = a0 * b3 */ - "movq 24(%%rbx),%%rax\n" - "mulq %%r10\n" - "addq %%rax,%%rcx\n" - "adcq %%rdx,%%r15\n" - /* c = a4 * b4 */ - "movq 32(%%rbx),%%rax\n" - "mulq %%r14\n" - "movq %%rax,%%r8\n" - "movq %%rdx,%%r9\n" - /* d += (c & M) * R */ - "movq $0xfffffffffffff,%%rdx\n" - "andq %%rdx,%%rax\n" - "movq $0x1000003d10,%%rdx\n" - "mulq %%rdx\n" - "addq %%rax,%%rcx\n" - "adcq %%rdx,%%r15\n" - /* c >>= 52 (%%r8 only) */ - "shrdq $52,%%r9,%%r8\n" - /* t3 (tmp1) = d & M */ - "movq %%rcx,%%rsi\n" - "movq $0xfffffffffffff,%%rdx\n" - "andq %%rdx,%%rsi\n" - "movq %%rsi,%q1\n" - /* d >>= 52 */ - "shrdq $52,%%r15,%%rcx\n" - "xorq %%r15,%%r15\n" - /* d += a4 * b0 */ - "movq 0(%%rbx),%%rax\n" - "mulq %%r14\n" - "addq %%rax,%%rcx\n" - "adcq %%rdx,%%r15\n" - /* d += a3 * b1 */ - "movq 8(%%rbx),%%rax\n" - "mulq %%r13\n" - "addq %%rax,%%rcx\n" - "adcq %%rdx,%%r15\n" - /* d += a2 * b2 */ - "movq 16(%%rbx),%%rax\n" - "mulq %%r12\n" - "addq %%rax,%%rcx\n" - "adcq %%rdx,%%r15\n" - /* d += a1 * b3 */ - "movq 24(%%rbx),%%rax\n" - "mulq %%r11\n" - "addq %%rax,%%rcx\n" - "adcq %%rdx,%%r15\n" - /* d += a0 * b4 */ - "movq 32(%%rbx),%%rax\n" - "mulq %%r10\n" - "addq %%rax,%%rcx\n" - "adcq %%rdx,%%r15\n" - /* d += c * R */ - "movq %%r8,%%rax\n" - "movq $0x1000003d10,%%rdx\n" - "mulq %%rdx\n" - "addq %%rax,%%rcx\n" - "adcq %%rdx,%%r15\n" - /* t4 = d & M (%%rsi) */ - "movq %%rcx,%%rsi\n" - "movq $0xfffffffffffff,%%rdx\n" - "andq %%rdx,%%rsi\n" - /* d >>= 52 */ - "shrdq $52,%%r15,%%rcx\n" - "xorq %%r15,%%r15\n" - /* tx = t4 >> 48 (tmp3) */ - "movq %%rsi,%%rax\n" - "shrq $48,%%rax\n" - "movq %%rax,%q3\n" - /* t4 &= (M >> 4) (tmp2) */ - "movq $0xffffffffffff,%%rax\n" - "andq %%rax,%%rsi\n" - "movq %%rsi,%q2\n" - /* c = a0 * b0 */ - "movq 0(%%rbx),%%rax\n" - "mulq %%r10\n" - "movq %%rax,%%r8\n" - "movq %%rdx,%%r9\n" - /* d += a4 * b1 */ - "movq 8(%%rbx),%%rax\n" - "mulq %%r14\n" - "addq %%rax,%%rcx\n" - "adcq %%rdx,%%r15\n" - /* d += a3 * b2 */ - "movq 16(%%rbx),%%rax\n" - "mulq %%r13\n" - "addq %%rax,%%rcx\n" - "adcq %%rdx,%%r15\n" - /* d += a2 * b3 */ - "movq 24(%%rbx),%%rax\n" - "mulq %%r12\n" - "addq %%rax,%%rcx\n" - "adcq %%rdx,%%r15\n" - /* d += a1 * b4 */ - "movq 32(%%rbx),%%rax\n" - "mulq %%r11\n" - "addq %%rax,%%rcx\n" - "adcq %%rdx,%%r15\n" - /* u0 = d & M (%%rsi) */ - "movq %%rcx,%%rsi\n" - "movq $0xfffffffffffff,%%rdx\n" - "andq %%rdx,%%rsi\n" - /* d >>= 52 */ - "shrdq $52,%%r15,%%rcx\n" - "xorq %%r15,%%r15\n" - /* u0 = (u0 << 4) | tx (%%rsi) */ - "shlq $4,%%rsi\n" - "movq %q3,%%rax\n" - "orq %%rax,%%rsi\n" - /* c += u0 * (R >> 4) */ - "movq $0x1000003d1,%%rax\n" - "mulq %%rsi\n" - "addq %%rax,%%r8\n" - "adcq %%rdx,%%r9\n" - /* r[0] = c & M */ - "movq %%r8,%%rax\n" - "movq $0xfffffffffffff,%%rdx\n" - "andq %%rdx,%%rax\n" - "movq %%rax,0(%%rdi)\n" - /* c >>= 52 */ - "shrdq $52,%%r9,%%r8\n" - "xorq %%r9,%%r9\n" - /* c += a1 * b0 */ - "movq 0(%%rbx),%%rax\n" - "mulq %%r11\n" - "addq %%rax,%%r8\n" - "adcq %%rdx,%%r9\n" - /* c += a0 * b1 */ - "movq 8(%%rbx),%%rax\n" - "mulq %%r10\n" - "addq %%rax,%%r8\n" - "adcq %%rdx,%%r9\n" - /* d += a4 * b2 */ - "movq 16(%%rbx),%%rax\n" - "mulq %%r14\n" - "addq %%rax,%%rcx\n" - "adcq %%rdx,%%r15\n" - /* d += a3 * b3 */ - "movq 24(%%rbx),%%rax\n" - "mulq %%r13\n" - "addq %%rax,%%rcx\n" - "adcq %%rdx,%%r15\n" - /* d += a2 * b4 */ - "movq 32(%%rbx),%%rax\n" - "mulq %%r12\n" - "addq %%rax,%%rcx\n" - "adcq %%rdx,%%r15\n" - /* c += (d & M) * R */ - "movq %%rcx,%%rax\n" - "movq $0xfffffffffffff,%%rdx\n" - "andq %%rdx,%%rax\n" - "movq $0x1000003d10,%%rdx\n" - "mulq %%rdx\n" - "addq %%rax,%%r8\n" - "adcq %%rdx,%%r9\n" - /* d >>= 52 */ - "shrdq $52,%%r15,%%rcx\n" - "xorq %%r15,%%r15\n" - /* r[1] = c & M */ - "movq %%r8,%%rax\n" - "movq $0xfffffffffffff,%%rdx\n" - "andq %%rdx,%%rax\n" - "movq %%rax,8(%%rdi)\n" - /* c >>= 52 */ - "shrdq $52,%%r9,%%r8\n" - "xorq %%r9,%%r9\n" - /* c += a2 * b0 */ - "movq 0(%%rbx),%%rax\n" - "mulq %%r12\n" - "addq %%rax,%%r8\n" - "adcq %%rdx,%%r9\n" - /* c += a1 * b1 */ - "movq 8(%%rbx),%%rax\n" - "mulq %%r11\n" - "addq %%rax,%%r8\n" - "adcq %%rdx,%%r9\n" - /* c += a0 * b2 (last use of %%r10 = a0) */ - "movq 16(%%rbx),%%rax\n" - "mulq %%r10\n" - "addq %%rax,%%r8\n" - "adcq %%rdx,%%r9\n" - /* fetch t3 (%%r10, overwrites a0), t4 (%%rsi) */ - "movq %q2,%%rsi\n" - "movq %q1,%%r10\n" - /* d += a4 * b3 */ - "movq 24(%%rbx),%%rax\n" - "mulq %%r14\n" - "addq %%rax,%%rcx\n" - "adcq %%rdx,%%r15\n" - /* d += a3 * b4 */ - "movq 32(%%rbx),%%rax\n" - "mulq %%r13\n" - "addq %%rax,%%rcx\n" - "adcq %%rdx,%%r15\n" - /* c += (d & M) * R */ - "movq %%rcx,%%rax\n" - "movq $0xfffffffffffff,%%rdx\n" - "andq %%rdx,%%rax\n" - "movq $0x1000003d10,%%rdx\n" - "mulq %%rdx\n" - "addq %%rax,%%r8\n" - "adcq %%rdx,%%r9\n" - /* d >>= 52 (%%rcx only) */ - "shrdq $52,%%r15,%%rcx\n" - /* r[2] = c & M */ - "movq %%r8,%%rax\n" - "movq $0xfffffffffffff,%%rdx\n" - "andq %%rdx,%%rax\n" - "movq %%rax,16(%%rdi)\n" - /* c >>= 52 */ - "shrdq $52,%%r9,%%r8\n" - "xorq %%r9,%%r9\n" - /* c += t3 */ - "addq %%r10,%%r8\n" - /* c += d * R */ - "movq %%rcx,%%rax\n" - "movq $0x1000003d10,%%rdx\n" - "mulq %%rdx\n" - "addq %%rax,%%r8\n" - "adcq %%rdx,%%r9\n" - /* r[3] = c & M */ - "movq %%r8,%%rax\n" - "movq $0xfffffffffffff,%%rdx\n" - "andq %%rdx,%%rax\n" - "movq %%rax,24(%%rdi)\n" - /* c >>= 52 (%%r8 only) */ - "shrdq $52,%%r9,%%r8\n" - /* c += t4 (%%r8 only) */ - "addq %%rsi,%%r8\n" - /* r[4] = c */ - "movq %%r8,32(%%rdi)\n" -: "+S"(a), "=m"(tmp1), "=m"(tmp2), "=m"(tmp3) -: "b"(b), "D"(r) -: "%rax", "%rcx", "%rdx", "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15", "cc", "memory" -); -} - -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_sqr_inner(uint64_t *r, const uint64_t *a) { -/** - * Registers: rdx:rax = multiplication accumulator - * r9:r8 = c - * rcx:rbx = d - * r10-r14 = a0-a4 - * r15 = M (0xfffffffffffff) - * rdi = r - * rsi = a / t? - */ - uint64_t tmp1, tmp2, tmp3; -__asm__ __volatile__( - "movq 0(%%rsi),%%r10\n" - "movq 8(%%rsi),%%r11\n" - "movq 16(%%rsi),%%r12\n" - "movq 24(%%rsi),%%r13\n" - "movq 32(%%rsi),%%r14\n" - "movq $0xfffffffffffff,%%r15\n" - - /* d = (a0*2) * a3 */ - "leaq (%%r10,%%r10,1),%%rax\n" - "mulq %%r13\n" - "movq %%rax,%%rbx\n" - "movq %%rdx,%%rcx\n" - /* d += (a1*2) * a2 */ - "leaq (%%r11,%%r11,1),%%rax\n" - "mulq %%r12\n" - "addq %%rax,%%rbx\n" - "adcq %%rdx,%%rcx\n" - /* c = a4 * a4 */ - "movq %%r14,%%rax\n" - "mulq %%r14\n" - "movq %%rax,%%r8\n" - "movq %%rdx,%%r9\n" - /* d += (c & M) * R */ - "andq %%r15,%%rax\n" - "movq $0x1000003d10,%%rdx\n" - "mulq %%rdx\n" - "addq %%rax,%%rbx\n" - "adcq %%rdx,%%rcx\n" - /* c >>= 52 (%%r8 only) */ - "shrdq $52,%%r9,%%r8\n" - /* t3 (tmp1) = d & M */ - "movq %%rbx,%%rsi\n" - "andq %%r15,%%rsi\n" - "movq %%rsi,%q1\n" - /* d >>= 52 */ - "shrdq $52,%%rcx,%%rbx\n" - "xorq %%rcx,%%rcx\n" - /* a4 *= 2 */ - "addq %%r14,%%r14\n" - /* d += a0 * a4 */ - "movq %%r10,%%rax\n" - "mulq %%r14\n" - "addq %%rax,%%rbx\n" - "adcq %%rdx,%%rcx\n" - /* d+= (a1*2) * a3 */ - "leaq (%%r11,%%r11,1),%%rax\n" - "mulq %%r13\n" - "addq %%rax,%%rbx\n" - "adcq %%rdx,%%rcx\n" - /* d += a2 * a2 */ - "movq %%r12,%%rax\n" - "mulq %%r12\n" - "addq %%rax,%%rbx\n" - "adcq %%rdx,%%rcx\n" - /* d += c * R */ - "movq %%r8,%%rax\n" - "movq $0x1000003d10,%%rdx\n" - "mulq %%rdx\n" - "addq %%rax,%%rbx\n" - "adcq %%rdx,%%rcx\n" - /* t4 = d & M (%%rsi) */ - "movq %%rbx,%%rsi\n" - "andq %%r15,%%rsi\n" - /* d >>= 52 */ - "shrdq $52,%%rcx,%%rbx\n" - "xorq %%rcx,%%rcx\n" - /* tx = t4 >> 48 (tmp3) */ - "movq %%rsi,%%rax\n" - "shrq $48,%%rax\n" - "movq %%rax,%q3\n" - /* t4 &= (M >> 4) (tmp2) */ - "movq $0xffffffffffff,%%rax\n" - "andq %%rax,%%rsi\n" - "movq %%rsi,%q2\n" - /* c = a0 * a0 */ - "movq %%r10,%%rax\n" - "mulq %%r10\n" - "movq %%rax,%%r8\n" - "movq %%rdx,%%r9\n" - /* d += a1 * a4 */ - "movq %%r11,%%rax\n" - "mulq %%r14\n" - "addq %%rax,%%rbx\n" - "adcq %%rdx,%%rcx\n" - /* d += (a2*2) * a3 */ - "leaq (%%r12,%%r12,1),%%rax\n" - "mulq %%r13\n" - "addq %%rax,%%rbx\n" - "adcq %%rdx,%%rcx\n" - /* u0 = d & M (%%rsi) */ - "movq %%rbx,%%rsi\n" - "andq %%r15,%%rsi\n" - /* d >>= 52 */ - "shrdq $52,%%rcx,%%rbx\n" - "xorq %%rcx,%%rcx\n" - /* u0 = (u0 << 4) | tx (%%rsi) */ - "shlq $4,%%rsi\n" - "movq %q3,%%rax\n" - "orq %%rax,%%rsi\n" - /* c += u0 * (R >> 4) */ - "movq $0x1000003d1,%%rax\n" - "mulq %%rsi\n" - "addq %%rax,%%r8\n" - "adcq %%rdx,%%r9\n" - /* r[0] = c & M */ - "movq %%r8,%%rax\n" - "andq %%r15,%%rax\n" - "movq %%rax,0(%%rdi)\n" - /* c >>= 52 */ - "shrdq $52,%%r9,%%r8\n" - "xorq %%r9,%%r9\n" - /* a0 *= 2 */ - "addq %%r10,%%r10\n" - /* c += a0 * a1 */ - "movq %%r10,%%rax\n" - "mulq %%r11\n" - "addq %%rax,%%r8\n" - "adcq %%rdx,%%r9\n" - /* d += a2 * a4 */ - "movq %%r12,%%rax\n" - "mulq %%r14\n" - "addq %%rax,%%rbx\n" - "adcq %%rdx,%%rcx\n" - /* d += a3 * a3 */ - "movq %%r13,%%rax\n" - "mulq %%r13\n" - "addq %%rax,%%rbx\n" - "adcq %%rdx,%%rcx\n" - /* c += (d & M) * R */ - "movq %%rbx,%%rax\n" - "andq %%r15,%%rax\n" - "movq $0x1000003d10,%%rdx\n" - "mulq %%rdx\n" - "addq %%rax,%%r8\n" - "adcq %%rdx,%%r9\n" - /* d >>= 52 */ - "shrdq $52,%%rcx,%%rbx\n" - "xorq %%rcx,%%rcx\n" - /* r[1] = c & M */ - "movq %%r8,%%rax\n" - "andq %%r15,%%rax\n" - "movq %%rax,8(%%rdi)\n" - /* c >>= 52 */ - "shrdq $52,%%r9,%%r8\n" - "xorq %%r9,%%r9\n" - /* c += a0 * a2 (last use of %%r10) */ - "movq %%r10,%%rax\n" - "mulq %%r12\n" - "addq %%rax,%%r8\n" - "adcq %%rdx,%%r9\n" - /* fetch t3 (%%r10, overwrites a0),t4 (%%rsi) */ - "movq %q2,%%rsi\n" - "movq %q1,%%r10\n" - /* c += a1 * a1 */ - "movq %%r11,%%rax\n" - "mulq %%r11\n" - "addq %%rax,%%r8\n" - "adcq %%rdx,%%r9\n" - /* d += a3 * a4 */ - "movq %%r13,%%rax\n" - "mulq %%r14\n" - "addq %%rax,%%rbx\n" - "adcq %%rdx,%%rcx\n" - /* c += (d & M) * R */ - "movq %%rbx,%%rax\n" - "andq %%r15,%%rax\n" - "movq $0x1000003d10,%%rdx\n" - "mulq %%rdx\n" - "addq %%rax,%%r8\n" - "adcq %%rdx,%%r9\n" - /* d >>= 52 (%%rbx only) */ - "shrdq $52,%%rcx,%%rbx\n" - /* r[2] = c & M */ - "movq %%r8,%%rax\n" - "andq %%r15,%%rax\n" - "movq %%rax,16(%%rdi)\n" - /* c >>= 52 */ - "shrdq $52,%%r9,%%r8\n" - "xorq %%r9,%%r9\n" - /* c += t3 */ - "addq %%r10,%%r8\n" - /* c += d * R */ - "movq %%rbx,%%rax\n" - "movq $0x1000003d10,%%rdx\n" - "mulq %%rdx\n" - "addq %%rax,%%r8\n" - "adcq %%rdx,%%r9\n" - /* r[3] = c & M */ - "movq %%r8,%%rax\n" - "andq %%r15,%%rax\n" - "movq %%rax,24(%%rdi)\n" - /* c >>= 52 (%%r8 only) */ - "shrdq $52,%%r9,%%r8\n" - /* c += t4 (%%r8 only) */ - "addq %%rsi,%%r8\n" - /* r[4] = c */ - "movq %%r8,32(%%rdi)\n" -: "+S"(a), "=m"(tmp1), "=m"(tmp2), "=m"(tmp3) -: "D"(r) -: "%rax", "%rbx", "%rcx", "%rdx", "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15", "cc", "memory" -); -} - -#endif /* SECP256K1_FIELD_INNER5X52_IMPL_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/field_5x52_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/field_5x52_impl.h index 9d570118..6fca4b7d 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/field_5x52_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/field_5x52_impl.h @@ -7,73 +7,40 @@ #ifndef SECP256K1_FIELD_REPR_IMPL_H #define SECP256K1_FIELD_REPR_IMPL_H -#if defined HAVE_CONFIG_H -#include "libsecp256k1-config.h" -#endif - +#include "checkmem.h" #include "util.h" #include "field.h" #include "modinv64_impl.h" -#if defined(USE_ASM_X86_64) -#include "field_5x52_asm_impl.h" -#else #include "field_5x52_int128_impl.h" -#endif - -/** Implements arithmetic modulo FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFC2F, - * represented as 5 uint64_t's in base 2^52, least significant first. Note that the limbs are allowed to - * contain >52 bits each. - * - * Each field element has a 'magnitude' associated with it. Internally, a magnitude M means: - * - 2*M*(2^48-1) is the max (inclusive) of the most significant limb - * - 2*M*(2^52-1) is the max (inclusive) of the remaining limbs - * - * Operations have different rules for propagating magnitude to their outputs. If an operation takes a - * magnitude M as a parameter, that means the magnitude of input field elements can be at most M (inclusive). - * - * Each field element also has a 'normalized' flag. A field element is normalized if its magnitude is either - * 0 or 1, and its value is already reduced modulo the order of the field. - */ #ifdef VERIFY -static void rustsecp256k1zkp_v0_8_0_fe_verify(const rustsecp256k1zkp_v0_8_0_fe *a) { +static void rustsecp256k1zkp_v0_10_0_fe_impl_verify(const rustsecp256k1zkp_v0_10_0_fe *a) { const uint64_t *d = a->n; - int m = a->normalized ? 1 : 2 * a->magnitude, r = 1; + int m = a->normalized ? 1 : 2 * a->magnitude; /* secp256k1 'p' value defined in "Standards for Efficient Cryptography" (SEC2) 2.7.1. */ - r &= (d[0] <= 0xFFFFFFFFFFFFFULL * m); - r &= (d[1] <= 0xFFFFFFFFFFFFFULL * m); - r &= (d[2] <= 0xFFFFFFFFFFFFFULL * m); - r &= (d[3] <= 0xFFFFFFFFFFFFFULL * m); - r &= (d[4] <= 0x0FFFFFFFFFFFFULL * m); - r &= (a->magnitude >= 0); - r &= (a->magnitude <= 2048); + VERIFY_CHECK(d[0] <= 0xFFFFFFFFFFFFFULL * m); + VERIFY_CHECK(d[1] <= 0xFFFFFFFFFFFFFULL * m); + VERIFY_CHECK(d[2] <= 0xFFFFFFFFFFFFFULL * m); + VERIFY_CHECK(d[3] <= 0xFFFFFFFFFFFFFULL * m); + VERIFY_CHECK(d[4] <= 0x0FFFFFFFFFFFFULL * m); if (a->normalized) { - r &= (a->magnitude <= 1); - if (r && (d[4] == 0x0FFFFFFFFFFFFULL) && ((d[3] & d[2] & d[1]) == 0xFFFFFFFFFFFFFULL)) { - r &= (d[0] < 0xFFFFEFFFFFC2FULL); + if ((d[4] == 0x0FFFFFFFFFFFFULL) && ((d[3] & d[2] & d[1]) == 0xFFFFFFFFFFFFFULL)) { + VERIFY_CHECK(d[0] < 0xFFFFEFFFFFC2FULL); } } - VERIFY_CHECK(r == 1); } #endif -static void rustsecp256k1zkp_v0_8_0_fe_get_bounds(rustsecp256k1zkp_v0_8_0_fe *r, int m) { - VERIFY_CHECK(m >= 0); - VERIFY_CHECK(m <= 2048); +static void rustsecp256k1zkp_v0_10_0_fe_impl_get_bounds(rustsecp256k1zkp_v0_10_0_fe *r, int m) { r->n[0] = 0xFFFFFFFFFFFFFULL * 2 * m; r->n[1] = 0xFFFFFFFFFFFFFULL * 2 * m; r->n[2] = 0xFFFFFFFFFFFFFULL * 2 * m; r->n[3] = 0xFFFFFFFFFFFFFULL * 2 * m; r->n[4] = 0x0FFFFFFFFFFFFULL * 2 * m; -#ifdef VERIFY - r->magnitude = m; - r->normalized = (m == 0); - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -static void rustsecp256k1zkp_v0_8_0_fe_normalize(rustsecp256k1zkp_v0_8_0_fe *r) { +static void rustsecp256k1zkp_v0_10_0_fe_impl_normalize(rustsecp256k1zkp_v0_10_0_fe *r) { uint64_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4]; /* Reduce t4 at the start so there will be at most a single carry from the first pass */ @@ -108,15 +75,9 @@ static void rustsecp256k1zkp_v0_8_0_fe_normalize(rustsecp256k1zkp_v0_8_0_fe *r) t4 &= 0x0FFFFFFFFFFFFULL; r->n[0] = t0; r->n[1] = t1; r->n[2] = t2; r->n[3] = t3; r->n[4] = t4; - -#ifdef VERIFY - r->magnitude = 1; - r->normalized = 1; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -static void rustsecp256k1zkp_v0_8_0_fe_normalize_weak(rustsecp256k1zkp_v0_8_0_fe *r) { +static void rustsecp256k1zkp_v0_10_0_fe_impl_normalize_weak(rustsecp256k1zkp_v0_10_0_fe *r) { uint64_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4]; /* Reduce t4 at the start so there will be at most a single carry from the first pass */ @@ -133,14 +94,9 @@ static void rustsecp256k1zkp_v0_8_0_fe_normalize_weak(rustsecp256k1zkp_v0_8_0_fe VERIFY_CHECK(t4 >> 49 == 0); r->n[0] = t0; r->n[1] = t1; r->n[2] = t2; r->n[3] = t3; r->n[4] = t4; - -#ifdef VERIFY - r->magnitude = 1; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -static void rustsecp256k1zkp_v0_8_0_fe_normalize_var(rustsecp256k1zkp_v0_8_0_fe *r) { +static void rustsecp256k1zkp_v0_10_0_fe_impl_normalize_var(rustsecp256k1zkp_v0_10_0_fe *r) { uint64_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4]; /* Reduce t4 at the start so there will be at most a single carry from the first pass */ @@ -176,15 +132,9 @@ static void rustsecp256k1zkp_v0_8_0_fe_normalize_var(rustsecp256k1zkp_v0_8_0_fe } r->n[0] = t0; r->n[1] = t1; r->n[2] = t2; r->n[3] = t3; r->n[4] = t4; - -#ifdef VERIFY - r->magnitude = 1; - r->normalized = 1; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -static int rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero(const rustsecp256k1zkp_v0_8_0_fe *r) { +static int rustsecp256k1zkp_v0_10_0_fe_impl_normalizes_to_zero(const rustsecp256k1zkp_v0_10_0_fe *r) { uint64_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4]; /* z0 tracks a possible raw value of 0, z1 tracks a possible raw value of P */ @@ -207,7 +157,7 @@ static int rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero(const rustsecp256k1zkp_ return (z0 == 0) | (z1 == 0xFFFFFFFFFFFFFULL); } -static int rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero_var(const rustsecp256k1zkp_v0_8_0_fe *r) { +static int rustsecp256k1zkp_v0_10_0_fe_impl_normalizes_to_zero_var(const rustsecp256k1zkp_v0_10_0_fe *r) { uint64_t t0, t1, t2, t3, t4; uint64_t z0, z1; uint64_t x; @@ -248,53 +198,29 @@ static int rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero_var(const rustsecp256k1 return (z0 == 0) | (z1 == 0xFFFFFFFFFFFFFULL); } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_set_int(rustsecp256k1zkp_v0_8_0_fe *r, int a) { - VERIFY_CHECK(0 <= a && a <= 0x7FFF); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_impl_set_int(rustsecp256k1zkp_v0_10_0_fe *r, int a) { r->n[0] = a; r->n[1] = r->n[2] = r->n[3] = r->n[4] = 0; -#ifdef VERIFY - r->magnitude = (a != 0); - r->normalized = 1; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_fe_is_zero(const rustsecp256k1zkp_v0_8_0_fe *a) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_fe_impl_is_zero(const rustsecp256k1zkp_v0_10_0_fe *a) { const uint64_t *t = a->n; -#ifdef VERIFY - VERIFY_CHECK(a->normalized); - rustsecp256k1zkp_v0_8_0_fe_verify(a); -#endif return (t[0] | t[1] | t[2] | t[3] | t[4]) == 0; } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_fe_is_odd(const rustsecp256k1zkp_v0_8_0_fe *a) { -#ifdef VERIFY - VERIFY_CHECK(a->normalized); - rustsecp256k1zkp_v0_8_0_fe_verify(a); -#endif +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_fe_impl_is_odd(const rustsecp256k1zkp_v0_10_0_fe *a) { return a->n[0] & 1; } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_clear(rustsecp256k1zkp_v0_8_0_fe *a) { +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_impl_clear(rustsecp256k1zkp_v0_10_0_fe *a) { int i; -#ifdef VERIFY - a->magnitude = 0; - a->normalized = 1; -#endif for (i=0; i<5; i++) { a->n[i] = 0; } } -static int rustsecp256k1zkp_v0_8_0_fe_cmp_var(const rustsecp256k1zkp_v0_8_0_fe *a, const rustsecp256k1zkp_v0_8_0_fe *b) { +static int rustsecp256k1zkp_v0_10_0_fe_impl_cmp_var(const rustsecp256k1zkp_v0_10_0_fe *a, const rustsecp256k1zkp_v0_10_0_fe *b) { int i; -#ifdef VERIFY - VERIFY_CHECK(a->normalized); - VERIFY_CHECK(b->normalized); - rustsecp256k1zkp_v0_8_0_fe_verify(a); - rustsecp256k1zkp_v0_8_0_fe_verify(b); -#endif for (i = 4; i >= 0; i--) { if (a->n[i] > b->n[i]) { return 1; @@ -306,8 +232,7 @@ static int rustsecp256k1zkp_v0_8_0_fe_cmp_var(const rustsecp256k1zkp_v0_8_0_fe * return 0; } -static int rustsecp256k1zkp_v0_8_0_fe_set_b32(rustsecp256k1zkp_v0_8_0_fe *r, const unsigned char *a) { - int ret; +static void rustsecp256k1zkp_v0_10_0_fe_impl_set_b32_mod(rustsecp256k1zkp_v0_10_0_fe *r, const unsigned char *a) { r->n[0] = (uint64_t)a[31] | ((uint64_t)a[30] << 8) | ((uint64_t)a[29] << 16) @@ -342,25 +267,15 @@ static int rustsecp256k1zkp_v0_8_0_fe_set_b32(rustsecp256k1zkp_v0_8_0_fe *r, con | ((uint64_t)a[2] << 24) | ((uint64_t)a[1] << 32) | ((uint64_t)a[0] << 40); - ret = !((r->n[4] == 0x0FFFFFFFFFFFFULL) & ((r->n[3] & r->n[2] & r->n[1]) == 0xFFFFFFFFFFFFFULL) & (r->n[0] >= 0xFFFFEFFFFFC2FULL)); -#ifdef VERIFY - r->magnitude = 1; - if (ret) { - r->normalized = 1; - rustsecp256k1zkp_v0_8_0_fe_verify(r); - } else { - r->normalized = 0; - } -#endif - return ret; +} + +static int rustsecp256k1zkp_v0_10_0_fe_impl_set_b32_limit(rustsecp256k1zkp_v0_10_0_fe *r, const unsigned char *a) { + rustsecp256k1zkp_v0_10_0_fe_impl_set_b32_mod(r, a); + return !((r->n[4] == 0x0FFFFFFFFFFFFULL) & ((r->n[3] & r->n[2] & r->n[1]) == 0xFFFFFFFFFFFFFULL) & (r->n[0] >= 0xFFFFEFFFFFC2FULL)); } /** Convert a field element to a 32-byte big endian value. Requires the input to be normalized */ -static void rustsecp256k1zkp_v0_8_0_fe_get_b32(unsigned char *r, const rustsecp256k1zkp_v0_8_0_fe *a) { -#ifdef VERIFY - VERIFY_CHECK(a->normalized); - rustsecp256k1zkp_v0_8_0_fe_verify(a); -#endif +static void rustsecp256k1zkp_v0_10_0_fe_impl_get_b32(unsigned char *r, const rustsecp256k1zkp_v0_10_0_fe *a) { r[0] = (a->n[4] >> 40) & 0xFF; r[1] = (a->n[4] >> 32) & 0xFF; r[2] = (a->n[4] >> 24) & 0xFF; @@ -395,113 +310,67 @@ static void rustsecp256k1zkp_v0_8_0_fe_get_b32(unsigned char *r, const rustsecp2 r[31] = a->n[0] & 0xFF; } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_negate(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *a, int m) { -#ifdef VERIFY - VERIFY_CHECK(a->magnitude <= m); - rustsecp256k1zkp_v0_8_0_fe_verify(a); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_impl_negate_unchecked(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a, int m) { + /* For all legal values of m (0..31), the following properties hold: */ VERIFY_CHECK(0xFFFFEFFFFFC2FULL * 2 * (m + 1) >= 0xFFFFFFFFFFFFFULL * 2 * m); VERIFY_CHECK(0xFFFFFFFFFFFFFULL * 2 * (m + 1) >= 0xFFFFFFFFFFFFFULL * 2 * m); VERIFY_CHECK(0x0FFFFFFFFFFFFULL * 2 * (m + 1) >= 0x0FFFFFFFFFFFFULL * 2 * m); -#endif + + /* Due to the properties above, the left hand in the subtractions below is never less than + * the right hand. */ r->n[0] = 0xFFFFEFFFFFC2FULL * 2 * (m + 1) - a->n[0]; r->n[1] = 0xFFFFFFFFFFFFFULL * 2 * (m + 1) - a->n[1]; r->n[2] = 0xFFFFFFFFFFFFFULL * 2 * (m + 1) - a->n[2]; r->n[3] = 0xFFFFFFFFFFFFFULL * 2 * (m + 1) - a->n[3]; r->n[4] = 0x0FFFFFFFFFFFFULL * 2 * (m + 1) - a->n[4]; -#ifdef VERIFY - r->magnitude = m + 1; - r->normalized = 0; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_mul_int(rustsecp256k1zkp_v0_8_0_fe *r, int a) { +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_impl_mul_int_unchecked(rustsecp256k1zkp_v0_10_0_fe *r, int a) { r->n[0] *= a; r->n[1] *= a; r->n[2] *= a; r->n[3] *= a; r->n[4] *= a; -#ifdef VERIFY - r->magnitude *= a; - r->normalized = 0; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_add(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *a) { -#ifdef VERIFY - rustsecp256k1zkp_v0_8_0_fe_verify(a); -#endif +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_impl_add_int(rustsecp256k1zkp_v0_10_0_fe *r, int a) { + r->n[0] += a; +} + +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_impl_add(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a) { r->n[0] += a->n[0]; r->n[1] += a->n[1]; r->n[2] += a->n[2]; r->n[3] += a->n[3]; r->n[4] += a->n[4]; -#ifdef VERIFY - r->magnitude += a->magnitude; - r->normalized = 0; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -static void rustsecp256k1zkp_v0_8_0_fe_mul(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *a, const rustsecp256k1zkp_v0_8_0_fe * SECP256K1_RESTRICT b) { -#ifdef VERIFY - VERIFY_CHECK(a->magnitude <= 8); - VERIFY_CHECK(b->magnitude <= 8); - rustsecp256k1zkp_v0_8_0_fe_verify(a); - rustsecp256k1zkp_v0_8_0_fe_verify(b); - VERIFY_CHECK(r != b); - VERIFY_CHECK(a != b); -#endif - rustsecp256k1zkp_v0_8_0_fe_mul_inner(r->n, a->n, b->n); -#ifdef VERIFY - r->magnitude = 1; - r->normalized = 0; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_impl_mul(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a, const rustsecp256k1zkp_v0_10_0_fe * SECP256K1_RESTRICT b) { + rustsecp256k1zkp_v0_10_0_fe_mul_inner(r->n, a->n, b->n); } -static void rustsecp256k1zkp_v0_8_0_fe_sqr(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *a) { -#ifdef VERIFY - VERIFY_CHECK(a->magnitude <= 8); - rustsecp256k1zkp_v0_8_0_fe_verify(a); -#endif - rustsecp256k1zkp_v0_8_0_fe_sqr_inner(r->n, a->n); -#ifdef VERIFY - r->magnitude = 1; - r->normalized = 0; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_impl_sqr(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a) { + rustsecp256k1zkp_v0_10_0_fe_sqr_inner(r->n, a->n); } -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_fe_cmov(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *a, int flag) { +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_impl_cmov(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a, int flag) { uint64_t mask0, mask1; - VG_CHECK_VERIFY(r->n, sizeof(r->n)); - mask0 = flag + ~((uint64_t)0); + volatile int vflag = flag; + SECP256K1_CHECKMEM_CHECK_VERIFY(r->n, sizeof(r->n)); + mask0 = vflag + ~((uint64_t)0); mask1 = ~mask0; r->n[0] = (r->n[0] & mask0) | (a->n[0] & mask1); r->n[1] = (r->n[1] & mask0) | (a->n[1] & mask1); r->n[2] = (r->n[2] & mask0) | (a->n[2] & mask1); r->n[3] = (r->n[3] & mask0) | (a->n[3] & mask1); r->n[4] = (r->n[4] & mask0) | (a->n[4] & mask1); -#ifdef VERIFY - if (flag) { - r->magnitude = a->magnitude; - r->normalized = a->normalized; - } -#endif } -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_fe_half(rustsecp256k1zkp_v0_8_0_fe *r) { +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_fe_impl_half(rustsecp256k1zkp_v0_10_0_fe *r) { uint64_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4]; uint64_t one = (uint64_t)1; uint64_t mask = -(t0 & one) >> 12; -#ifdef VERIFY - rustsecp256k1zkp_v0_8_0_fe_verify(r); - VERIFY_CHECK(r->magnitude < 32); -#endif - /* Bounds analysis (over the rationals). * * Let m = r->magnitude @@ -538,10 +407,8 @@ static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_fe_half(rustsecp256k1zkp_v0 * * Current bounds: t0..t3 <= C * (m/2 + 1/2) * t4 <= D * (m/2 + 1/4) - */ - -#ifdef VERIFY - /* Therefore the output magnitude (M) has to be set such that: + * + * Therefore the output magnitude (M) has to be set such that: * t0..t3: C * M >= C * (m/2 + 1/2) * t4: D * M >= D * (m/2 + 1/4) * @@ -551,16 +418,13 @@ static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_fe_half(rustsecp256k1zkp_v0 * and since we want the smallest such integer value for M: * M == floor(m/2) + 1 */ - r->magnitude = (r->magnitude >> 1) + 1; - r->normalized = 0; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_fe_storage_cmov(rustsecp256k1zkp_v0_8_0_fe_storage *r, const rustsecp256k1zkp_v0_8_0_fe_storage *a, int flag) { +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_fe_storage_cmov(rustsecp256k1zkp_v0_10_0_fe_storage *r, const rustsecp256k1zkp_v0_10_0_fe_storage *a, int flag) { uint64_t mask0, mask1; - VG_CHECK_VERIFY(r->n, sizeof(r->n)); - mask0 = flag + ~((uint64_t)0); + volatile int vflag = flag; + SECP256K1_CHECKMEM_CHECK_VERIFY(r->n, sizeof(r->n)); + mask0 = vflag + ~((uint64_t)0); mask1 = ~mask0; r->n[0] = (r->n[0] & mask0) | (a->n[0] & mask1); r->n[1] = (r->n[1] & mask0) | (a->n[1] & mask1); @@ -568,34 +432,26 @@ static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_fe_storage_cmov(rustsecp256 r->n[3] = (r->n[3] & mask0) | (a->n[3] & mask1); } -static void rustsecp256k1zkp_v0_8_0_fe_to_storage(rustsecp256k1zkp_v0_8_0_fe_storage *r, const rustsecp256k1zkp_v0_8_0_fe *a) { -#ifdef VERIFY - VERIFY_CHECK(a->normalized); -#endif +static void rustsecp256k1zkp_v0_10_0_fe_impl_to_storage(rustsecp256k1zkp_v0_10_0_fe_storage *r, const rustsecp256k1zkp_v0_10_0_fe *a) { r->n[0] = a->n[0] | a->n[1] << 52; r->n[1] = a->n[1] >> 12 | a->n[2] << 40; r->n[2] = a->n[2] >> 24 | a->n[3] << 28; r->n[3] = a->n[3] >> 36 | a->n[4] << 16; } -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_fe_from_storage(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe_storage *a) { +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_fe_impl_from_storage(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe_storage *a) { r->n[0] = a->n[0] & 0xFFFFFFFFFFFFFULL; r->n[1] = a->n[0] >> 52 | ((a->n[1] << 12) & 0xFFFFFFFFFFFFFULL); r->n[2] = a->n[1] >> 40 | ((a->n[2] << 24) & 0xFFFFFFFFFFFFFULL); r->n[3] = a->n[2] >> 28 | ((a->n[3] << 36) & 0xFFFFFFFFFFFFFULL); r->n[4] = a->n[3] >> 16; -#ifdef VERIFY - r->magnitude = 1; - r->normalized = 1; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -static void rustsecp256k1zkp_v0_8_0_fe_from_signed62(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_modinv64_signed62 *a) { +static void rustsecp256k1zkp_v0_10_0_fe_from_signed62(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_modinv64_signed62 *a) { const uint64_t M52 = UINT64_MAX >> 12; const uint64_t a0 = a->v[0], a1 = a->v[1], a2 = a->v[2], a3 = a->v[3], a4 = a->v[4]; - /* The output from rustsecp256k1zkp_v0_8_0_modinv64{_var} should be normalized to range [0,modulus), and + /* The output from rustsecp256k1zkp_v0_10_0_modinv64{_var} should be normalized to range [0,modulus), and * have limbs in [0,2^62). The modulus is < 2^256, so the top limb must be below 2^(256-62*4). */ VERIFY_CHECK(a0 >> 62 == 0); @@ -609,22 +465,12 @@ static void rustsecp256k1zkp_v0_8_0_fe_from_signed62(rustsecp256k1zkp_v0_8_0_fe r->n[2] = (a1 >> 42 | a2 << 20) & M52; r->n[3] = (a2 >> 32 | a3 << 30) & M52; r->n[4] = (a3 >> 22 | a4 << 40); - -#ifdef VERIFY - r->magnitude = 1; - r->normalized = 1; - rustsecp256k1zkp_v0_8_0_fe_verify(r); -#endif } -static void rustsecp256k1zkp_v0_8_0_fe_to_signed62(rustsecp256k1zkp_v0_8_0_modinv64_signed62 *r, const rustsecp256k1zkp_v0_8_0_fe *a) { +static void rustsecp256k1zkp_v0_10_0_fe_to_signed62(rustsecp256k1zkp_v0_10_0_modinv64_signed62 *r, const rustsecp256k1zkp_v0_10_0_fe *a) { const uint64_t M62 = UINT64_MAX >> 2; const uint64_t a0 = a->n[0], a1 = a->n[1], a2 = a->n[2], a3 = a->n[3], a4 = a->n[4]; -#ifdef VERIFY - VERIFY_CHECK(a->normalized); -#endif - r->v[0] = (a0 | a1 << 52) & M62; r->v[1] = (a1 >> 10 | a2 << 42) & M62; r->v[2] = (a2 >> 20 | a3 << 32) & M62; @@ -632,39 +478,52 @@ static void rustsecp256k1zkp_v0_8_0_fe_to_signed62(rustsecp256k1zkp_v0_8_0_modin r->v[4] = a4 >> 40; } -static const rustsecp256k1zkp_v0_8_0_modinv64_modinfo rustsecp256k1zkp_v0_8_0_const_modinfo_fe = { +static const rustsecp256k1zkp_v0_10_0_modinv64_modinfo rustsecp256k1zkp_v0_10_0_const_modinfo_fe = { {{-0x1000003D1LL, 0, 0, 0, 256}}, 0x27C7F6E22DDACACFLL }; -static void rustsecp256k1zkp_v0_8_0_fe_inv(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *x) { - rustsecp256k1zkp_v0_8_0_fe tmp; - rustsecp256k1zkp_v0_8_0_modinv64_signed62 s; +static void rustsecp256k1zkp_v0_10_0_fe_impl_inv(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *x) { + rustsecp256k1zkp_v0_10_0_fe tmp = *x; + rustsecp256k1zkp_v0_10_0_modinv64_signed62 s; - tmp = *x; - rustsecp256k1zkp_v0_8_0_fe_normalize(&tmp); - rustsecp256k1zkp_v0_8_0_fe_to_signed62(&s, &tmp); - rustsecp256k1zkp_v0_8_0_modinv64(&s, &rustsecp256k1zkp_v0_8_0_const_modinfo_fe); - rustsecp256k1zkp_v0_8_0_fe_from_signed62(r, &s); + rustsecp256k1zkp_v0_10_0_fe_normalize(&tmp); + rustsecp256k1zkp_v0_10_0_fe_to_signed62(&s, &tmp); + rustsecp256k1zkp_v0_10_0_modinv64(&s, &rustsecp256k1zkp_v0_10_0_const_modinfo_fe); + rustsecp256k1zkp_v0_10_0_fe_from_signed62(r, &s); +} -#ifdef VERIFY - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero(r) == rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero(&tmp)); -#endif +static void rustsecp256k1zkp_v0_10_0_fe_impl_inv_var(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *x) { + rustsecp256k1zkp_v0_10_0_fe tmp = *x; + rustsecp256k1zkp_v0_10_0_modinv64_signed62 s; + + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&tmp); + rustsecp256k1zkp_v0_10_0_fe_to_signed62(&s, &tmp); + rustsecp256k1zkp_v0_10_0_modinv64_var(&s, &rustsecp256k1zkp_v0_10_0_const_modinfo_fe); + rustsecp256k1zkp_v0_10_0_fe_from_signed62(r, &s); } -static void rustsecp256k1zkp_v0_8_0_fe_inv_var(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *x) { - rustsecp256k1zkp_v0_8_0_fe tmp; - rustsecp256k1zkp_v0_8_0_modinv64_signed62 s; +static int rustsecp256k1zkp_v0_10_0_fe_impl_is_square_var(const rustsecp256k1zkp_v0_10_0_fe *x) { + rustsecp256k1zkp_v0_10_0_fe tmp; + rustsecp256k1zkp_v0_10_0_modinv64_signed62 s; + int jac, ret; tmp = *x; - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&tmp); - rustsecp256k1zkp_v0_8_0_fe_to_signed62(&s, &tmp); - rustsecp256k1zkp_v0_8_0_modinv64_var(&s, &rustsecp256k1zkp_v0_8_0_const_modinfo_fe); - rustsecp256k1zkp_v0_8_0_fe_from_signed62(r, &s); - -#ifdef VERIFY - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero(r) == rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero(&tmp)); -#endif + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&tmp); + /* rustsecp256k1zkp_v0_10_0_jacobi64_maybe_var cannot deal with input 0. */ + if (rustsecp256k1zkp_v0_10_0_fe_is_zero(&tmp)) return 1; + rustsecp256k1zkp_v0_10_0_fe_to_signed62(&s, &tmp); + jac = rustsecp256k1zkp_v0_10_0_jacobi64_maybe_var(&s, &rustsecp256k1zkp_v0_10_0_const_modinfo_fe); + if (jac == 0) { + /* rustsecp256k1zkp_v0_10_0_jacobi64_maybe_var failed to compute the Jacobi symbol. Fall back + * to computing a square root. This should be extremely rare with random + * input (except in VERIFY mode, where a lower iteration count is used). */ + rustsecp256k1zkp_v0_10_0_fe dummy; + ret = rustsecp256k1zkp_v0_10_0_fe_sqrt(&dummy, &tmp); + } else { + ret = jac >= 0; + } + return ret; } #endif /* SECP256K1_FIELD_REPR_IMPL_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/field_5x52_int128_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/field_5x52_int128_impl.h index 8f8588ac..eb600862 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/field_5x52_int128_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/field_5x52_int128_impl.h @@ -9,14 +9,14 @@ #include -#ifdef VERIFY +#include "int128.h" +#include "util.h" + #define VERIFY_BITS(x, n) VERIFY_CHECK(((x) >> (n)) == 0) -#else -#define VERIFY_BITS(x, n) do { } while(0) -#endif +#define VERIFY_BITS_128(x, n) VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_u128_check_bits((x), (n))) -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_mul_inner(uint64_t *r, const uint64_t *a, const uint64_t * SECP256K1_RESTRICT b) { - uint128_t c, d; +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_mul_inner(uint64_t *r, const uint64_t *a, const uint64_t * SECP256K1_RESTRICT b) { + rustsecp256k1zkp_v0_10_0_uint128 c, d; uint64_t t3, t4, tx, u0; uint64_t a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4]; const uint64_t M = 0xFFFFFFFFFFFFFULL, R = 0x1000003D10ULL; @@ -40,123 +40,121 @@ SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_mul_inner(uint64_t *r, c * Note that [x 0 0 0 0 0] = [x*R]. */ - d = (uint128_t)a0 * b[3] - + (uint128_t)a1 * b[2] - + (uint128_t)a2 * b[1] - + (uint128_t)a3 * b[0]; - VERIFY_BITS(d, 114); + rustsecp256k1zkp_v0_10_0_u128_mul(&d, a0, b[3]); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a1, b[2]); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a2, b[1]); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a3, b[0]); + VERIFY_BITS_128(&d, 114); /* [d 0 0 0] = [p3 0 0 0] */ - c = (uint128_t)a4 * b[4]; - VERIFY_BITS(c, 112); + rustsecp256k1zkp_v0_10_0_u128_mul(&c, a4, b[4]); + VERIFY_BITS_128(&c, 112); /* [c 0 0 0 0 d 0 0 0] = [p8 0 0 0 0 p3 0 0 0] */ - d += (uint128_t)R * (uint64_t)c; c >>= 64; - VERIFY_BITS(d, 115); - VERIFY_BITS(c, 48); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, R, rustsecp256k1zkp_v0_10_0_u128_to_u64(&c)); rustsecp256k1zkp_v0_10_0_u128_rshift(&c, 64); + VERIFY_BITS_128(&d, 115); + VERIFY_BITS_128(&c, 48); /* [(c<<12) 0 0 0 0 0 d 0 0 0] = [p8 0 0 0 0 p3 0 0 0] */ - t3 = d & M; d >>= 52; + t3 = rustsecp256k1zkp_v0_10_0_u128_to_u64(&d) & M; rustsecp256k1zkp_v0_10_0_u128_rshift(&d, 52); VERIFY_BITS(t3, 52); - VERIFY_BITS(d, 63); + VERIFY_BITS_128(&d, 63); /* [(c<<12) 0 0 0 0 d t3 0 0 0] = [p8 0 0 0 0 p3 0 0 0] */ - d += (uint128_t)a0 * b[4] - + (uint128_t)a1 * b[3] - + (uint128_t)a2 * b[2] - + (uint128_t)a3 * b[1] - + (uint128_t)a4 * b[0]; - VERIFY_BITS(d, 115); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a0, b[4]); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a1, b[3]); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a2, b[2]); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a3, b[1]); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a4, b[0]); + VERIFY_BITS_128(&d, 115); /* [(c<<12) 0 0 0 0 d t3 0 0 0] = [p8 0 0 0 p4 p3 0 0 0] */ - d += (uint128_t)(R << 12) * (uint64_t)c; - VERIFY_BITS(d, 116); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, R << 12, rustsecp256k1zkp_v0_10_0_u128_to_u64(&c)); + VERIFY_BITS_128(&d, 116); /* [d t3 0 0 0] = [p8 0 0 0 p4 p3 0 0 0] */ - t4 = d & M; d >>= 52; + t4 = rustsecp256k1zkp_v0_10_0_u128_to_u64(&d) & M; rustsecp256k1zkp_v0_10_0_u128_rshift(&d, 52); VERIFY_BITS(t4, 52); - VERIFY_BITS(d, 64); + VERIFY_BITS_128(&d, 64); /* [d t4 t3 0 0 0] = [p8 0 0 0 p4 p3 0 0 0] */ tx = (t4 >> 48); t4 &= (M >> 4); VERIFY_BITS(tx, 4); VERIFY_BITS(t4, 48); /* [d t4+(tx<<48) t3 0 0 0] = [p8 0 0 0 p4 p3 0 0 0] */ - c = (uint128_t)a0 * b[0]; - VERIFY_BITS(c, 112); + rustsecp256k1zkp_v0_10_0_u128_mul(&c, a0, b[0]); + VERIFY_BITS_128(&c, 112); /* [d t4+(tx<<48) t3 0 0 c] = [p8 0 0 0 p4 p3 0 0 p0] */ - d += (uint128_t)a1 * b[4] - + (uint128_t)a2 * b[3] - + (uint128_t)a3 * b[2] - + (uint128_t)a4 * b[1]; - VERIFY_BITS(d, 115); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a1, b[4]); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a2, b[3]); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a3, b[2]); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a4, b[1]); + VERIFY_BITS_128(&d, 114); /* [d t4+(tx<<48) t3 0 0 c] = [p8 0 0 p5 p4 p3 0 0 p0] */ - u0 = d & M; d >>= 52; + u0 = rustsecp256k1zkp_v0_10_0_u128_to_u64(&d) & M; rustsecp256k1zkp_v0_10_0_u128_rshift(&d, 52); VERIFY_BITS(u0, 52); - VERIFY_BITS(d, 63); + VERIFY_BITS_128(&d, 62); /* [d u0 t4+(tx<<48) t3 0 0 c] = [p8 0 0 p5 p4 p3 0 0 p0] */ /* [d 0 t4+(tx<<48)+(u0<<52) t3 0 0 c] = [p8 0 0 p5 p4 p3 0 0 p0] */ u0 = (u0 << 4) | tx; VERIFY_BITS(u0, 56); /* [d 0 t4+(u0<<48) t3 0 0 c] = [p8 0 0 p5 p4 p3 0 0 p0] */ - c += (uint128_t)u0 * (R >> 4); - VERIFY_BITS(c, 115); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&c, u0, R >> 4); + VERIFY_BITS_128(&c, 113); /* [d 0 t4 t3 0 0 c] = [p8 0 0 p5 p4 p3 0 0 p0] */ - r[0] = c & M; c >>= 52; + r[0] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&c) & M; rustsecp256k1zkp_v0_10_0_u128_rshift(&c, 52); VERIFY_BITS(r[0], 52); - VERIFY_BITS(c, 61); + VERIFY_BITS_128(&c, 61); /* [d 0 t4 t3 0 c r0] = [p8 0 0 p5 p4 p3 0 0 p0] */ - c += (uint128_t)a0 * b[1] - + (uint128_t)a1 * b[0]; - VERIFY_BITS(c, 114); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&c, a0, b[1]); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&c, a1, b[0]); + VERIFY_BITS_128(&c, 114); /* [d 0 t4 t3 0 c r0] = [p8 0 0 p5 p4 p3 0 p1 p0] */ - d += (uint128_t)a2 * b[4] - + (uint128_t)a3 * b[3] - + (uint128_t)a4 * b[2]; - VERIFY_BITS(d, 114); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a2, b[4]); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a3, b[3]); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a4, b[2]); + VERIFY_BITS_128(&d, 114); /* [d 0 t4 t3 0 c r0] = [p8 0 p6 p5 p4 p3 0 p1 p0] */ - c += (d & M) * R; d >>= 52; - VERIFY_BITS(c, 115); - VERIFY_BITS(d, 62); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&c, rustsecp256k1zkp_v0_10_0_u128_to_u64(&d) & M, R); rustsecp256k1zkp_v0_10_0_u128_rshift(&d, 52); + VERIFY_BITS_128(&c, 115); + VERIFY_BITS_128(&d, 62); /* [d 0 0 t4 t3 0 c r0] = [p8 0 p6 p5 p4 p3 0 p1 p0] */ - r[1] = c & M; c >>= 52; + r[1] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&c) & M; rustsecp256k1zkp_v0_10_0_u128_rshift(&c, 52); VERIFY_BITS(r[1], 52); - VERIFY_BITS(c, 63); + VERIFY_BITS_128(&c, 63); /* [d 0 0 t4 t3 c r1 r0] = [p8 0 p6 p5 p4 p3 0 p1 p0] */ - c += (uint128_t)a0 * b[2] - + (uint128_t)a1 * b[1] - + (uint128_t)a2 * b[0]; - VERIFY_BITS(c, 114); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&c, a0, b[2]); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&c, a1, b[1]); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&c, a2, b[0]); + VERIFY_BITS_128(&c, 114); /* [d 0 0 t4 t3 c r1 r0] = [p8 0 p6 p5 p4 p3 p2 p1 p0] */ - d += (uint128_t)a3 * b[4] - + (uint128_t)a4 * b[3]; - VERIFY_BITS(d, 114); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a3, b[4]); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a4, b[3]); + VERIFY_BITS_128(&d, 114); /* [d 0 0 t4 t3 c t1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */ - c += (uint128_t)R * (uint64_t)d; d >>= 64; - VERIFY_BITS(c, 115); - VERIFY_BITS(d, 50); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&c, R, rustsecp256k1zkp_v0_10_0_u128_to_u64(&d)); rustsecp256k1zkp_v0_10_0_u128_rshift(&d, 64); + VERIFY_BITS_128(&c, 115); + VERIFY_BITS_128(&d, 50); /* [(d<<12) 0 0 0 t4 t3 c r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */ - r[2] = c & M; c >>= 52; + r[2] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&c) & M; rustsecp256k1zkp_v0_10_0_u128_rshift(&c, 52); VERIFY_BITS(r[2], 52); - VERIFY_BITS(c, 63); + VERIFY_BITS_128(&c, 63); /* [(d<<12) 0 0 0 t4 t3+c r2 r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */ - c += (uint128_t)(R << 12) * (uint64_t)d + t3; - VERIFY_BITS(c, 100); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&c, R << 12, rustsecp256k1zkp_v0_10_0_u128_to_u64(&d)); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&c, t3); + VERIFY_BITS_128(&c, 100); /* [t4 c r2 r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */ - r[3] = c & M; c >>= 52; + r[3] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&c) & M; rustsecp256k1zkp_v0_10_0_u128_rshift(&c, 52); VERIFY_BITS(r[3], 52); - VERIFY_BITS(c, 48); + VERIFY_BITS_128(&c, 48); /* [t4+c r3 r2 r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */ - c += t4; - VERIFY_BITS(c, 49); - /* [c r3 r2 r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */ - r[4] = c; + r[4] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&c) + t4; VERIFY_BITS(r[4], 49); /* [r4 r3 r2 r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */ } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_sqr_inner(uint64_t *r, const uint64_t *a) { - uint128_t c, d; +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_sqr_inner(uint64_t *r, const uint64_t *a) { + rustsecp256k1zkp_v0_10_0_uint128 c, d; uint64_t a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4]; - int64_t t3, t4, tx, u0; + uint64_t t3, t4, tx, u0; const uint64_t M = 0xFFFFFFFFFFFFFULL, R = 0x1000003D10ULL; VERIFY_BITS(a[0], 56); @@ -170,107 +168,105 @@ SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_fe_sqr_inner(uint64_t *r, c * Note that [x 0 0 0 0 0] = [x*R]. */ - d = (uint128_t)(a0*2) * a3 - + (uint128_t)(a1*2) * a2; - VERIFY_BITS(d, 114); + rustsecp256k1zkp_v0_10_0_u128_mul(&d, a0*2, a3); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a1*2, a2); + VERIFY_BITS_128(&d, 114); /* [d 0 0 0] = [p3 0 0 0] */ - c = (uint128_t)a4 * a4; - VERIFY_BITS(c, 112); + rustsecp256k1zkp_v0_10_0_u128_mul(&c, a4, a4); + VERIFY_BITS_128(&c, 112); /* [c 0 0 0 0 d 0 0 0] = [p8 0 0 0 0 p3 0 0 0] */ - d += (uint128_t)R * (uint64_t)c; c >>= 64; - VERIFY_BITS(d, 115); - VERIFY_BITS(c, 48); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, R, rustsecp256k1zkp_v0_10_0_u128_to_u64(&c)); rustsecp256k1zkp_v0_10_0_u128_rshift(&c, 64); + VERIFY_BITS_128(&d, 115); + VERIFY_BITS_128(&c, 48); /* [(c<<12) 0 0 0 0 0 d 0 0 0] = [p8 0 0 0 0 p3 0 0 0] */ - t3 = d & M; d >>= 52; + t3 = rustsecp256k1zkp_v0_10_0_u128_to_u64(&d) & M; rustsecp256k1zkp_v0_10_0_u128_rshift(&d, 52); VERIFY_BITS(t3, 52); - VERIFY_BITS(d, 63); + VERIFY_BITS_128(&d, 63); /* [(c<<12) 0 0 0 0 d t3 0 0 0] = [p8 0 0 0 0 p3 0 0 0] */ a4 *= 2; - d += (uint128_t)a0 * a4 - + (uint128_t)(a1*2) * a3 - + (uint128_t)a2 * a2; - VERIFY_BITS(d, 115); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a0, a4); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a1*2, a3); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a2, a2); + VERIFY_BITS_128(&d, 115); /* [(c<<12) 0 0 0 0 d t3 0 0 0] = [p8 0 0 0 p4 p3 0 0 0] */ - d += (uint128_t)(R << 12) * (uint64_t)c; - VERIFY_BITS(d, 116); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, R << 12, rustsecp256k1zkp_v0_10_0_u128_to_u64(&c)); + VERIFY_BITS_128(&d, 116); /* [d t3 0 0 0] = [p8 0 0 0 p4 p3 0 0 0] */ - t4 = d & M; d >>= 52; + t4 = rustsecp256k1zkp_v0_10_0_u128_to_u64(&d) & M; rustsecp256k1zkp_v0_10_0_u128_rshift(&d, 52); VERIFY_BITS(t4, 52); - VERIFY_BITS(d, 64); + VERIFY_BITS_128(&d, 64); /* [d t4 t3 0 0 0] = [p8 0 0 0 p4 p3 0 0 0] */ tx = (t4 >> 48); t4 &= (M >> 4); VERIFY_BITS(tx, 4); VERIFY_BITS(t4, 48); /* [d t4+(tx<<48) t3 0 0 0] = [p8 0 0 0 p4 p3 0 0 0] */ - c = (uint128_t)a0 * a0; - VERIFY_BITS(c, 112); + rustsecp256k1zkp_v0_10_0_u128_mul(&c, a0, a0); + VERIFY_BITS_128(&c, 112); /* [d t4+(tx<<48) t3 0 0 c] = [p8 0 0 0 p4 p3 0 0 p0] */ - d += (uint128_t)a1 * a4 - + (uint128_t)(a2*2) * a3; - VERIFY_BITS(d, 114); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a1, a4); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a2*2, a3); + VERIFY_BITS_128(&d, 114); /* [d t4+(tx<<48) t3 0 0 c] = [p8 0 0 p5 p4 p3 0 0 p0] */ - u0 = d & M; d >>= 52; + u0 = rustsecp256k1zkp_v0_10_0_u128_to_u64(&d) & M; rustsecp256k1zkp_v0_10_0_u128_rshift(&d, 52); VERIFY_BITS(u0, 52); - VERIFY_BITS(d, 62); + VERIFY_BITS_128(&d, 62); /* [d u0 t4+(tx<<48) t3 0 0 c] = [p8 0 0 p5 p4 p3 0 0 p0] */ /* [d 0 t4+(tx<<48)+(u0<<52) t3 0 0 c] = [p8 0 0 p5 p4 p3 0 0 p0] */ u0 = (u0 << 4) | tx; VERIFY_BITS(u0, 56); /* [d 0 t4+(u0<<48) t3 0 0 c] = [p8 0 0 p5 p4 p3 0 0 p0] */ - c += (uint128_t)u0 * (R >> 4); - VERIFY_BITS(c, 113); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&c, u0, R >> 4); + VERIFY_BITS_128(&c, 113); /* [d 0 t4 t3 0 0 c] = [p8 0 0 p5 p4 p3 0 0 p0] */ - r[0] = c & M; c >>= 52; + r[0] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&c) & M; rustsecp256k1zkp_v0_10_0_u128_rshift(&c, 52); VERIFY_BITS(r[0], 52); - VERIFY_BITS(c, 61); + VERIFY_BITS_128(&c, 61); /* [d 0 t4 t3 0 c r0] = [p8 0 0 p5 p4 p3 0 0 p0] */ a0 *= 2; - c += (uint128_t)a0 * a1; - VERIFY_BITS(c, 114); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&c, a0, a1); + VERIFY_BITS_128(&c, 114); /* [d 0 t4 t3 0 c r0] = [p8 0 0 p5 p4 p3 0 p1 p0] */ - d += (uint128_t)a2 * a4 - + (uint128_t)a3 * a3; - VERIFY_BITS(d, 114); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a2, a4); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a3, a3); + VERIFY_BITS_128(&d, 114); /* [d 0 t4 t3 0 c r0] = [p8 0 p6 p5 p4 p3 0 p1 p0] */ - c += (d & M) * R; d >>= 52; - VERIFY_BITS(c, 115); - VERIFY_BITS(d, 62); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&c, rustsecp256k1zkp_v0_10_0_u128_to_u64(&d) & M, R); rustsecp256k1zkp_v0_10_0_u128_rshift(&d, 52); + VERIFY_BITS_128(&c, 115); + VERIFY_BITS_128(&d, 62); /* [d 0 0 t4 t3 0 c r0] = [p8 0 p6 p5 p4 p3 0 p1 p0] */ - r[1] = c & M; c >>= 52; + r[1] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&c) & M; rustsecp256k1zkp_v0_10_0_u128_rshift(&c, 52); VERIFY_BITS(r[1], 52); - VERIFY_BITS(c, 63); + VERIFY_BITS_128(&c, 63); /* [d 0 0 t4 t3 c r1 r0] = [p8 0 p6 p5 p4 p3 0 p1 p0] */ - c += (uint128_t)a0 * a2 - + (uint128_t)a1 * a1; - VERIFY_BITS(c, 114); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&c, a0, a2); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&c, a1, a1); + VERIFY_BITS_128(&c, 114); /* [d 0 0 t4 t3 c r1 r0] = [p8 0 p6 p5 p4 p3 p2 p1 p0] */ - d += (uint128_t)a3 * a4; - VERIFY_BITS(d, 114); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&d, a3, a4); + VERIFY_BITS_128(&d, 114); /* [d 0 0 t4 t3 c r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */ - c += (uint128_t)R * (uint64_t)d; d >>= 64; - VERIFY_BITS(c, 115); - VERIFY_BITS(d, 50); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&c, R, rustsecp256k1zkp_v0_10_0_u128_to_u64(&d)); rustsecp256k1zkp_v0_10_0_u128_rshift(&d, 64); + VERIFY_BITS_128(&c, 115); + VERIFY_BITS_128(&d, 50); /* [(d<<12) 0 0 0 t4 t3 c r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */ - r[2] = c & M; c >>= 52; + r[2] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&c) & M; rustsecp256k1zkp_v0_10_0_u128_rshift(&c, 52); VERIFY_BITS(r[2], 52); - VERIFY_BITS(c, 63); + VERIFY_BITS_128(&c, 63); /* [(d<<12) 0 0 0 t4 t3+c r2 r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */ - c += (uint128_t)(R << 12) * (uint64_t)d + t3; - VERIFY_BITS(c, 100); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&c, R << 12, rustsecp256k1zkp_v0_10_0_u128_to_u64(&d)); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&c, t3); + VERIFY_BITS_128(&c, 100); /* [t4 c r2 r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */ - r[3] = c & M; c >>= 52; + r[3] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&c) & M; rustsecp256k1zkp_v0_10_0_u128_rshift(&c, 52); VERIFY_BITS(r[3], 52); - VERIFY_BITS(c, 48); + VERIFY_BITS_128(&c, 48); /* [t4+c r3 r2 r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */ - c += t4; - VERIFY_BITS(c, 49); - /* [c r3 r2 r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */ - r[4] = c; + r[4] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&c) + t4; VERIFY_BITS(r[4], 49); /* [r4 r3 r2 r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */ } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/field_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/field_impl.h index 4d5c2279..d621eeb0 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/field_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/field_impl.h @@ -7,10 +7,7 @@ #ifndef SECP256K1_FIELD_IMPL_H #define SECP256K1_FIELD_IMPL_H -#if defined HAVE_CONFIG_H -#include "libsecp256k1-config.h" -#endif - +#include "field.h" #include "util.h" #if defined(SECP256K1_WIDEMUL_INT128) @@ -21,21 +18,19 @@ #error "Please select wide multiplication implementation" #endif -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_fe_equal(const rustsecp256k1zkp_v0_8_0_fe *a, const rustsecp256k1zkp_v0_8_0_fe *b) { - rustsecp256k1zkp_v0_8_0_fe na; - rustsecp256k1zkp_v0_8_0_fe_negate(&na, a, 1); - rustsecp256k1zkp_v0_8_0_fe_add(&na, b); - return rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero(&na); -} +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_fe_equal(const rustsecp256k1zkp_v0_10_0_fe *a, const rustsecp256k1zkp_v0_10_0_fe *b) { + rustsecp256k1zkp_v0_10_0_fe na; + SECP256K1_FE_VERIFY(a); + SECP256K1_FE_VERIFY(b); + SECP256K1_FE_VERIFY_MAGNITUDE(a, 1); + SECP256K1_FE_VERIFY_MAGNITUDE(b, 31); -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_fe_equal_var(const rustsecp256k1zkp_v0_8_0_fe *a, const rustsecp256k1zkp_v0_8_0_fe *b) { - rustsecp256k1zkp_v0_8_0_fe na; - rustsecp256k1zkp_v0_8_0_fe_negate(&na, a, 1); - rustsecp256k1zkp_v0_8_0_fe_add(&na, b); - return rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero_var(&na); + rustsecp256k1zkp_v0_10_0_fe_negate(&na, a, 1); + rustsecp256k1zkp_v0_10_0_fe_add(&na, b); + return rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero(&na); } -static int rustsecp256k1zkp_v0_8_0_fe_sqrt(rustsecp256k1zkp_v0_8_0_fe *r, const rustsecp256k1zkp_v0_8_0_fe *a) { +static int rustsecp256k1zkp_v0_10_0_fe_sqrt(rustsecp256k1zkp_v0_10_0_fe * SECP256K1_RESTRICT r, const rustsecp256k1zkp_v0_10_0_fe * SECP256K1_RESTRICT a) { /** Given that p is congruent to 3 mod 4, we can compute the square root of * a mod p as the (p+1)/4'th power of a. * @@ -45,99 +40,423 @@ static int rustsecp256k1zkp_v0_8_0_fe_sqrt(rustsecp256k1zkp_v0_8_0_fe *r, const * Also because (p+1)/4 is an even number, the computed square root is * itself always a square (a ** ((p+1)/4) is the square of a ** ((p+1)/8)). */ - rustsecp256k1zkp_v0_8_0_fe x2, x3, x6, x9, x11, x22, x44, x88, x176, x220, x223, t1; - int j; + rustsecp256k1zkp_v0_10_0_fe x2, x3, x6, x9, x11, x22, x44, x88, x176, x220, x223, t1; + int j, ret; VERIFY_CHECK(r != a); + SECP256K1_FE_VERIFY(a); + SECP256K1_FE_VERIFY_MAGNITUDE(a, 8); /** The binary representation of (p + 1)/4 has 3 blocks of 1s, with lengths in * { 2, 22, 223 }. Use an addition chain to calculate 2^n - 1 for each block: * 1, [2], 3, 6, 9, 11, [22], 44, 88, 176, 220, [223] */ - rustsecp256k1zkp_v0_8_0_fe_sqr(&x2, a); - rustsecp256k1zkp_v0_8_0_fe_mul(&x2, &x2, a); + rustsecp256k1zkp_v0_10_0_fe_sqr(&x2, a); + rustsecp256k1zkp_v0_10_0_fe_mul(&x2, &x2, a); - rustsecp256k1zkp_v0_8_0_fe_sqr(&x3, &x2); - rustsecp256k1zkp_v0_8_0_fe_mul(&x3, &x3, a); + rustsecp256k1zkp_v0_10_0_fe_sqr(&x3, &x2); + rustsecp256k1zkp_v0_10_0_fe_mul(&x3, &x3, a); x6 = x3; for (j=0; j<3; j++) { - rustsecp256k1zkp_v0_8_0_fe_sqr(&x6, &x6); + rustsecp256k1zkp_v0_10_0_fe_sqr(&x6, &x6); } - rustsecp256k1zkp_v0_8_0_fe_mul(&x6, &x6, &x3); + rustsecp256k1zkp_v0_10_0_fe_mul(&x6, &x6, &x3); x9 = x6; for (j=0; j<3; j++) { - rustsecp256k1zkp_v0_8_0_fe_sqr(&x9, &x9); + rustsecp256k1zkp_v0_10_0_fe_sqr(&x9, &x9); } - rustsecp256k1zkp_v0_8_0_fe_mul(&x9, &x9, &x3); + rustsecp256k1zkp_v0_10_0_fe_mul(&x9, &x9, &x3); x11 = x9; for (j=0; j<2; j++) { - rustsecp256k1zkp_v0_8_0_fe_sqr(&x11, &x11); + rustsecp256k1zkp_v0_10_0_fe_sqr(&x11, &x11); } - rustsecp256k1zkp_v0_8_0_fe_mul(&x11, &x11, &x2); + rustsecp256k1zkp_v0_10_0_fe_mul(&x11, &x11, &x2); x22 = x11; for (j=0; j<11; j++) { - rustsecp256k1zkp_v0_8_0_fe_sqr(&x22, &x22); + rustsecp256k1zkp_v0_10_0_fe_sqr(&x22, &x22); } - rustsecp256k1zkp_v0_8_0_fe_mul(&x22, &x22, &x11); + rustsecp256k1zkp_v0_10_0_fe_mul(&x22, &x22, &x11); x44 = x22; for (j=0; j<22; j++) { - rustsecp256k1zkp_v0_8_0_fe_sqr(&x44, &x44); + rustsecp256k1zkp_v0_10_0_fe_sqr(&x44, &x44); } - rustsecp256k1zkp_v0_8_0_fe_mul(&x44, &x44, &x22); + rustsecp256k1zkp_v0_10_0_fe_mul(&x44, &x44, &x22); x88 = x44; for (j=0; j<44; j++) { - rustsecp256k1zkp_v0_8_0_fe_sqr(&x88, &x88); + rustsecp256k1zkp_v0_10_0_fe_sqr(&x88, &x88); } - rustsecp256k1zkp_v0_8_0_fe_mul(&x88, &x88, &x44); + rustsecp256k1zkp_v0_10_0_fe_mul(&x88, &x88, &x44); x176 = x88; for (j=0; j<88; j++) { - rustsecp256k1zkp_v0_8_0_fe_sqr(&x176, &x176); + rustsecp256k1zkp_v0_10_0_fe_sqr(&x176, &x176); } - rustsecp256k1zkp_v0_8_0_fe_mul(&x176, &x176, &x88); + rustsecp256k1zkp_v0_10_0_fe_mul(&x176, &x176, &x88); x220 = x176; for (j=0; j<44; j++) { - rustsecp256k1zkp_v0_8_0_fe_sqr(&x220, &x220); + rustsecp256k1zkp_v0_10_0_fe_sqr(&x220, &x220); } - rustsecp256k1zkp_v0_8_0_fe_mul(&x220, &x220, &x44); + rustsecp256k1zkp_v0_10_0_fe_mul(&x220, &x220, &x44); x223 = x220; for (j=0; j<3; j++) { - rustsecp256k1zkp_v0_8_0_fe_sqr(&x223, &x223); + rustsecp256k1zkp_v0_10_0_fe_sqr(&x223, &x223); } - rustsecp256k1zkp_v0_8_0_fe_mul(&x223, &x223, &x3); + rustsecp256k1zkp_v0_10_0_fe_mul(&x223, &x223, &x3); /* The final result is then assembled using a sliding window over the blocks. */ t1 = x223; for (j=0; j<23; j++) { - rustsecp256k1zkp_v0_8_0_fe_sqr(&t1, &t1); + rustsecp256k1zkp_v0_10_0_fe_sqr(&t1, &t1); } - rustsecp256k1zkp_v0_8_0_fe_mul(&t1, &t1, &x22); + rustsecp256k1zkp_v0_10_0_fe_mul(&t1, &t1, &x22); for (j=0; j<6; j++) { - rustsecp256k1zkp_v0_8_0_fe_sqr(&t1, &t1); + rustsecp256k1zkp_v0_10_0_fe_sqr(&t1, &t1); } - rustsecp256k1zkp_v0_8_0_fe_mul(&t1, &t1, &x2); - rustsecp256k1zkp_v0_8_0_fe_sqr(&t1, &t1); - rustsecp256k1zkp_v0_8_0_fe_sqr(r, &t1); + rustsecp256k1zkp_v0_10_0_fe_mul(&t1, &t1, &x2); + rustsecp256k1zkp_v0_10_0_fe_sqr(&t1, &t1); + rustsecp256k1zkp_v0_10_0_fe_sqr(r, &t1); /* Check that a square root was actually calculated */ - rustsecp256k1zkp_v0_8_0_fe_sqr(&t1, r); - return rustsecp256k1zkp_v0_8_0_fe_equal(&t1, a); + rustsecp256k1zkp_v0_10_0_fe_sqr(&t1, r); + ret = rustsecp256k1zkp_v0_10_0_fe_equal(&t1, a); + +#ifdef VERIFY + if (!ret) { + rustsecp256k1zkp_v0_10_0_fe_negate(&t1, &t1, 1); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&t1); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&t1, a)); + } +#endif + return ret; +} + +#ifndef VERIFY +static void rustsecp256k1zkp_v0_10_0_fe_verify(const rustsecp256k1zkp_v0_10_0_fe *a) { (void)a; } +static void rustsecp256k1zkp_v0_10_0_fe_verify_magnitude(const rustsecp256k1zkp_v0_10_0_fe *a, int m) { (void)a; (void)m; } +#else +static void rustsecp256k1zkp_v0_10_0_fe_impl_verify(const rustsecp256k1zkp_v0_10_0_fe *a); +static void rustsecp256k1zkp_v0_10_0_fe_verify(const rustsecp256k1zkp_v0_10_0_fe *a) { + /* Magnitude between 0 and 32. */ + SECP256K1_FE_VERIFY_MAGNITUDE(a, 32); + /* Normalized is 0 or 1. */ + VERIFY_CHECK((a->normalized == 0) || (a->normalized == 1)); + /* If normalized, magnitude must be 0 or 1. */ + if (a->normalized) SECP256K1_FE_VERIFY_MAGNITUDE(a, 1); + /* Invoke implementation-specific checks. */ + rustsecp256k1zkp_v0_10_0_fe_impl_verify(a); +} + +static void rustsecp256k1zkp_v0_10_0_fe_verify_magnitude(const rustsecp256k1zkp_v0_10_0_fe *a, int m) { + VERIFY_CHECK(m >= 0); + VERIFY_CHECK(m <= 32); + VERIFY_CHECK(a->magnitude <= m); +} + +static void rustsecp256k1zkp_v0_10_0_fe_impl_normalize(rustsecp256k1zkp_v0_10_0_fe *r); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_normalize(rustsecp256k1zkp_v0_10_0_fe *r) { + SECP256K1_FE_VERIFY(r); + + rustsecp256k1zkp_v0_10_0_fe_impl_normalize(r); + r->magnitude = 1; + r->normalized = 1; + + SECP256K1_FE_VERIFY(r); +} + +static void rustsecp256k1zkp_v0_10_0_fe_impl_normalize_weak(rustsecp256k1zkp_v0_10_0_fe *r); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_normalize_weak(rustsecp256k1zkp_v0_10_0_fe *r) { + SECP256K1_FE_VERIFY(r); + + rustsecp256k1zkp_v0_10_0_fe_impl_normalize_weak(r); + r->magnitude = 1; + + SECP256K1_FE_VERIFY(r); +} + +static void rustsecp256k1zkp_v0_10_0_fe_impl_normalize_var(rustsecp256k1zkp_v0_10_0_fe *r); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_normalize_var(rustsecp256k1zkp_v0_10_0_fe *r) { + SECP256K1_FE_VERIFY(r); + + rustsecp256k1zkp_v0_10_0_fe_impl_normalize_var(r); + r->magnitude = 1; + r->normalized = 1; + + SECP256K1_FE_VERIFY(r); +} + +static int rustsecp256k1zkp_v0_10_0_fe_impl_normalizes_to_zero(const rustsecp256k1zkp_v0_10_0_fe *r); +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero(const rustsecp256k1zkp_v0_10_0_fe *r) { + SECP256K1_FE_VERIFY(r); + + return rustsecp256k1zkp_v0_10_0_fe_impl_normalizes_to_zero(r); +} + +static int rustsecp256k1zkp_v0_10_0_fe_impl_normalizes_to_zero_var(const rustsecp256k1zkp_v0_10_0_fe *r); +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(const rustsecp256k1zkp_v0_10_0_fe *r) { + SECP256K1_FE_VERIFY(r); + + return rustsecp256k1zkp_v0_10_0_fe_impl_normalizes_to_zero_var(r); +} + +static void rustsecp256k1zkp_v0_10_0_fe_impl_set_int(rustsecp256k1zkp_v0_10_0_fe *r, int a); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_set_int(rustsecp256k1zkp_v0_10_0_fe *r, int a) { + VERIFY_CHECK(0 <= a && a <= 0x7FFF); + + rustsecp256k1zkp_v0_10_0_fe_impl_set_int(r, a); + r->magnitude = (a != 0); + r->normalized = 1; + + SECP256K1_FE_VERIFY(r); +} + +static void rustsecp256k1zkp_v0_10_0_fe_impl_add_int(rustsecp256k1zkp_v0_10_0_fe *r, int a); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_add_int(rustsecp256k1zkp_v0_10_0_fe *r, int a) { + VERIFY_CHECK(0 <= a && a <= 0x7FFF); + SECP256K1_FE_VERIFY(r); + + rustsecp256k1zkp_v0_10_0_fe_impl_add_int(r, a); + r->magnitude += 1; + r->normalized = 0; + + SECP256K1_FE_VERIFY(r); +} + +static void rustsecp256k1zkp_v0_10_0_fe_impl_clear(rustsecp256k1zkp_v0_10_0_fe *a); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_clear(rustsecp256k1zkp_v0_10_0_fe *a) { + a->magnitude = 0; + a->normalized = 1; + rustsecp256k1zkp_v0_10_0_fe_impl_clear(a); + + SECP256K1_FE_VERIFY(a); +} + +static int rustsecp256k1zkp_v0_10_0_fe_impl_is_zero(const rustsecp256k1zkp_v0_10_0_fe *a); +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_fe_is_zero(const rustsecp256k1zkp_v0_10_0_fe *a) { + SECP256K1_FE_VERIFY(a); + VERIFY_CHECK(a->normalized); + + return rustsecp256k1zkp_v0_10_0_fe_impl_is_zero(a); +} + +static int rustsecp256k1zkp_v0_10_0_fe_impl_is_odd(const rustsecp256k1zkp_v0_10_0_fe *a); +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_fe_is_odd(const rustsecp256k1zkp_v0_10_0_fe *a) { + SECP256K1_FE_VERIFY(a); + VERIFY_CHECK(a->normalized); + + return rustsecp256k1zkp_v0_10_0_fe_impl_is_odd(a); +} + +static int rustsecp256k1zkp_v0_10_0_fe_impl_cmp_var(const rustsecp256k1zkp_v0_10_0_fe *a, const rustsecp256k1zkp_v0_10_0_fe *b); +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_fe_cmp_var(const rustsecp256k1zkp_v0_10_0_fe *a, const rustsecp256k1zkp_v0_10_0_fe *b) { + SECP256K1_FE_VERIFY(a); + SECP256K1_FE_VERIFY(b); + VERIFY_CHECK(a->normalized); + VERIFY_CHECK(b->normalized); + + return rustsecp256k1zkp_v0_10_0_fe_impl_cmp_var(a, b); +} + +static void rustsecp256k1zkp_v0_10_0_fe_impl_set_b32_mod(rustsecp256k1zkp_v0_10_0_fe *r, const unsigned char *a); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_set_b32_mod(rustsecp256k1zkp_v0_10_0_fe *r, const unsigned char *a) { + rustsecp256k1zkp_v0_10_0_fe_impl_set_b32_mod(r, a); + r->magnitude = 1; + r->normalized = 0; + + SECP256K1_FE_VERIFY(r); +} + +static int rustsecp256k1zkp_v0_10_0_fe_impl_set_b32_limit(rustsecp256k1zkp_v0_10_0_fe *r, const unsigned char *a); +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(rustsecp256k1zkp_v0_10_0_fe *r, const unsigned char *a) { + if (rustsecp256k1zkp_v0_10_0_fe_impl_set_b32_limit(r, a)) { + r->magnitude = 1; + r->normalized = 1; + SECP256K1_FE_VERIFY(r); + return 1; + } else { + /* Mark the output field element as invalid. */ + r->magnitude = -1; + return 0; + } +} + +static void rustsecp256k1zkp_v0_10_0_fe_impl_get_b32(unsigned char *r, const rustsecp256k1zkp_v0_10_0_fe *a); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_get_b32(unsigned char *r, const rustsecp256k1zkp_v0_10_0_fe *a) { + SECP256K1_FE_VERIFY(a); + VERIFY_CHECK(a->normalized); + + rustsecp256k1zkp_v0_10_0_fe_impl_get_b32(r, a); +} + +static void rustsecp256k1zkp_v0_10_0_fe_impl_negate_unchecked(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a, int m); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_negate_unchecked(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a, int m) { + SECP256K1_FE_VERIFY(a); + VERIFY_CHECK(m >= 0 && m <= 31); + SECP256K1_FE_VERIFY_MAGNITUDE(a, m); + + rustsecp256k1zkp_v0_10_0_fe_impl_negate_unchecked(r, a, m); + r->magnitude = m + 1; + r->normalized = 0; + + SECP256K1_FE_VERIFY(r); } -static int rustsecp256k1zkp_v0_8_0_fe_is_quad_var(const rustsecp256k1zkp_v0_8_0_fe *a) { - rustsecp256k1zkp_v0_8_0_fe r; - return rustsecp256k1zkp_v0_8_0_fe_sqrt(&r, a); +static void rustsecp256k1zkp_v0_10_0_fe_impl_mul_int_unchecked(rustsecp256k1zkp_v0_10_0_fe *r, int a); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_mul_int_unchecked(rustsecp256k1zkp_v0_10_0_fe *r, int a) { + SECP256K1_FE_VERIFY(r); + + VERIFY_CHECK(a >= 0 && a <= 32); + VERIFY_CHECK(a*r->magnitude <= 32); + rustsecp256k1zkp_v0_10_0_fe_impl_mul_int_unchecked(r, a); + r->magnitude *= a; + r->normalized = 0; + + SECP256K1_FE_VERIFY(r); +} + +static void rustsecp256k1zkp_v0_10_0_fe_impl_add(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_add(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a) { + SECP256K1_FE_VERIFY(r); + SECP256K1_FE_VERIFY(a); + VERIFY_CHECK(r->magnitude + a->magnitude <= 32); + + rustsecp256k1zkp_v0_10_0_fe_impl_add(r, a); + r->magnitude += a->magnitude; + r->normalized = 0; + + SECP256K1_FE_VERIFY(r); +} + +static void rustsecp256k1zkp_v0_10_0_fe_impl_mul(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a, const rustsecp256k1zkp_v0_10_0_fe * SECP256K1_RESTRICT b); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_mul(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a, const rustsecp256k1zkp_v0_10_0_fe * SECP256K1_RESTRICT b) { + SECP256K1_FE_VERIFY(a); + SECP256K1_FE_VERIFY(b); + SECP256K1_FE_VERIFY_MAGNITUDE(a, 8); + SECP256K1_FE_VERIFY_MAGNITUDE(b, 8); + VERIFY_CHECK(r != b); + VERIFY_CHECK(a != b); + + rustsecp256k1zkp_v0_10_0_fe_impl_mul(r, a, b); + r->magnitude = 1; + r->normalized = 0; + + SECP256K1_FE_VERIFY(r); +} + +static void rustsecp256k1zkp_v0_10_0_fe_impl_sqr(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_sqr(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a) { + SECP256K1_FE_VERIFY(a); + SECP256K1_FE_VERIFY_MAGNITUDE(a, 8); + + rustsecp256k1zkp_v0_10_0_fe_impl_sqr(r, a); + r->magnitude = 1; + r->normalized = 0; + + SECP256K1_FE_VERIFY(r); +} + +static void rustsecp256k1zkp_v0_10_0_fe_impl_cmov(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a, int flag); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_cmov(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *a, int flag) { + VERIFY_CHECK(flag == 0 || flag == 1); + SECP256K1_FE_VERIFY(a); + SECP256K1_FE_VERIFY(r); + + rustsecp256k1zkp_v0_10_0_fe_impl_cmov(r, a, flag); + if (a->magnitude > r->magnitude) r->magnitude = a->magnitude; + if (!a->normalized) r->normalized = 0; + + SECP256K1_FE_VERIFY(r); } +static void rustsecp256k1zkp_v0_10_0_fe_impl_to_storage(rustsecp256k1zkp_v0_10_0_fe_storage *r, const rustsecp256k1zkp_v0_10_0_fe *a); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_to_storage(rustsecp256k1zkp_v0_10_0_fe_storage *r, const rustsecp256k1zkp_v0_10_0_fe *a) { + SECP256K1_FE_VERIFY(a); + VERIFY_CHECK(a->normalized); + + rustsecp256k1zkp_v0_10_0_fe_impl_to_storage(r, a); +} + +static void rustsecp256k1zkp_v0_10_0_fe_impl_from_storage(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe_storage *a); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_from_storage(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe_storage *a) { + rustsecp256k1zkp_v0_10_0_fe_impl_from_storage(r, a); + r->magnitude = 1; + r->normalized = 1; + + SECP256K1_FE_VERIFY(r); +} + +static void rustsecp256k1zkp_v0_10_0_fe_impl_inv(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *x); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_inv(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *x) { + int input_is_zero = rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero(x); + SECP256K1_FE_VERIFY(x); + + rustsecp256k1zkp_v0_10_0_fe_impl_inv(r, x); + r->magnitude = x->magnitude > 0; + r->normalized = 1; + + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero(r) == input_is_zero); + SECP256K1_FE_VERIFY(r); +} + +static void rustsecp256k1zkp_v0_10_0_fe_impl_inv_var(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *x); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_inv_var(rustsecp256k1zkp_v0_10_0_fe *r, const rustsecp256k1zkp_v0_10_0_fe *x) { + int input_is_zero = rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero(x); + SECP256K1_FE_VERIFY(x); + + rustsecp256k1zkp_v0_10_0_fe_impl_inv_var(r, x); + r->magnitude = x->magnitude > 0; + r->normalized = 1; + + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero(r) == input_is_zero); + SECP256K1_FE_VERIFY(r); +} + +static int rustsecp256k1zkp_v0_10_0_fe_impl_is_square_var(const rustsecp256k1zkp_v0_10_0_fe *x); +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_fe_is_square_var(const rustsecp256k1zkp_v0_10_0_fe *x) { + int ret; + rustsecp256k1zkp_v0_10_0_fe tmp = *x, sqrt; + SECP256K1_FE_VERIFY(x); + + ret = rustsecp256k1zkp_v0_10_0_fe_impl_is_square_var(x); + rustsecp256k1zkp_v0_10_0_fe_normalize_weak(&tmp); + VERIFY_CHECK(ret == rustsecp256k1zkp_v0_10_0_fe_sqrt(&sqrt, &tmp)); + return ret; +} + +static void rustsecp256k1zkp_v0_10_0_fe_impl_get_bounds(rustsecp256k1zkp_v0_10_0_fe* r, int m); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_get_bounds(rustsecp256k1zkp_v0_10_0_fe* r, int m) { + VERIFY_CHECK(m >= 0); + VERIFY_CHECK(m <= 32); + + rustsecp256k1zkp_v0_10_0_fe_impl_get_bounds(r, m); + r->magnitude = m; + r->normalized = (m == 0); + + SECP256K1_FE_VERIFY(r); +} + +static void rustsecp256k1zkp_v0_10_0_fe_impl_half(rustsecp256k1zkp_v0_10_0_fe *r); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_fe_half(rustsecp256k1zkp_v0_10_0_fe *r) { + SECP256K1_FE_VERIFY(r); + SECP256K1_FE_VERIFY_MAGNITUDE(r, 31); + + rustsecp256k1zkp_v0_10_0_fe_impl_half(r); + r->magnitude = (r->magnitude >> 1) + 1; + r->normalized = 0; + + SECP256K1_FE_VERIFY(r); +} + +#endif /* defined(VERIFY) */ + #endif /* SECP256K1_FIELD_IMPL_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/group.h b/secp256k1-zkp-sys/depend/secp256k1/src/group.h index f4e78e7f..8d3b9f0f 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/group.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/group.h @@ -14,66 +14,80 @@ * Note: For exhaustive test mode, secp256k1 is replaced by a small subgroup of a different curve. */ typedef struct { - rustsecp256k1zkp_v0_8_0_fe x; - rustsecp256k1zkp_v0_8_0_fe y; + rustsecp256k1zkp_v0_10_0_fe x; + rustsecp256k1zkp_v0_10_0_fe y; int infinity; /* whether this represents the point at infinity */ -} rustsecp256k1zkp_v0_8_0_ge; +} rustsecp256k1zkp_v0_10_0_ge; #define SECP256K1_GE_CONST(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) {SECP256K1_FE_CONST((a),(b),(c),(d),(e),(f),(g),(h)), SECP256K1_FE_CONST((i),(j),(k),(l),(m),(n),(o),(p)), 0} #define SECP256K1_GE_CONST_INFINITY {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), 1} /** A group element of the secp256k1 curve, in jacobian coordinates. - * Note: For exhastive test mode, sepc256k1 is replaced by a small subgroup of a different curve. + * Note: For exhastive test mode, secp256k1 is replaced by a small subgroup of a different curve. */ typedef struct { - rustsecp256k1zkp_v0_8_0_fe x; /* actual X: x/z^2 */ - rustsecp256k1zkp_v0_8_0_fe y; /* actual Y: y/z^3 */ - rustsecp256k1zkp_v0_8_0_fe z; + rustsecp256k1zkp_v0_10_0_fe x; /* actual X: x/z^2 */ + rustsecp256k1zkp_v0_10_0_fe y; /* actual Y: y/z^3 */ + rustsecp256k1zkp_v0_10_0_fe z; int infinity; /* whether this represents the point at infinity */ -} rustsecp256k1zkp_v0_8_0_gej; +} rustsecp256k1zkp_v0_10_0_gej; #define SECP256K1_GEJ_CONST(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) {SECP256K1_FE_CONST((a),(b),(c),(d),(e),(f),(g),(h)), SECP256K1_FE_CONST((i),(j),(k),(l),(m),(n),(o),(p)), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 1), 0} #define SECP256K1_GEJ_CONST_INFINITY {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), 1} typedef struct { - rustsecp256k1zkp_v0_8_0_fe_storage x; - rustsecp256k1zkp_v0_8_0_fe_storage y; -} rustsecp256k1zkp_v0_8_0_ge_storage; + rustsecp256k1zkp_v0_10_0_fe_storage x; + rustsecp256k1zkp_v0_10_0_fe_storage y; +} rustsecp256k1zkp_v0_10_0_ge_storage; #define SECP256K1_GE_STORAGE_CONST(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) {SECP256K1_FE_STORAGE_CONST((a),(b),(c),(d),(e),(f),(g),(h)), SECP256K1_FE_STORAGE_CONST((i),(j),(k),(l),(m),(n),(o),(p))} #define SECP256K1_GE_STORAGE_CONST_GET(t) SECP256K1_FE_STORAGE_CONST_GET(t.x), SECP256K1_FE_STORAGE_CONST_GET(t.y) +/** Maximum allowed magnitudes for group element coordinates + * in affine (x, y) and jacobian (x, y, z) representation. */ +#define SECP256K1_GE_X_MAGNITUDE_MAX 4 +#define SECP256K1_GE_Y_MAGNITUDE_MAX 3 +#define SECP256K1_GEJ_X_MAGNITUDE_MAX 4 +#define SECP256K1_GEJ_Y_MAGNITUDE_MAX 4 +#define SECP256K1_GEJ_Z_MAGNITUDE_MAX 1 + /** Set a group element equal to the point with given X and Y coordinates */ -static void rustsecp256k1zkp_v0_8_0_ge_set_xy(rustsecp256k1zkp_v0_8_0_ge *r, const rustsecp256k1zkp_v0_8_0_fe *x, const rustsecp256k1zkp_v0_8_0_fe *y); +static void rustsecp256k1zkp_v0_10_0_ge_set_xy(rustsecp256k1zkp_v0_10_0_ge *r, const rustsecp256k1zkp_v0_10_0_fe *x, const rustsecp256k1zkp_v0_10_0_fe *y); /** Set a group element (affine) equal to the point with the given X coordinate * and a Y coordinate that is a quadratic residue modulo p. The return value * is true iff a coordinate with the given X coordinate exists. */ -static int rustsecp256k1zkp_v0_8_0_ge_set_xquad(rustsecp256k1zkp_v0_8_0_ge *r, const rustsecp256k1zkp_v0_8_0_fe *x); +static int rustsecp256k1zkp_v0_10_0_ge_set_xquad(rustsecp256k1zkp_v0_10_0_ge *r, const rustsecp256k1zkp_v0_10_0_fe *x); /** Set a group element (affine) equal to the point with the given X coordinate, and given oddness * for Y. Return value indicates whether the result is valid. */ -static int rustsecp256k1zkp_v0_8_0_ge_set_xo_var(rustsecp256k1zkp_v0_8_0_ge *r, const rustsecp256k1zkp_v0_8_0_fe *x, int odd); +static int rustsecp256k1zkp_v0_10_0_ge_set_xo_var(rustsecp256k1zkp_v0_10_0_ge *r, const rustsecp256k1zkp_v0_10_0_fe *x, int odd); + +/** Determine whether x is a valid X coordinate on the curve. */ +static int rustsecp256k1zkp_v0_10_0_ge_x_on_curve_var(const rustsecp256k1zkp_v0_10_0_fe *x); + +/** Determine whether fraction xn/xd is a valid X coordinate on the curve (xd != 0). */ +static int rustsecp256k1zkp_v0_10_0_ge_x_frac_on_curve_var(const rustsecp256k1zkp_v0_10_0_fe *xn, const rustsecp256k1zkp_v0_10_0_fe *xd); /** Check whether a group element is the point at infinity. */ -static int rustsecp256k1zkp_v0_8_0_ge_is_infinity(const rustsecp256k1zkp_v0_8_0_ge *a); +static int rustsecp256k1zkp_v0_10_0_ge_is_infinity(const rustsecp256k1zkp_v0_10_0_ge *a); /** Check whether a group element is valid (i.e., on the curve). */ -static int rustsecp256k1zkp_v0_8_0_ge_is_valid_var(const rustsecp256k1zkp_v0_8_0_ge *a); +static int rustsecp256k1zkp_v0_10_0_ge_is_valid_var(const rustsecp256k1zkp_v0_10_0_ge *a); /** Set r equal to the inverse of a (i.e., mirrored around the X axis) */ -static void rustsecp256k1zkp_v0_8_0_ge_neg(rustsecp256k1zkp_v0_8_0_ge *r, const rustsecp256k1zkp_v0_8_0_ge *a); +static void rustsecp256k1zkp_v0_10_0_ge_neg(rustsecp256k1zkp_v0_10_0_ge *r, const rustsecp256k1zkp_v0_10_0_ge *a); /** Set a group element equal to another which is given in jacobian coordinates. Constant time. */ -static void rustsecp256k1zkp_v0_8_0_ge_set_gej(rustsecp256k1zkp_v0_8_0_ge *r, rustsecp256k1zkp_v0_8_0_gej *a); +static void rustsecp256k1zkp_v0_10_0_ge_set_gej(rustsecp256k1zkp_v0_10_0_ge *r, rustsecp256k1zkp_v0_10_0_gej *a); /** Set a group element equal to another which is given in jacobian coordinates. */ -static void rustsecp256k1zkp_v0_8_0_ge_set_gej_var(rustsecp256k1zkp_v0_8_0_ge *r, rustsecp256k1zkp_v0_8_0_gej *a); +static void rustsecp256k1zkp_v0_10_0_ge_set_gej_var(rustsecp256k1zkp_v0_10_0_ge *r, rustsecp256k1zkp_v0_10_0_gej *a); /** Set a batch of group elements equal to the inputs given in jacobian coordinates */ -static void rustsecp256k1zkp_v0_8_0_ge_set_all_gej_var(rustsecp256k1zkp_v0_8_0_ge *r, const rustsecp256k1zkp_v0_8_0_gej *a, size_t len); +static void rustsecp256k1zkp_v0_10_0_ge_set_all_gej_var(rustsecp256k1zkp_v0_10_0_ge *r, const rustsecp256k1zkp_v0_10_0_gej *a, size_t len); /** Bring a batch of inputs to the same global z "denominator", based on ratios between * (omitted) z coordinates of adjacent elements. @@ -92,72 +106,90 @@ static void rustsecp256k1zkp_v0_8_0_ge_set_all_gej_var(rustsecp256k1zkp_v0_8_0_g * * The coordinates of the final element a[len-1] are not changed. */ -static void rustsecp256k1zkp_v0_8_0_ge_table_set_globalz(size_t len, rustsecp256k1zkp_v0_8_0_ge *a, const rustsecp256k1zkp_v0_8_0_fe *zr); +static void rustsecp256k1zkp_v0_10_0_ge_table_set_globalz(size_t len, rustsecp256k1zkp_v0_10_0_ge *a, const rustsecp256k1zkp_v0_10_0_fe *zr); + +/** Check two group elements (affine) for equality in variable time. */ +static int rustsecp256k1zkp_v0_10_0_ge_eq_var(const rustsecp256k1zkp_v0_10_0_ge *a, const rustsecp256k1zkp_v0_10_0_ge *b); /** Set a group element (affine) equal to the point at infinity. */ -static void rustsecp256k1zkp_v0_8_0_ge_set_infinity(rustsecp256k1zkp_v0_8_0_ge *r); +static void rustsecp256k1zkp_v0_10_0_ge_set_infinity(rustsecp256k1zkp_v0_10_0_ge *r); /** Set a group element (jacobian) equal to the point at infinity. */ -static void rustsecp256k1zkp_v0_8_0_gej_set_infinity(rustsecp256k1zkp_v0_8_0_gej *r); +static void rustsecp256k1zkp_v0_10_0_gej_set_infinity(rustsecp256k1zkp_v0_10_0_gej *r); /** Set a group element (jacobian) equal to another which is given in affine coordinates. */ -static void rustsecp256k1zkp_v0_8_0_gej_set_ge(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_ge *a); +static void rustsecp256k1zkp_v0_10_0_gej_set_ge(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_ge *a); + +/** Check two group elements (jacobian) for equality in variable time. */ +static int rustsecp256k1zkp_v0_10_0_gej_eq_var(const rustsecp256k1zkp_v0_10_0_gej *a, const rustsecp256k1zkp_v0_10_0_gej *b); -/** Compare the X coordinate of a group element (jacobian). */ -static int rustsecp256k1zkp_v0_8_0_gej_eq_x_var(const rustsecp256k1zkp_v0_8_0_fe *x, const rustsecp256k1zkp_v0_8_0_gej *a); +/** Check two group elements (jacobian and affine) for equality in variable time. */ +static int rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(const rustsecp256k1zkp_v0_10_0_gej *a, const rustsecp256k1zkp_v0_10_0_ge *b); + +/** Compare the X coordinate of a group element (jacobian). + * The magnitude of the group element's X coordinate must not exceed 31. */ +static int rustsecp256k1zkp_v0_10_0_gej_eq_x_var(const rustsecp256k1zkp_v0_10_0_fe *x, const rustsecp256k1zkp_v0_10_0_gej *a); /** Set r equal to the inverse of a (i.e., mirrored around the X axis) */ -static void rustsecp256k1zkp_v0_8_0_gej_neg(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_gej *a); +static void rustsecp256k1zkp_v0_10_0_gej_neg(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_gej *a); /** Check whether a group element is the point at infinity. */ -static int rustsecp256k1zkp_v0_8_0_gej_is_infinity(const rustsecp256k1zkp_v0_8_0_gej *a); +static int rustsecp256k1zkp_v0_10_0_gej_is_infinity(const rustsecp256k1zkp_v0_10_0_gej *a); /** Check whether a group element's y coordinate is a quadratic residue. */ -static int rustsecp256k1zkp_v0_8_0_gej_has_quad_y_var(const rustsecp256k1zkp_v0_8_0_gej *a); +static int rustsecp256k1zkp_v0_10_0_gej_has_quad_y_var(const rustsecp256k1zkp_v0_10_0_gej *a); /** Set r equal to the double of a. Constant time. */ -static void rustsecp256k1zkp_v0_8_0_gej_double(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_gej *a); +static void rustsecp256k1zkp_v0_10_0_gej_double(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_gej *a); /** Set r equal to the double of a. If rzr is not-NULL this sets *rzr such that r->z == a->z * *rzr (where infinity means an implicit z = 0). */ -static void rustsecp256k1zkp_v0_8_0_gej_double_var(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_gej *a, rustsecp256k1zkp_v0_8_0_fe *rzr); +static void rustsecp256k1zkp_v0_10_0_gej_double_var(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_gej *a, rustsecp256k1zkp_v0_10_0_fe *rzr); /** Set r equal to the sum of a and b. If rzr is non-NULL this sets *rzr such that r->z == a->z * *rzr (a cannot be infinity in that case). */ -static void rustsecp256k1zkp_v0_8_0_gej_add_var(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_gej *a, const rustsecp256k1zkp_v0_8_0_gej *b, rustsecp256k1zkp_v0_8_0_fe *rzr); +static void rustsecp256k1zkp_v0_10_0_gej_add_var(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_gej *a, const rustsecp256k1zkp_v0_10_0_gej *b, rustsecp256k1zkp_v0_10_0_fe *rzr); /** Set r equal to the sum of a and b (with b given in affine coordinates, and not infinity). */ -static void rustsecp256k1zkp_v0_8_0_gej_add_ge(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_gej *a, const rustsecp256k1zkp_v0_8_0_ge *b); +static void rustsecp256k1zkp_v0_10_0_gej_add_ge(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_gej *a, const rustsecp256k1zkp_v0_10_0_ge *b); /** Set r equal to the sum of a and b (with b given in affine coordinates). This is more efficient - than rustsecp256k1zkp_v0_8_0_gej_add_var. It is identical to rustsecp256k1zkp_v0_8_0_gej_add_ge but without constant-time + than rustsecp256k1zkp_v0_10_0_gej_add_var. It is identical to rustsecp256k1zkp_v0_10_0_gej_add_ge but without constant-time guarantee, and b is allowed to be infinity. If rzr is non-NULL this sets *rzr such that r->z == a->z * *rzr (a cannot be infinity in that case). */ -static void rustsecp256k1zkp_v0_8_0_gej_add_ge_var(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_gej *a, const rustsecp256k1zkp_v0_8_0_ge *b, rustsecp256k1zkp_v0_8_0_fe *rzr); +static void rustsecp256k1zkp_v0_10_0_gej_add_ge_var(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_gej *a, const rustsecp256k1zkp_v0_10_0_ge *b, rustsecp256k1zkp_v0_10_0_fe *rzr); /** Set r equal to the sum of a and b (with the inverse of b's Z coordinate passed as bzinv). */ -static void rustsecp256k1zkp_v0_8_0_gej_add_zinv_var(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_gej *a, const rustsecp256k1zkp_v0_8_0_ge *b, const rustsecp256k1zkp_v0_8_0_fe *bzinv); +static void rustsecp256k1zkp_v0_10_0_gej_add_zinv_var(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_gej *a, const rustsecp256k1zkp_v0_10_0_ge *b, const rustsecp256k1zkp_v0_10_0_fe *bzinv); /** Set r to be equal to lambda times a, where lambda is chosen in a way such that this is very fast. */ -static void rustsecp256k1zkp_v0_8_0_ge_mul_lambda(rustsecp256k1zkp_v0_8_0_ge *r, const rustsecp256k1zkp_v0_8_0_ge *a); +static void rustsecp256k1zkp_v0_10_0_ge_mul_lambda(rustsecp256k1zkp_v0_10_0_ge *r, const rustsecp256k1zkp_v0_10_0_ge *a); -/** Clear a rustsecp256k1zkp_v0_8_0_gej to prevent leaking sensitive information. */ -static void rustsecp256k1zkp_v0_8_0_gej_clear(rustsecp256k1zkp_v0_8_0_gej *r); +/** Clear a rustsecp256k1zkp_v0_10_0_gej to prevent leaking sensitive information. */ +static void rustsecp256k1zkp_v0_10_0_gej_clear(rustsecp256k1zkp_v0_10_0_gej *r); -/** Clear a rustsecp256k1zkp_v0_8_0_ge to prevent leaking sensitive information. */ -static void rustsecp256k1zkp_v0_8_0_ge_clear(rustsecp256k1zkp_v0_8_0_ge *r); +/** Clear a rustsecp256k1zkp_v0_10_0_ge to prevent leaking sensitive information. */ +static void rustsecp256k1zkp_v0_10_0_ge_clear(rustsecp256k1zkp_v0_10_0_ge *r); /** Convert a group element to the storage type. */ -static void rustsecp256k1zkp_v0_8_0_ge_to_storage(rustsecp256k1zkp_v0_8_0_ge_storage *r, const rustsecp256k1zkp_v0_8_0_ge *a); +static void rustsecp256k1zkp_v0_10_0_ge_to_storage(rustsecp256k1zkp_v0_10_0_ge_storage *r, const rustsecp256k1zkp_v0_10_0_ge *a); /** Convert a group element back from the storage type. */ -static void rustsecp256k1zkp_v0_8_0_ge_from_storage(rustsecp256k1zkp_v0_8_0_ge *r, const rustsecp256k1zkp_v0_8_0_ge_storage *a); +static void rustsecp256k1zkp_v0_10_0_ge_from_storage(rustsecp256k1zkp_v0_10_0_ge *r, const rustsecp256k1zkp_v0_10_0_ge_storage *a); /** If flag is true, set *r equal to *a; otherwise leave it. Constant-time. Both *r and *a must be initialized.*/ -static void rustsecp256k1zkp_v0_8_0_gej_cmov(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_gej *a, int flag); +static void rustsecp256k1zkp_v0_10_0_gej_cmov(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_gej *a, int flag); /** If flag is true, set *r equal to *a; otherwise leave it. Constant-time. Both *r and *a must be initialized.*/ -static void rustsecp256k1zkp_v0_8_0_ge_storage_cmov(rustsecp256k1zkp_v0_8_0_ge_storage *r, const rustsecp256k1zkp_v0_8_0_ge_storage *a, int flag); +static void rustsecp256k1zkp_v0_10_0_ge_storage_cmov(rustsecp256k1zkp_v0_10_0_ge_storage *r, const rustsecp256k1zkp_v0_10_0_ge_storage *a, int flag); /** Rescale a jacobian point by b which must be non-zero. Constant-time. */ -static void rustsecp256k1zkp_v0_8_0_gej_rescale(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_fe *b); +static void rustsecp256k1zkp_v0_10_0_gej_rescale(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_fe *b); + +/** Convert a group element that is not infinity to a 64-byte array. The output + * array is platform-dependent. */ +static void rustsecp256k1zkp_v0_10_0_ge_to_bytes(unsigned char *buf, rustsecp256k1zkp_v0_10_0_ge *a); + +/** Convert a 64-byte array into group element. This function assumes that the + * provided buffer correctly encodes a group element. */ +static void rustsecp256k1zkp_v0_10_0_ge_from_bytes(rustsecp256k1zkp_v0_10_0_ge *r, const unsigned char *buf); /** Determine if a point (which is assumed to be on the curve) is in the correct (sub)group of the curve. * @@ -168,6 +200,14 @@ static void rustsecp256k1zkp_v0_8_0_gej_rescale(rustsecp256k1zkp_v0_8_0_gej *r, * (very) small subgroup, and that subgroup is what is used for all cryptographic operations. In that mode, this * function checks whether a point that is on the curve is in fact also in that subgroup. */ -static int rustsecp256k1zkp_v0_8_0_ge_is_in_correct_subgroup(const rustsecp256k1zkp_v0_8_0_ge* ge); +static int rustsecp256k1zkp_v0_10_0_ge_is_in_correct_subgroup(const rustsecp256k1zkp_v0_10_0_ge* ge); + +/** Check invariants on an affine group element (no-op unless VERIFY is enabled). */ +static void rustsecp256k1zkp_v0_10_0_ge_verify(const rustsecp256k1zkp_v0_10_0_ge *a); +#define SECP256K1_GE_VERIFY(a) rustsecp256k1zkp_v0_10_0_ge_verify(a) + +/** Check invariants on a Jacobian group element (no-op unless VERIFY is enabled). */ +static void rustsecp256k1zkp_v0_10_0_gej_verify(const rustsecp256k1zkp_v0_10_0_gej *a); +#define SECP256K1_GEJ_VERIFY(a) rustsecp256k1zkp_v0_10_0_gej_verify(a) #endif /* SECP256K1_GROUP_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/group_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/group_impl.h index 9becd35b..1b3681fc 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/group_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/group_impl.h @@ -7,132 +7,213 @@ #ifndef SECP256K1_GROUP_IMPL_H #define SECP256K1_GROUP_IMPL_H +#include + #include "field.h" #include "group.h" - +#include "util.h" + +/* Begin of section generated by sage/gen_exhaustive_groups.sage. */ +#define SECP256K1_G_ORDER_7 SECP256K1_GE_CONST(\ + 0x66625d13, 0x317ffe44, 0x63d32cff, 0x1ca02b9b,\ + 0xe5c6d070, 0x50b4b05e, 0x81cc30db, 0xf5166f0a,\ + 0x1e60e897, 0xa7c00c7c, 0x2df53eb6, 0x98274ff4,\ + 0x64252f42, 0x8ca44e17, 0x3b25418c, 0xff4ab0cf\ +) #define SECP256K1_G_ORDER_13 SECP256K1_GE_CONST(\ - 0xc3459c3d, 0x35326167, 0xcd86cce8, 0x07a2417f,\ - 0x5b8bd567, 0xde8538ee, 0x0d507b0c, 0xd128f5bb,\ - 0x8e467fec, 0xcd30000a, 0x6cc1184e, 0x25d382c2,\ - 0xa2f4494e, 0x2fbe9abc, 0x8b64abac, 0xd005fb24\ + 0xa2482ff8, 0x4bf34edf, 0xa51262fd, 0xe57921db,\ + 0xe0dd2cb7, 0xa5914790, 0xbc71631f, 0xc09704fb,\ + 0x942536cb, 0xa3e49492, 0x3a701cc3, 0xee3e443f,\ + 0xdf182aa9, 0x15b8aa6a, 0x166d3b19, 0xba84b045\ ) #define SECP256K1_G_ORDER_199 SECP256K1_GE_CONST(\ - 0x226e653f, 0xc8df7744, 0x9bacbf12, 0x7d1dcbf9,\ - 0x87f05b2a, 0xe7edbd28, 0x1f564575, 0xc48dcf18,\ - 0xa13872c2, 0xe933bb17, 0x5d9ffd5b, 0xb5b6e10c,\ - 0x57fe3c00, 0xbaaaa15a, 0xe003ec3e, 0x9c269bae\ + 0x7fb07b5c, 0xd07c3bda, 0x553902e2, 0x7a87ea2c,\ + 0x35108a7f, 0x051f41e5, 0xb76abad5, 0x1f2703ad,\ + 0x0a251539, 0x5b4c4438, 0x952a634f, 0xac10dd4d,\ + 0x6d6f4745, 0x98990c27, 0x3a4f3116, 0xd32ff969\ ) /** Generator for secp256k1, value 'g' defined in * "Standards for Efficient Cryptography" (SEC2) 2.7.1. */ #define SECP256K1_G SECP256K1_GE_CONST(\ - 0x79BE667EUL, 0xF9DCBBACUL, 0x55A06295UL, 0xCE870B07UL,\ - 0x029BFCDBUL, 0x2DCE28D9UL, 0x59F2815BUL, 0x16F81798UL,\ - 0x483ADA77UL, 0x26A3C465UL, 0x5DA4FBFCUL, 0x0E1108A8UL,\ - 0xFD17B448UL, 0xA6855419UL, 0x9C47D08FUL, 0xFB10D4B8UL\ + 0x79be667e, 0xf9dcbbac, 0x55a06295, 0xce870b07,\ + 0x029bfcdb, 0x2dce28d9, 0x59f2815b, 0x16f81798,\ + 0x483ada77, 0x26a3c465, 0x5da4fbfc, 0x0e1108a8,\ + 0xfd17b448, 0xa6855419, 0x9c47d08f, 0xfb10d4b8\ ) /* These exhaustive group test orders and generators are chosen such that: * - The field size is equal to that of secp256k1, so field code is the same. - * - The curve equation is of the form y^2=x^3+B for some constant B. - * - The subgroup has a generator 2*P, where P.x=1. + * - The curve equation is of the form y^2=x^3+B for some small constant B. + * - The subgroup has a generator 2*P, where P.x is as small as possible. * - The subgroup has size less than 1000 to permit exhaustive testing. * - The subgroup admits an endomorphism of the form lambda*(x,y) == (beta*x,y). - * - * These parameters are generated using sage/gen_exhaustive_groups.sage. */ #if defined(EXHAUSTIVE_TEST_ORDER) -# if EXHAUSTIVE_TEST_ORDER == 13 -static const rustsecp256k1zkp_v0_8_0_ge rustsecp256k1zkp_v0_8_0_ge_const_g = SECP256K1_G_ORDER_13; +# if EXHAUSTIVE_TEST_ORDER == 7 + +static const rustsecp256k1zkp_v0_10_0_ge rustsecp256k1zkp_v0_10_0_ge_const_g = SECP256K1_G_ORDER_7; +#define SECP256K1_B 6 + +# elif EXHAUSTIVE_TEST_ORDER == 13 + +static const rustsecp256k1zkp_v0_10_0_ge rustsecp256k1zkp_v0_10_0_ge_const_g = SECP256K1_G_ORDER_13; +#define SECP256K1_B 2 -static const rustsecp256k1zkp_v0_8_0_fe rustsecp256k1zkp_v0_8_0_fe_const_b = SECP256K1_FE_CONST( - 0x3d3486b2, 0x159a9ca5, 0xc75638be, 0xb23a69bc, - 0x946a45ab, 0x24801247, 0xb4ed2b8e, 0x26b6a417 -); # elif EXHAUSTIVE_TEST_ORDER == 199 -static const rustsecp256k1zkp_v0_8_0_ge rustsecp256k1zkp_v0_8_0_ge_const_g = SECP256K1_G_ORDER_199; -static const rustsecp256k1zkp_v0_8_0_fe rustsecp256k1zkp_v0_8_0_fe_const_b = SECP256K1_FE_CONST( - 0x2cca28fa, 0xfc614b80, 0x2a3db42b, 0x00ba00b1, - 0xbea8d943, 0xdace9ab2, 0x9536daea, 0x0074defb -); +static const rustsecp256k1zkp_v0_10_0_ge rustsecp256k1zkp_v0_10_0_ge_const_g = SECP256K1_G_ORDER_199; +#define SECP256K1_B 4 + # else # error No known generator for the specified exhaustive test group order. # endif #else -static const rustsecp256k1zkp_v0_8_0_ge rustsecp256k1zkp_v0_8_0_ge_const_g = SECP256K1_G; -static const rustsecp256k1zkp_v0_8_0_fe rustsecp256k1zkp_v0_8_0_fe_const_b = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 7); +static const rustsecp256k1zkp_v0_10_0_ge rustsecp256k1zkp_v0_10_0_ge_const_g = SECP256K1_G; +#define SECP256K1_B 7 + #endif +/* End of section generated by sage/gen_exhaustive_groups.sage. */ + +static void rustsecp256k1zkp_v0_10_0_ge_verify(const rustsecp256k1zkp_v0_10_0_ge *a) { + SECP256K1_FE_VERIFY(&a->x); + SECP256K1_FE_VERIFY(&a->y); + SECP256K1_FE_VERIFY_MAGNITUDE(&a->x, SECP256K1_GE_X_MAGNITUDE_MAX); + SECP256K1_FE_VERIFY_MAGNITUDE(&a->y, SECP256K1_GE_Y_MAGNITUDE_MAX); + VERIFY_CHECK(a->infinity == 0 || a->infinity == 1); + (void)a; +} + +static void rustsecp256k1zkp_v0_10_0_gej_verify(const rustsecp256k1zkp_v0_10_0_gej *a) { + SECP256K1_FE_VERIFY(&a->x); + SECP256K1_FE_VERIFY(&a->y); + SECP256K1_FE_VERIFY(&a->z); + SECP256K1_FE_VERIFY_MAGNITUDE(&a->x, SECP256K1_GEJ_X_MAGNITUDE_MAX); + SECP256K1_FE_VERIFY_MAGNITUDE(&a->y, SECP256K1_GEJ_Y_MAGNITUDE_MAX); + SECP256K1_FE_VERIFY_MAGNITUDE(&a->z, SECP256K1_GEJ_Z_MAGNITUDE_MAX); + VERIFY_CHECK(a->infinity == 0 || a->infinity == 1); + (void)a; +} + +/* Set r to the affine coordinates of Jacobian point (a.x, a.y, 1/zi). */ +static void rustsecp256k1zkp_v0_10_0_ge_set_gej_zinv(rustsecp256k1zkp_v0_10_0_ge *r, const rustsecp256k1zkp_v0_10_0_gej *a, const rustsecp256k1zkp_v0_10_0_fe *zi) { + rustsecp256k1zkp_v0_10_0_fe zi2; + rustsecp256k1zkp_v0_10_0_fe zi3; + SECP256K1_GEJ_VERIFY(a); + SECP256K1_FE_VERIFY(zi); + VERIFY_CHECK(!a->infinity); + + rustsecp256k1zkp_v0_10_0_fe_sqr(&zi2, zi); + rustsecp256k1zkp_v0_10_0_fe_mul(&zi3, &zi2, zi); + rustsecp256k1zkp_v0_10_0_fe_mul(&r->x, &a->x, &zi2); + rustsecp256k1zkp_v0_10_0_fe_mul(&r->y, &a->y, &zi3); + r->infinity = a->infinity; + + SECP256K1_GE_VERIFY(r); +} -static void rustsecp256k1zkp_v0_8_0_ge_set_gej_zinv(rustsecp256k1zkp_v0_8_0_ge *r, const rustsecp256k1zkp_v0_8_0_gej *a, const rustsecp256k1zkp_v0_8_0_fe *zi) { - rustsecp256k1zkp_v0_8_0_fe zi2; - rustsecp256k1zkp_v0_8_0_fe zi3; +/* Set r to the affine coordinates of Jacobian point (a.x, a.y, 1/zi). */ +static void rustsecp256k1zkp_v0_10_0_ge_set_ge_zinv(rustsecp256k1zkp_v0_10_0_ge *r, const rustsecp256k1zkp_v0_10_0_ge *a, const rustsecp256k1zkp_v0_10_0_fe *zi) { + rustsecp256k1zkp_v0_10_0_fe zi2; + rustsecp256k1zkp_v0_10_0_fe zi3; + SECP256K1_GE_VERIFY(a); + SECP256K1_FE_VERIFY(zi); VERIFY_CHECK(!a->infinity); - rustsecp256k1zkp_v0_8_0_fe_sqr(&zi2, zi); - rustsecp256k1zkp_v0_8_0_fe_mul(&zi3, &zi2, zi); - rustsecp256k1zkp_v0_8_0_fe_mul(&r->x, &a->x, &zi2); - rustsecp256k1zkp_v0_8_0_fe_mul(&r->y, &a->y, &zi3); + + rustsecp256k1zkp_v0_10_0_fe_sqr(&zi2, zi); + rustsecp256k1zkp_v0_10_0_fe_mul(&zi3, &zi2, zi); + rustsecp256k1zkp_v0_10_0_fe_mul(&r->x, &a->x, &zi2); + rustsecp256k1zkp_v0_10_0_fe_mul(&r->y, &a->y, &zi3); r->infinity = a->infinity; + + SECP256K1_GE_VERIFY(r); } -static void rustsecp256k1zkp_v0_8_0_ge_set_xy(rustsecp256k1zkp_v0_8_0_ge *r, const rustsecp256k1zkp_v0_8_0_fe *x, const rustsecp256k1zkp_v0_8_0_fe *y) { +static void rustsecp256k1zkp_v0_10_0_ge_set_xy(rustsecp256k1zkp_v0_10_0_ge *r, const rustsecp256k1zkp_v0_10_0_fe *x, const rustsecp256k1zkp_v0_10_0_fe *y) { + SECP256K1_FE_VERIFY(x); + SECP256K1_FE_VERIFY(y); + r->infinity = 0; r->x = *x; r->y = *y; + + SECP256K1_GE_VERIFY(r); } -static int rustsecp256k1zkp_v0_8_0_ge_is_infinity(const rustsecp256k1zkp_v0_8_0_ge *a) { +static int rustsecp256k1zkp_v0_10_0_ge_is_infinity(const rustsecp256k1zkp_v0_10_0_ge *a) { + SECP256K1_GE_VERIFY(a); + return a->infinity; } -static void rustsecp256k1zkp_v0_8_0_ge_neg(rustsecp256k1zkp_v0_8_0_ge *r, const rustsecp256k1zkp_v0_8_0_ge *a) { +static void rustsecp256k1zkp_v0_10_0_ge_neg(rustsecp256k1zkp_v0_10_0_ge *r, const rustsecp256k1zkp_v0_10_0_ge *a) { + SECP256K1_GE_VERIFY(a); + *r = *a; - rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&r->y); - rustsecp256k1zkp_v0_8_0_fe_negate(&r->y, &r->y, 1); + rustsecp256k1zkp_v0_10_0_fe_normalize_weak(&r->y); + rustsecp256k1zkp_v0_10_0_fe_negate(&r->y, &r->y, 1); + + SECP256K1_GE_VERIFY(r); } -static void rustsecp256k1zkp_v0_8_0_ge_set_gej(rustsecp256k1zkp_v0_8_0_ge *r, rustsecp256k1zkp_v0_8_0_gej *a) { - rustsecp256k1zkp_v0_8_0_fe z2, z3; +static void rustsecp256k1zkp_v0_10_0_ge_set_gej(rustsecp256k1zkp_v0_10_0_ge *r, rustsecp256k1zkp_v0_10_0_gej *a) { + rustsecp256k1zkp_v0_10_0_fe z2, z3; + SECP256K1_GEJ_VERIFY(a); + r->infinity = a->infinity; - rustsecp256k1zkp_v0_8_0_fe_inv(&a->z, &a->z); - rustsecp256k1zkp_v0_8_0_fe_sqr(&z2, &a->z); - rustsecp256k1zkp_v0_8_0_fe_mul(&z3, &a->z, &z2); - rustsecp256k1zkp_v0_8_0_fe_mul(&a->x, &a->x, &z2); - rustsecp256k1zkp_v0_8_0_fe_mul(&a->y, &a->y, &z3); - rustsecp256k1zkp_v0_8_0_fe_set_int(&a->z, 1); + rustsecp256k1zkp_v0_10_0_fe_inv(&a->z, &a->z); + rustsecp256k1zkp_v0_10_0_fe_sqr(&z2, &a->z); + rustsecp256k1zkp_v0_10_0_fe_mul(&z3, &a->z, &z2); + rustsecp256k1zkp_v0_10_0_fe_mul(&a->x, &a->x, &z2); + rustsecp256k1zkp_v0_10_0_fe_mul(&a->y, &a->y, &z3); + rustsecp256k1zkp_v0_10_0_fe_set_int(&a->z, 1); r->x = a->x; r->y = a->y; + + SECP256K1_GEJ_VERIFY(a); + SECP256K1_GE_VERIFY(r); } -static void rustsecp256k1zkp_v0_8_0_ge_set_gej_var(rustsecp256k1zkp_v0_8_0_ge *r, rustsecp256k1zkp_v0_8_0_gej *a) { - rustsecp256k1zkp_v0_8_0_fe z2, z3; - if (a->infinity) { - rustsecp256k1zkp_v0_8_0_ge_set_infinity(r); +static void rustsecp256k1zkp_v0_10_0_ge_set_gej_var(rustsecp256k1zkp_v0_10_0_ge *r, rustsecp256k1zkp_v0_10_0_gej *a) { + rustsecp256k1zkp_v0_10_0_fe z2, z3; + SECP256K1_GEJ_VERIFY(a); + + if (rustsecp256k1zkp_v0_10_0_gej_is_infinity(a)) { + rustsecp256k1zkp_v0_10_0_ge_set_infinity(r); return; } - rustsecp256k1zkp_v0_8_0_fe_inv_var(&a->z, &a->z); - rustsecp256k1zkp_v0_8_0_fe_sqr(&z2, &a->z); - rustsecp256k1zkp_v0_8_0_fe_mul(&z3, &a->z, &z2); - rustsecp256k1zkp_v0_8_0_fe_mul(&a->x, &a->x, &z2); - rustsecp256k1zkp_v0_8_0_fe_mul(&a->y, &a->y, &z3); - rustsecp256k1zkp_v0_8_0_fe_set_int(&a->z, 1); - rustsecp256k1zkp_v0_8_0_ge_set_xy(r, &a->x, &a->y); + r->infinity = 0; + rustsecp256k1zkp_v0_10_0_fe_inv_var(&a->z, &a->z); + rustsecp256k1zkp_v0_10_0_fe_sqr(&z2, &a->z); + rustsecp256k1zkp_v0_10_0_fe_mul(&z3, &a->z, &z2); + rustsecp256k1zkp_v0_10_0_fe_mul(&a->x, &a->x, &z2); + rustsecp256k1zkp_v0_10_0_fe_mul(&a->y, &a->y, &z3); + rustsecp256k1zkp_v0_10_0_fe_set_int(&a->z, 1); + rustsecp256k1zkp_v0_10_0_ge_set_xy(r, &a->x, &a->y); + + SECP256K1_GEJ_VERIFY(a); + SECP256K1_GE_VERIFY(r); } -static void rustsecp256k1zkp_v0_8_0_ge_set_all_gej_var(rustsecp256k1zkp_v0_8_0_ge *r, const rustsecp256k1zkp_v0_8_0_gej *a, size_t len) { - rustsecp256k1zkp_v0_8_0_fe u; +static void rustsecp256k1zkp_v0_10_0_ge_set_all_gej_var(rustsecp256k1zkp_v0_10_0_ge *r, const rustsecp256k1zkp_v0_10_0_gej *a, size_t len) { + rustsecp256k1zkp_v0_10_0_fe u; size_t i; size_t last_i = SIZE_MAX; +#ifdef VERIFY + for (i = 0; i < len; i++) { + SECP256K1_GEJ_VERIFY(&a[i]); + } +#endif for (i = 0; i < len; i++) { if (a[i].infinity) { - rustsecp256k1zkp_v0_8_0_ge_set_infinity(&r[i]); + rustsecp256k1zkp_v0_10_0_ge_set_infinity(&r[i]); } else { /* Use destination's x coordinates as scratch space */ if (last_i == SIZE_MAX) { r[i].x = a[i].z; } else { - rustsecp256k1zkp_v0_8_0_fe_mul(&r[i].x, &r[last_i].x, &a[i].z); + rustsecp256k1zkp_v0_10_0_fe_mul(&r[i].x, &r[last_i].x, &a[i].z); } last_i = i; } @@ -140,14 +221,14 @@ static void rustsecp256k1zkp_v0_8_0_ge_set_all_gej_var(rustsecp256k1zkp_v0_8_0_g if (last_i == SIZE_MAX) { return; } - rustsecp256k1zkp_v0_8_0_fe_inv_var(&u, &r[last_i].x); + rustsecp256k1zkp_v0_10_0_fe_inv_var(&u, &r[last_i].x); i = last_i; while (i > 0) { i--; if (!a[i].infinity) { - rustsecp256k1zkp_v0_8_0_fe_mul(&r[last_i].x, &r[i].x, &u); - rustsecp256k1zkp_v0_8_0_fe_mul(&u, &u, &a[last_i].z); + rustsecp256k1zkp_v0_10_0_fe_mul(&r[last_i].x, &r[i].x, &u); + rustsecp256k1zkp_v0_10_0_fe_mul(&u, &u, &a[last_i].z); last_i = i; } } @@ -156,127 +237,209 @@ static void rustsecp256k1zkp_v0_8_0_ge_set_all_gej_var(rustsecp256k1zkp_v0_8_0_g for (i = 0; i < len; i++) { if (!a[i].infinity) { - rustsecp256k1zkp_v0_8_0_ge_set_gej_zinv(&r[i], &a[i], &r[i].x); + rustsecp256k1zkp_v0_10_0_ge_set_gej_zinv(&r[i], &a[i], &r[i].x); } } + +#ifdef VERIFY + for (i = 0; i < len; i++) { + SECP256K1_GE_VERIFY(&r[i]); + } +#endif } -static void rustsecp256k1zkp_v0_8_0_ge_table_set_globalz(size_t len, rustsecp256k1zkp_v0_8_0_ge *a, const rustsecp256k1zkp_v0_8_0_fe *zr) { - size_t i = len - 1; - rustsecp256k1zkp_v0_8_0_fe zs; +static void rustsecp256k1zkp_v0_10_0_ge_table_set_globalz(size_t len, rustsecp256k1zkp_v0_10_0_ge *a, const rustsecp256k1zkp_v0_10_0_fe *zr) { + size_t i; + rustsecp256k1zkp_v0_10_0_fe zs; +#ifdef VERIFY + for (i = 0; i < len; i++) { + SECP256K1_GE_VERIFY(&a[i]); + SECP256K1_FE_VERIFY(&zr[i]); + } +#endif if (len > 0) { + i = len - 1; /* Ensure all y values are in weak normal form for fast negation of points */ - rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&a[i].y); + rustsecp256k1zkp_v0_10_0_fe_normalize_weak(&a[i].y); zs = zr[i]; /* Work our way backwards, using the z-ratios to scale the x/y values. */ while (i > 0) { - rustsecp256k1zkp_v0_8_0_gej tmpa; if (i != len - 1) { - rustsecp256k1zkp_v0_8_0_fe_mul(&zs, &zs, &zr[i]); + rustsecp256k1zkp_v0_10_0_fe_mul(&zs, &zs, &zr[i]); } i--; - tmpa.x = a[i].x; - tmpa.y = a[i].y; - tmpa.infinity = 0; - rustsecp256k1zkp_v0_8_0_ge_set_gej_zinv(&a[i], &tmpa, &zs); + rustsecp256k1zkp_v0_10_0_ge_set_ge_zinv(&a[i], &a[i], &zs); } } + +#ifdef VERIFY + for (i = 0; i < len; i++) { + SECP256K1_GE_VERIFY(&a[i]); + } +#endif } -static void rustsecp256k1zkp_v0_8_0_gej_set_infinity(rustsecp256k1zkp_v0_8_0_gej *r) { +static void rustsecp256k1zkp_v0_10_0_gej_set_infinity(rustsecp256k1zkp_v0_10_0_gej *r) { r->infinity = 1; - rustsecp256k1zkp_v0_8_0_fe_clear(&r->x); - rustsecp256k1zkp_v0_8_0_fe_clear(&r->y); - rustsecp256k1zkp_v0_8_0_fe_clear(&r->z); + rustsecp256k1zkp_v0_10_0_fe_clear(&r->x); + rustsecp256k1zkp_v0_10_0_fe_clear(&r->y); + rustsecp256k1zkp_v0_10_0_fe_clear(&r->z); + + SECP256K1_GEJ_VERIFY(r); } -static void rustsecp256k1zkp_v0_8_0_ge_set_infinity(rustsecp256k1zkp_v0_8_0_ge *r) { +static void rustsecp256k1zkp_v0_10_0_ge_set_infinity(rustsecp256k1zkp_v0_10_0_ge *r) { r->infinity = 1; - rustsecp256k1zkp_v0_8_0_fe_clear(&r->x); - rustsecp256k1zkp_v0_8_0_fe_clear(&r->y); + rustsecp256k1zkp_v0_10_0_fe_clear(&r->x); + rustsecp256k1zkp_v0_10_0_fe_clear(&r->y); + + SECP256K1_GE_VERIFY(r); } -static void rustsecp256k1zkp_v0_8_0_gej_clear(rustsecp256k1zkp_v0_8_0_gej *r) { +static void rustsecp256k1zkp_v0_10_0_gej_clear(rustsecp256k1zkp_v0_10_0_gej *r) { r->infinity = 0; - rustsecp256k1zkp_v0_8_0_fe_clear(&r->x); - rustsecp256k1zkp_v0_8_0_fe_clear(&r->y); - rustsecp256k1zkp_v0_8_0_fe_clear(&r->z); + rustsecp256k1zkp_v0_10_0_fe_clear(&r->x); + rustsecp256k1zkp_v0_10_0_fe_clear(&r->y); + rustsecp256k1zkp_v0_10_0_fe_clear(&r->z); + + SECP256K1_GEJ_VERIFY(r); } -static void rustsecp256k1zkp_v0_8_0_ge_clear(rustsecp256k1zkp_v0_8_0_ge *r) { +static void rustsecp256k1zkp_v0_10_0_ge_clear(rustsecp256k1zkp_v0_10_0_ge *r) { r->infinity = 0; - rustsecp256k1zkp_v0_8_0_fe_clear(&r->x); - rustsecp256k1zkp_v0_8_0_fe_clear(&r->y); + rustsecp256k1zkp_v0_10_0_fe_clear(&r->x); + rustsecp256k1zkp_v0_10_0_fe_clear(&r->y); + + SECP256K1_GE_VERIFY(r); } -static int rustsecp256k1zkp_v0_8_0_ge_set_xquad(rustsecp256k1zkp_v0_8_0_ge *r, const rustsecp256k1zkp_v0_8_0_fe *x) { - rustsecp256k1zkp_v0_8_0_fe x2, x3; +static int rustsecp256k1zkp_v0_10_0_ge_set_xquad(rustsecp256k1zkp_v0_10_0_ge *r, const rustsecp256k1zkp_v0_10_0_fe *x) { + rustsecp256k1zkp_v0_10_0_fe x2, x3; + int ret; + SECP256K1_FE_VERIFY(x); + r->x = *x; - rustsecp256k1zkp_v0_8_0_fe_sqr(&x2, x); - rustsecp256k1zkp_v0_8_0_fe_mul(&x3, x, &x2); + rustsecp256k1zkp_v0_10_0_fe_sqr(&x2, x); + rustsecp256k1zkp_v0_10_0_fe_mul(&x3, x, &x2); r->infinity = 0; - rustsecp256k1zkp_v0_8_0_fe_add(&x3, &rustsecp256k1zkp_v0_8_0_fe_const_b); - return rustsecp256k1zkp_v0_8_0_fe_sqrt(&r->y, &x3); + rustsecp256k1zkp_v0_10_0_fe_add_int(&x3, SECP256K1_B); + ret = rustsecp256k1zkp_v0_10_0_fe_sqrt(&r->y, &x3); + + SECP256K1_GE_VERIFY(r); + return ret; } -static int rustsecp256k1zkp_v0_8_0_ge_set_xo_var(rustsecp256k1zkp_v0_8_0_ge *r, const rustsecp256k1zkp_v0_8_0_fe *x, int odd) { - if (!rustsecp256k1zkp_v0_8_0_ge_set_xquad(r, x)) { - return 0; - } - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&r->y); - if (rustsecp256k1zkp_v0_8_0_fe_is_odd(&r->y) != odd) { - rustsecp256k1zkp_v0_8_0_fe_negate(&r->y, &r->y, 1); +static int rustsecp256k1zkp_v0_10_0_ge_set_xo_var(rustsecp256k1zkp_v0_10_0_ge *r, const rustsecp256k1zkp_v0_10_0_fe *x, int odd) { + int ret; + ret = rustsecp256k1zkp_v0_10_0_ge_set_xquad(r, x); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&r->y); + if (rustsecp256k1zkp_v0_10_0_fe_is_odd(&r->y) != odd) { + rustsecp256k1zkp_v0_10_0_fe_negate(&r->y, &r->y, 1); } - return 1; + SECP256K1_GE_VERIFY(r); + return ret; } -static void rustsecp256k1zkp_v0_8_0_gej_set_ge(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_ge *a) { +static void rustsecp256k1zkp_v0_10_0_gej_set_ge(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_ge *a) { + SECP256K1_GE_VERIFY(a); + r->infinity = a->infinity; r->x = a->x; r->y = a->y; - rustsecp256k1zkp_v0_8_0_fe_set_int(&r->z, 1); + rustsecp256k1zkp_v0_10_0_fe_set_int(&r->z, 1); + + SECP256K1_GEJ_VERIFY(r); +} + +static int rustsecp256k1zkp_v0_10_0_gej_eq_var(const rustsecp256k1zkp_v0_10_0_gej *a, const rustsecp256k1zkp_v0_10_0_gej *b) { + rustsecp256k1zkp_v0_10_0_gej tmp; + SECP256K1_GEJ_VERIFY(b); + SECP256K1_GEJ_VERIFY(a); + + rustsecp256k1zkp_v0_10_0_gej_neg(&tmp, a); + rustsecp256k1zkp_v0_10_0_gej_add_var(&tmp, &tmp, b, NULL); + return rustsecp256k1zkp_v0_10_0_gej_is_infinity(&tmp); +} + +static int rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(const rustsecp256k1zkp_v0_10_0_gej *a, const rustsecp256k1zkp_v0_10_0_ge *b) { + rustsecp256k1zkp_v0_10_0_gej tmp; + SECP256K1_GEJ_VERIFY(a); + SECP256K1_GE_VERIFY(b); + + rustsecp256k1zkp_v0_10_0_gej_neg(&tmp, a); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&tmp, &tmp, b, NULL); + return rustsecp256k1zkp_v0_10_0_gej_is_infinity(&tmp); +} + +static int rustsecp256k1zkp_v0_10_0_ge_eq_var(const rustsecp256k1zkp_v0_10_0_ge *a, const rustsecp256k1zkp_v0_10_0_ge *b) { + rustsecp256k1zkp_v0_10_0_fe tmp; + SECP256K1_GE_VERIFY(a); + SECP256K1_GE_VERIFY(b); + + if (a->infinity != b->infinity) return 0; + if (a->infinity) return 1; + + tmp = a->x; + rustsecp256k1zkp_v0_10_0_fe_normalize_weak(&tmp); + if (!rustsecp256k1zkp_v0_10_0_fe_equal(&tmp, &b->x)) return 0; + + tmp = a->y; + rustsecp256k1zkp_v0_10_0_fe_normalize_weak(&tmp); + if (!rustsecp256k1zkp_v0_10_0_fe_equal(&tmp, &b->y)) return 0; + + return 1; } -static int rustsecp256k1zkp_v0_8_0_gej_eq_x_var(const rustsecp256k1zkp_v0_8_0_fe *x, const rustsecp256k1zkp_v0_8_0_gej *a) { - rustsecp256k1zkp_v0_8_0_fe r, r2; +static int rustsecp256k1zkp_v0_10_0_gej_eq_x_var(const rustsecp256k1zkp_v0_10_0_fe *x, const rustsecp256k1zkp_v0_10_0_gej *a) { + rustsecp256k1zkp_v0_10_0_fe r; + SECP256K1_FE_VERIFY(x); + SECP256K1_GEJ_VERIFY(a); VERIFY_CHECK(!a->infinity); - rustsecp256k1zkp_v0_8_0_fe_sqr(&r, &a->z); rustsecp256k1zkp_v0_8_0_fe_mul(&r, &r, x); - r2 = a->x; rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&r2); - return rustsecp256k1zkp_v0_8_0_fe_equal_var(&r, &r2); + + rustsecp256k1zkp_v0_10_0_fe_sqr(&r, &a->z); rustsecp256k1zkp_v0_10_0_fe_mul(&r, &r, x); + return rustsecp256k1zkp_v0_10_0_fe_equal(&r, &a->x); } -static void rustsecp256k1zkp_v0_8_0_gej_neg(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_gej *a) { +static void rustsecp256k1zkp_v0_10_0_gej_neg(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_gej *a) { + SECP256K1_GEJ_VERIFY(a); + r->infinity = a->infinity; r->x = a->x; r->y = a->y; r->z = a->z; - rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&r->y); - rustsecp256k1zkp_v0_8_0_fe_negate(&r->y, &r->y, 1); + rustsecp256k1zkp_v0_10_0_fe_normalize_weak(&r->y); + rustsecp256k1zkp_v0_10_0_fe_negate(&r->y, &r->y, 1); + + SECP256K1_GEJ_VERIFY(r); } -static int rustsecp256k1zkp_v0_8_0_gej_is_infinity(const rustsecp256k1zkp_v0_8_0_gej *a) { +static int rustsecp256k1zkp_v0_10_0_gej_is_infinity(const rustsecp256k1zkp_v0_10_0_gej *a) { + SECP256K1_GEJ_VERIFY(a); + return a->infinity; } -static int rustsecp256k1zkp_v0_8_0_ge_is_valid_var(const rustsecp256k1zkp_v0_8_0_ge *a) { - rustsecp256k1zkp_v0_8_0_fe y2, x3; +static int rustsecp256k1zkp_v0_10_0_ge_is_valid_var(const rustsecp256k1zkp_v0_10_0_ge *a) { + rustsecp256k1zkp_v0_10_0_fe y2, x3; + SECP256K1_GE_VERIFY(a); + if (a->infinity) { return 0; } /* y^2 = x^3 + 7 */ - rustsecp256k1zkp_v0_8_0_fe_sqr(&y2, &a->y); - rustsecp256k1zkp_v0_8_0_fe_sqr(&x3, &a->x); rustsecp256k1zkp_v0_8_0_fe_mul(&x3, &x3, &a->x); - rustsecp256k1zkp_v0_8_0_fe_add(&x3, &rustsecp256k1zkp_v0_8_0_fe_const_b); - rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&x3); - return rustsecp256k1zkp_v0_8_0_fe_equal_var(&y2, &x3); + rustsecp256k1zkp_v0_10_0_fe_sqr(&y2, &a->y); + rustsecp256k1zkp_v0_10_0_fe_sqr(&x3, &a->x); rustsecp256k1zkp_v0_10_0_fe_mul(&x3, &x3, &a->x); + rustsecp256k1zkp_v0_10_0_fe_add_int(&x3, SECP256K1_B); + return rustsecp256k1zkp_v0_10_0_fe_equal(&y2, &x3); } -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_gej_double(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_gej *a) { +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_gej_double(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_gej *a) { /* Operations: 3 mul, 4 sqr, 8 add/half/mul_int/negate */ - rustsecp256k1zkp_v0_8_0_fe l, s, t; + rustsecp256k1zkp_v0_10_0_fe l, s, t; + SECP256K1_GEJ_VERIFY(a); r->infinity = a->infinity; @@ -289,24 +452,28 @@ static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_gej_double(rustsecp256k1zkp * Z3 = Y1*Z1 */ - rustsecp256k1zkp_v0_8_0_fe_mul(&r->z, &a->z, &a->y); /* Z3 = Y1*Z1 (1) */ - rustsecp256k1zkp_v0_8_0_fe_sqr(&s, &a->y); /* S = Y1^2 (1) */ - rustsecp256k1zkp_v0_8_0_fe_sqr(&l, &a->x); /* L = X1^2 (1) */ - rustsecp256k1zkp_v0_8_0_fe_mul_int(&l, 3); /* L = 3*X1^2 (3) */ - rustsecp256k1zkp_v0_8_0_fe_half(&l); /* L = 3/2*X1^2 (2) */ - rustsecp256k1zkp_v0_8_0_fe_negate(&t, &s, 1); /* T = -S (2) */ - rustsecp256k1zkp_v0_8_0_fe_mul(&t, &t, &a->x); /* T = -X1*S (1) */ - rustsecp256k1zkp_v0_8_0_fe_sqr(&r->x, &l); /* X3 = L^2 (1) */ - rustsecp256k1zkp_v0_8_0_fe_add(&r->x, &t); /* X3 = L^2 + T (2) */ - rustsecp256k1zkp_v0_8_0_fe_add(&r->x, &t); /* X3 = L^2 + 2*T (3) */ - rustsecp256k1zkp_v0_8_0_fe_sqr(&s, &s); /* S' = S^2 (1) */ - rustsecp256k1zkp_v0_8_0_fe_add(&t, &r->x); /* T' = X3 + T (4) */ - rustsecp256k1zkp_v0_8_0_fe_mul(&r->y, &t, &l); /* Y3 = L*(X3 + T) (1) */ - rustsecp256k1zkp_v0_8_0_fe_add(&r->y, &s); /* Y3 = L*(X3 + T) + S^2 (2) */ - rustsecp256k1zkp_v0_8_0_fe_negate(&r->y, &r->y, 2); /* Y3 = -(L*(X3 + T) + S^2) (3) */ -} - -static void rustsecp256k1zkp_v0_8_0_gej_double_var(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_gej *a, rustsecp256k1zkp_v0_8_0_fe *rzr) { + rustsecp256k1zkp_v0_10_0_fe_mul(&r->z, &a->z, &a->y); /* Z3 = Y1*Z1 (1) */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&s, &a->y); /* S = Y1^2 (1) */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&l, &a->x); /* L = X1^2 (1) */ + rustsecp256k1zkp_v0_10_0_fe_mul_int(&l, 3); /* L = 3*X1^2 (3) */ + rustsecp256k1zkp_v0_10_0_fe_half(&l); /* L = 3/2*X1^2 (2) */ + rustsecp256k1zkp_v0_10_0_fe_negate(&t, &s, 1); /* T = -S (2) */ + rustsecp256k1zkp_v0_10_0_fe_mul(&t, &t, &a->x); /* T = -X1*S (1) */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&r->x, &l); /* X3 = L^2 (1) */ + rustsecp256k1zkp_v0_10_0_fe_add(&r->x, &t); /* X3 = L^2 + T (2) */ + rustsecp256k1zkp_v0_10_0_fe_add(&r->x, &t); /* X3 = L^2 + 2*T (3) */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&s, &s); /* S' = S^2 (1) */ + rustsecp256k1zkp_v0_10_0_fe_add(&t, &r->x); /* T' = X3 + T (4) */ + rustsecp256k1zkp_v0_10_0_fe_mul(&r->y, &t, &l); /* Y3 = L*(X3 + T) (1) */ + rustsecp256k1zkp_v0_10_0_fe_add(&r->y, &s); /* Y3 = L*(X3 + T) + S^2 (2) */ + rustsecp256k1zkp_v0_10_0_fe_negate(&r->y, &r->y, 2); /* Y3 = -(L*(X3 + T) + S^2) (3) */ + + SECP256K1_GEJ_VERIFY(r); +} + +static void rustsecp256k1zkp_v0_10_0_gej_double_var(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_gej *a, rustsecp256k1zkp_v0_10_0_fe *rzr) { + SECP256K1_GEJ_VERIFY(a); + /** For secp256k1, 2Q is infinity if and only if Q is infinity. This is because if 2Q = infinity, * Q must equal -Q, or that Q.y == -(Q.y), or Q.y is 0. For a point on y^2 = x^3 + 7 to have * y=0, x^3 must be -7 mod p. However, -7 has no cube root mod p. @@ -318,142 +485,172 @@ static void rustsecp256k1zkp_v0_8_0_gej_double_var(rustsecp256k1zkp_v0_8_0_gej * * point will be gibberish (z = 0 but infinity = 0). */ if (a->infinity) { - rustsecp256k1zkp_v0_8_0_gej_set_infinity(r); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(r); if (rzr != NULL) { - rustsecp256k1zkp_v0_8_0_fe_set_int(rzr, 1); + rustsecp256k1zkp_v0_10_0_fe_set_int(rzr, 1); } return; } if (rzr != NULL) { *rzr = a->y; - rustsecp256k1zkp_v0_8_0_fe_normalize_weak(rzr); + rustsecp256k1zkp_v0_10_0_fe_normalize_weak(rzr); } - rustsecp256k1zkp_v0_8_0_gej_double(r, a); + rustsecp256k1zkp_v0_10_0_gej_double(r, a); + + SECP256K1_GEJ_VERIFY(r); } -static void rustsecp256k1zkp_v0_8_0_gej_add_var(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_gej *a, const rustsecp256k1zkp_v0_8_0_gej *b, rustsecp256k1zkp_v0_8_0_fe *rzr) { - /* Operations: 12 mul, 4 sqr, 2 normalize, 12 mul_int/add/negate */ - rustsecp256k1zkp_v0_8_0_fe z22, z12, u1, u2, s1, s2, h, i, i2, h2, h3, t; +static void rustsecp256k1zkp_v0_10_0_gej_add_var(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_gej *a, const rustsecp256k1zkp_v0_10_0_gej *b, rustsecp256k1zkp_v0_10_0_fe *rzr) { + /* 12 mul, 4 sqr, 11 add/negate/normalizes_to_zero (ignoring special cases) */ + rustsecp256k1zkp_v0_10_0_fe z22, z12, u1, u2, s1, s2, h, i, h2, h3, t; + SECP256K1_GEJ_VERIFY(a); + SECP256K1_GEJ_VERIFY(b); if (a->infinity) { VERIFY_CHECK(rzr == NULL); *r = *b; return; } - if (b->infinity) { if (rzr != NULL) { - rustsecp256k1zkp_v0_8_0_fe_set_int(rzr, 1); + rustsecp256k1zkp_v0_10_0_fe_set_int(rzr, 1); } *r = *a; return; } - r->infinity = 0; - rustsecp256k1zkp_v0_8_0_fe_sqr(&z22, &b->z); - rustsecp256k1zkp_v0_8_0_fe_sqr(&z12, &a->z); - rustsecp256k1zkp_v0_8_0_fe_mul(&u1, &a->x, &z22); - rustsecp256k1zkp_v0_8_0_fe_mul(&u2, &b->x, &z12); - rustsecp256k1zkp_v0_8_0_fe_mul(&s1, &a->y, &z22); rustsecp256k1zkp_v0_8_0_fe_mul(&s1, &s1, &b->z); - rustsecp256k1zkp_v0_8_0_fe_mul(&s2, &b->y, &z12); rustsecp256k1zkp_v0_8_0_fe_mul(&s2, &s2, &a->z); - rustsecp256k1zkp_v0_8_0_fe_negate(&h, &u1, 1); rustsecp256k1zkp_v0_8_0_fe_add(&h, &u2); - rustsecp256k1zkp_v0_8_0_fe_negate(&i, &s1, 1); rustsecp256k1zkp_v0_8_0_fe_add(&i, &s2); - if (rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero_var(&h)) { - if (rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero_var(&i)) { - rustsecp256k1zkp_v0_8_0_gej_double_var(r, a, rzr); + rustsecp256k1zkp_v0_10_0_fe_sqr(&z22, &b->z); + rustsecp256k1zkp_v0_10_0_fe_sqr(&z12, &a->z); + rustsecp256k1zkp_v0_10_0_fe_mul(&u1, &a->x, &z22); + rustsecp256k1zkp_v0_10_0_fe_mul(&u2, &b->x, &z12); + rustsecp256k1zkp_v0_10_0_fe_mul(&s1, &a->y, &z22); rustsecp256k1zkp_v0_10_0_fe_mul(&s1, &s1, &b->z); + rustsecp256k1zkp_v0_10_0_fe_mul(&s2, &b->y, &z12); rustsecp256k1zkp_v0_10_0_fe_mul(&s2, &s2, &a->z); + rustsecp256k1zkp_v0_10_0_fe_negate(&h, &u1, 1); rustsecp256k1zkp_v0_10_0_fe_add(&h, &u2); + rustsecp256k1zkp_v0_10_0_fe_negate(&i, &s2, 1); rustsecp256k1zkp_v0_10_0_fe_add(&i, &s1); + if (rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(&h)) { + if (rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(&i)) { + rustsecp256k1zkp_v0_10_0_gej_double_var(r, a, rzr); } else { if (rzr != NULL) { - rustsecp256k1zkp_v0_8_0_fe_set_int(rzr, 0); + rustsecp256k1zkp_v0_10_0_fe_set_int(rzr, 0); } - rustsecp256k1zkp_v0_8_0_gej_set_infinity(r); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(r); } return; } - rustsecp256k1zkp_v0_8_0_fe_sqr(&i2, &i); - rustsecp256k1zkp_v0_8_0_fe_sqr(&h2, &h); - rustsecp256k1zkp_v0_8_0_fe_mul(&h3, &h, &h2); - rustsecp256k1zkp_v0_8_0_fe_mul(&h, &h, &b->z); + + r->infinity = 0; + rustsecp256k1zkp_v0_10_0_fe_mul(&t, &h, &b->z); if (rzr != NULL) { - *rzr = h; + *rzr = t; } - rustsecp256k1zkp_v0_8_0_fe_mul(&r->z, &a->z, &h); - rustsecp256k1zkp_v0_8_0_fe_mul(&t, &u1, &h2); - r->x = t; rustsecp256k1zkp_v0_8_0_fe_mul_int(&r->x, 2); rustsecp256k1zkp_v0_8_0_fe_add(&r->x, &h3); rustsecp256k1zkp_v0_8_0_fe_negate(&r->x, &r->x, 3); rustsecp256k1zkp_v0_8_0_fe_add(&r->x, &i2); - rustsecp256k1zkp_v0_8_0_fe_negate(&r->y, &r->x, 5); rustsecp256k1zkp_v0_8_0_fe_add(&r->y, &t); rustsecp256k1zkp_v0_8_0_fe_mul(&r->y, &r->y, &i); - rustsecp256k1zkp_v0_8_0_fe_mul(&h3, &h3, &s1); rustsecp256k1zkp_v0_8_0_fe_negate(&h3, &h3, 1); - rustsecp256k1zkp_v0_8_0_fe_add(&r->y, &h3); + rustsecp256k1zkp_v0_10_0_fe_mul(&r->z, &a->z, &t); + + rustsecp256k1zkp_v0_10_0_fe_sqr(&h2, &h); + rustsecp256k1zkp_v0_10_0_fe_negate(&h2, &h2, 1); + rustsecp256k1zkp_v0_10_0_fe_mul(&h3, &h2, &h); + rustsecp256k1zkp_v0_10_0_fe_mul(&t, &u1, &h2); + + rustsecp256k1zkp_v0_10_0_fe_sqr(&r->x, &i); + rustsecp256k1zkp_v0_10_0_fe_add(&r->x, &h3); + rustsecp256k1zkp_v0_10_0_fe_add(&r->x, &t); + rustsecp256k1zkp_v0_10_0_fe_add(&r->x, &t); + + rustsecp256k1zkp_v0_10_0_fe_add(&t, &r->x); + rustsecp256k1zkp_v0_10_0_fe_mul(&r->y, &t, &i); + rustsecp256k1zkp_v0_10_0_fe_mul(&h3, &h3, &s1); + rustsecp256k1zkp_v0_10_0_fe_add(&r->y, &h3); + + SECP256K1_GEJ_VERIFY(r); } -static void rustsecp256k1zkp_v0_8_0_gej_add_ge_var(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_gej *a, const rustsecp256k1zkp_v0_8_0_ge *b, rustsecp256k1zkp_v0_8_0_fe *rzr) { - /* 8 mul, 3 sqr, 4 normalize, 12 mul_int/add/negate */ - rustsecp256k1zkp_v0_8_0_fe z12, u1, u2, s1, s2, h, i, i2, h2, h3, t; +static void rustsecp256k1zkp_v0_10_0_gej_add_ge_var(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_gej *a, const rustsecp256k1zkp_v0_10_0_ge *b, rustsecp256k1zkp_v0_10_0_fe *rzr) { + /* Operations: 8 mul, 3 sqr, 11 add/negate/normalizes_to_zero (ignoring special cases) */ + rustsecp256k1zkp_v0_10_0_fe z12, u1, u2, s1, s2, h, i, h2, h3, t; + SECP256K1_GEJ_VERIFY(a); + SECP256K1_GE_VERIFY(b); + if (a->infinity) { VERIFY_CHECK(rzr == NULL); - rustsecp256k1zkp_v0_8_0_gej_set_ge(r, b); + rustsecp256k1zkp_v0_10_0_gej_set_ge(r, b); return; } if (b->infinity) { if (rzr != NULL) { - rustsecp256k1zkp_v0_8_0_fe_set_int(rzr, 1); + rustsecp256k1zkp_v0_10_0_fe_set_int(rzr, 1); } *r = *a; return; } - r->infinity = 0; - rustsecp256k1zkp_v0_8_0_fe_sqr(&z12, &a->z); - u1 = a->x; rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&u1); - rustsecp256k1zkp_v0_8_0_fe_mul(&u2, &b->x, &z12); - s1 = a->y; rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&s1); - rustsecp256k1zkp_v0_8_0_fe_mul(&s2, &b->y, &z12); rustsecp256k1zkp_v0_8_0_fe_mul(&s2, &s2, &a->z); - rustsecp256k1zkp_v0_8_0_fe_negate(&h, &u1, 1); rustsecp256k1zkp_v0_8_0_fe_add(&h, &u2); - rustsecp256k1zkp_v0_8_0_fe_negate(&i, &s1, 1); rustsecp256k1zkp_v0_8_0_fe_add(&i, &s2); - if (rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero_var(&h)) { - if (rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero_var(&i)) { - rustsecp256k1zkp_v0_8_0_gej_double_var(r, a, rzr); + rustsecp256k1zkp_v0_10_0_fe_sqr(&z12, &a->z); + u1 = a->x; + rustsecp256k1zkp_v0_10_0_fe_mul(&u2, &b->x, &z12); + s1 = a->y; + rustsecp256k1zkp_v0_10_0_fe_mul(&s2, &b->y, &z12); rustsecp256k1zkp_v0_10_0_fe_mul(&s2, &s2, &a->z); + rustsecp256k1zkp_v0_10_0_fe_negate(&h, &u1, SECP256K1_GEJ_X_MAGNITUDE_MAX); rustsecp256k1zkp_v0_10_0_fe_add(&h, &u2); + rustsecp256k1zkp_v0_10_0_fe_negate(&i, &s2, 1); rustsecp256k1zkp_v0_10_0_fe_add(&i, &s1); + if (rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(&h)) { + if (rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(&i)) { + rustsecp256k1zkp_v0_10_0_gej_double_var(r, a, rzr); } else { if (rzr != NULL) { - rustsecp256k1zkp_v0_8_0_fe_set_int(rzr, 0); + rustsecp256k1zkp_v0_10_0_fe_set_int(rzr, 0); } - rustsecp256k1zkp_v0_8_0_gej_set_infinity(r); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(r); } return; } - rustsecp256k1zkp_v0_8_0_fe_sqr(&i2, &i); - rustsecp256k1zkp_v0_8_0_fe_sqr(&h2, &h); - rustsecp256k1zkp_v0_8_0_fe_mul(&h3, &h, &h2); + + r->infinity = 0; if (rzr != NULL) { *rzr = h; } - rustsecp256k1zkp_v0_8_0_fe_mul(&r->z, &a->z, &h); - rustsecp256k1zkp_v0_8_0_fe_mul(&t, &u1, &h2); - r->x = t; rustsecp256k1zkp_v0_8_0_fe_mul_int(&r->x, 2); rustsecp256k1zkp_v0_8_0_fe_add(&r->x, &h3); rustsecp256k1zkp_v0_8_0_fe_negate(&r->x, &r->x, 3); rustsecp256k1zkp_v0_8_0_fe_add(&r->x, &i2); - rustsecp256k1zkp_v0_8_0_fe_negate(&r->y, &r->x, 5); rustsecp256k1zkp_v0_8_0_fe_add(&r->y, &t); rustsecp256k1zkp_v0_8_0_fe_mul(&r->y, &r->y, &i); - rustsecp256k1zkp_v0_8_0_fe_mul(&h3, &h3, &s1); rustsecp256k1zkp_v0_8_0_fe_negate(&h3, &h3, 1); - rustsecp256k1zkp_v0_8_0_fe_add(&r->y, &h3); + rustsecp256k1zkp_v0_10_0_fe_mul(&r->z, &a->z, &h); + + rustsecp256k1zkp_v0_10_0_fe_sqr(&h2, &h); + rustsecp256k1zkp_v0_10_0_fe_negate(&h2, &h2, 1); + rustsecp256k1zkp_v0_10_0_fe_mul(&h3, &h2, &h); + rustsecp256k1zkp_v0_10_0_fe_mul(&t, &u1, &h2); + + rustsecp256k1zkp_v0_10_0_fe_sqr(&r->x, &i); + rustsecp256k1zkp_v0_10_0_fe_add(&r->x, &h3); + rustsecp256k1zkp_v0_10_0_fe_add(&r->x, &t); + rustsecp256k1zkp_v0_10_0_fe_add(&r->x, &t); + + rustsecp256k1zkp_v0_10_0_fe_add(&t, &r->x); + rustsecp256k1zkp_v0_10_0_fe_mul(&r->y, &t, &i); + rustsecp256k1zkp_v0_10_0_fe_mul(&h3, &h3, &s1); + rustsecp256k1zkp_v0_10_0_fe_add(&r->y, &h3); + + SECP256K1_GEJ_VERIFY(r); + if (rzr != NULL) SECP256K1_FE_VERIFY(rzr); } -static void rustsecp256k1zkp_v0_8_0_gej_add_zinv_var(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_gej *a, const rustsecp256k1zkp_v0_8_0_ge *b, const rustsecp256k1zkp_v0_8_0_fe *bzinv) { - /* 9 mul, 3 sqr, 4 normalize, 12 mul_int/add/negate */ - rustsecp256k1zkp_v0_8_0_fe az, z12, u1, u2, s1, s2, h, i, i2, h2, h3, t; +static void rustsecp256k1zkp_v0_10_0_gej_add_zinv_var(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_gej *a, const rustsecp256k1zkp_v0_10_0_ge *b, const rustsecp256k1zkp_v0_10_0_fe *bzinv) { + /* Operations: 9 mul, 3 sqr, 11 add/negate/normalizes_to_zero (ignoring special cases) */ + rustsecp256k1zkp_v0_10_0_fe az, z12, u1, u2, s1, s2, h, i, h2, h3, t; + SECP256K1_GEJ_VERIFY(a); + SECP256K1_GE_VERIFY(b); + SECP256K1_FE_VERIFY(bzinv); - if (b->infinity) { - *r = *a; - return; - } if (a->infinity) { - rustsecp256k1zkp_v0_8_0_fe bzinv2, bzinv3; + rustsecp256k1zkp_v0_10_0_fe bzinv2, bzinv3; r->infinity = b->infinity; - rustsecp256k1zkp_v0_8_0_fe_sqr(&bzinv2, bzinv); - rustsecp256k1zkp_v0_8_0_fe_mul(&bzinv3, &bzinv2, bzinv); - rustsecp256k1zkp_v0_8_0_fe_mul(&r->x, &b->x, &bzinv2); - rustsecp256k1zkp_v0_8_0_fe_mul(&r->y, &b->y, &bzinv3); - rustsecp256k1zkp_v0_8_0_fe_set_int(&r->z, 1); + rustsecp256k1zkp_v0_10_0_fe_sqr(&bzinv2, bzinv); + rustsecp256k1zkp_v0_10_0_fe_mul(&bzinv3, &bzinv2, bzinv); + rustsecp256k1zkp_v0_10_0_fe_mul(&r->x, &b->x, &bzinv2); + rustsecp256k1zkp_v0_10_0_fe_mul(&r->y, &b->y, &bzinv3); + rustsecp256k1zkp_v0_10_0_fe_set_int(&r->z, 1); + SECP256K1_GEJ_VERIFY(r); + return; + } + if (b->infinity) { + *r = *a; return; } - r->infinity = 0; /** We need to calculate (rx,ry,rz) = (ax,ay,az) + (bx,by,1/bzinv). Due to * secp256k1's isomorphism we can multiply the Z coordinates on both sides @@ -463,44 +660,56 @@ static void rustsecp256k1zkp_v0_8_0_gej_add_zinv_var(rustsecp256k1zkp_v0_8_0_gej * The variable az below holds the modified Z coordinate for a, which is used * for the computation of rx and ry, but not for rz. */ - rustsecp256k1zkp_v0_8_0_fe_mul(&az, &a->z, bzinv); - - rustsecp256k1zkp_v0_8_0_fe_sqr(&z12, &az); - u1 = a->x; rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&u1); - rustsecp256k1zkp_v0_8_0_fe_mul(&u2, &b->x, &z12); - s1 = a->y; rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&s1); - rustsecp256k1zkp_v0_8_0_fe_mul(&s2, &b->y, &z12); rustsecp256k1zkp_v0_8_0_fe_mul(&s2, &s2, &az); - rustsecp256k1zkp_v0_8_0_fe_negate(&h, &u1, 1); rustsecp256k1zkp_v0_8_0_fe_add(&h, &u2); - rustsecp256k1zkp_v0_8_0_fe_negate(&i, &s1, 1); rustsecp256k1zkp_v0_8_0_fe_add(&i, &s2); - if (rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero_var(&h)) { - if (rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero_var(&i)) { - rustsecp256k1zkp_v0_8_0_gej_double_var(r, a, NULL); + rustsecp256k1zkp_v0_10_0_fe_mul(&az, &a->z, bzinv); + + rustsecp256k1zkp_v0_10_0_fe_sqr(&z12, &az); + u1 = a->x; + rustsecp256k1zkp_v0_10_0_fe_mul(&u2, &b->x, &z12); + s1 = a->y; + rustsecp256k1zkp_v0_10_0_fe_mul(&s2, &b->y, &z12); rustsecp256k1zkp_v0_10_0_fe_mul(&s2, &s2, &az); + rustsecp256k1zkp_v0_10_0_fe_negate(&h, &u1, SECP256K1_GEJ_X_MAGNITUDE_MAX); rustsecp256k1zkp_v0_10_0_fe_add(&h, &u2); + rustsecp256k1zkp_v0_10_0_fe_negate(&i, &s2, 1); rustsecp256k1zkp_v0_10_0_fe_add(&i, &s1); + if (rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(&h)) { + if (rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(&i)) { + rustsecp256k1zkp_v0_10_0_gej_double_var(r, a, NULL); } else { - rustsecp256k1zkp_v0_8_0_gej_set_infinity(r); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(r); } return; } - rustsecp256k1zkp_v0_8_0_fe_sqr(&i2, &i); - rustsecp256k1zkp_v0_8_0_fe_sqr(&h2, &h); - rustsecp256k1zkp_v0_8_0_fe_mul(&h3, &h, &h2); - r->z = a->z; rustsecp256k1zkp_v0_8_0_fe_mul(&r->z, &r->z, &h); - rustsecp256k1zkp_v0_8_0_fe_mul(&t, &u1, &h2); - r->x = t; rustsecp256k1zkp_v0_8_0_fe_mul_int(&r->x, 2); rustsecp256k1zkp_v0_8_0_fe_add(&r->x, &h3); rustsecp256k1zkp_v0_8_0_fe_negate(&r->x, &r->x, 3); rustsecp256k1zkp_v0_8_0_fe_add(&r->x, &i2); - rustsecp256k1zkp_v0_8_0_fe_negate(&r->y, &r->x, 5); rustsecp256k1zkp_v0_8_0_fe_add(&r->y, &t); rustsecp256k1zkp_v0_8_0_fe_mul(&r->y, &r->y, &i); - rustsecp256k1zkp_v0_8_0_fe_mul(&h3, &h3, &s1); rustsecp256k1zkp_v0_8_0_fe_negate(&h3, &h3, 1); - rustsecp256k1zkp_v0_8_0_fe_add(&r->y, &h3); -} - - -static void rustsecp256k1zkp_v0_8_0_gej_add_ge(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_gej *a, const rustsecp256k1zkp_v0_8_0_ge *b) { - /* Operations: 7 mul, 5 sqr, 24 add/cmov/half/mul_int/negate/normalize_weak/normalizes_to_zero */ - rustsecp256k1zkp_v0_8_0_fe zz, u1, u2, s1, s2, t, tt, m, n, q, rr; - rustsecp256k1zkp_v0_8_0_fe m_alt, rr_alt; - int infinity, degenerate; + + r->infinity = 0; + rustsecp256k1zkp_v0_10_0_fe_mul(&r->z, &a->z, &h); + + rustsecp256k1zkp_v0_10_0_fe_sqr(&h2, &h); + rustsecp256k1zkp_v0_10_0_fe_negate(&h2, &h2, 1); + rustsecp256k1zkp_v0_10_0_fe_mul(&h3, &h2, &h); + rustsecp256k1zkp_v0_10_0_fe_mul(&t, &u1, &h2); + + rustsecp256k1zkp_v0_10_0_fe_sqr(&r->x, &i); + rustsecp256k1zkp_v0_10_0_fe_add(&r->x, &h3); + rustsecp256k1zkp_v0_10_0_fe_add(&r->x, &t); + rustsecp256k1zkp_v0_10_0_fe_add(&r->x, &t); + + rustsecp256k1zkp_v0_10_0_fe_add(&t, &r->x); + rustsecp256k1zkp_v0_10_0_fe_mul(&r->y, &t, &i); + rustsecp256k1zkp_v0_10_0_fe_mul(&h3, &h3, &s1); + rustsecp256k1zkp_v0_10_0_fe_add(&r->y, &h3); + + SECP256K1_GEJ_VERIFY(r); +} + + +static void rustsecp256k1zkp_v0_10_0_gej_add_ge(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_gej *a, const rustsecp256k1zkp_v0_10_0_ge *b) { + /* Operations: 7 mul, 5 sqr, 21 add/cmov/half/mul_int/negate/normalizes_to_zero */ + rustsecp256k1zkp_v0_10_0_fe zz, u1, u2, s1, s2, t, tt, m, n, q, rr; + rustsecp256k1zkp_v0_10_0_fe m_alt, rr_alt; + int degenerate; + SECP256K1_GEJ_VERIFY(a); + SECP256K1_GE_VERIFY(b); VERIFY_CHECK(!b->infinity); - VERIFY_CHECK(a->infinity == 0 || a->infinity == 1); - /** In: + /* In: * Eric Brier and Marc Joye, Weierstrass Elliptic Curves and Side-Channel Attacks. * In D. Naccache and P. Paillier, Eds., Public Key Cryptography, vol. 2274 of Lecture Notes in Computer Science, pages 335-345. Springer-Verlag, 2002. * we find as solution for a unified addition/doubling formula: @@ -550,113 +759,149 @@ static void rustsecp256k1zkp_v0_8_0_gej_add_ge(rustsecp256k1zkp_v0_8_0_gej *r, c * so this covers everything. */ - rustsecp256k1zkp_v0_8_0_fe_sqr(&zz, &a->z); /* z = Z1^2 */ - u1 = a->x; rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&u1); /* u1 = U1 = X1*Z2^2 (1) */ - rustsecp256k1zkp_v0_8_0_fe_mul(&u2, &b->x, &zz); /* u2 = U2 = X2*Z1^2 (1) */ - s1 = a->y; rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&s1); /* s1 = S1 = Y1*Z2^3 (1) */ - rustsecp256k1zkp_v0_8_0_fe_mul(&s2, &b->y, &zz); /* s2 = Y2*Z1^2 (1) */ - rustsecp256k1zkp_v0_8_0_fe_mul(&s2, &s2, &a->z); /* s2 = S2 = Y2*Z1^3 (1) */ - t = u1; rustsecp256k1zkp_v0_8_0_fe_add(&t, &u2); /* t = T = U1+U2 (2) */ - m = s1; rustsecp256k1zkp_v0_8_0_fe_add(&m, &s2); /* m = M = S1+S2 (2) */ - rustsecp256k1zkp_v0_8_0_fe_sqr(&rr, &t); /* rr = T^2 (1) */ - rustsecp256k1zkp_v0_8_0_fe_negate(&m_alt, &u2, 1); /* Malt = -X2*Z1^2 */ - rustsecp256k1zkp_v0_8_0_fe_mul(&tt, &u1, &m_alt); /* tt = -U1*U2 (2) */ - rustsecp256k1zkp_v0_8_0_fe_add(&rr, &tt); /* rr = R = T^2-U1*U2 (3) */ - /** If lambda = R/M = 0/0 we have a problem (except in the "trivial" - * case that Z = z1z2 = 0, and this is special-cased later on). */ - degenerate = rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero(&m) & - rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero(&rr); + rustsecp256k1zkp_v0_10_0_fe_sqr(&zz, &a->z); /* z = Z1^2 */ + u1 = a->x; /* u1 = U1 = X1*Z2^2 (GEJ_X_M) */ + rustsecp256k1zkp_v0_10_0_fe_mul(&u2, &b->x, &zz); /* u2 = U2 = X2*Z1^2 (1) */ + s1 = a->y; /* s1 = S1 = Y1*Z2^3 (GEJ_Y_M) */ + rustsecp256k1zkp_v0_10_0_fe_mul(&s2, &b->y, &zz); /* s2 = Y2*Z1^2 (1) */ + rustsecp256k1zkp_v0_10_0_fe_mul(&s2, &s2, &a->z); /* s2 = S2 = Y2*Z1^3 (1) */ + t = u1; rustsecp256k1zkp_v0_10_0_fe_add(&t, &u2); /* t = T = U1+U2 (GEJ_X_M+1) */ + m = s1; rustsecp256k1zkp_v0_10_0_fe_add(&m, &s2); /* m = M = S1+S2 (GEJ_Y_M+1) */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&rr, &t); /* rr = T^2 (1) */ + rustsecp256k1zkp_v0_10_0_fe_negate(&m_alt, &u2, 1); /* Malt = -X2*Z1^2 (2) */ + rustsecp256k1zkp_v0_10_0_fe_mul(&tt, &u1, &m_alt); /* tt = -U1*U2 (1) */ + rustsecp256k1zkp_v0_10_0_fe_add(&rr, &tt); /* rr = R = T^2-U1*U2 (2) */ + /* If lambda = R/M = R/0 we have a problem (except in the "trivial" + * case that Z = z1z2 = 0, and this is special-cased later on). */ + degenerate = rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero(&m); /* This only occurs when y1 == -y2 and x1^3 == x2^3, but x1 != x2. * This means either x1 == beta*x2 or beta*x1 == x2, where beta is * a nontrivial cube root of one. In either case, an alternate * non-indeterminate expression for lambda is (y1 - y2)/(x1 - x2), * so we set R/M equal to this. */ rr_alt = s1; - rustsecp256k1zkp_v0_8_0_fe_mul_int(&rr_alt, 2); /* rr = Y1*Z2^3 - Y2*Z1^3 (2) */ - rustsecp256k1zkp_v0_8_0_fe_add(&m_alt, &u1); /* Malt = X1*Z2^2 - X2*Z1^2 */ + rustsecp256k1zkp_v0_10_0_fe_mul_int(&rr_alt, 2); /* rr_alt = Y1*Z2^3 - Y2*Z1^3 (GEJ_Y_M*2) */ + rustsecp256k1zkp_v0_10_0_fe_add(&m_alt, &u1); /* Malt = X1*Z2^2 - X2*Z1^2 (GEJ_X_M+2) */ - rustsecp256k1zkp_v0_8_0_fe_cmov(&rr_alt, &rr, !degenerate); - rustsecp256k1zkp_v0_8_0_fe_cmov(&m_alt, &m, !degenerate); - /* Now Ralt / Malt = lambda and is guaranteed not to be 0/0. + rustsecp256k1zkp_v0_10_0_fe_cmov(&rr_alt, &rr, !degenerate); /* rr_alt (GEJ_Y_M*2) */ + rustsecp256k1zkp_v0_10_0_fe_cmov(&m_alt, &m, !degenerate); /* m_alt (GEJ_X_M+2) */ + /* Now Ralt / Malt = lambda and is guaranteed not to be Ralt / 0. * From here on out Ralt and Malt represent the numerator * and denominator of lambda; R and M represent the explicit * expressions x1^2 + x2^2 + x1x2 and y1 + y2. */ - rustsecp256k1zkp_v0_8_0_fe_sqr(&n, &m_alt); /* n = Malt^2 (1) */ - rustsecp256k1zkp_v0_8_0_fe_negate(&q, &t, 2); /* q = -T (3) */ - rustsecp256k1zkp_v0_8_0_fe_mul(&q, &q, &n); /* q = Q = -T*Malt^2 (1) */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&n, &m_alt); /* n = Malt^2 (1) */ + rustsecp256k1zkp_v0_10_0_fe_negate(&q, &t, + SECP256K1_GEJ_X_MAGNITUDE_MAX + 1); /* q = -T (GEJ_X_M+2) */ + rustsecp256k1zkp_v0_10_0_fe_mul(&q, &q, &n); /* q = Q = -T*Malt^2 (1) */ /* These two lines use the observation that either M == Malt or M == 0, * so M^3 * Malt is either Malt^4 (which is computed by squaring), or * zero (which is "computed" by cmov). So the cost is one squaring * versus two multiplications. */ - rustsecp256k1zkp_v0_8_0_fe_sqr(&n, &n); - rustsecp256k1zkp_v0_8_0_fe_cmov(&n, &m, degenerate); /* n = M^3 * Malt (2) */ - rustsecp256k1zkp_v0_8_0_fe_sqr(&t, &rr_alt); /* t = Ralt^2 (1) */ - rustsecp256k1zkp_v0_8_0_fe_mul(&r->z, &a->z, &m_alt); /* r->z = Z3 = Malt*Z (1) */ - infinity = rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero(&r->z) & ~a->infinity; - rustsecp256k1zkp_v0_8_0_fe_add(&t, &q); /* t = Ralt^2 + Q (2) */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&n, &n); /* n = Malt^4 (1) */ + rustsecp256k1zkp_v0_10_0_fe_cmov(&n, &m, degenerate); /* n = M^3 * Malt (GEJ_Y_M+1) */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&t, &rr_alt); /* t = Ralt^2 (1) */ + rustsecp256k1zkp_v0_10_0_fe_mul(&r->z, &a->z, &m_alt); /* r->z = Z3 = Malt*Z (1) */ + rustsecp256k1zkp_v0_10_0_fe_add(&t, &q); /* t = Ralt^2 + Q (2) */ r->x = t; /* r->x = X3 = Ralt^2 + Q (2) */ - rustsecp256k1zkp_v0_8_0_fe_mul_int(&t, 2); /* t = 2*X3 (4) */ - rustsecp256k1zkp_v0_8_0_fe_add(&t, &q); /* t = 2*X3 + Q (5) */ - rustsecp256k1zkp_v0_8_0_fe_mul(&t, &t, &rr_alt); /* t = Ralt*(2*X3 + Q) (1) */ - rustsecp256k1zkp_v0_8_0_fe_add(&t, &n); /* t = Ralt*(2*X3 + Q) + M^3*Malt (3) */ - rustsecp256k1zkp_v0_8_0_fe_negate(&r->y, &t, 3); /* r->y = -(Ralt*(2*X3 + Q) + M^3*Malt) (4) */ - rustsecp256k1zkp_v0_8_0_fe_half(&r->y); /* r->y = Y3 = -(Ralt*(2*X3 + Q) + M^3*Malt)/2 (3) */ + rustsecp256k1zkp_v0_10_0_fe_mul_int(&t, 2); /* t = 2*X3 (4) */ + rustsecp256k1zkp_v0_10_0_fe_add(&t, &q); /* t = 2*X3 + Q (5) */ + rustsecp256k1zkp_v0_10_0_fe_mul(&t, &t, &rr_alt); /* t = Ralt*(2*X3 + Q) (1) */ + rustsecp256k1zkp_v0_10_0_fe_add(&t, &n); /* t = Ralt*(2*X3 + Q) + M^3*Malt (GEJ_Y_M+2) */ + rustsecp256k1zkp_v0_10_0_fe_negate(&r->y, &t, + SECP256K1_GEJ_Y_MAGNITUDE_MAX + 2); /* r->y = -(Ralt*(2*X3 + Q) + M^3*Malt) (GEJ_Y_M+3) */ + rustsecp256k1zkp_v0_10_0_fe_half(&r->y); /* r->y = Y3 = -(Ralt*(2*X3 + Q) + M^3*Malt)/2 ((GEJ_Y_M+3)/2 + 1) */ + + /* In case a->infinity == 1, replace r with (b->x, b->y, 1). */ + rustsecp256k1zkp_v0_10_0_fe_cmov(&r->x, &b->x, a->infinity); + rustsecp256k1zkp_v0_10_0_fe_cmov(&r->y, &b->y, a->infinity); + rustsecp256k1zkp_v0_10_0_fe_cmov(&r->z, &rustsecp256k1zkp_v0_10_0_fe_one, a->infinity); + + /* Set r->infinity if r->z is 0. + * + * If a->infinity is set, then r->infinity = (r->z == 0) = (1 == 0) = false, + * which is correct because the function assumes that b is not infinity. + * + * Now assume !a->infinity. This implies Z = Z1 != 0. + * + * Case y1 = -y2: + * In this case we could have a = -b, namely if x1 = x2. + * We have degenerate = true, r->z = (x1 - x2) * Z. + * Then r->infinity = ((x1 - x2)Z == 0) = (x1 == x2) = (a == -b). + * + * Case y1 != -y2: + * In this case, we can't have a = -b. + * We have degenerate = false, r->z = (y1 + y2) * Z. + * Then r->infinity = ((y1 + y2)Z == 0) = (y1 == -y2) = false. */ + r->infinity = rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero(&r->z); - /** In case a->infinity == 1, replace r with (b->x, b->y, 1). */ - rustsecp256k1zkp_v0_8_0_fe_cmov(&r->x, &b->x, a->infinity); - rustsecp256k1zkp_v0_8_0_fe_cmov(&r->y, &b->y, a->infinity); - rustsecp256k1zkp_v0_8_0_fe_cmov(&r->z, &rustsecp256k1zkp_v0_8_0_fe_one, a->infinity); - r->infinity = infinity; + SECP256K1_GEJ_VERIFY(r); } -static void rustsecp256k1zkp_v0_8_0_gej_rescale(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_fe *s) { +static void rustsecp256k1zkp_v0_10_0_gej_rescale(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_fe *s) { /* Operations: 4 mul, 1 sqr */ - rustsecp256k1zkp_v0_8_0_fe zz; - VERIFY_CHECK(!rustsecp256k1zkp_v0_8_0_fe_is_zero(s)); - rustsecp256k1zkp_v0_8_0_fe_sqr(&zz, s); - rustsecp256k1zkp_v0_8_0_fe_mul(&r->x, &r->x, &zz); /* r->x *= s^2 */ - rustsecp256k1zkp_v0_8_0_fe_mul(&r->y, &r->y, &zz); - rustsecp256k1zkp_v0_8_0_fe_mul(&r->y, &r->y, s); /* r->y *= s^3 */ - rustsecp256k1zkp_v0_8_0_fe_mul(&r->z, &r->z, s); /* r->z *= s */ + rustsecp256k1zkp_v0_10_0_fe zz; + SECP256K1_GEJ_VERIFY(r); + SECP256K1_FE_VERIFY(s); + VERIFY_CHECK(!rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(s)); + + rustsecp256k1zkp_v0_10_0_fe_sqr(&zz, s); + rustsecp256k1zkp_v0_10_0_fe_mul(&r->x, &r->x, &zz); /* r->x *= s^2 */ + rustsecp256k1zkp_v0_10_0_fe_mul(&r->y, &r->y, &zz); + rustsecp256k1zkp_v0_10_0_fe_mul(&r->y, &r->y, s); /* r->y *= s^3 */ + rustsecp256k1zkp_v0_10_0_fe_mul(&r->z, &r->z, s); /* r->z *= s */ + + SECP256K1_GEJ_VERIFY(r); } -static void rustsecp256k1zkp_v0_8_0_ge_to_storage(rustsecp256k1zkp_v0_8_0_ge_storage *r, const rustsecp256k1zkp_v0_8_0_ge *a) { - rustsecp256k1zkp_v0_8_0_fe x, y; +static void rustsecp256k1zkp_v0_10_0_ge_to_storage(rustsecp256k1zkp_v0_10_0_ge_storage *r, const rustsecp256k1zkp_v0_10_0_ge *a) { + rustsecp256k1zkp_v0_10_0_fe x, y; + SECP256K1_GE_VERIFY(a); VERIFY_CHECK(!a->infinity); + x = a->x; - rustsecp256k1zkp_v0_8_0_fe_normalize(&x); + rustsecp256k1zkp_v0_10_0_fe_normalize(&x); y = a->y; - rustsecp256k1zkp_v0_8_0_fe_normalize(&y); - rustsecp256k1zkp_v0_8_0_fe_to_storage(&r->x, &x); - rustsecp256k1zkp_v0_8_0_fe_to_storage(&r->y, &y); + rustsecp256k1zkp_v0_10_0_fe_normalize(&y); + rustsecp256k1zkp_v0_10_0_fe_to_storage(&r->x, &x); + rustsecp256k1zkp_v0_10_0_fe_to_storage(&r->y, &y); } -static void rustsecp256k1zkp_v0_8_0_ge_from_storage(rustsecp256k1zkp_v0_8_0_ge *r, const rustsecp256k1zkp_v0_8_0_ge_storage *a) { - rustsecp256k1zkp_v0_8_0_fe_from_storage(&r->x, &a->x); - rustsecp256k1zkp_v0_8_0_fe_from_storage(&r->y, &a->y); +static void rustsecp256k1zkp_v0_10_0_ge_from_storage(rustsecp256k1zkp_v0_10_0_ge *r, const rustsecp256k1zkp_v0_10_0_ge_storage *a) { + rustsecp256k1zkp_v0_10_0_fe_from_storage(&r->x, &a->x); + rustsecp256k1zkp_v0_10_0_fe_from_storage(&r->y, &a->y); r->infinity = 0; + + SECP256K1_GE_VERIFY(r); } -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_gej_cmov(rustsecp256k1zkp_v0_8_0_gej *r, const rustsecp256k1zkp_v0_8_0_gej *a, int flag) { - rustsecp256k1zkp_v0_8_0_fe_cmov(&r->x, &a->x, flag); - rustsecp256k1zkp_v0_8_0_fe_cmov(&r->y, &a->y, flag); - rustsecp256k1zkp_v0_8_0_fe_cmov(&r->z, &a->z, flag); +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_gej_cmov(rustsecp256k1zkp_v0_10_0_gej *r, const rustsecp256k1zkp_v0_10_0_gej *a, int flag) { + SECP256K1_GEJ_VERIFY(r); + SECP256K1_GEJ_VERIFY(a); + rustsecp256k1zkp_v0_10_0_fe_cmov(&r->x, &a->x, flag); + rustsecp256k1zkp_v0_10_0_fe_cmov(&r->y, &a->y, flag); + rustsecp256k1zkp_v0_10_0_fe_cmov(&r->z, &a->z, flag); r->infinity ^= (r->infinity ^ a->infinity) & flag; + + SECP256K1_GEJ_VERIFY(r); } -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_ge_storage_cmov(rustsecp256k1zkp_v0_8_0_ge_storage *r, const rustsecp256k1zkp_v0_8_0_ge_storage *a, int flag) { - rustsecp256k1zkp_v0_8_0_fe_storage_cmov(&r->x, &a->x, flag); - rustsecp256k1zkp_v0_8_0_fe_storage_cmov(&r->y, &a->y, flag); +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_ge_storage_cmov(rustsecp256k1zkp_v0_10_0_ge_storage *r, const rustsecp256k1zkp_v0_10_0_ge_storage *a, int flag) { + rustsecp256k1zkp_v0_10_0_fe_storage_cmov(&r->x, &a->x, flag); + rustsecp256k1zkp_v0_10_0_fe_storage_cmov(&r->y, &a->y, flag); } -static void rustsecp256k1zkp_v0_8_0_ge_mul_lambda(rustsecp256k1zkp_v0_8_0_ge *r, const rustsecp256k1zkp_v0_8_0_ge *a) { +static void rustsecp256k1zkp_v0_10_0_ge_mul_lambda(rustsecp256k1zkp_v0_10_0_ge *r, const rustsecp256k1zkp_v0_10_0_ge *a) { + SECP256K1_GE_VERIFY(a); + *r = *a; - rustsecp256k1zkp_v0_8_0_fe_mul(&r->x, &r->x, &rustsecp256k1zkp_v0_8_0_const_beta); + rustsecp256k1zkp_v0_10_0_fe_mul(&r->x, &r->x, &rustsecp256k1zkp_v0_10_0_const_beta); + + SECP256K1_GE_VERIFY(r); } -static int rustsecp256k1zkp_v0_8_0_gej_has_quad_y_var(const rustsecp256k1zkp_v0_8_0_gej *a) { - rustsecp256k1zkp_v0_8_0_fe yz; +static int rustsecp256k1zkp_v0_10_0_gej_has_quad_y_var(const rustsecp256k1zkp_v0_10_0_gej *a) { + rustsecp256k1zkp_v0_10_0_fe yz; if (a->infinity) { return 0; @@ -665,29 +910,79 @@ static int rustsecp256k1zkp_v0_8_0_gej_has_quad_y_var(const rustsecp256k1zkp_v0_ /* We rely on the fact that the Jacobi symbol of 1 / a->z^3 is the same as * that of a->z. Thus a->y / a->z^3 is a quadratic residue iff a->y * a->z is */ - rustsecp256k1zkp_v0_8_0_fe_mul(&yz, &a->y, &a->z); - return rustsecp256k1zkp_v0_8_0_fe_is_quad_var(&yz); + rustsecp256k1zkp_v0_10_0_fe_mul(&yz, &a->y, &a->z); + return rustsecp256k1zkp_v0_10_0_fe_is_square_var(&yz); } -static int rustsecp256k1zkp_v0_8_0_ge_is_in_correct_subgroup(const rustsecp256k1zkp_v0_8_0_ge* ge) { +static int rustsecp256k1zkp_v0_10_0_ge_is_in_correct_subgroup(const rustsecp256k1zkp_v0_10_0_ge* ge) { #ifdef EXHAUSTIVE_TEST_ORDER - rustsecp256k1zkp_v0_8_0_gej out; + rustsecp256k1zkp_v0_10_0_gej out; int i; + SECP256K1_GE_VERIFY(ge); /* A very simple EC multiplication ladder that avoids a dependency on ecmult. */ - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&out); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&out); for (i = 0; i < 32; ++i) { - rustsecp256k1zkp_v0_8_0_gej_double_var(&out, &out, NULL); + rustsecp256k1zkp_v0_10_0_gej_double_var(&out, &out, NULL); if ((((uint32_t)EXHAUSTIVE_TEST_ORDER) >> (31 - i)) & 1) { - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&out, &out, ge, NULL); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&out, &out, ge, NULL); } } - return rustsecp256k1zkp_v0_8_0_gej_is_infinity(&out); + return rustsecp256k1zkp_v0_10_0_gej_is_infinity(&out); #else + SECP256K1_GE_VERIFY(ge); + (void)ge; /* The real secp256k1 group has cofactor 1, so the subgroup is the entire curve. */ return 1; #endif } +static int rustsecp256k1zkp_v0_10_0_ge_x_on_curve_var(const rustsecp256k1zkp_v0_10_0_fe *x) { + rustsecp256k1zkp_v0_10_0_fe c; + rustsecp256k1zkp_v0_10_0_fe_sqr(&c, x); + rustsecp256k1zkp_v0_10_0_fe_mul(&c, &c, x); + rustsecp256k1zkp_v0_10_0_fe_add_int(&c, SECP256K1_B); + return rustsecp256k1zkp_v0_10_0_fe_is_square_var(&c); +} + +static int rustsecp256k1zkp_v0_10_0_ge_x_frac_on_curve_var(const rustsecp256k1zkp_v0_10_0_fe *xn, const rustsecp256k1zkp_v0_10_0_fe *xd) { + /* We want to determine whether (xn/xd) is on the curve. + * + * (xn/xd)^3 + 7 is square <=> xd*xn^3 + 7*xd^4 is square (multiplying by xd^4, a square). + */ + rustsecp256k1zkp_v0_10_0_fe r, t; + VERIFY_CHECK(!rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(xd)); + + rustsecp256k1zkp_v0_10_0_fe_mul(&r, xd, xn); /* r = xd*xn */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&t, xn); /* t = xn^2 */ + rustsecp256k1zkp_v0_10_0_fe_mul(&r, &r, &t); /* r = xd*xn^3 */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&t, xd); /* t = xd^2 */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&t, &t); /* t = xd^4 */ + VERIFY_CHECK(SECP256K1_B <= 31); + rustsecp256k1zkp_v0_10_0_fe_mul_int(&t, SECP256K1_B); /* t = 7*xd^4 */ + rustsecp256k1zkp_v0_10_0_fe_add(&r, &t); /* r = xd*xn^3 + 7*xd^4 */ + return rustsecp256k1zkp_v0_10_0_fe_is_square_var(&r); +} + +static void rustsecp256k1zkp_v0_10_0_ge_to_bytes(unsigned char *buf, rustsecp256k1zkp_v0_10_0_ge *a) { + rustsecp256k1zkp_v0_10_0_ge_storage s; + + /* We require that the rustsecp256k1zkp_v0_10_0_ge_storage type is exactly 64 bytes. + * This is formally not guaranteed by the C standard, but should hold on any + * sane compiler in the real world. */ + STATIC_ASSERT(sizeof(rustsecp256k1zkp_v0_10_0_ge_storage) == 64); + VERIFY_CHECK(!rustsecp256k1zkp_v0_10_0_ge_is_infinity(a)); + rustsecp256k1zkp_v0_10_0_ge_to_storage(&s, a); + memcpy(buf, &s, 64); +} + +static void rustsecp256k1zkp_v0_10_0_ge_from_bytes(rustsecp256k1zkp_v0_10_0_ge *r, const unsigned char *buf) { + rustsecp256k1zkp_v0_10_0_ge_storage s; + + STATIC_ASSERT(sizeof(rustsecp256k1zkp_v0_10_0_ge_storage) == 64); + memcpy(&s, buf, 64); + rustsecp256k1zkp_v0_10_0_ge_from_storage(r, &s); +} + #endif /* SECP256K1_GROUP_IMPL_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/hash.h b/secp256k1-zkp-sys/depend/secp256k1/src/hash.h index ef21b5b3..2511f224 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/hash.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/hash.h @@ -14,28 +14,28 @@ typedef struct { uint32_t s[8]; unsigned char buf[64]; uint64_t bytes; -} rustsecp256k1zkp_v0_8_0_sha256; +} rustsecp256k1zkp_v0_10_0_sha256; -static void rustsecp256k1zkp_v0_8_0_sha256_initialize(rustsecp256k1zkp_v0_8_0_sha256 *hash); -static void rustsecp256k1zkp_v0_8_0_sha256_write(rustsecp256k1zkp_v0_8_0_sha256 *hash, const unsigned char *data, size_t size); -static void rustsecp256k1zkp_v0_8_0_sha256_finalize(rustsecp256k1zkp_v0_8_0_sha256 *hash, unsigned char *out32); +static void rustsecp256k1zkp_v0_10_0_sha256_initialize(rustsecp256k1zkp_v0_10_0_sha256 *hash); +static void rustsecp256k1zkp_v0_10_0_sha256_write(rustsecp256k1zkp_v0_10_0_sha256 *hash, const unsigned char *data, size_t size); +static void rustsecp256k1zkp_v0_10_0_sha256_finalize(rustsecp256k1zkp_v0_10_0_sha256 *hash, unsigned char *out32); typedef struct { - rustsecp256k1zkp_v0_8_0_sha256 inner, outer; -} rustsecp256k1zkp_v0_8_0_hmac_sha256; + rustsecp256k1zkp_v0_10_0_sha256 inner, outer; +} rustsecp256k1zkp_v0_10_0_hmac_sha256; -static void rustsecp256k1zkp_v0_8_0_hmac_sha256_initialize(rustsecp256k1zkp_v0_8_0_hmac_sha256 *hash, const unsigned char *key, size_t size); -static void rustsecp256k1zkp_v0_8_0_hmac_sha256_write(rustsecp256k1zkp_v0_8_0_hmac_sha256 *hash, const unsigned char *data, size_t size); -static void rustsecp256k1zkp_v0_8_0_hmac_sha256_finalize(rustsecp256k1zkp_v0_8_0_hmac_sha256 *hash, unsigned char *out32); +static void rustsecp256k1zkp_v0_10_0_hmac_sha256_initialize(rustsecp256k1zkp_v0_10_0_hmac_sha256 *hash, const unsigned char *key, size_t size); +static void rustsecp256k1zkp_v0_10_0_hmac_sha256_write(rustsecp256k1zkp_v0_10_0_hmac_sha256 *hash, const unsigned char *data, size_t size); +static void rustsecp256k1zkp_v0_10_0_hmac_sha256_finalize(rustsecp256k1zkp_v0_10_0_hmac_sha256 *hash, unsigned char *out32); typedef struct { unsigned char v[32]; unsigned char k[32]; int retry; -} rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256; +} rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256; -static void rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_initialize(rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256 *rng, const unsigned char *key, size_t keylen); -static void rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_generate(rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256 *rng, unsigned char *out, size_t outlen); -static void rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_finalize(rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256 *rng); +static void rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_initialize(rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256 *rng, const unsigned char *key, size_t keylen); +static void rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_generate(rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256 *rng, unsigned char *out, size_t outlen); +static void rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_finalize(rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256 *rng); #endif /* SECP256K1_HASH_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/hash_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/hash_impl.h index 780021af..1a0a8e89 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/hash_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/hash_impl.h @@ -28,7 +28,7 @@ (h) = t1 + t2; \ } while(0) -static void rustsecp256k1zkp_v0_8_0_sha256_initialize(rustsecp256k1zkp_v0_8_0_sha256 *hash) { +static void rustsecp256k1zkp_v0_10_0_sha256_initialize(rustsecp256k1zkp_v0_10_0_sha256 *hash) { hash->s[0] = 0x6a09e667ul; hash->s[1] = 0xbb67ae85ul; hash->s[2] = 0x3c6ef372ul; @@ -41,26 +41,26 @@ static void rustsecp256k1zkp_v0_8_0_sha256_initialize(rustsecp256k1zkp_v0_8_0_sh } /** Perform one SHA-256 transformation, processing 16 big endian 32-bit words. */ -static void rustsecp256k1zkp_v0_8_0_sha256_transform(uint32_t* s, const unsigned char* buf) { +static void rustsecp256k1zkp_v0_10_0_sha256_transform(uint32_t* s, const unsigned char* buf) { uint32_t a = s[0], b = s[1], c = s[2], d = s[3], e = s[4], f = s[5], g = s[6], h = s[7]; uint32_t w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15; - Round(a, b, c, d, e, f, g, h, 0x428a2f98, w0 = rustsecp256k1zkp_v0_8_0_read_be32(&buf[0])); - Round(h, a, b, c, d, e, f, g, 0x71374491, w1 = rustsecp256k1zkp_v0_8_0_read_be32(&buf[4])); - Round(g, h, a, b, c, d, e, f, 0xb5c0fbcf, w2 = rustsecp256k1zkp_v0_8_0_read_be32(&buf[8])); - Round(f, g, h, a, b, c, d, e, 0xe9b5dba5, w3 = rustsecp256k1zkp_v0_8_0_read_be32(&buf[12])); - Round(e, f, g, h, a, b, c, d, 0x3956c25b, w4 = rustsecp256k1zkp_v0_8_0_read_be32(&buf[16])); - Round(d, e, f, g, h, a, b, c, 0x59f111f1, w5 = rustsecp256k1zkp_v0_8_0_read_be32(&buf[20])); - Round(c, d, e, f, g, h, a, b, 0x923f82a4, w6 = rustsecp256k1zkp_v0_8_0_read_be32(&buf[24])); - Round(b, c, d, e, f, g, h, a, 0xab1c5ed5, w7 = rustsecp256k1zkp_v0_8_0_read_be32(&buf[28])); - Round(a, b, c, d, e, f, g, h, 0xd807aa98, w8 = rustsecp256k1zkp_v0_8_0_read_be32(&buf[32])); - Round(h, a, b, c, d, e, f, g, 0x12835b01, w9 = rustsecp256k1zkp_v0_8_0_read_be32(&buf[36])); - Round(g, h, a, b, c, d, e, f, 0x243185be, w10 = rustsecp256k1zkp_v0_8_0_read_be32(&buf[40])); - Round(f, g, h, a, b, c, d, e, 0x550c7dc3, w11 = rustsecp256k1zkp_v0_8_0_read_be32(&buf[44])); - Round(e, f, g, h, a, b, c, d, 0x72be5d74, w12 = rustsecp256k1zkp_v0_8_0_read_be32(&buf[48])); - Round(d, e, f, g, h, a, b, c, 0x80deb1fe, w13 = rustsecp256k1zkp_v0_8_0_read_be32(&buf[52])); - Round(c, d, e, f, g, h, a, b, 0x9bdc06a7, w14 = rustsecp256k1zkp_v0_8_0_read_be32(&buf[56])); - Round(b, c, d, e, f, g, h, a, 0xc19bf174, w15 = rustsecp256k1zkp_v0_8_0_read_be32(&buf[60])); + Round(a, b, c, d, e, f, g, h, 0x428a2f98, w0 = rustsecp256k1zkp_v0_10_0_read_be32(&buf[0])); + Round(h, a, b, c, d, e, f, g, 0x71374491, w1 = rustsecp256k1zkp_v0_10_0_read_be32(&buf[4])); + Round(g, h, a, b, c, d, e, f, 0xb5c0fbcf, w2 = rustsecp256k1zkp_v0_10_0_read_be32(&buf[8])); + Round(f, g, h, a, b, c, d, e, 0xe9b5dba5, w3 = rustsecp256k1zkp_v0_10_0_read_be32(&buf[12])); + Round(e, f, g, h, a, b, c, d, 0x3956c25b, w4 = rustsecp256k1zkp_v0_10_0_read_be32(&buf[16])); + Round(d, e, f, g, h, a, b, c, 0x59f111f1, w5 = rustsecp256k1zkp_v0_10_0_read_be32(&buf[20])); + Round(c, d, e, f, g, h, a, b, 0x923f82a4, w6 = rustsecp256k1zkp_v0_10_0_read_be32(&buf[24])); + Round(b, c, d, e, f, g, h, a, 0xab1c5ed5, w7 = rustsecp256k1zkp_v0_10_0_read_be32(&buf[28])); + Round(a, b, c, d, e, f, g, h, 0xd807aa98, w8 = rustsecp256k1zkp_v0_10_0_read_be32(&buf[32])); + Round(h, a, b, c, d, e, f, g, 0x12835b01, w9 = rustsecp256k1zkp_v0_10_0_read_be32(&buf[36])); + Round(g, h, a, b, c, d, e, f, 0x243185be, w10 = rustsecp256k1zkp_v0_10_0_read_be32(&buf[40])); + Round(f, g, h, a, b, c, d, e, 0x550c7dc3, w11 = rustsecp256k1zkp_v0_10_0_read_be32(&buf[44])); + Round(e, f, g, h, a, b, c, d, 0x72be5d74, w12 = rustsecp256k1zkp_v0_10_0_read_be32(&buf[48])); + Round(d, e, f, g, h, a, b, c, 0x80deb1fe, w13 = rustsecp256k1zkp_v0_10_0_read_be32(&buf[52])); + Round(c, d, e, f, g, h, a, b, 0x9bdc06a7, w14 = rustsecp256k1zkp_v0_10_0_read_be32(&buf[56])); + Round(b, c, d, e, f, g, h, a, 0xc19bf174, w15 = rustsecp256k1zkp_v0_10_0_read_be32(&buf[60])); Round(a, b, c, d, e, f, g, h, 0xe49b69c1, w0 += sigma1(w14) + w9 + sigma0(w1)); Round(h, a, b, c, d, e, f, g, 0xefbe4786, w1 += sigma1(w15) + w10 + sigma0(w2)); @@ -123,7 +123,7 @@ static void rustsecp256k1zkp_v0_8_0_sha256_transform(uint32_t* s, const unsigned s[7] += h; } -static void rustsecp256k1zkp_v0_8_0_sha256_write(rustsecp256k1zkp_v0_8_0_sha256 *hash, const unsigned char *data, size_t len) { +static void rustsecp256k1zkp_v0_10_0_sha256_write(rustsecp256k1zkp_v0_10_0_sha256 *hash, const unsigned char *data, size_t len) { size_t bufsize = hash->bytes & 0x3F; hash->bytes += len; VERIFY_CHECK(hash->bytes >= len); @@ -133,87 +133,87 @@ static void rustsecp256k1zkp_v0_8_0_sha256_write(rustsecp256k1zkp_v0_8_0_sha256 memcpy(hash->buf + bufsize, data, chunk_len); data += chunk_len; len -= chunk_len; - rustsecp256k1zkp_v0_8_0_sha256_transform(hash->s, hash->buf); + rustsecp256k1zkp_v0_10_0_sha256_transform(hash->s, hash->buf); bufsize = 0; } if (len) { /* Fill the buffer with what remains. */ - memcpy(((unsigned char*)hash->buf) + bufsize, data, len); + memcpy(hash->buf + bufsize, data, len); } } -static void rustsecp256k1zkp_v0_8_0_sha256_finalize(rustsecp256k1zkp_v0_8_0_sha256 *hash, unsigned char *out32) { +static void rustsecp256k1zkp_v0_10_0_sha256_finalize(rustsecp256k1zkp_v0_10_0_sha256 *hash, unsigned char *out32) { static const unsigned char pad[64] = {0x80}; unsigned char sizedesc[8]; int i; /* The maximum message size of SHA256 is 2^64-1 bits. */ VERIFY_CHECK(hash->bytes < ((uint64_t)1 << 61)); - rustsecp256k1zkp_v0_8_0_write_be32(&sizedesc[0], hash->bytes >> 29); - rustsecp256k1zkp_v0_8_0_write_be32(&sizedesc[4], hash->bytes << 3); - rustsecp256k1zkp_v0_8_0_sha256_write(hash, pad, 1 + ((119 - (hash->bytes % 64)) % 64)); - rustsecp256k1zkp_v0_8_0_sha256_write(hash, sizedesc, 8); + rustsecp256k1zkp_v0_10_0_write_be32(&sizedesc[0], hash->bytes >> 29); + rustsecp256k1zkp_v0_10_0_write_be32(&sizedesc[4], hash->bytes << 3); + rustsecp256k1zkp_v0_10_0_sha256_write(hash, pad, 1 + ((119 - (hash->bytes % 64)) % 64)); + rustsecp256k1zkp_v0_10_0_sha256_write(hash, sizedesc, 8); for (i = 0; i < 8; i++) { - rustsecp256k1zkp_v0_8_0_write_be32(&out32[4*i], hash->s[i]); + rustsecp256k1zkp_v0_10_0_write_be32(&out32[4*i], hash->s[i]); hash->s[i] = 0; } } /* Initializes a sha256 struct and writes the 64 byte string * SHA256(tag)||SHA256(tag) into it. */ -static void rustsecp256k1zkp_v0_8_0_sha256_initialize_tagged(rustsecp256k1zkp_v0_8_0_sha256 *hash, const unsigned char *tag, size_t taglen) { +static void rustsecp256k1zkp_v0_10_0_sha256_initialize_tagged(rustsecp256k1zkp_v0_10_0_sha256 *hash, const unsigned char *tag, size_t taglen) { unsigned char buf[32]; - rustsecp256k1zkp_v0_8_0_sha256_initialize(hash); - rustsecp256k1zkp_v0_8_0_sha256_write(hash, tag, taglen); - rustsecp256k1zkp_v0_8_0_sha256_finalize(hash, buf); + rustsecp256k1zkp_v0_10_0_sha256_initialize(hash); + rustsecp256k1zkp_v0_10_0_sha256_write(hash, tag, taglen); + rustsecp256k1zkp_v0_10_0_sha256_finalize(hash, buf); - rustsecp256k1zkp_v0_8_0_sha256_initialize(hash); - rustsecp256k1zkp_v0_8_0_sha256_write(hash, buf, 32); - rustsecp256k1zkp_v0_8_0_sha256_write(hash, buf, 32); + rustsecp256k1zkp_v0_10_0_sha256_initialize(hash); + rustsecp256k1zkp_v0_10_0_sha256_write(hash, buf, 32); + rustsecp256k1zkp_v0_10_0_sha256_write(hash, buf, 32); } -static void rustsecp256k1zkp_v0_8_0_hmac_sha256_initialize(rustsecp256k1zkp_v0_8_0_hmac_sha256 *hash, const unsigned char *key, size_t keylen) { +static void rustsecp256k1zkp_v0_10_0_hmac_sha256_initialize(rustsecp256k1zkp_v0_10_0_hmac_sha256 *hash, const unsigned char *key, size_t keylen) { size_t n; unsigned char rkey[64]; if (keylen <= sizeof(rkey)) { memcpy(rkey, key, keylen); memset(rkey + keylen, 0, sizeof(rkey) - keylen); } else { - rustsecp256k1zkp_v0_8_0_sha256 sha256; - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha256); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256, key, keylen); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha256, rkey); + rustsecp256k1zkp_v0_10_0_sha256 sha256; + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha256); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256, key, keylen); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha256, rkey); memset(rkey + 32, 0, 32); } - rustsecp256k1zkp_v0_8_0_sha256_initialize(&hash->outer); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&hash->outer); for (n = 0; n < sizeof(rkey); n++) { rkey[n] ^= 0x5c; } - rustsecp256k1zkp_v0_8_0_sha256_write(&hash->outer, rkey, sizeof(rkey)); + rustsecp256k1zkp_v0_10_0_sha256_write(&hash->outer, rkey, sizeof(rkey)); - rustsecp256k1zkp_v0_8_0_sha256_initialize(&hash->inner); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&hash->inner); for (n = 0; n < sizeof(rkey); n++) { rkey[n] ^= 0x5c ^ 0x36; } - rustsecp256k1zkp_v0_8_0_sha256_write(&hash->inner, rkey, sizeof(rkey)); + rustsecp256k1zkp_v0_10_0_sha256_write(&hash->inner, rkey, sizeof(rkey)); memset(rkey, 0, sizeof(rkey)); } -static void rustsecp256k1zkp_v0_8_0_hmac_sha256_write(rustsecp256k1zkp_v0_8_0_hmac_sha256 *hash, const unsigned char *data, size_t size) { - rustsecp256k1zkp_v0_8_0_sha256_write(&hash->inner, data, size); +static void rustsecp256k1zkp_v0_10_0_hmac_sha256_write(rustsecp256k1zkp_v0_10_0_hmac_sha256 *hash, const unsigned char *data, size_t size) { + rustsecp256k1zkp_v0_10_0_sha256_write(&hash->inner, data, size); } -static void rustsecp256k1zkp_v0_8_0_hmac_sha256_finalize(rustsecp256k1zkp_v0_8_0_hmac_sha256 *hash, unsigned char *out32) { +static void rustsecp256k1zkp_v0_10_0_hmac_sha256_finalize(rustsecp256k1zkp_v0_10_0_hmac_sha256 *hash, unsigned char *out32) { unsigned char temp[32]; - rustsecp256k1zkp_v0_8_0_sha256_finalize(&hash->inner, temp); - rustsecp256k1zkp_v0_8_0_sha256_write(&hash->outer, temp, 32); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&hash->inner, temp); + rustsecp256k1zkp_v0_10_0_sha256_write(&hash->outer, temp, 32); memset(temp, 0, 32); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&hash->outer, out32); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&hash->outer, out32); } -static void rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_initialize(rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256 *rng, const unsigned char *key, size_t keylen) { - rustsecp256k1zkp_v0_8_0_hmac_sha256 hmac; +static void rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_initialize(rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256 *rng, const unsigned char *key, size_t keylen) { + rustsecp256k1zkp_v0_10_0_hmac_sha256 hmac; static const unsigned char zero[1] = {0x00}; static const unsigned char one[1] = {0x01}; @@ -221,47 +221,47 @@ static void rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_initialize(rustsecp256k1 memset(rng->k, 0x00, 32); /* RFC6979 3.2.c. */ /* RFC6979 3.2.d. */ - rustsecp256k1zkp_v0_8_0_hmac_sha256_initialize(&hmac, rng->k, 32); - rustsecp256k1zkp_v0_8_0_hmac_sha256_write(&hmac, rng->v, 32); - rustsecp256k1zkp_v0_8_0_hmac_sha256_write(&hmac, zero, 1); - rustsecp256k1zkp_v0_8_0_hmac_sha256_write(&hmac, key, keylen); - rustsecp256k1zkp_v0_8_0_hmac_sha256_finalize(&hmac, rng->k); - rustsecp256k1zkp_v0_8_0_hmac_sha256_initialize(&hmac, rng->k, 32); - rustsecp256k1zkp_v0_8_0_hmac_sha256_write(&hmac, rng->v, 32); - rustsecp256k1zkp_v0_8_0_hmac_sha256_finalize(&hmac, rng->v); + rustsecp256k1zkp_v0_10_0_hmac_sha256_initialize(&hmac, rng->k, 32); + rustsecp256k1zkp_v0_10_0_hmac_sha256_write(&hmac, rng->v, 32); + rustsecp256k1zkp_v0_10_0_hmac_sha256_write(&hmac, zero, 1); + rustsecp256k1zkp_v0_10_0_hmac_sha256_write(&hmac, key, keylen); + rustsecp256k1zkp_v0_10_0_hmac_sha256_finalize(&hmac, rng->k); + rustsecp256k1zkp_v0_10_0_hmac_sha256_initialize(&hmac, rng->k, 32); + rustsecp256k1zkp_v0_10_0_hmac_sha256_write(&hmac, rng->v, 32); + rustsecp256k1zkp_v0_10_0_hmac_sha256_finalize(&hmac, rng->v); /* RFC6979 3.2.f. */ - rustsecp256k1zkp_v0_8_0_hmac_sha256_initialize(&hmac, rng->k, 32); - rustsecp256k1zkp_v0_8_0_hmac_sha256_write(&hmac, rng->v, 32); - rustsecp256k1zkp_v0_8_0_hmac_sha256_write(&hmac, one, 1); - rustsecp256k1zkp_v0_8_0_hmac_sha256_write(&hmac, key, keylen); - rustsecp256k1zkp_v0_8_0_hmac_sha256_finalize(&hmac, rng->k); - rustsecp256k1zkp_v0_8_0_hmac_sha256_initialize(&hmac, rng->k, 32); - rustsecp256k1zkp_v0_8_0_hmac_sha256_write(&hmac, rng->v, 32); - rustsecp256k1zkp_v0_8_0_hmac_sha256_finalize(&hmac, rng->v); + rustsecp256k1zkp_v0_10_0_hmac_sha256_initialize(&hmac, rng->k, 32); + rustsecp256k1zkp_v0_10_0_hmac_sha256_write(&hmac, rng->v, 32); + rustsecp256k1zkp_v0_10_0_hmac_sha256_write(&hmac, one, 1); + rustsecp256k1zkp_v0_10_0_hmac_sha256_write(&hmac, key, keylen); + rustsecp256k1zkp_v0_10_0_hmac_sha256_finalize(&hmac, rng->k); + rustsecp256k1zkp_v0_10_0_hmac_sha256_initialize(&hmac, rng->k, 32); + rustsecp256k1zkp_v0_10_0_hmac_sha256_write(&hmac, rng->v, 32); + rustsecp256k1zkp_v0_10_0_hmac_sha256_finalize(&hmac, rng->v); rng->retry = 0; } -static void rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_generate(rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256 *rng, unsigned char *out, size_t outlen) { +static void rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_generate(rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256 *rng, unsigned char *out, size_t outlen) { /* RFC6979 3.2.h. */ static const unsigned char zero[1] = {0x00}; if (rng->retry) { - rustsecp256k1zkp_v0_8_0_hmac_sha256 hmac; - rustsecp256k1zkp_v0_8_0_hmac_sha256_initialize(&hmac, rng->k, 32); - rustsecp256k1zkp_v0_8_0_hmac_sha256_write(&hmac, rng->v, 32); - rustsecp256k1zkp_v0_8_0_hmac_sha256_write(&hmac, zero, 1); - rustsecp256k1zkp_v0_8_0_hmac_sha256_finalize(&hmac, rng->k); - rustsecp256k1zkp_v0_8_0_hmac_sha256_initialize(&hmac, rng->k, 32); - rustsecp256k1zkp_v0_8_0_hmac_sha256_write(&hmac, rng->v, 32); - rustsecp256k1zkp_v0_8_0_hmac_sha256_finalize(&hmac, rng->v); + rustsecp256k1zkp_v0_10_0_hmac_sha256 hmac; + rustsecp256k1zkp_v0_10_0_hmac_sha256_initialize(&hmac, rng->k, 32); + rustsecp256k1zkp_v0_10_0_hmac_sha256_write(&hmac, rng->v, 32); + rustsecp256k1zkp_v0_10_0_hmac_sha256_write(&hmac, zero, 1); + rustsecp256k1zkp_v0_10_0_hmac_sha256_finalize(&hmac, rng->k); + rustsecp256k1zkp_v0_10_0_hmac_sha256_initialize(&hmac, rng->k, 32); + rustsecp256k1zkp_v0_10_0_hmac_sha256_write(&hmac, rng->v, 32); + rustsecp256k1zkp_v0_10_0_hmac_sha256_finalize(&hmac, rng->v); } while (outlen > 0) { - rustsecp256k1zkp_v0_8_0_hmac_sha256 hmac; + rustsecp256k1zkp_v0_10_0_hmac_sha256 hmac; int now = outlen; - rustsecp256k1zkp_v0_8_0_hmac_sha256_initialize(&hmac, rng->k, 32); - rustsecp256k1zkp_v0_8_0_hmac_sha256_write(&hmac, rng->v, 32); - rustsecp256k1zkp_v0_8_0_hmac_sha256_finalize(&hmac, rng->v); + rustsecp256k1zkp_v0_10_0_hmac_sha256_initialize(&hmac, rng->k, 32); + rustsecp256k1zkp_v0_10_0_hmac_sha256_write(&hmac, rng->v, 32); + rustsecp256k1zkp_v0_10_0_hmac_sha256_finalize(&hmac, rng->v); if (now > 32) { now = 32; } @@ -273,7 +273,7 @@ static void rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_generate(rustsecp256k1zk rng->retry = 1; } -static void rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_finalize(rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256 *rng) { +static void rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_finalize(rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256 *rng) { memset(rng->k, 0, 32); memset(rng->v, 0, 32); rng->retry = 0; diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/int128.h b/secp256k1-zkp-sys/depend/secp256k1/src/int128.h new file mode 100644 index 00000000..a72fec12 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/int128.h @@ -0,0 +1,90 @@ +#ifndef SECP256K1_INT128_H +#define SECP256K1_INT128_H + +#include "util.h" + +#if defined(SECP256K1_WIDEMUL_INT128) +# if defined(SECP256K1_INT128_NATIVE) +# include "int128_native.h" +# elif defined(SECP256K1_INT128_STRUCT) +# include "int128_struct.h" +# else +# error "Please select int128 implementation" +# endif + +/* Construct an unsigned 128-bit value from a high and a low 64-bit value. */ +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_u128_load(rustsecp256k1zkp_v0_10_0_uint128 *r, uint64_t hi, uint64_t lo); + +/* Multiply two unsigned 64-bit values a and b and write the result to r. */ +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_u128_mul(rustsecp256k1zkp_v0_10_0_uint128 *r, uint64_t a, uint64_t b); + +/* Multiply two unsigned 64-bit values a and b and add the result to r. + * The final result is taken modulo 2^128. + */ +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_u128_accum_mul(rustsecp256k1zkp_v0_10_0_uint128 *r, uint64_t a, uint64_t b); + +/* Add an unsigned 64-bit value a to r. + * The final result is taken modulo 2^128. + */ +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_u128_accum_u64(rustsecp256k1zkp_v0_10_0_uint128 *r, uint64_t a); + +/* Unsigned (logical) right shift. + * Non-constant time in n. + */ +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_u128_rshift(rustsecp256k1zkp_v0_10_0_uint128 *r, unsigned int n); + +/* Return the low 64-bits of a 128-bit value as an unsigned 64-bit value. */ +static SECP256K1_INLINE uint64_t rustsecp256k1zkp_v0_10_0_u128_to_u64(const rustsecp256k1zkp_v0_10_0_uint128 *a); + +/* Return the high 64-bits of a 128-bit value as an unsigned 64-bit value. */ +static SECP256K1_INLINE uint64_t rustsecp256k1zkp_v0_10_0_u128_hi_u64(const rustsecp256k1zkp_v0_10_0_uint128 *a); + +/* Write an unsigned 64-bit value to r. */ +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_u128_from_u64(rustsecp256k1zkp_v0_10_0_uint128 *r, uint64_t a); + +/* Tests if r is strictly less than to 2^n. + * n must be strictly less than 128. + */ +static SECP256K1_INLINE int rustsecp256k1zkp_v0_10_0_u128_check_bits(const rustsecp256k1zkp_v0_10_0_uint128 *r, unsigned int n); + +/* Construct an signed 128-bit value from a high and a low 64-bit value. */ +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_i128_load(rustsecp256k1zkp_v0_10_0_int128 *r, int64_t hi, uint64_t lo); + +/* Multiply two signed 64-bit values a and b and write the result to r. */ +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_i128_mul(rustsecp256k1zkp_v0_10_0_int128 *r, int64_t a, int64_t b); + +/* Multiply two signed 64-bit values a and b and add the result to r. + * Overflow or underflow from the addition is undefined behaviour. + */ +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_i128_accum_mul(rustsecp256k1zkp_v0_10_0_int128 *r, int64_t a, int64_t b); + +/* Compute a*d - b*c from signed 64-bit values and write the result to r. */ +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_i128_det(rustsecp256k1zkp_v0_10_0_int128 *r, int64_t a, int64_t b, int64_t c, int64_t d); + +/* Signed (arithmetic) right shift. + * Non-constant time in b. + */ +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_i128_rshift(rustsecp256k1zkp_v0_10_0_int128 *r, unsigned int b); + +/* Return the input value modulo 2^64. */ +static SECP256K1_INLINE uint64_t rustsecp256k1zkp_v0_10_0_i128_to_u64(const rustsecp256k1zkp_v0_10_0_int128 *a); + +/* Return the value as a signed 64-bit value. + * Requires the input to be between INT64_MIN and INT64_MAX. + */ +static SECP256K1_INLINE int64_t rustsecp256k1zkp_v0_10_0_i128_to_i64(const rustsecp256k1zkp_v0_10_0_int128 *a); + +/* Write a signed 64-bit value to r. */ +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_i128_from_i64(rustsecp256k1zkp_v0_10_0_int128 *r, int64_t a); + +/* Compare two 128-bit values for equality. */ +static SECP256K1_INLINE int rustsecp256k1zkp_v0_10_0_i128_eq_var(const rustsecp256k1zkp_v0_10_0_int128 *a, const rustsecp256k1zkp_v0_10_0_int128 *b); + +/* Tests if r is equal to sign*2^n (sign must be 1 or -1). + * n must be strictly less than 127. + */ +static SECP256K1_INLINE int rustsecp256k1zkp_v0_10_0_i128_check_pow2(const rustsecp256k1zkp_v0_10_0_int128 *r, unsigned int n, int sign); + +#endif + +#endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/int128_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/int128_impl.h new file mode 100644 index 00000000..cfc57340 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/int128_impl.h @@ -0,0 +1,18 @@ +#ifndef SECP256K1_INT128_IMPL_H +#define SECP256K1_INT128_IMPL_H + +#include "util.h" + +#include "int128.h" + +#if defined(SECP256K1_WIDEMUL_INT128) +# if defined(SECP256K1_INT128_NATIVE) +# include "int128_native_impl.h" +# elif defined(SECP256K1_INT128_STRUCT) +# include "int128_struct_impl.h" +# else +# error "Please select int128 implementation" +# endif +#endif + +#endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/int128_native.h b/secp256k1-zkp-sys/depend/secp256k1/src/int128_native.h new file mode 100644 index 00000000..be182728 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/int128_native.h @@ -0,0 +1,19 @@ +#ifndef SECP256K1_INT128_NATIVE_H +#define SECP256K1_INT128_NATIVE_H + +#include +#include "util.h" + +#if !defined(UINT128_MAX) && defined(__SIZEOF_INT128__) +SECP256K1_GNUC_EXT typedef unsigned __int128 uint128_t; +SECP256K1_GNUC_EXT typedef __int128 int128_t; +# define UINT128_MAX ((uint128_t)(-1)) +# define INT128_MAX ((int128_t)(UINT128_MAX >> 1)) +# define INT128_MIN (-INT128_MAX - 1) +/* No (U)INT128_C macros because compilers providing __int128 do not support 128-bit literals. */ +#endif + +typedef uint128_t rustsecp256k1zkp_v0_10_0_uint128; +typedef int128_t rustsecp256k1zkp_v0_10_0_int128; + +#endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/int128_native_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/int128_native_impl.h new file mode 100644 index 00000000..c93ac7bc --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/int128_native_impl.h @@ -0,0 +1,94 @@ +#ifndef SECP256K1_INT128_NATIVE_IMPL_H +#define SECP256K1_INT128_NATIVE_IMPL_H + +#include "int128.h" +#include "util.h" + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_u128_load(rustsecp256k1zkp_v0_10_0_uint128 *r, uint64_t hi, uint64_t lo) { + *r = (((uint128_t)hi) << 64) + lo; +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_u128_mul(rustsecp256k1zkp_v0_10_0_uint128 *r, uint64_t a, uint64_t b) { + *r = (uint128_t)a * b; +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_u128_accum_mul(rustsecp256k1zkp_v0_10_0_uint128 *r, uint64_t a, uint64_t b) { + *r += (uint128_t)a * b; +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_u128_accum_u64(rustsecp256k1zkp_v0_10_0_uint128 *r, uint64_t a) { + *r += a; +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_u128_rshift(rustsecp256k1zkp_v0_10_0_uint128 *r, unsigned int n) { + VERIFY_CHECK(n < 128); + *r >>= n; +} + +static SECP256K1_INLINE uint64_t rustsecp256k1zkp_v0_10_0_u128_to_u64(const rustsecp256k1zkp_v0_10_0_uint128 *a) { + return (uint64_t)(*a); +} + +static SECP256K1_INLINE uint64_t rustsecp256k1zkp_v0_10_0_u128_hi_u64(const rustsecp256k1zkp_v0_10_0_uint128 *a) { + return (uint64_t)(*a >> 64); +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_u128_from_u64(rustsecp256k1zkp_v0_10_0_uint128 *r, uint64_t a) { + *r = a; +} + +static SECP256K1_INLINE int rustsecp256k1zkp_v0_10_0_u128_check_bits(const rustsecp256k1zkp_v0_10_0_uint128 *r, unsigned int n) { + VERIFY_CHECK(n < 128); + return (*r >> n == 0); +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_i128_load(rustsecp256k1zkp_v0_10_0_int128 *r, int64_t hi, uint64_t lo) { + *r = (((uint128_t)(uint64_t)hi) << 64) + lo; +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_i128_mul(rustsecp256k1zkp_v0_10_0_int128 *r, int64_t a, int64_t b) { + *r = (int128_t)a * b; +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_i128_accum_mul(rustsecp256k1zkp_v0_10_0_int128 *r, int64_t a, int64_t b) { + int128_t ab = (int128_t)a * b; + VERIFY_CHECK(0 <= ab ? *r <= INT128_MAX - ab : INT128_MIN - ab <= *r); + *r += ab; +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_i128_det(rustsecp256k1zkp_v0_10_0_int128 *r, int64_t a, int64_t b, int64_t c, int64_t d) { + int128_t ad = (int128_t)a * d; + int128_t bc = (int128_t)b * c; + VERIFY_CHECK(0 <= bc ? INT128_MIN + bc <= ad : ad <= INT128_MAX + bc); + *r = ad - bc; +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_i128_rshift(rustsecp256k1zkp_v0_10_0_int128 *r, unsigned int n) { + VERIFY_CHECK(n < 128); + *r >>= n; +} + +static SECP256K1_INLINE uint64_t rustsecp256k1zkp_v0_10_0_i128_to_u64(const rustsecp256k1zkp_v0_10_0_int128 *a) { + return (uint64_t)*a; +} + +static SECP256K1_INLINE int64_t rustsecp256k1zkp_v0_10_0_i128_to_i64(const rustsecp256k1zkp_v0_10_0_int128 *a) { + VERIFY_CHECK(INT64_MIN <= *a && *a <= INT64_MAX); + return *a; +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_i128_from_i64(rustsecp256k1zkp_v0_10_0_int128 *r, int64_t a) { + *r = a; +} + +static SECP256K1_INLINE int rustsecp256k1zkp_v0_10_0_i128_eq_var(const rustsecp256k1zkp_v0_10_0_int128 *a, const rustsecp256k1zkp_v0_10_0_int128 *b) { + return *a == *b; +} + +static SECP256K1_INLINE int rustsecp256k1zkp_v0_10_0_i128_check_pow2(const rustsecp256k1zkp_v0_10_0_int128 *r, unsigned int n, int sign) { + VERIFY_CHECK(n < 127); + VERIFY_CHECK(sign == 1 || sign == -1); + return (*r == (int128_t)((uint128_t)sign << n)); +} + +#endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/int128_struct.h b/secp256k1-zkp-sys/depend/secp256k1/src/int128_struct.h new file mode 100644 index 00000000..8b1ddbb3 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/int128_struct.h @@ -0,0 +1,14 @@ +#ifndef SECP256K1_INT128_STRUCT_H +#define SECP256K1_INT128_STRUCT_H + +#include +#include "util.h" + +typedef struct { + uint64_t lo; + uint64_t hi; +} rustsecp256k1zkp_v0_10_0_uint128; + +typedef rustsecp256k1zkp_v0_10_0_uint128 rustsecp256k1zkp_v0_10_0_int128; + +#endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/int128_struct_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/int128_struct_impl.h new file mode 100644 index 00000000..92edf006 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/int128_struct_impl.h @@ -0,0 +1,205 @@ +#ifndef SECP256K1_INT128_STRUCT_IMPL_H +#define SECP256K1_INT128_STRUCT_IMPL_H + +#include "int128.h" +#include "util.h" + +#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_ARM64)) /* MSVC */ +# include +# if defined(_M_ARM64) || defined(SECP256K1_MSVC_MULH_TEST_OVERRIDE) +/* On ARM64 MSVC, use __(u)mulh for the upper half of 64x64 multiplications. + (Define SECP256K1_MSVC_MULH_TEST_OVERRIDE to test this code path on X64, + which supports both __(u)mulh and _umul128.) */ +# if defined(SECP256K1_MSVC_MULH_TEST_OVERRIDE) +# pragma message(__FILE__ ": SECP256K1_MSVC_MULH_TEST_OVERRIDE is defined, forcing use of __(u)mulh.") +# endif +static SECP256K1_INLINE uint64_t rustsecp256k1zkp_v0_10_0_umul128(uint64_t a, uint64_t b, uint64_t* hi) { + *hi = __umulh(a, b); + return a * b; +} + +static SECP256K1_INLINE int64_t rustsecp256k1zkp_v0_10_0_mul128(int64_t a, int64_t b, int64_t* hi) { + *hi = __mulh(a, b); + return (uint64_t)a * (uint64_t)b; +} +# else +/* On x84_64 MSVC, use native _(u)mul128 for 64x64->128 multiplications. */ +# define rustsecp256k1zkp_v0_10_0_umul128 _umul128 +# define rustsecp256k1zkp_v0_10_0_mul128 _mul128 +# endif +#else +/* On other systems, emulate 64x64->128 multiplications using 32x32->64 multiplications. */ +static SECP256K1_INLINE uint64_t rustsecp256k1zkp_v0_10_0_umul128(uint64_t a, uint64_t b, uint64_t* hi) { + uint64_t ll = (uint64_t)(uint32_t)a * (uint32_t)b; + uint64_t lh = (uint32_t)a * (b >> 32); + uint64_t hl = (a >> 32) * (uint32_t)b; + uint64_t hh = (a >> 32) * (b >> 32); + uint64_t mid34 = (ll >> 32) + (uint32_t)lh + (uint32_t)hl; + *hi = hh + (lh >> 32) + (hl >> 32) + (mid34 >> 32); + return (mid34 << 32) + (uint32_t)ll; +} + +static SECP256K1_INLINE int64_t rustsecp256k1zkp_v0_10_0_mul128(int64_t a, int64_t b, int64_t* hi) { + uint64_t ll = (uint64_t)(uint32_t)a * (uint32_t)b; + int64_t lh = (uint32_t)a * (b >> 32); + int64_t hl = (a >> 32) * (uint32_t)b; + int64_t hh = (a >> 32) * (b >> 32); + uint64_t mid34 = (ll >> 32) + (uint32_t)lh + (uint32_t)hl; + *hi = hh + (lh >> 32) + (hl >> 32) + (mid34 >> 32); + return (mid34 << 32) + (uint32_t)ll; +} +#endif + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_u128_load(rustsecp256k1zkp_v0_10_0_uint128 *r, uint64_t hi, uint64_t lo) { + r->hi = hi; + r->lo = lo; +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_u128_mul(rustsecp256k1zkp_v0_10_0_uint128 *r, uint64_t a, uint64_t b) { + r->lo = rustsecp256k1zkp_v0_10_0_umul128(a, b, &r->hi); +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_u128_accum_mul(rustsecp256k1zkp_v0_10_0_uint128 *r, uint64_t a, uint64_t b) { + uint64_t lo, hi; + lo = rustsecp256k1zkp_v0_10_0_umul128(a, b, &hi); + r->lo += lo; + r->hi += hi + (r->lo < lo); +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_u128_accum_u64(rustsecp256k1zkp_v0_10_0_uint128 *r, uint64_t a) { + r->lo += a; + r->hi += r->lo < a; +} + +/* Unsigned (logical) right shift. + * Non-constant time in n. + */ +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_u128_rshift(rustsecp256k1zkp_v0_10_0_uint128 *r, unsigned int n) { + VERIFY_CHECK(n < 128); + if (n >= 64) { + r->lo = r->hi >> (n-64); + r->hi = 0; + } else if (n > 0) { +#if defined(_MSC_VER) && defined(_M_X64) + VERIFY_CHECK(n < 64); + r->lo = __shiftright128(r->lo, r->hi, n); +#else + r->lo = ((1U * r->hi) << (64-n)) | r->lo >> n; +#endif + r->hi >>= n; + } +} + +static SECP256K1_INLINE uint64_t rustsecp256k1zkp_v0_10_0_u128_to_u64(const rustsecp256k1zkp_v0_10_0_uint128 *a) { + return a->lo; +} + +static SECP256K1_INLINE uint64_t rustsecp256k1zkp_v0_10_0_u128_hi_u64(const rustsecp256k1zkp_v0_10_0_uint128 *a) { + return a->hi; +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_u128_from_u64(rustsecp256k1zkp_v0_10_0_uint128 *r, uint64_t a) { + r->hi = 0; + r->lo = a; +} + +static SECP256K1_INLINE int rustsecp256k1zkp_v0_10_0_u128_check_bits(const rustsecp256k1zkp_v0_10_0_uint128 *r, unsigned int n) { + VERIFY_CHECK(n < 128); + return n >= 64 ? r->hi >> (n - 64) == 0 + : r->hi == 0 && r->lo >> n == 0; +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_i128_load(rustsecp256k1zkp_v0_10_0_int128 *r, int64_t hi, uint64_t lo) { + r->hi = hi; + r->lo = lo; +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_i128_mul(rustsecp256k1zkp_v0_10_0_int128 *r, int64_t a, int64_t b) { + int64_t hi; + r->lo = (uint64_t)rustsecp256k1zkp_v0_10_0_mul128(a, b, &hi); + r->hi = (uint64_t)hi; +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_i128_accum_mul(rustsecp256k1zkp_v0_10_0_int128 *r, int64_t a, int64_t b) { + int64_t hi; + uint64_t lo = (uint64_t)rustsecp256k1zkp_v0_10_0_mul128(a, b, &hi); + r->lo += lo; + hi += r->lo < lo; + /* Verify no overflow. + * If r represents a positive value (the sign bit is not set) and the value we are adding is a positive value (the sign bit is not set), + * then we require that the resulting value also be positive (the sign bit is not set). + * Note that (X <= Y) means (X implies Y) when X and Y are boolean values (i.e. 0 or 1). + */ + VERIFY_CHECK((r->hi <= 0x7fffffffffffffffu && (uint64_t)hi <= 0x7fffffffffffffffu) <= (r->hi + (uint64_t)hi <= 0x7fffffffffffffffu)); + /* Verify no underflow. + * If r represents a negative value (the sign bit is set) and the value we are adding is a negative value (the sign bit is set), + * then we require that the resulting value also be negative (the sign bit is set). + */ + VERIFY_CHECK((r->hi > 0x7fffffffffffffffu && (uint64_t)hi > 0x7fffffffffffffffu) <= (r->hi + (uint64_t)hi > 0x7fffffffffffffffu)); + r->hi += hi; +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_i128_dissip_mul(rustsecp256k1zkp_v0_10_0_int128 *r, int64_t a, int64_t b) { + int64_t hi; + uint64_t lo = (uint64_t)rustsecp256k1zkp_v0_10_0_mul128(a, b, &hi); + hi += r->lo < lo; + /* Verify no overflow. + * If r represents a positive value (the sign bit is not set) and the value we are subtracting is a negative value (the sign bit is set), + * then we require that the resulting value also be positive (the sign bit is not set). + */ + VERIFY_CHECK((r->hi <= 0x7fffffffffffffffu && (uint64_t)hi > 0x7fffffffffffffffu) <= (r->hi - (uint64_t)hi <= 0x7fffffffffffffffu)); + /* Verify no underflow. + * If r represents a negative value (the sign bit is set) and the value we are subtracting is a positive value (the sign sign bit is not set), + * then we require that the resulting value also be negative (the sign bit is set). + */ + VERIFY_CHECK((r->hi > 0x7fffffffffffffffu && (uint64_t)hi <= 0x7fffffffffffffffu) <= (r->hi - (uint64_t)hi > 0x7fffffffffffffffu)); + r->hi -= hi; + r->lo -= lo; +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_i128_det(rustsecp256k1zkp_v0_10_0_int128 *r, int64_t a, int64_t b, int64_t c, int64_t d) { + rustsecp256k1zkp_v0_10_0_i128_mul(r, a, d); + rustsecp256k1zkp_v0_10_0_i128_dissip_mul(r, b, c); +} + +/* Signed (arithmetic) right shift. + * Non-constant time in n. + */ +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_i128_rshift(rustsecp256k1zkp_v0_10_0_int128 *r, unsigned int n) { + VERIFY_CHECK(n < 128); + if (n >= 64) { + r->lo = (uint64_t)((int64_t)(r->hi) >> (n-64)); + r->hi = (uint64_t)((int64_t)(r->hi) >> 63); + } else if (n > 0) { + r->lo = ((1U * r->hi) << (64-n)) | r->lo >> n; + r->hi = (uint64_t)((int64_t)(r->hi) >> n); + } +} + +static SECP256K1_INLINE uint64_t rustsecp256k1zkp_v0_10_0_i128_to_u64(const rustsecp256k1zkp_v0_10_0_int128 *a) { + return a->lo; +} + +static SECP256K1_INLINE int64_t rustsecp256k1zkp_v0_10_0_i128_to_i64(const rustsecp256k1zkp_v0_10_0_int128 *a) { + /* Verify that a represents a 64 bit signed value by checking that the high bits are a sign extension of the low bits. */ + VERIFY_CHECK(a->hi == -(a->lo >> 63)); + return (int64_t)rustsecp256k1zkp_v0_10_0_i128_to_u64(a); +} + +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_i128_from_i64(rustsecp256k1zkp_v0_10_0_int128 *r, int64_t a) { + r->hi = (uint64_t)(a >> 63); + r->lo = (uint64_t)a; +} + +static SECP256K1_INLINE int rustsecp256k1zkp_v0_10_0_i128_eq_var(const rustsecp256k1zkp_v0_10_0_int128 *a, const rustsecp256k1zkp_v0_10_0_int128 *b) { + return a->hi == b->hi && a->lo == b->lo; +} + +static SECP256K1_INLINE int rustsecp256k1zkp_v0_10_0_i128_check_pow2(const rustsecp256k1zkp_v0_10_0_int128 *r, unsigned int n, int sign) { + VERIFY_CHECK(n < 127); + VERIFY_CHECK(sign == 1 || sign == -1); + return n >= 64 ? r->hi == (uint64_t)sign << (n - 64) && r->lo == 0 + : r->hi == (uint64_t)(sign >> 1) && r->lo == (uint64_t)sign << n; +} + +#endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modinv32.h b/secp256k1-zkp-sys/depend/secp256k1/src/modinv32.h index f5a551cc..169a3027 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modinv32.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modinv32.h @@ -7,10 +7,6 @@ #ifndef SECP256K1_MODINV32_H #define SECP256K1_MODINV32_H -#if defined HAVE_CONFIG_H -#include "libsecp256k1-config.h" -#endif - #include "util.h" /* A signed 30-bit limb representation of integers. @@ -18,15 +14,15 @@ * Its value is sum(v[i] * 2^(30*i), i=0..8). */ typedef struct { int32_t v[9]; -} rustsecp256k1zkp_v0_8_0_modinv32_signed30; +} rustsecp256k1zkp_v0_10_0_modinv32_signed30; typedef struct { /* The modulus in signed30 notation, must be odd and in [3, 2^256]. */ - rustsecp256k1zkp_v0_8_0_modinv32_signed30 modulus; + rustsecp256k1zkp_v0_10_0_modinv32_signed30 modulus; /* modulus^{-1} mod 2^30 */ uint32_t modulus_inv30; -} rustsecp256k1zkp_v0_8_0_modinv32_modinfo; +} rustsecp256k1zkp_v0_10_0_modinv32_modinfo; /* Replace x with its modular inverse mod modinfo->modulus. x must be in range [0, modulus). * If x is zero, the result will be zero as well. If not, the inverse must exist (i.e., the gcd of @@ -34,9 +30,14 @@ typedef struct { * * On output, all of x's limbs will be in [0, 2^30). */ -static void rustsecp256k1zkp_v0_8_0_modinv32_var(rustsecp256k1zkp_v0_8_0_modinv32_signed30 *x, const rustsecp256k1zkp_v0_8_0_modinv32_modinfo *modinfo); +static void rustsecp256k1zkp_v0_10_0_modinv32_var(rustsecp256k1zkp_v0_10_0_modinv32_signed30 *x, const rustsecp256k1zkp_v0_10_0_modinv32_modinfo *modinfo); + +/* Same as rustsecp256k1zkp_v0_10_0_modinv32_var, but constant time in x (not in the modulus). */ +static void rustsecp256k1zkp_v0_10_0_modinv32(rustsecp256k1zkp_v0_10_0_modinv32_signed30 *x, const rustsecp256k1zkp_v0_10_0_modinv32_modinfo *modinfo); -/* Same as rustsecp256k1zkp_v0_8_0_modinv32_var, but constant time in x (not in the modulus). */ -static void rustsecp256k1zkp_v0_8_0_modinv32(rustsecp256k1zkp_v0_8_0_modinv32_signed30 *x, const rustsecp256k1zkp_v0_8_0_modinv32_modinfo *modinfo); +/* Compute the Jacobi symbol for (x | modinfo->modulus). x must be coprime with modulus (and thus + * cannot be 0, as modulus >= 3). All limbs of x must be non-negative. Returns 0 if the result + * cannot be computed. */ +static int rustsecp256k1zkp_v0_10_0_jacobi32_maybe_var(const rustsecp256k1zkp_v0_10_0_modinv32_signed30 *x, const rustsecp256k1zkp_v0_10_0_modinv32_modinfo *modinfo); #endif /* SECP256K1_MODINV32_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modinv32_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modinv32_impl.h index a6b3698a..f5578bc3 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modinv32_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modinv32_impl.h @@ -21,10 +21,10 @@ */ #ifdef VERIFY -static const rustsecp256k1zkp_v0_8_0_modinv32_signed30 SECP256K1_SIGNED30_ONE = {{1}}; +static const rustsecp256k1zkp_v0_10_0_modinv32_signed30 SECP256K1_SIGNED30_ONE = {{1}}; /* Compute a*factor and put it in r. All but the top limb in r will be in range [0,2^30). */ -static void rustsecp256k1zkp_v0_8_0_modinv32_mul_30(rustsecp256k1zkp_v0_8_0_modinv32_signed30 *r, const rustsecp256k1zkp_v0_8_0_modinv32_signed30 *a, int alen, int32_t factor) { +static void rustsecp256k1zkp_v0_10_0_modinv32_mul_30(rustsecp256k1zkp_v0_10_0_modinv32_signed30 *r, const rustsecp256k1zkp_v0_10_0_modinv32_signed30 *a, int alen, int32_t factor) { const int32_t M30 = (int32_t)(UINT32_MAX >> 2); int64_t c = 0; int i; @@ -38,11 +38,11 @@ static void rustsecp256k1zkp_v0_8_0_modinv32_mul_30(rustsecp256k1zkp_v0_8_0_modi } /* Return -1 for ab*factor. A consists of alen limbs; b has 9. */ -static int rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(const rustsecp256k1zkp_v0_8_0_modinv32_signed30 *a, int alen, const rustsecp256k1zkp_v0_8_0_modinv32_signed30 *b, int32_t factor) { +static int rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(const rustsecp256k1zkp_v0_10_0_modinv32_signed30 *a, int alen, const rustsecp256k1zkp_v0_10_0_modinv32_signed30 *b, int32_t factor) { int i; - rustsecp256k1zkp_v0_8_0_modinv32_signed30 am, bm; - rustsecp256k1zkp_v0_8_0_modinv32_mul_30(&am, a, alen, 1); /* Normalize all but the top limb of a. */ - rustsecp256k1zkp_v0_8_0_modinv32_mul_30(&bm, b, 9, factor); + rustsecp256k1zkp_v0_10_0_modinv32_signed30 am, bm; + rustsecp256k1zkp_v0_10_0_modinv32_mul_30(&am, a, alen, 1); /* Normalize all but the top limb of a. */ + rustsecp256k1zkp_v0_10_0_modinv32_mul_30(&bm, b, 9, factor); for (i = 0; i < 8; ++i) { /* Verify that all but the top limb of a and b are normalized. */ VERIFY_CHECK(am.v[i] >> 30 == 0); @@ -60,11 +60,11 @@ static int rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(const rustsecp256k1zkp_v0 * to it to bring it to range [0,modulus). If sign < 0, the input will also be negated in the * process. The input must have limbs in range (-2^30,2^30). The output will have limbs in range * [0,2^30). */ -static void rustsecp256k1zkp_v0_8_0_modinv32_normalize_30(rustsecp256k1zkp_v0_8_0_modinv32_signed30 *r, int32_t sign, const rustsecp256k1zkp_v0_8_0_modinv32_modinfo *modinfo) { +static void rustsecp256k1zkp_v0_10_0_modinv32_normalize_30(rustsecp256k1zkp_v0_10_0_modinv32_signed30 *r, int32_t sign, const rustsecp256k1zkp_v0_10_0_modinv32_modinfo *modinfo) { const int32_t M30 = (int32_t)(UINT32_MAX >> 2); int32_t r0 = r->v[0], r1 = r->v[1], r2 = r->v[2], r3 = r->v[3], r4 = r->v[4], r5 = r->v[5], r6 = r->v[6], r7 = r->v[7], r8 = r->v[8]; - int32_t cond_add, cond_negate; + volatile int32_t cond_add, cond_negate; #ifdef VERIFY /* Verify that all limbs are in range (-2^30,2^30). */ @@ -73,8 +73,8 @@ static void rustsecp256k1zkp_v0_8_0_modinv32_normalize_30(rustsecp256k1zkp_v0_8_ VERIFY_CHECK(r->v[i] >= -M30); VERIFY_CHECK(r->v[i] <= M30); } - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(r, 9, &modinfo->modulus, -2) > 0); /* r > -2*modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(r, 9, &modinfo->modulus, 1) < 0); /* r < modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(r, 9, &modinfo->modulus, -2) > 0); /* r > -2*modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(r, 9, &modinfo->modulus, 1) < 0); /* r < modulus */ #endif /* In a first step, add the modulus if the input is negative, and then negate if requested. @@ -144,7 +144,6 @@ static void rustsecp256k1zkp_v0_8_0_modinv32_normalize_30(rustsecp256k1zkp_v0_8_ r->v[7] = r7; r->v[8] = r8; -#ifdef VERIFY VERIFY_CHECK(r0 >> 30 == 0); VERIFY_CHECK(r1 >> 30 == 0); VERIFY_CHECK(r2 >> 30 == 0); @@ -154,9 +153,8 @@ static void rustsecp256k1zkp_v0_8_0_modinv32_normalize_30(rustsecp256k1zkp_v0_8_ VERIFY_CHECK(r6 >> 30 == 0); VERIFY_CHECK(r7 >> 30 == 0); VERIFY_CHECK(r8 >> 30 == 0); - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(r, 9, &modinfo->modulus, 0) >= 0); /* r >= 0 */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(r, 9, &modinfo->modulus, 1) < 0); /* r < modulus */ -#endif + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(r, 9, &modinfo->modulus, 0) >= 0); /* r >= 0 */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(r, 9, &modinfo->modulus, 1) < 0); /* r < modulus */ } /* Data type for transition matrices (see section 3 of explanation). @@ -166,7 +164,7 @@ static void rustsecp256k1zkp_v0_8_0_modinv32_normalize_30(rustsecp256k1zkp_v0_8_ */ typedef struct { int32_t u, v, q, r; -} rustsecp256k1zkp_v0_8_0_modinv32_trans2x2; +} rustsecp256k1zkp_v0_10_0_modinv32_trans2x2; /* Compute the transition matrix and zeta for 30 divsteps. * @@ -178,7 +176,7 @@ typedef struct { * * Implements the divsteps_n_matrix function from the explanation. */ -static int32_t rustsecp256k1zkp_v0_8_0_modinv32_divsteps_30(int32_t zeta, uint32_t f0, uint32_t g0, rustsecp256k1zkp_v0_8_0_modinv32_trans2x2 *t) { +static int32_t rustsecp256k1zkp_v0_10_0_modinv32_divsteps_30(int32_t zeta, uint32_t f0, uint32_t g0, rustsecp256k1zkp_v0_10_0_modinv32_trans2x2 *t) { /* u,v,q,r are the elements of the transformation matrix being built up, * starting with the identity matrix. Semantically they are signed integers * in range [-2^30,2^30], but here represented as unsigned mod 2^32. This @@ -186,7 +184,8 @@ static int32_t rustsecp256k1zkp_v0_8_0_modinv32_divsteps_30(int32_t zeta, uint32 * being inside [-2^31,2^31) means that casting to signed works correctly. */ uint32_t u = 1, v = 0, q = 0, r = 1; - uint32_t c1, c2, f = f0, g = g0, x, y, z; + volatile uint32_t c1, c2; + uint32_t mask1, mask2, f = f0, g = g0, x, y, z; int i; for (i = 0; i < 30; ++i) { @@ -195,23 +194,25 @@ static int32_t rustsecp256k1zkp_v0_8_0_modinv32_divsteps_30(int32_t zeta, uint32 VERIFY_CHECK((q * f0 + r * g0) == g << i); /* Compute conditional masks for (zeta < 0) and for (g & 1). */ c1 = zeta >> 31; - c2 = -(g & 1); + mask1 = c1; + c2 = g & 1; + mask2 = -c2; /* Compute x,y,z, conditionally negated versions of f,u,v. */ - x = (f ^ c1) - c1; - y = (u ^ c1) - c1; - z = (v ^ c1) - c1; + x = (f ^ mask1) - mask1; + y = (u ^ mask1) - mask1; + z = (v ^ mask1) - mask1; /* Conditionally add x,y,z to g,q,r. */ - g += x & c2; - q += y & c2; - r += z & c2; - /* In what follows, c1 is a condition mask for (zeta < 0) and (g & 1). */ - c1 &= c2; + g += x & mask2; + q += y & mask2; + r += z & mask2; + /* In what follows, mask1 is a condition mask for (zeta < 0) and (g & 1). */ + mask1 &= mask2; /* Conditionally change zeta into -zeta-2 or zeta-1. */ - zeta = (zeta ^ c1) - 1; + zeta = (zeta ^ mask1) - 1; /* Conditionally add g,q,r to f,u,v. */ - f += g & c1; - u += q & c1; - v += r & c1; + f += g & mask1; + u += q & mask1; + v += r & mask1; /* Shifts */ g >>= 1; u <<= 1; @@ -232,6 +233,21 @@ static int32_t rustsecp256k1zkp_v0_8_0_modinv32_divsteps_30(int32_t zeta, uint32 return zeta; } +/* rustsecp256k1zkp_v0_10_0_modinv32_inv256[i] = -(2*i+1)^-1 (mod 256) */ +static const uint8_t rustsecp256k1zkp_v0_10_0_modinv32_inv256[128] = { + 0xFF, 0x55, 0x33, 0x49, 0xC7, 0x5D, 0x3B, 0x11, 0x0F, 0xE5, 0xC3, 0x59, + 0xD7, 0xED, 0xCB, 0x21, 0x1F, 0x75, 0x53, 0x69, 0xE7, 0x7D, 0x5B, 0x31, + 0x2F, 0x05, 0xE3, 0x79, 0xF7, 0x0D, 0xEB, 0x41, 0x3F, 0x95, 0x73, 0x89, + 0x07, 0x9D, 0x7B, 0x51, 0x4F, 0x25, 0x03, 0x99, 0x17, 0x2D, 0x0B, 0x61, + 0x5F, 0xB5, 0x93, 0xA9, 0x27, 0xBD, 0x9B, 0x71, 0x6F, 0x45, 0x23, 0xB9, + 0x37, 0x4D, 0x2B, 0x81, 0x7F, 0xD5, 0xB3, 0xC9, 0x47, 0xDD, 0xBB, 0x91, + 0x8F, 0x65, 0x43, 0xD9, 0x57, 0x6D, 0x4B, 0xA1, 0x9F, 0xF5, 0xD3, 0xE9, + 0x67, 0xFD, 0xDB, 0xB1, 0xAF, 0x85, 0x63, 0xF9, 0x77, 0x8D, 0x6B, 0xC1, + 0xBF, 0x15, 0xF3, 0x09, 0x87, 0x1D, 0xFB, 0xD1, 0xCF, 0xA5, 0x83, 0x19, + 0x97, 0xAD, 0x8B, 0xE1, 0xDF, 0x35, 0x13, 0x29, 0xA7, 0x3D, 0x1B, 0xF1, + 0xEF, 0xC5, 0xA3, 0x39, 0xB7, 0xCD, 0xAB, 0x01 +}; + /* Compute the transition matrix and eta for 30 divsteps (variable time). * * Input: eta: initial eta @@ -242,23 +258,8 @@ static int32_t rustsecp256k1zkp_v0_8_0_modinv32_divsteps_30(int32_t zeta, uint32 * * Implements the divsteps_n_matrix_var function from the explanation. */ -static int32_t rustsecp256k1zkp_v0_8_0_modinv32_divsteps_30_var(int32_t eta, uint32_t f0, uint32_t g0, rustsecp256k1zkp_v0_8_0_modinv32_trans2x2 *t) { - /* inv256[i] = -(2*i+1)^-1 (mod 256) */ - static const uint8_t inv256[128] = { - 0xFF, 0x55, 0x33, 0x49, 0xC7, 0x5D, 0x3B, 0x11, 0x0F, 0xE5, 0xC3, 0x59, - 0xD7, 0xED, 0xCB, 0x21, 0x1F, 0x75, 0x53, 0x69, 0xE7, 0x7D, 0x5B, 0x31, - 0x2F, 0x05, 0xE3, 0x79, 0xF7, 0x0D, 0xEB, 0x41, 0x3F, 0x95, 0x73, 0x89, - 0x07, 0x9D, 0x7B, 0x51, 0x4F, 0x25, 0x03, 0x99, 0x17, 0x2D, 0x0B, 0x61, - 0x5F, 0xB5, 0x93, 0xA9, 0x27, 0xBD, 0x9B, 0x71, 0x6F, 0x45, 0x23, 0xB9, - 0x37, 0x4D, 0x2B, 0x81, 0x7F, 0xD5, 0xB3, 0xC9, 0x47, 0xDD, 0xBB, 0x91, - 0x8F, 0x65, 0x43, 0xD9, 0x57, 0x6D, 0x4B, 0xA1, 0x9F, 0xF5, 0xD3, 0xE9, - 0x67, 0xFD, 0xDB, 0xB1, 0xAF, 0x85, 0x63, 0xF9, 0x77, 0x8D, 0x6B, 0xC1, - 0xBF, 0x15, 0xF3, 0x09, 0x87, 0x1D, 0xFB, 0xD1, 0xCF, 0xA5, 0x83, 0x19, - 0x97, 0xAD, 0x8B, 0xE1, 0xDF, 0x35, 0x13, 0x29, 0xA7, 0x3D, 0x1B, 0xF1, - 0xEF, 0xC5, 0xA3, 0x39, 0xB7, 0xCD, 0xAB, 0x01 - }; - - /* Transformation matrix; see comments in rustsecp256k1zkp_v0_8_0_modinv32_divsteps_30. */ +static int32_t rustsecp256k1zkp_v0_10_0_modinv32_divsteps_30_var(int32_t eta, uint32_t f0, uint32_t g0, rustsecp256k1zkp_v0_10_0_modinv32_trans2x2 *t) { + /* Transformation matrix; see comments in rustsecp256k1zkp_v0_10_0_modinv32_divsteps_30. */ uint32_t u = 1, v = 0, q = 0, r = 1; uint32_t f = f0, g = g0, m; uint16_t w; @@ -266,7 +267,7 @@ static int32_t rustsecp256k1zkp_v0_8_0_modinv32_divsteps_30_var(int32_t eta, uin for (;;) { /* Use a sentinel bit to count zeros only up to i. */ - zeros = rustsecp256k1zkp_v0_8_0_ctz32_var(g | (UINT32_MAX << i)); + zeros = rustsecp256k1zkp_v0_10_0_ctz32_var(g | (UINT32_MAX << i)); /* Perform zeros divsteps at once; they all just divide g by two. */ g >>= zeros; u <<= zeros; @@ -297,7 +298,7 @@ static int32_t rustsecp256k1zkp_v0_8_0_modinv32_divsteps_30_var(int32_t eta, uin VERIFY_CHECK(limit > 0 && limit <= 30); m = (UINT32_MAX >> (32 - limit)) & 255U; /* Find what multiple of f must be added to g to cancel its bottom min(limit, 8) bits. */ - w = (g * inv256[(f >> 1) & 127]) & m; + w = (g * rustsecp256k1zkp_v0_10_0_modinv32_inv256[(f >> 1) & 127]) & m; /* Do so. */ g += f * w; q += u * w; @@ -317,6 +318,86 @@ static int32_t rustsecp256k1zkp_v0_8_0_modinv32_divsteps_30_var(int32_t eta, uin return eta; } +/* Compute the transition matrix and eta for 30 posdivsteps (variable time, eta=-delta), and keeps track + * of the Jacobi symbol along the way. f0 and g0 must be f and g mod 2^32 rather than 2^30, because + * Jacobi tracking requires knowing (f mod 8) rather than just (f mod 2). + * + * Input: eta: initial eta + * f0: bottom limb of initial f + * g0: bottom limb of initial g + * Output: t: transition matrix + * Input/Output: (*jacp & 1) is bitflipped if and only if the Jacobi symbol of (f | g) changes sign + * by applying the returned transformation matrix to it. The other bits of *jacp may + * change, but are meaningless. + * Return: final eta + */ +static int32_t rustsecp256k1zkp_v0_10_0_modinv32_posdivsteps_30_var(int32_t eta, uint32_t f0, uint32_t g0, rustsecp256k1zkp_v0_10_0_modinv32_trans2x2 *t, int *jacp) { + /* Transformation matrix. */ + uint32_t u = 1, v = 0, q = 0, r = 1; + uint32_t f = f0, g = g0, m; + uint16_t w; + int i = 30, limit, zeros; + int jac = *jacp; + + for (;;) { + /* Use a sentinel bit to count zeros only up to i. */ + zeros = rustsecp256k1zkp_v0_10_0_ctz32_var(g | (UINT32_MAX << i)); + /* Perform zeros divsteps at once; they all just divide g by two. */ + g >>= zeros; + u <<= zeros; + v <<= zeros; + eta -= zeros; + i -= zeros; + /* Update the bottom bit of jac: when dividing g by an odd power of 2, + * if (f mod 8) is 3 or 5, the Jacobi symbol changes sign. */ + jac ^= (zeros & ((f >> 1) ^ (f >> 2))); + /* We're done once we've done 30 posdivsteps. */ + if (i == 0) break; + VERIFY_CHECK((f & 1) == 1); + VERIFY_CHECK((g & 1) == 1); + VERIFY_CHECK((u * f0 + v * g0) == f << (30 - i)); + VERIFY_CHECK((q * f0 + r * g0) == g << (30 - i)); + /* If eta is negative, negate it and replace f,g with g,f. */ + if (eta < 0) { + uint32_t tmp; + eta = -eta; + /* Update bottom bit of jac: when swapping f and g, the Jacobi symbol changes sign + * if both f and g are 3 mod 4. */ + jac ^= ((f & g) >> 1); + tmp = f; f = g; g = tmp; + tmp = u; u = q; q = tmp; + tmp = v; v = r; r = tmp; + } + /* eta is now >= 0. In what follows we're going to cancel out the bottom bits of g. No more + * than i can be cancelled out (as we'd be done before that point), and no more than eta+1 + * can be done as its sign will flip once that happens. */ + limit = ((int)eta + 1) > i ? i : ((int)eta + 1); + /* m is a mask for the bottom min(limit, 8) bits (our table only supports 8 bits). */ + VERIFY_CHECK(limit > 0 && limit <= 30); + m = (UINT32_MAX >> (32 - limit)) & 255U; + /* Find what multiple of f must be added to g to cancel its bottom min(limit, 8) bits. */ + w = (g * rustsecp256k1zkp_v0_10_0_modinv32_inv256[(f >> 1) & 127]) & m; + /* Do so. */ + g += f * w; + q += u * w; + r += v * w; + VERIFY_CHECK((g & m) == 0); + } + /* Return data in t and return value. */ + t->u = (int32_t)u; + t->v = (int32_t)v; + t->q = (int32_t)q; + t->r = (int32_t)r; + /* The determinant of t must be a power of two. This guarantees that multiplication with t + * does not change the gcd of f and g, apart from adding a power-of-2 factor to it (which + * will be divided out again). As each divstep's individual matrix has determinant 2 or -2, + * the aggregate of 30 of them will have determinant 2^30 or -2^30. */ + VERIFY_CHECK((int64_t)t->u * t->r - (int64_t)t->v * t->q == ((int64_t)1) << 30 || + (int64_t)t->u * t->r - (int64_t)t->v * t->q == -(((int64_t)1) << 30)); + *jacp = jac; + return eta; +} + /* Compute (t/2^30) * [d, e] mod modulus, where t is a transition matrix for 30 divsteps. * * On input and output, d and e are in range (-2*modulus,modulus). All output limbs will be in range @@ -324,22 +405,19 @@ static int32_t rustsecp256k1zkp_v0_8_0_modinv32_divsteps_30_var(int32_t eta, uin * * This implements the update_de function from the explanation. */ -static void rustsecp256k1zkp_v0_8_0_modinv32_update_de_30(rustsecp256k1zkp_v0_8_0_modinv32_signed30 *d, rustsecp256k1zkp_v0_8_0_modinv32_signed30 *e, const rustsecp256k1zkp_v0_8_0_modinv32_trans2x2 *t, const rustsecp256k1zkp_v0_8_0_modinv32_modinfo* modinfo) { +static void rustsecp256k1zkp_v0_10_0_modinv32_update_de_30(rustsecp256k1zkp_v0_10_0_modinv32_signed30 *d, rustsecp256k1zkp_v0_10_0_modinv32_signed30 *e, const rustsecp256k1zkp_v0_10_0_modinv32_trans2x2 *t, const rustsecp256k1zkp_v0_10_0_modinv32_modinfo* modinfo) { const int32_t M30 = (int32_t)(UINT32_MAX >> 2); const int32_t u = t->u, v = t->v, q = t->q, r = t->r; int32_t di, ei, md, me, sd, se; int64_t cd, ce; int i; -#ifdef VERIFY - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(d, 9, &modinfo->modulus, -2) > 0); /* d > -2*modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(d, 9, &modinfo->modulus, 1) < 0); /* d < modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(e, 9, &modinfo->modulus, -2) > 0); /* e > -2*modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(e, 9, &modinfo->modulus, 1) < 0); /* e < modulus */ - VERIFY_CHECK((labs(u) + labs(v)) >= 0); /* |u|+|v| doesn't overflow */ - VERIFY_CHECK((labs(q) + labs(r)) >= 0); /* |q|+|r| doesn't overflow */ - VERIFY_CHECK((labs(u) + labs(v)) <= M30 + 1); /* |u|+|v| <= 2^30 */ - VERIFY_CHECK((labs(q) + labs(r)) <= M30 + 1); /* |q|+|r| <= 2^30 */ -#endif + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(d, 9, &modinfo->modulus, -2) > 0); /* d > -2*modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(d, 9, &modinfo->modulus, 1) < 0); /* d < modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(e, 9, &modinfo->modulus, -2) > 0); /* e > -2*modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(e, 9, &modinfo->modulus, 1) < 0); /* e < modulus */ + VERIFY_CHECK(labs(u) <= (M30 + 1 - labs(v))); /* |u|+|v| <= 2^30 */ + VERIFY_CHECK(labs(q) <= (M30 + 1 - labs(r))); /* |q|+|r| <= 2^30 */ + /* [md,me] start as zero; plus [u,q] if d is negative; plus [v,r] if e is negative. */ sd = d->v[8] >> 31; se = e->v[8] >> 31; @@ -374,19 +452,18 @@ static void rustsecp256k1zkp_v0_8_0_modinv32_update_de_30(rustsecp256k1zkp_v0_8_ /* What remains is limb 9 of t*[d,e]+modulus*[md,me]; store it as output limb 8. */ d->v[8] = (int32_t)cd; e->v[8] = (int32_t)ce; -#ifdef VERIFY - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(d, 9, &modinfo->modulus, -2) > 0); /* d > -2*modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(d, 9, &modinfo->modulus, 1) < 0); /* d < modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(e, 9, &modinfo->modulus, -2) > 0); /* e > -2*modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(e, 9, &modinfo->modulus, 1) < 0); /* e < modulus */ -#endif + + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(d, 9, &modinfo->modulus, -2) > 0); /* d > -2*modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(d, 9, &modinfo->modulus, 1) < 0); /* d < modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(e, 9, &modinfo->modulus, -2) > 0); /* e > -2*modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(e, 9, &modinfo->modulus, 1) < 0); /* e < modulus */ } /* Compute (t/2^30) * [f, g], where t is a transition matrix for 30 divsteps. * * This implements the update_fg function from the explanation. */ -static void rustsecp256k1zkp_v0_8_0_modinv32_update_fg_30(rustsecp256k1zkp_v0_8_0_modinv32_signed30 *f, rustsecp256k1zkp_v0_8_0_modinv32_signed30 *g, const rustsecp256k1zkp_v0_8_0_modinv32_trans2x2 *t) { +static void rustsecp256k1zkp_v0_10_0_modinv32_update_fg_30(rustsecp256k1zkp_v0_10_0_modinv32_signed30 *f, rustsecp256k1zkp_v0_10_0_modinv32_signed30 *g, const rustsecp256k1zkp_v0_10_0_modinv32_trans2x2 *t) { const int32_t M30 = (int32_t)(UINT32_MAX >> 2); const int32_t u = t->u, v = t->v, q = t->q, r = t->r; int32_t fi, gi; @@ -421,7 +498,7 @@ static void rustsecp256k1zkp_v0_8_0_modinv32_update_fg_30(rustsecp256k1zkp_v0_8_ * * This implements the update_fg function from the explanation in modinv64_impl.h. */ -static void rustsecp256k1zkp_v0_8_0_modinv32_update_fg_30_var(int len, rustsecp256k1zkp_v0_8_0_modinv32_signed30 *f, rustsecp256k1zkp_v0_8_0_modinv32_signed30 *g, const rustsecp256k1zkp_v0_8_0_modinv32_trans2x2 *t) { +static void rustsecp256k1zkp_v0_10_0_modinv32_update_fg_30_var(int len, rustsecp256k1zkp_v0_10_0_modinv32_signed30 *f, rustsecp256k1zkp_v0_10_0_modinv32_signed30 *g, const rustsecp256k1zkp_v0_10_0_modinv32_trans2x2 *t) { const int32_t M30 = (int32_t)(UINT32_MAX >> 2); const int32_t u = t->u, v = t->v, q = t->q, r = t->r; int32_t fi, gi; @@ -452,65 +529,62 @@ static void rustsecp256k1zkp_v0_8_0_modinv32_update_fg_30_var(int len, rustsecp2 } /* Compute the inverse of x modulo modinfo->modulus, and replace x with it (constant time in x). */ -static void rustsecp256k1zkp_v0_8_0_modinv32(rustsecp256k1zkp_v0_8_0_modinv32_signed30 *x, const rustsecp256k1zkp_v0_8_0_modinv32_modinfo *modinfo) { +static void rustsecp256k1zkp_v0_10_0_modinv32(rustsecp256k1zkp_v0_10_0_modinv32_signed30 *x, const rustsecp256k1zkp_v0_10_0_modinv32_modinfo *modinfo) { /* Start with d=0, e=1, f=modulus, g=x, zeta=-1. */ - rustsecp256k1zkp_v0_8_0_modinv32_signed30 d = {{0}}; - rustsecp256k1zkp_v0_8_0_modinv32_signed30 e = {{1}}; - rustsecp256k1zkp_v0_8_0_modinv32_signed30 f = modinfo->modulus; - rustsecp256k1zkp_v0_8_0_modinv32_signed30 g = *x; + rustsecp256k1zkp_v0_10_0_modinv32_signed30 d = {{0}}; + rustsecp256k1zkp_v0_10_0_modinv32_signed30 e = {{1}}; + rustsecp256k1zkp_v0_10_0_modinv32_signed30 f = modinfo->modulus; + rustsecp256k1zkp_v0_10_0_modinv32_signed30 g = *x; int i; int32_t zeta = -1; /* zeta = -(delta+1/2); delta is initially 1/2. */ /* Do 20 iterations of 30 divsteps each = 600 divsteps. 590 suffices for 256-bit inputs. */ for (i = 0; i < 20; ++i) { /* Compute transition matrix and new zeta after 30 divsteps. */ - rustsecp256k1zkp_v0_8_0_modinv32_trans2x2 t; - zeta = rustsecp256k1zkp_v0_8_0_modinv32_divsteps_30(zeta, f.v[0], g.v[0], &t); + rustsecp256k1zkp_v0_10_0_modinv32_trans2x2 t; + zeta = rustsecp256k1zkp_v0_10_0_modinv32_divsteps_30(zeta, f.v[0], g.v[0], &t); /* Update d,e using that transition matrix. */ - rustsecp256k1zkp_v0_8_0_modinv32_update_de_30(&d, &e, &t, modinfo); + rustsecp256k1zkp_v0_10_0_modinv32_update_de_30(&d, &e, &t, modinfo); /* Update f,g using that transition matrix. */ -#ifdef VERIFY - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, -1) > 0); /* f > -modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, 1) <= 0); /* f <= modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&g, 9, &modinfo->modulus, -1) > 0); /* g > -modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&g, 9, &modinfo->modulus, 1) < 0); /* g < modulus */ -#endif - rustsecp256k1zkp_v0_8_0_modinv32_update_fg_30(&f, &g, &t); -#ifdef VERIFY - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, -1) > 0); /* f > -modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, 1) <= 0); /* f <= modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&g, 9, &modinfo->modulus, -1) > 0); /* g > -modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&g, 9, &modinfo->modulus, 1) < 0); /* g < modulus */ -#endif + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, -1) > 0); /* f > -modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, 1) <= 0); /* f <= modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&g, 9, &modinfo->modulus, -1) > 0); /* g > -modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&g, 9, &modinfo->modulus, 1) < 0); /* g < modulus */ + + rustsecp256k1zkp_v0_10_0_modinv32_update_fg_30(&f, &g, &t); + + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, -1) > 0); /* f > -modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, 1) <= 0); /* f <= modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&g, 9, &modinfo->modulus, -1) > 0); /* g > -modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&g, 9, &modinfo->modulus, 1) < 0); /* g < modulus */ } /* At this point sufficient iterations have been performed that g must have reached 0 * and (if g was not originally 0) f must now equal +/- GCD of the initial f, g * values i.e. +/- 1, and d now contains +/- the modular inverse. */ -#ifdef VERIFY + /* g == 0 */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&g, 9, &SECP256K1_SIGNED30_ONE, 0) == 0); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&g, 9, &SECP256K1_SIGNED30_ONE, 0) == 0); /* |f| == 1, or (x == 0 and d == 0 and |f|=modulus) */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&f, 9, &SECP256K1_SIGNED30_ONE, -1) == 0 || - rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&f, 9, &SECP256K1_SIGNED30_ONE, 1) == 0 || - (rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(x, 9, &SECP256K1_SIGNED30_ONE, 0) == 0 && - rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&d, 9, &SECP256K1_SIGNED30_ONE, 0) == 0 && - (rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, 1) == 0 || - rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, -1) == 0))); -#endif + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&f, 9, &SECP256K1_SIGNED30_ONE, -1) == 0 || + rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&f, 9, &SECP256K1_SIGNED30_ONE, 1) == 0 || + (rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(x, 9, &SECP256K1_SIGNED30_ONE, 0) == 0 && + rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&d, 9, &SECP256K1_SIGNED30_ONE, 0) == 0 && + (rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, 1) == 0 || + rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, -1) == 0))); /* Optionally negate d, normalize to [0,modulus), and return it. */ - rustsecp256k1zkp_v0_8_0_modinv32_normalize_30(&d, f.v[8], modinfo); + rustsecp256k1zkp_v0_10_0_modinv32_normalize_30(&d, f.v[8], modinfo); *x = d; } /* Compute the inverse of x modulo modinfo->modulus, and replace x with it (variable time). */ -static void rustsecp256k1zkp_v0_8_0_modinv32_var(rustsecp256k1zkp_v0_8_0_modinv32_signed30 *x, const rustsecp256k1zkp_v0_8_0_modinv32_modinfo *modinfo) { +static void rustsecp256k1zkp_v0_10_0_modinv32_var(rustsecp256k1zkp_v0_10_0_modinv32_signed30 *x, const rustsecp256k1zkp_v0_10_0_modinv32_modinfo *modinfo) { /* Start with d=0, e=1, f=modulus, g=x, eta=-1. */ - rustsecp256k1zkp_v0_8_0_modinv32_signed30 d = {{0, 0, 0, 0, 0, 0, 0, 0, 0}}; - rustsecp256k1zkp_v0_8_0_modinv32_signed30 e = {{1, 0, 0, 0, 0, 0, 0, 0, 0}}; - rustsecp256k1zkp_v0_8_0_modinv32_signed30 f = modinfo->modulus; - rustsecp256k1zkp_v0_8_0_modinv32_signed30 g = *x; + rustsecp256k1zkp_v0_10_0_modinv32_signed30 d = {{0, 0, 0, 0, 0, 0, 0, 0, 0}}; + rustsecp256k1zkp_v0_10_0_modinv32_signed30 e = {{1, 0, 0, 0, 0, 0, 0, 0, 0}}; + rustsecp256k1zkp_v0_10_0_modinv32_signed30 f = modinfo->modulus; + rustsecp256k1zkp_v0_10_0_modinv32_signed30 g = *x; #ifdef VERIFY int i = 0; #endif @@ -521,18 +595,18 @@ static void rustsecp256k1zkp_v0_8_0_modinv32_var(rustsecp256k1zkp_v0_8_0_modinv3 /* Do iterations of 30 divsteps each until g=0. */ while (1) { /* Compute transition matrix and new eta after 30 divsteps. */ - rustsecp256k1zkp_v0_8_0_modinv32_trans2x2 t; - eta = rustsecp256k1zkp_v0_8_0_modinv32_divsteps_30_var(eta, f.v[0], g.v[0], &t); + rustsecp256k1zkp_v0_10_0_modinv32_trans2x2 t; + eta = rustsecp256k1zkp_v0_10_0_modinv32_divsteps_30_var(eta, f.v[0], g.v[0], &t); /* Update d,e using that transition matrix. */ - rustsecp256k1zkp_v0_8_0_modinv32_update_de_30(&d, &e, &t, modinfo); + rustsecp256k1zkp_v0_10_0_modinv32_update_de_30(&d, &e, &t, modinfo); /* Update f,g using that transition matrix. */ -#ifdef VERIFY - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, -1) > 0); /* f > -modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, -1) > 0); /* g > -modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, 1) < 0); /* g < modulus */ -#endif - rustsecp256k1zkp_v0_8_0_modinv32_update_fg_30_var(len, &f, &g, &t); + + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, -1) > 0); /* f > -modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, -1) > 0); /* g > -modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, 1) < 0); /* g < modulus */ + + rustsecp256k1zkp_v0_10_0_modinv32_update_fg_30_var(len, &f, &g, &t); /* If the bottom limb of g is 0, there is a chance g=0. */ if (g.v[0] == 0) { cond = 0; @@ -556,32 +630,98 @@ static void rustsecp256k1zkp_v0_8_0_modinv32_var(rustsecp256k1zkp_v0_8_0_modinv3 g.v[len - 2] |= (uint32_t)gn << 30; --len; } -#ifdef VERIFY + VERIFY_CHECK(++i < 25); /* We should never need more than 25*30 = 750 divsteps */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, -1) > 0); /* f > -modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, -1) > 0); /* g > -modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, 1) < 0); /* g < modulus */ -#endif + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, -1) > 0); /* f > -modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, -1) > 0); /* g > -modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, 1) < 0); /* g < modulus */ } /* At this point g is 0 and (if g was not originally 0) f must now equal +/- GCD of * the initial f, g values i.e. +/- 1, and d now contains +/- the modular inverse. */ -#ifdef VERIFY + /* g == 0 */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&g, len, &SECP256K1_SIGNED30_ONE, 0) == 0); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&g, len, &SECP256K1_SIGNED30_ONE, 0) == 0); /* |f| == 1, or (x == 0 and d == 0 and |f|=modulus) */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&f, len, &SECP256K1_SIGNED30_ONE, -1) == 0 || - rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&f, len, &SECP256K1_SIGNED30_ONE, 1) == 0 || - (rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(x, 9, &SECP256K1_SIGNED30_ONE, 0) == 0 && - rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&d, 9, &SECP256K1_SIGNED30_ONE, 0) == 0 && - (rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 1) == 0 || - rustsecp256k1zkp_v0_8_0_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, -1) == 0))); -#endif + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&f, len, &SECP256K1_SIGNED30_ONE, -1) == 0 || + rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&f, len, &SECP256K1_SIGNED30_ONE, 1) == 0 || + (rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(x, 9, &SECP256K1_SIGNED30_ONE, 0) == 0 && + rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&d, 9, &SECP256K1_SIGNED30_ONE, 0) == 0 && + (rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 1) == 0 || + rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, -1) == 0))); /* Optionally negate d, normalize to [0,modulus), and return it. */ - rustsecp256k1zkp_v0_8_0_modinv32_normalize_30(&d, f.v[len - 1], modinfo); + rustsecp256k1zkp_v0_10_0_modinv32_normalize_30(&d, f.v[len - 1], modinfo); *x = d; } +/* Do up to 50 iterations of 30 posdivsteps (up to 1500 steps; more is extremely rare) each until f=1. + * In VERIFY mode use a lower number of iterations (750, close to the median 756), so failure actually occurs. */ +#ifdef VERIFY +#define JACOBI32_ITERATIONS 25 +#else +#define JACOBI32_ITERATIONS 50 +#endif + +/* Compute the Jacobi symbol of x modulo modinfo->modulus (variable time). gcd(x,modulus) must be 1. */ +static int rustsecp256k1zkp_v0_10_0_jacobi32_maybe_var(const rustsecp256k1zkp_v0_10_0_modinv32_signed30 *x, const rustsecp256k1zkp_v0_10_0_modinv32_modinfo *modinfo) { + /* Start with f=modulus, g=x, eta=-1. */ + rustsecp256k1zkp_v0_10_0_modinv32_signed30 f = modinfo->modulus; + rustsecp256k1zkp_v0_10_0_modinv32_signed30 g = *x; + int j, len = 9; + int32_t eta = -1; /* eta = -delta; delta is initially 1 */ + int32_t cond, fn, gn; + int jac = 0; + int count; + + /* The input limbs must all be non-negative. */ + VERIFY_CHECK(g.v[0] >= 0 && g.v[1] >= 0 && g.v[2] >= 0 && g.v[3] >= 0 && g.v[4] >= 0 && g.v[5] >= 0 && g.v[6] >= 0 && g.v[7] >= 0 && g.v[8] >= 0); + + /* If x > 0, then if the loop below converges, it converges to f=g=gcd(x,modulus). Since we + * require that gcd(x,modulus)=1 and modulus>=3, x cannot be 0. Thus, we must reach f=1 (or + * time out). */ + VERIFY_CHECK((g.v[0] | g.v[1] | g.v[2] | g.v[3] | g.v[4] | g.v[5] | g.v[6] | g.v[7] | g.v[8]) != 0); + + for (count = 0; count < JACOBI32_ITERATIONS; ++count) { + /* Compute transition matrix and new eta after 30 posdivsteps. */ + rustsecp256k1zkp_v0_10_0_modinv32_trans2x2 t; + eta = rustsecp256k1zkp_v0_10_0_modinv32_posdivsteps_30_var(eta, f.v[0] | ((uint32_t)f.v[1] << 30), g.v[0] | ((uint32_t)g.v[1] << 30), &t, &jac); + /* Update f,g using that transition matrix. */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 0) > 0); /* f > 0 */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, 0) > 0); /* g > 0 */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, 1) < 0); /* g < modulus */ + + rustsecp256k1zkp_v0_10_0_modinv32_update_fg_30_var(len, &f, &g, &t); + /* If the bottom limb of f is 1, there is a chance that f=1. */ + if (f.v[0] == 1) { + cond = 0; + /* Check if the other limbs are also 0. */ + for (j = 1; j < len; ++j) { + cond |= f.v[j]; + } + /* If so, we're done. If f=1, the Jacobi symbol (g | f)=1. */ + if (cond == 0) return 1 - 2*(jac & 1); + } + + /* Determine if len>1 and limb (len-1) of both f and g is 0. */ + fn = f.v[len - 1]; + gn = g.v[len - 1]; + cond = ((int32_t)len - 2) >> 31; + cond |= fn; + cond |= gn; + /* If so, reduce length. */ + if (cond == 0) --len; + + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 0) > 0); /* f > 0 */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, 0) > 0); /* g > 0 */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, 1) < 0); /* g < modulus */ + } + + /* The loop failed to converge to f=g after 1500 iterations. Return 0, indicating unknown result. */ + return 0; +} + #endif /* SECP256K1_MODINV32_IMPL_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modinv64.h b/secp256k1-zkp-sys/depend/secp256k1/src/modinv64.h index b947ef8e..4a91bca6 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modinv64.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modinv64.h @@ -7,10 +7,6 @@ #ifndef SECP256K1_MODINV64_H #define SECP256K1_MODINV64_H -#if defined HAVE_CONFIG_H -#include "libsecp256k1-config.h" -#endif - #include "util.h" #ifndef SECP256K1_WIDEMUL_INT128 @@ -22,15 +18,15 @@ * Its value is sum(v[i] * 2^(62*i), i=0..4). */ typedef struct { int64_t v[5]; -} rustsecp256k1zkp_v0_8_0_modinv64_signed62; +} rustsecp256k1zkp_v0_10_0_modinv64_signed62; typedef struct { /* The modulus in signed62 notation, must be odd and in [3, 2^256]. */ - rustsecp256k1zkp_v0_8_0_modinv64_signed62 modulus; + rustsecp256k1zkp_v0_10_0_modinv64_signed62 modulus; /* modulus^{-1} mod 2^62 */ uint64_t modulus_inv62; -} rustsecp256k1zkp_v0_8_0_modinv64_modinfo; +} rustsecp256k1zkp_v0_10_0_modinv64_modinfo; /* Replace x with its modular inverse mod modinfo->modulus. x must be in range [0, modulus). * If x is zero, the result will be zero as well. If not, the inverse must exist (i.e., the gcd of @@ -38,9 +34,14 @@ typedef struct { * * On output, all of x's limbs will be in [0, 2^62). */ -static void rustsecp256k1zkp_v0_8_0_modinv64_var(rustsecp256k1zkp_v0_8_0_modinv64_signed62 *x, const rustsecp256k1zkp_v0_8_0_modinv64_modinfo *modinfo); +static void rustsecp256k1zkp_v0_10_0_modinv64_var(rustsecp256k1zkp_v0_10_0_modinv64_signed62 *x, const rustsecp256k1zkp_v0_10_0_modinv64_modinfo *modinfo); + +/* Same as rustsecp256k1zkp_v0_10_0_modinv64_var, but constant time in x (not in the modulus). */ +static void rustsecp256k1zkp_v0_10_0_modinv64(rustsecp256k1zkp_v0_10_0_modinv64_signed62 *x, const rustsecp256k1zkp_v0_10_0_modinv64_modinfo *modinfo); -/* Same as rustsecp256k1zkp_v0_8_0_modinv64_var, but constant time in x (not in the modulus). */ -static void rustsecp256k1zkp_v0_8_0_modinv64(rustsecp256k1zkp_v0_8_0_modinv64_signed62 *x, const rustsecp256k1zkp_v0_8_0_modinv64_modinfo *modinfo); +/* Compute the Jacobi symbol for (x | modinfo->modulus). x must be coprime with modulus (and thus + * cannot be 0, as modulus >= 3). All limbs of x must be non-negative. Returns 0 if the result + * cannot be computed. */ +static int rustsecp256k1zkp_v0_10_0_jacobi64_maybe_var(const rustsecp256k1zkp_v0_10_0_modinv64_signed62 *x, const rustsecp256k1zkp_v0_10_0_modinv64_modinfo *modinfo); #endif /* SECP256K1_MODINV64_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modinv64_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modinv64_impl.h index d012a6cb..1e764c3d 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modinv64_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modinv64_impl.h @@ -7,10 +7,9 @@ #ifndef SECP256K1_MODINV64_IMPL_H #define SECP256K1_MODINV64_IMPL_H +#include "int128.h" #include "modinv64.h" -#include "util.h" - /* This file implements modular inversion based on the paper "Fast constant-time gcd computation and * modular inversion" by Daniel J. Bernstein and Bo-Yin Yang. * @@ -18,37 +17,48 @@ * implementation for N=62, using 62-bit signed limbs represented as int64_t. */ +/* Data type for transition matrices (see section 3 of explanation). + * + * t = [ u v ] + * [ q r ] + */ +typedef struct { + int64_t u, v, q, r; +} rustsecp256k1zkp_v0_10_0_modinv64_trans2x2; + #ifdef VERIFY /* Helper function to compute the absolute value of an int64_t. * (we don't use abs/labs/llabs as it depends on the int sizes). */ -static int64_t rustsecp256k1zkp_v0_8_0_modinv64_abs(int64_t v) { +static int64_t rustsecp256k1zkp_v0_10_0_modinv64_abs(int64_t v) { VERIFY_CHECK(v > INT64_MIN); if (v < 0) return -v; return v; } -static const rustsecp256k1zkp_v0_8_0_modinv64_signed62 SECP256K1_SIGNED62_ONE = {{1}}; +static const rustsecp256k1zkp_v0_10_0_modinv64_signed62 SECP256K1_SIGNED62_ONE = {{1}}; /* Compute a*factor and put it in r. All but the top limb in r will be in range [0,2^62). */ -static void rustsecp256k1zkp_v0_8_0_modinv64_mul_62(rustsecp256k1zkp_v0_8_0_modinv64_signed62 *r, const rustsecp256k1zkp_v0_8_0_modinv64_signed62 *a, int alen, int64_t factor) { - const int64_t M62 = (int64_t)(UINT64_MAX >> 2); - int128_t c = 0; +static void rustsecp256k1zkp_v0_10_0_modinv64_mul_62(rustsecp256k1zkp_v0_10_0_modinv64_signed62 *r, const rustsecp256k1zkp_v0_10_0_modinv64_signed62 *a, int alen, int64_t factor) { + const uint64_t M62 = UINT64_MAX >> 2; + rustsecp256k1zkp_v0_10_0_int128 c, d; int i; + rustsecp256k1zkp_v0_10_0_i128_from_i64(&c, 0); for (i = 0; i < 4; ++i) { - if (i < alen) c += (int128_t)a->v[i] * factor; - r->v[i] = (int64_t)c & M62; c >>= 62; + if (i < alen) rustsecp256k1zkp_v0_10_0_i128_accum_mul(&c, a->v[i], factor); + r->v[i] = rustsecp256k1zkp_v0_10_0_i128_to_u64(&c) & M62; rustsecp256k1zkp_v0_10_0_i128_rshift(&c, 62); } - if (4 < alen) c += (int128_t)a->v[4] * factor; - VERIFY_CHECK(c == (int64_t)c); - r->v[4] = (int64_t)c; + if (4 < alen) rustsecp256k1zkp_v0_10_0_i128_accum_mul(&c, a->v[4], factor); + rustsecp256k1zkp_v0_10_0_i128_from_i64(&d, rustsecp256k1zkp_v0_10_0_i128_to_i64(&c)); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_i128_eq_var(&c, &d)); + r->v[4] = rustsecp256k1zkp_v0_10_0_i128_to_i64(&c); } /* Return -1 for ab*factor. A has alen limbs; b has 5. */ -static int rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(const rustsecp256k1zkp_v0_8_0_modinv64_signed62 *a, int alen, const rustsecp256k1zkp_v0_8_0_modinv64_signed62 *b, int64_t factor) { +static int rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(const rustsecp256k1zkp_v0_10_0_modinv64_signed62 *a, int alen, const rustsecp256k1zkp_v0_10_0_modinv64_signed62 *b, int64_t factor) { int i; - rustsecp256k1zkp_v0_8_0_modinv64_signed62 am, bm; - rustsecp256k1zkp_v0_8_0_modinv64_mul_62(&am, a, alen, 1); /* Normalize all but the top limb of a. */ - rustsecp256k1zkp_v0_8_0_modinv64_mul_62(&bm, b, 5, factor); + rustsecp256k1zkp_v0_10_0_modinv64_signed62 am, bm; + rustsecp256k1zkp_v0_10_0_modinv64_mul_62(&am, a, alen, 1); /* Normalize all but the top limb of a. */ + rustsecp256k1zkp_v0_10_0_modinv64_mul_62(&bm, b, 5, factor); for (i = 0; i < 4; ++i) { /* Verify that all but the top limb of a and b are normalized. */ VERIFY_CHECK(am.v[i] >> 62 == 0); @@ -60,16 +70,25 @@ static int rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(const rustsecp256k1zkp_v0 } return 0; } + +/* Check if the determinant of t is equal to 1 << n. If abs, check if |det t| == 1 << n. */ +static int rustsecp256k1zkp_v0_10_0_modinv64_det_check_pow2(const rustsecp256k1zkp_v0_10_0_modinv64_trans2x2 *t, unsigned int n, int abs) { + rustsecp256k1zkp_v0_10_0_int128 a; + rustsecp256k1zkp_v0_10_0_i128_det(&a, t->u, t->v, t->q, t->r); + if (rustsecp256k1zkp_v0_10_0_i128_check_pow2(&a, n, 1)) return 1; + if (abs && rustsecp256k1zkp_v0_10_0_i128_check_pow2(&a, n, -1)) return 1; + return 0; +} #endif /* Take as input a signed62 number in range (-2*modulus,modulus), and add a multiple of the modulus * to it to bring it to range [0,modulus). If sign < 0, the input will also be negated in the * process. The input must have limbs in range (-2^62,2^62). The output will have limbs in range * [0,2^62). */ -static void rustsecp256k1zkp_v0_8_0_modinv64_normalize_62(rustsecp256k1zkp_v0_8_0_modinv64_signed62 *r, int64_t sign, const rustsecp256k1zkp_v0_8_0_modinv64_modinfo *modinfo) { +static void rustsecp256k1zkp_v0_10_0_modinv64_normalize_62(rustsecp256k1zkp_v0_10_0_modinv64_signed62 *r, int64_t sign, const rustsecp256k1zkp_v0_10_0_modinv64_modinfo *modinfo) { const int64_t M62 = (int64_t)(UINT64_MAX >> 2); int64_t r0 = r->v[0], r1 = r->v[1], r2 = r->v[2], r3 = r->v[3], r4 = r->v[4]; - int64_t cond_add, cond_negate; + volatile int64_t cond_add, cond_negate; #ifdef VERIFY /* Verify that all limbs are in range (-2^62,2^62). */ @@ -78,8 +97,8 @@ static void rustsecp256k1zkp_v0_8_0_modinv64_normalize_62(rustsecp256k1zkp_v0_8_ VERIFY_CHECK(r->v[i] >= -M62); VERIFY_CHECK(r->v[i] <= M62); } - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(r, 5, &modinfo->modulus, -2) > 0); /* r > -2*modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(r, 5, &modinfo->modulus, 1) < 0); /* r < modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(r, 5, &modinfo->modulus, -2) > 0); /* r > -2*modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(r, 5, &modinfo->modulus, 1) < 0); /* r < modulus */ #endif /* In a first step, add the modulus if the input is negative, and then negate if requested. @@ -125,26 +144,15 @@ static void rustsecp256k1zkp_v0_8_0_modinv64_normalize_62(rustsecp256k1zkp_v0_8_ r->v[3] = r3; r->v[4] = r4; -#ifdef VERIFY VERIFY_CHECK(r0 >> 62 == 0); VERIFY_CHECK(r1 >> 62 == 0); VERIFY_CHECK(r2 >> 62 == 0); VERIFY_CHECK(r3 >> 62 == 0); VERIFY_CHECK(r4 >> 62 == 0); - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(r, 5, &modinfo->modulus, 0) >= 0); /* r >= 0 */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(r, 5, &modinfo->modulus, 1) < 0); /* r < modulus */ -#endif + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(r, 5, &modinfo->modulus, 0) >= 0); /* r >= 0 */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(r, 5, &modinfo->modulus, 1) < 0); /* r < modulus */ } -/* Data type for transition matrices (see section 3 of explanation). - * - * t = [ u v ] - * [ q r ] - */ -typedef struct { - int64_t u, v, q, r; -} rustsecp256k1zkp_v0_8_0_modinv64_trans2x2; - /* Compute the transition matrix and eta for 59 divsteps (where zeta=-(delta+1/2)). * Note that the transformation matrix is scaled by 2^62 and not 2^59. * @@ -156,7 +164,7 @@ typedef struct { * * Implements the divsteps_n_matrix function from the explanation. */ -static int64_t rustsecp256k1zkp_v0_8_0_modinv64_divsteps_59(int64_t zeta, uint64_t f0, uint64_t g0, rustsecp256k1zkp_v0_8_0_modinv64_trans2x2 *t) { +static int64_t rustsecp256k1zkp_v0_10_0_modinv64_divsteps_59(int64_t zeta, uint64_t f0, uint64_t g0, rustsecp256k1zkp_v0_10_0_modinv64_trans2x2 *t) { /* u,v,q,r are the elements of the transformation matrix being built up, * starting with the identity matrix times 8 (because the caller expects * a result scaled by 2^62). Semantically they are signed integers @@ -165,7 +173,8 @@ static int64_t rustsecp256k1zkp_v0_8_0_modinv64_divsteps_59(int64_t zeta, uint64 * being inside [-2^63,2^63) means that casting to signed works correctly. */ uint64_t u = 8, v = 0, q = 0, r = 8; - uint64_t c1, c2, f = f0, g = g0, x, y, z; + volatile uint64_t c1, c2; + uint64_t mask1, mask2, f = f0, g = g0, x, y, z; int i; for (i = 3; i < 62; ++i) { @@ -174,23 +183,25 @@ static int64_t rustsecp256k1zkp_v0_8_0_modinv64_divsteps_59(int64_t zeta, uint64 VERIFY_CHECK((q * f0 + r * g0) == g << i); /* Compute conditional masks for (zeta < 0) and for (g & 1). */ c1 = zeta >> 63; - c2 = -(g & 1); + mask1 = c1; + c2 = g & 1; + mask2 = -c2; /* Compute x,y,z, conditionally negated versions of f,u,v. */ - x = (f ^ c1) - c1; - y = (u ^ c1) - c1; - z = (v ^ c1) - c1; + x = (f ^ mask1) - mask1; + y = (u ^ mask1) - mask1; + z = (v ^ mask1) - mask1; /* Conditionally add x,y,z to g,q,r. */ - g += x & c2; - q += y & c2; - r += z & c2; + g += x & mask2; + q += y & mask2; + r += z & mask2; /* In what follows, c1 is a condition mask for (zeta < 0) and (g & 1). */ - c1 &= c2; + mask1 &= mask2; /* Conditionally change zeta into -zeta-2 or zeta-1. */ - zeta = (zeta ^ c1) - 1; + zeta = (zeta ^ mask1) - 1; /* Conditionally add g,q,r to f,u,v. */ - f += g & c1; - u += q & c1; - v += r & c1; + f += g & mask1; + u += q & mask1; + v += r & mask1; /* Shifts */ g >>= 1; u <<= 1; @@ -203,13 +214,15 @@ static int64_t rustsecp256k1zkp_v0_8_0_modinv64_divsteps_59(int64_t zeta, uint64 t->v = (int64_t)v; t->q = (int64_t)q; t->r = (int64_t)r; + /* The determinant of t must be a power of two. This guarantees that multiplication with t * does not change the gcd of f and g, apart from adding a power-of-2 factor to it (which * will be divided out again). As each divstep's individual matrix has determinant 2, the * aggregate of 59 of them will have determinant 2^59. Multiplying with the initial * 8*identity (which has determinant 2^6) means the overall outputs has determinant * 2^65. */ - VERIFY_CHECK((int128_t)t->u * t->r - (int128_t)t->v * t->q == ((int128_t)1) << 65); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_det_check_pow2(t, 65, 0)); + return zeta; } @@ -223,8 +236,8 @@ static int64_t rustsecp256k1zkp_v0_8_0_modinv64_divsteps_59(int64_t zeta, uint64 * * Implements the divsteps_n_matrix_var function from the explanation. */ -static int64_t rustsecp256k1zkp_v0_8_0_modinv64_divsteps_62_var(int64_t eta, uint64_t f0, uint64_t g0, rustsecp256k1zkp_v0_8_0_modinv64_trans2x2 *t) { - /* Transformation matrix; see comments in rustsecp256k1zkp_v0_8_0_modinv64_divsteps_62. */ +static int64_t rustsecp256k1zkp_v0_10_0_modinv64_divsteps_62_var(int64_t eta, uint64_t f0, uint64_t g0, rustsecp256k1zkp_v0_10_0_modinv64_trans2x2 *t) { + /* Transformation matrix; see comments in rustsecp256k1zkp_v0_10_0_modinv64_divsteps_62. */ uint64_t u = 1, v = 0, q = 0, r = 1; uint64_t f = f0, g = g0, m; uint32_t w; @@ -232,7 +245,7 @@ static int64_t rustsecp256k1zkp_v0_8_0_modinv64_divsteps_62_var(int64_t eta, uin for (;;) { /* Use a sentinel bit to count zeros only up to i. */ - zeros = rustsecp256k1zkp_v0_8_0_ctz64_var(g | (UINT64_MAX << i)); + zeros = rustsecp256k1zkp_v0_10_0_ctz64_var(g | (UINT64_MAX << i)); /* Perform zeros divsteps at once; they all just divide g by two. */ g >>= zeros; u <<= zeros; @@ -256,7 +269,7 @@ static int64_t rustsecp256k1zkp_v0_8_0_modinv64_divsteps_62_var(int64_t eta, uin tmp = v; v = r; r = -tmp; /* Use a formula to cancel out up to 6 bits of g. Also, no more than i can be cancelled * out (as we'd be done before that point), and no more than eta+1 can be done as its - * will flip again once that happens. */ + * sign will flip again once that happens. */ limit = ((int)eta + 1) > i ? i : ((int)eta + 1); VERIFY_CHECK(limit > 0 && limit <= 62); /* m is a mask for the bottom min(limit, 6) bits. */ @@ -286,11 +299,105 @@ static int64_t rustsecp256k1zkp_v0_8_0_modinv64_divsteps_62_var(int64_t eta, uin t->v = (int64_t)v; t->q = (int64_t)q; t->r = (int64_t)r; + /* The determinant of t must be a power of two. This guarantees that multiplication with t * does not change the gcd of f and g, apart from adding a power-of-2 factor to it (which * will be divided out again). As each divstep's individual matrix has determinant 2, the * aggregate of 62 of them will have determinant 2^62. */ - VERIFY_CHECK((int128_t)t->u * t->r - (int128_t)t->v * t->q == ((int128_t)1) << 62); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_det_check_pow2(t, 62, 0)); + + return eta; +} + +/* Compute the transition matrix and eta for 62 posdivsteps (variable time, eta=-delta), and keeps track + * of the Jacobi symbol along the way. f0 and g0 must be f and g mod 2^64 rather than 2^62, because + * Jacobi tracking requires knowing (f mod 8) rather than just (f mod 2). + * + * Input: eta: initial eta + * f0: bottom limb of initial f + * g0: bottom limb of initial g + * Output: t: transition matrix + * Input/Output: (*jacp & 1) is bitflipped if and only if the Jacobi symbol of (f | g) changes sign + * by applying the returned transformation matrix to it. The other bits of *jacp may + * change, but are meaningless. + * Return: final eta + */ +static int64_t rustsecp256k1zkp_v0_10_0_modinv64_posdivsteps_62_var(int64_t eta, uint64_t f0, uint64_t g0, rustsecp256k1zkp_v0_10_0_modinv64_trans2x2 *t, int *jacp) { + /* Transformation matrix; see comments in rustsecp256k1zkp_v0_10_0_modinv64_divsteps_62. */ + uint64_t u = 1, v = 0, q = 0, r = 1; + uint64_t f = f0, g = g0, m; + uint32_t w; + int i = 62, limit, zeros; + int jac = *jacp; + + for (;;) { + /* Use a sentinel bit to count zeros only up to i. */ + zeros = rustsecp256k1zkp_v0_10_0_ctz64_var(g | (UINT64_MAX << i)); + /* Perform zeros divsteps at once; they all just divide g by two. */ + g >>= zeros; + u <<= zeros; + v <<= zeros; + eta -= zeros; + i -= zeros; + /* Update the bottom bit of jac: when dividing g by an odd power of 2, + * if (f mod 8) is 3 or 5, the Jacobi symbol changes sign. */ + jac ^= (zeros & ((f >> 1) ^ (f >> 2))); + /* We're done once we've done 62 posdivsteps. */ + if (i == 0) break; + VERIFY_CHECK((f & 1) == 1); + VERIFY_CHECK((g & 1) == 1); + VERIFY_CHECK((u * f0 + v * g0) == f << (62 - i)); + VERIFY_CHECK((q * f0 + r * g0) == g << (62 - i)); + /* If eta is negative, negate it and replace f,g with g,f. */ + if (eta < 0) { + uint64_t tmp; + eta = -eta; + tmp = f; f = g; g = tmp; + tmp = u; u = q; q = tmp; + tmp = v; v = r; r = tmp; + /* Update bottom bit of jac: when swapping f and g, the Jacobi symbol changes sign + * if both f and g are 3 mod 4. */ + jac ^= ((f & g) >> 1); + /* Use a formula to cancel out up to 6 bits of g. Also, no more than i can be cancelled + * out (as we'd be done before that point), and no more than eta+1 can be done as its + * sign will flip again once that happens. */ + limit = ((int)eta + 1) > i ? i : ((int)eta + 1); + VERIFY_CHECK(limit > 0 && limit <= 62); + /* m is a mask for the bottom min(limit, 6) bits. */ + m = (UINT64_MAX >> (64 - limit)) & 63U; + /* Find what multiple of f must be added to g to cancel its bottom min(limit, 6) + * bits. */ + w = (f * g * (f * f - 2)) & m; + } else { + /* In this branch, use a simpler formula that only lets us cancel up to 4 bits of g, as + * eta tends to be smaller here. */ + limit = ((int)eta + 1) > i ? i : ((int)eta + 1); + VERIFY_CHECK(limit > 0 && limit <= 62); + /* m is a mask for the bottom min(limit, 4) bits. */ + m = (UINT64_MAX >> (64 - limit)) & 15U; + /* Find what multiple of f must be added to g to cancel its bottom min(limit, 4) + * bits. */ + w = f + (((f + 1) & 4) << 1); + w = (-w * g) & m; + } + g += f * w; + q += u * w; + r += v * w; + VERIFY_CHECK((g & m) == 0); + } + /* Return data in t and return value. */ + t->u = (int64_t)u; + t->v = (int64_t)v; + t->q = (int64_t)q; + t->r = (int64_t)r; + + /* The determinant of t must be a power of two. This guarantees that multiplication with t + * does not change the gcd of f and g, apart from adding a power-of-2 factor to it (which + * will be divided out again). As each divstep's individual matrix has determinant 2 or -2, + * the aggregate of 62 of them will have determinant 2^62 or -2^62. */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_det_check_pow2(t, 62, 1)); + + *jacp = jac; return eta; } @@ -301,124 +408,140 @@ static int64_t rustsecp256k1zkp_v0_8_0_modinv64_divsteps_62_var(int64_t eta, uin * * This implements the update_de function from the explanation. */ -static void rustsecp256k1zkp_v0_8_0_modinv64_update_de_62(rustsecp256k1zkp_v0_8_0_modinv64_signed62 *d, rustsecp256k1zkp_v0_8_0_modinv64_signed62 *e, const rustsecp256k1zkp_v0_8_0_modinv64_trans2x2 *t, const rustsecp256k1zkp_v0_8_0_modinv64_modinfo* modinfo) { - const int64_t M62 = (int64_t)(UINT64_MAX >> 2); +static void rustsecp256k1zkp_v0_10_0_modinv64_update_de_62(rustsecp256k1zkp_v0_10_0_modinv64_signed62 *d, rustsecp256k1zkp_v0_10_0_modinv64_signed62 *e, const rustsecp256k1zkp_v0_10_0_modinv64_trans2x2 *t, const rustsecp256k1zkp_v0_10_0_modinv64_modinfo* modinfo) { + const uint64_t M62 = UINT64_MAX >> 2; const int64_t d0 = d->v[0], d1 = d->v[1], d2 = d->v[2], d3 = d->v[3], d4 = d->v[4]; const int64_t e0 = e->v[0], e1 = e->v[1], e2 = e->v[2], e3 = e->v[3], e4 = e->v[4]; const int64_t u = t->u, v = t->v, q = t->q, r = t->r; int64_t md, me, sd, se; - int128_t cd, ce; -#ifdef VERIFY - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(d, 5, &modinfo->modulus, -2) > 0); /* d > -2*modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(d, 5, &modinfo->modulus, 1) < 0); /* d < modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(e, 5, &modinfo->modulus, -2) > 0); /* e > -2*modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(e, 5, &modinfo->modulus, 1) < 0); /* e < modulus */ - VERIFY_CHECK((rustsecp256k1zkp_v0_8_0_modinv64_abs(u) + rustsecp256k1zkp_v0_8_0_modinv64_abs(v)) >= 0); /* |u|+|v| doesn't overflow */ - VERIFY_CHECK((rustsecp256k1zkp_v0_8_0_modinv64_abs(q) + rustsecp256k1zkp_v0_8_0_modinv64_abs(r)) >= 0); /* |q|+|r| doesn't overflow */ - VERIFY_CHECK((rustsecp256k1zkp_v0_8_0_modinv64_abs(u) + rustsecp256k1zkp_v0_8_0_modinv64_abs(v)) <= M62 + 1); /* |u|+|v| <= 2^62 */ - VERIFY_CHECK((rustsecp256k1zkp_v0_8_0_modinv64_abs(q) + rustsecp256k1zkp_v0_8_0_modinv64_abs(r)) <= M62 + 1); /* |q|+|r| <= 2^62 */ -#endif + rustsecp256k1zkp_v0_10_0_int128 cd, ce; + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(d, 5, &modinfo->modulus, -2) > 0); /* d > -2*modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(d, 5, &modinfo->modulus, 1) < 0); /* d < modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(e, 5, &modinfo->modulus, -2) > 0); /* e > -2*modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(e, 5, &modinfo->modulus, 1) < 0); /* e < modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_abs(u) <= (((int64_t)1 << 62) - rustsecp256k1zkp_v0_10_0_modinv64_abs(v))); /* |u|+|v| <= 2^62 */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_abs(q) <= (((int64_t)1 << 62) - rustsecp256k1zkp_v0_10_0_modinv64_abs(r))); /* |q|+|r| <= 2^62 */ + /* [md,me] start as zero; plus [u,q] if d is negative; plus [v,r] if e is negative. */ sd = d4 >> 63; se = e4 >> 63; md = (u & sd) + (v & se); me = (q & sd) + (r & se); /* Begin computing t*[d,e]. */ - cd = (int128_t)u * d0 + (int128_t)v * e0; - ce = (int128_t)q * d0 + (int128_t)r * e0; + rustsecp256k1zkp_v0_10_0_i128_mul(&cd, u, d0); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cd, v, e0); + rustsecp256k1zkp_v0_10_0_i128_mul(&ce, q, d0); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&ce, r, e0); /* Correct md,me so that t*[d,e]+modulus*[md,me] has 62 zero bottom bits. */ - md -= (modinfo->modulus_inv62 * (uint64_t)cd + md) & M62; - me -= (modinfo->modulus_inv62 * (uint64_t)ce + me) & M62; + md -= (modinfo->modulus_inv62 * rustsecp256k1zkp_v0_10_0_i128_to_u64(&cd) + md) & M62; + me -= (modinfo->modulus_inv62 * rustsecp256k1zkp_v0_10_0_i128_to_u64(&ce) + me) & M62; /* Update the beginning of computation for t*[d,e]+modulus*[md,me] now md,me are known. */ - cd += (int128_t)modinfo->modulus.v[0] * md; - ce += (int128_t)modinfo->modulus.v[0] * me; + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cd, modinfo->modulus.v[0], md); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&ce, modinfo->modulus.v[0], me); /* Verify that the low 62 bits of the computation are indeed zero, and then throw them away. */ - VERIFY_CHECK(((int64_t)cd & M62) == 0); cd >>= 62; - VERIFY_CHECK(((int64_t)ce & M62) == 0); ce >>= 62; + VERIFY_CHECK((rustsecp256k1zkp_v0_10_0_i128_to_u64(&cd) & M62) == 0); rustsecp256k1zkp_v0_10_0_i128_rshift(&cd, 62); + VERIFY_CHECK((rustsecp256k1zkp_v0_10_0_i128_to_u64(&ce) & M62) == 0); rustsecp256k1zkp_v0_10_0_i128_rshift(&ce, 62); /* Compute limb 1 of t*[d,e]+modulus*[md,me], and store it as output limb 0 (= down shift). */ - cd += (int128_t)u * d1 + (int128_t)v * e1; - ce += (int128_t)q * d1 + (int128_t)r * e1; + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cd, u, d1); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cd, v, e1); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&ce, q, d1); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&ce, r, e1); if (modinfo->modulus.v[1]) { /* Optimize for the case where limb of modulus is zero. */ - cd += (int128_t)modinfo->modulus.v[1] * md; - ce += (int128_t)modinfo->modulus.v[1] * me; + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cd, modinfo->modulus.v[1], md); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&ce, modinfo->modulus.v[1], me); } - d->v[0] = (int64_t)cd & M62; cd >>= 62; - e->v[0] = (int64_t)ce & M62; ce >>= 62; + d->v[0] = rustsecp256k1zkp_v0_10_0_i128_to_u64(&cd) & M62; rustsecp256k1zkp_v0_10_0_i128_rshift(&cd, 62); + e->v[0] = rustsecp256k1zkp_v0_10_0_i128_to_u64(&ce) & M62; rustsecp256k1zkp_v0_10_0_i128_rshift(&ce, 62); /* Compute limb 2 of t*[d,e]+modulus*[md,me], and store it as output limb 1. */ - cd += (int128_t)u * d2 + (int128_t)v * e2; - ce += (int128_t)q * d2 + (int128_t)r * e2; + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cd, u, d2); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cd, v, e2); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&ce, q, d2); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&ce, r, e2); if (modinfo->modulus.v[2]) { /* Optimize for the case where limb of modulus is zero. */ - cd += (int128_t)modinfo->modulus.v[2] * md; - ce += (int128_t)modinfo->modulus.v[2] * me; + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cd, modinfo->modulus.v[2], md); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&ce, modinfo->modulus.v[2], me); } - d->v[1] = (int64_t)cd & M62; cd >>= 62; - e->v[1] = (int64_t)ce & M62; ce >>= 62; + d->v[1] = rustsecp256k1zkp_v0_10_0_i128_to_u64(&cd) & M62; rustsecp256k1zkp_v0_10_0_i128_rshift(&cd, 62); + e->v[1] = rustsecp256k1zkp_v0_10_0_i128_to_u64(&ce) & M62; rustsecp256k1zkp_v0_10_0_i128_rshift(&ce, 62); /* Compute limb 3 of t*[d,e]+modulus*[md,me], and store it as output limb 2. */ - cd += (int128_t)u * d3 + (int128_t)v * e3; - ce += (int128_t)q * d3 + (int128_t)r * e3; + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cd, u, d3); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cd, v, e3); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&ce, q, d3); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&ce, r, e3); if (modinfo->modulus.v[3]) { /* Optimize for the case where limb of modulus is zero. */ - cd += (int128_t)modinfo->modulus.v[3] * md; - ce += (int128_t)modinfo->modulus.v[3] * me; + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cd, modinfo->modulus.v[3], md); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&ce, modinfo->modulus.v[3], me); } - d->v[2] = (int64_t)cd & M62; cd >>= 62; - e->v[2] = (int64_t)ce & M62; ce >>= 62; + d->v[2] = rustsecp256k1zkp_v0_10_0_i128_to_u64(&cd) & M62; rustsecp256k1zkp_v0_10_0_i128_rshift(&cd, 62); + e->v[2] = rustsecp256k1zkp_v0_10_0_i128_to_u64(&ce) & M62; rustsecp256k1zkp_v0_10_0_i128_rshift(&ce, 62); /* Compute limb 4 of t*[d,e]+modulus*[md,me], and store it as output limb 3. */ - cd += (int128_t)u * d4 + (int128_t)v * e4; - ce += (int128_t)q * d4 + (int128_t)r * e4; - cd += (int128_t)modinfo->modulus.v[4] * md; - ce += (int128_t)modinfo->modulus.v[4] * me; - d->v[3] = (int64_t)cd & M62; cd >>= 62; - e->v[3] = (int64_t)ce & M62; ce >>= 62; + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cd, u, d4); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cd, v, e4); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&ce, q, d4); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&ce, r, e4); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cd, modinfo->modulus.v[4], md); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&ce, modinfo->modulus.v[4], me); + d->v[3] = rustsecp256k1zkp_v0_10_0_i128_to_u64(&cd) & M62; rustsecp256k1zkp_v0_10_0_i128_rshift(&cd, 62); + e->v[3] = rustsecp256k1zkp_v0_10_0_i128_to_u64(&ce) & M62; rustsecp256k1zkp_v0_10_0_i128_rshift(&ce, 62); /* What remains is limb 5 of t*[d,e]+modulus*[md,me]; store it as output limb 4. */ - d->v[4] = (int64_t)cd; - e->v[4] = (int64_t)ce; -#ifdef VERIFY - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(d, 5, &modinfo->modulus, -2) > 0); /* d > -2*modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(d, 5, &modinfo->modulus, 1) < 0); /* d < modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(e, 5, &modinfo->modulus, -2) > 0); /* e > -2*modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(e, 5, &modinfo->modulus, 1) < 0); /* e < modulus */ -#endif + d->v[4] = rustsecp256k1zkp_v0_10_0_i128_to_i64(&cd); + e->v[4] = rustsecp256k1zkp_v0_10_0_i128_to_i64(&ce); + + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(d, 5, &modinfo->modulus, -2) > 0); /* d > -2*modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(d, 5, &modinfo->modulus, 1) < 0); /* d < modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(e, 5, &modinfo->modulus, -2) > 0); /* e > -2*modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(e, 5, &modinfo->modulus, 1) < 0); /* e < modulus */ } /* Compute (t/2^62) * [f, g], where t is a transition matrix scaled by 2^62. * * This implements the update_fg function from the explanation. */ -static void rustsecp256k1zkp_v0_8_0_modinv64_update_fg_62(rustsecp256k1zkp_v0_8_0_modinv64_signed62 *f, rustsecp256k1zkp_v0_8_0_modinv64_signed62 *g, const rustsecp256k1zkp_v0_8_0_modinv64_trans2x2 *t) { - const int64_t M62 = (int64_t)(UINT64_MAX >> 2); +static void rustsecp256k1zkp_v0_10_0_modinv64_update_fg_62(rustsecp256k1zkp_v0_10_0_modinv64_signed62 *f, rustsecp256k1zkp_v0_10_0_modinv64_signed62 *g, const rustsecp256k1zkp_v0_10_0_modinv64_trans2x2 *t) { + const uint64_t M62 = UINT64_MAX >> 2; const int64_t f0 = f->v[0], f1 = f->v[1], f2 = f->v[2], f3 = f->v[3], f4 = f->v[4]; const int64_t g0 = g->v[0], g1 = g->v[1], g2 = g->v[2], g3 = g->v[3], g4 = g->v[4]; const int64_t u = t->u, v = t->v, q = t->q, r = t->r; - int128_t cf, cg; + rustsecp256k1zkp_v0_10_0_int128 cf, cg; /* Start computing t*[f,g]. */ - cf = (int128_t)u * f0 + (int128_t)v * g0; - cg = (int128_t)q * f0 + (int128_t)r * g0; + rustsecp256k1zkp_v0_10_0_i128_mul(&cf, u, f0); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cf, v, g0); + rustsecp256k1zkp_v0_10_0_i128_mul(&cg, q, f0); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cg, r, g0); /* Verify that the bottom 62 bits of the result are zero, and then throw them away. */ - VERIFY_CHECK(((int64_t)cf & M62) == 0); cf >>= 62; - VERIFY_CHECK(((int64_t)cg & M62) == 0); cg >>= 62; + VERIFY_CHECK((rustsecp256k1zkp_v0_10_0_i128_to_u64(&cf) & M62) == 0); rustsecp256k1zkp_v0_10_0_i128_rshift(&cf, 62); + VERIFY_CHECK((rustsecp256k1zkp_v0_10_0_i128_to_u64(&cg) & M62) == 0); rustsecp256k1zkp_v0_10_0_i128_rshift(&cg, 62); /* Compute limb 1 of t*[f,g], and store it as output limb 0 (= down shift). */ - cf += (int128_t)u * f1 + (int128_t)v * g1; - cg += (int128_t)q * f1 + (int128_t)r * g1; - f->v[0] = (int64_t)cf & M62; cf >>= 62; - g->v[0] = (int64_t)cg & M62; cg >>= 62; + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cf, u, f1); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cf, v, g1); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cg, q, f1); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cg, r, g1); + f->v[0] = rustsecp256k1zkp_v0_10_0_i128_to_u64(&cf) & M62; rustsecp256k1zkp_v0_10_0_i128_rshift(&cf, 62); + g->v[0] = rustsecp256k1zkp_v0_10_0_i128_to_u64(&cg) & M62; rustsecp256k1zkp_v0_10_0_i128_rshift(&cg, 62); /* Compute limb 2 of t*[f,g], and store it as output limb 1. */ - cf += (int128_t)u * f2 + (int128_t)v * g2; - cg += (int128_t)q * f2 + (int128_t)r * g2; - f->v[1] = (int64_t)cf & M62; cf >>= 62; - g->v[1] = (int64_t)cg & M62; cg >>= 62; + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cf, u, f2); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cf, v, g2); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cg, q, f2); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cg, r, g2); + f->v[1] = rustsecp256k1zkp_v0_10_0_i128_to_u64(&cf) & M62; rustsecp256k1zkp_v0_10_0_i128_rshift(&cf, 62); + g->v[1] = rustsecp256k1zkp_v0_10_0_i128_to_u64(&cg) & M62; rustsecp256k1zkp_v0_10_0_i128_rshift(&cg, 62); /* Compute limb 3 of t*[f,g], and store it as output limb 2. */ - cf += (int128_t)u * f3 + (int128_t)v * g3; - cg += (int128_t)q * f3 + (int128_t)r * g3; - f->v[2] = (int64_t)cf & M62; cf >>= 62; - g->v[2] = (int64_t)cg & M62; cg >>= 62; + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cf, u, f3); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cf, v, g3); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cg, q, f3); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cg, r, g3); + f->v[2] = rustsecp256k1zkp_v0_10_0_i128_to_u64(&cf) & M62; rustsecp256k1zkp_v0_10_0_i128_rshift(&cf, 62); + g->v[2] = rustsecp256k1zkp_v0_10_0_i128_to_u64(&cg) & M62; rustsecp256k1zkp_v0_10_0_i128_rshift(&cg, 62); /* Compute limb 4 of t*[f,g], and store it as output limb 3. */ - cf += (int128_t)u * f4 + (int128_t)v * g4; - cg += (int128_t)q * f4 + (int128_t)r * g4; - f->v[3] = (int64_t)cf & M62; cf >>= 62; - g->v[3] = (int64_t)cg & M62; cg >>= 62; + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cf, u, f4); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cf, v, g4); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cg, q, f4); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cg, r, g4); + f->v[3] = rustsecp256k1zkp_v0_10_0_i128_to_u64(&cf) & M62; rustsecp256k1zkp_v0_10_0_i128_rshift(&cf, 62); + g->v[3] = rustsecp256k1zkp_v0_10_0_i128_to_u64(&cg) & M62; rustsecp256k1zkp_v0_10_0_i128_rshift(&cg, 62); /* What remains is limb 5 of t*[f,g]; store it as output limb 4. */ - f->v[4] = (int64_t)cf; - g->v[4] = (int64_t)cg; + f->v[4] = rustsecp256k1zkp_v0_10_0_i128_to_i64(&cf); + g->v[4] = rustsecp256k1zkp_v0_10_0_i128_to_i64(&cg); } /* Compute (t/2^62) * [f, g], where t is a transition matrix for 62 divsteps. @@ -427,96 +550,97 @@ static void rustsecp256k1zkp_v0_8_0_modinv64_update_fg_62(rustsecp256k1zkp_v0_8_ * * This implements the update_fg function from the explanation. */ -static void rustsecp256k1zkp_v0_8_0_modinv64_update_fg_62_var(int len, rustsecp256k1zkp_v0_8_0_modinv64_signed62 *f, rustsecp256k1zkp_v0_8_0_modinv64_signed62 *g, const rustsecp256k1zkp_v0_8_0_modinv64_trans2x2 *t) { - const int64_t M62 = (int64_t)(UINT64_MAX >> 2); +static void rustsecp256k1zkp_v0_10_0_modinv64_update_fg_62_var(int len, rustsecp256k1zkp_v0_10_0_modinv64_signed62 *f, rustsecp256k1zkp_v0_10_0_modinv64_signed62 *g, const rustsecp256k1zkp_v0_10_0_modinv64_trans2x2 *t) { + const uint64_t M62 = UINT64_MAX >> 2; const int64_t u = t->u, v = t->v, q = t->q, r = t->r; int64_t fi, gi; - int128_t cf, cg; + rustsecp256k1zkp_v0_10_0_int128 cf, cg; int i; VERIFY_CHECK(len > 0); /* Start computing t*[f,g]. */ fi = f->v[0]; gi = g->v[0]; - cf = (int128_t)u * fi + (int128_t)v * gi; - cg = (int128_t)q * fi + (int128_t)r * gi; + rustsecp256k1zkp_v0_10_0_i128_mul(&cf, u, fi); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cf, v, gi); + rustsecp256k1zkp_v0_10_0_i128_mul(&cg, q, fi); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cg, r, gi); /* Verify that the bottom 62 bits of the result are zero, and then throw them away. */ - VERIFY_CHECK(((int64_t)cf & M62) == 0); cf >>= 62; - VERIFY_CHECK(((int64_t)cg & M62) == 0); cg >>= 62; + VERIFY_CHECK((rustsecp256k1zkp_v0_10_0_i128_to_u64(&cf) & M62) == 0); rustsecp256k1zkp_v0_10_0_i128_rshift(&cf, 62); + VERIFY_CHECK((rustsecp256k1zkp_v0_10_0_i128_to_u64(&cg) & M62) == 0); rustsecp256k1zkp_v0_10_0_i128_rshift(&cg, 62); /* Now iteratively compute limb i=1..len of t*[f,g], and store them in output limb i-1 (shifting * down by 62 bits). */ for (i = 1; i < len; ++i) { fi = f->v[i]; gi = g->v[i]; - cf += (int128_t)u * fi + (int128_t)v * gi; - cg += (int128_t)q * fi + (int128_t)r * gi; - f->v[i - 1] = (int64_t)cf & M62; cf >>= 62; - g->v[i - 1] = (int64_t)cg & M62; cg >>= 62; + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cf, u, fi); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cf, v, gi); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cg, q, fi); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&cg, r, gi); + f->v[i - 1] = rustsecp256k1zkp_v0_10_0_i128_to_u64(&cf) & M62; rustsecp256k1zkp_v0_10_0_i128_rshift(&cf, 62); + g->v[i - 1] = rustsecp256k1zkp_v0_10_0_i128_to_u64(&cg) & M62; rustsecp256k1zkp_v0_10_0_i128_rshift(&cg, 62); } /* What remains is limb (len) of t*[f,g]; store it as output limb (len-1). */ - f->v[len - 1] = (int64_t)cf; - g->v[len - 1] = (int64_t)cg; + f->v[len - 1] = rustsecp256k1zkp_v0_10_0_i128_to_i64(&cf); + g->v[len - 1] = rustsecp256k1zkp_v0_10_0_i128_to_i64(&cg); } /* Compute the inverse of x modulo modinfo->modulus, and replace x with it (constant time in x). */ -static void rustsecp256k1zkp_v0_8_0_modinv64(rustsecp256k1zkp_v0_8_0_modinv64_signed62 *x, const rustsecp256k1zkp_v0_8_0_modinv64_modinfo *modinfo) { +static void rustsecp256k1zkp_v0_10_0_modinv64(rustsecp256k1zkp_v0_10_0_modinv64_signed62 *x, const rustsecp256k1zkp_v0_10_0_modinv64_modinfo *modinfo) { /* Start with d=0, e=1, f=modulus, g=x, zeta=-1. */ - rustsecp256k1zkp_v0_8_0_modinv64_signed62 d = {{0, 0, 0, 0, 0}}; - rustsecp256k1zkp_v0_8_0_modinv64_signed62 e = {{1, 0, 0, 0, 0}}; - rustsecp256k1zkp_v0_8_0_modinv64_signed62 f = modinfo->modulus; - rustsecp256k1zkp_v0_8_0_modinv64_signed62 g = *x; + rustsecp256k1zkp_v0_10_0_modinv64_signed62 d = {{0, 0, 0, 0, 0}}; + rustsecp256k1zkp_v0_10_0_modinv64_signed62 e = {{1, 0, 0, 0, 0}}; + rustsecp256k1zkp_v0_10_0_modinv64_signed62 f = modinfo->modulus; + rustsecp256k1zkp_v0_10_0_modinv64_signed62 g = *x; int i; int64_t zeta = -1; /* zeta = -(delta+1/2); delta starts at 1/2. */ /* Do 10 iterations of 59 divsteps each = 590 divsteps. This suffices for 256-bit inputs. */ for (i = 0; i < 10; ++i) { /* Compute transition matrix and new zeta after 59 divsteps. */ - rustsecp256k1zkp_v0_8_0_modinv64_trans2x2 t; - zeta = rustsecp256k1zkp_v0_8_0_modinv64_divsteps_59(zeta, f.v[0], g.v[0], &t); + rustsecp256k1zkp_v0_10_0_modinv64_trans2x2 t; + zeta = rustsecp256k1zkp_v0_10_0_modinv64_divsteps_59(zeta, f.v[0], g.v[0], &t); /* Update d,e using that transition matrix. */ - rustsecp256k1zkp_v0_8_0_modinv64_update_de_62(&d, &e, &t, modinfo); + rustsecp256k1zkp_v0_10_0_modinv64_update_de_62(&d, &e, &t, modinfo); /* Update f,g using that transition matrix. */ -#ifdef VERIFY - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&f, 5, &modinfo->modulus, -1) > 0); /* f > -modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&f, 5, &modinfo->modulus, 1) <= 0); /* f <= modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&g, 5, &modinfo->modulus, -1) > 0); /* g > -modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&g, 5, &modinfo->modulus, 1) < 0); /* g < modulus */ -#endif - rustsecp256k1zkp_v0_8_0_modinv64_update_fg_62(&f, &g, &t); -#ifdef VERIFY - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&f, 5, &modinfo->modulus, -1) > 0); /* f > -modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&f, 5, &modinfo->modulus, 1) <= 0); /* f <= modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&g, 5, &modinfo->modulus, -1) > 0); /* g > -modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&g, 5, &modinfo->modulus, 1) < 0); /* g < modulus */ -#endif + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&f, 5, &modinfo->modulus, -1) > 0); /* f > -modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&f, 5, &modinfo->modulus, 1) <= 0); /* f <= modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&g, 5, &modinfo->modulus, -1) > 0); /* g > -modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&g, 5, &modinfo->modulus, 1) < 0); /* g < modulus */ + + rustsecp256k1zkp_v0_10_0_modinv64_update_fg_62(&f, &g, &t); + + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&f, 5, &modinfo->modulus, -1) > 0); /* f > -modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&f, 5, &modinfo->modulus, 1) <= 0); /* f <= modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&g, 5, &modinfo->modulus, -1) > 0); /* g > -modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&g, 5, &modinfo->modulus, 1) < 0); /* g < modulus */ } /* At this point sufficient iterations have been performed that g must have reached 0 * and (if g was not originally 0) f must now equal +/- GCD of the initial f, g * values i.e. +/- 1, and d now contains +/- the modular inverse. */ -#ifdef VERIFY + /* g == 0 */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&g, 5, &SECP256K1_SIGNED62_ONE, 0) == 0); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&g, 5, &SECP256K1_SIGNED62_ONE, 0) == 0); /* |f| == 1, or (x == 0 and d == 0 and |f|=modulus) */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&f, 5, &SECP256K1_SIGNED62_ONE, -1) == 0 || - rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&f, 5, &SECP256K1_SIGNED62_ONE, 1) == 0 || - (rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(x, 5, &SECP256K1_SIGNED62_ONE, 0) == 0 && - rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&d, 5, &SECP256K1_SIGNED62_ONE, 0) == 0 && - (rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&f, 5, &modinfo->modulus, 1) == 0 || - rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&f, 5, &modinfo->modulus, -1) == 0))); -#endif + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&f, 5, &SECP256K1_SIGNED62_ONE, -1) == 0 || + rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&f, 5, &SECP256K1_SIGNED62_ONE, 1) == 0 || + (rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(x, 5, &SECP256K1_SIGNED62_ONE, 0) == 0 && + rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&d, 5, &SECP256K1_SIGNED62_ONE, 0) == 0 && + (rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&f, 5, &modinfo->modulus, 1) == 0 || + rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&f, 5, &modinfo->modulus, -1) == 0))); /* Optionally negate d, normalize to [0,modulus), and return it. */ - rustsecp256k1zkp_v0_8_0_modinv64_normalize_62(&d, f.v[4], modinfo); + rustsecp256k1zkp_v0_10_0_modinv64_normalize_62(&d, f.v[4], modinfo); *x = d; } /* Compute the inverse of x modulo modinfo->modulus, and replace x with it (variable time). */ -static void rustsecp256k1zkp_v0_8_0_modinv64_var(rustsecp256k1zkp_v0_8_0_modinv64_signed62 *x, const rustsecp256k1zkp_v0_8_0_modinv64_modinfo *modinfo) { +static void rustsecp256k1zkp_v0_10_0_modinv64_var(rustsecp256k1zkp_v0_10_0_modinv64_signed62 *x, const rustsecp256k1zkp_v0_10_0_modinv64_modinfo *modinfo) { /* Start with d=0, e=1, f=modulus, g=x, eta=-1. */ - rustsecp256k1zkp_v0_8_0_modinv64_signed62 d = {{0, 0, 0, 0, 0}}; - rustsecp256k1zkp_v0_8_0_modinv64_signed62 e = {{1, 0, 0, 0, 0}}; - rustsecp256k1zkp_v0_8_0_modinv64_signed62 f = modinfo->modulus; - rustsecp256k1zkp_v0_8_0_modinv64_signed62 g = *x; + rustsecp256k1zkp_v0_10_0_modinv64_signed62 d = {{0, 0, 0, 0, 0}}; + rustsecp256k1zkp_v0_10_0_modinv64_signed62 e = {{1, 0, 0, 0, 0}}; + rustsecp256k1zkp_v0_10_0_modinv64_signed62 f = modinfo->modulus; + rustsecp256k1zkp_v0_10_0_modinv64_signed62 g = *x; #ifdef VERIFY int i = 0; #endif @@ -527,18 +651,17 @@ static void rustsecp256k1zkp_v0_8_0_modinv64_var(rustsecp256k1zkp_v0_8_0_modinv6 /* Do iterations of 62 divsteps each until g=0. */ while (1) { /* Compute transition matrix and new eta after 62 divsteps. */ - rustsecp256k1zkp_v0_8_0_modinv64_trans2x2 t; - eta = rustsecp256k1zkp_v0_8_0_modinv64_divsteps_62_var(eta, f.v[0], g.v[0], &t); + rustsecp256k1zkp_v0_10_0_modinv64_trans2x2 t; + eta = rustsecp256k1zkp_v0_10_0_modinv64_divsteps_62_var(eta, f.v[0], g.v[0], &t); /* Update d,e using that transition matrix. */ - rustsecp256k1zkp_v0_8_0_modinv64_update_de_62(&d, &e, &t, modinfo); + rustsecp256k1zkp_v0_10_0_modinv64_update_de_62(&d, &e, &t, modinfo); /* Update f,g using that transition matrix. */ -#ifdef VERIFY - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, -1) > 0); /* f > -modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&g, len, &modinfo->modulus, -1) > 0); /* g > -modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&g, len, &modinfo->modulus, 1) < 0); /* g < modulus */ -#endif - rustsecp256k1zkp_v0_8_0_modinv64_update_fg_62_var(len, &f, &g, &t); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, -1) > 0); /* f > -modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&g, len, &modinfo->modulus, -1) > 0); /* g > -modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&g, len, &modinfo->modulus, 1) < 0); /* g < modulus */ + + rustsecp256k1zkp_v0_10_0_modinv64_update_fg_62_var(len, &f, &g, &t); /* If the bottom limb of g is zero, there is a chance that g=0. */ if (g.v[0] == 0) { cond = 0; @@ -562,32 +685,98 @@ static void rustsecp256k1zkp_v0_8_0_modinv64_var(rustsecp256k1zkp_v0_8_0_modinv6 g.v[len - 2] |= (uint64_t)gn << 62; --len; } -#ifdef VERIFY + VERIFY_CHECK(++i < 12); /* We should never need more than 12*62 = 744 divsteps */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, -1) > 0); /* f > -modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&g, len, &modinfo->modulus, -1) > 0); /* g > -modulus */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&g, len, &modinfo->modulus, 1) < 0); /* g < modulus */ -#endif + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, -1) > 0); /* f > -modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&g, len, &modinfo->modulus, -1) > 0); /* g > -modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&g, len, &modinfo->modulus, 1) < 0); /* g < modulus */ } /* At this point g is 0 and (if g was not originally 0) f must now equal +/- GCD of * the initial f, g values i.e. +/- 1, and d now contains +/- the modular inverse. */ -#ifdef VERIFY + /* g == 0 */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&g, len, &SECP256K1_SIGNED62_ONE, 0) == 0); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&g, len, &SECP256K1_SIGNED62_ONE, 0) == 0); /* |f| == 1, or (x == 0 and d == 0 and |f|=modulus) */ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&f, len, &SECP256K1_SIGNED62_ONE, -1) == 0 || - rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&f, len, &SECP256K1_SIGNED62_ONE, 1) == 0 || - (rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(x, 5, &SECP256K1_SIGNED62_ONE, 0) == 0 && - rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&d, 5, &SECP256K1_SIGNED62_ONE, 0) == 0 && - (rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, 1) == 0 || - rustsecp256k1zkp_v0_8_0_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, -1) == 0))); -#endif + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&f, len, &SECP256K1_SIGNED62_ONE, -1) == 0 || + rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&f, len, &SECP256K1_SIGNED62_ONE, 1) == 0 || + (rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(x, 5, &SECP256K1_SIGNED62_ONE, 0) == 0 && + rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&d, 5, &SECP256K1_SIGNED62_ONE, 0) == 0 && + (rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, 1) == 0 || + rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, -1) == 0))); /* Optionally negate d, normalize to [0,modulus), and return it. */ - rustsecp256k1zkp_v0_8_0_modinv64_normalize_62(&d, f.v[len - 1], modinfo); + rustsecp256k1zkp_v0_10_0_modinv64_normalize_62(&d, f.v[len - 1], modinfo); *x = d; } +/* Do up to 25 iterations of 62 posdivsteps (up to 1550 steps; more is extremely rare) each until f=1. + * In VERIFY mode use a lower number of iterations (744, close to the median 756), so failure actually occurs. */ +#ifdef VERIFY +#define JACOBI64_ITERATIONS 12 +#else +#define JACOBI64_ITERATIONS 25 +#endif + +/* Compute the Jacobi symbol of x modulo modinfo->modulus (variable time). gcd(x,modulus) must be 1. */ +static int rustsecp256k1zkp_v0_10_0_jacobi64_maybe_var(const rustsecp256k1zkp_v0_10_0_modinv64_signed62 *x, const rustsecp256k1zkp_v0_10_0_modinv64_modinfo *modinfo) { + /* Start with f=modulus, g=x, eta=-1. */ + rustsecp256k1zkp_v0_10_0_modinv64_signed62 f = modinfo->modulus; + rustsecp256k1zkp_v0_10_0_modinv64_signed62 g = *x; + int j, len = 5; + int64_t eta = -1; /* eta = -delta; delta is initially 1 */ + int64_t cond, fn, gn; + int jac = 0; + int count; + + /* The input limbs must all be non-negative. */ + VERIFY_CHECK(g.v[0] >= 0 && g.v[1] >= 0 && g.v[2] >= 0 && g.v[3] >= 0 && g.v[4] >= 0); + + /* If x > 0, then if the loop below converges, it converges to f=g=gcd(x,modulus). Since we + * require that gcd(x,modulus)=1 and modulus>=3, x cannot be 0. Thus, we must reach f=1 (or + * time out). */ + VERIFY_CHECK((g.v[0] | g.v[1] | g.v[2] | g.v[3] | g.v[4]) != 0); + + for (count = 0; count < JACOBI64_ITERATIONS; ++count) { + /* Compute transition matrix and new eta after 62 posdivsteps. */ + rustsecp256k1zkp_v0_10_0_modinv64_trans2x2 t; + eta = rustsecp256k1zkp_v0_10_0_modinv64_posdivsteps_62_var(eta, f.v[0] | ((uint64_t)f.v[1] << 62), g.v[0] | ((uint64_t)g.v[1] << 62), &t, &jac); + /* Update f,g using that transition matrix. */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, 0) > 0); /* f > 0 */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&g, len, &modinfo->modulus, 0) > 0); /* g > 0 */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&g, len, &modinfo->modulus, 1) < 0); /* g < modulus */ + + rustsecp256k1zkp_v0_10_0_modinv64_update_fg_62_var(len, &f, &g, &t); + /* If the bottom limb of f is 1, there is a chance that f=1. */ + if (f.v[0] == 1) { + cond = 0; + /* Check if the other limbs are also 0. */ + for (j = 1; j < len; ++j) { + cond |= f.v[j]; + } + /* If so, we're done. When f=1, the Jacobi symbol (g | f)=1. */ + if (cond == 0) return 1 - 2*(jac & 1); + } + + /* Determine if len>1 and limb (len-1) of both f and g is 0. */ + fn = f.v[len - 1]; + gn = g.v[len - 1]; + cond = ((int64_t)len - 2) >> 63; + cond |= fn; + cond |= gn; + /* If so, reduce length. */ + if (cond == 0) --len; + + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, 0) > 0); /* f > 0 */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&g, len, &modinfo->modulus, 0) > 0); /* g > 0 */ + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_modinv64_mul_cmp_62(&g, len, &modinfo->modulus, 1) < 0); /* g < modulus */ + } + + /* The loop failed to converge to f=g after 1550 iterations. Return 0, indicating unknown result. */ + return 0; +} + #endif /* SECP256K1_MODINV64_IMPL_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/Makefile.am.include b/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/Makefile.am.include index e6693a9e..1aa81488 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/Makefile.am.include +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/Makefile.am.include @@ -1,4 +1,4 @@ -include_HEADERS += include/rustsecp256k1zkp_v0_8_0_bppp.h +include_HEADERS += include/rustsecp256k1zkp_v0_10_0_bppp.h noinst_HEADERS += src/modules/bppp/bppp_util.h noinst_HEADERS += src/modules/bppp/main_impl.h noinst_HEADERS += src/modules/bppp/bppp_transcript_impl.h @@ -8,6 +8,6 @@ noinst_HEADERS += src/modules/bppp/tests_impl.h if USE_BENCHMARK noinst_PROGRAMS += bench_bppp bench_bppp_SOURCES = src/bench_bppp.c -bench_bppp_LDADD = libsecp256k1.la $(SECP_LIBS) -bench_bppp_LDFLAGS = -static +bench_bppp_LDADD = libsecp256k1.la +bench_bppp_CPPFLAGS = $(SECP_CONFIG_DEFINES) endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/bppp_norm_product_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/bppp_norm_product_impl.h index c2aa466b..3cceebed 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/bppp_norm_product_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/bppp_norm_product_impl.h @@ -4,38 +4,38 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef _SECP256K1_MODULE_BPPP_PP_NORM_PRODUCT_ -#define _SECP256K1_MODULE_BPPP_PP_NORM_PRODUCT_ +#ifndef SECP256K1_MODULE_BPPP_PP_NORM_PRODUCT_H +#define SECP256K1_MODULE_BPPP_PP_NORM_PRODUCT_H -#include "group.h" -#include "scalar.h" -#include "ecmult.h" -#include "ecmult_gen.h" -#include "hash.h" +#include "../../group.h" +#include "../../scalar.h" +#include "../../ecmult.h" +#include "../../ecmult_gen.h" +#include "../../hash.h" -#include "modules/bppp/main.h" -#include "modules/bppp/bppp_util.h" -#include "modules/bppp/bppp_transcript_impl.h" +#include "../bppp/main.h" +#include "../bppp/bppp_util.h" +#include "../bppp/bppp_transcript_impl.h" /* Computes the inner product of two vectors of scalars * with elements starting from offset a and offset b * skipping elements according to specified step. * Returns: Sum_{i=0..len-1}(a[offset_a + i*step] * b[offset_b + i*step]) */ -static int rustsecp256k1zkp_v0_8_0_scalar_inner_product( - rustsecp256k1zkp_v0_8_0_scalar* res, - const rustsecp256k1zkp_v0_8_0_scalar* a_vec, +static int rustsecp256k1zkp_v0_10_0_scalar_inner_product( + rustsecp256k1zkp_v0_10_0_scalar* res, + const rustsecp256k1zkp_v0_10_0_scalar* a_vec, const size_t a_offset, - const rustsecp256k1zkp_v0_8_0_scalar* b_vec, + const rustsecp256k1zkp_v0_10_0_scalar* b_vec, const size_t b_offset, const size_t step, const size_t len ) { size_t i; - rustsecp256k1zkp_v0_8_0_scalar_set_int(res, 0); + rustsecp256k1zkp_v0_10_0_scalar_set_int(res, 0); for (i = 0; i < len; i++) { - rustsecp256k1zkp_v0_8_0_scalar term; - rustsecp256k1zkp_v0_8_0_scalar_mul(&term, &a_vec[a_offset + step*i], &b_vec[b_offset + step*i]); - rustsecp256k1zkp_v0_8_0_scalar_add(res, res, &term); + rustsecp256k1zkp_v0_10_0_scalar term; + rustsecp256k1zkp_v0_10_0_scalar_mul(&term, &a_vec[a_offset + step*i], &b_vec[b_offset + step*i]); + rustsecp256k1zkp_v0_10_0_scalar_add(res, res, &term); } return 1; } @@ -43,51 +43,51 @@ static int rustsecp256k1zkp_v0_8_0_scalar_inner_product( /* Computes the q-weighted inner product of two vectors of scalars * for elements starting from offset a and offset b respectively with the * given step. - * Returns: Sum_{i=0..len-1}(a[offset_a + step*i] * b[offset_b2 + step*i]*q^(i+1)) */ -static int rustsecp256k1zkp_v0_8_0_weighted_scalar_inner_product( - rustsecp256k1zkp_v0_8_0_scalar* res, - const rustsecp256k1zkp_v0_8_0_scalar* a_vec, + * Returns: Sum_{i=0..len-1}(a[offset_a + step*i] * b[offset_b2 + step*i]*mu^(i+1)) */ +static int rustsecp256k1zkp_v0_10_0_weighted_scalar_inner_product( + rustsecp256k1zkp_v0_10_0_scalar* res, + const rustsecp256k1zkp_v0_10_0_scalar* a_vec, const size_t a_offset, - const rustsecp256k1zkp_v0_8_0_scalar* b_vec, + const rustsecp256k1zkp_v0_10_0_scalar* b_vec, const size_t b_offset, const size_t step, const size_t len, - const rustsecp256k1zkp_v0_8_0_scalar* q + const rustsecp256k1zkp_v0_10_0_scalar* mu ) { - rustsecp256k1zkp_v0_8_0_scalar q_pow; + rustsecp256k1zkp_v0_10_0_scalar mu_pow; size_t i; - rustsecp256k1zkp_v0_8_0_scalar_set_int(res, 0); - q_pow = *q; + rustsecp256k1zkp_v0_10_0_scalar_set_int(res, 0); + mu_pow = *mu; for (i = 0; i < len; i++) { - rustsecp256k1zkp_v0_8_0_scalar term; - rustsecp256k1zkp_v0_8_0_scalar_mul(&term, &a_vec[a_offset + step*i], &b_vec[b_offset + step*i]); - rustsecp256k1zkp_v0_8_0_scalar_mul(&term, &term, &q_pow); - rustsecp256k1zkp_v0_8_0_scalar_mul(&q_pow, &q_pow, q); - rustsecp256k1zkp_v0_8_0_scalar_add(res, res, &term); + rustsecp256k1zkp_v0_10_0_scalar term; + rustsecp256k1zkp_v0_10_0_scalar_mul(&term, &a_vec[a_offset + step*i], &b_vec[b_offset + step*i]); + rustsecp256k1zkp_v0_10_0_scalar_mul(&term, &term, &mu_pow); + rustsecp256k1zkp_v0_10_0_scalar_mul(&mu_pow, &mu_pow, mu); + rustsecp256k1zkp_v0_10_0_scalar_add(res, res, &term); } return 1; } -/* Compute the powers of r as r, r^2, r^4 ... r^(2^(n-1)) */ -static void rustsecp256k1zkp_v0_8_0_bppp_powers_of_r(rustsecp256k1zkp_v0_8_0_scalar *powers, const rustsecp256k1zkp_v0_8_0_scalar *r, size_t n) { +/* Compute the powers of rho as rho, rho^2, rho^4 ... rho^(2^(n-1)) */ +static void rustsecp256k1zkp_v0_10_0_bppp_powers_of_rho(rustsecp256k1zkp_v0_10_0_scalar *powers, const rustsecp256k1zkp_v0_10_0_scalar *rho, size_t n) { size_t i; if (n == 0) { return; } - powers[0] = *r; + powers[0] = *rho; for (i = 1; i < n; i++) { - rustsecp256k1zkp_v0_8_0_scalar_sqr(&powers[i], &powers[i - 1]); + rustsecp256k1zkp_v0_10_0_scalar_sqr(&powers[i], &powers[i - 1]); } } typedef struct ecmult_bp_commit_cb_data { - const rustsecp256k1zkp_v0_8_0_scalar *n; - const rustsecp256k1zkp_v0_8_0_ge *g; - const rustsecp256k1zkp_v0_8_0_scalar *l; + const rustsecp256k1zkp_v0_10_0_scalar *n; + const rustsecp256k1zkp_v0_10_0_ge *g; + const rustsecp256k1zkp_v0_10_0_scalar *l; size_t g_len; } ecmult_bp_commit_cb_data; -static int ecmult_bp_commit_cb(rustsecp256k1zkp_v0_8_0_scalar *sc, rustsecp256k1zkp_v0_8_0_ge *pt, size_t idx, void *cbdata) { +static int ecmult_bp_commit_cb(rustsecp256k1zkp_v0_10_0_scalar *sc, rustsecp256k1zkp_v0_10_0_ge *pt, size_t idx, void *cbdata) { ecmult_bp_commit_cb_data *data = (ecmult_bp_commit_cb_data*) cbdata; *pt = data->g[idx]; if (idx < data->g_len) { @@ -99,71 +99,75 @@ static int ecmult_bp_commit_cb(rustsecp256k1zkp_v0_8_0_scalar *sc, rustsecp256k1 } /* Create a commitment `commit` = vG + n_vec*G_vec + l_vec*H_vec where - v = |n_vec*n_vec|_q + . |w|_q denotes q-weighted norm of w and + v = |n_vec*n_vec|_mu + . |w|_mu denotes mu-weighted norm of w and denotes inner product of l and r. */ -static int rustsecp256k1zkp_v0_8_0_bppp_commit( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_scratch_space* scratch, - rustsecp256k1zkp_v0_8_0_ge* commit, - const rustsecp256k1zkp_v0_8_0_bppp_generators* g_vec, - const rustsecp256k1zkp_v0_8_0_scalar* n_vec, +static int rustsecp256k1zkp_v0_10_0_bppp_commit( + const rustsecp256k1zkp_v0_10_0_context* ctx, + rustsecp256k1zkp_v0_10_0_scratch_space* scratch, + rustsecp256k1zkp_v0_10_0_ge* commit, + const rustsecp256k1zkp_v0_10_0_bppp_generators* g_vec, + const rustsecp256k1zkp_v0_10_0_scalar* n_vec, size_t n_vec_len, - const rustsecp256k1zkp_v0_8_0_scalar* l_vec, + const rustsecp256k1zkp_v0_10_0_scalar* l_vec, size_t l_vec_len, - const rustsecp256k1zkp_v0_8_0_scalar* c_vec, + const rustsecp256k1zkp_v0_10_0_scalar* c_vec, size_t c_vec_len, - const rustsecp256k1zkp_v0_8_0_scalar* q + const rustsecp256k1zkp_v0_10_0_scalar* mu ) { - rustsecp256k1zkp_v0_8_0_scalar v, l_c; + rustsecp256k1zkp_v0_10_0_scalar v, l_c; /* First n_vec_len generators are Gs, rest are Hs*/ VERIFY_CHECK(g_vec->n == (n_vec_len + l_vec_len)); +#ifdef VERIFY VERIFY_CHECK(l_vec_len == c_vec_len); +#else + (void)c_vec_len; +#endif /* It is possible to extend to support n_vec and c_vec to not be power of two. For the initial iterations of the code, we stick to powers of two for simplicity.*/ - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_is_power_of_two(n_vec_len)); - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_is_power_of_two(c_vec_len)); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_is_power_of_two(n_vec_len)); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_is_power_of_two(c_vec_len)); - /* Compute v = n_vec*n_vec*q + l_vec*c_vec */ - rustsecp256k1zkp_v0_8_0_weighted_scalar_inner_product(&v, n_vec, 0 /*a offset */, n_vec, 0 /*b offset*/, 1 /*step*/, n_vec_len, q); - rustsecp256k1zkp_v0_8_0_scalar_inner_product(&l_c, l_vec, 0 /*a offset */, c_vec, 0 /*b offset*/, 1 /*step*/, l_vec_len); - rustsecp256k1zkp_v0_8_0_scalar_add(&v, &v, &l_c); + /* Compute v = n_vec*n_vec*mu + l_vec*c_vec */ + rustsecp256k1zkp_v0_10_0_weighted_scalar_inner_product(&v, n_vec, 0 /*a offset */, n_vec, 0 /*b offset*/, 1 /*step*/, n_vec_len, mu); + rustsecp256k1zkp_v0_10_0_scalar_inner_product(&l_c, l_vec, 0 /*a offset */, c_vec, 0 /*b offset*/, 1 /*step*/, l_vec_len); + rustsecp256k1zkp_v0_10_0_scalar_add(&v, &v, &l_c); { ecmult_bp_commit_cb_data data; - rustsecp256k1zkp_v0_8_0_gej commitj; + rustsecp256k1zkp_v0_10_0_gej commitj; data.g = g_vec->gens; data.n = n_vec; data.l = l_vec; data.g_len = n_vec_len; - if (!rustsecp256k1zkp_v0_8_0_ecmult_multi_var(&ctx->error_callback, scratch, &commitj, &v, ecmult_bp_commit_cb, (void*) &data, n_vec_len + l_vec_len)) { + if (!rustsecp256k1zkp_v0_10_0_ecmult_multi_var(&ctx->error_callback, scratch, &commitj, &v, ecmult_bp_commit_cb, (void*) &data, n_vec_len + l_vec_len)) { return 0; } - rustsecp256k1zkp_v0_8_0_ge_set_gej_var(commit, &commitj); + rustsecp256k1zkp_v0_10_0_ge_set_gej_var(commit, &commitj); } return 1; } typedef struct ecmult_x_cb_data { - const rustsecp256k1zkp_v0_8_0_scalar *n; - const rustsecp256k1zkp_v0_8_0_ge *g; - const rustsecp256k1zkp_v0_8_0_scalar *l; - const rustsecp256k1zkp_v0_8_0_scalar *r; - const rustsecp256k1zkp_v0_8_0_scalar *r_inv; + const rustsecp256k1zkp_v0_10_0_scalar *n; + const rustsecp256k1zkp_v0_10_0_ge *g; + const rustsecp256k1zkp_v0_10_0_scalar *l; + const rustsecp256k1zkp_v0_10_0_scalar *rho; + const rustsecp256k1zkp_v0_10_0_scalar *rho_inv; size_t G_GENS_LEN; /* Figure out initialization syntax so that this can also be const */ size_t n_len; } ecmult_x_cb_data; -static int ecmult_x_cb(rustsecp256k1zkp_v0_8_0_scalar *sc, rustsecp256k1zkp_v0_8_0_ge *pt, size_t idx, void *cbdata) { +static int ecmult_x_cb(rustsecp256k1zkp_v0_10_0_scalar *sc, rustsecp256k1zkp_v0_10_0_ge *pt, size_t idx, void *cbdata) { ecmult_x_cb_data *data = (ecmult_x_cb_data*) cbdata; if (idx < data->n_len) { if (idx % 2 == 0) { - rustsecp256k1zkp_v0_8_0_scalar_mul(sc, &data->n[idx + 1], data->r); + rustsecp256k1zkp_v0_10_0_scalar_mul(sc, &data->n[idx + 1], data->rho); *pt = data->g[idx]; } else { - rustsecp256k1zkp_v0_8_0_scalar_mul(sc, &data->n[idx - 1], data->r_inv); + rustsecp256k1zkp_v0_10_0_scalar_mul(sc, &data->n[idx - 1], data->rho_inv); *pt = data->g[idx]; } } else { @@ -180,14 +184,14 @@ static int ecmult_x_cb(rustsecp256k1zkp_v0_8_0_scalar *sc, rustsecp256k1zkp_v0_8 } typedef struct ecmult_r_cb_data { - const rustsecp256k1zkp_v0_8_0_scalar *n1; - const rustsecp256k1zkp_v0_8_0_ge *g1; - const rustsecp256k1zkp_v0_8_0_scalar *l1; + const rustsecp256k1zkp_v0_10_0_scalar *n1; + const rustsecp256k1zkp_v0_10_0_ge *g1; + const rustsecp256k1zkp_v0_10_0_scalar *l1; size_t G_GENS_LEN; size_t n_len; } ecmult_r_cb_data; -static int ecmult_r_cb(rustsecp256k1zkp_v0_8_0_scalar *sc, rustsecp256k1zkp_v0_8_0_ge *pt, size_t idx, void *cbdata) { +static int ecmult_r_cb(rustsecp256k1zkp_v0_10_0_scalar *sc, rustsecp256k1zkp_v0_10_0_ge *pt, size_t idx, void *cbdata) { ecmult_r_cb_data *data = (ecmult_r_cb_data*) cbdata; if (idx < data->n_len) { *sc = data->n1[2*idx + 1]; @@ -201,11 +205,11 @@ static int ecmult_r_cb(rustsecp256k1zkp_v0_8_0_scalar *sc, rustsecp256k1zkp_v0_8 } /* Recursively compute the norm argument proof satisfying the relation - * _q + = v for some commitment - * C = v*G + + . _q is the weighted inner - * product of x with itself, where the weights are the first n powers of q. - * _q = q*x_1^2 + q^2*x_2^2 + q^3*x_3^2 + ... + q^n*x_n^2. - * The API computes q as square of the r challenge (`r^2`). + * _mu + = v for some commitment + * C = v*G + + . _mu is the weighted inner + * product of x with itself, where the weights are the first n powers of mu. + * _mu = mu*x_1^2 + mu^2*x_2^2 + mu^3*x_3^2 + ... + mu^n*x_n^2. + * The API computes mu as square of the r challenge (`r^2`). * * The norm argument is not zero knowledge and does not operate on any secret data. * Thus the following code uses variable time operations while computing the proof. @@ -216,39 +220,45 @@ static int ecmult_r_cb(rustsecp256k1zkp_v0_8_0_scalar *sc, rustsecp256k1zkp_v0_8 * some parent protocol. To use this norm protocol in a standalone manner, the user * should add the commitment, generators and initial public data to the transcript hash. */ -static int rustsecp256k1zkp_v0_8_0_bppp_rangeproof_norm_product_prove( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_scratch_space* scratch, +static int rustsecp256k1zkp_v0_10_0_bppp_rangeproof_norm_product_prove( + const rustsecp256k1zkp_v0_10_0_context* ctx, + rustsecp256k1zkp_v0_10_0_scratch_space* scratch, unsigned char* proof, size_t *proof_len, - rustsecp256k1zkp_v0_8_0_sha256* transcript, /* Transcript hash of the parent protocol */ - const rustsecp256k1zkp_v0_8_0_scalar* r, - rustsecp256k1zkp_v0_8_0_ge* g_vec, + rustsecp256k1zkp_v0_10_0_sha256* transcript, /* Transcript hash of the parent protocol */ + const rustsecp256k1zkp_v0_10_0_scalar* rho, + rustsecp256k1zkp_v0_10_0_ge* g_vec, size_t g_vec_len, - rustsecp256k1zkp_v0_8_0_scalar* n_vec, + rustsecp256k1zkp_v0_10_0_scalar* n_vec, size_t n_vec_len, - rustsecp256k1zkp_v0_8_0_scalar* l_vec, + rustsecp256k1zkp_v0_10_0_scalar* l_vec, size_t l_vec_len, - rustsecp256k1zkp_v0_8_0_scalar* c_vec, + rustsecp256k1zkp_v0_10_0_scalar* c_vec, size_t c_vec_len ) { - rustsecp256k1zkp_v0_8_0_scalar q_f, r_f = *r; + rustsecp256k1zkp_v0_10_0_scalar mu_f, rho_f = *rho; size_t proof_idx = 0; ecmult_x_cb_data x_cb_data; ecmult_r_cb_data r_cb_data; size_t g_len = n_vec_len, h_len = l_vec_len; const size_t G_GENS_LEN = g_len; - size_t log_g_len, log_h_len; - size_t num_rounds; - VERIFY_CHECK(g_len > 0 && h_len > 0); - log_g_len = rustsecp256k1zkp_v0_8_0_bppp_log2(g_len); - log_h_len = rustsecp256k1zkp_v0_8_0_bppp_log2(h_len); - num_rounds = log_g_len > log_h_len ? log_g_len : log_h_len; - /* Check proof sizes.*/ - VERIFY_CHECK(*proof_len >= 65 * num_rounds + 64); - VERIFY_CHECK(g_vec_len == (n_vec_len + l_vec_len) && l_vec_len == c_vec_len); - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_is_power_of_two(n_vec_len) && rustsecp256k1zkp_v0_8_0_is_power_of_two(c_vec_len)); +#ifdef VERIFY + { + size_t log_g_len_ver, log_h_len_ver, num_rounds_ver; + VERIFY_CHECK(g_len > 0 && h_len > 0); /* Precondition for rustsecp256k1zkp_v0_10_0_bppp_log2() */ + log_g_len_ver = rustsecp256k1zkp_v0_10_0_bppp_log2(g_len); + log_h_len_ver = rustsecp256k1zkp_v0_10_0_bppp_log2(h_len); + num_rounds_ver = log_g_len_ver > log_h_len_ver ? log_g_len_ver : log_h_len_ver; + /* Check proof sizes.*/ + VERIFY_CHECK(*proof_len >= 65 * num_rounds_ver + 64); + VERIFY_CHECK(g_vec_len == (n_vec_len + l_vec_len) && l_vec_len == c_vec_len); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_is_power_of_two(n_vec_len) && rustsecp256k1zkp_v0_10_0_is_power_of_two(c_vec_len)); + } +#else + (void)g_vec_len; + (void)c_vec_len; +#endif x_cb_data.n = n_vec; x_cb_data.g = g_vec; @@ -259,106 +269,97 @@ static int rustsecp256k1zkp_v0_8_0_bppp_rangeproof_norm_product_prove( r_cb_data.g1 = g_vec; r_cb_data.l1 = l_vec; r_cb_data.G_GENS_LEN = G_GENS_LEN; - rustsecp256k1zkp_v0_8_0_scalar_sqr(&q_f, &r_f); + rustsecp256k1zkp_v0_10_0_scalar_sqr(&mu_f, &rho_f); while (g_len > 1 || h_len > 1) { size_t i, num_points; - rustsecp256k1zkp_v0_8_0_scalar q_sq, r_inv, c0_l1, c1_l0, x_v, c1_l1, r_v; - rustsecp256k1zkp_v0_8_0_gej rj, xj; - rustsecp256k1zkp_v0_8_0_ge r_ge, x_ge; - rustsecp256k1zkp_v0_8_0_scalar e; - - rustsecp256k1zkp_v0_8_0_scalar_inverse_var(&r_inv, &r_f); - rustsecp256k1zkp_v0_8_0_scalar_sqr(&q_sq, &q_f); - - /* Compute the X commitment X = WIP(r_inv*n0,n1)_q2 * g + r + */ - rustsecp256k1zkp_v0_8_0_scalar_inner_product(&c0_l1, c_vec, 0, l_vec, 1, 2, h_len/2); - rustsecp256k1zkp_v0_8_0_scalar_inner_product(&c1_l0, c_vec, 1, l_vec, 0, 2, h_len/2); - rustsecp256k1zkp_v0_8_0_weighted_scalar_inner_product(&x_v, n_vec, 0, n_vec, 1, 2, g_len/2, &q_sq); - rustsecp256k1zkp_v0_8_0_scalar_mul(&x_v, &x_v, &r_inv); - rustsecp256k1zkp_v0_8_0_scalar_add(&x_v, &x_v, &x_v); - rustsecp256k1zkp_v0_8_0_scalar_add(&x_v, &x_v, &c0_l1); - rustsecp256k1zkp_v0_8_0_scalar_add(&x_v, &x_v, &c1_l0); - - x_cb_data.r = &r_f; - x_cb_data.r_inv = &r_inv; + rustsecp256k1zkp_v0_10_0_scalar mu_sq, rho_inv, c0_l1, c1_l0, x_v, c1_l1, r_v; + rustsecp256k1zkp_v0_10_0_gej rj, xj; + rustsecp256k1zkp_v0_10_0_ge r_ge, x_ge; + rustsecp256k1zkp_v0_10_0_scalar gamma; + + rustsecp256k1zkp_v0_10_0_scalar_inverse_var(&rho_inv, &rho_f); + rustsecp256k1zkp_v0_10_0_scalar_sqr(&mu_sq, &mu_f); + + /* Compute the X commitment X = WIP(rho_inv*n0,n1)_mu2 * g + r + */ + rustsecp256k1zkp_v0_10_0_scalar_inner_product(&c0_l1, c_vec, 0, l_vec, 1, 2, h_len/2); + rustsecp256k1zkp_v0_10_0_scalar_inner_product(&c1_l0, c_vec, 1, l_vec, 0, 2, h_len/2); + rustsecp256k1zkp_v0_10_0_weighted_scalar_inner_product(&x_v, n_vec, 0, n_vec, 1, 2, g_len/2, &mu_sq); + rustsecp256k1zkp_v0_10_0_scalar_mul(&x_v, &x_v, &rho_inv); + rustsecp256k1zkp_v0_10_0_scalar_add(&x_v, &x_v, &x_v); + rustsecp256k1zkp_v0_10_0_scalar_add(&x_v, &x_v, &c0_l1); + rustsecp256k1zkp_v0_10_0_scalar_add(&x_v, &x_v, &c1_l0); + + x_cb_data.rho = &rho_f; + x_cb_data.rho_inv = &rho_inv; x_cb_data.n_len = g_len >= 2 ? g_len : 0; num_points = x_cb_data.n_len + (h_len >= 2 ? h_len : 0); - if (!rustsecp256k1zkp_v0_8_0_ecmult_multi_var(&ctx->error_callback, scratch, &xj, &x_v, ecmult_x_cb, (void*)&x_cb_data, num_points)) { + if (!rustsecp256k1zkp_v0_10_0_ecmult_multi_var(&ctx->error_callback, scratch, &xj, &x_v, ecmult_x_cb, (void*)&x_cb_data, num_points)) { return 0; } - rustsecp256k1zkp_v0_8_0_weighted_scalar_inner_product(&r_v, n_vec, 1, n_vec, 1, 2, g_len/2, &q_sq); - rustsecp256k1zkp_v0_8_0_scalar_inner_product(&c1_l1, c_vec, 1, l_vec, 1, 2, h_len/2); - rustsecp256k1zkp_v0_8_0_scalar_add(&r_v, &r_v, &c1_l1); + rustsecp256k1zkp_v0_10_0_weighted_scalar_inner_product(&r_v, n_vec, 1, n_vec, 1, 2, g_len/2, &mu_sq); + rustsecp256k1zkp_v0_10_0_scalar_inner_product(&c1_l1, c_vec, 1, l_vec, 1, 2, h_len/2); + rustsecp256k1zkp_v0_10_0_scalar_add(&r_v, &r_v, &c1_l1); r_cb_data.n_len = g_len/2; num_points = r_cb_data.n_len + h_len/2; - if (!rustsecp256k1zkp_v0_8_0_ecmult_multi_var(&ctx->error_callback, scratch, &rj, &r_v, ecmult_r_cb, (void*)&r_cb_data, num_points)) { - return 0; - } - - /* We only fail here because we cannot serialize points at infinity. */ - if (rustsecp256k1zkp_v0_8_0_gej_is_infinity(&xj) || rustsecp256k1zkp_v0_8_0_gej_is_infinity(&rj)) { + if (!rustsecp256k1zkp_v0_10_0_ecmult_multi_var(&ctx->error_callback, scratch, &rj, &r_v, ecmult_r_cb, (void*)&r_cb_data, num_points)) { return 0; } - rustsecp256k1zkp_v0_8_0_ge_set_gej_var(&x_ge, &xj); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&x_ge.x); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&x_ge.y); - rustsecp256k1zkp_v0_8_0_ge_set_gej_var(&r_ge, &rj); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&r_ge.x); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&r_ge.y); - rustsecp256k1zkp_v0_8_0_bppp_serialize_points(&proof[proof_idx], &x_ge, &r_ge); + rustsecp256k1zkp_v0_10_0_ge_set_gej_var(&x_ge, &xj); + rustsecp256k1zkp_v0_10_0_ge_set_gej_var(&r_ge, &rj); + rustsecp256k1zkp_v0_10_0_bppp_serialize_points(&proof[proof_idx], &x_ge, &r_ge); proof_idx += 65; - /* Obtain challenge e for the the next round */ - rustsecp256k1zkp_v0_8_0_sha256_write(transcript, &proof[proof_idx - 65], 65); - rustsecp256k1zkp_v0_8_0_bppp_challenge_scalar(&e, transcript, 0); + /* Obtain challenge gamma for the the next round */ + rustsecp256k1zkp_v0_10_0_sha256_write(transcript, &proof[proof_idx - 65], 65); + rustsecp256k1zkp_v0_10_0_bppp_challenge_scalar(&gamma, transcript, 0); if (g_len > 1) { for (i = 0; i < g_len; i = i + 2) { - rustsecp256k1zkp_v0_8_0_scalar nl, nr; - rustsecp256k1zkp_v0_8_0_gej gl, gr; - rustsecp256k1zkp_v0_8_0_scalar_mul(&nl, &n_vec[i], &r_inv); - rustsecp256k1zkp_v0_8_0_scalar_mul(&nr, &n_vec[i + 1], &e); - rustsecp256k1zkp_v0_8_0_scalar_add(&n_vec[i/2], &nl, &nr); - - rustsecp256k1zkp_v0_8_0_gej_set_ge(&gl, &g_vec[i]); - rustsecp256k1zkp_v0_8_0_ecmult(&gl, &gl, &r_f, NULL); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&gr, &g_vec[i + 1]); - rustsecp256k1zkp_v0_8_0_ecmult(&gr, &gr, &e, NULL); - rustsecp256k1zkp_v0_8_0_gej_add_var(&gl, &gl, &gr, NULL); - rustsecp256k1zkp_v0_8_0_ge_set_gej_var(&g_vec[i/2], &gl); + rustsecp256k1zkp_v0_10_0_scalar nl, nr; + rustsecp256k1zkp_v0_10_0_gej gl, gr; + rustsecp256k1zkp_v0_10_0_scalar_mul(&nl, &n_vec[i], &rho_inv); + rustsecp256k1zkp_v0_10_0_scalar_mul(&nr, &n_vec[i + 1], &gamma); + rustsecp256k1zkp_v0_10_0_scalar_add(&n_vec[i/2], &nl, &nr); + + rustsecp256k1zkp_v0_10_0_gej_set_ge(&gl, &g_vec[i]); + rustsecp256k1zkp_v0_10_0_ecmult(&gl, &gl, &rho_f, NULL); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&gr, &g_vec[i + 1]); + rustsecp256k1zkp_v0_10_0_ecmult(&gr, &gr, &gamma, NULL); + rustsecp256k1zkp_v0_10_0_gej_add_var(&gl, &gl, &gr, NULL); + rustsecp256k1zkp_v0_10_0_ge_set_gej_var(&g_vec[i/2], &gl); } } if (h_len > 1) { for (i = 0; i < h_len; i = i + 2) { - rustsecp256k1zkp_v0_8_0_scalar temp1; - rustsecp256k1zkp_v0_8_0_gej grj; - rustsecp256k1zkp_v0_8_0_scalar_mul(&temp1, &c_vec[i + 1], &e); - rustsecp256k1zkp_v0_8_0_scalar_add(&c_vec[i/2], &c_vec[i], &temp1); - - rustsecp256k1zkp_v0_8_0_scalar_mul(&temp1, &l_vec[i + 1], &e); - rustsecp256k1zkp_v0_8_0_scalar_add(&l_vec[i/2], &l_vec[i], &temp1); - - rustsecp256k1zkp_v0_8_0_gej_set_ge(&grj, &g_vec[G_GENS_LEN + i + 1]); - rustsecp256k1zkp_v0_8_0_ecmult(&grj, &grj, &e, NULL); - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&grj, &grj, &g_vec[G_GENS_LEN + i], NULL); - rustsecp256k1zkp_v0_8_0_ge_set_gej_var(&g_vec[G_GENS_LEN + i/2], &grj); + rustsecp256k1zkp_v0_10_0_scalar temp1; + rustsecp256k1zkp_v0_10_0_gej grj; + rustsecp256k1zkp_v0_10_0_scalar_mul(&temp1, &c_vec[i + 1], &gamma); + rustsecp256k1zkp_v0_10_0_scalar_add(&c_vec[i/2], &c_vec[i], &temp1); + + rustsecp256k1zkp_v0_10_0_scalar_mul(&temp1, &l_vec[i + 1], &gamma); + rustsecp256k1zkp_v0_10_0_scalar_add(&l_vec[i/2], &l_vec[i], &temp1); + + rustsecp256k1zkp_v0_10_0_gej_set_ge(&grj, &g_vec[G_GENS_LEN + i + 1]); + rustsecp256k1zkp_v0_10_0_ecmult(&grj, &grj, &gamma, NULL); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&grj, &grj, &g_vec[G_GENS_LEN + i], NULL); + rustsecp256k1zkp_v0_10_0_ge_set_gej_var(&g_vec[G_GENS_LEN + i/2], &grj); } } g_len = g_len / 2; h_len = h_len / 2; - r_f = q_f; - q_f = q_sq; + rho_f = mu_f; + mu_f = mu_sq; } - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&proof[proof_idx], &n_vec[0]); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&proof[proof_idx + 32], &l_vec[0]); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&proof[proof_idx], &n_vec[0]); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&proof[proof_idx + 32], &l_vec[0]); proof_idx += 64; *proof_len = proof_idx; return 1; @@ -366,39 +367,33 @@ static int rustsecp256k1zkp_v0_8_0_bppp_rangeproof_norm_product_prove( typedef struct ec_mult_verify_cb_data1 { const unsigned char *proof; - const rustsecp256k1zkp_v0_8_0_ge *commit; - const rustsecp256k1zkp_v0_8_0_scalar *challenges; + const rustsecp256k1zkp_v0_10_0_ge *commit; + const rustsecp256k1zkp_v0_10_0_scalar *gammas; } ec_mult_verify_cb_data1; -static int ec_mult_verify_cb1(rustsecp256k1zkp_v0_8_0_scalar *sc, rustsecp256k1zkp_v0_8_0_ge *pt, size_t idx, void *cbdata) { +static int ec_mult_verify_cb1(rustsecp256k1zkp_v0_10_0_scalar *sc, rustsecp256k1zkp_v0_10_0_ge *pt, size_t idx, void *cbdata) { ec_mult_verify_cb_data1 *data = (ec_mult_verify_cb_data1*) cbdata; if (idx == 0) { *pt = *data->commit; - rustsecp256k1zkp_v0_8_0_scalar_set_int(sc, 1); + rustsecp256k1zkp_v0_10_0_scalar_set_int(sc, 1); return 1; } idx -= 1; if (idx % 2 == 0) { - unsigned char pk_buf[33]; idx /= 2; - *sc = data->challenges[idx]; - pk_buf[0] = 2 | (data->proof[65*idx] >> 1); - memcpy(&pk_buf[1], &data->proof[65*idx + 1], 32); - if (!rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(pt, pk_buf, sizeof(pk_buf))) { + *sc = data->gammas[idx]; + if (!rustsecp256k1zkp_v0_10_0_bppp_parse_one_of_points(pt, &data->proof[65*idx], 0)) { return 0; } } else { - unsigned char pk_buf[33]; - rustsecp256k1zkp_v0_8_0_scalar neg_one; + rustsecp256k1zkp_v0_10_0_scalar neg_one; idx /= 2; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&neg_one, 1); - rustsecp256k1zkp_v0_8_0_scalar_negate(&neg_one, &neg_one); - *sc = data->challenges[idx]; - rustsecp256k1zkp_v0_8_0_scalar_sqr(sc, sc); - rustsecp256k1zkp_v0_8_0_scalar_add(sc, sc, &neg_one); - pk_buf[0] = 2 | data->proof[65*idx]; - memcpy(&pk_buf[1], &data->proof[65*idx + 33], 32); - if (!rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(pt, pk_buf, sizeof(pk_buf))) { + rustsecp256k1zkp_v0_10_0_scalar_set_int(&neg_one, 1); + rustsecp256k1zkp_v0_10_0_scalar_negate(&neg_one, &neg_one); + *sc = data->gammas[idx]; + rustsecp256k1zkp_v0_10_0_scalar_sqr(sc, sc); + rustsecp256k1zkp_v0_10_0_scalar_add(sc, sc, &neg_one); + if (!rustsecp256k1zkp_v0_10_0_bppp_parse_one_of_points(pt, &data->proof[65*idx], 1)) { return 0; } } @@ -406,13 +401,13 @@ static int ec_mult_verify_cb1(rustsecp256k1zkp_v0_8_0_scalar *sc, rustsecp256k1z } typedef struct ec_mult_verify_cb_data2 { - const rustsecp256k1zkp_v0_8_0_scalar *s_g; - const rustsecp256k1zkp_v0_8_0_scalar *s_h; - const rustsecp256k1zkp_v0_8_0_ge *g_vec; + const rustsecp256k1zkp_v0_10_0_scalar *s_g; + const rustsecp256k1zkp_v0_10_0_scalar *s_h; + const rustsecp256k1zkp_v0_10_0_ge *g_vec; size_t g_vec_len; } ec_mult_verify_cb_data2; -static int ec_mult_verify_cb2(rustsecp256k1zkp_v0_8_0_scalar *sc, rustsecp256k1zkp_v0_8_0_ge *pt, size_t idx, void *cbdata) { +static int ec_mult_verify_cb2(rustsecp256k1zkp_v0_10_0_scalar *sc, rustsecp256k1zkp_v0_10_0_ge *pt, size_t idx, void *cbdata) { ec_mult_verify_cb_data2 *data = (ec_mult_verify_cb_data2*) cbdata; if (idx < data->g_vec_len) { *sc = data->s_g[idx]; @@ -426,22 +421,22 @@ static int ec_mult_verify_cb2(rustsecp256k1zkp_v0_8_0_scalar *sc, rustsecp256k1z /* Verify the proof. This function modifies the generators, c_vec and the challenge r. The caller should make sure to back them up if they need to be reused. */ -static int rustsecp256k1zkp_v0_8_0_bppp_rangeproof_norm_product_verify( - const rustsecp256k1zkp_v0_8_0_context* ctx, - rustsecp256k1zkp_v0_8_0_scratch_space* scratch, +static int rustsecp256k1zkp_v0_10_0_bppp_rangeproof_norm_product_verify( + const rustsecp256k1zkp_v0_10_0_context* ctx, + rustsecp256k1zkp_v0_10_0_scratch_space* scratch, const unsigned char* proof, size_t proof_len, - rustsecp256k1zkp_v0_8_0_sha256* transcript, - const rustsecp256k1zkp_v0_8_0_scalar* r, - const rustsecp256k1zkp_v0_8_0_bppp_generators* g_vec, + rustsecp256k1zkp_v0_10_0_sha256* transcript, + const rustsecp256k1zkp_v0_10_0_scalar* rho, + const rustsecp256k1zkp_v0_10_0_bppp_generators* g_vec, size_t g_len, - const rustsecp256k1zkp_v0_8_0_scalar* c_vec, + const rustsecp256k1zkp_v0_10_0_scalar* c_vec, size_t c_vec_len, - const rustsecp256k1zkp_v0_8_0_ge* commit + const rustsecp256k1zkp_v0_10_0_ge* commit ) { - rustsecp256k1zkp_v0_8_0_scalar r_f, q_f, v, n, l, r_inv, h_c; - rustsecp256k1zkp_v0_8_0_scalar *es, *s_g, *s_h, *r_inv_pows; - rustsecp256k1zkp_v0_8_0_gej res1, res2; + rustsecp256k1zkp_v0_10_0_scalar rho_f, mu_f, v, n, l, rho_inv, h_c; + rustsecp256k1zkp_v0_10_0_scalar *gammas, *s_g, *s_h, *rho_inv_pows; + rustsecp256k1zkp_v0_10_0_gej res1, res2; size_t i = 0, scratch_checkpoint; int overflow; size_t log_g_len, log_h_len; @@ -451,88 +446,88 @@ static int rustsecp256k1zkp_v0_8_0_bppp_rangeproof_norm_product_verify( if (g_len == 0 || c_vec_len == 0) { return 0; } - log_g_len = rustsecp256k1zkp_v0_8_0_bppp_log2(g_len); - log_h_len = rustsecp256k1zkp_v0_8_0_bppp_log2(c_vec_len); + log_g_len = rustsecp256k1zkp_v0_10_0_bppp_log2(g_len); + log_h_len = rustsecp256k1zkp_v0_10_0_bppp_log2(c_vec_len); n_rounds = log_g_len > log_h_len ? log_g_len : log_h_len; if (g_vec->n != (h_len + g_len) || (proof_len != 65 * n_rounds + 64)) { return 0; } - if (!rustsecp256k1zkp_v0_8_0_is_power_of_two(g_len) || !rustsecp256k1zkp_v0_8_0_is_power_of_two(h_len)) { + if (!rustsecp256k1zkp_v0_10_0_is_power_of_two(g_len) || !rustsecp256k1zkp_v0_10_0_is_power_of_two(h_len)) { return 0; } - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&n, &proof[n_rounds*65], &overflow); /* n */ + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&n, &proof[n_rounds*65], &overflow); /* n */ if (overflow) return 0; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&l, &proof[n_rounds*65 + 32], &overflow); /* l */ + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&l, &proof[n_rounds*65 + 32], &overflow); /* l */ if (overflow) return 0; - if (rustsecp256k1zkp_v0_8_0_scalar_is_zero(r)) return 0; - - /* Collect the challenges in a new vector */ - scratch_checkpoint = rustsecp256k1zkp_v0_8_0_scratch_checkpoint(&ctx->error_callback, scratch); - es = (rustsecp256k1zkp_v0_8_0_scalar*)rustsecp256k1zkp_v0_8_0_scratch_alloc(&ctx->error_callback, scratch, n_rounds * sizeof(rustsecp256k1zkp_v0_8_0_scalar)); - s_g = (rustsecp256k1zkp_v0_8_0_scalar*)rustsecp256k1zkp_v0_8_0_scratch_alloc(&ctx->error_callback, scratch, g_len * sizeof(rustsecp256k1zkp_v0_8_0_scalar)); - s_h = (rustsecp256k1zkp_v0_8_0_scalar*)rustsecp256k1zkp_v0_8_0_scratch_alloc(&ctx->error_callback, scratch, h_len * sizeof(rustsecp256k1zkp_v0_8_0_scalar)); - r_inv_pows = (rustsecp256k1zkp_v0_8_0_scalar*)rustsecp256k1zkp_v0_8_0_scratch_alloc(&ctx->error_callback, scratch, log_g_len * sizeof(rustsecp256k1zkp_v0_8_0_scalar)); - if (es == NULL || s_g == NULL || s_h == NULL || r_inv_pows == NULL) { - rustsecp256k1zkp_v0_8_0_scratch_apply_checkpoint(&ctx->error_callback, scratch, scratch_checkpoint); + if (rustsecp256k1zkp_v0_10_0_scalar_is_zero(rho)) return 0; + + /* Collect the gammas in a new vector */ + scratch_checkpoint = rustsecp256k1zkp_v0_10_0_scratch_checkpoint(&ctx->error_callback, scratch); + gammas = (rustsecp256k1zkp_v0_10_0_scalar*)rustsecp256k1zkp_v0_10_0_scratch_alloc(&ctx->error_callback, scratch, n_rounds * sizeof(rustsecp256k1zkp_v0_10_0_scalar)); + s_g = (rustsecp256k1zkp_v0_10_0_scalar*)rustsecp256k1zkp_v0_10_0_scratch_alloc(&ctx->error_callback, scratch, g_len * sizeof(rustsecp256k1zkp_v0_10_0_scalar)); + s_h = (rustsecp256k1zkp_v0_10_0_scalar*)rustsecp256k1zkp_v0_10_0_scratch_alloc(&ctx->error_callback, scratch, h_len * sizeof(rustsecp256k1zkp_v0_10_0_scalar)); + rho_inv_pows = (rustsecp256k1zkp_v0_10_0_scalar*)rustsecp256k1zkp_v0_10_0_scratch_alloc(&ctx->error_callback, scratch, log_g_len * sizeof(rustsecp256k1zkp_v0_10_0_scalar)); + if (gammas == NULL || s_g == NULL || s_h == NULL || rho_inv_pows == NULL) { + rustsecp256k1zkp_v0_10_0_scratch_apply_checkpoint(&ctx->error_callback, scratch, scratch_checkpoint); return 0; } - /* Compute powers of r_inv. Later used in g_factor computations*/ - rustsecp256k1zkp_v0_8_0_scalar_inverse_var(&r_inv, r); - rustsecp256k1zkp_v0_8_0_bppp_powers_of_r(r_inv_pows, &r_inv, log_g_len); + /* Compute powers of rho_inv. Later used in g_factor computations*/ + rustsecp256k1zkp_v0_10_0_scalar_inverse_var(&rho_inv, rho); + rustsecp256k1zkp_v0_10_0_bppp_powers_of_rho(rho_inv_pows, &rho_inv, log_g_len); - /* Compute r_f = r^(2^log_g_len) */ - r_f = *r; + /* Compute rho_f = rho^(2^log_g_len) */ + rho_f = *rho; for (i = 0; i < log_g_len; i++) { - rustsecp256k1zkp_v0_8_0_scalar_sqr(&r_f, &r_f); + rustsecp256k1zkp_v0_10_0_scalar_sqr(&rho_f, &rho_f); } for (i = 0; i < n_rounds; i++) { - rustsecp256k1zkp_v0_8_0_scalar e; - rustsecp256k1zkp_v0_8_0_sha256_write(transcript, &proof[i * 65], 65); - rustsecp256k1zkp_v0_8_0_bppp_challenge_scalar(&e, transcript, 0); - es[i] = e; + rustsecp256k1zkp_v0_10_0_scalar gamma; + rustsecp256k1zkp_v0_10_0_sha256_write(transcript, &proof[i * 65], 65); + rustsecp256k1zkp_v0_10_0_bppp_challenge_scalar(&gamma, transcript, 0); + gammas[i] = gamma; } - /* s_g[0] = n * \prod_{j=0}^{log_g_len - 1} r^(2^j) - * = n * r^(2^log_g_len - 1) - * = n * r_f * r_inv */ - rustsecp256k1zkp_v0_8_0_scalar_mul(&s_g[0], &n, &r_f); - rustsecp256k1zkp_v0_8_0_scalar_mul(&s_g[0], &s_g[0], &r_inv); + /* s_g[0] = n * \prod_{j=0}^{log_g_len - 1} rho^(2^j) + * = n * rho^(2^log_g_len - 1) + * = n * rho_f * rho_inv */ + rustsecp256k1zkp_v0_10_0_scalar_mul(&s_g[0], &n, &rho_f); + rustsecp256k1zkp_v0_10_0_scalar_mul(&s_g[0], &s_g[0], &rho_inv); for (i = 1; i < g_len; i++) { - size_t log_i = rustsecp256k1zkp_v0_8_0_bppp_log2(i); + size_t log_i = rustsecp256k1zkp_v0_10_0_bppp_log2(i); size_t nearest_pow_of_two = (size_t)1 << log_i; - /* This combines the two multiplications of challenges and r_invs in a + /* This combines the two multiplications of gammas and rho_invs in a * single loop. * s_g[i] = s_g[i - nearest_pow_of_two] - * * e[log_i] * r_inv^(2^log_i) */ - rustsecp256k1zkp_v0_8_0_scalar_mul(&s_g[i], &s_g[i - nearest_pow_of_two], &es[log_i]); - rustsecp256k1zkp_v0_8_0_scalar_mul(&s_g[i], &s_g[i], &r_inv_pows[log_i]); + * * e[log_i] * rho_inv^(2^log_i) */ + rustsecp256k1zkp_v0_10_0_scalar_mul(&s_g[i], &s_g[i - nearest_pow_of_two], &gammas[log_i]); + rustsecp256k1zkp_v0_10_0_scalar_mul(&s_g[i], &s_g[i], &rho_inv_pows[log_i]); } s_h[0] = l; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&h_c, 0); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&h_c, 0); for (i = 1; i < h_len; i++) { - size_t log_i = rustsecp256k1zkp_v0_8_0_bppp_log2(i); + size_t log_i = rustsecp256k1zkp_v0_10_0_bppp_log2(i); size_t nearest_pow_of_two = (size_t)1 << log_i; - rustsecp256k1zkp_v0_8_0_scalar_mul(&s_h[i], &s_h[i - nearest_pow_of_two], &es[log_i]); + rustsecp256k1zkp_v0_10_0_scalar_mul(&s_h[i], &s_h[i - nearest_pow_of_two], &gammas[log_i]); } - rustsecp256k1zkp_v0_8_0_scalar_inner_product(&h_c, c_vec, 0 /* a_offset */ , s_h, 0 /* b_offset */, 1 /* step */, h_len); - /* Compute v = n*n*q_f + l*h_c where q_f = r_f^2 */ - rustsecp256k1zkp_v0_8_0_scalar_sqr(&q_f, &r_f); - rustsecp256k1zkp_v0_8_0_scalar_mul(&v, &n, &n); - rustsecp256k1zkp_v0_8_0_scalar_mul(&v, &v, &q_f); - rustsecp256k1zkp_v0_8_0_scalar_add(&v, &v, &h_c); + rustsecp256k1zkp_v0_10_0_scalar_inner_product(&h_c, c_vec, 0 /* a_offset */ , s_h, 0 /* b_offset */, 1 /* step */, h_len); + /* Compute v = n*n*mu_f + l*h_c where mu_f = rho_f^2 */ + rustsecp256k1zkp_v0_10_0_scalar_sqr(&mu_f, &rho_f); + rustsecp256k1zkp_v0_10_0_scalar_mul(&v, &n, &n); + rustsecp256k1zkp_v0_10_0_scalar_mul(&v, &v, &mu_f); + rustsecp256k1zkp_v0_10_0_scalar_add(&v, &v, &h_c); { ec_mult_verify_cb_data1 data; data.proof = proof; data.commit = commit; - data.challenges = es; + data.gammas = gammas; - if (!rustsecp256k1zkp_v0_8_0_ecmult_multi_var(&ctx->error_callback, scratch, &res1, NULL, ec_mult_verify_cb1, &data, 2*n_rounds + 1)) { - rustsecp256k1zkp_v0_8_0_scratch_apply_checkpoint(&ctx->error_callback, scratch, scratch_checkpoint); + if (!rustsecp256k1zkp_v0_10_0_ecmult_multi_var(&ctx->error_callback, scratch, &res1, NULL, ec_mult_verify_cb1, &data, 2*n_rounds + 1)) { + rustsecp256k1zkp_v0_10_0_scratch_apply_checkpoint(&ctx->error_callback, scratch, scratch_checkpoint); return 0; } } @@ -543,17 +538,14 @@ static int rustsecp256k1zkp_v0_8_0_bppp_rangeproof_norm_product_verify( data.s_g = s_g; data.s_h = s_h; - if (!rustsecp256k1zkp_v0_8_0_ecmult_multi_var(&ctx->error_callback, scratch, &res2, &v, ec_mult_verify_cb2, &data, g_len + h_len)) { - rustsecp256k1zkp_v0_8_0_scratch_apply_checkpoint(&ctx->error_callback, scratch, scratch_checkpoint); + if (!rustsecp256k1zkp_v0_10_0_ecmult_multi_var(&ctx->error_callback, scratch, &res2, &v, ec_mult_verify_cb2, &data, g_len + h_len)) { + rustsecp256k1zkp_v0_10_0_scratch_apply_checkpoint(&ctx->error_callback, scratch, scratch_checkpoint); return 0; } } - rustsecp256k1zkp_v0_8_0_scratch_apply_checkpoint(&ctx->error_callback, scratch, scratch_checkpoint); + rustsecp256k1zkp_v0_10_0_scratch_apply_checkpoint(&ctx->error_callback, scratch, scratch_checkpoint); - /* res1 and res2 should be equal. Could not find a simpler way to compare them */ - rustsecp256k1zkp_v0_8_0_gej_neg(&res1, &res1); - rustsecp256k1zkp_v0_8_0_gej_add_var(&res1, &res1, &res2, NULL); - return rustsecp256k1zkp_v0_8_0_gej_is_infinity(&res1); + return rustsecp256k1zkp_v0_10_0_gej_eq_var(&res1, &res2); } #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/bppp_transcript_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/bppp_transcript_impl.h index f277f848..26661397 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/bppp_transcript_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/bppp_transcript_impl.h @@ -3,18 +3,18 @@ * Distributed under the MIT software license, see the accompanying * * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef _SECP256K1_MODULE_BPPP_PP_TRANSCRIPT_IMPL_ -#define _SECP256K1_MODULE_BPPP_PP_TRANSCRIPT_IMPL_ +#ifndef SECP256K1_MODULE_BPPP_PP_TRANSCRIPT_IMPL_H +#define SECP256K1_MODULE_BPPP_PP_TRANSCRIPT_IMPL_H -#include "group.h" -#include "scalar.h" +#include "../../group.h" +#include "../../scalar.h" #include "bppp_util.h" /* Initializes SHA256 with fixed midstate. This midstate was computed by applying * SHA256 to SHA256("Bulletproofs_pp/v0/commitment")||SHA256("Bulletproofs_pp/v0/commitment"). */ -static void rustsecp256k1zkp_v0_8_0_bppp_sha256_tagged_commitment_init(rustsecp256k1zkp_v0_8_0_sha256 *sha) { - rustsecp256k1zkp_v0_8_0_sha256_initialize(sha); +static void rustsecp256k1zkp_v0_10_0_bppp_sha256_tagged_commitment_init(rustsecp256k1zkp_v0_10_0_sha256 *sha) { + rustsecp256k1zkp_v0_10_0_sha256_initialize(sha); sha->s[0] = 0x52fc8185ul; sha->s[1] = 0x0e7debf0ul; sha->s[2] = 0xb0967270ul; @@ -28,13 +28,13 @@ static void rustsecp256k1zkp_v0_8_0_bppp_sha256_tagged_commitment_init(rustsecp2 } /* Obtain a challenge scalar from the current transcript.*/ -static void rustsecp256k1zkp_v0_8_0_bppp_challenge_scalar(rustsecp256k1zkp_v0_8_0_scalar* ch, const rustsecp256k1zkp_v0_8_0_sha256 *transcript, uint64_t idx) { +static void rustsecp256k1zkp_v0_10_0_bppp_challenge_scalar(rustsecp256k1zkp_v0_10_0_scalar* ch, const rustsecp256k1zkp_v0_10_0_sha256 *transcript, uint64_t idx) { unsigned char buf[32]; - rustsecp256k1zkp_v0_8_0_sha256 sha = *transcript; - rustsecp256k1zkp_v0_8_0_bppp_le64(buf, idx); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, buf, 8); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, buf); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(ch, buf, NULL); + rustsecp256k1zkp_v0_10_0_sha256 sha = *transcript; + rustsecp256k1zkp_v0_10_0_bppp_le64(buf, idx); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, buf, 8); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, buf); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(ch, buf, NULL); } #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/bppp_util.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/bppp_util.h index 40851331..6a48f892 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/bppp_util.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/bppp_util.h @@ -4,32 +4,55 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef _SECP256K1_MODULE_BPPP_UTIL_ -#define _SECP256K1_MODULE_BPPP_UTIL_ +#ifndef SECP256K1_MODULE_BPPP_UTIL_H +#define SECP256K1_MODULE_BPPP_UTIL_H -#include "field.h" -#include "group.h" -#include "hash.h" -#include "eckey.h" +#include "../../field.h" +#include "../../group.h" +#include "../../hash.h" +#include "../../eckey.h" /* Outputs a pair of points, amortizing the parity byte between them * Assumes both points' coordinates have been normalized. */ -static void rustsecp256k1zkp_v0_8_0_bppp_serialize_points(unsigned char *output, const rustsecp256k1zkp_v0_8_0_ge *lpt, const rustsecp256k1zkp_v0_8_0_ge *rpt) { - output[0] = (rustsecp256k1zkp_v0_8_0_fe_is_odd(&lpt->y) << 1) + rustsecp256k1zkp_v0_8_0_fe_is_odd(&rpt->y); - rustsecp256k1zkp_v0_8_0_fe_get_b32(&output[1], &lpt->x); - rustsecp256k1zkp_v0_8_0_fe_get_b32(&output[33], &rpt->x); +static void rustsecp256k1zkp_v0_10_0_bppp_serialize_points(unsigned char *output, rustsecp256k1zkp_v0_10_0_ge *lpt, rustsecp256k1zkp_v0_10_0_ge *rpt) { + unsigned char tmp[33]; + rustsecp256k1zkp_v0_10_0_ge_serialize_ext(tmp, lpt); + output[0] = (tmp[0] & 1) << 1; + memcpy(&output[1], &tmp[1], 32); + rustsecp256k1zkp_v0_10_0_ge_serialize_ext(tmp, rpt); + output[0] |= (tmp[0] & 1); + memcpy(&output[33], &tmp[1], 32); +} + +static int rustsecp256k1zkp_v0_10_0_bppp_parse_one_of_points(rustsecp256k1zkp_v0_10_0_ge *pt, const unsigned char *in65, int idx) { + unsigned char tmp[33] = { 0 }; + if (in65[0] > 3) { + return 0; + } + /* Check if the input array encodes the point at infinity */ + if ((rustsecp256k1zkp_v0_10_0_memcmp_var(tmp, &in65[1 + 32*idx], 32)) != 0) { + tmp[0] = 2 | ((in65[0] & (2 - idx)) >> (1 - idx)); + memcpy(&tmp[1], &in65[1 + 32*idx], 32); + } else { + /* If we're parsing the point at infinity, enforce that the sign bit is + * 0. */ + if ((in65[0] & (2 - idx)) != 0) { + return 0; + } + } + return rustsecp256k1zkp_v0_10_0_ge_parse_ext(pt, tmp); } /* Outputs a serialized point in compressed form. Returns 0 at point at infinity. */ -static int rustsecp256k1zkp_v0_8_0_bppp_serialize_pt(unsigned char *output, rustsecp256k1zkp_v0_8_0_ge *lpt) { +static int rustsecp256k1zkp_v0_10_0_bppp_serialize_pt(unsigned char *output, rustsecp256k1zkp_v0_10_0_ge *lpt) { size_t size; - return rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(lpt, output, &size, 1 /*compressed*/); + return rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(lpt, output, &size, 1 /*compressed*/); } /* little-endian encodes a uint64 */ -static void rustsecp256k1zkp_v0_8_0_bppp_le64(unsigned char *output, const uint64_t n) { +static void rustsecp256k1zkp_v0_10_0_bppp_le64(unsigned char *output, const uint64_t n) { output[0] = n; output[1] = n >> 8; output[2] = n >> 16; @@ -41,7 +64,7 @@ static void rustsecp256k1zkp_v0_8_0_bppp_le64(unsigned char *output, const uint6 } /* Check if n is power of two*/ -static int rustsecp256k1zkp_v0_8_0_is_power_of_two(size_t n) { +static int rustsecp256k1zkp_v0_10_0_is_power_of_two(size_t n) { return n > 0 && (n & (n - 1)) == 0; } @@ -50,8 +73,8 @@ static int rustsecp256k1zkp_v0_8_0_is_power_of_two(size_t n) { * Bulletproofs, this is bounded by len of input vectors which can be safely * assumed to be less than 2^64. */ -static size_t rustsecp256k1zkp_v0_8_0_bppp_log2(size_t n) { - return 64 - 1 - rustsecp256k1zkp_v0_8_0_clz64_var((uint64_t)n); +static size_t rustsecp256k1zkp_v0_10_0_bppp_log2(size_t n) { + return 64 - 1 - rustsecp256k1zkp_v0_10_0_clz64_var((uint64_t)n); } #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/main.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/main.h index 4bef634d..4ff6ee5d 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/main.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/main.h @@ -2,12 +2,12 @@ #define SECP256K1_MODULE_BPPP_MAIN_H /* this type must be completed before any of the modules/bppp includes */ -struct rustsecp256k1zkp_v0_8_0_bppp_generators { +struct rustsecp256k1zkp_v0_10_0_bppp_generators { size_t n; /* n total generators; includes both G_i and H_i */ /* For BP++, the generators are G_i from [0..(n - 8)] and the last 8 values are generators are for H_i */ - rustsecp256k1zkp_v0_8_0_ge* gens; + rustsecp256k1zkp_v0_10_0_ge* gens; }; #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/main_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/main_impl.h index 441c5a82..5052148b 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/main_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/main_impl.h @@ -4,54 +4,54 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef _SECP256K1_MODULE_BPPP_MAIN_ -#define _SECP256K1_MODULE_BPPP_MAIN_ - -#include "include/secp256k1_bppp.h" -#include "include/secp256k1_generator.h" -#include "modules/generator/main_impl.h" /* for generator_{load, save} */ -#include "hash.h" -#include "util.h" -#include "modules/bppp/main.h" -#include "modules/bppp/bppp_norm_product_impl.h" - -rustsecp256k1zkp_v0_8_0_bppp_generators *rustsecp256k1zkp_v0_8_0_bppp_generators_create(const rustsecp256k1zkp_v0_8_0_context *ctx, size_t n) { - rustsecp256k1zkp_v0_8_0_bppp_generators *ret; - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256 rng; +#ifndef SECP256K1_MODULE_BPPP_MAIN_IMPL_H +#define SECP256K1_MODULE_BPPP_MAIN_IMPL_H + +#include "../../../include/secp256k1_bppp.h" +#include "../../../include/secp256k1_generator.h" +#include "../generator/main_impl.h" /* for generator_{load, save} */ +#include "../../hash.h" +#include "../../util.h" +#include "../bppp/main.h" +#include "../bppp/bppp_norm_product_impl.h" + +rustsecp256k1zkp_v0_10_0_bppp_generators *rustsecp256k1zkp_v0_10_0_bppp_generators_create(const rustsecp256k1zkp_v0_10_0_context *ctx, size_t n) { + rustsecp256k1zkp_v0_10_0_bppp_generators *ret; + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256 rng; unsigned char seed[64]; size_t i; VERIFY_CHECK(ctx != NULL); - ret = (rustsecp256k1zkp_v0_8_0_bppp_generators *)checked_malloc(&ctx->error_callback, sizeof(*ret)); + ret = (rustsecp256k1zkp_v0_10_0_bppp_generators *)checked_malloc(&ctx->error_callback, sizeof(*ret)); if (ret == NULL) { return NULL; } - ret->gens = (rustsecp256k1zkp_v0_8_0_ge*)checked_malloc(&ctx->error_callback, n * sizeof(*ret->gens)); + ret->gens = (rustsecp256k1zkp_v0_10_0_ge*)checked_malloc(&ctx->error_callback, n * sizeof(*ret->gens)); if (ret->gens == NULL) { free(ret); return NULL; } ret->n = n; - rustsecp256k1zkp_v0_8_0_fe_get_b32(&seed[0], &rustsecp256k1zkp_v0_8_0_ge_const_g.x); - rustsecp256k1zkp_v0_8_0_fe_get_b32(&seed[32], &rustsecp256k1zkp_v0_8_0_ge_const_g.y); + rustsecp256k1zkp_v0_10_0_fe_get_b32(&seed[0], &rustsecp256k1zkp_v0_10_0_ge_const_g.x); + rustsecp256k1zkp_v0_10_0_fe_get_b32(&seed[32], &rustsecp256k1zkp_v0_10_0_ge_const_g.y); - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_initialize(&rng, seed, 64); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_initialize(&rng, seed, 64); for (i = 0; i < n; i++) { - rustsecp256k1zkp_v0_8_0_generator gen; + rustsecp256k1zkp_v0_10_0_generator gen; unsigned char tmp[32] = { 0 }; - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_generate(&rng, tmp, 32); - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate(ctx, &gen, tmp)); - rustsecp256k1zkp_v0_8_0_generator_load(&ret->gens[i], &gen); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_generate(&rng, tmp, 32); + CHECK(rustsecp256k1zkp_v0_10_0_generator_generate(ctx, &gen, tmp)); + rustsecp256k1zkp_v0_10_0_generator_load(&ret->gens[i], &gen); } return ret; } -rustsecp256k1zkp_v0_8_0_bppp_generators* rustsecp256k1zkp_v0_8_0_bppp_generators_parse(const rustsecp256k1zkp_v0_8_0_context* ctx, const unsigned char* data, size_t data_len) { +rustsecp256k1zkp_v0_10_0_bppp_generators* rustsecp256k1zkp_v0_10_0_bppp_generators_parse(const rustsecp256k1zkp_v0_10_0_context* ctx, const unsigned char* data, size_t data_len) { size_t n = data_len / 33; - rustsecp256k1zkp_v0_8_0_bppp_generators* ret; + rustsecp256k1zkp_v0_10_0_bppp_generators* ret; VERIFY_CHECK(ctx != NULL); ARG_CHECK(data != NULL); @@ -60,30 +60,30 @@ rustsecp256k1zkp_v0_8_0_bppp_generators* rustsecp256k1zkp_v0_8_0_bppp_generators return NULL; } - ret = (rustsecp256k1zkp_v0_8_0_bppp_generators *)checked_malloc(&ctx->error_callback, sizeof(*ret)); + ret = (rustsecp256k1zkp_v0_10_0_bppp_generators *)checked_malloc(&ctx->error_callback, sizeof(*ret)); if (ret == NULL) { return NULL; } ret->n = n; - ret->gens = (rustsecp256k1zkp_v0_8_0_ge*)checked_malloc(&ctx->error_callback, n * sizeof(*ret->gens)); + ret->gens = (rustsecp256k1zkp_v0_10_0_ge*)checked_malloc(&ctx->error_callback, n * sizeof(*ret->gens)); if (ret->gens == NULL) { free(ret); return NULL; } while (n--) { - rustsecp256k1zkp_v0_8_0_generator gen; - if (!rustsecp256k1zkp_v0_8_0_generator_parse(ctx, &gen, &data[33 * n])) { + rustsecp256k1zkp_v0_10_0_generator gen; + if (!rustsecp256k1zkp_v0_10_0_generator_parse(ctx, &gen, &data[33 * n])) { free(ret->gens); free(ret); return NULL; } - rustsecp256k1zkp_v0_8_0_generator_load(&ret->gens[n], &gen); + rustsecp256k1zkp_v0_10_0_generator_load(&ret->gens[n], &gen); } return ret; } -int rustsecp256k1zkp_v0_8_0_bppp_generators_serialize(const rustsecp256k1zkp_v0_8_0_context* ctx, const rustsecp256k1zkp_v0_8_0_bppp_generators* gens, unsigned char* data, size_t *data_len) { +int rustsecp256k1zkp_v0_10_0_bppp_generators_serialize(const rustsecp256k1zkp_v0_10_0_context* ctx, const rustsecp256k1zkp_v0_10_0_bppp_generators* gens, unsigned char* data, size_t *data_len) { size_t i; VERIFY_CHECK(ctx != NULL); @@ -94,16 +94,16 @@ int rustsecp256k1zkp_v0_8_0_bppp_generators_serialize(const rustsecp256k1zkp_v0_ memset(data, 0, *data_len); for (i = 0; i < gens->n; i++) { - rustsecp256k1zkp_v0_8_0_generator gen; - rustsecp256k1zkp_v0_8_0_generator_save(&gen, &gens->gens[i]); - rustsecp256k1zkp_v0_8_0_generator_serialize(ctx, &data[33 * i], &gen); + rustsecp256k1zkp_v0_10_0_generator gen; + rustsecp256k1zkp_v0_10_0_generator_save(&gen, &gens->gens[i]); + rustsecp256k1zkp_v0_10_0_generator_serialize(ctx, &data[33 * i], &gen); } *data_len = 33 * gens->n; return 1; } -void rustsecp256k1zkp_v0_8_0_bppp_generators_destroy(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_bppp_generators *gens) { +void rustsecp256k1zkp_v0_10_0_bppp_generators_destroy(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_bppp_generators *gens) { VERIFY_CHECK(ctx != NULL); (void) ctx; if (gens != NULL) { diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/test_vectors/prove.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/test_vectors/prove.h new file mode 100644 index 00000000..3577d7dd --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/test_vectors/prove.h @@ -0,0 +1,47 @@ +static const unsigned char prove_vector_gens[264] = { 0x03, 0xAF, 0x2C, 0x40, 0xAD, 0x03, 0xCD, 0xC5, 0x76, 0x8C, 0x07, 0x1E, 0x58, 0xD6, 0x8C, 0x73, 0x45, 0xBA, 0xEB, 0xB5, 0x3F, 0x40, 0xFA, 0x8B, 0xBF, 0x73, 0x6E, 0x7B, 0x4A, 0x54, 0x06, 0xED, 0x32, 0x03, 0xCC, 0x11, 0x19, 0x22, 0x2C, 0xA1, 0x0A, 0x45, 0x23, 0xAF, 0x9B, 0x40, 0x0D, 0xA4, 0x5E, 0x06, 0x24, 0xF4, 0x5F, 0x07, 0x89, 0x88, 0xCD, 0x71, 0xAE, 0x77, 0xC1, 0xF5, 0x87, 0x4E, 0xFC, 0xA5, 0x03, 0xDE, 0x61, 0xB1, 0x8F, 0x2C, 0xAC, 0x18, 0xF5, 0xE4, 0x06, 0x8F, 0x65, 0x55, 0xA1, 0x30, 0x5E, 0xF5, 0xF4, 0x84, 0xED, 0x6B, 0xDD, 0xC2, 0xCC, 0xE8, 0x51, 0x38, 0xB8, 0xA5, 0x4C, 0x43, 0xBD, 0x02, 0xA5, 0xF9, 0x8C, 0x1F, 0x82, 0x2D, 0xC6, 0xF3, 0x0F, 0x53, 0xDB, 0x74, 0x77, 0xC7, 0x91, 0x04, 0xB0, 0xB1, 0xA6, 0x17, 0xB2, 0x91, 0xF4, 0x8B, 0x93, 0x3E, 0xBB, 0x73, 0x15, 0x3E, 0x5A, 0xD1, 0x02, 0x44, 0xF5, 0xC6, 0x4E, 0x77, 0x60, 0x81, 0x83, 0xFF, 0xC2, 0x8E, 0x06, 0xFE, 0x67, 0x0C, 0x9A, 0x4B, 0xF2, 0x34, 0xB9, 0xEA, 0xE9, 0x37, 0xDA, 0x30, 0xE2, 0x32, 0x27, 0xF3, 0x88, 0x5F, 0x2A, 0x02, 0x1D, 0x49, 0x5D, 0x04, 0xED, 0x61, 0x95, 0x37, 0xDD, 0x95, 0xB1, 0x4F, 0x64, 0x0E, 0x1E, 0xFB, 0x47, 0x9F, 0xA7, 0xD7, 0xE0, 0x7A, 0xB1, 0x02, 0x81, 0x95, 0xD1, 0xA5, 0x7E, 0xB2, 0x74, 0x8F, 0x03, 0x26, 0xA5, 0xEC, 0xE9, 0x71, 0x46, 0x37, 0xAC, 0x3D, 0x74, 0x84, 0x26, 0xCB, 0x7C, 0xE8, 0xFE, 0x4E, 0xB0, 0x6D, 0x70, 0x3D, 0x00, 0x10, 0x1A, 0x3A, 0x5B, 0xB8, 0xAA, 0x29, 0x59, 0x93, 0x15, 0x03, 0xE1, 0xA5, 0x39, 0x44, 0x75, 0x16, 0x28, 0x5F, 0xBA, 0x69, 0xA2, 0x4A, 0x2A, 0xC3, 0x5B, 0x63, 0x1F, 0x40, 0x10, 0x36, 0xF9, 0x4C, 0xD2, 0x76, 0x0F, 0xCF, 0x7F, 0x50, 0x30, 0x6E, 0x2B, 0x1D }; +static const unsigned char prove_vector_0_n_vec32[1][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3F } }; +static rustsecp256k1zkp_v0_10_0_scalar prove_vector_0_n_vec[1]; +static const unsigned char prove_vector_0_l_vec32[1][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3E } }; +static rustsecp256k1zkp_v0_10_0_scalar prove_vector_0_l_vec[1]; +static const unsigned char prove_vector_0_c_vec32[1][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3C } }; +static rustsecp256k1zkp_v0_10_0_scalar prove_vector_0_c_vec[1]; +static const unsigned char prove_vector_0_r32[32] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3A }; +static const unsigned char prove_vector_0_proof[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3E }; +static const int prove_vector_0_result = 1; +static const unsigned char prove_vector_1_n_vec32[2][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3F }, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }; +static rustsecp256k1zkp_v0_10_0_scalar prove_vector_1_n_vec[2]; +static const unsigned char prove_vector_1_l_vec32[4][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3E }, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }, { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x34 }, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B } }; +static rustsecp256k1zkp_v0_10_0_scalar prove_vector_1_l_vec[4]; +static const unsigned char prove_vector_1_c_vec32[4][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3C }, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03 }, { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x30 }, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D } }; +static rustsecp256k1zkp_v0_10_0_scalar prove_vector_1_c_vec[4]; +static const unsigned char prove_vector_1_r32[32] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3A }; +static const unsigned char prove_vector_1_proof[] = { 0x00, 0xD2, 0xEC, 0xE2, 0x53, 0x97, 0x28, 0x68, 0x22, 0x59, 0x34, 0xEF, 0xE4, 0x7B, 0x87, 0x4D, 0xE9, 0x57, 0xD5, 0xB7, 0xC7, 0x72, 0xF4, 0xC9, 0xEA, 0x66, 0x14, 0x59, 0xE1, 0xA9, 0xD5, 0xB2, 0x10, 0xDF, 0xE2, 0xFF, 0xF5, 0xA4, 0x38, 0x6B, 0xFE, 0x36, 0x89, 0xE4, 0x9D, 0x90, 0x9F, 0x71, 0x19, 0xE6, 0xA3, 0x1E, 0xAA, 0xAA, 0x4E, 0xFE, 0xC2, 0xD3, 0x37, 0xBB, 0xDE, 0xDB, 0x46, 0x43, 0xC2, 0x01, 0x42, 0x5F, 0xFC, 0xC6, 0x25, 0xA0, 0xB4, 0xF0, 0x76, 0x99, 0xF4, 0x7C, 0xE9, 0x83, 0x82, 0xED, 0x7C, 0x95, 0xBA, 0xD0, 0xE6, 0x5B, 0x88, 0xFD, 0x38, 0xEA, 0x23, 0x54, 0xD4, 0xBD, 0xD4, 0x37, 0xB8, 0x2B, 0x49, 0xAF, 0x81, 0xFD, 0xBE, 0x88, 0xB2, 0xE5, 0x3F, 0xF4, 0x30, 0x52, 0x00, 0x63, 0x9D, 0xAE, 0x82, 0x44, 0xE9, 0x62, 0x87, 0x2A, 0x23, 0x89, 0x10, 0xE4, 0x9A, 0x64, 0x9F, 0x71, 0xD9, 0x32, 0x57, 0x3B, 0xCB, 0xAC, 0x30, 0xAE, 0x71, 0x61, 0xE9, 0x50, 0x1F, 0xCB, 0x49, 0x9C, 0x52, 0xBA, 0x0C, 0xC4, 0x00, 0x58, 0x73, 0x63, 0xD3, 0x42, 0xDE, 0x42, 0x5E, 0xC5, 0x97, 0xE5, 0xDA, 0x88, 0x76, 0x49, 0x6C, 0x8B, 0x92, 0x99, 0xEE, 0xD0, 0xA9, 0xEB, 0x6E, 0xCA, 0xE1, 0x93, 0x81, 0x56, 0x2E, 0xCA, 0xF3, 0x8E, 0xF0, 0x04, 0xD2, 0x96, 0xD8, 0xDB, 0xEE, 0xEE, 0x1C, 0x44 }; +static const int prove_vector_1_result = 1; +static const unsigned char prove_vector_2_n_vec32[4][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3F }, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x34 }, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B } }; +static rustsecp256k1zkp_v0_10_0_scalar prove_vector_2_n_vec[4]; +static const unsigned char prove_vector_2_l_vec32[1][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3E } }; +static rustsecp256k1zkp_v0_10_0_scalar prove_vector_2_l_vec[1]; +static const unsigned char prove_vector_2_c_vec32[1][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3C } }; +static rustsecp256k1zkp_v0_10_0_scalar prove_vector_2_c_vec[1]; +static const unsigned char prove_vector_2_r32[32] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x34 }; +static const unsigned char prove_vector_2_proof[] = { 0x00, 0xBC, 0x4C, 0x42, 0x67, 0x71, 0x69, 0x52, 0x6A, 0x65, 0xFE, 0xA0, 0xCB, 0x3F, 0x58, 0x8B, 0x48, 0x48, 0x6E, 0x59, 0xFC, 0x55, 0x51, 0x10, 0xB9, 0xBF, 0x6A, 0x7D, 0xBF, 0x32, 0x34, 0x4E, 0x7D, 0xBA, 0xD5, 0xCB, 0xCC, 0x19, 0xED, 0xAA, 0x9F, 0x8D, 0x93, 0x26, 0x5E, 0x3F, 0x3E, 0xAA, 0xDF, 0x0B, 0x1C, 0xB3, 0xDC, 0x37, 0xB6, 0xDB, 0xAE, 0x43, 0x63, 0x92, 0xB5, 0xFF, 0x0D, 0x1C, 0x77, 0x02, 0x7E, 0x2B, 0xB8, 0x87, 0x85, 0x81, 0x13, 0x70, 0x1F, 0x03, 0x65, 0x7D, 0xD8, 0x91, 0x83, 0xE5, 0x7E, 0x8B, 0x9E, 0x6F, 0x1C, 0x08, 0x9C, 0x9C, 0x5F, 0xA4, 0x12, 0x5F, 0xD3, 0xEE, 0xE2, 0x74, 0x7A, 0x2C, 0x58, 0x3A, 0x29, 0x4F, 0x64, 0x10, 0xE7, 0x89, 0xBF, 0xB2, 0xE5, 0xD9, 0xD5, 0xC5, 0x62, 0x83, 0x0C, 0xA8, 0xDD, 0x1E, 0x24, 0x6D, 0xD1, 0x58, 0x8D, 0x80, 0x74, 0xF3, 0xD9, 0x3A, 0x68, 0x7B, 0xF5, 0x12, 0xC6, 0xC2, 0x3F, 0x71, 0x47, 0xDF, 0xCF, 0xC8, 0xE2, 0xC4, 0x59, 0xDF, 0x4F, 0xEC, 0x86, 0xE9, 0xF9, 0x31, 0x94, 0x6A, 0x5F, 0xD9, 0x1E, 0x6B, 0x09, 0xCD, 0xCF, 0x5D, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3E }; +static const int prove_vector_2_result = 1; +static const unsigned char prove_vector_3_n_vec32[1][32] = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; +static rustsecp256k1zkp_v0_10_0_scalar prove_vector_3_n_vec[1]; +static const unsigned char prove_vector_3_l_vec32[1][32] = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; +static rustsecp256k1zkp_v0_10_0_scalar prove_vector_3_l_vec[1]; +static const unsigned char prove_vector_3_c_vec32[1][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3C } }; +static rustsecp256k1zkp_v0_10_0_scalar prove_vector_3_c_vec[1]; +static const unsigned char prove_vector_3_r32[32] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x34 }; +static const unsigned char prove_vector_3_proof[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +static const int prove_vector_3_result = 1; +static const unsigned char prove_vector_4_n_vec32[2][32] = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; +static rustsecp256k1zkp_v0_10_0_scalar prove_vector_4_n_vec[2]; +static const unsigned char prove_vector_4_l_vec32[1][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3A } }; +static rustsecp256k1zkp_v0_10_0_scalar prove_vector_4_l_vec[1]; +static const unsigned char prove_vector_4_c_vec32[1][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3C } }; +static rustsecp256k1zkp_v0_10_0_scalar prove_vector_4_c_vec[1]; +static const unsigned char prove_vector_4_r32[32] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x34 }; +static const unsigned char prove_vector_4_proof[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3A }; +static const int prove_vector_4_result = 1; + diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/test_vectors/verify.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/test_vectors/verify.h index 1213dc7a..96d8ab96 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/test_vectors/verify.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/test_vectors/verify.h @@ -2,64 +2,92 @@ static const unsigned char verify_vector_gens[264] = { 0x03, 0xAF, 0x2C, 0x40, 0 static const unsigned char verify_vector_0_commit33[33] = { 0x03, 0xD7, 0x53, 0x31, 0x5B, 0xAA, 0x04, 0xD5, 0x7C, 0x4A, 0x34, 0x94, 0x98, 0xBC, 0xA9, 0x1E, 0xD6, 0xA3, 0xBF, 0x81, 0xFC, 0x38, 0x30, 0x7C, 0x3B, 0x7C, 0xFC, 0xC6, 0xFF, 0x1A, 0x13, 0x36, 0x72 }; static const size_t verify_vector_0_n_vec_len = 1; static const unsigned char verify_vector_0_c_vec32[1][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3C } }; -static rustsecp256k1zkp_v0_8_0_scalar verify_vector_0_c_vec[1]; +static rustsecp256k1zkp_v0_10_0_scalar verify_vector_0_c_vec[1]; static const unsigned char verify_vector_0_r32[32] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3A }; static const unsigned char verify_vector_0_proof[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3E }; static const int verify_vector_0_result = 1; static const unsigned char verify_vector_1_commit33[33] = { 0x02, 0x6C, 0x09, 0xD7, 0x06, 0x2D, 0x1C, 0x07, 0x0A, 0x64, 0x34, 0x82, 0xF6, 0x46, 0x03, 0xEB, 0x24, 0x3E, 0x54, 0x0F, 0xDA, 0xAF, 0x3A, 0x69, 0x5F, 0x86, 0xB6, 0xD2, 0xC2, 0x06, 0xE9, 0x49, 0xC7 }; static const size_t verify_vector_1_n_vec_len = 1; static const unsigned char verify_vector_1_c_vec32[1][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3C } }; -static rustsecp256k1zkp_v0_8_0_scalar verify_vector_1_c_vec[1]; +static rustsecp256k1zkp_v0_10_0_scalar verify_vector_1_c_vec[1]; static const unsigned char verify_vector_1_r32[32] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3A }; static const unsigned char verify_vector_1_proof[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3E }; static const int verify_vector_1_result = 0; static const unsigned char verify_vector_2_commit33[33] = { 0x03, 0xD7, 0x53, 0x31, 0x5B, 0xAA, 0x04, 0xD5, 0x7C, 0x4A, 0x34, 0x94, 0x98, 0xBC, 0xA9, 0x1E, 0xD6, 0xA3, 0xBF, 0x81, 0xFC, 0x38, 0x30, 0x7C, 0x3B, 0x7C, 0xFC, 0xC6, 0xFF, 0x1A, 0x13, 0x36, 0x72 }; static const size_t verify_vector_2_n_vec_len = 1; static const unsigned char verify_vector_2_c_vec32[1][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3C } }; -static rustsecp256k1zkp_v0_8_0_scalar verify_vector_2_c_vec[1]; +static rustsecp256k1zkp_v0_10_0_scalar verify_vector_2_c_vec[1]; static const unsigned char verify_vector_2_r32[32] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3A }; static const unsigned char verify_vector_2_proof[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x41 }; static const int verify_vector_2_result = 0; static const unsigned char verify_vector_3_commit33[33] = { 0x03, 0xD7, 0x53, 0x31, 0x5B, 0xAA, 0x04, 0xD5, 0x7C, 0x4A, 0x34, 0x94, 0x98, 0xBC, 0xA9, 0x1E, 0xD6, 0xA3, 0xBF, 0x81, 0xFC, 0x38, 0x30, 0x7C, 0x3B, 0x7C, 0xFC, 0xC6, 0xFF, 0x1A, 0x13, 0x36, 0x72 }; static const size_t verify_vector_3_n_vec_len = 1; static const unsigned char verify_vector_3_c_vec32[1][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3C } }; -static rustsecp256k1zkp_v0_8_0_scalar verify_vector_3_c_vec[1]; +static rustsecp256k1zkp_v0_10_0_scalar verify_vector_3_c_vec[1]; static const unsigned char verify_vector_3_r32[32] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3A }; static const unsigned char verify_vector_3_proof[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x41, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x41 }; static const int verify_vector_3_result = 0; static const unsigned char verify_vector_4_commit33[33] = { 0x03, 0xD7, 0x53, 0x31, 0x5B, 0xAA, 0x04, 0xD5, 0x7C, 0x4A, 0x34, 0x94, 0x98, 0xBC, 0xA9, 0x1E, 0xD6, 0xA3, 0xBF, 0x81, 0xFC, 0x38, 0x30, 0x7C, 0x3B, 0x7C, 0xFC, 0xC6, 0xFF, 0x1A, 0x13, 0x36, 0x72 }; static const size_t verify_vector_4_n_vec_len = 1; static const unsigned char verify_vector_4_c_vec32[1][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3C } }; -static rustsecp256k1zkp_v0_8_0_scalar verify_vector_4_c_vec[1]; +static rustsecp256k1zkp_v0_10_0_scalar verify_vector_4_c_vec[1]; static const unsigned char verify_vector_4_r32[32] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3A }; static const unsigned char verify_vector_4_proof[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41 }; static const int verify_vector_4_result = 0; static const unsigned char verify_vector_5_commit33[33] = { 0x03, 0x83, 0x6A, 0xD4, 0x2D, 0xD2, 0x02, 0x49, 0xC8, 0x6E, 0x53, 0x22, 0x53, 0x24, 0xDA, 0x52, 0x08, 0xC0, 0x62, 0x4C, 0xCB, 0xB3, 0x13, 0xD7, 0x14, 0x59, 0x68, 0x47, 0x56, 0x00, 0xC0, 0x8D, 0xBA }; static const size_t verify_vector_5_n_vec_len = 2; static const unsigned char verify_vector_5_c_vec32[1][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3C } }; -static rustsecp256k1zkp_v0_8_0_scalar verify_vector_5_c_vec[1]; +static rustsecp256k1zkp_v0_10_0_scalar verify_vector_5_c_vec[1]; static const unsigned char verify_vector_5_r32[32] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x36 }; static const unsigned char verify_vector_5_proof[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x4C, 0xB9, 0xD4, 0x34, 0xA2, 0xD6, 0xD5, 0x4C, 0x0F, 0x2E, 0x2C, 0xE3, 0x82, 0x17, 0x48, 0x63, 0xE0, 0xAE, 0x6B, 0xD7, 0x64, 0x9D, 0x43, 0x2B, 0x6E, 0x6E, 0x1C, 0x62, 0x55, 0x4B, 0xC5, 0x73, 0x3D, 0x74, 0x7B, 0x78, 0x43, 0xF4, 0x8B, 0x7C, 0x84, 0x10, 0x00, 0x8B, 0x12, 0xAF, 0xA4, 0xF1, 0xF4, 0x01, 0x96, 0x21, 0x8B, 0xE9, 0x05, 0x01, 0xF8, 0x23, 0x7A, 0x8F, 0x66, 0xC9, 0xDE, 0xE1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3E }; static const int verify_vector_5_result = 0; static const unsigned char verify_vector_6_commit33[33] = { 0x03, 0xCF, 0x7F, 0x08, 0xF5, 0x8A, 0x06, 0x74, 0x5C, 0xDB, 0xCE, 0xC6, 0x51, 0xF3, 0xE5, 0xE4, 0xDC, 0xAD, 0xF4, 0x40, 0x3C, 0xFA, 0xE6, 0x78, 0xBE, 0x49, 0x2D, 0x90, 0xC8, 0xD0, 0x16, 0x3D, 0x78 }; static const size_t verify_vector_6_n_vec_len = 2; static const unsigned char verify_vector_6_c_vec32[4][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3C }, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03 }, { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x30 }, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D } }; -static rustsecp256k1zkp_v0_8_0_scalar verify_vector_6_c_vec[4]; +static rustsecp256k1zkp_v0_10_0_scalar verify_vector_6_c_vec[4]; static const unsigned char verify_vector_6_r32[32] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3A }; static const unsigned char verify_vector_6_proof[] = { 0x00, 0xD2, 0xEC, 0xE2, 0x53, 0x97, 0x28, 0x68, 0x22, 0x59, 0x34, 0xEF, 0xE4, 0x7B, 0x87, 0x4D, 0xE9, 0x57, 0xD5, 0xB7, 0xC7, 0x72, 0xF4, 0xC9, 0xEA, 0x66, 0x14, 0x59, 0xE1, 0xA9, 0xD5, 0xB2, 0x10, 0xDF, 0xE2, 0xFF, 0xF5, 0xA4, 0x38, 0x6B, 0xFE, 0x36, 0x89, 0xE4, 0x9D, 0x90, 0x9F, 0x71, 0x19, 0xE6, 0xA3, 0x1E, 0xAA, 0xAA, 0x4E, 0xFE, 0xC2, 0xD3, 0x37, 0xBB, 0xDE, 0xDB, 0x46, 0x43, 0xC2, 0x01, 0x42, 0x5F, 0xFC, 0xC6, 0x25, 0xA0, 0xB4, 0xF0, 0x76, 0x99, 0xF4, 0x7C, 0xE9, 0x83, 0x82, 0xED, 0x7C, 0x95, 0xBA, 0xD0, 0xE6, 0x5B, 0x88, 0xFD, 0x38, 0xEA, 0x23, 0x54, 0xD4, 0xBD, 0xD4, 0x37, 0xB8, 0x2B, 0x49, 0xAF, 0x81, 0xFD, 0xBE, 0x88, 0xB2, 0xE5, 0x3F, 0xF4, 0x30, 0x52, 0x00, 0x63, 0x9D, 0xAE, 0x82, 0x44, 0xE9, 0x62, 0x87, 0x2A, 0x23, 0x89, 0x10, 0xE4, 0x9A, 0x64, 0x9F, 0x71, 0xD9, 0x32, 0x57, 0x3B, 0xCB, 0xAC, 0x30, 0xAE, 0x71, 0x61, 0xE9, 0x50, 0x1F, 0xCB, 0x49, 0x9C, 0x52, 0xBA, 0x0C, 0xC4, 0x00, 0x58, 0x73, 0x63, 0xD3, 0x42, 0xDE, 0x42, 0x5E, 0xC5, 0x97, 0xE5, 0xDA, 0x88, 0x76, 0x49, 0x6C, 0x8B, 0x92, 0x99, 0xEE, 0xD0, 0xA9, 0xEB, 0x6E, 0xCA, 0xE1, 0x93, 0x81, 0x56, 0x2E, 0xCA, 0xF3, 0x8E, 0xF0, 0x04, 0xD2, 0x96, 0xD8, 0xDB, 0xEE, 0xEE, 0x1C, 0x44 }; static const int verify_vector_6_result = 1; static const unsigned char verify_vector_7_commit33[33] = { 0x02, 0x7A, 0xAA, 0xB2, 0x7E, 0xA5, 0x5B, 0x77, 0x08, 0xE5, 0x43, 0xB6, 0x22, 0x7F, 0xC9, 0xAC, 0x53, 0x10, 0x32, 0x61, 0x7B, 0x7D, 0xAC, 0xB1, 0xB6, 0xF6, 0xAC, 0xDE, 0x63, 0x79, 0x82, 0x9C, 0x24 }; static const size_t verify_vector_7_n_vec_len = 4; static const unsigned char verify_vector_7_c_vec32[1][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3C } }; -static rustsecp256k1zkp_v0_8_0_scalar verify_vector_7_c_vec[1]; +static rustsecp256k1zkp_v0_10_0_scalar verify_vector_7_c_vec[1]; static const unsigned char verify_vector_7_r32[32] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x34 }; static const unsigned char verify_vector_7_proof[] = { 0x00, 0xBC, 0x4C, 0x42, 0x67, 0x71, 0x69, 0x52, 0x6A, 0x65, 0xFE, 0xA0, 0xCB, 0x3F, 0x58, 0x8B, 0x48, 0x48, 0x6E, 0x59, 0xFC, 0x55, 0x51, 0x10, 0xB9, 0xBF, 0x6A, 0x7D, 0xBF, 0x32, 0x34, 0x4E, 0x7D, 0xBA, 0xD5, 0xCB, 0xCC, 0x19, 0xED, 0xAA, 0x9F, 0x8D, 0x93, 0x26, 0x5E, 0x3F, 0x3E, 0xAA, 0xDF, 0x0B, 0x1C, 0xB3, 0xDC, 0x37, 0xB6, 0xDB, 0xAE, 0x43, 0x63, 0x92, 0xB5, 0xFF, 0x0D, 0x1C, 0x77, 0x02, 0x7E, 0x2B, 0xB8, 0x87, 0x85, 0x81, 0x13, 0x70, 0x1F, 0x03, 0x65, 0x7D, 0xD8, 0x91, 0x83, 0xE5, 0x7E, 0x8B, 0x9E, 0x6F, 0x1C, 0x08, 0x9C, 0x9C, 0x5F, 0xA4, 0x12, 0x5F, 0xD3, 0xEE, 0xE2, 0x74, 0x7A, 0x2C, 0x58, 0x3A, 0x29, 0x4F, 0x64, 0x10, 0xE7, 0x89, 0xBF, 0xB2, 0xE5, 0xD9, 0xD5, 0xC5, 0x62, 0x83, 0x0C, 0xA8, 0xDD, 0x1E, 0x24, 0x6D, 0xD1, 0x58, 0x8D, 0x80, 0x74, 0xF3, 0xD9, 0x3A, 0x68, 0x7B, 0xF5, 0x12, 0xC6, 0xC2, 0x3F, 0x71, 0x47, 0xDF, 0xCF, 0xC8, 0xE2, 0xC4, 0x59, 0xDF, 0x4F, 0xEC, 0x86, 0xE9, 0xF9, 0x31, 0x94, 0x6A, 0x5F, 0xD9, 0x1E, 0x6B, 0x09, 0xCD, 0xCF, 0x5D, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3E }; static const int verify_vector_7_result = 1; static const unsigned char verify_vector_8_commit33[33] = { 0x02, 0x2D, 0x4F, 0xF9, 0xB7, 0x15, 0x22, 0xBC, 0xB0, 0x8B, 0xF8, 0xBA, 0x31, 0x0A, 0x80, 0x76, 0x7A, 0xE9, 0xA9, 0x83, 0x00, 0xBC, 0x5A, 0x01, 0xCC, 0xE9, 0x00, 0x83, 0x56, 0xEA, 0x77, 0xEB, 0x75 }; static const size_t verify_vector_8_n_vec_len = 4; static const unsigned char verify_vector_8_c_vec32[1][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3C } }; -static rustsecp256k1zkp_v0_8_0_scalar verify_vector_8_c_vec[1]; +static rustsecp256k1zkp_v0_10_0_scalar verify_vector_8_c_vec[1]; static const unsigned char verify_vector_8_r32[32] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x34 }; static const unsigned char verify_vector_8_proof[] = { 0x00, 0xBC, 0x4C, 0x42, 0x67, 0x71, 0x69, 0x52, 0x6A, 0x65, 0xFE, 0xA0, 0xCB, 0x3F, 0x58, 0x8B, 0x48, 0x48, 0x6E, 0x59, 0xFC, 0x55, 0x51, 0x10, 0xB9, 0xBF, 0x6A, 0x7D, 0xBF, 0x32, 0x34, 0x4E, 0x7D, 0xBA, 0xD5, 0xCB, 0xCC, 0x19, 0xED, 0xAA, 0x9F, 0x8D, 0x93, 0x26, 0x5E, 0x3F, 0x3E, 0xAA, 0xDF, 0x0B, 0x1C, 0xB3, 0xDC, 0x37, 0xB6, 0xDB, 0xAE, 0x43, 0x63, 0x92, 0xB5, 0xFF, 0x0D, 0x1C, 0x77, 0x02, 0x7E, 0x2B, 0xB8, 0x87, 0x85, 0x81, 0x13, 0x70, 0x1F, 0x03, 0x65, 0x7D, 0xD8, 0x91, 0x83, 0xE5, 0x7E, 0x8B, 0x9E, 0x6F, 0x1C, 0x08, 0x9C, 0x9C, 0x5F, 0xA4, 0x12, 0x5F, 0xD3, 0xEE, 0xE2, 0x74, 0x7A, 0x2C, 0x58, 0x3A, 0x29, 0x4F, 0x64, 0x10, 0xE7, 0x89, 0xBF, 0xB2, 0xE5, 0xD9, 0xD5, 0xC5, 0x62, 0x83, 0x0C, 0xA8, 0xDD, 0x1E, 0x24, 0x6D, 0xD1, 0x58, 0x8D, 0x80, 0x74, 0xF3, 0xD9, 0x3A, 0x68, 0x7B, 0xF5, 0x12, 0xC6, 0xC2, 0x3F, 0x71, 0x47, 0xDF, 0xCF, 0xC8, 0xE2, 0xC4, 0x59, 0xDF, 0x4F, 0xEC, 0x86, 0xE9, 0xF9, 0x31, 0x94, 0x6A, 0x5F, 0xD9, 0x1E, 0x6B, 0x09, 0xCD, 0xCF, 0x5D, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3E }; static const int verify_vector_8_result = 0; +static const unsigned char verify_vector_9_commit33[33] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +static const size_t verify_vector_9_n_vec_len = 1; +static const unsigned char verify_vector_9_c_vec32[1][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3C } }; +static rustsecp256k1zkp_v0_10_0_scalar verify_vector_9_c_vec[1]; +static const unsigned char verify_vector_9_r32[32] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x34 }; +static const unsigned char verify_vector_9_proof[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +static const int verify_vector_9_result = 1; +static const unsigned char verify_vector_10_commit33[33] = { 0x03, 0x62, 0x8A, 0xC2, 0xF1, 0xF2, 0x00, 0xE0, 0x81, 0xBD, 0xA0, 0xA9, 0x6D, 0x25, 0x53, 0xB4, 0x17, 0xC1, 0x02, 0x93, 0x50, 0x3E, 0x91, 0xD4, 0xD1, 0x3A, 0x82, 0x89, 0x02, 0x24, 0x78, 0x49, 0xA5 }; +static const size_t verify_vector_10_n_vec_len = 2; +static const unsigned char verify_vector_10_c_vec32[1][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3C } }; +static rustsecp256k1zkp_v0_10_0_scalar verify_vector_10_c_vec[1]; +static const unsigned char verify_vector_10_r32[32] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x34 }; +static const unsigned char verify_vector_10_proof[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3A }; +static const int verify_vector_10_result = 1; +static const unsigned char verify_vector_11_commit33[33] = { 0x03, 0x62, 0x8A, 0xC2, 0xF1, 0xF2, 0x00, 0xE0, 0x81, 0xBD, 0xA0, 0xA9, 0x6D, 0x25, 0x53, 0xB4, 0x17, 0xC1, 0x02, 0x93, 0x50, 0x3E, 0x91, 0xD4, 0xD1, 0x3A, 0x82, 0x89, 0x02, 0x24, 0x78, 0x49, 0xA5 }; +static const size_t verify_vector_11_n_vec_len = 2; +static const unsigned char verify_vector_11_c_vec32[1][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3C } }; +static rustsecp256k1zkp_v0_10_0_scalar verify_vector_11_c_vec[1]; +static const unsigned char verify_vector_11_r32[32] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x34 }; +static const unsigned char verify_vector_11_proof[] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3A }; +static const int verify_vector_11_result = 0; +static const unsigned char verify_vector_12_commit33[33] = { 0x02, 0x7D, 0x5F, 0x4B, 0x11, 0xC0, 0xE4, 0x2E, 0x4C, 0x1B, 0x56, 0xAE, 0xF0, 0x5F, 0xAA, 0xD8, 0x77, 0x0C, 0x93, 0x71, 0xA2, 0x92, 0xF9, 0x89, 0xA2, 0xB4, 0x69, 0x9B, 0x46, 0x8A, 0x03, 0xF1, 0x50 }; +static const size_t verify_vector_12_n_vec_len = 0; +static const unsigned char verify_vector_12_c_vec32[1][32] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3C } }; +static rustsecp256k1zkp_v0_10_0_scalar verify_vector_12_c_vec[1]; +static const unsigned char verify_vector_12_r32[32] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x34 }; +static const unsigned char verify_vector_12_proof[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x34, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x3A }; +static const int verify_vector_12_result = 0; diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/tests_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/tests_impl.h index 30a7a4f1..f55caa9d 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/tests_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/bppp/tests_impl.h @@ -4,93 +4,73 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef _SECP256K1_MODULE_BPPP_TEST_ -#define _SECP256K1_MODULE_BPPP_TEST_ +#ifndef SECP256K1_MODULE_BPPP_TEST_H +#define SECP256K1_MODULE_BPPP_TEST_H #include -#include "include/secp256k1_bppp.h" +#include "../../../include/secp256k1_bppp.h" #include "bppp_norm_product_impl.h" #include "bppp_util.h" #include "bppp_transcript_impl.h" #include "test_vectors/verify.h" +#include "test_vectors/prove.h" static void test_bppp_generators_api(void) { - /* The BP generator API requires no precomp */ - rustsecp256k1zkp_v0_8_0_context *none = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_NONE); - - rustsecp256k1zkp_v0_8_0_bppp_generators *gens; - rustsecp256k1zkp_v0_8_0_bppp_generators *gens_orig; + rustsecp256k1zkp_v0_10_0_bppp_generators *gens; + rustsecp256k1zkp_v0_10_0_bppp_generators *gens_orig; unsigned char gens_ser[330]; size_t len = sizeof(gens_ser); - int32_t ecount = 0; - - rustsecp256k1zkp_v0_8_0_context_set_error_callback(none, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(none, counting_illegal_callback_fn, &ecount); - /* Create */ - gens = rustsecp256k1zkp_v0_8_0_bppp_generators_create(none, 10); - CHECK(gens != NULL && ecount == 0); + gens = rustsecp256k1zkp_v0_10_0_bppp_generators_create(CTX, 10); + CHECK(gens != NULL); gens_orig = gens; /* Preserve for round-trip test */ /* Serialize */ - ecount = 0; - CHECK(!rustsecp256k1zkp_v0_8_0_bppp_generators_serialize(none, NULL, gens_ser, &len)); - CHECK(ecount == 1); - CHECK(!rustsecp256k1zkp_v0_8_0_bppp_generators_serialize(none, gens, NULL, &len)); - CHECK(ecount == 2); - CHECK(!rustsecp256k1zkp_v0_8_0_bppp_generators_serialize(none, gens, gens_ser, NULL)); - CHECK(ecount == 3); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_bppp_generators_serialize(CTX, NULL, gens_ser, &len)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_bppp_generators_serialize(CTX, gens, NULL, &len)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_bppp_generators_serialize(CTX, gens, gens_ser, NULL)); len = 0; - CHECK(!rustsecp256k1zkp_v0_8_0_bppp_generators_serialize(none, gens, gens_ser, &len)); - CHECK(ecount == 4); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_bppp_generators_serialize(CTX, gens, gens_ser, &len)); len = sizeof(gens_ser) - 1; - CHECK(!rustsecp256k1zkp_v0_8_0_bppp_generators_serialize(none, gens, gens_ser, &len)); - CHECK(ecount == 5); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_bppp_generators_serialize(CTX, gens, gens_ser, &len)); len = sizeof(gens_ser); { /* Output buffer can be greater than minimum needed */ unsigned char gens_ser_tmp[331]; size_t len_tmp = sizeof(gens_ser_tmp); - CHECK(rustsecp256k1zkp_v0_8_0_bppp_generators_serialize(none, gens, gens_ser_tmp, &len_tmp)); + CHECK(rustsecp256k1zkp_v0_10_0_bppp_generators_serialize(CTX, gens, gens_ser_tmp, &len_tmp)); CHECK(len_tmp == sizeof(gens_ser_tmp) - 1); - CHECK(ecount == 5); } /* Parse */ - CHECK(rustsecp256k1zkp_v0_8_0_bppp_generators_serialize(none, gens, gens_ser, &len)); - ecount = 0; - gens = rustsecp256k1zkp_v0_8_0_bppp_generators_parse(none, NULL, sizeof(gens_ser)); - CHECK(gens == NULL && ecount == 1); + CHECK(rustsecp256k1zkp_v0_10_0_bppp_generators_serialize(CTX, gens, gens_ser, &len)); + CHECK_ILLEGAL_VOID(CTX, gens = rustsecp256k1zkp_v0_10_0_bppp_generators_parse(CTX, NULL, sizeof(gens_ser)); + CHECK(gens == NULL)); /* Not a multiple of 33 */ - gens = rustsecp256k1zkp_v0_8_0_bppp_generators_parse(none, gens_ser, sizeof(gens_ser) - 1); - CHECK(gens == NULL && ecount == 1); - gens = rustsecp256k1zkp_v0_8_0_bppp_generators_parse(none, gens_ser, sizeof(gens_ser)); - CHECK(gens != NULL && ecount == 1); + gens = rustsecp256k1zkp_v0_10_0_bppp_generators_parse(CTX, gens_ser, sizeof(gens_ser) - 1); + CHECK(gens == NULL); + gens = rustsecp256k1zkp_v0_10_0_bppp_generators_parse(CTX, gens_ser, sizeof(gens_ser)); + CHECK(gens != NULL); /* Not valid generators */ memset(gens_ser, 1, sizeof(gens_ser)); - CHECK(rustsecp256k1zkp_v0_8_0_bppp_generators_parse(none, gens_ser, sizeof(gens_ser)) == NULL); - CHECK(ecount == 1); + CHECK(rustsecp256k1zkp_v0_10_0_bppp_generators_parse(CTX, gens_ser, sizeof(gens_ser)) == NULL); /* Check that round-trip succeeded */ CHECK(gens->n == gens_orig->n); for (len = 0; len < gens->n; len++) { - ge_equals_ge(&gens->gens[len], &gens_orig->gens[len]); + rustsecp256k1zkp_v0_10_0_ge_eq_var(&gens->gens[len], &gens_orig->gens[len]); } /* Destroy (we allow destroying a NULL context, it's just a noop. like free().) */ - ecount = 0; - rustsecp256k1zkp_v0_8_0_bppp_generators_destroy(none, NULL); - rustsecp256k1zkp_v0_8_0_bppp_generators_destroy(none, gens); - rustsecp256k1zkp_v0_8_0_bppp_generators_destroy(none, gens_orig); - CHECK(ecount == 0); - - rustsecp256k1zkp_v0_8_0_context_destroy(none); + rustsecp256k1zkp_v0_10_0_bppp_generators_destroy(CTX, NULL); + rustsecp256k1zkp_v0_10_0_bppp_generators_destroy(CTX, gens); + rustsecp256k1zkp_v0_10_0_bppp_generators_destroy(CTX, gens_orig); } static void test_bppp_generators_fixed(void) { - rustsecp256k1zkp_v0_8_0_bppp_generators *gens = rustsecp256k1zkp_v0_8_0_bppp_generators_create(ctx, 3); + rustsecp256k1zkp_v0_10_0_bppp_generators *gens = rustsecp256k1zkp_v0_10_0_bppp_generators_create(CTX, 3); unsigned char gens_ser[330]; const unsigned char fixed_first_3[99] = { 0x0b, @@ -112,39 +92,39 @@ static void test_bppp_generators_fixed(void) { size_t len; len = 99; - CHECK(rustsecp256k1zkp_v0_8_0_bppp_generators_serialize(ctx, gens, gens_ser, &len)); - CHECK(memcmp(gens_ser, fixed_first_3, sizeof(fixed_first_3)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_bppp_generators_serialize(CTX, gens, gens_ser, &len)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(gens_ser, fixed_first_3, sizeof(fixed_first_3)) == 0); len = sizeof(gens_ser); - CHECK(rustsecp256k1zkp_v0_8_0_bppp_generators_serialize(ctx, gens, gens_ser, &len)); - CHECK(memcmp(gens_ser, fixed_first_3, sizeof(fixed_first_3)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_bppp_generators_serialize(CTX, gens, gens_ser, &len)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(gens_ser, fixed_first_3, sizeof(fixed_first_3)) == 0); - rustsecp256k1zkp_v0_8_0_bppp_generators_destroy(ctx, gens); + rustsecp256k1zkp_v0_10_0_bppp_generators_destroy(CTX, gens); } static void test_bppp_tagged_hash(void) { unsigned char tag_data[29] = "Bulletproofs_pp/v0/commitment"; - rustsecp256k1zkp_v0_8_0_sha256 sha; - rustsecp256k1zkp_v0_8_0_sha256 sha_cached; + rustsecp256k1zkp_v0_10_0_sha256 sha; + rustsecp256k1zkp_v0_10_0_sha256 sha_cached; unsigned char output[32]; unsigned char output_cached[32]; - rustsecp256k1zkp_v0_8_0_scalar s; + rustsecp256k1zkp_v0_10_0_scalar s; - rustsecp256k1zkp_v0_8_0_sha256_initialize_tagged(&sha, tag_data, sizeof(tag_data)); - rustsecp256k1zkp_v0_8_0_bppp_sha256_tagged_commitment_init(&sha_cached); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, output); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha_cached, output_cached); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(output, output_cached, 32) == 0); + rustsecp256k1zkp_v0_10_0_sha256_initialize_tagged(&sha, tag_data, sizeof(tag_data)); + rustsecp256k1zkp_v0_10_0_bppp_sha256_tagged_commitment_init(&sha_cached); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, output); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha_cached, output_cached); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(output, output_cached, 32) == 0); { unsigned char expected[32] = { 0x21, 0x2F, 0xB6, 0x4F, 0x9D, 0x8C, 0x3B, 0xC5, 0xF6, 0x91, 0x15, 0xEE, 0x74, 0xF5, 0x12, 0x67, 0x8A, 0x41, 0xC6, 0x85, 0x1A, 0x79, 0x14, 0xFC, 0x48, 0x15, 0xC7, 0x2D, 0xF8, 0x63, 0x8F, 0x1B }; - rustsecp256k1zkp_v0_8_0_bppp_sha256_tagged_commitment_init(&sha); - rustsecp256k1zkp_v0_8_0_bppp_challenge_scalar(&s, &sha, 0); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(output, &s); - CHECK(memcmp(output, expected, sizeof(output)) == 0); + rustsecp256k1zkp_v0_10_0_bppp_sha256_tagged_commitment_init(&sha); + rustsecp256k1zkp_v0_10_0_bppp_challenge_scalar(&s, &sha, 0); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(output, &s); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(output, expected, sizeof(output)) == 0); } { @@ -153,169 +133,235 @@ static void test_bppp_tagged_hash(void) { 0x72, 0x7E, 0x3E, 0xB7, 0x10, 0x03, 0xF0, 0xE9, 0x69, 0x4D, 0xAA, 0x96, 0xCE, 0x98, 0xBB, 0x39, 0x1C, 0x2F, 0x7C, 0x2E, 0x1C, 0x17, 0x78, 0x6D }; - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, tmp, sizeof(tmp)); - rustsecp256k1zkp_v0_8_0_bppp_challenge_scalar(&s, &sha, 0); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(output, &s); - CHECK(memcmp(output, expected, sizeof(output)) == 0); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, tmp, sizeof(tmp)); + rustsecp256k1zkp_v0_10_0_bppp_challenge_scalar(&s, &sha, 0); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(output, &s); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(output, expected, sizeof(output)) == 0); } } -void test_log_exp(void) { - CHECK(rustsecp256k1zkp_v0_8_0_is_power_of_two(0) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_is_power_of_two(1) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_is_power_of_two(2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_is_power_of_two(64) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_is_power_of_two(63) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_is_power_of_two(256) == 1); - - CHECK(rustsecp256k1zkp_v0_8_0_bppp_log2(1) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_bppp_log2(2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_bppp_log2(255) == 7); - CHECK(rustsecp256k1zkp_v0_8_0_bppp_log2(256) == 8); - CHECK(rustsecp256k1zkp_v0_8_0_bppp_log2(257) == 8); +static void test_log_exp(void) { + CHECK(rustsecp256k1zkp_v0_10_0_is_power_of_two(0) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_is_power_of_two(1) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_is_power_of_two(2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_is_power_of_two(64) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_is_power_of_two(63) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_is_power_of_two(256) == 1); + + CHECK(rustsecp256k1zkp_v0_10_0_bppp_log2(1) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_bppp_log2(2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_bppp_log2(255) == 7); + CHECK(rustsecp256k1zkp_v0_10_0_bppp_log2(256) == 8); + CHECK(rustsecp256k1zkp_v0_10_0_bppp_log2(257) == 8); } -void test_norm_util_helpers(void) { - rustsecp256k1zkp_v0_8_0_scalar a_vec[4], b_vec[4], r_pows[4], res, res2, q, r; +static void test_norm_util_helpers(void) { + rustsecp256k1zkp_v0_10_0_scalar a_vec[4], b_vec[4], rho_pows[4], res, res2, mu, rho; int i; - /* a = {1, 2, 3, 4} b = {5, 6, 7, 8}, q = 4, r = 2 */ + /* a = {1, 2, 3, 4} b = {5, 6, 7, 8}, mu = 4, rho = 2 */ for (i = 0; i < 4; i++) { - rustsecp256k1zkp_v0_8_0_scalar_set_int(&a_vec[i], i + 1); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&b_vec[i], i + 5); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&a_vec[i], i + 1); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&b_vec[i], i + 5); } - rustsecp256k1zkp_v0_8_0_scalar_set_int(&q, 4); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&r, 2); - rustsecp256k1zkp_v0_8_0_scalar_inner_product(&res, a_vec, 0, b_vec, 0, 1, 4); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&res2, 70); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&res2, &res) == 1); - - rustsecp256k1zkp_v0_8_0_scalar_inner_product(&res, a_vec, 0, b_vec, 1, 2, 2); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&res2, 30); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&res2, &res) == 1); - - rustsecp256k1zkp_v0_8_0_scalar_inner_product(&res, a_vec, 1, b_vec, 0, 2, 2); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&res2, 38); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&res2, &res) == 1); - - rustsecp256k1zkp_v0_8_0_scalar_inner_product(&res, a_vec, 1, b_vec, 1, 2, 2); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&res2, 44); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&res2, &res) == 1); - - rustsecp256k1zkp_v0_8_0_weighted_scalar_inner_product(&res, a_vec, 0, a_vec, 0, 1, 4, &q); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&res2, 4740); /*i*i*4^(i+1) */ - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&res2, &res) == 1); - - rustsecp256k1zkp_v0_8_0_bppp_powers_of_r(r_pows, &r, 4); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&res, 2); CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&res, &r_pows[0])); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&res, 4); CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&res, &r_pows[1])); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&res, 16); CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&res, &r_pows[2])); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&res, 256); CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&res, &r_pows[3])); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&mu, 4); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&rho, 2); + rustsecp256k1zkp_v0_10_0_scalar_inner_product(&res, a_vec, 0, b_vec, 0, 1, 4); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&res2, 70); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&res2, &res) == 1); + + rustsecp256k1zkp_v0_10_0_scalar_inner_product(&res, a_vec, 0, b_vec, 1, 2, 2); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&res2, 30); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&res2, &res) == 1); + + rustsecp256k1zkp_v0_10_0_scalar_inner_product(&res, a_vec, 1, b_vec, 0, 2, 2); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&res2, 38); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&res2, &res) == 1); + + rustsecp256k1zkp_v0_10_0_scalar_inner_product(&res, a_vec, 1, b_vec, 1, 2, 2); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&res2, 44); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&res2, &res) == 1); + + rustsecp256k1zkp_v0_10_0_weighted_scalar_inner_product(&res, a_vec, 0, a_vec, 0, 1, 4, &mu); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&res2, 4740); /*i*i*4^(i+1) */ + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&res2, &res) == 1); + + rustsecp256k1zkp_v0_10_0_bppp_powers_of_rho(rho_pows, &rho, 4); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&res, 2); CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&res, &rho_pows[0])); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&res, 4); CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&res, &rho_pows[1])); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&res, 16); CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&res, &rho_pows[2])); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&res, 256); CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&res, &rho_pows[3])); } -static void rustsecp256k1zkp_v0_8_0_norm_arg_commit_initial_data( - rustsecp256k1zkp_v0_8_0_sha256* transcript, - const rustsecp256k1zkp_v0_8_0_scalar* r, - const rustsecp256k1zkp_v0_8_0_bppp_generators* gens_vec, + +static void test_serialize_two_points_roundtrip(rustsecp256k1zkp_v0_10_0_ge *X, rustsecp256k1zkp_v0_10_0_ge *R) { + rustsecp256k1zkp_v0_10_0_ge X_tmp, R_tmp; + unsigned char buf[65]; + rustsecp256k1zkp_v0_10_0_bppp_serialize_points(buf, X, R); + CHECK(rustsecp256k1zkp_v0_10_0_bppp_parse_one_of_points(&X_tmp, buf, 0)); + CHECK(rustsecp256k1zkp_v0_10_0_bppp_parse_one_of_points(&R_tmp, buf, 1)); + rustsecp256k1zkp_v0_10_0_ge_eq_var(X, &X_tmp); + rustsecp256k1zkp_v0_10_0_ge_eq_var(R, &R_tmp); +} + +static void test_serialize_two_points(void) { + rustsecp256k1zkp_v0_10_0_ge X, R; + int i; + + for (i = 0; i < COUNT; i++) { + random_group_element_test(&X); + random_group_element_test(&R); + test_serialize_two_points_roundtrip(&X, &R); + } + + for (i = 0; i < COUNT; i++) { + random_group_element_test(&X); + rustsecp256k1zkp_v0_10_0_ge_set_infinity(&R); + test_serialize_two_points_roundtrip(&X, &R); + } + + for (i = 0; i < COUNT; i++) { + rustsecp256k1zkp_v0_10_0_ge_set_infinity(&X); + random_group_element_test(&R); + test_serialize_two_points_roundtrip(&X, &R); + } + + rustsecp256k1zkp_v0_10_0_ge_set_infinity(&X); + rustsecp256k1zkp_v0_10_0_ge_set_infinity(&R); + test_serialize_two_points_roundtrip(&X, &R); + + /* Test invalid sign byte */ + { + rustsecp256k1zkp_v0_10_0_ge X_tmp, R_tmp; + unsigned char buf[65]; + random_group_element_test(&X); + random_group_element_test(&R); + rustsecp256k1zkp_v0_10_0_bppp_serialize_points(buf, &X, &R); + + /* buf is valid if 0 <= buf[0] < 4. */ + buf[0] = (unsigned char)rustsecp256k1zkp_v0_10_0_testrandi64(4, 255); + CHECK(!rustsecp256k1zkp_v0_10_0_bppp_parse_one_of_points(&X_tmp, buf, 0)); + CHECK(!rustsecp256k1zkp_v0_10_0_bppp_parse_one_of_points(&R_tmp, buf, 0)); + } + /* Check that sign bit is 0 for point at infinity */ + for (i = 0; i < COUNT; i++) { + rustsecp256k1zkp_v0_10_0_ge X_tmp, R_tmp; + unsigned char buf[65]; + int expect; + random_group_element_test(&X); + random_group_element_test(&R); + rustsecp256k1zkp_v0_10_0_bppp_serialize_points(buf, &X, &R); + memset(&buf[1], 0, 32); + if ((buf[0] & 2) == 0) { + expect = 1; + } else { + expect = 0; + } + CHECK(rustsecp256k1zkp_v0_10_0_bppp_parse_one_of_points(&X_tmp, buf, 0) == expect); + CHECK(rustsecp256k1zkp_v0_10_0_bppp_parse_one_of_points(&R_tmp, buf, 1)); + memset(&buf[33], 0, 32); + if ((buf[0] & 1) == 0) { + expect = 1; + } else { + expect = 0; + } + CHECK(rustsecp256k1zkp_v0_10_0_bppp_parse_one_of_points(&R_tmp, buf, 1) == expect); + } +} + +static void rustsecp256k1zkp_v0_10_0_norm_arg_commit_initial_data( + rustsecp256k1zkp_v0_10_0_sha256* transcript, + const rustsecp256k1zkp_v0_10_0_scalar* rho, + const rustsecp256k1zkp_v0_10_0_bppp_generators* gens_vec, size_t g_len, /* Same as n_vec_len, g_len + c_vec_len = gens->n */ - const rustsecp256k1zkp_v0_8_0_scalar* c_vec, + const rustsecp256k1zkp_v0_10_0_scalar* c_vec, size_t c_vec_len, - const rustsecp256k1zkp_v0_8_0_ge* commit + const rustsecp256k1zkp_v0_10_0_ge* commit ) { /* Commit to the initial public values */ unsigned char ser_commit[33], ser_scalar[32], ser_le64[8]; size_t i; - rustsecp256k1zkp_v0_8_0_ge comm = *commit; - rustsecp256k1zkp_v0_8_0_bppp_sha256_tagged_commitment_init(transcript); - rustsecp256k1zkp_v0_8_0_fe_normalize(&comm.x); - rustsecp256k1zkp_v0_8_0_fe_normalize(&comm.y); - CHECK(rustsecp256k1zkp_v0_8_0_ge_is_infinity(&comm) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_bppp_serialize_pt(&ser_commit[0], &comm)); - rustsecp256k1zkp_v0_8_0_sha256_write(transcript, ser_commit, 33); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(ser_scalar, r); - rustsecp256k1zkp_v0_8_0_sha256_write(transcript, ser_scalar, 32); - rustsecp256k1zkp_v0_8_0_bppp_le64(ser_le64, g_len); - rustsecp256k1zkp_v0_8_0_sha256_write(transcript, ser_le64, 8); - rustsecp256k1zkp_v0_8_0_bppp_le64(ser_le64, gens_vec->n); - rustsecp256k1zkp_v0_8_0_sha256_write(transcript, ser_le64, 8); + rustsecp256k1zkp_v0_10_0_ge comm = *commit; + rustsecp256k1zkp_v0_10_0_bppp_sha256_tagged_commitment_init(transcript); + rustsecp256k1zkp_v0_10_0_fe_normalize(&comm.x); + rustsecp256k1zkp_v0_10_0_fe_normalize(&comm.y); + CHECK(rustsecp256k1zkp_v0_10_0_ge_is_infinity(&comm) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_bppp_serialize_pt(&ser_commit[0], &comm)); + rustsecp256k1zkp_v0_10_0_sha256_write(transcript, ser_commit, 33); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(ser_scalar, rho); + rustsecp256k1zkp_v0_10_0_sha256_write(transcript, ser_scalar, 32); + rustsecp256k1zkp_v0_10_0_bppp_le64(ser_le64, g_len); + rustsecp256k1zkp_v0_10_0_sha256_write(transcript, ser_le64, 8); + rustsecp256k1zkp_v0_10_0_bppp_le64(ser_le64, gens_vec->n); + rustsecp256k1zkp_v0_10_0_sha256_write(transcript, ser_le64, 8); for (i = 0; i < gens_vec->n; i++) { - rustsecp256k1zkp_v0_8_0_fe_normalize(&gens_vec->gens[i].x); - rustsecp256k1zkp_v0_8_0_fe_normalize(&gens_vec->gens[i].y); - CHECK(rustsecp256k1zkp_v0_8_0_bppp_serialize_pt(&ser_commit[0], &gens_vec->gens[i])); - rustsecp256k1zkp_v0_8_0_sha256_write(transcript, ser_commit, 33); + rustsecp256k1zkp_v0_10_0_fe_normalize(&gens_vec->gens[i].x); + rustsecp256k1zkp_v0_10_0_fe_normalize(&gens_vec->gens[i].y); + CHECK(rustsecp256k1zkp_v0_10_0_bppp_serialize_pt(&ser_commit[0], &gens_vec->gens[i])); + rustsecp256k1zkp_v0_10_0_sha256_write(transcript, ser_commit, 33); } - rustsecp256k1zkp_v0_8_0_bppp_le64(ser_le64, c_vec_len); - rustsecp256k1zkp_v0_8_0_sha256_write(transcript, ser_le64, 8); + rustsecp256k1zkp_v0_10_0_bppp_le64(ser_le64, c_vec_len); + rustsecp256k1zkp_v0_10_0_sha256_write(transcript, ser_le64, 8); for (i = 0; i < c_vec_len; i++) { - rustsecp256k1zkp_v0_8_0_scalar_get_b32(ser_scalar, &c_vec[i]); - rustsecp256k1zkp_v0_8_0_sha256_write(transcript, ser_scalar, 32); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(ser_scalar, &c_vec[i]); + rustsecp256k1zkp_v0_10_0_sha256_write(transcript, ser_scalar, 32); } } -static void copy_vectors_into_scratch(rustsecp256k1zkp_v0_8_0_scratch_space* scratch, - rustsecp256k1zkp_v0_8_0_scalar **ns, - rustsecp256k1zkp_v0_8_0_scalar **ls, - rustsecp256k1zkp_v0_8_0_scalar **cs, - rustsecp256k1zkp_v0_8_0_ge **gs, - const rustsecp256k1zkp_v0_8_0_scalar *n_vec, - const rustsecp256k1zkp_v0_8_0_scalar *l_vec, - const rustsecp256k1zkp_v0_8_0_scalar *c_vec, - const rustsecp256k1zkp_v0_8_0_ge *gens_vec, +static void copy_vectors_into_scratch(rustsecp256k1zkp_v0_10_0_scratch_space* scratch, + rustsecp256k1zkp_v0_10_0_scalar **ns, + rustsecp256k1zkp_v0_10_0_scalar **ls, + rustsecp256k1zkp_v0_10_0_scalar **cs, + rustsecp256k1zkp_v0_10_0_ge **gs, + const rustsecp256k1zkp_v0_10_0_scalar *n_vec, + const rustsecp256k1zkp_v0_10_0_scalar *l_vec, + const rustsecp256k1zkp_v0_10_0_scalar *c_vec, + const rustsecp256k1zkp_v0_10_0_ge *gens_vec, size_t g_len, size_t h_len) { - *ns = (rustsecp256k1zkp_v0_8_0_scalar*)rustsecp256k1zkp_v0_8_0_scratch_alloc(&ctx->error_callback, scratch, g_len * sizeof(rustsecp256k1zkp_v0_8_0_scalar)); - *ls = (rustsecp256k1zkp_v0_8_0_scalar*)rustsecp256k1zkp_v0_8_0_scratch_alloc(&ctx->error_callback, scratch, h_len * sizeof(rustsecp256k1zkp_v0_8_0_scalar)); - *cs = (rustsecp256k1zkp_v0_8_0_scalar*)rustsecp256k1zkp_v0_8_0_scratch_alloc(&ctx->error_callback, scratch, h_len * sizeof(rustsecp256k1zkp_v0_8_0_scalar)); - *gs = (rustsecp256k1zkp_v0_8_0_ge*)rustsecp256k1zkp_v0_8_0_scratch_alloc(&ctx->error_callback, scratch, (g_len + h_len) * sizeof(rustsecp256k1zkp_v0_8_0_ge)); + *ns = (rustsecp256k1zkp_v0_10_0_scalar*)rustsecp256k1zkp_v0_10_0_scratch_alloc(&CTX->error_callback, scratch, g_len * sizeof(rustsecp256k1zkp_v0_10_0_scalar)); + *ls = (rustsecp256k1zkp_v0_10_0_scalar*)rustsecp256k1zkp_v0_10_0_scratch_alloc(&CTX->error_callback, scratch, h_len * sizeof(rustsecp256k1zkp_v0_10_0_scalar)); + *cs = (rustsecp256k1zkp_v0_10_0_scalar*)rustsecp256k1zkp_v0_10_0_scratch_alloc(&CTX->error_callback, scratch, h_len * sizeof(rustsecp256k1zkp_v0_10_0_scalar)); + *gs = (rustsecp256k1zkp_v0_10_0_ge*)rustsecp256k1zkp_v0_10_0_scratch_alloc(&CTX->error_callback, scratch, (g_len + h_len) * sizeof(rustsecp256k1zkp_v0_10_0_ge)); CHECK(ns != NULL && ls != NULL && cs != NULL && gs != NULL); - memcpy(*ns, n_vec, g_len * sizeof(rustsecp256k1zkp_v0_8_0_scalar)); - memcpy(*ls, l_vec, h_len * sizeof(rustsecp256k1zkp_v0_8_0_scalar)); - memcpy(*cs, c_vec, h_len * sizeof(rustsecp256k1zkp_v0_8_0_scalar)); - memcpy(*gs, gens_vec, (g_len + h_len) * sizeof(rustsecp256k1zkp_v0_8_0_ge)); + memcpy(*ns, n_vec, g_len * sizeof(rustsecp256k1zkp_v0_10_0_scalar)); + memcpy(*ls, l_vec, h_len * sizeof(rustsecp256k1zkp_v0_10_0_scalar)); + memcpy(*cs, c_vec, h_len * sizeof(rustsecp256k1zkp_v0_10_0_scalar)); + memcpy(*gs, gens_vec, (g_len + h_len) * sizeof(rustsecp256k1zkp_v0_10_0_ge)); } -/* A complete norm argument. In contrast to rustsecp256k1zkp_v0_8_0_bppp_rangeproof_norm_product_prove, this is meant - to be used as a standalone norm argument. - This is a simple wrapper around rustsecp256k1zkp_v0_8_0_bppp_rangeproof_norm_product_prove - that also commits to the initial public values used in the protocol. In this case, these public - values are commitment. -*/ -static int rustsecp256k1zkp_v0_8_0_norm_arg_prove( - rustsecp256k1zkp_v0_8_0_scratch_space* scratch, +/* Same as rustsecp256k1zkp_v0_10_0_bppp_rangeproof_norm_product_prove but does not modify the inputs */ +static int rustsecp256k1zkp_v0_10_0_bppp_rangeproof_norm_product_prove_const( + rustsecp256k1zkp_v0_10_0_scratch_space* scratch, unsigned char* proof, size_t *proof_len, - const rustsecp256k1zkp_v0_8_0_scalar* r, - const rustsecp256k1zkp_v0_8_0_bppp_generators* gens_vec, - const rustsecp256k1zkp_v0_8_0_scalar* n_vec, + rustsecp256k1zkp_v0_10_0_sha256 *transcript, + const rustsecp256k1zkp_v0_10_0_scalar* rho, + const rustsecp256k1zkp_v0_10_0_ge* g_vec, + size_t g_vec_len, + const rustsecp256k1zkp_v0_10_0_scalar* n_vec, size_t n_vec_len, - const rustsecp256k1zkp_v0_8_0_scalar* l_vec, + const rustsecp256k1zkp_v0_10_0_scalar* l_vec, size_t l_vec_len, - const rustsecp256k1zkp_v0_8_0_scalar* c_vec, - size_t c_vec_len, - const rustsecp256k1zkp_v0_8_0_ge* commit + const rustsecp256k1zkp_v0_10_0_scalar* c_vec, + size_t c_vec_len ) { - rustsecp256k1zkp_v0_8_0_scalar *ns, *ls, *cs; - rustsecp256k1zkp_v0_8_0_ge *gs, comm = *commit; + rustsecp256k1zkp_v0_10_0_scalar *ns, *ls, *cs; + rustsecp256k1zkp_v0_10_0_ge *gs; size_t scratch_checkpoint; size_t g_len = n_vec_len, h_len = l_vec_len; int res; - rustsecp256k1zkp_v0_8_0_sha256 transcript; - scratch_checkpoint = rustsecp256k1zkp_v0_8_0_scratch_checkpoint(&ctx->error_callback, scratch); - - copy_vectors_into_scratch(scratch, &ns, &ls, &cs, &gs, n_vec, l_vec, c_vec, gens_vec->gens, g_len, h_len); - - /* Commit to the initial public values */ - rustsecp256k1zkp_v0_8_0_norm_arg_commit_initial_data(&transcript, r, gens_vec, g_len, c_vec, c_vec_len, &comm); - - res = rustsecp256k1zkp_v0_8_0_bppp_rangeproof_norm_product_prove( - ctx, + scratch_checkpoint = rustsecp256k1zkp_v0_10_0_scratch_checkpoint(&CTX->error_callback, scratch); + copy_vectors_into_scratch(scratch, &ns, &ls, &cs, &gs, n_vec, l_vec, c_vec, g_vec, g_len, h_len); + res = rustsecp256k1zkp_v0_10_0_bppp_rangeproof_norm_product_prove( + CTX, scratch, proof, proof_len, - &transcript, /* Transcript hash of the parent protocol */ - r, + transcript, /* Transcript hash of the parent protocol */ + rho, gs, - gens_vec->n, + g_vec_len, ns, n_vec_len, ls, @@ -323,36 +369,62 @@ static int rustsecp256k1zkp_v0_8_0_norm_arg_prove( cs, c_vec_len ); - rustsecp256k1zkp_v0_8_0_scratch_apply_checkpoint(&ctx->error_callback, scratch, scratch_checkpoint); + rustsecp256k1zkp_v0_10_0_scratch_apply_checkpoint(&CTX->error_callback, scratch, scratch_checkpoint); return res; } +/* A complete norm argument. In contrast to rustsecp256k1zkp_v0_10_0_bppp_rangeproof_norm_product_prove, this is meant + to be used as a standalone norm argument. + This is a simple wrapper around rustsecp256k1zkp_v0_10_0_bppp_rangeproof_norm_product_prove + that also commits to the initial public values used in the protocol. In this case, these public + values are commitment. +*/ +static int rustsecp256k1zkp_v0_10_0_norm_arg_prove( + rustsecp256k1zkp_v0_10_0_scratch_space* scratch, + unsigned char* proof, + size_t *proof_len, + const rustsecp256k1zkp_v0_10_0_scalar* rho, + const rustsecp256k1zkp_v0_10_0_bppp_generators* gens_vec, + const rustsecp256k1zkp_v0_10_0_scalar* n_vec, + size_t n_vec_len, + const rustsecp256k1zkp_v0_10_0_scalar* l_vec, + size_t l_vec_len, + const rustsecp256k1zkp_v0_10_0_scalar* c_vec, + size_t c_vec_len, + const rustsecp256k1zkp_v0_10_0_ge* commit +) { + rustsecp256k1zkp_v0_10_0_sha256 transcript; + rustsecp256k1zkp_v0_10_0_norm_arg_commit_initial_data(&transcript, rho, gens_vec, n_vec_len, c_vec, c_vec_len, commit); + + return rustsecp256k1zkp_v0_10_0_bppp_rangeproof_norm_product_prove_const(scratch, proof, proof_len, &transcript, rho, gens_vec->gens, gens_vec->n, n_vec, n_vec_len, l_vec, l_vec_len, c_vec, c_vec_len); +} + /* Verify the proof */ -static int rustsecp256k1zkp_v0_8_0_norm_arg_verify( - rustsecp256k1zkp_v0_8_0_scratch_space* scratch, +static int rustsecp256k1zkp_v0_10_0_norm_arg_verify( + rustsecp256k1zkp_v0_10_0_scratch_space* scratch, const unsigned char* proof, size_t proof_len, - const rustsecp256k1zkp_v0_8_0_scalar* r, - const rustsecp256k1zkp_v0_8_0_bppp_generators* gens_vec, + const rustsecp256k1zkp_v0_10_0_scalar* rho, + const rustsecp256k1zkp_v0_10_0_bppp_generators* gens_vec, size_t g_len, - const rustsecp256k1zkp_v0_8_0_scalar* c_vec, + const rustsecp256k1zkp_v0_10_0_scalar* c_vec, size_t c_vec_len, - const rustsecp256k1zkp_v0_8_0_ge* commit + const rustsecp256k1zkp_v0_10_0_ge* commit ) { - rustsecp256k1zkp_v0_8_0_ge comm = *commit; + rustsecp256k1zkp_v0_10_0_ge comm = *commit; int res; - rustsecp256k1zkp_v0_8_0_sha256 transcript; + rustsecp256k1zkp_v0_10_0_sha256 transcript; /* Commit to the initial public values */ - rustsecp256k1zkp_v0_8_0_norm_arg_commit_initial_data(&transcript, r, gens_vec, g_len, c_vec, c_vec_len, &comm); + rustsecp256k1zkp_v0_10_0_norm_arg_commit_initial_data(&transcript, rho, gens_vec, g_len, c_vec, c_vec_len, &comm); - res = rustsecp256k1zkp_v0_8_0_bppp_rangeproof_norm_product_verify( - ctx, + res = rustsecp256k1zkp_v0_10_0_bppp_rangeproof_norm_product_verify( + CTX, scratch, proof, proof_len, &transcript, - r, + rho, gens_vec, g_len, c_vec, @@ -362,97 +434,46 @@ static int rustsecp256k1zkp_v0_8_0_norm_arg_verify( return res; } -void norm_arg_zero(void) { - rustsecp256k1zkp_v0_8_0_scalar n_vec[64], l_vec[64], c_vec[64]; - rustsecp256k1zkp_v0_8_0_scalar r, q; - rustsecp256k1zkp_v0_8_0_ge commit; - size_t i; - rustsecp256k1zkp_v0_8_0_scratch *scratch = rustsecp256k1zkp_v0_8_0_scratch_space_create(ctx, 1000*10); /* shouldn't need much */ +/* Verify |c| = 0 */ +static void norm_arg_verify_zero_len(void) { + rustsecp256k1zkp_v0_10_0_scalar n_vec[64], l_vec[64], c_vec[64]; + rustsecp256k1zkp_v0_10_0_scalar rho, mu; + rustsecp256k1zkp_v0_10_0_ge commit; + rustsecp256k1zkp_v0_10_0_scratch *scratch = rustsecp256k1zkp_v0_10_0_scratch_space_create(CTX, 1000*10); /* shouldn't need much */ unsigned char proof[1000]; - rustsecp256k1zkp_v0_8_0_sha256 transcript; + unsigned int n_vec_len = 1; + unsigned int c_vec_len = 1; + rustsecp256k1zkp_v0_10_0_bppp_generators *gs = rustsecp256k1zkp_v0_10_0_bppp_generators_create(CTX, n_vec_len + c_vec_len); + size_t plen = sizeof(proof); - random_scalar_order(&r); - rustsecp256k1zkp_v0_8_0_scalar_sqr(&q, &r); - - /* l is zero vector and n is zero vectors of length 1 each. */ - { - size_t plen = sizeof(proof); - unsigned int n_vec_len = 1; - unsigned int c_vec_len = 1; - rustsecp256k1zkp_v0_8_0_bppp_generators *gens = rustsecp256k1zkp_v0_8_0_bppp_generators_create(ctx, n_vec_len + c_vec_len); - - rustsecp256k1zkp_v0_8_0_scalar_set_int(&n_vec[0], 0); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&l_vec[0], 0); - random_scalar_order(&c_vec[0]); - - rustsecp256k1zkp_v0_8_0_sha256_initialize(&transcript); /* No challenges used in n = 1, l = 1, but we set transcript as a good practice*/ - CHECK(rustsecp256k1zkp_v0_8_0_bppp_commit(ctx, scratch, &commit, gens, n_vec, n_vec_len, l_vec, c_vec_len, c_vec, c_vec_len, &q)); - { - rustsecp256k1zkp_v0_8_0_scalar *ns, *ls, *cs; - rustsecp256k1zkp_v0_8_0_ge *gs; - size_t scratch_checkpoint = rustsecp256k1zkp_v0_8_0_scratch_checkpoint(&ctx->error_callback, scratch); - copy_vectors_into_scratch(scratch, &ns, &ls, &cs, &gs, n_vec, l_vec, c_vec, gens->gens, n_vec_len, c_vec_len); - CHECK(rustsecp256k1zkp_v0_8_0_bppp_rangeproof_norm_product_prove(ctx, scratch, proof, &plen, &transcript, &r, gs, gens->n, ns, n_vec_len, ls, c_vec_len, cs, c_vec_len)); - rustsecp256k1zkp_v0_8_0_scratch_apply_checkpoint(&ctx->error_callback, scratch, scratch_checkpoint); - } - rustsecp256k1zkp_v0_8_0_sha256_initialize(&transcript); - CHECK(rustsecp256k1zkp_v0_8_0_bppp_rangeproof_norm_product_verify(ctx, scratch, proof, plen, &transcript, &r, gens, c_vec_len, c_vec, c_vec_len, &commit)); + random_scalar_order(&rho); + rustsecp256k1zkp_v0_10_0_scalar_sqr(&mu, &rho); - rustsecp256k1zkp_v0_8_0_bppp_generators_destroy(ctx, gens); - } - - /* l is the zero vector and longer than n. This results in one of the - * internal commitments X or R to be the point at infinity. */ - { - unsigned int n_vec_len = 1; - unsigned int c_vec_len = 2; - rustsecp256k1zkp_v0_8_0_bppp_generators *gs = rustsecp256k1zkp_v0_8_0_bppp_generators_create(ctx, n_vec_len + c_vec_len); - size_t plen = sizeof(proof); - for (i = 0; i < n_vec_len; i++) { - random_scalar_order(&n_vec[i]); - } - for (i = 0; i < c_vec_len; i++) { - rustsecp256k1zkp_v0_8_0_scalar_set_int(&l_vec[i], 0); - random_scalar_order(&c_vec[i]); - } - CHECK(rustsecp256k1zkp_v0_8_0_bppp_commit(ctx, scratch, &commit, gs, n_vec, n_vec_len, l_vec, c_vec_len, c_vec, c_vec_len, &q)); - CHECK(!rustsecp256k1zkp_v0_8_0_norm_arg_prove(scratch, proof, &plen, &r, gs, n_vec, n_vec_len, l_vec, c_vec_len, c_vec, c_vec_len, &commit)); - rustsecp256k1zkp_v0_8_0_bppp_generators_destroy(ctx, gs); - } + random_scalar_order(&n_vec[0]); + random_scalar_order(&c_vec[0]); + random_scalar_order(&l_vec[0]); + CHECK(rustsecp256k1zkp_v0_10_0_bppp_commit(CTX, scratch, &commit, gs, n_vec, n_vec_len, l_vec, c_vec_len, c_vec, c_vec_len, &mu)); + CHECK(rustsecp256k1zkp_v0_10_0_norm_arg_prove(scratch, proof, &plen, &rho, gs, n_vec, n_vec_len, l_vec, c_vec_len, c_vec, c_vec_len, &commit)); + CHECK(rustsecp256k1zkp_v0_10_0_norm_arg_verify(scratch, proof, plen, &rho, gs, n_vec_len, c_vec, c_vec_len, &commit)); + CHECK(!rustsecp256k1zkp_v0_10_0_norm_arg_verify(scratch, proof, plen, &rho, gs, n_vec_len, c_vec, 0, &commit)); - /* Verify vectors of length 0 */ - { - unsigned int n_vec_len = 1; - unsigned int c_vec_len = 1; - rustsecp256k1zkp_v0_8_0_bppp_generators *gs = rustsecp256k1zkp_v0_8_0_bppp_generators_create(ctx, n_vec_len + c_vec_len); - size_t plen = sizeof(proof); - random_scalar_order(&n_vec[0]); - random_scalar_order(&c_vec[0]); - random_scalar_order(&l_vec[0]); - CHECK(rustsecp256k1zkp_v0_8_0_bppp_commit(ctx, scratch, &commit, gs, n_vec, n_vec_len, l_vec, c_vec_len, c_vec, c_vec_len, &q)); - CHECK(rustsecp256k1zkp_v0_8_0_norm_arg_prove(scratch, proof, &plen, &r, gs, n_vec, n_vec_len, l_vec, c_vec_len, c_vec, c_vec_len, &commit)); - CHECK(rustsecp256k1zkp_v0_8_0_norm_arg_verify(scratch, proof, plen, &r, gs, n_vec_len, c_vec, c_vec_len, &commit)); - CHECK(!rustsecp256k1zkp_v0_8_0_norm_arg_verify(scratch, proof, plen, &r, gs, 0, c_vec, c_vec_len, &commit)); - CHECK(!rustsecp256k1zkp_v0_8_0_norm_arg_verify(scratch, proof, plen, &r, gs, n_vec_len, c_vec, 0, &commit)); - - rustsecp256k1zkp_v0_8_0_bppp_generators_destroy(ctx, gs); - } + rustsecp256k1zkp_v0_10_0_bppp_generators_destroy(CTX, gs); - rustsecp256k1zkp_v0_8_0_scratch_space_destroy(ctx, scratch); + rustsecp256k1zkp_v0_10_0_scratch_space_destroy(CTX, scratch); } -void norm_arg_test(unsigned int n, unsigned int m) { - rustsecp256k1zkp_v0_8_0_scalar n_vec[64], l_vec[64], c_vec[64]; - rustsecp256k1zkp_v0_8_0_scalar r, q; - rustsecp256k1zkp_v0_8_0_ge commit; +static void norm_arg_test(unsigned int n, unsigned int m) { + rustsecp256k1zkp_v0_10_0_scalar n_vec[64], l_vec[64], c_vec[64]; + rustsecp256k1zkp_v0_10_0_scalar rho, mu; + rustsecp256k1zkp_v0_10_0_ge commit; size_t i, plen; int res; - rustsecp256k1zkp_v0_8_0_bppp_generators *gs = rustsecp256k1zkp_v0_8_0_bppp_generators_create(ctx, n + m); - rustsecp256k1zkp_v0_8_0_scratch *scratch = rustsecp256k1zkp_v0_8_0_scratch_space_create(ctx, 1000*1000); /* shouldn't need much */ + rustsecp256k1zkp_v0_10_0_bppp_generators *gs = rustsecp256k1zkp_v0_10_0_bppp_generators_create(CTX, n + m); + rustsecp256k1zkp_v0_10_0_scratch *scratch = rustsecp256k1zkp_v0_10_0_scratch_space_create(CTX, 1000*1000); /* shouldn't need much */ unsigned char proof[1000]; plen = 1000; - random_scalar_order(&r); - rustsecp256k1zkp_v0_8_0_scalar_sqr(&q, &r); + random_scalar_order(&rho); + rustsecp256k1zkp_v0_10_0_scalar_sqr(&mu, &rho); for (i = 0; i < n; i++) { random_scalar_order(&n_vec[i]); @@ -463,51 +484,48 @@ void norm_arg_test(unsigned int n, unsigned int m) { random_scalar_order(&c_vec[i]); } - res = rustsecp256k1zkp_v0_8_0_bppp_commit(ctx, scratch, &commit, gs, n_vec, n, l_vec, m, c_vec, m, &q); + res = rustsecp256k1zkp_v0_10_0_bppp_commit(CTX, scratch, &commit, gs, n_vec, n, l_vec, m, c_vec, m, &mu); CHECK(res == 1); - res = rustsecp256k1zkp_v0_8_0_norm_arg_prove(scratch, proof, &plen, &r, gs, n_vec, n, l_vec, m, c_vec, m, &commit); + res = rustsecp256k1zkp_v0_10_0_norm_arg_prove(scratch, proof, &plen, &rho, gs, n_vec, n, l_vec, m, c_vec, m, &commit); CHECK(res == 1); - res = rustsecp256k1zkp_v0_8_0_norm_arg_verify(scratch, proof, plen, &r, gs, n, c_vec, m, &commit); + res = rustsecp256k1zkp_v0_10_0_norm_arg_verify(scratch, proof, plen, &rho, gs, n, c_vec, m, &commit); CHECK(res == 1); /* Changing any of last two scalars should break the proof */ proof[plen - 1] ^= 1; - res = rustsecp256k1zkp_v0_8_0_norm_arg_verify(scratch, proof, plen, &r, gs, n, c_vec, m, &commit); + res = rustsecp256k1zkp_v0_10_0_norm_arg_verify(scratch, proof, plen, &rho, gs, n, c_vec, m, &commit); CHECK(res == 0); proof[plen - 1 - 32] ^= 1; - res = rustsecp256k1zkp_v0_8_0_norm_arg_verify(scratch, proof, plen, &r, gs, n, c_vec, m, &commit); + res = rustsecp256k1zkp_v0_10_0_norm_arg_verify(scratch, proof, plen, &rho, gs, n, c_vec, m, &commit); CHECK(res == 0); - rustsecp256k1zkp_v0_8_0_scratch_space_destroy(ctx, scratch); - rustsecp256k1zkp_v0_8_0_bppp_generators_destroy(ctx, gs); + rustsecp256k1zkp_v0_10_0_scratch_space_destroy(CTX, scratch); + rustsecp256k1zkp_v0_10_0_bppp_generators_destroy(CTX, gs); } /* Parses generators from points compressed as pubkeys */ -rustsecp256k1zkp_v0_8_0_bppp_generators* bppp_generators_parse_regular(const unsigned char* data, size_t data_len) { +rustsecp256k1zkp_v0_10_0_bppp_generators* bppp_generators_parse_regular(const unsigned char* data, size_t data_len) { size_t n = data_len / 33; - rustsecp256k1zkp_v0_8_0_bppp_generators* ret; - - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(data != NULL); + rustsecp256k1zkp_v0_10_0_bppp_generators* ret; if (data_len % 33 != 0) { return NULL; } - ret = (rustsecp256k1zkp_v0_8_0_bppp_generators *)checked_malloc(&ctx->error_callback, sizeof(*ret)); + ret = (rustsecp256k1zkp_v0_10_0_bppp_generators *)checked_malloc(&CTX->error_callback, sizeof(*ret)); if (ret == NULL) { return NULL; } ret->n = n; - ret->gens = (rustsecp256k1zkp_v0_8_0_ge*)checked_malloc(&ctx->error_callback, n * sizeof(*ret->gens)); + ret->gens = (rustsecp256k1zkp_v0_10_0_ge*)checked_malloc(&CTX->error_callback, n * sizeof(*ret->gens)); if (ret->gens == NULL) { free(ret); return NULL; } while (n--) { - if (!rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(&ret->gens[n], &data[33 * n], 33)) { + if (!rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(&ret->gens[n], &data[33 * n], 33)) { free(ret->gens); free(ret); return NULL; @@ -516,36 +534,36 @@ rustsecp256k1zkp_v0_8_0_bppp_generators* bppp_generators_parse_regular(const uns return ret; } -int norm_arg_verify_vectors_helper(rustsecp256k1zkp_v0_8_0_scratch *scratch, const unsigned char *gens, const unsigned char *proof, size_t plen, const unsigned char *r32, size_t n_vec_len, const unsigned char c_vec32[][32], rustsecp256k1zkp_v0_8_0_scalar *c_vec, size_t c_vec_len, const unsigned char *commit33) { - rustsecp256k1zkp_v0_8_0_sha256 transcript; - rustsecp256k1zkp_v0_8_0_bppp_generators *gs = bppp_generators_parse_regular(gens, 33*(n_vec_len + c_vec_len)); - rustsecp256k1zkp_v0_8_0_scalar r; - rustsecp256k1zkp_v0_8_0_ge commit; +int norm_arg_verify_vectors_helper(rustsecp256k1zkp_v0_10_0_scratch *scratch, const unsigned char *gens, const unsigned char *proof, size_t plen, const unsigned char *r32, size_t n_vec_len, const unsigned char c_vec32[][32], rustsecp256k1zkp_v0_10_0_scalar *c_vec, size_t c_vec_len, const unsigned char *commit33) { + rustsecp256k1zkp_v0_10_0_sha256 transcript; + rustsecp256k1zkp_v0_10_0_bppp_generators *gs = bppp_generators_parse_regular(gens, 33*(n_vec_len + c_vec_len)); + rustsecp256k1zkp_v0_10_0_scalar rho; + rustsecp256k1zkp_v0_10_0_ge commit; int overflow; int i; int ret; CHECK(gs != NULL); - rustsecp256k1zkp_v0_8_0_sha256_initialize(&transcript); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&transcript); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&r, r32, &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&rho, r32, &overflow); CHECK(!overflow); for (i = 0; i < (int)c_vec_len; i++) { - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&c_vec[i], c_vec32[i], &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&c_vec[i], c_vec32[i], &overflow); CHECK(!overflow); } - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(&commit, commit33, 33)); - ret = rustsecp256k1zkp_v0_8_0_bppp_rangeproof_norm_product_verify(ctx, scratch, proof, plen, &transcript, &r, gs, n_vec_len, c_vec, c_vec_len, &commit); + CHECK(rustsecp256k1zkp_v0_10_0_ge_parse_ext(&commit, commit33)); + ret = rustsecp256k1zkp_v0_10_0_bppp_rangeproof_norm_product_verify(CTX, scratch, proof, plen, &transcript, &rho, gs, n_vec_len, c_vec, c_vec_len, &commit); - rustsecp256k1zkp_v0_8_0_bppp_generators_destroy(ctx, gs); + rustsecp256k1zkp_v0_10_0_bppp_generators_destroy(CTX, gs); return ret; } -#define IDX_TO_TEST(i) (norm_arg_verify_vectors_helper(scratch, verify_vector_gens, verify_vector_##i##_proof, sizeof(verify_vector_##i##_proof), verify_vector_##i##_r32, verify_vector_##i##_n_vec_len, verify_vector_##i##_c_vec32, verify_vector_##i##_c_vec, sizeof(verify_vector_##i##_c_vec)/sizeof(rustsecp256k1zkp_v0_8_0_scalar), verify_vector_##i##_commit33) == verify_vector_##i##_result) +#define IDX_TO_TEST(i) (norm_arg_verify_vectors_helper(scratch, verify_vector_gens, verify_vector_##i##_proof, sizeof(verify_vector_##i##_proof), verify_vector_##i##_r32, verify_vector_##i##_n_vec_len, verify_vector_##i##_c_vec32, verify_vector_##i##_c_vec, sizeof(verify_vector_##i##_c_vec)/sizeof(rustsecp256k1zkp_v0_10_0_scalar), verify_vector_##i##_commit33) == verify_vector_##i##_result) -void norm_arg_verify_vectors(void) { - rustsecp256k1zkp_v0_8_0_scratch *scratch = rustsecp256k1zkp_v0_8_0_scratch_space_create(ctx, 1000*1000); /* shouldn't need much */ +static void norm_arg_verify_vectors(void) { + rustsecp256k1zkp_v0_10_0_scratch *scratch = rustsecp256k1zkp_v0_10_0_scratch_space_create(CTX, 1000*1000); /* shouldn't need much */ size_t alloc = scratch->alloc_size; CHECK(IDX_TO_TEST(0)); @@ -557,20 +575,89 @@ void norm_arg_verify_vectors(void) { CHECK(IDX_TO_TEST(6)); CHECK(IDX_TO_TEST(7)); CHECK(IDX_TO_TEST(8)); + CHECK(IDX_TO_TEST(9)); + CHECK(IDX_TO_TEST(10)); + CHECK(IDX_TO_TEST(11)); + CHECK(IDX_TO_TEST(12)); CHECK(alloc == scratch->alloc_size); - rustsecp256k1zkp_v0_8_0_scratch_space_destroy(ctx, scratch); + rustsecp256k1zkp_v0_10_0_scratch_space_destroy(CTX, scratch); } #undef IDX_TO_TEST -void run_bppp_tests(void) { +static void norm_arg_prove_vectors_helper(rustsecp256k1zkp_v0_10_0_scratch *scratch, const unsigned char *gens, const unsigned char *proof, size_t plen, const unsigned char *r32, const unsigned char n_vec32[][32], rustsecp256k1zkp_v0_10_0_scalar *n_vec, size_t n_vec_len, const unsigned char l_vec32[][32], rustsecp256k1zkp_v0_10_0_scalar *l_vec, const unsigned char c_vec32[][32], rustsecp256k1zkp_v0_10_0_scalar *c_vec, size_t c_vec_len, int result) { + rustsecp256k1zkp_v0_10_0_sha256 transcript; + rustsecp256k1zkp_v0_10_0_bppp_generators *gs = bppp_generators_parse_regular(gens, 33*(n_vec_len + c_vec_len)); + rustsecp256k1zkp_v0_10_0_scalar rho, mu; + rustsecp256k1zkp_v0_10_0_ge commit; + unsigned char myproof[1024]; + size_t myplen = sizeof(myproof); + int overflow; + int i; + + CHECK(gs != NULL); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&transcript); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&rho, r32, &overflow); + CHECK(!overflow); + rustsecp256k1zkp_v0_10_0_scalar_sqr(&mu, &rho); + + for (i = 0; i < (int)n_vec_len; i++) { + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&n_vec[i], n_vec32[i], &overflow); + CHECK(!overflow); + } + for (i = 0; i < (int)c_vec_len; i++) { + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&l_vec[i], l_vec32[i], &overflow); + CHECK(!overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&c_vec[i], c_vec32[i], &overflow); + CHECK(!overflow); + } + + CHECK(rustsecp256k1zkp_v0_10_0_bppp_rangeproof_norm_product_prove_const(scratch, myproof, &myplen, &transcript, &rho, gs->gens, gs->n, n_vec, n_vec_len, l_vec, c_vec_len, c_vec, c_vec_len) == result); + if (!result) { + rustsecp256k1zkp_v0_10_0_bppp_generators_destroy(CTX, gs); + return; + } + CHECK(plen == myplen); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(proof, myproof, plen) == 0); + + CHECK(rustsecp256k1zkp_v0_10_0_bppp_commit(CTX, scratch, &commit, gs, n_vec, n_vec_len, l_vec, c_vec_len, c_vec, c_vec_len, &mu)); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&transcript); + CHECK(rustsecp256k1zkp_v0_10_0_bppp_rangeproof_norm_product_verify(CTX, scratch, proof, plen, &transcript, &rho, gs, n_vec_len, c_vec, c_vec_len, &commit)); + rustsecp256k1zkp_v0_10_0_bppp_generators_destroy(CTX, gs); +} + + +#define IDX_TO_TEST(i) (norm_arg_prove_vectors_helper(scratch, prove_vector_gens, prove_vector_##i##_proof, sizeof(prove_vector_##i##_proof), prove_vector_##i##_r32,\ + prove_vector_##i##_n_vec32, prove_vector_##i##_n_vec, sizeof(prove_vector_##i##_n_vec)/sizeof(rustsecp256k1zkp_v0_10_0_scalar),\ + prove_vector_##i##_l_vec32, prove_vector_##i##_l_vec,\ + prove_vector_##i##_c_vec32, prove_vector_##i##_c_vec, sizeof(prove_vector_##i##_c_vec)/sizeof(rustsecp256k1zkp_v0_10_0_scalar), \ + prove_vector_##i##_result)) + +static void norm_arg_prove_vectors(void) { + rustsecp256k1zkp_v0_10_0_scratch *scratch = rustsecp256k1zkp_v0_10_0_scratch_space_create(CTX, 1000*1000); /* shouldn't need much */ + size_t alloc = scratch->alloc_size; + + IDX_TO_TEST(0); + IDX_TO_TEST(1); + IDX_TO_TEST(2); + IDX_TO_TEST(3); + IDX_TO_TEST(4); + + CHECK(alloc == scratch->alloc_size); + rustsecp256k1zkp_v0_10_0_scratch_space_destroy(CTX, scratch); +} + +#undef IDX_TO_TEST + +static void run_bppp_tests(void) { test_log_exp(); test_norm_util_helpers(); + test_serialize_two_points(); test_bppp_generators_api(); test_bppp_generators_fixed(); test_bppp_tagged_hash(); - norm_arg_zero(); + norm_arg_verify_zero_len(); norm_arg_test(1, 1); norm_arg_test(1, 64); norm_arg_test(64, 1); @@ -578,7 +665,9 @@ void run_bppp_tests(void) { norm_arg_test(32, 64); norm_arg_test(64, 32); norm_arg_test(64, 64); + norm_arg_verify_vectors(); + norm_arg_prove_vectors(); } #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdh/Makefile.am.include b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdh/Makefile.am.include index 34d3c738..331299aa 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdh/Makefile.am.include +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdh/Makefile.am.include @@ -1,4 +1,4 @@ -include_HEADERS += include/rustsecp256k1zkp_v0_8_0_ecdh.h +include_HEADERS += include/rustsecp256k1zkp_v0_10_0_ecdh.h noinst_HEADERS += src/modules/ecdh/main_impl.h noinst_HEADERS += src/modules/ecdh/tests_impl.h noinst_HEADERS += src/modules/ecdh/bench_impl.h diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdh/bench_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdh/bench_impl.h index ab552c35..e7e8e56e 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdh/bench_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdh/bench_impl.h @@ -7,11 +7,11 @@ #ifndef SECP256K1_MODULE_ECDH_BENCH_H #define SECP256K1_MODULE_ECDH_BENCH_H -#include "../include/secp256k1_ecdh.h" +#include "../../../include/secp256k1_ecdh.h" typedef struct { - rustsecp256k1zkp_v0_8_0_context *ctx; - rustsecp256k1zkp_v0_8_0_pubkey point; + rustsecp256k1zkp_v0_10_0_context *ctx; + rustsecp256k1zkp_v0_10_0_pubkey point; unsigned char scalar[32]; } bench_ecdh_data; @@ -29,7 +29,7 @@ static void bench_ecdh_setup(void* arg) { for (i = 0; i < 32; i++) { data->scalar[i] = i + 1; } - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(data->ctx, &data->point, point, sizeof(point)) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(data->ctx, &data->point, point, sizeof(point)) == 1); } static void bench_ecdh(void* arg, int iters) { @@ -38,20 +38,20 @@ static void bench_ecdh(void* arg, int iters) { bench_ecdh_data *data = (bench_ecdh_data*)arg; for (i = 0; i < iters; i++) { - CHECK(rustsecp256k1zkp_v0_8_0_ecdh(data->ctx, res, &data->point, data->scalar, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdh(data->ctx, res, &data->point, data->scalar, NULL, NULL) == 1); } } -void run_ecdh_bench(int iters, int argc, char** argv) { +static void run_ecdh_bench(int iters, int argc, char** argv) { bench_ecdh_data data; int d = argc == 1; /* create a context with no capabilities */ - data.ctx = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_FLAGS_TYPE_CONTEXT); + data.ctx = rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_FLAGS_TYPE_CONTEXT); if (d || have_flag(argc, argv, "ecdh")) run_benchmark("ecdh", bench_ecdh, bench_ecdh_setup, NULL, &data, 10, iters); - rustsecp256k1zkp_v0_8_0_context_destroy(data.ctx); + rustsecp256k1zkp_v0_10_0_context_destroy(data.ctx); } #endif /* SECP256K1_MODULE_ECDH_BENCH_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdh/main_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdh/main_impl.h index ebee763f..46130a30 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdh/main_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdh/main_impl.h @@ -12,26 +12,26 @@ static int ecdh_hash_function_sha256(unsigned char *output, const unsigned char *x32, const unsigned char *y32, void *data) { unsigned char version = (y32[31] & 0x01) | 0x02; - rustsecp256k1zkp_v0_8_0_sha256 sha; + rustsecp256k1zkp_v0_10_0_sha256 sha; (void)data; - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, &version, 1); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, x32, 32); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, output); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, &version, 1); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, x32, 32); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, output); return 1; } -const rustsecp256k1zkp_v0_8_0_ecdh_hash_function rustsecp256k1zkp_v0_8_0_ecdh_hash_function_sha256 = ecdh_hash_function_sha256; -const rustsecp256k1zkp_v0_8_0_ecdh_hash_function rustsecp256k1zkp_v0_8_0_ecdh_hash_function_default = ecdh_hash_function_sha256; +const rustsecp256k1zkp_v0_10_0_ecdh_hash_function rustsecp256k1zkp_v0_10_0_ecdh_hash_function_sha256 = ecdh_hash_function_sha256; +const rustsecp256k1zkp_v0_10_0_ecdh_hash_function rustsecp256k1zkp_v0_10_0_ecdh_hash_function_default = ecdh_hash_function_sha256; -int rustsecp256k1zkp_v0_8_0_ecdh(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *output, const rustsecp256k1zkp_v0_8_0_pubkey *point, const unsigned char *scalar, rustsecp256k1zkp_v0_8_0_ecdh_hash_function hashfp, void *data) { +int rustsecp256k1zkp_v0_10_0_ecdh(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *output, const rustsecp256k1zkp_v0_10_0_pubkey *point, const unsigned char *scalar, rustsecp256k1zkp_v0_10_0_ecdh_hash_function hashfp, void *data) { int ret = 0; int overflow = 0; - rustsecp256k1zkp_v0_8_0_gej res; - rustsecp256k1zkp_v0_8_0_ge pt; - rustsecp256k1zkp_v0_8_0_scalar s; + rustsecp256k1zkp_v0_10_0_gej res; + rustsecp256k1zkp_v0_10_0_ge pt; + rustsecp256k1zkp_v0_10_0_scalar s; unsigned char x[32]; unsigned char y[32]; @@ -41,29 +41,29 @@ int rustsecp256k1zkp_v0_8_0_ecdh(const rustsecp256k1zkp_v0_8_0_context* ctx, uns ARG_CHECK(scalar != NULL); if (hashfp == NULL) { - hashfp = rustsecp256k1zkp_v0_8_0_ecdh_hash_function_default; + hashfp = rustsecp256k1zkp_v0_10_0_ecdh_hash_function_default; } - rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &pt, point); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&s, scalar, &overflow); + rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, &pt, point); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&s, scalar, &overflow); - overflow |= rustsecp256k1zkp_v0_8_0_scalar_is_zero(&s); - rustsecp256k1zkp_v0_8_0_scalar_cmov(&s, &rustsecp256k1zkp_v0_8_0_scalar_one, overflow); + overflow |= rustsecp256k1zkp_v0_10_0_scalar_is_zero(&s); + rustsecp256k1zkp_v0_10_0_scalar_cmov(&s, &rustsecp256k1zkp_v0_10_0_scalar_one, overflow); - rustsecp256k1zkp_v0_8_0_ecmult_const(&res, &pt, &s, 256); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&pt, &res); + rustsecp256k1zkp_v0_10_0_ecmult_const(&res, &pt, &s); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&pt, &res); /* Compute a hash of the point */ - rustsecp256k1zkp_v0_8_0_fe_normalize(&pt.x); - rustsecp256k1zkp_v0_8_0_fe_normalize(&pt.y); - rustsecp256k1zkp_v0_8_0_fe_get_b32(x, &pt.x); - rustsecp256k1zkp_v0_8_0_fe_get_b32(y, &pt.y); + rustsecp256k1zkp_v0_10_0_fe_normalize(&pt.x); + rustsecp256k1zkp_v0_10_0_fe_normalize(&pt.y); + rustsecp256k1zkp_v0_10_0_fe_get_b32(x, &pt.x); + rustsecp256k1zkp_v0_10_0_fe_get_b32(y, &pt.y); ret = hashfp(output, x, y, data); memset(x, 0, 32); memset(y, 0, 32); - rustsecp256k1zkp_v0_8_0_scalar_clear(&s); + rustsecp256k1zkp_v0_10_0_scalar_clear(&s); return !!ret & !overflow; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdh/tests_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdh/tests_impl.h index 75f8ebae..b44fb2e6 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdh/tests_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdh/tests_impl.h @@ -7,7 +7,7 @@ #ifndef SECP256K1_MODULE_ECDH_TESTS_H #define SECP256K1_MODULE_ECDH_TESTS_H -int ecdh_hash_function_test_fail(unsigned char *output, const unsigned char *x, const unsigned char *y, void *data) { +static int ecdh_hash_function_test_fail(unsigned char *output, const unsigned char *x, const unsigned char *y, void *data) { (void)output; (void)x; (void)y; @@ -15,7 +15,7 @@ int ecdh_hash_function_test_fail(unsigned char *output, const unsigned char *x, return 0; } -int ecdh_hash_function_custom(unsigned char *output, const unsigned char *x, const unsigned char *y, void *data) { +static int ecdh_hash_function_custom(unsigned char *output, const unsigned char *x, const unsigned char *y, void *data) { (void)data; /* Save x and y as uncompressed public key */ output[0] = 0x04; @@ -24,77 +24,64 @@ int ecdh_hash_function_custom(unsigned char *output, const unsigned char *x, con return 1; } -void test_ecdh_api(void) { - /* Setup context that just counts errors */ - rustsecp256k1zkp_v0_8_0_context *tctx = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN); - rustsecp256k1zkp_v0_8_0_pubkey point; +static void test_ecdh_api(void) { + rustsecp256k1zkp_v0_10_0_pubkey point; unsigned char res[32]; unsigned char s_one[32] = { 0 }; - int32_t ecount = 0; s_one[31] = 1; - rustsecp256k1zkp_v0_8_0_context_set_error_callback(tctx, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(tctx, counting_illegal_callback_fn, &ecount); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(tctx, &point, s_one) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &point, s_one) == 1); /* Check all NULLs are detected */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdh(tctx, res, &point, s_one, NULL, NULL) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdh(tctx, NULL, &point, s_one, NULL, NULL) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdh(tctx, res, NULL, s_one, NULL, NULL) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ecdh(tctx, res, &point, NULL, NULL, NULL) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_ecdh(tctx, res, &point, s_one, NULL, NULL) == 1); - CHECK(ecount == 3); - - /* Cleanup */ - rustsecp256k1zkp_v0_8_0_context_destroy(tctx); + CHECK(rustsecp256k1zkp_v0_10_0_ecdh(CTX, res, &point, s_one, NULL, NULL) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdh(CTX, NULL, &point, s_one, NULL, NULL)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdh(CTX, res, NULL, s_one, NULL, NULL)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdh(CTX, res, &point, NULL, NULL, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdh(CTX, res, &point, s_one, NULL, NULL) == 1); } -void test_ecdh_generator_basepoint(void) { +static void test_ecdh_generator_basepoint(void) { unsigned char s_one[32] = { 0 }; - rustsecp256k1zkp_v0_8_0_pubkey point[2]; + rustsecp256k1zkp_v0_10_0_pubkey point[2]; int i; s_one[31] = 1; /* Check against pubkey creation when the basepoint is the generator */ - for (i = 0; i < 2 * count; ++i) { - rustsecp256k1zkp_v0_8_0_sha256 sha; + for (i = 0; i < 2 * COUNT; ++i) { + rustsecp256k1zkp_v0_10_0_sha256 sha; unsigned char s_b32[32]; unsigned char output_ecdh[65]; unsigned char output_ser[32]; unsigned char point_ser[65]; size_t point_ser_len = sizeof(point_ser); - rustsecp256k1zkp_v0_8_0_scalar s; + rustsecp256k1zkp_v0_10_0_scalar s; random_scalar_order(&s); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(s_b32, &s); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(s_b32, &s); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &point[0], s_one) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &point[1], s_b32) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &point[0], s_one) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &point[1], s_b32) == 1); /* compute using ECDH function with custom hash function */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdh(ctx, output_ecdh, &point[0], s_b32, ecdh_hash_function_custom, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdh(CTX, output_ecdh, &point[0], s_b32, ecdh_hash_function_custom, NULL) == 1); /* compute "explicitly" */ - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, point_ser, &point_ser_len, &point[1], SECP256K1_EC_UNCOMPRESSED) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(CTX, point_ser, &point_ser_len, &point[1], SECP256K1_EC_UNCOMPRESSED) == 1); /* compare */ - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(output_ecdh, point_ser, 65) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(output_ecdh, point_ser, 65) == 0); /* compute using ECDH function with default hash function */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdh(ctx, output_ecdh, &point[0], s_b32, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdh(CTX, output_ecdh, &point[0], s_b32, NULL, NULL) == 1); /* compute "explicitly" */ - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, point_ser, &point_ser_len, &point[1], SECP256K1_EC_COMPRESSED) == 1); - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, point_ser, point_ser_len); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, output_ser); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(CTX, point_ser, &point_ser_len, &point[1], SECP256K1_EC_COMPRESSED) == 1); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, point_ser, point_ser_len); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, output_ser); /* compare */ - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(output_ecdh, output_ser, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(output_ecdh, output_ser, 32) == 0); } } -void test_bad_scalar(void) { +static void test_bad_scalar(void) { unsigned char s_zero[32] = { 0 }; unsigned char s_overflow[32] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, @@ -104,29 +91,29 @@ void test_bad_scalar(void) { }; unsigned char s_rand[32] = { 0 }; unsigned char output[32]; - rustsecp256k1zkp_v0_8_0_scalar rand; - rustsecp256k1zkp_v0_8_0_pubkey point; + rustsecp256k1zkp_v0_10_0_scalar rand; + rustsecp256k1zkp_v0_10_0_pubkey point; /* Create random point */ random_scalar_order(&rand); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(s_rand, &rand); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &point, s_rand) == 1); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(s_rand, &rand); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &point, s_rand) == 1); /* Try to multiply it by bad values */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdh(ctx, output, &point, s_zero, NULL, NULL) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdh(ctx, output, &point, s_overflow, NULL, NULL) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdh(CTX, output, &point, s_zero, NULL, NULL) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdh(CTX, output, &point, s_overflow, NULL, NULL) == 0); /* ...and a good one */ s_overflow[31] -= 1; - CHECK(rustsecp256k1zkp_v0_8_0_ecdh(ctx, output, &point, s_overflow, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdh(CTX, output, &point, s_overflow, NULL, NULL) == 1); /* Hash function failure results in ecdh failure */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdh(ctx, output, &point, s_overflow, ecdh_hash_function_test_fail, NULL) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdh(CTX, output, &point, s_overflow, ecdh_hash_function_test_fail, NULL) == 0); } /** Test that ECDH(sG, 1/s) == ECDH((1/s)G, s) == ECDH(G, 1) for a few random s. */ -void test_result_basepoint(void) { - rustsecp256k1zkp_v0_8_0_pubkey point; - rustsecp256k1zkp_v0_8_0_scalar rand; +static void test_result_basepoint(void) { + rustsecp256k1zkp_v0_10_0_pubkey point; + rustsecp256k1zkp_v0_10_0_scalar rand; unsigned char s[32]; unsigned char s_inv[32]; unsigned char out[32]; @@ -136,26 +123,26 @@ void test_result_basepoint(void) { unsigned char s_one[32] = { 0 }; s_one[31] = 1; - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &point, s_one) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdh(ctx, out_base, &point, s_one, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &point, s_one) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdh(CTX, out_base, &point, s_one, NULL, NULL) == 1); - for (i = 0; i < 2 * count; i++) { + for (i = 0; i < 2 * COUNT; i++) { random_scalar_order(&rand); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(s, &rand); - rustsecp256k1zkp_v0_8_0_scalar_inverse(&rand, &rand); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(s_inv, &rand); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(s, &rand); + rustsecp256k1zkp_v0_10_0_scalar_inverse(&rand, &rand); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(s_inv, &rand); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &point, s) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdh(ctx, out, &point, s_inv, NULL, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(out, out_base, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &point, s) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdh(CTX, out, &point, s_inv, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(out, out_base, 32) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &point, s_inv) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdh(ctx, out_inv, &point, s, NULL, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(out_inv, out_base, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &point, s_inv) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdh(CTX, out_inv, &point, s, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(out_inv, out_base, 32) == 0); } } -void run_ecdh_tests(void) { +static void run_ecdh_tests(void) { test_ecdh_api(); test_ecdh_generator_basepoint(); test_bad_scalar(); diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_adaptor/Makefile.am.include b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_adaptor/Makefile.am.include index cbdacc21..94487ee6 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_adaptor/Makefile.am.include +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_adaptor/Makefile.am.include @@ -1,4 +1,4 @@ -include_HEADERS += include/rustsecp256k1zkp_v0_8_0_ecdsa_adaptor.h +include_HEADERS += include/rustsecp256k1zkp_v0_10_0_ecdsa_adaptor.h noinst_HEADERS += src/modules/ecdsa_adaptor/main_impl.h noinst_HEADERS += src/modules/ecdsa_adaptor/dleq_impl.h noinst_HEADERS += src/modules/ecdsa_adaptor/tests_impl.h diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_adaptor/dleq_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_adaptor/dleq_impl.h index 222207f9..68f4da37 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_adaptor/dleq_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_adaptor/dleq_impl.h @@ -3,8 +3,8 @@ /* Initializes SHA256 with fixed midstate. This midstate was computed by applying * SHA256 to SHA256("DLEQ")||SHA256("DLEQ"). */ -static void rustsecp256k1zkp_v0_8_0_nonce_function_dleq_sha256_tagged(rustsecp256k1zkp_v0_8_0_sha256 *sha) { - rustsecp256k1zkp_v0_8_0_sha256_initialize(sha); +static void rustsecp256k1zkp_v0_10_0_nonce_function_dleq_sha256_tagged(rustsecp256k1zkp_v0_10_0_sha256 *sha) { + rustsecp256k1zkp_v0_10_0_sha256_initialize(sha); sha->s[0] = 0x8cc4beacul; sha->s[1] = 0x2e011f3ful; sha->s[2] = 0x355c75fbul; @@ -20,38 +20,38 @@ static void rustsecp256k1zkp_v0_8_0_nonce_function_dleq_sha256_tagged(rustsecp25 /* algo argument for nonce_function_ecdsa_adaptor to derive the nonce using a tagged hash function. */ static const unsigned char dleq_algo[4] = "DLEQ"; -static int rustsecp256k1zkp_v0_8_0_dleq_hash_point(rustsecp256k1zkp_v0_8_0_sha256 *sha, rustsecp256k1zkp_v0_8_0_ge *p) { +static int rustsecp256k1zkp_v0_10_0_dleq_hash_point(rustsecp256k1zkp_v0_10_0_sha256 *sha, rustsecp256k1zkp_v0_10_0_ge *p) { unsigned char buf[33]; size_t size = 33; - if (!rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(p, buf, &size, 1)) { + if (!rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(p, buf, &size, 1)) { return 0; } - rustsecp256k1zkp_v0_8_0_sha256_write(sha, buf, size); + rustsecp256k1zkp_v0_10_0_sha256_write(sha, buf, size); return 1; } -static int rustsecp256k1zkp_v0_8_0_dleq_nonce(rustsecp256k1zkp_v0_8_0_scalar *k, const unsigned char *sk32, const unsigned char *gen2_33, const unsigned char *p1_33, const unsigned char *p2_33, rustsecp256k1zkp_v0_8_0_nonce_function_hardened_ecdsa_adaptor noncefp, void *ndata) { - rustsecp256k1zkp_v0_8_0_sha256 sha; +static int rustsecp256k1zkp_v0_10_0_dleq_nonce(rustsecp256k1zkp_v0_10_0_scalar *k, const unsigned char *sk32, const unsigned char *gen2_33, const unsigned char *p1_33, const unsigned char *p2_33, rustsecp256k1zkp_v0_10_0_nonce_function_hardened_ecdsa_adaptor noncefp, void *ndata) { + rustsecp256k1zkp_v0_10_0_sha256 sha; unsigned char buf[32]; unsigned char nonce[32]; size_t size = 33; if (noncefp == NULL) { - noncefp = rustsecp256k1zkp_v0_8_0_nonce_function_ecdsa_adaptor; + noncefp = rustsecp256k1zkp_v0_10_0_nonce_function_ecdsa_adaptor; } - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, p1_33, size); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, p2_33, size); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, buf); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, p1_33, size); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, p2_33, size); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, buf); if (!noncefp(nonce, buf, sk32, gen2_33, dleq_algo, sizeof(dleq_algo), ndata)) { return 0; } - rustsecp256k1zkp_v0_8_0_scalar_set_b32(k, nonce, NULL); - if (rustsecp256k1zkp_v0_8_0_scalar_is_zero(k)) { + rustsecp256k1zkp_v0_10_0_scalar_set_b32(k, nonce, NULL); + if (rustsecp256k1zkp_v0_10_0_scalar_is_zero(k)) { return 0; } @@ -60,36 +60,36 @@ static int rustsecp256k1zkp_v0_8_0_dleq_nonce(rustsecp256k1zkp_v0_8_0_scalar *k, /* Generates a challenge as defined in the DLC Specification at * https://github.com/discreetlogcontracts/dlcspecs */ -static void rustsecp256k1zkp_v0_8_0_dleq_challenge(rustsecp256k1zkp_v0_8_0_scalar *e, rustsecp256k1zkp_v0_8_0_ge *gen2, rustsecp256k1zkp_v0_8_0_ge *r1, rustsecp256k1zkp_v0_8_0_ge *r2, rustsecp256k1zkp_v0_8_0_ge *p1, rustsecp256k1zkp_v0_8_0_ge *p2) { +static void rustsecp256k1zkp_v0_10_0_dleq_challenge(rustsecp256k1zkp_v0_10_0_scalar *e, rustsecp256k1zkp_v0_10_0_ge *gen2, rustsecp256k1zkp_v0_10_0_ge *r1, rustsecp256k1zkp_v0_10_0_ge *r2, rustsecp256k1zkp_v0_10_0_ge *p1, rustsecp256k1zkp_v0_10_0_ge *p2) { unsigned char buf[32]; - rustsecp256k1zkp_v0_8_0_sha256 sha; + rustsecp256k1zkp_v0_10_0_sha256 sha; - rustsecp256k1zkp_v0_8_0_nonce_function_dleq_sha256_tagged(&sha); - rustsecp256k1zkp_v0_8_0_dleq_hash_point(&sha, p1); - rustsecp256k1zkp_v0_8_0_dleq_hash_point(&sha, gen2); - rustsecp256k1zkp_v0_8_0_dleq_hash_point(&sha, p2); - rustsecp256k1zkp_v0_8_0_dleq_hash_point(&sha, r1); - rustsecp256k1zkp_v0_8_0_dleq_hash_point(&sha, r2); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, buf); + rustsecp256k1zkp_v0_10_0_nonce_function_dleq_sha256_tagged(&sha); + rustsecp256k1zkp_v0_10_0_dleq_hash_point(&sha, p1); + rustsecp256k1zkp_v0_10_0_dleq_hash_point(&sha, gen2); + rustsecp256k1zkp_v0_10_0_dleq_hash_point(&sha, p2); + rustsecp256k1zkp_v0_10_0_dleq_hash_point(&sha, r1); + rustsecp256k1zkp_v0_10_0_dleq_hash_point(&sha, r2); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, buf); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(e, buf, NULL); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(e, buf, NULL); } /* P1 = x*G, P2 = x*Y */ -static void rustsecp256k1zkp_v0_8_0_dleq_pair(const rustsecp256k1zkp_v0_8_0_ecmult_gen_context *ecmult_gen_ctx, rustsecp256k1zkp_v0_8_0_ge *p1, rustsecp256k1zkp_v0_8_0_ge *p2, const rustsecp256k1zkp_v0_8_0_scalar *sk, const rustsecp256k1zkp_v0_8_0_ge *gen2) { - rustsecp256k1zkp_v0_8_0_gej p1j, p2j; +static void rustsecp256k1zkp_v0_10_0_dleq_pair(const rustsecp256k1zkp_v0_10_0_ecmult_gen_context *ecmult_gen_ctx, rustsecp256k1zkp_v0_10_0_ge *p1, rustsecp256k1zkp_v0_10_0_ge *p2, const rustsecp256k1zkp_v0_10_0_scalar *sk, const rustsecp256k1zkp_v0_10_0_ge *gen2) { + rustsecp256k1zkp_v0_10_0_gej p1j, p2j; - rustsecp256k1zkp_v0_8_0_ecmult_gen(ecmult_gen_ctx, &p1j, sk); - rustsecp256k1zkp_v0_8_0_ge_set_gej(p1, &p1j); - rustsecp256k1zkp_v0_8_0_ecmult_const(&p2j, gen2, sk, 256); - rustsecp256k1zkp_v0_8_0_ge_set_gej(p2, &p2j); + rustsecp256k1zkp_v0_10_0_ecmult_gen(ecmult_gen_ctx, &p1j, sk); + rustsecp256k1zkp_v0_10_0_ge_set_gej(p1, &p1j); + rustsecp256k1zkp_v0_10_0_ecmult_const(&p2j, gen2, sk); + rustsecp256k1zkp_v0_10_0_ge_set_gej(p2, &p2j); } /* Generates a proof that the discrete logarithm of P1 to the secp256k1 base G is the * same as the discrete logarithm of P2 to the base Y */ -static int rustsecp256k1zkp_v0_8_0_dleq_prove(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_scalar *s, rustsecp256k1zkp_v0_8_0_scalar *e, const rustsecp256k1zkp_v0_8_0_scalar *sk, rustsecp256k1zkp_v0_8_0_ge *gen2, rustsecp256k1zkp_v0_8_0_ge *p1, rustsecp256k1zkp_v0_8_0_ge *p2, rustsecp256k1zkp_v0_8_0_nonce_function_hardened_ecdsa_adaptor noncefp, void *ndata) { - rustsecp256k1zkp_v0_8_0_ge r1, r2; - rustsecp256k1zkp_v0_8_0_scalar k = { 0 }; +static int rustsecp256k1zkp_v0_10_0_dleq_prove(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_scalar *s, rustsecp256k1zkp_v0_10_0_scalar *e, const rustsecp256k1zkp_v0_10_0_scalar *sk, rustsecp256k1zkp_v0_10_0_ge *gen2, rustsecp256k1zkp_v0_10_0_ge *p1, rustsecp256k1zkp_v0_10_0_ge *p2, rustsecp256k1zkp_v0_10_0_nonce_function_hardened_ecdsa_adaptor noncefp, void *ndata) { + rustsecp256k1zkp_v0_10_0_ge r1, r2; + rustsecp256k1zkp_v0_10_0_scalar k = { 0 }; unsigned char sk32[32]; unsigned char gen2_33[33]; unsigned char p1_33[33]; @@ -97,62 +97,62 @@ static int rustsecp256k1zkp_v0_8_0_dleq_prove(const rustsecp256k1zkp_v0_8_0_cont int ret = 1; size_t pubkey_size = 33; - rustsecp256k1zkp_v0_8_0_scalar_get_b32(sk32, sk); - if (!rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(gen2, gen2_33, &pubkey_size, 1)) { + rustsecp256k1zkp_v0_10_0_scalar_get_b32(sk32, sk); + if (!rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(gen2, gen2_33, &pubkey_size, 1)) { return 0; } - if (!rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(p1, p1_33, &pubkey_size, 1)) { + if (!rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(p1, p1_33, &pubkey_size, 1)) { return 0; } - if (!rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(p2, p2_33, &pubkey_size, 1)) { + if (!rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(p2, p2_33, &pubkey_size, 1)) { return 0; } - ret &= rustsecp256k1zkp_v0_8_0_dleq_nonce(&k, sk32, gen2_33, p1_33, p2_33, noncefp, ndata); + ret &= rustsecp256k1zkp_v0_10_0_dleq_nonce(&k, sk32, gen2_33, p1_33, p2_33, noncefp, ndata); /* R1 = k*G, R2 = k*Y */ - rustsecp256k1zkp_v0_8_0_dleq_pair(&ctx->ecmult_gen_ctx, &r1, &r2, &k, gen2); + rustsecp256k1zkp_v0_10_0_dleq_pair(&ctx->ecmult_gen_ctx, &r1, &r2, &k, gen2); /* We declassify the non-secret values r1 and r2 to allow using them as * branch points. */ - rustsecp256k1zkp_v0_8_0_declassify(ctx, &r1, sizeof(r1)); - rustsecp256k1zkp_v0_8_0_declassify(ctx, &r2, sizeof(r2)); + rustsecp256k1zkp_v0_10_0_declassify(ctx, &r1, sizeof(r1)); + rustsecp256k1zkp_v0_10_0_declassify(ctx, &r2, sizeof(r2)); /* e = tagged hash(p1, gen2, p2, r1, r2) */ /* s = k + e * sk */ - rustsecp256k1zkp_v0_8_0_dleq_challenge(e, gen2, &r1, &r2, p1, p2); - rustsecp256k1zkp_v0_8_0_scalar_mul(s, e, sk); - rustsecp256k1zkp_v0_8_0_scalar_add(s, s, &k); + rustsecp256k1zkp_v0_10_0_dleq_challenge(e, gen2, &r1, &r2, p1, p2); + rustsecp256k1zkp_v0_10_0_scalar_mul(s, e, sk); + rustsecp256k1zkp_v0_10_0_scalar_add(s, s, &k); - rustsecp256k1zkp_v0_8_0_scalar_clear(&k); + rustsecp256k1zkp_v0_10_0_scalar_clear(&k); return ret; } -static int rustsecp256k1zkp_v0_8_0_dleq_verify(const rustsecp256k1zkp_v0_8_0_scalar *s, const rustsecp256k1zkp_v0_8_0_scalar *e, rustsecp256k1zkp_v0_8_0_ge *p1, rustsecp256k1zkp_v0_8_0_ge *gen2, rustsecp256k1zkp_v0_8_0_ge *p2) { - rustsecp256k1zkp_v0_8_0_scalar e_neg; - rustsecp256k1zkp_v0_8_0_scalar e_expected; - rustsecp256k1zkp_v0_8_0_gej gen2j; - rustsecp256k1zkp_v0_8_0_gej p1j, p2j; - rustsecp256k1zkp_v0_8_0_gej r1j, r2j; - rustsecp256k1zkp_v0_8_0_ge r1, r2; - rustsecp256k1zkp_v0_8_0_gej tmpj; +static int rustsecp256k1zkp_v0_10_0_dleq_verify(const rustsecp256k1zkp_v0_10_0_scalar *s, const rustsecp256k1zkp_v0_10_0_scalar *e, rustsecp256k1zkp_v0_10_0_ge *p1, rustsecp256k1zkp_v0_10_0_ge *gen2, rustsecp256k1zkp_v0_10_0_ge *p2) { + rustsecp256k1zkp_v0_10_0_scalar e_neg; + rustsecp256k1zkp_v0_10_0_scalar e_expected; + rustsecp256k1zkp_v0_10_0_gej gen2j; + rustsecp256k1zkp_v0_10_0_gej p1j, p2j; + rustsecp256k1zkp_v0_10_0_gej r1j, r2j; + rustsecp256k1zkp_v0_10_0_ge r1, r2; + rustsecp256k1zkp_v0_10_0_gej tmpj; - rustsecp256k1zkp_v0_8_0_gej_set_ge(&p1j, p1); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&p2j, p2); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&p1j, p1); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&p2j, p2); - rustsecp256k1zkp_v0_8_0_scalar_negate(&e_neg, e); + rustsecp256k1zkp_v0_10_0_scalar_negate(&e_neg, e); /* R1 = s*G - e*P1 */ - rustsecp256k1zkp_v0_8_0_ecmult(&r1j, &p1j, &e_neg, s); + rustsecp256k1zkp_v0_10_0_ecmult(&r1j, &p1j, &e_neg, s); /* R2 = s*gen2 - e*P2 */ - rustsecp256k1zkp_v0_8_0_ecmult(&tmpj, &p2j, &e_neg, &rustsecp256k1zkp_v0_8_0_scalar_zero); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&gen2j, gen2); - rustsecp256k1zkp_v0_8_0_ecmult(&r2j, &gen2j, s, &rustsecp256k1zkp_v0_8_0_scalar_zero); - rustsecp256k1zkp_v0_8_0_gej_add_var(&r2j, &r2j, &tmpj, NULL); + rustsecp256k1zkp_v0_10_0_ecmult(&tmpj, &p2j, &e_neg, &rustsecp256k1zkp_v0_10_0_scalar_zero); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&gen2j, gen2); + rustsecp256k1zkp_v0_10_0_ecmult(&r2j, &gen2j, s, &rustsecp256k1zkp_v0_10_0_scalar_zero); + rustsecp256k1zkp_v0_10_0_gej_add_var(&r2j, &r2j, &tmpj, NULL); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&r1, &r1j); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&r2, &r2j); - rustsecp256k1zkp_v0_8_0_dleq_challenge(&e_expected, gen2, &r1, &r2, p1, p2); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&r1, &r1j); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&r2, &r2j); + rustsecp256k1zkp_v0_10_0_dleq_challenge(&e_expected, gen2, &r1, &r2, p1, p2); - rustsecp256k1zkp_v0_8_0_scalar_add(&e_expected, &e_expected, &e_neg); - return rustsecp256k1zkp_v0_8_0_scalar_is_zero(&e_expected); + rustsecp256k1zkp_v0_10_0_scalar_add(&e_expected, &e_expected, &e_neg); + return rustsecp256k1zkp_v0_10_0_scalar_is_zero(&e_expected); } #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_adaptor/main_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_adaptor/main_impl.h index 177d9e5c..0d78393a 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_adaptor/main_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_adaptor/main_impl.h @@ -11,53 +11,53 @@ #include "dleq_impl.h" /* (R, R', s', dleq_proof) */ -static int rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_serialize(unsigned char *adaptor_sig162, rustsecp256k1zkp_v0_8_0_ge *r, rustsecp256k1zkp_v0_8_0_ge *rp, const rustsecp256k1zkp_v0_8_0_scalar *sp, const rustsecp256k1zkp_v0_8_0_scalar *dleq_proof_e, const rustsecp256k1zkp_v0_8_0_scalar *dleq_proof_s) { +static int rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_serialize(unsigned char *adaptor_sig162, rustsecp256k1zkp_v0_10_0_ge *r, rustsecp256k1zkp_v0_10_0_ge *rp, const rustsecp256k1zkp_v0_10_0_scalar *sp, const rustsecp256k1zkp_v0_10_0_scalar *dleq_proof_e, const rustsecp256k1zkp_v0_10_0_scalar *dleq_proof_s) { size_t size = 33; - if (!rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(r, adaptor_sig162, &size, 1)) { + if (!rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(r, adaptor_sig162, &size, 1)) { return 0; } - if (!rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(rp, &adaptor_sig162[33], &size, 1)) { + if (!rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(rp, &adaptor_sig162[33], &size, 1)) { return 0; } - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&adaptor_sig162[66], sp); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&adaptor_sig162[98], dleq_proof_e); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&adaptor_sig162[130], dleq_proof_s); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&adaptor_sig162[66], sp); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&adaptor_sig162[98], dleq_proof_e); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&adaptor_sig162[130], dleq_proof_s); return 1; } -static int rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(rustsecp256k1zkp_v0_8_0_ge *r, rustsecp256k1zkp_v0_8_0_scalar *sigr, rustsecp256k1zkp_v0_8_0_ge *rp, rustsecp256k1zkp_v0_8_0_scalar *sp, rustsecp256k1zkp_v0_8_0_scalar *dleq_proof_e, rustsecp256k1zkp_v0_8_0_scalar *dleq_proof_s, const unsigned char *adaptor_sig162) { +static int rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(rustsecp256k1zkp_v0_10_0_ge *r, rustsecp256k1zkp_v0_10_0_scalar *sigr, rustsecp256k1zkp_v0_10_0_ge *rp, rustsecp256k1zkp_v0_10_0_scalar *sp, rustsecp256k1zkp_v0_10_0_scalar *dleq_proof_e, rustsecp256k1zkp_v0_10_0_scalar *dleq_proof_s, const unsigned char *adaptor_sig162) { /* If r is deserialized, require that a sigr is provided to receive * the X-coordinate */ VERIFY_CHECK((r == NULL) || (r != NULL && sigr != NULL)); if (r != NULL) { - if (!rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(r, &adaptor_sig162[0], 33)) { + if (!rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(r, &adaptor_sig162[0], 33)) { return 0; } } if (sigr != NULL) { - rustsecp256k1zkp_v0_8_0_scalar_set_b32(sigr, &adaptor_sig162[1], NULL); - if (rustsecp256k1zkp_v0_8_0_scalar_is_zero(sigr)) { + rustsecp256k1zkp_v0_10_0_scalar_set_b32(sigr, &adaptor_sig162[1], NULL); + if (rustsecp256k1zkp_v0_10_0_scalar_is_zero(sigr)) { return 0; } } if (rp != NULL) { - if (!rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(rp, &adaptor_sig162[33], 33)) { + if (!rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(rp, &adaptor_sig162[33], 33)) { return 0; } } if (sp != NULL) { - if (!rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(sp, &adaptor_sig162[66])) { + if (!rustsecp256k1zkp_v0_10_0_scalar_set_b32_seckey(sp, &adaptor_sig162[66])) { return 0; } } if (dleq_proof_e != NULL) { - rustsecp256k1zkp_v0_8_0_scalar_set_b32(dleq_proof_e, &adaptor_sig162[98], NULL); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(dleq_proof_e, &adaptor_sig162[98], NULL); } if (dleq_proof_s != NULL) { int overflow; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(dleq_proof_s, &adaptor_sig162[130], &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(dleq_proof_s, &adaptor_sig162[130], &overflow); if (overflow) { return 0; } @@ -67,8 +67,8 @@ static int rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(rustsecp256k1zk /* Initializes SHA256 with fixed midstate. This midstate was computed by applying * SHA256 to SHA256("ECDSAadaptor/non")||SHA256("ECDSAadaptor/non"). */ -static void rustsecp256k1zkp_v0_8_0_nonce_function_ecdsa_adaptor_sha256_tagged(rustsecp256k1zkp_v0_8_0_sha256 *sha) { - rustsecp256k1zkp_v0_8_0_sha256_initialize(sha); +static void rustsecp256k1zkp_v0_10_0_nonce_function_ecdsa_adaptor_sha256_tagged(rustsecp256k1zkp_v0_10_0_sha256 *sha) { + rustsecp256k1zkp_v0_10_0_sha256_initialize(sha); sha->s[0] = 0x791dae43ul; sha->s[1] = 0xe52d3b44ul; sha->s[2] = 0x37f9edeaul; @@ -83,8 +83,8 @@ static void rustsecp256k1zkp_v0_8_0_nonce_function_ecdsa_adaptor_sha256_tagged(r /* Initializes SHA256 with fixed midstate. This midstate was computed by applying * SHA256 to SHA256("ECDSAadaptor/aux")||SHA256("ECDSAadaptor/aux"). */ -static void rustsecp256k1zkp_v0_8_0_nonce_function_ecdsa_adaptor_sha256_tagged_aux(rustsecp256k1zkp_v0_8_0_sha256 *sha) { - rustsecp256k1zkp_v0_8_0_sha256_initialize(sha); +static void rustsecp256k1zkp_v0_10_0_nonce_function_ecdsa_adaptor_sha256_tagged_aux(rustsecp256k1zkp_v0_10_0_sha256 *sha) { + rustsecp256k1zkp_v0_10_0_sha256_initialize(sha); sha->s[0] = 0xd14c7bd9ul; sha->s[1] = 0x095d35e6ul; sha->s[2] = 0xb8490a88ul; @@ -102,7 +102,7 @@ static const unsigned char ecdsa_adaptor_algo[16] = "ECDSAadaptor/non"; /* Modified BIP-340 nonce function */ static int nonce_function_ecdsa_adaptor(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *pk33, const unsigned char *algo, size_t algolen, void *data) { - rustsecp256k1zkp_v0_8_0_sha256 sha; + rustsecp256k1zkp_v0_10_0_sha256 sha; unsigned char masked_key[32]; int i; @@ -111,9 +111,9 @@ static int nonce_function_ecdsa_adaptor(unsigned char *nonce32, const unsigned c } if (data != NULL) { - rustsecp256k1zkp_v0_8_0_nonce_function_ecdsa_adaptor_sha256_tagged_aux(&sha); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, data, 32); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, masked_key); + rustsecp256k1zkp_v0_10_0_nonce_function_ecdsa_adaptor_sha256_tagged_aux(&sha); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, data, 32); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, masked_key); for (i = 0; i < 32; i++) { masked_key[i] ^= key32[i]; } @@ -123,117 +123,117 @@ static int nonce_function_ecdsa_adaptor(unsigned char *nonce32, const unsigned c * algorithims. An optimized tagging implementation is used if the default * tag is provided. */ if (algolen == sizeof(ecdsa_adaptor_algo) - && rustsecp256k1zkp_v0_8_0_memcmp_var(algo, ecdsa_adaptor_algo, algolen) == 0) { - rustsecp256k1zkp_v0_8_0_nonce_function_ecdsa_adaptor_sha256_tagged(&sha); + && rustsecp256k1zkp_v0_10_0_memcmp_var(algo, ecdsa_adaptor_algo, algolen) == 0) { + rustsecp256k1zkp_v0_10_0_nonce_function_ecdsa_adaptor_sha256_tagged(&sha); } else if (algolen == sizeof(dleq_algo) - && rustsecp256k1zkp_v0_8_0_memcmp_var(algo, dleq_algo, algolen) == 0) { - rustsecp256k1zkp_v0_8_0_nonce_function_dleq_sha256_tagged(&sha); + && rustsecp256k1zkp_v0_10_0_memcmp_var(algo, dleq_algo, algolen) == 0) { + rustsecp256k1zkp_v0_10_0_nonce_function_dleq_sha256_tagged(&sha); } else { - rustsecp256k1zkp_v0_8_0_sha256_initialize_tagged(&sha, algo, algolen); + rustsecp256k1zkp_v0_10_0_sha256_initialize_tagged(&sha, algo, algolen); } /* Hash (masked-)key||pk||msg using the tagged hash as per BIP-340 */ if (data != NULL) { - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, masked_key, 32); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, masked_key, 32); } else { - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, key32, 32); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, key32, 32); } - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, pk33, 33); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, msg32, 32); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, nonce32); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, pk33, 33); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, msg32, 32); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, nonce32); return 1; } -const rustsecp256k1zkp_v0_8_0_nonce_function_hardened_ecdsa_adaptor rustsecp256k1zkp_v0_8_0_nonce_function_ecdsa_adaptor = nonce_function_ecdsa_adaptor; - -int rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *adaptor_sig162, unsigned char *seckey32, const rustsecp256k1zkp_v0_8_0_pubkey *enckey, const unsigned char *msg32, rustsecp256k1zkp_v0_8_0_nonce_function_hardened_ecdsa_adaptor noncefp, void *ndata) { - rustsecp256k1zkp_v0_8_0_scalar k; - rustsecp256k1zkp_v0_8_0_gej rj, rpj; - rustsecp256k1zkp_v0_8_0_ge r, rp; - rustsecp256k1zkp_v0_8_0_ge enckey_ge; - rustsecp256k1zkp_v0_8_0_scalar dleq_proof_s; - rustsecp256k1zkp_v0_8_0_scalar dleq_proof_e; - rustsecp256k1zkp_v0_8_0_scalar sk; - rustsecp256k1zkp_v0_8_0_scalar msg; - rustsecp256k1zkp_v0_8_0_scalar sp; - rustsecp256k1zkp_v0_8_0_scalar sigr; - rustsecp256k1zkp_v0_8_0_scalar n; +const rustsecp256k1zkp_v0_10_0_nonce_function_hardened_ecdsa_adaptor rustsecp256k1zkp_v0_10_0_nonce_function_ecdsa_adaptor = nonce_function_ecdsa_adaptor; + +int rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_encrypt(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *adaptor_sig162, unsigned char *seckey32, const rustsecp256k1zkp_v0_10_0_pubkey *enckey, const unsigned char *msg32, rustsecp256k1zkp_v0_10_0_nonce_function_hardened_ecdsa_adaptor noncefp, void *ndata) { + rustsecp256k1zkp_v0_10_0_scalar k; + rustsecp256k1zkp_v0_10_0_gej rj, rpj; + rustsecp256k1zkp_v0_10_0_ge r, rp; + rustsecp256k1zkp_v0_10_0_ge enckey_ge; + rustsecp256k1zkp_v0_10_0_scalar dleq_proof_s; + rustsecp256k1zkp_v0_10_0_scalar dleq_proof_e; + rustsecp256k1zkp_v0_10_0_scalar sk; + rustsecp256k1zkp_v0_10_0_scalar msg; + rustsecp256k1zkp_v0_10_0_scalar sp; + rustsecp256k1zkp_v0_10_0_scalar sigr; + rustsecp256k1zkp_v0_10_0_scalar n; unsigned char nonce32[32] = { 0 }; unsigned char buf33[33]; size_t size = 33; int ret = 1; VERIFY_CHECK(ctx != NULL); - ARG_CHECK(rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); ARG_CHECK(adaptor_sig162 != NULL); ARG_CHECK(seckey32 != NULL); ARG_CHECK(enckey != NULL); ARG_CHECK(msg32 != NULL); - rustsecp256k1zkp_v0_8_0_scalar_clear(&dleq_proof_e); - rustsecp256k1zkp_v0_8_0_scalar_clear(&dleq_proof_s); + rustsecp256k1zkp_v0_10_0_scalar_clear(&dleq_proof_e); + rustsecp256k1zkp_v0_10_0_scalar_clear(&dleq_proof_s); if (noncefp == NULL) { - noncefp = rustsecp256k1zkp_v0_8_0_nonce_function_ecdsa_adaptor; + noncefp = rustsecp256k1zkp_v0_10_0_nonce_function_ecdsa_adaptor; } - ret &= rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &enckey_ge, enckey); - ret &= rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&enckey_ge, buf33, &size, 1); + ret &= rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, &enckey_ge, enckey); + ret &= rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&enckey_ge, buf33, &size, 1); ret &= !!noncefp(nonce32, msg32, seckey32, buf33, ecdsa_adaptor_algo, sizeof(ecdsa_adaptor_algo), ndata); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&k, nonce32, NULL); - ret &= !rustsecp256k1zkp_v0_8_0_scalar_is_zero(&k); - rustsecp256k1zkp_v0_8_0_scalar_cmov(&k, &rustsecp256k1zkp_v0_8_0_scalar_one, !ret); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&k, nonce32, NULL); + ret &= !rustsecp256k1zkp_v0_10_0_scalar_is_zero(&k); + rustsecp256k1zkp_v0_10_0_scalar_cmov(&k, &rustsecp256k1zkp_v0_10_0_scalar_one, !ret); /* R' := k*G */ - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &rpj, &k); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&rp, &rpj); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&ctx->ecmult_gen_ctx, &rpj, &k); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&rp, &rpj); /* R = k*Y; */ - rustsecp256k1zkp_v0_8_0_ecmult_const(&rj, &enckey_ge, &k, 256); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&r, &rj); + rustsecp256k1zkp_v0_10_0_ecmult_const(&rj, &enckey_ge, &k); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&r, &rj); /* We declassify the non-secret values rp and r to allow using them * as branch points. */ - rustsecp256k1zkp_v0_8_0_declassify(ctx, &rp, sizeof(rp)); - rustsecp256k1zkp_v0_8_0_declassify(ctx, &r, sizeof(r)); + rustsecp256k1zkp_v0_10_0_declassify(ctx, &rp, sizeof(rp)); + rustsecp256k1zkp_v0_10_0_declassify(ctx, &r, sizeof(r)); /* dleq_proof = DLEQ_prove(k, (R', Y, R)) */ - ret &= rustsecp256k1zkp_v0_8_0_dleq_prove(ctx, &dleq_proof_s, &dleq_proof_e, &k, &enckey_ge, &rp, &r, noncefp, ndata); - - ret &= rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(&sk, seckey32); - rustsecp256k1zkp_v0_8_0_scalar_cmov(&sk, &rustsecp256k1zkp_v0_8_0_scalar_one, !ret); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&msg, msg32, NULL); - rustsecp256k1zkp_v0_8_0_fe_normalize(&r.x); - rustsecp256k1zkp_v0_8_0_fe_get_b32(buf33, &r.x); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&sigr, buf33, NULL); - ret &= !rustsecp256k1zkp_v0_8_0_scalar_is_zero(&sigr); + ret &= rustsecp256k1zkp_v0_10_0_dleq_prove(ctx, &dleq_proof_s, &dleq_proof_e, &k, &enckey_ge, &rp, &r, noncefp, ndata); + + ret &= rustsecp256k1zkp_v0_10_0_scalar_set_b32_seckey(&sk, seckey32); + rustsecp256k1zkp_v0_10_0_scalar_cmov(&sk, &rustsecp256k1zkp_v0_10_0_scalar_one, !ret); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&msg, msg32, NULL); + rustsecp256k1zkp_v0_10_0_fe_normalize(&r.x); + rustsecp256k1zkp_v0_10_0_fe_get_b32(buf33, &r.x); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&sigr, buf33, NULL); + ret &= !rustsecp256k1zkp_v0_10_0_scalar_is_zero(&sigr); /* s' = k⁻¹(m + R.x * x) */ - rustsecp256k1zkp_v0_8_0_scalar_mul(&n, &sigr, &sk); - rustsecp256k1zkp_v0_8_0_scalar_add(&n, &n, &msg); - rustsecp256k1zkp_v0_8_0_scalar_inverse(&sp, &k); - rustsecp256k1zkp_v0_8_0_scalar_mul(&sp, &sp, &n); - ret &= !rustsecp256k1zkp_v0_8_0_scalar_is_zero(&sp); + rustsecp256k1zkp_v0_10_0_scalar_mul(&n, &sigr, &sk); + rustsecp256k1zkp_v0_10_0_scalar_add(&n, &n, &msg); + rustsecp256k1zkp_v0_10_0_scalar_inverse(&sp, &k); + rustsecp256k1zkp_v0_10_0_scalar_mul(&sp, &sp, &n); + ret &= !rustsecp256k1zkp_v0_10_0_scalar_is_zero(&sp); /* return (R, R', s', dleq_proof) */ - ret &= rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_serialize(adaptor_sig162, &r, &rp, &sp, &dleq_proof_e, &dleq_proof_s); + ret &= rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_serialize(adaptor_sig162, &r, &rp, &sp, &dleq_proof_e, &dleq_proof_s); - rustsecp256k1zkp_v0_8_0_memczero(adaptor_sig162, 162, !ret); - rustsecp256k1zkp_v0_8_0_scalar_clear(&n); - rustsecp256k1zkp_v0_8_0_scalar_clear(&k); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sk); + rustsecp256k1zkp_v0_10_0_memczero(adaptor_sig162, 162, !ret); + rustsecp256k1zkp_v0_10_0_scalar_clear(&n); + rustsecp256k1zkp_v0_10_0_scalar_clear(&k); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sk); return ret; } -int rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(const rustsecp256k1zkp_v0_8_0_context* ctx, const unsigned char *adaptor_sig162, const rustsecp256k1zkp_v0_8_0_pubkey *pubkey, const unsigned char *msg32, const rustsecp256k1zkp_v0_8_0_pubkey *enckey) { - rustsecp256k1zkp_v0_8_0_scalar dleq_proof_s, dleq_proof_e; - rustsecp256k1zkp_v0_8_0_scalar msg; - rustsecp256k1zkp_v0_8_0_ge pubkey_ge; - rustsecp256k1zkp_v0_8_0_ge r, rp; - rustsecp256k1zkp_v0_8_0_scalar sp; - rustsecp256k1zkp_v0_8_0_scalar sigr; - rustsecp256k1zkp_v0_8_0_ge enckey_ge; - rustsecp256k1zkp_v0_8_0_gej derived_rp; - rustsecp256k1zkp_v0_8_0_scalar sn, u1, u2; - rustsecp256k1zkp_v0_8_0_gej pubkeyj; +int rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_verify(const rustsecp256k1zkp_v0_10_0_context* ctx, const unsigned char *adaptor_sig162, const rustsecp256k1zkp_v0_10_0_pubkey *pubkey, const unsigned char *msg32, const rustsecp256k1zkp_v0_10_0_pubkey *enckey) { + rustsecp256k1zkp_v0_10_0_scalar dleq_proof_s, dleq_proof_e; + rustsecp256k1zkp_v0_10_0_scalar msg; + rustsecp256k1zkp_v0_10_0_ge pubkey_ge; + rustsecp256k1zkp_v0_10_0_ge r, rp; + rustsecp256k1zkp_v0_10_0_scalar sp; + rustsecp256k1zkp_v0_10_0_scalar sigr; + rustsecp256k1zkp_v0_10_0_ge enckey_ge; + rustsecp256k1zkp_v0_10_0_gej derived_rp; + rustsecp256k1zkp_v0_10_0_scalar sn, u1, u2; + rustsecp256k1zkp_v0_10_0_gej pubkeyj; VERIFY_CHECK(ctx != NULL); ARG_CHECK(adaptor_sig162 != NULL); @@ -241,40 +241,40 @@ int rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(const rustsecp256k1zkp_v0_8_0_c ARG_CHECK(msg32 != NULL); ARG_CHECK(enckey != NULL); - if (!rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(&r, &sigr, &rp, &sp, &dleq_proof_e, &dleq_proof_s, adaptor_sig162)) { + if (!rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(&r, &sigr, &rp, &sp, &dleq_proof_e, &dleq_proof_s, adaptor_sig162)) { return 0; } - if (!rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &enckey_ge, enckey)) { + if (!rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, &enckey_ge, enckey)) { return 0; } /* DLEQ_verify((R', Y, R), dleq_proof) */ - if(!rustsecp256k1zkp_v0_8_0_dleq_verify(&dleq_proof_s, &dleq_proof_e, &rp, &enckey_ge, &r)) { + if(!rustsecp256k1zkp_v0_10_0_dleq_verify(&dleq_proof_s, &dleq_proof_e, &rp, &enckey_ge, &r)) { return 0; } - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&msg, msg32, NULL); - if (!rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &pubkey_ge, pubkey)) { + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&msg, msg32, NULL); + if (!rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, &pubkey_ge, pubkey)) { return 0; } /* return R' == s'⁻¹(m * G + R.x * X) */ - rustsecp256k1zkp_v0_8_0_scalar_inverse_var(&sn, &sp); - rustsecp256k1zkp_v0_8_0_scalar_mul(&u1, &sn, &msg); - rustsecp256k1zkp_v0_8_0_scalar_mul(&u2, &sn, &sigr); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&pubkeyj, &pubkey_ge); - rustsecp256k1zkp_v0_8_0_ecmult(&derived_rp, &pubkeyj, &u2, &u1); - if (rustsecp256k1zkp_v0_8_0_gej_is_infinity(&derived_rp)) { + rustsecp256k1zkp_v0_10_0_scalar_inverse_var(&sn, &sp); + rustsecp256k1zkp_v0_10_0_scalar_mul(&u1, &sn, &msg); + rustsecp256k1zkp_v0_10_0_scalar_mul(&u2, &sn, &sigr); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&pubkeyj, &pubkey_ge); + rustsecp256k1zkp_v0_10_0_ecmult(&derived_rp, &pubkeyj, &u2, &u1); + if (rustsecp256k1zkp_v0_10_0_gej_is_infinity(&derived_rp)) { return 0; } - rustsecp256k1zkp_v0_8_0_gej_neg(&derived_rp, &derived_rp); - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&derived_rp, &derived_rp, &rp, NULL); - return rustsecp256k1zkp_v0_8_0_gej_is_infinity(&derived_rp); + rustsecp256k1zkp_v0_10_0_gej_neg(&derived_rp, &derived_rp); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&derived_rp, &derived_rp, &rp, NULL); + return rustsecp256k1zkp_v0_10_0_gej_is_infinity(&derived_rp); } -int rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_decrypt(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ecdsa_signature *sig, const unsigned char *deckey32, const unsigned char *adaptor_sig162) { - rustsecp256k1zkp_v0_8_0_scalar deckey; - rustsecp256k1zkp_v0_8_0_scalar sp; - rustsecp256k1zkp_v0_8_0_scalar s; - rustsecp256k1zkp_v0_8_0_scalar sigr; +int rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_decrypt(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_ecdsa_signature *sig, const unsigned char *deckey32, const unsigned char *adaptor_sig162) { + rustsecp256k1zkp_v0_10_0_scalar deckey; + rustsecp256k1zkp_v0_10_0_scalar sp; + rustsecp256k1zkp_v0_10_0_scalar s; + rustsecp256k1zkp_v0_10_0_scalar sigr; int overflow; int high; int ret = 1; @@ -284,62 +284,62 @@ int rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_decrypt(const rustsecp256k1zkp_v0_8_0_ ARG_CHECK(deckey32 != NULL); ARG_CHECK(adaptor_sig162 != NULL); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sp); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&deckey, deckey32, &overflow); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sp); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&deckey, deckey32, &overflow); ret &= !overflow; - ret &= rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(NULL, &sigr, NULL, &sp, NULL, NULL, adaptor_sig162); - ret &= !rustsecp256k1zkp_v0_8_0_scalar_is_zero(&deckey); - rustsecp256k1zkp_v0_8_0_scalar_inverse(&s, &deckey); + ret &= rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(NULL, &sigr, NULL, &sp, NULL, NULL, adaptor_sig162); + ret &= !rustsecp256k1zkp_v0_10_0_scalar_is_zero(&deckey); + rustsecp256k1zkp_v0_10_0_scalar_inverse(&s, &deckey); /* s = s' * y⁻¹ */ - rustsecp256k1zkp_v0_8_0_scalar_mul(&s, &s, &sp); - high = rustsecp256k1zkp_v0_8_0_scalar_is_high(&s); - rustsecp256k1zkp_v0_8_0_scalar_cond_negate(&s, high); - rustsecp256k1zkp_v0_8_0_ecdsa_signature_save(sig, &sigr, &s); + rustsecp256k1zkp_v0_10_0_scalar_mul(&s, &s, &sp); + high = rustsecp256k1zkp_v0_10_0_scalar_is_high(&s); + rustsecp256k1zkp_v0_10_0_scalar_cond_negate(&s, high); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_save(sig, &sigr, &s); - rustsecp256k1zkp_v0_8_0_memczero(&sig->data[0], 64, !ret); - rustsecp256k1zkp_v0_8_0_scalar_clear(&deckey); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sp); - rustsecp256k1zkp_v0_8_0_scalar_clear(&s); + rustsecp256k1zkp_v0_10_0_memczero(&sig->data[0], 64, !ret); + rustsecp256k1zkp_v0_10_0_scalar_clear(&deckey); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sp); + rustsecp256k1zkp_v0_10_0_scalar_clear(&s); return ret; } -int rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_recover(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *deckey32, const rustsecp256k1zkp_v0_8_0_ecdsa_signature *sig, const unsigned char *adaptor_sig162, const rustsecp256k1zkp_v0_8_0_pubkey *enckey) { - rustsecp256k1zkp_v0_8_0_scalar sp, adaptor_sigr; - rustsecp256k1zkp_v0_8_0_scalar s, r; - rustsecp256k1zkp_v0_8_0_scalar deckey; - rustsecp256k1zkp_v0_8_0_ge enckey_expected_ge; - rustsecp256k1zkp_v0_8_0_gej enckey_expected_gej; +int rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_recover(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *deckey32, const rustsecp256k1zkp_v0_10_0_ecdsa_signature *sig, const unsigned char *adaptor_sig162, const rustsecp256k1zkp_v0_10_0_pubkey *enckey) { + rustsecp256k1zkp_v0_10_0_scalar sp, adaptor_sigr; + rustsecp256k1zkp_v0_10_0_scalar s, r; + rustsecp256k1zkp_v0_10_0_scalar deckey; + rustsecp256k1zkp_v0_10_0_ge enckey_expected_ge; + rustsecp256k1zkp_v0_10_0_gej enckey_expected_gej; unsigned char enckey33[33]; unsigned char enckey_expected33[33]; size_t size = 33; int ret = 1; VERIFY_CHECK(ctx != NULL); - ARG_CHECK(rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); ARG_CHECK(deckey32 != NULL); ARG_CHECK(sig != NULL); ARG_CHECK(adaptor_sig162 != NULL); ARG_CHECK(enckey != NULL); - if (!rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(NULL, &adaptor_sigr, NULL, &sp, NULL, NULL, adaptor_sig162)) { + if (!rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(NULL, &adaptor_sigr, NULL, &sp, NULL, NULL, adaptor_sig162)) { return 0; } - rustsecp256k1zkp_v0_8_0_ecdsa_signature_load(ctx, &r, &s, sig); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_load(ctx, &r, &s, sig); /* Check that we're not looking at some unrelated signature */ - ret &= rustsecp256k1zkp_v0_8_0_scalar_eq(&adaptor_sigr, &r); + ret &= rustsecp256k1zkp_v0_10_0_scalar_eq(&adaptor_sigr, &r); /* y = s⁻¹ * s' */ - ret &= !rustsecp256k1zkp_v0_8_0_scalar_is_zero(&s); - rustsecp256k1zkp_v0_8_0_scalar_inverse(&deckey, &s); - rustsecp256k1zkp_v0_8_0_scalar_mul(&deckey, &deckey, &sp); + ret &= !rustsecp256k1zkp_v0_10_0_scalar_is_zero(&s); + rustsecp256k1zkp_v0_10_0_scalar_inverse(&deckey, &s); + rustsecp256k1zkp_v0_10_0_scalar_mul(&deckey, &deckey, &sp); /* Deal with ECDSA malleability */ - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &enckey_expected_gej, &deckey); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&enckey_expected_ge, &enckey_expected_gej); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&ctx->ecmult_gen_ctx, &enckey_expected_gej, &deckey); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&enckey_expected_ge, &enckey_expected_gej); /* We declassify non-secret enckey_expected_ge to allow using it as a * branch point. */ - rustsecp256k1zkp_v0_8_0_declassify(ctx, &enckey_expected_ge, sizeof(enckey_expected_ge)); - if (!rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&enckey_expected_ge, enckey_expected33, &size, SECP256K1_EC_COMPRESSED)) { + rustsecp256k1zkp_v0_10_0_declassify(ctx, &enckey_expected_ge, sizeof(enckey_expected_ge)); + if (!rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&enckey_expected_ge, enckey_expected33, &size, SECP256K1_EC_COMPRESSED)) { /* Unreachable from tests (and other VERIFY builds) and therefore this * branch should be ignored in test coverage analysis. * @@ -353,21 +353,21 @@ int rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_recover(const rustsecp256k1zkp_v0_8_0_ */ return 0; } - if (!rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, enckey33, &size, enckey, SECP256K1_EC_COMPRESSED)) { + if (!rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(ctx, enckey33, &size, enckey, SECP256K1_EC_COMPRESSED)) { return 0; } - if (rustsecp256k1zkp_v0_8_0_memcmp_var(&enckey_expected33[1], &enckey33[1], 32) != 0) { + if (rustsecp256k1zkp_v0_10_0_memcmp_var(&enckey_expected33[1], &enckey33[1], 32) != 0) { return 0; } if (enckey_expected33[0] != enckey33[0]) { /* try Y_implied == -Y */ - rustsecp256k1zkp_v0_8_0_scalar_negate(&deckey, &deckey); + rustsecp256k1zkp_v0_10_0_scalar_negate(&deckey, &deckey); } - rustsecp256k1zkp_v0_8_0_scalar_get_b32(deckey32, &deckey); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(deckey32, &deckey); - rustsecp256k1zkp_v0_8_0_scalar_clear(&deckey); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sp); - rustsecp256k1zkp_v0_8_0_scalar_clear(&s); + rustsecp256k1zkp_v0_10_0_scalar_clear(&deckey); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sp); + rustsecp256k1zkp_v0_10_0_scalar_clear(&s); return ret; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_adaptor/tests_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_adaptor/tests_impl.h index 21a842fd..83595dee 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_adaptor/tests_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_adaptor/tests_impl.h @@ -3,33 +3,33 @@ #include "../../../include/secp256k1_ecdsa_adaptor.h" -void rand_scalar(rustsecp256k1zkp_v0_8_0_scalar *scalar) { +static void rand_scalar(rustsecp256k1zkp_v0_10_0_scalar *scalar) { unsigned char buf32[32]; - rustsecp256k1zkp_v0_8_0_testrand256(buf32); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(scalar, buf32, NULL); + rustsecp256k1zkp_v0_10_0_testrand256(buf32); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(scalar, buf32, NULL); } -void rand_point(rustsecp256k1zkp_v0_8_0_ge *point) { - rustsecp256k1zkp_v0_8_0_scalar x; - rustsecp256k1zkp_v0_8_0_gej pointj; +static void rand_point(rustsecp256k1zkp_v0_10_0_ge *point) { + rustsecp256k1zkp_v0_10_0_scalar x; + rustsecp256k1zkp_v0_10_0_gej pointj; rand_scalar(&x); - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &pointj, &x); - rustsecp256k1zkp_v0_8_0_ge_set_gej(point, &pointj); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&CTX->ecmult_gen_ctx, &pointj, &x); + rustsecp256k1zkp_v0_10_0_ge_set_gej(point, &pointj); } -void dleq_nonce_bitflip(unsigned char **args, size_t n_flip, size_t n_bytes) { - rustsecp256k1zkp_v0_8_0_scalar k1, k2; +static void dleq_nonce_bitflip(unsigned char **args, size_t n_flip, size_t n_bytes) { + rustsecp256k1zkp_v0_10_0_scalar k1, k2; - CHECK(rustsecp256k1zkp_v0_8_0_dleq_nonce(&k1, args[0], args[1], args[2], args[3], NULL, args[4]) == 1); - rustsecp256k1zkp_v0_8_0_testrand_flip(args[n_flip], n_bytes); - CHECK(rustsecp256k1zkp_v0_8_0_dleq_nonce(&k2, args[0], args[1], args[2], args[3], NULL, args[4]) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&k1, &k2) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_dleq_nonce(&k1, args[0], args[1], args[2], args[3], NULL, args[4]) == 1); + rustsecp256k1zkp_v0_10_0_testrand_flip(args[n_flip], n_bytes); + CHECK(rustsecp256k1zkp_v0_10_0_dleq_nonce(&k2, args[0], args[1], args[2], args[3], NULL, args[4]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&k1, &k2) == 0); } -void dleq_tests(void) { - rustsecp256k1zkp_v0_8_0_scalar s, e, sk, k; - rustsecp256k1zkp_v0_8_0_ge gen2, p1, p2; +static void dleq_tests(void) { + rustsecp256k1zkp_v0_10_0_scalar s, e, sk, k; + rustsecp256k1zkp_v0_10_0_ge gen2, p1, p2; unsigned char *args[5]; unsigned char sk32[32]; unsigned char gen2_33[33]; @@ -41,43 +41,43 @@ void dleq_tests(void) { rand_point(&gen2); rand_scalar(&sk); - rustsecp256k1zkp_v0_8_0_dleq_pair(&ctx->ecmult_gen_ctx, &p1, &p2, &sk, &gen2); - CHECK(rustsecp256k1zkp_v0_8_0_dleq_prove(ctx, &s, &e, &sk, &gen2, &p1, &p2, NULL, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_dleq_verify(&s, &e, &p1, &gen2, &p2) == 1); + rustsecp256k1zkp_v0_10_0_dleq_pair(&CTX->ecmult_gen_ctx, &p1, &p2, &sk, &gen2); + CHECK(rustsecp256k1zkp_v0_10_0_dleq_prove(CTX, &s, &e, &sk, &gen2, &p1, &p2, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_dleq_verify(&s, &e, &p1, &gen2, &p2) == 1); { - rustsecp256k1zkp_v0_8_0_scalar tmp; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&tmp, 1); - CHECK(rustsecp256k1zkp_v0_8_0_dleq_verify(&tmp, &e, &p1, &gen2, &p2) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_dleq_verify(&s, &tmp, &p1, &gen2, &p2) == 0); + rustsecp256k1zkp_v0_10_0_scalar tmp; + rustsecp256k1zkp_v0_10_0_scalar_set_int(&tmp, 1); + CHECK(rustsecp256k1zkp_v0_10_0_dleq_verify(&tmp, &e, &p1, &gen2, &p2) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_dleq_verify(&s, &tmp, &p1, &gen2, &p2) == 0); } { - rustsecp256k1zkp_v0_8_0_ge p_tmp; + rustsecp256k1zkp_v0_10_0_ge p_tmp; rand_point(&p_tmp); - CHECK(rustsecp256k1zkp_v0_8_0_dleq_verify(&s, &e, &p_tmp, &gen2, &p2) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_dleq_verify(&s, &e, &p1, &p_tmp, &p2) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_dleq_verify(&s, &e, &p1, &gen2, &p_tmp) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_dleq_verify(&s, &e, &p_tmp, &gen2, &p2) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_dleq_verify(&s, &e, &p1, &p_tmp, &p2) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_dleq_verify(&s, &e, &p1, &gen2, &p_tmp) == 0); } { - rustsecp256k1zkp_v0_8_0_ge p_inf; - rustsecp256k1zkp_v0_8_0_ge_set_infinity(&p_inf); - CHECK(rustsecp256k1zkp_v0_8_0_dleq_prove(ctx, &s, &e, &sk, &p_inf, &p1, &p2, NULL, NULL) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_dleq_prove(ctx, &s, &e, &sk, &gen2, &p_inf, &p2, NULL, NULL) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_dleq_prove(ctx, &s, &e, &sk, &gen2, &p1, &p_inf, NULL, NULL) == 0); + rustsecp256k1zkp_v0_10_0_ge p_inf; + rustsecp256k1zkp_v0_10_0_ge_set_infinity(&p_inf); + CHECK(rustsecp256k1zkp_v0_10_0_dleq_prove(CTX, &s, &e, &sk, &p_inf, &p1, &p2, NULL, NULL) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_dleq_prove(CTX, &s, &e, &sk, &gen2, &p_inf, &p2, NULL, NULL) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_dleq_prove(CTX, &s, &e, &sk, &gen2, &p1, &p_inf, NULL, NULL) == 0); } /* Nonce tests */ - rustsecp256k1zkp_v0_8_0_scalar_get_b32(sk32, &sk); - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&gen2, gen2_33, &pubkey_size, 1)); - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&p1, p1_33, &pubkey_size, 1)); - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&p2, p2_33, &pubkey_size, 1)); - CHECK(rustsecp256k1zkp_v0_8_0_dleq_nonce(&k, sk32, gen2_33, p1_33, p2_33, NULL, NULL) == 1); - - rustsecp256k1zkp_v0_8_0_testrand_bytes_test(sk32, sizeof(sk32)); - rustsecp256k1zkp_v0_8_0_testrand_bytes_test(gen2_33, sizeof(gen2_33)); - rustsecp256k1zkp_v0_8_0_testrand_bytes_test(p1_33, sizeof(p1_33)); - rustsecp256k1zkp_v0_8_0_testrand_bytes_test(p2_33, sizeof(p2_33)); - rustsecp256k1zkp_v0_8_0_testrand_bytes_test(aux_rand, sizeof(aux_rand)); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(sk32, &sk); + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&gen2, gen2_33, &pubkey_size, 1)); + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&p1, p1_33, &pubkey_size, 1)); + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&p2, p2_33, &pubkey_size, 1)); + CHECK(rustsecp256k1zkp_v0_10_0_dleq_nonce(&k, sk32, gen2_33, p1_33, p2_33, NULL, NULL) == 1); + + rustsecp256k1zkp_v0_10_0_testrand_bytes_test(sk32, sizeof(sk32)); + rustsecp256k1zkp_v0_10_0_testrand_bytes_test(gen2_33, sizeof(gen2_33)); + rustsecp256k1zkp_v0_10_0_testrand_bytes_test(p1_33, sizeof(p1_33)); + rustsecp256k1zkp_v0_10_0_testrand_bytes_test(p2_33, sizeof(p2_33)); + rustsecp256k1zkp_v0_10_0_testrand_bytes_test(aux_rand, sizeof(aux_rand)); /* Check that a bitflip in an argument results in different nonces. */ args[0] = sk32; @@ -85,7 +85,7 @@ void dleq_tests(void) { args[2] = p1_33; args[3] = p2_33; args[4] = aux_rand; - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { dleq_nonce_bitflip(args, 0, sizeof(sk32)); dleq_nonce_bitflip(args, 1, sizeof(gen2_33)); dleq_nonce_bitflip(args, 2, sizeof(p1_33)); @@ -97,78 +97,78 @@ void dleq_tests(void) { } /* NULL aux_rand argument is allowed. */ - CHECK(rustsecp256k1zkp_v0_8_0_dleq_nonce(&k, sk32, gen2_33, p1_33, p2_33, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_dleq_nonce(&k, sk32, gen2_33, p1_33, p2_33, NULL, NULL) == 1); } -void rand_flip_bit(unsigned char *array, size_t n) { - array[rustsecp256k1zkp_v0_8_0_testrand_int(n)] ^= 1 << rustsecp256k1zkp_v0_8_0_testrand_int(8); +static void rand_flip_bit(unsigned char *array, size_t n) { + array[rustsecp256k1zkp_v0_10_0_testrand_int(n)] ^= 1 << rustsecp256k1zkp_v0_10_0_testrand_int(8); } /* Helper function for test_ecdsa_adaptor_spec_vectors * Checks that the adaptor signature is valid for the public and encryption keys. */ -void test_ecdsa_adaptor_spec_vectors_check_verify(const unsigned char *adaptor_sig162, const unsigned char *msg32, const unsigned char *pubkey33, const unsigned char *encryption_key33, int expected) { - rustsecp256k1zkp_v0_8_0_pubkey pubkey; - rustsecp256k1zkp_v0_8_0_ge pubkey_ge; - rustsecp256k1zkp_v0_8_0_pubkey encryption_key; - rustsecp256k1zkp_v0_8_0_ge encryption_key_ge; - - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(&encryption_key_ge, encryption_key33, 33) == 1); - rustsecp256k1zkp_v0_8_0_pubkey_save(&encryption_key, &encryption_key_ge); - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(&pubkey_ge, pubkey33, 33) == 1); - rustsecp256k1zkp_v0_8_0_pubkey_save(&pubkey, &pubkey_ge); - - CHECK(expected == rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(ctx, adaptor_sig162, &pubkey, msg32, &encryption_key)); +static void test_ecdsa_adaptor_spec_vectors_check_verify(const unsigned char *adaptor_sig162, const unsigned char *msg32, const unsigned char *pubkey33, const unsigned char *encryption_key33, int expected) { + rustsecp256k1zkp_v0_10_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_ge pubkey_ge; + rustsecp256k1zkp_v0_10_0_pubkey encryption_key; + rustsecp256k1zkp_v0_10_0_ge encryption_key_ge; + + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(&encryption_key_ge, encryption_key33, 33) == 1); + rustsecp256k1zkp_v0_10_0_pubkey_save(&encryption_key, &encryption_key_ge); + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(&pubkey_ge, pubkey33, 33) == 1); + rustsecp256k1zkp_v0_10_0_pubkey_save(&pubkey, &pubkey_ge); + + CHECK(expected == rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_verify(CTX, adaptor_sig162, &pubkey, msg32, &encryption_key)); } /* Helper function for test_ecdsa_adaptor_spec_vectors * Checks that the signature can be decrypted from the adaptor signature and the decryption key. */ -void test_ecdsa_adaptor_spec_vectors_check_decrypt(const unsigned char *adaptor_sig162, const unsigned char *decryption_key32, const unsigned char *signature64, int expected) { +static void test_ecdsa_adaptor_spec_vectors_check_decrypt(const unsigned char *adaptor_sig162, const unsigned char *decryption_key32, const unsigned char *signature64, int expected) { unsigned char signature[64]; - rustsecp256k1zkp_v0_8_0_ecdsa_signature s; + rustsecp256k1zkp_v0_10_0_ecdsa_signature s; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_decrypt(ctx, &s, decryption_key32, adaptor_sig162) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_compact(ctx, signature, &s) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_decrypt(CTX, &s, decryption_key32, adaptor_sig162) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_compact(CTX, signature, &s) == 1); - CHECK(expected == !(rustsecp256k1zkp_v0_8_0_memcmp_var(signature, signature64, 64))); + CHECK(expected == !(rustsecp256k1zkp_v0_10_0_memcmp_var(signature, signature64, 64))); } /* Helper function for test_ecdsa_adaptor_spec_vectors * Checks that the decryption key can be recovered from the adaptor signature, encryption key, and the signature. */ -void test_ecdsa_adaptor_spec_vectors_check_recover(const unsigned char *adaptor_sig162, const unsigned char *encryption_key33, const unsigned char *decryption_key32, const unsigned char *signature64, int expected) { +static void test_ecdsa_adaptor_spec_vectors_check_recover(const unsigned char *adaptor_sig162, const unsigned char *encryption_key33, const unsigned char *decryption_key32, const unsigned char *signature64, int expected) { unsigned char deckey32[32] = { 0 }; - rustsecp256k1zkp_v0_8_0_ecdsa_signature sig; - rustsecp256k1zkp_v0_8_0_pubkey encryption_key; - rustsecp256k1zkp_v0_8_0_ge encryption_key_ge; + rustsecp256k1zkp_v0_10_0_ecdsa_signature sig; + rustsecp256k1zkp_v0_10_0_pubkey encryption_key; + rustsecp256k1zkp_v0_10_0_ge encryption_key_ge; - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(&encryption_key_ge, encryption_key33, 33) == 1); - rustsecp256k1zkp_v0_8_0_pubkey_save(&encryption_key, &encryption_key_ge); + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(&encryption_key_ge, encryption_key33, 33) == 1); + rustsecp256k1zkp_v0_10_0_pubkey_save(&encryption_key, &encryption_key_ge); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_compact(ctx, &sig, signature64) == 1); - CHECK(expected == rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_recover(ctx, deckey32, &sig, adaptor_sig162, &encryption_key)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_compact(CTX, &sig, signature64) == 1); + CHECK(expected == rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_recover(CTX, deckey32, &sig, adaptor_sig162, &encryption_key)); if (decryption_key32 != NULL) { - CHECK(expected == !(rustsecp256k1zkp_v0_8_0_memcmp_var(deckey32, decryption_key32, 32))); + CHECK(expected == !(rustsecp256k1zkp_v0_10_0_memcmp_var(deckey32, decryption_key32, 32))); } } /* Helper function for test_ecdsa_adaptor_spec_vectors * Checks deserialization and serialization. */ -void test_ecdsa_adaptor_spec_vectors_check_serialization(const unsigned char *adaptor_sig162, int expected) { +static void test_ecdsa_adaptor_spec_vectors_check_serialization(const unsigned char *adaptor_sig162, int expected) { unsigned char buf[162]; - rustsecp256k1zkp_v0_8_0_scalar dleq_proof_s, dleq_proof_e; - rustsecp256k1zkp_v0_8_0_ge r, rp; - rustsecp256k1zkp_v0_8_0_scalar sp; - rustsecp256k1zkp_v0_8_0_scalar sigr; + rustsecp256k1zkp_v0_10_0_scalar dleq_proof_s, dleq_proof_e; + rustsecp256k1zkp_v0_10_0_ge r, rp; + rustsecp256k1zkp_v0_10_0_scalar sp; + rustsecp256k1zkp_v0_10_0_scalar sigr; - CHECK(expected == rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(&r, &sigr, &rp, &sp, &dleq_proof_e, &dleq_proof_s, adaptor_sig162)); + CHECK(expected == rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(&r, &sigr, &rp, &sp, &dleq_proof_e, &dleq_proof_s, adaptor_sig162)); if (expected == 1) { - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_serialize(buf, &r, &rp, &sp, &dleq_proof_e, &dleq_proof_s) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(buf, adaptor_sig162, 162) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_serialize(buf, &r, &rp, &sp, &dleq_proof_e, &dleq_proof_s) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(buf, adaptor_sig162, 162) == 0); } } /* Test vectors according to ECDSA adaptor signature spec. See * https://github.com/discreetlogcontracts/dlcspecs/blob/596a177375932a47306f07e7385f398f52519a83/test/ecdsa_adaptor.json. */ -void test_ecdsa_adaptor_spec_vectors(void) { +static void test_ecdsa_adaptor_spec_vectors(void) { { /* Test vector 0 */ /* kind: verification test */ @@ -710,33 +710,33 @@ static int ecdsa_adaptor_nonce_function_overflowing(unsigned char *nonce32, cons /* Checks that a bit flip in the n_flip-th argument (that has n_bytes many * bytes) changes the hash function */ -void nonce_function_ecdsa_adaptor_bitflip(unsigned char **args, size_t n_flip, size_t n_bytes, size_t algolen) { +static void nonce_function_ecdsa_adaptor_bitflip(unsigned char **args, size_t n_flip, size_t n_bytes, size_t algolen) { unsigned char nonces[2][32]; CHECK(nonce_function_ecdsa_adaptor(nonces[0], args[0], args[1], args[2], args[3], algolen, args[4]) == 1); - rustsecp256k1zkp_v0_8_0_testrand_flip(args[n_flip], n_bytes); + rustsecp256k1zkp_v0_10_0_testrand_flip(args[n_flip], n_bytes); CHECK(nonce_function_ecdsa_adaptor(nonces[1], args[0], args[1], args[2], args[3], algolen, args[4]) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(nonces[0], nonces[1], 32) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(nonces[0], nonces[1], 32) != 0); } /* Tests for the equality of two sha256 structs. This function only produces a * correct result if an integer multiple of 64 many bytes have been written * into the hash functions. */ -void ecdsa_adaptor_test_sha256_eq(const rustsecp256k1zkp_v0_8_0_sha256 *sha1, const rustsecp256k1zkp_v0_8_0_sha256 *sha2) { +static void ecdsa_adaptor_test_sha256_eq(const rustsecp256k1zkp_v0_10_0_sha256 *sha1, const rustsecp256k1zkp_v0_10_0_sha256 *sha2) { /* Is buffer fully consumed? */ CHECK((sha1->bytes & 0x3F) == 0); CHECK(sha1->bytes == sha2->bytes); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(sha1->s, sha2->s, sizeof(sha1->s)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(sha1->s, sha2->s, sizeof(sha1->s)) == 0); } -void run_nonce_function_ecdsa_adaptor_tests(void) { +static void run_nonce_function_ecdsa_adaptor_tests(void) { unsigned char tag[16] = "ECDSAadaptor/non"; unsigned char aux_tag[16] = "ECDSAadaptor/aux"; unsigned char algo[16] = "ECDSAadaptor/non"; size_t algolen = sizeof(algo); unsigned char dleq_tag[4] = "DLEQ"; - rustsecp256k1zkp_v0_8_0_sha256 sha; - rustsecp256k1zkp_v0_8_0_sha256 sha_optimized; + rustsecp256k1zkp_v0_10_0_sha256 sha; + rustsecp256k1zkp_v0_10_0_sha256 sha_optimized; unsigned char nonce[32]; unsigned char msg[32]; unsigned char key[32]; @@ -746,30 +746,30 @@ void run_nonce_function_ecdsa_adaptor_tests(void) { int i; /* Check that hash initialized by - * rustsecp256k1zkp_v0_8_0_nonce_function_ecdsa_adaptor_sha256_tagged has the expected + * rustsecp256k1zkp_v0_10_0_nonce_function_ecdsa_adaptor_sha256_tagged has the expected * state. */ - rustsecp256k1zkp_v0_8_0_sha256_initialize_tagged(&sha, tag, sizeof(tag)); - rustsecp256k1zkp_v0_8_0_nonce_function_ecdsa_adaptor_sha256_tagged(&sha_optimized); + rustsecp256k1zkp_v0_10_0_sha256_initialize_tagged(&sha, tag, sizeof(tag)); + rustsecp256k1zkp_v0_10_0_nonce_function_ecdsa_adaptor_sha256_tagged(&sha_optimized); ecdsa_adaptor_test_sha256_eq(&sha, &sha_optimized); /* Check that hash initialized by - * rustsecp256k1zkp_v0_8_0_nonce_function_ecdsa_adaptor_sha256_tagged_aux has the expected + * rustsecp256k1zkp_v0_10_0_nonce_function_ecdsa_adaptor_sha256_tagged_aux has the expected * state. */ - rustsecp256k1zkp_v0_8_0_sha256_initialize_tagged(&sha, aux_tag, sizeof(aux_tag)); - rustsecp256k1zkp_v0_8_0_nonce_function_ecdsa_adaptor_sha256_tagged_aux(&sha_optimized); + rustsecp256k1zkp_v0_10_0_sha256_initialize_tagged(&sha, aux_tag, sizeof(aux_tag)); + rustsecp256k1zkp_v0_10_0_nonce_function_ecdsa_adaptor_sha256_tagged_aux(&sha_optimized); ecdsa_adaptor_test_sha256_eq(&sha, &sha_optimized); /* Check that hash initialized by - * rustsecp256k1zkp_v0_8_0_nonce_function_dleq_sha256_tagged_aux has the expected + * rustsecp256k1zkp_v0_10_0_nonce_function_dleq_sha256_tagged_aux has the expected * state. */ - rustsecp256k1zkp_v0_8_0_sha256_initialize_tagged(&sha, dleq_tag, sizeof(dleq_tag)); - rustsecp256k1zkp_v0_8_0_nonce_function_dleq_sha256_tagged(&sha_optimized); + rustsecp256k1zkp_v0_10_0_sha256_initialize_tagged(&sha, dleq_tag, sizeof(dleq_tag)); + rustsecp256k1zkp_v0_10_0_nonce_function_dleq_sha256_tagged(&sha_optimized); ecdsa_adaptor_test_sha256_eq(&sha, &sha_optimized); - rustsecp256k1zkp_v0_8_0_testrand_bytes_test(msg, sizeof(msg)); - rustsecp256k1zkp_v0_8_0_testrand_bytes_test(key, sizeof(key)); - rustsecp256k1zkp_v0_8_0_testrand_bytes_test(pk, sizeof(pk)); - rustsecp256k1zkp_v0_8_0_testrand_bytes_test(aux_rand, sizeof(aux_rand)); + rustsecp256k1zkp_v0_10_0_testrand_bytes_test(msg, sizeof(msg)); + rustsecp256k1zkp_v0_10_0_testrand_bytes_test(key, sizeof(key)); + rustsecp256k1zkp_v0_10_0_testrand_bytes_test(pk, sizeof(pk)); + rustsecp256k1zkp_v0_10_0_testrand_bytes_test(aux_rand, sizeof(aux_rand)); /* Check that a bitflip in an argument results in different nonces. */ args[0] = msg; @@ -777,7 +777,7 @@ void run_nonce_function_ecdsa_adaptor_tests(void) { args[2] = pk; args[3] = algo; args[4] = aux_rand; - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { nonce_function_ecdsa_adaptor_bitflip(args, 0, sizeof(msg), algolen); nonce_function_ecdsa_adaptor_bitflip(args, 1, sizeof(key), algolen); nonce_function_ecdsa_adaptor_bitflip(args, 2, sizeof(pk), algolen); @@ -800,244 +800,184 @@ void run_nonce_function_ecdsa_adaptor_tests(void) { CHECK(nonce_function_ecdsa_adaptor(nonce, msg, key, pk, dleq_algo, sizeof(dleq_algo), NULL) == 1); /* Different algolen gives different nonce */ - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { unsigned char nonce2[32]; - uint32_t offset = rustsecp256k1zkp_v0_8_0_testrand_int(algolen - 1); + uint32_t offset = rustsecp256k1zkp_v0_10_0_testrand_int(algolen - 1); size_t algolen_tmp = (algolen + offset) % algolen; CHECK(nonce_function_ecdsa_adaptor(nonce2, msg, key, pk, algo, algolen_tmp, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(nonce, nonce2, 32) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(nonce, nonce2, 32) != 0); } /* NULL aux_rand argument is allowed. */ CHECK(nonce_function_ecdsa_adaptor(nonce, msg, key, pk, algo, algolen, NULL) == 1); } -void test_ecdsa_adaptor_api(void) { - rustsecp256k1zkp_v0_8_0_pubkey pubkey; - rustsecp256k1zkp_v0_8_0_pubkey enckey; - rustsecp256k1zkp_v0_8_0_pubkey zero_pk; - rustsecp256k1zkp_v0_8_0_ecdsa_signature sig; +static void test_ecdsa_adaptor_api(void) { + rustsecp256k1zkp_v0_10_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_pubkey enckey; + rustsecp256k1zkp_v0_10_0_pubkey zero_pk; + rustsecp256k1zkp_v0_10_0_ecdsa_signature sig; unsigned char sk[32]; unsigned char msg[32]; unsigned char asig[162]; unsigned char deckey[32]; /** setup **/ - rustsecp256k1zkp_v0_8_0_context *none = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_NONE); - rustsecp256k1zkp_v0_8_0_context *sign = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN); - rustsecp256k1zkp_v0_8_0_context *vrfy = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_VERIFY); - rustsecp256k1zkp_v0_8_0_context *both = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); - rustsecp256k1zkp_v0_8_0_context *sttc = rustsecp256k1zkp_v0_8_0_context_clone(rustsecp256k1zkp_v0_8_0_context_no_precomp); - int ecount; - - rustsecp256k1zkp_v0_8_0_context_set_error_callback(none, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(sign, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(vrfy, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(both, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(sttc, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(none, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sign, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(vrfy, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(both, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sttc, counting_illegal_callback_fn, &ecount); - - rustsecp256k1zkp_v0_8_0_testrand256(sk); - rustsecp256k1zkp_v0_8_0_testrand256(msg); - rustsecp256k1zkp_v0_8_0_testrand256(deckey); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey, sk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &enckey, deckey) == 1); + rustsecp256k1zkp_v0_10_0_testrand256(sk); + rustsecp256k1zkp_v0_10_0_testrand256(msg); + rustsecp256k1zkp_v0_10_0_testrand256(deckey); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &enckey, deckey) == 1); memset(&zero_pk, 0, sizeof(zero_pk)); /** main test body **/ - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt(none, asig, sk, &enckey, msg, NULL, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt(vrfy, asig, sk, &enckey, msg, NULL, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt(sign, asig, sk, &enckey, msg, NULL, NULL) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt(sttc, asig, sk, &enckey, msg, NULL, NULL) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt(sign, NULL, sk, &enckey, msg, NULL, NULL) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt(sign, asig, sk, &enckey, NULL, NULL, NULL) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt(sign, asig, NULL, &enckey, msg, NULL, NULL) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt(sign, asig, sk, NULL, msg, NULL, NULL) == 0); - CHECK(ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt(sign, asig, sk, &zero_pk, msg, NULL, NULL) == 0); - CHECK(ecount == 6); - - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt(sign, asig, sk, &enckey, msg, NULL, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(none, asig, &pubkey, msg, &enckey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(sign, asig, &pubkey, msg, &enckey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(vrfy, asig, &pubkey, msg, &enckey) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(vrfy, NULL, &pubkey, msg, &enckey) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(vrfy, asig, &pubkey, NULL, &enckey) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(vrfy, asig, &pubkey, msg, NULL) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(vrfy, asig, NULL, msg, &enckey) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(vrfy, asig, &zero_pk, msg, &enckey) == 0); - CHECK(ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(vrfy, asig, &pubkey, msg, &zero_pk) == 0); - CHECK(ecount == 6); - - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_decrypt(none, &sig, deckey, asig) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_decrypt(sign, &sig, deckey, asig) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_decrypt(vrfy, &sig, deckey, asig) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_decrypt(both, &sig, deckey, asig) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_decrypt(both, NULL, deckey, asig) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_decrypt(both, &sig, NULL, asig) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_decrypt(both, &sig, deckey, NULL) == 0); - CHECK(ecount == 3); - - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_decrypt(both, &sig, deckey, asig) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_recover(none, deckey, &sig, asig, &enckey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_recover(vrfy, deckey, &sig, asig, &enckey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_recover(sign, deckey, &sig, asig, &enckey) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_recover(sttc, deckey, &sig, asig, &enckey) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_recover(sign, NULL, &sig, asig, &enckey) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_recover(sign, deckey, NULL, asig, &enckey) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_recover(sign, deckey, &sig, NULL, &enckey) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_recover(sign, deckey, &sig, asig, NULL) == 0); - CHECK(ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_recover(sign, deckey, &sig, asig, &zero_pk) == 0); - CHECK(ecount == 6); - - rustsecp256k1zkp_v0_8_0_context_destroy(none); - rustsecp256k1zkp_v0_8_0_context_destroy(sign); - rustsecp256k1zkp_v0_8_0_context_destroy(vrfy); - rustsecp256k1zkp_v0_8_0_context_destroy(both); - rustsecp256k1zkp_v0_8_0_context_destroy(sttc); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_encrypt(CTX, asig, sk, &enckey, msg, NULL, NULL) == 1); + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_encrypt(STATIC_CTX, asig, sk, &enckey, msg, NULL, NULL)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_encrypt(CTX, NULL, sk, &enckey, msg, NULL, NULL)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_encrypt(CTX, asig, sk, &enckey, NULL, NULL, NULL)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_encrypt(CTX, asig, NULL, &enckey, msg, NULL, NULL)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_encrypt(CTX, asig, sk, NULL, msg, NULL, NULL)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_encrypt(CTX, asig, sk, &zero_pk, msg, NULL, NULL)); + + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_encrypt(CTX, asig, sk, &enckey, msg, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_verify(CTX, asig, &pubkey, msg, &enckey) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_verify(CTX, NULL, &pubkey, msg, &enckey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_verify(CTX, asig, &pubkey, NULL, &enckey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_verify(CTX, asig, &pubkey, msg, NULL)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_verify(CTX, asig, NULL, msg, &enckey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_verify(CTX, asig, &zero_pk, msg, &enckey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_verify(CTX, asig, &pubkey, msg, &zero_pk)); + + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_decrypt(CTX, &sig, deckey, asig) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_decrypt(CTX, &sig, deckey, asig) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_decrypt(CTX, NULL, deckey, asig)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_decrypt(CTX, &sig, NULL, asig)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_decrypt(CTX, &sig, deckey, NULL)); + + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_decrypt(CTX, &sig, deckey, asig) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_recover(CTX, deckey, &sig, asig, &enckey) == 1); + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_recover(STATIC_CTX, deckey, &sig, asig, &enckey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_recover(CTX, NULL, &sig, asig, &enckey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_recover(CTX, deckey, NULL, asig, &enckey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_recover(CTX, deckey, &sig, NULL, &enckey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_recover(CTX, deckey, &sig, asig, NULL)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_recover(CTX, deckey, &sig, asig, &zero_pk)); } -void adaptor_tests(void) { +static void adaptor_tests(void) { unsigned char seckey[32]; - rustsecp256k1zkp_v0_8_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; unsigned char msg[32]; unsigned char deckey[32]; - rustsecp256k1zkp_v0_8_0_pubkey enckey; + rustsecp256k1zkp_v0_10_0_pubkey enckey; unsigned char adaptor_sig[162]; - rustsecp256k1zkp_v0_8_0_ecdsa_signature sig; + rustsecp256k1zkp_v0_10_0_ecdsa_signature sig; unsigned char zeros162[162] = { 0 }; unsigned char zeros64[64] = { 0 }; unsigned char big[32]; - rustsecp256k1zkp_v0_8_0_testrand256(seckey); - rustsecp256k1zkp_v0_8_0_testrand256(msg); - rustsecp256k1zkp_v0_8_0_testrand256(deckey); + rustsecp256k1zkp_v0_10_0_testrand256(seckey); + rustsecp256k1zkp_v0_10_0_testrand256(msg); + rustsecp256k1zkp_v0_10_0_testrand256(deckey); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey, seckey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &enckey, deckey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt(ctx, adaptor_sig, seckey, &enckey, msg, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey, seckey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &enckey, deckey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_encrypt(CTX, adaptor_sig, seckey, &enckey, msg, NULL, NULL) == 1); { /* Test overflowing seckey */ memset(big, 0xFF, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt(ctx, adaptor_sig, big, &enckey, msg, NULL, NULL) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(adaptor_sig, zeros162, sizeof(adaptor_sig)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_encrypt(CTX, adaptor_sig, big, &enckey, msg, NULL, NULL) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(adaptor_sig, zeros162, sizeof(adaptor_sig)) == 0); /* Test different nonce functions */ memset(adaptor_sig, 1, sizeof(adaptor_sig)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt(ctx, adaptor_sig, seckey, &enckey, msg, ecdsa_adaptor_nonce_function_failing, NULL) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(adaptor_sig, zeros162, sizeof(adaptor_sig)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_encrypt(CTX, adaptor_sig, seckey, &enckey, msg, ecdsa_adaptor_nonce_function_failing, NULL) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(adaptor_sig, zeros162, sizeof(adaptor_sig)) == 0); memset(&adaptor_sig, 1, sizeof(adaptor_sig)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt(ctx, adaptor_sig, seckey, &enckey, msg, ecdsa_adaptor_nonce_function_0, NULL) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(adaptor_sig, zeros162, sizeof(adaptor_sig)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt(ctx, adaptor_sig, seckey, &enckey, msg, ecdsa_adaptor_nonce_function_overflowing, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(adaptor_sig, zeros162, sizeof(adaptor_sig)) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_encrypt(CTX, adaptor_sig, seckey, &enckey, msg, ecdsa_adaptor_nonce_function_0, NULL) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(adaptor_sig, zeros162, sizeof(adaptor_sig)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_encrypt(CTX, adaptor_sig, seckey, &enckey, msg, ecdsa_adaptor_nonce_function_overflowing, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(adaptor_sig, zeros162, sizeof(adaptor_sig)) != 0); } { /* Test adaptor_sig_serialize roundtrip */ - rustsecp256k1zkp_v0_8_0_ge r, rp; - rustsecp256k1zkp_v0_8_0_scalar sigr; - rustsecp256k1zkp_v0_8_0_scalar sp; - rustsecp256k1zkp_v0_8_0_scalar dleq_proof_s, dleq_proof_e; - rustsecp256k1zkp_v0_8_0_ge p_inf; + rustsecp256k1zkp_v0_10_0_ge r, rp; + rustsecp256k1zkp_v0_10_0_scalar sigr; + rustsecp256k1zkp_v0_10_0_scalar sp; + rustsecp256k1zkp_v0_10_0_scalar dleq_proof_s, dleq_proof_e; + rustsecp256k1zkp_v0_10_0_ge p_inf; unsigned char adaptor_sig_tmp[162]; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(&r, &sigr, &rp, &sp, &dleq_proof_e, &dleq_proof_s, adaptor_sig) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(&r, &sigr, &rp, &sp, &dleq_proof_e, &dleq_proof_s, adaptor_sig) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_serialize(adaptor_sig_tmp, &r, &rp, &sp, &dleq_proof_e, &dleq_proof_s) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(adaptor_sig_tmp, adaptor_sig, sizeof(adaptor_sig_tmp)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_serialize(adaptor_sig_tmp, &r, &rp, &sp, &dleq_proof_e, &dleq_proof_s) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(adaptor_sig_tmp, adaptor_sig, sizeof(adaptor_sig_tmp)) == 0); /* Test adaptor_sig_serialize points at infinity */ - rustsecp256k1zkp_v0_8_0_ge_set_infinity(&p_inf); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_serialize(adaptor_sig_tmp, &p_inf, &rp, &sp, &dleq_proof_e, &dleq_proof_s) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_serialize(adaptor_sig_tmp, &r, &p_inf, &sp, &dleq_proof_e, &dleq_proof_s) == 0); + rustsecp256k1zkp_v0_10_0_ge_set_infinity(&p_inf); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_serialize(adaptor_sig_tmp, &p_inf, &rp, &sp, &dleq_proof_e, &dleq_proof_s) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_serialize(adaptor_sig_tmp, &r, &p_inf, &sp, &dleq_proof_e, &dleq_proof_s) == 0); } { /* Test adaptor_sig_deserialize */ - rustsecp256k1zkp_v0_8_0_ge r, rp; - rustsecp256k1zkp_v0_8_0_scalar sigr; - rustsecp256k1zkp_v0_8_0_scalar sp; - rustsecp256k1zkp_v0_8_0_scalar dleq_proof_s, dleq_proof_e; + rustsecp256k1zkp_v0_10_0_ge r, rp; + rustsecp256k1zkp_v0_10_0_scalar sigr; + rustsecp256k1zkp_v0_10_0_scalar sp; + rustsecp256k1zkp_v0_10_0_scalar dleq_proof_s, dleq_proof_e; unsigned char adaptor_sig_tmp[162]; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(&r, &sigr, &rp, &sp, &dleq_proof_e, &dleq_proof_s, adaptor_sig) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(&r, &sigr, &rp, &sp, &dleq_proof_e, &dleq_proof_s, adaptor_sig) == 1); /* r */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(&r, &sigr, NULL, NULL, NULL, NULL, adaptor_sig) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(&r, &sigr, NULL, NULL, NULL, NULL, adaptor_sig) == 1); memcpy(adaptor_sig_tmp, adaptor_sig, sizeof(adaptor_sig_tmp)); memset(&adaptor_sig_tmp[0], 0xFF, 33); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(&r, &sigr, NULL, NULL, NULL, NULL, adaptor_sig_tmp) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(&r, &sigr, NULL, NULL, NULL, NULL, adaptor_sig_tmp) == 0); /* sigr */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(NULL, &sigr, NULL, NULL, NULL, NULL, adaptor_sig) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(NULL, &sigr, NULL, NULL, NULL, NULL, adaptor_sig) == 1); memcpy(adaptor_sig_tmp, adaptor_sig, sizeof(adaptor_sig_tmp)); memset(&adaptor_sig_tmp[1], 0xFF, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(NULL, &sigr, NULL, NULL, NULL, NULL, adaptor_sig_tmp) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(NULL, &sigr, NULL, NULL, NULL, NULL, adaptor_sig_tmp) == 1); memset(&adaptor_sig_tmp[1], 0, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(NULL, &sigr, NULL, NULL, NULL, NULL, adaptor_sig_tmp) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(NULL, &sigr, NULL, NULL, NULL, NULL, adaptor_sig_tmp) == 0); /* rp */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(NULL, NULL, &rp, NULL, NULL, NULL, adaptor_sig) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(NULL, NULL, &rp, NULL, NULL, NULL, adaptor_sig) == 1); memcpy(adaptor_sig_tmp, adaptor_sig, sizeof(adaptor_sig_tmp)); memset(&adaptor_sig_tmp[33], 0xFF, 33); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(NULL, NULL, &rp, NULL, NULL, NULL, adaptor_sig_tmp) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(NULL, NULL, &rp, NULL, NULL, NULL, adaptor_sig_tmp) == 0); /* sp */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(NULL, NULL, NULL, &sp, NULL, NULL, adaptor_sig) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(NULL, NULL, NULL, &sp, NULL, NULL, adaptor_sig) == 1); memcpy(adaptor_sig_tmp, adaptor_sig, sizeof(adaptor_sig_tmp)); memset(&adaptor_sig_tmp[66], 0xFF, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(NULL, NULL, NULL, &sp, NULL, NULL, adaptor_sig_tmp) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(NULL, NULL, NULL, &sp, NULL, NULL, adaptor_sig_tmp) == 0); /* dleq_proof_e */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(NULL, NULL, NULL, NULL, &dleq_proof_e, NULL, adaptor_sig) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(NULL, NULL, NULL, NULL, &dleq_proof_e, NULL, adaptor_sig) == 1); memcpy(adaptor_sig_tmp, adaptor_sig, sizeof(adaptor_sig_tmp)); memset(&adaptor_sig_tmp[98], 0xFF, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(NULL, NULL, NULL, NULL, &dleq_proof_e, NULL, adaptor_sig_tmp) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(NULL, NULL, NULL, NULL, &dleq_proof_e, NULL, adaptor_sig_tmp) == 1); /* dleq_proof_s */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(NULL, NULL, NULL, NULL, NULL, &dleq_proof_s, adaptor_sig) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(NULL, NULL, NULL, NULL, NULL, &dleq_proof_s, adaptor_sig) == 1); memcpy(adaptor_sig_tmp, adaptor_sig, sizeof(adaptor_sig_tmp)); memset(&adaptor_sig_tmp[130], 0xFF, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(NULL, NULL, NULL, NULL, NULL, &dleq_proof_s, adaptor_sig_tmp) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(NULL, NULL, NULL, NULL, NULL, &dleq_proof_s, adaptor_sig_tmp) == 0); } /* Test adaptor_sig_verify */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(ctx, adaptor_sig, &pubkey, msg, &enckey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(ctx, adaptor_sig, &enckey, msg, &enckey) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(ctx, adaptor_sig, &pubkey, msg, &pubkey) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_verify(CTX, adaptor_sig, &pubkey, msg, &enckey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_verify(CTX, adaptor_sig, &enckey, msg, &enckey) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_verify(CTX, adaptor_sig, &pubkey, msg, &pubkey) == 0); { /* Test failed adaptor sig deserialization */ unsigned char adaptor_sig_tmp[162]; memset(&adaptor_sig_tmp, 0xFF, 162); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(ctx, adaptor_sig_tmp, &pubkey, msg, &enckey) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_verify(CTX, adaptor_sig_tmp, &pubkey, msg, &enckey) == 0); } { /* Test that any flipped bit in the adaptor signature will make @@ -1045,13 +985,13 @@ void adaptor_tests(void) { unsigned char adaptor_sig_tmp[162]; memcpy(adaptor_sig_tmp, adaptor_sig, sizeof(adaptor_sig_tmp)); rand_flip_bit(&adaptor_sig_tmp[1], sizeof(adaptor_sig_tmp) - 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(ctx, adaptor_sig_tmp, &pubkey, msg, &enckey) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_verify(CTX, adaptor_sig_tmp, &pubkey, msg, &enckey) == 0); } { unsigned char msg_tmp[32]; memcpy(msg_tmp, msg, sizeof(msg_tmp)); rand_flip_bit(msg_tmp, sizeof(msg_tmp)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(ctx, adaptor_sig, &pubkey, msg_tmp, &enckey) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_verify(CTX, adaptor_sig, &pubkey, msg_tmp, &enckey) == 0); } { /* Verification must check that the derived R' is not equal to the point at @@ -1079,53 +1019,53 @@ void adaptor_tests(void) { unsigned char seckey_tmp[32] = { 0 }; unsigned char msg_tmp[32]; unsigned char adaptor_sig_tmp[162]; - rustsecp256k1zkp_v0_8_0_pubkey pubkey_tmp; - rustsecp256k1zkp_v0_8_0_scalar sigr, t, m; + rustsecp256k1zkp_v0_10_0_pubkey pubkey_tmp; + rustsecp256k1zkp_v0_10_0_scalar sigr, t, m; /* m := t * sigr */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_sig_deserialize(NULL, &sigr, NULL, NULL, NULL, NULL, adaptor_sig) == 1); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&t, target, NULL); - rustsecp256k1zkp_v0_8_0_scalar_mul(&m, &t, &sigr); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(msg_tmp, &m); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_sig_deserialize(NULL, &sigr, NULL, NULL, NULL, NULL, adaptor_sig) == 1); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&t, target, NULL); + rustsecp256k1zkp_v0_10_0_scalar_mul(&m, &t, &sigr); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(msg_tmp, &m); /* X := G */ seckey_tmp[31] = 1; - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey_tmp, seckey_tmp) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey_tmp, seckey_tmp) == 1); /* sp := sigr */ memcpy(adaptor_sig_tmp, adaptor_sig, sizeof(adaptor_sig_tmp)); memcpy(&adaptor_sig_tmp[66], &adaptor_sig_tmp[1], 32); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(ctx, adaptor_sig_tmp, &pubkey_tmp, msg_tmp, &enckey) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_verify(CTX, adaptor_sig_tmp, &pubkey_tmp, msg_tmp, &enckey) == 0); } /* Test decryption */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_decrypt(ctx, &sig, deckey, adaptor_sig) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &sig, msg, &pubkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_decrypt(CTX, &sig, deckey, adaptor_sig) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &sig, msg, &pubkey) == 1); { /* Test overflowing decryption key */ - rustsecp256k1zkp_v0_8_0_ecdsa_signature s; + rustsecp256k1zkp_v0_10_0_ecdsa_signature s; memset(big, 0xFF, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_decrypt(ctx, &s, big, adaptor_sig) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&s.data[0], zeros64, sizeof(&s.data[0])) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_decrypt(CTX, &s, big, adaptor_sig) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&s.data[0], zeros64, sizeof(&s.data[0])) == 0); } { /* Test key recover */ unsigned char decryption_key_tmp[32]; unsigned char adaptor_sig_tmp[162]; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_recover(ctx, decryption_key_tmp, &sig, adaptor_sig, &enckey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(deckey, decryption_key_tmp, sizeof(deckey)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_recover(CTX, decryption_key_tmp, &sig, adaptor_sig, &enckey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(deckey, decryption_key_tmp, sizeof(deckey)) == 0); /* Test failed sp deserialization */ memcpy(adaptor_sig_tmp, adaptor_sig, sizeof(adaptor_sig_tmp)); memset(&adaptor_sig_tmp[66], 0xFF, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_recover(ctx, decryption_key_tmp, &sig, adaptor_sig_tmp, &enckey) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_recover(CTX, decryption_key_tmp, &sig, adaptor_sig_tmp, &enckey) == 0); } } -void multi_hop_lock_tests(void) { +static void multi_hop_lock_tests(void) { unsigned char seckey_a[32]; unsigned char seckey_b[32]; unsigned char pop[32]; @@ -1134,84 +1074,84 @@ void multi_hop_lock_tests(void) { unsigned char buf[32]; unsigned char asig_ab[162]; unsigned char asig_bc[162]; - rustsecp256k1zkp_v0_8_0_pubkey pubkey_pop; - rustsecp256k1zkp_v0_8_0_pubkey pubkey_a, pubkey_b; - rustsecp256k1zkp_v0_8_0_pubkey l, r; - rustsecp256k1zkp_v0_8_0_ge l_ge, r_ge; - rustsecp256k1zkp_v0_8_0_scalar t1, t2, tp; - rustsecp256k1zkp_v0_8_0_scalar deckey; - rustsecp256k1zkp_v0_8_0_ecdsa_signature sig_ab, sig_bc; + rustsecp256k1zkp_v0_10_0_pubkey pubkey_pop; + rustsecp256k1zkp_v0_10_0_pubkey pubkey_a, pubkey_b; + rustsecp256k1zkp_v0_10_0_pubkey l, r; + rustsecp256k1zkp_v0_10_0_ge l_ge, r_ge; + rustsecp256k1zkp_v0_10_0_scalar t1, t2, tp; + rustsecp256k1zkp_v0_10_0_scalar deckey; + rustsecp256k1zkp_v0_10_0_ecdsa_signature sig_ab, sig_bc; - rustsecp256k1zkp_v0_8_0_testrand256(seckey_a); - rustsecp256k1zkp_v0_8_0_testrand256(seckey_b); + rustsecp256k1zkp_v0_10_0_testrand256(seckey_a); + rustsecp256k1zkp_v0_10_0_testrand256(seckey_b); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey_a, seckey_a)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey_b, seckey_b)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey_a, seckey_a)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey_b, seckey_b)); /* Carol setup */ /* Proof of payment */ - rustsecp256k1zkp_v0_8_0_testrand256(pop); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey_pop, pop)); + rustsecp256k1zkp_v0_10_0_testrand256(pop); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey_pop, pop)); /* Alice setup */ - rustsecp256k1zkp_v0_8_0_testrand256(tx_ab); + rustsecp256k1zkp_v0_10_0_testrand256(tx_ab); rand_scalar(&t1); rand_scalar(&t2); - rustsecp256k1zkp_v0_8_0_scalar_add(&tp, &t1, &t2); + rustsecp256k1zkp_v0_10_0_scalar_add(&tp, &t1, &t2); /* Left lock */ - rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &l_ge, &pubkey_pop); - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_tweak_add(&l_ge, &t1)); - rustsecp256k1zkp_v0_8_0_pubkey_save(&l, &l_ge); + rustsecp256k1zkp_v0_10_0_pubkey_load(CTX, &l_ge, &pubkey_pop); + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_tweak_add(&l_ge, &t1)); + rustsecp256k1zkp_v0_10_0_pubkey_save(&l, &l_ge); /* Right lock */ - rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &r_ge, &pubkey_pop); - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_tweak_add(&r_ge, &tp)); - rustsecp256k1zkp_v0_8_0_pubkey_save(&r, &r_ge); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt(ctx, asig_ab, seckey_a, &l, tx_ab, NULL, NULL)); + rustsecp256k1zkp_v0_10_0_pubkey_load(CTX, &r_ge, &pubkey_pop); + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_tweak_add(&r_ge, &tp)); + rustsecp256k1zkp_v0_10_0_pubkey_save(&r, &r_ge); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_encrypt(CTX, asig_ab, seckey_a, &l, tx_ab, NULL, NULL)); /* Bob setup */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(ctx, asig_ab, &pubkey_a, tx_ab, &l)); - rustsecp256k1zkp_v0_8_0_testrand256(tx_bc); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt(ctx, asig_bc, seckey_b, &r, tx_bc, NULL, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_verify(CTX, asig_ab, &pubkey_a, tx_ab, &l)); + rustsecp256k1zkp_v0_10_0_testrand256(tx_bc); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_encrypt(CTX, asig_bc, seckey_b, &r, tx_bc, NULL, NULL)); /* Carol decrypt */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify(ctx, asig_bc, &pubkey_b, tx_bc, &r)); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&deckey, pop, NULL); - rustsecp256k1zkp_v0_8_0_scalar_add(&deckey, &deckey, &tp); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(buf, &deckey); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_decrypt(ctx, &sig_bc, buf, asig_bc)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &sig_bc, tx_bc, &pubkey_b)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_verify(CTX, asig_bc, &pubkey_b, tx_bc, &r)); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&deckey, pop, NULL); + rustsecp256k1zkp_v0_10_0_scalar_add(&deckey, &deckey, &tp); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(buf, &deckey); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_decrypt(CTX, &sig_bc, buf, asig_bc)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &sig_bc, tx_bc, &pubkey_b)); /* Bob recover and decrypt */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_recover(ctx, buf, &sig_bc, asig_bc, &r)); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&deckey, buf, NULL); - rustsecp256k1zkp_v0_8_0_scalar_negate(&t2, &t2); - rustsecp256k1zkp_v0_8_0_scalar_add(&deckey, &deckey, &t2); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(buf, &deckey); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_decrypt(ctx, &sig_ab, buf, asig_ab)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &sig_ab, tx_ab, &pubkey_a)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_recover(CTX, buf, &sig_bc, asig_bc, &r)); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&deckey, buf, NULL); + rustsecp256k1zkp_v0_10_0_scalar_negate(&t2, &t2); + rustsecp256k1zkp_v0_10_0_scalar_add(&deckey, &deckey, &t2); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(buf, &deckey); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_decrypt(CTX, &sig_ab, buf, asig_ab)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &sig_ab, tx_ab, &pubkey_a)); /* Alice recover and derive proof of payment */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_recover(ctx, buf, &sig_ab, asig_ab, &l)); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&deckey, buf, NULL); - rustsecp256k1zkp_v0_8_0_scalar_negate(&t1, &t1); - rustsecp256k1zkp_v0_8_0_scalar_add(&deckey, &deckey, &t1); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(buf, &deckey); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(buf, pop, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_recover(CTX, buf, &sig_ab, asig_ab, &l)); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&deckey, buf, NULL); + rustsecp256k1zkp_v0_10_0_scalar_negate(&t1, &t1); + rustsecp256k1zkp_v0_10_0_scalar_add(&deckey, &deckey, &t1); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(buf, &deckey); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(buf, pop, 32) == 0); } -void run_ecdsa_adaptor_tests(void) { +static void run_ecdsa_adaptor_tests(void) { int i; run_nonce_function_ecdsa_adaptor_tests(); test_ecdsa_adaptor_api(); test_ecdsa_adaptor_spec_vectors(); - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { dleq_tests(); } - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { adaptor_tests(); } - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { multi_hop_lock_tests(); } } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_s2c/Makefile.am.include b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_s2c/Makefile.am.include index 33d620d8..23b345af 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_s2c/Makefile.am.include +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_s2c/Makefile.am.include @@ -1,3 +1,3 @@ -include_HEADERS += include/rustsecp256k1zkp_v0_8_0_ecdsa_s2c.h +include_HEADERS += include/rustsecp256k1zkp_v0_10_0_ecdsa_s2c.h noinst_HEADERS += src/modules/ecdsa_s2c/main_impl.h noinst_HEADERS += src/modules/ecdsa_s2c/tests_impl.h diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_s2c/main_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_s2c/main_impl.h index a26862d2..1399d58b 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_s2c/main_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_s2c/main_impl.h @@ -10,33 +10,33 @@ #include "../../../include/secp256k1.h" #include "../../../include/secp256k1_ecdsa_s2c.h" -static void rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_save(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening* opening, rustsecp256k1zkp_v0_8_0_ge* ge) { - rustsecp256k1zkp_v0_8_0_pubkey_save((rustsecp256k1zkp_v0_8_0_pubkey*) opening, ge); +static void rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_save(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening* opening, rustsecp256k1zkp_v0_10_0_ge* ge) { + rustsecp256k1zkp_v0_10_0_pubkey_save((rustsecp256k1zkp_v0_10_0_pubkey*) opening, ge); } -static int rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_load(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ge* ge, const rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening* opening) { - return rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, ge, (const rustsecp256k1zkp_v0_8_0_pubkey*) opening); +static int rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_load(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_ge* ge, const rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening* opening) { + return rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, ge, (const rustsecp256k1zkp_v0_10_0_pubkey*) opening); } -int rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_parse(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening* opening, const unsigned char* input33) { +int rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_parse(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening* opening, const unsigned char* input33) { VERIFY_CHECK(ctx != NULL); ARG_CHECK(opening != NULL); ARG_CHECK(input33 != NULL); - return rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, (rustsecp256k1zkp_v0_8_0_pubkey*) opening, input33, 33); + return rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(ctx, (rustsecp256k1zkp_v0_10_0_pubkey*) opening, input33, 33); } -int rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_serialize(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char* output33, const rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening* opening) { +int rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_serialize(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char* output33, const rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening* opening) { size_t out_len = 33; VERIFY_CHECK(ctx != NULL); ARG_CHECK(output33 != NULL); ARG_CHECK(opening != NULL); - return rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, output33, &out_len, (const rustsecp256k1zkp_v0_8_0_pubkey*) opening, SECP256K1_EC_COMPRESSED); + return rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(ctx, output33, &out_len, (const rustsecp256k1zkp_v0_10_0_pubkey*) opening, SECP256K1_EC_COMPRESSED); } /* Initializes SHA256 with fixed midstate. This midstate was computed by applying * SHA256 to SHA256("s2c/ecdsa/point")||SHA256("s2c/ecdsa/point"). */ -static void rustsecp256k1zkp_v0_8_0_s2c_ecdsa_point_sha256_tagged(rustsecp256k1zkp_v0_8_0_sha256 *sha) { - rustsecp256k1zkp_v0_8_0_sha256_initialize(sha); +static void rustsecp256k1zkp_v0_10_0_s2c_ecdsa_point_sha256_tagged(rustsecp256k1zkp_v0_10_0_sha256 *sha) { + rustsecp256k1zkp_v0_10_0_sha256_initialize(sha); sha->s[0] = 0xa9b21c7bul; sha->s[1] = 0x358c3e3eul; sha->s[2] = 0x0b6863d1ul; @@ -51,8 +51,8 @@ static void rustsecp256k1zkp_v0_8_0_s2c_ecdsa_point_sha256_tagged(rustsecp256k1z /* Initializes SHA256 with fixed midstate. This midstate was computed by applying * SHA256 to SHA256("s2c/ecdsa/data")||SHA256("s2c/ecdsa/data"). */ -static void rustsecp256k1zkp_v0_8_0_s2c_ecdsa_data_sha256_tagged(rustsecp256k1zkp_v0_8_0_sha256 *sha) { - rustsecp256k1zkp_v0_8_0_sha256_initialize(sha); +static void rustsecp256k1zkp_v0_10_0_s2c_ecdsa_data_sha256_tagged(rustsecp256k1zkp_v0_10_0_sha256 *sha) { + rustsecp256k1zkp_v0_10_0_sha256_initialize(sha); sha->s[0] = 0xfeefd675ul; sha->s[1] = 0x73166c99ul; sha->s[2] = 0xe2309cb8ul; @@ -65,15 +65,15 @@ static void rustsecp256k1zkp_v0_8_0_s2c_ecdsa_data_sha256_tagged(rustsecp256k1zk sha->bytes = 64; } -int rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ecdsa_signature* signature, rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening* s2c_opening, const unsigned char +int rustsecp256k1zkp_v0_10_0_ecdsa_s2c_sign(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_ecdsa_signature* signature, rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening* s2c_opening, const unsigned char *msg32, const unsigned char *seckey, const unsigned char* s2c_data32) { - rustsecp256k1zkp_v0_8_0_scalar r, s; + rustsecp256k1zkp_v0_10_0_scalar r, s; int ret; unsigned char ndata[32]; - rustsecp256k1zkp_v0_8_0_sha256 s2c_sha; + rustsecp256k1zkp_v0_10_0_sha256 s2c_sha; VERIFY_CHECK(ctx != NULL); - ARG_CHECK(rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); ARG_CHECK(msg32 != NULL); ARG_CHECK(signature != NULL); ARG_CHECK(seckey != NULL); @@ -83,35 +83,35 @@ int rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign(const rustsecp256k1zkp_v0_8_0_context * derive the nonce. It is first hashed because it should be possible * to derive nonces even if only a SHA256 commitment to the data is * known. This is important in the ECDSA anti-exfil protocol. */ - rustsecp256k1zkp_v0_8_0_s2c_ecdsa_data_sha256_tagged(&s2c_sha); - rustsecp256k1zkp_v0_8_0_sha256_write(&s2c_sha, s2c_data32, 32); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&s2c_sha, ndata); - - rustsecp256k1zkp_v0_8_0_s2c_ecdsa_point_sha256_tagged(&s2c_sha); - ret = rustsecp256k1zkp_v0_8_0_ecdsa_sign_inner(ctx, &r, &s, NULL, &s2c_sha, s2c_opening, s2c_data32, msg32, seckey, NULL, ndata); - rustsecp256k1zkp_v0_8_0_scalar_cmov(&r, &rustsecp256k1zkp_v0_8_0_scalar_zero, !ret); - rustsecp256k1zkp_v0_8_0_scalar_cmov(&s, &rustsecp256k1zkp_v0_8_0_scalar_zero, !ret); - rustsecp256k1zkp_v0_8_0_ecdsa_signature_save(signature, &r, &s); + rustsecp256k1zkp_v0_10_0_s2c_ecdsa_data_sha256_tagged(&s2c_sha); + rustsecp256k1zkp_v0_10_0_sha256_write(&s2c_sha, s2c_data32, 32); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&s2c_sha, ndata); + + rustsecp256k1zkp_v0_10_0_s2c_ecdsa_point_sha256_tagged(&s2c_sha); + ret = rustsecp256k1zkp_v0_10_0_ecdsa_sign_inner(ctx, &r, &s, NULL, &s2c_sha, s2c_opening, s2c_data32, msg32, seckey, NULL, ndata); + rustsecp256k1zkp_v0_10_0_scalar_cmov(&r, &rustsecp256k1zkp_v0_10_0_scalar_zero, !ret); + rustsecp256k1zkp_v0_10_0_scalar_cmov(&s, &rustsecp256k1zkp_v0_10_0_scalar_zero, !ret); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_save(signature, &r, &s); return ret; } -int rustsecp256k1zkp_v0_8_0_ecdsa_s2c_verify_commit(const rustsecp256k1zkp_v0_8_0_context* ctx, const rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig, const unsigned char* data32, const rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening* opening) { - rustsecp256k1zkp_v0_8_0_ge commitment_ge; - rustsecp256k1zkp_v0_8_0_ge original_pubnonce_ge; +int rustsecp256k1zkp_v0_10_0_ecdsa_s2c_verify_commit(const rustsecp256k1zkp_v0_10_0_context* ctx, const rustsecp256k1zkp_v0_10_0_ecdsa_signature* sig, const unsigned char* data32, const rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening* opening) { + rustsecp256k1zkp_v0_10_0_ge commitment_ge; + rustsecp256k1zkp_v0_10_0_ge original_pubnonce_ge; unsigned char x_bytes[32]; - rustsecp256k1zkp_v0_8_0_scalar sigr, sigs, x_scalar; - rustsecp256k1zkp_v0_8_0_sha256 s2c_sha; + rustsecp256k1zkp_v0_10_0_scalar sigr, sigs, x_scalar; + rustsecp256k1zkp_v0_10_0_sha256 s2c_sha; VERIFY_CHECK(ctx != NULL); ARG_CHECK(sig != NULL); ARG_CHECK(data32 != NULL); ARG_CHECK(opening != NULL); - if (!rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_load(ctx, &original_pubnonce_ge, opening)) { + if (!rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_load(ctx, &original_pubnonce_ge, opening)) { return 0; } - rustsecp256k1zkp_v0_8_0_s2c_ecdsa_point_sha256_tagged(&s2c_sha); - if (!rustsecp256k1zkp_v0_8_0_ec_commit(&commitment_ge, &original_pubnonce_ge, &s2c_sha, data32, 32)) { + rustsecp256k1zkp_v0_10_0_s2c_ecdsa_point_sha256_tagged(&s2c_sha); + if (!rustsecp256k1zkp_v0_10_0_ec_commit(&commitment_ge, &original_pubnonce_ge, &s2c_sha, data32, 32)) { return 0; } @@ -122,44 +122,44 @@ int rustsecp256k1zkp_v0_8_0_ecdsa_s2c_verify_commit(const rustsecp256k1zkp_v0_8_ * Note that we are only checking the x-coordinate -- this is because the y-coordinate * is not part of the ECDSA signature (and therefore not part of the commitment!) */ - rustsecp256k1zkp_v0_8_0_ecdsa_signature_load(ctx, &sigr, &sigs, sig); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_load(ctx, &sigr, &sigs, sig); - rustsecp256k1zkp_v0_8_0_fe_normalize(&commitment_ge.x); - rustsecp256k1zkp_v0_8_0_fe_get_b32(x_bytes, &commitment_ge.x); + rustsecp256k1zkp_v0_10_0_fe_normalize(&commitment_ge.x); + rustsecp256k1zkp_v0_10_0_fe_get_b32(x_bytes, &commitment_ge.x); /* Do not check overflow; overflowing a scalar does not affect whether * or not the R value is a cryptographic commitment, only whether it * is a valid R value for an ECDSA signature. If users care about that * they should use `ecdsa_verify` or `anti_exfil_host_verify`. In other * words, this check would be (at best) unnecessary, and (at worst) * insufficient. */ - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&x_scalar, x_bytes, NULL); - return rustsecp256k1zkp_v0_8_0_scalar_eq(&sigr, &x_scalar); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&x_scalar, x_bytes, NULL); + return rustsecp256k1zkp_v0_10_0_scalar_eq(&sigr, &x_scalar); } /*** anti-exfil ***/ -int rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_host_commit(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char* rand_commitment32, const unsigned char* rand32) { - rustsecp256k1zkp_v0_8_0_sha256 sha; +int rustsecp256k1zkp_v0_10_0_ecdsa_anti_exfil_host_commit(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char* rand_commitment32, const unsigned char* rand32) { + rustsecp256k1zkp_v0_10_0_sha256 sha; VERIFY_CHECK(ctx != NULL); ARG_CHECK(rand_commitment32 != NULL); ARG_CHECK(rand32 != NULL); - rustsecp256k1zkp_v0_8_0_s2c_ecdsa_data_sha256_tagged(&sha); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, rand32, 32); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, rand_commitment32); + rustsecp256k1zkp_v0_10_0_s2c_ecdsa_data_sha256_tagged(&sha); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, rand32, 32); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, rand_commitment32); return 1; } -int rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_signer_commit(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening* opening, const unsigned char* msg32, const unsigned char* seckey32, const unsigned char* rand_commitment32) { +int rustsecp256k1zkp_v0_10_0_ecdsa_anti_exfil_signer_commit(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening* opening, const unsigned char* msg32, const unsigned char* seckey32, const unsigned char* rand_commitment32) { unsigned char nonce32[32]; - rustsecp256k1zkp_v0_8_0_scalar k; - rustsecp256k1zkp_v0_8_0_gej rj; - rustsecp256k1zkp_v0_8_0_ge r; + rustsecp256k1zkp_v0_10_0_scalar k; + rustsecp256k1zkp_v0_10_0_gej rj; + rustsecp256k1zkp_v0_10_0_ge r; unsigned int count = 0; int is_nonce_valid = 0; VERIFY_CHECK(ctx != NULL); - ARG_CHECK(rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); ARG_CHECK(opening != NULL); ARG_CHECK(msg32 != NULL); ARG_CHECK(seckey32 != NULL); @@ -167,31 +167,31 @@ int rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_signer_commit(const rustsecp256k1zk memset(nonce32, 0, 32); while (!is_nonce_valid) { - /* cast to void* removes const qualifier, but rustsecp256k1zkp_v0_8_0_nonce_function_default does not modify it */ - if (!rustsecp256k1zkp_v0_8_0_nonce_function_default(nonce32, msg32, seckey32, NULL, (void*)rand_commitment32, count)) { - rustsecp256k1zkp_v0_8_0_callback_call(&ctx->error_callback, "(cryptographically unreachable) generated bad nonce"); + /* cast to void* removes const qualifier, but rustsecp256k1zkp_v0_10_0_nonce_function_default does not modify it */ + if (!rustsecp256k1zkp_v0_10_0_nonce_function_default(nonce32, msg32, seckey32, NULL, (void*)rand_commitment32, count)) { + rustsecp256k1zkp_v0_10_0_callback_call(&ctx->error_callback, "(cryptographically unreachable) generated bad nonce"); } - is_nonce_valid = rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(&k, nonce32); + is_nonce_valid = rustsecp256k1zkp_v0_10_0_scalar_set_b32_seckey(&k, nonce32); /* The nonce is still secret here, but it being invalid is is less likely than 1:2^255. */ - rustsecp256k1zkp_v0_8_0_declassify(ctx, &is_nonce_valid, sizeof(is_nonce_valid)); + rustsecp256k1zkp_v0_10_0_declassify(ctx, &is_nonce_valid, sizeof(is_nonce_valid)); count++; } - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &rj, &k); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&r, &rj); - rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_save(opening, &r); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&ctx->ecmult_gen_ctx, &rj, &k); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&r, &rj); + rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_save(opening, &r); memset(nonce32, 0, 32); - rustsecp256k1zkp_v0_8_0_scalar_clear(&k); + rustsecp256k1zkp_v0_10_0_scalar_clear(&k); return 1; } -int rustsecp256k1zkp_v0_8_0_anti_exfil_sign(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig, const unsigned char* msg32, const unsigned char* seckey, const unsigned char* host_data32) { - return rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign(ctx, sig, NULL, msg32, seckey, host_data32); +int rustsecp256k1zkp_v0_10_0_anti_exfil_sign(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_ecdsa_signature* sig, const unsigned char* msg32, const unsigned char* seckey, const unsigned char* host_data32) { + return rustsecp256k1zkp_v0_10_0_ecdsa_s2c_sign(ctx, sig, NULL, msg32, seckey, host_data32); } -int rustsecp256k1zkp_v0_8_0_anti_exfil_host_verify(const rustsecp256k1zkp_v0_8_0_context* ctx, const rustsecp256k1zkp_v0_8_0_ecdsa_signature *sig, const unsigned char *msg32, const rustsecp256k1zkp_v0_8_0_pubkey *pubkey, const unsigned char *host_data32, const rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening *opening) { - return rustsecp256k1zkp_v0_8_0_ecdsa_s2c_verify_commit(ctx, sig, host_data32, opening) && - rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, sig, msg32, pubkey); +int rustsecp256k1zkp_v0_10_0_anti_exfil_host_verify(const rustsecp256k1zkp_v0_10_0_context* ctx, const rustsecp256k1zkp_v0_10_0_ecdsa_signature *sig, const unsigned char *msg32, const rustsecp256k1zkp_v0_10_0_pubkey *pubkey, const unsigned char *host_data32, const rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening *opening) { + return rustsecp256k1zkp_v0_10_0_ecdsa_s2c_verify_commit(ctx, sig, host_data32, opening) && + rustsecp256k1zkp_v0_10_0_ecdsa_verify(ctx, sig, msg32, pubkey); } #endif /* SECP256K1_ECDSA_S2C_MAIN_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_s2c/tests_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_s2c/tests_impl.h index b97e63e5..9705ddec 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_s2c/tests_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ecdsa_s2c/tests_impl.h @@ -12,29 +12,27 @@ static void test_ecdsa_s2c_tagged_hash(void) { unsigned char tag_data[14] = "s2c/ecdsa/data"; unsigned char tag_point[15] = "s2c/ecdsa/point"; - rustsecp256k1zkp_v0_8_0_sha256 sha; - rustsecp256k1zkp_v0_8_0_sha256 sha_optimized; + rustsecp256k1zkp_v0_10_0_sha256 sha; + rustsecp256k1zkp_v0_10_0_sha256 sha_optimized; unsigned char output[32]; unsigned char output_optimized[32]; - rustsecp256k1zkp_v0_8_0_sha256_initialize_tagged(&sha, tag_data, sizeof(tag_data)); - rustsecp256k1zkp_v0_8_0_s2c_ecdsa_data_sha256_tagged(&sha_optimized); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, output); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha_optimized, output_optimized); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(output, output_optimized, 32) == 0); - - rustsecp256k1zkp_v0_8_0_sha256_initialize_tagged(&sha, tag_point, sizeof(tag_point)); - rustsecp256k1zkp_v0_8_0_s2c_ecdsa_point_sha256_tagged(&sha_optimized); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, output); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha_optimized, output_optimized); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(output, output_optimized, 32) == 0); + rustsecp256k1zkp_v0_10_0_sha256_initialize_tagged(&sha, tag_data, sizeof(tag_data)); + rustsecp256k1zkp_v0_10_0_s2c_ecdsa_data_sha256_tagged(&sha_optimized); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, output); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha_optimized, output_optimized); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(output, output_optimized, 32) == 0); + + rustsecp256k1zkp_v0_10_0_sha256_initialize_tagged(&sha, tag_point, sizeof(tag_point)); + rustsecp256k1zkp_v0_10_0_s2c_ecdsa_point_sha256_tagged(&sha_optimized); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, output); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha_optimized, output_optimized); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(output, output_optimized, 32) == 0); } -void run_s2c_opening_test(void) { +static void run_s2c_opening_test(void) { int i = 0; unsigned char output[33]; - rustsecp256k1zkp_v0_8_0_context *none = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_NONE); - unsigned char input[33] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -42,176 +40,100 @@ void run_s2c_opening_test(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }; - rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening opening; - int32_t ecount = 0; - - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(none, counting_illegal_callback_fn, &ecount); + rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening opening; /* First parsing, then serializing works */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_parse(none, &opening, input) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_serialize(none, output, &opening) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_parse(none, &opening, input) == 1); - CHECK(ecount == 0); - - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_parse(none, NULL, input) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_parse(none, &opening, NULL) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_parse(none, &opening, input) == 1); - - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_serialize(none, NULL, &opening) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_serialize(none, output, NULL) == 0); - - CHECK(ecount == 4); - /* Invalid pubkey makes parsing fail */ + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_parse(CTX, &opening, input) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_serialize(CTX, output, &opening) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_parse(CTX, &opening, input) == 1); + + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_parse(CTX, NULL, input)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_parse(CTX, &opening, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_parse(CTX, &opening, input) == 1); + + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_serialize(CTX, NULL, &opening)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_serialize(CTX, output, NULL)); + + /* Invalid pubkey makes parsing fail but they are not API errors */ input[0] = 0; /* bad oddness bit */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_parse(none, &opening, input) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_parse(CTX, &opening, input) == 0); input[0] = 2; input[31] = 1; /* point not on the curve */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_parse(none, &opening, input) == 0); - CHECK(ecount == 4); /* neither of the above are API errors */ + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_parse(CTX, &opening, input) == 0); /* Try parsing and serializing a bunch of openings */ - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { /* This is expected to fail in about 50% of iterations because the * points' x-coordinates are uniformly random */ - if (rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_parse(none, &opening, input) == 1) { - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_serialize(none, output, &opening) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(output, input, sizeof(output)) == 0); + if (rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_parse(CTX, &opening, input) == 1) { + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_serialize(CTX, output, &opening) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(output, input, sizeof(output)) == 0); } - rustsecp256k1zkp_v0_8_0_testrand256(&input[1]); + rustsecp256k1zkp_v0_10_0_testrand256(&input[1]); /* Set pubkey oddness tag to first bit of input[1] */ input[0] = (input[1] & 1) + 2; } - - rustsecp256k1zkp_v0_8_0_context_destroy(none); } static void test_ecdsa_s2c_api(void) { - rustsecp256k1zkp_v0_8_0_context *none = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_NONE); - rustsecp256k1zkp_v0_8_0_context *sign = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN); - rustsecp256k1zkp_v0_8_0_context *vrfy = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_VERIFY); - rustsecp256k1zkp_v0_8_0_context *both = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); - rustsecp256k1zkp_v0_8_0_context *sttc = rustsecp256k1zkp_v0_8_0_context_clone(rustsecp256k1zkp_v0_8_0_context_no_precomp); - - rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening s2c_opening; - rustsecp256k1zkp_v0_8_0_ecdsa_signature sig; + rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening s2c_opening; + rustsecp256k1zkp_v0_10_0_ecdsa_signature sig; const unsigned char msg[32] = "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"; const unsigned char sec[32] = "ssssssssssssssssssssssssssssssss"; const unsigned char s2c_data[32] = "dddddddddddddddddddddddddddddddd"; const unsigned char hostrand[32] = "hrhrhrhrhrhrhrhrhrhrhrhrhrhrhrhr"; unsigned char hostrand_commitment[32]; - rustsecp256k1zkp_v0_8_0_pubkey pk; - - int32_t ecount; - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(none, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sign, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(vrfy, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(both, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sttc, counting_illegal_callback_fn, &ecount); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pk, sec)); - - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign(both, NULL, &s2c_opening, msg, sec, s2c_data) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign(both, &sig, NULL, msg, sec, s2c_data) == 1); - CHECK(ecount == 1); /* NULL opening is not an API error */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign(both, &sig, &s2c_opening, NULL, sec, s2c_data) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign(both, &sig, &s2c_opening, msg, NULL, s2c_data) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign(both, &sig, &s2c_opening, msg, sec, NULL) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign(none, &sig, &s2c_opening, msg, sec, s2c_data) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign(vrfy, &sig, &s2c_opening, msg, sec, s2c_data) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign(sign, &sig, &s2c_opening, msg, sec, s2c_data) == 1); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign(sttc, &sig, &s2c_opening, msg, sec, s2c_data) == 0); - CHECK(ecount == 5); - - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &sig, msg, &pk) == 1); - - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_verify_commit(both, NULL, s2c_data, &s2c_opening) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_verify_commit(both, &sig, NULL, &s2c_opening) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_verify_commit(both, &sig, s2c_data, NULL) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_verify_commit(none, &sig, s2c_data, &s2c_opening) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_verify_commit(sign, &sig, s2c_data, &s2c_opening) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_verify_commit(vrfy, &sig, s2c_data, &s2c_opening) == 1); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_verify_commit(vrfy, &sig, sec, &s2c_opening) == 0); - CHECK(ecount == 3); /* wrong data is not an API error */ + rustsecp256k1zkp_v0_10_0_pubkey pk; + + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pk, sec)); + + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_s2c_sign(CTX, NULL, &s2c_opening, msg, sec, s2c_data)); + /* NULL opening is not an API error */ + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_sign(CTX, &sig, NULL, msg, sec, s2c_data) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_s2c_sign(CTX, &sig, &s2c_opening, NULL, sec, s2c_data)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_s2c_sign(CTX, &sig, &s2c_opening, msg, NULL, s2c_data)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_s2c_sign(CTX, &sig, &s2c_opening, msg, sec, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_sign(CTX, &sig, &s2c_opening, msg, sec, s2c_data) == 1); + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_ecdsa_s2c_sign(STATIC_CTX, &sig, &s2c_opening, msg, sec, s2c_data)); + + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &sig, msg, &pk) == 1); + + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_s2c_verify_commit(CTX, NULL, s2c_data, &s2c_opening)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_s2c_verify_commit(CTX, &sig, NULL, &s2c_opening)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_s2c_verify_commit(CTX, &sig, s2c_data, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_verify_commit(CTX, &sig, s2c_data, &s2c_opening) == 1); + /* wrong data is not an API error */ + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_verify_commit(CTX, &sig, sec, &s2c_opening) == 0); /* Signing with NULL s2c_opening gives the same result */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign(sign, &sig, NULL, msg, sec, s2c_data) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_verify_commit(vrfy, &sig, s2c_data, &s2c_opening) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_sign(CTX, &sig, NULL, msg, sec, s2c_data) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_verify_commit(CTX, &sig, s2c_data, &s2c_opening) == 1); /* anti-exfil */ - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_host_commit(none, NULL, hostrand) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_host_commit(none, hostrand_commitment, NULL) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_host_commit(none, hostrand_commitment, hostrand) == 1); - CHECK(ecount == 2); - - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_signer_commit(both, NULL, msg, sec, hostrand_commitment) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_signer_commit(both, &s2c_opening, NULL, sec, hostrand_commitment) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_signer_commit(both, &s2c_opening, msg, NULL, hostrand_commitment) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_signer_commit(both, &s2c_opening, msg, sec, NULL) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_signer_commit(none, &s2c_opening, msg, sec, hostrand_commitment) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_signer_commit(vrfy, &s2c_opening, msg, sec, hostrand_commitment) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_signer_commit(sign, &s2c_opening, msg, sec, hostrand_commitment) == 1); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_signer_commit(sttc, &s2c_opening, msg, sec, hostrand_commitment) == 0); - CHECK(ecount == 5); - - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_sign(both, NULL, msg, sec, hostrand) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_sign(both, &sig, NULL, sec, hostrand) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_sign(both, &sig, msg, NULL, hostrand) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_sign(both, &sig, msg, sec, NULL) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_sign(none, &sig, msg, sec, hostrand) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_sign(vrfy, &sig, msg, sec, hostrand) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_sign(both, &sig, msg, sec, hostrand) == 1); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_sign(sttc, &sig, msg, sec, hostrand) == 0); - CHECK(ecount == 5); - - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_host_verify(both, NULL, msg, &pk, hostrand, &s2c_opening) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_host_verify(both, &sig, NULL, &pk, hostrand, &s2c_opening) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_host_verify(both, &sig, msg, NULL, hostrand, &s2c_opening) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_host_verify(both, &sig, msg, &pk, NULL, &s2c_opening) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_host_verify(both, &sig, msg, &pk, hostrand, NULL) == 0); - CHECK(ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_host_verify(none, &sig, msg, &pk, hostrand, &s2c_opening) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_host_verify(sign, &sig, msg, &pk, hostrand, &s2c_opening) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_host_verify(vrfy, &sig, msg, &pk, hostrand, &s2c_opening) == 1); - CHECK(ecount == 5); - - rustsecp256k1zkp_v0_8_0_context_destroy(both); - rustsecp256k1zkp_v0_8_0_context_destroy(vrfy); - rustsecp256k1zkp_v0_8_0_context_destroy(sign); - rustsecp256k1zkp_v0_8_0_context_destroy(none); - rustsecp256k1zkp_v0_8_0_context_destroy(sttc); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_anti_exfil_host_commit(CTX, NULL, hostrand)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_anti_exfil_host_commit(CTX, hostrand_commitment, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_anti_exfil_host_commit(CTX, hostrand_commitment, hostrand) == 1); + + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_anti_exfil_signer_commit(CTX, NULL, msg, sec, hostrand_commitment)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_anti_exfil_signer_commit(CTX, &s2c_opening, NULL, sec, hostrand_commitment)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_anti_exfil_signer_commit(CTX, &s2c_opening, msg, NULL, hostrand_commitment)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_anti_exfil_signer_commit(CTX, &s2c_opening, msg, sec, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_anti_exfil_signer_commit(CTX, &s2c_opening, msg, sec, hostrand_commitment) == 1); + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_ecdsa_anti_exfil_signer_commit(STATIC_CTX, &s2c_opening, msg, sec, hostrand_commitment)); + + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_anti_exfil_sign(CTX, NULL, msg, sec, hostrand)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_anti_exfil_sign(CTX, &sig, NULL, sec, hostrand)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_anti_exfil_sign(CTX, &sig, msg, NULL, hostrand)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_anti_exfil_sign(CTX, &sig, msg, sec, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_anti_exfil_sign(CTX, &sig, msg, sec, hostrand) == 1); + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_anti_exfil_sign(STATIC_CTX, &sig, msg, sec, hostrand)); + + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_anti_exfil_host_verify(CTX, NULL, msg, &pk, hostrand, &s2c_opening)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_anti_exfil_host_verify(CTX, &sig, NULL, &pk, hostrand, &s2c_opening)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_anti_exfil_host_verify(CTX, &sig, msg, NULL, hostrand, &s2c_opening)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_anti_exfil_host_verify(CTX, &sig, msg, &pk, NULL, &s2c_opening)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_anti_exfil_host_verify(CTX, &sig, msg, &pk, hostrand, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_anti_exfil_host_verify(CTX, &sig, msg, &pk, hostrand, &s2c_opening) == 1); } /* When using sign-to-contract commitments, the nonce function is fixed, so we can use fixtures to test. */ @@ -249,65 +171,65 @@ static void test_ecdsa_s2c_fixed_vectors(void) { size_t i; for (i = 0; i < sizeof(ecdsa_s2c_tests) / sizeof(ecdsa_s2c_tests[0]); i++) { - rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening s2c_opening; + rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening s2c_opening; unsigned char opening_ser[33]; const ecdsa_s2c_test *test = &ecdsa_s2c_tests[i]; - rustsecp256k1zkp_v0_8_0_ecdsa_signature signature; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign(ctx, &signature, &s2c_opening, message, privkey, test->s2c_data) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_serialize(ctx, opening_ser, &s2c_opening) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(test->expected_s2c_opening, opening_ser, sizeof(opening_ser)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_verify_commit(ctx, &signature, test->s2c_data, &s2c_opening) == 1); + rustsecp256k1zkp_v0_10_0_ecdsa_signature signature; + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_sign(CTX, &signature, &s2c_opening, message, privkey, test->s2c_data) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_serialize(CTX, opening_ser, &s2c_opening) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(test->expected_s2c_opening, opening_ser, sizeof(opening_ser)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_verify_commit(CTX, &signature, test->s2c_data, &s2c_opening) == 1); } } static void test_ecdsa_s2c_sign_verify(void) { unsigned char privkey[32]; - rustsecp256k1zkp_v0_8_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; unsigned char message[32]; unsigned char noncedata[32]; unsigned char s2c_data[32]; unsigned char s2c_data2[32]; - rustsecp256k1zkp_v0_8_0_ecdsa_signature signature; - rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening s2c_opening; + rustsecp256k1zkp_v0_10_0_ecdsa_signature signature; + rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening s2c_opening; /* Generate a random key, message, noncedata and s2c_data. */ { - rustsecp256k1zkp_v0_8_0_scalar key; + rustsecp256k1zkp_v0_10_0_scalar key; random_scalar_order_test(&key); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(privkey, &key); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey, privkey) == 1); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(privkey, &key); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey, privkey) == 1); - rustsecp256k1zkp_v0_8_0_testrand256_test(message); - rustsecp256k1zkp_v0_8_0_testrand256_test(noncedata); - rustsecp256k1zkp_v0_8_0_testrand256_test(s2c_data); - rustsecp256k1zkp_v0_8_0_testrand256_test(s2c_data2); + rustsecp256k1zkp_v0_10_0_testrand256_test(message); + rustsecp256k1zkp_v0_10_0_testrand256_test(noncedata); + rustsecp256k1zkp_v0_10_0_testrand256_test(s2c_data); + rustsecp256k1zkp_v0_10_0_testrand256_test(s2c_data2); } { /* invalid privkeys */ unsigned char zero_privkey[32] = {0}; unsigned char overflow_privkey[32] = "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign(ctx, &signature, NULL, message, zero_privkey, s2c_data) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign(ctx, &signature, NULL, message, overflow_privkey, s2c_data) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_sign(CTX, &signature, NULL, message, zero_privkey, s2c_data) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_sign(CTX, &signature, NULL, message, overflow_privkey, s2c_data) == 0); } /* Check that the sign-to-contract signature is valid, with s2c_data. Also check the commitment. */ { - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign(ctx, &signature, &s2c_opening, message, privkey, s2c_data) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &signature, message, &pubkey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_verify_commit(ctx, &signature, s2c_data, &s2c_opening) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_sign(CTX, &signature, &s2c_opening, message, privkey, s2c_data) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &signature, message, &pubkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_verify_commit(CTX, &signature, s2c_data, &s2c_opening) == 1); } /* Check that an invalid commitment does not verify */ { unsigned char sigbytes[64]; size_t i; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign(ctx, &signature, &s2c_opening, message, privkey, s2c_data) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &signature, message, &pubkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_sign(CTX, &signature, &s2c_opening, message, privkey, s2c_data) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &signature, message, &pubkey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_compact(ctx, sigbytes, &signature) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_compact(CTX, sigbytes, &signature) == 1); for(i = 0; i < 32; i++) { /* change one byte */ sigbytes[i] = (((int)sigbytes[i]) + 1) % 256; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_compact(ctx, &signature, sigbytes) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_verify_commit(ctx, &signature, s2c_data, &s2c_opening) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_compact(CTX, &signature, sigbytes) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_verify_commit(CTX, &signature, s2c_data, &s2c_opening) == 0); /* revert */ sigbytes[i] = (((int)sigbytes[i]) + 255) % 256; } @@ -326,12 +248,12 @@ static void test_ecdsa_anti_exfil_signer_commit(void) { }; /* Check that original pubnonce is derived from s2c_data */ for (i = 0; i < sizeof(ecdsa_s2c_tests) / sizeof(ecdsa_s2c_tests[0]); i++) { - rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening s2c_opening; + rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening s2c_opening; unsigned char buf[33]; const ecdsa_s2c_test *test = &ecdsa_s2c_tests[i]; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_signer_commit(ctx, &s2c_opening, message, privkey, test->s2c_data) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_serialize(ctx, buf, &s2c_opening) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(test->expected_s2c_exfil_opening, buf, sizeof(buf)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_anti_exfil_signer_commit(CTX, &s2c_opening, message, privkey, test->s2c_data) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_serialize(CTX, buf, &s2c_opening) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(test->expected_s2c_exfil_opening, buf, sizeof(buf)) == 0); } } @@ -341,63 +263,63 @@ static void test_ecdsa_anti_exfil(void) { unsigned char host_msg[32]; unsigned char host_commitment[32]; unsigned char host_nonce_contribution[32]; - rustsecp256k1zkp_v0_8_0_pubkey signer_pubkey; - rustsecp256k1zkp_v0_8_0_ecdsa_signature signature; - rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening s2c_opening; + rustsecp256k1zkp_v0_10_0_pubkey signer_pubkey; + rustsecp256k1zkp_v0_10_0_ecdsa_signature signature; + rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening s2c_opening; /* Generate a random key, message. */ { - rustsecp256k1zkp_v0_8_0_scalar key; + rustsecp256k1zkp_v0_10_0_scalar key; random_scalar_order_test(&key); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(signer_privkey, &key); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &signer_pubkey, signer_privkey) == 1); - rustsecp256k1zkp_v0_8_0_testrand256_test(host_msg); - rustsecp256k1zkp_v0_8_0_testrand256_test(host_nonce_contribution); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(signer_privkey, &key); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &signer_pubkey, signer_privkey) == 1); + rustsecp256k1zkp_v0_10_0_testrand256_test(host_msg); + rustsecp256k1zkp_v0_10_0_testrand256_test(host_nonce_contribution); } /* Protocol step 1. */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_host_commit(ctx, host_commitment, host_nonce_contribution) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_anti_exfil_host_commit(CTX, host_commitment, host_nonce_contribution) == 1); /* Protocol step 2. */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_signer_commit(ctx, &s2c_opening, host_msg, signer_privkey, host_commitment) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_anti_exfil_signer_commit(CTX, &s2c_opening, host_msg, signer_privkey, host_commitment) == 1); /* Protocol step 3: host_nonce_contribution send to signer to be used in step 4. */ /* Protocol step 4. */ - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_sign(ctx, &signature, host_msg, signer_privkey, host_nonce_contribution) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_anti_exfil_sign(CTX, &signature, host_msg, signer_privkey, host_nonce_contribution) == 1); /* Protocol step 5. */ - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_host_verify(ctx, &signature, host_msg, &signer_pubkey, host_nonce_contribution, &s2c_opening) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_anti_exfil_host_verify(CTX, &signature, host_msg, &signer_pubkey, host_nonce_contribution, &s2c_opening) == 1); /* Protocol step 5 (explicitly) */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_verify_commit(ctx, &signature, host_nonce_contribution, &s2c_opening) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &signature, host_msg, &signer_pubkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_verify_commit(CTX, &signature, host_nonce_contribution, &s2c_opening) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &signature, host_msg, &signer_pubkey) == 1); { /* host_verify: commitment does not match */ unsigned char sigbytes[64]; size_t i; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_compact(ctx, sigbytes, &signature) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_compact(CTX, sigbytes, &signature) == 1); for(i = 0; i < 32; i++) { /* change one byte */ sigbytes[i] += 1; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_compact(ctx, &signature, sigbytes) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_verify_commit(ctx, &signature, host_nonce_contribution, &s2c_opening) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_host_verify(ctx, &signature, host_msg, &signer_pubkey, host_nonce_contribution, &s2c_opening) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_compact(CTX, &signature, sigbytes) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_verify_commit(CTX, &signature, host_nonce_contribution, &s2c_opening) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_anti_exfil_host_verify(CTX, &signature, host_msg, &signer_pubkey, host_nonce_contribution, &s2c_opening) == 0); /* revert */ sigbytes[i] -= 1; } - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_compact(ctx, &signature, sigbytes) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_compact(CTX, &signature, sigbytes) == 1); } { /* host_verify: message does not match */ unsigned char bad_msg[32]; - rustsecp256k1zkp_v0_8_0_testrand256_test(bad_msg); - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_host_verify(ctx, &signature, host_msg, &signer_pubkey, host_nonce_contribution, &s2c_opening) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_host_verify(ctx, &signature, bad_msg, &signer_pubkey, host_nonce_contribution, &s2c_opening) == 0); + rustsecp256k1zkp_v0_10_0_testrand256_test(bad_msg); + CHECK(rustsecp256k1zkp_v0_10_0_anti_exfil_host_verify(CTX, &signature, host_msg, &signer_pubkey, host_nonce_contribution, &s2c_opening) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_anti_exfil_host_verify(CTX, &signature, bad_msg, &signer_pubkey, host_nonce_contribution, &s2c_opening) == 0); } { /* s2c_sign: host provided data that didn't match commitment */ - rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening orig_opening = s2c_opening; + rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening orig_opening = s2c_opening; unsigned char bad_nonce_contribution[32] = { 1, 2, 3, 4 }; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign(ctx, &signature, &s2c_opening, host_msg, signer_privkey, bad_nonce_contribution) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_sign(CTX, &signature, &s2c_opening, host_msg, signer_privkey, bad_nonce_contribution) == 1); /* good signature but the opening (original public nonce does not match the original */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &signature, host_msg, &signer_pubkey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_host_verify(ctx, &signature, host_msg, &signer_pubkey, host_nonce_contribution, &s2c_opening) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_anti_exfil_host_verify(ctx, &signature, host_msg, &signer_pubkey, bad_nonce_contribution, &s2c_opening) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&s2c_opening, &orig_opening, sizeof(s2c_opening)) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &signature, host_msg, &signer_pubkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_anti_exfil_host_verify(CTX, &signature, host_msg, &signer_pubkey, host_nonce_contribution, &s2c_opening) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_anti_exfil_host_verify(CTX, &signature, host_msg, &signer_pubkey, bad_nonce_contribution, &s2c_opening) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&s2c_opening, &orig_opening, sizeof(s2c_opening)) != 0); } } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ellswift/Makefile.am.include b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ellswift/Makefile.am.include new file mode 100644 index 00000000..04e1c1cf --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ellswift/Makefile.am.include @@ -0,0 +1,5 @@ +include_HEADERS += include/rustsecp256k1zkp_v0_10_0_ellswift.h +noinst_HEADERS += src/modules/ellswift/bench_impl.h +noinst_HEADERS += src/modules/ellswift/main_impl.h +noinst_HEADERS += src/modules/ellswift/tests_impl.h +noinst_HEADERS += src/modules/ellswift/tests_exhaustive_impl.h diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ellswift/bench_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ellswift/bench_impl.h new file mode 100644 index 00000000..bb2b5689 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ellswift/bench_impl.h @@ -0,0 +1,106 @@ +/*********************************************************************** + * Distributed under the MIT software license, see the accompanying * + * file COPYING or https://www.opensource.org/licenses/mit-license.php.* + ***********************************************************************/ + +#ifndef SECP256K1_MODULE_ELLSWIFT_BENCH_H +#define SECP256K1_MODULE_ELLSWIFT_BENCH_H + +#include "../../../include/secp256k1_ellswift.h" + +typedef struct { + rustsecp256k1zkp_v0_10_0_context *ctx; + rustsecp256k1zkp_v0_10_0_pubkey point[256]; + unsigned char rnd64[64]; +} bench_ellswift_data; + +static void bench_ellswift_setup(void *arg) { + int i; + bench_ellswift_data *data = (bench_ellswift_data*)arg; + static const unsigned char init[64] = { + 0x78, 0x1f, 0xb7, 0xd4, 0x67, 0x7f, 0x08, 0x68, + 0xdb, 0xe3, 0x1d, 0x7f, 0x1b, 0xb0, 0xf6, 0x9e, + 0x0a, 0x64, 0xca, 0x32, 0x9e, 0xc6, 0x20, 0x79, + 0x03, 0xf3, 0xd0, 0x46, 0x7a, 0x0f, 0xd2, 0x21, + 0xb0, 0x2c, 0x46, 0xd8, 0xba, 0xca, 0x26, 0x4f, + 0x8f, 0x8c, 0xd4, 0xdd, 0x2d, 0x04, 0xbe, 0x30, + 0x48, 0x51, 0x1e, 0xd4, 0x16, 0xfd, 0x42, 0x85, + 0x62, 0xc9, 0x02, 0xf9, 0x89, 0x84, 0xff, 0xdc + }; + memcpy(data->rnd64, init, 64); + for (i = 0; i < 256; ++i) { + int j; + CHECK(rustsecp256k1zkp_v0_10_0_ellswift_decode(data->ctx, &data->point[i], data->rnd64)); + for (j = 0; j < 64; ++j) { + data->rnd64[j] += 1; + } + } + CHECK(rustsecp256k1zkp_v0_10_0_ellswift_encode(data->ctx, data->rnd64, &data->point[255], init + 16)); +} + +static void bench_ellswift_encode(void *arg, int iters) { + int i; + bench_ellswift_data *data = (bench_ellswift_data*)arg; + + for (i = 0; i < iters; i++) { + CHECK(rustsecp256k1zkp_v0_10_0_ellswift_encode(data->ctx, data->rnd64, &data->point[i & 255], data->rnd64 + 16)); + } +} + +static void bench_ellswift_create(void *arg, int iters) { + int i; + bench_ellswift_data *data = (bench_ellswift_data*)arg; + + for (i = 0; i < iters; i++) { + unsigned char buf[64]; + CHECK(rustsecp256k1zkp_v0_10_0_ellswift_create(data->ctx, buf, data->rnd64, data->rnd64 + 32)); + memcpy(data->rnd64, buf, 64); + } +} + +static void bench_ellswift_decode(void *arg, int iters) { + int i; + rustsecp256k1zkp_v0_10_0_pubkey out; + size_t len; + bench_ellswift_data *data = (bench_ellswift_data*)arg; + + for (i = 0; i < iters; i++) { + CHECK(rustsecp256k1zkp_v0_10_0_ellswift_decode(data->ctx, &out, data->rnd64) == 1); + len = 33; + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(data->ctx, data->rnd64 + (i % 32), &len, &out, SECP256K1_EC_COMPRESSED)); + } +} + +static void bench_ellswift_xdh(void *arg, int iters) { + int i; + bench_ellswift_data *data = (bench_ellswift_data*)arg; + + for (i = 0; i < iters; i++) { + int party = i & 1; + CHECK(rustsecp256k1zkp_v0_10_0_ellswift_xdh(data->ctx, + data->rnd64 + (i % 33), + data->rnd64, + data->rnd64, + data->rnd64 + ((i + 16) % 33), + party, + rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function_bip324, + NULL) == 1); + } +} + +void run_ellswift_bench(int iters, int argc, char **argv) { + bench_ellswift_data data; + int d = argc == 1; + + /* create a context with signing capabilities */ + data.ctx = rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_CONTEXT_NONE); + + if (d || have_flag(argc, argv, "ellswift") || have_flag(argc, argv, "encode") || have_flag(argc, argv, "ellswift_encode")) run_benchmark("ellswift_encode", bench_ellswift_encode, bench_ellswift_setup, NULL, &data, 10, iters); + if (d || have_flag(argc, argv, "ellswift") || have_flag(argc, argv, "decode") || have_flag(argc, argv, "ellswift_decode")) run_benchmark("ellswift_decode", bench_ellswift_decode, bench_ellswift_setup, NULL, &data, 10, iters); + if (d || have_flag(argc, argv, "ellswift") || have_flag(argc, argv, "keygen") || have_flag(argc, argv, "ellswift_keygen")) run_benchmark("ellswift_keygen", bench_ellswift_create, bench_ellswift_setup, NULL, &data, 10, iters); + if (d || have_flag(argc, argv, "ellswift") || have_flag(argc, argv, "ecdh") || have_flag(argc, argv, "ellswift_ecdh")) run_benchmark("ellswift_ecdh", bench_ellswift_xdh, bench_ellswift_setup, NULL, &data, 10, iters); + + rustsecp256k1zkp_v0_10_0_context_destroy(data.ctx); +} + +#endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ellswift/main_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ellswift/main_impl.h new file mode 100644 index 00000000..a55996f4 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ellswift/main_impl.h @@ -0,0 +1,590 @@ +/*********************************************************************** + * Distributed under the MIT software license, see the accompanying * + * file COPYING or https://www.opensource.org/licenses/mit-license.php.* + ***********************************************************************/ + +#ifndef SECP256K1_MODULE_ELLSWIFT_MAIN_H +#define SECP256K1_MODULE_ELLSWIFT_MAIN_H + +#include "../../../include/secp256k1.h" +#include "../../../include/secp256k1_ellswift.h" +#include "../../eckey.h" +#include "../../hash.h" + +/** c1 = (sqrt(-3)-1)/2 */ +static const rustsecp256k1zkp_v0_10_0_fe rustsecp256k1zkp_v0_10_0_ellswift_c1 = SECP256K1_FE_CONST(0x851695d4, 0x9a83f8ef, 0x919bb861, 0x53cbcb16, 0x630fb68a, 0xed0a766a, 0x3ec693d6, 0x8e6afa40); +/** c2 = (-sqrt(-3)-1)/2 = -(c1+1) */ +static const rustsecp256k1zkp_v0_10_0_fe rustsecp256k1zkp_v0_10_0_ellswift_c2 = SECP256K1_FE_CONST(0x7ae96a2b, 0x657c0710, 0x6e64479e, 0xac3434e9, 0x9cf04975, 0x12f58995, 0xc1396c28, 0x719501ee); +/** c3 = (-sqrt(-3)+1)/2 = -c1 = c2+1 */ +static const rustsecp256k1zkp_v0_10_0_fe rustsecp256k1zkp_v0_10_0_ellswift_c3 = SECP256K1_FE_CONST(0x7ae96a2b, 0x657c0710, 0x6e64479e, 0xac3434e9, 0x9cf04975, 0x12f58995, 0xc1396c28, 0x719501ef); +/** c4 = (sqrt(-3)+1)/2 = -c2 = c1+1 */ +static const rustsecp256k1zkp_v0_10_0_fe rustsecp256k1zkp_v0_10_0_ellswift_c4 = SECP256K1_FE_CONST(0x851695d4, 0x9a83f8ef, 0x919bb861, 0x53cbcb16, 0x630fb68a, 0xed0a766a, 0x3ec693d6, 0x8e6afa41); + +/** Decode ElligatorSwift encoding (u, t) to a fraction xn/xd representing a curve X coordinate. */ +static void rustsecp256k1zkp_v0_10_0_ellswift_xswiftec_frac_var(rustsecp256k1zkp_v0_10_0_fe *xn, rustsecp256k1zkp_v0_10_0_fe *xd, const rustsecp256k1zkp_v0_10_0_fe *u, const rustsecp256k1zkp_v0_10_0_fe *t) { + /* The implemented algorithm is the following (all operations in GF(p)): + * + * - Let c0 = sqrt(-3) = 0xa2d2ba93507f1df233770c2a797962cc61f6d15da14ecd47d8d27ae1cd5f852. + * - If u = 0, set u = 1. + * - If t = 0, set t = 1. + * - If u^3+7+t^2 = 0, set t = 2*t. + * - Let X = (u^3+7-t^2)/(2*t). + * - Let Y = (X+t)/(c0*u). + * - If x3 = u+4*Y^2 is a valid x coordinate, return it. + * - If x2 = (-X/Y-u)/2 is a valid x coordinate, return it. + * - Return x1 = (X/Y-u)/2 (which is now guaranteed to be a valid x coordinate). + * + * Introducing s=t^2, g=u^3+7, and simplifying x1=-(x2+u) we get: + * + * - Let c0 = ... + * - If u = 0, set u = 1. + * - If t = 0, set t = 1. + * - Let s = t^2 + * - Let g = u^3+7 + * - If g+s = 0, set t = 2*t, s = 4*s + * - Let X = (g-s)/(2*t). + * - Let Y = (X+t)/(c0*u) = (g+s)/(2*c0*t*u). + * - If x3 = u+4*Y^2 is a valid x coordinate, return it. + * - If x2 = (-X/Y-u)/2 is a valid x coordinate, return it. + * - Return x1 = -(x2+u). + * + * Now substitute Y^2 = -(g+s)^2/(12*s*u^2) and X/Y = c0*u*(g-s)/(g+s). This + * means X and Y do not need to be evaluated explicitly anymore. + * + * - ... + * - If g+s = 0, set s = 4*s. + * - If x3 = u-(g+s)^2/(3*s*u^2) is a valid x coordinate, return it. + * - If x2 = (-c0*u*(g-s)/(g+s)-u)/2 is a valid x coordinate, return it. + * - Return x1 = -(x2+u). + * + * Simplifying x2 using 2 additional constants: + * + * - Let c1 = (c0-1)/2 = 0x851695d49a83f8ef919bb86153cbcb16630fb68aed0a766a3ec693d68e6afa40. + * - Let c2 = (-c0-1)/2 = 0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee. + * - ... + * - If x2 = u*(c1*s+c2*g)/(g+s) is a valid x coordinate, return it. + * - ... + * + * Writing x3 as a fraction: + * + * - ... + * - If x3 = (3*s*u^3-(g+s)^2)/(3*s*u^2) ... + * - ... + + * Overall, we get: + * + * - Let c1 = 0x851695d49a83f8ef919bb86153cbcb16630fb68aed0a766a3ec693d68e6afa40. + * - Let c2 = 0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee. + * - If u = 0, set u = 1. + * - If t = 0, set s = 1, else set s = t^2. + * - Let g = u^3+7. + * - If g+s = 0, set s = 4*s. + * - If x3 = (3*s*u^3-(g+s)^2)/(3*s*u^2) is a valid x coordinate, return it. + * - If x2 = u*(c1*s+c2*g)/(g+s) is a valid x coordinate, return it. + * - Return x1 = -(x2+u). + */ + rustsecp256k1zkp_v0_10_0_fe u1, s, g, p, d, n, l; + u1 = *u; + if (EXPECT(rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(&u1), 0)) u1 = rustsecp256k1zkp_v0_10_0_fe_one; + rustsecp256k1zkp_v0_10_0_fe_sqr(&s, t); + if (EXPECT(rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(t), 0)) s = rustsecp256k1zkp_v0_10_0_fe_one; + rustsecp256k1zkp_v0_10_0_fe_sqr(&l, &u1); /* l = u^2 */ + rustsecp256k1zkp_v0_10_0_fe_mul(&g, &l, &u1); /* g = u^3 */ + rustsecp256k1zkp_v0_10_0_fe_add_int(&g, SECP256K1_B); /* g = u^3 + 7 */ + p = g; /* p = g */ + rustsecp256k1zkp_v0_10_0_fe_add(&p, &s); /* p = g+s */ + if (EXPECT(rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(&p), 0)) { + rustsecp256k1zkp_v0_10_0_fe_mul_int(&s, 4); + /* Recompute p = g+s */ + p = g; /* p = g */ + rustsecp256k1zkp_v0_10_0_fe_add(&p, &s); /* p = g+s */ + } + rustsecp256k1zkp_v0_10_0_fe_mul(&d, &s, &l); /* d = s*u^2 */ + rustsecp256k1zkp_v0_10_0_fe_mul_int(&d, 3); /* d = 3*s*u^2 */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&l, &p); /* l = (g+s)^2 */ + rustsecp256k1zkp_v0_10_0_fe_negate(&l, &l, 1); /* l = -(g+s)^2 */ + rustsecp256k1zkp_v0_10_0_fe_mul(&n, &d, &u1); /* n = 3*s*u^3 */ + rustsecp256k1zkp_v0_10_0_fe_add(&n, &l); /* n = 3*s*u^3-(g+s)^2 */ + if (rustsecp256k1zkp_v0_10_0_ge_x_frac_on_curve_var(&n, &d)) { + /* Return x3 = n/d = (3*s*u^3-(g+s)^2)/(3*s*u^2) */ + *xn = n; + *xd = d; + return; + } + *xd = p; + rustsecp256k1zkp_v0_10_0_fe_mul(&l, &rustsecp256k1zkp_v0_10_0_ellswift_c1, &s); /* l = c1*s */ + rustsecp256k1zkp_v0_10_0_fe_mul(&n, &rustsecp256k1zkp_v0_10_0_ellswift_c2, &g); /* n = c2*g */ + rustsecp256k1zkp_v0_10_0_fe_add(&n, &l); /* n = c1*s+c2*g */ + rustsecp256k1zkp_v0_10_0_fe_mul(&n, &n, &u1); /* n = u*(c1*s+c2*g) */ + /* Possible optimization: in the invocation below, p^2 = (g+s)^2 is computed, + * which we already have computed above. This could be deduplicated. */ + if (rustsecp256k1zkp_v0_10_0_ge_x_frac_on_curve_var(&n, &p)) { + /* Return x2 = n/p = u*(c1*s+c2*g)/(g+s) */ + *xn = n; + return; + } + rustsecp256k1zkp_v0_10_0_fe_mul(&l, &p, &u1); /* l = u*(g+s) */ + rustsecp256k1zkp_v0_10_0_fe_add(&n, &l); /* n = u*(c1*s+c2*g)+u*(g+s) */ + rustsecp256k1zkp_v0_10_0_fe_negate(xn, &n, 2); /* n = -u*(c1*s+c2*g)-u*(g+s) */ + + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_ge_x_frac_on_curve_var(xn, &p)); + /* Return x3 = n/p = -(u*(c1*s+c2*g)/(g+s)+u) */ +} + +/** Decode ElligatorSwift encoding (u, t) to X coordinate. */ +static void rustsecp256k1zkp_v0_10_0_ellswift_xswiftec_var(rustsecp256k1zkp_v0_10_0_fe *x, const rustsecp256k1zkp_v0_10_0_fe *u, const rustsecp256k1zkp_v0_10_0_fe *t) { + rustsecp256k1zkp_v0_10_0_fe xn, xd; + rustsecp256k1zkp_v0_10_0_ellswift_xswiftec_frac_var(&xn, &xd, u, t); + rustsecp256k1zkp_v0_10_0_fe_inv_var(&xd, &xd); + rustsecp256k1zkp_v0_10_0_fe_mul(x, &xn, &xd); +} + +/** Decode ElligatorSwift encoding (u, t) to point P. */ +static void rustsecp256k1zkp_v0_10_0_ellswift_swiftec_var(rustsecp256k1zkp_v0_10_0_ge *p, const rustsecp256k1zkp_v0_10_0_fe *u, const rustsecp256k1zkp_v0_10_0_fe *t) { + rustsecp256k1zkp_v0_10_0_fe x; + rustsecp256k1zkp_v0_10_0_ellswift_xswiftec_var(&x, u, t); + rustsecp256k1zkp_v0_10_0_ge_set_xo_var(p, &x, rustsecp256k1zkp_v0_10_0_fe_is_odd(t)); +} + +/* Try to complete an ElligatorSwift encoding (u, t) for X coordinate x, given u and x. + * + * There may be up to 8 distinct t values such that (u, t) decodes back to x, but also + * fewer, or none at all. Each such partial inverse can be accessed individually using a + * distinct input argument c (in range 0-7), and some or all of these may return failure. + * The following guarantees exist: + * - Given (x, u), no two distinct c values give the same successful result t. + * - Every successful result maps back to x through rustsecp256k1zkp_v0_10_0_ellswift_xswiftec_var. + * - Given (x, u), all t values that map back to x can be reached by combining the + * successful results from this function over all c values, with the exception of: + * - this function cannot be called with u=0 + * - no result with t=0 will be returned + * - no result for which u^3 + t^2 + 7 = 0 will be returned. + * + * The rather unusual encoding of bits in c (a large "if" based on the middle bit, and then + * using the low and high bits to pick signs of square roots) is to match the paper's + * encoding more closely: c=0 through c=3 match branches 1..4 in the paper, while c=4 through + * c=7 are copies of those with an additional negation of sqrt(w). + */ +static int rustsecp256k1zkp_v0_10_0_ellswift_xswiftec_inv_var(rustsecp256k1zkp_v0_10_0_fe *t, const rustsecp256k1zkp_v0_10_0_fe *x_in, const rustsecp256k1zkp_v0_10_0_fe *u_in, int c) { + /* The implemented algorithm is this (all arithmetic, except involving c, is mod p): + * + * - If (c & 2) = 0: + * - If (-x-u) is a valid X coordinate, fail. + * - Let s=-(u^3+7)/(u^2+u*x+x^2). + * - If s is not square, fail. + * - Let v=x. + * - If (c & 2) = 2: + * - Let s=x-u. + * - If s is not square, fail. + * - Let r=sqrt(-s*(4*(u^3+7)+3*u^2*s)); fail if it doesn't exist. + * - If (c & 1) = 1 and r = 0, fail. + * - If s=0, fail. + * - Let v=(r/s-u)/2. + * - Let w=sqrt(s). + * - If (c & 5) = 0: return -w*(c3*u + v). + * - If (c & 5) = 1: return w*(c4*u + v). + * - If (c & 5) = 4: return w*(c3*u + v). + * - If (c & 5) = 5: return -w*(c4*u + v). + */ + rustsecp256k1zkp_v0_10_0_fe x = *x_in, u = *u_in, g, v, s, m, r, q; + int ret; + + rustsecp256k1zkp_v0_10_0_fe_normalize_weak(&x); + rustsecp256k1zkp_v0_10_0_fe_normalize_weak(&u); + + VERIFY_CHECK(c >= 0 && c < 8); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_ge_x_on_curve_var(&x)); + + if (!(c & 2)) { + /* c is in {0, 1, 4, 5}. In this case we look for an inverse under the x1 (if c=0 or + * c=4) formula, or x2 (if c=1 or c=5) formula. */ + + /* If -u-x is a valid X coordinate, fail. This would yield an encoding that roundtrips + * back under the x3 formula instead (which has priority over x1 and x2, so the decoding + * would not match x). */ + m = x; /* m = x */ + rustsecp256k1zkp_v0_10_0_fe_add(&m, &u); /* m = u+x */ + rustsecp256k1zkp_v0_10_0_fe_negate(&m, &m, 2); /* m = -u-x */ + /* Test if (-u-x) is a valid X coordinate. If so, fail. */ + if (rustsecp256k1zkp_v0_10_0_ge_x_on_curve_var(&m)) return 0; + + /* Let s = -(u^3 + 7)/(u^2 + u*x + x^2) [first part] */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&s, &m); /* s = (u+x)^2 */ + rustsecp256k1zkp_v0_10_0_fe_negate(&s, &s, 1); /* s = -(u+x)^2 */ + rustsecp256k1zkp_v0_10_0_fe_mul(&m, &u, &x); /* m = u*x */ + rustsecp256k1zkp_v0_10_0_fe_add(&s, &m); /* s = -(u^2 + u*x + x^2) */ + + /* Note that at this point, s = 0 is impossible. If it were the case: + * s = -(u^2 + u*x + x^2) = 0 + * => u^2 + u*x + x^2 = 0 + * => (u + 2*x) * (u^2 + u*x + x^2) = 0 + * => 2*x^3 + 3*x^2*u + 3*x*u^2 + u^3 = 0 + * => (x + u)^3 + x^3 = 0 + * => x^3 = -(x + u)^3 + * => x^3 + B = (-u - x)^3 + B + * + * However, we know x^3 + B is square (because x is on the curve) and + * that (-u-x)^3 + B is not square (the rustsecp256k1zkp_v0_10_0_ge_x_on_curve_var(&m) + * test above would have failed). This is a contradiction, and thus the + * assumption s=0 is false. */ + VERIFY_CHECK(!rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(&s)); + + /* If s is not square, fail. We have not fully computed s yet, but s is square iff + * -(u^3+7)*(u^2+u*x+x^2) is square (because a/b is square iff a*b is square and b is + * nonzero). */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&g, &u); /* g = u^2 */ + rustsecp256k1zkp_v0_10_0_fe_mul(&g, &g, &u); /* g = u^3 */ + rustsecp256k1zkp_v0_10_0_fe_add_int(&g, SECP256K1_B); /* g = u^3+7 */ + rustsecp256k1zkp_v0_10_0_fe_mul(&m, &s, &g); /* m = -(u^3 + 7)*(u^2 + u*x + x^2) */ + if (!rustsecp256k1zkp_v0_10_0_fe_is_square_var(&m)) return 0; + + /* Let s = -(u^3 + 7)/(u^2 + u*x + x^2) [second part] */ + rustsecp256k1zkp_v0_10_0_fe_inv_var(&s, &s); /* s = -1/(u^2 + u*x + x^2) [no div by 0] */ + rustsecp256k1zkp_v0_10_0_fe_mul(&s, &s, &g); /* s = -(u^3 + 7)/(u^2 + u*x + x^2) */ + + /* Let v = x. */ + v = x; + } else { + /* c is in {2, 3, 6, 7}. In this case we look for an inverse under the x3 formula. */ + + /* Let s = x-u. */ + rustsecp256k1zkp_v0_10_0_fe_negate(&m, &u, 1); /* m = -u */ + s = m; /* s = -u */ + rustsecp256k1zkp_v0_10_0_fe_add(&s, &x); /* s = x-u */ + + /* If s is not square, fail. */ + if (!rustsecp256k1zkp_v0_10_0_fe_is_square_var(&s)) return 0; + + /* Let r = sqrt(-s*(4*(u^3+7)+3*u^2*s)); fail if it doesn't exist. */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&g, &u); /* g = u^2 */ + rustsecp256k1zkp_v0_10_0_fe_mul(&q, &s, &g); /* q = s*u^2 */ + rustsecp256k1zkp_v0_10_0_fe_mul_int(&q, 3); /* q = 3*s*u^2 */ + rustsecp256k1zkp_v0_10_0_fe_mul(&g, &g, &u); /* g = u^3 */ + rustsecp256k1zkp_v0_10_0_fe_mul_int(&g, 4); /* g = 4*u^3 */ + rustsecp256k1zkp_v0_10_0_fe_add_int(&g, 4 * SECP256K1_B); /* g = 4*(u^3+7) */ + rustsecp256k1zkp_v0_10_0_fe_add(&q, &g); /* q = 4*(u^3+7)+3*s*u^2 */ + rustsecp256k1zkp_v0_10_0_fe_mul(&q, &q, &s); /* q = s*(4*(u^3+7)+3*u^2*s) */ + rustsecp256k1zkp_v0_10_0_fe_negate(&q, &q, 1); /* q = -s*(4*(u^3+7)+3*u^2*s) */ + if (!rustsecp256k1zkp_v0_10_0_fe_is_square_var(&q)) return 0; + ret = rustsecp256k1zkp_v0_10_0_fe_sqrt(&r, &q); /* r = sqrt(-s*(4*(u^3+7)+3*u^2*s)) */ +#ifdef VERIFY + VERIFY_CHECK(ret); +#else + (void)ret; +#endif + + /* If (c & 1) = 1 and r = 0, fail. */ + if (EXPECT((c & 1) && rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(&r), 0)) return 0; + + /* If s = 0, fail. */ + if (EXPECT(rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(&s), 0)) return 0; + + /* Let v = (r/s-u)/2. */ + rustsecp256k1zkp_v0_10_0_fe_inv_var(&v, &s); /* v = 1/s [no div by 0] */ + rustsecp256k1zkp_v0_10_0_fe_mul(&v, &v, &r); /* v = r/s */ + rustsecp256k1zkp_v0_10_0_fe_add(&v, &m); /* v = r/s-u */ + rustsecp256k1zkp_v0_10_0_fe_half(&v); /* v = (r/s-u)/2 */ + } + + /* Let w = sqrt(s). */ + ret = rustsecp256k1zkp_v0_10_0_fe_sqrt(&m, &s); /* m = sqrt(s) = w */ + VERIFY_CHECK(ret); + + /* Return logic. */ + if ((c & 5) == 0 || (c & 5) == 5) { + rustsecp256k1zkp_v0_10_0_fe_negate(&m, &m, 1); /* m = -w */ + } + /* Now m = {-w if c&5=0 or c&5=5; w otherwise}. */ + rustsecp256k1zkp_v0_10_0_fe_mul(&u, &u, c&1 ? &rustsecp256k1zkp_v0_10_0_ellswift_c4 : &rustsecp256k1zkp_v0_10_0_ellswift_c3); + /* u = {c4 if c&1=1; c3 otherwise}*u */ + rustsecp256k1zkp_v0_10_0_fe_add(&u, &v); /* u = {c4 if c&1=1; c3 otherwise}*u + v */ + rustsecp256k1zkp_v0_10_0_fe_mul(t, &m, &u); + return 1; +} + +/** Use SHA256 as a PRNG, returning SHA256(hasher || cnt). + * + * hasher is a SHA256 object to which an incrementing 4-byte counter is written to generate randomness. + * Writing 13 bytes (4 bytes for counter, plus 9 bytes for the SHA256 padding) cannot cross a + * 64-byte block size boundary (to make sure it only triggers a single SHA256 compression). */ +static void rustsecp256k1zkp_v0_10_0_ellswift_prng(unsigned char* out32, const rustsecp256k1zkp_v0_10_0_sha256 *hasher, uint32_t cnt) { + rustsecp256k1zkp_v0_10_0_sha256 hash = *hasher; + unsigned char buf4[4]; +#ifdef VERIFY + size_t blocks = hash.bytes >> 6; +#endif + buf4[0] = cnt; + buf4[1] = cnt >> 8; + buf4[2] = cnt >> 16; + buf4[3] = cnt >> 24; + rustsecp256k1zkp_v0_10_0_sha256_write(&hash, buf4, 4); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&hash, out32); + + /* Writing and finalizing together should trigger exactly one SHA256 compression. */ + VERIFY_CHECK(((hash.bytes) >> 6) == (blocks + 1)); +} + +/** Find an ElligatorSwift encoding (u, t) for X coordinate x, and random Y coordinate. + * + * u32 is the 32-byte big endian encoding of u; t is the output field element t that still + * needs encoding. + * + * hasher is a hasher in the rustsecp256k1zkp_v0_10_0_ellswift_prng sense, with the same restrictions. */ +static void rustsecp256k1zkp_v0_10_0_ellswift_xelligatorswift_var(unsigned char *u32, rustsecp256k1zkp_v0_10_0_fe *t, const rustsecp256k1zkp_v0_10_0_fe *x, const rustsecp256k1zkp_v0_10_0_sha256 *hasher) { + /* Pool of 3-bit branch values. */ + unsigned char branch_hash[32]; + /* Number of 3-bit values in branch_hash left. */ + int branches_left = 0; + /* Field elements u and branch values are extracted from RNG based on hasher for consecutive + * values of cnt. cnt==0 is first used to populate a pool of 64 4-bit branch values. The 64 + * cnt values that follow are used to generate field elements u. cnt==65 (and multiples + * thereof) are used to repopulate the pool and start over, if that were ever necessary. + * On average, 4 iterations are needed. */ + uint32_t cnt = 0; + while (1) { + int branch; + rustsecp256k1zkp_v0_10_0_fe u; + /* If the pool of branch values is empty, populate it. */ + if (branches_left == 0) { + rustsecp256k1zkp_v0_10_0_ellswift_prng(branch_hash, hasher, cnt++); + branches_left = 64; + } + /* Take a 3-bit branch value from the branch pool (top bit is discarded). */ + --branches_left; + branch = (branch_hash[branches_left >> 1] >> ((branches_left & 1) << 2)) & 7; + /* Compute a new u value by hashing. */ + rustsecp256k1zkp_v0_10_0_ellswift_prng(u32, hasher, cnt++); + /* overflow is not a problem (we prefer uniform u32 over uniform u). */ + rustsecp256k1zkp_v0_10_0_fe_set_b32_mod(&u, u32); + /* Since u is the output of a hash, it should practically never be 0. We could apply the + * u=0 to u=1 correction here too to deal with that case still, but it's such a low + * probability event that we do not bother. */ + VERIFY_CHECK(!rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(&u)); + + /* Find a remainder t, and return it if found. */ + if (EXPECT(rustsecp256k1zkp_v0_10_0_ellswift_xswiftec_inv_var(t, x, &u, branch), 0)) break; + } +} + +/** Find an ElligatorSwift encoding (u, t) for point P. + * + * This is similar rustsecp256k1zkp_v0_10_0_ellswift_xelligatorswift_var, except it takes a full group element p + * as input, and returns an encoding that matches the provided Y coordinate rather than a random + * one. + */ +static void rustsecp256k1zkp_v0_10_0_ellswift_elligatorswift_var(unsigned char *u32, rustsecp256k1zkp_v0_10_0_fe *t, const rustsecp256k1zkp_v0_10_0_ge *p, const rustsecp256k1zkp_v0_10_0_sha256 *hasher) { + rustsecp256k1zkp_v0_10_0_ellswift_xelligatorswift_var(u32, t, &p->x, hasher); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(t); + if (rustsecp256k1zkp_v0_10_0_fe_is_odd(t) != rustsecp256k1zkp_v0_10_0_fe_is_odd(&p->y)) { + rustsecp256k1zkp_v0_10_0_fe_negate(t, t, 1); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(t); + } +} + +/** Set hash state to the BIP340 tagged hash midstate for "rustsecp256k1zkp_v0_10_0_ellswift_encode". */ +static void rustsecp256k1zkp_v0_10_0_ellswift_sha256_init_encode(rustsecp256k1zkp_v0_10_0_sha256* hash) { + rustsecp256k1zkp_v0_10_0_sha256_initialize(hash); + hash->s[0] = 0xd1a6524bul; + hash->s[1] = 0x028594b3ul; + hash->s[2] = 0x96e42f4eul; + hash->s[3] = 0x1037a177ul; + hash->s[4] = 0x1b8fcb8bul; + hash->s[5] = 0x56023885ul; + hash->s[6] = 0x2560ede1ul; + hash->s[7] = 0xd626b715ul; + + hash->bytes = 64; +} + +int rustsecp256k1zkp_v0_10_0_ellswift_encode(const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *ell64, const rustsecp256k1zkp_v0_10_0_pubkey *pubkey, const unsigned char *rnd32) { + rustsecp256k1zkp_v0_10_0_ge p; + VERIFY_CHECK(ctx != NULL); + ARG_CHECK(ell64 != NULL); + ARG_CHECK(pubkey != NULL); + ARG_CHECK(rnd32 != NULL); + + if (rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, &p, pubkey)) { + rustsecp256k1zkp_v0_10_0_fe t; + unsigned char p64[64] = {0}; + size_t ser_size; + int ser_ret; + rustsecp256k1zkp_v0_10_0_sha256 hash; + + /* Set up hasher state; the used RNG is H(pubkey || "\x00"*31 || rnd32 || cnt++), using + * BIP340 tagged hash with tag "rustsecp256k1zkp_v0_10_0_ellswift_encode". */ + rustsecp256k1zkp_v0_10_0_ellswift_sha256_init_encode(&hash); + ser_ret = rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&p, p64, &ser_size, 1); +#ifdef VERIFY + VERIFY_CHECK(ser_ret && ser_size == 33); +#else + (void)ser_ret; +#endif + rustsecp256k1zkp_v0_10_0_sha256_write(&hash, p64, sizeof(p64)); + rustsecp256k1zkp_v0_10_0_sha256_write(&hash, rnd32, 32); + + /* Compute ElligatorSwift encoding and construct output. */ + rustsecp256k1zkp_v0_10_0_ellswift_elligatorswift_var(ell64, &t, &p, &hash); /* puts u in ell64[0..32] */ + rustsecp256k1zkp_v0_10_0_fe_get_b32(ell64 + 32, &t); /* puts t in ell64[32..64] */ + return 1; + } + /* Only reached in case the provided pubkey is invalid. */ + memset(ell64, 0, 64); + return 0; +} + +/** Set hash state to the BIP340 tagged hash midstate for "rustsecp256k1zkp_v0_10_0_ellswift_create". */ +static void rustsecp256k1zkp_v0_10_0_ellswift_sha256_init_create(rustsecp256k1zkp_v0_10_0_sha256* hash) { + rustsecp256k1zkp_v0_10_0_sha256_initialize(hash); + hash->s[0] = 0xd29e1bf5ul; + hash->s[1] = 0xf7025f42ul; + hash->s[2] = 0x9b024773ul; + hash->s[3] = 0x094cb7d5ul; + hash->s[4] = 0xe59ed789ul; + hash->s[5] = 0x03bc9786ul; + hash->s[6] = 0x68335b35ul; + hash->s[7] = 0x4e363b53ul; + + hash->bytes = 64; +} + +int rustsecp256k1zkp_v0_10_0_ellswift_create(const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *ell64, const unsigned char *seckey32, const unsigned char *auxrnd32) { + rustsecp256k1zkp_v0_10_0_ge p; + rustsecp256k1zkp_v0_10_0_fe t; + rustsecp256k1zkp_v0_10_0_sha256 hash; + rustsecp256k1zkp_v0_10_0_scalar seckey_scalar; + int ret; + static const unsigned char zero32[32] = {0}; + + /* Sanity check inputs. */ + VERIFY_CHECK(ctx != NULL); + ARG_CHECK(ell64 != NULL); + memset(ell64, 0, 64); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); + ARG_CHECK(seckey32 != NULL); + + /* Compute (affine) public key */ + ret = rustsecp256k1zkp_v0_10_0_ec_pubkey_create_helper(&ctx->ecmult_gen_ctx, &seckey_scalar, &p, seckey32); + rustsecp256k1zkp_v0_10_0_declassify(ctx, &p, sizeof(p)); /* not constant time in produced pubkey */ + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&p.x); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&p.y); + + /* Set up hasher state. The used RNG is H(privkey || "\x00"*32 [|| auxrnd32] || cnt++), + * using BIP340 tagged hash with tag "rustsecp256k1zkp_v0_10_0_ellswift_create". */ + rustsecp256k1zkp_v0_10_0_ellswift_sha256_init_create(&hash); + rustsecp256k1zkp_v0_10_0_sha256_write(&hash, seckey32, 32); + rustsecp256k1zkp_v0_10_0_sha256_write(&hash, zero32, sizeof(zero32)); + rustsecp256k1zkp_v0_10_0_declassify(ctx, &hash, sizeof(hash)); /* private key is hashed now */ + if (auxrnd32) rustsecp256k1zkp_v0_10_0_sha256_write(&hash, auxrnd32, 32); + + /* Compute ElligatorSwift encoding and construct output. */ + rustsecp256k1zkp_v0_10_0_ellswift_elligatorswift_var(ell64, &t, &p, &hash); /* puts u in ell64[0..32] */ + rustsecp256k1zkp_v0_10_0_fe_get_b32(ell64 + 32, &t); /* puts t in ell64[32..64] */ + + rustsecp256k1zkp_v0_10_0_memczero(ell64, 64, !ret); + rustsecp256k1zkp_v0_10_0_scalar_clear(&seckey_scalar); + + return ret; +} + +int rustsecp256k1zkp_v0_10_0_ellswift_decode(const rustsecp256k1zkp_v0_10_0_context *ctx, rustsecp256k1zkp_v0_10_0_pubkey *pubkey, const unsigned char *ell64) { + rustsecp256k1zkp_v0_10_0_fe u, t; + rustsecp256k1zkp_v0_10_0_ge p; + VERIFY_CHECK(ctx != NULL); + ARG_CHECK(pubkey != NULL); + ARG_CHECK(ell64 != NULL); + + rustsecp256k1zkp_v0_10_0_fe_set_b32_mod(&u, ell64); + rustsecp256k1zkp_v0_10_0_fe_set_b32_mod(&t, ell64 + 32); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&t); + rustsecp256k1zkp_v0_10_0_ellswift_swiftec_var(&p, &u, &t); + rustsecp256k1zkp_v0_10_0_pubkey_save(pubkey, &p); + return 1; +} + +static int ellswift_xdh_hash_function_prefix(unsigned char *output, const unsigned char *x32, const unsigned char *ell_a64, const unsigned char *ell_b64, void *data) { + rustsecp256k1zkp_v0_10_0_sha256 sha; + + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, data, 64); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, ell_a64, 64); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, ell_b64, 64); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, x32, 32); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, output); + + return 1; +} + +/** Set hash state to the BIP340 tagged hash midstate for "bip324_ellswift_xonly_ecdh". */ +static void rustsecp256k1zkp_v0_10_0_ellswift_sha256_init_bip324(rustsecp256k1zkp_v0_10_0_sha256* hash) { + rustsecp256k1zkp_v0_10_0_sha256_initialize(hash); + hash->s[0] = 0x8c12d730ul; + hash->s[1] = 0x827bd392ul; + hash->s[2] = 0x9e4fb2eeul; + hash->s[3] = 0x207b373eul; + hash->s[4] = 0x2292bd7aul; + hash->s[5] = 0xaa5441bcul; + hash->s[6] = 0x15c3779ful; + hash->s[7] = 0xcfb52549ul; + + hash->bytes = 64; +} + +static int ellswift_xdh_hash_function_bip324(unsigned char* output, const unsigned char *x32, const unsigned char *ell_a64, const unsigned char *ell_b64, void *data) { + rustsecp256k1zkp_v0_10_0_sha256 sha; + + (void)data; + + rustsecp256k1zkp_v0_10_0_ellswift_sha256_init_bip324(&sha); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, ell_a64, 64); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, ell_b64, 64); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, x32, 32); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, output); + + return 1; +} + +const rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function_prefix = ellswift_xdh_hash_function_prefix; +const rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function_bip324 = ellswift_xdh_hash_function_bip324; + +int rustsecp256k1zkp_v0_10_0_ellswift_xdh(const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *output, const unsigned char *ell_a64, const unsigned char *ell_b64, const unsigned char *seckey32, int party, rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function hashfp, void *data) { + int ret = 0; + int overflow; + rustsecp256k1zkp_v0_10_0_scalar s; + rustsecp256k1zkp_v0_10_0_fe xn, xd, px, u, t; + unsigned char sx[32]; + const unsigned char* theirs64; + + VERIFY_CHECK(ctx != NULL); + ARG_CHECK(output != NULL); + ARG_CHECK(ell_a64 != NULL); + ARG_CHECK(ell_b64 != NULL); + ARG_CHECK(seckey32 != NULL); + ARG_CHECK(hashfp != NULL); + + /* Load remote public key (as fraction). */ + theirs64 = party ? ell_a64 : ell_b64; + rustsecp256k1zkp_v0_10_0_fe_set_b32_mod(&u, theirs64); + rustsecp256k1zkp_v0_10_0_fe_set_b32_mod(&t, theirs64 + 32); + rustsecp256k1zkp_v0_10_0_ellswift_xswiftec_frac_var(&xn, &xd, &u, &t); + + /* Load private key (using one if invalid). */ + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&s, seckey32, &overflow); + overflow = rustsecp256k1zkp_v0_10_0_scalar_is_zero(&s); + rustsecp256k1zkp_v0_10_0_scalar_cmov(&s, &rustsecp256k1zkp_v0_10_0_scalar_one, overflow); + + /* Compute shared X coordinate. */ + rustsecp256k1zkp_v0_10_0_ecmult_const_xonly(&px, &xn, &xd, &s, 1); + rustsecp256k1zkp_v0_10_0_fe_normalize(&px); + rustsecp256k1zkp_v0_10_0_fe_get_b32(sx, &px); + + /* Invoke hasher */ + ret = hashfp(output, sx, ell_a64, ell_b64, data); + + memset(sx, 0, 32); + rustsecp256k1zkp_v0_10_0_fe_clear(&px); + rustsecp256k1zkp_v0_10_0_scalar_clear(&s); + + return !!ret & !overflow; +} + +#endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ellswift/tests_exhaustive_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ellswift/tests_exhaustive_impl.h new file mode 100644 index 00000000..879d1019 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ellswift/tests_exhaustive_impl.h @@ -0,0 +1,39 @@ +/*********************************************************************** + * Distributed under the MIT software license, see the accompanying * + * file COPYING or https://www.opensource.org/licenses/mit-license.php.* + ***********************************************************************/ + +#ifndef SECP256K1_MODULE_ELLSWIFT_TESTS_EXHAUSTIVE_H +#define SECP256K1_MODULE_ELLSWIFT_TESTS_EXHAUSTIVE_H + +#include "../../../include/secp256k1_ellswift.h" +#include "main_impl.h" + +static void test_exhaustive_ellswift(const rustsecp256k1zkp_v0_10_0_context *ctx, const rustsecp256k1zkp_v0_10_0_ge *group) { + int i; + + /* Note that SwiftEC/ElligatorSwift are inherently curve operations, not + * group operations, and this test only checks the curve points which are in + * a tiny subgroup. In that sense it can't be really seen as exhaustive as + * it doesn't (and for computational reasons obviously cannot) test the + * entire domain ellswift operates under. */ + for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) { + rustsecp256k1zkp_v0_10_0_scalar scalar_i; + unsigned char sec32[32]; + unsigned char ell64[64]; + rustsecp256k1zkp_v0_10_0_pubkey pub_decoded; + rustsecp256k1zkp_v0_10_0_ge ge_decoded; + + /* Construct ellswift pubkey from exhaustive loop scalar i. */ + rustsecp256k1zkp_v0_10_0_scalar_set_int(&scalar_i, i); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(sec32, &scalar_i); + CHECK(rustsecp256k1zkp_v0_10_0_ellswift_create(ctx, ell64, sec32, NULL)); + + /* Decode ellswift pubkey and check that it matches the precomputed group element. */ + rustsecp256k1zkp_v0_10_0_ellswift_decode(ctx, &pub_decoded, ell64); + rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, &ge_decoded, &pub_decoded); + CHECK(rustsecp256k1zkp_v0_10_0_ge_eq_var(&ge_decoded, &group[i])); + } +} + +#endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/ellswift/tests_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ellswift/tests_impl.h new file mode 100644 index 00000000..f224ebca --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/ellswift/tests_impl.h @@ -0,0 +1,436 @@ +/*********************************************************************** + * Distributed under the MIT software license, see the accompanying * + * file COPYING or https://www.opensource.org/licenses/mit-license.php.* + ***********************************************************************/ + +#ifndef SECP256K1_MODULE_ELLSWIFT_TESTS_H +#define SECP256K1_MODULE_ELLSWIFT_TESTS_H + +#include "../../../include/secp256k1_ellswift.h" + +struct ellswift_xswiftec_inv_test { + int enc_bitmap; + rustsecp256k1zkp_v0_10_0_fe u; + rustsecp256k1zkp_v0_10_0_fe x; + rustsecp256k1zkp_v0_10_0_fe encs[8]; +}; + +struct ellswift_decode_test { + unsigned char enc[64]; + rustsecp256k1zkp_v0_10_0_fe x; + int odd_y; +}; + +struct ellswift_xdh_test { + unsigned char priv_ours[32]; + unsigned char ellswift_ours[64]; + unsigned char ellswift_theirs[64]; + int initiating; + unsigned char shared_secret[32]; +}; + +/* Set of (point, encodings) test vectors, selected to maximize branch coverage, part of the BIP324 + * test vectors. Created using an independent implementation, and tested decoding against paper + * authors' code. */ +static const struct ellswift_xswiftec_inv_test ellswift_xswiftec_inv_tests[] = { + {0xcc, SECP256K1_FE_CONST(0x05ff6bda, 0xd900fc32, 0x61bc7fe3, 0x4e2fb0f5, 0x69f06e09, 0x1ae437d3, 0xa52e9da0, 0xcbfb9590), SECP256K1_FE_CONST(0x80cdf637, 0x74ec7022, 0xc89a5a85, 0x58e373a2, 0x79170285, 0xe0ab2741, 0x2dbce510, 0xbdfe23fc), {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0x45654798, 0xece071ba, 0x79286d04, 0xf7f3eb1c, 0x3f1d17dd, 0x883610f2, 0xad2efd82, 0xa287466b), SECP256K1_FE_CONST(0x0aeaa886, 0xf6b76c71, 0x58452418, 0xcbf5033a, 0xdc5747e9, 0xe9b5d3b2, 0x303db969, 0x36528557), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0xba9ab867, 0x131f8e45, 0x86d792fb, 0x080c14e3, 0xc0e2e822, 0x77c9ef0d, 0x52d1027c, 0x5d78b5c4), SECP256K1_FE_CONST(0xf5155779, 0x0948938e, 0xa7badbe7, 0x340afcc5, 0x23a8b816, 0x164a2c4d, 0xcfc24695, 0xc9ad76d8)}}, + {0x33, SECP256K1_FE_CONST(0x1737a85f, 0x4c8d146c, 0xec96e3ff, 0xdca76d99, 0x03dcf3bd, 0x53061868, 0xd478c78c, 0x63c2aa9e), SECP256K1_FE_CONST(0x39e48dd1, 0x50d2f429, 0xbe088dfd, 0x5b61882e, 0x7e840748, 0x3702ae9a, 0x5ab35927, 0xb15f85ea), {SECP256K1_FE_CONST(0x1be8cc0b, 0x04be0c68, 0x1d0c6a68, 0xf733f82c, 0x6c896e0c, 0x8a262fcd, 0x392918e3, 0x03a7abf4), SECP256K1_FE_CONST(0x605b5814, 0xbf9b8cb0, 0x66667c9e, 0x5480d22d, 0xc5b6c92f, 0x14b4af3e, 0xe0a9eb83, 0xb03685e3), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0xe41733f4, 0xfb41f397, 0xe2f39597, 0x08cc07d3, 0x937691f3, 0x75d9d032, 0xc6d6e71b, 0xfc58503b), SECP256K1_FE_CONST(0x9fa4a7eb, 0x4064734f, 0x99998361, 0xab7f2dd2, 0x3a4936d0, 0xeb4b50c1, 0x1f56147b, 0x4fc9764c), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, + {0x00, SECP256K1_FE_CONST(0x1aaa1cce, 0xbf9c7241, 0x91033df3, 0x66b36f69, 0x1c4d902c, 0x228033ff, 0x4516d122, 0xb2564f68), SECP256K1_FE_CONST(0xc7554125, 0x9d3ba98f, 0x207eaa30, 0xc69634d1, 0x87d0b6da, 0x594e719e, 0x420f4898, 0x638fc5b0), {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, + {0x33, SECP256K1_FE_CONST(0x2323a1d0, 0x79b0fd72, 0xfc8bb62e, 0xc34230a8, 0x15cb0596, 0xc2bfac99, 0x8bd6b842, 0x60f5dc26), SECP256K1_FE_CONST(0x239342df, 0xb675500a, 0x34a19631, 0x0b8d87d5, 0x4f49dcac, 0x9da50c17, 0x43ceab41, 0xa7b249ff), {SECP256K1_FE_CONST(0xf63580b8, 0xaa49c484, 0x6de56e39, 0xe1b3e73f, 0x171e881e, 0xba8c66f6, 0x14e67e5c, 0x975dfc07), SECP256K1_FE_CONST(0xb6307b33, 0x2e699f1c, 0xf77841d9, 0x0af25365, 0x404deb7f, 0xed5edb30, 0x90db49e6, 0x42a156b6), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0x09ca7f47, 0x55b63b7b, 0x921a91c6, 0x1e4c18c0, 0xe8e177e1, 0x45739909, 0xeb1981a2, 0x68a20028), SECP256K1_FE_CONST(0x49cf84cc, 0xd19660e3, 0x0887be26, 0xf50dac9a, 0xbfb21480, 0x12a124cf, 0x6f24b618, 0xbd5ea579), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, + {0x33, SECP256K1_FE_CONST(0x2dc90e64, 0x0cb646ae, 0x9164c0b5, 0xa9ef0169, 0xfebe34dc, 0x4437d6e4, 0x6acb0e27, 0xe219d1e8), SECP256K1_FE_CONST(0xd236f19b, 0xf349b951, 0x6e9b3f4a, 0x5610fe96, 0x0141cb23, 0xbbc8291b, 0x9534f1d7, 0x1de62a47), {SECP256K1_FE_CONST(0xe69df7d9, 0xc026c366, 0x00ebdf58, 0x80726758, 0x47c0c431, 0xc8eb7306, 0x82533e96, 0x4b6252c9), SECP256K1_FE_CONST(0x4f18bbdf, 0x7c2d6c5f, 0x818c1880, 0x2fa35cd0, 0x69eaa79f, 0xff74e4fc, 0x837c80d9, 0x3fece2f8), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0x19620826, 0x3fd93c99, 0xff1420a7, 0x7f8d98a7, 0xb83f3bce, 0x37148cf9, 0x7dacc168, 0xb49da966), SECP256K1_FE_CONST(0xb0e74420, 0x83d293a0, 0x7e73e77f, 0xd05ca32f, 0x96155860, 0x008b1b03, 0x7c837f25, 0xc0131937), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, + {0xcc, SECP256K1_FE_CONST(0x3edd7b39, 0x80e2f2f3, 0x4d1409a2, 0x07069f88, 0x1fda5f96, 0xf08027ac, 0x4465b63d, 0xc278d672), SECP256K1_FE_CONST(0x053a98de, 0x4a27b196, 0x1155822b, 0x3a3121f0, 0x3b2a1445, 0x8bd80eb4, 0xa560c4c7, 0xa85c149c), {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0xb3dae4b7, 0xdcf858e4, 0xc6968057, 0xcef2b156, 0x46543152, 0x6538199c, 0xf52dc1b2, 0xd62fda30), SECP256K1_FE_CONST(0x4aa77dd5, 0x5d6b6d3c, 0xfa10cc9d, 0x0fe42f79, 0x232e4575, 0x661049ae, 0x36779c1d, 0x0c666d88), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0x4c251b48, 0x2307a71b, 0x39697fa8, 0x310d4ea9, 0xb9abcead, 0x9ac7e663, 0x0ad23e4c, 0x29d021ff), SECP256K1_FE_CONST(0xb558822a, 0xa29492c3, 0x05ef3362, 0xf01bd086, 0xdcd1ba8a, 0x99efb651, 0xc98863e1, 0xf3998ea7)}}, + {0x00, SECP256K1_FE_CONST(0x4295737e, 0xfcb1da6f, 0xb1d96b9c, 0xa7dcd1e3, 0x20024b37, 0xa736c494, 0x8b625981, 0x73069f70), SECP256K1_FE_CONST(0xfa7ffe4f, 0x25f88362, 0x831c087a, 0xfe2e8a9b, 0x0713e2ca, 0xc1ddca6a, 0x383205a2, 0x66f14307), {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, + {0xff, SECP256K1_FE_CONST(0x587c1a0c, 0xee91939e, 0x7f784d23, 0xb963004a, 0x3bf44f5d, 0x4e32a008, 0x1995ba20, 0xb0fca59e), SECP256K1_FE_CONST(0x2ea98853, 0x0715e8d1, 0x0363907f, 0xf2512452, 0x4d471ba2, 0x454d5ce3, 0xbe3f0419, 0x4dfd3a3c), {SECP256K1_FE_CONST(0xcfd5a094, 0xaa0b9b88, 0x91b76c6a, 0xb9438f66, 0xaa1c095a, 0x65f9f701, 0x35e81712, 0x92245e74), SECP256K1_FE_CONST(0xa89057d7, 0xc6563f0d, 0x6efa19ae, 0x84412b8a, 0x7b47e791, 0xa191ecdf, 0xdf2af84f, 0xd97bc339), SECP256K1_FE_CONST(0x475d0ae9, 0xef46920d, 0xf07b3411, 0x7be5a081, 0x7de1023e, 0x3cc32689, 0xe9be145b, 0x406b0aef), SECP256K1_FE_CONST(0xa0759178, 0xad802324, 0x54f827ef, 0x05ea3e72, 0xad8d7541, 0x8e6d4cc1, 0xcd4f5306, 0xc5e7c453), SECP256K1_FE_CONST(0x302a5f6b, 0x55f46477, 0x6e489395, 0x46bc7099, 0x55e3f6a5, 0x9a0608fe, 0xca17e8ec, 0x6ddb9dbb), SECP256K1_FE_CONST(0x576fa828, 0x39a9c0f2, 0x9105e651, 0x7bbed475, 0x84b8186e, 0x5e6e1320, 0x20d507af, 0x268438f6), SECP256K1_FE_CONST(0xb8a2f516, 0x10b96df2, 0x0f84cbee, 0x841a5f7e, 0x821efdc1, 0xc33cd976, 0x1641eba3, 0xbf94f140), SECP256K1_FE_CONST(0x5f8a6e87, 0x527fdcdb, 0xab07d810, 0xfa15c18d, 0x52728abe, 0x7192b33e, 0x32b0acf8, 0x3a1837dc)}}, + {0xcc, SECP256K1_FE_CONST(0x5fa88b33, 0x65a635cb, 0xbcee003c, 0xce9ef51d, 0xd1a310de, 0x277e441a, 0xbccdb7be, 0x1e4ba249), SECP256K1_FE_CONST(0x79461ff6, 0x2bfcbcac, 0x4249ba84, 0xdd040f2c, 0xec3c63f7, 0x25204dc7, 0xf464c16b, 0xf0ff3170), {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0x6bb700e1, 0xf4d7e236, 0xe8d193ff, 0x4a76c1b3, 0xbcd4e2b2, 0x5acac3d5, 0x1c8dac65, 0x3fe909a0), SECP256K1_FE_CONST(0xf4c73410, 0x633da7f6, 0x3a4f1d55, 0xaec6dd32, 0xc4c6d89e, 0xe74075ed, 0xb5515ed9, 0x0da9e683), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0x9448ff1e, 0x0b281dc9, 0x172e6c00, 0xb5893e4c, 0x432b1d4d, 0xa5353c2a, 0xe3725399, 0xc016f28f), SECP256K1_FE_CONST(0x0b38cbef, 0x9cc25809, 0xc5b0e2aa, 0x513922cd, 0x3b392761, 0x18bf8a12, 0x4aaea125, 0xf25615ac)}}, + {0xcc, SECP256K1_FE_CONST(0x6fb31c75, 0x31f03130, 0xb42b155b, 0x952779ef, 0xbb46087d, 0xd9807d24, 0x1a48eac6, 0x3c3d96d6), SECP256K1_FE_CONST(0x56f81be7, 0x53e8d4ae, 0x4940ea6f, 0x46f6ec9f, 0xda66a6f9, 0x6cc95f50, 0x6cb2b574, 0x90e94260), {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0x59059774, 0x795bdb7a, 0x837fbe11, 0x40a5fa59, 0x984f48af, 0x8df95d57, 0xdd6d1c05, 0x437dcec1), SECP256K1_FE_CONST(0x22a644db, 0x79376ad4, 0xe7b3a009, 0xe58b3f13, 0x137c54fd, 0xf911122c, 0xc93667c4, 0x7077d784), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0xa6fa688b, 0x86a42485, 0x7c8041ee, 0xbf5a05a6, 0x67b0b750, 0x7206a2a8, 0x2292e3f9, 0xbc822d6e), SECP256K1_FE_CONST(0xdd59bb24, 0x86c8952b, 0x184c5ff6, 0x1a74c0ec, 0xec83ab02, 0x06eeedd3, 0x36c9983a, 0x8f8824ab)}}, + {0x00, SECP256K1_FE_CONST(0x704cd226, 0xe71cb682, 0x6a590e80, 0xdac90f2d, 0x2f5830f0, 0xfdf135a3, 0xeae3965b, 0xff25ff12), SECP256K1_FE_CONST(0x138e0afa, 0x68936ee6, 0x70bd2b8d, 0xb53aedbb, 0x7bea2a85, 0x97388b24, 0xd0518edd, 0x22ad66ec), {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, + {0x33, SECP256K1_FE_CONST(0x725e9147, 0x92cb8c89, 0x49e7e116, 0x8b7cdd8a, 0x8094c91c, 0x6ec2202c, 0xcd53a6a1, 0x8771edeb), SECP256K1_FE_CONST(0x8da16eb8, 0x6d347376, 0xb6181ee9, 0x74832275, 0x7f6b36e3, 0x913ddfd3, 0x32ac595d, 0x788e0e44), {SECP256K1_FE_CONST(0xdd357786, 0xb9f68733, 0x30391aa5, 0x62580965, 0x4e43116e, 0x82a5a5d8, 0x2ffd1d66, 0x24101fc4), SECP256K1_FE_CONST(0xa0b7efca, 0x01814594, 0xc59c9aae, 0x8e497001, 0x86ca5d95, 0xe88bcc80, 0x399044d9, 0xc2d8613d), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0x22ca8879, 0x460978cc, 0xcfc6e55a, 0x9da7f69a, 0xb1bcee91, 0x7d5a5a27, 0xd002e298, 0xdbefdc6b), SECP256K1_FE_CONST(0x5f481035, 0xfe7eba6b, 0x3a636551, 0x71b68ffe, 0x7935a26a, 0x1774337f, 0xc66fbb25, 0x3d279af2), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, + {0x00, SECP256K1_FE_CONST(0x78fe6b71, 0x7f2ea4a3, 0x2708d79c, 0x151bf503, 0xa5312a18, 0xc0963437, 0xe865cc6e, 0xd3f6ae97), SECP256K1_FE_CONST(0x8701948e, 0x80d15b5c, 0xd8f72863, 0xeae40afc, 0x5aced5e7, 0x3f69cbc8, 0x179a3390, 0x2c094d98), {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, + {0x44, SECP256K1_FE_CONST(0x7c37bb9c, 0x5061dc07, 0x413f11ac, 0xd5a34006, 0xe64c5c45, 0x7fdb9a43, 0x8f217255, 0xa961f50d), SECP256K1_FE_CONST(0x5c1a76b4, 0x4568eb59, 0xd6789a74, 0x42d9ed7c, 0xdc6226b7, 0x752b4ff8, 0xeaf8e1a9, 0x5736e507), {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0xb94d30cd, 0x7dbff60b, 0x64620c17, 0xca0fafaa, 0x40b3d1f5, 0x2d077a60, 0xa2e0cafd, 0x145086c2), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0x46b2cf32, 0x824009f4, 0x9b9df3e8, 0x35f05055, 0xbf4c2e0a, 0xd2f8859f, 0x5d1f3501, 0xebaf756d), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, + {0x00, SECP256K1_FE_CONST(0x82388888, 0x967f82a6, 0xb444438a, 0x7d44838e, 0x13c0d478, 0xb9ca060d, 0xa95a41fb, 0x94303de6), SECP256K1_FE_CONST(0x29e96541, 0x70628fec, 0x8b497289, 0x8b113cf9, 0x8807f460, 0x9274f4f3, 0x140d0674, 0x157c90a0), {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, + {0x33, SECP256K1_FE_CONST(0x91298f57, 0x70af7a27, 0xf0a47188, 0xd24c3b7b, 0xf98ab299, 0x0d84b0b8, 0x98507e3c, 0x561d6472), SECP256K1_FE_CONST(0x144f4ccb, 0xd9a74698, 0xa88cbf6f, 0xd00ad886, 0xd339d29e, 0xa19448f2, 0xc572cac0, 0xa07d5562), {SECP256K1_FE_CONST(0xe6a0ffa3, 0x807f09da, 0xdbe71e0f, 0x4be4725f, 0x2832e76c, 0xad8dc1d9, 0x43ce8393, 0x75eff248), SECP256K1_FE_CONST(0x837b8e68, 0xd4917544, 0x764ad090, 0x3cb11f86, 0x15d2823c, 0xefbb06d8, 0x9049dbab, 0xc69befda), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0x195f005c, 0x7f80f625, 0x2418e1f0, 0xb41b8da0, 0xd7cd1893, 0x52723e26, 0xbc317c6b, 0x8a1009e7), SECP256K1_FE_CONST(0x7c847197, 0x2b6e8abb, 0x89b52f6f, 0xc34ee079, 0xea2d7dc3, 0x1044f927, 0x6fb62453, 0x39640c55), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, + {0x00, SECP256K1_FE_CONST(0xb682f3d0, 0x3bbb5dee, 0x4f54b5eb, 0xfba931b4, 0xf52f6a19, 0x1e5c2f48, 0x3c73c66e, 0x9ace97e1), SECP256K1_FE_CONST(0x904717bf, 0x0bc0cb78, 0x73fcdc38, 0xaa97f19e, 0x3a626309, 0x72acff92, 0xb24cc6dd, 0xa197cb96), {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, + {0x77, SECP256K1_FE_CONST(0xc17ec69e, 0x665f0fb0, 0xdbab48d9, 0xc2f94d12, 0xec8a9d7e, 0xacb58084, 0x83309180, 0x1eb0b80b), SECP256K1_FE_CONST(0x147756e6, 0x6d96e31c, 0x426d3cc8, 0x5ed0c4cf, 0xbef6341d, 0xd8b28558, 0x5aa574ea, 0x0204b55e), {SECP256K1_FE_CONST(0x6f4aea43, 0x1a0043bd, 0xd03134d6, 0xd9159119, 0xce034b88, 0xc32e50e8, 0xe36c4ee4, 0x5eac7ae9), SECP256K1_FE_CONST(0xfd5be16d, 0x4ffa2690, 0x126c67c3, 0xef7cb9d2, 0x9b74d397, 0xc78b06b3, 0x605fda34, 0xdc9696a6), SECP256K1_FE_CONST(0x5e9c6079, 0x2a2f000e, 0x45c6250f, 0x296f875e, 0x174efc0e, 0x9703e628, 0x706103a9, 0xdd2d82c7), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0x90b515bc, 0xe5ffbc42, 0x2fcecb29, 0x26ea6ee6, 0x31fcb477, 0x3cd1af17, 0x1c93b11a, 0xa1538146), SECP256K1_FE_CONST(0x02a41e92, 0xb005d96f, 0xed93983c, 0x1083462d, 0x648b2c68, 0x3874f94c, 0x9fa025ca, 0x23696589), SECP256K1_FE_CONST(0xa1639f86, 0xd5d0fff1, 0xba39daf0, 0xd69078a1, 0xe8b103f1, 0x68fc19d7, 0x8f9efc55, 0x22d27968), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, + {0xcc, SECP256K1_FE_CONST(0xc25172fc, 0x3f29b6fc, 0x4a1155b8, 0x57523315, 0x5486b274, 0x64b74b8b, 0x260b499a, 0x3f53cb14), SECP256K1_FE_CONST(0x1ea9cbdb, 0x35cf6e03, 0x29aa31b0, 0xbb0a702a, 0x65123ed0, 0x08655a93, 0xb7dcd528, 0x0e52e1ab), {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0x7422edc7, 0x843136af, 0x0053bb88, 0x54448a82, 0x99994f9d, 0xdcefd3a9, 0xa92d4546, 0x2c59298a), SECP256K1_FE_CONST(0x78c7774a, 0x266f8b97, 0xea23d05d, 0x064f033c, 0x77319f92, 0x3f6b78bc, 0xe4e20bf0, 0x5fa5398d), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0x8bdd1238, 0x7bcec950, 0xffac4477, 0xabbb757d, 0x6666b062, 0x23102c56, 0x56d2bab8, 0xd3a6d2a5), SECP256K1_FE_CONST(0x873888b5, 0xd9907468, 0x15dc2fa2, 0xf9b0fcc3, 0x88ce606d, 0xc0948743, 0x1b1df40e, 0xa05ac2a2)}}, + {0x00, SECP256K1_FE_CONST(0xcab6626f, 0x832a4b12, 0x80ba7add, 0x2fc5322f, 0xf011caed, 0xedf7ff4d, 0xb6735d50, 0x26dc0367), SECP256K1_FE_CONST(0x2b2bef08, 0x52c6f7c9, 0x5d72ac99, 0xa23802b8, 0x75029cd5, 0x73b248d1, 0xf1b3fc80, 0x33788eb6), {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, + {0x33, SECP256K1_FE_CONST(0xd8621b4f, 0xfc85b9ed, 0x56e99d8d, 0xd1dd24ae, 0xdcecb147, 0x63b861a1, 0x7112dc77, 0x1a104fd2), SECP256K1_FE_CONST(0x812cabe9, 0x72a22aa6, 0x7c7da0c9, 0x4d8a9362, 0x96eb9949, 0xd70c37cb, 0x2b248757, 0x4cb3ce58), {SECP256K1_FE_CONST(0xfbc5febc, 0x6fdbc9ae, 0x3eb88a93, 0xb982196e, 0x8b6275a6, 0xd5a73c17, 0x387e000c, 0x711bd0e3), SECP256K1_FE_CONST(0x8724c96b, 0xd4e5527f, 0x2dd195a5, 0x1c468d2d, 0x211ba2fa, 0xc7cbe0b4, 0xb3434253, 0x409fb42d), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0x043a0143, 0x90243651, 0xc147756c, 0x467de691, 0x749d8a59, 0x2a58c3e8, 0xc781fff2, 0x8ee42b4c), SECP256K1_FE_CONST(0x78db3694, 0x2b1aad80, 0xd22e6a5a, 0xe3b972d2, 0xdee45d05, 0x38341f4b, 0x4cbcbdab, 0xbf604802), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, + {0x00, SECP256K1_FE_CONST(0xda463164, 0xc6f4bf71, 0x29ee5f0e, 0xc00f65a6, 0x75a8adf1, 0xbd931b39, 0xb64806af, 0xdcda9a22), SECP256K1_FE_CONST(0x25b9ce9b, 0x390b408e, 0xd611a0f1, 0x3ff09a59, 0x8a57520e, 0x426ce4c6, 0x49b7f94f, 0x2325620d), {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, + {0xcc, SECP256K1_FE_CONST(0xdafc971e, 0x4a3a7b6d, 0xcfb42a08, 0xd9692d82, 0xad9e7838, 0x523fcbda, 0x1d4827e1, 0x4481ae2d), SECP256K1_FE_CONST(0x250368e1, 0xb5c58492, 0x304bd5f7, 0x2696d27d, 0x526187c7, 0xadc03425, 0xe2b7d81d, 0xbb7e4e02), {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0x370c28f1, 0xbe665efa, 0xcde6aa43, 0x6bf86fe2, 0x1e6e314c, 0x1e53dd04, 0x0e6c73a4, 0x6b4c8c49), SECP256K1_FE_CONST(0xcd8acee9, 0x8ffe5653, 0x1a84d7eb, 0x3e48fa40, 0x34206ce8, 0x25ace907, 0xd0edf0ea, 0xeb5e9ca2), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0xc8f3d70e, 0x4199a105, 0x321955bc, 0x9407901d, 0xe191ceb3, 0xe1ac22fb, 0xf1938c5a, 0x94b36fe6), SECP256K1_FE_CONST(0x32753116, 0x7001a9ac, 0xe57b2814, 0xc1b705bf, 0xcbdf9317, 0xda5316f8, 0x2f120f14, 0x14a15f8d)}}, + {0x44, SECP256K1_FE_CONST(0xe0294c8b, 0xc1a36b41, 0x66ee92bf, 0xa70a5c34, 0x976fa982, 0x9405efea, 0x8f9cd54d, 0xcb29b99e), SECP256K1_FE_CONST(0xae9690d1, 0x3b8d20a0, 0xfbbf37be, 0xd8474f67, 0xa04e142f, 0x56efd787, 0x70a76b35, 0x9165d8a1), {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0xdcd45d93, 0x5613916a, 0xf167b029, 0x058ba3a7, 0x00d37150, 0xb9df3472, 0x8cb05412, 0xc16d4182), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0x232ba26c, 0xa9ec6e95, 0x0e984fd6, 0xfa745c58, 0xff2c8eaf, 0x4620cb8d, 0x734fabec, 0x3e92baad), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, + {0x00, SECP256K1_FE_CONST(0xe148441c, 0xd7b92b8b, 0x0e4fa3bd, 0x68712cfd, 0x0d709ad1, 0x98cace61, 0x1493c10e, 0x97f5394e), SECP256K1_FE_CONST(0x164a6397, 0x94d74c53, 0xafc4d329, 0x4e79cdb3, 0xcd25f99f, 0x6df45c00, 0x0f758aba, 0x54d699c0), {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, + {0xff, SECP256K1_FE_CONST(0xe4b00ec9, 0x7aadcca9, 0x7644d3b0, 0xc8a931b1, 0x4ce7bcf7, 0xbc877954, 0x6d6e35aa, 0x5937381c), SECP256K1_FE_CONST(0x94e9588d, 0x41647b3f, 0xcc772dc8, 0xd83c67ce, 0x3be00353, 0x8517c834, 0x103d2cd4, 0x9d62ef4d), {SECP256K1_FE_CONST(0xc88d25f4, 0x1407376b, 0xb2c03a7f, 0xffeb3ec7, 0x811cc434, 0x91a0c3aa, 0xc0378cdc, 0x78357bee), SECP256K1_FE_CONST(0x51c02636, 0xce00c234, 0x5ecd89ad, 0xb6089fe4, 0xd5e18ac9, 0x24e3145e, 0x6669501c, 0xd37a00d4), SECP256K1_FE_CONST(0x205b3512, 0xdb40521c, 0xb200952e, 0x67b46f67, 0xe09e7839, 0xe0de4400, 0x4138329e, 0xbd9138c5), SECP256K1_FE_CONST(0x58aab390, 0xab6fb55c, 0x1d1b8089, 0x7a207ce9, 0x4a78fa5b, 0x4aa61a33, 0x398bcae9, 0xadb20d3e), SECP256K1_FE_CONST(0x3772da0b, 0xebf8c894, 0x4d3fc580, 0x0014c138, 0x7ee33bcb, 0x6e5f3c55, 0x3fc87322, 0x87ca8041), SECP256K1_FE_CONST(0xae3fd9c9, 0x31ff3dcb, 0xa1327652, 0x49f7601b, 0x2a1e7536, 0xdb1ceba1, 0x9996afe2, 0x2c85fb5b), SECP256K1_FE_CONST(0xdfa4caed, 0x24bfade3, 0x4dff6ad1, 0x984b9098, 0x1f6187c6, 0x1f21bbff, 0xbec7cd60, 0x426ec36a), SECP256K1_FE_CONST(0xa7554c6f, 0x54904aa3, 0xe2e47f76, 0x85df8316, 0xb58705a4, 0xb559e5cc, 0xc6743515, 0x524deef1)}}, + {0x00, SECP256K1_FE_CONST(0xe5bbb9ef, 0x360d0a50, 0x1618f006, 0x7d36dceb, 0x75f5be9a, 0x620232aa, 0x9fd5139d, 0x0863fde5), SECP256K1_FE_CONST(0xe5bbb9ef, 0x360d0a50, 0x1618f006, 0x7d36dceb, 0x75f5be9a, 0x620232aa, 0x9fd5139d, 0x0863fde5), {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, + {0xff, SECP256K1_FE_CONST(0xe6bcb5c3, 0xd63467d4, 0x90bfa54f, 0xbbc6092a, 0x7248c25e, 0x11b248dc, 0x2964a6e1, 0x5edb1457), SECP256K1_FE_CONST(0x19434a3c, 0x29cb982b, 0x6f405ab0, 0x4439f6d5, 0x8db73da1, 0xee4db723, 0xd69b591d, 0xa124e7d8), {SECP256K1_FE_CONST(0x67119877, 0x832ab8f4, 0x59a82165, 0x6d8261f5, 0x44a553b8, 0x9ae4f25c, 0x52a97134, 0xb70f3426), SECP256K1_FE_CONST(0xffee02f5, 0xe649c07f, 0x0560eff1, 0x867ec7b3, 0x2d0e595e, 0x9b1c0ea6, 0xe2a4fc70, 0xc97cd71f), SECP256K1_FE_CONST(0xb5e0c189, 0xeb5b4bac, 0xd025b744, 0x4d74178b, 0xe8d5246c, 0xfa4a9a20, 0x7964a057, 0xee969992), SECP256K1_FE_CONST(0x5746e459, 0x1bf7f4c3, 0x044609ea, 0x372e9086, 0x03975d27, 0x9fdef834, 0x9f0b08d3, 0x2f07619d), SECP256K1_FE_CONST(0x98ee6788, 0x7cd5470b, 0xa657de9a, 0x927d9e0a, 0xbb5aac47, 0x651b0da3, 0xad568eca, 0x48f0c809), SECP256K1_FE_CONST(0x0011fd0a, 0x19b63f80, 0xfa9f100e, 0x7981384c, 0xd2f1a6a1, 0x64e3f159, 0x1d5b038e, 0x36832510), SECP256K1_FE_CONST(0x4a1f3e76, 0x14a4b453, 0x2fda48bb, 0xb28be874, 0x172adb93, 0x05b565df, 0x869b5fa7, 0x1169629d), SECP256K1_FE_CONST(0xa8b91ba6, 0xe4080b3c, 0xfbb9f615, 0xc8d16f79, 0xfc68a2d8, 0x602107cb, 0x60f4f72b, 0xd0f89a92)}}, + {0x33, SECP256K1_FE_CONST(0xf28fba64, 0xaf766845, 0xeb2f4302, 0x456e2b9f, 0x8d80affe, 0x57e7aae4, 0x2738d7cd, 0xdb1c2ce6), SECP256K1_FE_CONST(0xf28fba64, 0xaf766845, 0xeb2f4302, 0x456e2b9f, 0x8d80affe, 0x57e7aae4, 0x2738d7cd, 0xdb1c2ce6), {SECP256K1_FE_CONST(0x4f867ad8, 0xbb3d8404, 0x09d26b67, 0x307e6210, 0x0153273f, 0x72fa4b74, 0x84becfa1, 0x4ebe7408), SECP256K1_FE_CONST(0x5bbc4f59, 0xe452cc5f, 0x22a99144, 0xb10ce898, 0x9a89a995, 0xec3cea1c, 0x91ae10e8, 0xf721bb5d), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0xb0798527, 0x44c27bfb, 0xf62d9498, 0xcf819def, 0xfeacd8c0, 0x8d05b48b, 0x7b41305d, 0xb1418827), SECP256K1_FE_CONST(0xa443b0a6, 0x1bad33a0, 0xdd566ebb, 0x4ef31767, 0x6576566a, 0x13c315e3, 0x6e51ef16, 0x08de40d2), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, + {0xcc, SECP256K1_FE_CONST(0xf455605b, 0xc85bf48e, 0x3a908c31, 0x023faf98, 0x381504c6, 0xc6d3aeb9, 0xede55f8d, 0xd528924d), SECP256K1_FE_CONST(0xd31fbcd5, 0xcdb798f6, 0xc00db669, 0x2f8fe896, 0x7fa9c79d, 0xd10958f4, 0xa194f013, 0x74905e99), {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0x0c00c571, 0x5b56fe63, 0x2d814ad8, 0xa77f8e66, 0x628ea47a, 0x6116834f, 0x8c1218f3, 0xa03cbd50), SECP256K1_FE_CONST(0xdf88e44f, 0xac84fa52, 0xdf4d59f4, 0x8819f18f, 0x6a8cd415, 0x1d162afa, 0xf773166f, 0x57c7ff46), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0xf3ff3a8e, 0xa4a9019c, 0xd27eb527, 0x58807199, 0x9d715b85, 0x9ee97cb0, 0x73ede70b, 0x5fc33edf), SECP256K1_FE_CONST(0x20771bb0, 0x537b05ad, 0x20b2a60b, 0x77e60e70, 0x95732bea, 0xe2e9d505, 0x088ce98f, 0xa837fce9)}}, + {0xff, SECP256K1_FE_CONST(0xf58cd4d9, 0x830bad32, 0x2699035e, 0x8246007d, 0x4be27e19, 0xb6f53621, 0x317b4f30, 0x9b3daa9d), SECP256K1_FE_CONST(0x78ec2b3d, 0xc0948de5, 0x60148bbc, 0x7c6dc963, 0x3ad5df70, 0xa5a5750c, 0xbed72180, 0x4f082a3b), {SECP256K1_FE_CONST(0x6c4c580b, 0x76c75940, 0x43569f9d, 0xae16dc28, 0x01c16a1f, 0xbe128608, 0x81b75f8e, 0xf929bce5), SECP256K1_FE_CONST(0x94231355, 0xe7385c5f, 0x25ca436a, 0xa6419147, 0x1aea4393, 0xd6e86ab7, 0xa35fe2af, 0xacaefd0d), SECP256K1_FE_CONST(0xdff2a195, 0x1ada6db5, 0x74df8340, 0x48149da3, 0x397a75b8, 0x29abf58c, 0x7e69db1b, 0x41ac0989), SECP256K1_FE_CONST(0xa52b66d3, 0xc9070355, 0x48028bf8, 0x04711bf4, 0x22aba95f, 0x1a666fc8, 0x6f4648e0, 0x5f29caae), SECP256K1_FE_CONST(0x93b3a7f4, 0x8938a6bf, 0xbca96062, 0x51e923d7, 0xfe3e95e0, 0x41ed79f7, 0x7e48a070, 0x06d63f4a), SECP256K1_FE_CONST(0x6bdcecaa, 0x18c7a3a0, 0xda35bc95, 0x59be6eb8, 0xe515bc6c, 0x29179548, 0x5ca01d4f, 0x5350ff22), SECP256K1_FE_CONST(0x200d5e6a, 0xe525924a, 0x8b207cbf, 0xb7eb625c, 0xc6858a47, 0xd6540a73, 0x819624e3, 0xbe53f2a6), SECP256K1_FE_CONST(0x5ad4992c, 0x36f8fcaa, 0xb7fd7407, 0xfb8ee40b, 0xdd5456a0, 0xe5999037, 0x90b9b71e, 0xa0d63181)}}, + {0x00, SECP256K1_FE_CONST(0xfd7d912a, 0x40f182a3, 0x588800d6, 0x9ebfb504, 0x8766da20, 0x6fd7ebc8, 0xd2436c81, 0xcbef6421), SECP256K1_FE_CONST(0x8d37c862, 0x054debe7, 0x31694536, 0xff46b273, 0xec122b35, 0xa9bf1445, 0xac3c4ff9, 0xf262c952), {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}}, +}; + +/* Set of (encoding, xcoord) test vectors, selected to maximize branch coverage, part of the BIP324 + * test vectors. Created using an independent implementation, and tested decoding against the paper + * authors' code. */ +static const struct ellswift_decode_test ellswift_decode_tests[] = { + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, SECP256K1_FE_CONST(0xedd1fd3e, 0x327ce90c, 0xc7a35426, 0x14289aee, 0x9682003e, 0x9cf7dcc9, 0xcf2ca974, 0x3be5aa0c), 0}, + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xd3, 0x47, 0x5b, 0xf7, 0x65, 0x5b, 0x0f, 0xb2, 0xd8, 0x52, 0x92, 0x10, 0x35, 0xb2, 0xef, 0x60, 0x7f, 0x49, 0x06, 0x9b, 0x97, 0x45, 0x4e, 0x67, 0x95, 0x25, 0x10, 0x62, 0x74, 0x17, 0x71}, SECP256K1_FE_CONST(0xb5da00b7, 0x3cd65605, 0x20e7c364, 0x086e7cd2, 0x3a34bf60, 0xd0e707be, 0x9fc34d4c, 0xd5fdfa2c), 1}, + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x27, 0x7c, 0x4a, 0x71, 0xf9, 0xd2, 0x2e, 0x66, 0xec, 0xe5, 0x23, 0xf8, 0xfa, 0x08, 0x74, 0x1a, 0x7c, 0x09, 0x12, 0xc6, 0x6a, 0x69, 0xce, 0x68, 0x51, 0x4b, 0xfd, 0x35, 0x15, 0xb4, 0x9f}, SECP256K1_FE_CONST(0xf482f2e2, 0x41753ad0, 0xfb89150d, 0x8491dc1e, 0x34ff0b8a, 0xcfbb442c, 0xfe999e2e, 0x5e6fd1d2), 1}, + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x21, 0xcc, 0x93, 0x0e, 0x77, 0xc9, 0xf5, 0x14, 0xb6, 0x91, 0x5c, 0x3d, 0xbe, 0x2a, 0x94, 0xc6, 0xd8, 0xf6, 0x90, 0xb5, 0xb7, 0x39, 0x86, 0x4b, 0xa6, 0x78, 0x9f, 0xb8, 0xa5, 0x5d, 0xd0}, SECP256K1_FE_CONST(0x9f59c402, 0x75f5085a, 0x006f05da, 0xe77eb98c, 0x6fd0db1a, 0xb4a72ac4, 0x7eae90a4, 0xfc9e57e0), 0}, + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0xe7, 0x0d, 0xf5, 0x19, 0x39, 0xb9, 0x4c, 0x9c, 0x24, 0x97, 0x9f, 0xa7, 0xdd, 0x04, 0xeb, 0xd9, 0xb3, 0x57, 0x2d, 0xa7, 0x80, 0x22, 0x90, 0x43, 0x8a, 0xf2, 0xa6, 0x81, 0x89, 0x54, 0x41}, SECP256K1_FE_CONST(0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaa9, 0xfffffd6b), 1}, + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd1, 0x9c, 0x18, 0x2d, 0x27, 0x59, 0xcd, 0x99, 0x82, 0x42, 0x28, 0xd9, 0x47, 0x99, 0xf8, 0xc6, 0x55, 0x7c, 0x38, 0xa1, 0xc0, 0xd6, 0x77, 0x9b, 0x9d, 0x4b, 0x72, 0x9c, 0x6f, 0x1c, 0xcc, 0x42}, SECP256K1_FE_CONST(0x70720db7, 0xe238d041, 0x21f5b1af, 0xd8cc5ad9, 0xd18944c6, 0xbdc94881, 0xf502b7a3, 0xaf3aecff), 0}, + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f}, SECP256K1_FE_CONST(0xedd1fd3e, 0x327ce90c, 0xc7a35426, 0x14289aee, 0x9682003e, 0x9cf7dcc9, 0xcf2ca974, 0x3be5aa0c), 0}, + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x26, 0x64, 0xbb, 0xd5}, SECP256K1_FE_CONST(0x50873db3, 0x1badcc71, 0x890e4f67, 0x753a6575, 0x7f97aaa7, 0xdd5f1e82, 0xb753ace3, 0x2219064b), 0}, + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x70, 0x28, 0xde, 0x7d}, SECP256K1_FE_CONST(0x1eea9cc5, 0x9cfcf2fa, 0x151ac6c2, 0x74eea411, 0x0feb4f7b, 0x68c59657, 0x32e9992e, 0x976ef68e), 0}, + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcb, 0xcf, 0xb7, 0xe7}, SECP256K1_FE_CONST(0x12303941, 0xaedc2088, 0x80735b1f, 0x1795c8e5, 0x5be520ea, 0x93e10335, 0x7b5d2adb, 0x7ed59b8e), 0}, + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0x11, 0x3a, 0xd9}, SECP256K1_FE_CONST(0x7eed6b70, 0xe7b0767c, 0x7d7feac0, 0x4e57aa2a, 0x12fef5e0, 0xf48f878f, 0xcbb88b3b, 0x6b5e0783), 0}, + {{0x0a, 0x2d, 0x2b, 0xa9, 0x35, 0x07, 0xf1, 0xdf, 0x23, 0x37, 0x70, 0xc2, 0xa7, 0x97, 0x96, 0x2c, 0xc6, 0x1f, 0x6d, 0x15, 0xda, 0x14, 0xec, 0xd4, 0x7d, 0x8d, 0x27, 0xae, 0x1c, 0xd5, 0xf8, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, SECP256K1_FE_CONST(0x532167c1, 0x1200b08c, 0x0e84a354, 0xe74dcc40, 0xf8b25f4f, 0xe686e308, 0x69526366, 0x278a0688), 0}, + {{0x0a, 0x2d, 0x2b, 0xa9, 0x35, 0x07, 0xf1, 0xdf, 0x23, 0x37, 0x70, 0xc2, 0xa7, 0x97, 0x96, 0x2c, 0xc6, 0x1f, 0x6d, 0x15, 0xda, 0x14, 0xec, 0xd4, 0x7d, 0x8d, 0x27, 0xae, 0x1c, 0xd5, 0xf8, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f}, SECP256K1_FE_CONST(0x532167c1, 0x1200b08c, 0x0e84a354, 0xe74dcc40, 0xf8b25f4f, 0xe686e308, 0x69526366, 0x278a0688), 0}, + {{0x0f, 0xfd, 0xe9, 0xca, 0x81, 0xd7, 0x51, 0xe9, 0xcd, 0xaf, 0xfc, 0x1a, 0x50, 0x77, 0x92, 0x45, 0x32, 0x0b, 0x28, 0x99, 0x6d, 0xba, 0xf3, 0x2f, 0x82, 0x2f, 0x20, 0x11, 0x7c, 0x22, 0xfb, 0xd6, 0xc7, 0x4d, 0x99, 0xef, 0xce, 0xaa, 0x55, 0x0f, 0x1a, 0xd1, 0xc0, 0xf4, 0x3f, 0x46, 0xe7, 0xff, 0x1e, 0xe3, 0xbd, 0x01, 0x62, 0xb7, 0xbf, 0x55, 0xf2, 0x96, 0x5d, 0xa9, 0xc3, 0x45, 0x06, 0x46}, SECP256K1_FE_CONST(0x74e880b3, 0xffd18fe3, 0xcddf7902, 0x522551dd, 0xf97fa4a3, 0x5a3cfda8, 0x197f9470, 0x81a57b8f), 0}, + {{0x0f, 0xfd, 0xe9, 0xca, 0x81, 0xd7, 0x51, 0xe9, 0xcd, 0xaf, 0xfc, 0x1a, 0x50, 0x77, 0x92, 0x45, 0x32, 0x0b, 0x28, 0x99, 0x6d, 0xba, 0xf3, 0x2f, 0x82, 0x2f, 0x20, 0x11, 0x7c, 0x22, 0xfb, 0xd6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x15, 0x6c, 0xa8, 0x96}, SECP256K1_FE_CONST(0x377b643f, 0xce2271f6, 0x4e5c8101, 0x566107c1, 0xbe498074, 0x50917838, 0x04f65478, 0x1ac9217c), 1}, + {{0x12, 0x36, 0x58, 0x44, 0x4f, 0x32, 0xbe, 0x8f, 0x02, 0xea, 0x20, 0x34, 0xaf, 0xa7, 0xef, 0x4b, 0xbe, 0x8a, 0xdc, 0x91, 0x8c, 0xeb, 0x49, 0xb1, 0x27, 0x73, 0xb6, 0x25, 0xf4, 0x90, 0xb3, 0x68, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8d, 0xc5, 0xfe, 0x11}, SECP256K1_FE_CONST(0xed16d65c, 0xf3a9538f, 0xcb2c139f, 0x1ecbc143, 0xee148271, 0x20cbc265, 0x9e667256, 0x800b8142), 0}, + {{0x14, 0x6f, 0x92, 0x46, 0x4d, 0x15, 0xd3, 0x6e, 0x35, 0x38, 0x2b, 0xd3, 0xca, 0x5b, 0x0f, 0x97, 0x6c, 0x95, 0xcb, 0x08, 0xac, 0xdc, 0xf2, 0xd5, 0xb3, 0x57, 0x06, 0x17, 0x99, 0x08, 0x39, 0xd7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x31, 0x45, 0xe9, 0x3b}, SECP256K1_FE_CONST(0x0d5cd840, 0x427f941f, 0x65193079, 0xab8e2e83, 0x024ef2ee, 0x7ca558d8, 0x8879ffd8, 0x79fb6657), 0}, + {{0x15, 0xfd, 0xf5, 0xcf, 0x09, 0xc9, 0x07, 0x59, 0xad, 0xd2, 0x27, 0x2d, 0x57, 0x4d, 0x2b, 0xb5, 0xfe, 0x14, 0x29, 0xf9, 0xf3, 0xc1, 0x4c, 0x65, 0xe3, 0x19, 0x4b, 0xf6, 0x1b, 0x82, 0xaa, 0x73, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x04, 0xcf, 0xd9, 0x06}, SECP256K1_FE_CONST(0x16d0e439, 0x46aec93f, 0x62d57eb8, 0xcde68951, 0xaf136cf4, 0xb307938d, 0xd1447411, 0xe07bffe1), 1}, + {{0x1f, 0x67, 0xed, 0xf7, 0x79, 0xa8, 0xa6, 0x49, 0xd6, 0xde, 0xf6, 0x00, 0x35, 0xf2, 0xfa, 0x22, 0xd0, 0x22, 0xdd, 0x35, 0x90, 0x79, 0xa1, 0xa1, 0x44, 0x07, 0x3d, 0x84, 0xf1, 0x9b, 0x92, 0xd5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, SECP256K1_FE_CONST(0x025661f9, 0xaba9d15c, 0x3118456b, 0xbe980e3e, 0x1b8ba2e0, 0x47c737a4, 0xeb48a040, 0xbb566f6c), 0}, + {{0x1f, 0x67, 0xed, 0xf7, 0x79, 0xa8, 0xa6, 0x49, 0xd6, 0xde, 0xf6, 0x00, 0x35, 0xf2, 0xfa, 0x22, 0xd0, 0x22, 0xdd, 0x35, 0x90, 0x79, 0xa1, 0xa1, 0x44, 0x07, 0x3d, 0x84, 0xf1, 0x9b, 0x92, 0xd5, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f}, SECP256K1_FE_CONST(0x025661f9, 0xaba9d15c, 0x3118456b, 0xbe980e3e, 0x1b8ba2e0, 0x47c737a4, 0xeb48a040, 0xbb566f6c), 0}, + {{0x1f, 0xe1, 0xe5, 0xef, 0x3f, 0xce, 0xb5, 0xc1, 0x35, 0xab, 0x77, 0x41, 0x33, 0x3c, 0xe5, 0xa6, 0xe8, 0x0d, 0x68, 0x16, 0x76, 0x53, 0xf6, 0xb2, 0xb2, 0x4b, 0xcb, 0xcf, 0xaa, 0xaf, 0xf5, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f}, SECP256K1_FE_CONST(0x98bec3b2, 0xa351fa96, 0xcfd191c1, 0x77835193, 0x1b9e9ba9, 0xad1149f6, 0xd9eadca8, 0x0981b801), 0}, + {{0x40, 0x56, 0xa3, 0x4a, 0x21, 0x0e, 0xec, 0x78, 0x92, 0xe8, 0x82, 0x06, 0x75, 0xc8, 0x60, 0x09, 0x9f, 0x85, 0x7b, 0x26, 0xaa, 0xd8, 0x54, 0x70, 0xee, 0x6d, 0x3c, 0xf1, 0x30, 0x4a, 0x9d, 0xcf, 0x37, 0x5e, 0x70, 0x37, 0x42, 0x71, 0xf2, 0x0b, 0x13, 0xc9, 0x98, 0x6e, 0xd7, 0xd3, 0xc1, 0x77, 0x99, 0x69, 0x8c, 0xfc, 0x43, 0x5d, 0xbe, 0xd3, 0xa9, 0xf3, 0x4b, 0x38, 0xc8, 0x23, 0xc2, 0xb4}, SECP256K1_FE_CONST(0x868aac20, 0x03b29dbc, 0xad1a3e80, 0x3855e078, 0xa89d1654, 0x3ac64392, 0xd1224172, 0x98cec76e), 0}, + {{0x41, 0x97, 0xec, 0x37, 0x23, 0xc6, 0x54, 0xcf, 0xdd, 0x32, 0xab, 0x07, 0x55, 0x06, 0x64, 0x8b, 0x2f, 0xf5, 0x07, 0x03, 0x62, 0xd0, 0x1a, 0x4f, 0xff, 0x14, 0xb3, 0x36, 0xb7, 0x8f, 0x96, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xb3, 0xab, 0x1e, 0x95}, SECP256K1_FE_CONST(0xba5a6314, 0x502a8952, 0xb8f456e0, 0x85928105, 0xf665377a, 0x8ce27726, 0xa5b0eb7e, 0xc1ac0286), 0}, + {{0x47, 0xeb, 0x3e, 0x20, 0x8f, 0xed, 0xcd, 0xf8, 0x23, 0x4c, 0x94, 0x21, 0xe9, 0xcd, 0x9a, 0x7a, 0xe8, 0x73, 0xbf, 0xbd, 0xbc, 0x39, 0x37, 0x23, 0xd1, 0xba, 0x1e, 0x1e, 0x6a, 0x8e, 0x6b, 0x24, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7c, 0xd1, 0x2c, 0xb1}, SECP256K1_FE_CONST(0xd192d520, 0x07e541c9, 0x807006ed, 0x0468df77, 0xfd214af0, 0xa795fe11, 0x9359666f, 0xdcf08f7c), 0}, + {{0x5e, 0xb9, 0x69, 0x6a, 0x23, 0x36, 0xfe, 0x2c, 0x3c, 0x66, 0x6b, 0x02, 0xc7, 0x55, 0xdb, 0x4c, 0x0c, 0xfd, 0x62, 0x82, 0x5c, 0x7b, 0x58, 0x9a, 0x7b, 0x7b, 0xb4, 0x42, 0xe1, 0x41, 0xc1, 0xd6, 0x93, 0x41, 0x3f, 0x00, 0x52, 0xd4, 0x9e, 0x64, 0xab, 0xec, 0x6d, 0x58, 0x31, 0xd6, 0x6c, 0x43, 0x61, 0x28, 0x30, 0xa1, 0x7d, 0xf1, 0xfe, 0x43, 0x83, 0xdb, 0x89, 0x64, 0x68, 0x10, 0x02, 0x21}, SECP256K1_FE_CONST(0xef6e1da6, 0xd6c7627e, 0x80f7a723, 0x4cb08a02, 0x2c1ee1cf, 0x29e4d0f9, 0x642ae924, 0xcef9eb38), 1}, + {{0x7b, 0xf9, 0x6b, 0x7b, 0x6d, 0xa1, 0x5d, 0x34, 0x76, 0xa2, 0xb1, 0x95, 0x93, 0x4b, 0x69, 0x0a, 0x3a, 0x3d, 0xe3, 0xe8, 0xab, 0x84, 0x74, 0x85, 0x68, 0x63, 0xb0, 0xde, 0x3a, 0xf9, 0x0b, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, SECP256K1_FE_CONST(0x50851dfc, 0x9f418c31, 0x4a437295, 0xb24feeea, 0x27af3d0c, 0xd2308348, 0xfda6e21c, 0x463e46ff), 0}, + {{0x7b, 0xf9, 0x6b, 0x7b, 0x6d, 0xa1, 0x5d, 0x34, 0x76, 0xa2, 0xb1, 0x95, 0x93, 0x4b, 0x69, 0x0a, 0x3a, 0x3d, 0xe3, 0xe8, 0xab, 0x84, 0x74, 0x85, 0x68, 0x63, 0xb0, 0xde, 0x3a, 0xf9, 0x0b, 0x0e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f}, SECP256K1_FE_CONST(0x50851dfc, 0x9f418c31, 0x4a437295, 0xb24feeea, 0x27af3d0c, 0xd2308348, 0xfda6e21c, 0x463e46ff), 0}, + {{0x85, 0x1b, 0x1c, 0xa9, 0x45, 0x49, 0x37, 0x1c, 0x4f, 0x1f, 0x71, 0x87, 0x32, 0x1d, 0x39, 0xbf, 0x51, 0xc6, 0xb7, 0xfb, 0x61, 0xf7, 0xcb, 0xf0, 0x27, 0xc9, 0xda, 0x62, 0x02, 0x1b, 0x7a, 0x65, 0xfc, 0x54, 0xc9, 0x68, 0x37, 0xfb, 0x22, 0xb3, 0x62, 0xed, 0xa6, 0x3e, 0xc5, 0x2e, 0xc8, 0x3d, 0x81, 0xbe, 0xdd, 0x16, 0x0c, 0x11, 0xb2, 0x2d, 0x96, 0x5d, 0x9f, 0x4a, 0x6d, 0x64, 0xd2, 0x51}, SECP256K1_FE_CONST(0x3e731051, 0xe12d3323, 0x7eb324f2, 0xaa5b16bb, 0x868eb49a, 0x1aa1fadc, 0x19b6e876, 0x1b5a5f7b), 1}, + {{0x94, 0x3c, 0x2f, 0x77, 0x51, 0x08, 0xb7, 0x37, 0xfe, 0x65, 0xa9, 0x53, 0x1e, 0x19, 0xf2, 0xfc, 0x2a, 0x19, 0x7f, 0x56, 0x03, 0xe3, 0xa2, 0x88, 0x1d, 0x1d, 0x83, 0xe4, 0x00, 0x8f, 0x91, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, SECP256K1_FE_CONST(0x311c61f0, 0xab2f32b7, 0xb1f0223f, 0xa72f0a78, 0x752b8146, 0xe46107f8, 0x876dd9c4, 0xf92b2942), 0}, + {{0x94, 0x3c, 0x2f, 0x77, 0x51, 0x08, 0xb7, 0x37, 0xfe, 0x65, 0xa9, 0x53, 0x1e, 0x19, 0xf2, 0xfc, 0x2a, 0x19, 0x7f, 0x56, 0x03, 0xe3, 0xa2, 0x88, 0x1d, 0x1d, 0x83, 0xe4, 0x00, 0x8f, 0x91, 0x25, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f}, SECP256K1_FE_CONST(0x311c61f0, 0xab2f32b7, 0xb1f0223f, 0xa72f0a78, 0x752b8146, 0xe46107f8, 0x876dd9c4, 0xf92b2942), 0}, + {{0xa0, 0xf1, 0x84, 0x92, 0x18, 0x3e, 0x61, 0xe8, 0x06, 0x3e, 0x57, 0x36, 0x06, 0x59, 0x14, 0x21, 0xb0, 0x6b, 0xc3, 0x51, 0x36, 0x31, 0x57, 0x8a, 0x73, 0xa3, 0x9c, 0x1c, 0x33, 0x06, 0x23, 0x9f, 0x2f, 0x32, 0x90, 0x4f, 0x0d, 0x2a, 0x33, 0xec, 0xca, 0x8a, 0x54, 0x51, 0x70, 0x5b, 0xb5, 0x37, 0xd3, 0xbf, 0x44, 0xe0, 0x71, 0x22, 0x60, 0x25, 0xcd, 0xbf, 0xd2, 0x49, 0xfe, 0x0f, 0x7a, 0xd6}, SECP256K1_FE_CONST(0x97a09cf1, 0xa2eae7c4, 0x94df3c6f, 0x8a9445bf, 0xb8c09d60, 0x832f9b0b, 0x9d5eabe2, 0x5fbd14b9), 0}, + {{0xa1, 0xed, 0x0a, 0x0b, 0xd7, 0x9d, 0x8a, 0x23, 0xcf, 0xe4, 0xec, 0x5f, 0xef, 0x5b, 0xa5, 0xcc, 0xcf, 0xd8, 0x44, 0xe4, 0xff, 0x5c, 0xb4, 0xb0, 0xf2, 0xe7, 0x16, 0x27, 0x34, 0x1f, 0x1c, 0x5b, 0x17, 0xc4, 0x99, 0x24, 0x9e, 0x0a, 0xc0, 0x8d, 0x5d, 0x11, 0xea, 0x1c, 0x2c, 0x8c, 0xa7, 0x00, 0x16, 0x16, 0x55, 0x9a, 0x79, 0x94, 0xea, 0xde, 0xc9, 0xca, 0x10, 0xfb, 0x4b, 0x85, 0x16, 0xdc}, SECP256K1_FE_CONST(0x65a89640, 0x744192cd, 0xac64b2d2, 0x1ddf989c, 0xdac75007, 0x25b645be, 0xf8e2200a, 0xe39691f2), 0}, + {{0xba, 0x94, 0x59, 0x4a, 0x43, 0x27, 0x21, 0xaa, 0x35, 0x80, 0xb8, 0x4c, 0x16, 0x1d, 0x0d, 0x13, 0x4b, 0xc3, 0x54, 0xb6, 0x90, 0x40, 0x4d, 0x7c, 0xd4, 0xec, 0x57, 0xc1, 0x6d, 0x3f, 0xbe, 0x98, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xea, 0x50, 0x7d, 0xd7}, SECP256K1_FE_CONST(0x5e0d7656, 0x4aae92cb, 0x347e01a6, 0x2afd389a, 0x9aa401c7, 0x6c8dd227, 0x543dc9cd, 0x0efe685a), 0}, + {{0xbc, 0xaf, 0x72, 0x19, 0xf2, 0xf6, 0xfb, 0xf5, 0x5f, 0xe5, 0xe0, 0x62, 0xdc, 0xe0, 0xe4, 0x8c, 0x18, 0xf6, 0x81, 0x03, 0xf1, 0x0b, 0x81, 0x98, 0xe9, 0x74, 0xc1, 0x84, 0x75, 0x0e, 0x1b, 0xe3, 0x93, 0x20, 0x16, 0xcb, 0xf6, 0x9c, 0x44, 0x71, 0xbd, 0x1f, 0x65, 0x6c, 0x6a, 0x10, 0x7f, 0x19, 0x73, 0xde, 0x4a, 0xf7, 0x08, 0x6d, 0xb8, 0x97, 0x27, 0x70, 0x60, 0xe2, 0x56, 0x77, 0xf1, 0x9a}, SECP256K1_FE_CONST(0x2d97f96c, 0xac882dfe, 0x73dc44db, 0x6ce0f1d3, 0x1d624135, 0x8dd5d74e, 0xb3d3b500, 0x03d24c2b), 0}, + {{0xbc, 0xaf, 0x72, 0x19, 0xf2, 0xf6, 0xfb, 0xf5, 0x5f, 0xe5, 0xe0, 0x62, 0xdc, 0xe0, 0xe4, 0x8c, 0x18, 0xf6, 0x81, 0x03, 0xf1, 0x0b, 0x81, 0x98, 0xe9, 0x74, 0xc1, 0x84, 0x75, 0x0e, 0x1b, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x65, 0x07, 0xd0, 0x9a}, SECP256K1_FE_CONST(0xe7008afe, 0x6e8cbd50, 0x55df120b, 0xd748757c, 0x686dadb4, 0x1cce75e4, 0xaddcc5e0, 0x2ec02b44), 1}, + {{0xc5, 0x98, 0x1b, 0xae, 0x27, 0xfd, 0x84, 0x40, 0x1c, 0x72, 0xa1, 0x55, 0xe5, 0x70, 0x7f, 0xbb, 0x81, 0x1b, 0x2b, 0x62, 0x06, 0x45, 0xd1, 0x02, 0x8e, 0xa2, 0x70, 0xcb, 0xe0, 0xee, 0x22, 0x5d, 0x4b, 0x62, 0xaa, 0x4d, 0xca, 0x65, 0x06, 0xc1, 0xac, 0xdb, 0xec, 0xc0, 0x55, 0x25, 0x69, 0xb4, 0xb2, 0x14, 0x36, 0xa5, 0x69, 0x2e, 0x25, 0xd9, 0x0d, 0x3b, 0xc2, 0xeb, 0x7c, 0xe2, 0x40, 0x78}, SECP256K1_FE_CONST(0x948b40e7, 0x181713bc, 0x018ec170, 0x2d3d054d, 0x15746c59, 0xa7020730, 0xdd13ecf9, 0x85a010d7), 0}, + {{0xc8, 0x94, 0xce, 0x48, 0xbf, 0xec, 0x43, 0x30, 0x14, 0xb9, 0x31, 0xa6, 0xad, 0x42, 0x26, 0xd7, 0xdb, 0xd8, 0xea, 0xa7, 0xb6, 0xe3, 0xfa, 0xa8, 0xd0, 0xef, 0x94, 0x05, 0x2b, 0xcf, 0x8c, 0xff, 0x33, 0x6e, 0xeb, 0x39, 0x19, 0xe2, 0xb4, 0xef, 0xb7, 0x46, 0xc7, 0xf7, 0x1b, 0xbc, 0xa7, 0xe9, 0x38, 0x32, 0x30, 0xfb, 0xbc, 0x48, 0xff, 0xaf, 0xe7, 0x7e, 0x8b, 0xcc, 0x69, 0x54, 0x24, 0x71}, SECP256K1_FE_CONST(0xf1c91acd, 0xc2525330, 0xf9b53158, 0x434a4d43, 0xa1c547cf, 0xf29f1550, 0x6f5da4eb, 0x4fe8fa5a), 1}, + {{0xcb, 0xb0, 0xde, 0xab, 0x12, 0x57, 0x54, 0xf1, 0xfd, 0xb2, 0x03, 0x8b, 0x04, 0x34, 0xed, 0x9c, 0xb3, 0xfb, 0x53, 0xab, 0x73, 0x53, 0x91, 0x12, 0x99, 0x94, 0xa5, 0x35, 0xd9, 0x25, 0xf6, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, SECP256K1_FE_CONST(0x872d81ed, 0x8831d999, 0x8b67cb71, 0x05243edb, 0xf86c10ed, 0xfebb786c, 0x110b02d0, 0x7b2e67cd), 0}, + {{0xd9, 0x17, 0xb7, 0x86, 0xda, 0xc3, 0x56, 0x70, 0xc3, 0x30, 0xc9, 0xc5, 0xae, 0x59, 0x71, 0xdf, 0xb4, 0x95, 0xc8, 0xae, 0x52, 0x3e, 0xd9, 0x7e, 0xe2, 0x42, 0x01, 0x17, 0xb1, 0x71, 0xf4, 0x1e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x20, 0x01, 0xf6, 0xf6}, SECP256K1_FE_CONST(0xe45b71e1, 0x10b831f2, 0xbdad8651, 0x994526e5, 0x8393fde4, 0x328b1ec0, 0x4d598971, 0x42584691), 1}, + {{0xe2, 0x8b, 0xd8, 0xf5, 0x92, 0x9b, 0x46, 0x7e, 0xb7, 0x0e, 0x04, 0x33, 0x23, 0x74, 0xff, 0xb7, 0xe7, 0x18, 0x02, 0x18, 0xad, 0x16, 0xea, 0xa4, 0x6b, 0x71, 0x61, 0xaa, 0x67, 0x9e, 0xb4, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, SECP256K1_FE_CONST(0x66b8c980, 0xa75c72e5, 0x98d383a3, 0x5a62879f, 0x844242ad, 0x1e73ff12, 0xedaa59f4, 0xe58632b5), 0}, + {{0xe2, 0x8b, 0xd8, 0xf5, 0x92, 0x9b, 0x46, 0x7e, 0xb7, 0x0e, 0x04, 0x33, 0x23, 0x74, 0xff, 0xb7, 0xe7, 0x18, 0x02, 0x18, 0xad, 0x16, 0xea, 0xa4, 0x6b, 0x71, 0x61, 0xaa, 0x67, 0x9e, 0xb4, 0x26, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f}, SECP256K1_FE_CONST(0x66b8c980, 0xa75c72e5, 0x98d383a3, 0x5a62879f, 0x844242ad, 0x1e73ff12, 0xedaa59f4, 0xe58632b5), 0}, + {{0xe7, 0xee, 0x58, 0x14, 0xc1, 0x70, 0x6b, 0xf8, 0xa8, 0x93, 0x96, 0xa9, 0xb0, 0x32, 0xbc, 0x01, 0x4c, 0x2c, 0xac, 0x9c, 0x12, 0x11, 0x27, 0xdb, 0xf6, 0xc9, 0x92, 0x78, 0xf8, 0xbb, 0x53, 0xd1, 0xdf, 0xd0, 0x4d, 0xbc, 0xda, 0x8e, 0x35, 0x24, 0x66, 0xb6, 0xfc, 0xd5, 0xf2, 0xde, 0xa3, 0xe1, 0x7d, 0x5e, 0x13, 0x31, 0x15, 0x88, 0x6e, 0xda, 0x20, 0xdb, 0x8a, 0x12, 0xb5, 0x4d, 0xe7, 0x1b}, SECP256K1_FE_CONST(0xe842c6e3, 0x529b2342, 0x70a5e977, 0x44edc34a, 0x04d7ba94, 0xe44b6d25, 0x23c9cf01, 0x95730a50), 1}, + {{0xf2, 0x92, 0xe4, 0x68, 0x25, 0xf9, 0x22, 0x5a, 0xd2, 0x3d, 0xc0, 0x57, 0xc1, 0xd9, 0x1c, 0x4f, 0x57, 0xfc, 0xb1, 0x38, 0x6f, 0x29, 0xef, 0x10, 0x48, 0x1c, 0xb1, 0xd2, 0x25, 0x18, 0x59, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x70, 0x11, 0xc9, 0x89}, SECP256K1_FE_CONST(0x3cea2c53, 0xb8b01701, 0x66ac7da6, 0x7194694a, 0xdacc84d5, 0x6389225e, 0x330134da, 0xb85a4d55), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, SECP256K1_FE_CONST(0xedd1fd3e, 0x327ce90c, 0xc7a35426, 0x14289aee, 0x9682003e, 0x9cf7dcc9, 0xcf2ca974, 0x3be5aa0c), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f, 0x01, 0xd3, 0x47, 0x5b, 0xf7, 0x65, 0x5b, 0x0f, 0xb2, 0xd8, 0x52, 0x92, 0x10, 0x35, 0xb2, 0xef, 0x60, 0x7f, 0x49, 0x06, 0x9b, 0x97, 0x45, 0x4e, 0x67, 0x95, 0x25, 0x10, 0x62, 0x74, 0x17, 0x71}, SECP256K1_FE_CONST(0xb5da00b7, 0x3cd65605, 0x20e7c364, 0x086e7cd2, 0x3a34bf60, 0xd0e707be, 0x9fc34d4c, 0xd5fdfa2c), 1}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f, 0x42, 0x18, 0xf2, 0x0a, 0xe6, 0xc6, 0x46, 0xb3, 0x63, 0xdb, 0x68, 0x60, 0x58, 0x22, 0xfb, 0x14, 0x26, 0x4c, 0xa8, 0xd2, 0x58, 0x7f, 0xdd, 0x6f, 0xbc, 0x75, 0x0d, 0x58, 0x7e, 0x76, 0xa7, 0xee}, SECP256K1_FE_CONST(0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaa9, 0xfffffd6b), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f, 0x82, 0x27, 0x7c, 0x4a, 0x71, 0xf9, 0xd2, 0x2e, 0x66, 0xec, 0xe5, 0x23, 0xf8, 0xfa, 0x08, 0x74, 0x1a, 0x7c, 0x09, 0x12, 0xc6, 0x6a, 0x69, 0xce, 0x68, 0x51, 0x4b, 0xfd, 0x35, 0x15, 0xb4, 0x9f}, SECP256K1_FE_CONST(0xf482f2e2, 0x41753ad0, 0xfb89150d, 0x8491dc1e, 0x34ff0b8a, 0xcfbb442c, 0xfe999e2e, 0x5e6fd1d2), 1}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f, 0x84, 0x21, 0xcc, 0x93, 0x0e, 0x77, 0xc9, 0xf5, 0x14, 0xb6, 0x91, 0x5c, 0x3d, 0xbe, 0x2a, 0x94, 0xc6, 0xd8, 0xf6, 0x90, 0xb5, 0xb7, 0x39, 0x86, 0x4b, 0xa6, 0x78, 0x9f, 0xb8, 0xa5, 0x5d, 0xd0}, SECP256K1_FE_CONST(0x9f59c402, 0x75f5085a, 0x006f05da, 0xe77eb98c, 0x6fd0db1a, 0xb4a72ac4, 0x7eae90a4, 0xfc9e57e0), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f, 0xd1, 0x9c, 0x18, 0x2d, 0x27, 0x59, 0xcd, 0x99, 0x82, 0x42, 0x28, 0xd9, 0x47, 0x99, 0xf8, 0xc6, 0x55, 0x7c, 0x38, 0xa1, 0xc0, 0xd6, 0x77, 0x9b, 0x9d, 0x4b, 0x72, 0x9c, 0x6f, 0x1c, 0xcc, 0x42}, SECP256K1_FE_CONST(0x70720db7, 0xe238d041, 0x21f5b1af, 0xd8cc5ad9, 0xd18944c6, 0xbdc94881, 0xf502b7a3, 0xaf3aecff), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f}, SECP256K1_FE_CONST(0xedd1fd3e, 0x327ce90c, 0xc7a35426, 0x14289aee, 0x9682003e, 0x9cf7dcc9, 0xcf2ca974, 0x3be5aa0c), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x26, 0x64, 0xbb, 0xd5}, SECP256K1_FE_CONST(0x50873db3, 0x1badcc71, 0x890e4f67, 0x753a6575, 0x7f97aaa7, 0xdd5f1e82, 0xb753ace3, 0x2219064b), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x70, 0x28, 0xde, 0x7d}, SECP256K1_FE_CONST(0x1eea9cc5, 0x9cfcf2fa, 0x151ac6c2, 0x74eea411, 0x0feb4f7b, 0x68c59657, 0x32e9992e, 0x976ef68e), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcb, 0xcf, 0xb7, 0xe7}, SECP256K1_FE_CONST(0x12303941, 0xaedc2088, 0x80735b1f, 0x1795c8e5, 0x5be520ea, 0x93e10335, 0x7b5d2adb, 0x7ed59b8e), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0x11, 0x3a, 0xd9}, SECP256K1_FE_CONST(0x7eed6b70, 0xe7b0767c, 0x7d7feac0, 0x4e57aa2a, 0x12fef5e0, 0xf48f878f, 0xcbb88b3b, 0x6b5e0783), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x13, 0xce, 0xa4, 0xa7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, SECP256K1_FE_CONST(0x64998443, 0x5b62b4a2, 0x5d40c613, 0x3e8d9ab8, 0xc53d4b05, 0x9ee8a154, 0xa3be0fcf, 0x4e892edb), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x13, 0xce, 0xa4, 0xa7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f}, SECP256K1_FE_CONST(0x64998443, 0x5b62b4a2, 0x5d40c613, 0x3e8d9ab8, 0xc53d4b05, 0x9ee8a154, 0xa3be0fcf, 0x4e892edb), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x15, 0x02, 0x8c, 0x59, 0x00, 0x63, 0xf6, 0x4d, 0x5a, 0x7f, 0x1c, 0x14, 0x91, 0x5c, 0xd6, 0x1e, 0xac, 0x88, 0x6a, 0xb2, 0x95, 0xbe, 0xbd, 0x91, 0x99, 0x25, 0x04, 0xcf, 0x77, 0xed, 0xb0, 0x28, 0xbd, 0xd6, 0x26, 0x7f}, SECP256K1_FE_CONST(0x3fde5713, 0xf8282eea, 0xd7d39d42, 0x01f44a7c, 0x85a5ac8a, 0x0681f35e, 0x54085c6b, 0x69543374), 1}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x27, 0x15, 0xde, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, SECP256K1_FE_CONST(0x3524f77f, 0xa3a6eb43, 0x89c3cb5d, 0x27f1f914, 0x62086429, 0xcd6c0cb0, 0xdf43ea8f, 0x1e7b3fb4), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x27, 0x15, 0xde, 0x86, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f}, SECP256K1_FE_CONST(0x3524f77f, 0xa3a6eb43, 0x89c3cb5d, 0x27f1f914, 0x62086429, 0xcd6c0cb0, 0xdf43ea8f, 0x1e7b3fb4), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x2c, 0x2c, 0x57, 0x09, 0xe7, 0x15, 0x6c, 0x41, 0x77, 0x17, 0xf2, 0xfe, 0xab, 0x14, 0x71, 0x41, 0xec, 0x3d, 0xa1, 0x9f, 0xb7, 0x59, 0x57, 0x5c, 0xc6, 0xe3, 0x7b, 0x2e, 0xa5, 0xac, 0x93, 0x09, 0xf2, 0x6f, 0x0f, 0x66}, SECP256K1_FE_CONST(0xd2469ab3, 0xe04acbb2, 0x1c65a180, 0x9f39caaf, 0xe7a77c13, 0xd10f9dd3, 0x8f391c01, 0xdc499c52), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3a, 0x08, 0xcc, 0x1e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0x60, 0xe9, 0xf0}, SECP256K1_FE_CONST(0x38e2a5ce, 0x6a93e795, 0xe16d2c39, 0x8bc99f03, 0x69202ce2, 0x1e8f09d5, 0x6777b40f, 0xc512bccc), 1}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3e, 0x91, 0x25, 0x7d, 0x93, 0x20, 0x16, 0xcb, 0xf6, 0x9c, 0x44, 0x71, 0xbd, 0x1f, 0x65, 0x6c, 0x6a, 0x10, 0x7f, 0x19, 0x73, 0xde, 0x4a, 0xf7, 0x08, 0x6d, 0xb8, 0x97, 0x27, 0x70, 0x60, 0xe2, 0x56, 0x77, 0xf1, 0x9a}, SECP256K1_FE_CONST(0x864b3dc9, 0x02c37670, 0x9c10a93a, 0xd4bbe29f, 0xce0012f3, 0xdc8672c6, 0x286bba28, 0xd7d6d6fc), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x79, 0x5d, 0x6c, 0x1c, 0x32, 0x2c, 0xad, 0xf5, 0x99, 0xdb, 0xb8, 0x64, 0x81, 0x52, 0x2b, 0x3c, 0xc5, 0x5f, 0x15, 0xa6, 0x79, 0x32, 0xdb, 0x2a, 0xfa, 0x01, 0x11, 0xd9, 0xed, 0x69, 0x81, 0xbc, 0xd1, 0x24, 0xbf, 0x44}, SECP256K1_FE_CONST(0x766dfe4a, 0x700d9bee, 0x288b903a, 0xd58870e3, 0xd4fe2f0e, 0xf780bcac, 0x5c823f32, 0x0d9a9bef), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8e, 0x42, 0x6f, 0x03, 0x92, 0x38, 0x90, 0x78, 0xc1, 0x2b, 0x1a, 0x89, 0xe9, 0x54, 0x2f, 0x05, 0x93, 0xbc, 0x96, 0xb6, 0xbf, 0xde, 0x82, 0x24, 0xf8, 0x65, 0x4e, 0xf5, 0xd5, 0xcd, 0xa9, 0x35, 0xa3, 0x58, 0x21, 0x94}, SECP256K1_FE_CONST(0xfaec7bc1, 0x987b6323, 0x3fbc5f95, 0x6edbf37d, 0x54404e74, 0x61c58ab8, 0x631bc68e, 0x451a0478), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x91, 0x19, 0x21, 0x39, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x45, 0xf0, 0xf1, 0xeb}, SECP256K1_FE_CONST(0xec29a50b, 0xae138dbf, 0x7d8e2482, 0x5006bb5f, 0xc1a2cc12, 0x43ba335b, 0xc6116fb9, 0xe498ec1f), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x98, 0xeb, 0x9a, 0xb7, 0x6e, 0x84, 0x49, 0x9c, 0x48, 0x3b, 0x3b, 0xf0, 0x62, 0x14, 0xab, 0xfe, 0x06, 0x5d, 0xdd, 0xf4, 0x3b, 0x86, 0x01, 0xde, 0x59, 0x6d, 0x63, 0xb9, 0xe4, 0x5a, 0x16, 0x6a, 0x58, 0x05, 0x41, 0xfe}, SECP256K1_FE_CONST(0x1e0ff2de, 0xe9b09b13, 0x6292a9e9, 0x10f0d6ac, 0x3e552a64, 0x4bba39e6, 0x4e9dd3e3, 0xbbd3d4d4), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x9b, 0x77, 0xb7, 0xf2, 0xc7, 0x4d, 0x99, 0xef, 0xce, 0xaa, 0x55, 0x0f, 0x1a, 0xd1, 0xc0, 0xf4, 0x3f, 0x46, 0xe7, 0xff, 0x1e, 0xe3, 0xbd, 0x01, 0x62, 0xb7, 0xbf, 0x55, 0xf2, 0x96, 0x5d, 0xa9, 0xc3, 0x45, 0x06, 0x46}, SECP256K1_FE_CONST(0x8b7dd5c3, 0xedba9ee9, 0x7b70eff4, 0x38f22dca, 0x9849c825, 0x4a2f3345, 0xa0a572ff, 0xeaae0928), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x9b, 0x77, 0xb7, 0xf2, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x15, 0x6c, 0xa8, 0x96}, SECP256K1_FE_CONST(0x0881950c, 0x8f51d6b9, 0xa6387465, 0xd5f12609, 0xef1bb254, 0x12a08a74, 0xcb2dfb20, 0x0c74bfbf), 1}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa2, 0xf5, 0xcd, 0x83, 0x88, 0x16, 0xc1, 0x6c, 0x4f, 0xe8, 0xa1, 0x66, 0x1d, 0x60, 0x6f, 0xdb, 0x13, 0xcf, 0x9a, 0xf0, 0x4b, 0x97, 0x9a, 0x2e, 0x15, 0x9a, 0x09, 0x40, 0x9e, 0xbc, 0x86, 0x45, 0xd5, 0x8f, 0xde, 0x02}, SECP256K1_FE_CONST(0x2f083207, 0xb9fd9b55, 0x0063c31c, 0xd62b8746, 0xbd543bdc, 0x5bbf10e3, 0xa35563e9, 0x27f440c8), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xb1, 0x3f, 0x75, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, SECP256K1_FE_CONST(0x4f51e0be, 0x078e0cdd, 0xab274215, 0x6adba7e7, 0xa148e731, 0x57072fd6, 0x18cd6094, 0x2b146bd0), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xb1, 0x3f, 0x75, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f}, SECP256K1_FE_CONST(0x4f51e0be, 0x078e0cdd, 0xab274215, 0x6adba7e7, 0xa148e731, 0x57072fd6, 0x18cd6094, 0x2b146bd0), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xbc, 0x1f, 0x8d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, SECP256K1_FE_CONST(0x16c2ccb5, 0x4352ff4b, 0xd794f6ef, 0xd613c721, 0x97ab7082, 0xda5b563b, 0xdf9cb3ed, 0xaafe74c2), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xbc, 0x1f, 0x8d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f}, SECP256K1_FE_CONST(0x16c2ccb5, 0x4352ff4b, 0xd794f6ef, 0xd613c721, 0x97ab7082, 0xda5b563b, 0xdf9cb3ed, 0xaafe74c2), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xef, 0x64, 0xd1, 0x62, 0x75, 0x05, 0x46, 0xce, 0x42, 0xb0, 0x43, 0x13, 0x61, 0xe5, 0x2d, 0x4f, 0x52, 0x42, 0xd8, 0xf2, 0x4f, 0x33, 0xe6, 0xb1, 0xf9, 0x9b, 0x59, 0x16, 0x47, 0xcb, 0xc8, 0x08, 0xf4, 0x62, 0xaf, 0x51}, SECP256K1_FE_CONST(0xd41244d1, 0x1ca4f652, 0x40687759, 0xf95ca9ef, 0xbab767ed, 0xedb38fd1, 0x8c36e18c, 0xd3b6f6a9), 1}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xe5, 0xbe, 0x52, 0x37, 0x2d, 0xd6, 0xe8, 0x94, 0xb2, 0xa3, 0x26, 0xfc, 0x36, 0x05, 0xa6, 0xe8, 0xf3, 0xc6, 0x9c, 0x71, 0x0b, 0xf2, 0x7d, 0x63, 0x0d, 0xfe, 0x20, 0x04, 0x98, 0x8b, 0x78, 0xeb, 0x6e, 0xab, 0x36}, SECP256K1_FE_CONST(0x64bf84dd, 0x5e03670f, 0xdb24c0f5, 0xd3c2c365, 0x736f51db, 0x6c92d950, 0x10716ad2, 0xd36134c8), 0}, + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfb, 0xb9, 0x82, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf6, 0xd6, 0xdb, 0x1f}, SECP256K1_FE_CONST(0x1c92ccdf, 0xcf4ac550, 0xc28db57c, 0xff0c8515, 0xcb26936c, 0x786584a7, 0x0114008d, 0x6c33a34b), 0}, +}; + +/* Set of expected ellswift_xdh BIP324 shared secrets, given private key, encodings, initiating, + * taken from the BIP324 test vectors. Created using an independent implementation, and tested + * against the paper authors' decoding code. */ +static const struct ellswift_xdh_test ellswift_xdh_tests_bip324[] = { + {{0x61, 0x06, 0x2e, 0xa5, 0x07, 0x1d, 0x80, 0x0b, 0xbf, 0xd5, 0x9e, 0x2e, 0x8b, 0x53, 0xd4, 0x7d, 0x19, 0x4b, 0x09, 0x5a, 0xe5, 0xa4, 0xdf, 0x04, 0x93, 0x6b, 0x49, 0x77, 0x2e, 0xf0, 0xd4, 0xd7}, {0xec, 0x0a, 0xdf, 0xf2, 0x57, 0xbb, 0xfe, 0x50, 0x0c, 0x18, 0x8c, 0x80, 0xb4, 0xfd, 0xd6, 0x40, 0xf6, 0xb4, 0x5a, 0x48, 0x2b, 0xbc, 0x15, 0xfc, 0x7c, 0xef, 0x59, 0x31, 0xde, 0xff, 0x0a, 0xa1, 0x86, 0xf6, 0xeb, 0x9b, 0xba, 0x7b, 0x85, 0xdc, 0x4d, 0xcc, 0x28, 0xb2, 0x87, 0x22, 0xde, 0x1e, 0x3d, 0x91, 0x08, 0xb9, 0x85, 0xe2, 0x96, 0x70, 0x45, 0x66, 0x8f, 0x66, 0x09, 0x8e, 0x47, 0x5b}, {0xa4, 0xa9, 0x4d, 0xfc, 0xe6, 0x9b, 0x4a, 0x2a, 0x0a, 0x09, 0x93, 0x13, 0xd1, 0x0f, 0x9f, 0x7e, 0x7d, 0x64, 0x9d, 0x60, 0x50, 0x1c, 0x9e, 0x1d, 0x27, 0x4c, 0x30, 0x0e, 0x0d, 0x89, 0xaa, 0xfa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, 0xaf, 0x88, 0xd5}, 1, {0xc6, 0x99, 0x2a, 0x11, 0x7f, 0x5e, 0xdb, 0xea, 0x70, 0xc3, 0xf5, 0x11, 0xd3, 0x2d, 0x26, 0xb9, 0x79, 0x8b, 0xe4, 0xb8, 0x1a, 0x62, 0xea, 0xee, 0x1a, 0x5a, 0xca, 0xa8, 0x45, 0x9a, 0x35, 0x92}}, + {{0x1f, 0x9c, 0x58, 0x1b, 0x35, 0x23, 0x18, 0x38, 0xf0, 0xf1, 0x7c, 0xf0, 0xc9, 0x79, 0x83, 0x5b, 0xac, 0xcb, 0x7f, 0x3a, 0xbb, 0xbb, 0x96, 0xff, 0xcc, 0x31, 0x8a, 0xb7, 0x1e, 0x6e, 0x12, 0x6f}, {0xa1, 0x85, 0x5e, 0x10, 0xe9, 0x4e, 0x00, 0xba, 0xa2, 0x30, 0x41, 0xd9, 0x16, 0xe2, 0x59, 0xf7, 0x04, 0x4e, 0x49, 0x1d, 0xa6, 0x17, 0x12, 0x69, 0x69, 0x47, 0x63, 0xf0, 0x18, 0xc7, 0xe6, 0x36, 0x93, 0xd2, 0x95, 0x75, 0xdc, 0xb4, 0x64, 0xac, 0x81, 0x6b, 0xaa, 0x1b, 0xe3, 0x53, 0xba, 0x12, 0xe3, 0x87, 0x6c, 0xba, 0x76, 0x28, 0xbd, 0x0b, 0xd8, 0xe7, 0x55, 0xe7, 0x21, 0xeb, 0x01, 0x40}, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0, {0xa0, 0x13, 0x8f, 0x56, 0x4f, 0x74, 0xd0, 0xad, 0x70, 0xbc, 0x33, 0x7d, 0xac, 0xc9, 0xd0, 0xbf, 0x1d, 0x23, 0x49, 0x36, 0x4c, 0xaf, 0x11, 0x88, 0xa1, 0xe6, 0xe8, 0xdd, 0xb3, 0xb7, 0xb1, 0x84}}, + {{0x02, 0x86, 0xc4, 0x1c, 0xd3, 0x09, 0x13, 0xdb, 0x0f, 0xdf, 0xf7, 0xa6, 0x4e, 0xbd, 0xa5, 0xc8, 0xe3, 0xe7, 0xce, 0xf1, 0x0f, 0x2a, 0xeb, 0xc0, 0x0a, 0x76, 0x50, 0x44, 0x3c, 0xf4, 0xc6, 0x0d}, {0xd1, 0xee, 0x8a, 0x93, 0xa0, 0x11, 0x30, 0xcb, 0xf2, 0x99, 0x24, 0x9a, 0x25, 0x8f, 0x94, 0xfe, 0xb5, 0xf4, 0x69, 0xe7, 0xd0, 0xf2, 0xf2, 0x8f, 0x69, 0xee, 0x5e, 0x9a, 0xa8, 0xf9, 0xb5, 0x4a, 0x60, 0xf2, 0xc3, 0xff, 0x2d, 0x02, 0x36, 0x34, 0xec, 0x7f, 0x41, 0x27, 0xa9, 0x6c, 0xc1, 0x16, 0x62, 0xe4, 0x02, 0x89, 0x4c, 0xf1, 0xf6, 0x94, 0xfb, 0x9a, 0x7e, 0xaa, 0x5f, 0x1d, 0x92, 0x44}, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x22, 0xd5, 0xe4, 0x41, 0x52, 0x4d, 0x57, 0x1a, 0x52, 0xb3, 0xde, 0xf1, 0x26, 0x18, 0x9d, 0x3f, 0x41, 0x68, 0x90, 0xa9, 0x9d, 0x4d, 0xa6, 0xed, 0xe2, 0xb0, 0xcd, 0xe1, 0x76, 0x0c, 0xe2, 0xc3, 0xf9, 0x84, 0x57, 0xae}, 1, {0x25, 0x0b, 0x93, 0x57, 0x0d, 0x41, 0x11, 0x49, 0x10, 0x5a, 0xb8, 0xcb, 0x0b, 0xc5, 0x07, 0x99, 0x14, 0x90, 0x63, 0x06, 0x36, 0x8c, 0x23, 0xe9, 0xd7, 0x7c, 0x2a, 0x33, 0x26, 0x5b, 0x99, 0x4c}}, + {{0x6c, 0x77, 0x43, 0x2d, 0x1f, 0xda, 0x31, 0xe9, 0xf9, 0x42, 0xf8, 0xaf, 0x44, 0x60, 0x7e, 0x10, 0xf3, 0xad, 0x38, 0xa6, 0x5f, 0x8a, 0x4b, 0xdd, 0xae, 0x82, 0x3e, 0x5e, 0xff, 0x90, 0xdc, 0x38}, {0xd2, 0x68, 0x50, 0x70, 0xc1, 0xe6, 0x37, 0x6e, 0x63, 0x3e, 0x82, 0x52, 0x96, 0x63, 0x4f, 0xd4, 0x61, 0xfa, 0x9e, 0x5b, 0xdf, 0x21, 0x09, 0xbc, 0xeb, 0xd7, 0x35, 0xe5, 0xa9, 0x1f, 0x3e, 0x58, 0x7c, 0x5c, 0xb7, 0x82, 0xab, 0xb7, 0x97, 0xfb, 0xf6, 0xbb, 0x50, 0x74, 0xfd, 0x15, 0x42, 0xa4, 0x74, 0xf2, 0xa4, 0x5b, 0x67, 0x37, 0x63, 0xec, 0x2d, 0xb7, 0xfb, 0x99, 0xb7, 0x37, 0xbb, 0xb9}, {0x56, 0xbd, 0x0c, 0x06, 0xf1, 0x03, 0x52, 0xc3, 0xa1, 0xa9, 0xf4, 0xb4, 0xc9, 0x2f, 0x6f, 0xa2, 0xb2, 0x6d, 0xf1, 0x24, 0xb5, 0x78, 0x78, 0x35, 0x3c, 0x1f, 0xc6, 0x91, 0xc5, 0x1a, 0xbe, 0xa7, 0x7c, 0x88, 0x17, 0xda, 0xee, 0xb9, 0xfa, 0x54, 0x6b, 0x77, 0xc8, 0xda, 0xf7, 0x9d, 0x89, 0xb2, 0x2b, 0x0e, 0x1b, 0x87, 0x57, 0x4e, 0xce, 0x42, 0x37, 0x1f, 0x00, 0x23, 0x7a, 0xa9, 0xd8, 0x3a}, 0, {0x19, 0x18, 0xb7, 0x41, 0xef, 0x5f, 0x9d, 0x1d, 0x76, 0x70, 0xb0, 0x50, 0xc1, 0x52, 0xb4, 0xa4, 0xea, 0xd2, 0xc3, 0x1b, 0xe9, 0xae, 0xcb, 0x06, 0x81, 0xc0, 0xcd, 0x43, 0x24, 0x15, 0x08, 0x53}}, + {{0xa6, 0xec, 0x25, 0x12, 0x7c, 0xa1, 0xaa, 0x4c, 0xf1, 0x6b, 0x20, 0x08, 0x4b, 0xa1, 0xe6, 0x51, 0x6b, 0xaa, 0xe4, 0xd3, 0x24, 0x22, 0x28, 0x8e, 0x9b, 0x36, 0xd8, 0xbd, 0xdd, 0x2d, 0xe3, 0x5a}, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x05, 0x3d, 0x7e, 0xcc, 0xa5, 0x3e, 0x33, 0xe1, 0x85, 0xa8, 0xb9, 0xbe, 0x4e, 0x76, 0x99, 0xa9, 0x7c, 0x6f, 0xf4, 0xc7, 0x95, 0x52, 0x2e, 0x59, 0x18, 0xab, 0x7c, 0xd6, 0xb6, 0x88, 0x4f, 0x67, 0xe6, 0x83, 0xf3, 0xdc}, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa7, 0x73, 0x0b, 0xe3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 1, {0xdd, 0x21, 0x0a, 0xa6, 0x62, 0x9f, 0x20, 0xbb, 0x32, 0x8e, 0x5d, 0x89, 0xda, 0xa6, 0xeb, 0x2a, 0xc3, 0xd1, 0xc6, 0x58, 0xa7, 0x25, 0x53, 0x6f, 0xf1, 0x54, 0xf3, 0x1b, 0x53, 0x6c, 0x23, 0xb2}}, + {{0x0a, 0xf9, 0x52, 0x65, 0x9e, 0xd7, 0x6f, 0x80, 0xf5, 0x85, 0x96, 0x6b, 0x95, 0xab, 0x6e, 0x6f, 0xd6, 0x86, 0x54, 0x67, 0x28, 0x27, 0x87, 0x86, 0x84, 0xc8, 0xb5, 0x47, 0xb1, 0xb9, 0x4f, 0x5a}, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc8, 0x10, 0x17, 0xfd, 0x92, 0xfd, 0x31, 0x63, 0x7c, 0x26, 0xc9, 0x06, 0xb4, 0x20, 0x92, 0xe1, 0x1c, 0xc0, 0xd3, 0xaf, 0xae, 0x8d, 0x90, 0x19, 0xd2, 0x57, 0x8a, 0xf2, 0x27, 0x35, 0xce, 0x7b, 0xc4, 0x69, 0xc7, 0x2d}, {0x96, 0x52, 0xd7, 0x8b, 0xae, 0xfc, 0x02, 0x8c, 0xd3, 0x7a, 0x6a, 0x92, 0x62, 0x5b, 0x8b, 0x8f, 0x85, 0xfd, 0xe1, 0xe4, 0xc9, 0x44, 0xad, 0x3f, 0x20, 0xe1, 0x98, 0xbe, 0xf8, 0xc0, 0x2f, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf2, 0xe9, 0x18, 0x70}, 0, {0x35, 0x68, 0xf2, 0xae, 0xa2, 0xe1, 0x4e, 0xf4, 0xee, 0x4a, 0x3c, 0x2a, 0x8b, 0x8d, 0x31, 0xbc, 0x5e, 0x31, 0x87, 0xba, 0x86, 0xdb, 0x10, 0x73, 0x9b, 0x4f, 0xf8, 0xec, 0x92, 0xff, 0x66, 0x55}}, + {{0xf9, 0x0e, 0x08, 0x0c, 0x64, 0xb0, 0x58, 0x24, 0xc5, 0xa2, 0x4b, 0x25, 0x01, 0xd5, 0xae, 0xaf, 0x08, 0xaf, 0x38, 0x72, 0xee, 0x86, 0x0a, 0xa8, 0x0b, 0xdc, 0xd4, 0x30, 0xf7, 0xb6, 0x34, 0x94}, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x11, 0x51, 0x73, 0x76, 0x5d, 0xc2, 0x02, 0xcf, 0x02, 0x9a, 0xd3, 0xf1, 0x54, 0x79, 0x73, 0x5d, 0x57, 0x69, 0x7a, 0xf1, 0x2b, 0x01, 0x31, 0xdd, 0x21, 0x43, 0x0d, 0x57, 0x72, 0xe4, 0xef, 0x11, 0x47, 0x4d, 0x58, 0xb9}, {0x12, 0xa5, 0x0f, 0x3f, 0xaf, 0xea, 0x7c, 0x1e, 0xea, 0xda, 0x4c, 0xf8, 0xd3, 0x37, 0x77, 0x70, 0x4b, 0x77, 0x36, 0x14, 0x53, 0xaf, 0xc8, 0x3b, 0xda, 0x91, 0xee, 0xf3, 0x49, 0xae, 0x04, 0x4d, 0x20, 0x12, 0x6c, 0x62, 0x00, 0x54, 0x7e, 0xa5, 0xa6, 0x91, 0x17, 0x76, 0xc0, 0x5d, 0xee, 0x2a, 0x7f, 0x1a, 0x9b, 0xa7, 0xdf, 0xba, 0xbb, 0xbd, 0x27, 0x3c, 0x3e, 0xf2, 0x9e, 0xf4, 0x6e, 0x46}, 1, {0xe2, 0x54, 0x61, 0xfb, 0x0e, 0x4c, 0x16, 0x2e, 0x18, 0x12, 0x3e, 0xcd, 0xe8, 0x83, 0x42, 0xd5, 0x4d, 0x44, 0x96, 0x31, 0xe9, 0xb7, 0x5a, 0x26, 0x6f, 0xd9, 0x26, 0x0c, 0x2b, 0xb2, 0xf4, 0x1d}}, +}; + +/** This is a hasher for ellswift_xdh which just returns the shared X coordinate. + * + * This is generally a bad idea as it means changes to the encoding of the + * exchanged public keys do not affect the shared secret. However, it's used here + * in tests to be able to verify the X coordinate through other means. + */ +static int ellswift_xdh_hash_x32(unsigned char *output, const unsigned char *x32, const unsigned char *ell_a64, const unsigned char *ell_b64, void *data) { + (void)ell_a64; + (void)ell_b64; + (void)data; + memcpy(output, x32, 32); + return 1; +} + +void run_ellswift_tests(void) { + int i = 0; + /* Test vectors. */ + for (i = 0; (unsigned)i < sizeof(ellswift_xswiftec_inv_tests) / sizeof(ellswift_xswiftec_inv_tests[0]); ++i) { + const struct ellswift_xswiftec_inv_test *testcase = &ellswift_xswiftec_inv_tests[i]; + int c; + for (c = 0; c < 8; ++c) { + rustsecp256k1zkp_v0_10_0_fe t; + int ret = rustsecp256k1zkp_v0_10_0_ellswift_xswiftec_inv_var(&t, &testcase->x, &testcase->u, c); + CHECK(ret == ((testcase->enc_bitmap >> c) & 1)); + if (ret) { + rustsecp256k1zkp_v0_10_0_fe x2; + CHECK(check_fe_equal(&t, &testcase->encs[c])); + rustsecp256k1zkp_v0_10_0_ellswift_xswiftec_var(&x2, &testcase->u, &testcase->encs[c]); + CHECK(check_fe_equal(&testcase->x, &x2)); + } + } + } + for (i = 0; (unsigned)i < sizeof(ellswift_decode_tests) / sizeof(ellswift_decode_tests[0]); ++i) { + const struct ellswift_decode_test *testcase = &ellswift_decode_tests[i]; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_ge ge; + int ret; + ret = rustsecp256k1zkp_v0_10_0_ellswift_decode(CTX, &pubkey, testcase->enc); + CHECK(ret); + ret = rustsecp256k1zkp_v0_10_0_pubkey_load(CTX, &ge, &pubkey); + CHECK(ret); + CHECK(check_fe_equal(&testcase->x, &ge.x)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_is_odd(&ge.y) == testcase->odd_y); + } + for (i = 0; (unsigned)i < sizeof(ellswift_xdh_tests_bip324) / sizeof(ellswift_xdh_tests_bip324[0]); ++i) { + const struct ellswift_xdh_test *test = &ellswift_xdh_tests_bip324[i]; + unsigned char shared_secret[32]; + int ret; + int party = !test->initiating; + const unsigned char* ell_a64 = party ? test->ellswift_theirs : test->ellswift_ours; + const unsigned char* ell_b64 = party ? test->ellswift_ours : test->ellswift_theirs; + ret = rustsecp256k1zkp_v0_10_0_ellswift_xdh(CTX, shared_secret, + ell_a64, ell_b64, + test->priv_ours, + party, + rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function_bip324, + NULL); + CHECK(ret); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(shared_secret, test->shared_secret, 32) == 0); + } + /* Verify that rustsecp256k1zkp_v0_10_0_ellswift_encode + decode roundtrips. */ + for (i = 0; i < 1000 * COUNT; i++) { + unsigned char rnd32[32]; + unsigned char ell64[64]; + rustsecp256k1zkp_v0_10_0_ge g, g2; + rustsecp256k1zkp_v0_10_0_pubkey pubkey, pubkey2; + /* Generate random public key and random randomizer. */ + random_group_element_test(&g); + rustsecp256k1zkp_v0_10_0_pubkey_save(&pubkey, &g); + rustsecp256k1zkp_v0_10_0_testrand256(rnd32); + /* Convert the public key to ElligatorSwift and back. */ + rustsecp256k1zkp_v0_10_0_ellswift_encode(CTX, ell64, &pubkey, rnd32); + rustsecp256k1zkp_v0_10_0_ellswift_decode(CTX, &pubkey2, ell64); + rustsecp256k1zkp_v0_10_0_pubkey_load(CTX, &g2, &pubkey2); + /* Compare with original. */ + CHECK(rustsecp256k1zkp_v0_10_0_ge_eq_var(&g, &g2)); + } + /* Verify the behavior of rustsecp256k1zkp_v0_10_0_ellswift_create */ + for (i = 0; i < 400 * COUNT; i++) { + unsigned char auxrnd32[32], sec32[32]; + rustsecp256k1zkp_v0_10_0_scalar sec; + rustsecp256k1zkp_v0_10_0_gej res; + rustsecp256k1zkp_v0_10_0_ge dec; + rustsecp256k1zkp_v0_10_0_pubkey pub; + unsigned char ell64[64]; + int ret; + /* Generate random secret key and random randomizer. */ + if (i & 1) rustsecp256k1zkp_v0_10_0_testrand256_test(auxrnd32); + random_scalar_order_test(&sec); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(sec32, &sec); + /* Construct ElligatorSwift-encoded public keys for that key. */ + ret = rustsecp256k1zkp_v0_10_0_ellswift_create(CTX, ell64, sec32, (i & 1) ? auxrnd32 : NULL); + CHECK(ret); + /* Decode it, and compare with traditionally-computed public key. */ + rustsecp256k1zkp_v0_10_0_ellswift_decode(CTX, &pub, ell64); + rustsecp256k1zkp_v0_10_0_pubkey_load(CTX, &dec, &pub); + rustsecp256k1zkp_v0_10_0_ecmult(&res, NULL, &rustsecp256k1zkp_v0_10_0_scalar_zero, &sec); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&res, &dec)); + } + /* Verify that rustsecp256k1zkp_v0_10_0_ellswift_xdh computes the right shared X coordinate. */ + for (i = 0; i < 800 * COUNT; i++) { + unsigned char ell64[64], sec32[32], share32[32]; + rustsecp256k1zkp_v0_10_0_scalar sec; + rustsecp256k1zkp_v0_10_0_ge dec, res; + rustsecp256k1zkp_v0_10_0_fe share_x; + rustsecp256k1zkp_v0_10_0_gej decj, resj; + rustsecp256k1zkp_v0_10_0_pubkey pub; + int ret; + /* Generate random secret key. */ + random_scalar_order_test(&sec); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(sec32, &sec); + /* Generate random ElligatorSwift encoding for the remote key and decode it. */ + rustsecp256k1zkp_v0_10_0_testrand256_test(ell64); + rustsecp256k1zkp_v0_10_0_testrand256_test(ell64 + 32); + rustsecp256k1zkp_v0_10_0_ellswift_decode(CTX, &pub, ell64); + rustsecp256k1zkp_v0_10_0_pubkey_load(CTX, &dec, &pub); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&decj, &dec); + /* Compute the X coordinate of seckey*pubkey using ellswift_xdh. Note that we + * pass ell64 as claimed (but incorrect) encoding for sec32 here; this works + * because the "hasher" function we use here ignores the ell64 arguments. */ + ret = rustsecp256k1zkp_v0_10_0_ellswift_xdh(CTX, share32, ell64, ell64, sec32, i & 1, &ellswift_xdh_hash_x32, NULL); + CHECK(ret); + (void)rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&share_x, share32); /* no overflow is possible */ + SECP256K1_FE_VERIFY(&share_x); + /* Compute seckey*pubkey directly. */ + rustsecp256k1zkp_v0_10_0_ecmult(&resj, &decj, &sec, NULL); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&res, &resj); + /* Compare. */ + CHECK(check_fe_equal(&res.x, &share_x)); + } + /* Verify the joint behavior of rustsecp256k1zkp_v0_10_0_ellswift_xdh */ + for (i = 0; i < 200 * COUNT; i++) { + unsigned char auxrnd32a[32], auxrnd32b[32], auxrnd32a_bad[32], auxrnd32b_bad[32]; + unsigned char sec32a[32], sec32b[32], sec32a_bad[32], sec32b_bad[32]; + rustsecp256k1zkp_v0_10_0_scalar seca, secb; + unsigned char ell64a[64], ell64b[64], ell64a_bad[64], ell64b_bad[64]; + unsigned char share32a[32], share32b[32], share32_bad[32]; + unsigned char prefix64[64]; + rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function hash_function; + void* data; + int ret; + + /* Pick hasher to use. */ + if ((i % 3) == 0) { + hash_function = ellswift_xdh_hash_x32; + data = NULL; + } else if ((i % 3) == 1) { + hash_function = rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function_bip324; + data = NULL; + } else { + hash_function = rustsecp256k1zkp_v0_10_0_ellswift_xdh_hash_function_prefix; + rustsecp256k1zkp_v0_10_0_testrand256_test(prefix64); + rustsecp256k1zkp_v0_10_0_testrand256_test(prefix64 + 32); + data = prefix64; + } + + /* Generate random secret keys and random randomizers. */ + rustsecp256k1zkp_v0_10_0_testrand256_test(auxrnd32a); + rustsecp256k1zkp_v0_10_0_testrand256_test(auxrnd32b); + random_scalar_order_test(&seca); + /* Draw secb uniformly at random to make sure that the secret keys + * differ */ + random_scalar_order(&secb); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(sec32a, &seca); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(sec32b, &secb); + + /* Construct ElligatorSwift-encoded public keys for those keys. */ + /* For A: */ + ret = rustsecp256k1zkp_v0_10_0_ellswift_create(CTX, ell64a, sec32a, auxrnd32a); + CHECK(ret); + /* For B: */ + ret = rustsecp256k1zkp_v0_10_0_ellswift_create(CTX, ell64b, sec32b, auxrnd32b); + CHECK(ret); + + /* Compute the shared secret both ways and compare with each other. */ + /* For A: */ + ret = rustsecp256k1zkp_v0_10_0_ellswift_xdh(CTX, share32a, ell64a, ell64b, sec32a, 0, hash_function, data); + CHECK(ret); + /* For B: */ + ret = rustsecp256k1zkp_v0_10_0_ellswift_xdh(CTX, share32b, ell64a, ell64b, sec32b, 1, hash_function, data); + CHECK(ret); + /* And compare: */ + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(share32a, share32b, 32) == 0); + + /* Verify that the shared secret doesn't match if other side's public key is incorrect. */ + /* For A (using a bad public key for B): */ + memcpy(ell64b_bad, ell64b, sizeof(ell64a_bad)); + rustsecp256k1zkp_v0_10_0_testrand_flip(ell64b_bad, sizeof(ell64b_bad)); + ret = rustsecp256k1zkp_v0_10_0_ellswift_xdh(CTX, share32_bad, ell64a, ell64b_bad, sec32a, 0, hash_function, data); + CHECK(ret); /* Mismatching encodings don't get detected by rustsecp256k1zkp_v0_10_0_ellswift_xdh. */ + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(share32_bad, share32a, 32) != 0); + /* For B (using a bad public key for A): */ + memcpy(ell64a_bad, ell64a, sizeof(ell64a_bad)); + rustsecp256k1zkp_v0_10_0_testrand_flip(ell64a_bad, sizeof(ell64a_bad)); + ret = rustsecp256k1zkp_v0_10_0_ellswift_xdh(CTX, share32_bad, ell64a_bad, ell64b, sec32b, 1, hash_function, data); + CHECK(ret); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(share32_bad, share32b, 32) != 0); + + /* Verify that the shared secret doesn't match if the private key is incorrect. */ + /* For A: */ + memcpy(sec32a_bad, sec32a, sizeof(sec32a_bad)); + rustsecp256k1zkp_v0_10_0_testrand_flip(sec32a_bad, sizeof(sec32a_bad)); + ret = rustsecp256k1zkp_v0_10_0_ellswift_xdh(CTX, share32_bad, ell64a, ell64b, sec32a_bad, 0, hash_function, data); + CHECK(!ret || rustsecp256k1zkp_v0_10_0_memcmp_var(share32_bad, share32a, 32) != 0); + /* For B: */ + memcpy(sec32b_bad, sec32b, sizeof(sec32b_bad)); + rustsecp256k1zkp_v0_10_0_testrand_flip(sec32b_bad, sizeof(sec32b_bad)); + ret = rustsecp256k1zkp_v0_10_0_ellswift_xdh(CTX, share32_bad, ell64a, ell64b, sec32b_bad, 1, hash_function, data); + CHECK(!ret || rustsecp256k1zkp_v0_10_0_memcmp_var(share32_bad, share32b, 32) != 0); + + if (hash_function != ellswift_xdh_hash_x32) { + /* Verify that the shared secret doesn't match when a different encoding of the same public key is used. */ + /* For A (changing B's public key): */ + memcpy(auxrnd32b_bad, auxrnd32b, sizeof(auxrnd32b_bad)); + rustsecp256k1zkp_v0_10_0_testrand_flip(auxrnd32b_bad, sizeof(auxrnd32b_bad)); + ret = rustsecp256k1zkp_v0_10_0_ellswift_create(CTX, ell64b_bad, sec32b, auxrnd32b_bad); + CHECK(ret); + ret = rustsecp256k1zkp_v0_10_0_ellswift_xdh(CTX, share32_bad, ell64a, ell64b_bad, sec32a, 0, hash_function, data); + CHECK(ret); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(share32_bad, share32a, 32) != 0); + /* For B (changing A's public key): */ + memcpy(auxrnd32a_bad, auxrnd32a, sizeof(auxrnd32a_bad)); + rustsecp256k1zkp_v0_10_0_testrand_flip(auxrnd32a_bad, sizeof(auxrnd32a_bad)); + ret = rustsecp256k1zkp_v0_10_0_ellswift_create(CTX, ell64a_bad, sec32a, auxrnd32a_bad); + CHECK(ret); + ret = rustsecp256k1zkp_v0_10_0_ellswift_xdh(CTX, share32_bad, ell64a_bad, ell64b, sec32b, 1, hash_function, data); + CHECK(ret); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(share32_bad, share32b, 32) != 0); + + /* Verify that swapping sides changes the shared secret. */ + /* For A (claiming to be B): */ + ret = rustsecp256k1zkp_v0_10_0_ellswift_xdh(CTX, share32_bad, ell64a, ell64b, sec32a, 1, hash_function, data); + CHECK(ret); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(share32_bad, share32a, 32) != 0); + /* For B (claiming to be A): */ + ret = rustsecp256k1zkp_v0_10_0_ellswift_xdh(CTX, share32_bad, ell64a, ell64b, sec32b, 0, hash_function, data); + CHECK(ret); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(share32_bad, share32b, 32) != 0); + } + } + + /* Test hash initializers. */ + { + rustsecp256k1zkp_v0_10_0_sha256 sha, sha_optimized; + static const unsigned char encode_tag[25] = "rustsecp256k1zkp_v0_10_0_ellswift_encode"; + static const unsigned char create_tag[25] = "rustsecp256k1zkp_v0_10_0_ellswift_create"; + static const unsigned char bip324_tag[26] = "bip324_ellswift_xonly_ecdh"; + + /* Check that hash initialized by + * rustsecp256k1zkp_v0_10_0_ellswift_sha256_init_encode has the expected + * state. */ + rustsecp256k1zkp_v0_10_0_sha256_initialize_tagged(&sha, encode_tag, sizeof(encode_tag)); + rustsecp256k1zkp_v0_10_0_ellswift_sha256_init_encode(&sha_optimized); + test_sha256_eq(&sha, &sha_optimized); + + /* Check that hash initialized by + * rustsecp256k1zkp_v0_10_0_ellswift_sha256_init_create has the expected + * state. */ + rustsecp256k1zkp_v0_10_0_sha256_initialize_tagged(&sha, create_tag, sizeof(create_tag)); + rustsecp256k1zkp_v0_10_0_ellswift_sha256_init_create(&sha_optimized); + test_sha256_eq(&sha, &sha_optimized); + + /* Check that hash initialized by + * rustsecp256k1zkp_v0_10_0_ellswift_sha256_init_bip324 has the expected + * state. */ + rustsecp256k1zkp_v0_10_0_sha256_initialize_tagged(&sha, bip324_tag, sizeof(bip324_tag)); + rustsecp256k1zkp_v0_10_0_ellswift_sha256_init_bip324(&sha_optimized); + test_sha256_eq(&sha, &sha_optimized); + } +} + +#endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/Makefile.am.include b/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/Makefile.am.include index acc1f0ed..0127d6f3 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/Makefile.am.include +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/Makefile.am.include @@ -1,4 +1,4 @@ -include_HEADERS += include/rustsecp256k1zkp_v0_8_0_extrakeys.h +include_HEADERS += include/rustsecp256k1zkp_v0_10_0_extrakeys.h noinst_HEADERS += src/modules/extrakeys/tests_impl.h noinst_HEADERS += src/modules/extrakeys/tests_exhaustive_impl.h noinst_HEADERS += src/modules/extrakeys/main_impl.h diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/hsort.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/hsort.h index 69efdfa2..9b0915b5 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/hsort.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/hsort.h @@ -4,8 +4,8 @@ * file COPYING or https://www.opensource.org/licenses/mit-license.php.* ***********************************************************************/ -#ifndef SECP256K1_HSORT_H_ -#define SECP256K1_HSORT_H_ +#ifndef SECP256K1_HSORT_H +#define SECP256K1_HSORT_H #include #include @@ -16,7 +16,7 @@ * * See the qsort_r manpage for a description of the interface. */ -static void rustsecp256k1zkp_v0_8_0_hsort(void *ptr, size_t count, size_t size, +static void rustsecp256k1zkp_v0_10_0_hsort(void *ptr, size_t count, size_t size, int (*cmp)(const void *, const void *, void *), void *cmp_data); #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/hsort_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/hsort_impl.h index fcd59be4..1f55d66e 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/hsort_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/hsort_impl.h @@ -4,8 +4,8 @@ * file COPYING or https://www.opensource.org/licenses/mit-license.php.* ***********************************************************************/ -#ifndef SECP256K1_HSORT_IMPL_H_ -#define SECP256K1_HSORT_IMPL_H_ +#ifndef SECP256K1_HSORT_IMPL_H +#define SECP256K1_HSORT_IMPL_H #include "hsort.h" @@ -96,7 +96,7 @@ static SECP256K1_INLINE void heap_down(unsigned char *a, size_t i, size_t heap_s } /* In-place heap sort. */ -static void rustsecp256k1zkp_v0_8_0_hsort(void *ptr, size_t count, size_t size, +static void rustsecp256k1zkp_v0_10_0_hsort(void *ptr, size_t count, size_t size, int (*cmp)(const void *, const void *, void *), void *cmp_data ) { size_t i; diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/main_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/main_impl.h index 8e55c581..831aba35 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/main_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/main_impl.h @@ -10,55 +10,56 @@ #include "../../../include/secp256k1.h" #include "../../../include/secp256k1_extrakeys.h" #include "hsort_impl.h" +#include "../../util.h" -static SECP256K1_INLINE int rustsecp256k1zkp_v0_8_0_xonly_pubkey_load(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ge *ge, const rustsecp256k1zkp_v0_8_0_xonly_pubkey *pubkey) { - return rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, ge, (const rustsecp256k1zkp_v0_8_0_pubkey *) pubkey); +static SECP256K1_INLINE int rustsecp256k1zkp_v0_10_0_xonly_pubkey_load(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_ge *ge, const rustsecp256k1zkp_v0_10_0_xonly_pubkey *pubkey) { + return rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, ge, (const rustsecp256k1zkp_v0_10_0_pubkey *) pubkey); } -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_xonly_pubkey_save(rustsecp256k1zkp_v0_8_0_xonly_pubkey *pubkey, rustsecp256k1zkp_v0_8_0_ge *ge) { - rustsecp256k1zkp_v0_8_0_pubkey_save((rustsecp256k1zkp_v0_8_0_pubkey *) pubkey, ge); +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_xonly_pubkey_save(rustsecp256k1zkp_v0_10_0_xonly_pubkey *pubkey, rustsecp256k1zkp_v0_10_0_ge *ge) { + rustsecp256k1zkp_v0_10_0_pubkey_save((rustsecp256k1zkp_v0_10_0_pubkey *) pubkey, ge); } -int rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_xonly_pubkey *pubkey, const unsigned char *input32) { - rustsecp256k1zkp_v0_8_0_ge pk; - rustsecp256k1zkp_v0_8_0_fe x; +int rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_xonly_pubkey *pubkey, const unsigned char *input32) { + rustsecp256k1zkp_v0_10_0_ge pk; + rustsecp256k1zkp_v0_10_0_fe x; VERIFY_CHECK(ctx != NULL); ARG_CHECK(pubkey != NULL); memset(pubkey, 0, sizeof(*pubkey)); ARG_CHECK(input32 != NULL); - if (!rustsecp256k1zkp_v0_8_0_fe_set_b32(&x, input32)) { + if (!rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&x, input32)) { return 0; } - if (!rustsecp256k1zkp_v0_8_0_ge_set_xo_var(&pk, &x, 0)) { + if (!rustsecp256k1zkp_v0_10_0_ge_set_xo_var(&pk, &x, 0)) { return 0; } - if (!rustsecp256k1zkp_v0_8_0_ge_is_in_correct_subgroup(&pk)) { + if (!rustsecp256k1zkp_v0_10_0_ge_is_in_correct_subgroup(&pk)) { return 0; } - rustsecp256k1zkp_v0_8_0_xonly_pubkey_save(pubkey, &pk); + rustsecp256k1zkp_v0_10_0_xonly_pubkey_save(pubkey, &pk); return 1; } -int rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *output32, const rustsecp256k1zkp_v0_8_0_xonly_pubkey *pubkey) { - rustsecp256k1zkp_v0_8_0_ge pk; +int rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *output32, const rustsecp256k1zkp_v0_10_0_xonly_pubkey *pubkey) { + rustsecp256k1zkp_v0_10_0_ge pk; VERIFY_CHECK(ctx != NULL); ARG_CHECK(output32 != NULL); memset(output32, 0, 32); ARG_CHECK(pubkey != NULL); - if (!rustsecp256k1zkp_v0_8_0_xonly_pubkey_load(ctx, &pk, pubkey)) { + if (!rustsecp256k1zkp_v0_10_0_xonly_pubkey_load(ctx, &pk, pubkey)) { return 0; } - rustsecp256k1zkp_v0_8_0_fe_get_b32(output32, &pk.x); + rustsecp256k1zkp_v0_10_0_fe_get_b32(output32, &pk.x); return 1; } -int rustsecp256k1zkp_v0_8_0_xonly_pubkey_cmp(const rustsecp256k1zkp_v0_8_0_context* ctx, const rustsecp256k1zkp_v0_8_0_xonly_pubkey* pk0, const rustsecp256k1zkp_v0_8_0_xonly_pubkey* pk1) { +int rustsecp256k1zkp_v0_10_0_xonly_pubkey_cmp(const rustsecp256k1zkp_v0_10_0_context* ctx, const rustsecp256k1zkp_v0_10_0_xonly_pubkey* pk0, const rustsecp256k1zkp_v0_10_0_xonly_pubkey* pk1) { unsigned char out[2][32]; - const rustsecp256k1zkp_v0_8_0_xonly_pubkey* pk[2]; + const rustsecp256k1zkp_v0_10_0_xonly_pubkey* pk[2]; int i; VERIFY_CHECK(ctx != NULL); @@ -71,7 +72,7 @@ int rustsecp256k1zkp_v0_8_0_xonly_pubkey_cmp(const rustsecp256k1zkp_v0_8_0_conte * pubkeys are involved and prevents edge cases such as sorting * algorithms that use this function and do not terminate as a * result. */ - if (!rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(ctx, out[i], pk[i])) { + if (!rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(ctx, out[i], pk[i])) { /* Note that xonly_pubkey_serialize should already set the output to * zero in that case, but it's not guaranteed by the API, we can't * test it and writing a VERIFY_CHECK is more complex than @@ -79,44 +80,44 @@ int rustsecp256k1zkp_v0_8_0_xonly_pubkey_cmp(const rustsecp256k1zkp_v0_8_0_conte memset(out[i], 0, sizeof(out[i])); } } - return rustsecp256k1zkp_v0_8_0_memcmp_var(out[0], out[1], sizeof(out[1])); + return rustsecp256k1zkp_v0_10_0_memcmp_var(out[0], out[1], sizeof(out[1])); } /** Keeps a group element as is if it has an even Y and otherwise negates it. * y_parity is set to 0 in the former case and to 1 in the latter case. * Requires that the coordinates of r are normalized. */ -static int rustsecp256k1zkp_v0_8_0_extrakeys_ge_even_y(rustsecp256k1zkp_v0_8_0_ge *r) { +static int rustsecp256k1zkp_v0_10_0_extrakeys_ge_even_y(rustsecp256k1zkp_v0_10_0_ge *r) { int y_parity = 0; - VERIFY_CHECK(!rustsecp256k1zkp_v0_8_0_ge_is_infinity(r)); + VERIFY_CHECK(!rustsecp256k1zkp_v0_10_0_ge_is_infinity(r)); - if (rustsecp256k1zkp_v0_8_0_fe_is_odd(&r->y)) { - rustsecp256k1zkp_v0_8_0_fe_negate(&r->y, &r->y, 1); + if (rustsecp256k1zkp_v0_10_0_fe_is_odd(&r->y)) { + rustsecp256k1zkp_v0_10_0_fe_negate(&r->y, &r->y, 1); y_parity = 1; } return y_parity; } -int rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_xonly_pubkey *xonly_pubkey, int *pk_parity, const rustsecp256k1zkp_v0_8_0_pubkey *pubkey) { - rustsecp256k1zkp_v0_8_0_ge pk; +int rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_xonly_pubkey *xonly_pubkey, int *pk_parity, const rustsecp256k1zkp_v0_10_0_pubkey *pubkey) { + rustsecp256k1zkp_v0_10_0_ge pk; int tmp; VERIFY_CHECK(ctx != NULL); ARG_CHECK(xonly_pubkey != NULL); ARG_CHECK(pubkey != NULL); - if (!rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &pk, pubkey)) { + if (!rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, &pk, pubkey)) { return 0; } - tmp = rustsecp256k1zkp_v0_8_0_extrakeys_ge_even_y(&pk); + tmp = rustsecp256k1zkp_v0_10_0_extrakeys_ge_even_y(&pk); if (pk_parity != NULL) { *pk_parity = tmp; } - rustsecp256k1zkp_v0_8_0_xonly_pubkey_save(xonly_pubkey, &pk); + rustsecp256k1zkp_v0_10_0_xonly_pubkey_save(xonly_pubkey, &pk); return 1; } -int rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pubkey *output_pubkey, const rustsecp256k1zkp_v0_8_0_xonly_pubkey *internal_pubkey, const unsigned char *tweak32) { - rustsecp256k1zkp_v0_8_0_ge pk; +int rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_pubkey *output_pubkey, const rustsecp256k1zkp_v0_10_0_xonly_pubkey *internal_pubkey, const unsigned char *tweak32) { + rustsecp256k1zkp_v0_10_0_ge pk; VERIFY_CHECK(ctx != NULL); ARG_CHECK(output_pubkey != NULL); @@ -124,16 +125,16 @@ int rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add(const rustsecp256k1zkp_v0_8_0 ARG_CHECK(internal_pubkey != NULL); ARG_CHECK(tweak32 != NULL); - if (!rustsecp256k1zkp_v0_8_0_xonly_pubkey_load(ctx, &pk, internal_pubkey) - || !rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add_helper(&pk, tweak32)) { + if (!rustsecp256k1zkp_v0_10_0_xonly_pubkey_load(ctx, &pk, internal_pubkey) + || !rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add_helper(&pk, tweak32)) { return 0; } - rustsecp256k1zkp_v0_8_0_pubkey_save(output_pubkey, &pk); + rustsecp256k1zkp_v0_10_0_pubkey_save(output_pubkey, &pk); return 1; } -int rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add_check(const rustsecp256k1zkp_v0_8_0_context* ctx, const unsigned char *tweaked_pubkey32, int tweaked_pk_parity, const rustsecp256k1zkp_v0_8_0_xonly_pubkey *internal_pubkey, const unsigned char *tweak32) { - rustsecp256k1zkp_v0_8_0_ge pk; +int rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add_check(const rustsecp256k1zkp_v0_10_0_context* ctx, const unsigned char *tweaked_pubkey32, int tweaked_pk_parity, const rustsecp256k1zkp_v0_10_0_xonly_pubkey *internal_pubkey, const unsigned char *tweak32) { + rustsecp256k1zkp_v0_10_0_ge pk; unsigned char pk_expected32[32]; VERIFY_CHECK(ctx != NULL); @@ -141,31 +142,31 @@ int rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add_check(const rustsecp256k1zkp_ ARG_CHECK(tweaked_pubkey32 != NULL); ARG_CHECK(tweak32 != NULL); - if (!rustsecp256k1zkp_v0_8_0_xonly_pubkey_load(ctx, &pk, internal_pubkey) - || !rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add_helper(&pk, tweak32)) { + if (!rustsecp256k1zkp_v0_10_0_xonly_pubkey_load(ctx, &pk, internal_pubkey) + || !rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add_helper(&pk, tweak32)) { return 0; } - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&pk.x); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&pk.y); - rustsecp256k1zkp_v0_8_0_fe_get_b32(pk_expected32, &pk.x); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&pk.x); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&pk.y); + rustsecp256k1zkp_v0_10_0_fe_get_b32(pk_expected32, &pk.x); - return rustsecp256k1zkp_v0_8_0_memcmp_var(&pk_expected32, tweaked_pubkey32, 32) == 0 - && rustsecp256k1zkp_v0_8_0_fe_is_odd(&pk.y) == tweaked_pk_parity; + return rustsecp256k1zkp_v0_10_0_memcmp_var(&pk_expected32, tweaked_pubkey32, 32) == 0 + && rustsecp256k1zkp_v0_10_0_fe_is_odd(&pk.y) == tweaked_pk_parity; } -static void rustsecp256k1zkp_v0_8_0_keypair_save(rustsecp256k1zkp_v0_8_0_keypair *keypair, const rustsecp256k1zkp_v0_8_0_scalar *sk, rustsecp256k1zkp_v0_8_0_ge *pk) { - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&keypair->data[0], sk); - rustsecp256k1zkp_v0_8_0_pubkey_save((rustsecp256k1zkp_v0_8_0_pubkey *)&keypair->data[32], pk); +static void rustsecp256k1zkp_v0_10_0_keypair_save(rustsecp256k1zkp_v0_10_0_keypair *keypair, const rustsecp256k1zkp_v0_10_0_scalar *sk, rustsecp256k1zkp_v0_10_0_ge *pk) { + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&keypair->data[0], sk); + rustsecp256k1zkp_v0_10_0_pubkey_save((rustsecp256k1zkp_v0_10_0_pubkey *)&keypair->data[32], pk); } -static int rustsecp256k1zkp_v0_8_0_keypair_seckey_load(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_scalar *sk, const rustsecp256k1zkp_v0_8_0_keypair *keypair) { +static int rustsecp256k1zkp_v0_10_0_keypair_seckey_load(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_scalar *sk, const rustsecp256k1zkp_v0_10_0_keypair *keypair) { int ret; - ret = rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(sk, &keypair->data[0]); + ret = rustsecp256k1zkp_v0_10_0_scalar_set_b32_seckey(sk, &keypair->data[0]); /* We can declassify ret here because sk is only zero if a keypair function * failed (which zeroes the keypair) and its return value is ignored. */ - rustsecp256k1zkp_v0_8_0_declassify(ctx, &ret, sizeof(ret)); + rustsecp256k1zkp_v0_10_0_declassify(ctx, &ret, sizeof(ret)); ARG_CHECK(ret); return ret; } @@ -173,45 +174,45 @@ static int rustsecp256k1zkp_v0_8_0_keypair_seckey_load(const rustsecp256k1zkp_v0 /* Load a keypair into pk and sk (if non-NULL). This function declassifies pk * and ARG_CHECKs that the keypair is not invalid. It always initializes sk and * pk with dummy values. */ -static int rustsecp256k1zkp_v0_8_0_keypair_load(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_scalar *sk, rustsecp256k1zkp_v0_8_0_ge *pk, const rustsecp256k1zkp_v0_8_0_keypair *keypair) { +static int rustsecp256k1zkp_v0_10_0_keypair_load(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_scalar *sk, rustsecp256k1zkp_v0_10_0_ge *pk, const rustsecp256k1zkp_v0_10_0_keypair *keypair) { int ret; - const rustsecp256k1zkp_v0_8_0_pubkey *pubkey = (const rustsecp256k1zkp_v0_8_0_pubkey *)&keypair->data[32]; + const rustsecp256k1zkp_v0_10_0_pubkey *pubkey = (const rustsecp256k1zkp_v0_10_0_pubkey *)&keypair->data[32]; /* Need to declassify the pubkey because pubkey_load ARG_CHECKs if it's * invalid. */ - rustsecp256k1zkp_v0_8_0_declassify(ctx, pubkey, sizeof(*pubkey)); - ret = rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, pk, pubkey); + rustsecp256k1zkp_v0_10_0_declassify(ctx, pubkey, sizeof(*pubkey)); + ret = rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, pk, pubkey); if (sk != NULL) { - ret = ret && rustsecp256k1zkp_v0_8_0_keypair_seckey_load(ctx, sk, keypair); + ret = ret && rustsecp256k1zkp_v0_10_0_keypair_seckey_load(ctx, sk, keypair); } if (!ret) { - *pk = rustsecp256k1zkp_v0_8_0_ge_const_g; + *pk = rustsecp256k1zkp_v0_10_0_ge_const_g; if (sk != NULL) { - *sk = rustsecp256k1zkp_v0_8_0_scalar_one; + *sk = rustsecp256k1zkp_v0_10_0_scalar_one; } } return ret; } -int rustsecp256k1zkp_v0_8_0_keypair_create(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_keypair *keypair, const unsigned char *seckey32) { - rustsecp256k1zkp_v0_8_0_scalar sk; - rustsecp256k1zkp_v0_8_0_ge pk; +int rustsecp256k1zkp_v0_10_0_keypair_create(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_keypair *keypair, const unsigned char *seckey32) { + rustsecp256k1zkp_v0_10_0_scalar sk; + rustsecp256k1zkp_v0_10_0_ge pk; int ret = 0; VERIFY_CHECK(ctx != NULL); ARG_CHECK(keypair != NULL); memset(keypair, 0, sizeof(*keypair)); - ARG_CHECK(rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); ARG_CHECK(seckey32 != NULL); - ret = rustsecp256k1zkp_v0_8_0_ec_pubkey_create_helper(&ctx->ecmult_gen_ctx, &sk, &pk, seckey32); - rustsecp256k1zkp_v0_8_0_keypair_save(keypair, &sk, &pk); - rustsecp256k1zkp_v0_8_0_memczero(keypair, sizeof(*keypair), !ret); + ret = rustsecp256k1zkp_v0_10_0_ec_pubkey_create_helper(&ctx->ecmult_gen_ctx, &sk, &pk, seckey32); + rustsecp256k1zkp_v0_10_0_keypair_save(keypair, &sk, &pk); + rustsecp256k1zkp_v0_10_0_memczero(keypair, sizeof(*keypair), !ret); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sk); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sk); return ret; } -int rustsecp256k1zkp_v0_8_0_keypair_sec(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *seckey, const rustsecp256k1zkp_v0_8_0_keypair *keypair) { +int rustsecp256k1zkp_v0_10_0_keypair_sec(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *seckey, const rustsecp256k1zkp_v0_10_0_keypair *keypair) { VERIFY_CHECK(ctx != NULL); ARG_CHECK(seckey != NULL); memset(seckey, 0, 32); @@ -221,7 +222,7 @@ int rustsecp256k1zkp_v0_8_0_keypair_sec(const rustsecp256k1zkp_v0_8_0_context* c return 1; } -int rustsecp256k1zkp_v0_8_0_keypair_pub(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pubkey *pubkey, const rustsecp256k1zkp_v0_8_0_keypair *keypair) { +int rustsecp256k1zkp_v0_10_0_keypair_pub(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_pubkey *pubkey, const rustsecp256k1zkp_v0_10_0_keypair *keypair) { VERIFY_CHECK(ctx != NULL); ARG_CHECK(pubkey != NULL); memset(pubkey, 0, sizeof(*pubkey)); @@ -231,8 +232,8 @@ int rustsecp256k1zkp_v0_8_0_keypair_pub(const rustsecp256k1zkp_v0_8_0_context* c return 1; } -int rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_xonly_pubkey *pubkey, int *pk_parity, const rustsecp256k1zkp_v0_8_0_keypair *keypair) { - rustsecp256k1zkp_v0_8_0_ge pk; +int rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_xonly_pubkey *pubkey, int *pk_parity, const rustsecp256k1zkp_v0_10_0_keypair *keypair) { + rustsecp256k1zkp_v0_10_0_ge pk; int tmp; VERIFY_CHECK(ctx != NULL); @@ -240,21 +241,21 @@ int rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(const rustsecp256k1zkp_v0_8_0_cont memset(pubkey, 0, sizeof(*pubkey)); ARG_CHECK(keypair != NULL); - if (!rustsecp256k1zkp_v0_8_0_keypair_load(ctx, NULL, &pk, keypair)) { + if (!rustsecp256k1zkp_v0_10_0_keypair_load(ctx, NULL, &pk, keypair)) { return 0; } - tmp = rustsecp256k1zkp_v0_8_0_extrakeys_ge_even_y(&pk); + tmp = rustsecp256k1zkp_v0_10_0_extrakeys_ge_even_y(&pk); if (pk_parity != NULL) { *pk_parity = tmp; } - rustsecp256k1zkp_v0_8_0_xonly_pubkey_save(pubkey, &pk); + rustsecp256k1zkp_v0_10_0_xonly_pubkey_save(pubkey, &pk); return 1; } -int rustsecp256k1zkp_v0_8_0_keypair_xonly_tweak_add(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_keypair *keypair, const unsigned char *tweak32) { - rustsecp256k1zkp_v0_8_0_ge pk; - rustsecp256k1zkp_v0_8_0_scalar sk; +int rustsecp256k1zkp_v0_10_0_keypair_xonly_tweak_add(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_keypair *keypair, const unsigned char *tweak32) { + rustsecp256k1zkp_v0_10_0_ge pk; + rustsecp256k1zkp_v0_10_0_scalar sk; int y_parity; int ret; @@ -262,72 +263,57 @@ int rustsecp256k1zkp_v0_8_0_keypair_xonly_tweak_add(const rustsecp256k1zkp_v0_8_ ARG_CHECK(keypair != NULL); ARG_CHECK(tweak32 != NULL); - ret = rustsecp256k1zkp_v0_8_0_keypair_load(ctx, &sk, &pk, keypair); + ret = rustsecp256k1zkp_v0_10_0_keypair_load(ctx, &sk, &pk, keypair); memset(keypair, 0, sizeof(*keypair)); - y_parity = rustsecp256k1zkp_v0_8_0_extrakeys_ge_even_y(&pk); + y_parity = rustsecp256k1zkp_v0_10_0_extrakeys_ge_even_y(&pk); if (y_parity == 1) { - rustsecp256k1zkp_v0_8_0_scalar_negate(&sk, &sk); + rustsecp256k1zkp_v0_10_0_scalar_negate(&sk, &sk); } - ret &= rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add_helper(&sk, tweak32); - ret &= rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add_helper(&pk, tweak32); + ret &= rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add_helper(&sk, tweak32); + ret &= rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add_helper(&pk, tweak32); - rustsecp256k1zkp_v0_8_0_declassify(ctx, &ret, sizeof(ret)); + rustsecp256k1zkp_v0_10_0_declassify(ctx, &ret, sizeof(ret)); if (ret) { - rustsecp256k1zkp_v0_8_0_keypair_save(keypair, &sk, &pk); + rustsecp256k1zkp_v0_10_0_keypair_save(keypair, &sk, &pk); } - rustsecp256k1zkp_v0_8_0_scalar_clear(&sk); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sk); return ret; } -int rustsecp256k1zkp_v0_8_0_pubkey_cmp(const rustsecp256k1zkp_v0_8_0_context* ctx, const rustsecp256k1zkp_v0_8_0_pubkey* pk0, const rustsecp256k1zkp_v0_8_0_pubkey* pk1) { - unsigned char out[2][33]; - const rustsecp256k1zkp_v0_8_0_pubkey* pk[2]; - int i; - - VERIFY_CHECK(ctx != NULL); - pk[0] = pk0; pk[1] = pk1; - for (i = 0; i < 2; i++) { - size_t outputlen = sizeof(out[i]); - /* If the public key is NULL or invalid, pubkey_serialize will - * call the illegal_callback and return 0. In that case we will - * serialize the key as all zeros which is less than any valid public - * key. This results in consistent comparisons even if NULL or invalid - * pubkeys are involved and prevents edge cases such as sorting - * algorithms that use this function and do not terminate as a - * result. */ - if (!rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, out[i], &outputlen, pk[i], SECP256K1_EC_COMPRESSED)) { - /* Note that pubkey_serialize should already set the output to - * zero in that case, but it's not guaranteed by the API, we can't - * test it and writing a VERIFY_CHECK is more complex than - * explicitly memsetting (again). */ - memset(out[i], 0, sizeof(out[i])); - } - } - return rustsecp256k1zkp_v0_8_0_memcmp_var(out[0], out[1], sizeof(out[1])); -} - -/* This struct wraps a const context pointer to satisfy the rustsecp256k1zkp_v0_8_0_hsort api +/* This struct wraps a const context pointer to satisfy the rustsecp256k1zkp_v0_10_0_hsort api * which expects a non-const cmp_data pointer. */ typedef struct { - const rustsecp256k1zkp_v0_8_0_context *ctx; -} rustsecp256k1zkp_v0_8_0_pubkey_sort_cmp_data; + const rustsecp256k1zkp_v0_10_0_context *ctx; +} rustsecp256k1zkp_v0_10_0_pubkey_sort_cmp_data; -static int rustsecp256k1zkp_v0_8_0_pubkey_sort_cmp(const void* pk1, const void* pk2, void *cmp_data) { - return rustsecp256k1zkp_v0_8_0_pubkey_cmp(((rustsecp256k1zkp_v0_8_0_pubkey_sort_cmp_data*)cmp_data)->ctx, - *(rustsecp256k1zkp_v0_8_0_pubkey **)pk1, - *(rustsecp256k1zkp_v0_8_0_pubkey **)pk2); +static int rustsecp256k1zkp_v0_10_0_pubkey_sort_cmp(const void* pk1, const void* pk2, void *cmp_data) { + return rustsecp256k1zkp_v0_10_0_ec_pubkey_cmp(((rustsecp256k1zkp_v0_10_0_pubkey_sort_cmp_data*)cmp_data)->ctx, + *(rustsecp256k1zkp_v0_10_0_pubkey **)pk1, + *(rustsecp256k1zkp_v0_10_0_pubkey **)pk2); } -int rustsecp256k1zkp_v0_8_0_pubkey_sort(const rustsecp256k1zkp_v0_8_0_context* ctx, const rustsecp256k1zkp_v0_8_0_pubkey **pubkeys, size_t n_pubkeys) { - rustsecp256k1zkp_v0_8_0_pubkey_sort_cmp_data cmp_data; +int rustsecp256k1zkp_v0_10_0_pubkey_sort(const rustsecp256k1zkp_v0_10_0_context* ctx, const rustsecp256k1zkp_v0_10_0_pubkey **pubkeys, size_t n_pubkeys) { + rustsecp256k1zkp_v0_10_0_pubkey_sort_cmp_data cmp_data; VERIFY_CHECK(ctx != NULL); ARG_CHECK(pubkeys != NULL); cmp_data.ctx = ctx; - rustsecp256k1zkp_v0_8_0_hsort(pubkeys, n_pubkeys, sizeof(*pubkeys), rustsecp256k1zkp_v0_8_0_pubkey_sort_cmp, &cmp_data); + + /* Suppress wrong warning (fixed in MSVC 19.33) */ + #if defined(_MSC_VER) && (_MSC_VER < 1933) + #pragma warning(push) + #pragma warning(disable: 4090) + #endif + + rustsecp256k1zkp_v0_10_0_hsort(pubkeys, n_pubkeys, sizeof(*pubkeys), rustsecp256k1zkp_v0_10_0_pubkey_sort_cmp, &cmp_data); + + #if defined(_MSC_VER) && (_MSC_VER < 1933) + #pragma warning(pop) + #endif + return 1; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/tests_exhaustive_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/tests_exhaustive_impl.h index 70477758..4225762a 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/tests_exhaustive_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/tests_exhaustive_impl.h @@ -7,57 +7,57 @@ #ifndef SECP256K1_MODULE_EXTRAKEYS_TESTS_EXHAUSTIVE_H #define SECP256K1_MODULE_EXTRAKEYS_TESTS_EXHAUSTIVE_H -#include "src/modules/extrakeys/main_impl.h" #include "../../../include/secp256k1_extrakeys.h" +#include "main_impl.h" -static void test_exhaustive_extrakeys(const rustsecp256k1zkp_v0_8_0_context *ctx, const rustsecp256k1zkp_v0_8_0_ge* group) { - rustsecp256k1zkp_v0_8_0_keypair keypair[EXHAUSTIVE_TEST_ORDER - 1]; - rustsecp256k1zkp_v0_8_0_pubkey pubkey[EXHAUSTIVE_TEST_ORDER - 1]; - rustsecp256k1zkp_v0_8_0_xonly_pubkey xonly_pubkey[EXHAUSTIVE_TEST_ORDER - 1]; +static void test_exhaustive_extrakeys(const rustsecp256k1zkp_v0_10_0_context *ctx, const rustsecp256k1zkp_v0_10_0_ge* group) { + rustsecp256k1zkp_v0_10_0_keypair keypair[EXHAUSTIVE_TEST_ORDER - 1]; + rustsecp256k1zkp_v0_10_0_pubkey pubkey[EXHAUSTIVE_TEST_ORDER - 1]; + rustsecp256k1zkp_v0_10_0_xonly_pubkey xonly_pubkey[EXHAUSTIVE_TEST_ORDER - 1]; int parities[EXHAUSTIVE_TEST_ORDER - 1]; unsigned char xonly_pubkey_bytes[EXHAUSTIVE_TEST_ORDER - 1][32]; int i; for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) { - rustsecp256k1zkp_v0_8_0_fe fe; - rustsecp256k1zkp_v0_8_0_scalar scalar_i; + rustsecp256k1zkp_v0_10_0_fe fe; + rustsecp256k1zkp_v0_10_0_scalar scalar_i; unsigned char buf[33]; int parity; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&scalar_i, i); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(buf, &scalar_i); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&scalar_i, i); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(buf, &scalar_i); /* Construct pubkey and keypair. */ - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair[i - 1], buf)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey[i - 1], buf)); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(ctx, &keypair[i - 1], buf)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(ctx, &pubkey[i - 1], buf)); /* Construct serialized xonly_pubkey from keypair. */ - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(ctx, &xonly_pubkey[i - 1], &parities[i - 1], &keypair[i - 1])); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(ctx, xonly_pubkey_bytes[i - 1], &xonly_pubkey[i - 1])); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(ctx, &xonly_pubkey[i - 1], &parities[i - 1], &keypair[i - 1])); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(ctx, xonly_pubkey_bytes[i - 1], &xonly_pubkey[i - 1])); /* Parse the xonly_pubkey back and verify it matches the previously serialized value. */ - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(ctx, &xonly_pubkey[i - 1], xonly_pubkey_bytes[i - 1])); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(ctx, buf, &xonly_pubkey[i - 1])); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(xonly_pubkey_bytes[i - 1], buf, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(ctx, &xonly_pubkey[i - 1], xonly_pubkey_bytes[i - 1])); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(ctx, buf, &xonly_pubkey[i - 1])); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(xonly_pubkey_bytes[i - 1], buf, 32) == 0); /* Construct the xonly_pubkey from the pubkey, and verify it matches the same. */ - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(ctx, &xonly_pubkey[i - 1], &parity, &pubkey[i - 1])); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(ctx, &xonly_pubkey[i - 1], &parity, &pubkey[i - 1])); CHECK(parity == parities[i - 1]); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(ctx, buf, &xonly_pubkey[i - 1])); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(xonly_pubkey_bytes[i - 1], buf, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(ctx, buf, &xonly_pubkey[i - 1])); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(xonly_pubkey_bytes[i - 1], buf, 32) == 0); /* Compare the xonly_pubkey bytes against the precomputed group. */ - rustsecp256k1zkp_v0_8_0_fe_set_b32(&fe, xonly_pubkey_bytes[i - 1]); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&fe, &group[i].x)); + rustsecp256k1zkp_v0_10_0_fe_set_b32_mod(&fe, xonly_pubkey_bytes[i - 1]); + CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&fe, &group[i].x)); /* Check the parity against the precomputed group. */ fe = group[i].y; - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&fe); - CHECK(rustsecp256k1zkp_v0_8_0_fe_is_odd(&fe) == parities[i - 1]); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&fe); + CHECK(rustsecp256k1zkp_v0_10_0_fe_is_odd(&fe) == parities[i - 1]); /* Verify that the higher half is identical to the lower half mirrored. */ if (i > EXHAUSTIVE_TEST_ORDER / 2) { - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(xonly_pubkey_bytes[i - 1], xonly_pubkey_bytes[EXHAUSTIVE_TEST_ORDER - i - 1], 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(xonly_pubkey_bytes[i - 1], xonly_pubkey_bytes[EXHAUSTIVE_TEST_ORDER - i - 1], 32) == 0); CHECK(parities[i - 1] == 1 - parities[EXHAUSTIVE_TEST_ORDER - i - 1]); } } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/tests_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/tests_impl.h index 4c591f91..0a267db0 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/tests_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/extrakeys/tests_impl.h @@ -9,19 +9,12 @@ #include "../../../include/secp256k1_extrakeys.h" -static rustsecp256k1zkp_v0_8_0_context* api_test_context(int flags, int *ecount) { - rustsecp256k1zkp_v0_8_0_context *ctx0 = rustsecp256k1zkp_v0_8_0_context_create(flags); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(ctx0, counting_illegal_callback_fn, ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(ctx0, counting_illegal_callback_fn, ecount); - return ctx0; -} - -void test_xonly_pubkey(void) { - rustsecp256k1zkp_v0_8_0_pubkey pk; - rustsecp256k1zkp_v0_8_0_xonly_pubkey xonly_pk, xonly_pk_tmp; - rustsecp256k1zkp_v0_8_0_ge pk1; - rustsecp256k1zkp_v0_8_0_ge pk2; - rustsecp256k1zkp_v0_8_0_fe y; +static void test_xonly_pubkey(void) { + rustsecp256k1zkp_v0_10_0_pubkey pk; + rustsecp256k1zkp_v0_10_0_xonly_pubkey xonly_pk, xonly_pk_tmp; + rustsecp256k1zkp_v0_10_0_ge pk1; + rustsecp256k1zkp_v0_10_0_ge pk2; + rustsecp256k1zkp_v0_10_0_fe y; unsigned char sk[32]; unsigned char xy_sk[32]; unsigned char buf32[32]; @@ -30,114 +23,91 @@ void test_xonly_pubkey(void) { int pk_parity; int i; - int ecount; - rustsecp256k1zkp_v0_8_0_context *none = api_test_context(SECP256K1_CONTEXT_NONE, &ecount); - rustsecp256k1zkp_v0_8_0_context *sign = api_test_context(SECP256K1_CONTEXT_SIGN, &ecount); - rustsecp256k1zkp_v0_8_0_context *verify = api_test_context(SECP256K1_CONTEXT_VERIFY, &ecount); - - rustsecp256k1zkp_v0_8_0_testrand256(sk); + rustsecp256k1zkp_v0_10_0_testrand256(sk); memset(ones32, 0xFF, 32); - rustsecp256k1zkp_v0_8_0_testrand256(xy_sk); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(sign, &pk, sk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(none, &xonly_pk, &pk_parity, &pk) == 1); + rustsecp256k1zkp_v0_10_0_testrand256(xy_sk); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pk, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(CTX, &xonly_pk, &pk_parity, &pk) == 1); /* Test xonly_pubkey_from_pubkey */ - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(none, &xonly_pk, &pk_parity, &pk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(sign, &xonly_pk, &pk_parity, &pk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(verify, &xonly_pk, &pk_parity, &pk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(none, NULL, &pk_parity, &pk) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(none, &xonly_pk, NULL, &pk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(none, &xonly_pk, &pk_parity, NULL) == 0); - CHECK(ecount == 2); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(CTX, &xonly_pk, &pk_parity, &pk) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(CTX, NULL, &pk_parity, &pk)); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(CTX, &xonly_pk, NULL, &pk) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(CTX, &xonly_pk, &pk_parity, NULL)); memset(&pk, 0, sizeof(pk)); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(none, &xonly_pk, &pk_parity, &pk) == 0); - CHECK(ecount == 3); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(CTX, &xonly_pk, &pk_parity, &pk)); /* Choose a secret key such that the resulting pubkey and xonly_pubkey match. */ memset(sk, 0, sizeof(sk)); sk[0] = 1; - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pk, sk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(ctx, &xonly_pk, &pk_parity, &pk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pk, &xonly_pk, sizeof(pk)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pk, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(CTX, &xonly_pk, &pk_parity, &pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pk, &xonly_pk, sizeof(pk)) == 0); CHECK(pk_parity == 0); /* Choose a secret key such that pubkey and xonly_pubkey are each others * negation. */ sk[0] = 2; - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pk, sk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(ctx, &xonly_pk, &pk_parity, &pk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&xonly_pk, &pk, sizeof(xonly_pk)) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pk, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(CTX, &xonly_pk, &pk_parity, &pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&xonly_pk, &pk, sizeof(xonly_pk)) != 0); CHECK(pk_parity == 1); - rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &pk1, &pk); - rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &pk2, (rustsecp256k1zkp_v0_8_0_pubkey *) &xonly_pk); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal(&pk1.x, &pk2.x) == 1); - rustsecp256k1zkp_v0_8_0_fe_negate(&y, &pk2.y, 1); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal(&pk1.y, &y) == 1); + rustsecp256k1zkp_v0_10_0_pubkey_load(CTX, &pk1, &pk); + rustsecp256k1zkp_v0_10_0_pubkey_load(CTX, &pk2, (rustsecp256k1zkp_v0_10_0_pubkey *) &xonly_pk); + CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&pk1.x, &pk2.x) == 1); + rustsecp256k1zkp_v0_10_0_fe_negate(&y, &pk2.y, 1); + CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&pk1.y, &y) == 1); /* Test xonly_pubkey_serialize and xonly_pubkey_parse */ - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(none, NULL, &xonly_pk) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(none, buf32, NULL) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(buf32, zeros64, 32) == 0); - CHECK(ecount == 2); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(CTX, NULL, &xonly_pk)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(CTX, buf32, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(buf32, zeros64, 32) == 0); { /* A pubkey filled with 0s will fail to serialize due to pubkey_load * special casing. */ - rustsecp256k1zkp_v0_8_0_xonly_pubkey pk_tmp; + rustsecp256k1zkp_v0_10_0_xonly_pubkey pk_tmp; memset(&pk_tmp, 0, sizeof(pk_tmp)); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(none, buf32, &pk_tmp) == 0); + /* pubkey_load calls illegal callback */ + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(CTX, buf32, &pk_tmp)); } - /* pubkey_load called illegal callback */ - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(none, buf32, &xonly_pk) == 1); - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(none, NULL, buf32) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(none, &xonly_pk, NULL) == 0); - CHECK(ecount == 2); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(CTX, buf32, &xonly_pk) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(CTX, NULL, buf32)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(CTX, &xonly_pk, NULL)); /* Serialization and parse roundtrip */ - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(none, &xonly_pk, NULL, &pk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(ctx, buf32, &xonly_pk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(ctx, &xonly_pk_tmp, buf32) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&xonly_pk, &xonly_pk_tmp, sizeof(xonly_pk)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(CTX, &xonly_pk, NULL, &pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(CTX, buf32, &xonly_pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(CTX, &xonly_pk_tmp, buf32) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&xonly_pk, &xonly_pk_tmp, sizeof(xonly_pk)) == 0); /* Test parsing invalid field elements */ memset(&xonly_pk, 1, sizeof(xonly_pk)); /* Overflowing field element */ - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(none, &xonly_pk, ones32) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&xonly_pk, zeros64, sizeof(xonly_pk)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(CTX, &xonly_pk, ones32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&xonly_pk, zeros64, sizeof(xonly_pk)) == 0); memset(&xonly_pk, 1, sizeof(xonly_pk)); /* There's no point with x-coordinate 0 on secp256k1 */ - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(none, &xonly_pk, zeros64) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&xonly_pk, zeros64, sizeof(xonly_pk)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(CTX, &xonly_pk, zeros64) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&xonly_pk, zeros64, sizeof(xonly_pk)) == 0); /* If a random 32-byte string can not be parsed with ec_pubkey_parse * (because interpreted as X coordinate it does not correspond to a point on * the curve) then xonly_pubkey_parse should fail as well. */ - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { unsigned char rand33[33]; - rustsecp256k1zkp_v0_8_0_testrand256(&rand33[1]); + rustsecp256k1zkp_v0_10_0_testrand256(&rand33[1]); rand33[0] = SECP256K1_TAG_PUBKEY_EVEN; - if (!rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pk, rand33, 33)) { + if (!rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pk, rand33, 33)) { memset(&xonly_pk, 1, sizeof(xonly_pk)); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(ctx, &xonly_pk, &rand33[1]) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&xonly_pk, zeros64, sizeof(xonly_pk)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(CTX, &xonly_pk, &rand33[1]) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&xonly_pk, zeros64, sizeof(xonly_pk)) == 0); } else { - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(ctx, &xonly_pk, &rand33[1]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(CTX, &xonly_pk, &rand33[1]) == 1); } } - CHECK(ecount == 2); - - rustsecp256k1zkp_v0_8_0_context_destroy(none); - rustsecp256k1zkp_v0_8_0_context_destroy(sign); - rustsecp256k1zkp_v0_8_0_context_destroy(verify); } -void test_xonly_pubkey_comparison(void) { +static void test_xonly_pubkey_comparison(void) { unsigned char pk1_ser[32] = { 0x58, 0x84, 0xb3, 0xa2, 0x4b, 0x97, 0x37, 0x88, 0x92, 0x38, 0xa6, 0x26, 0x62, 0x52, 0x35, 0x11, 0xd0, 0x9a, 0xa1, 0x1b, 0x80, 0x0b, 0x5e, 0x93, 0x80, 0x26, 0x11, 0xef, 0x67, 0x4b, 0xd9, 0x23 @@ -146,437 +116,355 @@ void test_xonly_pubkey_comparison(void) { 0xde, 0x36, 0x0e, 0x87, 0x59, 0x8f, 0x3c, 0x01, 0x36, 0x2a, 0x2a, 0xb8, 0xc6, 0xf4, 0x5e, 0x4d, 0xb2, 0xc2, 0xd5, 0x03, 0xa7, 0xf9, 0xf1, 0x4f, 0xa8, 0xfa, 0x95, 0xa8, 0xe9, 0x69, 0x76, 0x1c }; - rustsecp256k1zkp_v0_8_0_xonly_pubkey pk1; - rustsecp256k1zkp_v0_8_0_xonly_pubkey pk2; - int ecount = 0; - rustsecp256k1zkp_v0_8_0_context *none = api_test_context(SECP256K1_CONTEXT_NONE, &ecount); - - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(none, &pk1, pk1_ser) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(none, &pk2, pk2_ser) == 1); - - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_cmp(none, NULL, &pk2) < 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_cmp(none, &pk1, NULL) > 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_cmp(none, &pk1, &pk2) < 0); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_cmp(none, &pk2, &pk1) > 0); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_cmp(none, &pk1, &pk1) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_cmp(none, &pk2, &pk2) == 0); - CHECK(ecount == 2); + rustsecp256k1zkp_v0_10_0_xonly_pubkey pk1; + rustsecp256k1zkp_v0_10_0_xonly_pubkey pk2; + + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(CTX, &pk1, pk1_ser) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(CTX, &pk2, pk2_ser) == 1); + + CHECK_ILLEGAL_VOID(CTX, CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_cmp(CTX, NULL, &pk2) < 0)); + CHECK_ILLEGAL_VOID(CTX, CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_cmp(CTX, &pk1, NULL) > 0)); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_cmp(CTX, &pk1, &pk2) < 0); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_cmp(CTX, &pk2, &pk1) > 0); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_cmp(CTX, &pk1, &pk1) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_cmp(CTX, &pk2, &pk2) == 0); memset(&pk1, 0, sizeof(pk1)); /* illegal pubkey */ - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_cmp(none, &pk1, &pk2) < 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_cmp(none, &pk1, &pk1) == 0); - CHECK(ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_cmp(none, &pk2, &pk1) > 0); - CHECK(ecount == 6); - - rustsecp256k1zkp_v0_8_0_context_destroy(none); + CHECK_ILLEGAL_VOID(CTX, CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_cmp(CTX, &pk1, &pk2) < 0)); + { + int32_t ecount = 0; + rustsecp256k1zkp_v0_10_0_context_set_illegal_callback(CTX, counting_callback_fn, &ecount); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_cmp(CTX, &pk1, &pk1) == 0); + CHECK(ecount == 2); + rustsecp256k1zkp_v0_10_0_context_set_illegal_callback(CTX, NULL, NULL); + } + CHECK_ILLEGAL_VOID(CTX, CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_cmp(CTX, &pk2, &pk1) > 0)); } -void test_xonly_pubkey_tweak(void) { +static void test_xonly_pubkey_tweak(void) { unsigned char zeros64[64] = { 0 }; unsigned char overflows[32]; unsigned char sk[32]; - rustsecp256k1zkp_v0_8_0_pubkey internal_pk; - rustsecp256k1zkp_v0_8_0_xonly_pubkey internal_xonly_pk; - rustsecp256k1zkp_v0_8_0_pubkey output_pk; + rustsecp256k1zkp_v0_10_0_pubkey internal_pk; + rustsecp256k1zkp_v0_10_0_xonly_pubkey internal_xonly_pk; + rustsecp256k1zkp_v0_10_0_pubkey output_pk; int pk_parity; unsigned char tweak[32]; int i; - int ecount; - rustsecp256k1zkp_v0_8_0_context *none = api_test_context(SECP256K1_CONTEXT_NONE, &ecount); - rustsecp256k1zkp_v0_8_0_context *sign = api_test_context(SECP256K1_CONTEXT_SIGN, &ecount); - rustsecp256k1zkp_v0_8_0_context *verify = api_test_context(SECP256K1_CONTEXT_VERIFY, &ecount); - memset(overflows, 0xff, sizeof(overflows)); - rustsecp256k1zkp_v0_8_0_testrand256(tweak); - rustsecp256k1zkp_v0_8_0_testrand256(sk); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &internal_pk, sk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(none, &internal_xonly_pk, &pk_parity, &internal_pk) == 1); - - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add(none, &output_pk, &internal_xonly_pk, tweak) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add(sign, &output_pk, &internal_xonly_pk, tweak) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add(verify, &output_pk, &internal_xonly_pk, tweak) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add(verify, NULL, &internal_xonly_pk, tweak) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add(verify, &output_pk, NULL, tweak) == 0); - CHECK(ecount == 2); + rustsecp256k1zkp_v0_10_0_testrand256(tweak); + rustsecp256k1zkp_v0_10_0_testrand256(sk); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &internal_pk, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(CTX, &internal_xonly_pk, &pk_parity, &internal_pk) == 1); + + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add(CTX, &output_pk, &internal_xonly_pk, tweak) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add(CTX, &output_pk, &internal_xonly_pk, tweak) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add(CTX, &output_pk, &internal_xonly_pk, tweak) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add(CTX, NULL, &internal_xonly_pk, tweak)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add(CTX, &output_pk, NULL, tweak)); /* NULL internal_xonly_pk zeroes the output_pk */ - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add(verify, &output_pk, &internal_xonly_pk, NULL) == 0); - CHECK(ecount == 3); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add(CTX, &output_pk, &internal_xonly_pk, NULL)); /* NULL tweak zeroes the output_pk */ - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0); /* Invalid tweak zeroes the output_pk */ - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add(verify, &output_pk, &internal_xonly_pk, overflows) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add(CTX, &output_pk, &internal_xonly_pk, overflows) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0); /* A zero tweak is fine */ - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add(verify, &output_pk, &internal_xonly_pk, zeros64) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add(CTX, &output_pk, &internal_xonly_pk, zeros64) == 1); /* Fails if the resulting key was infinity */ - for (i = 0; i < count; i++) { - rustsecp256k1zkp_v0_8_0_scalar scalar_tweak; + for (i = 0; i < COUNT; i++) { + rustsecp256k1zkp_v0_10_0_scalar scalar_tweak; /* Because sk may be negated before adding, we need to try with tweak = * sk as well as tweak = -sk. */ - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&scalar_tweak, sk, NULL); - rustsecp256k1zkp_v0_8_0_scalar_negate(&scalar_tweak, &scalar_tweak); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(tweak, &scalar_tweak); - CHECK((rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add(verify, &output_pk, &internal_xonly_pk, sk) == 0) - || (rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add(verify, &output_pk, &internal_xonly_pk, tweak) == 0)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&scalar_tweak, sk, NULL); + rustsecp256k1zkp_v0_10_0_scalar_negate(&scalar_tweak, &scalar_tweak); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(tweak, &scalar_tweak); + CHECK((rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add(CTX, &output_pk, &internal_xonly_pk, sk) == 0) + || (rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add(CTX, &output_pk, &internal_xonly_pk, tweak) == 0)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0); } /* Invalid pk with a valid tweak */ memset(&internal_xonly_pk, 0, sizeof(internal_xonly_pk)); - rustsecp256k1zkp_v0_8_0_testrand256(tweak); - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add(verify, &output_pk, &internal_xonly_pk, tweak) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0); - - rustsecp256k1zkp_v0_8_0_context_destroy(none); - rustsecp256k1zkp_v0_8_0_context_destroy(sign); - rustsecp256k1zkp_v0_8_0_context_destroy(verify); + rustsecp256k1zkp_v0_10_0_testrand256(tweak); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add(CTX, &output_pk, &internal_xonly_pk, tweak)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0); } -void test_xonly_pubkey_tweak_check(void) { +static void test_xonly_pubkey_tweak_check(void) { unsigned char zeros64[64] = { 0 }; unsigned char overflows[32]; unsigned char sk[32]; - rustsecp256k1zkp_v0_8_0_pubkey internal_pk; - rustsecp256k1zkp_v0_8_0_xonly_pubkey internal_xonly_pk; - rustsecp256k1zkp_v0_8_0_pubkey output_pk; - rustsecp256k1zkp_v0_8_0_xonly_pubkey output_xonly_pk; + rustsecp256k1zkp_v0_10_0_pubkey internal_pk; + rustsecp256k1zkp_v0_10_0_xonly_pubkey internal_xonly_pk; + rustsecp256k1zkp_v0_10_0_pubkey output_pk; + rustsecp256k1zkp_v0_10_0_xonly_pubkey output_xonly_pk; unsigned char output_pk32[32]; unsigned char buf32[32]; int pk_parity; unsigned char tweak[32]; - int ecount; - rustsecp256k1zkp_v0_8_0_context *none = api_test_context(SECP256K1_CONTEXT_NONE, &ecount); - rustsecp256k1zkp_v0_8_0_context *sign = api_test_context(SECP256K1_CONTEXT_SIGN, &ecount); - rustsecp256k1zkp_v0_8_0_context *verify = api_test_context(SECP256K1_CONTEXT_VERIFY, &ecount); - memset(overflows, 0xff, sizeof(overflows)); - rustsecp256k1zkp_v0_8_0_testrand256(tweak); - rustsecp256k1zkp_v0_8_0_testrand256(sk); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &internal_pk, sk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(none, &internal_xonly_pk, &pk_parity, &internal_pk) == 1); - - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add(verify, &output_pk, &internal_xonly_pk, tweak) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(verify, &output_xonly_pk, &pk_parity, &output_pk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(ctx, buf32, &output_xonly_pk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add_check(none, buf32, pk_parity, &internal_xonly_pk, tweak) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add_check(sign, buf32, pk_parity, &internal_xonly_pk, tweak) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add_check(verify, buf32, pk_parity, &internal_xonly_pk, tweak) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add_check(verify, NULL, pk_parity, &internal_xonly_pk, tweak) == 0); - CHECK(ecount == 1); + rustsecp256k1zkp_v0_10_0_testrand256(tweak); + rustsecp256k1zkp_v0_10_0_testrand256(sk); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &internal_pk, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(CTX, &internal_xonly_pk, &pk_parity, &internal_pk) == 1); + + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add(CTX, &output_pk, &internal_xonly_pk, tweak) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(CTX, &output_xonly_pk, &pk_parity, &output_pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(CTX, buf32, &output_xonly_pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add_check(CTX, buf32, pk_parity, &internal_xonly_pk, tweak) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add_check(CTX, buf32, pk_parity, &internal_xonly_pk, tweak) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add_check(CTX, buf32, pk_parity, &internal_xonly_pk, tweak) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add_check(CTX, NULL, pk_parity, &internal_xonly_pk, tweak)); /* invalid pk_parity value */ - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add_check(verify, buf32, 2, &internal_xonly_pk, tweak) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add_check(verify, buf32, pk_parity, NULL, tweak) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add_check(verify, buf32, pk_parity, &internal_xonly_pk, NULL) == 0); - CHECK(ecount == 3); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add_check(CTX, buf32, 2, &internal_xonly_pk, tweak) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add_check(CTX, buf32, pk_parity, NULL, tweak)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add_check(CTX, buf32, pk_parity, &internal_xonly_pk, NULL)); memset(tweak, 1, sizeof(tweak)); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(ctx, &internal_xonly_pk, NULL, &internal_pk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add(ctx, &output_pk, &internal_xonly_pk, tweak) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(ctx, &output_xonly_pk, &pk_parity, &output_pk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(ctx, output_pk32, &output_xonly_pk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add_check(ctx, output_pk32, pk_parity, &internal_xonly_pk, tweak) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(CTX, &internal_xonly_pk, NULL, &internal_pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add(CTX, &output_pk, &internal_xonly_pk, tweak) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(CTX, &output_xonly_pk, &pk_parity, &output_pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(CTX, output_pk32, &output_xonly_pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add_check(CTX, output_pk32, pk_parity, &internal_xonly_pk, tweak) == 1); /* Wrong pk_parity */ - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add_check(ctx, output_pk32, !pk_parity, &internal_xonly_pk, tweak) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add_check(CTX, output_pk32, !pk_parity, &internal_xonly_pk, tweak) == 0); /* Wrong public key */ - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(ctx, buf32, &internal_xonly_pk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add_check(ctx, buf32, pk_parity, &internal_xonly_pk, tweak) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(CTX, buf32, &internal_xonly_pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add_check(CTX, buf32, pk_parity, &internal_xonly_pk, tweak) == 0); /* Overflowing tweak not allowed */ - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add_check(ctx, output_pk32, pk_parity, &internal_xonly_pk, overflows) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add(ctx, &output_pk, &internal_xonly_pk, overflows) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0); - CHECK(ecount == 3); - - rustsecp256k1zkp_v0_8_0_context_destroy(none); - rustsecp256k1zkp_v0_8_0_context_destroy(sign); - rustsecp256k1zkp_v0_8_0_context_destroy(verify); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add_check(CTX, output_pk32, pk_parity, &internal_xonly_pk, overflows) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add(CTX, &output_pk, &internal_xonly_pk, overflows) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0); } /* Starts with an initial pubkey and recursively creates N_PUBKEYS - 1 * additional pubkeys by calling tweak_add. Then verifies every tweak starting * from the last pubkey. */ #define N_PUBKEYS 32 -void test_xonly_pubkey_tweak_recursive(void) { +static void test_xonly_pubkey_tweak_recursive(void) { unsigned char sk[32]; - rustsecp256k1zkp_v0_8_0_pubkey pk[N_PUBKEYS]; + rustsecp256k1zkp_v0_10_0_pubkey pk[N_PUBKEYS]; unsigned char pk_serialized[32]; unsigned char tweak[N_PUBKEYS - 1][32]; int i; - rustsecp256k1zkp_v0_8_0_testrand256(sk); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pk[0], sk) == 1); + rustsecp256k1zkp_v0_10_0_testrand256(sk); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pk[0], sk) == 1); /* Add tweaks */ for (i = 0; i < N_PUBKEYS - 1; i++) { - rustsecp256k1zkp_v0_8_0_xonly_pubkey xonly_pk; + rustsecp256k1zkp_v0_10_0_xonly_pubkey xonly_pk; memset(tweak[i], i + 1, sizeof(tweak[i])); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(ctx, &xonly_pk, NULL, &pk[i]) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add(ctx, &pk[i + 1], &xonly_pk, tweak[i]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(CTX, &xonly_pk, NULL, &pk[i]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add(CTX, &pk[i + 1], &xonly_pk, tweak[i]) == 1); } /* Verify tweaks */ for (i = N_PUBKEYS - 1; i > 0; i--) { - rustsecp256k1zkp_v0_8_0_xonly_pubkey xonly_pk; + rustsecp256k1zkp_v0_10_0_xonly_pubkey xonly_pk; int pk_parity; - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(ctx, &xonly_pk, &pk_parity, &pk[i]) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(ctx, pk_serialized, &xonly_pk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(ctx, &xonly_pk, NULL, &pk[i - 1]) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add_check(ctx, pk_serialized, pk_parity, &xonly_pk, tweak[i - 1]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(CTX, &xonly_pk, &pk_parity, &pk[i]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(CTX, pk_serialized, &xonly_pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(CTX, &xonly_pk, NULL, &pk[i - 1]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add_check(CTX, pk_serialized, pk_parity, &xonly_pk, tweak[i - 1]) == 1); } } #undef N_PUBKEYS -void test_keypair(void) { +static void test_keypair(void) { unsigned char sk[32]; unsigned char sk_tmp[32]; unsigned char zeros96[96] = { 0 }; unsigned char overflows[32]; - rustsecp256k1zkp_v0_8_0_keypair keypair; - rustsecp256k1zkp_v0_8_0_pubkey pk, pk_tmp; - rustsecp256k1zkp_v0_8_0_xonly_pubkey xonly_pk, xonly_pk_tmp; + rustsecp256k1zkp_v0_10_0_keypair keypair; + rustsecp256k1zkp_v0_10_0_pubkey pk, pk_tmp; + rustsecp256k1zkp_v0_10_0_xonly_pubkey xonly_pk, xonly_pk_tmp; int pk_parity, pk_parity_tmp; - int ecount; - rustsecp256k1zkp_v0_8_0_context *none = api_test_context(SECP256K1_CONTEXT_NONE, &ecount); - rustsecp256k1zkp_v0_8_0_context *sign = api_test_context(SECP256K1_CONTEXT_SIGN, &ecount); - rustsecp256k1zkp_v0_8_0_context *verify = api_test_context(SECP256K1_CONTEXT_VERIFY, &ecount); - rustsecp256k1zkp_v0_8_0_context *sttc = rustsecp256k1zkp_v0_8_0_context_clone(rustsecp256k1zkp_v0_8_0_context_no_precomp); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(sttc, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sttc, counting_illegal_callback_fn, &ecount); CHECK(sizeof(zeros96) == sizeof(keypair)); memset(overflows, 0xFF, sizeof(overflows)); /* Test keypair_create */ - ecount = 0; - rustsecp256k1zkp_v0_8_0_testrand256(sk); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(none, &keypair, sk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(zeros96, &keypair, sizeof(keypair)) != 0); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(verify, &keypair, sk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(zeros96, &keypair, sizeof(keypair)) != 0); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(sign, NULL, sk) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(sign, &keypair, NULL) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(zeros96, &keypair, sizeof(keypair)) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(sign, &keypair, sk) == 1); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(sttc, &keypair, sk) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(zeros96, &keypair, sizeof(keypair)) == 0); - CHECK(ecount == 3); + rustsecp256k1zkp_v0_10_0_testrand256(sk); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(zeros96, &keypair, sizeof(keypair)) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(zeros96, &keypair, sizeof(keypair)) != 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_keypair_create(CTX, NULL, sk)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(zeros96, &keypair, sizeof(keypair)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk) == 1); + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_keypair_create(STATIC_CTX, &keypair, sk)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(zeros96, &keypair, sizeof(keypair)) == 0); /* Invalid secret key */ - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(sign, &keypair, zeros96) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(zeros96, &keypair, sizeof(keypair)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(sign, &keypair, overflows) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(zeros96, &keypair, sizeof(keypair)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, zeros96) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(zeros96, &keypair, sizeof(keypair)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, overflows) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(zeros96, &keypair, sizeof(keypair)) == 0); /* Test keypair_pub */ - ecount = 0; - rustsecp256k1zkp_v0_8_0_testrand256(sk); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, sk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_pub(none, &pk, &keypair) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_pub(none, NULL, &keypair) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_pub(none, &pk, NULL) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(zeros96, &pk, sizeof(pk)) == 0); + rustsecp256k1zkp_v0_10_0_testrand256(sk); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_pub(CTX, &pk, &keypair) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_keypair_pub(CTX, NULL, &keypair)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_keypair_pub(CTX, &pk, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(zeros96, &pk, sizeof(pk)) == 0); /* Using an invalid keypair is fine for keypair_pub */ memset(&keypair, 0, sizeof(keypair)); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_pub(none, &pk, &keypair) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(zeros96, &pk, sizeof(pk)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_pub(CTX, &pk, &keypair) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(zeros96, &pk, sizeof(pk)) == 0); /* keypair holds the same pubkey as pubkey_create */ - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(sign, &pk, sk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(sign, &keypair, sk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_pub(none, &pk_tmp, &keypair) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pk, &pk_tmp, sizeof(pk)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pk, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_pub(CTX, &pk_tmp, &keypair) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pk, &pk_tmp, sizeof(pk)) == 0); /** Test keypair_xonly_pub **/ - ecount = 0; - rustsecp256k1zkp_v0_8_0_testrand256(sk); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, sk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(none, &xonly_pk, &pk_parity, &keypair) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(none, NULL, &pk_parity, &keypair) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(none, &xonly_pk, NULL, &keypair) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(none, &xonly_pk, &pk_parity, NULL) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(zeros96, &xonly_pk, sizeof(xonly_pk)) == 0); + rustsecp256k1zkp_v0_10_0_testrand256(sk); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(CTX, &xonly_pk, &pk_parity, &keypair) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(CTX, NULL, &pk_parity, &keypair)); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(CTX, &xonly_pk, NULL, &keypair) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(CTX, &xonly_pk, &pk_parity, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(zeros96, &xonly_pk, sizeof(xonly_pk)) == 0); /* Using an invalid keypair will set the xonly_pk to 0 (first reset * xonly_pk). */ - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(none, &xonly_pk, &pk_parity, &keypair) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(CTX, &xonly_pk, &pk_parity, &keypair) == 1); memset(&keypair, 0, sizeof(keypair)); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(none, &xonly_pk, &pk_parity, &keypair) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(zeros96, &xonly_pk, sizeof(xonly_pk)) == 0); - CHECK(ecount == 3); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(CTX, &xonly_pk, &pk_parity, &keypair)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(zeros96, &xonly_pk, sizeof(xonly_pk)) == 0); /** keypair holds the same xonly pubkey as pubkey_create **/ - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(sign, &pk, sk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(none, &xonly_pk, &pk_parity, &pk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(sign, &keypair, sk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(none, &xonly_pk_tmp, &pk_parity_tmp, &keypair) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&xonly_pk, &xonly_pk_tmp, sizeof(pk)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pk, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(CTX, &xonly_pk, &pk_parity, &pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(CTX, &xonly_pk_tmp, &pk_parity_tmp, &keypair) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&xonly_pk, &xonly_pk_tmp, sizeof(pk)) == 0); CHECK(pk_parity == pk_parity_tmp); /* Test keypair_seckey */ - ecount = 0; - rustsecp256k1zkp_v0_8_0_testrand256(sk); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, sk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_sec(none, sk_tmp, &keypair) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_sec(none, NULL, &keypair) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_sec(none, sk_tmp, NULL) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(zeros96, sk_tmp, sizeof(sk_tmp)) == 0); + rustsecp256k1zkp_v0_10_0_testrand256(sk); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_sec(CTX, sk_tmp, &keypair) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_keypair_sec(CTX, NULL, &keypair)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_keypair_sec(CTX, sk_tmp, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(zeros96, sk_tmp, sizeof(sk_tmp)) == 0); /* keypair returns the same seckey it got */ - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(sign, &keypair, sk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_sec(none, sk_tmp, &keypair) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(sk, sk_tmp, sizeof(sk_tmp)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_sec(CTX, sk_tmp, &keypair) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(sk, sk_tmp, sizeof(sk_tmp)) == 0); /* Using an invalid keypair is fine for keypair_seckey */ memset(&keypair, 0, sizeof(keypair)); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_sec(none, sk_tmp, &keypair) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(zeros96, sk_tmp, sizeof(sk_tmp)) == 0); - - rustsecp256k1zkp_v0_8_0_context_destroy(none); - rustsecp256k1zkp_v0_8_0_context_destroy(sign); - rustsecp256k1zkp_v0_8_0_context_destroy(verify); - rustsecp256k1zkp_v0_8_0_context_destroy(sttc); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_sec(CTX, sk_tmp, &keypair) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(zeros96, sk_tmp, sizeof(sk_tmp)) == 0); } -void test_keypair_add(void) { +static void test_keypair_add(void) { unsigned char sk[32]; - rustsecp256k1zkp_v0_8_0_keypair keypair; + rustsecp256k1zkp_v0_10_0_keypair keypair; unsigned char overflows[32]; unsigned char zeros96[96] = { 0 }; unsigned char tweak[32]; int i; - int ecount = 0; - rustsecp256k1zkp_v0_8_0_context *none = api_test_context(SECP256K1_CONTEXT_NONE, &ecount); - rustsecp256k1zkp_v0_8_0_context *sign = api_test_context(SECP256K1_CONTEXT_SIGN, &ecount); - rustsecp256k1zkp_v0_8_0_context *verify = api_test_context(SECP256K1_CONTEXT_VERIFY, &ecount); CHECK(sizeof(zeros96) == sizeof(keypair)); - rustsecp256k1zkp_v0_8_0_testrand256(sk); - rustsecp256k1zkp_v0_8_0_testrand256(tweak); + rustsecp256k1zkp_v0_10_0_testrand256(sk); + rustsecp256k1zkp_v0_10_0_testrand256(tweak); memset(overflows, 0xFF, 32); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, sk) == 1); - - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_tweak_add(none, &keypair, tweak) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_tweak_add(sign, &keypair, tweak) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_tweak_add(verify, &keypair, tweak) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_tweak_add(verify, NULL, tweak) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_tweak_add(verify, &keypair, NULL) == 0); - CHECK(ecount == 2); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk) == 1); + + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_tweak_add(CTX, &keypair, tweak) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_tweak_add(CTX, &keypair, tweak) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_tweak_add(CTX, &keypair, tweak) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_keypair_xonly_tweak_add(CTX, NULL, tweak)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_keypair_xonly_tweak_add(CTX, &keypair, NULL)); /* This does not set the keypair to zeroes */ - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&keypair, zeros96, sizeof(keypair)) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&keypair, zeros96, sizeof(keypair)) != 0); /* Invalid tweak zeroes the keypair */ - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, sk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_tweak_add(ctx, &keypair, overflows) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&keypair, zeros96, sizeof(keypair)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_tweak_add(CTX, &keypair, overflows) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&keypair, zeros96, sizeof(keypair)) == 0); /* A zero tweak is fine */ - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, sk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_tweak_add(ctx, &keypair, zeros96) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_tweak_add(CTX, &keypair, zeros96) == 1); /* Fails if the resulting keypair was (sk=0, pk=infinity) */ - for (i = 0; i < count; i++) { - rustsecp256k1zkp_v0_8_0_scalar scalar_tweak; - rustsecp256k1zkp_v0_8_0_keypair keypair_tmp; - rustsecp256k1zkp_v0_8_0_testrand256(sk); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, sk) == 1); + for (i = 0; i < COUNT; i++) { + rustsecp256k1zkp_v0_10_0_scalar scalar_tweak; + rustsecp256k1zkp_v0_10_0_keypair keypair_tmp; + rustsecp256k1zkp_v0_10_0_testrand256(sk); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk) == 1); memcpy(&keypair_tmp, &keypair, sizeof(keypair)); /* Because sk may be negated before adding, we need to try with tweak = * sk as well as tweak = -sk. */ - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&scalar_tweak, sk, NULL); - rustsecp256k1zkp_v0_8_0_scalar_negate(&scalar_tweak, &scalar_tweak); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(tweak, &scalar_tweak); - CHECK((rustsecp256k1zkp_v0_8_0_keypair_xonly_tweak_add(ctx, &keypair, sk) == 0) - || (rustsecp256k1zkp_v0_8_0_keypair_xonly_tweak_add(ctx, &keypair_tmp, tweak) == 0)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&keypair, zeros96, sizeof(keypair)) == 0 - || rustsecp256k1zkp_v0_8_0_memcmp_var(&keypair_tmp, zeros96, sizeof(keypair_tmp)) == 0); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&scalar_tweak, sk, NULL); + rustsecp256k1zkp_v0_10_0_scalar_negate(&scalar_tweak, &scalar_tweak); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(tweak, &scalar_tweak); + CHECK((rustsecp256k1zkp_v0_10_0_keypair_xonly_tweak_add(CTX, &keypair, sk) == 0) + || (rustsecp256k1zkp_v0_10_0_keypair_xonly_tweak_add(CTX, &keypair_tmp, tweak) == 0)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&keypair, zeros96, sizeof(keypair)) == 0 + || rustsecp256k1zkp_v0_10_0_memcmp_var(&keypair_tmp, zeros96, sizeof(keypair_tmp)) == 0); } /* Invalid keypair with a valid tweak */ memset(&keypair, 0, sizeof(keypair)); - rustsecp256k1zkp_v0_8_0_testrand256(tweak); - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_tweak_add(verify, &keypair, tweak) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&keypair, zeros96, sizeof(keypair)) == 0); + rustsecp256k1zkp_v0_10_0_testrand256(tweak); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_keypair_xonly_tweak_add(CTX, &keypair, tweak)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&keypair, zeros96, sizeof(keypair)) == 0); /* Only seckey part of keypair invalid */ - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk) == 1); memset(&keypair, 0, 32); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_tweak_add(verify, &keypair, tweak) == 0); - CHECK(ecount == 2); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_keypair_xonly_tweak_add(CTX, &keypair, tweak)); /* Only pubkey part of keypair invalid */ - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk) == 1); memset(&keypair.data[32], 0, 64); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_tweak_add(verify, &keypair, tweak) == 0); - CHECK(ecount == 3); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_keypair_xonly_tweak_add(CTX, &keypair, tweak)); /* Check that the keypair_tweak_add implementation is correct */ - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, sk) == 1); - for (i = 0; i < count; i++) { - rustsecp256k1zkp_v0_8_0_xonly_pubkey internal_pk; - rustsecp256k1zkp_v0_8_0_xonly_pubkey output_pk; - rustsecp256k1zkp_v0_8_0_pubkey output_pk_xy; - rustsecp256k1zkp_v0_8_0_pubkey output_pk_expected; + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk) == 1); + for (i = 0; i < COUNT; i++) { + rustsecp256k1zkp_v0_10_0_xonly_pubkey internal_pk; + rustsecp256k1zkp_v0_10_0_xonly_pubkey output_pk; + rustsecp256k1zkp_v0_10_0_pubkey output_pk_xy; + rustsecp256k1zkp_v0_10_0_pubkey output_pk_expected; unsigned char pk32[32]; unsigned char sk32[32]; int pk_parity; - rustsecp256k1zkp_v0_8_0_testrand256(tweak); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(ctx, &internal_pk, NULL, &keypair) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_tweak_add(ctx, &keypair, tweak) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(ctx, &output_pk, &pk_parity, &keypair) == 1); + rustsecp256k1zkp_v0_10_0_testrand256(tweak); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(CTX, &internal_pk, NULL, &keypair) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_tweak_add(CTX, &keypair, tweak) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(CTX, &output_pk, &pk_parity, &keypair) == 1); /* Check that it passes xonly_pubkey_tweak_add_check */ - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(ctx, pk32, &output_pk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add_check(ctx, pk32, pk_parity, &internal_pk, tweak) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(CTX, pk32, &output_pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add_check(CTX, pk32, pk_parity, &internal_pk, tweak) == 1); /* Check that the resulting pubkey matches xonly_pubkey_tweak_add */ - CHECK(rustsecp256k1zkp_v0_8_0_keypair_pub(ctx, &output_pk_xy, &keypair) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add(ctx, &output_pk_expected, &internal_pk, tweak) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&output_pk_xy, &output_pk_expected, sizeof(output_pk_xy)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_pub(CTX, &output_pk_xy, &keypair) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add(CTX, &output_pk_expected, &internal_pk, tweak) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&output_pk_xy, &output_pk_expected, sizeof(output_pk_xy)) == 0); /* Check that the secret key in the keypair is tweaked correctly */ - CHECK(rustsecp256k1zkp_v0_8_0_keypair_sec(none, sk32, &keypair) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &output_pk_expected, sk32) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&output_pk_xy, &output_pk_expected, sizeof(output_pk_xy)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_sec(CTX, sk32, &keypair) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &output_pk_expected, sk32) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&output_pk_xy, &output_pk_expected, sizeof(output_pk_xy)) == 0); } - rustsecp256k1zkp_v0_8_0_context_destroy(none); - rustsecp256k1zkp_v0_8_0_context_destroy(sign); - rustsecp256k1zkp_v0_8_0_context_destroy(verify); } static void test_hsort_is_sorted(int *ints, size_t n) { @@ -592,109 +480,68 @@ static int test_hsort_cmp(const void *i1, const void *i2, void *counter) { } #define NUM 64 -void test_hsort(void) { +static void test_hsort(void) { int ints[NUM] = { 0 }; size_t counter = 0; int i, j; - rustsecp256k1zkp_v0_8_0_hsort(ints, 0, sizeof(ints[0]), test_hsort_cmp, &counter); + rustsecp256k1zkp_v0_10_0_hsort(ints, 0, sizeof(ints[0]), test_hsort_cmp, &counter); CHECK(counter == 0); - rustsecp256k1zkp_v0_8_0_hsort(ints, 1, sizeof(ints[0]), test_hsort_cmp, &counter); + rustsecp256k1zkp_v0_10_0_hsort(ints, 1, sizeof(ints[0]), test_hsort_cmp, &counter); CHECK(counter == 0); - rustsecp256k1zkp_v0_8_0_hsort(ints, NUM, sizeof(ints[0]), test_hsort_cmp, &counter); + rustsecp256k1zkp_v0_10_0_hsort(ints, NUM, sizeof(ints[0]), test_hsort_cmp, &counter); CHECK(counter > 0); test_hsort_is_sorted(ints, NUM); /* Test hsort with length n array and random elements in * [-interval/2, interval/2] */ - for (i = 0; i < count; i++) { - int n = rustsecp256k1zkp_v0_8_0_testrand_int(NUM); - int interval = rustsecp256k1zkp_v0_8_0_testrand_int(64); + for (i = 0; i < COUNT; i++) { + int n = rustsecp256k1zkp_v0_10_0_testrand_int(NUM); + int interval = rustsecp256k1zkp_v0_10_0_testrand_int(63) + 1; for (j = 0; j < n; j++) { - ints[j] = rustsecp256k1zkp_v0_8_0_testrand_int(interval) - interval/2; + ints[j] = rustsecp256k1zkp_v0_10_0_testrand_int(interval) - interval/2; } - rustsecp256k1zkp_v0_8_0_hsort(ints, n, sizeof(ints[0]), test_hsort_cmp, &counter); + rustsecp256k1zkp_v0_10_0_hsort(ints, n, sizeof(ints[0]), test_hsort_cmp, &counter); test_hsort_is_sorted(ints, n); } } #undef NUM -void test_pubkey_comparison(void) { - unsigned char pk1_ser[33] = { - 0x02, - 0x58, 0x84, 0xb3, 0xa2, 0x4b, 0x97, 0x37, 0x88, 0x92, 0x38, 0xa6, 0x26, 0x62, 0x52, 0x35, 0x11, - 0xd0, 0x9a, 0xa1, 0x1b, 0x80, 0x0b, 0x5e, 0x93, 0x80, 0x26, 0x11, 0xef, 0x67, 0x4b, 0xd9, 0x23 - }; - const unsigned char pk2_ser[33] = { - 0x03, - 0xde, 0x36, 0x0e, 0x87, 0x59, 0x8f, 0x3c, 0x01, 0x36, 0x2a, 0x2a, 0xb8, 0xc6, 0xf4, 0x5e, 0x4d, - 0xb2, 0xc2, 0xd5, 0x03, 0xa7, 0xf9, 0xf1, 0x4f, 0xa8, 0xfa, 0x95, 0xa8, 0xe9, 0x69, 0x76, 0x1c - }; - rustsecp256k1zkp_v0_8_0_pubkey pk1; - rustsecp256k1zkp_v0_8_0_pubkey pk2; - int ecount = 0; - rustsecp256k1zkp_v0_8_0_context *none = api_test_context(SECP256K1_CONTEXT_NONE, &ecount); - - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(none, &pk1, pk1_ser, sizeof(pk1_ser)) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(none, &pk2, pk2_ser, sizeof(pk2_ser)) == 1); - - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_cmp(none, NULL, &pk2) < 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_cmp(none, &pk1, NULL) > 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_cmp(none, &pk1, &pk2) < 0); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_cmp(none, &pk2, &pk1) > 0); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_cmp(none, &pk1, &pk1) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_cmp(none, &pk2, &pk2) == 0); - CHECK(ecount == 2); - memset(&pk1, 0, sizeof(pk1)); /* illegal pubkey */ - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_cmp(none, &pk1, &pk2) < 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_cmp(none, &pk1, &pk1) == 0); - CHECK(ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_cmp(none, &pk2, &pk1) > 0); - CHECK(ecount == 6); - - rustsecp256k1zkp_v0_8_0_context_destroy(none); -} - -void test_sort_helper(rustsecp256k1zkp_v0_8_0_pubkey *pk, size_t *pk_order, size_t n_pk) { +static void test_sort_helper(rustsecp256k1zkp_v0_10_0_pubkey *pk, size_t *pk_order, size_t n_pk) { size_t i; - const rustsecp256k1zkp_v0_8_0_pubkey *pk_test[5]; + const rustsecp256k1zkp_v0_10_0_pubkey *pk_test[5]; for (i = 0; i < n_pk; i++) { pk_test[i] = &pk[pk_order[i]]; } - rustsecp256k1zkp_v0_8_0_pubkey_sort(ctx, pk_test, n_pk); + rustsecp256k1zkp_v0_10_0_pubkey_sort(CTX, pk_test, n_pk); for (i = 0; i < n_pk; i++) { - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(pk_test[i], &pk[i], sizeof(*pk_test[i])) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(pk_test[i], &pk[i], sizeof(*pk_test[i])) == 0); } } -void permute(size_t *arr, size_t n) { +static void permute(size_t *arr, size_t n) { size_t i; for (i = n - 1; i >= 1; i--) { size_t tmp, j; - j = rustsecp256k1zkp_v0_8_0_testrand_int(i + 1); + j = rustsecp256k1zkp_v0_10_0_testrand_int(i + 1); tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; } } -void rand_pk(rustsecp256k1zkp_v0_8_0_pubkey *pk) { +static void rand_pk(rustsecp256k1zkp_v0_10_0_pubkey *pk) { unsigned char seckey[32]; - rustsecp256k1zkp_v0_8_0_keypair keypair; - rustsecp256k1zkp_v0_8_0_testrand256(seckey); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, seckey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_pub(ctx, pk, &keypair) == 1); + rustsecp256k1zkp_v0_10_0_keypair keypair; + rustsecp256k1zkp_v0_10_0_testrand256(seckey); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, seckey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_pub(CTX, pk, &keypair) == 1); } -void test_sort_api(void) { - int ecount = 0; - rustsecp256k1zkp_v0_8_0_pubkey pks[2]; - const rustsecp256k1zkp_v0_8_0_pubkey *pks_ptr[2]; - rustsecp256k1zkp_v0_8_0_context *none = api_test_context(SECP256K1_CONTEXT_NONE, &ecount); +static void test_sort_api(void) { + rustsecp256k1zkp_v0_10_0_pubkey pks[2]; + const rustsecp256k1zkp_v0_10_0_pubkey *pks_ptr[2]; pks_ptr[0] = &pks[0]; pks_ptr[1] = &pks[1]; @@ -702,23 +549,24 @@ void test_sort_api(void) { rand_pk(&pks[0]); rand_pk(&pks[1]); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_sort(none, pks_ptr, 2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_sort(none, NULL, 2) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_sort(none, pks_ptr, 0) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_pubkey_sort(CTX, pks_ptr, 2) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pubkey_sort(CTX, NULL, 2)); + CHECK(rustsecp256k1zkp_v0_10_0_pubkey_sort(CTX, pks_ptr, 0) == 1); /* Test illegal public keys */ memset(&pks[0], 0, sizeof(pks[0])); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_sort(none, pks_ptr, 2) == 1); - CHECK(ecount == 2); + CHECK_ILLEGAL_VOID(CTX, CHECK(rustsecp256k1zkp_v0_10_0_pubkey_sort(CTX, pks_ptr, 2) == 1)); memset(&pks[1], 0, sizeof(pks[1])); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_sort(none, pks_ptr, 2) == 1); - CHECK(ecount > 2); - - rustsecp256k1zkp_v0_8_0_context_destroy(none); + { + int32_t ecount = 0; + rustsecp256k1zkp_v0_10_0_context_set_illegal_callback(CTX, counting_callback_fn, &ecount); + CHECK(rustsecp256k1zkp_v0_10_0_pubkey_sort(CTX, pks_ptr, 2) == 1); + CHECK(ecount == 2); + rustsecp256k1zkp_v0_10_0_context_set_illegal_callback(CTX, NULL, NULL); + } } -void test_sort(void) { - rustsecp256k1zkp_v0_8_0_pubkey pk[5]; +static void test_sort(void) { + rustsecp256k1zkp_v0_10_0_pubkey pk[5]; unsigned char pk_ser[5][33] = { { 0x02, 0x08 }, { 0x02, 0x0b }, @@ -730,7 +578,7 @@ void test_sort(void) { size_t pk_order[5] = { 0, 1, 2, 3, 4 }; for (i = 0; i < 5; i++) { - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pk[i], pk_ser[i], sizeof(pk_ser[i]))); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pk[i], pk_ser[i], sizeof(pk_ser[i]))); } permute(pk_order, 1); @@ -739,31 +587,31 @@ void test_sort(void) { test_sort_helper(pk, pk_order, 2); permute(pk_order, 3); test_sort_helper(pk, pk_order, 3); - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { permute(pk_order, 4); test_sort_helper(pk, pk_order, 4); } - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { permute(pk_order, 5); test_sort_helper(pk, pk_order, 5); } /* Check that sorting also works for random pubkeys */ - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { int j; - const rustsecp256k1zkp_v0_8_0_pubkey *pk_ptr[5]; + const rustsecp256k1zkp_v0_10_0_pubkey *pk_ptr[5]; for (j = 0; j < 5; j++) { rand_pk(&pk[j]); pk_ptr[j] = &pk[j]; } - rustsecp256k1zkp_v0_8_0_pubkey_sort(ctx, pk_ptr, 5); + rustsecp256k1zkp_v0_10_0_pubkey_sort(CTX, pk_ptr, 5); for (j = 1; j < 5; j++) { - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_sort_cmp(&pk_ptr[j - 1], &pk_ptr[j], ctx) <= 0); + CHECK(rustsecp256k1zkp_v0_10_0_pubkey_sort_cmp(&pk_ptr[j - 1], &pk_ptr[j], CTX) <= 0); } } } /* Test vectors from BIP-MuSig2 */ -void test_sort_vectors(void) { +static void test_sort_vectors(void) { enum { N_PUBKEYS = 6 }; unsigned char pk_ser[N_PUBKEYS][33] = { { 0x02, 0xDD, 0x30, 0x8A, 0xFE, 0xC5, 0x77, 0x7E, 0x13, 0x12, 0x1F, @@ -785,9 +633,9 @@ void test_sort_vectors(void) { 0xA7, 0x2B, 0x9C, 0xC1, 0xB7, 0xCC, 0x01, 0x39, 0x71, 0x53, 0x09, 0xB0, 0x86, 0xC9, 0x60, 0xE1, 0x8F, 0xD9, 0x69, 0x77, 0x4E, 0xB8 } }; - rustsecp256k1zkp_v0_8_0_pubkey pubkeys[N_PUBKEYS]; - rustsecp256k1zkp_v0_8_0_pubkey *sorted[N_PUBKEYS]; - const rustsecp256k1zkp_v0_8_0_pubkey *pks_ptr[N_PUBKEYS]; + rustsecp256k1zkp_v0_10_0_pubkey pubkeys[N_PUBKEYS]; + rustsecp256k1zkp_v0_10_0_pubkey *sorted[N_PUBKEYS]; + const rustsecp256k1zkp_v0_10_0_pubkey *pks_ptr[N_PUBKEYS]; int i; sorted[0] = &pubkeys[3]; @@ -798,16 +646,16 @@ void test_sort_vectors(void) { sorted[5] = &pubkeys[2]; for (i = 0; i < N_PUBKEYS; i++) { - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pubkeys[i], pk_ser[i], sizeof(pk_ser[i]))); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pubkeys[i], pk_ser[i], sizeof(pk_ser[i]))); pks_ptr[i] = &pubkeys[i]; } - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_sort(ctx, pks_ptr, N_PUBKEYS) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_pubkey_sort(CTX, pks_ptr, N_PUBKEYS) == 1); for (i = 0; i < N_PUBKEYS; i++) { - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(pks_ptr[i], sorted[i], sizeof(rustsecp256k1zkp_v0_8_0_pubkey)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(pks_ptr[i], sorted[i], sizeof(rustsecp256k1zkp_v0_10_0_pubkey)) == 0); } } -void run_extrakeys_tests(void) { +static void run_extrakeys_tests(void) { /* xonly key test cases */ test_xonly_pubkey(); test_xonly_pubkey_tweak(); @@ -820,7 +668,6 @@ void run_extrakeys_tests(void) { test_keypair_add(); test_hsort(); - test_pubkey_comparison(); test_sort_api(); test_sort(); test_sort_vectors(); diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/generator/Makefile.am.include b/secp256k1-zkp-sys/depend/secp256k1/src/modules/generator/Makefile.am.include index 25d1c85d..2ad6fb3d 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/generator/Makefile.am.include +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/generator/Makefile.am.include @@ -1,4 +1,4 @@ -include_HEADERS += include/rustsecp256k1zkp_v0_8_0_generator.h +include_HEADERS += include/rustsecp256k1zkp_v0_10_0_generator.h noinst_HEADERS += src/modules/generator/pedersen.h noinst_HEADERS += src/modules/generator/pedersen_impl.h noinst_HEADERS += src/modules/generator/main_impl.h @@ -6,6 +6,6 @@ noinst_HEADERS += src/modules/generator/tests_impl.h if USE_BENCHMARK noinst_PROGRAMS += bench_generator bench_generator_SOURCES = src/bench_generator.c -bench_generator_LDADD = libsecp256k1.la $(SECP_LIBS) -bench_generator_LDFLAGS = -static +bench_generator_LDADD = libsecp256k1.la +bench_generator_CPPFLAGS = $(SECP_CONFIG_DEFINES) endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/generator/main_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/generator/main_impl.h index 33df672a..69635392 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/generator/main_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/generator/main_impl.h @@ -4,8 +4,8 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef SECP256K1_MODULE_GENERATOR_MAIN -#define SECP256K1_MODULE_GENERATOR_MAIN +#ifndef SECP256K1_MODULE_GENERATOR_MAIN_H +#define SECP256K1_MODULE_GENERATOR_MAIN_H #include @@ -14,7 +14,7 @@ #include "../../hash.h" #include "../../scalar.h" -#include "modules/generator/pedersen_impl.h" +#include "../generator/pedersen_impl.h" /** Alternative generator for secp256k1. * This is the sha256 of 'g' after standard encoding (without compression), @@ -24,73 +24,73 @@ import hashlib F = FiniteField (0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F) G = '0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8' - H = EllipticCurve ([F (0), F (7)]).lift_x(F(int(hashlib.sha256(G.decode('hex')).hexdigest(),16))) + H = EllipticCurve ([F (0), F (7)]).lift_x(F(int(hashlib.sha256(bytes.fromhex(G)).hexdigest(),16))) print('%x %x' % H.xy()) */ -static const rustsecp256k1zkp_v0_8_0_generator rustsecp256k1zkp_v0_8_0_generator_h_internal = {{ +static const rustsecp256k1zkp_v0_10_0_generator rustsecp256k1zkp_v0_10_0_generator_h_internal = {{ 0x50, 0x92, 0x9b, 0x74, 0xc1, 0xa0, 0x49, 0x54, 0xb7, 0x8b, 0x4b, 0x60, 0x35, 0xe9, 0x7a, 0x5e, 0x07, 0x8a, 0x5a, 0x0f, 0x28, 0xec, 0x96, 0xd5, 0x47, 0xbf, 0xee, 0x9a, 0xce, 0x80, 0x3a, 0xc0, 0x31, 0xd3, 0xc6, 0x86, 0x39, 0x73, 0x92, 0x6e, 0x04, 0x9e, 0x63, 0x7c, 0xb1, 0xb5, 0xf4, 0x0a, 0x36, 0xda, 0xc2, 0x8a, 0xf1, 0x76, 0x69, 0x68, 0xc3, 0x0c, 0x23, 0x13, 0xf3, 0xa3, 0x89, 0x04 }}; -const rustsecp256k1zkp_v0_8_0_generator *rustsecp256k1zkp_v0_8_0_generator_h = &rustsecp256k1zkp_v0_8_0_generator_h_internal; +const rustsecp256k1zkp_v0_10_0_generator *rustsecp256k1zkp_v0_10_0_generator_h = &rustsecp256k1zkp_v0_10_0_generator_h_internal; -static void rustsecp256k1zkp_v0_8_0_generator_load(rustsecp256k1zkp_v0_8_0_ge* ge, const rustsecp256k1zkp_v0_8_0_generator* gen) { +static void rustsecp256k1zkp_v0_10_0_generator_load(rustsecp256k1zkp_v0_10_0_ge* ge, const rustsecp256k1zkp_v0_10_0_generator* gen) { int succeed; - succeed = rustsecp256k1zkp_v0_8_0_fe_set_b32(&ge->x, &gen->data[0]); + succeed = rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&ge->x, &gen->data[0]); VERIFY_CHECK(succeed != 0); - succeed = rustsecp256k1zkp_v0_8_0_fe_set_b32(&ge->y, &gen->data[32]); + succeed = rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&ge->y, &gen->data[32]); VERIFY_CHECK(succeed != 0); ge->infinity = 0; (void) succeed; } -static void rustsecp256k1zkp_v0_8_0_generator_save(rustsecp256k1zkp_v0_8_0_generator *gen, rustsecp256k1zkp_v0_8_0_ge* ge) { - VERIFY_CHECK(!rustsecp256k1zkp_v0_8_0_ge_is_infinity(ge)); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&ge->x); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&ge->y); - rustsecp256k1zkp_v0_8_0_fe_get_b32(&gen->data[0], &ge->x); - rustsecp256k1zkp_v0_8_0_fe_get_b32(&gen->data[32], &ge->y); +static void rustsecp256k1zkp_v0_10_0_generator_save(rustsecp256k1zkp_v0_10_0_generator *gen, rustsecp256k1zkp_v0_10_0_ge* ge) { + VERIFY_CHECK(!rustsecp256k1zkp_v0_10_0_ge_is_infinity(ge)); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&ge->x); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&ge->y); + rustsecp256k1zkp_v0_10_0_fe_get_b32(&gen->data[0], &ge->x); + rustsecp256k1zkp_v0_10_0_fe_get_b32(&gen->data[32], &ge->y); } -int rustsecp256k1zkp_v0_8_0_generator_parse(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_generator* gen, const unsigned char *input) { - rustsecp256k1zkp_v0_8_0_fe x; - rustsecp256k1zkp_v0_8_0_ge ge; +int rustsecp256k1zkp_v0_10_0_generator_parse(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_generator* gen, const unsigned char *input) { + rustsecp256k1zkp_v0_10_0_fe x; + rustsecp256k1zkp_v0_10_0_ge ge; VERIFY_CHECK(ctx != NULL); ARG_CHECK(gen != NULL); ARG_CHECK(input != NULL); if ((input[0] & 0xFE) != 10 || - !rustsecp256k1zkp_v0_8_0_fe_set_b32(&x, &input[1]) || - !rustsecp256k1zkp_v0_8_0_ge_set_xquad(&ge, &x)) { + !rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&x, &input[1]) || + !rustsecp256k1zkp_v0_10_0_ge_set_xquad(&ge, &x)) { return 0; } if (input[0] & 1) { - rustsecp256k1zkp_v0_8_0_ge_neg(&ge, &ge); + rustsecp256k1zkp_v0_10_0_ge_neg(&ge, &ge); } - rustsecp256k1zkp_v0_8_0_generator_save(gen, &ge); + rustsecp256k1zkp_v0_10_0_generator_save(gen, &ge); return 1; } -int rustsecp256k1zkp_v0_8_0_generator_serialize(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *output, const rustsecp256k1zkp_v0_8_0_generator* gen) { - rustsecp256k1zkp_v0_8_0_ge ge; +int rustsecp256k1zkp_v0_10_0_generator_serialize(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *output, const rustsecp256k1zkp_v0_10_0_generator* gen) { + rustsecp256k1zkp_v0_10_0_ge ge; VERIFY_CHECK(ctx != NULL); ARG_CHECK(output != NULL); ARG_CHECK(gen != NULL); - rustsecp256k1zkp_v0_8_0_generator_load(&ge, gen); + rustsecp256k1zkp_v0_10_0_generator_load(&ge, gen); - output[0] = 11 ^ rustsecp256k1zkp_v0_8_0_fe_is_quad_var(&ge.y); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&ge.x); - rustsecp256k1zkp_v0_8_0_fe_get_b32(&output[1], &ge.x); + output[0] = 11 ^ rustsecp256k1zkp_v0_10_0_fe_is_square_var(&ge.y); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&ge.x); + rustsecp256k1zkp_v0_10_0_fe_get_b32(&output[1], &ge.x); return 1; } -static void shallue_van_de_woestijne(rustsecp256k1zkp_v0_8_0_ge* ge, const rustsecp256k1zkp_v0_8_0_fe* t) { +static void shallue_van_de_woestijne(rustsecp256k1zkp_v0_10_0_ge* ge, const rustsecp256k1zkp_v0_10_0_fe* t) { /* Implements the algorithm from: * Indifferentiable Hashing to Barreto-Naehrig Curves * Pierre-Alain Fouque and Mehdi Tibouchi @@ -107,159 +107,175 @@ static void shallue_van_de_woestijne(rustsecp256k1zkp_v0_8_0_ge* ge, const rusts x2 = -(x1 + 1) x3 = 1 + 1/w^2 - To avoid the 2 divisions, compute the above in numerator/denominator form: - wn = c * t - wd = 1 + 7 + t^2 - x1n = d*wd - t*wn - x1d = wd - x2n = -(x1n + wd) - x2d = wd - x3n = wd^2 + c^2 + t^2 - x3d = (c * t)^2 - - The joint denominator j = wd * c^2 * t^2, and - 1 / x1d = 1/j * c^2 * t^2 - 1 / x2d = x3d = 1/j * wd + To avoid the 2 divisions, compute the joint denominator j = wd * x3d, where + wd = 1 + b + t^2 + x3d = c^2 * t^2 = -3 * t^2 + + so that if j != 0, then + + 1 / wd = 1/j * x3d + 1 / x3d = 1/j * wd + + x1 = d - c * t^2 * x3d / j + x3 = 1 + wd^3 / j + + If j = 0, the function outputs the point (d, f(d)). This point is equal + to (x1, f(x1)) as defined above if division by 0 is defined to be 0. In + below code this is not special-cased because rustsecp256k1zkp_v0_10_0_fe_inv returns 0 + on input 0. + + j = 0 happens only when t = 0 (since wd != 0 as -8 is not a square). */ - static const rustsecp256k1zkp_v0_8_0_fe c = SECP256K1_FE_CONST(0x0a2d2ba9, 0x3507f1df, 0x233770c2, 0xa797962c, 0xc61f6d15, 0xda14ecd4, 0x7d8d27ae, 0x1cd5f852); - static const rustsecp256k1zkp_v0_8_0_fe d = SECP256K1_FE_CONST(0x851695d4, 0x9a83f8ef, 0x919bb861, 0x53cbcb16, 0x630fb68a, 0xed0a766a, 0x3ec693d6, 0x8e6afa40); - static const rustsecp256k1zkp_v0_8_0_fe b = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 7); - static const rustsecp256k1zkp_v0_8_0_fe b_plus_one = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 8); + static const rustsecp256k1zkp_v0_10_0_fe negc = SECP256K1_FE_CONST(0xf5d2d456, 0xcaf80e20, 0xdcc88f3d, 0x586869d3, 0x39e092ea, 0x25eb132b, 0x8272d850, 0xe32a03dd); + static const rustsecp256k1zkp_v0_10_0_fe d = SECP256K1_FE_CONST(0x851695d4, 0x9a83f8ef, 0x919bb861, 0x53cbcb16, 0x630fb68a, 0xed0a766a, 0x3ec693d6, 0x8e6afa40); - rustsecp256k1zkp_v0_8_0_fe wn, wd, x1n, x2n, x3n, x3d, jinv, tmp, x1, x2, x3, alphain, betain, gammain, y1, y2, y3; + rustsecp256k1zkp_v0_10_0_fe wd, x3d, jinv, tmp, x1, x2, x3, alphain, betain, gammain, y1, y2, y3; int alphaquad, betaquad; - rustsecp256k1zkp_v0_8_0_fe_mul(&wn, &c, t); /* mag 1 */ - rustsecp256k1zkp_v0_8_0_fe_sqr(&wd, t); /* mag 1 */ - rustsecp256k1zkp_v0_8_0_fe_add(&wd, &b_plus_one); /* mag 2 */ - rustsecp256k1zkp_v0_8_0_fe_mul(&tmp, t, &wn); /* mag 1 */ - rustsecp256k1zkp_v0_8_0_fe_negate(&tmp, &tmp, 1); /* mag 2 */ - rustsecp256k1zkp_v0_8_0_fe_mul(&x1n, &d, &wd); /* mag 1 */ - rustsecp256k1zkp_v0_8_0_fe_add(&x1n, &tmp); /* mag 3 */ - x2n = x1n; /* mag 3 */ - rustsecp256k1zkp_v0_8_0_fe_add(&x2n, &wd); /* mag 5 */ - rustsecp256k1zkp_v0_8_0_fe_negate(&x2n, &x2n, 5); /* mag 6 */ - rustsecp256k1zkp_v0_8_0_fe_mul(&x3d, &c, t); /* mag 1 */ - rustsecp256k1zkp_v0_8_0_fe_sqr(&x3d, &x3d); /* mag 1 */ - rustsecp256k1zkp_v0_8_0_fe_sqr(&x3n, &wd); /* mag 1 */ - rustsecp256k1zkp_v0_8_0_fe_add(&x3n, &x3d); /* mag 2 */ - rustsecp256k1zkp_v0_8_0_fe_mul(&jinv, &x3d, &wd); /* mag 1 */ - rustsecp256k1zkp_v0_8_0_fe_inv(&jinv, &jinv); /* mag 1 */ - rustsecp256k1zkp_v0_8_0_fe_mul(&x1, &x1n, &x3d); /* mag 1 */ - rustsecp256k1zkp_v0_8_0_fe_mul(&x1, &x1, &jinv); /* mag 1 */ - rustsecp256k1zkp_v0_8_0_fe_mul(&x2, &x2n, &x3d); /* mag 1 */ - rustsecp256k1zkp_v0_8_0_fe_mul(&x2, &x2, &jinv); /* mag 1 */ - rustsecp256k1zkp_v0_8_0_fe_mul(&x3, &x3n, &wd); /* mag 1 */ - rustsecp256k1zkp_v0_8_0_fe_mul(&x3, &x3, &jinv); /* mag 1 */ - - rustsecp256k1zkp_v0_8_0_fe_sqr(&alphain, &x1); /* mag 1 */ - rustsecp256k1zkp_v0_8_0_fe_mul(&alphain, &alphain, &x1); /* mag 1 */ - rustsecp256k1zkp_v0_8_0_fe_add(&alphain, &b); /* mag 2 */ - rustsecp256k1zkp_v0_8_0_fe_sqr(&betain, &x2); /* mag 1 */ - rustsecp256k1zkp_v0_8_0_fe_mul(&betain, &betain, &x2); /* mag 1 */ - rustsecp256k1zkp_v0_8_0_fe_add(&betain, &b); /* mag 2 */ - rustsecp256k1zkp_v0_8_0_fe_sqr(&gammain, &x3); /* mag 1 */ - rustsecp256k1zkp_v0_8_0_fe_mul(&gammain, &gammain, &x3); /* mag 1 */ - rustsecp256k1zkp_v0_8_0_fe_add(&gammain, &b); /* mag 2 */ - - alphaquad = rustsecp256k1zkp_v0_8_0_fe_sqrt(&y1, &alphain); - betaquad = rustsecp256k1zkp_v0_8_0_fe_sqrt(&y2, &betain); - rustsecp256k1zkp_v0_8_0_fe_sqrt(&y3, &gammain); - - rustsecp256k1zkp_v0_8_0_fe_cmov(&x1, &x2, (!alphaquad) & betaquad); - rustsecp256k1zkp_v0_8_0_fe_cmov(&y1, &y2, (!alphaquad) & betaquad); - rustsecp256k1zkp_v0_8_0_fe_cmov(&x1, &x3, (!alphaquad) & !betaquad); - rustsecp256k1zkp_v0_8_0_fe_cmov(&y1, &y3, (!alphaquad) & !betaquad); - - rustsecp256k1zkp_v0_8_0_ge_set_xy(ge, &x1, &y1); + /* wd = t^2 */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&wd, t); /* mag 1 */ + /* x1 = -c * t^2 */ + rustsecp256k1zkp_v0_10_0_fe_mul(&x1, &negc, &wd); /* mag 1 */ + /* x3d = t^2 */ + x3d = wd; /* mag 1 */ + /* x3d = 3 * t^2 */ + rustsecp256k1zkp_v0_10_0_fe_mul_int(&x3d, 3); /* mag 3 */ + /* x3d = -3 * t^2 */ + rustsecp256k1zkp_v0_10_0_fe_negate(&x3d, &x3d, 3); /* mag 4 */ + /* wd = 1 + b + t^2 */ + rustsecp256k1zkp_v0_10_0_fe_add_int(&wd, SECP256K1_B + 1); /* mag 2 */ + /* jinv = wd * x3d */ + rustsecp256k1zkp_v0_10_0_fe_mul(&jinv, &wd, &x3d); /* mag 1 */ + /* jinv = 1/(wd * x3d) */ + rustsecp256k1zkp_v0_10_0_fe_inv(&jinv, &jinv); /* mag 1 */ + /* x1 = -c * t^2 * x3d */ + rustsecp256k1zkp_v0_10_0_fe_mul(&x1, &x1, &x3d); /* mag 1 */ + /* x1 = -c * t^2 * x3d * 1/j */ + rustsecp256k1zkp_v0_10_0_fe_mul(&x1, &x1, &jinv); /* mag 1 */ + /* x1 = d + -c * t^2 * x3d * 1/j */ + rustsecp256k1zkp_v0_10_0_fe_add(&x1, &d); /* mag 2 */ + /* x2 = x1 */ + x2 = x1; /* mag 2 */ + /* x2 = x1 + 1 */ + rustsecp256k1zkp_v0_10_0_fe_add_int(&x2, 1); /* mag 3 */ + /* x2 = - (x1 + 1) */ + rustsecp256k1zkp_v0_10_0_fe_negate(&x2, &x2, 3); /* mag 4 */ + /* x3 = wd^2 */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&x3, &wd); /* mag 1 */ + /* x3 = wd^3 */ + rustsecp256k1zkp_v0_10_0_fe_mul(&x3, &x3, &wd); /* mag 1 */ + /* x3 = wd^3 * 1/j */ + rustsecp256k1zkp_v0_10_0_fe_mul(&x3, &x3, &jinv); /* mag 1 */ + /* x3 = 1 + (wd^3 * 1/j) */ + rustsecp256k1zkp_v0_10_0_fe_add_int(&x3, 1); /* mag 2 */ + + rustsecp256k1zkp_v0_10_0_fe_sqr(&alphain, &x1); /* mag 1 */ + rustsecp256k1zkp_v0_10_0_fe_mul(&alphain, &alphain, &x1); /* mag 1 */ + rustsecp256k1zkp_v0_10_0_fe_add_int(&alphain, SECP256K1_B); /* mag 2 */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&betain, &x2); /* mag 1 */ + rustsecp256k1zkp_v0_10_0_fe_mul(&betain, &betain, &x2); /* mag 1 */ + rustsecp256k1zkp_v0_10_0_fe_add_int(&betain, SECP256K1_B); /* mag 2 */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&gammain, &x3); /* mag 1 */ + rustsecp256k1zkp_v0_10_0_fe_mul(&gammain, &gammain, &x3); /* mag 1 */ + rustsecp256k1zkp_v0_10_0_fe_add_int(&gammain, SECP256K1_B); /* mag 2 */ + + alphaquad = rustsecp256k1zkp_v0_10_0_fe_sqrt(&y1, &alphain); + betaquad = rustsecp256k1zkp_v0_10_0_fe_sqrt(&y2, &betain); + rustsecp256k1zkp_v0_10_0_fe_sqrt(&y3, &gammain); + + rustsecp256k1zkp_v0_10_0_fe_cmov(&x1, &x2, (!alphaquad) & betaquad); + rustsecp256k1zkp_v0_10_0_fe_cmov(&y1, &y2, (!alphaquad) & betaquad); + rustsecp256k1zkp_v0_10_0_fe_cmov(&x1, &x3, (!alphaquad) & !betaquad); + rustsecp256k1zkp_v0_10_0_fe_cmov(&y1, &y3, (!alphaquad) & !betaquad); + + rustsecp256k1zkp_v0_10_0_ge_set_xy(ge, &x1, &y1); /* The linked algorithm from the paper uses the Jacobi symbol of t to * determine the Jacobi symbol of the produced y coordinate. Since the * rest of the algorithm only uses t^2, we can safely use another criterion * as long as negation of t results in negation of the y coordinate. Here * we choose to use t's oddness, as it is faster to determine. */ - rustsecp256k1zkp_v0_8_0_fe_negate(&tmp, &ge->y, 1); - rustsecp256k1zkp_v0_8_0_fe_cmov(&ge->y, &tmp, rustsecp256k1zkp_v0_8_0_fe_is_odd(t)); + rustsecp256k1zkp_v0_10_0_fe_negate(&tmp, &ge->y, 1); + rustsecp256k1zkp_v0_10_0_fe_cmov(&ge->y, &tmp, rustsecp256k1zkp_v0_10_0_fe_is_odd(t)); } -static int rustsecp256k1zkp_v0_8_0_generator_generate_internal(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_generator* gen, const unsigned char *key32, const unsigned char *blind32) { +static int rustsecp256k1zkp_v0_10_0_generator_generate_internal(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_generator* gen, const unsigned char *key32, const unsigned char *blind32) { static const unsigned char prefix1[17] = "1st generation: "; static const unsigned char prefix2[17] = "2nd generation: "; - rustsecp256k1zkp_v0_8_0_fe t = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 4); - rustsecp256k1zkp_v0_8_0_ge add; - rustsecp256k1zkp_v0_8_0_gej accum; + rustsecp256k1zkp_v0_10_0_fe t = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 4); + rustsecp256k1zkp_v0_10_0_ge add; + rustsecp256k1zkp_v0_10_0_gej accum; int overflow; - rustsecp256k1zkp_v0_8_0_sha256 sha256; + rustsecp256k1zkp_v0_10_0_sha256 sha256; unsigned char b32[32]; int ret = 1; if (blind32) { - rustsecp256k1zkp_v0_8_0_scalar blind; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&blind, blind32, &overflow); + rustsecp256k1zkp_v0_10_0_scalar blind; + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&blind, blind32, &overflow); ret = !overflow; - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &accum, &blind); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&ctx->ecmult_gen_ctx, &accum, &blind); } - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha256); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256, prefix1, 16); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256, key32, 32); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha256, b32); - ret &= rustsecp256k1zkp_v0_8_0_fe_set_b32(&t, b32); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha256); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256, prefix1, 16); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256, key32, 32); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha256, b32); + ret &= rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&t, b32); shallue_van_de_woestijne(&add, &t); if (blind32) { - rustsecp256k1zkp_v0_8_0_gej_add_ge(&accum, &accum, &add); + rustsecp256k1zkp_v0_10_0_gej_add_ge(&accum, &accum, &add); } else { - rustsecp256k1zkp_v0_8_0_gej_set_ge(&accum, &add); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&accum, &add); } - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha256); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256, prefix2, 16); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256, key32, 32); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha256, b32); - ret &= rustsecp256k1zkp_v0_8_0_fe_set_b32(&t, b32); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha256); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256, prefix2, 16); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256, key32, 32); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha256, b32); + ret &= rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&t, b32); shallue_van_de_woestijne(&add, &t); - rustsecp256k1zkp_v0_8_0_gej_add_ge(&accum, &accum, &add); + rustsecp256k1zkp_v0_10_0_gej_add_ge(&accum, &accum, &add); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&add, &accum); - rustsecp256k1zkp_v0_8_0_generator_save(gen, &add); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&add, &accum); + rustsecp256k1zkp_v0_10_0_generator_save(gen, &add); return ret; } -int rustsecp256k1zkp_v0_8_0_generator_generate(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_generator* gen, const unsigned char *key32) { +int rustsecp256k1zkp_v0_10_0_generator_generate(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_generator* gen, const unsigned char *key32) { VERIFY_CHECK(ctx != NULL); ARG_CHECK(gen != NULL); ARG_CHECK(key32 != NULL); - return rustsecp256k1zkp_v0_8_0_generator_generate_internal(ctx, gen, key32, NULL); + return rustsecp256k1zkp_v0_10_0_generator_generate_internal(ctx, gen, key32, NULL); } -int rustsecp256k1zkp_v0_8_0_generator_generate_blinded(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_generator* gen, const unsigned char *key32, const unsigned char *blind32) { +int rustsecp256k1zkp_v0_10_0_generator_generate_blinded(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_generator* gen, const unsigned char *key32, const unsigned char *blind32) { VERIFY_CHECK(ctx != NULL); ARG_CHECK(gen != NULL); ARG_CHECK(key32 != NULL); ARG_CHECK(blind32 != NULL); - ARG_CHECK(rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); - return rustsecp256k1zkp_v0_8_0_generator_generate_internal(ctx, gen, key32, blind32); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); + return rustsecp256k1zkp_v0_10_0_generator_generate_internal(ctx, gen, key32, blind32); } -static void rustsecp256k1zkp_v0_8_0_pedersen_commitment_load(rustsecp256k1zkp_v0_8_0_ge* ge, const rustsecp256k1zkp_v0_8_0_pedersen_commitment* commit) { - rustsecp256k1zkp_v0_8_0_fe fe; - rustsecp256k1zkp_v0_8_0_fe_set_b32(&fe, &commit->data[1]); - rustsecp256k1zkp_v0_8_0_ge_set_xquad(ge, &fe); +static void rustsecp256k1zkp_v0_10_0_pedersen_commitment_load(rustsecp256k1zkp_v0_10_0_ge* ge, const rustsecp256k1zkp_v0_10_0_pedersen_commitment* commit) { + rustsecp256k1zkp_v0_10_0_fe fe; + rustsecp256k1zkp_v0_10_0_fe_set_b32_mod(&fe, &commit->data[1]); + rustsecp256k1zkp_v0_10_0_ge_set_xquad(ge, &fe); if (commit->data[0] & 1) { - rustsecp256k1zkp_v0_8_0_ge_neg(ge, ge); + rustsecp256k1zkp_v0_10_0_ge_neg(ge, ge); } } -static void rustsecp256k1zkp_v0_8_0_pedersen_commitment_save(rustsecp256k1zkp_v0_8_0_pedersen_commitment* commit, rustsecp256k1zkp_v0_8_0_ge* ge) { - rustsecp256k1zkp_v0_8_0_fe_normalize(&ge->x); - rustsecp256k1zkp_v0_8_0_fe_get_b32(&commit->data[1], &ge->x); - commit->data[0] = 9 ^ rustsecp256k1zkp_v0_8_0_fe_is_quad_var(&ge->y); +static void rustsecp256k1zkp_v0_10_0_pedersen_commitment_save(rustsecp256k1zkp_v0_10_0_pedersen_commitment* commit, rustsecp256k1zkp_v0_10_0_ge* ge) { + rustsecp256k1zkp_v0_10_0_fe_normalize(&ge->x); + rustsecp256k1zkp_v0_10_0_fe_get_b32(&commit->data[1], &ge->x); + commit->data[0] = 9 ^ rustsecp256k1zkp_v0_10_0_fe_is_square_var(&ge->y); } -int rustsecp256k1zkp_v0_8_0_pedersen_commitment_parse(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pedersen_commitment* commit, const unsigned char *input) { - rustsecp256k1zkp_v0_8_0_fe x; - rustsecp256k1zkp_v0_8_0_ge ge; +int rustsecp256k1zkp_v0_10_0_pedersen_commitment_parse(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_pedersen_commitment* commit, const unsigned char *input) { + rustsecp256k1zkp_v0_10_0_fe x; VERIFY_CHECK(ctx != NULL); ARG_CHECK(commit != NULL); @@ -267,67 +283,59 @@ int rustsecp256k1zkp_v0_8_0_pedersen_commitment_parse(const rustsecp256k1zkp_v0_ (void) ctx; if ((input[0] & 0xFE) != 8 || - !rustsecp256k1zkp_v0_8_0_fe_set_b32(&x, &input[1]) || - !rustsecp256k1zkp_v0_8_0_ge_set_xquad(&ge, &x)) { + !rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&x, &input[1]) || + !rustsecp256k1zkp_v0_10_0_ge_x_on_curve_var(&x)) { return 0; } - if (input[0] & 1) { - rustsecp256k1zkp_v0_8_0_ge_neg(&ge, &ge); - } - rustsecp256k1zkp_v0_8_0_pedersen_commitment_save(commit, &ge); + + memcpy(commit->data, input, 33); return 1; } -int rustsecp256k1zkp_v0_8_0_pedersen_commitment_serialize(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *output, const rustsecp256k1zkp_v0_8_0_pedersen_commitment* commit) { - rustsecp256k1zkp_v0_8_0_ge ge; - +int rustsecp256k1zkp_v0_10_0_pedersen_commitment_serialize(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *output, const rustsecp256k1zkp_v0_10_0_pedersen_commitment* commit) { VERIFY_CHECK(ctx != NULL); ARG_CHECK(output != NULL); ARG_CHECK(commit != NULL); - rustsecp256k1zkp_v0_8_0_pedersen_commitment_load(&ge, commit); - - output[0] = 9 ^ rustsecp256k1zkp_v0_8_0_fe_is_quad_var(&ge.y); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&ge.x); - rustsecp256k1zkp_v0_8_0_fe_get_b32(&output[1], &ge.x); + memcpy(output, commit->data, 33); return 1; } /* Generates a pedersen commitment: *commit = blind * G + value * G2. The blinding factor is 32 bytes.*/ -int rustsecp256k1zkp_v0_8_0_pedersen_commit(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pedersen_commitment *commit, const unsigned char *blind, uint64_t value, const rustsecp256k1zkp_v0_8_0_generator* gen) { - rustsecp256k1zkp_v0_8_0_ge genp; - rustsecp256k1zkp_v0_8_0_gej rj; - rustsecp256k1zkp_v0_8_0_ge r; - rustsecp256k1zkp_v0_8_0_scalar sec; +int rustsecp256k1zkp_v0_10_0_pedersen_commit(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_pedersen_commitment *commit, const unsigned char *blind, uint64_t value, const rustsecp256k1zkp_v0_10_0_generator* gen) { + rustsecp256k1zkp_v0_10_0_ge genp; + rustsecp256k1zkp_v0_10_0_gej rj; + rustsecp256k1zkp_v0_10_0_ge r; + rustsecp256k1zkp_v0_10_0_scalar sec; int overflow; int ret = 0; VERIFY_CHECK(ctx != NULL); - ARG_CHECK(rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); ARG_CHECK(commit != NULL); ARG_CHECK(blind != NULL); ARG_CHECK(gen != NULL); - rustsecp256k1zkp_v0_8_0_generator_load(&genp, gen); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&sec, blind, &overflow); + rustsecp256k1zkp_v0_10_0_generator_load(&genp, gen); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&sec, blind, &overflow); if (!overflow) { - rustsecp256k1zkp_v0_8_0_pedersen_ecmult(&ctx->ecmult_gen_ctx, &rj, &sec, value, &genp); - if (!rustsecp256k1zkp_v0_8_0_gej_is_infinity(&rj)) { - rustsecp256k1zkp_v0_8_0_ge_set_gej(&r, &rj); - rustsecp256k1zkp_v0_8_0_pedersen_commitment_save(commit, &r); + rustsecp256k1zkp_v0_10_0_pedersen_ecmult(&ctx->ecmult_gen_ctx, &rj, &sec, value, &genp); + if (!rustsecp256k1zkp_v0_10_0_gej_is_infinity(&rj)) { + rustsecp256k1zkp_v0_10_0_ge_set_gej(&r, &rj); + rustsecp256k1zkp_v0_10_0_pedersen_commitment_save(commit, &r); ret = 1; } - rustsecp256k1zkp_v0_8_0_gej_clear(&rj); - rustsecp256k1zkp_v0_8_0_ge_clear(&r); + rustsecp256k1zkp_v0_10_0_gej_clear(&rj); + rustsecp256k1zkp_v0_10_0_ge_clear(&r); } - rustsecp256k1zkp_v0_8_0_scalar_clear(&sec); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sec); return ret; } /** Takes a list of n pointers to 32 byte blinding values, the first negs of which are treated with positive sign and the rest * negative, then calculates an additional blinding value that adds to zero. */ -int rustsecp256k1zkp_v0_8_0_pedersen_blind_sum(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *blind_out, const unsigned char * const *blinds, size_t n, size_t npositive) { - rustsecp256k1zkp_v0_8_0_scalar acc; - rustsecp256k1zkp_v0_8_0_scalar x; +int rustsecp256k1zkp_v0_10_0_pedersen_blind_sum(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *blind_out, const unsigned char * const *blinds, size_t n, size_t npositive) { + rustsecp256k1zkp_v0_10_0_scalar acc; + rustsecp256k1zkp_v0_10_0_scalar x; size_t i; int overflow; VERIFY_CHECK(ctx != NULL); @@ -335,48 +343,48 @@ int rustsecp256k1zkp_v0_8_0_pedersen_blind_sum(const rustsecp256k1zkp_v0_8_0_con ARG_CHECK(blinds != NULL); ARG_CHECK(npositive <= n); (void) ctx; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&acc, 0); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&acc, 0); for (i = 0; i < n; i++) { - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&x, blinds[i], &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&x, blinds[i], &overflow); if (overflow) { return 0; } if (i >= npositive) { - rustsecp256k1zkp_v0_8_0_scalar_negate(&x, &x); + rustsecp256k1zkp_v0_10_0_scalar_negate(&x, &x); } - rustsecp256k1zkp_v0_8_0_scalar_add(&acc, &acc, &x); + rustsecp256k1zkp_v0_10_0_scalar_add(&acc, &acc, &x); } - rustsecp256k1zkp_v0_8_0_scalar_get_b32(blind_out, &acc); - rustsecp256k1zkp_v0_8_0_scalar_clear(&acc); - rustsecp256k1zkp_v0_8_0_scalar_clear(&x); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(blind_out, &acc); + rustsecp256k1zkp_v0_10_0_scalar_clear(&acc); + rustsecp256k1zkp_v0_10_0_scalar_clear(&x); return 1; } /* Takes two lists of commitments and sums the first set and subtracts the second and verifies that they sum to excess. */ -int rustsecp256k1zkp_v0_8_0_pedersen_verify_tally(const rustsecp256k1zkp_v0_8_0_context* ctx, const rustsecp256k1zkp_v0_8_0_pedersen_commitment * const* commits, size_t pcnt, const rustsecp256k1zkp_v0_8_0_pedersen_commitment * const* ncommits, size_t ncnt) { - rustsecp256k1zkp_v0_8_0_gej accj; - rustsecp256k1zkp_v0_8_0_ge add; +int rustsecp256k1zkp_v0_10_0_pedersen_verify_tally(const rustsecp256k1zkp_v0_10_0_context* ctx, const rustsecp256k1zkp_v0_10_0_pedersen_commitment * const* commits, size_t pcnt, const rustsecp256k1zkp_v0_10_0_pedersen_commitment * const* ncommits, size_t ncnt) { + rustsecp256k1zkp_v0_10_0_gej accj; + rustsecp256k1zkp_v0_10_0_ge add; size_t i; VERIFY_CHECK(ctx != NULL); ARG_CHECK(!pcnt || (commits != NULL)); ARG_CHECK(!ncnt || (ncommits != NULL)); (void) ctx; - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&accj); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&accj); for (i = 0; i < ncnt; i++) { - rustsecp256k1zkp_v0_8_0_pedersen_commitment_load(&add, ncommits[i]); - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&accj, &accj, &add, NULL); + rustsecp256k1zkp_v0_10_0_pedersen_commitment_load(&add, ncommits[i]); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&accj, &accj, &add, NULL); } - rustsecp256k1zkp_v0_8_0_gej_neg(&accj, &accj); + rustsecp256k1zkp_v0_10_0_gej_neg(&accj, &accj); for (i = 0; i < pcnt; i++) { - rustsecp256k1zkp_v0_8_0_pedersen_commitment_load(&add, commits[i]); - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&accj, &accj, &add, NULL); + rustsecp256k1zkp_v0_10_0_pedersen_commitment_load(&add, commits[i]); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&accj, &accj, &add, NULL); } - return rustsecp256k1zkp_v0_8_0_gej_is_infinity(&accj); + return rustsecp256k1zkp_v0_10_0_gej_is_infinity(&accj); } -int rustsecp256k1zkp_v0_8_0_pedersen_blind_generator_blind_sum(const rustsecp256k1zkp_v0_8_0_context* ctx, const uint64_t *value, const unsigned char* const* generator_blind, unsigned char* const* blinding_factor, size_t n_total, size_t n_inputs) { - rustsecp256k1zkp_v0_8_0_scalar sum; - rustsecp256k1zkp_v0_8_0_scalar tmp; +int rustsecp256k1zkp_v0_10_0_pedersen_blind_generator_blind_sum(const rustsecp256k1zkp_v0_10_0_context* ctx, const uint64_t *value, const unsigned char* const* generator_blind, unsigned char* const* blinding_factor, size_t n_total, size_t n_inputs) { + rustsecp256k1zkp_v0_10_0_scalar sum; + rustsecp256k1zkp_v0_10_0_scalar tmp; size_t i; VERIFY_CHECK(ctx != NULL); @@ -390,8 +398,8 @@ int rustsecp256k1zkp_v0_8_0_pedersen_blind_generator_blind_sum(const rustsecp256 return 1; } - rustsecp256k1zkp_v0_8_0_scalar_set_int(&sum, 0); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&tmp, 0); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&sum, 0); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&tmp, 0); /* Here, n_total > 0. Thus the loop runs at least once. Thus we may use a do-while loop, which checks the loop @@ -402,40 +410,40 @@ int rustsecp256k1zkp_v0_8_0_pedersen_blind_generator_blind_sum(const rustsecp256 i = 0; do { int overflow = 0; - rustsecp256k1zkp_v0_8_0_scalar addend; - rustsecp256k1zkp_v0_8_0_scalar_set_u64(&addend, value[i]); /* s = v */ + rustsecp256k1zkp_v0_10_0_scalar addend; + rustsecp256k1zkp_v0_10_0_scalar_set_u64(&addend, value[i]); /* s = v */ - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&tmp, generator_blind[i], &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&tmp, generator_blind[i], &overflow); if (overflow == 1) { - rustsecp256k1zkp_v0_8_0_scalar_clear(&tmp); - rustsecp256k1zkp_v0_8_0_scalar_clear(&addend); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sum); + rustsecp256k1zkp_v0_10_0_scalar_clear(&tmp); + rustsecp256k1zkp_v0_10_0_scalar_clear(&addend); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sum); return 0; } - rustsecp256k1zkp_v0_8_0_scalar_mul(&addend, &addend, &tmp); /* s = vr */ + rustsecp256k1zkp_v0_10_0_scalar_mul(&addend, &addend, &tmp); /* s = vr */ - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&tmp, blinding_factor[i], &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&tmp, blinding_factor[i], &overflow); if (overflow == 1) { - rustsecp256k1zkp_v0_8_0_scalar_clear(&tmp); - rustsecp256k1zkp_v0_8_0_scalar_clear(&addend); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sum); + rustsecp256k1zkp_v0_10_0_scalar_clear(&tmp); + rustsecp256k1zkp_v0_10_0_scalar_clear(&addend); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sum); return 0; } - rustsecp256k1zkp_v0_8_0_scalar_add(&addend, &addend, &tmp); /* s = vr + r' */ - rustsecp256k1zkp_v0_8_0_scalar_cond_negate(&addend, i < n_inputs); /* s is negated if it's an input */ - rustsecp256k1zkp_v0_8_0_scalar_add(&sum, &sum, &addend); /* sum += s */ - rustsecp256k1zkp_v0_8_0_scalar_clear(&addend); + rustsecp256k1zkp_v0_10_0_scalar_add(&addend, &addend, &tmp); /* s = vr + r' */ + rustsecp256k1zkp_v0_10_0_scalar_cond_negate(&addend, i < n_inputs); /* s is negated if it's an input */ + rustsecp256k1zkp_v0_10_0_scalar_add(&sum, &sum, &addend); /* sum += s */ + rustsecp256k1zkp_v0_10_0_scalar_clear(&addend); i++; } while (i < n_total); /* Right now tmp has the last pedersen blinding factor. Subtract the sum from it. */ - rustsecp256k1zkp_v0_8_0_scalar_negate(&sum, &sum); - rustsecp256k1zkp_v0_8_0_scalar_add(&tmp, &tmp, &sum); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(blinding_factor[n_total - 1], &tmp); + rustsecp256k1zkp_v0_10_0_scalar_negate(&sum, &sum); + rustsecp256k1zkp_v0_10_0_scalar_add(&tmp, &tmp, &sum); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(blinding_factor[n_total - 1], &tmp); - rustsecp256k1zkp_v0_8_0_scalar_clear(&tmp); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sum); + rustsecp256k1zkp_v0_10_0_scalar_clear(&tmp); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sum); return 1; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/generator/pedersen.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/generator/pedersen.h index a45b5825..23fd98b9 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/generator/pedersen.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/generator/pedersen.h @@ -4,8 +4,8 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef _SECP256K1_PEDERSEN_H_ -#define _SECP256K1_PEDERSEN_H_ +#ifndef SECP256K1_PEDERSEN_H +#define SECP256K1_PEDERSEN_H #include "../../ecmult_gen.h" #include "../../group.h" @@ -14,9 +14,9 @@ #include /** Multiply a small number with the generator: r = gn*G2 */ -static void rustsecp256k1zkp_v0_8_0_pedersen_ecmult_small(rustsecp256k1zkp_v0_8_0_gej *r, uint64_t gn, const rustsecp256k1zkp_v0_8_0_ge* genp); +static void rustsecp256k1zkp_v0_10_0_pedersen_ecmult_small(rustsecp256k1zkp_v0_10_0_gej *r, uint64_t gn, const rustsecp256k1zkp_v0_10_0_ge* genp); /* sec * G + value * G2. */ -static void rustsecp256k1zkp_v0_8_0_pedersen_ecmult(const rustsecp256k1zkp_v0_8_0_ecmult_gen_context *ecmult_gen_ctx, rustsecp256k1zkp_v0_8_0_gej *rj, const rustsecp256k1zkp_v0_8_0_scalar *sec, uint64_t value, const rustsecp256k1zkp_v0_8_0_ge* genp); +static void rustsecp256k1zkp_v0_10_0_pedersen_ecmult(const rustsecp256k1zkp_v0_10_0_ecmult_gen_context *ecmult_gen_ctx, rustsecp256k1zkp_v0_10_0_gej *rj, const rustsecp256k1zkp_v0_10_0_scalar *sec, uint64_t value, const rustsecp256k1zkp_v0_10_0_ge* genp); #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/generator/pedersen_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/generator/pedersen_impl.h index d37c7a1a..f4158901 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/generator/pedersen_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/generator/pedersen_impl.h @@ -4,8 +4,8 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php. * ***********************************************************************/ -#ifndef _SECP256K1_PEDERSEN_IMPL_H_ -#define _SECP256K1_PEDERSEN_IMPL_H_ +#ifndef SECP256K1_PEDERSEN_IMPL_H +#define SECP256K1_PEDERSEN_IMPL_H #include @@ -17,7 +17,7 @@ #include "../../scalar.h" #include "../../util.h" -static void rustsecp256k1zkp_v0_8_0_pedersen_scalar_set_u64(rustsecp256k1zkp_v0_8_0_scalar *sec, uint64_t value) { +static void rustsecp256k1zkp_v0_10_0_pedersen_scalar_set_u64(rustsecp256k1zkp_v0_10_0_scalar *sec, uint64_t value) { unsigned char data[32]; int i; for (i = 0; i < 24; i++) { @@ -27,25 +27,25 @@ static void rustsecp256k1zkp_v0_8_0_pedersen_scalar_set_u64(rustsecp256k1zkp_v0_ data[i] = value >> 56; value <<= 8; } - rustsecp256k1zkp_v0_8_0_scalar_set_b32(sec, data, NULL); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(sec, data, NULL); memset(data, 0, 32); } -static void rustsecp256k1zkp_v0_8_0_pedersen_ecmult_small(rustsecp256k1zkp_v0_8_0_gej *r, uint64_t gn, const rustsecp256k1zkp_v0_8_0_ge* genp) { - rustsecp256k1zkp_v0_8_0_scalar s; - rustsecp256k1zkp_v0_8_0_pedersen_scalar_set_u64(&s, gn); - rustsecp256k1zkp_v0_8_0_ecmult_const(r, genp, &s, 64); - rustsecp256k1zkp_v0_8_0_scalar_clear(&s); +static void rustsecp256k1zkp_v0_10_0_pedersen_ecmult_small(rustsecp256k1zkp_v0_10_0_gej *r, uint64_t gn, const rustsecp256k1zkp_v0_10_0_ge* genp) { + rustsecp256k1zkp_v0_10_0_scalar s; + rustsecp256k1zkp_v0_10_0_pedersen_scalar_set_u64(&s, gn); + rustsecp256k1zkp_v0_10_0_ecmult_const(r, genp, &s); + rustsecp256k1zkp_v0_10_0_scalar_clear(&s); } /* sec * G + value * G2. */ -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_pedersen_ecmult(const rustsecp256k1zkp_v0_8_0_ecmult_gen_context *ecmult_gen_ctx, rustsecp256k1zkp_v0_8_0_gej *rj, const rustsecp256k1zkp_v0_8_0_scalar *sec, uint64_t value, const rustsecp256k1zkp_v0_8_0_ge* genp) { - rustsecp256k1zkp_v0_8_0_gej vj; - rustsecp256k1zkp_v0_8_0_ecmult_gen(ecmult_gen_ctx, rj, sec); - rustsecp256k1zkp_v0_8_0_pedersen_ecmult_small(&vj, value, genp); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_pedersen_ecmult(const rustsecp256k1zkp_v0_10_0_ecmult_gen_context *ecmult_gen_ctx, rustsecp256k1zkp_v0_10_0_gej *rj, const rustsecp256k1zkp_v0_10_0_scalar *sec, uint64_t value, const rustsecp256k1zkp_v0_10_0_ge* genp) { + rustsecp256k1zkp_v0_10_0_gej vj; + rustsecp256k1zkp_v0_10_0_ecmult_gen(ecmult_gen_ctx, rj, sec); + rustsecp256k1zkp_v0_10_0_pedersen_ecmult_small(&vj, value, genp); /* FIXME: constant time. */ - rustsecp256k1zkp_v0_8_0_gej_add_var(rj, rj, &vj, NULL); - rustsecp256k1zkp_v0_8_0_gej_clear(&vj); + rustsecp256k1zkp_v0_10_0_gej_add_var(rj, rj, &vj, NULL); + rustsecp256k1zkp_v0_10_0_gej_clear(&vj); } #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/generator/tests_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/generator/tests_impl.h index 63dcbbeb..3b48d098 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/generator/tests_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/generator/tests_impl.h @@ -4,8 +4,8 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef SECP256K1_MODULE_GENERATOR_TESTS -#define SECP256K1_MODULE_GENERATOR_TESTS +#ifndef SECP256K1_MODULE_GENERATOR_TESTS_H +#define SECP256K1_MODULE_GENERATOR_TESTS_H #include #include @@ -17,74 +17,40 @@ #include "../../../include/secp256k1_generator.h" -void test_generator_api(void) { +static void test_generator_api(void) { unsigned char key[32]; unsigned char blind[32]; unsigned char sergen[33]; - rustsecp256k1zkp_v0_8_0_context *none = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_NONE); - rustsecp256k1zkp_v0_8_0_context *sign = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN); - rustsecp256k1zkp_v0_8_0_context *vrfy = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_VERIFY); - rustsecp256k1zkp_v0_8_0_context *sttc = rustsecp256k1zkp_v0_8_0_context_clone(rustsecp256k1zkp_v0_8_0_context_no_precomp); - rustsecp256k1zkp_v0_8_0_generator gen; - int32_t ecount = 0; - - rustsecp256k1zkp_v0_8_0_context_set_error_callback(none, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(sign, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(vrfy, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(sttc, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(none, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sign, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(vrfy, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sttc, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_testrand256(key); - rustsecp256k1zkp_v0_8_0_testrand256(blind); - - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate(none, &gen, key) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate(none, NULL, key) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate(none, &gen, NULL) == 0); - CHECK(ecount == 2); - - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate_blinded(sign, &gen, key, blind) == 1); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate_blinded(vrfy, &gen, key, blind) == 1); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate_blinded(none, &gen, key, blind) == 1); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate_blinded(sttc, &gen, key, blind) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate_blinded(vrfy, NULL, key, blind) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate_blinded(vrfy, &gen, NULL, blind) == 0); - CHECK(ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate_blinded(vrfy, &gen, key, NULL) == 0); - CHECK(ecount == 6); - - CHECK(rustsecp256k1zkp_v0_8_0_generator_serialize(none, sergen, &gen) == 1); - CHECK(ecount == 6); - CHECK(rustsecp256k1zkp_v0_8_0_generator_serialize(none, NULL, &gen) == 0); - CHECK(ecount == 7); - CHECK(rustsecp256k1zkp_v0_8_0_generator_serialize(none, sergen, NULL) == 0); - CHECK(ecount == 8); - - CHECK(rustsecp256k1zkp_v0_8_0_generator_serialize(none, sergen, &gen) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_generator_parse(none, &gen, sergen) == 1); - CHECK(ecount == 8); - CHECK(rustsecp256k1zkp_v0_8_0_generator_parse(none, NULL, sergen) == 0); - CHECK(ecount == 9); - CHECK(rustsecp256k1zkp_v0_8_0_generator_parse(none, &gen, NULL) == 0); - CHECK(ecount == 10); - - rustsecp256k1zkp_v0_8_0_context_destroy(none); - rustsecp256k1zkp_v0_8_0_context_destroy(sign); - rustsecp256k1zkp_v0_8_0_context_destroy(vrfy); - rustsecp256k1zkp_v0_8_0_context_destroy(sttc); + rustsecp256k1zkp_v0_10_0_generator gen; + + rustsecp256k1zkp_v0_10_0_testrand256(key); + rustsecp256k1zkp_v0_10_0_testrand256(blind); + + CHECK(rustsecp256k1zkp_v0_10_0_generator_generate(CTX, &gen, key) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_generator_generate(CTX, NULL, key)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_generator_generate(CTX, &gen, NULL)); + + CHECK(rustsecp256k1zkp_v0_10_0_generator_generate_blinded(CTX, &gen, key, blind) == 1); + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_generator_generate_blinded(STATIC_CTX, &gen, key, blind)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_generator_generate_blinded(CTX, NULL, key, blind)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_generator_generate_blinded(CTX, &gen, NULL, blind)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_generator_generate_blinded(CTX, &gen, key, NULL)); + + CHECK(rustsecp256k1zkp_v0_10_0_generator_serialize(CTX, sergen, &gen) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_generator_serialize(CTX, NULL, &gen)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_generator_serialize(CTX, sergen, NULL)); + + CHECK(rustsecp256k1zkp_v0_10_0_generator_serialize(CTX, sergen, &gen) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_generator_parse(CTX, &gen, sergen) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_generator_parse(CTX, NULL, sergen)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_generator_parse(CTX, &gen, NULL)); } -void test_shallue_van_de_woestijne(void) { +static void test_shallue_van_de_woestijne(void) { /* Matches with the output of the shallue_van_de_woestijne.sage SAGE program */ - static const rustsecp256k1zkp_v0_8_0_ge_storage results[32] = { + static const rustsecp256k1zkp_v0_10_0_ge_storage results[34] = { + SECP256K1_GE_STORAGE_CONST(0x851695d4, 0x9a83f8ef, 0x919bb861, 0x53cbcb16, 0x630fb68a, 0xed0a766a, 0x3ec693d6, 0x8e6afa40, 0x4218f20a, 0xe6c646b3, 0x63db6860, 0x5822fb14, 0x264ca8d2, 0x587fdd6f, 0xbc750d58, 0x7e76a7ee), + SECP256K1_GE_STORAGE_CONST(0x851695d4, 0x9a83f8ef, 0x919bb861, 0x53cbcb16, 0x630fb68a, 0xed0a766a, 0x3ec693d6, 0x8e6afa40, 0x4218f20a, 0xe6c646b3, 0x63db6860, 0x5822fb14, 0x264ca8d2, 0x587fdd6f, 0xbc750d58, 0x7e76a7ee), SECP256K1_GE_STORAGE_CONST(0xedd1fd3e, 0x327ce90c, 0xc7a35426, 0x14289aee, 0x9682003e, 0x9cf7dcc9, 0xcf2ca974, 0x3be5aa0c, 0x0225f529, 0xee75acaf, 0xccfc4560, 0x26c5e46b, 0xf80237a3, 0x3924655a, 0x16f90e88, 0x085ed52a), SECP256K1_GE_STORAGE_CONST(0xedd1fd3e, 0x327ce90c, 0xc7a35426, 0x14289aee, 0x9682003e, 0x9cf7dcc9, 0xcf2ca974, 0x3be5aa0c, 0xfdda0ad6, 0x118a5350, 0x3303ba9f, 0xd93a1b94, 0x07fdc85c, 0xc6db9aa5, 0xe906f176, 0xf7a12705), SECP256K1_GE_STORAGE_CONST(0x2c5cdc9c, 0x338152fa, 0x85de92cb, 0x1bee9907, 0x765a922e, 0x4f037cce, 0x14ecdbf2, 0x2f78fe15, 0x56716069, 0x6818286b, 0x72f01a3e, 0x5e8caca7, 0x36249160, 0xc7ded69d, 0xd51913c3, 0x03a2fa97), @@ -119,28 +85,28 @@ void test_shallue_van_de_woestijne(void) { SECP256K1_GE_STORAGE_CONST(0xf75763bc, 0x2907e79b, 0x125e33c3, 0x9a027f48, 0x0f8c6409, 0x2153432f, 0x967bc2b1, 0x1d1f5cf0, 0x4b571239, 0xc9c6e4c6, 0x643de63f, 0xc2fcced7, 0x2432b9c1, 0x2daf9c6b, 0xf9e47859, 0x61aef9fa), }; - rustsecp256k1zkp_v0_8_0_ge ge; - rustsecp256k1zkp_v0_8_0_fe fe; - rustsecp256k1zkp_v0_8_0_ge_storage ges; + rustsecp256k1zkp_v0_10_0_ge ge; + rustsecp256k1zkp_v0_10_0_fe fe; + rustsecp256k1zkp_v0_10_0_ge_storage ges; int i, s; - for (i = 1; i <= 16; i++) { - rustsecp256k1zkp_v0_8_0_fe_set_int(&fe, i); + for (i = 0; i <= 16; i++) { + rustsecp256k1zkp_v0_10_0_fe_set_int(&fe, i); for (s = 0; s < 2; s++) { if (s) { - rustsecp256k1zkp_v0_8_0_fe_negate(&fe, &fe, 1); - rustsecp256k1zkp_v0_8_0_fe_normalize(&fe); + rustsecp256k1zkp_v0_10_0_fe_negate(&fe, &fe, 1); + rustsecp256k1zkp_v0_10_0_fe_normalize(&fe); } shallue_van_de_woestijne(&ge, &fe); - rustsecp256k1zkp_v0_8_0_ge_to_storage(&ges, &ge); - - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&ges, &results[i * 2 + s - 2], sizeof(rustsecp256k1zkp_v0_8_0_ge_storage)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ge_is_valid_var(&ge)); + rustsecp256k1zkp_v0_10_0_ge_to_storage(&ges, &ge); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&ges, &results[i * 2 + s], sizeof(rustsecp256k1zkp_v0_10_0_ge_storage)) == 0); } } } -void test_generator_generate(void) { - static const rustsecp256k1zkp_v0_8_0_ge_storage results[32] = { +static void test_generator_generate(void) { + static const rustsecp256k1zkp_v0_10_0_ge_storage results[32] = { SECP256K1_GE_STORAGE_CONST(0x806cd8ed, 0xd6c153e3, 0x4aa9b9a0, 0x8755c4be, 0x4718b1ef, 0xb26cb93f, 0xfdd99e1b, 0x21f2af8e, 0xc7062208, 0xcc649a03, 0x1bdc1a33, 0x9d01f115, 0x4bcd0dca, 0xfe0b875d, 0x62f35f73, 0x28673006), SECP256K1_GE_STORAGE_CONST(0xd91b15ec, 0x47a811f4, 0xaa189561, 0xd13f5c4d, 0x4e81f10d, 0xc7dc551f, 0x4fea9b84, 0x610314c4, 0x9b0ada1e, 0xb38efd67, 0x8bff0b6c, 0x7d7315f7, 0xb49b8cc5, 0xa679fad4, 0xc94f9dc6, 0x9da66382), SECP256K1_GE_STORAGE_CONST(0x11c00de6, 0xf885035e, 0x76051430, 0xa3c38b2a, 0x5f86ab8c, 0xf66dae58, 0x04ea7307, 0x348b19bf, 0xe0858ae7, 0x61dcb1ba, 0xff247e37, 0xd38fcd88, 0xf3bd7911, 0xaa4ed6e0, 0x28d792dd, 0x3ee1ac09), @@ -174,148 +140,108 @@ void test_generator_generate(void) { SECP256K1_GE_STORAGE_CONST(0x150df593, 0x5b6956a0, 0x0cfed843, 0xb9d6ffce, 0x4f790022, 0xea18730f, 0xc495111d, 0x91568e55, 0x6700a2ca, 0x9ff4ed32, 0xc1697312, 0x4eb51ce3, 0x5656344b, 0x65a1e3d5, 0xd6c1f7ce, 0x29233f82), SECP256K1_GE_STORAGE_CONST(0x38e02eaf, 0x2c8774fd, 0x58b8b373, 0x732457f1, 0x16dbe53b, 0xea5683d9, 0xada20dd7, 0x14ce20a6, 0x6ac5362e, 0xbb425416, 0x8250f43f, 0xa4ee2b63, 0x0406324f, 0x1c876d60, 0xebe5be2c, 0x6eb1515b), }; - rustsecp256k1zkp_v0_8_0_generator gen; - rustsecp256k1zkp_v0_8_0_ge ge; - rustsecp256k1zkp_v0_8_0_ge_storage ges; + rustsecp256k1zkp_v0_10_0_generator gen; + rustsecp256k1zkp_v0_10_0_ge ge; + rustsecp256k1zkp_v0_10_0_ge_storage ges; int i; unsigned char v[32]; unsigned char s[32] = {0}; - rustsecp256k1zkp_v0_8_0_scalar sc; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&sc, s, NULL); + rustsecp256k1zkp_v0_10_0_scalar sc; + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&sc, s, NULL); for (i = 1; i <= 32; i++) { memset(v, 0, 31); v[31] = i; - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate_blinded(ctx, &gen, v, s)); - rustsecp256k1zkp_v0_8_0_generator_load(&ge, &gen); - rustsecp256k1zkp_v0_8_0_ge_to_storage(&ges, &ge); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&ges, &results[i - 1], sizeof(rustsecp256k1zkp_v0_8_0_ge_storage)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate(ctx, &gen, v)); - rustsecp256k1zkp_v0_8_0_generator_load(&ge, &gen); - rustsecp256k1zkp_v0_8_0_ge_to_storage(&ges, &ge); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&ges, &results[i - 1], sizeof(rustsecp256k1zkp_v0_8_0_ge_storage)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_generator_generate_blinded(CTX, &gen, v, s)); + rustsecp256k1zkp_v0_10_0_generator_load(&ge, &gen); + rustsecp256k1zkp_v0_10_0_ge_to_storage(&ges, &ge); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&ges, &results[i - 1], sizeof(rustsecp256k1zkp_v0_10_0_ge_storage)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_generator_generate(CTX, &gen, v)); + rustsecp256k1zkp_v0_10_0_generator_load(&ge, &gen); + rustsecp256k1zkp_v0_10_0_ge_to_storage(&ges, &ge); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&ges, &results[i - 1], sizeof(rustsecp256k1zkp_v0_10_0_ge_storage)) == 0); } /* There is no range restriction on the value, but the blinder must be a * valid scalar. Check that an invalid blinder causes the call to fail * but not crash. */ memset(v, 0xff, 32); - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate(ctx, &gen, v)); + CHECK(rustsecp256k1zkp_v0_10_0_generator_generate(CTX, &gen, v)); memset(s, 0xff, 32); - CHECK(!rustsecp256k1zkp_v0_8_0_generator_generate_blinded(ctx, &gen, v, s)); + CHECK(!rustsecp256k1zkp_v0_10_0_generator_generate_blinded(CTX, &gen, v, s)); } -void test_generator_fixed_vector(void) { +static void test_generator_fixed_vector(void) { const unsigned char two_g[33] = { 0x0b, 0xc6, 0x04, 0x7f, 0x94, 0x41, 0xed, 0x7d, 0x6d, 0x30, 0x45, 0x40, 0x6e, 0x95, 0xc0, 0x7c, 0xd8, 0x5c, 0x77, 0x8e, 0x4b, 0x8c, 0xef, 0x3c, 0xa7, 0xab, 0xac, 0x09, 0xb9, 0x5c, 0x70, 0x9e, 0xe5 }; unsigned char result[33]; - rustsecp256k1zkp_v0_8_0_generator parse; + rustsecp256k1zkp_v0_10_0_generator parse; - CHECK(rustsecp256k1zkp_v0_8_0_generator_parse(ctx, &parse, two_g)); - CHECK(rustsecp256k1zkp_v0_8_0_generator_serialize(ctx, result, &parse)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(two_g, result, 33) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_generator_parse(CTX, &parse, two_g)); + CHECK(rustsecp256k1zkp_v0_10_0_generator_serialize(CTX, result, &parse)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(two_g, result, 33) == 0); result[0] = 0x0a; - CHECK(rustsecp256k1zkp_v0_8_0_generator_parse(ctx, &parse, result)); + CHECK(rustsecp256k1zkp_v0_10_0_generator_parse(CTX, &parse, result)); result[0] = 0x08; - CHECK(!rustsecp256k1zkp_v0_8_0_generator_parse(ctx, &parse, result)); + CHECK(!rustsecp256k1zkp_v0_10_0_generator_parse(CTX, &parse, result)); } static void test_pedersen_api(void) { - rustsecp256k1zkp_v0_8_0_context *none = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_NONE); - rustsecp256k1zkp_v0_8_0_context *sign = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN); - rustsecp256k1zkp_v0_8_0_context *vrfy = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_VERIFY); - rustsecp256k1zkp_v0_8_0_context *sttc = rustsecp256k1zkp_v0_8_0_context_clone(rustsecp256k1zkp_v0_8_0_context_no_precomp); - rustsecp256k1zkp_v0_8_0_pedersen_commitment commit; - const rustsecp256k1zkp_v0_8_0_pedersen_commitment *commit_ptr = &commit; + rustsecp256k1zkp_v0_10_0_pedersen_commitment commit; + const rustsecp256k1zkp_v0_10_0_pedersen_commitment *commit_ptr = &commit; unsigned char blind[32]; unsigned char blind_out[32]; const unsigned char *blind_ptr = blind; unsigned char *blind_out_ptr = blind_out; - uint64_t val = rustsecp256k1zkp_v0_8_0_testrand32(); - int32_t ecount = 0; - - rustsecp256k1zkp_v0_8_0_context_set_error_callback(none, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(sign, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(vrfy, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(sttc, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(none, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sign, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(vrfy, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sttc, counting_illegal_callback_fn, &ecount); - - rustsecp256k1zkp_v0_8_0_testrand256(blind); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(none, &commit, blind, val, rustsecp256k1zkp_v0_8_0_generator_h) != 0); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(vrfy, &commit, blind, val, rustsecp256k1zkp_v0_8_0_generator_h) != 0); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(sign, &commit, blind, val, rustsecp256k1zkp_v0_8_0_generator_h) != 0); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(sttc, &commit, blind, val, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(ecount == 1); - - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(sign, NULL, blind, val, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(sign, &commit, NULL, val, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(sign, &commit, blind, val, NULL) == 0); - CHECK(ecount == 4); - - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_blind_sum(none, blind_out, &blind_ptr, 1, 1) != 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_blind_sum(none, NULL, &blind_ptr, 1, 1) == 0); - CHECK(ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_blind_sum(none, blind_out, NULL, 1, 1) == 0); - CHECK(ecount == 6); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_blind_sum(none, blind_out, &blind_ptr, 0, 1) == 0); - CHECK(ecount == 7); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_blind_sum(none, blind_out, &blind_ptr, 0, 0) != 0); - CHECK(ecount == 7); - - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(sign, &commit, blind, val, rustsecp256k1zkp_v0_8_0_generator_h) != 0); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_verify_tally(none, &commit_ptr, 1, &commit_ptr, 1) != 0); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_verify_tally(none, NULL, 0, &commit_ptr, 1) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_verify_tally(none, &commit_ptr, 1, NULL, 0) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_verify_tally(none, NULL, 0, NULL, 0) != 0); - CHECK(ecount == 7); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_verify_tally(none, NULL, 1, &commit_ptr, 1) == 0); - CHECK(ecount == 8); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_verify_tally(none, &commit_ptr, 1, NULL, 1) == 0); - CHECK(ecount == 9); - - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_blind_generator_blind_sum(none, &val, &blind_ptr, &blind_out_ptr, 1, 0) != 0); - CHECK(ecount == 9); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_blind_generator_blind_sum(none, &val, &blind_ptr, &blind_out_ptr, 1, 1) == 0); - CHECK(ecount == 10); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_blind_generator_blind_sum(none, &val, &blind_ptr, &blind_out_ptr, 0, 0) == 0); - CHECK(ecount == 11); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_blind_generator_blind_sum(none, NULL, &blind_ptr, &blind_out_ptr, 1, 0) == 0); - CHECK(ecount == 12); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_blind_generator_blind_sum(none, &val, NULL, &blind_out_ptr, 1, 0) == 0); - CHECK(ecount == 13); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_blind_generator_blind_sum(none, &val, &blind_ptr, NULL, 1, 0) == 0); - CHECK(ecount == 14); - - rustsecp256k1zkp_v0_8_0_context_destroy(none); - rustsecp256k1zkp_v0_8_0_context_destroy(sign); - rustsecp256k1zkp_v0_8_0_context_destroy(vrfy); - rustsecp256k1zkp_v0_8_0_context_destroy(sttc); + uint64_t val = rustsecp256k1zkp_v0_10_0_testrand32(); + + rustsecp256k1zkp_v0_10_0_testrand256(blind); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commit(CTX, &commit, blind, val, rustsecp256k1zkp_v0_10_0_generator_h) != 0); + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_pedersen_commit(STATIC_CTX, &commit, blind, val, rustsecp256k1zkp_v0_10_0_generator_h)); + + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pedersen_commit(CTX, NULL, blind, val, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pedersen_commit(CTX, &commit, NULL, val, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pedersen_commit(CTX, &commit, blind, val, NULL)); + + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_blind_sum(CTX, blind_out, &blind_ptr, 1, 1) != 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pedersen_blind_sum(CTX, NULL, &blind_ptr, 1, 1)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pedersen_blind_sum(CTX, blind_out, NULL, 1, 1)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pedersen_blind_sum(CTX, blind_out, &blind_ptr, 0, 1)); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_blind_sum(CTX, blind_out, &blind_ptr, 0, 0) != 0); + + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commit(CTX, &commit, blind, val, rustsecp256k1zkp_v0_10_0_generator_h) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_verify_tally(CTX, &commit_ptr, 1, &commit_ptr, 1) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_verify_tally(CTX, NULL, 0, &commit_ptr, 1) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_verify_tally(CTX, &commit_ptr, 1, NULL, 0) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_verify_tally(CTX, NULL, 0, NULL, 0) != 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pedersen_verify_tally(CTX, NULL, 1, &commit_ptr, 1)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pedersen_verify_tally(CTX, &commit_ptr, 1, NULL, 1)); + + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_blind_generator_blind_sum(CTX, &val, &blind_ptr, &blind_out_ptr, 1, 0) != 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pedersen_blind_generator_blind_sum(CTX, &val, &blind_ptr, &blind_out_ptr, 1, 1)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pedersen_blind_generator_blind_sum(CTX, &val, &blind_ptr, &blind_out_ptr, 0, 0)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pedersen_blind_generator_blind_sum(CTX, NULL, &blind_ptr, &blind_out_ptr, 1, 0)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pedersen_blind_generator_blind_sum(CTX, &val, NULL, &blind_out_ptr, 1, 0)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pedersen_blind_generator_blind_sum(CTX, &val, &blind_ptr, NULL, 1, 0)); } static void test_pedersen(void) { - rustsecp256k1zkp_v0_8_0_pedersen_commitment commits[19]; - const rustsecp256k1zkp_v0_8_0_pedersen_commitment *cptr[19]; + rustsecp256k1zkp_v0_10_0_pedersen_commitment commits[19]; + const rustsecp256k1zkp_v0_10_0_pedersen_commitment *cptr[19]; unsigned char blinds[32*19]; const unsigned char *bptr[19]; - rustsecp256k1zkp_v0_8_0_scalar s; + rustsecp256k1zkp_v0_10_0_scalar s; uint64_t values[19]; int64_t totalv; int i; int inputs; int outputs; int total; - inputs = (rustsecp256k1zkp_v0_8_0_testrand32() & 7) + 1; - outputs = (rustsecp256k1zkp_v0_8_0_testrand32() & 7) + 2; + inputs = (rustsecp256k1zkp_v0_10_0_testrand32() & 7) + 1; + outputs = (rustsecp256k1zkp_v0_10_0_testrand32() & 7) + 2; total = inputs + outputs; for (i = 0; i < 19; i++) { cptr[i] = &commits[i]; @@ -323,63 +249,69 @@ static void test_pedersen(void) { } totalv = 0; for (i = 0; i < inputs; i++) { - values[i] = rustsecp256k1zkp_v0_8_0_testrandi64(0, INT64_MAX - totalv); + values[i] = rustsecp256k1zkp_v0_10_0_testrandi64(0, INT64_MAX - totalv); totalv += values[i]; } for (i = 0; i < outputs - 1; i++) { - values[i + inputs] = rustsecp256k1zkp_v0_8_0_testrandi64(0, totalv); + values[i + inputs] = rustsecp256k1zkp_v0_10_0_testrandi64(0, totalv); totalv -= values[i + inputs]; } values[total - 1] = totalv; for (i = 0; i < total - 1; i++) { random_scalar_order(&s); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&blinds[i * 32], &s); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&blinds[i * 32], &s); } - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_blind_sum(ctx, &blinds[(total - 1) * 32], bptr, total - 1, inputs)); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_blind_sum(CTX, &blinds[(total - 1) * 32], bptr, total - 1, inputs)); for (i = 0; i < total; i++) { - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(ctx, &commits[i], &blinds[i * 32], values[i], rustsecp256k1zkp_v0_8_0_generator_h)); + unsigned char result[33]; + rustsecp256k1zkp_v0_10_0_pedersen_commitment parse; + + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commit(CTX, &commits[i], &blinds[i * 32], values[i], rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commitment_serialize(CTX, result, &commits[i])); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commitment_parse(CTX, &parse, result)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&commits[i], &parse, 33) == 0); } - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_verify_tally(ctx, cptr, inputs, &cptr[inputs], outputs)); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_verify_tally(ctx, &cptr[inputs], outputs, cptr, inputs)); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_verify_tally(CTX, cptr, inputs, &cptr[inputs], outputs)); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_verify_tally(CTX, &cptr[inputs], outputs, cptr, inputs)); if (inputs > 0 && values[0] > 0) { - CHECK(!rustsecp256k1zkp_v0_8_0_pedersen_verify_tally(ctx, cptr, inputs - 1, &cptr[inputs], outputs)); + CHECK(!rustsecp256k1zkp_v0_10_0_pedersen_verify_tally(CTX, cptr, inputs - 1, &cptr[inputs], outputs)); } random_scalar_order(&s); for (i = 0; i < 4; i++) { - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&blinds[i * 32], &s); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&blinds[i * 32], &s); } values[0] = INT64_MAX; values[1] = 0; values[2] = 1; for (i = 0; i < 3; i++) { - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(ctx, &commits[i], &blinds[i * 32], values[i], rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commit(CTX, &commits[i], &blinds[i * 32], values[i], rustsecp256k1zkp_v0_10_0_generator_h)); } - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_verify_tally(ctx, &cptr[0], 1, &cptr[0], 1)); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_verify_tally(ctx, &cptr[1], 1, &cptr[1], 1)); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_verify_tally(CTX, &cptr[0], 1, &cptr[0], 1)); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_verify_tally(CTX, &cptr[1], 1, &cptr[1], 1)); } -void test_pedersen_commitment_fixed_vector(void) { +static void test_pedersen_commitment_fixed_vector(void) { const unsigned char two_g[33] = { 0x09, 0xc6, 0x04, 0x7f, 0x94, 0x41, 0xed, 0x7d, 0x6d, 0x30, 0x45, 0x40, 0x6e, 0x95, 0xc0, 0x7c, 0xd8, 0x5c, 0x77, 0x8e, 0x4b, 0x8c, 0xef, 0x3c, 0xa7, 0xab, 0xac, 0x09, 0xb9, 0x5c, 0x70, 0x9e, 0xe5 }; unsigned char result[33]; - rustsecp256k1zkp_v0_8_0_pedersen_commitment parse; + rustsecp256k1zkp_v0_10_0_pedersen_commitment parse; - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commitment_parse(ctx, &parse, two_g)); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commitment_serialize(ctx, result, &parse)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(two_g, result, 33) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commitment_parse(CTX, &parse, two_g)); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commitment_serialize(CTX, result, &parse)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(two_g, result, 33) == 0); result[0] = 0x08; - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commitment_parse(ctx, &parse, result)); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commitment_parse(CTX, &parse, result)); result[0] = 0x0c; - CHECK(!rustsecp256k1zkp_v0_8_0_pedersen_commitment_parse(ctx, &parse, result)); + CHECK(!rustsecp256k1zkp_v0_10_0_pedersen_commitment_parse(CTX, &parse, result)); } -void run_generator_tests(void) { +static void run_generator_tests(void) { int i; test_shallue_van_de_woestijne(); @@ -388,7 +320,7 @@ void run_generator_tests(void) { test_generator_generate(); test_pedersen_api(); test_pedersen_commitment_fixed_vector(); - for (i = 0; i < count / 2 + 1; i++) { + for (i = 0; i < COUNT / 2 + 1; i++) { test_pedersen(); } } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/Makefile.am.include b/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/Makefile.am.include index 5d9dc608..c5e8a922 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/Makefile.am.include +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/Makefile.am.include @@ -1,4 +1,4 @@ -include_HEADERS += include/rustsecp256k1zkp_v0_8_0_musig.h +include_HEADERS += include/rustsecp256k1zkp_v0_10_0_musig.h noinst_HEADERS += src/modules/musig/main_impl.h noinst_HEADERS += src/modules/musig/keyagg.h noinst_HEADERS += src/modules/musig/keyagg_impl.h diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/adaptor_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/adaptor_impl.h index 93e70531..660cf543 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/adaptor_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/adaptor_impl.h @@ -15,22 +15,22 @@ #include "session.h" #include "../../scalar.h" -int rustsecp256k1zkp_v0_8_0_musig_nonce_parity(const rustsecp256k1zkp_v0_8_0_context* ctx, int *nonce_parity, const rustsecp256k1zkp_v0_8_0_musig_session *session) { - rustsecp256k1zkp_v0_8_0_musig_session_internal session_i; +int rustsecp256k1zkp_v0_10_0_musig_nonce_parity(const rustsecp256k1zkp_v0_10_0_context* ctx, int *nonce_parity, const rustsecp256k1zkp_v0_10_0_musig_session *session) { + rustsecp256k1zkp_v0_10_0_musig_session_internal session_i; VERIFY_CHECK(ctx != NULL); ARG_CHECK(nonce_parity != NULL); ARG_CHECK(session != NULL); - if (!rustsecp256k1zkp_v0_8_0_musig_session_load(ctx, &session_i, session)) { + if (!rustsecp256k1zkp_v0_10_0_musig_session_load(ctx, &session_i, session)) { return 0; } *nonce_parity = session_i.fin_nonce_parity; return 1; } -int rustsecp256k1zkp_v0_8_0_musig_adapt(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *sig64, const unsigned char *pre_sig64, const unsigned char *sec_adaptor32, int nonce_parity) { - rustsecp256k1zkp_v0_8_0_scalar s; - rustsecp256k1zkp_v0_8_0_scalar t; +int rustsecp256k1zkp_v0_10_0_musig_adapt(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *sig64, const unsigned char *pre_sig64, const unsigned char *sec_adaptor32, int nonce_parity) { + rustsecp256k1zkp_v0_10_0_scalar s; + rustsecp256k1zkp_v0_10_0_scalar t; int overflow; int ret = 1; @@ -40,11 +40,11 @@ int rustsecp256k1zkp_v0_8_0_musig_adapt(const rustsecp256k1zkp_v0_8_0_context* c ARG_CHECK(sec_adaptor32 != NULL); ARG_CHECK(nonce_parity == 0 || nonce_parity == 1); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&s, &pre_sig64[32], &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&s, &pre_sig64[32], &overflow); if (overflow) { return 0; } - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&t, sec_adaptor32, &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&t, sec_adaptor32, &overflow); ret &= !overflow; /* Determine if the secret adaptor should be negated. @@ -58,19 +58,19 @@ int rustsecp256k1zkp_v0_8_0_musig_adapt(const rustsecp256k1zkp_v0_8_0_context* c * pre-signature requires negating t in this case. */ if (nonce_parity) { - rustsecp256k1zkp_v0_8_0_scalar_negate(&t, &t); + rustsecp256k1zkp_v0_10_0_scalar_negate(&t, &t); } - rustsecp256k1zkp_v0_8_0_scalar_add(&s, &s, &t); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&sig64[32], &s); + rustsecp256k1zkp_v0_10_0_scalar_add(&s, &s, &t); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&sig64[32], &s); memmove(sig64, pre_sig64, 32); - rustsecp256k1zkp_v0_8_0_scalar_clear(&t); + rustsecp256k1zkp_v0_10_0_scalar_clear(&t); return ret; } -int rustsecp256k1zkp_v0_8_0_musig_extract_adaptor(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *sec_adaptor32, const unsigned char *sig64, const unsigned char *pre_sig64, int nonce_parity) { - rustsecp256k1zkp_v0_8_0_scalar t; - rustsecp256k1zkp_v0_8_0_scalar s; +int rustsecp256k1zkp_v0_10_0_musig_extract_adaptor(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *sec_adaptor32, const unsigned char *sig64, const unsigned char *pre_sig64, int nonce_parity) { + rustsecp256k1zkp_v0_10_0_scalar t; + rustsecp256k1zkp_v0_10_0_scalar s; int overflow; int ret = 1; @@ -80,21 +80,21 @@ int rustsecp256k1zkp_v0_8_0_musig_extract_adaptor(const rustsecp256k1zkp_v0_8_0_ ARG_CHECK(pre_sig64 != NULL); ARG_CHECK(nonce_parity == 0 || nonce_parity == 1); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&t, &sig64[32], &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&t, &sig64[32], &overflow); ret &= !overflow; - rustsecp256k1zkp_v0_8_0_scalar_negate(&t, &t); + rustsecp256k1zkp_v0_10_0_scalar_negate(&t, &t); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&s, &pre_sig64[32], &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&s, &pre_sig64[32], &overflow); if (overflow) { return 0; } - rustsecp256k1zkp_v0_8_0_scalar_add(&t, &t, &s); + rustsecp256k1zkp_v0_10_0_scalar_add(&t, &t, &s); if (!nonce_parity) { - rustsecp256k1zkp_v0_8_0_scalar_negate(&t, &t); + rustsecp256k1zkp_v0_10_0_scalar_negate(&t, &t); } - rustsecp256k1zkp_v0_8_0_scalar_get_b32(sec_adaptor32, &t); - rustsecp256k1zkp_v0_8_0_scalar_clear(&t); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(sec_adaptor32, &t); + rustsecp256k1zkp_v0_10_0_scalar_clear(&t); return ret; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/keyagg.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/keyagg.h index 79d24eb0..ee9df295 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/keyagg.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/keyagg.h @@ -15,35 +15,26 @@ #include "../../scalar.h" typedef struct { - rustsecp256k1zkp_v0_8_0_ge pk; + rustsecp256k1zkp_v0_10_0_ge pk; /* If there is no "second" public key, second_pk is set to the point at * infinity */ - rustsecp256k1zkp_v0_8_0_ge second_pk; + rustsecp256k1zkp_v0_10_0_ge second_pk; unsigned char pk_hash[32]; /* tweak is identical to value tacc[v] in the specification. */ - rustsecp256k1zkp_v0_8_0_scalar tweak; + rustsecp256k1zkp_v0_10_0_scalar tweak; /* parity_acc corresponds to gacc[v] in the spec. If gacc[v] is -1, * parity_acc is 1. Otherwise, parity_acc is 0. */ int parity_acc; -} rustsecp256k1zkp_v0_8_0_keyagg_cache_internal; - -/* Save and load points to and from byte arrays, similar to - * rustsecp256k1zkp_v0_8_0_pubkey_{save,load}. */ -static void rustsecp256k1zkp_v0_8_0_point_save(unsigned char *data, rustsecp256k1zkp_v0_8_0_ge *ge); - -/* In contrast to pubkey_load, point_load does not attempt to check that data - * has been initialized, since it is assumed that this check already happened - * (e.g. by comparing magic bytes) */ -static void rustsecp256k1zkp_v0_8_0_point_load(rustsecp256k1zkp_v0_8_0_ge *ge, const unsigned char *data); +} rustsecp256k1zkp_v0_10_0_keyagg_cache_internal; /* point_save_ext and point_load_ext are identical to point_save and point_load * except that they allow saving and loading the point at infinity */ -static void rustsecp256k1zkp_v0_8_0_point_save_ext(unsigned char *data, rustsecp256k1zkp_v0_8_0_ge *ge); +static void rustsecp256k1zkp_v0_10_0_point_save_ext(unsigned char *data, rustsecp256k1zkp_v0_10_0_ge *ge); -static void rustsecp256k1zkp_v0_8_0_point_load_ext(rustsecp256k1zkp_v0_8_0_ge *ge, const unsigned char *data); +static void rustsecp256k1zkp_v0_10_0_point_load_ext(rustsecp256k1zkp_v0_10_0_ge *ge, const unsigned char *data); -static int rustsecp256k1zkp_v0_8_0_keyagg_cache_load(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_keyagg_cache_internal *cache_i, const rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *cache); +static int rustsecp256k1zkp_v0_10_0_keyagg_cache_load(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_keyagg_cache_internal *cache_i, const rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *cache); -static void rustsecp256k1zkp_v0_8_0_musig_keyaggcoef(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_keyagg_cache_internal *cache_i, rustsecp256k1zkp_v0_8_0_ge *pk); +static void rustsecp256k1zkp_v0_10_0_musig_keyaggcoef(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_keyagg_cache_internal *cache_i, rustsecp256k1zkp_v0_10_0_ge *pk); #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/keyagg_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/keyagg_impl.h index 5ec13263..d849af70 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/keyagg_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/keyagg_impl.h @@ -17,54 +17,24 @@ #include "../../hash.h" #include "../../util.h" -static void rustsecp256k1zkp_v0_8_0_point_save(unsigned char *data, rustsecp256k1zkp_v0_8_0_ge *ge) { - if (sizeof(rustsecp256k1zkp_v0_8_0_ge_storage) == 64) { - rustsecp256k1zkp_v0_8_0_ge_storage s; - rustsecp256k1zkp_v0_8_0_ge_to_storage(&s, ge); - memcpy(data, &s, sizeof(s)); - } else { - VERIFY_CHECK(!rustsecp256k1zkp_v0_8_0_ge_is_infinity(ge)); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&ge->x); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&ge->y); - rustsecp256k1zkp_v0_8_0_fe_get_b32(data, &ge->x); - rustsecp256k1zkp_v0_8_0_fe_get_b32(data + 32, &ge->y); - } -} - -static void rustsecp256k1zkp_v0_8_0_point_load(rustsecp256k1zkp_v0_8_0_ge *ge, const unsigned char *data) { - if (sizeof(rustsecp256k1zkp_v0_8_0_ge_storage) == 64) { - /* When the rustsecp256k1zkp_v0_8_0_ge_storage type is exactly 64 byte, use its - * representation as conversion is very fast. */ - rustsecp256k1zkp_v0_8_0_ge_storage s; - memcpy(&s, data, sizeof(s)); - rustsecp256k1zkp_v0_8_0_ge_from_storage(ge, &s); - } else { - /* Otherwise, fall back to 32-byte big endian for X and Y. */ - rustsecp256k1zkp_v0_8_0_fe x, y; - rustsecp256k1zkp_v0_8_0_fe_set_b32(&x, data); - rustsecp256k1zkp_v0_8_0_fe_set_b32(&y, data + 32); - rustsecp256k1zkp_v0_8_0_ge_set_xy(ge, &x, &y); - } -} - -static void rustsecp256k1zkp_v0_8_0_point_save_ext(unsigned char *data, rustsecp256k1zkp_v0_8_0_ge *ge) { - if (rustsecp256k1zkp_v0_8_0_ge_is_infinity(ge)) { +static void rustsecp256k1zkp_v0_10_0_point_save_ext(unsigned char *data, rustsecp256k1zkp_v0_10_0_ge *ge) { + if (rustsecp256k1zkp_v0_10_0_ge_is_infinity(ge)) { memset(data, 0, 64); } else { - rustsecp256k1zkp_v0_8_0_point_save(data, ge); + rustsecp256k1zkp_v0_10_0_ge_to_bytes(data, ge); } } -static void rustsecp256k1zkp_v0_8_0_point_load_ext(rustsecp256k1zkp_v0_8_0_ge *ge, const unsigned char *data) { +static void rustsecp256k1zkp_v0_10_0_point_load_ext(rustsecp256k1zkp_v0_10_0_ge *ge, const unsigned char *data) { unsigned char zeros[64] = { 0 }; - if (rustsecp256k1zkp_v0_8_0_memcmp_var(data, zeros, sizeof(zeros)) == 0) { - rustsecp256k1zkp_v0_8_0_ge_set_infinity(ge); + if (rustsecp256k1zkp_v0_10_0_memcmp_var(data, zeros, sizeof(zeros)) == 0) { + rustsecp256k1zkp_v0_10_0_ge_set_infinity(ge); } else { - rustsecp256k1zkp_v0_8_0_point_load(ge, data); + rustsecp256k1zkp_v0_10_0_ge_from_bytes(ge, data); } } -static const unsigned char rustsecp256k1zkp_v0_8_0_musig_keyagg_cache_magic[4] = { 0xf4, 0xad, 0xbb, 0xdf }; +static const unsigned char rustsecp256k1zkp_v0_10_0_musig_keyagg_cache_magic[4] = { 0xf4, 0xad, 0xbb, 0xdf }; /* A keyagg cache consists of * - 4 byte magic set during initialization to allow detecting an uninitialized @@ -76,41 +46,41 @@ static const unsigned char rustsecp256k1zkp_v0_8_0_musig_keyagg_cache_magic[4] = * - 32 byte tweak */ /* Requires that cache_i->pk is not infinity and cache_i->second_pk_x to be normalized. */ -static void rustsecp256k1zkp_v0_8_0_keyagg_cache_save(rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *cache, rustsecp256k1zkp_v0_8_0_keyagg_cache_internal *cache_i) { +static void rustsecp256k1zkp_v0_10_0_keyagg_cache_save(rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *cache, rustsecp256k1zkp_v0_10_0_keyagg_cache_internal *cache_i) { unsigned char *ptr = cache->data; - memcpy(ptr, rustsecp256k1zkp_v0_8_0_musig_keyagg_cache_magic, 4); + memcpy(ptr, rustsecp256k1zkp_v0_10_0_musig_keyagg_cache_magic, 4); ptr += 4; - rustsecp256k1zkp_v0_8_0_point_save(ptr, &cache_i->pk); + rustsecp256k1zkp_v0_10_0_ge_to_bytes(ptr, &cache_i->pk); ptr += 64; - rustsecp256k1zkp_v0_8_0_point_save_ext(ptr, &cache_i->second_pk); + rustsecp256k1zkp_v0_10_0_point_save_ext(ptr, &cache_i->second_pk); ptr += 64; memcpy(ptr, cache_i->pk_hash, 32); ptr += 32; *ptr = cache_i->parity_acc; ptr += 1; - rustsecp256k1zkp_v0_8_0_scalar_get_b32(ptr, &cache_i->tweak); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(ptr, &cache_i->tweak); } -static int rustsecp256k1zkp_v0_8_0_keyagg_cache_load(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_keyagg_cache_internal *cache_i, const rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *cache) { +static int rustsecp256k1zkp_v0_10_0_keyagg_cache_load(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_keyagg_cache_internal *cache_i, const rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *cache) { const unsigned char *ptr = cache->data; - ARG_CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(ptr, rustsecp256k1zkp_v0_8_0_musig_keyagg_cache_magic, 4) == 0); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(ptr, rustsecp256k1zkp_v0_10_0_musig_keyagg_cache_magic, 4) == 0); ptr += 4; - rustsecp256k1zkp_v0_8_0_point_load(&cache_i->pk, ptr); + rustsecp256k1zkp_v0_10_0_ge_from_bytes(&cache_i->pk, ptr); ptr += 64; - rustsecp256k1zkp_v0_8_0_point_load_ext(&cache_i->second_pk, ptr); + rustsecp256k1zkp_v0_10_0_point_load_ext(&cache_i->second_pk, ptr); ptr += 64; memcpy(cache_i->pk_hash, ptr, 32); ptr += 32; cache_i->parity_acc = *ptr & 1; ptr += 1; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&cache_i->tweak, ptr, NULL); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&cache_i->tweak, ptr, NULL); return 1; } /* Initializes SHA256 with fixed midstate. This midstate was computed by applying * SHA256 to SHA256("KeyAgg list")||SHA256("KeyAgg list"). */ -static void rustsecp256k1zkp_v0_8_0_musig_keyagglist_sha256(rustsecp256k1zkp_v0_8_0_sha256 *sha) { - rustsecp256k1zkp_v0_8_0_sha256_initialize(sha); +static void rustsecp256k1zkp_v0_10_0_musig_keyagglist_sha256(rustsecp256k1zkp_v0_10_0_sha256 *sha) { + rustsecp256k1zkp_v0_10_0_sha256_initialize(sha); sha->s[0] = 0xb399d5e0ul; sha->s[1] = 0xc8fff302ul; @@ -124,28 +94,28 @@ static void rustsecp256k1zkp_v0_8_0_musig_keyagglist_sha256(rustsecp256k1zkp_v0_ } /* Computes pk_hash = tagged_hash(pk[0], ..., pk[np-1]) */ -static int rustsecp256k1zkp_v0_8_0_musig_compute_pk_hash(const rustsecp256k1zkp_v0_8_0_context *ctx, unsigned char *pk_hash, const rustsecp256k1zkp_v0_8_0_pubkey * const* pk, size_t np) { - rustsecp256k1zkp_v0_8_0_sha256 sha; +static int rustsecp256k1zkp_v0_10_0_musig_compute_pk_hash(const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *pk_hash, const rustsecp256k1zkp_v0_10_0_pubkey * const* pk, size_t np) { + rustsecp256k1zkp_v0_10_0_sha256 sha; size_t i; - rustsecp256k1zkp_v0_8_0_musig_keyagglist_sha256(&sha); + rustsecp256k1zkp_v0_10_0_musig_keyagglist_sha256(&sha); for (i = 0; i < np; i++) { unsigned char ser[33]; size_t ser_len = sizeof(ser); - if (!rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, ser, &ser_len, pk[i], SECP256K1_EC_COMPRESSED)) { + if (!rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(ctx, ser, &ser_len, pk[i], SECP256K1_EC_COMPRESSED)) { return 0; } VERIFY_CHECK(ser_len == sizeof(ser)); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, ser, sizeof(ser)); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, ser, sizeof(ser)); } - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, pk_hash); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, pk_hash); return 1; } /* Initializes SHA256 with fixed midstate. This midstate was computed by applying * SHA256 to SHA256("KeyAgg coefficient")||SHA256("KeyAgg coefficient"). */ -static void rustsecp256k1zkp_v0_8_0_musig_keyaggcoef_sha256(rustsecp256k1zkp_v0_8_0_sha256 *sha) { - rustsecp256k1zkp_v0_8_0_sha256_initialize(sha); +static void rustsecp256k1zkp_v0_10_0_musig_keyaggcoef_sha256(rustsecp256k1zkp_v0_10_0_sha256 *sha) { + rustsecp256k1zkp_v0_10_0_sha256_initialize(sha); sha->s[0] = 0x6ef02c5aul; sha->s[1] = 0x06a480deul; @@ -161,60 +131,70 @@ static void rustsecp256k1zkp_v0_8_0_musig_keyaggcoef_sha256(rustsecp256k1zkp_v0_ /* Compute KeyAgg coefficient which is constant 1 for the second pubkey and * otherwise tagged_hash(pk_hash, x) where pk_hash is the hash of public keys. * second_pk is the point at infinity in case there is no second_pk. Assumes - * that pk is not the point at infinity and that the coordinates of pk and + * that pk is not the point at infinity and that the Y-coordinates of pk and * second_pk are normalized. */ -static void rustsecp256k1zkp_v0_8_0_musig_keyaggcoef_internal(rustsecp256k1zkp_v0_8_0_scalar *r, const unsigned char *pk_hash, rustsecp256k1zkp_v0_8_0_ge *pk, const rustsecp256k1zkp_v0_8_0_ge *second_pk) { - rustsecp256k1zkp_v0_8_0_sha256 sha; +static void rustsecp256k1zkp_v0_10_0_musig_keyaggcoef_internal(rustsecp256k1zkp_v0_10_0_scalar *r, const unsigned char *pk_hash, rustsecp256k1zkp_v0_10_0_ge *pk, const rustsecp256k1zkp_v0_10_0_ge *second_pk) { + rustsecp256k1zkp_v0_10_0_sha256 sha; + + VERIFY_CHECK(!rustsecp256k1zkp_v0_10_0_ge_is_infinity(pk)); - if (!rustsecp256k1zkp_v0_8_0_ge_is_infinity(second_pk) - && rustsecp256k1zkp_v0_8_0_fe_equal(&pk->x, &second_pk->x) - && rustsecp256k1zkp_v0_8_0_fe_is_odd(&pk->y) == rustsecp256k1zkp_v0_8_0_fe_is_odd(&second_pk->y)) { - rustsecp256k1zkp_v0_8_0_scalar_set_int(r, 1); + if (!rustsecp256k1zkp_v0_10_0_ge_is_infinity(second_pk) + && rustsecp256k1zkp_v0_10_0_fe_equal(&pk->x, &second_pk->x) + && rustsecp256k1zkp_v0_10_0_fe_is_odd(&pk->y) == rustsecp256k1zkp_v0_10_0_fe_is_odd(&second_pk->y)) { + rustsecp256k1zkp_v0_10_0_scalar_set_int(r, 1); } else { unsigned char buf[33]; size_t buflen = sizeof(buf); int ret; - rustsecp256k1zkp_v0_8_0_musig_keyaggcoef_sha256(&sha); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, pk_hash, 32); - ret = rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(pk, buf, &buflen, 1); + rustsecp256k1zkp_v0_10_0_musig_keyaggcoef_sha256(&sha); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, pk_hash, 32); + ret = rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(pk, buf, &buflen, 1); +#ifdef VERIFY /* Serialization does not fail since the pk is not the point at infinity * (according to this function's precondition). */ VERIFY_CHECK(ret && buflen == sizeof(buf)); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, buf, sizeof(buf)); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, buf); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(r, buf, NULL); +#else + (void) ret; +#endif + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, buf, sizeof(buf)); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, buf); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(r, buf, NULL); } } /* Assumes both field elements x and second_pk_x are normalized. */ -static void rustsecp256k1zkp_v0_8_0_musig_keyaggcoef(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_keyagg_cache_internal *cache_i, rustsecp256k1zkp_v0_8_0_ge *pk) { - rustsecp256k1zkp_v0_8_0_musig_keyaggcoef_internal(r, cache_i->pk_hash, pk, &cache_i->second_pk); +static void rustsecp256k1zkp_v0_10_0_musig_keyaggcoef(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_keyagg_cache_internal *cache_i, rustsecp256k1zkp_v0_10_0_ge *pk) { + rustsecp256k1zkp_v0_10_0_musig_keyaggcoef_internal(r, cache_i->pk_hash, pk, &cache_i->second_pk); } typedef struct { - const rustsecp256k1zkp_v0_8_0_context *ctx; + const rustsecp256k1zkp_v0_10_0_context *ctx; /* pk_hash is the hash of the public keys */ unsigned char pk_hash[32]; - const rustsecp256k1zkp_v0_8_0_pubkey * const* pks; - rustsecp256k1zkp_v0_8_0_ge second_pk; -} rustsecp256k1zkp_v0_8_0_musig_pubkey_agg_ecmult_data; + const rustsecp256k1zkp_v0_10_0_pubkey * const* pks; + rustsecp256k1zkp_v0_10_0_ge second_pk; +} rustsecp256k1zkp_v0_10_0_musig_pubkey_agg_ecmult_data; /* Callback for batch EC multiplication to compute keyaggcoef_0*P0 + keyaggcoef_1*P1 + ... */ -static int rustsecp256k1zkp_v0_8_0_musig_pubkey_agg_callback(rustsecp256k1zkp_v0_8_0_scalar *sc, rustsecp256k1zkp_v0_8_0_ge *pt, size_t idx, void *data) { - rustsecp256k1zkp_v0_8_0_musig_pubkey_agg_ecmult_data *ctx = (rustsecp256k1zkp_v0_8_0_musig_pubkey_agg_ecmult_data *) data; +static int rustsecp256k1zkp_v0_10_0_musig_pubkey_agg_callback(rustsecp256k1zkp_v0_10_0_scalar *sc, rustsecp256k1zkp_v0_10_0_ge *pt, size_t idx, void *data) { + rustsecp256k1zkp_v0_10_0_musig_pubkey_agg_ecmult_data *ctx = (rustsecp256k1zkp_v0_10_0_musig_pubkey_agg_ecmult_data *) data; int ret; - ret = rustsecp256k1zkp_v0_8_0_pubkey_load(ctx->ctx, pt, ctx->pks[idx]); + ret = rustsecp256k1zkp_v0_10_0_pubkey_load(ctx->ctx, pt, ctx->pks[idx]); +#ifdef VERIFY /* pubkey_load can't fail because the same pks have already been loaded in * `musig_compute_pk_hash` (and we test this). */ VERIFY_CHECK(ret); - rustsecp256k1zkp_v0_8_0_musig_keyaggcoef_internal(sc, ctx->pk_hash, pt, &ctx->second_pk); +#else + (void) ret; +#endif + rustsecp256k1zkp_v0_10_0_musig_keyaggcoef_internal(sc, ctx->pk_hash, pt, &ctx->second_pk); return 1; } -int rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_scratch_space *scratch, rustsecp256k1zkp_v0_8_0_xonly_pubkey *agg_pk, rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache, const rustsecp256k1zkp_v0_8_0_pubkey * const* pubkeys, size_t n_pubkeys) { - rustsecp256k1zkp_v0_8_0_musig_pubkey_agg_ecmult_data ecmult_data; - rustsecp256k1zkp_v0_8_0_gej pkj; - rustsecp256k1zkp_v0_8_0_ge pkp; +int rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_scratch_space *scratch, rustsecp256k1zkp_v0_10_0_xonly_pubkey *agg_pk, rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache, const rustsecp256k1zkp_v0_10_0_pubkey * const* pubkeys, size_t n_pubkeys) { + rustsecp256k1zkp_v0_10_0_musig_pubkey_agg_ecmult_data ecmult_data; + rustsecp256k1zkp_v0_10_0_gej pkj; + rustsecp256k1zkp_v0_10_0_ge pkp; size_t i; (void) scratch; @@ -228,11 +208,11 @@ int rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(const rustsecp256k1zkp_v0_8_0_conte ecmult_data.ctx = ctx; ecmult_data.pks = pubkeys; - rustsecp256k1zkp_v0_8_0_ge_set_infinity(&ecmult_data.second_pk); + rustsecp256k1zkp_v0_10_0_ge_set_infinity(&ecmult_data.second_pk); for (i = 1; i < n_pubkeys; i++) { - if (rustsecp256k1zkp_v0_8_0_memcmp_var(pubkeys[0], pubkeys[i], sizeof(*pubkeys[0])) != 0) { - rustsecp256k1zkp_v0_8_0_ge pk; - if (!rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &pk, pubkeys[i])) { + if (rustsecp256k1zkp_v0_10_0_memcmp_var(pubkeys[0], pubkeys[i], sizeof(*pubkeys[0])) != 0) { + rustsecp256k1zkp_v0_10_0_ge pk; + if (!rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, &pk, pubkeys[i])) { return 0; } ecmult_data.second_pk = pk; @@ -240,54 +220,54 @@ int rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(const rustsecp256k1zkp_v0_8_0_conte } } - if (!rustsecp256k1zkp_v0_8_0_musig_compute_pk_hash(ctx, ecmult_data.pk_hash, pubkeys, n_pubkeys)) { + if (!rustsecp256k1zkp_v0_10_0_musig_compute_pk_hash(ctx, ecmult_data.pk_hash, pubkeys, n_pubkeys)) { return 0; } /* TODO: actually use optimized ecmult_multi algorithms by providing a * scratch space */ - if (!rustsecp256k1zkp_v0_8_0_ecmult_multi_var(&ctx->error_callback, NULL, &pkj, NULL, rustsecp256k1zkp_v0_8_0_musig_pubkey_agg_callback, (void *) &ecmult_data, n_pubkeys)) { + if (!rustsecp256k1zkp_v0_10_0_ecmult_multi_var(&ctx->error_callback, NULL, &pkj, NULL, rustsecp256k1zkp_v0_10_0_musig_pubkey_agg_callback, (void *) &ecmult_data, n_pubkeys)) { /* In order to reach this line with the current implementation of * ecmult_multi_var one would need to provide a callback that can * fail. */ return 0; } - rustsecp256k1zkp_v0_8_0_ge_set_gej(&pkp, &pkj); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&pkp.y); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&pkp, &pkj); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&pkp.y); /* The resulting public key is infinity with negligible probability */ - VERIFY_CHECK(!rustsecp256k1zkp_v0_8_0_ge_is_infinity(&pkp)); + VERIFY_CHECK(!rustsecp256k1zkp_v0_10_0_ge_is_infinity(&pkp)); if (keyagg_cache != NULL) { - rustsecp256k1zkp_v0_8_0_keyagg_cache_internal cache_i = { 0 }; + rustsecp256k1zkp_v0_10_0_keyagg_cache_internal cache_i = { 0 }; cache_i.pk = pkp; cache_i.second_pk = ecmult_data.second_pk; memcpy(cache_i.pk_hash, ecmult_data.pk_hash, sizeof(cache_i.pk_hash)); - rustsecp256k1zkp_v0_8_0_keyagg_cache_save(keyagg_cache, &cache_i); + rustsecp256k1zkp_v0_10_0_keyagg_cache_save(keyagg_cache, &cache_i); } - rustsecp256k1zkp_v0_8_0_extrakeys_ge_even_y(&pkp); + rustsecp256k1zkp_v0_10_0_extrakeys_ge_even_y(&pkp); if (agg_pk != NULL) { - rustsecp256k1zkp_v0_8_0_xonly_pubkey_save(agg_pk, &pkp); + rustsecp256k1zkp_v0_10_0_xonly_pubkey_save(agg_pk, &pkp); } return 1; } -int rustsecp256k1zkp_v0_8_0_musig_pubkey_get(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pubkey *agg_pk, rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache) { - rustsecp256k1zkp_v0_8_0_keyagg_cache_internal cache_i; +int rustsecp256k1zkp_v0_10_0_musig_pubkey_get(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_pubkey *agg_pk, const rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache) { + rustsecp256k1zkp_v0_10_0_keyagg_cache_internal cache_i; VERIFY_CHECK(ctx != NULL); ARG_CHECK(agg_pk != NULL); memset(agg_pk, 0, sizeof(*agg_pk)); ARG_CHECK(keyagg_cache != NULL); - if(!rustsecp256k1zkp_v0_8_0_keyagg_cache_load(ctx, &cache_i, keyagg_cache)) { + if(!rustsecp256k1zkp_v0_10_0_keyagg_cache_load(ctx, &cache_i, keyagg_cache)) { return 0; } - rustsecp256k1zkp_v0_8_0_pubkey_save(agg_pk, &cache_i.pk); + rustsecp256k1zkp_v0_10_0_pubkey_save(agg_pk, &cache_i.pk); return 1; } -static int rustsecp256k1zkp_v0_8_0_musig_pubkey_tweak_add_internal(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pubkey *output_pubkey, rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache, const unsigned char *tweak32, int xonly) { - rustsecp256k1zkp_v0_8_0_keyagg_cache_internal cache_i; +static int rustsecp256k1zkp_v0_10_0_musig_pubkey_tweak_add_internal(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_pubkey *output_pubkey, rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache, const unsigned char *tweak32, int xonly) { + rustsecp256k1zkp_v0_10_0_keyagg_cache_internal cache_i; int overflow = 0; - rustsecp256k1zkp_v0_8_0_scalar tweak; + rustsecp256k1zkp_v0_10_0_scalar tweak; VERIFY_CHECK(ctx != NULL); if (output_pubkey != NULL) { @@ -296,36 +276,36 @@ static int rustsecp256k1zkp_v0_8_0_musig_pubkey_tweak_add_internal(const rustsec ARG_CHECK(keyagg_cache != NULL); ARG_CHECK(tweak32 != NULL); - if (!rustsecp256k1zkp_v0_8_0_keyagg_cache_load(ctx, &cache_i, keyagg_cache)) { + if (!rustsecp256k1zkp_v0_10_0_keyagg_cache_load(ctx, &cache_i, keyagg_cache)) { return 0; } - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&tweak, tweak32, &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&tweak, tweak32, &overflow); if (overflow) { return 0; } - if (xonly && rustsecp256k1zkp_v0_8_0_extrakeys_ge_even_y(&cache_i.pk)) { + if (xonly && rustsecp256k1zkp_v0_10_0_extrakeys_ge_even_y(&cache_i.pk)) { cache_i.parity_acc ^= 1; - rustsecp256k1zkp_v0_8_0_scalar_negate(&cache_i.tweak, &cache_i.tweak); + rustsecp256k1zkp_v0_10_0_scalar_negate(&cache_i.tweak, &cache_i.tweak); } - rustsecp256k1zkp_v0_8_0_scalar_add(&cache_i.tweak, &cache_i.tweak, &tweak); - if (!rustsecp256k1zkp_v0_8_0_eckey_pubkey_tweak_add(&cache_i.pk, &tweak)) { + rustsecp256k1zkp_v0_10_0_scalar_add(&cache_i.tweak, &cache_i.tweak, &tweak); + if (!rustsecp256k1zkp_v0_10_0_eckey_pubkey_tweak_add(&cache_i.pk, &tweak)) { return 0; } /* eckey_pubkey_tweak_add fails if cache_i.pk is infinity */ - VERIFY_CHECK(!rustsecp256k1zkp_v0_8_0_ge_is_infinity(&cache_i.pk)); - rustsecp256k1zkp_v0_8_0_keyagg_cache_save(keyagg_cache, &cache_i); + VERIFY_CHECK(!rustsecp256k1zkp_v0_10_0_ge_is_infinity(&cache_i.pk)); + rustsecp256k1zkp_v0_10_0_keyagg_cache_save(keyagg_cache, &cache_i); if (output_pubkey != NULL) { - rustsecp256k1zkp_v0_8_0_pubkey_save(output_pubkey, &cache_i.pk); + rustsecp256k1zkp_v0_10_0_pubkey_save(output_pubkey, &cache_i.pk); } return 1; } -int rustsecp256k1zkp_v0_8_0_musig_pubkey_ec_tweak_add(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pubkey *output_pubkey, rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache, const unsigned char *tweak32) { - return rustsecp256k1zkp_v0_8_0_musig_pubkey_tweak_add_internal(ctx, output_pubkey, keyagg_cache, tweak32, 0); +int rustsecp256k1zkp_v0_10_0_musig_pubkey_ec_tweak_add(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_pubkey *output_pubkey, rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache, const unsigned char *tweak32) { + return rustsecp256k1zkp_v0_10_0_musig_pubkey_tweak_add_internal(ctx, output_pubkey, keyagg_cache, tweak32, 0); } -int rustsecp256k1zkp_v0_8_0_musig_pubkey_xonly_tweak_add(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pubkey *output_pubkey, rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache, const unsigned char *tweak32) { - return rustsecp256k1zkp_v0_8_0_musig_pubkey_tweak_add_internal(ctx, output_pubkey, keyagg_cache, tweak32, 1); +int rustsecp256k1zkp_v0_10_0_musig_pubkey_xonly_tweak_add(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_pubkey *output_pubkey, rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache, const unsigned char *tweak32) { + return rustsecp256k1zkp_v0_10_0_musig_pubkey_tweak_add_internal(ctx, output_pubkey, keyagg_cache, tweak32, 1); } #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/main_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/main_impl.h index 53a62979..e69afed5 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/main_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/main_impl.h @@ -4,8 +4,8 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef SECP256K1_MODULE_MUSIG_MAIN -#define SECP256K1_MODULE_MUSIG_MAIN +#ifndef SECP256K1_MODULE_MUSIG_MAIN_H +#define SECP256K1_MODULE_MUSIG_MAIN_H #include "keyagg_impl.h" #include "session_impl.h" diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/musig.md b/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/musig.md index c44a7911..4f043b6e 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/musig.md +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/musig.md @@ -1,7 +1,7 @@ Notes on the musig module API =========================== -The following sections contain additional notes on the API of the musig module (`include/rustsecp256k1zkp_v0_8_0_musig.h`). +The following sections contain additional notes on the API of the musig module (`include/rustsecp256k1zkp_v0_10_0_musig.h`). A usage example can be found in `examples/musig.c`. # API misuse @@ -12,35 +12,35 @@ While the results can be catastrophic (e.g. leaking of the secret key), it is un Therefore, users of the musig module must take great care to make sure of the following: -1. A unique nonce per signing session is generated in `rustsecp256k1zkp_v0_8_0_musig_nonce_gen`. - See the corresponding comment in `include/rustsecp256k1zkp_v0_8_0_musig.h` for how to ensure that. -2. The `rustsecp256k1zkp_v0_8_0_musig_secnonce` structure is never copied or serialized. - See also the comment on `rustsecp256k1zkp_v0_8_0_musig_secnonce` in `include/rustsecp256k1zkp_v0_8_0_musig.h`. +1. A unique nonce per signing session is generated in `rustsecp256k1zkp_v0_10_0_musig_nonce_gen`. + See the corresponding comment in `include/rustsecp256k1zkp_v0_10_0_musig.h` for how to ensure that. +2. The `rustsecp256k1zkp_v0_10_0_musig_secnonce` structure is never copied or serialized. + See also the comment on `rustsecp256k1zkp_v0_10_0_musig_secnonce` in `include/rustsecp256k1zkp_v0_10_0_musig.h`. 3. Opaque data structures are never written to or read from directly. Instead, only the provided accessor functions are used. 4. If adaptor signatures are used, all partial signatures are verified. # Key Aggregation and (Taproot) Tweaking -Given a set of public keys, the aggregate public key is computed with `rustsecp256k1zkp_v0_8_0_musig_pubkey_agg`. -A (Taproot) tweak can be added to the resulting public key with `rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add` and a plain tweak can be added with `rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add`. +Given a set of public keys, the aggregate public key is computed with `rustsecp256k1zkp_v0_10_0_musig_pubkey_agg`. +A (Taproot) tweak can be added to the resulting public key with `rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add` and a plain tweak can be added with `rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add`. # Signing This is covered by `examples/musig.c`. Essentially, the protocol proceeds in the following steps: -1. Generate a keypair with `rustsecp256k1zkp_v0_8_0_keypair_create` and obtain the public key with `rustsecp256k1zkp_v0_8_0_keypair_pub`. -2. Call `rustsecp256k1zkp_v0_8_0_musig_pubkey_agg` with the pubkeys of all participants. -3. Optionally add a (Taproot) tweak with `rustsecp256k1zkp_v0_8_0_musig_pubkey_xonly_tweak_add` and a plain tweak with `rustsecp256k1zkp_v0_8_0_musig_pubkey_ec_tweak_add`. -4. Generate a pair of secret and public nonce with `rustsecp256k1zkp_v0_8_0_musig_nonce_gen` and send the public nonce to the other signers. -5. Someone (not necessarily the signer) aggregates the public nonce with `rustsecp256k1zkp_v0_8_0_musig_nonce_agg` and sends it to the signers. -6. Process the aggregate nonce with `rustsecp256k1zkp_v0_8_0_musig_nonce_process`. -7. Create a partial signature with `rustsecp256k1zkp_v0_8_0_musig_partial_sign`. -8. Verify the partial signatures (optional in some scenarios) with `rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify`. -9. Someone (not necessarily the signer) obtains all partial signatures and aggregates them into the final Schnorr signature using `rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg`. +1. Generate a keypair with `rustsecp256k1zkp_v0_10_0_keypair_create` and obtain the public key with `rustsecp256k1zkp_v0_10_0_keypair_pub`. +2. Call `rustsecp256k1zkp_v0_10_0_musig_pubkey_agg` with the pubkeys of all participants. +3. Optionally add a (Taproot) tweak with `rustsecp256k1zkp_v0_10_0_musig_pubkey_xonly_tweak_add` and a plain tweak with `rustsecp256k1zkp_v0_10_0_musig_pubkey_ec_tweak_add`. +4. Generate a pair of secret and public nonce with `rustsecp256k1zkp_v0_10_0_musig_nonce_gen` and send the public nonce to the other signers. +5. Someone (not necessarily the signer) aggregates the public nonce with `rustsecp256k1zkp_v0_10_0_musig_nonce_agg` and sends it to the signers. +6. Process the aggregate nonce with `rustsecp256k1zkp_v0_10_0_musig_nonce_process`. +7. Create a partial signature with `rustsecp256k1zkp_v0_10_0_musig_partial_sign`. +8. Verify the partial signatures (optional in some scenarios) with `rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify`. +9. Someone (not necessarily the signer) obtains all partial signatures and aggregates them into the final Schnorr signature using `rustsecp256k1zkp_v0_10_0_musig_partial_sig_agg`. -The aggregate signature can be verified with `rustsecp256k1zkp_v0_8_0_schnorrsig_verify`. +The aggregate signature can be verified with `rustsecp256k1zkp_v0_10_0_schnorrsig_verify`. Note that steps 1 to 5 can happen before the message to be signed is known to the signers. Therefore, the communication round to exchange nonces can be viewed as a pre-processing step that is run whenever convenient to the signers. @@ -56,8 +56,8 @@ A participant who wants to verify the partial signatures, but does not sign itse The signing API supports the production of "adaptor signatures", modified partial signatures which are offset by an auxiliary secret known to one party. That is, 1. One party generates a (secret) adaptor `t` with corresponding (public) adaptor `T = t*G`. -2. When calling `rustsecp256k1zkp_v0_8_0_musig_nonce_process`, the public adaptor `T` is provided as the `adaptor` argument. +2. When calling `rustsecp256k1zkp_v0_10_0_musig_nonce_process`, the public adaptor `T` is provided as the `adaptor` argument. 3. The party who is going to extract the secret adaptor `t` later must verify all partial signatures. -4. Due to step 2, the signature output of `rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg` is a pre-signature and not a valid Schnorr signature. All parties involved extract this session's `nonce_parity` with `rustsecp256k1zkp_v0_8_0_musig_nonce_parity`. -5. The party who knows `t` must "adapt" the pre-signature with `t` (and the `nonce_parity` using `rustsecp256k1zkp_v0_8_0_musig_adapt` to complete the signature. -6. Any party who sees both the final signature and the pre-signature (and has the `nonce_parity`) can extract `t` with `rustsecp256k1zkp_v0_8_0_musig_extract_adaptor`. +4. Due to step 2, the signature output of `rustsecp256k1zkp_v0_10_0_musig_partial_sig_agg` is a pre-signature and not a valid Schnorr signature. All parties involved extract this session's `nonce_parity` with `rustsecp256k1zkp_v0_10_0_musig_nonce_parity`. +5. The party who knows `t` must "adapt" the pre-signature with `t` (and the `nonce_parity` using `rustsecp256k1zkp_v0_10_0_musig_adapt` to complete the signature. +6. Any party who sees both the final signature and the pre-signature (and has the `nonce_parity`) can extract `t` with `rustsecp256k1zkp_v0_10_0_musig_extract_adaptor`. diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/session.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/session.h index 78bd4f20..2efa0c20 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/session.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/session.h @@ -15,11 +15,11 @@ typedef struct { int fin_nonce_parity; unsigned char fin_nonce[32]; - rustsecp256k1zkp_v0_8_0_scalar noncecoef; - rustsecp256k1zkp_v0_8_0_scalar challenge; - rustsecp256k1zkp_v0_8_0_scalar s_part; -} rustsecp256k1zkp_v0_8_0_musig_session_internal; + rustsecp256k1zkp_v0_10_0_scalar noncecoef; + rustsecp256k1zkp_v0_10_0_scalar challenge; + rustsecp256k1zkp_v0_10_0_scalar s_part; +} rustsecp256k1zkp_v0_10_0_musig_session_internal; -static int rustsecp256k1zkp_v0_8_0_musig_session_load(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_musig_session_internal *session_i, const rustsecp256k1zkp_v0_8_0_musig_session *session); +static int rustsecp256k1zkp_v0_10_0_musig_session_load(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_musig_session_internal *session_i, const rustsecp256k1zkp_v0_10_0_musig_session *session); #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/session_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/session_impl.h index b8b79ac4..489c1ea4 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/session_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/session_impl.h @@ -20,85 +20,85 @@ #include "../../scalar.h" #include "../../util.h" -static const unsigned char rustsecp256k1zkp_v0_8_0_musig_secnonce_magic[4] = { 0x22, 0x0e, 0xdc, 0xf1 }; +static const unsigned char rustsecp256k1zkp_v0_10_0_musig_secnonce_magic[4] = { 0x22, 0x0e, 0xdc, 0xf1 }; -static void rustsecp256k1zkp_v0_8_0_musig_secnonce_save(rustsecp256k1zkp_v0_8_0_musig_secnonce *secnonce, const rustsecp256k1zkp_v0_8_0_scalar *k, rustsecp256k1zkp_v0_8_0_ge *pk) { - memcpy(&secnonce->data[0], rustsecp256k1zkp_v0_8_0_musig_secnonce_magic, 4); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&secnonce->data[4], &k[0]); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&secnonce->data[36], &k[1]); - rustsecp256k1zkp_v0_8_0_point_save(&secnonce->data[68], pk); +static void rustsecp256k1zkp_v0_10_0_musig_secnonce_save(rustsecp256k1zkp_v0_10_0_musig_secnonce *secnonce, const rustsecp256k1zkp_v0_10_0_scalar *k, rustsecp256k1zkp_v0_10_0_ge *pk) { + memcpy(&secnonce->data[0], rustsecp256k1zkp_v0_10_0_musig_secnonce_magic, 4); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&secnonce->data[4], &k[0]); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&secnonce->data[36], &k[1]); + rustsecp256k1zkp_v0_10_0_ge_to_bytes(&secnonce->data[68], pk); } -static int rustsecp256k1zkp_v0_8_0_musig_secnonce_load(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_scalar *k, rustsecp256k1zkp_v0_8_0_ge *pk, rustsecp256k1zkp_v0_8_0_musig_secnonce *secnonce) { +static int rustsecp256k1zkp_v0_10_0_musig_secnonce_load(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_scalar *k, rustsecp256k1zkp_v0_10_0_ge *pk, rustsecp256k1zkp_v0_10_0_musig_secnonce *secnonce) { int is_zero; - ARG_CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&secnonce->data[0], rustsecp256k1zkp_v0_8_0_musig_secnonce_magic, 4) == 0); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&k[0], &secnonce->data[4], NULL); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&k[1], &secnonce->data[36], NULL); - rustsecp256k1zkp_v0_8_0_point_load(pk, &secnonce->data[68]); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&secnonce->data[0], rustsecp256k1zkp_v0_10_0_musig_secnonce_magic, 4) == 0); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&k[0], &secnonce->data[4], NULL); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&k[1], &secnonce->data[36], NULL); + rustsecp256k1zkp_v0_10_0_ge_from_bytes(pk, &secnonce->data[68]); /* We make very sure that the nonce isn't invalidated by checking the values * in addition to the magic. */ - is_zero = rustsecp256k1zkp_v0_8_0_scalar_is_zero(&k[0]) & rustsecp256k1zkp_v0_8_0_scalar_is_zero(&k[1]); - rustsecp256k1zkp_v0_8_0_declassify(ctx, &is_zero, sizeof(is_zero)); + is_zero = rustsecp256k1zkp_v0_10_0_scalar_is_zero(&k[0]) & rustsecp256k1zkp_v0_10_0_scalar_is_zero(&k[1]); + rustsecp256k1zkp_v0_10_0_declassify(ctx, &is_zero, sizeof(is_zero)); ARG_CHECK(!is_zero); return 1; } /* If flag is true, invalidate the secnonce; otherwise leave it. Constant-time. */ -static void rustsecp256k1zkp_v0_8_0_musig_secnonce_invalidate(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_musig_secnonce *secnonce, int flag) { - rustsecp256k1zkp_v0_8_0_memczero(secnonce->data, sizeof(secnonce->data), flag); +static void rustsecp256k1zkp_v0_10_0_musig_secnonce_invalidate(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_musig_secnonce *secnonce, int flag) { + rustsecp256k1zkp_v0_10_0_memczero(secnonce->data, sizeof(secnonce->data), flag); /* The flag argument is usually classified. So, the line above makes the * magic and public key classified. However, we need both to be * declassified. Note that we don't declassify the entire object, because if * flag is 0, then k[0] and k[1] have not been zeroed. */ - rustsecp256k1zkp_v0_8_0_declassify(ctx, secnonce->data, sizeof(rustsecp256k1zkp_v0_8_0_musig_secnonce_magic)); - rustsecp256k1zkp_v0_8_0_declassify(ctx, &secnonce->data[68], 64); + rustsecp256k1zkp_v0_10_0_declassify(ctx, secnonce->data, sizeof(rustsecp256k1zkp_v0_10_0_musig_secnonce_magic)); + rustsecp256k1zkp_v0_10_0_declassify(ctx, &secnonce->data[68], 64); } -static const unsigned char rustsecp256k1zkp_v0_8_0_musig_pubnonce_magic[4] = { 0xf5, 0x7a, 0x3d, 0xa0 }; +static const unsigned char rustsecp256k1zkp_v0_10_0_musig_pubnonce_magic[4] = { 0xf5, 0x7a, 0x3d, 0xa0 }; /* Saves two group elements into a pubnonce. Requires that none of the provided * group elements is infinity. */ -static void rustsecp256k1zkp_v0_8_0_musig_pubnonce_save(rustsecp256k1zkp_v0_8_0_musig_pubnonce* nonce, rustsecp256k1zkp_v0_8_0_ge* ge) { +static void rustsecp256k1zkp_v0_10_0_musig_pubnonce_save(rustsecp256k1zkp_v0_10_0_musig_pubnonce* nonce, rustsecp256k1zkp_v0_10_0_ge* ge) { int i; - memcpy(&nonce->data[0], rustsecp256k1zkp_v0_8_0_musig_pubnonce_magic, 4); + memcpy(&nonce->data[0], rustsecp256k1zkp_v0_10_0_musig_pubnonce_magic, 4); for (i = 0; i < 2; i++) { - rustsecp256k1zkp_v0_8_0_point_save(nonce->data + 4+64*i, &ge[i]); + rustsecp256k1zkp_v0_10_0_ge_to_bytes(nonce->data + 4+64*i, &ge[i]); } } /* Loads two group elements from a pubnonce. Returns 1 unless the nonce wasn't * properly initialized */ -static int rustsecp256k1zkp_v0_8_0_musig_pubnonce_load(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ge* ge, const rustsecp256k1zkp_v0_8_0_musig_pubnonce* nonce) { +static int rustsecp256k1zkp_v0_10_0_musig_pubnonce_load(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_ge* ge, const rustsecp256k1zkp_v0_10_0_musig_pubnonce* nonce) { int i; - ARG_CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&nonce->data[0], rustsecp256k1zkp_v0_8_0_musig_pubnonce_magic, 4) == 0); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&nonce->data[0], rustsecp256k1zkp_v0_10_0_musig_pubnonce_magic, 4) == 0); for (i = 0; i < 2; i++) { - rustsecp256k1zkp_v0_8_0_point_load(&ge[i], nonce->data + 4 + 64*i); + rustsecp256k1zkp_v0_10_0_ge_from_bytes(&ge[i], nonce->data + 4 + 64*i); } return 1; } -static const unsigned char rustsecp256k1zkp_v0_8_0_musig_aggnonce_magic[4] = { 0xa8, 0xb7, 0xe4, 0x67 }; +static const unsigned char rustsecp256k1zkp_v0_10_0_musig_aggnonce_magic[4] = { 0xa8, 0xb7, 0xe4, 0x67 }; -static void rustsecp256k1zkp_v0_8_0_musig_aggnonce_save(rustsecp256k1zkp_v0_8_0_musig_aggnonce* nonce, rustsecp256k1zkp_v0_8_0_ge* ge) { +static void rustsecp256k1zkp_v0_10_0_musig_aggnonce_save(rustsecp256k1zkp_v0_10_0_musig_aggnonce* nonce, rustsecp256k1zkp_v0_10_0_ge* ge) { int i; - memcpy(&nonce->data[0], rustsecp256k1zkp_v0_8_0_musig_aggnonce_magic, 4); + memcpy(&nonce->data[0], rustsecp256k1zkp_v0_10_0_musig_aggnonce_magic, 4); for (i = 0; i < 2; i++) { - rustsecp256k1zkp_v0_8_0_point_save_ext(&nonce->data[4 + 64*i], &ge[i]); + rustsecp256k1zkp_v0_10_0_point_save_ext(&nonce->data[4 + 64*i], &ge[i]); } } -static int rustsecp256k1zkp_v0_8_0_musig_aggnonce_load(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ge* ge, const rustsecp256k1zkp_v0_8_0_musig_aggnonce* nonce) { +static int rustsecp256k1zkp_v0_10_0_musig_aggnonce_load(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_ge* ge, const rustsecp256k1zkp_v0_10_0_musig_aggnonce* nonce) { int i; - ARG_CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&nonce->data[0], rustsecp256k1zkp_v0_8_0_musig_aggnonce_magic, 4) == 0); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&nonce->data[0], rustsecp256k1zkp_v0_10_0_musig_aggnonce_magic, 4) == 0); for (i = 0; i < 2; i++) { - rustsecp256k1zkp_v0_8_0_point_load_ext(&ge[i], &nonce->data[4 + 64*i]); + rustsecp256k1zkp_v0_10_0_point_load_ext(&ge[i], &nonce->data[4 + 64*i]); } return 1; } -static const unsigned char rustsecp256k1zkp_v0_8_0_musig_session_cache_magic[4] = { 0x9d, 0xed, 0xe9, 0x17 }; +static const unsigned char rustsecp256k1zkp_v0_10_0_musig_session_cache_magic[4] = { 0x9d, 0xed, 0xe9, 0x17 }; /* A session consists of * - 4 byte session cache magic @@ -108,58 +108,58 @@ static const unsigned char rustsecp256k1zkp_v0_8_0_musig_session_cache_magic[4] * - 32 byte signature challenge hash e * - 32 byte scalar s that is added to the partial signatures of the signers */ -static void rustsecp256k1zkp_v0_8_0_musig_session_save(rustsecp256k1zkp_v0_8_0_musig_session *session, const rustsecp256k1zkp_v0_8_0_musig_session_internal *session_i) { +static void rustsecp256k1zkp_v0_10_0_musig_session_save(rustsecp256k1zkp_v0_10_0_musig_session *session, const rustsecp256k1zkp_v0_10_0_musig_session_internal *session_i) { unsigned char *ptr = session->data; - memcpy(ptr, rustsecp256k1zkp_v0_8_0_musig_session_cache_magic, 4); + memcpy(ptr, rustsecp256k1zkp_v0_10_0_musig_session_cache_magic, 4); ptr += 4; *ptr = session_i->fin_nonce_parity; ptr += 1; memcpy(ptr, session_i->fin_nonce, 32); ptr += 32; - rustsecp256k1zkp_v0_8_0_scalar_get_b32(ptr, &session_i->noncecoef); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(ptr, &session_i->noncecoef); ptr += 32; - rustsecp256k1zkp_v0_8_0_scalar_get_b32(ptr, &session_i->challenge); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(ptr, &session_i->challenge); ptr += 32; - rustsecp256k1zkp_v0_8_0_scalar_get_b32(ptr, &session_i->s_part); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(ptr, &session_i->s_part); } -static int rustsecp256k1zkp_v0_8_0_musig_session_load(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_musig_session_internal *session_i, const rustsecp256k1zkp_v0_8_0_musig_session *session) { +static int rustsecp256k1zkp_v0_10_0_musig_session_load(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_musig_session_internal *session_i, const rustsecp256k1zkp_v0_10_0_musig_session *session) { const unsigned char *ptr = session->data; - ARG_CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(ptr, rustsecp256k1zkp_v0_8_0_musig_session_cache_magic, 4) == 0); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(ptr, rustsecp256k1zkp_v0_10_0_musig_session_cache_magic, 4) == 0); ptr += 4; session_i->fin_nonce_parity = *ptr; ptr += 1; memcpy(session_i->fin_nonce, ptr, 32); ptr += 32; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&session_i->noncecoef, ptr, NULL); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&session_i->noncecoef, ptr, NULL); ptr += 32; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&session_i->challenge, ptr, NULL); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&session_i->challenge, ptr, NULL); ptr += 32; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&session_i->s_part, ptr, NULL); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&session_i->s_part, ptr, NULL); return 1; } -static const unsigned char rustsecp256k1zkp_v0_8_0_musig_partial_sig_magic[4] = { 0xeb, 0xfb, 0x1a, 0x32 }; +static const unsigned char rustsecp256k1zkp_v0_10_0_musig_partial_sig_magic[4] = { 0xeb, 0xfb, 0x1a, 0x32 }; -static void rustsecp256k1zkp_v0_8_0_musig_partial_sig_save(rustsecp256k1zkp_v0_8_0_musig_partial_sig* sig, rustsecp256k1zkp_v0_8_0_scalar *s) { - memcpy(&sig->data[0], rustsecp256k1zkp_v0_8_0_musig_partial_sig_magic, 4); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&sig->data[4], s); +static void rustsecp256k1zkp_v0_10_0_musig_partial_sig_save(rustsecp256k1zkp_v0_10_0_musig_partial_sig* sig, rustsecp256k1zkp_v0_10_0_scalar *s) { + memcpy(&sig->data[0], rustsecp256k1zkp_v0_10_0_musig_partial_sig_magic, 4); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&sig->data[4], s); } -static int rustsecp256k1zkp_v0_8_0_musig_partial_sig_load(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_scalar *s, const rustsecp256k1zkp_v0_8_0_musig_partial_sig* sig) { +static int rustsecp256k1zkp_v0_10_0_musig_partial_sig_load(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_scalar *s, const rustsecp256k1zkp_v0_10_0_musig_partial_sig* sig) { int overflow; - ARG_CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&sig->data[0], rustsecp256k1zkp_v0_8_0_musig_partial_sig_magic, 4) == 0); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(s, &sig->data[4], &overflow); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&sig->data[0], rustsecp256k1zkp_v0_10_0_musig_partial_sig_magic, 4) == 0); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(s, &sig->data[4], &overflow); /* Parsed signatures can not overflow */ VERIFY_CHECK(!overflow); return 1; } -int rustsecp256k1zkp_v0_8_0_musig_pubnonce_serialize(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *out66, const rustsecp256k1zkp_v0_8_0_musig_pubnonce* nonce) { - rustsecp256k1zkp_v0_8_0_ge ge[2]; +int rustsecp256k1zkp_v0_10_0_musig_pubnonce_serialize(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *out66, const rustsecp256k1zkp_v0_10_0_musig_pubnonce* nonce) { + rustsecp256k1zkp_v0_10_0_ge ge[2]; int i; VERIFY_CHECK(ctx != NULL); @@ -167,21 +167,25 @@ int rustsecp256k1zkp_v0_8_0_musig_pubnonce_serialize(const rustsecp256k1zkp_v0_8 memset(out66, 0, 66); ARG_CHECK(nonce != NULL); - if (!rustsecp256k1zkp_v0_8_0_musig_pubnonce_load(ctx, ge, nonce)) { + if (!rustsecp256k1zkp_v0_10_0_musig_pubnonce_load(ctx, ge, nonce)) { return 0; } for (i = 0; i < 2; i++) { int ret; size_t size = 33; - ret = rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&ge[i], &out66[33*i], &size, 1); + ret = rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&ge[i], &out66[33*i], &size, 1); +#ifdef VERIFY /* serialize must succeed because the point was just loaded */ VERIFY_CHECK(ret && size == 33); +#else + (void) ret; +#endif } return 1; } -int rustsecp256k1zkp_v0_8_0_musig_pubnonce_parse(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_musig_pubnonce* nonce, const unsigned char *in66) { - rustsecp256k1zkp_v0_8_0_ge ge[2]; +int rustsecp256k1zkp_v0_10_0_musig_pubnonce_parse(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_musig_pubnonce* nonce, const unsigned char *in66) { + rustsecp256k1zkp_v0_10_0_ge ge[2]; int i; VERIFY_CHECK(ctx != NULL); @@ -189,45 +193,19 @@ int rustsecp256k1zkp_v0_8_0_musig_pubnonce_parse(const rustsecp256k1zkp_v0_8_0_c ARG_CHECK(in66 != NULL); for (i = 0; i < 2; i++) { - if (!rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(&ge[i], &in66[33*i], 33)) { + if (!rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(&ge[i], &in66[33*i], 33)) { return 0; } - if (!rustsecp256k1zkp_v0_8_0_ge_is_in_correct_subgroup(&ge[i])) { + if (!rustsecp256k1zkp_v0_10_0_ge_is_in_correct_subgroup(&ge[i])) { return 0; } } - rustsecp256k1zkp_v0_8_0_musig_pubnonce_save(nonce, ge); + rustsecp256k1zkp_v0_10_0_musig_pubnonce_save(nonce, ge); return 1; } -/* Outputs 33 zero bytes if the given group element is the point at infinity and - * otherwise outputs the compressed serialization */ -static void rustsecp256k1zkp_v0_8_0_ge_serialize_ext(unsigned char *out33, rustsecp256k1zkp_v0_8_0_ge* ge) { - if (rustsecp256k1zkp_v0_8_0_ge_is_infinity(ge)) { - memset(out33, 0, 33); - } else { - int ret; - size_t size = 33; - ret = rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(ge, out33, &size, 1); - /* Serialize must succeed because the point is not at infinity */ - VERIFY_CHECK(ret && size == 33); - } -} - -/* Outputs the point at infinity if the given byte array is all zero, otherwise - * attempts to parse compressed point serialization. */ -static int rustsecp256k1zkp_v0_8_0_ge_parse_ext(rustsecp256k1zkp_v0_8_0_ge* ge, const unsigned char *in33) { - unsigned char zeros[33] = { 0 }; - - if (memcmp(in33, zeros, sizeof(zeros)) == 0) { - rustsecp256k1zkp_v0_8_0_ge_set_infinity(ge); - return 1; - } - return rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(ge, in33, 33); -} - -int rustsecp256k1zkp_v0_8_0_musig_aggnonce_serialize(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *out66, const rustsecp256k1zkp_v0_8_0_musig_aggnonce* nonce) { - rustsecp256k1zkp_v0_8_0_ge ge[2]; +int rustsecp256k1zkp_v0_10_0_musig_aggnonce_serialize(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *out66, const rustsecp256k1zkp_v0_10_0_musig_aggnonce* nonce) { + rustsecp256k1zkp_v0_10_0_ge ge[2]; int i; VERIFY_CHECK(ctx != NULL); @@ -235,17 +213,17 @@ int rustsecp256k1zkp_v0_8_0_musig_aggnonce_serialize(const rustsecp256k1zkp_v0_8 memset(out66, 0, 66); ARG_CHECK(nonce != NULL); - if (!rustsecp256k1zkp_v0_8_0_musig_aggnonce_load(ctx, ge, nonce)) { + if (!rustsecp256k1zkp_v0_10_0_musig_aggnonce_load(ctx, ge, nonce)) { return 0; } for (i = 0; i < 2; i++) { - rustsecp256k1zkp_v0_8_0_ge_serialize_ext(&out66[33*i], &ge[i]); + rustsecp256k1zkp_v0_10_0_ge_serialize_ext(&out66[33*i], &ge[i]); } return 1; } -int rustsecp256k1zkp_v0_8_0_musig_aggnonce_parse(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_musig_aggnonce* nonce, const unsigned char *in66) { - rustsecp256k1zkp_v0_8_0_ge ge[2]; +int rustsecp256k1zkp_v0_10_0_musig_aggnonce_parse(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_musig_aggnonce* nonce, const unsigned char *in66) { + rustsecp256k1zkp_v0_10_0_ge ge[2]; int i; VERIFY_CHECK(ctx != NULL); @@ -253,15 +231,15 @@ int rustsecp256k1zkp_v0_8_0_musig_aggnonce_parse(const rustsecp256k1zkp_v0_8_0_c ARG_CHECK(in66 != NULL); for (i = 0; i < 2; i++) { - if (!rustsecp256k1zkp_v0_8_0_ge_parse_ext(&ge[i], &in66[33*i])) { + if (!rustsecp256k1zkp_v0_10_0_ge_parse_ext(&ge[i], &in66[33*i])) { return 0; } } - rustsecp256k1zkp_v0_8_0_musig_aggnonce_save(nonce, ge); + rustsecp256k1zkp_v0_10_0_musig_aggnonce_save(nonce, ge); return 1; } -int rustsecp256k1zkp_v0_8_0_musig_partial_sig_serialize(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *out32, const rustsecp256k1zkp_v0_8_0_musig_partial_sig* sig) { +int rustsecp256k1zkp_v0_10_0_musig_partial_sig_serialize(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *out32, const rustsecp256k1zkp_v0_10_0_musig_partial_sig* sig) { VERIFY_CHECK(ctx != NULL); ARG_CHECK(out32 != NULL); ARG_CHECK(sig != NULL); @@ -269,59 +247,49 @@ int rustsecp256k1zkp_v0_8_0_musig_partial_sig_serialize(const rustsecp256k1zkp_v return 1; } -int rustsecp256k1zkp_v0_8_0_musig_partial_sig_parse(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_musig_partial_sig* sig, const unsigned char *in32) { - rustsecp256k1zkp_v0_8_0_scalar tmp; +int rustsecp256k1zkp_v0_10_0_musig_partial_sig_parse(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_musig_partial_sig* sig, const unsigned char *in32) { + rustsecp256k1zkp_v0_10_0_scalar tmp; int overflow; VERIFY_CHECK(ctx != NULL); ARG_CHECK(sig != NULL); ARG_CHECK(in32 != NULL); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&tmp, in32, &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&tmp, in32, &overflow); if (overflow) { return 0; } - rustsecp256k1zkp_v0_8_0_musig_partial_sig_save(sig, &tmp); - return 1; -} - -/* Normalizes the x-coordinate of the given group element. */ -static int rustsecp256k1zkp_v0_8_0_xonly_ge_serialize(unsigned char *output32, rustsecp256k1zkp_v0_8_0_ge *ge) { - if (rustsecp256k1zkp_v0_8_0_ge_is_infinity(ge)) { - return 0; - } - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&ge->x); - rustsecp256k1zkp_v0_8_0_fe_get_b32(output32, &ge->x); + rustsecp256k1zkp_v0_10_0_musig_partial_sig_save(sig, &tmp); return 1; } /* Write optional inputs into the hash */ -static void rustsecp256k1zkp_v0_8_0_nonce_function_musig_helper(rustsecp256k1zkp_v0_8_0_sha256 *sha, unsigned int prefix_size, const unsigned char *data, unsigned char len) { +static void rustsecp256k1zkp_v0_10_0_nonce_function_musig_helper(rustsecp256k1zkp_v0_10_0_sha256 *sha, unsigned int prefix_size, const unsigned char *data, unsigned char len) { unsigned char zero[7] = { 0 }; /* The spec requires length prefixes to be between 1 and 8 bytes * (inclusive) */ VERIFY_CHECK(prefix_size <= 8); /* Since the length of all input data fits in a byte, we can always pad the * length prefix with prefix_size - 1 zero bytes. */ - rustsecp256k1zkp_v0_8_0_sha256_write(sha, zero, prefix_size - 1); + rustsecp256k1zkp_v0_10_0_sha256_write(sha, zero, prefix_size - 1); if (data != NULL) { - rustsecp256k1zkp_v0_8_0_sha256_write(sha, &len, 1); - rustsecp256k1zkp_v0_8_0_sha256_write(sha, data, len); + rustsecp256k1zkp_v0_10_0_sha256_write(sha, &len, 1); + rustsecp256k1zkp_v0_10_0_sha256_write(sha, data, len); } else { len = 0; - rustsecp256k1zkp_v0_8_0_sha256_write(sha, &len, 1); + rustsecp256k1zkp_v0_10_0_sha256_write(sha, &len, 1); } } -static void rustsecp256k1zkp_v0_8_0_nonce_function_musig(rustsecp256k1zkp_v0_8_0_scalar *k, const unsigned char *session_id, const unsigned char *msg32, const unsigned char *seckey32, const unsigned char *pk33, const unsigned char *agg_pk32, const unsigned char *extra_input32) { - rustsecp256k1zkp_v0_8_0_sha256 sha; +static void rustsecp256k1zkp_v0_10_0_nonce_function_musig(rustsecp256k1zkp_v0_10_0_scalar *k, const unsigned char *session_id, const unsigned char *msg32, const unsigned char *seckey32, const unsigned char *pk33, const unsigned char *agg_pk32, const unsigned char *extra_input32) { + rustsecp256k1zkp_v0_10_0_sha256 sha; unsigned char rand[32]; unsigned char i; unsigned char msg_present; if (seckey32 != NULL) { - rustsecp256k1zkp_v0_8_0_sha256_initialize_tagged(&sha, (unsigned char*)"MuSig/aux", sizeof("MuSig/aux") - 1); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, session_id, 32); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, rand); + rustsecp256k1zkp_v0_10_0_sha256_initialize_tagged(&sha, (unsigned char*)"MuSig/aux", sizeof("MuSig/aux") - 1); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, session_id, 32); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, rand); for (i = 0; i < 32; i++) { rand[i] ^= seckey32[i]; } @@ -330,36 +298,36 @@ static void rustsecp256k1zkp_v0_8_0_nonce_function_musig(rustsecp256k1zkp_v0_8_0 } /* Subtract one from `sizeof` to avoid hashing the implicit null byte */ - rustsecp256k1zkp_v0_8_0_sha256_initialize_tagged(&sha, (unsigned char*)"MuSig/nonce", sizeof("MuSig/nonce") - 1); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, rand, sizeof(rand)); - rustsecp256k1zkp_v0_8_0_nonce_function_musig_helper(&sha, 1, pk33, 33); - rustsecp256k1zkp_v0_8_0_nonce_function_musig_helper(&sha, 1, agg_pk32, 32); + rustsecp256k1zkp_v0_10_0_sha256_initialize_tagged(&sha, (unsigned char*)"MuSig/nonce", sizeof("MuSig/nonce") - 1); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, rand, sizeof(rand)); + rustsecp256k1zkp_v0_10_0_nonce_function_musig_helper(&sha, 1, pk33, 33); + rustsecp256k1zkp_v0_10_0_nonce_function_musig_helper(&sha, 1, agg_pk32, 32); msg_present = msg32 != NULL; - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, &msg_present, 1); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, &msg_present, 1); if (msg_present) { - rustsecp256k1zkp_v0_8_0_nonce_function_musig_helper(&sha, 8, msg32, 32); + rustsecp256k1zkp_v0_10_0_nonce_function_musig_helper(&sha, 8, msg32, 32); } - rustsecp256k1zkp_v0_8_0_nonce_function_musig_helper(&sha, 4, extra_input32, 32); + rustsecp256k1zkp_v0_10_0_nonce_function_musig_helper(&sha, 4, extra_input32, 32); for (i = 0; i < 2; i++) { unsigned char buf[32]; - rustsecp256k1zkp_v0_8_0_sha256 sha_tmp = sha; - rustsecp256k1zkp_v0_8_0_sha256_write(&sha_tmp, &i, 1); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha_tmp, buf); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&k[i], buf, NULL); + rustsecp256k1zkp_v0_10_0_sha256 sha_tmp = sha; + rustsecp256k1zkp_v0_10_0_sha256_write(&sha_tmp, &i, 1); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha_tmp, buf); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&k[i], buf, NULL); } } -int rustsecp256k1zkp_v0_8_0_musig_nonce_gen(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_musig_secnonce *secnonce, rustsecp256k1zkp_v0_8_0_musig_pubnonce *pubnonce, const unsigned char *session_id32, const unsigned char *seckey, const rustsecp256k1zkp_v0_8_0_pubkey *pubkey, const unsigned char *msg32, const rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache, const unsigned char *extra_input32) { - rustsecp256k1zkp_v0_8_0_keyagg_cache_internal cache_i; - rustsecp256k1zkp_v0_8_0_scalar k[2]; - rustsecp256k1zkp_v0_8_0_ge nonce_pt[2]; +int rustsecp256k1zkp_v0_10_0_musig_nonce_gen(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_musig_secnonce *secnonce, rustsecp256k1zkp_v0_10_0_musig_pubnonce *pubnonce, const unsigned char *session_id32, const unsigned char *seckey, const rustsecp256k1zkp_v0_10_0_pubkey *pubkey, const unsigned char *msg32, const rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache, const unsigned char *extra_input32) { + rustsecp256k1zkp_v0_10_0_keyagg_cache_internal cache_i; + rustsecp256k1zkp_v0_10_0_scalar k[2]; + rustsecp256k1zkp_v0_10_0_ge nonce_pt[2]; int i; unsigned char pk_ser[33]; size_t pk_ser_len = sizeof(pk_ser); unsigned char aggpk_ser[32]; unsigned char *aggpk_ser_ptr = NULL; - rustsecp256k1zkp_v0_8_0_ge pk; + rustsecp256k1zkp_v0_10_0_ge pk; int pk_serialize_success; int ret = 1; @@ -370,7 +338,7 @@ int rustsecp256k1zkp_v0_8_0_musig_nonce_gen(const rustsecp256k1zkp_v0_8_0_contex memset(pubnonce, 0, sizeof(*pubnonce)); ARG_CHECK(session_id32 != NULL); ARG_CHECK(pubkey != NULL); - ARG_CHECK(rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); if (seckey == NULL) { /* Check in constant time that the session_id is not 0 as a * defense-in-depth measure that may protect against a faulty RNG. */ @@ -384,138 +352,140 @@ int rustsecp256k1zkp_v0_8_0_musig_nonce_gen(const rustsecp256k1zkp_v0_8_0_contex /* Check that the seckey is valid to be able to sign for it later. */ if (seckey != NULL) { - rustsecp256k1zkp_v0_8_0_scalar sk; - ret &= rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(&sk, seckey); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sk); + rustsecp256k1zkp_v0_10_0_scalar sk; + ret &= rustsecp256k1zkp_v0_10_0_scalar_set_b32_seckey(&sk, seckey); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sk); } if (keyagg_cache != NULL) { - int ret_tmp; - if (!rustsecp256k1zkp_v0_8_0_keyagg_cache_load(ctx, &cache_i, keyagg_cache)) { + if (!rustsecp256k1zkp_v0_10_0_keyagg_cache_load(ctx, &cache_i, keyagg_cache)) { return 0; } - ret_tmp = rustsecp256k1zkp_v0_8_0_xonly_ge_serialize(aggpk_ser, &cache_i.pk); - /* Serialization can not fail because the loaded point can not be infinity. */ - VERIFY_CHECK(ret_tmp); + /* The loaded point cache_i.pk can not be the point at infinity. */ + rustsecp256k1zkp_v0_10_0_fe_get_b32(aggpk_ser, &cache_i.pk.x); aggpk_ser_ptr = aggpk_ser; } - if (!rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &pk, pubkey)) { + if (!rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, &pk, pubkey)) { return 0; } - pk_serialize_success = rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&pk, pk_ser, &pk_ser_len, SECP256K1_EC_COMPRESSED); + pk_serialize_success = rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&pk, pk_ser, &pk_ser_len, SECP256K1_EC_COMPRESSED); + +#ifdef VERIFY /* A pubkey cannot be the point at infinity */ VERIFY_CHECK(pk_serialize_success); VERIFY_CHECK(pk_ser_len == sizeof(pk_ser)); +#else + (void) pk_serialize_success; +#endif - rustsecp256k1zkp_v0_8_0_nonce_function_musig(k, session_id32, msg32, seckey, pk_ser, aggpk_ser_ptr, extra_input32); - VERIFY_CHECK(!rustsecp256k1zkp_v0_8_0_scalar_is_zero(&k[0])); - VERIFY_CHECK(!rustsecp256k1zkp_v0_8_0_scalar_is_zero(&k[1])); - VERIFY_CHECK(!rustsecp256k1zkp_v0_8_0_scalar_eq(&k[0], &k[1])); - rustsecp256k1zkp_v0_8_0_musig_secnonce_save(secnonce, k, &pk); - rustsecp256k1zkp_v0_8_0_musig_secnonce_invalidate(ctx, secnonce, !ret); + rustsecp256k1zkp_v0_10_0_nonce_function_musig(k, session_id32, msg32, seckey, pk_ser, aggpk_ser_ptr, extra_input32); + VERIFY_CHECK(!rustsecp256k1zkp_v0_10_0_scalar_is_zero(&k[0])); + VERIFY_CHECK(!rustsecp256k1zkp_v0_10_0_scalar_is_zero(&k[1])); + VERIFY_CHECK(!rustsecp256k1zkp_v0_10_0_scalar_eq(&k[0], &k[1])); + rustsecp256k1zkp_v0_10_0_musig_secnonce_save(secnonce, k, &pk); + rustsecp256k1zkp_v0_10_0_musig_secnonce_invalidate(ctx, secnonce, !ret); for (i = 0; i < 2; i++) { - rustsecp256k1zkp_v0_8_0_gej nonce_ptj; - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &nonce_ptj, &k[i]); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&nonce_pt[i], &nonce_ptj); - rustsecp256k1zkp_v0_8_0_declassify(ctx, &nonce_pt[i], sizeof(nonce_pt)); - rustsecp256k1zkp_v0_8_0_scalar_clear(&k[i]); + rustsecp256k1zkp_v0_10_0_gej nonce_ptj; + rustsecp256k1zkp_v0_10_0_ecmult_gen(&ctx->ecmult_gen_ctx, &nonce_ptj, &k[i]); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&nonce_pt[i], &nonce_ptj); + rustsecp256k1zkp_v0_10_0_declassify(ctx, &nonce_pt[i], sizeof(nonce_pt)); + rustsecp256k1zkp_v0_10_0_scalar_clear(&k[i]); } /* nonce_pt won't be infinity because k != 0 with overwhelming probability */ - rustsecp256k1zkp_v0_8_0_musig_pubnonce_save(pubnonce, nonce_pt); + rustsecp256k1zkp_v0_10_0_musig_pubnonce_save(pubnonce, nonce_pt); return ret; } -static int rustsecp256k1zkp_v0_8_0_musig_sum_nonces(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_gej *summed_nonces, const rustsecp256k1zkp_v0_8_0_musig_pubnonce * const* pubnonces, size_t n_pubnonces) { +static int rustsecp256k1zkp_v0_10_0_musig_sum_nonces(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_gej *summed_nonces, const rustsecp256k1zkp_v0_10_0_musig_pubnonce * const* pubnonces, size_t n_pubnonces) { size_t i; int j; - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&summed_nonces[0]); - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&summed_nonces[1]); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&summed_nonces[0]); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&summed_nonces[1]); for (i = 0; i < n_pubnonces; i++) { - rustsecp256k1zkp_v0_8_0_ge nonce_pt[2]; - if (!rustsecp256k1zkp_v0_8_0_musig_pubnonce_load(ctx, nonce_pt, pubnonces[i])) { + rustsecp256k1zkp_v0_10_0_ge nonce_pt[2]; + if (!rustsecp256k1zkp_v0_10_0_musig_pubnonce_load(ctx, nonce_pt, pubnonces[i])) { return 0; } for (j = 0; j < 2; j++) { - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&summed_nonces[j], &summed_nonces[j], &nonce_pt[j], NULL); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&summed_nonces[j], &summed_nonces[j], &nonce_pt[j], NULL); } } return 1; } -int rustsecp256k1zkp_v0_8_0_musig_nonce_agg(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_musig_aggnonce *aggnonce, const rustsecp256k1zkp_v0_8_0_musig_pubnonce * const* pubnonces, size_t n_pubnonces) { - rustsecp256k1zkp_v0_8_0_gej aggnonce_ptj[2]; - rustsecp256k1zkp_v0_8_0_ge aggnonce_pt[2]; +int rustsecp256k1zkp_v0_10_0_musig_nonce_agg(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_musig_aggnonce *aggnonce, const rustsecp256k1zkp_v0_10_0_musig_pubnonce * const* pubnonces, size_t n_pubnonces) { + rustsecp256k1zkp_v0_10_0_gej aggnonce_ptj[2]; + rustsecp256k1zkp_v0_10_0_ge aggnonce_pt[2]; int i; VERIFY_CHECK(ctx != NULL); ARG_CHECK(aggnonce != NULL); ARG_CHECK(pubnonces != NULL); ARG_CHECK(n_pubnonces > 0); - if (!rustsecp256k1zkp_v0_8_0_musig_sum_nonces(ctx, aggnonce_ptj, pubnonces, n_pubnonces)) { + if (!rustsecp256k1zkp_v0_10_0_musig_sum_nonces(ctx, aggnonce_ptj, pubnonces, n_pubnonces)) { return 0; } for (i = 0; i < 2; i++) { - rustsecp256k1zkp_v0_8_0_ge_set_gej(&aggnonce_pt[i], &aggnonce_ptj[i]); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&aggnonce_pt[i], &aggnonce_ptj[i]); } - rustsecp256k1zkp_v0_8_0_musig_aggnonce_save(aggnonce, aggnonce_pt); + rustsecp256k1zkp_v0_10_0_musig_aggnonce_save(aggnonce, aggnonce_pt); return 1; } /* tagged_hash(aggnonce[0], aggnonce[1], agg_pk, msg) */ -static int rustsecp256k1zkp_v0_8_0_musig_compute_noncehash(unsigned char *noncehash, rustsecp256k1zkp_v0_8_0_ge *aggnonce, const unsigned char *agg_pk32, const unsigned char *msg) { +static int rustsecp256k1zkp_v0_10_0_musig_compute_noncehash(unsigned char *noncehash, rustsecp256k1zkp_v0_10_0_ge *aggnonce, const unsigned char *agg_pk32, const unsigned char *msg) { unsigned char buf[33]; - rustsecp256k1zkp_v0_8_0_sha256 sha; + rustsecp256k1zkp_v0_10_0_sha256 sha; int i; - rustsecp256k1zkp_v0_8_0_sha256_initialize_tagged(&sha, (unsigned char*)"MuSig/noncecoef", sizeof("MuSig/noncecoef") - 1); + rustsecp256k1zkp_v0_10_0_sha256_initialize_tagged(&sha, (unsigned char*)"MuSig/noncecoef", sizeof("MuSig/noncecoef") - 1); for (i = 0; i < 2; i++) { - rustsecp256k1zkp_v0_8_0_ge_serialize_ext(buf, &aggnonce[i]); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, buf, sizeof(buf)); + rustsecp256k1zkp_v0_10_0_ge_serialize_ext(buf, &aggnonce[i]); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, buf, sizeof(buf)); } - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, agg_pk32, 32); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, msg, 32); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, noncehash); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, agg_pk32, 32); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, msg, 32); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, noncehash); return 1; } -static int rustsecp256k1zkp_v0_8_0_musig_nonce_process_internal(int *fin_nonce_parity, unsigned char *fin_nonce, rustsecp256k1zkp_v0_8_0_scalar *b, rustsecp256k1zkp_v0_8_0_gej *aggnoncej, const unsigned char *agg_pk32, const unsigned char *msg) { +static int rustsecp256k1zkp_v0_10_0_musig_nonce_process_internal(int *fin_nonce_parity, unsigned char *fin_nonce, rustsecp256k1zkp_v0_10_0_scalar *b, rustsecp256k1zkp_v0_10_0_gej *aggnoncej, const unsigned char *agg_pk32, const unsigned char *msg) { unsigned char noncehash[32]; - rustsecp256k1zkp_v0_8_0_ge fin_nonce_pt; - rustsecp256k1zkp_v0_8_0_gej fin_nonce_ptj; - rustsecp256k1zkp_v0_8_0_ge aggnonce[2]; - int ret; + rustsecp256k1zkp_v0_10_0_ge fin_nonce_pt; + rustsecp256k1zkp_v0_10_0_gej fin_nonce_ptj; + rustsecp256k1zkp_v0_10_0_ge aggnonce[2]; - rustsecp256k1zkp_v0_8_0_ge_set_gej(&aggnonce[0], &aggnoncej[0]); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&aggnonce[1], &aggnoncej[1]); - if (!rustsecp256k1zkp_v0_8_0_musig_compute_noncehash(noncehash, aggnonce, agg_pk32, msg)) { + rustsecp256k1zkp_v0_10_0_ge_set_gej(&aggnonce[0], &aggnoncej[0]); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&aggnonce[1], &aggnoncej[1]); + if (!rustsecp256k1zkp_v0_10_0_musig_compute_noncehash(noncehash, aggnonce, agg_pk32, msg)) { return 0; } /* fin_nonce = aggnonce[0] + b*aggnonce[1] */ - rustsecp256k1zkp_v0_8_0_scalar_set_b32(b, noncehash, NULL); - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&fin_nonce_ptj); - rustsecp256k1zkp_v0_8_0_ecmult(&fin_nonce_ptj, &aggnoncej[1], b, NULL); - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&fin_nonce_ptj, &fin_nonce_ptj, &aggnonce[0], NULL); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&fin_nonce_pt, &fin_nonce_ptj); - if (rustsecp256k1zkp_v0_8_0_ge_is_infinity(&fin_nonce_pt)) { - fin_nonce_pt = rustsecp256k1zkp_v0_8_0_ge_const_g; - } - ret = rustsecp256k1zkp_v0_8_0_xonly_ge_serialize(fin_nonce, &fin_nonce_pt); - /* Can't fail since fin_nonce_pt is not infinity */ - VERIFY_CHECK(ret); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&fin_nonce_pt.y); - *fin_nonce_parity = rustsecp256k1zkp_v0_8_0_fe_is_odd(&fin_nonce_pt.y); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(b, noncehash, NULL); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&fin_nonce_ptj); + rustsecp256k1zkp_v0_10_0_ecmult(&fin_nonce_ptj, &aggnoncej[1], b, NULL); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&fin_nonce_ptj, &fin_nonce_ptj, &aggnonce[0], NULL); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&fin_nonce_pt, &fin_nonce_ptj); + if (rustsecp256k1zkp_v0_10_0_ge_is_infinity(&fin_nonce_pt)) { + fin_nonce_pt = rustsecp256k1zkp_v0_10_0_ge_const_g; + } + /* fin_nonce_pt is not the point at infinity */ + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&fin_nonce_pt.x); + rustsecp256k1zkp_v0_10_0_fe_get_b32(fin_nonce, &fin_nonce_pt.x); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&fin_nonce_pt.y); + *fin_nonce_parity = rustsecp256k1zkp_v0_10_0_fe_is_odd(&fin_nonce_pt.y); return 1; } -int rustsecp256k1zkp_v0_8_0_musig_nonce_process(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_musig_session *session, const rustsecp256k1zkp_v0_8_0_musig_aggnonce *aggnonce, const unsigned char *msg32, const rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache, const rustsecp256k1zkp_v0_8_0_pubkey *adaptor) { - rustsecp256k1zkp_v0_8_0_keyagg_cache_internal cache_i; - rustsecp256k1zkp_v0_8_0_ge aggnonce_pt[2]; - rustsecp256k1zkp_v0_8_0_gej aggnonce_ptj[2]; +int rustsecp256k1zkp_v0_10_0_musig_nonce_process(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_musig_session *session, const rustsecp256k1zkp_v0_10_0_musig_aggnonce *aggnonce, const unsigned char *msg32, const rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache, const rustsecp256k1zkp_v0_10_0_pubkey *adaptor) { + rustsecp256k1zkp_v0_10_0_keyagg_cache_internal cache_i; + rustsecp256k1zkp_v0_10_0_ge aggnonce_pt[2]; + rustsecp256k1zkp_v0_10_0_gej aggnonce_ptj[2]; unsigned char fin_nonce[32]; - rustsecp256k1zkp_v0_8_0_musig_session_internal session_i; + rustsecp256k1zkp_v0_10_0_musig_session_internal session_i; unsigned char agg_pk32[32]; VERIFY_CHECK(ctx != NULL); @@ -524,70 +494,70 @@ int rustsecp256k1zkp_v0_8_0_musig_nonce_process(const rustsecp256k1zkp_v0_8_0_co ARG_CHECK(msg32 != NULL); ARG_CHECK(keyagg_cache != NULL); - if (!rustsecp256k1zkp_v0_8_0_keyagg_cache_load(ctx, &cache_i, keyagg_cache)) { + if (!rustsecp256k1zkp_v0_10_0_keyagg_cache_load(ctx, &cache_i, keyagg_cache)) { return 0; } - rustsecp256k1zkp_v0_8_0_fe_get_b32(agg_pk32, &cache_i.pk.x); + rustsecp256k1zkp_v0_10_0_fe_get_b32(agg_pk32, &cache_i.pk.x); - if (!rustsecp256k1zkp_v0_8_0_musig_aggnonce_load(ctx, aggnonce_pt, aggnonce)) { + if (!rustsecp256k1zkp_v0_10_0_musig_aggnonce_load(ctx, aggnonce_pt, aggnonce)) { return 0; } - rustsecp256k1zkp_v0_8_0_gej_set_ge(&aggnonce_ptj[0], &aggnonce_pt[0]); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&aggnonce_ptj[1], &aggnonce_pt[1]); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&aggnonce_ptj[0], &aggnonce_pt[0]); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&aggnonce_ptj[1], &aggnonce_pt[1]); /* Add public adaptor to nonce */ if (adaptor != NULL) { - rustsecp256k1zkp_v0_8_0_ge adaptorp; - if (!rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &adaptorp, adaptor)) { + rustsecp256k1zkp_v0_10_0_ge adaptorp; + if (!rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, &adaptorp, adaptor)) { return 0; } - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&aggnonce_ptj[0], &aggnonce_ptj[0], &adaptorp, NULL); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&aggnonce_ptj[0], &aggnonce_ptj[0], &adaptorp, NULL); } - if (!rustsecp256k1zkp_v0_8_0_musig_nonce_process_internal(&session_i.fin_nonce_parity, fin_nonce, &session_i.noncecoef, aggnonce_ptj, agg_pk32, msg32)) { + if (!rustsecp256k1zkp_v0_10_0_musig_nonce_process_internal(&session_i.fin_nonce_parity, fin_nonce, &session_i.noncecoef, aggnonce_ptj, agg_pk32, msg32)) { return 0; } - rustsecp256k1zkp_v0_8_0_schnorrsig_challenge(&session_i.challenge, fin_nonce, msg32, 32, agg_pk32); + rustsecp256k1zkp_v0_10_0_schnorrsig_challenge(&session_i.challenge, fin_nonce, msg32, 32, agg_pk32); /* If there is a tweak then set `challenge` times `tweak` to the `s`-part.*/ - rustsecp256k1zkp_v0_8_0_scalar_set_int(&session_i.s_part, 0); - if (!rustsecp256k1zkp_v0_8_0_scalar_is_zero(&cache_i.tweak)) { - rustsecp256k1zkp_v0_8_0_scalar e_tmp; - rustsecp256k1zkp_v0_8_0_scalar_mul(&e_tmp, &session_i.challenge, &cache_i.tweak); - if (rustsecp256k1zkp_v0_8_0_fe_is_odd(&cache_i.pk.y)) { - rustsecp256k1zkp_v0_8_0_scalar_negate(&e_tmp, &e_tmp); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&session_i.s_part, 0); + if (!rustsecp256k1zkp_v0_10_0_scalar_is_zero(&cache_i.tweak)) { + rustsecp256k1zkp_v0_10_0_scalar e_tmp; + rustsecp256k1zkp_v0_10_0_scalar_mul(&e_tmp, &session_i.challenge, &cache_i.tweak); + if (rustsecp256k1zkp_v0_10_0_fe_is_odd(&cache_i.pk.y)) { + rustsecp256k1zkp_v0_10_0_scalar_negate(&e_tmp, &e_tmp); } - rustsecp256k1zkp_v0_8_0_scalar_add(&session_i.s_part, &session_i.s_part, &e_tmp); + rustsecp256k1zkp_v0_10_0_scalar_add(&session_i.s_part, &session_i.s_part, &e_tmp); } memcpy(session_i.fin_nonce, fin_nonce, sizeof(session_i.fin_nonce)); - rustsecp256k1zkp_v0_8_0_musig_session_save(session, &session_i); + rustsecp256k1zkp_v0_10_0_musig_session_save(session, &session_i); return 1; } -static void rustsecp256k1zkp_v0_8_0_musig_partial_sign_clear(rustsecp256k1zkp_v0_8_0_scalar *sk, rustsecp256k1zkp_v0_8_0_scalar *k) { - rustsecp256k1zkp_v0_8_0_scalar_clear(sk); - rustsecp256k1zkp_v0_8_0_scalar_clear(&k[0]); - rustsecp256k1zkp_v0_8_0_scalar_clear(&k[1]); +static void rustsecp256k1zkp_v0_10_0_musig_partial_sign_clear(rustsecp256k1zkp_v0_10_0_scalar *sk, rustsecp256k1zkp_v0_10_0_scalar *k) { + rustsecp256k1zkp_v0_10_0_scalar_clear(sk); + rustsecp256k1zkp_v0_10_0_scalar_clear(&k[0]); + rustsecp256k1zkp_v0_10_0_scalar_clear(&k[1]); } -int rustsecp256k1zkp_v0_8_0_musig_partial_sign(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_musig_partial_sig *partial_sig, rustsecp256k1zkp_v0_8_0_musig_secnonce *secnonce, const rustsecp256k1zkp_v0_8_0_keypair *keypair, const rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache, const rustsecp256k1zkp_v0_8_0_musig_session *session) { - rustsecp256k1zkp_v0_8_0_scalar sk; - rustsecp256k1zkp_v0_8_0_ge pk, keypair_pk; - rustsecp256k1zkp_v0_8_0_scalar k[2]; - rustsecp256k1zkp_v0_8_0_scalar mu, s; - rustsecp256k1zkp_v0_8_0_keyagg_cache_internal cache_i; - rustsecp256k1zkp_v0_8_0_musig_session_internal session_i; +int rustsecp256k1zkp_v0_10_0_musig_partial_sign(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_musig_partial_sig *partial_sig, rustsecp256k1zkp_v0_10_0_musig_secnonce *secnonce, const rustsecp256k1zkp_v0_10_0_keypair *keypair, const rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache, const rustsecp256k1zkp_v0_10_0_musig_session *session) { + rustsecp256k1zkp_v0_10_0_scalar sk; + rustsecp256k1zkp_v0_10_0_ge pk, keypair_pk; + rustsecp256k1zkp_v0_10_0_scalar k[2]; + rustsecp256k1zkp_v0_10_0_scalar mu, s; + rustsecp256k1zkp_v0_10_0_keyagg_cache_internal cache_i; + rustsecp256k1zkp_v0_10_0_musig_session_internal session_i; int ret; VERIFY_CHECK(ctx != NULL); ARG_CHECK(secnonce != NULL); /* Fails if the magic doesn't match */ - ret = rustsecp256k1zkp_v0_8_0_musig_secnonce_load(ctx, k, &pk, secnonce); + ret = rustsecp256k1zkp_v0_10_0_musig_secnonce_load(ctx, k, &pk, secnonce); /* Set nonce to zero to avoid nonce reuse. This will cause subsequent calls * of this function to fail */ memset(secnonce, 0, sizeof(*secnonce)); if (!ret) { - rustsecp256k1zkp_v0_8_0_musig_partial_sign_clear(&sk, k); + rustsecp256k1zkp_v0_10_0_musig_partial_sign_clear(&sk, k); return 0; } @@ -596,61 +566,61 @@ int rustsecp256k1zkp_v0_8_0_musig_partial_sign(const rustsecp256k1zkp_v0_8_0_con ARG_CHECK(keyagg_cache != NULL); ARG_CHECK(session != NULL); - if (!rustsecp256k1zkp_v0_8_0_keypair_load(ctx, &sk, &keypair_pk, keypair)) { - rustsecp256k1zkp_v0_8_0_musig_partial_sign_clear(&sk, k); + if (!rustsecp256k1zkp_v0_10_0_keypair_load(ctx, &sk, &keypair_pk, keypair)) { + rustsecp256k1zkp_v0_10_0_musig_partial_sign_clear(&sk, k); return 0; } - ARG_CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&pk.x, &keypair_pk.x) - && rustsecp256k1zkp_v0_8_0_fe_equal_var(&pk.y, &keypair_pk.y)); - if (!rustsecp256k1zkp_v0_8_0_keyagg_cache_load(ctx, &cache_i, keyagg_cache)) { - rustsecp256k1zkp_v0_8_0_musig_partial_sign_clear(&sk, k); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&pk.x, &keypair_pk.x) + && rustsecp256k1zkp_v0_10_0_fe_equal(&pk.y, &keypair_pk.y)); + if (!rustsecp256k1zkp_v0_10_0_keyagg_cache_load(ctx, &cache_i, keyagg_cache)) { + rustsecp256k1zkp_v0_10_0_musig_partial_sign_clear(&sk, k); return 0; } - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&pk.y); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&pk.y); - /* Negate sk if rustsecp256k1zkp_v0_8_0_fe_is_odd(&cache_i.pk.y)) XOR cache_i.parity_acc. + /* Negate sk if rustsecp256k1zkp_v0_10_0_fe_is_odd(&cache_i.pk.y)) XOR cache_i.parity_acc. * This corresponds to the line "Let d = g⋅gacc⋅d' mod n" in the * specification. */ - if ((rustsecp256k1zkp_v0_8_0_fe_is_odd(&cache_i.pk.y) + if ((rustsecp256k1zkp_v0_10_0_fe_is_odd(&cache_i.pk.y) != cache_i.parity_acc)) { - rustsecp256k1zkp_v0_8_0_scalar_negate(&sk, &sk); + rustsecp256k1zkp_v0_10_0_scalar_negate(&sk, &sk); } /* Multiply KeyAgg coefficient */ - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&pk.x); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&pk.x); /* TODO Cache mu */ - rustsecp256k1zkp_v0_8_0_musig_keyaggcoef(&mu, &cache_i, &pk); - rustsecp256k1zkp_v0_8_0_scalar_mul(&sk, &sk, &mu); + rustsecp256k1zkp_v0_10_0_musig_keyaggcoef(&mu, &cache_i, &pk); + rustsecp256k1zkp_v0_10_0_scalar_mul(&sk, &sk, &mu); - if (!rustsecp256k1zkp_v0_8_0_musig_session_load(ctx, &session_i, session)) { - rustsecp256k1zkp_v0_8_0_musig_partial_sign_clear(&sk, k); + if (!rustsecp256k1zkp_v0_10_0_musig_session_load(ctx, &session_i, session)) { + rustsecp256k1zkp_v0_10_0_musig_partial_sign_clear(&sk, k); return 0; } if (session_i.fin_nonce_parity) { - rustsecp256k1zkp_v0_8_0_scalar_negate(&k[0], &k[0]); - rustsecp256k1zkp_v0_8_0_scalar_negate(&k[1], &k[1]); + rustsecp256k1zkp_v0_10_0_scalar_negate(&k[0], &k[0]); + rustsecp256k1zkp_v0_10_0_scalar_negate(&k[1], &k[1]); } /* Sign */ - rustsecp256k1zkp_v0_8_0_scalar_mul(&s, &session_i.challenge, &sk); - rustsecp256k1zkp_v0_8_0_scalar_mul(&k[1], &session_i.noncecoef, &k[1]); - rustsecp256k1zkp_v0_8_0_scalar_add(&k[0], &k[0], &k[1]); - rustsecp256k1zkp_v0_8_0_scalar_add(&s, &s, &k[0]); - rustsecp256k1zkp_v0_8_0_musig_partial_sig_save(partial_sig, &s); - rustsecp256k1zkp_v0_8_0_musig_partial_sign_clear(&sk, k); + rustsecp256k1zkp_v0_10_0_scalar_mul(&s, &session_i.challenge, &sk); + rustsecp256k1zkp_v0_10_0_scalar_mul(&k[1], &session_i.noncecoef, &k[1]); + rustsecp256k1zkp_v0_10_0_scalar_add(&k[0], &k[0], &k[1]); + rustsecp256k1zkp_v0_10_0_scalar_add(&s, &s, &k[0]); + rustsecp256k1zkp_v0_10_0_musig_partial_sig_save(partial_sig, &s); + rustsecp256k1zkp_v0_10_0_musig_partial_sign_clear(&sk, k); return 1; } -int rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(const rustsecp256k1zkp_v0_8_0_context* ctx, const rustsecp256k1zkp_v0_8_0_musig_partial_sig *partial_sig, const rustsecp256k1zkp_v0_8_0_musig_pubnonce *pubnonce, const rustsecp256k1zkp_v0_8_0_pubkey *pubkey, const rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache, const rustsecp256k1zkp_v0_8_0_musig_session *session) { - rustsecp256k1zkp_v0_8_0_keyagg_cache_internal cache_i; - rustsecp256k1zkp_v0_8_0_musig_session_internal session_i; - rustsecp256k1zkp_v0_8_0_scalar mu, e, s; - rustsecp256k1zkp_v0_8_0_gej pkj; - rustsecp256k1zkp_v0_8_0_ge nonce_pt[2]; - rustsecp256k1zkp_v0_8_0_gej rj; - rustsecp256k1zkp_v0_8_0_gej tmp; - rustsecp256k1zkp_v0_8_0_ge pkp; +int rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(const rustsecp256k1zkp_v0_10_0_context* ctx, const rustsecp256k1zkp_v0_10_0_musig_partial_sig *partial_sig, const rustsecp256k1zkp_v0_10_0_musig_pubnonce *pubnonce, const rustsecp256k1zkp_v0_10_0_pubkey *pubkey, const rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache, const rustsecp256k1zkp_v0_10_0_musig_session *session) { + rustsecp256k1zkp_v0_10_0_keyagg_cache_internal cache_i; + rustsecp256k1zkp_v0_10_0_musig_session_internal session_i; + rustsecp256k1zkp_v0_10_0_scalar mu, e, s; + rustsecp256k1zkp_v0_10_0_gej pkj; + rustsecp256k1zkp_v0_10_0_ge nonce_pt[2]; + rustsecp256k1zkp_v0_10_0_gej rj; + rustsecp256k1zkp_v0_10_0_gej tmp; + rustsecp256k1zkp_v0_10_0_ge pkp; VERIFY_CHECK(ctx != NULL); ARG_CHECK(partial_sig != NULL); @@ -659,57 +629,57 @@ int rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(const rustsecp256k1zkp_v0_8 ARG_CHECK(keyagg_cache != NULL); ARG_CHECK(session != NULL); - if (!rustsecp256k1zkp_v0_8_0_musig_session_load(ctx, &session_i, session)) { + if (!rustsecp256k1zkp_v0_10_0_musig_session_load(ctx, &session_i, session)) { return 0; } /* Compute "effective" nonce rj = aggnonce[0] + b*aggnonce[1] */ /* TODO: use multiexp to compute -s*G + e*mu*pubkey + aggnonce[0] + b*aggnonce[1] */ - if (!rustsecp256k1zkp_v0_8_0_musig_pubnonce_load(ctx, nonce_pt, pubnonce)) { + if (!rustsecp256k1zkp_v0_10_0_musig_pubnonce_load(ctx, nonce_pt, pubnonce)) { return 0; } - rustsecp256k1zkp_v0_8_0_gej_set_ge(&rj, &nonce_pt[1]); - rustsecp256k1zkp_v0_8_0_ecmult(&rj, &rj, &session_i.noncecoef, NULL); - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&rj, &rj, &nonce_pt[0], NULL); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&rj, &nonce_pt[1]); + rustsecp256k1zkp_v0_10_0_ecmult(&rj, &rj, &session_i.noncecoef, NULL); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&rj, &rj, &nonce_pt[0], NULL); - if (!rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &pkp, pubkey)) { + if (!rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, &pkp, pubkey)) { return 0; } - if (!rustsecp256k1zkp_v0_8_0_keyagg_cache_load(ctx, &cache_i, keyagg_cache)) { + if (!rustsecp256k1zkp_v0_10_0_keyagg_cache_load(ctx, &cache_i, keyagg_cache)) { return 0; } /* Multiplying the challenge by the KeyAgg coefficient is equivalent * to multiplying the signer's public key by the coefficient, except * much easier to do. */ - rustsecp256k1zkp_v0_8_0_musig_keyaggcoef(&mu, &cache_i, &pkp); - rustsecp256k1zkp_v0_8_0_scalar_mul(&e, &session_i.challenge, &mu); + rustsecp256k1zkp_v0_10_0_musig_keyaggcoef(&mu, &cache_i, &pkp); + rustsecp256k1zkp_v0_10_0_scalar_mul(&e, &session_i.challenge, &mu); - /* Negate e if rustsecp256k1zkp_v0_8_0_fe_is_odd(&cache_i.pk.y)) XOR cache_i.parity_acc. + /* Negate e if rustsecp256k1zkp_v0_10_0_fe_is_odd(&cache_i.pk.y)) XOR cache_i.parity_acc. * This corresponds to the line "Let g' = g⋅gacc mod n" and the multiplication "g'⋅e" * in the specification. */ - if (rustsecp256k1zkp_v0_8_0_fe_is_odd(&cache_i.pk.y) + if (rustsecp256k1zkp_v0_10_0_fe_is_odd(&cache_i.pk.y) != cache_i.parity_acc) { - rustsecp256k1zkp_v0_8_0_scalar_negate(&e, &e); + rustsecp256k1zkp_v0_10_0_scalar_negate(&e, &e); } - if (!rustsecp256k1zkp_v0_8_0_musig_partial_sig_load(ctx, &s, partial_sig)) { + if (!rustsecp256k1zkp_v0_10_0_musig_partial_sig_load(ctx, &s, partial_sig)) { return 0; } /* Compute -s*G + e*pkj + rj (e already includes the keyagg coefficient mu) */ - rustsecp256k1zkp_v0_8_0_scalar_negate(&s, &s); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&pkj, &pkp); - rustsecp256k1zkp_v0_8_0_ecmult(&tmp, &pkj, &e, &s); + rustsecp256k1zkp_v0_10_0_scalar_negate(&s, &s); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&pkj, &pkp); + rustsecp256k1zkp_v0_10_0_ecmult(&tmp, &pkj, &e, &s); if (session_i.fin_nonce_parity) { - rustsecp256k1zkp_v0_8_0_gej_neg(&rj, &rj); + rustsecp256k1zkp_v0_10_0_gej_neg(&rj, &rj); } - rustsecp256k1zkp_v0_8_0_gej_add_var(&tmp, &tmp, &rj, NULL); + rustsecp256k1zkp_v0_10_0_gej_add_var(&tmp, &tmp, &rj, NULL); - return rustsecp256k1zkp_v0_8_0_gej_is_infinity(&tmp); + return rustsecp256k1zkp_v0_10_0_gej_is_infinity(&tmp); } -int rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *sig64, const rustsecp256k1zkp_v0_8_0_musig_session *session, const rustsecp256k1zkp_v0_8_0_musig_partial_sig * const* partial_sigs, size_t n_sigs) { +int rustsecp256k1zkp_v0_10_0_musig_partial_sig_agg(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *sig64, const rustsecp256k1zkp_v0_10_0_musig_session *session, const rustsecp256k1zkp_v0_10_0_musig_partial_sig * const* partial_sigs, size_t n_sigs) { size_t i; - rustsecp256k1zkp_v0_8_0_musig_session_internal session_i; + rustsecp256k1zkp_v0_10_0_musig_session_internal session_i; VERIFY_CHECK(ctx != NULL); ARG_CHECK(sig64 != NULL); @@ -717,17 +687,17 @@ int rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg(const rustsecp256k1zkp_v0_8_0_ ARG_CHECK(partial_sigs != NULL); ARG_CHECK(n_sigs > 0); - if (!rustsecp256k1zkp_v0_8_0_musig_session_load(ctx, &session_i, session)) { + if (!rustsecp256k1zkp_v0_10_0_musig_session_load(ctx, &session_i, session)) { return 0; } for (i = 0; i < n_sigs; i++) { - rustsecp256k1zkp_v0_8_0_scalar term; - if (!rustsecp256k1zkp_v0_8_0_musig_partial_sig_load(ctx, &term, partial_sigs[i])) { + rustsecp256k1zkp_v0_10_0_scalar term; + if (!rustsecp256k1zkp_v0_10_0_musig_partial_sig_load(ctx, &term, partial_sigs[i])) { return 0; } - rustsecp256k1zkp_v0_8_0_scalar_add(&session_i.s_part, &session_i.s_part, &term); + rustsecp256k1zkp_v0_10_0_scalar_add(&session_i.s_part, &session_i.s_part, &term); } - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&sig64[32], &session_i.s_part); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&sig64[32], &session_i.s_part); memcpy(&sig64[0], session_i.fin_nonce, 32); return 1; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/tests_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/tests_impl.h index 8476958b..9ff93cde 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/tests_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/musig/tests_impl.h @@ -25,11 +25,11 @@ #include "vectors.h" -static int create_keypair_and_pk(rustsecp256k1zkp_v0_8_0_keypair *keypair, rustsecp256k1zkp_v0_8_0_pubkey *pk, const unsigned char *sk) { +static int create_keypair_and_pk(rustsecp256k1zkp_v0_10_0_keypair *keypair, rustsecp256k1zkp_v0_10_0_pubkey *pk, const unsigned char *sk) { int ret; - rustsecp256k1zkp_v0_8_0_keypair keypair_tmp; - ret = rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair_tmp, sk); - ret &= rustsecp256k1zkp_v0_8_0_keypair_pub(ctx, pk, &keypair_tmp); + rustsecp256k1zkp_v0_10_0_keypair keypair_tmp; + ret = rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair_tmp, sk); + ret &= rustsecp256k1zkp_v0_10_0_keypair_pub(CTX, pk, &keypair_tmp); if (keypair != NULL) { *keypair = keypair_tmp; } @@ -38,143 +38,128 @@ static int create_keypair_and_pk(rustsecp256k1zkp_v0_8_0_keypair *keypair, rusts /* Just a simple (non-adaptor, non-tweaked) 2-of-2 MuSig aggregate, sign, verify * test. */ -void musig_simple_test(rustsecp256k1zkp_v0_8_0_scratch_space *scratch) { +static void musig_simple_test(rustsecp256k1zkp_v0_10_0_scratch_space *scratch) { unsigned char sk[2][32]; - rustsecp256k1zkp_v0_8_0_keypair keypair[2]; - rustsecp256k1zkp_v0_8_0_musig_pubnonce pubnonce[2]; - const rustsecp256k1zkp_v0_8_0_musig_pubnonce *pubnonce_ptr[2]; - rustsecp256k1zkp_v0_8_0_musig_aggnonce aggnonce; + rustsecp256k1zkp_v0_10_0_keypair keypair[2]; + rustsecp256k1zkp_v0_10_0_musig_pubnonce pubnonce[2]; + const rustsecp256k1zkp_v0_10_0_musig_pubnonce *pubnonce_ptr[2]; + rustsecp256k1zkp_v0_10_0_musig_aggnonce aggnonce; unsigned char msg[32]; - rustsecp256k1zkp_v0_8_0_xonly_pubkey agg_pk; - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache keyagg_cache; + rustsecp256k1zkp_v0_10_0_xonly_pubkey agg_pk; + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache keyagg_cache; unsigned char session_id[2][32]; - rustsecp256k1zkp_v0_8_0_musig_secnonce secnonce[2]; - rustsecp256k1zkp_v0_8_0_pubkey pk[2]; - const rustsecp256k1zkp_v0_8_0_pubkey *pk_ptr[2]; - rustsecp256k1zkp_v0_8_0_musig_partial_sig partial_sig[2]; - const rustsecp256k1zkp_v0_8_0_musig_partial_sig *partial_sig_ptr[2]; + rustsecp256k1zkp_v0_10_0_musig_secnonce secnonce[2]; + rustsecp256k1zkp_v0_10_0_pubkey pk[2]; + const rustsecp256k1zkp_v0_10_0_pubkey *pk_ptr[2]; + rustsecp256k1zkp_v0_10_0_musig_partial_sig partial_sig[2]; + const rustsecp256k1zkp_v0_10_0_musig_partial_sig *partial_sig_ptr[2]; unsigned char final_sig[64]; - rustsecp256k1zkp_v0_8_0_musig_session session; + rustsecp256k1zkp_v0_10_0_musig_session session; int i; - rustsecp256k1zkp_v0_8_0_testrand256(msg); + rustsecp256k1zkp_v0_10_0_testrand256(msg); for (i = 0; i < 2; i++) { - rustsecp256k1zkp_v0_8_0_testrand256(session_id[i]); - rustsecp256k1zkp_v0_8_0_testrand256(sk[i]); + rustsecp256k1zkp_v0_10_0_testrand256(session_id[i]); + rustsecp256k1zkp_v0_10_0_testrand256(sk[i]); pk_ptr[i] = &pk[i]; pubnonce_ptr[i] = &pubnonce[i]; partial_sig_ptr[i] = &partial_sig[i]; CHECK(create_keypair_and_pk(&keypair[i], &pk[i], sk[i])); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(ctx, &secnonce[i], &pubnonce[i], session_id[i], sk[i], &pk[i], NULL, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce[i], &pubnonce[i], session_id[i], sk[i], &pk[i], NULL, NULL, NULL) == 1); } - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(ctx, scratch, &agg_pk, &keyagg_cache, pk_ptr, 2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_agg(ctx, &aggnonce, pubnonce_ptr, 2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(ctx, &session, &aggnonce, msg, &keyagg_cache, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(CTX, scratch, &agg_pk, &keyagg_cache, pk_ptr, 2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_agg(CTX, &aggnonce, pubnonce_ptr, 2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_process(CTX, &session, &aggnonce, msg, &keyagg_cache, NULL) == 1); for (i = 0; i < 2; i++) { - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(ctx, &partial_sig[i], &secnonce[i], &keypair[i], &keyagg_cache, &session) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(ctx, &partial_sig[i], &pubnonce[i], &pk[i], &keyagg_cache, &session) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig[i], &secnonce[i], &keypair[i], &keyagg_cache, &session) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &partial_sig[i], &pubnonce[i], &pk[i], &keyagg_cache, &session) == 1); } - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg(ctx, final_sig, &session, partial_sig_ptr, 2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, final_sig, msg, sizeof(msg), &agg_pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_agg(CTX, final_sig, &session, partial_sig_ptr, 2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, final_sig, msg, sizeof(msg), &agg_pk) == 1); } -void pubnonce_summing_to_inf(rustsecp256k1zkp_v0_8_0_musig_pubnonce *pubnonce) { - rustsecp256k1zkp_v0_8_0_ge ge[2]; +static void pubnonce_summing_to_inf(rustsecp256k1zkp_v0_10_0_musig_pubnonce *pubnonce) { + rustsecp256k1zkp_v0_10_0_ge ge[2]; int i; - rustsecp256k1zkp_v0_8_0_gej summed_nonces[2]; - const rustsecp256k1zkp_v0_8_0_musig_pubnonce *pubnonce_ptr[2]; + rustsecp256k1zkp_v0_10_0_gej summed_nonces[2]; + const rustsecp256k1zkp_v0_10_0_musig_pubnonce *pubnonce_ptr[2]; - ge[0] = rustsecp256k1zkp_v0_8_0_ge_const_g; - ge[1] = rustsecp256k1zkp_v0_8_0_ge_const_g; + ge[0] = rustsecp256k1zkp_v0_10_0_ge_const_g; + ge[1] = rustsecp256k1zkp_v0_10_0_ge_const_g; for (i = 0; i < 2; i++) { - rustsecp256k1zkp_v0_8_0_musig_pubnonce_save(&pubnonce[i], ge); + rustsecp256k1zkp_v0_10_0_musig_pubnonce_save(&pubnonce[i], ge); pubnonce_ptr[i] = &pubnonce[i]; - rustsecp256k1zkp_v0_8_0_ge_neg(&ge[0], &ge[0]); - rustsecp256k1zkp_v0_8_0_ge_neg(&ge[1], &ge[1]); + rustsecp256k1zkp_v0_10_0_ge_neg(&ge[0], &ge[0]); + rustsecp256k1zkp_v0_10_0_ge_neg(&ge[1], &ge[1]); } - rustsecp256k1zkp_v0_8_0_musig_sum_nonces(ctx, summed_nonces, pubnonce_ptr, 2); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&summed_nonces[0])); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&summed_nonces[1])); + rustsecp256k1zkp_v0_10_0_musig_sum_nonces(CTX, summed_nonces, pubnonce_ptr, 2); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&summed_nonces[0])); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&summed_nonces[1])); } int memcmp_and_randomize(unsigned char *value, const unsigned char *expected, size_t len) { int ret; size_t i; - ret = rustsecp256k1zkp_v0_8_0_memcmp_var(value, expected, len); + ret = rustsecp256k1zkp_v0_10_0_memcmp_var(value, expected, len); for (i = 0; i < len; i++) { - value[i] = rustsecp256k1zkp_v0_8_0_testrand_bits(8); + value[i] = rustsecp256k1zkp_v0_10_0_testrand_bits(8); } return ret; } -void musig_api_tests(rustsecp256k1zkp_v0_8_0_scratch_space *scratch) { - rustsecp256k1zkp_v0_8_0_scratch_space *scratch_small; - rustsecp256k1zkp_v0_8_0_musig_partial_sig partial_sig[2]; - const rustsecp256k1zkp_v0_8_0_musig_partial_sig *partial_sig_ptr[2]; - rustsecp256k1zkp_v0_8_0_musig_partial_sig invalid_partial_sig; - const rustsecp256k1zkp_v0_8_0_musig_partial_sig *invalid_partial_sig_ptr[2]; +static void musig_api_tests(rustsecp256k1zkp_v0_10_0_scratch_space *scratch) { + rustsecp256k1zkp_v0_10_0_scratch_space *scratch_small; + rustsecp256k1zkp_v0_10_0_musig_partial_sig partial_sig[2]; + const rustsecp256k1zkp_v0_10_0_musig_partial_sig *partial_sig_ptr[2]; + rustsecp256k1zkp_v0_10_0_musig_partial_sig invalid_partial_sig; + const rustsecp256k1zkp_v0_10_0_musig_partial_sig *invalid_partial_sig_ptr[2]; unsigned char final_sig[64]; unsigned char pre_sig[64]; unsigned char buf[32]; unsigned char sk[2][32]; - rustsecp256k1zkp_v0_8_0_keypair keypair[2]; - rustsecp256k1zkp_v0_8_0_keypair invalid_keypair; + rustsecp256k1zkp_v0_10_0_keypair keypair[2]; + rustsecp256k1zkp_v0_10_0_keypair invalid_keypair; unsigned char max64[64]; unsigned char zeros132[132] = { 0 }; unsigned char session_id[2][32]; - rustsecp256k1zkp_v0_8_0_musig_secnonce secnonce[2]; - rustsecp256k1zkp_v0_8_0_musig_secnonce secnonce_tmp; - rustsecp256k1zkp_v0_8_0_musig_secnonce invalid_secnonce; - rustsecp256k1zkp_v0_8_0_musig_pubnonce pubnonce[2]; - const rustsecp256k1zkp_v0_8_0_musig_pubnonce *pubnonce_ptr[2]; + rustsecp256k1zkp_v0_10_0_musig_secnonce secnonce[2]; + rustsecp256k1zkp_v0_10_0_musig_secnonce secnonce_tmp; + rustsecp256k1zkp_v0_10_0_musig_secnonce invalid_secnonce; + rustsecp256k1zkp_v0_10_0_musig_pubnonce pubnonce[2]; + const rustsecp256k1zkp_v0_10_0_musig_pubnonce *pubnonce_ptr[2]; unsigned char pubnonce_ser[66]; - rustsecp256k1zkp_v0_8_0_musig_pubnonce inf_pubnonce[2]; - const rustsecp256k1zkp_v0_8_0_musig_pubnonce *inf_pubnonce_ptr[2]; - rustsecp256k1zkp_v0_8_0_musig_pubnonce invalid_pubnonce; - const rustsecp256k1zkp_v0_8_0_musig_pubnonce *invalid_pubnonce_ptr[1]; - rustsecp256k1zkp_v0_8_0_musig_aggnonce aggnonce; + rustsecp256k1zkp_v0_10_0_musig_pubnonce inf_pubnonce[2]; + const rustsecp256k1zkp_v0_10_0_musig_pubnonce *inf_pubnonce_ptr[2]; + rustsecp256k1zkp_v0_10_0_musig_pubnonce invalid_pubnonce; + const rustsecp256k1zkp_v0_10_0_musig_pubnonce *invalid_pubnonce_ptr[1]; + rustsecp256k1zkp_v0_10_0_musig_aggnonce aggnonce; unsigned char aggnonce_ser[66]; unsigned char msg[32]; - rustsecp256k1zkp_v0_8_0_xonly_pubkey agg_pk; - rustsecp256k1zkp_v0_8_0_pubkey full_agg_pk; - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache keyagg_cache; - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache invalid_keyagg_cache; - rustsecp256k1zkp_v0_8_0_musig_session session; - rustsecp256k1zkp_v0_8_0_musig_session invalid_session; - rustsecp256k1zkp_v0_8_0_pubkey pk[2]; - const rustsecp256k1zkp_v0_8_0_pubkey *pk_ptr[2]; - rustsecp256k1zkp_v0_8_0_pubkey invalid_pk; - const rustsecp256k1zkp_v0_8_0_pubkey *invalid_pk_ptr2[2]; - const rustsecp256k1zkp_v0_8_0_pubkey *invalid_pk_ptr3[3]; + rustsecp256k1zkp_v0_10_0_xonly_pubkey agg_pk; + rustsecp256k1zkp_v0_10_0_pubkey full_agg_pk; + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache keyagg_cache; + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache invalid_keyagg_cache; + rustsecp256k1zkp_v0_10_0_musig_session session; + rustsecp256k1zkp_v0_10_0_musig_session invalid_session; + rustsecp256k1zkp_v0_10_0_pubkey pk[2]; + const rustsecp256k1zkp_v0_10_0_pubkey *pk_ptr[2]; + rustsecp256k1zkp_v0_10_0_pubkey invalid_pk; + const rustsecp256k1zkp_v0_10_0_pubkey *invalid_pk_ptr2[2]; + const rustsecp256k1zkp_v0_10_0_pubkey *invalid_pk_ptr3[3]; unsigned char tweak[32]; int nonce_parity; unsigned char sec_adaptor[32]; unsigned char sec_adaptor1[32]; - rustsecp256k1zkp_v0_8_0_pubkey adaptor; + rustsecp256k1zkp_v0_10_0_pubkey adaptor; int i; /** setup **/ - rustsecp256k1zkp_v0_8_0_context *none = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_NONE); - rustsecp256k1zkp_v0_8_0_context *sign = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN); - rustsecp256k1zkp_v0_8_0_context *vrfy = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_VERIFY); - rustsecp256k1zkp_v0_8_0_context *sttc = rustsecp256k1zkp_v0_8_0_context_clone(rustsecp256k1zkp_v0_8_0_context_no_precomp); - int ecount; - - rustsecp256k1zkp_v0_8_0_context_set_error_callback(none, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(sign, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(vrfy, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(sttc, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(none, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sign, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(vrfy, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sttc, counting_illegal_callback_fn, &ecount); - memset(max64, 0xff, sizeof(max64)); memset(&invalid_keypair, 0, sizeof(invalid_keypair)); memset(&invalid_pk, 0, sizeof(invalid_pk)); @@ -189,10 +174,10 @@ void musig_api_tests(rustsecp256k1zkp_v0_8_0_scratch_space *scratch) { memset(&invalid_pubnonce, 0, sizeof(invalid_pubnonce)); memset(&invalid_session, 0, sizeof(invalid_session)); - rustsecp256k1zkp_v0_8_0_testrand256(sec_adaptor); - rustsecp256k1zkp_v0_8_0_testrand256(msg); - rustsecp256k1zkp_v0_8_0_testrand256(tweak); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &adaptor, sec_adaptor) == 1); + rustsecp256k1zkp_v0_10_0_testrand256(sec_adaptor); + rustsecp256k1zkp_v0_10_0_testrand256(msg); + rustsecp256k1zkp_v0_10_0_testrand256(tweak); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &adaptor, sec_adaptor) == 1); for (i = 0; i < 2; i++) { pk_ptr[i] = &pk[i]; invalid_pk_ptr2[i] = &invalid_pk; @@ -201,8 +186,8 @@ void musig_api_tests(rustsecp256k1zkp_v0_8_0_scratch_space *scratch) { inf_pubnonce_ptr[i] = &inf_pubnonce[i]; partial_sig_ptr[i] = &partial_sig[i]; invalid_partial_sig_ptr[i] = &partial_sig[i]; - rustsecp256k1zkp_v0_8_0_testrand256(session_id[i]); - rustsecp256k1zkp_v0_8_0_testrand256(sk[i]); + rustsecp256k1zkp_v0_10_0_testrand256(session_id[i]); + rustsecp256k1zkp_v0_10_0_testrand256(sk[i]); CHECK(create_keypair_and_pk(&keypair[i], &pk[i], sk[i])); } invalid_pubnonce_ptr[0] = &invalid_pubnonce; @@ -214,423 +199,291 @@ void musig_api_tests(rustsecp256k1zkp_v0_8_0_scratch_space *scratch) { /** main test body **/ /** Key aggregation **/ - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(none, scratch, &agg_pk, &keyagg_cache, pk_ptr, 2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(sign, scratch, &agg_pk, &keyagg_cache, pk_ptr, 2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(vrfy, scratch, &agg_pk, &keyagg_cache, pk_ptr, 2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(CTX, scratch, &agg_pk, &keyagg_cache, pk_ptr, 2) == 1); /* pubkey_agg does not require a scratch space */ - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(vrfy, NULL, &agg_pk, &keyagg_cache, pk_ptr, 2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(CTX, NULL, &agg_pk, &keyagg_cache, pk_ptr, 2) == 1); /* A small scratch space works too, but will result in using an ineffecient algorithm */ - scratch_small = rustsecp256k1zkp_v0_8_0_scratch_space_create(ctx, 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(vrfy, scratch_small, &agg_pk, &keyagg_cache, pk_ptr, 2) == 1); - rustsecp256k1zkp_v0_8_0_scratch_space_destroy(ctx, scratch_small); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(vrfy, scratch, NULL, &keyagg_cache, pk_ptr, 2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(vrfy, scratch, &agg_pk, NULL, pk_ptr, 2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(vrfy, scratch, &agg_pk, &keyagg_cache, NULL, 2) == 0); - CHECK(ecount == 1); + scratch_small = rustsecp256k1zkp_v0_10_0_scratch_space_create(CTX, 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(CTX, scratch_small, &agg_pk, &keyagg_cache, pk_ptr, 2) == 1); + rustsecp256k1zkp_v0_10_0_scratch_space_destroy(CTX, scratch_small); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(CTX, scratch, NULL, &keyagg_cache, pk_ptr, 2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(CTX, scratch, &agg_pk, NULL, pk_ptr, 2) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(CTX, scratch, &agg_pk, &keyagg_cache, NULL, 2)); CHECK(memcmp_and_randomize(agg_pk.data, zeros132, sizeof(agg_pk.data)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(vrfy, scratch, &agg_pk, &keyagg_cache, invalid_pk_ptr2, 2) == 0); - CHECK(ecount == 2); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(CTX, scratch, &agg_pk, &keyagg_cache, invalid_pk_ptr2, 2)); CHECK(memcmp_and_randomize(agg_pk.data, zeros132, sizeof(agg_pk.data)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(vrfy, scratch, &agg_pk, &keyagg_cache, invalid_pk_ptr3, 3) == 0); - CHECK(ecount == 3); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(CTX, scratch, &agg_pk, &keyagg_cache, invalid_pk_ptr3, 3)); CHECK(memcmp_and_randomize(agg_pk.data, zeros132, sizeof(agg_pk.data)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(vrfy, scratch, &agg_pk, &keyagg_cache, pk_ptr, 0) == 0); - CHECK(ecount == 4); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(CTX, scratch, &agg_pk, &keyagg_cache, pk_ptr, 0)); CHECK(memcmp_and_randomize(agg_pk.data, zeros132, sizeof(agg_pk.data)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(vrfy, scratch, &agg_pk, &keyagg_cache, NULL, 0) == 0); - CHECK(ecount == 5); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(CTX, scratch, &agg_pk, &keyagg_cache, NULL, 0)); CHECK(memcmp_and_randomize(agg_pk.data, zeros132, sizeof(agg_pk.data)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(none, scratch, &agg_pk, &keyagg_cache, pk_ptr, 2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(sign, scratch, &agg_pk, &keyagg_cache, pk_ptr, 2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(vrfy, scratch, &agg_pk, &keyagg_cache, pk_ptr, 2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(CTX, scratch, &agg_pk, &keyagg_cache, pk_ptr, 2) == 1); /* pubkey_get */ - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_get(none, &full_agg_pk, &keyagg_cache) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_get(none, NULL, &keyagg_cache) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_get(none, &full_agg_pk, NULL) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&full_agg_pk, zeros132, sizeof(full_agg_pk)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubkey_get(CTX, &full_agg_pk, &keyagg_cache) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_pubkey_get(CTX, NULL, &keyagg_cache)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_pubkey_get(CTX, &full_agg_pk, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&full_agg_pk, zeros132, sizeof(full_agg_pk)) == 0); /** Tweaking **/ { - int (*tweak_func[2]) (const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pubkey *output_pubkey, rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache, const unsigned char *tweak32); - tweak_func[0] = rustsecp256k1zkp_v0_8_0_musig_pubkey_ec_tweak_add; - tweak_func[1] = rustsecp256k1zkp_v0_8_0_musig_pubkey_xonly_tweak_add; + int (*tweak_func[2]) (const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_pubkey *output_pubkey, rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache, const unsigned char *tweak32); + tweak_func[0] = rustsecp256k1zkp_v0_10_0_musig_pubkey_ec_tweak_add; + tweak_func[1] = rustsecp256k1zkp_v0_10_0_musig_pubkey_xonly_tweak_add; for (i = 0; i < 2; i++) { - rustsecp256k1zkp_v0_8_0_pubkey tmp_output_pk; - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache tmp_keyagg_cache = keyagg_cache; - ecount = 0; - CHECK((*tweak_func[i])(ctx, &tmp_output_pk, &tmp_keyagg_cache, tweak) == 1); + rustsecp256k1zkp_v0_10_0_pubkey tmp_output_pk; + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache tmp_keyagg_cache = keyagg_cache; + CHECK((*tweak_func[i])(CTX, &tmp_output_pk, &tmp_keyagg_cache, tweak) == 1); /* Reset keyagg_cache */ tmp_keyagg_cache = keyagg_cache; - CHECK((*tweak_func[i])(none, &tmp_output_pk, &tmp_keyagg_cache, tweak) == 1); - tmp_keyagg_cache = keyagg_cache; - CHECK((*tweak_func[i])(sign, &tmp_output_pk, &tmp_keyagg_cache, tweak) == 1); + CHECK((*tweak_func[i])(CTX, &tmp_output_pk, &tmp_keyagg_cache, tweak) == 1); tmp_keyagg_cache = keyagg_cache; - CHECK((*tweak_func[i])(vrfy, &tmp_output_pk, &tmp_keyagg_cache, tweak) == 1); + CHECK((*tweak_func[i])(CTX, NULL, &tmp_keyagg_cache, tweak) == 1); tmp_keyagg_cache = keyagg_cache; - CHECK((*tweak_func[i])(vrfy, NULL, &tmp_keyagg_cache, tweak) == 1); - tmp_keyagg_cache = keyagg_cache; - CHECK((*tweak_func[i])(vrfy, &tmp_output_pk, NULL, tweak) == 0); - CHECK(ecount == 1); + CHECK_ILLEGAL(CTX, (*tweak_func[i])(CTX, &tmp_output_pk, NULL, tweak)); CHECK(memcmp_and_randomize(tmp_output_pk.data, zeros132, sizeof(tmp_output_pk.data)) == 0); tmp_keyagg_cache = keyagg_cache; - CHECK((*tweak_func[i])(vrfy, &tmp_output_pk, &tmp_keyagg_cache, NULL) == 0); - CHECK(ecount == 2); + CHECK_ILLEGAL(CTX, (*tweak_func[i])(CTX, &tmp_output_pk, &tmp_keyagg_cache, NULL)); CHECK(memcmp_and_randomize(tmp_output_pk.data, zeros132, sizeof(tmp_output_pk.data)) == 0); tmp_keyagg_cache = keyagg_cache; - CHECK((*tweak_func[i])(vrfy, &tmp_output_pk, &tmp_keyagg_cache, max64) == 0); - CHECK(ecount == 2); + CHECK((*tweak_func[i])(CTX, &tmp_output_pk, &tmp_keyagg_cache, max64) == 0); CHECK(memcmp_and_randomize(tmp_output_pk.data, zeros132, sizeof(tmp_output_pk.data)) == 0); tmp_keyagg_cache = keyagg_cache; /* Uninitialized keyagg_cache */ - CHECK((*tweak_func[i])(vrfy, &tmp_output_pk, &invalid_keyagg_cache, tweak) == 0); - CHECK(ecount == 3); + CHECK_ILLEGAL(CTX, (*tweak_func[i])(CTX, &tmp_output_pk, &invalid_keyagg_cache, tweak)); CHECK(memcmp_and_randomize(tmp_output_pk.data, zeros132, sizeof(tmp_output_pk.data)) == 0); } } /** Session creation **/ - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(none, &secnonce[0], &pubnonce[0], session_id[0], sk[0], &pk[0], msg, &keyagg_cache, max64) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(vrfy, &secnonce[0], &pubnonce[0], session_id[0], sk[0], &pk[0], msg, &keyagg_cache, max64) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(sign, &secnonce[0], &pubnonce[0], session_id[0], sk[0], &pk[0], msg, &keyagg_cache, max64) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(sttc, &secnonce[0], &pubnonce[0], session_id[0], sk[0], &pk[0], msg, &keyagg_cache, max64) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(sign, NULL, &pubnonce[0], session_id[0], sk[0], &pk[0], msg, &keyagg_cache, max64) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(sign, &secnonce[0], NULL, session_id[0], sk[0], &pk[0], msg, &keyagg_cache, max64) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(sign, &secnonce[0], &pubnonce[0], NULL, sk[0], &pk[0], msg, &keyagg_cache, max64) == 0); - CHECK(ecount == 4); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce[0], &pubnonce[0], session_id[0], sk[0], &pk[0], msg, &keyagg_cache, max64) == 1); + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_gen(STATIC_CTX, &secnonce[0], &pubnonce[0], session_id[0], sk[0], &pk[0], msg, &keyagg_cache, max64)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, NULL, &pubnonce[0], session_id[0], sk[0], &pk[0], msg, &keyagg_cache, max64)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce[0], NULL, session_id[0], sk[0], &pk[0], msg, &keyagg_cache, max64)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce[0], &pubnonce[0], NULL, sk[0], &pk[0], msg, &keyagg_cache, max64)); CHECK(memcmp_and_randomize(secnonce[0].data, zeros132, sizeof(secnonce[0].data)) == 0); /* no seckey and session_id is 0 */ - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(sign, &secnonce[0], &pubnonce[0], zeros132, NULL, &pk[0], msg, &keyagg_cache, max64) == 0); - CHECK(ecount == 4); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce[0], &pubnonce[0], zeros132, NULL, &pk[0], msg, &keyagg_cache, max64) == 0); CHECK(memcmp_and_randomize(secnonce[0].data, zeros132, sizeof(secnonce[0].data)) == 0); /* session_id 0 is fine when a seckey is provided */ - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(sign, &secnonce[0], &pubnonce[0], zeros132, sk[0], &pk[0], msg, &keyagg_cache, max64) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(sign, &secnonce[0], &pubnonce[0], session_id[0], NULL, &pk[0], msg, &keyagg_cache, max64) == 1); - CHECK(ecount == 4); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce[0], &pubnonce[0], zeros132, sk[0], &pk[0], msg, &keyagg_cache, max64) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce[0], &pubnonce[0], session_id[0], NULL, &pk[0], msg, &keyagg_cache, max64) == 1); /* invalid seckey */ - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(sign, &secnonce[0], &pubnonce[0], session_id[0], max64, &pk[0], msg, &keyagg_cache, max64) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce[0], &pubnonce[0], session_id[0], max64, &pk[0], msg, &keyagg_cache, max64) == 0); CHECK(memcmp_and_randomize(secnonce[0].data, zeros132, sizeof(secnonce[0].data)) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(sign, &secnonce[0], &pubnonce[0], session_id[0], sk[0], NULL, msg, &keyagg_cache, max64) == 0); - CHECK(ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(sign, &secnonce[0], &pubnonce[0], session_id[0], sk[0], &invalid_pk, msg, &keyagg_cache, max64) == 0); - CHECK(ecount == 6); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(sign, &secnonce[0], &pubnonce[0], session_id[0], sk[0], &pk[0], NULL, &keyagg_cache, max64) == 1); - CHECK(ecount == 6); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(sign, &secnonce[0], &pubnonce[0], session_id[0], sk[0], &pk[0], msg, NULL, max64) == 1); - CHECK(ecount == 6); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(sign, &secnonce[0], &pubnonce[0], session_id[0], sk[0], &pk[0], msg, &invalid_keyagg_cache, max64) == 0); - CHECK(ecount == 7); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce[0], &pubnonce[0], session_id[0], sk[0], NULL, msg, &keyagg_cache, max64)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce[0], &pubnonce[0], session_id[0], sk[0], &invalid_pk, msg, &keyagg_cache, max64)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce[0], &pubnonce[0], session_id[0], sk[0], &pk[0], NULL, &keyagg_cache, max64) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce[0], &pubnonce[0], session_id[0], sk[0], &pk[0], msg, NULL, max64) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce[0], &pubnonce[0], session_id[0], sk[0], &pk[0], msg, &invalid_keyagg_cache, max64)); CHECK(memcmp_and_randomize(secnonce[0].data, zeros132, sizeof(secnonce[0].data)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(sign, &secnonce[0], &pubnonce[0], session_id[0], sk[0], &pk[0], msg, &keyagg_cache, NULL) == 1); - CHECK(ecount == 7); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce[0], &pubnonce[0], session_id[0], sk[0], &pk[0], msg, &keyagg_cache, NULL) == 1); /* Every in-argument except session_id and pubkey can be NULL */ - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(sign, &secnonce[0], &pubnonce[0], session_id[0], NULL, &pk[0], NULL, NULL, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(sign, &secnonce[1], &pubnonce[1], session_id[1], sk[1], &pk[1], NULL, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce[0], &pubnonce[0], session_id[0], NULL, &pk[0], NULL, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce[1], &pubnonce[1], session_id[1], sk[1], &pk[1], NULL, NULL, NULL) == 1); /** Serialize and parse public nonces **/ - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubnonce_serialize(none, NULL, &pubnonce[0]) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubnonce_serialize(none, pubnonce_ser, NULL) == 0); - CHECK(ecount == 2); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_pubnonce_serialize(CTX, NULL, &pubnonce[0])); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_pubnonce_serialize(CTX, pubnonce_ser, NULL)); CHECK(memcmp_and_randomize(pubnonce_ser, zeros132, sizeof(pubnonce_ser)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubnonce_serialize(none, pubnonce_ser, &invalid_pubnonce) == 0); - CHECK(ecount == 3); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_pubnonce_serialize(CTX, pubnonce_ser, &invalid_pubnonce)); CHECK(memcmp_and_randomize(pubnonce_ser, zeros132, sizeof(pubnonce_ser)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubnonce_serialize(none, pubnonce_ser, &pubnonce[0]) == 1); - - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubnonce_parse(none, &pubnonce[0], pubnonce_ser) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubnonce_parse(none, NULL, pubnonce_ser) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubnonce_parse(none, &pubnonce[0], NULL) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubnonce_parse(none, &pubnonce[0], zeros132) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubnonce_parse(none, &pubnonce[0], pubnonce_ser) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubnonce_serialize(CTX, pubnonce_ser, &pubnonce[0]) == 1); + + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubnonce_parse(CTX, &pubnonce[0], pubnonce_ser) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_pubnonce_parse(CTX, NULL, pubnonce_ser)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_pubnonce_parse(CTX, &pubnonce[0], NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubnonce_parse(CTX, &pubnonce[0], zeros132) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubnonce_parse(CTX, &pubnonce[0], pubnonce_ser) == 1); { /* Check that serialize and parse results in the same value */ - rustsecp256k1zkp_v0_8_0_musig_pubnonce tmp; - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubnonce_serialize(none, pubnonce_ser, &pubnonce[0]) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubnonce_parse(none, &tmp, pubnonce_ser) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&tmp, &pubnonce[0], sizeof(tmp)) == 0); + rustsecp256k1zkp_v0_10_0_musig_pubnonce tmp; + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubnonce_serialize(CTX, pubnonce_ser, &pubnonce[0]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubnonce_parse(CTX, &tmp, pubnonce_ser) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&tmp, &pubnonce[0], sizeof(tmp)) == 0); } /** Receive nonces and aggregate **/ - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_agg(none, &aggnonce, pubnonce_ptr, 2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_agg(none, NULL, pubnonce_ptr, 2) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_agg(none, &aggnonce, NULL, 2) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_agg(none, &aggnonce, pubnonce_ptr, 0) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_agg(none, &aggnonce, invalid_pubnonce_ptr, 1) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_agg(none, &aggnonce, inf_pubnonce_ptr, 2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_agg(CTX, &aggnonce, pubnonce_ptr, 2) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_agg(CTX, NULL, pubnonce_ptr, 2)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_agg(CTX, &aggnonce, NULL, 2)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_agg(CTX, &aggnonce, pubnonce_ptr, 0)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_agg(CTX, &aggnonce, invalid_pubnonce_ptr, 1)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_agg(CTX, &aggnonce, inf_pubnonce_ptr, 2) == 1); { /* Check that the aggnonce encodes two points at infinity */ - rustsecp256k1zkp_v0_8_0_ge aggnonce_pt[2]; - rustsecp256k1zkp_v0_8_0_musig_aggnonce_load(ctx, aggnonce_pt, &aggnonce); + rustsecp256k1zkp_v0_10_0_ge aggnonce_pt[2]; + rustsecp256k1zkp_v0_10_0_musig_aggnonce_load(CTX, aggnonce_pt, &aggnonce); for (i = 0; i < 2; i++) { - rustsecp256k1zkp_v0_8_0_ge_is_infinity(&aggnonce_pt[i]); + rustsecp256k1zkp_v0_10_0_ge_is_infinity(&aggnonce_pt[i]); } } - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_agg(none, &aggnonce, pubnonce_ptr, 2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_agg(CTX, &aggnonce, pubnonce_ptr, 2) == 1); /** Serialize and parse aggregate nonces **/ - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_musig_aggnonce_serialize(none, aggnonce_ser, &aggnonce) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_aggnonce_serialize(none, NULL, &aggnonce) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_aggnonce_serialize(none, aggnonce_ser, NULL) == 0); - CHECK(ecount == 2); + CHECK(rustsecp256k1zkp_v0_10_0_musig_aggnonce_serialize(CTX, aggnonce_ser, &aggnonce) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_aggnonce_serialize(CTX, NULL, &aggnonce)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_aggnonce_serialize(CTX, aggnonce_ser, NULL)); CHECK(memcmp_and_randomize(aggnonce_ser, zeros132, sizeof(aggnonce_ser)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_musig_aggnonce_serialize(none, aggnonce_ser, (rustsecp256k1zkp_v0_8_0_musig_aggnonce*) &invalid_pubnonce) == 0); - CHECK(ecount == 3); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_aggnonce_serialize(CTX, aggnonce_ser, (rustsecp256k1zkp_v0_10_0_musig_aggnonce*) &invalid_pubnonce)); CHECK(memcmp_and_randomize(aggnonce_ser, zeros132, sizeof(aggnonce_ser)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_musig_aggnonce_serialize(none, aggnonce_ser, &aggnonce) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_aggnonce_serialize(CTX, aggnonce_ser, &aggnonce) == 1); - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_musig_aggnonce_parse(none, &aggnonce, aggnonce_ser) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_aggnonce_parse(none, NULL, aggnonce_ser) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_aggnonce_parse(none, &aggnonce, NULL) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_musig_aggnonce_parse(none, &aggnonce, zeros132) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_aggnonce_parse(none, &aggnonce, aggnonce_ser) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_aggnonce_parse(CTX, &aggnonce, aggnonce_ser) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_aggnonce_parse(CTX, NULL, aggnonce_ser)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_aggnonce_parse(CTX, &aggnonce, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_aggnonce_parse(CTX, &aggnonce, zeros132) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_aggnonce_parse(CTX, &aggnonce, aggnonce_ser) == 1); { /* Check that serialize and parse results in the same value */ - rustsecp256k1zkp_v0_8_0_musig_aggnonce tmp; - CHECK(rustsecp256k1zkp_v0_8_0_musig_aggnonce_serialize(none, aggnonce_ser, &aggnonce) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_aggnonce_parse(none, &tmp, aggnonce_ser) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&tmp, &aggnonce, sizeof(tmp)) == 0); + rustsecp256k1zkp_v0_10_0_musig_aggnonce tmp; + CHECK(rustsecp256k1zkp_v0_10_0_musig_aggnonce_serialize(CTX, aggnonce_ser, &aggnonce) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_aggnonce_parse(CTX, &tmp, aggnonce_ser) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&tmp, &aggnonce, sizeof(tmp)) == 0); } /** Process nonces **/ - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(none, &session, &aggnonce, msg, &keyagg_cache, &adaptor) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(sign, &session, &aggnonce, msg, &keyagg_cache, &adaptor) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(vrfy, NULL, &aggnonce, msg, &keyagg_cache, &adaptor) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(vrfy, &session, NULL, msg, &keyagg_cache, &adaptor) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(vrfy, &session, (rustsecp256k1zkp_v0_8_0_musig_aggnonce*) &invalid_pubnonce, msg, &keyagg_cache, &adaptor) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(vrfy, &session, &aggnonce, NULL, &keyagg_cache, &adaptor) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(vrfy, &session, &aggnonce, msg, NULL, &adaptor) == 0); - CHECK(ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(vrfy, &session, &aggnonce, msg, &invalid_keyagg_cache, &adaptor) == 0); - CHECK(ecount == 6); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(vrfy, &session, &aggnonce, msg, &keyagg_cache, NULL) == 1); - CHECK(ecount == 6); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(vrfy, &session, &aggnonce, msg, &keyagg_cache, (rustsecp256k1zkp_v0_8_0_pubkey *)&invalid_pk) == 0); - CHECK(ecount == 7); - - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(vrfy, &session, &aggnonce, msg, &keyagg_cache, &adaptor) == 1); - - ecount = 0; + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_process(CTX, &session, &aggnonce, msg, &keyagg_cache, &adaptor) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_process(CTX, NULL, &aggnonce, msg, &keyagg_cache, &adaptor)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_process(CTX, &session, NULL, msg, &keyagg_cache, &adaptor)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_process(CTX, &session, (rustsecp256k1zkp_v0_10_0_musig_aggnonce*) &invalid_pubnonce, msg, &keyagg_cache, &adaptor)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_process(CTX, &session, &aggnonce, NULL, &keyagg_cache, &adaptor)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_process(CTX, &session, &aggnonce, msg, NULL, &adaptor)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_process(CTX, &session, &aggnonce, msg, &invalid_keyagg_cache, &adaptor)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_process(CTX, &session, &aggnonce, msg, &keyagg_cache, NULL) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_process(CTX, &session, &aggnonce, msg, &keyagg_cache, (rustsecp256k1zkp_v0_10_0_pubkey *)&invalid_pk)); + + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_process(CTX, &session, &aggnonce, msg, &keyagg_cache, &adaptor) == 1); + memcpy(&secnonce_tmp, &secnonce[0], sizeof(secnonce_tmp)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(none, &partial_sig[0], &secnonce_tmp, &keypair[0], &keyagg_cache, &session) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig[0], &secnonce_tmp, &keypair[0], &keyagg_cache, &session) == 1); /* The secnonce is set to 0 and subsequent signing attempts fail */ - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&secnonce_tmp, zeros132, sizeof(secnonce_tmp)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(none, &partial_sig[0], &secnonce_tmp, &keypair[0], &keyagg_cache, &session) == 0); - CHECK(ecount == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&secnonce_tmp, zeros132, sizeof(secnonce_tmp)) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig[0], &secnonce_tmp, &keypair[0], &keyagg_cache, &session)); memcpy(&secnonce_tmp, &secnonce[0], sizeof(secnonce_tmp)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(none, NULL, &secnonce_tmp, &keypair[0], &keyagg_cache, &session) == 0); - CHECK(ecount == 2); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, NULL, &secnonce_tmp, &keypair[0], &keyagg_cache, &session)); memcpy(&secnonce_tmp, &secnonce[0], sizeof(secnonce_tmp)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(none, &partial_sig[0], NULL, &keypair[0], &keyagg_cache, &session) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(none, &partial_sig[0], &invalid_secnonce, &keypair[0], &keyagg_cache, &session) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(none, &partial_sig[0], &secnonce_tmp, NULL, &keyagg_cache, &session) == 0); - CHECK(ecount == 5); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig[0], NULL, &keypair[0], &keyagg_cache, &session)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig[0], &invalid_secnonce, &keypair[0], &keyagg_cache, &session)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig[0], &secnonce_tmp, NULL, &keyagg_cache, &session)); memcpy(&secnonce_tmp, &secnonce[0], sizeof(secnonce_tmp)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(none, &partial_sig[0], &secnonce_tmp, &invalid_keypair, &keyagg_cache, &session) == 0); - CHECK(ecount == 6); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig[0], &secnonce_tmp, &invalid_keypair, &keyagg_cache, &session)); memcpy(&secnonce_tmp, &secnonce[0], sizeof(secnonce_tmp)); { unsigned char sk_tmp[32]; - rustsecp256k1zkp_v0_8_0_keypair keypair_tmp; - rustsecp256k1zkp_v0_8_0_testrand256(sk_tmp); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair_tmp, sk_tmp)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(none, &partial_sig[0], &secnonce_tmp, &keypair_tmp, &keyagg_cache, &session) == 0); - CHECK(ecount == 7); + rustsecp256k1zkp_v0_10_0_keypair keypair_tmp; + rustsecp256k1zkp_v0_10_0_testrand256(sk_tmp); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair_tmp, sk_tmp)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig[0], &secnonce_tmp, &keypair_tmp, &keyagg_cache, &session)); memcpy(&secnonce_tmp, &secnonce[0], sizeof(secnonce_tmp)); } - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(none, &partial_sig[0], &secnonce_tmp, &keypair[0], NULL, &session) == 0); - CHECK(ecount == 8); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig[0], &secnonce_tmp, &keypair[0], NULL, &session)); memcpy(&secnonce_tmp, &secnonce[0], sizeof(secnonce_tmp)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(none, &partial_sig[0], &secnonce_tmp, &keypair[0], &invalid_keyagg_cache, &session) == 0); - CHECK(ecount == 9); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig[0], &secnonce_tmp, &keypair[0], &invalid_keyagg_cache, &session)); memcpy(&secnonce_tmp, &secnonce[0], sizeof(secnonce_tmp)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(none, &partial_sig[0], &secnonce_tmp, &keypair[0], &keyagg_cache, NULL) == 0); - CHECK(ecount == 10); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig[0], &secnonce_tmp, &keypair[0], &keyagg_cache, NULL)); memcpy(&secnonce_tmp, &secnonce[0], sizeof(secnonce_tmp)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(none, &partial_sig[0], &secnonce_tmp, &keypair[0], &keyagg_cache, &invalid_session) == 0); - CHECK(ecount == 11); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig[0], &secnonce_tmp, &keypair[0], &keyagg_cache, &invalid_session)); memcpy(&secnonce_tmp, &secnonce[0], sizeof(secnonce_tmp)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(none, &partial_sig[0], &secnonce[0], &keypair[0], &keyagg_cache, &session) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(none, &partial_sig[1], &secnonce[1], &keypair[1], &keyagg_cache, &session) == 1); - - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_serialize(none, buf, &partial_sig[0]) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_serialize(none, NULL, &partial_sig[0]) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_serialize(none, buf, NULL) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_parse(none, &partial_sig[0], buf) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_parse(none, NULL, buf) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_parse(none, &partial_sig[0], max64) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_parse(none, &partial_sig[0], NULL) == 0); - CHECK(ecount == 4); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig[0], &secnonce[0], &keypair[0], &keyagg_cache, &session) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig[1], &secnonce[1], &keypair[1], &keyagg_cache, &session) == 1); + + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_serialize(CTX, buf, &partial_sig[0]) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sig_serialize(CTX, NULL, &partial_sig[0])); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sig_serialize(CTX, buf, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_parse(CTX, &partial_sig[0], buf) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sig_parse(CTX, NULL, buf)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_parse(CTX, &partial_sig[0], max64) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sig_parse(CTX, &partial_sig[0], NULL)); { /* Check that serialize and parse results in the same value */ - rustsecp256k1zkp_v0_8_0_musig_partial_sig tmp; - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_serialize(none, buf, &partial_sig[0]) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_parse(none, &tmp, buf) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&tmp, &partial_sig[0], sizeof(tmp)) == 0); + rustsecp256k1zkp_v0_10_0_musig_partial_sig tmp; + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_serialize(CTX, buf, &partial_sig[0]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_parse(CTX, &tmp, buf) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&tmp, &partial_sig[0], sizeof(tmp)) == 0); } /** Partial signature verification */ - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(none, &partial_sig[0], &pubnonce[0], &pk[0], &keyagg_cache, &session) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(sign, &partial_sig[0], &pubnonce[0], &pk[0], &keyagg_cache, &session) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(vrfy, &partial_sig[0], &pubnonce[0], &pk[0], &keyagg_cache, &session) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(vrfy, &partial_sig[1], &pubnonce[0], &pk[0], &keyagg_cache, &session) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(vrfy, NULL, &pubnonce[0], &pk[0], &keyagg_cache, &session) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(vrfy, &invalid_partial_sig, &pubnonce[0], &pk[0], &keyagg_cache, &session) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(vrfy, &partial_sig[0], NULL, &pk[0], &keyagg_cache, &session) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(vrfy, &partial_sig[0], &invalid_pubnonce, &pk[0], &keyagg_cache, &session) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(vrfy, &partial_sig[0], &pubnonce[0], NULL, &keyagg_cache, &session) == 0); - CHECK(ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(vrfy, &partial_sig[0], &pubnonce[0], &invalid_pk, &keyagg_cache, &session) == 0); - CHECK(ecount == 6); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(vrfy, &partial_sig[0], &pubnonce[0], &pk[0], NULL, &session) == 0); - CHECK(ecount == 7); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(vrfy, &partial_sig[0], &pubnonce[0], &pk[0], &invalid_keyagg_cache, &session) == 0); - CHECK(ecount == 8); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(vrfy, &partial_sig[0], &pubnonce[0], &pk[0], &keyagg_cache, NULL) == 0); - CHECK(ecount == 9); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(vrfy, &partial_sig[0], &pubnonce[0], &pk[0], &keyagg_cache, &invalid_session) == 0); - CHECK(ecount == 10); - - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(vrfy, &partial_sig[0], &pubnonce[0], &pk[0], &keyagg_cache, &session) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(vrfy, &partial_sig[1], &pubnonce[1], &pk[1], &keyagg_cache, &session) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &partial_sig[0], &pubnonce[0], &pk[0], &keyagg_cache, &session) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &partial_sig[1], &pubnonce[0], &pk[0], &keyagg_cache, &session) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, NULL, &pubnonce[0], &pk[0], &keyagg_cache, &session)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &invalid_partial_sig, &pubnonce[0], &pk[0], &keyagg_cache, &session)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &partial_sig[0], NULL, &pk[0], &keyagg_cache, &session)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &partial_sig[0], &invalid_pubnonce, &pk[0], &keyagg_cache, &session)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &partial_sig[0], &pubnonce[0], NULL, &keyagg_cache, &session)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &partial_sig[0], &pubnonce[0], &invalid_pk, &keyagg_cache, &session)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &partial_sig[0], &pubnonce[0], &pk[0], NULL, &session)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &partial_sig[0], &pubnonce[0], &pk[0], &invalid_keyagg_cache, &session)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &partial_sig[0], &pubnonce[0], &pk[0], &keyagg_cache, NULL)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &partial_sig[0], &pubnonce[0], &pk[0], &keyagg_cache, &invalid_session)); + + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &partial_sig[0], &pubnonce[0], &pk[0], &keyagg_cache, &session) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &partial_sig[1], &pubnonce[1], &pk[1], &keyagg_cache, &session) == 1); /** Signature aggregation and verification */ - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg(none, pre_sig, &session, partial_sig_ptr, 2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg(none, NULL, &session, partial_sig_ptr, 2) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg(none, pre_sig, NULL, partial_sig_ptr, 2) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg(none, pre_sig, &invalid_session, partial_sig_ptr, 2) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg(none, pre_sig, &session, NULL, 2) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg(none, pre_sig, &session, invalid_partial_sig_ptr, 2) == 0); - CHECK(ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg(none, pre_sig, &session, partial_sig_ptr, 0) == 0); - CHECK(ecount == 6); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg(none, pre_sig, &session, partial_sig_ptr, 1) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg(none, pre_sig, &session, partial_sig_ptr, 2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_agg(CTX, pre_sig, &session, partial_sig_ptr, 2) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sig_agg(CTX, NULL, &session, partial_sig_ptr, 2)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sig_agg(CTX, pre_sig, NULL, partial_sig_ptr, 2)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sig_agg(CTX, pre_sig, &invalid_session, partial_sig_ptr, 2)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sig_agg(CTX, pre_sig, &session, NULL, 2)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sig_agg(CTX, pre_sig, &session, invalid_partial_sig_ptr, 2)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sig_agg(CTX, pre_sig, &session, partial_sig_ptr, 0)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_agg(CTX, pre_sig, &session, partial_sig_ptr, 1) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_agg(CTX, pre_sig, &session, partial_sig_ptr, 2) == 1); /** Adaptor signature verification */ - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_parity(none, &nonce_parity, &session) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_parity(none, NULL, &session) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_parity(none, &nonce_parity, NULL) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_parity(none, &nonce_parity, &invalid_session) == 0); - CHECK(ecount == 3); - - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_musig_adapt(none, final_sig, pre_sig, sec_adaptor, nonce_parity) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_adapt(none, NULL, pre_sig, sec_adaptor, 0) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_adapt(none, final_sig, NULL, sec_adaptor, 0) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_musig_adapt(none, final_sig, max64, sec_adaptor, 0) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_musig_adapt(none, final_sig, pre_sig, NULL, 0) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_musig_adapt(none, final_sig, pre_sig, max64, 0) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_musig_adapt(none, final_sig, pre_sig, sec_adaptor, 2) == 0); - CHECK(ecount == 4); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_parity(CTX, &nonce_parity, &session) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_parity(CTX, NULL, &session)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_parity(CTX, &nonce_parity, NULL)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_nonce_parity(CTX, &nonce_parity, &invalid_session)); + + CHECK(rustsecp256k1zkp_v0_10_0_musig_adapt(CTX, final_sig, pre_sig, sec_adaptor, nonce_parity) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_adapt(CTX, NULL, pre_sig, sec_adaptor, 0)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_adapt(CTX, final_sig, NULL, sec_adaptor, 0)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_adapt(CTX, final_sig, max64, sec_adaptor, 0) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_adapt(CTX, final_sig, pre_sig, NULL, 0)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_adapt(CTX, final_sig, pre_sig, max64, 0) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_adapt(CTX, final_sig, pre_sig, sec_adaptor, 2)); /* sig and pre_sig argument point to the same location */ memcpy(final_sig, pre_sig, sizeof(final_sig)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_adapt(none, final_sig, final_sig, sec_adaptor, nonce_parity) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(vrfy, final_sig, msg, sizeof(msg), &agg_pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_adapt(CTX, final_sig, final_sig, sec_adaptor, nonce_parity) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, final_sig, msg, sizeof(msg), &agg_pk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_adapt(none, final_sig, pre_sig, sec_adaptor, nonce_parity) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(vrfy, final_sig, msg, sizeof(msg), &agg_pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_adapt(CTX, final_sig, pre_sig, sec_adaptor, nonce_parity) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, final_sig, msg, sizeof(msg), &agg_pk) == 1); /** Secret adaptor can be extracted from signature */ - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_musig_extract_adaptor(none, sec_adaptor1, final_sig, pre_sig, nonce_parity) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(sec_adaptor, sec_adaptor1, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_musig_extract_adaptor(CTX, sec_adaptor1, final_sig, pre_sig, nonce_parity) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(sec_adaptor, sec_adaptor1, 32) == 0); /* wrong nonce parity */ - CHECK(rustsecp256k1zkp_v0_8_0_musig_extract_adaptor(none, sec_adaptor1, final_sig, pre_sig, !nonce_parity) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(sec_adaptor, sec_adaptor1, 32) != 0); - CHECK(rustsecp256k1zkp_v0_8_0_musig_extract_adaptor(none, NULL, final_sig, pre_sig, 0) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_extract_adaptor(none, sec_adaptor1, NULL, pre_sig, 0) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_musig_extract_adaptor(none, sec_adaptor1, max64, pre_sig, 0) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_musig_extract_adaptor(none, sec_adaptor1, final_sig, NULL, 0) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_musig_extract_adaptor(none, sec_adaptor1, final_sig, max64, 0) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_musig_extract_adaptor(none, sec_adaptor1, final_sig, pre_sig, 2) == 0); - CHECK(ecount == 4); - - /** cleanup **/ - rustsecp256k1zkp_v0_8_0_context_destroy(none); - rustsecp256k1zkp_v0_8_0_context_destroy(sign); - rustsecp256k1zkp_v0_8_0_context_destroy(vrfy); - rustsecp256k1zkp_v0_8_0_context_destroy(sttc); + CHECK(rustsecp256k1zkp_v0_10_0_musig_extract_adaptor(CTX, sec_adaptor1, final_sig, pre_sig, !nonce_parity) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(sec_adaptor, sec_adaptor1, 32) != 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_extract_adaptor(CTX, NULL, final_sig, pre_sig, 0)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_extract_adaptor(CTX, sec_adaptor1, NULL, pre_sig, 0)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_extract_adaptor(CTX, sec_adaptor1, max64, pre_sig, 0) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_extract_adaptor(CTX, sec_adaptor1, final_sig, NULL, 0)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_extract_adaptor(CTX, sec_adaptor1, final_sig, max64, 0) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_extract_adaptor(CTX, sec_adaptor1, final_sig, pre_sig, 2)); } -void musig_nonce_bitflip(unsigned char **args, size_t n_flip, size_t n_bytes) { - rustsecp256k1zkp_v0_8_0_scalar k1[2], k2[2]; +static void musig_nonce_bitflip(unsigned char **args, size_t n_flip, size_t n_bytes) { + rustsecp256k1zkp_v0_10_0_scalar k1[2], k2[2]; - rustsecp256k1zkp_v0_8_0_nonce_function_musig(k1, args[0], args[1], args[2], args[3], args[4], args[5]); - rustsecp256k1zkp_v0_8_0_testrand_flip(args[n_flip], n_bytes); - rustsecp256k1zkp_v0_8_0_nonce_function_musig(k2, args[0], args[1], args[2], args[3], args[4], args[5]); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&k1[0], &k2[0]) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&k1[1], &k2[1]) == 0); + rustsecp256k1zkp_v0_10_0_nonce_function_musig(k1, args[0], args[1], args[2], args[3], args[4], args[5]); + rustsecp256k1zkp_v0_10_0_testrand_flip(args[n_flip], n_bytes); + rustsecp256k1zkp_v0_10_0_nonce_function_musig(k2, args[0], args[1], args[2], args[3], args[4], args[5]); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&k1[0], &k2[0]) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&k1[1], &k2[1]) == 0); } -void musig_nonce_test(void) { +static void musig_nonce_test(void) { unsigned char *args[6]; unsigned char session_id[32]; unsigned char sk[32]; @@ -639,14 +492,14 @@ void musig_nonce_test(void) { unsigned char agg_pk[32]; unsigned char extra_input[32]; int i, j; - rustsecp256k1zkp_v0_8_0_scalar k[6][2]; + rustsecp256k1zkp_v0_10_0_scalar k[6][2]; - rustsecp256k1zkp_v0_8_0_testrand_bytes_test(session_id, sizeof(session_id)); - rustsecp256k1zkp_v0_8_0_testrand_bytes_test(sk, sizeof(sk)); - rustsecp256k1zkp_v0_8_0_testrand_bytes_test(pk, sizeof(pk)); - rustsecp256k1zkp_v0_8_0_testrand_bytes_test(msg, sizeof(msg)); - rustsecp256k1zkp_v0_8_0_testrand_bytes_test(agg_pk, sizeof(agg_pk)); - rustsecp256k1zkp_v0_8_0_testrand_bytes_test(extra_input, sizeof(extra_input)); + rustsecp256k1zkp_v0_10_0_testrand_bytes_test(session_id, sizeof(session_id)); + rustsecp256k1zkp_v0_10_0_testrand_bytes_test(sk, sizeof(sk)); + rustsecp256k1zkp_v0_10_0_testrand_bytes_test(pk, sizeof(pk)); + rustsecp256k1zkp_v0_10_0_testrand_bytes_test(msg, sizeof(msg)); + rustsecp256k1zkp_v0_10_0_testrand_bytes_test(agg_pk, sizeof(agg_pk)); + rustsecp256k1zkp_v0_10_0_testrand_bytes_test(extra_input, sizeof(extra_input)); /* Check that a bitflip in an argument results in different nonces. */ args[0] = session_id; @@ -655,7 +508,7 @@ void musig_nonce_test(void) { args[3] = pk; args[4] = agg_pk; args[5] = extra_input; - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { musig_nonce_bitflip(args, 0, sizeof(session_id)); musig_nonce_bitflip(args, 1, sizeof(msg)); musig_nonce_bitflip(args, 2, sizeof(sk)); @@ -670,22 +523,22 @@ void musig_nonce_test(void) { memcpy(pk, session_id, sizeof(session_id)); memcpy(agg_pk, session_id, sizeof(agg_pk)); memcpy(extra_input, session_id, sizeof(extra_input)); - rustsecp256k1zkp_v0_8_0_nonce_function_musig(k[0], args[0], args[1], args[2], args[3], args[4], args[5]); - rustsecp256k1zkp_v0_8_0_nonce_function_musig(k[1], args[0], NULL, args[2], args[3], args[4], args[5]); - rustsecp256k1zkp_v0_8_0_nonce_function_musig(k[2], args[0], args[1], NULL, args[3], args[4], args[5]); - rustsecp256k1zkp_v0_8_0_nonce_function_musig(k[3], args[0], args[1], args[2], NULL, args[4], args[5]); - rustsecp256k1zkp_v0_8_0_nonce_function_musig(k[4], args[0], args[1], args[2], args[3], NULL, args[5]); - rustsecp256k1zkp_v0_8_0_nonce_function_musig(k[5], args[0], args[1], args[2], args[3], args[4], NULL); + rustsecp256k1zkp_v0_10_0_nonce_function_musig(k[0], args[0], args[1], args[2], args[3], args[4], args[5]); + rustsecp256k1zkp_v0_10_0_nonce_function_musig(k[1], args[0], NULL, args[2], args[3], args[4], args[5]); + rustsecp256k1zkp_v0_10_0_nonce_function_musig(k[2], args[0], args[1], NULL, args[3], args[4], args[5]); + rustsecp256k1zkp_v0_10_0_nonce_function_musig(k[3], args[0], args[1], args[2], NULL, args[4], args[5]); + rustsecp256k1zkp_v0_10_0_nonce_function_musig(k[4], args[0], args[1], args[2], args[3], NULL, args[5]); + rustsecp256k1zkp_v0_10_0_nonce_function_musig(k[5], args[0], args[1], args[2], args[3], args[4], NULL); for (i = 0; i < 6; i++) { - CHECK(!rustsecp256k1zkp_v0_8_0_scalar_eq(&k[i][0], &k[i][1])); + CHECK(!rustsecp256k1zkp_v0_10_0_scalar_eq(&k[i][0], &k[i][1])); for (j = i+1; j < 6; j++) { - CHECK(!rustsecp256k1zkp_v0_8_0_scalar_eq(&k[i][0], &k[j][0])); - CHECK(!rustsecp256k1zkp_v0_8_0_scalar_eq(&k[i][1], &k[j][1])); + CHECK(!rustsecp256k1zkp_v0_10_0_scalar_eq(&k[i][0], &k[j][0])); + CHECK(!rustsecp256k1zkp_v0_10_0_scalar_eq(&k[i][1], &k[j][1])); } } } -void scriptless_atomic_swap(rustsecp256k1zkp_v0_8_0_scratch_space *scratch) { +static void scriptless_atomic_swap(rustsecp256k1zkp_v0_10_0_scratch_space *scratch) { /* Throughout this test "a" and "b" refer to two hypothetical blockchains, * while the indices 0 and 1 refer to the two signers. Here signer 0 is * sending a-coins to signer 1, while signer 1 is sending b-coins to signer @@ -694,34 +547,34 @@ void scriptless_atomic_swap(rustsecp256k1zkp_v0_8_0_scratch_space *scratch) { unsigned char final_sig_a[64]; unsigned char pre_sig_b[64]; unsigned char final_sig_b[64]; - rustsecp256k1zkp_v0_8_0_musig_partial_sig partial_sig_a[2]; - const rustsecp256k1zkp_v0_8_0_musig_partial_sig *partial_sig_a_ptr[2]; - rustsecp256k1zkp_v0_8_0_musig_partial_sig partial_sig_b[2]; - const rustsecp256k1zkp_v0_8_0_musig_partial_sig *partial_sig_b_ptr[2]; + rustsecp256k1zkp_v0_10_0_musig_partial_sig partial_sig_a[2]; + const rustsecp256k1zkp_v0_10_0_musig_partial_sig *partial_sig_a_ptr[2]; + rustsecp256k1zkp_v0_10_0_musig_partial_sig partial_sig_b[2]; + const rustsecp256k1zkp_v0_10_0_musig_partial_sig *partial_sig_b_ptr[2]; unsigned char sec_adaptor[32]; unsigned char sec_adaptor_extracted[32]; - rustsecp256k1zkp_v0_8_0_pubkey pub_adaptor; + rustsecp256k1zkp_v0_10_0_pubkey pub_adaptor; unsigned char sk_a[2][32]; unsigned char sk_b[2][32]; - rustsecp256k1zkp_v0_8_0_keypair keypair_a[2]; - rustsecp256k1zkp_v0_8_0_keypair keypair_b[2]; - rustsecp256k1zkp_v0_8_0_pubkey pk_a[2]; - const rustsecp256k1zkp_v0_8_0_pubkey *pk_a_ptr[2]; - rustsecp256k1zkp_v0_8_0_pubkey pk_b[2]; - const rustsecp256k1zkp_v0_8_0_pubkey *pk_b_ptr[2]; - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache keyagg_cache_a; - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache keyagg_cache_b; - rustsecp256k1zkp_v0_8_0_xonly_pubkey agg_pk_a; - rustsecp256k1zkp_v0_8_0_xonly_pubkey agg_pk_b; - rustsecp256k1zkp_v0_8_0_musig_secnonce secnonce_a[2]; - rustsecp256k1zkp_v0_8_0_musig_secnonce secnonce_b[2]; - rustsecp256k1zkp_v0_8_0_musig_pubnonce pubnonce_a[2]; - rustsecp256k1zkp_v0_8_0_musig_pubnonce pubnonce_b[2]; - const rustsecp256k1zkp_v0_8_0_musig_pubnonce *pubnonce_ptr_a[2]; - const rustsecp256k1zkp_v0_8_0_musig_pubnonce *pubnonce_ptr_b[2]; - rustsecp256k1zkp_v0_8_0_musig_aggnonce aggnonce_a; - rustsecp256k1zkp_v0_8_0_musig_aggnonce aggnonce_b; - rustsecp256k1zkp_v0_8_0_musig_session session_a, session_b; + rustsecp256k1zkp_v0_10_0_keypair keypair_a[2]; + rustsecp256k1zkp_v0_10_0_keypair keypair_b[2]; + rustsecp256k1zkp_v0_10_0_pubkey pk_a[2]; + const rustsecp256k1zkp_v0_10_0_pubkey *pk_a_ptr[2]; + rustsecp256k1zkp_v0_10_0_pubkey pk_b[2]; + const rustsecp256k1zkp_v0_10_0_pubkey *pk_b_ptr[2]; + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache keyagg_cache_a; + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache keyagg_cache_b; + rustsecp256k1zkp_v0_10_0_xonly_pubkey agg_pk_a; + rustsecp256k1zkp_v0_10_0_xonly_pubkey agg_pk_b; + rustsecp256k1zkp_v0_10_0_musig_secnonce secnonce_a[2]; + rustsecp256k1zkp_v0_10_0_musig_secnonce secnonce_b[2]; + rustsecp256k1zkp_v0_10_0_musig_pubnonce pubnonce_a[2]; + rustsecp256k1zkp_v0_10_0_musig_pubnonce pubnonce_b[2]; + const rustsecp256k1zkp_v0_10_0_musig_pubnonce *pubnonce_ptr_a[2]; + const rustsecp256k1zkp_v0_10_0_musig_pubnonce *pubnonce_ptr_b[2]; + rustsecp256k1zkp_v0_10_0_musig_aggnonce aggnonce_a; + rustsecp256k1zkp_v0_10_0_musig_aggnonce aggnonce_b; + rustsecp256k1zkp_v0_10_0_musig_session session_a, session_b; int nonce_parity_a; int nonce_parity_b; unsigned char seed_a[2][32] = { "a0", "a1" }; @@ -739,71 +592,71 @@ void scriptless_atomic_swap(rustsecp256k1zkp_v0_8_0_scratch_space *scratch) { partial_sig_a_ptr[i] = &partial_sig_a[i]; partial_sig_b_ptr[i] = &partial_sig_b[i]; - rustsecp256k1zkp_v0_8_0_testrand256(sk_a[i]); - rustsecp256k1zkp_v0_8_0_testrand256(sk_b[i]); + rustsecp256k1zkp_v0_10_0_testrand256(sk_a[i]); + rustsecp256k1zkp_v0_10_0_testrand256(sk_b[i]); CHECK(create_keypair_and_pk(&keypair_a[i], &pk_a[i], sk_a[i]) == 1); CHECK(create_keypair_and_pk(&keypair_b[i], &pk_b[i], sk_b[i]) == 1); } - rustsecp256k1zkp_v0_8_0_testrand256(sec_adaptor); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pub_adaptor, sec_adaptor) == 1); + rustsecp256k1zkp_v0_10_0_testrand256(sec_adaptor); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pub_adaptor, sec_adaptor) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(ctx, scratch, &agg_pk_a, &keyagg_cache_a, pk_a_ptr, 2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(ctx, scratch, &agg_pk_b, &keyagg_cache_b, pk_b_ptr, 2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(CTX, scratch, &agg_pk_a, &keyagg_cache_a, pk_a_ptr, 2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(CTX, scratch, &agg_pk_b, &keyagg_cache_b, pk_b_ptr, 2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(ctx, &secnonce_a[0], &pubnonce_a[0], seed_a[0], sk_a[0], &pk_a[0], NULL, NULL, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(ctx, &secnonce_a[1], &pubnonce_a[1], seed_a[1], sk_a[1], &pk_a[1], NULL, NULL, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(ctx, &secnonce_b[0], &pubnonce_b[0], seed_b[0], sk_b[0], &pk_b[0], NULL, NULL, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(ctx, &secnonce_b[1], &pubnonce_b[1], seed_b[1], sk_b[1], &pk_b[1], NULL, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce_a[0], &pubnonce_a[0], seed_a[0], sk_a[0], &pk_a[0], NULL, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce_a[1], &pubnonce_a[1], seed_a[1], sk_a[1], &pk_a[1], NULL, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce_b[0], &pubnonce_b[0], seed_b[0], sk_b[0], &pk_b[0], NULL, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce_b[1], &pubnonce_b[1], seed_b[1], sk_b[1], &pk_b[1], NULL, NULL, NULL) == 1); /* Step 2: Exchange nonces */ - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_agg(ctx, &aggnonce_a, pubnonce_ptr_a, 2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(ctx, &session_a, &aggnonce_a, msg32_a, &keyagg_cache_a, &pub_adaptor) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_parity(ctx, &nonce_parity_a, &session_a) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_agg(ctx, &aggnonce_b, pubnonce_ptr_b, 2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(ctx, &session_b, &aggnonce_b, msg32_b, &keyagg_cache_b, &pub_adaptor) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_parity(ctx, &nonce_parity_b, &session_b) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_agg(CTX, &aggnonce_a, pubnonce_ptr_a, 2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_process(CTX, &session_a, &aggnonce_a, msg32_a, &keyagg_cache_a, &pub_adaptor) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_parity(CTX, &nonce_parity_a, &session_a) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_agg(CTX, &aggnonce_b, pubnonce_ptr_b, 2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_process(CTX, &session_b, &aggnonce_b, msg32_b, &keyagg_cache_b, &pub_adaptor) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_parity(CTX, &nonce_parity_b, &session_b) == 1); /* Step 3: Signer 0 produces partial signatures for both chains. */ - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(ctx, &partial_sig_a[0], &secnonce_a[0], &keypair_a[0], &keyagg_cache_a, &session_a) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(ctx, &partial_sig_b[0], &secnonce_b[0], &keypair_b[0], &keyagg_cache_b, &session_b) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig_a[0], &secnonce_a[0], &keypair_a[0], &keyagg_cache_a, &session_a) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig_b[0], &secnonce_b[0], &keypair_b[0], &keyagg_cache_b, &session_b) == 1); /* Step 4: Signer 1 receives partial signatures, verifies them and creates a * partial signature to send B-coins to signer 0. */ - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(ctx, &partial_sig_a[0], &pubnonce_a[0], &pk_a[0], &keyagg_cache_a, &session_a) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(ctx, &partial_sig_b[0], &pubnonce_b[0], &pk_b[0], &keyagg_cache_b, &session_b) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(ctx, &partial_sig_b[1], &secnonce_b[1], &keypair_b[1], &keyagg_cache_b, &session_b) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &partial_sig_a[0], &pubnonce_a[0], &pk_a[0], &keyagg_cache_a, &session_a) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &partial_sig_b[0], &pubnonce_b[0], &pk_b[0], &keyagg_cache_b, &session_b) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig_b[1], &secnonce_b[1], &keypair_b[1], &keyagg_cache_b, &session_b) == 1); /* Step 5: Signer 0 aggregates its own partial signature with the partial * signature from signer 1 and adapts it. This results in a complete * signature which is broadcasted by signer 0 to take B-coins. */ - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg(ctx, pre_sig_b, &session_b, partial_sig_b_ptr, 2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_adapt(ctx, final_sig_b, pre_sig_b, sec_adaptor, nonce_parity_b) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, final_sig_b, msg32_b, sizeof(msg32_b), &agg_pk_b) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_agg(CTX, pre_sig_b, &session_b, partial_sig_b_ptr, 2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_adapt(CTX, final_sig_b, pre_sig_b, sec_adaptor, nonce_parity_b) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, final_sig_b, msg32_b, sizeof(msg32_b), &agg_pk_b) == 1); /* Step 6: Signer 1 signs, extracts adaptor from the published signature, * and adapts the signature to take A-coins. */ - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(ctx, &partial_sig_a[1], &secnonce_a[1], &keypair_a[1], &keyagg_cache_a, &session_a) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg(ctx, pre_sig_a, &session_a, partial_sig_a_ptr, 2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_extract_adaptor(ctx, sec_adaptor_extracted, final_sig_b, pre_sig_b, nonce_parity_b) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(sec_adaptor_extracted, sec_adaptor, sizeof(sec_adaptor)) == 0); /* in real life we couldn't check this, of course */ - CHECK(rustsecp256k1zkp_v0_8_0_musig_adapt(ctx, final_sig_a, pre_sig_a, sec_adaptor_extracted, nonce_parity_a) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, final_sig_a, msg32_a, sizeof(msg32_a), &agg_pk_a) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig_a[1], &secnonce_a[1], &keypair_a[1], &keyagg_cache_a, &session_a) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_agg(CTX, pre_sig_a, &session_a, partial_sig_a_ptr, 2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_extract_adaptor(CTX, sec_adaptor_extracted, final_sig_b, pre_sig_b, nonce_parity_b) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(sec_adaptor_extracted, sec_adaptor, sizeof(sec_adaptor)) == 0); /* in real life we couldn't check this, of course */ + CHECK(rustsecp256k1zkp_v0_10_0_musig_adapt(CTX, final_sig_a, pre_sig_a, sec_adaptor_extracted, nonce_parity_a) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, final_sig_a, msg32_a, sizeof(msg32_a), &agg_pk_a) == 1); } -void sha256_tag_test_internal(rustsecp256k1zkp_v0_8_0_sha256 *sha_tagged, unsigned char *tag, size_t taglen) { - rustsecp256k1zkp_v0_8_0_sha256 sha; +static void sha256_tag_test_internal(rustsecp256k1zkp_v0_10_0_sha256 *sha_tagged, unsigned char *tag, size_t taglen) { + rustsecp256k1zkp_v0_10_0_sha256 sha; unsigned char buf[32]; unsigned char buf2[32]; size_t i; - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, tag, taglen); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, buf); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, tag, taglen); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, buf); /* buf = SHA256(tag) */ - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, buf, 32); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, buf, 32); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, buf, 32); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, buf, 32); /* Is buffer fully consumed? */ CHECK((sha.bytes & 0x3F) == 0); @@ -811,43 +664,43 @@ void sha256_tag_test_internal(rustsecp256k1zkp_v0_8_0_sha256 *sha_tagged, unsign for (i = 0; i < 8; i++) { CHECK(sha_tagged->s[i] == sha.s[i]); } - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, buf, 32); - rustsecp256k1zkp_v0_8_0_sha256_write(sha_tagged, buf, 32); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, buf); - rustsecp256k1zkp_v0_8_0_sha256_finalize(sha_tagged, buf2); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(buf, buf2, 32) == 0); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, buf, 32); + rustsecp256k1zkp_v0_10_0_sha256_write(sha_tagged, buf, 32); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, buf); + rustsecp256k1zkp_v0_10_0_sha256_finalize(sha_tagged, buf2); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(buf, buf2, 32) == 0); } /* Checks that the initialized tagged hashes initialized have the expected * state. */ -void sha256_tag_test(void) { - rustsecp256k1zkp_v0_8_0_sha256 sha_tagged; +static void sha256_tag_test(void) { + rustsecp256k1zkp_v0_10_0_sha256 sha_tagged; { char tag[11] = "KeyAgg list"; - rustsecp256k1zkp_v0_8_0_musig_keyagglist_sha256(&sha_tagged); + rustsecp256k1zkp_v0_10_0_musig_keyagglist_sha256(&sha_tagged); sha256_tag_test_internal(&sha_tagged, (unsigned char*)tag, sizeof(tag)); } { char tag[18] = "KeyAgg coefficient"; - rustsecp256k1zkp_v0_8_0_musig_keyaggcoef_sha256(&sha_tagged); + rustsecp256k1zkp_v0_10_0_musig_keyaggcoef_sha256(&sha_tagged); sha256_tag_test_internal(&sha_tagged, (unsigned char*)tag, sizeof(tag)); } } /* Attempts to create a signature for the aggregate public key using given secret * keys and keyagg_cache. */ -void musig_tweak_test_helper(const rustsecp256k1zkp_v0_8_0_xonly_pubkey* agg_pk, const unsigned char *sk0, const unsigned char *sk1, rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache) { - rustsecp256k1zkp_v0_8_0_pubkey pk[2]; +static void musig_tweak_test_helper(const rustsecp256k1zkp_v0_10_0_xonly_pubkey* agg_pk, const unsigned char *sk0, const unsigned char *sk1, rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache) { + rustsecp256k1zkp_v0_10_0_pubkey pk[2]; unsigned char session_id[2][32]; unsigned char msg[32]; - rustsecp256k1zkp_v0_8_0_musig_secnonce secnonce[2]; - rustsecp256k1zkp_v0_8_0_musig_pubnonce pubnonce[2]; - const rustsecp256k1zkp_v0_8_0_musig_pubnonce *pubnonce_ptr[2]; - rustsecp256k1zkp_v0_8_0_musig_aggnonce aggnonce; - rustsecp256k1zkp_v0_8_0_keypair keypair[2]; - rustsecp256k1zkp_v0_8_0_musig_session session; - rustsecp256k1zkp_v0_8_0_musig_partial_sig partial_sig[2]; - const rustsecp256k1zkp_v0_8_0_musig_partial_sig *partial_sig_ptr[2]; + rustsecp256k1zkp_v0_10_0_musig_secnonce secnonce[2]; + rustsecp256k1zkp_v0_10_0_musig_pubnonce pubnonce[2]; + const rustsecp256k1zkp_v0_10_0_musig_pubnonce *pubnonce_ptr[2]; + rustsecp256k1zkp_v0_10_0_musig_aggnonce aggnonce; + rustsecp256k1zkp_v0_10_0_keypair keypair[2]; + rustsecp256k1zkp_v0_10_0_musig_session session; + rustsecp256k1zkp_v0_10_0_musig_partial_sig partial_sig[2]; + const rustsecp256k1zkp_v0_10_0_musig_partial_sig *partial_sig_ptr[2]; unsigned char final_sig[64]; int i; @@ -855,50 +708,50 @@ void musig_tweak_test_helper(const rustsecp256k1zkp_v0_8_0_xonly_pubkey* agg_pk, pubnonce_ptr[i] = &pubnonce[i]; partial_sig_ptr[i] = &partial_sig[i]; - rustsecp256k1zkp_v0_8_0_testrand256(session_id[i]); + rustsecp256k1zkp_v0_10_0_testrand256(session_id[i]); } CHECK(create_keypair_and_pk(&keypair[0], &pk[0], sk0) == 1); CHECK(create_keypair_and_pk(&keypair[1], &pk[1], sk1) == 1); - rustsecp256k1zkp_v0_8_0_testrand256(msg); + rustsecp256k1zkp_v0_10_0_testrand256(msg); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(ctx, &secnonce[0], &pubnonce[0], session_id[0], sk0, &pk[0], NULL, NULL, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(ctx, &secnonce[1], &pubnonce[1], session_id[1], sk1, &pk[1], NULL, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce[0], &pubnonce[0], session_id[0], sk0, &pk[0], NULL, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce[1], &pubnonce[1], session_id[1], sk1, &pk[1], NULL, NULL, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_agg(ctx, &aggnonce, pubnonce_ptr, 2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(ctx, &session, &aggnonce, msg, keyagg_cache, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_agg(CTX, &aggnonce, pubnonce_ptr, 2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_process(CTX, &session, &aggnonce, msg, keyagg_cache, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(ctx, &partial_sig[0], &secnonce[0], &keypair[0], keyagg_cache, &session) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(ctx, &partial_sig[1], &secnonce[1], &keypair[1], keyagg_cache, &session) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig[0], &secnonce[0], &keypair[0], keyagg_cache, &session) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig[1], &secnonce[1], &keypair[1], keyagg_cache, &session) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(ctx, &partial_sig[0], &pubnonce[0], &pk[0], keyagg_cache, &session) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(ctx, &partial_sig[1], &pubnonce[1], &pk[1], keyagg_cache, &session) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &partial_sig[0], &pubnonce[0], &pk[0], keyagg_cache, &session) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &partial_sig[1], &pubnonce[1], &pk[1], keyagg_cache, &session) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg(ctx, final_sig, &session, partial_sig_ptr, 2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, final_sig, msg, sizeof(msg), agg_pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_agg(CTX, final_sig, &session, partial_sig_ptr, 2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, final_sig, msg, sizeof(msg), agg_pk) == 1); } /* Create aggregate public key P[0], tweak multiple times (using xonly and * plain tweaking) and test signing. */ -void musig_tweak_test(rustsecp256k1zkp_v0_8_0_scratch_space *scratch) { +static void musig_tweak_test(rustsecp256k1zkp_v0_10_0_scratch_space *scratch) { unsigned char sk[2][32]; - rustsecp256k1zkp_v0_8_0_pubkey pk[2]; - const rustsecp256k1zkp_v0_8_0_pubkey *pk_ptr[2]; - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache keyagg_cache; + rustsecp256k1zkp_v0_10_0_pubkey pk[2]; + const rustsecp256k1zkp_v0_10_0_pubkey *pk_ptr[2]; + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache keyagg_cache; enum { N_TWEAKS = 8 }; - rustsecp256k1zkp_v0_8_0_pubkey P[N_TWEAKS + 1]; - rustsecp256k1zkp_v0_8_0_xonly_pubkey P_xonly[N_TWEAKS + 1]; + rustsecp256k1zkp_v0_10_0_pubkey P[N_TWEAKS + 1]; + rustsecp256k1zkp_v0_10_0_xonly_pubkey P_xonly[N_TWEAKS + 1]; int i; /* Key Setup */ for (i = 0; i < 2; i++) { pk_ptr[i] = &pk[i]; - rustsecp256k1zkp_v0_8_0_testrand256(sk[i]); + rustsecp256k1zkp_v0_10_0_testrand256(sk[i]); CHECK(create_keypair_and_pk(NULL, &pk[i], sk[i]) == 1); } /* Compute P0 = keyagg(pk0, pk1) and test signing for it */ - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(ctx, scratch, &P_xonly[0], &keyagg_cache, pk_ptr, 2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(CTX, scratch, &P_xonly[0], &keyagg_cache, pk_ptr, 2) == 1); musig_tweak_test_helper(&P_xonly[0], sk[0], sk[1], &keyagg_cache); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_get(ctx, &P[0], &keyagg_cache)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubkey_get(CTX, &P[0], &keyagg_cache)); /* Compute Pi = f(Pj) + tweaki*G where where j = i-1 and try signing for * that key. If xonly is set to true, the function f is normalizes the input @@ -907,25 +760,25 @@ void musig_tweak_test(rustsecp256k1zkp_v0_8_0_scratch_space *scratch) { for (i = 1; i <= N_TWEAKS; i++) { unsigned char tweak[32]; int P_parity; - int xonly = rustsecp256k1zkp_v0_8_0_testrand_bits(1); + int xonly = rustsecp256k1zkp_v0_10_0_testrand_bits(1); - rustsecp256k1zkp_v0_8_0_testrand256(tweak); + rustsecp256k1zkp_v0_10_0_testrand256(tweak); if (xonly) { - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_xonly_tweak_add(ctx, &P[i], &keyagg_cache, tweak) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubkey_xonly_tweak_add(CTX, &P[i], &keyagg_cache, tweak) == 1); } else { - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_ec_tweak_add(ctx, &P[i], &keyagg_cache, tweak) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubkey_ec_tweak_add(CTX, &P[i], &keyagg_cache, tweak) == 1); } - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(ctx, &P_xonly[i], &P_parity, &P[i])); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(CTX, &P_xonly[i], &P_parity, &P[i])); /* Check that musig_pubkey_tweak_add produces same result as * xonly_pubkey_tweak_add or ec_pubkey_tweak_add. */ if (xonly) { unsigned char P_serialized[32]; - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(ctx, P_serialized, &P_xonly[i])); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add_check(ctx, P_serialized, P_parity, &P_xonly[i-1], tweak) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(CTX, P_serialized, &P_xonly[i])); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add_check(CTX, P_serialized, P_parity, &P_xonly[i-1], tweak) == 1); } else { - rustsecp256k1zkp_v0_8_0_pubkey tmp_key = P[i-1]; - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add(ctx, &tmp_key, tweak)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&tmp_key, &P[i], sizeof(tmp_key)) == 0); + rustsecp256k1zkp_v0_10_0_pubkey tmp_key = P[i-1]; + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add(CTX, &tmp_key, tweak)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&tmp_key, &P[i], sizeof(tmp_key)) == 0); } /* Test signing for P[i] */ musig_tweak_test_helper(&P_xonly[i], sk[0], sk[1], &keyagg_cache); @@ -933,7 +786,7 @@ void musig_tweak_test(rustsecp256k1zkp_v0_8_0_scratch_space *scratch) { } int musig_vectors_keyagg_and_tweak(enum MUSIG_ERROR *error, - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache, + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache, unsigned char *agg_pk_ser, const unsigned char pubkeys33[][33], const unsigned char tweaks32[][32], @@ -942,49 +795,49 @@ int musig_vectors_keyagg_and_tweak(enum MUSIG_ERROR *error, size_t tweak_indices_len, const size_t *tweak_indices, const int *is_xonly) { - rustsecp256k1zkp_v0_8_0_pubkey pubkeys[MUSIG_VECTORS_MAX_PUBKEYS]; - const rustsecp256k1zkp_v0_8_0_pubkey *pk_ptr[MUSIG_VECTORS_MAX_PUBKEYS]; + rustsecp256k1zkp_v0_10_0_pubkey pubkeys[MUSIG_VECTORS_MAX_PUBKEYS]; + const rustsecp256k1zkp_v0_10_0_pubkey *pk_ptr[MUSIG_VECTORS_MAX_PUBKEYS]; int i; - rustsecp256k1zkp_v0_8_0_pubkey agg_pk; - rustsecp256k1zkp_v0_8_0_xonly_pubkey agg_pk_xonly; + rustsecp256k1zkp_v0_10_0_pubkey agg_pk; + rustsecp256k1zkp_v0_10_0_xonly_pubkey agg_pk_xonly; for (i = 0; i < (int)key_indices_len; i++) { - if (!rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pubkeys[i], pubkeys33[key_indices[i]], 33)) { + if (!rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pubkeys[i], pubkeys33[key_indices[i]], 33)) { *error = MUSIG_PUBKEY; return 0; } pk_ptr[i] = &pubkeys[i]; } - if (!rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(ctx, NULL, NULL, keyagg_cache, pk_ptr, key_indices_len)) { + if (!rustsecp256k1zkp_v0_10_0_musig_pubkey_agg(CTX, NULL, NULL, keyagg_cache, pk_ptr, key_indices_len)) { *error = MUSIG_OTHER; return 0; } for (i = 0; i < (int)tweak_indices_len; i++) { if (is_xonly[i]) { - if (!rustsecp256k1zkp_v0_8_0_musig_pubkey_xonly_tweak_add(ctx, NULL, keyagg_cache, tweaks32[tweak_indices[i]])) { + if (!rustsecp256k1zkp_v0_10_0_musig_pubkey_xonly_tweak_add(CTX, NULL, keyagg_cache, tweaks32[tweak_indices[i]])) { *error = MUSIG_TWEAK; return 0; } } else { - if (!rustsecp256k1zkp_v0_8_0_musig_pubkey_ec_tweak_add(ctx, NULL, keyagg_cache, tweaks32[tweak_indices[i]])) { + if (!rustsecp256k1zkp_v0_10_0_musig_pubkey_ec_tweak_add(CTX, NULL, keyagg_cache, tweaks32[tweak_indices[i]])) { *error = MUSIG_TWEAK; return 0; } } } - if (!rustsecp256k1zkp_v0_8_0_musig_pubkey_get(ctx, &agg_pk, keyagg_cache)) { + if (!rustsecp256k1zkp_v0_10_0_musig_pubkey_get(CTX, &agg_pk, keyagg_cache)) { *error = MUSIG_OTHER; return 0; } - if (!rustsecp256k1zkp_v0_8_0_xonly_pubkey_from_pubkey(ctx, &agg_pk_xonly, NULL, &agg_pk)) { + if (!rustsecp256k1zkp_v0_10_0_xonly_pubkey_from_pubkey(CTX, &agg_pk_xonly, NULL, &agg_pk)) { *error = MUSIG_OTHER; return 0; } if (agg_pk_ser != NULL) { - if (!rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(ctx, agg_pk_ser, &agg_pk_xonly)) { + if (!rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(CTX, agg_pk_ser, &agg_pk_xonly)) { *error = MUSIG_OTHER; return 0; } @@ -993,44 +846,44 @@ int musig_vectors_keyagg_and_tweak(enum MUSIG_ERROR *error, return 1; } -void musig_test_vectors_keyagg(void) { +static void musig_test_vectors_keyagg(void) { size_t i; const struct musig_key_agg_vector *vector = &musig_key_agg_vector; for (i = 0; i < sizeof(vector->valid_case)/sizeof(vector->valid_case[0]); i++) { const struct musig_key_agg_valid_test_case *c = &vector->valid_case[i]; enum MUSIG_ERROR error; - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache keyagg_cache; + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache keyagg_cache; unsigned char agg_pk[32]; CHECK(musig_vectors_keyagg_and_tweak(&error, &keyagg_cache, agg_pk, vector->pubkeys, vector->tweaks, c->key_indices_len, c->key_indices, 0, NULL, NULL)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(agg_pk, c->expected, sizeof(agg_pk)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(agg_pk, c->expected, sizeof(agg_pk)) == 0); } for (i = 0; i < sizeof(vector->error_case)/sizeof(vector->error_case[0]); i++) { const struct musig_key_agg_error_test_case *c = &vector->error_case[i]; enum MUSIG_ERROR error; - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache keyagg_cache; + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache keyagg_cache; CHECK(!musig_vectors_keyagg_and_tweak(&error, &keyagg_cache, NULL, vector->pubkeys, vector->tweaks, c->key_indices_len, c->key_indices, c->tweak_indices_len, c->tweak_indices, c->is_xonly)); CHECK(c->error == error); } } -void musig_test_vectors_noncegen(void) { +static void musig_test_vectors_noncegen(void) { size_t i; const struct musig_nonce_gen_vector *vector = &musig_nonce_gen_vector; for (i = 0; i < sizeof(vector->test_case)/sizeof(vector->test_case[0]); i++) { const struct musig_nonce_gen_test_case *c = &vector->test_case[i]; - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache keyagg_cache; - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache *keyagg_cache_ptr = NULL; - rustsecp256k1zkp_v0_8_0_musig_secnonce secnonce; - rustsecp256k1zkp_v0_8_0_musig_pubnonce pubnonce; + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache keyagg_cache; + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache *keyagg_cache_ptr = NULL; + rustsecp256k1zkp_v0_10_0_musig_secnonce secnonce; + rustsecp256k1zkp_v0_10_0_musig_pubnonce pubnonce; const unsigned char *sk = NULL; const unsigned char *msg = NULL; const unsigned char *extra_in = NULL; - rustsecp256k1zkp_v0_8_0_pubkey pk; + rustsecp256k1zkp_v0_10_0_pubkey pk; unsigned char pubnonce66[66]; if (c->has_sk) { @@ -1038,12 +891,12 @@ void musig_test_vectors_noncegen(void) { } if (c->has_aggpk) { /* Create keyagg_cache from aggpk */ - rustsecp256k1zkp_v0_8_0_keyagg_cache_internal cache_i; - rustsecp256k1zkp_v0_8_0_xonly_pubkey aggpk; + rustsecp256k1zkp_v0_10_0_keyagg_cache_internal cache_i; + rustsecp256k1zkp_v0_10_0_xonly_pubkey aggpk; memset(&cache_i, 0, sizeof(cache_i)); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(ctx, &aggpk, c->aggpk)); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_load(ctx, &cache_i.pk, &aggpk)); - rustsecp256k1zkp_v0_8_0_keyagg_cache_save(&keyagg_cache, &cache_i); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(CTX, &aggpk, c->aggpk)); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_load(CTX, &cache_i.pk, &aggpk)); + rustsecp256k1zkp_v0_10_0_keyagg_cache_save(&keyagg_cache, &cache_i); keyagg_cache_ptr = &keyagg_cache; } if (c->has_msg) { @@ -1053,100 +906,100 @@ void musig_test_vectors_noncegen(void) { extra_in = c->extra_in; } - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pk, c->pk, sizeof(c->pk))); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_gen(ctx, &secnonce, &pubnonce, c->rand_, sk, &pk, msg, keyagg_cache_ptr, extra_in) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&secnonce.data[4], c->expected_secnonce, 2*32) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&secnonce.data[4+2*32], &pk, sizeof(pk)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pk, c->pk, sizeof(c->pk))); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_gen(CTX, &secnonce, &pubnonce, c->rand_, sk, &pk, msg, keyagg_cache_ptr, extra_in) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&secnonce.data[4], c->expected_secnonce, 2*32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&secnonce.data[4+2*32], &pk, sizeof(pk)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubnonce_serialize(ctx, pubnonce66, &pubnonce) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubnonce_serialize(CTX, pubnonce66, &pubnonce) == 1); CHECK(sizeof(c->expected_pubnonce) == sizeof(pubnonce66)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(pubnonce66, c->expected_pubnonce, sizeof(pubnonce66)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(pubnonce66, c->expected_pubnonce, sizeof(pubnonce66)) == 0); } } -void musig_test_vectors_nonceagg(void) { +static void musig_test_vectors_nonceagg(void) { size_t i; int j; const struct musig_nonce_agg_vector *vector = &musig_nonce_agg_vector; for (i = 0; i < sizeof(vector->valid_case)/sizeof(vector->valid_case[0]); i++) { const struct musig_nonce_agg_test_case *c = &vector->valid_case[i]; - rustsecp256k1zkp_v0_8_0_musig_pubnonce pubnonce[2]; - const rustsecp256k1zkp_v0_8_0_musig_pubnonce *pubnonce_ptr[2]; - rustsecp256k1zkp_v0_8_0_musig_aggnonce aggnonce; + rustsecp256k1zkp_v0_10_0_musig_pubnonce pubnonce[2]; + const rustsecp256k1zkp_v0_10_0_musig_pubnonce *pubnonce_ptr[2]; + rustsecp256k1zkp_v0_10_0_musig_aggnonce aggnonce; unsigned char aggnonce66[66]; for (j = 0; j < 2; j++) { - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubnonce_parse(ctx, &pubnonce[j], vector->pnonces[c->pnonce_indices[j]]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubnonce_parse(CTX, &pubnonce[j], vector->pnonces[c->pnonce_indices[j]]) == 1); pubnonce_ptr[j] = &pubnonce[j]; } - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_agg(ctx, &aggnonce, pubnonce_ptr, 2)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_aggnonce_serialize(ctx, aggnonce66, &aggnonce)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(aggnonce66, c->expected, 33) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_agg(CTX, &aggnonce, pubnonce_ptr, 2)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_aggnonce_serialize(CTX, aggnonce66, &aggnonce)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(aggnonce66, c->expected, 33) == 0); } for (i = 0; i < sizeof(vector->error_case)/sizeof(vector->error_case[0]); i++) { const struct musig_nonce_agg_test_case *c = &vector->error_case[i]; - rustsecp256k1zkp_v0_8_0_musig_pubnonce pubnonce[2]; + rustsecp256k1zkp_v0_10_0_musig_pubnonce pubnonce[2]; for (j = 0; j < 2; j++) { int expected = c->invalid_nonce_idx != j; - CHECK(expected == rustsecp256k1zkp_v0_8_0_musig_pubnonce_parse(ctx, &pubnonce[j], vector->pnonces[c->pnonce_indices[j]])); + CHECK(expected == rustsecp256k1zkp_v0_10_0_musig_pubnonce_parse(CTX, &pubnonce[j], vector->pnonces[c->pnonce_indices[j]])); } } } -void musig_test_set_secnonce(rustsecp256k1zkp_v0_8_0_musig_secnonce *secnonce, const unsigned char *secnonce64, const rustsecp256k1zkp_v0_8_0_pubkey *pubkey) { - rustsecp256k1zkp_v0_8_0_ge pk; - rustsecp256k1zkp_v0_8_0_scalar k[2]; +static void musig_test_set_secnonce(rustsecp256k1zkp_v0_10_0_musig_secnonce *secnonce, const unsigned char *secnonce64, const rustsecp256k1zkp_v0_10_0_pubkey *pubkey) { + rustsecp256k1zkp_v0_10_0_ge pk; + rustsecp256k1zkp_v0_10_0_scalar k[2]; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&k[0], &secnonce64[0], NULL); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&k[1], &secnonce64[32], NULL); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &pk, pubkey)); - rustsecp256k1zkp_v0_8_0_musig_secnonce_save(secnonce, k, &pk); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&k[0], &secnonce64[0], NULL); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&k[1], &secnonce64[32], NULL); + CHECK(rustsecp256k1zkp_v0_10_0_pubkey_load(CTX, &pk, pubkey)); + rustsecp256k1zkp_v0_10_0_musig_secnonce_save(secnonce, k, &pk); } -void musig_test_vectors_signverify(void) { +static void musig_test_vectors_signverify(void) { size_t i; const struct musig_sign_verify_vector *vector = &musig_sign_verify_vector; for (i = 0; i < sizeof(vector->valid_case)/sizeof(vector->valid_case[0]); i++) { const struct musig_valid_case *c = &vector->valid_case[i]; enum MUSIG_ERROR error; - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache keyagg_cache; - rustsecp256k1zkp_v0_8_0_pubkey pubkey; - rustsecp256k1zkp_v0_8_0_musig_pubnonce pubnonce; - rustsecp256k1zkp_v0_8_0_musig_aggnonce aggnonce; - rustsecp256k1zkp_v0_8_0_musig_session session; - rustsecp256k1zkp_v0_8_0_musig_partial_sig partial_sig; - rustsecp256k1zkp_v0_8_0_musig_secnonce secnonce; - rustsecp256k1zkp_v0_8_0_keypair keypair; + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache keyagg_cache; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_musig_pubnonce pubnonce; + rustsecp256k1zkp_v0_10_0_musig_aggnonce aggnonce; + rustsecp256k1zkp_v0_10_0_musig_session session; + rustsecp256k1zkp_v0_10_0_musig_partial_sig partial_sig; + rustsecp256k1zkp_v0_10_0_musig_secnonce secnonce; + rustsecp256k1zkp_v0_10_0_keypair keypair; unsigned char partial_sig32[32]; - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, vector->sk)); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, vector->sk)); CHECK(musig_vectors_keyagg_and_tweak(&error, &keyagg_cache, NULL, vector->pubkeys, NULL, c->key_indices_len, c->key_indices, 0, NULL, NULL)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_aggnonce_parse(ctx, &aggnonce, vector->aggnonces[c->aggnonce_index])); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(ctx, &session, &aggnonce, vector->msgs[c->msg_index], &keyagg_cache, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_aggnonce_parse(CTX, &aggnonce, vector->aggnonces[c->aggnonce_index])); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_process(CTX, &session, &aggnonce, vector->msgs[c->msg_index], &keyagg_cache, NULL)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pubkey, vector->pubkeys[0], sizeof(vector->pubkeys[0]))); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pubkey, vector->pubkeys[0], sizeof(vector->pubkeys[0]))); musig_test_set_secnonce(&secnonce, vector->secnonces[0], &pubkey); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(ctx, &partial_sig, &secnonce, &keypair, &keyagg_cache, &session)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_serialize(ctx, partial_sig32, &partial_sig)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(partial_sig32, c->expected, sizeof(partial_sig32)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig, &secnonce, &keypair, &keyagg_cache, &session)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_serialize(CTX, partial_sig32, &partial_sig)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(partial_sig32, c->expected, sizeof(partial_sig32)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubnonce_parse(ctx, &pubnonce, vector->pubnonces[0])); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(ctx, &partial_sig, &pubnonce, &pubkey, &keyagg_cache, &session)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubnonce_parse(CTX, &pubnonce, vector->pubnonces[0])); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &partial_sig, &pubnonce, &pubkey, &keyagg_cache, &session)); } for (i = 0; i < sizeof(vector->sign_error_case)/sizeof(vector->sign_error_case[0]); i++) { const struct musig_sign_error_case *c = &vector->sign_error_case[i]; enum MUSIG_ERROR error; - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache keyagg_cache; - rustsecp256k1zkp_v0_8_0_pubkey pubkey; - rustsecp256k1zkp_v0_8_0_musig_aggnonce aggnonce; - rustsecp256k1zkp_v0_8_0_musig_session session; - rustsecp256k1zkp_v0_8_0_musig_partial_sig partial_sig; - rustsecp256k1zkp_v0_8_0_musig_secnonce secnonce; - rustsecp256k1zkp_v0_8_0_keypair keypair; + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache keyagg_cache; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_musig_aggnonce aggnonce; + rustsecp256k1zkp_v0_10_0_musig_session session; + rustsecp256k1zkp_v0_10_0_musig_partial_sig partial_sig; + rustsecp256k1zkp_v0_10_0_musig_secnonce secnonce; + rustsecp256k1zkp_v0_10_0_keypair keypair; int expected; if (i == 0) { @@ -1162,67 +1015,60 @@ void musig_test_vectors_signverify(void) { } expected = c->error != MUSIG_AGGNONCE; - CHECK(expected == rustsecp256k1zkp_v0_8_0_musig_aggnonce_parse(ctx, &aggnonce, vector->aggnonces[c->aggnonce_index])); + CHECK(expected == rustsecp256k1zkp_v0_10_0_musig_aggnonce_parse(CTX, &aggnonce, vector->aggnonces[c->aggnonce_index])); if (!expected) { continue; } - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(ctx, &session, &aggnonce, vector->msgs[c->msg_index], &keyagg_cache, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_process(CTX, &session, &aggnonce, vector->msgs[c->msg_index], &keyagg_cache, NULL)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pubkey, vector->pubkeys[0], sizeof(vector->pubkeys[0]))); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pubkey, vector->pubkeys[0], sizeof(vector->pubkeys[0]))); musig_test_set_secnonce(&secnonce, vector->secnonces[c->secnonce_index], &pubkey); - { - /* In the last test vector we sign with an invalid secnonce, which - * triggers an illegal_callback. Hence, we need to use a custom - * context that does not abort in this case. */ - rustsecp256k1zkp_v0_8_0_context *ctx_tmp = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_NONE); - int32_t ecount = 0; - rustsecp256k1zkp_v0_8_0_context_set_error_callback(ctx_tmp, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(ctx_tmp, counting_illegal_callback_fn, &ecount); - expected = c->error != MUSIG_SECNONCE; - CHECK(expected == rustsecp256k1zkp_v0_8_0_musig_partial_sign(ctx_tmp, &partial_sig, &secnonce, &keypair, &keyagg_cache, &session)); - CHECK((!expected) == ecount); - rustsecp256k1zkp_v0_8_0_context_destroy(ctx_tmp); + expected = c->error != MUSIG_SECNONCE; + if (expected) { + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig, &secnonce, &keypair, &keyagg_cache, &session)); + } else { + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig, &secnonce, &keypair, &keyagg_cache, &session)); } } for (i = 0; i < sizeof(vector->verify_fail_case)/sizeof(vector->verify_fail_case[0]); i++) { const struct musig_verify_fail_error_case *c = &vector->verify_fail_case[i]; enum MUSIG_ERROR error; - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache keyagg_cache; - rustsecp256k1zkp_v0_8_0_musig_aggnonce aggnonce; - rustsecp256k1zkp_v0_8_0_musig_session session; - rustsecp256k1zkp_v0_8_0_musig_partial_sig partial_sig; + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache keyagg_cache; + rustsecp256k1zkp_v0_10_0_musig_aggnonce aggnonce; + rustsecp256k1zkp_v0_10_0_musig_session session; + rustsecp256k1zkp_v0_10_0_musig_partial_sig partial_sig; enum { NUM_PUBNONCES = 3 }; - rustsecp256k1zkp_v0_8_0_musig_pubnonce pubnonce[NUM_PUBNONCES]; - const rustsecp256k1zkp_v0_8_0_musig_pubnonce *pubnonce_ptr[NUM_PUBNONCES]; - rustsecp256k1zkp_v0_8_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_musig_pubnonce pubnonce[NUM_PUBNONCES]; + const rustsecp256k1zkp_v0_10_0_musig_pubnonce *pubnonce_ptr[NUM_PUBNONCES]; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; int expected; size_t j; CHECK(NUM_PUBNONCES <= c->nonce_indices_len); for (j = 0; j < c->nonce_indices_len; j++) { - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubnonce_parse(ctx, &pubnonce[j], vector->pubnonces[c->nonce_indices[j]])); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubnonce_parse(CTX, &pubnonce[j], vector->pubnonces[c->nonce_indices[j]])); pubnonce_ptr[j] = &pubnonce[j]; } CHECK(musig_vectors_keyagg_and_tweak(&error, &keyagg_cache, NULL, vector->pubkeys, NULL, c->key_indices_len, c->key_indices, 0, NULL, NULL)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_agg(ctx, &aggnonce, pubnonce_ptr, c->nonce_indices_len) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(ctx, &session, &aggnonce, vector->msgs[c->msg_index], &keyagg_cache, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_agg(CTX, &aggnonce, pubnonce_ptr, c->nonce_indices_len) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_process(CTX, &session, &aggnonce, vector->msgs[c->msg_index], &keyagg_cache, NULL)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pubkey, vector->pubkeys[c->signer_index], sizeof(vector->pubkeys[0]))); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pubkey, vector->pubkeys[c->signer_index], sizeof(vector->pubkeys[0]))); expected = c->error != MUSIG_SIG; - CHECK(expected == rustsecp256k1zkp_v0_8_0_musig_partial_sig_parse(ctx, &partial_sig, c->sig)); + CHECK(expected == rustsecp256k1zkp_v0_10_0_musig_partial_sig_parse(CTX, &partial_sig, c->sig)); if (!expected) { continue; } expected = c->error != MUSIG_SIG_VERIFY; - CHECK(expected == rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(ctx, &partial_sig, pubnonce, &pubkey, &keyagg_cache, &session)); + CHECK(expected == rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &partial_sig, pubnonce, &pubkey, &keyagg_cache, &session)); } for (i = 0; i < sizeof(vector->verify_error_case)/sizeof(vector->verify_error_case[0]); i++) { const struct musig_verify_fail_error_case *c = &vector->verify_error_case[i]; enum MUSIG_ERROR error; - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache keyagg_cache; - rustsecp256k1zkp_v0_8_0_musig_pubnonce pubnonce; + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache keyagg_cache; + rustsecp256k1zkp_v0_10_0_musig_pubnonce pubnonce; int expected; expected = c->error != MUSIG_PUBKEY; @@ -1232,54 +1078,54 @@ void musig_test_vectors_signverify(void) { continue; } expected = c->error != MUSIG_PUBNONCE; - CHECK(expected == rustsecp256k1zkp_v0_8_0_musig_pubnonce_parse(ctx, &pubnonce, vector->pubnonces[c->nonce_indices[c->signer_index]])); + CHECK(expected == rustsecp256k1zkp_v0_10_0_musig_pubnonce_parse(CTX, &pubnonce, vector->pubnonces[c->nonce_indices[c->signer_index]])); } } -void musig_test_vectors_tweak(void) { +static void musig_test_vectors_tweak(void) { size_t i; const struct musig_tweak_vector *vector = &musig_tweak_vector; - rustsecp256k1zkp_v0_8_0_pubkey pubkey; - rustsecp256k1zkp_v0_8_0_musig_aggnonce aggnonce; - rustsecp256k1zkp_v0_8_0_musig_secnonce secnonce; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_musig_aggnonce aggnonce; + rustsecp256k1zkp_v0_10_0_musig_secnonce secnonce; - CHECK(rustsecp256k1zkp_v0_8_0_musig_aggnonce_parse(ctx, &aggnonce, vector->aggnonce)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pubkey, vector->pubkeys[0], sizeof(vector->pubkeys[0]))); + CHECK(rustsecp256k1zkp_v0_10_0_musig_aggnonce_parse(CTX, &aggnonce, vector->aggnonce)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pubkey, vector->pubkeys[0], sizeof(vector->pubkeys[0]))); for (i = 0; i < sizeof(vector->valid_case)/sizeof(vector->valid_case[0]); i++) { const struct musig_tweak_case *c = &vector->valid_case[i]; enum MUSIG_ERROR error; - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache keyagg_cache; - rustsecp256k1zkp_v0_8_0_musig_pubnonce pubnonce; - rustsecp256k1zkp_v0_8_0_musig_session session; - rustsecp256k1zkp_v0_8_0_musig_partial_sig partial_sig; - rustsecp256k1zkp_v0_8_0_keypair keypair; + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache keyagg_cache; + rustsecp256k1zkp_v0_10_0_musig_pubnonce pubnonce; + rustsecp256k1zkp_v0_10_0_musig_session session; + rustsecp256k1zkp_v0_10_0_musig_partial_sig partial_sig; + rustsecp256k1zkp_v0_10_0_keypair keypair; unsigned char partial_sig32[32]; musig_test_set_secnonce(&secnonce, vector->secnonce, &pubkey); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, vector->sk)); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, vector->sk)); CHECK(musig_vectors_keyagg_and_tweak(&error, &keyagg_cache, NULL, vector->pubkeys, vector->tweaks, c->key_indices_len, c->key_indices, c->tweak_indices_len, c->tweak_indices, c->is_xonly)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(ctx, &session, &aggnonce, vector->msg, &keyagg_cache, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_process(CTX, &session, &aggnonce, vector->msg, &keyagg_cache, NULL)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sign(ctx, &partial_sig, &secnonce, &keypair, &keyagg_cache, &session)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_serialize(ctx, partial_sig32, &partial_sig)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(partial_sig32, c->expected, sizeof(partial_sig32)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sign(CTX, &partial_sig, &secnonce, &keypair, &keyagg_cache, &session)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_serialize(CTX, partial_sig32, &partial_sig)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(partial_sig32, c->expected, sizeof(partial_sig32)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubnonce_parse(ctx, &pubnonce, vector->pubnonces[c->nonce_indices[c->signer_index]])); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_verify(ctx, &partial_sig, &pubnonce, &pubkey, &keyagg_cache, &session)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_pubnonce_parse(CTX, &pubnonce, vector->pubnonces[c->nonce_indices[c->signer_index]])); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_verify(CTX, &partial_sig, &pubnonce, &pubkey, &keyagg_cache, &session)); } for (i = 0; i < sizeof(vector->error_case)/sizeof(vector->error_case[0]); i++) { const struct musig_tweak_case *c = &vector->error_case[i]; enum MUSIG_ERROR error; - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache keyagg_cache; + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache keyagg_cache; CHECK(!musig_vectors_keyagg_and_tweak(&error, &keyagg_cache, NULL, vector->pubkeys, vector->tweaks, c->key_indices_len, c->key_indices, c->tweak_indices_len, c->tweak_indices, c->is_xonly)); CHECK(error == MUSIG_TWEAK); } } -void musig_test_vectors_sigagg(void) { +static void musig_test_vectors_sigagg(void) { size_t i, j; const struct musig_sig_agg_vector *vector = &musig_sig_agg_vector; @@ -1287,48 +1133,48 @@ void musig_test_vectors_sigagg(void) { const struct musig_sig_agg_case *c = &vector->valid_case[i]; enum MUSIG_ERROR error; unsigned char final_sig[64]; - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache keyagg_cache; + rustsecp256k1zkp_v0_10_0_musig_keyagg_cache keyagg_cache; unsigned char agg_pk32[32]; - rustsecp256k1zkp_v0_8_0_xonly_pubkey agg_pk; - rustsecp256k1zkp_v0_8_0_musig_aggnonce aggnonce; - rustsecp256k1zkp_v0_8_0_musig_session session; - rustsecp256k1zkp_v0_8_0_musig_partial_sig partial_sig[(sizeof(vector->psigs)/sizeof(vector->psigs[0]))]; - const rustsecp256k1zkp_v0_8_0_musig_partial_sig *partial_sig_ptr[(sizeof(vector->psigs)/sizeof(vector->psigs[0]))]; + rustsecp256k1zkp_v0_10_0_xonly_pubkey agg_pk; + rustsecp256k1zkp_v0_10_0_musig_aggnonce aggnonce; + rustsecp256k1zkp_v0_10_0_musig_session session; + rustsecp256k1zkp_v0_10_0_musig_partial_sig partial_sig[(sizeof(vector->psigs)/sizeof(vector->psigs[0]))]; + const rustsecp256k1zkp_v0_10_0_musig_partial_sig *partial_sig_ptr[(sizeof(vector->psigs)/sizeof(vector->psigs[0]))]; CHECK(musig_vectors_keyagg_and_tweak(&error, &keyagg_cache, agg_pk32, vector->pubkeys, vector->tweaks, c->key_indices_len, c->key_indices, c->tweak_indices_len, c->tweak_indices, c->is_xonly)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_aggnonce_parse(ctx, &aggnonce, c->aggnonce)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(ctx, &session, &aggnonce, vector->msg, &keyagg_cache, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_aggnonce_parse(CTX, &aggnonce, c->aggnonce)); + CHECK(rustsecp256k1zkp_v0_10_0_musig_nonce_process(CTX, &session, &aggnonce, vector->msg, &keyagg_cache, NULL)); for (j = 0; j < c->psig_indices_len; j++) { - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_parse(ctx, &partial_sig[j], vector->psigs[c->psig_indices[j]])); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_parse(CTX, &partial_sig[j], vector->psigs[c->psig_indices[j]])); partial_sig_ptr[j] = &partial_sig[j]; } - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg(ctx, final_sig, &session, partial_sig_ptr, c->psig_indices_len) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(final_sig, c->expected, sizeof(final_sig)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_musig_partial_sig_agg(CTX, final_sig, &session, partial_sig_ptr, c->psig_indices_len) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(final_sig, c->expected, sizeof(final_sig)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(ctx, &agg_pk, agg_pk32)); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, final_sig, vector->msg, sizeof(vector->msg), &agg_pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(CTX, &agg_pk, agg_pk32)); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, final_sig, vector->msg, sizeof(vector->msg), &agg_pk) == 1); } for (i = 0; i < sizeof(vector->error_case)/sizeof(vector->error_case[0]); i++) { const struct musig_sig_agg_case *c = &vector->error_case[i]; - rustsecp256k1zkp_v0_8_0_musig_partial_sig partial_sig[(sizeof(vector->psigs)/sizeof(vector->psigs[0]))]; + rustsecp256k1zkp_v0_10_0_musig_partial_sig partial_sig[(sizeof(vector->psigs)/sizeof(vector->psigs[0]))]; for (j = 0; j < c->psig_indices_len; j++) { int expected = c->invalid_sig_idx != (int)j; - CHECK(expected == rustsecp256k1zkp_v0_8_0_musig_partial_sig_parse(ctx, &partial_sig[j], vector->psigs[c->psig_indices[j]])); + CHECK(expected == rustsecp256k1zkp_v0_10_0_musig_partial_sig_parse(CTX, &partial_sig[j], vector->psigs[c->psig_indices[j]])); } } } -void run_musig_tests(void) { +static void run_musig_tests(void) { int i; - rustsecp256k1zkp_v0_8_0_scratch_space *scratch = rustsecp256k1zkp_v0_8_0_scratch_space_create(ctx, 1024 * 1024); + rustsecp256k1zkp_v0_10_0_scratch_space *scratch = rustsecp256k1zkp_v0_10_0_scratch_space_create(CTX, 1024 * 1024); - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { musig_simple_test(scratch); } musig_api_tests(scratch); musig_nonce_test(); - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { /* Run multiple times to ensure that pk and nonce have different y * parities */ scriptless_atomic_swap(scratch); @@ -1342,7 +1188,7 @@ void run_musig_tests(void) { musig_test_vectors_tweak(); musig_test_vectors_sigagg(); - rustsecp256k1zkp_v0_8_0_scratch_space_destroy(ctx, scratch); + rustsecp256k1zkp_v0_10_0_scratch_space_destroy(CTX, scratch); } #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/Makefile.am.include b/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/Makefile.am.include index 88892505..d40232db 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/Makefile.am.include +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/Makefile.am.include @@ -1,4 +1,4 @@ -include_HEADERS += include/rustsecp256k1zkp_v0_8_0_rangeproof.h +include_HEADERS += include/rustsecp256k1zkp_v0_10_0_rangeproof.h noinst_HEADERS += src/modules/rangeproof/main_impl.h noinst_HEADERS += src/modules/rangeproof/borromean.h noinst_HEADERS += src/modules/rangeproof/borromean_impl.h @@ -8,6 +8,6 @@ noinst_HEADERS += src/modules/rangeproof/tests_impl.h if USE_BENCHMARK noinst_PROGRAMS += bench_rangeproof bench_rangeproof_SOURCES = src/bench_rangeproof.c -bench_rangeproof_LDADD = libsecp256k1.la $(SECP_LIBS) -bench_rangeproof_LDFLAGS = -static +bench_rangeproof_LDADD = libsecp256k1.la +bench_rangeproof_CPPFLAGS = $(SECP_CONFIG_DEFINES) endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/borromean.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/borromean.h index df17168d..3228b0b6 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/borromean.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/borromean.h @@ -5,8 +5,8 @@ **********************************************************************/ -#ifndef _SECP256K1_BORROMEAN_H_ -#define _SECP256K1_BORROMEAN_H_ +#ifndef SECP256K1_BORROMEAN_H +#define SECP256K1_BORROMEAN_H #include "../../scalar.h" #include "../../field.h" @@ -14,11 +14,11 @@ #include "../../ecmult.h" #include "../../ecmult_gen.h" -int rustsecp256k1zkp_v0_8_0_borromean_verify(rustsecp256k1zkp_v0_8_0_scalar *evalues, const unsigned char *e0, const rustsecp256k1zkp_v0_8_0_scalar *s, - const rustsecp256k1zkp_v0_8_0_gej *pubs, const size_t *rsizes, size_t nrings, const unsigned char *m, size_t mlen); +static int rustsecp256k1zkp_v0_10_0_borromean_verify(rustsecp256k1zkp_v0_10_0_scalar *evalues, const unsigned char *e0, const rustsecp256k1zkp_v0_10_0_scalar *s, + const rustsecp256k1zkp_v0_10_0_gej *pubs, const size_t *rsizes, size_t nrings, const unsigned char *m, size_t mlen); -int rustsecp256k1zkp_v0_8_0_borromean_sign(const rustsecp256k1zkp_v0_8_0_ecmult_gen_context *ecmult_gen_ctx, - unsigned char *e0, rustsecp256k1zkp_v0_8_0_scalar *s, const rustsecp256k1zkp_v0_8_0_gej *pubs, const rustsecp256k1zkp_v0_8_0_scalar *k, const rustsecp256k1zkp_v0_8_0_scalar *sec, +static int rustsecp256k1zkp_v0_10_0_borromean_sign(const rustsecp256k1zkp_v0_10_0_ecmult_gen_context *ecmult_gen_ctx, + unsigned char *e0, rustsecp256k1zkp_v0_10_0_scalar *s, const rustsecp256k1zkp_v0_10_0_gej *pubs, const rustsecp256k1zkp_v0_10_0_scalar *k, const rustsecp256k1zkp_v0_10_0_scalar *sec, const size_t *rsizes, const size_t *secidx, size_t nrings, const unsigned char *m, size_t mlen); #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/borromean_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/borromean_impl.h index 1217646c..6e1d36ad 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/borromean_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/borromean_impl.h @@ -5,8 +5,8 @@ **********************************************************************/ -#ifndef _SECP256K1_BORROMEAN_IMPL_H_ -#define _SECP256K1_BORROMEAN_IMPL_H_ +#ifndef SECP256K1_BORROMEAN_IMPL_H +#define SECP256K1_BORROMEAN_IMPL_H #include "../../scalar.h" #include "../../field.h" @@ -20,25 +20,19 @@ #include #include -#if defined(SECP256K1_BIG_ENDIAN) -#define BE32(x) (x) -#elif defined(SECP256K1_LITTLE_ENDIAN) -#define BE32(p) ((((p) & 0xFF) << 24) | (((p) & 0xFF00) << 8) | (((p) & 0xFF0000) >> 8) | (((p) & 0xFF000000) >> 24)) -#endif - -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_borromean_hash(unsigned char *hash, const unsigned char *m, size_t mlen, const unsigned char *e, size_t elen, +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_borromean_hash(unsigned char *hash, const unsigned char *m, size_t mlen, const unsigned char *e, size_t elen, size_t ridx, size_t eidx) { - uint32_t ring; - uint32_t epos; - rustsecp256k1zkp_v0_8_0_sha256 sha256_en; - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha256_en); - ring = BE32((uint32_t)ridx); - epos = BE32((uint32_t)eidx); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_en, e, elen); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_en, m, mlen); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_en, (unsigned char*)&ring, 4); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_en, (unsigned char*)&epos, 4); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha256_en, hash); + unsigned char ring[4]; + unsigned char epos[4]; + rustsecp256k1zkp_v0_10_0_sha256 sha256_en; + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha256_en); + rustsecp256k1zkp_v0_10_0_write_be32(ring, (uint32_t)ridx); + rustsecp256k1zkp_v0_10_0_write_be32(epos, (uint32_t)eidx); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_en, e, elen); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_en, m, mlen); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_en, ring, 4); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_en, epos, 4); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha256_en, hash); } /** "Borromean" ring signature. @@ -55,12 +49,12 @@ SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_borromean_hash(unsigned cha * | | r_i = r * | return e_0 ==== H(r_{0..i}||m) */ -int rustsecp256k1zkp_v0_8_0_borromean_verify(rustsecp256k1zkp_v0_8_0_scalar *evalues, const unsigned char *e0, - const rustsecp256k1zkp_v0_8_0_scalar *s, const rustsecp256k1zkp_v0_8_0_gej *pubs, const size_t *rsizes, size_t nrings, const unsigned char *m, size_t mlen) { - rustsecp256k1zkp_v0_8_0_gej rgej; - rustsecp256k1zkp_v0_8_0_ge rge; - rustsecp256k1zkp_v0_8_0_scalar ens; - rustsecp256k1zkp_v0_8_0_sha256 sha256_e0; +int rustsecp256k1zkp_v0_10_0_borromean_verify(rustsecp256k1zkp_v0_10_0_scalar *evalues, const unsigned char *e0, + const rustsecp256k1zkp_v0_10_0_scalar *s, const rustsecp256k1zkp_v0_10_0_gej *pubs, const size_t *rsizes, size_t nrings, const unsigned char *m, size_t mlen) { + rustsecp256k1zkp_v0_10_0_gej rgej; + rustsecp256k1zkp_v0_10_0_ge rge; + rustsecp256k1zkp_v0_10_0_scalar ens; + rustsecp256k1zkp_v0_10_0_sha256 sha256_e0; unsigned char tmp[33]; size_t i; size_t j; @@ -74,47 +68,47 @@ int rustsecp256k1zkp_v0_8_0_borromean_verify(rustsecp256k1zkp_v0_8_0_scalar *eva VERIFY_CHECK(nrings > 0); VERIFY_CHECK(m != NULL); count = 0; - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha256_e0); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha256_e0); for (i = 0; i < nrings; i++) { VERIFY_CHECK(INT_MAX - count > rsizes[i]); - rustsecp256k1zkp_v0_8_0_borromean_hash(tmp, m, mlen, e0, 32, i, 0); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&ens, tmp, &overflow); + rustsecp256k1zkp_v0_10_0_borromean_hash(tmp, m, mlen, e0, 32, i, 0); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&ens, tmp, &overflow); for (j = 0; j < rsizes[i]; j++) { - if (overflow || rustsecp256k1zkp_v0_8_0_scalar_is_zero(&s[count]) || rustsecp256k1zkp_v0_8_0_scalar_is_zero(&ens) || rustsecp256k1zkp_v0_8_0_gej_is_infinity(&pubs[count])) { + if (overflow || rustsecp256k1zkp_v0_10_0_scalar_is_zero(&s[count]) || rustsecp256k1zkp_v0_10_0_scalar_is_zero(&ens) || rustsecp256k1zkp_v0_10_0_gej_is_infinity(&pubs[count])) { return 0; } if (evalues) { /*If requested, save the challenges for proof rewind.*/ evalues[count] = ens; } - rustsecp256k1zkp_v0_8_0_ecmult(&rgej, &pubs[count], &ens, &s[count]); - if (rustsecp256k1zkp_v0_8_0_gej_is_infinity(&rgej)) { + rustsecp256k1zkp_v0_10_0_ecmult(&rgej, &pubs[count], &ens, &s[count]); + if (rustsecp256k1zkp_v0_10_0_gej_is_infinity(&rgej)) { return 0; } /* OPT: loop can be hoisted and split to use batch inversion across all the rings; this would make it much faster. */ - rustsecp256k1zkp_v0_8_0_ge_set_gej_var(&rge, &rgej); - rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&rge, tmp, &size, 1); + rustsecp256k1zkp_v0_10_0_ge_set_gej_var(&rge, &rgej); + rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&rge, tmp, &size, 1); if (j != rsizes[i] - 1) { - rustsecp256k1zkp_v0_8_0_borromean_hash(tmp, m, mlen, tmp, 33, i, j + 1); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&ens, tmp, &overflow); + rustsecp256k1zkp_v0_10_0_borromean_hash(tmp, m, mlen, tmp, 33, i, j + 1); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&ens, tmp, &overflow); } else { - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_e0, tmp, size); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_e0, tmp, size); } count++; } } - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_e0, m, mlen); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha256_e0, tmp); - return rustsecp256k1zkp_v0_8_0_memcmp_var(e0, tmp, 32) == 0; + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_e0, m, mlen); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha256_e0, tmp); + return rustsecp256k1zkp_v0_10_0_memcmp_var(e0, tmp, 32) == 0; } -int rustsecp256k1zkp_v0_8_0_borromean_sign(const rustsecp256k1zkp_v0_8_0_ecmult_gen_context *ecmult_gen_ctx, - unsigned char *e0, rustsecp256k1zkp_v0_8_0_scalar *s, const rustsecp256k1zkp_v0_8_0_gej *pubs, const rustsecp256k1zkp_v0_8_0_scalar *k, const rustsecp256k1zkp_v0_8_0_scalar *sec, +int rustsecp256k1zkp_v0_10_0_borromean_sign(const rustsecp256k1zkp_v0_10_0_ecmult_gen_context *ecmult_gen_ctx, + unsigned char *e0, rustsecp256k1zkp_v0_10_0_scalar *s, const rustsecp256k1zkp_v0_10_0_gej *pubs, const rustsecp256k1zkp_v0_10_0_scalar *k, const rustsecp256k1zkp_v0_10_0_scalar *sec, const size_t *rsizes, const size_t *secidx, size_t nrings, const unsigned char *m, size_t mlen) { - rustsecp256k1zkp_v0_8_0_gej rgej; - rustsecp256k1zkp_v0_8_0_ge rge; - rustsecp256k1zkp_v0_8_0_scalar ens; - rustsecp256k1zkp_v0_8_0_sha256 sha256_e0; + rustsecp256k1zkp_v0_10_0_gej rgej; + rustsecp256k1zkp_v0_10_0_ge rge; + rustsecp256k1zkp_v0_10_0_scalar ens; + rustsecp256k1zkp_v0_10_0_sha256 sha256_e0; unsigned char tmp[33]; size_t i; size_t j; @@ -131,70 +125,70 @@ int rustsecp256k1zkp_v0_8_0_borromean_sign(const rustsecp256k1zkp_v0_8_0_ecmult_ VERIFY_CHECK(secidx != NULL); VERIFY_CHECK(nrings > 0); VERIFY_CHECK(m != NULL); - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha256_e0); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha256_e0); count = 0; for (i = 0; i < nrings; i++) { VERIFY_CHECK(INT_MAX - count > rsizes[i]); - rustsecp256k1zkp_v0_8_0_ecmult_gen(ecmult_gen_ctx, &rgej, &k[i]); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&rge, &rgej); - if (rustsecp256k1zkp_v0_8_0_gej_is_infinity(&rgej)) { + rustsecp256k1zkp_v0_10_0_ecmult_gen(ecmult_gen_ctx, &rgej, &k[i]); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&rge, &rgej); + if (rustsecp256k1zkp_v0_10_0_gej_is_infinity(&rgej)) { return 0; } - rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&rge, tmp, &size, 1); + rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&rge, tmp, &size, 1); for (j = secidx[i] + 1; j < rsizes[i]; j++) { - rustsecp256k1zkp_v0_8_0_borromean_hash(tmp, m, mlen, tmp, 33, i, j); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&ens, tmp, &overflow); - if (overflow || rustsecp256k1zkp_v0_8_0_scalar_is_zero(&ens)) { + rustsecp256k1zkp_v0_10_0_borromean_hash(tmp, m, mlen, tmp, 33, i, j); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&ens, tmp, &overflow); + if (overflow || rustsecp256k1zkp_v0_10_0_scalar_is_zero(&ens)) { return 0; } /** The signing algorithm as a whole is not memory uniform so there is likely a cache sidechannel that * leaks which members are non-forgeries. That the forgeries themselves are variable time may leave * an additional privacy impacting timing side-channel, but not a key loss one. */ - rustsecp256k1zkp_v0_8_0_ecmult(&rgej, &pubs[count + j], &ens, &s[count + j]); - if (rustsecp256k1zkp_v0_8_0_gej_is_infinity(&rgej)) { + rustsecp256k1zkp_v0_10_0_ecmult(&rgej, &pubs[count + j], &ens, &s[count + j]); + if (rustsecp256k1zkp_v0_10_0_gej_is_infinity(&rgej)) { return 0; } - rustsecp256k1zkp_v0_8_0_ge_set_gej_var(&rge, &rgej); - rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&rge, tmp, &size, 1); + rustsecp256k1zkp_v0_10_0_ge_set_gej_var(&rge, &rgej); + rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&rge, tmp, &size, 1); } - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_e0, tmp, size); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_e0, tmp, size); count += rsizes[i]; } - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_e0, m, mlen); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha256_e0, e0); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_e0, m, mlen); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha256_e0, e0); count = 0; for (i = 0; i < nrings; i++) { VERIFY_CHECK(INT_MAX - count > rsizes[i]); - rustsecp256k1zkp_v0_8_0_borromean_hash(tmp, m, mlen, e0, 32, i, 0); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&ens, tmp, &overflow); - if (overflow || rustsecp256k1zkp_v0_8_0_scalar_is_zero(&ens)) { + rustsecp256k1zkp_v0_10_0_borromean_hash(tmp, m, mlen, e0, 32, i, 0); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&ens, tmp, &overflow); + if (overflow || rustsecp256k1zkp_v0_10_0_scalar_is_zero(&ens)) { return 0; } for (j = 0; j < secidx[i]; j++) { - rustsecp256k1zkp_v0_8_0_ecmult(&rgej, &pubs[count + j], &ens, &s[count + j]); - if (rustsecp256k1zkp_v0_8_0_gej_is_infinity(&rgej)) { + rustsecp256k1zkp_v0_10_0_ecmult(&rgej, &pubs[count + j], &ens, &s[count + j]); + if (rustsecp256k1zkp_v0_10_0_gej_is_infinity(&rgej)) { return 0; } - rustsecp256k1zkp_v0_8_0_ge_set_gej_var(&rge, &rgej); - rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&rge, tmp, &size, 1); - rustsecp256k1zkp_v0_8_0_borromean_hash(tmp, m, mlen, tmp, 33, i, j + 1); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&ens, tmp, &overflow); - if (overflow || rustsecp256k1zkp_v0_8_0_scalar_is_zero(&ens)) { + rustsecp256k1zkp_v0_10_0_ge_set_gej_var(&rge, &rgej); + rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&rge, tmp, &size, 1); + rustsecp256k1zkp_v0_10_0_borromean_hash(tmp, m, mlen, tmp, 33, i, j + 1); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&ens, tmp, &overflow); + if (overflow || rustsecp256k1zkp_v0_10_0_scalar_is_zero(&ens)) { return 0; } } - rustsecp256k1zkp_v0_8_0_scalar_mul(&s[count + j], &ens, &sec[i]); - rustsecp256k1zkp_v0_8_0_scalar_negate(&s[count + j], &s[count + j]); - rustsecp256k1zkp_v0_8_0_scalar_add(&s[count + j], &s[count + j], &k[i]); - if (rustsecp256k1zkp_v0_8_0_scalar_is_zero(&s[count + j])) { + rustsecp256k1zkp_v0_10_0_scalar_mul(&s[count + j], &ens, &sec[i]); + rustsecp256k1zkp_v0_10_0_scalar_negate(&s[count + j], &s[count + j]); + rustsecp256k1zkp_v0_10_0_scalar_add(&s[count + j], &s[count + j], &k[i]); + if (rustsecp256k1zkp_v0_10_0_scalar_is_zero(&s[count + j])) { return 0; } count += rsizes[i]; } - rustsecp256k1zkp_v0_8_0_scalar_clear(&ens); - rustsecp256k1zkp_v0_8_0_ge_clear(&rge); - rustsecp256k1zkp_v0_8_0_gej_clear(&rgej); + rustsecp256k1zkp_v0_10_0_scalar_clear(&ens); + rustsecp256k1zkp_v0_10_0_ge_clear(&rge); + rustsecp256k1zkp_v0_10_0_gej_clear(&rgej); memset(tmp, 0, 33); return 1; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/main_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/main_impl.h index c9de5cd4..4264c9bc 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/main_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/main_impl.h @@ -4,16 +4,16 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef SECP256K1_MODULE_RANGEPROOF_MAIN -#define SECP256K1_MODULE_RANGEPROOF_MAIN +#ifndef SECP256K1_MODULE_RANGEPROOF_MAIN_H +#define SECP256K1_MODULE_RANGEPROOF_MAIN_H #include "../../group.h" -#include "modules/generator/main_impl.h" -#include "modules/rangeproof/borromean_impl.h" -#include "modules/rangeproof/rangeproof_impl.h" +#include "../generator/main_impl.h" +#include "../rangeproof/borromean_impl.h" +#include "../rangeproof/rangeproof_impl.h" -int rustsecp256k1zkp_v0_8_0_rangeproof_info(const rustsecp256k1zkp_v0_8_0_context* ctx, int *exp, int *mantissa, +int rustsecp256k1zkp_v0_10_0_rangeproof_info(const rustsecp256k1zkp_v0_10_0_context* ctx, int *exp, int *mantissa, uint64_t *min_value, uint64_t *max_value, const unsigned char *proof, size_t plen) { size_t offset; uint64_t scale; @@ -25,15 +25,15 @@ int rustsecp256k1zkp_v0_8_0_rangeproof_info(const rustsecp256k1zkp_v0_8_0_contex offset = 0; scale = 1; (void)ctx; - return rustsecp256k1zkp_v0_8_0_rangeproof_getheader_impl(&offset, exp, mantissa, &scale, min_value, max_value, proof, plen); + return rustsecp256k1zkp_v0_10_0_rangeproof_getheader_impl(&offset, exp, mantissa, &scale, min_value, max_value, proof, plen); } -int rustsecp256k1zkp_v0_8_0_rangeproof_rewind(const rustsecp256k1zkp_v0_8_0_context* ctx, +int rustsecp256k1zkp_v0_10_0_rangeproof_rewind(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *blind_out, uint64_t *value_out, unsigned char *message_out, size_t *outlen, const unsigned char *nonce, uint64_t *min_value, uint64_t *max_value, - const rustsecp256k1zkp_v0_8_0_pedersen_commitment *commit, const unsigned char *proof, size_t plen, const unsigned char *extra_commit, size_t extra_commit_len, const rustsecp256k1zkp_v0_8_0_generator* gen) { - rustsecp256k1zkp_v0_8_0_ge commitp; - rustsecp256k1zkp_v0_8_0_ge genp; + const rustsecp256k1zkp_v0_10_0_pedersen_commitment *commit, const unsigned char *proof, size_t plen, const unsigned char *extra_commit, size_t extra_commit_len, const rustsecp256k1zkp_v0_10_0_generator* gen) { + rustsecp256k1zkp_v0_10_0_ge commitp; + rustsecp256k1zkp_v0_10_0_ge genp; VERIFY_CHECK(ctx != NULL); ARG_CHECK(commit != NULL); ARG_CHECK(proof != NULL); @@ -43,17 +43,17 @@ int rustsecp256k1zkp_v0_8_0_rangeproof_rewind(const rustsecp256k1zkp_v0_8_0_cont ARG_CHECK(nonce != NULL); ARG_CHECK(extra_commit != NULL || extra_commit_len == 0); ARG_CHECK(gen != NULL); - ARG_CHECK(rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); - rustsecp256k1zkp_v0_8_0_pedersen_commitment_load(&commitp, commit); - rustsecp256k1zkp_v0_8_0_generator_load(&genp, gen); - return rustsecp256k1zkp_v0_8_0_rangeproof_verify_impl(&ctx->ecmult_gen_ctx, + ARG_CHECK(rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); + rustsecp256k1zkp_v0_10_0_pedersen_commitment_load(&commitp, commit); + rustsecp256k1zkp_v0_10_0_generator_load(&genp, gen); + return rustsecp256k1zkp_v0_10_0_rangeproof_verify_impl(&ctx->ecmult_gen_ctx, blind_out, value_out, message_out, outlen, nonce, min_value, max_value, &commitp, proof, plen, extra_commit, extra_commit_len, &genp); } -int rustsecp256k1zkp_v0_8_0_rangeproof_verify(const rustsecp256k1zkp_v0_8_0_context* ctx, uint64_t *min_value, uint64_t *max_value, - const rustsecp256k1zkp_v0_8_0_pedersen_commitment *commit, const unsigned char *proof, size_t plen, const unsigned char *extra_commit, size_t extra_commit_len, const rustsecp256k1zkp_v0_8_0_generator* gen) { - rustsecp256k1zkp_v0_8_0_ge commitp; - rustsecp256k1zkp_v0_8_0_ge genp; +int rustsecp256k1zkp_v0_10_0_rangeproof_verify(const rustsecp256k1zkp_v0_10_0_context* ctx, uint64_t *min_value, uint64_t *max_value, + const rustsecp256k1zkp_v0_10_0_pedersen_commitment *commit, const unsigned char *proof, size_t plen, const unsigned char *extra_commit, size_t extra_commit_len, const rustsecp256k1zkp_v0_10_0_generator* gen) { + rustsecp256k1zkp_v0_10_0_ge commitp; + rustsecp256k1zkp_v0_10_0_ge genp; VERIFY_CHECK(ctx != NULL); ARG_CHECK(commit != NULL); ARG_CHECK(proof != NULL); @@ -61,17 +61,17 @@ int rustsecp256k1zkp_v0_8_0_rangeproof_verify(const rustsecp256k1zkp_v0_8_0_cont ARG_CHECK(max_value != NULL); ARG_CHECK(extra_commit != NULL || extra_commit_len == 0); ARG_CHECK(gen != NULL); - rustsecp256k1zkp_v0_8_0_pedersen_commitment_load(&commitp, commit); - rustsecp256k1zkp_v0_8_0_generator_load(&genp, gen); - return rustsecp256k1zkp_v0_8_0_rangeproof_verify_impl(NULL, + rustsecp256k1zkp_v0_10_0_pedersen_commitment_load(&commitp, commit); + rustsecp256k1zkp_v0_10_0_generator_load(&genp, gen); + return rustsecp256k1zkp_v0_10_0_rangeproof_verify_impl(NULL, NULL, NULL, NULL, NULL, NULL, min_value, max_value, &commitp, proof, plen, extra_commit, extra_commit_len, &genp); } -int rustsecp256k1zkp_v0_8_0_rangeproof_sign(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *proof, size_t *plen, uint64_t min_value, - const rustsecp256k1zkp_v0_8_0_pedersen_commitment *commit, const unsigned char *blind, const unsigned char *nonce, int exp, int min_bits, uint64_t value, - const unsigned char *message, size_t msg_len, const unsigned char *extra_commit, size_t extra_commit_len, const rustsecp256k1zkp_v0_8_0_generator* gen){ - rustsecp256k1zkp_v0_8_0_ge commitp; - rustsecp256k1zkp_v0_8_0_ge genp; +int rustsecp256k1zkp_v0_10_0_rangeproof_sign(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *proof, size_t *plen, uint64_t min_value, + const rustsecp256k1zkp_v0_10_0_pedersen_commitment *commit, const unsigned char *blind, const unsigned char *nonce, int exp, int min_bits, uint64_t value, + const unsigned char *message, size_t msg_len, const unsigned char *extra_commit, size_t extra_commit_len, const rustsecp256k1zkp_v0_10_0_generator* gen){ + rustsecp256k1zkp_v0_10_0_ge commitp; + rustsecp256k1zkp_v0_10_0_ge genp; VERIFY_CHECK(ctx != NULL); ARG_CHECK(proof != NULL); ARG_CHECK(plen != NULL); @@ -81,15 +81,15 @@ int rustsecp256k1zkp_v0_8_0_rangeproof_sign(const rustsecp256k1zkp_v0_8_0_contex ARG_CHECK(message != NULL || msg_len == 0); ARG_CHECK(extra_commit != NULL || extra_commit_len == 0); ARG_CHECK(gen != NULL); - ARG_CHECK(rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); - rustsecp256k1zkp_v0_8_0_pedersen_commitment_load(&commitp, commit); - rustsecp256k1zkp_v0_8_0_generator_load(&genp, gen); - return rustsecp256k1zkp_v0_8_0_rangeproof_sign_impl(&ctx->ecmult_gen_ctx, + ARG_CHECK(rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); + rustsecp256k1zkp_v0_10_0_pedersen_commitment_load(&commitp, commit); + rustsecp256k1zkp_v0_10_0_generator_load(&genp, gen); + return rustsecp256k1zkp_v0_10_0_rangeproof_sign_impl(&ctx->ecmult_gen_ctx, proof, plen, min_value, &commitp, blind, nonce, exp, min_bits, value, message, msg_len, extra_commit, extra_commit_len, &genp); } -size_t rustsecp256k1zkp_v0_8_0_rangeproof_max_size(const rustsecp256k1zkp_v0_8_0_context* ctx, uint64_t max_value, int min_bits) { - const int val_mantissa = max_value > 0 ? 64 - rustsecp256k1zkp_v0_8_0_clz64_var(max_value) : 1; +size_t rustsecp256k1zkp_v0_10_0_rangeproof_max_size(const rustsecp256k1zkp_v0_10_0_context* ctx, uint64_t max_value, int min_bits) { + const int val_mantissa = max_value > 0 ? 64 - rustsecp256k1zkp_v0_10_0_clz64_var(max_value) : 1; const int mantissa = min_bits > val_mantissa ? min_bits : val_mantissa; const size_t rings = (mantissa + 1) / 2; const size_t npubs = rings * 4 - 2 * (mantissa % 2); diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/rangeproof.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/rangeproof.h index 9f25442f..d2bdbd32 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/rangeproof.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/rangeproof.h @@ -4,17 +4,17 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef _SECP256K1_RANGEPROOF_H_ -#define _SECP256K1_RANGEPROOF_H_ +#ifndef SECP256K1_RANGEPROOF_H +#define SECP256K1_RANGEPROOF_H #include "../../scalar.h" #include "../../group.h" #include "../../ecmult.h" #include "../../ecmult_gen.h" -static int rustsecp256k1zkp_v0_8_0_rangeproof_verify_impl(const rustsecp256k1zkp_v0_8_0_ecmult_gen_context* ecmult_gen_ctx, +static int rustsecp256k1zkp_v0_10_0_rangeproof_verify_impl(const rustsecp256k1zkp_v0_10_0_ecmult_gen_context* ecmult_gen_ctx, unsigned char *blindout, uint64_t *value_out, unsigned char *message_out, size_t *outlen, const unsigned char *nonce, - uint64_t *min_value, uint64_t *max_value, const rustsecp256k1zkp_v0_8_0_ge *commit, const unsigned char *proof, size_t plen, - const unsigned char *extra_commit, size_t extra_commit_len, const rustsecp256k1zkp_v0_8_0_ge* genp); + uint64_t *min_value, uint64_t *max_value, const rustsecp256k1zkp_v0_10_0_ge *commit, const unsigned char *proof, size_t plen, + const unsigned char *extra_commit, size_t extra_commit_len, const rustsecp256k1zkp_v0_10_0_ge* genp); #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/rangeproof_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/rangeproof_impl.h index 5589e128..08a07992 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/rangeproof_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/rangeproof_impl.h @@ -4,8 +4,8 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef _SECP256K1_RANGEPROOF_IMPL_H_ -#define _SECP256K1_RANGEPROOF_IMPL_H_ +#ifndef SECP256K1_RANGEPROOF_IMPL_H +#define SECP256K1_RANGEPROOF_IMPL_H #include "../../eckey.h" #include "../../scalar.h" @@ -13,13 +13,13 @@ #include "../../hash_impl.h" #include "../../util.h" -#include "modules/generator/pedersen.h" -#include "modules/rangeproof/borromean.h" -#include "modules/rangeproof/rangeproof.h" +#include "../generator/pedersen.h" +#include "../rangeproof/borromean.h" +#include "../rangeproof/rangeproof.h" -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_rangeproof_pub_expand(rustsecp256k1zkp_v0_8_0_gej *pubs, - int exp, size_t *rsizes, size_t rings, const rustsecp256k1zkp_v0_8_0_ge* genp) { - rustsecp256k1zkp_v0_8_0_gej base; +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_rangeproof_pub_expand(rustsecp256k1zkp_v0_10_0_gej *pubs, + int exp, size_t *rsizes, size_t rings, const rustsecp256k1zkp_v0_10_0_ge* genp) { + rustsecp256k1zkp_v0_10_0_gej base; size_t i; size_t j; size_t npub; @@ -27,43 +27,43 @@ SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_rangeproof_pub_expand(rusts if (exp < 0) { exp = 0; } - rustsecp256k1zkp_v0_8_0_gej_set_ge(&base, genp); - rustsecp256k1zkp_v0_8_0_gej_neg(&base, &base); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&base, genp); + rustsecp256k1zkp_v0_10_0_gej_neg(&base, &base); while (exp--) { /* Multiplication by 10 */ - rustsecp256k1zkp_v0_8_0_gej tmp; - rustsecp256k1zkp_v0_8_0_gej_double_var(&tmp, &base, NULL); - rustsecp256k1zkp_v0_8_0_gej_double_var(&base, &tmp, NULL); - rustsecp256k1zkp_v0_8_0_gej_double_var(&base, &base, NULL); - rustsecp256k1zkp_v0_8_0_gej_add_var(&base, &base, &tmp, NULL); + rustsecp256k1zkp_v0_10_0_gej tmp; + rustsecp256k1zkp_v0_10_0_gej_double_var(&tmp, &base, NULL); + rustsecp256k1zkp_v0_10_0_gej_double_var(&base, &tmp, NULL); + rustsecp256k1zkp_v0_10_0_gej_double_var(&base, &base, NULL); + rustsecp256k1zkp_v0_10_0_gej_add_var(&base, &base, &tmp, NULL); } npub = 0; for (i = 0; i < rings; i++) { for (j = 1; j < rsizes[i]; j++) { - rustsecp256k1zkp_v0_8_0_gej_add_var(&pubs[npub + j], &pubs[npub + j - 1], &base, NULL); + rustsecp256k1zkp_v0_10_0_gej_add_var(&pubs[npub + j], &pubs[npub + j - 1], &base, NULL); } if (i < rings - 1) { - rustsecp256k1zkp_v0_8_0_gej_double_var(&base, &base, NULL); - rustsecp256k1zkp_v0_8_0_gej_double_var(&base, &base, NULL); + rustsecp256k1zkp_v0_10_0_gej_double_var(&base, &base, NULL); + rustsecp256k1zkp_v0_10_0_gej_double_var(&base, &base, NULL); } npub += rsizes[i]; } } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_rangeproof_serialize_point(unsigned char* data, const rustsecp256k1zkp_v0_8_0_ge *point) { - rustsecp256k1zkp_v0_8_0_fe pointx; +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_rangeproof_serialize_point(unsigned char* data, const rustsecp256k1zkp_v0_10_0_ge *point) { + rustsecp256k1zkp_v0_10_0_fe pointx; pointx = point->x; - rustsecp256k1zkp_v0_8_0_fe_normalize(&pointx); - data[0] = !rustsecp256k1zkp_v0_8_0_fe_is_quad_var(&point->y); - rustsecp256k1zkp_v0_8_0_fe_get_b32(data + 1, &pointx); + rustsecp256k1zkp_v0_10_0_fe_normalize(&pointx); + data[0] = !rustsecp256k1zkp_v0_10_0_fe_is_square_var(&point->y); + rustsecp256k1zkp_v0_10_0_fe_get_b32(data + 1, &pointx); } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_genrand(rustsecp256k1zkp_v0_8_0_scalar *sec, rustsecp256k1zkp_v0_8_0_scalar *s, unsigned char *message, - size_t *rsizes, size_t rings, const unsigned char *nonce, const rustsecp256k1zkp_v0_8_0_ge *commit, const unsigned char *proof, size_t len, const rustsecp256k1zkp_v0_8_0_ge* genp) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_rangeproof_genrand(rustsecp256k1zkp_v0_10_0_scalar *sec, rustsecp256k1zkp_v0_10_0_scalar *s, unsigned char *message, + size_t *rsizes, size_t rings, const unsigned char *nonce, const rustsecp256k1zkp_v0_10_0_ge *commit, const unsigned char *proof, size_t len, const rustsecp256k1zkp_v0_10_0_ge* genp) { unsigned char tmp[32]; unsigned char rngseed[32 + 33 + 33 + 10]; - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256 rng; - rustsecp256k1zkp_v0_8_0_scalar acc; + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256 rng; + rustsecp256k1zkp_v0_10_0_scalar acc; int overflow; int ret; size_t i; @@ -72,45 +72,45 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_genrand(rustsecp2 size_t npub; VERIFY_CHECK(len <= 10); memcpy(rngseed, nonce, 32); - rustsecp256k1zkp_v0_8_0_rangeproof_serialize_point(rngseed + 32, commit); - rustsecp256k1zkp_v0_8_0_rangeproof_serialize_point(rngseed + 32 + 33, genp); + rustsecp256k1zkp_v0_10_0_rangeproof_serialize_point(rngseed + 32, commit); + rustsecp256k1zkp_v0_10_0_rangeproof_serialize_point(rngseed + 32 + 33, genp); memcpy(rngseed + 33 + 33 + 32, proof, len); - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_initialize(&rng, rngseed, 32 + 33 + 33 + len); - rustsecp256k1zkp_v0_8_0_scalar_clear(&acc); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_initialize(&rng, rngseed, 32 + 33 + 33 + len); + rustsecp256k1zkp_v0_10_0_scalar_clear(&acc); npub = 0; ret = 1; for (i = 0; i < rings; i++) { if (i < rings - 1) { - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_generate(&rng, tmp, 32); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_generate(&rng, tmp, 32); do { - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_generate(&rng, tmp, 32); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&sec[i], tmp, &overflow); - } while (overflow || rustsecp256k1zkp_v0_8_0_scalar_is_zero(&sec[i])); - rustsecp256k1zkp_v0_8_0_scalar_add(&acc, &acc, &sec[i]); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_generate(&rng, tmp, 32); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&sec[i], tmp, &overflow); + } while (overflow || rustsecp256k1zkp_v0_10_0_scalar_is_zero(&sec[i])); + rustsecp256k1zkp_v0_10_0_scalar_add(&acc, &acc, &sec[i]); } else { - rustsecp256k1zkp_v0_8_0_scalar_negate(&acc, &acc); + rustsecp256k1zkp_v0_10_0_scalar_negate(&acc, &acc); sec[i] = acc; } for (j = 0; j < rsizes[i]; j++) { - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_generate(&rng, tmp, 32); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_generate(&rng, tmp, 32); if (message) { for (b = 0; b < 32; b++) { tmp[b] ^= message[(i * 4 + j) * 32 + b]; message[(i * 4 + j) * 32 + b] = tmp[b]; } } - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&s[npub], tmp, &overflow); - ret &= !(overflow || rustsecp256k1zkp_v0_8_0_scalar_is_zero(&s[npub])); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&s[npub], tmp, &overflow); + ret &= !(overflow || rustsecp256k1zkp_v0_10_0_scalar_is_zero(&s[npub])); npub++; } } - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_finalize(&rng); - rustsecp256k1zkp_v0_8_0_scalar_clear(&acc); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_finalize(&rng); + rustsecp256k1zkp_v0_10_0_scalar_clear(&acc); memset(tmp, 0, 32); return ret; } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_range_proveparams(uint64_t *v, size_t *rings, size_t *rsizes, size_t *npub, size_t *secidx, uint64_t *min_value, +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_range_proveparams(uint64_t *v, size_t *rings, size_t *rsizes, size_t *npub, size_t *secidx, uint64_t *min_value, int *mantissa, uint64_t *scale, int *exp, int *min_bits, uint64_t value) { size_t i; *rings = 1; @@ -130,7 +130,7 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_range_proveparams(uint64_t * /* If either value or min_value is >= 2^63-1 then the other must by zero to avoid overflowing the proven range. */ return 0; } - max_bits = *min_value ? rustsecp256k1zkp_v0_8_0_clz64_var(*min_value) : 64; + max_bits = *min_value ? rustsecp256k1zkp_v0_10_0_clz64_var(*min_value) : 64; if (*min_bits > max_bits) { *min_bits = max_bits; } @@ -159,7 +159,7 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_range_proveparams(uint64_t * /* If the masked number isn't precise, compute the public offset. */ *min_value = value - v2; /* How many bits do we need to represent our value? */ - *mantissa = *v ? 64 - rustsecp256k1zkp_v0_8_0_clz64_var(*v) : 1; + *mantissa = *v ? 64 - rustsecp256k1zkp_v0_10_0_clz64_var(*v) : 1; if (*min_bits > *mantissa) { /* If the user asked for more precision, give it to them. */ *mantissa = *min_bits; @@ -188,16 +188,16 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_range_proveparams(uint64_t * } /* strawman interface, writes proof in proof, a buffer of plen, proves with respect to min_value the range for commit which has the provided blinding factor and value. */ -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_sign_impl(const rustsecp256k1zkp_v0_8_0_ecmult_gen_context* ecmult_gen_ctx, +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_rangeproof_sign_impl(const rustsecp256k1zkp_v0_10_0_ecmult_gen_context* ecmult_gen_ctx, unsigned char *proof, size_t *plen, uint64_t min_value, - const rustsecp256k1zkp_v0_8_0_ge *commit, const unsigned char *blind, const unsigned char *nonce, int exp, int min_bits, uint64_t value, - const unsigned char *message, size_t msg_len, const unsigned char *extra_commit, size_t extra_commit_len, const rustsecp256k1zkp_v0_8_0_ge* genp){ - rustsecp256k1zkp_v0_8_0_gej pubs[128]; /* Candidate digits for our proof, most inferred. */ - rustsecp256k1zkp_v0_8_0_scalar s[128]; /* Signatures in our proof, most forged. */ - rustsecp256k1zkp_v0_8_0_scalar sec[32]; /* Blinding factors for the correct digits. */ - rustsecp256k1zkp_v0_8_0_scalar k[32]; /* Nonces for our non-forged signatures. */ - rustsecp256k1zkp_v0_8_0_scalar stmp; - rustsecp256k1zkp_v0_8_0_sha256 sha256_m; + const rustsecp256k1zkp_v0_10_0_ge *commit, const unsigned char *blind, const unsigned char *nonce, int exp, int min_bits, uint64_t value, + const unsigned char *message, size_t msg_len, const unsigned char *extra_commit, size_t extra_commit_len, const rustsecp256k1zkp_v0_10_0_ge* genp){ + rustsecp256k1zkp_v0_10_0_gej pubs[128]; /* Candidate digits for our proof, most inferred. */ + rustsecp256k1zkp_v0_10_0_scalar s[128]; /* Signatures in our proof, most forged. */ + rustsecp256k1zkp_v0_10_0_scalar sec[32]; /* Blinding factors for the correct digits. */ + rustsecp256k1zkp_v0_10_0_scalar k[32]; /* Nonces for our non-forged signatures. */ + rustsecp256k1zkp_v0_10_0_scalar stmp; + rustsecp256k1zkp_v0_10_0_sha256 sha256_m; unsigned char prep[4096]; unsigned char tmp[33]; unsigned char *signs; /* Location of sign flags in the proof. */ @@ -215,7 +215,7 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_sign_impl(const r if (*plen < 65 || min_value > value || min_bits > 64 || min_bits < 0 || exp < -1 || exp > 18) { return 0; } - if (!rustsecp256k1zkp_v0_8_0_range_proveparams(&v, &rings, rsizes, &npub, secidx, &min_value, &mantissa, &scale, &exp, &min_bits, value)) { + if (!rustsecp256k1zkp_v0_10_0_range_proveparams(&v, &rings, rsizes, &npub, secidx, &min_value, &mantissa, &scale, &exp, &min_bits, value)) { return 0; } proof[len] = (rsizes[0] > 1 ? (64 | exp) : 0) | (min_value ? 32 : 0); @@ -242,12 +242,12 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_sign_impl(const r if (*plen - len < 32 * (npub + rings - 1) + 32 + ((rings+6) >> 3)) { return 0; } - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha256_m); - rustsecp256k1zkp_v0_8_0_rangeproof_serialize_point(tmp, commit); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_m, tmp, 33); - rustsecp256k1zkp_v0_8_0_rangeproof_serialize_point(tmp, genp); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_m, tmp, 33); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_m, proof, len); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha256_m); + rustsecp256k1zkp_v0_10_0_rangeproof_serialize_point(tmp, commit); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_m, tmp, 33); + rustsecp256k1zkp_v0_10_0_rangeproof_serialize_point(tmp, genp); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_m, tmp, 33); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_m, proof, len); memset(prep, 0, 4096); if (message != NULL) { @@ -266,14 +266,14 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_sign_impl(const r } prep[idx] = 128; } - if (!rustsecp256k1zkp_v0_8_0_rangeproof_genrand(sec, s, prep, rsizes, rings, nonce, commit, proof, len, genp)) { + if (!rustsecp256k1zkp_v0_10_0_rangeproof_genrand(sec, s, prep, rsizes, rings, nonce, commit, proof, len, genp)) { return 0; } memset(prep, 0, 4096); for (i = 0; i < rings; i++) { /* Sign will overwrite the non-forged signature, move that random value into the nonce. */ k[i] = s[i * 4 + secidx[i]]; - rustsecp256k1zkp_v0_8_0_scalar_clear(&s[i * 4 + secidx[i]]); + rustsecp256k1zkp_v0_10_0_scalar_clear(&s[i * 4 + secidx[i]]); } /** Genrand returns the last blinding factor as -sum(rest), * adding in the blinding factor for our commitment, results in the blinding factor for @@ -281,9 +281,9 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_sign_impl(const r * all the digits in the proof from the commitment. This lets the prover skip sending the * blinded value for one digit. */ - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&stmp, blind, &overflow); - rustsecp256k1zkp_v0_8_0_scalar_add(&sec[rings - 1], &sec[rings - 1], &stmp); - if (overflow || rustsecp256k1zkp_v0_8_0_scalar_is_zero(&sec[rings - 1])) { + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&stmp, blind, &overflow); + rustsecp256k1zkp_v0_10_0_scalar_add(&sec[rings - 1], &sec[rings - 1], &stmp); + if (overflow || rustsecp256k1zkp_v0_10_0_scalar_is_zero(&sec[rings - 1])) { return 0; } signs = &proof[len]; @@ -295,37 +295,37 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_sign_impl(const r npub = 0; for (i = 0; i < rings; i++) { /*OPT: Use the precomputed gen2 basis?*/ - rustsecp256k1zkp_v0_8_0_pedersen_ecmult(ecmult_gen_ctx, &pubs[npub], &sec[i], ((uint64_t)secidx[i] * scale) << (i*2), genp); - if (rustsecp256k1zkp_v0_8_0_gej_is_infinity(&pubs[npub])) { + rustsecp256k1zkp_v0_10_0_pedersen_ecmult(ecmult_gen_ctx, &pubs[npub], &sec[i], ((uint64_t)secidx[i] * scale) << (i*2), genp); + if (rustsecp256k1zkp_v0_10_0_gej_is_infinity(&pubs[npub])) { return 0; } if (i < rings - 1) { unsigned char tmpc[33]; - rustsecp256k1zkp_v0_8_0_ge c; + rustsecp256k1zkp_v0_10_0_ge c; unsigned char quadness; /*OPT: split loop and batch invert.*/ /*OPT: do not compute full pubs[npub] in ge form; we only need x */ - rustsecp256k1zkp_v0_8_0_ge_set_gej_var(&c, &pubs[npub]); - rustsecp256k1zkp_v0_8_0_rangeproof_serialize_point(tmpc, &c); + rustsecp256k1zkp_v0_10_0_ge_set_gej_var(&c, &pubs[npub]); + rustsecp256k1zkp_v0_10_0_rangeproof_serialize_point(tmpc, &c); quadness = tmpc[0]; - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_m, tmpc, 33); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_m, tmpc, 33); signs[i>>3] |= quadness << (i&7); memcpy(&proof[len], tmpc + 1, 32); len += 32; } npub += rsizes[i]; } - rustsecp256k1zkp_v0_8_0_rangeproof_pub_expand(pubs, exp, rsizes, rings, genp); + rustsecp256k1zkp_v0_10_0_rangeproof_pub_expand(pubs, exp, rsizes, rings, genp); if (extra_commit != NULL) { - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_m, extra_commit, extra_commit_len); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_m, extra_commit, extra_commit_len); } - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha256_m, tmp); - if (!rustsecp256k1zkp_v0_8_0_borromean_sign(ecmult_gen_ctx, &proof[len], s, pubs, k, sec, rsizes, secidx, rings, tmp, 32)) { + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha256_m, tmp); + if (!rustsecp256k1zkp_v0_10_0_borromean_sign(ecmult_gen_ctx, &proof[len], s, pubs, k, sec, rsizes, secidx, rings, tmp, 32)) { return 0; } len += 32; for (i = 0; i < npub; i++) { - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&proof[len],&s[i]); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&proof[len],&s[i]); len += 32; } VERIFY_CHECK(len <= *plen); @@ -335,36 +335,36 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_sign_impl(const r } /* Computes blinding factor x given k, s, and the challenge e. */ -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_rangeproof_recover_x(rustsecp256k1zkp_v0_8_0_scalar *x, const rustsecp256k1zkp_v0_8_0_scalar *k, const rustsecp256k1zkp_v0_8_0_scalar *e, - const rustsecp256k1zkp_v0_8_0_scalar *s) { - rustsecp256k1zkp_v0_8_0_scalar stmp; - rustsecp256k1zkp_v0_8_0_scalar_negate(x, s); - rustsecp256k1zkp_v0_8_0_scalar_add(x, x, k); - rustsecp256k1zkp_v0_8_0_scalar_inverse(&stmp, e); - rustsecp256k1zkp_v0_8_0_scalar_mul(x, x, &stmp); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_rangeproof_recover_x(rustsecp256k1zkp_v0_10_0_scalar *x, const rustsecp256k1zkp_v0_10_0_scalar *k, const rustsecp256k1zkp_v0_10_0_scalar *e, + const rustsecp256k1zkp_v0_10_0_scalar *s) { + rustsecp256k1zkp_v0_10_0_scalar stmp; + rustsecp256k1zkp_v0_10_0_scalar_negate(x, s); + rustsecp256k1zkp_v0_10_0_scalar_add(x, x, k); + rustsecp256k1zkp_v0_10_0_scalar_inverse(&stmp, e); + rustsecp256k1zkp_v0_10_0_scalar_mul(x, x, &stmp); } /* Computes ring's nonce given the blinding factor x, the challenge e, and the signature s. */ -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_rangeproof_recover_k(rustsecp256k1zkp_v0_8_0_scalar *k, const rustsecp256k1zkp_v0_8_0_scalar *x, const rustsecp256k1zkp_v0_8_0_scalar *e, - const rustsecp256k1zkp_v0_8_0_scalar *s) { - rustsecp256k1zkp_v0_8_0_scalar stmp; - rustsecp256k1zkp_v0_8_0_scalar_mul(&stmp, x, e); - rustsecp256k1zkp_v0_8_0_scalar_add(k, s, &stmp); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_rangeproof_recover_k(rustsecp256k1zkp_v0_10_0_scalar *k, const rustsecp256k1zkp_v0_10_0_scalar *x, const rustsecp256k1zkp_v0_10_0_scalar *e, + const rustsecp256k1zkp_v0_10_0_scalar *s) { + rustsecp256k1zkp_v0_10_0_scalar stmp; + rustsecp256k1zkp_v0_10_0_scalar_mul(&stmp, x, e); + rustsecp256k1zkp_v0_10_0_scalar_add(k, s, &stmp); } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_rangeproof_ch32xor(unsigned char *x, const unsigned char *y) { +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_rangeproof_ch32xor(unsigned char *x, const unsigned char *y) { int i; for (i = 0; i < 32; i++) { x[i] ^= y[i]; } } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_rewind_inner(rustsecp256k1zkp_v0_8_0_scalar *blind, uint64_t *v, - unsigned char *m, size_t *mlen, rustsecp256k1zkp_v0_8_0_scalar *ev, rustsecp256k1zkp_v0_8_0_scalar *s, - size_t *rsizes, size_t rings, const unsigned char *nonce, const rustsecp256k1zkp_v0_8_0_ge *commit, const unsigned char *proof, size_t len, const rustsecp256k1zkp_v0_8_0_ge *genp) { - rustsecp256k1zkp_v0_8_0_scalar s_orig[128]; - rustsecp256k1zkp_v0_8_0_scalar sec[32]; - rustsecp256k1zkp_v0_8_0_scalar stmp; +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_rangeproof_rewind_inner(rustsecp256k1zkp_v0_10_0_scalar *blind, uint64_t *v, + unsigned char *m, size_t *mlen, rustsecp256k1zkp_v0_10_0_scalar *ev, rustsecp256k1zkp_v0_10_0_scalar *s, + size_t *rsizes, size_t rings, const unsigned char *nonce, const rustsecp256k1zkp_v0_10_0_ge *commit, const unsigned char *proof, size_t len, const rustsecp256k1zkp_v0_10_0_ge *genp) { + rustsecp256k1zkp_v0_10_0_scalar s_orig[128]; + rustsecp256k1zkp_v0_10_0_scalar sec[32]; + rustsecp256k1zkp_v0_10_0_scalar stmp; unsigned char prep[4096]; unsigned char tmp[32]; uint64_t value = 0; @@ -380,12 +380,12 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_rewind_inner(rust VERIFY_CHECK(npub >= 1); memset(prep, 0, 4096); /* Reconstruct the provers random values. */ - rustsecp256k1zkp_v0_8_0_rangeproof_genrand(sec, s_orig, prep, rsizes, rings, nonce, commit, proof, len, genp); + rustsecp256k1zkp_v0_10_0_rangeproof_genrand(sec, s_orig, prep, rsizes, rings, nonce, commit, proof, len, genp); *v = UINT64_MAX; - rustsecp256k1zkp_v0_8_0_scalar_clear(blind); + rustsecp256k1zkp_v0_10_0_scalar_clear(blind); if (rings == 1 && rsizes[0] == 1) { /* With only a single proof, we can only recover the blinding factor. */ - rustsecp256k1zkp_v0_8_0_rangeproof_recover_x(blind, &s_orig[0], &ev[0], &s[0]); + rustsecp256k1zkp_v0_10_0_rangeproof_recover_x(blind, &s_orig[0], &ev[0], &s[0]); if (v) { *v = 0; } @@ -399,9 +399,9 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_rewind_inner(rust size_t idx; /* Look for a value encoding in the last ring. */ idx = npub + rsizes[rings - 1] - 1 - j; - rustsecp256k1zkp_v0_8_0_scalar_get_b32(tmp, &s[idx]); - rustsecp256k1zkp_v0_8_0_rangeproof_ch32xor(tmp, &prep[idx * 32]); - if ((tmp[0] & 128) && (rustsecp256k1zkp_v0_8_0_memcmp_var(&tmp[16], &tmp[24], 8) == 0) && (rustsecp256k1zkp_v0_8_0_memcmp_var(&tmp[8], &tmp[16], 8) == 0)) { + rustsecp256k1zkp_v0_10_0_scalar_get_b32(tmp, &s[idx]); + rustsecp256k1zkp_v0_10_0_rangeproof_ch32xor(tmp, &prep[idx * 32]); + if ((tmp[0] & 128) && (rustsecp256k1zkp_v0_10_0_memcmp_var(&tmp[16], &tmp[24], 8) == 0) && (rustsecp256k1zkp_v0_10_0_memcmp_var(&tmp[8], &tmp[16], 8) == 0)) { value = 0; for (i = 0; i < 8; i++) { value = (value << 8) + tmp[24 + i]; @@ -432,9 +432,9 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_rewind_inner(rust skip1 += (rings - 1) << 2; skip2 += (rings - 1) << 2; /* Like in the rsize[] == 1 case, Having figured out which s is the one which was not forged, we can recover the blinding factor. */ - rustsecp256k1zkp_v0_8_0_rangeproof_recover_x(&stmp, &s_orig[skip2], &ev[skip2], &s[skip2]); - rustsecp256k1zkp_v0_8_0_scalar_negate(&sec[rings - 1], &sec[rings - 1]); - rustsecp256k1zkp_v0_8_0_scalar_add(blind, &stmp, &sec[rings - 1]); + rustsecp256k1zkp_v0_10_0_rangeproof_recover_x(&stmp, &s_orig[skip2], &ev[skip2], &s[skip2]); + rustsecp256k1zkp_v0_10_0_scalar_negate(&sec[rings - 1], &sec[rings - 1]); + rustsecp256k1zkp_v0_10_0_scalar_add(blind, &stmp, &sec[rings - 1]); if (!m || !mlen || *mlen == 0) { if (mlen) { *mlen = 0; @@ -457,12 +457,12 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_rewind_inner(rust * this could just as well recover the blinding factors and messages could be put there as is done for recovering the * blinding factor in the last ring, but it takes an inversion to recover x so it's faster to put the message data in k. */ - rustsecp256k1zkp_v0_8_0_rangeproof_recover_k(&stmp, &sec[i], &ev[npub], &s[npub]); + rustsecp256k1zkp_v0_10_0_rangeproof_recover_k(&stmp, &sec[i], &ev[npub], &s[npub]); } else { stmp = s[npub]; } - rustsecp256k1zkp_v0_8_0_scalar_get_b32(tmp, &stmp); - rustsecp256k1zkp_v0_8_0_rangeproof_ch32xor(tmp, &prep[npub * 32]); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(tmp, &stmp); + rustsecp256k1zkp_v0_10_0_rangeproof_ch32xor(tmp, &prep[npub * 32]); for (b = 0; b < 32 && offset < *mlen; b++) { m[offset] = tmp[b]; offset++; @@ -473,16 +473,16 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_rewind_inner(rust *mlen = offset; memset(prep, 0, 4096); for (i = 0; i < 128; i++) { - rustsecp256k1zkp_v0_8_0_scalar_clear(&s_orig[i]); + rustsecp256k1zkp_v0_10_0_scalar_clear(&s_orig[i]); } for (i = 0; i < 32; i++) { - rustsecp256k1zkp_v0_8_0_scalar_clear(&sec[i]); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sec[i]); } - rustsecp256k1zkp_v0_8_0_scalar_clear(&stmp); + rustsecp256k1zkp_v0_10_0_scalar_clear(&stmp); return 1; } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_getheader_impl(size_t *offset, int *exp, int *mantissa, uint64_t *scale, +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_rangeproof_getheader_impl(size_t *offset, int *exp, int *mantissa, uint64_t *scale, uint64_t *min_value, uint64_t *max_value, const unsigned char *proof, size_t plen) { int i; int has_nz_range; @@ -536,15 +536,15 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_getheader_impl(si } /* Verifies range proof (len plen) for commit, the min/max values proven are put in the min/max arguments; returns 0 on failure 1 on success.*/ -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_verify_impl(const rustsecp256k1zkp_v0_8_0_ecmult_gen_context* ecmult_gen_ctx, +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_rangeproof_verify_impl(const rustsecp256k1zkp_v0_10_0_ecmult_gen_context* ecmult_gen_ctx, unsigned char *blindout, uint64_t *value_out, unsigned char *message_out, size_t *outlen, const unsigned char *nonce, - uint64_t *min_value, uint64_t *max_value, const rustsecp256k1zkp_v0_8_0_ge *commit, const unsigned char *proof, size_t plen, const unsigned char *extra_commit, size_t extra_commit_len, const rustsecp256k1zkp_v0_8_0_ge* genp) { - rustsecp256k1zkp_v0_8_0_gej accj; - rustsecp256k1zkp_v0_8_0_gej pubs[128]; - rustsecp256k1zkp_v0_8_0_ge c; - rustsecp256k1zkp_v0_8_0_scalar s[128]; - rustsecp256k1zkp_v0_8_0_scalar evalues[128]; /* Challenges, only used during proof rewind. */ - rustsecp256k1zkp_v0_8_0_sha256 sha256_m; + uint64_t *min_value, uint64_t *max_value, const rustsecp256k1zkp_v0_10_0_ge *commit, const unsigned char *proof, size_t plen, const unsigned char *extra_commit, size_t extra_commit_len, const rustsecp256k1zkp_v0_10_0_ge* genp) { + rustsecp256k1zkp_v0_10_0_gej accj; + rustsecp256k1zkp_v0_10_0_gej pubs[128]; + rustsecp256k1zkp_v0_10_0_ge c; + rustsecp256k1zkp_v0_10_0_scalar s[128]; + rustsecp256k1zkp_v0_10_0_scalar evalues[128]; /* Challenges, only used during proof rewind. */ + rustsecp256k1zkp_v0_10_0_sha256 sha256_m; size_t rsizes[32]; int ret; size_t i; @@ -560,7 +560,7 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_verify_impl(const unsigned char m[33]; const unsigned char *e0; offset = 0; - if (!rustsecp256k1zkp_v0_8_0_rangeproof_getheader_impl(&offset, &exp, &mantissa, &scale, min_value, max_value, proof, plen)) { + if (!rustsecp256k1zkp_v0_10_0_rangeproof_getheader_impl(&offset, &exp, &mantissa, &scale, min_value, max_value, proof, plen)) { return 0; } offset_post_header = offset; @@ -583,12 +583,12 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_verify_impl(const if (plen - offset < 32 * (npub + rings - 1) + 32 + ((rings+6) >> 3)) { return 0; } - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha256_m); - rustsecp256k1zkp_v0_8_0_rangeproof_serialize_point(m, commit); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_m, m, 33); - rustsecp256k1zkp_v0_8_0_rangeproof_serialize_point(m, genp); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_m, m, 33); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_m, proof, offset); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha256_m); + rustsecp256k1zkp_v0_10_0_rangeproof_serialize_point(m, commit); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_m, m, 33); + rustsecp256k1zkp_v0_10_0_rangeproof_serialize_point(m, genp); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_m, m, 33); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_m, proof, offset); for(i = 0; i < rings - 1; i++) { signs[i] = (proof[offset + ( i>> 3)] & (1 << (i & 7))) != 0; } @@ -600,39 +600,39 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_verify_impl(const } } npub = 0; - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&accj); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&accj); if (*min_value) { - rustsecp256k1zkp_v0_8_0_pedersen_ecmult_small(&accj, *min_value, genp); + rustsecp256k1zkp_v0_10_0_pedersen_ecmult_small(&accj, *min_value, genp); } for(i = 0; i < rings - 1; i++) { - rustsecp256k1zkp_v0_8_0_fe fe; - if (!rustsecp256k1zkp_v0_8_0_fe_set_b32(&fe, &proof[offset]) || - !rustsecp256k1zkp_v0_8_0_ge_set_xquad(&c, &fe)) { + rustsecp256k1zkp_v0_10_0_fe fe; + if (!rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&fe, &proof[offset]) || + !rustsecp256k1zkp_v0_10_0_ge_set_xquad(&c, &fe)) { return 0; } if (signs[i]) { - rustsecp256k1zkp_v0_8_0_ge_neg(&c, &c); + rustsecp256k1zkp_v0_10_0_ge_neg(&c, &c); } - /* Not using rustsecp256k1zkp_v0_8_0_rangeproof_serialize_point as we almost have it + /* Not using rustsecp256k1zkp_v0_10_0_rangeproof_serialize_point as we almost have it * serialized form already. */ - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_m, &signs[i], 1); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_m, &proof[offset], 32); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&pubs[npub], &c); - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&accj, &accj, &c, NULL); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_m, &signs[i], 1); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_m, &proof[offset], 32); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&pubs[npub], &c); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&accj, &accj, &c, NULL); offset += 32; npub += rsizes[i]; } - rustsecp256k1zkp_v0_8_0_gej_neg(&accj, &accj); - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&pubs[npub], &accj, commit, NULL); - if (rustsecp256k1zkp_v0_8_0_gej_is_infinity(&pubs[npub])) { + rustsecp256k1zkp_v0_10_0_gej_neg(&accj, &accj); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&pubs[npub], &accj, commit, NULL); + if (rustsecp256k1zkp_v0_10_0_gej_is_infinity(&pubs[npub])) { return 0; } - rustsecp256k1zkp_v0_8_0_rangeproof_pub_expand(pubs, exp, rsizes, rings, genp); + rustsecp256k1zkp_v0_10_0_rangeproof_pub_expand(pubs, exp, rsizes, rings, genp); npub += rsizes[rings - 1]; e0 = &proof[offset]; offset += 32; for (i = 0; i < npub; i++) { - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&s[i], &proof[offset], &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&s[i], &proof[offset], &overflow); if (overflow) { return 0; } @@ -643,34 +643,34 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_rangeproof_verify_impl(const return 0; } if (extra_commit != NULL) { - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_m, extra_commit, extra_commit_len); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_m, extra_commit, extra_commit_len); } - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha256_m, m); - ret = rustsecp256k1zkp_v0_8_0_borromean_verify(nonce ? evalues : NULL, e0, s, pubs, rsizes, rings, m, 32); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha256_m, m); + ret = rustsecp256k1zkp_v0_10_0_borromean_verify(nonce ? evalues : NULL, e0, s, pubs, rsizes, rings, m, 32); if (ret && nonce) { /* Given the nonce, try rewinding the witness to recover its initial state. */ - rustsecp256k1zkp_v0_8_0_scalar blind; + rustsecp256k1zkp_v0_10_0_scalar blind; uint64_t vv; if (!ecmult_gen_ctx) { return 0; } - if (!rustsecp256k1zkp_v0_8_0_rangeproof_rewind_inner(&blind, &vv, message_out, outlen, evalues, s, rsizes, rings, nonce, commit, proof, offset_post_header, genp)) { + if (!rustsecp256k1zkp_v0_10_0_rangeproof_rewind_inner(&blind, &vv, message_out, outlen, evalues, s, rsizes, rings, nonce, commit, proof, offset_post_header, genp)) { return 0; } /* Unwind apparently successful, see if the commitment can be reconstructed. */ /* FIXME: should check vv is in the mantissa's range. */ vv = (vv * scale) + *min_value; - rustsecp256k1zkp_v0_8_0_pedersen_ecmult(ecmult_gen_ctx, &accj, &blind, vv, genp); - if (rustsecp256k1zkp_v0_8_0_gej_is_infinity(&accj)) { + rustsecp256k1zkp_v0_10_0_pedersen_ecmult(ecmult_gen_ctx, &accj, &blind, vv, genp); + if (rustsecp256k1zkp_v0_10_0_gej_is_infinity(&accj)) { return 0; } - rustsecp256k1zkp_v0_8_0_gej_neg(&accj, &accj); - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&accj, &accj, commit, NULL); - if (!rustsecp256k1zkp_v0_8_0_gej_is_infinity(&accj)) { + rustsecp256k1zkp_v0_10_0_gej_neg(&accj, &accj); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&accj, &accj, commit, NULL); + if (!rustsecp256k1zkp_v0_10_0_gej_is_infinity(&accj)) { return 0; } if (blindout) { - rustsecp256k1zkp_v0_8_0_scalar_get_b32(blindout, &blind); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(blindout, &blind); } if (value_out) { *value_out = vv; diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/tests_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/tests_impl.h index d97113d4..7f2b5384 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/tests_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/rangeproof/tests_impl.h @@ -4,8 +4,8 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef SECP256K1_MODULE_RANGEPROOF_TESTS -#define SECP256K1_MODULE_RANGEPROOF_TESTS +#ifndef SECP256K1_MODULE_RANGEPROOF_TESTS_H +#define SECP256K1_MODULE_RANGEPROOF_TESTS_H #include @@ -16,12 +16,12 @@ #include "../../../include/secp256k1_rangeproof.h" -static void test_rangeproof_api(const rustsecp256k1zkp_v0_8_0_context *none, const rustsecp256k1zkp_v0_8_0_context *sign, const rustsecp256k1zkp_v0_8_0_context *vrfy, const rustsecp256k1zkp_v0_8_0_context *both, const rustsecp256k1zkp_v0_8_0_context *sttc, const int32_t *ecount) { +static void test_rangeproof_api(void) { unsigned char proof[5134]; unsigned char blind[32]; - rustsecp256k1zkp_v0_8_0_pedersen_commitment commit; - uint64_t vmin = rustsecp256k1zkp_v0_8_0_testrand32(); - uint64_t val = vmin + rustsecp256k1zkp_v0_8_0_testrand32(); + rustsecp256k1zkp_v0_10_0_pedersen_commitment commit; + uint64_t vmin = rustsecp256k1zkp_v0_10_0_testrand32(); + uint64_t val = vmin + rustsecp256k1zkp_v0_10_0_testrand32(); size_t len = sizeof(proof); /* we'll switch to dylan thomas for this one */ const unsigned char message[68] = "My tears are like the quiet drift / Of petals from some magic rose;"; @@ -29,90 +29,57 @@ static void test_rangeproof_api(const rustsecp256k1zkp_v0_8_0_context *none, con const unsigned char ext_commit[72] = "And all my grief flows from the rift / Of unremembered skies and snows."; size_t ext_commit_len = sizeof(ext_commit); - rustsecp256k1zkp_v0_8_0_testrand256(blind); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(ctx, &commit, blind, val, rustsecp256k1zkp_v0_8_0_generator_h)); - - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(none, proof, &len, vmin, &commit, blind, commit.data, 0, 0, val, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) != 0); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(sign, proof, &len, vmin, &commit, blind, commit.data, 0, 0, val, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(vrfy, proof, &len, vmin, &commit, blind, commit.data, 0, 0, val, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) != 0); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(both, proof, &len, vmin, &commit, blind, commit.data, 0, 0, val, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) != 0); - CHECK(*ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(sttc, proof, &len, vmin, &commit, blind, commit.data, 0, 0, val, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 1); - - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(both, NULL, &len, vmin, &commit, blind, commit.data, 0, 0, val, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(both, proof, NULL, vmin, &commit, blind, commit.data, 0, 0, val, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(both, proof, &len, vmin, NULL, blind, commit.data, 0, 0, val, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(both, proof, &len, vmin, &commit, NULL, commit.data, 0, 0, val, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(both, proof, &len, vmin, &commit, blind, NULL, 0, 0, val, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 6); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(both, proof, &len, vmin, &commit, blind, commit.data, 0, 0, vmin - 1, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 6); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(both, proof, &len, vmin, &commit, blind, commit.data, 0, 0, val, NULL, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 7); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(both, proof, &len, vmin, &commit, blind, commit.data, 0, 0, val, NULL, 0, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) != 0); - CHECK(*ecount == 7); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(both, proof, &len, vmin, &commit, blind, commit.data, 0, 0, val, NULL, 0, NULL, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 8); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(both, proof, &len, vmin, &commit, blind, commit.data, 0, 0, val, NULL, 0, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h) != 0); - CHECK(*ecount == 8); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(both, proof, &len, vmin, &commit, blind, commit.data, 0, 0, val, NULL, 0, NULL, 0, NULL) == 0); - CHECK(*ecount == 9); - - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(both, proof, &len, vmin, &commit, blind, commit.data, 0, 0, val, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) != 0); + rustsecp256k1zkp_v0_10_0_testrand256(blind); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commit(CTX, &commit, blind, val, rustsecp256k1zkp_v0_10_0_generator_h)); + + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, vmin, &commit, blind, commit.data, 0, 0, val, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h) == 1); + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_rangeproof_sign(STATIC_CTX, proof, &len, vmin, &commit, blind, commit.data, 0, 0, val, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); + + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, NULL, &len, vmin, &commit, blind, commit.data, 0, 0, val, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, NULL, vmin, &commit, blind, commit.data, 0, 0, val, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, vmin, NULL, blind, commit.data, 0, 0, val, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, vmin, &commit, NULL, commit.data, 0, 0, val, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, vmin, &commit, blind, NULL, 0, 0, val, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, vmin, &commit, blind, commit.data, 0, 0, vmin - 1, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, vmin, &commit, blind, commit.data, 0, 0, val, NULL, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, vmin, &commit, blind, commit.data, 0, 0, val, NULL, 0, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h) != 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, vmin, &commit, blind, commit.data, 0, 0, val, NULL, 0, NULL, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, vmin, &commit, blind, commit.data, 0, 0, val, NULL, 0, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h) != 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, vmin, &commit, blind, commit.data, 0, 0, val, NULL, 0, NULL, 0, NULL)); + + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, vmin, &commit, blind, commit.data, 0, 0, val, message, mlen, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h) != 0); { int exp; int mantissa; uint64_t min_value; uint64_t max_value; - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_info(none, &exp, &mantissa, &min_value, &max_value, proof, len) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_info(CTX, &exp, &mantissa, &min_value, &max_value, proof, len) != 0); CHECK(exp == 0); CHECK(((uint64_t) 1 << mantissa) > val - vmin); CHECK(((uint64_t) 1 << (mantissa - 1)) <= val - vmin); CHECK(min_value == vmin); CHECK(max_value >= val); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_info(none, NULL, &mantissa, &min_value, &max_value, proof, len) == 0); - CHECK(*ecount == 10); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_info(none, &exp, NULL, &min_value, &max_value, proof, len) == 0); - CHECK(*ecount == 11); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_info(none, &exp, &mantissa, NULL, &max_value, proof, len) == 0); - CHECK(*ecount == 12); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_info(none, &exp, &mantissa, &min_value, NULL, proof, len) == 0); - CHECK(*ecount == 13); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_info(none, &exp, &mantissa, &min_value, &max_value, NULL, len) == 0); - CHECK(*ecount == 14); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_info(none, &exp, &mantissa, &min_value, &max_value, proof, 0) == 0); - CHECK(*ecount == 14); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_info(CTX, NULL, &mantissa, &min_value, &max_value, proof, len)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_info(CTX, &exp, NULL, &min_value, &max_value, proof, len)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_info(CTX, &exp, &mantissa, NULL, &max_value, proof, len)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_info(CTX, &exp, &mantissa, &min_value, NULL, proof, len)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_info(CTX, &exp, &mantissa, &min_value, &max_value, NULL, len)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_info(CTX, &exp, &mantissa, &min_value, &max_value, proof, 0) == 0); } { uint64_t min_value; uint64_t max_value; - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify(none, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify(sign, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify(vrfy, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) != 0); - CHECK(*ecount == 14); - - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify(vrfy, NULL, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 15); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify(vrfy, &min_value, NULL, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 16); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify(vrfy, &min_value, &max_value, NULL, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 17); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify(vrfy, &min_value, &max_value, &commit, NULL, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 18); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify(vrfy, &min_value, &max_value, &commit, proof, 0, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 18); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify(vrfy, &min_value, &max_value, &commit, proof, len, NULL, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 19); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify(vrfy, &min_value, &max_value, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 19); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify(vrfy, &min_value, &max_value, &commit, proof, len, NULL, 0, NULL) == 0); - CHECK(*ecount == 20); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_verify(CTX, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h) == 1); + + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_verify(CTX, NULL, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_verify(CTX, &min_value, NULL, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_verify(CTX, &min_value, &max_value, NULL, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_verify(CTX, &min_value, &max_value, &commit, NULL, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_verify(CTX, &min_value, &max_value, &commit, proof, 0, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_verify(CTX, &min_value, &max_value, &commit, proof, len, NULL, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_verify(CTX, &min_value, &max_value, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_verify(CTX, &min_value, &max_value, &commit, proof, len, NULL, 0, NULL)); } { unsigned char blind_out[32]; @@ -122,96 +89,46 @@ static void test_rangeproof_api(const rustsecp256k1zkp_v0_8_0_context *none, con uint64_t max_value; size_t message_len = sizeof(message_out); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(none, blind_out, &value_out, message_out, &message_len, commit.data, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) != 0); - CHECK(*ecount == 20); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(sign, blind_out, &value_out, message_out, &message_len, commit.data, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(vrfy, blind_out, &value_out, message_out, &message_len, commit.data, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) != 0); - CHECK(*ecount == 20); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(both, blind_out, &value_out, message_out, &message_len, commit.data, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) != 0); - CHECK(*ecount == 20); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(sttc, blind_out, &value_out, message_out, &message_len, commit.data, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 21); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blind_out, &value_out, message_out, &message_len, commit.data, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h) == 1); + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_rangeproof_rewind(STATIC_CTX, blind_out, &value_out, message_out, &message_len, commit.data, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); CHECK(min_value == vmin); CHECK(max_value >= val); CHECK(value_out == val); CHECK(message_len == sizeof(message_out)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(message, message_out, sizeof(message_out)) == 0); - - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(both, NULL, &value_out, message_out, &message_len, commit.data, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) != 0); - CHECK(*ecount == 21); /* blindout may be NULL */ - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(both, blind_out, NULL, message_out, &message_len, commit.data, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) != 0); - CHECK(*ecount == 21); /* valueout may be NULL */ - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(both, blind_out, &value_out, NULL, &message_len, commit.data, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 22); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(both, blind_out, &value_out, NULL, 0, commit.data, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) != 0); - CHECK(*ecount == 22); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(both, blind_out, &value_out, NULL, 0, NULL, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 23); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(both, blind_out, &value_out, NULL, 0, commit.data, NULL, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 24); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(both, blind_out, &value_out, NULL, 0, commit.data, &min_value, NULL, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 25); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(both, blind_out, &value_out, NULL, 0, commit.data, &min_value, &max_value, NULL, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 26); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(both, blind_out, &value_out, NULL, 0, commit.data, &min_value, &max_value, &commit, NULL, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 27); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(both, blind_out, &value_out, NULL, 0, commit.data, &min_value, &max_value, &commit, proof, 0, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 27); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(both, blind_out, &value_out, NULL, 0, commit.data, &min_value, &max_value, &commit, proof, len, NULL, ext_commit_len, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 28); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(both, blind_out, &value_out, NULL, 0, commit.data, &min_value, &max_value, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h) == 0); - CHECK(*ecount == 28); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(both, blind_out, &value_out, NULL, 0, commit.data, &min_value, &max_value, &commit, proof, len, NULL, 0, NULL) == 0); - CHECK(*ecount == 29); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(message, message_out, sizeof(message_out)) == 0); + + /* blindout may be NULL */ + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, NULL, &value_out, message_out, &message_len, commit.data, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h) != 0); + /* valueout may be NULL */ + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blind_out, NULL, message_out, &message_len, commit.data, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h) != 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blind_out, &value_out, NULL, &message_len, commit.data, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blind_out, &value_out, NULL, 0, commit.data, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h) != 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blind_out, &value_out, NULL, 0, NULL, &min_value, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blind_out, &value_out, NULL, 0, commit.data, NULL, &max_value, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blind_out, &value_out, NULL, 0, commit.data, &min_value, NULL, &commit, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blind_out, &value_out, NULL, 0, commit.data, &min_value, &max_value, NULL, proof, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blind_out, &value_out, NULL, 0, commit.data, &min_value, &max_value, &commit, NULL, len, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blind_out, &value_out, NULL, 0, commit.data, &min_value, &max_value, &commit, proof, 0, ext_commit, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blind_out, &value_out, NULL, 0, commit.data, &min_value, &max_value, &commit, proof, len, NULL, ext_commit_len, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blind_out, &value_out, NULL, 0, commit.data, &min_value, &max_value, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blind_out, &value_out, NULL, 0, commit.data, &min_value, &max_value, &commit, proof, len, NULL, 0, NULL)); } /* This constant is hardcoded in these tests and elsewhere, so we * consider it to be part of the API and test it here. */ - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_max_size(none, 0, 64) == 5134); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_max_size(none, UINT64_MAX, 0) == 5134); -} - -static void test_api(void) { - rustsecp256k1zkp_v0_8_0_context *none = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_NONE); - rustsecp256k1zkp_v0_8_0_context *sign = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN); - rustsecp256k1zkp_v0_8_0_context *vrfy = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_VERIFY); - rustsecp256k1zkp_v0_8_0_context *both = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); - rustsecp256k1zkp_v0_8_0_context *sttc = rustsecp256k1zkp_v0_8_0_context_clone(rustsecp256k1zkp_v0_8_0_context_no_precomp); - int32_t ecount; - int i; - - rustsecp256k1zkp_v0_8_0_context_set_error_callback(none, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(sign, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(vrfy, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(both, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(sttc, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(none, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sign, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(vrfy, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(both, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sttc, counting_illegal_callback_fn, &ecount); - - for (i = 0; i < count; i++) { - ecount = 0; - test_rangeproof_api(none, sign, vrfy, both, sttc, &ecount); - } - - rustsecp256k1zkp_v0_8_0_context_destroy(none); - rustsecp256k1zkp_v0_8_0_context_destroy(sign); - rustsecp256k1zkp_v0_8_0_context_destroy(vrfy); - rustsecp256k1zkp_v0_8_0_context_destroy(both); - rustsecp256k1zkp_v0_8_0_context_destroy(sttc); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_max_size(CTX, 0, 64) == 5134); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_max_size(CTX, UINT64_MAX, 0) == 5134); } static void test_borromean(void) { unsigned char e0[32]; - rustsecp256k1zkp_v0_8_0_scalar s[64]; - rustsecp256k1zkp_v0_8_0_gej pubs[64]; - rustsecp256k1zkp_v0_8_0_scalar k[8]; - rustsecp256k1zkp_v0_8_0_scalar sec[8]; - rustsecp256k1zkp_v0_8_0_ge ge; - rustsecp256k1zkp_v0_8_0_scalar one; + rustsecp256k1zkp_v0_10_0_scalar s[64]; + rustsecp256k1zkp_v0_10_0_gej pubs[64]; + rustsecp256k1zkp_v0_10_0_scalar k[8]; + rustsecp256k1zkp_v0_10_0_scalar sec[8]; + rustsecp256k1zkp_v0_10_0_ge ge; + rustsecp256k1zkp_v0_10_0_scalar one; unsigned char m[32]; size_t rsizes[8]; size_t secidx[8]; @@ -219,31 +136,31 @@ static void test_borromean(void) { size_t i; size_t j; int c; - rustsecp256k1zkp_v0_8_0_testrand256_test(m); - nrings = 1 + (rustsecp256k1zkp_v0_8_0_testrand32()&7); + rustsecp256k1zkp_v0_10_0_testrand256_test(m); + nrings = 1 + (rustsecp256k1zkp_v0_10_0_testrand32()&7); c = 0; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&one, 1); - if (rustsecp256k1zkp_v0_8_0_testrand32()&1) { - rustsecp256k1zkp_v0_8_0_scalar_negate(&one, &one); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&one, 1); + if (rustsecp256k1zkp_v0_10_0_testrand32()&1) { + rustsecp256k1zkp_v0_10_0_scalar_negate(&one, &one); } for (i = 0; i < nrings; i++) { - rsizes[i] = 1 + (rustsecp256k1zkp_v0_8_0_testrand32()&7); - secidx[i] = rustsecp256k1zkp_v0_8_0_testrand32() % rsizes[i]; + rsizes[i] = 1 + (rustsecp256k1zkp_v0_10_0_testrand32()&7); + secidx[i] = rustsecp256k1zkp_v0_10_0_testrand32() % rsizes[i]; random_scalar_order(&sec[i]); random_scalar_order(&k[i]); - if(rustsecp256k1zkp_v0_8_0_testrand32()&7) { + if(rustsecp256k1zkp_v0_10_0_testrand32()&7) { sec[i] = one; } - if(rustsecp256k1zkp_v0_8_0_testrand32()&7) { + if(rustsecp256k1zkp_v0_10_0_testrand32()&7) { k[i] = one; } for (j = 0; j < rsizes[i]; j++) { random_scalar_order(&s[c + j]); - if(rustsecp256k1zkp_v0_8_0_testrand32()&7) { + if(rustsecp256k1zkp_v0_10_0_testrand32()&7) { s[i] = one; } if (j == secidx[i]) { - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &pubs[c + j], &sec[i]); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&CTX->ecmult_gen_ctx, &pubs[c + j], &sec[i]); } else { random_group_element_test(&ge); random_group_element_jacobian_test(&pubs[c + j],&ge); @@ -251,28 +168,28 @@ static void test_borromean(void) { } c += rsizes[i]; } - CHECK(rustsecp256k1zkp_v0_8_0_borromean_sign(&ctx->ecmult_gen_ctx, e0, s, pubs, k, sec, rsizes, secidx, nrings, m, 32)); - CHECK(rustsecp256k1zkp_v0_8_0_borromean_verify(NULL, e0, s, pubs, rsizes, nrings, m, 32)); - i = rustsecp256k1zkp_v0_8_0_testrand32() % c; - rustsecp256k1zkp_v0_8_0_scalar_negate(&s[i],&s[i]); - CHECK(!rustsecp256k1zkp_v0_8_0_borromean_verify(NULL, e0, s, pubs, rsizes, nrings, m, 32)); - rustsecp256k1zkp_v0_8_0_scalar_negate(&s[i],&s[i]); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&one, 1); + CHECK(rustsecp256k1zkp_v0_10_0_borromean_sign(&CTX->ecmult_gen_ctx, e0, s, pubs, k, sec, rsizes, secidx, nrings, m, 32)); + CHECK(rustsecp256k1zkp_v0_10_0_borromean_verify(NULL, e0, s, pubs, rsizes, nrings, m, 32)); + i = rustsecp256k1zkp_v0_10_0_testrand32() % c; + rustsecp256k1zkp_v0_10_0_scalar_negate(&s[i],&s[i]); + CHECK(!rustsecp256k1zkp_v0_10_0_borromean_verify(NULL, e0, s, pubs, rsizes, nrings, m, 32)); + rustsecp256k1zkp_v0_10_0_scalar_negate(&s[i],&s[i]); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&one, 1); for(j = 0; j < 4; j++) { - i = rustsecp256k1zkp_v0_8_0_testrand32() % c; - if (rustsecp256k1zkp_v0_8_0_testrand32() & 1) { - rustsecp256k1zkp_v0_8_0_gej_double_var(&pubs[i],&pubs[i], NULL); + i = rustsecp256k1zkp_v0_10_0_testrand32() % c; + if (rustsecp256k1zkp_v0_10_0_testrand32() & 1) { + rustsecp256k1zkp_v0_10_0_gej_double_var(&pubs[i],&pubs[i], NULL); } else { - rustsecp256k1zkp_v0_8_0_scalar_add(&s[i],&s[i],&one); + rustsecp256k1zkp_v0_10_0_scalar_add(&s[i],&s[i],&one); } - CHECK(!rustsecp256k1zkp_v0_8_0_borromean_verify(NULL, e0, s, pubs, rsizes, nrings, m, 32)); + CHECK(!rustsecp256k1zkp_v0_10_0_borromean_verify(NULL, e0, s, pubs, rsizes, nrings, m, 32)); } } static void test_rangeproof(void) { const uint64_t testvs[11] = {0, 1, 5, 11, 65535, 65537, INT32_MAX, UINT32_MAX, INT64_MAX - 1, INT64_MAX, UINT64_MAX}; - rustsecp256k1zkp_v0_8_0_pedersen_commitment commit; - rustsecp256k1zkp_v0_8_0_pedersen_commitment commit2; + rustsecp256k1zkp_v0_10_0_pedersen_commitment commit; + rustsecp256k1zkp_v0_10_0_pedersen_commitment commit2; unsigned char proof[5134 + 1]; /* One additional byte to test if trailing bytes are rejected */ unsigned char blind[32]; unsigned char blindout[32]; @@ -296,10 +213,10 @@ static void test_rangeproof(void) { memcpy(&message_long[i], message_short, sizeof(message_short)); } - rustsecp256k1zkp_v0_8_0_testrand256(blind); + rustsecp256k1zkp_v0_10_0_testrand256(blind); for (i = 0; i < 11; i++) { v = testvs[i]; - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(ctx, &commit, blind, v, rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commit(CTX, &commit, blind, v, rustsecp256k1zkp_v0_10_0_generator_h)); for (vmin = 0; vmin < (i<9 && i > 0 ? 2 : 1); vmin++) { const unsigned char *input_message = NULL; size_t input_message_len = 0; @@ -315,127 +232,127 @@ static void test_rangeproof(void) { input_message_len = sizeof(message_long); } len = 5134; - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(ctx, proof, &len, vmin, &commit, blind, commit.data, 0, 0, v, input_message, input_message_len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, vmin, &commit, blind, commit.data, 0, 0, v, input_message, input_message_len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); CHECK(len <= 5134); - CHECK(len <= rustsecp256k1zkp_v0_8_0_rangeproof_max_size(ctx, v, 0)); + CHECK(len <= rustsecp256k1zkp_v0_10_0_rangeproof_max_size(CTX, v, 0)); mlen = 4096; - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(ctx, blindout, &vout, message, &mlen, commit.data, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blindout, &vout, message, &mlen, commit.data, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); if (input_message != NULL) { - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(message, input_message, input_message_len) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(message, input_message, input_message_len) == 0); } for (j = input_message_len; j < mlen; j++) { CHECK(message[j] == 0); } CHECK(mlen <= 4096); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(blindout, blind, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(blindout, blind, 32) == 0); CHECK(vout == v); CHECK(minv <= v); CHECK(maxv >= v); len = 5134; - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(ctx, proof, &len, v, &commit, blind, commit.data, -1, 64, v, NULL, 0, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, v, &commit, blind, commit.data, -1, 64, v, NULL, 0, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); CHECK(len <= 73); - CHECK(len <= rustsecp256k1zkp_v0_8_0_rangeproof_max_size(ctx, v, 0)); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(ctx, blindout, &vout, NULL, NULL, commit.data, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(blindout, blind, 32) == 0); + CHECK(len <= rustsecp256k1zkp_v0_10_0_rangeproof_max_size(CTX, v, 0)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blindout, &vout, NULL, NULL, commit.data, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(blindout, blind, 32) == 0); CHECK(vout == v); CHECK(minv == v); CHECK(maxv == v); /* Check with a committed message */ len = 5134; - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(ctx, proof, &len, v, &commit, blind, commit.data, -1, 64, v, NULL, 0, message_short, sizeof(message_short), rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, v, &commit, blind, commit.data, -1, 64, v, NULL, 0, message_short, sizeof(message_short), rustsecp256k1zkp_v0_10_0_generator_h)); CHECK(len <= 73); - CHECK(len <= rustsecp256k1zkp_v0_8_0_rangeproof_max_size(ctx, v, 0)); - CHECK(!rustsecp256k1zkp_v0_8_0_rangeproof_rewind(ctx, blindout, &vout, NULL, NULL, commit.data, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); - CHECK(!rustsecp256k1zkp_v0_8_0_rangeproof_rewind(ctx, blindout, &vout, NULL, NULL, commit.data, &minv, &maxv, &commit, proof, len, message_long, sizeof(message_long), rustsecp256k1zkp_v0_8_0_generator_h)); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(ctx, blindout, &vout, NULL, NULL, commit.data, &minv, &maxv, &commit, proof, len, message_short, sizeof(message_short), rustsecp256k1zkp_v0_8_0_generator_h)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(blindout, blind, 32) == 0); + CHECK(len <= rustsecp256k1zkp_v0_10_0_rangeproof_max_size(CTX, v, 0)); + CHECK(!rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blindout, &vout, NULL, NULL, commit.data, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(!rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blindout, &vout, NULL, NULL, commit.data, &minv, &maxv, &commit, proof, len, message_long, sizeof(message_long), rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blindout, &vout, NULL, NULL, commit.data, &minv, &maxv, &commit, proof, len, message_short, sizeof(message_short), rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(blindout, blind, 32) == 0); CHECK(vout == v); CHECK(minv == v); CHECK(maxv == v); } } - rustsecp256k1zkp_v0_8_0_testrand256(blind); + rustsecp256k1zkp_v0_10_0_testrand256(blind); v = INT64_MAX - 1; - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(ctx, &commit, blind, v, rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commit(CTX, &commit, blind, v, rustsecp256k1zkp_v0_10_0_generator_h)); for (i = 0; i < 19; i++) { len = 5134; - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(ctx, proof, &len, 0, &commit, blind, commit.data, i, 0, v, NULL, 0, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); - CHECK(len <= rustsecp256k1zkp_v0_8_0_rangeproof_max_size(ctx, v, 0)); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify(ctx, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, 0, &commit, blind, commit.data, i, 0, v, NULL, 0, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(len <= rustsecp256k1zkp_v0_10_0_rangeproof_max_size(CTX, v, 0)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_verify(CTX, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); CHECK(len <= 5134); CHECK(minv <= v); CHECK(maxv >= v); /* Make sure it fails when validating with a committed message */ - CHECK(!rustsecp256k1zkp_v0_8_0_rangeproof_verify(ctx, &minv, &maxv, &commit, proof, len, message_short, sizeof(message_short), rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(!rustsecp256k1zkp_v0_10_0_rangeproof_verify(CTX, &minv, &maxv, &commit, proof, len, message_short, sizeof(message_short), rustsecp256k1zkp_v0_10_0_generator_h)); } - rustsecp256k1zkp_v0_8_0_testrand256(blind); + rustsecp256k1zkp_v0_10_0_testrand256(blind); { /*Malleability test.*/ - v = rustsecp256k1zkp_v0_8_0_testrandi64(0, 255); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(ctx, &commit, blind, v, rustsecp256k1zkp_v0_8_0_generator_h)); + v = rustsecp256k1zkp_v0_10_0_testrandi64(0, 255); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commit(CTX, &commit, blind, v, rustsecp256k1zkp_v0_10_0_generator_h)); len = 5134; - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(ctx, proof, &len, 0, &commit, blind, commit.data, 0, 3, v, NULL, 0, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, 0, &commit, blind, commit.data, 0, 3, v, NULL, 0, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); CHECK(len <= 5134); - CHECK(len <= rustsecp256k1zkp_v0_8_0_rangeproof_max_size(ctx, v, 3)); + CHECK(len <= rustsecp256k1zkp_v0_10_0_rangeproof_max_size(CTX, v, 3)); /* Test if trailing bytes are rejected. */ proof[len] = v; - CHECK(!rustsecp256k1zkp_v0_8_0_rangeproof_verify(ctx, &minv, &maxv, &commit, proof, len + 1, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(!rustsecp256k1zkp_v0_10_0_rangeproof_verify(CTX, &minv, &maxv, &commit, proof, len + 1, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); for (i = 0; i < len*8; i++) { proof[i >> 3] ^= 1 << (i & 7); - CHECK(!rustsecp256k1zkp_v0_8_0_rangeproof_verify(ctx, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(!rustsecp256k1zkp_v0_10_0_rangeproof_verify(CTX, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); proof[i >> 3] ^= 1 << (i & 7); } - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify(ctx, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_verify(CTX, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); CHECK(minv <= v); CHECK(maxv >= v); } memcpy(&commit2, &commit, sizeof(commit)); - for (i = 0; i < (size_t) count; i++) { + for (i = 0; i < (size_t) COUNT; i++) { int exp; int min_bits; - v = rustsecp256k1zkp_v0_8_0_testrandi64(0, UINT64_MAX >> (rustsecp256k1zkp_v0_8_0_testrand32()&63)); + v = rustsecp256k1zkp_v0_10_0_testrandi64(0, UINT64_MAX >> (rustsecp256k1zkp_v0_10_0_testrand32()&63)); vmin = 0; - if ((v < INT64_MAX) && (rustsecp256k1zkp_v0_8_0_testrand32()&1)) { - vmin = rustsecp256k1zkp_v0_8_0_testrandi64(0, v); + if ((v < INT64_MAX) && (rustsecp256k1zkp_v0_10_0_testrand32()&1)) { + vmin = rustsecp256k1zkp_v0_10_0_testrandi64(0, v); } - rustsecp256k1zkp_v0_8_0_testrand256(blind); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(ctx, &commit, blind, v, rustsecp256k1zkp_v0_8_0_generator_h)); + rustsecp256k1zkp_v0_10_0_testrand256(blind); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commit(CTX, &commit, blind, v, rustsecp256k1zkp_v0_10_0_generator_h)); len = 5134; - exp = (int)rustsecp256k1zkp_v0_8_0_testrandi64(0,18)-(int)rustsecp256k1zkp_v0_8_0_testrandi64(0,18); + exp = (int)rustsecp256k1zkp_v0_10_0_testrandi64(0,18)-(int)rustsecp256k1zkp_v0_10_0_testrandi64(0,18); if (exp < 0) { exp = -exp; } - min_bits = (int)rustsecp256k1zkp_v0_8_0_testrandi64(0,64)-(int)rustsecp256k1zkp_v0_8_0_testrandi64(0,64); + min_bits = (int)rustsecp256k1zkp_v0_10_0_testrandi64(0,64)-(int)rustsecp256k1zkp_v0_10_0_testrandi64(0,64); if (min_bits < 0) { min_bits = -min_bits; } - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(ctx, proof, &len, vmin, &commit, blind, commit.data, exp, min_bits, v, NULL, 0, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, vmin, &commit, blind, commit.data, exp, min_bits, v, NULL, 0, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); CHECK(len <= 5134); - CHECK(len <= rustsecp256k1zkp_v0_8_0_rangeproof_max_size(ctx, v, min_bits)); + CHECK(len <= rustsecp256k1zkp_v0_10_0_rangeproof_max_size(CTX, v, min_bits)); mlen = 4096; - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(ctx, blindout, &vout, message, &mlen, commit.data, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blindout, &vout, message, &mlen, commit.data, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); for (j = 0; j < mlen; j++) { CHECK(message[j] == 0); } CHECK(mlen <= 4096); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(blindout, blind, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(blindout, blind, 32) == 0); CHECK(minv <= v); CHECK(maxv >= v); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(ctx, blindout, &vout, NULL, NULL, commit.data, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blindout, &vout, NULL, NULL, commit.data, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); memcpy(&commit2, &commit, sizeof(commit)); } for (j = 0; j < 3; j++) { for (i = 0; i < 96; i++) { - rustsecp256k1zkp_v0_8_0_testrand256(&proof[i * 32]); + rustsecp256k1zkp_v0_10_0_testrand256(&proof[i * 32]); } for (k = 0; k < 128; k += 3) { len = k; - CHECK(!rustsecp256k1zkp_v0_8_0_rangeproof_verify(ctx, &minv, &maxv, &commit2, proof, len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(!rustsecp256k1zkp_v0_10_0_rangeproof_verify(CTX, &minv, &maxv, &commit2, proof, len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); } - len = rustsecp256k1zkp_v0_8_0_testrandi64(0, 3072); - CHECK(!rustsecp256k1zkp_v0_8_0_rangeproof_verify(ctx, &minv, &maxv, &commit2, proof, len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); + len = rustsecp256k1zkp_v0_10_0_testrandi64(0, 3072); + CHECK(!rustsecp256k1zkp_v0_10_0_rangeproof_verify(CTX, &minv, &maxv, &commit2, proof, len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); } } @@ -444,29 +361,29 @@ static void test_rangeproof_null_blinder(void) { const unsigned char blind[32] = { 0 }; const uint64_t v = 1111; uint64_t minv, maxv; - rustsecp256k1zkp_v0_8_0_pedersen_commitment commit; + rustsecp256k1zkp_v0_10_0_pedersen_commitment commit; size_t len; - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(ctx, &commit, blind, v, rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commit(CTX, &commit, blind, v, rustsecp256k1zkp_v0_10_0_generator_h)); /* Try a 32-bit proof; should work */ len = 5134; - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(ctx, proof, &len, 1, &commit, blind, commit.data, 0, 32, v, NULL, 0, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify(ctx, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, 1, &commit, blind, commit.data, 0, 32, v, NULL, 0, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_verify(CTX, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); CHECK(minv == 1); CHECK(maxv == 1ULL << 32); /* Try a 3-bit proof; should work */ len = 5134; - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(ctx, proof, &len, v - 1, &commit, blind, commit.data, 0, 3, v, NULL, 0, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify(ctx, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, v - 1, &commit, blind, commit.data, 0, 3, v, NULL, 0, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_verify(CTX, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); CHECK(minv == 1110); CHECK(maxv == 1117); /* But a 2-bits will not because then it does not have any subcommitments (which rerandomize * the blinding factors that get passed into the borromean logic ... passing 0s will fail) */ len = 5134; - CHECK(!rustsecp256k1zkp_v0_8_0_rangeproof_sign(ctx, proof, &len, v - 1, &commit, blind, commit.data, 0, 2, v, NULL, 0, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); + CHECK(!rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, v - 1, &commit, blind, commit.data, 0, 2, v, NULL, 0, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); /* Rewinding with 3-bits works */ { @@ -477,14 +394,14 @@ static void test_rangeproof_null_blinder(void) { size_t msg_len = sizeof(msg); len = 1000; - rustsecp256k1zkp_v0_8_0_testrand256(msg); - rustsecp256k1zkp_v0_8_0_testrand256(&msg[32]); - rustsecp256k1zkp_v0_8_0_testrand256(&msg[64]); - rustsecp256k1zkp_v0_8_0_testrand256(&msg[96]); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(ctx, proof, &len, v, &commit, blind, commit.data, 0, 3, v, msg, sizeof(msg), NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind(ctx, blind_out, &value_out, msg_out, &msg_len, commit.data, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h) != 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(blind, blind_out, sizeof(blind)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(msg, msg_out, sizeof(msg)) == 0); + rustsecp256k1zkp_v0_10_0_testrand256(msg); + rustsecp256k1zkp_v0_10_0_testrand256(&msg[32]); + rustsecp256k1zkp_v0_10_0_testrand256(&msg[64]); + rustsecp256k1zkp_v0_10_0_testrand256(&msg[96]); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &len, v, &commit, blind, commit.data, 0, 3, v, msg, sizeof(msg), NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_rewind(CTX, blind_out, &value_out, msg_out, &msg_len, commit.data, &minv, &maxv, &commit, proof, len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(blind, blind_out, sizeof(blind)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(msg, msg_out, sizeof(msg)) == 0); CHECK(value_out == v); CHECK(minv == v); CHECK(maxv == v + 7); @@ -493,7 +410,7 @@ static void test_rangeproof_null_blinder(void) { static void test_single_value_proof(uint64_t val) { unsigned char proof[5000]; - rustsecp256k1zkp_v0_8_0_pedersen_commitment commit; + rustsecp256k1zkp_v0_10_0_pedersen_commitment commit; unsigned char blind[32]; unsigned char blind_out[32]; unsigned char nonce[32]; @@ -505,13 +422,14 @@ static void test_single_value_proof(uint64_t val) { uint64_t val_out = 0; size_t m_len_out = 0; + size_t i; - rustsecp256k1zkp_v0_8_0_testrand256(blind); - rustsecp256k1zkp_v0_8_0_testrand256(nonce); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(ctx, &commit, blind, val, rustsecp256k1zkp_v0_8_0_generator_h)); + rustsecp256k1zkp_v0_10_0_testrand256(blind); + rustsecp256k1zkp_v0_10_0_testrand256(nonce); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commit(CTX, &commit, blind, val, rustsecp256k1zkp_v0_10_0_generator_h)); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign( - ctx, + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_sign( + CTX, proof, &plen, val, /* min_val */ &commit, blind, nonce, @@ -520,12 +438,12 @@ static void test_single_value_proof(uint64_t val) { val, /* val */ message, sizeof(message), /* Will cause this to fail */ NULL, 0, - rustsecp256k1zkp_v0_8_0_generator_h + rustsecp256k1zkp_v0_10_0_generator_h ) == 0); plen = sizeof(proof); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign( - ctx, + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_sign( + CTX, proof, &plen, val, /* min_val */ &commit, blind, nonce, @@ -534,9 +452,9 @@ static void test_single_value_proof(uint64_t val) { val, /* val */ NULL, 0, NULL, 0, - rustsecp256k1zkp_v0_8_0_generator_h + rustsecp256k1zkp_v0_10_0_generator_h ) == 1); - CHECK(plen <= rustsecp256k1zkp_v0_8_0_rangeproof_max_size(ctx, val, 0)); + CHECK(plen <= rustsecp256k1zkp_v0_10_0_rangeproof_max_size(CTX, val, 0)); /* Different proof sizes are unfortunate but is caused by `min_value` of * zero being special-cased and encoded more efficiently. */ @@ -546,21 +464,45 @@ static void test_single_value_proof(uint64_t val) { CHECK(plen == 73); } - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify( - ctx, + /* Test if trailing bytes are rejected. */ + proof[plen] = 0; + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_verify( + CTX, + &min_val_out, &max_val_out, + &commit, + proof, plen + 1, + NULL, 0, + rustsecp256k1zkp_v0_10_0_generator_h + ) == 0); + /* Test if single-bit malleation is caught */ + for (i = 0; i < plen*8; i++) { + proof[i >> 3] ^= 1 << (i & 7); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_verify( + CTX, + &min_val_out, &max_val_out, + &commit, + proof, plen, + NULL, 0, + rustsecp256k1zkp_v0_10_0_generator_h + ) == 0); + proof[i >> 3] ^= 1 << (i & 7); + } + /* Test if unchanged proof is accepted. */ + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_verify( + CTX, &min_val_out, &max_val_out, &commit, proof, plen, NULL, 0, - rustsecp256k1zkp_v0_8_0_generator_h + rustsecp256k1zkp_v0_10_0_generator_h ) == 1); CHECK(min_val_out == val); CHECK(max_val_out == val); memset(message_out, 0, sizeof(message_out)); m_len_out = sizeof(message_out); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind( - ctx, + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_rewind( + CTX, blind_out, &val_out, message_out, &m_len_out, nonce, @@ -568,13 +510,13 @@ static void test_single_value_proof(uint64_t val) { &commit, proof, plen, NULL, 0, - rustsecp256k1zkp_v0_8_0_generator_h + rustsecp256k1zkp_v0_10_0_generator_h )); CHECK(val_out == val); CHECK(min_val_out == val); CHECK(max_val_out == val); CHECK(m_len_out == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(blind, blind_out, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(blind, blind_out, 32) == 0); for (m_len_out = 0; m_len_out < sizeof(message_out); m_len_out++) { CHECK(message_out[m_len_out] == 0); } @@ -582,34 +524,34 @@ static void test_single_value_proof(uint64_t val) { #define MAX_N_GENS 30 static void test_multiple_generators(void) { - const size_t n_inputs = (rustsecp256k1zkp_v0_8_0_testrand32() % (MAX_N_GENS / 2)) + 1; - const size_t n_outputs = (rustsecp256k1zkp_v0_8_0_testrand32() % (MAX_N_GENS / 2)) + 1; + const size_t n_inputs = (rustsecp256k1zkp_v0_10_0_testrand32() % (MAX_N_GENS / 2)) + 1; + const size_t n_outputs = (rustsecp256k1zkp_v0_10_0_testrand32() % (MAX_N_GENS / 2)) + 1; const size_t n_generators = n_inputs + n_outputs; unsigned char *generator_blind[MAX_N_GENS]; unsigned char *pedersen_blind[MAX_N_GENS]; - rustsecp256k1zkp_v0_8_0_generator generator[MAX_N_GENS]; - rustsecp256k1zkp_v0_8_0_pedersen_commitment commit[MAX_N_GENS]; - const rustsecp256k1zkp_v0_8_0_pedersen_commitment *commit_ptr[MAX_N_GENS]; + rustsecp256k1zkp_v0_10_0_generator generator[MAX_N_GENS]; + rustsecp256k1zkp_v0_10_0_pedersen_commitment commit[MAX_N_GENS]; + const rustsecp256k1zkp_v0_10_0_pedersen_commitment *commit_ptr[MAX_N_GENS]; size_t i; int64_t total_value; uint64_t value[MAX_N_GENS]; - rustsecp256k1zkp_v0_8_0_scalar s; + rustsecp256k1zkp_v0_10_0_scalar s; unsigned char generator_seed[32]; random_scalar_order(&s); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(generator_seed, &s); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(generator_seed, &s); /* Create all the needed generators */ for (i = 0; i < n_generators; i++) { generator_blind[i] = (unsigned char*) malloc(32); pedersen_blind[i] = (unsigned char*) malloc(32); random_scalar_order(&s); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(generator_blind[i], &s); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(generator_blind[i], &s); random_scalar_order(&s); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(pedersen_blind[i], &s); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(pedersen_blind[i], &s); - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate_blinded(ctx, &generator[i], generator_seed, generator_blind[i])); + CHECK(rustsecp256k1zkp_v0_10_0_generator_generate_blinded(CTX, &generator[i], generator_seed, generator_blind[i])); commit_ptr[i] = &commit[i]; } @@ -617,23 +559,23 @@ static void test_multiple_generators(void) { /* Compute all the values -- can be positive or negative */ total_value = 0; for (i = 0; i < n_outputs; i++) { - value[n_inputs + i] = rustsecp256k1zkp_v0_8_0_testrandi64(0, INT64_MAX - total_value); + value[n_inputs + i] = rustsecp256k1zkp_v0_10_0_testrandi64(0, INT64_MAX - total_value); total_value += value[n_inputs + i]; } for (i = 0; i < n_inputs - 1; i++) { - value[i] = rustsecp256k1zkp_v0_8_0_testrandi64(0, total_value); + value[i] = rustsecp256k1zkp_v0_10_0_testrandi64(0, total_value); total_value -= value[i]; } value[i] = total_value; /* Correct for blinding factors and do the commitments */ - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_blind_generator_blind_sum(ctx, value, (const unsigned char * const *) generator_blind, pedersen_blind, n_generators, n_inputs)); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_blind_generator_blind_sum(CTX, value, (const unsigned char * const *) generator_blind, pedersen_blind, n_generators, n_inputs)); for (i = 0; i < n_generators; i++) { - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(ctx, &commit[i], pedersen_blind[i], value[i], &generator[i])); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commit(CTX, &commit[i], pedersen_blind[i], value[i], &generator[i])); } /* Verify */ - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_verify_tally(ctx, &commit_ptr[0], n_inputs, &commit_ptr[n_inputs], n_outputs)); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_verify_tally(CTX, &commit_ptr[0], n_inputs, &commit_ptr[n_inputs], n_outputs)); /* Cleanup */ for (i = 0; i < n_generators; i++) { @@ -642,13 +584,13 @@ static void test_multiple_generators(void) { } } -void test_rangeproof_fixed_vectors(void) { +static void test_rangeproof_fixed_vectors(void) { size_t i; unsigned char blind[32]; uint64_t value; uint64_t min_value; uint64_t max_value; - rustsecp256k1zkp_v0_8_0_pedersen_commitment pc; + rustsecp256k1zkp_v0_10_0_pedersen_commitment pc; unsigned char message[4000] = {0}; size_t m_len = sizeof(message); @@ -707,20 +649,20 @@ void test_rangeproof_fixed_vectors(void) { 0x77, 0x47, 0xa4, 0xd3, 0x53, 0x17, 0xc6, 0x44, 0x30, 0x73, 0x84, 0xeb, 0x1f, 0xbe, 0xa1, 0xfb }; - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commitment_parse(ctx, &pc, commit_1)); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify( - ctx, + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commitment_parse(CTX, &pc, commit_1)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_verify( + CTX, &min_value, &max_value, &pc, vector_1, sizeof(vector_1), NULL, 0, - rustsecp256k1zkp_v0_8_0_generator_h + rustsecp256k1zkp_v0_10_0_generator_h )); CHECK(min_value == 86); CHECK(max_value == 25586); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind( - ctx, + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_rewind( + CTX, blind, &value, message, &m_len, pc.data, @@ -728,10 +670,10 @@ void test_rangeproof_fixed_vectors(void) { &pc, vector_1, sizeof(vector_1), NULL, 0, - rustsecp256k1zkp_v0_8_0_generator_h + rustsecp256k1zkp_v0_10_0_generator_h )); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(blind, blind_1, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(blind, blind_1, 32) == 0); CHECK(value == 86); CHECK(min_value == 86); CHECK(max_value == 25586); @@ -778,20 +720,20 @@ void test_rangeproof_fixed_vectors(void) { }; static const unsigned char message_2[] = "When I see my own likeness in the depths of someone else's consciousness, I always experience a moment of panic."; - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commitment_parse(ctx, &pc, commit_2)); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify( - ctx, + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commitment_parse(CTX, &pc, commit_2)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_verify( + CTX, &min_value, &max_value, &pc, vector_2, sizeof(vector_2), NULL, 0, - rustsecp256k1zkp_v0_8_0_generator_h + rustsecp256k1zkp_v0_10_0_generator_h )); CHECK(min_value == 0); CHECK(max_value == 15); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind( - ctx, + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_rewind( + CTX, blind, &value, message, &m_len, pc.data, @@ -799,15 +741,15 @@ void test_rangeproof_fixed_vectors(void) { &pc, vector_2, sizeof(vector_2), NULL, 0, - rustsecp256k1zkp_v0_8_0_generator_h + rustsecp256k1zkp_v0_10_0_generator_h )); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(blind, blind_2, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(blind, blind_2, 32) == 0); CHECK(value == 11); CHECK(min_value == 0); CHECK(max_value == 15); CHECK(m_len == 192); /* length of the sidechannel in the proof */ - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(message, message_2, sizeof(message_2)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(message, message_2, sizeof(message_2)) == 0); for (i = sizeof(message_2); i < m_len; i++) { CHECK(message[i] == 0); } @@ -836,20 +778,20 @@ void test_rangeproof_fixed_vectors(void) { 0xc0, 0x6b, 0x9b, 0x4c, 0x02, 0xa6, 0xc8, 0xf6, 0xc0, 0x34, 0xea, 0x35, 0x57, 0xf4, 0xe1, 0x37 }; - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commitment_parse(ctx, &pc, commit_3)); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify( - ctx, + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commitment_parse(CTX, &pc, commit_3)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_verify( + CTX, &min_value, &max_value, &pc, vector_3, sizeof(vector_3), NULL, 0, - rustsecp256k1zkp_v0_8_0_generator_h + rustsecp256k1zkp_v0_10_0_generator_h )); CHECK(min_value == UINT64_MAX); CHECK(max_value == UINT64_MAX); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind( - ctx, + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_rewind( + CTX, blind, &value, message, &m_len, nonce_3, @@ -857,9 +799,9 @@ void test_rangeproof_fixed_vectors(void) { &pc, vector_3, sizeof(vector_3), NULL, 0, - rustsecp256k1zkp_v0_8_0_generator_h + rustsecp256k1zkp_v0_10_0_generator_h )); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(blind, blind_3, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(blind, blind_3, 32) == 0); CHECK(value == UINT64_MAX); CHECK(min_value == UINT64_MAX); CHECK(max_value == UINT64_MAX); @@ -884,13 +826,13 @@ static void print_vector_helper(unsigned char *buf, size_t buf_len) { printf("};\n"); } -static void print_vector(int i, unsigned char *proof, size_t p_len, rustsecp256k1zkp_v0_8_0_pedersen_commitment *commit) { +static void print_vector(int i, unsigned char *proof, size_t p_len, rustsecp256k1zkp_v0_10_0_pedersen_commitment *commit) { unsigned char commit_output[33]; printf("unsigned char vector_%d[] = {\n", i); print_vector_helper(proof, p_len); - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commitment_serialize(ctx, commit_output, commit)); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commitment_serialize(CTX, commit_output, commit)); printf("unsigned char commit_%d[] = {\n", i); print_vector_helper(commit_output, sizeof(commit_output)); } @@ -907,23 +849,23 @@ static unsigned char vector_nonce[] = { }; /* Maximum length of a message that can be embedded into a rangeproof */ -void test_rangeproof_fixed_vectors_reproducible_helper(unsigned char *vector, size_t vector_len, unsigned char *commit, uint64_t *value_r, uint64_t *min_value_r, uint64_t *max_value_r, unsigned char *message_r, size_t *m_len_r) { - rustsecp256k1zkp_v0_8_0_pedersen_commitment pc; +static void test_rangeproof_fixed_vectors_reproducible_helper(unsigned char *vector, size_t vector_len, unsigned char *commit, uint64_t *value_r, uint64_t *min_value_r, uint64_t *max_value_r, unsigned char *message_r, size_t *m_len_r) { + rustsecp256k1zkp_v0_10_0_pedersen_commitment pc; unsigned char blind_r[32]; - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commitment_parse(ctx, &pc, commit)); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_verify( - ctx, + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commitment_parse(CTX, &pc, commit)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_verify( + CTX, min_value_r, max_value_r, &pc, vector, vector_len, NULL, 0, - rustsecp256k1zkp_v0_8_0_generator_h + rustsecp256k1zkp_v0_10_0_generator_h )); *m_len_r = SECP256K1_RANGEPROOF_MAX_MESSAGE_LEN; - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_rewind( - ctx, + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_rewind( + CTX, blind_r, value_r, message_r, m_len_r, vector_nonce, @@ -931,12 +873,12 @@ void test_rangeproof_fixed_vectors_reproducible_helper(unsigned char *vector, si &pc, vector, vector_len, NULL, 0, - rustsecp256k1zkp_v0_8_0_generator_h + rustsecp256k1zkp_v0_10_0_generator_h )); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(blind_r, vector_blind, sizeof(vector_blind)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(blind_r, vector_blind, sizeof(vector_blind)) == 0); } -void test_rangeproof_fixed_vectors_reproducible(void) { +static void test_rangeproof_fixed_vectors_reproducible(void) { uint64_t value_r; uint64_t min_value_r; uint64_t max_value_r; @@ -954,7 +896,7 @@ void test_rangeproof_fixed_vectors_reproducible(void) { int exp = 18; unsigned char proof[5126]; size_t p_len = sizeof(proof); - rustsecp256k1zkp_v0_8_0_pedersen_commitment pc; + rustsecp256k1zkp_v0_10_0_pedersen_commitment pc; unsigned char vector_0[] = { 0x40, 0x3f, 0xd1, 0x77, 0x65, 0x05, 0x87, 0x88, 0xd0, 0x3d, 0xb2, 0x24, 0x60, 0x7a, 0x08, 0x76, @@ -1285,19 +1227,19 @@ void test_rangeproof_fixed_vectors_reproducible(void) { 0xef, }; - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(ctx, &pc, vector_blind, value, rustsecp256k1zkp_v0_8_0_generator_h)); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(ctx, proof, &p_len, min_value, &pc, vector_blind, vector_nonce, exp, min_bits, value, message, m_len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); - CHECK(p_len <= rustsecp256k1zkp_v0_8_0_rangeproof_max_size(ctx, value, min_bits)); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commit(CTX, &pc, vector_blind, value, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &p_len, min_value, &pc, vector_blind, vector_nonce, exp, min_bits, value, message, m_len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(p_len <= rustsecp256k1zkp_v0_10_0_rangeproof_max_size(CTX, value, min_bits)); CHECK(p_len == sizeof(proof)); /* Uncomment the next line to print the test vector */ /* print_vector(0, proof, p_len, &pc); */ CHECK(p_len == sizeof(vector_0)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(proof, vector_0, p_len) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(proof, vector_0, p_len) == 0); test_rangeproof_fixed_vectors_reproducible_helper(vector_0, sizeof(vector_0), commit_0, &value_r, &min_value_r, &max_value_r, message_r, &m_len_r); CHECK(value_r == value); CHECK(m_len_r == m_len); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(message_r, message, m_len_r) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(message_r, message, m_len_r) == 0); CHECK(min_value_r == min_value); CHECK(max_value_r == UINT64_MAX); memset(message_r, 0, sizeof(message_r)); @@ -1313,7 +1255,7 @@ void test_rangeproof_fixed_vectors_reproducible(void) { int exp = 1; unsigned char proof[267]; size_t p_len = sizeof(proof); - rustsecp256k1zkp_v0_8_0_pedersen_commitment pc; + rustsecp256k1zkp_v0_10_0_pedersen_commitment pc; unsigned char vector_1[] = { 0x61, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0xcb, 0xdc, 0xbe, 0x42, 0xe6, @@ -1339,19 +1281,19 @@ void test_rangeproof_fixed_vectors_reproducible(void) { 0x66, 0x16, 0x2e, 0x44, 0xc8, 0x65, 0x8e, 0xe6, 0x3a, 0x1a, 0x57, 0x2c, 0xb9, 0x6c, 0x07, 0x85, 0xf0, }; - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(ctx, &pc, vector_blind, value, rustsecp256k1zkp_v0_8_0_generator_h)); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(ctx, proof, &p_len, min_value, &pc, vector_blind, vector_nonce, exp, min_bits, value, message, m_len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); - CHECK(p_len <= rustsecp256k1zkp_v0_8_0_rangeproof_max_size(ctx, value, min_bits)); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commit(CTX, &pc, vector_blind, value, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &p_len, min_value, &pc, vector_blind, vector_nonce, exp, min_bits, value, message, m_len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(p_len <= rustsecp256k1zkp_v0_10_0_rangeproof_max_size(CTX, value, min_bits)); CHECK(p_len == sizeof(proof)); /* Uncomment the next line to print the test vector */ /* print_vector(1, proof, p_len, &pc); */ CHECK(p_len == sizeof(vector_1)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(proof, vector_1, p_len) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(proof, vector_1, p_len) == 0); test_rangeproof_fixed_vectors_reproducible_helper(vector_1, sizeof(vector_1), commit_1, &value_r, &min_value_r, &max_value_r, message_r, &m_len_r); CHECK(value_r == value); CHECK(m_len_r == m_len); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(message_r, message, m_len_r) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(message_r, message, m_len_r) == 0); CHECK(min_value_r == 3); CHECK(max_value_r == 73); memset(message_r, 0, sizeof(message_r)); @@ -1368,7 +1310,7 @@ void test_rangeproof_fixed_vectors_reproducible(void) { int exp = 0; unsigned char proof[106]; size_t p_len = sizeof(proof); - rustsecp256k1zkp_v0_8_0_pedersen_commitment pc; + rustsecp256k1zkp_v0_10_0_pedersen_commitment pc; unsigned char vector_2[] = { 0x60, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x81, 0xd8, 0x21, 0x12, 0x4d, 0xa4, @@ -1385,28 +1327,30 @@ void test_rangeproof_fixed_vectors_reproducible(void) { 0x70, }; - CHECK(rustsecp256k1zkp_v0_8_0_pedersen_commit(ctx, &pc, vector_blind, value, rustsecp256k1zkp_v0_8_0_generator_h)); - CHECK(rustsecp256k1zkp_v0_8_0_rangeproof_sign(ctx, proof, &p_len, min_value, &pc, vector_blind, vector_nonce, exp, min_bits, value, message, m_len, NULL, 0, rustsecp256k1zkp_v0_8_0_generator_h)); - CHECK(p_len <= rustsecp256k1zkp_v0_8_0_rangeproof_max_size(ctx, value, min_bits)); + CHECK(rustsecp256k1zkp_v0_10_0_pedersen_commit(CTX, &pc, vector_blind, value, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(rustsecp256k1zkp_v0_10_0_rangeproof_sign(CTX, proof, &p_len, min_value, &pc, vector_blind, vector_nonce, exp, min_bits, value, message, m_len, NULL, 0, rustsecp256k1zkp_v0_10_0_generator_h)); + CHECK(p_len <= rustsecp256k1zkp_v0_10_0_rangeproof_max_size(CTX, value, min_bits)); CHECK(p_len == sizeof(proof)); /* Uncomment the next line to print the test vector */ /* print_vector(2, proof, p_len, &pc); */ CHECK(p_len == sizeof(vector_2)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(proof, vector_2, p_len) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(proof, vector_2, p_len) == 0); test_rangeproof_fixed_vectors_reproducible_helper(vector_2, sizeof(vector_2), commit_2, &value_r, &min_value_r, &max_value_r, message_r, &m_len_r); CHECK(value_r == value); CHECK(m_len_r == m_len); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(message_r, message, m_len_r) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(message_r, message, m_len_r) == 0); CHECK(min_value_r == INT64_MAX-1); CHECK(max_value_r == INT64_MAX); memset(message_r, 0, sizeof(message_r)); } } -void run_rangeproof_tests(void) { +static void run_rangeproof_tests(void) { int i; - test_api(); + for (i = 0; i < COUNT; i++) { + test_rangeproof_api(); + } test_single_value_proof(0); test_single_value_proof(12345678); @@ -1414,7 +1358,7 @@ void run_rangeproof_tests(void) { test_rangeproof_fixed_vectors(); test_rangeproof_fixed_vectors_reproducible(); - for (i = 0; i < count / 2 + 1; i++) { + for (i = 0; i < COUNT / 2 + 1; i++) { test_borromean(); } test_rangeproof(); diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/recovery/Makefile.am.include b/secp256k1-zkp-sys/depend/secp256k1/src/modules/recovery/Makefile.am.include index 2917f4f6..769b8a44 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/recovery/Makefile.am.include +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/recovery/Makefile.am.include @@ -1,4 +1,4 @@ -include_HEADERS += include/rustsecp256k1zkp_v0_8_0_recovery.h +include_HEADERS += include/rustsecp256k1zkp_v0_10_0_recovery.h noinst_HEADERS += src/modules/recovery/main_impl.h noinst_HEADERS += src/modules/recovery/tests_impl.h noinst_HEADERS += src/modules/recovery/tests_exhaustive_impl.h diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/recovery/bench_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/recovery/bench_impl.h index 75c3470a..daa19704 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/recovery/bench_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/recovery/bench_impl.h @@ -7,27 +7,27 @@ #ifndef SECP256K1_MODULE_RECOVERY_BENCH_H #define SECP256K1_MODULE_RECOVERY_BENCH_H -#include "../include/secp256k1_recovery.h" +#include "../../../include/secp256k1_recovery.h" typedef struct { - rustsecp256k1zkp_v0_8_0_context *ctx; + rustsecp256k1zkp_v0_10_0_context *ctx; unsigned char msg[32]; unsigned char sig[64]; } bench_recover_data; -void bench_recover(void* arg, int iters) { +static void bench_recover(void* arg, int iters) { int i; bench_recover_data *data = (bench_recover_data*)arg; - rustsecp256k1zkp_v0_8_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; unsigned char pubkeyc[33]; for (i = 0; i < iters; i++) { int j; size_t pubkeylen = 33; - rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature sig; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact(data->ctx, &sig, data->sig, i % 2)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recover(data->ctx, &pubkey, &sig, data->msg)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(data->ctx, pubkeyc, &pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED)); + rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature sig; + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_parse_compact(data->ctx, &sig, data->sig, i % 2)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recover(data->ctx, &pubkey, &sig, data->msg)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(data->ctx, pubkeyc, &pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED)); for (j = 0; j < 32; j++) { data->sig[j + 32] = data->msg[j]; /* Move former message to S. */ data->msg[j] = data->sig[j]; /* Move former R to message. */ @@ -36,7 +36,7 @@ void bench_recover(void* arg, int iters) { } } -void bench_recover_setup(void* arg) { +static void bench_recover_setup(void* arg) { int i; bench_recover_data *data = (bench_recover_data*)arg; @@ -48,15 +48,15 @@ void bench_recover_setup(void* arg) { } } -void run_recovery_bench(int iters, int argc, char** argv) { +static void run_recovery_bench(int iters, int argc, char** argv) { bench_recover_data data; int d = argc == 1; - data.ctx = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_VERIFY); + data.ctx = rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_CONTEXT_NONE); if (d || have_flag(argc, argv, "ecdsa") || have_flag(argc, argv, "recover") || have_flag(argc, argv, "ecdsa_recover")) run_benchmark("ecdsa_recover", bench_recover, bench_recover_setup, NULL, &data, 10, iters); - rustsecp256k1zkp_v0_8_0_context_destroy(data.ctx); + rustsecp256k1zkp_v0_10_0_context_destroy(data.ctx); } #endif /* SECP256K1_MODULE_RECOVERY_BENCH_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/recovery/main_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/recovery/main_impl.h index 23e70efa..dc665e6d 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/recovery/main_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/recovery/main_impl.h @@ -9,34 +9,34 @@ #include "../../../include/secp256k1_recovery.h" -static void rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_load(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_scalar* r, rustsecp256k1zkp_v0_8_0_scalar* s, int* recid, const rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature* sig) { +static void rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_load(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_scalar* r, rustsecp256k1zkp_v0_10_0_scalar* s, int* recid, const rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature* sig) { (void)ctx; - if (sizeof(rustsecp256k1zkp_v0_8_0_scalar) == 32) { - /* When the rustsecp256k1zkp_v0_8_0_scalar type is exactly 32 byte, use its - * representation inside rustsecp256k1zkp_v0_8_0_ecdsa_signature, as conversion is very fast. - * Note that rustsecp256k1zkp_v0_8_0_ecdsa_signature_save must use the same representation. */ + if (sizeof(rustsecp256k1zkp_v0_10_0_scalar) == 32) { + /* When the rustsecp256k1zkp_v0_10_0_scalar type is exactly 32 byte, use its + * representation inside rustsecp256k1zkp_v0_10_0_ecdsa_signature, as conversion is very fast. + * Note that rustsecp256k1zkp_v0_10_0_ecdsa_signature_save must use the same representation. */ memcpy(r, &sig->data[0], 32); memcpy(s, &sig->data[32], 32); } else { - rustsecp256k1zkp_v0_8_0_scalar_set_b32(r, &sig->data[0], NULL); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(s, &sig->data[32], NULL); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(r, &sig->data[0], NULL); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(s, &sig->data[32], NULL); } *recid = sig->data[64]; } -static void rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_save(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature* sig, const rustsecp256k1zkp_v0_8_0_scalar* r, const rustsecp256k1zkp_v0_8_0_scalar* s, int recid) { - if (sizeof(rustsecp256k1zkp_v0_8_0_scalar) == 32) { +static void rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_save(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature* sig, const rustsecp256k1zkp_v0_10_0_scalar* r, const rustsecp256k1zkp_v0_10_0_scalar* s, int recid) { + if (sizeof(rustsecp256k1zkp_v0_10_0_scalar) == 32) { memcpy(&sig->data[0], r, 32); memcpy(&sig->data[32], s, 32); } else { - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&sig->data[0], r); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&sig->data[32], s); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&sig->data[0], r); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&sig->data[32], s); } sig->data[64] = recid; } -int rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature* sig, const unsigned char *input64, int recid) { - rustsecp256k1zkp_v0_8_0_scalar r, s; +int rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_parse_compact(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature* sig, const unsigned char *input64, int recid) { + rustsecp256k1zkp_v0_10_0_scalar r, s; int ret = 1; int overflow = 0; @@ -45,110 +45,110 @@ int rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact(const rust ARG_CHECK(input64 != NULL); ARG_CHECK(recid >= 0 && recid <= 3); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&r, &input64[0], &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&r, &input64[0], &overflow); ret &= !overflow; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&s, &input64[32], &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&s, &input64[32], &overflow); ret &= !overflow; if (ret) { - rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_save(sig, &r, &s, recid); + rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_save(sig, &r, &s, recid); } else { memset(sig, 0, sizeof(*sig)); } return ret; } -int rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_serialize_compact(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *output64, int *recid, const rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature* sig) { - rustsecp256k1zkp_v0_8_0_scalar r, s; +int rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_serialize_compact(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *output64, int *recid, const rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature* sig) { + rustsecp256k1zkp_v0_10_0_scalar r, s; VERIFY_CHECK(ctx != NULL); ARG_CHECK(output64 != NULL); ARG_CHECK(sig != NULL); ARG_CHECK(recid != NULL); - rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_load(ctx, &r, &s, recid, sig); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&output64[0], &r); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&output64[32], &s); + rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_load(ctx, &r, &s, recid, sig); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&output64[0], &r); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&output64[32], &s); return 1; } -int rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_convert(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig, const rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature* sigin) { - rustsecp256k1zkp_v0_8_0_scalar r, s; +int rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_convert(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_ecdsa_signature* sig, const rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature* sigin) { + rustsecp256k1zkp_v0_10_0_scalar r, s; int recid; VERIFY_CHECK(ctx != NULL); ARG_CHECK(sig != NULL); ARG_CHECK(sigin != NULL); - rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_load(ctx, &r, &s, &recid, sigin); - rustsecp256k1zkp_v0_8_0_ecdsa_signature_save(sig, &r, &s); + rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_load(ctx, &r, &s, &recid, sigin); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_save(sig, &r, &s); return 1; } -static int rustsecp256k1zkp_v0_8_0_ecdsa_sig_recover(const rustsecp256k1zkp_v0_8_0_scalar *sigr, const rustsecp256k1zkp_v0_8_0_scalar* sigs, rustsecp256k1zkp_v0_8_0_ge *pubkey, const rustsecp256k1zkp_v0_8_0_scalar *message, int recid) { +static int rustsecp256k1zkp_v0_10_0_ecdsa_sig_recover(const rustsecp256k1zkp_v0_10_0_scalar *sigr, const rustsecp256k1zkp_v0_10_0_scalar* sigs, rustsecp256k1zkp_v0_10_0_ge *pubkey, const rustsecp256k1zkp_v0_10_0_scalar *message, int recid) { unsigned char brx[32]; - rustsecp256k1zkp_v0_8_0_fe fx; - rustsecp256k1zkp_v0_8_0_ge x; - rustsecp256k1zkp_v0_8_0_gej xj; - rustsecp256k1zkp_v0_8_0_scalar rn, u1, u2; - rustsecp256k1zkp_v0_8_0_gej qj; + rustsecp256k1zkp_v0_10_0_fe fx; + rustsecp256k1zkp_v0_10_0_ge x; + rustsecp256k1zkp_v0_10_0_gej xj; + rustsecp256k1zkp_v0_10_0_scalar rn, u1, u2; + rustsecp256k1zkp_v0_10_0_gej qj; int r; - if (rustsecp256k1zkp_v0_8_0_scalar_is_zero(sigr) || rustsecp256k1zkp_v0_8_0_scalar_is_zero(sigs)) { + if (rustsecp256k1zkp_v0_10_0_scalar_is_zero(sigr) || rustsecp256k1zkp_v0_10_0_scalar_is_zero(sigs)) { return 0; } - rustsecp256k1zkp_v0_8_0_scalar_get_b32(brx, sigr); - r = rustsecp256k1zkp_v0_8_0_fe_set_b32(&fx, brx); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(brx, sigr); + r = rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&fx, brx); (void)r; VERIFY_CHECK(r); /* brx comes from a scalar, so is less than the order; certainly less than p */ if (recid & 2) { - if (rustsecp256k1zkp_v0_8_0_fe_cmp_var(&fx, &rustsecp256k1zkp_v0_8_0_ecdsa_const_p_minus_order) >= 0) { + if (rustsecp256k1zkp_v0_10_0_fe_cmp_var(&fx, &rustsecp256k1zkp_v0_10_0_ecdsa_const_p_minus_order) >= 0) { return 0; } - rustsecp256k1zkp_v0_8_0_fe_add(&fx, &rustsecp256k1zkp_v0_8_0_ecdsa_const_order_as_fe); + rustsecp256k1zkp_v0_10_0_fe_add(&fx, &rustsecp256k1zkp_v0_10_0_ecdsa_const_order_as_fe); } - if (!rustsecp256k1zkp_v0_8_0_ge_set_xo_var(&x, &fx, recid & 1)) { + if (!rustsecp256k1zkp_v0_10_0_ge_set_xo_var(&x, &fx, recid & 1)) { return 0; } - rustsecp256k1zkp_v0_8_0_gej_set_ge(&xj, &x); - rustsecp256k1zkp_v0_8_0_scalar_inverse_var(&rn, sigr); - rustsecp256k1zkp_v0_8_0_scalar_mul(&u1, &rn, message); - rustsecp256k1zkp_v0_8_0_scalar_negate(&u1, &u1); - rustsecp256k1zkp_v0_8_0_scalar_mul(&u2, &rn, sigs); - rustsecp256k1zkp_v0_8_0_ecmult(&qj, &xj, &u2, &u1); - rustsecp256k1zkp_v0_8_0_ge_set_gej_var(pubkey, &qj); - return !rustsecp256k1zkp_v0_8_0_gej_is_infinity(&qj); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&xj, &x); + rustsecp256k1zkp_v0_10_0_scalar_inverse_var(&rn, sigr); + rustsecp256k1zkp_v0_10_0_scalar_mul(&u1, &rn, message); + rustsecp256k1zkp_v0_10_0_scalar_negate(&u1, &u1); + rustsecp256k1zkp_v0_10_0_scalar_mul(&u2, &rn, sigs); + rustsecp256k1zkp_v0_10_0_ecmult(&qj, &xj, &u2, &u1); + rustsecp256k1zkp_v0_10_0_ge_set_gej_var(pubkey, &qj); + return !rustsecp256k1zkp_v0_10_0_gej_is_infinity(&qj); } -int rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature *signature, const unsigned char *msghash32, const unsigned char *seckey, rustsecp256k1zkp_v0_8_0_nonce_function noncefp, const void* noncedata) { - rustsecp256k1zkp_v0_8_0_scalar r, s; +int rustsecp256k1zkp_v0_10_0_ecdsa_sign_recoverable(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature *signature, const unsigned char *msghash32, const unsigned char *seckey, rustsecp256k1zkp_v0_10_0_nonce_function noncefp, const void* noncedata) { + rustsecp256k1zkp_v0_10_0_scalar r, s; int ret, recid; VERIFY_CHECK(ctx != NULL); - ARG_CHECK(rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); ARG_CHECK(msghash32 != NULL); ARG_CHECK(signature != NULL); ARG_CHECK(seckey != NULL); - ret = rustsecp256k1zkp_v0_8_0_ecdsa_sign_inner(ctx, &r, &s, &recid, NULL, NULL, NULL, msghash32, seckey, noncefp, noncedata); - rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_save(signature, &r, &s, recid); + ret = rustsecp256k1zkp_v0_10_0_ecdsa_sign_inner(ctx, &r, &s, &recid, NULL, NULL, NULL, msghash32, seckey, noncefp, noncedata); + rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_save(signature, &r, &s, recid); return ret; } -int rustsecp256k1zkp_v0_8_0_ecdsa_recover(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pubkey *pubkey, const rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature *signature, const unsigned char *msghash32) { - rustsecp256k1zkp_v0_8_0_ge q; - rustsecp256k1zkp_v0_8_0_scalar r, s; - rustsecp256k1zkp_v0_8_0_scalar m; +int rustsecp256k1zkp_v0_10_0_ecdsa_recover(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_pubkey *pubkey, const rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature *signature, const unsigned char *msghash32) { + rustsecp256k1zkp_v0_10_0_ge q; + rustsecp256k1zkp_v0_10_0_scalar r, s; + rustsecp256k1zkp_v0_10_0_scalar m; int recid; VERIFY_CHECK(ctx != NULL); ARG_CHECK(msghash32 != NULL); ARG_CHECK(signature != NULL); ARG_CHECK(pubkey != NULL); - rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_load(ctx, &r, &s, &recid, signature); + rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_load(ctx, &r, &s, &recid, signature); VERIFY_CHECK(recid >= 0 && recid < 4); /* should have been caught in parse_compact */ - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&m, msghash32, NULL); - if (rustsecp256k1zkp_v0_8_0_ecdsa_sig_recover(&r, &s, &q, &m, recid)) { - rustsecp256k1zkp_v0_8_0_pubkey_save(pubkey, &q); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&m, msghash32, NULL); + if (rustsecp256k1zkp_v0_10_0_ecdsa_sig_recover(&r, &s, &q, &m, recid)) { + rustsecp256k1zkp_v0_10_0_pubkey_save(pubkey, &q); return 1; } else { memset(pubkey, 0, sizeof(*pubkey)); diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/recovery/tests_exhaustive_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/recovery/tests_exhaustive_impl.h index 9b6deadd..a462c7b6 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/recovery/tests_exhaustive_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/recovery/tests_exhaustive_impl.h @@ -7,10 +7,10 @@ #ifndef SECP256K1_MODULE_RECOVERY_EXHAUSTIVE_TESTS_H #define SECP256K1_MODULE_RECOVERY_EXHAUSTIVE_TESTS_H -#include "src/modules/recovery/main_impl.h" +#include "main_impl.h" #include "../../../include/secp256k1_recovery.h" -void test_exhaustive_recovery_sign(const rustsecp256k1zkp_v0_8_0_context *ctx, const rustsecp256k1zkp_v0_8_0_ge *group) { +static void test_exhaustive_recovery_sign(const rustsecp256k1zkp_v0_10_0_context *ctx, const rustsecp256k1zkp_v0_10_0_ge *group) { int i, j, k; uint64_t iter = 0; @@ -20,48 +20,47 @@ void test_exhaustive_recovery_sign(const rustsecp256k1zkp_v0_8_0_context *ctx, c if (skip_section(&iter)) continue; for (k = 1; k < EXHAUSTIVE_TEST_ORDER; k++) { /* nonce */ const int starting_k = k; - rustsecp256k1zkp_v0_8_0_fe r_dot_y_normalized; - rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature rsig; - rustsecp256k1zkp_v0_8_0_ecdsa_signature sig; - rustsecp256k1zkp_v0_8_0_scalar sk, msg, r, s, expected_r; + rustsecp256k1zkp_v0_10_0_fe r_dot_y_normalized; + rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature rsig; + rustsecp256k1zkp_v0_10_0_ecdsa_signature sig; + rustsecp256k1zkp_v0_10_0_scalar sk, msg, r, s, expected_r; unsigned char sk32[32], msg32[32]; int expected_recid; int recid; int overflow; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&msg, i); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&sk, j); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(sk32, &sk); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(msg32, &msg); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&msg, i); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&sk, j); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(sk32, &sk); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(msg32, &msg); - rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(ctx, &rsig, msg32, sk32, rustsecp256k1zkp_v0_8_0_nonce_function_smallint, &k); + rustsecp256k1zkp_v0_10_0_ecdsa_sign_recoverable(ctx, &rsig, msg32, sk32, rustsecp256k1zkp_v0_10_0_nonce_function_smallint, &k); /* Check directly */ - rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_load(ctx, &r, &s, &recid, &rsig); + rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_load(ctx, &r, &s, &recid, &rsig); r_from_k(&expected_r, group, k, &overflow); CHECK(r == expected_r); CHECK((k * s) % EXHAUSTIVE_TEST_ORDER == (i + r * j) % EXHAUSTIVE_TEST_ORDER || (k * (EXHAUSTIVE_TEST_ORDER - s)) % EXHAUSTIVE_TEST_ORDER == (i + r * j) % EXHAUSTIVE_TEST_ORDER); /* The recid's second bit is for conveying overflow (R.x value >= group order). * In the actual secp256k1 this is an astronomically unlikely event, but in the - * small group used here, it will be the case for all points except the ones where - * R.x=1 (which the group is specifically selected to have). + * small group used here, it will almost certainly be the case for all points. * Note that this isn't actually useful; full recovery would need to convey * floor(R.x / group_order), but only one bit is used as that is sufficient * in the real group. */ expected_recid = overflow ? 2 : 0; r_dot_y_normalized = group[k].y; - rustsecp256k1zkp_v0_8_0_fe_normalize(&r_dot_y_normalized); + rustsecp256k1zkp_v0_10_0_fe_normalize(&r_dot_y_normalized); /* Also the recovery id is flipped depending if we hit the low-s branch */ if ((k * s) % EXHAUSTIVE_TEST_ORDER == (i + r * j) % EXHAUSTIVE_TEST_ORDER) { - expected_recid |= rustsecp256k1zkp_v0_8_0_fe_is_odd(&r_dot_y_normalized); + expected_recid |= rustsecp256k1zkp_v0_10_0_fe_is_odd(&r_dot_y_normalized); } else { - expected_recid |= !rustsecp256k1zkp_v0_8_0_fe_is_odd(&r_dot_y_normalized); + expected_recid |= !rustsecp256k1zkp_v0_10_0_fe_is_odd(&r_dot_y_normalized); } CHECK(recid == expected_recid); /* Convert to a standard sig then check */ - rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_convert(ctx, &sig, &rsig); - rustsecp256k1zkp_v0_8_0_ecdsa_signature_load(ctx, &r, &s, &sig); + rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_convert(ctx, &sig, &rsig); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_load(ctx, &r, &s, &sig); /* Note that we compute expected_r *after* signing -- this is important * because our nonce-computing function function might change k during * signing. */ @@ -79,7 +78,7 @@ void test_exhaustive_recovery_sign(const rustsecp256k1zkp_v0_8_0_context *ctx, c } } -void test_exhaustive_recovery_verify(const rustsecp256k1zkp_v0_8_0_context *ctx, const rustsecp256k1zkp_v0_8_0_ge *group) { +static void test_exhaustive_recovery_verify(const rustsecp256k1zkp_v0_10_0_context *ctx, const rustsecp256k1zkp_v0_10_0_ge *group) { /* This is essentially a copy of test_exhaustive_verify, with recovery added */ int s, r, msg, key; uint64_t iter = 0; @@ -87,41 +86,41 @@ void test_exhaustive_recovery_verify(const rustsecp256k1zkp_v0_8_0_context *ctx, for (r = 1; r < EXHAUSTIVE_TEST_ORDER; r++) { for (msg = 1; msg < EXHAUSTIVE_TEST_ORDER; msg++) { for (key = 1; key < EXHAUSTIVE_TEST_ORDER; key++) { - rustsecp256k1zkp_v0_8_0_ge nonconst_ge; - rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature rsig; - rustsecp256k1zkp_v0_8_0_ecdsa_signature sig; - rustsecp256k1zkp_v0_8_0_pubkey pk; - rustsecp256k1zkp_v0_8_0_scalar sk_s, msg_s, r_s, s_s; - rustsecp256k1zkp_v0_8_0_scalar s_times_k_s, msg_plus_r_times_sk_s; + rustsecp256k1zkp_v0_10_0_ge nonconst_ge; + rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature rsig; + rustsecp256k1zkp_v0_10_0_ecdsa_signature sig; + rustsecp256k1zkp_v0_10_0_pubkey pk; + rustsecp256k1zkp_v0_10_0_scalar sk_s, msg_s, r_s, s_s; + rustsecp256k1zkp_v0_10_0_scalar s_times_k_s, msg_plus_r_times_sk_s; int recid = 0; int k, should_verify; unsigned char msg32[32]; if (skip_section(&iter)) continue; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&s_s, s); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&r_s, r); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&msg_s, msg); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&sk_s, key); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(msg32, &msg_s); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&s_s, s); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&r_s, r); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&msg_s, msg); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&sk_s, key); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(msg32, &msg_s); /* Verify by hand */ /* Run through every k value that gives us this r and check that *one* works. * Note there could be none, there could be multiple, ECDSA is weird. */ should_verify = 0; for (k = 0; k < EXHAUSTIVE_TEST_ORDER; k++) { - rustsecp256k1zkp_v0_8_0_scalar check_x_s; + rustsecp256k1zkp_v0_10_0_scalar check_x_s; r_from_k(&check_x_s, group, k, NULL); if (r_s == check_x_s) { - rustsecp256k1zkp_v0_8_0_scalar_set_int(&s_times_k_s, k); - rustsecp256k1zkp_v0_8_0_scalar_mul(&s_times_k_s, &s_times_k_s, &s_s); - rustsecp256k1zkp_v0_8_0_scalar_mul(&msg_plus_r_times_sk_s, &r_s, &sk_s); - rustsecp256k1zkp_v0_8_0_scalar_add(&msg_plus_r_times_sk_s, &msg_plus_r_times_sk_s, &msg_s); - should_verify |= rustsecp256k1zkp_v0_8_0_scalar_eq(&s_times_k_s, &msg_plus_r_times_sk_s); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&s_times_k_s, k); + rustsecp256k1zkp_v0_10_0_scalar_mul(&s_times_k_s, &s_times_k_s, &s_s); + rustsecp256k1zkp_v0_10_0_scalar_mul(&msg_plus_r_times_sk_s, &r_s, &sk_s); + rustsecp256k1zkp_v0_10_0_scalar_add(&msg_plus_r_times_sk_s, &msg_plus_r_times_sk_s, &msg_s); + should_verify |= rustsecp256k1zkp_v0_10_0_scalar_eq(&s_times_k_s, &msg_plus_r_times_sk_s); } } /* nb we have a "high s" rule */ - should_verify &= !rustsecp256k1zkp_v0_8_0_scalar_is_high(&s_s); + should_verify &= !rustsecp256k1zkp_v0_10_0_scalar_is_high(&s_s); /* We would like to try recovering the pubkey and checking that it matches, * but pubkey recovery is impossible in the exhaustive tests (the reason @@ -129,19 +128,19 @@ void test_exhaustive_recovery_verify(const rustsecp256k1zkp_v0_8_0_context *ctx, * overlap between the sets, so there are no valid signatures). */ /* Verify by converting to a standard signature and calling verify */ - rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_save(&rsig, &r_s, &s_s, recid); - rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_convert(ctx, &sig, &rsig); + rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_save(&rsig, &r_s, &s_s, recid); + rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_convert(ctx, &sig, &rsig); memcpy(&nonconst_ge, &group[sk_s], sizeof(nonconst_ge)); - rustsecp256k1zkp_v0_8_0_pubkey_save(&pk, &nonconst_ge); + rustsecp256k1zkp_v0_10_0_pubkey_save(&pk, &nonconst_ge); CHECK(should_verify == - rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &sig, msg32, &pk)); + rustsecp256k1zkp_v0_10_0_ecdsa_verify(ctx, &sig, msg32, &pk)); } } } } } -static void test_exhaustive_recovery(const rustsecp256k1zkp_v0_8_0_context *ctx, const rustsecp256k1zkp_v0_8_0_ge *group) { +static void test_exhaustive_recovery(const rustsecp256k1zkp_v0_10_0_context *ctx, const rustsecp256k1zkp_v0_10_0_ge *group) { test_exhaustive_recovery_sign(ctx, group); test_exhaustive_recovery_verify(ctx, group); } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/recovery/tests_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/recovery/tests_impl.h index ada80225..c497879f 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/recovery/tests_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/recovery/tests_impl.h @@ -25,23 +25,17 @@ static int recovery_test_nonce_function(unsigned char *nonce32, const unsigned c } /* On the next run, return a valid nonce, but flip a coin as to whether or not to fail signing. */ memset(nonce32, 1, 32); - return rustsecp256k1zkp_v0_8_0_testrand_bits(1); + return rustsecp256k1zkp_v0_10_0_testrand_bits(1); } -void test_ecdsa_recovery_api(void) { +static void test_ecdsa_recovery_api(void) { /* Setup contexts that just count errors */ - rustsecp256k1zkp_v0_8_0_context *none = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_NONE); - rustsecp256k1zkp_v0_8_0_context *sign = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN); - rustsecp256k1zkp_v0_8_0_context *vrfy = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_VERIFY); - rustsecp256k1zkp_v0_8_0_context *both = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); - rustsecp256k1zkp_v0_8_0_context *sttc = rustsecp256k1zkp_v0_8_0_context_clone(rustsecp256k1zkp_v0_8_0_context_no_precomp); - rustsecp256k1zkp_v0_8_0_pubkey pubkey; - rustsecp256k1zkp_v0_8_0_pubkey recpubkey; - rustsecp256k1zkp_v0_8_0_ecdsa_signature normal_sig; - rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature recsig; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_pubkey recpubkey; + rustsecp256k1zkp_v0_10_0_ecdsa_signature normal_sig; + rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature recsig; unsigned char privkey[32] = { 1 }; unsigned char message[32] = { 2 }; - int32_t ecount = 0; int recid = 0; unsigned char sig[74]; unsigned char zero_privkey[32] = { 0 }; @@ -50,169 +44,114 @@ void test_ecdsa_recovery_api(void) { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - rustsecp256k1zkp_v0_8_0_context_set_error_callback(none, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(sign, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(vrfy, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(both, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(sttc, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(none, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sign, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(vrfy, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(both, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sttc, counting_illegal_callback_fn, &ecount); - /* Construct and verify corresponding public key. */ - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, privkey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey, privkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_verify(CTX, privkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey, privkey) == 1); /* Check bad contexts and NULLs for signing */ - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(none, &recsig, message, privkey, NULL, NULL) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(sign, &recsig, message, privkey, NULL, NULL) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(vrfy, &recsig, message, privkey, NULL, NULL) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(both, &recsig, message, privkey, NULL, NULL) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(both, NULL, message, privkey, NULL, NULL) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(both, &recsig, NULL, privkey, NULL, NULL) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(both, &recsig, message, NULL, NULL, NULL) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(sttc, &recsig, message, privkey, NULL, NULL) == 0); - CHECK(ecount == 4); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign_recoverable(CTX, &recsig, message, privkey, NULL, NULL) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_sign_recoverable(CTX, NULL, message, privkey, NULL, NULL)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_sign_recoverable(CTX, &recsig, NULL, privkey, NULL, NULL)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_sign_recoverable(CTX, &recsig, message, NULL, NULL, NULL)); + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_ecdsa_sign_recoverable(STATIC_CTX, &recsig, message, privkey, NULL, NULL)); /* This will fail or succeed randomly, and in either case will not ARG_CHECK failure */ - rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(both, &recsig, message, privkey, recovery_test_nonce_function, NULL); - CHECK(ecount == 4); + rustsecp256k1zkp_v0_10_0_ecdsa_sign_recoverable(CTX, &recsig, message, privkey, recovery_test_nonce_function, NULL); /* These will all fail, but not in ARG_CHECK way */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(both, &recsig, message, zero_privkey, NULL, NULL) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(both, &recsig, message, over_privkey, NULL, NULL) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign_recoverable(CTX, &recsig, message, zero_privkey, NULL, NULL) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign_recoverable(CTX, &recsig, message, over_privkey, NULL, NULL) == 0); /* This one will succeed. */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(both, &recsig, message, privkey, NULL, NULL) == 1); - CHECK(ecount == 4); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign_recoverable(CTX, &recsig, message, privkey, NULL, NULL) == 1); /* Check signing with a goofy nonce function */ /* Check bad contexts and NULLs for recovery */ - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recover(none, &recpubkey, &recsig, message) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recover(sign, &recpubkey, &recsig, message) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recover(vrfy, &recpubkey, &recsig, message) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recover(both, &recpubkey, &recsig, message) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recover(both, NULL, &recsig, message) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recover(both, &recpubkey, NULL, message) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recover(both, &recpubkey, &recsig, NULL) == 0); - CHECK(ecount == 3); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recover(CTX, &recpubkey, &recsig, message) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_recover(CTX, NULL, &recsig, message)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_recover(CTX, &recpubkey, NULL, message)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_recover(CTX, &recpubkey, &recsig, NULL)); /* Check NULLs for conversion */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(both, &normal_sig, message, privkey, NULL, NULL) == 1); - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_convert(both, NULL, &recsig) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_convert(both, &normal_sig, NULL) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_convert(both, &normal_sig, &recsig) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &normal_sig, message, privkey, NULL, NULL) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_convert(CTX, NULL, &recsig)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_convert(CTX, &normal_sig, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_convert(CTX, &normal_sig, &recsig) == 1); /* Check NULLs for de/serialization */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(both, &recsig, message, privkey, NULL, NULL) == 1); - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_serialize_compact(both, NULL, &recid, &recsig) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_serialize_compact(both, sig, NULL, &recsig) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_serialize_compact(both, sig, &recid, NULL) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_serialize_compact(both, sig, &recid, &recsig) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign_recoverable(CTX, &recsig, message, privkey, NULL, NULL) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_serialize_compact(CTX, NULL, &recid, &recsig)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_serialize_compact(CTX, sig, NULL, &recsig)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_serialize_compact(CTX, sig, &recid, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_serialize_compact(CTX, sig, &recid, &recsig) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact(both, NULL, sig, recid) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact(both, &recsig, NULL, recid) == 0); - CHECK(ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact(both, &recsig, sig, -1) == 0); - CHECK(ecount == 6); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact(both, &recsig, sig, 5) == 0); - CHECK(ecount == 7); - /* overflow in signature will fail but not affect ecount */ + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_parse_compact(CTX, NULL, sig, recid)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_parse_compact(CTX, &recsig, NULL, recid)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_parse_compact(CTX, &recsig, sig, -1)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_parse_compact(CTX, &recsig, sig, 5)); + /* overflow in signature will not result in calling illegal_callback */ memcpy(sig, over_privkey, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact(both, &recsig, sig, recid) == 0); - CHECK(ecount == 7); - - /* cleanup */ - rustsecp256k1zkp_v0_8_0_context_destroy(none); - rustsecp256k1zkp_v0_8_0_context_destroy(sign); - rustsecp256k1zkp_v0_8_0_context_destroy(vrfy); - rustsecp256k1zkp_v0_8_0_context_destroy(both); - rustsecp256k1zkp_v0_8_0_context_destroy(sttc); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_parse_compact(CTX, &recsig, sig, recid) == 0); } -void test_ecdsa_recovery_end_to_end(void) { +static void test_ecdsa_recovery_end_to_end(void) { unsigned char extra[32] = {0x00}; unsigned char privkey[32]; unsigned char message[32]; - rustsecp256k1zkp_v0_8_0_ecdsa_signature signature[5]; - rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature rsignature[5]; + rustsecp256k1zkp_v0_10_0_ecdsa_signature signature[5]; + rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature rsignature[5]; unsigned char sig[74]; - rustsecp256k1zkp_v0_8_0_pubkey pubkey; - rustsecp256k1zkp_v0_8_0_pubkey recpubkey; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_pubkey recpubkey; int recid = 0; /* Generate a random key and message. */ { - rustsecp256k1zkp_v0_8_0_scalar msg, key; + rustsecp256k1zkp_v0_10_0_scalar msg, key; random_scalar_order_test(&msg); random_scalar_order_test(&key); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(privkey, &key); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(message, &msg); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(privkey, &key); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(message, &msg); } /* Construct and verify corresponding public key. */ - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, privkey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey, privkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_verify(CTX, privkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey, privkey) == 1); /* Serialize/parse compact and verify/recover. */ extra[0] = 0; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(ctx, &rsignature[0], message, privkey, NULL, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &signature[0], message, privkey, NULL, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(ctx, &rsignature[4], message, privkey, NULL, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(ctx, &rsignature[1], message, privkey, NULL, extra) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign_recoverable(CTX, &rsignature[0], message, privkey, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &signature[0], message, privkey, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign_recoverable(CTX, &rsignature[4], message, privkey, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign_recoverable(CTX, &rsignature[1], message, privkey, NULL, extra) == 1); extra[31] = 1; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(ctx, &rsignature[2], message, privkey, NULL, extra) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign_recoverable(CTX, &rsignature[2], message, privkey, NULL, extra) == 1); extra[31] = 0; extra[0] = 1; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(ctx, &rsignature[3], message, privkey, NULL, extra) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_serialize_compact(ctx, sig, &recid, &rsignature[4]) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_convert(ctx, &signature[4], &rsignature[4]) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&signature[4], &signature[0], 64) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &signature[4], message, &pubkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign_recoverable(CTX, &rsignature[3], message, privkey, NULL, extra) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_serialize_compact(CTX, sig, &recid, &rsignature[4]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_convert(CTX, &signature[4], &rsignature[4]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&signature[4], &signature[0], 64) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &signature[4], message, &pubkey) == 1); memset(&rsignature[4], 0, sizeof(rsignature[4])); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact(ctx, &rsignature[4], sig, recid) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_convert(ctx, &signature[4], &rsignature[4]) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &signature[4], message, &pubkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_parse_compact(CTX, &rsignature[4], sig, recid) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_convert(CTX, &signature[4], &rsignature[4]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &signature[4], message, &pubkey) == 1); /* Parse compact (with recovery id) and recover. */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact(ctx, &rsignature[4], sig, recid) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recover(ctx, &recpubkey, &rsignature[4], message) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, &recpubkey, sizeof(pubkey)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_parse_compact(CTX, &rsignature[4], sig, recid) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recover(CTX, &recpubkey, &rsignature[4], message) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, &recpubkey, sizeof(pubkey)) == 0); /* Serialize/destroy/parse signature and verify again. */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_serialize_compact(ctx, sig, &recid, &rsignature[4]) == 1); - sig[rustsecp256k1zkp_v0_8_0_testrand_bits(6)] += 1 + rustsecp256k1zkp_v0_8_0_testrand_int(255); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact(ctx, &rsignature[4], sig, recid) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_convert(ctx, &signature[4], &rsignature[4]) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &signature[4], message, &pubkey) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_serialize_compact(CTX, sig, &recid, &rsignature[4]) == 1); + sig[rustsecp256k1zkp_v0_10_0_testrand_bits(6)] += 1 + rustsecp256k1zkp_v0_10_0_testrand_int(255); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_parse_compact(CTX, &rsignature[4], sig, recid) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_convert(CTX, &signature[4], &rsignature[4]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &signature[4], message, &pubkey) == 0); /* Recover again */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recover(ctx, &recpubkey, &rsignature[4], message) == 0 || - rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, &recpubkey, sizeof(pubkey)) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recover(CTX, &recpubkey, &rsignature[4], message) == 0 || + rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, &recpubkey, sizeof(pubkey)) != 0); } /* Tests several edge cases. */ -void test_ecdsa_recovery_edge_cases(void) { +static void test_ecdsa_recovery_edge_cases(void) { const unsigned char msg32[32] = { 'T', 'h', 'i', 's', ' ', 'i', 's', ' ', 'a', ' ', 'v', 'e', 'r', 'y', ' ', 's', @@ -231,7 +170,7 @@ void test_ecdsa_recovery_edge_cases(void) { 0x7D, 0xD7, 0x3E, 0x38, 0x7E, 0xE4, 0xFC, 0x86, 0x6E, 0x1B, 0xE8, 0xEC, 0xC7, 0xDD, 0x95, 0x57 }; - rustsecp256k1zkp_v0_8_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; /* signature (r,s) = (4,4), which can be recovered with all 4 recids. */ const unsigned char sigb64[64] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -243,19 +182,19 @@ void test_ecdsa_recovery_edge_cases(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, }; - rustsecp256k1zkp_v0_8_0_pubkey pubkeyb; - rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature rsig; - rustsecp256k1zkp_v0_8_0_ecdsa_signature sig; + rustsecp256k1zkp_v0_10_0_pubkey pubkeyb; + rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature rsig; + rustsecp256k1zkp_v0_10_0_ecdsa_signature sig; int recid; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact(ctx, &rsig, sig64, 0)); - CHECK(!rustsecp256k1zkp_v0_8_0_ecdsa_recover(ctx, &pubkey, &rsig, msg32)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact(ctx, &rsig, sig64, 1)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recover(ctx, &pubkey, &rsig, msg32)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact(ctx, &rsig, sig64, 2)); - CHECK(!rustsecp256k1zkp_v0_8_0_ecdsa_recover(ctx, &pubkey, &rsig, msg32)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact(ctx, &rsig, sig64, 3)); - CHECK(!rustsecp256k1zkp_v0_8_0_ecdsa_recover(ctx, &pubkey, &rsig, msg32)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_parse_compact(CTX, &rsig, sig64, 0)); + CHECK(!rustsecp256k1zkp_v0_10_0_ecdsa_recover(CTX, &pubkey, &rsig, msg32)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_parse_compact(CTX, &rsig, sig64, 1)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recover(CTX, &pubkey, &rsig, msg32)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_parse_compact(CTX, &rsig, sig64, 2)); + CHECK(!rustsecp256k1zkp_v0_10_0_ecdsa_recover(CTX, &pubkey, &rsig, msg32)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_parse_compact(CTX, &rsig, sig64, 3)); + CHECK(!rustsecp256k1zkp_v0_10_0_ecdsa_recover(CTX, &pubkey, &rsig, msg32)); for (recid = 0; recid < 4; recid++) { int i; @@ -300,40 +239,40 @@ void test_ecdsa_recovery_edge_cases(void) { 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x45, 0x02, 0x01, 0x04 }; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact(ctx, &rsig, sigb64, recid) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recover(ctx, &pubkeyb, &rsig, msg32) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &sig, sigbder, sizeof(sigbder)) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &sig, msg32, &pubkeyb) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_parse_compact(CTX, &rsig, sigb64, recid) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recover(CTX, &pubkeyb, &rsig, msg32) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &sig, sigbder, sizeof(sigbder)) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &sig, msg32, &pubkeyb) == 1); for (recid2 = 0; recid2 < 4; recid2++) { - rustsecp256k1zkp_v0_8_0_pubkey pubkey2b; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact(ctx, &rsig, sigb64, recid2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recover(ctx, &pubkey2b, &rsig, msg32) == 1); + rustsecp256k1zkp_v0_10_0_pubkey pubkey2b; + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_parse_compact(CTX, &rsig, sigb64, recid2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recover(CTX, &pubkey2b, &rsig, msg32) == 1); /* Verifying with (order + r,4) should always fail. */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &sig, sigbderlong, sizeof(sigbderlong)) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &sig, msg32, &pubkeyb) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &sig, sigbderlong, sizeof(sigbderlong)) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &sig, msg32, &pubkeyb) == 0); } /* DER parsing tests. */ /* Zero length r/s. */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &sig, sigcder_zr, sizeof(sigcder_zr)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &sig, sigcder_zs, sizeof(sigcder_zs)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &sig, sigcder_zr, sizeof(sigcder_zr)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &sig, sigcder_zs, sizeof(sigcder_zs)) == 0); /* Leading zeros. */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &sig, sigbderalt1, sizeof(sigbderalt1)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &sig, sigbderalt2, sizeof(sigbderalt2)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &sig, sigbderalt3, sizeof(sigbderalt3)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &sig, sigbderalt4, sizeof(sigbderalt4)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &sig, sigbderalt1, sizeof(sigbderalt1)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &sig, sigbderalt2, sizeof(sigbderalt2)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &sig, sigbderalt3, sizeof(sigbderalt3)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &sig, sigbderalt4, sizeof(sigbderalt4)) == 0); sigbderalt3[4] = 1; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &sig, sigbderalt3, sizeof(sigbderalt3)) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &sig, msg32, &pubkeyb) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &sig, sigbderalt3, sizeof(sigbderalt3)) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &sig, msg32, &pubkeyb) == 0); sigbderalt4[7] = 1; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &sig, sigbderalt4, sizeof(sigbderalt4)) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &sig, msg32, &pubkeyb) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &sig, sigbderalt4, sizeof(sigbderalt4)) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &sig, msg32, &pubkeyb) == 0); /* Damage signature. */ sigbder[7]++; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &sig, sigbder, sizeof(sigbder)) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &sig, msg32, &pubkeyb) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &sig, sigbder, sizeof(sigbder)) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &sig, msg32, &pubkeyb) == 0); sigbder[7]--; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &sig, sigbder, 6) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &sig, sigbder, sizeof(sigbder) - 1) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &sig, sigbder, 6) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &sig, sigbder, sizeof(sigbder) - 1) == 0); for(i = 0; i < 8; i++) { int c; unsigned char orig = sigbder[i]; @@ -343,7 +282,7 @@ void test_ecdsa_recovery_edge_cases(void) { continue; } sigbder[i] = c; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &sig, sigbder, sizeof(sigbder)) == 0 || rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &sig, msg32, &pubkeyb) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &sig, sigbder, sizeof(sigbder)) == 0 || rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &sig, msg32, &pubkeyb) == 0); } sigbder[i] = orig; } @@ -363,34 +302,34 @@ void test_ecdsa_recovery_edge_cases(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }; - rustsecp256k1zkp_v0_8_0_pubkey pubkeyc; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact(ctx, &rsig, sigc64, 0) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recover(ctx, &pubkeyc, &rsig, msg32) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &sig, sigcder, sizeof(sigcder)) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &sig, msg32, &pubkeyc) == 1); + rustsecp256k1zkp_v0_10_0_pubkey pubkeyc; + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_parse_compact(CTX, &rsig, sigc64, 0) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recover(CTX, &pubkeyc, &rsig, msg32) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &sig, sigcder, sizeof(sigcder)) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &sig, msg32, &pubkeyc) == 1); sigcder[4] = 0; sigc64[31] = 0; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact(ctx, &rsig, sigc64, 0) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recover(ctx, &pubkeyb, &rsig, msg32) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &sig, sigcder, sizeof(sigcder)) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &sig, msg32, &pubkeyc) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_parse_compact(CTX, &rsig, sigc64, 0) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recover(CTX, &pubkeyb, &rsig, msg32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &sig, sigcder, sizeof(sigcder)) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &sig, msg32, &pubkeyc) == 0); sigcder[4] = 1; sigcder[7] = 0; sigc64[31] = 1; sigc64[63] = 0; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_parse_compact(ctx, &rsig, sigc64, 0) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recover(ctx, &pubkeyb, &rsig, msg32) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &sig, sigcder, sizeof(sigcder)) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &sig, msg32, &pubkeyc) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recoverable_signature_parse_compact(CTX, &rsig, sigc64, 0) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_recover(CTX, &pubkeyb, &rsig, msg32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &sig, sigcder, sizeof(sigcder)) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &sig, msg32, &pubkeyc) == 0); } } -void run_recovery_tests(void) { +static void run_recovery_tests(void) { int i; - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { test_ecdsa_recovery_api(); } - for (i = 0; i < 64*count; i++) { + for (i = 0; i < 64*COUNT; i++) { test_ecdsa_recovery_end_to_end(); } test_ecdsa_recovery_edge_cases(); diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig/Makefile.am.include b/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig/Makefile.am.include index 300a8ecf..9180b4ef 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig/Makefile.am.include +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig/Makefile.am.include @@ -1,4 +1,4 @@ -include_HEADERS += include/rustsecp256k1zkp_v0_8_0_schnorrsig.h +include_HEADERS += include/rustsecp256k1zkp_v0_10_0_schnorrsig.h noinst_HEADERS += src/modules/schnorrsig/main_impl.h noinst_HEADERS += src/modules/schnorrsig/tests_impl.h noinst_HEADERS += src/modules/schnorrsig/tests_exhaustive_impl.h diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig/bench_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig/bench_impl.h index 47f83df6..f1709863 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig/bench_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig/bench_impl.h @@ -12,16 +12,16 @@ #define MSGLEN 32 typedef struct { - rustsecp256k1zkp_v0_8_0_context *ctx; + rustsecp256k1zkp_v0_10_0_context *ctx; int n; - const rustsecp256k1zkp_v0_8_0_keypair **keypairs; + const rustsecp256k1zkp_v0_10_0_keypair **keypairs; const unsigned char **pk; const unsigned char **sigs; const unsigned char **msgs; } bench_schnorrsig_data; -void bench_schnorrsig_sign(void* arg, int iters) { +static void bench_schnorrsig_sign(void* arg, int iters) { bench_schnorrsig_data *data = (bench_schnorrsig_data *)arg; int i; unsigned char msg[MSGLEN] = {0}; @@ -30,28 +30,28 @@ void bench_schnorrsig_sign(void* arg, int iters) { for (i = 0; i < iters; i++) { msg[0] = i; msg[1] = i >> 8; - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(data->ctx, sig, msg, MSGLEN, data->keypairs[i], NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(data->ctx, sig, msg, MSGLEN, data->keypairs[i], NULL)); } } -void bench_schnorrsig_verify(void* arg, int iters) { +static void bench_schnorrsig_verify(void* arg, int iters) { bench_schnorrsig_data *data = (bench_schnorrsig_data *)arg; int i; for (i = 0; i < iters; i++) { - rustsecp256k1zkp_v0_8_0_xonly_pubkey pk; - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(data->ctx, &pk, data->pk[i]) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(data->ctx, data->sigs[i], data->msgs[i], MSGLEN, &pk)); + rustsecp256k1zkp_v0_10_0_xonly_pubkey pk; + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(data->ctx, &pk, data->pk[i]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(data->ctx, data->sigs[i], data->msgs[i], MSGLEN, &pk)); } } -void run_schnorrsig_bench(int iters, int argc, char** argv) { +static void run_schnorrsig_bench(int iters, int argc, char** argv) { int i; bench_schnorrsig_data data; int d = argc == 1; - data.ctx = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_VERIFY | SECP256K1_CONTEXT_SIGN); - data.keypairs = (const rustsecp256k1zkp_v0_8_0_keypair **)malloc(iters * sizeof(rustsecp256k1zkp_v0_8_0_keypair *)); + data.ctx = rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_CONTEXT_NONE); + data.keypairs = (const rustsecp256k1zkp_v0_10_0_keypair **)malloc(iters * sizeof(rustsecp256k1zkp_v0_10_0_keypair *)); data.pk = (const unsigned char **)malloc(iters * sizeof(unsigned char *)); data.msgs = (const unsigned char **)malloc(iters * sizeof(unsigned char *)); data.sigs = (const unsigned char **)malloc(iters * sizeof(unsigned char *)); @@ -61,9 +61,9 @@ void run_schnorrsig_bench(int iters, int argc, char** argv) { unsigned char sk[32]; unsigned char *msg = (unsigned char *)malloc(MSGLEN); unsigned char *sig = (unsigned char *)malloc(64); - rustsecp256k1zkp_v0_8_0_keypair *keypair = (rustsecp256k1zkp_v0_8_0_keypair *)malloc(sizeof(*keypair)); + rustsecp256k1zkp_v0_10_0_keypair *keypair = (rustsecp256k1zkp_v0_10_0_keypair *)malloc(sizeof(*keypair)); unsigned char *pk_char = (unsigned char *)malloc(32); - rustsecp256k1zkp_v0_8_0_xonly_pubkey pk; + rustsecp256k1zkp_v0_10_0_xonly_pubkey pk; msg[0] = sk[0] = i; msg[1] = sk[1] = i >> 8; msg[2] = sk[2] = i >> 16; @@ -76,10 +76,10 @@ void run_schnorrsig_bench(int iters, int argc, char** argv) { data.msgs[i] = msg; data.sigs[i] = sig; - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(data.ctx, keypair, sk)); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(data.ctx, sig, msg, MSGLEN, keypair, NULL)); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(data.ctx, &pk, NULL, keypair)); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(data.ctx, pk_char, &pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(data.ctx, keypair, sk)); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(data.ctx, sig, msg, MSGLEN, keypair, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(data.ctx, &pk, NULL, keypair)); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(data.ctx, pk_char, &pk) == 1); } if (d || have_flag(argc, argv, "schnorrsig") || have_flag(argc, argv, "sign") || have_flag(argc, argv, "schnorrsig_sign")) run_benchmark("schnorrsig_sign", bench_schnorrsig_sign, NULL, NULL, (void *) &data, 10, iters); @@ -91,12 +91,14 @@ void run_schnorrsig_bench(int iters, int argc, char** argv) { free((void *)data.msgs[i]); free((void *)data.sigs[i]); } - free(data.keypairs); - free(data.pk); - free(data.msgs); - free(data.sigs); - rustsecp256k1zkp_v0_8_0_context_destroy(data.ctx); + /* Casting to (void *) avoids a stupid warning in MSVC. */ + free((void *)data.keypairs); + free((void *)data.pk); + free((void *)data.msgs); + free((void *)data.sigs); + + rustsecp256k1zkp_v0_10_0_context_destroy(data.ctx); } #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig/main_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig/main_impl.h index 20059687..4585383a 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig/main_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig/main_impl.h @@ -13,8 +13,8 @@ /* Initializes SHA256 with fixed midstate. This midstate was computed by applying * SHA256 to SHA256("BIP0340/nonce")||SHA256("BIP0340/nonce"). */ -static void rustsecp256k1zkp_v0_8_0_nonce_function_bip340_sha256_tagged(rustsecp256k1zkp_v0_8_0_sha256 *sha) { - rustsecp256k1zkp_v0_8_0_sha256_initialize(sha); +static void rustsecp256k1zkp_v0_10_0_nonce_function_bip340_sha256_tagged(rustsecp256k1zkp_v0_10_0_sha256 *sha) { + rustsecp256k1zkp_v0_10_0_sha256_initialize(sha); sha->s[0] = 0x46615b35ul; sha->s[1] = 0xf4bfbff7ul; sha->s[2] = 0x9f8dc671ul; @@ -29,8 +29,8 @@ static void rustsecp256k1zkp_v0_8_0_nonce_function_bip340_sha256_tagged(rustsecp /* Initializes SHA256 with fixed midstate. This midstate was computed by applying * SHA256 to SHA256("BIP0340/aux")||SHA256("BIP0340/aux"). */ -static void rustsecp256k1zkp_v0_8_0_nonce_function_bip340_sha256_tagged_aux(rustsecp256k1zkp_v0_8_0_sha256 *sha) { - rustsecp256k1zkp_v0_8_0_sha256_initialize(sha); +static void rustsecp256k1zkp_v0_10_0_nonce_function_bip340_sha256_tagged_aux(rustsecp256k1zkp_v0_10_0_sha256 *sha) { + rustsecp256k1zkp_v0_10_0_sha256_initialize(sha); sha->s[0] = 0x24dd3219ul; sha->s[1] = 0x4eba7e70ul; sha->s[2] = 0xca0fabb9ul; @@ -50,7 +50,7 @@ static const unsigned char bip340_algo[13] = "BIP0340/nonce"; static const unsigned char schnorrsig_extraparams_magic[4] = SECP256K1_SCHNORRSIG_EXTRAPARAMS_MAGIC; static int nonce_function_bip340(unsigned char *nonce32, const unsigned char *msg, size_t msglen, const unsigned char *key32, const unsigned char *xonly_pk32, const unsigned char *algo, size_t algolen, void *data) { - rustsecp256k1zkp_v0_8_0_sha256 sha; + rustsecp256k1zkp_v0_10_0_sha256 sha; unsigned char masked_key[32]; int i; @@ -59,9 +59,9 @@ static int nonce_function_bip340(unsigned char *nonce32, const unsigned char *ms } if (data != NULL) { - rustsecp256k1zkp_v0_8_0_nonce_function_bip340_sha256_tagged_aux(&sha); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, data, 32); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, masked_key); + rustsecp256k1zkp_v0_10_0_nonce_function_bip340_sha256_tagged_aux(&sha); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, data, 32); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, masked_key); for (i = 0; i < 32; i++) { masked_key[i] ^= key32[i]; } @@ -82,26 +82,26 @@ static int nonce_function_bip340(unsigned char *nonce32, const unsigned char *ms * algorithms. If this nonce function is used in BIP-340 signing as defined * in the spec, an optimized tagging implementation is used. */ if (algolen == sizeof(bip340_algo) - && rustsecp256k1zkp_v0_8_0_memcmp_var(algo, bip340_algo, algolen) == 0) { - rustsecp256k1zkp_v0_8_0_nonce_function_bip340_sha256_tagged(&sha); + && rustsecp256k1zkp_v0_10_0_memcmp_var(algo, bip340_algo, algolen) == 0) { + rustsecp256k1zkp_v0_10_0_nonce_function_bip340_sha256_tagged(&sha); } else { - rustsecp256k1zkp_v0_8_0_sha256_initialize_tagged(&sha, algo, algolen); + rustsecp256k1zkp_v0_10_0_sha256_initialize_tagged(&sha, algo, algolen); } /* Hash masked-key||pk||msg using the tagged hash as per the spec */ - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, masked_key, 32); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, xonly_pk32, 32); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, msg, msglen); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, nonce32); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, masked_key, 32); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, xonly_pk32, 32); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, msg, msglen); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, nonce32); return 1; } -const rustsecp256k1zkp_v0_8_0_nonce_function_hardened rustsecp256k1zkp_v0_8_0_nonce_function_bip340 = nonce_function_bip340; +const rustsecp256k1zkp_v0_10_0_nonce_function_hardened rustsecp256k1zkp_v0_10_0_nonce_function_bip340 = nonce_function_bip340; /* Initializes SHA256 with fixed midstate. This midstate was computed by applying * SHA256 to SHA256("BIP0340/challenge")||SHA256("BIP0340/challenge"). */ -static void rustsecp256k1zkp_v0_8_0_schnorrsig_sha256_tagged(rustsecp256k1zkp_v0_8_0_sha256 *sha) { - rustsecp256k1zkp_v0_8_0_sha256_initialize(sha); +static void rustsecp256k1zkp_v0_10_0_schnorrsig_sha256_tagged(rustsecp256k1zkp_v0_10_0_sha256 *sha) { + rustsecp256k1zkp_v0_10_0_sha256_initialize(sha); sha->s[0] = 0x9cecba11ul; sha->s[1] = 0x23925381ul; sha->s[2] = 0x11679112ul; @@ -113,117 +113,117 @@ static void rustsecp256k1zkp_v0_8_0_schnorrsig_sha256_tagged(rustsecp256k1zkp_v0 sha->bytes = 64; } -static void rustsecp256k1zkp_v0_8_0_schnorrsig_challenge(rustsecp256k1zkp_v0_8_0_scalar* e, const unsigned char *r32, const unsigned char *msg, size_t msglen, const unsigned char *pubkey32) +static void rustsecp256k1zkp_v0_10_0_schnorrsig_challenge(rustsecp256k1zkp_v0_10_0_scalar* e, const unsigned char *r32, const unsigned char *msg, size_t msglen, const unsigned char *pubkey32) { unsigned char buf[32]; - rustsecp256k1zkp_v0_8_0_sha256 sha; + rustsecp256k1zkp_v0_10_0_sha256 sha; /* tagged hash(r.x, pk.x, msg) */ - rustsecp256k1zkp_v0_8_0_schnorrsig_sha256_tagged(&sha); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, r32, 32); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, pubkey32, 32); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, msg, msglen); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, buf); + rustsecp256k1zkp_v0_10_0_schnorrsig_sha256_tagged(&sha); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, r32, 32); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, pubkey32, 32); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, msg, msglen); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, buf); /* Set scalar e to the challenge hash modulo the curve order as per * BIP340. */ - rustsecp256k1zkp_v0_8_0_scalar_set_b32(e, buf, NULL); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(e, buf, NULL); } -static int rustsecp256k1zkp_v0_8_0_schnorrsig_sign_internal(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *sig64, const unsigned char *msg, size_t msglen, const rustsecp256k1zkp_v0_8_0_keypair *keypair, rustsecp256k1zkp_v0_8_0_nonce_function_hardened noncefp, void *ndata) { - rustsecp256k1zkp_v0_8_0_scalar sk; - rustsecp256k1zkp_v0_8_0_scalar e; - rustsecp256k1zkp_v0_8_0_scalar k; - rustsecp256k1zkp_v0_8_0_gej rj; - rustsecp256k1zkp_v0_8_0_ge pk; - rustsecp256k1zkp_v0_8_0_ge r; +static int rustsecp256k1zkp_v0_10_0_schnorrsig_sign_internal(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *sig64, const unsigned char *msg, size_t msglen, const rustsecp256k1zkp_v0_10_0_keypair *keypair, rustsecp256k1zkp_v0_10_0_nonce_function_hardened noncefp, void *ndata) { + rustsecp256k1zkp_v0_10_0_scalar sk; + rustsecp256k1zkp_v0_10_0_scalar e; + rustsecp256k1zkp_v0_10_0_scalar k; + rustsecp256k1zkp_v0_10_0_gej rj; + rustsecp256k1zkp_v0_10_0_ge pk; + rustsecp256k1zkp_v0_10_0_ge r; unsigned char buf[32] = { 0 }; unsigned char pk_buf[32]; unsigned char seckey[32]; int ret = 1; VERIFY_CHECK(ctx != NULL); - ARG_CHECK(rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); ARG_CHECK(sig64 != NULL); ARG_CHECK(msg != NULL || msglen == 0); ARG_CHECK(keypair != NULL); if (noncefp == NULL) { - noncefp = rustsecp256k1zkp_v0_8_0_nonce_function_bip340; + noncefp = rustsecp256k1zkp_v0_10_0_nonce_function_bip340; } - ret &= rustsecp256k1zkp_v0_8_0_keypair_load(ctx, &sk, &pk, keypair); + ret &= rustsecp256k1zkp_v0_10_0_keypair_load(ctx, &sk, &pk, keypair); /* Because we are signing for a x-only pubkey, the secret key is negated * before signing if the point corresponding to the secret key does not * have an even Y. */ - if (rustsecp256k1zkp_v0_8_0_fe_is_odd(&pk.y)) { - rustsecp256k1zkp_v0_8_0_scalar_negate(&sk, &sk); + if (rustsecp256k1zkp_v0_10_0_fe_is_odd(&pk.y)) { + rustsecp256k1zkp_v0_10_0_scalar_negate(&sk, &sk); } - rustsecp256k1zkp_v0_8_0_scalar_get_b32(seckey, &sk); - rustsecp256k1zkp_v0_8_0_fe_get_b32(pk_buf, &pk.x); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(seckey, &sk); + rustsecp256k1zkp_v0_10_0_fe_get_b32(pk_buf, &pk.x); ret &= !!noncefp(buf, msg, msglen, seckey, pk_buf, bip340_algo, sizeof(bip340_algo), ndata); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&k, buf, NULL); - ret &= !rustsecp256k1zkp_v0_8_0_scalar_is_zero(&k); - rustsecp256k1zkp_v0_8_0_scalar_cmov(&k, &rustsecp256k1zkp_v0_8_0_scalar_one, !ret); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&k, buf, NULL); + ret &= !rustsecp256k1zkp_v0_10_0_scalar_is_zero(&k); + rustsecp256k1zkp_v0_10_0_scalar_cmov(&k, &rustsecp256k1zkp_v0_10_0_scalar_one, !ret); - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &rj, &k); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&r, &rj); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&ctx->ecmult_gen_ctx, &rj, &k); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&r, &rj); /* We declassify r to allow using it as a branch point. This is fine * because r is not a secret. */ - rustsecp256k1zkp_v0_8_0_declassify(ctx, &r, sizeof(r)); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&r.y); - if (rustsecp256k1zkp_v0_8_0_fe_is_odd(&r.y)) { - rustsecp256k1zkp_v0_8_0_scalar_negate(&k, &k); + rustsecp256k1zkp_v0_10_0_declassify(ctx, &r, sizeof(r)); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&r.y); + if (rustsecp256k1zkp_v0_10_0_fe_is_odd(&r.y)) { + rustsecp256k1zkp_v0_10_0_scalar_negate(&k, &k); } - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&r.x); - rustsecp256k1zkp_v0_8_0_fe_get_b32(&sig64[0], &r.x); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&r.x); + rustsecp256k1zkp_v0_10_0_fe_get_b32(&sig64[0], &r.x); - rustsecp256k1zkp_v0_8_0_schnorrsig_challenge(&e, &sig64[0], msg, msglen, pk_buf); - rustsecp256k1zkp_v0_8_0_scalar_mul(&e, &e, &sk); - rustsecp256k1zkp_v0_8_0_scalar_add(&e, &e, &k); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&sig64[32], &e); + rustsecp256k1zkp_v0_10_0_schnorrsig_challenge(&e, &sig64[0], msg, msglen, pk_buf); + rustsecp256k1zkp_v0_10_0_scalar_mul(&e, &e, &sk); + rustsecp256k1zkp_v0_10_0_scalar_add(&e, &e, &k); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&sig64[32], &e); - rustsecp256k1zkp_v0_8_0_memczero(sig64, 64, !ret); - rustsecp256k1zkp_v0_8_0_scalar_clear(&k); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sk); + rustsecp256k1zkp_v0_10_0_memczero(sig64, 64, !ret); + rustsecp256k1zkp_v0_10_0_scalar_clear(&k); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sk); memset(seckey, 0, sizeof(seckey)); return ret; } -int rustsecp256k1zkp_v0_8_0_schnorrsig_sign32(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *sig64, const unsigned char *msg32, const rustsecp256k1zkp_v0_8_0_keypair *keypair, const unsigned char *aux_rand32) { +int rustsecp256k1zkp_v0_10_0_schnorrsig_sign32(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *sig64, const unsigned char *msg32, const rustsecp256k1zkp_v0_10_0_keypair *keypair, const unsigned char *aux_rand32) { /* We cast away const from the passed aux_rand32 argument since we know the default nonce function does not modify it. */ - return rustsecp256k1zkp_v0_8_0_schnorrsig_sign_internal(ctx, sig64, msg32, 32, keypair, rustsecp256k1zkp_v0_8_0_nonce_function_bip340, (unsigned char*)aux_rand32); + return rustsecp256k1zkp_v0_10_0_schnorrsig_sign_internal(ctx, sig64, msg32, 32, keypair, rustsecp256k1zkp_v0_10_0_nonce_function_bip340, (unsigned char*)aux_rand32); } -int rustsecp256k1zkp_v0_8_0_schnorrsig_sign(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *sig64, const unsigned char *msg32, const rustsecp256k1zkp_v0_8_0_keypair *keypair, const unsigned char *aux_rand32) { - return rustsecp256k1zkp_v0_8_0_schnorrsig_sign32(ctx, sig64, msg32, keypair, aux_rand32); +int rustsecp256k1zkp_v0_10_0_schnorrsig_sign(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *sig64, const unsigned char *msg32, const rustsecp256k1zkp_v0_10_0_keypair *keypair, const unsigned char *aux_rand32) { + return rustsecp256k1zkp_v0_10_0_schnorrsig_sign32(ctx, sig64, msg32, keypair, aux_rand32); } -int rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *sig64, const unsigned char *msg, size_t msglen, const rustsecp256k1zkp_v0_8_0_keypair *keypair, rustsecp256k1zkp_v0_8_0_schnorrsig_extraparams *extraparams) { - rustsecp256k1zkp_v0_8_0_nonce_function_hardened noncefp = NULL; +int rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *sig64, const unsigned char *msg, size_t msglen, const rustsecp256k1zkp_v0_10_0_keypair *keypair, rustsecp256k1zkp_v0_10_0_schnorrsig_extraparams *extraparams) { + rustsecp256k1zkp_v0_10_0_nonce_function_hardened noncefp = NULL; void *ndata = NULL; VERIFY_CHECK(ctx != NULL); if (extraparams != NULL) { - ARG_CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(extraparams->magic, + ARG_CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(extraparams->magic, schnorrsig_extraparams_magic, sizeof(extraparams->magic)) == 0); noncefp = extraparams->noncefp; ndata = extraparams->ndata; } - return rustsecp256k1zkp_v0_8_0_schnorrsig_sign_internal(ctx, sig64, msg, msglen, keypair, noncefp, ndata); + return rustsecp256k1zkp_v0_10_0_schnorrsig_sign_internal(ctx, sig64, msg, msglen, keypair, noncefp, ndata); } -int rustsecp256k1zkp_v0_8_0_schnorrsig_verify(const rustsecp256k1zkp_v0_8_0_context* ctx, const unsigned char *sig64, const unsigned char *msg, size_t msglen, const rustsecp256k1zkp_v0_8_0_xonly_pubkey *pubkey) { - rustsecp256k1zkp_v0_8_0_scalar s; - rustsecp256k1zkp_v0_8_0_scalar e; - rustsecp256k1zkp_v0_8_0_gej rj; - rustsecp256k1zkp_v0_8_0_ge pk; - rustsecp256k1zkp_v0_8_0_gej pkj; - rustsecp256k1zkp_v0_8_0_fe rx; - rustsecp256k1zkp_v0_8_0_ge r; +int rustsecp256k1zkp_v0_10_0_schnorrsig_verify(const rustsecp256k1zkp_v0_10_0_context* ctx, const unsigned char *sig64, const unsigned char *msg, size_t msglen, const rustsecp256k1zkp_v0_10_0_xonly_pubkey *pubkey) { + rustsecp256k1zkp_v0_10_0_scalar s; + rustsecp256k1zkp_v0_10_0_scalar e; + rustsecp256k1zkp_v0_10_0_gej rj; + rustsecp256k1zkp_v0_10_0_ge pk; + rustsecp256k1zkp_v0_10_0_gej pkj; + rustsecp256k1zkp_v0_10_0_fe rx; + rustsecp256k1zkp_v0_10_0_ge r; unsigned char buf[32]; int overflow; @@ -232,36 +232,36 @@ int rustsecp256k1zkp_v0_8_0_schnorrsig_verify(const rustsecp256k1zkp_v0_8_0_cont ARG_CHECK(msg != NULL || msglen == 0); ARG_CHECK(pubkey != NULL); - if (!rustsecp256k1zkp_v0_8_0_fe_set_b32(&rx, &sig64[0])) { + if (!rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&rx, &sig64[0])) { return 0; } - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&s, &sig64[32], &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&s, &sig64[32], &overflow); if (overflow) { return 0; } - if (!rustsecp256k1zkp_v0_8_0_xonly_pubkey_load(ctx, &pk, pubkey)) { + if (!rustsecp256k1zkp_v0_10_0_xonly_pubkey_load(ctx, &pk, pubkey)) { return 0; } /* Compute e. */ - rustsecp256k1zkp_v0_8_0_fe_get_b32(buf, &pk.x); - rustsecp256k1zkp_v0_8_0_schnorrsig_challenge(&e, &sig64[0], msg, msglen, buf); + rustsecp256k1zkp_v0_10_0_fe_get_b32(buf, &pk.x); + rustsecp256k1zkp_v0_10_0_schnorrsig_challenge(&e, &sig64[0], msg, msglen, buf); /* Compute rj = s*G + (-e)*pkj */ - rustsecp256k1zkp_v0_8_0_scalar_negate(&e, &e); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&pkj, &pk); - rustsecp256k1zkp_v0_8_0_ecmult(&rj, &pkj, &e, &s); + rustsecp256k1zkp_v0_10_0_scalar_negate(&e, &e); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&pkj, &pk); + rustsecp256k1zkp_v0_10_0_ecmult(&rj, &pkj, &e, &s); - rustsecp256k1zkp_v0_8_0_ge_set_gej_var(&r, &rj); - if (rustsecp256k1zkp_v0_8_0_ge_is_infinity(&r)) { + rustsecp256k1zkp_v0_10_0_ge_set_gej_var(&r, &rj); + if (rustsecp256k1zkp_v0_10_0_ge_is_infinity(&r)) { return 0; } - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&r.y); - return !rustsecp256k1zkp_v0_8_0_fe_is_odd(&r.y) && - rustsecp256k1zkp_v0_8_0_fe_equal_var(&rx, &r.x); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&r.y); + return !rustsecp256k1zkp_v0_10_0_fe_is_odd(&r.y) && + rustsecp256k1zkp_v0_10_0_fe_equal(&rx, &r.x); } #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig/tests_exhaustive_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig/tests_exhaustive_impl.h index 24cf19e6..18ae9891 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig/tests_exhaustive_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig/tests_exhaustive_impl.h @@ -8,7 +8,7 @@ #define SECP256K1_MODULE_SCHNORRSIG_TESTS_EXHAUSTIVE_H #include "../../../include/secp256k1_schnorrsig.h" -#include "src/modules/schnorrsig/main_impl.h" +#include "main_impl.h" static const unsigned char invalid_pubkey_bytes[][32] = { /* 0 */ @@ -58,12 +58,12 @@ static const unsigned char invalid_pubkey_bytes[][32] = { #define NUM_INVALID_KEYS (sizeof(invalid_pubkey_bytes) / sizeof(invalid_pubkey_bytes[0])) -static int rustsecp256k1zkp_v0_8_0_hardened_nonce_function_smallint(unsigned char *nonce32, const unsigned char *msg, +static int rustsecp256k1zkp_v0_10_0_hardened_nonce_function_smallint(unsigned char *nonce32, const unsigned char *msg, size_t msglen, const unsigned char *key32, const unsigned char *xonly_pk32, const unsigned char *algo, size_t algolen, void* data) { - rustsecp256k1zkp_v0_8_0_scalar s; + rustsecp256k1zkp_v0_10_0_scalar s; int *idata = data; (void)msg; (void)msglen; @@ -71,12 +71,12 @@ static int rustsecp256k1zkp_v0_8_0_hardened_nonce_function_smallint(unsigned cha (void)xonly_pk32; (void)algo; (void)algolen; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&s, *idata); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(nonce32, &s); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&s, *idata); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(nonce32, &s); return 1; } -static void test_exhaustive_schnorrsig_verify(const rustsecp256k1zkp_v0_8_0_context *ctx, const rustsecp256k1zkp_v0_8_0_xonly_pubkey* pubkeys, unsigned char (*xonly_pubkey_bytes)[32], const int* parities) { +static void test_exhaustive_schnorrsig_verify(const rustsecp256k1zkp_v0_10_0_context *ctx, const rustsecp256k1zkp_v0_10_0_xonly_pubkey* pubkeys, unsigned char (*xonly_pubkey_bytes)[32], const int* parities) { int d; uint64_t iter = 0; /* Iterate over the possible public keys to verify against (through their corresponding DL d). */ @@ -102,28 +102,28 @@ static void test_exhaustive_schnorrsig_verify(const rustsecp256k1zkp_v0_8_0_cont } /* Randomly generate messages until all challenges have been hit. */ while (e_count_done < EXHAUSTIVE_TEST_ORDER) { - rustsecp256k1zkp_v0_8_0_scalar e; + rustsecp256k1zkp_v0_10_0_scalar e; unsigned char msg32[32]; - rustsecp256k1zkp_v0_8_0_testrand256(msg32); - rustsecp256k1zkp_v0_8_0_schnorrsig_challenge(&e, sig64, msg32, sizeof(msg32), pk32); + rustsecp256k1zkp_v0_10_0_testrand256(msg32); + rustsecp256k1zkp_v0_10_0_schnorrsig_challenge(&e, sig64, msg32, sizeof(msg32), pk32); /* Only do work if we hit a challenge we haven't tried before. */ if (!e_done[e]) { /* Iterate over the possible valid last 32 bytes in the signature. 0..order=that s value; order+1=random bytes */ - int count_valid = 0, s; + int count_valid = 0; + unsigned int s; for (s = 0; s <= EXHAUSTIVE_TEST_ORDER + 1; ++s) { int expect_valid, valid; if (s <= EXHAUSTIVE_TEST_ORDER) { - rustsecp256k1zkp_v0_8_0_scalar s_s; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&s_s, s); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(sig64 + 32, &s_s); + memset(sig64 + 32, 0, 32); + rustsecp256k1zkp_v0_10_0_write_be32(sig64 + 60, s); expect_valid = actual_k != -1 && s != EXHAUSTIVE_TEST_ORDER && - (s_s == (actual_k + actual_d * e) % EXHAUSTIVE_TEST_ORDER); + (s == (actual_k + actual_d * e) % EXHAUSTIVE_TEST_ORDER); } else { - rustsecp256k1zkp_v0_8_0_testrand256(sig64 + 32); + rustsecp256k1zkp_v0_10_0_testrand256(sig64 + 32); expect_valid = 0; } - valid = rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, sig64, msg32, sizeof(msg32), &pubkeys[d - 1]); + valid = rustsecp256k1zkp_v0_10_0_schnorrsig_verify(ctx, sig64, msg32, sizeof(msg32), &pubkeys[d - 1]); CHECK(valid == expect_valid); count_valid += valid; } @@ -138,10 +138,10 @@ static void test_exhaustive_schnorrsig_verify(const rustsecp256k1zkp_v0_8_0_cont } } -static void test_exhaustive_schnorrsig_sign(const rustsecp256k1zkp_v0_8_0_context *ctx, unsigned char (*xonly_pubkey_bytes)[32], const rustsecp256k1zkp_v0_8_0_keypair* keypairs, const int* parities) { +static void test_exhaustive_schnorrsig_sign(const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char (*xonly_pubkey_bytes)[32], const rustsecp256k1zkp_v0_10_0_keypair* keypairs, const int* parities) { int d, k; uint64_t iter = 0; - rustsecp256k1zkp_v0_8_0_schnorrsig_extraparams extraparams = SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT; + rustsecp256k1zkp_v0_10_0_schnorrsig_extraparams extraparams = SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT; /* Loop over keys. */ for (d = 1; d < EXHAUSTIVE_TEST_ORDER; ++d) { @@ -155,25 +155,25 @@ static void test_exhaustive_schnorrsig_sign(const rustsecp256k1zkp_v0_8_0_contex unsigned char sig64[64]; int actual_k = k; if (skip_section(&iter)) continue; - extraparams.noncefp = rustsecp256k1zkp_v0_8_0_hardened_nonce_function_smallint; + extraparams.noncefp = rustsecp256k1zkp_v0_10_0_hardened_nonce_function_smallint; extraparams.ndata = &k; if (parities[k - 1]) actual_k = EXHAUSTIVE_TEST_ORDER - k; /* Generate random messages until all challenges have been tried. */ while (e_count_done < EXHAUSTIVE_TEST_ORDER) { - rustsecp256k1zkp_v0_8_0_scalar e; - rustsecp256k1zkp_v0_8_0_testrand256(msg32); - rustsecp256k1zkp_v0_8_0_schnorrsig_challenge(&e, xonly_pubkey_bytes[k - 1], msg32, sizeof(msg32), xonly_pubkey_bytes[d - 1]); + rustsecp256k1zkp_v0_10_0_scalar e; + rustsecp256k1zkp_v0_10_0_testrand256(msg32); + rustsecp256k1zkp_v0_10_0_schnorrsig_challenge(&e, xonly_pubkey_bytes[k - 1], msg32, sizeof(msg32), xonly_pubkey_bytes[d - 1]); /* Only do work if we hit a challenge we haven't tried before. */ if (!e_done[e]) { - rustsecp256k1zkp_v0_8_0_scalar expected_s = (actual_k + e * actual_d) % EXHAUSTIVE_TEST_ORDER; + rustsecp256k1zkp_v0_10_0_scalar expected_s = (actual_k + e * actual_d) % EXHAUSTIVE_TEST_ORDER; unsigned char expected_s_bytes[32]; - rustsecp256k1zkp_v0_8_0_scalar_get_b32(expected_s_bytes, &expected_s); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(expected_s_bytes, &expected_s); /* Invoke the real function to construct a signature. */ - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(ctx, sig64, msg32, sizeof(msg32), &keypairs[d - 1], &extraparams)); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(ctx, sig64, msg32, sizeof(msg32), &keypairs[d - 1], &extraparams)); /* The first 32 bytes must match the xonly pubkey for the specified k. */ - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(sig64, xonly_pubkey_bytes[k - 1], 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(sig64, xonly_pubkey_bytes[k - 1], 32) == 0); /* The last 32 bytes must match the expected s value. */ - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(sig64 + 32, expected_s_bytes, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(sig64 + 32, expected_s_bytes, 32) == 0); /* Don't retry other messages that result in the same challenge. */ e_done[e] = 1; ++e_count_done; @@ -183,28 +183,28 @@ static void test_exhaustive_schnorrsig_sign(const rustsecp256k1zkp_v0_8_0_contex } } -static void test_exhaustive_schnorrsig(const rustsecp256k1zkp_v0_8_0_context *ctx) { - rustsecp256k1zkp_v0_8_0_keypair keypair[EXHAUSTIVE_TEST_ORDER - 1]; - rustsecp256k1zkp_v0_8_0_xonly_pubkey xonly_pubkey[EXHAUSTIVE_TEST_ORDER - 1]; +static void test_exhaustive_schnorrsig(const rustsecp256k1zkp_v0_10_0_context *ctx) { + rustsecp256k1zkp_v0_10_0_keypair keypair[EXHAUSTIVE_TEST_ORDER - 1]; + rustsecp256k1zkp_v0_10_0_xonly_pubkey xonly_pubkey[EXHAUSTIVE_TEST_ORDER - 1]; int parity[EXHAUSTIVE_TEST_ORDER - 1]; unsigned char xonly_pubkey_bytes[EXHAUSTIVE_TEST_ORDER - 1][32]; unsigned i; /* Verify that all invalid_pubkey_bytes are actually invalid. */ for (i = 0; i < NUM_INVALID_KEYS; ++i) { - rustsecp256k1zkp_v0_8_0_xonly_pubkey pk; - CHECK(!rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(ctx, &pk, invalid_pubkey_bytes[i])); + rustsecp256k1zkp_v0_10_0_xonly_pubkey pk; + CHECK(!rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(ctx, &pk, invalid_pubkey_bytes[i])); } /* Construct keypairs and xonly-pubkeys for the entire group. */ for (i = 1; i < EXHAUSTIVE_TEST_ORDER; ++i) { - rustsecp256k1zkp_v0_8_0_scalar scalar_i; + rustsecp256k1zkp_v0_10_0_scalar scalar_i; unsigned char buf[32]; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&scalar_i, i); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(buf, &scalar_i); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair[i - 1], buf)); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(ctx, &xonly_pubkey[i - 1], &parity[i - 1], &keypair[i - 1])); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(ctx, xonly_pubkey_bytes[i - 1], &xonly_pubkey[i - 1])); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&scalar_i, i); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(buf, &scalar_i); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(ctx, &keypair[i - 1], buf)); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(ctx, &xonly_pubkey[i - 1], &parity[i - 1], &keypair[i - 1])); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(ctx, xonly_pubkey_bytes[i - 1], &xonly_pubkey[i - 1])); } test_exhaustive_schnorrsig_sign(ctx, xonly_pubkey_bytes, keypair, parity); diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig/tests_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig/tests_impl.h index 5c6a76de..1b87817c 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig/tests_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig/tests_impl.h @@ -12,32 +12,21 @@ /* Checks that a bit flip in the n_flip-th argument (that has n_bytes many * bytes) changes the hash function */ -void nonce_function_bip340_bitflip(unsigned char **args, size_t n_flip, size_t n_bytes, size_t msglen, size_t algolen) { +static void nonce_function_bip340_bitflip(unsigned char **args, size_t n_flip, size_t n_bytes, size_t msglen, size_t algolen) { unsigned char nonces[2][32]; CHECK(nonce_function_bip340(nonces[0], args[0], msglen, args[1], args[2], args[3], algolen, args[4]) == 1); - rustsecp256k1zkp_v0_8_0_testrand_flip(args[n_flip], n_bytes); + rustsecp256k1zkp_v0_10_0_testrand_flip(args[n_flip], n_bytes); CHECK(nonce_function_bip340(nonces[1], args[0], msglen, args[1], args[2], args[3], algolen, args[4]) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(nonces[0], nonces[1], 32) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(nonces[0], nonces[1], 32) != 0); } -/* Tests for the equality of two sha256 structs. This function only produces a - * correct result if an integer multiple of 64 many bytes have been written - * into the hash functions. */ -void test_sha256_eq(const rustsecp256k1zkp_v0_8_0_sha256 *sha1, const rustsecp256k1zkp_v0_8_0_sha256 *sha2) { - /* Is buffer fully consumed? */ - CHECK((sha1->bytes & 0x3F) == 0); - - CHECK(sha1->bytes == sha2->bytes); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(sha1->s, sha2->s, sizeof(sha1->s)) == 0); -} - -void run_nonce_function_bip340_tests(void) { +static void run_nonce_function_bip340_tests(void) { unsigned char tag[13] = "BIP0340/nonce"; unsigned char aux_tag[11] = "BIP0340/aux"; unsigned char algo[13] = "BIP0340/nonce"; size_t algolen = sizeof(algo); - rustsecp256k1zkp_v0_8_0_sha256 sha; - rustsecp256k1zkp_v0_8_0_sha256 sha_optimized; + rustsecp256k1zkp_v0_10_0_sha256 sha; + rustsecp256k1zkp_v0_10_0_sha256 sha_optimized; unsigned char nonce[32], nonce_z[32]; unsigned char msg[32]; size_t msglen = sizeof(msg); @@ -48,23 +37,23 @@ void run_nonce_function_bip340_tests(void) { int i; /* Check that hash initialized by - * rustsecp256k1zkp_v0_8_0_nonce_function_bip340_sha256_tagged has the expected + * rustsecp256k1zkp_v0_10_0_nonce_function_bip340_sha256_tagged has the expected * state. */ - rustsecp256k1zkp_v0_8_0_sha256_initialize_tagged(&sha, tag, sizeof(tag)); - rustsecp256k1zkp_v0_8_0_nonce_function_bip340_sha256_tagged(&sha_optimized); + rustsecp256k1zkp_v0_10_0_sha256_initialize_tagged(&sha, tag, sizeof(tag)); + rustsecp256k1zkp_v0_10_0_nonce_function_bip340_sha256_tagged(&sha_optimized); test_sha256_eq(&sha, &sha_optimized); /* Check that hash initialized by - * rustsecp256k1zkp_v0_8_0_nonce_function_bip340_sha256_tagged_aux has the expected + * rustsecp256k1zkp_v0_10_0_nonce_function_bip340_sha256_tagged_aux has the expected * state. */ - rustsecp256k1zkp_v0_8_0_sha256_initialize_tagged(&sha, aux_tag, sizeof(aux_tag)); - rustsecp256k1zkp_v0_8_0_nonce_function_bip340_sha256_tagged_aux(&sha_optimized); + rustsecp256k1zkp_v0_10_0_sha256_initialize_tagged(&sha, aux_tag, sizeof(aux_tag)); + rustsecp256k1zkp_v0_10_0_nonce_function_bip340_sha256_tagged_aux(&sha_optimized); test_sha256_eq(&sha, &sha_optimized); - rustsecp256k1zkp_v0_8_0_testrand256(msg); - rustsecp256k1zkp_v0_8_0_testrand256(key); - rustsecp256k1zkp_v0_8_0_testrand256(pk); - rustsecp256k1zkp_v0_8_0_testrand256(aux_rand); + rustsecp256k1zkp_v0_10_0_testrand256(msg); + rustsecp256k1zkp_v0_10_0_testrand256(key); + rustsecp256k1zkp_v0_10_0_testrand256(pk); + rustsecp256k1zkp_v0_10_0_testrand256(aux_rand); /* Check that a bitflip in an argument results in different nonces. */ args[0] = msg; @@ -72,7 +61,7 @@ void run_nonce_function_bip340_tests(void) { args[2] = pk; args[3] = algo; args[4] = aux_rand; - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { nonce_function_bip340_bitflip(args, 0, 32, msglen, algolen); nonce_function_bip340_bitflip(args, 1, 32, msglen, algolen); nonce_function_bip340_bitflip(args, 2, 32, msglen, algolen); @@ -87,187 +76,134 @@ void run_nonce_function_bip340_tests(void) { CHECK(nonce_function_bip340(nonce, msg, msglen, key, pk, NULL, 0, NULL) == 0); CHECK(nonce_function_bip340(nonce, msg, msglen, key, pk, algo, algolen, NULL) == 1); /* Other algo is fine */ - rustsecp256k1zkp_v0_8_0_testrand_bytes_test(algo, algolen); + rustsecp256k1zkp_v0_10_0_testrand_bytes_test(algo, algolen); CHECK(nonce_function_bip340(nonce, msg, msglen, key, pk, algo, algolen, NULL) == 1); - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { unsigned char nonce2[32]; - uint32_t offset = rustsecp256k1zkp_v0_8_0_testrand_int(msglen - 1); + uint32_t offset = rustsecp256k1zkp_v0_10_0_testrand_int(msglen - 1); size_t msglen_tmp = (msglen + offset) % msglen; size_t algolen_tmp; /* Different msglen gives different nonce */ CHECK(nonce_function_bip340(nonce2, msg, msglen_tmp, key, pk, algo, algolen, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(nonce, nonce2, 32) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(nonce, nonce2, 32) != 0); /* Different algolen gives different nonce */ - offset = rustsecp256k1zkp_v0_8_0_testrand_int(algolen - 1); + offset = rustsecp256k1zkp_v0_10_0_testrand_int(algolen - 1); algolen_tmp = (algolen + offset) % algolen; CHECK(nonce_function_bip340(nonce2, msg, msglen, key, pk, algo, algolen_tmp, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(nonce, nonce2, 32) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(nonce, nonce2, 32) != 0); } /* NULL aux_rand argument is allowed, and identical to passing all zero aux_rand. */ memset(aux_rand, 0, 32); CHECK(nonce_function_bip340(nonce_z, msg, msglen, key, pk, algo, algolen, &aux_rand) == 1); CHECK(nonce_function_bip340(nonce, msg, msglen, key, pk, algo, algolen, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(nonce_z, nonce, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(nonce_z, nonce, 32) == 0); } -void test_schnorrsig_api(void) { +static void test_schnorrsig_api(void) { unsigned char sk1[32]; unsigned char sk2[32]; unsigned char sk3[32]; unsigned char msg[32]; - rustsecp256k1zkp_v0_8_0_keypair keypairs[3]; - rustsecp256k1zkp_v0_8_0_keypair invalid_keypair = {{ 0 }}; - rustsecp256k1zkp_v0_8_0_xonly_pubkey pk[3]; - rustsecp256k1zkp_v0_8_0_xonly_pubkey zero_pk; + rustsecp256k1zkp_v0_10_0_keypair keypairs[3]; + rustsecp256k1zkp_v0_10_0_keypair invalid_keypair = {{ 0 }}; + rustsecp256k1zkp_v0_10_0_xonly_pubkey pk[3]; + rustsecp256k1zkp_v0_10_0_xonly_pubkey zero_pk; unsigned char sig[64]; - rustsecp256k1zkp_v0_8_0_schnorrsig_extraparams extraparams = SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT; - rustsecp256k1zkp_v0_8_0_schnorrsig_extraparams invalid_extraparams = {{ 0 }, NULL, NULL}; - - /** setup **/ - rustsecp256k1zkp_v0_8_0_context *none = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_NONE); - rustsecp256k1zkp_v0_8_0_context *sign = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN); - rustsecp256k1zkp_v0_8_0_context *vrfy = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_VERIFY); - rustsecp256k1zkp_v0_8_0_context *both = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); - rustsecp256k1zkp_v0_8_0_context *sttc = rustsecp256k1zkp_v0_8_0_context_clone(rustsecp256k1zkp_v0_8_0_context_no_precomp); - int ecount; - - rustsecp256k1zkp_v0_8_0_context_set_error_callback(none, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(sign, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(vrfy, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(both, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(sttc, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(none, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sign, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(vrfy, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(both, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sttc, counting_illegal_callback_fn, &ecount); - - rustsecp256k1zkp_v0_8_0_testrand256(sk1); - rustsecp256k1zkp_v0_8_0_testrand256(sk2); - rustsecp256k1zkp_v0_8_0_testrand256(sk3); - rustsecp256k1zkp_v0_8_0_testrand256(msg); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypairs[0], sk1) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypairs[1], sk2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypairs[2], sk3) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(ctx, &pk[0], NULL, &keypairs[0]) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(ctx, &pk[1], NULL, &keypairs[1]) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(ctx, &pk[2], NULL, &keypairs[2]) == 1); + rustsecp256k1zkp_v0_10_0_schnorrsig_extraparams extraparams = SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT; + rustsecp256k1zkp_v0_10_0_schnorrsig_extraparams invalid_extraparams = {{ 0 }, NULL, NULL}; + + rustsecp256k1zkp_v0_10_0_testrand256(sk1); + rustsecp256k1zkp_v0_10_0_testrand256(sk2); + rustsecp256k1zkp_v0_10_0_testrand256(sk3); + rustsecp256k1zkp_v0_10_0_testrand256(msg); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypairs[0], sk1) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypairs[1], sk2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypairs[2], sk3) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(CTX, &pk[0], NULL, &keypairs[0]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(CTX, &pk[1], NULL, &keypairs[1]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(CTX, &pk[2], NULL, &keypairs[2]) == 1); memset(&zero_pk, 0, sizeof(zero_pk)); /** main test body **/ - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign32(none, sig, msg, &keypairs[0], NULL) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign32(vrfy, sig, msg, &keypairs[0], NULL) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign32(sign, sig, msg, &keypairs[0], NULL) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign32(sign, NULL, msg, &keypairs[0], NULL) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign32(sign, sig, NULL, &keypairs[0], NULL) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign32(sign, sig, msg, NULL, NULL) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign32(sign, sig, msg, &invalid_keypair, NULL) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign32(sttc, sig, msg, &keypairs[0], NULL) == 0); - CHECK(ecount == 5); - - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(none, sig, msg, sizeof(msg), &keypairs[0], &extraparams) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(vrfy, sig, msg, sizeof(msg), &keypairs[0], &extraparams) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(sign, sig, msg, sizeof(msg), &keypairs[0], &extraparams) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(sign, NULL, msg, sizeof(msg), &keypairs[0], &extraparams) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(sign, sig, NULL, sizeof(msg), &keypairs[0], &extraparams) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(sign, sig, NULL, 0, &keypairs[0], &extraparams) == 1); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(sign, sig, msg, sizeof(msg), NULL, &extraparams) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(sign, sig, msg, sizeof(msg), &invalid_keypair, &extraparams) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(sign, sig, msg, sizeof(msg), &keypairs[0], NULL) == 1); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(sign, sig, msg, sizeof(msg), &keypairs[0], &invalid_extraparams) == 0); - CHECK(ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(sttc, sig, msg, sizeof(msg), &keypairs[0], &extraparams) == 0); - CHECK(ecount == 6); - - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign32(sign, sig, msg, &keypairs[0], NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(none, sig, msg, sizeof(msg), &pk[0]) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(sign, sig, msg, sizeof(msg), &pk[0]) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(vrfy, sig, msg, sizeof(msg), &pk[0]) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(vrfy, NULL, msg, sizeof(msg), &pk[0]) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(vrfy, sig, NULL, sizeof(msg), &pk[0]) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(vrfy, sig, NULL, 0, &pk[0]) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(vrfy, sig, msg, sizeof(msg), NULL) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(vrfy, sig, msg, sizeof(msg), &zero_pk) == 0); - CHECK(ecount == 4); - - rustsecp256k1zkp_v0_8_0_context_destroy(none); - rustsecp256k1zkp_v0_8_0_context_destroy(sign); - rustsecp256k1zkp_v0_8_0_context_destroy(vrfy); - rustsecp256k1zkp_v0_8_0_context_destroy(both); - rustsecp256k1zkp_v0_8_0_context_destroy(sttc); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign32(CTX, sig, msg, &keypairs[0], NULL) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_sign32(CTX, NULL, msg, &keypairs[0], NULL)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_sign32(CTX, sig, NULL, &keypairs[0], NULL)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_sign32(CTX, sig, msg, NULL, NULL)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_sign32(CTX, sig, msg, &invalid_keypair, NULL)); + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_sign32(STATIC_CTX, sig, msg, &keypairs[0], NULL)); + + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(CTX, sig, msg, sizeof(msg), &keypairs[0], &extraparams) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(CTX, NULL, msg, sizeof(msg), &keypairs[0], &extraparams)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(CTX, sig, NULL, sizeof(msg), &keypairs[0], &extraparams)); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(CTX, sig, NULL, 0, &keypairs[0], &extraparams) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(CTX, sig, msg, sizeof(msg), NULL, &extraparams)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(CTX, sig, msg, sizeof(msg), &invalid_keypair, &extraparams)); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(CTX, sig, msg, sizeof(msg), &keypairs[0], NULL) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(CTX, sig, msg, sizeof(msg), &keypairs[0], &invalid_extraparams)); + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(STATIC_CTX, sig, msg, sizeof(msg), &keypairs[0], &extraparams)); + + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign32(CTX, sig, msg, &keypairs[0], NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig, msg, sizeof(msg), &pk[0]) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, NULL, msg, sizeof(msg), &pk[0])); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig, NULL, sizeof(msg), &pk[0])); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig, NULL, 0, &pk[0]) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig, msg, sizeof(msg), NULL)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig, msg, sizeof(msg), &zero_pk)); } -/* Checks that hash initialized by rustsecp256k1zkp_v0_8_0_schnorrsig_sha256_tagged has the +/* Checks that hash initialized by rustsecp256k1zkp_v0_10_0_schnorrsig_sha256_tagged has the * expected state. */ -void test_schnorrsig_sha256_tagged(void) { +static void test_schnorrsig_sha256_tagged(void) { unsigned char tag[17] = "BIP0340/challenge"; - rustsecp256k1zkp_v0_8_0_sha256 sha; - rustsecp256k1zkp_v0_8_0_sha256 sha_optimized; + rustsecp256k1zkp_v0_10_0_sha256 sha; + rustsecp256k1zkp_v0_10_0_sha256 sha_optimized; - rustsecp256k1zkp_v0_8_0_sha256_initialize_tagged(&sha, (unsigned char *) tag, sizeof(tag)); - rustsecp256k1zkp_v0_8_0_schnorrsig_sha256_tagged(&sha_optimized); + rustsecp256k1zkp_v0_10_0_sha256_initialize_tagged(&sha, (unsigned char *) tag, sizeof(tag)); + rustsecp256k1zkp_v0_10_0_schnorrsig_sha256_tagged(&sha_optimized); test_sha256_eq(&sha, &sha_optimized); } /* Helper function for schnorrsig_bip_vectors * Signs the message and checks that it's the same as expected_sig. */ -void test_schnorrsig_bip_vectors_check_signing(const unsigned char *sk, const unsigned char *pk_serialized, const unsigned char *aux_rand, const unsigned char *msg32, const unsigned char *expected_sig) { +static void test_schnorrsig_bip_vectors_check_signing(const unsigned char *sk, const unsigned char *pk_serialized, const unsigned char *aux_rand, const unsigned char *msg, size_t msglen, const unsigned char *expected_sig) { unsigned char sig[64]; - rustsecp256k1zkp_v0_8_0_keypair keypair; - rustsecp256k1zkp_v0_8_0_xonly_pubkey pk, pk_expected; - - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, sk)); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign32(ctx, sig, msg32, &keypair, aux_rand)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(sig, expected_sig, 64) == 0); + rustsecp256k1zkp_v0_10_0_keypair keypair; + rustsecp256k1zkp_v0_10_0_xonly_pubkey pk, pk_expected; + + rustsecp256k1zkp_v0_10_0_schnorrsig_extraparams extraparams = SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT; + extraparams.ndata = (unsigned char*)aux_rand; + + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk)); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(CTX, sig, msg, msglen, &keypair, &extraparams)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(sig, expected_sig, 64) == 0); + if (msglen == 32) { + memset(sig, 0, 64); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign32(CTX, sig, msg, &keypair, aux_rand)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(sig, expected_sig, 64) == 0); + } - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(ctx, &pk_expected, pk_serialized)); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(ctx, &pk, NULL, &keypair)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pk, &pk_expected, sizeof(pk)) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, sig, msg32, 32, &pk)); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(CTX, &pk_expected, pk_serialized)); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(CTX, &pk, NULL, &keypair)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pk, &pk_expected, sizeof(pk)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig, msg, msglen, &pk)); } /* Helper function for schnorrsig_bip_vectors * Checks that both verify and verify_batch (TODO) return the same value as expected. */ -void test_schnorrsig_bip_vectors_check_verify(const unsigned char *pk_serialized, const unsigned char *msg32, const unsigned char *sig, int expected) { - rustsecp256k1zkp_v0_8_0_xonly_pubkey pk; +static void test_schnorrsig_bip_vectors_check_verify(const unsigned char *pk_serialized, const unsigned char *msg, size_t msglen, const unsigned char *sig, int expected) { + rustsecp256k1zkp_v0_10_0_xonly_pubkey pk; - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(ctx, &pk, pk_serialized)); - CHECK(expected == rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, sig, msg32, 32, &pk)); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(CTX, &pk, pk_serialized)); + CHECK(expected == rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig, msg, msglen, &pk)); } /* Test vectors according to BIP-340 ("Schnorr Signatures for secp256k1"). See * https://github.com/bitcoin/bips/blob/master/bip-0340/test-vectors.csv. */ -void test_schnorrsig_bip_vectors(void) { +static void test_schnorrsig_bip_vectors(void) { { /* Test vector 0 */ const unsigned char sk[32] = { @@ -282,7 +218,7 @@ void test_schnorrsig_bip_vectors(void) { 0xB5, 0x31, 0xC8, 0x45, 0x83, 0x6F, 0x99, 0xB0, 0x86, 0x01, 0xF1, 0x13, 0xBC, 0xE0, 0x36, 0xF9 }; - unsigned char aux_rand[32] = { + const unsigned char aux_rand[32] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -304,8 +240,8 @@ void test_schnorrsig_bip_vectors(void) { 0xEB, 0xEE, 0xE8, 0xFD, 0xB2, 0x17, 0x2F, 0x47, 0x7D, 0xF4, 0x90, 0x0D, 0x31, 0x05, 0x36, 0xC0 }; - test_schnorrsig_bip_vectors_check_signing(sk, pk, aux_rand, msg, sig); - test_schnorrsig_bip_vectors_check_verify(pk, msg, sig, 1); + test_schnorrsig_bip_vectors_check_signing(sk, pk, aux_rand, msg, sizeof(msg), sig); + test_schnorrsig_bip_vectors_check_verify(pk, msg, sizeof(msg), sig, 1); } { /* Test vector 1 */ @@ -321,7 +257,7 @@ void test_schnorrsig_bip_vectors(void) { 0x58, 0xFE, 0xAE, 0x1D, 0xA2, 0xDE, 0xCE, 0xD8, 0x43, 0x24, 0x0F, 0x7B, 0x50, 0x2B, 0xA6, 0x59 }; - unsigned char aux_rand[32] = { + const unsigned char aux_rand[32] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -343,8 +279,8 @@ void test_schnorrsig_bip_vectors(void) { 0x89, 0x7E, 0xFC, 0xB6, 0x39, 0xEA, 0x87, 0x1C, 0xFA, 0x95, 0xF6, 0xDE, 0x33, 0x9E, 0x4B, 0x0A }; - test_schnorrsig_bip_vectors_check_signing(sk, pk, aux_rand, msg, sig); - test_schnorrsig_bip_vectors_check_verify(pk, msg, sig, 1); + test_schnorrsig_bip_vectors_check_signing(sk, pk, aux_rand, msg, sizeof(msg), sig); + test_schnorrsig_bip_vectors_check_verify(pk, msg, sizeof(msg), sig, 1); } { /* Test vector 2 */ @@ -360,7 +296,7 @@ void test_schnorrsig_bip_vectors(void) { 0x01, 0x39, 0x71, 0x53, 0x09, 0xB0, 0x86, 0xC9, 0x60, 0xE1, 0x8F, 0xD9, 0x69, 0x77, 0x4E, 0xB8 }; - unsigned char aux_rand[32] = { + const unsigned char aux_rand[32] = { 0xC8, 0x7A, 0xA5, 0x38, 0x24, 0xB4, 0xD7, 0xAE, 0x2E, 0xB0, 0x35, 0xA2, 0xB5, 0xBB, 0xBC, 0xCC, 0x08, 0x0E, 0x76, 0xCD, 0xC6, 0xD1, 0x69, 0x2C, @@ -382,8 +318,8 @@ void test_schnorrsig_bip_vectors(void) { 0x7A, 0xDE, 0xA9, 0x8D, 0x82, 0xF8, 0x48, 0x1E, 0x0E, 0x1E, 0x03, 0x67, 0x4A, 0x6F, 0x3F, 0xB7 }; - test_schnorrsig_bip_vectors_check_signing(sk, pk, aux_rand, msg, sig); - test_schnorrsig_bip_vectors_check_verify(pk, msg, sig, 1); + test_schnorrsig_bip_vectors_check_signing(sk, pk, aux_rand, msg, sizeof(msg), sig); + test_schnorrsig_bip_vectors_check_verify(pk, msg, sizeof(msg), sig, 1); } { /* Test vector 3 */ @@ -399,7 +335,7 @@ void test_schnorrsig_bip_vectors(void) { 0x3A, 0x0D, 0x95, 0xFB, 0xF2, 0x1D, 0x46, 0x8A, 0x1B, 0x33, 0xF8, 0xC1, 0x60, 0xD8, 0xF5, 0x17 }; - unsigned char aux_rand[32] = { + const unsigned char aux_rand[32] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -421,8 +357,8 @@ void test_schnorrsig_bip_vectors(void) { 0xF2, 0x5F, 0xD7, 0x88, 0x81, 0xEB, 0xB3, 0x27, 0x71, 0xFC, 0x59, 0x22, 0xEF, 0xC6, 0x6E, 0xA3 }; - test_schnorrsig_bip_vectors_check_signing(sk, pk, aux_rand, msg, sig); - test_schnorrsig_bip_vectors_check_verify(pk, msg, sig, 1); + test_schnorrsig_bip_vectors_check_signing(sk, pk, aux_rand, msg, sizeof(msg), sig); + test_schnorrsig_bip_vectors_check_verify(pk, msg, sizeof(msg), sig, 1); } { /* Test vector 4 */ @@ -448,7 +384,7 @@ void test_schnorrsig_bip_vectors(void) { 0x60, 0xCB, 0x71, 0xC0, 0x4E, 0x80, 0xF5, 0x93, 0x06, 0x0B, 0x07, 0xD2, 0x83, 0x08, 0xD7, 0xF4 }; - test_schnorrsig_bip_vectors_check_verify(pk, msg, sig, 1); + test_schnorrsig_bip_vectors_check_verify(pk, msg, sizeof(msg), sig, 1); } { /* Test vector 5 */ @@ -458,9 +394,9 @@ void test_schnorrsig_bip_vectors(void) { 0xEB, 0x98, 0x98, 0xAE, 0x79, 0xB9, 0x76, 0x87, 0x66, 0xE4, 0xFA, 0xA0, 0x4A, 0x2D, 0x4A, 0x34 }; - rustsecp256k1zkp_v0_8_0_xonly_pubkey pk_parsed; + rustsecp256k1zkp_v0_10_0_xonly_pubkey pk_parsed; /* No need to check the signature of the test vector as parsing the pubkey already fails */ - CHECK(!rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(ctx, &pk_parsed, pk)); + CHECK(!rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(CTX, &pk_parsed, pk)); } { /* Test vector 6 */ @@ -486,7 +422,7 @@ void test_schnorrsig_bip_vectors(void) { 0x7A, 0x73, 0xC6, 0x43, 0xE1, 0x66, 0xBE, 0x5E, 0xBE, 0xAF, 0xA3, 0x4B, 0x1A, 0xC5, 0x53, 0xE2 }; - test_schnorrsig_bip_vectors_check_verify(pk, msg, sig, 0); + test_schnorrsig_bip_vectors_check_verify(pk, msg, sizeof(msg), sig, 0); } { /* Test vector 7 */ @@ -512,7 +448,7 @@ void test_schnorrsig_bip_vectors(void) { 0x62, 0x2A, 0x95, 0x4C, 0xFE, 0x54, 0x57, 0x35, 0xAA, 0xEA, 0x51, 0x34, 0xFC, 0xCD, 0xB2, 0xBD }; - test_schnorrsig_bip_vectors_check_verify(pk, msg, sig, 0); + test_schnorrsig_bip_vectors_check_verify(pk, msg, sizeof(msg), sig, 0); } { /* Test vector 8 */ @@ -538,7 +474,7 @@ void test_schnorrsig_bip_vectors(void) { 0xE8, 0xD7, 0xC9, 0x3E, 0x00, 0xC5, 0xED, 0x0C, 0x18, 0x34, 0xFF, 0x0D, 0x0C, 0x2E, 0x6D, 0xA6 }; - test_schnorrsig_bip_vectors_check_verify(pk, msg, sig, 0); + test_schnorrsig_bip_vectors_check_verify(pk, msg, sizeof(msg), sig, 0); } { /* Test vector 9 */ @@ -564,7 +500,7 @@ void test_schnorrsig_bip_vectors(void) { 0x4F, 0xB7, 0x34, 0x76, 0xF0, 0xD5, 0x94, 0xDC, 0xB6, 0x5C, 0x64, 0x25, 0xBD, 0x18, 0x60, 0x51 }; - test_schnorrsig_bip_vectors_check_verify(pk, msg, sig, 0); + test_schnorrsig_bip_vectors_check_verify(pk, msg, sizeof(msg), sig, 0); } { /* Test vector 10 */ @@ -590,7 +526,7 @@ void test_schnorrsig_bip_vectors(void) { 0xDB, 0xA8, 0x7F, 0x11, 0xAC, 0x67, 0x54, 0xF9, 0x37, 0x80, 0xD5, 0xA1, 0x83, 0x7C, 0xF1, 0x97 }; - test_schnorrsig_bip_vectors_check_verify(pk, msg, sig, 0); + test_schnorrsig_bip_vectors_check_verify(pk, msg, sizeof(msg), sig, 0); } { /* Test vector 11 */ @@ -616,7 +552,7 @@ void test_schnorrsig_bip_vectors(void) { 0xD1, 0xD7, 0x13, 0xA8, 0xAE, 0x82, 0xB3, 0x2F, 0xA7, 0x9D, 0x5F, 0x7F, 0xC4, 0x07, 0xD3, 0x9B }; - test_schnorrsig_bip_vectors_check_verify(pk, msg, sig, 0); + test_schnorrsig_bip_vectors_check_verify(pk, msg, sizeof(msg), sig, 0); } { /* Test vector 12 */ @@ -642,7 +578,7 @@ void test_schnorrsig_bip_vectors(void) { 0xD1, 0xD7, 0x13, 0xA8, 0xAE, 0x82, 0xB3, 0x2F, 0xA7, 0x9D, 0x5F, 0x7F, 0xC4, 0x07, 0xD3, 0x9B }; - test_schnorrsig_bip_vectors_check_verify(pk, msg, sig, 0); + test_schnorrsig_bip_vectors_check_verify(pk, msg, sizeof(msg), sig, 0); } { /* Test vector 13 */ @@ -668,7 +604,7 @@ void test_schnorrsig_bip_vectors(void) { 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x41 }; - test_schnorrsig_bip_vectors_check_verify(pk, msg, sig, 0); + test_schnorrsig_bip_vectors_check_verify(pk, msg, sizeof(msg), sig, 0); } { /* Test vector 14 */ @@ -678,9 +614,150 @@ void test_schnorrsig_bip_vectors(void) { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFC, 0x30 }; - rustsecp256k1zkp_v0_8_0_xonly_pubkey pk_parsed; + rustsecp256k1zkp_v0_10_0_xonly_pubkey pk_parsed; /* No need to check the signature of the test vector as parsing the pubkey already fails */ - CHECK(!rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(ctx, &pk_parsed, pk)); + CHECK(!rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(CTX, &pk_parsed, pk)); + } + { + /* Test vector 15 */ + const unsigned char sk[32] = { + 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, + 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, + 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, + 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, + }; + const unsigned char pk[32] = { + 0x77, 0x8C, 0xAA, 0x53, 0xB4, 0x39, 0x3A, 0xC4, + 0x67, 0x77, 0x4D, 0x09, 0x49, 0x7A, 0x87, 0x22, + 0x4B, 0xF9, 0xFA, 0xB6, 0xF6, 0xE6, 0x8B, 0x23, + 0x08, 0x64, 0x97, 0x32, 0x4D, 0x6F, 0xD1, 0x17, + }; + const unsigned char aux_rand[32] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + /* const unsigned char msg[0] = {}; */ + const unsigned char sig[64] = { + 0x71, 0x53, 0x5D, 0xB1, 0x65, 0xEC, 0xD9, 0xFB, + 0xBC, 0x04, 0x6E, 0x5F, 0xFA, 0xEA, 0x61, 0x18, + 0x6B, 0xB6, 0xAD, 0x43, 0x67, 0x32, 0xFC, 0xCC, + 0x25, 0x29, 0x1A, 0x55, 0x89, 0x54, 0x64, 0xCF, + 0x60, 0x69, 0xCE, 0x26, 0xBF, 0x03, 0x46, 0x62, + 0x28, 0xF1, 0x9A, 0x3A, 0x62, 0xDB, 0x8A, 0x64, + 0x9F, 0x2D, 0x56, 0x0F, 0xAC, 0x65, 0x28, 0x27, + 0xD1, 0xAF, 0x05, 0x74, 0xE4, 0x27, 0xAB, 0x63, + }; + test_schnorrsig_bip_vectors_check_signing(sk, pk, aux_rand, NULL, 0, sig); + test_schnorrsig_bip_vectors_check_verify(pk, NULL, 0, sig, 1); + } + { + /* Test vector 16 */ + const unsigned char sk[32] = { + 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, + 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, + 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, + 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, + }; + const unsigned char pk[32] = { + 0x77, 0x8C, 0xAA, 0x53, 0xB4, 0x39, 0x3A, 0xC4, + 0x67, 0x77, 0x4D, 0x09, 0x49, 0x7A, 0x87, 0x22, + 0x4B, 0xF9, 0xFA, 0xB6, 0xF6, 0xE6, 0x8B, 0x23, + 0x08, 0x64, 0x97, 0x32, 0x4D, 0x6F, 0xD1, 0x17, + }; + const unsigned char aux_rand[32] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + const unsigned char msg[] = { 0x11 }; + const unsigned char sig[64] = { + 0x08, 0xA2, 0x0A, 0x0A, 0xFE, 0xF6, 0x41, 0x24, + 0x64, 0x92, 0x32, 0xE0, 0x69, 0x3C, 0x58, 0x3A, + 0xB1, 0xB9, 0x93, 0x4A, 0xE6, 0x3B, 0x4C, 0x35, + 0x11, 0xF3, 0xAE, 0x11, 0x34, 0xC6, 0xA3, 0x03, + 0xEA, 0x31, 0x73, 0xBF, 0xEA, 0x66, 0x83, 0xBD, + 0x10, 0x1F, 0xA5, 0xAA, 0x5D, 0xBC, 0x19, 0x96, + 0xFE, 0x7C, 0xAC, 0xFC, 0x5A, 0x57, 0x7D, 0x33, + 0xEC, 0x14, 0x56, 0x4C, 0xEC, 0x2B, 0xAC, 0xBF, + }; + test_schnorrsig_bip_vectors_check_signing(sk, pk, aux_rand, msg, sizeof(msg), sig); + test_schnorrsig_bip_vectors_check_verify(pk, msg, sizeof(msg), sig, 1); + } + { + /* Test vector 17 */ + const unsigned char sk[32] = { + 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, + 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, + 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, + 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, + }; + const unsigned char pk[32] = { + 0x77, 0x8C, 0xAA, 0x53, 0xB4, 0x39, 0x3A, 0xC4, + 0x67, 0x77, 0x4D, 0x09, 0x49, 0x7A, 0x87, 0x22, + 0x4B, 0xF9, 0xFA, 0xB6, 0xF6, 0xE6, 0x8B, 0x23, + 0x08, 0x64, 0x97, 0x32, 0x4D, 0x6F, 0xD1, 0x17, + }; + const unsigned char aux_rand[32] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + const unsigned char msg[] = { + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, + 0x11, + }; + const unsigned char sig[64] = { + 0x51, 0x30, 0xF3, 0x9A, 0x40, 0x59, 0xB4, 0x3B, + 0xC7, 0xCA, 0xC0, 0x9A, 0x19, 0xEC, 0xE5, 0x2B, + 0x5D, 0x86, 0x99, 0xD1, 0xA7, 0x1E, 0x3C, 0x52, + 0xDA, 0x9A, 0xFD, 0xB6, 0xB5, 0x0A, 0xC3, 0x70, + 0xC4, 0xA4, 0x82, 0xB7, 0x7B, 0xF9, 0x60, 0xF8, + 0x68, 0x15, 0x40, 0xE2, 0x5B, 0x67, 0x71, 0xEC, + 0xE1, 0xE5, 0xA3, 0x7F, 0xD8, 0x0E, 0x5A, 0x51, + 0x89, 0x7C, 0x55, 0x66, 0xA9, 0x7E, 0xA5, 0xA5, + }; + test_schnorrsig_bip_vectors_check_signing(sk, pk, aux_rand, msg, sizeof(msg), sig); + test_schnorrsig_bip_vectors_check_verify(pk, msg, sizeof(msg), sig, 1); + } + { + /* Test vector 18 */ + const unsigned char sk[32] = { + 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, + 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, + 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, + 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40, + }; + const unsigned char pk[32] = { + 0x77, 0x8C, 0xAA, 0x53, 0xB4, 0x39, 0x3A, 0xC4, + 0x67, 0x77, 0x4D, 0x09, 0x49, 0x7A, 0x87, 0x22, + 0x4B, 0xF9, 0xFA, 0xB6, 0xF6, 0xE6, 0x8B, 0x23, + 0x08, 0x64, 0x97, 0x32, 0x4D, 0x6F, 0xD1, 0x17, + }; + const unsigned char aux_rand[32] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + const unsigned char sig[64] = { + 0x40, 0x3B, 0x12, 0xB0, 0xD8, 0x55, 0x5A, 0x34, + 0x41, 0x75, 0xEA, 0x7E, 0xC7, 0x46, 0x56, 0x63, + 0x03, 0x32, 0x1E, 0x5D, 0xBF, 0xA8, 0xBE, 0x6F, + 0x09, 0x16, 0x35, 0x16, 0x3E, 0xCA, 0x79, 0xA8, + 0x58, 0x5E, 0xD3, 0xE3, 0x17, 0x08, 0x07, 0xE7, + 0xC0, 0x3B, 0x72, 0x0F, 0xC5, 0x4C, 0x7B, 0x23, + 0x89, 0x7F, 0xCB, 0xA0, 0xE9, 0xD0, 0xB4, 0xA0, + 0x68, 0x94, 0xCF, 0xD2, 0x49, 0xF2, 0x23, 0x67, + }; + unsigned char msg[100]; + memset(msg, 0x99, sizeof(msg)); + test_schnorrsig_bip_vectors_check_signing(sk, pk, aux_rand, msg, sizeof(msg), sig); + test_schnorrsig_bip_vectors_check_verify(pk, msg, sizeof(msg), sig, 1); } } @@ -725,139 +802,139 @@ static int nonce_function_overflowing(unsigned char *nonce32, const unsigned cha return 1; } -void test_schnorrsig_sign(void) { +static void test_schnorrsig_sign(void) { unsigned char sk[32]; - rustsecp256k1zkp_v0_8_0_xonly_pubkey pk; - rustsecp256k1zkp_v0_8_0_keypair keypair; + rustsecp256k1zkp_v0_10_0_xonly_pubkey pk; + rustsecp256k1zkp_v0_10_0_keypair keypair; const unsigned char msg[32] = "this is a msg for a schnorrsig.."; unsigned char sig[64]; unsigned char sig2[64]; unsigned char zeros64[64] = { 0 }; - rustsecp256k1zkp_v0_8_0_schnorrsig_extraparams extraparams = SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT; + rustsecp256k1zkp_v0_10_0_schnorrsig_extraparams extraparams = SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT; unsigned char aux_rand[32]; - rustsecp256k1zkp_v0_8_0_testrand256(sk); - rustsecp256k1zkp_v0_8_0_testrand256(aux_rand); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, sk)); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(ctx, &pk, NULL, &keypair)); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign32(ctx, sig, msg, &keypair, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, sig, msg, sizeof(msg), &pk)); + rustsecp256k1zkp_v0_10_0_testrand256(sk); + rustsecp256k1zkp_v0_10_0_testrand256(aux_rand); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk)); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(CTX, &pk, NULL, &keypair)); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign32(CTX, sig, msg, &keypair, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig, msg, sizeof(msg), &pk)); /* Check that deprecated alias gives the same result */ - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign(ctx, sig2, msg, &keypair, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(sig, sig2, sizeof(sig)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign(CTX, sig2, msg, &keypair, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(sig, sig2, sizeof(sig)) == 0); /* Test different nonce functions */ - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(ctx, sig, msg, sizeof(msg), &keypair, &extraparams) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, sig, msg, sizeof(msg), &pk)); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(CTX, sig, msg, sizeof(msg), &keypair, &extraparams) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig, msg, sizeof(msg), &pk)); memset(sig, 1, sizeof(sig)); extraparams.noncefp = nonce_function_failing; - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(ctx, sig, msg, sizeof(msg), &keypair, &extraparams) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(sig, zeros64, sizeof(sig)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(CTX, sig, msg, sizeof(msg), &keypair, &extraparams) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(sig, zeros64, sizeof(sig)) == 0); memset(&sig, 1, sizeof(sig)); extraparams.noncefp = nonce_function_0; - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(ctx, sig, msg, sizeof(msg), &keypair, &extraparams) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(sig, zeros64, sizeof(sig)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(CTX, sig, msg, sizeof(msg), &keypair, &extraparams) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(sig, zeros64, sizeof(sig)) == 0); memset(&sig, 1, sizeof(sig)); extraparams.noncefp = nonce_function_overflowing; - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(ctx, sig, msg, sizeof(msg), &keypair, &extraparams) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, sig, msg, sizeof(msg), &pk)); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(CTX, sig, msg, sizeof(msg), &keypair, &extraparams) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig, msg, sizeof(msg), &pk)); /* When using the default nonce function, schnorrsig_sign_custom produces * the same result as schnorrsig_sign with aux_rand = extraparams.ndata */ extraparams.noncefp = NULL; extraparams.ndata = aux_rand; - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(ctx, sig, msg, sizeof(msg), &keypair, &extraparams) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign32(ctx, sig2, msg, &keypair, extraparams.ndata) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(sig, sig2, sizeof(sig)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(CTX, sig, msg, sizeof(msg), &keypair, &extraparams) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign32(CTX, sig2, msg, &keypair, extraparams.ndata) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(sig, sig2, sizeof(sig)) == 0); } #define N_SIGS 3 /* Creates N_SIGS valid signatures and verifies them with verify and * verify_batch (TODO). Then flips some bits and checks that verification now * fails. */ -void test_schnorrsig_sign_verify(void) { +static void test_schnorrsig_sign_verify(void) { unsigned char sk[32]; unsigned char msg[N_SIGS][32]; unsigned char sig[N_SIGS][64]; size_t i; - rustsecp256k1zkp_v0_8_0_keypair keypair; - rustsecp256k1zkp_v0_8_0_xonly_pubkey pk; - rustsecp256k1zkp_v0_8_0_scalar s; + rustsecp256k1zkp_v0_10_0_keypair keypair; + rustsecp256k1zkp_v0_10_0_xonly_pubkey pk; + rustsecp256k1zkp_v0_10_0_scalar s; - rustsecp256k1zkp_v0_8_0_testrand256(sk); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, sk)); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(ctx, &pk, NULL, &keypair)); + rustsecp256k1zkp_v0_10_0_testrand256(sk); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk)); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(CTX, &pk, NULL, &keypair)); for (i = 0; i < N_SIGS; i++) { - rustsecp256k1zkp_v0_8_0_testrand256(msg[i]); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign32(ctx, sig[i], msg[i], &keypair, NULL)); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, sig[i], msg[i], sizeof(msg[i]), &pk)); + rustsecp256k1zkp_v0_10_0_testrand256(msg[i]); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign32(CTX, sig[i], msg[i], &keypair, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig[i], msg[i], sizeof(msg[i]), &pk)); } { /* Flip a few bits in the signature and in the message and check that * verify and verify_batch (TODO) fail */ - size_t sig_idx = rustsecp256k1zkp_v0_8_0_testrand_int(N_SIGS); - size_t byte_idx = rustsecp256k1zkp_v0_8_0_testrand_bits(5); - unsigned char xorbyte = rustsecp256k1zkp_v0_8_0_testrand_int(254)+1; + size_t sig_idx = rustsecp256k1zkp_v0_10_0_testrand_int(N_SIGS); + size_t byte_idx = rustsecp256k1zkp_v0_10_0_testrand_bits(5); + unsigned char xorbyte = rustsecp256k1zkp_v0_10_0_testrand_int(254)+1; sig[sig_idx][byte_idx] ^= xorbyte; - CHECK(!rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, sig[sig_idx], msg[sig_idx], sizeof(msg[sig_idx]), &pk)); + CHECK(!rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig[sig_idx], msg[sig_idx], sizeof(msg[sig_idx]), &pk)); sig[sig_idx][byte_idx] ^= xorbyte; - byte_idx = rustsecp256k1zkp_v0_8_0_testrand_bits(5); + byte_idx = rustsecp256k1zkp_v0_10_0_testrand_bits(5); sig[sig_idx][32+byte_idx] ^= xorbyte; - CHECK(!rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, sig[sig_idx], msg[sig_idx], sizeof(msg[sig_idx]), &pk)); + CHECK(!rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig[sig_idx], msg[sig_idx], sizeof(msg[sig_idx]), &pk)); sig[sig_idx][32+byte_idx] ^= xorbyte; - byte_idx = rustsecp256k1zkp_v0_8_0_testrand_bits(5); + byte_idx = rustsecp256k1zkp_v0_10_0_testrand_bits(5); msg[sig_idx][byte_idx] ^= xorbyte; - CHECK(!rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, sig[sig_idx], msg[sig_idx], sizeof(msg[sig_idx]), &pk)); + CHECK(!rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig[sig_idx], msg[sig_idx], sizeof(msg[sig_idx]), &pk)); msg[sig_idx][byte_idx] ^= xorbyte; /* Check that above bitflips have been reversed correctly */ - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, sig[sig_idx], msg[sig_idx], sizeof(msg[sig_idx]), &pk)); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig[sig_idx], msg[sig_idx], sizeof(msg[sig_idx]), &pk)); } /* Test overflowing s */ - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign32(ctx, sig[0], msg[0], &keypair, NULL)); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, sig[0], msg[0], sizeof(msg[0]), &pk)); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign32(CTX, sig[0], msg[0], &keypair, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig[0], msg[0], sizeof(msg[0]), &pk)); memset(&sig[0][32], 0xFF, 32); - CHECK(!rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, sig[0], msg[0], sizeof(msg[0]), &pk)); + CHECK(!rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig[0], msg[0], sizeof(msg[0]), &pk)); /* Test negative s */ - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign32(ctx, sig[0], msg[0], &keypair, NULL)); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, sig[0], msg[0], sizeof(msg[0]), &pk)); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&s, &sig[0][32], NULL); - rustsecp256k1zkp_v0_8_0_scalar_negate(&s, &s); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&sig[0][32], &s); - CHECK(!rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, sig[0], msg[0], sizeof(msg[0]), &pk)); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign32(CTX, sig[0], msg[0], &keypair, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig[0], msg[0], sizeof(msg[0]), &pk)); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&s, &sig[0][32], NULL); + rustsecp256k1zkp_v0_10_0_scalar_negate(&s, &s); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&sig[0][32], &s); + CHECK(!rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig[0], msg[0], sizeof(msg[0]), &pk)); /* The empty message can be signed & verified */ - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(ctx, sig[0], NULL, 0, &keypair, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, sig[0], NULL, 0, &pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(CTX, sig[0], NULL, 0, &keypair, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig[0], NULL, 0, &pk) == 1); { /* Test varying message lengths */ unsigned char msg_large[32 * 8]; - uint32_t msglen = rustsecp256k1zkp_v0_8_0_testrand_int(sizeof(msg_large)); + uint32_t msglen = rustsecp256k1zkp_v0_10_0_testrand_int(sizeof(msg_large)); for (i = 0; i < sizeof(msg_large); i += 32) { - rustsecp256k1zkp_v0_8_0_testrand256(&msg_large[i]); + rustsecp256k1zkp_v0_10_0_testrand256(&msg_large[i]); } - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign_custom(ctx, sig[0], msg_large, msglen, &keypair, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, sig[0], msg_large, msglen, &pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign_custom(CTX, sig[0], msg_large, msglen, &keypair, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig[0], msg_large, msglen, &pk) == 1); /* Verification for a random wrong message length fails */ msglen = (msglen + (sizeof(msg_large) - 1)) % sizeof(msg_large); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, sig[0], msg_large, msglen, &pk) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig[0], msg_large, msglen, &pk) == 0); } } #undef N_SIGS -void test_schnorrsig_taproot(void) { +static void test_schnorrsig_taproot(void) { unsigned char sk[32]; - rustsecp256k1zkp_v0_8_0_keypair keypair; - rustsecp256k1zkp_v0_8_0_xonly_pubkey internal_pk; + rustsecp256k1zkp_v0_10_0_keypair keypair; + rustsecp256k1zkp_v0_10_0_xonly_pubkey internal_pk; unsigned char internal_pk_bytes[32]; - rustsecp256k1zkp_v0_8_0_xonly_pubkey output_pk; + rustsecp256k1zkp_v0_10_0_xonly_pubkey output_pk; unsigned char output_pk_bytes[32]; unsigned char tweak[32]; int pk_parity; @@ -865,37 +942,37 @@ void test_schnorrsig_taproot(void) { unsigned char sig[64]; /* Create output key */ - rustsecp256k1zkp_v0_8_0_testrand256(sk); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, sk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(ctx, &internal_pk, NULL, &keypair) == 1); + rustsecp256k1zkp_v0_10_0_testrand256(sk); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(CTX, &internal_pk, NULL, &keypair) == 1); /* In actual taproot the tweak would be hash of internal_pk */ - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(ctx, tweak, &internal_pk) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_tweak_add(ctx, &keypair, tweak) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_xonly_pub(ctx, &output_pk, &pk_parity, &keypair) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(ctx, output_pk_bytes, &output_pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(CTX, tweak, &internal_pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_tweak_add(CTX, &keypair, tweak) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(CTX, &output_pk, &pk_parity, &keypair) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(CTX, output_pk_bytes, &output_pk) == 1); /* Key spend */ - rustsecp256k1zkp_v0_8_0_testrand256(msg); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_sign32(ctx, sig, msg, &keypair, NULL) == 1); + rustsecp256k1zkp_v0_10_0_testrand256(msg); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign32(CTX, sig, msg, &keypair, NULL) == 1); /* Verify key spend */ - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(ctx, &output_pk, output_pk_bytes) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_schnorrsig_verify(ctx, sig, msg, sizeof(msg), &output_pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(CTX, &output_pk, output_pk_bytes) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_verify(CTX, sig, msg, sizeof(msg), &output_pk) == 1); /* Script spend */ - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_serialize(ctx, internal_pk_bytes, &internal_pk) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(CTX, internal_pk_bytes, &internal_pk) == 1); /* Verify script spend */ - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_parse(ctx, &internal_pk, internal_pk_bytes) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_xonly_pubkey_tweak_add_check(ctx, output_pk_bytes, pk_parity, &internal_pk, tweak) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(CTX, &internal_pk, internal_pk_bytes) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_tweak_add_check(CTX, output_pk_bytes, pk_parity, &internal_pk, tweak) == 1); } -void run_schnorrsig_tests(void) { +static void run_schnorrsig_tests(void) { int i; run_nonce_function_bip340_tests(); test_schnorrsig_api(); test_schnorrsig_sha256_tagged(); test_schnorrsig_bip_vectors(); - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { test_schnorrsig_sign(); test_schnorrsig_sign_verify(); } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig_halfagg/Makefile.am.include b/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig_halfagg/Makefile.am.include new file mode 100644 index 00000000..b396f709 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig_halfagg/Makefile.am.include @@ -0,0 +1,3 @@ +include_HEADERS += include/rustsecp256k1zkp_v0_10_0_schnorrsig_halfagg.h +noinst_HEADERS += src/modules/schnorrsig_halfagg/main_impl.h +noinst_HEADERS += src/modules/schnorrsig_halfagg/tests_impl.h diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig_halfagg/main_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig_halfagg/main_impl.h new file mode 100644 index 00000000..64b1807d --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig_halfagg/main_impl.h @@ -0,0 +1,202 @@ +#ifndef SECP256K1_MODULE_SCHNORRSIG_HALFAGG_MAIN_H +#define SECP256K1_MODULE_SCHNORRSIG_HALFAGG_MAIN_H + +#include "../../../include/secp256k1.h" +#include "../../../include/secp256k1_schnorrsig.h" +#include "../../../include/secp256k1_schnorrsig_halfagg.h" +#include "../../hash.h" + +/* Initializes SHA256 with fixed midstate. This midstate was computed by applying + * SHA256 to SHA256("HalfAgg/randomizer")||SHA256("HalfAgg/randomizer"). */ +void rustsecp256k1zkp_v0_10_0_schnorrsig_sha256_tagged_aggregation(rustsecp256k1zkp_v0_10_0_sha256 *sha) { + rustsecp256k1zkp_v0_10_0_sha256_initialize(sha); + sha->s[0] = 0xd11f5532ul; + sha->s[1] = 0xfa57f70ful; + sha->s[2] = 0x5db0d728ul; + sha->s[3] = 0xf806ffe1ul; + sha->s[4] = 0x1d4db069ul; + sha->s[5] = 0xb4d587e1ul; + sha->s[6] = 0x50451c2aul; + sha->s[7] = 0x10fb63e9ul; + + sha->bytes = 64; +} + +int rustsecp256k1zkp_v0_10_0_schnorrsig_inc_aggregate(const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *aggsig, size_t *aggsig_len, const rustsecp256k1zkp_v0_10_0_xonly_pubkey *all_pubkeys, const unsigned char *all_msgs32, const unsigned char *new_sigs64, size_t n_before, size_t n_new) { + size_t i; + size_t n; + rustsecp256k1zkp_v0_10_0_sha256 hash; + rustsecp256k1zkp_v0_10_0_scalar s; + + VERIFY_CHECK(ctx != NULL); + ARG_CHECK(aggsig != NULL); + ARG_CHECK(aggsig_len != NULL); + ARG_CHECK(new_sigs64 != NULL || n_new == 0); + + /* Check that aggsig_len is large enough, i.e. aggsig_len >= 32*(n+1) */ + n = n_before + n_new; + ARG_CHECK(n >= n_before); + ARG_CHECK(all_pubkeys != NULL || n == 0); + ARG_CHECK(all_msgs32 != NULL || n == 0); + if ((*aggsig_len / 32) <= 0 || ((*aggsig_len / 32) - 1) < n) { + return 0; + } + + /* Prepare hash with common prefix. The prefix is the tag and */ + /* r_0 || pk_0 || m_0 || .... || r_{n'-1} || pk_{n'-1} || m_{n'-1} */ + /* where n' = n_before */ + rustsecp256k1zkp_v0_10_0_schnorrsig_sha256_tagged_aggregation(&hash); + for (i = 0; i < n_before; ++i) { + /* serialize pk_i */ + unsigned char pk_ser[32]; + if (!rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(ctx, pk_ser, &all_pubkeys[i])) { + return 0; + } + /* write r_i */ + rustsecp256k1zkp_v0_10_0_sha256_write(&hash, &aggsig[i*32], 32); + /* write pk_i */ + rustsecp256k1zkp_v0_10_0_sha256_write(&hash, pk_ser, 32); + /* write m_i*/ + rustsecp256k1zkp_v0_10_0_sha256_write(&hash, &all_msgs32[i*32], 32); + } + + /* Compute s = s_old + sum_{i = n_before}^{n} z_i*s_i */ + /* where s_old = 0 if n_before = 0 */ + rustsecp256k1zkp_v0_10_0_scalar_set_int(&s, 0); + if (n_before > 0) rustsecp256k1zkp_v0_10_0_scalar_set_b32(&s, &aggsig[n_before*32], NULL); + for (i = n_before; i < n; ++i) { + unsigned char pk_ser[32]; + unsigned char hashoutput[32]; + rustsecp256k1zkp_v0_10_0_sha256 hashcopy; + rustsecp256k1zkp_v0_10_0_scalar si; + rustsecp256k1zkp_v0_10_0_scalar zi; + + /* Step 0: Serialize pk_i into pk_ser */ + if (!rustsecp256k1zkp_v0_10_0_xonly_pubkey_serialize(ctx, pk_ser, &all_pubkeys[i])) { + return 0; + } + + /* Step 1: z_i = TaggedHash(...) */ + /* 1.a) Write into hash r_i, pk_i, m_i, r_i */ + rustsecp256k1zkp_v0_10_0_sha256_write(&hash, &new_sigs64[(i-n_before)*64], 32); + rustsecp256k1zkp_v0_10_0_sha256_write(&hash, pk_ser, 32); + rustsecp256k1zkp_v0_10_0_sha256_write(&hash, &all_msgs32[i*32], 32); + /* 1.b) Copy the hash */ + hashcopy = hash; + /* 1.c) Finalize the copy to get zi*/ + rustsecp256k1zkp_v0_10_0_sha256_finalize(&hashcopy, hashoutput); + /* Note: No need to check overflow, comes from hash */ + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&zi, hashoutput, NULL); + + /* Step 2: s := s + zi*si */ + /* except if i == 0, then zi = 1 implicitly */ + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&si, &new_sigs64[(i-n_before)*64+32], NULL); + if (i != 0) rustsecp256k1zkp_v0_10_0_scalar_mul(&si, &si, &zi); + rustsecp256k1zkp_v0_10_0_scalar_add(&s, &s, &si); + } + + /* copy new rs into aggsig */ + for (i = n_before; i < n; ++i) { + memcpy(&aggsig[i*32], &new_sigs64[(i-n_before)*64], 32); + } + /* copy new s into aggsig */ + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&aggsig[n*32], &s); + *aggsig_len = 32 * (1 + n); + return 1; +} + +int rustsecp256k1zkp_v0_10_0_schnorrsig_aggregate(const rustsecp256k1zkp_v0_10_0_context *ctx, unsigned char *aggsig, size_t *aggsig_len, const rustsecp256k1zkp_v0_10_0_xonly_pubkey *pubkeys, const unsigned char *msgs32, const unsigned char *sigs64, size_t n) { + return rustsecp256k1zkp_v0_10_0_schnorrsig_inc_aggregate(ctx, aggsig, aggsig_len, pubkeys, msgs32, sigs64, 0, n); +} + +int rustsecp256k1zkp_v0_10_0_schnorrsig_aggverify(const rustsecp256k1zkp_v0_10_0_context *ctx, const rustsecp256k1zkp_v0_10_0_xonly_pubkey *pubkeys, const unsigned char *msgs32, size_t n, const unsigned char *aggsig, size_t aggsig_len) { + size_t i; + rustsecp256k1zkp_v0_10_0_gej lhs, rhs; + rustsecp256k1zkp_v0_10_0_scalar s; + rustsecp256k1zkp_v0_10_0_sha256 hash; + int overflow; + + VERIFY_CHECK(ctx != NULL); + ARG_CHECK(pubkeys != NULL || n == 0); + ARG_CHECK(msgs32 != NULL || n == 0); + ARG_CHECK(aggsig != NULL); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); + + /* Check that aggsig_len is correct, i.e., aggsig_len = 32*(n+1) */ + if ((aggsig_len / 32) <= 0 || ((aggsig_len / 32)-1) != n || (aggsig_len % 32) != 0) { + return 0; + } + + /* Compute the rhs: */ + /* Set rhs = 0 */ + /* For each i in 0,.., n-1, do: */ + /* (1) z_i = TaggedHash(...) */ + /* (2) T_i = R_i+e_i*P_i */ + /* (3) rhs = rhs + z_i*T_i */ + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&rhs); + rustsecp256k1zkp_v0_10_0_schnorrsig_sha256_tagged_aggregation(&hash); + for (i = 0; i < n; ++i) { + rustsecp256k1zkp_v0_10_0_fe rx; + rustsecp256k1zkp_v0_10_0_ge rp, pp; + rustsecp256k1zkp_v0_10_0_scalar ei; + rustsecp256k1zkp_v0_10_0_gej ppj, ti; + + unsigned char pk_ser[32]; + unsigned char hashoutput[32]; + rustsecp256k1zkp_v0_10_0_sha256 hashcopy; + rustsecp256k1zkp_v0_10_0_scalar zi; + + /* Step 0: Serialize pk_i into pk_ser */ + /* We need that in Step 1 and in Step 2 */ + if (!rustsecp256k1zkp_v0_10_0_xonly_pubkey_load(ctx, &pp, &pubkeys[i])) { + return 0; + } + rustsecp256k1zkp_v0_10_0_fe_get_b32(pk_ser, &pp.x); + + /* Step 1: z_i = TaggedHash(...) */ + /* 1.a) Write into hash r_i, pk_i, m_i, r_i */ + rustsecp256k1zkp_v0_10_0_sha256_write(&hash, &aggsig[i*32], 32); + rustsecp256k1zkp_v0_10_0_sha256_write(&hash, pk_ser, 32); + rustsecp256k1zkp_v0_10_0_sha256_write(&hash, &msgs32[i*32], 32); + /* 1.b) Copy the hash */ + hashcopy = hash; + /* 1.c) Finalize the copy to get zi*/ + rustsecp256k1zkp_v0_10_0_sha256_finalize(&hashcopy, hashoutput); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&zi, hashoutput, NULL); + + /* Step 2: T_i = R_i+e_i*P_i */ + /* 2.a) R_i = lift_x(int(r_i)); fail if that fails */ + if (!rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&rx, &aggsig[i*32])) { + return 0; + } + if (!rustsecp256k1zkp_v0_10_0_ge_set_xo_var(&rp, &rx, 0)) { + return 0; + } + + /* 2.b) e_i = int(hash_{BIP0340/challenge}(bytes(r_i) || pk_i || m_i)) mod n */ + rustsecp256k1zkp_v0_10_0_schnorrsig_challenge(&ei, &aggsig[i*32], &msgs32[i*32], 32, pk_ser); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&ppj, &pp); + /* 2.c) T_i = R_i + e_i*P_i */ + rustsecp256k1zkp_v0_10_0_ecmult(&ti, &ppj, &ei, NULL); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&ti, &ti, &rp, NULL); + + /* Step 3: rhs = rhs + zi*T_i */ + /* Note that if i == 0, then zi = 1 implicitly */ + if (i != 0) rustsecp256k1zkp_v0_10_0_ecmult(&ti, &ti, &zi, NULL); + rustsecp256k1zkp_v0_10_0_gej_add_var(&rhs, &rhs, &ti, NULL); + } + + /* Compute the lhs as lhs = s*G */ + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&s, &aggsig[n*32], &overflow); + if (overflow) { + return 0; + } + rustsecp256k1zkp_v0_10_0_ecmult_gen(&ctx->ecmult_gen_ctx, &lhs, &s); + + /* Check that lhs == rhs */ + rustsecp256k1zkp_v0_10_0_gej_neg(&lhs, &lhs); + rustsecp256k1zkp_v0_10_0_gej_add_var(&lhs, &lhs, &rhs, NULL); + return rustsecp256k1zkp_v0_10_0_gej_is_infinity(&lhs); +} + +#endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig_halfagg/tests_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig_halfagg/tests_impl.h new file mode 100644 index 00000000..47db0697 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/schnorrsig_halfagg/tests_impl.h @@ -0,0 +1,338 @@ +#ifndef SECP256K1_MODULE_SCHNORRSIG_HALFAGG_TESTS_H +#define SECP256K1_MODULE_SCHNORRSIG_HALFAGG_TESTS_H + +#include "../../../include/secp256k1_schnorrsig_halfagg.h" + +#define N_MAX 50 + +/* We test that the hash initialized by rustsecp256k1zkp_v0_10_0_schnorrsig_sha256_tagged_aggregate + * has the expected state. */ +void test_schnorrsig_sha256_tagged_aggregate(void) { + unsigned char tag[18] = "HalfAgg/randomizer"; + rustsecp256k1zkp_v0_10_0_sha256 sha; + rustsecp256k1zkp_v0_10_0_sha256 sha_optimized; + + rustsecp256k1zkp_v0_10_0_sha256_initialize_tagged(&sha, (unsigned char *) tag, sizeof(tag)); + rustsecp256k1zkp_v0_10_0_schnorrsig_sha256_tagged_aggregation(&sha_optimized); + test_sha256_eq(&sha, &sha_optimized); +} + +/* Create n many x-only pubkeys and sigs for random messages */ +void test_schnorrsig_aggregate_input_helper(rustsecp256k1zkp_v0_10_0_xonly_pubkey *pubkeys, unsigned char *msgs32, unsigned char *sigs64, size_t n) { + size_t i; + for (i = 0; i < n; ++i) { + unsigned char sk[32]; + rustsecp256k1zkp_v0_10_0_keypair keypair; + rustsecp256k1zkp_v0_10_0_testrand256(sk); + rustsecp256k1zkp_v0_10_0_testrand256(&msgs32[i*32]); + + CHECK(rustsecp256k1zkp_v0_10_0_keypair_create(CTX, &keypair, sk)); + CHECK(rustsecp256k1zkp_v0_10_0_keypair_xonly_pub(CTX, &pubkeys[i], NULL, &keypair)); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_sign(CTX, &sigs64[i*64], &msgs32[i*32], &keypair, NULL)); + } +} + +/* In this test we create a bunch of Schnorr signatures, + * aggregate some of them in one shot, and then + * aggregate the others incrementally to the already aggregated ones. + * The aggregate signature should verify after both steps. */ +void test_schnorrsig_aggregate(void) { + rustsecp256k1zkp_v0_10_0_xonly_pubkey pubkeys[N_MAX]; + unsigned char msgs32[N_MAX*32]; + unsigned char sigs64[N_MAX*64]; + unsigned char aggsig[32*(N_MAX + 1) + 17]; + size_t aggsig_len = sizeof(aggsig); + + size_t n = rustsecp256k1zkp_v0_10_0_testrand_int(N_MAX + 1); + size_t n_initial = rustsecp256k1zkp_v0_10_0_testrand_int(n + 1); + size_t n_new = n - n_initial; + test_schnorrsig_aggregate_input_helper(pubkeys, msgs32, sigs64, n); + + /* Aggregate the first n_initial of them */ + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, sigs64, n_initial)); + /* Make sure that the aggregate signature verifies */ + CHECK(aggsig_len == 32*(n_initial + 1)); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_aggverify(CTX, pubkeys, msgs32, n_initial, aggsig, aggsig_len)); + /* Aggregate the remaining n_new many signatures to the already existing ones */ + aggsig_len = sizeof(aggsig); + rustsecp256k1zkp_v0_10_0_schnorrsig_inc_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, &sigs64[n_initial*64], n_initial, n_new); + /* Make sure that the aggregate signature verifies */ + CHECK(aggsig_len == 32*(n + 1)); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_aggverify(CTX, pubkeys, msgs32, n, aggsig, aggsig_len)); + + /* Check that a direct aggregation of the n sigs yields an identical aggsig */ + { + unsigned char aggsig2[sizeof(aggsig)]; + size_t aggsig_len2 = sizeof(aggsig2); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_aggregate(CTX, aggsig2, &aggsig_len2, pubkeys, msgs32, sigs64, n)); + CHECK(aggsig_len == aggsig_len2); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(aggsig, aggsig2, aggsig_len) == 0); + } +} + +/* This tests the verification test vectors from + * https://github.com/BlockstreamResearch/cross-input-aggregation/blob/master/hacspec-halfagg/tests/tests.rs#L78 . */ +void test_schnorrsig_aggverify_spec_vectors(void) { + /* Test vector 0 */ + { + size_t n = 0; + const unsigned char aggsig[32] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + size_t aggsig_len = sizeof(aggsig); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_aggverify(CTX, NULL, NULL, n, aggsig, aggsig_len)); + } + /* Test vector 1 */ + { + size_t n = 1; + const unsigned char pubkeys_ser[1*32] = { + 0x1b, 0x84, 0xc5, 0x56, 0x7b, 0x12, 0x64, 0x40, + 0x99, 0x5d, 0x3e, 0xd5, 0xaa, 0xba, 0x05, 0x65, + 0xd7, 0x1e, 0x18, 0x34, 0x60, 0x48, 0x19, 0xff, + 0x9c, 0x17, 0xf5, 0xe9, 0xd5, 0xdd, 0x07, 0x8f + }; + rustsecp256k1zkp_v0_10_0_xonly_pubkey pubkeys[1]; + const unsigned char msgs32[1*32] = { + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 + }; + const unsigned char aggsig[1*32+32] = { + 0xb0, 0x70, 0xaa, 0xfc, 0xea, 0x43, 0x9a, 0x4f, + 0x6f, 0x1b, 0xbf, 0xc2, 0xeb, 0x66, 0xd2, 0x9d, + 0x24, 0xb0, 0xca, 0xb7, 0x4d, 0x6b, 0x74, 0x5c, + 0x3c, 0xfb, 0x00, 0x9c, 0xc8, 0xfe, 0x4a, 0xa8, + 0x0e, 0x06, 0x6c, 0x34, 0x81, 0x99, 0x36, 0x54, + 0x9f, 0xf4, 0x9b, 0x6f, 0xd4, 0xd4, 0x1e, 0xdf, + 0xc4, 0x01, 0xa3, 0x67, 0xb8, 0x7d, 0xdd, 0x59, + 0xfe, 0xe3, 0x81, 0x77, 0x96, 0x1c, 0x22, 0x5f, + }; + size_t aggsig_len = sizeof(aggsig); + size_t i; + for (i = 0; i < n; ++i) { + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(CTX, &pubkeys[i], &pubkeys_ser[i*32])); + } + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_aggverify(CTX, pubkeys, msgs32, n, aggsig, aggsig_len)); + } + /* Test vector 2 */ + { + size_t n = 2; + const unsigned char pubkeys_ser[2*32] = { + 0x1b, 0x84, 0xc5, 0x56, 0x7b, 0x12, 0x64, 0x40, + 0x99, 0x5d, 0x3e, 0xd5, 0xaa, 0xba, 0x05, 0x65, + 0xd7, 0x1e, 0x18, 0x34, 0x60, 0x48, 0x19, 0xff, + 0x9c, 0x17, 0xf5, 0xe9, 0xd5, 0xdd, 0x07, 0x8f, + + 0x46, 0x27, 0x79, 0xad, 0x4a, 0xad, 0x39, 0x51, + 0x46, 0x14, 0x75, 0x1a, 0x71, 0x08, 0x5f, 0x2f, + 0x10, 0xe1, 0xc7, 0xa5, 0x93, 0xe4, 0xe0, 0x30, + 0xef, 0xb5, 0xb8, 0x72, 0x1c, 0xe5, 0x5b, 0x0b, + }; + rustsecp256k1zkp_v0_10_0_xonly_pubkey pubkeys[2]; + const unsigned char msgs32[2*32] = { + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + }; + const unsigned char aggsig[2*32+32] = { + 0xb0, 0x70, 0xaa, 0xfc, 0xea, 0x43, 0x9a, 0x4f, + 0x6f, 0x1b, 0xbf, 0xc2, 0xeb, 0x66, 0xd2, 0x9d, + 0x24, 0xb0, 0xca, 0xb7, 0x4d, 0x6b, 0x74, 0x5c, + 0x3c, 0xfb, 0x00, 0x9c, 0xc8, 0xfe, 0x4a, 0xa8, + 0xa3, 0xaf, 0xbd, 0xb4, 0x5a, 0x6a, 0x34, 0xbf, + 0x7c, 0x8c, 0x00, 0xf1, 0xb6, 0xd7, 0xe7, 0xd3, + 0x75, 0xb5, 0x45, 0x40, 0xf1, 0x37, 0x16, 0xc8, + 0x7b, 0x62, 0xe5, 0x1e, 0x2f, 0x4f, 0x22, 0xff, + 0xbf, 0x89, 0x13, 0xec, 0x53, 0x22, 0x6a, 0x34, + 0x89, 0x2d, 0x60, 0x25, 0x2a, 0x70, 0x52, 0x61, + 0x4c, 0xa7, 0x9a, 0xe9, 0x39, 0x98, 0x68, 0x28, + 0xd8, 0x1d, 0x23, 0x11, 0x95, 0x73, 0x71, 0xad, + }; + size_t aggsig_len = sizeof(aggsig); + size_t i; + for (i = 0; i < n; ++i) { + CHECK(rustsecp256k1zkp_v0_10_0_xonly_pubkey_parse(CTX, &pubkeys[i], &pubkeys_ser[i*32])); + } + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_aggverify(CTX, pubkeys, msgs32, n, aggsig, aggsig_len)); + } +} + +static void test_schnorrsig_aggregate_api(void) { + size_t n = rustsecp256k1zkp_v0_10_0_testrand_int(N_MAX + 1); + size_t n_initial = rustsecp256k1zkp_v0_10_0_testrand_int(n + 1); + size_t n_new = n - n_initial; + + /* Test preparation. */ + rustsecp256k1zkp_v0_10_0_xonly_pubkey pubkeys[N_MAX]; + unsigned char msgs32[N_MAX*32]; + unsigned char sigs64[N_MAX*64]; + unsigned char aggsig[32*(N_MAX + 1)]; + test_schnorrsig_aggregate_input_helper(pubkeys, msgs32, sigs64, n); + + /* Test body 1: Check API of function aggregate. */ + { + /* Should not accept NULL for aggsig or aggsig length */ + size_t aggsig_len = sizeof(aggsig); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_aggregate(CTX, NULL, &aggsig_len, pubkeys, msgs32, sigs64, n_initial)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_aggregate(CTX, aggsig, NULL, pubkeys, msgs32, sigs64, n_initial)); + /* Should not accept NULL for keys, messages, or signatures if n_initial is not 0 */ + if (n_initial != 0) { + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_aggregate(CTX, aggsig, &aggsig_len, NULL, msgs32, sigs64, n_initial)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_aggregate(CTX, aggsig, &aggsig_len, pubkeys, NULL, sigs64, n_initial)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, NULL, n_initial)); + } + } + + /* Test body 2: Check API of function inc_aggregate. */ + { + size_t aggsig_len = sizeof(aggsig); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, sigs64, n_initial)); + aggsig_len = 32*(n+1); + /* Should not accept NULL for aggsig or aggsig length */ + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_inc_aggregate(CTX, NULL, &aggsig_len, pubkeys, msgs32, &sigs64[n_initial*64], n_initial, n_new)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_inc_aggregate(CTX, aggsig, NULL, pubkeys, msgs32, &sigs64[n_initial*64], n_initial, n_new)); + /* Should not accept NULL for keys or messages if n is not 0 */ + if (n != 0) { + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_inc_aggregate(CTX, aggsig, &aggsig_len, NULL, msgs32, &sigs64[n_initial*64], n_initial, n_new)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_inc_aggregate(CTX, aggsig, &aggsig_len, pubkeys, NULL, &sigs64[n_initial*64], n_initial, n_new)); + } + /* Should not accept NULL for new_sigs64 if n_new is not 0 */ + if (n_new != 0) { + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_inc_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, NULL, n_initial, n_new)); + } + /* Should not accept overflowing number of sigs. */ + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_inc_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, &sigs64[n_initial*64], SIZE_MAX, SIZE_MAX)); + if (n_initial > 0) { + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_inc_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, &sigs64[n_initial*64], n_initial, SIZE_MAX)); + } + /* Should reject if aggsig_len is too small. */ + aggsig_len = 32*n; + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_inc_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, &sigs64[n_initial*64], n_initial, n_new) == 0); + aggsig_len = 32*(n+1) - 1; + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_inc_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, &sigs64[n_initial*64], n_initial, n_new) == 0); + } + + /* Test body 3: Check API of function aggverify. */ + { + size_t aggsig_len = sizeof(aggsig); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_inc_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, &sigs64[n_initial*64], n_initial, n_new)); + /* Should not accept NULL for keys or messages if n is not 0 */ + if (n != 0) { + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_aggverify(CTX, NULL, msgs32, n, aggsig, aggsig_len)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_aggverify(CTX, pubkeys, NULL, n, aggsig, aggsig_len)); + } + /* Should never accept NULL the aggsig */ + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_schnorrsig_aggverify(CTX, pubkeys, msgs32, n, NULL, aggsig_len)); + /* Should reject for invalid aggsig_len. */ + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_aggverify(CTX, pubkeys, msgs32, n, aggsig, aggsig_len + 1) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_aggverify(CTX, pubkeys, msgs32, n, aggsig, aggsig_len - 1) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_aggverify(CTX, pubkeys, msgs32, n, aggsig, aggsig_len + 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_aggverify(CTX, pubkeys, msgs32, n, aggsig, aggsig_len - 32) == 0); + } +} + +/* In this test, we make sure that trivial attempts to break + * the security of verification do not work. */ +static void test_schnorrsig_aggregate_unforge(void) { + rustsecp256k1zkp_v0_10_0_xonly_pubkey pubkeys[N_MAX]; + unsigned char msgs32[N_MAX*32]; + unsigned char sigs64[N_MAX*64]; + unsigned char aggsig[32*(N_MAX + 1)]; + + size_t n = rustsecp256k1zkp_v0_10_0_testrand_int(N_MAX + 1); + + /* Test 1: We fix a set of n messages and compute + * a random aggsig for them. This should not verify. */ + test_schnorrsig_aggregate_input_helper(pubkeys, msgs32, sigs64, n); + { + size_t aggsig_len = sizeof(aggsig); + size_t i; + /* Sample aggsig randomly */ + for (i = 0; i < n + 1; ++i) { + rustsecp256k1zkp_v0_10_0_testrand256(&aggsig[i*32]); + } + /* Make sure that it does not verify */ + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_aggverify(CTX, pubkeys, msgs32, n, aggsig, aggsig_len) == 0); + } + + /* Test 2: We fix a set of n messages and compute valid + * signatures for all but one. The resulting aggregate signature + * should not verify. */ + test_schnorrsig_aggregate_input_helper(pubkeys, msgs32, sigs64, n); + if (n > 0) { + size_t aggsig_len = sizeof(aggsig); + /* Replace a randomly chosen real sig with a random one. */ + size_t k = rustsecp256k1zkp_v0_10_0_testrand_int(n); + rustsecp256k1zkp_v0_10_0_testrand256(&sigs64[k*64]); + rustsecp256k1zkp_v0_10_0_testrand256(&sigs64[k*64+32]); + /* Aggregate the n signatures */ + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, sigs64, n)); + /* Make sure the result does not verify */ + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_aggverify(CTX, pubkeys, msgs32, n, aggsig, aggsig_len) == 0); + } + + /* Test 3: We generate a valid aggregate signature and then + * change one of the messages. This should not verify. */ + test_schnorrsig_aggregate_input_helper(pubkeys, msgs32, sigs64, n); + if (n > 0) { + size_t aggsig_len = sizeof(aggsig); + size_t k; + /* Aggregate the n signatures */ + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, sigs64, n)); + /* Change one of the messages */ + k = rustsecp256k1zkp_v0_10_0_testrand_int(32*n); + msgs32[k] = msgs32[k]^0xff; + /* Make sure the result does not verify */ + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_aggverify(CTX, pubkeys, msgs32, n, aggsig, aggsig_len) == 0); + } +} + +/* In this test, we make sure that the algorithms properly reject + * for overflowing and non parseable values. */ +static void test_schnorrsig_aggregate_overflow(void) { + rustsecp256k1zkp_v0_10_0_xonly_pubkey pubkeys[N_MAX]; + unsigned char msgs32[N_MAX*32]; + unsigned char sigs64[N_MAX*64]; + unsigned char aggsig[32*(N_MAX + 1)]; + size_t n = rustsecp256k1zkp_v0_10_0_testrand_int(N_MAX + 1); + + /* We check that verification returns 0 if the s in aggsig overflows. */ + test_schnorrsig_aggregate_input_helper(pubkeys, msgs32, sigs64, n); + { + size_t aggsig_len = sizeof(aggsig); + /* Aggregate */ + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, sigs64, n)); + /* Make s in the aggsig overflow */ + memset(&aggsig[n*32], 0xFF, 32); + /* Should not verify */ + CHECK(rustsecp256k1zkp_v0_10_0_schnorrsig_aggverify(CTX, pubkeys, msgs32, n, aggsig, aggsig_len) == 0); + } +} + +static void run_schnorrsig_halfagg_tests(void) { + int i; + + test_schnorrsig_sha256_tagged_aggregate(); + test_schnorrsig_aggverify_spec_vectors(); + + for (i = 0; i < COUNT; i++) { + test_schnorrsig_aggregate(); + test_schnorrsig_aggregate_api(); + test_schnorrsig_aggregate_unforge(); + test_schnorrsig_aggregate_overflow(); + } +} + +#undef N_MAX + +#endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/surjection/Makefile.am.include b/secp256k1-zkp-sys/depend/secp256k1/src/modules/surjection/Makefile.am.include index 26395b05..32baaee6 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/surjection/Makefile.am.include +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/surjection/Makefile.am.include @@ -1,4 +1,4 @@ -include_HEADERS += include/rustsecp256k1zkp_v0_8_0_surjectionproof.h +include_HEADERS += include/rustsecp256k1zkp_v0_10_0_surjectionproof.h noinst_HEADERS += src/modules/surjection/main_impl.h noinst_HEADERS += src/modules/surjection/surjection.h noinst_HEADERS += src/modules/surjection/surjection_impl.h diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/surjection/main_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/surjection/main_impl.h index 9d69bdb8..831a9994 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/surjection/main_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/surjection/main_impl.h @@ -3,15 +3,11 @@ * Distributed under the MIT software license, see the accompanying * * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef SECP256K1_MODULE_SURJECTION_MAIN -#define SECP256K1_MODULE_SURJECTION_MAIN +#ifndef SECP256K1_MODULE_SURJECTION_MAIN_H +#define SECP256K1_MODULE_SURJECTION_MAIN_H #include -#if defined HAVE_CONFIG_H -#include "libsecp256k1-config.h" -#endif - #include "../../../include/secp256k1_rangeproof.h" #include "../../../include/secp256k1_surjectionproof.h" #include "../rangeproof/borromean.h" @@ -23,7 +19,7 @@ #define SECP256K1_SURJECTIONPROOF_MAX_USED_INPUTS 16 #endif -static size_t rustsecp256k1zkp_v0_8_0_count_bits_set(const unsigned char* data, size_t count) { +static size_t rustsecp256k1zkp_v0_10_0_count_bits_set(const unsigned char* data, size_t count) { size_t ret = 0; size_t i; for (i = 0; i < count; i++) { @@ -46,7 +42,7 @@ static size_t rustsecp256k1zkp_v0_8_0_count_bits_set(const unsigned char* data, #ifdef USE_REDUCED_SURJECTION_PROOF_SIZE static #endif -int rustsecp256k1zkp_v0_8_0_surjectionproof_parse(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_surjectionproof *proof, const unsigned char *input, size_t inputlen) { +int rustsecp256k1zkp_v0_10_0_surjectionproof_parse(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_surjectionproof *proof, const unsigned char *input, size_t inputlen) { size_t n_inputs; size_t signature_len; @@ -75,7 +71,7 @@ int rustsecp256k1zkp_v0_8_0_surjectionproof_parse(const rustsecp256k1zkp_v0_8_0_ } } - signature_len = 32 * (1 + rustsecp256k1zkp_v0_8_0_count_bits_set(&input[2], (n_inputs + 7) / 8)); + signature_len = 32 * (1 + rustsecp256k1zkp_v0_10_0_count_bits_set(&input[2], (n_inputs + 7) / 8)); if (inputlen != 2 + (n_inputs + 7) / 8 + signature_len) { return 0; } @@ -86,7 +82,7 @@ int rustsecp256k1zkp_v0_8_0_surjectionproof_parse(const rustsecp256k1zkp_v0_8_0_ return 1; } -int rustsecp256k1zkp_v0_8_0_surjectionproof_serialize(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *output, size_t *outputlen, const rustsecp256k1zkp_v0_8_0_surjectionproof *proof) { +int rustsecp256k1zkp_v0_10_0_surjectionproof_serialize(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *output, size_t *outputlen, const rustsecp256k1zkp_v0_10_0_surjectionproof *proof) { size_t signature_len; size_t serialized_len; @@ -96,7 +92,7 @@ int rustsecp256k1zkp_v0_8_0_surjectionproof_serialize(const rustsecp256k1zkp_v0_ ARG_CHECK(proof != NULL); (void) ctx; - signature_len = 32 * (1 + rustsecp256k1zkp_v0_8_0_count_bits_set(proof->used_inputs, (proof->n_inputs + 7) / 8)); + signature_len = 32 * (1 + rustsecp256k1zkp_v0_10_0_count_bits_set(proof->used_inputs, (proof->n_inputs + 7) / 8)); serialized_len = 2 + (proof->n_inputs + 7) / 8 + signature_len; if (*outputlen < serialized_len) { return 0; @@ -111,37 +107,37 @@ int rustsecp256k1zkp_v0_8_0_surjectionproof_serialize(const rustsecp256k1zkp_v0_ return 1; } -size_t rustsecp256k1zkp_v0_8_0_surjectionproof_n_total_inputs(const rustsecp256k1zkp_v0_8_0_context* ctx, const rustsecp256k1zkp_v0_8_0_surjectionproof* proof) { +size_t rustsecp256k1zkp_v0_10_0_surjectionproof_n_total_inputs(const rustsecp256k1zkp_v0_10_0_context* ctx, const rustsecp256k1zkp_v0_10_0_surjectionproof* proof) { VERIFY_CHECK(ctx != NULL); ARG_CHECK(proof != NULL); (void) ctx; return proof->n_inputs; } -size_t rustsecp256k1zkp_v0_8_0_surjectionproof_n_used_inputs(const rustsecp256k1zkp_v0_8_0_context* ctx, const rustsecp256k1zkp_v0_8_0_surjectionproof* proof) { +size_t rustsecp256k1zkp_v0_10_0_surjectionproof_n_used_inputs(const rustsecp256k1zkp_v0_10_0_context* ctx, const rustsecp256k1zkp_v0_10_0_surjectionproof* proof) { VERIFY_CHECK(ctx != NULL); ARG_CHECK(proof != NULL); (void) ctx; - return rustsecp256k1zkp_v0_8_0_count_bits_set(proof->used_inputs, (proof->n_inputs + 7) / 8); + return rustsecp256k1zkp_v0_10_0_count_bits_set(proof->used_inputs, (proof->n_inputs + 7) / 8); } -size_t rustsecp256k1zkp_v0_8_0_surjectionproof_serialized_size(const rustsecp256k1zkp_v0_8_0_context* ctx, const rustsecp256k1zkp_v0_8_0_surjectionproof* proof) { +size_t rustsecp256k1zkp_v0_10_0_surjectionproof_serialized_size(const rustsecp256k1zkp_v0_10_0_context* ctx, const rustsecp256k1zkp_v0_10_0_surjectionproof* proof) { VERIFY_CHECK(ctx != NULL); ARG_CHECK(proof != NULL); - return 2 + (proof->n_inputs + 7) / 8 + 32 * (1 + rustsecp256k1zkp_v0_8_0_surjectionproof_n_used_inputs(ctx, proof)); + return 2 + (proof->n_inputs + 7) / 8 + 32 * (1 + rustsecp256k1zkp_v0_10_0_surjectionproof_n_used_inputs(ctx, proof)); } typedef struct { unsigned char state[32]; size_t state_i; -} rustsecp256k1zkp_v0_8_0_surjectionproof_csprng; +} rustsecp256k1zkp_v0_10_0_surjectionproof_csprng; -static void rustsecp256k1zkp_v0_8_0_surjectionproof_csprng_init(rustsecp256k1zkp_v0_8_0_surjectionproof_csprng *csprng, const unsigned char* state) { +static void rustsecp256k1zkp_v0_10_0_surjectionproof_csprng_init(rustsecp256k1zkp_v0_10_0_surjectionproof_csprng *csprng, const unsigned char* state) { memcpy(csprng->state, state, 32); csprng->state_i = 0; } -static size_t rustsecp256k1zkp_v0_8_0_surjectionproof_csprng_next(rustsecp256k1zkp_v0_8_0_surjectionproof_csprng *csprng, size_t rand_max) { +static size_t rustsecp256k1zkp_v0_10_0_surjectionproof_csprng_next(rustsecp256k1zkp_v0_10_0_surjectionproof_csprng *csprng, size_t rand_max) { /* The number of random bytes to read for each random sample */ const size_t increment = rand_max > 256 ? 2 : 1; /* The maximum value expressable by the number of random bytes we read */ @@ -152,10 +148,10 @@ static size_t rustsecp256k1zkp_v0_8_0_surjectionproof_csprng_next(rustsecp256k1z while (1) { size_t val; if (csprng->state_i + increment >= 32) { - rustsecp256k1zkp_v0_8_0_sha256 sha; - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, csprng->state, 32); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, csprng->state); + rustsecp256k1zkp_v0_10_0_sha256 sha; + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, csprng->state, 32); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, csprng->state); csprng->state_i = 0; } val = csprng->state[csprng->state_i]; @@ -171,8 +167,8 @@ static size_t rustsecp256k1zkp_v0_8_0_surjectionproof_csprng_next(rustsecp256k1z } } -int rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_surjectionproof* proof, size_t *input_index, const rustsecp256k1zkp_v0_8_0_fixed_asset_tag* fixed_input_tags, const size_t n_input_tags, const size_t n_input_tags_to_use, const rustsecp256k1zkp_v0_8_0_fixed_asset_tag* fixed_output_tag, const size_t n_max_iterations, const unsigned char *random_seed32) { - rustsecp256k1zkp_v0_8_0_surjectionproof_csprng csprng; +int rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_surjectionproof* proof, size_t *input_index, const rustsecp256k1zkp_v0_10_0_fixed_asset_tag* fixed_input_tags, const size_t n_input_tags, const size_t n_input_tags_to_use, const rustsecp256k1zkp_v0_10_0_fixed_asset_tag* fixed_output_tag, const size_t n_max_iterations, const unsigned char *random_seed32) { + rustsecp256k1zkp_v0_10_0_surjectionproof_csprng csprng; size_t n_iterations = 0; VERIFY_CHECK(ctx != NULL); @@ -186,7 +182,7 @@ int rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(const rustsecp256k1zkp_v0 ARG_CHECK(n_input_tags_to_use <= n_input_tags); (void) ctx; - rustsecp256k1zkp_v0_8_0_surjectionproof_csprng_init(&csprng, random_seed32); + rustsecp256k1zkp_v0_10_0_surjectionproof_csprng_init(&csprng, random_seed32); memset(proof->data, 0, sizeof(proof->data)); proof->n_inputs = n_input_tags; @@ -199,8 +195,8 @@ int rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(const rustsecp256k1zkp_v0 for (i = 0; i < n_input_tags_to_use; i++) { while (1) { size_t next_input_index; - next_input_index = rustsecp256k1zkp_v0_8_0_surjectionproof_csprng_next(&csprng, n_input_tags); - if (rustsecp256k1zkp_v0_8_0_memcmp_var(&fixed_input_tags[next_input_index], fixed_output_tag, sizeof(*fixed_output_tag)) == 0) { + next_input_index = rustsecp256k1zkp_v0_10_0_surjectionproof_csprng_next(&csprng, n_input_tags); + if (rustsecp256k1zkp_v0_10_0_memcmp_var(&fixed_input_tags[next_input_index], fixed_output_tag, sizeof(*fixed_output_tag)) == 0) { *input_index = next_input_index; has_output_tag = 1; } @@ -229,10 +225,10 @@ int rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(const rustsecp256k1zkp_v0 } } -int rustsecp256k1zkp_v0_8_0_surjectionproof_generate(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_surjectionproof* proof, const rustsecp256k1zkp_v0_8_0_generator* ephemeral_input_tags, size_t n_ephemeral_input_tags, const rustsecp256k1zkp_v0_8_0_generator* ephemeral_output_tag, size_t input_index, const unsigned char *input_blinding_key, const unsigned char *output_blinding_key) { - rustsecp256k1zkp_v0_8_0_scalar blinding_key; - rustsecp256k1zkp_v0_8_0_scalar tmps; - rustsecp256k1zkp_v0_8_0_scalar nonce; +int rustsecp256k1zkp_v0_10_0_surjectionproof_generate(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_surjectionproof* proof, const rustsecp256k1zkp_v0_10_0_generator* ephemeral_input_tags, size_t n_ephemeral_input_tags, const rustsecp256k1zkp_v0_10_0_generator* ephemeral_output_tag, size_t input_index, const unsigned char *input_blinding_key, const unsigned char *output_blinding_key) { + rustsecp256k1zkp_v0_10_0_scalar blinding_key; + rustsecp256k1zkp_v0_10_0_scalar tmps; + rustsecp256k1zkp_v0_10_0_scalar nonce; int overflow = 0; size_t rsizes[1]; /* array needed for borromean sig API */ size_t indices[1]; /* array needed for borromean sig API */ @@ -240,12 +236,12 @@ int rustsecp256k1zkp_v0_8_0_surjectionproof_generate(const rustsecp256k1zkp_v0_8 size_t n_total_pubkeys; size_t n_used_pubkeys; size_t ring_input_index = 0; - rustsecp256k1zkp_v0_8_0_gej ring_pubkeys[SECP256K1_SURJECTIONPROOF_MAX_USED_INPUTS]; - rustsecp256k1zkp_v0_8_0_scalar borromean_s[SECP256K1_SURJECTIONPROOF_MAX_USED_INPUTS]; + rustsecp256k1zkp_v0_10_0_gej ring_pubkeys[SECP256K1_SURJECTIONPROOF_MAX_USED_INPUTS]; + rustsecp256k1zkp_v0_10_0_scalar borromean_s[SECP256K1_SURJECTIONPROOF_MAX_USED_INPUTS]; unsigned char msg32[32]; VERIFY_CHECK(ctx != NULL); - ARG_CHECK(rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); ARG_CHECK(proof != NULL); ARG_CHECK(ephemeral_input_tags != NULL); ARG_CHECK(ephemeral_output_tag != NULL); @@ -255,16 +251,16 @@ int rustsecp256k1zkp_v0_8_0_surjectionproof_generate(const rustsecp256k1zkp_v0_8 CHECK(proof->initialized == 1); #endif - n_used_pubkeys = rustsecp256k1zkp_v0_8_0_surjectionproof_n_used_inputs(ctx, proof); + n_used_pubkeys = rustsecp256k1zkp_v0_10_0_surjectionproof_n_used_inputs(ctx, proof); /* This must be true if the proof was created with surjectionproof_initialize */ ARG_CHECK(n_used_pubkeys > 0); /* Compute secret key */ - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&tmps, input_blinding_key, &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&tmps, input_blinding_key, &overflow); if (overflow) { return 0; } - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&blinding_key, output_blinding_key, &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&blinding_key, output_blinding_key, &overflow); if (overflow) { return 0; } @@ -273,41 +269,41 @@ int rustsecp256k1zkp_v0_8_0_surjectionproof_generate(const rustsecp256k1zkp_v0_8 * it is deployed on Liquid and cannot be fixed without a hardfork. We should review * this at the same time that we relax the max-256-inputs rule. */ for (i = 0; i < n_ephemeral_input_tags; i++) { - if (rustsecp256k1zkp_v0_8_0_memcmp_var(ephemeral_input_tags[i].data, ephemeral_output_tag->data, sizeof(ephemeral_output_tag->data)) == 0) { + if (rustsecp256k1zkp_v0_10_0_memcmp_var(ephemeral_input_tags[i].data, ephemeral_output_tag->data, sizeof(ephemeral_output_tag->data)) == 0) { return 0; } } - rustsecp256k1zkp_v0_8_0_scalar_negate(&tmps, &tmps); - rustsecp256k1zkp_v0_8_0_scalar_add(&blinding_key, &blinding_key, &tmps); + rustsecp256k1zkp_v0_10_0_scalar_negate(&tmps, &tmps); + rustsecp256k1zkp_v0_10_0_scalar_add(&blinding_key, &blinding_key, &tmps); /* Compute public keys */ - n_total_pubkeys = rustsecp256k1zkp_v0_8_0_surjectionproof_n_total_inputs(ctx, proof); + n_total_pubkeys = rustsecp256k1zkp_v0_10_0_surjectionproof_n_total_inputs(ctx, proof); if (n_used_pubkeys > n_total_pubkeys || n_total_pubkeys != n_ephemeral_input_tags) { return 0; } - if (rustsecp256k1zkp_v0_8_0_surjection_compute_public_keys(ring_pubkeys, n_used_pubkeys, ephemeral_input_tags, n_total_pubkeys, proof->used_inputs, ephemeral_output_tag, input_index, &ring_input_index) == 0) { + if (rustsecp256k1zkp_v0_10_0_surjection_compute_public_keys(ring_pubkeys, n_used_pubkeys, ephemeral_input_tags, n_total_pubkeys, proof->used_inputs, ephemeral_output_tag, input_index, &ring_input_index) == 0) { return 0; } /* Produce signature */ rsizes[0] = (int) n_used_pubkeys; indices[0] = (int) ring_input_index; - rustsecp256k1zkp_v0_8_0_surjection_genmessage(msg32, ephemeral_input_tags, n_total_pubkeys, ephemeral_output_tag); - if (rustsecp256k1zkp_v0_8_0_surjection_genrand(borromean_s, n_used_pubkeys, &blinding_key) == 0) { + rustsecp256k1zkp_v0_10_0_surjection_genmessage(msg32, ephemeral_input_tags, n_total_pubkeys, ephemeral_output_tag); + if (rustsecp256k1zkp_v0_10_0_surjection_genrand(borromean_s, n_used_pubkeys, &blinding_key) == 0) { return 0; } /* Borromean sign will overwrite one of the s values we just generated, so use * it as a nonce instead. This avoids extra random generation and also is an * homage to the rangeproof code which does this very cleverly to encode messages. */ nonce = borromean_s[ring_input_index]; - rustsecp256k1zkp_v0_8_0_scalar_clear(&borromean_s[ring_input_index]); - if (rustsecp256k1zkp_v0_8_0_borromean_sign(&ctx->ecmult_gen_ctx, &proof->data[0], borromean_s, ring_pubkeys, &nonce, &blinding_key, rsizes, indices, 1, msg32, 32) == 0) { + rustsecp256k1zkp_v0_10_0_scalar_clear(&borromean_s[ring_input_index]); + if (rustsecp256k1zkp_v0_10_0_borromean_sign(&ctx->ecmult_gen_ctx, &proof->data[0], borromean_s, ring_pubkeys, &nonce, &blinding_key, rsizes, indices, 1, msg32, 32) == 0) { return 0; } for (i = 0; i < n_used_pubkeys; i++) { - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&proof->data[32 + 32 * i], &borromean_s[i]); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&proof->data[32 + 32 * i], &borromean_s[i]); } return 1; } @@ -315,13 +311,13 @@ int rustsecp256k1zkp_v0_8_0_surjectionproof_generate(const rustsecp256k1zkp_v0_8 #ifdef USE_REDUCED_SURJECTION_PROOF_SIZE static #endif -int rustsecp256k1zkp_v0_8_0_surjectionproof_verify(const rustsecp256k1zkp_v0_8_0_context* ctx, const rustsecp256k1zkp_v0_8_0_surjectionproof* proof, const rustsecp256k1zkp_v0_8_0_generator* ephemeral_input_tags, size_t n_ephemeral_input_tags, const rustsecp256k1zkp_v0_8_0_generator* ephemeral_output_tag) { +int rustsecp256k1zkp_v0_10_0_surjectionproof_verify(const rustsecp256k1zkp_v0_10_0_context* ctx, const rustsecp256k1zkp_v0_10_0_surjectionproof* proof, const rustsecp256k1zkp_v0_10_0_generator* ephemeral_input_tags, size_t n_ephemeral_input_tags, const rustsecp256k1zkp_v0_10_0_generator* ephemeral_output_tag) { size_t rsizes[1]; /* array needed for borromean sig API */ size_t i; size_t n_total_pubkeys; size_t n_used_pubkeys; - rustsecp256k1zkp_v0_8_0_gej ring_pubkeys[SECP256K1_SURJECTIONPROOF_MAX_USED_INPUTS]; - rustsecp256k1zkp_v0_8_0_scalar borromean_s[SECP256K1_SURJECTIONPROOF_MAX_USED_INPUTS]; + rustsecp256k1zkp_v0_10_0_gej ring_pubkeys[SECP256K1_SURJECTIONPROOF_MAX_USED_INPUTS]; + rustsecp256k1zkp_v0_10_0_scalar borromean_s[SECP256K1_SURJECTIONPROOF_MAX_USED_INPUTS]; unsigned char msg32[32]; VERIFY_CHECK(ctx != NULL); @@ -330,8 +326,8 @@ int rustsecp256k1zkp_v0_8_0_surjectionproof_verify(const rustsecp256k1zkp_v0_8_0 ARG_CHECK(ephemeral_output_tag != NULL); /* Compute public keys */ - n_total_pubkeys = rustsecp256k1zkp_v0_8_0_surjectionproof_n_total_inputs(ctx, proof); - n_used_pubkeys = rustsecp256k1zkp_v0_8_0_surjectionproof_n_used_inputs(ctx, proof); + n_total_pubkeys = rustsecp256k1zkp_v0_10_0_surjectionproof_n_total_inputs(ctx, proof); + n_used_pubkeys = rustsecp256k1zkp_v0_10_0_surjectionproof_n_used_inputs(ctx, proof); if (n_used_pubkeys == 0 || n_used_pubkeys > n_total_pubkeys || n_total_pubkeys != n_ephemeral_input_tags) { return 0; } @@ -341,7 +337,7 @@ int rustsecp256k1zkp_v0_8_0_surjectionproof_verify(const rustsecp256k1zkp_v0_8_0 return 0; } - if (rustsecp256k1zkp_v0_8_0_surjection_compute_public_keys(ring_pubkeys, n_used_pubkeys, ephemeral_input_tags, n_total_pubkeys, proof->used_inputs, ephemeral_output_tag, 0, NULL) == 0) { + if (rustsecp256k1zkp_v0_10_0_surjection_compute_public_keys(ring_pubkeys, n_used_pubkeys, ephemeral_input_tags, n_total_pubkeys, proof->used_inputs, ephemeral_output_tag, 0, NULL) == 0) { return 0; } @@ -349,13 +345,13 @@ int rustsecp256k1zkp_v0_8_0_surjectionproof_verify(const rustsecp256k1zkp_v0_8_0 rsizes[0] = (int) n_used_pubkeys; for (i = 0; i < n_used_pubkeys; i++) { int overflow = 0; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&borromean_s[i], &proof->data[32 + 32 * i], &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&borromean_s[i], &proof->data[32 + 32 * i], &overflow); if (overflow == 1) { return 0; } } - rustsecp256k1zkp_v0_8_0_surjection_genmessage(msg32, ephemeral_input_tags, n_total_pubkeys, ephemeral_output_tag); - return rustsecp256k1zkp_v0_8_0_borromean_verify(NULL, &proof->data[0], borromean_s, ring_pubkeys, rsizes, 1, msg32, 32); + rustsecp256k1zkp_v0_10_0_surjection_genmessage(msg32, ephemeral_input_tags, n_total_pubkeys, ephemeral_output_tag); + return rustsecp256k1zkp_v0_10_0_borromean_verify(NULL, &proof->data[0], borromean_s, ring_pubkeys, rsizes, 1, msg32, 32); } #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/surjection/surjection.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/surjection/surjection.h index 87eb96e6..7ddef58e 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/surjection/surjection.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/surjection/surjection.h @@ -4,16 +4,16 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef _SECP256K1_SURJECTION_H_ -#define _SECP256K1_SURJECTION_H_ +#ifndef SECP256K1_SURJECTION_H +#define SECP256K1_SURJECTION_H #include "../../group.h" #include "../../scalar.h" -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_surjection_genmessage(unsigned char *msg32, rustsecp256k1zkp_v0_8_0_ge *ephemeral_input_tags, size_t n_input_tags, rustsecp256k1zkp_v0_8_0_ge *ephemeral_output_tag); +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_surjection_genmessage(unsigned char *msg32, rustsecp256k1zkp_v0_10_0_ge *ephemeral_input_tags, size_t n_input_tags, rustsecp256k1zkp_v0_10_0_ge *ephemeral_output_tag); -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_surjection_genrand(rustsecp256k1zkp_v0_8_0_scalar *s, size_t ns, const rustsecp256k1zkp_v0_8_0_scalar *blinding_key); +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_surjection_genrand(rustsecp256k1zkp_v0_10_0_scalar *s, size_t ns, const rustsecp256k1zkp_v0_10_0_scalar *blinding_key); -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_surjection_compute_public_keys(rustsecp256k1zkp_v0_8_0_gej *pubkeys, size_t n_pubkeys, const rustsecp256k1zkp_v0_8_0_ge *input_tags, size_t n_input_tags, const unsigned char *used_tags, const rustsecp256k1zkp_v0_8_0_ge *output_tag, size_t input_index, size_t *ring_input_index); +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_surjection_compute_public_keys(rustsecp256k1zkp_v0_10_0_gej *pubkeys, size_t n_pubkeys, const rustsecp256k1zkp_v0_10_0_ge *input_tags, size_t n_input_tags, const unsigned char *used_tags, const rustsecp256k1zkp_v0_10_0_ge *output_tag, size_t input_index, size_t *ring_input_index); #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/surjection/surjection_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/surjection/surjection_impl.h index 39e12fc8..54501093 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/surjection/surjection_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/surjection/surjection_impl.h @@ -4,8 +4,8 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef _SECP256K1_SURJECTION_IMPL_H_ -#define _SECP256K1_SURJECTION_IMPL_H_ +#ifndef SECP256K1_SURJECTION_IMPL_H +#define SECP256K1_SURJECTION_IMPL_H #include @@ -14,32 +14,32 @@ #include "../../scalar.h" #include "../../hash.h" -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_surjection_genmessage(unsigned char *msg32, const rustsecp256k1zkp_v0_8_0_generator *ephemeral_input_tags, size_t n_input_tags, const rustsecp256k1zkp_v0_8_0_generator *ephemeral_output_tag) { +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_surjection_genmessage(unsigned char *msg32, const rustsecp256k1zkp_v0_10_0_generator *ephemeral_input_tags, size_t n_input_tags, const rustsecp256k1zkp_v0_10_0_generator *ephemeral_output_tag) { /* compute message */ size_t i; unsigned char pk_ser[33]; size_t pk_len = sizeof(pk_ser); - rustsecp256k1zkp_v0_8_0_sha256 sha256_en; + rustsecp256k1zkp_v0_10_0_sha256 sha256_en; - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha256_en); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha256_en); for (i = 0; i < n_input_tags; i++) { pk_ser[0] = 2 + (ephemeral_input_tags[i].data[63] & 1); memcpy(&pk_ser[1], &ephemeral_input_tags[i].data[0], 32); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_en, pk_ser, pk_len); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_en, pk_ser, pk_len); } pk_ser[0] = 2 + (ephemeral_output_tag->data[63] & 1); memcpy(&pk_ser[1], &ephemeral_output_tag->data[0], 32); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_en, pk_ser, pk_len); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha256_en, msg32); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_en, pk_ser, pk_len); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha256_en, msg32); } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_surjection_genrand(rustsecp256k1zkp_v0_8_0_scalar *s, size_t ns, const rustsecp256k1zkp_v0_8_0_scalar *blinding_key) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_surjection_genrand(rustsecp256k1zkp_v0_10_0_scalar *s, size_t ns, const rustsecp256k1zkp_v0_10_0_scalar *blinding_key) { size_t i; unsigned char sec_input[36]; - rustsecp256k1zkp_v0_8_0_sha256 sha256_en; + rustsecp256k1zkp_v0_10_0_sha256 sha256_en; /* compute s values */ - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&sec_input[4], blinding_key); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&sec_input[4], blinding_key); for (i = 0; i < ns; i++) { int overflow = 0; sec_input[0] = i; @@ -47,10 +47,10 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_surjection_genrand(rustsecp2 sec_input[2] = i >> 16; sec_input[3] = i >> 24; - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha256_en); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_en, sec_input, 36); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha256_en, sec_input); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&s[i], sec_input, &overflow); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha256_en); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_en, sec_input, 36); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha256_en, sec_input); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&s[i], sec_input, &overflow); if (overflow == 1) { memset(sec_input, 0, 32); return 0; @@ -60,29 +60,33 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_surjection_genrand(rustsecp2 return 1; } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_surjection_compute_public_keys(rustsecp256k1zkp_v0_8_0_gej *pubkeys, size_t n_pubkeys, const rustsecp256k1zkp_v0_8_0_generator *input_tags, size_t n_input_tags, const unsigned char *used_tags, const rustsecp256k1zkp_v0_8_0_generator *output_tag, size_t input_index, size_t *ring_input_index) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_surjection_compute_public_keys(rustsecp256k1zkp_v0_10_0_gej *pubkeys, size_t n_pubkeys, const rustsecp256k1zkp_v0_10_0_generator *input_tags, size_t n_input_tags, const unsigned char *used_tags, const rustsecp256k1zkp_v0_10_0_generator *output_tag, size_t input_index, size_t *ring_input_index) { size_t i; size_t j = 0; for (i = 0; i < n_input_tags; i++) { if (used_tags[i / 8] & (1 << (i % 8))) { - rustsecp256k1zkp_v0_8_0_ge tmpge; - rustsecp256k1zkp_v0_8_0_generator_load(&tmpge, &input_tags[i]); - rustsecp256k1zkp_v0_8_0_ge_neg(&tmpge, &tmpge); + rustsecp256k1zkp_v0_10_0_ge tmpge; + rustsecp256k1zkp_v0_10_0_generator_load(&tmpge, &input_tags[i]); + rustsecp256k1zkp_v0_10_0_ge_neg(&tmpge, &tmpge); VERIFY_CHECK(j < SECP256K1_SURJECTIONPROOF_MAX_USED_INPUTS); VERIFY_CHECK(j < n_pubkeys); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&pubkeys[j], &tmpge); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&pubkeys[j], &tmpge); - rustsecp256k1zkp_v0_8_0_generator_load(&tmpge, output_tag); - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&pubkeys[j], &pubkeys[j], &tmpge, NULL); + rustsecp256k1zkp_v0_10_0_generator_load(&tmpge, output_tag); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&pubkeys[j], &pubkeys[j], &tmpge, NULL); if (ring_input_index != NULL && input_index == i) { *ring_input_index = j; } j++; } } +#ifdef VERIFY /* Caller needs to ensure that the number of set bits in used_tags (which we counted in j) equals n_pubkeys. */ VERIFY_CHECK(j == n_pubkeys); +#else + (void)n_pubkeys; +#endif return 1; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/surjection/tests_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/surjection/tests_impl.h index 796eb305..046db41b 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/surjection/tests_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/surjection/tests_impl.h @@ -4,8 +4,8 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef SECP256K1_MODULE_SURJECTIONPROOF_TESTS -#define SECP256K1_MODULE_SURJECTIONPROOF_TESTS +#ifndef SECP256K1_MODULE_SURJECTIONPROOF_TESTS_H +#define SECP256K1_MODULE_SURJECTIONPROOF_TESTS_H #include "../../testrand.h" #include "../../group.h" @@ -15,209 +15,127 @@ static void test_surjectionproof_api(void) { unsigned char seed[32]; - rustsecp256k1zkp_v0_8_0_context *none = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_NONE); - rustsecp256k1zkp_v0_8_0_context *sign = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN); - rustsecp256k1zkp_v0_8_0_context *vrfy = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_VERIFY); - rustsecp256k1zkp_v0_8_0_context *both = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); - rustsecp256k1zkp_v0_8_0_context *sttc = rustsecp256k1zkp_v0_8_0_context_clone(rustsecp256k1zkp_v0_8_0_context_no_precomp); - rustsecp256k1zkp_v0_8_0_fixed_asset_tag fixed_input_tags[10]; - rustsecp256k1zkp_v0_8_0_fixed_asset_tag fixed_output_tag; - rustsecp256k1zkp_v0_8_0_generator ephemeral_input_tags[10]; - rustsecp256k1zkp_v0_8_0_generator ephemeral_output_tag; + rustsecp256k1zkp_v0_10_0_fixed_asset_tag fixed_input_tags[10]; + rustsecp256k1zkp_v0_10_0_fixed_asset_tag fixed_output_tag; + rustsecp256k1zkp_v0_10_0_generator ephemeral_input_tags[10]; + rustsecp256k1zkp_v0_10_0_generator ephemeral_output_tag; unsigned char input_blinding_key[10][32]; unsigned char output_blinding_key[32]; unsigned char serialized_proof[SECP256K1_SURJECTIONPROOF_SERIALIZATION_BYTES_MAX]; size_t serialized_len; - rustsecp256k1zkp_v0_8_0_surjectionproof proof; - rustsecp256k1zkp_v0_8_0_surjectionproof* proof_on_heap; + rustsecp256k1zkp_v0_10_0_surjectionproof proof; + rustsecp256k1zkp_v0_10_0_surjectionproof* proof_on_heap; size_t n_inputs = sizeof(fixed_input_tags) / sizeof(fixed_input_tags[0]); size_t input_index; - int32_t ecount = 0; size_t i; - rustsecp256k1zkp_v0_8_0_testrand256(seed); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(none, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(sign, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(vrfy, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(both, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(sttc, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(none, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sign, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(vrfy, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(both, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sttc, counting_illegal_callback_fn, &ecount); - + rustsecp256k1zkp_v0_10_0_testrand256(seed); for (i = 0; i < n_inputs; i++) { - rustsecp256k1zkp_v0_8_0_testrand256(input_blinding_key[i]); - rustsecp256k1zkp_v0_8_0_testrand256(fixed_input_tags[i].data); - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate_blinded(ctx, &ephemeral_input_tags[i], fixed_input_tags[i].data, input_blinding_key[i])); + rustsecp256k1zkp_v0_10_0_testrand256(input_blinding_key[i]); + rustsecp256k1zkp_v0_10_0_testrand256(fixed_input_tags[i].data); + CHECK(rustsecp256k1zkp_v0_10_0_generator_generate_blinded(CTX, &ephemeral_input_tags[i], fixed_input_tags[i].data, input_blinding_key[i])); } - rustsecp256k1zkp_v0_8_0_testrand256(output_blinding_key); + rustsecp256k1zkp_v0_10_0_testrand256(output_blinding_key); memcpy(&fixed_output_tag, &fixed_input_tags[0], sizeof(fixed_input_tags[0])); - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate_blinded(ctx, &ephemeral_output_tag, fixed_output_tag.data, output_blinding_key)); + CHECK(rustsecp256k1zkp_v0_10_0_generator_generate_blinded(CTX, &ephemeral_output_tag, fixed_output_tag.data, output_blinding_key)); /* check allocate_initialized */ - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_allocate_initialized(none, &proof_on_heap, &input_index, fixed_input_tags, n_inputs, 0, &fixed_input_tags[0], 100, seed) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_allocate_initialized(CTX, &proof_on_heap, &input_index, fixed_input_tags, n_inputs, 0, &fixed_input_tags[0], 100, seed) == 0); CHECK(proof_on_heap == 0); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_allocate_initialized(none, &proof_on_heap, &input_index, fixed_input_tags, n_inputs, 3, &fixed_input_tags[0], 100, seed) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_allocate_initialized(CTX, &proof_on_heap, &input_index, fixed_input_tags, n_inputs, 3, &fixed_input_tags[0], 100, seed) != 0); CHECK(proof_on_heap != 0); - rustsecp256k1zkp_v0_8_0_surjectionproof_destroy(proof_on_heap); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_allocate_initialized(none, NULL, &input_index, fixed_input_tags, n_inputs, 3, &fixed_input_tags[0], 100, seed) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_allocate_initialized(none, &proof_on_heap, NULL, fixed_input_tags, n_inputs, 3, &fixed_input_tags[0], 100, seed) == 0); + rustsecp256k1zkp_v0_10_0_surjectionproof_destroy(proof_on_heap); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_allocate_initialized(CTX, NULL, &input_index, fixed_input_tags, n_inputs, 3, &fixed_input_tags[0], 100, seed)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_allocate_initialized(CTX, &proof_on_heap, NULL, fixed_input_tags, n_inputs, 3, &fixed_input_tags[0], 100, seed)); CHECK(proof_on_heap == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_allocate_initialized(none, &proof_on_heap, &input_index, NULL, n_inputs, 3, &fixed_input_tags[0], 100, seed) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_allocate_initialized(CTX, &proof_on_heap, &input_index, NULL, n_inputs, 3, &fixed_input_tags[0], 100, seed)); CHECK(proof_on_heap == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_allocate_initialized(none, &proof_on_heap, &input_index, fixed_input_tags, SECP256K1_SURJECTIONPROOF_MAX_N_INPUTS + 1, 3, &fixed_input_tags[0], 100, seed) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_allocate_initialized(CTX, &proof_on_heap, &input_index, fixed_input_tags, SECP256K1_SURJECTIONPROOF_MAX_N_INPUTS + 1, 3, &fixed_input_tags[0], 100, seed)); CHECK(proof_on_heap == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_allocate_initialized(none, &proof_on_heap, &input_index, fixed_input_tags, n_inputs, n_inputs, &fixed_input_tags[0], 100, seed) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_allocate_initialized(CTX, &proof_on_heap, &input_index, fixed_input_tags, n_inputs, n_inputs, &fixed_input_tags[0], 100, seed) != 0); CHECK(proof_on_heap != 0); - rustsecp256k1zkp_v0_8_0_surjectionproof_destroy(proof_on_heap); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_allocate_initialized(none, &proof_on_heap, &input_index, fixed_input_tags, n_inputs, n_inputs + 1, &fixed_input_tags[0], 100, seed) == 0); + rustsecp256k1zkp_v0_10_0_surjectionproof_destroy(proof_on_heap); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_allocate_initialized(CTX, &proof_on_heap, &input_index, fixed_input_tags, n_inputs, n_inputs + 1, &fixed_input_tags[0], 100, seed)); CHECK(proof_on_heap == 0); - CHECK(ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_allocate_initialized(none, &proof_on_heap, &input_index, fixed_input_tags, n_inputs, 3, NULL, 100, seed) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_allocate_initialized(CTX, &proof_on_heap, &input_index, fixed_input_tags, n_inputs, 3, NULL, 100, seed)); CHECK(proof_on_heap == 0); - CHECK(ecount == 6); - CHECK((rustsecp256k1zkp_v0_8_0_surjectionproof_allocate_initialized(none, &proof_on_heap, &input_index, fixed_input_tags, n_inputs, 0, &fixed_input_tags[0], 0, seed) & 1) == 0); + CHECK((rustsecp256k1zkp_v0_10_0_surjectionproof_allocate_initialized(CTX, &proof_on_heap, &input_index, fixed_input_tags, n_inputs, 0, &fixed_input_tags[0], 0, seed) & 1) == 0); CHECK(proof_on_heap == 0); - CHECK(ecount == 6); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_allocate_initialized(none, &proof_on_heap, &input_index, fixed_input_tags, n_inputs, 0, &fixed_input_tags[0], 100, NULL) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_allocate_initialized(CTX, &proof_on_heap, &input_index, fixed_input_tags, n_inputs, 0, &fixed_input_tags[0], 100, NULL)); CHECK(proof_on_heap == 0); - CHECK(ecount == 7); - /* we are now going to test essentially the same functions, just without heap allocation. - * reset ecount. */ - ecount = 0; + /* we are now going to test essentially the same functions, just without + * heap allocation. */ /* check initialize */ - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(none, &proof, &input_index, fixed_input_tags, n_inputs, 0, &fixed_input_tags[0], 100, seed) == 0); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(none, &proof, &input_index, fixed_input_tags, n_inputs, 3, &fixed_input_tags[0], 100, seed) != 0); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(none, NULL, &input_index, fixed_input_tags, n_inputs, 3, &fixed_input_tags[0], 100, seed) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(none, &proof, NULL, fixed_input_tags, n_inputs, 3, &fixed_input_tags[0], 100, seed) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(none, &proof, &input_index, NULL, n_inputs, 3, &fixed_input_tags[0], 100, seed) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(none, &proof, &input_index, fixed_input_tags, SECP256K1_SURJECTIONPROOF_MAX_N_INPUTS + 1, 3, &fixed_input_tags[0], 100, seed) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(none, &proof, &input_index, fixed_input_tags, n_inputs, n_inputs, &fixed_input_tags[0], 100, seed) != 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(none, &proof, &input_index, fixed_input_tags, n_inputs, n_inputs + 1, &fixed_input_tags[0], 100, seed) == 0); - CHECK(ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(none, &proof, &input_index, fixed_input_tags, n_inputs, 3, NULL, 100, seed) == 0); - CHECK(ecount == 6); - CHECK((rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(none, &proof, &input_index, fixed_input_tags, n_inputs, 0, &fixed_input_tags[0], 0, seed) & 1) == 0); - CHECK(ecount == 6); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(none, &proof, &input_index, fixed_input_tags, n_inputs, 0, &fixed_input_tags[0], 100, NULL) == 0); - CHECK(ecount == 7); - - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(none, &proof, &input_index, fixed_input_tags, n_inputs, 3, &fixed_input_tags[0], 100, seed) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, &proof, &input_index, fixed_input_tags, n_inputs, 0, &fixed_input_tags[0], 100, seed) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, &proof, &input_index, fixed_input_tags, n_inputs, 3, &fixed_input_tags[0], 100, seed) != 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, NULL, &input_index, fixed_input_tags, n_inputs, 3, &fixed_input_tags[0], 100, seed)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, &proof, NULL, fixed_input_tags, n_inputs, 3, &fixed_input_tags[0], 100, seed)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, &proof, &input_index, NULL, n_inputs, 3, &fixed_input_tags[0], 100, seed)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, &proof, &input_index, fixed_input_tags, SECP256K1_SURJECTIONPROOF_MAX_N_INPUTS + 1, 3, &fixed_input_tags[0], 100, seed)); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, &proof, &input_index, fixed_input_tags, n_inputs, n_inputs, &fixed_input_tags[0], 100, seed) != 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, &proof, &input_index, fixed_input_tags, n_inputs, n_inputs + 1, &fixed_input_tags[0], 100, seed)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, &proof, &input_index, fixed_input_tags, n_inputs, 3, NULL, 100, seed)); + CHECK((rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, &proof, &input_index, fixed_input_tags, n_inputs, 0, &fixed_input_tags[0], 0, seed) & 1) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, &proof, &input_index, fixed_input_tags, n_inputs, 0, &fixed_input_tags[0], 100, NULL)); + + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, &proof, &input_index, fixed_input_tags, n_inputs, 3, &fixed_input_tags[0], 100, seed) != 0); /* check generate */ - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_generate(none, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) != 0); - CHECK(ecount == 7); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_generate(vrfy, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) != 0); - CHECK(ecount == 7); - - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_generate(sign, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_generate(both, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) != 0); - CHECK(ecount == 7); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_generate(sttc, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) == 0); - CHECK(ecount == 8); - - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_generate(both, NULL, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) == 0); - CHECK(ecount == 9); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_generate(both, &proof, NULL, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) == 0); - CHECK(ecount == 10); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_generate(both, &proof, ephemeral_input_tags, n_inputs + 1, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) == 0); - CHECK(ecount == 10); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_generate(both, &proof, ephemeral_input_tags, n_inputs - 1, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) == 0); - CHECK(ecount == 10); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_generate(both, &proof, ephemeral_input_tags, 0, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) == 0); - CHECK(ecount == 10); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_generate(both, &proof, ephemeral_input_tags, n_inputs, NULL, 0, input_blinding_key[0], output_blinding_key) == 0); - CHECK(ecount == 11); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_generate(both, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 1, input_blinding_key[0], output_blinding_key) != 0); - CHECK(ecount == 11); /* the above line "succeeds" but generates an invalid proof as the input_index is wrong. it is fairly expensive to detect this. should we? */ - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_generate(both, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, n_inputs + 1, input_blinding_key[0], output_blinding_key) != 0); - CHECK(ecount == 11); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_generate(both, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, NULL, output_blinding_key) == 0); - CHECK(ecount == 12); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_generate(both, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], NULL) == 0); - CHECK(ecount == 13); - - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_generate(both, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_generate(CTX, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) != 0); + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_generate(STATIC_CTX, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key)); + + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_generate(CTX, NULL, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_generate(CTX, &proof, NULL, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key)); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_generate(CTX, &proof, ephemeral_input_tags, n_inputs + 1, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_generate(CTX, &proof, ephemeral_input_tags, n_inputs - 1, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_generate(CTX, &proof, ephemeral_input_tags, 0, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_generate(CTX, &proof, ephemeral_input_tags, n_inputs, NULL, 0, input_blinding_key[0], output_blinding_key)); + /* the below line "succeeds" but generates an invalid proof as the input_index is wrong. it is fairly expensive to detect this. should we? */ + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_generate(CTX, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 1, input_blinding_key[0], output_blinding_key) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_generate(CTX, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, n_inputs + 1, input_blinding_key[0], output_blinding_key) != 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_generate(CTX, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, NULL, output_blinding_key)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_generate(CTX, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], NULL)); + + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_generate(CTX, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) != 0); /* check verify */ - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_verify(none, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_verify(sign, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_verify(vrfy, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag) == 1); - CHECK(ecount == 13); - - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_verify(vrfy, NULL, ephemeral_input_tags, n_inputs, &ephemeral_output_tag) == 0); - CHECK(ecount == 14); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_verify(vrfy, &proof, NULL, n_inputs, &ephemeral_output_tag) == 0); - CHECK(ecount == 15); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_verify(vrfy, &proof, ephemeral_input_tags, n_inputs - 1, &ephemeral_output_tag) == 0); - CHECK(ecount == 15); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_verify(vrfy, &proof, ephemeral_input_tags, n_inputs + 1, &ephemeral_output_tag) == 0); - CHECK(ecount == 15); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_verify(vrfy, &proof, ephemeral_input_tags, n_inputs, NULL) == 0); - CHECK(ecount == 16); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_verify(CTX, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag) == 1); + + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_verify(CTX, NULL, ephemeral_input_tags, n_inputs, &ephemeral_output_tag)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_verify(CTX, &proof, NULL, n_inputs, &ephemeral_output_tag)); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_verify(CTX, &proof, ephemeral_input_tags, n_inputs - 1, &ephemeral_output_tag) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_verify(CTX, &proof, ephemeral_input_tags, n_inputs + 1, &ephemeral_output_tag) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_verify(CTX, &proof, ephemeral_input_tags, n_inputs, NULL)); /* Test how surjectionproof_generate fails when the proof was not created * with surjectionproof_initialize */ - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_generate(sign, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_generate(CTX, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) == 1); { - rustsecp256k1zkp_v0_8_0_surjectionproof tmp_proof = proof; + rustsecp256k1zkp_v0_10_0_surjectionproof tmp_proof = proof; tmp_proof.n_inputs = 0; - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_generate(sign, &tmp_proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_generate(CTX, &tmp_proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key)); } - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_generate(sign, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_generate(CTX, &proof, ephemeral_input_tags, n_inputs, &ephemeral_output_tag, 0, input_blinding_key[0], output_blinding_key) == 1); /* Check serialize */ - ecount = 0; serialized_len = sizeof(serialized_proof); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_serialize(none, serialized_proof, &serialized_len, &proof) != 0); - CHECK(ecount == 0); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_serialize(CTX, serialized_proof, &serialized_len, &proof) != 0); serialized_len = sizeof(serialized_proof); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_serialize(none, NULL, &serialized_len, &proof) == 0); - CHECK(ecount == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_serialize(CTX, NULL, &serialized_len, &proof)); serialized_len = sizeof(serialized_proof); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_serialize(none, serialized_proof, NULL, &proof) == 0); - CHECK(ecount == 2); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_serialize(CTX, serialized_proof, NULL, &proof)); serialized_len = sizeof(serialized_proof); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_serialize(none, serialized_proof, &serialized_len, NULL) == 0); - CHECK(ecount == 3); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_serialize(CTX, serialized_proof, &serialized_len, NULL)); serialized_len = sizeof(serialized_proof); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_serialize(none, serialized_proof, &serialized_len, &proof) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_serialize(CTX, serialized_proof, &serialized_len, &proof) != 0); /* Check parse */ - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_parse(none, &proof, serialized_proof, serialized_len) != 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_parse(none, NULL, serialized_proof, serialized_len) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_parse(none, &proof, NULL, serialized_len) == 0); - CHECK(ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_parse(none, &proof, serialized_proof, 0) == 0); - CHECK(ecount == 5); - - rustsecp256k1zkp_v0_8_0_context_destroy(none); - rustsecp256k1zkp_v0_8_0_context_destroy(sign); - rustsecp256k1zkp_v0_8_0_context_destroy(vrfy); - rustsecp256k1zkp_v0_8_0_context_destroy(both); - rustsecp256k1zkp_v0_8_0_context_destroy(sttc); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, serialized_proof, serialized_len) != 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, NULL, serialized_proof, serialized_len)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, NULL, serialized_len)); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, serialized_proof, 0) == 0); } static void test_input_selection(size_t n_inputs) { @@ -226,70 +144,70 @@ static void test_input_selection(size_t n_inputs) { size_t result; size_t input_index; size_t try_count = n_inputs * 100; - rustsecp256k1zkp_v0_8_0_surjectionproof proof; - rustsecp256k1zkp_v0_8_0_fixed_asset_tag fixed_input_tags[1000]; + rustsecp256k1zkp_v0_10_0_surjectionproof proof; + rustsecp256k1zkp_v0_10_0_fixed_asset_tag fixed_input_tags[1000]; const size_t max_n_inputs = sizeof(fixed_input_tags) / sizeof(fixed_input_tags[0]) - 1; CHECK(n_inputs < max_n_inputs); - rustsecp256k1zkp_v0_8_0_testrand256(seed); + rustsecp256k1zkp_v0_10_0_testrand256(seed); for (i = 0; i < n_inputs + 1; i++) { - rustsecp256k1zkp_v0_8_0_testrand256(fixed_input_tags[i].data); + rustsecp256k1zkp_v0_10_0_testrand256(fixed_input_tags[i].data); } /* cannot match output when told to use zero keys */ - result = rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(ctx, &proof, &input_index, fixed_input_tags, n_inputs, 0, &fixed_input_tags[0], try_count, seed); + result = rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, &proof, &input_index, fixed_input_tags, n_inputs, 0, &fixed_input_tags[0], try_count, seed); CHECK(result == 0); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_n_used_inputs(ctx, &proof) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_n_total_inputs(ctx, &proof) == n_inputs); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_serialized_size(ctx, &proof) == 34 + (n_inputs + 7) / 8); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_n_used_inputs(CTX, &proof) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_n_total_inputs(CTX, &proof) == n_inputs); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_serialized_size(CTX, &proof) == 34 + (n_inputs + 7) / 8); if (n_inputs > 0) { /* succeed in 100*n_inputs tries (probability of failure e^-100) */ - result = rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(ctx, &proof, &input_index, fixed_input_tags, n_inputs, 1, &fixed_input_tags[0], try_count, seed); + result = rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, &proof, &input_index, fixed_input_tags, n_inputs, 1, &fixed_input_tags[0], try_count, seed); CHECK(result > 0); CHECK(result < n_inputs * 10); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_n_used_inputs(ctx, &proof) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_n_total_inputs(ctx, &proof) == n_inputs); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_serialized_size(ctx, &proof) == 66 + (n_inputs + 7) / 8); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_n_used_inputs(CTX, &proof) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_n_total_inputs(CTX, &proof) == n_inputs); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_serialized_size(CTX, &proof) == 66 + (n_inputs + 7) / 8); CHECK(input_index == 0); } if (n_inputs >= 3) { /* succeed in 10*n_inputs tries (probability of failure e^-10) */ - result = rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(ctx, &proof, &input_index, fixed_input_tags, n_inputs, 3, &fixed_input_tags[1], try_count, seed); + result = rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, &proof, &input_index, fixed_input_tags, n_inputs, 3, &fixed_input_tags[1], try_count, seed); CHECK(result > 0); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_n_used_inputs(ctx, &proof) == 3); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_n_total_inputs(ctx, &proof) == n_inputs); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_serialized_size(ctx, &proof) == 130 + (n_inputs + 7) / 8); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_n_used_inputs(CTX, &proof) == 3); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_n_total_inputs(CTX, &proof) == n_inputs); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_serialized_size(CTX, &proof) == 130 + (n_inputs + 7) / 8); CHECK(input_index == 1); /* fail, key not found */ - result = rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(ctx, &proof, &input_index, fixed_input_tags, n_inputs, 3, &fixed_input_tags[n_inputs], try_count, seed); + result = rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, &proof, &input_index, fixed_input_tags, n_inputs, 3, &fixed_input_tags[n_inputs], try_count, seed); CHECK(result == 0); /* succeed on first try when told to use all keys */ - result = rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(ctx, &proof, &input_index, fixed_input_tags, n_inputs, n_inputs, &fixed_input_tags[0], try_count, seed); + result = rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, &proof, &input_index, fixed_input_tags, n_inputs, n_inputs, &fixed_input_tags[0], try_count, seed); CHECK(result == 1); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_n_used_inputs(ctx, &proof) == n_inputs); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_n_total_inputs(ctx, &proof) == n_inputs); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_serialized_size(ctx, &proof) == 2 + 32 * (n_inputs + 1) + (n_inputs + 7) / 8); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_n_used_inputs(CTX, &proof) == n_inputs); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_n_total_inputs(CTX, &proof) == n_inputs); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_serialized_size(CTX, &proof) == 2 + 32 * (n_inputs + 1) + (n_inputs + 7) / 8); CHECK(input_index == 0); /* succeed in less than 64 tries when told to use half keys. (probability of failure 2^-64) */ - result = rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(ctx, &proof, &input_index, fixed_input_tags, n_inputs, n_inputs / 2, &fixed_input_tags[0], 64, seed); + result = rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, &proof, &input_index, fixed_input_tags, n_inputs, n_inputs / 2, &fixed_input_tags[0], 64, seed); CHECK(result > 0); CHECK(result < 64); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_n_used_inputs(ctx, &proof) == n_inputs / 2); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_n_total_inputs(ctx, &proof) == n_inputs); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_serialized_size(ctx, &proof) == 2 + 32 * (n_inputs / 2 + 1) + (n_inputs + 7) / 8); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_n_used_inputs(CTX, &proof) == n_inputs / 2); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_n_total_inputs(CTX, &proof) == n_inputs); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_serialized_size(CTX, &proof) == 2 + 32 * (n_inputs / 2 + 1) + (n_inputs + 7) / 8); CHECK(input_index == 0); } } /** Runs surjectionproof_initilize multiple times and records the number of times each input was used. */ -static void test_input_selection_distribution_helper(const rustsecp256k1zkp_v0_8_0_fixed_asset_tag* fixed_input_tags, const size_t n_input_tags, const size_t n_input_tags_to_use, size_t *used_inputs) { - rustsecp256k1zkp_v0_8_0_surjectionproof proof; +static void test_input_selection_distribution_helper(const rustsecp256k1zkp_v0_10_0_fixed_asset_tag* fixed_input_tags, const size_t n_input_tags, const size_t n_input_tags_to_use, size_t *used_inputs) { + rustsecp256k1zkp_v0_10_0_surjectionproof proof; size_t input_index; size_t i; size_t j; @@ -299,8 +217,8 @@ static void test_input_selection_distribution_helper(const rustsecp256k1zkp_v0_8 used_inputs[i] = 0; } for(j = 0; j < 10000; j++) { - rustsecp256k1zkp_v0_8_0_testrand256(seed); - result = rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(ctx, &proof, &input_index, fixed_input_tags, n_input_tags, n_input_tags_to_use, &fixed_input_tags[0], 64, seed); + rustsecp256k1zkp_v0_10_0_testrand256(seed); + result = rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, &proof, &input_index, fixed_input_tags, n_input_tags, n_input_tags_to_use, &fixed_input_tags[0], 64, seed); CHECK(result > 0); for (i = 0; i < n_input_tags; i++) { @@ -318,11 +236,11 @@ static void test_input_selection_distribution(void) { size_t i; size_t n_input_tags_to_use; const size_t n_inputs = 4; - rustsecp256k1zkp_v0_8_0_fixed_asset_tag fixed_input_tags[4]; + rustsecp256k1zkp_v0_10_0_fixed_asset_tag fixed_input_tags[4]; size_t used_inputs[4]; for (i = 0; i < n_inputs; i++) { - rustsecp256k1zkp_v0_8_0_testrand256(fixed_input_tags[i].data); + rustsecp256k1zkp_v0_10_0_testrand256(fixed_input_tags[i].data); } /* If there is one input tag to use, initialize must choose the one equal to fixed_output_tag. */ @@ -388,12 +306,12 @@ static void test_input_selection_distribution(void) { static void test_gen_verify(size_t n_inputs, size_t n_used) { unsigned char seed[32]; - rustsecp256k1zkp_v0_8_0_surjectionproof proof; + rustsecp256k1zkp_v0_10_0_surjectionproof proof; unsigned char serialized_proof[SECP256K1_SURJECTIONPROOF_SERIALIZATION_BYTES_MAX]; unsigned char serialized_proof_trailing[SECP256K1_SURJECTIONPROOF_SERIALIZATION_BYTES_MAX + 1]; size_t serialized_len = SECP256K1_SURJECTIONPROOF_SERIALIZATION_BYTES_MAX; - rustsecp256k1zkp_v0_8_0_fixed_asset_tag fixed_input_tags[1000]; - rustsecp256k1zkp_v0_8_0_generator ephemeral_input_tags[1000]; + rustsecp256k1zkp_v0_10_0_fixed_asset_tag fixed_input_tags[1000]; + rustsecp256k1zkp_v0_10_0_generator ephemeral_input_tags[1000]; unsigned char *input_blinding_key[1000]; const size_t max_n_inputs = sizeof(fixed_input_tags) / sizeof(fixed_input_tags[0]) - 1; size_t try_count = n_inputs * 100; @@ -405,24 +323,24 @@ static void test_gen_verify(size_t n_inputs, size_t n_used) { /* setup */ CHECK(n_used <= n_inputs); CHECK(n_inputs < max_n_inputs); - rustsecp256k1zkp_v0_8_0_testrand256(seed); + rustsecp256k1zkp_v0_10_0_testrand256(seed); key_index = (((size_t) seed[0] << 8) + seed[1]) % n_inputs; for (i = 0; i < n_inputs + 1; i++) { input_blinding_key[i] = malloc(32); - rustsecp256k1zkp_v0_8_0_testrand256(input_blinding_key[i]); + rustsecp256k1zkp_v0_10_0_testrand256(input_blinding_key[i]); /* choose random fixed tag, except that for the output one copy from the key_index */ if (i < n_inputs) { - rustsecp256k1zkp_v0_8_0_testrand256(fixed_input_tags[i].data); + rustsecp256k1zkp_v0_10_0_testrand256(fixed_input_tags[i].data); } else { memcpy(&fixed_input_tags[i], &fixed_input_tags[key_index], sizeof(fixed_input_tags[i])); } - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate_blinded(ctx, &ephemeral_input_tags[i], fixed_input_tags[i].data, input_blinding_key[i])); + CHECK(rustsecp256k1zkp_v0_10_0_generator_generate_blinded(CTX, &ephemeral_input_tags[i], fixed_input_tags[i].data, input_blinding_key[i])); } /* test */ - result = rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(ctx, &proof, &input_index, fixed_input_tags, n_inputs, n_used, &fixed_input_tags[key_index], try_count, seed); + result = rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, &proof, &input_index, fixed_input_tags, n_inputs, n_used, &fixed_input_tags[key_index], try_count, seed); if (n_used == 0) { CHECK(result == 0); return; @@ -430,32 +348,32 @@ static void test_gen_verify(size_t n_inputs, size_t n_used) { CHECK(result > 0); CHECK(input_index == key_index); - result = rustsecp256k1zkp_v0_8_0_surjectionproof_generate(ctx, &proof, ephemeral_input_tags, n_inputs, &ephemeral_input_tags[n_inputs], input_index, input_blinding_key[input_index], input_blinding_key[n_inputs]); + result = rustsecp256k1zkp_v0_10_0_surjectionproof_generate(CTX, &proof, ephemeral_input_tags, n_inputs, &ephemeral_input_tags[n_inputs], input_index, input_blinding_key[input_index], input_blinding_key[n_inputs]); CHECK(result == 1); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_serialize(ctx, serialized_proof, &serialized_len, &proof)); - CHECK(serialized_len == rustsecp256k1zkp_v0_8_0_surjectionproof_serialized_size(ctx, &proof)); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_serialize(CTX, serialized_proof, &serialized_len, &proof)); + CHECK(serialized_len == rustsecp256k1zkp_v0_10_0_surjectionproof_serialized_size(CTX, &proof)); CHECK(serialized_len == SECP256K1_SURJECTIONPROOF_SERIALIZATION_BYTES(n_inputs, n_used)); /* trailing garbage */ memcpy(&serialized_proof_trailing, &serialized_proof, serialized_len); serialized_proof_trailing[serialized_len] = seed[0]; - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_parse(ctx, &proof, serialized_proof_trailing, serialized_len + 1) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, serialized_proof_trailing, serialized_len + 1) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_parse(ctx, &proof, serialized_proof, serialized_len)); - result = rustsecp256k1zkp_v0_8_0_surjectionproof_verify(ctx, &proof, ephemeral_input_tags, n_inputs, &ephemeral_input_tags[n_inputs]); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, serialized_proof, serialized_len)); + result = rustsecp256k1zkp_v0_10_0_surjectionproof_verify(CTX, &proof, ephemeral_input_tags, n_inputs, &ephemeral_input_tags[n_inputs]); CHECK(result == 1); /* various fail cases */ if (n_inputs > 1) { - result = rustsecp256k1zkp_v0_8_0_surjectionproof_verify(ctx, &proof, ephemeral_input_tags, n_inputs, &ephemeral_input_tags[n_inputs - 1]); + result = rustsecp256k1zkp_v0_10_0_surjectionproof_verify(CTX, &proof, ephemeral_input_tags, n_inputs, &ephemeral_input_tags[n_inputs - 1]); CHECK(result == 0); /* number of entries in ephemeral_input_tags array is less than proof.n_inputs */ n_inputs -= 1; - result = rustsecp256k1zkp_v0_8_0_surjectionproof_generate(ctx, &proof, ephemeral_input_tags, n_inputs, &ephemeral_input_tags[n_inputs], input_index, input_blinding_key[input_index], input_blinding_key[n_inputs]); + result = rustsecp256k1zkp_v0_10_0_surjectionproof_generate(CTX, &proof, ephemeral_input_tags, n_inputs, &ephemeral_input_tags[n_inputs], input_index, input_blinding_key[input_index], input_blinding_key[n_inputs]); CHECK(result == 0); - result = rustsecp256k1zkp_v0_8_0_surjectionproof_verify(ctx, &proof, ephemeral_input_tags, n_inputs, &ephemeral_input_tags[n_inputs - 1]); + result = rustsecp256k1zkp_v0_10_0_surjectionproof_verify(CTX, &proof, ephemeral_input_tags, n_inputs, &ephemeral_input_tags[n_inputs - 1]); CHECK(result == 0); n_inputs += 1; } @@ -463,7 +381,7 @@ static void test_gen_verify(size_t n_inputs, size_t n_used) { for (i = 0; i < n_inputs; i++) { /* flip bit */ proof.used_inputs[i / 8] ^= (1 << (i % 8)); - result = rustsecp256k1zkp_v0_8_0_surjectionproof_verify(ctx, &proof, ephemeral_input_tags, n_inputs, &ephemeral_input_tags[n_inputs]); + result = rustsecp256k1zkp_v0_10_0_surjectionproof_verify(CTX, &proof, ephemeral_input_tags, n_inputs, &ephemeral_input_tags[n_inputs]); CHECK(result == 0); /* reset the bit */ proof.used_inputs[i / 8] ^= (1 << (i % 8)); @@ -477,93 +395,93 @@ static void test_gen_verify(size_t n_inputs, size_t n_used) { /* check that a proof with empty n_used_inputs is invalid */ static void test_no_used_inputs_verify(void) { - rustsecp256k1zkp_v0_8_0_surjectionproof proof; - rustsecp256k1zkp_v0_8_0_fixed_asset_tag fixed_input_tag; - rustsecp256k1zkp_v0_8_0_fixed_asset_tag fixed_output_tag; - rustsecp256k1zkp_v0_8_0_generator ephemeral_input_tags[1]; + rustsecp256k1zkp_v0_10_0_surjectionproof proof; + rustsecp256k1zkp_v0_10_0_fixed_asset_tag fixed_input_tag; + rustsecp256k1zkp_v0_10_0_fixed_asset_tag fixed_output_tag; + rustsecp256k1zkp_v0_10_0_generator ephemeral_input_tags[1]; size_t n_ephemeral_input_tags = 1; - rustsecp256k1zkp_v0_8_0_generator ephemeral_output_tag; + rustsecp256k1zkp_v0_10_0_generator ephemeral_output_tag; unsigned char blinding_key[32]; - rustsecp256k1zkp_v0_8_0_ge output; - rustsecp256k1zkp_v0_8_0_sha256 sha256_e0; + rustsecp256k1zkp_v0_10_0_ge output; + rustsecp256k1zkp_v0_10_0_sha256 sha256_e0; int result; - /* Create proof that doesn't use inputs. rustsecp256k1zkp_v0_8_0_surjectionproof_initialize + /* Create proof that doesn't use inputs. rustsecp256k1zkp_v0_10_0_surjectionproof_initialize * will not work here since it insists on selecting an input that matches the output. */ proof.n_inputs = 1; memset(proof.used_inputs, 0, SECP256K1_SURJECTIONPROOF_MAX_N_INPUTS / 8); /* create different fixed input and output tags */ - rustsecp256k1zkp_v0_8_0_testrand256(fixed_input_tag.data); - rustsecp256k1zkp_v0_8_0_testrand256(fixed_output_tag.data); + rustsecp256k1zkp_v0_10_0_testrand256(fixed_input_tag.data); + rustsecp256k1zkp_v0_10_0_testrand256(fixed_output_tag.data); /* blind fixed output tags with random blinding key */ - rustsecp256k1zkp_v0_8_0_testrand256(blinding_key); - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate_blinded(ctx, &ephemeral_input_tags[0], fixed_input_tag.data, blinding_key)); - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate_blinded(ctx, &ephemeral_output_tag, fixed_output_tag.data, blinding_key)); + rustsecp256k1zkp_v0_10_0_testrand256(blinding_key); + CHECK(rustsecp256k1zkp_v0_10_0_generator_generate_blinded(CTX, &ephemeral_input_tags[0], fixed_input_tag.data, blinding_key)); + CHECK(rustsecp256k1zkp_v0_10_0_generator_generate_blinded(CTX, &ephemeral_output_tag, fixed_output_tag.data, blinding_key)); /* create "borromean signature" which is just a hash of metadata (pubkeys, etc) in this case */ - rustsecp256k1zkp_v0_8_0_generator_load(&output, &ephemeral_output_tag); - rustsecp256k1zkp_v0_8_0_surjection_genmessage(proof.data, ephemeral_input_tags, 1, &ephemeral_output_tag); - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha256_e0); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha256_e0, proof.data, 32); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha256_e0, proof.data); + rustsecp256k1zkp_v0_10_0_generator_load(&output, &ephemeral_output_tag); + rustsecp256k1zkp_v0_10_0_surjection_genmessage(proof.data, ephemeral_input_tags, 1, &ephemeral_output_tag); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha256_e0); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha256_e0, proof.data, 32); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha256_e0, proof.data); - result = rustsecp256k1zkp_v0_8_0_surjectionproof_verify(ctx, &proof, ephemeral_input_tags, n_ephemeral_input_tags, &ephemeral_output_tag); + result = rustsecp256k1zkp_v0_10_0_surjectionproof_verify(CTX, &proof, ephemeral_input_tags, n_ephemeral_input_tags, &ephemeral_output_tag); CHECK(result == 0); } -void test_bad_serialize(void) { - rustsecp256k1zkp_v0_8_0_surjectionproof proof; +static void test_bad_serialize(void) { + rustsecp256k1zkp_v0_10_0_surjectionproof proof; unsigned char serialized_proof[SECP256K1_SURJECTIONPROOF_SERIALIZATION_BYTES_MAX]; size_t serialized_len; proof.n_inputs = 0; serialized_len = 2 + 31; /* e0 is one byte too short */ - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_serialize(ctx, serialized_proof, &serialized_len, &proof) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_serialize(CTX, serialized_proof, &serialized_len, &proof) == 0); } -void test_bad_parse(void) { - rustsecp256k1zkp_v0_8_0_surjectionproof proof; +static void test_bad_parse(void) { + rustsecp256k1zkp_v0_10_0_surjectionproof proof; unsigned char serialized_proof0[] = { 0x00 }; unsigned char serialized_proof1[] = { 0x01, 0x00 }; unsigned char serialized_proof2[33] = { 0 }; /* Missing total input count */ - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_parse(ctx, &proof, serialized_proof0, sizeof(serialized_proof0)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, serialized_proof0, sizeof(serialized_proof0)) == 0); /* Missing bitmap */ - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_parse(ctx, &proof, serialized_proof1, sizeof(serialized_proof1)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, serialized_proof1, sizeof(serialized_proof1)) == 0); /* Missing e0 value */ - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_parse(ctx, &proof, serialized_proof2, sizeof(serialized_proof2)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, serialized_proof2, sizeof(serialized_proof2)) == 0); } -void test_input_eq_output(void) { - rustsecp256k1zkp_v0_8_0_surjectionproof proof; - rustsecp256k1zkp_v0_8_0_fixed_asset_tag fixed_tag; - rustsecp256k1zkp_v0_8_0_generator ephemeral_tag; +static void test_input_eq_output(void) { + rustsecp256k1zkp_v0_10_0_surjectionproof proof; + rustsecp256k1zkp_v0_10_0_fixed_asset_tag fixed_tag; + rustsecp256k1zkp_v0_10_0_generator ephemeral_tag; unsigned char blinding_key[32]; unsigned char entropy[32]; size_t input_index; - rustsecp256k1zkp_v0_8_0_testrand256(fixed_tag.data); - rustsecp256k1zkp_v0_8_0_testrand256(blinding_key); - rustsecp256k1zkp_v0_8_0_testrand256(entropy); + rustsecp256k1zkp_v0_10_0_testrand256(fixed_tag.data); + rustsecp256k1zkp_v0_10_0_testrand256(blinding_key); + rustsecp256k1zkp_v0_10_0_testrand256(entropy); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_initialize(ctx, &proof, &input_index, &fixed_tag, 1, 1, &fixed_tag, 100, entropy) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_initialize(CTX, &proof, &input_index, &fixed_tag, 1, 1, &fixed_tag, 100, entropy) == 1); CHECK(input_index == 0); /* Generation should fail */ - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate_blinded(ctx, &ephemeral_tag, fixed_tag.data, blinding_key)); - CHECK(!rustsecp256k1zkp_v0_8_0_surjectionproof_generate(ctx, &proof, &ephemeral_tag, 1, &ephemeral_tag, input_index, blinding_key, blinding_key)); + CHECK(rustsecp256k1zkp_v0_10_0_generator_generate_blinded(CTX, &ephemeral_tag, fixed_tag.data, blinding_key)); + CHECK(!rustsecp256k1zkp_v0_10_0_surjectionproof_generate(CTX, &proof, &ephemeral_tag, 1, &ephemeral_tag, input_index, blinding_key, blinding_key)); /* ...even when the blinding key is zero */ memset(blinding_key, 0, 32); - CHECK(rustsecp256k1zkp_v0_8_0_generator_generate_blinded(ctx, &ephemeral_tag, fixed_tag.data, blinding_key)); - CHECK(!rustsecp256k1zkp_v0_8_0_surjectionproof_generate(ctx, &proof, &ephemeral_tag, 1, &ephemeral_tag, input_index, blinding_key, blinding_key)); + CHECK(rustsecp256k1zkp_v0_10_0_generator_generate_blinded(CTX, &ephemeral_tag, fixed_tag.data, blinding_key)); + CHECK(!rustsecp256k1zkp_v0_10_0_surjectionproof_generate(CTX, &proof, &ephemeral_tag, 1, &ephemeral_tag, input_index, blinding_key, blinding_key)); } -void test_fixed_vectors(void) { +static void test_fixed_vectors(void) { const unsigned char tag0_ser[] = { 0x0a, 0x1c, 0xa3, 0xdd, 0x12, 0x48, 0xdd, 0x4d, 0xd0, 0x04, 0x30, 0x47, 0x48, 0x75, 0xf5, 0xf5, 0xff, @@ -656,60 +574,60 @@ void test_fixed_vectors(void) { unsigned char bad[sizeof(total5_used5) + 32] = { 0 }; - rustsecp256k1zkp_v0_8_0_generator input_tags[5]; - rustsecp256k1zkp_v0_8_0_generator output_tag; - rustsecp256k1zkp_v0_8_0_surjectionproof proof; + rustsecp256k1zkp_v0_10_0_generator input_tags[5]; + rustsecp256k1zkp_v0_10_0_generator output_tag; + rustsecp256k1zkp_v0_10_0_surjectionproof proof; - CHECK(rustsecp256k1zkp_v0_8_0_generator_parse(ctx, &input_tags[0], tag0_ser)); - CHECK(rustsecp256k1zkp_v0_8_0_generator_parse(ctx, &input_tags[1], tag1_ser)); - CHECK(rustsecp256k1zkp_v0_8_0_generator_parse(ctx, &input_tags[2], tag2_ser)); - CHECK(rustsecp256k1zkp_v0_8_0_generator_parse(ctx, &input_tags[3], tag3_ser)); - CHECK(rustsecp256k1zkp_v0_8_0_generator_parse(ctx, &input_tags[4], tag4_ser)); - CHECK(rustsecp256k1zkp_v0_8_0_generator_parse(ctx, &output_tag, output_tag_ser)); + CHECK(rustsecp256k1zkp_v0_10_0_generator_parse(CTX, &input_tags[0], tag0_ser)); + CHECK(rustsecp256k1zkp_v0_10_0_generator_parse(CTX, &input_tags[1], tag1_ser)); + CHECK(rustsecp256k1zkp_v0_10_0_generator_parse(CTX, &input_tags[2], tag2_ser)); + CHECK(rustsecp256k1zkp_v0_10_0_generator_parse(CTX, &input_tags[3], tag3_ser)); + CHECK(rustsecp256k1zkp_v0_10_0_generator_parse(CTX, &input_tags[4], tag4_ser)); + CHECK(rustsecp256k1zkp_v0_10_0_generator_parse(CTX, &output_tag, output_tag_ser)); /* check 1-of-1 */ - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_parse(ctx, &proof, total1_used1, total1_used1_len)); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_verify(ctx, &proof, input_tags, 1, &output_tag)); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, total1_used1, total1_used1_len)); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_verify(CTX, &proof, input_tags, 1, &output_tag)); /* check 1-of-2 */ - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_parse(ctx, &proof, total2_used1, total2_used1_len)); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_verify(ctx, &proof, input_tags, 2, &output_tag)); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, total2_used1, total2_used1_len)); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_verify(CTX, &proof, input_tags, 2, &output_tag)); /* check 2-of-3 */ - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_parse(ctx, &proof, total3_used2, total3_used2_len)); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_verify(ctx, &proof, input_tags, 3, &output_tag)); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, total3_used2, total3_used2_len)); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_verify(CTX, &proof, input_tags, 3, &output_tag)); /* check 3-of-5 */ - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_parse(ctx, &proof, total5_used3, total5_used3_len)); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_verify(ctx, &proof, input_tags, 5, &output_tag)); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, total5_used3, total5_used3_len)); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_verify(CTX, &proof, input_tags, 5, &output_tag)); /* check 5-of-5 */ - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_parse(ctx, &proof, total5_used5, total5_used5_len)); - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_verify(ctx, &proof, input_tags, 5, &output_tag)); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, total5_used5, total5_used5_len)); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_verify(CTX, &proof, input_tags, 5, &output_tag)); /* check invalid length fails */ - CHECK(!rustsecp256k1zkp_v0_8_0_surjectionproof_parse(ctx, &proof, total5_used5, total5_used3_len)); + CHECK(!rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, total5_used5, total5_used3_len)); /* check invalid keys fail */ - CHECK(rustsecp256k1zkp_v0_8_0_surjectionproof_parse(ctx, &proof, total1_used1, total1_used1_len)); - CHECK(!rustsecp256k1zkp_v0_8_0_surjectionproof_verify(ctx, &proof, &input_tags[1], 1, &output_tag)); - CHECK(!rustsecp256k1zkp_v0_8_0_surjectionproof_verify(ctx, &proof, input_tags, 1, &input_tags[0])); + CHECK(rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, total1_used1, total1_used1_len)); + CHECK(!rustsecp256k1zkp_v0_10_0_surjectionproof_verify(CTX, &proof, &input_tags[1], 1, &output_tag)); + CHECK(!rustsecp256k1zkp_v0_10_0_surjectionproof_verify(CTX, &proof, input_tags, 1, &input_tags[0])); /* Try setting 6 bits on the total5-used-5; check that parsing fails */ memcpy(bad, total5_used5, total5_used5_len); bad[2] = 0x3f; /* 0x1f -> 0x3f */ - CHECK(!rustsecp256k1zkp_v0_8_0_surjectionproof_parse(ctx, &proof, bad, total5_used5_len)); + CHECK(!rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, bad, total5_used5_len)); /* Correct for the length */ - CHECK(!rustsecp256k1zkp_v0_8_0_surjectionproof_parse(ctx, &proof, bad, total5_used5_len + 32)); + CHECK(!rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, bad, total5_used5_len + 32)); /* Alternately just turn off one of the "legit" bits */ bad[2] = 0x37; /* 0x1f -> 0x37 */ - CHECK(!rustsecp256k1zkp_v0_8_0_surjectionproof_parse(ctx, &proof, bad, total5_used5_len)); + CHECK(!rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, bad, total5_used5_len)); /* Similarly try setting 4 bits on the total5-used-3, with one bit out of range */ memcpy(bad, total5_used3, total5_used3_len); bad[2] = 0x35; /* 0x15 -> 0x35 */ - CHECK(!rustsecp256k1zkp_v0_8_0_surjectionproof_parse(ctx, &proof, bad, total5_used3_len)); - CHECK(!rustsecp256k1zkp_v0_8_0_surjectionproof_parse(ctx, &proof, bad, total5_used3_len + 32)); + CHECK(!rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, bad, total5_used3_len)); + CHECK(!rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, bad, total5_used3_len + 32)); bad[2] = 0x34; /* 0x15 -> 0x34 */ - CHECK(!rustsecp256k1zkp_v0_8_0_surjectionproof_parse(ctx, &proof, bad, total5_used3_len)); + CHECK(!rustsecp256k1zkp_v0_10_0_surjectionproof_parse(CTX, &proof, bad, total5_used3_len)); } -void run_surjection_tests(void) { +static void run_surjection_tests(void) { test_surjectionproof_api(); test_input_eq_output(); test_fixed_vectors(); diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/whitelist/Makefile.am.include b/secp256k1-zkp-sys/depend/secp256k1/src/modules/whitelist/Makefile.am.include index 328c1e3d..88c9ac06 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/whitelist/Makefile.am.include +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/whitelist/Makefile.am.include @@ -1,11 +1,10 @@ -include_HEADERS += include/rustsecp256k1zkp_v0_8_0_whitelist.h +include_HEADERS += include/rustsecp256k1zkp_v0_10_0_whitelist.h noinst_HEADERS += src/modules/whitelist/whitelist_impl.h noinst_HEADERS += src/modules/whitelist/main_impl.h noinst_HEADERS += src/modules/whitelist/tests_impl.h if USE_BENCHMARK noinst_PROGRAMS += bench_whitelist bench_whitelist_SOURCES = src/bench_whitelist.c -bench_whitelist_CPPFLAGS = -DSECP256K1_BUILD $(SECP_INCLUDES) -bench_whitelist_LDADD = libsecp256k1.la $(SECP_LIBS) -bench_generator_LDFLAGS = -static +bench_whitelist_LDADD = libsecp256k1.la +bench_generator_CPPFLAGS = $(SECP_CONFIG_DEFINES) endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/whitelist/main_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/whitelist/main_impl.h index eb4f774c..7f597400 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/whitelist/main_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/whitelist/main_impl.h @@ -4,24 +4,24 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef SECP256K1_MODULE_WHITELIST_MAIN -#define SECP256K1_MODULE_WHITELIST_MAIN +#ifndef SECP256K1_MODULE_WHITELIST_MAIN_H +#define SECP256K1_MODULE_WHITELIST_MAIN_H #include "../../../include/secp256k1_whitelist.h" #include "whitelist_impl.h" #define MAX_KEYS SECP256K1_WHITELIST_MAX_N_KEYS /* shorter alias */ -int rustsecp256k1zkp_v0_8_0_whitelist_sign(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_whitelist_signature *sig, const rustsecp256k1zkp_v0_8_0_pubkey *online_pubkeys, const rustsecp256k1zkp_v0_8_0_pubkey *offline_pubkeys, const size_t n_keys, const rustsecp256k1zkp_v0_8_0_pubkey *sub_pubkey, const unsigned char *online_seckey, const unsigned char *summed_seckey, const size_t index) { - rustsecp256k1zkp_v0_8_0_gej pubs[MAX_KEYS]; - rustsecp256k1zkp_v0_8_0_scalar s[MAX_KEYS]; - rustsecp256k1zkp_v0_8_0_scalar sec, non; +int rustsecp256k1zkp_v0_10_0_whitelist_sign(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_whitelist_signature *sig, const rustsecp256k1zkp_v0_10_0_pubkey *online_pubkeys, const rustsecp256k1zkp_v0_10_0_pubkey *offline_pubkeys, const size_t n_keys, const rustsecp256k1zkp_v0_10_0_pubkey *sub_pubkey, const unsigned char *online_seckey, const unsigned char *summed_seckey, const size_t index) { + rustsecp256k1zkp_v0_10_0_gej pubs[MAX_KEYS]; + rustsecp256k1zkp_v0_10_0_scalar s[MAX_KEYS]; + rustsecp256k1zkp_v0_10_0_scalar sec, non; unsigned char msg32[32]; int ret; /* Sanity checks */ VERIFY_CHECK(ctx != NULL); - ARG_CHECK(rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); ARG_CHECK(sig != NULL); ARG_CHECK(online_pubkeys != NULL); ARG_CHECK(offline_pubkeys != NULL); @@ -32,11 +32,11 @@ int rustsecp256k1zkp_v0_8_0_whitelist_sign(const rustsecp256k1zkp_v0_8_0_context ARG_CHECK(index < n_keys); /* Compute pubkeys: online_pubkey + tweaked(offline_pubkey + address), and message */ - ret = rustsecp256k1zkp_v0_8_0_whitelist_compute_keys_and_message(ctx, msg32, pubs, online_pubkeys, offline_pubkeys, n_keys, sub_pubkey); + ret = rustsecp256k1zkp_v0_10_0_whitelist_compute_keys_and_message(ctx, msg32, pubs, online_pubkeys, offline_pubkeys, n_keys, sub_pubkey); /* Compute signing key: online_seckey + tweaked(summed_seckey) */ if (ret) { - ret = rustsecp256k1zkp_v0_8_0_whitelist_compute_tweaked_privkey(ctx, &sec, online_seckey, summed_seckey); + ret = rustsecp256k1zkp_v0_10_0_whitelist_compute_tweaked_privkey(ctx, &sec, online_seckey, summed_seckey); } /* Compute nonce and random s-values */ if (ret) { @@ -44,18 +44,18 @@ int rustsecp256k1zkp_v0_8_0_whitelist_sign(const rustsecp256k1zkp_v0_8_0_context unsigned int count = 0; int overflow = 0; - rustsecp256k1zkp_v0_8_0_scalar_get_b32(seckey32, &sec); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(seckey32, &sec); while (1) { size_t i; unsigned char nonce32[32]; int done; - ret = rustsecp256k1zkp_v0_8_0_nonce_function_default(nonce32, msg32, seckey32, NULL, NULL, count); + ret = rustsecp256k1zkp_v0_10_0_nonce_function_default(nonce32, msg32, seckey32, NULL, NULL, count); if (!ret) { break; } - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&non, nonce32, &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&non, nonce32, &overflow); memset(nonce32, 0, 32); - if (overflow || rustsecp256k1zkp_v0_8_0_scalar_is_zero(&non)) { + if (overflow || rustsecp256k1zkp_v0_10_0_scalar_is_zero(&non)) { count++; continue; } @@ -63,14 +63,14 @@ int rustsecp256k1zkp_v0_8_0_whitelist_sign(const rustsecp256k1zkp_v0_8_0_context for (i = 0; i < n_keys; i++) { msg32[0] ^= i + 1; msg32[1] ^= (i + 1) / 0x100; - ret = rustsecp256k1zkp_v0_8_0_nonce_function_default(&sig->data[32 * (i + 1)], msg32, seckey32, NULL, NULL, count); + ret = rustsecp256k1zkp_v0_10_0_nonce_function_default(&sig->data[32 * (i + 1)], msg32, seckey32, NULL, NULL, count); if (!ret) { break; } - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&s[i], &sig->data[32 * (i + 1)], &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&s[i], &sig->data[32 * (i + 1)], &overflow); msg32[0] ^= i + 1; msg32[1] ^= (i + 1) / 0x100; - if (overflow || rustsecp256k1zkp_v0_8_0_scalar_is_zero(&s[i])) { + if (overflow || rustsecp256k1zkp_v0_10_0_scalar_is_zero(&s[i])) { count++; done = 0; break; @@ -85,19 +85,19 @@ int rustsecp256k1zkp_v0_8_0_whitelist_sign(const rustsecp256k1zkp_v0_8_0_context /* Actually sign */ if (ret) { sig->n_keys = n_keys; - ret = rustsecp256k1zkp_v0_8_0_borromean_sign(&ctx->ecmult_gen_ctx, &sig->data[0], s, pubs, &non, &sec, &n_keys, &index, 1, msg32, 32); + ret = rustsecp256k1zkp_v0_10_0_borromean_sign(&ctx->ecmult_gen_ctx, &sig->data[0], s, pubs, &non, &sec, &n_keys, &index, 1, msg32, 32); /* Signing will change s[index], so update in the sig structure */ - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&sig->data[32 * (index + 1)], &s[index]); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&sig->data[32 * (index + 1)], &s[index]); } - rustsecp256k1zkp_v0_8_0_scalar_clear(&non); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sec); + rustsecp256k1zkp_v0_10_0_scalar_clear(&non); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sec); return ret; } -int rustsecp256k1zkp_v0_8_0_whitelist_verify(const rustsecp256k1zkp_v0_8_0_context* ctx, const rustsecp256k1zkp_v0_8_0_whitelist_signature *sig, const rustsecp256k1zkp_v0_8_0_pubkey *online_pubkeys, const rustsecp256k1zkp_v0_8_0_pubkey *offline_pubkeys, const size_t n_keys, const rustsecp256k1zkp_v0_8_0_pubkey *sub_pubkey) { - rustsecp256k1zkp_v0_8_0_scalar s[MAX_KEYS]; - rustsecp256k1zkp_v0_8_0_gej pubs[MAX_KEYS]; +int rustsecp256k1zkp_v0_10_0_whitelist_verify(const rustsecp256k1zkp_v0_10_0_context* ctx, const rustsecp256k1zkp_v0_10_0_whitelist_signature *sig, const rustsecp256k1zkp_v0_10_0_pubkey *online_pubkeys, const rustsecp256k1zkp_v0_10_0_pubkey *offline_pubkeys, const size_t n_keys, const rustsecp256k1zkp_v0_10_0_pubkey *sub_pubkey) { + rustsecp256k1zkp_v0_10_0_scalar s[MAX_KEYS]; + rustsecp256k1zkp_v0_10_0_gej pubs[MAX_KEYS]; unsigned char msg32[32]; size_t i; @@ -112,25 +112,25 @@ int rustsecp256k1zkp_v0_8_0_whitelist_verify(const rustsecp256k1zkp_v0_8_0_conte } for (i = 0; i < sig->n_keys; i++) { int overflow = 0; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&s[i], &sig->data[32 * (i + 1)], &overflow); - if (overflow || rustsecp256k1zkp_v0_8_0_scalar_is_zero(&s[i])) { + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&s[i], &sig->data[32 * (i + 1)], &overflow); + if (overflow || rustsecp256k1zkp_v0_10_0_scalar_is_zero(&s[i])) { return 0; } } /* Compute pubkeys: online_pubkey + tweaked(offline_pubkey + address), and message */ - if (!rustsecp256k1zkp_v0_8_0_whitelist_compute_keys_and_message(ctx, msg32, pubs, online_pubkeys, offline_pubkeys, sig->n_keys, sub_pubkey)) { + if (!rustsecp256k1zkp_v0_10_0_whitelist_compute_keys_and_message(ctx, msg32, pubs, online_pubkeys, offline_pubkeys, sig->n_keys, sub_pubkey)) { return 0; } /* Do verification */ - return rustsecp256k1zkp_v0_8_0_borromean_verify(NULL, &sig->data[0], s, pubs, &sig->n_keys, 1, msg32, 32); + return rustsecp256k1zkp_v0_10_0_borromean_verify(NULL, &sig->data[0], s, pubs, &sig->n_keys, 1, msg32, 32); } -size_t rustsecp256k1zkp_v0_8_0_whitelist_signature_n_keys(const rustsecp256k1zkp_v0_8_0_whitelist_signature *sig) { +size_t rustsecp256k1zkp_v0_10_0_whitelist_signature_n_keys(const rustsecp256k1zkp_v0_10_0_whitelist_signature *sig) { return sig->n_keys; } -int rustsecp256k1zkp_v0_8_0_whitelist_signature_parse(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_whitelist_signature *sig, const unsigned char *input, size_t input_len) { +int rustsecp256k1zkp_v0_10_0_whitelist_signature_parse(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_whitelist_signature *sig, const unsigned char *input, size_t input_len) { VERIFY_CHECK(ctx != NULL); ARG_CHECK(sig != NULL); ARG_CHECK(input != NULL); @@ -148,7 +148,7 @@ int rustsecp256k1zkp_v0_8_0_whitelist_signature_parse(const rustsecp256k1zkp_v0_ return 1; } -int rustsecp256k1zkp_v0_8_0_whitelist_signature_serialize(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *output, size_t *output_len, const rustsecp256k1zkp_v0_8_0_whitelist_signature *sig) { +int rustsecp256k1zkp_v0_10_0_whitelist_signature_serialize(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *output, size_t *output_len, const rustsecp256k1zkp_v0_10_0_whitelist_signature *sig) { VERIFY_CHECK(ctx != NULL); ARG_CHECK(output != NULL); ARG_CHECK(output_len != NULL); diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/whitelist/tests_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/whitelist/tests_impl.h index 4004ab44..2ccd992a 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/whitelist/tests_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/whitelist/tests_impl.h @@ -4,82 +4,82 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef SECP256K1_MODULE_WHITELIST_TESTS -#define SECP256K1_MODULE_WHITELIST_TESTS +#ifndef SECP256K1_MODULE_WHITELIST_TESTS_H +#define SECP256K1_MODULE_WHITELIST_TESTS_H #include "../../../include/secp256k1_whitelist.h" -void test_whitelist_end_to_end_internal(const unsigned char *summed_seckey, const unsigned char *online_seckey, const rustsecp256k1zkp_v0_8_0_pubkey *online_pubkeys, const rustsecp256k1zkp_v0_8_0_pubkey *offline_pubkeys, const rustsecp256k1zkp_v0_8_0_pubkey *sub_pubkey, const size_t signer_i, const size_t n_keys) { +static void test_whitelist_end_to_end_internal(const unsigned char *summed_seckey, const unsigned char *online_seckey, const rustsecp256k1zkp_v0_10_0_pubkey *online_pubkeys, const rustsecp256k1zkp_v0_10_0_pubkey *offline_pubkeys, const rustsecp256k1zkp_v0_10_0_pubkey *sub_pubkey, const size_t signer_i, const size_t n_keys) { unsigned char serialized[32 + 4 + 32 * SECP256K1_WHITELIST_MAX_N_KEYS] = {0}; size_t slen = sizeof(serialized); - rustsecp256k1zkp_v0_8_0_whitelist_signature sig; - rustsecp256k1zkp_v0_8_0_whitelist_signature sig1; + rustsecp256k1zkp_v0_10_0_whitelist_signature sig; + rustsecp256k1zkp_v0_10_0_whitelist_signature sig1; - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_sign(ctx, &sig, online_pubkeys, offline_pubkeys, n_keys, sub_pubkey, online_seckey, summed_seckey, signer_i)); - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_verify(ctx, &sig, online_pubkeys, offline_pubkeys, n_keys, sub_pubkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_sign(CTX, &sig, online_pubkeys, offline_pubkeys, n_keys, sub_pubkey, online_seckey, summed_seckey, signer_i)); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_verify(CTX, &sig, online_pubkeys, offline_pubkeys, n_keys, sub_pubkey) == 1); /* Check that exchanging keys causes a failure */ - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_verify(ctx, &sig, offline_pubkeys, online_pubkeys, n_keys, sub_pubkey) != 1); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_verify(CTX, &sig, offline_pubkeys, online_pubkeys, n_keys, sub_pubkey) != 1); /* Serialization round trip */ - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_signature_serialize(ctx, serialized, &slen, &sig) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_signature_serialize(CTX, serialized, &slen, &sig) == 1); CHECK(slen == 33 + 32 * n_keys); - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_signature_parse(ctx, &sig1, serialized, slen) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_signature_parse(CTX, &sig1, serialized, slen) == 1); /* (Check various bad-length conditions) */ - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_signature_parse(ctx, &sig1, serialized, slen + 32) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_signature_parse(ctx, &sig1, serialized, slen + 1) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_signature_parse(ctx, &sig1, serialized, slen - 1) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_signature_parse(ctx, &sig1, serialized, 0) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_verify(ctx, &sig1, online_pubkeys, offline_pubkeys, n_keys, sub_pubkey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_verify(ctx, &sig1, offline_pubkeys, online_pubkeys, n_keys, sub_pubkey) != 1); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_signature_parse(CTX, &sig1, serialized, slen + 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_signature_parse(CTX, &sig1, serialized, slen + 1) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_signature_parse(CTX, &sig1, serialized, slen - 1) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_signature_parse(CTX, &sig1, serialized, 0) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_verify(CTX, &sig1, online_pubkeys, offline_pubkeys, n_keys, sub_pubkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_verify(CTX, &sig1, offline_pubkeys, online_pubkeys, n_keys, sub_pubkey) != 1); /* Test n_keys */ - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_signature_n_keys(&sig) == n_keys); - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_signature_n_keys(&sig1) == n_keys); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_signature_n_keys(&sig) == n_keys); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_signature_n_keys(&sig1) == n_keys); /* Test bad number of keys in signature */ sig.n_keys = n_keys + 1; - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_verify(ctx, &sig, offline_pubkeys, online_pubkeys, n_keys, sub_pubkey) != 1); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_verify(CTX, &sig, offline_pubkeys, online_pubkeys, n_keys, sub_pubkey) != 1); sig.n_keys = n_keys; } -void test_whitelist_end_to_end(const size_t n_keys, int test_all_keys) { +static void test_whitelist_end_to_end(const size_t n_keys, int test_all_keys) { unsigned char **online_seckey = (unsigned char **) malloc(n_keys * sizeof(*online_seckey)); unsigned char **summed_seckey = (unsigned char **) malloc(n_keys * sizeof(*summed_seckey)); - rustsecp256k1zkp_v0_8_0_pubkey *online_pubkeys = (rustsecp256k1zkp_v0_8_0_pubkey *) malloc(n_keys * sizeof(*online_pubkeys)); - rustsecp256k1zkp_v0_8_0_pubkey *offline_pubkeys = (rustsecp256k1zkp_v0_8_0_pubkey *) malloc(n_keys * sizeof(*offline_pubkeys)); + rustsecp256k1zkp_v0_10_0_pubkey *online_pubkeys = (rustsecp256k1zkp_v0_10_0_pubkey *) malloc(n_keys * sizeof(*online_pubkeys)); + rustsecp256k1zkp_v0_10_0_pubkey *offline_pubkeys = (rustsecp256k1zkp_v0_10_0_pubkey *) malloc(n_keys * sizeof(*offline_pubkeys)); - rustsecp256k1zkp_v0_8_0_scalar ssub; + rustsecp256k1zkp_v0_10_0_scalar ssub; unsigned char csub[32]; - rustsecp256k1zkp_v0_8_0_pubkey sub_pubkey; + rustsecp256k1zkp_v0_10_0_pubkey sub_pubkey; /* Generate random keys */ size_t i; /* Start with subkey */ random_scalar_order_test(&ssub); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(csub, &ssub); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, csub) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &sub_pubkey, csub) == 1); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(csub, &ssub); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_verify(CTX, csub) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &sub_pubkey, csub) == 1); /* Then offline and online whitelist keys */ for (i = 0; i < n_keys; i++) { - rustsecp256k1zkp_v0_8_0_scalar son, soff; + rustsecp256k1zkp_v0_10_0_scalar son, soff; online_seckey[i] = (unsigned char *) malloc(32); summed_seckey[i] = (unsigned char *) malloc(32); /* Create two keys */ random_scalar_order_test(&son); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(online_seckey[i], &son); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, online_seckey[i]) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &online_pubkeys[i], online_seckey[i]) == 1); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(online_seckey[i], &son); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_verify(CTX, online_seckey[i]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &online_pubkeys[i], online_seckey[i]) == 1); random_scalar_order_test(&soff); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(summed_seckey[i], &soff); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, summed_seckey[i]) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &offline_pubkeys[i], summed_seckey[i]) == 1); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(summed_seckey[i], &soff); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_verify(CTX, summed_seckey[i]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &offline_pubkeys[i], summed_seckey[i]) == 1); /* Make summed_seckey correspond to the sum of offline_pubkey and sub_pubkey */ - rustsecp256k1zkp_v0_8_0_scalar_add(&soff, &soff, &ssub); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(summed_seckey[i], &soff); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, summed_seckey[i]) == 1); + rustsecp256k1zkp_v0_10_0_scalar_add(&soff, &soff, &ssub); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(summed_seckey[i], &soff); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_verify(CTX, summed_seckey[i]) == 1); } /* Sign/verify with each one */ @@ -88,7 +88,7 @@ void test_whitelist_end_to_end(const size_t n_keys, int test_all_keys) { test_whitelist_end_to_end_internal(summed_seckey[i], online_seckey[i], online_pubkeys, offline_pubkeys, &sub_pubkey, i, n_keys); } } else { - uint32_t rand_idx = rustsecp256k1zkp_v0_8_0_testrand_int(n_keys-1); + uint32_t rand_idx = rustsecp256k1zkp_v0_10_0_testrand_int(n_keys-1); test_whitelist_end_to_end_internal(summed_seckey[0], online_seckey[0], online_pubkeys, offline_pubkeys, &sub_pubkey, 0, n_keys); test_whitelist_end_to_end_internal(summed_seckey[rand_idx], online_seckey[rand_idx], online_pubkeys, offline_pubkeys, &sub_pubkey, rand_idx, n_keys); test_whitelist_end_to_end_internal(summed_seckey[n_keys-1], online_seckey[n_keys-1], online_pubkeys, offline_pubkeys, &sub_pubkey, n_keys-1, n_keys); @@ -104,8 +104,8 @@ void test_whitelist_end_to_end(const size_t n_keys, int test_all_keys) { free(offline_pubkeys); } -void test_whitelist_bad_parse(void) { - rustsecp256k1zkp_v0_8_0_whitelist_signature sig; +static void test_whitelist_bad_parse(void) { + rustsecp256k1zkp_v0_10_0_whitelist_signature sig; const unsigned char serialized0[] = { 1+32*(0+1) }; const unsigned char serialized1[] = { @@ -124,14 +124,14 @@ void test_whitelist_bad_parse(void) { }; /* Empty input */ - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_signature_parse(ctx, &sig, serialized0, 0) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_signature_parse(CTX, &sig, serialized0, 0) == 0); /* Misses one byte of e0 */ - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_signature_parse(ctx, &sig, serialized1, sizeof(serialized1)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_signature_parse(CTX, &sig, serialized1, sizeof(serialized1)) == 0); /* Enough bytes for e0, but there is no s value */ - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_signature_parse(ctx, &sig, serialized2, sizeof(serialized2)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_signature_parse(CTX, &sig, serialized2, sizeof(serialized2)) == 0); } -void test_whitelist_bad_serialize(void) { +static void test_whitelist_bad_serialize(void) { unsigned char serialized[] = { 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, @@ -140,19 +140,19 @@ void test_whitelist_bad_serialize(void) { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; size_t serialized_len; - rustsecp256k1zkp_v0_8_0_whitelist_signature sig; + rustsecp256k1zkp_v0_10_0_whitelist_signature sig; - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_signature_parse(ctx, &sig, serialized, sizeof(serialized)) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_signature_parse(CTX, &sig, serialized, sizeof(serialized)) == 1); serialized_len = sizeof(serialized) - 1; /* Output buffer is one byte too short */ - CHECK(rustsecp256k1zkp_v0_8_0_whitelist_signature_serialize(ctx, serialized, &serialized_len, &sig) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_whitelist_signature_serialize(CTX, serialized, &serialized_len, &sig) == 0); } -void run_whitelist_tests(void) { +static void run_whitelist_tests(void) { int i; test_whitelist_bad_parse(); test_whitelist_bad_serialize(); - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { test_whitelist_end_to_end(1, 1); test_whitelist_end_to_end(10, 1); test_whitelist_end_to_end(50, 1); diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/modules/whitelist/whitelist_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/modules/whitelist/whitelist_impl.h index eb81de75..d2bab247 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/modules/whitelist/whitelist_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/modules/whitelist/whitelist_impl.h @@ -4,78 +4,78 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#ifndef _SECP256K1_WHITELIST_IMPL_H_ -#define _SECP256K1_WHITELIST_IMPL_H_ +#ifndef SECP256K1_WHITELIST_IMPL_H +#define SECP256K1_WHITELIST_IMPL_H -static int rustsecp256k1zkp_v0_8_0_whitelist_hash_pubkey(rustsecp256k1zkp_v0_8_0_scalar* output, rustsecp256k1zkp_v0_8_0_gej* pubkey) { +static int rustsecp256k1zkp_v0_10_0_whitelist_hash_pubkey(rustsecp256k1zkp_v0_10_0_scalar* output, rustsecp256k1zkp_v0_10_0_gej* pubkey) { unsigned char h[32]; unsigned char c[33]; - rustsecp256k1zkp_v0_8_0_sha256 sha; + rustsecp256k1zkp_v0_10_0_sha256 sha; int overflow = 0; size_t size = 33; - rustsecp256k1zkp_v0_8_0_ge ge; + rustsecp256k1zkp_v0_10_0_ge ge; - rustsecp256k1zkp_v0_8_0_ge_set_gej(&ge, pubkey); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&ge, pubkey); - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha); - if (!rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&ge, c, &size, SECP256K1_EC_COMPRESSED)) { + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha); + if (!rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&ge, c, &size, SECP256K1_EC_COMPRESSED)) { return 0; } - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, c, size); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, h); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, c, size); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, h); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(output, h, &overflow); - if (overflow || rustsecp256k1zkp_v0_8_0_scalar_is_zero(output)) { + rustsecp256k1zkp_v0_10_0_scalar_set_b32(output, h, &overflow); + if (overflow || rustsecp256k1zkp_v0_10_0_scalar_is_zero(output)) { /* This return path is mathematically impossible to hit */ - rustsecp256k1zkp_v0_8_0_scalar_clear(output); + rustsecp256k1zkp_v0_10_0_scalar_clear(output); return 0; } return 1; } -static int rustsecp256k1zkp_v0_8_0_whitelist_tweak_pubkey(rustsecp256k1zkp_v0_8_0_gej* pub_tweaked) { - rustsecp256k1zkp_v0_8_0_scalar tweak; - rustsecp256k1zkp_v0_8_0_scalar zero; +static int rustsecp256k1zkp_v0_10_0_whitelist_tweak_pubkey(rustsecp256k1zkp_v0_10_0_gej* pub_tweaked) { + rustsecp256k1zkp_v0_10_0_scalar tweak; + rustsecp256k1zkp_v0_10_0_scalar zero; int ret; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&zero, 0); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&zero, 0); - ret = rustsecp256k1zkp_v0_8_0_whitelist_hash_pubkey(&tweak, pub_tweaked); + ret = rustsecp256k1zkp_v0_10_0_whitelist_hash_pubkey(&tweak, pub_tweaked); if (ret) { - rustsecp256k1zkp_v0_8_0_ecmult(pub_tweaked, pub_tweaked, &tweak, &zero); + rustsecp256k1zkp_v0_10_0_ecmult(pub_tweaked, pub_tweaked, &tweak, &zero); } return ret; } -static int rustsecp256k1zkp_v0_8_0_whitelist_compute_tweaked_privkey(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_scalar* skey, const unsigned char *online_key, const unsigned char *summed_key) { - rustsecp256k1zkp_v0_8_0_scalar tweak; +static int rustsecp256k1zkp_v0_10_0_whitelist_compute_tweaked_privkey(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_scalar* skey, const unsigned char *online_key, const unsigned char *summed_key) { + rustsecp256k1zkp_v0_10_0_scalar tweak; int ret = 1; int overflow = 0; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(skey, summed_key, &overflow); - if (overflow || rustsecp256k1zkp_v0_8_0_scalar_is_zero(skey)) { + rustsecp256k1zkp_v0_10_0_scalar_set_b32(skey, summed_key, &overflow); + if (overflow || rustsecp256k1zkp_v0_10_0_scalar_is_zero(skey)) { ret = 0; } if (ret) { - rustsecp256k1zkp_v0_8_0_gej pkeyj; - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &pkeyj, skey); - ret = rustsecp256k1zkp_v0_8_0_whitelist_hash_pubkey(&tweak, &pkeyj); + rustsecp256k1zkp_v0_10_0_gej pkeyj; + rustsecp256k1zkp_v0_10_0_ecmult_gen(&ctx->ecmult_gen_ctx, &pkeyj, skey); + ret = rustsecp256k1zkp_v0_10_0_whitelist_hash_pubkey(&tweak, &pkeyj); } if (ret) { - rustsecp256k1zkp_v0_8_0_scalar sonline; - rustsecp256k1zkp_v0_8_0_scalar_mul(skey, skey, &tweak); + rustsecp256k1zkp_v0_10_0_scalar sonline; + rustsecp256k1zkp_v0_10_0_scalar_mul(skey, skey, &tweak); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&sonline, online_key, &overflow); - if (overflow || rustsecp256k1zkp_v0_8_0_scalar_is_zero(&sonline)) { + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&sonline, online_key, &overflow); + if (overflow || rustsecp256k1zkp_v0_10_0_scalar_is_zero(&sonline)) { ret = 0; } - rustsecp256k1zkp_v0_8_0_scalar_add(skey, skey, &sonline); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sonline); - rustsecp256k1zkp_v0_8_0_scalar_clear(&tweak); + rustsecp256k1zkp_v0_10_0_scalar_add(skey, skey, &sonline); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sonline); + rustsecp256k1zkp_v0_10_0_scalar_clear(&tweak); } if (!ret) { - rustsecp256k1zkp_v0_8_0_scalar_clear(skey); + rustsecp256k1zkp_v0_10_0_scalar_clear(skey); } return ret; } @@ -83,45 +83,45 @@ static int rustsecp256k1zkp_v0_8_0_whitelist_compute_tweaked_privkey(const rusts /* Takes a list of pubkeys and combines them to form the public keys needed * for the ring signature; also produce a commitment to every one that will * be our "message". */ -static int rustsecp256k1zkp_v0_8_0_whitelist_compute_keys_and_message(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *msg32, rustsecp256k1zkp_v0_8_0_gej *keys, const rustsecp256k1zkp_v0_8_0_pubkey *online_pubkeys, const rustsecp256k1zkp_v0_8_0_pubkey *offline_pubkeys, const int n_keys, const rustsecp256k1zkp_v0_8_0_pubkey *sub_pubkey) { +static int rustsecp256k1zkp_v0_10_0_whitelist_compute_keys_and_message(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *msg32, rustsecp256k1zkp_v0_10_0_gej *keys, const rustsecp256k1zkp_v0_10_0_pubkey *online_pubkeys, const rustsecp256k1zkp_v0_10_0_pubkey *offline_pubkeys, const int n_keys, const rustsecp256k1zkp_v0_10_0_pubkey *sub_pubkey) { unsigned char c[33]; size_t size = 33; - rustsecp256k1zkp_v0_8_0_sha256 sha; + rustsecp256k1zkp_v0_10_0_sha256 sha; int i; - rustsecp256k1zkp_v0_8_0_ge subkey_ge; + rustsecp256k1zkp_v0_10_0_ge subkey_ge; - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha); - rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &subkey_ge, sub_pubkey); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha); + rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, &subkey_ge, sub_pubkey); /* commit to sub-key */ - if (!rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&subkey_ge, c, &size, SECP256K1_EC_COMPRESSED)) { + if (!rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&subkey_ge, c, &size, SECP256K1_EC_COMPRESSED)) { return 0; } - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, c, size); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, c, size); for (i = 0; i < n_keys; i++) { - rustsecp256k1zkp_v0_8_0_ge offline_ge; - rustsecp256k1zkp_v0_8_0_ge online_ge; - rustsecp256k1zkp_v0_8_0_gej tweaked_gej; + rustsecp256k1zkp_v0_10_0_ge offline_ge; + rustsecp256k1zkp_v0_10_0_ge online_ge; + rustsecp256k1zkp_v0_10_0_gej tweaked_gej; /* commit to fixed keys */ - rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &offline_ge, &offline_pubkeys[i]); - if (!rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&offline_ge, c, &size, SECP256K1_EC_COMPRESSED)) { + rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, &offline_ge, &offline_pubkeys[i]); + if (!rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&offline_ge, c, &size, SECP256K1_EC_COMPRESSED)) { return 0; } - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, c, size); - rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &online_ge, &online_pubkeys[i]); - if (!rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&online_ge, c, &size, SECP256K1_EC_COMPRESSED)) { + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, c, size); + rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, &online_ge, &online_pubkeys[i]); + if (!rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&online_ge, c, &size, SECP256K1_EC_COMPRESSED)) { return 0; } - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, c, size); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, c, size); /* compute tweaked keys */ - rustsecp256k1zkp_v0_8_0_gej_set_ge(&tweaked_gej, &offline_ge); - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&tweaked_gej, &tweaked_gej, &subkey_ge, NULL); - rustsecp256k1zkp_v0_8_0_whitelist_tweak_pubkey(&tweaked_gej); - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&keys[i], &tweaked_gej, &online_ge, NULL); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&tweaked_gej, &offline_ge); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&tweaked_gej, &tweaked_gej, &subkey_ge, NULL); + rustsecp256k1zkp_v0_10_0_whitelist_tweak_pubkey(&tweaked_gej); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&keys[i], &tweaked_gej, &online_ge, NULL); } - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, msg32); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, msg32); return 1; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/precompute_ecmult.c b/secp256k1-zkp-sys/depend/secp256k1/src/precompute_ecmult.c index 1041d5ee..a378d14e 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/precompute_ecmult.c +++ b/secp256k1-zkp-sys/depend/secp256k1/src/precompute_ecmult.c @@ -7,25 +7,22 @@ #include #include -/* Autotools creates libsecp256k1-config.h, of which ECMULT_WINDOW_SIZE is needed. - ifndef guard so downstream users can define their own if they do not use autotools. */ -#if !defined(ECMULT_WINDOW_SIZE) -#include "libsecp256k1-config.h" -#endif - #include "../include/secp256k1.h" + #include "assumptions.h" #include "util.h" + #include "field_impl.h" #include "group_impl.h" +#include "int128_impl.h" #include "ecmult.h" #include "ecmult_compute_table_impl.h" -static void print_table(FILE *fp, const char *name, int window_g, const rustsecp256k1zkp_v0_8_0_ge_storage* table) { +static void print_table(FILE *fp, const char *name, int window_g, const rustsecp256k1zkp_v0_10_0_ge_storage* table) { int j; int i; - fprintf(fp, "const rustsecp256k1zkp_v0_8_0_ge_storage %s[ECMULT_TABLE_SIZE(WINDOW_G)] = {\n", name); + fprintf(fp, "const rustsecp256k1zkp_v0_10_0_ge_storage %s[ECMULT_TABLE_SIZE(WINDOW_G)] = {\n", name); fprintf(fp, " S(%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32 ",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32")\n", SECP256K1_GE_STORAGE_CONST_GET(table[0])); @@ -44,13 +41,13 @@ static void print_table(FILE *fp, const char *name, int window_g, const rustsecp } static void print_two_tables(FILE *fp, int window_g) { - rustsecp256k1zkp_v0_8_0_ge_storage* table = malloc(ECMULT_TABLE_SIZE(window_g) * sizeof(rustsecp256k1zkp_v0_8_0_ge_storage)); - rustsecp256k1zkp_v0_8_0_ge_storage* table_128 = malloc(ECMULT_TABLE_SIZE(window_g) * sizeof(rustsecp256k1zkp_v0_8_0_ge_storage)); + rustsecp256k1zkp_v0_10_0_ge_storage* table = malloc(ECMULT_TABLE_SIZE(window_g) * sizeof(rustsecp256k1zkp_v0_10_0_ge_storage)); + rustsecp256k1zkp_v0_10_0_ge_storage* table_128 = malloc(ECMULT_TABLE_SIZE(window_g) * sizeof(rustsecp256k1zkp_v0_10_0_ge_storage)); - rustsecp256k1zkp_v0_8_0_ecmult_compute_two_tables(table, table_128, window_g, &rustsecp256k1zkp_v0_8_0_ge_const_g); + rustsecp256k1zkp_v0_10_0_ecmult_compute_two_tables(table, table_128, window_g, &rustsecp256k1zkp_v0_10_0_ge_const_g); - print_table(fp, "rustsecp256k1zkp_v0_8_0_pre_g", window_g, table); - print_table(fp, "rustsecp256k1zkp_v0_8_0_pre_g_128", window_g, table_128); + print_table(fp, "rustsecp256k1zkp_v0_10_0_pre_g", window_g, table); + print_table(fp, "rustsecp256k1zkp_v0_10_0_pre_g_128", window_g, table_128); free(table); free(table_128); @@ -59,22 +56,19 @@ static void print_two_tables(FILE *fp, int window_g) { int main(void) { /* Always compute all tables for window sizes up to 15. */ int window_g = (ECMULT_WINDOW_SIZE < 15) ? 15 : ECMULT_WINDOW_SIZE; + const char outfile[] = "src/precomputed_ecmult.c"; FILE* fp; - fp = fopen("src/precomputed_ecmult.c","w"); + fp = fopen(outfile, "w"); if (fp == NULL) { - fprintf(stderr, "Could not open src/precomputed_ecmult.h for writing!\n"); + fprintf(stderr, "Could not open %s for writing!\n", outfile); return -1; } fprintf(fp, "/* This file was automatically generated by precompute_ecmult. */\n"); - fprintf(fp, "/* This file contains an array rustsecp256k1zkp_v0_8_0_pre_g with odd multiples of the base point G and\n"); - fprintf(fp, " * an array rustsecp256k1zkp_v0_8_0_pre_g_128 with odd multiples of 2^128*G for accelerating the computation of a*P + b*G.\n"); + fprintf(fp, "/* This file contains an array rustsecp256k1zkp_v0_10_0_pre_g with odd multiples of the base point G and\n"); + fprintf(fp, " * an array rustsecp256k1zkp_v0_10_0_pre_g_128 with odd multiples of 2^128*G for accelerating the computation of a*P + b*G.\n"); fprintf(fp, " */\n"); - fprintf(fp, "#if defined HAVE_CONFIG_H\n"); - fprintf(fp, "# include \"libsecp256k1-config.h\"\n"); - fprintf(fp, "#endif\n"); - fprintf(fp, "#include \"../include/secp256k1.h\"\n"); fprintf(fp, "#include \"group.h\"\n"); fprintf(fp, "#include \"ecmult.h\"\n"); fprintf(fp, "#include \"precomputed_ecmult.h\"\n"); diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/precompute_ecmult_gen.c b/secp256k1-zkp-sys/depend/secp256k1/src/precompute_ecmult_gen.c index 015feb3e..b45d53ab 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/precompute_ecmult_gen.c +++ b/secp256k1-zkp-sys/depend/secp256k1/src/precompute_ecmult_gen.c @@ -8,9 +8,12 @@ #include #include "../include/secp256k1.h" + #include "assumptions.h" #include "util.h" + #include "group.h" +#include "int128_impl.h" #include "ecmult_gen.h" #include "ecmult_gen_compute_table_impl.h" @@ -30,10 +33,6 @@ int main(int argc, char **argv) { fprintf(fp, "/* This file was automatically generated by precompute_ecmult_gen. */\n"); fprintf(fp, "/* See ecmult_gen_impl.h for details about the contents of this file. */\n"); - fprintf(fp, "#if defined HAVE_CONFIG_H\n"); - fprintf(fp, "# include \"libsecp256k1-config.h\"\n"); - fprintf(fp, "#endif\n"); - fprintf(fp, "#include \"../include/secp256k1.h\"\n"); fprintf(fp, "#include \"group.h\"\n"); fprintf(fp, "#include \"ecmult_gen.h\"\n"); fprintf(fp, "#include \"precomputed_ecmult_gen.h\"\n"); @@ -41,15 +40,15 @@ int main(int argc, char **argv) { fprintf(fp, "# error Cannot compile precomputed_ecmult_gen.c in exhaustive test mode\n"); fprintf(fp, "#endif /* EXHAUSTIVE_TEST_ORDER */\n"); fprintf(fp, "#define S(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) SECP256K1_GE_STORAGE_CONST(0x##a##u,0x##b##u,0x##c##u,0x##d##u,0x##e##u,0x##f##u,0x##g##u,0x##h##u,0x##i##u,0x##j##u,0x##k##u,0x##l##u,0x##m##u,0x##n##u,0x##o##u,0x##p##u)\n"); - fprintf(fp, "const rustsecp256k1zkp_v0_8_0_ge_storage rustsecp256k1zkp_v0_8_0_ecmult_gen_prec_table[ECMULT_GEN_PREC_N(ECMULT_GEN_PREC_BITS)][ECMULT_GEN_PREC_G(ECMULT_GEN_PREC_BITS)] = {\n"); + fprintf(fp, "const rustsecp256k1zkp_v0_10_0_ge_storage rustsecp256k1zkp_v0_10_0_ecmult_gen_prec_table[ECMULT_GEN_PREC_N(ECMULT_GEN_PREC_BITS)][ECMULT_GEN_PREC_G(ECMULT_GEN_PREC_BITS)] = {\n"); for (bits = 2; bits <= 8; bits *= 2) { int g = ECMULT_GEN_PREC_G(bits); int n = ECMULT_GEN_PREC_N(bits); int inner, outer; - rustsecp256k1zkp_v0_8_0_ge_storage* table = checked_malloc(&default_error_callback, n * g * sizeof(rustsecp256k1zkp_v0_8_0_ge_storage)); - rustsecp256k1zkp_v0_8_0_ecmult_gen_compute_table(table, &rustsecp256k1zkp_v0_8_0_ge_const_g, bits); + rustsecp256k1zkp_v0_10_0_ge_storage* table = checked_malloc(&default_error_callback, n * g * sizeof(rustsecp256k1zkp_v0_10_0_ge_storage)); + rustsecp256k1zkp_v0_10_0_ecmult_gen_compute_table(table, &rustsecp256k1zkp_v0_10_0_ge_const_g, bits); fprintf(fp, "#if ECMULT_GEN_PREC_BITS == %d\n", bits); for(outer = 0; outer != n; outer++) { diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/precomputed_ecmult.c b/secp256k1-zkp-sys/depend/secp256k1/src/precomputed_ecmult.c index 0c5ae6e9..8c70920e 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/precomputed_ecmult.c +++ b/secp256k1-zkp-sys/depend/secp256k1/src/precomputed_ecmult.c @@ -1,11 +1,7 @@ /* This file was automatically generated by precompute_ecmult. */ -/* This file contains an array rustsecp256k1zkp_v0_8_0_pre_g with odd multiples of the base point G and - * an array rustsecp256k1zkp_v0_8_0_pre_g_128 with odd multiples of 2^128*G for accelerating the computation of a*P + b*G. +/* This file contains an array rustsecp256k1zkp_v0_10_0_pre_g with odd multiples of the base point G and + * an array rustsecp256k1zkp_v0_10_0_pre_g_128 with odd multiples of 2^128*G for accelerating the computation of a*P + b*G. */ -#if defined HAVE_CONFIG_H -# include "libsecp256k1-config.h" -#endif -#include "../include/secp256k1.h" #include "group.h" #include "ecmult.h" #include "precomputed_ecmult.h" @@ -17,7 +13,7 @@ # error Cannot compile precomputed_ecmult.c in exhaustive test mode #endif /* EXHAUSTIVE_TEST_ORDER */ #define WINDOW_G ECMULT_WINDOW_SIZE -const rustsecp256k1zkp_v0_8_0_ge_storage rustsecp256k1zkp_v0_8_0_pre_g[ECMULT_TABLE_SIZE(WINDOW_G)] = { +const rustsecp256k1zkp_v0_10_0_ge_storage rustsecp256k1zkp_v0_10_0_pre_g[ECMULT_TABLE_SIZE(WINDOW_G)] = { S(79be667e,f9dcbbac,55a06295,ce870b07,29bfcdb,2dce28d9,59f2815b,16f81798,483ada77,26a3c465,5da4fbfc,e1108a8,fd17b448,a6855419,9c47d08f,fb10d4b8) #if WINDOW_G > 2 ,S(f9308a01,9258c310,49344f85,f89d5229,b531c845,836f99b0,8601f113,bce036f9,388f7b0f,632de814,fe337e6,2a37f356,6500a999,34c2231b,6cb9fd75,84b8e672) @@ -8237,7 +8233,7 @@ const rustsecp256k1zkp_v0_8_0_ge_storage rustsecp256k1zkp_v0_8_0_pre_g[ECMULT_TA ,S(1e70619c,381a6adc,e5d925e0,c9c74f97,3c02ff64,ff2662d7,34efc485,d2bce895,c923f771,f543ffed,42935c28,8474aaaf,80a46ad4,3c579ce0,bb5e663d,668b24b3) #endif }; -const rustsecp256k1zkp_v0_8_0_ge_storage rustsecp256k1zkp_v0_8_0_pre_g_128[ECMULT_TABLE_SIZE(WINDOW_G)] = { +const rustsecp256k1zkp_v0_10_0_ge_storage rustsecp256k1zkp_v0_10_0_pre_g_128[ECMULT_TABLE_SIZE(WINDOW_G)] = { S(8f68b9d2,f63b5f33,9239c1ad,981f162e,e88c5678,723ea335,1b7b444c,9ec4c0da,662a9f2d,ba063986,de1d90c2,b6be215d,bbea2cfe,95510bfd,f23cbf79,501fff82) #if WINDOW_G > 2 ,S(38381dbe,2e509f22,8ba93363,f2451f08,fd845cb3,51d954be,18e2b8ed,d23809fa,e4a32d0a,fb917dc,b09405a5,520eb1cc,3681fccb,32d8f24d,bd707518,331fed52) diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/precomputed_ecmult.h b/secp256k1-zkp-sys/depend/secp256k1/src/precomputed_ecmult.h index 1a6006b8..05e0f6b2 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/precomputed_ecmult.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/precomputed_ecmult.h @@ -11,21 +11,24 @@ extern "C" { #endif +#include "ecmult.h" #include "group.h" #if defined(EXHAUSTIVE_TEST_ORDER) -#if EXHAUSTIVE_TEST_ORDER == 13 +# if EXHAUSTIVE_TEST_ORDER == 7 +# define WINDOW_G 3 +# elif EXHAUSTIVE_TEST_ORDER == 13 # define WINDOW_G 4 # elif EXHAUSTIVE_TEST_ORDER == 199 # define WINDOW_G 8 # else # error No known generator for the specified exhaustive test group order. # endif -static rustsecp256k1zkp_v0_8_0_ge_storage rustsecp256k1zkp_v0_8_0_pre_g[ECMULT_TABLE_SIZE(WINDOW_G)]; -static rustsecp256k1zkp_v0_8_0_ge_storage rustsecp256k1zkp_v0_8_0_pre_g_128[ECMULT_TABLE_SIZE(WINDOW_G)]; +static rustsecp256k1zkp_v0_10_0_ge_storage rustsecp256k1zkp_v0_10_0_pre_g[ECMULT_TABLE_SIZE(WINDOW_G)]; +static rustsecp256k1zkp_v0_10_0_ge_storage rustsecp256k1zkp_v0_10_0_pre_g_128[ECMULT_TABLE_SIZE(WINDOW_G)]; #else /* !defined(EXHAUSTIVE_TEST_ORDER) */ # define WINDOW_G ECMULT_WINDOW_SIZE -extern const rustsecp256k1zkp_v0_8_0_ge_storage rustsecp256k1zkp_v0_8_0_pre_g[ECMULT_TABLE_SIZE(WINDOW_G)]; -extern const rustsecp256k1zkp_v0_8_0_ge_storage rustsecp256k1zkp_v0_8_0_pre_g_128[ECMULT_TABLE_SIZE(WINDOW_G)]; +extern const rustsecp256k1zkp_v0_10_0_ge_storage rustsecp256k1zkp_v0_10_0_pre_g[ECMULT_TABLE_SIZE(WINDOW_G)]; +extern const rustsecp256k1zkp_v0_10_0_ge_storage rustsecp256k1zkp_v0_10_0_pre_g_128[ECMULT_TABLE_SIZE(WINDOW_G)]; #endif /* defined(EXHAUSTIVE_TEST_ORDER) */ #ifdef __cplusplus diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/precomputed_ecmult_gen.c b/secp256k1-zkp-sys/depend/secp256k1/src/precomputed_ecmult_gen.c index 3252e31c..5442475f 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/precomputed_ecmult_gen.c +++ b/secp256k1-zkp-sys/depend/secp256k1/src/precomputed_ecmult_gen.c @@ -1,9 +1,5 @@ /* This file was automatically generated by precompute_ecmult_gen. */ /* See ecmult_gen_impl.h for details about the contents of this file. */ -#if defined HAVE_CONFIG_H -# include "libsecp256k1-config.h" -#endif -#include "../include/secp256k1.h" #include "group.h" #include "ecmult_gen.h" #include "precomputed_ecmult_gen.h" @@ -11,7 +7,7 @@ # error Cannot compile precomputed_ecmult_gen.c in exhaustive test mode #endif /* EXHAUSTIVE_TEST_ORDER */ #define S(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) SECP256K1_GE_STORAGE_CONST(0x##a##u,0x##b##u,0x##c##u,0x##d##u,0x##e##u,0x##f##u,0x##g##u,0x##h##u,0x##i##u,0x##j##u,0x##k##u,0x##l##u,0x##m##u,0x##n##u,0x##o##u,0x##p##u) -const rustsecp256k1zkp_v0_8_0_ge_storage rustsecp256k1zkp_v0_8_0_ecmult_gen_prec_table[ECMULT_GEN_PREC_N(ECMULT_GEN_PREC_BITS)][ECMULT_GEN_PREC_G(ECMULT_GEN_PREC_BITS)] = { +const rustsecp256k1zkp_v0_10_0_ge_storage rustsecp256k1zkp_v0_10_0_ecmult_gen_prec_table[ECMULT_GEN_PREC_N(ECMULT_GEN_PREC_BITS)][ECMULT_GEN_PREC_G(ECMULT_GEN_PREC_BITS)] = { #if ECMULT_GEN_PREC_BITS == 2 {S(3a9ed373,6eed3eec,9aeb5ac0,21b54652,56817b1f,8de6cd0,fbcee548,ba044bb5,7bcc5928,bdc9c023,dfc663b8,9e4f6969,ab751798,8e600ec1,d242010c,45c7974a), S(e44d7675,c3cb2857,4e133c01,a74f4afc,5ce684f8,4a789711,603f7c4f,50abef58,25bcb62f,fe2e2ce2,196ad86c,a006e20,8c64d21b,b25320a3,b5574b9c,1e1bfb4b), diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/precomputed_ecmult_gen.h b/secp256k1-zkp-sys/depend/secp256k1/src/precomputed_ecmult_gen.h index ab06d7df..0d965a8b 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/precomputed_ecmult_gen.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/precomputed_ecmult_gen.h @@ -14,9 +14,9 @@ extern "C" { #include "group.h" #include "ecmult_gen.h" #ifdef EXHAUSTIVE_TEST_ORDER -static rustsecp256k1zkp_v0_8_0_ge_storage rustsecp256k1zkp_v0_8_0_ecmult_gen_prec_table[ECMULT_GEN_PREC_N(ECMULT_GEN_PREC_BITS)][ECMULT_GEN_PREC_G(ECMULT_GEN_PREC_BITS)]; +static rustsecp256k1zkp_v0_10_0_ge_storage rustsecp256k1zkp_v0_10_0_ecmult_gen_prec_table[ECMULT_GEN_PREC_N(ECMULT_GEN_PREC_BITS)][ECMULT_GEN_PREC_G(ECMULT_GEN_PREC_BITS)]; #else -extern const rustsecp256k1zkp_v0_8_0_ge_storage rustsecp256k1zkp_v0_8_0_ecmult_gen_prec_table[ECMULT_GEN_PREC_N(ECMULT_GEN_PREC_BITS)][ECMULT_GEN_PREC_G(ECMULT_GEN_PREC_BITS)]; +extern const rustsecp256k1zkp_v0_10_0_ge_storage rustsecp256k1zkp_v0_10_0_ecmult_gen_prec_table[ECMULT_GEN_PREC_N(ECMULT_GEN_PREC_BITS)][ECMULT_GEN_PREC_G(ECMULT_GEN_PREC_BITS)]; #endif /* defined(EXHAUSTIVE_TEST_ORDER) */ #ifdef __cplusplus diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/scalar.h b/secp256k1-zkp-sys/depend/secp256k1/src/scalar.h index 14aea0e0..29aa8e47 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/scalar.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/scalar.h @@ -9,10 +9,6 @@ #include "util.h" -#if defined HAVE_CONFIG_H -#include "libsecp256k1-config.h" -#endif - #if defined(EXHAUSTIVE_TEST_ORDER) #include "scalar_low.h" #elif defined(SECP256K1_WIDEMUL_INT128) @@ -24,91 +20,92 @@ #endif /** Clear a scalar to prevent the leak of sensitive data. */ -static void rustsecp256k1zkp_v0_8_0_scalar_clear(rustsecp256k1zkp_v0_8_0_scalar *r); +static void rustsecp256k1zkp_v0_10_0_scalar_clear(rustsecp256k1zkp_v0_10_0_scalar *r); /** Access bits from a scalar. All requested bits must belong to the same 32-bit limb. */ -static unsigned int rustsecp256k1zkp_v0_8_0_scalar_get_bits(const rustsecp256k1zkp_v0_8_0_scalar *a, unsigned int offset, unsigned int count); +static unsigned int rustsecp256k1zkp_v0_10_0_scalar_get_bits(const rustsecp256k1zkp_v0_10_0_scalar *a, unsigned int offset, unsigned int count); -/** Access bits from a scalar. Not constant time. */ -static unsigned int rustsecp256k1zkp_v0_8_0_scalar_get_bits_var(const rustsecp256k1zkp_v0_8_0_scalar *a, unsigned int offset, unsigned int count); +/** Access bits from a scalar. Not constant time in offset and count. */ +static unsigned int rustsecp256k1zkp_v0_10_0_scalar_get_bits_var(const rustsecp256k1zkp_v0_10_0_scalar *a, unsigned int offset, unsigned int count); /** Set a scalar from a big endian byte array. The scalar will be reduced modulo group order `n`. * In: bin: pointer to a 32-byte array. * Out: r: scalar to be set. * overflow: non-zero if the scalar was bigger or equal to `n` before reduction, zero otherwise (can be NULL). */ -static void rustsecp256k1zkp_v0_8_0_scalar_set_b32(rustsecp256k1zkp_v0_8_0_scalar *r, const unsigned char *bin, int *overflow); +static void rustsecp256k1zkp_v0_10_0_scalar_set_b32(rustsecp256k1zkp_v0_10_0_scalar *r, const unsigned char *bin, int *overflow); /** Set a scalar from a big endian byte array and returns 1 if it is a valid * seckey and 0 otherwise. */ -static int rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(rustsecp256k1zkp_v0_8_0_scalar *r, const unsigned char *bin); +static int rustsecp256k1zkp_v0_10_0_scalar_set_b32_seckey(rustsecp256k1zkp_v0_10_0_scalar *r, const unsigned char *bin); /** Set a scalar to an unsigned integer. */ -static void rustsecp256k1zkp_v0_8_0_scalar_set_int(rustsecp256k1zkp_v0_8_0_scalar *r, unsigned int v); +static void rustsecp256k1zkp_v0_10_0_scalar_set_int(rustsecp256k1zkp_v0_10_0_scalar *r, unsigned int v); /** Set a scalar to an unsigned 64-bit integer */ -static void rustsecp256k1zkp_v0_8_0_scalar_set_u64(rustsecp256k1zkp_v0_8_0_scalar *r, uint64_t v); +static void rustsecp256k1zkp_v0_10_0_scalar_set_u64(rustsecp256k1zkp_v0_10_0_scalar *r, uint64_t v); /** Convert a scalar to a byte array. */ -static void rustsecp256k1zkp_v0_8_0_scalar_get_b32(unsigned char *bin, const rustsecp256k1zkp_v0_8_0_scalar* a); +static void rustsecp256k1zkp_v0_10_0_scalar_get_b32(unsigned char *bin, const rustsecp256k1zkp_v0_10_0_scalar* a); /** Add two scalars together (modulo the group order). Returns whether it overflowed. */ -static int rustsecp256k1zkp_v0_8_0_scalar_add(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a, const rustsecp256k1zkp_v0_8_0_scalar *b); +static int rustsecp256k1zkp_v0_10_0_scalar_add(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a, const rustsecp256k1zkp_v0_10_0_scalar *b); /** Conditionally add a power of two to a scalar. The result is not allowed to overflow. */ -static void rustsecp256k1zkp_v0_8_0_scalar_cadd_bit(rustsecp256k1zkp_v0_8_0_scalar *r, unsigned int bit, int flag); +static void rustsecp256k1zkp_v0_10_0_scalar_cadd_bit(rustsecp256k1zkp_v0_10_0_scalar *r, unsigned int bit, int flag); /** Multiply two scalars (modulo the group order). */ -static void rustsecp256k1zkp_v0_8_0_scalar_mul(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a, const rustsecp256k1zkp_v0_8_0_scalar *b); - -/** Shift a scalar right by some amount strictly between 0 and 16, returning - * the low bits that were shifted off */ -static int rustsecp256k1zkp_v0_8_0_scalar_shr_int(rustsecp256k1zkp_v0_8_0_scalar *r, int n); +static void rustsecp256k1zkp_v0_10_0_scalar_mul(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a, const rustsecp256k1zkp_v0_10_0_scalar *b); /** Compute the square of a scalar (modulo the group order). */ -static void rustsecp256k1zkp_v0_8_0_scalar_sqr(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a); +static void rustsecp256k1zkp_v0_10_0_scalar_sqr(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a); /** Compute the inverse of a scalar (modulo the group order). */ -static void rustsecp256k1zkp_v0_8_0_scalar_inverse(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a); +static void rustsecp256k1zkp_v0_10_0_scalar_inverse(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a); /** Compute the inverse of a scalar (modulo the group order), without constant-time guarantee. */ -static void rustsecp256k1zkp_v0_8_0_scalar_inverse_var(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a); +static void rustsecp256k1zkp_v0_10_0_scalar_inverse_var(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a); /** Compute the complement of a scalar (modulo the group order). */ -static void rustsecp256k1zkp_v0_8_0_scalar_negate(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a); +static void rustsecp256k1zkp_v0_10_0_scalar_negate(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a); + +/** Multiply a scalar with the multiplicative inverse of 2. */ +static void rustsecp256k1zkp_v0_10_0_scalar_half(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a); /** Check whether a scalar equals zero. */ -static int rustsecp256k1zkp_v0_8_0_scalar_is_zero(const rustsecp256k1zkp_v0_8_0_scalar *a); +static int rustsecp256k1zkp_v0_10_0_scalar_is_zero(const rustsecp256k1zkp_v0_10_0_scalar *a); /** Check whether a scalar equals one. */ -static int rustsecp256k1zkp_v0_8_0_scalar_is_one(const rustsecp256k1zkp_v0_8_0_scalar *a); +static int rustsecp256k1zkp_v0_10_0_scalar_is_one(const rustsecp256k1zkp_v0_10_0_scalar *a); /** Check whether a scalar, considered as an nonnegative integer, is even. */ -static int rustsecp256k1zkp_v0_8_0_scalar_is_even(const rustsecp256k1zkp_v0_8_0_scalar *a); +static int rustsecp256k1zkp_v0_10_0_scalar_is_even(const rustsecp256k1zkp_v0_10_0_scalar *a); /** Check whether a scalar is higher than the group order divided by 2. */ -static int rustsecp256k1zkp_v0_8_0_scalar_is_high(const rustsecp256k1zkp_v0_8_0_scalar *a); +static int rustsecp256k1zkp_v0_10_0_scalar_is_high(const rustsecp256k1zkp_v0_10_0_scalar *a); /** Conditionally negate a number, in constant time. * Returns -1 if the number was negated, 1 otherwise */ -static int rustsecp256k1zkp_v0_8_0_scalar_cond_negate(rustsecp256k1zkp_v0_8_0_scalar *a, int flag); +static int rustsecp256k1zkp_v0_10_0_scalar_cond_negate(rustsecp256k1zkp_v0_10_0_scalar *a, int flag); /** Compare two scalars. */ -static int rustsecp256k1zkp_v0_8_0_scalar_eq(const rustsecp256k1zkp_v0_8_0_scalar *a, const rustsecp256k1zkp_v0_8_0_scalar *b); +static int rustsecp256k1zkp_v0_10_0_scalar_eq(const rustsecp256k1zkp_v0_10_0_scalar *a, const rustsecp256k1zkp_v0_10_0_scalar *b); /** Find r1 and r2 such that r1+r2*2^128 = k. */ -static void rustsecp256k1zkp_v0_8_0_scalar_split_128(rustsecp256k1zkp_v0_8_0_scalar *r1, rustsecp256k1zkp_v0_8_0_scalar *r2, const rustsecp256k1zkp_v0_8_0_scalar *k); -/** Find r1 and r2 such that r1+r2*lambda = k, - * where r1 and r2 or their negations are maximum 128 bits long (see rustsecp256k1zkp_v0_8_0_ge_mul_lambda). */ -static void rustsecp256k1zkp_v0_8_0_scalar_split_lambda(rustsecp256k1zkp_v0_8_0_scalar *r1, rustsecp256k1zkp_v0_8_0_scalar *r2, const rustsecp256k1zkp_v0_8_0_scalar *k); +static void rustsecp256k1zkp_v0_10_0_scalar_split_128(rustsecp256k1zkp_v0_10_0_scalar *r1, rustsecp256k1zkp_v0_10_0_scalar *r2, const rustsecp256k1zkp_v0_10_0_scalar *k); +/** Find r1 and r2 such that r1+r2*lambda = k, where r1 and r2 or their + * negations are maximum 128 bits long (see rustsecp256k1zkp_v0_10_0_ge_mul_lambda). It is + * required that r1, r2, and k all point to different objects. */ +static void rustsecp256k1zkp_v0_10_0_scalar_split_lambda(rustsecp256k1zkp_v0_10_0_scalar * SECP256K1_RESTRICT r1, rustsecp256k1zkp_v0_10_0_scalar * SECP256K1_RESTRICT r2, const rustsecp256k1zkp_v0_10_0_scalar * SECP256K1_RESTRICT k); /** Multiply a and b (without taking the modulus!), divide by 2**shift, and round to the nearest integer. Shift must be at least 256. */ -static void rustsecp256k1zkp_v0_8_0_scalar_mul_shift_var(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a, const rustsecp256k1zkp_v0_8_0_scalar *b, unsigned int shift); +static void rustsecp256k1zkp_v0_10_0_scalar_mul_shift_var(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a, const rustsecp256k1zkp_v0_10_0_scalar *b, unsigned int shift); /** If flag is true, set *r equal to *a; otherwise leave it. Constant-time. Both *r and *a must be initialized.*/ -static void rustsecp256k1zkp_v0_8_0_scalar_cmov(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a, int flag); +static void rustsecp256k1zkp_v0_10_0_scalar_cmov(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a, int flag); -/** Generate two scalars from a 32-byte seed and an integer using the chacha20 stream cipher */ -static void rustsecp256k1zkp_v0_8_0_scalar_chacha20(rustsecp256k1zkp_v0_8_0_scalar *r1, rustsecp256k1zkp_v0_8_0_scalar *r2, const unsigned char *seed, uint64_t idx); +/** Check invariants on a scalar (no-op unless VERIFY is enabled). */ +static void rustsecp256k1zkp_v0_10_0_scalar_verify(const rustsecp256k1zkp_v0_10_0_scalar *r); +#define SECP256K1_SCALAR_VERIFY(r) rustsecp256k1zkp_v0_10_0_scalar_verify(r) #endif /* SECP256K1_SCALAR_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/scalar_4x64.h b/secp256k1-zkp-sys/depend/secp256k1/src/scalar_4x64.h index e6d25aa4..80166f30 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/scalar_4x64.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/scalar_4x64.h @@ -12,7 +12,7 @@ /** A scalar modulo the group order of the secp256k1 curve. */ typedef struct { uint64_t d[4]; -} rustsecp256k1zkp_v0_8_0_scalar; +} rustsecp256k1zkp_v0_10_0_scalar; #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{((uint64_t)(d1)) << 32 | (d0), ((uint64_t)(d3)) << 32 | (d2), ((uint64_t)(d5)) << 32 | (d4), ((uint64_t)(d7)) << 32 | (d6)}} diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/scalar_4x64_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/scalar_4x64_impl.h index fe0af361..8ca2b962 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/scalar_4x64_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/scalar_4x64_impl.h @@ -7,10 +7,11 @@ #ifndef SECP256K1_SCALAR_REPR_IMPL_H #define SECP256K1_SCALAR_REPR_IMPL_H -#include "scalar.h" #include - +#include "checkmem.h" +#include "int128.h" #include "modinv64_impl.h" +#include "util.h" /* Limbs of the secp256k1 order. */ #define SECP256K1_N_0 ((uint64_t)0xBFD25E8CD0364141ULL) @@ -29,44 +30,50 @@ #define SECP256K1_N_H_2 ((uint64_t)0xFFFFFFFFFFFFFFFFULL) #define SECP256K1_N_H_3 ((uint64_t)0x7FFFFFFFFFFFFFFFULL) -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_scalar_clear(rustsecp256k1zkp_v0_8_0_scalar *r) { +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_scalar_clear(rustsecp256k1zkp_v0_10_0_scalar *r) { r->d[0] = 0; r->d[1] = 0; r->d[2] = 0; r->d[3] = 0; } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_scalar_set_int(rustsecp256k1zkp_v0_8_0_scalar *r, unsigned int v) { +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_scalar_set_int(rustsecp256k1zkp_v0_10_0_scalar *r, unsigned int v) { r->d[0] = v; r->d[1] = 0; r->d[2] = 0; r->d[3] = 0; + + SECP256K1_SCALAR_VERIFY(r); } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_scalar_set_u64(rustsecp256k1zkp_v0_8_0_scalar *r, uint64_t v) { +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_scalar_set_u64(rustsecp256k1zkp_v0_10_0_scalar *r, uint64_t v) { r->d[0] = v; r->d[1] = 0; r->d[2] = 0; r->d[3] = 0; } -SECP256K1_INLINE static unsigned int rustsecp256k1zkp_v0_8_0_scalar_get_bits(const rustsecp256k1zkp_v0_8_0_scalar *a, unsigned int offset, unsigned int count) { +SECP256K1_INLINE static unsigned int rustsecp256k1zkp_v0_10_0_scalar_get_bits(const rustsecp256k1zkp_v0_10_0_scalar *a, unsigned int offset, unsigned int count) { + SECP256K1_SCALAR_VERIFY(a); VERIFY_CHECK((offset + count - 1) >> 6 == offset >> 6); + return (a->d[offset >> 6] >> (offset & 0x3F)) & ((((uint64_t)1) << count) - 1); } -SECP256K1_INLINE static unsigned int rustsecp256k1zkp_v0_8_0_scalar_get_bits_var(const rustsecp256k1zkp_v0_8_0_scalar *a, unsigned int offset, unsigned int count) { +SECP256K1_INLINE static unsigned int rustsecp256k1zkp_v0_10_0_scalar_get_bits_var(const rustsecp256k1zkp_v0_10_0_scalar *a, unsigned int offset, unsigned int count) { + SECP256K1_SCALAR_VERIFY(a); VERIFY_CHECK(count < 32); VERIFY_CHECK(offset + count <= 256); + if ((offset + count - 1) >> 6 == offset >> 6) { - return rustsecp256k1zkp_v0_8_0_scalar_get_bits(a, offset, count); + return rustsecp256k1zkp_v0_10_0_scalar_get_bits(a, offset, count); } else { VERIFY_CHECK((offset >> 6) + 1 < 4); return ((a->d[offset >> 6] >> (offset & 0x3F)) | (a->d[(offset >> 6) + 1] << (64 - (offset & 0x3F)))) & ((((uint64_t)1) << count) - 1); } } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_scalar_check_overflow(const rustsecp256k1zkp_v0_8_0_scalar *a) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_scalar_check_overflow(const rustsecp256k1zkp_v0_10_0_scalar *a) { int yes = 0; int no = 0; no |= (a->d[3] < SECP256K1_N_3); /* No need for a > check. */ @@ -78,96 +85,178 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_scalar_check_overflow(const return yes; } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_scalar_reduce(rustsecp256k1zkp_v0_8_0_scalar *r, unsigned int overflow) { - uint128_t t; +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_scalar_reduce(rustsecp256k1zkp_v0_10_0_scalar *r, unsigned int overflow) { + rustsecp256k1zkp_v0_10_0_uint128 t; VERIFY_CHECK(overflow <= 1); - t = (uint128_t)r->d[0] + overflow * SECP256K1_N_C_0; - r->d[0] = t & 0xFFFFFFFFFFFFFFFFULL; t >>= 64; - t += (uint128_t)r->d[1] + overflow * SECP256K1_N_C_1; - r->d[1] = t & 0xFFFFFFFFFFFFFFFFULL; t >>= 64; - t += (uint128_t)r->d[2] + overflow * SECP256K1_N_C_2; - r->d[2] = t & 0xFFFFFFFFFFFFFFFFULL; t >>= 64; - t += (uint64_t)r->d[3]; - r->d[3] = t & 0xFFFFFFFFFFFFFFFFULL; + + rustsecp256k1zkp_v0_10_0_u128_from_u64(&t, r->d[0]); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, overflow * SECP256K1_N_C_0); + r->d[0] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t); rustsecp256k1zkp_v0_10_0_u128_rshift(&t, 64); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, r->d[1]); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, overflow * SECP256K1_N_C_1); + r->d[1] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t); rustsecp256k1zkp_v0_10_0_u128_rshift(&t, 64); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, r->d[2]); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, overflow * SECP256K1_N_C_2); + r->d[2] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t); rustsecp256k1zkp_v0_10_0_u128_rshift(&t, 64); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, r->d[3]); + r->d[3] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t); + + SECP256K1_SCALAR_VERIFY(r); return overflow; } -static int rustsecp256k1zkp_v0_8_0_scalar_add(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a, const rustsecp256k1zkp_v0_8_0_scalar *b) { +static int rustsecp256k1zkp_v0_10_0_scalar_add(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a, const rustsecp256k1zkp_v0_10_0_scalar *b) { int overflow; - uint128_t t = (uint128_t)a->d[0] + b->d[0]; - r->d[0] = t & 0xFFFFFFFFFFFFFFFFULL; t >>= 64; - t += (uint128_t)a->d[1] + b->d[1]; - r->d[1] = t & 0xFFFFFFFFFFFFFFFFULL; t >>= 64; - t += (uint128_t)a->d[2] + b->d[2]; - r->d[2] = t & 0xFFFFFFFFFFFFFFFFULL; t >>= 64; - t += (uint128_t)a->d[3] + b->d[3]; - r->d[3] = t & 0xFFFFFFFFFFFFFFFFULL; t >>= 64; - overflow = t + rustsecp256k1zkp_v0_8_0_scalar_check_overflow(r); + rustsecp256k1zkp_v0_10_0_uint128 t; + SECP256K1_SCALAR_VERIFY(a); + SECP256K1_SCALAR_VERIFY(b); + + rustsecp256k1zkp_v0_10_0_u128_from_u64(&t, a->d[0]); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, b->d[0]); + r->d[0] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t); rustsecp256k1zkp_v0_10_0_u128_rshift(&t, 64); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, a->d[1]); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, b->d[1]); + r->d[1] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t); rustsecp256k1zkp_v0_10_0_u128_rshift(&t, 64); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, a->d[2]); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, b->d[2]); + r->d[2] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t); rustsecp256k1zkp_v0_10_0_u128_rshift(&t, 64); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, a->d[3]); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, b->d[3]); + r->d[3] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t); rustsecp256k1zkp_v0_10_0_u128_rshift(&t, 64); + overflow = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t) + rustsecp256k1zkp_v0_10_0_scalar_check_overflow(r); VERIFY_CHECK(overflow == 0 || overflow == 1); - rustsecp256k1zkp_v0_8_0_scalar_reduce(r, overflow); + rustsecp256k1zkp_v0_10_0_scalar_reduce(r, overflow); + + SECP256K1_SCALAR_VERIFY(r); return overflow; } -static void rustsecp256k1zkp_v0_8_0_scalar_cadd_bit(rustsecp256k1zkp_v0_8_0_scalar *r, unsigned int bit, int flag) { - uint128_t t; +static void rustsecp256k1zkp_v0_10_0_scalar_cadd_bit(rustsecp256k1zkp_v0_10_0_scalar *r, unsigned int bit, int flag) { + rustsecp256k1zkp_v0_10_0_uint128 t; + volatile int vflag = flag; + SECP256K1_SCALAR_VERIFY(r); VERIFY_CHECK(bit < 256); - bit += ((uint32_t) flag - 1) & 0x100; /* forcing (bit >> 6) > 3 makes this a noop */ - t = (uint128_t)r->d[0] + (((uint64_t)((bit >> 6) == 0)) << (bit & 0x3F)); - r->d[0] = t & 0xFFFFFFFFFFFFFFFFULL; t >>= 64; - t += (uint128_t)r->d[1] + (((uint64_t)((bit >> 6) == 1)) << (bit & 0x3F)); - r->d[1] = t & 0xFFFFFFFFFFFFFFFFULL; t >>= 64; - t += (uint128_t)r->d[2] + (((uint64_t)((bit >> 6) == 2)) << (bit & 0x3F)); - r->d[2] = t & 0xFFFFFFFFFFFFFFFFULL; t >>= 64; - t += (uint128_t)r->d[3] + (((uint64_t)((bit >> 6) == 3)) << (bit & 0x3F)); - r->d[3] = t & 0xFFFFFFFFFFFFFFFFULL; -#ifdef VERIFY - VERIFY_CHECK((t >> 64) == 0); - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_scalar_check_overflow(r) == 0); -#endif + + bit += ((uint32_t) vflag - 1) & 0x100; /* forcing (bit >> 6) > 3 makes this a noop */ + rustsecp256k1zkp_v0_10_0_u128_from_u64(&t, r->d[0]); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, ((uint64_t)((bit >> 6) == 0)) << (bit & 0x3F)); + r->d[0] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t); rustsecp256k1zkp_v0_10_0_u128_rshift(&t, 64); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, r->d[1]); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, ((uint64_t)((bit >> 6) == 1)) << (bit & 0x3F)); + r->d[1] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t); rustsecp256k1zkp_v0_10_0_u128_rshift(&t, 64); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, r->d[2]); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, ((uint64_t)((bit >> 6) == 2)) << (bit & 0x3F)); + r->d[2] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t); rustsecp256k1zkp_v0_10_0_u128_rshift(&t, 64); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, r->d[3]); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, ((uint64_t)((bit >> 6) == 3)) << (bit & 0x3F)); + r->d[3] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t); + + SECP256K1_SCALAR_VERIFY(r); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_u128_hi_u64(&t) == 0); } -static void rustsecp256k1zkp_v0_8_0_scalar_set_b32(rustsecp256k1zkp_v0_8_0_scalar *r, const unsigned char *b32, int *overflow) { +static void rustsecp256k1zkp_v0_10_0_scalar_set_b32(rustsecp256k1zkp_v0_10_0_scalar *r, const unsigned char *b32, int *overflow) { int over; - r->d[0] = (uint64_t)b32[31] | (uint64_t)b32[30] << 8 | (uint64_t)b32[29] << 16 | (uint64_t)b32[28] << 24 | (uint64_t)b32[27] << 32 | (uint64_t)b32[26] << 40 | (uint64_t)b32[25] << 48 | (uint64_t)b32[24] << 56; - r->d[1] = (uint64_t)b32[23] | (uint64_t)b32[22] << 8 | (uint64_t)b32[21] << 16 | (uint64_t)b32[20] << 24 | (uint64_t)b32[19] << 32 | (uint64_t)b32[18] << 40 | (uint64_t)b32[17] << 48 | (uint64_t)b32[16] << 56; - r->d[2] = (uint64_t)b32[15] | (uint64_t)b32[14] << 8 | (uint64_t)b32[13] << 16 | (uint64_t)b32[12] << 24 | (uint64_t)b32[11] << 32 | (uint64_t)b32[10] << 40 | (uint64_t)b32[9] << 48 | (uint64_t)b32[8] << 56; - r->d[3] = (uint64_t)b32[7] | (uint64_t)b32[6] << 8 | (uint64_t)b32[5] << 16 | (uint64_t)b32[4] << 24 | (uint64_t)b32[3] << 32 | (uint64_t)b32[2] << 40 | (uint64_t)b32[1] << 48 | (uint64_t)b32[0] << 56; - over = rustsecp256k1zkp_v0_8_0_scalar_reduce(r, rustsecp256k1zkp_v0_8_0_scalar_check_overflow(r)); + r->d[0] = rustsecp256k1zkp_v0_10_0_read_be64(&b32[24]); + r->d[1] = rustsecp256k1zkp_v0_10_0_read_be64(&b32[16]); + r->d[2] = rustsecp256k1zkp_v0_10_0_read_be64(&b32[8]); + r->d[3] = rustsecp256k1zkp_v0_10_0_read_be64(&b32[0]); + over = rustsecp256k1zkp_v0_10_0_scalar_reduce(r, rustsecp256k1zkp_v0_10_0_scalar_check_overflow(r)); if (overflow) { *overflow = over; } + + SECP256K1_SCALAR_VERIFY(r); } -static void rustsecp256k1zkp_v0_8_0_scalar_get_b32(unsigned char *bin, const rustsecp256k1zkp_v0_8_0_scalar* a) { - bin[0] = a->d[3] >> 56; bin[1] = a->d[3] >> 48; bin[2] = a->d[3] >> 40; bin[3] = a->d[3] >> 32; bin[4] = a->d[3] >> 24; bin[5] = a->d[3] >> 16; bin[6] = a->d[3] >> 8; bin[7] = a->d[3]; - bin[8] = a->d[2] >> 56; bin[9] = a->d[2] >> 48; bin[10] = a->d[2] >> 40; bin[11] = a->d[2] >> 32; bin[12] = a->d[2] >> 24; bin[13] = a->d[2] >> 16; bin[14] = a->d[2] >> 8; bin[15] = a->d[2]; - bin[16] = a->d[1] >> 56; bin[17] = a->d[1] >> 48; bin[18] = a->d[1] >> 40; bin[19] = a->d[1] >> 32; bin[20] = a->d[1] >> 24; bin[21] = a->d[1] >> 16; bin[22] = a->d[1] >> 8; bin[23] = a->d[1]; - bin[24] = a->d[0] >> 56; bin[25] = a->d[0] >> 48; bin[26] = a->d[0] >> 40; bin[27] = a->d[0] >> 32; bin[28] = a->d[0] >> 24; bin[29] = a->d[0] >> 16; bin[30] = a->d[0] >> 8; bin[31] = a->d[0]; +static void rustsecp256k1zkp_v0_10_0_scalar_get_b32(unsigned char *bin, const rustsecp256k1zkp_v0_10_0_scalar* a) { + SECP256K1_SCALAR_VERIFY(a); + + rustsecp256k1zkp_v0_10_0_write_be64(&bin[0], a->d[3]); + rustsecp256k1zkp_v0_10_0_write_be64(&bin[8], a->d[2]); + rustsecp256k1zkp_v0_10_0_write_be64(&bin[16], a->d[1]); + rustsecp256k1zkp_v0_10_0_write_be64(&bin[24], a->d[0]); } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_scalar_is_zero(const rustsecp256k1zkp_v0_8_0_scalar *a) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_scalar_is_zero(const rustsecp256k1zkp_v0_10_0_scalar *a) { + SECP256K1_SCALAR_VERIFY(a); + return (a->d[0] | a->d[1] | a->d[2] | a->d[3]) == 0; } -static void rustsecp256k1zkp_v0_8_0_scalar_negate(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a) { - uint64_t nonzero = 0xFFFFFFFFFFFFFFFFULL * (rustsecp256k1zkp_v0_8_0_scalar_is_zero(a) == 0); - uint128_t t = (uint128_t)(~a->d[0]) + SECP256K1_N_0 + 1; - r->d[0] = t & nonzero; t >>= 64; - t += (uint128_t)(~a->d[1]) + SECP256K1_N_1; - r->d[1] = t & nonzero; t >>= 64; - t += (uint128_t)(~a->d[2]) + SECP256K1_N_2; - r->d[2] = t & nonzero; t >>= 64; - t += (uint128_t)(~a->d[3]) + SECP256K1_N_3; - r->d[3] = t & nonzero; +static void rustsecp256k1zkp_v0_10_0_scalar_negate(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a) { + uint64_t nonzero = 0xFFFFFFFFFFFFFFFFULL * (rustsecp256k1zkp_v0_10_0_scalar_is_zero(a) == 0); + rustsecp256k1zkp_v0_10_0_uint128 t; + SECP256K1_SCALAR_VERIFY(a); + + rustsecp256k1zkp_v0_10_0_u128_from_u64(&t, ~a->d[0]); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, SECP256K1_N_0 + 1); + r->d[0] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t) & nonzero; rustsecp256k1zkp_v0_10_0_u128_rshift(&t, 64); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, ~a->d[1]); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, SECP256K1_N_1); + r->d[1] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t) & nonzero; rustsecp256k1zkp_v0_10_0_u128_rshift(&t, 64); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, ~a->d[2]); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, SECP256K1_N_2); + r->d[2] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t) & nonzero; rustsecp256k1zkp_v0_10_0_u128_rshift(&t, 64); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, ~a->d[3]); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, SECP256K1_N_3); + r->d[3] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t) & nonzero; + + SECP256K1_SCALAR_VERIFY(r); +} + +static void rustsecp256k1zkp_v0_10_0_scalar_half(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a) { + /* Writing `/` for field division and `//` for integer division, we compute + * + * a/2 = (a - (a&1))/2 + (a&1)/2 + * = (a >> 1) + (a&1 ? 1/2 : 0) + * = (a >> 1) + (a&1 ? n//2+1 : 0), + * + * where n is the group order and in the last equality we have used 1/2 = n//2+1 (mod n). + * For n//2, we have the constants SECP256K1_N_H_0, ... + * + * This sum does not overflow. The most extreme case is a = -2, the largest odd scalar. Here: + * - the left summand is: a >> 1 = (a - a&1)/2 = (n-2-1)//2 = (n-3)//2 + * - the right summand is: a&1 ? n//2+1 : 0 = n//2+1 = (n-1)//2 + 2//2 = (n+1)//2 + * Together they sum to (n-3)//2 + (n+1)//2 = (2n-2)//2 = n - 1, which is less than n. + */ + uint64_t mask = -(uint64_t)(a->d[0] & 1U); + rustsecp256k1zkp_v0_10_0_uint128 t; + SECP256K1_SCALAR_VERIFY(a); + + rustsecp256k1zkp_v0_10_0_u128_from_u64(&t, (a->d[0] >> 1) | (a->d[1] << 63)); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, (SECP256K1_N_H_0 + 1U) & mask); + r->d[0] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t); rustsecp256k1zkp_v0_10_0_u128_rshift(&t, 64); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, (a->d[1] >> 1) | (a->d[2] << 63)); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, SECP256K1_N_H_1 & mask); + r->d[1] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t); rustsecp256k1zkp_v0_10_0_u128_rshift(&t, 64); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, (a->d[2] >> 1) | (a->d[3] << 63)); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, SECP256K1_N_H_2 & mask); + r->d[2] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t); rustsecp256k1zkp_v0_10_0_u128_rshift(&t, 64); + r->d[3] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t) + (a->d[3] >> 1) + (SECP256K1_N_H_3 & mask); +#ifdef VERIFY + /* The line above only computed the bottom 64 bits of r->d[3]; redo the computation + * in full 128 bits to make sure the top 64 bits are indeed zero. */ + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, a->d[3] >> 1); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, SECP256K1_N_H_3 & mask); + rustsecp256k1zkp_v0_10_0_u128_rshift(&t, 64); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_u128_to_u64(&t) == 0); + + SECP256K1_SCALAR_VERIFY(r); +#endif } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_scalar_is_one(const rustsecp256k1zkp_v0_8_0_scalar *a) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_scalar_is_one(const rustsecp256k1zkp_v0_10_0_scalar *a) { + SECP256K1_SCALAR_VERIFY(a); + return ((a->d[0] ^ 1) | a->d[1] | a->d[2] | a->d[3]) == 0; } -static int rustsecp256k1zkp_v0_8_0_scalar_is_high(const rustsecp256k1zkp_v0_8_0_scalar *a) { +static int rustsecp256k1zkp_v0_10_0_scalar_is_high(const rustsecp256k1zkp_v0_10_0_scalar *a) { int yes = 0; int no = 0; + SECP256K1_SCALAR_VERIFY(a); + no |= (a->d[3] < SECP256K1_N_H_3); yes |= (a->d[3] > SECP256K1_N_H_3) & ~no; no |= (a->d[2] < SECP256K1_N_H_2) & ~yes; /* No need for a > check. */ @@ -177,19 +266,29 @@ static int rustsecp256k1zkp_v0_8_0_scalar_is_high(const rustsecp256k1zkp_v0_8_0_ return yes; } -static int rustsecp256k1zkp_v0_8_0_scalar_cond_negate(rustsecp256k1zkp_v0_8_0_scalar *r, int flag) { +static int rustsecp256k1zkp_v0_10_0_scalar_cond_negate(rustsecp256k1zkp_v0_10_0_scalar *r, int flag) { /* If we are flag = 0, mask = 00...00 and this is a no-op; - * if we are flag = 1, mask = 11...11 and this is identical to rustsecp256k1zkp_v0_8_0_scalar_negate */ - uint64_t mask = !flag - 1; - uint64_t nonzero = (rustsecp256k1zkp_v0_8_0_scalar_is_zero(r) != 0) - 1; - uint128_t t = (uint128_t)(r->d[0] ^ mask) + ((SECP256K1_N_0 + 1) & mask); - r->d[0] = t & nonzero; t >>= 64; - t += (uint128_t)(r->d[1] ^ mask) + (SECP256K1_N_1 & mask); - r->d[1] = t & nonzero; t >>= 64; - t += (uint128_t)(r->d[2] ^ mask) + (SECP256K1_N_2 & mask); - r->d[2] = t & nonzero; t >>= 64; - t += (uint128_t)(r->d[3] ^ mask) + (SECP256K1_N_3 & mask); - r->d[3] = t & nonzero; + * if we are flag = 1, mask = 11...11 and this is identical to rustsecp256k1zkp_v0_10_0_scalar_negate */ + volatile int vflag = flag; + uint64_t mask = -vflag; + uint64_t nonzero = (rustsecp256k1zkp_v0_10_0_scalar_is_zero(r) != 0) - 1; + rustsecp256k1zkp_v0_10_0_uint128 t; + SECP256K1_SCALAR_VERIFY(r); + + rustsecp256k1zkp_v0_10_0_u128_from_u64(&t, r->d[0] ^ mask); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, (SECP256K1_N_0 + 1) & mask); + r->d[0] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t) & nonzero; rustsecp256k1zkp_v0_10_0_u128_rshift(&t, 64); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, r->d[1] ^ mask); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, SECP256K1_N_1 & mask); + r->d[1] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t) & nonzero; rustsecp256k1zkp_v0_10_0_u128_rshift(&t, 64); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, r->d[2] ^ mask); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, SECP256K1_N_2 & mask); + r->d[2] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t) & nonzero; rustsecp256k1zkp_v0_10_0_u128_rshift(&t, 64); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, r->d[3] ^ mask); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&t, SECP256K1_N_3 & mask); + r->d[3] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t) & nonzero; + + SECP256K1_SCALAR_VERIFY(r); return 2 * (mask == 0) - 1; } @@ -199,9 +298,10 @@ static int rustsecp256k1zkp_v0_8_0_scalar_cond_negate(rustsecp256k1zkp_v0_8_0_sc #define muladd(a,b) { \ uint64_t tl, th; \ { \ - uint128_t t = (uint128_t)a * b; \ - th = t >> 64; /* at most 0xFFFFFFFFFFFFFFFE */ \ - tl = t; \ + rustsecp256k1zkp_v0_10_0_uint128 t; \ + rustsecp256k1zkp_v0_10_0_u128_mul(&t, a, b); \ + th = rustsecp256k1zkp_v0_10_0_u128_hi_u64(&t); /* at most 0xFFFFFFFFFFFFFFFE */ \ + tl = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t); \ } \ c0 += tl; /* overflow is handled on the next line */ \ th += (c0 < tl); /* at most 0xFFFFFFFFFFFFFFFF */ \ @@ -214,9 +314,10 @@ static int rustsecp256k1zkp_v0_8_0_scalar_cond_negate(rustsecp256k1zkp_v0_8_0_sc #define muladd_fast(a,b) { \ uint64_t tl, th; \ { \ - uint128_t t = (uint128_t)a * b; \ - th = t >> 64; /* at most 0xFFFFFFFFFFFFFFFE */ \ - tl = t; \ + rustsecp256k1zkp_v0_10_0_uint128 t; \ + rustsecp256k1zkp_v0_10_0_u128_mul(&t, a, b); \ + th = rustsecp256k1zkp_v0_10_0_u128_hi_u64(&t); /* at most 0xFFFFFFFFFFFFFFFE */ \ + tl = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t); \ } \ c0 += tl; /* overflow is handled on the next line */ \ th += (c0 < tl); /* at most 0xFFFFFFFFFFFFFFFF */ \ @@ -228,9 +329,10 @@ static int rustsecp256k1zkp_v0_8_0_scalar_cond_negate(rustsecp256k1zkp_v0_8_0_sc #define muladd2(a,b) { \ uint64_t tl, th, th2, tl2; \ { \ - uint128_t t = (uint128_t)a * b; \ - th = t >> 64; /* at most 0xFFFFFFFFFFFFFFFE */ \ - tl = t; \ + rustsecp256k1zkp_v0_10_0_uint128 t; \ + rustsecp256k1zkp_v0_10_0_u128_mul(&t, a, b); \ + th = rustsecp256k1zkp_v0_10_0_u128_hi_u64(&t); /* at most 0xFFFFFFFFFFFFFFFE */ \ + tl = rustsecp256k1zkp_v0_10_0_u128_to_u64(&t); \ } \ th2 = th + th; /* at most 0xFFFFFFFFFFFFFFFE (in case th was 0x7FFFFFFFFFFFFFFF) */ \ c2 += (th2 < th); /* never overflows by contract (verified the next line) */ \ @@ -279,7 +381,7 @@ static int rustsecp256k1zkp_v0_8_0_scalar_cond_negate(rustsecp256k1zkp_v0_8_0_sc VERIFY_CHECK(c2 == 0); \ } -static void rustsecp256k1zkp_v0_8_0_scalar_reduce_512(rustsecp256k1zkp_v0_8_0_scalar *r, const uint64_t *l) { +static void rustsecp256k1zkp_v0_10_0_scalar_reduce_512(rustsecp256k1zkp_v0_10_0_scalar *r, const uint64_t *l) { #ifdef USE_ASM_X86_64 /* Reduce 512 bits into 385. */ uint64_t m0, m1, m2, m3, m4, m5, m6; @@ -387,7 +489,7 @@ static void rustsecp256k1zkp_v0_8_0_scalar_reduce_512(rustsecp256k1zkp_v0_8_0_sc "movq %%r10, %q5\n" /* extract m6 */ "movq %%r8, %q6\n" - : "=g"(m0), "=g"(m1), "=g"(m2), "=g"(m3), "=g"(m4), "=g"(m5), "=g"(m6) + : "=&g"(m0), "=&g"(m1), "=&g"(m2), "=g"(m3), "=g"(m4), "=g"(m5), "=g"(m6) : "S"(l), "i"(SECP256K1_N_C_0), "i"(SECP256K1_N_C_1) : "rax", "rdx", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "cc"); @@ -516,8 +618,8 @@ static void rustsecp256k1zkp_v0_8_0_scalar_reduce_512(rustsecp256k1zkp_v0_8_0_sc : "g"(p0), "g"(p1), "g"(p2), "g"(p3), "g"(p4), "D"(r), "i"(SECP256K1_N_C_0), "i"(SECP256K1_N_C_1) : "rax", "rdx", "r8", "r9", "r10", "cc", "memory"); #else - uint128_t c; - uint64_t c0, c1, c2; + rustsecp256k1zkp_v0_10_0_uint128 c128; + uint64_t c, c0, c1, c2; uint64_t n0 = l[4], n1 = l[5], n2 = l[6], n3 = l[7]; uint64_t m0, m1, m2, m3, m4, m5; uint32_t m6; @@ -574,21 +676,25 @@ static void rustsecp256k1zkp_v0_8_0_scalar_reduce_512(rustsecp256k1zkp_v0_8_0_sc /* Reduce 258 bits into 256. */ /* r[0..3] = p[0..3] + p[4] * SECP256K1_N_C. */ - c = p0 + (uint128_t)SECP256K1_N_C_0 * p4; - r->d[0] = c & 0xFFFFFFFFFFFFFFFFULL; c >>= 64; - c += p1 + (uint128_t)SECP256K1_N_C_1 * p4; - r->d[1] = c & 0xFFFFFFFFFFFFFFFFULL; c >>= 64; - c += p2 + (uint128_t)p4; - r->d[2] = c & 0xFFFFFFFFFFFFFFFFULL; c >>= 64; - c += p3; - r->d[3] = c & 0xFFFFFFFFFFFFFFFFULL; c >>= 64; + rustsecp256k1zkp_v0_10_0_u128_from_u64(&c128, p0); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&c128, SECP256K1_N_C_0, p4); + r->d[0] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&c128); rustsecp256k1zkp_v0_10_0_u128_rshift(&c128, 64); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&c128, p1); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&c128, SECP256K1_N_C_1, p4); + r->d[1] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&c128); rustsecp256k1zkp_v0_10_0_u128_rshift(&c128, 64); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&c128, p2); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&c128, p4); + r->d[2] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&c128); rustsecp256k1zkp_v0_10_0_u128_rshift(&c128, 64); + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&c128, p3); + r->d[3] = rustsecp256k1zkp_v0_10_0_u128_to_u64(&c128); + c = rustsecp256k1zkp_v0_10_0_u128_hi_u64(&c128); #endif /* Final reduction of r. */ - rustsecp256k1zkp_v0_8_0_scalar_reduce(r, c + rustsecp256k1zkp_v0_8_0_scalar_check_overflow(r)); + rustsecp256k1zkp_v0_10_0_scalar_reduce(r, c + rustsecp256k1zkp_v0_10_0_scalar_check_overflow(r)); } -static void rustsecp256k1zkp_v0_8_0_scalar_mul_512(uint64_t l[8], const rustsecp256k1zkp_v0_8_0_scalar *a, const rustsecp256k1zkp_v0_8_0_scalar *b) { +static void rustsecp256k1zkp_v0_10_0_scalar_mul_512(uint64_t l[8], const rustsecp256k1zkp_v0_10_0_scalar *a, const rustsecp256k1zkp_v0_10_0_scalar *b) { #ifdef USE_ASM_X86_64 const uint64_t *pb = b->d; __asm__ __volatile__( @@ -755,7 +861,7 @@ static void rustsecp256k1zkp_v0_8_0_scalar_mul_512(uint64_t l[8], const rustsecp #endif } -static void rustsecp256k1zkp_v0_8_0_scalar_sqr_512(uint64_t l[8], const rustsecp256k1zkp_v0_8_0_scalar *a) { +static void rustsecp256k1zkp_v0_10_0_scalar_sqr_512(uint64_t l[8], const rustsecp256k1zkp_v0_10_0_scalar *a) { #ifdef USE_ASM_X86_64 __asm__ __volatile__( /* Preload */ @@ -900,31 +1006,26 @@ static void rustsecp256k1zkp_v0_8_0_scalar_sqr_512(uint64_t l[8], const rustsecp #undef extract #undef extract_fast -static void rustsecp256k1zkp_v0_8_0_scalar_mul(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a, const rustsecp256k1zkp_v0_8_0_scalar *b) { +static void rustsecp256k1zkp_v0_10_0_scalar_mul(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a, const rustsecp256k1zkp_v0_10_0_scalar *b) { uint64_t l[8]; - rustsecp256k1zkp_v0_8_0_scalar_mul_512(l, a, b); - rustsecp256k1zkp_v0_8_0_scalar_reduce_512(r, l); -} + SECP256K1_SCALAR_VERIFY(a); + SECP256K1_SCALAR_VERIFY(b); -static int rustsecp256k1zkp_v0_8_0_scalar_shr_int(rustsecp256k1zkp_v0_8_0_scalar *r, int n) { - int ret; - VERIFY_CHECK(n > 0); - VERIFY_CHECK(n < 16); - ret = r->d[0] & ((1 << n) - 1); - r->d[0] = (r->d[0] >> n) + (r->d[1] << (64 - n)); - r->d[1] = (r->d[1] >> n) + (r->d[2] << (64 - n)); - r->d[2] = (r->d[2] >> n) + (r->d[3] << (64 - n)); - r->d[3] = (r->d[3] >> n); - return ret; + rustsecp256k1zkp_v0_10_0_scalar_mul_512(l, a, b); + rustsecp256k1zkp_v0_10_0_scalar_reduce_512(r, l); + + SECP256K1_SCALAR_VERIFY(r); } -static void rustsecp256k1zkp_v0_8_0_scalar_sqr(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a) { +static void rustsecp256k1zkp_v0_10_0_scalar_sqr(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a) { uint64_t l[8]; - rustsecp256k1zkp_v0_8_0_scalar_sqr_512(l, a); - rustsecp256k1zkp_v0_8_0_scalar_reduce_512(r, l); + rustsecp256k1zkp_v0_10_0_scalar_sqr_512(l, a); + rustsecp256k1zkp_v0_10_0_scalar_reduce_512(r, l); } -static void rustsecp256k1zkp_v0_8_0_scalar_split_128(rustsecp256k1zkp_v0_8_0_scalar *r1, rustsecp256k1zkp_v0_8_0_scalar *r2, const rustsecp256k1zkp_v0_8_0_scalar *k) { +static void rustsecp256k1zkp_v0_10_0_scalar_split_128(rustsecp256k1zkp_v0_10_0_scalar *r1, rustsecp256k1zkp_v0_10_0_scalar *r2, const rustsecp256k1zkp_v0_10_0_scalar *k) { + SECP256K1_SCALAR_VERIFY(k); + r1->d[0] = k->d[0]; r1->d[1] = k->d[1]; r1->d[2] = 0; @@ -933,19 +1034,28 @@ static void rustsecp256k1zkp_v0_8_0_scalar_split_128(rustsecp256k1zkp_v0_8_0_sca r2->d[1] = k->d[3]; r2->d[2] = 0; r2->d[3] = 0; + + SECP256K1_SCALAR_VERIFY(r1); + SECP256K1_SCALAR_VERIFY(r2); } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_scalar_eq(const rustsecp256k1zkp_v0_8_0_scalar *a, const rustsecp256k1zkp_v0_8_0_scalar *b) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_scalar_eq(const rustsecp256k1zkp_v0_10_0_scalar *a, const rustsecp256k1zkp_v0_10_0_scalar *b) { + SECP256K1_SCALAR_VERIFY(a); + SECP256K1_SCALAR_VERIFY(b); + return ((a->d[0] ^ b->d[0]) | (a->d[1] ^ b->d[1]) | (a->d[2] ^ b->d[2]) | (a->d[3] ^ b->d[3])) == 0; } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_scalar_mul_shift_var(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a, const rustsecp256k1zkp_v0_8_0_scalar *b, unsigned int shift) { +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_scalar_mul_shift_var(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a, const rustsecp256k1zkp_v0_10_0_scalar *b, unsigned int shift) { uint64_t l[8]; unsigned int shiftlimbs; unsigned int shiftlow; unsigned int shifthigh; + SECP256K1_SCALAR_VERIFY(a); + SECP256K1_SCALAR_VERIFY(b); VERIFY_CHECK(shift >= 256); - rustsecp256k1zkp_v0_8_0_scalar_mul_512(l, a, b); + + rustsecp256k1zkp_v0_10_0_scalar_mul_512(l, a, b); shiftlimbs = shift >> 6; shiftlow = shift & 0x3F; shifthigh = 64 - shiftlow; @@ -953,111 +1063,31 @@ SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_scalar_mul_shift_var(rustse r->d[1] = shift < 448 ? (l[1 + shiftlimbs] >> shiftlow | (shift < 384 && shiftlow ? (l[2 + shiftlimbs] << shifthigh) : 0)) : 0; r->d[2] = shift < 384 ? (l[2 + shiftlimbs] >> shiftlow | (shift < 320 && shiftlow ? (l[3 + shiftlimbs] << shifthigh) : 0)) : 0; r->d[3] = shift < 320 ? (l[3 + shiftlimbs] >> shiftlow) : 0; - rustsecp256k1zkp_v0_8_0_scalar_cadd_bit(r, 0, (l[(shift - 1) >> 6] >> ((shift - 1) & 0x3f)) & 1); + rustsecp256k1zkp_v0_10_0_scalar_cadd_bit(r, 0, (l[(shift - 1) >> 6] >> ((shift - 1) & 0x3f)) & 1); + + SECP256K1_SCALAR_VERIFY(r); } -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_scalar_cmov(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a, int flag) { +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_scalar_cmov(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a, int flag) { uint64_t mask0, mask1; - VG_CHECK_VERIFY(r->d, sizeof(r->d)); - mask0 = flag + ~((uint64_t)0); + volatile int vflag = flag; + SECP256K1_SCALAR_VERIFY(a); + SECP256K1_CHECKMEM_CHECK_VERIFY(r->d, sizeof(r->d)); + + mask0 = vflag + ~((uint64_t)0); mask1 = ~mask0; r->d[0] = (r->d[0] & mask0) | (a->d[0] & mask1); r->d[1] = (r->d[1] & mask0) | (a->d[1] & mask1); r->d[2] = (r->d[2] & mask0) | (a->d[2] & mask1); r->d[3] = (r->d[3] & mask0) | (a->d[3] & mask1); -} -#define ROTL32(x,n) ((x) << (n) | (x) >> (32-(n))) -#define QUARTERROUND(a,b,c,d) \ - a += b; d = ROTL32(d ^ a, 16); \ - c += d; b = ROTL32(b ^ c, 12); \ - a += b; d = ROTL32(d ^ a, 8); \ - c += d; b = ROTL32(b ^ c, 7); - -#if defined(SECP256K1_BIG_ENDIAN) -#define LE32(p) ((((p) & 0xFF) << 24) | (((p) & 0xFF00) << 8) | (((p) & 0xFF0000) >> 8) | (((p) & 0xFF000000) >> 24)) -#elif defined(SECP256K1_LITTLE_ENDIAN) -#define LE32(p) (p) -#endif - -static void rustsecp256k1zkp_v0_8_0_scalar_chacha20(rustsecp256k1zkp_v0_8_0_scalar *r1, rustsecp256k1zkp_v0_8_0_scalar *r2, const unsigned char *seed, uint64_t idx) { - size_t n; - size_t over_count = 0; - uint32_t seed32[8]; - uint32_t x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15; - int over1, over2; - - memcpy((void *) seed32, (const void *) seed, 32); - do { - x0 = 0x61707865; - x1 = 0x3320646e; - x2 = 0x79622d32; - x3 = 0x6b206574; - x4 = LE32(seed32[0]); - x5 = LE32(seed32[1]); - x6 = LE32(seed32[2]); - x7 = LE32(seed32[3]); - x8 = LE32(seed32[4]); - x9 = LE32(seed32[5]); - x10 = LE32(seed32[6]); - x11 = LE32(seed32[7]); - x12 = idx; - x13 = idx >> 32; - x14 = 0; - x15 = over_count; - - n = 10; - while (n--) { - QUARTERROUND(x0, x4, x8,x12) - QUARTERROUND(x1, x5, x9,x13) - QUARTERROUND(x2, x6,x10,x14) - QUARTERROUND(x3, x7,x11,x15) - QUARTERROUND(x0, x5,x10,x15) - QUARTERROUND(x1, x6,x11,x12) - QUARTERROUND(x2, x7, x8,x13) - QUARTERROUND(x3, x4, x9,x14) - } - - x0 += 0x61707865; - x1 += 0x3320646e; - x2 += 0x79622d32; - x3 += 0x6b206574; - x4 += LE32(seed32[0]); - x5 += LE32(seed32[1]); - x6 += LE32(seed32[2]); - x7 += LE32(seed32[3]); - x8 += LE32(seed32[4]); - x9 += LE32(seed32[5]); - x10 += LE32(seed32[6]); - x11 += LE32(seed32[7]); - x12 += idx; - x13 += idx >> 32; - x14 += 0; - x15 += over_count; - - r1->d[3] = (((uint64_t) x0) << 32) | x1; - r1->d[2] = (((uint64_t) x2) << 32) | x3; - r1->d[1] = (((uint64_t) x4) << 32) | x5; - r1->d[0] = (((uint64_t) x6) << 32) | x7; - r2->d[3] = (((uint64_t) x8) << 32) | x9; - r2->d[2] = (((uint64_t) x10) << 32) | x11; - r2->d[1] = (((uint64_t) x12) << 32) | x13; - r2->d[0] = (((uint64_t) x14) << 32) | x15; - - over1 = rustsecp256k1zkp_v0_8_0_scalar_check_overflow(r1); - over2 = rustsecp256k1zkp_v0_8_0_scalar_check_overflow(r2); - over_count++; - } while (over1 | over2); + SECP256K1_SCALAR_VERIFY(r); } -#undef ROTL32 -#undef QUARTERROUND -#undef LE32 - -static void rustsecp256k1zkp_v0_8_0_scalar_from_signed62(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_modinv64_signed62 *a) { +static void rustsecp256k1zkp_v0_10_0_scalar_from_signed62(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_modinv64_signed62 *a) { const uint64_t a0 = a->v[0], a1 = a->v[1], a2 = a->v[2], a3 = a->v[3], a4 = a->v[4]; - /* The output from rustsecp256k1zkp_v0_8_0_modinv64{_var} should be normalized to range [0,modulus), and + /* The output from rustsecp256k1zkp_v0_10_0_modinv64{_var} should be normalized to range [0,modulus), and * have limbs in [0,2^62). The modulus is < 2^256, so the top limb must be below 2^(256-62*4). */ VERIFY_CHECK(a0 >> 62 == 0); @@ -1071,18 +1101,13 @@ static void rustsecp256k1zkp_v0_8_0_scalar_from_signed62(rustsecp256k1zkp_v0_8_0 r->d[2] = a2 >> 4 | a3 << 58; r->d[3] = a3 >> 6 | a4 << 56; -#ifdef VERIFY - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_scalar_check_overflow(r) == 0); -#endif + SECP256K1_SCALAR_VERIFY(r); } -static void rustsecp256k1zkp_v0_8_0_scalar_to_signed62(rustsecp256k1zkp_v0_8_0_modinv64_signed62 *r, const rustsecp256k1zkp_v0_8_0_scalar *a) { +static void rustsecp256k1zkp_v0_10_0_scalar_to_signed62(rustsecp256k1zkp_v0_10_0_modinv64_signed62 *r, const rustsecp256k1zkp_v0_10_0_scalar *a) { const uint64_t M62 = UINT64_MAX >> 2; const uint64_t a0 = a->d[0], a1 = a->d[1], a2 = a->d[2], a3 = a->d[3]; - -#ifdef VERIFY - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_scalar_check_overflow(a) == 0); -#endif + SECP256K1_SCALAR_VERIFY(a); r->v[0] = a0 & M62; r->v[1] = (a0 >> 62 | a1 << 2) & M62; @@ -1091,40 +1116,44 @@ static void rustsecp256k1zkp_v0_8_0_scalar_to_signed62(rustsecp256k1zkp_v0_8_0_m r->v[4] = a3 >> 56; } -static const rustsecp256k1zkp_v0_8_0_modinv64_modinfo rustsecp256k1zkp_v0_8_0_const_modinfo_scalar = { +static const rustsecp256k1zkp_v0_10_0_modinv64_modinfo rustsecp256k1zkp_v0_10_0_const_modinfo_scalar = { {{0x3FD25E8CD0364141LL, 0x2ABB739ABD2280EELL, -0x15LL, 0, 256}}, 0x34F20099AA774EC1LL }; -static void rustsecp256k1zkp_v0_8_0_scalar_inverse(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *x) { - rustsecp256k1zkp_v0_8_0_modinv64_signed62 s; +static void rustsecp256k1zkp_v0_10_0_scalar_inverse(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *x) { + rustsecp256k1zkp_v0_10_0_modinv64_signed62 s; #ifdef VERIFY - int zero_in = rustsecp256k1zkp_v0_8_0_scalar_is_zero(x); + int zero_in = rustsecp256k1zkp_v0_10_0_scalar_is_zero(x); #endif - rustsecp256k1zkp_v0_8_0_scalar_to_signed62(&s, x); - rustsecp256k1zkp_v0_8_0_modinv64(&s, &rustsecp256k1zkp_v0_8_0_const_modinfo_scalar); - rustsecp256k1zkp_v0_8_0_scalar_from_signed62(r, &s); + SECP256K1_SCALAR_VERIFY(x); -#ifdef VERIFY - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_scalar_is_zero(r) == zero_in); -#endif + rustsecp256k1zkp_v0_10_0_scalar_to_signed62(&s, x); + rustsecp256k1zkp_v0_10_0_modinv64(&s, &rustsecp256k1zkp_v0_10_0_const_modinfo_scalar); + rustsecp256k1zkp_v0_10_0_scalar_from_signed62(r, &s); + + SECP256K1_SCALAR_VERIFY(r); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_scalar_is_zero(r) == zero_in); } -static void rustsecp256k1zkp_v0_8_0_scalar_inverse_var(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *x) { - rustsecp256k1zkp_v0_8_0_modinv64_signed62 s; +static void rustsecp256k1zkp_v0_10_0_scalar_inverse_var(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *x) { + rustsecp256k1zkp_v0_10_0_modinv64_signed62 s; #ifdef VERIFY - int zero_in = rustsecp256k1zkp_v0_8_0_scalar_is_zero(x); + int zero_in = rustsecp256k1zkp_v0_10_0_scalar_is_zero(x); #endif - rustsecp256k1zkp_v0_8_0_scalar_to_signed62(&s, x); - rustsecp256k1zkp_v0_8_0_modinv64_var(&s, &rustsecp256k1zkp_v0_8_0_const_modinfo_scalar); - rustsecp256k1zkp_v0_8_0_scalar_from_signed62(r, &s); + SECP256K1_SCALAR_VERIFY(x); -#ifdef VERIFY - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_scalar_is_zero(r) == zero_in); -#endif + rustsecp256k1zkp_v0_10_0_scalar_to_signed62(&s, x); + rustsecp256k1zkp_v0_10_0_modinv64_var(&s, &rustsecp256k1zkp_v0_10_0_const_modinfo_scalar); + rustsecp256k1zkp_v0_10_0_scalar_from_signed62(r, &s); + + SECP256K1_SCALAR_VERIFY(r); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_scalar_is_zero(r) == zero_in); } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_scalar_is_even(const rustsecp256k1zkp_v0_8_0_scalar *a) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_scalar_is_even(const rustsecp256k1zkp_v0_10_0_scalar *a) { + SECP256K1_SCALAR_VERIFY(a); + return !(a->d[0] & 1); } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/scalar_8x32.h b/secp256k1-zkp-sys/depend/secp256k1/src/scalar_8x32.h index 2e70db25..74c0d98b 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/scalar_8x32.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/scalar_8x32.h @@ -12,7 +12,7 @@ /** A scalar modulo the group order of the secp256k1 curve. */ typedef struct { uint32_t d[8]; -} rustsecp256k1zkp_v0_8_0_scalar; +} rustsecp256k1zkp_v0_10_0_scalar; #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{(d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7)}} diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/scalar_8x32_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/scalar_8x32_impl.h index 0ce9a058..a94ce892 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/scalar_8x32_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/scalar_8x32_impl.h @@ -9,7 +9,9 @@ #include +#include "checkmem.h" #include "modinv32_impl.h" +#include "util.h" /* Limbs of the secp256k1 order. */ #define SECP256K1_N_0 ((uint32_t)0xD0364141UL) @@ -38,7 +40,7 @@ #define SECP256K1_N_H_6 ((uint32_t)0xFFFFFFFFUL) #define SECP256K1_N_H_7 ((uint32_t)0x7FFFFFFFUL) -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_scalar_clear(rustsecp256k1zkp_v0_8_0_scalar *r) { +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_scalar_clear(rustsecp256k1zkp_v0_10_0_scalar *r) { r->d[0] = 0; r->d[1] = 0; r->d[2] = 0; @@ -49,7 +51,7 @@ SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_scalar_clear(rustsecp256k1z r->d[7] = 0; } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_scalar_set_int(rustsecp256k1zkp_v0_8_0_scalar *r, unsigned int v) { +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_scalar_set_int(rustsecp256k1zkp_v0_10_0_scalar *r, unsigned int v) { r->d[0] = v; r->d[1] = 0; r->d[2] = 0; @@ -58,9 +60,11 @@ SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_scalar_set_int(rustsecp256k r->d[5] = 0; r->d[6] = 0; r->d[7] = 0; + + SECP256K1_SCALAR_VERIFY(r); } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_scalar_set_u64(rustsecp256k1zkp_v0_8_0_scalar *r, uint64_t v) { +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_scalar_set_u64(rustsecp256k1zkp_v0_10_0_scalar *r, uint64_t v) { r->d[0] = v; r->d[1] = v >> 32; r->d[2] = 0; @@ -71,23 +75,27 @@ SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_scalar_set_u64(rustsecp256k r->d[7] = 0; } -SECP256K1_INLINE static unsigned int rustsecp256k1zkp_v0_8_0_scalar_get_bits(const rustsecp256k1zkp_v0_8_0_scalar *a, unsigned int offset, unsigned int count) { +SECP256K1_INLINE static unsigned int rustsecp256k1zkp_v0_10_0_scalar_get_bits(const rustsecp256k1zkp_v0_10_0_scalar *a, unsigned int offset, unsigned int count) { + SECP256K1_SCALAR_VERIFY(a); VERIFY_CHECK((offset + count - 1) >> 5 == offset >> 5); + return (a->d[offset >> 5] >> (offset & 0x1F)) & ((1 << count) - 1); } -SECP256K1_INLINE static unsigned int rustsecp256k1zkp_v0_8_0_scalar_get_bits_var(const rustsecp256k1zkp_v0_8_0_scalar *a, unsigned int offset, unsigned int count) { +SECP256K1_INLINE static unsigned int rustsecp256k1zkp_v0_10_0_scalar_get_bits_var(const rustsecp256k1zkp_v0_10_0_scalar *a, unsigned int offset, unsigned int count) { + SECP256K1_SCALAR_VERIFY(a); VERIFY_CHECK(count < 32); VERIFY_CHECK(offset + count <= 256); + if ((offset + count - 1) >> 5 == offset >> 5) { - return rustsecp256k1zkp_v0_8_0_scalar_get_bits(a, offset, count); + return rustsecp256k1zkp_v0_10_0_scalar_get_bits(a, offset, count); } else { VERIFY_CHECK((offset >> 5) + 1 < 8); return ((a->d[offset >> 5] >> (offset & 0x1F)) | (a->d[(offset >> 5) + 1] << (32 - (offset & 0x1F)))) & ((((uint32_t)1) << count) - 1); } } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_scalar_check_overflow(const rustsecp256k1zkp_v0_8_0_scalar *a) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_scalar_check_overflow(const rustsecp256k1zkp_v0_10_0_scalar *a) { int yes = 0; int no = 0; no |= (a->d[7] < SECP256K1_N_7); /* No need for a > check. */ @@ -105,9 +113,10 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_scalar_check_overflow(const return yes; } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_scalar_reduce(rustsecp256k1zkp_v0_8_0_scalar *r, uint32_t overflow) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_scalar_reduce(rustsecp256k1zkp_v0_10_0_scalar *r, uint32_t overflow) { uint64_t t; VERIFY_CHECK(overflow <= 1); + t = (uint64_t)r->d[0] + overflow * SECP256K1_N_C_0; r->d[0] = t & 0xFFFFFFFFUL; t >>= 32; t += (uint64_t)r->d[1] + overflow * SECP256K1_N_C_1; @@ -124,12 +133,17 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_scalar_reduce(rustsecp256k1z r->d[6] = t & 0xFFFFFFFFUL; t >>= 32; t += (uint64_t)r->d[7]; r->d[7] = t & 0xFFFFFFFFUL; + + SECP256K1_SCALAR_VERIFY(r); return overflow; } -static int rustsecp256k1zkp_v0_8_0_scalar_add(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a, const rustsecp256k1zkp_v0_8_0_scalar *b) { +static int rustsecp256k1zkp_v0_10_0_scalar_add(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a, const rustsecp256k1zkp_v0_10_0_scalar *b) { int overflow; uint64_t t = (uint64_t)a->d[0] + b->d[0]; + SECP256K1_SCALAR_VERIFY(a); + SECP256K1_SCALAR_VERIFY(b); + r->d[0] = t & 0xFFFFFFFFULL; t >>= 32; t += (uint64_t)a->d[1] + b->d[1]; r->d[1] = t & 0xFFFFFFFFULL; t >>= 32; @@ -145,16 +159,21 @@ static int rustsecp256k1zkp_v0_8_0_scalar_add(rustsecp256k1zkp_v0_8_0_scalar *r, r->d[6] = t & 0xFFFFFFFFULL; t >>= 32; t += (uint64_t)a->d[7] + b->d[7]; r->d[7] = t & 0xFFFFFFFFULL; t >>= 32; - overflow = t + rustsecp256k1zkp_v0_8_0_scalar_check_overflow(r); + overflow = t + rustsecp256k1zkp_v0_10_0_scalar_check_overflow(r); VERIFY_CHECK(overflow == 0 || overflow == 1); - rustsecp256k1zkp_v0_8_0_scalar_reduce(r, overflow); + rustsecp256k1zkp_v0_10_0_scalar_reduce(r, overflow); + + SECP256K1_SCALAR_VERIFY(r); return overflow; } -static void rustsecp256k1zkp_v0_8_0_scalar_cadd_bit(rustsecp256k1zkp_v0_8_0_scalar *r, unsigned int bit, int flag) { +static void rustsecp256k1zkp_v0_10_0_scalar_cadd_bit(rustsecp256k1zkp_v0_10_0_scalar *r, unsigned int bit, int flag) { uint64_t t; + volatile int vflag = flag; + SECP256K1_SCALAR_VERIFY(r); VERIFY_CHECK(bit < 256); - bit += ((uint32_t) flag - 1) & 0x100; /* forcing (bit >> 5) > 7 makes this a noop */ + + bit += ((uint32_t) vflag - 1) & 0x100; /* forcing (bit >> 5) > 7 makes this a noop */ t = (uint64_t)r->d[0] + (((uint32_t)((bit >> 5) == 0)) << (bit & 0x1F)); r->d[0] = t & 0xFFFFFFFFULL; t >>= 32; t += (uint64_t)r->d[1] + (((uint32_t)((bit >> 5) == 1)) << (bit & 0x1F)); @@ -171,46 +190,53 @@ static void rustsecp256k1zkp_v0_8_0_scalar_cadd_bit(rustsecp256k1zkp_v0_8_0_scal r->d[6] = t & 0xFFFFFFFFULL; t >>= 32; t += (uint64_t)r->d[7] + (((uint32_t)((bit >> 5) == 7)) << (bit & 0x1F)); r->d[7] = t & 0xFFFFFFFFULL; -#ifdef VERIFY + + SECP256K1_SCALAR_VERIFY(r); VERIFY_CHECK((t >> 32) == 0); - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_scalar_check_overflow(r) == 0); -#endif } -static void rustsecp256k1zkp_v0_8_0_scalar_set_b32(rustsecp256k1zkp_v0_8_0_scalar *r, const unsigned char *b32, int *overflow) { +static void rustsecp256k1zkp_v0_10_0_scalar_set_b32(rustsecp256k1zkp_v0_10_0_scalar *r, const unsigned char *b32, int *overflow) { int over; - r->d[0] = (uint32_t)b32[31] | (uint32_t)b32[30] << 8 | (uint32_t)b32[29] << 16 | (uint32_t)b32[28] << 24; - r->d[1] = (uint32_t)b32[27] | (uint32_t)b32[26] << 8 | (uint32_t)b32[25] << 16 | (uint32_t)b32[24] << 24; - r->d[2] = (uint32_t)b32[23] | (uint32_t)b32[22] << 8 | (uint32_t)b32[21] << 16 | (uint32_t)b32[20] << 24; - r->d[3] = (uint32_t)b32[19] | (uint32_t)b32[18] << 8 | (uint32_t)b32[17] << 16 | (uint32_t)b32[16] << 24; - r->d[4] = (uint32_t)b32[15] | (uint32_t)b32[14] << 8 | (uint32_t)b32[13] << 16 | (uint32_t)b32[12] << 24; - r->d[5] = (uint32_t)b32[11] | (uint32_t)b32[10] << 8 | (uint32_t)b32[9] << 16 | (uint32_t)b32[8] << 24; - r->d[6] = (uint32_t)b32[7] | (uint32_t)b32[6] << 8 | (uint32_t)b32[5] << 16 | (uint32_t)b32[4] << 24; - r->d[7] = (uint32_t)b32[3] | (uint32_t)b32[2] << 8 | (uint32_t)b32[1] << 16 | (uint32_t)b32[0] << 24; - over = rustsecp256k1zkp_v0_8_0_scalar_reduce(r, rustsecp256k1zkp_v0_8_0_scalar_check_overflow(r)); + r->d[0] = rustsecp256k1zkp_v0_10_0_read_be32(&b32[28]); + r->d[1] = rustsecp256k1zkp_v0_10_0_read_be32(&b32[24]); + r->d[2] = rustsecp256k1zkp_v0_10_0_read_be32(&b32[20]); + r->d[3] = rustsecp256k1zkp_v0_10_0_read_be32(&b32[16]); + r->d[4] = rustsecp256k1zkp_v0_10_0_read_be32(&b32[12]); + r->d[5] = rustsecp256k1zkp_v0_10_0_read_be32(&b32[8]); + r->d[6] = rustsecp256k1zkp_v0_10_0_read_be32(&b32[4]); + r->d[7] = rustsecp256k1zkp_v0_10_0_read_be32(&b32[0]); + over = rustsecp256k1zkp_v0_10_0_scalar_reduce(r, rustsecp256k1zkp_v0_10_0_scalar_check_overflow(r)); if (overflow) { *overflow = over; } + + SECP256K1_SCALAR_VERIFY(r); } -static void rustsecp256k1zkp_v0_8_0_scalar_get_b32(unsigned char *bin, const rustsecp256k1zkp_v0_8_0_scalar* a) { - bin[0] = a->d[7] >> 24; bin[1] = a->d[7] >> 16; bin[2] = a->d[7] >> 8; bin[3] = a->d[7]; - bin[4] = a->d[6] >> 24; bin[5] = a->d[6] >> 16; bin[6] = a->d[6] >> 8; bin[7] = a->d[6]; - bin[8] = a->d[5] >> 24; bin[9] = a->d[5] >> 16; bin[10] = a->d[5] >> 8; bin[11] = a->d[5]; - bin[12] = a->d[4] >> 24; bin[13] = a->d[4] >> 16; bin[14] = a->d[4] >> 8; bin[15] = a->d[4]; - bin[16] = a->d[3] >> 24; bin[17] = a->d[3] >> 16; bin[18] = a->d[3] >> 8; bin[19] = a->d[3]; - bin[20] = a->d[2] >> 24; bin[21] = a->d[2] >> 16; bin[22] = a->d[2] >> 8; bin[23] = a->d[2]; - bin[24] = a->d[1] >> 24; bin[25] = a->d[1] >> 16; bin[26] = a->d[1] >> 8; bin[27] = a->d[1]; - bin[28] = a->d[0] >> 24; bin[29] = a->d[0] >> 16; bin[30] = a->d[0] >> 8; bin[31] = a->d[0]; +static void rustsecp256k1zkp_v0_10_0_scalar_get_b32(unsigned char *bin, const rustsecp256k1zkp_v0_10_0_scalar* a) { + SECP256K1_SCALAR_VERIFY(a); + + rustsecp256k1zkp_v0_10_0_write_be32(&bin[0], a->d[7]); + rustsecp256k1zkp_v0_10_0_write_be32(&bin[4], a->d[6]); + rustsecp256k1zkp_v0_10_0_write_be32(&bin[8], a->d[5]); + rustsecp256k1zkp_v0_10_0_write_be32(&bin[12], a->d[4]); + rustsecp256k1zkp_v0_10_0_write_be32(&bin[16], a->d[3]); + rustsecp256k1zkp_v0_10_0_write_be32(&bin[20], a->d[2]); + rustsecp256k1zkp_v0_10_0_write_be32(&bin[24], a->d[1]); + rustsecp256k1zkp_v0_10_0_write_be32(&bin[28], a->d[0]); } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_scalar_is_zero(const rustsecp256k1zkp_v0_8_0_scalar *a) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_scalar_is_zero(const rustsecp256k1zkp_v0_10_0_scalar *a) { + SECP256K1_SCALAR_VERIFY(a); + return (a->d[0] | a->d[1] | a->d[2] | a->d[3] | a->d[4] | a->d[5] | a->d[6] | a->d[7]) == 0; } -static void rustsecp256k1zkp_v0_8_0_scalar_negate(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a) { - uint32_t nonzero = 0xFFFFFFFFUL * (rustsecp256k1zkp_v0_8_0_scalar_is_zero(a) == 0); +static void rustsecp256k1zkp_v0_10_0_scalar_negate(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a) { + uint32_t nonzero = 0xFFFFFFFFUL * (rustsecp256k1zkp_v0_10_0_scalar_is_zero(a) == 0); uint64_t t = (uint64_t)(~a->d[0]) + SECP256K1_N_0 + 1; + SECP256K1_SCALAR_VERIFY(a); + r->d[0] = t & nonzero; t >>= 32; t += (uint64_t)(~a->d[1]) + SECP256K1_N_1; r->d[1] = t & nonzero; t >>= 32; @@ -226,15 +252,69 @@ static void rustsecp256k1zkp_v0_8_0_scalar_negate(rustsecp256k1zkp_v0_8_0_scalar r->d[6] = t & nonzero; t >>= 32; t += (uint64_t)(~a->d[7]) + SECP256K1_N_7; r->d[7] = t & nonzero; -} -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_scalar_is_one(const rustsecp256k1zkp_v0_8_0_scalar *a) { + SECP256K1_SCALAR_VERIFY(r); +} + +static void rustsecp256k1zkp_v0_10_0_scalar_half(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a) { + /* Writing `/` for field division and `//` for integer division, we compute + * + * a/2 = (a - (a&1))/2 + (a&1)/2 + * = (a >> 1) + (a&1 ? 1/2 : 0) + * = (a >> 1) + (a&1 ? n//2+1 : 0), + * + * where n is the group order and in the last equality we have used 1/2 = n//2+1 (mod n). + * For n//2, we have the constants SECP256K1_N_H_0, ... + * + * This sum does not overflow. The most extreme case is a = -2, the largest odd scalar. Here: + * - the left summand is: a >> 1 = (a - a&1)/2 = (n-2-1)//2 = (n-3)//2 + * - the right summand is: a&1 ? n//2+1 : 0 = n//2+1 = (n-1)//2 + 2//2 = (n+1)//2 + * Together they sum to (n-3)//2 + (n+1)//2 = (2n-2)//2 = n - 1, which is less than n. + */ + uint32_t mask = -(uint32_t)(a->d[0] & 1U); + uint64_t t = (uint32_t)((a->d[0] >> 1) | (a->d[1] << 31)); + SECP256K1_SCALAR_VERIFY(a); + + t += (SECP256K1_N_H_0 + 1U) & mask; + r->d[0] = t; t >>= 32; + t += (uint32_t)((a->d[1] >> 1) | (a->d[2] << 31)); + t += SECP256K1_N_H_1 & mask; + r->d[1] = t; t >>= 32; + t += (uint32_t)((a->d[2] >> 1) | (a->d[3] << 31)); + t += SECP256K1_N_H_2 & mask; + r->d[2] = t; t >>= 32; + t += (uint32_t)((a->d[3] >> 1) | (a->d[4] << 31)); + t += SECP256K1_N_H_3 & mask; + r->d[3] = t; t >>= 32; + t += (uint32_t)((a->d[4] >> 1) | (a->d[5] << 31)); + t += SECP256K1_N_H_4 & mask; + r->d[4] = t; t >>= 32; + t += (uint32_t)((a->d[5] >> 1) | (a->d[6] << 31)); + t += SECP256K1_N_H_5 & mask; + r->d[5] = t; t >>= 32; + t += (uint32_t)((a->d[6] >> 1) | (a->d[7] << 31)); + t += SECP256K1_N_H_6 & mask; + r->d[6] = t; t >>= 32; + r->d[7] = (uint32_t)t + (uint32_t)(a->d[7] >> 1) + (SECP256K1_N_H_7 & mask); + + /* The line above only computed the bottom 32 bits of r->d[7]. Redo the computation + * in full 64 bits to make sure the top 32 bits are indeed zero. */ + VERIFY_CHECK((t + (a->d[7] >> 1) + (SECP256K1_N_H_7 & mask)) >> 32 == 0); + + SECP256K1_SCALAR_VERIFY(r); +} + +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_scalar_is_one(const rustsecp256k1zkp_v0_10_0_scalar *a) { + SECP256K1_SCALAR_VERIFY(a); + return ((a->d[0] ^ 1) | a->d[1] | a->d[2] | a->d[3] | a->d[4] | a->d[5] | a->d[6] | a->d[7]) == 0; } -static int rustsecp256k1zkp_v0_8_0_scalar_is_high(const rustsecp256k1zkp_v0_8_0_scalar *a) { +static int rustsecp256k1zkp_v0_10_0_scalar_is_high(const rustsecp256k1zkp_v0_10_0_scalar *a) { int yes = 0; int no = 0; + SECP256K1_SCALAR_VERIFY(a); + no |= (a->d[7] < SECP256K1_N_H_7); yes |= (a->d[7] > SECP256K1_N_H_7) & ~no; no |= (a->d[6] < SECP256K1_N_H_6) & ~yes; /* No need for a > check. */ @@ -250,12 +330,15 @@ static int rustsecp256k1zkp_v0_8_0_scalar_is_high(const rustsecp256k1zkp_v0_8_0_ return yes; } -static int rustsecp256k1zkp_v0_8_0_scalar_cond_negate(rustsecp256k1zkp_v0_8_0_scalar *r, int flag) { +static int rustsecp256k1zkp_v0_10_0_scalar_cond_negate(rustsecp256k1zkp_v0_10_0_scalar *r, int flag) { /* If we are flag = 0, mask = 00...00 and this is a no-op; - * if we are flag = 1, mask = 11...11 and this is identical to rustsecp256k1zkp_v0_8_0_scalar_negate */ - uint32_t mask = !flag - 1; - uint32_t nonzero = 0xFFFFFFFFUL * (rustsecp256k1zkp_v0_8_0_scalar_is_zero(r) == 0); + * if we are flag = 1, mask = 11...11 and this is identical to rustsecp256k1zkp_v0_10_0_scalar_negate */ + volatile int vflag = flag; + uint32_t mask = -vflag; + uint32_t nonzero = 0xFFFFFFFFUL * (rustsecp256k1zkp_v0_10_0_scalar_is_zero(r) == 0); uint64_t t = (uint64_t)(r->d[0] ^ mask) + ((SECP256K1_N_0 + 1) & mask); + SECP256K1_SCALAR_VERIFY(r); + r->d[0] = t & nonzero; t >>= 32; t += (uint64_t)(r->d[1] ^ mask) + (SECP256K1_N_1 & mask); r->d[1] = t & nonzero; t >>= 32; @@ -271,6 +354,8 @@ static int rustsecp256k1zkp_v0_8_0_scalar_cond_negate(rustsecp256k1zkp_v0_8_0_sc r->d[6] = t & nonzero; t >>= 32; t += (uint64_t)(r->d[7] ^ mask) + (SECP256K1_N_7 & mask); r->d[7] = t & nonzero; + + SECP256K1_SCALAR_VERIFY(r); return 2 * (mask == 0) - 1; } @@ -361,7 +446,7 @@ static int rustsecp256k1zkp_v0_8_0_scalar_cond_negate(rustsecp256k1zkp_v0_8_0_sc VERIFY_CHECK(c2 == 0); \ } -static void rustsecp256k1zkp_v0_8_0_scalar_reduce_512(rustsecp256k1zkp_v0_8_0_scalar *r, const uint32_t *l) { +static void rustsecp256k1zkp_v0_10_0_scalar_reduce_512(rustsecp256k1zkp_v0_10_0_scalar *r, const uint32_t *l) { uint64_t c; uint32_t n0 = l[8], n1 = l[9], n2 = l[10], n3 = l[11], n4 = l[12], n5 = l[13], n6 = l[14], n7 = l[15]; uint32_t m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12; @@ -500,10 +585,10 @@ static void rustsecp256k1zkp_v0_8_0_scalar_reduce_512(rustsecp256k1zkp_v0_8_0_sc r->d[7] = c & 0xFFFFFFFFUL; c >>= 32; /* Final reduction of r. */ - rustsecp256k1zkp_v0_8_0_scalar_reduce(r, c + rustsecp256k1zkp_v0_8_0_scalar_check_overflow(r)); + rustsecp256k1zkp_v0_10_0_scalar_reduce(r, c + rustsecp256k1zkp_v0_10_0_scalar_check_overflow(r)); } -static void rustsecp256k1zkp_v0_8_0_scalar_mul_512(uint32_t *l, const rustsecp256k1zkp_v0_8_0_scalar *a, const rustsecp256k1zkp_v0_8_0_scalar *b) { +static void rustsecp256k1zkp_v0_10_0_scalar_mul_512(uint32_t *l, const rustsecp256k1zkp_v0_10_0_scalar *a, const rustsecp256k1zkp_v0_10_0_scalar *b) { /* 96 bit accumulator. */ uint32_t c0 = 0, c1 = 0, c2 = 0; @@ -591,7 +676,7 @@ static void rustsecp256k1zkp_v0_8_0_scalar_mul_512(uint32_t *l, const rustsecp25 l[15] = c0; } -static void rustsecp256k1zkp_v0_8_0_scalar_sqr_512(uint32_t *l, const rustsecp256k1zkp_v0_8_0_scalar *a) { +static void rustsecp256k1zkp_v0_10_0_scalar_sqr_512(uint32_t *l, const rustsecp256k1zkp_v0_10_0_scalar *a) { /* 96 bit accumulator. */ uint32_t c0 = 0, c1 = 0, c2 = 0; @@ -659,35 +744,26 @@ static void rustsecp256k1zkp_v0_8_0_scalar_sqr_512(uint32_t *l, const rustsecp25 #undef extract #undef extract_fast -static void rustsecp256k1zkp_v0_8_0_scalar_mul(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a, const rustsecp256k1zkp_v0_8_0_scalar *b) { +static void rustsecp256k1zkp_v0_10_0_scalar_mul(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a, const rustsecp256k1zkp_v0_10_0_scalar *b) { uint32_t l[16]; - rustsecp256k1zkp_v0_8_0_scalar_mul_512(l, a, b); - rustsecp256k1zkp_v0_8_0_scalar_reduce_512(r, l); -} - -static int rustsecp256k1zkp_v0_8_0_scalar_shr_int(rustsecp256k1zkp_v0_8_0_scalar *r, int n) { - int ret; - VERIFY_CHECK(n > 0); - VERIFY_CHECK(n < 16); - ret = r->d[0] & ((1 << n) - 1); - r->d[0] = (r->d[0] >> n) + (r->d[1] << (32 - n)); - r->d[1] = (r->d[1] >> n) + (r->d[2] << (32 - n)); - r->d[2] = (r->d[2] >> n) + (r->d[3] << (32 - n)); - r->d[3] = (r->d[3] >> n) + (r->d[4] << (32 - n)); - r->d[4] = (r->d[4] >> n) + (r->d[5] << (32 - n)); - r->d[5] = (r->d[5] >> n) + (r->d[6] << (32 - n)); - r->d[6] = (r->d[6] >> n) + (r->d[7] << (32 - n)); - r->d[7] = (r->d[7] >> n); - return ret; -} - -static void rustsecp256k1zkp_v0_8_0_scalar_sqr(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a) { + SECP256K1_SCALAR_VERIFY(a); + SECP256K1_SCALAR_VERIFY(b); + + rustsecp256k1zkp_v0_10_0_scalar_mul_512(l, a, b); + rustsecp256k1zkp_v0_10_0_scalar_reduce_512(r, l); + + SECP256K1_SCALAR_VERIFY(r); +} + +static void rustsecp256k1zkp_v0_10_0_scalar_sqr(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a) { uint32_t l[16]; - rustsecp256k1zkp_v0_8_0_scalar_sqr_512(l, a); - rustsecp256k1zkp_v0_8_0_scalar_reduce_512(r, l); + rustsecp256k1zkp_v0_10_0_scalar_sqr_512(l, a); + rustsecp256k1zkp_v0_10_0_scalar_reduce_512(r, l); } -static void rustsecp256k1zkp_v0_8_0_scalar_split_128(rustsecp256k1zkp_v0_8_0_scalar *r1, rustsecp256k1zkp_v0_8_0_scalar *r2, const rustsecp256k1zkp_v0_8_0_scalar *k) { +static void rustsecp256k1zkp_v0_10_0_scalar_split_128(rustsecp256k1zkp_v0_10_0_scalar *r1, rustsecp256k1zkp_v0_10_0_scalar *r2, const rustsecp256k1zkp_v0_10_0_scalar *k) { + SECP256K1_SCALAR_VERIFY(k); + r1->d[0] = k->d[0]; r1->d[1] = k->d[1]; r1->d[2] = k->d[2]; @@ -704,19 +780,28 @@ static void rustsecp256k1zkp_v0_8_0_scalar_split_128(rustsecp256k1zkp_v0_8_0_sca r2->d[5] = 0; r2->d[6] = 0; r2->d[7] = 0; + + SECP256K1_SCALAR_VERIFY(r1); + SECP256K1_SCALAR_VERIFY(r2); } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_scalar_eq(const rustsecp256k1zkp_v0_8_0_scalar *a, const rustsecp256k1zkp_v0_8_0_scalar *b) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_scalar_eq(const rustsecp256k1zkp_v0_10_0_scalar *a, const rustsecp256k1zkp_v0_10_0_scalar *b) { + SECP256K1_SCALAR_VERIFY(a); + SECP256K1_SCALAR_VERIFY(b); + return ((a->d[0] ^ b->d[0]) | (a->d[1] ^ b->d[1]) | (a->d[2] ^ b->d[2]) | (a->d[3] ^ b->d[3]) | (a->d[4] ^ b->d[4]) | (a->d[5] ^ b->d[5]) | (a->d[6] ^ b->d[6]) | (a->d[7] ^ b->d[7])) == 0; } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_scalar_mul_shift_var(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a, const rustsecp256k1zkp_v0_8_0_scalar *b, unsigned int shift) { +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_scalar_mul_shift_var(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a, const rustsecp256k1zkp_v0_10_0_scalar *b, unsigned int shift) { uint32_t l[16]; unsigned int shiftlimbs; unsigned int shiftlow; unsigned int shifthigh; + SECP256K1_SCALAR_VERIFY(a); + SECP256K1_SCALAR_VERIFY(b); VERIFY_CHECK(shift >= 256); - rustsecp256k1zkp_v0_8_0_scalar_mul_512(l, a, b); + + rustsecp256k1zkp_v0_10_0_scalar_mul_512(l, a, b); shiftlimbs = shift >> 5; shiftlow = shift & 0x1F; shifthigh = 32 - shiftlow; @@ -728,13 +813,18 @@ SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_scalar_mul_shift_var(rustse r->d[5] = shift < 352 ? (l[5 + shiftlimbs] >> shiftlow | (shift < 320 && shiftlow ? (l[6 + shiftlimbs] << shifthigh) : 0)) : 0; r->d[6] = shift < 320 ? (l[6 + shiftlimbs] >> shiftlow | (shift < 288 && shiftlow ? (l[7 + shiftlimbs] << shifthigh) : 0)) : 0; r->d[7] = shift < 288 ? (l[7 + shiftlimbs] >> shiftlow) : 0; - rustsecp256k1zkp_v0_8_0_scalar_cadd_bit(r, 0, (l[(shift - 1) >> 5] >> ((shift - 1) & 0x1f)) & 1); + rustsecp256k1zkp_v0_10_0_scalar_cadd_bit(r, 0, (l[(shift - 1) >> 5] >> ((shift - 1) & 0x1f)) & 1); + + SECP256K1_SCALAR_VERIFY(r); } -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_scalar_cmov(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a, int flag) { +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_scalar_cmov(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a, int flag) { uint32_t mask0, mask1; - VG_CHECK_VERIFY(r->d, sizeof(r->d)); - mask0 = flag + ~((uint32_t)0); + volatile int vflag = flag; + SECP256K1_SCALAR_VERIFY(a); + SECP256K1_CHECKMEM_CHECK_VERIFY(r->d, sizeof(r->d)); + + mask0 = vflag + ~((uint32_t)0); mask1 = ~mask0; r->d[0] = (r->d[0] & mask0) | (a->d[0] & mask1); r->d[1] = (r->d[1] & mask0) | (a->d[1] & mask1); @@ -744,108 +834,15 @@ static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_scalar_cmov(rustsecp256k1zk r->d[5] = (r->d[5] & mask0) | (a->d[5] & mask1); r->d[6] = (r->d[6] & mask0) | (a->d[6] & mask1); r->d[7] = (r->d[7] & mask0) | (a->d[7] & mask1); -} - -#define ROTL32(x,n) ((x) << (n) | (x) >> (32-(n))) -#define QUARTERROUND(a,b,c,d) \ - a += b; d = ROTL32(d ^ a, 16); \ - c += d; b = ROTL32(b ^ c, 12); \ - a += b; d = ROTL32(d ^ a, 8); \ - c += d; b = ROTL32(b ^ c, 7); -#if defined(SECP256K1_BIG_ENDIAN) -#define LE32(p) ((((p) & 0xFF) << 24) | (((p) & 0xFF00) << 8) | (((p) & 0xFF0000) >> 8) | (((p) & 0xFF000000) >> 24)) -#elif defined(SECP256K1_LITTLE_ENDIAN) -#define LE32(p) (p) -#endif + SECP256K1_SCALAR_VERIFY(r); +} -static void rustsecp256k1zkp_v0_8_0_scalar_chacha20(rustsecp256k1zkp_v0_8_0_scalar *r1, rustsecp256k1zkp_v0_8_0_scalar *r2, const unsigned char *seed, uint64_t idx) { - size_t n; - size_t over_count = 0; - uint32_t seed32[8]; - uint32_t x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15; - int over1, over2; - - memcpy((void *) seed32, (const void *) seed, 32); - do { - x0 = 0x61707865; - x1 = 0x3320646e; - x2 = 0x79622d32; - x3 = 0x6b206574; - x4 = LE32(seed32[0]); - x5 = LE32(seed32[1]); - x6 = LE32(seed32[2]); - x7 = LE32(seed32[3]); - x8 = LE32(seed32[4]); - x9 = LE32(seed32[5]); - x10 = LE32(seed32[6]); - x11 = LE32(seed32[7]); - x12 = idx; - x13 = idx >> 32; - x14 = 0; - x15 = over_count; - - n = 10; - while (n--) { - QUARTERROUND(x0, x4, x8,x12) - QUARTERROUND(x1, x5, x9,x13) - QUARTERROUND(x2, x6,x10,x14) - QUARTERROUND(x3, x7,x11,x15) - QUARTERROUND(x0, x5,x10,x15) - QUARTERROUND(x1, x6,x11,x12) - QUARTERROUND(x2, x7, x8,x13) - QUARTERROUND(x3, x4, x9,x14) - } - - x0 += 0x61707865; - x1 += 0x3320646e; - x2 += 0x79622d32; - x3 += 0x6b206574; - x4 += LE32(seed32[0]); - x5 += LE32(seed32[1]); - x6 += LE32(seed32[2]); - x7 += LE32(seed32[3]); - x8 += LE32(seed32[4]); - x9 += LE32(seed32[5]); - x10 += LE32(seed32[6]); - x11 += LE32(seed32[7]); - x12 += idx; - x13 += idx >> 32; - x14 += 0; - x15 += over_count; - - r1->d[7] = x0; - r1->d[6] = x1; - r1->d[5] = x2; - r1->d[4] = x3; - r1->d[3] = x4; - r1->d[2] = x5; - r1->d[1] = x6; - r1->d[0] = x7; - r2->d[7] = x8; - r2->d[6] = x9; - r2->d[5] = x10; - r2->d[4] = x11; - r2->d[3] = x12; - r2->d[2] = x13; - r2->d[1] = x14; - r2->d[0] = x15; - - over1 = rustsecp256k1zkp_v0_8_0_scalar_check_overflow(r1); - over2 = rustsecp256k1zkp_v0_8_0_scalar_check_overflow(r2); - over_count++; - } while (over1 | over2); -} - -#undef ROTL32 -#undef QUARTERROUND -#undef LE32 - -static void rustsecp256k1zkp_v0_8_0_scalar_from_signed30(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_modinv32_signed30 *a) { +static void rustsecp256k1zkp_v0_10_0_scalar_from_signed30(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_modinv32_signed30 *a) { const uint32_t a0 = a->v[0], a1 = a->v[1], a2 = a->v[2], a3 = a->v[3], a4 = a->v[4], a5 = a->v[5], a6 = a->v[6], a7 = a->v[7], a8 = a->v[8]; - /* The output from rustsecp256k1zkp_v0_8_0_modinv32{_var} should be normalized to range [0,modulus), and + /* The output from rustsecp256k1zkp_v0_10_0_modinv32{_var} should be normalized to range [0,modulus), and * have limbs in [0,2^30). The modulus is < 2^256, so the top limb must be below 2^(256-30*8). */ VERIFY_CHECK(a0 >> 30 == 0); @@ -867,19 +864,14 @@ static void rustsecp256k1zkp_v0_8_0_scalar_from_signed30(rustsecp256k1zkp_v0_8_0 r->d[6] = a6 >> 12 | a7 << 18; r->d[7] = a7 >> 14 | a8 << 16; -#ifdef VERIFY - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_scalar_check_overflow(r) == 0); -#endif + SECP256K1_SCALAR_VERIFY(r); } -static void rustsecp256k1zkp_v0_8_0_scalar_to_signed30(rustsecp256k1zkp_v0_8_0_modinv32_signed30 *r, const rustsecp256k1zkp_v0_8_0_scalar *a) { +static void rustsecp256k1zkp_v0_10_0_scalar_to_signed30(rustsecp256k1zkp_v0_10_0_modinv32_signed30 *r, const rustsecp256k1zkp_v0_10_0_scalar *a) { const uint32_t M30 = UINT32_MAX >> 2; const uint32_t a0 = a->d[0], a1 = a->d[1], a2 = a->d[2], a3 = a->d[3], a4 = a->d[4], a5 = a->d[5], a6 = a->d[6], a7 = a->d[7]; - -#ifdef VERIFY - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_scalar_check_overflow(a) == 0); -#endif + SECP256K1_SCALAR_VERIFY(a); r->v[0] = a0 & M30; r->v[1] = (a0 >> 30 | a1 << 2) & M30; @@ -892,40 +884,44 @@ static void rustsecp256k1zkp_v0_8_0_scalar_to_signed30(rustsecp256k1zkp_v0_8_0_m r->v[8] = a7 >> 16; } -static const rustsecp256k1zkp_v0_8_0_modinv32_modinfo rustsecp256k1zkp_v0_8_0_const_modinfo_scalar = { +static const rustsecp256k1zkp_v0_10_0_modinv32_modinfo rustsecp256k1zkp_v0_10_0_const_modinfo_scalar = { {{0x10364141L, 0x3F497A33L, 0x348A03BBL, 0x2BB739ABL, -0x146L, 0, 0, 0, 65536}}, 0x2A774EC1L }; -static void rustsecp256k1zkp_v0_8_0_scalar_inverse(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *x) { - rustsecp256k1zkp_v0_8_0_modinv32_signed30 s; +static void rustsecp256k1zkp_v0_10_0_scalar_inverse(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *x) { + rustsecp256k1zkp_v0_10_0_modinv32_signed30 s; #ifdef VERIFY - int zero_in = rustsecp256k1zkp_v0_8_0_scalar_is_zero(x); + int zero_in = rustsecp256k1zkp_v0_10_0_scalar_is_zero(x); #endif - rustsecp256k1zkp_v0_8_0_scalar_to_signed30(&s, x); - rustsecp256k1zkp_v0_8_0_modinv32(&s, &rustsecp256k1zkp_v0_8_0_const_modinfo_scalar); - rustsecp256k1zkp_v0_8_0_scalar_from_signed30(r, &s); + SECP256K1_SCALAR_VERIFY(x); -#ifdef VERIFY - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_scalar_is_zero(r) == zero_in); -#endif + rustsecp256k1zkp_v0_10_0_scalar_to_signed30(&s, x); + rustsecp256k1zkp_v0_10_0_modinv32(&s, &rustsecp256k1zkp_v0_10_0_const_modinfo_scalar); + rustsecp256k1zkp_v0_10_0_scalar_from_signed30(r, &s); + + SECP256K1_SCALAR_VERIFY(r); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_scalar_is_zero(r) == zero_in); } -static void rustsecp256k1zkp_v0_8_0_scalar_inverse_var(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *x) { - rustsecp256k1zkp_v0_8_0_modinv32_signed30 s; +static void rustsecp256k1zkp_v0_10_0_scalar_inverse_var(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *x) { + rustsecp256k1zkp_v0_10_0_modinv32_signed30 s; #ifdef VERIFY - int zero_in = rustsecp256k1zkp_v0_8_0_scalar_is_zero(x); + int zero_in = rustsecp256k1zkp_v0_10_0_scalar_is_zero(x); #endif - rustsecp256k1zkp_v0_8_0_scalar_to_signed30(&s, x); - rustsecp256k1zkp_v0_8_0_modinv32_var(&s, &rustsecp256k1zkp_v0_8_0_const_modinfo_scalar); - rustsecp256k1zkp_v0_8_0_scalar_from_signed30(r, &s); + SECP256K1_SCALAR_VERIFY(x); -#ifdef VERIFY - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_scalar_is_zero(r) == zero_in); -#endif + rustsecp256k1zkp_v0_10_0_scalar_to_signed30(&s, x); + rustsecp256k1zkp_v0_10_0_modinv32_var(&s, &rustsecp256k1zkp_v0_10_0_const_modinfo_scalar); + rustsecp256k1zkp_v0_10_0_scalar_from_signed30(r, &s); + + SECP256K1_SCALAR_VERIFY(r); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_scalar_is_zero(r) == zero_in); } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_scalar_is_even(const rustsecp256k1zkp_v0_8_0_scalar *a) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_scalar_is_even(const rustsecp256k1zkp_v0_10_0_scalar *a) { + SECP256K1_SCALAR_VERIFY(a); + return !(a->d[0] & 1); } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/scalar_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/scalar_impl.h index 3b8d0f7d..4f5e1bd0 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/scalar_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/scalar_impl.h @@ -14,10 +14,6 @@ #include "scalar.h" #include "util.h" -#if defined HAVE_CONFIG_H -#include "libsecp256k1-config.h" -#endif - #if defined(EXHAUSTIVE_TEST_ORDER) #include "scalar_low_impl.h" #elif defined(SECP256K1_WIDEMUL_INT128) @@ -28,24 +24,35 @@ #error "Please select wide multiplication implementation" #endif -static const rustsecp256k1zkp_v0_8_0_scalar rustsecp256k1zkp_v0_8_0_scalar_one = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 1); -static const rustsecp256k1zkp_v0_8_0_scalar rustsecp256k1zkp_v0_8_0_scalar_zero = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0); +static const rustsecp256k1zkp_v0_10_0_scalar rustsecp256k1zkp_v0_10_0_scalar_one = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 1); +static const rustsecp256k1zkp_v0_10_0_scalar rustsecp256k1zkp_v0_10_0_scalar_zero = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0); -static int rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(rustsecp256k1zkp_v0_8_0_scalar *r, const unsigned char *bin) { +static int rustsecp256k1zkp_v0_10_0_scalar_set_b32_seckey(rustsecp256k1zkp_v0_10_0_scalar *r, const unsigned char *bin) { int overflow; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(r, bin, &overflow); - return (!overflow) & (!rustsecp256k1zkp_v0_8_0_scalar_is_zero(r)); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(r, bin, &overflow); + + SECP256K1_SCALAR_VERIFY(r); + return (!overflow) & (!rustsecp256k1zkp_v0_10_0_scalar_is_zero(r)); +} + +static void rustsecp256k1zkp_v0_10_0_scalar_verify(const rustsecp256k1zkp_v0_10_0_scalar *r) { + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_scalar_check_overflow(r) == 0); + + (void)r; } -/* These parameters are generated using sage/gen_exhaustive_groups.sage. */ #if defined(EXHAUSTIVE_TEST_ORDER) -# if EXHAUSTIVE_TEST_ORDER == 13 +/* Begin of section generated by sage/gen_exhaustive_groups.sage. */ +# if EXHAUSTIVE_TEST_ORDER == 7 +# define EXHAUSTIVE_TEST_LAMBDA 2 +# elif EXHAUSTIVE_TEST_ORDER == 13 # define EXHAUSTIVE_TEST_LAMBDA 9 # elif EXHAUSTIVE_TEST_ORDER == 199 # define EXHAUSTIVE_TEST_LAMBDA 92 # else # error No known lambda for the specified exhaustive test group order. # endif +/* End of section generated by sage/gen_exhaustive_groups.sage. */ /** * Find r1 and r2 given k, such that r1 + r2 * lambda == k mod n; unlike in the @@ -53,21 +60,29 @@ static int rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(rustsecp256k1zkp_v0_8_0 * nontrivial to get full test coverage for the exhaustive tests. We therefore * (arbitrarily) set r2 = k + 5 (mod n) and r1 = k - r2 * lambda (mod n). */ -static void rustsecp256k1zkp_v0_8_0_scalar_split_lambda(rustsecp256k1zkp_v0_8_0_scalar *r1, rustsecp256k1zkp_v0_8_0_scalar *r2, const rustsecp256k1zkp_v0_8_0_scalar *k) { +static void rustsecp256k1zkp_v0_10_0_scalar_split_lambda(rustsecp256k1zkp_v0_10_0_scalar * SECP256K1_RESTRICT r1, rustsecp256k1zkp_v0_10_0_scalar * SECP256K1_RESTRICT r2, const rustsecp256k1zkp_v0_10_0_scalar * SECP256K1_RESTRICT k) { + SECP256K1_SCALAR_VERIFY(k); + VERIFY_CHECK(r1 != k); + VERIFY_CHECK(r2 != k); + VERIFY_CHECK(r1 != r2); + *r2 = (*k + 5) % EXHAUSTIVE_TEST_ORDER; *r1 = (*k + (EXHAUSTIVE_TEST_ORDER - *r2) * EXHAUSTIVE_TEST_LAMBDA) % EXHAUSTIVE_TEST_ORDER; + + SECP256K1_SCALAR_VERIFY(r1); + SECP256K1_SCALAR_VERIFY(r2); } #else /** * The Secp256k1 curve has an endomorphism, where lambda * (x, y) = (beta * x, y), where * lambda is: */ -static const rustsecp256k1zkp_v0_8_0_scalar rustsecp256k1zkp_v0_8_0_const_lambda = SECP256K1_SCALAR_CONST( +static const rustsecp256k1zkp_v0_10_0_scalar rustsecp256k1zkp_v0_10_0_const_lambda = SECP256K1_SCALAR_CONST( 0x5363AD4CUL, 0xC05C30E0UL, 0xA5261C02UL, 0x8812645AUL, 0x122E22EAUL, 0x20816678UL, 0xDF02967CUL, 0x1B23BD72UL ); #ifdef VERIFY -static void rustsecp256k1zkp_v0_8_0_scalar_split_lambda_verify(const rustsecp256k1zkp_v0_8_0_scalar *r1, const rustsecp256k1zkp_v0_8_0_scalar *r2, const rustsecp256k1zkp_v0_8_0_scalar *k); +static void rustsecp256k1zkp_v0_10_0_scalar_split_lambda_verify(const rustsecp256k1zkp_v0_10_0_scalar *r1, const rustsecp256k1zkp_v0_10_0_scalar *r2, const rustsecp256k1zkp_v0_10_0_scalar *k); #endif /* @@ -120,44 +135,49 @@ static void rustsecp256k1zkp_v0_8_0_scalar_split_lambda_verify(const rustsecp256 * * See proof below. */ -static void rustsecp256k1zkp_v0_8_0_scalar_split_lambda(rustsecp256k1zkp_v0_8_0_scalar *r1, rustsecp256k1zkp_v0_8_0_scalar *r2, const rustsecp256k1zkp_v0_8_0_scalar *k) { - rustsecp256k1zkp_v0_8_0_scalar c1, c2; - static const rustsecp256k1zkp_v0_8_0_scalar minus_b1 = SECP256K1_SCALAR_CONST( +static void rustsecp256k1zkp_v0_10_0_scalar_split_lambda(rustsecp256k1zkp_v0_10_0_scalar * SECP256K1_RESTRICT r1, rustsecp256k1zkp_v0_10_0_scalar * SECP256K1_RESTRICT r2, const rustsecp256k1zkp_v0_10_0_scalar * SECP256K1_RESTRICT k) { + rustsecp256k1zkp_v0_10_0_scalar c1, c2; + static const rustsecp256k1zkp_v0_10_0_scalar minus_b1 = SECP256K1_SCALAR_CONST( 0x00000000UL, 0x00000000UL, 0x00000000UL, 0x00000000UL, 0xE4437ED6UL, 0x010E8828UL, 0x6F547FA9UL, 0x0ABFE4C3UL ); - static const rustsecp256k1zkp_v0_8_0_scalar minus_b2 = SECP256K1_SCALAR_CONST( + static const rustsecp256k1zkp_v0_10_0_scalar minus_b2 = SECP256K1_SCALAR_CONST( 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFEUL, 0x8A280AC5UL, 0x0774346DUL, 0xD765CDA8UL, 0x3DB1562CUL ); - static const rustsecp256k1zkp_v0_8_0_scalar g1 = SECP256K1_SCALAR_CONST( + static const rustsecp256k1zkp_v0_10_0_scalar g1 = SECP256K1_SCALAR_CONST( 0x3086D221UL, 0xA7D46BCDUL, 0xE86C90E4UL, 0x9284EB15UL, 0x3DAA8A14UL, 0x71E8CA7FUL, 0xE893209AUL, 0x45DBB031UL ); - static const rustsecp256k1zkp_v0_8_0_scalar g2 = SECP256K1_SCALAR_CONST( + static const rustsecp256k1zkp_v0_10_0_scalar g2 = SECP256K1_SCALAR_CONST( 0xE4437ED6UL, 0x010E8828UL, 0x6F547FA9UL, 0x0ABFE4C4UL, 0x221208ACUL, 0x9DF506C6UL, 0x1571B4AEUL, 0x8AC47F71UL ); + SECP256K1_SCALAR_VERIFY(k); VERIFY_CHECK(r1 != k); VERIFY_CHECK(r2 != k); + VERIFY_CHECK(r1 != r2); + /* these _var calls are constant time since the shift amount is constant */ - rustsecp256k1zkp_v0_8_0_scalar_mul_shift_var(&c1, k, &g1, 384); - rustsecp256k1zkp_v0_8_0_scalar_mul_shift_var(&c2, k, &g2, 384); - rustsecp256k1zkp_v0_8_0_scalar_mul(&c1, &c1, &minus_b1); - rustsecp256k1zkp_v0_8_0_scalar_mul(&c2, &c2, &minus_b2); - rustsecp256k1zkp_v0_8_0_scalar_add(r2, &c1, &c2); - rustsecp256k1zkp_v0_8_0_scalar_mul(r1, r2, &rustsecp256k1zkp_v0_8_0_const_lambda); - rustsecp256k1zkp_v0_8_0_scalar_negate(r1, r1); - rustsecp256k1zkp_v0_8_0_scalar_add(r1, r1, k); + rustsecp256k1zkp_v0_10_0_scalar_mul_shift_var(&c1, k, &g1, 384); + rustsecp256k1zkp_v0_10_0_scalar_mul_shift_var(&c2, k, &g2, 384); + rustsecp256k1zkp_v0_10_0_scalar_mul(&c1, &c1, &minus_b1); + rustsecp256k1zkp_v0_10_0_scalar_mul(&c2, &c2, &minus_b2); + rustsecp256k1zkp_v0_10_0_scalar_add(r2, &c1, &c2); + rustsecp256k1zkp_v0_10_0_scalar_mul(r1, r2, &rustsecp256k1zkp_v0_10_0_const_lambda); + rustsecp256k1zkp_v0_10_0_scalar_negate(r1, r1); + rustsecp256k1zkp_v0_10_0_scalar_add(r1, r1, k); + SECP256K1_SCALAR_VERIFY(r1); + SECP256K1_SCALAR_VERIFY(r2); #ifdef VERIFY - rustsecp256k1zkp_v0_8_0_scalar_split_lambda_verify(r1, r2, k); + rustsecp256k1zkp_v0_10_0_scalar_split_lambda_verify(r1, r2, k); #endif } #ifdef VERIFY /* - * Proof for rustsecp256k1zkp_v0_8_0_scalar_split_lambda's bounds. + * Proof for rustsecp256k1zkp_v0_10_0_scalar_split_lambda's bounds. * * Let * - epsilon1 = 2^256 * |g1/2^384 - b2/d| @@ -209,7 +229,7 @@ static void rustsecp256k1zkp_v0_8_0_scalar_split_lambda(rustsecp256k1zkp_v0_8_0_ * <= {triangle inequality} * a1*|k*b2/n - c1| + a2*|k*(-b1)/n - c2| * < {Lemma 1 and Lemma 2} - * a1*(2^-1 + epslion1) + a2*(2^-1 + epsilon2) + * a1*(2^-1 + epsilon1) + a2*(2^-1 + epsilon2) * < {rounding up to an integer} * (a1 + a2 + 1)/2 * < {rounding up to a power of 2} @@ -227,7 +247,7 @@ static void rustsecp256k1zkp_v0_8_0_scalar_split_lambda(rustsecp256k1zkp_v0_8_0_ * <= {triangle inequality} * (-b1)*|k*b2/n - c1| + b2*|k*(-b1)/n - c2| * < {Lemma 1 and Lemma 2} - * (-b1)*(2^-1 + epslion1) + b2*(2^-1 + epsilon2) + * (-b1)*(2^-1 + epsilon1) + b2*(2^-1 + epsilon2) * < {rounding up to an integer} * (-b1 + b2)/2 + 1 * < {rounding up to a power of 2} @@ -260,8 +280,8 @@ static void rustsecp256k1zkp_v0_8_0_scalar_split_lambda(rustsecp256k1zkp_v0_8_0_ * * Q.E.D. */ -static void rustsecp256k1zkp_v0_8_0_scalar_split_lambda_verify(const rustsecp256k1zkp_v0_8_0_scalar *r1, const rustsecp256k1zkp_v0_8_0_scalar *r2, const rustsecp256k1zkp_v0_8_0_scalar *k) { - rustsecp256k1zkp_v0_8_0_scalar s; +static void rustsecp256k1zkp_v0_10_0_scalar_split_lambda_verify(const rustsecp256k1zkp_v0_10_0_scalar *r1, const rustsecp256k1zkp_v0_10_0_scalar *r2, const rustsecp256k1zkp_v0_10_0_scalar *k) { + rustsecp256k1zkp_v0_10_0_scalar s; unsigned char buf1[32]; unsigned char buf2[32]; @@ -277,19 +297,19 @@ static void rustsecp256k1zkp_v0_8_0_scalar_split_lambda_verify(const rustsecp256 0x8a, 0x65, 0x28, 0x7b, 0xd4, 0x71, 0x79, 0xfb, 0x2b, 0xe0, 0x88, 0x46, 0xce, 0xa2, 0x67, 0xed }; - rustsecp256k1zkp_v0_8_0_scalar_mul(&s, &rustsecp256k1zkp_v0_8_0_const_lambda, r2); - rustsecp256k1zkp_v0_8_0_scalar_add(&s, &s, r1); - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&s, k)); + rustsecp256k1zkp_v0_10_0_scalar_mul(&s, &rustsecp256k1zkp_v0_10_0_const_lambda, r2); + rustsecp256k1zkp_v0_10_0_scalar_add(&s, &s, r1); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&s, k)); - rustsecp256k1zkp_v0_8_0_scalar_negate(&s, r1); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(buf1, r1); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(buf2, &s); - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(buf1, k1_bound, 32) < 0 || rustsecp256k1zkp_v0_8_0_memcmp_var(buf2, k1_bound, 32) < 0); + rustsecp256k1zkp_v0_10_0_scalar_negate(&s, r1); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(buf1, r1); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(buf2, &s); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(buf1, k1_bound, 32) < 0 || rustsecp256k1zkp_v0_10_0_memcmp_var(buf2, k1_bound, 32) < 0); - rustsecp256k1zkp_v0_8_0_scalar_negate(&s, r2); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(buf1, r2); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(buf2, &s); - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(buf1, k2_bound, 32) < 0 || rustsecp256k1zkp_v0_8_0_memcmp_var(buf2, k2_bound, 32) < 0); + rustsecp256k1zkp_v0_10_0_scalar_negate(&s, r2); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(buf1, r2); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(buf2, &s); + VERIFY_CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(buf1, k2_bound, 32) < 0 || rustsecp256k1zkp_v0_10_0_memcmp_var(buf2, k2_bound, 32) < 0); } #endif /* VERIFY */ #endif /* !defined(EXHAUSTIVE_TEST_ORDER) */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/scalar_low.h b/secp256k1-zkp-sys/depend/secp256k1/src/scalar_low.h index 828e8cd5..97e202be 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/scalar_low.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/scalar_low.h @@ -1,5 +1,5 @@ /*********************************************************************** - * Copyright (c) 2015 Andrew Poelstra * + * Copyright (c) 2015, 2022 Andrew Poelstra, Pieter Wuille * * Distributed under the MIT software license, see the accompanying * * file COPYING or https://www.opensource.org/licenses/mit-license.php.* ***********************************************************************/ @@ -10,8 +10,15 @@ #include /** A scalar modulo the group order of the secp256k1 curve. */ -typedef uint32_t rustsecp256k1zkp_v0_8_0_scalar; +typedef uint32_t rustsecp256k1zkp_v0_10_0_scalar; -#define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) (d0) +/* A compile-time constant equal to 2^32 (modulo order). */ +#define SCALAR_2P32 ((0xffffffffUL % EXHAUSTIVE_TEST_ORDER) + 1U) + +/* Compute a*2^32 + b (modulo order). */ +#define SCALAR_HORNER(a, b) (((uint64_t)(a) * SCALAR_2P32 + (b)) % EXHAUSTIVE_TEST_ORDER) + +/* Evaluates to the provided 256-bit constant reduced modulo order. */ +#define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) SCALAR_HORNER(SCALAR_HORNER(SCALAR_HORNER(SCALAR_HORNER(SCALAR_HORNER(SCALAR_HORNER(SCALAR_HORNER((d7), (d6)), (d5)), (d4)), (d3)), (d2)), (d1)), (d0)) #endif /* SECP256K1_SCALAR_REPR_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/scalar_low_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/scalar_low_impl.h index cf6b0028..e3eebc29 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/scalar_low_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/scalar_low_impl.h @@ -7,48 +7,72 @@ #ifndef SECP256K1_SCALAR_REPR_IMPL_H #define SECP256K1_SCALAR_REPR_IMPL_H +#include "checkmem.h" #include "scalar.h" +#include "util.h" #include -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_scalar_is_even(const rustsecp256k1zkp_v0_8_0_scalar *a) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_scalar_is_even(const rustsecp256k1zkp_v0_10_0_scalar *a) { + SECP256K1_SCALAR_VERIFY(a); + return !(*a & 1); } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_scalar_clear(rustsecp256k1zkp_v0_8_0_scalar *r) { *r = 0; } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_scalar_set_int(rustsecp256k1zkp_v0_8_0_scalar *r, unsigned int v) { *r = v; } -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_scalar_set_u64(rustsecp256k1zkp_v0_8_0_scalar *r, uint64_t v) { *r = v % EXHAUSTIVE_TEST_ORDER; } +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_scalar_clear(rustsecp256k1zkp_v0_10_0_scalar *r) { *r = 0; } + +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_scalar_set_int(rustsecp256k1zkp_v0_10_0_scalar *r, unsigned int v) { + *r = v % EXHAUSTIVE_TEST_ORDER; + + SECP256K1_SCALAR_VERIFY(r); +} + +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_scalar_set_u64(rustsecp256k1zkp_v0_10_0_scalar *r, uint64_t v) { + *r = v % EXHAUSTIVE_TEST_ORDER; + + rustsecp256k1zkp_v0_10_0_scalar_verify(r); +} + +SECP256K1_INLINE static unsigned int rustsecp256k1zkp_v0_10_0_scalar_get_bits(const rustsecp256k1zkp_v0_10_0_scalar *a, unsigned int offset, unsigned int count) { + SECP256K1_SCALAR_VERIFY(a); -SECP256K1_INLINE static unsigned int rustsecp256k1zkp_v0_8_0_scalar_get_bits(const rustsecp256k1zkp_v0_8_0_scalar *a, unsigned int offset, unsigned int count) { if (offset < 32) return ((*a >> offset) & ((((uint32_t)1) << count) - 1)); else return 0; } -SECP256K1_INLINE static unsigned int rustsecp256k1zkp_v0_8_0_scalar_get_bits_var(const rustsecp256k1zkp_v0_8_0_scalar *a, unsigned int offset, unsigned int count) { - return rustsecp256k1zkp_v0_8_0_scalar_get_bits(a, offset, count); +SECP256K1_INLINE static unsigned int rustsecp256k1zkp_v0_10_0_scalar_get_bits_var(const rustsecp256k1zkp_v0_10_0_scalar *a, unsigned int offset, unsigned int count) { + SECP256K1_SCALAR_VERIFY(a); + + return rustsecp256k1zkp_v0_10_0_scalar_get_bits(a, offset, count); } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_scalar_check_overflow(const rustsecp256k1zkp_v0_8_0_scalar *a) { return *a >= EXHAUSTIVE_TEST_ORDER; } +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_scalar_check_overflow(const rustsecp256k1zkp_v0_10_0_scalar *a) { return *a >= EXHAUSTIVE_TEST_ORDER; } + +static int rustsecp256k1zkp_v0_10_0_scalar_add(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a, const rustsecp256k1zkp_v0_10_0_scalar *b) { + SECP256K1_SCALAR_VERIFY(a); + SECP256K1_SCALAR_VERIFY(b); -static int rustsecp256k1zkp_v0_8_0_scalar_add(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a, const rustsecp256k1zkp_v0_8_0_scalar *b) { *r = (*a + *b) % EXHAUSTIVE_TEST_ORDER; + + SECP256K1_SCALAR_VERIFY(r); return *r < *b; } -static void rustsecp256k1zkp_v0_8_0_scalar_cadd_bit(rustsecp256k1zkp_v0_8_0_scalar *r, unsigned int bit, int flag) { +static void rustsecp256k1zkp_v0_10_0_scalar_cadd_bit(rustsecp256k1zkp_v0_10_0_scalar *r, unsigned int bit, int flag) { + SECP256K1_SCALAR_VERIFY(r); + if (flag && bit < 32) *r += ((uint32_t)1 << bit); -#ifdef VERIFY + + SECP256K1_SCALAR_VERIFY(r); VERIFY_CHECK(bit < 32); /* Verify that adding (1 << bit) will not overflow any in-range scalar *r by overflowing the underlying uint32_t. */ VERIFY_CHECK(((uint32_t)1 << bit) - 1 <= UINT32_MAX - EXHAUSTIVE_TEST_ORDER); - VERIFY_CHECK(rustsecp256k1zkp_v0_8_0_scalar_check_overflow(r) == 0); -#endif } -static void rustsecp256k1zkp_v0_8_0_scalar_set_b32(rustsecp256k1zkp_v0_8_0_scalar *r, const unsigned char *b32, int *overflow) { +static void rustsecp256k1zkp_v0_10_0_scalar_set_b32(rustsecp256k1zkp_v0_10_0_scalar *r, const unsigned char *b32, int *overflow) { int i; int over = 0; *r = 0; @@ -60,90 +84,128 @@ static void rustsecp256k1zkp_v0_8_0_scalar_set_b32(rustsecp256k1zkp_v0_8_0_scala } } if (overflow) *overflow = over; + + SECP256K1_SCALAR_VERIFY(r); } -static void rustsecp256k1zkp_v0_8_0_scalar_get_b32(unsigned char *bin, const rustsecp256k1zkp_v0_8_0_scalar* a) { +static void rustsecp256k1zkp_v0_10_0_scalar_get_b32(unsigned char *bin, const rustsecp256k1zkp_v0_10_0_scalar* a) { + SECP256K1_SCALAR_VERIFY(a); + memset(bin, 0, 32); bin[28] = *a >> 24; bin[29] = *a >> 16; bin[30] = *a >> 8; bin[31] = *a; } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_scalar_is_zero(const rustsecp256k1zkp_v0_8_0_scalar *a) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_scalar_is_zero(const rustsecp256k1zkp_v0_10_0_scalar *a) { + SECP256K1_SCALAR_VERIFY(a); + return *a == 0; } -static void rustsecp256k1zkp_v0_8_0_scalar_negate(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a) { +static void rustsecp256k1zkp_v0_10_0_scalar_negate(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a) { + SECP256K1_SCALAR_VERIFY(a); + if (*a == 0) { *r = 0; } else { *r = EXHAUSTIVE_TEST_ORDER - *a; } + + SECP256K1_SCALAR_VERIFY(r); } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_scalar_is_one(const rustsecp256k1zkp_v0_8_0_scalar *a) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_scalar_is_one(const rustsecp256k1zkp_v0_10_0_scalar *a) { + SECP256K1_SCALAR_VERIFY(a); + return *a == 1; } -static int rustsecp256k1zkp_v0_8_0_scalar_is_high(const rustsecp256k1zkp_v0_8_0_scalar *a) { +static int rustsecp256k1zkp_v0_10_0_scalar_is_high(const rustsecp256k1zkp_v0_10_0_scalar *a) { + SECP256K1_SCALAR_VERIFY(a); + return *a > EXHAUSTIVE_TEST_ORDER / 2; } -static int rustsecp256k1zkp_v0_8_0_scalar_cond_negate(rustsecp256k1zkp_v0_8_0_scalar *r, int flag) { - if (flag) rustsecp256k1zkp_v0_8_0_scalar_negate(r, r); +static int rustsecp256k1zkp_v0_10_0_scalar_cond_negate(rustsecp256k1zkp_v0_10_0_scalar *r, int flag) { + SECP256K1_SCALAR_VERIFY(r); + + if (flag) rustsecp256k1zkp_v0_10_0_scalar_negate(r, r); + + SECP256K1_SCALAR_VERIFY(r); return flag ? -1 : 1; } -static void rustsecp256k1zkp_v0_8_0_scalar_mul(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a, const rustsecp256k1zkp_v0_8_0_scalar *b) { +static void rustsecp256k1zkp_v0_10_0_scalar_mul(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a, const rustsecp256k1zkp_v0_10_0_scalar *b) { + SECP256K1_SCALAR_VERIFY(a); + SECP256K1_SCALAR_VERIFY(b); + *r = (*a * *b) % EXHAUSTIVE_TEST_ORDER; -} -static int rustsecp256k1zkp_v0_8_0_scalar_shr_int(rustsecp256k1zkp_v0_8_0_scalar *r, int n) { - int ret; - VERIFY_CHECK(n > 0); - VERIFY_CHECK(n < 16); - ret = *r & ((1 << n) - 1); - *r >>= n; - return ret; + SECP256K1_SCALAR_VERIFY(r); } -static void rustsecp256k1zkp_v0_8_0_scalar_sqr(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a) { +static void rustsecp256k1zkp_v0_10_0_scalar_sqr(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a) { *r = (*a * *a) % EXHAUSTIVE_TEST_ORDER; } -static void rustsecp256k1zkp_v0_8_0_scalar_split_128(rustsecp256k1zkp_v0_8_0_scalar *r1, rustsecp256k1zkp_v0_8_0_scalar *r2, const rustsecp256k1zkp_v0_8_0_scalar *a) { +static void rustsecp256k1zkp_v0_10_0_scalar_split_128(rustsecp256k1zkp_v0_10_0_scalar *r1, rustsecp256k1zkp_v0_10_0_scalar *r2, const rustsecp256k1zkp_v0_10_0_scalar *a) { + SECP256K1_SCALAR_VERIFY(a); + *r1 = *a; *r2 = 0; + + SECP256K1_SCALAR_VERIFY(r1); + SECP256K1_SCALAR_VERIFY(r2); } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_scalar_eq(const rustsecp256k1zkp_v0_8_0_scalar *a, const rustsecp256k1zkp_v0_8_0_scalar *b) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_scalar_eq(const rustsecp256k1zkp_v0_10_0_scalar *a, const rustsecp256k1zkp_v0_10_0_scalar *b) { + SECP256K1_SCALAR_VERIFY(a); + SECP256K1_SCALAR_VERIFY(b); + return *a == *b; } -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_scalar_cmov(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *a, int flag) { +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_scalar_cmov(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a, int flag) { uint32_t mask0, mask1; - VG_CHECK_VERIFY(r, sizeof(*r)); - mask0 = flag + ~((uint32_t)0); + volatile int vflag = flag; + SECP256K1_SCALAR_VERIFY(a); + SECP256K1_CHECKMEM_CHECK_VERIFY(r, sizeof(*r)); + + mask0 = vflag + ~((uint32_t)0); mask1 = ~mask0; *r = (*r & mask0) | (*a & mask1); -} -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_scalar_chacha20(rustsecp256k1zkp_v0_8_0_scalar *r1, rustsecp256k1zkp_v0_8_0_scalar *r2, const unsigned char *seed, uint64_t n) { - *r1 = (seed[0] + n) % EXHAUSTIVE_TEST_ORDER; - *r2 = (seed[1] + n) % EXHAUSTIVE_TEST_ORDER; + SECP256K1_SCALAR_VERIFY(r); } -static void rustsecp256k1zkp_v0_8_0_scalar_inverse(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *x) { +static void rustsecp256k1zkp_v0_10_0_scalar_inverse(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *x) { int i; *r = 0; + SECP256K1_SCALAR_VERIFY(x); + for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) if ((i * *x) % EXHAUSTIVE_TEST_ORDER == 1) *r = i; + + SECP256K1_SCALAR_VERIFY(r); /* If this VERIFY_CHECK triggers we were given a noninvertible scalar (and thus * have a composite group order; fix it in exhaustive_tests.c). */ VERIFY_CHECK(*r != 0); } -static void rustsecp256k1zkp_v0_8_0_scalar_inverse_var(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_scalar *x) { - rustsecp256k1zkp_v0_8_0_scalar_inverse(r, x); +static void rustsecp256k1zkp_v0_10_0_scalar_inverse_var(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *x) { + SECP256K1_SCALAR_VERIFY(x); + + rustsecp256k1zkp_v0_10_0_scalar_inverse(r, x); + + SECP256K1_SCALAR_VERIFY(r); +} + +static void rustsecp256k1zkp_v0_10_0_scalar_half(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_scalar *a) { + SECP256K1_SCALAR_VERIFY(a); + + *r = (*a + ((-(uint32_t)(*a & 1)) & EXHAUSTIVE_TEST_ORDER)) >> 1; + + SECP256K1_SCALAR_VERIFY(r); } #endif /* SECP256K1_SCALAR_REPR_IMPL_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/scratch.h b/secp256k1-zkp-sys/depend/secp256k1/src/scratch.h index ea2be4b5..0ff329bb 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/scratch.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/scratch.h @@ -9,7 +9,7 @@ /* The typedef is used internally; the struct name is used in the public API * (where it is exposed as a different typedef) */ -typedef struct rustsecp256k1zkp_v0_8_0_scratch_space_struct { +typedef struct rustsecp256k1zkp_v0_10_0_scratch_space_struct { /** guard against interpreting this object as other types */ unsigned char magic[8]; /** actual allocated data */ @@ -19,24 +19,24 @@ typedef struct rustsecp256k1zkp_v0_8_0_scratch_space_struct { size_t alloc_size; /** maximum size available to allocate */ size_t max_size; -} rustsecp256k1zkp_v0_8_0_scratch; +} rustsecp256k1zkp_v0_10_0_scratch; -static rustsecp256k1zkp_v0_8_0_scratch* rustsecp256k1zkp_v0_8_0_scratch_create(const rustsecp256k1zkp_v0_8_0_callback* error_callback, size_t max_size); +static rustsecp256k1zkp_v0_10_0_scratch* rustsecp256k1zkp_v0_10_0_scratch_create(const rustsecp256k1zkp_v0_10_0_callback* error_callback, size_t max_size); -static void rustsecp256k1zkp_v0_8_0_scratch_destroy(const rustsecp256k1zkp_v0_8_0_callback* error_callback, rustsecp256k1zkp_v0_8_0_scratch* scratch); +static void rustsecp256k1zkp_v0_10_0_scratch_destroy(const rustsecp256k1zkp_v0_10_0_callback* error_callback, rustsecp256k1zkp_v0_10_0_scratch* scratch); /** Returns an opaque object used to "checkpoint" a scratch space. Used - * with `rustsecp256k1zkp_v0_8_0_scratch_apply_checkpoint` to undo allocations. */ -static size_t rustsecp256k1zkp_v0_8_0_scratch_checkpoint(const rustsecp256k1zkp_v0_8_0_callback* error_callback, const rustsecp256k1zkp_v0_8_0_scratch* scratch); + * with `rustsecp256k1zkp_v0_10_0_scratch_apply_checkpoint` to undo allocations. */ +static size_t rustsecp256k1zkp_v0_10_0_scratch_checkpoint(const rustsecp256k1zkp_v0_10_0_callback* error_callback, const rustsecp256k1zkp_v0_10_0_scratch* scratch); -/** Applies a check point received from `rustsecp256k1zkp_v0_8_0_scratch_checkpoint`, +/** Applies a check point received from `rustsecp256k1zkp_v0_10_0_scratch_checkpoint`, * undoing all allocations since that point. */ -static void rustsecp256k1zkp_v0_8_0_scratch_apply_checkpoint(const rustsecp256k1zkp_v0_8_0_callback* error_callback, rustsecp256k1zkp_v0_8_0_scratch* scratch, size_t checkpoint); +static void rustsecp256k1zkp_v0_10_0_scratch_apply_checkpoint(const rustsecp256k1zkp_v0_10_0_callback* error_callback, rustsecp256k1zkp_v0_10_0_scratch* scratch, size_t checkpoint); /** Returns the maximum allocation the scratch space will allow */ -static size_t rustsecp256k1zkp_v0_8_0_scratch_max_allocation(const rustsecp256k1zkp_v0_8_0_callback* error_callback, const rustsecp256k1zkp_v0_8_0_scratch* scratch, size_t n_objects); +static size_t rustsecp256k1zkp_v0_10_0_scratch_max_allocation(const rustsecp256k1zkp_v0_10_0_callback* error_callback, const rustsecp256k1zkp_v0_10_0_scratch* scratch, size_t n_objects); /** Returns a pointer into the most recently allocated frame, or NULL if there is insufficient available space */ -static void *rustsecp256k1zkp_v0_8_0_scratch_alloc(const rustsecp256k1zkp_v0_8_0_callback* error_callback, rustsecp256k1zkp_v0_8_0_scratch* scratch, size_t n); +static void *rustsecp256k1zkp_v0_10_0_scratch_alloc(const rustsecp256k1zkp_v0_10_0_callback* error_callback, rustsecp256k1zkp_v0_10_0_scratch* scratch, size_t n); #endif diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/scratch_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/scratch_impl.h index 5aaed95e..43187f09 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/scratch_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/scratch_impl.h @@ -10,29 +10,29 @@ #include "util.h" #include "scratch.h" -static size_t rustsecp256k1zkp_v0_8_0_scratch_checkpoint(const rustsecp256k1zkp_v0_8_0_callback* error_callback, const rustsecp256k1zkp_v0_8_0_scratch* scratch) { - if (rustsecp256k1zkp_v0_8_0_memcmp_var(scratch->magic, "scratch", 8) != 0) { - rustsecp256k1zkp_v0_8_0_callback_call(error_callback, "invalid scratch space"); +static size_t rustsecp256k1zkp_v0_10_0_scratch_checkpoint(const rustsecp256k1zkp_v0_10_0_callback* error_callback, const rustsecp256k1zkp_v0_10_0_scratch* scratch) { + if (rustsecp256k1zkp_v0_10_0_memcmp_var(scratch->magic, "scratch", 8) != 0) { + rustsecp256k1zkp_v0_10_0_callback_call(error_callback, "invalid scratch space"); return 0; } return scratch->alloc_size; } -static void rustsecp256k1zkp_v0_8_0_scratch_apply_checkpoint(const rustsecp256k1zkp_v0_8_0_callback* error_callback, rustsecp256k1zkp_v0_8_0_scratch* scratch, size_t checkpoint) { - if (rustsecp256k1zkp_v0_8_0_memcmp_var(scratch->magic, "scratch", 8) != 0) { - rustsecp256k1zkp_v0_8_0_callback_call(error_callback, "invalid scratch space"); +static void rustsecp256k1zkp_v0_10_0_scratch_apply_checkpoint(const rustsecp256k1zkp_v0_10_0_callback* error_callback, rustsecp256k1zkp_v0_10_0_scratch* scratch, size_t checkpoint) { + if (rustsecp256k1zkp_v0_10_0_memcmp_var(scratch->magic, "scratch", 8) != 0) { + rustsecp256k1zkp_v0_10_0_callback_call(error_callback, "invalid scratch space"); return; } if (checkpoint > scratch->alloc_size) { - rustsecp256k1zkp_v0_8_0_callback_call(error_callback, "invalid checkpoint"); + rustsecp256k1zkp_v0_10_0_callback_call(error_callback, "invalid checkpoint"); return; } scratch->alloc_size = checkpoint; } -static size_t rustsecp256k1zkp_v0_8_0_scratch_max_allocation(const rustsecp256k1zkp_v0_8_0_callback* error_callback, const rustsecp256k1zkp_v0_8_0_scratch* scratch, size_t objects) { - if (rustsecp256k1zkp_v0_8_0_memcmp_var(scratch->magic, "scratch", 8) != 0) { - rustsecp256k1zkp_v0_8_0_callback_call(error_callback, "invalid scratch space"); +static size_t rustsecp256k1zkp_v0_10_0_scratch_max_allocation(const rustsecp256k1zkp_v0_10_0_callback* error_callback, const rustsecp256k1zkp_v0_10_0_scratch* scratch, size_t objects) { + if (rustsecp256k1zkp_v0_10_0_memcmp_var(scratch->magic, "scratch", 8) != 0) { + rustsecp256k1zkp_v0_10_0_callback_call(error_callback, "invalid scratch space"); return 0; } /* Ensure that multiplication will not wrap around */ @@ -45,7 +45,7 @@ static size_t rustsecp256k1zkp_v0_8_0_scratch_max_allocation(const rustsecp256k1 return scratch->max_size - scratch->alloc_size - objects * (ALIGNMENT - 1); } -static void *rustsecp256k1zkp_v0_8_0_scratch_alloc(const rustsecp256k1zkp_v0_8_0_callback* error_callback, rustsecp256k1zkp_v0_8_0_scratch* scratch, size_t size) { +static void *rustsecp256k1zkp_v0_10_0_scratch_alloc(const rustsecp256k1zkp_v0_10_0_callback* error_callback, rustsecp256k1zkp_v0_10_0_scratch* scratch, size_t size) { void *ret; size_t rounded_size; @@ -56,8 +56,8 @@ static void *rustsecp256k1zkp_v0_8_0_scratch_alloc(const rustsecp256k1zkp_v0_8_0 } size = rounded_size; - if (rustsecp256k1zkp_v0_8_0_memcmp_var(scratch->magic, "scratch", 8) != 0) { - rustsecp256k1zkp_v0_8_0_callback_call(error_callback, "invalid scratch space"); + if (rustsecp256k1zkp_v0_10_0_memcmp_var(scratch->magic, "scratch", 8) != 0) { + rustsecp256k1zkp_v0_10_0_callback_call(error_callback, "invalid scratch space"); return NULL; } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/secp256k1.c b/secp256k1-zkp-sys/depend/secp256k1/src/secp256k1.c index ca28518a..4670f8d9 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/secp256k1.c +++ b/secp256k1-zkp-sys/depend/secp256k1/src/secp256k1.c @@ -4,13 +4,26 @@ * file COPYING or https://www.opensource.org/licenses/mit-license.php.* ***********************************************************************/ +/* This is a C project. It should not be compiled with a C++ compiler, + * and we error out if we detect one. + * + * We still want to be able to test the project with a C++ compiler + * because it is still good to know if this will lead to real trouble, so + * there is a possibility to override the check. But be warned that + * compiling with a C++ compiler is not supported. */ +#if defined(__cplusplus) && !defined(SECP256K1_CPLUSPLUS_TEST_OVERRIDE) +#error Trying to compile a C project with a C++ compiler. +#endif + #define SECP256K1_BUILD #include "../include/secp256k1.h" #include "../include/secp256k1_preallocated.h" #include "assumptions.h" +#include "checkmem.h" #include "util.h" + #include "field_impl.h" #include "scalar_impl.h" #include "group_impl.h" @@ -21,6 +34,7 @@ #include "ecdsa_impl.h" #include "eckey_impl.h" #include "hash_impl.h" +#include "int128_impl.h" #include "scratch_impl.h" #include "selftest.h" @@ -28,24 +42,20 @@ # error "secp256k1.h processed without SECP256K1_BUILD defined while building secp256k1.c" #endif -#if defined(VALGRIND) -#include -#endif - #ifdef ENABLE_MODULE_GENERATOR -#include "include/secp256k1_generator.h" +#include "../include/secp256k1_generator.h" #endif #ifdef ENABLE_MODULE_RANGEPROOF -#include "include/secp256k1_rangeproof.h" +#include "../include/secp256k1_rangeproof.h" #endif #ifdef ENABLE_MODULE_ECDSA_S2C -#include "include/secp256k1_ecdsa_s2c.h" -static void rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_save(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening* opening, rustsecp256k1zkp_v0_8_0_ge* ge); +#include "../include/secp256k1_ecdsa_s2c.h" +static void rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_save(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening* opening, rustsecp256k1zkp_v0_10_0_ge* ge); #else -typedef void rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening; -static void rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_save(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening* opening, rustsecp256k1zkp_v0_8_0_ge* ge) { +typedef void rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening; +static void rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_save(rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening* opening, rustsecp256k1zkp_v0_10_0_ge* ge) { (void) opening; (void) ge; VERIFY_CHECK(0); @@ -54,179 +64,183 @@ static void rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_save(rustsecp256k1zkp_v0_8 #define ARG_CHECK(cond) do { \ if (EXPECT(!(cond), 0)) { \ - rustsecp256k1zkp_v0_8_0_callback_call(&ctx->illegal_callback, #cond); \ + rustsecp256k1zkp_v0_10_0_callback_call(&ctx->illegal_callback, #cond); \ return 0; \ } \ } while(0) -#define ARG_CHECK_NO_RETURN(cond) do { \ +#define ARG_CHECK_VOID(cond) do { \ if (EXPECT(!(cond), 0)) { \ - rustsecp256k1zkp_v0_8_0_callback_call(&ctx->illegal_callback, #cond); \ + rustsecp256k1zkp_v0_10_0_callback_call(&ctx->illegal_callback, #cond); \ + return; \ } \ } while(0) -struct rustsecp256k1zkp_v0_8_0_context_struct { - rustsecp256k1zkp_v0_8_0_ecmult_gen_context ecmult_gen_ctx; - rustsecp256k1zkp_v0_8_0_callback illegal_callback; - rustsecp256k1zkp_v0_8_0_callback error_callback; +/* Note that whenever you change the context struct, you must also change the + * context_eq function. */ +struct rustsecp256k1zkp_v0_10_0_context_struct { + rustsecp256k1zkp_v0_10_0_ecmult_gen_context ecmult_gen_ctx; + rustsecp256k1zkp_v0_10_0_callback illegal_callback; + rustsecp256k1zkp_v0_10_0_callback error_callback; int declassify; }; -static const rustsecp256k1zkp_v0_8_0_context rustsecp256k1zkp_v0_8_0_context_no_precomp_ = { +static const rustsecp256k1zkp_v0_10_0_context rustsecp256k1zkp_v0_10_0_context_static_ = { { 0 }, - { rustsecp256k1zkp_v0_8_0_default_illegal_callback_fn, 0 }, - { rustsecp256k1zkp_v0_8_0_default_error_callback_fn, 0 }, + { rustsecp256k1zkp_v0_10_0_default_illegal_callback_fn, 0 }, + { rustsecp256k1zkp_v0_10_0_default_error_callback_fn, 0 }, 0 }; -const rustsecp256k1zkp_v0_8_0_context *rustsecp256k1zkp_v0_8_0_context_no_precomp = &rustsecp256k1zkp_v0_8_0_context_no_precomp_; +const rustsecp256k1zkp_v0_10_0_context *rustsecp256k1zkp_v0_10_0_context_static = &rustsecp256k1zkp_v0_10_0_context_static_; +const rustsecp256k1zkp_v0_10_0_context *rustsecp256k1zkp_v0_10_0_context_no_precomp = &rustsecp256k1zkp_v0_10_0_context_static_; -size_t rustsecp256k1zkp_v0_8_0_context_preallocated_size(unsigned int flags) { - size_t ret = sizeof(rustsecp256k1zkp_v0_8_0_context); +/* Helper function that determines if a context is proper, i.e., is not the static context or a copy thereof. + * + * This is intended for "context" functions such as rustsecp256k1zkp_v0_10_0_context_clone. Function which need specific + * features of a context should still check for these features directly. For example, a function that needs + * ecmult_gen should directly check for the existence of the ecmult_gen context. */ +static int rustsecp256k1zkp_v0_10_0_context_is_proper(const rustsecp256k1zkp_v0_10_0_context* ctx) { + return rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx); +} + +void rustsecp256k1zkp_v0_10_0_selftest(void) { + if (!rustsecp256k1zkp_v0_10_0_selftest_passes()) { + rustsecp256k1zkp_v0_10_0_callback_call(&default_error_callback, "self test failed"); + } +} + +size_t rustsecp256k1zkp_v0_10_0_context_preallocated_size(unsigned int flags) { + size_t ret = sizeof(rustsecp256k1zkp_v0_10_0_context); /* A return value of 0 is reserved as an indicator for errors when we call this function internally. */ VERIFY_CHECK(ret != 0); if (EXPECT((flags & SECP256K1_FLAGS_TYPE_MASK) != SECP256K1_FLAGS_TYPE_CONTEXT, 0)) { - rustsecp256k1zkp_v0_8_0_callback_call(&default_illegal_callback, + rustsecp256k1zkp_v0_10_0_callback_call(&default_illegal_callback, "Invalid flags"); return 0; } + if (EXPECT(!SECP256K1_CHECKMEM_RUNNING() && (flags & SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY), 0)) { + rustsecp256k1zkp_v0_10_0_callback_call(&default_illegal_callback, + "Declassify flag requires running with memory checking"); + return 0; + } + return ret; } -size_t rustsecp256k1zkp_v0_8_0_context_preallocated_clone_size(const rustsecp256k1zkp_v0_8_0_context* ctx) { - size_t ret = sizeof(rustsecp256k1zkp_v0_8_0_context); +size_t rustsecp256k1zkp_v0_10_0_context_preallocated_clone_size(const rustsecp256k1zkp_v0_10_0_context* ctx) { VERIFY_CHECK(ctx != NULL); - return ret; + ARG_CHECK(rustsecp256k1zkp_v0_10_0_context_is_proper(ctx)); + return sizeof(rustsecp256k1zkp_v0_10_0_context); } -rustsecp256k1zkp_v0_8_0_context* rustsecp256k1zkp_v0_8_0_context_preallocated_create(void* prealloc, unsigned int flags) { +rustsecp256k1zkp_v0_10_0_context* rustsecp256k1zkp_v0_10_0_context_preallocated_create(void* prealloc, unsigned int flags) { size_t prealloc_size; - rustsecp256k1zkp_v0_8_0_context* ret; + rustsecp256k1zkp_v0_10_0_context* ret; - if (!rustsecp256k1zkp_v0_8_0_selftest()) { - rustsecp256k1zkp_v0_8_0_callback_call(&default_error_callback, "self test failed"); - } + rustsecp256k1zkp_v0_10_0_selftest(); - prealloc_size = rustsecp256k1zkp_v0_8_0_context_preallocated_size(flags); + prealloc_size = rustsecp256k1zkp_v0_10_0_context_preallocated_size(flags); if (prealloc_size == 0) { return NULL; } VERIFY_CHECK(prealloc != NULL); - ret = (rustsecp256k1zkp_v0_8_0_context*)prealloc; + ret = (rustsecp256k1zkp_v0_10_0_context*)prealloc; ret->illegal_callback = default_illegal_callback; ret->error_callback = default_error_callback; - /* Flags have been checked by rustsecp256k1zkp_v0_8_0_context_preallocated_size. */ + /* Flags have been checked by rustsecp256k1zkp_v0_10_0_context_preallocated_size. */ VERIFY_CHECK((flags & SECP256K1_FLAGS_TYPE_MASK) == SECP256K1_FLAGS_TYPE_CONTEXT); - rustsecp256k1zkp_v0_8_0_ecmult_gen_context_build(&ret->ecmult_gen_ctx); + rustsecp256k1zkp_v0_10_0_ecmult_gen_context_build(&ret->ecmult_gen_ctx); ret->declassify = !!(flags & SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY); return ret; } -rustsecp256k1zkp_v0_8_0_context* rustsecp256k1zkp_v0_8_0_context_preallocated_clone(const rustsecp256k1zkp_v0_8_0_context* ctx, void* prealloc) { - rustsecp256k1zkp_v0_8_0_context* ret; +rustsecp256k1zkp_v0_10_0_context* rustsecp256k1zkp_v0_10_0_context_preallocated_clone(const rustsecp256k1zkp_v0_10_0_context* ctx, void* prealloc) { + rustsecp256k1zkp_v0_10_0_context* ret; VERIFY_CHECK(ctx != NULL); ARG_CHECK(prealloc != NULL); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_context_is_proper(ctx)); - ret = (rustsecp256k1zkp_v0_8_0_context*)prealloc; + ret = (rustsecp256k1zkp_v0_10_0_context*)prealloc; *ret = *ctx; return ret; } -void rustsecp256k1zkp_v0_8_0_context_preallocated_destroy(rustsecp256k1zkp_v0_8_0_context* ctx) { - ARG_CHECK_NO_RETURN(ctx != rustsecp256k1zkp_v0_8_0_context_no_precomp); - if (ctx != NULL) { - rustsecp256k1zkp_v0_8_0_ecmult_gen_context_clear(&ctx->ecmult_gen_ctx); +void rustsecp256k1zkp_v0_10_0_context_preallocated_destroy(rustsecp256k1zkp_v0_10_0_context* ctx) { + ARG_CHECK_VOID(ctx == NULL || rustsecp256k1zkp_v0_10_0_context_is_proper(ctx)); + + /* Defined as noop */ + if (ctx == NULL) { + return; } + + rustsecp256k1zkp_v0_10_0_ecmult_gen_context_clear(&ctx->ecmult_gen_ctx); } -void rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(rustsecp256k1zkp_v0_8_0_context* ctx, void (*fun)(const char* message, void* data), const void* data) { - ARG_CHECK_NO_RETURN(ctx != rustsecp256k1zkp_v0_8_0_context_no_precomp); +void rustsecp256k1zkp_v0_10_0_context_set_illegal_callback(rustsecp256k1zkp_v0_10_0_context* ctx, void (*fun)(const char* message, void* data), const void* data) { + /* We compare pointers instead of checking rustsecp256k1zkp_v0_10_0_context_is_proper() here + because setting callbacks is allowed on *copies* of the static context: + it's harmless and makes testing easier. */ + ARG_CHECK_VOID(ctx != rustsecp256k1zkp_v0_10_0_context_static); if (fun == NULL) { - fun = rustsecp256k1zkp_v0_8_0_default_illegal_callback_fn; + fun = rustsecp256k1zkp_v0_10_0_default_illegal_callback_fn; } ctx->illegal_callback.fn = fun; ctx->illegal_callback.data = data; } -void rustsecp256k1zkp_v0_8_0_context_set_error_callback(rustsecp256k1zkp_v0_8_0_context* ctx, void (*fun)(const char* message, void* data), const void* data) { - ARG_CHECK_NO_RETURN(ctx != rustsecp256k1zkp_v0_8_0_context_no_precomp); +void rustsecp256k1zkp_v0_10_0_context_set_error_callback(rustsecp256k1zkp_v0_10_0_context* ctx, void (*fun)(const char* message, void* data), const void* data) { + /* We compare pointers instead of checking rustsecp256k1zkp_v0_10_0_context_is_proper() here + because setting callbacks is allowed on *copies* of the static context: + it's harmless and makes testing easier. */ + ARG_CHECK_VOID(ctx != rustsecp256k1zkp_v0_10_0_context_static); if (fun == NULL) { - fun = rustsecp256k1zkp_v0_8_0_default_error_callback_fn; + fun = rustsecp256k1zkp_v0_10_0_default_error_callback_fn; } ctx->error_callback.fn = fun; ctx->error_callback.data = data; } /* Mark memory as no-longer-secret for the purpose of analysing constant-time behaviour - * of the software. This is setup for use with valgrind but could be substituted with - * the appropriate instrumentation for other analysis tools. + * of the software. */ -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_declassify(const rustsecp256k1zkp_v0_8_0_context* ctx, const void *p, size_t len) { -#if defined(VALGRIND) - if (EXPECT(ctx->declassify,0)) VALGRIND_MAKE_MEM_DEFINED(p, len); -#else - (void)ctx; - (void)p; - (void)len; -#endif +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_declassify(const rustsecp256k1zkp_v0_10_0_context* ctx, const void *p, size_t len) { + if (EXPECT(ctx->declassify, 0)) SECP256K1_CHECKMEM_DEFINE(p, len); } -static int rustsecp256k1zkp_v0_8_0_pubkey_load(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ge* ge, const rustsecp256k1zkp_v0_8_0_pubkey* pubkey) { - if (sizeof(rustsecp256k1zkp_v0_8_0_ge_storage) == 64) { - /* When the rustsecp256k1zkp_v0_8_0_ge_storage type is exactly 64 byte, use its - * representation inside rustsecp256k1zkp_v0_8_0_pubkey, as conversion is very fast. - * Note that rustsecp256k1zkp_v0_8_0_pubkey_save must use the same representation. */ - rustsecp256k1zkp_v0_8_0_ge_storage s; - memcpy(&s, &pubkey->data[0], sizeof(s)); - rustsecp256k1zkp_v0_8_0_ge_from_storage(ge, &s); - } else { - /* Otherwise, fall back to 32-byte big endian for X and Y. */ - rustsecp256k1zkp_v0_8_0_fe x, y; - rustsecp256k1zkp_v0_8_0_fe_set_b32(&x, pubkey->data); - rustsecp256k1zkp_v0_8_0_fe_set_b32(&y, pubkey->data + 32); - rustsecp256k1zkp_v0_8_0_ge_set_xy(ge, &x, &y); - } - ARG_CHECK(!rustsecp256k1zkp_v0_8_0_fe_is_zero(&ge->x)); +static int rustsecp256k1zkp_v0_10_0_pubkey_load(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_ge* ge, const rustsecp256k1zkp_v0_10_0_pubkey* pubkey) { + rustsecp256k1zkp_v0_10_0_ge_from_bytes(ge, pubkey->data); + ARG_CHECK(!rustsecp256k1zkp_v0_10_0_fe_is_zero(&ge->x)); return 1; } -static void rustsecp256k1zkp_v0_8_0_pubkey_save(rustsecp256k1zkp_v0_8_0_pubkey* pubkey, rustsecp256k1zkp_v0_8_0_ge* ge) { - if (sizeof(rustsecp256k1zkp_v0_8_0_ge_storage) == 64) { - rustsecp256k1zkp_v0_8_0_ge_storage s; - rustsecp256k1zkp_v0_8_0_ge_to_storage(&s, ge); - memcpy(&pubkey->data[0], &s, sizeof(s)); - } else { - VERIFY_CHECK(!rustsecp256k1zkp_v0_8_0_ge_is_infinity(ge)); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&ge->x); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&ge->y); - rustsecp256k1zkp_v0_8_0_fe_get_b32(pubkey->data, &ge->x); - rustsecp256k1zkp_v0_8_0_fe_get_b32(pubkey->data + 32, &ge->y); - } +static void rustsecp256k1zkp_v0_10_0_pubkey_save(rustsecp256k1zkp_v0_10_0_pubkey* pubkey, rustsecp256k1zkp_v0_10_0_ge* ge) { + rustsecp256k1zkp_v0_10_0_ge_to_bytes(pubkey->data, ge); } -int rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pubkey* pubkey, const unsigned char *input, size_t inputlen) { - rustsecp256k1zkp_v0_8_0_ge Q; +int rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_pubkey* pubkey, const unsigned char *input, size_t inputlen) { + rustsecp256k1zkp_v0_10_0_ge Q; VERIFY_CHECK(ctx != NULL); ARG_CHECK(pubkey != NULL); memset(pubkey, 0, sizeof(*pubkey)); ARG_CHECK(input != NULL); - if (!rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(&Q, input, inputlen)) { + if (!rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(&Q, input, inputlen)) { return 0; } - if (!rustsecp256k1zkp_v0_8_0_ge_is_in_correct_subgroup(&Q)) { + if (!rustsecp256k1zkp_v0_10_0_ge_is_in_correct_subgroup(&Q)) { return 0; } - rustsecp256k1zkp_v0_8_0_pubkey_save(pubkey, &Q); - rustsecp256k1zkp_v0_8_0_ge_clear(&Q); + rustsecp256k1zkp_v0_10_0_pubkey_save(pubkey, &Q); + rustsecp256k1zkp_v0_10_0_ge_clear(&Q); return 1; } -int rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *output, size_t *outputlen, const rustsecp256k1zkp_v0_8_0_pubkey* pubkey, unsigned int flags) { - rustsecp256k1zkp_v0_8_0_ge Q; +int rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *output, size_t *outputlen, const rustsecp256k1zkp_v0_10_0_pubkey* pubkey, unsigned int flags) { + rustsecp256k1zkp_v0_10_0_ge Q; size_t len; int ret = 0; @@ -239,8 +253,8 @@ int rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(const rustsecp256k1zkp_v0_8_0_co memset(output, 0, len); ARG_CHECK(pubkey != NULL); ARG_CHECK((flags & SECP256K1_FLAGS_TYPE_MASK) == SECP256K1_FLAGS_TYPE_COMPRESSION); - if (rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &Q, pubkey)) { - ret = rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&Q, output, &len, flags & SECP256K1_FLAGS_BIT_COMPRESSION); + if (rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, &Q, pubkey)) { + ret = rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&Q, output, &len, flags & SECP256K1_FLAGS_BIT_COMPRESSION); if (ret) { *outputlen = len; } @@ -248,9 +262,9 @@ int rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(const rustsecp256k1zkp_v0_8_0_co return ret; } -int rustsecp256k1zkp_v0_8_0_ec_pubkey_cmp(const rustsecp256k1zkp_v0_8_0_context* ctx, const rustsecp256k1zkp_v0_8_0_pubkey* pubkey0, const rustsecp256k1zkp_v0_8_0_pubkey* pubkey1) { +int rustsecp256k1zkp_v0_10_0_ec_pubkey_cmp(const rustsecp256k1zkp_v0_10_0_context* ctx, const rustsecp256k1zkp_v0_10_0_pubkey* pubkey0, const rustsecp256k1zkp_v0_10_0_pubkey* pubkey1) { unsigned char out[2][33]; - const rustsecp256k1zkp_v0_8_0_pubkey* pk[2]; + const rustsecp256k1zkp_v0_10_0_pubkey* pk[2]; int i; VERIFY_CHECK(ctx != NULL); @@ -263,7 +277,7 @@ int rustsecp256k1zkp_v0_8_0_ec_pubkey_cmp(const rustsecp256k1zkp_v0_8_0_context* * results in consistent comparisons even if NULL or invalid pubkeys are * involved and prevents edge cases such as sorting algorithms that use * this function and do not terminate as a result. */ - if (!rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, out[i], &out_size, pk[i], SECP256K1_EC_COMPRESSED)) { + if (!rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(ctx, out[i], &out_size, pk[i], SECP256K1_EC_COMPRESSED)) { /* Note that ec_pubkey_serialize should already set the output to * zero in that case, but it's not guaranteed by the API, we can't * test it and writing a VERIFY_CHECK is more complex than @@ -271,42 +285,42 @@ int rustsecp256k1zkp_v0_8_0_ec_pubkey_cmp(const rustsecp256k1zkp_v0_8_0_context* memset(out[i], 0, sizeof(out[i])); } } - return rustsecp256k1zkp_v0_8_0_memcmp_var(out[0], out[1], sizeof(out[0])); + return rustsecp256k1zkp_v0_10_0_memcmp_var(out[0], out[1], sizeof(out[0])); } -static void rustsecp256k1zkp_v0_8_0_ecdsa_signature_load(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_scalar* r, rustsecp256k1zkp_v0_8_0_scalar* s, const rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig) { +static void rustsecp256k1zkp_v0_10_0_ecdsa_signature_load(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_scalar* r, rustsecp256k1zkp_v0_10_0_scalar* s, const rustsecp256k1zkp_v0_10_0_ecdsa_signature* sig) { (void)ctx; - if (sizeof(rustsecp256k1zkp_v0_8_0_scalar) == 32) { - /* When the rustsecp256k1zkp_v0_8_0_scalar type is exactly 32 byte, use its - * representation inside rustsecp256k1zkp_v0_8_0_ecdsa_signature, as conversion is very fast. - * Note that rustsecp256k1zkp_v0_8_0_ecdsa_signature_save must use the same representation. */ + if (sizeof(rustsecp256k1zkp_v0_10_0_scalar) == 32) { + /* When the rustsecp256k1zkp_v0_10_0_scalar type is exactly 32 byte, use its + * representation inside rustsecp256k1zkp_v0_10_0_ecdsa_signature, as conversion is very fast. + * Note that rustsecp256k1zkp_v0_10_0_ecdsa_signature_save must use the same representation. */ memcpy(r, &sig->data[0], 32); memcpy(s, &sig->data[32], 32); } else { - rustsecp256k1zkp_v0_8_0_scalar_set_b32(r, &sig->data[0], NULL); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(s, &sig->data[32], NULL); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(r, &sig->data[0], NULL); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(s, &sig->data[32], NULL); } } -static void rustsecp256k1zkp_v0_8_0_ecdsa_signature_save(rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig, const rustsecp256k1zkp_v0_8_0_scalar* r, const rustsecp256k1zkp_v0_8_0_scalar* s) { - if (sizeof(rustsecp256k1zkp_v0_8_0_scalar) == 32) { +static void rustsecp256k1zkp_v0_10_0_ecdsa_signature_save(rustsecp256k1zkp_v0_10_0_ecdsa_signature* sig, const rustsecp256k1zkp_v0_10_0_scalar* r, const rustsecp256k1zkp_v0_10_0_scalar* s) { + if (sizeof(rustsecp256k1zkp_v0_10_0_scalar) == 32) { memcpy(&sig->data[0], r, 32); memcpy(&sig->data[32], s, 32); } else { - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&sig->data[0], r); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&sig->data[32], s); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&sig->data[0], r); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&sig->data[32], s); } } -int rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) { - rustsecp256k1zkp_v0_8_0_scalar r, s; +int rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) { + rustsecp256k1zkp_v0_10_0_scalar r, s; VERIFY_CHECK(ctx != NULL); ARG_CHECK(sig != NULL); ARG_CHECK(input != NULL); - if (rustsecp256k1zkp_v0_8_0_ecdsa_sig_parse(&r, &s, input, inputlen)) { - rustsecp256k1zkp_v0_8_0_ecdsa_signature_save(sig, &r, &s); + if (rustsecp256k1zkp_v0_10_0_ecdsa_sig_parse(&r, &s, input, inputlen)) { + rustsecp256k1zkp_v0_10_0_ecdsa_signature_save(sig, &r, &s); return 1; } else { memset(sig, 0, sizeof(*sig)); @@ -314,8 +328,8 @@ int rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(const rustsecp256k1zkp_v0_ } } -int rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_compact(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig, const unsigned char *input64) { - rustsecp256k1zkp_v0_8_0_scalar r, s; +int rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_compact(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_ecdsa_signature* sig, const unsigned char *input64) { + rustsecp256k1zkp_v0_10_0_scalar r, s; int ret = 1; int overflow = 0; @@ -323,76 +337,76 @@ int rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_compact(const rustsecp256k1zkp ARG_CHECK(sig != NULL); ARG_CHECK(input64 != NULL); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&r, &input64[0], &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&r, &input64[0], &overflow); ret &= !overflow; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&s, &input64[32], &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&s, &input64[32], &overflow); ret &= !overflow; if (ret) { - rustsecp256k1zkp_v0_8_0_ecdsa_signature_save(sig, &r, &s); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_save(sig, &r, &s); } else { memset(sig, 0, sizeof(*sig)); } return ret; } -int rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_der(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *output, size_t *outputlen, const rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig) { - rustsecp256k1zkp_v0_8_0_scalar r, s; +int rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_der(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *output, size_t *outputlen, const rustsecp256k1zkp_v0_10_0_ecdsa_signature* sig) { + rustsecp256k1zkp_v0_10_0_scalar r, s; VERIFY_CHECK(ctx != NULL); ARG_CHECK(output != NULL); ARG_CHECK(outputlen != NULL); ARG_CHECK(sig != NULL); - rustsecp256k1zkp_v0_8_0_ecdsa_signature_load(ctx, &r, &s, sig); - return rustsecp256k1zkp_v0_8_0_ecdsa_sig_serialize(output, outputlen, &r, &s); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_load(ctx, &r, &s, sig); + return rustsecp256k1zkp_v0_10_0_ecdsa_sig_serialize(output, outputlen, &r, &s); } -int rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_compact(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *output64, const rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig) { - rustsecp256k1zkp_v0_8_0_scalar r, s; +int rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_compact(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *output64, const rustsecp256k1zkp_v0_10_0_ecdsa_signature* sig) { + rustsecp256k1zkp_v0_10_0_scalar r, s; VERIFY_CHECK(ctx != NULL); ARG_CHECK(output64 != NULL); ARG_CHECK(sig != NULL); - rustsecp256k1zkp_v0_8_0_ecdsa_signature_load(ctx, &r, &s, sig); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&output64[0], &r); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&output64[32], &s); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_load(ctx, &r, &s, sig); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&output64[0], &r); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(&output64[32], &s); return 1; } -int rustsecp256k1zkp_v0_8_0_ecdsa_signature_normalize(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ecdsa_signature *sigout, const rustsecp256k1zkp_v0_8_0_ecdsa_signature *sigin) { - rustsecp256k1zkp_v0_8_0_scalar r, s; +int rustsecp256k1zkp_v0_10_0_ecdsa_signature_normalize(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_ecdsa_signature *sigout, const rustsecp256k1zkp_v0_10_0_ecdsa_signature *sigin) { + rustsecp256k1zkp_v0_10_0_scalar r, s; int ret = 0; VERIFY_CHECK(ctx != NULL); ARG_CHECK(sigin != NULL); - rustsecp256k1zkp_v0_8_0_ecdsa_signature_load(ctx, &r, &s, sigin); - ret = rustsecp256k1zkp_v0_8_0_scalar_is_high(&s); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_load(ctx, &r, &s, sigin); + ret = rustsecp256k1zkp_v0_10_0_scalar_is_high(&s); if (sigout != NULL) { if (ret) { - rustsecp256k1zkp_v0_8_0_scalar_negate(&s, &s); + rustsecp256k1zkp_v0_10_0_scalar_negate(&s, &s); } - rustsecp256k1zkp_v0_8_0_ecdsa_signature_save(sigout, &r, &s); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_save(sigout, &r, &s); } return ret; } -int rustsecp256k1zkp_v0_8_0_ecdsa_verify(const rustsecp256k1zkp_v0_8_0_context* ctx, const rustsecp256k1zkp_v0_8_0_ecdsa_signature *sig, const unsigned char *msghash32, const rustsecp256k1zkp_v0_8_0_pubkey *pubkey) { - rustsecp256k1zkp_v0_8_0_ge q; - rustsecp256k1zkp_v0_8_0_scalar r, s; - rustsecp256k1zkp_v0_8_0_scalar m; +int rustsecp256k1zkp_v0_10_0_ecdsa_verify(const rustsecp256k1zkp_v0_10_0_context* ctx, const rustsecp256k1zkp_v0_10_0_ecdsa_signature *sig, const unsigned char *msghash32, const rustsecp256k1zkp_v0_10_0_pubkey *pubkey) { + rustsecp256k1zkp_v0_10_0_ge q; + rustsecp256k1zkp_v0_10_0_scalar r, s; + rustsecp256k1zkp_v0_10_0_scalar m; VERIFY_CHECK(ctx != NULL); ARG_CHECK(msghash32 != NULL); ARG_CHECK(sig != NULL); ARG_CHECK(pubkey != NULL); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&m, msghash32, NULL); - rustsecp256k1zkp_v0_8_0_ecdsa_signature_load(ctx, &r, &s, sig); - return (!rustsecp256k1zkp_v0_8_0_scalar_is_high(&s) && - rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &q, pubkey) && - rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&r, &s, &q, &m)); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&m, msghash32, NULL); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_load(ctx, &r, &s, sig); + return (!rustsecp256k1zkp_v0_10_0_scalar_is_high(&s) && + rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, &q, pubkey) && + rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&r, &s, &q, &m)); } static SECP256K1_INLINE void buffer_append(unsigned char *buf, unsigned int *offset, const void *data, unsigned int len) { @@ -403,12 +417,12 @@ static SECP256K1_INLINE void buffer_append(unsigned char *buf, unsigned int *off static int nonce_function_rfc6979(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int counter) { unsigned char keydata[112]; unsigned int offset = 0; - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256 rng; + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256 rng; unsigned int i; - rustsecp256k1zkp_v0_8_0_scalar msg; + rustsecp256k1zkp_v0_10_0_scalar msg; unsigned char msgmod32[32]; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&msg, msg32, NULL); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(msgmod32, &msg); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&msg, msg32, NULL); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(msgmod32, &msg); /* We feed a byte array to the PRNG as input, consisting of: * - the private key (32 bytes) and reduced message (32 bytes), see RFC 6979 3.2d. * - optionally 32 extra bytes of data, see RFC 6979 3.6 Additional Data. @@ -425,80 +439,80 @@ static int nonce_function_rfc6979(unsigned char *nonce32, const unsigned char *m if (algo16 != NULL) { buffer_append(keydata, &offset, algo16, 16); } - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_initialize(&rng, keydata, offset); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_initialize(&rng, keydata, offset); memset(keydata, 0, sizeof(keydata)); for (i = 0; i <= counter; i++) { - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_generate(&rng, nonce32, 32); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_generate(&rng, nonce32, 32); } - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_finalize(&rng); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_finalize(&rng); return 1; } -const rustsecp256k1zkp_v0_8_0_nonce_function rustsecp256k1zkp_v0_8_0_nonce_function_rfc6979 = nonce_function_rfc6979; -const rustsecp256k1zkp_v0_8_0_nonce_function rustsecp256k1zkp_v0_8_0_nonce_function_default = nonce_function_rfc6979; +const rustsecp256k1zkp_v0_10_0_nonce_function rustsecp256k1zkp_v0_10_0_nonce_function_rfc6979 = nonce_function_rfc6979; +const rustsecp256k1zkp_v0_10_0_nonce_function rustsecp256k1zkp_v0_10_0_nonce_function_default = nonce_function_rfc6979; -static int rustsecp256k1zkp_v0_8_0_ecdsa_sign_inner(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_scalar* r, rustsecp256k1zkp_v0_8_0_scalar* s, int* recid, rustsecp256k1zkp_v0_8_0_sha256* s2c_sha, rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening *s2c_opening, const unsigned char* s2c_data32, const unsigned char *msg32, const unsigned char *seckey, rustsecp256k1zkp_v0_8_0_nonce_function noncefp, const void* noncedata) { - rustsecp256k1zkp_v0_8_0_scalar sec, non, msg; +static int rustsecp256k1zkp_v0_10_0_ecdsa_sign_inner(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_scalar* r, rustsecp256k1zkp_v0_10_0_scalar* s, int* recid, rustsecp256k1zkp_v0_10_0_sha256* s2c_sha, rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening *s2c_opening, const unsigned char* s2c_data32, const unsigned char *msg32, const unsigned char *seckey, rustsecp256k1zkp_v0_10_0_nonce_function noncefp, const void* noncedata) { + rustsecp256k1zkp_v0_10_0_scalar sec, non, msg; int ret = 0; int is_sec_valid; unsigned char nonce32[32]; unsigned int count = 0; /* Default initialization here is important so we won't pass uninit values to the cmov in the end */ - *r = rustsecp256k1zkp_v0_8_0_scalar_zero; - *s = rustsecp256k1zkp_v0_8_0_scalar_zero; + *r = rustsecp256k1zkp_v0_10_0_scalar_zero; + *s = rustsecp256k1zkp_v0_10_0_scalar_zero; if (recid) { *recid = 0; } if (noncefp == NULL) { - noncefp = rustsecp256k1zkp_v0_8_0_nonce_function_default; + noncefp = rustsecp256k1zkp_v0_10_0_nonce_function_default; } /* sign-to-contract commitments only work with the default nonce function, * because we need to ensure that s2c_data is actually hashed into the nonce and * not just ignored. Otherwise an attacker can exfiltrate the secret key by * signing the same message thrice with different commitments. */ - VERIFY_CHECK(s2c_data32 == NULL || noncefp == rustsecp256k1zkp_v0_8_0_nonce_function_default); + VERIFY_CHECK(s2c_data32 == NULL || noncefp == rustsecp256k1zkp_v0_10_0_nonce_function_default); /* Fail if the secret key is invalid. */ - is_sec_valid = rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(&sec, seckey); - rustsecp256k1zkp_v0_8_0_scalar_cmov(&sec, &rustsecp256k1zkp_v0_8_0_scalar_one, !is_sec_valid); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&msg, msg32, NULL); + is_sec_valid = rustsecp256k1zkp_v0_10_0_scalar_set_b32_seckey(&sec, seckey); + rustsecp256k1zkp_v0_10_0_scalar_cmov(&sec, &rustsecp256k1zkp_v0_10_0_scalar_one, !is_sec_valid); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&msg, msg32, NULL); while (1) { int is_nonce_valid; ret = !!noncefp(nonce32, msg32, seckey, NULL, (void*)noncedata, count); if (!ret) { break; } - is_nonce_valid = rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(&non, nonce32); + is_nonce_valid = rustsecp256k1zkp_v0_10_0_scalar_set_b32_seckey(&non, nonce32); /* The nonce is still secret here, but it being invalid is is less likely than 1:2^255. */ - rustsecp256k1zkp_v0_8_0_declassify(ctx, &is_nonce_valid, sizeof(is_nonce_valid)); + rustsecp256k1zkp_v0_10_0_declassify(ctx, &is_nonce_valid, sizeof(is_nonce_valid)); if (is_nonce_valid) { if (s2c_data32 != NULL) { - rustsecp256k1zkp_v0_8_0_gej nonce_pj; - rustsecp256k1zkp_v0_8_0_ge nonce_p; + rustsecp256k1zkp_v0_10_0_gej nonce_pj; + rustsecp256k1zkp_v0_10_0_ge nonce_p; /* Compute original nonce commitment/pubkey */ - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &nonce_pj, &non); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&nonce_p, &nonce_pj); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&ctx->ecmult_gen_ctx, &nonce_pj, &non); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&nonce_p, &nonce_pj); if (s2c_opening != NULL) { - rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_save(s2c_opening, &nonce_p); + rustsecp256k1zkp_v0_10_0_ecdsa_s2c_opening_save(s2c_opening, &nonce_p); } /* Because the nonce is valid, the nonce point isn't the point * at infinity and we can declassify that information to be able to * serialize the point. */ - rustsecp256k1zkp_v0_8_0_declassify(ctx, &nonce_p.infinity, sizeof(nonce_p.infinity)); + rustsecp256k1zkp_v0_10_0_declassify(ctx, &nonce_p.infinity, sizeof(nonce_p.infinity)); /* Tweak nonce with s2c commitment. */ - ret = rustsecp256k1zkp_v0_8_0_ec_commit_seckey(&non, &nonce_p, s2c_sha, s2c_data32, 32); - rustsecp256k1zkp_v0_8_0_declassify(ctx, &ret, sizeof(ret)); /* may be secret that the tweak falied, but happens with negligible probability */ + ret = rustsecp256k1zkp_v0_10_0_ec_commit_seckey(&non, &nonce_p, s2c_sha, s2c_data32, 32); + rustsecp256k1zkp_v0_10_0_declassify(ctx, &ret, sizeof(ret)); /* may be secret that the tweak falied, but happens with negligible probability */ if (!ret) { break; } } - ret = rustsecp256k1zkp_v0_8_0_ecdsa_sig_sign(&ctx->ecmult_gen_ctx, r, s, &sec, &msg, &non, recid); + ret = rustsecp256k1zkp_v0_10_0_ecdsa_sig_sign(&ctx->ecmult_gen_ctx, r, s, &sec, &msg, &non, recid); /* The final signature is no longer a secret, nor is the fact that we were successful or not. */ - rustsecp256k1zkp_v0_8_0_declassify(ctx, &ret, sizeof(ret)); + rustsecp256k1zkp_v0_10_0_declassify(ctx, &ret, sizeof(ret)); if (ret) { break; } @@ -510,202 +524,202 @@ static int rustsecp256k1zkp_v0_8_0_ecdsa_sign_inner(const rustsecp256k1zkp_v0_8_ * used as a branching variable. */ ret &= is_sec_valid; memset(nonce32, 0, 32); - rustsecp256k1zkp_v0_8_0_scalar_clear(&msg); - rustsecp256k1zkp_v0_8_0_scalar_clear(&non); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sec); - rustsecp256k1zkp_v0_8_0_scalar_cmov(r, &rustsecp256k1zkp_v0_8_0_scalar_zero, !ret); - rustsecp256k1zkp_v0_8_0_scalar_cmov(s, &rustsecp256k1zkp_v0_8_0_scalar_zero, !ret); + rustsecp256k1zkp_v0_10_0_scalar_clear(&msg); + rustsecp256k1zkp_v0_10_0_scalar_clear(&non); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sec); + rustsecp256k1zkp_v0_10_0_scalar_cmov(r, &rustsecp256k1zkp_v0_10_0_scalar_zero, !ret); + rustsecp256k1zkp_v0_10_0_scalar_cmov(s, &rustsecp256k1zkp_v0_10_0_scalar_zero, !ret); if (recid) { const int zero = 0; - rustsecp256k1zkp_v0_8_0_int_cmov(recid, &zero, !ret); + rustsecp256k1zkp_v0_10_0_int_cmov(recid, &zero, !ret); } return ret; } -int rustsecp256k1zkp_v0_8_0_ecdsa_sign(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ecdsa_signature *signature, const unsigned char *msghash32, const unsigned char *seckey, rustsecp256k1zkp_v0_8_0_nonce_function noncefp, const void* noncedata) { - rustsecp256k1zkp_v0_8_0_scalar r, s; +int rustsecp256k1zkp_v0_10_0_ecdsa_sign(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_ecdsa_signature *signature, const unsigned char *msghash32, const unsigned char *seckey, rustsecp256k1zkp_v0_10_0_nonce_function noncefp, const void* noncedata) { + rustsecp256k1zkp_v0_10_0_scalar r, s; int ret; VERIFY_CHECK(ctx != NULL); - ARG_CHECK(rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); ARG_CHECK(msghash32 != NULL); ARG_CHECK(signature != NULL); ARG_CHECK(seckey != NULL); - ret = rustsecp256k1zkp_v0_8_0_ecdsa_sign_inner(ctx, &r, &s, NULL, NULL, NULL, NULL, msghash32, seckey, noncefp, noncedata); - rustsecp256k1zkp_v0_8_0_ecdsa_signature_save(signature, &r, &s); + ret = rustsecp256k1zkp_v0_10_0_ecdsa_sign_inner(ctx, &r, &s, NULL, NULL, NULL, NULL, msghash32, seckey, noncefp, noncedata); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_save(signature, &r, &s); return ret; } -int rustsecp256k1zkp_v0_8_0_ec_seckey_verify(const rustsecp256k1zkp_v0_8_0_context* ctx, const unsigned char *seckey) { - rustsecp256k1zkp_v0_8_0_scalar sec; +int rustsecp256k1zkp_v0_10_0_ec_seckey_verify(const rustsecp256k1zkp_v0_10_0_context* ctx, const unsigned char *seckey) { + rustsecp256k1zkp_v0_10_0_scalar sec; int ret; VERIFY_CHECK(ctx != NULL); ARG_CHECK(seckey != NULL); - ret = rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(&sec, seckey); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sec); + ret = rustsecp256k1zkp_v0_10_0_scalar_set_b32_seckey(&sec, seckey); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sec); return ret; } -static int rustsecp256k1zkp_v0_8_0_ec_pubkey_create_helper(const rustsecp256k1zkp_v0_8_0_ecmult_gen_context *ecmult_gen_ctx, rustsecp256k1zkp_v0_8_0_scalar *seckey_scalar, rustsecp256k1zkp_v0_8_0_ge *p, const unsigned char *seckey) { - rustsecp256k1zkp_v0_8_0_gej pj; +static int rustsecp256k1zkp_v0_10_0_ec_pubkey_create_helper(const rustsecp256k1zkp_v0_10_0_ecmult_gen_context *ecmult_gen_ctx, rustsecp256k1zkp_v0_10_0_scalar *seckey_scalar, rustsecp256k1zkp_v0_10_0_ge *p, const unsigned char *seckey) { + rustsecp256k1zkp_v0_10_0_gej pj; int ret; - ret = rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(seckey_scalar, seckey); - rustsecp256k1zkp_v0_8_0_scalar_cmov(seckey_scalar, &rustsecp256k1zkp_v0_8_0_scalar_one, !ret); + ret = rustsecp256k1zkp_v0_10_0_scalar_set_b32_seckey(seckey_scalar, seckey); + rustsecp256k1zkp_v0_10_0_scalar_cmov(seckey_scalar, &rustsecp256k1zkp_v0_10_0_scalar_one, !ret); - rustsecp256k1zkp_v0_8_0_ecmult_gen(ecmult_gen_ctx, &pj, seckey_scalar); - rustsecp256k1zkp_v0_8_0_ge_set_gej(p, &pj); + rustsecp256k1zkp_v0_10_0_ecmult_gen(ecmult_gen_ctx, &pj, seckey_scalar); + rustsecp256k1zkp_v0_10_0_ge_set_gej(p, &pj); return ret; } -int rustsecp256k1zkp_v0_8_0_ec_pubkey_create(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pubkey *pubkey, const unsigned char *seckey) { - rustsecp256k1zkp_v0_8_0_ge p; - rustsecp256k1zkp_v0_8_0_scalar seckey_scalar; +int rustsecp256k1zkp_v0_10_0_ec_pubkey_create(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_pubkey *pubkey, const unsigned char *seckey) { + rustsecp256k1zkp_v0_10_0_ge p; + rustsecp256k1zkp_v0_10_0_scalar seckey_scalar; int ret = 0; VERIFY_CHECK(ctx != NULL); ARG_CHECK(pubkey != NULL); memset(pubkey, 0, sizeof(*pubkey)); - ARG_CHECK(rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); ARG_CHECK(seckey != NULL); - ret = rustsecp256k1zkp_v0_8_0_ec_pubkey_create_helper(&ctx->ecmult_gen_ctx, &seckey_scalar, &p, seckey); - rustsecp256k1zkp_v0_8_0_pubkey_save(pubkey, &p); - rustsecp256k1zkp_v0_8_0_memczero(pubkey, sizeof(*pubkey), !ret); + ret = rustsecp256k1zkp_v0_10_0_ec_pubkey_create_helper(&ctx->ecmult_gen_ctx, &seckey_scalar, &p, seckey); + rustsecp256k1zkp_v0_10_0_pubkey_save(pubkey, &p); + rustsecp256k1zkp_v0_10_0_memczero(pubkey, sizeof(*pubkey), !ret); - rustsecp256k1zkp_v0_8_0_scalar_clear(&seckey_scalar); + rustsecp256k1zkp_v0_10_0_scalar_clear(&seckey_scalar); return ret; } -int rustsecp256k1zkp_v0_8_0_ec_seckey_negate(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *seckey) { - rustsecp256k1zkp_v0_8_0_scalar sec; +int rustsecp256k1zkp_v0_10_0_ec_seckey_negate(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *seckey) { + rustsecp256k1zkp_v0_10_0_scalar sec; int ret = 0; VERIFY_CHECK(ctx != NULL); ARG_CHECK(seckey != NULL); - ret = rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(&sec, seckey); - rustsecp256k1zkp_v0_8_0_scalar_cmov(&sec, &rustsecp256k1zkp_v0_8_0_scalar_zero, !ret); - rustsecp256k1zkp_v0_8_0_scalar_negate(&sec, &sec); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(seckey, &sec); + ret = rustsecp256k1zkp_v0_10_0_scalar_set_b32_seckey(&sec, seckey); + rustsecp256k1zkp_v0_10_0_scalar_cmov(&sec, &rustsecp256k1zkp_v0_10_0_scalar_zero, !ret); + rustsecp256k1zkp_v0_10_0_scalar_negate(&sec, &sec); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(seckey, &sec); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sec); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sec); return ret; } -int rustsecp256k1zkp_v0_8_0_ec_privkey_negate(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *seckey) { - return rustsecp256k1zkp_v0_8_0_ec_seckey_negate(ctx, seckey); +int rustsecp256k1zkp_v0_10_0_ec_privkey_negate(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *seckey) { + return rustsecp256k1zkp_v0_10_0_ec_seckey_negate(ctx, seckey); } -int rustsecp256k1zkp_v0_8_0_ec_pubkey_negate(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pubkey *pubkey) { +int rustsecp256k1zkp_v0_10_0_ec_pubkey_negate(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_pubkey *pubkey) { int ret = 0; - rustsecp256k1zkp_v0_8_0_ge p; + rustsecp256k1zkp_v0_10_0_ge p; VERIFY_CHECK(ctx != NULL); ARG_CHECK(pubkey != NULL); - ret = rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &p, pubkey); + ret = rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, &p, pubkey); memset(pubkey, 0, sizeof(*pubkey)); if (ret) { - rustsecp256k1zkp_v0_8_0_ge_neg(&p, &p); - rustsecp256k1zkp_v0_8_0_pubkey_save(pubkey, &p); + rustsecp256k1zkp_v0_10_0_ge_neg(&p, &p); + rustsecp256k1zkp_v0_10_0_pubkey_save(pubkey, &p); } return ret; } -static int rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add_helper(rustsecp256k1zkp_v0_8_0_scalar *sec, const unsigned char *tweak32) { - rustsecp256k1zkp_v0_8_0_scalar term; +static int rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add_helper(rustsecp256k1zkp_v0_10_0_scalar *sec, const unsigned char *tweak32) { + rustsecp256k1zkp_v0_10_0_scalar term; int overflow = 0; int ret = 0; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&term, tweak32, &overflow); - ret = (!overflow) & rustsecp256k1zkp_v0_8_0_eckey_privkey_tweak_add(sec, &term); - rustsecp256k1zkp_v0_8_0_scalar_clear(&term); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&term, tweak32, &overflow); + ret = (!overflow) & rustsecp256k1zkp_v0_10_0_eckey_privkey_tweak_add(sec, &term); + rustsecp256k1zkp_v0_10_0_scalar_clear(&term); return ret; } -int rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *seckey, const unsigned char *tweak32) { - rustsecp256k1zkp_v0_8_0_scalar sec; +int rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *seckey, const unsigned char *tweak32) { + rustsecp256k1zkp_v0_10_0_scalar sec; int ret = 0; VERIFY_CHECK(ctx != NULL); ARG_CHECK(seckey != NULL); ARG_CHECK(tweak32 != NULL); - ret = rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(&sec, seckey); - ret &= rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add_helper(&sec, tweak32); - rustsecp256k1zkp_v0_8_0_scalar_cmov(&sec, &rustsecp256k1zkp_v0_8_0_scalar_zero, !ret); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(seckey, &sec); + ret = rustsecp256k1zkp_v0_10_0_scalar_set_b32_seckey(&sec, seckey); + ret &= rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add_helper(&sec, tweak32); + rustsecp256k1zkp_v0_10_0_scalar_cmov(&sec, &rustsecp256k1zkp_v0_10_0_scalar_zero, !ret); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(seckey, &sec); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sec); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sec); return ret; } -int rustsecp256k1zkp_v0_8_0_ec_privkey_tweak_add(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *seckey, const unsigned char *tweak32) { - return rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add(ctx, seckey, tweak32); +int rustsecp256k1zkp_v0_10_0_ec_privkey_tweak_add(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *seckey, const unsigned char *tweak32) { + return rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add(ctx, seckey, tweak32); } -static int rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add_helper(rustsecp256k1zkp_v0_8_0_ge *p, const unsigned char *tweak32) { - rustsecp256k1zkp_v0_8_0_scalar term; +static int rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add_helper(rustsecp256k1zkp_v0_10_0_ge *p, const unsigned char *tweak32) { + rustsecp256k1zkp_v0_10_0_scalar term; int overflow = 0; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&term, tweak32, &overflow); - return !overflow && rustsecp256k1zkp_v0_8_0_eckey_pubkey_tweak_add(p, &term); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&term, tweak32, &overflow); + return !overflow && rustsecp256k1zkp_v0_10_0_eckey_pubkey_tweak_add(p, &term); } -int rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pubkey *pubkey, const unsigned char *tweak32) { - rustsecp256k1zkp_v0_8_0_ge p; +int rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_pubkey *pubkey, const unsigned char *tweak32) { + rustsecp256k1zkp_v0_10_0_ge p; int ret = 0; VERIFY_CHECK(ctx != NULL); ARG_CHECK(pubkey != NULL); ARG_CHECK(tweak32 != NULL); - ret = rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &p, pubkey); + ret = rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, &p, pubkey); memset(pubkey, 0, sizeof(*pubkey)); - ret = ret && rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add_helper(&p, tweak32); + ret = ret && rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add_helper(&p, tweak32); if (ret) { - rustsecp256k1zkp_v0_8_0_pubkey_save(pubkey, &p); + rustsecp256k1zkp_v0_10_0_pubkey_save(pubkey, &p); } return ret; } -int rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_mul(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *seckey, const unsigned char *tweak32) { - rustsecp256k1zkp_v0_8_0_scalar factor; - rustsecp256k1zkp_v0_8_0_scalar sec; +int rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_mul(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *seckey, const unsigned char *tweak32) { + rustsecp256k1zkp_v0_10_0_scalar factor; + rustsecp256k1zkp_v0_10_0_scalar sec; int ret = 0; int overflow = 0; VERIFY_CHECK(ctx != NULL); ARG_CHECK(seckey != NULL); ARG_CHECK(tweak32 != NULL); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&factor, tweak32, &overflow); - ret = rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(&sec, seckey); - ret &= (!overflow) & rustsecp256k1zkp_v0_8_0_eckey_privkey_tweak_mul(&sec, &factor); - rustsecp256k1zkp_v0_8_0_scalar_cmov(&sec, &rustsecp256k1zkp_v0_8_0_scalar_zero, !ret); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(seckey, &sec); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&factor, tweak32, &overflow); + ret = rustsecp256k1zkp_v0_10_0_scalar_set_b32_seckey(&sec, seckey); + ret &= (!overflow) & rustsecp256k1zkp_v0_10_0_eckey_privkey_tweak_mul(&sec, &factor); + rustsecp256k1zkp_v0_10_0_scalar_cmov(&sec, &rustsecp256k1zkp_v0_10_0_scalar_zero, !ret); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(seckey, &sec); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sec); - rustsecp256k1zkp_v0_8_0_scalar_clear(&factor); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sec); + rustsecp256k1zkp_v0_10_0_scalar_clear(&factor); return ret; } -int rustsecp256k1zkp_v0_8_0_ec_privkey_tweak_mul(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *seckey, const unsigned char *tweak32) { - return rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_mul(ctx, seckey, tweak32); +int rustsecp256k1zkp_v0_10_0_ec_privkey_tweak_mul(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *seckey, const unsigned char *tweak32) { + return rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_mul(ctx, seckey, tweak32); } -int rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_mul(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pubkey *pubkey, const unsigned char *tweak32) { - rustsecp256k1zkp_v0_8_0_ge p; - rustsecp256k1zkp_v0_8_0_scalar factor; +int rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_mul(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_pubkey *pubkey, const unsigned char *tweak32) { + rustsecp256k1zkp_v0_10_0_ge p; + rustsecp256k1zkp_v0_10_0_scalar factor; int ret = 0; int overflow = 0; VERIFY_CHECK(ctx != NULL); ARG_CHECK(pubkey != NULL); ARG_CHECK(tweak32 != NULL); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&factor, tweak32, &overflow); - ret = !overflow && rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &p, pubkey); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&factor, tweak32, &overflow); + ret = !overflow && rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, &p, pubkey); memset(pubkey, 0, sizeof(*pubkey)); if (ret) { - if (rustsecp256k1zkp_v0_8_0_eckey_pubkey_tweak_mul(&p, &factor)) { - rustsecp256k1zkp_v0_8_0_pubkey_save(pubkey, &p); + if (rustsecp256k1zkp_v0_10_0_eckey_pubkey_tweak_mul(&p, &factor)) { + rustsecp256k1zkp_v0_10_0_pubkey_save(pubkey, &p); } else { ret = 0; } @@ -714,18 +728,20 @@ int rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_mul(const rustsecp256k1zkp_v0_8_0_co return ret; } -int rustsecp256k1zkp_v0_8_0_context_randomize(rustsecp256k1zkp_v0_8_0_context* ctx, const unsigned char *seed32) { +int rustsecp256k1zkp_v0_10_0_context_randomize(rustsecp256k1zkp_v0_10_0_context* ctx, const unsigned char *seed32) { VERIFY_CHECK(ctx != NULL); - if (rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)) { - rustsecp256k1zkp_v0_8_0_ecmult_gen_blind(&ctx->ecmult_gen_ctx, seed32); + ARG_CHECK(rustsecp256k1zkp_v0_10_0_context_is_proper(ctx)); + + if (rustsecp256k1zkp_v0_10_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)) { + rustsecp256k1zkp_v0_10_0_ecmult_gen_blind(&ctx->ecmult_gen_ctx, seed32); } return 1; } -int rustsecp256k1zkp_v0_8_0_ec_pubkey_combine(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pubkey *pubnonce, const rustsecp256k1zkp_v0_8_0_pubkey * const *pubnonces, size_t n) { +int rustsecp256k1zkp_v0_10_0_ec_pubkey_combine(const rustsecp256k1zkp_v0_10_0_context* ctx, rustsecp256k1zkp_v0_10_0_pubkey *pubnonce, const rustsecp256k1zkp_v0_10_0_pubkey * const *pubnonces, size_t n) { size_t i; - rustsecp256k1zkp_v0_8_0_gej Qj; - rustsecp256k1zkp_v0_8_0_ge Q; + rustsecp256k1zkp_v0_10_0_gej Qj; + rustsecp256k1zkp_v0_10_0_ge Q; VERIFY_CHECK(ctx != NULL); ARG_CHECK(pubnonce != NULL); @@ -733,34 +749,64 @@ int rustsecp256k1zkp_v0_8_0_ec_pubkey_combine(const rustsecp256k1zkp_v0_8_0_cont ARG_CHECK(n >= 1); ARG_CHECK(pubnonces != NULL); - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&Qj); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&Qj); for (i = 0; i < n; i++) { ARG_CHECK(pubnonces[i] != NULL); - rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &Q, pubnonces[i]); - rustsecp256k1zkp_v0_8_0_gej_add_ge(&Qj, &Qj, &Q); + rustsecp256k1zkp_v0_10_0_pubkey_load(ctx, &Q, pubnonces[i]); + rustsecp256k1zkp_v0_10_0_gej_add_ge(&Qj, &Qj, &Q); } - if (rustsecp256k1zkp_v0_8_0_gej_is_infinity(&Qj)) { + if (rustsecp256k1zkp_v0_10_0_gej_is_infinity(&Qj)) { return 0; } - rustsecp256k1zkp_v0_8_0_ge_set_gej(&Q, &Qj); - rustsecp256k1zkp_v0_8_0_pubkey_save(pubnonce, &Q); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&Q, &Qj); + rustsecp256k1zkp_v0_10_0_pubkey_save(pubnonce, &Q); return 1; } -int rustsecp256k1zkp_v0_8_0_tagged_sha256(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *hash32, const unsigned char *tag, size_t taglen, const unsigned char *msg, size_t msglen) { - rustsecp256k1zkp_v0_8_0_sha256 sha; +int rustsecp256k1zkp_v0_10_0_tagged_sha256(const rustsecp256k1zkp_v0_10_0_context* ctx, unsigned char *hash32, const unsigned char *tag, size_t taglen, const unsigned char *msg, size_t msglen) { + rustsecp256k1zkp_v0_10_0_sha256 sha; VERIFY_CHECK(ctx != NULL); ARG_CHECK(hash32 != NULL); ARG_CHECK(tag != NULL); ARG_CHECK(msg != NULL); - rustsecp256k1zkp_v0_8_0_sha256_initialize_tagged(&sha, tag, taglen); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, msg, msglen); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, hash32); + rustsecp256k1zkp_v0_10_0_sha256_initialize_tagged(&sha, tag, taglen); + rustsecp256k1zkp_v0_10_0_sha256_write(&sha, msg, msglen); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&sha, hash32); return 1; } +/* Outputs 33 zero bytes if the given group element is the point at infinity and + * otherwise outputs the compressed serialization */ +static void rustsecp256k1zkp_v0_10_0_ge_serialize_ext(unsigned char *out33, rustsecp256k1zkp_v0_10_0_ge* ge) { + if (rustsecp256k1zkp_v0_10_0_ge_is_infinity(ge)) { + memset(out33, 0, 33); + } else { + int ret; + size_t size = 33; + ret = rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(ge, out33, &size, 1); +#ifdef VERIFY + /* Serialize must succeed because the point is not at infinity */ + VERIFY_CHECK(ret && size == 33); +#else + (void) ret; +#endif + } +} + +/* Outputs the point at infinity if the given byte array is all zero, otherwise + * attempts to parse compressed point serialization. */ +static int rustsecp256k1zkp_v0_10_0_ge_parse_ext(rustsecp256k1zkp_v0_10_0_ge* ge, const unsigned char *in33) { + unsigned char zeros[33] = { 0 }; + + if (rustsecp256k1zkp_v0_10_0_memcmp_var(in33, zeros, sizeof(zeros)) == 0) { + rustsecp256k1zkp_v0_10_0_ge_set_infinity(ge); + return 1; + } + return rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(ge, in33, 33); +} + #ifdef ENABLE_MODULE_BPPP #include "modules/bppp/main_impl.h" #endif @@ -781,6 +827,14 @@ int rustsecp256k1zkp_v0_8_0_tagged_sha256(const rustsecp256k1zkp_v0_8_0_context* #include "modules/schnorrsig/main_impl.h" #endif +#ifdef ENABLE_MODULE_SCHNORRSIG_HALFAGG +#include "modules/schnorrsig_halfagg/main_impl.h" +#endif + +#ifdef ENABLE_MODULE_ELLSWIFT +#include "modules/ellswift/main_impl.h" +#endif + #ifdef ENABLE_MODULE_ECDSA_S2C #include "modules/ecdsa_s2c/main_impl.h" #endif @@ -808,4 +862,3 @@ int rustsecp256k1zkp_v0_8_0_tagged_sha256(const rustsecp256k1zkp_v0_8_0_context* #ifdef ENABLE_MODULE_SURJECTIONPROOF #include "modules/surjection/main_impl.h" #endif - diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/secp256k1.c.orig b/secp256k1-zkp-sys/depend/secp256k1/src/secp256k1.c.orig deleted file mode 100644 index b378a749..00000000 --- a/secp256k1-zkp-sys/depend/secp256k1/src/secp256k1.c.orig +++ /dev/null @@ -1,850 +0,0 @@ -/*********************************************************************** - * Copyright (c) 2013-2015 Pieter Wuille * - * Distributed under the MIT software license, see the accompanying * - * file COPYING or https://www.opensource.org/licenses/mit-license.php.* - ***********************************************************************/ - -#define SECP256K1_BUILD - -#include "../include/secp256k1.h" -#include "../include/secp256k1_preallocated.h" - -#include "assumptions.h" -#include "util.h" -#include "field_impl.h" -#include "scalar_impl.h" -#include "group_impl.h" -#include "eccommit_impl.h" -#include "ecmult_impl.h" -#include "ecmult_const_impl.h" -#include "ecmult_gen_impl.h" -#include "ecdsa_impl.h" -#include "eckey_impl.h" -#include "hash_impl.h" -#include "scratch_impl.h" -#include "selftest.h" - -#ifdef SECP256K1_NO_BUILD -# error "secp256k1.h processed without SECP256K1_BUILD defined while building secp256k1.c" -#endif - -#if defined(VALGRIND) -#include -#endif - -#ifdef ENABLE_MODULE_GENERATOR -#include "include/secp256k1_generator.h" -#endif - -#ifdef ENABLE_MODULE_RANGEPROOF -#include "include/secp256k1_rangeproof.h" -#endif - -#ifdef ENABLE_MODULE_ECDSA_S2C -#include "include/secp256k1_ecdsa_s2c.h" -static void rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_save(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening* opening, rustsecp256k1zkp_v0_8_0_ge* ge); -#else -typedef void rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening; -static void rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_save(rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening* opening, rustsecp256k1zkp_v0_8_0_ge* ge) { - (void) opening; - (void) ge; - VERIFY_CHECK(0); -} -#endif - -#define ARG_CHECK(cond) do { \ - if (EXPECT(!(cond), 0)) { \ - rustsecp256k1zkp_v0_8_0_callback_call(&ctx->illegal_callback, #cond); \ - return 0; \ - } \ -} while(0) - -#define ARG_CHECK_NO_RETURN(cond) do { \ - if (EXPECT(!(cond), 0)) { \ - rustsecp256k1zkp_v0_8_0_callback_call(&ctx->illegal_callback, #cond); \ - } \ -} while(0) - -struct rustsecp256k1zkp_v0_8_0_context_struct { - rustsecp256k1zkp_v0_8_0_ecmult_gen_context ecmult_gen_ctx; - rustsecp256k1zkp_v0_8_0_callback illegal_callback; - rustsecp256k1zkp_v0_8_0_callback error_callback; - int declassify; -}; - -static const rustsecp256k1zkp_v0_8_0_context rustsecp256k1zkp_v0_8_0_context_no_precomp_ = { - { 0 }, - { rustsecp256k1zkp_v0_8_0_default_illegal_callback_fn, 0 }, - { rustsecp256k1zkp_v0_8_0_default_error_callback_fn, 0 }, - 0 -}; -const rustsecp256k1zkp_v0_8_0_context *rustsecp256k1zkp_v0_8_0_context_no_precomp = &rustsecp256k1zkp_v0_8_0_context_no_precomp_; - -size_t rustsecp256k1zkp_v0_8_0_context_preallocated_size(unsigned int flags) { - size_t ret = sizeof(rustsecp256k1zkp_v0_8_0_context); - /* A return value of 0 is reserved as an indicator for errors when we call this function internally. */ - VERIFY_CHECK(ret != 0); - - if (EXPECT((flags & SECP256K1_FLAGS_TYPE_MASK) != SECP256K1_FLAGS_TYPE_CONTEXT, 0)) { - rustsecp256k1zkp_v0_8_0_callback_call(&default_illegal_callback, - "Invalid flags"); - return 0; - } - - return ret; -} - -size_t rustsecp256k1zkp_v0_8_0_context_preallocated_clone_size(const rustsecp256k1zkp_v0_8_0_context* ctx) { - size_t ret = sizeof(rustsecp256k1zkp_v0_8_0_context); - VERIFY_CHECK(ctx != NULL); - return ret; -} - -rustsecp256k1zkp_v0_8_0_context* rustsecp256k1zkp_v0_8_0_context_preallocated_create(void* prealloc, unsigned int flags) { - size_t prealloc_size; - rustsecp256k1zkp_v0_8_0_context* ret; - - if (!rustsecp256k1zkp_v0_8_0_selftest()) { - rustsecp256k1zkp_v0_8_0_callback_call(&default_error_callback, "self test failed"); - } - - prealloc_size = rustsecp256k1zkp_v0_8_0_context_preallocated_size(flags); - if (prealloc_size == 0) { - return NULL; - } - VERIFY_CHECK(prealloc != NULL); - ret = (rustsecp256k1zkp_v0_8_0_context*)prealloc; - ret->illegal_callback = default_illegal_callback; - ret->error_callback = default_error_callback; - - /* Flags have been checked by rustsecp256k1zkp_v0_8_0_context_preallocated_size. */ - VERIFY_CHECK((flags & SECP256K1_FLAGS_TYPE_MASK) == SECP256K1_FLAGS_TYPE_CONTEXT); - rustsecp256k1zkp_v0_8_0_ecmult_gen_context_build(&ret->ecmult_gen_ctx); - ret->declassify = !!(flags & SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY); - - return ret; -} - -rustsecp256k1zkp_v0_8_0_context* rustsecp256k1zkp_v0_8_0_context_create(unsigned int flags) { - size_t const prealloc_size = rustsecp256k1zkp_v0_8_0_context_preallocated_size(flags); - rustsecp256k1zkp_v0_8_0_context* ctx = (rustsecp256k1zkp_v0_8_0_context*)checked_malloc(&default_error_callback, prealloc_size); - if (EXPECT(rustsecp256k1zkp_v0_8_0_context_preallocated_create(ctx, flags) == NULL, 0)) { - free(ctx); - return NULL; - } - - return ctx; -} - -rustsecp256k1zkp_v0_8_0_context* rustsecp256k1zkp_v0_8_0_context_preallocated_clone(const rustsecp256k1zkp_v0_8_0_context* ctx, void* prealloc) { - rustsecp256k1zkp_v0_8_0_context* ret; - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(prealloc != NULL); - - ret = (rustsecp256k1zkp_v0_8_0_context*)prealloc; - *ret = *ctx; - return ret; -} - -rustsecp256k1zkp_v0_8_0_context* rustsecp256k1zkp_v0_8_0_context_clone(const rustsecp256k1zkp_v0_8_0_context* ctx) { - rustsecp256k1zkp_v0_8_0_context* ret; - size_t prealloc_size; - - VERIFY_CHECK(ctx != NULL); - prealloc_size = rustsecp256k1zkp_v0_8_0_context_preallocated_clone_size(ctx); - ret = (rustsecp256k1zkp_v0_8_0_context*)checked_malloc(&ctx->error_callback, prealloc_size); - ret = rustsecp256k1zkp_v0_8_0_context_preallocated_clone(ctx, ret); - return ret; -} - -void rustsecp256k1zkp_v0_8_0_context_preallocated_destroy(rustsecp256k1zkp_v0_8_0_context* ctx) { - ARG_CHECK_NO_RETURN(ctx != rustsecp256k1zkp_v0_8_0_context_no_precomp); - if (ctx != NULL) { - rustsecp256k1zkp_v0_8_0_ecmult_gen_context_clear(&ctx->ecmult_gen_ctx); - } -} - -void rustsecp256k1zkp_v0_8_0_context_destroy(rustsecp256k1zkp_v0_8_0_context* ctx) { - if (ctx != NULL) { - rustsecp256k1zkp_v0_8_0_context_preallocated_destroy(ctx); - free(ctx); - } -} - -void rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(rustsecp256k1zkp_v0_8_0_context* ctx, void (*fun)(const char* message, void* data), const void* data) { - ARG_CHECK_NO_RETURN(ctx != rustsecp256k1zkp_v0_8_0_context_no_precomp); - if (fun == NULL) { - fun = rustsecp256k1zkp_v0_8_0_default_illegal_callback_fn; - } - ctx->illegal_callback.fn = fun; - ctx->illegal_callback.data = data; -} - -void rustsecp256k1zkp_v0_8_0_context_set_error_callback(rustsecp256k1zkp_v0_8_0_context* ctx, void (*fun)(const char* message, void* data), const void* data) { - ARG_CHECK_NO_RETURN(ctx != rustsecp256k1zkp_v0_8_0_context_no_precomp); - if (fun == NULL) { - fun = rustsecp256k1zkp_v0_8_0_default_error_callback_fn; - } - ctx->error_callback.fn = fun; - ctx->error_callback.data = data; -} - -rustsecp256k1zkp_v0_8_0_scratch_space* rustsecp256k1zkp_v0_8_0_scratch_space_create(const rustsecp256k1zkp_v0_8_0_context* ctx, size_t max_size) { - VERIFY_CHECK(ctx != NULL); - return rustsecp256k1zkp_v0_8_0_scratch_create(&ctx->error_callback, max_size); -} - -void rustsecp256k1zkp_v0_8_0_scratch_space_destroy(const rustsecp256k1zkp_v0_8_0_context *ctx, rustsecp256k1zkp_v0_8_0_scratch_space* scratch) { - VERIFY_CHECK(ctx != NULL); - rustsecp256k1zkp_v0_8_0_scratch_destroy(&ctx->error_callback, scratch); -} - -/* Mark memory as no-longer-secret for the purpose of analysing constant-time behaviour - * of the software. This is setup for use with valgrind but could be substituted with - * the appropriate instrumentation for other analysis tools. - */ -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_declassify(const rustsecp256k1zkp_v0_8_0_context* ctx, const void *p, size_t len) { -#if defined(VALGRIND) - if (EXPECT(ctx->declassify,0)) VALGRIND_MAKE_MEM_DEFINED(p, len); -#else - (void)ctx; - (void)p; - (void)len; -#endif -} - -static int rustsecp256k1zkp_v0_8_0_pubkey_load(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ge* ge, const rustsecp256k1zkp_v0_8_0_pubkey* pubkey) { - if (sizeof(rustsecp256k1zkp_v0_8_0_ge_storage) == 64) { - /* When the rustsecp256k1zkp_v0_8_0_ge_storage type is exactly 64 byte, use its - * representation inside rustsecp256k1zkp_v0_8_0_pubkey, as conversion is very fast. - * Note that rustsecp256k1zkp_v0_8_0_pubkey_save must use the same representation. */ - rustsecp256k1zkp_v0_8_0_ge_storage s; - memcpy(&s, &pubkey->data[0], sizeof(s)); - rustsecp256k1zkp_v0_8_0_ge_from_storage(ge, &s); - } else { - /* Otherwise, fall back to 32-byte big endian for X and Y. */ - rustsecp256k1zkp_v0_8_0_fe x, y; - rustsecp256k1zkp_v0_8_0_fe_set_b32(&x, pubkey->data); - rustsecp256k1zkp_v0_8_0_fe_set_b32(&y, pubkey->data + 32); - rustsecp256k1zkp_v0_8_0_ge_set_xy(ge, &x, &y); - } - ARG_CHECK(!rustsecp256k1zkp_v0_8_0_fe_is_zero(&ge->x)); - return 1; -} - -static void rustsecp256k1zkp_v0_8_0_pubkey_save(rustsecp256k1zkp_v0_8_0_pubkey* pubkey, rustsecp256k1zkp_v0_8_0_ge* ge) { - if (sizeof(rustsecp256k1zkp_v0_8_0_ge_storage) == 64) { - rustsecp256k1zkp_v0_8_0_ge_storage s; - rustsecp256k1zkp_v0_8_0_ge_to_storage(&s, ge); - memcpy(&pubkey->data[0], &s, sizeof(s)); - } else { - VERIFY_CHECK(!rustsecp256k1zkp_v0_8_0_ge_is_infinity(ge)); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&ge->x); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&ge->y); - rustsecp256k1zkp_v0_8_0_fe_get_b32(pubkey->data, &ge->x); - rustsecp256k1zkp_v0_8_0_fe_get_b32(pubkey->data + 32, &ge->y); - } -} - -int rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pubkey* pubkey, const unsigned char *input, size_t inputlen) { - rustsecp256k1zkp_v0_8_0_ge Q; - - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(pubkey != NULL); - memset(pubkey, 0, sizeof(*pubkey)); - ARG_CHECK(input != NULL); - if (!rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(&Q, input, inputlen)) { - return 0; - } - if (!rustsecp256k1zkp_v0_8_0_ge_is_in_correct_subgroup(&Q)) { - return 0; - } - rustsecp256k1zkp_v0_8_0_pubkey_save(pubkey, &Q); - rustsecp256k1zkp_v0_8_0_ge_clear(&Q); - return 1; -} - -int rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *output, size_t *outputlen, const rustsecp256k1zkp_v0_8_0_pubkey* pubkey, unsigned int flags) { - rustsecp256k1zkp_v0_8_0_ge Q; - size_t len; - int ret = 0; - - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(outputlen != NULL); - ARG_CHECK(*outputlen >= ((flags & SECP256K1_FLAGS_BIT_COMPRESSION) ? 33u : 65u)); - len = *outputlen; - *outputlen = 0; - ARG_CHECK(output != NULL); - memset(output, 0, len); - ARG_CHECK(pubkey != NULL); - ARG_CHECK((flags & SECP256K1_FLAGS_TYPE_MASK) == SECP256K1_FLAGS_TYPE_COMPRESSION); - if (rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &Q, pubkey)) { - ret = rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&Q, output, &len, flags & SECP256K1_FLAGS_BIT_COMPRESSION); - if (ret) { - *outputlen = len; - } - } - return ret; -} - -int rustsecp256k1zkp_v0_8_0_ec_pubkey_cmp(const rustsecp256k1zkp_v0_8_0_context* ctx, const rustsecp256k1zkp_v0_8_0_pubkey* pubkey0, const rustsecp256k1zkp_v0_8_0_pubkey* pubkey1) { - unsigned char out[2][33]; - const rustsecp256k1zkp_v0_8_0_pubkey* pk[2]; - int i; - - VERIFY_CHECK(ctx != NULL); - pk[0] = pubkey0; pk[1] = pubkey1; - for (i = 0; i < 2; i++) { - size_t out_size = sizeof(out[i]); - /* If the public key is NULL or invalid, ec_pubkey_serialize will call - * the illegal_callback and return 0. In that case we will serialize the - * key as all zeros which is less than any valid public key. This - * results in consistent comparisons even if NULL or invalid pubkeys are - * involved and prevents edge cases such as sorting algorithms that use - * this function and do not terminate as a result. */ - if (!rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, out[i], &out_size, pk[i], SECP256K1_EC_COMPRESSED)) { - /* Note that ec_pubkey_serialize should already set the output to - * zero in that case, but it's not guaranteed by the API, we can't - * test it and writing a VERIFY_CHECK is more complex than - * explicitly memsetting (again). */ - memset(out[i], 0, sizeof(out[i])); - } - } - return rustsecp256k1zkp_v0_8_0_memcmp_var(out[0], out[1], sizeof(out[0])); -} - -static void rustsecp256k1zkp_v0_8_0_ecdsa_signature_load(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_scalar* r, rustsecp256k1zkp_v0_8_0_scalar* s, const rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig) { - (void)ctx; - if (sizeof(rustsecp256k1zkp_v0_8_0_scalar) == 32) { - /* When the rustsecp256k1zkp_v0_8_0_scalar type is exactly 32 byte, use its - * representation inside rustsecp256k1zkp_v0_8_0_ecdsa_signature, as conversion is very fast. - * Note that rustsecp256k1zkp_v0_8_0_ecdsa_signature_save must use the same representation. */ - memcpy(r, &sig->data[0], 32); - memcpy(s, &sig->data[32], 32); - } else { - rustsecp256k1zkp_v0_8_0_scalar_set_b32(r, &sig->data[0], NULL); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(s, &sig->data[32], NULL); - } -} - -static void rustsecp256k1zkp_v0_8_0_ecdsa_signature_save(rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig, const rustsecp256k1zkp_v0_8_0_scalar* r, const rustsecp256k1zkp_v0_8_0_scalar* s) { - if (sizeof(rustsecp256k1zkp_v0_8_0_scalar) == 32) { - memcpy(&sig->data[0], r, 32); - memcpy(&sig->data[32], s, 32); - } else { - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&sig->data[0], r); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&sig->data[32], s); - } -} - -int rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) { - rustsecp256k1zkp_v0_8_0_scalar r, s; - - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(sig != NULL); - ARG_CHECK(input != NULL); - - if (rustsecp256k1zkp_v0_8_0_ecdsa_sig_parse(&r, &s, input, inputlen)) { - rustsecp256k1zkp_v0_8_0_ecdsa_signature_save(sig, &r, &s); - return 1; - } else { - memset(sig, 0, sizeof(*sig)); - return 0; - } -} - -int rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_compact(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig, const unsigned char *input64) { - rustsecp256k1zkp_v0_8_0_scalar r, s; - int ret = 1; - int overflow = 0; - - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(sig != NULL); - ARG_CHECK(input64 != NULL); - - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&r, &input64[0], &overflow); - ret &= !overflow; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&s, &input64[32], &overflow); - ret &= !overflow; - if (ret) { - rustsecp256k1zkp_v0_8_0_ecdsa_signature_save(sig, &r, &s); - } else { - memset(sig, 0, sizeof(*sig)); - } - return ret; -} - -int rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_der(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *output, size_t *outputlen, const rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig) { - rustsecp256k1zkp_v0_8_0_scalar r, s; - - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(output != NULL); - ARG_CHECK(outputlen != NULL); - ARG_CHECK(sig != NULL); - - rustsecp256k1zkp_v0_8_0_ecdsa_signature_load(ctx, &r, &s, sig); - return rustsecp256k1zkp_v0_8_0_ecdsa_sig_serialize(output, outputlen, &r, &s); -} - -int rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_compact(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *output64, const rustsecp256k1zkp_v0_8_0_ecdsa_signature* sig) { - rustsecp256k1zkp_v0_8_0_scalar r, s; - - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(output64 != NULL); - ARG_CHECK(sig != NULL); - - rustsecp256k1zkp_v0_8_0_ecdsa_signature_load(ctx, &r, &s, sig); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&output64[0], &r); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(&output64[32], &s); - return 1; -} - -int rustsecp256k1zkp_v0_8_0_ecdsa_signature_normalize(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ecdsa_signature *sigout, const rustsecp256k1zkp_v0_8_0_ecdsa_signature *sigin) { - rustsecp256k1zkp_v0_8_0_scalar r, s; - int ret = 0; - - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(sigin != NULL); - - rustsecp256k1zkp_v0_8_0_ecdsa_signature_load(ctx, &r, &s, sigin); - ret = rustsecp256k1zkp_v0_8_0_scalar_is_high(&s); - if (sigout != NULL) { - if (ret) { - rustsecp256k1zkp_v0_8_0_scalar_negate(&s, &s); - } - rustsecp256k1zkp_v0_8_0_ecdsa_signature_save(sigout, &r, &s); - } - - return ret; -} - -int rustsecp256k1zkp_v0_8_0_ecdsa_verify(const rustsecp256k1zkp_v0_8_0_context* ctx, const rustsecp256k1zkp_v0_8_0_ecdsa_signature *sig, const unsigned char *msghash32, const rustsecp256k1zkp_v0_8_0_pubkey *pubkey) { - rustsecp256k1zkp_v0_8_0_ge q; - rustsecp256k1zkp_v0_8_0_scalar r, s; - rustsecp256k1zkp_v0_8_0_scalar m; - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(msghash32 != NULL); - ARG_CHECK(sig != NULL); - ARG_CHECK(pubkey != NULL); - - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&m, msghash32, NULL); - rustsecp256k1zkp_v0_8_0_ecdsa_signature_load(ctx, &r, &s, sig); - return (!rustsecp256k1zkp_v0_8_0_scalar_is_high(&s) && - rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &q, pubkey) && - rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&r, &s, &q, &m)); -} - -static SECP256K1_INLINE void buffer_append(unsigned char *buf, unsigned int *offset, const void *data, unsigned int len) { - memcpy(buf + *offset, data, len); - *offset += len; -} - -static int nonce_function_rfc6979(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int counter) { - unsigned char keydata[112]; - unsigned int offset = 0; - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256 rng; - unsigned int i; - rustsecp256k1zkp_v0_8_0_scalar msg; - unsigned char msgmod32[32]; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&msg, msg32, NULL); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(msgmod32, &msg); - /* We feed a byte array to the PRNG as input, consisting of: - * - the private key (32 bytes) and reduced message (32 bytes), see RFC 6979 3.2d. - * - optionally 32 extra bytes of data, see RFC 6979 3.6 Additional Data. - * - optionally 16 extra bytes with the algorithm name. - * Because the arguments have distinct fixed lengths it is not possible for - * different argument mixtures to emulate each other and result in the same - * nonces. - */ - buffer_append(keydata, &offset, key32, 32); - buffer_append(keydata, &offset, msgmod32, 32); - if (data != NULL) { - buffer_append(keydata, &offset, data, 32); - } - if (algo16 != NULL) { - buffer_append(keydata, &offset, algo16, 16); - } - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_initialize(&rng, keydata, offset); - memset(keydata, 0, sizeof(keydata)); - for (i = 0; i <= counter; i++) { - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_generate(&rng, nonce32, 32); - } - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_finalize(&rng); - return 1; -} - -const rustsecp256k1zkp_v0_8_0_nonce_function rustsecp256k1zkp_v0_8_0_nonce_function_rfc6979 = nonce_function_rfc6979; -const rustsecp256k1zkp_v0_8_0_nonce_function rustsecp256k1zkp_v0_8_0_nonce_function_default = nonce_function_rfc6979; - -static int rustsecp256k1zkp_v0_8_0_ecdsa_sign_inner(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_scalar* r, rustsecp256k1zkp_v0_8_0_scalar* s, int* recid, rustsecp256k1zkp_v0_8_0_sha256* s2c_sha, rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening *s2c_opening, const unsigned char* s2c_data32, const unsigned char *msg32, const unsigned char *seckey, rustsecp256k1zkp_v0_8_0_nonce_function noncefp, const void* noncedata) { - rustsecp256k1zkp_v0_8_0_scalar sec, non, msg; - int ret = 0; - int is_sec_valid; - unsigned char nonce32[32]; - unsigned int count = 0; - /* Default initialization here is important so we won't pass uninit values to the cmov in the end */ - *r = rustsecp256k1zkp_v0_8_0_scalar_zero; - *s = rustsecp256k1zkp_v0_8_0_scalar_zero; - if (recid) { - *recid = 0; - } - if (noncefp == NULL) { - noncefp = rustsecp256k1zkp_v0_8_0_nonce_function_default; - } - /* sign-to-contract commitments only work with the default nonce function, - * because we need to ensure that s2c_data is actually hashed into the nonce and - * not just ignored. Otherwise an attacker can exfiltrate the secret key by - * signing the same message thrice with different commitments. */ - VERIFY_CHECK(s2c_data32 == NULL || noncefp == rustsecp256k1zkp_v0_8_0_nonce_function_default); - - /* Fail if the secret key is invalid. */ - is_sec_valid = rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(&sec, seckey); - rustsecp256k1zkp_v0_8_0_scalar_cmov(&sec, &rustsecp256k1zkp_v0_8_0_scalar_one, !is_sec_valid); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&msg, msg32, NULL); - while (1) { - int is_nonce_valid; - ret = !!noncefp(nonce32, msg32, seckey, NULL, (void*)noncedata, count); - if (!ret) { - break; - } - is_nonce_valid = rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(&non, nonce32); - /* The nonce is still secret here, but it being invalid is is less likely than 1:2^255. */ - rustsecp256k1zkp_v0_8_0_declassify(ctx, &is_nonce_valid, sizeof(is_nonce_valid)); - if (is_nonce_valid) { - if (s2c_data32 != NULL) { - rustsecp256k1zkp_v0_8_0_gej nonce_pj; - rustsecp256k1zkp_v0_8_0_ge nonce_p; - - /* Compute original nonce commitment/pubkey */ - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &nonce_pj, &non); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&nonce_p, &nonce_pj); - if (s2c_opening != NULL) { - rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening_save(s2c_opening, &nonce_p); - } - - /* Because the nonce is valid, the nonce point isn't the point - * at infinity and we can declassify that information to be able to - * serialize the point. */ - rustsecp256k1zkp_v0_8_0_declassify(ctx, &nonce_p.infinity, sizeof(nonce_p.infinity)); - - /* Tweak nonce with s2c commitment. */ - ret = rustsecp256k1zkp_v0_8_0_ec_commit_seckey(&non, &nonce_p, s2c_sha, s2c_data32, 32); - rustsecp256k1zkp_v0_8_0_declassify(ctx, &ret, sizeof(ret)); /* may be secret that the tweak falied, but happens with negligible probability */ - if (!ret) { - break; - } - } - - ret = rustsecp256k1zkp_v0_8_0_ecdsa_sig_sign(&ctx->ecmult_gen_ctx, r, s, &sec, &msg, &non, recid); - /* The final signature is no longer a secret, nor is the fact that we were successful or not. */ - rustsecp256k1zkp_v0_8_0_declassify(ctx, &ret, sizeof(ret)); - if (ret) { - break; - } - } - count++; - } - /* We don't want to declassify is_sec_valid and therefore the range of - * seckey. As a result is_sec_valid is included in ret only after ret was - * used as a branching variable. */ - ret &= is_sec_valid; - memset(nonce32, 0, 32); - rustsecp256k1zkp_v0_8_0_scalar_clear(&msg); - rustsecp256k1zkp_v0_8_0_scalar_clear(&non); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sec); - rustsecp256k1zkp_v0_8_0_scalar_cmov(r, &rustsecp256k1zkp_v0_8_0_scalar_zero, !ret); - rustsecp256k1zkp_v0_8_0_scalar_cmov(s, &rustsecp256k1zkp_v0_8_0_scalar_zero, !ret); - if (recid) { - const int zero = 0; - rustsecp256k1zkp_v0_8_0_int_cmov(recid, &zero, !ret); - } - return ret; -} - -int rustsecp256k1zkp_v0_8_0_ecdsa_sign(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_ecdsa_signature *signature, const unsigned char *msghash32, const unsigned char *seckey, rustsecp256k1zkp_v0_8_0_nonce_function noncefp, const void* noncedata) { - rustsecp256k1zkp_v0_8_0_scalar r, s; - int ret; - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); - ARG_CHECK(msghash32 != NULL); - ARG_CHECK(signature != NULL); - ARG_CHECK(seckey != NULL); - - ret = rustsecp256k1zkp_v0_8_0_ecdsa_sign_inner(ctx, &r, &s, NULL, NULL, NULL, NULL, msghash32, seckey, noncefp, noncedata); - rustsecp256k1zkp_v0_8_0_ecdsa_signature_save(signature, &r, &s); - return ret; -} - -int rustsecp256k1zkp_v0_8_0_ec_seckey_verify(const rustsecp256k1zkp_v0_8_0_context* ctx, const unsigned char *seckey) { - rustsecp256k1zkp_v0_8_0_scalar sec; - int ret; - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(seckey != NULL); - - ret = rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(&sec, seckey); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sec); - return ret; -} - -static int rustsecp256k1zkp_v0_8_0_ec_pubkey_create_helper(const rustsecp256k1zkp_v0_8_0_ecmult_gen_context *ecmult_gen_ctx, rustsecp256k1zkp_v0_8_0_scalar *seckey_scalar, rustsecp256k1zkp_v0_8_0_ge *p, const unsigned char *seckey) { - rustsecp256k1zkp_v0_8_0_gej pj; - int ret; - - ret = rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(seckey_scalar, seckey); - rustsecp256k1zkp_v0_8_0_scalar_cmov(seckey_scalar, &rustsecp256k1zkp_v0_8_0_scalar_one, !ret); - - rustsecp256k1zkp_v0_8_0_ecmult_gen(ecmult_gen_ctx, &pj, seckey_scalar); - rustsecp256k1zkp_v0_8_0_ge_set_gej(p, &pj); - return ret; -} - -int rustsecp256k1zkp_v0_8_0_ec_pubkey_create(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pubkey *pubkey, const unsigned char *seckey) { - rustsecp256k1zkp_v0_8_0_ge p; - rustsecp256k1zkp_v0_8_0_scalar seckey_scalar; - int ret = 0; - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(pubkey != NULL); - memset(pubkey, 0, sizeof(*pubkey)); - ARG_CHECK(rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); - ARG_CHECK(seckey != NULL); - - ret = rustsecp256k1zkp_v0_8_0_ec_pubkey_create_helper(&ctx->ecmult_gen_ctx, &seckey_scalar, &p, seckey); - rustsecp256k1zkp_v0_8_0_pubkey_save(pubkey, &p); - rustsecp256k1zkp_v0_8_0_memczero(pubkey, sizeof(*pubkey), !ret); - - rustsecp256k1zkp_v0_8_0_scalar_clear(&seckey_scalar); - return ret; -} - -int rustsecp256k1zkp_v0_8_0_ec_seckey_negate(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *seckey) { - rustsecp256k1zkp_v0_8_0_scalar sec; - int ret = 0; - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(seckey != NULL); - - ret = rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(&sec, seckey); - rustsecp256k1zkp_v0_8_0_scalar_cmov(&sec, &rustsecp256k1zkp_v0_8_0_scalar_zero, !ret); - rustsecp256k1zkp_v0_8_0_scalar_negate(&sec, &sec); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(seckey, &sec); - - rustsecp256k1zkp_v0_8_0_scalar_clear(&sec); - return ret; -} - -int rustsecp256k1zkp_v0_8_0_ec_privkey_negate(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *seckey) { - return rustsecp256k1zkp_v0_8_0_ec_seckey_negate(ctx, seckey); -} - -int rustsecp256k1zkp_v0_8_0_ec_pubkey_negate(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pubkey *pubkey) { - int ret = 0; - rustsecp256k1zkp_v0_8_0_ge p; - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(pubkey != NULL); - - ret = rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &p, pubkey); - memset(pubkey, 0, sizeof(*pubkey)); - if (ret) { - rustsecp256k1zkp_v0_8_0_ge_neg(&p, &p); - rustsecp256k1zkp_v0_8_0_pubkey_save(pubkey, &p); - } - return ret; -} - - -static int rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add_helper(rustsecp256k1zkp_v0_8_0_scalar *sec, const unsigned char *tweak32) { - rustsecp256k1zkp_v0_8_0_scalar term; - int overflow = 0; - int ret = 0; - - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&term, tweak32, &overflow); - ret = (!overflow) & rustsecp256k1zkp_v0_8_0_eckey_privkey_tweak_add(sec, &term); - rustsecp256k1zkp_v0_8_0_scalar_clear(&term); - return ret; -} - -int rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *seckey, const unsigned char *tweak32) { - rustsecp256k1zkp_v0_8_0_scalar sec; - int ret = 0; - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(seckey != NULL); - ARG_CHECK(tweak32 != NULL); - - ret = rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(&sec, seckey); - ret &= rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add_helper(&sec, tweak32); - rustsecp256k1zkp_v0_8_0_scalar_cmov(&sec, &rustsecp256k1zkp_v0_8_0_scalar_zero, !ret); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(seckey, &sec); - - rustsecp256k1zkp_v0_8_0_scalar_clear(&sec); - return ret; -} - -int rustsecp256k1zkp_v0_8_0_ec_privkey_tweak_add(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *seckey, const unsigned char *tweak32) { - return rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add(ctx, seckey, tweak32); -} - -static int rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add_helper(rustsecp256k1zkp_v0_8_0_ge *p, const unsigned char *tweak32) { - rustsecp256k1zkp_v0_8_0_scalar term; - int overflow = 0; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&term, tweak32, &overflow); - return !overflow && rustsecp256k1zkp_v0_8_0_eckey_pubkey_tweak_add(p, &term); -} - -int rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pubkey *pubkey, const unsigned char *tweak32) { - rustsecp256k1zkp_v0_8_0_ge p; - int ret = 0; - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(pubkey != NULL); - ARG_CHECK(tweak32 != NULL); - - ret = rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &p, pubkey); - memset(pubkey, 0, sizeof(*pubkey)); - ret = ret && rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add_helper(&p, tweak32); - if (ret) { - rustsecp256k1zkp_v0_8_0_pubkey_save(pubkey, &p); - } - - return ret; -} - -int rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_mul(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *seckey, const unsigned char *tweak32) { - rustsecp256k1zkp_v0_8_0_scalar factor; - rustsecp256k1zkp_v0_8_0_scalar sec; - int ret = 0; - int overflow = 0; - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(seckey != NULL); - ARG_CHECK(tweak32 != NULL); - - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&factor, tweak32, &overflow); - ret = rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(&sec, seckey); - ret &= (!overflow) & rustsecp256k1zkp_v0_8_0_eckey_privkey_tweak_mul(&sec, &factor); - rustsecp256k1zkp_v0_8_0_scalar_cmov(&sec, &rustsecp256k1zkp_v0_8_0_scalar_zero, !ret); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(seckey, &sec); - - rustsecp256k1zkp_v0_8_0_scalar_clear(&sec); - rustsecp256k1zkp_v0_8_0_scalar_clear(&factor); - return ret; -} - -int rustsecp256k1zkp_v0_8_0_ec_privkey_tweak_mul(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *seckey, const unsigned char *tweak32) { - return rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_mul(ctx, seckey, tweak32); -} - -int rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_mul(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pubkey *pubkey, const unsigned char *tweak32) { - rustsecp256k1zkp_v0_8_0_ge p; - rustsecp256k1zkp_v0_8_0_scalar factor; - int ret = 0; - int overflow = 0; - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(pubkey != NULL); - ARG_CHECK(tweak32 != NULL); - - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&factor, tweak32, &overflow); - ret = !overflow && rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &p, pubkey); - memset(pubkey, 0, sizeof(*pubkey)); - if (ret) { - if (rustsecp256k1zkp_v0_8_0_eckey_pubkey_tweak_mul(&p, &factor)) { - rustsecp256k1zkp_v0_8_0_pubkey_save(pubkey, &p); - } else { - ret = 0; - } - } - - return ret; -} - -int rustsecp256k1zkp_v0_8_0_context_randomize(rustsecp256k1zkp_v0_8_0_context* ctx, const unsigned char *seed32) { - VERIFY_CHECK(ctx != NULL); - if (rustsecp256k1zkp_v0_8_0_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)) { - rustsecp256k1zkp_v0_8_0_ecmult_gen_blind(&ctx->ecmult_gen_ctx, seed32); - } - return 1; -} - -int rustsecp256k1zkp_v0_8_0_ec_pubkey_combine(const rustsecp256k1zkp_v0_8_0_context* ctx, rustsecp256k1zkp_v0_8_0_pubkey *pubnonce, const rustsecp256k1zkp_v0_8_0_pubkey * const *pubnonces, size_t n) { - size_t i; - rustsecp256k1zkp_v0_8_0_gej Qj; - rustsecp256k1zkp_v0_8_0_ge Q; - - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(pubnonce != NULL); - memset(pubnonce, 0, sizeof(*pubnonce)); - ARG_CHECK(n >= 1); - ARG_CHECK(pubnonces != NULL); - - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&Qj); - - for (i = 0; i < n; i++) { - ARG_CHECK(pubnonces[i] != NULL); - rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &Q, pubnonces[i]); - rustsecp256k1zkp_v0_8_0_gej_add_ge(&Qj, &Qj, &Q); - } - if (rustsecp256k1zkp_v0_8_0_gej_is_infinity(&Qj)) { - return 0; - } - rustsecp256k1zkp_v0_8_0_ge_set_gej(&Q, &Qj); - rustsecp256k1zkp_v0_8_0_pubkey_save(pubnonce, &Q); - return 1; -} - -int rustsecp256k1zkp_v0_8_0_tagged_sha256(const rustsecp256k1zkp_v0_8_0_context* ctx, unsigned char *hash32, const unsigned char *tag, size_t taglen, const unsigned char *msg, size_t msglen) { - rustsecp256k1zkp_v0_8_0_sha256 sha; - VERIFY_CHECK(ctx != NULL); - ARG_CHECK(hash32 != NULL); - ARG_CHECK(tag != NULL); - ARG_CHECK(msg != NULL); - - rustsecp256k1zkp_v0_8_0_sha256_initialize_tagged(&sha, tag, taglen); - rustsecp256k1zkp_v0_8_0_sha256_write(&sha, msg, msglen); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&sha, hash32); - return 1; -} - -#ifdef ENABLE_MODULE_BPPP -#include "modules/bppp/main_impl.h" -#endif - -#ifdef ENABLE_MODULE_ECDH -#include "modules/ecdh/main_impl.h" -#endif - -#ifdef ENABLE_MODULE_RECOVERY -#include "modules/recovery/main_impl.h" -#endif - -#ifdef ENABLE_MODULE_EXTRAKEYS -#include "modules/extrakeys/main_impl.h" -#endif - -#ifdef ENABLE_MODULE_SCHNORRSIG -#include "modules/schnorrsig/main_impl.h" -#endif - -#ifdef ENABLE_MODULE_ECDSA_S2C -#include "modules/ecdsa_s2c/main_impl.h" -#endif - -#ifdef ENABLE_MODULE_ECDSA_ADAPTOR -#include "modules/ecdsa_adaptor/main_impl.h" -#endif - -#ifdef ENABLE_MODULE_MUSIG -#include "modules/musig/main_impl.h" -#endif - -#ifdef ENABLE_MODULE_GENERATOR -#include "modules/generator/main_impl.h" -#endif - -#ifdef ENABLE_MODULE_RANGEPROOF -#include "modules/rangeproof/main_impl.h" -#endif - -#ifdef ENABLE_MODULE_WHITELIST -#include "modules/whitelist/main_impl.h" -#endif - -#ifdef ENABLE_MODULE_SURJECTIONPROOF -#include "modules/surjection/main_impl.h" -#endif - diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/selftest.h b/secp256k1-zkp-sys/depend/secp256k1/src/selftest.h index 2f280263..007e9769 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/selftest.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/selftest.h @@ -11,22 +11,22 @@ #include -static int rustsecp256k1zkp_v0_8_0_selftest_sha256(void) { +static int rustsecp256k1zkp_v0_10_0_selftest_sha256(void) { static const char *input63 = "For this sample, this 63-byte string will be used as input data"; static const unsigned char output32[32] = { 0xf0, 0x8a, 0x78, 0xcb, 0xba, 0xee, 0x08, 0x2b, 0x05, 0x2a, 0xe0, 0x70, 0x8f, 0x32, 0xfa, 0x1e, 0x50, 0xc5, 0xc4, 0x21, 0xaa, 0x77, 0x2b, 0xa5, 0xdb, 0xb4, 0x06, 0xa2, 0xea, 0x6b, 0xe3, 0x42, }; unsigned char out[32]; - rustsecp256k1zkp_v0_8_0_sha256 hasher; - rustsecp256k1zkp_v0_8_0_sha256_initialize(&hasher); - rustsecp256k1zkp_v0_8_0_sha256_write(&hasher, (const unsigned char*)input63, 63); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&hasher, out); - return rustsecp256k1zkp_v0_8_0_memcmp_var(out, output32, 32) == 0; + rustsecp256k1zkp_v0_10_0_sha256 hasher; + rustsecp256k1zkp_v0_10_0_sha256_initialize(&hasher); + rustsecp256k1zkp_v0_10_0_sha256_write(&hasher, (const unsigned char*)input63, 63); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&hasher, out); + return rustsecp256k1zkp_v0_10_0_memcmp_var(out, output32, 32) == 0; } -static int rustsecp256k1zkp_v0_8_0_selftest(void) { - return rustsecp256k1zkp_v0_8_0_selftest_sha256(); +static int rustsecp256k1zkp_v0_10_0_selftest_passes(void) { + return rustsecp256k1zkp_v0_10_0_selftest_sha256(); } #endif /* SECP256K1_SELFTEST_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/testrand.h b/secp256k1-zkp-sys/depend/secp256k1/src/testrand.h index 94c961a4..e541889a 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/testrand.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/testrand.h @@ -7,47 +7,45 @@ #ifndef SECP256K1_TESTRAND_H #define SECP256K1_TESTRAND_H -#if defined HAVE_CONFIG_H -#include "libsecp256k1-config.h" -#endif +#include "util.h" /* A non-cryptographic RNG used only for test infrastructure. */ /** Seed the pseudorandom number generator for testing. */ -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_testrand_seed(const unsigned char *seed16); +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_testrand_seed(const unsigned char *seed16); /** Generate a pseudorandom number in the range [0..2**32-1]. */ -SECP256K1_INLINE static uint32_t rustsecp256k1zkp_v0_8_0_testrand32(void); +SECP256K1_INLINE static uint32_t rustsecp256k1zkp_v0_10_0_testrand32(void); /** Generate a pseudorandom number in the range [0..2**64-1]. */ -SECP256K1_INLINE static uint64_t rustsecp256k1zkp_v0_8_0_testrand64(void); +SECP256K1_INLINE static uint64_t rustsecp256k1zkp_v0_10_0_testrand64(void); /** Generate a pseudorandom number in the range [0..2**bits-1]. Bits must be 1 or * more. */ -SECP256K1_INLINE static uint64_t rustsecp256k1zkp_v0_8_0_testrand_bits(int bits); +SECP256K1_INLINE static uint64_t rustsecp256k1zkp_v0_10_0_testrand_bits(int bits); /** Generate a pseudorandom number in the range [0..range-1]. */ -static uint32_t rustsecp256k1zkp_v0_8_0_testrand_int(uint32_t range); +static uint32_t rustsecp256k1zkp_v0_10_0_testrand_int(uint32_t range); /** Generate a pseudorandom 32-byte array. */ -static void rustsecp256k1zkp_v0_8_0_testrand256(unsigned char *b32); +static void rustsecp256k1zkp_v0_10_0_testrand256(unsigned char *b32); /** Generate a pseudorandom 32-byte array with long sequences of zero and one bits. */ -static void rustsecp256k1zkp_v0_8_0_testrand256_test(unsigned char *b32); +static void rustsecp256k1zkp_v0_10_0_testrand256_test(unsigned char *b32); /** Generate pseudorandom bytes with long sequences of zero and one bits. */ -static void rustsecp256k1zkp_v0_8_0_testrand_bytes_test(unsigned char *bytes, size_t len); +static void rustsecp256k1zkp_v0_10_0_testrand_bytes_test(unsigned char *bytes, size_t len); /** Generate a pseudorandom 64-bit integer in the range min..max, inclusive. */ -static int64_t rustsecp256k1zkp_v0_8_0_testrandi64(uint64_t min, uint64_t max); +static int64_t rustsecp256k1zkp_v0_10_0_testrandi64(uint64_t min, uint64_t max); /** Flip a single random bit in a byte array */ -static void rustsecp256k1zkp_v0_8_0_testrand_flip(unsigned char *b, size_t len); +static void rustsecp256k1zkp_v0_10_0_testrand_flip(unsigned char *b, size_t len); /** Initialize the test RNG using (hex encoded) array up to 16 bytes, or randomly if hexseed is NULL. */ -static void rustsecp256k1zkp_v0_8_0_testrand_init(const char* hexseed); +static void rustsecp256k1zkp_v0_10_0_testrand_init(const char* hexseed); /** Print final test information. */ -static void rustsecp256k1zkp_v0_8_0_testrand_finish(void); +static void rustsecp256k1zkp_v0_10_0_testrand_finish(void); #endif /* SECP256K1_TESTRAND_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/testrand_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/testrand_impl.h index c06e3d71..9b50017f 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/testrand_impl.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/testrand_impl.h @@ -14,108 +14,78 @@ #include "testrand.h" #include "hash.h" +#include "util.h" -static uint64_t rustsecp256k1zkp_v0_8_0_test_state[4]; -static uint64_t rustsecp256k1zkp_v0_8_0_test_rng_integer; -static int rustsecp256k1zkp_v0_8_0_test_rng_integer_bits_left = 0; +static uint64_t rustsecp256k1zkp_v0_10_0_test_state[4]; -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_testrand_seed(const unsigned char *seed16) { +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_testrand_seed(const unsigned char *seed16) { static const unsigned char PREFIX[19] = "secp256k1 test init"; unsigned char out32[32]; - rustsecp256k1zkp_v0_8_0_sha256 hash; + rustsecp256k1zkp_v0_10_0_sha256 hash; int i; /* Use SHA256(PREFIX || seed16) as initial state. */ - rustsecp256k1zkp_v0_8_0_sha256_initialize(&hash); - rustsecp256k1zkp_v0_8_0_sha256_write(&hash, PREFIX, sizeof(PREFIX)); - rustsecp256k1zkp_v0_8_0_sha256_write(&hash, seed16, 16); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&hash, out32); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&hash); + rustsecp256k1zkp_v0_10_0_sha256_write(&hash, PREFIX, sizeof(PREFIX)); + rustsecp256k1zkp_v0_10_0_sha256_write(&hash, seed16, 16); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&hash, out32); for (i = 0; i < 4; ++i) { uint64_t s = 0; int j; for (j = 0; j < 8; ++j) s = (s << 8) | out32[8*i + j]; - rustsecp256k1zkp_v0_8_0_test_state[i] = s; + rustsecp256k1zkp_v0_10_0_test_state[i] = s; } - rustsecp256k1zkp_v0_8_0_test_rng_integer_bits_left = 0; } SECP256K1_INLINE static uint64_t rotl(const uint64_t x, int k) { return (x << k) | (x >> (64 - k)); } -SECP256K1_INLINE static uint64_t rustsecp256k1zkp_v0_8_0_testrand64(void) { +SECP256K1_INLINE static uint64_t rustsecp256k1zkp_v0_10_0_testrand64(void) { /* Test-only Xoshiro256++ RNG. See https://prng.di.unimi.it/ */ - const uint64_t result = rotl(rustsecp256k1zkp_v0_8_0_test_state[0] + rustsecp256k1zkp_v0_8_0_test_state[3], 23) + rustsecp256k1zkp_v0_8_0_test_state[0]; - const uint64_t t = rustsecp256k1zkp_v0_8_0_test_state[1] << 17; - rustsecp256k1zkp_v0_8_0_test_state[2] ^= rustsecp256k1zkp_v0_8_0_test_state[0]; - rustsecp256k1zkp_v0_8_0_test_state[3] ^= rustsecp256k1zkp_v0_8_0_test_state[1]; - rustsecp256k1zkp_v0_8_0_test_state[1] ^= rustsecp256k1zkp_v0_8_0_test_state[2]; - rustsecp256k1zkp_v0_8_0_test_state[0] ^= rustsecp256k1zkp_v0_8_0_test_state[3]; - rustsecp256k1zkp_v0_8_0_test_state[2] ^= t; - rustsecp256k1zkp_v0_8_0_test_state[3] = rotl(rustsecp256k1zkp_v0_8_0_test_state[3], 45); + const uint64_t result = rotl(rustsecp256k1zkp_v0_10_0_test_state[0] + rustsecp256k1zkp_v0_10_0_test_state[3], 23) + rustsecp256k1zkp_v0_10_0_test_state[0]; + const uint64_t t = rustsecp256k1zkp_v0_10_0_test_state[1] << 17; + rustsecp256k1zkp_v0_10_0_test_state[2] ^= rustsecp256k1zkp_v0_10_0_test_state[0]; + rustsecp256k1zkp_v0_10_0_test_state[3] ^= rustsecp256k1zkp_v0_10_0_test_state[1]; + rustsecp256k1zkp_v0_10_0_test_state[1] ^= rustsecp256k1zkp_v0_10_0_test_state[2]; + rustsecp256k1zkp_v0_10_0_test_state[0] ^= rustsecp256k1zkp_v0_10_0_test_state[3]; + rustsecp256k1zkp_v0_10_0_test_state[2] ^= t; + rustsecp256k1zkp_v0_10_0_test_state[3] = rotl(rustsecp256k1zkp_v0_10_0_test_state[3], 45); return result; } -SECP256K1_INLINE static uint64_t rustsecp256k1zkp_v0_8_0_testrand_bits(int bits) { - uint64_t ret; - if (rustsecp256k1zkp_v0_8_0_test_rng_integer_bits_left < bits) { - rustsecp256k1zkp_v0_8_0_test_rng_integer = rustsecp256k1zkp_v0_8_0_testrand64(); - rustsecp256k1zkp_v0_8_0_test_rng_integer_bits_left = 64; - } - ret = rustsecp256k1zkp_v0_8_0_test_rng_integer; - rustsecp256k1zkp_v0_8_0_test_rng_integer >>= bits; - rustsecp256k1zkp_v0_8_0_test_rng_integer_bits_left -= bits; - ret &= ((~((uint64_t)0)) >> (64 - bits)); - return ret; +SECP256K1_INLINE static uint64_t rustsecp256k1zkp_v0_10_0_testrand_bits(int bits) { + if (bits == 0) return 0; + return rustsecp256k1zkp_v0_10_0_testrand64() >> (64 - bits); } -SECP256K1_INLINE static uint32_t rustsecp256k1zkp_v0_8_0_testrand32(void) { - return rustsecp256k1zkp_v0_8_0_testrand_bits(32); +SECP256K1_INLINE static uint32_t rustsecp256k1zkp_v0_10_0_testrand32(void) { + return rustsecp256k1zkp_v0_10_0_testrand64() >> 32; } -static uint32_t rustsecp256k1zkp_v0_8_0_testrand_int(uint32_t range) { - /* We want a uniform integer between 0 and range-1, inclusive. - * B is the smallest number such that range <= 2**B. - * two mechanisms implemented here: - * - generate B bits numbers until one below range is found, and return it - * - find the largest multiple M of range that is <= 2**(B+A), generate B+A - * bits numbers until one below M is found, and return it modulo range - * The second mechanism consumes A more bits of entropy in every iteration, - * but may need fewer iterations due to M being closer to 2**(B+A) then - * range is to 2**B. The array below (indexed by B) contains a 0 when the - * first mechanism is to be used, and the number A otherwise. - */ - static const int addbits[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0}; - uint32_t trange, mult; - int bits = 0; - if (range <= 1) { - return 0; - } - trange = range - 1; - while (trange > 0) { - trange >>= 1; - bits++; +static uint32_t rustsecp256k1zkp_v0_10_0_testrand_int(uint32_t range) { + uint32_t mask = 0; + uint32_t range_copy; + /* Reduce range by 1, changing its meaning to "maximum value". */ + VERIFY_CHECK(range != 0); + range -= 1; + /* Count the number of bits in range. */ + range_copy = range; + while (range_copy) { + mask = (mask << 1) | 1U; + range_copy >>= 1; } - if (addbits[bits]) { - bits = bits + addbits[bits]; - mult = ((~((uint32_t)0)) >> (32 - bits)) / range; - trange = range * mult; - } else { - trange = range; - mult = 1; - } - while(1) { - uint32_t x = rustsecp256k1zkp_v0_8_0_testrand_bits(bits); - if (x < trange) { - return (mult == 1) ? x : (x % range); - } + /* Generation loop. */ + while (1) { + uint32_t val = rustsecp256k1zkp_v0_10_0_testrand64() & mask; + if (val <= range) return val; } } -static void rustsecp256k1zkp_v0_8_0_testrand256(unsigned char *b32) { +static void rustsecp256k1zkp_v0_10_0_testrand256(unsigned char *b32) { int i; for (i = 0; i < 4; ++i) { - uint64_t val = rustsecp256k1zkp_v0_8_0_testrand64(); + uint64_t val = rustsecp256k1zkp_v0_10_0_testrand64(); b32[0] = val; b32[1] = val >> 8; b32[2] = val >> 16; @@ -128,14 +98,14 @@ static void rustsecp256k1zkp_v0_8_0_testrand256(unsigned char *b32) { } } -static void rustsecp256k1zkp_v0_8_0_testrand_bytes_test(unsigned char *bytes, size_t len) { +static void rustsecp256k1zkp_v0_10_0_testrand_bytes_test(unsigned char *bytes, size_t len) { size_t bits = 0; memset(bytes, 0, len); while (bits < len * 8) { int now; uint32_t val; - now = 1 + (rustsecp256k1zkp_v0_8_0_testrand_bits(6) * rustsecp256k1zkp_v0_8_0_testrand_bits(5) + 16) / 31; - val = rustsecp256k1zkp_v0_8_0_testrand_bits(1); + now = 1 + (rustsecp256k1zkp_v0_10_0_testrand_bits(6) * rustsecp256k1zkp_v0_10_0_testrand_bits(5) + 16) / 31; + val = rustsecp256k1zkp_v0_10_0_testrand_bits(1); while (now > 0 && bits < len * 8) { bytes[bits / 8] |= val << (bits % 8); now--; @@ -144,11 +114,11 @@ static void rustsecp256k1zkp_v0_8_0_testrand_bytes_test(unsigned char *bytes, si } } -static void rustsecp256k1zkp_v0_8_0_testrand256_test(unsigned char *b32) { - rustsecp256k1zkp_v0_8_0_testrand_bytes_test(b32, 32); +static void rustsecp256k1zkp_v0_10_0_testrand256_test(unsigned char *b32) { + rustsecp256k1zkp_v0_10_0_testrand_bytes_test(b32, 32); } -SECP256K1_INLINE static int64_t rustsecp256k1zkp_v0_8_0_testrandi64(uint64_t min, uint64_t max) { +SECP256K1_INLINE static int64_t rustsecp256k1zkp_v0_10_0_testrandi64(uint64_t min, uint64_t max) { uint64_t range; uint64_t r; uint64_t clz; @@ -157,19 +127,19 @@ SECP256K1_INLINE static int64_t rustsecp256k1zkp_v0_8_0_testrandi64(uint64_t min return min; } range = max - min; - clz = rustsecp256k1zkp_v0_8_0_clz64_var(range); + clz = rustsecp256k1zkp_v0_10_0_clz64_var(range); do { - r = ((uint64_t)rustsecp256k1zkp_v0_8_0_testrand32() << 32) | rustsecp256k1zkp_v0_8_0_testrand32(); + r = ((uint64_t)rustsecp256k1zkp_v0_10_0_testrand32() << 32) | rustsecp256k1zkp_v0_10_0_testrand32(); r >>= clz; } while (r > range); return min + (int64_t)r; } -static void rustsecp256k1zkp_v0_8_0_testrand_flip(unsigned char *b, size_t len) { - b[rustsecp256k1zkp_v0_8_0_testrand_int(len)] ^= (1 << rustsecp256k1zkp_v0_8_0_testrand_bits(3)); +static void rustsecp256k1zkp_v0_10_0_testrand_flip(unsigned char *b, size_t len) { + b[rustsecp256k1zkp_v0_10_0_testrand_int(len)] ^= (1 << rustsecp256k1zkp_v0_10_0_testrand_bits(3)); } -static void rustsecp256k1zkp_v0_8_0_testrand_init(const char* hexseed) { +static void rustsecp256k1zkp_v0_10_0_testrand_init(const char* hexseed) { unsigned char seed16[16] = {0}; if (hexseed && strlen(hexseed) != 0) { int pos = 0; @@ -203,12 +173,12 @@ static void rustsecp256k1zkp_v0_8_0_testrand_init(const char* hexseed) { } printf("random seed = %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n", seed16[0], seed16[1], seed16[2], seed16[3], seed16[4], seed16[5], seed16[6], seed16[7], seed16[8], seed16[9], seed16[10], seed16[11], seed16[12], seed16[13], seed16[14], seed16[15]); - rustsecp256k1zkp_v0_8_0_testrand_seed(seed16); + rustsecp256k1zkp_v0_10_0_testrand_seed(seed16); } -static void rustsecp256k1zkp_v0_8_0_testrand_finish(void) { +static void rustsecp256k1zkp_v0_10_0_testrand_finish(void) { unsigned char run32[32]; - rustsecp256k1zkp_v0_8_0_testrand256(run32); + rustsecp256k1zkp_v0_10_0_testrand256(run32); printf("random run = %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n", run32[0], run32[1], run32[2], run32[3], run32[4], run32[5], run32[6], run32[7], run32[8], run32[9], run32[10], run32[11], run32[12], run32[13], run32[14], run32[15]); } diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/tests.c b/secp256k1-zkp-sys/depend/secp256k1/src/tests.c index 51423e58..d872503e 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/tests.c +++ b/secp256k1-zkp-sys/depend/secp256k1/src/tests.c @@ -4,20 +4,26 @@ * file COPYING or https://www.opensource.org/licenses/mit-license.php.* ***********************************************************************/ -#if defined HAVE_CONFIG_H -#include "libsecp256k1-config.h" -#endif - #include #include #include #include +#ifdef USE_EXTERNAL_DEFAULT_CALLBACKS + #pragma message("Ignoring USE_EXTERNAL_CALLBACKS in tests.") + #undef USE_EXTERNAL_DEFAULT_CALLBACKS +#endif +#if defined(VERIFY) && defined(COVERAGE) + #pragma message("Defining VERIFY for tests being built for coverage analysis support is meaningless.") +#endif #include "secp256k1.c" + #include "../include/secp256k1.h" #include "../include/secp256k1_preallocated.h" #include "testrand_impl.h" +#include "checkmem.h" +#include "testutil.h" #include "util.h" #include "../contrib/lax_der_parsing.c" @@ -26,18 +32,58 @@ #include "modinv32_impl.h" #ifdef SECP256K1_WIDEMUL_INT128 #include "modinv64_impl.h" +#include "int128_impl.h" #endif -#define CONDITIONAL_TEST(cnt, nam) if (count < (cnt)) { printf("Skipping %s (iteration count too low)\n", nam); } else +#define CONDITIONAL_TEST(cnt, nam) if (COUNT < (cnt)) { printf("Skipping %s (iteration count too low)\n", nam); } else + +static int COUNT = 64; +static rustsecp256k1zkp_v0_10_0_context *CTX = NULL; +static rustsecp256k1zkp_v0_10_0_context *STATIC_CTX = NULL; + +static int all_bytes_equal(const void* s, unsigned char value, size_t n) { + const unsigned char *p = s; + size_t i; -static int count = 64; -static rustsecp256k1zkp_v0_8_0_context *ctx = NULL; + for (i = 0; i < n; i++) { + if (p[i] != value) { + return 0; + } + } + return 1; +} + +#define CHECK_COUNTING_CALLBACK_VOID(ctx, expr_or_stmt, callback, callback_setter) do { \ + int32_t _calls_to_callback = 0; \ + rustsecp256k1zkp_v0_10_0_callback _saved_callback = ctx->callback; \ + callback_setter(ctx, counting_callback_fn, &_calls_to_callback); \ + { expr_or_stmt; } \ + ctx->callback = _saved_callback; \ + CHECK(_calls_to_callback == 1); \ +} while(0); -static void counting_illegal_callback_fn(const char* str, void* data) { +/* CHECK that expr_or_stmt calls the error or illegal callback of ctx exactly once + * + * Useful for checking functions that return void (e.g., API functions that use ARG_CHECK_VOID) */ +#define CHECK_ERROR_VOID(ctx, expr_or_stmt) \ + CHECK_COUNTING_CALLBACK_VOID(ctx, expr_or_stmt, error_callback, rustsecp256k1zkp_v0_10_0_context_set_error_callback) +#define CHECK_ILLEGAL_VOID(ctx, expr_or_stmt) \ + CHECK_COUNTING_CALLBACK_VOID(ctx, expr_or_stmt, illegal_callback, rustsecp256k1zkp_v0_10_0_context_set_illegal_callback) + +/* CHECK that + * - expr calls the illegal callback of ctx exactly once and, + * - expr == 0 (or equivalently, expr == NULL) + * + * Useful for checking functions that return an integer or a pointer. */ +#define CHECK_ILLEGAL(ctx, expr) CHECK_ILLEGAL_VOID(ctx, CHECK((expr) == 0)) +#define CHECK_ERROR(ctx, expr) CHECK_ERROR_VOID(ctx, CHECK((expr) == 0)) + +static void counting_callback_fn(const char* str, void* data) { /* Dummy callback function that just counts. */ int32_t *p; (void)str; p = data; + CHECK(*p != INT32_MAX); (*p)++; } @@ -46,458 +92,525 @@ static void uncounting_illegal_callback_fn(const char* str, void* data) { int32_t *p; (void)str; p = data; + CHECK(*p != INT32_MIN); (*p)--; } -void random_field_element_test(rustsecp256k1zkp_v0_8_0_fe *fe) { - do { - unsigned char b32[32]; - rustsecp256k1zkp_v0_8_0_testrand256_test(b32); - if (rustsecp256k1zkp_v0_8_0_fe_set_b32(fe, b32)) { - break; - } - } while(1); -} - -void random_field_element_magnitude(rustsecp256k1zkp_v0_8_0_fe *fe) { - rustsecp256k1zkp_v0_8_0_fe zero; - int n = rustsecp256k1zkp_v0_8_0_testrand_int(9); - rustsecp256k1zkp_v0_8_0_fe_normalize(fe); +static void random_field_element_magnitude(rustsecp256k1zkp_v0_10_0_fe *fe, int m) { + rustsecp256k1zkp_v0_10_0_fe zero; + int n = rustsecp256k1zkp_v0_10_0_testrand_int(m + 1); + rustsecp256k1zkp_v0_10_0_fe_normalize(fe); if (n == 0) { return; } - rustsecp256k1zkp_v0_8_0_fe_clear(&zero); - rustsecp256k1zkp_v0_8_0_fe_negate(&zero, &zero, 0); - rustsecp256k1zkp_v0_8_0_fe_mul_int(&zero, n - 1); - rustsecp256k1zkp_v0_8_0_fe_add(fe, &zero); + rustsecp256k1zkp_v0_10_0_fe_clear(&zero); + rustsecp256k1zkp_v0_10_0_fe_negate(&zero, &zero, 0); + rustsecp256k1zkp_v0_10_0_fe_mul_int_unchecked(&zero, n - 1); + rustsecp256k1zkp_v0_10_0_fe_add(fe, &zero); #ifdef VERIFY CHECK(fe->magnitude == n); #endif } -void random_group_element_test(rustsecp256k1zkp_v0_8_0_ge *ge) { - rustsecp256k1zkp_v0_8_0_fe fe; +static void random_fe_test(rustsecp256k1zkp_v0_10_0_fe *x) { + unsigned char bin[32]; do { - random_field_element_test(&fe); - if (rustsecp256k1zkp_v0_8_0_ge_set_xo_var(ge, &fe, rustsecp256k1zkp_v0_8_0_testrand_bits(1))) { - rustsecp256k1zkp_v0_8_0_fe_normalize(&ge->y); - break; + rustsecp256k1zkp_v0_10_0_testrand256_test(bin); + if (rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(x, bin)) { + return; } } while(1); - ge->infinity = 0; } -void random_group_element_jacobian_test(rustsecp256k1zkp_v0_8_0_gej *gej, const rustsecp256k1zkp_v0_8_0_ge *ge) { - rustsecp256k1zkp_v0_8_0_fe z2, z3; +static void random_fe_non_zero_test(rustsecp256k1zkp_v0_10_0_fe *fe) { do { - random_field_element_test(&gej->z); - if (!rustsecp256k1zkp_v0_8_0_fe_is_zero(&gej->z)) { + random_fe_test(fe); + } while(rustsecp256k1zkp_v0_10_0_fe_is_zero(fe)); +} + +static void random_fe_magnitude(rustsecp256k1zkp_v0_10_0_fe *fe) { + random_field_element_magnitude(fe, 8); +} + +static void random_ge_x_magnitude(rustsecp256k1zkp_v0_10_0_ge *ge) { + random_field_element_magnitude(&ge->x, SECP256K1_GE_X_MAGNITUDE_MAX); +} + +static void random_ge_y_magnitude(rustsecp256k1zkp_v0_10_0_ge *ge) { + random_field_element_magnitude(&ge->y, SECP256K1_GE_Y_MAGNITUDE_MAX); +} + +static void random_gej_x_magnitude(rustsecp256k1zkp_v0_10_0_gej *gej) { + random_field_element_magnitude(&gej->x, SECP256K1_GEJ_X_MAGNITUDE_MAX); +} + +static void random_gej_y_magnitude(rustsecp256k1zkp_v0_10_0_gej *gej) { + random_field_element_magnitude(&gej->y, SECP256K1_GEJ_Y_MAGNITUDE_MAX); +} + +static void random_gej_z_magnitude(rustsecp256k1zkp_v0_10_0_gej *gej) { + random_field_element_magnitude(&gej->z, SECP256K1_GEJ_Z_MAGNITUDE_MAX); +} + +static void random_group_element_test(rustsecp256k1zkp_v0_10_0_ge *ge) { + rustsecp256k1zkp_v0_10_0_fe fe; + do { + random_fe_test(&fe); + if (rustsecp256k1zkp_v0_10_0_ge_set_xo_var(ge, &fe, rustsecp256k1zkp_v0_10_0_testrand_bits(1))) { + rustsecp256k1zkp_v0_10_0_fe_normalize(&ge->y); break; } } while(1); - rustsecp256k1zkp_v0_8_0_fe_sqr(&z2, &gej->z); - rustsecp256k1zkp_v0_8_0_fe_mul(&z3, &z2, &gej->z); - rustsecp256k1zkp_v0_8_0_fe_mul(&gej->x, &ge->x, &z2); - rustsecp256k1zkp_v0_8_0_fe_mul(&gej->y, &ge->y, &z3); + ge->infinity = 0; +} + +static void random_group_element_jacobian_test(rustsecp256k1zkp_v0_10_0_gej *gej, const rustsecp256k1zkp_v0_10_0_ge *ge) { + rustsecp256k1zkp_v0_10_0_fe z2, z3; + random_fe_non_zero_test(&gej->z); + rustsecp256k1zkp_v0_10_0_fe_sqr(&z2, &gej->z); + rustsecp256k1zkp_v0_10_0_fe_mul(&z3, &z2, &gej->z); + rustsecp256k1zkp_v0_10_0_fe_mul(&gej->x, &ge->x, &z2); + rustsecp256k1zkp_v0_10_0_fe_mul(&gej->y, &ge->y, &z3); gej->infinity = ge->infinity; } -void random_gej_test(rustsecp256k1zkp_v0_8_0_gej *gej) { - rustsecp256k1zkp_v0_8_0_ge ge; +static void random_gej_test(rustsecp256k1zkp_v0_10_0_gej *gej) { + rustsecp256k1zkp_v0_10_0_ge ge; random_group_element_test(&ge); random_group_element_jacobian_test(gej, &ge); } -void random_scalar_order_test(rustsecp256k1zkp_v0_8_0_scalar *num) { +static void random_scalar_order_test(rustsecp256k1zkp_v0_10_0_scalar *num) { do { unsigned char b32[32]; int overflow = 0; - rustsecp256k1zkp_v0_8_0_testrand256_test(b32); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(num, b32, &overflow); - if (overflow || rustsecp256k1zkp_v0_8_0_scalar_is_zero(num)) { + rustsecp256k1zkp_v0_10_0_testrand256_test(b32); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(num, b32, &overflow); + if (overflow || rustsecp256k1zkp_v0_10_0_scalar_is_zero(num)) { continue; } break; } while(1); } -void random_scalar_order(rustsecp256k1zkp_v0_8_0_scalar *num) { +static void random_scalar_order(rustsecp256k1zkp_v0_10_0_scalar *num) { do { unsigned char b32[32]; int overflow = 0; - rustsecp256k1zkp_v0_8_0_testrand256(b32); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(num, b32, &overflow); - if (overflow || rustsecp256k1zkp_v0_8_0_scalar_is_zero(num)) { + rustsecp256k1zkp_v0_10_0_testrand256(b32); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(num, b32, &overflow); + if (overflow || rustsecp256k1zkp_v0_10_0_scalar_is_zero(num)) { continue; } break; } while(1); } -void random_scalar_order_b32(unsigned char *b32) { - rustsecp256k1zkp_v0_8_0_scalar num; +static void random_scalar_order_b32(unsigned char *b32) { + rustsecp256k1zkp_v0_10_0_scalar num; random_scalar_order(&num); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(b32, &num); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(b32, &num); } -void run_util_tests(void) { +static void run_util_tests(void) { int i; uint64_t r; uint64_t r2; uint64_t r3; int64_t s; - CHECK(rustsecp256k1zkp_v0_8_0_clz64_var(0) == 64); - CHECK(rustsecp256k1zkp_v0_8_0_clz64_var(1) == 63); - CHECK(rustsecp256k1zkp_v0_8_0_clz64_var(2) == 62); - CHECK(rustsecp256k1zkp_v0_8_0_clz64_var(3) == 62); - CHECK(rustsecp256k1zkp_v0_8_0_clz64_var(~0ULL) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_clz64_var((~0ULL) - 1) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_clz64_var((~0ULL) >> 1) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_clz64_var((~0ULL) >> 2) == 2); - CHECK(rustsecp256k1zkp_v0_8_0_sign_and_abs64(&r, INT64_MAX) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_clz64_var(0) == 64); + CHECK(rustsecp256k1zkp_v0_10_0_clz64_var(1) == 63); + CHECK(rustsecp256k1zkp_v0_10_0_clz64_var(2) == 62); + CHECK(rustsecp256k1zkp_v0_10_0_clz64_var(3) == 62); + CHECK(rustsecp256k1zkp_v0_10_0_clz64_var(~0ULL) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_clz64_var((~0ULL) - 1) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_clz64_var((~0ULL) >> 1) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_clz64_var((~0ULL) >> 2) == 2); + CHECK(rustsecp256k1zkp_v0_10_0_sign_and_abs64(&r, INT64_MAX) == 0); CHECK(r == INT64_MAX); - CHECK(rustsecp256k1zkp_v0_8_0_sign_and_abs64(&r, INT64_MAX - 1) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_sign_and_abs64(&r, INT64_MAX - 1) == 0); CHECK(r == INT64_MAX - 1); - CHECK(rustsecp256k1zkp_v0_8_0_sign_and_abs64(&r, INT64_MIN) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_sign_and_abs64(&r, INT64_MIN) == 1); CHECK(r == (uint64_t)INT64_MAX + 1); - CHECK(rustsecp256k1zkp_v0_8_0_sign_and_abs64(&r, INT64_MIN + 1) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_sign_and_abs64(&r, INT64_MIN + 1) == 1); CHECK(r == (uint64_t)INT64_MAX); - CHECK(rustsecp256k1zkp_v0_8_0_sign_and_abs64(&r, 0) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_sign_and_abs64(&r, 0) == 0); CHECK(r == 0); - CHECK(rustsecp256k1zkp_v0_8_0_sign_and_abs64(&r, 1) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_sign_and_abs64(&r, 1) == 0); CHECK(r == 1); - CHECK(rustsecp256k1zkp_v0_8_0_sign_and_abs64(&r, -1) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_sign_and_abs64(&r, -1) == 1); CHECK(r == 1); - CHECK(rustsecp256k1zkp_v0_8_0_sign_and_abs64(&r, 2) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_sign_and_abs64(&r, 2) == 0); CHECK(r == 2); - CHECK(rustsecp256k1zkp_v0_8_0_sign_and_abs64(&r, -2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_sign_and_abs64(&r, -2) == 1); CHECK(r == 2); for (i = 0; i < 10; i++) { - CHECK(rustsecp256k1zkp_v0_8_0_clz64_var((~0ULL) - rustsecp256k1zkp_v0_8_0_testrand32()) == 0); - r = ((uint64_t)rustsecp256k1zkp_v0_8_0_testrand32() << 32) | rustsecp256k1zkp_v0_8_0_testrand32(); - r2 = rustsecp256k1zkp_v0_8_0_testrandi64(0, r); + CHECK(rustsecp256k1zkp_v0_10_0_clz64_var((~0ULL) - rustsecp256k1zkp_v0_10_0_testrand32()) == 0); + r = ((uint64_t)rustsecp256k1zkp_v0_10_0_testrand32() << 32) | rustsecp256k1zkp_v0_10_0_testrand32(); + r2 = rustsecp256k1zkp_v0_10_0_testrandi64(0, r); CHECK(r2 <= r); - r3 = rustsecp256k1zkp_v0_8_0_testrandi64(r2, r); + r3 = rustsecp256k1zkp_v0_10_0_testrandi64(r2, r); CHECK((r3 >= r2) && (r3 <= r)); - r = rustsecp256k1zkp_v0_8_0_testrandi64(0, INT64_MAX); - s = (int64_t)r * (rustsecp256k1zkp_v0_8_0_testrand32()&1?-1:1); - CHECK(rustsecp256k1zkp_v0_8_0_sign_and_abs64(&r2, s) == (s < 0)); + r = rustsecp256k1zkp_v0_10_0_testrandi64(0, INT64_MAX); + s = (int64_t)r * (rustsecp256k1zkp_v0_10_0_testrand32()&1?-1:1); + CHECK(rustsecp256k1zkp_v0_10_0_sign_and_abs64(&r2, s) == (s < 0)); CHECK(r2 == r); } } -void run_context_tests(int use_prealloc) { - rustsecp256k1zkp_v0_8_0_pubkey pubkey; - rustsecp256k1zkp_v0_8_0_pubkey zero_pubkey; - rustsecp256k1zkp_v0_8_0_ecdsa_signature sig; +static void run_xoshiro256pp_tests(void) { + { + size_t i; + /* Sanity check that we run before the actual seeding. */ + for (i = 0; i < sizeof(rustsecp256k1zkp_v0_10_0_test_state)/sizeof(rustsecp256k1zkp_v0_10_0_test_state[0]); i++) { + CHECK(rustsecp256k1zkp_v0_10_0_test_state[i] == 0); + } + } + { + int i; + unsigned char buf32[32]; + unsigned char seed16[16] = { + 'C', 'H', 'I', 'C', 'K', 'E', 'N', '!', + 'C', 'H', 'I', 'C', 'K', 'E', 'N', '!', + }; + unsigned char buf32_expected[32] = { + 0xAF, 0xCC, 0xA9, 0x16, 0xB5, 0x6C, 0xE3, 0xF0, + 0x44, 0x3F, 0x45, 0xE0, 0x47, 0xA5, 0x08, 0x36, + 0x4C, 0xCC, 0xC1, 0x18, 0xB2, 0xD8, 0x8F, 0xEF, + 0x43, 0x26, 0x15, 0x57, 0x37, 0x00, 0xEF, 0x30, + }; + rustsecp256k1zkp_v0_10_0_testrand_seed(seed16); + for (i = 0; i < 17; i++) { + rustsecp256k1zkp_v0_10_0_testrand256(buf32); + } + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(buf32, buf32_expected, sizeof(buf32)) == 0); + } +} + +static void run_selftest_tests(void) { + /* Test public API */ + rustsecp256k1zkp_v0_10_0_selftest(); +} + +static int ecmult_gen_context_eq(const rustsecp256k1zkp_v0_10_0_ecmult_gen_context *a, const rustsecp256k1zkp_v0_10_0_ecmult_gen_context *b) { + return a->built == b->built + && rustsecp256k1zkp_v0_10_0_scalar_eq(&a->blind, &b->blind) + && rustsecp256k1zkp_v0_10_0_gej_eq_var(&a->initial, &b->initial); +} + +static int context_eq(const rustsecp256k1zkp_v0_10_0_context *a, const rustsecp256k1zkp_v0_10_0_context *b) { + return a->declassify == b->declassify + && ecmult_gen_context_eq(&a->ecmult_gen_ctx, &b->ecmult_gen_ctx) + && a->illegal_callback.fn == b->illegal_callback.fn + && a->illegal_callback.data == b->illegal_callback.data + && a->error_callback.fn == b->error_callback.fn + && a->error_callback.data == b->error_callback.data; +} + +static void run_deprecated_context_flags_test(void) { + /* Check that a context created with any of the flags in the flags array is + * identical to the NONE context. */ + unsigned int flags[] = { SECP256K1_CONTEXT_SIGN, + SECP256K1_CONTEXT_VERIFY, + SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY }; + rustsecp256k1zkp_v0_10_0_context *none_ctx = rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_CONTEXT_NONE); + int i; + for (i = 0; i < (int)(sizeof(flags)/sizeof(flags[0])); i++) { + rustsecp256k1zkp_v0_10_0_context *tmp_ctx; + CHECK(rustsecp256k1zkp_v0_10_0_context_preallocated_size(SECP256K1_CONTEXT_NONE) == rustsecp256k1zkp_v0_10_0_context_preallocated_size(flags[i])); + tmp_ctx = rustsecp256k1zkp_v0_10_0_context_create(flags[i]); + CHECK(context_eq(none_ctx, tmp_ctx)); + rustsecp256k1zkp_v0_10_0_context_destroy(tmp_ctx); + } + rustsecp256k1zkp_v0_10_0_context_destroy(none_ctx); +} + +static void run_ec_illegal_argument_tests(void) { + rustsecp256k1zkp_v0_10_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_pubkey zero_pubkey; + rustsecp256k1zkp_v0_10_0_ecdsa_signature sig; unsigned char ctmp[32]; - int32_t ecount; - int32_t ecount2; - rustsecp256k1zkp_v0_8_0_context *none; - rustsecp256k1zkp_v0_8_0_context *sign; - rustsecp256k1zkp_v0_8_0_context *vrfy; - rustsecp256k1zkp_v0_8_0_context *both; - rustsecp256k1zkp_v0_8_0_context *sttc; - void *none_prealloc = NULL; - void *sign_prealloc = NULL; - void *vrfy_prealloc = NULL; - void *both_prealloc = NULL; - void *sttc_prealloc = NULL; - - rustsecp256k1zkp_v0_8_0_gej pubj; - rustsecp256k1zkp_v0_8_0_ge pub; - rustsecp256k1zkp_v0_8_0_scalar msg, key, nonce; - rustsecp256k1zkp_v0_8_0_scalar sigr, sigs; + + /* Setup */ + memset(ctmp, 1, 32); + memset(&zero_pubkey, 0, sizeof(zero_pubkey)); + + /* Verify context-type checking illegal-argument errors. */ + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_create(STATIC_CTX, &pubkey, ctmp)); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey, ctmp) == 1); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(pubkey)); + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_ecdsa_sign(STATIC_CTX, &sig, ctmp, ctmp, NULL, NULL)); + SECP256K1_CHECKMEM_UNDEFINE(&sig, sizeof(sig)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &sig, ctmp, ctmp, NULL, NULL) == 1); + SECP256K1_CHECKMEM_CHECK(&sig, sizeof(sig)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &sig, ctmp, &pubkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(STATIC_CTX, &sig, ctmp, &pubkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add(CTX, &pubkey, ctmp) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add(STATIC_CTX, &pubkey, ctmp) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_mul(CTX, &pubkey, ctmp) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_negate(STATIC_CTX, &pubkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_negate(CTX, &pubkey) == 1); + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_negate(STATIC_CTX, &zero_pubkey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_negate(CTX, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_mul(STATIC_CTX, &pubkey, ctmp) == 1); +} + +static void run_static_context_tests(int use_prealloc) { + /* Check that deprecated rustsecp256k1zkp_v0_10_0_context_no_precomp is an alias to rustsecp256k1zkp_v0_10_0_context_static. */ + CHECK(rustsecp256k1zkp_v0_10_0_context_no_precomp == rustsecp256k1zkp_v0_10_0_context_static); + + { + unsigned char seed[32] = {0x17}; + + /* Randomizing rustsecp256k1zkp_v0_10_0_context_static is not supported. */ + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_context_randomize(STATIC_CTX, seed)); + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_context_randomize(STATIC_CTX, NULL)); + + /* Destroying or cloning rustsecp256k1zkp_v0_10_0_context_static is not supported. */ + if (use_prealloc) { + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_context_preallocated_clone_size(STATIC_CTX)); + { + rustsecp256k1zkp_v0_10_0_context *my_static_ctx = malloc(sizeof(*STATIC_CTX)); + CHECK(my_static_ctx != NULL); + memset(my_static_ctx, 0x2a, sizeof(*my_static_ctx)); + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_context_preallocated_clone(STATIC_CTX, my_static_ctx)); + CHECK(all_bytes_equal(my_static_ctx, 0x2a, sizeof(*my_static_ctx))); + free(my_static_ctx); + } + CHECK_ILLEGAL_VOID(STATIC_CTX, rustsecp256k1zkp_v0_10_0_context_preallocated_destroy(STATIC_CTX)); + } else { + CHECK_ILLEGAL(STATIC_CTX, rustsecp256k1zkp_v0_10_0_context_clone(STATIC_CTX)); + CHECK_ILLEGAL_VOID(STATIC_CTX, rustsecp256k1zkp_v0_10_0_context_destroy(STATIC_CTX)); + } + } + + { + /* Verify that setting and resetting illegal callback works */ + int32_t dummy = 0; + rustsecp256k1zkp_v0_10_0_context_set_illegal_callback(STATIC_CTX, counting_callback_fn, &dummy); + CHECK(STATIC_CTX->illegal_callback.fn == counting_callback_fn); + CHECK(STATIC_CTX->illegal_callback.data == &dummy); + rustsecp256k1zkp_v0_10_0_context_set_illegal_callback(STATIC_CTX, NULL, NULL); + CHECK(STATIC_CTX->illegal_callback.fn == rustsecp256k1zkp_v0_10_0_default_illegal_callback_fn); + CHECK(STATIC_CTX->illegal_callback.data == NULL); + } +} + +static void run_proper_context_tests(int use_prealloc) { + int32_t dummy = 0; + rustsecp256k1zkp_v0_10_0_context *my_ctx, *my_ctx_fresh; + void *my_ctx_prealloc = NULL; + unsigned char seed[32] = {0x17}; + + rustsecp256k1zkp_v0_10_0_gej pubj; + rustsecp256k1zkp_v0_10_0_ge pub; + rustsecp256k1zkp_v0_10_0_scalar msg, key, nonce; + rustsecp256k1zkp_v0_10_0_scalar sigr, sigs; + + /* Fresh reference context for comparison */ + my_ctx_fresh = rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_CONTEXT_NONE); if (use_prealloc) { - none_prealloc = malloc(rustsecp256k1zkp_v0_8_0_context_preallocated_size(SECP256K1_CONTEXT_NONE)); - sign_prealloc = malloc(rustsecp256k1zkp_v0_8_0_context_preallocated_size(SECP256K1_CONTEXT_SIGN)); - vrfy_prealloc = malloc(rustsecp256k1zkp_v0_8_0_context_preallocated_size(SECP256K1_CONTEXT_VERIFY)); - both_prealloc = malloc(rustsecp256k1zkp_v0_8_0_context_preallocated_size(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY)); - sttc_prealloc = malloc(rustsecp256k1zkp_v0_8_0_context_preallocated_clone_size(rustsecp256k1zkp_v0_8_0_context_no_precomp)); - CHECK(none_prealloc != NULL); - CHECK(sign_prealloc != NULL); - CHECK(vrfy_prealloc != NULL); - CHECK(both_prealloc != NULL); - CHECK(sttc_prealloc != NULL); - none = rustsecp256k1zkp_v0_8_0_context_preallocated_create(none_prealloc, SECP256K1_CONTEXT_NONE); - sign = rustsecp256k1zkp_v0_8_0_context_preallocated_create(sign_prealloc, SECP256K1_CONTEXT_SIGN); - vrfy = rustsecp256k1zkp_v0_8_0_context_preallocated_create(vrfy_prealloc, SECP256K1_CONTEXT_VERIFY); - both = rustsecp256k1zkp_v0_8_0_context_preallocated_create(both_prealloc, SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); - sttc = rustsecp256k1zkp_v0_8_0_context_preallocated_clone(rustsecp256k1zkp_v0_8_0_context_no_precomp, sttc_prealloc); + my_ctx_prealloc = malloc(rustsecp256k1zkp_v0_10_0_context_preallocated_size(SECP256K1_CONTEXT_NONE)); + CHECK(my_ctx_prealloc != NULL); + my_ctx = rustsecp256k1zkp_v0_10_0_context_preallocated_create(my_ctx_prealloc, SECP256K1_CONTEXT_NONE); } else { - none = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_NONE); - sign = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN); - vrfy = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_VERIFY); - both = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); - sttc = rustsecp256k1zkp_v0_8_0_context_clone(rustsecp256k1zkp_v0_8_0_context_no_precomp); + my_ctx = rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_CONTEXT_NONE); } - memset(&zero_pubkey, 0, sizeof(zero_pubkey)); + /* Randomize and reset randomization */ + CHECK(context_eq(my_ctx, my_ctx_fresh)); + CHECK(rustsecp256k1zkp_v0_10_0_context_randomize(my_ctx, seed) == 1); + CHECK(!context_eq(my_ctx, my_ctx_fresh)); + CHECK(rustsecp256k1zkp_v0_10_0_context_randomize(my_ctx, NULL) == 1); + CHECK(context_eq(my_ctx, my_ctx_fresh)); - ecount = 0; - ecount2 = 10; - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sttc, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sign, counting_illegal_callback_fn, &ecount2); - /* set error callback (to a function that still aborts in case malloc() fails in rustsecp256k1zkp_v0_8_0_context_clone() below) */ - rustsecp256k1zkp_v0_8_0_context_set_error_callback(sign, rustsecp256k1zkp_v0_8_0_default_illegal_callback_fn, NULL); - CHECK(sign->error_callback.fn != vrfy->error_callback.fn); - CHECK(sign->error_callback.fn == rustsecp256k1zkp_v0_8_0_default_illegal_callback_fn); + /* set error callback (to a function that still aborts in case malloc() fails in rustsecp256k1zkp_v0_10_0_context_clone() below) */ + rustsecp256k1zkp_v0_10_0_context_set_error_callback(my_ctx, rustsecp256k1zkp_v0_10_0_default_illegal_callback_fn, NULL); + CHECK(my_ctx->error_callback.fn != rustsecp256k1zkp_v0_10_0_default_error_callback_fn); + CHECK(my_ctx->error_callback.fn == rustsecp256k1zkp_v0_10_0_default_illegal_callback_fn); /* check if sizes for cloning are consistent */ - CHECK(rustsecp256k1zkp_v0_8_0_context_preallocated_clone_size(none) == rustsecp256k1zkp_v0_8_0_context_preallocated_size(SECP256K1_CONTEXT_NONE)); - CHECK(rustsecp256k1zkp_v0_8_0_context_preallocated_clone_size(sign) == rustsecp256k1zkp_v0_8_0_context_preallocated_size(SECP256K1_CONTEXT_SIGN)); - CHECK(rustsecp256k1zkp_v0_8_0_context_preallocated_clone_size(vrfy) == rustsecp256k1zkp_v0_8_0_context_preallocated_size(SECP256K1_CONTEXT_VERIFY)); - CHECK(rustsecp256k1zkp_v0_8_0_context_preallocated_clone_size(both) == rustsecp256k1zkp_v0_8_0_context_preallocated_size(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY)); - CHECK(rustsecp256k1zkp_v0_8_0_context_preallocated_clone_size(sttc) >= sizeof(rustsecp256k1zkp_v0_8_0_context)); + CHECK(rustsecp256k1zkp_v0_10_0_context_preallocated_clone_size(my_ctx) == rustsecp256k1zkp_v0_10_0_context_preallocated_size(SECP256K1_CONTEXT_NONE)); /*** clone and destroy all of them to make sure cloning was complete ***/ { - rustsecp256k1zkp_v0_8_0_context *ctx_tmp; + rustsecp256k1zkp_v0_10_0_context *ctx_tmp; if (use_prealloc) { /* clone into a non-preallocated context and then again into a new preallocated one. */ - ctx_tmp = none; none = rustsecp256k1zkp_v0_8_0_context_clone(none); rustsecp256k1zkp_v0_8_0_context_preallocated_destroy(ctx_tmp); - free(none_prealloc); none_prealloc = malloc(rustsecp256k1zkp_v0_8_0_context_preallocated_size(SECP256K1_CONTEXT_NONE)); CHECK(none_prealloc != NULL); - ctx_tmp = none; none = rustsecp256k1zkp_v0_8_0_context_preallocated_clone(none, none_prealloc); rustsecp256k1zkp_v0_8_0_context_destroy(ctx_tmp); - - ctx_tmp = sign; sign = rustsecp256k1zkp_v0_8_0_context_clone(sign); rustsecp256k1zkp_v0_8_0_context_preallocated_destroy(ctx_tmp); - free(sign_prealloc); sign_prealloc = malloc(rustsecp256k1zkp_v0_8_0_context_preallocated_size(SECP256K1_CONTEXT_SIGN)); CHECK(sign_prealloc != NULL); - ctx_tmp = sign; sign = rustsecp256k1zkp_v0_8_0_context_preallocated_clone(sign, sign_prealloc); rustsecp256k1zkp_v0_8_0_context_destroy(ctx_tmp); - - ctx_tmp = vrfy; vrfy = rustsecp256k1zkp_v0_8_0_context_clone(vrfy); rustsecp256k1zkp_v0_8_0_context_preallocated_destroy(ctx_tmp); - free(vrfy_prealloc); vrfy_prealloc = malloc(rustsecp256k1zkp_v0_8_0_context_preallocated_size(SECP256K1_CONTEXT_VERIFY)); CHECK(vrfy_prealloc != NULL); - ctx_tmp = vrfy; vrfy = rustsecp256k1zkp_v0_8_0_context_preallocated_clone(vrfy, vrfy_prealloc); rustsecp256k1zkp_v0_8_0_context_destroy(ctx_tmp); - - ctx_tmp = both; both = rustsecp256k1zkp_v0_8_0_context_clone(both); rustsecp256k1zkp_v0_8_0_context_preallocated_destroy(ctx_tmp); - free(both_prealloc); both_prealloc = malloc(rustsecp256k1zkp_v0_8_0_context_preallocated_size(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY)); CHECK(both_prealloc != NULL); - ctx_tmp = both; both = rustsecp256k1zkp_v0_8_0_context_preallocated_clone(both, both_prealloc); rustsecp256k1zkp_v0_8_0_context_destroy(ctx_tmp); + ctx_tmp = my_ctx; + my_ctx = rustsecp256k1zkp_v0_10_0_context_clone(my_ctx); + CHECK(context_eq(ctx_tmp, my_ctx)); + rustsecp256k1zkp_v0_10_0_context_preallocated_destroy(ctx_tmp); + + free(my_ctx_prealloc); + my_ctx_prealloc = malloc(rustsecp256k1zkp_v0_10_0_context_preallocated_size(SECP256K1_CONTEXT_NONE)); + CHECK(my_ctx_prealloc != NULL); + ctx_tmp = my_ctx; + my_ctx = rustsecp256k1zkp_v0_10_0_context_preallocated_clone(my_ctx, my_ctx_prealloc); + CHECK(context_eq(ctx_tmp, my_ctx)); + rustsecp256k1zkp_v0_10_0_context_destroy(ctx_tmp); } else { /* clone into a preallocated context and then again into a new non-preallocated one. */ void *prealloc_tmp; - prealloc_tmp = malloc(rustsecp256k1zkp_v0_8_0_context_preallocated_size(SECP256K1_CONTEXT_NONE)); CHECK(prealloc_tmp != NULL); - ctx_tmp = none; none = rustsecp256k1zkp_v0_8_0_context_preallocated_clone(none, prealloc_tmp); rustsecp256k1zkp_v0_8_0_context_destroy(ctx_tmp); - ctx_tmp = none; none = rustsecp256k1zkp_v0_8_0_context_clone(none); rustsecp256k1zkp_v0_8_0_context_preallocated_destroy(ctx_tmp); - free(prealloc_tmp); - - prealloc_tmp = malloc(rustsecp256k1zkp_v0_8_0_context_preallocated_size(SECP256K1_CONTEXT_SIGN)); CHECK(prealloc_tmp != NULL); - ctx_tmp = sign; sign = rustsecp256k1zkp_v0_8_0_context_preallocated_clone(sign, prealloc_tmp); rustsecp256k1zkp_v0_8_0_context_destroy(ctx_tmp); - ctx_tmp = sign; sign = rustsecp256k1zkp_v0_8_0_context_clone(sign); rustsecp256k1zkp_v0_8_0_context_preallocated_destroy(ctx_tmp); - free(prealloc_tmp); - - prealloc_tmp = malloc(rustsecp256k1zkp_v0_8_0_context_preallocated_size(SECP256K1_CONTEXT_VERIFY)); CHECK(prealloc_tmp != NULL); - ctx_tmp = vrfy; vrfy = rustsecp256k1zkp_v0_8_0_context_preallocated_clone(vrfy, prealloc_tmp); rustsecp256k1zkp_v0_8_0_context_destroy(ctx_tmp); - ctx_tmp = vrfy; vrfy = rustsecp256k1zkp_v0_8_0_context_clone(vrfy); rustsecp256k1zkp_v0_8_0_context_preallocated_destroy(ctx_tmp); - free(prealloc_tmp); - - prealloc_tmp = malloc(rustsecp256k1zkp_v0_8_0_context_preallocated_size(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY)); CHECK(prealloc_tmp != NULL); - ctx_tmp = both; both = rustsecp256k1zkp_v0_8_0_context_preallocated_clone(both, prealloc_tmp); rustsecp256k1zkp_v0_8_0_context_destroy(ctx_tmp); - ctx_tmp = both; both = rustsecp256k1zkp_v0_8_0_context_clone(both); rustsecp256k1zkp_v0_8_0_context_preallocated_destroy(ctx_tmp); + prealloc_tmp = malloc(rustsecp256k1zkp_v0_10_0_context_preallocated_size(SECP256K1_CONTEXT_NONE)); + CHECK(prealloc_tmp != NULL); + ctx_tmp = my_ctx; + my_ctx = rustsecp256k1zkp_v0_10_0_context_preallocated_clone(my_ctx, prealloc_tmp); + CHECK(context_eq(ctx_tmp, my_ctx)); + rustsecp256k1zkp_v0_10_0_context_destroy(ctx_tmp); + + ctx_tmp = my_ctx; + my_ctx = rustsecp256k1zkp_v0_10_0_context_clone(my_ctx); + CHECK(context_eq(ctx_tmp, my_ctx)); + rustsecp256k1zkp_v0_10_0_context_preallocated_destroy(ctx_tmp); free(prealloc_tmp); } } /* Verify that the error callback makes it across the clone. */ - CHECK(sign->error_callback.fn != vrfy->error_callback.fn); - CHECK(sign->error_callback.fn == rustsecp256k1zkp_v0_8_0_default_illegal_callback_fn); + CHECK(my_ctx->error_callback.fn != rustsecp256k1zkp_v0_10_0_default_error_callback_fn); + CHECK(my_ctx->error_callback.fn == rustsecp256k1zkp_v0_10_0_default_illegal_callback_fn); /* And that it resets back to default. */ - rustsecp256k1zkp_v0_8_0_context_set_error_callback(sign, NULL, NULL); - CHECK(vrfy->error_callback.fn == sign->error_callback.fn); + rustsecp256k1zkp_v0_10_0_context_set_error_callback(my_ctx, NULL, NULL); + CHECK(my_ctx->error_callback.fn == rustsecp256k1zkp_v0_10_0_default_error_callback_fn); + CHECK(context_eq(my_ctx, my_ctx_fresh)); + + /* Verify that setting and resetting illegal callback works */ + rustsecp256k1zkp_v0_10_0_context_set_illegal_callback(my_ctx, counting_callback_fn, &dummy); + CHECK(my_ctx->illegal_callback.fn == counting_callback_fn); + CHECK(my_ctx->illegal_callback.data == &dummy); + rustsecp256k1zkp_v0_10_0_context_set_illegal_callback(my_ctx, NULL, NULL); + CHECK(my_ctx->illegal_callback.fn == rustsecp256k1zkp_v0_10_0_default_illegal_callback_fn); + CHECK(my_ctx->illegal_callback.data == NULL); + CHECK(context_eq(my_ctx, my_ctx_fresh)); /*** attempt to use them ***/ random_scalar_order_test(&msg); random_scalar_order_test(&key); - rustsecp256k1zkp_v0_8_0_ecmult_gen(&both->ecmult_gen_ctx, &pubj, &key); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&pub, &pubj); - - /* Verify context-type checking illegal-argument errors. */ - memset(ctmp, 1, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(sttc, &pubkey, ctmp) == 0); - CHECK(ecount == 1); - VG_UNDEF(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(sign, &pubkey, ctmp) == 1); - VG_CHECK(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(sttc, &sig, ctmp, ctmp, NULL, NULL) == 0); - CHECK(ecount == 2); - VG_UNDEF(&sig, sizeof(sig)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(sign, &sig, ctmp, ctmp, NULL, NULL) == 1); - VG_CHECK(&sig, sizeof(sig)); - CHECK(ecount2 == 10); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(sign, &sig, ctmp, &pubkey) == 1); - CHECK(ecount2 == 10); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(sttc, &sig, ctmp, &pubkey) == 1); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add(sign, &pubkey, ctmp) == 1); - CHECK(ecount2 == 10); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add(sttc, &pubkey, ctmp) == 1); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_mul(sign, &pubkey, ctmp) == 1); - CHECK(ecount2 == 10); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_negate(sttc, &pubkey) == 1); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_negate(sign, &pubkey) == 1); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_negate(sign, NULL) == 0); - CHECK(ecount2 == 11); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_negate(sttc, &zero_pubkey) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_mul(sttc, &pubkey, ctmp) == 1); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_context_randomize(sttc, ctmp) == 1); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_context_randomize(sttc, NULL) == 1); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_context_randomize(sign, ctmp) == 1); - CHECK(ecount2 == 11); - CHECK(rustsecp256k1zkp_v0_8_0_context_randomize(sign, NULL) == 1); - CHECK(ecount2 == 11); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sttc, NULL, NULL); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(sign, NULL, NULL); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&my_ctx->ecmult_gen_ctx, &pubj, &key); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&pub, &pubj); /* obtain a working nonce */ do { random_scalar_order_test(&nonce); - } while(!rustsecp256k1zkp_v0_8_0_ecdsa_sig_sign(&both->ecmult_gen_ctx, &sigr, &sigs, &key, &msg, &nonce, NULL)); + } while(!rustsecp256k1zkp_v0_10_0_ecdsa_sig_sign(&my_ctx->ecmult_gen_ctx, &sigr, &sigs, &key, &msg, &nonce, NULL)); /* try signing */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_sign(&sign->ecmult_gen_ctx, &sigr, &sigs, &key, &msg, &nonce, NULL)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_sign(&both->ecmult_gen_ctx, &sigr, &sigs, &key, &msg, &nonce, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_sign(&my_ctx->ecmult_gen_ctx, &sigr, &sigs, &key, &msg, &nonce, NULL)); /* try verifying */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sigr, &sigs, &pub, &msg)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sigr, &sigs, &pub, &msg)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&sigr, &sigs, &pub, &msg)); /* cleanup */ if (use_prealloc) { - rustsecp256k1zkp_v0_8_0_context_preallocated_destroy(none); - rustsecp256k1zkp_v0_8_0_context_preallocated_destroy(sign); - rustsecp256k1zkp_v0_8_0_context_preallocated_destroy(vrfy); - rustsecp256k1zkp_v0_8_0_context_preallocated_destroy(both); - rustsecp256k1zkp_v0_8_0_context_preallocated_destroy(sttc); - free(none_prealloc); - free(sign_prealloc); - free(vrfy_prealloc); - free(both_prealloc); - free(sttc_prealloc); + rustsecp256k1zkp_v0_10_0_context_preallocated_destroy(my_ctx); + free(my_ctx_prealloc); } else { - rustsecp256k1zkp_v0_8_0_context_destroy(none); - rustsecp256k1zkp_v0_8_0_context_destroy(sign); - rustsecp256k1zkp_v0_8_0_context_destroy(vrfy); - rustsecp256k1zkp_v0_8_0_context_destroy(both); - rustsecp256k1zkp_v0_8_0_context_destroy(sttc); + rustsecp256k1zkp_v0_10_0_context_destroy(my_ctx); } - /* Defined as no-op. */ - rustsecp256k1zkp_v0_8_0_context_destroy(NULL); - rustsecp256k1zkp_v0_8_0_context_preallocated_destroy(NULL); + rustsecp256k1zkp_v0_10_0_context_destroy(my_ctx_fresh); + /* Defined as no-op. */ + rustsecp256k1zkp_v0_10_0_context_destroy(NULL); + rustsecp256k1zkp_v0_10_0_context_preallocated_destroy(NULL); } -void run_scratch_tests(void) { +static void run_scratch_tests(void) { const size_t adj_alloc = ((500 + ALIGNMENT - 1) / ALIGNMENT) * ALIGNMENT; - int32_t ecount = 0; size_t checkpoint; size_t checkpoint_2; - rustsecp256k1zkp_v0_8_0_context *none = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_NONE); - rustsecp256k1zkp_v0_8_0_scratch_space *scratch; - rustsecp256k1zkp_v0_8_0_scratch_space local_scratch; + rustsecp256k1zkp_v0_10_0_scratch_space *scratch; + rustsecp256k1zkp_v0_10_0_scratch_space local_scratch; /* Test public API */ - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(none, counting_illegal_callback_fn, &ecount); - rustsecp256k1zkp_v0_8_0_context_set_error_callback(none, counting_illegal_callback_fn, &ecount); - - scratch = rustsecp256k1zkp_v0_8_0_scratch_space_create(none, 1000); + scratch = rustsecp256k1zkp_v0_10_0_scratch_space_create(CTX, 1000); CHECK(scratch != NULL); - CHECK(ecount == 0); /* Test internal API */ - CHECK(rustsecp256k1zkp_v0_8_0_scratch_max_allocation(&none->error_callback, scratch, 0) == 1000); - CHECK(rustsecp256k1zkp_v0_8_0_scratch_max_allocation(&none->error_callback, scratch, 1) == 1000 - (ALIGNMENT - 1)); + CHECK(rustsecp256k1zkp_v0_10_0_scratch_max_allocation(&CTX->error_callback, scratch, 0) == 1000); + CHECK(rustsecp256k1zkp_v0_10_0_scratch_max_allocation(&CTX->error_callback, scratch, 1) == 1000 - (ALIGNMENT - 1)); CHECK(scratch->alloc_size == 0); CHECK(scratch->alloc_size % ALIGNMENT == 0); /* Allocating 500 bytes succeeds */ - checkpoint = rustsecp256k1zkp_v0_8_0_scratch_checkpoint(&none->error_callback, scratch); - CHECK(rustsecp256k1zkp_v0_8_0_scratch_alloc(&none->error_callback, scratch, 500) != NULL); - CHECK(rustsecp256k1zkp_v0_8_0_scratch_max_allocation(&none->error_callback, scratch, 0) == 1000 - adj_alloc); - CHECK(rustsecp256k1zkp_v0_8_0_scratch_max_allocation(&none->error_callback, scratch, 1) == 1000 - adj_alloc - (ALIGNMENT - 1)); + checkpoint = rustsecp256k1zkp_v0_10_0_scratch_checkpoint(&CTX->error_callback, scratch); + CHECK(rustsecp256k1zkp_v0_10_0_scratch_alloc(&CTX->error_callback, scratch, 500) != NULL); + CHECK(rustsecp256k1zkp_v0_10_0_scratch_max_allocation(&CTX->error_callback, scratch, 0) == 1000 - adj_alloc); + CHECK(rustsecp256k1zkp_v0_10_0_scratch_max_allocation(&CTX->error_callback, scratch, 1) == 1000 - adj_alloc - (ALIGNMENT - 1)); CHECK(scratch->alloc_size != 0); CHECK(scratch->alloc_size % ALIGNMENT == 0); /* Allocating another 501 bytes fails */ - CHECK(rustsecp256k1zkp_v0_8_0_scratch_alloc(&none->error_callback, scratch, 501) == NULL); - CHECK(rustsecp256k1zkp_v0_8_0_scratch_max_allocation(&none->error_callback, scratch, 0) == 1000 - adj_alloc); - CHECK(rustsecp256k1zkp_v0_8_0_scratch_max_allocation(&none->error_callback, scratch, 1) == 1000 - adj_alloc - (ALIGNMENT - 1)); + CHECK(rustsecp256k1zkp_v0_10_0_scratch_alloc(&CTX->error_callback, scratch, 501) == NULL); + CHECK(rustsecp256k1zkp_v0_10_0_scratch_max_allocation(&CTX->error_callback, scratch, 0) == 1000 - adj_alloc); + CHECK(rustsecp256k1zkp_v0_10_0_scratch_max_allocation(&CTX->error_callback, scratch, 1) == 1000 - adj_alloc - (ALIGNMENT - 1)); CHECK(scratch->alloc_size != 0); CHECK(scratch->alloc_size % ALIGNMENT == 0); /* ...but it succeeds once we apply the checkpoint to undo it */ - rustsecp256k1zkp_v0_8_0_scratch_apply_checkpoint(&none->error_callback, scratch, checkpoint); + rustsecp256k1zkp_v0_10_0_scratch_apply_checkpoint(&CTX->error_callback, scratch, checkpoint); CHECK(scratch->alloc_size == 0); - CHECK(rustsecp256k1zkp_v0_8_0_scratch_max_allocation(&none->error_callback, scratch, 0) == 1000); - CHECK(rustsecp256k1zkp_v0_8_0_scratch_alloc(&none->error_callback, scratch, 500) != NULL); + CHECK(rustsecp256k1zkp_v0_10_0_scratch_max_allocation(&CTX->error_callback, scratch, 0) == 1000); + CHECK(rustsecp256k1zkp_v0_10_0_scratch_alloc(&CTX->error_callback, scratch, 500) != NULL); CHECK(scratch->alloc_size != 0); /* try to apply a bad checkpoint */ - checkpoint_2 = rustsecp256k1zkp_v0_8_0_scratch_checkpoint(&none->error_callback, scratch); - rustsecp256k1zkp_v0_8_0_scratch_apply_checkpoint(&none->error_callback, scratch, checkpoint); - CHECK(ecount == 0); - rustsecp256k1zkp_v0_8_0_scratch_apply_checkpoint(&none->error_callback, scratch, checkpoint_2); /* checkpoint_2 is after checkpoint */ - CHECK(ecount == 1); - rustsecp256k1zkp_v0_8_0_scratch_apply_checkpoint(&none->error_callback, scratch, (size_t) -1); /* this is just wildly invalid */ - CHECK(ecount == 2); + checkpoint_2 = rustsecp256k1zkp_v0_10_0_scratch_checkpoint(&CTX->error_callback, scratch); + rustsecp256k1zkp_v0_10_0_scratch_apply_checkpoint(&CTX->error_callback, scratch, checkpoint); + CHECK_ERROR_VOID(CTX, rustsecp256k1zkp_v0_10_0_scratch_apply_checkpoint(&CTX->error_callback, scratch, checkpoint_2)); /* checkpoint_2 is after checkpoint */ + CHECK_ERROR_VOID(CTX, rustsecp256k1zkp_v0_10_0_scratch_apply_checkpoint(&CTX->error_callback, scratch, (size_t) -1)); /* this is just wildly invalid */ /* try to use badly initialized scratch space */ - rustsecp256k1zkp_v0_8_0_scratch_space_destroy(none, scratch); + rustsecp256k1zkp_v0_10_0_scratch_space_destroy(CTX, scratch); memset(&local_scratch, 0, sizeof(local_scratch)); scratch = &local_scratch; - CHECK(!rustsecp256k1zkp_v0_8_0_scratch_max_allocation(&none->error_callback, scratch, 0)); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_scratch_alloc(&none->error_callback, scratch, 500) == NULL); - CHECK(ecount == 4); - rustsecp256k1zkp_v0_8_0_scratch_space_destroy(none, scratch); - CHECK(ecount == 5); + CHECK_ERROR(CTX, rustsecp256k1zkp_v0_10_0_scratch_max_allocation(&CTX->error_callback, scratch, 0)); + CHECK_ERROR(CTX, rustsecp256k1zkp_v0_10_0_scratch_alloc(&CTX->error_callback, scratch, 500)); + CHECK_ERROR_VOID(CTX, rustsecp256k1zkp_v0_10_0_scratch_space_destroy(CTX, scratch)); /* Test that large integers do not wrap around in a bad way */ - scratch = rustsecp256k1zkp_v0_8_0_scratch_space_create(none, 1000); + scratch = rustsecp256k1zkp_v0_10_0_scratch_space_create(CTX, 1000); /* Try max allocation with a large number of objects. Only makes sense if * ALIGNMENT is greater than 1 because otherwise the objects take no extra * space. */ - CHECK(ALIGNMENT <= 1 || !rustsecp256k1zkp_v0_8_0_scratch_max_allocation(&none->error_callback, scratch, (SIZE_MAX / (ALIGNMENT - 1)) + 1)); + CHECK(ALIGNMENT <= 1 || !rustsecp256k1zkp_v0_10_0_scratch_max_allocation(&CTX->error_callback, scratch, (SIZE_MAX / (ALIGNMENT - 1)) + 1)); /* Try allocating SIZE_MAX to test wrap around which only happens if * ALIGNMENT > 1, otherwise it returns NULL anyway because the scratch * space is too small. */ - CHECK(rustsecp256k1zkp_v0_8_0_scratch_alloc(&none->error_callback, scratch, SIZE_MAX) == NULL); - rustsecp256k1zkp_v0_8_0_scratch_space_destroy(none, scratch); + CHECK(rustsecp256k1zkp_v0_10_0_scratch_alloc(&CTX->error_callback, scratch, SIZE_MAX) == NULL); + rustsecp256k1zkp_v0_10_0_scratch_space_destroy(CTX, scratch); /* cleanup */ - rustsecp256k1zkp_v0_8_0_scratch_space_destroy(none, NULL); /* no-op */ - rustsecp256k1zkp_v0_8_0_context_destroy(none); + rustsecp256k1zkp_v0_10_0_scratch_space_destroy(CTX, NULL); /* no-op */ } -void run_ctz_tests(void) { +static void run_ctz_tests(void) { static const uint32_t b32[] = {1, 0xffffffff, 0x5e56968f, 0xe0d63129}; static const uint64_t b64[] = {1, 0xffffffffffffffff, 0xbcd02462139b3fc3, 0x98b5f80c769693ef}; int shift; unsigned i; for (i = 0; i < sizeof(b32) / sizeof(b32[0]); ++i) { for (shift = 0; shift < 32; ++shift) { - CHECK(rustsecp256k1zkp_v0_8_0_ctz32_var_debruijn(b32[i] << shift) == shift); - CHECK(rustsecp256k1zkp_v0_8_0_ctz32_var(b32[i] << shift) == shift); + CHECK(rustsecp256k1zkp_v0_10_0_ctz32_var_debruijn(b32[i] << shift) == shift); + CHECK(rustsecp256k1zkp_v0_10_0_ctz32_var(b32[i] << shift) == shift); } } for (i = 0; i < sizeof(b64) / sizeof(b64[0]); ++i) { for (shift = 0; shift < 64; ++shift) { - CHECK(rustsecp256k1zkp_v0_8_0_ctz64_var_debruijn(b64[i] << shift) == shift); - CHECK(rustsecp256k1zkp_v0_8_0_ctz64_var(b64[i] << shift) == shift); + CHECK(rustsecp256k1zkp_v0_10_0_ctz64_var_debruijn(b64[i] << shift) == shift); + CHECK(rustsecp256k1zkp_v0_10_0_ctz64_var(b64[i] << shift) == shift); } } } /***** HASH TESTS *****/ -void run_sha256_known_output_tests(void) { +static void run_sha256_known_output_tests(void) { static const char *inputs[] = { "", "abc", "message digest", "secure hash algorithm", "SHA256 is considered to be safe", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", @@ -527,29 +640,29 @@ void run_sha256_known_output_tests(void) { for (i = 0; i < ninputs; i++) { unsigned char out[32]; - rustsecp256k1zkp_v0_8_0_sha256 hasher; + rustsecp256k1zkp_v0_10_0_sha256 hasher; unsigned int j; /* 1. Run: simply write the input bytestrings */ j = repeat[i]; - rustsecp256k1zkp_v0_8_0_sha256_initialize(&hasher); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&hasher); while (j > 0) { - rustsecp256k1zkp_v0_8_0_sha256_write(&hasher, (const unsigned char*)(inputs[i]), strlen(inputs[i])); + rustsecp256k1zkp_v0_10_0_sha256_write(&hasher, (const unsigned char*)(inputs[i]), strlen(inputs[i])); j--; } - rustsecp256k1zkp_v0_8_0_sha256_finalize(&hasher, out); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(out, outputs[i], 32) == 0); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&hasher, out); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(out, outputs[i], 32) == 0); /* 2. Run: split the input bytestrings randomly before writing */ if (strlen(inputs[i]) > 0) { - int split = rustsecp256k1zkp_v0_8_0_testrand_int(strlen(inputs[i])); - rustsecp256k1zkp_v0_8_0_sha256_initialize(&hasher); + int split = rustsecp256k1zkp_v0_10_0_testrand_int(strlen(inputs[i])); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&hasher); j = repeat[i]; while (j > 0) { - rustsecp256k1zkp_v0_8_0_sha256_write(&hasher, (const unsigned char*)(inputs[i]), split); - rustsecp256k1zkp_v0_8_0_sha256_write(&hasher, (const unsigned char*)(inputs[i] + split), strlen(inputs[i]) - split); + rustsecp256k1zkp_v0_10_0_sha256_write(&hasher, (const unsigned char*)(inputs[i]), split); + rustsecp256k1zkp_v0_10_0_sha256_write(&hasher, (const unsigned char*)(inputs[i] + split), strlen(inputs[i]) - split); j--; } - rustsecp256k1zkp_v0_8_0_sha256_finalize(&hasher, out); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(out, outputs[i], 32) == 0); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&hasher, out); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(out, outputs[i], 32) == 0); } } } @@ -598,9 +711,9 @@ for x in digests: print(x + ',') ``` */ -void run_sha256_counter_tests(void) { +static void run_sha256_counter_tests(void) { static const char *input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno"; - static const rustsecp256k1zkp_v0_8_0_sha256 midstates[] = { + static const rustsecp256k1zkp_v0_10_0_sha256 midstates[] = { {{0xa2b5c8bb, 0x26c88bb3, 0x2abdc3d2, 0x9def99a3, 0xdfd21a6e, 0x41fe585b, 0x7ef2c440, 0x2b79adda}, {0x00}, 0xfffc0}, {{0xa0d29445, 0x9287de66, 0x76aabd71, 0x41acd765, 0x0c7528b4, 0x84e14906, 0x942faec6, 0xcc5a7b26}, @@ -649,14 +762,25 @@ void run_sha256_counter_tests(void) { unsigned int i; for (i = 0; i < sizeof(midstates)/sizeof(midstates[0]); i++) { unsigned char out[32]; - rustsecp256k1zkp_v0_8_0_sha256 hasher = midstates[i]; - rustsecp256k1zkp_v0_8_0_sha256_write(&hasher, (const unsigned char*)input, strlen(input)); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&hasher, out); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(out, outputs[i], 32) == 0); + rustsecp256k1zkp_v0_10_0_sha256 hasher = midstates[i]; + rustsecp256k1zkp_v0_10_0_sha256_write(&hasher, (const unsigned char*)input, strlen(input)); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&hasher, out); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(out, outputs[i], 32) == 0); } } -void run_hmac_sha256_tests(void) { +/* Tests for the equality of two sha256 structs. This function only produces a + * correct result if an integer multiple of 64 many bytes have been written + * into the hash functions. This function is used by some module tests. */ +static void test_sha256_eq(const rustsecp256k1zkp_v0_10_0_sha256 *sha1, const rustsecp256k1zkp_v0_10_0_sha256 *sha2) { + /* Is buffer fully consumed? */ + CHECK((sha1->bytes & 0x3F) == 0); + + CHECK(sha1->bytes == sha2->bytes); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(sha1->s, sha2->s, sizeof(sha1->s)) == 0); +} + +static void run_hmac_sha256_tests(void) { static const char *keys[6] = { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", "\x4a\x65\x66\x65", @@ -683,24 +807,24 @@ void run_hmac_sha256_tests(void) { }; int i; for (i = 0; i < 6; i++) { - rustsecp256k1zkp_v0_8_0_hmac_sha256 hasher; + rustsecp256k1zkp_v0_10_0_hmac_sha256 hasher; unsigned char out[32]; - rustsecp256k1zkp_v0_8_0_hmac_sha256_initialize(&hasher, (const unsigned char*)(keys[i]), strlen(keys[i])); - rustsecp256k1zkp_v0_8_0_hmac_sha256_write(&hasher, (const unsigned char*)(inputs[i]), strlen(inputs[i])); - rustsecp256k1zkp_v0_8_0_hmac_sha256_finalize(&hasher, out); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(out, outputs[i], 32) == 0); + rustsecp256k1zkp_v0_10_0_hmac_sha256_initialize(&hasher, (const unsigned char*)(keys[i]), strlen(keys[i])); + rustsecp256k1zkp_v0_10_0_hmac_sha256_write(&hasher, (const unsigned char*)(inputs[i]), strlen(inputs[i])); + rustsecp256k1zkp_v0_10_0_hmac_sha256_finalize(&hasher, out); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(out, outputs[i], 32) == 0); if (strlen(inputs[i]) > 0) { - int split = rustsecp256k1zkp_v0_8_0_testrand_int(strlen(inputs[i])); - rustsecp256k1zkp_v0_8_0_hmac_sha256_initialize(&hasher, (const unsigned char*)(keys[i]), strlen(keys[i])); - rustsecp256k1zkp_v0_8_0_hmac_sha256_write(&hasher, (const unsigned char*)(inputs[i]), split); - rustsecp256k1zkp_v0_8_0_hmac_sha256_write(&hasher, (const unsigned char*)(inputs[i] + split), strlen(inputs[i]) - split); - rustsecp256k1zkp_v0_8_0_hmac_sha256_finalize(&hasher, out); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(out, outputs[i], 32) == 0); + int split = rustsecp256k1zkp_v0_10_0_testrand_int(strlen(inputs[i])); + rustsecp256k1zkp_v0_10_0_hmac_sha256_initialize(&hasher, (const unsigned char*)(keys[i]), strlen(keys[i])); + rustsecp256k1zkp_v0_10_0_hmac_sha256_write(&hasher, (const unsigned char*)(inputs[i]), split); + rustsecp256k1zkp_v0_10_0_hmac_sha256_write(&hasher, (const unsigned char*)(inputs[i] + split), strlen(inputs[i]) - split); + rustsecp256k1zkp_v0_10_0_hmac_sha256_finalize(&hasher, out); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(out, outputs[i], 32) == 0); } } } -void run_rfc6979_hmac_sha256_tests(void) { +static void run_rfc6979_hmac_sha256_tests(void) { static const unsigned char key1[65] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x00, 0x4b, 0xf5, 0x12, 0x2f, 0x34, 0x45, 0x54, 0xc5, 0x3b, 0xde, 0x2e, 0xbb, 0x8c, 0xd2, 0xb7, 0xe3, 0xd1, 0x60, 0x0a, 0xd6, 0x31, 0xc3, 0x85, 0xa5, 0xd7, 0xcc, 0xe2, 0x3c, 0x77, 0x85, 0x45, 0x9a, 0}; static const unsigned char out1[3][32] = { {0x4f, 0xe2, 0x95, 0x25, 0xb2, 0x08, 0x68, 0x09, 0x15, 0x9a, 0xcd, 0xf0, 0x50, 0x6e, 0xfb, 0x86, 0xb0, 0xec, 0x93, 0x2c, 0x7b, 0xa4, 0x42, 0x56, 0xab, 0x32, 0x1e, 0x42, 0x1e, 0x67, 0xe9, 0xfb}, @@ -715,35 +839,33 @@ void run_rfc6979_hmac_sha256_tests(void) { {0x75, 0x97, 0x88, 0x7c, 0xbd, 0x76, 0x32, 0x1f, 0x32, 0xe3, 0x04, 0x40, 0x67, 0x9a, 0x22, 0xcf, 0x7f, 0x8d, 0x9d, 0x2e, 0xac, 0x39, 0x0e, 0x58, 0x1f, 0xea, 0x09, 0x1c, 0xe2, 0x02, 0xba, 0x94} }; - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256 rng; + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256 rng; unsigned char out[32]; int i; - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_initialize(&rng, key1, 64); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_initialize(&rng, key1, 64); for (i = 0; i < 3; i++) { - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_generate(&rng, out, 32); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(out, out1[i], 32) == 0); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_generate(&rng, out, 32); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(out, out1[i], 32) == 0); } - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_finalize(&rng); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_finalize(&rng); - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_initialize(&rng, key1, 65); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_initialize(&rng, key1, 65); for (i = 0; i < 3; i++) { - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_generate(&rng, out, 32); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(out, out1[i], 32) != 0); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_generate(&rng, out, 32); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(out, out1[i], 32) != 0); } - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_finalize(&rng); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_finalize(&rng); - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_initialize(&rng, key2, 64); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_initialize(&rng, key2, 64); for (i = 0; i < 3; i++) { - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_generate(&rng, out, 32); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(out, out2[i], 32) == 0); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_generate(&rng, out, 32); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(out, out2[i], 32) == 0); } - rustsecp256k1zkp_v0_8_0_rfc6979_hmac_sha256_finalize(&rng); + rustsecp256k1zkp_v0_10_0_rfc6979_hmac_sha256_finalize(&rng); } -void run_tagged_sha256_tests(void) { - int ecount = 0; - rustsecp256k1zkp_v0_8_0_context *none = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_NONE); +static void run_tagged_sha256_tests(void) { unsigned char tag[32] = { 0 }; unsigned char msg[32] = { 0 }; unsigned char hash32[32]; @@ -754,101 +876,23 @@ void run_tagged_sha256_tests(void) { 0xE2, 0x76, 0x55, 0x9A, 0x3B, 0xDE, 0x55, 0xB3 }; - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(none, counting_illegal_callback_fn, &ecount); - /* API test */ - CHECK(rustsecp256k1zkp_v0_8_0_tagged_sha256(none, hash32, tag, sizeof(tag), msg, sizeof(msg)) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_tagged_sha256(none, NULL, tag, sizeof(tag), msg, sizeof(msg)) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_tagged_sha256(none, hash32, NULL, 0, msg, sizeof(msg)) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_tagged_sha256(none, hash32, tag, sizeof(tag), NULL, 0) == 0); - CHECK(ecount == 3); + CHECK(rustsecp256k1zkp_v0_10_0_tagged_sha256(CTX, hash32, tag, sizeof(tag), msg, sizeof(msg)) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_tagged_sha256(CTX, NULL, tag, sizeof(tag), msg, sizeof(msg))); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_tagged_sha256(CTX, hash32, NULL, 0, msg, sizeof(msg))); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_tagged_sha256(CTX, hash32, tag, sizeof(tag), NULL, 0)); /* Static test vector */ memcpy(tag, "tag", 3); memcpy(msg, "msg", 3); - CHECK(rustsecp256k1zkp_v0_8_0_tagged_sha256(none, hash32, tag, 3, msg, 3) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(hash32, hash_expected, sizeof(hash32)) == 0); - rustsecp256k1zkp_v0_8_0_context_destroy(none); -} - -/***** RANDOM TESTS *****/ - -void test_rand_bits(int rand32, int bits) { - /* (1-1/2^B)^rounds[B] < 1/10^9, so rounds is the number of iterations to - * get a false negative chance below once in a billion */ - static const unsigned int rounds[7] = {1, 30, 73, 156, 322, 653, 1316}; - /* We try multiplying the results with various odd numbers, which shouldn't - * influence the uniform distribution modulo a power of 2. */ - static const uint32_t mults[6] = {1, 3, 21, 289, 0x9999, 0x80402011}; - /* We only select up to 6 bits from the output to analyse */ - unsigned int usebits = bits > 6 ? 6 : bits; - unsigned int maxshift = bits - usebits; - /* For each of the maxshift+1 usebits-bit sequences inside a bits-bit - number, track all observed outcomes, one per bit in a uint64_t. */ - uint64_t x[6][27] = {{0}}; - unsigned int i, shift, m; - /* Multiply the output of all rand calls with the odd number m, which - should not change the uniformity of its distribution. */ - for (i = 0; i < rounds[usebits]; i++) { - uint32_t r = (rand32 ? rustsecp256k1zkp_v0_8_0_testrand32() : rustsecp256k1zkp_v0_8_0_testrand_bits(bits)); - CHECK((((uint64_t)r) >> bits) == 0); - for (m = 0; m < sizeof(mults) / sizeof(mults[0]); m++) { - uint32_t rm = r * mults[m]; - for (shift = 0; shift <= maxshift; shift++) { - x[m][shift] |= (((uint64_t)1) << ((rm >> shift) & ((1 << usebits) - 1))); - } - } - } - for (m = 0; m < sizeof(mults) / sizeof(mults[0]); m++) { - for (shift = 0; shift <= maxshift; shift++) { - /* Test that the lower usebits bits of x[shift] are 1 */ - CHECK(((~x[m][shift]) << (64 - (1 << usebits))) == 0); - } - } -} - -/* Subrange must be a whole divisor of range, and at most 64 */ -void test_rand_int(uint32_t range, uint32_t subrange) { - /* (1-1/subrange)^rounds < 1/10^9 */ - int rounds = (subrange * 2073) / 100; - int i; - uint64_t x = 0; - CHECK((range % subrange) == 0); - for (i = 0; i < rounds; i++) { - uint32_t r = rustsecp256k1zkp_v0_8_0_testrand_int(range); - CHECK(r < range); - r = r % subrange; - x |= (((uint64_t)1) << r); - } - /* Test that the lower subrange bits of x are 1. */ - CHECK(((~x) << (64 - subrange)) == 0); -} - -void run_rand_bits(void) { - size_t b; - test_rand_bits(1, 32); - for (b = 1; b <= 32; b++) { - test_rand_bits(0, b); - } -} - -void run_rand_int(void) { - static const uint32_t ms[] = {1, 3, 17, 1000, 13771, 999999, 33554432}; - static const uint32_t ss[] = {1, 3, 6, 9, 13, 31, 64}; - unsigned int m, s; - for (m = 0; m < sizeof(ms) / sizeof(ms[0]); m++) { - for (s = 0; s < sizeof(ss) / sizeof(ss[0]); s++) { - test_rand_int(ms[m] * ss[s], ss[s]); - } - } + CHECK(rustsecp256k1zkp_v0_10_0_tagged_sha256(CTX, hash32, tag, 3, msg, 3) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(hash32, hash_expected, sizeof(hash32)) == 0); } /***** MODINV TESTS *****/ /* Compute the modular inverse of (odd) x mod 2^64. */ -uint64_t modinv2p64(uint64_t x) { +static uint64_t modinv2p64(uint64_t x) { /* If w = 1/x mod 2^(2^L), then w*(2 - w*x) = 1/x mod 2^(2^(L+1)). See * Hacker's Delight second edition, Henry S. Warren, Jr., pages 245-247 for * why. Start with L=0, for which it is true for every odd x that @@ -860,11 +904,12 @@ uint64_t modinv2p64(uint64_t x) { return w; } -/* compute out = (a*b) mod m; if b=NULL, treat b=1. + +/* compute out = (a*b) mod m; if b=NULL, treat b=1; if m=NULL, treat m=infinity. * * Out is a 512-bit number (represented as 32 uint16_t's in LE order). The other * arguments are 256-bit numbers (represented as 16 uint16_t's in LE order). */ -void mulmod256(uint16_t* out, const uint16_t* a, const uint16_t* b, const uint16_t* m) { +static void mulmod256(uint16_t* out, const uint16_t* a, const uint16_t* b, const uint16_t* m) { uint16_t mul[32]; uint64_t c = 0; int i, j; @@ -902,51 +947,53 @@ void mulmod256(uint16_t* out, const uint16_t* a, const uint16_t* b, const uint16 } } - /* Compute the highest set bit in m. */ - for (i = 255; i >= 0; --i) { - if ((m[i >> 4] >> (i & 15)) & 1) { - m_bitlen = i; - break; + if (m) { + /* Compute the highest set bit in m. */ + for (i = 255; i >= 0; --i) { + if ((m[i >> 4] >> (i & 15)) & 1) { + m_bitlen = i; + break; + } } - } - /* Try do mul -= m<= 0; --i) { - uint16_t mul2[32]; - int64_t cs; - - /* Compute mul2 = mul - m<= 0 && bitpos < 256) { - sub |= ((m[bitpos >> 4] >> (bitpos & 15)) & 1) << p; + /* Try do mul -= m<= 0; --i) { + uint16_t mul2[32]; + int64_t cs; + + /* Compute mul2 = mul - m<= 0 && bitpos < 256) { + sub |= ((m[bitpos >> 4] >> (bitpos & 15)) & 1) << p; + } } + /* Add mul[j]-sub to accumulator, and shift bottom 16 bits out to mul2[j]. */ + cs += mul[j]; + cs -= sub; + mul2[j] = (cs & 0xFFFF); + cs >>= 16; + } + /* If remainder of subtraction is 0, set mul = mul2. */ + if (cs == 0) { + memcpy(mul, mul2, sizeof(mul)); } - /* Add mul[j]-sub to accumulator, and shift bottom 16 bits out to mul2[j]. */ - cs += mul[j]; - cs -= sub; - mul2[j] = (cs & 0xFFFF); - cs >>= 16; } - /* If remainder of subtraction is 0, set mul = mul2. */ - if (cs == 0) { - memcpy(mul, mul2, sizeof(mul)); + /* Sanity check: test that all limbs higher than m's highest are zero */ + for (i = (m_bitlen >> 4) + 1; i < 32; ++i) { + CHECK(mul[i] == 0); } } - /* Sanity check: test that all limbs higher than m's highest are zero */ - for (i = (m_bitlen >> 4) + 1; i < 32; ++i) { - CHECK(mul[i] == 0); - } memcpy(out, mul, 32); } /* Convert a 256-bit number represented as 16 uint16_t's to signed30 notation. */ -void uint16_to_signed30(rustsecp256k1zkp_v0_8_0_modinv32_signed30* out, const uint16_t* in) { +static void uint16_to_signed30(rustsecp256k1zkp_v0_10_0_modinv32_signed30* out, const uint16_t* in) { int i; memset(out->v, 0, sizeof(out->v)); for (i = 0; i < 256; ++i) { @@ -955,7 +1002,7 @@ void uint16_to_signed30(rustsecp256k1zkp_v0_8_0_modinv32_signed30* out, const ui } /* Convert a 256-bit number in signed30 notation to a representation as 16 uint16_t's. */ -void signed30_to_uint16(uint16_t* out, const rustsecp256k1zkp_v0_8_0_modinv32_signed30* in) { +static void signed30_to_uint16(uint16_t* out, const rustsecp256k1zkp_v0_10_0_modinv32_signed30* in) { int i; memset(out, 0, 32); for (i = 0; i < 256; ++i) { @@ -964,10 +1011,10 @@ void signed30_to_uint16(uint16_t* out, const rustsecp256k1zkp_v0_8_0_modinv32_si } /* Randomly mutate the sign of limbs in signed30 representation, without changing the value. */ -void mutate_sign_signed30(rustsecp256k1zkp_v0_8_0_modinv32_signed30* x) { +static void mutate_sign_signed30(rustsecp256k1zkp_v0_10_0_modinv32_signed30* x) { int i; for (i = 0; i < 16; ++i) { - int pos = rustsecp256k1zkp_v0_8_0_testrand_bits(3); + int pos = rustsecp256k1zkp_v0_10_0_testrand_bits(3); if (x->v[pos] > 0 && x->v[pos + 1] <= 0x3fffffff) { x->v[pos] -= 0x40000000; x->v[pos + 1] += 1; @@ -978,25 +1025,45 @@ void mutate_sign_signed30(rustsecp256k1zkp_v0_8_0_modinv32_signed30* x) { } } -/* Test rustsecp256k1zkp_v0_8_0_modinv32{_var}, using inputs in 16-bit limb format, and returning inverse. */ -void test_modinv32_uint16(uint16_t* out, const uint16_t* in, const uint16_t* mod) { +/* Test rustsecp256k1zkp_v0_10_0_modinv32{_var}, using inputs in 16-bit limb format, and returning inverse. */ +static void test_modinv32_uint16(uint16_t* out, const uint16_t* in, const uint16_t* mod) { uint16_t tmp[16]; - rustsecp256k1zkp_v0_8_0_modinv32_signed30 x; - rustsecp256k1zkp_v0_8_0_modinv32_modinfo m; + rustsecp256k1zkp_v0_10_0_modinv32_signed30 x; + rustsecp256k1zkp_v0_10_0_modinv32_modinfo m; int i, vartime, nonzero; uint16_to_signed30(&x, in); nonzero = (x.v[0] | x.v[1] | x.v[2] | x.v[3] | x.v[4] | x.v[5] | x.v[6] | x.v[7] | x.v[8]) != 0; uint16_to_signed30(&m.modulus, mod); - mutate_sign_signed30(&m.modulus); /* compute 1/modulus mod 2^30 */ m.modulus_inv30 = modinv2p64(m.modulus.v[0]) & 0x3fffffff; CHECK(((m.modulus_inv30 * m.modulus.v[0]) & 0x3fffffff) == 1); + /* Test rustsecp256k1zkp_v0_10_0_jacobi32_maybe_var. */ + if (nonzero) { + int jac; + uint16_t sqr[16], negone[16]; + mulmod256(sqr, in, in, mod); + uint16_to_signed30(&x, sqr); + /* Compute jacobi symbol of in^2, which must be 1 (or uncomputable). */ + jac = rustsecp256k1zkp_v0_10_0_jacobi32_maybe_var(&x, &m); + CHECK(jac == 0 || jac == 1); + /* Then compute the jacobi symbol of -(in^2). x and -x have opposite + * jacobi symbols if and only if (mod % 4) == 3. */ + negone[0] = mod[0] - 1; + for (i = 1; i < 16; ++i) negone[i] = mod[i]; + mulmod256(sqr, sqr, negone, mod); + uint16_to_signed30(&x, sqr); + jac = rustsecp256k1zkp_v0_10_0_jacobi32_maybe_var(&x, &m); + CHECK(jac == 0 || jac == 1 - (mod[0] & 2)); + } + + uint16_to_signed30(&x, in); + mutate_sign_signed30(&m.modulus); for (vartime = 0; vartime < 2; ++vartime) { /* compute inverse */ - (vartime ? rustsecp256k1zkp_v0_8_0_modinv32_var : rustsecp256k1zkp_v0_8_0_modinv32)(&x, &m); + (vartime ? rustsecp256k1zkp_v0_10_0_modinv32_var : rustsecp256k1zkp_v0_10_0_modinv32)(&x, &m); /* produce output */ signed30_to_uint16(out, &x); @@ -1007,7 +1074,7 @@ void test_modinv32_uint16(uint16_t* out, const uint16_t* in, const uint16_t* mod for (i = 1; i < 16; ++i) CHECK(tmp[i] == 0); /* invert again */ - (vartime ? rustsecp256k1zkp_v0_8_0_modinv32_var : rustsecp256k1zkp_v0_8_0_modinv32)(&x, &m); + (vartime ? rustsecp256k1zkp_v0_10_0_modinv32_var : rustsecp256k1zkp_v0_10_0_modinv32)(&x, &m); /* check if the result is equal to the input */ signed30_to_uint16(tmp, &x); @@ -1017,7 +1084,7 @@ void test_modinv32_uint16(uint16_t* out, const uint16_t* in, const uint16_t* mod #ifdef SECP256K1_WIDEMUL_INT128 /* Convert a 256-bit number represented as 16 uint16_t's to signed62 notation. */ -void uint16_to_signed62(rustsecp256k1zkp_v0_8_0_modinv64_signed62* out, const uint16_t* in) { +static void uint16_to_signed62(rustsecp256k1zkp_v0_10_0_modinv64_signed62* out, const uint16_t* in) { int i; memset(out->v, 0, sizeof(out->v)); for (i = 0; i < 256; ++i) { @@ -1026,7 +1093,7 @@ void uint16_to_signed62(rustsecp256k1zkp_v0_8_0_modinv64_signed62* out, const ui } /* Convert a 256-bit number in signed62 notation to a representation as 16 uint16_t's. */ -void signed62_to_uint16(uint16_t* out, const rustsecp256k1zkp_v0_8_0_modinv64_signed62* in) { +static void signed62_to_uint16(uint16_t* out, const rustsecp256k1zkp_v0_10_0_modinv64_signed62* in) { int i; memset(out, 0, 32); for (i = 0; i < 256; ++i) { @@ -1035,11 +1102,11 @@ void signed62_to_uint16(uint16_t* out, const rustsecp256k1zkp_v0_8_0_modinv64_si } /* Randomly mutate the sign of limbs in signed62 representation, without changing the value. */ -void mutate_sign_signed62(rustsecp256k1zkp_v0_8_0_modinv64_signed62* x) { +static void mutate_sign_signed62(rustsecp256k1zkp_v0_10_0_modinv64_signed62* x) { static const int64_t M62 = (int64_t)(UINT64_MAX >> 2); int i; for (i = 0; i < 8; ++i) { - int pos = rustsecp256k1zkp_v0_8_0_testrand_bits(2); + int pos = rustsecp256k1zkp_v0_10_0_testrand_bits(2); if (x->v[pos] > 0 && x->v[pos + 1] <= M62) { x->v[pos] -= (M62 + 1); x->v[pos + 1] += 1; @@ -1050,26 +1117,46 @@ void mutate_sign_signed62(rustsecp256k1zkp_v0_8_0_modinv64_signed62* x) { } } -/* Test rustsecp256k1zkp_v0_8_0_modinv64{_var}, using inputs in 16-bit limb format, and returning inverse. */ -void test_modinv64_uint16(uint16_t* out, const uint16_t* in, const uint16_t* mod) { +/* Test rustsecp256k1zkp_v0_10_0_modinv64{_var}, using inputs in 16-bit limb format, and returning inverse. */ +static void test_modinv64_uint16(uint16_t* out, const uint16_t* in, const uint16_t* mod) { static const int64_t M62 = (int64_t)(UINT64_MAX >> 2); uint16_t tmp[16]; - rustsecp256k1zkp_v0_8_0_modinv64_signed62 x; - rustsecp256k1zkp_v0_8_0_modinv64_modinfo m; + rustsecp256k1zkp_v0_10_0_modinv64_signed62 x; + rustsecp256k1zkp_v0_10_0_modinv64_modinfo m; int i, vartime, nonzero; uint16_to_signed62(&x, in); nonzero = (x.v[0] | x.v[1] | x.v[2] | x.v[3] | x.v[4]) != 0; uint16_to_signed62(&m.modulus, mod); - mutate_sign_signed62(&m.modulus); /* compute 1/modulus mod 2^62 */ m.modulus_inv62 = modinv2p64(m.modulus.v[0]) & M62; CHECK(((m.modulus_inv62 * m.modulus.v[0]) & M62) == 1); + /* Test rustsecp256k1zkp_v0_10_0_jacobi64_maybe_var. */ + if (nonzero) { + int jac; + uint16_t sqr[16], negone[16]; + mulmod256(sqr, in, in, mod); + uint16_to_signed62(&x, sqr); + /* Compute jacobi symbol of in^2, which must be 1 (or uncomputable). */ + jac = rustsecp256k1zkp_v0_10_0_jacobi64_maybe_var(&x, &m); + CHECK(jac == 0 || jac == 1); + /* Then compute the jacobi symbol of -(in^2). x and -x have opposite + * jacobi symbols if and only if (mod % 4) == 3. */ + negone[0] = mod[0] - 1; + for (i = 1; i < 16; ++i) negone[i] = mod[i]; + mulmod256(sqr, sqr, negone, mod); + uint16_to_signed62(&x, sqr); + jac = rustsecp256k1zkp_v0_10_0_jacobi64_maybe_var(&x, &m); + CHECK(jac == 0 || jac == 1 - (mod[0] & 2)); + } + + uint16_to_signed62(&x, in); + mutate_sign_signed62(&m.modulus); for (vartime = 0; vartime < 2; ++vartime) { /* compute inverse */ - (vartime ? rustsecp256k1zkp_v0_8_0_modinv64_var : rustsecp256k1zkp_v0_8_0_modinv64)(&x, &m); + (vartime ? rustsecp256k1zkp_v0_10_0_modinv64_var : rustsecp256k1zkp_v0_10_0_modinv64)(&x, &m); /* produce output */ signed62_to_uint16(out, &x); @@ -1080,7 +1167,7 @@ void test_modinv64_uint16(uint16_t* out, const uint16_t* in, const uint16_t* mod for (i = 1; i < 16; ++i) CHECK(tmp[i] == 0); /* invert again */ - (vartime ? rustsecp256k1zkp_v0_8_0_modinv64_var : rustsecp256k1zkp_v0_8_0_modinv64)(&x, &m); + (vartime ? rustsecp256k1zkp_v0_10_0_modinv64_var : rustsecp256k1zkp_v0_10_0_modinv64)(&x, &m); /* check if the result is equal to the input */ signed62_to_uint16(tmp, &x); @@ -1090,7 +1177,7 @@ void test_modinv64_uint16(uint16_t* out, const uint16_t* in, const uint16_t* mod #endif /* test if a and b are coprime */ -int coprime(const uint16_t* a, const uint16_t* b) { +static int coprime(const uint16_t* a, const uint16_t* b) { uint16_t x[16], y[16], t[16]; int i; int iszero; @@ -1120,7 +1207,7 @@ int coprime(const uint16_t* a, const uint16_t* b) { return 1; } -void run_modinv_tests(void) { +static void run_modinv_tests(void) { /* Fixed test cases. Each tuple is (input, modulus, output), each as 16x16 bits in LE order. */ static const uint16_t CASES[][3][16] = { /* Test cases triggering edge cases in divsteps */ @@ -1722,7 +1809,7 @@ void run_modinv_tests(void) { #endif } - for (i = 0; i < 100 * count; ++i) { + for (i = 0; i < 100 * COUNT; ++i) { /* 256-bit numbers in 16-uint16_t's notation */ static const uint16_t ZERO[16] = {0}; uint16_t xd[16]; /* the number (in range [0,2^256)) to be inverted */ @@ -1732,8 +1819,8 @@ void run_modinv_tests(void) { /* generate random xd and md, so that md is odd, md>1, xd>= 16; + } +} + +/* Negate a 256-bit number (represented as 16 uint16_t's in LE order) mod 2^256. */ +static void neg256(uint16_t* out, const uint16_t* a) { + int i; + uint32_t carry = 1; + for (i = 0; i < 16; ++i) { + carry += (uint16_t)~a[i]; + out[i] = carry; + carry >>= 16; + } +} + +/* Right-shift a 256-bit number (represented as 16 uint16_t's in LE order). */ +static void rshift256(uint16_t* out, const uint16_t* a, int n, int sign_extend) { + uint16_t sign = sign_extend && (a[15] >> 15); + int i, j; + for (i = 15; i >= 0; --i) { + uint16_t v = 0; + for (j = 0; j < 16; ++j) { + int frompos = i*16 + j + n; + if (frompos >= 256) { + v |= sign << j; + } else { + v |= ((uint16_t)((a[frompos >> 4] >> (frompos & 15)) & 1)) << j; + } + } + out[i] = v; + } +} + +/* Load a 64-bit unsigned integer into an array of 16 uint16_t's in LE order representing a 256-bit value. */ +static void load256u64(uint16_t* out, uint64_t v, int is_signed) { + int i; + uint64_t sign = is_signed && (v >> 63) ? UINT64_MAX : 0; + for (i = 0; i < 4; ++i) { + out[i] = v >> (16 * i); + } + for (i = 4; i < 16; ++i) { + out[i] = sign; + } +} + +/* Load a 128-bit unsigned integer into an array of 16 uint16_t's in LE order representing a 256-bit value. */ +static void load256two64(uint16_t* out, uint64_t hi, uint64_t lo, int is_signed) { + int i; + uint64_t sign = is_signed && (hi >> 63) ? UINT64_MAX : 0; + for (i = 0; i < 4; ++i) { + out[i] = lo >> (16 * i); + } + for (i = 4; i < 8; ++i) { + out[i] = hi >> (16 * (i - 4)); + } + for (i = 8; i < 16; ++i) { + out[i] = sign; + } +} + +/* Check whether the 256-bit value represented by array of 16-bit values is in range -2^127 < v < 2^127. */ +static int int256is127(const uint16_t* v) { + int all_0 = ((v[7] & 0x8000) == 0), all_1 = ((v[7] & 0x8000) == 0x8000); + int i; + for (i = 8; i < 16; ++i) { + if (v[i] != 0) all_0 = 0; + if (v[i] != 0xffff) all_1 = 0; + } + return all_0 || all_1; +} + +static void load256u128(uint16_t* out, const rustsecp256k1zkp_v0_10_0_uint128* v) { + uint64_t lo = rustsecp256k1zkp_v0_10_0_u128_to_u64(v), hi = rustsecp256k1zkp_v0_10_0_u128_hi_u64(v); + load256two64(out, hi, lo, 0); +} + +static void load256i128(uint16_t* out, const rustsecp256k1zkp_v0_10_0_int128* v) { + uint64_t lo; + int64_t hi; + rustsecp256k1zkp_v0_10_0_int128 c = *v; + lo = rustsecp256k1zkp_v0_10_0_i128_to_u64(&c); + rustsecp256k1zkp_v0_10_0_i128_rshift(&c, 64); + hi = rustsecp256k1zkp_v0_10_0_i128_to_i64(&c); + load256two64(out, hi, lo, 1); +} + +static void run_int128_test_case(void) { + unsigned char buf[32]; + uint64_t v[4]; + rustsecp256k1zkp_v0_10_0_int128 swa, swz; + rustsecp256k1zkp_v0_10_0_uint128 uwa, uwz; + uint64_t ub, uc; + int64_t sb, sc; + uint16_t rswa[16], rswz[32], rswr[32], ruwa[16], ruwz[32], ruwr[32]; + uint16_t rub[16], ruc[16], rsb[16], rsc[16]; + int i; + + /* Generate 32-byte random value. */ + rustsecp256k1zkp_v0_10_0_testrand256_test(buf); + /* Convert into 4 64-bit integers. */ + for (i = 0; i < 4; ++i) { + uint64_t vi = 0; + int j; + for (j = 0; j < 8; ++j) vi = (vi << 8) + buf[8*i + j]; + v[i] = vi; + } + /* Convert those into a 128-bit value and two 64-bit values (signed and unsigned). */ + rustsecp256k1zkp_v0_10_0_u128_load(&uwa, v[1], v[0]); + rustsecp256k1zkp_v0_10_0_i128_load(&swa, v[1], v[0]); + ub = v[2]; + sb = v[2]; + uc = v[3]; + sc = v[3]; + /* Load those also into 16-bit array representations. */ + load256u128(ruwa, &uwa); + load256i128(rswa, &swa); + load256u64(rub, ub, 0); + load256u64(rsb, sb, 1); + load256u64(ruc, uc, 0); + load256u64(rsc, sc, 1); + /* test rustsecp256k1zkp_v0_10_0_u128_mul */ + mulmod256(ruwr, rub, ruc, NULL); + rustsecp256k1zkp_v0_10_0_u128_mul(&uwz, ub, uc); + load256u128(ruwz, &uwz); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(ruwr, ruwz, 16) == 0); + /* test rustsecp256k1zkp_v0_10_0_u128_accum_mul */ + mulmod256(ruwr, rub, ruc, NULL); + add256(ruwr, ruwr, ruwa); + uwz = uwa; + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&uwz, ub, uc); + load256u128(ruwz, &uwz); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(ruwr, ruwz, 16) == 0); + /* test rustsecp256k1zkp_v0_10_0_u128_accum_u64 */ + add256(ruwr, rub, ruwa); + uwz = uwa; + rustsecp256k1zkp_v0_10_0_u128_accum_u64(&uwz, ub); + load256u128(ruwz, &uwz); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(ruwr, ruwz, 16) == 0); + /* test rustsecp256k1zkp_v0_10_0_u128_rshift */ + rshift256(ruwr, ruwa, uc % 128, 0); + uwz = uwa; + rustsecp256k1zkp_v0_10_0_u128_rshift(&uwz, uc % 128); + load256u128(ruwz, &uwz); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(ruwr, ruwz, 16) == 0); + /* test rustsecp256k1zkp_v0_10_0_u128_to_u64 */ + CHECK(rustsecp256k1zkp_v0_10_0_u128_to_u64(&uwa) == v[0]); + /* test rustsecp256k1zkp_v0_10_0_u128_hi_u64 */ + CHECK(rustsecp256k1zkp_v0_10_0_u128_hi_u64(&uwa) == v[1]); + /* test rustsecp256k1zkp_v0_10_0_u128_from_u64 */ + rustsecp256k1zkp_v0_10_0_u128_from_u64(&uwz, ub); + load256u128(ruwz, &uwz); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(rub, ruwz, 16) == 0); + /* test rustsecp256k1zkp_v0_10_0_u128_check_bits */ + { + int uwa_bits = 0; + int j; + for (j = 0; j < 128; ++j) { + if (ruwa[j / 16] >> (j % 16)) uwa_bits = 1 + j; + } + for (j = 0; j < 128; ++j) { + CHECK(rustsecp256k1zkp_v0_10_0_u128_check_bits(&uwa, j) == (uwa_bits <= j)); + } + } + /* test rustsecp256k1zkp_v0_10_0_i128_mul */ + mulmod256(rswr, rsb, rsc, NULL); + rustsecp256k1zkp_v0_10_0_i128_mul(&swz, sb, sc); + load256i128(rswz, &swz); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(rswr, rswz, 16) == 0); + /* test rustsecp256k1zkp_v0_10_0_i128_accum_mul */ + mulmod256(rswr, rsb, rsc, NULL); + add256(rswr, rswr, rswa); + if (int256is127(rswr)) { + swz = swa; + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&swz, sb, sc); + load256i128(rswz, &swz); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(rswr, rswz, 16) == 0); + } + /* test rustsecp256k1zkp_v0_10_0_i128_det */ + { + uint16_t rsd[16], rse[16], rst[32]; + int64_t sd = v[0], se = v[1]; + load256u64(rsd, sd, 1); + load256u64(rse, se, 1); + mulmod256(rst, rsc, rsd, NULL); + neg256(rst, rst); + mulmod256(rswr, rsb, rse, NULL); + add256(rswr, rswr, rst); + rustsecp256k1zkp_v0_10_0_i128_det(&swz, sb, sc, sd, se); + load256i128(rswz, &swz); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(rswr, rswz, 16) == 0); + } + /* test rustsecp256k1zkp_v0_10_0_i128_rshift */ + rshift256(rswr, rswa, uc % 127, 1); + swz = swa; + rustsecp256k1zkp_v0_10_0_i128_rshift(&swz, uc % 127); + load256i128(rswz, &swz); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(rswr, rswz, 16) == 0); + /* test rustsecp256k1zkp_v0_10_0_i128_to_u64 */ + CHECK(rustsecp256k1zkp_v0_10_0_i128_to_u64(&swa) == v[0]); + /* test rustsecp256k1zkp_v0_10_0_i128_from_i64 */ + rustsecp256k1zkp_v0_10_0_i128_from_i64(&swz, sb); + load256i128(rswz, &swz); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(rsb, rswz, 16) == 0); + /* test rustsecp256k1zkp_v0_10_0_i128_to_i64 */ + CHECK(rustsecp256k1zkp_v0_10_0_i128_to_i64(&swz) == sb); + /* test rustsecp256k1zkp_v0_10_0_i128_eq_var */ + { + int expect = (uc & 1); + swz = swa; + if (!expect) { + /* Make sure swz != swa */ + uint64_t v0c = v[0], v1c = v[1]; + if (ub & 64) { + v1c ^= (((uint64_t)1) << (ub & 63)); + } else { + v0c ^= (((uint64_t)1) << (ub & 63)); + } + rustsecp256k1zkp_v0_10_0_i128_load(&swz, v1c, v0c); + } + CHECK(rustsecp256k1zkp_v0_10_0_i128_eq_var(&swa, &swz) == expect); + } + /* test rustsecp256k1zkp_v0_10_0_i128_check_pow2 (sign == 1) */ + { + int expect = (uc & 1); + int pos = ub % 127; + if (expect) { + /* If expect==1, set swz to exactly 2^pos. */ + uint64_t hi = 0; + uint64_t lo = 0; + if (pos >= 64) { + hi = (((uint64_t)1) << (pos & 63)); + } else { + lo = (((uint64_t)1) << (pos & 63)); + } + rustsecp256k1zkp_v0_10_0_i128_load(&swz, hi, lo); + } else { + /* If expect==0, set swz = swa, but update expect=1 if swa happens to equal 2^pos. */ + if (pos >= 64) { + if ((v[1] == (((uint64_t)1) << (pos & 63))) && v[0] == 0) expect = 1; + } else { + if ((v[0] == (((uint64_t)1) << (pos & 63))) && v[1] == 0) expect = 1; + } + swz = swa; + } + CHECK(rustsecp256k1zkp_v0_10_0_i128_check_pow2(&swz, pos, 1) == expect); + } + /* test rustsecp256k1zkp_v0_10_0_i128_check_pow2 (sign == -1) */ + { + int expect = (uc & 1); + int pos = ub % 127; + if (expect) { + /* If expect==1, set swz to exactly -2^pos. */ + uint64_t hi = ~(uint64_t)0; + uint64_t lo = ~(uint64_t)0; + if (pos >= 64) { + hi <<= (pos & 63); + lo = 0; + } else { + lo <<= (pos & 63); + } + rustsecp256k1zkp_v0_10_0_i128_load(&swz, hi, lo); + } else { + /* If expect==0, set swz = swa, but update expect=1 if swa happens to equal -2^pos. */ + if (pos >= 64) { + if ((v[1] == ((~(uint64_t)0) << (pos & 63))) && v[0] == 0) expect = 1; + } else { + if ((v[0] == ((~(uint64_t)0) << (pos & 63))) && v[1] == ~(uint64_t)0) expect = 1; + } + swz = swa; + } + CHECK(rustsecp256k1zkp_v0_10_0_i128_check_pow2(&swz, pos, -1) == expect); + } +} + +static void run_int128_tests(void) { + { /* rustsecp256k1zkp_v0_10_0_u128_accum_mul */ + rustsecp256k1zkp_v0_10_0_uint128 res; + + /* Check rustsecp256k1zkp_v0_10_0_u128_accum_mul overflow */ + rustsecp256k1zkp_v0_10_0_u128_mul(&res, UINT64_MAX, UINT64_MAX); + rustsecp256k1zkp_v0_10_0_u128_accum_mul(&res, UINT64_MAX, UINT64_MAX); + CHECK(rustsecp256k1zkp_v0_10_0_u128_to_u64(&res) == 2); + CHECK(rustsecp256k1zkp_v0_10_0_u128_hi_u64(&res) == 18446744073709551612U); + } + { /* rustsecp256k1zkp_v0_10_0_u128_accum_mul */ + rustsecp256k1zkp_v0_10_0_int128 res; + + /* Compute INT128_MAX = 2^127 - 1 with rustsecp256k1zkp_v0_10_0_i128_accum_mul */ + rustsecp256k1zkp_v0_10_0_i128_mul(&res, INT64_MAX, INT64_MAX); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&res, INT64_MAX, INT64_MAX); + CHECK(rustsecp256k1zkp_v0_10_0_i128_to_u64(&res) == 2); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&res, 4, 9223372036854775807); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&res, 1, 1); + CHECK(rustsecp256k1zkp_v0_10_0_i128_to_u64(&res) == UINT64_MAX); + rustsecp256k1zkp_v0_10_0_i128_rshift(&res, 64); + CHECK(rustsecp256k1zkp_v0_10_0_i128_to_i64(&res) == INT64_MAX); + + /* Compute INT128_MIN = - 2^127 with rustsecp256k1zkp_v0_10_0_i128_accum_mul */ + rustsecp256k1zkp_v0_10_0_i128_mul(&res, INT64_MAX, INT64_MIN); + CHECK(rustsecp256k1zkp_v0_10_0_i128_to_u64(&res) == (uint64_t)INT64_MIN); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&res, INT64_MAX, INT64_MIN); + CHECK(rustsecp256k1zkp_v0_10_0_i128_to_u64(&res) == 0); + rustsecp256k1zkp_v0_10_0_i128_accum_mul(&res, 2, INT64_MIN); + CHECK(rustsecp256k1zkp_v0_10_0_i128_to_u64(&res) == 0); + rustsecp256k1zkp_v0_10_0_i128_rshift(&res, 64); + CHECK(rustsecp256k1zkp_v0_10_0_i128_to_i64(&res) == INT64_MIN); + } + { + /* Randomized tests. */ + int i; + for (i = 0; i < 256 * COUNT; ++i) run_int128_test_case(); + } +} +#endif +/***** SCALAR TESTS *****/ -void scalar_test(void) { - rustsecp256k1zkp_v0_8_0_scalar s; - rustsecp256k1zkp_v0_8_0_scalar s1; - rustsecp256k1zkp_v0_8_0_scalar s2; +static void scalar_test(void) { + rustsecp256k1zkp_v0_10_0_scalar s; + rustsecp256k1zkp_v0_10_0_scalar s1; + rustsecp256k1zkp_v0_10_0_scalar s2; unsigned char c[32]; /* Set 's' to a random scalar, with value 'snum'. */ @@ -1773,320 +2185,244 @@ void scalar_test(void) { /* Set 's2' to a random scalar, with value 'snum2', and byte array representation 'c'. */ random_scalar_order_test(&s2); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(c, &s2); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(c, &s2); { int i; /* Test that fetching groups of 4 bits from a scalar and recursing n(i)=16*n(i-1)+p(i) reconstructs it. */ - rustsecp256k1zkp_v0_8_0_scalar n; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&n, 0); + rustsecp256k1zkp_v0_10_0_scalar n; + rustsecp256k1zkp_v0_10_0_scalar_set_int(&n, 0); for (i = 0; i < 256; i += 4) { - rustsecp256k1zkp_v0_8_0_scalar t; + rustsecp256k1zkp_v0_10_0_scalar t; int j; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&t, rustsecp256k1zkp_v0_8_0_scalar_get_bits(&s, 256 - 4 - i, 4)); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&t, rustsecp256k1zkp_v0_10_0_scalar_get_bits(&s, 256 - 4 - i, 4)); for (j = 0; j < 4; j++) { - rustsecp256k1zkp_v0_8_0_scalar_add(&n, &n, &n); + rustsecp256k1zkp_v0_10_0_scalar_add(&n, &n, &n); } - rustsecp256k1zkp_v0_8_0_scalar_add(&n, &n, &t); + rustsecp256k1zkp_v0_10_0_scalar_add(&n, &n, &t); } - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&n, &s)); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&n, &s)); } { /* Test that fetching groups of randomly-sized bits from a scalar and recursing n(i)=b*n(i-1)+p(i) reconstructs it. */ - rustsecp256k1zkp_v0_8_0_scalar n; + rustsecp256k1zkp_v0_10_0_scalar n; int i = 0; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&n, 0); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&n, 0); while (i < 256) { - rustsecp256k1zkp_v0_8_0_scalar t; + rustsecp256k1zkp_v0_10_0_scalar t; int j; - int now = rustsecp256k1zkp_v0_8_0_testrand_int(15) + 1; + int now = rustsecp256k1zkp_v0_10_0_testrand_int(15) + 1; if (now + i > 256) { now = 256 - i; } - rustsecp256k1zkp_v0_8_0_scalar_set_int(&t, rustsecp256k1zkp_v0_8_0_scalar_get_bits_var(&s, 256 - now - i, now)); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&t, rustsecp256k1zkp_v0_10_0_scalar_get_bits_var(&s, 256 - now - i, now)); for (j = 0; j < now; j++) { - rustsecp256k1zkp_v0_8_0_scalar_add(&n, &n, &n); + rustsecp256k1zkp_v0_10_0_scalar_add(&n, &n, &n); } - rustsecp256k1zkp_v0_8_0_scalar_add(&n, &n, &t); + rustsecp256k1zkp_v0_10_0_scalar_add(&n, &n, &t); i += now; } - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&n, &s)); - } - - { - /* test rustsecp256k1zkp_v0_8_0_scalar_shr_int */ - rustsecp256k1zkp_v0_8_0_scalar r; - int i; - random_scalar_order_test(&r); - for (i = 0; i < 100; ++i) { - int low; - int shift = 1 + rustsecp256k1zkp_v0_8_0_testrand_int(15); - int expected = r.d[0] % (1 << shift); - low = rustsecp256k1zkp_v0_8_0_scalar_shr_int(&r, shift); - CHECK(expected == low); - } + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&n, &s)); } { /* Test commutativity of add. */ - rustsecp256k1zkp_v0_8_0_scalar r1, r2; - rustsecp256k1zkp_v0_8_0_scalar_add(&r1, &s1, &s2); - rustsecp256k1zkp_v0_8_0_scalar_add(&r2, &s2, &s1); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&r1, &r2)); + rustsecp256k1zkp_v0_10_0_scalar r1, r2; + rustsecp256k1zkp_v0_10_0_scalar_add(&r1, &s1, &s2); + rustsecp256k1zkp_v0_10_0_scalar_add(&r2, &s2, &s1); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&r1, &r2)); } { - rustsecp256k1zkp_v0_8_0_scalar r1, r2; - rustsecp256k1zkp_v0_8_0_scalar b; + rustsecp256k1zkp_v0_10_0_scalar r1, r2; + rustsecp256k1zkp_v0_10_0_scalar b; int i; /* Test add_bit. */ - int bit = rustsecp256k1zkp_v0_8_0_testrand_bits(8); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&b, 1); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_is_one(&b)); + int bit = rustsecp256k1zkp_v0_10_0_testrand_bits(8); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&b, 1); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_is_one(&b)); for (i = 0; i < bit; i++) { - rustsecp256k1zkp_v0_8_0_scalar_add(&b, &b, &b); + rustsecp256k1zkp_v0_10_0_scalar_add(&b, &b, &b); } r1 = s1; r2 = s1; - if (!rustsecp256k1zkp_v0_8_0_scalar_add(&r1, &r1, &b)) { + if (!rustsecp256k1zkp_v0_10_0_scalar_add(&r1, &r1, &b)) { /* No overflow happened. */ - rustsecp256k1zkp_v0_8_0_scalar_cadd_bit(&r2, bit, 1); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&r1, &r2)); + rustsecp256k1zkp_v0_10_0_scalar_cadd_bit(&r2, bit, 1); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&r1, &r2)); /* cadd is a noop when flag is zero */ - rustsecp256k1zkp_v0_8_0_scalar_cadd_bit(&r2, bit, 0); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&r1, &r2)); + rustsecp256k1zkp_v0_10_0_scalar_cadd_bit(&r2, bit, 0); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&r1, &r2)); } } { /* Test commutativity of mul. */ - rustsecp256k1zkp_v0_8_0_scalar r1, r2; - rustsecp256k1zkp_v0_8_0_scalar_mul(&r1, &s1, &s2); - rustsecp256k1zkp_v0_8_0_scalar_mul(&r2, &s2, &s1); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&r1, &r2)); + rustsecp256k1zkp_v0_10_0_scalar r1, r2; + rustsecp256k1zkp_v0_10_0_scalar_mul(&r1, &s1, &s2); + rustsecp256k1zkp_v0_10_0_scalar_mul(&r2, &s2, &s1); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&r1, &r2)); } { /* Test associativity of add. */ - rustsecp256k1zkp_v0_8_0_scalar r1, r2; - rustsecp256k1zkp_v0_8_0_scalar_add(&r1, &s1, &s2); - rustsecp256k1zkp_v0_8_0_scalar_add(&r1, &r1, &s); - rustsecp256k1zkp_v0_8_0_scalar_add(&r2, &s2, &s); - rustsecp256k1zkp_v0_8_0_scalar_add(&r2, &s1, &r2); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&r1, &r2)); + rustsecp256k1zkp_v0_10_0_scalar r1, r2; + rustsecp256k1zkp_v0_10_0_scalar_add(&r1, &s1, &s2); + rustsecp256k1zkp_v0_10_0_scalar_add(&r1, &r1, &s); + rustsecp256k1zkp_v0_10_0_scalar_add(&r2, &s2, &s); + rustsecp256k1zkp_v0_10_0_scalar_add(&r2, &s1, &r2); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&r1, &r2)); } { /* Test associativity of mul. */ - rustsecp256k1zkp_v0_8_0_scalar r1, r2; - rustsecp256k1zkp_v0_8_0_scalar_mul(&r1, &s1, &s2); - rustsecp256k1zkp_v0_8_0_scalar_mul(&r1, &r1, &s); - rustsecp256k1zkp_v0_8_0_scalar_mul(&r2, &s2, &s); - rustsecp256k1zkp_v0_8_0_scalar_mul(&r2, &s1, &r2); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&r1, &r2)); + rustsecp256k1zkp_v0_10_0_scalar r1, r2; + rustsecp256k1zkp_v0_10_0_scalar_mul(&r1, &s1, &s2); + rustsecp256k1zkp_v0_10_0_scalar_mul(&r1, &r1, &s); + rustsecp256k1zkp_v0_10_0_scalar_mul(&r2, &s2, &s); + rustsecp256k1zkp_v0_10_0_scalar_mul(&r2, &s1, &r2); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&r1, &r2)); } { /* Test distributitivity of mul over add. */ - rustsecp256k1zkp_v0_8_0_scalar r1, r2, t; - rustsecp256k1zkp_v0_8_0_scalar_add(&r1, &s1, &s2); - rustsecp256k1zkp_v0_8_0_scalar_mul(&r1, &r1, &s); - rustsecp256k1zkp_v0_8_0_scalar_mul(&r2, &s1, &s); - rustsecp256k1zkp_v0_8_0_scalar_mul(&t, &s2, &s); - rustsecp256k1zkp_v0_8_0_scalar_add(&r2, &r2, &t); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&r1, &r2)); + rustsecp256k1zkp_v0_10_0_scalar r1, r2, t; + rustsecp256k1zkp_v0_10_0_scalar_add(&r1, &s1, &s2); + rustsecp256k1zkp_v0_10_0_scalar_mul(&r1, &r1, &s); + rustsecp256k1zkp_v0_10_0_scalar_mul(&r2, &s1, &s); + rustsecp256k1zkp_v0_10_0_scalar_mul(&t, &s2, &s); + rustsecp256k1zkp_v0_10_0_scalar_add(&r2, &r2, &t); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&r1, &r2)); } { /* Test square. */ - rustsecp256k1zkp_v0_8_0_scalar r1, r2; - rustsecp256k1zkp_v0_8_0_scalar_sqr(&r1, &s1); - rustsecp256k1zkp_v0_8_0_scalar_mul(&r2, &s1, &s1); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&r1, &r2)); + rustsecp256k1zkp_v0_10_0_scalar r1, r2; + rustsecp256k1zkp_v0_10_0_scalar_sqr(&r1, &s1); + rustsecp256k1zkp_v0_10_0_scalar_mul(&r2, &s1, &s1); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&r1, &r2)); } { /* Test multiplicative identity. */ - rustsecp256k1zkp_v0_8_0_scalar r1, v1; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&v1,1); - rustsecp256k1zkp_v0_8_0_scalar_mul(&r1, &s1, &v1); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&r1, &s1)); + rustsecp256k1zkp_v0_10_0_scalar r1; + rustsecp256k1zkp_v0_10_0_scalar_mul(&r1, &s1, &rustsecp256k1zkp_v0_10_0_scalar_one); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&r1, &s1)); } { /* Test additive identity. */ - rustsecp256k1zkp_v0_8_0_scalar r1, v0; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&v0,0); - rustsecp256k1zkp_v0_8_0_scalar_add(&r1, &s1, &v0); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&r1, &s1)); + rustsecp256k1zkp_v0_10_0_scalar r1; + rustsecp256k1zkp_v0_10_0_scalar_add(&r1, &s1, &rustsecp256k1zkp_v0_10_0_scalar_zero); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&r1, &s1)); } { /* Test zero product property. */ - rustsecp256k1zkp_v0_8_0_scalar r1, v0; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&v0,0); - rustsecp256k1zkp_v0_8_0_scalar_mul(&r1, &s1, &v0); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&r1, &v0)); + rustsecp256k1zkp_v0_10_0_scalar r1; + rustsecp256k1zkp_v0_10_0_scalar_mul(&r1, &s1, &rustsecp256k1zkp_v0_10_0_scalar_zero); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&r1, &rustsecp256k1zkp_v0_10_0_scalar_zero)); } + { + /* Test halving. */ + rustsecp256k1zkp_v0_10_0_scalar r; + rustsecp256k1zkp_v0_10_0_scalar_add(&r, &s, &s); + rustsecp256k1zkp_v0_10_0_scalar_half(&r, &r); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&r, &s)); + } } -void run_scalar_set_b32_seckey_tests(void) { +static void run_scalar_set_b32_seckey_tests(void) { unsigned char b32[32]; - rustsecp256k1zkp_v0_8_0_scalar s1; - rustsecp256k1zkp_v0_8_0_scalar s2; + rustsecp256k1zkp_v0_10_0_scalar s1; + rustsecp256k1zkp_v0_10_0_scalar s2; /* Usually set_b32 and set_b32_seckey give the same result */ random_scalar_order_b32(b32); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&s1, b32, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(&s2, b32) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&s1, &s2) == 1); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&s1, b32, NULL); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_set_b32_seckey(&s2, b32) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&s1, &s2) == 1); memset(b32, 0, sizeof(b32)); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(&s2, b32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_set_b32_seckey(&s2, b32) == 0); memset(b32, 0xFF, sizeof(b32)); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_set_b32_seckey(&s2, b32) == 0); -} - -void scalar_chacha_tests(void) { - /* Test vectors 1 to 4 from https://tools.ietf.org/html/rfc8439#appendix-A - * Note that scalar_set_b32 and scalar_get_b32 represent integers - * underlying the scalar in big-endian format. */ - unsigned char expected1[64] = { - 0xad, 0xe0, 0xb8, 0x76, 0x90, 0x3d, 0xf1, 0xa0, - 0xe5, 0x6a, 0x5d, 0x40, 0x28, 0xbd, 0x86, 0x53, - 0xb8, 0x19, 0xd2, 0xbd, 0x1a, 0xed, 0x8d, 0xa0, - 0xcc, 0xef, 0x36, 0xa8, 0xc7, 0x0d, 0x77, 0x8b, - 0x7c, 0x59, 0x41, 0xda, 0x8d, 0x48, 0x57, 0x51, - 0x3f, 0xe0, 0x24, 0x77, 0x37, 0x4a, 0xd8, 0xb8, - 0xf4, 0xb8, 0x43, 0x6a, 0x1c, 0xa1, 0x18, 0x15, - 0x69, 0xb6, 0x87, 0xc3, 0x86, 0x65, 0xee, 0xb2 - }; - unsigned char expected2[64] = { - 0xbe, 0xe7, 0x07, 0x9f, 0x7a, 0x38, 0x51, 0x55, - 0x7c, 0x97, 0xba, 0x98, 0x0d, 0x08, 0x2d, 0x73, - 0xa0, 0x29, 0x0f, 0xcb, 0x69, 0x65, 0xe3, 0x48, - 0x3e, 0x53, 0xc6, 0x12, 0xed, 0x7a, 0xee, 0x32, - 0x76, 0x21, 0xb7, 0x29, 0x43, 0x4e, 0xe6, 0x9c, - 0xb0, 0x33, 0x71, 0xd5, 0xd5, 0x39, 0xd8, 0x74, - 0x28, 0x1f, 0xed, 0x31, 0x45, 0xfb, 0x0a, 0x51, - 0x1f, 0x0a, 0xe1, 0xac, 0x6f, 0x4d, 0x79, 0x4b - }; - unsigned char seed3[32] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 - }; - unsigned char expected3[64] = { - 0x24, 0x52, 0xeb, 0x3a, 0x92, 0x49, 0xf8, 0xec, - 0x8d, 0x82, 0x9d, 0x9b, 0xdd, 0xd4, 0xce, 0xb1, - 0xe8, 0x25, 0x20, 0x83, 0x60, 0x81, 0x8b, 0x01, - 0xf3, 0x84, 0x22, 0xb8, 0x5a, 0xaa, 0x49, 0xc9, - 0xbb, 0x00, 0xca, 0x8e, 0xda, 0x3b, 0xa7, 0xb4, - 0xc4, 0xb5, 0x92, 0xd1, 0xfd, 0xf2, 0x73, 0x2f, - 0x44, 0x36, 0x27, 0x4e, 0x25, 0x61, 0xb3, 0xc8, - 0xeb, 0xdd, 0x4a, 0xa6, 0xa0, 0x13, 0x6c, 0x00 - }; - unsigned char seed4[32] = { - 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; - unsigned char expected4[64] = { - 0xfb, 0x4d, 0xd5, 0x72, 0x4b, 0xc4, 0x2e, 0xf1, - 0xdf, 0x92, 0x26, 0x36, 0x32, 0x7f, 0x13, 0x94, - 0xa7, 0x8d, 0xea, 0x8f, 0x5e, 0x26, 0x90, 0x39, - 0xa1, 0xbe, 0xbb, 0xc1, 0xca, 0xf0, 0x9a, 0xae, - 0xa2, 0x5a, 0xb2, 0x13, 0x48, 0xa6, 0xb4, 0x6c, - 0x1b, 0x9d, 0x9b, 0xcb, 0x09, 0x2c, 0x5b, 0xe6, - 0x54, 0x6c, 0xa6, 0x24, 0x1b, 0xec, 0x45, 0xd5, - 0x87, 0xf4, 0x74, 0x73, 0x96, 0xf0, 0x99, 0x2e - }; - unsigned char seed5[32] = { - 0x32, 0x56, 0x56, 0xf4, 0x29, 0x02, 0xc2, 0xf8, - 0xa3, 0x4b, 0x96, 0xf5, 0xa7, 0xf7, 0xe3, 0x6c, - 0x92, 0xad, 0xa5, 0x18, 0x1c, 0xe3, 0x41, 0xae, - 0xc3, 0xf3, 0x18, 0xd0, 0xfa, 0x5b, 0x72, 0x53 - }; - unsigned char expected5[64] = { - 0xe7, 0x56, 0xd3, 0x28, 0xe9, 0xc6, 0x19, 0x5c, - 0x6f, 0x17, 0x8e, 0x21, 0x8c, 0x1e, 0x72, 0x11, - 0xe7, 0xbd, 0x17, 0x0d, 0xac, 0x14, 0xad, 0xe9, - 0x3d, 0x9f, 0xb6, 0x92, 0xd6, 0x09, 0x20, 0xfb, - 0x43, 0x8e, 0x3b, 0x6d, 0xe3, 0x33, 0xdc, 0xc7, - 0x6c, 0x07, 0x6f, 0xbb, 0x1f, 0xb4, 0xc8, 0xb5, - 0xe3, 0x6c, 0xe5, 0x12, 0xd9, 0xd7, 0x64, 0x0c, - 0xf5, 0xa7, 0x0d, 0xab, 0x79, 0x03, 0xf1, 0x81 - }; + CHECK(rustsecp256k1zkp_v0_10_0_scalar_set_b32_seckey(&s2, b32) == 0); +} - rustsecp256k1zkp_v0_8_0_scalar exp_r1, exp_r2; - rustsecp256k1zkp_v0_8_0_scalar r1, r2; - unsigned char seed0[32] = { 0 }; - - rustsecp256k1zkp_v0_8_0_scalar_chacha20(&r1, &r2, seed0, 0); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&exp_r1, &expected1[0], NULL); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&exp_r2, &expected1[32], NULL); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&exp_r1, &r1)); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&exp_r2, &r2)); - - rustsecp256k1zkp_v0_8_0_scalar_chacha20(&r1, &r2, seed0, 1); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&exp_r1, &expected2[0], NULL); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&exp_r2, &expected2[32], NULL); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&exp_r1, &r1)); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&exp_r2, &r2)); - - rustsecp256k1zkp_v0_8_0_scalar_chacha20(&r1, &r2, seed3, 1); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&exp_r1, &expected3[0], NULL); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&exp_r2, &expected3[32], NULL); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&exp_r1, &r1)); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&exp_r2, &r2)); - - rustsecp256k1zkp_v0_8_0_scalar_chacha20(&r1, &r2, seed4, 2); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&exp_r1, &expected4[0], NULL); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&exp_r2, &expected4[32], NULL); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&exp_r1, &r1)); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&exp_r2, &r2)); - - rustsecp256k1zkp_v0_8_0_scalar_chacha20(&r1, &r2, seed5, 0x6ff8602a7a78e2f2ULL); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&exp_r1, &expected5[0], NULL); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&exp_r2, &expected5[32], NULL); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&exp_r1, &r1)); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&exp_r2, &r2)); -} - -void run_scalar_tests(void) { +static void run_scalar_tests(void) { int i; - for (i = 0; i < 128 * count; i++) { + for (i = 0; i < 128 * COUNT; i++) { scalar_test(); } - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { run_scalar_set_b32_seckey_tests(); } - scalar_chacha_tests(); + { + /* Check that the scalar constants rustsecp256k1zkp_v0_10_0_scalar_zero and + rustsecp256k1zkp_v0_10_0_scalar_one contain the expected values. */ + rustsecp256k1zkp_v0_10_0_scalar zero, one; + + CHECK(rustsecp256k1zkp_v0_10_0_scalar_is_zero(&rustsecp256k1zkp_v0_10_0_scalar_zero)); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&zero, 0); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&zero, &rustsecp256k1zkp_v0_10_0_scalar_zero)); + + CHECK(rustsecp256k1zkp_v0_10_0_scalar_is_one(&rustsecp256k1zkp_v0_10_0_scalar_one)); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&one, 1); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&one, &rustsecp256k1zkp_v0_10_0_scalar_one)); + } { /* (-1)+1 should be zero. */ - rustsecp256k1zkp_v0_8_0_scalar s, o; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&s, 1); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_is_one(&s)); - rustsecp256k1zkp_v0_8_0_scalar_negate(&o, &s); - rustsecp256k1zkp_v0_8_0_scalar_add(&o, &o, &s); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_is_zero(&o)); - rustsecp256k1zkp_v0_8_0_scalar_negate(&o, &o); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_is_zero(&o)); + rustsecp256k1zkp_v0_10_0_scalar o; + rustsecp256k1zkp_v0_10_0_scalar_negate(&o, &rustsecp256k1zkp_v0_10_0_scalar_one); + rustsecp256k1zkp_v0_10_0_scalar_add(&o, &o, &rustsecp256k1zkp_v0_10_0_scalar_one); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_is_zero(&o)); + rustsecp256k1zkp_v0_10_0_scalar_negate(&o, &o); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_is_zero(&o)); + } + + { + /* Test that halving and doubling roundtrips on some fixed values. */ + static const rustsecp256k1zkp_v0_10_0_scalar HALF_TESTS[] = { + /* 0 */ + SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0), + /* 1 */ + SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 1), + /* -1 */ + SECP256K1_SCALAR_CONST(0xfffffffful, 0xfffffffful, 0xfffffffful, 0xfffffffeul, 0xbaaedce6ul, 0xaf48a03bul, 0xbfd25e8cul, 0xd0364140ul), + /* -2 (largest odd value) */ + SECP256K1_SCALAR_CONST(0xfffffffful, 0xfffffffful, 0xfffffffful, 0xfffffffeul, 0xbaaedce6ul, 0xaf48a03bul, 0xbfd25e8cul, 0xd036413Ful), + /* Half the secp256k1 order */ + SECP256K1_SCALAR_CONST(0x7ffffffful, 0xfffffffful, 0xfffffffful, 0xfffffffful, 0x5d576e73ul, 0x57a4501dul, 0xdfe92f46ul, 0x681b20a0ul), + /* Half the secp256k1 order + 1 */ + SECP256K1_SCALAR_CONST(0x7ffffffful, 0xfffffffful, 0xfffffffful, 0xfffffffful, 0x5d576e73ul, 0x57a4501dul, 0xdfe92f46ul, 0x681b20a1ul), + /* 2^255 */ + SECP256K1_SCALAR_CONST(0x80000000ul, 0, 0, 0, 0, 0, 0, 0), + /* 2^255 - 1 */ + SECP256K1_SCALAR_CONST(0x7ffffffful, 0xfffffffful, 0xfffffffful, 0xfffffffful, 0xfffffffful, 0xfffffffful, 0xfffffffful, 0xfffffffful), + }; + unsigned n; + for (n = 0; n < sizeof(HALF_TESTS) / sizeof(HALF_TESTS[0]); ++n) { + rustsecp256k1zkp_v0_10_0_scalar s; + rustsecp256k1zkp_v0_10_0_scalar_half(&s, &HALF_TESTS[n]); + rustsecp256k1zkp_v0_10_0_scalar_add(&s, &s, &s); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&s, &HALF_TESTS[n])); + rustsecp256k1zkp_v0_10_0_scalar_add(&s, &s, &s); + rustsecp256k1zkp_v0_10_0_scalar_half(&s, &s); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&s, &HALF_TESTS[n])); + } } { /* Does check_overflow check catch all ones? */ - static const rustsecp256k1zkp_v0_8_0_scalar overflowed = SECP256K1_SCALAR_CONST( + static const rustsecp256k1zkp_v0_10_0_scalar overflowed = SECP256K1_SCALAR_CONST( 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL ); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_check_overflow(&overflowed)); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_check_overflow(&overflowed)); } { @@ -2095,14 +2431,13 @@ void run_scalar_tests(void) { * and edge-case coverage on 32-bit and 64-bit implementations. * The responses were generated with Sage 5.9. */ - rustsecp256k1zkp_v0_8_0_scalar x; - rustsecp256k1zkp_v0_8_0_scalar y; - rustsecp256k1zkp_v0_8_0_scalar z; - rustsecp256k1zkp_v0_8_0_scalar zz; - rustsecp256k1zkp_v0_8_0_scalar one; - rustsecp256k1zkp_v0_8_0_scalar r1; - rustsecp256k1zkp_v0_8_0_scalar r2; - rustsecp256k1zkp_v0_8_0_scalar zzv; + rustsecp256k1zkp_v0_10_0_scalar x; + rustsecp256k1zkp_v0_10_0_scalar y; + rustsecp256k1zkp_v0_10_0_scalar z; + rustsecp256k1zkp_v0_10_0_scalar zz; + rustsecp256k1zkp_v0_10_0_scalar r1; + rustsecp256k1zkp_v0_10_0_scalar r2; + rustsecp256k1zkp_v0_10_0_scalar zzv; int overflow; unsigned char chal[33][2][32] = { {{0xff, 0xff, 0x03, 0x07, 0x00, 0x00, 0x00, 0x00, @@ -2636,278 +2971,318 @@ void run_scalar_tests(void) { 0x1e, 0x86, 0x5d, 0x89, 0x63, 0xe6, 0x0a, 0x46, 0x5c, 0x02, 0x97, 0x1b, 0x62, 0x43, 0x86, 0xf5}} }; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&one, 1); for (i = 0; i < 33; i++) { - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&x, chal[i][0], &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&x, chal[i][0], &overflow); CHECK(!overflow); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&y, chal[i][1], &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&y, chal[i][1], &overflow); CHECK(!overflow); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&r1, res[i][0], &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&r1, res[i][0], &overflow); CHECK(!overflow); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&r2, res[i][1], &overflow); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&r2, res[i][1], &overflow); CHECK(!overflow); - rustsecp256k1zkp_v0_8_0_scalar_mul(&z, &x, &y); - CHECK(!rustsecp256k1zkp_v0_8_0_scalar_check_overflow(&z)); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&r1, &z)); - if (!rustsecp256k1zkp_v0_8_0_scalar_is_zero(&y)) { - rustsecp256k1zkp_v0_8_0_scalar_inverse(&zz, &y); - CHECK(!rustsecp256k1zkp_v0_8_0_scalar_check_overflow(&zz)); - rustsecp256k1zkp_v0_8_0_scalar_inverse_var(&zzv, &y); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&zzv, &zz)); - rustsecp256k1zkp_v0_8_0_scalar_mul(&z, &z, &zz); - CHECK(!rustsecp256k1zkp_v0_8_0_scalar_check_overflow(&z)); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&x, &z)); - rustsecp256k1zkp_v0_8_0_scalar_mul(&zz, &zz, &y); - CHECK(!rustsecp256k1zkp_v0_8_0_scalar_check_overflow(&zz)); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&one, &zz)); + rustsecp256k1zkp_v0_10_0_scalar_mul(&z, &x, &y); + CHECK(!rustsecp256k1zkp_v0_10_0_scalar_check_overflow(&z)); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&r1, &z)); + if (!rustsecp256k1zkp_v0_10_0_scalar_is_zero(&y)) { + rustsecp256k1zkp_v0_10_0_scalar_inverse(&zz, &y); + CHECK(!rustsecp256k1zkp_v0_10_0_scalar_check_overflow(&zz)); + rustsecp256k1zkp_v0_10_0_scalar_inverse_var(&zzv, &y); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&zzv, &zz)); + rustsecp256k1zkp_v0_10_0_scalar_mul(&z, &z, &zz); + CHECK(!rustsecp256k1zkp_v0_10_0_scalar_check_overflow(&z)); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&x, &z)); + rustsecp256k1zkp_v0_10_0_scalar_mul(&zz, &zz, &y); + CHECK(!rustsecp256k1zkp_v0_10_0_scalar_check_overflow(&zz)); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&rustsecp256k1zkp_v0_10_0_scalar_one, &zz)); } - rustsecp256k1zkp_v0_8_0_scalar_mul(&z, &x, &x); - CHECK(!rustsecp256k1zkp_v0_8_0_scalar_check_overflow(&z)); - rustsecp256k1zkp_v0_8_0_scalar_sqr(&zz, &x); - CHECK(!rustsecp256k1zkp_v0_8_0_scalar_check_overflow(&zz)); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&zz, &z)); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&r2, &zz)); + rustsecp256k1zkp_v0_10_0_scalar_mul(&z, &x, &x); + rustsecp256k1zkp_v0_10_0_scalar_sqr(&zz, &x); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&zz, &z)); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&r2, &z)); } } } /***** FIELD TESTS *****/ -void random_fe(rustsecp256k1zkp_v0_8_0_fe *x) { - unsigned char bin[32]; - do { - rustsecp256k1zkp_v0_8_0_testrand256(bin); - if (rustsecp256k1zkp_v0_8_0_fe_set_b32(x, bin)) { - return; - } - } while(1); -} - -void random_fe_test(rustsecp256k1zkp_v0_8_0_fe *x) { - unsigned char bin[32]; - do { - rustsecp256k1zkp_v0_8_0_testrand256_test(bin); - if (rustsecp256k1zkp_v0_8_0_fe_set_b32(x, bin)) { - return; - } - } while(1); -} - -void random_fe_non_zero(rustsecp256k1zkp_v0_8_0_fe *nz) { - int tries = 10; - while (--tries >= 0) { - random_fe(nz); - rustsecp256k1zkp_v0_8_0_fe_normalize(nz); - if (!rustsecp256k1zkp_v0_8_0_fe_is_zero(nz)) { - break; - } - } - /* Infinitesimal probability of spurious failure here */ - CHECK(tries >= 0); -} - -void random_fe_non_square(rustsecp256k1zkp_v0_8_0_fe *ns) { - rustsecp256k1zkp_v0_8_0_fe r; +static void random_fe_non_square(rustsecp256k1zkp_v0_10_0_fe *ns) { + rustsecp256k1zkp_v0_10_0_fe r; random_fe_non_zero(ns); - if (rustsecp256k1zkp_v0_8_0_fe_sqrt(&r, ns)) { - rustsecp256k1zkp_v0_8_0_fe_negate(ns, ns, 1); + if (rustsecp256k1zkp_v0_10_0_fe_sqrt(&r, ns)) { + rustsecp256k1zkp_v0_10_0_fe_negate(ns, ns, 1); } } -int check_fe_equal(const rustsecp256k1zkp_v0_8_0_fe *a, const rustsecp256k1zkp_v0_8_0_fe *b) { - rustsecp256k1zkp_v0_8_0_fe an = *a; - rustsecp256k1zkp_v0_8_0_fe bn = *b; - rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&an); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&bn); - return rustsecp256k1zkp_v0_8_0_fe_equal_var(&an, &bn); +static int check_fe_equal(const rustsecp256k1zkp_v0_10_0_fe *a, const rustsecp256k1zkp_v0_10_0_fe *b) { + rustsecp256k1zkp_v0_10_0_fe an = *a; + rustsecp256k1zkp_v0_10_0_fe bn = *b; + rustsecp256k1zkp_v0_10_0_fe_normalize_weak(&an); + return rustsecp256k1zkp_v0_10_0_fe_equal(&an, &bn); } -void run_field_convert(void) { +static void run_field_convert(void) { static const unsigned char b32[32] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x40 }; - static const rustsecp256k1zkp_v0_8_0_fe_storage fes = SECP256K1_FE_STORAGE_CONST( + static const rustsecp256k1zkp_v0_10_0_fe_storage fes = SECP256K1_FE_STORAGE_CONST( 0x00010203UL, 0x04050607UL, 0x11121314UL, 0x15161718UL, 0x22232425UL, 0x26272829UL, 0x33343536UL, 0x37383940UL ); - static const rustsecp256k1zkp_v0_8_0_fe fe = SECP256K1_FE_CONST( + static const rustsecp256k1zkp_v0_10_0_fe fe = SECP256K1_FE_CONST( 0x00010203UL, 0x04050607UL, 0x11121314UL, 0x15161718UL, 0x22232425UL, 0x26272829UL, 0x33343536UL, 0x37383940UL ); - rustsecp256k1zkp_v0_8_0_fe fe2; + rustsecp256k1zkp_v0_10_0_fe fe2; unsigned char b322[32]; - rustsecp256k1zkp_v0_8_0_fe_storage fes2; + rustsecp256k1zkp_v0_10_0_fe_storage fes2; /* Check conversions to fe. */ - CHECK(rustsecp256k1zkp_v0_8_0_fe_set_b32(&fe2, b32)); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&fe, &fe2)); - rustsecp256k1zkp_v0_8_0_fe_from_storage(&fe2, &fes); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&fe, &fe2)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&fe2, b32)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&fe, &fe2)); + rustsecp256k1zkp_v0_10_0_fe_from_storage(&fe2, &fes); + CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&fe, &fe2)); /* Check conversion from fe. */ - rustsecp256k1zkp_v0_8_0_fe_get_b32(b322, &fe); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(b322, b32, 32) == 0); - rustsecp256k1zkp_v0_8_0_fe_to_storage(&fes2, &fe); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&fes2, &fes, sizeof(fes)) == 0); + rustsecp256k1zkp_v0_10_0_fe_get_b32(b322, &fe); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(b322, b32, 32) == 0); + rustsecp256k1zkp_v0_10_0_fe_to_storage(&fes2, &fe); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&fes2, &fes, sizeof(fes)) == 0); +} + +static void run_field_be32_overflow(void) { + { + static const unsigned char zero_overflow[32] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFC, 0x2F, + }; + static const unsigned char zero[32] = { 0x00 }; + unsigned char out[32]; + rustsecp256k1zkp_v0_10_0_fe fe; + CHECK(rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&fe, zero_overflow) == 0); + rustsecp256k1zkp_v0_10_0_fe_set_b32_mod(&fe, zero_overflow); + CHECK(rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero(&fe) == 1); + rustsecp256k1zkp_v0_10_0_fe_normalize(&fe); + CHECK(rustsecp256k1zkp_v0_10_0_fe_is_zero(&fe) == 1); + rustsecp256k1zkp_v0_10_0_fe_get_b32(out, &fe); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(out, zero, 32) == 0); + } + { + static const unsigned char one_overflow[32] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFC, 0x30, + }; + static const unsigned char one[32] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + }; + unsigned char out[32]; + rustsecp256k1zkp_v0_10_0_fe fe; + CHECK(rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&fe, one_overflow) == 0); + rustsecp256k1zkp_v0_10_0_fe_set_b32_mod(&fe, one_overflow); + rustsecp256k1zkp_v0_10_0_fe_normalize(&fe); + CHECK(rustsecp256k1zkp_v0_10_0_fe_cmp_var(&fe, &rustsecp256k1zkp_v0_10_0_fe_one) == 0); + rustsecp256k1zkp_v0_10_0_fe_get_b32(out, &fe); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(out, one, 32) == 0); + } + { + static const unsigned char ff_overflow[32] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + }; + static const unsigned char ff[32] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x03, 0xD0, + }; + unsigned char out[32]; + rustsecp256k1zkp_v0_10_0_fe fe; + const rustsecp256k1zkp_v0_10_0_fe fe_ff = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0x01, 0x000003d0); + CHECK(rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(&fe, ff_overflow) == 0); + rustsecp256k1zkp_v0_10_0_fe_set_b32_mod(&fe, ff_overflow); + rustsecp256k1zkp_v0_10_0_fe_normalize(&fe); + CHECK(rustsecp256k1zkp_v0_10_0_fe_cmp_var(&fe, &fe_ff) == 0); + rustsecp256k1zkp_v0_10_0_fe_get_b32(out, &fe); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(out, ff, 32) == 0); + } } /* Returns true if two field elements have the same representation. */ -int fe_identical(const rustsecp256k1zkp_v0_8_0_fe *a, const rustsecp256k1zkp_v0_8_0_fe *b) { +static int fe_identical(const rustsecp256k1zkp_v0_10_0_fe *a, const rustsecp256k1zkp_v0_10_0_fe *b) { int ret = 1; -#ifdef VERIFY - ret &= (a->magnitude == b->magnitude); - ret &= (a->normalized == b->normalized); -#endif /* Compare the struct member that holds the limbs. */ - ret &= (rustsecp256k1zkp_v0_8_0_memcmp_var(a->n, b->n, sizeof(a->n)) == 0); + ret &= (rustsecp256k1zkp_v0_10_0_memcmp_var(a->n, b->n, sizeof(a->n)) == 0); return ret; } -void run_field_half(void) { - rustsecp256k1zkp_v0_8_0_fe t, u; +static void run_field_half(void) { + rustsecp256k1zkp_v0_10_0_fe t, u; int m; /* Check magnitude 0 input */ - rustsecp256k1zkp_v0_8_0_fe_get_bounds(&t, 0); - rustsecp256k1zkp_v0_8_0_fe_half(&t); + rustsecp256k1zkp_v0_10_0_fe_get_bounds(&t, 0); + rustsecp256k1zkp_v0_10_0_fe_half(&t); #ifdef VERIFY CHECK(t.magnitude == 1); CHECK(t.normalized == 0); #endif - CHECK(rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero(&t)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero(&t)); /* Check non-zero magnitudes in the supported range */ for (m = 1; m < 32; m++) { /* Check max-value input */ - rustsecp256k1zkp_v0_8_0_fe_get_bounds(&t, m); + rustsecp256k1zkp_v0_10_0_fe_get_bounds(&t, m); u = t; - rustsecp256k1zkp_v0_8_0_fe_half(&u); + rustsecp256k1zkp_v0_10_0_fe_half(&u); #ifdef VERIFY CHECK(u.magnitude == (m >> 1) + 1); CHECK(u.normalized == 0); #endif - rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&u); - rustsecp256k1zkp_v0_8_0_fe_add(&u, &u); + rustsecp256k1zkp_v0_10_0_fe_normalize_weak(&u); + rustsecp256k1zkp_v0_10_0_fe_add(&u, &u); CHECK(check_fe_equal(&t, &u)); /* Check worst-case input: ensure the LSB is 1 so that P will be added, * which will also cause all carries to be 1, since all limbs that can * generate a carry are initially even and all limbs of P are odd in * every existing field implementation. */ - rustsecp256k1zkp_v0_8_0_fe_get_bounds(&t, m); + rustsecp256k1zkp_v0_10_0_fe_get_bounds(&t, m); CHECK(t.n[0] > 0); CHECK((t.n[0] & 1) == 0); --t.n[0]; u = t; - rustsecp256k1zkp_v0_8_0_fe_half(&u); + rustsecp256k1zkp_v0_10_0_fe_half(&u); #ifdef VERIFY CHECK(u.magnitude == (m >> 1) + 1); CHECK(u.normalized == 0); #endif - rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&u); - rustsecp256k1zkp_v0_8_0_fe_add(&u, &u); + rustsecp256k1zkp_v0_10_0_fe_normalize_weak(&u); + rustsecp256k1zkp_v0_10_0_fe_add(&u, &u); CHECK(check_fe_equal(&t, &u)); } } -void run_field_misc(void) { - rustsecp256k1zkp_v0_8_0_fe x; - rustsecp256k1zkp_v0_8_0_fe y; - rustsecp256k1zkp_v0_8_0_fe z; - rustsecp256k1zkp_v0_8_0_fe q; - rustsecp256k1zkp_v0_8_0_fe fe5 = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 5); +static void run_field_misc(void) { + rustsecp256k1zkp_v0_10_0_fe x; + rustsecp256k1zkp_v0_10_0_fe y; + rustsecp256k1zkp_v0_10_0_fe z; + rustsecp256k1zkp_v0_10_0_fe q; + int v; + rustsecp256k1zkp_v0_10_0_fe fe5 = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 5); int i, j; - for (i = 0; i < 1000 * count; i++) { - rustsecp256k1zkp_v0_8_0_fe_storage xs, ys, zs; + for (i = 0; i < 1000 * COUNT; i++) { + rustsecp256k1zkp_v0_10_0_fe_storage xs, ys, zs; if (i & 1) { random_fe(&x); } else { random_fe_test(&x); } random_fe_non_zero(&y); + v = rustsecp256k1zkp_v0_10_0_testrand_bits(15); + /* Test that fe_add_int is equivalent to fe_set_int + fe_add. */ + rustsecp256k1zkp_v0_10_0_fe_set_int(&q, v); /* q = v */ + z = x; /* z = x */ + rustsecp256k1zkp_v0_10_0_fe_add(&z, &q); /* z = x+v */ + q = x; /* q = x */ + rustsecp256k1zkp_v0_10_0_fe_add_int(&q, v); /* q = x+v */ + CHECK(check_fe_equal(&q, &z)); /* Test the fe equality and comparison operations. */ - CHECK(rustsecp256k1zkp_v0_8_0_fe_cmp_var(&x, &x) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&x, &x)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_cmp_var(&x, &x) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&x, &x)); z = x; - rustsecp256k1zkp_v0_8_0_fe_add(&z,&y); + rustsecp256k1zkp_v0_10_0_fe_add(&z,&y); /* Test fe conditional move; z is not normalized here. */ q = x; - rustsecp256k1zkp_v0_8_0_fe_cmov(&x, &z, 0); + rustsecp256k1zkp_v0_10_0_fe_cmov(&x, &z, 0); #ifdef VERIFY - CHECK(x.normalized && x.magnitude == 1); + CHECK(!x.normalized); + CHECK((x.magnitude == q.magnitude) || (x.magnitude == z.magnitude)); + CHECK((x.magnitude >= q.magnitude) && (x.magnitude >= z.magnitude)); #endif - rustsecp256k1zkp_v0_8_0_fe_cmov(&x, &x, 1); + x = q; + rustsecp256k1zkp_v0_10_0_fe_cmov(&x, &x, 1); CHECK(!fe_identical(&x, &z)); CHECK(fe_identical(&x, &q)); - rustsecp256k1zkp_v0_8_0_fe_cmov(&q, &z, 1); + rustsecp256k1zkp_v0_10_0_fe_cmov(&q, &z, 1); #ifdef VERIFY - CHECK(!q.normalized && q.magnitude == z.magnitude); + CHECK(!q.normalized); + CHECK((q.magnitude == x.magnitude) || (q.magnitude == z.magnitude)); + CHECK((q.magnitude >= x.magnitude) && (q.magnitude >= z.magnitude)); #endif CHECK(fe_identical(&q, &z)); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&x); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&z); - CHECK(!rustsecp256k1zkp_v0_8_0_fe_equal_var(&x, &z)); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&q); - rustsecp256k1zkp_v0_8_0_fe_cmov(&q, &z, (i&1)); + q = z; + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&x); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&z); + CHECK(!rustsecp256k1zkp_v0_10_0_fe_equal(&x, &z)); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&q); + rustsecp256k1zkp_v0_10_0_fe_cmov(&q, &z, (i&1)); #ifdef VERIFY CHECK(q.normalized && q.magnitude == 1); #endif for (j = 0; j < 6; j++) { - rustsecp256k1zkp_v0_8_0_fe_negate(&z, &z, j+1); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&q); - rustsecp256k1zkp_v0_8_0_fe_cmov(&q, &z, (j&1)); + rustsecp256k1zkp_v0_10_0_fe_negate_unchecked(&z, &z, j+1); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&q); + rustsecp256k1zkp_v0_10_0_fe_cmov(&q, &z, (j&1)); #ifdef VERIFY - CHECK((q.normalized != (j&1)) && q.magnitude == ((j&1) ? z.magnitude : 1)); + CHECK(!q.normalized && q.magnitude == z.magnitude); #endif } - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&z); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&z); /* Test storage conversion and conditional moves. */ - rustsecp256k1zkp_v0_8_0_fe_to_storage(&xs, &x); - rustsecp256k1zkp_v0_8_0_fe_to_storage(&ys, &y); - rustsecp256k1zkp_v0_8_0_fe_to_storage(&zs, &z); - rustsecp256k1zkp_v0_8_0_fe_storage_cmov(&zs, &xs, 0); - rustsecp256k1zkp_v0_8_0_fe_storage_cmov(&zs, &zs, 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&xs, &zs, sizeof(xs)) != 0); - rustsecp256k1zkp_v0_8_0_fe_storage_cmov(&ys, &xs, 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&xs, &ys, sizeof(xs)) == 0); - rustsecp256k1zkp_v0_8_0_fe_from_storage(&x, &xs); - rustsecp256k1zkp_v0_8_0_fe_from_storage(&y, &ys); - rustsecp256k1zkp_v0_8_0_fe_from_storage(&z, &zs); + rustsecp256k1zkp_v0_10_0_fe_to_storage(&xs, &x); + rustsecp256k1zkp_v0_10_0_fe_to_storage(&ys, &y); + rustsecp256k1zkp_v0_10_0_fe_to_storage(&zs, &z); + rustsecp256k1zkp_v0_10_0_fe_storage_cmov(&zs, &xs, 0); + rustsecp256k1zkp_v0_10_0_fe_storage_cmov(&zs, &zs, 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&xs, &zs, sizeof(xs)) != 0); + rustsecp256k1zkp_v0_10_0_fe_storage_cmov(&ys, &xs, 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&xs, &ys, sizeof(xs)) == 0); + rustsecp256k1zkp_v0_10_0_fe_from_storage(&x, &xs); + rustsecp256k1zkp_v0_10_0_fe_from_storage(&y, &ys); + rustsecp256k1zkp_v0_10_0_fe_from_storage(&z, &zs); /* Test that mul_int, mul, and add agree. */ - rustsecp256k1zkp_v0_8_0_fe_add(&y, &x); - rustsecp256k1zkp_v0_8_0_fe_add(&y, &x); + rustsecp256k1zkp_v0_10_0_fe_add(&y, &x); + rustsecp256k1zkp_v0_10_0_fe_add(&y, &x); z = x; - rustsecp256k1zkp_v0_8_0_fe_mul_int(&z, 3); + rustsecp256k1zkp_v0_10_0_fe_mul_int(&z, 3); CHECK(check_fe_equal(&y, &z)); - rustsecp256k1zkp_v0_8_0_fe_add(&y, &x); - rustsecp256k1zkp_v0_8_0_fe_add(&z, &x); + rustsecp256k1zkp_v0_10_0_fe_add(&y, &x); + rustsecp256k1zkp_v0_10_0_fe_add(&z, &x); CHECK(check_fe_equal(&z, &y)); z = x; - rustsecp256k1zkp_v0_8_0_fe_mul_int(&z, 5); - rustsecp256k1zkp_v0_8_0_fe_mul(&q, &x, &fe5); + rustsecp256k1zkp_v0_10_0_fe_mul_int(&z, 5); + rustsecp256k1zkp_v0_10_0_fe_mul(&q, &x, &fe5); CHECK(check_fe_equal(&z, &q)); - rustsecp256k1zkp_v0_8_0_fe_negate(&x, &x, 1); - rustsecp256k1zkp_v0_8_0_fe_add(&z, &x); - rustsecp256k1zkp_v0_8_0_fe_add(&q, &x); + rustsecp256k1zkp_v0_10_0_fe_negate(&x, &x, 1); + rustsecp256k1zkp_v0_10_0_fe_add(&z, &x); + rustsecp256k1zkp_v0_10_0_fe_add(&q, &x); CHECK(check_fe_equal(&y, &z)); CHECK(check_fe_equal(&q, &y)); - /* Check rustsecp256k1zkp_v0_8_0_fe_half. */ + /* Check rustsecp256k1zkp_v0_10_0_fe_half. */ z = x; - rustsecp256k1zkp_v0_8_0_fe_half(&z); - rustsecp256k1zkp_v0_8_0_fe_add(&z, &z); + rustsecp256k1zkp_v0_10_0_fe_half(&z); + rustsecp256k1zkp_v0_10_0_fe_add(&z, &z); CHECK(check_fe_equal(&x, &z)); - rustsecp256k1zkp_v0_8_0_fe_add(&z, &z); - rustsecp256k1zkp_v0_8_0_fe_half(&z); + rustsecp256k1zkp_v0_10_0_fe_add(&z, &z); + rustsecp256k1zkp_v0_10_0_fe_half(&z); CHECK(check_fe_equal(&x, &z)); } } -void test_fe_mul(const rustsecp256k1zkp_v0_8_0_fe* a, const rustsecp256k1zkp_v0_8_0_fe* b, int use_sqr) +static void test_fe_mul(const rustsecp256k1zkp_v0_10_0_fe* a, const rustsecp256k1zkp_v0_10_0_fe* b, int use_sqr) { - rustsecp256k1zkp_v0_8_0_fe c, an, bn; + rustsecp256k1zkp_v0_10_0_fe c, an, bn; /* Variables in BE 32-byte format. */ unsigned char a32[32], b32[32], c32[32]; /* Variables in LE 16x uint16_t format. */ @@ -2923,20 +3298,20 @@ void test_fe_mul(const rustsecp256k1zkp_v0_8_0_fe* a, const rustsecp256k1zkp_v0_ /* Compute C = A * B in fe format. */ c = *a; if (use_sqr) { - rustsecp256k1zkp_v0_8_0_fe_sqr(&c, &c); + rustsecp256k1zkp_v0_10_0_fe_sqr(&c, &c); } else { - rustsecp256k1zkp_v0_8_0_fe_mul(&c, &c, b); + rustsecp256k1zkp_v0_10_0_fe_mul(&c, &c, b); } /* Convert A, B, C into LE 16x uint16_t format. */ an = *a; bn = *b; - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&c); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&an); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&bn); - rustsecp256k1zkp_v0_8_0_fe_get_b32(a32, &an); - rustsecp256k1zkp_v0_8_0_fe_get_b32(b32, &bn); - rustsecp256k1zkp_v0_8_0_fe_get_b32(c32, &c); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&c); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&an); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&bn); + rustsecp256k1zkp_v0_10_0_fe_get_b32(a32, &an); + rustsecp256k1zkp_v0_10_0_fe_get_b32(b32, &bn); + rustsecp256k1zkp_v0_10_0_fe_get_b32(c32, &c); for (i = 0; i < 16; ++i) { a16[i] = a32[31 - 2*i] + ((uint16_t)a32[30 - 2*i] << 8); b16[i] = b32[31 - 2*i] + ((uint16_t)b32[30 - 2*i] << 8); @@ -2945,21 +3320,21 @@ void test_fe_mul(const rustsecp256k1zkp_v0_8_0_fe* a, const rustsecp256k1zkp_v0_ /* Compute T = A * B in LE 16x uint16_t format. */ mulmod256(t16, a16, b16, m16); /* Compare */ - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(t16, c16, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(t16, c16, 32) == 0); } -void run_fe_mul(void) { +static void run_fe_mul(void) { int i; - for (i = 0; i < 100 * count; ++i) { - rustsecp256k1zkp_v0_8_0_fe a, b, c, d; + for (i = 0; i < 100 * COUNT; ++i) { + rustsecp256k1zkp_v0_10_0_fe a, b, c, d; random_fe(&a); - random_field_element_magnitude(&a); + random_fe_magnitude(&a); random_fe(&b); - random_field_element_magnitude(&b); + random_fe_magnitude(&b); random_fe_test(&c); - random_field_element_magnitude(&c); + random_fe_magnitude(&c); random_fe_test(&d); - random_field_element_magnitude(&d); + random_fe_magnitude(&d); test_fe_mul(&a, &a, 1); test_fe_mul(&c, &c, 1); test_fe_mul(&a, &b, 0); @@ -2969,51 +3344,51 @@ void run_fe_mul(void) { } } -void run_sqr(void) { - rustsecp256k1zkp_v0_8_0_fe x, s; +static void run_sqr(void) { + rustsecp256k1zkp_v0_10_0_fe x, s; { int i; - rustsecp256k1zkp_v0_8_0_fe_set_int(&x, 1); - rustsecp256k1zkp_v0_8_0_fe_negate(&x, &x, 1); + rustsecp256k1zkp_v0_10_0_fe_set_int(&x, 1); + rustsecp256k1zkp_v0_10_0_fe_negate(&x, &x, 1); for (i = 1; i <= 512; ++i) { - rustsecp256k1zkp_v0_8_0_fe_mul_int(&x, 2); - rustsecp256k1zkp_v0_8_0_fe_normalize(&x); - rustsecp256k1zkp_v0_8_0_fe_sqr(&s, &x); + rustsecp256k1zkp_v0_10_0_fe_mul_int(&x, 2); + rustsecp256k1zkp_v0_10_0_fe_normalize(&x); + rustsecp256k1zkp_v0_10_0_fe_sqr(&s, &x); } } } -void test_sqrt(const rustsecp256k1zkp_v0_8_0_fe *a, const rustsecp256k1zkp_v0_8_0_fe *k) { - rustsecp256k1zkp_v0_8_0_fe r1, r2; - int v = rustsecp256k1zkp_v0_8_0_fe_sqrt(&r1, a); +static void test_sqrt(const rustsecp256k1zkp_v0_10_0_fe *a, const rustsecp256k1zkp_v0_10_0_fe *k) { + rustsecp256k1zkp_v0_10_0_fe r1, r2; + int v = rustsecp256k1zkp_v0_10_0_fe_sqrt(&r1, a); CHECK((v == 0) == (k == NULL)); if (k != NULL) { /* Check that the returned root is +/- the given known answer */ - rustsecp256k1zkp_v0_8_0_fe_negate(&r2, &r1, 1); - rustsecp256k1zkp_v0_8_0_fe_add(&r1, k); rustsecp256k1zkp_v0_8_0_fe_add(&r2, k); - rustsecp256k1zkp_v0_8_0_fe_normalize(&r1); rustsecp256k1zkp_v0_8_0_fe_normalize(&r2); - CHECK(rustsecp256k1zkp_v0_8_0_fe_is_zero(&r1) || rustsecp256k1zkp_v0_8_0_fe_is_zero(&r2)); + rustsecp256k1zkp_v0_10_0_fe_negate(&r2, &r1, 1); + rustsecp256k1zkp_v0_10_0_fe_add(&r1, k); rustsecp256k1zkp_v0_10_0_fe_add(&r2, k); + rustsecp256k1zkp_v0_10_0_fe_normalize(&r1); rustsecp256k1zkp_v0_10_0_fe_normalize(&r2); + CHECK(rustsecp256k1zkp_v0_10_0_fe_is_zero(&r1) || rustsecp256k1zkp_v0_10_0_fe_is_zero(&r2)); } } -void run_sqrt(void) { - rustsecp256k1zkp_v0_8_0_fe ns, x, s, t; +static void run_sqrt(void) { + rustsecp256k1zkp_v0_10_0_fe ns, x, s, t; int i; /* Check sqrt(0) is 0 */ - rustsecp256k1zkp_v0_8_0_fe_set_int(&x, 0); - rustsecp256k1zkp_v0_8_0_fe_sqr(&s, &x); + rustsecp256k1zkp_v0_10_0_fe_set_int(&x, 0); + rustsecp256k1zkp_v0_10_0_fe_sqr(&s, &x); test_sqrt(&s, &x); /* Check sqrt of small squares (and their negatives) */ for (i = 1; i <= 100; i++) { - rustsecp256k1zkp_v0_8_0_fe_set_int(&x, i); - rustsecp256k1zkp_v0_8_0_fe_sqr(&s, &x); + rustsecp256k1zkp_v0_10_0_fe_set_int(&x, i); + rustsecp256k1zkp_v0_10_0_fe_sqr(&s, &x); test_sqrt(&s, &x); - rustsecp256k1zkp_v0_8_0_fe_negate(&t, &s, 1); + rustsecp256k1zkp_v0_10_0_fe_negate(&t, &s, 1); test_sqrt(&t, NULL); } @@ -3021,13 +3396,15 @@ void run_sqrt(void) { for (i = 0; i < 10; i++) { int j; random_fe_non_square(&ns); - for (j = 0; j < count; j++) { + for (j = 0; j < COUNT; j++) { random_fe(&x); - rustsecp256k1zkp_v0_8_0_fe_sqr(&s, &x); + rustsecp256k1zkp_v0_10_0_fe_sqr(&s, &x); + CHECK(rustsecp256k1zkp_v0_10_0_fe_is_square_var(&s)); test_sqrt(&s, &x); - rustsecp256k1zkp_v0_8_0_fe_negate(&t, &s, 1); + rustsecp256k1zkp_v0_10_0_fe_negate(&t, &s, 1); + CHECK(!rustsecp256k1zkp_v0_10_0_fe_is_square_var(&t)); test_sqrt(&t, NULL); - rustsecp256k1zkp_v0_8_0_fe_mul(&t, &s, &ns); + rustsecp256k1zkp_v0_10_0_fe_mul(&t, &s, &ns); test_sqrt(&t, NULL); } } @@ -3035,12 +3412,12 @@ void run_sqrt(void) { /***** FIELD/SCALAR INVERSE TESTS *****/ -static const rustsecp256k1zkp_v0_8_0_scalar scalar_minus_one = SECP256K1_SCALAR_CONST( +static const rustsecp256k1zkp_v0_10_0_scalar scalar_minus_one = SECP256K1_SCALAR_CONST( 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE, 0xBAAEDCE6, 0xAF48A03B, 0xBFD25E8C, 0xD0364140 ); -static const rustsecp256k1zkp_v0_8_0_fe fe_minus_one = SECP256K1_FE_CONST( +static const rustsecp256k1zkp_v0_10_0_fe fe_minus_one = SECP256K1_FE_CONST( 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFC2E ); @@ -3052,57 +3429,57 @@ static const rustsecp256k1zkp_v0_8_0_fe fe_minus_one = SECP256K1_FE_CONST( * for x!=0 and x!=1: 1/(1/x - 1) + 1 == -1/(x-1) */ -void test_inverse_scalar(rustsecp256k1zkp_v0_8_0_scalar* out, const rustsecp256k1zkp_v0_8_0_scalar* x, int var) +static void test_inverse_scalar(rustsecp256k1zkp_v0_10_0_scalar* out, const rustsecp256k1zkp_v0_10_0_scalar* x, int var) { - rustsecp256k1zkp_v0_8_0_scalar l, r, t; + rustsecp256k1zkp_v0_10_0_scalar l, r, t; - (var ? rustsecp256k1zkp_v0_8_0_scalar_inverse_var : rustsecp256k1zkp_v0_8_0_scalar_inverse)(&l, x); /* l = 1/x */ + (var ? rustsecp256k1zkp_v0_10_0_scalar_inverse_var : rustsecp256k1zkp_v0_10_0_scalar_inverse)(&l, x); /* l = 1/x */ if (out) *out = l; - if (rustsecp256k1zkp_v0_8_0_scalar_is_zero(x)) { - CHECK(rustsecp256k1zkp_v0_8_0_scalar_is_zero(&l)); + if (rustsecp256k1zkp_v0_10_0_scalar_is_zero(x)) { + CHECK(rustsecp256k1zkp_v0_10_0_scalar_is_zero(&l)); return; } - rustsecp256k1zkp_v0_8_0_scalar_mul(&t, x, &l); /* t = x*(1/x) */ - CHECK(rustsecp256k1zkp_v0_8_0_scalar_is_one(&t)); /* x*(1/x) == 1 */ - rustsecp256k1zkp_v0_8_0_scalar_add(&r, x, &scalar_minus_one); /* r = x-1 */ - if (rustsecp256k1zkp_v0_8_0_scalar_is_zero(&r)) return; - (var ? rustsecp256k1zkp_v0_8_0_scalar_inverse_var : rustsecp256k1zkp_v0_8_0_scalar_inverse)(&r, &r); /* r = 1/(x-1) */ - rustsecp256k1zkp_v0_8_0_scalar_add(&l, &scalar_minus_one, &l); /* l = 1/x-1 */ - (var ? rustsecp256k1zkp_v0_8_0_scalar_inverse_var : rustsecp256k1zkp_v0_8_0_scalar_inverse)(&l, &l); /* l = 1/(1/x-1) */ - rustsecp256k1zkp_v0_8_0_scalar_add(&l, &l, &rustsecp256k1zkp_v0_8_0_scalar_one); /* l = 1/(1/x-1)+1 */ - rustsecp256k1zkp_v0_8_0_scalar_add(&l, &r, &l); /* l = 1/(1/x-1)+1 + 1/(x-1) */ - CHECK(rustsecp256k1zkp_v0_8_0_scalar_is_zero(&l)); /* l == 0 */ + rustsecp256k1zkp_v0_10_0_scalar_mul(&t, x, &l); /* t = x*(1/x) */ + CHECK(rustsecp256k1zkp_v0_10_0_scalar_is_one(&t)); /* x*(1/x) == 1 */ + rustsecp256k1zkp_v0_10_0_scalar_add(&r, x, &scalar_minus_one); /* r = x-1 */ + if (rustsecp256k1zkp_v0_10_0_scalar_is_zero(&r)) return; + (var ? rustsecp256k1zkp_v0_10_0_scalar_inverse_var : rustsecp256k1zkp_v0_10_0_scalar_inverse)(&r, &r); /* r = 1/(x-1) */ + rustsecp256k1zkp_v0_10_0_scalar_add(&l, &scalar_minus_one, &l); /* l = 1/x-1 */ + (var ? rustsecp256k1zkp_v0_10_0_scalar_inverse_var : rustsecp256k1zkp_v0_10_0_scalar_inverse)(&l, &l); /* l = 1/(1/x-1) */ + rustsecp256k1zkp_v0_10_0_scalar_add(&l, &l, &rustsecp256k1zkp_v0_10_0_scalar_one); /* l = 1/(1/x-1)+1 */ + rustsecp256k1zkp_v0_10_0_scalar_add(&l, &r, &l); /* l = 1/(1/x-1)+1 + 1/(x-1) */ + CHECK(rustsecp256k1zkp_v0_10_0_scalar_is_zero(&l)); /* l == 0 */ } -void test_inverse_field(rustsecp256k1zkp_v0_8_0_fe* out, const rustsecp256k1zkp_v0_8_0_fe* x, int var) +static void test_inverse_field(rustsecp256k1zkp_v0_10_0_fe* out, const rustsecp256k1zkp_v0_10_0_fe* x, int var) { - rustsecp256k1zkp_v0_8_0_fe l, r, t; + rustsecp256k1zkp_v0_10_0_fe l, r, t; - (var ? rustsecp256k1zkp_v0_8_0_fe_inv_var : rustsecp256k1zkp_v0_8_0_fe_inv)(&l, x) ; /* l = 1/x */ + (var ? rustsecp256k1zkp_v0_10_0_fe_inv_var : rustsecp256k1zkp_v0_10_0_fe_inv)(&l, x) ; /* l = 1/x */ if (out) *out = l; t = *x; /* t = x */ - if (rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero_var(&t)) { - CHECK(rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero(&l)); + if (rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(&t)) { + CHECK(rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero(&l)); return; } - rustsecp256k1zkp_v0_8_0_fe_mul(&t, x, &l); /* t = x*(1/x) */ - rustsecp256k1zkp_v0_8_0_fe_add(&t, &fe_minus_one); /* t = x*(1/x)-1 */ - CHECK(rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero(&t)); /* x*(1/x)-1 == 0 */ + rustsecp256k1zkp_v0_10_0_fe_mul(&t, x, &l); /* t = x*(1/x) */ + rustsecp256k1zkp_v0_10_0_fe_add(&t, &fe_minus_one); /* t = x*(1/x)-1 */ + CHECK(rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero(&t)); /* x*(1/x)-1 == 0 */ r = *x; /* r = x */ - rustsecp256k1zkp_v0_8_0_fe_add(&r, &fe_minus_one); /* r = x-1 */ - if (rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero_var(&r)) return; - (var ? rustsecp256k1zkp_v0_8_0_fe_inv_var : rustsecp256k1zkp_v0_8_0_fe_inv)(&r, &r); /* r = 1/(x-1) */ - rustsecp256k1zkp_v0_8_0_fe_add(&l, &fe_minus_one); /* l = 1/x-1 */ - (var ? rustsecp256k1zkp_v0_8_0_fe_inv_var : rustsecp256k1zkp_v0_8_0_fe_inv)(&l, &l); /* l = 1/(1/x-1) */ - rustsecp256k1zkp_v0_8_0_fe_add(&l, &rustsecp256k1zkp_v0_8_0_fe_one); /* l = 1/(1/x-1)+1 */ - rustsecp256k1zkp_v0_8_0_fe_add(&l, &r); /* l = 1/(1/x-1)+1 + 1/(x-1) */ - CHECK(rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero_var(&l)); /* l == 0 */ + rustsecp256k1zkp_v0_10_0_fe_add(&r, &fe_minus_one); /* r = x-1 */ + if (rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(&r)) return; + (var ? rustsecp256k1zkp_v0_10_0_fe_inv_var : rustsecp256k1zkp_v0_10_0_fe_inv)(&r, &r); /* r = 1/(x-1) */ + rustsecp256k1zkp_v0_10_0_fe_add(&l, &fe_minus_one); /* l = 1/x-1 */ + (var ? rustsecp256k1zkp_v0_10_0_fe_inv_var : rustsecp256k1zkp_v0_10_0_fe_inv)(&l, &l); /* l = 1/(1/x-1) */ + rustsecp256k1zkp_v0_10_0_fe_add_int(&l, 1); /* l = 1/(1/x-1)+1 */ + rustsecp256k1zkp_v0_10_0_fe_add(&l, &r); /* l = 1/(1/x-1)+1 + 1/(x-1) */ + CHECK(rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(&l)); /* l == 0 */ } -void run_inverse_tests(void) +static void run_inverse_tests(void) { /* Fixed test cases for field inverses: pairs of (x, 1/x) mod p. */ - static const rustsecp256k1zkp_v0_8_0_fe fe_cases[][2] = { + static const rustsecp256k1zkp_v0_10_0_fe fe_cases[][2] = { /* 0 */ {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0)}, @@ -3207,7 +3584,7 @@ void run_inverse_tests(void) SECP256K1_FE_CONST(0x9a94b9b5, 0x57eb71ee, 0x4c975b8b, 0xac5262a8, 0x077b0595, 0xe12a6b1f, 0xd728edef, 0x1a6bf956)} }; /* Fixed test cases for scalar inverses: pairs of (x, 1/x) mod n. */ - static const rustsecp256k1zkp_v0_8_0_scalar scalar_cases[][2] = { + static const rustsecp256k1zkp_v0_10_0_scalar scalar_cases[][2] = { /* 0 */ {SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0)}, @@ -3294,8 +3671,8 @@ void run_inverse_tests(void) }; int i, var, testrand; unsigned char b32[32]; - rustsecp256k1zkp_v0_8_0_fe x_fe; - rustsecp256k1zkp_v0_8_0_scalar x_scalar; + rustsecp256k1zkp_v0_10_0_fe x_fe; + rustsecp256k1zkp_v0_10_0_scalar x_scalar; memset(b32, 0, sizeof(b32)); /* Test fixed test cases through test_inverse_{scalar,field}, both ways. */ for (i = 0; (size_t)i < sizeof(fe_cases)/sizeof(fe_cases[0]); ++i) { @@ -3309,23 +3686,23 @@ void run_inverse_tests(void) for (i = 0; (size_t)i < sizeof(scalar_cases)/sizeof(scalar_cases[0]); ++i) { for (var = 0; var <= 1; ++var) { test_inverse_scalar(&x_scalar, &scalar_cases[i][0], var); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&x_scalar, &scalar_cases[i][1])); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&x_scalar, &scalar_cases[i][1])); test_inverse_scalar(&x_scalar, &scalar_cases[i][1], var); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&x_scalar, &scalar_cases[i][0])); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&x_scalar, &scalar_cases[i][0])); } } /* Test inputs 0..999 and their respective negations. */ for (i = 0; i < 1000; ++i) { b32[31] = i & 0xff; b32[30] = (i >> 8) & 0xff; - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&x_scalar, b32, NULL); - rustsecp256k1zkp_v0_8_0_fe_set_b32(&x_fe, b32); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&x_scalar, b32, NULL); + rustsecp256k1zkp_v0_10_0_fe_set_b32_mod(&x_fe, b32); for (var = 0; var <= 1; ++var) { test_inverse_scalar(NULL, &x_scalar, var); test_inverse_field(NULL, &x_fe, var); } - rustsecp256k1zkp_v0_8_0_scalar_negate(&x_scalar, &x_scalar); - rustsecp256k1zkp_v0_8_0_fe_negate(&x_fe, &x_fe, 1); + rustsecp256k1zkp_v0_10_0_scalar_negate(&x_scalar, &x_scalar); + rustsecp256k1zkp_v0_10_0_fe_negate(&x_fe, &x_fe, 1); for (var = 0; var <= 1; ++var) { test_inverse_scalar(NULL, &x_scalar, var); test_inverse_field(NULL, &x_fe, var); @@ -3333,10 +3710,10 @@ void run_inverse_tests(void) } /* test 128*count random inputs; half with testrand256_test, half with testrand256 */ for (testrand = 0; testrand <= 1; ++testrand) { - for (i = 0; i < 64 * count; ++i) { - (testrand ? rustsecp256k1zkp_v0_8_0_testrand256_test : rustsecp256k1zkp_v0_8_0_testrand256)(b32); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&x_scalar, b32, NULL); - rustsecp256k1zkp_v0_8_0_fe_set_b32(&x_fe, b32); + for (i = 0; i < 64 * COUNT; ++i) { + (testrand ? rustsecp256k1zkp_v0_10_0_testrand256_test : rustsecp256k1zkp_v0_10_0_testrand256)(b32); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&x_scalar, b32, NULL); + rustsecp256k1zkp_v0_10_0_fe_set_b32_mod(&x_fe, b32); for (var = 0; var <= 1; ++var) { test_inverse_scalar(NULL, &x_scalar, var); test_inverse_field(NULL, &x_fe, var); @@ -3347,55 +3724,29 @@ void run_inverse_tests(void) /***** GROUP TESTS *****/ -void ge_equals_ge(const rustsecp256k1zkp_v0_8_0_ge *a, const rustsecp256k1zkp_v0_8_0_ge *b) { - CHECK(a->infinity == b->infinity); - if (a->infinity) { - return; - } - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&a->x, &b->x)); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&a->y, &b->y)); -} - /* This compares jacobian points including their Z, not just their geometric meaning. */ -int gej_xyz_equals_gej(const rustsecp256k1zkp_v0_8_0_gej *a, const rustsecp256k1zkp_v0_8_0_gej *b) { - rustsecp256k1zkp_v0_8_0_gej a2; - rustsecp256k1zkp_v0_8_0_gej b2; +static int gej_xyz_equals_gej(const rustsecp256k1zkp_v0_10_0_gej *a, const rustsecp256k1zkp_v0_10_0_gej *b) { + rustsecp256k1zkp_v0_10_0_gej a2; + rustsecp256k1zkp_v0_10_0_gej b2; int ret = 1; ret &= a->infinity == b->infinity; if (ret && !a->infinity) { a2 = *a; b2 = *b; - rustsecp256k1zkp_v0_8_0_fe_normalize(&a2.x); - rustsecp256k1zkp_v0_8_0_fe_normalize(&a2.y); - rustsecp256k1zkp_v0_8_0_fe_normalize(&a2.z); - rustsecp256k1zkp_v0_8_0_fe_normalize(&b2.x); - rustsecp256k1zkp_v0_8_0_fe_normalize(&b2.y); - rustsecp256k1zkp_v0_8_0_fe_normalize(&b2.z); - ret &= rustsecp256k1zkp_v0_8_0_fe_cmp_var(&a2.x, &b2.x) == 0; - ret &= rustsecp256k1zkp_v0_8_0_fe_cmp_var(&a2.y, &b2.y) == 0; - ret &= rustsecp256k1zkp_v0_8_0_fe_cmp_var(&a2.z, &b2.z) == 0; + rustsecp256k1zkp_v0_10_0_fe_normalize(&a2.x); + rustsecp256k1zkp_v0_10_0_fe_normalize(&a2.y); + rustsecp256k1zkp_v0_10_0_fe_normalize(&a2.z); + rustsecp256k1zkp_v0_10_0_fe_normalize(&b2.x); + rustsecp256k1zkp_v0_10_0_fe_normalize(&b2.y); + rustsecp256k1zkp_v0_10_0_fe_normalize(&b2.z); + ret &= rustsecp256k1zkp_v0_10_0_fe_cmp_var(&a2.x, &b2.x) == 0; + ret &= rustsecp256k1zkp_v0_10_0_fe_cmp_var(&a2.y, &b2.y) == 0; + ret &= rustsecp256k1zkp_v0_10_0_fe_cmp_var(&a2.z, &b2.z) == 0; } return ret; } -void ge_equals_gej(const rustsecp256k1zkp_v0_8_0_ge *a, const rustsecp256k1zkp_v0_8_0_gej *b) { - rustsecp256k1zkp_v0_8_0_fe z2s; - rustsecp256k1zkp_v0_8_0_fe u1, u2, s1, s2; - CHECK(a->infinity == b->infinity); - if (a->infinity) { - return; - } - /* Check a.x * b.z^2 == b.x && a.y * b.z^3 == b.y, to avoid inverses. */ - rustsecp256k1zkp_v0_8_0_fe_sqr(&z2s, &b->z); - rustsecp256k1zkp_v0_8_0_fe_mul(&u1, &a->x, &z2s); - u2 = b->x; rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&u2); - rustsecp256k1zkp_v0_8_0_fe_mul(&s1, &a->y, &z2s); rustsecp256k1zkp_v0_8_0_fe_mul(&s1, &s1, &b->z); - s2 = b->y; rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&s2); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&u1, &u2)); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&s1, &s2)); -} - -void test_ge(void) { +static void test_ge(void) { int i, i1; int runs = 6; /* 25 points are used: @@ -3404,230 +3755,264 @@ void test_ge(void) { * negation, and then those two again but with randomized Z coordinate. * - The same is then done for lambda*p1 and lambda^2*p1. */ - rustsecp256k1zkp_v0_8_0_ge *ge = (rustsecp256k1zkp_v0_8_0_ge *)checked_malloc(&ctx->error_callback, sizeof(rustsecp256k1zkp_v0_8_0_ge) * (1 + 4 * runs)); - rustsecp256k1zkp_v0_8_0_gej *gej = (rustsecp256k1zkp_v0_8_0_gej *)checked_malloc(&ctx->error_callback, sizeof(rustsecp256k1zkp_v0_8_0_gej) * (1 + 4 * runs)); - rustsecp256k1zkp_v0_8_0_fe zf; - rustsecp256k1zkp_v0_8_0_fe zfi2, zfi3; - - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&gej[0]); - rustsecp256k1zkp_v0_8_0_ge_clear(&ge[0]); - rustsecp256k1zkp_v0_8_0_ge_set_gej_var(&ge[0], &gej[0]); + rustsecp256k1zkp_v0_10_0_ge *ge = (rustsecp256k1zkp_v0_10_0_ge *)checked_malloc(&CTX->error_callback, sizeof(rustsecp256k1zkp_v0_10_0_ge) * (1 + 4 * runs)); + rustsecp256k1zkp_v0_10_0_gej *gej = (rustsecp256k1zkp_v0_10_0_gej *)checked_malloc(&CTX->error_callback, sizeof(rustsecp256k1zkp_v0_10_0_gej) * (1 + 4 * runs)); + rustsecp256k1zkp_v0_10_0_fe zf, r; + rustsecp256k1zkp_v0_10_0_fe zfi2, zfi3; + + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&gej[0]); + rustsecp256k1zkp_v0_10_0_ge_clear(&ge[0]); + rustsecp256k1zkp_v0_10_0_ge_set_gej_var(&ge[0], &gej[0]); for (i = 0; i < runs; i++) { - int j; - rustsecp256k1zkp_v0_8_0_ge g; + int j, k; + rustsecp256k1zkp_v0_10_0_ge g; random_group_element_test(&g); if (i >= runs - 2) { - rustsecp256k1zkp_v0_8_0_ge_mul_lambda(&g, &ge[1]); + rustsecp256k1zkp_v0_10_0_ge_mul_lambda(&g, &ge[1]); + CHECK(!rustsecp256k1zkp_v0_10_0_ge_eq_var(&g, &ge[1])); } if (i >= runs - 1) { - rustsecp256k1zkp_v0_8_0_ge_mul_lambda(&g, &g); + rustsecp256k1zkp_v0_10_0_ge_mul_lambda(&g, &g); } ge[1 + 4 * i] = g; ge[2 + 4 * i] = g; - rustsecp256k1zkp_v0_8_0_ge_neg(&ge[3 + 4 * i], &g); - rustsecp256k1zkp_v0_8_0_ge_neg(&ge[4 + 4 * i], &g); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&gej[1 + 4 * i], &ge[1 + 4 * i]); + rustsecp256k1zkp_v0_10_0_ge_neg(&ge[3 + 4 * i], &g); + rustsecp256k1zkp_v0_10_0_ge_neg(&ge[4 + 4 * i], &g); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&gej[1 + 4 * i], &ge[1 + 4 * i]); random_group_element_jacobian_test(&gej[2 + 4 * i], &ge[2 + 4 * i]); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&gej[3 + 4 * i], &ge[3 + 4 * i]); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&gej[3 + 4 * i], &ge[3 + 4 * i]); random_group_element_jacobian_test(&gej[4 + 4 * i], &ge[4 + 4 * i]); for (j = 0; j < 4; j++) { - random_field_element_magnitude(&ge[1 + j + 4 * i].x); - random_field_element_magnitude(&ge[1 + j + 4 * i].y); - random_field_element_magnitude(&gej[1 + j + 4 * i].x); - random_field_element_magnitude(&gej[1 + j + 4 * i].y); - random_field_element_magnitude(&gej[1 + j + 4 * i].z); + random_ge_x_magnitude(&ge[1 + j + 4 * i]); + random_ge_y_magnitude(&ge[1 + j + 4 * i]); + random_gej_x_magnitude(&gej[1 + j + 4 * i]); + random_gej_y_magnitude(&gej[1 + j + 4 * i]); + random_gej_z_magnitude(&gej[1 + j + 4 * i]); + } + + for (j = 0; j < 4; ++j) { + for (k = 0; k < 4; ++k) { + int expect_equal = (j >> 1) == (k >> 1); + CHECK(rustsecp256k1zkp_v0_10_0_ge_eq_var(&ge[1 + j + 4 * i], &ge[1 + k + 4 * i]) == expect_equal); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_var(&gej[1 + j + 4 * i], &gej[1 + k + 4 * i]) == expect_equal); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&gej[1 + j + 4 * i], &ge[1 + k + 4 * i]) == expect_equal); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&gej[1 + k + 4 * i], &ge[1 + j + 4 * i]) == expect_equal); + } } } /* Generate random zf, and zfi2 = 1/zf^2, zfi3 = 1/zf^3 */ - do { - random_field_element_test(&zf); - } while(rustsecp256k1zkp_v0_8_0_fe_is_zero(&zf)); - random_field_element_magnitude(&zf); - rustsecp256k1zkp_v0_8_0_fe_inv_var(&zfi3, &zf); - rustsecp256k1zkp_v0_8_0_fe_sqr(&zfi2, &zfi3); - rustsecp256k1zkp_v0_8_0_fe_mul(&zfi3, &zfi3, &zfi2); + random_fe_non_zero_test(&zf); + random_fe_magnitude(&zf); + rustsecp256k1zkp_v0_10_0_fe_inv_var(&zfi3, &zf); + rustsecp256k1zkp_v0_10_0_fe_sqr(&zfi2, &zfi3); + rustsecp256k1zkp_v0_10_0_fe_mul(&zfi3, &zfi3, &zfi2); + + /* Generate random r */ + random_fe_non_zero_test(&r); for (i1 = 0; i1 < 1 + 4 * runs; i1++) { int i2; for (i2 = 0; i2 < 1 + 4 * runs; i2++) { /* Compute reference result using gej + gej (var). */ - rustsecp256k1zkp_v0_8_0_gej refj, resj; - rustsecp256k1zkp_v0_8_0_ge ref; - rustsecp256k1zkp_v0_8_0_fe zr; - rustsecp256k1zkp_v0_8_0_gej_add_var(&refj, &gej[i1], &gej[i2], rustsecp256k1zkp_v0_8_0_gej_is_infinity(&gej[i1]) ? NULL : &zr); + rustsecp256k1zkp_v0_10_0_gej refj, resj; + rustsecp256k1zkp_v0_10_0_ge ref; + rustsecp256k1zkp_v0_10_0_fe zr; + rustsecp256k1zkp_v0_10_0_gej_add_var(&refj, &gej[i1], &gej[i2], rustsecp256k1zkp_v0_10_0_gej_is_infinity(&gej[i1]) ? NULL : &zr); /* Check Z ratio. */ - if (!rustsecp256k1zkp_v0_8_0_gej_is_infinity(&gej[i1]) && !rustsecp256k1zkp_v0_8_0_gej_is_infinity(&refj)) { - rustsecp256k1zkp_v0_8_0_fe zrz; rustsecp256k1zkp_v0_8_0_fe_mul(&zrz, &zr, &gej[i1].z); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&zrz, &refj.z)); + if (!rustsecp256k1zkp_v0_10_0_gej_is_infinity(&gej[i1]) && !rustsecp256k1zkp_v0_10_0_gej_is_infinity(&refj)) { + rustsecp256k1zkp_v0_10_0_fe zrz; rustsecp256k1zkp_v0_10_0_fe_mul(&zrz, &zr, &gej[i1].z); + CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&zrz, &refj.z)); } - rustsecp256k1zkp_v0_8_0_ge_set_gej_var(&ref, &refj); + rustsecp256k1zkp_v0_10_0_ge_set_gej_var(&ref, &refj); /* Test gej + ge with Z ratio result (var). */ - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&resj, &gej[i1], &ge[i2], rustsecp256k1zkp_v0_8_0_gej_is_infinity(&gej[i1]) ? NULL : &zr); - ge_equals_gej(&ref, &resj); - if (!rustsecp256k1zkp_v0_8_0_gej_is_infinity(&gej[i1]) && !rustsecp256k1zkp_v0_8_0_gej_is_infinity(&resj)) { - rustsecp256k1zkp_v0_8_0_fe zrz; rustsecp256k1zkp_v0_8_0_fe_mul(&zrz, &zr, &gej[i1].z); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&zrz, &resj.z)); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&resj, &gej[i1], &ge[i2], rustsecp256k1zkp_v0_10_0_gej_is_infinity(&gej[i1]) ? NULL : &zr); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&resj, &ref)); + if (!rustsecp256k1zkp_v0_10_0_gej_is_infinity(&gej[i1]) && !rustsecp256k1zkp_v0_10_0_gej_is_infinity(&resj)) { + rustsecp256k1zkp_v0_10_0_fe zrz; rustsecp256k1zkp_v0_10_0_fe_mul(&zrz, &zr, &gej[i1].z); + CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&zrz, &resj.z)); } /* Test gej + ge (var, with additional Z factor). */ { - rustsecp256k1zkp_v0_8_0_ge ge2_zfi = ge[i2]; /* the second term with x and y rescaled for z = 1/zf */ - rustsecp256k1zkp_v0_8_0_fe_mul(&ge2_zfi.x, &ge2_zfi.x, &zfi2); - rustsecp256k1zkp_v0_8_0_fe_mul(&ge2_zfi.y, &ge2_zfi.y, &zfi3); - random_field_element_magnitude(&ge2_zfi.x); - random_field_element_magnitude(&ge2_zfi.y); - rustsecp256k1zkp_v0_8_0_gej_add_zinv_var(&resj, &gej[i1], &ge2_zfi, &zf); - ge_equals_gej(&ref, &resj); + rustsecp256k1zkp_v0_10_0_ge ge2_zfi = ge[i2]; /* the second term with x and y rescaled for z = 1/zf */ + rustsecp256k1zkp_v0_10_0_fe_mul(&ge2_zfi.x, &ge2_zfi.x, &zfi2); + rustsecp256k1zkp_v0_10_0_fe_mul(&ge2_zfi.y, &ge2_zfi.y, &zfi3); + random_ge_x_magnitude(&ge2_zfi); + random_ge_y_magnitude(&ge2_zfi); + rustsecp256k1zkp_v0_10_0_gej_add_zinv_var(&resj, &gej[i1], &ge2_zfi, &zf); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&resj, &ref)); } /* Test gej + ge (const). */ if (i2 != 0) { - /* rustsecp256k1zkp_v0_8_0_gej_add_ge does not support its second argument being infinity. */ - rustsecp256k1zkp_v0_8_0_gej_add_ge(&resj, &gej[i1], &ge[i2]); - ge_equals_gej(&ref, &resj); + /* rustsecp256k1zkp_v0_10_0_gej_add_ge does not support its second argument being infinity. */ + rustsecp256k1zkp_v0_10_0_gej_add_ge(&resj, &gej[i1], &ge[i2]); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&resj, &ref)); } /* Test doubling (var). */ if ((i1 == 0 && i2 == 0) || ((i1 + 3)/4 == (i2 + 3)/4 && ((i1 + 3)%4)/2 == ((i2 + 3)%4)/2)) { - rustsecp256k1zkp_v0_8_0_fe zr2; + rustsecp256k1zkp_v0_10_0_fe zr2; /* Normal doubling with Z ratio result. */ - rustsecp256k1zkp_v0_8_0_gej_double_var(&resj, &gej[i1], &zr2); - ge_equals_gej(&ref, &resj); + rustsecp256k1zkp_v0_10_0_gej_double_var(&resj, &gej[i1], &zr2); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&resj, &ref)); /* Check Z ratio. */ - rustsecp256k1zkp_v0_8_0_fe_mul(&zr2, &zr2, &gej[i1].z); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&zr2, &resj.z)); + rustsecp256k1zkp_v0_10_0_fe_mul(&zr2, &zr2, &gej[i1].z); + CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&zr2, &resj.z)); /* Normal doubling. */ - rustsecp256k1zkp_v0_8_0_gej_double_var(&resj, &gej[i2], NULL); - ge_equals_gej(&ref, &resj); + rustsecp256k1zkp_v0_10_0_gej_double_var(&resj, &gej[i2], NULL); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&resj, &ref)); /* Constant-time doubling. */ - rustsecp256k1zkp_v0_8_0_gej_double(&resj, &gej[i2]); - ge_equals_gej(&ref, &resj); + rustsecp256k1zkp_v0_10_0_gej_double(&resj, &gej[i2]); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&resj, &ref)); } /* Test adding opposites. */ if ((i1 == 0 && i2 == 0) || ((i1 + 3)/4 == (i2 + 3)/4 && ((i1 + 3)%4)/2 != ((i2 + 3)%4)/2)) { - CHECK(rustsecp256k1zkp_v0_8_0_ge_is_infinity(&ref)); + CHECK(rustsecp256k1zkp_v0_10_0_ge_is_infinity(&ref)); } /* Test adding infinity. */ if (i1 == 0) { - CHECK(rustsecp256k1zkp_v0_8_0_ge_is_infinity(&ge[i1])); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&gej[i1])); - ge_equals_gej(&ref, &gej[i2]); + CHECK(rustsecp256k1zkp_v0_10_0_ge_is_infinity(&ge[i1])); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&gej[i1])); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&gej[i2], &ref)); } if (i2 == 0) { - CHECK(rustsecp256k1zkp_v0_8_0_ge_is_infinity(&ge[i2])); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&gej[i2])); - ge_equals_gej(&ref, &gej[i1]); + CHECK(rustsecp256k1zkp_v0_10_0_ge_is_infinity(&ge[i2])); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&gej[i2])); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&gej[i1], &ref)); } } } /* Test adding all points together in random order equals infinity. */ { - rustsecp256k1zkp_v0_8_0_gej sum = SECP256K1_GEJ_CONST_INFINITY; - rustsecp256k1zkp_v0_8_0_gej *gej_shuffled = (rustsecp256k1zkp_v0_8_0_gej *)checked_malloc(&ctx->error_callback, (4 * runs + 1) * sizeof(rustsecp256k1zkp_v0_8_0_gej)); + rustsecp256k1zkp_v0_10_0_gej sum = SECP256K1_GEJ_CONST_INFINITY; + rustsecp256k1zkp_v0_10_0_gej *gej_shuffled = (rustsecp256k1zkp_v0_10_0_gej *)checked_malloc(&CTX->error_callback, (4 * runs + 1) * sizeof(rustsecp256k1zkp_v0_10_0_gej)); for (i = 0; i < 4 * runs + 1; i++) { gej_shuffled[i] = gej[i]; } for (i = 0; i < 4 * runs + 1; i++) { - int swap = i + rustsecp256k1zkp_v0_8_0_testrand_int(4 * runs + 1 - i); + int swap = i + rustsecp256k1zkp_v0_10_0_testrand_int(4 * runs + 1 - i); if (swap != i) { - rustsecp256k1zkp_v0_8_0_gej t = gej_shuffled[i]; + rustsecp256k1zkp_v0_10_0_gej t = gej_shuffled[i]; gej_shuffled[i] = gej_shuffled[swap]; gej_shuffled[swap] = t; } } for (i = 0; i < 4 * runs + 1; i++) { - rustsecp256k1zkp_v0_8_0_gej_add_var(&sum, &sum, &gej_shuffled[i], NULL); + rustsecp256k1zkp_v0_10_0_gej_add_var(&sum, &sum, &gej_shuffled[i], NULL); } - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&sum)); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&sum)); free(gej_shuffled); } /* Test batch gej -> ge conversion without known z ratios. */ { - rustsecp256k1zkp_v0_8_0_ge *ge_set_all = (rustsecp256k1zkp_v0_8_0_ge *)checked_malloc(&ctx->error_callback, (4 * runs + 1) * sizeof(rustsecp256k1zkp_v0_8_0_ge)); - rustsecp256k1zkp_v0_8_0_ge_set_all_gej_var(ge_set_all, gej, 4 * runs + 1); + rustsecp256k1zkp_v0_10_0_ge *ge_set_all = (rustsecp256k1zkp_v0_10_0_ge *)checked_malloc(&CTX->error_callback, (4 * runs + 1) * sizeof(rustsecp256k1zkp_v0_10_0_ge)); + rustsecp256k1zkp_v0_10_0_ge_set_all_gej_var(ge_set_all, gej, 4 * runs + 1); for (i = 0; i < 4 * runs + 1; i++) { - rustsecp256k1zkp_v0_8_0_fe s; + rustsecp256k1zkp_v0_10_0_fe s; random_fe_non_zero(&s); - rustsecp256k1zkp_v0_8_0_gej_rescale(&gej[i], &s); - ge_equals_gej(&ge_set_all[i], &gej[i]); + rustsecp256k1zkp_v0_10_0_gej_rescale(&gej[i], &s); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&gej[i], &ge_set_all[i])); } free(ge_set_all); } + /* Test that all elements have X coordinates on the curve. */ + for (i = 1; i < 4 * runs + 1; i++) { + rustsecp256k1zkp_v0_10_0_fe n; + CHECK(rustsecp256k1zkp_v0_10_0_ge_x_on_curve_var(&ge[i].x)); + /* And the same holds after random rescaling. */ + rustsecp256k1zkp_v0_10_0_fe_mul(&n, &zf, &ge[i].x); + CHECK(rustsecp256k1zkp_v0_10_0_ge_x_frac_on_curve_var(&n, &zf)); + } + + /* Test correspondence of rustsecp256k1zkp_v0_10_0_ge_x{,_frac}_on_curve_var with ge_set_xo. */ + { + rustsecp256k1zkp_v0_10_0_fe n; + rustsecp256k1zkp_v0_10_0_ge q; + int ret_on_curve, ret_frac_on_curve, ret_set_xo; + rustsecp256k1zkp_v0_10_0_fe_mul(&n, &zf, &r); + ret_on_curve = rustsecp256k1zkp_v0_10_0_ge_x_on_curve_var(&r); + ret_frac_on_curve = rustsecp256k1zkp_v0_10_0_ge_x_frac_on_curve_var(&n, &zf); + ret_set_xo = rustsecp256k1zkp_v0_10_0_ge_set_xo_var(&q, &r, 0); + CHECK(ret_on_curve == ret_frac_on_curve); + CHECK(ret_on_curve == ret_set_xo); + if (ret_set_xo) CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&r, &q.x)); + } + /* Test batch gej -> ge conversion with many infinities. */ for (i = 0; i < 4 * runs + 1; i++) { int odd; random_group_element_test(&ge[i]); - odd = rustsecp256k1zkp_v0_8_0_fe_is_odd(&ge[i].x); + odd = rustsecp256k1zkp_v0_10_0_fe_is_odd(&ge[i].x); CHECK(odd == 0 || odd == 1); /* randomly set half the points to infinity */ if (odd == i % 2) { - rustsecp256k1zkp_v0_8_0_ge_set_infinity(&ge[i]); + rustsecp256k1zkp_v0_10_0_ge_set_infinity(&ge[i]); } - rustsecp256k1zkp_v0_8_0_gej_set_ge(&gej[i], &ge[i]); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&gej[i], &ge[i]); } /* batch convert */ - rustsecp256k1zkp_v0_8_0_ge_set_all_gej_var(ge, gej, 4 * runs + 1); + rustsecp256k1zkp_v0_10_0_ge_set_all_gej_var(ge, gej, 4 * runs + 1); /* check result */ for (i = 0; i < 4 * runs + 1; i++) { - ge_equals_gej(&ge[i], &gej[i]); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&gej[i], &ge[i])); } /* Test batch gej -> ge conversion with all infinities. */ for (i = 0; i < 4 * runs + 1; i++) { - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&gej[i]); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&gej[i]); } /* batch convert */ - rustsecp256k1zkp_v0_8_0_ge_set_all_gej_var(ge, gej, 4 * runs + 1); + rustsecp256k1zkp_v0_10_0_ge_set_all_gej_var(ge, gej, 4 * runs + 1); /* check result */ for (i = 0; i < 4 * runs + 1; i++) { - CHECK(rustsecp256k1zkp_v0_8_0_ge_is_infinity(&ge[i])); + CHECK(rustsecp256k1zkp_v0_10_0_ge_is_infinity(&ge[i])); } free(ge); free(gej); } - -void test_intialized_inf(void) { - rustsecp256k1zkp_v0_8_0_ge p; - rustsecp256k1zkp_v0_8_0_gej pj, npj, infj1, infj2, infj3; - rustsecp256k1zkp_v0_8_0_fe zinv; +static void test_intialized_inf(void) { + rustsecp256k1zkp_v0_10_0_ge p; + rustsecp256k1zkp_v0_10_0_gej pj, npj, infj1, infj2, infj3; + rustsecp256k1zkp_v0_10_0_fe zinv; /* Test that adding P+(-P) results in a fully initialized infinity*/ random_group_element_test(&p); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&pj, &p); - rustsecp256k1zkp_v0_8_0_gej_neg(&npj, &pj); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&pj, &p); + rustsecp256k1zkp_v0_10_0_gej_neg(&npj, &pj); - rustsecp256k1zkp_v0_8_0_gej_add_var(&infj1, &pj, &npj, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&infj1)); - CHECK(rustsecp256k1zkp_v0_8_0_fe_is_zero(&infj1.x)); - CHECK(rustsecp256k1zkp_v0_8_0_fe_is_zero(&infj1.y)); - CHECK(rustsecp256k1zkp_v0_8_0_fe_is_zero(&infj1.z)); + rustsecp256k1zkp_v0_10_0_gej_add_var(&infj1, &pj, &npj, NULL); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&infj1)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_is_zero(&infj1.x)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_is_zero(&infj1.y)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_is_zero(&infj1.z)); - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&infj2, &npj, &p, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&infj2)); - CHECK(rustsecp256k1zkp_v0_8_0_fe_is_zero(&infj2.x)); - CHECK(rustsecp256k1zkp_v0_8_0_fe_is_zero(&infj2.y)); - CHECK(rustsecp256k1zkp_v0_8_0_fe_is_zero(&infj2.z)); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&infj2, &npj, &p, NULL); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&infj2)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_is_zero(&infj2.x)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_is_zero(&infj2.y)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_is_zero(&infj2.z)); - rustsecp256k1zkp_v0_8_0_fe_set_int(&zinv, 1); - rustsecp256k1zkp_v0_8_0_gej_add_zinv_var(&infj3, &npj, &p, &zinv); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&infj3)); - CHECK(rustsecp256k1zkp_v0_8_0_fe_is_zero(&infj3.x)); - CHECK(rustsecp256k1zkp_v0_8_0_fe_is_zero(&infj3.y)); - CHECK(rustsecp256k1zkp_v0_8_0_fe_is_zero(&infj3.z)); + rustsecp256k1zkp_v0_10_0_fe_set_int(&zinv, 1); + rustsecp256k1zkp_v0_10_0_gej_add_zinv_var(&infj3, &npj, &p, &zinv); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&infj3)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_is_zero(&infj3.x)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_is_zero(&infj3.y)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_is_zero(&infj3.z)); } -void test_add_neg_y_diff_x(void) { +static void test_add_neg_y_diff_x(void) { /* The point of this test is to check that we can add two points * whose y-coordinates are negatives of each other but whose x * coordinates differ. If the x-coordinates were the same, these @@ -3641,84 +4026,92 @@ void test_add_neg_y_diff_x(void) { * which this test is a regression test for. * * These points were generated in sage as - * # secp256k1 params - * F = FiniteField (0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F) - * C = EllipticCurve ([F (0), F (7)]) - * G = C.lift_x(0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798) - * N = FiniteField(G.order()) * - * # endomorphism values (lambda is 1^{1/3} in N, beta is 1^{1/3} in F) - * x = polygen(N) - * lam = (1 - x^3).roots()[1][0] + * load("rustsecp256k1zkp_v0_10_0_params.sage") * * # random "bad pair" * P = C.random_element() - * Q = -int(lam) * P - * print " P: %x %x" % P.xy() - * print " Q: %x %x" % Q.xy() - * print "P + Q: %x %x" % (P + Q).xy() + * Q = -int(LAMBDA) * P + * print(" P: %x %x" % P.xy()) + * print(" Q: %x %x" % Q.xy()) + * print("P + Q: %x %x" % (P + Q).xy()) */ - rustsecp256k1zkp_v0_8_0_gej aj = SECP256K1_GEJ_CONST( + rustsecp256k1zkp_v0_10_0_gej aj = SECP256K1_GEJ_CONST( 0x8d24cd95, 0x0a355af1, 0x3c543505, 0x44238d30, 0x0643d79f, 0x05a59614, 0x2f8ec030, 0xd58977cb, 0x001e337a, 0x38093dcd, 0x6c0f386d, 0x0b1293a8, 0x4d72c879, 0xd7681924, 0x44e6d2f3, 0x9190117d ); - rustsecp256k1zkp_v0_8_0_gej bj = SECP256K1_GEJ_CONST( + rustsecp256k1zkp_v0_10_0_gej bj = SECP256K1_GEJ_CONST( 0xc7b74206, 0x1f788cd9, 0xabd0937d, 0x164a0d86, 0x95f6ff75, 0xf19a4ce9, 0xd013bd7b, 0xbf92d2a7, 0xffe1cc85, 0xc7f6c232, 0x93f0c792, 0xf4ed6c57, 0xb28d3786, 0x2897e6db, 0xbb192d0b, 0x6e6feab2 ); - rustsecp256k1zkp_v0_8_0_gej sumj = SECP256K1_GEJ_CONST( + rustsecp256k1zkp_v0_10_0_gej sumj = SECP256K1_GEJ_CONST( 0x671a63c0, 0x3efdad4c, 0x389a7798, 0x24356027, 0xb3d69010, 0x278625c3, 0x5c86d390, 0x184a8f7a, 0x5f6409c2, 0x2ce01f2b, 0x511fd375, 0x25071d08, 0xda651801, 0x70e95caf, 0x8f0d893c, 0xbed8fbbe ); - rustsecp256k1zkp_v0_8_0_ge b; - rustsecp256k1zkp_v0_8_0_gej resj; - rustsecp256k1zkp_v0_8_0_ge res; - rustsecp256k1zkp_v0_8_0_ge_set_gej(&b, &bj); + rustsecp256k1zkp_v0_10_0_ge b; + rustsecp256k1zkp_v0_10_0_gej resj; + rustsecp256k1zkp_v0_10_0_ge res; + rustsecp256k1zkp_v0_10_0_ge_set_gej(&b, &bj); - rustsecp256k1zkp_v0_8_0_gej_add_var(&resj, &aj, &bj, NULL); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&res, &resj); - ge_equals_gej(&res, &sumj); + rustsecp256k1zkp_v0_10_0_gej_add_var(&resj, &aj, &bj, NULL); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&res, &resj); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&sumj, &res)); - rustsecp256k1zkp_v0_8_0_gej_add_ge(&resj, &aj, &b); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&res, &resj); - ge_equals_gej(&res, &sumj); + rustsecp256k1zkp_v0_10_0_gej_add_ge(&resj, &aj, &b); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&res, &resj); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&sumj, &res)); - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&resj, &aj, &b, NULL); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&res, &resj); - ge_equals_gej(&res, &sumj); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&resj, &aj, &b, NULL); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&res, &resj); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&sumj, &res)); } -void run_ge(void) { +static void test_ge_bytes(void) { int i; - for (i = 0; i < count * 32; i++) { + + for (i = 0; i < COUNT; i++) { + unsigned char buf[64]; + rustsecp256k1zkp_v0_10_0_ge p, q; + + random_group_element_test(&p); + rustsecp256k1zkp_v0_10_0_ge_to_bytes(buf, &p); + rustsecp256k1zkp_v0_10_0_ge_from_bytes(&q, buf); + CHECK(rustsecp256k1zkp_v0_10_0_ge_eq_var(&p, &q)); + } +} + +static void run_ge(void) { + int i; + for (i = 0; i < COUNT * 32; i++) { test_ge(); } test_add_neg_y_diff_x(); test_intialized_inf(); + test_ge_bytes(); } -void test_gej_cmov(const rustsecp256k1zkp_v0_8_0_gej *a, const rustsecp256k1zkp_v0_8_0_gej *b) { - rustsecp256k1zkp_v0_8_0_gej t = *a; - rustsecp256k1zkp_v0_8_0_gej_cmov(&t, b, 0); +static void test_gej_cmov(const rustsecp256k1zkp_v0_10_0_gej *a, const rustsecp256k1zkp_v0_10_0_gej *b) { + rustsecp256k1zkp_v0_10_0_gej t = *a; + rustsecp256k1zkp_v0_10_0_gej_cmov(&t, b, 0); CHECK(gej_xyz_equals_gej(&t, a)); - rustsecp256k1zkp_v0_8_0_gej_cmov(&t, b, 1); + rustsecp256k1zkp_v0_10_0_gej_cmov(&t, b, 1); CHECK(gej_xyz_equals_gej(&t, b)); } -void run_gej(void) { +static void run_gej(void) { int i; - rustsecp256k1zkp_v0_8_0_gej a, b; + rustsecp256k1zkp_v0_10_0_gej a, b; - /* Tests for rustsecp256k1zkp_v0_8_0_gej_cmov */ - for (i = 0; i < count; i++) { - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&a); - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&b); + /* Tests for rustsecp256k1zkp_v0_10_0_gej_cmov */ + for (i = 0; i < COUNT; i++) { + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&a); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&b); test_gej_cmov(&a, &b); random_gej_test(&a); @@ -3732,143 +4125,156 @@ void run_gej(void) { test_gej_cmov(&a, &b); test_gej_cmov(&b, &a); } + + /* Tests for rustsecp256k1zkp_v0_10_0_gej_eq_var */ + for (i = 0; i < COUNT; i++) { + rustsecp256k1zkp_v0_10_0_fe fe; + random_gej_test(&a); + random_gej_test(&b); + CHECK(!rustsecp256k1zkp_v0_10_0_gej_eq_var(&a, &b)); + + b = a; + random_fe_non_zero_test(&fe); + rustsecp256k1zkp_v0_10_0_gej_rescale(&a, &fe); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_var(&a, &b)); + } } -void test_ec_combine(void) { - rustsecp256k1zkp_v0_8_0_scalar sum = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0); - rustsecp256k1zkp_v0_8_0_pubkey data[6]; - const rustsecp256k1zkp_v0_8_0_pubkey* d[6]; - rustsecp256k1zkp_v0_8_0_pubkey sd; - rustsecp256k1zkp_v0_8_0_pubkey sd2; - rustsecp256k1zkp_v0_8_0_gej Qj; - rustsecp256k1zkp_v0_8_0_ge Q; +static void test_ec_combine(void) { + rustsecp256k1zkp_v0_10_0_scalar sum = rustsecp256k1zkp_v0_10_0_scalar_zero; + rustsecp256k1zkp_v0_10_0_pubkey data[6]; + const rustsecp256k1zkp_v0_10_0_pubkey* d[6]; + rustsecp256k1zkp_v0_10_0_pubkey sd; + rustsecp256k1zkp_v0_10_0_pubkey sd2; + rustsecp256k1zkp_v0_10_0_gej Qj; + rustsecp256k1zkp_v0_10_0_ge Q; int i; for (i = 1; i <= 6; i++) { - rustsecp256k1zkp_v0_8_0_scalar s; + rustsecp256k1zkp_v0_10_0_scalar s; random_scalar_order_test(&s); - rustsecp256k1zkp_v0_8_0_scalar_add(&sum, &sum, &s); - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &Qj, &s); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&Q, &Qj); - rustsecp256k1zkp_v0_8_0_pubkey_save(&data[i - 1], &Q); + rustsecp256k1zkp_v0_10_0_scalar_add(&sum, &sum, &s); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&CTX->ecmult_gen_ctx, &Qj, &s); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&Q, &Qj); + rustsecp256k1zkp_v0_10_0_pubkey_save(&data[i - 1], &Q); d[i - 1] = &data[i - 1]; - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &Qj, &sum); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&Q, &Qj); - rustsecp256k1zkp_v0_8_0_pubkey_save(&sd, &Q); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_combine(ctx, &sd2, d, i) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&sd, &sd2, sizeof(sd)) == 0); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&CTX->ecmult_gen_ctx, &Qj, &sum); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&Q, &Qj); + rustsecp256k1zkp_v0_10_0_pubkey_save(&sd, &Q); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_combine(CTX, &sd2, d, i) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&sd, &sd2, sizeof(sd)) == 0); } } -void run_ec_combine(void) { +static void run_ec_combine(void) { int i; - for (i = 0; i < count * 8; i++) { + for (i = 0; i < COUNT * 8; i++) { test_ec_combine(); } } -void test_ec_commit(void) { - rustsecp256k1zkp_v0_8_0_scalar seckey_s; - rustsecp256k1zkp_v0_8_0_ge pubkey; - rustsecp256k1zkp_v0_8_0_gej pubkeyj; - rustsecp256k1zkp_v0_8_0_ge commitment; +static void test_ec_commit(void) { + rustsecp256k1zkp_v0_10_0_scalar seckey_s; + rustsecp256k1zkp_v0_10_0_ge pubkey; + rustsecp256k1zkp_v0_10_0_gej pubkeyj; + rustsecp256k1zkp_v0_10_0_ge commitment; unsigned char data[32]; - rustsecp256k1zkp_v0_8_0_sha256 sha; + rustsecp256k1zkp_v0_10_0_sha256 sha; /* Create random keypair and data */ random_scalar_order_test(&seckey_s); - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &pubkeyj, &seckey_s); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&pubkey, &pubkeyj); - rustsecp256k1zkp_v0_8_0_testrand256_test(data); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&CTX->ecmult_gen_ctx, &pubkeyj, &seckey_s); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&pubkey, &pubkeyj); + rustsecp256k1zkp_v0_10_0_testrand256_test(data); /* Commit to data and verify */ - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha); - CHECK(rustsecp256k1zkp_v0_8_0_ec_commit(&commitment, &pubkey, &sha, data, 32) == 1); - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha); - CHECK(rustsecp256k1zkp_v0_8_0_ec_commit_verify(&commitment, &pubkey, &sha, data, 32) == 1); - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha); - CHECK(rustsecp256k1zkp_v0_8_0_ec_commit_seckey(&seckey_s, &pubkey, &sha, data, 32) == 1); - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &pubkeyj, &seckey_s); - ge_equals_gej(&commitment, &pubkeyj); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha); + CHECK(rustsecp256k1zkp_v0_10_0_ec_commit(&commitment, &pubkey, &sha, data, 32) == 1); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha); + CHECK(rustsecp256k1zkp_v0_10_0_ec_commit_verify(&commitment, &pubkey, &sha, data, 32) == 1); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha); + CHECK(rustsecp256k1zkp_v0_10_0_ec_commit_seckey(&seckey_s, &pubkey, &sha, data, 32) == 1); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&CTX->ecmult_gen_ctx, &pubkeyj, &seckey_s); + rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&pubkeyj, &commitment); /* Check that verification fails with different data */ - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha); - CHECK(rustsecp256k1zkp_v0_8_0_ec_commit_verify(&commitment, &pubkey, &sha, data, 31) == 0); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha); + CHECK(rustsecp256k1zkp_v0_10_0_ec_commit_verify(&commitment, &pubkey, &sha, data, 31) == 0); /* Check that commmitting fails when the inner pubkey is the point at * infinity */ - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha); - rustsecp256k1zkp_v0_8_0_ge_set_infinity(&pubkey); - CHECK(rustsecp256k1zkp_v0_8_0_ec_commit(&commitment, &pubkey, &sha, data, 32) == 0); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&seckey_s, 0); - CHECK(rustsecp256k1zkp_v0_8_0_ec_commit_seckey(&seckey_s, &pubkey, &sha, data, 32) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ec_commit_verify(&commitment, &pubkey, &sha, data, 32) == 0); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha); + rustsecp256k1zkp_v0_10_0_ge_set_infinity(&pubkey); + CHECK(rustsecp256k1zkp_v0_10_0_ec_commit(&commitment, &pubkey, &sha, data, 32) == 0); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&seckey_s, 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_commit_seckey(&seckey_s, &pubkey, &sha, data, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_commit_verify(&commitment, &pubkey, &sha, data, 32) == 0); } -void test_ec_commit_api(void) { +static void test_ec_commit_api(void) { unsigned char seckey[32]; - rustsecp256k1zkp_v0_8_0_scalar seckey_s; - rustsecp256k1zkp_v0_8_0_ge pubkey; - rustsecp256k1zkp_v0_8_0_gej pubkeyj; - rustsecp256k1zkp_v0_8_0_ge commitment; + rustsecp256k1zkp_v0_10_0_scalar seckey_s; + rustsecp256k1zkp_v0_10_0_ge pubkey; + rustsecp256k1zkp_v0_10_0_gej pubkeyj; + rustsecp256k1zkp_v0_10_0_ge commitment; unsigned char data[32]; - rustsecp256k1zkp_v0_8_0_sha256 sha; + rustsecp256k1zkp_v0_10_0_sha256 sha; memset(data, 23, sizeof(data)); /* Create random keypair */ random_scalar_order_test(&seckey_s); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(seckey, &seckey_s); - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &pubkeyj, &seckey_s); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&pubkey, &pubkeyj); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(seckey, &seckey_s); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&CTX->ecmult_gen_ctx, &pubkeyj, &seckey_s); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&pubkey, &pubkeyj); - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha); - CHECK(rustsecp256k1zkp_v0_8_0_ec_commit(&commitment, &pubkey, &sha, data, 1) == 1); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha); + CHECK(rustsecp256k1zkp_v0_10_0_ec_commit(&commitment, &pubkey, &sha, data, 1) == 1); /* The same pubkey can be both input and output of the function */ { - rustsecp256k1zkp_v0_8_0_ge pubkey_tmp = pubkey; - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha); - CHECK(rustsecp256k1zkp_v0_8_0_ec_commit(&pubkey_tmp, &pubkey_tmp, &sha, data, 1) == 1); - ge_equals_ge(&commitment, &pubkey_tmp); + rustsecp256k1zkp_v0_10_0_ge pubkey_tmp = pubkey; + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha); + CHECK(rustsecp256k1zkp_v0_10_0_ec_commit(&pubkey_tmp, &pubkey_tmp, &sha, data, 1) == 1); + rustsecp256k1zkp_v0_10_0_ge_eq_var(&commitment, &pubkey_tmp); } - rustsecp256k1zkp_v0_8_0_sha256_initialize(&sha); - CHECK(rustsecp256k1zkp_v0_8_0_ec_commit_verify(&commitment, &pubkey, &sha, data, 1) == 1); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&sha); + CHECK(rustsecp256k1zkp_v0_10_0_ec_commit_verify(&commitment, &pubkey, &sha, data, 1) == 1); } -void run_ec_commit(void) { +static void run_ec_commit(void) { int i; - for (i = 0; i < count * 8; i++) { + for (i = 0; i < COUNT * 8; i++) { test_ec_commit(); } test_ec_commit_api(); } -void test_group_decompress(const rustsecp256k1zkp_v0_8_0_fe* x) { +static void test_group_decompress(const rustsecp256k1zkp_v0_10_0_fe* x) { /* The input itself, normalized. */ - rustsecp256k1zkp_v0_8_0_fe fex = *x; - rustsecp256k1zkp_v0_8_0_fe fez; + rustsecp256k1zkp_v0_10_0_fe fex = *x; + rustsecp256k1zkp_v0_10_0_fe fez; /* Results of set_xquad_var, set_xo_var(..., 0), set_xo_var(..., 1). */ - rustsecp256k1zkp_v0_8_0_ge ge_quad, ge_even, ge_odd; - rustsecp256k1zkp_v0_8_0_gej gej_quad; + rustsecp256k1zkp_v0_10_0_ge ge_quad, ge_even, ge_odd; + rustsecp256k1zkp_v0_10_0_gej gej_quad; /* Return values of the above calls. */ int res_quad, res_even, res_odd; - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&fex); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&fex); - res_quad = rustsecp256k1zkp_v0_8_0_ge_set_xquad(&ge_quad, &fex); - res_even = rustsecp256k1zkp_v0_8_0_ge_set_xo_var(&ge_even, &fex, 0); - res_odd = rustsecp256k1zkp_v0_8_0_ge_set_xo_var(&ge_odd, &fex, 1); + res_quad = rustsecp256k1zkp_v0_10_0_ge_set_xquad(&ge_quad, &fex); + res_even = rustsecp256k1zkp_v0_10_0_ge_set_xo_var(&ge_even, &fex, 0); + res_odd = rustsecp256k1zkp_v0_10_0_ge_set_xo_var(&ge_odd, &fex, 1); CHECK(res_quad == res_even); CHECK(res_quad == res_odd); if (res_quad) { - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&ge_quad.x); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&ge_odd.x); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&ge_even.x); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&ge_quad.y); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&ge_odd.y); - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&ge_even.y); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&ge_quad.x); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&ge_odd.x); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&ge_even.x); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&ge_quad.y); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&ge_odd.y); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&ge_even.y); /* No infinity allowed. */ CHECK(!ge_quad.infinity); @@ -3876,41 +4282,41 @@ void test_group_decompress(const rustsecp256k1zkp_v0_8_0_fe* x) { CHECK(!ge_odd.infinity); /* Check that the x coordinates check out. */ - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&ge_quad.x, x)); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&ge_even.x, x)); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&ge_odd.x, x)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&ge_quad.x, x)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&ge_even.x, x)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&ge_odd.x, x)); /* Check that the Y coordinate result in ge_quad is a square. */ - CHECK(rustsecp256k1zkp_v0_8_0_fe_is_quad_var(&ge_quad.y)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_is_square_var(&ge_quad.y)); /* Check odd/even Y in ge_odd, ge_even. */ - CHECK(rustsecp256k1zkp_v0_8_0_fe_is_odd(&ge_odd.y)); - CHECK(!rustsecp256k1zkp_v0_8_0_fe_is_odd(&ge_even.y)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_is_odd(&ge_odd.y)); + CHECK(!rustsecp256k1zkp_v0_10_0_fe_is_odd(&ge_even.y)); - /* Check rustsecp256k1zkp_v0_8_0_gej_has_quad_y_var. */ - rustsecp256k1zkp_v0_8_0_gej_set_ge(&gej_quad, &ge_quad); - CHECK(rustsecp256k1zkp_v0_8_0_gej_has_quad_y_var(&gej_quad)); + /* Check rustsecp256k1zkp_v0_10_0_gej_has_quad_y_var. */ + rustsecp256k1zkp_v0_10_0_gej_set_ge(&gej_quad, &ge_quad); + CHECK(rustsecp256k1zkp_v0_10_0_gej_has_quad_y_var(&gej_quad)); do { random_fe_test(&fez); - } while (rustsecp256k1zkp_v0_8_0_fe_is_zero(&fez)); - rustsecp256k1zkp_v0_8_0_gej_rescale(&gej_quad, &fez); - CHECK(rustsecp256k1zkp_v0_8_0_gej_has_quad_y_var(&gej_quad)); - rustsecp256k1zkp_v0_8_0_gej_neg(&gej_quad, &gej_quad); - CHECK(!rustsecp256k1zkp_v0_8_0_gej_has_quad_y_var(&gej_quad)); + } while (rustsecp256k1zkp_v0_10_0_fe_is_zero(&fez)); + rustsecp256k1zkp_v0_10_0_gej_rescale(&gej_quad, &fez); + CHECK(rustsecp256k1zkp_v0_10_0_gej_has_quad_y_var(&gej_quad)); + rustsecp256k1zkp_v0_10_0_gej_neg(&gej_quad, &gej_quad); + CHECK(!rustsecp256k1zkp_v0_10_0_gej_has_quad_y_var(&gej_quad)); do { random_fe_test(&fez); - } while (rustsecp256k1zkp_v0_8_0_fe_is_zero(&fez)); - rustsecp256k1zkp_v0_8_0_gej_rescale(&gej_quad, &fez); - CHECK(!rustsecp256k1zkp_v0_8_0_gej_has_quad_y_var(&gej_quad)); - rustsecp256k1zkp_v0_8_0_gej_neg(&gej_quad, &gej_quad); - CHECK(rustsecp256k1zkp_v0_8_0_gej_has_quad_y_var(&gej_quad)); + } while (rustsecp256k1zkp_v0_10_0_fe_is_zero(&fez)); + rustsecp256k1zkp_v0_10_0_gej_rescale(&gej_quad, &fez); + CHECK(!rustsecp256k1zkp_v0_10_0_gej_has_quad_y_var(&gej_quad)); + rustsecp256k1zkp_v0_10_0_gej_neg(&gej_quad, &gej_quad); + CHECK(rustsecp256k1zkp_v0_10_0_gej_has_quad_y_var(&gej_quad)); } } -void run_group_decompress(void) { +static void run_group_decompress(void) { int i; - for (i = 0; i < count * 4; i++) { - rustsecp256k1zkp_v0_8_0_fe fe; + for (i = 0; i < COUNT * 4; i++) { + rustsecp256k1zkp_v0_10_0_fe fe; random_fe_test(&fe); test_group_decompress(&fe); } @@ -3918,7 +4324,7 @@ void run_group_decompress(void) { /***** ECMULT TESTS *****/ -void test_pre_g_table(const rustsecp256k1zkp_v0_8_0_ge_storage * pre_g, size_t n) { +static void test_pre_g_table(const rustsecp256k1zkp_v0_10_0_ge_storage * pre_g, size_t n) { /* Tests the pre_g / pre_g_128 tables for consistency. * For independent verification we take a "geometric" approach to verification. * We check that every entry is on-curve. @@ -3929,175 +4335,168 @@ void test_pre_g_table(const rustsecp256k1zkp_v0_8_0_ge_storage * pre_g, size_t n * * Checking the table's generators are correct is done in run_ecmult_pre_g. */ - rustsecp256k1zkp_v0_8_0_gej g2; - rustsecp256k1zkp_v0_8_0_ge p, q, gg; - rustsecp256k1zkp_v0_8_0_fe dpx, dpy, dqx, dqy; + rustsecp256k1zkp_v0_10_0_gej g2; + rustsecp256k1zkp_v0_10_0_ge p, q, gg; + rustsecp256k1zkp_v0_10_0_fe dpx, dpy, dqx, dqy; size_t i; CHECK(0 < n); - rustsecp256k1zkp_v0_8_0_ge_from_storage(&p, &pre_g[0]); - CHECK(rustsecp256k1zkp_v0_8_0_ge_is_valid_var(&p)); + rustsecp256k1zkp_v0_10_0_ge_from_storage(&p, &pre_g[0]); + CHECK(rustsecp256k1zkp_v0_10_0_ge_is_valid_var(&p)); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&g2, &p); - rustsecp256k1zkp_v0_8_0_gej_double_var(&g2, &g2, NULL); - rustsecp256k1zkp_v0_8_0_ge_set_gej_var(&gg, &g2); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&g2, &p); + rustsecp256k1zkp_v0_10_0_gej_double_var(&g2, &g2, NULL); + rustsecp256k1zkp_v0_10_0_ge_set_gej_var(&gg, &g2); for (i = 1; i < n; ++i) { - rustsecp256k1zkp_v0_8_0_fe_negate(&dpx, &p.x, 1); rustsecp256k1zkp_v0_8_0_fe_add(&dpx, &gg.x); rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&dpx); - rustsecp256k1zkp_v0_8_0_fe_negate(&dpy, &p.y, 1); rustsecp256k1zkp_v0_8_0_fe_add(&dpy, &gg.y); rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&dpy); + rustsecp256k1zkp_v0_10_0_fe_negate(&dpx, &p.x, 1); rustsecp256k1zkp_v0_10_0_fe_add(&dpx, &gg.x); rustsecp256k1zkp_v0_10_0_fe_normalize_weak(&dpx); + rustsecp256k1zkp_v0_10_0_fe_negate(&dpy, &p.y, 1); rustsecp256k1zkp_v0_10_0_fe_add(&dpy, &gg.y); rustsecp256k1zkp_v0_10_0_fe_normalize_weak(&dpy); /* Check that p is not equal to gg */ - CHECK(!rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero_var(&dpx) || !rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero_var(&dpy)); + CHECK(!rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(&dpx) || !rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(&dpy)); - rustsecp256k1zkp_v0_8_0_ge_from_storage(&q, &pre_g[i]); - CHECK(rustsecp256k1zkp_v0_8_0_ge_is_valid_var(&q)); + rustsecp256k1zkp_v0_10_0_ge_from_storage(&q, &pre_g[i]); + CHECK(rustsecp256k1zkp_v0_10_0_ge_is_valid_var(&q)); - rustsecp256k1zkp_v0_8_0_fe_negate(&dqx, &q.x, 1); rustsecp256k1zkp_v0_8_0_fe_add(&dqx, &gg.x); rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&dqx); - dqy = q.y; rustsecp256k1zkp_v0_8_0_fe_add(&dqy, &gg.y); rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&dqy); + rustsecp256k1zkp_v0_10_0_fe_negate(&dqx, &q.x, 1); rustsecp256k1zkp_v0_10_0_fe_add(&dqx, &gg.x); + dqy = q.y; rustsecp256k1zkp_v0_10_0_fe_add(&dqy, &gg.y); /* Check that -q is not equal to gg */ - CHECK(!rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero_var(&dqx) || !rustsecp256k1zkp_v0_8_0_fe_normalizes_to_zero_var(&dqy)); + CHECK(!rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(&dqx) || !rustsecp256k1zkp_v0_10_0_fe_normalizes_to_zero_var(&dqy)); /* Check that -q is not equal to p */ - CHECK(!rustsecp256k1zkp_v0_8_0_fe_equal_var(&dpx, &dqx) || !rustsecp256k1zkp_v0_8_0_fe_equal_var(&dpy, &dqy)); + CHECK(!rustsecp256k1zkp_v0_10_0_fe_equal(&dpx, &dqx) || !rustsecp256k1zkp_v0_10_0_fe_equal(&dpy, &dqy)); /* Check that p, -q and gg are colinear */ - rustsecp256k1zkp_v0_8_0_fe_mul(&dpx, &dpx, &dqy); - rustsecp256k1zkp_v0_8_0_fe_mul(&dpy, &dpy, &dqx); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&dpx, &dpy)); + rustsecp256k1zkp_v0_10_0_fe_mul(&dpx, &dpx, &dqy); + rustsecp256k1zkp_v0_10_0_fe_mul(&dpy, &dpy, &dqx); + CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&dpx, &dpy)); p = q; } } -void run_ecmult_pre_g(void) { - rustsecp256k1zkp_v0_8_0_ge_storage gs; - rustsecp256k1zkp_v0_8_0_gej gj; - rustsecp256k1zkp_v0_8_0_ge g; +static void run_ecmult_pre_g(void) { + rustsecp256k1zkp_v0_10_0_ge_storage gs; + rustsecp256k1zkp_v0_10_0_gej gj; + rustsecp256k1zkp_v0_10_0_ge g; size_t i; /* Check that the pre_g and pre_g_128 tables are consistent. */ - test_pre_g_table(rustsecp256k1zkp_v0_8_0_pre_g, ECMULT_TABLE_SIZE(WINDOW_G)); - test_pre_g_table(rustsecp256k1zkp_v0_8_0_pre_g_128, ECMULT_TABLE_SIZE(WINDOW_G)); + test_pre_g_table(rustsecp256k1zkp_v0_10_0_pre_g, ECMULT_TABLE_SIZE(WINDOW_G)); + test_pre_g_table(rustsecp256k1zkp_v0_10_0_pre_g_128, ECMULT_TABLE_SIZE(WINDOW_G)); /* Check the first entry from the pre_g table. */ - rustsecp256k1zkp_v0_8_0_ge_to_storage(&gs, &rustsecp256k1zkp_v0_8_0_ge_const_g); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&gs, &rustsecp256k1zkp_v0_8_0_pre_g[0], sizeof(gs)) == 0); + rustsecp256k1zkp_v0_10_0_ge_to_storage(&gs, &rustsecp256k1zkp_v0_10_0_ge_const_g); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&gs, &rustsecp256k1zkp_v0_10_0_pre_g[0], sizeof(gs)) == 0); /* Check the first entry from the pre_g_128 table. */ - rustsecp256k1zkp_v0_8_0_gej_set_ge(&gj, &rustsecp256k1zkp_v0_8_0_ge_const_g); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&gj, &rustsecp256k1zkp_v0_10_0_ge_const_g); for (i = 0; i < 128; ++i) { - rustsecp256k1zkp_v0_8_0_gej_double_var(&gj, &gj, NULL); + rustsecp256k1zkp_v0_10_0_gej_double_var(&gj, &gj, NULL); } - rustsecp256k1zkp_v0_8_0_ge_set_gej(&g, &gj); - rustsecp256k1zkp_v0_8_0_ge_to_storage(&gs, &g); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&gs, &rustsecp256k1zkp_v0_8_0_pre_g_128[0], sizeof(gs)) == 0); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&g, &gj); + rustsecp256k1zkp_v0_10_0_ge_to_storage(&gs, &g); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&gs, &rustsecp256k1zkp_v0_10_0_pre_g_128[0], sizeof(gs)) == 0); } -void run_ecmult_chain(void) { +static void run_ecmult_chain(void) { /* random starting point A (on the curve) */ - rustsecp256k1zkp_v0_8_0_gej a = SECP256K1_GEJ_CONST( + rustsecp256k1zkp_v0_10_0_gej a = SECP256K1_GEJ_CONST( 0x8b30bbe9, 0xae2a9906, 0x96b22f67, 0x0709dff3, 0x727fd8bc, 0x04d3362c, 0x6c7bf458, 0xe2846004, 0xa357ae91, 0x5c4a6528, 0x1309edf2, 0x0504740f, 0x0eb33439, 0x90216b4f, 0x81063cb6, 0x5f2f7e0f ); /* two random initial factors xn and gn */ - rustsecp256k1zkp_v0_8_0_scalar xn = SECP256K1_SCALAR_CONST( + rustsecp256k1zkp_v0_10_0_scalar xn = SECP256K1_SCALAR_CONST( 0x84cc5452, 0xf7fde1ed, 0xb4d38a8c, 0xe9b1b84c, 0xcef31f14, 0x6e569be9, 0x705d357a, 0x42985407 ); - rustsecp256k1zkp_v0_8_0_scalar gn = SECP256K1_SCALAR_CONST( + rustsecp256k1zkp_v0_10_0_scalar gn = SECP256K1_SCALAR_CONST( 0xa1e58d22, 0x553dcd42, 0xb2398062, 0x5d4c57a9, 0x6e9323d4, 0x2b3152e5, 0xca2c3990, 0xedc7c9de ); /* two small multipliers to be applied to xn and gn in every iteration: */ - static const rustsecp256k1zkp_v0_8_0_scalar xf = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0x1337); - static const rustsecp256k1zkp_v0_8_0_scalar gf = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0x7113); + static const rustsecp256k1zkp_v0_10_0_scalar xf = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0x1337); + static const rustsecp256k1zkp_v0_10_0_scalar gf = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0x7113); /* accumulators with the resulting coefficients to A and G */ - rustsecp256k1zkp_v0_8_0_scalar ae = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 1); - rustsecp256k1zkp_v0_8_0_scalar ge = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0); + rustsecp256k1zkp_v0_10_0_scalar ae = rustsecp256k1zkp_v0_10_0_scalar_one; + rustsecp256k1zkp_v0_10_0_scalar ge = rustsecp256k1zkp_v0_10_0_scalar_zero; /* actual points */ - rustsecp256k1zkp_v0_8_0_gej x; - rustsecp256k1zkp_v0_8_0_gej x2; + rustsecp256k1zkp_v0_10_0_gej x; + rustsecp256k1zkp_v0_10_0_gej x2; int i; /* the point being computed */ x = a; - for (i = 0; i < 200*count; i++) { + for (i = 0; i < 200*COUNT; i++) { /* in each iteration, compute X = xn*X + gn*G; */ - rustsecp256k1zkp_v0_8_0_ecmult(&x, &x, &xn, &gn); + rustsecp256k1zkp_v0_10_0_ecmult(&x, &x, &xn, &gn); /* also compute ae and ge: the actual accumulated factors for A and G */ /* if X was (ae*A+ge*G), xn*X + gn*G results in (xn*ae*A + (xn*ge+gn)*G) */ - rustsecp256k1zkp_v0_8_0_scalar_mul(&ae, &ae, &xn); - rustsecp256k1zkp_v0_8_0_scalar_mul(&ge, &ge, &xn); - rustsecp256k1zkp_v0_8_0_scalar_add(&ge, &ge, &gn); + rustsecp256k1zkp_v0_10_0_scalar_mul(&ae, &ae, &xn); + rustsecp256k1zkp_v0_10_0_scalar_mul(&ge, &ge, &xn); + rustsecp256k1zkp_v0_10_0_scalar_add(&ge, &ge, &gn); /* modify xn and gn */ - rustsecp256k1zkp_v0_8_0_scalar_mul(&xn, &xn, &xf); - rustsecp256k1zkp_v0_8_0_scalar_mul(&gn, &gn, &gf); + rustsecp256k1zkp_v0_10_0_scalar_mul(&xn, &xn, &xf); + rustsecp256k1zkp_v0_10_0_scalar_mul(&gn, &gn, &gf); /* verify */ if (i == 19999) { /* expected result after 19999 iterations */ - rustsecp256k1zkp_v0_8_0_gej rp = SECP256K1_GEJ_CONST( + rustsecp256k1zkp_v0_10_0_gej rp = SECP256K1_GEJ_CONST( 0xD6E96687, 0xF9B10D09, 0x2A6F3543, 0x9D86CEBE, 0xA4535D0D, 0x409F5358, 0x6440BD74, 0xB933E830, 0xB95CBCA2, 0xC77DA786, 0x539BE8FD, 0x53354D2D, 0x3B4F566A, 0xE6580454, 0x07ED6015, 0xEE1B2A88 ); - - rustsecp256k1zkp_v0_8_0_gej_neg(&rp, &rp); - rustsecp256k1zkp_v0_8_0_gej_add_var(&rp, &rp, &x, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&rp)); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_var(&rp, &x)); } } /* redo the computation, but directly with the resulting ae and ge coefficients: */ - rustsecp256k1zkp_v0_8_0_ecmult(&x2, &a, &ae, &ge); - rustsecp256k1zkp_v0_8_0_gej_neg(&x2, &x2); - rustsecp256k1zkp_v0_8_0_gej_add_var(&x2, &x2, &x, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&x2)); + rustsecp256k1zkp_v0_10_0_ecmult(&x2, &a, &ae, &ge); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_var(&x, &x2)); } -void test_point_times_order(const rustsecp256k1zkp_v0_8_0_gej *point) { +static void test_point_times_order(const rustsecp256k1zkp_v0_10_0_gej *point) { /* X * (point + G) + (order-X) * (pointer + G) = 0 */ - rustsecp256k1zkp_v0_8_0_scalar x; - rustsecp256k1zkp_v0_8_0_scalar nx; - rustsecp256k1zkp_v0_8_0_scalar zero = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0); - rustsecp256k1zkp_v0_8_0_scalar one = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 1); - rustsecp256k1zkp_v0_8_0_gej res1, res2; - rustsecp256k1zkp_v0_8_0_ge res3; + rustsecp256k1zkp_v0_10_0_scalar x; + rustsecp256k1zkp_v0_10_0_scalar nx; + rustsecp256k1zkp_v0_10_0_gej res1, res2; + rustsecp256k1zkp_v0_10_0_ge res3; unsigned char pub[65]; size_t psize = 65; random_scalar_order_test(&x); - rustsecp256k1zkp_v0_8_0_scalar_negate(&nx, &x); - rustsecp256k1zkp_v0_8_0_ecmult(&res1, point, &x, &x); /* calc res1 = x * point + x * G; */ - rustsecp256k1zkp_v0_8_0_ecmult(&res2, point, &nx, &nx); /* calc res2 = (order - x) * point + (order - x) * G; */ - rustsecp256k1zkp_v0_8_0_gej_add_var(&res1, &res1, &res2, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&res1)); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&res3, &res1); - CHECK(rustsecp256k1zkp_v0_8_0_ge_is_infinity(&res3)); - CHECK(rustsecp256k1zkp_v0_8_0_ge_is_valid_var(&res3) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&res3, pub, &psize, 0) == 0); + rustsecp256k1zkp_v0_10_0_scalar_negate(&nx, &x); + rustsecp256k1zkp_v0_10_0_ecmult(&res1, point, &x, &x); /* calc res1 = x * point + x * G; */ + rustsecp256k1zkp_v0_10_0_ecmult(&res2, point, &nx, &nx); /* calc res2 = (order - x) * point + (order - x) * G; */ + rustsecp256k1zkp_v0_10_0_gej_add_var(&res1, &res1, &res2, NULL); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&res1)); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&res3, &res1); + CHECK(rustsecp256k1zkp_v0_10_0_ge_is_infinity(&res3)); + CHECK(rustsecp256k1zkp_v0_10_0_ge_is_valid_var(&res3) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&res3, pub, &psize, 0) == 0); psize = 65; - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&res3, pub, &psize, 1) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&res3, pub, &psize, 1) == 0); /* check zero/one edge cases */ - rustsecp256k1zkp_v0_8_0_ecmult(&res1, point, &zero, &zero); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&res3, &res1); - CHECK(rustsecp256k1zkp_v0_8_0_ge_is_infinity(&res3)); - rustsecp256k1zkp_v0_8_0_ecmult(&res1, point, &one, &zero); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&res3, &res1); - ge_equals_gej(&res3, point); - rustsecp256k1zkp_v0_8_0_ecmult(&res1, point, &zero, &one); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&res3, &res1); - ge_equals_ge(&res3, &rustsecp256k1zkp_v0_8_0_ge_const_g); -} - -/* These scalars reach large (in absolute value) outputs when fed to rustsecp256k1zkp_v0_8_0_scalar_split_lambda. + rustsecp256k1zkp_v0_10_0_ecmult(&res1, point, &rustsecp256k1zkp_v0_10_0_scalar_zero, &rustsecp256k1zkp_v0_10_0_scalar_zero); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&res3, &res1); + CHECK(rustsecp256k1zkp_v0_10_0_ge_is_infinity(&res3)); + rustsecp256k1zkp_v0_10_0_ecmult(&res1, point, &rustsecp256k1zkp_v0_10_0_scalar_one, &rustsecp256k1zkp_v0_10_0_scalar_zero); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&res3, &res1); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(point, &res3)); + rustsecp256k1zkp_v0_10_0_ecmult(&res1, point, &rustsecp256k1zkp_v0_10_0_scalar_zero, &rustsecp256k1zkp_v0_10_0_scalar_one); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&res3, &res1); + CHECK(rustsecp256k1zkp_v0_10_0_ge_eq_var(&rustsecp256k1zkp_v0_10_0_ge_const_g, &res3)); +} + +/* These scalars reach large (in absolute value) outputs when fed to rustsecp256k1zkp_v0_10_0_scalar_split_lambda. * * They are computed as: * - For a in [-2, -1, 0, 1, 2]: * - For b in [-3, -1, 1, 3]: * - Output (a*LAMBDA + (ORDER+b)/2) % ORDER */ -static const rustsecp256k1zkp_v0_8_0_scalar scalars_near_split_bounds[20] = { +static const rustsecp256k1zkp_v0_10_0_scalar scalars_near_split_bounds[20] = { SECP256K1_SCALAR_CONST(0xd938a566, 0x7f479e3e, 0xb5b3c7fa, 0xefdb3749, 0x3aa0585c, 0xc5ea2367, 0xe1b660db, 0x0209e6fc), SECP256K1_SCALAR_CONST(0xd938a566, 0x7f479e3e, 0xb5b3c7fa, 0xefdb3749, 0x3aa0585c, 0xc5ea2367, 0xe1b660db, 0x0209e6fd), SECP256K1_SCALAR_CONST(0xd938a566, 0x7f479e3e, 0xb5b3c7fa, 0xefdb3749, 0x3aa0585c, 0xc5ea2367, 0xe1b660db, 0x0209e6fe), @@ -4120,49 +4519,48 @@ static const rustsecp256k1zkp_v0_8_0_scalar scalars_near_split_bounds[20] = { SECP256K1_SCALAR_CONST(0x26c75a99, 0x80b861c1, 0x4a4c3805, 0x1024c8b4, 0x704d760e, 0xe95e7cd3, 0xde1bfdb1, 0xce2c5a45) }; -void test_ecmult_target(const rustsecp256k1zkp_v0_8_0_scalar* target, int mode) { +static void test_ecmult_target(const rustsecp256k1zkp_v0_10_0_scalar* target, int mode) { /* Mode: 0=ecmult_gen, 1=ecmult, 2=ecmult_const */ - rustsecp256k1zkp_v0_8_0_scalar n1, n2; - rustsecp256k1zkp_v0_8_0_ge p; - rustsecp256k1zkp_v0_8_0_gej pj, p1j, p2j, ptj; - static const rustsecp256k1zkp_v0_8_0_scalar zero = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0); + rustsecp256k1zkp_v0_10_0_scalar n1, n2; + rustsecp256k1zkp_v0_10_0_ge p; + rustsecp256k1zkp_v0_10_0_gej pj, p1j, p2j, ptj; /* Generate random n1,n2 such that n1+n2 = -target. */ random_scalar_order_test(&n1); - rustsecp256k1zkp_v0_8_0_scalar_add(&n2, &n1, target); - rustsecp256k1zkp_v0_8_0_scalar_negate(&n2, &n2); + rustsecp256k1zkp_v0_10_0_scalar_add(&n2, &n1, target); + rustsecp256k1zkp_v0_10_0_scalar_negate(&n2, &n2); /* Generate a random input point. */ if (mode != 0) { random_group_element_test(&p); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&pj, &p); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&pj, &p); } /* EC multiplications */ if (mode == 0) { - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &p1j, &n1); - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &p2j, &n2); - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &ptj, target); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&CTX->ecmult_gen_ctx, &p1j, &n1); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&CTX->ecmult_gen_ctx, &p2j, &n2); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&CTX->ecmult_gen_ctx, &ptj, target); } else if (mode == 1) { - rustsecp256k1zkp_v0_8_0_ecmult(&p1j, &pj, &n1, &zero); - rustsecp256k1zkp_v0_8_0_ecmult(&p2j, &pj, &n2, &zero); - rustsecp256k1zkp_v0_8_0_ecmult(&ptj, &pj, target, &zero); + rustsecp256k1zkp_v0_10_0_ecmult(&p1j, &pj, &n1, &rustsecp256k1zkp_v0_10_0_scalar_zero); + rustsecp256k1zkp_v0_10_0_ecmult(&p2j, &pj, &n2, &rustsecp256k1zkp_v0_10_0_scalar_zero); + rustsecp256k1zkp_v0_10_0_ecmult(&ptj, &pj, target, &rustsecp256k1zkp_v0_10_0_scalar_zero); } else { - rustsecp256k1zkp_v0_8_0_ecmult_const(&p1j, &p, &n1, 256); - rustsecp256k1zkp_v0_8_0_ecmult_const(&p2j, &p, &n2, 256); - rustsecp256k1zkp_v0_8_0_ecmult_const(&ptj, &p, target, 256); + rustsecp256k1zkp_v0_10_0_ecmult_const(&p1j, &p, &n1); + rustsecp256k1zkp_v0_10_0_ecmult_const(&p2j, &p, &n2); + rustsecp256k1zkp_v0_10_0_ecmult_const(&ptj, &p, target); } /* Add them all up: n1*P + n2*P + target*P = (n1+n2+target)*P = (n1+n1-n1-n2)*P = 0. */ - rustsecp256k1zkp_v0_8_0_gej_add_var(&ptj, &ptj, &p1j, NULL); - rustsecp256k1zkp_v0_8_0_gej_add_var(&ptj, &ptj, &p2j, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&ptj)); + rustsecp256k1zkp_v0_10_0_gej_add_var(&ptj, &ptj, &p1j, NULL); + rustsecp256k1zkp_v0_10_0_gej_add_var(&ptj, &ptj, &p2j, NULL); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&ptj)); } -void run_ecmult_near_split_bound(void) { +static void run_ecmult_near_split_bound(void) { int i; unsigned j; - for (i = 0; i < 4*count; ++i) { + for (i = 0; i < 4*COUNT; ++i) { for (j = 0; j < sizeof(scalars_near_split_bounds) / sizeof(scalars_near_split_bounds[0]); ++j) { test_ecmult_target(&scalars_near_split_bounds[j], 0); test_ecmult_target(&scalars_near_split_bounds[j], 1); @@ -4171,143 +4569,247 @@ void run_ecmult_near_split_bound(void) { } } -void run_point_times_order(void) { +static void run_point_times_order(void) { int i; - rustsecp256k1zkp_v0_8_0_fe x = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 2); - static const rustsecp256k1zkp_v0_8_0_fe xr = SECP256K1_FE_CONST( + rustsecp256k1zkp_v0_10_0_fe x = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 2); + static const rustsecp256k1zkp_v0_10_0_fe xr = SECP256K1_FE_CONST( 0x7603CB59, 0xB0EF6C63, 0xFE608479, 0x2A0C378C, 0xDB3233A8, 0x0F8A9A09, 0xA877DEAD, 0x31B38C45 ); for (i = 0; i < 500; i++) { - rustsecp256k1zkp_v0_8_0_ge p; - if (rustsecp256k1zkp_v0_8_0_ge_set_xo_var(&p, &x, 1)) { - rustsecp256k1zkp_v0_8_0_gej j; - CHECK(rustsecp256k1zkp_v0_8_0_ge_is_valid_var(&p)); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&j, &p); + rustsecp256k1zkp_v0_10_0_ge p; + if (rustsecp256k1zkp_v0_10_0_ge_set_xo_var(&p, &x, 1)) { + rustsecp256k1zkp_v0_10_0_gej j; + CHECK(rustsecp256k1zkp_v0_10_0_ge_is_valid_var(&p)); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&j, &p); test_point_times_order(&j); } - rustsecp256k1zkp_v0_8_0_fe_sqr(&x, &x); + rustsecp256k1zkp_v0_10_0_fe_sqr(&x, &x); } - rustsecp256k1zkp_v0_8_0_fe_normalize_var(&x); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&x, &xr)); + rustsecp256k1zkp_v0_10_0_fe_normalize_var(&x); + CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&x, &xr)); } -void ecmult_const_random_mult(void) { +static void ecmult_const_random_mult(void) { /* random starting point A (on the curve) */ - rustsecp256k1zkp_v0_8_0_ge a = SECP256K1_GE_CONST( + rustsecp256k1zkp_v0_10_0_ge a = SECP256K1_GE_CONST( 0x6d986544, 0x57ff52b8, 0xcf1b8126, 0x5b802a5b, 0xa97f9263, 0xb1e88044, 0x93351325, 0x91bc450a, 0x535c59f7, 0x325e5d2b, 0xc391fbe8, 0x3c12787c, 0x337e4a98, 0xe82a9011, 0x0123ba37, 0xdd769c7d ); /* random initial factor xn */ - rustsecp256k1zkp_v0_8_0_scalar xn = SECP256K1_SCALAR_CONST( + rustsecp256k1zkp_v0_10_0_scalar xn = SECP256K1_SCALAR_CONST( 0x649d4f77, 0xc4242df7, 0x7f2079c9, 0x14530327, 0xa31b876a, 0xd2d8ce2a, 0x2236d5c6, 0xd7b2029b ); /* expected xn * A (from sage) */ - rustsecp256k1zkp_v0_8_0_ge expected_b = SECP256K1_GE_CONST( + rustsecp256k1zkp_v0_10_0_ge expected_b = SECP256K1_GE_CONST( 0x23773684, 0x4d209dc7, 0x098a786f, 0x20d06fcd, 0x070a38bf, 0xc11ac651, 0x03004319, 0x1e2a8786, 0xed8c3b8e, 0xc06dd57b, 0xd06ea66e, 0x45492b0f, 0xb84e4e1b, 0xfb77e21f, 0x96baae2a, 0x63dec956 ); - rustsecp256k1zkp_v0_8_0_gej b; - rustsecp256k1zkp_v0_8_0_ecmult_const(&b, &a, &xn, 256); + rustsecp256k1zkp_v0_10_0_gej b; + rustsecp256k1zkp_v0_10_0_ecmult_const(&b, &a, &xn); - CHECK(rustsecp256k1zkp_v0_8_0_ge_is_valid_var(&a)); - ge_equals_gej(&expected_b, &b); + CHECK(rustsecp256k1zkp_v0_10_0_ge_is_valid_var(&a)); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&b, &expected_b)); } -void ecmult_const_commutativity(void) { - rustsecp256k1zkp_v0_8_0_scalar a; - rustsecp256k1zkp_v0_8_0_scalar b; - rustsecp256k1zkp_v0_8_0_gej res1; - rustsecp256k1zkp_v0_8_0_gej res2; - rustsecp256k1zkp_v0_8_0_ge mid1; - rustsecp256k1zkp_v0_8_0_ge mid2; +static void ecmult_const_commutativity(void) { + rustsecp256k1zkp_v0_10_0_scalar a; + rustsecp256k1zkp_v0_10_0_scalar b; + rustsecp256k1zkp_v0_10_0_gej res1; + rustsecp256k1zkp_v0_10_0_gej res2; + rustsecp256k1zkp_v0_10_0_ge mid1; + rustsecp256k1zkp_v0_10_0_ge mid2; random_scalar_order_test(&a); random_scalar_order_test(&b); - rustsecp256k1zkp_v0_8_0_ecmult_const(&res1, &rustsecp256k1zkp_v0_8_0_ge_const_g, &a, 256); - rustsecp256k1zkp_v0_8_0_ecmult_const(&res2, &rustsecp256k1zkp_v0_8_0_ge_const_g, &b, 256); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&mid1, &res1); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&mid2, &res2); - rustsecp256k1zkp_v0_8_0_ecmult_const(&res1, &mid1, &b, 256); - rustsecp256k1zkp_v0_8_0_ecmult_const(&res2, &mid2, &a, 256); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&mid1, &res1); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&mid2, &res2); - ge_equals_ge(&mid1, &mid2); -} - -void ecmult_const_mult_zero_one(void) { - rustsecp256k1zkp_v0_8_0_scalar zero = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0); - rustsecp256k1zkp_v0_8_0_scalar one = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 1); - rustsecp256k1zkp_v0_8_0_scalar negone; - rustsecp256k1zkp_v0_8_0_gej res1; - rustsecp256k1zkp_v0_8_0_ge res2; - rustsecp256k1zkp_v0_8_0_ge point; - rustsecp256k1zkp_v0_8_0_scalar_negate(&negone, &one); + rustsecp256k1zkp_v0_10_0_ecmult_const(&res1, &rustsecp256k1zkp_v0_10_0_ge_const_g, &a); + rustsecp256k1zkp_v0_10_0_ecmult_const(&res2, &rustsecp256k1zkp_v0_10_0_ge_const_g, &b); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&mid1, &res1); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&mid2, &res2); + rustsecp256k1zkp_v0_10_0_ecmult_const(&res1, &mid1, &b); + rustsecp256k1zkp_v0_10_0_ecmult_const(&res2, &mid2, &a); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&mid1, &res1); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&mid2, &res2); + CHECK(rustsecp256k1zkp_v0_10_0_ge_eq_var(&mid1, &mid2)); +} + +static void ecmult_const_mult_zero_one(void) { + rustsecp256k1zkp_v0_10_0_scalar s; + rustsecp256k1zkp_v0_10_0_scalar negone; + rustsecp256k1zkp_v0_10_0_gej res1; + rustsecp256k1zkp_v0_10_0_ge res2; + rustsecp256k1zkp_v0_10_0_ge point; + rustsecp256k1zkp_v0_10_0_ge inf; + random_scalar_order_test(&s); + rustsecp256k1zkp_v0_10_0_scalar_negate(&negone, &rustsecp256k1zkp_v0_10_0_scalar_one); random_group_element_test(&point); - rustsecp256k1zkp_v0_8_0_ecmult_const(&res1, &point, &zero, 3); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&res2, &res1); - CHECK(rustsecp256k1zkp_v0_8_0_ge_is_infinity(&res2)); - rustsecp256k1zkp_v0_8_0_ecmult_const(&res1, &point, &one, 2); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&res2, &res1); - ge_equals_ge(&res2, &point); - rustsecp256k1zkp_v0_8_0_ecmult_const(&res1, &point, &negone, 256); - rustsecp256k1zkp_v0_8_0_gej_neg(&res1, &res1); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&res2, &res1); - ge_equals_ge(&res2, &point); -} - -void ecmult_const_chain_multiply(void) { + rustsecp256k1zkp_v0_10_0_ge_set_infinity(&inf); + + /* 0*point */ + rustsecp256k1zkp_v0_10_0_ecmult_const(&res1, &point, &rustsecp256k1zkp_v0_10_0_scalar_zero); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&res1)); + + /* s*inf */ + rustsecp256k1zkp_v0_10_0_ecmult_const(&res1, &inf, &s); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&res1)); + + /* 1*point */ + rustsecp256k1zkp_v0_10_0_ecmult_const(&res1, &point, &rustsecp256k1zkp_v0_10_0_scalar_one); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&res2, &res1); + CHECK(rustsecp256k1zkp_v0_10_0_ge_eq_var(&res2, &point)); + + /* -1*point */ + rustsecp256k1zkp_v0_10_0_ecmult_const(&res1, &point, &negone); + rustsecp256k1zkp_v0_10_0_gej_neg(&res1, &res1); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&res2, &res1); + CHECK(rustsecp256k1zkp_v0_10_0_ge_eq_var(&res2, &point)); +} + +static void ecmult_const_check_result(const rustsecp256k1zkp_v0_10_0_ge *A, const rustsecp256k1zkp_v0_10_0_scalar* q, const rustsecp256k1zkp_v0_10_0_gej *res) { + rustsecp256k1zkp_v0_10_0_gej pointj, res2j; + rustsecp256k1zkp_v0_10_0_ge res2; + rustsecp256k1zkp_v0_10_0_gej_set_ge(&pointj, A); + rustsecp256k1zkp_v0_10_0_ecmult(&res2j, &pointj, q, &rustsecp256k1zkp_v0_10_0_scalar_zero); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&res2, &res2j); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(res, &res2)); +} + +static void ecmult_const_edges(void) { + rustsecp256k1zkp_v0_10_0_scalar q; + rustsecp256k1zkp_v0_10_0_ge point; + rustsecp256k1zkp_v0_10_0_gej res; + size_t i; + size_t cases = 1 + sizeof(scalars_near_split_bounds) / sizeof(scalars_near_split_bounds[0]); + + /* We are trying to reach the following edge cases (variables are defined as + * in ecmult_const_impl.h): + * 1. i = 0: s = 0 <=> q = -K + * 2. i > 0: v1, v2 large values + * <=> s1, s2 large values + * <=> s = scalars_near_split_bounds[i] + * <=> q = 2*scalars_near_split_bounds[i] - K + */ + for (i = 0; i < cases; ++i) { + rustsecp256k1zkp_v0_10_0_scalar_negate(&q, &rustsecp256k1zkp_v0_10_0_ecmult_const_K); + if (i > 0) { + rustsecp256k1zkp_v0_10_0_scalar_add(&q, &q, &scalars_near_split_bounds[i - 1]); + rustsecp256k1zkp_v0_10_0_scalar_add(&q, &q, &scalars_near_split_bounds[i - 1]); + } + random_group_element_test(&point); + rustsecp256k1zkp_v0_10_0_ecmult_const(&res, &point, &q); + ecmult_const_check_result(&point, &q, &res); + } +} + +static void ecmult_const_mult_xonly(void) { + int i; + + /* Test correspondence between rustsecp256k1zkp_v0_10_0_ecmult_const and rustsecp256k1zkp_v0_10_0_ecmult_const_xonly. */ + for (i = 0; i < 2*COUNT; ++i) { + rustsecp256k1zkp_v0_10_0_ge base; + rustsecp256k1zkp_v0_10_0_gej basej, resj; + rustsecp256k1zkp_v0_10_0_fe n, d, resx, v; + rustsecp256k1zkp_v0_10_0_scalar q; + int res; + /* Random base point. */ + random_group_element_test(&base); + /* Random scalar to multiply it with. */ + random_scalar_order_test(&q); + /* If i is odd, n=d*base.x for random non-zero d */ + if (i & 1) { + random_fe_non_zero_test(&d); + rustsecp256k1zkp_v0_10_0_fe_mul(&n, &base.x, &d); + } else { + n = base.x; + } + /* Perform x-only multiplication. */ + res = rustsecp256k1zkp_v0_10_0_ecmult_const_xonly(&resx, &n, (i & 1) ? &d : NULL, &q, i & 2); + CHECK(res); + /* Perform normal multiplication. */ + rustsecp256k1zkp_v0_10_0_gej_set_ge(&basej, &base); + rustsecp256k1zkp_v0_10_0_ecmult(&resj, &basej, &q, NULL); + /* Check that resj's X coordinate corresponds with resx. */ + rustsecp256k1zkp_v0_10_0_fe_sqr(&v, &resj.z); + rustsecp256k1zkp_v0_10_0_fe_mul(&v, &v, &resx); + CHECK(check_fe_equal(&v, &resj.x)); + } + + /* Test that rustsecp256k1zkp_v0_10_0_ecmult_const_xonly correctly rejects X coordinates not on curve. */ + for (i = 0; i < 2*COUNT; ++i) { + rustsecp256k1zkp_v0_10_0_fe x, n, d, r; + int res; + rustsecp256k1zkp_v0_10_0_scalar q; + random_scalar_order_test(&q); + /* Generate random X coordinate not on the curve. */ + do { + random_fe_test(&x); + } while (rustsecp256k1zkp_v0_10_0_ge_x_on_curve_var(&x)); + /* If i is odd, n=d*x for random non-zero d. */ + if (i & 1) { + random_fe_non_zero_test(&d); + rustsecp256k1zkp_v0_10_0_fe_mul(&n, &x, &d); + } else { + n = x; + } + res = rustsecp256k1zkp_v0_10_0_ecmult_const_xonly(&r, &n, (i & 1) ? &d : NULL, &q, 0); + CHECK(res == 0); + } +} + +static void ecmult_const_chain_multiply(void) { /* Check known result (randomly generated test problem from sage) */ - const rustsecp256k1zkp_v0_8_0_scalar scalar = SECP256K1_SCALAR_CONST( + const rustsecp256k1zkp_v0_10_0_scalar scalar = SECP256K1_SCALAR_CONST( 0x4968d524, 0x2abf9b7a, 0x466abbcf, 0x34b11b6d, 0xcd83d307, 0x827bed62, 0x05fad0ce, 0x18fae63b ); - const rustsecp256k1zkp_v0_8_0_gej expected_point = SECP256K1_GEJ_CONST( + const rustsecp256k1zkp_v0_10_0_gej expected_point = SECP256K1_GEJ_CONST( 0x5494c15d, 0x32099706, 0xc2395f94, 0x348745fd, 0x757ce30e, 0x4e8c90fb, 0xa2bad184, 0xf883c69f, 0x5d195d20, 0xe191bf7f, 0x1be3e55f, 0x56a80196, 0x6071ad01, 0xf1462f66, 0xc997fa94, 0xdb858435 ); - rustsecp256k1zkp_v0_8_0_gej point; - rustsecp256k1zkp_v0_8_0_ge res; + rustsecp256k1zkp_v0_10_0_gej point; + rustsecp256k1zkp_v0_10_0_ge res; int i; - rustsecp256k1zkp_v0_8_0_gej_set_ge(&point, &rustsecp256k1zkp_v0_8_0_ge_const_g); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&point, &rustsecp256k1zkp_v0_10_0_ge_const_g); for (i = 0; i < 100; ++i) { - rustsecp256k1zkp_v0_8_0_ge tmp; - rustsecp256k1zkp_v0_8_0_ge_set_gej(&tmp, &point); - rustsecp256k1zkp_v0_8_0_ecmult_const(&point, &tmp, &scalar, 256); + rustsecp256k1zkp_v0_10_0_ge tmp; + rustsecp256k1zkp_v0_10_0_ge_set_gej(&tmp, &point); + rustsecp256k1zkp_v0_10_0_ecmult_const(&point, &tmp, &scalar); } - rustsecp256k1zkp_v0_8_0_ge_set_gej(&res, &point); - ge_equals_gej(&res, &expected_point); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&res, &point); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&expected_point, &res)); } -void run_ecmult_const_tests(void) { +static void run_ecmult_const_tests(void) { ecmult_const_mult_zero_one(); + ecmult_const_edges(); ecmult_const_random_mult(); ecmult_const_commutativity(); ecmult_const_chain_multiply(); + ecmult_const_mult_xonly(); } typedef struct { - rustsecp256k1zkp_v0_8_0_scalar *sc; - rustsecp256k1zkp_v0_8_0_ge *pt; + rustsecp256k1zkp_v0_10_0_scalar *sc; + rustsecp256k1zkp_v0_10_0_ge *pt; } ecmult_multi_data; -static int ecmult_multi_callback(rustsecp256k1zkp_v0_8_0_scalar *sc, rustsecp256k1zkp_v0_8_0_ge *pt, size_t idx, void *cbdata) { +static int ecmult_multi_callback(rustsecp256k1zkp_v0_10_0_scalar *sc, rustsecp256k1zkp_v0_10_0_ge *pt, size_t idx, void *cbdata) { ecmult_multi_data *data = (ecmult_multi_data*) cbdata; *sc = data->sc[idx]; *pt = data->pt[idx]; return 1; } -static int ecmult_multi_false_callback(rustsecp256k1zkp_v0_8_0_scalar *sc, rustsecp256k1zkp_v0_8_0_ge *pt, size_t idx, void *cbdata) { +static int ecmult_multi_false_callback(rustsecp256k1zkp_v0_10_0_scalar *sc, rustsecp256k1zkp_v0_10_0_ge *pt, size_t idx, void *cbdata) { (void)sc; (void)pt; (void)idx; @@ -4315,102 +4817,92 @@ static int ecmult_multi_false_callback(rustsecp256k1zkp_v0_8_0_scalar *sc, rusts return 0; } -void test_ecmult_multi(rustsecp256k1zkp_v0_8_0_scratch *scratch, rustsecp256k1zkp_v0_8_0_ecmult_multi_func ecmult_multi) { +static void test_ecmult_multi(rustsecp256k1zkp_v0_10_0_scratch *scratch, rustsecp256k1zkp_v0_10_0_ecmult_multi_func ecmult_multi) { int ncount; - rustsecp256k1zkp_v0_8_0_scalar szero; - rustsecp256k1zkp_v0_8_0_scalar sc[32]; - rustsecp256k1zkp_v0_8_0_ge pt[32]; - rustsecp256k1zkp_v0_8_0_gej r; - rustsecp256k1zkp_v0_8_0_gej r2; + rustsecp256k1zkp_v0_10_0_scalar sc[32]; + rustsecp256k1zkp_v0_10_0_ge pt[32]; + rustsecp256k1zkp_v0_10_0_gej r; + rustsecp256k1zkp_v0_10_0_gej r2; ecmult_multi_data data; data.sc = sc; data.pt = pt; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&szero, 0); /* No points to multiply */ - CHECK(ecmult_multi(&ctx->error_callback, scratch, &r, NULL, ecmult_multi_callback, &data, 0)); + CHECK(ecmult_multi(&CTX->error_callback, scratch, &r, NULL, ecmult_multi_callback, &data, 0)); /* Check 1- and 2-point multiplies against ecmult */ - for (ncount = 0; ncount < count; ncount++) { - rustsecp256k1zkp_v0_8_0_ge ptg; - rustsecp256k1zkp_v0_8_0_gej ptgj; + for (ncount = 0; ncount < COUNT; ncount++) { + rustsecp256k1zkp_v0_10_0_ge ptg; + rustsecp256k1zkp_v0_10_0_gej ptgj; random_scalar_order(&sc[0]); random_scalar_order(&sc[1]); random_group_element_test(&ptg); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&ptgj, &ptg); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&ptgj, &ptg); pt[0] = ptg; - pt[1] = rustsecp256k1zkp_v0_8_0_ge_const_g; + pt[1] = rustsecp256k1zkp_v0_10_0_ge_const_g; /* only G scalar */ - rustsecp256k1zkp_v0_8_0_ecmult(&r2, &ptgj, &szero, &sc[0]); - CHECK(ecmult_multi(&ctx->error_callback, scratch, &r, &sc[0], ecmult_multi_callback, &data, 0)); - rustsecp256k1zkp_v0_8_0_gej_neg(&r2, &r2); - rustsecp256k1zkp_v0_8_0_gej_add_var(&r, &r, &r2, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&r)); + rustsecp256k1zkp_v0_10_0_ecmult(&r2, &ptgj, &rustsecp256k1zkp_v0_10_0_scalar_zero, &sc[0]); + CHECK(ecmult_multi(&CTX->error_callback, scratch, &r, &sc[0], ecmult_multi_callback, &data, 0)); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_var(&r, &r2)); /* 1-point */ - rustsecp256k1zkp_v0_8_0_ecmult(&r2, &ptgj, &sc[0], &szero); - CHECK(ecmult_multi(&ctx->error_callback, scratch, &r, &szero, ecmult_multi_callback, &data, 1)); - rustsecp256k1zkp_v0_8_0_gej_neg(&r2, &r2); - rustsecp256k1zkp_v0_8_0_gej_add_var(&r, &r, &r2, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&r)); + rustsecp256k1zkp_v0_10_0_ecmult(&r2, &ptgj, &sc[0], &rustsecp256k1zkp_v0_10_0_scalar_zero); + CHECK(ecmult_multi(&CTX->error_callback, scratch, &r, &rustsecp256k1zkp_v0_10_0_scalar_zero, ecmult_multi_callback, &data, 1)); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_var(&r, &r2)); /* Try to multiply 1 point, but callback returns false */ - CHECK(!ecmult_multi(&ctx->error_callback, scratch, &r, &szero, ecmult_multi_false_callback, &data, 1)); + CHECK(!ecmult_multi(&CTX->error_callback, scratch, &r, &rustsecp256k1zkp_v0_10_0_scalar_zero, ecmult_multi_false_callback, &data, 1)); /* 2-point */ - rustsecp256k1zkp_v0_8_0_ecmult(&r2, &ptgj, &sc[0], &sc[1]); - CHECK(ecmult_multi(&ctx->error_callback, scratch, &r, &szero, ecmult_multi_callback, &data, 2)); - rustsecp256k1zkp_v0_8_0_gej_neg(&r2, &r2); - rustsecp256k1zkp_v0_8_0_gej_add_var(&r, &r, &r2, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&r)); + rustsecp256k1zkp_v0_10_0_ecmult(&r2, &ptgj, &sc[0], &sc[1]); + CHECK(ecmult_multi(&CTX->error_callback, scratch, &r, &rustsecp256k1zkp_v0_10_0_scalar_zero, ecmult_multi_callback, &data, 2)); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_var(&r, &r2)); /* 2-point with G scalar */ - rustsecp256k1zkp_v0_8_0_ecmult(&r2, &ptgj, &sc[0], &sc[1]); - CHECK(ecmult_multi(&ctx->error_callback, scratch, &r, &sc[1], ecmult_multi_callback, &data, 1)); - rustsecp256k1zkp_v0_8_0_gej_neg(&r2, &r2); - rustsecp256k1zkp_v0_8_0_gej_add_var(&r, &r, &r2, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&r)); + rustsecp256k1zkp_v0_10_0_ecmult(&r2, &ptgj, &sc[0], &sc[1]); + CHECK(ecmult_multi(&CTX->error_callback, scratch, &r, &sc[1], ecmult_multi_callback, &data, 1)); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_var(&r, &r2)); } /* Check infinite outputs of various forms */ - for (ncount = 0; ncount < count; ncount++) { - rustsecp256k1zkp_v0_8_0_ge ptg; + for (ncount = 0; ncount < COUNT; ncount++) { + rustsecp256k1zkp_v0_10_0_ge ptg; size_t i, j; size_t sizes[] = { 2, 10, 32 }; for (j = 0; j < 3; j++) { for (i = 0; i < 32; i++) { random_scalar_order(&sc[i]); - rustsecp256k1zkp_v0_8_0_ge_set_infinity(&pt[i]); + rustsecp256k1zkp_v0_10_0_ge_set_infinity(&pt[i]); } - CHECK(ecmult_multi(&ctx->error_callback, scratch, &r, &szero, ecmult_multi_callback, &data, sizes[j])); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&r)); + CHECK(ecmult_multi(&CTX->error_callback, scratch, &r, &rustsecp256k1zkp_v0_10_0_scalar_zero, ecmult_multi_callback, &data, sizes[j])); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&r)); } for (j = 0; j < 3; j++) { for (i = 0; i < 32; i++) { random_group_element_test(&ptg); pt[i] = ptg; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&sc[i], 0); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&sc[i], 0); } - CHECK(ecmult_multi(&ctx->error_callback, scratch, &r, &szero, ecmult_multi_callback, &data, sizes[j])); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&r)); + CHECK(ecmult_multi(&CTX->error_callback, scratch, &r, &rustsecp256k1zkp_v0_10_0_scalar_zero, ecmult_multi_callback, &data, sizes[j])); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&r)); } for (j = 0; j < 3; j++) { random_group_element_test(&ptg); for (i = 0; i < 16; i++) { random_scalar_order(&sc[2*i]); - rustsecp256k1zkp_v0_8_0_scalar_negate(&sc[2*i + 1], &sc[2*i]); + rustsecp256k1zkp_v0_10_0_scalar_negate(&sc[2*i + 1], &sc[2*i]); pt[2 * i] = ptg; pt[2 * i + 1] = ptg; } - CHECK(ecmult_multi(&ctx->error_callback, scratch, &r, &szero, ecmult_multi_callback, &data, sizes[j])); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&r)); + CHECK(ecmult_multi(&CTX->error_callback, scratch, &r, &rustsecp256k1zkp_v0_10_0_scalar_zero, ecmult_multi_callback, &data, sizes[j])); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&r)); random_scalar_order(&sc[0]); for (i = 0; i < 16; i++) { @@ -4419,70 +4911,66 @@ void test_ecmult_multi(rustsecp256k1zkp_v0_8_0_scratch *scratch, rustsecp256k1zk sc[2*i] = sc[0]; sc[2*i+1] = sc[0]; pt[2 * i] = ptg; - rustsecp256k1zkp_v0_8_0_ge_neg(&pt[2*i+1], &pt[2*i]); + rustsecp256k1zkp_v0_10_0_ge_neg(&pt[2*i+1], &pt[2*i]); } - CHECK(ecmult_multi(&ctx->error_callback, scratch, &r, &szero, ecmult_multi_callback, &data, sizes[j])); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&r)); + CHECK(ecmult_multi(&CTX->error_callback, scratch, &r, &rustsecp256k1zkp_v0_10_0_scalar_zero, ecmult_multi_callback, &data, sizes[j])); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&r)); } random_group_element_test(&ptg); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&sc[0], 0); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&sc[0], 0); pt[0] = ptg; for (i = 1; i < 32; i++) { pt[i] = ptg; random_scalar_order(&sc[i]); - rustsecp256k1zkp_v0_8_0_scalar_add(&sc[0], &sc[0], &sc[i]); - rustsecp256k1zkp_v0_8_0_scalar_negate(&sc[i], &sc[i]); + rustsecp256k1zkp_v0_10_0_scalar_add(&sc[0], &sc[0], &sc[i]); + rustsecp256k1zkp_v0_10_0_scalar_negate(&sc[i], &sc[i]); } - CHECK(ecmult_multi(&ctx->error_callback, scratch, &r, &szero, ecmult_multi_callback, &data, 32)); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&r)); + CHECK(ecmult_multi(&CTX->error_callback, scratch, &r, &rustsecp256k1zkp_v0_10_0_scalar_zero, ecmult_multi_callback, &data, 32)); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&r)); } /* Check random points, constant scalar */ - for (ncount = 0; ncount < count; ncount++) { + for (ncount = 0; ncount < COUNT; ncount++) { size_t i; - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&r); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&r); random_scalar_order(&sc[0]); for (i = 0; i < 20; i++) { - rustsecp256k1zkp_v0_8_0_ge ptg; + rustsecp256k1zkp_v0_10_0_ge ptg; sc[i] = sc[0]; random_group_element_test(&ptg); pt[i] = ptg; - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&r, &r, &pt[i], NULL); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&r, &r, &pt[i], NULL); } - rustsecp256k1zkp_v0_8_0_ecmult(&r2, &r, &sc[0], &szero); - CHECK(ecmult_multi(&ctx->error_callback, scratch, &r, &szero, ecmult_multi_callback, &data, 20)); - rustsecp256k1zkp_v0_8_0_gej_neg(&r2, &r2); - rustsecp256k1zkp_v0_8_0_gej_add_var(&r, &r, &r2, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&r)); + rustsecp256k1zkp_v0_10_0_ecmult(&r2, &r, &sc[0], &rustsecp256k1zkp_v0_10_0_scalar_zero); + CHECK(ecmult_multi(&CTX->error_callback, scratch, &r, &rustsecp256k1zkp_v0_10_0_scalar_zero, ecmult_multi_callback, &data, 20)); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_var(&r, &r2)); } /* Check random scalars, constant point */ - for (ncount = 0; ncount < count; ncount++) { + for (ncount = 0; ncount < COUNT; ncount++) { size_t i; - rustsecp256k1zkp_v0_8_0_ge ptg; - rustsecp256k1zkp_v0_8_0_gej p0j; - rustsecp256k1zkp_v0_8_0_scalar rs; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&rs, 0); + rustsecp256k1zkp_v0_10_0_ge ptg; + rustsecp256k1zkp_v0_10_0_gej p0j; + rustsecp256k1zkp_v0_10_0_scalar rs; + rustsecp256k1zkp_v0_10_0_scalar_set_int(&rs, 0); random_group_element_test(&ptg); for (i = 0; i < 20; i++) { random_scalar_order(&sc[i]); pt[i] = ptg; - rustsecp256k1zkp_v0_8_0_scalar_add(&rs, &rs, &sc[i]); + rustsecp256k1zkp_v0_10_0_scalar_add(&rs, &rs, &sc[i]); } - rustsecp256k1zkp_v0_8_0_gej_set_ge(&p0j, &pt[0]); - rustsecp256k1zkp_v0_8_0_ecmult(&r2, &p0j, &rs, &szero); - CHECK(ecmult_multi(&ctx->error_callback, scratch, &r, &szero, ecmult_multi_callback, &data, 20)); - rustsecp256k1zkp_v0_8_0_gej_neg(&r2, &r2); - rustsecp256k1zkp_v0_8_0_gej_add_var(&r, &r, &r2, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&r)); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&p0j, &pt[0]); + rustsecp256k1zkp_v0_10_0_ecmult(&r2, &p0j, &rs, &rustsecp256k1zkp_v0_10_0_scalar_zero); + CHECK(ecmult_multi(&CTX->error_callback, scratch, &r, &rustsecp256k1zkp_v0_10_0_scalar_zero, ecmult_multi_callback, &data, 20)); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_var(&r, &r2)); } /* Sanity check that zero scalars don't cause problems */ @@ -4491,62 +4979,60 @@ void test_ecmult_multi(rustsecp256k1zkp_v0_8_0_scratch *scratch, rustsecp256k1zk random_group_element_test(&pt[ncount]); } - rustsecp256k1zkp_v0_8_0_scalar_clear(&sc[0]); - CHECK(ecmult_multi(&ctx->error_callback, scratch, &r, &szero, ecmult_multi_callback, &data, 20)); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sc[1]); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sc[2]); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sc[3]); - rustsecp256k1zkp_v0_8_0_scalar_clear(&sc[4]); - CHECK(ecmult_multi(&ctx->error_callback, scratch, &r, &szero, ecmult_multi_callback, &data, 6)); - CHECK(ecmult_multi(&ctx->error_callback, scratch, &r, &szero, ecmult_multi_callback, &data, 5)); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&r)); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sc[0]); + CHECK(ecmult_multi(&CTX->error_callback, scratch, &r, &rustsecp256k1zkp_v0_10_0_scalar_zero, ecmult_multi_callback, &data, 20)); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sc[1]); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sc[2]); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sc[3]); + rustsecp256k1zkp_v0_10_0_scalar_clear(&sc[4]); + CHECK(ecmult_multi(&CTX->error_callback, scratch, &r, &rustsecp256k1zkp_v0_10_0_scalar_zero, ecmult_multi_callback, &data, 6)); + CHECK(ecmult_multi(&CTX->error_callback, scratch, &r, &rustsecp256k1zkp_v0_10_0_scalar_zero, ecmult_multi_callback, &data, 5)); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&r)); /* Run through s0*(t0*P) + s1*(t1*P) exhaustively for many small values of s0, s1, t0, t1 */ { const size_t TOP = 8; size_t s0i, s1i; size_t t0i, t1i; - rustsecp256k1zkp_v0_8_0_ge ptg; - rustsecp256k1zkp_v0_8_0_gej ptgj; + rustsecp256k1zkp_v0_10_0_ge ptg; + rustsecp256k1zkp_v0_10_0_gej ptgj; random_group_element_test(&ptg); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&ptgj, &ptg); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&ptgj, &ptg); for(t0i = 0; t0i < TOP; t0i++) { for(t1i = 0; t1i < TOP; t1i++) { - rustsecp256k1zkp_v0_8_0_gej t0p, t1p; - rustsecp256k1zkp_v0_8_0_scalar t0, t1; + rustsecp256k1zkp_v0_10_0_gej t0p, t1p; + rustsecp256k1zkp_v0_10_0_scalar t0, t1; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&t0, (t0i + 1) / 2); - rustsecp256k1zkp_v0_8_0_scalar_cond_negate(&t0, t0i & 1); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&t1, (t1i + 1) / 2); - rustsecp256k1zkp_v0_8_0_scalar_cond_negate(&t1, t1i & 1); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&t0, (t0i + 1) / 2); + rustsecp256k1zkp_v0_10_0_scalar_cond_negate(&t0, t0i & 1); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&t1, (t1i + 1) / 2); + rustsecp256k1zkp_v0_10_0_scalar_cond_negate(&t1, t1i & 1); - rustsecp256k1zkp_v0_8_0_ecmult(&t0p, &ptgj, &t0, &szero); - rustsecp256k1zkp_v0_8_0_ecmult(&t1p, &ptgj, &t1, &szero); + rustsecp256k1zkp_v0_10_0_ecmult(&t0p, &ptgj, &t0, &rustsecp256k1zkp_v0_10_0_scalar_zero); + rustsecp256k1zkp_v0_10_0_ecmult(&t1p, &ptgj, &t1, &rustsecp256k1zkp_v0_10_0_scalar_zero); for(s0i = 0; s0i < TOP; s0i++) { for(s1i = 0; s1i < TOP; s1i++) { - rustsecp256k1zkp_v0_8_0_scalar tmp1, tmp2; - rustsecp256k1zkp_v0_8_0_gej expected, actual; - - rustsecp256k1zkp_v0_8_0_ge_set_gej(&pt[0], &t0p); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&pt[1], &t1p); - - rustsecp256k1zkp_v0_8_0_scalar_set_int(&sc[0], (s0i + 1) / 2); - rustsecp256k1zkp_v0_8_0_scalar_cond_negate(&sc[0], s0i & 1); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&sc[1], (s1i + 1) / 2); - rustsecp256k1zkp_v0_8_0_scalar_cond_negate(&sc[1], s1i & 1); - - rustsecp256k1zkp_v0_8_0_scalar_mul(&tmp1, &t0, &sc[0]); - rustsecp256k1zkp_v0_8_0_scalar_mul(&tmp2, &t1, &sc[1]); - rustsecp256k1zkp_v0_8_0_scalar_add(&tmp1, &tmp1, &tmp2); - - rustsecp256k1zkp_v0_8_0_ecmult(&expected, &ptgj, &tmp1, &szero); - CHECK(ecmult_multi(&ctx->error_callback, scratch, &actual, &szero, ecmult_multi_callback, &data, 2)); - rustsecp256k1zkp_v0_8_0_gej_neg(&expected, &expected); - rustsecp256k1zkp_v0_8_0_gej_add_var(&actual, &actual, &expected, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&actual)); + rustsecp256k1zkp_v0_10_0_scalar tmp1, tmp2; + rustsecp256k1zkp_v0_10_0_gej expected, actual; + + rustsecp256k1zkp_v0_10_0_ge_set_gej(&pt[0], &t0p); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&pt[1], &t1p); + + rustsecp256k1zkp_v0_10_0_scalar_set_int(&sc[0], (s0i + 1) / 2); + rustsecp256k1zkp_v0_10_0_scalar_cond_negate(&sc[0], s0i & 1); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&sc[1], (s1i + 1) / 2); + rustsecp256k1zkp_v0_10_0_scalar_cond_negate(&sc[1], s1i & 1); + + rustsecp256k1zkp_v0_10_0_scalar_mul(&tmp1, &t0, &sc[0]); + rustsecp256k1zkp_v0_10_0_scalar_mul(&tmp2, &t1, &sc[1]); + rustsecp256k1zkp_v0_10_0_scalar_add(&tmp1, &tmp1, &tmp2); + + rustsecp256k1zkp_v0_10_0_ecmult(&expected, &ptgj, &tmp1, &rustsecp256k1zkp_v0_10_0_scalar_zero); + CHECK(ecmult_multi(&CTX->error_callback, scratch, &actual, &rustsecp256k1zkp_v0_10_0_scalar_zero, ecmult_multi_callback, &data, 2)); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_var(&actual, &expected)); } } } @@ -4554,7 +5040,7 @@ void test_ecmult_multi(rustsecp256k1zkp_v0_8_0_scratch *scratch, rustsecp256k1zk } } -int test_ecmult_multi_random(rustsecp256k1zkp_v0_8_0_scratch *scratch) { +static int test_ecmult_multi_random(rustsecp256k1zkp_v0_10_0_scratch *scratch) { /* Large random test for ecmult_multi_* functions which exercises: * - Few or many inputs (0 up to 128, roughly exponentially distributed). * - Few or many 0*P or a*INF inputs (roughly uniformly distributed). @@ -4568,48 +5054,48 @@ int test_ecmult_multi_random(rustsecp256k1zkp_v0_8_0_scratch *scratch) { * scalars[0..filled-1] and gejs[0..filled-1] are the scalars and points * which form its normal inputs. */ int filled = 0; - rustsecp256k1zkp_v0_8_0_scalar g_scalar = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0); - rustsecp256k1zkp_v0_8_0_scalar scalars[128]; - rustsecp256k1zkp_v0_8_0_gej gejs[128]; + rustsecp256k1zkp_v0_10_0_scalar g_scalar = rustsecp256k1zkp_v0_10_0_scalar_zero; + rustsecp256k1zkp_v0_10_0_scalar scalars[128]; + rustsecp256k1zkp_v0_10_0_gej gejs[128]; /* The expected result, and the computed result. */ - rustsecp256k1zkp_v0_8_0_gej expected, computed; + rustsecp256k1zkp_v0_10_0_gej expected, computed; /* Temporaries. */ - rustsecp256k1zkp_v0_8_0_scalar sc_tmp; - rustsecp256k1zkp_v0_8_0_ge ge_tmp; + rustsecp256k1zkp_v0_10_0_scalar sc_tmp; + rustsecp256k1zkp_v0_10_0_ge ge_tmp; /* Variables needed for the actual input to ecmult_multi. */ - rustsecp256k1zkp_v0_8_0_ge ges[128]; + rustsecp256k1zkp_v0_10_0_ge ges[128]; ecmult_multi_data data; int i; /* Which multiplication function to use */ - int fn = rustsecp256k1zkp_v0_8_0_testrand_int(3); - rustsecp256k1zkp_v0_8_0_ecmult_multi_func ecmult_multi = fn == 0 ? rustsecp256k1zkp_v0_8_0_ecmult_multi_var : - fn == 1 ? rustsecp256k1zkp_v0_8_0_ecmult_strauss_batch_single : - rustsecp256k1zkp_v0_8_0_ecmult_pippenger_batch_single; + int fn = rustsecp256k1zkp_v0_10_0_testrand_int(3); + rustsecp256k1zkp_v0_10_0_ecmult_multi_func ecmult_multi = fn == 0 ? rustsecp256k1zkp_v0_10_0_ecmult_multi_var : + fn == 1 ? rustsecp256k1zkp_v0_10_0_ecmult_strauss_batch_single : + rustsecp256k1zkp_v0_10_0_ecmult_pippenger_batch_single; /* Simulate exponentially distributed num. */ - int num_bits = 2 + rustsecp256k1zkp_v0_8_0_testrand_int(6); + int num_bits = 2 + rustsecp256k1zkp_v0_10_0_testrand_int(6); /* Number of (scalar, point) inputs (excluding g). */ - int num = rustsecp256k1zkp_v0_8_0_testrand_int((1 << num_bits) + 1); + int num = rustsecp256k1zkp_v0_10_0_testrand_int((1 << num_bits) + 1); /* Number of those which are nonzero. */ - int num_nonzero = rustsecp256k1zkp_v0_8_0_testrand_int(num + 1); + int num_nonzero = rustsecp256k1zkp_v0_10_0_testrand_int(num + 1); /* Whether we're aiming to create an input with nonzero expected result. */ - int nonzero_result = rustsecp256k1zkp_v0_8_0_testrand_bits(1); + int nonzero_result = rustsecp256k1zkp_v0_10_0_testrand_bits(1); /* Whether we will provide nonzero g multiplicand. In some cases our hand * is forced here based on num_nonzero and nonzero_result. */ int g_nonzero = num_nonzero == 0 ? nonzero_result : num_nonzero == 1 && !nonzero_result ? 1 : - (int)rustsecp256k1zkp_v0_8_0_testrand_bits(1); + (int)rustsecp256k1zkp_v0_10_0_testrand_bits(1); /* Which g_scalar pointer to pass into ecmult_multi(). */ - const rustsecp256k1zkp_v0_8_0_scalar* g_scalar_ptr = (g_nonzero || rustsecp256k1zkp_v0_8_0_testrand_bits(1)) ? &g_scalar : NULL; + const rustsecp256k1zkp_v0_10_0_scalar* g_scalar_ptr = (g_nonzero || rustsecp256k1zkp_v0_10_0_testrand_bits(1)) ? &g_scalar : NULL; /* How many EC multiplications were performed in this function. */ int mults = 0; /* How many randomization steps to apply to the input list. */ - int rands = (int)rustsecp256k1zkp_v0_8_0_testrand_bits(3); + int rands = (int)rustsecp256k1zkp_v0_10_0_testrand_bits(3); if (rands > num_nonzero) rands = num_nonzero; - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&expected); - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&gejs[0]); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&scalars[0], 0); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&expected); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&gejs[0]); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&scalars[0], 0); if (g_nonzero) { /* If g_nonzero, set g_scalar to nonzero value r. */ @@ -4618,10 +5104,10 @@ int test_ecmult_multi_random(rustsecp256k1zkp_v0_8_0_scratch *scratch) { /* If expected=0 is desired, add a (a*r, -(1/a)*g) term to compensate. */ CHECK(num_nonzero > filled); random_scalar_order_test(&sc_tmp); - rustsecp256k1zkp_v0_8_0_scalar_mul(&scalars[filled], &sc_tmp, &g_scalar); - rustsecp256k1zkp_v0_8_0_scalar_inverse_var(&sc_tmp, &sc_tmp); - rustsecp256k1zkp_v0_8_0_scalar_negate(&sc_tmp, &sc_tmp); - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &gejs[filled], &sc_tmp); + rustsecp256k1zkp_v0_10_0_scalar_mul(&scalars[filled], &sc_tmp, &g_scalar); + rustsecp256k1zkp_v0_10_0_scalar_inverse_var(&sc_tmp, &sc_tmp); + rustsecp256k1zkp_v0_10_0_scalar_negate(&sc_tmp, &sc_tmp); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&CTX->ecmult_gen_ctx, &gejs[filled], &sc_tmp); ++filled; ++mults; } @@ -4631,14 +5117,14 @@ int test_ecmult_multi_random(rustsecp256k1zkp_v0_8_0_scratch *scratch) { /* If a nonzero result is desired, and there is space, add a random nonzero term. */ random_scalar_order_test(&scalars[filled]); random_group_element_test(&ge_tmp); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&gejs[filled], &ge_tmp); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&gejs[filled], &ge_tmp); ++filled; } if (nonzero_result) { /* Compute the expected result using normal ecmult. */ CHECK(filled <= 1); - rustsecp256k1zkp_v0_8_0_ecmult(&expected, &gejs[0], &scalars[0], &g_scalar); + rustsecp256k1zkp_v0_10_0_ecmult(&expected, &gejs[0], &scalars[0], &g_scalar); mults += filled + g_nonzero; } @@ -4649,13 +5135,13 @@ int test_ecmult_multi_random(rustsecp256k1zkp_v0_8_0_scratch *scratch) { /* Add entries to scalars,gejs so that there are num of them. All the added entries * either have scalar=0 or point=infinity, so these do not change the expected result. */ while (filled < num) { - if (rustsecp256k1zkp_v0_8_0_testrand_bits(1)) { - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&gejs[filled]); + if (rustsecp256k1zkp_v0_10_0_testrand_bits(1)) { + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&gejs[filled]); random_scalar_order_test(&scalars[filled]); } else { - rustsecp256k1zkp_v0_8_0_scalar_set_int(&scalars[filled], 0); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&scalars[filled], 0); random_group_element_test(&ge_tmp); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&gejs[filled], &ge_tmp); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&gejs[filled], &ge_tmp); } ++filled; } @@ -4665,13 +5151,13 @@ int test_ecmult_multi_random(rustsecp256k1zkp_v0_8_0_scratch *scratch) { * convert some of them to be both non-0-scalar and non-infinity-point. */ for (i = 0; i < rands; ++i) { int j; - rustsecp256k1zkp_v0_8_0_scalar v, iv; + rustsecp256k1zkp_v0_10_0_scalar v, iv; /* Shuffle the entries. */ for (j = 0; j < num_nonzero; ++j) { - int k = rustsecp256k1zkp_v0_8_0_testrand_int(num_nonzero - j); + int k = rustsecp256k1zkp_v0_10_0_testrand_int(num_nonzero - j); if (k != 0) { - rustsecp256k1zkp_v0_8_0_gej gej = gejs[j]; - rustsecp256k1zkp_v0_8_0_scalar sc = scalars[j]; + rustsecp256k1zkp_v0_10_0_gej gej = gejs[j]; + rustsecp256k1zkp_v0_10_0_scalar sc = scalars[j]; gejs[j] = gejs[j + k]; scalars[j] = scalars[j + k]; gejs[j + k] = gej; @@ -4681,26 +5167,26 @@ int test_ecmult_multi_random(rustsecp256k1zkp_v0_8_0_scratch *scratch) { /* Perturb all consecutive pairs of inputs: * a*P + b*Q -> (a+b)*P + b*(Q-P). */ for (j = 0; j + 1 < num_nonzero; j += 2) { - rustsecp256k1zkp_v0_8_0_gej gej; - rustsecp256k1zkp_v0_8_0_scalar_add(&scalars[j], &scalars[j], &scalars[j+1]); - rustsecp256k1zkp_v0_8_0_gej_neg(&gej, &gejs[j]); - rustsecp256k1zkp_v0_8_0_gej_add_var(&gejs[j+1], &gejs[j+1], &gej, NULL); + rustsecp256k1zkp_v0_10_0_gej gej; + rustsecp256k1zkp_v0_10_0_scalar_add(&scalars[j], &scalars[j], &scalars[j+1]); + rustsecp256k1zkp_v0_10_0_gej_neg(&gej, &gejs[j]); + rustsecp256k1zkp_v0_10_0_gej_add_var(&gejs[j+1], &gejs[j+1], &gej, NULL); } /* Transform the last input: a*P -> (v*a) * ((1/v)*P). */ CHECK(num_nonzero >= 1); random_scalar_order_test(&v); - rustsecp256k1zkp_v0_8_0_scalar_inverse(&iv, &v); - rustsecp256k1zkp_v0_8_0_scalar_mul(&scalars[num_nonzero - 1], &scalars[num_nonzero - 1], &v); - rustsecp256k1zkp_v0_8_0_ecmult(&gejs[num_nonzero - 1], &gejs[num_nonzero - 1], &iv, NULL); + rustsecp256k1zkp_v0_10_0_scalar_inverse(&iv, &v); + rustsecp256k1zkp_v0_10_0_scalar_mul(&scalars[num_nonzero - 1], &scalars[num_nonzero - 1], &v); + rustsecp256k1zkp_v0_10_0_ecmult(&gejs[num_nonzero - 1], &gejs[num_nonzero - 1], &iv, NULL); ++mults; } /* Shuffle all entries (0..num-1). */ for (i = 0; i < num; ++i) { - int j = rustsecp256k1zkp_v0_8_0_testrand_int(num - i); + int j = rustsecp256k1zkp_v0_10_0_testrand_int(num - i); if (j != 0) { - rustsecp256k1zkp_v0_8_0_gej gej = gejs[i]; - rustsecp256k1zkp_v0_8_0_scalar sc = scalars[i]; + rustsecp256k1zkp_v0_10_0_gej gej = gejs[i]; + rustsecp256k1zkp_v0_10_0_scalar sc = scalars[i]; gejs[i] = gejs[i + j]; scalars[i] = scalars[i + j]; gejs[i + j] = gej; @@ -4709,51 +5195,47 @@ int test_ecmult_multi_random(rustsecp256k1zkp_v0_8_0_scratch *scratch) { } /* Compute affine versions of all inputs. */ - rustsecp256k1zkp_v0_8_0_ge_set_all_gej_var(ges, gejs, filled); + rustsecp256k1zkp_v0_10_0_ge_set_all_gej_var(ges, gejs, filled); /* Invoke ecmult_multi code. */ data.sc = scalars; data.pt = ges; - CHECK(ecmult_multi(&ctx->error_callback, scratch, &computed, g_scalar_ptr, ecmult_multi_callback, &data, filled)); + CHECK(ecmult_multi(&CTX->error_callback, scratch, &computed, g_scalar_ptr, ecmult_multi_callback, &data, filled)); mults += num_nonzero + g_nonzero; /* Compare with expected result. */ - rustsecp256k1zkp_v0_8_0_gej_neg(&computed, &computed); - rustsecp256k1zkp_v0_8_0_gej_add_var(&computed, &computed, &expected, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&computed)); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_var(&computed, &expected)); return mults; } -void test_ecmult_multi_batch_single(rustsecp256k1zkp_v0_8_0_ecmult_multi_func ecmult_multi) { - rustsecp256k1zkp_v0_8_0_scalar szero; - rustsecp256k1zkp_v0_8_0_scalar sc; - rustsecp256k1zkp_v0_8_0_ge pt; - rustsecp256k1zkp_v0_8_0_gej r; +static void test_ecmult_multi_batch_single(rustsecp256k1zkp_v0_10_0_ecmult_multi_func ecmult_multi) { + rustsecp256k1zkp_v0_10_0_scalar sc; + rustsecp256k1zkp_v0_10_0_ge pt; + rustsecp256k1zkp_v0_10_0_gej r; ecmult_multi_data data; - rustsecp256k1zkp_v0_8_0_scratch *scratch_empty; + rustsecp256k1zkp_v0_10_0_scratch *scratch_empty; random_group_element_test(&pt); random_scalar_order(&sc); data.sc = ≻ data.pt = &pt; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&szero, 0); /* Try to multiply 1 point, but scratch space is empty.*/ - scratch_empty = rustsecp256k1zkp_v0_8_0_scratch_create(&ctx->error_callback, 0); - CHECK(!ecmult_multi(&ctx->error_callback, scratch_empty, &r, &szero, ecmult_multi_callback, &data, 1)); - rustsecp256k1zkp_v0_8_0_scratch_destroy(&ctx->error_callback, scratch_empty); + scratch_empty = rustsecp256k1zkp_v0_10_0_scratch_create(&CTX->error_callback, 0); + CHECK(!ecmult_multi(&CTX->error_callback, scratch_empty, &r, &rustsecp256k1zkp_v0_10_0_scalar_zero, ecmult_multi_callback, &data, 1)); + rustsecp256k1zkp_v0_10_0_scratch_destroy(&CTX->error_callback, scratch_empty); } -void test_rustsecp256k1zkp_v0_8_0_pippenger_bucket_window_inv(void) { +static void test_rustsecp256k1zkp_v0_10_0_pippenger_bucket_window_inv(void) { int i; - CHECK(rustsecp256k1zkp_v0_8_0_pippenger_bucket_window_inv(0) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_pippenger_bucket_window_inv(0) == 0); for(i = 1; i <= PIPPENGER_MAX_BUCKET_WINDOW; i++) { /* Bucket_window of 8 is not used with endo */ if (i == 8) { continue; } - CHECK(rustsecp256k1zkp_v0_8_0_pippenger_bucket_window(rustsecp256k1zkp_v0_8_0_pippenger_bucket_window_inv(i)) == i); + CHECK(rustsecp256k1zkp_v0_10_0_pippenger_bucket_window(rustsecp256k1zkp_v0_10_0_pippenger_bucket_window_inv(i)) == i); if (i != PIPPENGER_MAX_BUCKET_WINDOW) { - CHECK(rustsecp256k1zkp_v0_8_0_pippenger_bucket_window(rustsecp256k1zkp_v0_8_0_pippenger_bucket_window_inv(i)+1) > i); + CHECK(rustsecp256k1zkp_v0_10_0_pippenger_bucket_window(rustsecp256k1zkp_v0_10_0_pippenger_bucket_window_inv(i)+1) > i); } } } @@ -4762,10 +5244,10 @@ void test_rustsecp256k1zkp_v0_8_0_pippenger_bucket_window_inv(void) { * Probabilistically test the function returning the maximum number of possible points * for a given scratch space. */ -void test_ecmult_multi_pippenger_max_points(void) { - size_t scratch_size = rustsecp256k1zkp_v0_8_0_testrand_bits(8); - size_t max_size = rustsecp256k1zkp_v0_8_0_pippenger_scratch_size(rustsecp256k1zkp_v0_8_0_pippenger_bucket_window_inv(PIPPENGER_MAX_BUCKET_WINDOW-1)+512, 12); - rustsecp256k1zkp_v0_8_0_scratch *scratch; +static void test_ecmult_multi_pippenger_max_points(void) { + size_t scratch_size = rustsecp256k1zkp_v0_10_0_testrand_bits(8); + size_t max_size = rustsecp256k1zkp_v0_10_0_pippenger_scratch_size(rustsecp256k1zkp_v0_10_0_pippenger_bucket_window_inv(PIPPENGER_MAX_BUCKET_WINDOW-1)+512, 12); + rustsecp256k1zkp_v0_10_0_scratch *scratch; size_t n_points_supported; int bucket_window = 0; @@ -4773,183 +5255,181 @@ void test_ecmult_multi_pippenger_max_points(void) { size_t i; size_t total_alloc; size_t checkpoint; - scratch = rustsecp256k1zkp_v0_8_0_scratch_create(&ctx->error_callback, scratch_size); + scratch = rustsecp256k1zkp_v0_10_0_scratch_create(&CTX->error_callback, scratch_size); CHECK(scratch != NULL); - checkpoint = rustsecp256k1zkp_v0_8_0_scratch_checkpoint(&ctx->error_callback, scratch); - n_points_supported = rustsecp256k1zkp_v0_8_0_pippenger_max_points(&ctx->error_callback, scratch); + checkpoint = rustsecp256k1zkp_v0_10_0_scratch_checkpoint(&CTX->error_callback, scratch); + n_points_supported = rustsecp256k1zkp_v0_10_0_pippenger_max_points(&CTX->error_callback, scratch); if (n_points_supported == 0) { - rustsecp256k1zkp_v0_8_0_scratch_destroy(&ctx->error_callback, scratch); + rustsecp256k1zkp_v0_10_0_scratch_destroy(&CTX->error_callback, scratch); continue; } - bucket_window = rustsecp256k1zkp_v0_8_0_pippenger_bucket_window(n_points_supported); + bucket_window = rustsecp256k1zkp_v0_10_0_pippenger_bucket_window(n_points_supported); /* allocate `total_alloc` bytes over `PIPPENGER_SCRATCH_OBJECTS` many allocations */ - total_alloc = rustsecp256k1zkp_v0_8_0_pippenger_scratch_size(n_points_supported, bucket_window); + total_alloc = rustsecp256k1zkp_v0_10_0_pippenger_scratch_size(n_points_supported, bucket_window); for (i = 0; i < PIPPENGER_SCRATCH_OBJECTS - 1; i++) { - CHECK(rustsecp256k1zkp_v0_8_0_scratch_alloc(&ctx->error_callback, scratch, 1)); + CHECK(rustsecp256k1zkp_v0_10_0_scratch_alloc(&CTX->error_callback, scratch, 1)); total_alloc--; } - CHECK(rustsecp256k1zkp_v0_8_0_scratch_alloc(&ctx->error_callback, scratch, total_alloc)); - rustsecp256k1zkp_v0_8_0_scratch_apply_checkpoint(&ctx->error_callback, scratch, checkpoint); - rustsecp256k1zkp_v0_8_0_scratch_destroy(&ctx->error_callback, scratch); + CHECK(rustsecp256k1zkp_v0_10_0_scratch_alloc(&CTX->error_callback, scratch, total_alloc)); + rustsecp256k1zkp_v0_10_0_scratch_apply_checkpoint(&CTX->error_callback, scratch, checkpoint); + rustsecp256k1zkp_v0_10_0_scratch_destroy(&CTX->error_callback, scratch); } CHECK(bucket_window == PIPPENGER_MAX_BUCKET_WINDOW); } -void test_ecmult_multi_batch_size_helper(void) { +static void test_ecmult_multi_batch_size_helper(void) { size_t n_batches, n_batch_points, max_n_batch_points, n; max_n_batch_points = 0; n = 1; - CHECK(rustsecp256k1zkp_v0_8_0_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 0); max_n_batch_points = 1; n = 0; - CHECK(rustsecp256k1zkp_v0_8_0_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 1); CHECK(n_batches == 0); CHECK(n_batch_points == 0); max_n_batch_points = 2; n = 5; - CHECK(rustsecp256k1zkp_v0_8_0_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 1); CHECK(n_batches == 3); CHECK(n_batch_points == 2); max_n_batch_points = ECMULT_MAX_POINTS_PER_BATCH; n = ECMULT_MAX_POINTS_PER_BATCH; - CHECK(rustsecp256k1zkp_v0_8_0_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 1); CHECK(n_batches == 1); CHECK(n_batch_points == ECMULT_MAX_POINTS_PER_BATCH); max_n_batch_points = ECMULT_MAX_POINTS_PER_BATCH + 1; n = ECMULT_MAX_POINTS_PER_BATCH + 1; - CHECK(rustsecp256k1zkp_v0_8_0_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 1); CHECK(n_batches == 2); CHECK(n_batch_points == ECMULT_MAX_POINTS_PER_BATCH/2 + 1); max_n_batch_points = 1; n = SIZE_MAX; - CHECK(rustsecp256k1zkp_v0_8_0_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 1); CHECK(n_batches == SIZE_MAX); CHECK(n_batch_points == 1); max_n_batch_points = 2; n = SIZE_MAX; - CHECK(rustsecp256k1zkp_v0_8_0_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 1); CHECK(n_batches == SIZE_MAX/2 + 1); CHECK(n_batch_points == 2); } /** - * Run rustsecp256k1zkp_v0_8_0_ecmult_multi_var with num points and a scratch space restricted to + * Run rustsecp256k1zkp_v0_10_0_ecmult_multi_var with num points and a scratch space restricted to * 1 <= i <= num points. */ -void test_ecmult_multi_batching(void) { +static void test_ecmult_multi_batching(void) { static const int n_points = 2*ECMULT_PIPPENGER_THRESHOLD; - rustsecp256k1zkp_v0_8_0_scalar scG; - rustsecp256k1zkp_v0_8_0_scalar szero; - rustsecp256k1zkp_v0_8_0_scalar *sc = (rustsecp256k1zkp_v0_8_0_scalar *)checked_malloc(&ctx->error_callback, sizeof(rustsecp256k1zkp_v0_8_0_scalar) * n_points); - rustsecp256k1zkp_v0_8_0_ge *pt = (rustsecp256k1zkp_v0_8_0_ge *)checked_malloc(&ctx->error_callback, sizeof(rustsecp256k1zkp_v0_8_0_ge) * n_points); - rustsecp256k1zkp_v0_8_0_gej r; - rustsecp256k1zkp_v0_8_0_gej r2; + rustsecp256k1zkp_v0_10_0_scalar scG; + rustsecp256k1zkp_v0_10_0_scalar *sc = (rustsecp256k1zkp_v0_10_0_scalar *)checked_malloc(&CTX->error_callback, sizeof(rustsecp256k1zkp_v0_10_0_scalar) * n_points); + rustsecp256k1zkp_v0_10_0_ge *pt = (rustsecp256k1zkp_v0_10_0_ge *)checked_malloc(&CTX->error_callback, sizeof(rustsecp256k1zkp_v0_10_0_ge) * n_points); + rustsecp256k1zkp_v0_10_0_gej r; + rustsecp256k1zkp_v0_10_0_gej r2; ecmult_multi_data data; int i; - rustsecp256k1zkp_v0_8_0_scratch *scratch; + rustsecp256k1zkp_v0_10_0_scratch *scratch; - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&r2); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&szero, 0); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&r2); /* Get random scalars and group elements and compute result */ random_scalar_order(&scG); - rustsecp256k1zkp_v0_8_0_ecmult(&r2, &r2, &szero, &scG); + rustsecp256k1zkp_v0_10_0_ecmult(&r2, &r2, &rustsecp256k1zkp_v0_10_0_scalar_zero, &scG); for(i = 0; i < n_points; i++) { - rustsecp256k1zkp_v0_8_0_ge ptg; - rustsecp256k1zkp_v0_8_0_gej ptgj; + rustsecp256k1zkp_v0_10_0_ge ptg; + rustsecp256k1zkp_v0_10_0_gej ptgj; random_group_element_test(&ptg); - rustsecp256k1zkp_v0_8_0_gej_set_ge(&ptgj, &ptg); + rustsecp256k1zkp_v0_10_0_gej_set_ge(&ptgj, &ptg); pt[i] = ptg; random_scalar_order(&sc[i]); - rustsecp256k1zkp_v0_8_0_ecmult(&ptgj, &ptgj, &sc[i], NULL); - rustsecp256k1zkp_v0_8_0_gej_add_var(&r2, &r2, &ptgj, NULL); + rustsecp256k1zkp_v0_10_0_ecmult(&ptgj, &ptgj, &sc[i], NULL); + rustsecp256k1zkp_v0_10_0_gej_add_var(&r2, &r2, &ptgj, NULL); } data.sc = sc; data.pt = pt; - rustsecp256k1zkp_v0_8_0_gej_neg(&r2, &r2); + rustsecp256k1zkp_v0_10_0_gej_neg(&r2, &r2); /* Test with empty scratch space. It should compute the correct result using * ecmult_mult_simple algorithm which doesn't require a scratch space. */ - scratch = rustsecp256k1zkp_v0_8_0_scratch_create(&ctx->error_callback, 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecmult_multi_var(&ctx->error_callback, scratch, &r, &scG, ecmult_multi_callback, &data, n_points)); - rustsecp256k1zkp_v0_8_0_gej_add_var(&r, &r, &r2, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&r)); - rustsecp256k1zkp_v0_8_0_scratch_destroy(&ctx->error_callback, scratch); + scratch = rustsecp256k1zkp_v0_10_0_scratch_create(&CTX->error_callback, 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecmult_multi_var(&CTX->error_callback, scratch, &r, &scG, ecmult_multi_callback, &data, n_points)); + rustsecp256k1zkp_v0_10_0_gej_add_var(&r, &r, &r2, NULL); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&r)); + rustsecp256k1zkp_v0_10_0_scratch_destroy(&CTX->error_callback, scratch); /* Test with space for 1 point in pippenger. That's not enough because * ecmult_multi selects strauss which requires more memory. It should * therefore select the simple algorithm. */ - scratch = rustsecp256k1zkp_v0_8_0_scratch_create(&ctx->error_callback, rustsecp256k1zkp_v0_8_0_pippenger_scratch_size(1, 1) + PIPPENGER_SCRATCH_OBJECTS*ALIGNMENT); - CHECK(rustsecp256k1zkp_v0_8_0_ecmult_multi_var(&ctx->error_callback, scratch, &r, &scG, ecmult_multi_callback, &data, n_points)); - rustsecp256k1zkp_v0_8_0_gej_add_var(&r, &r, &r2, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&r)); - rustsecp256k1zkp_v0_8_0_scratch_destroy(&ctx->error_callback, scratch); + scratch = rustsecp256k1zkp_v0_10_0_scratch_create(&CTX->error_callback, rustsecp256k1zkp_v0_10_0_pippenger_scratch_size(1, 1) + PIPPENGER_SCRATCH_OBJECTS*ALIGNMENT); + CHECK(rustsecp256k1zkp_v0_10_0_ecmult_multi_var(&CTX->error_callback, scratch, &r, &scG, ecmult_multi_callback, &data, n_points)); + rustsecp256k1zkp_v0_10_0_gej_add_var(&r, &r, &r2, NULL); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&r)); + rustsecp256k1zkp_v0_10_0_scratch_destroy(&CTX->error_callback, scratch); for(i = 1; i <= n_points; i++) { if (i > ECMULT_PIPPENGER_THRESHOLD) { - int bucket_window = rustsecp256k1zkp_v0_8_0_pippenger_bucket_window(i); - size_t scratch_size = rustsecp256k1zkp_v0_8_0_pippenger_scratch_size(i, bucket_window); - scratch = rustsecp256k1zkp_v0_8_0_scratch_create(&ctx->error_callback, scratch_size + PIPPENGER_SCRATCH_OBJECTS*ALIGNMENT); + int bucket_window = rustsecp256k1zkp_v0_10_0_pippenger_bucket_window(i); + size_t scratch_size = rustsecp256k1zkp_v0_10_0_pippenger_scratch_size(i, bucket_window); + scratch = rustsecp256k1zkp_v0_10_0_scratch_create(&CTX->error_callback, scratch_size + PIPPENGER_SCRATCH_OBJECTS*ALIGNMENT); } else { - size_t scratch_size = rustsecp256k1zkp_v0_8_0_strauss_scratch_size(i); - scratch = rustsecp256k1zkp_v0_8_0_scratch_create(&ctx->error_callback, scratch_size + STRAUSS_SCRATCH_OBJECTS*ALIGNMENT); + size_t scratch_size = rustsecp256k1zkp_v0_10_0_strauss_scratch_size(i); + scratch = rustsecp256k1zkp_v0_10_0_scratch_create(&CTX->error_callback, scratch_size + STRAUSS_SCRATCH_OBJECTS*ALIGNMENT); } - CHECK(rustsecp256k1zkp_v0_8_0_ecmult_multi_var(&ctx->error_callback, scratch, &r, &scG, ecmult_multi_callback, &data, n_points)); - rustsecp256k1zkp_v0_8_0_gej_add_var(&r, &r, &r2, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&r)); - rustsecp256k1zkp_v0_8_0_scratch_destroy(&ctx->error_callback, scratch); + CHECK(rustsecp256k1zkp_v0_10_0_ecmult_multi_var(&CTX->error_callback, scratch, &r, &scG, ecmult_multi_callback, &data, n_points)); + rustsecp256k1zkp_v0_10_0_gej_add_var(&r, &r, &r2, NULL); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&r)); + rustsecp256k1zkp_v0_10_0_scratch_destroy(&CTX->error_callback, scratch); } free(sc); free(pt); } -void run_ecmult_multi_tests(void) { - rustsecp256k1zkp_v0_8_0_scratch *scratch; - int64_t todo = (int64_t)320 * count; +static void run_ecmult_multi_tests(void) { + rustsecp256k1zkp_v0_10_0_scratch *scratch; + int64_t todo = (int64_t)320 * COUNT; - test_rustsecp256k1zkp_v0_8_0_pippenger_bucket_window_inv(); + test_rustsecp256k1zkp_v0_10_0_pippenger_bucket_window_inv(); test_ecmult_multi_pippenger_max_points(); - scratch = rustsecp256k1zkp_v0_8_0_scratch_create(&ctx->error_callback, 819200); - test_ecmult_multi(scratch, rustsecp256k1zkp_v0_8_0_ecmult_multi_var); - test_ecmult_multi(NULL, rustsecp256k1zkp_v0_8_0_ecmult_multi_var); - test_ecmult_multi(scratch, rustsecp256k1zkp_v0_8_0_ecmult_pippenger_batch_single); - test_ecmult_multi_batch_single(rustsecp256k1zkp_v0_8_0_ecmult_pippenger_batch_single); - test_ecmult_multi(scratch, rustsecp256k1zkp_v0_8_0_ecmult_strauss_batch_single); - test_ecmult_multi_batch_single(rustsecp256k1zkp_v0_8_0_ecmult_strauss_batch_single); + scratch = rustsecp256k1zkp_v0_10_0_scratch_create(&CTX->error_callback, 819200); + test_ecmult_multi(scratch, rustsecp256k1zkp_v0_10_0_ecmult_multi_var); + test_ecmult_multi(NULL, rustsecp256k1zkp_v0_10_0_ecmult_multi_var); + test_ecmult_multi(scratch, rustsecp256k1zkp_v0_10_0_ecmult_pippenger_batch_single); + test_ecmult_multi_batch_single(rustsecp256k1zkp_v0_10_0_ecmult_pippenger_batch_single); + test_ecmult_multi(scratch, rustsecp256k1zkp_v0_10_0_ecmult_strauss_batch_single); + test_ecmult_multi_batch_single(rustsecp256k1zkp_v0_10_0_ecmult_strauss_batch_single); while (todo > 0) { todo -= test_ecmult_multi_random(scratch); } - rustsecp256k1zkp_v0_8_0_scratch_destroy(&ctx->error_callback, scratch); + rustsecp256k1zkp_v0_10_0_scratch_destroy(&CTX->error_callback, scratch); /* Run test_ecmult_multi with space for exactly one point */ - scratch = rustsecp256k1zkp_v0_8_0_scratch_create(&ctx->error_callback, rustsecp256k1zkp_v0_8_0_strauss_scratch_size(1) + STRAUSS_SCRATCH_OBJECTS*ALIGNMENT); - test_ecmult_multi(scratch, rustsecp256k1zkp_v0_8_0_ecmult_multi_var); - rustsecp256k1zkp_v0_8_0_scratch_destroy(&ctx->error_callback, scratch); + scratch = rustsecp256k1zkp_v0_10_0_scratch_create(&CTX->error_callback, rustsecp256k1zkp_v0_10_0_strauss_scratch_size(1) + STRAUSS_SCRATCH_OBJECTS*ALIGNMENT); + test_ecmult_multi(scratch, rustsecp256k1zkp_v0_10_0_ecmult_multi_var); + rustsecp256k1zkp_v0_10_0_scratch_destroy(&CTX->error_callback, scratch); test_ecmult_multi_batch_size_helper(); test_ecmult_multi_batching(); } -void test_wnaf(const rustsecp256k1zkp_v0_8_0_scalar *number, int w) { - rustsecp256k1zkp_v0_8_0_scalar x, two, t; +static void test_wnaf(const rustsecp256k1zkp_v0_10_0_scalar *number, int w) { + rustsecp256k1zkp_v0_10_0_scalar x, two, t; int wnaf[256]; int zeroes = -1; int i; int bits; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&x, 0); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&two, 2); - bits = rustsecp256k1zkp_v0_8_0_ecmult_wnaf(wnaf, 256, number, w); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&x, 0); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&two, 2); + bits = rustsecp256k1zkp_v0_10_0_ecmult_wnaf(wnaf, 256, number, w); CHECK(bits <= 256); for (i = bits-1; i >= 0; i--) { int v = wnaf[i]; - rustsecp256k1zkp_v0_8_0_scalar_mul(&x, &x, &two); + rustsecp256k1zkp_v0_10_0_scalar_mul(&x, &x, &two); if (v) { CHECK(zeroes == -1 || zeroes >= w-1); /* check that distance between non-zero elements is at least w-1 */ zeroes=0; @@ -4961,109 +5441,53 @@ void test_wnaf(const rustsecp256k1zkp_v0_8_0_scalar *number, int w) { zeroes++; } if (v >= 0) { - rustsecp256k1zkp_v0_8_0_scalar_set_int(&t, v); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&t, v); } else { - rustsecp256k1zkp_v0_8_0_scalar_set_int(&t, -v); - rustsecp256k1zkp_v0_8_0_scalar_negate(&t, &t); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&t, -v); + rustsecp256k1zkp_v0_10_0_scalar_negate(&t, &t); } - rustsecp256k1zkp_v0_8_0_scalar_add(&x, &x, &t); - } - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&x, number)); /* check that wnaf represents number */ -} - -void test_constant_wnaf_negate(const rustsecp256k1zkp_v0_8_0_scalar *number) { - rustsecp256k1zkp_v0_8_0_scalar neg1 = *number; - rustsecp256k1zkp_v0_8_0_scalar neg2 = *number; - int sign1 = 1; - int sign2 = 1; - - if (!rustsecp256k1zkp_v0_8_0_scalar_get_bits(&neg1, 0, 1)) { - rustsecp256k1zkp_v0_8_0_scalar_negate(&neg1, &neg1); - sign1 = -1; + rustsecp256k1zkp_v0_10_0_scalar_add(&x, &x, &t); } - sign2 = rustsecp256k1zkp_v0_8_0_scalar_cond_negate(&neg2, rustsecp256k1zkp_v0_8_0_scalar_is_even(&neg2)); - CHECK(sign1 == sign2); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&neg1, &neg2)); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&x, number)); /* check that wnaf represents number */ } -void test_constant_wnaf(const rustsecp256k1zkp_v0_8_0_scalar *number, int w) { - rustsecp256k1zkp_v0_8_0_scalar x, shift; +static void test_fixed_wnaf(const rustsecp256k1zkp_v0_10_0_scalar *number, int w) { + rustsecp256k1zkp_v0_10_0_scalar x, shift; int wnaf[256] = {0}; int i; int skew; - int bits = 256; - rustsecp256k1zkp_v0_8_0_scalar num = *number; - rustsecp256k1zkp_v0_8_0_scalar scalar_skew; + rustsecp256k1zkp_v0_10_0_scalar num, unused; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&x, 0); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&shift, 1 << w); - for (i = 0; i < 16; ++i) { - rustsecp256k1zkp_v0_8_0_scalar_shr_int(&num, 8); - } - bits = 128; - skew = rustsecp256k1zkp_v0_8_0_wnaf_const(wnaf, &num, w, bits); - - for (i = WNAF_SIZE_BITS(bits, w); i >= 0; --i) { - rustsecp256k1zkp_v0_8_0_scalar t; - int v = wnaf[i]; - CHECK(v != 0); /* check nonzero */ - CHECK(v & 1); /* check parity */ - CHECK(v > -(1 << w)); /* check range above */ - CHECK(v < (1 << w)); /* check range below */ - - rustsecp256k1zkp_v0_8_0_scalar_mul(&x, &x, &shift); - if (v >= 0) { - rustsecp256k1zkp_v0_8_0_scalar_set_int(&t, v); - } else { - rustsecp256k1zkp_v0_8_0_scalar_set_int(&t, -v); - rustsecp256k1zkp_v0_8_0_scalar_negate(&t, &t); - } - rustsecp256k1zkp_v0_8_0_scalar_add(&x, &x, &t); - } - /* Skew num because when encoding numbers as odd we use an offset */ - rustsecp256k1zkp_v0_8_0_scalar_set_int(&scalar_skew, skew); - rustsecp256k1zkp_v0_8_0_scalar_add(&num, &num, &scalar_skew); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&x, &num)); -} - -void test_fixed_wnaf(const rustsecp256k1zkp_v0_8_0_scalar *number, int w) { - rustsecp256k1zkp_v0_8_0_scalar x, shift; - int wnaf[256] = {0}; - int i; - int skew; - rustsecp256k1zkp_v0_8_0_scalar num = *number; - - rustsecp256k1zkp_v0_8_0_scalar_set_int(&x, 0); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&shift, 1 << w); - for (i = 0; i < 16; ++i) { - rustsecp256k1zkp_v0_8_0_scalar_shr_int(&num, 8); - } - skew = rustsecp256k1zkp_v0_8_0_wnaf_fixed(wnaf, &num, w); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&x, 0); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&shift, 1 << w); + /* Make num a 128-bit scalar. */ + rustsecp256k1zkp_v0_10_0_scalar_split_128(&num, &unused, number); + skew = rustsecp256k1zkp_v0_10_0_wnaf_fixed(wnaf, &num, w); for (i = WNAF_SIZE(w)-1; i >= 0; --i) { - rustsecp256k1zkp_v0_8_0_scalar t; + rustsecp256k1zkp_v0_10_0_scalar t; int v = wnaf[i]; CHECK(v == 0 || v & 1); /* check parity */ CHECK(v > -(1 << w)); /* check range above */ CHECK(v < (1 << w)); /* check range below */ - rustsecp256k1zkp_v0_8_0_scalar_mul(&x, &x, &shift); + rustsecp256k1zkp_v0_10_0_scalar_mul(&x, &x, &shift); if (v >= 0) { - rustsecp256k1zkp_v0_8_0_scalar_set_int(&t, v); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&t, v); } else { - rustsecp256k1zkp_v0_8_0_scalar_set_int(&t, -v); - rustsecp256k1zkp_v0_8_0_scalar_negate(&t, &t); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&t, -v); + rustsecp256k1zkp_v0_10_0_scalar_negate(&t, &t); } - rustsecp256k1zkp_v0_8_0_scalar_add(&x, &x, &t); + rustsecp256k1zkp_v0_10_0_scalar_add(&x, &x, &t); } /* If skew is 1 then add 1 to num */ - rustsecp256k1zkp_v0_8_0_scalar_cadd_bit(&num, 0, skew == 1); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&x, &num)); + rustsecp256k1zkp_v0_10_0_scalar_cadd_bit(&num, 0, skew == 1); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&x, &num)); } /* Checks that the first 8 elements of wnaf are equal to wnaf_expected and the * rest is 0.*/ -void test_fixed_wnaf_small_helper(int *wnaf, int *wnaf_expected, int w) { +static void test_fixed_wnaf_small_helper(int *wnaf, int *wnaf_expected, int w) { int i; for (i = WNAF_SIZE(w)-1; i >= 8; --i) { CHECK(wnaf[i] == 0); @@ -5073,23 +5497,23 @@ void test_fixed_wnaf_small_helper(int *wnaf, int *wnaf_expected, int w) { } } -void test_fixed_wnaf_small(void) { +static void test_fixed_wnaf_small(void) { int w = 4; int wnaf[256] = {0}; int i; int skew; - rustsecp256k1zkp_v0_8_0_scalar num; + rustsecp256k1zkp_v0_10_0_scalar num; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&num, 0); - skew = rustsecp256k1zkp_v0_8_0_wnaf_fixed(wnaf, &num, w); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&num, 0); + skew = rustsecp256k1zkp_v0_10_0_wnaf_fixed(wnaf, &num, w); for (i = WNAF_SIZE(w)-1; i >= 0; --i) { int v = wnaf[i]; CHECK(v == 0); } CHECK(skew == 0); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&num, 1); - skew = rustsecp256k1zkp_v0_8_0_wnaf_fixed(wnaf, &num, w); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&num, 1); + skew = rustsecp256k1zkp_v0_10_0_wnaf_fixed(wnaf, &num, w); for (i = WNAF_SIZE(w)-1; i >= 1; --i) { int v = wnaf[i]; CHECK(v == 0); @@ -5099,122 +5523,94 @@ void test_fixed_wnaf_small(void) { { int wnaf_expected[8] = { 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf }; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&num, 0xffffffff); - skew = rustsecp256k1zkp_v0_8_0_wnaf_fixed(wnaf, &num, w); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&num, 0xffffffff); + skew = rustsecp256k1zkp_v0_10_0_wnaf_fixed(wnaf, &num, w); test_fixed_wnaf_small_helper(wnaf, wnaf_expected, w); CHECK(skew == 0); } { int wnaf_expected[8] = { -1, -1, -1, -1, -1, -1, -1, 0xf }; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&num, 0xeeeeeeee); - skew = rustsecp256k1zkp_v0_8_0_wnaf_fixed(wnaf, &num, w); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&num, 0xeeeeeeee); + skew = rustsecp256k1zkp_v0_10_0_wnaf_fixed(wnaf, &num, w); test_fixed_wnaf_small_helper(wnaf, wnaf_expected, w); CHECK(skew == 1); } { int wnaf_expected[8] = { 1, 0, 1, 0, 1, 0, 1, 0 }; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&num, 0x01010101); - skew = rustsecp256k1zkp_v0_8_0_wnaf_fixed(wnaf, &num, w); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&num, 0x01010101); + skew = rustsecp256k1zkp_v0_10_0_wnaf_fixed(wnaf, &num, w); test_fixed_wnaf_small_helper(wnaf, wnaf_expected, w); CHECK(skew == 0); } { int wnaf_expected[8] = { -0xf, 0, 0xf, -0xf, 0, 0xf, 1, 0 }; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&num, 0x01ef1ef1); - skew = rustsecp256k1zkp_v0_8_0_wnaf_fixed(wnaf, &num, w); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&num, 0x01ef1ef1); + skew = rustsecp256k1zkp_v0_10_0_wnaf_fixed(wnaf, &num, w); test_fixed_wnaf_small_helper(wnaf, wnaf_expected, w); CHECK(skew == 0); } } -void run_wnaf(void) { +static void run_wnaf(void) { int i; - rustsecp256k1zkp_v0_8_0_scalar n = {{0}}; - - test_constant_wnaf(&n, 4); - /* Sanity check: 1 and 2 are the smallest odd and even numbers and should - * have easier-to-diagnose failure modes */ - n.d[0] = 1; - test_constant_wnaf(&n, 4); - n.d[0] = 2; - test_constant_wnaf(&n, 4); - /* Test -1, because it's a special case in wnaf_const */ - n = rustsecp256k1zkp_v0_8_0_scalar_one; - rustsecp256k1zkp_v0_8_0_scalar_negate(&n, &n); - test_constant_wnaf(&n, 4); - - /* Test -2, which may not lead to overflows in wnaf_const */ - rustsecp256k1zkp_v0_8_0_scalar_add(&n, &rustsecp256k1zkp_v0_8_0_scalar_one, &rustsecp256k1zkp_v0_8_0_scalar_one); - rustsecp256k1zkp_v0_8_0_scalar_negate(&n, &n); - test_constant_wnaf(&n, 4); - - /* Test (1/2) - 1 = 1/-2 and 1/2 = (1/-2) + 1 - as corner cases of negation handling in wnaf_const */ - rustsecp256k1zkp_v0_8_0_scalar_inverse(&n, &n); - test_constant_wnaf(&n, 4); - - rustsecp256k1zkp_v0_8_0_scalar_add(&n, &n, &rustsecp256k1zkp_v0_8_0_scalar_one); - test_constant_wnaf(&n, 4); + rustsecp256k1zkp_v0_10_0_scalar n; /* Test 0 for fixed wnaf */ test_fixed_wnaf_small(); /* Random tests */ - for (i = 0; i < count; i++) { + for (i = 0; i < COUNT; i++) { random_scalar_order(&n); test_wnaf(&n, 4+(i%10)); - test_constant_wnaf_negate(&n); - test_constant_wnaf(&n, 4 + (i % 10)); test_fixed_wnaf(&n, 4 + (i % 10)); } - rustsecp256k1zkp_v0_8_0_scalar_set_int(&n, 0); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_cond_negate(&n, 1) == -1); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_is_zero(&n)); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_cond_negate(&n, 0) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_is_zero(&n)); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&n, 0); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_cond_negate(&n, 1) == -1); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_is_zero(&n)); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_cond_negate(&n, 0) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_is_zero(&n)); } -static int test_ecmult_accumulate_cb(rustsecp256k1zkp_v0_8_0_scalar* sc, rustsecp256k1zkp_v0_8_0_ge* pt, size_t idx, void* data) { - const rustsecp256k1zkp_v0_8_0_scalar* indata = (const rustsecp256k1zkp_v0_8_0_scalar*)data; +static int test_ecmult_accumulate_cb(rustsecp256k1zkp_v0_10_0_scalar* sc, rustsecp256k1zkp_v0_10_0_ge* pt, size_t idx, void* data) { + const rustsecp256k1zkp_v0_10_0_scalar* indata = (const rustsecp256k1zkp_v0_10_0_scalar*)data; *sc = *indata; - *pt = rustsecp256k1zkp_v0_8_0_ge_const_g; + *pt = rustsecp256k1zkp_v0_10_0_ge_const_g; CHECK(idx == 0); return 1; } -void test_ecmult_accumulate(rustsecp256k1zkp_v0_8_0_sha256* acc, const rustsecp256k1zkp_v0_8_0_scalar* x, rustsecp256k1zkp_v0_8_0_scratch* scratch) { +static void test_ecmult_accumulate(rustsecp256k1zkp_v0_10_0_sha256* acc, const rustsecp256k1zkp_v0_10_0_scalar* x, rustsecp256k1zkp_v0_10_0_scratch* scratch) { /* Compute x*G in 6 different ways, serialize it uncompressed, and feed it into acc. */ - rustsecp256k1zkp_v0_8_0_gej rj1, rj2, rj3, rj4, rj5, rj6, gj, infj; - rustsecp256k1zkp_v0_8_0_ge r; - const rustsecp256k1zkp_v0_8_0_scalar zero = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0); + rustsecp256k1zkp_v0_10_0_gej rj1, rj2, rj3, rj4, rj5, rj6, gj, infj; + rustsecp256k1zkp_v0_10_0_ge r; unsigned char bytes[65]; size_t size = 65; - rustsecp256k1zkp_v0_8_0_gej_set_ge(&gj, &rustsecp256k1zkp_v0_8_0_ge_const_g); - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&infj); - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &rj1, x); - rustsecp256k1zkp_v0_8_0_ecmult(&rj2, &gj, x, &zero); - rustsecp256k1zkp_v0_8_0_ecmult(&rj3, &infj, &zero, x); - rustsecp256k1zkp_v0_8_0_ecmult_multi_var(NULL, scratch, &rj4, x, NULL, NULL, 0); - rustsecp256k1zkp_v0_8_0_ecmult_multi_var(NULL, scratch, &rj5, &zero, test_ecmult_accumulate_cb, (void*)x, 1); - rustsecp256k1zkp_v0_8_0_ecmult_const(&rj6, &rustsecp256k1zkp_v0_8_0_ge_const_g, x, 256); - rustsecp256k1zkp_v0_8_0_ge_set_gej_var(&r, &rj1); - ge_equals_gej(&r, &rj2); - ge_equals_gej(&r, &rj3); - ge_equals_gej(&r, &rj4); - ge_equals_gej(&r, &rj5); - ge_equals_gej(&r, &rj6); - if (rustsecp256k1zkp_v0_8_0_ge_is_infinity(&r)) { + rustsecp256k1zkp_v0_10_0_gej_set_ge(&gj, &rustsecp256k1zkp_v0_10_0_ge_const_g); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&infj); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&CTX->ecmult_gen_ctx, &rj1, x); + rustsecp256k1zkp_v0_10_0_ecmult(&rj2, &gj, x, &rustsecp256k1zkp_v0_10_0_scalar_zero); + rustsecp256k1zkp_v0_10_0_ecmult(&rj3, &infj, &rustsecp256k1zkp_v0_10_0_scalar_zero, x); + rustsecp256k1zkp_v0_10_0_ecmult_multi_var(NULL, scratch, &rj4, x, NULL, NULL, 0); + rustsecp256k1zkp_v0_10_0_ecmult_multi_var(NULL, scratch, &rj5, &rustsecp256k1zkp_v0_10_0_scalar_zero, test_ecmult_accumulate_cb, (void*)x, 1); + rustsecp256k1zkp_v0_10_0_ecmult_const(&rj6, &rustsecp256k1zkp_v0_10_0_ge_const_g, x); + rustsecp256k1zkp_v0_10_0_ge_set_gej_var(&r, &rj1); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&rj2, &r)); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&rj3, &r)); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&rj4, &r)); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&rj5, &r)); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&rj6, &r)); + if (rustsecp256k1zkp_v0_10_0_ge_is_infinity(&r)) { /* Store infinity as 0x00 */ const unsigned char zerobyte[1] = {0}; - rustsecp256k1zkp_v0_8_0_sha256_write(acc, zerobyte, 1); + rustsecp256k1zkp_v0_10_0_sha256_write(acc, zerobyte, 1); } else { /* Store other points using their uncompressed serialization. */ - rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&r, bytes, &size, 0); + rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&r, bytes, &size, 0); CHECK(size == 65); - rustsecp256k1zkp_v0_8_0_sha256_write(acc, bytes, size); + rustsecp256k1zkp_v0_10_0_sha256_write(acc, bytes, size); } } -void test_ecmult_constants_2bit(void) { +static void test_ecmult_constants_2bit(void) { /* Using test_ecmult_accumulate, test ecmult for: * - For i in 0..36: * - Key i @@ -5223,11 +5619,11 @@ void test_ecmult_constants_2bit(void) { * - For j in 1..255 (only odd values): * - Key (j*2^i) mod order */ - rustsecp256k1zkp_v0_8_0_scalar x; - rustsecp256k1zkp_v0_8_0_sha256 acc; + rustsecp256k1zkp_v0_10_0_scalar x; + rustsecp256k1zkp_v0_10_0_sha256 acc; unsigned char b32[32]; int i, j; - rustsecp256k1zkp_v0_8_0_scratch_space *scratch = rustsecp256k1zkp_v0_8_0_scratch_space_create(ctx, 65536); + rustsecp256k1zkp_v0_10_0_scratch_space *scratch = rustsecp256k1zkp_v0_10_0_scratch_space_create(CTX, 65536); /* Expected hash of all the computed points; created with an independent * implementation. */ @@ -5237,28 +5633,28 @@ void test_ecmult_constants_2bit(void) { 0x3a, 0x75, 0x87, 0x60, 0x1a, 0xf9, 0x63, 0x60, 0xd0, 0xcb, 0x1f, 0xaa, 0x85, 0x9a, 0xb7, 0xb4 }; - rustsecp256k1zkp_v0_8_0_sha256_initialize(&acc); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&acc); for (i = 0; i <= 36; ++i) { - rustsecp256k1zkp_v0_8_0_scalar_set_int(&x, i); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&x, i); test_ecmult_accumulate(&acc, &x, scratch); - rustsecp256k1zkp_v0_8_0_scalar_negate(&x, &x); + rustsecp256k1zkp_v0_10_0_scalar_negate(&x, &x); test_ecmult_accumulate(&acc, &x, scratch); }; for (i = 0; i < 256; ++i) { for (j = 1; j < 256; j += 2) { int k; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&x, j); - for (k = 0; k < i; ++k) rustsecp256k1zkp_v0_8_0_scalar_add(&x, &x, &x); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&x, j); + for (k = 0; k < i; ++k) rustsecp256k1zkp_v0_10_0_scalar_add(&x, &x, &x); test_ecmult_accumulate(&acc, &x, scratch); } } - rustsecp256k1zkp_v0_8_0_sha256_finalize(&acc, b32); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(b32, expected32, 32) == 0); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&acc, b32); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(b32, expected32, 32) == 0); - rustsecp256k1zkp_v0_8_0_scratch_space_destroy(ctx, scratch); + rustsecp256k1zkp_v0_10_0_scratch_space_destroy(CTX, scratch); } -void test_ecmult_constants_sha(uint32_t prefix, size_t iter, const unsigned char* expected32) { +static void test_ecmult_constants_sha(uint32_t prefix, size_t iter, const unsigned char* expected32) { /* Using test_ecmult_accumulate, test ecmult for: * - Key 0 * - Key 1 @@ -5266,42 +5662,42 @@ void test_ecmult_constants_sha(uint32_t prefix, size_t iter, const unsigned char * - For i in range(iter): * - Key SHA256(LE32(prefix) || LE16(i)) */ - rustsecp256k1zkp_v0_8_0_scalar x; - rustsecp256k1zkp_v0_8_0_sha256 acc; + rustsecp256k1zkp_v0_10_0_scalar x; + rustsecp256k1zkp_v0_10_0_sha256 acc; unsigned char b32[32]; unsigned char inp[6]; size_t i; - rustsecp256k1zkp_v0_8_0_scratch_space *scratch = rustsecp256k1zkp_v0_8_0_scratch_space_create(ctx, 65536); + rustsecp256k1zkp_v0_10_0_scratch_space *scratch = rustsecp256k1zkp_v0_10_0_scratch_space_create(CTX, 65536); inp[0] = prefix & 0xFF; inp[1] = (prefix >> 8) & 0xFF; inp[2] = (prefix >> 16) & 0xFF; inp[3] = (prefix >> 24) & 0xFF; - rustsecp256k1zkp_v0_8_0_sha256_initialize(&acc); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&x, 0); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&acc); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&x, 0); test_ecmult_accumulate(&acc, &x, scratch); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&x, 1); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&x, 1); test_ecmult_accumulate(&acc, &x, scratch); - rustsecp256k1zkp_v0_8_0_scalar_negate(&x, &x); + rustsecp256k1zkp_v0_10_0_scalar_negate(&x, &x); test_ecmult_accumulate(&acc, &x, scratch); for (i = 0; i < iter; ++i) { - rustsecp256k1zkp_v0_8_0_sha256 gen; + rustsecp256k1zkp_v0_10_0_sha256 gen; inp[4] = i & 0xff; inp[5] = (i >> 8) & 0xff; - rustsecp256k1zkp_v0_8_0_sha256_initialize(&gen); - rustsecp256k1zkp_v0_8_0_sha256_write(&gen, inp, sizeof(inp)); - rustsecp256k1zkp_v0_8_0_sha256_finalize(&gen, b32); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&x, b32, NULL); + rustsecp256k1zkp_v0_10_0_sha256_initialize(&gen); + rustsecp256k1zkp_v0_10_0_sha256_write(&gen, inp, sizeof(inp)); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&gen, b32); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&x, b32, NULL); test_ecmult_accumulate(&acc, &x, scratch); } - rustsecp256k1zkp_v0_8_0_sha256_finalize(&acc, b32); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(b32, expected32, 32) == 0); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&acc, b32); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(b32, expected32, 32) == 0); - rustsecp256k1zkp_v0_8_0_scratch_space_destroy(ctx, scratch); + rustsecp256k1zkp_v0_10_0_scratch_space_destroy(CTX, scratch); } -void run_ecmult_constants(void) { +static void run_ecmult_constants(void) { /* Expected hashes of all points in the tests below. Computed using an * independent implementation. */ static const unsigned char expected32_6bit20[32] = { @@ -5335,42 +5731,42 @@ void run_ecmult_constants(void) { } } -void test_ecmult_gen_blind(void) { +static void test_ecmult_gen_blind(void) { /* Test ecmult_gen() blinding and confirm that the blinding changes, the affine points match, and the z's don't match. */ - rustsecp256k1zkp_v0_8_0_scalar key; - rustsecp256k1zkp_v0_8_0_scalar b; + rustsecp256k1zkp_v0_10_0_scalar key; + rustsecp256k1zkp_v0_10_0_scalar b; unsigned char seed32[32]; - rustsecp256k1zkp_v0_8_0_gej pgej; - rustsecp256k1zkp_v0_8_0_gej pgej2; - rustsecp256k1zkp_v0_8_0_gej i; - rustsecp256k1zkp_v0_8_0_ge pge; + rustsecp256k1zkp_v0_10_0_gej pgej; + rustsecp256k1zkp_v0_10_0_gej pgej2; + rustsecp256k1zkp_v0_10_0_gej i; + rustsecp256k1zkp_v0_10_0_ge pge; random_scalar_order_test(&key); - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &pgej, &key); - rustsecp256k1zkp_v0_8_0_testrand256(seed32); - b = ctx->ecmult_gen_ctx.blind; - i = ctx->ecmult_gen_ctx.initial; - rustsecp256k1zkp_v0_8_0_ecmult_gen_blind(&ctx->ecmult_gen_ctx, seed32); - CHECK(!rustsecp256k1zkp_v0_8_0_scalar_eq(&b, &ctx->ecmult_gen_ctx.blind)); - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &pgej2, &key); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&CTX->ecmult_gen_ctx, &pgej, &key); + rustsecp256k1zkp_v0_10_0_testrand256(seed32); + b = CTX->ecmult_gen_ctx.blind; + i = CTX->ecmult_gen_ctx.initial; + rustsecp256k1zkp_v0_10_0_ecmult_gen_blind(&CTX->ecmult_gen_ctx, seed32); + CHECK(!rustsecp256k1zkp_v0_10_0_scalar_eq(&b, &CTX->ecmult_gen_ctx.blind)); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&CTX->ecmult_gen_ctx, &pgej2, &key); CHECK(!gej_xyz_equals_gej(&pgej, &pgej2)); - CHECK(!gej_xyz_equals_gej(&i, &ctx->ecmult_gen_ctx.initial)); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&pge, &pgej); - ge_equals_gej(&pge, &pgej2); + CHECK(!gej_xyz_equals_gej(&i, &CTX->ecmult_gen_ctx.initial)); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&pge, &pgej); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&pgej2, &pge)); } -void test_ecmult_gen_blind_reset(void) { +static void test_ecmult_gen_blind_reset(void) { /* Test ecmult_gen() blinding reset and confirm that the blinding is consistent. */ - rustsecp256k1zkp_v0_8_0_scalar b; - rustsecp256k1zkp_v0_8_0_gej initial; - rustsecp256k1zkp_v0_8_0_ecmult_gen_blind(&ctx->ecmult_gen_ctx, 0); - b = ctx->ecmult_gen_ctx.blind; - initial = ctx->ecmult_gen_ctx.initial; - rustsecp256k1zkp_v0_8_0_ecmult_gen_blind(&ctx->ecmult_gen_ctx, 0); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&b, &ctx->ecmult_gen_ctx.blind)); - CHECK(gej_xyz_equals_gej(&initial, &ctx->ecmult_gen_ctx.initial)); + rustsecp256k1zkp_v0_10_0_scalar b; + rustsecp256k1zkp_v0_10_0_gej initial; + rustsecp256k1zkp_v0_10_0_ecmult_gen_blind(&CTX->ecmult_gen_ctx, 0); + b = CTX->ecmult_gen_ctx.blind; + initial = CTX->ecmult_gen_ctx.initial; + rustsecp256k1zkp_v0_10_0_ecmult_gen_blind(&CTX->ecmult_gen_ctx, 0); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&b, &CTX->ecmult_gen_ctx.blind)); + CHECK(gej_xyz_equals_gej(&initial, &CTX->ecmult_gen_ctx.initial)); } -void run_ecmult_gen_blind(void) { +static void run_ecmult_gen_blind(void) { int i; test_ecmult_gen_blind_reset(); for (i = 0; i < 10; i++) { @@ -5379,46 +5775,46 @@ void run_ecmult_gen_blind(void) { } /***** ENDOMORPHISH TESTS *****/ -void test_scalar_split(const rustsecp256k1zkp_v0_8_0_scalar* full) { - rustsecp256k1zkp_v0_8_0_scalar s, s1, slam; +static void test_scalar_split(const rustsecp256k1zkp_v0_10_0_scalar* full) { + rustsecp256k1zkp_v0_10_0_scalar s, s1, slam; const unsigned char zero[32] = {0}; unsigned char tmp[32]; - rustsecp256k1zkp_v0_8_0_scalar_split_lambda(&s1, &slam, full); + rustsecp256k1zkp_v0_10_0_scalar_split_lambda(&s1, &slam, full); /* check slam*lambda + s1 == full */ - rustsecp256k1zkp_v0_8_0_scalar_mul(&s, &rustsecp256k1zkp_v0_8_0_const_lambda, &slam); - rustsecp256k1zkp_v0_8_0_scalar_add(&s, &s, &s1); - CHECK(rustsecp256k1zkp_v0_8_0_scalar_eq(&s, full)); + rustsecp256k1zkp_v0_10_0_scalar_mul(&s, &rustsecp256k1zkp_v0_10_0_const_lambda, &slam); + rustsecp256k1zkp_v0_10_0_scalar_add(&s, &s, &s1); + CHECK(rustsecp256k1zkp_v0_10_0_scalar_eq(&s, full)); /* check that both are <= 128 bits in size */ - if (rustsecp256k1zkp_v0_8_0_scalar_is_high(&s1)) { - rustsecp256k1zkp_v0_8_0_scalar_negate(&s1, &s1); + if (rustsecp256k1zkp_v0_10_0_scalar_is_high(&s1)) { + rustsecp256k1zkp_v0_10_0_scalar_negate(&s1, &s1); } - if (rustsecp256k1zkp_v0_8_0_scalar_is_high(&slam)) { - rustsecp256k1zkp_v0_8_0_scalar_negate(&slam, &slam); + if (rustsecp256k1zkp_v0_10_0_scalar_is_high(&slam)) { + rustsecp256k1zkp_v0_10_0_scalar_negate(&slam, &slam); } - rustsecp256k1zkp_v0_8_0_scalar_get_b32(tmp, &s1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(zero, tmp, 16) == 0); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(tmp, &slam); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(zero, tmp, 16) == 0); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(tmp, &s1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(zero, tmp, 16) == 0); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(tmp, &slam); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(zero, tmp, 16) == 0); } -void run_endomorphism_tests(void) { +static void run_endomorphism_tests(void) { unsigned i; - static rustsecp256k1zkp_v0_8_0_scalar s; - test_scalar_split(&rustsecp256k1zkp_v0_8_0_scalar_zero); - test_scalar_split(&rustsecp256k1zkp_v0_8_0_scalar_one); - rustsecp256k1zkp_v0_8_0_scalar_negate(&s,&rustsecp256k1zkp_v0_8_0_scalar_one); + static rustsecp256k1zkp_v0_10_0_scalar s; + test_scalar_split(&rustsecp256k1zkp_v0_10_0_scalar_zero); + test_scalar_split(&rustsecp256k1zkp_v0_10_0_scalar_one); + rustsecp256k1zkp_v0_10_0_scalar_negate(&s,&rustsecp256k1zkp_v0_10_0_scalar_one); test_scalar_split(&s); - test_scalar_split(&rustsecp256k1zkp_v0_8_0_const_lambda); - rustsecp256k1zkp_v0_8_0_scalar_add(&s, &rustsecp256k1zkp_v0_8_0_const_lambda, &rustsecp256k1zkp_v0_8_0_scalar_one); + test_scalar_split(&rustsecp256k1zkp_v0_10_0_const_lambda); + rustsecp256k1zkp_v0_10_0_scalar_add(&s, &rustsecp256k1zkp_v0_10_0_const_lambda, &rustsecp256k1zkp_v0_10_0_scalar_one); test_scalar_split(&s); - for (i = 0; i < 100U * count; ++i) { - rustsecp256k1zkp_v0_8_0_scalar full; + for (i = 0; i < 100U * COUNT; ++i) { + rustsecp256k1zkp_v0_10_0_scalar full; random_scalar_order_test(&full); test_scalar_split(&full); } @@ -5427,19 +5823,17 @@ void run_endomorphism_tests(void) { } } -void ec_pubkey_parse_pointtest(const unsigned char *input, int xvalid, int yvalid) { +static void ec_pubkey_parse_pointtest(const unsigned char *input, int xvalid, int yvalid) { unsigned char pubkeyc[65]; - rustsecp256k1zkp_v0_8_0_pubkey pubkey; - rustsecp256k1zkp_v0_8_0_ge ge; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_ge ge; size_t pubkeyclen; - int32_t ecount; - ecount = 0; - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(ctx, counting_illegal_callback_fn, &ecount); + for (pubkeyclen = 3; pubkeyclen <= 65; pubkeyclen++) { /* Smaller sizes are tested exhaustively elsewhere. */ int32_t i; memcpy(&pubkeyc[1], input, 64); - VG_UNDEF(&pubkeyc[pubkeyclen], 65 - pubkeyclen); + SECP256K1_CHECKMEM_UNDEFINE(&pubkeyc[pubkeyclen], 65 - pubkeyclen); for (i = 0; i < 256; i++) { /* Try all type bytes. */ int xpass; @@ -5458,51 +5852,45 @@ void ec_pubkey_parse_pointtest(const unsigned char *input, int xvalid, int yvali unsigned char pubkeyo[65]; size_t outl; memset(&pubkey, 0, sizeof(pubkey)); - VG_UNDEF(&pubkey, sizeof(pubkey)); - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pubkey, pubkeyc, pubkeyclen) == 1); - VG_CHECK(&pubkey, sizeof(pubkey)); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pubkey, pubkeyc, pubkeyclen) == 1); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(pubkey)); outl = 65; - VG_UNDEF(pubkeyo, 65); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, pubkeyo, &outl, &pubkey, SECP256K1_EC_COMPRESSED) == 1); - VG_CHECK(pubkeyo, outl); + SECP256K1_CHECKMEM_UNDEFINE(pubkeyo, 65); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(CTX, pubkeyo, &outl, &pubkey, SECP256K1_EC_COMPRESSED) == 1); + SECP256K1_CHECKMEM_CHECK(pubkeyo, outl); CHECK(outl == 33); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkeyo[1], &pubkeyc[1], 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkeyo[1], &pubkeyc[1], 32) == 0); CHECK((pubkeyclen != 33) || (pubkeyo[0] == pubkeyc[0])); if (ypass) { /* This test isn't always done because we decode with alternative signs, so the y won't match. */ CHECK(pubkeyo[0] == ysign); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &ge, &pubkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_pubkey_load(CTX, &ge, &pubkey) == 1); memset(&pubkey, 0, sizeof(pubkey)); - VG_UNDEF(&pubkey, sizeof(pubkey)); - rustsecp256k1zkp_v0_8_0_pubkey_save(&pubkey, &ge); - VG_CHECK(&pubkey, sizeof(pubkey)); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(pubkey)); + rustsecp256k1zkp_v0_10_0_pubkey_save(&pubkey, &ge); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(pubkey)); outl = 65; - VG_UNDEF(pubkeyo, 65); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, pubkeyo, &outl, &pubkey, SECP256K1_EC_UNCOMPRESSED) == 1); - VG_CHECK(pubkeyo, outl); + SECP256K1_CHECKMEM_UNDEFINE(pubkeyo, 65); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(CTX, pubkeyo, &outl, &pubkey, SECP256K1_EC_UNCOMPRESSED) == 1); + SECP256K1_CHECKMEM_CHECK(pubkeyo, outl); CHECK(outl == 65); CHECK(pubkeyo[0] == 4); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkeyo[1], input, 64) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkeyo[1], input, 64) == 0); } - CHECK(ecount == 0); } else { /* These cases must fail to parse. */ memset(&pubkey, 0xfe, sizeof(pubkey)); - ecount = 0; - VG_UNDEF(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pubkey, pubkeyc, pubkeyclen) == 0); - VG_CHECK(&pubkey, sizeof(pubkey)); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &ge, &pubkey) == 0); - CHECK(ecount == 1); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pubkey, pubkeyc, pubkeyclen) == 0); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(pubkey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pubkey_load(CTX, &ge, &pubkey)); } } } - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(ctx, NULL, NULL); } -void run_ec_pubkey_parse_test(void) { +static void run_ec_pubkey_parse_test(void) { #define SECP256K1_EC_PARSE_TEST_NVALID (12) const unsigned char valid[SECP256K1_EC_PARSE_TEST_NVALID][64] = { { @@ -5682,142 +6070,99 @@ void run_ec_pubkey_parse_test(void) { 0xB8, 0x00 }; unsigned char sout[65]; - unsigned char shortkey[2]; - rustsecp256k1zkp_v0_8_0_ge ge; - rustsecp256k1zkp_v0_8_0_pubkey pubkey; + unsigned char shortkey[2] = { 0 }; + rustsecp256k1zkp_v0_10_0_ge ge; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; size_t len; int32_t i; - int32_t ecount; - int32_t ecount2; - ecount = 0; + /* Nothing should be reading this far into pubkeyc. */ - VG_UNDEF(&pubkeyc[65], 1); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(ctx, counting_illegal_callback_fn, &ecount); + SECP256K1_CHECKMEM_UNDEFINE(&pubkeyc[65], 1); /* Zero length claimed, fail, zeroize, no illegal arg error. */ memset(&pubkey, 0xfe, sizeof(pubkey)); - ecount = 0; - VG_UNDEF(shortkey, 2); - VG_UNDEF(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pubkey, shortkey, 0) == 0); - VG_CHECK(&pubkey, sizeof(pubkey)); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &ge, &pubkey) == 0); - CHECK(ecount == 1); + SECP256K1_CHECKMEM_UNDEFINE(shortkey, 2); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pubkey, shortkey, 0) == 0); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(pubkey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pubkey_load(CTX, &ge, &pubkey)); /* Length one claimed, fail, zeroize, no illegal arg error. */ for (i = 0; i < 256 ; i++) { memset(&pubkey, 0xfe, sizeof(pubkey)); - ecount = 0; shortkey[0] = i; - VG_UNDEF(&shortkey[1], 1); - VG_UNDEF(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pubkey, shortkey, 1) == 0); - VG_CHECK(&pubkey, sizeof(pubkey)); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &ge, &pubkey) == 0); - CHECK(ecount == 1); + SECP256K1_CHECKMEM_UNDEFINE(&shortkey[1], 1); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pubkey, shortkey, 1) == 0); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(pubkey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pubkey_load(CTX, &ge, &pubkey)); } /* Length two claimed, fail, zeroize, no illegal arg error. */ for (i = 0; i < 65536 ; i++) { memset(&pubkey, 0xfe, sizeof(pubkey)); - ecount = 0; shortkey[0] = i & 255; shortkey[1] = i >> 8; - VG_UNDEF(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pubkey, shortkey, 2) == 0); - VG_CHECK(&pubkey, sizeof(pubkey)); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &ge, &pubkey) == 0); - CHECK(ecount == 1); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pubkey, shortkey, 2) == 0); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(pubkey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pubkey_load(CTX, &ge, &pubkey)); } memset(&pubkey, 0xfe, sizeof(pubkey)); - ecount = 0; - VG_UNDEF(&pubkey, sizeof(pubkey)); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(pubkey)); /* 33 bytes claimed on otherwise valid input starting with 0x04, fail, zeroize output, no illegal arg error. */ - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pubkey, pubkeyc, 33) == 0); - VG_CHECK(&pubkey, sizeof(pubkey)); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &ge, &pubkey) == 0); - CHECK(ecount == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pubkey, pubkeyc, 33) == 0); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(pubkey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pubkey_load(CTX, &ge, &pubkey)); /* NULL pubkey, illegal arg error. Pubkey isn't rewritten before this step, since it's NULL into the parser. */ - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, NULL, pubkeyc, 65) == 0); - CHECK(ecount == 2); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, NULL, pubkeyc, 65)); /* NULL input string. Illegal arg and zeroize output. */ memset(&pubkey, 0xfe, sizeof(pubkey)); - ecount = 0; - VG_UNDEF(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pubkey, NULL, 65) == 0); - VG_CHECK(&pubkey, sizeof(pubkey)); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &ge, &pubkey) == 0); - CHECK(ecount == 2); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(pubkey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pubkey, NULL, 65)); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(pubkey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pubkey_load(CTX, &ge, &pubkey)); /* 64 bytes claimed on input starting with 0x04, fail, zeroize output, no illegal arg error. */ memset(&pubkey, 0xfe, sizeof(pubkey)); - ecount = 0; - VG_UNDEF(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pubkey, pubkeyc, 64) == 0); - VG_CHECK(&pubkey, sizeof(pubkey)); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &ge, &pubkey) == 0); - CHECK(ecount == 1); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pubkey, pubkeyc, 64) == 0); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(pubkey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pubkey_load(CTX, &ge, &pubkey)); /* 66 bytes claimed, fail, zeroize output, no illegal arg error. */ memset(&pubkey, 0xfe, sizeof(pubkey)); - ecount = 0; - VG_UNDEF(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pubkey, pubkeyc, 66) == 0); - VG_CHECK(&pubkey, sizeof(pubkey)); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &ge, &pubkey) == 0); - CHECK(ecount == 1); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pubkey, pubkeyc, 66) == 0); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(pubkey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_pubkey_load(CTX, &ge, &pubkey)); /* Valid parse. */ memset(&pubkey, 0, sizeof(pubkey)); - ecount = 0; - VG_UNDEF(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pubkey, pubkeyc, 65) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(rustsecp256k1zkp_v0_8_0_context_no_precomp, &pubkey, pubkeyc, 65) == 1); - VG_CHECK(&pubkey, sizeof(pubkey)); - CHECK(ecount == 0); - VG_UNDEF(&ge, sizeof(ge)); - CHECK(rustsecp256k1zkp_v0_8_0_pubkey_load(ctx, &ge, &pubkey) == 1); - VG_CHECK(&ge.x, sizeof(ge.x)); - VG_CHECK(&ge.y, sizeof(ge.y)); - VG_CHECK(&ge.infinity, sizeof(ge.infinity)); - ge_equals_ge(&rustsecp256k1zkp_v0_8_0_ge_const_g, &ge); - CHECK(ecount == 0); - /* rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize illegal args. */ - ecount = 0; + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pubkey, pubkeyc, 65) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(rustsecp256k1zkp_v0_10_0_context_static, &pubkey, pubkeyc, 65) == 1); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(pubkey)); + SECP256K1_CHECKMEM_UNDEFINE(&ge, sizeof(ge)); + CHECK(rustsecp256k1zkp_v0_10_0_pubkey_load(CTX, &ge, &pubkey) == 1); + SECP256K1_CHECKMEM_CHECK(&ge.x, sizeof(ge.x)); + SECP256K1_CHECKMEM_CHECK(&ge.y, sizeof(ge.y)); + SECP256K1_CHECKMEM_CHECK(&ge.infinity, sizeof(ge.infinity)); + CHECK(rustsecp256k1zkp_v0_10_0_ge_eq_var(&ge, &rustsecp256k1zkp_v0_10_0_ge_const_g)); + /* rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize illegal args. */ len = 65; - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, NULL, &len, &pubkey, SECP256K1_EC_UNCOMPRESSED) == 0); - CHECK(ecount == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(CTX, NULL, &len, &pubkey, SECP256K1_EC_UNCOMPRESSED)); CHECK(len == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, sout, NULL, &pubkey, SECP256K1_EC_UNCOMPRESSED) == 0); - CHECK(ecount == 2); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(CTX, sout, NULL, &pubkey, SECP256K1_EC_UNCOMPRESSED)); len = 65; - VG_UNDEF(sout, 65); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, sout, &len, NULL, SECP256K1_EC_UNCOMPRESSED) == 0); - VG_CHECK(sout, 65); - CHECK(ecount == 3); + SECP256K1_CHECKMEM_UNDEFINE(sout, 65); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(CTX, sout, &len, NULL, SECP256K1_EC_UNCOMPRESSED)); + SECP256K1_CHECKMEM_CHECK(sout, 65); CHECK(len == 0); len = 65; - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, sout, &len, &pubkey, ~0) == 0); - CHECK(ecount == 4); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(CTX, sout, &len, &pubkey, ~0)); CHECK(len == 0); len = 65; - VG_UNDEF(sout, 65); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, sout, &len, &pubkey, SECP256K1_EC_UNCOMPRESSED) == 1); - VG_CHECK(sout, 65); - CHECK(ecount == 4); + SECP256K1_CHECKMEM_UNDEFINE(sout, 65); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(CTX, sout, &len, &pubkey, SECP256K1_EC_UNCOMPRESSED) == 1); + SECP256K1_CHECKMEM_CHECK(sout, 65); CHECK(len == 65); /* Multiple illegal args. Should still set arg error only once. */ - ecount = 0; - ecount2 = 11; - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, NULL, NULL, 65) == 0); - CHECK(ecount == 1); - /* Does the illegal arg callback actually change the behavior? */ - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(ctx, uncounting_illegal_callback_fn, &ecount2); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, NULL, NULL, 65) == 0); - CHECK(ecount == 1); - CHECK(ecount2 == 10); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(ctx, NULL, NULL); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, NULL, NULL, 65)); /* Try a bunch of prefabbed points with all possible encodings. */ for (i = 0; i < SECP256K1_EC_PARSE_TEST_NVALID; i++) { ec_pubkey_parse_pointtest(valid[i], 1, 1); @@ -5830,263 +6175,229 @@ void run_ec_pubkey_parse_test(void) { } } -void run_eckey_edge_case_test(void) { +static void run_eckey_edge_case_test(void) { const unsigned char orderc[32] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41 }; - const unsigned char zeros[sizeof(rustsecp256k1zkp_v0_8_0_pubkey)] = {0x00}; + const unsigned char zeros[sizeof(rustsecp256k1zkp_v0_10_0_pubkey)] = {0x00}; unsigned char ctmp[33]; unsigned char ctmp2[33]; - rustsecp256k1zkp_v0_8_0_pubkey pubkey; - rustsecp256k1zkp_v0_8_0_pubkey pubkey2; - rustsecp256k1zkp_v0_8_0_pubkey pubkey_one; - rustsecp256k1zkp_v0_8_0_pubkey pubkey_negone; - const rustsecp256k1zkp_v0_8_0_pubkey *pubkeys[3]; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_pubkey pubkey2; + rustsecp256k1zkp_v0_10_0_pubkey pubkey_one; + rustsecp256k1zkp_v0_10_0_pubkey pubkey_negone; + const rustsecp256k1zkp_v0_10_0_pubkey *pubkeys[3]; size_t len; - int32_t ecount; /* Group order is too large, reject. */ - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, orderc) == 0); - VG_UNDEF(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey, orderc) == 0); - VG_CHECK(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_verify(CTX, orderc) == 0); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey, orderc) == 0); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)) == 0); /* Maximum value is too large, reject. */ memset(ctmp, 255, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, ctmp) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_verify(CTX, ctmp) == 0); memset(&pubkey, 1, sizeof(pubkey)); - VG_UNDEF(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey, ctmp) == 0); - VG_CHECK(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)) == 0); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey, ctmp) == 0); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)) == 0); /* Zero is too small, reject. */ memset(ctmp, 0, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, ctmp) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_verify(CTX, ctmp) == 0); memset(&pubkey, 1, sizeof(pubkey)); - VG_UNDEF(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey, ctmp) == 0); - VG_CHECK(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)) == 0); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey, ctmp) == 0); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)) == 0); /* One must be accepted. */ ctmp[31] = 0x01; - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, ctmp) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_verify(CTX, ctmp) == 1); memset(&pubkey, 0, sizeof(pubkey)); - VG_UNDEF(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey, ctmp) == 1); - VG_CHECK(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)) > 0); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey, ctmp) == 1); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)) > 0); pubkey_one = pubkey; /* Group order + 1 is too large, reject. */ memcpy(ctmp, orderc, 32); ctmp[31] = 0x42; - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, ctmp) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_verify(CTX, ctmp) == 0); memset(&pubkey, 1, sizeof(pubkey)); - VG_UNDEF(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey, ctmp) == 0); - VG_CHECK(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)) == 0); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey, ctmp) == 0); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)) == 0); /* -1 must be accepted. */ ctmp[31] = 0x40; - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, ctmp) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_verify(CTX, ctmp) == 1); memset(&pubkey, 0, sizeof(pubkey)); - VG_UNDEF(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey, ctmp) == 1); - VG_CHECK(&pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)) > 0); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey, ctmp) == 1); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)) > 0); pubkey_negone = pubkey; /* Tweak of zero leaves the value unchanged. */ memset(ctmp2, 0, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add(ctx, ctmp, ctmp2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(orderc, ctmp, 31) == 0 && ctmp[31] == 0x40); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add(CTX, ctmp, ctmp2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(orderc, ctmp, 31) == 0 && ctmp[31] == 0x40); memcpy(&pubkey2, &pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add(ctx, &pubkey, ctmp2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, &pubkey2, sizeof(pubkey)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add(CTX, &pubkey, ctmp2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, &pubkey2, sizeof(pubkey)) == 0); /* Multiply tweak of zero zeroizes the output. */ - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_mul(ctx, ctmp, ctmp2) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(zeros, ctmp, 32) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_mul(ctx, &pubkey, ctmp2) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, zeros, sizeof(pubkey)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_mul(CTX, ctmp, ctmp2) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(zeros, ctmp, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_mul(CTX, &pubkey, ctmp2) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, zeros, sizeof(pubkey)) == 0); memcpy(&pubkey, &pubkey2, sizeof(pubkey)); /* If seckey_tweak_add or seckey_tweak_mul are called with an overflowing seckey, the seckey is zeroized. */ memcpy(ctmp, orderc, 32); memset(ctmp2, 0, 32); ctmp2[31] = 0x01; - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, ctmp2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, ctmp) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add(ctx, ctmp, ctmp2) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(zeros, ctmp, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_verify(CTX, ctmp2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_verify(CTX, ctmp) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add(CTX, ctmp, ctmp2) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(zeros, ctmp, 32) == 0); memcpy(ctmp, orderc, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_mul(ctx, ctmp, ctmp2) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(zeros, ctmp, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_mul(CTX, ctmp, ctmp2) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(zeros, ctmp, 32) == 0); /* If seckey_tweak_add or seckey_tweak_mul are called with an overflowing tweak, the seckey is zeroized. */ memcpy(ctmp, orderc, 32); ctmp[31] = 0x40; - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add(ctx, ctmp, orderc) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(zeros, ctmp, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add(CTX, ctmp, orderc) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(zeros, ctmp, 32) == 0); memcpy(ctmp, orderc, 32); ctmp[31] = 0x40; - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_mul(ctx, ctmp, orderc) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(zeros, ctmp, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_mul(CTX, ctmp, orderc) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(zeros, ctmp, 32) == 0); memcpy(ctmp, orderc, 32); ctmp[31] = 0x40; /* If pubkey_tweak_add or pubkey_tweak_mul are called with an overflowing tweak, the pubkey is zeroized. */ - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add(ctx, &pubkey, orderc) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, zeros, sizeof(pubkey)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add(CTX, &pubkey, orderc) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, zeros, sizeof(pubkey)) == 0); memcpy(&pubkey, &pubkey2, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_mul(ctx, &pubkey, orderc) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, zeros, sizeof(pubkey)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_mul(CTX, &pubkey, orderc) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, zeros, sizeof(pubkey)) == 0); memcpy(&pubkey, &pubkey2, sizeof(pubkey)); - /* If the resulting key in rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add and - * rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add is 0 the functions fail and in the latter + /* If the resulting key in rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add and + * rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add is 0 the functions fail and in the latter * case the pubkey is zeroized. */ memcpy(ctmp, orderc, 32); ctmp[31] = 0x40; memset(ctmp2, 0, 32); ctmp2[31] = 1; - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add(ctx, ctmp2, ctmp) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(zeros, ctmp2, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add(CTX, ctmp2, ctmp) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(zeros, ctmp2, 32) == 0); ctmp2[31] = 1; - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add(ctx, &pubkey, ctmp2) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, zeros, sizeof(pubkey)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add(CTX, &pubkey, ctmp2) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, zeros, sizeof(pubkey)) == 0); memcpy(&pubkey, &pubkey2, sizeof(pubkey)); /* Tweak computation wraps and results in a key of 1. */ ctmp2[31] = 2; - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add(ctx, ctmp2, ctmp) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(ctmp2, zeros, 31) == 0 && ctmp2[31] == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add(CTX, ctmp2, ctmp) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(ctmp2, zeros, 31) == 0 && ctmp2[31] == 1); ctmp2[31] = 2; - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add(ctx, &pubkey, ctmp2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add(CTX, &pubkey, ctmp2) == 1); ctmp2[31] = 1; - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey2, ctmp2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, &pubkey2, sizeof(pubkey)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey2, ctmp2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, &pubkey2, sizeof(pubkey)) == 0); /* Tweak mul * 2 = 1+1. */ - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add(ctx, &pubkey, ctmp2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add(CTX, &pubkey, ctmp2) == 1); ctmp2[31] = 2; - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_mul(ctx, &pubkey2, ctmp2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, &pubkey2, sizeof(pubkey)) == 0); - /* Test argument errors. */ - ecount = 0; - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(ctx, counting_illegal_callback_fn, &ecount); - CHECK(ecount == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_mul(CTX, &pubkey2, ctmp2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, &pubkey2, sizeof(pubkey)) == 0); /* Zeroize pubkey on parse error. */ memset(&pubkey, 0, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add(ctx, &pubkey, ctmp2) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, zeros, sizeof(pubkey)) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add(CTX, &pubkey, ctmp2)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, zeros, sizeof(pubkey)) == 0); memcpy(&pubkey, &pubkey2, sizeof(pubkey)); memset(&pubkey2, 0, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_mul(ctx, &pubkey2, ctmp2) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey2, zeros, sizeof(pubkey2)) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_mul(CTX, &pubkey2, ctmp2)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey2, zeros, sizeof(pubkey2)) == 0); /* Plain argument errors. */ - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, ctmp) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, NULL) == 0); - CHECK(ecount == 1); - ecount = 0; + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_verify(CTX, ctmp) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_seckey_verify(CTX, NULL)); memset(ctmp2, 0, 32); ctmp2[31] = 4; - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add(ctx, NULL, ctmp2) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add(ctx, &pubkey, NULL) == 0); - CHECK(ecount == 2); - ecount = 0; + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add(CTX, NULL, ctmp2)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add(CTX, &pubkey, NULL)); memset(ctmp2, 0, 32); ctmp2[31] = 4; - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_mul(ctx, NULL, ctmp2) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_mul(ctx, &pubkey, NULL) == 0); - CHECK(ecount == 2); - ecount = 0; + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_mul(CTX, NULL, ctmp2)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_mul(CTX, &pubkey, NULL)); memset(ctmp2, 0, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add(ctx, NULL, ctmp2) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add(ctx, ctmp, NULL) == 0); - CHECK(ecount == 2); - ecount = 0; + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add(CTX, NULL, ctmp2)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add(CTX, ctmp, NULL)); memset(ctmp2, 0, 32); ctmp2[31] = 1; - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_mul(ctx, NULL, ctmp2) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_mul(ctx, ctmp, NULL) == 0); - CHECK(ecount == 2); - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, NULL, ctmp) == 0); - CHECK(ecount == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_mul(CTX, NULL, ctmp2)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_mul(CTX, ctmp, NULL)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, NULL, ctmp)); memset(&pubkey, 1, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey, NULL) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)) == 0); - /* rustsecp256k1zkp_v0_8_0_ec_pubkey_combine tests. */ - ecount = 0; + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)) == 0); + /* rustsecp256k1zkp_v0_10_0_ec_pubkey_combine tests. */ pubkeys[0] = &pubkey_one; - VG_UNDEF(&pubkeys[0], sizeof(rustsecp256k1zkp_v0_8_0_pubkey *)); - VG_UNDEF(&pubkeys[1], sizeof(rustsecp256k1zkp_v0_8_0_pubkey *)); - VG_UNDEF(&pubkeys[2], sizeof(rustsecp256k1zkp_v0_8_0_pubkey *)); - memset(&pubkey, 255, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)); - VG_UNDEF(&pubkey, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_combine(ctx, &pubkey, pubkeys, 0) == 0); - VG_CHECK(&pubkey, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_combine(ctx, NULL, pubkeys, 1) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)) == 0); - CHECK(ecount == 2); - memset(&pubkey, 255, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)); - VG_UNDEF(&pubkey, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_combine(ctx, &pubkey, NULL, 1) == 0); - VG_CHECK(&pubkey, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)) == 0); - CHECK(ecount == 3); + SECP256K1_CHECKMEM_UNDEFINE(&pubkeys[0], sizeof(rustsecp256k1zkp_v0_10_0_pubkey *)); + SECP256K1_CHECKMEM_UNDEFINE(&pubkeys[1], sizeof(rustsecp256k1zkp_v0_10_0_pubkey *)); + SECP256K1_CHECKMEM_UNDEFINE(&pubkeys[2], sizeof(rustsecp256k1zkp_v0_10_0_pubkey *)); + memset(&pubkey, 255, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_combine(CTX, &pubkey, pubkeys, 0)); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_combine(CTX, NULL, pubkeys, 1)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)) == 0); + memset(&pubkey, 255, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_combine(CTX, &pubkey, NULL, 1)); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)) == 0); pubkeys[0] = &pubkey_negone; - memset(&pubkey, 255, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)); - VG_UNDEF(&pubkey, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_combine(ctx, &pubkey, pubkeys, 1) == 1); - VG_CHECK(&pubkey, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)) > 0); - CHECK(ecount == 3); + memset(&pubkey, 255, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_combine(CTX, &pubkey, pubkeys, 1) == 1); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)) > 0); len = 33; - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, ctmp, &len, &pubkey, SECP256K1_EC_COMPRESSED) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, ctmp2, &len, &pubkey_negone, SECP256K1_EC_COMPRESSED) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(ctmp, ctmp2, 33) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(CTX, ctmp, &len, &pubkey, SECP256K1_EC_COMPRESSED) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(CTX, ctmp2, &len, &pubkey_negone, SECP256K1_EC_COMPRESSED) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(ctmp, ctmp2, 33) == 0); /* Result is infinity. */ pubkeys[0] = &pubkey_one; pubkeys[1] = &pubkey_negone; - memset(&pubkey, 255, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)); - VG_UNDEF(&pubkey, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_combine(ctx, &pubkey, pubkeys, 2) == 0); - VG_CHECK(&pubkey, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)) == 0); - CHECK(ecount == 3); + memset(&pubkey, 255, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_combine(CTX, &pubkey, pubkeys, 2) == 0); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)) == 0); /* Passes through infinity but comes out one. */ pubkeys[2] = &pubkey_one; - memset(&pubkey, 255, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)); - VG_UNDEF(&pubkey, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_combine(ctx, &pubkey, pubkeys, 3) == 1); - VG_CHECK(&pubkey, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)) > 0); - CHECK(ecount == 3); + memset(&pubkey, 255, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_combine(CTX, &pubkey, pubkeys, 3) == 1); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)) > 0); len = 33; - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, ctmp, &len, &pubkey, SECP256K1_EC_COMPRESSED) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, ctmp2, &len, &pubkey_one, SECP256K1_EC_COMPRESSED) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(ctmp, ctmp2, 33) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(CTX, ctmp, &len, &pubkey, SECP256K1_EC_COMPRESSED) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(CTX, ctmp2, &len, &pubkey_one, SECP256K1_EC_COMPRESSED) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(ctmp, ctmp2, 33) == 0); /* Adds to two. */ pubkeys[1] = &pubkey_one; - memset(&pubkey, 255, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)); - VG_UNDEF(&pubkey, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_combine(ctx, &pubkey, pubkeys, 2) == 1); - VG_CHECK(&pubkey, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)) > 0); - CHECK(ecount == 3); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(ctx, NULL, NULL); + memset(&pubkey, 255, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)); + SECP256K1_CHECKMEM_UNDEFINE(&pubkey, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_combine(CTX, &pubkey, pubkeys, 2) == 1); + SECP256K1_CHECKMEM_CHECK(&pubkey, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, zeros, sizeof(rustsecp256k1zkp_v0_10_0_pubkey)) > 0); } -void run_eckey_negate_test(void) { +static void run_eckey_negate_test(void) { unsigned char seckey[32]; unsigned char seckey_tmp[32]; @@ -6094,22 +6405,22 @@ void run_eckey_negate_test(void) { memcpy(seckey_tmp, seckey, 32); /* Verify negation changes the key and changes it back */ - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_negate(ctx, seckey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(seckey, seckey_tmp, 32) != 0); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_negate(ctx, seckey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(seckey, seckey_tmp, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_negate(CTX, seckey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(seckey, seckey_tmp, 32) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_negate(CTX, seckey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(seckey, seckey_tmp, 32) == 0); /* Check that privkey alias gives same result */ - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_negate(ctx, seckey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_privkey_negate(ctx, seckey_tmp) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(seckey, seckey_tmp, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_negate(CTX, seckey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_privkey_negate(CTX, seckey_tmp) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(seckey, seckey_tmp, 32) == 0); /* Negating all 0s fails */ memset(seckey, 0, 32); memset(seckey_tmp, 0, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_negate(ctx, seckey) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_negate(CTX, seckey) == 0); /* Check that seckey is not modified */ - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(seckey, seckey_tmp, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(seckey, seckey_tmp, 32) == 0); /* Negating an overflowing seckey fails and the seckey is zeroed. In this * test, the seckey has 16 random bytes to ensure that ec_seckey_negate @@ -6117,30 +6428,30 @@ void run_eckey_negate_test(void) { random_scalar_order_b32(seckey); memset(seckey, 0xFF, 16); memset(seckey_tmp, 0, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_negate(ctx, seckey) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(seckey, seckey_tmp, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_negate(CTX, seckey) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(seckey, seckey_tmp, 32) == 0); } -void random_sign(rustsecp256k1zkp_v0_8_0_scalar *sigr, rustsecp256k1zkp_v0_8_0_scalar *sigs, const rustsecp256k1zkp_v0_8_0_scalar *key, const rustsecp256k1zkp_v0_8_0_scalar *msg, int *recid) { - rustsecp256k1zkp_v0_8_0_scalar nonce; +static void random_sign(rustsecp256k1zkp_v0_10_0_scalar *sigr, rustsecp256k1zkp_v0_10_0_scalar *sigs, const rustsecp256k1zkp_v0_10_0_scalar *key, const rustsecp256k1zkp_v0_10_0_scalar *msg, int *recid) { + rustsecp256k1zkp_v0_10_0_scalar nonce; do { random_scalar_order_test(&nonce); - } while(!rustsecp256k1zkp_v0_8_0_ecdsa_sig_sign(&ctx->ecmult_gen_ctx, sigr, sigs, key, msg, &nonce, recid)); + } while(!rustsecp256k1zkp_v0_10_0_ecdsa_sig_sign(&CTX->ecmult_gen_ctx, sigr, sigs, key, msg, &nonce, recid)); } -void test_ecdsa_sign_verify(void) { - rustsecp256k1zkp_v0_8_0_gej pubj; - rustsecp256k1zkp_v0_8_0_ge pub; - rustsecp256k1zkp_v0_8_0_scalar one; - rustsecp256k1zkp_v0_8_0_scalar msg, key; - rustsecp256k1zkp_v0_8_0_scalar sigr, sigs; +static void test_ecdsa_sign_verify(void) { + rustsecp256k1zkp_v0_10_0_gej pubj; + rustsecp256k1zkp_v0_10_0_ge pub; + rustsecp256k1zkp_v0_10_0_scalar one; + rustsecp256k1zkp_v0_10_0_scalar msg, key; + rustsecp256k1zkp_v0_10_0_scalar sigr, sigs; int getrec; int recid; random_scalar_order_test(&msg); random_scalar_order_test(&key); - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &pubj, &key); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&pub, &pubj); - getrec = rustsecp256k1zkp_v0_8_0_testrand_bits(1); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&CTX->ecmult_gen_ctx, &pubj, &key); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&pub, &pubj); + getrec = rustsecp256k1zkp_v0_10_0_testrand_bits(1); /* The specific way in which this conditional is written sidesteps a potential bug in clang. See the commit messages of the commit that introduced this comment for details. */ if (getrec) { @@ -6149,15 +6460,15 @@ void test_ecdsa_sign_verify(void) { } else { random_sign(&sigr, &sigs, &key, &msg, NULL); } - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sigr, &sigs, &pub, &msg)); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&one, 1); - rustsecp256k1zkp_v0_8_0_scalar_add(&msg, &msg, &one); - CHECK(!rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sigr, &sigs, &pub, &msg)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&sigr, &sigs, &pub, &msg)); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&one, 1); + rustsecp256k1zkp_v0_10_0_scalar_add(&msg, &msg, &one); + CHECK(!rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&sigr, &sigs, &pub, &msg)); } -void run_ecdsa_sign_verify(void) { +static void run_ecdsa_sign_verify(void) { int i; - for (i = 0; i < 10*count; i++) { + for (i = 0; i < 10*COUNT; i++) { test_ecdsa_sign_verify(); } } @@ -6209,201 +6520,201 @@ static int nonce_function_test_retry(unsigned char *nonce32, const unsigned char return nonce_function_rfc6979(nonce32, msg32, key32, algo16, data, counter - 5); } -int is_empty_signature(const rustsecp256k1zkp_v0_8_0_ecdsa_signature *sig) { - static const unsigned char res[sizeof(rustsecp256k1zkp_v0_8_0_ecdsa_signature)] = {0}; - return rustsecp256k1zkp_v0_8_0_memcmp_var(sig, res, sizeof(rustsecp256k1zkp_v0_8_0_ecdsa_signature)) == 0; +static int is_empty_signature(const rustsecp256k1zkp_v0_10_0_ecdsa_signature *sig) { + static const unsigned char res[sizeof(rustsecp256k1zkp_v0_10_0_ecdsa_signature)] = {0}; + return rustsecp256k1zkp_v0_10_0_memcmp_var(sig, res, sizeof(rustsecp256k1zkp_v0_10_0_ecdsa_signature)) == 0; } -void test_ecdsa_end_to_end(void) { +static void test_ecdsa_end_to_end(void) { unsigned char extra[32] = {0x00}; unsigned char privkey[32]; unsigned char message[32]; unsigned char privkey2[32]; - rustsecp256k1zkp_v0_8_0_ecdsa_signature signature[6]; - rustsecp256k1zkp_v0_8_0_scalar r, s; + rustsecp256k1zkp_v0_10_0_ecdsa_signature signature[6]; + rustsecp256k1zkp_v0_10_0_scalar r, s; unsigned char sig[74]; size_t siglen = 74; unsigned char pubkeyc[65]; size_t pubkeyclen = 65; - rustsecp256k1zkp_v0_8_0_pubkey pubkey; - rustsecp256k1zkp_v0_8_0_pubkey pubkey_tmp; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_pubkey pubkey_tmp; unsigned char seckey[300]; size_t seckeylen = 300; /* Generate a random key and message. */ { - rustsecp256k1zkp_v0_8_0_scalar msg, key; + rustsecp256k1zkp_v0_10_0_scalar msg, key; random_scalar_order_test(&msg); random_scalar_order_test(&key); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(privkey, &key); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(message, &msg); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(privkey, &key); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(message, &msg); } /* Construct and verify corresponding public key. */ - CHECK(rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, privkey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey, privkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_seckey_verify(CTX, privkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey, privkey) == 1); /* Verify exporting and importing public key. */ - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, pubkeyc, &pubkeyclen, &pubkey, rustsecp256k1zkp_v0_8_0_testrand_bits(1) == 1 ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_serialize(CTX, pubkeyc, &pubkeyclen, &pubkey, rustsecp256k1zkp_v0_10_0_testrand_bits(1) == 1 ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED)); memset(&pubkey, 0, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pubkey, pubkeyc, pubkeyclen) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pubkey, pubkeyc, pubkeyclen) == 1); /* Verify negation changes the key and changes it back */ memcpy(&pubkey_tmp, &pubkey, sizeof(pubkey)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_negate(ctx, &pubkey_tmp) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey_tmp, &pubkey, sizeof(pubkey)) != 0); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_negate(ctx, &pubkey_tmp) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey_tmp, &pubkey, sizeof(pubkey)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_negate(CTX, &pubkey_tmp) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey_tmp, &pubkey, sizeof(pubkey)) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_negate(CTX, &pubkey_tmp) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey_tmp, &pubkey, sizeof(pubkey)) == 0); /* Verify private key import and export. */ - CHECK(ec_privkey_export_der(ctx, seckey, &seckeylen, privkey, rustsecp256k1zkp_v0_8_0_testrand_bits(1) == 1)); - CHECK(ec_privkey_import_der(ctx, privkey2, seckey, seckeylen) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(privkey, privkey2, 32) == 0); + CHECK(ec_privkey_export_der(CTX, seckey, &seckeylen, privkey, rustsecp256k1zkp_v0_10_0_testrand_bits(1) == 1)); + CHECK(ec_privkey_import_der(CTX, privkey2, seckey, seckeylen) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(privkey, privkey2, 32) == 0); /* Optionally tweak the keys using addition. */ - if (rustsecp256k1zkp_v0_8_0_testrand_int(3) == 0) { + if (rustsecp256k1zkp_v0_10_0_testrand_int(3) == 0) { int ret1; int ret2; int ret3; unsigned char rnd[32]; unsigned char privkey_tmp[32]; - rustsecp256k1zkp_v0_8_0_pubkey pubkey2; - rustsecp256k1zkp_v0_8_0_testrand256_test(rnd); + rustsecp256k1zkp_v0_10_0_pubkey pubkey2; + rustsecp256k1zkp_v0_10_0_testrand256_test(rnd); memcpy(privkey_tmp, privkey, 32); - ret1 = rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add(ctx, privkey, rnd); - ret2 = rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_add(ctx, &pubkey, rnd); + ret1 = rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_add(CTX, privkey, rnd); + ret2 = rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_add(CTX, &pubkey, rnd); /* Check that privkey alias gives same result */ - ret3 = rustsecp256k1zkp_v0_8_0_ec_privkey_tweak_add(ctx, privkey_tmp, rnd); + ret3 = rustsecp256k1zkp_v0_10_0_ec_privkey_tweak_add(CTX, privkey_tmp, rnd); CHECK(ret1 == ret2); CHECK(ret2 == ret3); if (ret1 == 0) { return; } - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(privkey, privkey_tmp, 32) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey2, privkey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, &pubkey2, sizeof(pubkey)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(privkey, privkey_tmp, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey2, privkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, &pubkey2, sizeof(pubkey)) == 0); } /* Optionally tweak the keys using multiplication. */ - if (rustsecp256k1zkp_v0_8_0_testrand_int(3) == 0) { + if (rustsecp256k1zkp_v0_10_0_testrand_int(3) == 0) { int ret1; int ret2; int ret3; unsigned char rnd[32]; unsigned char privkey_tmp[32]; - rustsecp256k1zkp_v0_8_0_pubkey pubkey2; - rustsecp256k1zkp_v0_8_0_testrand256_test(rnd); + rustsecp256k1zkp_v0_10_0_pubkey pubkey2; + rustsecp256k1zkp_v0_10_0_testrand256_test(rnd); memcpy(privkey_tmp, privkey, 32); - ret1 = rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_mul(ctx, privkey, rnd); - ret2 = rustsecp256k1zkp_v0_8_0_ec_pubkey_tweak_mul(ctx, &pubkey, rnd); + ret1 = rustsecp256k1zkp_v0_10_0_ec_seckey_tweak_mul(CTX, privkey, rnd); + ret2 = rustsecp256k1zkp_v0_10_0_ec_pubkey_tweak_mul(CTX, &pubkey, rnd); /* Check that privkey alias gives same result */ - ret3 = rustsecp256k1zkp_v0_8_0_ec_privkey_tweak_mul(ctx, privkey_tmp, rnd); + ret3 = rustsecp256k1zkp_v0_10_0_ec_privkey_tweak_mul(CTX, privkey_tmp, rnd); CHECK(ret1 == ret2); CHECK(ret2 == ret3); if (ret1 == 0) { return; } - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(privkey, privkey_tmp, 32) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey2, privkey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&pubkey, &pubkey2, sizeof(pubkey)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(privkey, privkey_tmp, 32) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey2, privkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&pubkey, &pubkey2, sizeof(pubkey)) == 0); } /* Sign. */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &signature[0], message, privkey, NULL, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &signature[4], message, privkey, NULL, NULL) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &signature[1], message, privkey, NULL, extra) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &signature[0], message, privkey, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &signature[4], message, privkey, NULL, NULL) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &signature[1], message, privkey, NULL, extra) == 1); extra[31] = 1; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &signature[2], message, privkey, NULL, extra) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &signature[2], message, privkey, NULL, extra) == 1); extra[31] = 0; extra[0] = 1; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &signature[3], message, privkey, NULL, extra) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&signature[0], &signature[4], sizeof(signature[0])) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&signature[0], &signature[1], sizeof(signature[0])) != 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&signature[0], &signature[2], sizeof(signature[0])) != 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&signature[0], &signature[3], sizeof(signature[0])) != 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&signature[1], &signature[2], sizeof(signature[0])) != 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&signature[1], &signature[3], sizeof(signature[0])) != 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&signature[2], &signature[3], sizeof(signature[0])) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &signature[3], message, privkey, NULL, extra) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&signature[0], &signature[4], sizeof(signature[0])) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&signature[0], &signature[1], sizeof(signature[0])) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&signature[0], &signature[2], sizeof(signature[0])) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&signature[0], &signature[3], sizeof(signature[0])) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&signature[1], &signature[2], sizeof(signature[0])) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&signature[1], &signature[3], sizeof(signature[0])) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&signature[2], &signature[3], sizeof(signature[0])) != 0); /* Verify. */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &signature[0], message, &pubkey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &signature[1], message, &pubkey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &signature[2], message, &pubkey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &signature[3], message, &pubkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &signature[0], message, &pubkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &signature[1], message, &pubkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &signature[2], message, &pubkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &signature[3], message, &pubkey) == 1); /* Test lower-S form, malleate, verify and fail, test again, malleate again */ - CHECK(!rustsecp256k1zkp_v0_8_0_ecdsa_signature_normalize(ctx, NULL, &signature[0])); - rustsecp256k1zkp_v0_8_0_ecdsa_signature_load(ctx, &r, &s, &signature[0]); - rustsecp256k1zkp_v0_8_0_scalar_negate(&s, &s); - rustsecp256k1zkp_v0_8_0_ecdsa_signature_save(&signature[5], &r, &s); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &signature[5], message, &pubkey) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_normalize(ctx, NULL, &signature[5])); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_normalize(ctx, &signature[5], &signature[5])); - CHECK(!rustsecp256k1zkp_v0_8_0_ecdsa_signature_normalize(ctx, NULL, &signature[5])); - CHECK(!rustsecp256k1zkp_v0_8_0_ecdsa_signature_normalize(ctx, &signature[5], &signature[5])); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &signature[5], message, &pubkey) == 1); - rustsecp256k1zkp_v0_8_0_scalar_negate(&s, &s); - rustsecp256k1zkp_v0_8_0_ecdsa_signature_save(&signature[5], &r, &s); - CHECK(!rustsecp256k1zkp_v0_8_0_ecdsa_signature_normalize(ctx, NULL, &signature[5])); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &signature[5], message, &pubkey) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&signature[5], &signature[0], 64) == 0); + CHECK(!rustsecp256k1zkp_v0_10_0_ecdsa_signature_normalize(CTX, NULL, &signature[0])); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_load(CTX, &r, &s, &signature[0]); + rustsecp256k1zkp_v0_10_0_scalar_negate(&s, &s); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_save(&signature[5], &r, &s); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &signature[5], message, &pubkey) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_normalize(CTX, NULL, &signature[5])); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_normalize(CTX, &signature[5], &signature[5])); + CHECK(!rustsecp256k1zkp_v0_10_0_ecdsa_signature_normalize(CTX, NULL, &signature[5])); + CHECK(!rustsecp256k1zkp_v0_10_0_ecdsa_signature_normalize(CTX, &signature[5], &signature[5])); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &signature[5], message, &pubkey) == 1); + rustsecp256k1zkp_v0_10_0_scalar_negate(&s, &s); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_save(&signature[5], &r, &s); + CHECK(!rustsecp256k1zkp_v0_10_0_ecdsa_signature_normalize(CTX, NULL, &signature[5])); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &signature[5], message, &pubkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&signature[5], &signature[0], 64) == 0); /* Serialize/parse DER and verify again */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_der(ctx, sig, &siglen, &signature[0]) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_der(CTX, sig, &siglen, &signature[0]) == 1); memset(&signature[0], 0, sizeof(signature[0])); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &signature[0], sig, siglen) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &signature[0], message, &pubkey) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &signature[0], sig, siglen) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &signature[0], message, &pubkey) == 1); /* Serialize/destroy/parse DER and verify again. */ siglen = 74; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_der(ctx, sig, &siglen, &signature[0]) == 1); - sig[rustsecp256k1zkp_v0_8_0_testrand_int(siglen)] += 1 + rustsecp256k1zkp_v0_8_0_testrand_int(255); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &signature[0], sig, siglen) == 0 || - rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &signature[0], message, &pubkey) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_der(CTX, sig, &siglen, &signature[0]) == 1); + sig[rustsecp256k1zkp_v0_10_0_testrand_int(siglen)] += 1 + rustsecp256k1zkp_v0_10_0_testrand_int(255); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &signature[0], sig, siglen) == 0 || + rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &signature[0], message, &pubkey) == 0); } -void test_random_pubkeys(void) { - rustsecp256k1zkp_v0_8_0_ge elem; - rustsecp256k1zkp_v0_8_0_ge elem2; +static void test_random_pubkeys(void) { + rustsecp256k1zkp_v0_10_0_ge elem; + rustsecp256k1zkp_v0_10_0_ge elem2; unsigned char in[65]; /* Generate some randomly sized pubkeys. */ - size_t len = rustsecp256k1zkp_v0_8_0_testrand_bits(2) == 0 ? 65 : 33; - if (rustsecp256k1zkp_v0_8_0_testrand_bits(2) == 0) { - len = rustsecp256k1zkp_v0_8_0_testrand_bits(6); + size_t len = rustsecp256k1zkp_v0_10_0_testrand_bits(2) == 0 ? 65 : 33; + if (rustsecp256k1zkp_v0_10_0_testrand_bits(2) == 0) { + len = rustsecp256k1zkp_v0_10_0_testrand_bits(6); } if (len == 65) { - in[0] = rustsecp256k1zkp_v0_8_0_testrand_bits(1) ? 4 : (rustsecp256k1zkp_v0_8_0_testrand_bits(1) ? 6 : 7); + in[0] = rustsecp256k1zkp_v0_10_0_testrand_bits(1) ? 4 : (rustsecp256k1zkp_v0_10_0_testrand_bits(1) ? 6 : 7); } else { - in[0] = rustsecp256k1zkp_v0_8_0_testrand_bits(1) ? 2 : 3; + in[0] = rustsecp256k1zkp_v0_10_0_testrand_bits(1) ? 2 : 3; } - if (rustsecp256k1zkp_v0_8_0_testrand_bits(3) == 0) { - in[0] = rustsecp256k1zkp_v0_8_0_testrand_bits(8); + if (rustsecp256k1zkp_v0_10_0_testrand_bits(3) == 0) { + in[0] = rustsecp256k1zkp_v0_10_0_testrand_bits(8); } if (len > 1) { - rustsecp256k1zkp_v0_8_0_testrand256(&in[1]); + rustsecp256k1zkp_v0_10_0_testrand256(&in[1]); } if (len > 33) { - rustsecp256k1zkp_v0_8_0_testrand256(&in[33]); + rustsecp256k1zkp_v0_10_0_testrand256(&in[33]); } - if (rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(&elem, in, len)) { + if (rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(&elem, in, len)) { unsigned char out[65]; unsigned char firstb; int res; size_t size = len; firstb = in[0]; /* If the pubkey can be parsed, it should round-trip... */ - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&elem, out, &size, len == 33)); + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&elem, out, &size, len == 33)); CHECK(size == len); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&in[1], &out[1], len-1) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&in[1], &out[1], len-1) == 0); /* ... except for the type of hybrid inputs. */ if ((in[0] != 6) && (in[0] != 7)) { CHECK(in[0] == out[0]); } size = 65; - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&elem, in, &size, 0)); + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&elem, in, &size, 0)); CHECK(size == 65); - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(&elem2, in, size)); - ge_equals_ge(&elem,&elem2); + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(&elem2, in, size)); + CHECK(rustsecp256k1zkp_v0_10_0_ge_eq_var(&elem2, &elem)); /* Check that the X9.62 hybrid type is checked. */ - in[0] = rustsecp256k1zkp_v0_8_0_testrand_bits(1) ? 6 : 7; - res = rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(&elem2, in, size); + in[0] = rustsecp256k1zkp_v0_10_0_testrand_bits(1) ? 6 : 7; + res = rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(&elem2, in, size); if (firstb == 2 || firstb == 3) { if (in[0] == firstb + 4) { CHECK(res); @@ -6412,14 +6723,14 @@ void test_random_pubkeys(void) { } } if (res) { - ge_equals_ge(&elem,&elem2); - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_serialize(&elem, out, &size, 0)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&in[1], &out[1], 64) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ge_eq_var(&elem, &elem2)); + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_serialize(&elem, out, &size, 0)); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&in[1], &out[1], 64) == 0); } } } -void run_pubkey_comparison(void) { +static void run_pubkey_comparison(void) { unsigned char pk1_ser[33] = { 0x02, 0x58, 0x84, 0xb3, 0xa2, 0x4b, 0x97, 0x37, 0x88, 0x92, 0x38, 0xa6, 0x26, 0x62, 0x52, 0x35, 0x11, @@ -6430,93 +6741,89 @@ void run_pubkey_comparison(void) { 0xde, 0x36, 0x0e, 0x87, 0x59, 0x8f, 0x3c, 0x01, 0x36, 0x2a, 0x2a, 0xb8, 0xc6, 0xf4, 0x5e, 0x4d, 0xb2, 0xc2, 0xd5, 0x03, 0xa7, 0xf9, 0xf1, 0x4f, 0xa8, 0xfa, 0x95, 0xa8, 0xe9, 0x69, 0x76, 0x1c }; - rustsecp256k1zkp_v0_8_0_pubkey pk1; - rustsecp256k1zkp_v0_8_0_pubkey pk2; - int32_t ecount = 0; - - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pk1, pk1_ser, sizeof(pk1_ser)) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pk2, pk2_ser, sizeof(pk2_ser)) == 1); - - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(ctx, counting_illegal_callback_fn, &ecount); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_cmp(ctx, NULL, &pk2) < 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_cmp(ctx, &pk1, NULL) > 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_cmp(ctx, &pk1, &pk2) < 0); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_cmp(ctx, &pk2, &pk1) > 0); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_cmp(ctx, &pk1, &pk1) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_cmp(ctx, &pk2, &pk2) == 0); - CHECK(ecount == 2); + rustsecp256k1zkp_v0_10_0_pubkey pk1; + rustsecp256k1zkp_v0_10_0_pubkey pk2; + + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pk1, pk1_ser, sizeof(pk1_ser)) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pk2, pk2_ser, sizeof(pk2_ser)) == 1); + + CHECK_ILLEGAL_VOID(CTX, CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_cmp(CTX, NULL, &pk2) < 0)); + CHECK_ILLEGAL_VOID(CTX, CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_cmp(CTX, &pk1, NULL) > 0)); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_cmp(CTX, &pk1, &pk2) < 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_cmp(CTX, &pk2, &pk1) > 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_cmp(CTX, &pk1, &pk1) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_cmp(CTX, &pk2, &pk2) == 0); { - rustsecp256k1zkp_v0_8_0_pubkey pk_tmp; + rustsecp256k1zkp_v0_10_0_pubkey pk_tmp; memset(&pk_tmp, 0, sizeof(pk_tmp)); /* illegal pubkey */ - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_cmp(ctx, &pk_tmp, &pk2) < 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_cmp(ctx, &pk_tmp, &pk_tmp) == 0); - CHECK(ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_cmp(ctx, &pk2, &pk_tmp) > 0); - CHECK(ecount == 6); + CHECK_ILLEGAL_VOID(CTX, CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_cmp(CTX, &pk_tmp, &pk2) < 0)); + { + int32_t ecount = 0; + rustsecp256k1zkp_v0_10_0_context_set_illegal_callback(CTX, counting_callback_fn, &ecount); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_cmp(CTX, &pk_tmp, &pk_tmp) == 0); + CHECK(ecount == 2); + rustsecp256k1zkp_v0_10_0_context_set_illegal_callback(CTX, NULL, NULL); + } + CHECK_ILLEGAL_VOID(CTX, CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_cmp(CTX, &pk2, &pk_tmp) > 0)); } - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(ctx, NULL, NULL); - /* Make pk2 the same as pk1 but with 3 rather than 2. Note that in * an uncompressed encoding, these would have the opposite ordering */ pk1_ser[0] = 3; - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_parse(ctx, &pk2, pk1_ser, sizeof(pk1_ser)) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_cmp(ctx, &pk1, &pk2) < 0); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_cmp(ctx, &pk2, &pk1) > 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pk2, pk1_ser, sizeof(pk1_ser)) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_cmp(CTX, &pk1, &pk2) < 0); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_cmp(CTX, &pk2, &pk1) > 0); } -void run_random_pubkeys(void) { +static void run_random_pubkeys(void) { int i; - for (i = 0; i < 10*count; i++) { + for (i = 0; i < 10*COUNT; i++) { test_random_pubkeys(); } } -void run_ecdsa_end_to_end(void) { +static void run_ecdsa_end_to_end(void) { int i; - for (i = 0; i < 64*count; i++) { + for (i = 0; i < 64*COUNT; i++) { test_ecdsa_end_to_end(); } } -int test_ecdsa_der_parse(const unsigned char *sig, size_t siglen, int certainly_der, int certainly_not_der) { +static int test_ecdsa_der_parse(const unsigned char *sig, size_t siglen, int certainly_der, int certainly_not_der) { static const unsigned char zeroes[32] = {0}; int ret = 0; - rustsecp256k1zkp_v0_8_0_ecdsa_signature sig_der; + rustsecp256k1zkp_v0_10_0_ecdsa_signature sig_der; unsigned char roundtrip_der[2048]; unsigned char compact_der[64]; size_t len_der = 2048; int parsed_der = 0, valid_der = 0, roundtrips_der = 0; - rustsecp256k1zkp_v0_8_0_ecdsa_signature sig_der_lax; + rustsecp256k1zkp_v0_10_0_ecdsa_signature sig_der_lax; unsigned char roundtrip_der_lax[2048]; unsigned char compact_der_lax[64]; size_t len_der_lax = 2048; int parsed_der_lax = 0, valid_der_lax = 0, roundtrips_der_lax = 0; - parsed_der = rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &sig_der, sig, siglen); + parsed_der = rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &sig_der, sig, siglen); if (parsed_der) { - ret |= (!rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_compact(ctx, compact_der, &sig_der)) << 0; - valid_der = (rustsecp256k1zkp_v0_8_0_memcmp_var(compact_der, zeroes, 32) != 0) && (rustsecp256k1zkp_v0_8_0_memcmp_var(compact_der + 32, zeroes, 32) != 0); + ret |= (!rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_compact(CTX, compact_der, &sig_der)) << 0; + valid_der = (rustsecp256k1zkp_v0_10_0_memcmp_var(compact_der, zeroes, 32) != 0) && (rustsecp256k1zkp_v0_10_0_memcmp_var(compact_der + 32, zeroes, 32) != 0); } if (valid_der) { - ret |= (!rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_der(ctx, roundtrip_der, &len_der, &sig_der)) << 1; - roundtrips_der = (len_der == siglen) && rustsecp256k1zkp_v0_8_0_memcmp_var(roundtrip_der, sig, siglen) == 0; + ret |= (!rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_der(CTX, roundtrip_der, &len_der, &sig_der)) << 1; + roundtrips_der = (len_der == siglen) && rustsecp256k1zkp_v0_10_0_memcmp_var(roundtrip_der, sig, siglen) == 0; } - parsed_der_lax = rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der_lax(ctx, &sig_der_lax, sig, siglen); + parsed_der_lax = rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der_lax(CTX, &sig_der_lax, sig, siglen); if (parsed_der_lax) { - ret |= (!rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_compact(ctx, compact_der_lax, &sig_der_lax)) << 10; - valid_der_lax = (rustsecp256k1zkp_v0_8_0_memcmp_var(compact_der_lax, zeroes, 32) != 0) && (rustsecp256k1zkp_v0_8_0_memcmp_var(compact_der_lax + 32, zeroes, 32) != 0); + ret |= (!rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_compact(CTX, compact_der_lax, &sig_der_lax)) << 10; + valid_der_lax = (rustsecp256k1zkp_v0_10_0_memcmp_var(compact_der_lax, zeroes, 32) != 0) && (rustsecp256k1zkp_v0_10_0_memcmp_var(compact_der_lax + 32, zeroes, 32) != 0); } if (valid_der_lax) { - ret |= (!rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_der(ctx, roundtrip_der_lax, &len_der_lax, &sig_der_lax)) << 11; - roundtrips_der_lax = (len_der_lax == siglen) && rustsecp256k1zkp_v0_8_0_memcmp_var(roundtrip_der_lax, sig, siglen) == 0; + ret |= (!rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_der(CTX, roundtrip_der_lax, &len_der_lax, &sig_der_lax)) << 11; + roundtrips_der_lax = (len_der_lax == siglen) && rustsecp256k1zkp_v0_10_0_memcmp_var(roundtrip_der_lax, sig, siglen) == 0; } if (certainly_der) { @@ -6532,7 +6839,7 @@ int test_ecdsa_der_parse(const unsigned char *sig, size_t siglen, int certainly_ if (valid_der) { ret |= (!roundtrips_der_lax) << 12; ret |= (len_der != len_der_lax) << 13; - ret |= ((len_der != len_der_lax) || (rustsecp256k1zkp_v0_8_0_memcmp_var(roundtrip_der_lax, roundtrip_der, len_der) != 0)) << 14; + ret |= ((len_der != len_der_lax) || (rustsecp256k1zkp_v0_10_0_memcmp_var(roundtrip_der_lax, roundtrip_der, len_der) != 0)) << 14; } ret |= (roundtrips_der != roundtrips_der_lax) << 15; if (parsed_der) { @@ -6556,27 +6863,27 @@ static void assign_big_endian(unsigned char *ptr, size_t ptrlen, uint32_t val) { static void damage_array(unsigned char *sig, size_t *len) { int pos; - int action = rustsecp256k1zkp_v0_8_0_testrand_bits(3); + int action = rustsecp256k1zkp_v0_10_0_testrand_bits(3); if (action < 1 && *len > 3) { /* Delete a byte. */ - pos = rustsecp256k1zkp_v0_8_0_testrand_int(*len); + pos = rustsecp256k1zkp_v0_10_0_testrand_int(*len); memmove(sig + pos, sig + pos + 1, *len - pos - 1); (*len)--; return; } else if (action < 2 && *len < 2048) { /* Insert a byte. */ - pos = rustsecp256k1zkp_v0_8_0_testrand_int(1 + *len); + pos = rustsecp256k1zkp_v0_10_0_testrand_int(1 + *len); memmove(sig + pos + 1, sig + pos, *len - pos); - sig[pos] = rustsecp256k1zkp_v0_8_0_testrand_bits(8); + sig[pos] = rustsecp256k1zkp_v0_10_0_testrand_bits(8); (*len)++; return; } else if (action < 4) { /* Modify a byte. */ - sig[rustsecp256k1zkp_v0_8_0_testrand_int(*len)] += 1 + rustsecp256k1zkp_v0_8_0_testrand_int(255); + sig[rustsecp256k1zkp_v0_10_0_testrand_int(*len)] += 1 + rustsecp256k1zkp_v0_10_0_testrand_int(255); return; } else { /* action < 8 */ /* Modify a bit. */ - sig[rustsecp256k1zkp_v0_8_0_testrand_int(*len)] ^= 1 << rustsecp256k1zkp_v0_8_0_testrand_bits(3); + sig[rustsecp256k1zkp_v0_10_0_testrand_int(*len)] ^= 1 << rustsecp256k1zkp_v0_10_0_testrand_bits(3); return; } } @@ -6589,23 +6896,23 @@ static void random_ber_signature(unsigned char *sig, size_t *len, int* certainly int n; *len = 0; - der = rustsecp256k1zkp_v0_8_0_testrand_bits(2) == 0; + der = rustsecp256k1zkp_v0_10_0_testrand_bits(2) == 0; *certainly_der = der; *certainly_not_der = 0; - indet = der ? 0 : rustsecp256k1zkp_v0_8_0_testrand_int(10) == 0; + indet = der ? 0 : rustsecp256k1zkp_v0_10_0_testrand_int(10) == 0; for (n = 0; n < 2; n++) { /* We generate two classes of numbers: nlow==1 "low" ones (up to 32 bytes), nlow==0 "high" ones (32 bytes with 129 top bits set, or larger than 32 bytes) */ - nlow[n] = der ? 1 : (rustsecp256k1zkp_v0_8_0_testrand_bits(3) != 0); + nlow[n] = der ? 1 : (rustsecp256k1zkp_v0_10_0_testrand_bits(3) != 0); /* The length of the number in bytes (the first byte of which will always be nonzero) */ - nlen[n] = nlow[n] ? rustsecp256k1zkp_v0_8_0_testrand_int(33) : 32 + rustsecp256k1zkp_v0_8_0_testrand_int(200) * rustsecp256k1zkp_v0_8_0_testrand_bits(3) / 8; + nlen[n] = nlow[n] ? rustsecp256k1zkp_v0_10_0_testrand_int(33) : 32 + rustsecp256k1zkp_v0_10_0_testrand_int(200) * rustsecp256k1zkp_v0_10_0_testrand_bits(3) / 8; CHECK(nlen[n] <= 232); /* The top bit of the number. */ - nhbit[n] = (nlow[n] == 0 && nlen[n] == 32) ? 1 : (nlen[n] == 0 ? 0 : rustsecp256k1zkp_v0_8_0_testrand_bits(1)); + nhbit[n] = (nlow[n] == 0 && nlen[n] == 32) ? 1 : (nlen[n] == 0 ? 0 : rustsecp256k1zkp_v0_10_0_testrand_bits(1)); /* The top byte of the number (after the potential hardcoded 16 0xFF characters for "high" 32 bytes numbers) */ - nhbyte[n] = nlen[n] == 0 ? 0 : (nhbit[n] ? 128 + rustsecp256k1zkp_v0_8_0_testrand_bits(7) : 1 + rustsecp256k1zkp_v0_8_0_testrand_int(127)); + nhbyte[n] = nlen[n] == 0 ? 0 : (nhbit[n] ? 128 + rustsecp256k1zkp_v0_10_0_testrand_bits(7) : 1 + rustsecp256k1zkp_v0_10_0_testrand_int(127)); /* The number of zero bytes in front of the number (which is 0 or 1 in case of DER, otherwise we extend up to 300 bytes) */ - nzlen[n] = der ? ((nlen[n] == 0 || nhbit[n]) ? 1 : 0) : (nlow[n] ? rustsecp256k1zkp_v0_8_0_testrand_int(3) : rustsecp256k1zkp_v0_8_0_testrand_int(300 - nlen[n]) * rustsecp256k1zkp_v0_8_0_testrand_bits(3) / 8); + nzlen[n] = der ? ((nlen[n] == 0 || nhbit[n]) ? 1 : 0) : (nlow[n] ? rustsecp256k1zkp_v0_10_0_testrand_int(3) : rustsecp256k1zkp_v0_10_0_testrand_int(300 - nlen[n]) * rustsecp256k1zkp_v0_10_0_testrand_bits(3) / 8); if (nzlen[n] > ((nlen[n] == 0 || nhbit[n]) ? 1 : 0)) { *certainly_not_der = 1; } @@ -6614,7 +6921,7 @@ static void random_ber_signature(unsigned char *sig, size_t *len, int* certainly nlenlen[n] = nlen[n] + nzlen[n] < 128 ? 0 : (nlen[n] + nzlen[n] < 256 ? 1 : 2); if (!der) { /* nlenlen[n] max 127 bytes */ - int add = rustsecp256k1zkp_v0_8_0_testrand_int(127 - nlenlen[n]) * rustsecp256k1zkp_v0_8_0_testrand_bits(4) * rustsecp256k1zkp_v0_8_0_testrand_bits(4) / 256; + int add = rustsecp256k1zkp_v0_10_0_testrand_int(127 - nlenlen[n]) * rustsecp256k1zkp_v0_10_0_testrand_bits(4) * rustsecp256k1zkp_v0_10_0_testrand_bits(4) / 256; nlenlen[n] += add; if (add != 0) { *certainly_not_der = 1; @@ -6628,7 +6935,7 @@ static void random_ber_signature(unsigned char *sig, size_t *len, int* certainly CHECK(tlen <= 856); /* The length of the garbage inside the tuple. */ - elen = (der || indet) ? 0 : rustsecp256k1zkp_v0_8_0_testrand_int(980 - tlen) * rustsecp256k1zkp_v0_8_0_testrand_bits(3) / 8; + elen = (der || indet) ? 0 : rustsecp256k1zkp_v0_10_0_testrand_int(980 - tlen) * rustsecp256k1zkp_v0_10_0_testrand_bits(3) / 8; if (elen != 0) { *certainly_not_der = 1; } @@ -6636,7 +6943,7 @@ static void random_ber_signature(unsigned char *sig, size_t *len, int* certainly CHECK(tlen <= 980); /* The length of the garbage after the end of the tuple. */ - glen = der ? 0 : rustsecp256k1zkp_v0_8_0_testrand_int(990 - tlen) * rustsecp256k1zkp_v0_8_0_testrand_bits(3) / 8; + glen = der ? 0 : rustsecp256k1zkp_v0_10_0_testrand_int(990 - tlen) * rustsecp256k1zkp_v0_10_0_testrand_bits(3) / 8; if (glen != 0) { *certainly_not_der = 1; } @@ -6651,7 +6958,7 @@ static void random_ber_signature(unsigned char *sig, size_t *len, int* certainly } else { int tlenlen = tlen < 128 ? 0 : (tlen < 256 ? 1 : 2); if (!der) { - int add = rustsecp256k1zkp_v0_8_0_testrand_int(127 - tlenlen) * rustsecp256k1zkp_v0_8_0_testrand_bits(4) * rustsecp256k1zkp_v0_8_0_testrand_bits(4) / 256; + int add = rustsecp256k1zkp_v0_10_0_testrand_int(127 - tlenlen) * rustsecp256k1zkp_v0_10_0_testrand_bits(4) * rustsecp256k1zkp_v0_10_0_testrand_bits(4) / 256; tlenlen += add; if (add != 0) { *certainly_not_der = 1; @@ -6702,13 +7009,13 @@ static void random_ber_signature(unsigned char *sig, size_t *len, int* certainly nlen[n]--; } /* Generate remaining random bytes of number */ - rustsecp256k1zkp_v0_8_0_testrand_bytes_test(sig + *len, nlen[n]); + rustsecp256k1zkp_v0_10_0_testrand_bytes_test(sig + *len, nlen[n]); *len += nlen[n]; nlen[n] = 0; } /* Generate random garbage inside tuple. */ - rustsecp256k1zkp_v0_8_0_testrand_bytes_test(sig + *len, elen); + rustsecp256k1zkp_v0_10_0_testrand_bytes_test(sig + *len, elen); *len += elen; /* Generate end-of-contents bytes. */ @@ -6720,16 +7027,16 @@ static void random_ber_signature(unsigned char *sig, size_t *len, int* certainly CHECK(tlen + glen <= 1121); /* Generate random garbage outside tuple. */ - rustsecp256k1zkp_v0_8_0_testrand_bytes_test(sig + *len, glen); + rustsecp256k1zkp_v0_10_0_testrand_bytes_test(sig + *len, glen); *len += glen; tlen += glen; CHECK(tlen <= 1121); CHECK(tlen == *len); } -void run_ecdsa_der_parse(void) { +static void run_ecdsa_der_parse(void) { int i,j; - for (i = 0; i < 200 * count; i++) { + for (i = 0; i < 200 * COUNT; i++) { unsigned char buffer[2048]; size_t buflen = 0; int certainly_der = 0; @@ -6759,24 +7066,24 @@ void run_ecdsa_der_parse(void) { } /* Tests several edge cases. */ -void test_ecdsa_edge_cases(void) { +static void test_ecdsa_edge_cases(void) { int t; - rustsecp256k1zkp_v0_8_0_ecdsa_signature sig; + rustsecp256k1zkp_v0_10_0_ecdsa_signature sig; /* Test the case where ECDSA recomputes a point that is infinity. */ { - rustsecp256k1zkp_v0_8_0_gej keyj; - rustsecp256k1zkp_v0_8_0_ge key; - rustsecp256k1zkp_v0_8_0_scalar msg; - rustsecp256k1zkp_v0_8_0_scalar sr, ss; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&ss, 1); - rustsecp256k1zkp_v0_8_0_scalar_negate(&ss, &ss); - rustsecp256k1zkp_v0_8_0_scalar_inverse(&ss, &ss); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&sr, 1); - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &keyj, &sr); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&key, &keyj); + rustsecp256k1zkp_v0_10_0_gej keyj; + rustsecp256k1zkp_v0_10_0_ge key; + rustsecp256k1zkp_v0_10_0_scalar msg; + rustsecp256k1zkp_v0_10_0_scalar sr, ss; + rustsecp256k1zkp_v0_10_0_scalar_set_int(&ss, 1); + rustsecp256k1zkp_v0_10_0_scalar_negate(&ss, &ss); + rustsecp256k1zkp_v0_10_0_scalar_inverse(&ss, &ss); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&sr, 1); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&CTX->ecmult_gen_ctx, &keyj, &sr); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&key, &keyj); msg = ss; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 0); } /* Verify signature with r of zero fails. */ @@ -6788,14 +7095,14 @@ void test_ecdsa_edge_cases(void) { 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41 }; - rustsecp256k1zkp_v0_8_0_ge key; - rustsecp256k1zkp_v0_8_0_scalar msg; - rustsecp256k1zkp_v0_8_0_scalar sr, ss; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&ss, 1); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&msg, 0); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&sr, 0); - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(&key, pubkey_mods_zero, 33)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify( &sr, &ss, &key, &msg) == 0); + rustsecp256k1zkp_v0_10_0_ge key; + rustsecp256k1zkp_v0_10_0_scalar msg; + rustsecp256k1zkp_v0_10_0_scalar sr, ss; + rustsecp256k1zkp_v0_10_0_scalar_set_int(&ss, 1); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&msg, 0); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&sr, 0); + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(&key, pubkey_mods_zero, 33)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify( &sr, &ss, &key, &msg) == 0); } /* Verify signature with s of zero fails. */ @@ -6807,14 +7114,14 @@ void test_ecdsa_edge_cases(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; - rustsecp256k1zkp_v0_8_0_ge key; - rustsecp256k1zkp_v0_8_0_scalar msg; - rustsecp256k1zkp_v0_8_0_scalar sr, ss; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&ss, 0); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&msg, 0); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&sr, 1); - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(&key, pubkey, 33)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 0); + rustsecp256k1zkp_v0_10_0_ge key; + rustsecp256k1zkp_v0_10_0_scalar msg; + rustsecp256k1zkp_v0_10_0_scalar sr, ss; + rustsecp256k1zkp_v0_10_0_scalar_set_int(&ss, 0); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&msg, 0); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&sr, 1); + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(&key, pubkey, 33)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 0); } /* Verify signature with message 0 passes. */ @@ -6833,23 +7140,23 @@ void test_ecdsa_edge_cases(void) { 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x43 }; - rustsecp256k1zkp_v0_8_0_ge key; - rustsecp256k1zkp_v0_8_0_ge key2; - rustsecp256k1zkp_v0_8_0_scalar msg; - rustsecp256k1zkp_v0_8_0_scalar sr, ss; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&ss, 2); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&msg, 0); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&sr, 2); - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(&key, pubkey, 33)); - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(&key2, pubkey2, 33)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sr, &ss, &key2, &msg) == 1); - rustsecp256k1zkp_v0_8_0_scalar_negate(&ss, &ss); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sr, &ss, &key2, &msg) == 1); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&ss, 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sr, &ss, &key2, &msg) == 0); + rustsecp256k1zkp_v0_10_0_ge key; + rustsecp256k1zkp_v0_10_0_ge key2; + rustsecp256k1zkp_v0_10_0_scalar msg; + rustsecp256k1zkp_v0_10_0_scalar sr, ss; + rustsecp256k1zkp_v0_10_0_scalar_set_int(&ss, 2); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&msg, 0); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&sr, 2); + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(&key, pubkey, 33)); + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(&key2, pubkey2, 33)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&sr, &ss, &key2, &msg) == 1); + rustsecp256k1zkp_v0_10_0_scalar_negate(&ss, &ss); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&sr, &ss, &key2, &msg) == 1); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&ss, 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&sr, &ss, &key2, &msg) == 0); } /* Verify signature with message 1 passes. */ @@ -6874,24 +7181,24 @@ void test_ecdsa_edge_cases(void) { 0x45, 0x51, 0x23, 0x19, 0x50, 0xb7, 0x5f, 0xc4, 0x40, 0x2d, 0xa1, 0x72, 0x2f, 0xc9, 0xba, 0xeb }; - rustsecp256k1zkp_v0_8_0_ge key; - rustsecp256k1zkp_v0_8_0_ge key2; - rustsecp256k1zkp_v0_8_0_scalar msg; - rustsecp256k1zkp_v0_8_0_scalar sr, ss; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&ss, 1); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&msg, 1); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&sr, csr, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(&key, pubkey, 33)); - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(&key2, pubkey2, 33)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sr, &ss, &key2, &msg) == 1); - rustsecp256k1zkp_v0_8_0_scalar_negate(&ss, &ss); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sr, &ss, &key2, &msg) == 1); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&ss, 2); - rustsecp256k1zkp_v0_8_0_scalar_inverse_var(&ss, &ss); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sr, &ss, &key2, &msg) == 0); + rustsecp256k1zkp_v0_10_0_ge key; + rustsecp256k1zkp_v0_10_0_ge key2; + rustsecp256k1zkp_v0_10_0_scalar msg; + rustsecp256k1zkp_v0_10_0_scalar sr, ss; + rustsecp256k1zkp_v0_10_0_scalar_set_int(&ss, 1); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&msg, 1); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&sr, csr, NULL); + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(&key, pubkey, 33)); + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(&key2, pubkey2, 33)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&sr, &ss, &key2, &msg) == 1); + rustsecp256k1zkp_v0_10_0_scalar_negate(&ss, &ss); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&sr, &ss, &key2, &msg) == 1); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&ss, 2); + rustsecp256k1zkp_v0_10_0_scalar_inverse_var(&ss, &ss); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&sr, &ss, &key2, &msg) == 0); } /* Verify signature with message -1 passes. */ @@ -6909,27 +7216,26 @@ void test_ecdsa_edge_cases(void) { 0x45, 0x51, 0x23, 0x19, 0x50, 0xb7, 0x5f, 0xc4, 0x40, 0x2d, 0xa1, 0x72, 0x2f, 0xc9, 0xba, 0xee }; - rustsecp256k1zkp_v0_8_0_ge key; - rustsecp256k1zkp_v0_8_0_scalar msg; - rustsecp256k1zkp_v0_8_0_scalar sr, ss; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&ss, 1); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&msg, 1); - rustsecp256k1zkp_v0_8_0_scalar_negate(&msg, &msg); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(&sr, csr, NULL); - CHECK(rustsecp256k1zkp_v0_8_0_eckey_pubkey_parse(&key, pubkey, 33)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 1); - rustsecp256k1zkp_v0_8_0_scalar_negate(&ss, &ss); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 1); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&ss, 3); - rustsecp256k1zkp_v0_8_0_scalar_inverse_var(&ss, &ss); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 0); + rustsecp256k1zkp_v0_10_0_ge key; + rustsecp256k1zkp_v0_10_0_scalar msg; + rustsecp256k1zkp_v0_10_0_scalar sr, ss; + rustsecp256k1zkp_v0_10_0_scalar_set_int(&ss, 1); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&msg, 1); + rustsecp256k1zkp_v0_10_0_scalar_negate(&msg, &msg); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(&sr, csr, NULL); + CHECK(rustsecp256k1zkp_v0_10_0_eckey_pubkey_parse(&key, pubkey, 33)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 1); + rustsecp256k1zkp_v0_10_0_scalar_negate(&ss, &ss); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 1); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&ss, 3); + rustsecp256k1zkp_v0_10_0_scalar_inverse_var(&ss, &ss); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sig_verify(&sr, &ss, &key, &msg) == 0); } /* Signature where s would be zero. */ { - rustsecp256k1zkp_v0_8_0_pubkey pubkey; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; size_t siglen; - int32_t ecount; unsigned char signature[72]; static const unsigned char nonce[32] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -6955,72 +7261,42 @@ void test_ecdsa_edge_cases(void) { 0xb8, 0x12, 0xe0, 0x0b, 0x81, 0x7a, 0x77, 0x62, 0x65, 0xdf, 0xdd, 0x31, 0xb9, 0x3e, 0x29, 0xa9, }; - ecount = 0; - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(ctx, counting_illegal_callback_fn, &ecount); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &sig, msg, key, precomputed_nonce_function, nonce) == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &sig, msg, key, precomputed_nonce_function, nonce2) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &sig, msg, key, precomputed_nonce_function, nonce) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &sig, msg, key, precomputed_nonce_function, nonce2) == 0); msg[31] = 0xaa; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &sig, msg, key, precomputed_nonce_function, nonce) == 1); - CHECK(ecount == 0); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, NULL, msg, key, precomputed_nonce_function, nonce2) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &sig, NULL, key, precomputed_nonce_function, nonce2) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &sig, msg, NULL, precomputed_nonce_function, nonce2) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &sig, msg, key, precomputed_nonce_function, nonce2) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey, key) == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, NULL, msg, &pubkey) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &sig, NULL, &pubkey) == 0); - CHECK(ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &sig, msg, NULL) == 0); - CHECK(ecount == 6); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &sig, msg, &pubkey) == 1); - CHECK(ecount == 6); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey, NULL) == 0); - CHECK(ecount == 7); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &sig, msg, key, precomputed_nonce_function, nonce) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, NULL, msg, key, precomputed_nonce_function, nonce2)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &sig, NULL, key, precomputed_nonce_function, nonce2)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &sig, msg, NULL, precomputed_nonce_function, nonce2)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &sig, msg, key, precomputed_nonce_function, nonce2) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey, key) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, NULL, msg, &pubkey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &sig, NULL, &pubkey)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &sig, msg, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &sig, msg, &pubkey) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ec_pubkey_create(CTX, &pubkey, NULL)); /* That pubkeyload fails via an ARGCHECK is a little odd but makes sense because pubkeys are an opaque data type. */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &sig, msg, &pubkey) == 0); - CHECK(ecount == 8); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, &sig, msg, &pubkey)); siglen = 72; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_der(ctx, NULL, &siglen, &sig) == 0); - CHECK(ecount == 9); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_der(ctx, signature, NULL, &sig) == 0); - CHECK(ecount == 10); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_der(ctx, signature, &siglen, NULL) == 0); - CHECK(ecount == 11); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_der(ctx, signature, &siglen, &sig) == 1); - CHECK(ecount == 11); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, NULL, signature, siglen) == 0); - CHECK(ecount == 12); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &sig, NULL, siglen) == 0); - CHECK(ecount == 13); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_der(ctx, &sig, signature, siglen) == 1); - CHECK(ecount == 13); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_der(CTX, NULL, &siglen, &sig)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_der(CTX, signature, NULL, &sig)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_der(CTX, signature, &siglen, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_der(CTX, signature, &siglen, &sig) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, NULL, signature, siglen)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &sig, NULL, siglen)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &sig, signature, siglen) == 1); siglen = 10; /* Too little room for a signature does not fail via ARGCHECK. */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_der(ctx, signature, &siglen, &sig) == 0); - CHECK(ecount == 13); - ecount = 0; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_normalize(ctx, NULL, NULL) == 0); - CHECK(ecount == 1); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_compact(ctx, NULL, &sig) == 0); - CHECK(ecount == 2); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_compact(ctx, signature, NULL) == 0); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_compact(ctx, signature, &sig) == 1); - CHECK(ecount == 3); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_compact(ctx, NULL, signature) == 0); - CHECK(ecount == 4); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_compact(ctx, &sig, NULL) == 0); - CHECK(ecount == 5); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_compact(ctx, &sig, signature) == 1); - CHECK(ecount == 5); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_der(CTX, signature, &siglen, &sig) == 0); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_signature_normalize(CTX, NULL, NULL)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_compact(CTX, NULL, &sig)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_compact(CTX, signature, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_serialize_compact(CTX, signature, &sig) == 1); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_compact(CTX, NULL, signature)); + CHECK_ILLEGAL(CTX, rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_compact(CTX, &sig, NULL)); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_compact(CTX, &sig, signature) == 1); memset(signature, 255, 64); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_parse_compact(ctx, &sig, signature) == 0); - CHECK(ecount == 5); - rustsecp256k1zkp_v0_8_0_context_set_illegal_callback(ctx, NULL, NULL); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_compact(CTX, &sig, signature) == 0); } /* Nonce function corner cases. */ @@ -7029,43 +7305,43 @@ void test_ecdsa_edge_cases(void) { int i; unsigned char key[32]; unsigned char msg[32]; - rustsecp256k1zkp_v0_8_0_ecdsa_signature sig2; - rustsecp256k1zkp_v0_8_0_scalar sr[512], ss; + rustsecp256k1zkp_v0_10_0_ecdsa_signature sig2; + rustsecp256k1zkp_v0_10_0_scalar sr[512], ss; const unsigned char *extra; extra = t == 0 ? NULL : zero; memset(msg, 0, 32); msg[31] = 1; /* High key results in signature failure. */ memset(key, 0xFF, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &sig, msg, key, NULL, extra) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &sig, msg, key, NULL, extra) == 0); CHECK(is_empty_signature(&sig)); /* Zero key results in signature failure. */ memset(key, 0, 32); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &sig, msg, key, NULL, extra) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &sig, msg, key, NULL, extra) == 0); CHECK(is_empty_signature(&sig)); /* Nonce function failure results in signature failure. */ key[31] = 1; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &sig, msg, key, nonce_function_test_fail, extra) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &sig, msg, key, nonce_function_test_fail, extra) == 0); CHECK(is_empty_signature(&sig)); /* The retry loop successfully makes its way to the first good value. */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &sig, msg, key, nonce_function_test_retry, extra) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &sig, msg, key, nonce_function_test_retry, extra) == 1); CHECK(!is_empty_signature(&sig)); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &sig2, msg, key, nonce_function_rfc6979, extra) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &sig2, msg, key, nonce_function_rfc6979, extra) == 1); CHECK(!is_empty_signature(&sig2)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&sig, &sig2, sizeof(sig)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&sig, &sig2, sizeof(sig)) == 0); /* The default nonce function is deterministic. */ - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &sig2, msg, key, NULL, extra) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &sig2, msg, key, NULL, extra) == 1); CHECK(!is_empty_signature(&sig2)); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&sig, &sig2, sizeof(sig)) == 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&sig, &sig2, sizeof(sig)) == 0); /* The default nonce function changes output with different messages. */ for(i = 0; i < 256; i++) { int j; msg[0] = i; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &sig2, msg, key, NULL, extra) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &sig2, msg, key, NULL, extra) == 1); CHECK(!is_empty_signature(&sig2)); - rustsecp256k1zkp_v0_8_0_ecdsa_signature_load(ctx, &sr[i], &ss, &sig2); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_load(CTX, &sr[i], &ss, &sig2); for (j = 0; j < i; j++) { - CHECK(!rustsecp256k1zkp_v0_8_0_scalar_eq(&sr[i], &sr[j])); + CHECK(!rustsecp256k1zkp_v0_10_0_scalar_eq(&sr[i], &sr[j])); } } msg[0] = 0; @@ -7074,11 +7350,11 @@ void test_ecdsa_edge_cases(void) { for(i = 256; i < 512; i++) { int j; key[0] = i - 256; - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &sig2, msg, key, NULL, extra) == 1); + CHECK(rustsecp256k1zkp_v0_10_0_ecdsa_sign(CTX, &sig2, msg, key, NULL, extra) == 1); CHECK(!is_empty_signature(&sig2)); - rustsecp256k1zkp_v0_8_0_ecdsa_signature_load(ctx, &sr[i], &ss, &sig2); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_load(CTX, &sr[i], &ss, &sig2); for (j = 0; j < i; j++) { - CHECK(!rustsecp256k1zkp_v0_8_0_scalar_eq(&sr[i], &sr[j])); + CHECK(!rustsecp256k1zkp_v0_10_0_scalar_eq(&sr[i], &sr[j])); } } key[0] = 0; @@ -7091,24 +7367,24 @@ void test_ecdsa_edge_cases(void) { unsigned char nonce2[32]; unsigned char nonce3[32]; unsigned char nonce4[32]; - VG_UNDEF(nonce,32); - VG_UNDEF(nonce2,32); - VG_UNDEF(nonce3,32); - VG_UNDEF(nonce4,32); + SECP256K1_CHECKMEM_UNDEFINE(nonce,32); + SECP256K1_CHECKMEM_UNDEFINE(nonce2,32); + SECP256K1_CHECKMEM_UNDEFINE(nonce3,32); + SECP256K1_CHECKMEM_UNDEFINE(nonce4,32); CHECK(nonce_function_rfc6979(nonce, zeros, zeros, NULL, NULL, 0) == 1); - VG_CHECK(nonce,32); + SECP256K1_CHECKMEM_CHECK(nonce,32); CHECK(nonce_function_rfc6979(nonce2, zeros, zeros, zeros, NULL, 0) == 1); - VG_CHECK(nonce2,32); + SECP256K1_CHECKMEM_CHECK(nonce2,32); CHECK(nonce_function_rfc6979(nonce3, zeros, zeros, NULL, (void *)zeros, 0) == 1); - VG_CHECK(nonce3,32); + SECP256K1_CHECKMEM_CHECK(nonce3,32); CHECK(nonce_function_rfc6979(nonce4, zeros, zeros, zeros, (void *)zeros, 0) == 1); - VG_CHECK(nonce4,32); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(nonce, nonce2, 32) != 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(nonce, nonce3, 32) != 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(nonce, nonce4, 32) != 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(nonce2, nonce3, 32) != 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(nonce2, nonce4, 32) != 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(nonce3, nonce4, 32) != 0); + SECP256K1_CHECKMEM_CHECK(nonce4,32); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(nonce, nonce2, 32) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(nonce, nonce3, 32) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(nonce, nonce4, 32) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(nonce2, nonce3, 32) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(nonce2, nonce4, 32) != 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(nonce3, nonce4, 32) != 0); } @@ -7122,16 +7398,58 @@ void test_ecdsa_edge_cases(void) { 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41, }; size_t outlen = 300; - CHECK(!ec_privkey_export_der(ctx, privkey, &outlen, seckey, 0)); + CHECK(!ec_privkey_export_der(CTX, privkey, &outlen, seckey, 0)); outlen = 300; - CHECK(!ec_privkey_export_der(ctx, privkey, &outlen, seckey, 1)); + CHECK(!ec_privkey_export_der(CTX, privkey, &outlen, seckey, 1)); } } -void run_ecdsa_edge_cases(void) { +static void run_ecdsa_edge_cases(void) { test_ecdsa_edge_cases(); } +/** Wycheproof tests + +The tests check for known attacks (range checks in (r,s), arithmetic errors, malleability). +*/ +static void test_ecdsa_wycheproof(void) { + #include "wycheproof/ecdsa_rustsecp256k1zkp_v0_10_0_sha256_bitcoin_test.h" + + int t; + for (t = 0; t < SECP256K1_ECDSA_WYCHEPROOF_NUMBER_TESTVECTORS; t++) { + rustsecp256k1zkp_v0_10_0_ecdsa_signature signature; + rustsecp256k1zkp_v0_10_0_sha256 hasher; + rustsecp256k1zkp_v0_10_0_pubkey pubkey; + const unsigned char *msg, *sig, *pk; + unsigned char out[32] = {0}; + int actual_verify = 0; + + memset(&pubkey, 0, sizeof(pubkey)); + pk = &wycheproof_ecdsa_public_keys[testvectors[t].pk_offset]; + CHECK(rustsecp256k1zkp_v0_10_0_ec_pubkey_parse(CTX, &pubkey, pk, 65) == 1); + + rustsecp256k1zkp_v0_10_0_sha256_initialize(&hasher); + msg = &wycheproof_ecdsa_messages[testvectors[t].msg_offset]; + rustsecp256k1zkp_v0_10_0_sha256_write(&hasher, msg, testvectors[t].msg_len); + rustsecp256k1zkp_v0_10_0_sha256_finalize(&hasher, out); + + sig = &wycheproof_ecdsa_signatures[testvectors[t].sig_offset]; + if (rustsecp256k1zkp_v0_10_0_ecdsa_signature_parse_der(CTX, &signature, sig, testvectors[t].sig_len) == 1) { + actual_verify = rustsecp256k1zkp_v0_10_0_ecdsa_verify(CTX, (const rustsecp256k1zkp_v0_10_0_ecdsa_signature *)&signature, out, &pubkey); + } + CHECK(testvectors[t].expected_verify == actual_verify); + } +} + +/* Tests cases from Wycheproof test suite. */ +static void run_ecdsa_wycheproof(void) { + test_ecdsa_wycheproof(); +} + +#ifdef ENABLE_MODULE_SCHNORRSIG_HALFAGG +#include "modules/schnorrsig_halfagg/tests_impl.h" +#endif + #ifdef ENABLE_MODULE_BPPP #include "modules/bppp/tests_impl.h" #endif @@ -7172,6 +7490,10 @@ void run_ecdsa_edge_cases(void) { #include "modules/schnorrsig/tests_impl.h" #endif +#ifdef ENABLE_MODULE_ELLSWIFT +#include "modules/ellswift/tests_impl.h" +#endif + #ifdef ENABLE_MODULE_ECDSA_S2C #include "modules/ecdsa_s2c/tests_impl.h" #endif @@ -7180,182 +7502,195 @@ void run_ecdsa_edge_cases(void) { #include "modules/ecdsa_adaptor/tests_impl.h" #endif -void run_rustsecp256k1zkp_v0_8_0_memczero_test(void) { +static void run_rustsecp256k1zkp_v0_10_0_memczero_test(void) { unsigned char buf1[6] = {1, 2, 3, 4, 5, 6}; unsigned char buf2[sizeof(buf1)]; - /* rustsecp256k1zkp_v0_8_0_memczero(..., ..., 0) is a noop. */ + /* rustsecp256k1zkp_v0_10_0_memczero(..., ..., 0) is a noop. */ memcpy(buf2, buf1, sizeof(buf1)); - rustsecp256k1zkp_v0_8_0_memczero(buf1, sizeof(buf1), 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(buf1, buf2, sizeof(buf1)) == 0); + rustsecp256k1zkp_v0_10_0_memczero(buf1, sizeof(buf1), 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(buf1, buf2, sizeof(buf1)) == 0); - /* rustsecp256k1zkp_v0_8_0_memczero(..., ..., 1) zeros the buffer. */ + /* rustsecp256k1zkp_v0_10_0_memczero(..., ..., 1) zeros the buffer. */ memset(buf2, 0, sizeof(buf2)); - rustsecp256k1zkp_v0_8_0_memczero(buf1, sizeof(buf1) , 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(buf1, buf2, sizeof(buf1)) == 0); + rustsecp256k1zkp_v0_10_0_memczero(buf1, sizeof(buf1) , 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(buf1, buf2, sizeof(buf1)) == 0); } -void run_rustsecp256k1zkp_v0_8_0_byteorder_tests(void) { - const uint32_t x = 0xFF03AB45; - const unsigned char x_be[4] = {0xFF, 0x03, 0xAB, 0x45}; - unsigned char buf[4]; - uint32_t x_; +static void run_rustsecp256k1zkp_v0_10_0_byteorder_tests(void) { + { + const uint32_t x = 0xFF03AB45; + const unsigned char x_be[4] = {0xFF, 0x03, 0xAB, 0x45}; + unsigned char buf[4]; + uint32_t x_; - rustsecp256k1zkp_v0_8_0_write_be32(buf, x); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(buf, x_be, sizeof(buf)) == 0); + rustsecp256k1zkp_v0_10_0_write_be32(buf, x); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(buf, x_be, sizeof(buf)) == 0); - x_ = rustsecp256k1zkp_v0_8_0_read_be32(buf); - CHECK(x == x_); + x_ = rustsecp256k1zkp_v0_10_0_read_be32(buf); + CHECK(x == x_); + } + + { + const uint64_t x = 0xCAFE0123BEEF4567; + const unsigned char x_be[8] = {0xCA, 0xFE, 0x01, 0x23, 0xBE, 0xEF, 0x45, 0x67}; + unsigned char buf[8]; + uint64_t x_; + + rustsecp256k1zkp_v0_10_0_write_be64(buf, x); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(buf, x_be, sizeof(buf)) == 0); + + x_ = rustsecp256k1zkp_v0_10_0_read_be64(buf); + CHECK(x == x_); + } } -void int_cmov_test(void) { +static void int_cmov_test(void) { int r = INT_MAX; int a = 0; - rustsecp256k1zkp_v0_8_0_int_cmov(&r, &a, 0); + rustsecp256k1zkp_v0_10_0_int_cmov(&r, &a, 0); CHECK(r == INT_MAX); r = 0; a = INT_MAX; - rustsecp256k1zkp_v0_8_0_int_cmov(&r, &a, 1); + rustsecp256k1zkp_v0_10_0_int_cmov(&r, &a, 1); CHECK(r == INT_MAX); a = 0; - rustsecp256k1zkp_v0_8_0_int_cmov(&r, &a, 1); + rustsecp256k1zkp_v0_10_0_int_cmov(&r, &a, 1); CHECK(r == 0); a = 1; - rustsecp256k1zkp_v0_8_0_int_cmov(&r, &a, 1); + rustsecp256k1zkp_v0_10_0_int_cmov(&r, &a, 1); CHECK(r == 1); r = 1; a = 0; - rustsecp256k1zkp_v0_8_0_int_cmov(&r, &a, 0); + rustsecp256k1zkp_v0_10_0_int_cmov(&r, &a, 0); CHECK(r == 1); } -void fe_cmov_test(void) { - static const rustsecp256k1zkp_v0_8_0_fe zero = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0); - static const rustsecp256k1zkp_v0_8_0_fe one = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 1); - static const rustsecp256k1zkp_v0_8_0_fe max = SECP256K1_FE_CONST( +static void fe_cmov_test(void) { + static const rustsecp256k1zkp_v0_10_0_fe zero = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0); + static const rustsecp256k1zkp_v0_10_0_fe one = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 1); + static const rustsecp256k1zkp_v0_10_0_fe max = SECP256K1_FE_CONST( 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL ); - rustsecp256k1zkp_v0_8_0_fe r = max; - rustsecp256k1zkp_v0_8_0_fe a = zero; + rustsecp256k1zkp_v0_10_0_fe r = max; + rustsecp256k1zkp_v0_10_0_fe a = zero; - rustsecp256k1zkp_v0_8_0_fe_cmov(&r, &a, 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&r, &max, sizeof(r)) == 0); + rustsecp256k1zkp_v0_10_0_fe_cmov(&r, &a, 0); + CHECK(fe_identical(&r, &max)); r = zero; a = max; - rustsecp256k1zkp_v0_8_0_fe_cmov(&r, &a, 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&r, &max, sizeof(r)) == 0); + rustsecp256k1zkp_v0_10_0_fe_cmov(&r, &a, 1); + CHECK(fe_identical(&r, &max)); a = zero; - rustsecp256k1zkp_v0_8_0_fe_cmov(&r, &a, 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&r, &zero, sizeof(r)) == 0); + rustsecp256k1zkp_v0_10_0_fe_cmov(&r, &a, 1); + CHECK(fe_identical(&r, &zero)); a = one; - rustsecp256k1zkp_v0_8_0_fe_cmov(&r, &a, 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&r, &one, sizeof(r)) == 0); + rustsecp256k1zkp_v0_10_0_fe_cmov(&r, &a, 1); + CHECK(fe_identical(&r, &one)); r = one; a = zero; - rustsecp256k1zkp_v0_8_0_fe_cmov(&r, &a, 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&r, &one, sizeof(r)) == 0); + rustsecp256k1zkp_v0_10_0_fe_cmov(&r, &a, 0); + CHECK(fe_identical(&r, &one)); } -void fe_storage_cmov_test(void) { - static const rustsecp256k1zkp_v0_8_0_fe_storage zero = SECP256K1_FE_STORAGE_CONST(0, 0, 0, 0, 0, 0, 0, 0); - static const rustsecp256k1zkp_v0_8_0_fe_storage one = SECP256K1_FE_STORAGE_CONST(0, 0, 0, 0, 0, 0, 0, 1); - static const rustsecp256k1zkp_v0_8_0_fe_storage max = SECP256K1_FE_STORAGE_CONST( +static void fe_storage_cmov_test(void) { + static const rustsecp256k1zkp_v0_10_0_fe_storage zero = SECP256K1_FE_STORAGE_CONST(0, 0, 0, 0, 0, 0, 0, 0); + static const rustsecp256k1zkp_v0_10_0_fe_storage one = SECP256K1_FE_STORAGE_CONST(0, 0, 0, 0, 0, 0, 0, 1); + static const rustsecp256k1zkp_v0_10_0_fe_storage max = SECP256K1_FE_STORAGE_CONST( 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL ); - rustsecp256k1zkp_v0_8_0_fe_storage r = max; - rustsecp256k1zkp_v0_8_0_fe_storage a = zero; + rustsecp256k1zkp_v0_10_0_fe_storage r = max; + rustsecp256k1zkp_v0_10_0_fe_storage a = zero; - rustsecp256k1zkp_v0_8_0_fe_storage_cmov(&r, &a, 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&r, &max, sizeof(r)) == 0); + rustsecp256k1zkp_v0_10_0_fe_storage_cmov(&r, &a, 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&r, &max, sizeof(r)) == 0); r = zero; a = max; - rustsecp256k1zkp_v0_8_0_fe_storage_cmov(&r, &a, 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&r, &max, sizeof(r)) == 0); + rustsecp256k1zkp_v0_10_0_fe_storage_cmov(&r, &a, 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&r, &max, sizeof(r)) == 0); a = zero; - rustsecp256k1zkp_v0_8_0_fe_storage_cmov(&r, &a, 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&r, &zero, sizeof(r)) == 0); + rustsecp256k1zkp_v0_10_0_fe_storage_cmov(&r, &a, 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&r, &zero, sizeof(r)) == 0); a = one; - rustsecp256k1zkp_v0_8_0_fe_storage_cmov(&r, &a, 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&r, &one, sizeof(r)) == 0); + rustsecp256k1zkp_v0_10_0_fe_storage_cmov(&r, &a, 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&r, &one, sizeof(r)) == 0); r = one; a = zero; - rustsecp256k1zkp_v0_8_0_fe_storage_cmov(&r, &a, 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&r, &one, sizeof(r)) == 0); + rustsecp256k1zkp_v0_10_0_fe_storage_cmov(&r, &a, 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&r, &one, sizeof(r)) == 0); } -void scalar_cmov_test(void) { - static const rustsecp256k1zkp_v0_8_0_scalar zero = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0); - static const rustsecp256k1zkp_v0_8_0_scalar one = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 1); - static const rustsecp256k1zkp_v0_8_0_scalar max = SECP256K1_SCALAR_CONST( - 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, - 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL +static void scalar_cmov_test(void) { + static const rustsecp256k1zkp_v0_10_0_scalar max = SECP256K1_SCALAR_CONST( + 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFEUL, + 0xBAAEDCE6UL, 0xAF48A03BUL, 0xBFD25E8CUL, 0xD0364140UL ); - rustsecp256k1zkp_v0_8_0_scalar r = max; - rustsecp256k1zkp_v0_8_0_scalar a = zero; + rustsecp256k1zkp_v0_10_0_scalar r = max; + rustsecp256k1zkp_v0_10_0_scalar a = rustsecp256k1zkp_v0_10_0_scalar_zero; - rustsecp256k1zkp_v0_8_0_scalar_cmov(&r, &a, 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&r, &max, sizeof(r)) == 0); + rustsecp256k1zkp_v0_10_0_scalar_cmov(&r, &a, 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&r, &max, sizeof(r)) == 0); - r = zero; a = max; - rustsecp256k1zkp_v0_8_0_scalar_cmov(&r, &a, 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&r, &max, sizeof(r)) == 0); + r = rustsecp256k1zkp_v0_10_0_scalar_zero; a = max; + rustsecp256k1zkp_v0_10_0_scalar_cmov(&r, &a, 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&r, &max, sizeof(r)) == 0); - a = zero; - rustsecp256k1zkp_v0_8_0_scalar_cmov(&r, &a, 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&r, &zero, sizeof(r)) == 0); + a = rustsecp256k1zkp_v0_10_0_scalar_zero; + rustsecp256k1zkp_v0_10_0_scalar_cmov(&r, &a, 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&r, &rustsecp256k1zkp_v0_10_0_scalar_zero, sizeof(r)) == 0); - a = one; - rustsecp256k1zkp_v0_8_0_scalar_cmov(&r, &a, 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&r, &one, sizeof(r)) == 0); + a = rustsecp256k1zkp_v0_10_0_scalar_one; + rustsecp256k1zkp_v0_10_0_scalar_cmov(&r, &a, 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&r, &rustsecp256k1zkp_v0_10_0_scalar_one, sizeof(r)) == 0); - r = one; a = zero; - rustsecp256k1zkp_v0_8_0_scalar_cmov(&r, &a, 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&r, &one, sizeof(r)) == 0); + r = rustsecp256k1zkp_v0_10_0_scalar_one; a = rustsecp256k1zkp_v0_10_0_scalar_zero; + rustsecp256k1zkp_v0_10_0_scalar_cmov(&r, &a, 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&r, &rustsecp256k1zkp_v0_10_0_scalar_one, sizeof(r)) == 0); } -void ge_storage_cmov_test(void) { - static const rustsecp256k1zkp_v0_8_0_ge_storage zero = SECP256K1_GE_STORAGE_CONST(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - static const rustsecp256k1zkp_v0_8_0_ge_storage one = SECP256K1_GE_STORAGE_CONST(0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1); - static const rustsecp256k1zkp_v0_8_0_ge_storage max = SECP256K1_GE_STORAGE_CONST( +static void ge_storage_cmov_test(void) { + static const rustsecp256k1zkp_v0_10_0_ge_storage zero = SECP256K1_GE_STORAGE_CONST(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + static const rustsecp256k1zkp_v0_10_0_ge_storage one = SECP256K1_GE_STORAGE_CONST(0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1); + static const rustsecp256k1zkp_v0_10_0_ge_storage max = SECP256K1_GE_STORAGE_CONST( 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL ); - rustsecp256k1zkp_v0_8_0_ge_storage r = max; - rustsecp256k1zkp_v0_8_0_ge_storage a = zero; + rustsecp256k1zkp_v0_10_0_ge_storage r = max; + rustsecp256k1zkp_v0_10_0_ge_storage a = zero; - rustsecp256k1zkp_v0_8_0_ge_storage_cmov(&r, &a, 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&r, &max, sizeof(r)) == 0); + rustsecp256k1zkp_v0_10_0_ge_storage_cmov(&r, &a, 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&r, &max, sizeof(r)) == 0); r = zero; a = max; - rustsecp256k1zkp_v0_8_0_ge_storage_cmov(&r, &a, 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&r, &max, sizeof(r)) == 0); + rustsecp256k1zkp_v0_10_0_ge_storage_cmov(&r, &a, 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&r, &max, sizeof(r)) == 0); a = zero; - rustsecp256k1zkp_v0_8_0_ge_storage_cmov(&r, &a, 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&r, &zero, sizeof(r)) == 0); + rustsecp256k1zkp_v0_10_0_ge_storage_cmov(&r, &a, 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&r, &zero, sizeof(r)) == 0); a = one; - rustsecp256k1zkp_v0_8_0_ge_storage_cmov(&r, &a, 1); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&r, &one, sizeof(r)) == 0); + rustsecp256k1zkp_v0_10_0_ge_storage_cmov(&r, &a, 1); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&r, &one, sizeof(r)) == 0); r = one; a = zero; - rustsecp256k1zkp_v0_8_0_ge_storage_cmov(&r, &a, 0); - CHECK(rustsecp256k1zkp_v0_8_0_memcmp_var(&r, &one, sizeof(r)) == 0); + rustsecp256k1zkp_v0_10_0_ge_storage_cmov(&r, &a, 0); + CHECK(rustsecp256k1zkp_v0_10_0_memcmp_var(&r, &one, sizeof(r)) == 0); } -void run_cmov_tests(void) { +static void run_cmov_tests(void) { int_cmov_test(); fe_cmov_test(); fe_storage_cmov_test(); @@ -7374,41 +7709,71 @@ int main(int argc, char **argv) { /* find iteration count */ if (argc > 1) { - count = strtol(argv[1], NULL, 0); + COUNT = strtol(argv[1], NULL, 0); } else { const char* env = getenv("SECP256K1_TEST_ITERS"); if (env && strlen(env) > 0) { - count = strtol(env, NULL, 0); + COUNT = strtol(env, NULL, 0); } } - if (count <= 0) { + if (COUNT <= 0) { fputs("An iteration count of 0 or less is not allowed.\n", stderr); return EXIT_FAILURE; } - printf("test count = %i\n", count); + printf("test count = %i\n", COUNT); + + /* run test RNG tests (must run before we really initialize the test RNG) */ + run_xoshiro256pp_tests(); /* find random seed */ - rustsecp256k1zkp_v0_8_0_testrand_init(argc > 2 ? argv[2] : NULL); + rustsecp256k1zkp_v0_10_0_testrand_init(argc > 2 ? argv[2] : NULL); - /* initialize */ - run_context_tests(0); - run_context_tests(1); - run_scratch_tests(); - ctx = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); - if (rustsecp256k1zkp_v0_8_0_testrand_bits(1)) { + /*** Setup test environment ***/ + + /* Create a global context available to all tests */ + CTX = rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_CONTEXT_NONE); + /* Randomize the context only with probability 15/16 + to make sure we test without context randomization from time to time. + TODO Reconsider this when recalibrating the tests. */ + if (rustsecp256k1zkp_v0_10_0_testrand_bits(4)) { unsigned char rand32[32]; - rustsecp256k1zkp_v0_8_0_testrand256(rand32); - CHECK(rustsecp256k1zkp_v0_8_0_context_randomize(ctx, rustsecp256k1zkp_v0_8_0_testrand_bits(1) ? rand32 : NULL)); + rustsecp256k1zkp_v0_10_0_testrand256(rand32); + CHECK(rustsecp256k1zkp_v0_10_0_context_randomize(CTX, rand32)); } + /* Make a writable copy of rustsecp256k1zkp_v0_10_0_context_static in order to test the effect of API functions + that write to the context. The API does not support cloning the static context, so we use + memcpy instead. The user is not supposed to copy a context but we should still ensure that + the API functions handle copies of the static context gracefully. */ + STATIC_CTX = malloc(sizeof(*rustsecp256k1zkp_v0_10_0_context_static)); + CHECK(STATIC_CTX != NULL); + memcpy(STATIC_CTX, rustsecp256k1zkp_v0_10_0_context_static, sizeof(rustsecp256k1zkp_v0_10_0_context)); + CHECK(!rustsecp256k1zkp_v0_10_0_context_is_proper(STATIC_CTX)); + + /*** Run actual tests ***/ + + /* selftest tests */ + run_selftest_tests(); + + /* context tests */ + run_proper_context_tests(0); run_proper_context_tests(1); + run_static_context_tests(0); run_static_context_tests(1); + run_deprecated_context_flags_test(); - run_rand_bits(); - run_rand_int(); + /* scratch tests */ + run_scratch_tests(); + + /* util tests */ run_util_tests(); + /* integer arithmetic tests */ +#ifdef SECP256K1_WIDEMUL_INT128 + run_int128_tests(); +#endif run_ctz_tests(); run_modinv_tests(); run_inverse_tests(); + /* hash tests */ run_sha256_known_output_tests(); run_sha256_counter_tests(); run_hmac_sha256_tests(); @@ -7422,6 +7787,7 @@ int main(int argc, char **argv) { run_field_half(); run_field_misc(); run_field_convert(); + run_field_be32_overflow(); run_fe_mul(); run_sqr(); run_sqrt(); @@ -7456,6 +7822,10 @@ int main(int argc, char **argv) { /* EC key arithmetic test */ run_eckey_negate_test(); +#ifdef ENABLE_MODULE_SCHNORRSIG_HALFAGG + run_schnorrsig_halfagg_tests(); +#endif + #ifdef ENABLE_MODULE_BPPP run_bppp_tests(); #endif @@ -7470,12 +7840,14 @@ int main(int argc, char **argv) { #endif /* ecdsa tests */ + run_ec_illegal_argument_tests(); run_pubkey_comparison(); run_random_pubkeys(); run_ecdsa_der_parse(); run_ecdsa_sign_verify(); run_ecdsa_end_to_end(); run_ecdsa_edge_cases(); + run_ecdsa_wycheproof(); #ifdef ENABLE_MODULE_RECOVERY /* ECDSA pubkey recovery tests */ @@ -7507,6 +7879,10 @@ int main(int argc, char **argv) { run_schnorrsig_tests(); #endif +#ifdef ENABLE_MODULE_ELLSWIFT + run_ellswift_tests(); +#endif + #ifdef ENABLE_MODULE_ECDSA_S2C /* ECDSA sign to contract */ run_ecdsa_s2c_tests(); @@ -7517,15 +7893,16 @@ int main(int argc, char **argv) { #endif /* util tests */ - run_rustsecp256k1zkp_v0_8_0_memczero_test(); - run_rustsecp256k1zkp_v0_8_0_byteorder_tests(); + run_rustsecp256k1zkp_v0_10_0_memczero_test(); + run_rustsecp256k1zkp_v0_10_0_byteorder_tests(); run_cmov_tests(); - rustsecp256k1zkp_v0_8_0_testrand_finish(); + /*** Tear down test environment ***/ + free(STATIC_CTX); + rustsecp256k1zkp_v0_10_0_context_destroy(CTX); - /* shutdown */ - rustsecp256k1zkp_v0_8_0_context_destroy(ctx); + rustsecp256k1zkp_v0_10_0_testrand_finish(); printf("no problems found\n"); return 0; diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/tests_exhaustive.c b/secp256k1-zkp-sys/depend/secp256k1/src/tests_exhaustive.c index 5ea88fe0..1c22a9ed 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/tests_exhaustive.c +++ b/secp256k1-zkp-sys/depend/secp256k1/src/tests_exhaustive.c @@ -4,10 +4,6 @@ * file COPYING or https://www.opensource.org/licenses/mit-license.php.* ***********************************************************************/ -#if defined HAVE_CONFIG_H -#include "libsecp256k1-config.h" -#endif - #include #include #include @@ -17,54 +13,26 @@ #define EXHAUSTIVE_TEST_ORDER 13 #endif +/* These values of B are all values in [1, 8] that result in a curve with even order. */ +#define EXHAUSTIVE_TEST_CURVE_HAS_EVEN_ORDER (SECP256K1_B == 1 || SECP256K1_B == 6 || SECP256K1_B == 8) + +#ifdef USE_EXTERNAL_DEFAULT_CALLBACKS + #pragma message("Ignoring USE_EXTERNAL_CALLBACKS in exhaustive_tests.") + #undef USE_EXTERNAL_DEFAULT_CALLBACKS +#endif #include "secp256k1.c" + #include "../include/secp256k1.h" #include "assumptions.h" #include "group.h" #include "testrand_impl.h" #include "ecmult_compute_table_impl.h" #include "ecmult_gen_compute_table_impl.h" +#include "testutil.h" +#include "util.h" static int count = 2; -/** stolen from tests.c */ -void ge_equals_ge(const rustsecp256k1zkp_v0_8_0_ge *a, const rustsecp256k1zkp_v0_8_0_ge *b) { - CHECK(a->infinity == b->infinity); - if (a->infinity) { - return; - } - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&a->x, &b->x)); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&a->y, &b->y)); -} - -void ge_equals_gej(const rustsecp256k1zkp_v0_8_0_ge *a, const rustsecp256k1zkp_v0_8_0_gej *b) { - rustsecp256k1zkp_v0_8_0_fe z2s; - rustsecp256k1zkp_v0_8_0_fe u1, u2, s1, s2; - CHECK(a->infinity == b->infinity); - if (a->infinity) { - return; - } - /* Check a.x * b.z^2 == b.x && a.y * b.z^3 == b.y, to avoid inverses. */ - rustsecp256k1zkp_v0_8_0_fe_sqr(&z2s, &b->z); - rustsecp256k1zkp_v0_8_0_fe_mul(&u1, &a->x, &z2s); - u2 = b->x; rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&u2); - rustsecp256k1zkp_v0_8_0_fe_mul(&s1, &a->y, &z2s); rustsecp256k1zkp_v0_8_0_fe_mul(&s1, &s1, &b->z); - s2 = b->y; rustsecp256k1zkp_v0_8_0_fe_normalize_weak(&s2); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&u1, &u2)); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&s1, &s2)); -} - -void random_fe(rustsecp256k1zkp_v0_8_0_fe *x) { - unsigned char bin[32]; - do { - rustsecp256k1zkp_v0_8_0_testrand256(bin); - if (rustsecp256k1zkp_v0_8_0_fe_set_b32(x, bin)) { - return; - } - } while(1); -} -/** END stolen from tests.c */ - static uint32_t num_cores = 1; static uint32_t this_core = 0; @@ -74,10 +42,10 @@ SECP256K1_INLINE static int skip_section(uint64_t* iter) { return ((((uint32_t)*iter ^ (*iter >> 32)) * num_cores) >> 32) != this_core; } -int rustsecp256k1zkp_v0_8_0_nonce_function_smallint(unsigned char *nonce32, const unsigned char *msg32, +static int rustsecp256k1zkp_v0_10_0_nonce_function_smallint(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int attempt) { - rustsecp256k1zkp_v0_8_0_scalar s; + rustsecp256k1zkp_v0_10_0_scalar s; int *idata = data; (void)msg32; (void)key32; @@ -89,210 +57,236 @@ int rustsecp256k1zkp_v0_8_0_nonce_function_smallint(unsigned char *nonce32, cons if (attempt > 0) { *idata = (*idata + 1) % EXHAUSTIVE_TEST_ORDER; } - rustsecp256k1zkp_v0_8_0_scalar_set_int(&s, *idata); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(nonce32, &s); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&s, *idata); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(nonce32, &s); return 1; } -void test_exhaustive_endomorphism(const rustsecp256k1zkp_v0_8_0_ge *group) { +static void test_exhaustive_endomorphism(const rustsecp256k1zkp_v0_10_0_ge *group) { int i; for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) { - rustsecp256k1zkp_v0_8_0_ge res; - rustsecp256k1zkp_v0_8_0_ge_mul_lambda(&res, &group[i]); - ge_equals_ge(&group[i * EXHAUSTIVE_TEST_LAMBDA % EXHAUSTIVE_TEST_ORDER], &res); + rustsecp256k1zkp_v0_10_0_ge res; + rustsecp256k1zkp_v0_10_0_ge_mul_lambda(&res, &group[i]); + CHECK(rustsecp256k1zkp_v0_10_0_ge_eq_var(&group[i * EXHAUSTIVE_TEST_LAMBDA % EXHAUSTIVE_TEST_ORDER], &res)); } } -void test_exhaustive_addition(const rustsecp256k1zkp_v0_8_0_ge *group, const rustsecp256k1zkp_v0_8_0_gej *groupj) { +static void test_exhaustive_addition(const rustsecp256k1zkp_v0_10_0_ge *group, const rustsecp256k1zkp_v0_10_0_gej *groupj) { int i, j; uint64_t iter = 0; /* Sanity-check (and check infinity functions) */ - CHECK(rustsecp256k1zkp_v0_8_0_ge_is_infinity(&group[0])); - CHECK(rustsecp256k1zkp_v0_8_0_gej_is_infinity(&groupj[0])); + CHECK(rustsecp256k1zkp_v0_10_0_ge_is_infinity(&group[0])); + CHECK(rustsecp256k1zkp_v0_10_0_gej_is_infinity(&groupj[0])); for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) { - CHECK(!rustsecp256k1zkp_v0_8_0_ge_is_infinity(&group[i])); - CHECK(!rustsecp256k1zkp_v0_8_0_gej_is_infinity(&groupj[i])); + CHECK(!rustsecp256k1zkp_v0_10_0_ge_is_infinity(&group[i])); + CHECK(!rustsecp256k1zkp_v0_10_0_gej_is_infinity(&groupj[i])); } /* Check all addition formulae */ for (j = 0; j < EXHAUSTIVE_TEST_ORDER; j++) { - rustsecp256k1zkp_v0_8_0_fe fe_inv; + rustsecp256k1zkp_v0_10_0_fe fe_inv; if (skip_section(&iter)) continue; - rustsecp256k1zkp_v0_8_0_fe_inv(&fe_inv, &groupj[j].z); + rustsecp256k1zkp_v0_10_0_fe_inv(&fe_inv, &groupj[j].z); for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) { - rustsecp256k1zkp_v0_8_0_ge zless_gej; - rustsecp256k1zkp_v0_8_0_gej tmp; + rustsecp256k1zkp_v0_10_0_ge zless_gej; + rustsecp256k1zkp_v0_10_0_gej tmp; /* add_var */ - rustsecp256k1zkp_v0_8_0_gej_add_var(&tmp, &groupj[i], &groupj[j], NULL); - ge_equals_gej(&group[(i + j) % EXHAUSTIVE_TEST_ORDER], &tmp); + rustsecp256k1zkp_v0_10_0_gej_add_var(&tmp, &groupj[i], &groupj[j], NULL); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&tmp, &group[(i + j) % EXHAUSTIVE_TEST_ORDER])); /* add_ge */ if (j > 0) { - rustsecp256k1zkp_v0_8_0_gej_add_ge(&tmp, &groupj[i], &group[j]); - ge_equals_gej(&group[(i + j) % EXHAUSTIVE_TEST_ORDER], &tmp); + rustsecp256k1zkp_v0_10_0_gej_add_ge(&tmp, &groupj[i], &group[j]); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&tmp, &group[(i + j) % EXHAUSTIVE_TEST_ORDER])); } /* add_ge_var */ - rustsecp256k1zkp_v0_8_0_gej_add_ge_var(&tmp, &groupj[i], &group[j], NULL); - ge_equals_gej(&group[(i + j) % EXHAUSTIVE_TEST_ORDER], &tmp); + rustsecp256k1zkp_v0_10_0_gej_add_ge_var(&tmp, &groupj[i], &group[j], NULL); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&tmp, &group[(i + j) % EXHAUSTIVE_TEST_ORDER])); /* add_zinv_var */ zless_gej.infinity = groupj[j].infinity; zless_gej.x = groupj[j].x; zless_gej.y = groupj[j].y; - rustsecp256k1zkp_v0_8_0_gej_add_zinv_var(&tmp, &groupj[i], &zless_gej, &fe_inv); - ge_equals_gej(&group[(i + j) % EXHAUSTIVE_TEST_ORDER], &tmp); + rustsecp256k1zkp_v0_10_0_gej_add_zinv_var(&tmp, &groupj[i], &zless_gej, &fe_inv); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&tmp, &group[(i + j) % EXHAUSTIVE_TEST_ORDER])); } } /* Check doubling */ for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) { - rustsecp256k1zkp_v0_8_0_gej tmp; - rustsecp256k1zkp_v0_8_0_gej_double(&tmp, &groupj[i]); - ge_equals_gej(&group[(2 * i) % EXHAUSTIVE_TEST_ORDER], &tmp); - rustsecp256k1zkp_v0_8_0_gej_double_var(&tmp, &groupj[i], NULL); - ge_equals_gej(&group[(2 * i) % EXHAUSTIVE_TEST_ORDER], &tmp); + rustsecp256k1zkp_v0_10_0_gej tmp; + rustsecp256k1zkp_v0_10_0_gej_double(&tmp, &groupj[i]); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&tmp, &group[(2 * i) % EXHAUSTIVE_TEST_ORDER])); + rustsecp256k1zkp_v0_10_0_gej_double_var(&tmp, &groupj[i], NULL); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&tmp, &group[(2 * i) % EXHAUSTIVE_TEST_ORDER])); } /* Check negation */ for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) { - rustsecp256k1zkp_v0_8_0_ge tmp; - rustsecp256k1zkp_v0_8_0_gej tmpj; - rustsecp256k1zkp_v0_8_0_ge_neg(&tmp, &group[i]); - ge_equals_ge(&group[EXHAUSTIVE_TEST_ORDER - i], &tmp); - rustsecp256k1zkp_v0_8_0_gej_neg(&tmpj, &groupj[i]); - ge_equals_gej(&group[EXHAUSTIVE_TEST_ORDER - i], &tmpj); + rustsecp256k1zkp_v0_10_0_ge tmp; + rustsecp256k1zkp_v0_10_0_gej tmpj; + rustsecp256k1zkp_v0_10_0_ge_neg(&tmp, &group[i]); + CHECK(rustsecp256k1zkp_v0_10_0_ge_eq_var(&tmp, &group[EXHAUSTIVE_TEST_ORDER - i])); + rustsecp256k1zkp_v0_10_0_gej_neg(&tmpj, &groupj[i]); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&tmpj, &group[EXHAUSTIVE_TEST_ORDER - i])); } } -void test_exhaustive_ecmult(const rustsecp256k1zkp_v0_8_0_ge *group, const rustsecp256k1zkp_v0_8_0_gej *groupj) { +static void test_exhaustive_ecmult(const rustsecp256k1zkp_v0_10_0_ge *group, const rustsecp256k1zkp_v0_10_0_gej *groupj) { int i, j, r_log; uint64_t iter = 0; for (r_log = 1; r_log < EXHAUSTIVE_TEST_ORDER; r_log++) { for (j = 0; j < EXHAUSTIVE_TEST_ORDER; j++) { if (skip_section(&iter)) continue; for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) { - rustsecp256k1zkp_v0_8_0_gej tmp; - rustsecp256k1zkp_v0_8_0_scalar na, ng; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&na, i); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&ng, j); + rustsecp256k1zkp_v0_10_0_gej tmp; + rustsecp256k1zkp_v0_10_0_scalar na, ng; + rustsecp256k1zkp_v0_10_0_scalar_set_int(&na, i); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&ng, j); - rustsecp256k1zkp_v0_8_0_ecmult(&tmp, &groupj[r_log], &na, &ng); - ge_equals_gej(&group[(i * r_log + j) % EXHAUSTIVE_TEST_ORDER], &tmp); + rustsecp256k1zkp_v0_10_0_ecmult(&tmp, &groupj[r_log], &na, &ng); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&tmp, &group[(i * r_log + j) % EXHAUSTIVE_TEST_ORDER])); + } + } + } - if (i > 0) { - rustsecp256k1zkp_v0_8_0_ecmult_const(&tmp, &group[i], &ng, 256); - ge_equals_gej(&group[(i * j) % EXHAUSTIVE_TEST_ORDER], &tmp); - } + for (j = 0; j < EXHAUSTIVE_TEST_ORDER; j++) { + for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) { + int ret; + rustsecp256k1zkp_v0_10_0_gej tmp; + rustsecp256k1zkp_v0_10_0_fe xn, xd, tmpf; + rustsecp256k1zkp_v0_10_0_scalar ng; + + if (skip_section(&iter)) continue; + + rustsecp256k1zkp_v0_10_0_scalar_set_int(&ng, j); + + /* Test rustsecp256k1zkp_v0_10_0_ecmult_const. */ + rustsecp256k1zkp_v0_10_0_ecmult_const(&tmp, &group[i], &ng); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&tmp, &group[(i * j) % EXHAUSTIVE_TEST_ORDER])); + + if (i != 0 && j != 0) { + /* Test rustsecp256k1zkp_v0_10_0_ecmult_const_xonly with all curve X coordinates, and xd=NULL. */ + ret = rustsecp256k1zkp_v0_10_0_ecmult_const_xonly(&tmpf, &group[i].x, NULL, &ng, 0); + CHECK(ret); + CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&tmpf, &group[(i * j) % EXHAUSTIVE_TEST_ORDER].x)); + + /* Test rustsecp256k1zkp_v0_10_0_ecmult_const_xonly with all curve X coordinates, with random xd. */ + random_fe_non_zero(&xd); + rustsecp256k1zkp_v0_10_0_fe_mul(&xn, &xd, &group[i].x); + ret = rustsecp256k1zkp_v0_10_0_ecmult_const_xonly(&tmpf, &xn, &xd, &ng, 0); + CHECK(ret); + CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&tmpf, &group[(i * j) % EXHAUSTIVE_TEST_ORDER].x)); } } } } typedef struct { - rustsecp256k1zkp_v0_8_0_scalar sc[2]; - rustsecp256k1zkp_v0_8_0_ge pt[2]; + rustsecp256k1zkp_v0_10_0_scalar sc[2]; + rustsecp256k1zkp_v0_10_0_ge pt[2]; } ecmult_multi_data; -static int ecmult_multi_callback(rustsecp256k1zkp_v0_8_0_scalar *sc, rustsecp256k1zkp_v0_8_0_ge *pt, size_t idx, void *cbdata) { +static int ecmult_multi_callback(rustsecp256k1zkp_v0_10_0_scalar *sc, rustsecp256k1zkp_v0_10_0_ge *pt, size_t idx, void *cbdata) { ecmult_multi_data *data = (ecmult_multi_data*) cbdata; *sc = data->sc[idx]; *pt = data->pt[idx]; return 1; } -void test_exhaustive_ecmult_multi(const rustsecp256k1zkp_v0_8_0_context *ctx, const rustsecp256k1zkp_v0_8_0_ge *group) { +static void test_exhaustive_ecmult_multi(const rustsecp256k1zkp_v0_10_0_context *ctx, const rustsecp256k1zkp_v0_10_0_ge *group) { int i, j, k, x, y; uint64_t iter = 0; - rustsecp256k1zkp_v0_8_0_scratch *scratch = rustsecp256k1zkp_v0_8_0_scratch_create(&ctx->error_callback, 4096); + rustsecp256k1zkp_v0_10_0_scratch *scratch = rustsecp256k1zkp_v0_10_0_scratch_create(&ctx->error_callback, 4096); for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) { for (j = 0; j < EXHAUSTIVE_TEST_ORDER; j++) { for (k = 0; k < EXHAUSTIVE_TEST_ORDER; k++) { for (x = 0; x < EXHAUSTIVE_TEST_ORDER; x++) { if (skip_section(&iter)) continue; for (y = 0; y < EXHAUSTIVE_TEST_ORDER; y++) { - rustsecp256k1zkp_v0_8_0_gej tmp; - rustsecp256k1zkp_v0_8_0_scalar g_sc; + rustsecp256k1zkp_v0_10_0_gej tmp; + rustsecp256k1zkp_v0_10_0_scalar g_sc; ecmult_multi_data data; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&data.sc[0], i); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&data.sc[1], j); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&g_sc, k); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&data.sc[0], i); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&data.sc[1], j); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&g_sc, k); data.pt[0] = group[x]; data.pt[1] = group[y]; - rustsecp256k1zkp_v0_8_0_ecmult_multi_var(&ctx->error_callback, scratch, &tmp, &g_sc, ecmult_multi_callback, &data, 2); - ge_equals_gej(&group[(i * x + j * y + k) % EXHAUSTIVE_TEST_ORDER], &tmp); + rustsecp256k1zkp_v0_10_0_ecmult_multi_var(&ctx->error_callback, scratch, &tmp, &g_sc, ecmult_multi_callback, &data, 2); + CHECK(rustsecp256k1zkp_v0_10_0_gej_eq_ge_var(&tmp, &group[(i * x + j * y + k) % EXHAUSTIVE_TEST_ORDER])); } } } } } - rustsecp256k1zkp_v0_8_0_scratch_destroy(&ctx->error_callback, scratch); + rustsecp256k1zkp_v0_10_0_scratch_destroy(&ctx->error_callback, scratch); } -void r_from_k(rustsecp256k1zkp_v0_8_0_scalar *r, const rustsecp256k1zkp_v0_8_0_ge *group, int k, int* overflow) { - rustsecp256k1zkp_v0_8_0_fe x; +static void r_from_k(rustsecp256k1zkp_v0_10_0_scalar *r, const rustsecp256k1zkp_v0_10_0_ge *group, int k, int* overflow) { + rustsecp256k1zkp_v0_10_0_fe x; unsigned char x_bin[32]; k %= EXHAUSTIVE_TEST_ORDER; x = group[k].x; - rustsecp256k1zkp_v0_8_0_fe_normalize(&x); - rustsecp256k1zkp_v0_8_0_fe_get_b32(x_bin, &x); - rustsecp256k1zkp_v0_8_0_scalar_set_b32(r, x_bin, overflow); + rustsecp256k1zkp_v0_10_0_fe_normalize(&x); + rustsecp256k1zkp_v0_10_0_fe_get_b32(x_bin, &x); + rustsecp256k1zkp_v0_10_0_scalar_set_b32(r, x_bin, overflow); } -void test_exhaustive_verify(const rustsecp256k1zkp_v0_8_0_context *ctx, const rustsecp256k1zkp_v0_8_0_ge *group) { +static void test_exhaustive_verify(const rustsecp256k1zkp_v0_10_0_context *ctx, const rustsecp256k1zkp_v0_10_0_ge *group) { int s, r, msg, key; uint64_t iter = 0; for (s = 1; s < EXHAUSTIVE_TEST_ORDER; s++) { for (r = 1; r < EXHAUSTIVE_TEST_ORDER; r++) { for (msg = 1; msg < EXHAUSTIVE_TEST_ORDER; msg++) { for (key = 1; key < EXHAUSTIVE_TEST_ORDER; key++) { - rustsecp256k1zkp_v0_8_0_ge nonconst_ge; - rustsecp256k1zkp_v0_8_0_ecdsa_signature sig; - rustsecp256k1zkp_v0_8_0_pubkey pk; - rustsecp256k1zkp_v0_8_0_scalar sk_s, msg_s, r_s, s_s; - rustsecp256k1zkp_v0_8_0_scalar s_times_k_s, msg_plus_r_times_sk_s; + rustsecp256k1zkp_v0_10_0_ge nonconst_ge; + rustsecp256k1zkp_v0_10_0_ecdsa_signature sig; + rustsecp256k1zkp_v0_10_0_pubkey pk; + rustsecp256k1zkp_v0_10_0_scalar sk_s, msg_s, r_s, s_s; + rustsecp256k1zkp_v0_10_0_scalar s_times_k_s, msg_plus_r_times_sk_s; int k, should_verify; unsigned char msg32[32]; if (skip_section(&iter)) continue; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&s_s, s); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&r_s, r); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&msg_s, msg); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&sk_s, key); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&s_s, s); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&r_s, r); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&msg_s, msg); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&sk_s, key); /* Verify by hand */ /* Run through every k value that gives us this r and check that *one* works. * Note there could be none, there could be multiple, ECDSA is weird. */ should_verify = 0; for (k = 0; k < EXHAUSTIVE_TEST_ORDER; k++) { - rustsecp256k1zkp_v0_8_0_scalar check_x_s; + rustsecp256k1zkp_v0_10_0_scalar check_x_s; r_from_k(&check_x_s, group, k, NULL); if (r_s == check_x_s) { - rustsecp256k1zkp_v0_8_0_scalar_set_int(&s_times_k_s, k); - rustsecp256k1zkp_v0_8_0_scalar_mul(&s_times_k_s, &s_times_k_s, &s_s); - rustsecp256k1zkp_v0_8_0_scalar_mul(&msg_plus_r_times_sk_s, &r_s, &sk_s); - rustsecp256k1zkp_v0_8_0_scalar_add(&msg_plus_r_times_sk_s, &msg_plus_r_times_sk_s, &msg_s); - should_verify |= rustsecp256k1zkp_v0_8_0_scalar_eq(&s_times_k_s, &msg_plus_r_times_sk_s); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&s_times_k_s, k); + rustsecp256k1zkp_v0_10_0_scalar_mul(&s_times_k_s, &s_times_k_s, &s_s); + rustsecp256k1zkp_v0_10_0_scalar_mul(&msg_plus_r_times_sk_s, &r_s, &sk_s); + rustsecp256k1zkp_v0_10_0_scalar_add(&msg_plus_r_times_sk_s, &msg_plus_r_times_sk_s, &msg_s); + should_verify |= rustsecp256k1zkp_v0_10_0_scalar_eq(&s_times_k_s, &msg_plus_r_times_sk_s); } } /* nb we have a "high s" rule */ - should_verify &= !rustsecp256k1zkp_v0_8_0_scalar_is_high(&s_s); + should_verify &= !rustsecp256k1zkp_v0_10_0_scalar_is_high(&s_s); /* Verify by calling verify */ - rustsecp256k1zkp_v0_8_0_ecdsa_signature_save(&sig, &r_s, &s_s); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_save(&sig, &r_s, &s_s); memcpy(&nonconst_ge, &group[sk_s], sizeof(nonconst_ge)); - rustsecp256k1zkp_v0_8_0_pubkey_save(&pk, &nonconst_ge); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(msg32, &msg_s); + rustsecp256k1zkp_v0_10_0_pubkey_save(&pk, &nonconst_ge); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(msg32, &msg_s); CHECK(should_verify == - rustsecp256k1zkp_v0_8_0_ecdsa_verify(ctx, &sig, msg32, &pk)); + rustsecp256k1zkp_v0_10_0_ecdsa_verify(ctx, &sig, msg32, &pk)); } } } } } -void test_exhaustive_sign(const rustsecp256k1zkp_v0_8_0_context *ctx, const rustsecp256k1zkp_v0_8_0_ge *group) { +static void test_exhaustive_sign(const rustsecp256k1zkp_v0_10_0_context *ctx, const rustsecp256k1zkp_v0_10_0_ge *group) { int i, j, k; uint64_t iter = 0; @@ -303,18 +297,18 @@ void test_exhaustive_sign(const rustsecp256k1zkp_v0_8_0_context *ctx, const rust for (k = 1; k < EXHAUSTIVE_TEST_ORDER; k++) { /* nonce */ const int starting_k = k; int ret; - rustsecp256k1zkp_v0_8_0_ecdsa_signature sig; - rustsecp256k1zkp_v0_8_0_scalar sk, msg, r, s, expected_r; + rustsecp256k1zkp_v0_10_0_ecdsa_signature sig; + rustsecp256k1zkp_v0_10_0_scalar sk, msg, r, s, expected_r; unsigned char sk32[32], msg32[32]; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&msg, i); - rustsecp256k1zkp_v0_8_0_scalar_set_int(&sk, j); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(sk32, &sk); - rustsecp256k1zkp_v0_8_0_scalar_get_b32(msg32, &msg); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&msg, i); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&sk, j); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(sk32, &sk); + rustsecp256k1zkp_v0_10_0_scalar_get_b32(msg32, &msg); - ret = rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &sig, msg32, sk32, rustsecp256k1zkp_v0_8_0_nonce_function_smallint, &k); + ret = rustsecp256k1zkp_v0_10_0_ecdsa_sign(ctx, &sig, msg32, sk32, rustsecp256k1zkp_v0_10_0_nonce_function_smallint, &k); CHECK(ret == 1); - rustsecp256k1zkp_v0_8_0_ecdsa_signature_load(ctx, &r, &s, &sig); + rustsecp256k1zkp_v0_10_0_ecdsa_signature_load(ctx, &r, &s, &sig); /* Note that we compute expected_r *after* signing -- this is important * because our nonce-computing function function might change k during * signing. */ @@ -342,23 +336,27 @@ void test_exhaustive_sign(const rustsecp256k1zkp_v0_8_0_context *ctx, const rust } #ifdef ENABLE_MODULE_RECOVERY -#include "src/modules/recovery/tests_exhaustive_impl.h" +#include "modules/recovery/tests_exhaustive_impl.h" #endif #ifdef ENABLE_MODULE_EXTRAKEYS -#include "src/modules/extrakeys/tests_exhaustive_impl.h" +#include "modules/extrakeys/tests_exhaustive_impl.h" #endif #ifdef ENABLE_MODULE_SCHNORRSIG -#include "src/modules/schnorrsig/tests_exhaustive_impl.h" +#include "modules/schnorrsig/tests_exhaustive_impl.h" +#endif + +#ifdef ENABLE_MODULE_ELLSWIFT +#include "modules/ellswift/tests_exhaustive_impl.h" #endif int main(int argc, char** argv) { int i; - rustsecp256k1zkp_v0_8_0_gej groupj[EXHAUSTIVE_TEST_ORDER]; - rustsecp256k1zkp_v0_8_0_ge group[EXHAUSTIVE_TEST_ORDER]; + rustsecp256k1zkp_v0_10_0_gej groupj[EXHAUSTIVE_TEST_ORDER]; + rustsecp256k1zkp_v0_10_0_ge group[EXHAUSTIVE_TEST_ORDER]; unsigned char rand32[32]; - rustsecp256k1zkp_v0_8_0_context *ctx; + rustsecp256k1zkp_v0_10_0_context *ctx; /* Disable buffering for stdout to improve reliability of getting * diagnostic information. Happens right at the start of main because @@ -377,7 +375,7 @@ int main(int argc, char** argv) { printf("test count = %i\n", count); /* find random seed */ - rustsecp256k1zkp_v0_8_0_testrand_init(argc > 2 ? argv[2] : NULL); + rustsecp256k1zkp_v0_10_0_testrand_init(argc > 2 ? argv[2] : NULL); /* set up split processing */ if (argc > 4) { @@ -391,43 +389,43 @@ int main(int argc, char** argv) { } /* Recreate the ecmult{,_gen} tables using the right generator (as selected via EXHAUSTIVE_TEST_ORDER) */ - rustsecp256k1zkp_v0_8_0_ecmult_gen_compute_table(&rustsecp256k1zkp_v0_8_0_ecmult_gen_prec_table[0][0], &rustsecp256k1zkp_v0_8_0_ge_const_g, ECMULT_GEN_PREC_BITS); - rustsecp256k1zkp_v0_8_0_ecmult_compute_two_tables(rustsecp256k1zkp_v0_8_0_pre_g, rustsecp256k1zkp_v0_8_0_pre_g_128, WINDOW_G, &rustsecp256k1zkp_v0_8_0_ge_const_g); + rustsecp256k1zkp_v0_10_0_ecmult_gen_compute_table(&rustsecp256k1zkp_v0_10_0_ecmult_gen_prec_table[0][0], &rustsecp256k1zkp_v0_10_0_ge_const_g, ECMULT_GEN_PREC_BITS); + rustsecp256k1zkp_v0_10_0_ecmult_compute_two_tables(rustsecp256k1zkp_v0_10_0_pre_g, rustsecp256k1zkp_v0_10_0_pre_g_128, WINDOW_G, &rustsecp256k1zkp_v0_10_0_ge_const_g); while (count--) { /* Build context */ - ctx = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); - rustsecp256k1zkp_v0_8_0_testrand256(rand32); - CHECK(rustsecp256k1zkp_v0_8_0_context_randomize(ctx, rand32)); + ctx = rustsecp256k1zkp_v0_10_0_context_create(SECP256K1_CONTEXT_NONE); + rustsecp256k1zkp_v0_10_0_testrand256(rand32); + CHECK(rustsecp256k1zkp_v0_10_0_context_randomize(ctx, rand32)); /* Generate the entire group */ - rustsecp256k1zkp_v0_8_0_gej_set_infinity(&groupj[0]); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&group[0], &groupj[0]); + rustsecp256k1zkp_v0_10_0_gej_set_infinity(&groupj[0]); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&group[0], &groupj[0]); for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) { - rustsecp256k1zkp_v0_8_0_gej_add_ge(&groupj[i], &groupj[i - 1], &rustsecp256k1zkp_v0_8_0_ge_const_g); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&group[i], &groupj[i]); + rustsecp256k1zkp_v0_10_0_gej_add_ge(&groupj[i], &groupj[i - 1], &rustsecp256k1zkp_v0_10_0_ge_const_g); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&group[i], &groupj[i]); if (count != 0) { /* Set a different random z-value for each Jacobian point, except z=1 is used in the last iteration. */ - rustsecp256k1zkp_v0_8_0_fe z; + rustsecp256k1zkp_v0_10_0_fe z; random_fe(&z); - rustsecp256k1zkp_v0_8_0_gej_rescale(&groupj[i], &z); + rustsecp256k1zkp_v0_10_0_gej_rescale(&groupj[i], &z); } /* Verify against ecmult_gen */ { - rustsecp256k1zkp_v0_8_0_scalar scalar_i; - rustsecp256k1zkp_v0_8_0_gej generatedj; - rustsecp256k1zkp_v0_8_0_ge generated; + rustsecp256k1zkp_v0_10_0_scalar scalar_i; + rustsecp256k1zkp_v0_10_0_gej generatedj; + rustsecp256k1zkp_v0_10_0_ge generated; - rustsecp256k1zkp_v0_8_0_scalar_set_int(&scalar_i, i); - rustsecp256k1zkp_v0_8_0_ecmult_gen(&ctx->ecmult_gen_ctx, &generatedj, &scalar_i); - rustsecp256k1zkp_v0_8_0_ge_set_gej(&generated, &generatedj); + rustsecp256k1zkp_v0_10_0_scalar_set_int(&scalar_i, i); + rustsecp256k1zkp_v0_10_0_ecmult_gen(&ctx->ecmult_gen_ctx, &generatedj, &scalar_i); + rustsecp256k1zkp_v0_10_0_ge_set_gej(&generated, &generatedj); CHECK(group[i].infinity == 0); CHECK(generated.infinity == 0); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&generated.x, &group[i].x)); - CHECK(rustsecp256k1zkp_v0_8_0_fe_equal_var(&generated.y, &group[i].y)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&generated.x, &group[i].x)); + CHECK(rustsecp256k1zkp_v0_10_0_fe_equal(&generated.y, &group[i].y)); } } @@ -448,11 +446,20 @@ int main(int argc, char** argv) { #ifdef ENABLE_MODULE_SCHNORRSIG test_exhaustive_schnorrsig(ctx); #endif +#ifdef ENABLE_MODULE_ELLSWIFT + /* The ellswift algorithm does have additional edge cases when operating on + * curves of even order, which are not included in the code as secp256k1 is + * of odd order. Skip the ellswift tests if the used exhaustive tests curve + * is even-ordered accordingly. */ + #if !EXHAUSTIVE_TEST_CURVE_HAS_EVEN_ORDER + test_exhaustive_ellswift(ctx, group); + #endif +#endif - rustsecp256k1zkp_v0_8_0_context_destroy(ctx); + rustsecp256k1zkp_v0_10_0_context_destroy(ctx); } - rustsecp256k1zkp_v0_8_0_testrand_finish(); + rustsecp256k1zkp_v0_10_0_testrand_finish(); printf("no problems found\n"); return 0; diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/testutil.h b/secp256k1-zkp-sys/depend/secp256k1/src/testutil.h new file mode 100644 index 00000000..a967f747 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/testutil.h @@ -0,0 +1,29 @@ +/*********************************************************************** + * Distributed under the MIT software license, see the accompanying * + * file COPYING or https://www.opensource.org/licenses/mit-license.php.* + ***********************************************************************/ + +#ifndef SECP256K1_TESTUTIL_H +#define SECP256K1_TESTUTIL_H + +#include "field.h" +#include "testrand.h" +#include "util.h" + +static void random_fe(rustsecp256k1zkp_v0_10_0_fe *x) { + unsigned char bin[32]; + do { + rustsecp256k1zkp_v0_10_0_testrand256(bin); + if (rustsecp256k1zkp_v0_10_0_fe_set_b32_limit(x, bin)) { + return; + } + } while(1); +} + +static void random_fe_non_zero(rustsecp256k1zkp_v0_10_0_fe *nz) { + do { + random_fe(nz); + } while (rustsecp256k1zkp_v0_10_0_fe_is_zero(nz)); +} + +#endif /* SECP256K1_TESTUTIL_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/util.h b/secp256k1-zkp-sys/depend/secp256k1/src/util.h index e1d1ba7e..bb2656e3 100644 --- a/secp256k1-zkp-sys/depend/secp256k1/src/util.h +++ b/secp256k1-zkp-sys/depend/secp256k1/src/util.h @@ -7,47 +7,109 @@ #ifndef SECP256K1_UTIL_H #define SECP256K1_UTIL_H -#if defined HAVE_CONFIG_H -#include "libsecp256k1-config.h" -#endif +#include "../include/secp256k1.h" #include #include #include #include +#define STR_(x) #x +#define STR(x) STR_(x) +#define DEBUG_CONFIG_MSG(x) "DEBUG_CONFIG: " x +#define DEBUG_CONFIG_DEF(x) DEBUG_CONFIG_MSG(#x "=" STR(x)) + +/* Debug helper for printing arrays of unsigned char. */ +#define PRINT_BUF(buf, len) do { \ + printf("%s[%lu] = ", #buf, (unsigned long)len); \ + print_buf_plain(buf, len); \ +} while(0) + +static void print_buf_plain(const unsigned char *buf, size_t len) { + size_t i; + printf("{"); + for (i = 0; i < len; i++) { + if (i % 8 == 0) { + printf("\n "); + } else { + printf(" "); + } + printf("0x%02X,", buf[i]); + } + printf("\n}\n"); +} + +# if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) ) +# if SECP256K1_GNUC_PREREQ(2,7) +# define SECP256K1_INLINE __inline__ +# elif (defined(_MSC_VER)) +# define SECP256K1_INLINE __inline +# else +# define SECP256K1_INLINE +# endif +# else +# define SECP256K1_INLINE inline +# endif + +/** Assert statically that expr is true. + * + * This is a statement-like macro and can only be used inside functions. + */ +#define STATIC_ASSERT(expr) do { \ + switch(0) { \ + case 0: \ + /* If expr evaluates to 0, we have two case labels "0", which is illegal. */ \ + case /* ERROR: static assertion failed */ (expr): \ + ; \ + } \ +} while(0) + +/** Assert statically that expr is an integer constant expression, and run stmt. + * + * Useful for example to enforce that magnitude arguments are constant. + */ +#define ASSERT_INT_CONST_AND_DO(expr, stmt) do { \ + switch(42) { \ + /* C allows only integer constant expressions as case labels. */ \ + case /* ERROR: integer argument is not constant */ (expr): \ + break; \ + default: ; \ + } \ + stmt; \ +} while(0) + typedef struct { void (*fn)(const char *text, void* data); const void* data; -} rustsecp256k1zkp_v0_8_0_callback; +} rustsecp256k1zkp_v0_10_0_callback; -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_callback_call(const rustsecp256k1zkp_v0_8_0_callback * const cb, const char * const text) { +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_callback_call(const rustsecp256k1zkp_v0_10_0_callback * const cb, const char * const text) { cb->fn(text, (void*)cb->data); } #ifndef USE_EXTERNAL_DEFAULT_CALLBACKS -static void rustsecp256k1zkp_v0_8_0_default_illegal_callback_fn(const char* str, void* data) { +static void rustsecp256k1zkp_v0_10_0_default_illegal_callback_fn(const char* str, void* data) { (void)data; fprintf(stderr, "[libsecp256k1] illegal argument: %s\n", str); abort(); } -static void rustsecp256k1zkp_v0_8_0_default_error_callback_fn(const char* str, void* data) { +static void rustsecp256k1zkp_v0_10_0_default_error_callback_fn(const char* str, void* data) { (void)data; fprintf(stderr, "[libsecp256k1] internal consistency check failed: %s\n", str); abort(); } #else -void rustsecp256k1zkp_v0_8_0_default_illegal_callback_fn(const char* str, void* data); -void rustsecp256k1zkp_v0_8_0_default_error_callback_fn(const char* str, void* data); +void rustsecp256k1zkp_v0_10_0_default_illegal_callback_fn(const char* str, void* data); +void rustsecp256k1zkp_v0_10_0_default_error_callback_fn(const char* str, void* data); #endif -static const rustsecp256k1zkp_v0_8_0_callback default_illegal_callback = { - rustsecp256k1zkp_v0_8_0_default_illegal_callback_fn, +static const rustsecp256k1zkp_v0_10_0_callback default_illegal_callback = { + rustsecp256k1zkp_v0_10_0_default_illegal_callback_fn, NULL }; -static const rustsecp256k1zkp_v0_8_0_callback default_error_callback = { - rustsecp256k1zkp_v0_8_0_default_error_callback_fn, +static const rustsecp256k1zkp_v0_10_0_callback default_error_callback = { + rustsecp256k1zkp_v0_10_0_default_error_callback_fn, NULL }; @@ -84,35 +146,11 @@ static const rustsecp256k1zkp_v0_8_0_callback default_error_callback = { } while(0) #endif -/* Like assert(), but when VERIFY is defined, and side-effect safe. */ -#if defined(COVERAGE) -#define VERIFY_CHECK(check) -#define VERIFY_SETUP(stmt) -#elif defined(VERIFY) -#define VERIFY_CHECK CHECK -#define VERIFY_SETUP(stmt) do { stmt; } while(0) -#else -#define VERIFY_CHECK(cond) do { (void)(cond); } while(0) -#define VERIFY_SETUP(stmt) -#endif - -/* Define `VG_UNDEF` and `VG_CHECK` when VALGRIND is defined */ -#if !defined(VG_CHECK) -# if defined(VALGRIND) -# include -# define VG_UNDEF(x,y) VALGRIND_MAKE_MEM_UNDEFINED((x),(y)) -# define VG_CHECK(x,y) VALGRIND_CHECK_MEM_IS_DEFINED((x),(y)) -# else -# define VG_UNDEF(x,y) -# define VG_CHECK(x,y) -# endif -#endif - -/* Like `VG_CHECK` but on VERIFY only */ +/* Like assert(), but when VERIFY is defined. */ #if defined(VERIFY) -#define VG_CHECK_VERIFY(x,y) VG_CHECK((x), (y)) +#define VERIFY_CHECK CHECK #else -#define VG_CHECK_VERIFY(x,y) +#define VERIFY_CHECK(cond) #endif #if defined(__BIGGEST_ALIGNMENT__) @@ -127,7 +165,7 @@ static const rustsecp256k1zkp_v0_8_0_callback default_error_callback = { #define ROUND_TO_ALIGN(size) ((((size) + ALIGNMENT - 1) / ALIGNMENT) * ALIGNMENT) /* Extract the sign of an int64, take the abs and return a uint64, constant time. */ -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_sign_and_abs64(uint64_t *out, int64_t in) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_sign_and_abs64(uint64_t *out, int64_t in) { uint64_t mask0, mask1; int ret; ret = in < 0; @@ -138,7 +176,7 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_sign_and_abs64(uint64_t *out return ret; } -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_clz64_var(uint64_t x) { +SECP256K1_INLINE static int rustsecp256k1zkp_v0_10_0_clz64_var(uint64_t x) { int ret; if (!x) { return 64; @@ -183,33 +221,8 @@ SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_clz64_var(uint64_t x) { # define SECP256K1_GNUC_EXT #endif -/* If SECP256K1_{LITTLE,BIG}_ENDIAN is not explicitly provided, infer from various other system macros. */ -#if !defined(SECP256K1_LITTLE_ENDIAN) && !defined(SECP256K1_BIG_ENDIAN) -/* Inspired by https://github.com/rofl0r/endianness.h/blob/9853923246b065a3b52d2c43835f3819a62c7199/endianness.h#L52L73 */ -# if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \ - defined(_X86_) || defined(__x86_64__) || defined(__i386__) || \ - defined(__i486__) || defined(__i586__) || defined(__i686__) || \ - defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) || \ - defined(__ARMEL__) || defined(__AARCH64EL__) || \ - (defined(__LITTLE_ENDIAN__) && __LITTLE_ENDIAN__ == 1) || \ - (defined(_LITTLE_ENDIAN) && _LITTLE_ENDIAN == 1) || \ - defined(_M_IX86) || defined(_M_AMD64) || defined(_M_ARM) /* MSVC */ -# define SECP256K1_LITTLE_ENDIAN -# endif -# if (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) || \ - defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) || \ - defined(__MICROBLAZEEB__) || defined(__ARMEB__) || defined(__AARCH64EB__) || \ - (defined(__BIG_ENDIAN__) && __BIG_ENDIAN__ == 1) || \ - (defined(_BIG_ENDIAN) && _BIG_ENDIAN == 1) -# define SECP256K1_BIG_ENDIAN -# endif -#endif -#if defined(SECP256K1_LITTLE_ENDIAN) == defined(SECP256K1_BIG_ENDIAN) -# error Please make sure that either SECP256K1_LITTLE_ENDIAN or SECP256K1_BIG_ENDIAN is set, see src/util.h. -#endif - /* Zero memory if flag == 1. Flag must be 0 or 1. Constant time. */ -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_memczero(void *s, size_t len, int flag) { +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_memczero(void *s, size_t len, int flag) { unsigned char *p = (unsigned char *)s; /* Access flag with a volatile-qualified lvalue. This prevents clang from figuring out (after inlining) that flag can @@ -228,7 +241,7 @@ static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_memczero(void *s, size_t le * We use this to avoid possible compiler bugs with memcmp, e.g. * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95189 */ -static SECP256K1_INLINE int rustsecp256k1zkp_v0_8_0_memcmp_var(const void *s1, const void *s2, size_t n) { +static SECP256K1_INLINE int rustsecp256k1zkp_v0_10_0_memcmp_var(const void *s1, const void *s2, size_t n) { const unsigned char *p1 = s1, *p2 = s2; size_t i; @@ -242,7 +255,7 @@ static SECP256K1_INLINE int rustsecp256k1zkp_v0_8_0_memcmp_var(const void *s1, c } /** If flag is true, set *r equal to *a; otherwise leave it. Constant-time. Both *r and *a must be initialized and non-negative.*/ -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_int_cmov(int *r, const int *a, int flag) { +static SECP256K1_INLINE void rustsecp256k1zkp_v0_10_0_int_cmov(int *r, const int *a, int flag) { unsigned int mask0, mask1, r_masked, a_masked; /* Access flag with a volatile-qualified lvalue. This prevents clang from figuring out (after inlining) that flag can @@ -260,28 +273,36 @@ static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_int_cmov(int *r, const int *r = (int)(r_masked | a_masked); } -/* If USE_FORCE_WIDEMUL_{INT128,INT64} is set, use that wide multiplication implementation. - * Otherwise use the presence of __SIZEOF_INT128__ to decide. - */ -#if defined(USE_FORCE_WIDEMUL_INT128) +#if defined(USE_FORCE_WIDEMUL_INT128_STRUCT) +/* If USE_FORCE_WIDEMUL_INT128_STRUCT is set, use int128_struct. */ # define SECP256K1_WIDEMUL_INT128 1 +# define SECP256K1_INT128_STRUCT 1 +#elif defined(USE_FORCE_WIDEMUL_INT128) +/* If USE_FORCE_WIDEMUL_INT128 is set, use int128. */ +# define SECP256K1_WIDEMUL_INT128 1 +# define SECP256K1_INT128_NATIVE 1 #elif defined(USE_FORCE_WIDEMUL_INT64) +/* If USE_FORCE_WIDEMUL_INT64 is set, use int64. */ # define SECP256K1_WIDEMUL_INT64 1 #elif defined(UINT128_MAX) || defined(__SIZEOF_INT128__) +/* If a native 128-bit integer type exists, use int128. */ +# define SECP256K1_WIDEMUL_INT128 1 +# define SECP256K1_INT128_NATIVE 1 +#elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_ARM64)) +/* On 64-bit MSVC targets (x86_64 and arm64), use int128_struct + * (which has special logic to implement using intrinsics on those systems). */ +# define SECP256K1_WIDEMUL_INT128 1 +# define SECP256K1_INT128_STRUCT 1 +#elif SIZE_MAX > 0xffffffff +/* Systems with 64-bit pointers (and thus registers) very likely benefit from + * using 64-bit based arithmetic (even if we need to fall back to 32x32->64 based + * multiplication logic). */ # define SECP256K1_WIDEMUL_INT128 1 +# define SECP256K1_INT128_STRUCT 1 #else +/* Lastly, fall back to int64 based arithmetic. */ # define SECP256K1_WIDEMUL_INT64 1 #endif -#if defined(SECP256K1_WIDEMUL_INT128) -# if !defined(UINT128_MAX) && defined(__SIZEOF_INT128__) -SECP256K1_GNUC_EXT typedef unsigned __int128 uint128_t; -SECP256K1_GNUC_EXT typedef __int128 int128_t; -#define UINT128_MAX ((uint128_t)(-1)) -#define INT128_MAX ((int128_t)(UINT128_MAX >> 1)) -#define INT128_MIN (-INT128_MAX - 1) -/* No (U)INT128_C macros because compilers providing __int128 do not support 128-bit literals. */ -# endif -#endif #ifndef __has_builtin #define __has_builtin(x) 0 @@ -289,31 +310,31 @@ SECP256K1_GNUC_EXT typedef __int128 int128_t; /* Determine the number of trailing zero bits in a (non-zero) 32-bit x. * This function is only intended to be used as fallback for - * rustsecp256k1zkp_v0_8_0_ctz32_var, but permits it to be tested separately. */ -static SECP256K1_INLINE int rustsecp256k1zkp_v0_8_0_ctz32_var_debruijn(uint32_t x) { + * rustsecp256k1zkp_v0_10_0_ctz32_var, but permits it to be tested separately. */ +static SECP256K1_INLINE int rustsecp256k1zkp_v0_10_0_ctz32_var_debruijn(uint32_t x) { static const uint8_t debruijn[32] = { 0x00, 0x01, 0x02, 0x18, 0x03, 0x13, 0x06, 0x19, 0x16, 0x04, 0x14, 0x0A, 0x10, 0x07, 0x0C, 0x1A, 0x1F, 0x17, 0x12, 0x05, 0x15, 0x09, 0x0F, 0x0B, 0x1E, 0x11, 0x08, 0x0E, 0x1D, 0x0D, 0x1C, 0x1B }; - return debruijn[((x & -x) * 0x04D7651F) >> 27]; + return debruijn[(uint32_t)((x & -x) * 0x04D7651FU) >> 27]; } /* Determine the number of trailing zero bits in a (non-zero) 64-bit x. * This function is only intended to be used as fallback for - * rustsecp256k1zkp_v0_8_0_ctz64_var, but permits it to be tested separately. */ -static SECP256K1_INLINE int rustsecp256k1zkp_v0_8_0_ctz64_var_debruijn(uint64_t x) { + * rustsecp256k1zkp_v0_10_0_ctz64_var, but permits it to be tested separately. */ +static SECP256K1_INLINE int rustsecp256k1zkp_v0_10_0_ctz64_var_debruijn(uint64_t x) { static const uint8_t debruijn[64] = { 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28, 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11, 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10, 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12 }; - return debruijn[((x & -x) * 0x022FDD63CC95386D) >> 58]; + return debruijn[(uint64_t)((x & -x) * 0x022FDD63CC95386DU) >> 58]; } /* Determine the number of trailing zero bits in a (non-zero) 32-bit x. */ -static SECP256K1_INLINE int rustsecp256k1zkp_v0_8_0_ctz32_var(uint32_t x) { +static SECP256K1_INLINE int rustsecp256k1zkp_v0_10_0_ctz32_var(uint32_t x) { VERIFY_CHECK(x != 0); #if (__has_builtin(__builtin_ctz) || SECP256K1_GNUC_PREREQ(3,4)) /* If the unsigned type is sufficient to represent the largest uint32_t, consider __builtin_ctz. */ @@ -326,12 +347,12 @@ static SECP256K1_INLINE int rustsecp256k1zkp_v0_8_0_ctz32_var(uint32_t x) { return __builtin_ctzl(x); #else /* If no suitable CTZ builtin is available, use a (variable time) software emulation. */ - return rustsecp256k1zkp_v0_8_0_ctz32_var_debruijn(x); + return rustsecp256k1zkp_v0_10_0_ctz32_var_debruijn(x); #endif } /* Determine the number of trailing zero bits in a (non-zero) 64-bit x. */ -static SECP256K1_INLINE int rustsecp256k1zkp_v0_8_0_ctz64_var(uint64_t x) { +static SECP256K1_INLINE int rustsecp256k1zkp_v0_10_0_ctz64_var(uint64_t x) { VERIFY_CHECK(x != 0); #if (__has_builtin(__builtin_ctzl) || SECP256K1_GNUC_PREREQ(3,4)) /* If the unsigned long type is sufficient to represent the largest uint64_t, consider __builtin_ctzl. */ @@ -344,12 +365,12 @@ static SECP256K1_INLINE int rustsecp256k1zkp_v0_8_0_ctz64_var(uint64_t x) { return __builtin_ctzll(x); #else /* If no suitable CTZ builtin is available, use a (variable time) software emulation. */ - return rustsecp256k1zkp_v0_8_0_ctz64_var_debruijn(x); + return rustsecp256k1zkp_v0_10_0_ctz64_var_debruijn(x); #endif } /* Read a uint32_t in big endian */ -SECP256K1_INLINE static uint32_t rustsecp256k1zkp_v0_8_0_read_be32(const unsigned char* p) { +SECP256K1_INLINE static uint32_t rustsecp256k1zkp_v0_10_0_read_be32(const unsigned char* p) { return (uint32_t)p[0] << 24 | (uint32_t)p[1] << 16 | (uint32_t)p[2] << 8 | @@ -357,11 +378,35 @@ SECP256K1_INLINE static uint32_t rustsecp256k1zkp_v0_8_0_read_be32(const unsigne } /* Write a uint32_t in big endian */ -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_write_be32(unsigned char* p, uint32_t x) { +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_write_be32(unsigned char* p, uint32_t x) { p[3] = x; p[2] = x >> 8; p[1] = x >> 16; p[0] = x >> 24; } +/* Read a uint64_t in big endian */ +SECP256K1_INLINE static uint64_t rustsecp256k1zkp_v0_10_0_read_be64(const unsigned char* p) { + return (uint64_t)p[0] << 56 | + (uint64_t)p[1] << 48 | + (uint64_t)p[2] << 40 | + (uint64_t)p[3] << 32 | + (uint64_t)p[4] << 24 | + (uint64_t)p[5] << 16 | + (uint64_t)p[6] << 8 | + (uint64_t)p[7]; +} + +/* Write a uint64_t in big endian */ +SECP256K1_INLINE static void rustsecp256k1zkp_v0_10_0_write_be64(unsigned char* p, uint64_t x) { + p[7] = x; + p[6] = x >> 8; + p[5] = x >> 16; + p[4] = x >> 24; + p[3] = x >> 32; + p[2] = x >> 40; + p[1] = x >> 48; + p[0] = x >> 56; +} + #endif /* SECP256K1_UTIL_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/util.h.orig b/secp256k1-zkp-sys/depend/secp256k1/src/util.h.orig deleted file mode 100644 index d8f8a954..00000000 --- a/secp256k1-zkp-sys/depend/secp256k1/src/util.h.orig +++ /dev/null @@ -1,383 +0,0 @@ -/*********************************************************************** - * Copyright (c) 2013-2015 Pieter Wuille, Gregory Maxwell * - * Distributed under the MIT software license, see the accompanying * - * file COPYING or https://www.opensource.org/licenses/mit-license.php.* - ***********************************************************************/ - -#ifndef SECP256K1_UTIL_H -#define SECP256K1_UTIL_H - -#if defined HAVE_CONFIG_H -#include "libsecp256k1-config.h" -#endif - -#include -#include -#include -#include - -typedef struct { - void (*fn)(const char *text, void* data); - const void* data; -} rustsecp256k1zkp_v0_8_0_callback; - -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_callback_call(const rustsecp256k1zkp_v0_8_0_callback * const cb, const char * const text) { - cb->fn(text, (void*)cb->data); -} - -#ifndef USE_EXTERNAL_DEFAULT_CALLBACKS -static void rustsecp256k1zkp_v0_8_0_default_illegal_callback_fn(const char* str, void* data) { - (void)data; - fprintf(stderr, "[libsecp256k1] illegal argument: %s\n", str); - abort(); -} -static void rustsecp256k1zkp_v0_8_0_default_error_callback_fn(const char* str, void* data) { - (void)data; - fprintf(stderr, "[libsecp256k1] internal consistency check failed: %s\n", str); - abort(); -} -#else -void rustsecp256k1zkp_v0_8_0_default_illegal_callback_fn(const char* str, void* data); -void rustsecp256k1zkp_v0_8_0_default_error_callback_fn(const char* str, void* data); -#endif - -static const rustsecp256k1zkp_v0_8_0_callback default_illegal_callback = { - rustsecp256k1zkp_v0_8_0_default_illegal_callback_fn, - NULL -}; - -static const rustsecp256k1zkp_v0_8_0_callback default_error_callback = { - rustsecp256k1zkp_v0_8_0_default_error_callback_fn, - NULL -}; - - -#ifdef DETERMINISTIC -#define TEST_FAILURE(msg) do { \ - fprintf(stderr, "%s\n", msg); \ - abort(); \ -} while(0); -#else -#define TEST_FAILURE(msg) do { \ - fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, msg); \ - abort(); \ -} while(0) -#endif - -#if SECP256K1_GNUC_PREREQ(3, 0) -#define EXPECT(x,c) __builtin_expect((x),(c)) -#else -#define EXPECT(x,c) (x) -#endif - -#ifdef DETERMINISTIC -#define CHECK(cond) do { \ - if (EXPECT(!(cond), 0)) { \ - TEST_FAILURE("test condition failed"); \ - } \ -} while(0) -#else -#define CHECK(cond) do { \ - if (EXPECT(!(cond), 0)) { \ - TEST_FAILURE("test condition failed: " #cond); \ - } \ -} while(0) -#endif - -/* Like assert(), but when VERIFY is defined, and side-effect safe. */ -#if defined(COVERAGE) -#define VERIFY_CHECK(check) -#define VERIFY_SETUP(stmt) -#elif defined(VERIFY) -#define VERIFY_CHECK CHECK -#define VERIFY_SETUP(stmt) do { stmt; } while(0) -#else -#define VERIFY_CHECK(cond) do { (void)(cond); } while(0) -#define VERIFY_SETUP(stmt) -#endif - -/* Define `VG_UNDEF` and `VG_CHECK` when VALGRIND is defined */ -#if !defined(VG_CHECK) -# if defined(VALGRIND) -# include -# define VG_UNDEF(x,y) VALGRIND_MAKE_MEM_UNDEFINED((x),(y)) -# define VG_CHECK(x,y) VALGRIND_CHECK_MEM_IS_DEFINED((x),(y)) -# else -# define VG_UNDEF(x,y) -# define VG_CHECK(x,y) -# endif -#endif - -/* Like `VG_CHECK` but on VERIFY only */ -#if defined(VERIFY) -#define VG_CHECK_VERIFY(x,y) VG_CHECK((x), (y)) -#else -#define VG_CHECK_VERIFY(x,y) -#endif - -static SECP256K1_INLINE void *checked_malloc(const rustsecp256k1zkp_v0_8_0_callback* cb, size_t size) { - void *ret = malloc(size); - if (ret == NULL) { - rustsecp256k1zkp_v0_8_0_callback_call(cb, "Out of memory"); - } - return ret; -} - -static SECP256K1_INLINE void *checked_realloc(const rustsecp256k1zkp_v0_8_0_callback* cb, void *ptr, size_t size) { - void *ret = realloc(ptr, size); - if (ret == NULL) { - rustsecp256k1zkp_v0_8_0_callback_call(cb, "Out of memory"); - } - return ret; -} - -#if defined(__BIGGEST_ALIGNMENT__) -#define ALIGNMENT __BIGGEST_ALIGNMENT__ -#else -/* Using 16 bytes alignment because common architectures never have alignment - * requirements above 8 for any of the types we care about. In addition we - * leave some room because currently we don't care about a few bytes. */ -#define ALIGNMENT 16 -#endif - -#define ROUND_TO_ALIGN(size) ((((size) + ALIGNMENT - 1) / ALIGNMENT) * ALIGNMENT) - -/* Extract the sign of an int64, take the abs and return a uint64, constant time. */ -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_sign_and_abs64(uint64_t *out, int64_t in) { - uint64_t mask0, mask1; - int ret; - ret = in < 0; - mask0 = ret + ~((uint64_t)0); - mask1 = ~mask0; - *out = (uint64_t)in; - *out = (*out & mask0) | ((~*out + 1) & mask1); - return ret; -} - -SECP256K1_INLINE static int rustsecp256k1zkp_v0_8_0_clz64_var(uint64_t x) { - int ret; - if (!x) { - return 64; - } -# if defined(HAVE_BUILTIN_CLZLL) - ret = __builtin_clzll(x); -# else - /*FIXME: debruijn fallback. */ - for (ret = 0; ((x & (1ULL << 63)) == 0); x <<= 1, ret++); -# endif - return ret; -} - -/* Macro for restrict, when available and not in a VERIFY build. */ -#if defined(SECP256K1_BUILD) && defined(VERIFY) -# define SECP256K1_RESTRICT -#else -# if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) ) -# if SECP256K1_GNUC_PREREQ(3,0) -# define SECP256K1_RESTRICT __restrict__ -# elif (defined(_MSC_VER) && _MSC_VER >= 1400) -# define SECP256K1_RESTRICT __restrict -# else -# define SECP256K1_RESTRICT -# endif -# else -# define SECP256K1_RESTRICT restrict -# endif -#endif - -#if defined(_WIN32) -# define I64FORMAT "I64d" -# define I64uFORMAT "I64u" -#else -# define I64FORMAT "lld" -# define I64uFORMAT "llu" -#endif - -#if defined(__GNUC__) -# define SECP256K1_GNUC_EXT __extension__ -#else -# define SECP256K1_GNUC_EXT -#endif - -/* If SECP256K1_{LITTLE,BIG}_ENDIAN is not explicitly provided, infer from various other system macros. */ -#if !defined(SECP256K1_LITTLE_ENDIAN) && !defined(SECP256K1_BIG_ENDIAN) -/* Inspired by https://github.com/rofl0r/endianness.h/blob/9853923246b065a3b52d2c43835f3819a62c7199/endianness.h#L52L73 */ -# if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \ - defined(_X86_) || defined(__x86_64__) || defined(__i386__) || \ - defined(__i486__) || defined(__i586__) || defined(__i686__) || \ - defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) || \ - defined(__ARMEL__) || defined(__AARCH64EL__) || \ - (defined(__LITTLE_ENDIAN__) && __LITTLE_ENDIAN__ == 1) || \ - (defined(_LITTLE_ENDIAN) && _LITTLE_ENDIAN == 1) || \ - defined(_M_IX86) || defined(_M_AMD64) || defined(_M_ARM) /* MSVC */ -# define SECP256K1_LITTLE_ENDIAN -# endif -# if (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) || \ - defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) || \ - defined(__MICROBLAZEEB__) || defined(__ARMEB__) || defined(__AARCH64EB__) || \ - (defined(__BIG_ENDIAN__) && __BIG_ENDIAN__ == 1) || \ - (defined(_BIG_ENDIAN) && _BIG_ENDIAN == 1) -# define SECP256K1_BIG_ENDIAN -# endif -#endif -#if defined(SECP256K1_LITTLE_ENDIAN) == defined(SECP256K1_BIG_ENDIAN) -# error Please make sure that either SECP256K1_LITTLE_ENDIAN or SECP256K1_BIG_ENDIAN is set, see src/util.h. -#endif - -/* Zero memory if flag == 1. Flag must be 0 or 1. Constant time. */ -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_memczero(void *s, size_t len, int flag) { - unsigned char *p = (unsigned char *)s; - /* Access flag with a volatile-qualified lvalue. - This prevents clang from figuring out (after inlining) that flag can - take only be 0 or 1, which leads to variable time code. */ - volatile int vflag = flag; - unsigned char mask = -(unsigned char) vflag; - while (len) { - *p &= ~mask; - p++; - len--; - } -} - -/** Semantics like memcmp. Variable-time. - * - * We use this to avoid possible compiler bugs with memcmp, e.g. - * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95189 - */ -static SECP256K1_INLINE int rustsecp256k1zkp_v0_8_0_memcmp_var(const void *s1, const void *s2, size_t n) { - const unsigned char *p1 = s1, *p2 = s2; - size_t i; - - for (i = 0; i < n; i++) { - int diff = p1[i] - p2[i]; - if (diff != 0) { - return diff; - } - } - return 0; -} - -/** If flag is true, set *r equal to *a; otherwise leave it. Constant-time. Both *r and *a must be initialized and non-negative.*/ -static SECP256K1_INLINE void rustsecp256k1zkp_v0_8_0_int_cmov(int *r, const int *a, int flag) { - unsigned int mask0, mask1, r_masked, a_masked; - /* Access flag with a volatile-qualified lvalue. - This prevents clang from figuring out (after inlining) that flag can - take only be 0 or 1, which leads to variable time code. */ - volatile int vflag = flag; - - /* Casting a negative int to unsigned and back to int is implementation defined behavior */ - VERIFY_CHECK(*r >= 0 && *a >= 0); - - mask0 = (unsigned int)vflag + ~0u; - mask1 = ~mask0; - r_masked = ((unsigned int)*r & mask0); - a_masked = ((unsigned int)*a & mask1); - - *r = (int)(r_masked | a_masked); -} - -/* If USE_FORCE_WIDEMUL_{INT128,INT64} is set, use that wide multiplication implementation. - * Otherwise use the presence of __SIZEOF_INT128__ to decide. - */ -#if defined(USE_FORCE_WIDEMUL_INT128) -# define SECP256K1_WIDEMUL_INT128 1 -#elif defined(USE_FORCE_WIDEMUL_INT64) -# define SECP256K1_WIDEMUL_INT64 1 -#elif defined(UINT128_MAX) || defined(__SIZEOF_INT128__) -# define SECP256K1_WIDEMUL_INT128 1 -#else -# define SECP256K1_WIDEMUL_INT64 1 -#endif -#if defined(SECP256K1_WIDEMUL_INT128) -# if !defined(UINT128_MAX) && defined(__SIZEOF_INT128__) -SECP256K1_GNUC_EXT typedef unsigned __int128 uint128_t; -SECP256K1_GNUC_EXT typedef __int128 int128_t; -#define UINT128_MAX ((uint128_t)(-1)) -#define INT128_MAX ((int128_t)(UINT128_MAX >> 1)) -#define INT128_MIN (-INT128_MAX - 1) -/* No (U)INT128_C macros because compilers providing __int128 do not support 128-bit literals. */ -# endif -#endif - -#ifndef __has_builtin -#define __has_builtin(x) 0 -#endif - -/* Determine the number of trailing zero bits in a (non-zero) 32-bit x. - * This function is only intended to be used as fallback for - * rustsecp256k1zkp_v0_8_0_ctz32_var, but permits it to be tested separately. */ -static SECP256K1_INLINE int rustsecp256k1zkp_v0_8_0_ctz32_var_debruijn(uint32_t x) { - static const uint8_t debruijn[32] = { - 0x00, 0x01, 0x02, 0x18, 0x03, 0x13, 0x06, 0x19, 0x16, 0x04, 0x14, 0x0A, - 0x10, 0x07, 0x0C, 0x1A, 0x1F, 0x17, 0x12, 0x05, 0x15, 0x09, 0x0F, 0x0B, - 0x1E, 0x11, 0x08, 0x0E, 0x1D, 0x0D, 0x1C, 0x1B - }; - return debruijn[((x & -x) * 0x04D7651F) >> 27]; -} - -/* Determine the number of trailing zero bits in a (non-zero) 64-bit x. - * This function is only intended to be used as fallback for - * rustsecp256k1zkp_v0_8_0_ctz64_var, but permits it to be tested separately. */ -static SECP256K1_INLINE int rustsecp256k1zkp_v0_8_0_ctz64_var_debruijn(uint64_t x) { - static const uint8_t debruijn[64] = { - 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28, - 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11, - 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10, - 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12 - }; - return debruijn[((x & -x) * 0x022FDD63CC95386D) >> 58]; -} - -/* Determine the number of trailing zero bits in a (non-zero) 32-bit x. */ -static SECP256K1_INLINE int rustsecp256k1zkp_v0_8_0_ctz32_var(uint32_t x) { - VERIFY_CHECK(x != 0); -#if (__has_builtin(__builtin_ctz) || SECP256K1_GNUC_PREREQ(3,4)) - /* If the unsigned type is sufficient to represent the largest uint32_t, consider __builtin_ctz. */ - if (((unsigned)UINT32_MAX) == UINT32_MAX) { - return __builtin_ctz(x); - } -#endif -#if (__has_builtin(__builtin_ctzl) || SECP256K1_GNUC_PREREQ(3,4)) - /* Otherwise consider __builtin_ctzl (the unsigned long type is always at least 32 bits). */ - return __builtin_ctzl(x); -#else - /* If no suitable CTZ builtin is available, use a (variable time) software emulation. */ - return rustsecp256k1zkp_v0_8_0_ctz32_var_debruijn(x); -#endif -} - -/* Determine the number of trailing zero bits in a (non-zero) 64-bit x. */ -static SECP256K1_INLINE int rustsecp256k1zkp_v0_8_0_ctz64_var(uint64_t x) { - VERIFY_CHECK(x != 0); -#if (__has_builtin(__builtin_ctzl) || SECP256K1_GNUC_PREREQ(3,4)) - /* If the unsigned long type is sufficient to represent the largest uint64_t, consider __builtin_ctzl. */ - if (((unsigned long)UINT64_MAX) == UINT64_MAX) { - return __builtin_ctzl(x); - } -#endif -#if (__has_builtin(__builtin_ctzll) || SECP256K1_GNUC_PREREQ(3,4)) - /* Otherwise consider __builtin_ctzll (the unsigned long long type is always at least 64 bits). */ - return __builtin_ctzll(x); -#else - /* If no suitable CTZ builtin is available, use a (variable time) software emulation. */ - return rustsecp256k1zkp_v0_8_0_ctz64_var_debruijn(x); -#endif -} - -/* Read a uint32_t in big endian */ -SECP256K1_INLINE static uint32_t rustsecp256k1zkp_v0_8_0_read_be32(const unsigned char* p) { - return (uint32_t)p[0] << 24 | - (uint32_t)p[1] << 16 | - (uint32_t)p[2] << 8 | - (uint32_t)p[3]; -} - -/* Write a uint32_t in big endian */ -SECP256K1_INLINE static void rustsecp256k1zkp_v0_8_0_write_be32(unsigned char* p, uint32_t x) { - p[3] = x; - p[2] = x >> 8; - p[1] = x >> 16; - p[0] = x >> 24; -} - -#endif /* SECP256K1_UTIL_H */ diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/valgrind_ctime_test.c b/secp256k1-zkp-sys/depend/secp256k1/src/valgrind_ctime_test.c deleted file mode 100644 index 547f6063..00000000 --- a/secp256k1-zkp-sys/depend/secp256k1/src/valgrind_ctime_test.c +++ /dev/null @@ -1,315 +0,0 @@ -/*********************************************************************** - * Copyright (c) 2020 Gregory Maxwell * - * Distributed under the MIT software license, see the accompanying * - * file COPYING or https://www.opensource.org/licenses/mit-license.php.* - ***********************************************************************/ - -#include -#include -#include - -#include "../include/secp256k1.h" -#include "assumptions.h" -#include "util.h" - -#ifdef ENABLE_MODULE_ECDH -#include "../include/secp256k1_ecdh.h" -#endif - -#ifdef ENABLE_MODULE_RECOVERY -#include "../include/secp256k1_recovery.h" -#endif - -#ifdef ENABLE_MODULE_EXTRAKEYS -#include "../include/secp256k1_extrakeys.h" -#endif - -#ifdef ENABLE_MODULE_SCHNORRSIG -#include "../include/secp256k1_schnorrsig.h" -#endif - -#ifdef ENABLE_MODULE_ECDSA_S2C -#include "include/secp256k1_ecdsa_s2c.h" -#endif - -#ifdef ENABLE_MODULE_ECDSA_ADAPTOR -#include "include/secp256k1_ecdsa_adaptor.h" -#endif - -#ifdef ENABLE_MODULE_MUSIG -#include "include/secp256k1_musig.h" -#endif - -void run_tests(rustsecp256k1zkp_v0_8_0_context *ctx, unsigned char *key); - -int main(void) { - rustsecp256k1zkp_v0_8_0_context* ctx; - unsigned char key[32]; - int ret, i; - - if (!RUNNING_ON_VALGRIND) { - fprintf(stderr, "This test can only usefully be run inside valgrind.\n"); - fprintf(stderr, "Usage: libtool --mode=execute valgrind ./valgrind_ctime_test\n"); - return 1; - } - ctx = rustsecp256k1zkp_v0_8_0_context_create(SECP256K1_CONTEXT_SIGN - | SECP256K1_CONTEXT_VERIFY - | SECP256K1_CONTEXT_DECLASSIFY); - /** In theory, testing with a single secret input should be sufficient: - * If control flow depended on secrets the tool would generate an error. - */ - for (i = 0; i < 32; i++) { - key[i] = i + 65; - } - - run_tests(ctx, key); - - /* Test context randomisation. Do this last because it leaves the context - * tainted. */ - VALGRIND_MAKE_MEM_UNDEFINED(key, 32); - ret = rustsecp256k1zkp_v0_8_0_context_randomize(ctx, key); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret); - - rustsecp256k1zkp_v0_8_0_context_destroy(ctx); - return 0; -} - -void run_tests(rustsecp256k1zkp_v0_8_0_context *ctx, unsigned char *key) { - rustsecp256k1zkp_v0_8_0_ecdsa_signature signature; - rustsecp256k1zkp_v0_8_0_pubkey pubkey; - size_t siglen = 74; - size_t outputlen = 33; - int i; - int ret; - unsigned char msg[32]; - unsigned char sig[74]; - unsigned char spubkey[33]; -#ifdef ENABLE_MODULE_RECOVERY - rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature recoverable_signature; - int recid; -#endif -#ifdef ENABLE_MODULE_EXTRAKEYS - rustsecp256k1zkp_v0_8_0_keypair keypair; -#endif - - for (i = 0; i < 32; i++) { - msg[i] = i + 1; - } - - /* Test keygen. */ - VALGRIND_MAKE_MEM_UNDEFINED(key, 32); - ret = rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &pubkey, key); - VALGRIND_MAKE_MEM_DEFINED(&pubkey, sizeof(rustsecp256k1zkp_v0_8_0_pubkey)); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_serialize(ctx, spubkey, &outputlen, &pubkey, SECP256K1_EC_COMPRESSED) == 1); - - /* Test signing. */ - VALGRIND_MAKE_MEM_UNDEFINED(key, 32); - ret = rustsecp256k1zkp_v0_8_0_ecdsa_sign(ctx, &signature, msg, key, NULL, NULL); - VALGRIND_MAKE_MEM_DEFINED(&signature, sizeof(rustsecp256k1zkp_v0_8_0_ecdsa_signature)); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_signature_serialize_der(ctx, sig, &siglen, &signature)); - -#ifdef ENABLE_MODULE_ECDH - /* Test ECDH. */ - VALGRIND_MAKE_MEM_UNDEFINED(key, 32); - ret = rustsecp256k1zkp_v0_8_0_ecdh(ctx, msg, &pubkey, key, NULL, NULL); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); -#endif - -#ifdef ENABLE_MODULE_RECOVERY - /* Test signing a recoverable signature. */ - VALGRIND_MAKE_MEM_UNDEFINED(key, 32); - ret = rustsecp256k1zkp_v0_8_0_ecdsa_sign_recoverable(ctx, &recoverable_signature, msg, key, NULL, NULL); - VALGRIND_MAKE_MEM_DEFINED(&recoverable_signature, sizeof(recoverable_signature)); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret); - CHECK(rustsecp256k1zkp_v0_8_0_ecdsa_recoverable_signature_serialize_compact(ctx, sig, &recid, &recoverable_signature)); - CHECK(recid >= 0 && recid <= 3); -#endif - - VALGRIND_MAKE_MEM_UNDEFINED(key, 32); - ret = rustsecp256k1zkp_v0_8_0_ec_seckey_verify(ctx, key); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); - - VALGRIND_MAKE_MEM_UNDEFINED(key, 32); - ret = rustsecp256k1zkp_v0_8_0_ec_seckey_negate(ctx, key); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); - - VALGRIND_MAKE_MEM_UNDEFINED(key, 32); - VALGRIND_MAKE_MEM_UNDEFINED(msg, 32); - ret = rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_add(ctx, key, msg); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); - - VALGRIND_MAKE_MEM_UNDEFINED(key, 32); - VALGRIND_MAKE_MEM_UNDEFINED(msg, 32); - ret = rustsecp256k1zkp_v0_8_0_ec_seckey_tweak_mul(ctx, key, msg); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); - - /* Test keypair_create and keypair_xonly_tweak_add. */ -#ifdef ENABLE_MODULE_EXTRAKEYS - VALGRIND_MAKE_MEM_UNDEFINED(key, 32); - ret = rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, key); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); - - /* The tweak is not treated as a secret in keypair_tweak_add */ - VALGRIND_MAKE_MEM_DEFINED(msg, 32); - ret = rustsecp256k1zkp_v0_8_0_keypair_xonly_tweak_add(ctx, &keypair, msg); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); - - VALGRIND_MAKE_MEM_UNDEFINED(key, 32); - VALGRIND_MAKE_MEM_UNDEFINED(&keypair, sizeof(keypair)); - ret = rustsecp256k1zkp_v0_8_0_keypair_sec(ctx, key, &keypair); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); -#endif - -#ifdef ENABLE_MODULE_SCHNORRSIG - VALGRIND_MAKE_MEM_UNDEFINED(key, 32); - ret = rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, key); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); - ret = rustsecp256k1zkp_v0_8_0_schnorrsig_sign32(ctx, sig, msg, &keypair, NULL); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); -#endif - -#ifdef ENABLE_MODULE_ECDSA_S2C - { - unsigned char s2c_data[32] = {0}; - unsigned char s2c_data_comm[32] = {0}; - rustsecp256k1zkp_v0_8_0_ecdsa_s2c_opening s2c_opening; - - VALGRIND_MAKE_MEM_UNDEFINED(key, 32); - VALGRIND_MAKE_MEM_UNDEFINED(s2c_data, 32); - ret = rustsecp256k1zkp_v0_8_0_ecdsa_s2c_sign(ctx, &signature, &s2c_opening, msg, key, s2c_data); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); - - VALGRIND_MAKE_MEM_UNDEFINED(s2c_data, 32); - ret = rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_host_commit(ctx, s2c_data_comm, s2c_data); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); - - VALGRIND_MAKE_MEM_UNDEFINED(key, 32); - VALGRIND_MAKE_MEM_UNDEFINED(s2c_data, 32); - ret = rustsecp256k1zkp_v0_8_0_ecdsa_anti_exfil_signer_commit(ctx, &s2c_opening, msg, key, s2c_data); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); - } -#endif - -#ifdef ENABLE_MODULE_ECDSA_ADAPTOR - { - unsigned char adaptor_sig[162]; - unsigned char deckey[32]; - unsigned char expected_deckey[32]; - rustsecp256k1zkp_v0_8_0_pubkey enckey; - - for (i = 0; i < 32; i++) { - deckey[i] = i + 2; - } - - ret = rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &enckey, deckey); - CHECK(ret == 1); - - VALGRIND_MAKE_MEM_UNDEFINED(key, 32); - ret = rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt(ctx, adaptor_sig, key, &enckey, msg, NULL, NULL); - VALGRIND_MAKE_MEM_DEFINED(adaptor_sig, sizeof(adaptor_sig)); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); - - VALGRIND_MAKE_MEM_UNDEFINED(deckey, 32); - ret = rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_decrypt(ctx, &signature, deckey, adaptor_sig); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); - - VALGRIND_MAKE_MEM_UNDEFINED(&signature, 32); - ret = rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_recover(ctx, expected_deckey, &signature, adaptor_sig, &enckey); - VALGRIND_MAKE_MEM_DEFINED(expected_deckey, sizeof(expected_deckey)); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); - - VALGRIND_MAKE_MEM_DEFINED(deckey, sizeof(deckey)); - ret = rustsecp256k1zkp_v0_8_0_memcmp_var(deckey, expected_deckey, sizeof(expected_deckey)); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 0); - } -#endif - -#ifdef ENABLE_MODULE_MUSIG - { - rustsecp256k1zkp_v0_8_0_pubkey pk; - const rustsecp256k1zkp_v0_8_0_pubkey *pk_ptr[1]; - rustsecp256k1zkp_v0_8_0_xonly_pubkey agg_pk; - unsigned char session_id[32]; - rustsecp256k1zkp_v0_8_0_musig_secnonce secnonce; - rustsecp256k1zkp_v0_8_0_musig_pubnonce pubnonce; - const rustsecp256k1zkp_v0_8_0_musig_pubnonce *pubnonce_ptr[1]; - rustsecp256k1zkp_v0_8_0_musig_aggnonce aggnonce; - rustsecp256k1zkp_v0_8_0_musig_keyagg_cache cache; - rustsecp256k1zkp_v0_8_0_musig_session session; - rustsecp256k1zkp_v0_8_0_musig_partial_sig partial_sig; - const rustsecp256k1zkp_v0_8_0_musig_partial_sig *partial_sig_ptr[1]; - unsigned char extra_input[32]; - unsigned char sec_adaptor[32]; - rustsecp256k1zkp_v0_8_0_pubkey adaptor; - unsigned char pre_sig[64]; - int nonce_parity; - - pk_ptr[0] = &pk; - pubnonce_ptr[0] = &pubnonce; - VALGRIND_MAKE_MEM_DEFINED(key, 32); - memcpy(session_id, key, sizeof(session_id)); - session_id[0] = session_id[0] + 1; - memcpy(extra_input, key, sizeof(extra_input)); - extra_input[0] = extra_input[0] + 2; - memcpy(sec_adaptor, key, sizeof(sec_adaptor)); - sec_adaptor[0] = extra_input[0] + 3; - partial_sig_ptr[0] = &partial_sig; - - CHECK(rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, key)); - CHECK(rustsecp256k1zkp_v0_8_0_keypair_pub(ctx, &pk, &keypair)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_pubkey_agg(ctx, NULL, &agg_pk, &cache, pk_ptr, 1)); - CHECK(rustsecp256k1zkp_v0_8_0_ec_pubkey_create(ctx, &adaptor, sec_adaptor)); - VALGRIND_MAKE_MEM_UNDEFINED(key, 32); - VALGRIND_MAKE_MEM_UNDEFINED(session_id, sizeof(session_id)); - VALGRIND_MAKE_MEM_UNDEFINED(extra_input, sizeof(extra_input)); - VALGRIND_MAKE_MEM_UNDEFINED(sec_adaptor, sizeof(sec_adaptor)); - ret = rustsecp256k1zkp_v0_8_0_musig_nonce_gen(ctx, &secnonce, &pubnonce, session_id, key, &pk, msg, &cache, extra_input); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_agg(ctx, &aggnonce, pubnonce_ptr, 1)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_process(ctx, &session, &aggnonce, msg, &cache, &adaptor) == 1); - - ret = rustsecp256k1zkp_v0_8_0_keypair_create(ctx, &keypair, key); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); - ret = rustsecp256k1zkp_v0_8_0_musig_partial_sign(ctx, &partial_sig, &secnonce, &keypair, &cache, &session); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); - - VALGRIND_MAKE_MEM_DEFINED(&partial_sig, sizeof(partial_sig)); - CHECK(rustsecp256k1zkp_v0_8_0_musig_partial_sig_agg(ctx, pre_sig, &session, partial_sig_ptr, 1)); - VALGRIND_MAKE_MEM_DEFINED(pre_sig, sizeof(pre_sig)); - - CHECK(rustsecp256k1zkp_v0_8_0_musig_nonce_parity(ctx, &nonce_parity, &session)); - ret = rustsecp256k1zkp_v0_8_0_musig_adapt(ctx, sig, pre_sig, sec_adaptor, nonce_parity); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); - ret = rustsecp256k1zkp_v0_8_0_musig_extract_adaptor(ctx, sec_adaptor, sig, pre_sig, nonce_parity); - VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); - CHECK(ret == 1); - } -#endif -} diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/wycheproof/WYCHEPROOF_COPYING b/secp256k1-zkp-sys/depend/secp256k1/src/wycheproof/WYCHEPROOF_COPYING new file mode 100644 index 00000000..5f6a097d --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/wycheproof/WYCHEPROOF_COPYING @@ -0,0 +1,212 @@ +* The file `ecdsa_rustsecp256k1zkp_v0_10_0_sha256_bitcoin_test.json` in this directory + comes from Google's project Wycheproof with git commit + `b063b4aedae951c69df014cd25fa6d69ae9e8cb9`, see + https://github.com/google/wycheproof/blob/b063b4aedae951c69df014cd25fa6d69ae9e8cb9/testvectors_v1/ecdsa_rustsecp256k1zkp_v0_10_0_sha256_bitcoin_test.json + +* The file `ecdsa_rustsecp256k1zkp_v0_10_0_sha256_bitcoin_test.h` is generated from + `ecdsa_rustsecp256k1zkp_v0_10_0_sha256_bitcoin_test.json` using the script + `tests_wycheproof_generate.py`. + +------------------------------------------------------------------------------- + + 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/secp256k1-zkp-sys/depend/secp256k1/src/wycheproof/ecdsa_secp256k1_sha256_bitcoin_test.h b/secp256k1-zkp-sys/depend/secp256k1/src/wycheproof/ecdsa_secp256k1_sha256_bitcoin_test.h new file mode 100644 index 00000000..736737fd --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/wycheproof/ecdsa_secp256k1_sha256_bitcoin_test.h @@ -0,0 +1,1564 @@ +/* Note: this file was autogenerated using tests_wycheproof_generate.py. Do not edit. */ +#define SECP256K1_ECDSA_WYCHEPROOF_NUMBER_TESTVECTORS (463) + +typedef struct { + size_t pk_offset; + size_t msg_offset; + size_t msg_len; + size_t sig_offset; + size_t sig_len; + int expected_verify; +} wycheproof_ecdsa_testvector; + +static const unsigned char wycheproof_ecdsa_messages[] = { 0x31,0x32,0x33,0x34,0x30,0x30, + 0x32,0x35,0x35,0x38,0x35, + 0x34,0x32,0x36,0x34,0x37,0x39,0x37,0x32,0x34, + 0x37,0x31,0x33,0x38,0x36,0x38,0x34,0x38,0x39,0x31, + 0x31,0x30,0x33,0x35,0x39,0x33,0x33,0x31,0x36,0x36,0x38, + 0x33,0x39,0x34,0x39,0x34,0x30,0x31,0x32,0x31,0x35, + 0x31,0x33,0x34,0x34,0x32,0x39,0x33,0x30,0x37,0x39, + 0x33,0x37,0x30,0x36,0x32,0x31,0x31,0x37,0x31,0x32, + 0x33,0x34,0x33,0x36,0x38,0x38,0x37,0x31,0x32, + 0x31,0x33,0x35,0x31,0x35,0x33,0x30,0x33,0x37,0x30, + 0x36,0x35,0x35,0x33,0x32,0x30,0x33,0x31,0x32,0x36, + 0x31,0x35,0x36,0x34,0x33,0x34,0x36,0x36,0x30,0x33, + 0x34,0x34,0x32,0x39,0x35,0x33,0x39,0x31,0x31,0x37, + 0x31,0x30,0x39,0x35,0x33,0x32,0x36,0x31,0x33,0x35,0x31, + 0x35,0x39,0x38,0x37,0x33,0x35,0x30,0x30,0x34,0x31, + 0x33,0x34,0x36,0x33,0x30,0x30,0x36,0x38,0x37,0x38, + 0x39,0x38,0x31,0x37,0x33,0x32,0x30,0x32,0x38,0x37, + 0x33,0x32,0x32,0x32,0x30,0x34,0x31,0x30,0x34,0x36, + 0x36,0x36,0x36,0x36,0x33,0x30,0x37,0x31,0x30,0x34, + 0x31,0x30,0x33,0x35,0x39,0x35,0x31,0x38,0x39,0x38, + 0x31,0x38,0x34,0x36,0x35,0x39,0x37,0x31,0x39,0x35, + 0x33,0x31,0x33,0x36,0x30,0x34,0x36,0x31,0x38,0x39, + 0x32,0x36,0x36,0x33,0x37,0x38,0x34,0x32,0x35,0x34, + 0x31,0x36,0x35,0x32,0x31,0x30,0x30,0x35,0x32,0x34, + 0x35,0x37,0x34,0x38,0x30,0x38,0x31,0x36,0x39,0x36, + 0x36,0x33,0x34,0x33,0x39,0x31,0x33,0x34,0x36,0x38, + 0x31,0x35,0x34,0x31,0x31,0x30,0x33,0x35,0x39,0x38, + 0x31,0x30,0x34,0x37,0x38,0x35,0x38,0x30,0x31,0x32,0x38, + 0x31,0x30,0x35,0x33,0x36,0x32,0x38,0x35,0x35,0x36,0x38, + 0x39,0x35,0x33,0x39,0x30,0x34,0x31,0x30,0x35, + 0x39,0x37,0x38,0x38,0x34,0x38,0x30,0x33,0x39, + 0x33,0x36,0x31,0x30,0x36,0x37,0x32,0x34,0x34,0x32, + 0x31,0x30,0x35,0x34,0x32,0x34,0x30,0x37,0x30,0x35, + 0x35,0x31,0x37,0x34,0x34,0x34,0x38,0x31,0x39,0x37, + 0x31,0x39,0x36,0x37,0x35,0x36,0x31,0x32,0x35,0x31, + 0x33,0x34,0x34,0x37,0x32,0x35,0x33,0x33,0x34,0x33, + 0x33,0x36,0x38,0x32,0x36,0x34,0x33,0x31,0x38, + 0x33,0x32,0x36,0x31,0x31,0x39,0x38,0x36,0x30,0x38, + 0x39,0x36,0x37,0x38,0x37,0x38,0x31,0x30,0x39,0x34, + 0x34,0x39,0x35,0x38,0x38,0x32,0x33,0x38,0x32,0x33, + 0x38,0x32,0x34,0x36,0x33,0x37,0x38,0x33,0x37, + 0x31,0x31,0x30,0x32,0x30,0x38,0x33,0x33,0x37,0x37,0x36, + 0x31,0x33,0x33,0x38,0x37,0x31,0x36,0x34,0x38, + 0x33,0x32,0x32,0x31,0x34,0x34,0x31,0x36,0x32, + 0x31,0x30,0x36,0x38,0x36,0x36,0x35,0x35,0x35,0x34,0x36, + 0x36,0x32,0x31,0x35,0x35,0x32,0x34,0x36, + 0x37,0x30,0x33,0x30,0x38,0x31,0x38,0x37,0x37,0x34, + 0x35,0x39,0x32,0x34,0x35,0x32,0x33,0x37,0x34,0x34, + 0x31,0x34,0x39,0x35,0x35,0x38,0x36,0x36,0x32,0x31, + 0x34,0x30,0x30,0x35,0x33,0x31,0x34,0x34,0x30,0x36, + 0x33,0x30,0x39,0x36,0x34,0x35,0x37,0x35,0x31,0x32, + 0x32,0x37,0x38,0x34,0x30,0x32,0x35,0x36,0x32,0x30, + 0x32,0x36,0x31,0x38,0x37,0x38,0x37,0x34,0x31,0x38, + 0x31,0x36,0x34,0x32,0x36,0x32,0x35,0x32,0x36,0x32, + 0x36,0x38,0x32,0x34,0x31,0x38,0x39,0x34,0x33,0x36, + 0x34,0x38,0x34,0x32,0x34,0x35,0x34,0x32,0x35, + 0x4d,0x73,0x67, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x4d,0x65,0x73,0x73,0x61,0x67,0x65}; + +static const unsigned char wycheproof_ecdsa_public_keys[] = { 0x04,0xb8,0x38,0xff,0x44,0xe5,0xbc,0x17,0x7b,0xf2,0x11,0x89,0xd0,0x76,0x60,0x82,0xfc,0x9d,0x84,0x32,0x26,0x88,0x7f,0xc9,0x76,0x03,0x71,0x10,0x0b,0x7e,0xe2,0x0a,0x6f,0xf0,0xc9,0xd7,0x5b,0xfb,0xa7,0xb3,0x1a,0x6b,0xca,0x19,0x74,0x49,0x6e,0xeb,0x56,0xde,0x35,0x70,0x71,0x95,0x5d,0x83,0xc4,0xb1,0xba,0xda,0xa0,0xb2,0x18,0x32,0xe9, + 0x04,0x07,0x31,0x0f,0x90,0xa9,0xea,0xe1,0x49,0xa0,0x84,0x02,0xf5,0x41,0x94,0xa0,0xf7,0xb4,0xac,0x42,0x7b,0xf8,0xd9,0xbd,0x6c,0x76,0x81,0x07,0x1d,0xc4,0x7d,0xc3,0x62,0x26,0xa6,0xd3,0x7a,0xc4,0x6d,0x61,0xfd,0x60,0x0c,0x0b,0xf1,0xbf,0xf8,0x76,0x89,0xed,0x11,0x7d,0xda,0x6b,0x0e,0x59,0x31,0x8a,0xe0,0x10,0xa1,0x97,0xa2,0x6c,0xa0, + 0x04,0xbc,0x97,0xe7,0x58,0x5e,0xec,0xad,0x48,0xe1,0x66,0x83,0xbc,0x40,0x91,0x70,0x8e,0x1a,0x93,0x0c,0x68,0x3f,0xc4,0x70,0x01,0xd4,0xb3,0x83,0x59,0x4f,0x2c,0x4e,0x22,0x70,0x59,0x89,0xcf,0x69,0xda,0xea,0xdd,0x4e,0x4e,0x4b,0x81,0x51,0xed,0x88,0x8d,0xfe,0xc2,0x0f,0xb0,0x17,0x28,0xd8,0x9d,0x56,0xb3,0xf3,0x8f,0x2a,0xe9,0xc8,0xc5, + 0x04,0x44,0xad,0x33,0x9a,0xfb,0xc2,0x1e,0x9a,0xbf,0x7b,0x60,0x2a,0x5c,0xa5,0x35,0xea,0x37,0x81,0x35,0xb6,0xd1,0x0d,0x81,0x31,0x0b,0xdd,0x82,0x93,0xd1,0xdf,0x32,0x52,0xb6,0x3f,0xf7,0xd0,0x77,0x47,0x70,0xf8,0xfe,0x1d,0x17,0x22,0xfa,0x83,0xac,0xd0,0x2f,0x43,0x4e,0x4f,0xc1,0x10,0xa0,0xcc,0x8f,0x6d,0xdd,0xd3,0x7d,0x56,0xc4,0x63, + 0x04,0x12,0x60,0xc2,0x12,0x2c,0x9e,0x24,0x4e,0x1a,0xf5,0x15,0x1b,0xed,0xe0,0xc3,0xae,0x23,0xb5,0x4d,0x7c,0x59,0x68,0x81,0xd3,0xee,0xba,0xd2,0x1f,0x37,0xdd,0x87,0x8c,0x5c,0x9a,0x0c,0x1a,0x9a,0xde,0x76,0x73,0x7a,0x88,0x11,0xbd,0x6a,0x7f,0x92,0x87,0xc9,0x78,0xee,0x39,0x6a,0xa8,0x9c,0x11,0xe4,0x72,0x29,0xd2,0xcc,0xb5,0x52,0xf0, + 0x04,0x18,0x77,0x04,0x5b,0xe2,0x5d,0x34,0xa1,0xd0,0x60,0x0f,0x9d,0x5c,0x00,0xd0,0x64,0x5a,0x2a,0x54,0x37,0x9b,0x6c,0xee,0xfa,0xd2,0xe6,0xbf,0x5c,0x2a,0x33,0x52,0xce,0x82,0x1a,0x53,0x2c,0xc1,0x75,0x1e,0xe1,0xd3,0x6d,0x41,0xc3,0xd6,0xab,0x4e,0x9b,0x14,0x3e,0x44,0xec,0x46,0xd7,0x34,0x78,0xea,0x6a,0x79,0xa5,0xc0,0xe5,0x41,0x59, + 0x04,0x45,0x54,0x39,0xfc,0xc3,0xd2,0xde,0xec,0xed,0xde,0xae,0xce,0x60,0xe7,0xbd,0x17,0x30,0x4f,0x36,0xeb,0xb6,0x02,0xad,0xf5,0xa2,0x2e,0x0b,0x8f,0x1d,0xb4,0x6a,0x50,0xae,0xc3,0x8f,0xb2,0xba,0xf2,0x21,0xe9,0xa8,0xd1,0x88,0x7c,0x7b,0xf6,0x22,0x2d,0xd1,0x83,0x46,0x34,0xe7,0x72,0x63,0x31,0x5a,0xf6,0xd2,0x36,0x09,0xd0,0x4f,0x77, + 0x04,0x2e,0x1f,0x46,0x6b,0x02,0x4c,0x0c,0x3a,0xce,0x24,0x37,0xde,0x09,0x12,0x7f,0xed,0x04,0xb7,0x06,0xf9,0x4b,0x19,0xa2,0x1b,0xb1,0xc2,0xac,0xf3,0x5c,0xec,0xe7,0x18,0x04,0x49,0xae,0x35,0x23,0xd7,0x25,0x34,0xe9,0x64,0x97,0x2c,0xfd,0x3b,0x38,0xaf,0x0b,0xdd,0xd9,0x61,0x9e,0x5a,0xf2,0x23,0xe4,0xd1,0xa4,0x0f,0x34,0xcf,0x9f,0x1d, + 0x04,0x8e,0x7a,0xbd,0xbb,0xd1,0x8d,0xe7,0x45,0x23,0x74,0xc1,0x87,0x9a,0x1c,0x3b,0x01,0xd1,0x32,0x61,0xe7,0xd4,0x57,0x1c,0x3b,0x47,0xa1,0xc7,0x6c,0x55,0xa2,0x33,0x73,0x26,0xed,0x89,0x7c,0xd5,0x17,0xa4,0xf5,0x34,0x9d,0xb8,0x09,0x78,0x0f,0x6d,0x2f,0x2b,0x9f,0x62,0x99,0xd8,0xb5,0xa8,0x90,0x77,0xf1,0x11,0x9a,0x71,0x8f,0xd7,0xb3, + 0x04,0x7b,0x33,0x3d,0x43,0x40,0xd3,0xd7,0x18,0xdd,0x3e,0x6a,0xff,0x7d,0xe7,0xbb,0xf8,0xb7,0x2b,0xfd,0x61,0x6c,0x84,0x20,0x05,0x60,0x52,0x84,0x23,0x76,0xb9,0xaf,0x19,0x42,0x11,0x7c,0x5a,0xfe,0xac,0x75,0x5d,0x6f,0x37,0x6f,0xc6,0x32,0x9a,0x7d,0x76,0x05,0x1b,0x87,0x12,0x3a,0x4a,0x5d,0x0b,0xc4,0xa5,0x39,0x38,0x0f,0x03,0xde,0x7b, + 0x04,0xd3,0x0c,0xa4,0xa0,0xdd,0xb6,0x61,0x6c,0x85,0x1d,0x30,0xce,0xd6,0x82,0xc4,0x0f,0x83,0xc6,0x27,0x58,0xa1,0xf2,0x75,0x99,0x88,0xd6,0x76,0x3a,0x88,0xf1,0xc0,0xe5,0x03,0xa8,0x0d,0x54,0x15,0x65,0x0d,0x41,0x23,0x97,0x84,0xe8,0xe2,0xfb,0x12,0x35,0xe9,0xfe,0x99,0x1d,0x11,0x2e,0xbb,0x81,0x18,0x6c,0xbf,0x0d,0xa2,0xde,0x3a,0xff, + 0x04,0x48,0x96,0x9b,0x39,0x99,0x12,0x97,0xb3,0x32,0xa6,0x52,0xd3,0xee,0x6e,0x01,0xe9,0x09,0xb3,0x99,0x04,0xe7,0x1f,0xa2,0x35,0x4a,0x78,0x30,0xc7,0x75,0x0b,0xaf,0x24,0xb4,0x01,0x2d,0x1b,0x83,0x0d,0x19,0x9c,0xcb,0x1f,0xc9,0x72,0xb3,0x2b,0xfd,0xed,0x55,0xf0,0x9c,0xd6,0x2d,0x25,0x7e,0x5e,0x84,0x4e,0x27,0xe5,0x7a,0x15,0x94,0xec, + 0x04,0x02,0xef,0x4d,0x6d,0x6c,0xfd,0x5a,0x94,0xf1,0xd7,0x78,0x42,0x26,0xe3,0xe2,0xa6,0xc0,0xa4,0x36,0xc5,0x58,0x39,0x61,0x9f,0x38,0xfb,0x44,0x72,0xb5,0xf9,0xee,0x77,0x7e,0xb4,0xac,0xd4,0xee,0xbd,0xa5,0xcd,0x72,0x87,0x5f,0xfd,0x2a,0x2f,0x26,0x22,0x9c,0x2d,0xc6,0xb4,0x65,0x00,0x91,0x9a,0x43,0x2c,0x86,0x73,0x9f,0x3a,0xe8,0x66, + 0x04,0x46,0x4f,0x4f,0xf7,0x15,0x72,0x9c,0xae,0x50,0x72,0xca,0x3b,0xd8,0x01,0xd3,0x19,0x5b,0x67,0xae,0xc6,0x5e,0x9b,0x01,0xaa,0xd2,0x0a,0x29,0x43,0xdc,0xbc,0xb5,0x84,0xb1,0xaf,0xd2,0x9d,0x31,0xa3,0x9a,0x11,0xd5,0x70,0xaa,0x15,0x97,0x43,0x9b,0x3b,0x2d,0x19,0x71,0xbf,0x2f,0x1a,0xbf,0x15,0x43,0x2d,0x02,0x07,0xb1,0x0d,0x1d,0x08, + 0x04,0x15,0x7f,0x8f,0xdd,0xf3,0x73,0xeb,0x5f,0x49,0xcf,0xcf,0x10,0xd8,0xb8,0x53,0xcf,0x91,0xcb,0xcd,0x7d,0x66,0x5c,0x35,0x22,0xba,0x7d,0xd7,0x38,0xdd,0xb7,0x9a,0x4c,0xde,0xad,0xf1,0xa5,0xc4,0x48,0xea,0x3c,0x9f,0x41,0x91,0xa8,0x99,0x9a,0xbf,0xcc,0x75,0x7a,0xc6,0xd6,0x45,0x67,0xef,0x07,0x2c,0x47,0xfe,0xc6,0x13,0x44,0x3b,0x8f, + 0x04,0x09,0x34,0xa5,0x37,0x46,0x6c,0x07,0x43,0x0e,0x2c,0x48,0xfe,0xb9,0x90,0xbb,0x19,0xfb,0x78,0xce,0xcc,0x9c,0xee,0x42,0x4e,0xa4,0xd1,0x30,0x29,0x1a,0xa2,0x37,0xf0,0xd4,0xf9,0x2d,0x23,0xb4,0x62,0x80,0x4b,0x5b,0x68,0xc5,0x25,0x58,0xc0,0x1c,0x99,0x96,0xdb,0xf7,0x27,0xfc,0xca,0xbb,0xee,0xdb,0x96,0x21,0xa4,0x00,0x53,0x5a,0xfa, + 0x04,0xd6,0xef,0x20,0xbe,0x66,0xc8,0x93,0xf7,0x41,0xa9,0xbf,0x90,0xd9,0xb7,0x46,0x75,0xd1,0xc2,0xa3,0x12,0x96,0x39,0x7a,0xcb,0x3e,0xf1,0x74,0xfd,0x0b,0x30,0x0c,0x65,0x4a,0x0c,0x95,0x47,0x8c,0xa0,0x03,0x99,0x16,0x2d,0x7f,0x0f,0x2d,0xc8,0x9e,0xfd,0xc2,0xb2,0x8a,0x30,0xfb,0xab,0xe2,0x85,0x85,0x72,0x95,0xa4,0xb0,0xc4,0xe2,0x65, + 0x04,0xb7,0x29,0x1d,0x14,0x04,0xe0,0xc0,0xc0,0x7d,0xab,0x93,0x72,0x18,0x9f,0x4b,0xd5,0x8d,0x2c,0xea,0xa8,0xd1,0x5e,0xde,0x54,0x4d,0x95,0x14,0x54,0x5b,0xa9,0xee,0x06,0x29,0xc9,0xa6,0x3d,0x5e,0x30,0x87,0x69,0xcc,0x30,0xec,0x27,0x6a,0x41,0x0e,0x64,0x64,0xa2,0x7e,0xea,0xfd,0x9e,0x59,0x9d,0xb1,0x0f,0x05,0x3a,0x4f,0xe4,0xa8,0x29, + 0x04,0x6e,0x28,0x30,0x33,0x05,0xd6,0x42,0xcc,0xb9,0x23,0xb7,0x22,0xea,0x86,0xb2,0xa0,0xbc,0x8e,0x37,0x35,0xec,0xb2,0x6e,0x84,0x9b,0x19,0xc9,0xf7,0x6b,0x2f,0xdb,0xb8,0x18,0x6e,0x80,0xd6,0x4d,0x8c,0xab,0x16,0x4f,0x52,0x38,0xf5,0x31,0x84,0x61,0xbf,0x89,0xd4,0xd9,0x6e,0xe6,0x54,0x4c,0x81,0x6c,0x75,0x66,0x94,0x77,0x74,0xe0,0xf6, + 0x04,0x37,0x5b,0xda,0x93,0xf6,0xaf,0x92,0xfb,0x5f,0x8f,0x4b,0x1b,0x5f,0x05,0x34,0xe3,0xba,0xfa,0xb3,0x4c,0xb7,0xad,0x9f,0xb9,0xd0,0xb7,0x22,0xe4,0xa5,0xc3,0x02,0xa9,0xa0,0x0b,0x9f,0x38,0x7a,0x5a,0x39,0x60,0x97,0xaa,0x21,0x62,0xfc,0x5b,0xbc,0xf4,0xa5,0x26,0x33,0x72,0xf6,0x81,0xc9,0x4d,0xa5,0x1e,0x97,0x99,0x12,0x09,0x90,0xfd, + 0x04,0xd7,0x5b,0x68,0x21,0x6b,0xab,0xe0,0x3a,0xe2,0x57,0xe9,0x4b,0x4e,0x3b,0xf1,0xc5,0x2f,0x44,0xe3,0xdf,0x26,0x6d,0x15,0x24,0xff,0x8c,0x5e,0xa6,0x9d,0xa7,0x31,0x97,0xda,0x4b,0xff,0x9e,0xd1,0xc5,0x3f,0x44,0x91,0x7a,0x67,0xd7,0xb9,0x78,0x59,0x8e,0x89,0xdf,0x35,0x9e,0x3d,0x59,0x13,0xea,0xea,0x24,0xf3,0xae,0x25,0x9a,0xbc,0x44, + 0x04,0x78,0xbc,0xda,0x14,0x0a,0xed,0x23,0xd4,0x30,0xcb,0x23,0xc3,0xdc,0x0d,0x01,0xf4,0x23,0xdb,0x13,0x4e,0xe9,0x4a,0x3a,0x8c,0xb4,0x83,0xf2,0xde,0xac,0x2a,0xc6,0x53,0x11,0x81,0x14,0xf6,0xf3,0x30,0x45,0xd4,0xe9,0xed,0x91,0x07,0x08,0x50,0x07,0xbf,0xbd,0xdf,0x8f,0x58,0xfe,0x7a,0x1a,0x24,0x45,0xd6,0x6a,0x99,0x00,0x45,0x47,0x6e, + 0x04,0xbb,0x79,0xf6,0x18,0x57,0xf7,0x43,0xbf,0xa1,0xb6,0xe7,0x11,0x1c,0xe4,0x09,0x43,0x77,0x25,0x69,0x69,0xe4,0xe1,0x51,0x59,0x12,0x3d,0x95,0x48,0xac,0xc3,0xbe,0x6c,0x1f,0x9d,0x9f,0x88,0x60,0xdc,0xff,0xd3,0xeb,0x36,0xdd,0x6c,0x31,0xff,0x2e,0x72,0x26,0xc2,0x00,0x9c,0x4c,0x94,0xd8,0xd7,0xd2,0xb5,0x68,0x6b,0xf7,0xab,0xd6,0x77, + 0x04,0x93,0x59,0x18,0x27,0xd9,0xe6,0x71,0x3b,0x4e,0x9f,0xae,0xa6,0x2c,0x72,0xb2,0x8d,0xfe,0xfa,0x68,0xe0,0xc0,0x51,0x60,0xb5,0xd6,0xaa,0xe8,0x8f,0xd2,0xe3,0x6c,0x36,0x07,0x3f,0x55,0x45,0xad,0x5a,0xf4,0x10,0xaf,0x26,0xaf,0xff,0x68,0x65,0x4c,0xf7,0x2d,0x45,0xe4,0x93,0x48,0x93,0x11,0x20,0x32,0x47,0x34,0x7a,0x89,0x0f,0x45,0x18, + 0x04,0x31,0xed,0x30,0x81,0xae,0xfe,0x00,0x1e,0xb6,0x40,0x20,0x69,0xee,0x2c,0xcc,0x18,0x62,0x93,0x7b,0x85,0x99,0x51,0x44,0xdb,0xa9,0x50,0x39,0x43,0x58,0x7b,0xf0,0xda,0xda,0x01,0xb8,0xcc,0x4d,0xf3,0x4f,0x5a,0xb3,0xb1,0xa3,0x59,0x61,0x52,0x08,0x94,0x6e,0x5e,0xe3,0x5f,0x98,0xee,0x77,0x5b,0x8c,0xce,0xcd,0x86,0xcc,0xc1,0x65,0x0f, + 0x04,0x7d,0xff,0x66,0xfa,0x98,0x50,0x9f,0xf3,0xe2,0xe5,0x10,0x45,0xf4,0x39,0x05,0x23,0xdc,0xcd,0xa4,0x3a,0x3b,0xc2,0x88,0x5e,0x58,0xc2,0x48,0x09,0x09,0x90,0xee,0xa8,0x54,0xc7,0x6c,0x2b,0x9a,0xde,0xb6,0xbb,0x57,0x18,0x23,0xe0,0x7f,0xd7,0xc6,0x5c,0x86,0x39,0xcf,0x9d,0x90,0x52,0x60,0x06,0x4c,0x8e,0x76,0x75,0xce,0x6d,0x98,0xb4, + 0x04,0x42,0x80,0x50,0x9a,0xab,0x64,0xed,0xfc,0x0b,0x4a,0x29,0x67,0xe4,0xcb,0xce,0x84,0x9c,0xb5,0x44,0xe4,0xa7,0x73,0x13,0xc8,0xe6,0xec,0xe5,0x79,0xfb,0xd7,0x42,0x0a,0x2e,0x89,0xfe,0x5c,0xc1,0x92,0x7d,0x55,0x4e,0x6a,0x3b,0xb1,0x40,0x33,0xea,0x7c,0x92,0x2c,0xd7,0x5c,0xba,0x2c,0x74,0x15,0xfd,0xab,0x52,0xf2,0x0b,0x18,0x60,0xf1, + 0x04,0x4f,0x8d,0xf1,0x45,0x19,0x4e,0x3c,0x4f,0xc3,0xee,0xa2,0x6d,0x43,0xce,0x75,0xb4,0x02,0xd6,0xb1,0x74,0x72,0xdd,0xcb,0xb2,0x54,0xb8,0xa7,0x9b,0x0b,0xf3,0xd9,0xcb,0x2a,0xa2,0x0d,0x82,0x84,0x4c,0xb2,0x66,0x34,0x4e,0x71,0xca,0x78,0xf2,0xad,0x27,0xa7,0x5a,0x09,0xe5,0xbc,0x0f,0xa5,0x7e,0x4e,0xfd,0x9d,0x46,0x5a,0x08,0x88,0xdb, + 0x04,0x95,0x98,0xa5,0x7d,0xd6,0x7e,0xc3,0xe1,0x6b,0x58,0x7a,0x33,0x8a,0xa3,0xa1,0x0a,0x3a,0x39,0x13,0xb4,0x1a,0x3a,0xf3,0x2e,0x3e,0xd3,0xff,0x01,0x35,0x8c,0x6b,0x14,0x12,0x28,0x19,0xed,0xf8,0x07,0x4b,0xbc,0x52,0x1f,0x7d,0x4c,0xdc,0xe8,0x2f,0xef,0x7a,0x51,0x67,0x06,0xaf,0xfb,0xa1,0xd9,0x3d,0x9d,0xea,0x9c,0xca,0xe1,0xa2,0x07, + 0x04,0x91,0x71,0xfe,0xc3,0xca,0x20,0x80,0x6b,0xc0,0x84,0xf1,0x2f,0x07,0x60,0x91,0x1b,0x60,0x99,0x0b,0xd8,0x0e,0x5b,0x2a,0x71,0xca,0x03,0xa0,0x48,0xb2,0x0f,0x83,0x7e,0x63,0x4f,0xd1,0x78,0x63,0x76,0x1b,0x29,0x58,0xd2,0xbe,0x4e,0x14,0x9f,0x8d,0x3d,0x7a,0xbb,0xdc,0x18,0xbe,0x03,0xf4,0x51,0xab,0x6c,0x17,0xfa,0x0a,0x1f,0x83,0x30, + 0x04,0x77,0x7c,0x89,0x30,0xb6,0xe1,0xd2,0x71,0x10,0x0f,0xe6,0x8c,0xe9,0x3f,0x16,0x3f,0xa3,0x76,0x12,0xc5,0xff,0xf6,0x7f,0x4a,0x62,0xfc,0x3b,0xaf,0xaf,0x3d,0x17,0xa9,0xed,0x73,0xd8,0x6f,0x60,0xa5,0x1b,0x5e,0xd9,0x13,0x53,0xa3,0xb0,0x54,0xed,0xc0,0xaa,0x92,0xc9,0xeb,0xcb,0xd0,0xb7,0x5d,0x18,0x8f,0xdc,0x88,0x27,0x91,0xd6,0x8d, + 0x04,0xea,0xbc,0x24,0x8f,0x62,0x6e,0x0a,0x63,0xe1,0xeb,0x81,0xc4,0x3d,0x46,0x1a,0x39,0xa1,0xdb,0xa8,0x81,0xeb,0x6e,0xe2,0x15,0x2b,0x07,0xc3,0x2d,0x71,0xbc,0xf4,0x70,0x06,0x03,0xca,0xa8,0xb9,0xd3,0x3d,0xb1,0x3a,0xf4,0x4c,0x6e,0xfb,0xec,0x8a,0x19,0x8e,0xd6,0x12,0x4a,0xc9,0xeb,0x17,0xea,0xaf,0xd2,0x82,0x4a,0x54,0x5e,0xc0,0x00, + 0x04,0x9f,0x7a,0x13,0xad,0xa1,0x58,0xa5,0x5f,0x9d,0xdf,0x1a,0x45,0xf0,0x44,0xf0,0x73,0xd9,0xb8,0x00,0x30,0xef,0xdc,0xfc,0x9f,0x9f,0x58,0x41,0x8f,0xbc,0xea,0xf0,0x01,0xf8,0xad,0xa0,0x17,0x50,0x90,0xf8,0x0d,0x47,0x22,0x7d,0x67,0x13,0xb6,0x74,0x0f,0x9a,0x00,0x91,0xd8,0x8a,0x83,0x7d,0x0a,0x1c,0xd7,0x7b,0x58,0xa8,0xf2,0x8d,0x73, + 0x04,0x11,0xc4,0xf3,0xe4,0x61,0xcd,0x01,0x9b,0x5c,0x06,0xea,0x0c,0xea,0x4c,0x40,0x90,0xc3,0xcc,0x3e,0x3c,0x5d,0x9f,0x3c,0x6d,0x65,0xb4,0x36,0x82,0x6d,0xa9,0xb4,0xdb,0xbb,0xeb,0x7a,0x77,0xe4,0xcb,0xfd,0xa2,0x07,0x09,0x7c,0x43,0x42,0x37,0x05,0xf7,0x2c,0x80,0x47,0x6d,0xa3,0xda,0xc4,0x0a,0x48,0x3b,0x0a,0xb0,0xf2,0xea,0xd1,0xcb, + 0x04,0xe2,0xe1,0x86,0x82,0xd5,0x31,0x23,0xaa,0x01,0xa6,0xc5,0xd0,0x0b,0x0c,0x62,0x3d,0x67,0x1b,0x46,0x2e,0xa8,0x0b,0xdd,0xd6,0x52,0x27,0xfd,0x51,0x05,0x98,0x8a,0xa4,0x16,0x19,0x07,0xb3,0xfd,0x25,0x04,0x4a,0x94,0x9e,0xa4,0x1c,0x8e,0x2e,0xa8,0x45,0x9d,0xc6,0xf1,0x65,0x48,0x56,0xb8,0xb6,0x1b,0x31,0x54,0x3b,0xb1,0xb4,0x5b,0xdb, + 0x04,0x90,0xf8,0xd4,0xca,0x73,0xde,0x08,0xa6,0x56,0x4a,0xaf,0x00,0x52,0x47,0xb6,0xf0,0xff,0xe9,0x78,0x50,0x4d,0xce,0x52,0x60,0x5f,0x46,0xb7,0xc3,0xe5,0x61,0x97,0xda,0xfa,0xdb,0xe5,0x28,0xeb,0x70,0xd9,0xee,0x7e,0xa0,0xe7,0x07,0x02,0xdb,0x54,0xf7,0x21,0x51,0x4c,0x7b,0x86,0x04,0xac,0x2c,0xb2,0x14,0xf1,0xde,0xcb,0x7e,0x38,0x3d, + 0x04,0x82,0x4c,0x19,0x5c,0x73,0xcf,0xfd,0xf0,0x38,0xd1,0x01,0xbc,0xe1,0x68,0x7b,0x5c,0x3b,0x61,0x46,0xf3,0x95,0xc8,0x85,0x97,0x6f,0x77,0x53,0xb2,0x37,0x6b,0x94,0x8e,0x3c,0xde,0xfa,0x6f,0xc3,0x47,0xd1,0x3e,0x4d,0xcb,0xc6,0x3a,0x0b,0x03,0xa1,0x65,0x18,0x0c,0xd2,0xbe,0x14,0x31,0xa0,0xcf,0x74,0xce,0x1e,0xa2,0x50,0x82,0xd2,0xbc, + 0x04,0x27,0x88,0xa5,0x2f,0x07,0x8e,0xb3,0xf2,0x02,0xc4,0xfa,0x73,0xe0,0xd3,0x38,0x6f,0xaf,0x3d,0xf6,0xbe,0x85,0x60,0x03,0x63,0x6f,0x59,0x99,0x22,0xd4,0xf5,0x26,0x8f,0x30,0xb4,0xf2,0x07,0xc9,0x19,0xbb,0xdf,0x5e,0x67,0xa8,0xbe,0x42,0x65,0xa8,0x17,0x47,0x54,0xb3,0xab,0xa8,0xf1,0x6e,0x57,0x5b,0x77,0xff,0x4d,0x5a,0x7e,0xb6,0x4f, + 0x04,0xd5,0x33,0xb7,0x89,0xa4,0xaf,0x89,0x0f,0xa7,0xa8,0x2a,0x1f,0xae,0x58,0xc4,0x04,0xf9,0xa6,0x2a,0x50,0xb4,0x9a,0xda,0xfa,0xb3,0x49,0xc5,0x13,0xb4,0x15,0x08,0x74,0x01,0xb4,0x17,0x1b,0x80,0x3e,0x76,0xb3,0x4a,0x98,0x61,0xe1,0x0f,0x7b,0xc2,0x89,0xa0,0x66,0xfd,0x01,0xbd,0x29,0xf8,0x4c,0x98,0x7a,0x10,0xa5,0xfb,0x18,0xc2,0xd4, + 0x04,0x3a,0x31,0x50,0x79,0x8c,0x8a,0xf6,0x9d,0x1e,0x6e,0x98,0x1f,0x3a,0x45,0x40,0x2b,0xa1,0xd7,0x32,0xf4,0xbe,0x83,0x30,0xc5,0x16,0x4f,0x49,0xe1,0x0e,0xc5,0x55,0xb4,0x22,0x1b,0xd8,0x42,0xbc,0x5e,0x4d,0x97,0xef,0xf3,0x71,0x65,0xf6,0x0e,0x39,0x98,0xa4,0x24,0xd7,0x2a,0x45,0x0c,0xf9,0x5e,0xa4,0x77,0xc7,0x82,0x87,0xd0,0x34,0x3a, + 0x04,0x3b,0x37,0xdf,0x5f,0xb3,0x47,0xc6,0x9a,0x0f,0x17,0xd8,0x5c,0x0c,0x7c,0xa8,0x37,0x36,0x88,0x3a,0x82,0x5e,0x13,0x14,0x3d,0x0f,0xcf,0xc8,0x10,0x1e,0x85,0x1e,0x80,0x0d,0xe3,0xc0,0x90,0xb6,0xca,0x21,0xba,0x54,0x35,0x17,0x33,0x0c,0x04,0xb1,0x2f,0x94,0x8c,0x6b,0xad,0xf1,0x4a,0x63,0xab,0xff,0xdf,0x4e,0xf8,0xc7,0x53,0x70,0x26, + 0x04,0xfe,0xb5,0x16,0x3b,0x0e,0xce,0x30,0xff,0x3e,0x03,0xc7,0xd5,0x5c,0x43,0x80,0xfa,0x2f,0xa8,0x1e,0xe2,0xc0,0x35,0x49,0x42,0xff,0x6f,0x08,0xc9,0x9d,0x0c,0xd8,0x2c,0xe8,0x7d,0xe0,0x5e,0xe1,0xbd,0xa0,0x89,0xd3,0xe4,0xe2,0x48,0xfa,0x0f,0x72,0x11,0x02,0xac,0xff,0xfd,0xf5,0x0e,0x65,0x4b,0xe2,0x81,0x43,0x39,0x99,0xdf,0x89,0x7e, + 0x04,0x23,0x8c,0xed,0x00,0x1c,0xf2,0x2b,0x88,0x53,0xe0,0x2e,0xdc,0x89,0xcb,0xec,0xa5,0x05,0x0b,0xa7,0xe0,0x42,0xa7,0xa7,0x7f,0x93,0x82,0xcd,0x41,0x49,0x22,0x89,0x76,0x40,0x68,0x3d,0x30,0x94,0x64,0x38,0x40,0xf2,0x95,0x89,0x0a,0xa4,0xc1,0x8a,0xa3,0x9b,0x41,0xd7,0x7d,0xd0,0xfb,0x3b,0xb2,0x70,0x0e,0x4f,0x9e,0xc2,0x84,0xff,0xc2, + 0x04,0x96,0x1c,0xf6,0x48,0x17,0xc0,0x6c,0x0e,0x51,0xb3,0xc2,0x73,0x6c,0x92,0x2f,0xde,0x18,0xbd,0x8c,0x49,0x06,0xfc,0xd7,0xf5,0xef,0x66,0xc4,0x67,0x85,0x08,0xf3,0x5e,0xd2,0xc5,0xd1,0x81,0x68,0xcf,0xbe,0x70,0xf2,0xf1,0x23,0xbd,0x74,0x19,0x23,0x2b,0xb9,0x2d,0xd6,0x91,0x13,0xe2,0x94,0x10,0x61,0x88,0x94,0x81,0xc5,0xa0,0x27,0xbf, + 0x04,0x13,0x68,0x1e,0xae,0x16,0x8c,0xd4,0xea,0x7c,0xf2,0xe2,0xa4,0x5d,0x05,0x27,0x42,0xd1,0x0a,0x9f,0x64,0xe7,0x96,0x86,0x7d,0xbd,0xcb,0x82,0x9f,0xe0,0xb1,0x02,0x88,0x16,0x52,0x87,0x60,0xd1,0x77,0x37,0x6c,0x09,0xdf,0x79,0xde,0x39,0x55,0x7c,0x32,0x9c,0xc1,0x75,0x35,0x17,0xac,0xff,0xe8,0xfa,0x2e,0xc2,0x98,0x02,0x6b,0x83,0x84, + 0x04,0x5a,0xa7,0xab,0xfd,0xb6,0xb4,0x08,0x6d,0x54,0x33,0x25,0xe5,0xd7,0x9c,0x6e,0x95,0xce,0x42,0xf8,0x66,0xd2,0xbb,0x84,0x90,0x96,0x33,0xa0,0x4b,0xb1,0xaa,0x31,0xc2,0x91,0xc8,0x00,0x88,0x79,0x49,0x05,0xe1,0xda,0x33,0x33,0x6d,0x87,0x4e,0x2f,0x91,0xcc,0xf4,0x5c,0xc5,0x91,0x85,0xbe,0xde,0x5d,0xd6,0xf3,0xf7,0xac,0xaa,0xe1,0x8b, + 0x04,0x00,0x27,0x77,0x91,0xb3,0x05,0xa4,0x5b,0x2b,0x39,0x59,0x0b,0x2f,0x05,0xd3,0x39,0x2a,0x6c,0x81,0x82,0xce,0xf4,0xeb,0x54,0x01,0x20,0xe0,0xf5,0xc2,0x06,0xc3,0xe4,0x64,0x10,0x82,0x33,0xfb,0x0b,0x8c,0x3a,0xc8,0x92,0xd7,0x9e,0xf8,0xe0,0xfb,0xf9,0x2e,0xd1,0x33,0xad,0xdb,0x45,0x54,0x27,0x01,0x32,0x58,0x4d,0xc5,0x2e,0xef,0x41, + 0x04,0x6e,0xfa,0x09,0x2b,0x68,0xde,0x94,0x60,0xf0,0xbc,0xc9,0x19,0x00,0x5a,0x5f,0x6e,0x80,0xe1,0x9d,0xe9,0x89,0x68,0xbe,0x3c,0xd2,0xc7,0x70,0xa9,0x94,0x9b,0xfb,0x1a,0xc7,0x5e,0x6e,0x50,0x87,0xd6,0x55,0x0d,0x5f,0x9b,0xeb,0x1e,0x79,0xe5,0x02,0x93,0x07,0xbc,0x25,0x52,0x35,0xe2,0xd5,0xdc,0x99,0x24,0x1a,0xc3,0xab,0x88,0x6c,0x49, + 0x04,0x72,0xd4,0xa1,0x9c,0x4f,0x9d,0x2c,0xf5,0x84,0x8e,0xa4,0x04,0x45,0xb7,0x0d,0x46,0x96,0xb5,0xf0,0x2d,0x63,0x2c,0x0c,0x65,0x4c,0xc7,0xd7,0xee,0xb0,0xc6,0xd0,0x58,0xe8,0xc4,0xcd,0x99,0x43,0xe4,0x59,0x17,0x4c,0x7a,0xc0,0x1f,0xa7,0x42,0x19,0x8e,0x47,0xe6,0xc1,0x9a,0x6b,0xdb,0x0c,0x4f,0x6c,0x23,0x78,0x31,0xc1,0xb3,0xf9,0x42, + 0x04,0x2a,0x8e,0xa2,0xf5,0x0d,0xcc,0xed,0x0c,0x21,0x75,0x75,0xbd,0xfa,0x7c,0xd4,0x7d,0x1c,0x6f,0x10,0x00,0x41,0xec,0x0e,0x35,0x51,0x27,0x94,0xc1,0xbe,0x7e,0x74,0x02,0x58,0xf8,0xc1,0x71,0x22,0xed,0x30,0x3f,0xda,0x71,0x43,0xeb,0x58,0xbe,0xde,0x70,0x29,0x5b,0x65,0x32,0x66,0x01,0x3b,0x0b,0x0e,0xbd,0x3f,0x05,0x31,0x37,0xf6,0xec, + 0x04,0x88,0xde,0x68,0x9c,0xe9,0xaf,0x1e,0x94,0xbe,0x6a,0x20,0x89,0xc8,0xa8,0xb1,0x25,0x3f,0xfd,0xbb,0x6c,0x8e,0x9c,0x86,0x24,0x9b,0xa2,0x20,0x00,0x1a,0x4a,0xd3,0xb8,0x0c,0x49,0x98,0xe5,0x48,0x42,0xf4,0x13,0xb9,0xed,0xb1,0x82,0x5a,0xcb,0xb6,0x33,0x5e,0x81,0xe4,0xd1,0x84,0xb2,0xb0,0x1c,0x8b,0xeb,0xdc,0x85,0xd1,0xf2,0x89,0x46, + 0x04,0xfe,0xa2,0xd3,0x1f,0x70,0xf9,0x0d,0x5f,0xb3,0xe0,0x0e,0x18,0x6a,0xc4,0x2a,0xb3,0xc1,0x61,0x5c,0xee,0x71,0x4e,0x0b,0x4e,0x11,0x31,0xb3,0xd4,0xd8,0x22,0x5b,0xf7,0xb0,0x37,0xa1,0x8d,0xf2,0xac,0x15,0x34,0x3f,0x30,0xf7,0x40,0x67,0xdd,0xf2,0x9e,0x81,0x7d,0x5f,0x77,0xf8,0xdc,0xe0,0x57,0x14,0xda,0x59,0xc0,0x94,0xf0,0xcd,0xa9, + 0x04,0x72,0x58,0x91,0x1e,0x3d,0x42,0x33,0x49,0x16,0x64,0x79,0xdb,0xe0,0xb8,0x34,0x1a,0xf7,0xfb,0xd0,0x3d,0x0a,0x7e,0x10,0xed,0xcc,0xb3,0x6b,0x6c,0xee,0xa5,0xa3,0xdb,0x17,0xac,0x2b,0x89,0x92,0x79,0x11,0x28,0xfa,0x3b,0x96,0xdc,0x2f,0xbd,0x4c,0xa3,0xbf,0xa7,0x82,0xef,0x28,0x32,0xfc,0x66,0x56,0x94,0x3d,0xb1,0x8e,0x73,0x46,0xb0, + 0x04,0x4f,0x28,0x46,0x1d,0xea,0x64,0x47,0x4d,0x6b,0xb3,0x4d,0x14,0x99,0xc9,0x7d,0x37,0xb9,0xe9,0x56,0x33,0xdf,0x1c,0xee,0xea,0xac,0xd4,0x50,0x16,0xc9,0x8b,0x39,0x14,0xc8,0x81,0x88,0x10,0xb8,0xcc,0x06,0xdd,0xb4,0x0e,0x8a,0x12,0x61,0xc5,0x28,0xfa,0xa5,0x89,0x45,0x5d,0x5a,0x6d,0xf9,0x3b,0x77,0xbc,0x5e,0x0e,0x49,0x3c,0x74,0x70, + 0x04,0x74,0xf2,0xa8,0x14,0xfb,0x5d,0x8e,0xca,0x91,0xa6,0x9b,0x5e,0x60,0x71,0x27,0x32,0xb3,0x93,0x7d,0xe3,0x28,0x29,0xbe,0x97,0x4e,0xd7,0xb6,0x8c,0x5c,0x2f,0x5d,0x66,0xef,0xf0,0xf0,0x7c,0x56,0xf9,0x87,0xa6,0x57,0xf4,0x21,0x96,0x20,0x5f,0x58,0x8c,0x0f,0x1d,0x96,0xfd,0x8a,0x63,0xa5,0xf2,0x38,0xb4,0x8f,0x47,0x87,0x88,0xfe,0x3b, + 0x04,0x19,0x5b,0x51,0xa7,0xcc,0x4a,0x21,0xb8,0x27,0x4a,0x70,0xa9,0x0d,0xe7,0x79,0x81,0x4c,0x3c,0x8c,0xa3,0x58,0x32,0x82,0x08,0xc0,0x9a,0x29,0xf3,0x36,0xb8,0x2d,0x6a,0xb2,0x41,0x6b,0x7c,0x92,0xff,0xfd,0xc2,0x9c,0x3b,0x12,0x82,0xdd,0x2a,0x77,0xa4,0xd0,0x4d,0xf7,0xf7,0x45,0x20,0x47,0x39,0x3d,0x84,0x99,0x89,0xc5,0xce,0xe9,0xad, + 0x04,0x62,0x2f,0xc7,0x47,0x32,0x03,0x4b,0xec,0x2d,0xdf,0x3b,0xc1,0x6d,0x34,0xb3,0xd1,0xf7,0xa3,0x27,0xdd,0x2a,0x8c,0x19,0xba,0xb4,0xbb,0x4f,0xe3,0xa2,0x4b,0x58,0xaa,0x73,0x6b,0x2f,0x2f,0xae,0x76,0xf4,0xdf,0xae,0xcc,0x90,0x96,0x33,0x3b,0x01,0x32,0x8d,0x51,0xeb,0x3f,0xda,0x9c,0x92,0x27,0xe9,0x0d,0x0b,0x44,0x99,0x83,0xc4,0xf0, + 0x04,0x1f,0x7f,0x85,0xca,0xf2,0xd7,0x55,0x0e,0x7a,0xf9,0xb6,0x50,0x23,0xeb,0xb4,0xdc,0xe3,0x45,0x03,0x11,0x69,0x23,0x09,0xdb,0x26,0x99,0x69,0xb8,0x34,0xb6,0x11,0xc7,0x08,0x27,0xf4,0x5b,0x78,0x02,0x0e,0xcb,0xba,0xf4,0x84,0xfd,0xd5,0xbf,0xaa,0xe6,0x87,0x0f,0x11,0x84,0xc2,0x15,0x81,0xba,0xf6,0xef,0x82,0xbd,0x7b,0x53,0x0f,0x93, + 0x04,0x49,0xc1,0x97,0xdc,0x80,0xad,0x1d,0xa4,0x7a,0x43,0x42,0xb9,0x38,0x93,0xe8,0xe1,0xfb,0x0b,0xb9,0x4f,0xc3,0x3a,0x83,0xe7,0x83,0xc0,0x0b,0x24,0xc7,0x81,0x37,0x7a,0xef,0xc2,0x0d,0xa9,0x2b,0xac,0x76,0x29,0x51,0xf7,0x24,0x74,0xbe,0xcc,0x73,0x4d,0x4c,0xc2,0x2b,0xa8,0x1b,0x89,0x5e,0x28,0x2f,0xda,0xc4,0xdf,0x7a,0xf0,0xf3,0x7d, + 0x04,0xd8,0xcb,0x68,0x51,0x7b,0x61,0x6a,0x56,0x40,0x0a,0xa3,0x86,0x86,0x35,0xe5,0x4b,0x6f,0x69,0x95,0x98,0xa2,0xf6,0x16,0x77,0x57,0x65,0x49,0x80,0xba,0xf6,0xac,0xbe,0x7e,0xc8,0xcf,0x44,0x9c,0x84,0x9a,0xa0,0x34,0x61,0xa3,0x0e,0xfa,0xda,0x41,0x45,0x3c,0x57,0xc6,0xe6,0xfb,0xc9,0x3b,0xbc,0x6f,0xa4,0x9a,0xda,0x6d,0xc0,0x55,0x5c, + 0x04,0x03,0x07,0x13,0xfb,0x63,0xf2,0xaa,0x6f,0xe2,0xca,0xdf,0x1b,0x20,0xef,0xc2,0x59,0xc7,0x74,0x45,0xda,0xfa,0x87,0xda,0xc3,0x98,0xb8,0x40,0x65,0xca,0x34,0x7d,0xf3,0xb2,0x27,0x81,0x8d,0xe1,0xa3,0x9b,0x58,0x9c,0xb0,0x71,0xd8,0x3e,0x53,0x17,0xcc,0xcd,0xc2,0x33,0x8e,0x51,0xe3,0x12,0xfe,0x31,0xd8,0xdc,0x34,0xa4,0x80,0x17,0x50, + 0x04,0xba,0xbb,0x36,0x77,0xb0,0x95,0x58,0x02,0xd8,0xe9,0x29,0xa4,0x13,0x55,0x64,0x0e,0xaf,0x1e,0xa1,0x35,0x3f,0x8a,0x77,0x13,0x31,0xc4,0x94,0x6e,0x34,0x80,0xaf,0xa7,0x25,0x2f,0x19,0x6c,0x87,0xed,0x3d,0x2a,0x59,0xd3,0xb1,0xb5,0x59,0x13,0x7f,0xed,0x00,0x13,0xfe,0xce,0xfc,0x19,0xfb,0x5a,0x92,0x68,0x2b,0x9b,0xca,0x51,0xb9,0x50, + 0x04,0x1a,0xab,0x20,0x18,0x79,0x34,0x71,0x11,0x1a,0x8a,0x0e,0x9b,0x14,0x3f,0xde,0x02,0xfc,0x95,0x92,0x07,0x96,0xd3,0xa6,0x3d,0xe3,0x29,0xb4,0x24,0x39,0x6f,0xba,0x60,0xbb,0xe4,0x13,0x07,0x05,0x17,0x47,0x92,0x44,0x1b,0x31,0x8d,0x3a,0xa3,0x1d,0xfe,0x85,0x77,0x82,0x1e,0x9b,0x44,0x6e,0xc5,0x73,0xd2,0x72,0xe0,0x36,0xc4,0xeb,0xe9, + 0x04,0x8c,0xb0,0xb9,0x09,0x49,0x9c,0x83,0xea,0x80,0x6c,0xd8,0x85,0xb1,0xdd,0x46,0x7a,0x01,0x19,0xf0,0x6a,0x88,0xa0,0x27,0x6e,0xb0,0xcf,0xda,0x27,0x45,0x35,0xa8,0xff,0x47,0xb5,0x42,0x88,0x33,0xbc,0x3f,0x2c,0x8b,0xf9,0xd9,0x04,0x11,0x58,0xcf,0x33,0x71,0x8a,0x69,0x96,0x1c,0xd0,0x17,0x29,0xbc,0x00,0x11,0xd1,0xe5,0x86,0xab,0x75, + 0x04,0x8f,0x03,0xcf,0x1a,0x42,0x27,0x2b,0xb1,0x53,0x27,0x23,0x09,0x3f,0x72,0xe6,0xfe,0xea,0xc8,0x5e,0x17,0x00,0xe9,0xfb,0xe9,0xa6,0xa2,0xdd,0x64,0x2d,0x74,0xbf,0x5d,0x3b,0x89,0xa7,0x18,0x9d,0xad,0x8c,0xf7,0x5f,0xc2,0x2f,0x6f,0x15,0x8a,0xa2,0x7f,0x9c,0x2c,0xa0,0x0d,0xac,0xa7,0x85,0xbe,0x33,0x58,0xf2,0xbd,0xa3,0x86,0x2c,0xa0, + 0x04,0x44,0xde,0x3b,0x9c,0x7a,0x57,0xa8,0xc9,0xe8,0x20,0x95,0x27,0x53,0x42,0x1e,0x7d,0x98,0x7b,0xb3,0xd7,0x9f,0x71,0xf0,0x13,0x80,0x5c,0x89,0x7e,0x01,0x8f,0x8a,0xce,0xa2,0x46,0x07,0x58,0xc8,0xf9,0x8d,0x3f,0xdc,0xe1,0x21,0xa9,0x43,0x65,0x9e,0x37,0x2c,0x32,0x6f,0xff,0x2e,0x5f,0xc2,0xae,0x7f,0xa3,0xf7,0x9d,0xaa,0xe1,0x3c,0x12, + 0x04,0x6f,0xb8,0xb2,0xb4,0x8e,0x33,0x03,0x12,0x68,0xad,0x6a,0x51,0x74,0x84,0xdc,0x88,0x39,0xea,0x90,0xf6,0x66,0x9e,0xa0,0xc7,0xac,0x32,0x33,0xe2,0xac,0x31,0x39,0x4a,0x0a,0xc8,0xbb,0xe7,0xf7,0x3c,0x2f,0xf4,0xdf,0x99,0x78,0x72,0x7a,0xc1,0xdf,0xc2,0xfd,0x58,0x64,0x7d,0x20,0xf3,0x1f,0x99,0x10,0x53,0x16,0xb6,0x46,0x71,0xf2,0x04, + 0x04,0xbe,0xa7,0x11,0x22,0xa0,0x48,0x69,0x3e,0x90,0x5f,0xf6,0x02,0xb3,0xcf,0x9d,0xd1,0x8a,0xf6,0x9b,0x9f,0xc9,0xd8,0x43,0x1d,0x2b,0x1d,0xd2,0x6b,0x94,0x2c,0x95,0xe6,0xf4,0x3c,0x7b,0x8b,0x95,0xeb,0x62,0x08,0x2c,0x12,0xdb,0x9d,0xbd,0xa7,0xfe,0x38,0xe4,0x5c,0xbe,0x4a,0x48,0x86,0x90,0x7f,0xb8,0x1b,0xdb,0x0c,0x5e,0xa9,0x24,0x6c, + 0x04,0xda,0x91,0x8c,0x73,0x1b,0xa0,0x6a,0x20,0xcb,0x94,0xef,0x33,0xb7,0x78,0xe9,0x81,0xa4,0x04,0xa3,0x05,0xf1,0x94,0x1f,0xe3,0x36,0x66,0xb4,0x5b,0x03,0x35,0x31,0x56,0xe2,0xbb,0x26,0x94,0xf5,0x75,0xb4,0x51,0x83,0xbe,0x78,0xe5,0xc9,0xb5,0x21,0x0b,0xf3,0xbf,0x48,0x8f,0xd4,0xc8,0x29,0x45,0x16,0xd8,0x95,0x72,0xca,0x4f,0x53,0x91, + 0x04,0x30,0x07,0xe9,0x2c,0x39,0x37,0xda,0xde,0x79,0x64,0xdf,0xa3,0x5b,0x0e,0xff,0x03,0x1f,0x7e,0xb0,0x2a,0xed,0x0a,0x03,0x14,0x41,0x11,0x06,0xcd,0xeb,0x70,0xfe,0x3d,0x5a,0x75,0x46,0xfc,0x05,0x52,0x99,0x7b,0x20,0xe3,0xd6,0xf4,0x13,0xe7,0x5e,0x2c,0xb6,0x6e,0x11,0x63,0x22,0x69,0x71,0x14,0xb7,0x9b,0xac,0x73,0x4b,0xfc,0x4d,0xc5, + 0x04,0x60,0xe7,0x34,0xef,0x56,0x24,0xd3,0xcb,0xf0,0xdd,0xd3,0x75,0x01,0x1b,0xd6,0x63,0xd6,0xd6,0xae,0xbc,0x64,0x4e,0xb5,0x99,0xfd,0xf9,0x8d,0xbd,0xcd,0x18,0xce,0x9b,0xd2,0xd9,0x0b,0x3a,0xc3,0x1f,0x13,0x9a,0xf8,0x32,0xcc,0xcf,0x6c,0xcb,0xbb,0x2c,0x6e,0xa1,0x1f,0xa9,0x73,0x70,0xdc,0x99,0x06,0xda,0x47,0x4d,0x7d,0x8a,0x75,0x67, + 0x04,0x85,0xa9,0x00,0xe9,0x78,0x58,0xf6,0x93,0xc0,0xb7,0xdf,0xa2,0x61,0xe3,0x80,0xda,0xd6,0xea,0x04,0x6d,0x1f,0x65,0xdd,0xee,0xed,0xd5,0xf7,0xd8,0xaf,0x0b,0xa3,0x37,0x69,0x74,0x4d,0x15,0xad,0xd4,0xf6,0xc0,0xbc,0x3b,0x0d,0xa2,0xae,0xc9,0x3b,0x34,0xcb,0x8c,0x65,0xf9,0x34,0x0d,0xdf,0x74,0xe7,0xb0,0x00,0x9e,0xee,0xcc,0xce,0x3c, + 0x04,0x38,0x06,0x6f,0x75,0xd8,0x8e,0xfc,0x4c,0x93,0xde,0x36,0xf4,0x9e,0x03,0x7b,0x23,0x4c,0xc1,0x8b,0x1d,0xe5,0x60,0x87,0x50,0xa6,0x2c,0xab,0x03,0x45,0x40,0x10,0x46,0xa3,0xe8,0x4b,0xed,0x8c,0xfc,0xb8,0x19,0xef,0x4d,0x55,0x04,0x44,0xf2,0xce,0x4b,0x65,0x17,0x66,0xb6,0x9e,0x2e,0x29,0x01,0xf8,0x88,0x36,0xff,0x90,0x03,0x4f,0xed, + 0x04,0x98,0xf6,0x81,0x77,0xdc,0x95,0xc1,0xb4,0xcb,0xfa,0x52,0x45,0x48,0x8c,0xa5,0x23,0xa7,0xd5,0x62,0x94,0x70,0xd0,0x35,0xd6,0x21,0xa4,0x43,0xc7,0x2f,0x39,0xaa,0xbf,0xa3,0x3d,0x29,0x54,0x6f,0xa1,0xc6,0x48,0xf2,0xc7,0xd5,0xcc,0xf7,0x0c,0xf1,0xce,0x4a,0xb7,0x9b,0x5d,0xb1,0xac,0x05,0x9d,0xbe,0xcd,0x06,0x8d,0xbd,0xff,0x1b,0x89, + 0x04,0x5c,0x2b,0xbf,0xa2,0x3c,0x9b,0x9a,0xd0,0x7f,0x03,0x8a,0xa8,0x9b,0x49,0x30,0xbf,0x26,0x7d,0x94,0x01,0xe4,0x25,0x5d,0xe9,0xe8,0xda,0x0a,0x50,0x78,0xec,0x82,0x77,0xe3,0xe8,0x82,0xa3,0x1d,0x5e,0x6a,0x37,0x9e,0x07,0x93,0x98,0x3c,0xcd,0xed,0x39,0xb9,0x5c,0x43,0x53,0xab,0x2f,0xf0,0x1e,0xa5,0x36,0x9b,0xa4,0x7b,0x0c,0x31,0x91, + 0x04,0x2e,0xa7,0x13,0x34,0x32,0x33,0x9c,0x69,0xd2,0x7f,0x9b,0x26,0x72,0x81,0xbd,0x2d,0xdd,0x5f,0x19,0xd6,0x33,0x8d,0x40,0x0a,0x05,0xcd,0x36,0x47,0xb1,0x57,0xa3,0x85,0x35,0x47,0x80,0x82,0x98,0x44,0x8e,0xdb,0x5e,0x70,0x1a,0xde,0x84,0xcd,0x5f,0xb1,0xac,0x95,0x67,0xba,0x5e,0x8f,0xb6,0x8a,0x6b,0x93,0x3e,0xc4,0xb5,0xcc,0x84,0xcc, + 0x04,0x2e,0xa7,0x13,0x34,0x32,0x33,0x9c,0x69,0xd2,0x7f,0x9b,0x26,0x72,0x81,0xbd,0x2d,0xdd,0x5f,0x19,0xd6,0x33,0x8d,0x40,0x0a,0x05,0xcd,0x36,0x47,0xb1,0x57,0xa3,0x85,0xca,0xb8,0x7f,0x7d,0x67,0xbb,0x71,0x24,0xa1,0x8f,0xe5,0x21,0x7b,0x32,0xa0,0x4e,0x53,0x6a,0x98,0x45,0xa1,0x70,0x49,0x75,0x94,0x6c,0xc1,0x3a,0x4a,0x33,0x77,0x63, + 0x04,0x8a,0xa2,0xc6,0x4f,0xa9,0xc6,0x43,0x75,0x63,0xab,0xfb,0xcb,0xd0,0x0b,0x20,0x48,0xd4,0x8c,0x18,0xc1,0x52,0xa2,0xa6,0xf4,0x90,0x36,0xde,0x76,0x47,0xeb,0xe8,0x2e,0x1c,0xe6,0x43,0x87,0x99,0x5c,0x68,0xa0,0x60,0xfa,0x3b,0xc0,0x39,0x9b,0x05,0xcc,0x06,0xee,0xc7,0xd5,0x98,0xf7,0x50,0x41,0xa4,0x91,0x7e,0x69,0x2b,0x7f,0x51,0xff, + 0x04,0x39,0x14,0x27,0xff,0x7e,0xe7,0x80,0x13,0xc1,0x4a,0xec,0x7d,0x96,0xa8,0xa0,0x62,0x20,0x92,0x98,0xa7,0x83,0x83,0x5e,0x94,0xfd,0x65,0x49,0xd5,0x02,0xff,0xf7,0x1f,0xdd,0x66,0x24,0xec,0x34,0x3a,0xd9,0xfc,0xf4,0xd9,0x87,0x21,0x81,0xe5,0x9f,0x84,0x2f,0x9b,0xa4,0xcc,0xca,0xe0,0x9a,0x6c,0x09,0x72,0xfb,0x6a,0xc6,0xb4,0xc6,0xbd, + 0x04,0xe7,0x62,0xb8,0xa2,0x19,0xb4,0xf1,0x80,0x21,0x9c,0xc7,0xa9,0x05,0x92,0x45,0xe4,0x96,0x1b,0xd1,0x91,0xc0,0x38,0x99,0x78,0x9c,0x7a,0x34,0xb8,0x9e,0x8c,0x13,0x8e,0xc1,0x53,0x3e,0xf0,0x41,0x9b,0xb7,0x37,0x6e,0x0b,0xfd,0xe9,0x31,0x9d,0x10,0xa0,0x69,0x68,0x79,0x1d,0x9e,0xa0,0xee,0xd9,0xc1,0xce,0x63,0x45,0xae,0xd9,0x75,0x9e, + 0x04,0x9a,0xed,0xb0,0xd2,0x81,0xdb,0x16,0x4e,0x13,0x00,0x00,0xc5,0x69,0x7f,0xae,0x0f,0x30,0x5e,0xf8,0x48,0xbe,0x6f,0xff,0xb4,0x3a,0xc5,0x93,0xfb,0xb9,0x50,0xe9,0x52,0xfa,0x6f,0x63,0x33,0x59,0xbd,0xcd,0x82,0xb5,0x6b,0x0b,0x9f,0x96,0x5b,0x03,0x77,0x89,0xd4,0x6b,0x9a,0x81,0x41,0xb7,0x91,0xb2,0xae,0xfa,0x71,0x3f,0x96,0xc1,0x75, + 0x04,0x8a,0xd4,0x45,0xdb,0x62,0x81,0x62,0x60,0xe4,0xe6,0x87,0xfd,0x18,0x84,0xe4,0x8b,0x9f,0xc0,0x63,0x6d,0x03,0x15,0x47,0xd6,0x33,0x15,0xe7,0x92,0xe1,0x9b,0xfa,0xee,0x1d,0xe6,0x4f,0x99,0xd5,0xf1,0xcd,0x8b,0x6e,0xc9,0xcb,0x0f,0x78,0x7a,0x65,0x4a,0xe8,0x69,0x93,0xba,0x3d,0xb1,0x00,0x8e,0xf4,0x3c,0xff,0x06,0x84,0xcb,0x22,0xbd, + 0x04,0x1f,0x57,0x99,0xc9,0x5b,0xe8,0x90,0x63,0xb2,0x4f,0x26,0xe4,0x0c,0xb9,0x28,0xc1,0xa8,0x68,0xa7,0x6f,0xb0,0x09,0x46,0x07,0xe8,0x04,0x3d,0xb4,0x09,0xc9,0x1c,0x32,0xe7,0x57,0x24,0xe8,0x13,0xa4,0x19,0x1e,0x3a,0x83,0x90,0x07,0xf0,0x8e,0x2e,0x89,0x73,0x88,0xb0,0x6d,0x4a,0x00,0xde,0x6d,0xe6,0x0e,0x53,0x6d,0x91,0xfa,0xb5,0x66, + 0x04,0xa3,0x33,0x1a,0x4e,0x1b,0x42,0x23,0xec,0x2c,0x02,0x7e,0xdd,0x48,0x2c,0x92,0x8a,0x14,0xed,0x35,0x8d,0x93,0xf1,0xd4,0x21,0x7d,0x39,0xab,0xf6,0x9f,0xcb,0x5c,0xcc,0x28,0xd6,0x84,0xd2,0xaa,0xab,0xcd,0x63,0x83,0x77,0x5c,0xaa,0x62,0x39,0xde,0x26,0xd4,0xc6,0x93,0x7b,0xb6,0x03,0xec,0xb4,0x19,0x60,0x82,0xf4,0xcf,0xfd,0x50,0x9d, + 0x04,0x3f,0x39,0x52,0x19,0x97,0x74,0xc7,0xcf,0x39,0xb3,0x8b,0x66,0xcb,0x10,0x42,0xa6,0x26,0x0d,0x86,0x80,0x80,0x38,0x45,0xe4,0xd4,0x33,0xad,0xba,0x3b,0xb2,0x48,0x18,0x5e,0xa4,0x95,0xb6,0x8c,0xbc,0x7e,0xd4,0x17,0x3e,0xe6,0x3c,0x90,0x42,0xdc,0x50,0x26,0x25,0xc7,0xeb,0x7e,0x21,0xfb,0x02,0xca,0x9a,0x91,0x14,0xe0,0xa3,0xa1,0x8d, + 0x04,0xcd,0xfb,0x8c,0x0f,0x42,0x2e,0x14,0x4e,0x13,0x7c,0x24,0x12,0xc8,0x6c,0x17,0x1f,0x5f,0xe3,0xfa,0x3f,0x5b,0xbb,0x54,0x4e,0x90,0x76,0x28,0x8f,0x3c,0xed,0x78,0x6e,0x05,0x4f,0xd0,0x72,0x1b,0x77,0xc1,0x1c,0x79,0xbe,0xac,0xb3,0xc9,0x42,0x11,0xb0,0xa1,0x9b,0xda,0x08,0x65,0x2e,0xfe,0xaf,0x92,0x51,0x3a,0x3b,0x0a,0x16,0x36,0x98, + 0x04,0x73,0x59,0x8a,0x6a,0x1c,0x68,0x27,0x8f,0xa6,0xbf,0xd0,0xce,0x40,0x64,0xe6,0x82,0x35,0xbc,0x1c,0x0f,0x6b,0x20,0xa9,0x28,0x10,0x8b,0xe3,0x36,0x73,0x0f,0x87,0xe3,0xcb,0xae,0x61,0x25,0x19,0xb5,0x03,0x2e,0xcc,0x85,0xae,0xd8,0x11,0x27,0x1a,0x95,0xfe,0x79,0x39,0xd5,0xd3,0x46,0x01,0x40,0xba,0x31,0x8f,0x4d,0x14,0xab,0xa3,0x1d, + 0x04,0x58,0xde,0xbd,0x9a,0x7e,0xe2,0xc9,0xd5,0x91,0x32,0x47,0x8a,0x54,0x40,0xae,0x4d,0x5d,0x7e,0xd4,0x37,0x30,0x83,0x69,0xf9,0x2e,0xa8,0x6c,0x82,0x18,0x3f,0x10,0xa1,0x67,0x73,0xe7,0x6f,0x5e,0xdb,0xf4,0xda,0x0e,0x4f,0x1b,0xdf,0xfa,0xc0,0xf5,0x72,0x57,0xe1,0xdf,0xa4,0x65,0x84,0x29,0x31,0x30,0x9a,0x24,0x24,0x5f,0xda,0x6a,0x5d, + 0x04,0x8b,0x90,0x4d,0xe4,0x79,0x67,0x34,0x0c,0x5f,0x8c,0x35,0x72,0xa7,0x20,0x92,0x4e,0xf7,0x57,0x86,0x37,0xfe,0xab,0x19,0x49,0xac,0xb2,0x41,0xa5,0xa6,0xac,0x3f,0x5b,0x95,0x09,0x04,0x49,0x6f,0x98,0x24,0xb1,0xd6,0x3f,0x33,0x13,0xba,0xe2,0x1b,0x89,0xfa,0xe8,0x9a,0xfd,0xfc,0x81,0x1b,0x5e,0xce,0x03,0xfd,0x5a,0xa3,0x01,0x86,0x4f, + 0x04,0xf4,0x89,0x2b,0x6d,0x52,0x5c,0x77,0x1e,0x03,0x5f,0x2a,0x25,0x27,0x08,0xf3,0x78,0x4e,0x48,0x23,0x86,0x04,0xb4,0xf9,0x4d,0xc5,0x6e,0xaa,0x1e,0x54,0x6d,0x94,0x1a,0x34,0x6b,0x1a,0xa0,0xbc,0xe6,0x8b,0x1c,0x50,0xe5,0xb5,0x2f,0x50,0x9f,0xb5,0x52,0x2e,0x5c,0x25,0xe0,0x28,0xbc,0x8f,0x86,0x34,0x02,0xed,0xb7,0xbc,0xad,0x8b,0x1b, + 0x04,0x79,0xbe,0x66,0x7e,0xf9,0xdc,0xbb,0xac,0x55,0xa0,0x62,0x95,0xce,0x87,0x0b,0x07,0x02,0x9b,0xfc,0xdb,0x2d,0xce,0x28,0xd9,0x59,0xf2,0x81,0x5b,0x16,0xf8,0x17,0x98,0x48,0x3a,0xda,0x77,0x26,0xa3,0xc4,0x65,0x5d,0xa4,0xfb,0xfc,0x0e,0x11,0x08,0xa8,0xfd,0x17,0xb4,0x48,0xa6,0x85,0x54,0x19,0x9c,0x47,0xd0,0x8f,0xfb,0x10,0xd4,0xb8, + 0x04,0x79,0xbe,0x66,0x7e,0xf9,0xdc,0xbb,0xac,0x55,0xa0,0x62,0x95,0xce,0x87,0x0b,0x07,0x02,0x9b,0xfc,0xdb,0x2d,0xce,0x28,0xd9,0x59,0xf2,0x81,0x5b,0x16,0xf8,0x17,0x98,0xb7,0xc5,0x25,0x88,0xd9,0x5c,0x3b,0x9a,0xa2,0x5b,0x04,0x03,0xf1,0xee,0xf7,0x57,0x02,0xe8,0x4b,0xb7,0x59,0x7a,0xab,0xe6,0x63,0xb8,0x2f,0x6f,0x04,0xef,0x27,0x77, + 0x04,0x78,0x2c,0x8e,0xd1,0x7e,0x3b,0x2a,0x78,0x3b,0x54,0x64,0xf3,0x3b,0x09,0x65,0x2a,0x71,0xc6,0x78,0xe0,0x5e,0xc5,0x1e,0x84,0xe2,0xbc,0xfc,0x66,0x3a,0x3d,0xe9,0x63,0xaf,0x9a,0xcb,0x42,0x80,0xb8,0xc7,0xf7,0xc4,0x2f,0x4e,0xf9,0xab,0xa6,0x24,0x5e,0xc1,0xec,0x17,0x12,0xfd,0x38,0xa0,0xfa,0x96,0x41,0x8d,0x8c,0xd6,0xaa,0x61,0x52, + 0x04,0x6e,0x82,0x35,0x55,0x45,0x29,0x14,0x09,0x91,0x82,0xc6,0xb2,0xc1,0xd6,0xf0,0xb5,0xd2,0x8d,0x50,0xcc,0xd0,0x05,0xaf,0x2c,0xe1,0xbb,0xa5,0x41,0xaa,0x40,0xca,0xff,0x00,0x00,0x00,0x01,0x06,0x04,0x92,0xd5,0xa5,0x67,0x3e,0x0f,0x25,0xd8,0xd5,0x0f,0xb7,0xe5,0x8c,0x49,0xd8,0x6d,0x46,0xd4,0x21,0x69,0x55,0xe0,0xaa,0x3d,0x40,0xe1, + 0x04,0x6e,0x82,0x35,0x55,0x45,0x29,0x14,0x09,0x91,0x82,0xc6,0xb2,0xc1,0xd6,0xf0,0xb5,0xd2,0x8d,0x50,0xcc,0xd0,0x05,0xaf,0x2c,0xe1,0xbb,0xa5,0x41,0xaa,0x40,0xca,0xff,0xff,0xff,0xff,0xfe,0xf9,0xfb,0x6d,0x2a,0x5a,0x98,0xc1,0xf0,0xda,0x27,0x2a,0xf0,0x48,0x1a,0x73,0xb6,0x27,0x92,0xb9,0x2b,0xde,0x96,0xaa,0x1e,0x55,0xc2,0xbb,0x4e, + 0x04,0x00,0x00,0x00,0x01,0x3f,0xd2,0x22,0x48,0xd6,0x4d,0x95,0xf7,0x3c,0x29,0xb4,0x8a,0xb4,0x86,0x31,0x85,0x0b,0xe5,0x03,0xfd,0x00,0xf8,0x46,0x8b,0x5f,0x0f,0x70,0xe0,0xf6,0xee,0x7a,0xa4,0x3b,0xc2,0xc6,0xfd,0x25,0xb1,0xd8,0x26,0x92,0x41,0xcb,0xdd,0x9d,0xbb,0x0d,0xac,0x96,0xdc,0x96,0x23,0x1f,0x43,0x07,0x05,0xf8,0x38,0x71,0x7d, + 0x04,0x25,0xaf,0xd6,0x89,0xac,0xab,0xae,0xd6,0x7c,0x1f,0x29,0x6d,0xe5,0x94,0x06,0xf8,0xc5,0x50,0xf5,0x71,0x46,0xa0,0xb4,0xec,0x2c,0x97,0x87,0x6d,0xff,0xff,0xff,0xff,0xfa,0x46,0xa7,0x6e,0x52,0x03,0x22,0xdf,0xbc,0x49,0x1e,0xc4,0xf0,0xcc,0x19,0x74,0x20,0xfc,0x4e,0xa5,0x88,0x3d,0x8f,0x6d,0xd5,0x3c,0x35,0x4b,0xc4,0xf6,0x7c,0x35, + 0x04,0xd1,0x2e,0x6c,0x66,0xb6,0x77,0x34,0xc3,0xc8,0x4d,0x26,0x01,0xcf,0x5d,0x35,0xdc,0x09,0x7e,0x27,0x63,0x7f,0x0a,0xca,0x4a,0x4f,0xdb,0x74,0xb6,0xaa,0xdd,0x3b,0xb9,0x3f,0x5b,0xdf,0xf8,0x8b,0xd5,0x73,0x6d,0xf8,0x98,0xe6,0x99,0x00,0x6e,0xd7,0x50,0xf1,0x1c,0xf0,0x7c,0x58,0x66,0xcd,0x7a,0xd7,0x0c,0x71,0x21,0xff,0xff,0xff,0xff, + 0x04,0x6d,0x4a,0x7f,0x60,0xd4,0x77,0x4a,0x4f,0x0a,0xa8,0xbb,0xde,0xdb,0x95,0x3c,0x7e,0xea,0x79,0x09,0x40,0x7e,0x31,0x64,0x75,0x56,0x64,0xbc,0x28,0x00,0x00,0x00,0x00,0xe6,0x59,0xd3,0x4e,0x4d,0xf3,0x8d,0x9e,0x8c,0x9e,0xaa,0xdf,0xba,0x36,0x61,0x2c,0x76,0x91,0x95,0xbe,0x86,0xc7,0x7a,0xac,0x3f,0x36,0xe7,0x8b,0x53,0x86,0x80,0xfb}; + +static const unsigned char wycheproof_ecdsa_signatures[] = { 0x30,0x46,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x21,0x00,0x90,0x0e,0x75,0xad,0x23,0x3f,0xcc,0x90,0x85,0x09,0xdb,0xff,0x59,0x22,0x64,0x7d,0xb3,0x7c,0x21,0xf4,0xaf,0xd3,0x20,0x3a,0xe8,0xdc,0x4a,0xe7,0x79,0x4b,0x0f,0x87, + 0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x81,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x82,0x00,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x46,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x44,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x85,0x01,0x00,0x00,0x00,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x89,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x84,0x7f,0xff,0xff,0xff,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x84,0x80,0x00,0x00,0x00,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x84,0xff,0xff,0xff,0xff,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x85,0xff,0xff,0xff,0xff,0xff,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x88,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0xff,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x80,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30, + 0x30,0x47,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x00,0x00, + 0x30,0x47,0x00,0x00,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x00,0x00, + 0x30,0x47,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x05,0x00, + 0x30,0x4a,0x49,0x81,0x77,0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x49,0x25,0x00,0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x47,0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x00,0x04,0xde,0xad,0xbe,0xef, + 0x30,0x4d,0xaa,0x00,0xbb,0x00,0xcd,0x00,0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x4d,0x22,0x29,0xaa,0x00,0xbb,0x00,0xcd,0x00,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x4d,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x22,0x28,0xaa,0x00,0xbb,0x00,0xcd,0x00,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x81, + 0x30,0x4b,0xaa,0x02,0xaa,0xbb,0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x80,0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x00,0x00, + 0x30,0x80,0x31,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x00,0x00, + 0x05,0x00, + 0x2e,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x2f,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x31,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x32,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0xff,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x00, + 0x30,0x49,0x30,0x01,0x02,0x30,0x44,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x44,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31, + 0x30,0x44,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x82,0x10,0x46,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x30,0x80,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x00,0x00, + 0x30,0x80,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x00, + 0x30,0x80,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x05,0x00,0x00,0x00, + 0x30,0x80,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x06,0x08,0x11,0x22,0x00,0x00, + 0x30,0x80,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x00,0x00,0xfe,0x02,0xbe,0xef, + 0x30,0x80,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x00,0x02,0xbe,0xef, + 0x30,0x47,0x30,0x00,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x47,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x30,0x00, + 0x30,0x48,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x02,0x01,0x00, + 0x30,0x48,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0xbf,0x7f,0x00, + 0x30,0x49,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0xa0,0x02,0x05,0x00, + 0x30,0x47,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0xa0,0x00, + 0x30,0x47,0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x23,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65, + 0x30,0x67,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x43,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x64,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x43,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xca,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x43,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x13,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x43,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x08,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x46,0x02,0x81,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x47,0x02,0x82,0x00,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x22,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x20,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x4a,0x02,0x85,0x01,0x00,0x00,0x00,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x4e,0x02,0x89,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x49,0x02,0x84,0x7f,0xff,0xff,0xff,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x49,0x02,0x84,0x80,0x00,0x00,0x00,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x49,0x02,0x84,0xff,0xff,0xff,0xff,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x4a,0x02,0x85,0xff,0xff,0xff,0xff,0xff,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x4d,0x02,0x88,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0xff,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x80,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x22,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x23,0x02,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x24,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02, + 0x30,0x47,0x02,0x23,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x00,0x00,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x47,0x02,0x23,0x00,0x00,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x47,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x00,0x00,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x47,0x02,0x23,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x05,0x00,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x4a,0x22,0x26,0x49,0x81,0x77,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x49,0x22,0x25,0x25,0x00,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x4d,0x22,0x23,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x00,0x04,0xde,0xad,0xbe,0xef,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x24,0x02,0x81,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x4b,0x22,0x27,0xaa,0x02,0xaa,0xbb,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x49,0x22,0x80,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x00,0x00,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x49,0x22,0x80,0x03,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x00,0x00,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x24,0x05,0x00,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x00,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x01,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x03,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x04,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0xff,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x24,0x02,0x00,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x49,0x22,0x25,0x02,0x01,0x00,0x02,0x20,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0x02,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0xe5,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x44,0x02,0x20,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x44,0x02,0x20,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x82,0x10,0x48,0x02,0x82,0x10,0x22,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x46,0x02,0x22,0xff,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x25,0x09,0x01,0x80,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x25,0x02,0x01,0x00,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x43,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xbb, + 0x30,0x43,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa4,0x56,0xeb,0x31,0xba, + 0x30,0x43,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf7,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x43,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x01,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x46,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x81,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x47,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x82,0x00,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x21,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x1f,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x4a,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x85,0x01,0x00,0x00,0x00,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x4e,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x89,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x49,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x84,0x7f,0xff,0xff,0xff,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x49,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x84,0x80,0x00,0x00,0x00,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x49,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x84,0xff,0xff,0xff,0xff,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x4a,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x85,0xff,0xff,0xff,0xff,0xff,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x4d,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x88,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0xff,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x80,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x47,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x22,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x00,0x00, + 0x30,0x47,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x22,0x00,0x00,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x47,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x22,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x05,0x00, + 0x30,0x4a,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x22,0x25,0x49,0x81,0x77,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x49,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x22,0x24,0x25,0x00,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x4d,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x22,0x22,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x00,0x04,0xde,0xad,0xbe,0xef, + 0x30,0x25,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x81, + 0x30,0x4b,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x22,0x26,0xaa,0x02,0xaa,0xbb,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x49,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x22,0x80,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x00,0x00, + 0x30,0x49,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x22,0x80,0x03,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x00,0x00, + 0x30,0x25,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x05,0x00, + 0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x00,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x01,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x03,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x04,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0xff,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x25,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x00, + 0x30,0x49,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x22,0x24,0x02,0x01,0x6f,0x02,0x1f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6d,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0x3a, + 0x30,0x44,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x1f,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31, + 0x30,0x44,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x1f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x82,0x10,0x48,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x82,0x10,0x21,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x30,0x46,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x21,0xff,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x26,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x09,0x01,0x80, + 0x30,0x26,0x02,0x21,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x01,0x00, + 0x30,0x45,0x02,0x21,0x01,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x83,0xb9,0x0d,0xea,0xbc,0xa4,0xb0,0x5c,0x45,0x74,0xe4,0x9b,0x58,0x99,0xb9,0x64,0xa6,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x44,0x02,0x20,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x86,0x43,0xb0,0x30,0xef,0x46,0x1f,0x1b,0xcd,0xf5,0x3f,0xde,0x3e,0xf9,0x4c,0xe2,0x24,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x46,0x02,0x22,0x01,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x84,0x3f,0xad,0x3b,0xf4,0x85,0x3e,0x07,0xf7,0xc9,0x87,0x70,0xc9,0x9b,0xff,0xc4,0x64,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0xff,0x7e,0xc1,0x08,0x63,0x31,0x05,0x65,0xa9,0x08,0x45,0x7f,0xa0,0xf1,0xb8,0x7a,0x7b,0x01,0xa0,0xf2,0x2a,0x0a,0x98,0x43,0xf6,0x4a,0xed,0xc3,0x34,0x36,0x7c,0xdc,0x9b,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x44,0x02,0x20,0x7e,0xc1,0x08,0x63,0x31,0x05,0x65,0xa9,0x08,0x45,0x7f,0xa0,0xf1,0xb8,0x7a,0x79,0xbc,0x4f,0xcf,0x10,0xb9,0xe0,0xe4,0x32,0x0a,0xc0,0x21,0xc1,0x06,0xb3,0x1d,0xdc,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0xfe,0x7e,0xc1,0x08,0x63,0x31,0x05,0x65,0xa9,0x08,0x45,0x7f,0xa0,0xf1,0xb8,0x7a,0x7c,0x46,0xf2,0x15,0x43,0x5b,0x4f,0xa3,0xba,0x8b,0x1b,0x64,0xa7,0x66,0x46,0x9b,0x5a,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0x01,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x4d,0x02,0x29,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x81,0x3e,0xf7,0x9c,0xce,0xfa,0x9a,0x56,0xf7,0xba,0x80,0x5f,0x0e,0x47,0x85,0x84,0xfe,0x5f,0x0d,0xd5,0xf5,0x67,0xbc,0x09,0xb5,0x12,0x3c,0xcb,0xc9,0x83,0x23,0x65,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0x01,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x7f,0xc1,0xe1,0x97,0xd8,0xae,0xbe,0x20,0x3c,0x96,0xc8,0x72,0x32,0x27,0x21,0x72,0xfb,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0xff,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x82,0x4c,0x83,0xde,0x0b,0x50,0x2c,0xdf,0xc5,0x17,0x23,0xb5,0x18,0x86,0xb4,0xf0,0x79,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x46,0x02,0x22,0x01,0x00,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9a,0x3b,0xb6,0x0f,0xa1,0xa1,0x48,0x15,0xbb,0xc0,0xa9,0x54,0xa0,0x75,0x8d,0x2c,0x72,0xba,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x44,0x02,0x20,0x90,0x0e,0x75,0xad,0x23,0x3f,0xcc,0x90,0x85,0x09,0xdb,0xff,0x59,0x22,0x64,0x7e,0xf8,0xcd,0x45,0x0e,0x00,0x8a,0x7f,0xff,0x29,0x09,0xec,0x5a,0xa9,0x14,0xce,0x46,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0xfe,0x90,0x0e,0x75,0xad,0x23,0x3f,0xcc,0x90,0x85,0x09,0xdb,0xff,0x59,0x22,0x64,0x80,0x3e,0x1e,0x68,0x27,0x51,0x41,0xdf,0xc3,0x69,0x37,0x8d,0xcd,0xd8,0xde,0x8d,0x05,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0x01,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x45,0x02,0x21,0xff,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x4d,0x02,0x29,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba,0x02,0x20,0x6f,0xf1,0x8a,0x52,0xdc,0xc0,0x33,0x6f,0x7a,0xf6,0x24,0x00,0xa6,0xdd,0x9b,0x81,0x07,0x32,0xba,0xf1,0xff,0x75,0x80,0x00,0xd6,0xf6,0x13,0xa5,0x56,0xeb,0x31,0xba, + 0x30,0x06,0x02,0x01,0x00,0x02,0x01,0x00, + 0x30,0x06,0x02,0x01,0x00,0x02,0x01,0x01, + 0x30,0x06,0x02,0x01,0x00,0x02,0x01,0xff, + 0x30,0x26,0x02,0x01,0x00,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41, + 0x30,0x26,0x02,0x01,0x00,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x40, + 0x30,0x26,0x02,0x01,0x00,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x42, + 0x30,0x26,0x02,0x01,0x00,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f, + 0x30,0x26,0x02,0x01,0x00,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x30, + 0x30,0x06,0x02,0x01,0x01,0x02,0x01,0x00, + 0x30,0x06,0x02,0x01,0x01,0x02,0x01,0x01, + 0x30,0x06,0x02,0x01,0x01,0x02,0x01,0xff, + 0x30,0x26,0x02,0x01,0x01,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41, + 0x30,0x26,0x02,0x01,0x01,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x40, + 0x30,0x26,0x02,0x01,0x01,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x42, + 0x30,0x26,0x02,0x01,0x01,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f, + 0x30,0x26,0x02,0x01,0x01,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x30, + 0x30,0x06,0x02,0x01,0xff,0x02,0x01,0x00, + 0x30,0x06,0x02,0x01,0xff,0x02,0x01,0x01, + 0x30,0x06,0x02,0x01,0xff,0x02,0x01,0xff, + 0x30,0x26,0x02,0x01,0xff,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41, + 0x30,0x26,0x02,0x01,0xff,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x40, + 0x30,0x26,0x02,0x01,0xff,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x42, + 0x30,0x26,0x02,0x01,0xff,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f, + 0x30,0x26,0x02,0x01,0xff,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x30, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41,0x02,0x01,0x00, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41,0x02,0x01,0x01, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41,0x02,0x01,0xff, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x40, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x42, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x30, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x40,0x02,0x01,0x00, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x40,0x02,0x01,0x01, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x40,0x02,0x01,0xff, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x40,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x40,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x40, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x40,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x42, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x40,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x40,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x30, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x42,0x02,0x01,0x00, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x42,0x02,0x01,0x01, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x42,0x02,0x01,0xff, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x42,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x42,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x40, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x42,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x42, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x42,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x42,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x30, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f,0x02,0x01,0x00, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f,0x02,0x01,0x01, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f,0x02,0x01,0xff, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x40, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x42, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x30, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x30,0x02,0x01,0x00, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x30,0x02,0x01,0x01, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x30,0x02,0x01,0xff, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x30,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x30,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x40, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x30,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x42, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x30,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f, + 0x30,0x46,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x30,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x30, + 0x30,0x08,0x02,0x01,0x00,0x09,0x03,0x80,0xfe,0x01, + 0x30,0x06,0x02,0x01,0x00,0x09,0x01,0x42, + 0x30,0x06,0x02,0x01,0x00,0x01,0x01,0x01, + 0x30,0x06,0x02,0x01,0x00,0x01,0x01,0x00, + 0x30,0x05,0x02,0x01,0x00,0x05,0x00, + 0x30,0x05,0x02,0x01,0x00,0x0c,0x00, + 0x30,0x06,0x02,0x01,0x00,0x0c,0x01,0x30, + 0x30,0x05,0x02,0x01,0x00,0x30,0x00, + 0x30,0x08,0x02,0x01,0x00,0x30,0x03,0x02,0x01,0x00, + 0x30,0x08,0x02,0x01,0x01,0x09,0x03,0x80,0xfe,0x01, + 0x30,0x06,0x02,0x01,0x01,0x09,0x01,0x42, + 0x30,0x06,0x02,0x01,0x01,0x01,0x01,0x01, + 0x30,0x06,0x02,0x01,0x01,0x01,0x01,0x00, + 0x30,0x05,0x02,0x01,0x01,0x05,0x00, + 0x30,0x05,0x02,0x01,0x01,0x0c,0x00, + 0x30,0x06,0x02,0x01,0x01,0x0c,0x01,0x30, + 0x30,0x05,0x02,0x01,0x01,0x30,0x00, + 0x30,0x08,0x02,0x01,0x01,0x30,0x03,0x02,0x01,0x00, + 0x30,0x08,0x02,0x01,0xff,0x09,0x03,0x80,0xfe,0x01, + 0x30,0x06,0x02,0x01,0xff,0x09,0x01,0x42, + 0x30,0x06,0x02,0x01,0xff,0x01,0x01,0x01, + 0x30,0x06,0x02,0x01,0xff,0x01,0x01,0x00, + 0x30,0x05,0x02,0x01,0xff,0x05,0x00, + 0x30,0x05,0x02,0x01,0xff,0x0c,0x00, + 0x30,0x06,0x02,0x01,0xff,0x0c,0x01,0x30, + 0x30,0x05,0x02,0x01,0xff,0x30,0x00, + 0x30,0x08,0x02,0x01,0xff,0x30,0x03,0x02,0x01,0x00, + 0x30,0x28,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41,0x09,0x03,0x80,0xfe,0x01, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41,0x09,0x01,0x42, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41,0x01,0x01,0x01, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41,0x01,0x01,0x00, + 0x30,0x25,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41,0x05,0x00, + 0x30,0x25,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41,0x0c,0x00, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41,0x0c,0x01,0x30, + 0x30,0x25,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41,0x30,0x00, + 0x30,0x28,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x41,0x30,0x03,0x02,0x01,0x00, + 0x30,0x28,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f,0x09,0x03,0x80,0xfe,0x01, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f,0x09,0x01,0x42, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f,0x01,0x01,0x01, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f,0x01,0x01,0x00, + 0x30,0x25,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f,0x05,0x00, + 0x30,0x25,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f,0x0c,0x00, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f,0x0c,0x01,0x30, + 0x30,0x25,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f,0x30,0x00, + 0x30,0x28,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2f,0x30,0x03,0x02,0x01,0x00, + 0x30,0x0a,0x09,0x03,0x80,0xfe,0x01,0x09,0x03,0x80,0xfe,0x01, + 0x30,0x06,0x09,0x01,0x42,0x09,0x01,0x42, + 0x30,0x06,0x01,0x01,0x01,0x01,0x01,0x01, + 0x30,0x06,0x01,0x01,0x00,0x01,0x01,0x00, + 0x30,0x04,0x05,0x00,0x05,0x00, + 0x30,0x04,0x0c,0x00,0x0c,0x00, + 0x30,0x06,0x0c,0x01,0x30,0x0c,0x01,0x30, + 0x30,0x04,0x30,0x00,0x30,0x00, + 0x30,0x0a,0x30,0x03,0x02,0x01,0x00,0x30,0x03,0x02,0x01,0x00, + 0x30,0x08,0x09,0x03,0x80,0xfe,0x01,0x02,0x01,0x00, + 0x30,0x06,0x09,0x01,0x42,0x02,0x01,0x00, + 0x30,0x06,0x01,0x01,0x01,0x02,0x01,0x00, + 0x30,0x06,0x01,0x01,0x00,0x02,0x01,0x00, + 0x30,0x05,0x05,0x00,0x02,0x01,0x00, + 0x30,0x05,0x0c,0x00,0x02,0x01,0x00, + 0x30,0x06,0x0c,0x01,0x30,0x02,0x01,0x00, + 0x30,0x05,0x30,0x00,0x02,0x01,0x00, + 0x30,0x08,0x30,0x03,0x02,0x01,0x00,0x02,0x01,0x00, + 0x30,0x45,0x02,0x21,0x00,0xdd,0x1b,0x7d,0x09,0xa7,0xbd,0x82,0x18,0x96,0x10,0x34,0xa3,0x9a,0x87,0xfe,0xcf,0x53,0x14,0xf0,0x0c,0x4d,0x25,0xeb,0x58,0xa0,0x7a,0xc8,0x5e,0x85,0xea,0xb5,0x16,0x02,0x20,0x35,0x13,0x8c,0x40,0x1e,0xf8,0xd3,0x49,0x3d,0x65,0xc9,0x00,0x2f,0xe6,0x2b,0x43,0xae,0xe5,0x68,0x73,0x1b,0x74,0x45,0x48,0x35,0x89,0x96,0xd9,0xcc,0x42,0x7e,0x06, + 0x30,0x45,0x02,0x21,0x00,0x95,0xc2,0x92,0x67,0xd9,0x72,0xa0,0x43,0xd9,0x55,0x22,0x45,0x46,0x22,0x2b,0xba,0x34,0x3f,0xc1,0xd4,0xdb,0x0f,0xec,0x26,0x2a,0x33,0xac,0x61,0x30,0x56,0x96,0xae,0x02,0x20,0x6e,0xdf,0xe9,0x67,0x13,0xae,0xd5,0x6f,0x8a,0x28,0xa6,0x65,0x3f,0x57,0xe0,0xb8,0x29,0x71,0x2e,0x5e,0xdd,0xc6,0x7f,0x34,0x68,0x2b,0x24,0xf0,0x67,0x6b,0x26,0x40, + 0x30,0x44,0x02,0x20,0x28,0xf9,0x4a,0x89,0x4e,0x92,0x02,0x46,0x99,0xe3,0x45,0xfe,0x66,0x97,0x1e,0x3e,0xdc,0xd0,0x50,0x02,0x33,0x86,0x13,0x5a,0xb3,0x93,0x9d,0x55,0x08,0x98,0xfb,0x25,0x02,0x20,0x32,0x96,0x3e,0x5b,0xd4,0x1f,0xa5,0x91,0x1e,0xd8,0xf3,0x7d,0xeb,0x86,0xda,0xe0,0xa7,0x62,0xbb,0x61,0x21,0xc8,0x94,0x61,0x50,0x83,0xc5,0xd9,0x5e,0xa0,0x1d,0xb3, + 0x30,0x45,0x02,0x21,0x00,0xbe,0x26,0xb1,0x8f,0x95,0x49,0xf8,0x9f,0x41,0x1a,0x9b,0x52,0x53,0x6b,0x15,0xaa,0x27,0x0b,0x84,0x54,0x8d,0x0e,0x85,0x9a,0x19,0x52,0xa2,0x7a,0xf1,0xa7,0x7a,0xc6,0x02,0x20,0x70,0xc1,0xd4,0xfa,0x9c,0xd0,0x3c,0xc8,0xea,0xa8,0xd5,0x06,0xed,0xb9,0x7e,0xed,0x7b,0x83,0x58,0xb4,0x53,0xc8,0x8a,0xef,0xbb,0x88,0x0a,0x3f,0x0e,0x8d,0x47,0x2f, + 0x30,0x45,0x02,0x21,0x00,0xb1,0xa4,0xb1,0x47,0x8e,0x65,0xcc,0x3e,0xaf,0xdf,0x22,0x5d,0x12,0x98,0xb4,0x3f,0x2d,0xa1,0x9e,0x4b,0xcf,0xf7,0xea,0xcc,0x0a,0x2e,0x98,0xcd,0x4b,0x74,0xb1,0x14,0x02,0x20,0x17,0x9a,0xa3,0x1e,0x30,0x4c,0xc1,0x42,0xcf,0x50,0x73,0x17,0x17,0x51,0xb2,0x8f,0x3f,0x5e,0x0f,0xa8,0x8c,0x99,0x4e,0x7c,0x55,0xf1,0xbc,0x07,0xb8,0xd5,0x6c,0x16, + 0x30,0x44,0x02,0x20,0x32,0x53,0x32,0x02,0x12,0x61,0xf1,0xbd,0x18,0xf2,0x71,0x2a,0xa1,0xe2,0x25,0x2d,0xa2,0x37,0x96,0xda,0x8a,0x4b,0x1f,0xf6,0xea,0x18,0xca,0xfe,0xc7,0xe1,0x71,0xf2,0x02,0x20,0x40,0xb4,0xf5,0xe2,0x87,0xee,0x61,0xfc,0x3c,0x80,0x41,0x86,0x98,0x23,0x60,0x89,0x1e,0xaa,0x35,0xc7,0x5f,0x05,0xa4,0x3e,0xcd,0x48,0xb3,0x5d,0x98,0x4a,0x66,0x48, + 0x30,0x45,0x02,0x21,0x00,0xa2,0x3a,0xd1,0x8d,0x8f,0xc6,0x6d,0x81,0xaf,0x09,0x03,0x89,0x0c,0xbd,0x45,0x3a,0x55,0x4c,0xb0,0x4c,0xdc,0x1a,0x8c,0xa7,0xf7,0xf7,0x8e,0x53,0x67,0xed,0x88,0xa0,0x02,0x20,0x23,0xe3,0xeb,0x2c,0xe1,0xc0,0x4e,0xa7,0x48,0xc3,0x89,0xbd,0x97,0x37,0x4a,0xa9,0x41,0x3b,0x92,0x68,0x85,0x1c,0x04,0xdc,0xd9,0xf8,0x8e,0x78,0x81,0x3f,0xee,0x56, + 0x30,0x44,0x02,0x20,0x2b,0xde,0xa4,0x1c,0xda,0x63,0xa2,0xd1,0x4b,0xf4,0x73,0x53,0xbd,0x20,0x88,0x0a,0x69,0x09,0x01,0xde,0x7c,0xd6,0xe3,0xcc,0x6d,0x8e,0xd5,0xba,0x0c,0xdb,0x10,0x91,0x02,0x20,0x3c,0xea,0x66,0xbc,0xcf,0xc9,0xf9,0xbf,0x8c,0x7c,0xa4,0xe1,0xc1,0x45,0x7c,0xc9,0x14,0x5e,0x13,0xe9,0x36,0xd9,0x0b,0x3d,0x9c,0x77,0x86,0xb8,0xb2,0x6c,0xf4,0xc7, + 0x30,0x45,0x02,0x21,0x00,0xd7,0xcd,0x76,0xec,0x01,0xc1,0xb1,0x07,0x9e,0xba,0x9e,0x2a,0xa2,0xa3,0x97,0x24,0x3c,0x47,0x58,0xc9,0x8a,0x1b,0xa0,0xb7,0x40,0x4a,0x34,0x0b,0x9b,0x00,0xce,0xd6,0x02,0x20,0x35,0x75,0x00,0x1e,0x19,0xd9,0x22,0xe6,0xde,0x8b,0x3d,0x6c,0x84,0xea,0x43,0xb5,0xc3,0x33,0x81,0x06,0xcf,0x29,0x99,0x01,0x34,0xe7,0x66,0x9a,0x82,0x6f,0x78,0xe6, + 0x30,0x45,0x02,0x21,0x00,0xa8,0x72,0xc7,0x44,0xd9,0x36,0xdb,0x21,0xa1,0x0c,0x36,0x1d,0xd5,0xc9,0x06,0x33,0x55,0xf8,0x49,0x02,0x21,0x96,0x52,0xf6,0xfc,0x56,0xdc,0x95,0xa7,0x13,0x9d,0x96,0x02,0x20,0x40,0x0d,0xf7,0x57,0x5d,0x97,0x56,0x21,0x0e,0x9c,0xcc,0x77,0x16,0x2c,0x6b,0x59,0x3c,0x77,0x46,0xcf,0xb4,0x8a,0xc2,0x63,0xc4,0x27,0x50,0xb4,0x21,0xef,0x4b,0xb9, + 0x30,0x45,0x02,0x21,0x00,0x9f,0xa9,0xaf,0xe0,0x77,0x52,0xda,0x10,0xb3,0x6d,0x3a,0xfc,0xd0,0xfe,0x44,0xbf,0xc4,0x02,0x44,0xd7,0x52,0x03,0x59,0x9c,0xf8,0xf5,0x04,0x7f,0xa3,0x45,0x38,0x54,0x02,0x20,0x50,0xe0,0xa7,0xc0,0x13,0xbf,0xbf,0x51,0x81,0x97,0x36,0x97,0x2d,0x44,0xb4,0xb5,0x6b,0xc2,0xa2,0xb2,0xc1,0x80,0xdf,0x6e,0xc6,0x72,0xdf,0x17,0x14,0x10,0xd7,0x7a, + 0x30,0x45,0x02,0x21,0x00,0x88,0x56,0x40,0x38,0x4d,0x0d,0x91,0x0e,0xfb,0x17,0x7b,0x46,0xbe,0x6c,0x3d,0xc5,0xca,0xc8,0x1f,0x0b,0x88,0xc3,0x19,0x0b,0xb6,0xb5,0xf9,0x9c,0x26,0x41,0xf2,0x05,0x02,0x20,0x73,0x8e,0xd9,0xbf,0xf1,0x16,0x30,0x6d,0x9c,0xaa,0x0f,0x8f,0xc6,0x08,0xbe,0x24,0x3e,0x0b,0x56,0x77,0x79,0xd8,0xda,0xb0,0x3e,0x8e,0x19,0xd5,0x53,0xf1,0xdc,0x8e, + 0x30,0x44,0x02,0x20,0x2d,0x05,0x1f,0x91,0xc5,0xa9,0xd4,0x40,0xc5,0x67,0x69,0x85,0x71,0x04,0x83,0xbc,0x4f,0x1a,0x6c,0x61,0x1b,0x10,0xc9,0x5a,0x2f,0xf0,0x36,0x3d,0x90,0xc2,0xa4,0x58,0x02,0x20,0x6d,0xdf,0x94,0xe6,0xfb,0xa5,0xbe,0x58,0x68,0x33,0xd0,0xc5,0x3c,0xf2,0x16,0xad,0x39,0x48,0xf3,0x79,0x53,0xc2,0x6c,0x1c,0xf4,0x96,0x8e,0x9a,0x9e,0x82,0x43,0xdc, + 0x30,0x45,0x02,0x21,0x00,0xf3,0xac,0x25,0x23,0x96,0x74,0x82,0xf5,0x3d,0x50,0x85,0x22,0x71,0x2d,0x58,0x3f,0x43,0x79,0xcd,0x82,0x41,0x01,0xff,0x63,0x5e,0xa0,0x93,0x51,0x17,0xba,0xa5,0x4f,0x02,0x20,0x27,0xf1,0x08,0x12,0x22,0x73,0x97,0xe0,0x2c,0xea,0x96,0xfb,0x0e,0x68,0x07,0x61,0x63,0x6d,0xab,0x2b,0x08,0x0d,0x1f,0xc5,0xd1,0x16,0x85,0xcb,0xe8,0x50,0x0c,0xfe, + 0x30,0x45,0x02,0x21,0x00,0x96,0x44,0x7c,0xf6,0x8c,0x3a,0xb7,0x26,0x6e,0xd7,0x44,0x7d,0xe3,0xac,0x52,0xfe,0xd7,0xcc,0x08,0xcb,0xdf,0xea,0x39,0x1c,0x18,0xa9,0xb8,0xab,0x37,0x0b,0xc9,0x13,0x02,0x20,0x0f,0x5e,0x78,0x74,0xd3,0xac,0x0e,0x91,0x8f,0x01,0xc8,0x85,0xa1,0x63,0x91,0x77,0xc9,0x23,0xf8,0x66,0x0d,0x1c,0xeb,0xa1,0xca,0x1f,0x30,0x1b,0xc6,0x75,0xcd,0xbc, + 0x30,0x44,0x02,0x20,0x53,0x0a,0x08,0x32,0xb6,0x91,0xda,0x0b,0x56,0x19,0xa0,0xb1,0x1d,0xe6,0x87,0x7f,0x3c,0x09,0x71,0xba,0xaa,0x68,0xed,0x12,0x27,0x58,0xc2,0x9c,0xaa,0xf4,0x6b,0x72,0x02,0x20,0x6c,0x89,0xe4,0x4f,0x5e,0xb3,0x30,0x60,0xea,0x4b,0x46,0x31,0x8c,0x39,0x13,0x8e,0xae,0xde,0xc7,0x2d,0xe4,0x2b,0xa5,0x76,0x57,0x9a,0x6a,0x46,0x90,0xe3,0x39,0xf3, + 0x30,0x45,0x02,0x21,0x00,0x9c,0x54,0xc2,0x55,0x00,0xbd,0xe0,0xb9,0x2d,0x72,0xd6,0xec,0x48,0x3d,0xc2,0x48,0x2f,0x36,0x54,0x29,0x4c,0xa7,0x4d,0xe7,0x96,0xb6,0x81,0x25,0x5e,0xd5,0x8a,0x77,0x02,0x20,0x67,0x74,0x53,0xc6,0xb5,0x6f,0x52,0x76,0x31,0xc9,0xf6,0x7b,0x3f,0x3e,0xb6,0x21,0xfd,0x88,0x58,0x2b,0x4a,0xff,0x15,0x6d,0x2f,0x15,0x67,0xd6,0x21,0x1a,0x2a,0x33, + 0x30,0x45,0x02,0x21,0x00,0xe7,0x90,0x9d,0x41,0x43,0x9e,0x2f,0x6a,0xf2,0x91,0x36,0xc7,0x34,0x8c,0xa2,0x64,0x1a,0x2b,0x07,0x0d,0x5b,0x64,0xf9,0x1e,0xa9,0xda,0x70,0x70,0xc7,0xa2,0x61,0x8b,0x02,0x20,0x42,0xd7,0x82,0xf1,0x32,0xfa,0x1d,0x36,0xc2,0xc8,0x8b,0xa2,0x7c,0x3d,0x67,0x8d,0x80,0x18,0x4a,0x5d,0x1e,0xcc,0xac,0x75,0x01,0xf0,0xb4,0x7e,0x3d,0x20,0x50,0x08, + 0x30,0x44,0x02,0x20,0x59,0x24,0x87,0x32,0x09,0x59,0x31,0x35,0xa4,0xc3,0xda,0x7b,0xb3,0x81,0x22,0x7f,0x8a,0x4b,0x6a,0xa9,0xf3,0x4f,0xe5,0xbb,0x7f,0x8f,0xbc,0x13,0x1a,0x03,0x9f,0xfe,0x02,0x20,0x1f,0x1b,0xb1,0x1b,0x44,0x1c,0x8f,0xea,0xa4,0x0f,0x44,0x21,0x3d,0x9a,0x40,0x5e,0xd7,0x92,0xd5,0x9f,0xb4,0x9d,0x5b,0xcd,0xd9,0xa4,0x28,0x5a,0xe5,0x69,0x30,0x22, + 0x30,0x45,0x02,0x21,0x00,0xee,0xb6,0x92,0xc9,0xb2,0x62,0x96,0x9b,0x23,0x1c,0x38,0xb5,0xa7,0xf6,0x06,0x49,0xe0,0xc8,0x75,0xcd,0x64,0xdf,0x88,0xf3,0x3a,0xa5,0x71,0xfa,0x3d,0x29,0xab,0x0e,0x02,0x20,0x21,0x8b,0x3a,0x1e,0xb0,0x63,0x79,0xc2,0xc1,0x8c,0xf5,0x1b,0x06,0x43,0x07,0x86,0xd1,0xc6,0x4c,0xd2,0xd2,0x4c,0x9b,0x23,0x2b,0x23,0xe5,0xba,0xc7,0x98,0x9a,0xcd, + 0x30,0x45,0x02,0x21,0x00,0xa4,0x00,0x34,0x17,0x7f,0x36,0x09,0x1c,0x2b,0x65,0x36,0x84,0xa0,0xe3,0xeb,0x5d,0x4b,0xff,0x18,0xe4,0xd0,0x9f,0x66,0x4c,0x28,0x00,0xe7,0xca,0xfd,0xa1,0xda,0xf8,0x02,0x20,0x3a,0x3e,0xc2,0x98,0x53,0x70,0x4e,0x52,0x03,0x1c,0x58,0x92,0x7a,0x80,0x0a,0x96,0x83,0x53,0xad,0xc3,0xd9,0x73,0xbe,0xba,0x91,0x72,0xcb,0xbe,0xab,0x4d,0xd1,0x49, + 0x30,0x45,0x02,0x21,0x00,0xb5,0xd7,0x95,0xcc,0x75,0xce,0xa5,0xc4,0x34,0xfa,0x41,0x85,0x18,0x0c,0xd6,0xbd,0x21,0x22,0x3f,0x3d,0x5a,0x86,0xda,0x66,0x70,0xd7,0x1d,0x95,0x68,0x0d,0xad,0xbf,0x02,0x20,0x54,0xe4,0xd8,0x81,0x0a,0x00,0x1e,0xcb,0xb9,0xf7,0xca,0x1c,0x2e,0xbf,0xdb,0x9d,0x00,0x9e,0x90,0x31,0xa4,0x31,0xac,0xa3,0xc2,0x0a,0xb4,0xe0,0xd1,0x37,0x4e,0xc1, + 0x30,0x44,0x02,0x20,0x07,0xdc,0x24,0x78,0xd4,0x3c,0x12,0x32,0xa4,0x59,0x56,0x08,0xc6,0x44,0x26,0xc3,0x55,0x10,0x05,0x1a,0x63,0x1a,0xe6,0xa5,0xa6,0xeb,0x11,0x61,0xe5,0x7e,0x42,0xe1,0x02,0x20,0x4a,0x59,0xea,0x0f,0xdb,0x72,0xd1,0x21,0x65,0xce,0xa3,0xbf,0x1c,0xa8,0x6b,0xa9,0x75,0x17,0xbd,0x18,0x8d,0xb3,0xdb,0xd2,0x1a,0x5a,0x15,0x78,0x50,0x02,0x19,0x84, + 0x30,0x45,0x02,0x21,0x00,0xdd,0xd2,0x0c,0x4a,0x05,0x59,0x6c,0xa8,0x68,0xb5,0x58,0x83,0x9f,0xce,0x9f,0x65,0x11,0xdd,0xd8,0x3d,0x1c,0xcb,0x53,0xf8,0x2e,0x52,0x69,0xd5,0x59,0xa0,0x15,0x52,0x02,0x20,0x5b,0x91,0x73,0x47,0x29,0xd9,0x30,0x93,0xff,0x22,0x12,0x3c,0x4a,0x25,0x81,0x9d,0x7f,0xeb,0x66,0xa2,0x50,0x66,0x3f,0xc7,0x80,0xcb,0x66,0xfc,0x7b,0x6e,0x6d,0x17, + 0x30,0x45,0x02,0x21,0x00,0x9c,0xde,0x6e,0x0e,0xde,0x0a,0x00,0x3f,0x02,0xfd,0xa0,0xa0,0x1b,0x59,0xfa,0xcf,0xe5,0xde,0xc0,0x63,0x31,0x8f,0x27,0x9c,0xe2,0xde,0x7a,0x9b,0x10,0x62,0xf7,0xb7,0x02,0x20,0x28,0x86,0xa5,0xb8,0xc6,0x79,0xbd,0xf8,0x22,0x4c,0x66,0xf9,0x08,0xfd,0x62,0x05,0x49,0x2c,0xb7,0x0b,0x00,0x68,0xd4,0x6a,0xe4,0xf3,0x3a,0x41,0x49,0xb1,0x2a,0x52, + 0x30,0x45,0x02,0x21,0x00,0xc5,0x77,0x10,0x16,0xd0,0xdd,0x63,0x57,0x14,0x3c,0x89,0xf6,0x84,0xcd,0x74,0x04,0x23,0x50,0x25,0x54,0xc0,0xc5,0x9a,0xa8,0xc9,0x95,0x84,0xf1,0xff,0x38,0xf6,0x09,0x02,0x20,0x54,0xb4,0x05,0xf4,0x47,0x75,0x46,0x68,0x6e,0x46,0x4c,0x54,0x63,0xb4,0xfd,0x41,0x90,0x57,0x2e,0x58,0xd0,0xf7,0xe7,0x35,0x7f,0x6e,0x61,0x94,0x7d,0x20,0x71,0x5c, + 0x30,0x45,0x02,0x21,0x00,0xa2,0x4e,0xbc,0x0e,0xc2,0x24,0xbd,0x67,0xae,0x39,0x7c,0xbe,0x6f,0xa3,0x7b,0x31,0x25,0xad,0xbd,0x34,0x89,0x1a,0xbe,0x2d,0x7c,0x73,0x56,0x92,0x19,0x16,0xdf,0xe6,0x02,0x20,0x34,0xf6,0xeb,0x63,0x74,0x73,0x1b,0xbb,0xaf,0xc4,0x92,0x4f,0xb8,0xb0,0xbd,0xcd,0xda,0x49,0x45,0x6d,0x72,0x4c,0xda,0xe6,0x17,0x8d,0x87,0x01,0x4c,0xb5,0x3d,0x8c, + 0x30,0x44,0x02,0x20,0x25,0x57,0xd6,0x4a,0x7a,0xee,0x2e,0x09,0x31,0xc0,0x12,0xe4,0xfe,0xa1,0xcd,0x3a,0x2c,0x33,0x4e,0xda,0xe6,0x8c,0xde,0xb7,0x15,0x8c,0xaf,0x21,0xb6,0x8e,0x5a,0x24,0x02,0x20,0x7f,0x06,0xcd,0xbb,0x6a,0x90,0x02,0x3a,0x97,0x38,0x82,0xed,0x97,0xb0,0x80,0xfe,0x6b,0x05,0xaf,0x3e,0xc9,0x3d,0xb6,0xf1,0xa4,0x39,0x9a,0x69,0xed,0xf7,0x67,0x0d, + 0x30,0x45,0x02,0x21,0x00,0xc4,0xf2,0xec,0xcb,0xb6,0xa2,0x43,0x50,0xc8,0x46,0x64,0x50,0xb9,0xd6,0x1b,0x20,0x7e,0xe3,0x59,0xe0,0x37,0xb3,0xdc,0xed,0xb4,0x2a,0x3f,0x2e,0x6d,0xd6,0xae,0xb5,0x02,0x20,0x32,0x63,0xc6,0xb5,0x9a,0x2f,0x55,0xcd,0xd1,0xc6,0xe1,0x48,0x94,0xd5,0xe5,0x96,0x3b,0x28,0xbc,0x3e,0x24,0x69,0xac,0x9b,0xa1,0x19,0x79,0x91,0xca,0x7f,0xf9,0xc7, + 0x30,0x45,0x02,0x21,0x00,0xef,0xf0,0x47,0x81,0xc9,0xcb,0xcd,0x16,0x2d,0x0a,0x25,0xa6,0xe2,0xeb,0xcc,0xa4,0x35,0x06,0xc5,0x23,0x38,0x5c,0xb5,0x15,0xd4,0x9e,0xa3,0x8a,0x1b,0x12,0xfc,0xad,0x02,0x20,0x15,0xac,0xd7,0x31,0x94,0xc9,0x1a,0x95,0x47,0x85,0x34,0xf2,0x30,0x15,0xb6,0x72,0xeb,0xed,0x21,0x3e,0x45,0x42,0x4d,0xd2,0xc8,0xe2,0x6a,0xc8,0xb3,0xeb,0x34,0xa5, + 0x30,0x45,0x02,0x21,0x00,0xf5,0x8b,0x4e,0x31,0x10,0xa6,0x4b,0xf1,0xb5,0xdb,0x97,0x63,0x9e,0xe0,0xe5,0xa9,0xc8,0xdf,0xa4,0x9d,0xc5,0x9b,0x67,0x98,0x91,0xf5,0x20,0xfd,0xf0,0x58,0x4c,0x87,0x02,0x20,0x2c,0xd8,0xfe,0x51,0x88,0x8a,0xee,0x9d,0xb3,0xe0,0x75,0x44,0x0f,0xd4,0xdb,0x73,0xb5,0xc7,0x32,0xfb,0x87,0xb5,0x10,0xe9,0x70,0x93,0xd6,0x64,0x15,0xf6,0x2a,0xf7, + 0x30,0x45,0x02,0x21,0x00,0xf8,0xab,0xec,0xaa,0x4f,0x0c,0x50,0x2d,0xe4,0xbf,0x59,0x03,0xd4,0x84,0x17,0xf7,0x86,0xbf,0x92,0xe8,0xad,0x72,0xfe,0xc0,0xbd,0x7f,0xcb,0x78,0x00,0xc0,0xbb,0xe3,0x02,0x20,0x4c,0x7f,0x9e,0x23,0x10,0x76,0xa3,0x0b,0x7a,0xe3,0x6b,0x0c,0xeb,0xe6,0x9c,0xce,0xf1,0xcd,0x19,0x4f,0x7c,0xce,0x93,0xa5,0x58,0x8f,0xd6,0x81,0x4f,0x43,0x7c,0x0e, + 0x30,0x44,0x02,0x20,0x5d,0x5b,0x38,0xbd,0x37,0xad,0x49,0x8b,0x22,0x27,0xa6,0x33,0x26,0x8a,0x8c,0xca,0x87,0x9a,0x5c,0x7c,0x94,0xa4,0xe4,0x16,0xbd,0x0a,0x61,0x4d,0x09,0xe6,0x06,0xd2,0x02,0x20,0x12,0xb8,0xd6,0x64,0xea,0x99,0x91,0x06,0x2e,0xcb,0xb8,0x34,0xe5,0x84,0x00,0xe2,0x5c,0x46,0x00,0x7a,0xf8,0x4f,0x60,0x07,0xd7,0xf1,0x68,0x54,0x43,0x26,0x9a,0xfe, + 0x30,0x44,0x02,0x20,0x0c,0x1c,0xd9,0xfe,0x40,0x34,0xf0,0x86,0xa2,0xb5,0x2d,0x65,0xb9,0xd3,0x83,0x4d,0x72,0xae,0xbe,0x7f,0x33,0xdf,0xe8,0xf9,0x76,0xda,0x82,0x64,0x81,0x77,0xd8,0xe3,0x02,0x20,0x13,0x10,0x57,0x82,0xe3,0xd0,0xcf,0xe8,0x5c,0x27,0x78,0xde,0xc1,0xa8,0x48,0xb2,0x7a,0xc0,0xae,0x07,0x1a,0xa6,0xda,0x34,0x1a,0x95,0x53,0xa9,0x46,0xb4,0x1e,0x59, + 0x30,0x45,0x02,0x21,0x00,0xae,0x79,0x35,0xfb,0x96,0xff,0x24,0x6b,0x7b,0x5d,0x56,0x62,0x87,0x0d,0x1b,0xa5,0x87,0xb0,0x3d,0x6e,0x13,0x60,0xba,0xf4,0x79,0x88,0xb5,0xc0,0x2c,0xcc,0x1a,0x5b,0x02,0x20,0x5f,0x00,0xc3,0x23,0x27,0x20,0x83,0x78,0x2d,0x4a,0x59,0xf2,0xdf,0xd6,0x5e,0x49,0xde,0x06,0x93,0x62,0x70,0x16,0x90,0x0e,0xf7,0xe6,0x14,0x28,0x05,0x66,0x64,0xb3, + 0x30,0x44,0x02,0x20,0x00,0xa1,0x34,0xb5,0xc6,0xcc,0xbc,0xef,0xd4,0xc8,0x82,0xb9,0x45,0xba,0xeb,0x49,0x33,0x44,0x41,0x72,0x79,0x5f,0xa6,0x79,0x6a,0xae,0x14,0x90,0x67,0x54,0x70,0x98,0x02,0x20,0x56,0x6e,0x46,0x10,0x5d,0x24,0xd8,0x90,0x15,0x1e,0x3e,0xea,0x3e,0xbf,0x88,0xf5,0xb9,0x2b,0x3f,0x5e,0xc9,0x3a,0x21,0x77,0x65,0xa6,0xdc,0xbd,0x94,0xf2,0xc5,0x5b, + 0x30,0x44,0x02,0x20,0x2e,0x47,0x21,0x36,0x3a,0xd3,0x99,0x2c,0x13,0x9e,0x5a,0x1c,0x26,0x39,0x5d,0x2c,0x2d,0x77,0x78,0x24,0xaa,0x24,0xfd,0xe0,0x75,0xe0,0xd7,0x38,0x11,0x71,0x30,0x9d,0x02,0x20,0x74,0x0f,0x7c,0x49,0x44,0x18,0xe1,0x30,0x0d,0xd4,0x51,0x2f,0x78,0x2a,0x58,0x80,0x0b,0xff,0x6a,0x7a,0xbd,0xfd,0xd2,0x0f,0xbb,0xd4,0xf0,0x55,0x15,0xca,0x1a,0x4f, + 0x30,0x44,0x02,0x20,0x68,0x52,0xe9,0xd3,0xcd,0x9f,0xe3,0x73,0xc2,0xd5,0x04,0x87,0x79,0x67,0xd3,0x65,0xab,0x14,0x56,0x70,0x7b,0x68,0x17,0xa0,0x42,0x86,0x46,0x94,0xe1,0x96,0x0c,0xcf,0x02,0x20,0x06,0x4b,0x27,0xea,0x14,0x2b,0x30,0x88,0x7b,0x84,0xc8,0x6a,0xdc,0xcb,0x2f,0xa3,0x9a,0x69,0x11,0xad,0x21,0xfc,0x7e,0x81,0x9f,0x59,0x3b,0xe5,0x2b,0xc4,0xf3,0xbd, + 0x30,0x44,0x02,0x20,0x18,0x8a,0x8c,0x56,0x48,0xdc,0x79,0xea,0xce,0x15,0x8c,0xf8,0x86,0xc6,0x2b,0x54,0x68,0xf0,0x5f,0xd9,0x5f,0x03,0xa7,0x63,0x5c,0x5b,0x4c,0x31,0xf0,0x9a,0xf4,0xc5,0x02,0x20,0x36,0x36,0x1a,0x0b,0x57,0x1a,0x00,0xc6,0xcd,0x5e,0x68,0x6c,0xcb,0xfc,0xfa,0x70,0x3c,0x4f,0x97,0xe4,0x89,0x38,0x34,0x6d,0x0c,0x10,0x3f,0xdc,0x76,0xdc,0x58,0x67, + 0x30,0x45,0x02,0x21,0x00,0xa7,0x4f,0x1f,0xb9,0xa8,0x26,0x3f,0x62,0xfc,0x44,0x16,0xa5,0xb7,0xd5,0x84,0xf4,0x20,0x6f,0x39,0x96,0xbb,0x91,0xf6,0xfc,0x8e,0x73,0xb9,0xe9,0x2b,0xad,0x0e,0x13,0x02,0x20,0x68,0x15,0x03,0x2e,0x8c,0x7d,0x76,0xc3,0xab,0x06,0xa8,0x6f,0x33,0x24,0x9c,0xe9,0x94,0x01,0x48,0xcb,0x36,0xd1,0xf4,0x17,0xc2,0xe9,0x92,0xe8,0x01,0xaf,0xa3,0xfa, + 0x30,0x44,0x02,0x20,0x07,0x24,0x48,0x65,0xb7,0x2f,0xf3,0x7e,0x62,0xe3,0x14,0x6f,0x0d,0xc1,0x46,0x82,0xba,0xdd,0x71,0x97,0x79,0x91,0x35,0xf0,0xb0,0x0a,0xde,0x76,0x71,0x74,0x2b,0xfe,0x02,0x20,0x0d,0x80,0xc2,0x23,0x8e,0xdb,0x4e,0x4a,0x7a,0x86,0xa8,0xc5,0x7c,0xa9,0xaf,0x17,0x11,0xf4,0x06,0xf7,0xf5,0xda,0x02,0x99,0xaa,0x04,0xe2,0x93,0x2d,0x96,0x07,0x54, + 0x30,0x45,0x02,0x21,0x00,0xda,0x7f,0xdd,0x05,0xb5,0xba,0xda,0xbd,0x61,0x9d,0x80,0x5c,0x4e,0xe7,0xd9,0xa8,0x4f,0x84,0xdd,0xd5,0xcf,0x9c,0x5b,0xf4,0xd4,0x33,0x81,0x40,0xd6,0x89,0xef,0x08,0x02,0x20,0x28,0xf1,0xcf,0x4f,0xa1,0xc3,0xc5,0x86,0x2c,0xfa,0x14,0x9c,0x00,0x13,0xcf,0x5f,0xe6,0xcf,0x50,0x76,0xca,0xe0,0x00,0x51,0x10,0x63,0xe7,0xde,0x25,0xbb,0x38,0xe5, + 0x30,0x45,0x02,0x21,0x00,0xd3,0x02,0x7c,0x65,0x6f,0x6d,0x4f,0xdf,0xd8,0xed,0xe2,0x20,0x93,0xe3,0xc3,0x03,0xb0,0x13,0x3c,0x34,0x0d,0x61,0x5e,0x77,0x56,0xf6,0x25,0x3a,0xea,0x92,0x72,0x38,0x02,0x20,0x09,0xae,0xf0,0x60,0xc8,0xe4,0xce,0xf9,0x72,0x97,0x40,0x11,0x55,0x8d,0xf1,0x44,0xfe,0xd2,0x5c,0xa6,0x9a,0xe8,0xd0,0xb2,0xea,0xf1,0xa8,0xfe,0xef,0xbe,0xc4,0x17, + 0x30,0x44,0x02,0x20,0x0b,0xf6,0xc0,0x18,0x8d,0xc9,0x57,0x1c,0xd0,0xe2,0x1e,0xec,0xac,0x5f,0xbb,0x19,0xd2,0x43,0x49,0x88,0xe9,0xcc,0x10,0x24,0x45,0x93,0xef,0x3a,0x98,0x09,0x9f,0x69,0x02,0x20,0x48,0x64,0xa5,0x62,0x66,0x1f,0x92,0x21,0xec,0x88,0xe3,0xdd,0x0b,0xc2,0xf6,0xe2,0x7a,0xc1,0x28,0xc3,0x0c,0xc1,0xa8,0x0f,0x79,0xec,0x67,0x0a,0x22,0xb0,0x42,0xee, + 0x30,0x45,0x02,0x21,0x00,0xae,0x45,0x96,0x40,0xd5,0xd1,0x17,0x9b,0xe4,0x7a,0x47,0xfa,0x53,0x8e,0x16,0xd9,0x4d,0xde,0xa5,0x58,0x5e,0x7a,0x24,0x48,0x04,0xa5,0x17,0x42,0xc6,0x86,0x44,0x3a,0x02,0x20,0x6c,0x8e,0x30,0xe5,0x30,0xa6,0x34,0xfa,0xe8,0x0b,0x3c,0xeb,0x06,0x29,0x78,0xb3,0x9e,0xdb,0xe1,0x97,0x77,0xe0,0xa2,0x45,0x53,0xb6,0x88,0x86,0x18,0x1f,0xd8,0x97, + 0x30,0x44,0x02,0x20,0x1c,0xf3,0x51,0x7b,0xa3,0xbf,0x2a,0xb8,0xb9,0xea,0xd4,0xeb,0xb6,0xe8,0x66,0xcb,0x88,0xa1,0xde,0xac,0xb6,0xa7,0x85,0xd3,0xb6,0x3b,0x48,0x3c,0xa0,0x2a,0xc4,0x95,0x02,0x20,0x24,0x9a,0x79,0x8b,0x73,0x60,0x6f,0x55,0xf5,0xf1,0xc7,0x0d,0xe6,0x7c,0xb1,0xa0,0xcf,0xf9,0x5d,0x7d,0xc5,0x0b,0x3a,0x61,0x7d,0xf8,0x61,0xba,0xd3,0xc6,0xb1,0xc9, + 0x30,0x45,0x02,0x21,0x00,0xe6,0x9b,0x52,0x38,0x26,0x5e,0xa3,0x5d,0x77,0xe4,0xdd,0x17,0x22,0x88,0xd8,0xce,0xa1,0x98,0x10,0xa1,0x02,0x92,0x61,0x7d,0x59,0x76,0x51,0x9d,0xc5,0x75,0x7c,0xb8,0x02,0x20,0x4b,0x03,0xc5,0xbc,0x47,0xe8,0x26,0xbd,0xb2,0x73,0x28,0xab,0xd3,0x8d,0x30,0x56,0xd7,0x74,0x76,0xb2,0x13,0x0f,0x3d,0xf6,0xec,0x48,0x91,0xaf,0x08,0xba,0x1e,0x29, + 0x30,0x44,0x02,0x20,0x5f,0x9d,0x7d,0x7c,0x87,0x0d,0x08,0x5f,0xc1,0xd4,0x9f,0xff,0x69,0xe4,0xa2,0x75,0x81,0x28,0x00,0xd2,0xcf,0x89,0x73,0xe7,0x32,0x58,0x66,0xcb,0x40,0xfa,0x2b,0x6f,0x02,0x20,0x6d,0x1f,0x54,0x91,0xd9,0xf7,0x17,0xa5,0x97,0xa1,0x5f,0xd5,0x40,0x40,0x64,0x86,0xd7,0x6a,0x44,0x69,0x7b,0x3f,0x0d,0x9d,0x6d,0xce,0xf6,0x66,0x9f,0x8a,0x0a,0x56, + 0x30,0x44,0x02,0x20,0x0a,0x7d,0x5b,0x19,0x59,0xf7,0x1d,0xf9,0xf8,0x17,0x14,0x6e,0xe4,0x9b,0xd5,0xc8,0x9b,0x43,0x1e,0x79,0x93,0xe2,0xfd,0xec,0xab,0x68,0x58,0x95,0x7d,0xa6,0x85,0xae,0x02,0x20,0x0f,0x8a,0xad,0x2d,0x25,0x46,0x90,0xbd,0xc1,0x3f,0x34,0xa4,0xfe,0xc4,0x4a,0x02,0xfd,0x74,0x5a,0x42,0x2d,0xf0,0x5c,0xcb,0xb5,0x46,0x35,0xa8,0xb8,0x6b,0x96,0x09, + 0x30,0x44,0x02,0x20,0x79,0xe8,0x8b,0xf5,0x76,0xb7,0x4b,0xc0,0x7c,0xa1,0x42,0x39,0x5f,0xda,0x28,0xf0,0x3d,0x3d,0x5e,0x64,0x0b,0x0b,0x4f,0xf0,0x75,0x2c,0x6d,0x94,0xcd,0x55,0x34,0x08,0x02,0x20,0x32,0xce,0xa0,0x5b,0xd2,0xd7,0x06,0xc8,0xf6,0x03,0x6a,0x50,0x7e,0x2a,0xb7,0x76,0x60,0x04,0xf0,0x90,0x4e,0x2e,0x5c,0x58,0x62,0x74,0x9c,0x00,0x73,0x24,0x5d,0x6a, + 0x30,0x45,0x02,0x21,0x00,0x9d,0x54,0xe0,0x37,0xa0,0x02,0x12,0xb3,0x77,0xbc,0x88,0x74,0x79,0x8b,0x8d,0xa0,0x80,0x56,0x4b,0xbd,0xf7,0xe0,0x75,0x91,0xb8,0x61,0x28,0x58,0x09,0xd0,0x14,0x88,0x02,0x20,0x18,0xb4,0xe5,0x57,0x66,0x7a,0x82,0xbd,0x95,0x96,0x5f,0x07,0x06,0xf8,0x1a,0x29,0x24,0x3f,0xbd,0xd8,0x69,0x68,0xa7,0xeb,0xeb,0x43,0x06,0x9d,0xb3,0xb1,0x8c,0x7f, + 0x30,0x44,0x02,0x20,0x26,0x64,0xf1,0xff,0xa9,0x82,0xfe,0xdb,0xcc,0x7c,0xab,0x1b,0x8b,0xc6,0xe2,0xcb,0x42,0x02,0x18,0xd2,0xa6,0x07,0x7a,0xd0,0x8e,0x59,0x1b,0xa9,0xfe,0xab,0x33,0xbd,0x02,0x20,0x49,0xf5,0xc7,0xcb,0x51,0x5e,0x83,0x87,0x2a,0x3d,0x41,0xb4,0xcd,0xb8,0x5f,0x24,0x2a,0xd9,0xd6,0x1a,0x5b,0xfc,0x01,0xde,0xbf,0xbb,0x52,0xc6,0xc8,0x4b,0xa7,0x28, + 0x30,0x44,0x02,0x20,0x58,0x27,0x51,0x83,0x44,0x84,0x4f,0xd6,0xa7,0xde,0x73,0xcb,0xb0,0xa6,0xbe,0xfd,0xea,0x7b,0x13,0xd2,0xde,0xe4,0x47,0x53,0x17,0xf0,0xf1,0x8f,0xfc,0x81,0x52,0x4b,0x02,0x20,0x4f,0x5c,0xcb,0x4e,0x0b,0x48,0x8b,0x5a,0x5d,0x76,0x0a,0xac,0xdd,0xb2,0xd7,0x91,0x97,0x0f,0xe4,0x3d,0xa6,0x1e,0xb3,0x0e,0x2e,0x90,0x20,0x8a,0x81,0x7e,0x46,0xdb, + 0x30,0x45,0x02,0x21,0x00,0x97,0xab,0x19,0xbd,0x13,0x9c,0xac,0x31,0x93,0x25,0x86,0x92,0x18,0xb1,0xbc,0xe1,0x11,0x87,0x5d,0x63,0xfb,0x12,0x09,0x8a,0x04,0xb0,0xcd,0x59,0xb6,0xfd,0xd3,0xa3,0x02,0x20,0x43,0x1d,0x9c,0xea,0x3a,0x24,0x38,0x47,0x30,0x3c,0xeb,0xda,0x56,0x47,0x64,0x31,0xd0,0x34,0x33,0x9f,0x31,0xd7,0x85,0xee,0x88,0x52,0xdb,0x4f,0x04,0x0d,0x49,0x21, + 0x30,0x44,0x02,0x20,0x52,0xc6,0x83,0x14,0x4e,0x44,0x11,0x9a,0xe2,0x01,0x37,0x49,0xd4,0x96,0x4e,0xf6,0x75,0x09,0x27,0x8f,0x6d,0x38,0xba,0x86,0x9a,0xdc,0xfa,0x69,0x97,0x0e,0x12,0x3d,0x02,0x20,0x34,0x79,0x91,0x01,0x67,0x40,0x8f,0x45,0xbd,0xa4,0x20,0xa6,0x26,0xec,0x9c,0x4e,0xc7,0x11,0xc1,0x27,0x4b,0xe0,0x92,0x19,0x8b,0x41,0x87,0xc0,0x18,0xb5,0x62,0xca, + 0x30,0x16,0x02,0x11,0x01,0x45,0x51,0x23,0x19,0x50,0xb7,0x5f,0xc4,0x40,0x2d,0xa1,0x72,0x2f,0xc9,0xba,0xeb,0x02,0x01,0x03, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xfc,0x2c,0x02,0x01,0x03, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x3f,0x02,0x01,0x03, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x3e,0x9a,0x75,0x82,0x88,0x60,0x89,0xc6,0x2f,0xb8,0x40,0xcf,0x3b,0x83,0x06,0x1c,0xd1,0xcf,0xf3,0xae,0x43,0x41,0x80,0x8b,0xb5,0xbd,0xee,0x61,0x91,0x17,0x41,0x77, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x24,0x23,0x8e,0x70,0xb4,0x31,0xb1,0xa6,0x4e,0xfd,0xf9,0x03,0x26,0x69,0x93,0x9d,0x4b,0x77,0xf2,0x49,0x50,0x3f,0xc6,0x90,0x5f,0xeb,0x75,0x40,0xde,0xa3,0xe6,0xd2, + 0x30,0x06,0x02,0x01,0x01,0x02,0x01,0x01, + 0x30,0x06,0x02,0x01,0x01,0x02,0x01,0x02, + 0x30,0x06,0x02,0x01,0x01,0x02,0x01,0x03, + 0x30,0x06,0x02,0x01,0x02,0x02,0x01,0x01, + 0x30,0x06,0x02,0x01,0x02,0x02,0x01,0x02, + 0x30,0x06,0x02,0x01,0x02,0x02,0x01,0x03, + 0x30,0x26,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x41,0x43,0x02,0x01,0x03, + 0x30,0x08,0x02,0x01,0x02,0x02,0x03,0xed,0x29,0x79, + 0x30,0x26,0x02,0x02,0x01,0x01,0x02,0x20,0x3a,0x74,0xe9,0xd3,0xa7,0x4e,0x9d,0x3a,0x74,0xe9,0xd3,0xa7,0x4e,0x9d,0x3a,0x74,0x9f,0x8a,0xb3,0x73,0x2a,0x0a,0x89,0x60,0x4a,0x09,0xbc,0xe5,0xb2,0x91,0x6d,0xa4, + 0x30,0x2b,0x02,0x07,0x2d,0x9b,0x4d,0x34,0x79,0x52,0xcc,0x02,0x20,0x03,0x43,0xae,0xfc,0x2f,0x25,0xd9,0x8b,0x88,0x2e,0x86,0xeb,0x9e,0x30,0xd5,0x5a,0x6e,0xb5,0x08,0xb5,0x16,0x51,0x0b,0x34,0x02,0x4a,0xe4,0xb6,0x36,0x23,0x30,0xb3, + 0x30,0x31,0x02,0x0d,0x10,0x33,0xe6,0x7e,0x37,0xb3,0x2b,0x44,0x55,0x80,0xbf,0x4e,0xfc,0x02,0x20,0x6f,0x90,0x6f,0x90,0x6f,0x90,0x6f,0x90,0x6f,0x90,0x6f,0x90,0x6f,0x90,0x6f,0x8f,0xe1,0xca,0xb5,0xee,0xfd,0xb2,0x14,0x06,0x1d,0xce,0x3b,0x22,0x78,0x9f,0x1d,0x6f, + 0x30,0x26,0x02,0x02,0x01,0x01,0x02,0x20,0x78,0x32,0x66,0xe9,0x0f,0x43,0xda,0xfe,0x5c,0xd9,0xb3,0xb0,0xbe,0x86,0xde,0x22,0xf9,0xde,0x83,0x67,0x7d,0x0f,0x50,0x71,0x3a,0x46,0x8e,0xc7,0x2f,0xcf,0x5d,0x57, + 0x30,0x31,0x02,0x0d,0x06,0x25,0x22,0xbb,0xd3,0xec,0xbe,0x7c,0x39,0xe9,0x3e,0x7c,0x26,0x02,0x20,0x78,0x32,0x66,0xe9,0x0f,0x43,0xda,0xfe,0x5c,0xd9,0xb3,0xb0,0xbe,0x86,0xde,0x22,0xf9,0xde,0x83,0x67,0x7d,0x0f,0x50,0x71,0x3a,0x46,0x8e,0xc7,0x2f,0xcf,0x5d,0x57, + 0x30,0x45,0x02,0x21,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xba,0xae,0xdc,0xe6,0xaf,0x48,0xa0,0x3b,0xbf,0xd2,0x5e,0x8c,0xd0,0x36,0x40,0xc1,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc0, + 0x30,0x16,0x02,0x09,0x00,0x9c,0x44,0xfe,0xbf,0x31,0xc3,0x59,0x4d,0x02,0x09,0x00,0x83,0x9e,0xd2,0x82,0x47,0xc2,0xb0,0x6b, + 0x30,0x1e,0x02,0x0d,0x09,0xdf,0x8b,0x68,0x24,0x30,0xbe,0xef,0x6f,0x5f,0xd7,0xc7,0xcf,0x02,0x0d,0x0f,0xd0,0xa6,0x2e,0x13,0x77,0x8f,0x42,0x22,0xa0,0xd6,0x1c,0x8a, + 0x30,0x26,0x02,0x11,0x00,0x8a,0x59,0x8e,0x56,0x3a,0x89,0xf5,0x26,0xc3,0x2e,0xbe,0xc8,0xde,0x26,0x36,0x7a,0x02,0x11,0x00,0x84,0xf6,0x33,0xe2,0x04,0x26,0x30,0xe9,0x9d,0xd0,0xf1,0xe1,0x6f,0x7a,0x04,0xbf, + 0x30,0x2e,0x02,0x15,0x00,0xaa,0x6e,0xeb,0x58,0x23,0xf7,0xfa,0x31,0xb4,0x66,0xbb,0x47,0x37,0x97,0xf0,0xd0,0x31,0x4c,0x0b,0xdf,0x02,0x15,0x00,0xe2,0x97,0x7c,0x47,0x9e,0x6d,0x25,0x70,0x3c,0xeb,0xbc,0x6b,0xd5,0x61,0x93,0x8c,0xc9,0xd1,0xbf,0xb9, + 0x30,0x25,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc1,0x02,0x01,0x01, + 0x30,0x25,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc1,0x02,0x01,0x00, + 0x30,0x44,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc1,0x02,0x20,0x41,0x9d,0x98,0x1c,0x51,0x5a,0xf8,0xcc,0x82,0x54,0x5a,0xac,0x0c,0x85,0xe9,0xe3,0x08,0xfb,0xb2,0xea,0xb6,0xac,0xd7,0xed,0x49,0x7e,0x0b,0x41,0x45,0xa1,0x8f,0xd9, + 0x30,0x44,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc1,0x02,0x20,0x1b,0x21,0x71,0x7a,0xd7,0x1d,0x23,0xbb,0xac,0x60,0xa9,0xad,0x0b,0xaf,0x75,0xb0,0x63,0xc9,0xfd,0xf5,0x2a,0x00,0xeb,0xf9,0x9d,0x02,0x21,0x72,0x91,0x09,0x93,0xc9, + 0x30,0x44,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc1,0x02,0x20,0x2f,0x58,0x8f,0x66,0x01,0x8f,0x3d,0xd1,0x4d,0xb3,0xe2,0x8e,0x77,0x99,0x64,0x87,0xe3,0x24,0x86,0xb5,0x21,0xed,0x8e,0x5a,0x20,0xf0,0x65,0x91,0x95,0x17,0x77,0xe9, + 0x30,0x44,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc1,0x02,0x20,0x09,0x1a,0x08,0x87,0x0f,0xf4,0xda,0xf9,0x12,0x3b,0x30,0xc2,0x0e,0x8c,0x4f,0xc8,0x50,0x57,0x58,0xdc,0xf4,0x07,0x4f,0xca,0xff,0x21,0x70,0xc9,0xbf,0xcf,0x74,0xf4, + 0x30,0x44,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc1,0x02,0x20,0x7c,0x37,0x0d,0xc0,0xce,0x8c,0x59,0xa8,0xb2,0x73,0xcb,0xa4,0x4a,0x7c,0x11,0x91,0xfc,0x31,0x86,0xdc,0x03,0xca,0xb9,0x6b,0x05,0x67,0x31,0x2d,0xf0,0xd0,0xb2,0x50, + 0x30,0x44,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc1,0x02,0x20,0x70,0xb5,0x9a,0x7d,0x1e,0xe7,0x7a,0x2f,0x9e,0x04,0x91,0xc2,0xa7,0xcf,0xcd,0x0e,0xd0,0x4d,0xf4,0xa3,0x51,0x92,0xf6,0x13,0x2d,0xcc,0x66,0x8c,0x79,0xa6,0x16,0x0e, + 0x30,0x44,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc1,0x02,0x20,0x27,0x36,0xd7,0x6e,0x41,0x22,0x46,0xe0,0x97,0x14,0x8e,0x2b,0xf6,0x29,0x15,0x61,0x4e,0xb7,0xc4,0x28,0x91,0x3a,0x58,0xeb,0x5e,0x9c,0xd4,0x67,0x4a,0x94,0x23,0xde, + 0x30,0x44,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc1,0x02,0x20,0x4a,0x1e,0x12,0x83,0x1f,0xbe,0x93,0x62,0x7b,0x02,0xd6,0xe7,0xf2,0x4b,0xcc,0xdd,0x6e,0xf4,0xb2,0xd0,0xf4,0x67,0x39,0xea,0xf3,0xb1,0xea,0xf0,0xca,0x11,0x77,0x70, + 0x30,0x44,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc1,0x02,0x20,0x06,0xc7,0x78,0xd4,0xdf,0xff,0x7d,0xee,0x06,0xed,0x88,0xbc,0x4e,0x0e,0xd3,0x4f,0xc5,0x53,0xaa,0xd6,0x7c,0xaf,0x79,0x6f,0x2a,0x1c,0x64,0x87,0xc1,0xb2,0xe8,0x77, + 0x30,0x44,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc1,0x02,0x20,0x4d,0xe4,0x59,0xef,0x91,0x59,0xaf,0xa0,0x57,0xfe,0xb3,0xec,0x40,0xfe,0xf0,0x1c,0x45,0xb8,0x09,0xf4,0xab,0x29,0x6e,0xa4,0x8c,0x20,0x6d,0x42,0x49,0xa2,0xb4,0x51, + 0x30,0x44,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc1,0x02,0x20,0x74,0x5d,0x29,0x49,0x78,0x00,0x73,0x02,0x03,0x35,0x02,0xe1,0xac,0xc4,0x8b,0x63,0xae,0x65,0x00,0xbe,0x43,0xad,0xbe,0xa1,0xb2,0x58,0xd6,0xb4,0x23,0xdb,0xb4,0x16, + 0x30,0x44,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc1,0x02,0x20,0x7b,0x2a,0x78,0x5e,0x38,0x96,0xf5,0x9b,0x2d,0x69,0xda,0x57,0x64,0x8e,0x80,0xad,0x3c,0x13,0x3a,0x75,0x0a,0x28,0x47,0xfd,0x20,0x98,0xcc,0xd9,0x02,0x04,0x2b,0x6c, + 0x30,0x44,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc1,0x02,0x20,0x71,0xae,0x94,0xa7,0x2c,0xa8,0x96,0x87,0x5e,0x7a,0xa4,0xa4,0xc3,0xd2,0x9a,0xfd,0xb4,0xb3,0x5b,0x69,0x96,0x27,0x3e,0x63,0xc4,0x7a,0xc5,0x19,0x25,0x6c,0x5e,0xb1, + 0x30,0x44,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc1,0x02,0x20,0x0f,0xa5,0x27,0xfa,0x73,0x43,0xc0,0xbc,0x9e,0xc3,0x5a,0x62,0x78,0xbf,0xbf,0xf4,0xd8,0x33,0x01,0xb1,0x54,0xfc,0x4b,0xd1,0x4a,0xee,0x7e,0xb9,0x34,0x45,0xb5,0xf9, + 0x30,0x44,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc1,0x02,0x20,0x65,0x39,0xc0,0xad,0xad,0xd0,0x52,0x5f,0xf4,0x26,0x22,0x16,0x4c,0xe9,0x31,0x43,0x48,0xbd,0x08,0x63,0xb4,0xc8,0x0e,0x93,0x6b,0x23,0xca,0x04,0x14,0x26,0x46,0x71, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x5d,0x57,0x6e,0x73,0x57,0xa4,0x50,0x1d,0xdf,0xe9,0x2f,0x46,0x68,0x1b,0x20,0xa0,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc0, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x5d,0x57,0x6e,0x73,0x57,0xa4,0x50,0x1d,0xdf,0xe9,0x2f,0x46,0x68,0x1b,0x20,0xa0,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x5d,0x57,0x6e,0x73,0x57,0xa4,0x50,0x1d,0xdf,0xe9,0x2f,0x46,0x68,0x1b,0x20,0xa0, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x5d,0x57,0x6e,0x73,0x57,0xa4,0x50,0x1d,0xdf,0xe9,0x2f,0x46,0x68,0x1b,0x20,0xa0,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x5d,0x57,0x6e,0x73,0x57,0xa4,0x50,0x1d,0xdf,0xe9,0x2f,0x46,0x68,0x1b,0x20,0xa1, + 0x30,0x44,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xb8,0x02,0x20,0x44,0xa5,0xad,0x0b,0xd0,0x63,0x6d,0x9e,0x12,0xbc,0x9e,0x0a,0x6b,0xdd,0x5e,0x1b,0xba,0x77,0xf5,0x23,0x84,0x21,0x93,0xb3,0xb8,0x2e,0x44,0x8e,0x05,0xd5,0xf1,0x1e, + 0x30,0x44,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xb8,0x02,0x20,0x44,0xa5,0xad,0x0b,0xd0,0x63,0x6d,0x9e,0x12,0xbc,0x9e,0x0a,0x6b,0xdd,0x5e,0x1b,0xba,0x77,0xf5,0x23,0x84,0x21,0x93,0xb3,0xb8,0x2e,0x44,0x8e,0x05,0xd5,0xf1,0x1e, + 0x30,0x44,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xb8,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xb8, + 0x30,0x44,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xb8,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xb8, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x16,0xe1,0xe4,0x59,0x45,0x76,0x79,0xdf,0x5b,0x94,0x34,0xae,0x23,0xf4,0x74,0xb3,0xe8,0xd2,0xa7,0x0b,0xd6,0xb5,0xdb,0xe6,0x92,0xba,0x16,0xda,0x01,0xf1,0xfb,0x0a, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x1c,0x94,0x0f,0x31,0x3f,0x92,0x64,0x7b,0xe2,0x57,0xec,0xcd,0x7e,0xd0,0x8b,0x0b,0xae,0xf3,0xf0,0x47,0x8f,0x25,0x87,0x1b,0x53,0x63,0x53,0x02,0xc5,0xf6,0x31,0x4a, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x15,0xd9,0x4a,0x85,0x07,0x7b,0x49,0x3f,0x91,0xcb,0x71,0x01,0xec,0x63,0xe1,0xb0,0x1b,0xe5,0x8b,0x59,0x4e,0x85,0x5f,0x45,0x05,0x0a,0x8c,0x14,0x06,0x2d,0x68,0x9b, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x5b,0x1d,0x27,0xa7,0x69,0x4c,0x14,0x62,0x44,0xa5,0xad,0x0b,0xd0,0x63,0x6d,0x9d,0x9e,0xf3,0xb9,0xfb,0x58,0x38,0x54,0x18,0xd9,0xc9,0x82,0x10,0x50,0x77,0xd1,0xb7, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x2d,0x85,0x89,0x6b,0x3e,0xb9,0xdb,0xb5,0xa5,0x2f,0x42,0xf9,0xc9,0x26,0x1e,0xd3,0xfc,0x46,0x64,0x4e,0xc6,0x5f,0x06,0xad,0xe3,0xfd,0x78,0xf2,0x57,0xe4,0x34,0x32, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x5b,0x0b,0x12,0xd6,0x7d,0x73,0xb7,0x6b,0x4a,0x5e,0x85,0xf3,0x92,0x4c,0x3d,0xa7,0xf8,0x8c,0xc8,0x9d,0x8c,0xbe,0x0d,0x5b,0xc7,0xfa,0xf1,0xe4,0xaf,0xc8,0x68,0x64, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x69,0x4c,0x14,0x62,0x44,0xa5,0xad,0x0b,0xd0,0x63,0x6d,0x9e,0x12,0xbc,0x9e,0x09,0xe6,0x0e,0x68,0xb9,0x0d,0x0b,0x5e,0x6c,0x5d,0xdd,0xd0,0xcb,0x69,0x4d,0x87,0x99, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x3d,0x7f,0x48,0x7c,0x07,0xbf,0xc5,0xf3,0x08,0x46,0x93,0x8a,0x3d,0xce,0xf6,0x96,0x44,0x47,0x07,0xcf,0x96,0x77,0x25,0x4a,0x92,0xb0,0x6c,0x63,0xab,0x86,0x7d,0x22, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x6c,0x76,0x48,0xfc,0x0f,0xbf,0x8a,0x06,0xad,0xb8,0xb8,0x39,0xf9,0x7b,0x4f,0xf7,0xa8,0x00,0xf1,0x1b,0x1e,0x37,0xc5,0x93,0xb2,0x61,0x39,0x45,0x99,0x79,0x2b,0xa4, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x64,0x1c,0x9c,0x5d,0x79,0x0d,0xc0,0x9c,0xdd,0x3d,0xfa,0xbb,0x62,0xcd,0xf4,0x53,0xe6,0x97,0x47,0xa7,0xe3,0xd7,0xaa,0x1a,0x71,0x41,0x89,0xef,0x53,0x17,0x1a,0x99, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x29,0x79,0x8c,0x5c,0x45,0xbd,0xf5,0x8b,0x4a,0x7b,0x2f,0xdc,0x2c,0x46,0xab,0x4a,0xf1,0x21,0x8c,0x7e,0xeb,0x9f,0x0f,0x27,0xa8,0x8f,0x12,0x67,0x67,0x4d,0xe3,0xb0, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x0b,0x70,0xf2,0x2c,0xa2,0xbb,0x3c,0xef,0xad,0xca,0x1a,0x57,0x11,0xfa,0x3a,0x59,0xf4,0x69,0x53,0x85,0xeb,0x5a,0xed,0xf3,0x49,0x5d,0x0b,0x6d,0x00,0xf8,0xfd,0x85, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x16,0xe1,0xe4,0x59,0x45,0x76,0x79,0xdf,0x5b,0x94,0x34,0xae,0x23,0xf4,0x74,0xb3,0xe8,0xd2,0xa7,0x0b,0xd6,0xb5,0xdb,0xe6,0x92,0xba,0x16,0xda,0x01,0xf1,0xfb,0x0a, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x22,0x52,0xd6,0x85,0xe8,0x31,0xb6,0xcf,0x09,0x5e,0x4f,0x05,0x35,0xee,0xaf,0x0d,0xdd,0x3b,0xfa,0x91,0xc2,0x10,0xc9,0xd9,0xdc,0x17,0x22,0x47,0x02,0xea,0xf8,0x8f, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x75,0x13,0x5a,0xbd,0x7c,0x42,0x5b,0x60,0x37,0x1a,0x47,0x7f,0x09,0xce,0x0f,0x27,0x4f,0x64,0xa8,0xc6,0xb0,0x61,0xa0,0x7b,0x5d,0x63,0xe9,0x3c,0x65,0x04,0x6c,0x53, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x2a,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0x3e,0x3a,0x49,0xa2,0x3a,0x6d,0x8a,0xbe,0x95,0x46,0x1f,0x84,0x45,0x67,0x6b,0x17, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x3e,0x88,0x83,0x77,0xac,0x6c,0x71,0xac,0x9d,0xec,0x3f,0xdb,0x9b,0x56,0xc9,0xfe,0xaf,0x0c,0xfa,0xca,0x9f,0x82,0x7f,0xc5,0xeb,0x65,0xfc,0x3e,0xac,0x81,0x12,0x10, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x30,0xbb,0xb7,0x94,0xdb,0x58,0x83,0x63,0xb4,0x06,0x79,0xf6,0xc1,0x82,0xa5,0x0d,0x3c,0xe9,0x67,0x9a,0xcd,0xd3,0xff,0xbe,0x36,0xd7,0x81,0x3d,0xac,0xbd,0xc8,0x18, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x2c,0x37,0xfd,0x99,0x56,0x22,0xc4,0xfb,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc7,0xce,0xe7,0x45,0x11,0x0c,0xb4,0x5a,0xb5,0x58,0xed,0x7c,0x90,0xc1,0x5a,0x2f, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x7f,0xd9,0x95,0x62,0x2c,0x4f,0xb7,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x5d,0x88,0x3f,0xfa,0xb5,0xb3,0x26,0x52,0xcc,0xdc,0xaa,0x29,0x0f,0xcc,0xb9,0x7d, + 0x30,0x43,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x1f,0x4c,0xd5,0x3b,0xa7,0x60,0x8f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x9e,0x5c,0xf1,0x43,0xe2,0x53,0x96,0x26,0x19,0x0a,0x3a,0xb0,0x9c,0xce,0x47, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x56,0x22,0xc4,0xfb,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x92,0x8a,0x8f,0x1c,0x7a,0xc7,0xbe,0xc1,0x80,0x8b,0x9f,0x61,0xc0,0x1e,0xc3,0x27, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x44,0x10,0x41,0x04,0x10,0x41,0x04,0x10,0x41,0x04,0x10,0x41,0x04,0x10,0x41,0x03,0xb8,0x78,0x53,0xfd,0x3b,0x7d,0x3f,0x8e,0x17,0x51,0x25,0xb4,0x38,0x2f,0x25,0xed, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x27,0x39,0xce,0x73,0x9c,0xe7,0x39,0xce,0x73,0x9c,0xe7,0x39,0xce,0x73,0x9c,0xe7,0x05,0x56,0x02,0x98,0xd1,0xf2,0xf0,0x8d,0xc4,0x19,0xac,0x27,0x3a,0x5b,0x54,0xd9, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x48,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x31,0xc8,0x3a,0xe8,0x2e,0xbe,0x08,0x98,0x77,0x6b,0x4c,0x69,0xd1,0x1f,0x88,0xde, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x64,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x06,0xdd,0x3a,0x19,0xb8,0xd5,0xfb,0x87,0x52,0x35,0x96,0x3c,0x59,0x3b,0xd2,0xd3, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x6a,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0x3e,0x3a,0x49,0xa2,0x3a,0x6d,0x8a,0xbe,0x95,0x46,0x1f,0x84,0x45,0x67,0x6b,0x15, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x2a,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0x3e,0x3a,0x49,0xa2,0x3a,0x6d,0x8a,0xbe,0x95,0x46,0x1f,0x84,0x45,0x67,0x6b,0x17, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x3f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe, + 0x30,0x44,0x02,0x20,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x02,0x20,0x18,0x5d,0xdb,0xca,0x6d,0xac,0x41,0xb1,0xda,0x03,0x3c,0xfb,0x60,0xc1,0x52,0x86,0x9e,0x74,0xb3,0xcd,0x66,0xe9,0xff,0xdf,0x1b,0x6b,0xc0,0x9e,0xd6,0x5e,0xe4,0x0c, + 0x30,0x44,0x02,0x20,0x32,0xb0,0xd1,0x0d,0x8d,0x0e,0x04,0xbc,0x8d,0x4d,0x06,0x4d,0x27,0x06,0x99,0xe8,0x7c,0xff,0xc9,0xb4,0x9c,0x5c,0x20,0x73,0x0e,0x1c,0x26,0xf6,0x10,0x5d,0xdc,0xda,0x02,0x20,0x29,0xed,0x3d,0x67,0xb3,0xd5,0x05,0xbe,0x95,0x58,0x0d,0x77,0xd5,0xb7,0x92,0xb4,0x36,0x88,0x11,0x79,0xb2,0xb6,0xb2,0xe0,0x4c,0x5f,0xe5,0x92,0xd3,0x8d,0x82,0xd9, + 0x30,0x44,0x02,0x20,0x32,0xb0,0xd1,0x0d,0x8d,0x0e,0x04,0xbc,0x8d,0x4d,0x06,0x4d,0x27,0x06,0x99,0xe8,0x7c,0xff,0xc9,0xb4,0x9c,0x5c,0x20,0x73,0x0e,0x1c,0x26,0xf6,0x10,0x5d,0xdc,0xda,0x02,0x20,0x29,0xed,0x3d,0x67,0xb3,0xd5,0x05,0xbe,0x95,0x58,0x0d,0x77,0xd5,0xb7,0x92,0xb4,0x36,0x88,0x11,0x79,0xb2,0xb6,0xb2,0xe0,0x4c,0x5f,0xe5,0x92,0xd3,0x8d,0x82,0xd9, + 0x30,0x44,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc0,0x02,0x20,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x32,0xf2,0x22,0xf8,0xfa,0xef,0xdb,0x53,0x3f,0x26,0x5d,0x46,0x1c,0x29,0xa4,0x73,0x73, + 0x30,0x45,0x02,0x21,0x00,0xc6,0x04,0x7f,0x94,0x41,0xed,0x7d,0x6d,0x30,0x45,0x40,0x6e,0x95,0xc0,0x7c,0xd8,0x5c,0x77,0x8e,0x4b,0x8c,0xef,0x3c,0xa7,0xab,0xac,0x09,0xb9,0x5c,0x70,0x9e,0xe5,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc0, + 0x30,0x45,0x02,0x21,0x00,0xc6,0x04,0x7f,0x94,0x41,0xed,0x7d,0x6d,0x30,0x45,0x40,0x6e,0x95,0xc0,0x7c,0xd8,0x5c,0x77,0x8e,0x4b,0x8c,0xef,0x3c,0xa7,0xab,0xac,0x09,0xb9,0x5c,0x70,0x9e,0xe5,0x02,0x20,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x48,0xc7,0x9f,0xac,0xd4,0x32,0x14,0xc0,0x11,0x12,0x3c,0x1b,0x03,0xa9,0x34,0x12,0xa5, + 0x30,0x45,0x02,0x21,0x00,0xc6,0x04,0x7f,0x94,0x41,0xed,0x7d,0x6d,0x30,0x45,0x40,0x6e,0x95,0xc0,0x7c,0xd8,0x5c,0x77,0x8e,0x4b,0x8c,0xef,0x3c,0xa7,0xab,0xac,0x09,0xb9,0x5c,0x70,0x9e,0xe5,0x02,0x20,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x65,0xe4,0x45,0xf1,0xf5,0xdf,0xb6,0xa6,0x7e,0x4c,0xba,0x8c,0x38,0x53,0x48,0xe6,0xe7, + 0x30,0x45,0x02,0x21,0x00,0xc6,0x04,0x7f,0x94,0x41,0xed,0x7d,0x6d,0x30,0x45,0x40,0x6e,0x95,0xc0,0x7c,0xd8,0x5c,0x77,0x8e,0x4b,0x8c,0xef,0x3c,0xa7,0xab,0xac,0x09,0xb9,0x5c,0x70,0x9e,0xe5,0x02,0x20,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x65,0xe4,0x45,0xf1,0xf5,0xdf,0xb6,0xa6,0x7e,0x4c,0xba,0x8c,0x38,0x53,0x48,0xe6,0xe7, + 0x30,0x45,0x02,0x21,0x00,0xc6,0x04,0x7f,0x94,0x41,0xed,0x7d,0x6d,0x30,0x45,0x40,0x6e,0x95,0xc0,0x7c,0xd8,0x5c,0x77,0x8e,0x4b,0x8c,0xef,0x3c,0xa7,0xab,0xac,0x09,0xb9,0x5c,0x70,0x9e,0xe5,0x02,0x20,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x48,0xc7,0x9f,0xac,0xd4,0x32,0x14,0xc0,0x11,0x12,0x3c,0x1b,0x03,0xa9,0x34,0x12,0xa5, + 0x30,0x45,0x02,0x21,0x00,0xc6,0x04,0x7f,0x94,0x41,0xed,0x7d,0x6d,0x30,0x45,0x40,0x6e,0x95,0xc0,0x7c,0xd8,0x5c,0x77,0x8e,0x4b,0x8c,0xef,0x3c,0xa7,0xab,0xac,0x09,0xb9,0x5c,0x70,0x9e,0xe5,0x02,0x20,0x0e,0xb1,0x0e,0x5a,0xb9,0x5f,0x2f,0x27,0x53,0x48,0xd8,0x2a,0xd2,0xe4,0xd7,0x94,0x9c,0x81,0x93,0x80,0x0d,0x8c,0x9c,0x75,0xdf,0x58,0xe3,0x43,0xf0,0xeb,0xba,0x7b, + 0x30,0x44,0x02,0x20,0x79,0xbe,0x66,0x7e,0xf9,0xdc,0xbb,0xac,0x55,0xa0,0x62,0x95,0xce,0x87,0x0b,0x07,0x02,0x9b,0xfc,0xdb,0x2d,0xce,0x28,0xd9,0x59,0xf2,0x81,0x5b,0x16,0xf8,0x17,0x98,0x02,0x20,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x54,0xe8,0xe4,0xf4,0x4c,0xe5,0x18,0x35,0x69,0x3f,0xf0,0xca,0x2e,0xf0,0x12,0x15,0xc0, + 0x30,0x44,0x02,0x20,0x79,0xbe,0x66,0x7e,0xf9,0xdc,0xbb,0xac,0x55,0xa0,0x62,0x95,0xce,0x87,0x0b,0x07,0x02,0x9b,0xfc,0xdb,0x2d,0xce,0x28,0xd9,0x59,0xf2,0x81,0x5b,0x16,0xf8,0x17,0x98,0x02,0x20,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x48,0xc7,0x9f,0xac,0xd4,0x32,0x14,0xc0,0x11,0x12,0x3c,0x1b,0x03,0xa9,0x34,0x12,0xa5, + 0x30,0x44,0x02,0x20,0x79,0xbe,0x66,0x7e,0xf9,0xdc,0xbb,0xac,0x55,0xa0,0x62,0x95,0xce,0x87,0x0b,0x07,0x02,0x9b,0xfc,0xdb,0x2d,0xce,0x28,0xd9,0x59,0xf2,0x81,0x5b,0x16,0xf8,0x17,0x98,0x02,0x20,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x65,0xe4,0x45,0xf1,0xf5,0xdf,0xb6,0xa6,0x7e,0x4c,0xba,0x8c,0x38,0x53,0x48,0xe6,0xe7, + 0x30,0x44,0x02,0x20,0x79,0xbe,0x66,0x7e,0xf9,0xdc,0xbb,0xac,0x55,0xa0,0x62,0x95,0xce,0x87,0x0b,0x07,0x02,0x9b,0xfc,0xdb,0x2d,0xce,0x28,0xd9,0x59,0xf2,0x81,0x5b,0x16,0xf8,0x17,0x98,0x02,0x20,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x65,0xe4,0x45,0xf1,0xf5,0xdf,0xb6,0xa6,0x7e,0x4c,0xba,0x8c,0x38,0x53,0x48,0xe6,0xe7, + 0x30,0x44,0x02,0x20,0x79,0xbe,0x66,0x7e,0xf9,0xdc,0xbb,0xac,0x55,0xa0,0x62,0x95,0xce,0x87,0x0b,0x07,0x02,0x9b,0xfc,0xdb,0x2d,0xce,0x28,0xd9,0x59,0xf2,0x81,0x5b,0x16,0xf8,0x17,0x98,0x02,0x20,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x48,0xc7,0x9f,0xac,0xd4,0x32,0x14,0xc0,0x11,0x12,0x3c,0x1b,0x03,0xa9,0x34,0x12,0xa5, + 0x30,0x44,0x02,0x20,0x79,0xbe,0x66,0x7e,0xf9,0xdc,0xbb,0xac,0x55,0xa0,0x62,0x95,0xce,0x87,0x0b,0x07,0x02,0x9b,0xfc,0xdb,0x2d,0xce,0x28,0xd9,0x59,0xf2,0x81,0x5b,0x16,0xf8,0x17,0x98,0x02,0x20,0x0e,0xb1,0x0e,0x5a,0xb9,0x5f,0x2f,0x27,0x53,0x48,0xd8,0x2a,0xd2,0xe4,0xd7,0x94,0x9c,0x81,0x93,0x80,0x0d,0x8c,0x9c,0x75,0xdf,0x58,0xe3,0x43,0xf0,0xeb,0xba,0x7b, + 0x30,0x45,0x02,0x21,0x00,0xbb,0x5a,0x52,0xf4,0x2f,0x9c,0x92,0x61,0xed,0x43,0x61,0xf5,0x94,0x22,0xa1,0xe3,0x00,0x36,0xe7,0xc3,0x2b,0x27,0x0c,0x88,0x07,0xa4,0x19,0xfe,0xca,0x60,0x50,0x23,0x02,0x20,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x63,0xcf,0xd6,0x6a,0x19,0x0a,0x60,0x08,0x89,0x1e,0x0d,0x81,0xd4,0x9a,0x09,0x52, + 0x30,0x44,0x02,0x20,0x44,0xa5,0xad,0x0b,0xd0,0x63,0x6d,0x9e,0x12,0xbc,0x9e,0x0a,0x6b,0xdd,0x5e,0x1b,0xba,0x77,0xf5,0x23,0x84,0x21,0x93,0xb3,0xb8,0x2e,0x44,0x8e,0x05,0xd5,0xf1,0x1e,0x02,0x20,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x63,0xcf,0xd6,0x6a,0x19,0x0a,0x60,0x08,0x89,0x1e,0x0d,0x81,0xd4,0x9a,0x09,0x52, + 0x30,0x45,0x02,0x21,0x00,0xbb,0x5a,0x52,0xf4,0x2f,0x9c,0x92,0x61,0xed,0x43,0x61,0xf5,0x94,0x22,0xa1,0xe3,0x00,0x36,0xe7,0xc3,0x2b,0x27,0x0c,0x88,0x07,0xa4,0x19,0xfe,0xca,0x60,0x50,0x23,0x02,0x20,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x63,0xcf,0xd6,0x6a,0x19,0x0a,0x60,0x08,0x89,0x1e,0x0d,0x81,0xd4,0x9a,0x09,0x52, + 0x30,0x44,0x02,0x20,0x44,0xa5,0xad,0x0b,0xd0,0x63,0x6d,0x9e,0x12,0xbc,0x9e,0x0a,0x6b,0xdd,0x5e,0x1b,0xba,0x77,0xf5,0x23,0x84,0x21,0x93,0xb3,0xb8,0x2e,0x44,0x8e,0x05,0xd5,0xf1,0x1e,0x02,0x20,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x92,0x49,0x24,0x63,0xcf,0xd6,0x6a,0x19,0x0a,0x60,0x08,0x89,0x1e,0x0d,0x81,0xd4,0x9a,0x09,0x52, + 0x30,0x45,0x02,0x21,0x00,0xf8,0x0a,0xe4,0xf9,0x6c,0xdb,0xc9,0xd8,0x53,0xf8,0x3d,0x47,0xaa,0xe2,0x25,0xbf,0x40,0x7d,0x51,0xc5,0x6b,0x77,0x76,0xcd,0x67,0xd0,0xdc,0x19,0x5d,0x99,0xa9,0xdc,0x02,0x20,0x4c,0xfc,0x1d,0x94,0x1e,0x08,0xcb,0x9a,0xce,0xad,0xde,0x0f,0x4c,0xce,0xad,0x76,0xb3,0x0d,0x33,0x2f,0xc4,0x42,0x11,0x5d,0x50,0xe6,0x73,0xe2,0x86,0x86,0xb7,0x0b, + 0x30,0x44,0x02,0x20,0x10,0x9c,0xd8,0xae,0x03,0x74,0x35,0x89,0x84,0xa8,0x24,0x9c,0x0a,0x84,0x36,0x28,0xf2,0x83,0x5f,0xfa,0xd1,0xdf,0x1a,0x9a,0x69,0xaa,0x2f,0xe7,0x23,0x55,0x54,0x5c,0x02,0x20,0x53,0x90,0xff,0x25,0x0a,0xc4,0x27,0x4e,0x1c,0xb2,0x5c,0xd6,0xca,0x64,0x91,0xf6,0xb9,0x12,0x81,0xe3,0x2f,0x5b,0x26,0x4d,0x87,0x97,0x7a,0xed,0x4a,0x94,0xe7,0x7b, + 0x30,0x45,0x02,0x21,0x00,0xd0,0x35,0xee,0x1f,0x17,0xfd,0xb0,0xb2,0x68,0x1b,0x16,0x3e,0x33,0xc3,0x59,0x93,0x26,0x59,0x99,0x0a,0xf7,0x7d,0xca,0x63,0x20,0x12,0xb3,0x0b,0x27,0xa0,0x57,0xb3,0x02,0x20,0x19,0x39,0xd9,0xf3,0xb2,0x85,0x8b,0xc1,0x3e,0x34,0x74,0xcb,0x50,0xe6,0xa8,0x2b,0xe4,0x4f,0xaa,0x71,0x94,0x0f,0x87,0x6c,0x1c,0xba,0x4c,0x3e,0x98,0x92,0x02,0xb6, + 0x30,0x44,0x02,0x20,0x4f,0x05,0x3f,0x56,0x3a,0xd3,0x4b,0x74,0xfd,0x8c,0x99,0x34,0xce,0x59,0xe7,0x9c,0x2e,0xb8,0xe6,0xec,0xa0,0xfe,0xf5,0xb3,0x23,0xca,0x67,0xd5,0xac,0x7e,0xd2,0x38,0x02,0x20,0x4d,0x4b,0x05,0xda,0xa0,0x71,0x9e,0x77,0x3d,0x86,0x17,0xdc,0xe5,0x63,0x1c,0x5f,0xd6,0xf5,0x9c,0x9b,0xdc,0x74,0x8e,0x4b,0x55,0xc9,0x70,0x04,0x0a,0xf0,0x1b,0xe5, + 0x30,0x44,0x02,0x20,0x6d,0x6a,0x4f,0x55,0x6c,0xcc,0xe1,0x54,0xe7,0xfb,0x9f,0x19,0xe7,0x6c,0x3d,0xec,0xa1,0x3d,0x59,0xcc,0x2a,0xeb,0x4e,0xca,0xd9,0x68,0xaa,0xb2,0xde,0xd4,0x59,0x65,0x02,0x20,0x53,0xb9,0xfa,0x74,0x80,0x3e,0xde,0x0f,0xc4,0x44,0x1b,0xf6,0x83,0xd5,0x6c,0x56,0x4d,0x3e,0x27,0x4e,0x09,0xcc,0xf4,0x73,0x90,0xba,0xdd,0x14,0x71,0xc0,0x5f,0xb7, + 0x30,0x44,0x02,0x21,0x00,0xaa,0xd5,0x03,0xde,0x9b,0x9f,0xd6,0x6b,0x94,0x8e,0x9a,0xcf,0x59,0x6f,0x0a,0x0e,0x65,0xe7,0x00,0xb2,0x8b,0x26,0xec,0x56,0xe6,0xe4,0x5e,0x84,0x64,0x89,0xb3,0xc4,0x02,0x1f,0x0d,0xdc,0x3a,0x2f,0x89,0xab,0xb8,0x17,0xbb,0x85,0xc0,0x62,0xce,0x02,0xf8,0x23,0xc6,0x3f,0xc2,0x6b,0x26,0x9e,0x0b,0xc9,0xb8,0x4d,0x81,0xa5,0xaa,0x12,0x3d, + 0x30,0x45,0x02,0x21,0x00,0x91,0x82,0xce,0xbd,0x3b,0xb8,0xab,0x57,0x2e,0x16,0x71,0x74,0x39,0x72,0x09,0xef,0x4b,0x1d,0x43,0x9a,0xf3,0xb2,0x00,0xcd,0xf0,0x03,0x62,0x00,0x89,0xe4,0x32,0x25,0x02,0x20,0x54,0x47,0x7c,0x98,0x2e,0xa0,0x19,0xd2,0xe1,0x00,0x04,0x97,0xfc,0x25,0xfc,0xee,0x1b,0xcc,0xae,0x55,0xf2,0xac,0x27,0x53,0x0a,0xe5,0x3b,0x29,0xc4,0xb3,0x56,0xa4, + 0x30,0x44,0x02,0x20,0x38,0x54,0xa3,0x99,0x8a,0xeb,0xdf,0x2d,0xbc,0x28,0xad,0xac,0x41,0x81,0x46,0x2c,0xca,0xc7,0x87,0x39,0x07,0xab,0x7f,0x21,0x2c,0x42,0xdb,0x0e,0x69,0xb5,0x6e,0xd8,0x02,0x20,0x3e,0xd3,0xf6,0xb8,0xa3,0x88,0xd0,0x2f,0x3e,0x4d,0xf9,0xf2,0xae,0x9c,0x1b,0xd2,0xc3,0x91,0x6a,0x68,0x64,0x60,0xdf,0xfc,0xd4,0x29,0x09,0xcd,0x7f,0x82,0x05,0x8e, + 0x30,0x45,0x02,0x21,0x00,0xe9,0x4d,0xbd,0xc3,0x87,0x95,0xfe,0x5c,0x90,0x4d,0x8f,0x16,0xd9,0x69,0xd3,0xb5,0x87,0xf0,0xa2,0x5d,0x2d,0xe9,0x0b,0x6d,0x8c,0x5c,0x53,0xff,0x88,0x7e,0x36,0x07,0x02,0x20,0x7a,0x94,0x73,0x69,0xc1,0x64,0x97,0x25,0x21,0xbb,0x8a,0xf4,0x06,0x81,0x3b,0x2d,0x9f,0x94,0xd2,0xae,0xaa,0x53,0xd4,0xc2,0x15,0xaa,0xa0,0xa2,0x57,0x8a,0x2c,0x5d, + 0x30,0x44,0x02,0x20,0x49,0xfc,0x10,0x2a,0x08,0xca,0x47,0xb6,0x0e,0x08,0x58,0xcd,0x02,0x84,0xd2,0x2c,0xdd,0xd7,0x23,0x3f,0x94,0xaa,0xff,0xbb,0x2d,0xb1,0xdd,0x2c,0xf0,0x84,0x25,0xe1,0x02,0x20,0x5b,0x16,0xfc,0xa5,0xa1,0x2c,0xdb,0x39,0x70,0x16,0x97,0xad,0x8e,0x39,0xff,0xd6,0xbd,0xec,0x00,0x24,0x29,0x8a,0xfa,0xa2,0x32,0x6a,0xea,0x09,0x20,0x0b,0x14,0xd6, + 0x30,0x44,0x02,0x20,0x41,0xef,0xa7,0xd3,0xf0,0x5a,0x00,0x10,0x67,0x5f,0xcb,0x91,0x8a,0x45,0xc6,0x93,0xda,0x4b,0x34,0x8d,0xf2,0x1a,0x59,0xd6,0xf9,0xcd,0x73,0xe0,0xd8,0x31,0xd6,0x7a,0x02,0x20,0x44,0x54,0xad,0xa6,0x93,0xe5,0xe2,0x6b,0x7b,0xd6,0x93,0x23,0x6d,0x34,0x0f,0x80,0x54,0x5c,0x83,0x45,0x77,0xb6,0xf7,0x3d,0x37,0x8c,0x7b,0xcc,0x53,0x42,0x44,0xda, + 0x30,0x45,0x02,0x21,0x00,0xb6,0x15,0x69,0x8c,0x35,0x8b,0x35,0x92,0x0d,0xd8,0x83,0xec,0xa6,0x25,0xa6,0xc5,0xf7,0x56,0x39,0x70,0xcd,0xfc,0x37,0x8f,0x8f,0xe0,0xce,0xe1,0x70,0x92,0x14,0x4c,0x02,0x20,0x25,0xf4,0x7b,0x32,0x6b,0x5b,0xe1,0xfb,0x61,0x0b,0x88,0x51,0x53,0xea,0x84,0xd4,0x1e,0xb4,0x71,0x6b,0xe6,0x6a,0x99,0x4e,0x87,0x79,0x98,0x9d,0xf1,0xc8,0x63,0xd4, + 0x30,0x45,0x02,0x21,0x00,0x87,0xcf,0x8c,0x0e,0xb8,0x2d,0x44,0xf6,0x9c,0x60,0xa2,0xff,0x54,0x57,0xd3,0xaa,0xa3,0x22,0xe7,0xec,0x61,0xae,0x5a,0xec,0xfd,0x67,0x8a,0xe1,0xc1,0x93,0x2b,0x0e,0x02,0x20,0x3a,0xdd,0x3b,0x11,0x58,0x15,0x04,0x7d,0x6e,0xb3,0x40,0xa3,0xe0,0x08,0x98,0x9e,0xaa,0x0f,0x87,0x08,0xd1,0x79,0x48,0x14,0x72,0x90,0x94,0xd0,0x8d,0x24,0x60,0xd3, + 0x30,0x44,0x02,0x20,0x62,0xf4,0x8e,0xf7,0x1a,0xce,0x27,0xbf,0x5a,0x01,0x83,0x4d,0xe1,0xf7,0xe3,0xf9,0x48,0xb9,0xdc,0xe1,0xca,0x1e,0x91,0x1d,0x5e,0x13,0xd3,0xb1,0x04,0x47,0x1d,0x82,0x02,0x20,0x5e,0xa8,0xf3,0x3f,0x0c,0x77,0x89,0x72,0xc4,0x58,0x20,0x80,0xde,0xda,0x9b,0x34,0x18,0x57,0xdd,0x64,0x51,0x4f,0x08,0x49,0xa0,0x5f,0x69,0x64,0xc2,0xe3,0x40,0x22, + 0x30,0x45,0x02,0x21,0x00,0xf6,0xb0,0xe2,0xf6,0xfe,0x02,0x0c,0xf7,0xc0,0xc2,0x01,0x37,0x43,0x43,0x44,0xed,0x7a,0xdd,0x6c,0x4b,0xe5,0x18,0x61,0xe2,0xd1,0x4c,0xbd,0xa4,0x72,0xa6,0xff,0xb4,0x02,0x20,0x64,0x16,0xc8,0xdd,0x3e,0x5c,0x52,0x82,0xb3,0x06,0xe8,0xdc,0x8f,0xf3,0x4a,0xb6,0x4c,0xc9,0x95,0x49,0x23,0x2d,0x67,0x8d,0x71,0x44,0x02,0xeb,0x6c,0xa7,0xaa,0x0f, + 0x30,0x45,0x02,0x21,0x00,0xdb,0x09,0xd8,0x46,0x0f,0x05,0xef,0xf2,0x3b,0xc7,0xe4,0x36,0xb6,0x7d,0xa5,0x63,0xfa,0x4b,0x4e,0xdb,0x58,0xac,0x24,0xce,0x20,0x1f,0xa8,0xa3,0x58,0x12,0x50,0x57,0x02,0x20,0x46,0xda,0x11,0x67,0x54,0x60,0x29,0x40,0xc8,0x99,0x9c,0x8d,0x66,0x5f,0x78,0x6c,0x50,0xf5,0x77,0x2c,0x0a,0x3c,0xdb,0xda,0x07,0x5e,0x77,0xea,0xbc,0x64,0xdf,0x16, + 0x30,0x44,0x02,0x20,0x59,0x2c,0x41,0xe1,0x65,0x17,0xf1,0x2f,0xca,0xbd,0x98,0x26,0x76,0x74,0xf9,0x74,0xb5,0x88,0xe9,0xf3,0x5d,0x35,0x40,0x6c,0x1a,0x7b,0xb2,0xed,0x1d,0x19,0xb7,0xb8,0x02,0x20,0x3e,0x65,0xa0,0x6b,0xd9,0xf8,0x3c,0xaa,0xeb,0x7b,0x00,0xf2,0x36,0x8d,0x7e,0x0d,0xec,0xe6,0xb1,0x22,0x21,0x26,0x9a,0x9b,0x5b,0x76,0x51,0x98,0xf8,0x40,0xa3,0xa1, + 0x30,0x45,0x02,0x21,0x00,0xbe,0x0d,0x70,0x88,0x7d,0x5e,0x40,0x82,0x1a,0x61,0xb6,0x80,0x47,0xde,0x4e,0xa0,0x3d,0xeb,0xfd,0xf5,0x1c,0xdf,0x4d,0x4b,0x19,0x55,0x58,0xb9,0x59,0xa0,0x32,0xb2,0x02,0x20,0x7d,0x99,0x4b,0x2d,0x8f,0x1d,0xbb,0xeb,0x13,0x53,0x4e,0xb3,0xf6,0xe5,0xdc,0xcd,0x85,0xf5,0xc4,0x13,0x3c,0x27,0xd9,0xe6,0x42,0x71,0xb1,0x82,0x6c,0xe1,0xf6,0x7d, + 0x30,0x45,0x02,0x21,0x00,0xfa,0xe9,0x2d,0xfc,0xb2,0xee,0x39,0x2d,0x27,0x0a,0xf3,0xa5,0x73,0x9f,0xaa,0x26,0xd4,0xf9,0x7b,0xfd,0x39,0xed,0x3c,0xbe,0xe4,0xd2,0x9e,0x26,0xaf,0x3b,0x20,0x6a,0x02,0x20,0x6c,0x9b,0xa3,0x7f,0x9f,0xaa,0x6a,0x1f,0xd3,0xf6,0x5f,0x23,0xb4,0xe8,0x53,0xd4,0x69,0x2a,0x72,0x74,0x24,0x0a,0x12,0xdb,0x7b,0xa3,0x88,0x48,0x30,0x63,0x0d,0x16, + 0x30,0x44,0x02,0x20,0x17,0x6a,0x25,0x57,0x56,0x6f,0xfa,0x51,0x8b,0x11,0x22,0x66,0x94,0xeb,0x98,0x02,0xed,0x20,0x98,0xbf,0xe2,0x78,0xe5,0x57,0x0f,0xe1,0xd5,0xd7,0xaf,0x18,0xa9,0x43,0x02,0x20,0x12,0x91,0xdf,0x6a,0x0e,0xd5,0xfc,0x0d,0x15,0x09,0x8e,0x70,0xbc,0xf1,0x3a,0x00,0x92,0x84,0xdf,0xd0,0x68,0x9d,0x3b,0xb4,0xbe,0x6c,0xee,0xb9,0xbe,0x14,0x87,0xc4, + 0x30,0x44,0x02,0x20,0x60,0xbe,0x20,0xc3,0xdb,0xc1,0x62,0xdd,0x34,0xd2,0x67,0x80,0x62,0x1c,0x10,0x4b,0xbe,0x5d,0xac,0xe6,0x30,0x17,0x1b,0x2d,0xae,0xf0,0xd8,0x26,0x40,0x9e,0xe5,0xc2,0x02,0x20,0x42,0x7f,0x7e,0x4d,0x88,0x9d,0x54,0x91,0x70,0xbd,0xa6,0xa9,0x40,0x9f,0xb1,0xcb,0x8b,0x0e,0x76,0x3d,0x13,0xee,0xa7,0xbd,0x97,0xf6,0x4c,0xf4,0x1d,0xc6,0xe4,0x97, + 0x30,0x45,0x02,0x21,0x00,0xed,0xf0,0x3c,0xf6,0x3f,0x65,0x88,0x83,0x28,0x9a,0x1a,0x59,0x3d,0x10,0x07,0x89,0x5b,0x9f,0x23,0x6d,0x27,0xc9,0xc1,0xf1,0x31,0x30,0x89,0xaa,0xed,0x6b,0x16,0xae,0x02,0x20,0x1a,0x4d,0xd6,0xfc,0x08,0x14,0xdc,0x52,0x3d,0x1f,0xef,0xa8,0x1c,0x64,0xfb,0xf5,0xe6,0x18,0xe6,0x51,0xe7,0x09,0x6f,0xcc,0xad,0xbb,0x94,0xcd,0x48,0xe5,0xe0,0xcd}; + +static const wycheproof_ecdsa_testvector testvectors[SECP256K1_ECDSA_WYCHEPROOF_NUMBER_TESTVECTORS] = { + /* tcId: 1. Signature malleability */ + {0, 0, 6, 0, 72, 0 }, + /* tcId: 2. valid */ + {0, 0, 6, 72, 71, 1 }, + /* tcId: 3. length of sequence [r, s] uses long form encoding */ + {0, 0, 6, 143, 72, 0 }, + /* tcId: 4. length of sequence [r, s] contains a leading 0 */ + {0, 0, 6, 215, 73, 0 }, + /* tcId: 5. length of sequence [r, s] uses 70 instead of 69 */ + {0, 0, 6, 288, 71, 0 }, + /* tcId: 6. length of sequence [r, s] uses 68 instead of 69 */ + {0, 0, 6, 359, 71, 0 }, + /* tcId: 7. uint32 overflow in length of sequence [r, s] */ + {0, 0, 6, 430, 76, 0 }, + /* tcId: 8. uint64 overflow in length of sequence [r, s] */ + {0, 0, 6, 506, 80, 0 }, + /* tcId: 9. length of sequence [r, s] = 2**31 - 1 */ + {0, 0, 6, 586, 75, 0 }, + /* tcId: 10. length of sequence [r, s] = 2**31 */ + {0, 0, 6, 661, 75, 0 }, + /* tcId: 11. length of sequence [r, s] = 2**32 - 1 */ + {0, 0, 6, 736, 75, 0 }, + /* tcId: 12. length of sequence [r, s] = 2**40 - 1 */ + {0, 0, 6, 811, 76, 0 }, + /* tcId: 13. length of sequence [r, s] = 2**64 - 1 */ + {0, 0, 6, 887, 79, 0 }, + /* tcId: 14. incorrect length of sequence [r, s] */ + {0, 0, 6, 966, 71, 0 }, + /* tcId: 15. replaced sequence [r, s] by an indefinite length tag without termination */ + {0, 0, 6, 1037, 71, 0 }, + /* tcId: 16. removing sequence [r, s] */ + {0, 0, 6, 1108, 0, 0 }, + /* tcId: 17. lonely sequence tag */ + {0, 0, 6, 1108, 1, 0 }, + /* tcId: 18. appending 0's to sequence [r, s] */ + {0, 0, 6, 1109, 73, 0 }, + /* tcId: 19. prepending 0's to sequence [r, s] */ + {0, 0, 6, 1182, 73, 0 }, + /* tcId: 20. appending unused 0's to sequence [r, s] */ + {0, 0, 6, 1255, 73, 0 }, + /* tcId: 21. appending null value to sequence [r, s] */ + {0, 0, 6, 1328, 73, 0 }, + /* tcId: 22. prepending garbage to sequence [r, s] */ + {0, 0, 6, 1401, 76, 0 }, + /* tcId: 23. prepending garbage to sequence [r, s] */ + {0, 0, 6, 1477, 75, 0 }, + /* tcId: 24. appending garbage to sequence [r, s] */ + {0, 0, 6, 1552, 79, 0 }, + /* tcId: 25. including undefined tags */ + {0, 0, 6, 1631, 79, 0 }, + /* tcId: 26. including undefined tags */ + {0, 0, 6, 1710, 79, 0 }, + /* tcId: 27. including undefined tags */ + {0, 0, 6, 1789, 79, 0 }, + /* tcId: 28. truncated length of sequence [r, s] */ + {0, 0, 6, 1868, 2, 0 }, + /* tcId: 29. including undefined tags to sequence [r, s] */ + {0, 0, 6, 1870, 77, 0 }, + /* tcId: 30. using composition with indefinite length for sequence [r, s] */ + {0, 0, 6, 1947, 75, 0 }, + /* tcId: 31. using composition with wrong tag for sequence [r, s] */ + {0, 0, 6, 2022, 75, 0 }, + /* tcId: 32. Replacing sequence [r, s] with NULL */ + {0, 0, 6, 2097, 2, 0 }, + /* tcId: 33. changing tag value of sequence [r, s] */ + {0, 0, 6, 2099, 71, 0 }, + /* tcId: 34. changing tag value of sequence [r, s] */ + {0, 0, 6, 2170, 71, 0 }, + /* tcId: 35. changing tag value of sequence [r, s] */ + {0, 0, 6, 2241, 71, 0 }, + /* tcId: 36. changing tag value of sequence [r, s] */ + {0, 0, 6, 2312, 71, 0 }, + /* tcId: 37. changing tag value of sequence [r, s] */ + {0, 0, 6, 2383, 71, 0 }, + /* tcId: 38. dropping value of sequence [r, s] */ + {0, 0, 6, 2454, 2, 0 }, + /* tcId: 39. using composition for sequence [r, s] */ + {0, 0, 6, 2456, 75, 0 }, + /* tcId: 40. truncated sequence [r, s] */ + {0, 0, 6, 2531, 70, 0 }, + /* tcId: 41. truncated sequence [r, s] */ + {0, 0, 6, 2601, 70, 0 }, + /* tcId: 42. sequence [r, s] of size 4166 to check for overflows */ + {0, 0, 6, 2671, 4170, 0 }, + /* tcId: 43. indefinite length */ + {0, 0, 6, 6841, 73, 0 }, + /* tcId: 44. indefinite length with truncated delimiter */ + {0, 0, 6, 6914, 72, 0 }, + /* tcId: 45. indefinite length with additional element */ + {0, 0, 6, 6986, 75, 0 }, + /* tcId: 46. indefinite length with truncated element */ + {0, 0, 6, 7061, 77, 0 }, + /* tcId: 47. indefinite length with garbage */ + {0, 0, 6, 7138, 77, 0 }, + /* tcId: 48. indefinite length with nonempty EOC */ + {0, 0, 6, 7215, 75, 0 }, + /* tcId: 49. prepend empty sequence */ + {0, 0, 6, 7290, 73, 0 }, + /* tcId: 50. append empty sequence */ + {0, 0, 6, 7363, 73, 0 }, + /* tcId: 51. append zero */ + {0, 0, 6, 7436, 74, 0 }, + /* tcId: 52. append garbage with high tag number */ + {0, 0, 6, 7510, 74, 0 }, + /* tcId: 53. append null with explicit tag */ + {0, 0, 6, 7584, 75, 0 }, + /* tcId: 54. append null with implicit tag */ + {0, 0, 6, 7659, 73, 0 }, + /* tcId: 55. sequence of sequence */ + {0, 0, 6, 7732, 73, 0 }, + /* tcId: 56. truncated sequence: removed last 1 elements */ + {0, 0, 6, 7805, 37, 0 }, + /* tcId: 57. repeating element in sequence */ + {0, 0, 6, 7842, 105, 0 }, + /* tcId: 58. flipped bit 0 in r */ + {0, 0, 6, 7947, 69, 0 }, + /* tcId: 59. flipped bit 32 in r */ + {0, 0, 6, 8016, 69, 0 }, + /* tcId: 60. flipped bit 48 in r */ + {0, 0, 6, 8085, 69, 0 }, + /* tcId: 61. flipped bit 64 in r */ + {0, 0, 6, 8154, 69, 0 }, + /* tcId: 62. length of r uses long form encoding */ + {0, 0, 6, 8223, 72, 0 }, + /* tcId: 63. length of r contains a leading 0 */ + {0, 0, 6, 8295, 73, 0 }, + /* tcId: 64. length of r uses 34 instead of 33 */ + {0, 0, 6, 8368, 71, 0 }, + /* tcId: 65. length of r uses 32 instead of 33 */ + {0, 0, 6, 8439, 71, 0 }, + /* tcId: 66. uint32 overflow in length of r */ + {0, 0, 6, 8510, 76, 0 }, + /* tcId: 67. uint64 overflow in length of r */ + {0, 0, 6, 8586, 80, 0 }, + /* tcId: 68. length of r = 2**31 - 1 */ + {0, 0, 6, 8666, 75, 0 }, + /* tcId: 69. length of r = 2**31 */ + {0, 0, 6, 8741, 75, 0 }, + /* tcId: 70. length of r = 2**32 - 1 */ + {0, 0, 6, 8816, 75, 0 }, + /* tcId: 71. length of r = 2**40 - 1 */ + {0, 0, 6, 8891, 76, 0 }, + /* tcId: 72. length of r = 2**64 - 1 */ + {0, 0, 6, 8967, 79, 0 }, + /* tcId: 73. incorrect length of r */ + {0, 0, 6, 9046, 71, 0 }, + /* tcId: 74. replaced r by an indefinite length tag without termination */ + {0, 0, 6, 9117, 71, 0 }, + /* tcId: 75. removing r */ + {0, 0, 6, 9188, 36, 0 }, + /* tcId: 76. lonely integer tag */ + {0, 0, 6, 9224, 37, 0 }, + /* tcId: 77. lonely integer tag */ + {0, 0, 6, 9261, 38, 0 }, + /* tcId: 78. appending 0's to r */ + {0, 0, 6, 9299, 73, 0 }, + /* tcId: 79. prepending 0's to r */ + {0, 0, 6, 9372, 73, 0 }, + /* tcId: 80. appending unused 0's to r */ + {0, 0, 6, 9445, 73, 0 }, + /* tcId: 81. appending null value to r */ + {0, 0, 6, 9518, 73, 0 }, + /* tcId: 82. prepending garbage to r */ + {0, 0, 6, 9591, 76, 0 }, + /* tcId: 83. prepending garbage to r */ + {0, 0, 6, 9667, 75, 0 }, + /* tcId: 84. appending garbage to r */ + {0, 0, 6, 9742, 79, 0 }, + /* tcId: 85. truncated length of r */ + {0, 0, 6, 9821, 38, 0 }, + /* tcId: 86. including undefined tags to r */ + {0, 0, 6, 9859, 77, 0 }, + /* tcId: 87. using composition with indefinite length for r */ + {0, 0, 6, 9936, 75, 0 }, + /* tcId: 88. using composition with wrong tag for r */ + {0, 0, 6, 10011, 75, 0 }, + /* tcId: 89. Replacing r with NULL */ + {0, 0, 6, 10086, 38, 0 }, + /* tcId: 90. changing tag value of r */ + {0, 0, 6, 10124, 71, 0 }, + /* tcId: 91. changing tag value of r */ + {0, 0, 6, 10195, 71, 0 }, + /* tcId: 92. changing tag value of r */ + {0, 0, 6, 10266, 71, 0 }, + /* tcId: 93. changing tag value of r */ + {0, 0, 6, 10337, 71, 0 }, + /* tcId: 94. changing tag value of r */ + {0, 0, 6, 10408, 71, 0 }, + /* tcId: 95. dropping value of r */ + {0, 0, 6, 10479, 38, 0 }, + /* tcId: 96. using composition for r */ + {0, 0, 6, 10517, 75, 0 }, + /* tcId: 97. modifying first byte of r */ + {0, 0, 6, 10592, 71, 0 }, + /* tcId: 98. modifying last byte of r */ + {0, 0, 6, 10663, 71, 0 }, + /* tcId: 99. truncated r */ + {0, 0, 6, 10734, 70, 0 }, + /* tcId: 100. truncated r */ + {0, 0, 6, 10804, 70, 0 }, + /* tcId: 101. r of size 4130 to check for overflows */ + {0, 0, 6, 10874, 4172, 0 }, + /* tcId: 102. leading ff in r */ + {0, 0, 6, 15046, 72, 0 }, + /* tcId: 103. replaced r by infinity */ + {0, 0, 6, 15118, 39, 0 }, + /* tcId: 104. replacing r with zero */ + {0, 0, 6, 15157, 39, 0 }, + /* tcId: 105. flipped bit 0 in s */ + {0, 0, 6, 15196, 69, 0 }, + /* tcId: 106. flipped bit 32 in s */ + {0, 0, 6, 15265, 69, 0 }, + /* tcId: 107. flipped bit 48 in s */ + {0, 0, 6, 15334, 69, 0 }, + /* tcId: 108. flipped bit 64 in s */ + {0, 0, 6, 15403, 69, 0 }, + /* tcId: 109. length of s uses long form encoding */ + {0, 0, 6, 15472, 72, 0 }, + /* tcId: 110. length of s contains a leading 0 */ + {0, 0, 6, 15544, 73, 0 }, + /* tcId: 111. length of s uses 33 instead of 32 */ + {0, 0, 6, 15617, 71, 0 }, + /* tcId: 112. length of s uses 31 instead of 32 */ + {0, 0, 6, 15688, 71, 0 }, + /* tcId: 113. uint32 overflow in length of s */ + {0, 0, 6, 15759, 76, 0 }, + /* tcId: 114. uint64 overflow in length of s */ + {0, 0, 6, 15835, 80, 0 }, + /* tcId: 115. length of s = 2**31 - 1 */ + {0, 0, 6, 15915, 75, 0 }, + /* tcId: 116. length of s = 2**31 */ + {0, 0, 6, 15990, 75, 0 }, + /* tcId: 117. length of s = 2**32 - 1 */ + {0, 0, 6, 16065, 75, 0 }, + /* tcId: 118. length of s = 2**40 - 1 */ + {0, 0, 6, 16140, 76, 0 }, + /* tcId: 119. length of s = 2**64 - 1 */ + {0, 0, 6, 16216, 79, 0 }, + /* tcId: 120. incorrect length of s */ + {0, 0, 6, 16295, 71, 0 }, + /* tcId: 121. replaced s by an indefinite length tag without termination */ + {0, 0, 6, 16366, 71, 0 }, + /* tcId: 122. appending 0's to s */ + {0, 0, 6, 16437, 73, 0 }, + /* tcId: 123. prepending 0's to s */ + {0, 0, 6, 16510, 73, 0 }, + /* tcId: 124. appending null value to s */ + {0, 0, 6, 16583, 73, 0 }, + /* tcId: 125. prepending garbage to s */ + {0, 0, 6, 16656, 76, 0 }, + /* tcId: 126. prepending garbage to s */ + {0, 0, 6, 16732, 75, 0 }, + /* tcId: 127. appending garbage to s */ + {0, 0, 6, 16807, 79, 0 }, + /* tcId: 128. truncated length of s */ + {0, 0, 6, 16886, 39, 0 }, + /* tcId: 129. including undefined tags to s */ + {0, 0, 6, 16925, 77, 0 }, + /* tcId: 130. using composition with indefinite length for s */ + {0, 0, 6, 17002, 75, 0 }, + /* tcId: 131. using composition with wrong tag for s */ + {0, 0, 6, 17077, 75, 0 }, + /* tcId: 132. Replacing s with NULL */ + {0, 0, 6, 17152, 39, 0 }, + /* tcId: 133. changing tag value of s */ + {0, 0, 6, 17191, 71, 0 }, + /* tcId: 134. changing tag value of s */ + {0, 0, 6, 17262, 71, 0 }, + /* tcId: 135. changing tag value of s */ + {0, 0, 6, 17333, 71, 0 }, + /* tcId: 136. changing tag value of s */ + {0, 0, 6, 17404, 71, 0 }, + /* tcId: 137. changing tag value of s */ + {0, 0, 6, 17475, 71, 0 }, + /* tcId: 138. dropping value of s */ + {0, 0, 6, 17546, 39, 0 }, + /* tcId: 139. using composition for s */ + {0, 0, 6, 17585, 75, 0 }, + /* tcId: 140. modifying first byte of s */ + {0, 0, 6, 17660, 71, 0 }, + /* tcId: 141. modifying last byte of s */ + {0, 0, 6, 17731, 71, 0 }, + /* tcId: 142. truncated s */ + {0, 0, 6, 17802, 70, 0 }, + /* tcId: 143. truncated s */ + {0, 0, 6, 17872, 70, 0 }, + /* tcId: 144. s of size 4129 to check for overflows */ + {0, 0, 6, 17942, 4172, 0 }, + /* tcId: 145. leading ff in s */ + {0, 0, 6, 22114, 72, 0 }, + /* tcId: 146. replaced s by infinity */ + {0, 0, 6, 22186, 40, 0 }, + /* tcId: 147. replacing s with zero */ + {0, 0, 6, 22226, 40, 0 }, + /* tcId: 148. replaced r by r + n */ + {0, 0, 6, 22266, 71, 0 }, + /* tcId: 149. replaced r by r - n */ + {0, 0, 6, 22337, 70, 0 }, + /* tcId: 150. replaced r by r + 256 * n */ + {0, 0, 6, 22407, 72, 0 }, + /* tcId: 151. replaced r by -r */ + {0, 0, 6, 22479, 71, 0 }, + /* tcId: 152. replaced r by n - r */ + {0, 0, 6, 22550, 70, 0 }, + /* tcId: 153. replaced r by -n - r */ + {0, 0, 6, 22620, 71, 0 }, + /* tcId: 154. replaced r by r + 2**256 */ + {0, 0, 6, 22691, 71, 0 }, + /* tcId: 155. replaced r by r + 2**320 */ + {0, 0, 6, 22762, 79, 0 }, + /* tcId: 156. replaced s by s + n */ + {0, 0, 6, 22841, 71, 0 }, + /* tcId: 157. replaced s by s - n */ + {0, 0, 6, 22912, 71, 0 }, + /* tcId: 158. replaced s by s + 256 * n */ + {0, 0, 6, 22983, 72, 0 }, + /* tcId: 159. replaced s by -s */ + {0, 0, 6, 23055, 70, 0 }, + /* tcId: 160. replaced s by -n - s */ + {0, 0, 6, 23125, 71, 0 }, + /* tcId: 161. replaced s by s + 2**256 */ + {0, 0, 6, 23196, 71, 0 }, + /* tcId: 162. replaced s by s - 2**256 */ + {0, 0, 6, 23267, 71, 0 }, + /* tcId: 163. replaced s by s + 2**320 */ + {0, 0, 6, 23338, 79, 0 }, + /* tcId: 164. Signature with special case values r=0 and s=0 */ + {0, 0, 6, 23417, 8, 0 }, + /* tcId: 165. Signature with special case values r=0 and s=1 */ + {0, 0, 6, 23425, 8, 0 }, + /* tcId: 166. Signature with special case values r=0 and s=-1 */ + {0, 0, 6, 23433, 8, 0 }, + /* tcId: 167. Signature with special case values r=0 and s=n */ + {0, 0, 6, 23441, 40, 0 }, + /* tcId: 168. Signature with special case values r=0 and s=n - 1 */ + {0, 0, 6, 23481, 40, 0 }, + /* tcId: 169. Signature with special case values r=0 and s=n + 1 */ + {0, 0, 6, 23521, 40, 0 }, + /* tcId: 170. Signature with special case values r=0 and s=p */ + {0, 0, 6, 23561, 40, 0 }, + /* tcId: 171. Signature with special case values r=0 and s=p + 1 */ + {0, 0, 6, 23601, 40, 0 }, + /* tcId: 172. Signature with special case values r=1 and s=0 */ + {0, 0, 6, 23641, 8, 0 }, + /* tcId: 173. Signature with special case values r=1 and s=1 */ + {0, 0, 6, 23649, 8, 0 }, + /* tcId: 174. Signature with special case values r=1 and s=-1 */ + {0, 0, 6, 23657, 8, 0 }, + /* tcId: 175. Signature with special case values r=1 and s=n */ + {0, 0, 6, 23665, 40, 0 }, + /* tcId: 176. Signature with special case values r=1 and s=n - 1 */ + {0, 0, 6, 23705, 40, 0 }, + /* tcId: 177. Signature with special case values r=1 and s=n + 1 */ + {0, 0, 6, 23745, 40, 0 }, + /* tcId: 178. Signature with special case values r=1 and s=p */ + {0, 0, 6, 23785, 40, 0 }, + /* tcId: 179. Signature with special case values r=1 and s=p + 1 */ + {0, 0, 6, 23825, 40, 0 }, + /* tcId: 180. Signature with special case values r=-1 and s=0 */ + {0, 0, 6, 23865, 8, 0 }, + /* tcId: 181. Signature with special case values r=-1 and s=1 */ + {0, 0, 6, 23873, 8, 0 }, + /* tcId: 182. Signature with special case values r=-1 and s=-1 */ + {0, 0, 6, 23881, 8, 0 }, + /* tcId: 183. Signature with special case values r=-1 and s=n */ + {0, 0, 6, 23889, 40, 0 }, + /* tcId: 184. Signature with special case values r=-1 and s=n - 1 */ + {0, 0, 6, 23929, 40, 0 }, + /* tcId: 185. Signature with special case values r=-1 and s=n + 1 */ + {0, 0, 6, 23969, 40, 0 }, + /* tcId: 186. Signature with special case values r=-1 and s=p */ + {0, 0, 6, 24009, 40, 0 }, + /* tcId: 187. Signature with special case values r=-1 and s=p + 1 */ + {0, 0, 6, 24049, 40, 0 }, + /* tcId: 188. Signature with special case values r=n and s=0 */ + {0, 0, 6, 24089, 40, 0 }, + /* tcId: 189. Signature with special case values r=n and s=1 */ + {0, 0, 6, 24129, 40, 0 }, + /* tcId: 190. Signature with special case values r=n and s=-1 */ + {0, 0, 6, 24169, 40, 0 }, + /* tcId: 191. Signature with special case values r=n and s=n */ + {0, 0, 6, 24209, 72, 0 }, + /* tcId: 192. Signature with special case values r=n and s=n - 1 */ + {0, 0, 6, 24281, 72, 0 }, + /* tcId: 193. Signature with special case values r=n and s=n + 1 */ + {0, 0, 6, 24353, 72, 0 }, + /* tcId: 194. Signature with special case values r=n and s=p */ + {0, 0, 6, 24425, 72, 0 }, + /* tcId: 195. Signature with special case values r=n and s=p + 1 */ + {0, 0, 6, 24497, 72, 0 }, + /* tcId: 196. Signature with special case values r=n - 1 and s=0 */ + {0, 0, 6, 24569, 40, 0 }, + /* tcId: 197. Signature with special case values r=n - 1 and s=1 */ + {0, 0, 6, 24609, 40, 0 }, + /* tcId: 198. Signature with special case values r=n - 1 and s=-1 */ + {0, 0, 6, 24649, 40, 0 }, + /* tcId: 199. Signature with special case values r=n - 1 and s=n */ + {0, 0, 6, 24689, 72, 0 }, + /* tcId: 200. Signature with special case values r=n - 1 and s=n - 1 */ + {0, 0, 6, 24761, 72, 0 }, + /* tcId: 201. Signature with special case values r=n - 1 and s=n + 1 */ + {0, 0, 6, 24833, 72, 0 }, + /* tcId: 202. Signature with special case values r=n - 1 and s=p */ + {0, 0, 6, 24905, 72, 0 }, + /* tcId: 203. Signature with special case values r=n - 1 and s=p + 1 */ + {0, 0, 6, 24977, 72, 0 }, + /* tcId: 204. Signature with special case values r=n + 1 and s=0 */ + {0, 0, 6, 25049, 40, 0 }, + /* tcId: 205. Signature with special case values r=n + 1 and s=1 */ + {0, 0, 6, 25089, 40, 0 }, + /* tcId: 206. Signature with special case values r=n + 1 and s=-1 */ + {0, 0, 6, 25129, 40, 0 }, + /* tcId: 207. Signature with special case values r=n + 1 and s=n */ + {0, 0, 6, 25169, 72, 0 }, + /* tcId: 208. Signature with special case values r=n + 1 and s=n - 1 */ + {0, 0, 6, 25241, 72, 0 }, + /* tcId: 209. Signature with special case values r=n + 1 and s=n + 1 */ + {0, 0, 6, 25313, 72, 0 }, + /* tcId: 210. Signature with special case values r=n + 1 and s=p */ + {0, 0, 6, 25385, 72, 0 }, + /* tcId: 211. Signature with special case values r=n + 1 and s=p + 1 */ + {0, 0, 6, 25457, 72, 0 }, + /* tcId: 212. Signature with special case values r=p and s=0 */ + {0, 0, 6, 25529, 40, 0 }, + /* tcId: 213. Signature with special case values r=p and s=1 */ + {0, 0, 6, 25569, 40, 0 }, + /* tcId: 214. Signature with special case values r=p and s=-1 */ + {0, 0, 6, 25609, 40, 0 }, + /* tcId: 215. Signature with special case values r=p and s=n */ + {0, 0, 6, 25649, 72, 0 }, + /* tcId: 216. Signature with special case values r=p and s=n - 1 */ + {0, 0, 6, 25721, 72, 0 }, + /* tcId: 217. Signature with special case values r=p and s=n + 1 */ + {0, 0, 6, 25793, 72, 0 }, + /* tcId: 218. Signature with special case values r=p and s=p */ + {0, 0, 6, 25865, 72, 0 }, + /* tcId: 219. Signature with special case values r=p and s=p + 1 */ + {0, 0, 6, 25937, 72, 0 }, + /* tcId: 220. Signature with special case values r=p + 1 and s=0 */ + {0, 0, 6, 26009, 40, 0 }, + /* tcId: 221. Signature with special case values r=p + 1 and s=1 */ + {0, 0, 6, 26049, 40, 0 }, + /* tcId: 222. Signature with special case values r=p + 1 and s=-1 */ + {0, 0, 6, 26089, 40, 0 }, + /* tcId: 223. Signature with special case values r=p + 1 and s=n */ + {0, 0, 6, 26129, 72, 0 }, + /* tcId: 224. Signature with special case values r=p + 1 and s=n - 1 */ + {0, 0, 6, 26201, 72, 0 }, + /* tcId: 225. Signature with special case values r=p + 1 and s=n + 1 */ + {0, 0, 6, 26273, 72, 0 }, + /* tcId: 226. Signature with special case values r=p + 1 and s=p */ + {0, 0, 6, 26345, 72, 0 }, + /* tcId: 227. Signature with special case values r=p + 1 and s=p + 1 */ + {0, 0, 6, 26417, 72, 0 }, + /* tcId: 228. Signature encoding contains incorrect types: r=0, s=0.25 */ + {0, 0, 6, 26489, 10, 0 }, + /* tcId: 229. Signature encoding contains incorrect types: r=0, s=nan */ + {0, 0, 6, 26499, 8, 0 }, + /* tcId: 230. Signature encoding contains incorrect types: r=0, s=True */ + {0, 0, 6, 26507, 8, 0 }, + /* tcId: 231. Signature encoding contains incorrect types: r=0, s=False */ + {0, 0, 6, 26515, 8, 0 }, + /* tcId: 232. Signature encoding contains incorrect types: r=0, s=Null */ + {0, 0, 6, 26523, 7, 0 }, + /* tcId: 233. Signature encoding contains incorrect types: r=0, s=empyt UTF-8 string */ + {0, 0, 6, 26530, 7, 0 }, + /* tcId: 234. Signature encoding contains incorrect types: r=0, s="0" */ + {0, 0, 6, 26537, 8, 0 }, + /* tcId: 235. Signature encoding contains incorrect types: r=0, s=empty list */ + {0, 0, 6, 26545, 7, 0 }, + /* tcId: 236. Signature encoding contains incorrect types: r=0, s=list containing 0 */ + {0, 0, 6, 26552, 10, 0 }, + /* tcId: 237. Signature encoding contains incorrect types: r=1, s=0.25 */ + {0, 0, 6, 26562, 10, 0 }, + /* tcId: 238. Signature encoding contains incorrect types: r=1, s=nan */ + {0, 0, 6, 26572, 8, 0 }, + /* tcId: 239. Signature encoding contains incorrect types: r=1, s=True */ + {0, 0, 6, 26580, 8, 0 }, + /* tcId: 240. Signature encoding contains incorrect types: r=1, s=False */ + {0, 0, 6, 26588, 8, 0 }, + /* tcId: 241. Signature encoding contains incorrect types: r=1, s=Null */ + {0, 0, 6, 26596, 7, 0 }, + /* tcId: 242. Signature encoding contains incorrect types: r=1, s=empyt UTF-8 string */ + {0, 0, 6, 26603, 7, 0 }, + /* tcId: 243. Signature encoding contains incorrect types: r=1, s="0" */ + {0, 0, 6, 26610, 8, 0 }, + /* tcId: 244. Signature encoding contains incorrect types: r=1, s=empty list */ + {0, 0, 6, 26618, 7, 0 }, + /* tcId: 245. Signature encoding contains incorrect types: r=1, s=list containing 0 */ + {0, 0, 6, 26625, 10, 0 }, + /* tcId: 246. Signature encoding contains incorrect types: r=-1, s=0.25 */ + {0, 0, 6, 26635, 10, 0 }, + /* tcId: 247. Signature encoding contains incorrect types: r=-1, s=nan */ + {0, 0, 6, 26645, 8, 0 }, + /* tcId: 248. Signature encoding contains incorrect types: r=-1, s=True */ + {0, 0, 6, 26653, 8, 0 }, + /* tcId: 249. Signature encoding contains incorrect types: r=-1, s=False */ + {0, 0, 6, 26661, 8, 0 }, + /* tcId: 250. Signature encoding contains incorrect types: r=-1, s=Null */ + {0, 0, 6, 26669, 7, 0 }, + /* tcId: 251. Signature encoding contains incorrect types: r=-1, s=empyt UTF-8 string */ + {0, 0, 6, 26676, 7, 0 }, + /* tcId: 252. Signature encoding contains incorrect types: r=-1, s="0" */ + {0, 0, 6, 26683, 8, 0 }, + /* tcId: 253. Signature encoding contains incorrect types: r=-1, s=empty list */ + {0, 0, 6, 26691, 7, 0 }, + /* tcId: 254. Signature encoding contains incorrect types: r=-1, s=list containing 0 */ + {0, 0, 6, 26698, 10, 0 }, + /* tcId: 255. Signature encoding contains incorrect types: r=n, s=0.25 */ + {0, 0, 6, 26708, 42, 0 }, + /* tcId: 256. Signature encoding contains incorrect types: r=n, s=nan */ + {0, 0, 6, 26750, 40, 0 }, + /* tcId: 257. Signature encoding contains incorrect types: r=n, s=True */ + {0, 0, 6, 26790, 40, 0 }, + /* tcId: 258. Signature encoding contains incorrect types: r=n, s=False */ + {0, 0, 6, 26830, 40, 0 }, + /* tcId: 259. Signature encoding contains incorrect types: r=n, s=Null */ + {0, 0, 6, 26870, 39, 0 }, + /* tcId: 260. Signature encoding contains incorrect types: r=n, s=empyt UTF-8 string */ + {0, 0, 6, 26909, 39, 0 }, + /* tcId: 261. Signature encoding contains incorrect types: r=n, s="0" */ + {0, 0, 6, 26948, 40, 0 }, + /* tcId: 262. Signature encoding contains incorrect types: r=n, s=empty list */ + {0, 0, 6, 26988, 39, 0 }, + /* tcId: 263. Signature encoding contains incorrect types: r=n, s=list containing 0 */ + {0, 0, 6, 27027, 42, 0 }, + /* tcId: 264. Signature encoding contains incorrect types: r=p, s=0.25 */ + {0, 0, 6, 27069, 42, 0 }, + /* tcId: 265. Signature encoding contains incorrect types: r=p, s=nan */ + {0, 0, 6, 27111, 40, 0 }, + /* tcId: 266. Signature encoding contains incorrect types: r=p, s=True */ + {0, 0, 6, 27151, 40, 0 }, + /* tcId: 267. Signature encoding contains incorrect types: r=p, s=False */ + {0, 0, 6, 27191, 40, 0 }, + /* tcId: 268. Signature encoding contains incorrect types: r=p, s=Null */ + {0, 0, 6, 27231, 39, 0 }, + /* tcId: 269. Signature encoding contains incorrect types: r=p, s=empyt UTF-8 string */ + {0, 0, 6, 27270, 39, 0 }, + /* tcId: 270. Signature encoding contains incorrect types: r=p, s="0" */ + {0, 0, 6, 27309, 40, 0 }, + /* tcId: 271. Signature encoding contains incorrect types: r=p, s=empty list */ + {0, 0, 6, 27349, 39, 0 }, + /* tcId: 272. Signature encoding contains incorrect types: r=p, s=list containing 0 */ + {0, 0, 6, 27388, 42, 0 }, + /* tcId: 273. Signature encoding contains incorrect types: r=0.25, s=0.25 */ + {0, 0, 6, 27430, 12, 0 }, + /* tcId: 274. Signature encoding contains incorrect types: r=nan, s=nan */ + {0, 0, 6, 27442, 8, 0 }, + /* tcId: 275. Signature encoding contains incorrect types: r=True, s=True */ + {0, 0, 6, 27450, 8, 0 }, + /* tcId: 276. Signature encoding contains incorrect types: r=False, s=False */ + {0, 0, 6, 27458, 8, 0 }, + /* tcId: 277. Signature encoding contains incorrect types: r=Null, s=Null */ + {0, 0, 6, 27466, 6, 0 }, + /* tcId: 278. Signature encoding contains incorrect types: r=empyt UTF-8 string, s=empyt UTF-8 string */ + {0, 0, 6, 27472, 6, 0 }, + /* tcId: 279. Signature encoding contains incorrect types: r="0", s="0" */ + {0, 0, 6, 27478, 8, 0 }, + /* tcId: 280. Signature encoding contains incorrect types: r=empty list, s=empty list */ + {0, 0, 6, 27486, 6, 0 }, + /* tcId: 281. Signature encoding contains incorrect types: r=list containing 0, s=list containing 0 */ + {0, 0, 6, 27492, 12, 0 }, + /* tcId: 282. Signature encoding contains incorrect types: r=0.25, s=0 */ + {0, 0, 6, 27504, 10, 0 }, + /* tcId: 283. Signature encoding contains incorrect types: r=nan, s=0 */ + {0, 0, 6, 27514, 8, 0 }, + /* tcId: 284. Signature encoding contains incorrect types: r=True, s=0 */ + {0, 0, 6, 27522, 8, 0 }, + /* tcId: 285. Signature encoding contains incorrect types: r=False, s=0 */ + {0, 0, 6, 27530, 8, 0 }, + /* tcId: 286. Signature encoding contains incorrect types: r=Null, s=0 */ + {0, 0, 6, 27538, 7, 0 }, + /* tcId: 287. Signature encoding contains incorrect types: r=empyt UTF-8 string, s=0 */ + {0, 0, 6, 27545, 7, 0 }, + /* tcId: 288. Signature encoding contains incorrect types: r="0", s=0 */ + {0, 0, 6, 27552, 8, 0 }, + /* tcId: 289. Signature encoding contains incorrect types: r=empty list, s=0 */ + {0, 0, 6, 27560, 7, 0 }, + /* tcId: 290. Signature encoding contains incorrect types: r=list containing 0, s=0 */ + {0, 0, 6, 27567, 10, 0 }, + /* tcId: 291. Edge case for Shamir multiplication */ + {0, 6, 5, 27577, 71, 1 }, + /* tcId: 292. special case hash */ + {0, 11, 9, 27648, 71, 1 }, + /* tcId: 293. special case hash */ + {0, 20, 10, 27719, 70, 1 }, + /* tcId: 294. special case hash */ + {0, 30, 11, 27789, 71, 1 }, + /* tcId: 295. special case hash */ + {0, 41, 10, 27860, 71, 1 }, + /* tcId: 296. special case hash */ + {0, 51, 10, 27931, 70, 1 }, + /* tcId: 297. special case hash */ + {0, 61, 10, 28001, 71, 1 }, + /* tcId: 298. special case hash */ + {0, 71, 9, 28072, 70, 1 }, + /* tcId: 299. special case hash */ + {0, 80, 10, 28142, 71, 1 }, + /* tcId: 300. special case hash */ + {0, 90, 10, 28213, 71, 1 }, + /* tcId: 301. special case hash */ + {0, 100, 10, 28284, 71, 1 }, + /* tcId: 302. special case hash */ + {0, 110, 10, 28355, 71, 1 }, + /* tcId: 303. special case hash */ + {0, 120, 11, 28426, 70, 1 }, + /* tcId: 304. special case hash */ + {0, 131, 10, 28496, 71, 1 }, + /* tcId: 305. special case hash */ + {0, 141, 10, 28567, 71, 1 }, + /* tcId: 306. special case hash */ + {0, 151, 10, 28638, 70, 1 }, + /* tcId: 307. special case hash */ + {0, 161, 10, 28708, 71, 1 }, + /* tcId: 308. special case hash */ + {0, 171, 10, 28779, 71, 1 }, + /* tcId: 309. special case hash */ + {0, 181, 10, 28850, 70, 1 }, + /* tcId: 310. special case hash */ + {0, 191, 10, 28920, 71, 1 }, + /* tcId: 311. special case hash */ + {0, 201, 10, 28991, 71, 1 }, + /* tcId: 312. special case hash */ + {0, 211, 10, 29062, 71, 1 }, + /* tcId: 313. special case hash */ + {0, 221, 10, 29133, 70, 1 }, + /* tcId: 314. special case hash */ + {0, 231, 10, 29203, 71, 1 }, + /* tcId: 315. special case hash */ + {0, 241, 10, 29274, 71, 1 }, + /* tcId: 316. special case hash */ + {0, 251, 10, 29345, 71, 1 }, + /* tcId: 317. special case hash */ + {0, 261, 11, 29416, 71, 1 }, + /* tcId: 318. special case hash */ + {0, 272, 11, 29487, 70, 1 }, + /* tcId: 319. special case hash */ + {0, 283, 9, 29557, 71, 1 }, + /* tcId: 320. special case hash */ + {0, 292, 9, 29628, 71, 1 }, + /* tcId: 321. special case hash */ + {0, 301, 10, 29699, 71, 1 }, + /* tcId: 322. special case hash */ + {0, 311, 10, 29770, 71, 1 }, + /* tcId: 323. special case hash */ + {0, 321, 10, 29841, 70, 1 }, + /* tcId: 324. special case hash */ + {0, 331, 10, 29911, 70, 1 }, + /* tcId: 325. special case hash */ + {0, 341, 10, 29981, 71, 1 }, + /* tcId: 326. special case hash */ + {0, 351, 9, 30052, 70, 1 }, + /* tcId: 327. special case hash */ + {0, 360, 10, 30122, 70, 1 }, + /* tcId: 328. special case hash */ + {0, 370, 10, 30192, 70, 1 }, + /* tcId: 329. special case hash */ + {0, 380, 10, 30262, 70, 1 }, + /* tcId: 330. special case hash */ + {0, 390, 9, 30332, 71, 1 }, + /* tcId: 331. special case hash */ + {0, 399, 11, 30403, 70, 1 }, + /* tcId: 332. special case hash */ + {0, 410, 9, 30473, 71, 1 }, + /* tcId: 333. special case hash */ + {0, 419, 9, 30544, 71, 1 }, + /* tcId: 334. special case hash */ + {0, 428, 11, 30615, 70, 1 }, + /* tcId: 335. special case hash */ + {0, 439, 8, 30685, 71, 1 }, + /* tcId: 336. special case hash */ + {0, 447, 10, 30756, 70, 1 }, + /* tcId: 337. special case hash */ + {0, 457, 10, 30826, 71, 1 }, + /* tcId: 338. special case hash */ + {0, 467, 10, 30897, 70, 1 }, + /* tcId: 339. special case hash */ + {0, 477, 10, 30967, 70, 1 }, + /* tcId: 340. special case hash */ + {0, 487, 10, 31037, 70, 1 }, + /* tcId: 341. special case hash */ + {0, 497, 10, 31107, 71, 1 }, + /* tcId: 342. special case hash */ + {0, 507, 10, 31178, 70, 1 }, + /* tcId: 343. special case hash */ + {0, 517, 10, 31248, 70, 1 }, + /* tcId: 344. special case hash */ + {0, 527, 10, 31318, 71, 1 }, + /* tcId: 345. special case hash */ + {0, 537, 9, 31389, 70, 1 }, + /* tcId: 346. k*G has a large x-coordinate */ + {65, 0, 6, 31459, 24, 1 }, + /* tcId: 347. r too large */ + {65, 0, 6, 31483, 40, 0 }, + /* tcId: 348. r,s are large */ + {130, 0, 6, 31523, 40, 1 }, + /* tcId: 349. r and s^-1 have a large Hamming weight */ + {195, 0, 6, 31563, 70, 1 }, + /* tcId: 350. r and s^-1 have a large Hamming weight */ + {260, 0, 6, 31633, 70, 1 }, + /* tcId: 351. small r and s */ + {325, 0, 6, 31703, 8, 1 }, + /* tcId: 352. small r and s */ + {390, 0, 6, 31711, 8, 1 }, + /* tcId: 353. small r and s */ + {455, 0, 6, 31719, 8, 1 }, + /* tcId: 354. small r and s */ + {520, 0, 6, 31727, 8, 1 }, + /* tcId: 355. small r and s */ + {585, 0, 6, 31735, 8, 1 }, + /* tcId: 356. small r and s */ + {650, 0, 6, 31743, 8, 1 }, + /* tcId: 357. r is larger than n */ + {650, 0, 6, 31751, 40, 0 }, + /* tcId: 358. s is larger than n */ + {715, 0, 6, 31791, 10, 0 }, + /* tcId: 359. small r and s^-1 */ + {780, 0, 6, 31801, 40, 1 }, + /* tcId: 360. smallish r and s^-1 */ + {845, 0, 6, 31841, 45, 1 }, + /* tcId: 361. 100-bit r and small s^-1 */ + {910, 0, 6, 31886, 51, 1 }, + /* tcId: 362. small r and 100 bit s^-1 */ + {975, 0, 6, 31937, 40, 1 }, + /* tcId: 363. 100-bit r and s^-1 */ + {1040, 0, 6, 31977, 51, 1 }, + /* tcId: 364. r and s^-1 are close to n */ + {1105, 0, 6, 32028, 71, 1 }, + /* tcId: 365. r and s are 64-bit integer */ + {1170, 0, 6, 32099, 24, 1 }, + /* tcId: 366. r and s are 100-bit integer */ + {1235, 0, 6, 32123, 32, 1 }, + /* tcId: 367. r and s are 128-bit integer */ + {1300, 0, 6, 32155, 40, 1 }, + /* tcId: 368. r and s are 160-bit integer */ + {1365, 0, 6, 32195, 48, 1 }, + /* tcId: 369. s == 1 */ + {1430, 0, 6, 32243, 39, 1 }, + /* tcId: 370. s == 0 */ + {1430, 0, 6, 32282, 39, 0 }, + /* tcId: 371. edge case modular inverse */ + {1495, 0, 6, 32321, 70, 1 }, + /* tcId: 372. edge case modular inverse */ + {1560, 0, 6, 32391, 70, 1 }, + /* tcId: 373. edge case modular inverse */ + {1625, 0, 6, 32461, 70, 1 }, + /* tcId: 374. edge case modular inverse */ + {1690, 0, 6, 32531, 70, 1 }, + /* tcId: 375. edge case modular inverse */ + {1755, 0, 6, 32601, 70, 1 }, + /* tcId: 376. edge case modular inverse */ + {1820, 0, 6, 32671, 70, 1 }, + /* tcId: 377. edge case modular inverse */ + {1885, 0, 6, 32741, 70, 1 }, + /* tcId: 378. edge case modular inverse */ + {1950, 0, 6, 32811, 70, 1 }, + /* tcId: 379. edge case modular inverse */ + {2015, 0, 6, 32881, 70, 1 }, + /* tcId: 380. edge case modular inverse */ + {2080, 0, 6, 32951, 70, 1 }, + /* tcId: 381. edge case modular inverse */ + {2145, 0, 6, 33021, 70, 1 }, + /* tcId: 382. edge case modular inverse */ + {2210, 0, 6, 33091, 70, 1 }, + /* tcId: 383. edge case modular inverse */ + {2275, 0, 6, 33161, 70, 1 }, + /* tcId: 384. edge case modular inverse */ + {2340, 0, 6, 33231, 70, 1 }, + /* tcId: 385. edge case modular inverse */ + {2405, 0, 6, 33301, 70, 1 }, + /* tcId: 386. point at infinity during verify */ + {2470, 0, 6, 33371, 70, 0 }, + /* tcId: 387. edge case for signature malleability */ + {2535, 0, 6, 33441, 70, 1 }, + /* tcId: 388. edge case for signature malleability */ + {2600, 0, 6, 33511, 70, 0 }, + /* tcId: 389. u1 == 1 */ + {2665, 0, 6, 33581, 70, 1 }, + /* tcId: 390. u1 == n - 1 */ + {2730, 0, 6, 33651, 70, 1 }, + /* tcId: 391. u2 == 1 */ + {2795, 0, 6, 33721, 70, 1 }, + /* tcId: 392. u2 == n - 1 */ + {2860, 0, 6, 33791, 70, 1 }, + /* tcId: 393. edge case for u1 */ + {2925, 0, 6, 33861, 70, 1 }, + /* tcId: 394. edge case for u1 */ + {2990, 0, 6, 33931, 70, 1 }, + /* tcId: 395. edge case for u1 */ + {3055, 0, 6, 34001, 70, 1 }, + /* tcId: 396. edge case for u1 */ + {3120, 0, 6, 34071, 70, 1 }, + /* tcId: 397. edge case for u1 */ + {3185, 0, 6, 34141, 70, 1 }, + /* tcId: 398. edge case for u1 */ + {3250, 0, 6, 34211, 70, 1 }, + /* tcId: 399. edge case for u1 */ + {3315, 0, 6, 34281, 70, 1 }, + /* tcId: 400. edge case for u1 */ + {3380, 0, 6, 34351, 70, 1 }, + /* tcId: 401. edge case for u1 */ + {3445, 0, 6, 34421, 70, 1 }, + /* tcId: 402. edge case for u1 */ + {3510, 0, 6, 34491, 70, 1 }, + /* tcId: 403. edge case for u1 */ + {3575, 0, 6, 34561, 70, 1 }, + /* tcId: 404. edge case for u1 */ + {3640, 0, 6, 34631, 70, 1 }, + /* tcId: 405. edge case for u1 */ + {3705, 0, 6, 34701, 70, 1 }, + /* tcId: 406. edge case for u1 */ + {3770, 0, 6, 34771, 70, 1 }, + /* tcId: 407. edge case for u1 */ + {3835, 0, 6, 34841, 70, 1 }, + /* tcId: 408. edge case for u2 */ + {3900, 0, 6, 34911, 70, 1 }, + /* tcId: 409. edge case for u2 */ + {3965, 0, 6, 34981, 70, 1 }, + /* tcId: 410. edge case for u2 */ + {4030, 0, 6, 35051, 70, 1 }, + /* tcId: 411. edge case for u2 */ + {4095, 0, 6, 35121, 70, 1 }, + /* tcId: 412. edge case for u2 */ + {4160, 0, 6, 35191, 70, 1 }, + /* tcId: 413. edge case for u2 */ + {4225, 0, 6, 35261, 69, 1 }, + /* tcId: 414. edge case for u2 */ + {4290, 0, 6, 35330, 70, 1 }, + /* tcId: 415. edge case for u2 */ + {4355, 0, 6, 35400, 70, 1 }, + /* tcId: 416. edge case for u2 */ + {4420, 0, 6, 35470, 70, 1 }, + /* tcId: 417. edge case for u2 */ + {4485, 0, 6, 35540, 70, 1 }, + /* tcId: 418. edge case for u2 */ + {4550, 0, 6, 35610, 70, 1 }, + /* tcId: 419. edge case for u2 */ + {4615, 0, 6, 35680, 70, 1 }, + /* tcId: 420. edge case for u2 */ + {4680, 0, 6, 35750, 70, 1 }, + /* tcId: 421. edge case for u2 */ + {4745, 0, 6, 35820, 70, 1 }, + /* tcId: 422. edge case for u2 */ + {4810, 0, 6, 35890, 70, 1 }, + /* tcId: 423. point duplication during verification */ + {4875, 0, 6, 35960, 70, 1 }, + /* tcId: 424. duplication bug */ + {4940, 0, 6, 36030, 70, 0 }, + /* tcId: 425. comparison with point at infinity */ + {5005, 0, 6, 36100, 70, 0 }, + /* tcId: 426. extreme value for k and edgecase s */ + {5070, 0, 6, 36170, 71, 1 }, + /* tcId: 427. extreme value for k and s^-1 */ + {5135, 0, 6, 36241, 71, 1 }, + /* tcId: 428. extreme value for k and s^-1 */ + {5200, 0, 6, 36312, 71, 1 }, + /* tcId: 429. extreme value for k and s^-1 */ + {5265, 0, 6, 36383, 71, 1 }, + /* tcId: 430. extreme value for k and s^-1 */ + {5330, 0, 6, 36454, 71, 1 }, + /* tcId: 431. extreme value for k */ + {5395, 0, 6, 36525, 71, 1 }, + /* tcId: 432. extreme value for k and edgecase s */ + {5460, 0, 6, 36596, 70, 1 }, + /* tcId: 433. extreme value for k and s^-1 */ + {5525, 0, 6, 36666, 70, 1 }, + /* tcId: 434. extreme value for k and s^-1 */ + {5590, 0, 6, 36736, 70, 1 }, + /* tcId: 435. extreme value for k and s^-1 */ + {5655, 0, 6, 36806, 70, 1 }, + /* tcId: 436. extreme value for k and s^-1 */ + {5720, 0, 6, 36876, 70, 1 }, + /* tcId: 437. extreme value for k */ + {5785, 0, 6, 36946, 70, 1 }, + /* tcId: 438. public key shares x-coordinate with generator */ + {5850, 0, 6, 37016, 71, 0 }, + /* tcId: 439. public key shares x-coordinate with generator */ + {5850, 0, 6, 37087, 70, 0 }, + /* tcId: 440. public key shares x-coordinate with generator */ + {5915, 0, 6, 37157, 71, 0 }, + /* tcId: 441. public key shares x-coordinate with generator */ + {5915, 0, 6, 37228, 70, 0 }, + /* tcId: 442. pseudorandom signature */ + {5980, 546, 0, 37298, 71, 1 }, + /* tcId: 443. pseudorandom signature */ + {5980, 546, 3, 37369, 70, 1 }, + /* tcId: 444. pseudorandom signature */ + {5980, 0, 6, 37439, 71, 1 }, + /* tcId: 445. pseudorandom signature */ + {5980, 549, 20, 37510, 70, 1 }, + /* tcId: 446. y-coordinate of the public key is small */ + {6045, 569, 7, 37580, 70, 1 }, + /* tcId: 447. y-coordinate of the public key is small */ + {6045, 569, 7, 37650, 70, 1 }, + /* tcId: 448. y-coordinate of the public key is small */ + {6045, 569, 7, 37720, 71, 1 }, + /* tcId: 449. y-coordinate of the public key is large */ + {6110, 569, 7, 37791, 70, 1 }, + /* tcId: 450. y-coordinate of the public key is large */ + {6110, 569, 7, 37861, 71, 1 }, + /* tcId: 451. y-coordinate of the public key is large */ + {6110, 569, 7, 37932, 70, 1 }, + /* tcId: 452. x-coordinate of the public key is small */ + {6175, 569, 7, 38002, 70, 1 }, + /* tcId: 453. x-coordinate of the public key is small */ + {6175, 569, 7, 38072, 71, 1 }, + /* tcId: 454. x-coordinate of the public key is small */ + {6175, 569, 7, 38143, 71, 1 }, + /* tcId: 455. x-coordinate of the public key has many trailing 1's */ + {6240, 569, 7, 38214, 70, 1 }, + /* tcId: 456. x-coordinate of the public key has many trailing 1's */ + {6240, 569, 7, 38284, 71, 1 }, + /* tcId: 457. x-coordinate of the public key has many trailing 1's */ + {6240, 569, 7, 38355, 71, 1 }, + /* tcId: 458. y-coordinate of the public key has many trailing 1's */ + {6305, 569, 7, 38426, 70, 1 }, + /* tcId: 459. y-coordinate of the public key has many trailing 1's */ + {6305, 569, 7, 38496, 71, 1 }, + /* tcId: 460. y-coordinate of the public key has many trailing 1's */ + {6305, 569, 7, 38567, 71, 1 }, + /* tcId: 461. x-coordinate of the public key has many trailing 0's */ + {6370, 569, 7, 38638, 70, 1 }, + /* tcId: 462. x-coordinate of the public key has many trailing 0's */ + {6370, 569, 7, 38708, 70, 1 }, + /* tcId: 463. x-coordinate of the public key has many trailing 0's */ + {6370, 569, 7, 38778, 71, 1 }, + +}; diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/wycheproof/ecdsa_secp256k1_sha256_bitcoin_test.json b/secp256k1-zkp-sys/depend/secp256k1/src/wycheproof/ecdsa_secp256k1_sha256_bitcoin_test.json new file mode 100644 index 00000000..9c907479 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/src/wycheproof/ecdsa_secp256k1_sha256_bitcoin_test.json @@ -0,0 +1,6360 @@ +{ + "algorithm" : "ECDSA", + "schema" : "ecdsa_bitcoin_verify_schema.json", + "generatorVersion" : "0.9rc5", + "numberOfTests" : 463, + "header" : [ + "Test vectors of type EcdsaBitcoinVerify are meant for the verification", + "of a ECDSA variant used for bitcoin, that add signature non-malleability." + ], + "notes" : { + "ArithmeticError" : { + "bugType" : "EDGE_CASE", + "description" : "Some implementations of ECDSA have arithmetic errors that occur when intermediate results have extreme values. This test vector has been constructed to test such occurences.", + "cves" : [ + "CVE-2017-18146" + ] + }, + "BerEncodedSignature" : { + "bugType" : "BER_ENCODING", + "description" : "ECDSA signatures are usually DER encoded. This signature contains valid values for r and s, but it uses alternative BER encoding.", + "effect" : "Accepting alternative BER encodings may be benign in some cases, or be an issue if protocol requires signature malleability.", + "cves" : [ + "CVE-2020-14966", + "CVE-2020-13822", + "CVE-2019-14859", + "CVE-2016-1000342" + ] + }, + "EdgeCasePublicKey" : { + "bugType" : "EDGE_CASE", + "description" : "The test vector uses a special case public key. " + }, + "EdgeCaseShamirMultiplication" : { + "bugType" : "EDGE_CASE", + "description" : "Shamir proposed a fast method for computing the sum of two scalar multiplications efficiently. This test vector has been constructed so that an intermediate result is the point at infinity if Shamir's method is used." + }, + "IntegerOverflow" : { + "bugType" : "CAN_OF_WORMS", + "description" : "The test vector contains an r and s that has been modified, so that the original value is restored if the implementation ignores the most significant bits.", + "effect" : "Without further analysis it is unclear if the modification can be used to forge signatures." + }, + "InvalidEncoding" : { + "bugType" : "CAN_OF_WORMS", + "description" : "ECDSA signatures are encoded using ASN.1. This test vector contains an incorrectly encoded signature. The test vector itself was generated from a valid signature by modifying its encoding.", + "effect" : "Without further analysis it is unclear if the modification can be used to forge signatures." + }, + "InvalidSignature" : { + "bugType" : "AUTH_BYPASS", + "description" : "The signature contains special case values such as r=0 and s=0. Buggy implementations may accept such values, if the implementation does not check boundaries and computes s^(-1) == 0.", + "effect" : "Accepting such signatures can have the effect that an adversary can forge signatures without even knowning the message to sign.", + "cves" : [ + "CVE-2022-21449", + "CVE-2021-43572", + "CVE-2022-24884" + ] + }, + "InvalidTypesInSignature" : { + "bugType" : "AUTH_BYPASS", + "description" : "The signature contains invalid types. Dynamic typed languages sometime coerce such values of different types into integers. If an implementation is careless and has additional bugs, such as not checking integer boundaries then it may be possible that such signatures are accepted.", + "effect" : "Accepting such signatures can have the effect that an adversary can forge signatures without even knowning the message to sign.", + "cves" : [ + "CVE-2022-21449" + ] + }, + "ModifiedInteger" : { + "bugType" : "CAN_OF_WORMS", + "description" : "The test vector contains an r and s that has been modified. The goal is to check for arithmetic errors.", + "effect" : "Without further analysis it is unclear if the modification can be used to forge signatures." + }, + "ModifiedSignature" : { + "bugType" : "CAN_OF_WORMS", + "description" : "The test vector contains an invalid signature that was generated from a valid signature by modifying it.", + "effect" : "Without further analysis it is unclear if the modification can be used to forge signatures." + }, + "ModularInverse" : { + "bugType" : "EDGE_CASE", + "description" : "The test vectors contains a signature where computing the modular inverse of s hits an edge case.", + "effect" : "While the signature in this test vector is constructed and similar cases are unlikely to occur, it is important to determine if the underlying arithmetic error can be used to forge signatures.", + "cves" : [ + "CVE-2019-0865" + ] + }, + "PointDuplication" : { + "bugType" : "EDGE_CASE", + "description" : "Some implementations of ECDSA do not handle duplication and points at infinity correctly. This is a test vector that has been specially crafted to check for such an omission.", + "cves" : [ + "2020-12607", + "CVE-2015-2730" + ] + }, + "RangeCheck" : { + "bugType" : "CAN_OF_WORMS", + "description" : "The test vector contains an r and s that has been modified. By adding or subtracting the order of the group (or other values) the test vector checks whether signature verification verifies the range of r and s.", + "effect" : "Without further analysis it is unclear if the modification can be used to forge signatures." + }, + "SignatureMalleabilityBitcoin" : { + "bugType" : "SIGNATURE_MALLEABILITY", + "description" : "\"BitCoins\"-curves are curves where signature malleability can be a serious issue. An implementation should only accept a signature s where s < n/2. If an implementation is not meant for uses cases that require signature malleability then this implemenation should be tested with another set of test vectors.", + "effect" : "In bitcoin exchanges, it may be used to make a double deposits or double withdrawals", + "links" : [ + "https://en.bitcoin.it/wiki/Transaction_malleability", + "https://en.bitcoinwiki.org/wiki/Transaction_Malleability" + ] + }, + "SmallRandS" : { + "bugType" : "EDGE_CASE", + "description" : "The test vectors contains a signature where both r and s are small integers. Some libraries cannot verify such signatures.", + "effect" : "While the signature in this test vector is constructed and similar cases are unlikely to occur, it is important to determine if the underlying arithmetic error can be used to forge signatures.", + "cves" : [ + "2020-13895" + ] + }, + "SpecialCaseHash" : { + "bugType" : "EDGE_CASE", + "description" : "The test vector contains a signature where the hash of the message is a special case, e.g., contains a long run of 0 or 1 bits." + }, + "ValidSignature" : { + "bugType" : "BASIC", + "description" : "The test vector contains a valid signature that was generated pseudorandomly. Such signatures should not fail to verify unless some of the parameters (e.g. curve or hash function) are not supported." + } + }, + "testGroups" : [ + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04b838ff44e5bc177bf21189d0766082fc9d843226887fc9760371100b7ee20a6ff0c9d75bfba7b31a6bca1974496eeb56de357071955d83c4b1badaa0b21832e9", + "wx" : "00b838ff44e5bc177bf21189d0766082fc9d843226887fc9760371100b7ee20a6f", + "wy" : "00f0c9d75bfba7b31a6bca1974496eeb56de357071955d83c4b1badaa0b21832e9" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004b838ff44e5bc177bf21189d0766082fc9d843226887fc9760371100b7ee20a6ff0c9d75bfba7b31a6bca1974496eeb56de357071955d83c4b1badaa0b21832e9", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEuDj/ROW8F3vyEYnQdmCC/J2EMiaIf8l2\nA3EQC37iCm/wyddb+6ezGmvKGXRJbutW3jVwcZVdg8Sxutqgshgy6Q==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 1, + "comment" : "Signature malleability", + "flags" : [ + "SignatureMalleabilityBitcoin" + ], + "msg" : "313233343030", + "sig" : "3046022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365022100900e75ad233fcc908509dbff5922647db37c21f4afd3203ae8dc4ae7794b0f87", + "result" : "invalid" + }, + { + "tcId" : 2, + "comment" : "valid", + "flags" : [ + "ValidSignature" + ], + "msg" : "313233343030", + "sig" : "3045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "valid" + }, + { + "tcId" : 3, + "comment" : "length of sequence [r, s] uses long form encoding", + "flags" : [ + "BerEncodedSignature" + ], + "msg" : "313233343030", + "sig" : "308145022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 4, + "comment" : "length of sequence [r, s] contains a leading 0", + "flags" : [ + "BerEncodedSignature" + ], + "msg" : "313233343030", + "sig" : "30820045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 5, + "comment" : "length of sequence [r, s] uses 70 instead of 69", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3046022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 6, + "comment" : "length of sequence [r, s] uses 68 instead of 69", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3044022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 7, + "comment" : "uint32 overflow in length of sequence [r, s]", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "30850100000045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 8, + "comment" : "uint64 overflow in length of sequence [r, s]", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3089010000000000000045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 9, + "comment" : "length of sequence [r, s] = 2**31 - 1", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "30847fffffff022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 10, + "comment" : "length of sequence [r, s] = 2**31", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "308480000000022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 11, + "comment" : "length of sequence [r, s] = 2**32 - 1", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3084ffffffff022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 12, + "comment" : "length of sequence [r, s] = 2**40 - 1", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3085ffffffffff022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 13, + "comment" : "length of sequence [r, s] = 2**64 - 1", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3088ffffffffffffffff022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 14, + "comment" : "incorrect length of sequence [r, s]", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "30ff022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 15, + "comment" : "replaced sequence [r, s] by an indefinite length tag without termination", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3080022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 16, + "comment" : "removing sequence [r, s]", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "", + "result" : "invalid" + }, + { + "tcId" : 17, + "comment" : "lonely sequence tag", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "30", + "result" : "invalid" + }, + { + "tcId" : 18, + "comment" : "appending 0's to sequence [r, s]", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3047022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba0000", + "result" : "invalid" + }, + { + "tcId" : 19, + "comment" : "prepending 0's to sequence [r, s]", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "30470000022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 20, + "comment" : "appending unused 0's to sequence [r, s]", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba0000", + "result" : "invalid" + }, + { + "tcId" : 21, + "comment" : "appending null value to sequence [r, s]", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3047022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba0500", + "result" : "invalid" + }, + { + "tcId" : 22, + "comment" : "prepending garbage to sequence [r, s]", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304a4981773045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 23, + "comment" : "prepending garbage to sequence [r, s]", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304925003045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 24, + "comment" : "appending garbage to sequence [r, s]", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "30473045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba0004deadbeef", + "result" : "invalid" + }, + { + "tcId" : 25, + "comment" : "including undefined tags", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "304daa00bb00cd003045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 26, + "comment" : "including undefined tags", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304d2229aa00bb00cd00022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 27, + "comment" : "including undefined tags", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304d022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc98323652228aa00bb00cd0002206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 28, + "comment" : "truncated length of sequence [r, s]", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3081", + "result" : "invalid" + }, + { + "tcId" : 29, + "comment" : "including undefined tags to sequence [r, s]", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "304baa02aabb3045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 30, + "comment" : "using composition with indefinite length for sequence [r, s]", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "30803045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba0000", + "result" : "invalid" + }, + { + "tcId" : 31, + "comment" : "using composition with wrong tag for sequence [r, s]", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "30803145022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba0000", + "result" : "invalid" + }, + { + "tcId" : 32, + "comment" : "Replacing sequence [r, s] with NULL", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "0500", + "result" : "invalid" + }, + { + "tcId" : 33, + "comment" : "changing tag value of sequence [r, s]", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "2e45022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 34, + "comment" : "changing tag value of sequence [r, s]", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "2f45022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 35, + "comment" : "changing tag value of sequence [r, s]", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3145022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 36, + "comment" : "changing tag value of sequence [r, s]", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3245022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 37, + "comment" : "changing tag value of sequence [r, s]", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "ff45022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 38, + "comment" : "dropping value of sequence [r, s]", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3000", + "result" : "invalid" + }, + { + "tcId" : 39, + "comment" : "using composition for sequence [r, s]", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304930010230442100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 40, + "comment" : "truncated sequence [r, s]", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3044022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31", + "result" : "invalid" + }, + { + "tcId" : 41, + "comment" : "truncated sequence [r, s]", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "30442100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 42, + "comment" : "sequence [r, s] of size 4166 to check for overflows", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "30821046022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "result" : "invalid" + }, + { + "tcId" : 43, + "comment" : "indefinite length", + "flags" : [ + "BerEncodedSignature" + ], + "msg" : "313233343030", + "sig" : "3080022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba0000", + "result" : "invalid" + }, + { + "tcId" : 44, + "comment" : "indefinite length with truncated delimiter", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3080022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba00", + "result" : "invalid" + }, + { + "tcId" : 45, + "comment" : "indefinite length with additional element", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3080022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba05000000", + "result" : "invalid" + }, + { + "tcId" : 46, + "comment" : "indefinite length with truncated element", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3080022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba060811220000", + "result" : "invalid" + }, + { + "tcId" : 47, + "comment" : "indefinite length with garbage", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3080022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba0000fe02beef", + "result" : "invalid" + }, + { + "tcId" : 48, + "comment" : "indefinite length with nonempty EOC", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3080022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba0002beef", + "result" : "invalid" + }, + { + "tcId" : 49, + "comment" : "prepend empty sequence", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "30473000022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 50, + "comment" : "append empty sequence", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3047022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba3000", + "result" : "invalid" + }, + { + "tcId" : 51, + "comment" : "append zero", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3048022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba020100", + "result" : "invalid" + }, + { + "tcId" : 52, + "comment" : "append garbage with high tag number", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3048022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31babf7f00", + "result" : "invalid" + }, + { + "tcId" : 53, + "comment" : "append null with explicit tag", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3049022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31baa0020500", + "result" : "invalid" + }, + { + "tcId" : 54, + "comment" : "append null with implicit tag", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3047022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31baa000", + "result" : "invalid" + }, + { + "tcId" : 55, + "comment" : "sequence of sequence", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "30473045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 56, + "comment" : "truncated sequence: removed last 1 elements", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3023022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365", + "result" : "invalid" + }, + { + "tcId" : 57, + "comment" : "repeating element in sequence", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3067022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba02206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 58, + "comment" : "flipped bit 0 in r", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304300813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236402206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 59, + "comment" : "flipped bit 32 in r", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304300813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccac983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 60, + "comment" : "flipped bit 48 in r", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304300813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5133ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 61, + "comment" : "flipped bit 64 in r", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304300813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc08b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 62, + "comment" : "length of r uses long form encoding", + "flags" : [ + "BerEncodedSignature" + ], + "msg" : "313233343030", + "sig" : "304602812100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 63, + "comment" : "length of r contains a leading 0", + "flags" : [ + "BerEncodedSignature" + ], + "msg" : "313233343030", + "sig" : "30470282002100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 64, + "comment" : "length of r uses 34 instead of 33", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3045022200813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 65, + "comment" : "length of r uses 32 instead of 33", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3045022000813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 66, + "comment" : "uint32 overflow in length of r", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304a0285010000002100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 67, + "comment" : "uint64 overflow in length of r", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304e028901000000000000002100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 68, + "comment" : "length of r = 2**31 - 1", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304902847fffffff00813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 69, + "comment" : "length of r = 2**31", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304902848000000000813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 70, + "comment" : "length of r = 2**32 - 1", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "30490284ffffffff00813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 71, + "comment" : "length of r = 2**40 - 1", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304a0285ffffffffff00813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 72, + "comment" : "length of r = 2**64 - 1", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304d0288ffffffffffffffff00813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 73, + "comment" : "incorrect length of r", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304502ff00813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 74, + "comment" : "replaced r by an indefinite length tag without termination", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3045028000813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 75, + "comment" : "removing r", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "302202206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 76, + "comment" : "lonely integer tag", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "30230202206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 77, + "comment" : "lonely integer tag", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3024022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502", + "result" : "invalid" + }, + { + "tcId" : 78, + "comment" : "appending 0's to r", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3047022300813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365000002206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 79, + "comment" : "prepending 0's to r", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "30470223000000813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 80, + "comment" : "appending unused 0's to r", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3047022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365000002206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 81, + "comment" : "appending null value to r", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3047022300813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365050002206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 82, + "comment" : "prepending garbage to r", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304a2226498177022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 83, + "comment" : "prepending garbage to r", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304922252500022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 84, + "comment" : "appending garbage to r", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304d2223022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc98323650004deadbeef02206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 85, + "comment" : "truncated length of r", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3024028102206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 86, + "comment" : "including undefined tags to r", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304b2227aa02aabb022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 87, + "comment" : "using composition with indefinite length for r", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "30492280022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365000002206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 88, + "comment" : "using composition with wrong tag for r", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "30492280032100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365000002206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 89, + "comment" : "Replacing r with NULL", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3024050002206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 90, + "comment" : "changing tag value of r", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3045002100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 91, + "comment" : "changing tag value of r", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3045012100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 92, + "comment" : "changing tag value of r", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3045032100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 93, + "comment" : "changing tag value of r", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3045042100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 94, + "comment" : "changing tag value of r", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3045ff2100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 95, + "comment" : "dropping value of r", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3024020002206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 96, + "comment" : "using composition for r", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304922250201000220813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 97, + "comment" : "modifying first byte of r", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3045022102813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 98, + "comment" : "modifying last byte of r", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc98323e502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 99, + "comment" : "truncated r", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3044022000813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832302206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 100, + "comment" : "truncated r", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "30440220813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 101, + "comment" : "r of size 4130 to check for overflows", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "308210480282102200813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 102, + "comment" : "leading ff in r", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "30460222ff00813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 103, + "comment" : "replaced r by infinity", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "302509018002206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 104, + "comment" : "replacing r with zero", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "302502010002206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 105, + "comment" : "flipped bit 0 in s", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3043022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc98323656ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31bb", + "result" : "invalid" + }, + { + "tcId" : 106, + "comment" : "flipped bit 32 in s", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3043022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc98323656ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a456eb31ba", + "result" : "invalid" + }, + { + "tcId" : 107, + "comment" : "flipped bit 48 in s", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3043022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc98323656ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f713a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 108, + "comment" : "flipped bit 64 in s", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3043022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc98323656ff18a52dcc0336f7af62400a6dd9b810732baf1ff758001d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 109, + "comment" : "length of s uses long form encoding", + "flags" : [ + "BerEncodedSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc98323650281206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 110, + "comment" : "length of s contains a leading 0", + "flags" : [ + "BerEncodedSignature" + ], + "msg" : "313233343030", + "sig" : "3047022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365028200206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 111, + "comment" : "length of s uses 33 instead of 32", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502216ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 112, + "comment" : "length of s uses 31 instead of 32", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365021f6ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 113, + "comment" : "uint32 overflow in length of s", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304a022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365028501000000206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 114, + "comment" : "uint64 overflow in length of s", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304e022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502890100000000000000206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 115, + "comment" : "length of s = 2**31 - 1", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3049022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502847fffffff6ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 116, + "comment" : "length of s = 2**31", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3049022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc98323650284800000006ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 117, + "comment" : "length of s = 2**32 - 1", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3049022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc98323650284ffffffff6ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 118, + "comment" : "length of s = 2**40 - 1", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304a022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc98323650285ffffffffff6ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 119, + "comment" : "length of s = 2**64 - 1", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304d022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc98323650288ffffffffffffffff6ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 120, + "comment" : "incorrect length of s", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502ff6ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 121, + "comment" : "replaced s by an indefinite length tag without termination", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502806ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 122, + "comment" : "appending 0's to s", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3047022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502226ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba0000", + "result" : "invalid" + }, + { + "tcId" : 123, + "comment" : "prepending 0's to s", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3047022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365022200006ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 124, + "comment" : "appending null value to s", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3047022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502226ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba0500", + "result" : "invalid" + }, + { + "tcId" : 125, + "comment" : "prepending garbage to s", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304a022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365222549817702206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 126, + "comment" : "prepending garbage to s", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3049022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc98323652224250002206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 127, + "comment" : "appending garbage to s", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304d022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365222202206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba0004deadbeef", + "result" : "invalid" + }, + { + "tcId" : 128, + "comment" : "truncated length of s", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3025022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc98323650281", + "result" : "invalid" + }, + { + "tcId" : 129, + "comment" : "including undefined tags to s", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "304b022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc98323652226aa02aabb02206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 130, + "comment" : "using composition with indefinite length for s", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3049022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365228002206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba0000", + "result" : "invalid" + }, + { + "tcId" : 131, + "comment" : "using composition with wrong tag for s", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3049022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365228003206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba0000", + "result" : "invalid" + }, + { + "tcId" : 132, + "comment" : "Replacing s with NULL", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3025022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc98323650500", + "result" : "invalid" + }, + { + "tcId" : 133, + "comment" : "changing tag value of s", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236500206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 134, + "comment" : "changing tag value of s", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236501206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 135, + "comment" : "changing tag value of s", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236503206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 136, + "comment" : "changing tag value of s", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236504206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 137, + "comment" : "changing tag value of s", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365ff206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 138, + "comment" : "dropping value of s", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3025022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc98323650200", + "result" : "invalid" + }, + { + "tcId" : 139, + "comment" : "using composition for s", + "flags" : [ + "InvalidEncoding" + ], + "msg" : "313233343030", + "sig" : "3049022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365222402016f021ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 140, + "comment" : "modifying first byte of s", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206df18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 141, + "comment" : "modifying last byte of s", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3045022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb313a", + "result" : "invalid" + }, + { + "tcId" : 142, + "comment" : "truncated s", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3044022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365021f6ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31", + "result" : "invalid" + }, + { + "tcId" : 143, + "comment" : "truncated s", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3044022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365021ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 144, + "comment" : "s of size 4129 to check for overflows", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "30821048022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365028210216ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "result" : "invalid" + }, + { + "tcId" : 145, + "comment" : "leading ff in s", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc98323650221ff6ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 146, + "comment" : "replaced s by infinity", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365090180", + "result" : "invalid" + }, + { + "tcId" : 147, + "comment" : "replacing s with zero", + "flags" : [ + "ModifiedSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc9832365020100", + "result" : "invalid" + }, + { + "tcId" : 148, + "comment" : "replaced r by r + n", + "flags" : [ + "RangeCheck" + ], + "msg" : "313233343030", + "sig" : "3045022101813ef79ccefa9a56f7ba805f0e478583b90deabca4b05c4574e49b5899b964a602206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 149, + "comment" : "replaced r by r - n", + "flags" : [ + "RangeCheck" + ], + "msg" : "313233343030", + "sig" : "30440220813ef79ccefa9a56f7ba805f0e47858643b030ef461f1bcdf53fde3ef94ce22402206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 150, + "comment" : "replaced r by r + 256 * n", + "flags" : [ + "RangeCheck" + ], + "msg" : "313233343030", + "sig" : "304602220100813ef79ccefa9a56f7ba805f0e47843fad3bf4853e07f7c98770c99bffc4646502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 151, + "comment" : "replaced r by -r", + "flags" : [ + "ModifiedInteger" + ], + "msg" : "313233343030", + "sig" : "30450221ff7ec10863310565a908457fa0f1b87a7b01a0f22a0a9843f64aedc334367cdc9b02206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 152, + "comment" : "replaced r by n - r", + "flags" : [ + "ModifiedInteger" + ], + "msg" : "313233343030", + "sig" : "304402207ec10863310565a908457fa0f1b87a79bc4fcf10b9e0e4320ac021c106b31ddc02206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 153, + "comment" : "replaced r by -n - r", + "flags" : [ + "ModifiedInteger" + ], + "msg" : "313233343030", + "sig" : "30450221fe7ec10863310565a908457fa0f1b87a7c46f215435b4fa3ba8b1b64a766469b5a02206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 154, + "comment" : "replaced r by r + 2**256", + "flags" : [ + "IntegerOverflow" + ], + "msg" : "313233343030", + "sig" : "3045022101813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 155, + "comment" : "replaced r by r + 2**320", + "flags" : [ + "IntegerOverflow" + ], + "msg" : "313233343030", + "sig" : "304d0229010000000000000000813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 156, + "comment" : "replaced s by s + n", + "flags" : [ + "RangeCheck" + ], + "msg" : "313233343030", + "sig" : "30450221016ff18a52dcc0336f7af62400a6dd9b7fc1e197d8aebe203c96c87232272172fb02206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 157, + "comment" : "replaced s by s - n", + "flags" : [ + "RangeCheck" + ], + "msg" : "313233343030", + "sig" : "30450221ff6ff18a52dcc0336f7af62400a6dd9b824c83de0b502cdfc51723b51886b4f07902206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 158, + "comment" : "replaced s by s + 256 * n", + "flags" : [ + "RangeCheck" + ], + "msg" : "313233343030", + "sig" : "3046022201006ff18a52dcc0336f7af62400a6dd9a3bb60fa1a14815bbc0a954a0758d2c72ba02206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 159, + "comment" : "replaced s by -s", + "flags" : [ + "ModifiedInteger" + ], + "msg" : "313233343030", + "sig" : "30440220900e75ad233fcc908509dbff5922647ef8cd450e008a7fff2909ec5aa914ce4602206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 160, + "comment" : "replaced s by -n - s", + "flags" : [ + "ModifiedInteger" + ], + "msg" : "313233343030", + "sig" : "30450221fe900e75ad233fcc908509dbff592264803e1e68275141dfc369378dcdd8de8d0502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 161, + "comment" : "replaced s by s + 2**256", + "flags" : [ + "IntegerOverflow" + ], + "msg" : "313233343030", + "sig" : "30450221016ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba02206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 162, + "comment" : "replaced s by s - 2**256", + "flags" : [ + "IntegerOverflow" + ], + "msg" : "313233343030", + "sig" : "30450221ff6ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba02206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 163, + "comment" : "replaced s by s + 2**320", + "flags" : [ + "IntegerOverflow" + ], + "msg" : "313233343030", + "sig" : "304d02290100000000000000006ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba02206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba", + "result" : "invalid" + }, + { + "tcId" : 164, + "comment" : "Signature with special case values r=0 and s=0", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3006020100020100", + "result" : "invalid" + }, + { + "tcId" : 165, + "comment" : "Signature with special case values r=0 and s=1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3006020100020101", + "result" : "invalid" + }, + { + "tcId" : 166, + "comment" : "Signature with special case values r=0 and s=-1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "30060201000201ff", + "result" : "invalid" + }, + { + "tcId" : 167, + "comment" : "Signature with special case values r=0 and s=n", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026020100022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", + "result" : "invalid" + }, + { + "tcId" : 168, + "comment" : "Signature with special case values r=0 and s=n - 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026020100022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140", + "result" : "invalid" + }, + { + "tcId" : 169, + "comment" : "Signature with special case values r=0 and s=n + 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026020100022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142", + "result" : "invalid" + }, + { + "tcId" : 170, + "comment" : "Signature with special case values r=0 and s=p", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026020100022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", + "result" : "invalid" + }, + { + "tcId" : 171, + "comment" : "Signature with special case values r=0 and s=p + 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026020100022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc30", + "result" : "invalid" + }, + { + "tcId" : 172, + "comment" : "Signature with special case values r=1 and s=0", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3006020101020100", + "result" : "invalid" + }, + { + "tcId" : 173, + "comment" : "Signature with special case values r=1 and s=1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3006020101020101", + "result" : "invalid" + }, + { + "tcId" : 174, + "comment" : "Signature with special case values r=1 and s=-1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "30060201010201ff", + "result" : "invalid" + }, + { + "tcId" : 175, + "comment" : "Signature with special case values r=1 and s=n", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026020101022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", + "result" : "invalid" + }, + { + "tcId" : 176, + "comment" : "Signature with special case values r=1 and s=n - 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026020101022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140", + "result" : "invalid" + }, + { + "tcId" : 177, + "comment" : "Signature with special case values r=1 and s=n + 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026020101022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142", + "result" : "invalid" + }, + { + "tcId" : 178, + "comment" : "Signature with special case values r=1 and s=p", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026020101022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", + "result" : "invalid" + }, + { + "tcId" : 179, + "comment" : "Signature with special case values r=1 and s=p + 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026020101022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc30", + "result" : "invalid" + }, + { + "tcId" : 180, + "comment" : "Signature with special case values r=-1 and s=0", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "30060201ff020100", + "result" : "invalid" + }, + { + "tcId" : 181, + "comment" : "Signature with special case values r=-1 and s=1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "30060201ff020101", + "result" : "invalid" + }, + { + "tcId" : 182, + "comment" : "Signature with special case values r=-1 and s=-1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "30060201ff0201ff", + "result" : "invalid" + }, + { + "tcId" : 183, + "comment" : "Signature with special case values r=-1 and s=n", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "30260201ff022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", + "result" : "invalid" + }, + { + "tcId" : 184, + "comment" : "Signature with special case values r=-1 and s=n - 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "30260201ff022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140", + "result" : "invalid" + }, + { + "tcId" : 185, + "comment" : "Signature with special case values r=-1 and s=n + 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "30260201ff022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142", + "result" : "invalid" + }, + { + "tcId" : 186, + "comment" : "Signature with special case values r=-1 and s=p", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "30260201ff022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", + "result" : "invalid" + }, + { + "tcId" : 187, + "comment" : "Signature with special case values r=-1 and s=p + 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "30260201ff022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc30", + "result" : "invalid" + }, + { + "tcId" : 188, + "comment" : "Signature with special case values r=n and s=0", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141020100", + "result" : "invalid" + }, + { + "tcId" : 189, + "comment" : "Signature with special case values r=n and s=1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141020101", + "result" : "invalid" + }, + { + "tcId" : 190, + "comment" : "Signature with special case values r=n and s=-1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd03641410201ff", + "result" : "invalid" + }, + { + "tcId" : 191, + "comment" : "Signature with special case values r=n and s=n", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", + "result" : "invalid" + }, + { + "tcId" : 192, + "comment" : "Signature with special case values r=n and s=n - 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140", + "result" : "invalid" + }, + { + "tcId" : 193, + "comment" : "Signature with special case values r=n and s=n + 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142", + "result" : "invalid" + }, + { + "tcId" : 194, + "comment" : "Signature with special case values r=n and s=p", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", + "result" : "invalid" + }, + { + "tcId" : 195, + "comment" : "Signature with special case values r=n and s=p + 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc30", + "result" : "invalid" + }, + { + "tcId" : 196, + "comment" : "Signature with special case values r=n - 1 and s=0", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140020100", + "result" : "invalid" + }, + { + "tcId" : 197, + "comment" : "Signature with special case values r=n - 1 and s=1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140020101", + "result" : "invalid" + }, + { + "tcId" : 198, + "comment" : "Signature with special case values r=n - 1 and s=-1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd03641400201ff", + "result" : "invalid" + }, + { + "tcId" : 199, + "comment" : "Signature with special case values r=n - 1 and s=n", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", + "result" : "invalid" + }, + { + "tcId" : 200, + "comment" : "Signature with special case values r=n - 1 and s=n - 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140", + "result" : "invalid" + }, + { + "tcId" : 201, + "comment" : "Signature with special case values r=n - 1 and s=n + 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142", + "result" : "invalid" + }, + { + "tcId" : 202, + "comment" : "Signature with special case values r=n - 1 and s=p", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", + "result" : "invalid" + }, + { + "tcId" : 203, + "comment" : "Signature with special case values r=n - 1 and s=p + 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc30", + "result" : "invalid" + }, + { + "tcId" : 204, + "comment" : "Signature with special case values r=n + 1 and s=0", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142020100", + "result" : "invalid" + }, + { + "tcId" : 205, + "comment" : "Signature with special case values r=n + 1 and s=1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142020101", + "result" : "invalid" + }, + { + "tcId" : 206, + "comment" : "Signature with special case values r=n + 1 and s=-1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd03641420201ff", + "result" : "invalid" + }, + { + "tcId" : 207, + "comment" : "Signature with special case values r=n + 1 and s=n", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", + "result" : "invalid" + }, + { + "tcId" : 208, + "comment" : "Signature with special case values r=n + 1 and s=n - 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140", + "result" : "invalid" + }, + { + "tcId" : 209, + "comment" : "Signature with special case values r=n + 1 and s=n + 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142", + "result" : "invalid" + }, + { + "tcId" : 210, + "comment" : "Signature with special case values r=n + 1 and s=p", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", + "result" : "invalid" + }, + { + "tcId" : 211, + "comment" : "Signature with special case values r=n + 1 and s=p + 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc30", + "result" : "invalid" + }, + { + "tcId" : 212, + "comment" : "Signature with special case values r=p and s=0", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f020100", + "result" : "invalid" + }, + { + "tcId" : 213, + "comment" : "Signature with special case values r=p and s=1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f020101", + "result" : "invalid" + }, + { + "tcId" : 214, + "comment" : "Signature with special case values r=p and s=-1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f0201ff", + "result" : "invalid" + }, + { + "tcId" : 215, + "comment" : "Signature with special case values r=p and s=n", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", + "result" : "invalid" + }, + { + "tcId" : 216, + "comment" : "Signature with special case values r=p and s=n - 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140", + "result" : "invalid" + }, + { + "tcId" : 217, + "comment" : "Signature with special case values r=p and s=n + 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142", + "result" : "invalid" + }, + { + "tcId" : 218, + "comment" : "Signature with special case values r=p and s=p", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", + "result" : "invalid" + }, + { + "tcId" : 219, + "comment" : "Signature with special case values r=p and s=p + 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc30", + "result" : "invalid" + }, + { + "tcId" : 220, + "comment" : "Signature with special case values r=p + 1 and s=0", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc30020100", + "result" : "invalid" + }, + { + "tcId" : 221, + "comment" : "Signature with special case values r=p + 1 and s=1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc30020101", + "result" : "invalid" + }, + { + "tcId" : 222, + "comment" : "Signature with special case values r=p + 1 and s=-1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc300201ff", + "result" : "invalid" + }, + { + "tcId" : 223, + "comment" : "Signature with special case values r=p + 1 and s=n", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc30022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", + "result" : "invalid" + }, + { + "tcId" : 224, + "comment" : "Signature with special case values r=p + 1 and s=n - 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc30022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140", + "result" : "invalid" + }, + { + "tcId" : 225, + "comment" : "Signature with special case values r=p + 1 and s=n + 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc30022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142", + "result" : "invalid" + }, + { + "tcId" : 226, + "comment" : "Signature with special case values r=p + 1 and s=p", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc30022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", + "result" : "invalid" + }, + { + "tcId" : 227, + "comment" : "Signature with special case values r=p + 1 and s=p + 1", + "flags" : [ + "InvalidSignature" + ], + "msg" : "313233343030", + "sig" : "3046022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc30022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc30", + "result" : "invalid" + }, + { + "tcId" : 228, + "comment" : "Signature encoding contains incorrect types: r=0, s=0.25", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3008020100090380fe01", + "result" : "invalid" + }, + { + "tcId" : 229, + "comment" : "Signature encoding contains incorrect types: r=0, s=nan", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3006020100090142", + "result" : "invalid" + }, + { + "tcId" : 230, + "comment" : "Signature encoding contains incorrect types: r=0, s=True", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3006020100010101", + "result" : "invalid" + }, + { + "tcId" : 231, + "comment" : "Signature encoding contains incorrect types: r=0, s=False", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3006020100010100", + "result" : "invalid" + }, + { + "tcId" : 232, + "comment" : "Signature encoding contains incorrect types: r=0, s=Null", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30050201000500", + "result" : "invalid" + }, + { + "tcId" : 233, + "comment" : "Signature encoding contains incorrect types: r=0, s=empyt UTF-8 string", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30050201000c00", + "result" : "invalid" + }, + { + "tcId" : 234, + "comment" : "Signature encoding contains incorrect types: r=0, s=\"0\"", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30060201000c0130", + "result" : "invalid" + }, + { + "tcId" : 235, + "comment" : "Signature encoding contains incorrect types: r=0, s=empty list", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30050201003000", + "result" : "invalid" + }, + { + "tcId" : 236, + "comment" : "Signature encoding contains incorrect types: r=0, s=list containing 0", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30080201003003020100", + "result" : "invalid" + }, + { + "tcId" : 237, + "comment" : "Signature encoding contains incorrect types: r=1, s=0.25", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3008020101090380fe01", + "result" : "invalid" + }, + { + "tcId" : 238, + "comment" : "Signature encoding contains incorrect types: r=1, s=nan", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3006020101090142", + "result" : "invalid" + }, + { + "tcId" : 239, + "comment" : "Signature encoding contains incorrect types: r=1, s=True", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3006020101010101", + "result" : "invalid" + }, + { + "tcId" : 240, + "comment" : "Signature encoding contains incorrect types: r=1, s=False", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3006020101010100", + "result" : "invalid" + }, + { + "tcId" : 241, + "comment" : "Signature encoding contains incorrect types: r=1, s=Null", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30050201010500", + "result" : "invalid" + }, + { + "tcId" : 242, + "comment" : "Signature encoding contains incorrect types: r=1, s=empyt UTF-8 string", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30050201010c00", + "result" : "invalid" + }, + { + "tcId" : 243, + "comment" : "Signature encoding contains incorrect types: r=1, s=\"0\"", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30060201010c0130", + "result" : "invalid" + }, + { + "tcId" : 244, + "comment" : "Signature encoding contains incorrect types: r=1, s=empty list", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30050201013000", + "result" : "invalid" + }, + { + "tcId" : 245, + "comment" : "Signature encoding contains incorrect types: r=1, s=list containing 0", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30080201013003020100", + "result" : "invalid" + }, + { + "tcId" : 246, + "comment" : "Signature encoding contains incorrect types: r=-1, s=0.25", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30080201ff090380fe01", + "result" : "invalid" + }, + { + "tcId" : 247, + "comment" : "Signature encoding contains incorrect types: r=-1, s=nan", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30060201ff090142", + "result" : "invalid" + }, + { + "tcId" : 248, + "comment" : "Signature encoding contains incorrect types: r=-1, s=True", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30060201ff010101", + "result" : "invalid" + }, + { + "tcId" : 249, + "comment" : "Signature encoding contains incorrect types: r=-1, s=False", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30060201ff010100", + "result" : "invalid" + }, + { + "tcId" : 250, + "comment" : "Signature encoding contains incorrect types: r=-1, s=Null", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30050201ff0500", + "result" : "invalid" + }, + { + "tcId" : 251, + "comment" : "Signature encoding contains incorrect types: r=-1, s=empyt UTF-8 string", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30050201ff0c00", + "result" : "invalid" + }, + { + "tcId" : 252, + "comment" : "Signature encoding contains incorrect types: r=-1, s=\"0\"", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30060201ff0c0130", + "result" : "invalid" + }, + { + "tcId" : 253, + "comment" : "Signature encoding contains incorrect types: r=-1, s=empty list", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30050201ff3000", + "result" : "invalid" + }, + { + "tcId" : 254, + "comment" : "Signature encoding contains incorrect types: r=-1, s=list containing 0", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30080201ff3003020100", + "result" : "invalid" + }, + { + "tcId" : 255, + "comment" : "Signature encoding contains incorrect types: r=n, s=0.25", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3028022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141090380fe01", + "result" : "invalid" + }, + { + "tcId" : 256, + "comment" : "Signature encoding contains incorrect types: r=n, s=nan", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141090142", + "result" : "invalid" + }, + { + "tcId" : 257, + "comment" : "Signature encoding contains incorrect types: r=n, s=True", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141010101", + "result" : "invalid" + }, + { + "tcId" : 258, + "comment" : "Signature encoding contains incorrect types: r=n, s=False", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141010100", + "result" : "invalid" + }, + { + "tcId" : 259, + "comment" : "Signature encoding contains incorrect types: r=n, s=Null", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3025022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd03641410500", + "result" : "invalid" + }, + { + "tcId" : 260, + "comment" : "Signature encoding contains incorrect types: r=n, s=empyt UTF-8 string", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3025022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd03641410c00", + "result" : "invalid" + }, + { + "tcId" : 261, + "comment" : "Signature encoding contains incorrect types: r=n, s=\"0\"", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd03641410c0130", + "result" : "invalid" + }, + { + "tcId" : 262, + "comment" : "Signature encoding contains incorrect types: r=n, s=empty list", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3025022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd03641413000", + "result" : "invalid" + }, + { + "tcId" : 263, + "comment" : "Signature encoding contains incorrect types: r=n, s=list containing 0", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3028022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd03641413003020100", + "result" : "invalid" + }, + { + "tcId" : 264, + "comment" : "Signature encoding contains incorrect types: r=p, s=0.25", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3028022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f090380fe01", + "result" : "invalid" + }, + { + "tcId" : 265, + "comment" : "Signature encoding contains incorrect types: r=p, s=nan", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f090142", + "result" : "invalid" + }, + { + "tcId" : 266, + "comment" : "Signature encoding contains incorrect types: r=p, s=True", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f010101", + "result" : "invalid" + }, + { + "tcId" : 267, + "comment" : "Signature encoding contains incorrect types: r=p, s=False", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f010100", + "result" : "invalid" + }, + { + "tcId" : 268, + "comment" : "Signature encoding contains incorrect types: r=p, s=Null", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3025022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f0500", + "result" : "invalid" + }, + { + "tcId" : 269, + "comment" : "Signature encoding contains incorrect types: r=p, s=empyt UTF-8 string", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3025022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f0c00", + "result" : "invalid" + }, + { + "tcId" : 270, + "comment" : "Signature encoding contains incorrect types: r=p, s=\"0\"", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f0c0130", + "result" : "invalid" + }, + { + "tcId" : 271, + "comment" : "Signature encoding contains incorrect types: r=p, s=empty list", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3025022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f3000", + "result" : "invalid" + }, + { + "tcId" : 272, + "comment" : "Signature encoding contains incorrect types: r=p, s=list containing 0", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3028022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f3003020100", + "result" : "invalid" + }, + { + "tcId" : 273, + "comment" : "Signature encoding contains incorrect types: r=0.25, s=0.25", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "300a090380fe01090380fe01", + "result" : "invalid" + }, + { + "tcId" : 274, + "comment" : "Signature encoding contains incorrect types: r=nan, s=nan", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3006090142090142", + "result" : "invalid" + }, + { + "tcId" : 275, + "comment" : "Signature encoding contains incorrect types: r=True, s=True", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3006010101010101", + "result" : "invalid" + }, + { + "tcId" : 276, + "comment" : "Signature encoding contains incorrect types: r=False, s=False", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3006010100010100", + "result" : "invalid" + }, + { + "tcId" : 277, + "comment" : "Signature encoding contains incorrect types: r=Null, s=Null", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "300405000500", + "result" : "invalid" + }, + { + "tcId" : 278, + "comment" : "Signature encoding contains incorrect types: r=empyt UTF-8 string, s=empyt UTF-8 string", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30040c000c00", + "result" : "invalid" + }, + { + "tcId" : 279, + "comment" : "Signature encoding contains incorrect types: r=\"0\", s=\"0\"", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30060c01300c0130", + "result" : "invalid" + }, + { + "tcId" : 280, + "comment" : "Signature encoding contains incorrect types: r=empty list, s=empty list", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "300430003000", + "result" : "invalid" + }, + { + "tcId" : 281, + "comment" : "Signature encoding contains incorrect types: r=list containing 0, s=list containing 0", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "300a30030201003003020100", + "result" : "invalid" + }, + { + "tcId" : 282, + "comment" : "Signature encoding contains incorrect types: r=0.25, s=0", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3008090380fe01020100", + "result" : "invalid" + }, + { + "tcId" : 283, + "comment" : "Signature encoding contains incorrect types: r=nan, s=0", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3006090142020100", + "result" : "invalid" + }, + { + "tcId" : 284, + "comment" : "Signature encoding contains incorrect types: r=True, s=0", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3006010101020100", + "result" : "invalid" + }, + { + "tcId" : 285, + "comment" : "Signature encoding contains incorrect types: r=False, s=0", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "3006010100020100", + "result" : "invalid" + }, + { + "tcId" : 286, + "comment" : "Signature encoding contains incorrect types: r=Null, s=0", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30050500020100", + "result" : "invalid" + }, + { + "tcId" : 287, + "comment" : "Signature encoding contains incorrect types: r=empyt UTF-8 string, s=0", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30050c00020100", + "result" : "invalid" + }, + { + "tcId" : 288, + "comment" : "Signature encoding contains incorrect types: r=\"0\", s=0", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30060c0130020100", + "result" : "invalid" + }, + { + "tcId" : 289, + "comment" : "Signature encoding contains incorrect types: r=empty list, s=0", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30053000020100", + "result" : "invalid" + }, + { + "tcId" : 290, + "comment" : "Signature encoding contains incorrect types: r=list containing 0, s=0", + "flags" : [ + "InvalidTypesInSignature" + ], + "msg" : "313233343030", + "sig" : "30083003020100020100", + "result" : "invalid" + }, + { + "tcId" : 291, + "comment" : "Edge case for Shamir multiplication", + "flags" : [ + "EdgeCaseShamirMultiplication" + ], + "msg" : "3235353835", + "sig" : "3045022100dd1b7d09a7bd8218961034a39a87fecf5314f00c4d25eb58a07ac85e85eab516022035138c401ef8d3493d65c9002fe62b43aee568731b744548358996d9cc427e06", + "result" : "valid" + }, + { + "tcId" : 292, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "343236343739373234", + "sig" : "304502210095c29267d972a043d955224546222bba343fc1d4db0fec262a33ac61305696ae02206edfe96713aed56f8a28a6653f57e0b829712e5eddc67f34682b24f0676b2640", + "result" : "valid" + }, + { + "tcId" : 293, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "37313338363834383931", + "sig" : "3044022028f94a894e92024699e345fe66971e3edcd050023386135ab3939d550898fb25022032963e5bd41fa5911ed8f37deb86dae0a762bb6121c894615083c5d95ea01db3", + "result" : "valid" + }, + { + "tcId" : 294, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "3130333539333331363638", + "sig" : "3045022100be26b18f9549f89f411a9b52536b15aa270b84548d0e859a1952a27af1a77ac6022070c1d4fa9cd03cc8eaa8d506edb97eed7b8358b453c88aefbb880a3f0e8d472f", + "result" : "valid" + }, + { + "tcId" : 295, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "33393439343031323135", + "sig" : "3045022100b1a4b1478e65cc3eafdf225d1298b43f2da19e4bcff7eacc0a2e98cd4b74b1140220179aa31e304cc142cf5073171751b28f3f5e0fa88c994e7c55f1bc07b8d56c16", + "result" : "valid" + }, + { + "tcId" : 296, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "31333434323933303739", + "sig" : "30440220325332021261f1bd18f2712aa1e2252da23796da8a4b1ff6ea18cafec7e171f2022040b4f5e287ee61fc3c804186982360891eaa35c75f05a43ecd48b35d984a6648", + "result" : "valid" + }, + { + "tcId" : 297, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "33373036323131373132", + "sig" : "3045022100a23ad18d8fc66d81af0903890cbd453a554cb04cdc1a8ca7f7f78e5367ed88a0022023e3eb2ce1c04ea748c389bd97374aa9413b9268851c04dcd9f88e78813fee56", + "result" : "valid" + }, + { + "tcId" : 298, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "333433363838373132", + "sig" : "304402202bdea41cda63a2d14bf47353bd20880a690901de7cd6e3cc6d8ed5ba0cdb109102203cea66bccfc9f9bf8c7ca4e1c1457cc9145e13e936d90b3d9c7786b8b26cf4c7", + "result" : "valid" + }, + { + "tcId" : 299, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "31333531353330333730", + "sig" : "3045022100d7cd76ec01c1b1079eba9e2aa2a397243c4758c98a1ba0b7404a340b9b00ced602203575001e19d922e6de8b3d6c84ea43b5c3338106cf29990134e7669a826f78e6", + "result" : "valid" + }, + { + "tcId" : 300, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "36353533323033313236", + "sig" : "3045022100a872c744d936db21a10c361dd5c9063355f84902219652f6fc56dc95a7139d960220400df7575d9756210e9ccc77162c6b593c7746cfb48ac263c42750b421ef4bb9", + "result" : "valid" + }, + { + "tcId" : 301, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "31353634333436363033", + "sig" : "30450221009fa9afe07752da10b36d3afcd0fe44bfc40244d75203599cf8f5047fa3453854022050e0a7c013bfbf51819736972d44b4b56bc2a2b2c180df6ec672df171410d77a", + "result" : "valid" + }, + { + "tcId" : 302, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "34343239353339313137", + "sig" : "3045022100885640384d0d910efb177b46be6c3dc5cac81f0b88c3190bb6b5f99c2641f2050220738ed9bff116306d9caa0f8fc608be243e0b567779d8dab03e8e19d553f1dc8e", + "result" : "valid" + }, + { + "tcId" : 303, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "3130393533323631333531", + "sig" : "304402202d051f91c5a9d440c5676985710483bc4f1a6c611b10c95a2ff0363d90c2a45802206ddf94e6fba5be586833d0c53cf216ad3948f37953c26c1cf4968e9a9e8243dc", + "result" : "valid" + }, + { + "tcId" : 304, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "35393837333530303431", + "sig" : "3045022100f3ac2523967482f53d508522712d583f4379cd824101ff635ea0935117baa54f022027f10812227397e02cea96fb0e680761636dab2b080d1fc5d11685cbe8500cfe", + "result" : "valid" + }, + { + "tcId" : 305, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "33343633303036383738", + "sig" : "304502210096447cf68c3ab7266ed7447de3ac52fed7cc08cbdfea391c18a9b8ab370bc91302200f5e7874d3ac0e918f01c885a1639177c923f8660d1ceba1ca1f301bc675cdbc", + "result" : "valid" + }, + { + "tcId" : 306, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "39383137333230323837", + "sig" : "30440220530a0832b691da0b5619a0b11de6877f3c0971baaa68ed122758c29caaf46b7202206c89e44f5eb33060ea4b46318c39138eaedec72de42ba576579a6a4690e339f3", + "result" : "valid" + }, + { + "tcId" : 307, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "33323232303431303436", + "sig" : "30450221009c54c25500bde0b92d72d6ec483dc2482f3654294ca74de796b681255ed58a770220677453c6b56f527631c9f67b3f3eb621fd88582b4aff156d2f1567d6211a2a33", + "result" : "valid" + }, + { + "tcId" : 308, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "36363636333037313034", + "sig" : "3045022100e7909d41439e2f6af29136c7348ca2641a2b070d5b64f91ea9da7070c7a2618b022042d782f132fa1d36c2c88ba27c3d678d80184a5d1eccac7501f0b47e3d205008", + "result" : "valid" + }, + { + "tcId" : 309, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "31303335393531383938", + "sig" : "304402205924873209593135a4c3da7bb381227f8a4b6aa9f34fe5bb7f8fbc131a039ffe02201f1bb11b441c8feaa40f44213d9a405ed792d59fb49d5bcdd9a4285ae5693022", + "result" : "valid" + }, + { + "tcId" : 310, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "31383436353937313935", + "sig" : "3045022100eeb692c9b262969b231c38b5a7f60649e0c875cd64df88f33aa571fa3d29ab0e0220218b3a1eb06379c2c18cf51b06430786d1c64cd2d24c9b232b23e5bac7989acd", + "result" : "valid" + }, + { + "tcId" : 311, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "33313336303436313839", + "sig" : "3045022100a40034177f36091c2b653684a0e3eb5d4bff18e4d09f664c2800e7cafda1daf802203a3ec29853704e52031c58927a800a968353adc3d973beba9172cbbeab4dd149", + "result" : "valid" + }, + { + "tcId" : 312, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "32363633373834323534", + "sig" : "3045022100b5d795cc75cea5c434fa4185180cd6bd21223f3d5a86da6670d71d95680dadbf022054e4d8810a001ecbb9f7ca1c2ebfdb9d009e9031a431aca3c20ab4e0d1374ec1", + "result" : "valid" + }, + { + "tcId" : 313, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "31363532313030353234", + "sig" : "3044022007dc2478d43c1232a4595608c64426c35510051a631ae6a5a6eb1161e57e42e102204a59ea0fdb72d12165cea3bf1ca86ba97517bd188db3dbd21a5a157850021984", + "result" : "valid" + }, + { + "tcId" : 314, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "35373438303831363936", + "sig" : "3045022100ddd20c4a05596ca868b558839fce9f6511ddd83d1ccb53f82e5269d559a0155202205b91734729d93093ff22123c4a25819d7feb66a250663fc780cb66fc7b6e6d17", + "result" : "valid" + }, + { + "tcId" : 315, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "36333433393133343638", + "sig" : "30450221009cde6e0ede0a003f02fda0a01b59facfe5dec063318f279ce2de7a9b1062f7b702202886a5b8c679bdf8224c66f908fd6205492cb70b0068d46ae4f33a4149b12a52", + "result" : "valid" + }, + { + "tcId" : 316, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "31353431313033353938", + "sig" : "3045022100c5771016d0dd6357143c89f684cd740423502554c0c59aa8c99584f1ff38f609022054b405f4477546686e464c5463b4fd4190572e58d0f7e7357f6e61947d20715c", + "result" : "valid" + }, + { + "tcId" : 317, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "3130343738353830313238", + "sig" : "3045022100a24ebc0ec224bd67ae397cbe6fa37b3125adbd34891abe2d7c7356921916dfe6022034f6eb6374731bbbafc4924fb8b0bdcdda49456d724cdae6178d87014cb53d8c", + "result" : "valid" + }, + { + "tcId" : 318, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "3130353336323835353638", + "sig" : "304402202557d64a7aee2e0931c012e4fea1cd3a2c334edae68cdeb7158caf21b68e5a2402207f06cdbb6a90023a973882ed97b080fe6b05af3ec93db6f1a4399a69edf7670d", + "result" : "valid" + }, + { + "tcId" : 319, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "393533393034313035", + "sig" : "3045022100c4f2eccbb6a24350c8466450b9d61b207ee359e037b3dcedb42a3f2e6dd6aeb502203263c6b59a2f55cdd1c6e14894d5e5963b28bc3e2469ac9ba1197991ca7ff9c7", + "result" : "valid" + }, + { + "tcId" : 320, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "393738383438303339", + "sig" : "3045022100eff04781c9cbcd162d0a25a6e2ebcca43506c523385cb515d49ea38a1b12fcad022015acd73194c91a95478534f23015b672ebed213e45424dd2c8e26ac8b3eb34a5", + "result" : "valid" + }, + { + "tcId" : 321, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "33363130363732343432", + "sig" : "3045022100f58b4e3110a64bf1b5db97639ee0e5a9c8dfa49dc59b679891f520fdf0584c8702202cd8fe51888aee9db3e075440fd4db73b5c732fb87b510e97093d66415f62af7", + "result" : "valid" + }, + { + "tcId" : 322, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "31303534323430373035", + "sig" : "3045022100f8abecaa4f0c502de4bf5903d48417f786bf92e8ad72fec0bd7fcb7800c0bbe302204c7f9e231076a30b7ae36b0cebe69ccef1cd194f7cce93a5588fd6814f437c0e", + "result" : "valid" + }, + { + "tcId" : 323, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "35313734343438313937", + "sig" : "304402205d5b38bd37ad498b2227a633268a8cca879a5c7c94a4e416bd0a614d09e606d2022012b8d664ea9991062ecbb834e58400e25c46007af84f6007d7f1685443269afe", + "result" : "valid" + }, + { + "tcId" : 324, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "31393637353631323531", + "sig" : "304402200c1cd9fe4034f086a2b52d65b9d3834d72aebe7f33dfe8f976da82648177d8e3022013105782e3d0cfe85c2778dec1a848b27ac0ae071aa6da341a9553a946b41e59", + "result" : "valid" + }, + { + "tcId" : 325, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "33343437323533333433", + "sig" : "3045022100ae7935fb96ff246b7b5d5662870d1ba587b03d6e1360baf47988b5c02ccc1a5b02205f00c323272083782d4a59f2dfd65e49de0693627016900ef7e61428056664b3", + "result" : "valid" + }, + { + "tcId" : 326, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "333638323634333138", + "sig" : "3044022000a134b5c6ccbcefd4c882b945baeb4933444172795fa6796aae1490675470980220566e46105d24d890151e3eea3ebf88f5b92b3f5ec93a217765a6dcbd94f2c55b", + "result" : "valid" + }, + { + "tcId" : 327, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "33323631313938363038", + "sig" : "304402202e4721363ad3992c139e5a1c26395d2c2d777824aa24fde075e0d7381171309d0220740f7c494418e1300dd4512f782a58800bff6a7abdfdd20fbbd4f05515ca1a4f", + "result" : "valid" + }, + { + "tcId" : 328, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "39363738373831303934", + "sig" : "304402206852e9d3cd9fe373c2d504877967d365ab1456707b6817a042864694e1960ccf0220064b27ea142b30887b84c86adccb2fa39a6911ad21fc7e819f593be52bc4f3bd", + "result" : "valid" + }, + { + "tcId" : 329, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "34393538383233383233", + "sig" : "30440220188a8c5648dc79eace158cf886c62b5468f05fd95f03a7635c5b4c31f09af4c5022036361a0b571a00c6cd5e686ccbfcfa703c4f97e48938346d0c103fdc76dc5867", + "result" : "valid" + }, + { + "tcId" : 330, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "383234363337383337", + "sig" : "3045022100a74f1fb9a8263f62fc4416a5b7d584f4206f3996bb91f6fc8e73b9e92bad0e1302206815032e8c7d76c3ab06a86f33249ce9940148cb36d1f417c2e992e801afa3fa", + "result" : "valid" + }, + { + "tcId" : 331, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "3131303230383333373736", + "sig" : "3044022007244865b72ff37e62e3146f0dc14682badd7197799135f0b00ade7671742bfe02200d80c2238edb4e4a7a86a8c57ca9af1711f406f7f5da0299aa04e2932d960754", + "result" : "valid" + }, + { + "tcId" : 332, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "313333383731363438", + "sig" : "3045022100da7fdd05b5badabd619d805c4ee7d9a84f84ddd5cf9c5bf4d4338140d689ef08022028f1cf4fa1c3c5862cfa149c0013cf5fe6cf5076cae000511063e7de25bb38e5", + "result" : "valid" + }, + { + "tcId" : 333, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "333232313434313632", + "sig" : "3045022100d3027c656f6d4fdfd8ede22093e3c303b0133c340d615e7756f6253aea927238022009aef060c8e4cef972974011558df144fed25ca69ae8d0b2eaf1a8feefbec417", + "result" : "valid" + }, + { + "tcId" : 334, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "3130363836363535353436", + "sig" : "304402200bf6c0188dc9571cd0e21eecac5fbb19d2434988e9cc10244593ef3a98099f6902204864a562661f9221ec88e3dd0bc2f6e27ac128c30cc1a80f79ec670a22b042ee", + "result" : "valid" + }, + { + "tcId" : 335, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "3632313535323436", + "sig" : "3045022100ae459640d5d1179be47a47fa538e16d94ddea5585e7a244804a51742c686443a02206c8e30e530a634fae80b3ceb062978b39edbe19777e0a24553b68886181fd897", + "result" : "valid" + }, + { + "tcId" : 336, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "37303330383138373734", + "sig" : "304402201cf3517ba3bf2ab8b9ead4ebb6e866cb88a1deacb6a785d3b63b483ca02ac4950220249a798b73606f55f5f1c70de67cb1a0cff95d7dc50b3a617df861bad3c6b1c9", + "result" : "valid" + }, + { + "tcId" : 337, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "35393234353233373434", + "sig" : "3045022100e69b5238265ea35d77e4dd172288d8cea19810a10292617d5976519dc5757cb802204b03c5bc47e826bdb27328abd38d3056d77476b2130f3df6ec4891af08ba1e29", + "result" : "valid" + }, + { + "tcId" : 338, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "31343935353836363231", + "sig" : "304402205f9d7d7c870d085fc1d49fff69e4a275812800d2cf8973e7325866cb40fa2b6f02206d1f5491d9f717a597a15fd540406486d76a44697b3f0d9d6dcef6669f8a0a56", + "result" : "valid" + }, + { + "tcId" : 339, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "34303035333134343036", + "sig" : "304402200a7d5b1959f71df9f817146ee49bd5c89b431e7993e2fdecab6858957da685ae02200f8aad2d254690bdc13f34a4fec44a02fd745a422df05ccbb54635a8b86b9609", + "result" : "valid" + }, + { + "tcId" : 340, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "33303936343537353132", + "sig" : "3044022079e88bf576b74bc07ca142395fda28f03d3d5e640b0b4ff0752c6d94cd553408022032cea05bd2d706c8f6036a507e2ab7766004f0904e2e5c5862749c0073245d6a", + "result" : "valid" + }, + { + "tcId" : 341, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "32373834303235363230", + "sig" : "30450221009d54e037a00212b377bc8874798b8da080564bbdf7e07591b861285809d01488022018b4e557667a82bd95965f0706f81a29243fbdd86968a7ebeb43069db3b18c7f", + "result" : "valid" + }, + { + "tcId" : 342, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "32363138373837343138", + "sig" : "304402202664f1ffa982fedbcc7cab1b8bc6e2cb420218d2a6077ad08e591ba9feab33bd022049f5c7cb515e83872a3d41b4cdb85f242ad9d61a5bfc01debfbb52c6c84ba728", + "result" : "valid" + }, + { + "tcId" : 343, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "31363432363235323632", + "sig" : "304402205827518344844fd6a7de73cbb0a6befdea7b13d2dee4475317f0f18ffc81524b02204f5ccb4e0b488b5a5d760aacddb2d791970fe43da61eb30e2e90208a817e46db", + "result" : "valid" + }, + { + "tcId" : 344, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "36383234313839343336", + "sig" : "304502210097ab19bd139cac319325869218b1bce111875d63fb12098a04b0cd59b6fdd3a30220431d9cea3a243847303cebda56476431d034339f31d785ee8852db4f040d4921", + "result" : "valid" + }, + { + "tcId" : 345, + "comment" : "special case hash", + "flags" : [ + "SpecialCaseHash" + ], + "msg" : "343834323435343235", + "sig" : "3044022052c683144e44119ae2013749d4964ef67509278f6d38ba869adcfa69970e123d02203479910167408f45bda420a626ec9c4ec711c1274be092198b4187c018b562ca", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0407310f90a9eae149a08402f54194a0f7b4ac427bf8d9bd6c7681071dc47dc36226a6d37ac46d61fd600c0bf1bff87689ed117dda6b0e59318ae010a197a26ca0", + "wx" : "07310f90a9eae149a08402f54194a0f7b4ac427bf8d9bd6c7681071dc47dc362", + "wy" : "26a6d37ac46d61fd600c0bf1bff87689ed117dda6b0e59318ae010a197a26ca0" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000407310f90a9eae149a08402f54194a0f7b4ac427bf8d9bd6c7681071dc47dc36226a6d37ac46d61fd600c0bf1bff87689ed117dda6b0e59318ae010a197a26ca0", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEBzEPkKnq4UmghAL1QZSg97SsQnv42b1s\ndoEHHcR9w2ImptN6xG1h/WAMC/G/+HaJ7RF92msOWTGK4BChl6JsoA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 346, + "comment" : "k*G has a large x-coordinate", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "30160211014551231950b75fc4402da1722fc9baeb020103", + "result" : "valid" + }, + { + "tcId" : 347, + "comment" : "r too large", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2c020103", + "result" : "invalid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04bc97e7585eecad48e16683bc4091708e1a930c683fc47001d4b383594f2c4e22705989cf69daeadd4e4e4b8151ed888dfec20fb01728d89d56b3f38f2ae9c8c5", + "wx" : "00bc97e7585eecad48e16683bc4091708e1a930c683fc47001d4b383594f2c4e22", + "wy" : "705989cf69daeadd4e4e4b8151ed888dfec20fb01728d89d56b3f38f2ae9c8c5" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004bc97e7585eecad48e16683bc4091708e1a930c683fc47001d4b383594f2c4e22705989cf69daeadd4e4e4b8151ed888dfec20fb01728d89d56b3f38f2ae9c8c5", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEvJfnWF7srUjhZoO8QJFwjhqTDGg/xHAB\n1LODWU8sTiJwWYnPadrq3U5OS4FR7YiN/sIPsBco2J1Ws/OPKunIxQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 348, + "comment" : "r,s are large", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413f020103", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0444ad339afbc21e9abf7b602a5ca535ea378135b6d10d81310bdd8293d1df3252b63ff7d0774770f8fe1d1722fa83acd02f434e4fc110a0cc8f6dddd37d56c463", + "wx" : "44ad339afbc21e9abf7b602a5ca535ea378135b6d10d81310bdd8293d1df3252", + "wy" : "00b63ff7d0774770f8fe1d1722fa83acd02f434e4fc110a0cc8f6dddd37d56c463" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000444ad339afbc21e9abf7b602a5ca535ea378135b6d10d81310bdd8293d1df3252b63ff7d0774770f8fe1d1722fa83acd02f434e4fc110a0cc8f6dddd37d56c463", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAERK0zmvvCHpq/e2AqXKU16jeBNbbRDYEx\nC92Ck9HfMlK2P/fQd0dw+P4dFyL6g6zQL0NOT8EQoMyPbd3TfVbEYw==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 349, + "comment" : "r and s^-1 have a large Hamming weight", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc02203e9a7582886089c62fb840cf3b83061cd1cff3ae4341808bb5bdee6191174177", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "041260c2122c9e244e1af5151bede0c3ae23b54d7c596881d3eebad21f37dd878c5c9a0c1a9ade76737a8811bd6a7f9287c978ee396aa89c11e47229d2ccb552f0", + "wx" : "1260c2122c9e244e1af5151bede0c3ae23b54d7c596881d3eebad21f37dd878c", + "wy" : "5c9a0c1a9ade76737a8811bd6a7f9287c978ee396aa89c11e47229d2ccb552f0" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200041260c2122c9e244e1af5151bede0c3ae23b54d7c596881d3eebad21f37dd878c5c9a0c1a9ade76737a8811bd6a7f9287c978ee396aa89c11e47229d2ccb552f0", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEEmDCEiyeJE4a9RUb7eDDriO1TXxZaIHT\n7rrSHzfdh4xcmgwamt52c3qIEb1qf5KHyXjuOWqonBHkcinSzLVS8A==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 350, + "comment" : "r and s^-1 have a large Hamming weight", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc022024238e70b431b1a64efdf9032669939d4b77f249503fc6905feb7540dea3e6d2", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "041877045be25d34a1d0600f9d5c00d0645a2a54379b6ceefad2e6bf5c2a3352ce821a532cc1751ee1d36d41c3d6ab4e9b143e44ec46d73478ea6a79a5c0e54159", + "wx" : "1877045be25d34a1d0600f9d5c00d0645a2a54379b6ceefad2e6bf5c2a3352ce", + "wy" : "00821a532cc1751ee1d36d41c3d6ab4e9b143e44ec46d73478ea6a79a5c0e54159" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200041877045be25d34a1d0600f9d5c00d0645a2a54379b6ceefad2e6bf5c2a3352ce821a532cc1751ee1d36d41c3d6ab4e9b143e44ec46d73478ea6a79a5c0e54159", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEGHcEW+JdNKHQYA+dXADQZFoqVDebbO76\n0ua/XCozUs6CGlMswXUe4dNtQcPWq06bFD5E7EbXNHjqanmlwOVBWQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 351, + "comment" : "small r and s", + "flags" : [ + "SmallRandS", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3006020101020101", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04455439fcc3d2deeceddeaece60e7bd17304f36ebb602adf5a22e0b8f1db46a50aec38fb2baf221e9a8d1887c7bf6222dd1834634e77263315af6d23609d04f77", + "wx" : "455439fcc3d2deeceddeaece60e7bd17304f36ebb602adf5a22e0b8f1db46a50", + "wy" : "00aec38fb2baf221e9a8d1887c7bf6222dd1834634e77263315af6d23609d04f77" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004455439fcc3d2deeceddeaece60e7bd17304f36ebb602adf5a22e0b8f1db46a50aec38fb2baf221e9a8d1887c7bf6222dd1834634e77263315af6d23609d04f77", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAERVQ5/MPS3uzt3q7OYOe9FzBPNuu2Aq31\noi4Ljx20alCuw4+yuvIh6ajRiHx79iIt0YNGNOdyYzFa9tI2CdBPdw==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 352, + "comment" : "small r and s", + "flags" : [ + "SmallRandS", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3006020101020102", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "042e1f466b024c0c3ace2437de09127fed04b706f94b19a21bb1c2acf35cece7180449ae3523d72534e964972cfd3b38af0bddd9619e5af223e4d1a40f34cf9f1d", + "wx" : "2e1f466b024c0c3ace2437de09127fed04b706f94b19a21bb1c2acf35cece718", + "wy" : "0449ae3523d72534e964972cfd3b38af0bddd9619e5af223e4d1a40f34cf9f1d" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200042e1f466b024c0c3ace2437de09127fed04b706f94b19a21bb1c2acf35cece7180449ae3523d72534e964972cfd3b38af0bddd9619e5af223e4d1a40f34cf9f1d", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAELh9GawJMDDrOJDfeCRJ/7QS3BvlLGaIb\nscKs81zs5xgESa41I9clNOlklyz9OzivC93ZYZ5a8iPk0aQPNM+fHQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 353, + "comment" : "small r and s", + "flags" : [ + "SmallRandS", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3006020101020103", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "048e7abdbbd18de7452374c1879a1c3b01d13261e7d4571c3b47a1c76c55a2337326ed897cd517a4f5349db809780f6d2f2b9f6299d8b5a89077f1119a718fd7b3", + "wx" : "008e7abdbbd18de7452374c1879a1c3b01d13261e7d4571c3b47a1c76c55a23373", + "wy" : "26ed897cd517a4f5349db809780f6d2f2b9f6299d8b5a89077f1119a718fd7b3" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200048e7abdbbd18de7452374c1879a1c3b01d13261e7d4571c3b47a1c76c55a2337326ed897cd517a4f5349db809780f6d2f2b9f6299d8b5a89077f1119a718fd7b3", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEjnq9u9GN50UjdMGHmhw7AdEyYefUVxw7\nR6HHbFWiM3Mm7Yl81Rek9TSduAl4D20vK59imdi1qJB38RGacY/Xsw==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 354, + "comment" : "small r and s", + "flags" : [ + "SmallRandS", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3006020102020101", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "047b333d4340d3d718dd3e6aff7de7bbf8b72bfd616c8420056052842376b9af1942117c5afeac755d6f376fc6329a7d76051b87123a4a5d0bc4a539380f03de7b", + "wx" : "7b333d4340d3d718dd3e6aff7de7bbf8b72bfd616c8420056052842376b9af19", + "wy" : "42117c5afeac755d6f376fc6329a7d76051b87123a4a5d0bc4a539380f03de7b" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200047b333d4340d3d718dd3e6aff7de7bbf8b72bfd616c8420056052842376b9af1942117c5afeac755d6f376fc6329a7d76051b87123a4a5d0bc4a539380f03de7b", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEezM9Q0DT1xjdPmr/fee7+Lcr/WFshCAF\nYFKEI3a5rxlCEXxa/qx1XW83b8Yymn12BRuHEjpKXQvEpTk4DwPeew==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 355, + "comment" : "small r and s", + "flags" : [ + "SmallRandS", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3006020102020102", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04d30ca4a0ddb6616c851d30ced682c40f83c62758a1f2759988d6763a88f1c0e503a80d5415650d41239784e8e2fb1235e9fe991d112ebb81186cbf0da2de3aff", + "wx" : "00d30ca4a0ddb6616c851d30ced682c40f83c62758a1f2759988d6763a88f1c0e5", + "wy" : "03a80d5415650d41239784e8e2fb1235e9fe991d112ebb81186cbf0da2de3aff" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004d30ca4a0ddb6616c851d30ced682c40f83c62758a1f2759988d6763a88f1c0e503a80d5415650d41239784e8e2fb1235e9fe991d112ebb81186cbf0da2de3aff", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE0wykoN22YWyFHTDO1oLED4PGJ1ih8nWZ\niNZ2OojxwOUDqA1UFWUNQSOXhOji+xI16f6ZHREuu4EYbL8Not46/w==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 356, + "comment" : "small r and s", + "flags" : [ + "SmallRandS", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3006020102020103", + "result" : "valid" + }, + { + "tcId" : 357, + "comment" : "r is larger than n", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3026022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364143020103", + "result" : "invalid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0448969b39991297b332a652d3ee6e01e909b39904e71fa2354a7830c7750baf24b4012d1b830d199ccb1fc972b32bfded55f09cd62d257e5e844e27e57a1594ec", + "wx" : "48969b39991297b332a652d3ee6e01e909b39904e71fa2354a7830c7750baf24", + "wy" : "00b4012d1b830d199ccb1fc972b32bfded55f09cd62d257e5e844e27e57a1594ec" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000448969b39991297b332a652d3ee6e01e909b39904e71fa2354a7830c7750baf24b4012d1b830d199ccb1fc972b32bfded55f09cd62d257e5e844e27e57a1594ec", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAESJabOZkSl7MyplLT7m4B6QmzmQTnH6I1\nSngwx3ULryS0AS0bgw0ZnMsfyXKzK/3tVfCc1i0lfl6ETiflehWU7A==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 358, + "comment" : "s is larger than n", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "30080201020203ed2979", + "result" : "invalid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0402ef4d6d6cfd5a94f1d7784226e3e2a6c0a436c55839619f38fb4472b5f9ee777eb4acd4eebda5cd72875ffd2a2f26229c2dc6b46500919a432c86739f3ae866", + "wx" : "02ef4d6d6cfd5a94f1d7784226e3e2a6c0a436c55839619f38fb4472b5f9ee77", + "wy" : "7eb4acd4eebda5cd72875ffd2a2f26229c2dc6b46500919a432c86739f3ae866" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000402ef4d6d6cfd5a94f1d7784226e3e2a6c0a436c55839619f38fb4472b5f9ee777eb4acd4eebda5cd72875ffd2a2f26229c2dc6b46500919a432c86739f3ae866", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEAu9NbWz9WpTx13hCJuPipsCkNsVYOWGf\nOPtEcrX57nd+tKzU7r2lzXKHX/0qLyYinC3GtGUAkZpDLIZznzroZg==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 359, + "comment" : "small r and s^-1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "30260202010102203a74e9d3a74e9d3a74e9d3a74e9d3a749f8ab3732a0a89604a09bce5b2916da4", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04464f4ff715729cae5072ca3bd801d3195b67aec65e9b01aad20a2943dcbcb584b1afd29d31a39a11d570aa1597439b3b2d1971bf2f1abf15432d0207b10d1d08", + "wx" : "464f4ff715729cae5072ca3bd801d3195b67aec65e9b01aad20a2943dcbcb584", + "wy" : "00b1afd29d31a39a11d570aa1597439b3b2d1971bf2f1abf15432d0207b10d1d08" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004464f4ff715729cae5072ca3bd801d3195b67aec65e9b01aad20a2943dcbcb584b1afd29d31a39a11d570aa1597439b3b2d1971bf2f1abf15432d0207b10d1d08", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAERk9P9xVynK5Qcso72AHTGVtnrsZemwGq\n0gopQ9y8tYSxr9KdMaOaEdVwqhWXQ5s7LRlxvy8avxVDLQIHsQ0dCA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 360, + "comment" : "smallish r and s^-1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "302b02072d9b4d347952cc02200343aefc2f25d98b882e86eb9e30d55a6eb508b516510b34024ae4b6362330b3", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04157f8fddf373eb5f49cfcf10d8b853cf91cbcd7d665c3522ba7dd738ddb79a4cdeadf1a5c448ea3c9f4191a8999abfcc757ac6d64567ef072c47fec613443b8f", + "wx" : "157f8fddf373eb5f49cfcf10d8b853cf91cbcd7d665c3522ba7dd738ddb79a4c", + "wy" : "00deadf1a5c448ea3c9f4191a8999abfcc757ac6d64567ef072c47fec613443b8f" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004157f8fddf373eb5f49cfcf10d8b853cf91cbcd7d665c3522ba7dd738ddb79a4cdeadf1a5c448ea3c9f4191a8999abfcc757ac6d64567ef072c47fec613443b8f", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEFX+P3fNz619Jz88Q2LhTz5HLzX1mXDUi\nun3XON23mkzerfGlxEjqPJ9BkaiZmr/MdXrG1kVn7wcsR/7GE0Q7jw==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 361, + "comment" : "100-bit r and small s^-1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3031020d1033e67e37b32b445580bf4efc02206f906f906f906f906f906f906f906f8fe1cab5eefdb214061dce3b22789f1d6f", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "040934a537466c07430e2c48feb990bb19fb78cecc9cee424ea4d130291aa237f0d4f92d23b462804b5b68c52558c01c9996dbf727fccabbeedb9621a400535afa", + "wx" : "0934a537466c07430e2c48feb990bb19fb78cecc9cee424ea4d130291aa237f0", + "wy" : "00d4f92d23b462804b5b68c52558c01c9996dbf727fccabbeedb9621a400535afa" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200040934a537466c07430e2c48feb990bb19fb78cecc9cee424ea4d130291aa237f0d4f92d23b462804b5b68c52558c01c9996dbf727fccabbeedb9621a400535afa", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAECTSlN0ZsB0MOLEj+uZC7Gft4zsyc7kJO\npNEwKRqiN/DU+S0jtGKAS1toxSVYwByZltv3J/zKu+7bliGkAFNa+g==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 362, + "comment" : "small r and 100 bit s^-1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3026020201010220783266e90f43dafe5cd9b3b0be86de22f9de83677d0f50713a468ec72fcf5d57", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04d6ef20be66c893f741a9bf90d9b74675d1c2a31296397acb3ef174fd0b300c654a0c95478ca00399162d7f0f2dc89efdc2b28a30fbabe285857295a4b0c4e265", + "wx" : "00d6ef20be66c893f741a9bf90d9b74675d1c2a31296397acb3ef174fd0b300c65", + "wy" : "4a0c95478ca00399162d7f0f2dc89efdc2b28a30fbabe285857295a4b0c4e265" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004d6ef20be66c893f741a9bf90d9b74675d1c2a31296397acb3ef174fd0b300c654a0c95478ca00399162d7f0f2dc89efdc2b28a30fbabe285857295a4b0c4e265", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE1u8gvmbIk/dBqb+Q2bdGddHCoxKWOXrL\nPvF0/QswDGVKDJVHjKADmRYtfw8tyJ79wrKKMPur4oWFcpWksMTiZQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 363, + "comment" : "100-bit r and s^-1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3031020d062522bbd3ecbe7c39e93e7c260220783266e90f43dafe5cd9b3b0be86de22f9de83677d0f50713a468ec72fcf5d57", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04b7291d1404e0c0c07dab9372189f4bd58d2ceaa8d15ede544d9514545ba9ee0629c9a63d5e308769cc30ec276a410e6464a27eeafd9e599db10f053a4fe4a829", + "wx" : "00b7291d1404e0c0c07dab9372189f4bd58d2ceaa8d15ede544d9514545ba9ee06", + "wy" : "29c9a63d5e308769cc30ec276a410e6464a27eeafd9e599db10f053a4fe4a829" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004b7291d1404e0c0c07dab9372189f4bd58d2ceaa8d15ede544d9514545ba9ee0629c9a63d5e308769cc30ec276a410e6464a27eeafd9e599db10f053a4fe4a829", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEtykdFATgwMB9q5NyGJ9L1Y0s6qjRXt5U\nTZUUVFup7gYpyaY9XjCHacww7CdqQQ5kZKJ+6v2eWZ2xDwU6T+SoKQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 364, + "comment" : "r and s^-1 are close to n", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3045022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd03640c1022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c0", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "046e28303305d642ccb923b722ea86b2a0bc8e3735ecb26e849b19c9f76b2fdbb8186e80d64d8cab164f5238f5318461bf89d4d96ee6544c816c7566947774e0f6", + "wx" : "6e28303305d642ccb923b722ea86b2a0bc8e3735ecb26e849b19c9f76b2fdbb8", + "wy" : "186e80d64d8cab164f5238f5318461bf89d4d96ee6544c816c7566947774e0f6" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200046e28303305d642ccb923b722ea86b2a0bc8e3735ecb26e849b19c9f76b2fdbb8186e80d64d8cab164f5238f5318461bf89d4d96ee6544c816c7566947774e0f6", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEbigwMwXWQsy5I7ci6oayoLyONzXssm6E\nmxnJ92sv27gYboDWTYyrFk9SOPUxhGG/idTZbuZUTIFsdWaUd3Tg9g==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 365, + "comment" : "r and s are 64-bit integer", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "30160209009c44febf31c3594d020900839ed28247c2b06b", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04375bda93f6af92fb5f8f4b1b5f0534e3bafab34cb7ad9fb9d0b722e4a5c302a9a00b9f387a5a396097aa2162fc5bbcf4a5263372f681c94da51e9799120990fd", + "wx" : "375bda93f6af92fb5f8f4b1b5f0534e3bafab34cb7ad9fb9d0b722e4a5c302a9", + "wy" : "00a00b9f387a5a396097aa2162fc5bbcf4a5263372f681c94da51e9799120990fd" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004375bda93f6af92fb5f8f4b1b5f0534e3bafab34cb7ad9fb9d0b722e4a5c302a9a00b9f387a5a396097aa2162fc5bbcf4a5263372f681c94da51e9799120990fd", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEN1vak/avkvtfj0sbXwU047r6s0y3rZ+5\n0Lci5KXDAqmgC584elo5YJeqIWL8W7z0pSYzcvaByU2lHpeZEgmQ/Q==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 366, + "comment" : "r and s are 100-bit integer", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "301e020d09df8b682430beef6f5fd7c7cf020d0fd0a62e13778f4222a0d61c8a", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04d75b68216babe03ae257e94b4e3bf1c52f44e3df266d1524ff8c5ea69da73197da4bff9ed1c53f44917a67d7b978598e89df359e3d5913eaea24f3ae259abc44", + "wx" : "00d75b68216babe03ae257e94b4e3bf1c52f44e3df266d1524ff8c5ea69da73197", + "wy" : "00da4bff9ed1c53f44917a67d7b978598e89df359e3d5913eaea24f3ae259abc44" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004d75b68216babe03ae257e94b4e3bf1c52f44e3df266d1524ff8c5ea69da73197da4bff9ed1c53f44917a67d7b978598e89df359e3d5913eaea24f3ae259abc44", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE11toIWur4DriV+lLTjvxxS9E498mbRUk\n/4xepp2nMZfaS/+e0cU/RJF6Z9e5eFmOid81nj1ZE+rqJPOuJZq8RA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 367, + "comment" : "r and s are 128-bit integer", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "30260211008a598e563a89f526c32ebec8de26367a02110084f633e2042630e99dd0f1e16f7a04bf", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0478bcda140aed23d430cb23c3dc0d01f423db134ee94a3a8cb483f2deac2ac653118114f6f33045d4e9ed9107085007bfbddf8f58fe7a1a2445d66a990045476e", + "wx" : "78bcda140aed23d430cb23c3dc0d01f423db134ee94a3a8cb483f2deac2ac653", + "wy" : "118114f6f33045d4e9ed9107085007bfbddf8f58fe7a1a2445d66a990045476e" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000478bcda140aed23d430cb23c3dc0d01f423db134ee94a3a8cb483f2deac2ac653118114f6f33045d4e9ed9107085007bfbddf8f58fe7a1a2445d66a990045476e", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEeLzaFArtI9QwyyPD3A0B9CPbE07pSjqM\ntIPy3qwqxlMRgRT28zBF1OntkQcIUAe/vd+PWP56GiRF1mqZAEVHbg==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 368, + "comment" : "r and s are 160-bit integer", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "302e021500aa6eeb5823f7fa31b466bb473797f0d0314c0bdf021500e2977c479e6d25703cebbc6bd561938cc9d1bfb9", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04bb79f61857f743bfa1b6e7111ce4094377256969e4e15159123d9548acc3be6c1f9d9f8860dcffd3eb36dd6c31ff2e7226c2009c4c94d8d7d2b5686bf7abd677", + "wx" : "00bb79f61857f743bfa1b6e7111ce4094377256969e4e15159123d9548acc3be6c", + "wy" : "1f9d9f8860dcffd3eb36dd6c31ff2e7226c2009c4c94d8d7d2b5686bf7abd677" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004bb79f61857f743bfa1b6e7111ce4094377256969e4e15159123d9548acc3be6c1f9d9f8860dcffd3eb36dd6c31ff2e7226c2009c4c94d8d7d2b5686bf7abd677", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEu3n2GFf3Q7+htucRHOQJQ3claWnk4VFZ\nEj2VSKzDvmwfnZ+IYNz/0+s23Wwx/y5yJsIAnEyU2NfStWhr96vWdw==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 369, + "comment" : "s == 1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3025022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c1020101", + "result" : "valid" + }, + { + "tcId" : 370, + "comment" : "s == 0", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3025022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c1020100", + "result" : "invalid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0493591827d9e6713b4e9faea62c72b28dfefa68e0c05160b5d6aae88fd2e36c36073f5545ad5af410af26afff68654cf72d45e493489311203247347a890f4518", + "wx" : "0093591827d9e6713b4e9faea62c72b28dfefa68e0c05160b5d6aae88fd2e36c36", + "wy" : "073f5545ad5af410af26afff68654cf72d45e493489311203247347a890f4518" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000493591827d9e6713b4e9faea62c72b28dfefa68e0c05160b5d6aae88fd2e36c36073f5545ad5af410af26afff68654cf72d45e493489311203247347a890f4518", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEk1kYJ9nmcTtOn66mLHKyjf76aODAUWC1\n1qroj9LjbDYHP1VFrVr0EK8mr/9oZUz3LUXkk0iTESAyRzR6iQ9FGA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 371, + "comment" : "edge case modular inverse", + "flags" : [ + "ModularInverse", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c10220419d981c515af8cc82545aac0c85e9e308fbb2eab6acd7ed497e0b4145a18fd9", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0431ed3081aefe001eb6402069ee2ccc1862937b85995144dba9503943587bf0dada01b8cc4df34f5ab3b1a359615208946e5ee35f98ee775b8ccecd86ccc1650f", + "wx" : "31ed3081aefe001eb6402069ee2ccc1862937b85995144dba9503943587bf0da", + "wy" : "00da01b8cc4df34f5ab3b1a359615208946e5ee35f98ee775b8ccecd86ccc1650f" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000431ed3081aefe001eb6402069ee2ccc1862937b85995144dba9503943587bf0dada01b8cc4df34f5ab3b1a359615208946e5ee35f98ee775b8ccecd86ccc1650f", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEMe0wga7+AB62QCBp7izMGGKTe4WZUUTb\nqVA5Q1h78NraAbjMTfNPWrOxo1lhUgiUbl7jX5jud1uMzs2GzMFlDw==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 372, + "comment" : "edge case modular inverse", + "flags" : [ + "ModularInverse", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c102201b21717ad71d23bbac60a9ad0baf75b063c9fdf52a00ebf99d022172910993c9", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "047dff66fa98509ff3e2e51045f4390523dccda43a3bc2885e58c248090990eea854c76c2b9adeb6bb571823e07fd7c65c8639cf9d905260064c8e7675ce6d98b4", + "wx" : "7dff66fa98509ff3e2e51045f4390523dccda43a3bc2885e58c248090990eea8", + "wy" : "54c76c2b9adeb6bb571823e07fd7c65c8639cf9d905260064c8e7675ce6d98b4" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200047dff66fa98509ff3e2e51045f4390523dccda43a3bc2885e58c248090990eea854c76c2b9adeb6bb571823e07fd7c65c8639cf9d905260064c8e7675ce6d98b4", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEff9m+phQn/Pi5RBF9DkFI9zNpDo7wohe\nWMJICQmQ7qhUx2wrmt62u1cYI+B/18ZchjnPnZBSYAZMjnZ1zm2YtA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 373, + "comment" : "edge case modular inverse", + "flags" : [ + "ModularInverse", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c102202f588f66018f3dd14db3e28e77996487e32486b521ed8e5a20f06591951777e9", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "044280509aab64edfc0b4a2967e4cbce849cb544e4a77313c8e6ece579fbd7420a2e89fe5cc1927d554e6a3bb14033ea7c922cd75cba2c7415fdab52f20b1860f1", + "wx" : "4280509aab64edfc0b4a2967e4cbce849cb544e4a77313c8e6ece579fbd7420a", + "wy" : "2e89fe5cc1927d554e6a3bb14033ea7c922cd75cba2c7415fdab52f20b1860f1" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200044280509aab64edfc0b4a2967e4cbce849cb544e4a77313c8e6ece579fbd7420a2e89fe5cc1927d554e6a3bb14033ea7c922cd75cba2c7415fdab52f20b1860f1", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEQoBQmqtk7fwLSiln5MvOhJy1ROSncxPI\n5uzlefvXQgouif5cwZJ9VU5qO7FAM+p8kizXXLosdBX9q1LyCxhg8Q==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 374, + "comment" : "edge case modular inverse", + "flags" : [ + "ModularInverse", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c10220091a08870ff4daf9123b30c20e8c4fc8505758dcf4074fcaff2170c9bfcf74f4", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "044f8df145194e3c4fc3eea26d43ce75b402d6b17472ddcbb254b8a79b0bf3d9cb2aa20d82844cb266344e71ca78f2ad27a75a09e5bc0fa57e4efd9d465a0888db", + "wx" : "4f8df145194e3c4fc3eea26d43ce75b402d6b17472ddcbb254b8a79b0bf3d9cb", + "wy" : "2aa20d82844cb266344e71ca78f2ad27a75a09e5bc0fa57e4efd9d465a0888db" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200044f8df145194e3c4fc3eea26d43ce75b402d6b17472ddcbb254b8a79b0bf3d9cb2aa20d82844cb266344e71ca78f2ad27a75a09e5bc0fa57e4efd9d465a0888db", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAET43xRRlOPE/D7qJtQ851tALWsXRy3cuy\nVLinmwvz2csqog2ChEyyZjROccp48q0np1oJ5bwPpX5O/Z1GWgiI2w==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 375, + "comment" : "edge case modular inverse", + "flags" : [ + "ModularInverse", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c102207c370dc0ce8c59a8b273cba44a7c1191fc3186dc03cab96b0567312df0d0b250", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "049598a57dd67ec3e16b587a338aa3a10a3a3913b41a3af32e3ed3ff01358c6b14122819edf8074bbc521f7d4cdce82fef7a516706affba1d93d9dea9ccae1a207", + "wx" : "009598a57dd67ec3e16b587a338aa3a10a3a3913b41a3af32e3ed3ff01358c6b14", + "wy" : "122819edf8074bbc521f7d4cdce82fef7a516706affba1d93d9dea9ccae1a207" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200049598a57dd67ec3e16b587a338aa3a10a3a3913b41a3af32e3ed3ff01358c6b14122819edf8074bbc521f7d4cdce82fef7a516706affba1d93d9dea9ccae1a207", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAElZilfdZ+w+FrWHoziqOhCjo5E7QaOvMu\nPtP/ATWMaxQSKBnt+AdLvFIffUzc6C/velFnBq/7odk9neqcyuGiBw==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 376, + "comment" : "edge case modular inverse", + "flags" : [ + "ModularInverse", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c1022070b59a7d1ee77a2f9e0491c2a7cfcd0ed04df4a35192f6132dcc668c79a6160e", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "049171fec3ca20806bc084f12f0760911b60990bd80e5b2a71ca03a048b20f837e634fd17863761b2958d2be4e149f8d3d7abbdc18be03f451ab6c17fa0a1f8330", + "wx" : "009171fec3ca20806bc084f12f0760911b60990bd80e5b2a71ca03a048b20f837e", + "wy" : "634fd17863761b2958d2be4e149f8d3d7abbdc18be03f451ab6c17fa0a1f8330" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200049171fec3ca20806bc084f12f0760911b60990bd80e5b2a71ca03a048b20f837e634fd17863761b2958d2be4e149f8d3d7abbdc18be03f451ab6c17fa0a1f8330", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEkXH+w8oggGvAhPEvB2CRG2CZC9gOWypx\nygOgSLIPg35jT9F4Y3YbKVjSvk4Un409ervcGL4D9FGrbBf6Ch+DMA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 377, + "comment" : "edge case modular inverse", + "flags" : [ + "ModularInverse", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c102202736d76e412246e097148e2bf62915614eb7c428913a58eb5e9cd4674a9423de", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04777c8930b6e1d271100fe68ce93f163fa37612c5fff67f4a62fc3bafaf3d17a9ed73d86f60a51b5ed91353a3b054edc0aa92c9ebcbd0b75d188fdc882791d68d", + "wx" : "777c8930b6e1d271100fe68ce93f163fa37612c5fff67f4a62fc3bafaf3d17a9", + "wy" : "00ed73d86f60a51b5ed91353a3b054edc0aa92c9ebcbd0b75d188fdc882791d68d" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004777c8930b6e1d271100fe68ce93f163fa37612c5fff67f4a62fc3bafaf3d17a9ed73d86f60a51b5ed91353a3b054edc0aa92c9ebcbd0b75d188fdc882791d68d", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEd3yJMLbh0nEQD+aM6T8WP6N2EsX/9n9K\nYvw7r689F6ntc9hvYKUbXtkTU6OwVO3AqpLJ68vQt10Yj9yIJ5HWjQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 378, + "comment" : "edge case modular inverse", + "flags" : [ + "ModularInverse", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c102204a1e12831fbe93627b02d6e7f24bccdd6ef4b2d0f46739eaf3b1eaf0ca117770", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04eabc248f626e0a63e1eb81c43d461a39a1dba881eb6ee2152b07c32d71bcf4700603caa8b9d33db13af44c6efbec8a198ed6124ac9eb17eaafd2824a545ec000", + "wx" : "00eabc248f626e0a63e1eb81c43d461a39a1dba881eb6ee2152b07c32d71bcf470", + "wy" : "0603caa8b9d33db13af44c6efbec8a198ed6124ac9eb17eaafd2824a545ec000" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004eabc248f626e0a63e1eb81c43d461a39a1dba881eb6ee2152b07c32d71bcf4700603caa8b9d33db13af44c6efbec8a198ed6124ac9eb17eaafd2824a545ec000", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE6rwkj2JuCmPh64HEPUYaOaHbqIHrbuIV\nKwfDLXG89HAGA8qoudM9sTr0TG777IoZjtYSSsnrF+qv0oJKVF7AAA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 379, + "comment" : "edge case modular inverse", + "flags" : [ + "ModularInverse", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c1022006c778d4dfff7dee06ed88bc4e0ed34fc553aad67caf796f2a1c6487c1b2e877", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "049f7a13ada158a55f9ddf1a45f044f073d9b80030efdcfc9f9f58418fbceaf001f8ada0175090f80d47227d6713b6740f9a0091d88a837d0a1cd77b58a8f28d73", + "wx" : "009f7a13ada158a55f9ddf1a45f044f073d9b80030efdcfc9f9f58418fbceaf001", + "wy" : "00f8ada0175090f80d47227d6713b6740f9a0091d88a837d0a1cd77b58a8f28d73" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200049f7a13ada158a55f9ddf1a45f044f073d9b80030efdcfc9f9f58418fbceaf001f8ada0175090f80d47227d6713b6740f9a0091d88a837d0a1cd77b58a8f28d73", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEn3oTraFYpV+d3xpF8ETwc9m4ADDv3Pyf\nn1hBj7zq8AH4raAXUJD4DUcifWcTtnQPmgCR2IqDfQoc13tYqPKNcw==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 380, + "comment" : "edge case modular inverse", + "flags" : [ + "ModularInverse", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c102204de459ef9159afa057feb3ec40fef01c45b809f4ab296ea48c206d4249a2b451", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0411c4f3e461cd019b5c06ea0cea4c4090c3cc3e3c5d9f3c6d65b436826da9b4dbbbeb7a77e4cbfda207097c43423705f72c80476da3dac40a483b0ab0f2ead1cb", + "wx" : "11c4f3e461cd019b5c06ea0cea4c4090c3cc3e3c5d9f3c6d65b436826da9b4db", + "wy" : "00bbeb7a77e4cbfda207097c43423705f72c80476da3dac40a483b0ab0f2ead1cb" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000411c4f3e461cd019b5c06ea0cea4c4090c3cc3e3c5d9f3c6d65b436826da9b4dbbbeb7a77e4cbfda207097c43423705f72c80476da3dac40a483b0ab0f2ead1cb", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEEcTz5GHNAZtcBuoM6kxAkMPMPjxdnzxt\nZbQ2gm2ptNu763p35Mv9ogcJfENCNwX3LIBHbaPaxApIOwqw8urRyw==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 381, + "comment" : "edge case modular inverse", + "flags" : [ + "ModularInverse", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c10220745d294978007302033502e1acc48b63ae6500be43adbea1b258d6b423dbb416", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04e2e18682d53123aa01a6c5d00b0c623d671b462ea80bddd65227fd5105988aa4161907b3fd25044a949ea41c8e2ea8459dc6f1654856b8b61b31543bb1b45bdb", + "wx" : "00e2e18682d53123aa01a6c5d00b0c623d671b462ea80bddd65227fd5105988aa4", + "wy" : "161907b3fd25044a949ea41c8e2ea8459dc6f1654856b8b61b31543bb1b45bdb" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004e2e18682d53123aa01a6c5d00b0c623d671b462ea80bddd65227fd5105988aa4161907b3fd25044a949ea41c8e2ea8459dc6f1654856b8b61b31543bb1b45bdb", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE4uGGgtUxI6oBpsXQCwxiPWcbRi6oC93W\nUif9UQWYiqQWGQez/SUESpSepByOLqhFncbxZUhWuLYbMVQ7sbRb2w==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 382, + "comment" : "edge case modular inverse", + "flags" : [ + "ModularInverse", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c102207b2a785e3896f59b2d69da57648e80ad3c133a750a2847fd2098ccd902042b6c", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0490f8d4ca73de08a6564aaf005247b6f0ffe978504dce52605f46b7c3e56197dafadbe528eb70d9ee7ea0e70702db54f721514c7b8604ac2cb214f1decb7e383d", + "wx" : "0090f8d4ca73de08a6564aaf005247b6f0ffe978504dce52605f46b7c3e56197da", + "wy" : "00fadbe528eb70d9ee7ea0e70702db54f721514c7b8604ac2cb214f1decb7e383d" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000490f8d4ca73de08a6564aaf005247b6f0ffe978504dce52605f46b7c3e56197dafadbe528eb70d9ee7ea0e70702db54f721514c7b8604ac2cb214f1decb7e383d", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEkPjUynPeCKZWSq8AUke28P/peFBNzlJg\nX0a3w+Vhl9r62+Uo63DZ7n6g5wcC21T3IVFMe4YErCyyFPHey344PQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 383, + "comment" : "edge case modular inverse", + "flags" : [ + "ModularInverse", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c1022071ae94a72ca896875e7aa4a4c3d29afdb4b35b6996273e63c47ac519256c5eb1", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04824c195c73cffdf038d101bce1687b5c3b6146f395c885976f7753b2376b948e3cdefa6fc347d13e4dcbc63a0b03a165180cd2be1431a0cf74ce1ea25082d2bc", + "wx" : "00824c195c73cffdf038d101bce1687b5c3b6146f395c885976f7753b2376b948e", + "wy" : "3cdefa6fc347d13e4dcbc63a0b03a165180cd2be1431a0cf74ce1ea25082d2bc" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004824c195c73cffdf038d101bce1687b5c3b6146f395c885976f7753b2376b948e3cdefa6fc347d13e4dcbc63a0b03a165180cd2be1431a0cf74ce1ea25082d2bc", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEgkwZXHPP/fA40QG84Wh7XDthRvOVyIWX\nb3dTsjdrlI483vpvw0fRPk3LxjoLA6FlGAzSvhQxoM90zh6iUILSvA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 384, + "comment" : "edge case modular inverse", + "flags" : [ + "ModularInverse", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c102200fa527fa7343c0bc9ec35a6278bfbff4d83301b154fc4bd14aee7eb93445b5f9", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "042788a52f078eb3f202c4fa73e0d3386faf3df6be856003636f599922d4f5268f30b4f207c919bbdf5e67a8be4265a8174754b3aba8f16e575b77ff4d5a7eb64f", + "wx" : "2788a52f078eb3f202c4fa73e0d3386faf3df6be856003636f599922d4f5268f", + "wy" : "30b4f207c919bbdf5e67a8be4265a8174754b3aba8f16e575b77ff4d5a7eb64f" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200042788a52f078eb3f202c4fa73e0d3386faf3df6be856003636f599922d4f5268f30b4f207c919bbdf5e67a8be4265a8174754b3aba8f16e575b77ff4d5a7eb64f", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEJ4ilLweOs/ICxPpz4NM4b6899r6FYANj\nb1mZItT1Jo8wtPIHyRm7315nqL5CZagXR1Szq6jxbldbd/9NWn62Tw==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 385, + "comment" : "edge case modular inverse", + "flags" : [ + "ModularInverse", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c102206539c0adadd0525ff42622164ce9314348bd0863b4c80e936b23ca0414264671", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04d533b789a4af890fa7a82a1fae58c404f9a62a50b49adafab349c513b415087401b4171b803e76b34a9861e10f7bc289a066fd01bd29f84c987a10a5fb18c2d4", + "wx" : "00d533b789a4af890fa7a82a1fae58c404f9a62a50b49adafab349c513b4150874", + "wy" : "01b4171b803e76b34a9861e10f7bc289a066fd01bd29f84c987a10a5fb18c2d4" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004d533b789a4af890fa7a82a1fae58c404f9a62a50b49adafab349c513b415087401b4171b803e76b34a9861e10f7bc289a066fd01bd29f84c987a10a5fb18c2d4", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE1TO3iaSviQ+nqCofrljEBPmmKlC0mtr6\ns0nFE7QVCHQBtBcbgD52s0qYYeEPe8KJoGb9Ab0p+EyYehCl+xjC1A==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 386, + "comment" : "point at infinity during verify", + "flags" : [ + "PointDuplication", + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c0", + "result" : "invalid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "043a3150798c8af69d1e6e981f3a45402ba1d732f4be8330c5164f49e10ec555b4221bd842bc5e4d97eff37165f60e3998a424d72a450cf95ea477c78287d0343a", + "wx" : "3a3150798c8af69d1e6e981f3a45402ba1d732f4be8330c5164f49e10ec555b4", + "wy" : "221bd842bc5e4d97eff37165f60e3998a424d72a450cf95ea477c78287d0343a" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200043a3150798c8af69d1e6e981f3a45402ba1d732f4be8330c5164f49e10ec555b4221bd842bc5e4d97eff37165f60e3998a424d72a450cf95ea477c78287d0343a", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEOjFQeYyK9p0ebpgfOkVAK6HXMvS+gzDF\nFk9J4Q7FVbQiG9hCvF5Nl+/zcWX2DjmYpCTXKkUM+V6kd8eCh9A0Og==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 387, + "comment" : "edge case for signature malleability", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a002207fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "043b37df5fb347c69a0f17d85c0c7ca83736883a825e13143d0fcfc8101e851e800de3c090b6ca21ba543517330c04b12f948c6badf14a63abffdf4ef8c7537026", + "wx" : "3b37df5fb347c69a0f17d85c0c7ca83736883a825e13143d0fcfc8101e851e80", + "wy" : "0de3c090b6ca21ba543517330c04b12f948c6badf14a63abffdf4ef8c7537026" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200043b37df5fb347c69a0f17d85c0c7ca83736883a825e13143d0fcfc8101e851e800de3c090b6ca21ba543517330c04b12f948c6badf14a63abffdf4ef8c7537026", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEOzffX7NHxpoPF9hcDHyoNzaIOoJeExQ9\nD8/IEB6FHoAN48CQtsohulQ1FzMMBLEvlIxrrfFKY6v/3074x1NwJg==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 388, + "comment" : "edge case for signature malleability", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a002207fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a1", + "result" : "invalid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04feb5163b0ece30ff3e03c7d55c4380fa2fa81ee2c0354942ff6f08c99d0cd82ce87de05ee1bda089d3e4e248fa0f721102acfffdf50e654be281433999df897e", + "wx" : "00feb5163b0ece30ff3e03c7d55c4380fa2fa81ee2c0354942ff6f08c99d0cd82c", + "wy" : "00e87de05ee1bda089d3e4e248fa0f721102acfffdf50e654be281433999df897e" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004feb5163b0ece30ff3e03c7d55c4380fa2fa81ee2c0354942ff6f08c99d0cd82ce87de05ee1bda089d3e4e248fa0f721102acfffdf50e654be281433999df897e", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE/rUWOw7OMP8+A8fVXEOA+i+oHuLANUlC\n/28IyZ0M2CzofeBe4b2gidPk4kj6D3IRAqz//fUOZUvigUM5md+Jfg==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 389, + "comment" : "u1 == 1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215b8022044a5ad0bd0636d9e12bc9e0a6bdd5e1bba77f523842193b3b82e448e05d5f11e", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04238ced001cf22b8853e02edc89cbeca5050ba7e042a7a77f9382cd414922897640683d3094643840f295890aa4c18aa39b41d77dd0fb3bb2700e4f9ec284ffc2", + "wx" : "238ced001cf22b8853e02edc89cbeca5050ba7e042a7a77f9382cd4149228976", + "wy" : "40683d3094643840f295890aa4c18aa39b41d77dd0fb3bb2700e4f9ec284ffc2" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004238ced001cf22b8853e02edc89cbeca5050ba7e042a7a77f9382cd414922897640683d3094643840f295890aa4c18aa39b41d77dd0fb3bb2700e4f9ec284ffc2", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEI4ztABzyK4hT4C7cicvspQULp+BCp6d/\nk4LNQUkiiXZAaD0wlGQ4QPKViQqkwYqjm0HXfdD7O7JwDk+ewoT/wg==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 390, + "comment" : "u1 == n - 1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215b8022044a5ad0bd0636d9e12bc9e0a6bdd5e1bba77f523842193b3b82e448e05d5f11e", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04961cf64817c06c0e51b3c2736c922fde18bd8c4906fcd7f5ef66c4678508f35ed2c5d18168cfbe70f2f123bd7419232bb92dd69113e2941061889481c5a027bf", + "wx" : "00961cf64817c06c0e51b3c2736c922fde18bd8c4906fcd7f5ef66c4678508f35e", + "wy" : "00d2c5d18168cfbe70f2f123bd7419232bb92dd69113e2941061889481c5a027bf" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004961cf64817c06c0e51b3c2736c922fde18bd8c4906fcd7f5ef66c4678508f35ed2c5d18168cfbe70f2f123bd7419232bb92dd69113e2941061889481c5a027bf", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAElhz2SBfAbA5Rs8JzbJIv3hi9jEkG/Nf1\n72bEZ4UI817SxdGBaM++cPLxI710GSMruS3WkRPilBBhiJSBxaAnvw==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 391, + "comment" : "u2 == 1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215b8022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215b8", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0413681eae168cd4ea7cf2e2a45d052742d10a9f64e796867dbdcb829fe0b1028816528760d177376c09df79de39557c329cc1753517acffe8fa2ec298026b8384", + "wx" : "13681eae168cd4ea7cf2e2a45d052742d10a9f64e796867dbdcb829fe0b10288", + "wy" : "16528760d177376c09df79de39557c329cc1753517acffe8fa2ec298026b8384" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000413681eae168cd4ea7cf2e2a45d052742d10a9f64e796867dbdcb829fe0b1028816528760d177376c09df79de39557c329cc1753517acffe8fa2ec298026b8384", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEE2gerhaM1Op88uKkXQUnQtEKn2TnloZ9\nvcuCn+CxAogWUodg0Xc3bAnfed45VXwynMF1NRes/+j6LsKYAmuDhA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 392, + "comment" : "u2 == n - 1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215b8022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215b8", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "045aa7abfdb6b4086d543325e5d79c6e95ce42f866d2bb84909633a04bb1aa31c291c80088794905e1da33336d874e2f91ccf45cc59185bede5dd6f3f7acaae18b", + "wx" : "5aa7abfdb6b4086d543325e5d79c6e95ce42f866d2bb84909633a04bb1aa31c2", + "wy" : "0091c80088794905e1da33336d874e2f91ccf45cc59185bede5dd6f3f7acaae18b" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200045aa7abfdb6b4086d543325e5d79c6e95ce42f866d2bb84909633a04bb1aa31c291c80088794905e1da33336d874e2f91ccf45cc59185bede5dd6f3f7acaae18b", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEWqer/ba0CG1UMyXl15xulc5C+GbSu4SQ\nljOgS7GqMcKRyACIeUkF4dozM22HTi+RzPRcxZGFvt5d1vP3rKrhiw==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 393, + "comment" : "edge case for u1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc022016e1e459457679df5b9434ae23f474b3e8d2a70bd6b5dbe692ba16da01f1fb0a", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0400277791b305a45b2b39590b2f05d3392a6c8182cef4eb540120e0f5c206c3e464108233fb0b8c3ac892d79ef8e0fbf92ed133addb4554270132584dc52eef41", + "wx" : "277791b305a45b2b39590b2f05d3392a6c8182cef4eb540120e0f5c206c3e4", + "wy" : "64108233fb0b8c3ac892d79ef8e0fbf92ed133addb4554270132584dc52eef41" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000400277791b305a45b2b39590b2f05d3392a6c8182cef4eb540120e0f5c206c3e464108233fb0b8c3ac892d79ef8e0fbf92ed133addb4554270132584dc52eef41", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEACd3kbMFpFsrOVkLLwXTOSpsgYLO9OtU\nASDg9cIGw+RkEIIz+wuMOsiS15744Pv5LtEzrdtFVCcBMlhNxS7vQQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 394, + "comment" : "edge case for u1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc02201c940f313f92647be257eccd7ed08b0baef3f0478f25871b53635302c5f6314a", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "046efa092b68de9460f0bcc919005a5f6e80e19de98968be3cd2c770a9949bfb1ac75e6e5087d6550d5f9beb1e79e5029307bc255235e2d5dc99241ac3ab886c49", + "wx" : "6efa092b68de9460f0bcc919005a5f6e80e19de98968be3cd2c770a9949bfb1a", + "wy" : "00c75e6e5087d6550d5f9beb1e79e5029307bc255235e2d5dc99241ac3ab886c49" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200046efa092b68de9460f0bcc919005a5f6e80e19de98968be3cd2c770a9949bfb1ac75e6e5087d6550d5f9beb1e79e5029307bc255235e2d5dc99241ac3ab886c49", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEbvoJK2jelGDwvMkZAFpfboDhnemJaL48\n0sdwqZSb+xrHXm5Qh9ZVDV+b6x555QKTB7wlUjXi1dyZJBrDq4hsSQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 395, + "comment" : "edge case for u1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc022015d94a85077b493f91cb7101ec63e1b01be58b594e855f45050a8c14062d689b", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0472d4a19c4f9d2cf5848ea40445b70d4696b5f02d632c0c654cc7d7eeb0c6d058e8c4cd9943e459174c7ac01fa742198e47e6c19a6bdb0c4f6c237831c1b3f942", + "wx" : "72d4a19c4f9d2cf5848ea40445b70d4696b5f02d632c0c654cc7d7eeb0c6d058", + "wy" : "00e8c4cd9943e459174c7ac01fa742198e47e6c19a6bdb0c4f6c237831c1b3f942" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000472d4a19c4f9d2cf5848ea40445b70d4696b5f02d632c0c654cc7d7eeb0c6d058e8c4cd9943e459174c7ac01fa742198e47e6c19a6bdb0c4f6c237831c1b3f942", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEctShnE+dLPWEjqQERbcNRpa18C1jLAxl\nTMfX7rDG0FjoxM2ZQ+RZF0x6wB+nQhmOR+bBmmvbDE9sI3gxwbP5Qg==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 396, + "comment" : "edge case for u1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc02205b1d27a7694c146244a5ad0bd0636d9d9ef3b9fb58385418d9c982105077d1b7", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "042a8ea2f50dcced0c217575bdfa7cd47d1c6f100041ec0e35512794c1be7e740258f8c17122ed303fda7143eb58bede70295b653266013b0b0ebd3f053137f6ec", + "wx" : "2a8ea2f50dcced0c217575bdfa7cd47d1c6f100041ec0e35512794c1be7e7402", + "wy" : "58f8c17122ed303fda7143eb58bede70295b653266013b0b0ebd3f053137f6ec" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200042a8ea2f50dcced0c217575bdfa7cd47d1c6f100041ec0e35512794c1be7e740258f8c17122ed303fda7143eb58bede70295b653266013b0b0ebd3f053137f6ec", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEKo6i9Q3M7QwhdXW9+nzUfRxvEABB7A41\nUSeUwb5+dAJY+MFxIu0wP9pxQ+tYvt5wKVtlMmYBOwsOvT8FMTf27A==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 397, + "comment" : "edge case for u1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc02202d85896b3eb9dbb5a52f42f9c9261ed3fc46644ec65f06ade3fd78f257e43432", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0488de689ce9af1e94be6a2089c8a8b1253ffdbb6c8e9c86249ba220001a4ad3b80c4998e54842f413b9edb1825acbb6335e81e4d184b2b01c8bebdc85d1f28946", + "wx" : "0088de689ce9af1e94be6a2089c8a8b1253ffdbb6c8e9c86249ba220001a4ad3b8", + "wy" : "0c4998e54842f413b9edb1825acbb6335e81e4d184b2b01c8bebdc85d1f28946" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000488de689ce9af1e94be6a2089c8a8b1253ffdbb6c8e9c86249ba220001a4ad3b80c4998e54842f413b9edb1825acbb6335e81e4d184b2b01c8bebdc85d1f28946", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEiN5onOmvHpS+aiCJyKixJT/9u2yOnIYk\nm6IgABpK07gMSZjlSEL0E7ntsYJay7YzXoHk0YSysByL69yF0fKJRg==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 398, + "comment" : "edge case for u1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc02205b0b12d67d73b76b4a5e85f3924c3da7f88cc89d8cbe0d5bc7faf1e4afc86864", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04fea2d31f70f90d5fb3e00e186ac42ab3c1615cee714e0b4e1131b3d4d8225bf7b037a18df2ac15343f30f74067ddf29e817d5f77f8dce05714da59c094f0cda9", + "wx" : "00fea2d31f70f90d5fb3e00e186ac42ab3c1615cee714e0b4e1131b3d4d8225bf7", + "wy" : "00b037a18df2ac15343f30f74067ddf29e817d5f77f8dce05714da59c094f0cda9" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004fea2d31f70f90d5fb3e00e186ac42ab3c1615cee714e0b4e1131b3d4d8225bf7b037a18df2ac15343f30f74067ddf29e817d5f77f8dce05714da59c094f0cda9", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE/qLTH3D5DV+z4A4YasQqs8FhXO5xTgtO\nETGz1NgiW/ewN6GN8qwVND8w90Bn3fKegX1fd/jc4FcU2lnAlPDNqQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 399, + "comment" : "edge case for u1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc0220694c146244a5ad0bd0636d9e12bc9e09e60e68b90d0b5e6c5dddd0cb694d8799", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "047258911e3d423349166479dbe0b8341af7fbd03d0a7e10edccb36b6ceea5a3db17ac2b8992791128fa3b96dc2fbd4ca3bfa782ef2832fc6656943db18e7346b0", + "wx" : "7258911e3d423349166479dbe0b8341af7fbd03d0a7e10edccb36b6ceea5a3db", + "wy" : "17ac2b8992791128fa3b96dc2fbd4ca3bfa782ef2832fc6656943db18e7346b0" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200047258911e3d423349166479dbe0b8341af7fbd03d0a7e10edccb36b6ceea5a3db17ac2b8992791128fa3b96dc2fbd4ca3bfa782ef2832fc6656943db18e7346b0", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEcliRHj1CM0kWZHnb4Lg0Gvf70D0KfhDt\nzLNrbO6lo9sXrCuJknkRKPo7ltwvvUyjv6eC7ygy/GZWlD2xjnNGsA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 400, + "comment" : "edge case for u1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc02203d7f487c07bfc5f30846938a3dcef696444707cf9677254a92b06c63ab867d22", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "044f28461dea64474d6bb34d1499c97d37b9e95633df1ceeeaacd45016c98b3914c8818810b8cc06ddb40e8a1261c528faa589455d5a6df93b77bc5e0e493c7470", + "wx" : "4f28461dea64474d6bb34d1499c97d37b9e95633df1ceeeaacd45016c98b3914", + "wy" : "00c8818810b8cc06ddb40e8a1261c528faa589455d5a6df93b77bc5e0e493c7470" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200044f28461dea64474d6bb34d1499c97d37b9e95633df1ceeeaacd45016c98b3914c8818810b8cc06ddb40e8a1261c528faa589455d5a6df93b77bc5e0e493c7470", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAETyhGHepkR01rs00Umcl9N7npVjPfHO7q\nrNRQFsmLORTIgYgQuMwG3bQOihJhxSj6pYlFXVpt+Tt3vF4OSTx0cA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 401, + "comment" : "edge case for u1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc02206c7648fc0fbf8a06adb8b839f97b4ff7a800f11b1e37c593b261394599792ba4", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0474f2a814fb5d8eca91a69b5e60712732b3937de32829be974ed7b68c5c2f5d66eff0f07c56f987a657f42196205f588c0f1d96fd8a63a5f238b48f478788fe3b", + "wx" : "74f2a814fb5d8eca91a69b5e60712732b3937de32829be974ed7b68c5c2f5d66", + "wy" : "00eff0f07c56f987a657f42196205f588c0f1d96fd8a63a5f238b48f478788fe3b" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000474f2a814fb5d8eca91a69b5e60712732b3937de32829be974ed7b68c5c2f5d66eff0f07c56f987a657f42196205f588c0f1d96fd8a63a5f238b48f478788fe3b", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEdPKoFPtdjsqRppteYHEnMrOTfeMoKb6X\nTte2jFwvXWbv8PB8VvmHplf0IZYgX1iMDx2W/YpjpfI4tI9Hh4j+Ow==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 402, + "comment" : "edge case for u1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc0220641c9c5d790dc09cdd3dfabb62cdf453e69747a7e3d7aa1a714189ef53171a99", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04195b51a7cc4a21b8274a70a90de779814c3c8ca358328208c09a29f336b82d6ab2416b7c92fffdc29c3b1282dd2a77a4d04df7f7452047393d849989c5cee9ad", + "wx" : "195b51a7cc4a21b8274a70a90de779814c3c8ca358328208c09a29f336b82d6a", + "wy" : "00b2416b7c92fffdc29c3b1282dd2a77a4d04df7f7452047393d849989c5cee9ad" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004195b51a7cc4a21b8274a70a90de779814c3c8ca358328208c09a29f336b82d6ab2416b7c92fffdc29c3b1282dd2a77a4d04df7f7452047393d849989c5cee9ad", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEGVtRp8xKIbgnSnCpDed5gUw8jKNYMoII\nwJop8za4LWqyQWt8kv/9wpw7EoLdKnek0E3390UgRzk9hJmJxc7prQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 403, + "comment" : "edge case for u1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc022029798c5c45bdf58b4a7b2fdc2c46ab4af1218c7eeb9f0f27a88f1267674de3b0", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04622fc74732034bec2ddf3bc16d34b3d1f7a327dd2a8c19bab4bb4fe3a24b58aa736b2f2fae76f4dfaecc9096333b01328d51eb3fda9c9227e90d0b449983c4f0", + "wx" : "622fc74732034bec2ddf3bc16d34b3d1f7a327dd2a8c19bab4bb4fe3a24b58aa", + "wy" : "736b2f2fae76f4dfaecc9096333b01328d51eb3fda9c9227e90d0b449983c4f0" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004622fc74732034bec2ddf3bc16d34b3d1f7a327dd2a8c19bab4bb4fe3a24b58aa736b2f2fae76f4dfaecc9096333b01328d51eb3fda9c9227e90d0b449983c4f0", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEYi/HRzIDS+wt3zvBbTSz0fejJ90qjBm6\ntLtP46JLWKpzay8vrnb0367MkJYzOwEyjVHrP9qckifpDQtEmYPE8A==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 404, + "comment" : "edge case for u1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc02200b70f22ca2bb3cefadca1a5711fa3a59f4695385eb5aedf3495d0b6d00f8fd85", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "041f7f85caf2d7550e7af9b65023ebb4dce3450311692309db269969b834b611c70827f45b78020ecbbaf484fdd5bfaae6870f1184c21581baf6ef82bd7b530f93", + "wx" : "1f7f85caf2d7550e7af9b65023ebb4dce3450311692309db269969b834b611c7", + "wy" : "0827f45b78020ecbbaf484fdd5bfaae6870f1184c21581baf6ef82bd7b530f93" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200041f7f85caf2d7550e7af9b65023ebb4dce3450311692309db269969b834b611c70827f45b78020ecbbaf484fdd5bfaae6870f1184c21581baf6ef82bd7b530f93", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEH3+FyvLXVQ56+bZQI+u03ONFAxFpIwnb\nJplpuDS2EccIJ/RbeAIOy7r0hP3Vv6rmhw8RhMIVgbr274K9e1MPkw==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 405, + "comment" : "edge case for u1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc022016e1e459457679df5b9434ae23f474b3e8d2a70bd6b5dbe692ba16da01f1fb0a", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0449c197dc80ad1da47a4342b93893e8e1fb0bb94fc33a83e783c00b24c781377aefc20da92bac762951f72474becc734d4cc22ba81b895e282fdac4df7af0f37d", + "wx" : "49c197dc80ad1da47a4342b93893e8e1fb0bb94fc33a83e783c00b24c781377a", + "wy" : "00efc20da92bac762951f72474becc734d4cc22ba81b895e282fdac4df7af0f37d" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000449c197dc80ad1da47a4342b93893e8e1fb0bb94fc33a83e783c00b24c781377aefc20da92bac762951f72474becc734d4cc22ba81b895e282fdac4df7af0f37d", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEScGX3ICtHaR6Q0K5OJPo4fsLuU/DOoPn\ng8ALJMeBN3rvwg2pK6x2KVH3JHS+zHNNTMIrqBuJXigv2sTfevDzfQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 406, + "comment" : "edge case for u1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc02202252d685e831b6cf095e4f0535eeaf0ddd3bfa91c210c9d9dc17224702eaf88f", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04d8cb68517b616a56400aa3868635e54b6f699598a2f6167757654980baf6acbe7ec8cf449c849aa03461a30efada41453c57c6e6fbc93bbc6fa49ada6dc0555c", + "wx" : "00d8cb68517b616a56400aa3868635e54b6f699598a2f6167757654980baf6acbe", + "wy" : "7ec8cf449c849aa03461a30efada41453c57c6e6fbc93bbc6fa49ada6dc0555c" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004d8cb68517b616a56400aa3868635e54b6f699598a2f6167757654980baf6acbe7ec8cf449c849aa03461a30efada41453c57c6e6fbc93bbc6fa49ada6dc0555c", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE2MtoUXthalZACqOGhjXlS29plZii9hZ3\nV2VJgLr2rL5+yM9EnISaoDRhow762kFFPFfG5vvJO7xvpJrabcBVXA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 407, + "comment" : "edge case for u1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc022075135abd7c425b60371a477f09ce0f274f64a8c6b061a07b5d63e93c65046c53", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04030713fb63f2aa6fe2cadf1b20efc259c77445dafa87dac398b84065ca347df3b227818de1a39b589cb071d83e5317cccdc2338e51e312fe31d8dc34a4801750", + "wx" : "030713fb63f2aa6fe2cadf1b20efc259c77445dafa87dac398b84065ca347df3", + "wy" : "00b227818de1a39b589cb071d83e5317cccdc2338e51e312fe31d8dc34a4801750" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004030713fb63f2aa6fe2cadf1b20efc259c77445dafa87dac398b84065ca347df3b227818de1a39b589cb071d83e5317cccdc2338e51e312fe31d8dc34a4801750", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEAwcT+2Pyqm/iyt8bIO/CWcd0Rdr6h9rD\nmLhAZco0ffOyJ4GN4aObWJywcdg+UxfMzcIzjlHjEv4x2Nw0pIAXUA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 408, + "comment" : "edge case for u2", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc02202aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa3e3a49a23a6d8abe95461f8445676b17", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04babb3677b0955802d8e929a41355640eaf1ea1353f8a771331c4946e3480afa7252f196c87ed3d2a59d3b1b559137fed0013fecefc19fb5a92682b9bca51b950", + "wx" : "00babb3677b0955802d8e929a41355640eaf1ea1353f8a771331c4946e3480afa7", + "wy" : "252f196c87ed3d2a59d3b1b559137fed0013fecefc19fb5a92682b9bca51b950" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004babb3677b0955802d8e929a41355640eaf1ea1353f8a771331c4946e3480afa7252f196c87ed3d2a59d3b1b559137fed0013fecefc19fb5a92682b9bca51b950", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEurs2d7CVWALY6SmkE1VkDq8eoTU/incT\nMcSUbjSAr6clLxlsh+09KlnTsbVZE3/tABP+zvwZ+1qSaCubylG5UA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 409, + "comment" : "edge case for u2", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc02203e888377ac6c71ac9dec3fdb9b56c9feaf0cfaca9f827fc5eb65fc3eac811210", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "041aab2018793471111a8a0e9b143fde02fc95920796d3a63de329b424396fba60bbe4130705174792441b318d3aa31dfe8577821e9b446ec573d272e036c4ebe9", + "wx" : "1aab2018793471111a8a0e9b143fde02fc95920796d3a63de329b424396fba60", + "wy" : "00bbe4130705174792441b318d3aa31dfe8577821e9b446ec573d272e036c4ebe9" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200041aab2018793471111a8a0e9b143fde02fc95920796d3a63de329b424396fba60bbe4130705174792441b318d3aa31dfe8577821e9b446ec573d272e036c4ebe9", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEGqsgGHk0cREaig6bFD/eAvyVkgeW06Y9\n4ym0JDlvumC75BMHBRdHkkQbMY06ox3+hXeCHptEbsVz0nLgNsTr6Q==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 410, + "comment" : "edge case for u2", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc022030bbb794db588363b40679f6c182a50d3ce9679acdd3ffbe36d7813dacbdc818", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "048cb0b909499c83ea806cd885b1dd467a0119f06a88a0276eb0cfda274535a8ff47b5428833bc3f2c8bf9d9041158cf33718a69961cd01729bc0011d1e586ab75", + "wx" : "008cb0b909499c83ea806cd885b1dd467a0119f06a88a0276eb0cfda274535a8ff", + "wy" : "47b5428833bc3f2c8bf9d9041158cf33718a69961cd01729bc0011d1e586ab75" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200048cb0b909499c83ea806cd885b1dd467a0119f06a88a0276eb0cfda274535a8ff47b5428833bc3f2c8bf9d9041158cf33718a69961cd01729bc0011d1e586ab75", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEjLC5CUmcg+qAbNiFsd1GegEZ8GqIoCdu\nsM/aJ0U1qP9HtUKIM7w/LIv52QQRWM8zcYpplhzQFym8ABHR5YardQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 411, + "comment" : "edge case for u2", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc02202c37fd995622c4fb7fffffffffffffffc7cee745110cb45ab558ed7c90c15a2f", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "048f03cf1a42272bb1532723093f72e6feeac85e1700e9fbe9a6a2dd642d74bf5d3b89a7189dad8cf75fc22f6f158aa27f9c2ca00daca785be3358f2bda3862ca0", + "wx" : "008f03cf1a42272bb1532723093f72e6feeac85e1700e9fbe9a6a2dd642d74bf5d", + "wy" : "3b89a7189dad8cf75fc22f6f158aa27f9c2ca00daca785be3358f2bda3862ca0" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200048f03cf1a42272bb1532723093f72e6feeac85e1700e9fbe9a6a2dd642d74bf5d3b89a7189dad8cf75fc22f6f158aa27f9c2ca00daca785be3358f2bda3862ca0", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEjwPPGkInK7FTJyMJP3Lm/urIXhcA6fvp\npqLdZC10v107iacYna2M91/CL28ViqJ/nCygDaynhb4zWPK9o4YsoA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 412, + "comment" : "edge case for u2", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc02207fd995622c4fb7ffffffffffffffffff5d883ffab5b32652ccdcaa290fccb97d", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0444de3b9c7a57a8c9e820952753421e7d987bb3d79f71f013805c897e018f8acea2460758c8f98d3fdce121a943659e372c326fff2e5fc2ae7fa3f79daae13c12", + "wx" : "44de3b9c7a57a8c9e820952753421e7d987bb3d79f71f013805c897e018f8ace", + "wy" : "00a2460758c8f98d3fdce121a943659e372c326fff2e5fc2ae7fa3f79daae13c12" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000444de3b9c7a57a8c9e820952753421e7d987bb3d79f71f013805c897e018f8acea2460758c8f98d3fdce121a943659e372c326fff2e5fc2ae7fa3f79daae13c12", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAERN47nHpXqMnoIJUnU0IefZh7s9efcfAT\ngFyJfgGPis6iRgdYyPmNP9zhIalDZZ43LDJv/y5fwq5/o/edquE8Eg==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 413, + "comment" : "edge case for u2", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304302207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc021f4cd53ba7608fffffffffffffffffffff9e5cf143e2539626190a3ab09cce47", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "046fb8b2b48e33031268ad6a517484dc8839ea90f6669ea0c7ac3233e2ac31394a0ac8bbe7f73c2ff4df9978727ac1dfc2fd58647d20f31f99105316b64671f204", + "wx" : "6fb8b2b48e33031268ad6a517484dc8839ea90f6669ea0c7ac3233e2ac31394a", + "wy" : "0ac8bbe7f73c2ff4df9978727ac1dfc2fd58647d20f31f99105316b64671f204" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200046fb8b2b48e33031268ad6a517484dc8839ea90f6669ea0c7ac3233e2ac31394a0ac8bbe7f73c2ff4df9978727ac1dfc2fd58647d20f31f99105316b64671f204", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEb7iytI4zAxJorWpRdITciDnqkPZmnqDH\nrDIz4qwxOUoKyLvn9zwv9N+ZeHJ6wd/C/VhkfSDzH5kQUxa2RnHyBA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 414, + "comment" : "edge case for u2", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc02205622c4fb7fffffffffffffffffffffff928a8f1c7ac7bec1808b9f61c01ec327", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04bea71122a048693e905ff602b3cf9dd18af69b9fc9d8431d2b1dd26b942c95e6f43c7b8b95eb62082c12db9dbda7fe38e45cbe4a4886907fb81bdb0c5ea9246c", + "wx" : "00bea71122a048693e905ff602b3cf9dd18af69b9fc9d8431d2b1dd26b942c95e6", + "wy" : "00f43c7b8b95eb62082c12db9dbda7fe38e45cbe4a4886907fb81bdb0c5ea9246c" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004bea71122a048693e905ff602b3cf9dd18af69b9fc9d8431d2b1dd26b942c95e6f43c7b8b95eb62082c12db9dbda7fe38e45cbe4a4886907fb81bdb0c5ea9246c", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEvqcRIqBIaT6QX/YCs8+d0Yr2m5/J2EMd\nKx3Sa5Qsleb0PHuLletiCCwS2529p/445Fy+SkiGkH+4G9sMXqkkbA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 415, + "comment" : "edge case for u2", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc022044104104104104104104104104104103b87853fd3b7d3f8e175125b4382f25ed", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04da918c731ba06a20cb94ef33b778e981a404a305f1941fe33666b45b03353156e2bb2694f575b45183be78e5c9b5210bf3bf488fd4c8294516d89572ca4f5391", + "wx" : "00da918c731ba06a20cb94ef33b778e981a404a305f1941fe33666b45b03353156", + "wy" : "00e2bb2694f575b45183be78e5c9b5210bf3bf488fd4c8294516d89572ca4f5391" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004da918c731ba06a20cb94ef33b778e981a404a305f1941fe33666b45b03353156e2bb2694f575b45183be78e5c9b5210bf3bf488fd4c8294516d89572ca4f5391", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE2pGMcxugaiDLlO8zt3jpgaQEowXxlB/j\nNma0WwM1MVbiuyaU9XW0UYO+eOXJtSEL879Ij9TIKUUW2JVyyk9TkQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 416, + "comment" : "edge case for u2", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc02202739ce739ce739ce739ce739ce739ce705560298d1f2f08dc419ac273a5b54d9", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "043007e92c3937dade7964dfa35b0eff031f7eb02aed0a0314411106cdeb70fe3d5a7546fc0552997b20e3d6f413e75e2cb66e116322697114b79bac734bfc4dc5", + "wx" : "3007e92c3937dade7964dfa35b0eff031f7eb02aed0a0314411106cdeb70fe3d", + "wy" : "5a7546fc0552997b20e3d6f413e75e2cb66e116322697114b79bac734bfc4dc5" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200043007e92c3937dade7964dfa35b0eff031f7eb02aed0a0314411106cdeb70fe3d5a7546fc0552997b20e3d6f413e75e2cb66e116322697114b79bac734bfc4dc5", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEMAfpLDk32t55ZN+jWw7/Ax9+sCrtCgMU\nQREGzetw/j1adUb8BVKZeyDj1vQT514stm4RYyJpcRS3m6xzS/xNxQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 417, + "comment" : "edge case for u2", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc02204888888888888888888888888888888831c83ae82ebe0898776b4c69d11f88de", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0460e734ef5624d3cbf0ddd375011bd663d6d6aebc644eb599fdf98dbdcd18ce9bd2d90b3ac31f139af832cccf6ccbbb2c6ea11fa97370dc9906da474d7d8a7567", + "wx" : "60e734ef5624d3cbf0ddd375011bd663d6d6aebc644eb599fdf98dbdcd18ce9b", + "wy" : "00d2d90b3ac31f139af832cccf6ccbbb2c6ea11fa97370dc9906da474d7d8a7567" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000460e734ef5624d3cbf0ddd375011bd663d6d6aebc644eb599fdf98dbdcd18ce9bd2d90b3ac31f139af832cccf6ccbbb2c6ea11fa97370dc9906da474d7d8a7567", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEYOc071Yk08vw3dN1ARvWY9bWrrxkTrWZ\n/fmNvc0YzpvS2Qs6wx8TmvgyzM9sy7ssbqEfqXNw3JkG2kdNfYp1Zw==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 418, + "comment" : "edge case for u2", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc02206492492492492492492492492492492406dd3a19b8d5fb875235963c593bd2d3", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0485a900e97858f693c0b7dfa261e380dad6ea046d1f65ddeeedd5f7d8af0ba33769744d15add4f6c0bc3b0da2aec93b34cb8c65f9340ddf74e7b0009eeeccce3c", + "wx" : "0085a900e97858f693c0b7dfa261e380dad6ea046d1f65ddeeedd5f7d8af0ba337", + "wy" : "69744d15add4f6c0bc3b0da2aec93b34cb8c65f9340ddf74e7b0009eeeccce3c" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000485a900e97858f693c0b7dfa261e380dad6ea046d1f65ddeeedd5f7d8af0ba33769744d15add4f6c0bc3b0da2aec93b34cb8c65f9340ddf74e7b0009eeeccce3c", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEhakA6XhY9pPAt9+iYeOA2tbqBG0fZd3u\n7dX32K8LozdpdE0VrdT2wLw7DaKuyTs0y4xl+TQN33TnsACe7szOPA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 419, + "comment" : "edge case for u2", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc02206aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa3e3a49a23a6d8abe95461f8445676b15", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0438066f75d88efc4c93de36f49e037b234cc18b1de5608750a62cab0345401046a3e84bed8cfcb819ef4d550444f2ce4b651766b69e2e2901f88836ff90034fed", + "wx" : "38066f75d88efc4c93de36f49e037b234cc18b1de5608750a62cab0345401046", + "wy" : "00a3e84bed8cfcb819ef4d550444f2ce4b651766b69e2e2901f88836ff90034fed" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000438066f75d88efc4c93de36f49e037b234cc18b1de5608750a62cab0345401046a3e84bed8cfcb819ef4d550444f2ce4b651766b69e2e2901f88836ff90034fed", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEOAZvddiO/EyT3jb0ngN7I0zBix3lYIdQ\npiyrA0VAEEaj6EvtjPy4Ge9NVQRE8s5LZRdmtp4uKQH4iDb/kANP7Q==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 420, + "comment" : "edge case for u2", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc02202aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa3e3a49a23a6d8abe95461f8445676b17", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0498f68177dc95c1b4cbfa5245488ca523a7d5629470d035d621a443c72f39aabfa33d29546fa1c648f2c7d5ccf70cf1ce4ab79b5db1ac059dbecd068dbdff1b89", + "wx" : "0098f68177dc95c1b4cbfa5245488ca523a7d5629470d035d621a443c72f39aabf", + "wy" : "00a33d29546fa1c648f2c7d5ccf70cf1ce4ab79b5db1ac059dbecd068dbdff1b89" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000498f68177dc95c1b4cbfa5245488ca523a7d5629470d035d621a443c72f39aabfa33d29546fa1c648f2c7d5ccf70cf1ce4ab79b5db1ac059dbecd068dbdff1b89", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEmPaBd9yVwbTL+lJFSIylI6fVYpRw0DXW\nIaRDxy85qr+jPSlUb6HGSPLH1cz3DPHOSrebXbGsBZ2+zQaNvf8biQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 421, + "comment" : "edge case for u2", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc02203ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "045c2bbfa23c9b9ad07f038aa89b4930bf267d9401e4255de9e8da0a5078ec8277e3e882a31d5e6a379e0793983ccded39b95c4353ab2ff01ea5369ba47b0c3191", + "wx" : "5c2bbfa23c9b9ad07f038aa89b4930bf267d9401e4255de9e8da0a5078ec8277", + "wy" : "00e3e882a31d5e6a379e0793983ccded39b95c4353ab2ff01ea5369ba47b0c3191" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200045c2bbfa23c9b9ad07f038aa89b4930bf267d9401e4255de9e8da0a5078ec8277e3e882a31d5e6a379e0793983ccded39b95c4353ab2ff01ea5369ba47b0c3191", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEXCu/ojybmtB/A4qom0kwvyZ9lAHkJV3p\n6NoKUHjsgnfj6IKjHV5qN54Hk5g8ze05uVxDU6sv8B6lNpukewwxkQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 422, + "comment" : "edge case for u2", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "304402207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc0220185ddbca6dac41b1da033cfb60c152869e74b3cd66e9ffdf1b6bc09ed65ee40c", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "042ea7133432339c69d27f9b267281bd2ddd5f19d6338d400a05cd3647b157a3853547808298448edb5e701ade84cd5fb1ac9567ba5e8fb68a6b933ec4b5cc84cc", + "wx" : "2ea7133432339c69d27f9b267281bd2ddd5f19d6338d400a05cd3647b157a385", + "wy" : "3547808298448edb5e701ade84cd5fb1ac9567ba5e8fb68a6b933ec4b5cc84cc" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200042ea7133432339c69d27f9b267281bd2ddd5f19d6338d400a05cd3647b157a3853547808298448edb5e701ade84cd5fb1ac9567ba5e8fb68a6b933ec4b5cc84cc", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAELqcTNDIznGnSf5smcoG9Ld1fGdYzjUAK\nBc02R7FXo4U1R4CCmESO215wGt6EzV+xrJVnul6Ptoprkz7EtcyEzA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 423, + "comment" : "point duplication during verification", + "flags" : [ + "PointDuplication" + ], + "msg" : "313233343030", + "sig" : "3044022032b0d10d8d0e04bc8d4d064d270699e87cffc9b49c5c20730e1c26f6105ddcda022029ed3d67b3d505be95580d77d5b792b436881179b2b6b2e04c5fe592d38d82d9", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "042ea7133432339c69d27f9b267281bd2ddd5f19d6338d400a05cd3647b157a385cab87f7d67bb7124a18fe5217b32a04e536a9845a1704975946cc13a4a337763", + "wx" : "2ea7133432339c69d27f9b267281bd2ddd5f19d6338d400a05cd3647b157a385", + "wy" : "00cab87f7d67bb7124a18fe5217b32a04e536a9845a1704975946cc13a4a337763" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200042ea7133432339c69d27f9b267281bd2ddd5f19d6338d400a05cd3647b157a385cab87f7d67bb7124a18fe5217b32a04e536a9845a1704975946cc13a4a337763", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAELqcTNDIznGnSf5smcoG9Ld1fGdYzjUAK\nBc02R7FXo4XKuH99Z7txJKGP5SF7MqBOU2qYRaFwSXWUbME6SjN3Yw==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 424, + "comment" : "duplication bug", + "flags" : [ + "PointDuplication" + ], + "msg" : "313233343030", + "sig" : "3044022032b0d10d8d0e04bc8d4d064d270699e87cffc9b49c5c20730e1c26f6105ddcda022029ed3d67b3d505be95580d77d5b792b436881179b2b6b2e04c5fe592d38d82d9", + "result" : "invalid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "048aa2c64fa9c6437563abfbcbd00b2048d48c18c152a2a6f49036de7647ebe82e1ce64387995c68a060fa3bc0399b05cc06eec7d598f75041a4917e692b7f51ff", + "wx" : "008aa2c64fa9c6437563abfbcbd00b2048d48c18c152a2a6f49036de7647ebe82e", + "wy" : "1ce64387995c68a060fa3bc0399b05cc06eec7d598f75041a4917e692b7f51ff" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200048aa2c64fa9c6437563abfbcbd00b2048d48c18c152a2a6f49036de7647ebe82e1ce64387995c68a060fa3bc0399b05cc06eec7d598f75041a4917e692b7f51ff", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEiqLGT6nGQ3Vjq/vL0AsgSNSMGMFSoqb0\nkDbedkfr6C4c5kOHmVxooGD6O8A5mwXMBu7H1Zj3UEGkkX5pK39R/w==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 425, + "comment" : "comparison with point at infinity ", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c0022033333333333333333333333333333332f222f8faefdb533f265d461c29a47373", + "result" : "invalid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04391427ff7ee78013c14aec7d96a8a062209298a783835e94fd6549d502fff71fdd6624ec343ad9fcf4d9872181e59f842f9ba4cccae09a6c0972fb6ac6b4c6bd", + "wx" : "391427ff7ee78013c14aec7d96a8a062209298a783835e94fd6549d502fff71f", + "wy" : "00dd6624ec343ad9fcf4d9872181e59f842f9ba4cccae09a6c0972fb6ac6b4c6bd" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004391427ff7ee78013c14aec7d96a8a062209298a783835e94fd6549d502fff71fdd6624ec343ad9fcf4d9872181e59f842f9ba4cccae09a6c0972fb6ac6b4c6bd", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEORQn/37ngBPBSux9lqigYiCSmKeDg16U\n/WVJ1QL/9x/dZiTsNDrZ/PTZhyGB5Z+EL5ukzMrgmmwJcvtqxrTGvQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 426, + "comment" : "extreme value for k and edgecase s", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3045022100c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c0", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04e762b8a219b4f180219cc7a9059245e4961bd191c03899789c7a34b89e8c138ec1533ef0419bb7376e0bfde9319d10a06968791d9ea0eed9c1ce6345aed9759e", + "wx" : "00e762b8a219b4f180219cc7a9059245e4961bd191c03899789c7a34b89e8c138e", + "wy" : "00c1533ef0419bb7376e0bfde9319d10a06968791d9ea0eed9c1ce6345aed9759e" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004e762b8a219b4f180219cc7a9059245e4961bd191c03899789c7a34b89e8c138ec1533ef0419bb7376e0bfde9319d10a06968791d9ea0eed9c1ce6345aed9759e", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE52K4ohm08YAhnMepBZJF5JYb0ZHAOJl4\nnHo0uJ6ME47BUz7wQZu3N24L/ekxnRCgaWh5HZ6g7tnBzmNFrtl1ng==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 427, + "comment" : "extreme value for k and s^-1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3045022100c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5022049249249249249249249249249249248c79facd43214c011123c1b03a93412a5", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "049aedb0d281db164e130000c5697fae0f305ef848be6fffb43ac593fbb950e952fa6f633359bdcd82b56b0b9f965b037789d46b9a8141b791b2aefa713f96c175", + "wx" : "009aedb0d281db164e130000c5697fae0f305ef848be6fffb43ac593fbb950e952", + "wy" : "00fa6f633359bdcd82b56b0b9f965b037789d46b9a8141b791b2aefa713f96c175" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200049aedb0d281db164e130000c5697fae0f305ef848be6fffb43ac593fbb950e952fa6f633359bdcd82b56b0b9f965b037789d46b9a8141b791b2aefa713f96c175", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEmu2w0oHbFk4TAADFaX+uDzBe+Ei+b/+0\nOsWT+7lQ6VL6b2MzWb3NgrVrC5+WWwN3idRrmoFBt5GyrvpxP5bBdQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 428, + "comment" : "extreme value for k and s^-1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3045022100c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5022066666666666666666666666666666665e445f1f5dfb6a67e4cba8c385348e6e7", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "048ad445db62816260e4e687fd1884e48b9fc0636d031547d63315e792e19bfaee1de64f99d5f1cd8b6ec9cb0f787a654ae86993ba3db1008ef43cff0684cb22bd", + "wx" : "008ad445db62816260e4e687fd1884e48b9fc0636d031547d63315e792e19bfaee", + "wy" : "1de64f99d5f1cd8b6ec9cb0f787a654ae86993ba3db1008ef43cff0684cb22bd" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200048ad445db62816260e4e687fd1884e48b9fc0636d031547d63315e792e19bfaee1de64f99d5f1cd8b6ec9cb0f787a654ae86993ba3db1008ef43cff0684cb22bd", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEitRF22KBYmDk5of9GITki5/AY20DFUfW\nMxXnkuGb+u4d5k+Z1fHNi27Jyw94emVK6GmTuj2xAI70PP8GhMsivQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 429, + "comment" : "extreme value for k and s^-1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3045022100c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5022066666666666666666666666666666665e445f1f5dfb6a67e4cba8c385348e6e7", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "041f5799c95be89063b24f26e40cb928c1a868a76fb0094607e8043db409c91c32e75724e813a4191e3a839007f08e2e897388b06d4a00de6de60e536d91fab566", + "wx" : "1f5799c95be89063b24f26e40cb928c1a868a76fb0094607e8043db409c91c32", + "wy" : "00e75724e813a4191e3a839007f08e2e897388b06d4a00de6de60e536d91fab566" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200041f5799c95be89063b24f26e40cb928c1a868a76fb0094607e8043db409c91c32e75724e813a4191e3a839007f08e2e897388b06d4a00de6de60e536d91fab566", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEH1eZyVvokGOyTybkDLkowahop2+wCUYH\n6AQ9tAnJHDLnVyToE6QZHjqDkAfwji6Jc4iwbUoA3m3mDlNtkfq1Zg==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 430, + "comment" : "extreme value for k and s^-1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3045022100c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5022049249249249249249249249249249248c79facd43214c011123c1b03a93412a5", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04a3331a4e1b4223ec2c027edd482c928a14ed358d93f1d4217d39abf69fcb5ccc28d684d2aaabcd6383775caa6239de26d4c6937bb603ecb4196082f4cffd509d", + "wx" : "00a3331a4e1b4223ec2c027edd482c928a14ed358d93f1d4217d39abf69fcb5ccc", + "wy" : "28d684d2aaabcd6383775caa6239de26d4c6937bb603ecb4196082f4cffd509d" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004a3331a4e1b4223ec2c027edd482c928a14ed358d93f1d4217d39abf69fcb5ccc28d684d2aaabcd6383775caa6239de26d4c6937bb603ecb4196082f4cffd509d", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEozMaThtCI+wsAn7dSCySihTtNY2T8dQh\nfTmr9p/LXMwo1oTSqqvNY4N3XKpiOd4m1MaTe7YD7LQZYIL0z/1QnQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 431, + "comment" : "extreme value for k", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3045022100c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee502200eb10e5ab95f2f275348d82ad2e4d7949c8193800d8c9c75df58e343f0ebba7b", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "043f3952199774c7cf39b38b66cb1042a6260d8680803845e4d433adba3bb248185ea495b68cbc7ed4173ee63c9042dc502625c7eb7e21fb02ca9a9114e0a3a18d", + "wx" : "3f3952199774c7cf39b38b66cb1042a6260d8680803845e4d433adba3bb24818", + "wy" : "5ea495b68cbc7ed4173ee63c9042dc502625c7eb7e21fb02ca9a9114e0a3a18d" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200043f3952199774c7cf39b38b66cb1042a6260d8680803845e4d433adba3bb248185ea495b68cbc7ed4173ee63c9042dc502625c7eb7e21fb02ca9a9114e0a3a18d", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEPzlSGZd0x885s4tmyxBCpiYNhoCAOEXk\n1DOtujuySBhepJW2jLx+1Bc+5jyQQtxQJiXH634h+wLKmpEU4KOhjQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 432, + "comment" : "extreme value for k and edgecase s", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798022055555555555555555555555555555554e8e4f44ce51835693ff0ca2ef01215c0", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04cdfb8c0f422e144e137c2412c86c171f5fe3fa3f5bbb544e9076288f3ced786e054fd0721b77c11c79beacb3c94211b0a19bda08652efeaf92513a3b0a163698", + "wx" : "00cdfb8c0f422e144e137c2412c86c171f5fe3fa3f5bbb544e9076288f3ced786e", + "wy" : "054fd0721b77c11c79beacb3c94211b0a19bda08652efeaf92513a3b0a163698" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004cdfb8c0f422e144e137c2412c86c171f5fe3fa3f5bbb544e9076288f3ced786e054fd0721b77c11c79beacb3c94211b0a19bda08652efeaf92513a3b0a163698", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEzfuMD0IuFE4TfCQSyGwXH1/j+j9bu1RO\nkHYojzzteG4FT9ByG3fBHHm+rLPJQhGwoZvaCGUu/q+SUTo7ChY2mA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 433, + "comment" : "extreme value for k and s^-1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798022049249249249249249249249249249248c79facd43214c011123c1b03a93412a5", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0473598a6a1c68278fa6bfd0ce4064e68235bc1c0f6b20a928108be336730f87e3cbae612519b5032ecc85aed811271a95fe7939d5d3460140ba318f4d14aba31d", + "wx" : "73598a6a1c68278fa6bfd0ce4064e68235bc1c0f6b20a928108be336730f87e3", + "wy" : "00cbae612519b5032ecc85aed811271a95fe7939d5d3460140ba318f4d14aba31d" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000473598a6a1c68278fa6bfd0ce4064e68235bc1c0f6b20a928108be336730f87e3cbae612519b5032ecc85aed811271a95fe7939d5d3460140ba318f4d14aba31d", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEc1mKahxoJ4+mv9DOQGTmgjW8HA9rIKko\nEIvjNnMPh+PLrmElGbUDLsyFrtgRJxqV/nk51dNGAUC6MY9NFKujHQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 434, + "comment" : "extreme value for k and s^-1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798022066666666666666666666666666666665e445f1f5dfb6a67e4cba8c385348e6e7", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0458debd9a7ee2c9d59132478a5440ae4d5d7ed437308369f92ea86c82183f10a16773e76f5edbf4da0e4f1bdffac0f57257e1dfa465842931309a24245fda6a5d", + "wx" : "58debd9a7ee2c9d59132478a5440ae4d5d7ed437308369f92ea86c82183f10a1", + "wy" : "6773e76f5edbf4da0e4f1bdffac0f57257e1dfa465842931309a24245fda6a5d" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000458debd9a7ee2c9d59132478a5440ae4d5d7ed437308369f92ea86c82183f10a16773e76f5edbf4da0e4f1bdffac0f57257e1dfa465842931309a24245fda6a5d", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEWN69mn7iydWRMkeKVECuTV1+1Dcwg2n5\nLqhsghg/EKFnc+dvXtv02g5PG9/6wPVyV+HfpGWEKTEwmiQkX9pqXQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 435, + "comment" : "extreme value for k and s^-1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798022066666666666666666666666666666665e445f1f5dfb6a67e4cba8c385348e6e7", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "048b904de47967340c5f8c3572a720924ef7578637feab1949acb241a5a6ac3f5b950904496f9824b1d63f3313bae21b89fae89afdfc811b5ece03fd5aa301864f", + "wx" : "008b904de47967340c5f8c3572a720924ef7578637feab1949acb241a5a6ac3f5b", + "wy" : "00950904496f9824b1d63f3313bae21b89fae89afdfc811b5ece03fd5aa301864f" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200048b904de47967340c5f8c3572a720924ef7578637feab1949acb241a5a6ac3f5b950904496f9824b1d63f3313bae21b89fae89afdfc811b5ece03fd5aa301864f", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEi5BN5HlnNAxfjDVypyCSTvdXhjf+qxlJ\nrLJBpaasP1uVCQRJb5gksdY/MxO64huJ+uia/fyBG17OA/1aowGGTw==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 436, + "comment" : "extreme value for k and s^-1", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798022049249249249249249249249249249248c79facd43214c011123c1b03a93412a5", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04f4892b6d525c771e035f2a252708f3784e48238604b4f94dc56eaa1e546d941a346b1aa0bce68b1c50e5b52f509fb5522e5c25e028bc8f863402edb7bcad8b1b", + "wx" : "00f4892b6d525c771e035f2a252708f3784e48238604b4f94dc56eaa1e546d941a", + "wy" : "346b1aa0bce68b1c50e5b52f509fb5522e5c25e028bc8f863402edb7bcad8b1b" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004f4892b6d525c771e035f2a252708f3784e48238604b4f94dc56eaa1e546d941a346b1aa0bce68b1c50e5b52f509fb5522e5c25e028bc8f863402edb7bcad8b1b", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE9IkrbVJcdx4DXyolJwjzeE5II4YEtPlN\nxW6qHlRtlBo0axqgvOaLHFDltS9Qn7VSLlwl4Ci8j4Y0Au23vK2LGw==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 437, + "comment" : "extreme value for k", + "flags" : [ + "ArithmeticError" + ], + "msg" : "313233343030", + "sig" : "3044022079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179802200eb10e5ab95f2f275348d82ad2e4d7949c8193800d8c9c75df58e343f0ebba7b", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8", + "wx" : "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798", + "wy" : "483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEeb5mfvncu6xVoGKVzocLBwKb/NstzijZ\nWfKBWxb4F5hIOtp3JqPEZV2k+/wOEQio/Re0SKaFVBmcR9CP+xDUuA==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 438, + "comment" : "public key shares x-coordinate with generator", + "flags" : [ + "PointDuplication" + ], + "msg" : "313233343030", + "sig" : "3045022100bb5a52f42f9c9261ed4361f59422a1e30036e7c32b270c8807a419feca60502302202492492492492492492492492492492463cfd66a190a6008891e0d81d49a0952", + "result" : "invalid" + }, + { + "tcId" : 439, + "comment" : "public key shares x-coordinate with generator", + "flags" : [ + "PointDuplication" + ], + "msg" : "313233343030", + "sig" : "3044022044a5ad0bd0636d9e12bc9e0a6bdd5e1bba77f523842193b3b82e448e05d5f11e02202492492492492492492492492492492463cfd66a190a6008891e0d81d49a0952", + "result" : "invalid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798b7c52588d95c3b9aa25b0403f1eef75702e84bb7597aabe663b82f6f04ef2777", + "wx" : "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798", + "wy" : "00b7c52588d95c3b9aa25b0403f1eef75702e84bb7597aabe663b82f6f04ef2777" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798b7c52588d95c3b9aa25b0403f1eef75702e84bb7597aabe663b82f6f04ef2777", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEeb5mfvncu6xVoGKVzocLBwKb/NstzijZ\nWfKBWxb4F5i3xSWI2Vw7mqJbBAPx7vdXAuhLt1l6q+ZjuC9vBO8ndw==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 440, + "comment" : "public key shares x-coordinate with generator", + "flags" : [ + "PointDuplication" + ], + "msg" : "313233343030", + "sig" : "3045022100bb5a52f42f9c9261ed4361f59422a1e30036e7c32b270c8807a419feca60502302202492492492492492492492492492492463cfd66a190a6008891e0d81d49a0952", + "result" : "invalid" + }, + { + "tcId" : 441, + "comment" : "public key shares x-coordinate with generator", + "flags" : [ + "PointDuplication" + ], + "msg" : "313233343030", + "sig" : "3044022044a5ad0bd0636d9e12bc9e0a6bdd5e1bba77f523842193b3b82e448e05d5f11e02202492492492492492492492492492492463cfd66a190a6008891e0d81d49a0952", + "result" : "invalid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04782c8ed17e3b2a783b5464f33b09652a71c678e05ec51e84e2bcfc663a3de963af9acb4280b8c7f7c42f4ef9aba6245ec1ec1712fd38a0fa96418d8cd6aa6152", + "wx" : "782c8ed17e3b2a783b5464f33b09652a71c678e05ec51e84e2bcfc663a3de963", + "wy" : "00af9acb4280b8c7f7c42f4ef9aba6245ec1ec1712fd38a0fa96418d8cd6aa6152" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004782c8ed17e3b2a783b5464f33b09652a71c678e05ec51e84e2bcfc663a3de963af9acb4280b8c7f7c42f4ef9aba6245ec1ec1712fd38a0fa96418d8cd6aa6152", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEeCyO0X47Kng7VGTzOwllKnHGeOBexR6E\n4rz8Zjo96WOvmstCgLjH98QvTvmrpiRewewXEv04oPqWQY2M1qphUg==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 442, + "comment" : "pseudorandom signature", + "flags" : [ + "ValidSignature" + ], + "msg" : "", + "sig" : "3045022100f80ae4f96cdbc9d853f83d47aae225bf407d51c56b7776cd67d0dc195d99a9dc02204cfc1d941e08cb9aceadde0f4ccead76b30d332fc442115d50e673e28686b70b", + "result" : "valid" + }, + { + "tcId" : 443, + "comment" : "pseudorandom signature", + "flags" : [ + "ValidSignature" + ], + "msg" : "4d7367", + "sig" : "30440220109cd8ae0374358984a8249c0a843628f2835ffad1df1a9a69aa2fe72355545c02205390ff250ac4274e1cb25cd6ca6491f6b91281e32f5b264d87977aed4a94e77b", + "result" : "valid" + }, + { + "tcId" : 444, + "comment" : "pseudorandom signature", + "flags" : [ + "ValidSignature" + ], + "msg" : "313233343030", + "sig" : "3045022100d035ee1f17fdb0b2681b163e33c359932659990af77dca632012b30b27a057b302201939d9f3b2858bc13e3474cb50e6a82be44faa71940f876c1cba4c3e989202b6", + "result" : "valid" + }, + { + "tcId" : 445, + "comment" : "pseudorandom signature", + "flags" : [ + "ValidSignature" + ], + "msg" : "0000000000000000000000000000000000000000", + "sig" : "304402204f053f563ad34b74fd8c9934ce59e79c2eb8e6eca0fef5b323ca67d5ac7ed23802204d4b05daa0719e773d8617dce5631c5fd6f59c9bdc748e4b55c970040af01be5", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "046e823555452914099182c6b2c1d6f0b5d28d50ccd005af2ce1bba541aa40caff00000001060492d5a5673e0f25d8d50fb7e58c49d86d46d4216955e0aa3d40e1", + "wx" : "6e823555452914099182c6b2c1d6f0b5d28d50ccd005af2ce1bba541aa40caff", + "wy" : "01060492d5a5673e0f25d8d50fb7e58c49d86d46d4216955e0aa3d40e1" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200046e823555452914099182c6b2c1d6f0b5d28d50ccd005af2ce1bba541aa40caff00000001060492d5a5673e0f25d8d50fb7e58c49d86d46d4216955e0aa3d40e1", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEboI1VUUpFAmRgsaywdbwtdKNUMzQBa8s\n4bulQapAyv8AAAABBgSS1aVnPg8l2NUPt+WMSdhtRtQhaVXgqj1A4Q==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 446, + "comment" : "y-coordinate of the public key is small", + "flags" : [ + "EdgeCasePublicKey" + ], + "msg" : "4d657373616765", + "sig" : "304402206d6a4f556ccce154e7fb9f19e76c3deca13d59cc2aeb4ecad968aab2ded45965022053b9fa74803ede0fc4441bf683d56c564d3e274e09ccf47390badd1471c05fb7", + "result" : "valid" + }, + { + "tcId" : 447, + "comment" : "y-coordinate of the public key is small", + "flags" : [ + "EdgeCasePublicKey" + ], + "msg" : "4d657373616765", + "sig" : "3044022100aad503de9b9fd66b948e9acf596f0a0e65e700b28b26ec56e6e45e846489b3c4021f0ddc3a2f89abb817bb85c062ce02f823c63fc26b269e0bc9b84d81a5aa123d", + "result" : "valid" + }, + { + "tcId" : 448, + "comment" : "y-coordinate of the public key is small", + "flags" : [ + "EdgeCasePublicKey" + ], + "msg" : "4d657373616765", + "sig" : "30450221009182cebd3bb8ab572e167174397209ef4b1d439af3b200cdf003620089e43225022054477c982ea019d2e1000497fc25fcee1bccae55f2ac27530ae53b29c4b356a4", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "046e823555452914099182c6b2c1d6f0b5d28d50ccd005af2ce1bba541aa40cafffffffffef9fb6d2a5a98c1f0da272af0481a73b62792b92bde96aa1e55c2bb4e", + "wx" : "6e823555452914099182c6b2c1d6f0b5d28d50ccd005af2ce1bba541aa40caff", + "wy" : "00fffffffef9fb6d2a5a98c1f0da272af0481a73b62792b92bde96aa1e55c2bb4e" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200046e823555452914099182c6b2c1d6f0b5d28d50ccd005af2ce1bba541aa40cafffffffffef9fb6d2a5a98c1f0da272af0481a73b62792b92bde96aa1e55c2bb4e", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEboI1VUUpFAmRgsaywdbwtdKNUMzQBa8s\n4bulQapAyv/////++fttKlqYwfDaJyrwSBpztieSuSvelqoeVcK7Tg==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 449, + "comment" : "y-coordinate of the public key is large", + "flags" : [ + "EdgeCasePublicKey" + ], + "msg" : "4d657373616765", + "sig" : "304402203854a3998aebdf2dbc28adac4181462ccac7873907ab7f212c42db0e69b56ed802203ed3f6b8a388d02f3e4df9f2ae9c1bd2c3916a686460dffcd42909cd7f82058e", + "result" : "valid" + }, + { + "tcId" : 450, + "comment" : "y-coordinate of the public key is large", + "flags" : [ + "EdgeCasePublicKey" + ], + "msg" : "4d657373616765", + "sig" : "3045022100e94dbdc38795fe5c904d8f16d969d3b587f0a25d2de90b6d8c5c53ff887e360702207a947369c164972521bb8af406813b2d9f94d2aeaa53d4c215aaa0a2578a2c5d", + "result" : "valid" + }, + { + "tcId" : 451, + "comment" : "y-coordinate of the public key is large", + "flags" : [ + "EdgeCasePublicKey" + ], + "msg" : "4d657373616765", + "sig" : "3044022049fc102a08ca47b60e0858cd0284d22cddd7233f94aaffbb2db1dd2cf08425e102205b16fca5a12cdb39701697ad8e39ffd6bdec0024298afaa2326aea09200b14d6", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04000000013fd22248d64d95f73c29b48ab48631850be503fd00f8468b5f0f70e0f6ee7aa43bc2c6fd25b1d8269241cbdd9dbb0dac96dc96231f430705f838717d", + "wx" : "013fd22248d64d95f73c29b48ab48631850be503fd00f8468b5f0f70e0", + "wy" : "00f6ee7aa43bc2c6fd25b1d8269241cbdd9dbb0dac96dc96231f430705f838717d" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004000000013fd22248d64d95f73c29b48ab48631850be503fd00f8468b5f0f70e0f6ee7aa43bc2c6fd25b1d8269241cbdd9dbb0dac96dc96231f430705f838717d", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEAAAAAT/SIkjWTZX3PCm0irSGMYUL5QP9\nAPhGi18PcOD27nqkO8LG/SWx2CaSQcvdnbsNrJbcliMfQwcF+DhxfQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 452, + "comment" : "x-coordinate of the public key is small", + "flags" : [ + "EdgeCasePublicKey" + ], + "msg" : "4d657373616765", + "sig" : "3044022041efa7d3f05a0010675fcb918a45c693da4b348df21a59d6f9cd73e0d831d67a02204454ada693e5e26b7bd693236d340f80545c834577b6f73d378c7bcc534244da", + "result" : "valid" + }, + { + "tcId" : 453, + "comment" : "x-coordinate of the public key is small", + "flags" : [ + "EdgeCasePublicKey" + ], + "msg" : "4d657373616765", + "sig" : "3045022100b615698c358b35920dd883eca625a6c5f7563970cdfc378f8fe0cee17092144c022025f47b326b5be1fb610b885153ea84d41eb4716be66a994e8779989df1c863d4", + "result" : "valid" + }, + { + "tcId" : 454, + "comment" : "x-coordinate of the public key is small", + "flags" : [ + "EdgeCasePublicKey" + ], + "msg" : "4d657373616765", + "sig" : "304502210087cf8c0eb82d44f69c60a2ff5457d3aaa322e7ec61ae5aecfd678ae1c1932b0e02203add3b115815047d6eb340a3e008989eaa0f8708d1794814729094d08d2460d3", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "0425afd689acabaed67c1f296de59406f8c550f57146a0b4ec2c97876dfffffffffa46a76e520322dfbc491ec4f0cc197420fc4ea5883d8f6dd53c354bc4f67c35", + "wx" : "25afd689acabaed67c1f296de59406f8c550f57146a0b4ec2c97876dffffffff", + "wy" : "00fa46a76e520322dfbc491ec4f0cc197420fc4ea5883d8f6dd53c354bc4f67c35" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a0342000425afd689acabaed67c1f296de59406f8c550f57146a0b4ec2c97876dfffffffffa46a76e520322dfbc491ec4f0cc197420fc4ea5883d8f6dd53c354bc4f67c35", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEJa/WiayrrtZ8Hylt5ZQG+MVQ9XFGoLTs\nLJeHbf/////6RqduUgMi37xJHsTwzBl0IPxOpYg9j23VPDVLxPZ8NQ==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 455, + "comment" : "x-coordinate of the public key has many trailing 1's", + "flags" : [ + "EdgeCasePublicKey" + ], + "msg" : "4d657373616765", + "sig" : "3044022062f48ef71ace27bf5a01834de1f7e3f948b9dce1ca1e911d5e13d3b104471d8202205ea8f33f0c778972c4582080deda9b341857dd64514f0849a05f6964c2e34022", + "result" : "valid" + }, + { + "tcId" : 456, + "comment" : "x-coordinate of the public key has many trailing 1's", + "flags" : [ + "EdgeCasePublicKey" + ], + "msg" : "4d657373616765", + "sig" : "3045022100f6b0e2f6fe020cf7c0c20137434344ed7add6c4be51861e2d14cbda472a6ffb402206416c8dd3e5c5282b306e8dc8ff34ab64cc99549232d678d714402eb6ca7aa0f", + "result" : "valid" + }, + { + "tcId" : 457, + "comment" : "x-coordinate of the public key has many trailing 1's", + "flags" : [ + "EdgeCasePublicKey" + ], + "msg" : "4d657373616765", + "sig" : "3045022100db09d8460f05eff23bc7e436b67da563fa4b4edb58ac24ce201fa8a358125057022046da116754602940c8999c8d665f786c50f5772c0a3cdbda075e77eabc64df16", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "04d12e6c66b67734c3c84d2601cf5d35dc097e27637f0aca4a4fdb74b6aadd3bb93f5bdff88bd5736df898e699006ed750f11cf07c5866cd7ad70c7121ffffffff", + "wx" : "00d12e6c66b67734c3c84d2601cf5d35dc097e27637f0aca4a4fdb74b6aadd3bb9", + "wy" : "3f5bdff88bd5736df898e699006ed750f11cf07c5866cd7ad70c7121ffffffff" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a03420004d12e6c66b67734c3c84d2601cf5d35dc097e27637f0aca4a4fdb74b6aadd3bb93f5bdff88bd5736df898e699006ed750f11cf07c5866cd7ad70c7121ffffffff", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE0S5sZrZ3NMPITSYBz1013Al+J2N/CspK\nT9t0tqrdO7k/W9/4i9VzbfiY5pkAbtdQ8RzwfFhmzXrXDHEh/////w==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 458, + "comment" : "y-coordinate of the public key has many trailing 1's", + "flags" : [ + "EdgeCasePublicKey" + ], + "msg" : "4d657373616765", + "sig" : "30440220592c41e16517f12fcabd98267674f974b588e9f35d35406c1a7bb2ed1d19b7b802203e65a06bd9f83caaeb7b00f2368d7e0dece6b12221269a9b5b765198f840a3a1", + "result" : "valid" + }, + { + "tcId" : 459, + "comment" : "y-coordinate of the public key has many trailing 1's", + "flags" : [ + "EdgeCasePublicKey" + ], + "msg" : "4d657373616765", + "sig" : "3045022100be0d70887d5e40821a61b68047de4ea03debfdf51cdf4d4b195558b959a032b202207d994b2d8f1dbbeb13534eb3f6e5dccd85f5c4133c27d9e64271b1826ce1f67d", + "result" : "valid" + }, + { + "tcId" : 460, + "comment" : "y-coordinate of the public key has many trailing 1's", + "flags" : [ + "EdgeCasePublicKey" + ], + "msg" : "4d657373616765", + "sig" : "3045022100fae92dfcb2ee392d270af3a5739faa26d4f97bfd39ed3cbee4d29e26af3b206a02206c9ba37f9faa6a1fd3f65f23b4e853d4692a7274240a12db7ba3884830630d16", + "result" : "valid" + } + ] + }, + { + "type" : "EcdsaBitcoinVerify", + "publicKey" : { + "type" : "EcPublicKey", + "curve" : "secp256k1", + "keySize" : 256, + "uncompressed" : "046d4a7f60d4774a4f0aa8bbdedb953c7eea7909407e3164755664bc2800000000e659d34e4df38d9e8c9eaadfba36612c769195be86c77aac3f36e78b538680fb", + "wx" : "6d4a7f60d4774a4f0aa8bbdedb953c7eea7909407e3164755664bc2800000000", + "wy" : "00e659d34e4df38d9e8c9eaadfba36612c769195be86c77aac3f36e78b538680fb" + }, + "publicKeyDer" : "3056301006072a8648ce3d020106052b8104000a034200046d4a7f60d4774a4f0aa8bbdedb953c7eea7909407e3164755664bc2800000000e659d34e4df38d9e8c9eaadfba36612c769195be86c77aac3f36e78b538680fb", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEbUp/YNR3Sk8KqLve25U8fup5CUB+MWR1\nVmS8KAAAAADmWdNOTfONnoyeqt+6NmEsdpGVvobHeqw/NueLU4aA+w==\n-----END PUBLIC KEY-----\n", + "sha" : "SHA-256", + "tests" : [ + { + "tcId" : 461, + "comment" : "x-coordinate of the public key has many trailing 0's", + "flags" : [ + "EdgeCasePublicKey" + ], + "msg" : "4d657373616765", + "sig" : "30440220176a2557566ffa518b11226694eb9802ed2098bfe278e5570fe1d5d7af18a94302201291df6a0ed5fc0d15098e70bcf13a009284dfd0689d3bb4be6ceeb9be1487c4", + "result" : "valid" + }, + { + "tcId" : 462, + "comment" : "x-coordinate of the public key has many trailing 0's", + "flags" : [ + "EdgeCasePublicKey" + ], + "msg" : "4d657373616765", + "sig" : "3044022060be20c3dbc162dd34d26780621c104bbe5dace630171b2daef0d826409ee5c20220427f7e4d889d549170bda6a9409fb1cb8b0e763d13eea7bd97f64cf41dc6e497", + "result" : "valid" + }, + { + "tcId" : 463, + "comment" : "x-coordinate of the public key has many trailing 0's", + "flags" : [ + "EdgeCasePublicKey" + ], + "msg" : "4d657373616765", + "sig" : "3045022100edf03cf63f658883289a1a593d1007895b9f236d27c9c1f1313089aaed6b16ae02201a4dd6fc0814dc523d1fefa81c64fbf5e618e651e7096fccadbb94cd48e5e0cd", + "result" : "valid" + } + ] + } + ] +} diff --git a/secp256k1-zkp-sys/depend/secp256k1/tools/check-abi.sh b/secp256k1-zkp-sys/depend/secp256k1/tools/check-abi.sh new file mode 100755 index 00000000..55c945ac --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/tools/check-abi.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +set -eu + +default_base_version="$(git describe --match "v*.*.*" --abbrev=0)" +default_new_version="HEAD" + +display_help_and_exit() { + echo "Usage: $0 [ []]" + echo "" + echo "Description: This script uses the ABI Compliance Checker tool to determine if the ABI" + echo " of a new version of libsecp256k1 has changed in a backward-incompatible way." + echo "" + echo "Options:" + echo " base_ver Specify the base version as a git commit-ish" + echo " (default: most recent reachable tag matching \"v.*.*\", currently \"$default_base_version\")" + echo " new_ver Specify the new version as a git commit-ish" + echo " (default: $default_new_version)" + echo " -h, --help Display this help message" + exit 0 +} + +if [ "$#" -eq 0 ]; then + base_version="$default_base_version" + new_version="$default_new_version" +elif [ "$#" -eq 1 ] && { [ "$1" = "-h" ] || [ "$1" = "--help" ]; }; then + display_help_and_exit +elif [ "$#" -eq 1 ] || [ "$#" -eq 2 ]; then + base_version="$1" + if [ "$#" -eq 2 ]; then + new_version="$2" + fi +else + echo "Invalid usage. See help:" + echo "" + display_help_and_exit +fi + +checkout_and_build() { + _orig_dir="$(pwd)" + git worktree add --detach "$1" "$2" + cd "$1" + mkdir build && cd build + cmake -S .. --preset dev-mode \ + -DCMAKE_C_COMPILER=gcc -DCMAKE_BUILD_TYPE=None -DCMAKE_C_FLAGS="-g -Og -gdwarf-4" \ + -DSECP256K1_BUILD_BENCHMARK=OFF \ + -DSECP256K1_BUILD_TESTS=OFF \ + -DSECP256K1_BUILD_EXHAUSTIVE_TESTS=OFF \ + -DSECP256K1_BUILD_CTIME_TESTS=OFF \ + -DSECP256K1_BUILD_EXAMPLES=OFF + cmake --build . -j "$(nproc)" + abi-dumper src/libsecp256k1.so -o ABI.dump -lver "$2" + cd "$_orig_dir" +} + +echo "Comparing $base_version (base version) to $new_version (new version)" +echo + +base_source_dir="$(mktemp -d)" +checkout_and_build "$base_source_dir" "$base_version" + +new_source_dir="$(mktemp -d)" +checkout_and_build "$new_source_dir" "$new_version" + +abi-compliance-checker -lib libsecp256k1 -old "${base_source_dir}/build/ABI.dump" -new "${new_source_dir}/build/ABI.dump" +git worktree remove "$base_source_dir" +git worktree remove "$new_source_dir" diff --git a/secp256k1-zkp-sys/depend/secp256k1/tools/tests_wycheproof_generate.py b/secp256k1-zkp-sys/depend/secp256k1/tools/tests_wycheproof_generate.py new file mode 100755 index 00000000..b26dfa89 --- /dev/null +++ b/secp256k1-zkp-sys/depend/secp256k1/tools/tests_wycheproof_generate.py @@ -0,0 +1,115 @@ +#!/usr/bin/env python3 +# Copyright (c) 2023 Random "Randy" Lattice and Sean Andersen +# Distributed under the MIT software license, see the accompanying +# file COPYING or https://www.opensource.org/licenses/mit-license.php. +''' +Generate a C file with ECDSA testvectors from the Wycheproof project. +''' + +import json +import sys + +filename_input = sys.argv[1] + +with open(filename_input) as f: + doc = json.load(f) + +num_groups = len(doc['testGroups']) + +def to_c_array(x): + if x == "": + return "" + s = ',0x'.join(a+b for a,b in zip(x[::2], x[1::2])) + return "0x" + s + + +num_vectors = 0 +offset_msg_running, offset_pk_running, offset_sig = 0, 0, 0 +out = "" +messages = "" +signatures = "" +public_keys = "" +cache_msgs = {} +cache_public_keys = {} + +for i in range(num_groups): + group = doc['testGroups'][i] + num_tests = len(group['tests']) + public_key = group['publicKey'] + for j in range(num_tests): + test_vector = group['tests'][j] + # // 2 to convert hex to byte length + sig_size = len(test_vector['sig']) // 2 + msg_size = len(test_vector['msg']) // 2 + + if test_vector['result'] == "invalid": + expected_verify = 0 + elif test_vector['result'] == "valid": + expected_verify = 1 + else: + raise ValueError("invalid result field") + + if num_vectors != 0 and sig_size != 0: + signatures += ",\n " + + new_msg = False + msg = to_c_array(test_vector['msg']) + msg_offset = offset_msg_running + # check for repeated msg + if msg not in cache_msgs: + if num_vectors != 0 and msg_size != 0: + messages += ",\n " + cache_msgs[msg] = offset_msg_running + messages += msg + new_msg = True + else: + msg_offset = cache_msgs[msg] + + new_pk = False + pk = to_c_array(public_key['uncompressed']) + pk_offset = offset_pk_running + # check for repeated pk + if pk not in cache_public_keys: + if num_vectors != 0: + public_keys += ",\n " + cache_public_keys[pk] = offset_pk_running + public_keys += pk + new_pk = True + else: + pk_offset = cache_public_keys[pk] + + signatures += to_c_array(test_vector['sig']) + + out += " /" + "* tcId: " + str(test_vector['tcId']) + ". " + test_vector['comment'] + " *" + "/\n" + out += f" {{{pk_offset}, {msg_offset}, {msg_size}, {offset_sig}, {sig_size}, {expected_verify} }},\n" + if new_msg: + offset_msg_running += msg_size + if new_pk: + offset_pk_running += 65 + offset_sig += sig_size + num_vectors += 1 + +struct_definition = """ +typedef struct { + size_t pk_offset; + size_t msg_offset; + size_t msg_len; + size_t sig_offset; + size_t sig_len; + int expected_verify; +} wycheproof_ecdsa_testvector; +""" + + +print("/* Note: this file was autogenerated using tests_wycheproof_generate.py. Do not edit. */") +print(f"#define SECP256K1_ECDSA_WYCHEPROOF_NUMBER_TESTVECTORS ({num_vectors})") + +print(struct_definition) + +print("static const unsigned char wycheproof_ecdsa_messages[] = { " + messages + "};\n") +print("static const unsigned char wycheproof_ecdsa_public_keys[] = { " + public_keys + "};\n") +print("static const unsigned char wycheproof_ecdsa_signatures[] = { " + signatures + "};\n") + +print("static const wycheproof_ecdsa_testvector testvectors[SECP256K1_ECDSA_WYCHEPROOF_NUMBER_TESTVECTORS] = {") +print(out) +print("};") diff --git a/secp256k1-zkp-sys/src/error_callbacks.rs b/secp256k1-zkp-sys/src/error_callbacks.rs index a4ecc055..7b3e4dc4 100644 --- a/secp256k1-zkp-sys/src/error_callbacks.rs +++ b/secp256k1-zkp-sys/src/error_callbacks.rs @@ -9,7 +9,7 @@ use secp256k1_sys::types::{c_char, c_void}; #[no_mangle] #[cfg(not(rust_secp_zkp_no_symbol_renaming))] -pub unsafe extern "C" fn rustsecp256k1zkp_v0_8_0_default_illegal_callback_fn( +pub unsafe extern "C" fn rustsecp256k1zkp_v0_10_0_default_illegal_callback_fn( _: *const c_char, _data: *mut c_void, ) { @@ -18,7 +18,7 @@ pub unsafe extern "C" fn rustsecp256k1zkp_v0_8_0_default_illegal_callback_fn( #[no_mangle] #[cfg(not(rust_secp_zkp_no_symbol_renaming))] -pub unsafe extern "C" fn rustsecp256k1zkp_v0_8_0_default_error_callback_fn( +pub unsafe extern "C" fn rustsecp256k1zkp_v0_10_0_default_error_callback_fn( _: *const c_char, _data: *mut c_void, ) { diff --git a/secp256k1-zkp-sys/src/zkp.rs b/secp256k1-zkp-sys/src/zkp.rs index eac14b5f..d3b31f34 100644 --- a/secp256k1-zkp-sys/src/zkp.rs +++ b/secp256k1-zkp-sys/src/zkp.rs @@ -14,7 +14,7 @@ pub const WHITELIST_MAX_N_KEYS: size_t = 255; extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_pedersen_commitment_parse" + link_name = "rustsecp256k1zkp_v0_10_0_pedersen_commitment_parse" )] // Parse a 33-byte commitment into 64 byte internal commitment object pub fn secp256k1_pedersen_commitment_parse( @@ -25,7 +25,7 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_pedersen_commitment_serialize" + link_name = "rustsecp256k1zkp_v0_10_0_pedersen_commitment_serialize" )] // Serialize a 64-byte commit object into a 33 byte serialized byte sequence pub fn secp256k1_pedersen_commitment_serialize( @@ -36,7 +36,7 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_pedersen_commit" + link_name = "rustsecp256k1zkp_v0_10_0_pedersen_commit" )] // Generates a pedersen commitment: *commit = blind * G + value * G2. // The commitment is 33 bytes, the blinding factor is 32 bytes. @@ -50,7 +50,7 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_pedersen_blind_generator_blind_sum" + link_name = "rustsecp256k1zkp_v0_10_0_pedersen_blind_generator_blind_sum" )] /// Sets the final Pedersen blinding factor correctly when the generators themselves /// have blinding factors. @@ -92,7 +92,7 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_pedersen_verify_tally" + link_name = "rustsecp256k1zkp_v0_10_0_pedersen_verify_tally" )] // Takes two list of 64-byte commitments and sums the first set and // subtracts the second and verifies that they sum to 0. @@ -107,7 +107,7 @@ extern "C" { #[cfg(feature = "std")] #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_rangeproof_info" + link_name = "rustsecp256k1zkp_v0_10_0_rangeproof_info" )] pub fn secp256k1_rangeproof_info( ctx: *const Context, @@ -122,7 +122,7 @@ extern "C" { #[cfg(feature = "std")] #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_rangeproof_rewind" + link_name = "rustsecp256k1zkp_v0_10_0_rangeproof_rewind" )] pub fn secp256k1_rangeproof_rewind( ctx: *const Context, @@ -144,7 +144,7 @@ extern "C" { #[cfg(feature = "std")] #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_rangeproof_verify" + link_name = "rustsecp256k1zkp_v0_10_0_rangeproof_verify" )] pub fn secp256k1_rangeproof_verify( ctx: *const Context, @@ -161,7 +161,7 @@ extern "C" { #[cfg(feature = "std")] #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_rangeproof_sign" + link_name = "rustsecp256k1zkp_v0_10_0_rangeproof_sign" )] pub fn secp256k1_rangeproof_sign( ctx: *const Context, @@ -183,7 +183,7 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_surjectionproof_initialize" + link_name = "rustsecp256k1zkp_v0_10_0_surjectionproof_initialize" )] pub fn secp256k1_surjectionproof_initialize( ctx: *const Context, @@ -199,7 +199,7 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_surjectionproof_serialize" + link_name = "rustsecp256k1zkp_v0_10_0_surjectionproof_serialize" )] pub fn secp256k1_surjectionproof_serialize( ctx: *const Context, @@ -210,7 +210,7 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_surjectionproof_serialized_size" + link_name = "rustsecp256k1zkp_v0_10_0_surjectionproof_serialized_size" )] pub fn secp256k1_surjectionproof_serialized_size( ctx: *const Context, @@ -219,7 +219,7 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_surjectionproof_parse" + link_name = "rustsecp256k1zkp_v0_10_0_surjectionproof_parse" )] pub fn secp256k1_surjectionproof_parse( ctx: *const Context, @@ -230,7 +230,7 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_surjectionproof_generate" + link_name = "rustsecp256k1zkp_v0_10_0_surjectionproof_generate" )] pub fn secp256k1_surjectionproof_generate( ctx: *const Context, @@ -245,7 +245,7 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_surjectionproof_verify" + link_name = "rustsecp256k1zkp_v0_10_0_surjectionproof_verify" )] pub fn secp256k1_surjectionproof_verify( ctx: *const Context, @@ -257,7 +257,7 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_generator_generate_blinded" + link_name = "rustsecp256k1zkp_v0_10_0_generator_generate_blinded" )] pub fn secp256k1_generator_generate_blinded( ctx: *const Context, @@ -268,7 +268,7 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_generator_serialize" + link_name = "rustsecp256k1zkp_v0_10_0_generator_serialize" )] pub fn secp256k1_generator_serialize( ctx: *const Context, @@ -278,7 +278,7 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_generator_parse" + link_name = "rustsecp256k1zkp_v0_10_0_generator_parse" )] pub fn secp256k1_generator_parse( ctx: *const Context, @@ -288,13 +288,13 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_nonce_function_ecdsa_adaptor" + link_name = "rustsecp256k1zkp_v0_10_0_nonce_function_ecdsa_adaptor" )] pub static secp256k1_nonce_function_ecdsa_adaptor: EcdsaAdaptorNonceFn; #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_encrypt" + link_name = "rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_encrypt" )] pub fn secp256k1_ecdsa_adaptor_encrypt( cx: *const Context, @@ -308,7 +308,7 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_verify" + link_name = "rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_verify" )] pub fn secp256k1_ecdsa_adaptor_verify( cx: *const Context, @@ -320,7 +320,7 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_decrypt" + link_name = "rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_decrypt" )] pub fn secp256k1_ecdsa_adaptor_decrypt( cx: *const Context, @@ -331,7 +331,7 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_ecdsa_adaptor_recover" + link_name = "rustsecp256k1zkp_v0_10_0_ecdsa_adaptor_recover" )] pub fn secp256k1_ecdsa_adaptor_recover( cx: *const Context, @@ -343,7 +343,7 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_whitelist_signature_parse" + link_name = "rustsecp256k1zkp_v0_10_0_whitelist_signature_parse" )] pub fn secp256k1_whitelist_signature_parse( cx: *const Context, @@ -354,7 +354,7 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_whitelist_signature_serialize" + link_name = "rustsecp256k1zkp_v0_10_0_whitelist_signature_serialize" )] pub fn secp256k1_whitelist_signature_serialize( ctx: *const Context, @@ -365,7 +365,7 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_whitelist_sign" + link_name = "rustsecp256k1zkp_v0_10_0_whitelist_sign" )] pub fn secp256k1_whitelist_sign( ctx: *const Context, @@ -381,7 +381,7 @@ extern "C" { #[cfg_attr( not(rust_secp_zkp_no_symbol_renaming), - link_name = "rustsecp256k1zkp_v0_8_0_whitelist_verify" + link_name = "rustsecp256k1zkp_v0_10_0_whitelist_verify" )] pub fn secp256k1_whitelist_verify( ctx: *const Context,