Skip to content

Commit 0388dd7

Browse files
committed
Merge bitcoin/bitcoin#30120: Update libsecp256k1 subtree to current master
a057869 build: pass --with-ecmult-gen-kb=86 to secp256k1 (fanquake) ca3d945 Squashed 'src/secp256k1/' changes from d8311688bd..06bff6dec8 (fanquake) Pull request description: This includes changes from the 0.5.0 release: https://github.com/bitcoin-core/secp256k1/releases/tag/v0.5.0 > New function secp256k1_ec_pubkey_sort that sorts public keys using lexicographic (of compressed serialization) order. > The implementation of the point multiplication algorithm used for signing and public key generation was changed, resulting in improved performance for those operations. > The related configure option --ecmult-gen-precision was replaced with --ecmult-gen-kb (ECMULT_GEN_KB for CMake). > This changes the supported precomputed table sizes for these operations. The new supported sizes are 2 KiB, 22 KiB, or 86 KiB (while the old supported sizes were 32 KiB, 64 KiB, or 512 KiB). ACKs for top commit: hebasto: ACK a057869, I've got a zero diff with my local branch, which reproduces the subtree update, and `ecmult gen table size = 86 KiB` in the configure summary. jonasnick: utACK a057869 Tree-SHA512: 907012b0d7e0a6bd68b245c238e968f2318d8ac5de5ec9070245de8391c996eb5ec6428184d028f6f0f54d3b2f5a8292ad7081177e1c331397879505436dc38e
2 parents 2ec0a28 + a057869 commit 0388dd7

30 files changed

+2877
-9986
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,7 @@ CPPFLAGS="$CPPFLAGS_TEMP"
17711771
if test -n "$use_sanitizers"; then
17721772
export SECP_CFLAGS="$SECP_CFLAGS $SANITIZER_CFLAGS"
17731773
fi
1774-
ac_configure_args="${ac_configure_args} --disable-shared --with-pic --enable-benchmark=no --enable-module-recovery --disable-module-ecdh"
1774+
ac_configure_args="${ac_configure_args} --disable-shared --with-pic --with-ecmult-gen-kb=86 --enable-benchmark=no --enable-module-recovery --disable-module-ecdh"
17751775
AC_CONFIG_SUBDIRS([src/secp256k1])
17761776

17771777
AC_OUTPUT

src/secp256k1/.cirrus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ env:
1111
BUILD: check
1212
### secp256k1 config
1313
ECMULTWINDOW: auto
14-
ECMULTGENPRECISION: auto
14+
ECMULTGENKB: auto
1515
ASM: no
1616
WIDEMUL: auto
1717
WITH_VALGRIND: yes

src/secp256k1/.github/workflows/ci.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ env:
2222
BUILD: 'check'
2323
### secp256k1 config
2424
ECMULTWINDOW: 'auto'
25-
ECMULTGENPRECISION: 'auto'
25+
ECMULTGENKB: 'auto'
2626
ASM: 'no'
2727
WIDEMUL: 'auto'
2828
WITH_VALGRIND: 'yes'
@@ -83,8 +83,8 @@ jobs:
8383
- env_vars: { CPPFLAGS: '-DDETERMINISTIC' }
8484
- env_vars: { CFLAGS: '-O0', CTIMETESTS: 'no' }
8585
- env_vars: { CFLAGS: '-O1', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes' }
86-
- env_vars: { ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 }
87-
- env_vars: { ECMULTGENPRECISION: 8, ECMULTWINDOW: 4 }
86+
- env_vars: { ECMULTGENKB: 2, ECMULTWINDOW: 2 }
87+
- env_vars: { ECMULTGENKB: 86, ECMULTWINDOW: 4 }
8888
cc:
8989
- 'gcc'
9090
- 'clang'
@@ -377,8 +377,8 @@ jobs:
377377
configuration:
378378
- env_vars: { CC: 'clang', ASM: 'auto' }
379379
- env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'auto' }
380-
- env_vars: { CC: 'clang', ASM: 'no', ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 }
381-
- env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'no', ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 }
380+
- env_vars: { CC: 'clang', ASM: 'no', ECMULTGENKB: 2, ECMULTWINDOW: 2 }
381+
- env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'no', ECMULTGENKB: 2, ECMULTWINDOW: 2 }
382382

