Skip to content

Commit ef5eeb6

Browse files
josibakemacgyver13
authored andcommitted
Squashed 'src/secp256k1/' changes from b9313c6e1a..9e85256bbe
9e85256bbe docs: update README 4b1fb2c186 ci: enable silentpayments module de508a78ac tests: add constant time tests 45427dd4d7 tests: add BIP-352 test vectors 6975614517 silentpayments: add benchmarks for scanning a9af9ebf35 silentpayments: add examples/silentpayments.c b06254b6c7 silentpayments: receiving 3c9362dd6a silentpayments: recipient label support 70e20b7145 silentpayments: sending cf44324b5e build: add skeleton for new silentpayments (BIP352) module REVERT: b9313c6e1a Merge bitcoin-core/secp256k1#1708: release cleanup: bump version after 0.7.0 REVERT: a660a4976e Merge bitcoin-core/secp256k1#1707: release: Prepare for 0.7.0 REVERT: 7ab8b0cc01 release cleanup: bump version after 0.7.0 REVERT: a3e742d947 release: Prepare for 0.7.0 REVERT: f67b0ac1a0 ci: Don't hardcode ABI version REVERT: 020ee60495 Merge bitcoin-core/secp256k1#1706: musig/tests: initialize keypair REVERT: cde4130898 musig/tests: initialize keypair REVERT: 6037833c9e Merge bitcoin-core/secp256k1#1702: changelog: update REVERT: 40b4a06520 changelog: update REVERT: 5e74086dc8 Merge bitcoin-core/secp256k1#1705: musig/test: Remove dead code REVERT: 7c3380423c Merge bitcoin-core/secp256k1#1696: build: Refactor visibility logic and add override REVERT: 8d967a602b musig/test: Remove dead code REVERT: 983711cd6d musig/tests: Refactor vectors_signverify REVERT: 73a695958a Merge bitcoin-core/secp256k1#1704: cmake: Make `secp256k1_objs` inherit interface defines from `secp256k1` REVERT: bf082221ff cmake: Make `secp256k1_objs` inherit interface defines from `secp256k1` REVERT: c82d84bb86 build: add CMake option for disabling symbol visibility attributes REVERT: ce7923874f build: Add SECP256K1_NO_API_VISIBILITY_ATTRIBUTES REVERT: e5297f6d79 build: Refactor visibility logic REVERT: cbbbf3bd6e Merge bitcoin-core/secp256k1#1699: ci: enable musig module for native macOS arm64 job REVERT: 943479a7a3 Merge bitcoin-core/secp256k1#1694: Revert "cmake: configure libsecp256k1.pc during install" REVERT: 3352f9d667 ci: enable musig module for native macOS arm64 job REVERT: 44b205e9ee Revert "cmake: configure libsecp256k1.pc during install" git-subtree-dir: src/secp256k1 git-subtree-split: 9e85256bbe527bf084222ee08dade9ea497d5c99
1 parent 01e275b commit ef5eeb6

21 files changed

+9166
-345
lines changed

.github/workflows/ci.yml

Lines changed: 545 additions & 37 deletions
Large diffs are not rendered by default.

.gitignore

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1-
# Patterns that are specific to a text editor, IDE, operating system, or user
2-
# environment are not added here. They should be added to your local gitignore
3-
# file instead:
4-
# https://docs.github.com/en/get-started/git-basics/ignoring-files#configuring-ignored-files-for-all-repositories-on-your-computer
1+
bench
2+
bench_ecmult
3+
bench_internal
4+
noverify_tests
5+
tests
6+
exhaustive_tests
7+
precompute_ecmult_gen
8+
precompute_ecmult
9+
ctime_tests
10+
ecdh_example
11+
ecdsa_example
12+
schnorr_example
13+
ellswift_example
14+
musig_example
15+
silentpayments_example
16+
*.exe
17+
*.so
18+
*.a
19+
*.csv
20+
*.log
21+
*.trs
22+
*.sage.py
523

