Skip to content

Commit fe3e7eb

Browse files
committed
Merge scalar/field config into widemul setting
1 parent 805082d commit fe3e7eb

File tree

7 files changed

+43
-91
lines changed

7 files changed

+43
-91
lines changed

build-aux/m4/bitcoin_secp.m4

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
dnl libsecp25k1 helper checks
22
AC_DEFUN([SECP_INT128_CHECK],[
3-
has_int128=$ac_cv_type___int128
3+
if test x"$ac_cv_type___int128" = xyes -a x"$ac_cv_type_unsigned___int128" = xyes; then
4+
has_int128=yes
5+
else
6+
has_int128=no
7+
fi
48
])
59

610
dnl escape "$0x" below using the m4 quadrigaph @S|@, and escape it again with a \ for the shell.

configure.ac

Lines changed: 21 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,12 @@ AC_ARG_ENABLE(external_default_callbacks,
141141
[use_external_default_callbacks=$enableval],
142142
[use_external_default_callbacks=no])
143143

144-
AC_ARG_WITH([field], [AS_HELP_STRING([--with-field=64bit|32bit|auto],
145-
[finite field implementation to use [default=auto]])],[req_field=$withval], [req_field=auto])
144+
AC_ARG_WITH([wide-multiply], [AS_HELP_STRING([--with-wide-multiply=int64|int128|auto],
145+
[which wide multiplication implementation to use [default=auto]])],[req_widemul=$withval], [req_widemul=auto])
146146

147147
AC_ARG_WITH([bignum], [AS_HELP_STRING([--with-bignum=gmp|no|auto],
148148
[bignum implementation to use [default=auto]])],[req_bignum=$withval], [req_bignum=auto])
149149

150-
AC_ARG_WITH([scalar], [AS_HELP_STRING([--with-scalar=64bit|32bit|auto],
151-
[scalar implementation to use [default=auto]])],[req_scalar=$withval], [req_scalar=auto])
152-
153150
AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|arm|no|auto],
154151
[assembly optimizations to use (experimental: arm) [default=auto]])],[req_asm=$withval], [req_asm=auto])
155152

@@ -170,7 +167,7 @@ AC_ARG_WITH([ecmult-gen-precision], [AS_HELP_STRING([--with-ecmult-gen-precision
170167
)],
171168
[req_ecmult_gen_precision=$withval], [req_ecmult_gen_precision=auto])
172169

173-
AC_CHECK_TYPES([__int128])
170+
AC_CHECK_TYPES([__int128, unsigned __int128])
174171

175172
AC_CHECK_HEADER([valgrind/memcheck.h], [enable_valgrind=yes], [enable_valgrind=no], [])
176173
AM_CONDITIONAL([VALGRIND_ENABLED],[test "$enable_valgrind" = "yes"])
@@ -265,59 +262,27 @@ else
265262
esac
266263
fi
267264

268-
if test x"$req_field" = x"auto"; then
269-
if test x"set_asm" = x"x86_64"; then
270-
set_field=64bit
271-
fi
272-
if test x"$set_field" = x; then
273-
SECP_INT128_CHECK
274-
if test x"$has_int128" = x"yes"; then
275-
set_field=64bit
276-
fi
277-
fi
278-
if test x"$set_field" = x; then
279-
set_field=32bit
280-
fi
281-
else
282-
set_field=$req_field
283-
case $set_field in
284-
64bit)
285-
if test x"$set_asm" != x"x86_64"; then
286-
SECP_INT128_CHECK
287-
if test x"$has_int128" != x"yes"; then
288-
AC_MSG_ERROR([64bit field explicitly requested but neither __int128 support or x86_64 assembly available])
289-
fi
290-
fi
291-
;;
292-
32bit)
293-
;;
294-
*)
295-
AC_MSG_ERROR([invalid field implementation selection])
296-
;;
297-
esac
298-
fi
299-
300-
if test x"$req_scalar" = x"auto"; then
265+
if test x"$req_widemul" = x"auto"; then
301266
SECP_INT128_CHECK
302267
if test x"$has_int128" = x"yes"; then
303-
set_scalar=64bit
268+
set_widemul=int128
304269
fi
305-
if test x"$set_scalar" = x; then
306-
set_scalar=32bit
270+
if test x"$set_widemul" = x; then
271+
set_widemul=int64
307272
fi
308273
else
309-
set_scalar=$req_scalar
310-
case $set_scalar in
311-
64bit)
274+
set_widemul=$req_widemul
275+
case $set_widemul in
276+
int128)
312277
SECP_INT128_CHECK
313278
if test x"$has_int128" != x"yes"; then
314-
AC_MSG_ERROR([64bit scalar explicitly requested but __int128 support not available])
279+
AC_MSG_ERROR([Wide multiplication implementation int128 explicitly requested but __int128 support not available])
315280
fi
316281
;;
317-
32bit)
282+
int64)
318283
;;
319284
*)
320-
AC_MSG_ERROR([invalid scalar implementation selected])
285+
AC_MSG_ERROR([invalid wide multiplication implementation selected])
321286
;;
322287
esac
323288
fi
@@ -365,16 +330,16 @@ no)
365330
;;
366331
esac
367332

368-
# select field implementation
369-
case $set_field in
370-
64bit)
371-
AC_DEFINE(USE_FIELD_5X52, 1, [Define this symbol to use the FIELD_5X52 implementation])
333+
# select wide multiplication implementation
334+
case $set_widemul in
335+
int128)
336+
AC_DEFINE(USE_WIDEMUL_INT128, 1, [Define this symbol to use (unsigned) __int128 based wide multiplication implementation])
372337
;;
373-
32bit)
374-
AC_DEFINE(USE_FIELD_10X26, 1, [Define this symbol to use the FIELD_10X26 implementation])
338+
int64)
339+
AC_DEFINE(USE_WIDEMUL_INT64, 1, [Define this symbol to use (u)int64_t based wide multiplication implementation])
375340
;;
376341
*)
377-
AC_MSG_ERROR([invalid field implementation])
342+
AC_MSG_ERROR([invalid wide multiplication implementation])
378343
;;
379344
esac
380345

