Skip to content

Commit 7873633

Browse files
committed
Squashed 'src/secp256k1/' changes from bccaf86..50cc6ab
50cc6ab Merge pull request bitcoin-core#178 941e221 Add tests for handling of the nonce function in signing. 10c81ff Merge pull request bitcoin-core#177 7688e34 Add magnitude limits to secp256k1_fe_verify to ensure that it's own tests function correctly. 4ee4f7a Merge pull request bitcoin-core#176 70ae0d2 Use secp256k1_fe_equal_var in secp256k1_fe_sqrt_var. 7767b4d Merge pull request bitcoin-core#175 9ab9335 Add a reference consistency test to ge_tests. 60571c6 Rework group tests d26e26f Avoid constructing an invalid signature with probability 1:2^256. b450c34 Merge pull request bitcoin-core#163 d57cae9 Merge pull request bitcoin-core#154 49ee0db Add _normalizes_to_zero_var variant eed599d Add _fe_normalizes_to_zero method d7174ed Weak normalization for secp256k1_fe_equal 0295f0a weak normalization bbd5ba7 Use rfc6979 as default nonce generation function b37fbc2 Implement SHA256 / HMAC-SHA256 / RFC6979. c6e7f4e [API BREAK] Use a nonce-generation function instead of a nonce cf0c48b Merge pull request bitcoin-core#169 603c33b Make signing fail if a too small buffer is passed. 6d16606 Merge pull request bitcoin-core#168 7277fd7 Remove GMP field implementation e99c4c4 Merge pull request bitcoin-core#123 13278f6 Add explanation about how inversion can be avoided ce7eb6f Optimize verification: avoid field inverse a098f78 Merge pull request bitcoin-core#160 38acd01 Merge pull request bitcoin-core#165 6a59012 Make git ignore bench_recover when configured with benchmark enabled 1ba4a60 Configure options reorganization 3c0f246 Merge pull request bitcoin-core#157 808dd9b Merge pull request bitcoin-core#156 8dc75e9 Merge pull request bitcoin-core#158 28ade27 build: nuke bashisms 5190079 build: use subdir-objects for automake 8336040 build: disable benchmark by default git-subtree-dir: src/secp256k1 git-subtree-split: 50cc6ab0625efda6dddf1dc86c1e2671f069b0d8
1 parent ecae2ac commit 7873633

23 files changed

+1172
-529
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
bench_inv
22
bench_sign
33
bench_verify
4+
bench_recover
45
tests
56
*.exe
67
*.so

.travis.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,22 @@ compiler:
44
- gcc
55
install:
66
- sudo apt-get install -qq libssl-dev
7-
- if [ "$BIGNUM" = "gmp" -o "$BIGNUM" = "auto" -o "$FIELD" = "gmp" ]; then sudo apt-get install --no-install-recommends --no-upgrade -qq libgmp-dev; fi
7+
- if [ "$BIGNUM" = "gmp" -o "$BIGNUM" = "auto" ]; then sudo apt-get install --no-install-recommends --no-upgrade -qq libgmp-dev; fi
88
- if [ -n "$EXTRAPACKAGES" ]; then sudo apt-get update && sudo apt-get install --no-install-recommends --no-upgrade $EXTRAPACKAGES; fi
99
env:
1010
global:
11-
- FIELD=auto BIGNUM=auto SCALAR=auto ENDOMORPHISM=no BUILD=check EXTRAFLAGS= HOST= EXTRAPACKAGES=
11+
- FIELD=auto BIGNUM=auto SCALAR=auto ENDOMORPHISM=no ASM=no BUILD=check EXTRAFLAGS= HOST= EXTRAPACKAGES=
1212
matrix:
1313
- SCALAR=32bit
1414
- SCALAR=64bit
15-
- FIELD=gmp
16-
- FIELD=gmp ENDOMORPHISM=yes
17-
- FIELD=64bit_asm
18-
- FIELD=64bit_asm ENDOMORPHISM=yes
1915
- FIELD=64bit
2016
- FIELD=64bit ENDOMORPHISM=yes
17+
- FIELD=64bit ASM=x86_64
18+
- FIELD=64bit ENDOMORPHISM=yes ASM=x86_64
2119
- FIELD=32bit
2220
- FIELD=32bit ENDOMORPHISM=yes
23-
- BIGNUM=none
24-
- BIGNUM=none ENDOMORPHISM=yes
21+
- BIGNUM=no
22+
- BIGNUM=no ENDOMORPHISM=yes
2523
- BUILD=distcheck
2624
- EXTRAFLAGS=CFLAGS=-DDETERMINISTIC
2725
- HOST=i686-linux-gnu EXTRAPACKAGES="gcc-multilib"

Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ noinst_HEADERS += src/java/org_bitcoin_NativeSecp256k1.h
3333
noinst_HEADERS += src/util.h
3434
noinst_HEADERS += src/testrand.h
3535
noinst_HEADERS += src/testrand_impl.h
36-
noinst_HEADERS += src/field_gmp.h
37-
noinst_HEADERS += src/field_gmp_impl.h
36+
noinst_HEADERS += src/hash.h
37+
noinst_HEADERS += src/hash_impl.h
3838
noinst_HEADERS += src/field.h
3939
noinst_HEADERS += src/field_impl.h
4040
noinst_HEADERS += src/bench.h

