Skip to content

Commit 28310ef

Browse files
committed
Squashed 'src/secp256k1/' changes from 4187a46649..c82d84bb86
c82d84bb86 build: add CMake option for disabling symbol visibility attributes ce7923874f build: Add SECP256K1_NO_API_VISIBILITY_ATTRIBUTES e5297f6d79 build: Refactor visibility logic c498779096 Merge bitcoin-core/secp256k1#1687: cmake: support the use of launchers in ctest -S scripts 0dfe387dbe cmake: support the use of launchers in ctest -S scripts 89096c234d Merge bitcoin-core/secp256k1#1692: cmake: configure libsecp256k1.pc during install 7106dce6fd cmake: configure libsecp256k1.pc during install 29e73f4ba5 Merge bitcoin-core/secp256k1#1685: cmake: Emulate Libtool's behavior on FreeBSD 746e36b141 Merge bitcoin-core/secp256k1#1678: cmake: add a helper for linking into static libs a28c2ffa5c Merge bitcoin-core/secp256k1#1683: README: add link to musig example 2a9d374735 Merge bitcoin-core/secp256k1#1690: ci: Bump GCC snapshot major version to 16 add146e101 ci: Bump GCC snapshot major version to 16 145ae3e28d cmake: add a helper for linking into static libs 819210974b README: add link to musig example, generalize module enabling hint 95db29b144 Merge bitcoin-core/secp256k1#1679: cmake: Use `PUBLIC_HEADER` target property in installation logic 37dd422b5c cmake: Emulate Libtool's behavior on FreeBSD f24b838bed Merge bitcoin-core/secp256k1#1680: doc: Promote "Building with CMake" to standard procedure 3f31ac43e0 doc: Promote "Building with CMake" to standard procedure 6f67151ee2 cmake: Use `PUBLIC_HEADER` target property c32715b2a0 cmake, move-only: Move module option processing to `src/CMakeLists.txt` 201b2b8f06 Merge bitcoin-core/secp256k1#1675: cmake: Bump minimum required CMake version to 3.22 3af71987a8 cmake: Bump minimum required CMake version to 3.22 92394476e9 Merge bitcoin-core/secp256k1#1673: Assert field magnitude at control-flow join 3a4f448cb4 Assert field magnitude at control-flow join 9fab425256 Merge bitcoin-core/secp256k1#1668: bench_ecmult: add benchmark for ecmult_const_xonly 05445377f4 bench_ecmult: add benchmark for ecmult_const_xonly bb597b3d39 Merge bitcoin-core/secp256k1#1670: tests: update wycheproof files d73ed99479 tests: update wycheproof files git-subtree-dir: src/secp256k1 git-subtree-split: c82d84bb86f9769a4f9d958f40e86cd99e071bc7
1 parent c31fcaa commit 28310ef

13 files changed

+185
-146
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ We strongly recommend updating to 0.3.1 if you use or plan to use Clang >=14 to
115115
- 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.
116116

117117
#### Added
118-
- 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.
118+
- Added tests against [Project Wycheproof's](https://github.com/C2SP/wycheproof/) set of ECDSA test vectors (Bitcoin "low-S" variant), a fixed set of test cases designed to trigger various edge cases.
119119

120120
#### Changed
121121
- Increased minimum required CMake version to 3.13. CMake builds remain experimental.

CMakeLists.txt

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.16)
1+
cmake_minimum_required(VERSION 3.22)
22

33
#=============================
44
# Project / Package metadata
@@ -13,19 +13,9 @@ project(libsecp256k1
1313
LANGUAGES C
1414
)
1515
enable_testing()
16+
include(CTestUseLaunchers) # Allow users to set CTEST_USE_LAUNCHERS in custom `ctest -S` scripts.
1617
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
1718

