Skip to content

Commit 7d90c68

Browse files
Make WINDOW_G configurable
This makes WINDOW_G a configurable value in the range of [2..24]. The upper limit of 24 is a defensive choice. The code is probably correct for values up to 33 but those larger values yield in huge tables (>= 256MiB), which are i) unlikely to be really benefitial in practice and ii) increasingly difficult to test.
1 parent aa15154 commit 7d90c68

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

configure.ac

+23
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ AC_ARG_WITH([scalar], [AS_HELP_STRING([--with-scalar=64bit|32bit|auto],
151151
AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|arm|no|auto]
152152
[Specify assembly optimizations to use. Default is auto (experimental: arm)])],[req_asm=$withval], [req_asm=auto])
153153

154+
# Default is window size 16 (or window size 15 with endomorphism) which needs 1.375 MiB. */
155+
AC_ARG_WITH([ecmult-window], [AS_HELP_STRING([--with-ecmult-window=SIZE],
156+
[window size for ecmult precomputation for verification, specified as integer in range [2..24],]
157+
[or in range [3..25] if endomorphisms optimization is used [default=16].]
158+
[Larger values result in better performance at the cost of an exponentially larger precomputed table.]
159+
[The table will need to store 2^(SIZE-2) * 64 bytes of data but can be larger in memory due]
160+
[to platform-specific padding and alignment.]
161+
)],
162+
[set_ecmult_window=$withval], [set_ecmult_window=16])
163+
154164
AC_CHECK_TYPES([__int128])
155165

156166
if test x"$enable_coverage" = x"yes"; then
@@ -387,6 +397,18 @@ case $set_scalar in
387397
;;
388398
esac
389399

400+
#set ecmult window size
401+
if test x"$use_endomorphism" = x"yes"; then
402+
if test "$set_ecmult_window" -lt 3 -o "$set_ecmult_window" -gt 25 ; then
403+
AC_MSG_ERROR([[Window size for ecmult precomputation must be in range [3..25] if endomorphism optimization is enabled.]])
404+
fi
405+
else
406+
if test "$set_ecmult_window" -lt 2 -o "$set_ecmult_window" -gt 24 ; then
407+
AC_MSG_ERROR([[Window size for ecmult precomputation must be in range [2..24] if endomorphism optimization is disabled.]])
408+
fi
409+
fi
410+
AC_DEFINE_UNQUOTED(ECMULT_WINDOW_SIZE, $set_ecmult_window, [Set window size for ecmult precomputation])
411+
390412
if test x"$use_tests" = x"yes"; then
391413
SECP_OPENSSL_CHECK
392414
if test x"$has_openssl_ec" = x"yes"; then
@@ -516,6 +538,7 @@ echo " asm = $set_asm"
516538
echo " bignum = $set_bignum"
517539
echo " field = $set_field"
518540
echo " scalar = $set_scalar"
541+
echo " ecmult window size = $set_ecmult_window"
519542
echo
520543
echo " CC = $CC"
521544
echo " CFLAGS = $CFLAGS"

src/ecmult_impl.h

+17-9
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,24 @@
3030
# endif
3131
#else
3232
/* optimal for 128-bit and 256-bit exponents. */
33-
#define WINDOW_A 5
34-
/** larger numbers may result in slightly better performance, at the cost of
35-
exponentially larger precomputed tables. */
36-
#ifdef USE_ENDOMORPHISM
37-
/** Two tables for window size 15: 1.375 MiB. */
38-
#define WINDOW_G 15
39-
#else
40-
/** One table for window size 16: 1.375 MiB. */
41-
#define WINDOW_G 16
33+
# define WINDOW_A 5
34+
# ifdef USE_ENDOMORPHISM
35+
# define WINDOW_G ((ECMULT_WINDOW_SIZE)-1)
36+
# else
37+
# define WINDOW_G (ECMULT_WINDOW_SIZE)
38+
# endif
4239
#endif
40+
41+
/* Noone will ever need more than a window size of 24.
42+
* (The code probably works with window sizes up to 33 but
43+
* it is not tested for it. For WINDOW_G >= 34, the
44+
* expansion of ECMULT_TABLE_SIZE(WINDOW_G) will overflow. */
45+
#if WINDOW_G < 2 || WINDOW_G > 24
46+
# ifdef USE_ENDOMORPHISM
47+
# error Set ECMULT_WINDOW_SIZE to an integer in range [3..25] if endomorphism optimization is enabled.
48+
# else
49+
# error Set ECMULT_WINDOW_SIZE to an integer in range [2..24] if endomorphism optimization is disabled.
50+
# endif
4351
#endif
4452

4553
#ifdef USE_ENDOMORPHISM

0 commit comments

Comments
 (0)