build-aux/m4/bitcoin_secp.m4

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
dnl libsecp25k1 helper checks
22
AC_DEFUN([SECP_INT128_CHECK],[
33
has_int128=$ac_cv_type___int128
4-
if test x"$has_int128" != x"yes" && test x"$set_field" = x"64bit"; then
5-
AC_MSG_ERROR([$set_field field support explicitly requested but is not compatible with this host])
6-
fi
7-
if test x"$has_int128" != x"yes" && test x"$set_scalar" = x"64bit"; then
8-
AC_MSG_ERROR([$set_scalar scalar support explicitly requested but is not compatible with this host])
9-
fi
104
])
115

126
dnl
@@ -18,11 +12,6 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1812
__asm__ __volatile__("movq $0x100000000,%1; mulq %%rsi" : "+a"(a) : "S"(tmp) : "cc", "%rdx");
1913
]])],[has_64bit_asm=yes],[has_64bit_asm=no])
2014
AC_MSG_RESULT([$has_64bit_asm])
21-
if test x"$set_field" == x"64bit_asm"; then
22-
if test x"$has_64bit_asm" == x"no"; then
23-
AC_MSG_ERROR([$set_field field support explicitly requested but no x86_64 assembly available])
24-
fi
25-
fi
2615
])
2716

2817
dnl
@@ -43,7 +32,7 @@ else
4332
)])
4433
LIBS=
4534
fi
46-
if test x"$has_libcrypto" == x"yes" && test x"$has_openssl_ec" = x; then
35+
if test x"$has_libcrypto" = x"yes" && test x"$has_openssl_ec" = x; then
4736
AC_MSG_CHECKING(for EC functions in libcrypto)
4837
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4938
#include <openssl/ec.h>
@@ -69,11 +58,4 @@ if test x"$has_gmp" != x"yes"; then
6958
CPPFLAGS="$CPPFLAGS_TEMP"
7059
LIBS="$LIBS_TEMP"
7160
fi
72-
if test x"$set_field" = x"gmp" && test x"$has_gmp" != x"yes"; then
73-
AC_MSG_ERROR([$set_field field support explicitly requested but libgmp was not found])
74-
fi
75-
if test x"$set_bignum" = x"gmp" && test x"$has_gmp" != x"yes"; then
76-
AC_MSG_ERROR([$set_bignum field support explicitly requested but libgmp was not found])
77-
fi
7861
])
79-

configure.ac

