Skip to content

Commit d0dde4a

Browse files
committed
Merge commits '35c0fdc 5dd637f 69b2192 d7ae25c d403eea f473c95 4af241b a526937 fcc5d73 ca06e58 ea2d5f0 0055b86 ' into temp-merge-1551
2 parents 84ca3b3 + 0055b86 commit d0dde4a

File tree

17 files changed

+201
-97
lines changed

17 files changed

+201
-97
lines changed

.cirrus.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ env:
1010
MAKEFLAGS: -j4
1111
BUILD: check
1212
### secp256k1 config
13-
ECMULTWINDOW: auto
14-
ECMULTGENKB: auto
13+
ECMULTWINDOW: 15
14+
ECMULTGENKB: 22
1515
ASM: no
1616
WIDEMUL: auto
1717
WITH_VALGRIND: yes

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ env:
2121
MAKEFLAGS: '-j4'
2222
BUILD: 'check'
2323
### secp256k1 config
24-
ECMULTWINDOW: 'auto'
25-
ECMULTGENKB: 'auto'
24+
ECMULTWINDOW: 15
25+
ECMULTGENKB: 86
2626
ASM: 'no'
2727
WIDEMUL: 'auto'
2828
WITH_VALGRIND: 'yes'
@@ -962,5 +962,5 @@ jobs:
962962
CI_BUILD: ${{ runner.temp }}/${{ github.run_id }}${{ github.action }}/build
963963
CI_INSTALL: ${{ runner.temp }}/${{ github.run_id }}${{ github.action }}/install
964964
run: |
965-
cmake -B ${{ env.CI_BUILD }} -DCMAKE_INSTALL_PREFIX=${{ env.CI_INSTALL }} && cmake --build ${{ env.CI_BUILD }} --target install && ls -RlAh ${{ env.CI_INSTALL }}
965+
cmake -B ${{ env.CI_BUILD }} -DCMAKE_INSTALL_PREFIX=${{ env.CI_INSTALL }} && cmake --build ${{ env.CI_BUILD }} && cmake --install ${{ env.CI_BUILD }} && ls -RlAh ${{ env.CI_INSTALL }}
966966
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

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ctime_tests
1515
ecdh_example
1616
ecdsa_example
1717
schnorr_example
18+
ellswift_example
1819
*.exe
1920
*.so
2021
*.a

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
## [Unreleased]
1212

13+
#### Added
14+
- Added usage example for an ElligatorSwift key exchange.
15+
1316
## [0.5.0] - 2024-05-06
1417

1518
#### Added

CMakeLists.txt

Lines changed: 37 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
cmake_minimum_required(VERSION 3.13)
2-
3-
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.15)
4-
# MSVC runtime library flags are selected by the CMAKE_MSVC_RUNTIME_LIBRARY abstraction.
5-
cmake_policy(SET CMP0091 NEW)
6-
# MSVC warning flags are not in CMAKE_<LANG>_FLAGS by default.
7-
cmake_policy(SET CMP0092 NEW)
8-
endif()
1+
cmake_minimum_required(VERSION 3.16)
92

103
project(libsecp256k1
114
# The package (a.k.a. release) version is based on semantic versioning 2.0.0 of
@@ -18,15 +11,14 @@ project(libsecp256k1
1811
)
1912

2013
if(CMAKE_VERSION VERSION_LESS 3.21)
21-
get_directory_property(parent_directory PARENT_DIRECTORY)
22-
if(parent_directory)
23-
set(PROJECT_IS_TOP_LEVEL OFF CACHE INTERNAL "Emulates CMake 3.21+ behavior.")
24-
set(${PROJECT_NAME}_IS_TOP_LEVEL OFF CACHE INTERNAL "Emulates CMake 3.21+ behavior.")
14+
# Emulates CMake 3.21+ behavior.
15+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
16+
set(PROJECT_IS_TOP_LEVEL ON)
17+
set(${PROJECT_NAME}_IS_TOP_LEVEL ON)
2518
else()
26-
set(PROJECT_IS_TOP_LEVEL ON CACHE INTERNAL "Emulates CMake 3.21+ behavior.")
27-
set(${PROJECT_NAME}_IS_TOP_LEVEL ON CACHE INTERNAL "Emulates CMake 3.21+ behavior.")
19+
set(PROJECT_IS_TOP_LEVEL OFF)
20+
set(${PROJECT_NAME}_IS_TOP_LEVEL OFF)
2821
endif()
29-
unset(parent_directory)
3022
endif()
3123

3224
# The library version is based on libtool versioning of the ABI. The set of
@@ -154,21 +146,15 @@ if(SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS)
154146
add_compile_definitions(USE_EXTERNAL_DEFAULT_CALLBACKS=1)
155147
endif()
156148

157-
set(SECP256K1_ECMULT_WINDOW_SIZE "AUTO" CACHE STRING "Window size for ecmult precomputation for verification, specified as integer in range [2..24]. \"AUTO\" is a reasonable setting for desktop machines (currently 15). [default=AUTO]")
158-
set_property(CACHE SECP256K1_ECMULT_WINDOW_SIZE PROPERTY STRINGS "AUTO" 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24)
149+
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]")
150+
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)
159151
include(CheckStringOptionValue)
160152
check_string_option_value(SECP256K1_ECMULT_WINDOW_SIZE)
161-
if(SECP256K1_ECMULT_WINDOW_SIZE STREQUAL "AUTO")
162-
set(SECP256K1_ECMULT_WINDOW_SIZE 15)
163-
endif()
164153
add_compile_definitions(ECMULT_WINDOW_SIZE=${SECP256K1_ECMULT_WINDOW_SIZE})
165154

