Skip to content

Commit 026cbfb

Browse files
committed
Make COMB_BLOCKS, COMB_TEETH, COMB_NEGATION configurable, and test in Travis
1 parent 90d0b70 commit 026cbfb

File tree

4 files changed

+84
-22
lines changed

4 files changed

+84
-22
lines changed

.travis.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ compiler:
1717
- gcc
1818
env:
1919
global:
20-
- FIELD=auto BIGNUM=auto SCALAR=auto ENDOMORPHISM=no STATICPRECOMPUTATION=yes ECMULTGENPRECISION=auto ASM=no BUILD=check EXTRAFLAGS= HOST= ECDH=no RECOVERY=no EXPERIMENTAL=no CTIMETEST=yes BENCH=yes ITERS=2
20+
- FIELD=auto BIGNUM=auto SCALAR=auto ENDOMORPHISM=no STATICPRECOMPUTATION=yes ECMULTGENBLOCKS=auto ECMULTGENTEETH=auto ECMULTGENNEG=1 ASM=no BUILD=check EXTRAFLAGS= HOST= ECDH=no RECOVERY=no EXPERIMENTAL=no CTIMETEST=yes BENCH=yes ITERS=2
2121
matrix:
2222
- SCALAR=32bit RECOVERY=yes
2323
- SCALAR=32bit FIELD=32bit ECDH=yes EXPERIMENTAL=yes
@@ -34,8 +34,10 @@ env:
3434
- BUILD=distcheck CTIMETEST= BENCH=
3535
- CPPFLAGS=-DDETERMINISTIC
3636
- CFLAGS=-O0 CTIMETEST=
37-
- ECMULTGENPRECISION=2
38-
- ECMULTGENPRECISION=8
37+
- ECMULTGENBLOCKS=256 ECMULTGENTEETH=1 ENDOMORPHISM=yes
38+
- ECMULTGENBLOCKS=43 ECMULTGENTEETH=6 ENDOMORPHISM=yes STATICPRECOMPUTATION=no
39+
- ECMULTGENBLOCKS=1 ECMULTGENTEETH=1 STATICPRECOMPUTATION=no
40+
- ECMULTGENBLOCKS=4 ECMULTGENTEETH=5 ECMULTGENNEG=0
3941
- VALGRIND=yes ENDOMORPHISM=yes BIGNUM=no ASM=x86_64 EXPERIMENTAL=yes ECDH=yes RECOVERY=yes EXTRAFLAGS="--disable-openssl-tests" CPPFLAGS=-DVALGRIND BUILD=
4042
- VALGRIND=yes BIGNUM=no ASM=x86_64 EXPERIMENTAL=yes ECDH=yes RECOVERY=yes EXTRAFLAGS="--disable-openssl-tests" CPPFLAGS=-DVALGRIND BUILD=
4143
matrix:

configure.ac

+57-14
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,26 @@ AC_ARG_WITH([ecmult-window], [AS_HELP_STRING([--with-ecmult-window=SIZE|auto],
162162
)],
163163
[req_ecmult_window=$withval], [req_ecmult_window=auto])
164164

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

173186
AC_CHECK_TYPES([__int128])
174187

@@ -431,22 +444,50 @@ case $set_ecmult_window in
431444
;;
432445
esac
433446

434-
#set ecmult gen precision
435-
if test x"$req_ecmult_gen_precision" = x"auto"; then
436-
set_ecmult_gen_precision=4
447+
#set ecmult gen blocks
448+
if test x"$req_ecmult_gen_blocks" = x"auto"; then
449+
set_ecmult_gen_blocks=4
437450
else
438-
set_ecmult_gen_precision=$req_ecmult_gen_precision
451+
set_ecmult_gen_blocks=$req_ecmult_gen_blocks
439452
fi
453+
error_gen_blocks=['option to --with-ecmult-gen-blocks not an integer in range [1..256] or "auto"']
454+
case $set_ecmult_gen_blocks in
455+
''|*[[!0-9]]*)
456+
# no valid integer
457+
AC_MSG_ERROR($error_gen_blocks)
458+
;;
459+
*)
460+
if test "$set_ecmult_gen_blocks" -lt 1 -o "$set_ecmult_gen_blocks" -gt 256 ; then
461+
# not in range
462+
AC_MSG_ERROR($error_gen_blocks)
463+
fi
464+
AC_DEFINE_UNQUOTED(COMB_BLOCKS, $set_ecmult_gen_blocks, [Set number of blocks in ecmult_gen precomputation])
465+
;;
466+
esac
440467

