Skip to content

Commit 937a8c2

Browse files
committed
Make COMB_BLOCKS and COMB_TEETH configurable, and test in Cirrus
1 parent 63d2cf5 commit 937a8c2

File tree

4 files changed

+72
-21
lines changed

4 files changed

+72
-21
lines changed

.cirrus.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
env:
22
WIDEMUL: auto
33
STATICPRECOMPUTATION: yes
4-
ECMULTGENPRECISION: auto
4+
ECMULTGENBLOCKS: auto
5+
ECMULTGENTEETH: auto
56
ASM: no
67
BUILD: check
78
WITH_VALGRIND: yes
@@ -73,8 +74,9 @@ task:
7374
EXPERIMENTAL: yes
7475
SCHNORRSIG: yes
7576
CTIMETEST: no
76-
- env: { ECMULTGENPRECISION: 2 }
77-
- env: { ECMULTGENPRECISION: 8 }
77+
- env: { ECMULTGENBLOCKS: 256, ECMULTGENTEETH: 1 }
78+
- env: { ECMULTGENBLOCKS: 43, ECMULTGENTEETH: 6, STATICPRECOMPUTATION: no }
79+
- env: { ECMULTGENBLOCKS: 1, ECMULTGENTEETH: 1, STATICPRECOMPUTATION: no }
7880
- env:
7981
RUN_VALGRIND: yes
8082
ASM: x86_64

ci/cirrus.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ valgrind --version || true
1515
./configure \
1616
--enable-experimental="$EXPERIMENTAL" \
1717
--with-test-override-wide-multiply="$WIDEMUL" --with-asm="$ASM" \
18-
--enable-ecmult-static-precomputation="$STATICPRECOMPUTATION" --with-ecmult-gen-precision="$ECMULTGENPRECISION" \
18+
--enable-ecmult-static-precomputation="$STATICPRECOMPUTATION" --with-ecmult-gen-blocks="$ECMULTGENBLOCKS" --with-ecmult-gen-teeth="$ECMULTGENTEETH" \
1919
--enable-module-ecdh="$ECDH" --enable-module-recovery="$RECOVERY" \
2020
--enable-module-schnorrsig="$SCHNORRSIG" \
2121
--with-valgrind="$WITH_VALGRIND" \

configure.ac

+49-14
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,21 @@ AC_ARG_WITH([ecmult-window], [AS_HELP_STRING([--with-ecmult-window=SIZE|auto],
170170
)],
171171
[req_ecmult_window=$withval], [req_ecmult_window=auto])
172172

