Skip to content

Commit

Permalink
Make COMB_BLOCKS and COMB_TEETH configurable, and test in Cirrus
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Mar 18, 2021
1 parent 63d2cf5 commit 937a8c2
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 21 deletions.
8 changes: 5 additions & 3 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
env:
WIDEMUL: auto
STATICPRECOMPUTATION: yes
ECMULTGENPRECISION: auto
ECMULTGENBLOCKS: auto
ECMULTGENTEETH: auto
ASM: no
BUILD: check
WITH_VALGRIND: yes
Expand Down Expand Up @@ -73,8 +74,9 @@ task:
EXPERIMENTAL: yes
SCHNORRSIG: yes
CTIMETEST: no
- env: { ECMULTGENPRECISION: 2 }
- env: { ECMULTGENPRECISION: 8 }
- env: { ECMULTGENBLOCKS: 256, ECMULTGENTEETH: 1 }
- env: { ECMULTGENBLOCKS: 43, ECMULTGENTEETH: 6, STATICPRECOMPUTATION: no }
- env: { ECMULTGENBLOCKS: 1, ECMULTGENTEETH: 1, STATICPRECOMPUTATION: no }
- env:
RUN_VALGRIND: yes
ASM: x86_64
Expand Down
2 changes: 1 addition & 1 deletion ci/cirrus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ valgrind --version || true
./configure \
--enable-experimental="$EXPERIMENTAL" \
--with-test-override-wide-multiply="$WIDEMUL" --with-asm="$ASM" \
--enable-ecmult-static-precomputation="$STATICPRECOMPUTATION" --with-ecmult-gen-precision="$ECMULTGENPRECISION" \
--enable-ecmult-static-precomputation="$STATICPRECOMPUTATION" --with-ecmult-gen-blocks="$ECMULTGENBLOCKS" --with-ecmult-gen-teeth="$ECMULTGENTEETH" \
--enable-module-ecdh="$ECDH" --enable-module-recovery="$RECOVERY" \
--enable-module-schnorrsig="$SCHNORRSIG" \
--with-valgrind="$WITH_VALGRIND" \
Expand Down
63 changes: 49 additions & 14 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,21 @@ AC_ARG_WITH([ecmult-window], [AS_HELP_STRING([--with-ecmult-window=SIZE|auto],
)],
[req_ecmult_window=$withval], [req_ecmult_window=auto])

AC_ARG_WITH([ecmult-gen-precision], [AS_HELP_STRING([--with-ecmult-gen-precision=2|4|8|auto],
[Precision bits to tune the precomputed table size for signing.]
[The size of the table is 32kB for 2 bits, 64kB for 4 bits, 512kB for 8 bits of precision.]
[A larger table size usually results in possible faster signing.]
AC_ARG_WITH([ecmult-gen-blocks], [AS_HELP_STRING([--with-ecmult-gen-blocks=BLOCKS|auto],
[The number of blocks to use in the multi-comb multiplication algorithm, in the range [1..256].]
[Larger values result in possibly better performance at the cost of a linearly larger precomputed table.]
[There must exist a multiple of BLOCKS*TEETH that is between 256 and 288, inclusive.]
["auto" is a reasonable setting for desktop machines (currently 4). [default=auto]]
)],
[req_ecmult_gen_precision=$withval], [req_ecmult_gen_precision=auto])
[req_ecmult_gen_blocks=$withval], [req_ecmult_gen_blocks=auto])

AC_ARG_WITH([ecmult-gen-teeth], [AS_HELP_STRING([--with-ecmult-gen-teeth=TEETH|auto],
[The number of teeth to use in the multi-comb multiplication algorithm, in the range [1..8].]
[Larger values result in possibly better performance at the cost of an exponentially larger precomputed table.]
[There must exist a multiple of BLOCKS*TEETH that is between 256 and 288, inclusive.]
["auto" is a reasonable setting for desktop machines (currently 5). [default=auto]]
)],
[req_ecmult_gen_teeth=$withval], [req_ecmult_gen_teeth=auto])

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

# Set ecmult gen precision
if test x"$req_ecmult_gen_precision" = x"auto"; then
set_ecmult_gen_precision=4
# Set ecmult gen blocks
if test x"$req_ecmult_gen_blocks" = x"auto"; then
set_ecmult_gen_blocks=4
else
set_ecmult_gen_precision=$req_ecmult_gen_precision
set_ecmult_gen_blocks=$req_ecmult_gen_blocks
fi
error_gen_blocks=['option to --with-ecmult-gen-blocks not an integer in range [1..256] or "auto"']
case $set_ecmult_gen_blocks in
''|*[[!0-9]]*)
# no valid integer
AC_MSG_ERROR($error_gen_blocks)
;;
*)
if test "$set_ecmult_gen_blocks" -lt 1 -o "$set_ecmult_gen_blocks" -gt 256 ; then
# not in range
AC_MSG_ERROR($error_gen_blocks)
fi
AC_DEFINE_UNQUOTED(COMB_BLOCKS, $set_ecmult_gen_blocks, [Set number of blocks in ecmult_gen precomputation])
;;
esac