Lines changed: 69 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ AC_CANONICAL_HOST
66
AH_TOP([#ifndef LIBSECP256K1_CONFIG_H])
77
AH_TOP([#define LIBSECP256K1_CONFIG_H])
88
AH_BOTTOM([#endif //LIBSECP256K1_CONFIG_H])
9-
AM_INIT_AUTOMAKE([foreign])
9+
AM_INIT_AUTOMAKE([foreign subdir-objects])
1010
LT_INIT
1111

1212
dnl make the compilation flags quiet unless V=1 is used
@@ -23,7 +23,7 @@ if test "x$CFLAGS" = "x"; then
2323
fi
2424

2525
AC_PROG_CC_C99
26-
if test x"$ac_cv_prog_cc_c99" == x"no"; then
26+
if test x"$ac_cv_prog_cc_c99" = x"no"; then
2727
AC_MSG_ERROR([c99 compiler support required])
2828
fi
2929

@@ -82,9 +82,9 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
8282

8383

8484
AC_ARG_ENABLE(benchmark,
85-
AS_HELP_STRING([--enable-benchmark],[compile benchmark (default is yes)]),
85+
AS_HELP_STRING([--enable-benchmark],[compile benchmark (default is no)]),
8686
[use_benchmark=$enableval],
87-
[use_benchmark=yes])
87+
[use_benchmark=no])
8888

8989
AC_ARG_ENABLE(tests,
9090
AS_HELP_STRING([--enable-tests],[compile tests (default is yes)]),
@@ -96,15 +96,18 @@ AC_ARG_ENABLE(endomorphism,
9696
[use_endomorphism=$enableval],
9797
[use_endomorphism=no])
9898

99-
AC_ARG_WITH([field], [AS_HELP_STRING([--with-field=gmp|64bit|64bit_asm|32bit|auto],
99+
AC_ARG_WITH([field], [AS_HELP_STRING([--with-field=64bit|32bit|auto],
100100
[Specify Field Implementation. Default is auto])],[req_field=$withval], [req_field=auto])
101101

102-
AC_ARG_WITH([bignum], [AS_HELP_STRING([--with-bignum=gmp|none|auto],
102+
AC_ARG_WITH([bignum], [AS_HELP_STRING([--with-bignum=gmp|no|auto],
103103
[Specify Bignum Implementation. Default is auto])],[req_bignum=$withval], [req_bignum=auto])
104104

105105
AC_ARG_WITH([scalar], [AS_HELP_STRING([--with-scalar=64bit|32bit|auto],
106106
[Specify scalar implementation. Default is auto])],[req_scalar=$withval], [req_scalar=auto])
107107

108+
AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|no|auto]
109+
[Specify assembly optimizations to use. Default is auto])],[req_asm=$withval], [req_asm=auto])
110+
108111
AC_CHECK_TYPES([__int128])
109112

110113
AC_MSG_CHECKING([for __builtin_expect])
@@ -113,40 +116,54 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[void myfunc() {__builtin_expect(0,0);}]])],
113116
[ AC_MSG_RESULT([no])
114117
])
115118

116-
if test x"$req_field" = x"auto"; then
119+
if test x"$req_asm" = x"auto"; then
117120
SECP_64BIT_ASM_CHECK
118121
if test x"$has_64bit_asm" = x"yes"; then
119-
set_field=64bit_asm
122+
set_asm=x86_64
123+
fi
124+
if test x"$set_asm" = x; then
125+
set_asm=no
120126
fi
127+
else
128+
set_asm=$req_asm
129+
case $set_asm in
130+
x86_64)
131+
SECP_64BIT_ASM_CHECK
132+
if test x"$has_64bit_asm" != x"yes"; then
133+
AC_MSG_ERROR([x86_64 assembly optimization requested but not available])
134+
fi
135+
;;
136+
no)
137+
;;
138+
*)
139+
AC_MSG_ERROR([invalid assembly optimization selection])
140+
;;
141+
esac
142+
fi
121143

144+
if test x"$req_field" = x"auto"; then
145+
if test x"set_asm" = x"x86_64"; then
146+
set_field=64bit
147+
fi
122148
if test x"$set_field" = x; then
123149
SECP_INT128_CHECK
124150
if test x"$has_int128" = x"yes"; then
125151
set_field=64bit
126152
fi
127153
fi
128-
129-
if test x"$set_field" = x; then
130-
SECP_GMP_CHECK
131-
if test x"$has_gmp" = x"yes"; then
132-
set_field=gmp
133-
fi
134-
fi
135-
136154
if test x"$set_field" = x; then
137155
set_field=32bit
138156
fi
139157
else
140158
set_field=$req_field
141159
case $set_field in
142-
64bit_asm)
143-
SECP_64BIT_ASM_CHECK
144-
;;
145160
64bit)
146-
SECP_INT128_CHECK
147-
;;
148-
gmp)
149-
SECP_GMP_CHECK
161+
if test x"$set_asm" != x"x86_64"; then
162+
SECP_INT128_CHECK
163+
if test x"$has_int128" != x"yes"; then
164+
AC_MSG_ERROR([64bit field explicitly requested but neither __int128 support or x86_64 assembly available])
165+
fi
166+
fi
150167
;;
151168
32bit)
152169
;;
@@ -157,11 +174,9 @@ else
157174
fi
158175