@@ -396,19 +361,6 @@ no)
396361
;;
397362
esac
398363

399-
#select scalar implementation
400-
case $set_scalar in
401-
64bit)
402-
AC_DEFINE(USE_SCALAR_4X64, 1, [Define this symbol to use the 4x64 scalar implementation])
403-
;;
404-
32bit)
405-
AC_DEFINE(USE_SCALAR_8X32, 1, [Define this symbol to use the 8x32 scalar implementation])
406-
;;
407-
*)
408-
AC_MSG_ERROR([invalid scalar implementation])
409-
;;
410-
esac
411-
412364
#set ecmult window size
413365
if test x"$req_ecmult_window" = x"auto"; then
414366
set_ecmult_window=15
@@ -553,8 +505,7 @@ echo " module recovery = $enable_module_recovery"
553505
echo
554506
echo " asm = $set_asm"
555507
echo " bignum = $set_bignum"
556-
echo " field = $set_field"
557-
echo " scalar = $set_scalar"
508+
echo " wide multiplication = $set_widemul"
558509
echo " ecmult window size = $set_ecmult_window"
559510
echo " ecmult gen prec. bits = $set_ecmult_gen_precision"
560511
echo

src/basic-config.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,21 @@
1414
#undef USE_ENDOMORPHISM
1515
#undef USE_EXTERNAL_ASM
1616
#undef USE_EXTERNAL_DEFAULT_CALLBACKS
17-
#undef USE_FIELD_10X26
18-
#undef USE_FIELD_5X52
1917
#undef USE_FIELD_INV_BUILTIN
2018
#undef USE_FIELD_INV_NUM
2119
#undef USE_NUM_GMP
2220
#undef USE_NUM_NONE
23-
#undef USE_SCALAR_4X64
24-
#undef USE_SCALAR_8X32
2521
#undef USE_SCALAR_INV_BUILTIN
2622
#undef USE_SCALAR_INV_NUM
23+
#undef USE_WIDEMUL_INT64
24+
#under USE_WIDEMUL_INT128
2725
#undef ECMULT_WINDOW_SIZE
2826
#undef HAVE___INT128 /* used in util.h */
2927

3028
#define USE_NUM_NONE 1
3129
#define USE_FIELD_INV_BUILTIN 1
3230
#define USE_SCALAR_INV_BUILTIN 1
33-
#define USE_FIELD_10X26 1
34-
#define USE_SCALAR_8X32 1
31+
#define USE_WIDEMUL_64 1
3532
#define ECMULT_WINDOW_SIZE 15
3633

3734
#endif /* USE_BASIC_CONFIG */

src/field.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
#include "libsecp256k1-config.h"
2323
#endif
2424

25-
#if defined(USE_FIELD_10X26)
26-
#include "field_10x26.h"
27-
#elif defined(USE_FIELD_5X52)
25+
#if defined(USE_WIDEMUL_INT128)
2826
#include "field_5x52.h"
27+
#elif defined(USE_WIDEMUL_INT64)
28+
#include "field_10x26.h"
2929
#else
30-
#error "Please select field implementation"
30+
#error "Please select wide multiplication implementation"
3131
#endif
3232

3333
#include "util.h"

src/field_impl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
#include "util.h"
1515
#include "num.h"
1616

17-
#if defined(USE_FIELD_10X26)
18-
#include "field_10x26_impl.h"
19-
#elif defined(USE_FIELD_5X52)
17+
#if defined(USE_WIDEMUL_INT128)
2018
#include "field_5x52_impl.h"
19+
#elif defined(USE_WIDEMUL_INT64)
20+
#include "field_10x26_impl.h"
2121
#else
22-
#error "Please select field implementation"
22+
#error "Please select wide multiplication implementation"
2323
#endif
2424

2525
SECP256K1_INLINE static int secp256k1_fe_equal(const secp256k1_fe *a, const secp256k1_fe *b) {

src/scalar.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515

1616
#if defined(EXHAUSTIVE_TEST_ORDER)
1717
#include "scalar_low.h"
18-
#elif defined(USE_SCALAR_4X64)
18+
#elif defined(USE_WIDEMUL_INT128)
1919
#include "scalar_4x64.h"
20-
#elif defined(USE_SCALAR_8X32)
20+
#elif defined(USE_WIDEMUL_INT64)
2121
#include "scalar_8x32.h"
2222
#else
23-
#error "Please select scalar implementation"
23+
#error "Please select wide multiplication implementation"
2424
#endif
2525

2626
/** Clear a scalar to prevent the leak of sensitive data. */

src/scalar_impl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
#if defined(EXHAUSTIVE_TEST_ORDER)
1818
#include "scalar_low_impl.h"
19-
#elif defined(USE_SCALAR_4X64)
19+
#elif defined(USE_WIDEMUL_INT128)
2020
#include "scalar_4x64_impl.h"
21-
#elif defined(USE_SCALAR_8X32)
21+
#elif defined(USE_WIDEMUL_INT64)
2222
#include "scalar_8x32_impl.h"
2323
#else
24-
#error "Please select scalar implementation"
24+
#error "Please select wide multiplication implementation"
2525
#endif
2626

2727
static const secp256k1_scalar secp256k1_scalar_one = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 1);

0 commit comments

Comments
 (0)