Skip to content

Commit ed2a056

Browse files
committed
Provide 3 configurations accessible through ./configure
1 parent 5f7be9f commit ed2a056

File tree

7 files changed

+1462
-36
lines changed

7 files changed

+1462
-36
lines changed

.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

.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' }

CMakeLists.txt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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}")

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" \

configure.ac

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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/precompute_ecmult_gen.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
#include "ecmult_gen.h"
1818
#include "ecmult_gen_compute_table_impl.h"
1919

20-
static const int CONFIGS[1][2] = {
21-
{11, 6}
20+
static const int CONFIGS[][2] = {
21+
{2, 5},
22+
{11, 6},
23+
{43, 6}
2224
};
2325

2426
static void print_table(FILE* fp, int blocks, int teeth) {

0 commit comments

Comments
 (0)