441-
case $set_ecmult_gen_precision in
442-
2|4|8)
443-
AC_DEFINE_UNQUOTED(ECMULT_GEN_PREC_BITS, $set_ecmult_gen_precision, [Set ecmult gen precision bits])
468+
#set ecmult gen teeth
469+
if test x"$req_ecmult_gen_teeth" = x"auto"; then
470+
set_ecmult_gen_teeth=5
471+
else
472+
set_ecmult_gen_teeth=$req_ecmult_gen_teeth
473+
fi
474+
error_gen_teeth=['option to --with-ecmult-gen-teeth not an integer in range [1..8] or "auto"']
475+
case $set_ecmult_gen_teeth in
476+
''|*[[!0-9]]*)
477+
# no valid integer
478+
AC_MSG_ERROR($error_gen_teeth)
444479
;;
445480
*)
446-
AC_MSG_ERROR(['ecmult gen precision not 2, 4, 8 or "auto"'])
481+
if test "$set_ecmult_gen_teeth" -lt 1 -o "$set_ecmult_gen_teeth" -gt 8 ; then
482+
# not in range
483+
AC_MSG_ERROR($error_gen_teeth)
484+
fi
485+
AC_DEFINE_UNQUOTED(COMB_TEETH, $set_ecmult_gen_teeth, [Set number of teeth in ecmult_gen precomputation])
447486
;;
448487
esac
449488

489+
AC_DEFINE_UNQUOTED(COMB_NEGATION, $set_ecmult_gen_neg, [Set whether to use negation in ecmult_gen])
490+
450491
if test x"$use_tests" = x"yes"; then
451492
SECP_OPENSSL_CHECK
452493
if test x"$has_openssl_ec" = x"yes"; then
@@ -556,7 +597,9 @@ echo " bignum = $set_bignum"
556597
echo " field = $set_field"
557598
echo " scalar = $set_scalar"
558599
echo " ecmult window size = $set_ecmult_window"
559-
echo " ecmult gen prec. bits = $set_ecmult_gen_precision"
600+
echo " ecmult gen blocks = $set_ecmult_gen_blocks"
601+
echo " ecmult gen teeth = $set_ecmult_gen_teeth"
602+
echo " ecmult gen negation = $set_ecmult_gen_neg"
560603
echo
561604
echo " valgrind = $enable_valgrind"
562605
echo " CC = $CC"

contrib/travis.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fi
1515
./configure \
1616
--enable-experimental="$EXPERIMENTAL" --enable-endomorphism="$ENDOMORPHISM" \
1717
--with-field="$FIELD" --with-bignum="$BIGNUM" --with-asm="$ASM" --with-scalar="$SCALAR" \
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" --with-ecmult-gen-gen="$ECMULTGENNEG" \
1919
--enable-module-ecdh="$ECDH" --enable-module-recovery="$RECOVERY" \
2020
--host="$HOST" $EXTRAFLAGS
2121

src/ecmult_gen.h

+21-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,20 @@
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+
#undef COMB_NEGATION
26+
1827
# if EXHAUSTIVE_TEST_ORDER > 32
1928
# define COMB_BLOCKS 52
2029
# define COMB_TEETH 5
@@ -42,10 +51,18 @@
4251
* comb will use negations so that only negative multiples need be precomputed. The resulting memory
4352
* usage for precomputation will be COMB_POINTS_TOTAL * sizeof(secp256k1_ge_storage).
4453
*/
45-
#define COMB_BLOCKS 4
46-
#define COMB_TEETH 5
47-
#define COMB_SPACING 13
48-
#define COMB_NEGATION 1
54+
#ifndef COMB_BLOCKS
55+
#define COMB_BLOCKS 4
56+
#endif
57+
#ifndef COMB_TEETH
58+
#define COMB_TEETH 5
59+
#endif
60+
#ifndef COMB_SPACING
61+
#define COMB_SPACING ((COMB_BLOCKS * COMB_TEETH + 255) / (COMB_BLOCKS * COMB_TEETH))
62+
#endif
63+
#ifndef COMB_NEGATION
64+
#define COMB_NEGATION 1
65+
#endif
4966

5067
#endif
5168

0 commit comments

Comments
 (0)