159176
if test x"$req_scalar" = x"auto"; then
160-
if test x"$set_scalar" = x; then
161-
SECP_INT128_CHECK
162-
if test x"$has_int128" = x"yes"; then
163-
set_scalar=64bit
164-
fi
177+
SECP_INT128_CHECK
178+
if test x"$has_int128" = x"yes"; then
179+
set_scalar=64bit
165180
fi
166181
if test x"$set_scalar" = x; then
167182
set_scalar=32bit
@@ -171,6 +186,9 @@ else
171186
case $set_scalar in
172187
64bit)
173188
SECP_INT128_CHECK
189+
if test x"$has_int128" != x"yes"; then
190+
AC_MSG_ERROR([64bit scalar explicitly requested but __int128 support not available])
191+
fi
174192
;;
175193
32bit)
176194
;;
@@ -187,36 +205,42 @@ if test x"$req_bignum" = x"auto"; then
187205
fi
188206

189207
if test x"$set_bignum" = x; then
190-
set_bignum=none
208+
set_bignum=no
191209
fi
192210
else
193211
set_bignum=$req_bignum
194212
case $set_bignum in
195213
gmp)
196214
SECP_GMP_CHECK
215+
if test x"$has_gmp" != x"yes"; then
216+
AC_MSG_ERROR([gmp bignum explicitly requested but libgmp not available])
217+
fi
197218
;;
198-
none)
219+
no)
199220
;;
200221
*)
201222
AC_MSG_ERROR([invalid bignum implementation selection])
202223
;;
203224
esac
204225
fi
205226