383383
env:
384384
# The `--error-exitcode` is required to make the test fail if valgrind found errors,
@@ -431,8 +431,8 @@ jobs:
431431
configuration:
432432
- env_vars: { CC: 'clang', ASM: 'auto' }
433433
- env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'auto' }
434-
- env_vars: { CC: 'clang', ASM: 'no', ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 }
435-
- env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'no', ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 }
434+
- env_vars: { CC: 'clang', ASM: 'no', ECMULTGENKB: 2, ECMULTWINDOW: 2 }
435+
- env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'no', ECMULTGENKB: 2, ECMULTWINDOW: 2 }
436436

437437
env:
438438
ECDH: 'yes'
@@ -487,7 +487,7 @@ jobs:
487487
- env_vars:
488488
CFLAGS: '-fsanitize=memory -fsanitize-recover=memory -g'
489489
- env_vars:
490-
ECMULTGENPRECISION: 2
490+
ECMULTGENKB: 2
491491
ECMULTWINDOW: 2
492492
CFLAGS: '-fsanitize=memory -fsanitize-recover=memory -g -O3'
493493

@@ -600,7 +600,7 @@ jobs:
600600
matrix:
601601
env_vars:
602602
- { WIDEMUL: 'int64', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes' }
603-
- { WIDEMUL: 'int128_struct', ECMULTGENPRECISION: 2, ECMULTWINDOW: 4 }
603+
- { WIDEMUL: 'int128_struct', ECMULTGENKB: 2, ECMULTWINDOW: 4 }
604604
- { WIDEMUL: 'int128', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes' }
605605
- { WIDEMUL: 'int128', RECOVERY: 'yes' }
606606
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes' }

src/secp256k1/CHANGELOG.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.5.0] - 2024-05-06
11+
12+
#### Added
13+
- New function `secp256k1_ec_pubkey_sort` that sorts public keys using lexicographic (of compressed serialization) order.
14+
15+
#### Changed
16+
- The implementation of the point multiplication algorithm used for signing and public key generation was changed, resulting in improved performance for those operations.
17+
- The related configure option `--ecmult-gen-precision` was replaced with `--ecmult-gen-kb` (`ECMULT_GEN_KB` for CMake).
18+
- This changes the supported precomputed table sizes for these operations. The new supported sizes are 2 KiB, 22 KiB, or 86 KiB (while the old supported sizes were 32 KiB, 64 KiB, or 512 KiB).
19+
20+
#### ABI Compatibility
21+
The ABI is backward compatible with versions 0.4.x and 0.3.x.
22+
1023
## [0.4.1] - 2023-12-21
1124

1225
#### Changed
@@ -115,7 +128,8 @@ This version was in fact never released.
115128
The number was given by the build system since the introduction of autotools in Jan 2014 (ea0fe5a5bf0c04f9cc955b2966b614f5f378c6f6).
116129
Therefore, this version number does not uniquely identify a set of source files.
117130

118-
[unreleased]: https://github.com/bitcoin-core/secp256k1/compare/v0.4.1...HEAD
131+
[unreleased]: https://github.com/bitcoin-core/secp256k1/compare/v0.5.0...HEAD
132+
[0.5.0]: https://github.com/bitcoin-core/secp256k1/compare/v0.4.1...v0.5.0
119133
[0.4.1]: https://github.com/bitcoin-core/secp256k1/compare/v0.4.0...v0.4.1
120134
[0.4.0]: https://github.com/bitcoin-core/secp256k1/compare/v0.3.2...v0.4.0
121135
[0.3.2]: https://github.com/bitcoin-core/secp256k1/compare/v0.3.1...v0.3.2

src/secp256k1/CMakeLists.txt

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ project(libsecp256k1
1111
# The package (a.k.a. release) version is based on semantic versioning 2.0.0 of
1212
# the API. All changes in experimental modules are treated as
1313
# backwards-compatible and therefore at most increase the minor version.
14-
VERSION 0.4.2
14+
VERSION 0.5.1
1515
DESCRIPTION "Optimized C library for ECDSA signatures and secret/public key operations on curve secp256k1."
1616
HOMEPAGE_URL "https://github.com/bitcoin-core/secp256k1"
1717
LANGUAGES C
@@ -34,9 +34,9 @@ endif()
3434
# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
3535
# All changes in experimental modules are treated as if they don't affect the
3636
# interface and therefore only increase the revision.
37-
set(${PROJECT_NAME}_LIB_VERSION_CURRENT 3)
38-
set(${PROJECT_NAME}_LIB_VERSION_REVISION 2)
39-
set(${PROJECT_NAME}_LIB_VERSION_AGE 1)
37+
set(${PROJECT_NAME}_LIB_VERSION_CURRENT 4)
38+
set(${PROJECT_NAME}_LIB_VERSION_REVISION 1)
39+
set(${PROJECT_NAME}_LIB_VERSION_AGE 2)
4040

4141
set(CMAKE_C_STANDARD 90)
4242
set(CMAKE_C_EXTENSIONS OFF)
@@ -101,13 +101,22 @@ if(SECP256K1_ECMULT_WINDOW_SIZE STREQUAL "AUTO")
101101
endif()
102102
add_compile_definitions(ECMULT_WINDOW_SIZE=${SECP256K1_ECMULT_WINDOW_SIZE})
103103

104-
set(SECP256K1_ECMULT_GEN_PREC_BITS "AUTO" CACHE STRING "Precision bits to tune the precomputed table size for signing, specified as integer 2, 4 or 8. \"AUTO\" is a reasonable setting for desktop machines (currently 4). [default=AUTO]")
105-
set_property(CACHE SECP256K1_ECMULT_GEN_PREC_BITS PROPERTY STRINGS "AUTO" 2 4 8)
106-
check_string_option_value(SECP256K1_ECMULT_GEN_PREC_BITS)
107-
if(SECP256K1_ECMULT_GEN_PREC_BITS STREQUAL "AUTO")
108-
set(SECP256K1_ECMULT_GEN_PREC_BITS 4)
104+
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]")
105+
set_property(CACHE SECP256K1_ECMULT_GEN_KB PROPERTY STRINGS "AUTO" 2 22 86)
106+
check_string_option_value(SECP256K1_ECMULT_GEN_KB)
107+
if(SECP256K1_ECMULT_GEN_KB STREQUAL "AUTO")
108+
set(SECP256K1_ECMULT_GEN_KB 22)
109+
endif()
110+
if(SECP256K1_ECMULT_GEN_KB EQUAL 2)
111+
add_compile_definitions(COMB_BLOCKS=2)
112+
add_compile_definitions(COMB_TEETH=5)
113+
elseif(SECP256K1_ECMULT_GEN_KB EQUAL 22)
114+
add_compile_definitions(COMB_BLOCKS=11)
115+
add_compile_definitions(COMB_TEETH=6)
116+
elseif(SECP256K1_ECMULT_GEN_KB EQUAL 86)
117+
add_compile_definitions(COMB_BLOCKS=43)
118+
add_compile_definitions(COMB_TEETH=6)
109119
endif()
110-
add_compile_definitions(ECMULT_GEN_PREC_BITS=${SECP256K1_ECMULT_GEN_PREC_BITS})
111120

112121
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]")
113122
set_property(CACHE SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY PROPERTY STRINGS "OFF" "int128_struct" "int128" "int64")
@@ -294,7 +303,7 @@ message(" schnorrsig .......................... ${SECP256K1_ENABLE_MODULE_SCHNO
294303
message(" ElligatorSwift ...................... ${SECP256K1_ENABLE_MODULE_ELLSWIFT}")
295304
message("Parameters:")
296305
message(" ecmult window size .................. ${SECP256K1_ECMULT_WINDOW_SIZE}")
297-
message(" ecmult gen precision bits ........... ${SECP256K1_ECMULT_GEN_PREC_BITS}")
306+
message(" ecmult gen table size ............... ${SECP256K1_ECMULT_GEN_KB} KiB")
298307
message("Optional features:")
299308
message(" assembly ............................ ${SECP256K1_ASM}")
300309
message(" external callbacks .................. ${SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS}")

src/secp256k1/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ noinst_HEADERS += src/field.h
6464
noinst_HEADERS += src/field_impl.h
6565
noinst_HEADERS += src/bench.h
6666
noinst_HEADERS += src/wycheproof/ecdsa_secp256k1_sha256_bitcoin_test.h
67+
noinst_HEADERS += src/hsort.h
68+
noinst_HEADERS += src/hsort_impl.h
6769
noinst_HEADERS += contrib/lax_der_parsing.h
6870
noinst_HEADERS += contrib/lax_der_parsing.c
6971
noinst_HEADERS += contrib/lax_der_privatekey_parsing.h

src/secp256k1/ci/ci.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ print_environment() {
1212
# There are many ways to print variable names and their content. This one
1313
# does not rely on bash.
1414
for var in WERROR_CFLAGS MAKEFLAGS BUILD \
15-
ECMULTWINDOW ECMULTGENPRECISION ASM WIDEMUL WITH_VALGRIND EXTRAFLAGS \
15+
ECMULTWINDOW ECMULTGENKB ASM WIDEMUL WITH_VALGRIND EXTRAFLAGS \
1616
EXPERIMENTAL ECDH RECOVERY SCHNORRSIG ELLSWIFT \
1717
SECP256K1_TEST_ITERS BENCH SECP256K1_BENCH_ITERS CTIMETESTS\
1818
EXAMPLES \
@@ -74,7 +74,7 @@ esac
7474
--enable-experimental="$EXPERIMENTAL" \
7575
--with-test-override-wide-multiply="$WIDEMUL" --with-asm="$ASM" \
7676
--with-ecmult-window="$ECMULTWINDOW" \
77-
--with-ecmult-gen-precision="$ECMULTGENPRECISION" \
77+
--with-ecmult-gen-kb="$ECMULTGENKB" \
7878
--enable-module-ecdh="$ECDH" --enable-module-recovery="$RECOVERY" \
7979
--enable-module-ellswift="$ELLSWIFT" \
8080
--enable-module-schnorrsig="$SCHNORRSIG" \
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function(check_arm32_assembly)
22
try_compile(HAVE_ARM32_ASM
3-
${CMAKE_BINARY_DIR}/check_arm32_assembly
4-
SOURCES ${CMAKE_SOURCE_DIR}/cmake/source_arm32.s
3+
${PROJECT_BINARY_DIR}/check_arm32_assembly
4+
SOURCES ${PROJECT_SOURCE_DIR}/cmake/source_arm32.s
55
)
66
endfunction()

src/secp256k1/configure.ac

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ AC_PREREQ([2.60])
44
# the API. All changes in experimental modules are treated as
55
# backwards-compatible and therefore at most increase the minor version.
66
define(_PKG_VERSION_MAJOR, 0)
7-
define(_PKG_VERSION_MINOR, 4)
8-
define(_PKG_VERSION_PATCH, 2)
7+
define(_PKG_VERSION_MINOR, 5)
8+
define(_PKG_VERSION_PATCH, 1)
99
define(_PKG_VERSION_IS_RELEASE, false)
1010

1111
# The library version is based on libtool versioning of the ABI. The set of
1212
# rules for updating the version can be found here:
1313
# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
1414
# All changes in experimental modules are treated as if they don't affect the
1515
# interface and therefore only increase the revision.
16-
define(_LIB_VERSION_CURRENT, 3)
17-
define(_LIB_VERSION_REVISION, 2)
18-
define(_LIB_VERSION_AGE, 1)
16+
define(_LIB_VERSION_CURRENT, 4)
17+
define(_LIB_VERSION_REVISION, 1)
18+
define(_LIB_VERSION_AGE, 2)
1919

2020
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])
2121