173-
AC_ARG_WITH([ecmult-gen-precision], [AS_HELP_STRING([--with-ecmult-gen-precision=2|4|8|auto],
174-
[Precision bits to tune the precomputed table size for signing.]
175-
[The size of the table is 32kB for 2 bits, 64kB for 4 bits, 512kB for 8 bits of precision.]
176-
[A larger table size usually results in possible faster signing.]
173+
AC_ARG_WITH([ecmult-gen-blocks], [AS_HELP_STRING([--with-ecmult-gen-blocks=BLOCKS|auto],
174+
[The number of blocks to use in the multi-comb multiplication algorithm, in the range [1..256].]
175+
[Larger values result in possibly better performance at the cost of a linearly larger precomputed table.]
176+
[There must exist a multiple of BLOCKS*TEETH that is between 256 and 288, inclusive.]
177177
["auto" is a reasonable setting for desktop machines (currently 4). [default=auto]]
178178
)],
179-
[req_ecmult_gen_precision=$withval], [req_ecmult_gen_precision=auto])
179+
[req_ecmult_gen_blocks=$withval], [req_ecmult_gen_blocks=auto])
180+
181+
AC_ARG_WITH([ecmult-gen-teeth], [AS_HELP_STRING([--with-ecmult-gen-teeth=TEETH|auto],
182+
[The number of teeth to use in the multi-comb multiplication algorithm, in the range [1..8].]
183+
[Larger values result in possibly better performance at the cost of an exponentially larger precomputed table.]
184+
[There must exist a multiple of BLOCKS*TEETH that is between 256 and 288, inclusive.]
185+
["auto" is a reasonable setting for desktop machines (currently 5). [default=auto]]
186+
)],
187+
[req_ecmult_gen_teeth=$withval], [req_ecmult_gen_teeth=auto])
180188

181189
AC_ARG_WITH([valgrind], [AS_HELP_STRING([--with-valgrind=yes|no|auto],
182190
[Build with extra checks for running inside Valgrind [default=auto]]
@@ -296,19 +304,45 @@ case $set_ecmult_window in
296304
;;
297305
esac
298306

299-
# Set ecmult gen precision
300-
if test x"$req_ecmult_gen_precision" = x"auto"; then
301-
set_ecmult_gen_precision=4
307+
# Set ecmult gen blocks
308+
if test x"$req_ecmult_gen_blocks" = x"auto"; then
309+
set_ecmult_gen_blocks=4
302310
else
303-
set_ecmult_gen_precision=$req_ecmult_gen_precision
311+
set_ecmult_gen_blocks=$req_ecmult_gen_blocks
304312
fi
313+
error_gen_blocks=['option to --with-ecmult-gen-blocks not an integer in range [1..256] or "auto"']
314+
case $set_ecmult_gen_blocks in
315+
''|*[[!0-9]]*)
316+
# no valid integer
317+
AC_MSG_ERROR($error_gen_blocks)
318+
;;
319+
*)
320+
if test "$set_ecmult_gen_blocks" -lt 1 -o "$set_ecmult_gen_blocks" -gt 256 ; then
321+
# not in range
322+
AC_MSG_ERROR($error_gen_blocks)
323+
fi
324+
AC_DEFINE_UNQUOTED(COMB_BLOCKS, $set_ecmult_gen_blocks, [Set number of blocks in ecmult_gen precomputation])
325+
;;
326+
esac
305327

306-
case $set_ecmult_gen_precision in
307-
2|4|8)
308-
AC_DEFINE_UNQUOTED(ECMULT_GEN_PREC_BITS, $set_ecmult_gen_precision, [Set ecmult gen precision bits])
328+
#set ecmult gen teeth
329+
if test x"$req_ecmult_gen_teeth" = x"auto"; then
330+
set_ecmult_gen_teeth=5
331+
else
332+
set_ecmult_gen_teeth=$req_ecmult_gen_teeth
333+
fi
334+
error_gen_teeth=['option to --with-ecmult-gen-teeth not an integer in range [1..8] or "auto"']
335+
case $set_ecmult_gen_teeth in
336+
''|*[[!0-9]]*)
337+
# no valid integer
338+
AC_MSG_ERROR($error_gen_teeth)
309339
;;
310340
*)
311-
AC_MSG_ERROR(['ecmult gen precision not 2, 4, 8 or "auto"'])
341+
if test "$set_ecmult_gen_teeth" -lt 1 -o "$set_ecmult_gen_teeth" -gt 8 ; then
342+
# not in range
343+
AC_MSG_ERROR($error_gen_teeth)
344+
fi
345+
AC_DEFINE_UNQUOTED(COMB_TEETH, $set_ecmult_gen_teeth, [Set number of teeth in ecmult_gen precomputation])
312346
;;
313347
esac
314348

@@ -515,7 +549,8 @@ echo " module schnorrsig = $enable_module_schnorrsig"
515549
echo
516550
echo " asm = $set_asm"
517551
echo " ecmult window size = $set_ecmult_window"
518-
echo " ecmult gen prec. bits = $set_ecmult_gen_precision"
552+
echo " ecmult gen blocks = $set_ecmult_gen_blocks"
553+
echo " ecmult gen teeth = $set_ecmult_gen_teeth"
519554
# Hide test-only options unless they're used.
520555
if test x"$set_widemul" != xauto; then
521556
echo " wide multiplication = $set_widemul"

src/ecmult_gen.h

+17-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@
1010
#include "scalar.h"
1111
#include "group.h"
1212

13+
#if defined HAVE_CONFIG_H
14+
#include "libsecp256k1-config.h"
15+
#endif
16+
1317
#if defined(EXHAUSTIVE_TEST_ORDER)
1418

1519
/* We need to control these values for exhaustive tests because
1620
* the tables cannot have infinities in them (secp256k1_ge_storage
1721
* doesn't support infinities) */
22+
#undef COMB_BLOCKS
23+
#undef COMB_TEETH
24+
#undef COMB_SPACING
25+
1826
# if EXHAUSTIVE_TEST_ORDER > 32
1927
# define COMB_BLOCKS 52
2028
# define COMB_TEETH 5
@@ -39,9 +47,15 @@
3947
/* COMB_BLOCKS, COMB_TEETH, COMB_SPACING must all be positive and the product of the three (COMB_BITS)
4048
* must evaluate to a value in the range [256, 288]. The resulting memory usage for precomputation
4149
* will be COMB_POINTS_TOTAL * sizeof(secp256k1_ge_storage). */
42-
#define COMB_BLOCKS 4
43-
#define COMB_TEETH 5
44-
#define COMB_SPACING 13
50+
# ifndef COMB_BLOCKS
51+
# define COMB_BLOCKS 4
52+
# endif
53+
# ifndef COMB_TEETH
54+
# define COMB_TEETH 5
55+
# endif
56+
# ifndef COMB_SPACING
57+
# define COMB_SPACING ((COMB_BLOCKS * COMB_TEETH + 255) / (COMB_BLOCKS * COMB_TEETH))
58+
# endif
4559

4660
#endif
4761

0 commit comments

Comments
 (0)