case $set_ecmult_gen_precision in
2|4|8)
AC_DEFINE_UNQUOTED(ECMULT_GEN_PREC_BITS, $set_ecmult_gen_precision, [Set ecmult gen precision bits])
#set ecmult gen teeth
if test x"$req_ecmult_gen_teeth" = x"auto"; then
set_ecmult_gen_teeth=5
else
set_ecmult_gen_teeth=$req_ecmult_gen_teeth
fi
error_gen_teeth=['option to --with-ecmult-gen-teeth not an integer in range [1..8] or "auto"']
case $set_ecmult_gen_teeth in
''|*[[!0-9]]*)
# no valid integer
AC_MSG_ERROR($error_gen_teeth)
;;
*)
AC_MSG_ERROR(['ecmult gen precision not 2, 4, 8 or "auto"'])
if test "$set_ecmult_gen_teeth" -lt 1 -o "$set_ecmult_gen_teeth" -gt 8 ; then
# not in range
AC_MSG_ERROR($error_gen_teeth)
fi
AC_DEFINE_UNQUOTED(COMB_TEETH, $set_ecmult_gen_teeth, [Set number of teeth in ecmult_gen precomputation])
;;
esac

Expand Down Expand Up @@ -515,7 +549,8 @@ echo " module schnorrsig = $enable_module_schnorrsig"
echo
echo " asm = $set_asm"
echo " ecmult window size = $set_ecmult_window"
echo " ecmult gen prec. bits = $set_ecmult_gen_precision"
echo " ecmult gen blocks = $set_ecmult_gen_blocks"
echo " ecmult gen teeth = $set_ecmult_gen_teeth"
# Hide test-only options unless they're used.
if test x"$set_widemul" != xauto; then
echo " wide multiplication = $set_widemul"
Expand Down
20 changes: 17 additions & 3 deletions src/ecmult_gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@
#include "scalar.h"
#include "group.h"

#if defined HAVE_CONFIG_H
#include "libsecp256k1-config.h"
#endif

#if defined(EXHAUSTIVE_TEST_ORDER)

/* We need to control these values for exhaustive tests because
* the tables cannot have infinities in them (secp256k1_ge_storage
* doesn't support infinities) */
#undef COMB_BLOCKS
#undef COMB_TEETH
#undef COMB_SPACING

# if EXHAUSTIVE_TEST_ORDER > 32
# define COMB_BLOCKS 52
# define COMB_TEETH 5
Expand All @@ -39,9 +47,15 @@
/* COMB_BLOCKS, COMB_TEETH, COMB_SPACING must all be positive and the product of the three (COMB_BITS)
* must evaluate to a value in the range [256, 288]. The resulting memory usage for precomputation
* will be COMB_POINTS_TOTAL * sizeof(secp256k1_ge_storage). */
#define COMB_BLOCKS 4
#define COMB_TEETH 5
#define COMB_SPACING 13
# ifndef COMB_BLOCKS
# define COMB_BLOCKS 4
# endif
# ifndef COMB_TEETH
# define COMB_TEETH 5
# endif
# ifndef COMB_SPACING
# define COMB_SPACING ((COMB_BLOCKS * COMB_TEETH + 255) / (COMB_BLOCKS * COMB_TEETH))
# endif

#endif

Expand Down

0 comments on commit 937a8c2

Please sign in to comment.