@@ -213,13 +213,12 @@ AC_ARG_WITH([ecmult-window], [AS_HELP_STRING([--with-ecmult-window=SIZE|auto],
213213
)],
214214
[req_ecmult_window=$withval], [req_ecmult_window=auto])
215215

216-
AC_ARG_WITH([ecmult-gen-precision], [AS_HELP_STRING([--with-ecmult-gen-precision=2|4|8|auto],
217-
[Precision bits to tune the precomputed table size for signing.]
218-
[The size of the table is 32kB for 2 bits, 64kB for 4 bits, 512kB for 8 bits of precision.]
219-
[A larger table size usually results in possible faster signing.]
220-
["auto" is a reasonable setting for desktop machines (currently 4). [default=auto]]
216+
AC_ARG_WITH([ecmult-gen-kb], [AS_HELP_STRING([--with-ecmult-gen-kb=2|22|86|auto],
217+
[The size of the precomputed table for signing in multiples of 1024 bytes (on typical platforms).]
218+
[Larger values result in possibly better signing/keygeneration performance at the cost of a larger table.]
219+
["auto" is a reasonable setting for desktop machines (currently 22). [default=auto]]
221220
)],
222-
[req_ecmult_gen_precision=$withval], [req_ecmult_gen_precision=auto])
221+
[req_ecmult_gen_kb=$withval], [req_ecmult_gen_kb=auto])
223222

224223
AC_ARG_WITH([valgrind], [AS_HELP_STRING([--with-valgrind=yes|no|auto],
225224
[Build with extra checks for running inside Valgrind [default=auto]]
@@ -358,19 +357,25 @@ case $set_ecmult_window in
358357
;;
359358
esac
360359

361-
# Set ecmult gen precision
362-
if test x"$req_ecmult_gen_precision" = x"auto"; then
363-
set_ecmult_gen_precision=4
360+
# Set ecmult gen kb
361+
if test x"$req_ecmult_gen_kb" = x"auto"; then
362+
set_ecmult_gen_kb=22
364363
else
365-
set_ecmult_gen_precision=$req_ecmult_gen_precision
364+
set_ecmult_gen_kb=$req_ecmult_gen_kb
366365
fi
367366

368-
case $set_ecmult_gen_precision in
369-
2|4|8)
370-
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DECMULT_GEN_PREC_BITS=$set_ecmult_gen_precision"
367+
case $set_ecmult_gen_kb in
368+
2)
369+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DCOMB_BLOCKS=2 -DCOMB_TEETH=5"
370+
;;
371+
22)
372+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DCOMB_BLOCKS=11 -DCOMB_TEETH=6"
373+
;;
374+
86)
375+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DCOMB_BLOCKS=43 -DCOMB_TEETH=6"
371376
;;
372377
*)
373-
AC_MSG_ERROR(['ecmult gen precision not 2, 4, 8 or "auto"'])
378+
AC_MSG_ERROR(['ecmult gen table size not 2, 22, 86 or "auto"'])
374379
;;
375380
esac
376381

