Commit Graph

13 Commits

Author SHA1 Message Date
Hennadii Stepanov 8be82d4362
cmake: Rename project to "libsecp256k1" 2023-03-08 21:22:24 +00:00
Pieter Wuille df323b5c14
Merge bitcoin-core/secp256k1#1113: build: Add CMake-based build system
e1eb33724c ci: Add "x86_64: Windows (VS 2022)" task (Hennadii Stepanov)
10602b0030 cmake: Export config files (Hennadii Stepanov)
5468d70964 build: Add CMake-based build system (Hennadii Stepanov)

Pull request description:

  This PR adds a [CMake](https://cmake.org/)-based build system.

  Added build instructions and examples to the [`README.md`](https://github.com/hebasto/secp256k1/blob/220628-cmake/README.md#building-with-cmake-experimental) file.

  Ways to integrate with downstream CMake-based projects:
  - if `secp256k1` is a subtree (including Bitcoin Core project) -- `add_subdirectory(secp256k1)`
  - if `secp256k1` has been installed -- `find_package(secp256k1 0.2.1 CONFIG)`, see https://github.com/hebasto/secp256k1-CMake-example

  Added a few toolchain files for easy cross compiling.

  Discussions on IRC:
  - https://gnusha.org/secp256k1/2022-06-23.log
  - https://gnusha.org/secp256k1/2022-06-24.log
  - https://gnusha.org/secp256k1/2022-06-27.log
  - https://gnusha.org/secp256k1/2023-01-30.log

  ---

  Related PRs:
  - #315
  - #549
  - #761

  ---

  **Implementation notes**

  Minimum required CMake version is 3.1. This was required to provide [`C_STANDARD`](https://cmake.org/cmake/help/latest/prop_tgt/C_STANDARD.html) property.

  In turn, this choice of CMake version implies it is not possible to build with default CMake on Debian 8, which has CMake v3.0.2 only.

  Also see:
  - [CMake Versions on Linux Distros](https://gitlab.kitware.com/cmake/community/-/wikis/CMake-Versions-on-Linux-Distros)
  - https://repology.org/project/cmake/versions

  ---

  # Autotools -- CMake Feature Parity Tables

  ## 1. Configuration options

  Autotool-based build system features being listed according to the `./configure --help` output.

  | Autotools | CMake |
  |---|---|
  | `--prefix` | `-DCMAKE_INSTALL_PREFIX`
  | `--enable-shared` | `-DSECP256K1_BUILD_SHARED` |
  | `--enable-static` | `-DSECP256K1_BUILD_STATIC` |
  | `--enable-dev-mode` _hidden_ | N/A, see https://github.com/bitcoin-core/secp256k1/pull/1113#discussion_r916979117 |
  | `--enable-benchmark` | `-DSECP256K1_BUILD_BENCHMARK` |
  | `--enable-coverage` | `-DCMAKE_BUILD_TYPE=Coverage` |
  | `--enable-tests` | `-DSECP256K1_BUILD_TESTS` |
  | `--enable-ctime-tests` | `-DSECP256K1_BUILD_CTIME_TESTS` |
  | `--enable-experimental` | `-DSECP256K1_EXPERIMENTAL` |
  | `--enable-exhaustive-tests` | `-DSECP256K1_BUILD_EXHAUSTIVE_TESTS` |
  | `--enable-examples` | `-DSECP256K1_BUILD_EXAMPLES` |
  | `--enable-module-ecdh` | `-DSECP256K1_ENABLE_MODULE_ECDH` |
  | `--enable-module-recovery` | `-DSECP256K1_ENABLE_MODULE_RECOVERY` |
  | `--enable-module-extrakeys` | `-DSECP256K1_ENABLE_MODULE_EXTRAKEYS` |
  | `--enable-module-schnorrsig` | `-DSECP256K1_ENABLE_MODULE_SCHNORRSIG` |
  | `--enable-external-default-callbacks` | `-DSECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS` |
  | `--with-test-override-wide-multiply` _hidden_ | `-DSECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY` |
  | `--with-asm` | `-DSECP256K1_ASM` |
  | `--with-ecmult-window` | `-DSECP256K1_ECMULT_WINDOW_SIZE` |
  | `--with-ecmult-gen-precision` | `-DSECP256K1_ECMULT_GEN_PREC_BITS` |
  | `--with-valgrind` | `-DSECP256K1_VALGRING` |

  A screenshot of grouped options from `cmake-gui`:
  ![image](https://user-images.githubusercontent.com/32963518/214821305-fc3ffe82-4d05-4dd7-b2c2-7ca2d5d12e86.png)

  ## 2. `make` targets

  | Autotools | CMake |
  |---|---|
  | `make` | `make` |
  | `make check` | `make check` |
  | `make install` | `make install` * |

  * Installation of `lib/pkgconfig/libsecp256k1.pc` not implemented.

ACKs for top commit:
  theuni:
    ACK e1eb33724c.
  sipa:
    ACK e1eb33724c
  real-or-random:
    ACK e1eb33724c

Tree-SHA512: ebe2772eeb1a430a0a7ae767fb1a9a82d52d5e9bf2306956cd08f7b442c862be2539774dd10d5555817353d37d1c6add78b8fe5a85bb71239304fb42c98ff337
2023-03-08 10:33:09 -05:00
Hennadii Stepanov 5468d70964
build: Add CMake-based build system
Co-authored-by: Tim Ruffing <crypto@timruffing.de>
2023-03-08 13:33:16 +00:00
Tim Ruffing 5757318782
Merge bitcoin-core/secp256k1#1212: Prevent dead-store elimination when clearing secrets in examples
5660c13755 prevent optimization in algorithms (Harshil Jani)

Pull request description:

  Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>

ACKs for top commit:
  sipa:
    utACK 5660c13755
  real-or-random:
    utACK 5660c13755

Tree-SHA512: 90024b7445c04e18a88af4099fc1ac6d1b9b2309b88dd22ae2b1f50aed7bac28b2c180cc28e1a95d5e9ec94b4c4adc44b9ada1477e6abe8efae7884c2382645c
2023-03-02 23:30:20 +01:00
Harshil Jani 5660c13755 prevent optimization in algorithms
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>

Add secure_erase function to clear secrets

Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>

Update the function with good practices

Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>

Renaming random.h to examples_util.h

Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
2023-03-02 15:36:41 +05:30
Tim Ruffing 739c53b19a examples: Extend sig examples by call that uses static context
Besides improving the examples, this makes sure that the examples
import a variable (instead of a function), namely the static context,
from the library. This is helpful when testing MSVC builds, because
the MSVC linker tends to be awkward when importing variables.
2023-02-06 21:44:56 +01:00
Tim Ruffing 4386a2306c examples: Switch to NONE contexts 2022-12-05 11:26:44 +01:00
Tim Ruffing f813bb0df3 schnorrsig: Adapt example to new API 2022-03-17 22:41:36 +01:00
Tim Ruffing 99e6568fc6 schnorrsig: Rename schnorrsig_sign to schnorsig_sign32 and deprecate 2022-03-17 22:41:36 +01:00
Elichai Turkel 7c9502cece
Add a copy of the CC0 license to the examples 2022-02-23 16:15:00 +02:00
Elichai Turkel 422a7cc86a
Add a ecdh shared secret example
Co-authored-by: Jonas Nick <jonasd.nick@gmail.com>
2022-02-23 16:14:57 +02:00
Elichai Turkel b0cfbcc143
Add a Schnorr signing and verifying example
Co-authored-by: Jonas Nick <jonasd.nick@gmail.com>
2022-02-23 16:14:55 +02:00
Elichai Turkel fee7d4bf9e
Add an ECDSA signing and verifying example
Co-authored-by: Jonas Nick <jonasd.nick@gmail.com>
2022-02-23 16:14:53 +02:00