18-
if(CMAKE_VERSION VERSION_LESS 3.21)
19-
# Emulates CMake 3.21+ behavior.
20-
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
21-
set(PROJECT_IS_TOP_LEVEL ON)
22-
set(${PROJECT_NAME}_IS_TOP_LEVEL ON)
23-
else()
24-
set(PROJECT_IS_TOP_LEVEL OFF)
25-
set(${PROJECT_NAME}_IS_TOP_LEVEL OFF)
26-
endif()
27-
endif()
28-
2919
# The library version is based on libtool versioning of the ABI. The set of
3020
# rules for updating the version can be found here:
3121
# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
@@ -52,6 +42,8 @@ endif()
5242

5343
option(SECP256K1_INSTALL "Enable installation." ${PROJECT_IS_TOP_LEVEL})
5444

45+
option(SECP256K1_ENABLE_API_VISIBILITY_ATTRIBUTES "Enable visibility attributes in the API." ON)
46+
5547
## Modules
5648

5749
# We declare all options before processing them, to make sure we can express
@@ -63,40 +55,6 @@ option(SECP256K1_ENABLE_MODULE_SCHNORRSIG "Enable schnorrsig module." ON)
6355
option(SECP256K1_ENABLE_MODULE_MUSIG "Enable musig module." ON)
6456
option(SECP256K1_ENABLE_MODULE_ELLSWIFT "Enable ElligatorSwift module." ON)
6557

66-
# Processing must be done in a topological sorting of the dependency graph
67-
# (dependent module first).
68-
if(SECP256K1_ENABLE_MODULE_ELLSWIFT)
69-
add_compile_definitions(ENABLE_MODULE_ELLSWIFT=1)
70-
endif()
71-
72-
if(SECP256K1_ENABLE_MODULE_MUSIG)
73-
if(DEFINED SECP256K1_ENABLE_MODULE_SCHNORRSIG AND NOT SECP256K1_ENABLE_MODULE_SCHNORRSIG)
74-
message(FATAL_ERROR "Module dependency error: You have disabled the schnorrsig module explicitly, but it is required by the musig module.")
75-
endif()
76-
set(SECP256K1_ENABLE_MODULE_SCHNORRSIG ON)
77-
add_compile_definitions(ENABLE_MODULE_MUSIG=1)
78-
endif()
79-
80-
if(SECP256K1_ENABLE_MODULE_SCHNORRSIG)
81-
if(DEFINED SECP256K1_ENABLE_MODULE_EXTRAKEYS AND NOT SECP256K1_ENABLE_MODULE_EXTRAKEYS)
82-
message(FATAL_ERROR "Module dependency error: You have disabled the extrakeys module explicitly, but it is required by the schnorrsig module.")
83-
endif()
84-
set(SECP256K1_ENABLE_MODULE_EXTRAKEYS ON)
85-
add_compile_definitions(ENABLE_MODULE_SCHNORRSIG=1)
86-
endif()
87-
88-
if(SECP256K1_ENABLE_MODULE_EXTRAKEYS)
89-
add_compile_definitions(ENABLE_MODULE_EXTRAKEYS=1)
90-
endif()
91-
92-
if(SECP256K1_ENABLE_MODULE_RECOVERY)
93-
add_compile_definitions(ENABLE_MODULE_RECOVERY=1)
94-
endif()
95-
96-
if(SECP256K1_ENABLE_MODULE_ECDH)
97-
add_compile_definitions(ENABLE_MODULE_ECDH=1)
98-
endif()
99-
10058
option(SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS "Enable external default callback functions." OFF)
10159
if(SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS)
10260
add_compile_definitions(USE_EXTERNAL_DEFAULT_CALLBACKS=1)
@@ -356,6 +314,7 @@ else()
356314
set(cross_status "FALSE")
357315
endif()
358316
message("Cross compiling ....................... ${cross_status}")
317+
message("API visibility attributes ............. ${SECP256K1_ENABLE_API_VISIBILITY_ATTRIBUTES}")
359318
message("Valgrind .............................. ${SECP256K1_VALGRIND}")
360319
get_directory_property(definitions COMPILE_DEFINITIONS)
361320
string(REPLACE ";" " " definitions "${definitions}")