624
# Build subdirectories.
725
/*build*

CMakeLists.txt

Lines changed: 136 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -26,45 +26,27 @@ get_directory_property(precious_variables CACHE_VARIABLES)
2626
#=============================
2727
# Project / Package metadata
2828
#=============================
29-
set(CLIENT_NAME "Bitcoin Core")
30-
set(CLIENT_VERSION_MAJOR 29)
31-
set(CLIENT_VERSION_MINOR 99)
32-
set(CLIENT_VERSION_BUILD 0)
33-
set(CLIENT_VERSION_RC 0)
34-
set(CLIENT_VERSION_IS_RELEASE "false")
35-
set(COPYRIGHT_YEAR "2025")
36-
37-
# During the enabling of the CXX and CXXOBJ languages, we modify
38-
# CMake's compiler/linker invocation strings by appending the content
39-
# of the user-defined `APPEND_*` variables, which allows overriding
40-
# any flag. We also ensure that the APPEND_* flags are considered
41-
# during CMake's tests, which use the `try_compile()` command.
42-
#
43-
# CMake's docs state that the `CMAKE_TRY_COMPILE_PLATFORM_VARIABLES`
44-
# variable "is meant to be set by CMake's platform information modules
45-
# for the current toolchain, or by a toolchain file." We do our best
46-
# to set it before the `project()` command.
47-
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
48-
CMAKE_CXX_COMPILE_OBJECT
49-
CMAKE_OBJCXX_COMPILE_OBJECT
50-
CMAKE_CXX_LINK_EXECUTABLE
51-
)
52-
53-
project(BitcoinCore
54-
VERSION ${CLIENT_VERSION_MAJOR}.${CLIENT_VERSION_MINOR}.${CLIENT_VERSION_BUILD}
55-
DESCRIPTION "Bitcoin client software"
56-
HOMEPAGE_URL "https://bitcoincore.org/"
57-
LANGUAGES NONE
29+
project(libsecp256k1
30+
# The package (a.k.a. release) version is based on semantic versioning 2.0.0 of
31+
# the API. All changes in experimental modules are treated as
32+
# backwards-compatible and therefore at most increase the minor version.
33+
VERSION 0.6.1
34+
DESCRIPTION "Optimized C library for ECDSA signatures and secret/public key operations on curve secp256k1."
35+
HOMEPAGE_URL "https://github.com/bitcoin-core/secp256k1"
36+
LANGUAGES C
5837
)
59-
60-
set(CLIENT_VERSION_STRING ${PROJECT_VERSION})
61-
if(CLIENT_VERSION_RC GREATER 0)
62-
string(APPEND CLIENT_VERSION_STRING "rc${CLIENT_VERSION_RC}")
63-
endif()
64-
65-
set(COPYRIGHT_HOLDERS "The %s developers")
66-
set(COPYRIGHT_HOLDERS_FINAL "The ${CLIENT_NAME} developers")
67-
set(CLIENT_BUGREPORT "https://github.com/bitcoin/bitcoin/issues")
38+
enable_testing()
39+
include(CTestUseLaunchers) # Allow users to set CTEST_USE_LAUNCHERS in custom `ctest -S` scripts.
40+
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
41+
42+
# The library version is based on libtool versioning of the ABI. The set of
43+
# rules for updating the version can be found here:
44+
# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
45+
# All changes in experimental modules are treated as if they don't affect the
46+
# interface and therefore only increase the revision.
47+
set(${PROJECT_NAME}_LIB_VERSION_CURRENT 5)
48+
set(${PROJECT_NAME}_LIB_VERSION_REVISION 1)
49+
set(${PROJECT_NAME}_LIB_VERSION_AGE 0)
6850

6951
#=============================
7052
# Language setup
@@ -103,14 +85,61 @@ option(BUILD_TESTS "Build test_bitcoin and other unit test executables." ON)
10385
option(BUILD_TX "Build bitcoin-tx executable." ${BUILD_TESTS})
10486
option(BUILD_UTIL "Build bitcoin-util executable." ${BUILD_TESTS})
10587

106-
option(BUILD_UTIL_CHAINSTATE "Build experimental bitcoin-chainstate executable." OFF)
107-
option(BUILD_KERNEL_LIB "Build experimental bitcoinkernel library." ${BUILD_UTIL_CHAINSTATE})
108-
109-
option(ENABLE_WALLET "Enable wallet." ON)
110-
if(ENABLE_WALLET)
111-
if(VCPKG_TARGET_TRIPLET)
112-
# Use of the `unofficial::` namespace is a vcpkg package manager convention.
113-
find_package(unofficial-sqlite3 CONFIG REQUIRED)
88+
## Modules
89+
90+
# We declare all options before processing them, to make sure we can express
91+
# dependencies while processing.
92+
option(SECP256K1_ENABLE_MODULE_ECDH "Enable ECDH module." ON)
93+
option(SECP256K1_ENABLE_MODULE_RECOVERY "Enable ECDSA pubkey recovery module." OFF)
94+
option(SECP256K1_ENABLE_MODULE_EXTRAKEYS "Enable extrakeys module." ON)
95+
option(SECP256K1_ENABLE_MODULE_SCHNORRSIG "Enable schnorrsig module." ON)
96+
option(SECP256K1_ENABLE_MODULE_MUSIG "Enable musig module." ON)
97+
option(SECP256K1_ENABLE_MODULE_ELLSWIFT "Enable ElligatorSwift module." ON)
98+
option(SECP256K1_ENABLE_MODULE_SILENTPAYMENTS "Enable Silent Payments module." ON)
99+
100+
option(SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS "Enable external default callback functions." OFF)
101+
if(SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS)
102+
add_compile_definitions(USE_EXTERNAL_DEFAULT_CALLBACKS=1)
103+
endif()
104+
105+
set(SECP256K1_ECMULT_WINDOW_SIZE 15 CACHE STRING "Window size for ecmult precomputation for verification, specified as integer in range [2..24]. The default value is a reasonable setting for desktop machines (currently 15). [default=15]")
106+
set_property(CACHE SECP256K1_ECMULT_WINDOW_SIZE PROPERTY STRINGS 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24)
107+
include(CheckStringOptionValue)
108+
check_string_option_value(SECP256K1_ECMULT_WINDOW_SIZE)
109+
add_compile_definitions(ECMULT_WINDOW_SIZE=${SECP256K1_ECMULT_WINDOW_SIZE})
110+
111+
set(SECP256K1_ECMULT_GEN_KB 86 CACHE STRING "The size of the precomputed table for signing in multiples of 1024 bytes (on typical platforms). Larger values result in possibly better signing or key generation performance at the cost of a larger table. Valid choices are 2, 22, 86. The default value is a reasonable setting for desktop machines (currently 86). [default=86]")
112+
set_property(CACHE SECP256K1_ECMULT_GEN_KB PROPERTY STRINGS 2 22 86)
113+
check_string_option_value(SECP256K1_ECMULT_GEN_KB)
114+
if(SECP256K1_ECMULT_GEN_KB EQUAL 2)
115+
add_compile_definitions(COMB_BLOCKS=2)
116+
add_compile_definitions(COMB_TEETH=5)
117+
elseif(SECP256K1_ECMULT_GEN_KB EQUAL 22)
118+
add_compile_definitions(COMB_BLOCKS=11)
119+
add_compile_definitions(COMB_TEETH=6)
120+
elseif(SECP256K1_ECMULT_GEN_KB EQUAL 86)
121+
add_compile_definitions(COMB_BLOCKS=43)
122+
add_compile_definitions(COMB_TEETH=6)
123+
endif()
124+
125+
set(SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY "OFF" CACHE STRING "Test-only override of the (autodetected by the C code) \"widemul\" setting. Legal values are: \"OFF\", \"int128_struct\", \"int128\" or \"int64\". [default=OFF]")
126+
set_property(CACHE SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY PROPERTY STRINGS "OFF" "int128_struct" "int128" "int64")
127+
check_string_option_value(SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY)
128+
if(SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY)
129+
string(TOUPPER "${SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY}" widemul_upper_value)
130+
add_compile_definitions(USE_FORCE_WIDEMUL_${widemul_upper_value}=1)
131+
endif()
132+
mark_as_advanced(FORCE SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY)
133+
134+
set(SECP256K1_ASM "AUTO" CACHE STRING "Assembly to use: \"AUTO\", \"OFF\", \"x86_64\" or \"arm32\" (experimental). [default=AUTO]")
135+
set_property(CACHE SECP256K1_ASM PROPERTY STRINGS "AUTO" "OFF" "x86_64" "arm32")
136+
check_string_option_value(SECP256K1_ASM)
137+
if(SECP256K1_ASM STREQUAL "arm32")
138+
enable_language(ASM)
139+
include(CheckArm32Assembly)
140+
check_arm32_assembly()
141+
if(HAVE_ARM32_ASM)
142+
add_compile_definitions(USE_EXTERNAL_ASM=1)
114143
else()
115144
find_package(SQLite3 3.7.17 REQUIRED)
116145
endif()
@@ -653,20 +682,19 @@ if(BUILD_DAEMON AND ENABLE_IPC)
653682
else()
654683
set(bitcoin_daemon_status OFF)
655684
endif()
656-
message(" bitcoin-node (multiprocess) ......... ${bitcoin_daemon_status}")
657-
message(" bitcoin-qt (GUI) .................... ${BUILD_GUI}")
658-
if(BUILD_GUI AND ENABLE_IPC)
659-
set(bitcoin_gui_status ON)
660-
else()
661-
set(bitcoin_gui_status OFF)
662-
endif()
663-
message(" bitcoin-gui (GUI, multiprocess) ..... ${bitcoin_gui_status}")
664-
message(" bitcoin-cli ......................... ${BUILD_CLI}")
665-
message(" bitcoin-tx .......................... ${BUILD_TX}")
666-
message(" bitcoin-util ........................ ${BUILD_UTIL}")
667-
message(" bitcoin-wallet ...................... ${BUILD_WALLET_TOOL}")
668-
message(" bitcoin-chainstate (experimental) ... ${BUILD_UTIL_CHAINSTATE}")
669-
message(" libbitcoinkernel (experimental) ..... ${BUILD_KERNEL_LIB}")
685+
686+
message(" library type ........................ ${library_type}")
687+
message("Optional modules:")
688+
message(" ECDH ................................ ${SECP256K1_ENABLE_MODULE_ECDH}")
689+
message(" ECDSA pubkey recovery ............... ${SECP256K1_ENABLE_MODULE_RECOVERY}")
690+
message(" extrakeys ........................... ${SECP256K1_ENABLE_MODULE_EXTRAKEYS}")
691+
message(" schnorrsig .......................... ${SECP256K1_ENABLE_MODULE_SCHNORRSIG}")
692+
message(" musig ............................... ${SECP256K1_ENABLE_MODULE_MUSIG}")
693+
message(" ElligatorSwift ...................... ${SECP256K1_ENABLE_MODULE_ELLSWIFT}")
694+
message(" Silent Payments ..................... ${SECP256K1_ENABLE_MODULE_SILENTPAYMENTS}")
695+
message("Parameters:")
696+
message(" ecmult window size .................. ${SECP256K1_ECMULT_WINDOW_SIZE}")
697+
message(" ecmult gen table size ............... ${SECP256K1_ECMULT_GEN_KB} KiB")
670698
message("Optional features:")
671699
message(" wallet support ...................... ${ENABLE_WALLET}")
672700
message(" external signer ..................... ${ENABLE_EXTERNAL_SIGNER}")
@@ -696,18 +724,54 @@ else()
696724
set(cross_status "FALSE")
697725
endif()
698726
message("Cross compiling ....................... ${cross_status}")
699-
message("C++ compiler .......................... ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}, ${CMAKE_CXX_COMPILER}")
700-
include(FlagsSummary)
701-
flags_summary()
702-
message("Treat compiler warnings as errors ..... ${WERROR}")
703-
message("Use ccache for compiling .............. ${WITH_CCACHE}")
704-
message("\n")
705-
if(configure_warnings)
706-
message(" ******\n")
707-
foreach(warning IN LISTS configure_warnings)
708-
message(WARNING "${warning}")
709-
endforeach()
710-
message(" ******\n")
727+
message("Valgrind .............................. ${SECP256K1_VALGRIND}")
728+
get_directory_property(definitions COMPILE_DEFINITIONS)
729+
string(REPLACE ";" " " definitions "${definitions}")
730+
message("Preprocessor defined macros ........... ${definitions}")
731+
message("C compiler ............................ ${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}, ${CMAKE_C_COMPILER}")
732+
message("CFLAGS ................................ ${CMAKE_C_FLAGS}")
733+
get_directory_property(compile_options COMPILE_OPTIONS)
734+
string(REPLACE ";" " " compile_options "${compile_options}")
735+
message("Compile options ....................... " ${compile_options})
736+
if(NOT is_multi_config)
737+
message("Build type:")
738+
message(" - CMAKE_BUILD_TYPE ................... ${CMAKE_BUILD_TYPE}")
739+
string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
740+
message(" - CFLAGS ............................. ${CMAKE_C_FLAGS_${build_type}}")
741+
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_${build_type}}")
742+
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_${build_type}}")
743+
else()
744+
message("Supported configurations .............. ${CMAKE_CONFIGURATION_TYPES}")
745+
message("RelWithDebInfo configuration:")
746+
message(" - CFLAGS ............................. ${CMAKE_C_FLAGS_RELWITHDEBINFO}")
747+
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")
748+
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO}")
749+
message("Debug configuration:")
750+
message(" - CFLAGS ............................. ${CMAKE_C_FLAGS_DEBUG}")
751+
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
752+
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
753+
endif()
754+
if(SECP256K1_APPEND_CFLAGS)
755+
message("SECP256K1_APPEND_CFLAGS ............... ${SECP256K1_APPEND_CFLAGS}")
756+
endif()
757+
if(SECP256K1_APPEND_LDFLAGS)
758+
message("SECP256K1_APPEND_LDFLAGS .............. ${SECP256K1_APPEND_LDFLAGS}")
759+
endif()
760+
message("")
761+
if(print_msan_notice)
762+
message(
763+
"Note:\n"
764+
" MemorySanitizer detected, tried to add -fno-sanitize-memory-param-retval to compile options\n"
765+
" to avoid false positives in ctime_tests. Pass -DSECP256K1_BUILD_CTIME_TESTS=OFF to avoid this.\n"
766+
)
767+
endif()
768+
if(SECP256K1_EXPERIMENTAL)
769+
message(
770+
" ******\n"
771+
" WARNING: experimental build\n"
772+
" Experimental features do not have stable APIs or properties, and may not be safe for production use.\n"
773+
" ******\n"
774+
)
711775
endif()
712776

713777
# We want all build properties to be encapsulated properly.

README.md

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,21 @@ https://bitcoincore.org/en/download/.
99
What is Bitcoin Core?
1010
---------------------
1111

12-
Bitcoin Core connects to the Bitcoin peer-to-peer network to download and fully
13-
validate blocks and transactions. It also includes a wallet and graphical user
14-
interface, which can be optionally built.
12+
Features:
13+
* secp256k1 ECDSA signing/verification and key generation.
14+
* Additive and multiplicative tweaking of secret/public keys.
15+
* Serialization/parsing of secret keys, public keys, signatures.
16+
* Constant time, constant memory access signing and public key generation.
17+
* Derandomized ECDSA (via RFC6979 or with a caller provided function.)
18+
* Very efficient implementation.
19+
* Suitable for embedded systems.
20+
* No runtime dependencies.
21+
* Optional module for public key recovery.
22+
* Optional module for ECDH key exchange.
23+
* Optional module for Schnorr signatures according to [BIP-340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki).
24+
* Optional module for ElligatorSwift key exchange according to [BIP-324](https://github.com/bitcoin/bips/blob/master/bip-0324.mediawiki).
25+
* Optional module for MuSig2 Schnorr multi-signatures according to [BIP-327](https://github.com/bitcoin/bips/blob/master/bip-0327.mediawiki).
26+
* Optional module for Silent Payments send and receive according to [BIP-352](https://github.com/bitcoin/bips/blob/master/bip-0352.mediawiki).
1527

1628
Further information about Bitcoin Core is available in the [doc folder](/doc).
1729

@@ -66,7 +78,38 @@ code. This is especially important for large or high-risk changes. It is useful
6678
to add a test plan to the pull request description if testing the changes is
6779
not straightforward.
6880

69-
Translations
81+
The following example assumes using of Visual Studio 2022 and CMake v3.21+.
82+
83+
In "Developer Command Prompt for VS 2022":
84+
85+
>cmake -G "Visual Studio 17 2022" -A x64 -B build
86+
>cmake --build build --config RelWithDebInfo
87+
88+
Usage examples
89+
-----------
90+
Usage examples can be found in the [examples](examples) directory. To compile them you need to configure with `--enable-examples`.
91+
* [ECDSA example](examples/ecdsa.c)
92+
* [Schnorr signatures example](examples/schnorr.c)
93+
* [Deriving a shared secret (ECDH) example](examples/ecdh.c)
94+
* [ElligatorSwift key exchange example](examples/ellswift.c)
95+
* [MuSig2 Schnorr multi-signatures example](examples/musig.c)
96+
* [Silent Payments send and receive example](examples/silentpayments.c)
97+
98+
To compile the examples, make sure the corresponding modules are enabled.
99+
100+
Benchmark
101+
------------
102+
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.
103+
104+
To print the benchmark result to the command line:
105+
106+
$ ./bench_name
107+
108+
To create a CSV file for the benchmark result :
109+
110+
$ ./bench_name | sed '2d;s/ \{1,\}//g' > bench_name.csv
111+
112+
Reporting a vulnerability
70113
------------
71114

72115
Changes to translations as well as new translations can be submitted to

0 commit comments

Comments
 (0)