Skip to content

Commit 2bfd600

Browse files
committed
Squashed 'src/secp256k1/' changes from 0270b14309..92f592023f
92f592023f ci: enable silentpayments module 8ddc4574c9 tests: add BIP-352 test vectors 8315abd830 silentpayments: add benchmark for `scan_outputs` f3a9516ec8 silentpayments: add examples/silentpayments.c 7e11e7613b silentpayments: add recipient light client support 3321771b0e silentpayments: add recipient scanning routine 766567f099 silentpayments: add opaque data type `public_data` 8d0bb06ce7 silentpayments: add recipient label support 9c9bd057bc silentpayments: add sender routine 036e688fd0 silentpayments: implement output pubkey creation 1ffee123d6 silentpayments: implement shared secret creation 7a5683260c silentpayments: add sortable recipient struct a8d6f4b8e1 doc: add module description for silentpayments 1121a4d376 build: add skeleton for new silentpayments (BIP352) module 7d2591ce12 Add secp256k1_pubkey_sort da515074e3 Merge bitcoin-core/secp256k1#1058: Signed-digit multi-comb ecmult_gen algorithm 4c341f89ab Add changelog entry for SDMC a043940253 Permit COMB_BITS < 256 for exhaustive tests 39b2f2a321 Add test case for ecmult_gen recoded = {-1,0,1} 644e86de9a Reintroduce projective blinding 07810d9abb Reduce side channels from single-bit reads a0d32b597d Optimization: use Nx32 representation for recoded bits e03dcc44b5 Make secp256k1_scalar_get_bits support 32-bit reads 5005abee60 Rename scalar_get_bits -> scalar_get_bits_limb32; return uint32_t 6247f485b6 Optimization: avoid unnecessary doublings in precomputation 15d0cca2a6 Optimization: first table lookup needs no point addition 7a33db35cd Optimization: move (2^COMB_BITS-1)/2 term into ctx->scalar_offset ed2a056f3d Provide 3 configurations accessible through ./configure 5f7be9f6a5 Always generate tables for current (blocks,teeth) config fde1dfcd8d Signed-digit multi-comb ecmult_gen algorithm 486518b350 Make exhaustive tests's scalar_inverse(&x,&x) work ab45c3e089 Initial gej blinding -> final ge blinding aa00a6b892 Introduce CEIL_DIV macro and use it REVERT: 0270b14309 labels: actually set the label REVERT: 3d08027789 ci: enable silentpayments module REVERT: 85946762a5 tests: add BIP-352 test vectors REVERT: bf349c2a08 silentpayments: add examples/silentpayments.c REVERT: 9a7106e19c silentpayments: add recipient light client support REVERT: f113564298 silentpayments: add recipient scanning routine REVERT: 4fb8716f4f silentpayments: add opaque data type `public_data` REVERT: 987d829e8f silentpayments: add recipient label support REVERT: 14ca754578 silentpayments: add sender routine REVERT: 9b965927da silentpayments: implement output pubkey creation REVERT: a0fcc2c780 silentpayments: implement shared secret creation REVERT: 13f203dacd silentpayments: add sortable recipient struct REVERT: a9326bdd7a doc: add module description for silentpayments REVERT: 15d3e71cc1 build: add skeleton for new silentpayments (BIP352) module REVERT: cc7d18a8a8 extrakeys: add secp256k1_pubkey_sort git-subtree-dir: src/secp256k1 git-subtree-split: 92f592023f3f4d6a66724772349fbdc4967ab50f
1 parent 7607d3c commit 2bfd600

35 files changed

+4158
-11441
lines changed

.cirrus.yml

+1-1
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

.github/workflows/ci.yml

+9-9
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'
@@ -84,8 +84,8 @@ jobs:
8484
- env_vars: { CPPFLAGS: '-DDETERMINISTIC' }
8585
- env_vars: { CFLAGS: '-O0', CTIMETESTS: 'no' }
8686
- env_vars: { CFLAGS: '-O1', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', SILENTPAYMENTS: 'yes' }
87-
- env_vars: { ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 }
88-
- env_vars: { ECMULTGENPRECISION: 8, ECMULTWINDOW: 4 }
87+
- env_vars: { ECMULTGENKB: 2, ECMULTWINDOW: 2 }
88+
- env_vars: { ECMULTGENKB: 86, ECMULTWINDOW: 4 }
8989
cc:
9090
- 'gcc'
9191
- 'clang'
@@ -383,8 +383,8 @@ jobs:
383383
configuration:
384384
- env_vars: { CC: 'clang', ASM: 'auto' }
385385
- env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'auto' }
386-
- env_vars: { CC: 'clang', ASM: 'no', ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 }
387-
- env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'no', ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 }
386+
- env_vars: { CC: 'clang', ASM: 'no', ECMULTGENKB: 2, ECMULTWINDOW: 2 }
387+
- env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'no', ECMULTGENKB: 2, ECMULTWINDOW: 2 }
388388