CMakePresets.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"cmakeMinimumRequired": {"major": 3, "minor": 21, "patch": 0},
32
"version": 3,
43
"configurePresets": [
54
{

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ Building with Autotools
108108
109109
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.
110110
111-
Building with CMake (experimental)
112-
----------------------------------
111+
Building with CMake
112+
-------------------
113113
114114
To maintain a pristine source tree, CMake encourages to perform an out-of-source build by using a separate dedicated build tree.
115115
@@ -151,8 +151,9 @@ Usage examples can be found in the [examples](examples) directory. To compile th
151151
* [Schnorr signatures example](examples/schnorr.c)
152152
* [Deriving a shared secret (ECDH) example](examples/ecdh.c)
153153
* [ElligatorSwift key exchange example](examples/ellswift.c)
154+
* [MuSig2 Schnorr multi-signatures example](examples/musig.c)
154155
155-
To compile the Schnorr signature and ECDH examples, you also need to configure with `--enable-module-schnorrsig` and `--enable-module-ecdh`.
156+
To compile the examples, make sure the corresponding modules are enabled.
156157
157158
Benchmark
158159
------------

ci/linux-debian.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
4040
apt-get clean && rm -rf /var/lib/apt/lists/*
4141

4242
# Build and install gcc snapshot
43-
ARG GCC_SNAPSHOT_MAJOR=15
43+
ARG GCC_SNAPSHOT_MAJOR=16
4444
RUN apt-get update && apt-get install --no-install-recommends -y wget libgmp-dev libmpfr-dev libmpc-dev flex && \
4545
mkdir gcc && cd gcc && \
4646
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}" && \

cmake/GeneratePkgConfigFile.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
function(generate_pkg_config_file in_file)
2-
set(prefix ${CMAKE_INSTALL_PREFIX})
2+
set(prefix "@CMAKE_INSTALL_PREFIX@")
33
set(exec_prefix \${prefix})
44
set(libdir \${exec_prefix}/${CMAKE_INSTALL_LIBDIR})
55
set(includedir \${prefix}/${CMAKE_INSTALL_INCLUDEDIR})
66
set(PACKAGE_VERSION ${PROJECT_VERSION})
7-
configure_file(${in_file} ${PROJECT_NAME}.pc @ONLY)
7+
configure_file(${in_file} ${PROJECT_NAME}.pc.in @ONLY)
8+
install(CODE "configure_file(
9+
\"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc.in\"
10+
\"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc\"
11+
@ONLY)" ALL_COMPONENTS)
812
endfunction()

include/secp256k1.h

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -121,45 +121,57 @@ typedef int (*secp256k1_nonce_function)(
121121
#endif
122122

123123
/* Symbol visibility. */
124-
#if defined(_WIN32)
125-
/* GCC for Windows (e.g., MinGW) accepts the __declspec syntax
126-
* for MSVC compatibility. A __declspec declaration implies (but is not
127-
* exactly equivalent to) __attribute__ ((visibility("default"))), and so we
128-
* actually want __declspec even on GCC, see "Microsoft Windows Function
129-
* Attributes" in the GCC manual and the recommendations in
130-
* https://gcc.gnu.org/wiki/Visibility. */
131-
# if defined(SECP256K1_BUILD)
132-
# if defined(DLL_EXPORT) || defined(SECP256K1_DLL_EXPORT)
133-
/* Building libsecp256k1 as a DLL.
134-
* 1. If using Libtool, it defines DLL_EXPORT automatically.
135-
* 2. In other cases, SECP256K1_DLL_EXPORT must be defined. */
136-
# define SECP256K1_API extern __declspec (dllexport)
137-
# else
138-
/* Building libsecp256k1 as a static library on Windows.
139-
* No declspec is needed, and so we would want the non-Windows-specific
140-
* logic below take care of this case. However, this may result in setting
141-
* __attribute__ ((visibility("default"))), which is supposed to be a noop
142-
* on Windows but may trigger warnings when compiling with -flto due to a
143-
* bug in GCC, see
144-
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116478 . */
145-
# define SECP256K1_API extern
146-
# endif
147-
/* The user must define SECP256K1_STATIC when consuming libsecp256k1 as a static
148-
* library on Windows. */
149-
# elif !defined(SECP256K1_STATIC)
150-
/* Consuming libsecp256k1 as a DLL. */
151-
# define SECP256K1_API extern __declspec (dllimport)
152-
# endif
124+
#if !defined(SECP256K1_API) && defined(SECP256K1_NO_API_VISIBILITY_ATTRIBUTES)
125+
/* The user has requested that we don't specify visibility attributes in
126+
* the public API.
127+
*
128+
* Since all our non-API declarations use the static qualifier, this means
129+
* that the user can use -fvisibility=<value> to set the visibility of the
130+
* API symbols. For instance, -fvisibility=hidden can be useful *even for
131+
* the API symbols*, e.g., when building a static library which is linked
132+
* into a shared library, and the latter should not re-export the
133+
* libsecp256k1 API.
134+
*
135+
* While visibility is a concept that applies only to shared libraries,
136+
* setting visibility will still make a difference when building a static
137+
* library: the visibility settings will be stored in the static library,
138+
* solely for the potential case that the static library will be linked into
139+
* a shared library. In that case, the stored visibility settings will
140+
* resurface and be honored for the shared library. */
141+
# define SECP256K1_API extern
153142
#endif
154-
#ifndef SECP256K1_API
155-
/* All cases not captured by the Windows-specific logic. */
156-
# if defined(__GNUC__) && (__GNUC__ >= 4) && defined(SECP256K1_BUILD)
157-
/* Building libsecp256k1 using GCC or compatible. */
158-
# define SECP256K1_API extern __attribute__ ((visibility ("default")))
159-
# else
160-
/* Fall back to standard C's extern. */
161-
# define SECP256K1_API extern
162-
# endif
143+
#if !defined(SECP256K1_API)
144+
# if defined(SECP256K1_BUILD)
145+
/* On Windows, assume a shared library only if explicitly requested.
146+
* 1. If using Libtool, it defines DLL_EXPORT automatically.
147+
* 2. In other cases, SECP256K1_DLL_EXPORT must be defined. */
148+
# if defined(_WIN32) && (defined(SECP256K1_DLL_EXPORT) || defined(DLL_EXPORT))
149+
/* GCC for Windows (e.g., MinGW) accepts the __declspec syntax for
150+
* MSVC compatibility. A __declspec declaration implies (but is not
151+
* exactly equivalent to) __attribute__ ((visibility("default"))),
152+
* and so we actually want __declspec even on GCC, see "Microsoft
153+
* Windows Function Attributes" in the GCC manual and the
154+
* recommendations in https://gcc.gnu.org/wiki/Visibility . */
155+
# define SECP256K1_API extern __declspec(dllexport)
156+
/* Avoid __attribute__ ((visibility("default"))) on Windows to get rid
157+
* of warnings when compiling with -flto due to a bug in GCC, see
158+
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116478 . */
159+
# elif !defined(_WIN32) && defined (__GNUC__) && (__GNUC__ >= 4)
160+
# define SECP256K1_API extern __attribute__ ((visibility("default")))
161+
# else
162+
# define SECP256K1_API extern
163+
# endif
164+
# else
165+
/* On Windows, SECP256K1_STATIC must be defined when consuming
166+
* libsecp256k1 as a static library. Note that SECP256K1_STATIC is a
167+
* "consumer-only" macro, and it has no meaning when building
168+
* libsecp256k1. */
169+
# if defined(_WIN32) && !defined(SECP256K1_STATIC)
170+
# define SECP256K1_API extern __declspec(dllimport)
171+
# else
172+
# define SECP256K1_API extern
173+
# endif
174+
# endif
163175
#endif
164176

165177
/* Warning attributes

0 commit comments

Comments
 (0)