@@ -475,7 +480,7 @@ echo " module ellswift = $enable_module_ellswift"
475480
echo
476481
echo " asm = $set_asm"
477482
echo " ecmult window size = $set_ecmult_window"
478-
echo " ecmult gen prec. bits = $set_ecmult_gen_precision"
483+
echo " ecmult gen table size = $set_ecmult_gen_kb KiB"
479484
# Hide test-only options unless they're used.
480485
if test x"$set_widemul" != xauto; then
481486
echo " wide multiplication = $set_widemul"

src/secp256k1/include/secp256k1.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,20 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_cmp(
474474
const secp256k1_pubkey *pubkey2
475475
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
476476

477+
/** Sort public keys using lexicographic (of compressed serialization) order
478+
*
479+
* Returns: 0 if the arguments are invalid. 1 otherwise.
480+
*
481+
* Args: ctx: pointer to a context object
482+
* In: pubkeys: array of pointers to pubkeys to sort
483+
* n_pubkeys: number of elements in the pubkeys array
484+
*/
485+
SECP256K1_API int secp256k1_ec_pubkey_sort(
486+
const secp256k1_context *ctx,
487+
const secp256k1_pubkey **pubkeys,
488+
size_t n_pubkeys
489+
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);
490+
477491
/** Parse an ECDSA signature in compact (64 bytes) format.
478492
*
479493
* Returns: 1 when the signature could be parsed, 0 otherwise.

0 commit comments

Comments
 (0)