389389
env:
390390
# The `--error-exitcode` is required to make the test fail if valgrind found errors,
@@ -438,8 +438,8 @@ jobs:
438438
configuration:
439439
- env_vars: { CC: 'clang', ASM: 'auto' }
440440
- env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'auto' }
441-
- env_vars: { CC: 'clang', ASM: 'no', ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 }
442-
- env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'no', ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 }
441+
- env_vars: { CC: 'clang', ASM: 'no', ECMULTGENKB: 2, ECMULTWINDOW: 2 }
442+
- env_vars: { CC: 'i686-linux-gnu-gcc', HOST: 'i686-linux-gnu', ASM: 'no', ECMULTGENKB: 2, ECMULTWINDOW: 2 }
443443

444444
env:
445445
ECDH: 'yes'
@@ -495,7 +495,7 @@ jobs:
495495
- env_vars:
496496
CFLAGS: '-fsanitize=memory -fsanitize-recover=memory -g'
497497
- env_vars:
498-
ECMULTGENPRECISION: 2
498+
ECMULTGENKB: 2
499499
ECMULTWINDOW: 2
500500
CFLAGS: '-fsanitize=memory -fsanitize-recover=memory -g -O3'
501501

@@ -610,7 +610,7 @@ jobs:
610610
matrix:
611611
env_vars:
612612
- { WIDEMUL: 'int64', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', SILENTPAYMENTS: 'yes' }
613-
- { WIDEMUL: 'int128_struct', ECMULTGENPRECISION: 2, ECMULTWINDOW: 4 }
613+
- { WIDEMUL: 'int128_struct', ECMULTGENKB: 2, ECMULTWINDOW: 4 }
614614
- { WIDEMUL: 'int128', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', SILENTPAYMENTS: 'yes' }
615615
- { WIDEMUL: 'int128', RECOVERY: 'yes' }
616616
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', SILENTPAYMENTS: 'yes' }

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
#### Added
11+
- New function `secp256k1_ec_pubkey_sort` that sorts public keys using lexicographic (of compressed serialization) order.
12+
13+
#### Changed
14+
- The implementation of the point multiplication algorithm used for signing and public key generation was changed, resulting in improved performance for those operations.
15+
- The related configure option `--ecmult-gen-precision` was replaced with `--ecmult-gen-kb` (`ECMULT_GEN_KB` for CMake).
16+
- 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).
17+
1018
## [0.4.1] - 2023-12-21
1119

1220
#### Changed

CMakeLists.txt

+16-7
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,22 @@ if(SECP256K1_ECMULT_WINDOW_SIZE STREQUAL "AUTO")
106106
endif()
107107
add_compile_definitions(ECMULT_WINDOW_SIZE=${SECP256K1_ECMULT_WINDOW_SIZE})
108108

109-
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]")
110-
set_property(CACHE SECP256K1_ECMULT_GEN_PREC_BITS PROPERTY STRINGS "AUTO" 2 4 8)
111-
check_string_option_value(SECP256K1_ECMULT_GEN_PREC_BITS)
112-
if(SECP256K1_ECMULT_GEN_PREC_BITS STREQUAL "AUTO")
113-
set(SECP256K1_ECMULT_GEN_PREC_BITS 4)
109+
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]")
110+
set_property(CACHE SECP256K1_ECMULT_GEN_KB PROPERTY STRINGS "AUTO" 2 22 86)
111+
check_string_option_value(SECP256K1_ECMULT_GEN_KB)
112+
if(SECP256K1_ECMULT_GEN_KB STREQUAL "AUTO")
113+
set(SECP256K1_ECMULT_GEN_KB 22)
114+
endif()
115+
if(SECP256K1_ECMULT_GEN_KB EQUAL 2)
116+
add_compile_definitions(COMB_BLOCKS=2)
117+
add_compile_definitions(COMB_TEETH=5)
118+
elseif(SECP256K1_ECMULT_GEN_KB EQUAL 22)
119+
add_compile_definitions(COMB_BLOCKS=11)
120+
add_compile_definitions(COMB_TEETH=6)
121+
elseif(SECP256K1_ECMULT_GEN_KB EQUAL 86)
122+
add_compile_definitions(COMB_BLOCKS=43)
123+
add_compile_definitions(COMB_TEETH=6)
114124
endif()
115-
add_compile_definitions(ECMULT_GEN_PREC_BITS=${SECP256K1_ECMULT_GEN_PREC_BITS})
116125