166-
set(SECP256K1_ECMULT_GEN_KB "AUTO" 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. \"AUTO\" is a reasonable setting for desktop machines (currently 22). [default=AUTO]")
167-
set_property(CACHE SECP256K1_ECMULT_GEN_KB PROPERTY STRINGS "AUTO" 2 22 86)
155+
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]")
156+
set_property(CACHE SECP256K1_ECMULT_GEN_KB PROPERTY STRINGS 2 22 86)
168157
check_string_option_value(SECP256K1_ECMULT_GEN_KB)
169-
if(SECP256K1_ECMULT_GEN_KB STREQUAL "AUTO")
170-
set(SECP256K1_ECMULT_GEN_KB 22)
171-
endif()
172158
if(SECP256K1_ECMULT_GEN_KB EQUAL 2)
173159
add_compile_definitions(COMB_BLOCKS=2)
174160
add_compile_definitions(COMB_TEETH=5)
@@ -254,7 +240,7 @@ else()
254240
string(REGEX REPLACE "-DNDEBUG[ \t\r\n]*" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
255241
string(REGEX REPLACE "-DNDEBUG[ \t\r\n]*" "" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
256242
# Prefer -O2 optimization level. (-O3 is CMake's default for Release for many compilers.)
257-
string(REGEX REPLACE "-O3[ \t\r\n]*" "-O2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
243+
string(REGEX REPLACE "-O3( |$)" "-O2\\1" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
258244
endif()
259245

260246
# Define custom "Coverage" build type.
@@ -276,23 +262,25 @@ mark_as_advanced(
276262
CMAKE_SHARED_LINKER_FLAGS_COVERAGE
277263
)
278264

279-
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
280-
set(default_build_type "RelWithDebInfo")
281-
if(is_multi_config)
282-
set(CMAKE_CONFIGURATION_TYPES "${default_build_type}" "Release" "Debug" "MinSizeRel" "Coverage" CACHE STRING
283-
"Supported configuration types."
284-
FORCE
285-
)
286-
else()
287-
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
288-
STRINGS "${default_build_type}" "Release" "Debug" "MinSizeRel" "Coverage"
289-
)
290-
if(NOT CMAKE_BUILD_TYPE)
291-
message(STATUS "Setting build type to \"${default_build_type}\" as none was specified")
292-
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING
293-
"Choose the type of build."
265+
if(PROJECT_IS_TOP_LEVEL)
266+
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
267+
set(default_build_type "RelWithDebInfo")
268+
if(is_multi_config)
269+
set(CMAKE_CONFIGURATION_TYPES "${default_build_type}" "Release" "Debug" "MinSizeRel" "Coverage" CACHE STRING
270+
"Supported configuration types."
294271
FORCE
295272
)
273+
else()
274+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
275+
STRINGS "${default_build_type}" "Release" "Debug" "MinSizeRel" "Coverage"
276+
)
277+
if(NOT CMAKE_BUILD_TYPE)
278+
message(STATUS "Setting build type to \"${default_build_type}\" as none was specified")
279+
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING
280+
"Choose the type of build."
281+
FORCE
282+
)
283+
endif()
296284
endif()
297285
endif()
298286

@@ -336,25 +324,23 @@ if(SECP256K1_BUILD_CTIME_TESTS)
336324
unset(msan_enabled)
337325
endif()
338326

339-
# Ask CTest to create a "check" target (e.g., make check) as alias for the "test" target.
340-
# CTEST_TEST_TARGET_ALIAS is not documented but supposed to be user-facing.
341-
# See: https://gitlab.kitware.com/cmake/cmake/-/commit/816c9d1aa1f2b42d40c81a991b68c96eb12b6d2
342-
set(CTEST_TEST_TARGET_ALIAS check)
343327
include(CTest)
344328
# We do not use CTest's BUILD_TESTING because a single toggle for all tests is too coarse for our needs.
345329
mark_as_advanced(BUILD_TESTING)
346330
if(SECP256K1_BUILD_BENCHMARK OR SECP256K1_BUILD_TESTS OR SECP256K1_BUILD_EXHAUSTIVE_TESTS OR SECP256K1_BUILD_CTIME_TESTS OR SECP256K1_BUILD_EXAMPLES)
347331
enable_testing()
348332
endif()
349333

350-
set(SECP256K1_LATE_CFLAGS "" CACHE STRING "Compiler flags that are added to the command line after all other flags added by the build system.")
351-
include(AllTargetsCompileOptions)
334+
set(SECP256K1_APPEND_CFLAGS "" CACHE STRING "Compiler flags that are appended to the command line after all other flags added by the build system. This variable is intended for debugging and special builds.")
335+
if(SECP256K1_APPEND_CFLAGS)
336+
# Appending to this low-level rule variable is the only way to
337+
# guarantee that the flags appear at the end of the command line.
338+
string(APPEND CMAKE_C_COMPILE_OBJECT " ${SECP256K1_APPEND_CFLAGS}")
339+
endif()
352340

353341
add_subdirectory(src)
354-
all_targets_compile_options(src "${SECP256K1_LATE_CFLAGS}")
355342
if(SECP256K1_BUILD_EXAMPLES)
356343
add_subdirectory(examples)
357-
all_targets_compile_options(examples "${SECP256K1_LATE_CFLAGS}")
358344
endif()
359345

360346
message("\n")
@@ -436,8 +422,8 @@ else()
436422
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
437423
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
438424
endif()
439-
if(SECP256K1_LATE_CFLAGS)
440-
message("SECP256K1_LATE_CFLAGS ................. ${SECP256K1_LATE_CFLAGS}")
425+
if(SECP256K1_APPEND_CFLAGS)
426+
message("SECP256K1_APPEND_CFLAGS ............... ${SECP256K1_APPEND_CFLAGS}")
441427
endif()
442428
message("")
443429
if(print_msan_notice)

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ In addition, libsecp256k1 tries to maintain the following coding conventions:
4949
* 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)).
5050
* Local variables containing secret data should be cleared explicitly to try to delete secrets from memory.
5151
* Use `secp256k1_memcmp_var` instead of `memcmp` (see [#823](https://github.com/bitcoin-core/secp256k1/issues/823)).
52+
* As a rule of thumb, the default values for configuration options should target standard desktop machines and align with Bitcoin Core's defaults, and the tests should mostly exercise the default configuration (see [#1549](https://github.com/bitcoin-core/secp256k1/issues/1549#issuecomment-2200559257)).
5253

5354
#### Style conventions
5455

Makefile.am

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,17 @@ schnorr_example_LDFLAGS += -lbcrypt
186186
endif
187187
TESTS += schnorr_example
188188
endif
189+
if ENABLE_MODULE_ELLSWIFT
190+
noinst_PROGRAMS += ellswift_example
191+
ellswift_example_SOURCES = examples/ellswift.c
192+
ellswift_example_CPPFLAGS = -I$(top_srcdir)/include -DSECP256K1_STATIC
193+
ellswift_example_LDADD = libsecp256k1.la
194+
ellswift_example_LDFLAGS = -static
195+
if BUILD_WINDOWS
196+
ellswift_example_LDFLAGS += -lbcrypt
197+
endif
198+
TESTS += ellswift_example
199+
endif
189200
if ENABLE_MODULE_MUSIG
190201
noinst_PROGRAMS += musig_example
191202
musig_example_SOURCES = examples/musig.c

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ To maintain a pristine source tree, CMake encourages to perform an out-of-source
4040
$ cmake ..
4141
$ cmake --build .
4242
$ ctest # run the test suite
43-
$ sudo cmake --build . --target install # optional
43+
$ sudo cmake --install . # optional
4444

4545
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.
4646

@@ -73,6 +73,7 @@ Usage examples can be found in the [examples](examples) directory. To compile th
7373
* [ECDSA example](examples/ecdsa.c)
7474
* [Schnorr signatures example](examples/schnorr.c)
7575
* [Deriving a shared secret (ECDH) example](examples/ecdh.c)
76+
* [ElligatorSwift key exchange example](examples/ellswift.c)
7677
* [MuSig example](examples/musig.c)
7778

7879
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`.

cmake/AllTargetsCompileOptions.cmake

Lines changed: 0 additions & 12 deletions
This file was deleted.

configure.ac

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -251,22 +251,22 @@ AC_ARG_WITH([test-override-wide-multiply], [] ,[set_widemul=$withval], [set_wide
251251
AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|arm32|no|auto],
252252
[assembly to use (experimental: arm32) [default=auto]])],[req_asm=$withval], [req_asm=auto])
253253

254-
AC_ARG_WITH([ecmult-window], [AS_HELP_STRING([--with-ecmult-window=SIZE|auto],
254+
AC_ARG_WITH([ecmult-window], [AS_HELP_STRING([--with-ecmult-window=SIZE],
255255
[window size for ecmult precomputation for verification, specified as integer in range [2..24].]
256256
[Larger values result in possibly better performance at the cost of an exponentially larger precomputed table.]
257257
[The table will store 2^(SIZE-1) * 64 bytes of data but can be larger in memory due to platform-specific padding and alignment.]
258258
[A window size larger than 15 will require you delete the prebuilt precomputed_ecmult.c file so that it can be rebuilt.]
259259
[For very large window sizes, use "make -j 1" to reduce memory use during compilation.]
260-
["auto" is a reasonable setting for desktop machines (currently 15). [default=auto]]
260+
[The default value is a reasonable setting for desktop machines (currently 15). [default=15]]
261261
)],
262-
[req_ecmult_window=$withval], [req_ecmult_window=auto])
262+
[set_ecmult_window=$withval], [set_ecmult_window=15])
263263

264-
AC_ARG_WITH([ecmult-gen-kb], [AS_HELP_STRING([--with-ecmult-gen-kb=2|22|86|auto],
264+
AC_ARG_WITH([ecmult-gen-kb], [AS_HELP_STRING([--with-ecmult-gen-kb=2|22|86],
265265
[The size of the precomputed table for signing in multiples of 1024 bytes (on typical platforms).]
266266
[Larger values result in possibly better signing/keygeneration performance at the cost of a larger table.]
267-
["auto" is a reasonable setting for desktop machines (currently 22). [default=auto]]
267+
[The default value is a reasonable setting for desktop machines (currently 86). [default=86]]
268268
)],
269-
[req_ecmult_gen_kb=$withval], [req_ecmult_gen_kb=auto])
269+
[set_ecmult_gen_kb=$withval], [set_ecmult_gen_kb=86])
270270

271271
AC_ARG_WITH([valgrind], [AS_HELP_STRING([--with-valgrind=yes|no|auto],
272272
[Build with extra checks for running inside Valgrind [default=auto]]
@@ -409,14 +409,7 @@ auto)
409409
;;
410410
esac
411411

412-
# Set ecmult window size
413-
if test x"$req_ecmult_window" = x"auto"; then
414-
set_ecmult_window=15
415-
else
416-
set_ecmult_window=$req_ecmult_window
417-
fi
418-
419-
error_window_size=['window size for ecmult precomputation not an integer in range [2..24] or "auto"']
412+
error_window_size=['window size for ecmult precomputation not an integer in range [2..24]']
420413
case $set_ecmult_window in
421414
''|*[[!0-9]]*)
422415
# no valid integer
@@ -431,13 +424,6 @@ case $set_ecmult_window in
431424
;;
432425
esac
433426

434-
# Set ecmult gen kb
435-
if test x"$req_ecmult_gen_kb" = x"auto"; then
436-
set_ecmult_gen_kb=22
437-
else
438-
set_ecmult_gen_kb=$req_ecmult_gen_kb
439-
fi
440-
441427
case $set_ecmult_gen_kb in
442428
2)
443429
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DCOMB_BLOCKS=2 -DCOMB_TEETH=5"
@@ -449,7 +435,7 @@ case $set_ecmult_gen_kb in
449435
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DCOMB_BLOCKS=43 -DCOMB_TEETH=6"
450436
;;
451437
*)
452-
AC_MSG_ERROR(['ecmult gen table size not 2, 22, 86 or "auto"'])
438+
AC_MSG_ERROR(['ecmult gen table size not 2, 22 or 86'])
453439
;;
454440
esac
455441

0 commit comments

Comments
 (0)