Skip to content

Commit 413713c

Browse files
committed
Make COMB_BLOCKS and COMB_TEETH configurable, and test in Travis
1 parent c918a32 commit 413713c

File tree

3 files changed

+74
-21
lines changed

3 files changed

+74
-21
lines changed

.travis.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cache:
1111
- src/java/guava/
1212
env:
1313
global:
14-
- FIELD=auto BIGNUM=auto SCALAR=auto ENDOMORPHISM=no STATICPRECOMPUTATION=yes ECMULTGENPRECISION=auto ASM=no BUILD=check EXTRAFLAGS= HOST= ECDH=no RECOVERY=no EXPERIMENTAL=no JNI=no
14+
- FIELD=auto BIGNUM=auto SCALAR=auto ENDOMORPHISM=no STATICPRECOMPUTATION=yes ECMULTGENBLOCKS=auto ECMULTGENTEETH=auto ASM=no BUILD=check EXTRAFLAGS= HOST= ECDH=no RECOVERY=no EXPERIMENTAL=no JNI=no
1515
- GUAVA_URL=https://search.maven.org/remotecontent?filepath=com/google/guava/guava/18.0/guava-18.0.jar GUAVA_JAR=src/java/guava/guava-18.0.jar
1616
matrix:
1717
- SCALAR=32bit RECOVERY=yes
@@ -30,8 +30,9 @@ env:
3030
- EXTRAFLAGS=CPPFLAGS=-DDETERMINISTIC
3131
- EXTRAFLAGS=CFLAGS=-O0
3232
- BUILD=check-java JNI=yes ECDH=yes EXPERIMENTAL=yes
33-
- ECMULTGENPRECISION=2
34-
- ECMULTGENPRECISION=8
33+
- ECMULTGENBLOCKS=256 ECMULTGENTEETH=1
34+
- ECMULTGENBLOCKS=43 ECMULTGENTEETH=6
35+
- ECMULTGENBLOCKS=1 ECMULTGENTEETH=1
3536
matrix:
3637
fast_finish: true
3738
include:

configure.ac

+49-14
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,21 @@ AC_ARG_WITH([ecmult-window], [AS_HELP_STRING([--with-ecmult-window=SIZE|auto],
165165
)],
166166
[req_ecmult_window=$withval], [req_ecmult_window=auto])
167167

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

176184
AC_CHECK_TYPES([__int128])
177185

@@ -431,19 +439,45 @@ case $set_ecmult_window in
431439
;;
432440
esac
433441

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

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])
463+
#set ecmult gen teeth
464+
if test x"$req_ecmult_gen_teeth" = x"auto"; then
465+
set_ecmult_gen_teeth=5
466+
else
467+
set_ecmult_gen_teeth=$req_ecmult_gen_teeth
468+
fi
469+
error_gen_teeth=['option to --with-ecmult-gen-teeth not an integer in range [1..8] or "auto"']
470+
case $set_ecmult_gen_teeth in
471+
''|*[[!0-9]]*)
472+
# no valid integer
473+
AC_MSG_ERROR($error_gen_teeth)
444474
;;
445475
*)
446-
AC_MSG_ERROR(['ecmult gen precision not 2, 4, 8 or "auto"'])
476+
if test "$set_ecmult_gen_teeth" -lt 1 -o "$set_ecmult_gen_teeth" -gt 8 ; then
477+
# not in range
478+
AC_MSG_ERROR($error_gen_teeth)
479+
fi
480+
AC_DEFINE_UNQUOTED(COMB_TEETH, $set_ecmult_gen_teeth, [Set number of teeth in ecmult_gen precomputation])
447481
;;
448482
esac
449483

@@ -582,7 +616,8 @@ echo " bignum = $set_bignum"
582616
echo " field = $set_field"
583617
echo " scalar = $set_scalar"
584618
echo " ecmult window size = $set_ecmult_window"
585-
echo " ecmult gen prec. bits = $set_ecmult_gen_precision"
619+
echo " ecmult gen blocks = $set_ecmult_gen_blocks"
620+
echo " ecmult gen teeth = $set_ecmult_gen_teeth"
586621
echo
587622
echo " CC = $CC"
588623
echo " CFLAGS = $CFLAGS"

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)