117126
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]")
118127
set_property(CACHE SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY PROPERTY STRINGS "OFF" "int128_struct" "int128" "int64")
@@ -300,7 +309,7 @@ message(" ElligatorSwift ...................... ${SECP256K1_ENABLE_MODULE_ELLSW
300309
message(" Silent Payments ..................... ${SECP256K1_ENABLE_MODULE_SILENTPAYMENTS}")
301310
message("Parameters:")
302311
message(" ecmult window size .................. ${SECP256K1_ECMULT_WINDOW_SIZE}")
303-
message(" ecmult gen precision bits ........... ${SECP256K1_ECMULT_GEN_PREC_BITS}")
312+
message(" ecmult gen table size ............... ${SECP256K1_ECMULT_GEN_KB} KiB")
304313
message("Optional features:")
305314
message(" assembly ............................ ${SECP256K1_ASM}")
306315
message(" external callbacks .................. ${SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS}")

ci/ci.sh

+2-2
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 SILENTPAYMENTS \
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-silentpayments="$SILENTPAYMENTS" \

configure.ac

+20-15
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,12 @@ AC_ARG_WITH([ecmult-window], [AS_HELP_STRING([--with-ecmult-window=SIZE|auto],
217217
)],
218218
[req_ecmult_window=$withval], [req_ecmult_window=auto])
219219

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

228227
AC_ARG_WITH([valgrind], [AS_HELP_STRING([--with-valgrind=yes|no|auto],
229228
[Build with extra checks for running inside Valgrind [default=auto]]
@@ -362,19 +361,25 @@ case $set_ecmult_window in
362361
;;
363362
esac
364363

365-
# Set ecmult gen precision
366-
if test x"$req_ecmult_gen_precision" = x"auto"; then
367-
set_ecmult_gen_precision=4
364+
# Set ecmult gen kb
365+
if test x"$req_ecmult_gen_kb" = x"auto"; then
366+
set_ecmult_gen_kb=22
368367
else
369-
set_ecmult_gen_precision=$req_ecmult_gen_precision
368+
set_ecmult_gen_kb=$req_ecmult_gen_kb
370369
fi
371370

372-
case $set_ecmult_gen_precision in
373-
2|4|8)
374-
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DECMULT_GEN_PREC_BITS=$set_ecmult_gen_precision"
371+
case $set_ecmult_gen_kb in
372+
2)
373+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DCOMB_BLOCKS=2 -DCOMB_TEETH=5"
374+
;;
375+
22)
376+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DCOMB_BLOCKS=11 -DCOMB_TEETH=6"
377+
;;
378+
86)
379+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DCOMB_BLOCKS=43 -DCOMB_TEETH=6"
375380
;;
376381
*)
377-
AC_MSG_ERROR(['ecmult gen precision not 2, 4, 8 or "auto"'])
382+
AC_MSG_ERROR(['ecmult gen table size not 2, 22, 86 or "auto"'])
378383
;;
379384
esac
380385

@@ -485,7 +490,7 @@ echo " module silentpayments = $enable_module_silentpayments"
485490
echo
486491
echo " asm = $set_asm"
487492
echo " ecmult window size = $set_ecmult_window"
488-
echo " ecmult gen prec. bits = $set_ecmult_gen_precision"
493+
echo " ecmult gen table size = $set_ecmult_gen_kb KiB"
489494
# Hide test-only options unless they're used.
490495
if test x"$set_widemul" != xauto; then
491496
echo " wide multiplication = $set_widemul"

include/secp256k1.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ 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 keys using lexicographic (of compressed serialization) order
477+
/** Sort public keys using lexicographic (of compressed serialization) order
478478
*
479479
* Returns: 0 if the arguments are invalid. 1 otherwise.
480480
*

0 commit comments

Comments
 (0)