Skip to content

Commit 4935a46

Browse files
committed
Make COMB_BLOCKS and COMB_TEETH configurable, and test in Cirrus
1 parent 6d6d31a commit 4935a46

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
@@ -2,7 +2,8 @@ env:
22
WIDEMUL: auto
33
BIGNUM: auto
44
STATICPRECOMPUTATION: yes
5-
ECMULTGENPRECISION: auto
5+
ECMULTGENBLOCKS: auto
6+
ECMULTGENTEETH: auto
67
ASM: no
78
BUILD: check
89
WITH_VALGRIND: yes
@@ -64,8 +65,9 @@ task:
6465
EXPERIMENTAL: yes
6566
SCHNORRSIG: yes
6667
CTIMETEST: no
67-
- env: { ECMULTGENPRECISION: 2 }
68-
- env: { ECMULTGENPRECISION: 8 }
68+
- env: { ECMULTGENBLOCKS: 256, ECMULTGENTEETH: 1 }
69+
- env: { ECMULTGENBLOCKS: 43, ECMULTGENTEETH: 6, STATICPRECOMPUTATION: no }
70+
- env: { ECMULTGENBLOCKS: 1, ECMULTGENTEETH: 1, STATICPRECOMPUTATION: no }
6971
- env:
7072
RUN_VALGRIND: yes
7173
BIGNUM: no

ci/cirrus.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ sed -i'' -e 's@/usr/bin/file@$(which file)@g' configure
1919
./configure \
2020
--enable-experimental="$EXPERIMENTAL" \
2121
--with-test-override-wide-multiply="$WIDEMUL" --with-bignum="$BIGNUM" --with-asm="$ASM" \
22-
--enable-ecmult-static-precomputation="$STATICPRECOMPUTATION" --with-ecmult-gen-precision="$ECMULTGENPRECISION" \
22+
--enable-ecmult-static-precomputation="$STATICPRECOMPUTATION" --with-ecmult-gen-blocks="$ECMULTGENBLOCKS" --with-ecmult-gen-teeth="$ECMULTGENTEETH" \
2323
--enable-module-ecdh="$ECDH" --enable-module-recovery="$RECOVERY" \
2424
--enable-module-schnorrsig="$SCHNORRSIG" \
2525
--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]]
@@ -340,19 +348,45 @@ case $set_ecmult_window in
340348
;;
341349
esac
342350

343-
# Set ecmult gen precision
344-
if test x"$req_ecmult_gen_precision" = x"auto"; then
345-
set_ecmult_gen_precision=4
351+
# Set ecmult gen blocks
352+
if test x"$req_ecmult_gen_blocks" = x"auto"; then
353+
set_ecmult_gen_blocks=4
346354
else
347-
set_ecmult_gen_precision=$req_ecmult_gen_precision
355+
set_ecmult_gen_blocks=$req_ecmult_gen_blocks
348356
fi
357+
error_gen_blocks=['option to --with-ecmult-gen-blocks not an integer in range [1..256] or "auto"']
358+
case $set_ecmult_gen_blocks in
359+
''|*[[!0-9]]*)
360+
# no valid integer
361+
AC_MSG_ERROR($error_gen_blocks)
362+
;;
363+
*)
364+
if test "$set_ecmult_gen_blocks" -lt 1 -o "$set_ecmult_gen_blocks" -gt 256 ; then
365+
# not in range
366+
AC_MSG_ERROR($error_gen_blocks)
367+
fi
368+
AC_DEFINE_UNQUOTED(COMB_BLOCKS, $set_ecmult_gen_blocks, [Set number of blocks in ecmult_gen precomputation])
369+
;;
370+
esac
349371

350-
case $set_ecmult_gen_precision in
351-
2|4|8)
352-
AC_DEFINE_UNQUOTED(ECMULT_GEN_PREC_BITS, $set_ecmult_gen_precision, [Set ecmult gen precision bits])
372+
#set ecmult gen teeth
373+
if test x"$req_ecmult_gen_teeth" = x"auto"; then
374+
set_ecmult_gen_teeth=5
375+
else
376+
set_ecmult_gen_teeth=$req_ecmult_gen_teeth
377+
fi
378+
error_gen_teeth=['option to --with-ecmult-gen-teeth not an integer in range [1..8] or "auto"']
379+
case $set_ecmult_gen_teeth in
380+
''|*[[!0-9]]*)
381+
# no valid integer
382+
AC_MSG_ERROR($error_gen_teeth)
353383
;;
354384
*)
355-
AC_MSG_ERROR(['ecmult gen precision not 2, 4, 8 or "auto"'])
385+
if test "$set_ecmult_gen_teeth" -lt 1 -o "$set_ecmult_gen_teeth" -gt 8 ; then
386+
# not in range
387+
AC_MSG_ERROR($error_gen_teeth)
388+
fi
389+
AC_DEFINE_UNQUOTED(COMB_TEETH, $set_ecmult_gen_teeth, [Set number of teeth in ecmult_gen precomputation])
356390
;;
357391
esac
358392

@@ -565,7 +599,8 @@ echo
565599
echo " asm = $set_asm"
566600
echo " bignum = $set_bignum"
567601
echo " ecmult window size = $set_ecmult_window"
568-
echo " ecmult gen prec. bits = $set_ecmult_gen_precision"
602+
echo " ecmult gen blocks = $set_ecmult_gen_blocks"
603+
echo " ecmult gen teeth = $set_ecmult_gen_teeth"
569604
# Hide test-only options unless they're used.
570605
if test x"$set_widemul" != xauto; then
571606
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)