227+
# select assembly optimization
228+
case $set_asm in
229+
x86_64)
230+
AC_DEFINE(USE_ASM_X86_64, 1, [Define this symbol to enable x86_64 assembly optimizations])
231+
;;
232+
no)
233+
;;
234+
*)
235+
AC_MSG_ERROR([invalid assembly optimizations])
236+
;;
237+
esac
238+
206239
# select field implementation
207240
case $set_field in
208-
64bit_asm)
209-
AC_DEFINE(USE_FIELD_5X52_ASM, 1, [Define this symbol to use the assembly version for the 5x52 field implementation])
210-
AC_DEFINE(USE_FIELD_5X52, 1, [Define this symbol to use the FIELD_5X52 implementation])
211-
;;
212241
64bit)
213-
AC_DEFINE(USE_FIELD_5X52_INT128, 1, [Define this symbol to use the __int128 version for the 5x52 field implementation])
214242
AC_DEFINE(USE_FIELD_5X52, 1, [Define this symbol to use the FIELD_5X52 implementation])
215243
;;
216-
gmp)
217-
AC_DEFINE(HAVE_LIBGMP,1,[Define this symbol if libgmp is installed])
218-
AC_DEFINE(USE_FIELD_GMP, 1, [Define this symbol to use the FIELD_GMP implementation])
219-
;;
220244
32bit)
221245
AC_DEFINE(USE_FIELD_10X26, 1, [Define this symbol to use the FIELD_10X26 implementation])
222246
;;
@@ -233,7 +257,7 @@ gmp)
233257
AC_DEFINE(USE_FIELD_INV_NUM, 1, [Define this symbol to use the num-based field inverse implementation])
234258
AC_DEFINE(USE_SCALAR_INV_NUM, 1, [Define this symbol to use the num-based scalar inverse implementation])
235259
;;
236-
none)
260+
no)
237261
AC_DEFINE(USE_NUM_NONE, 1, [Define this symbol to use no num implementation])
238262
AC_DEFINE(USE_FIELD_INV_BUILTIN, 1, [Define this symbol to use the native field inverse implementation])
239263
AC_DEFINE(USE_SCALAR_INV_BUILTIN, 1, [Define this symbol to use the native scalar inverse implementation])
@@ -258,7 +282,7 @@ esac
258282

259283
if test x"$use_tests" = x"yes"; then
260284
SECP_OPENSSL_CHECK
261-
if test x"$has_openssl_ec" == x"yes"; then
285+
if test x"$has_openssl_ec" = x"yes"; then
262286
AC_DEFINE(ENABLE_OPENSSL_TESTS, 1, [Define this symbol if OpenSSL EC functions are available])
263287
SECP_TEST_INCLUDES="$SSL_CFLAGS $CRYPTO_CFLAGS"
264288
SECP_TEST_LIBS="$CRYPTO_LIBS"
@@ -272,7 +296,7 @@ if test x"$use_tests" = x"yes"; then
272296
fi
273297
fi
274298

275-
if test x"$set_field" = x"gmp" || test x"$set_bignum" = x"gmp"; then
299+
if test x"$set_bignum" = x"gmp"; then
276300
SECP_LIBS="$SECP_LIBS $GMP_LIBS"
277301
SECP_INCLUDES="$SECP_INCLUDES $GMP_CPPFLAGS"
278302
fi
@@ -281,19 +305,20 @@ if test x"$use_endomorphism" = x"yes"; then
281305
AC_DEFINE(USE_ENDOMORPHISM, 1, [Define this symbol to use endomorphism optimization])
282306
fi
283307

308+
AC_MSG_NOTICE([Using assembly optimizations: $set_asm])
284309
AC_MSG_NOTICE([Using field implementation: $set_field])
285310
AC_MSG_NOTICE([Using bignum implementation: $set_bignum])
286311
AC_MSG_NOTICE([Using scalar implementation: $set_scalar])
312+
AC_MSG_NOTICE([Using endomorphism optimizations: $use_endomorphism])
287313

288314
AC_CONFIG_HEADERS([src/libsecp256k1-config.h])
289315
AC_CONFIG_FILES([Makefile libsecp256k1.pc])
290316
AC_SUBST(SECP_INCLUDES)
291317
AC_SUBST(SECP_LIBS)
292318
AC_SUBST(SECP_TEST_LIBS)
293319
AC_SUBST(SECP_TEST_INCLUDES)
294-
AM_CONDITIONAL([USE_ASM], [test x"$set_field" == x"64bit_asm"])
295320
AM_CONDITIONAL([USE_TESTS], [test x"$use_tests" != x"no"])
296-
AM_CONDITIONAL([USE_BENCHMARK], [test x"$use_benchmark" != x"no"])
321+
AM_CONDITIONAL([USE_BENCHMARK], [test x"$use_benchmark" = x"yes"])
297322

298323
dnl make sure nothing new is exported so that we don't break the cache
299324
PKGCONFIG_PATH_TEMP="$PKG_CONFIG_PATH"

0 commit comments

Comments
 (0)