Skip to content

Commit 544c1f3

Browse files
committed
Squashed 'src/secp256k1/' changes from b19c000..9d5373307c
9d5373307c f add new bip-schnorr test vector 14 44881b21e3 f rename is_positive in schnorrsig module to has_square_y affa6e87e9 f rename is_positive in xonly_pubkey api to has_square_y b5fcf54149 f uninitialized memory in tests 7e4ea97582 f trigger travis 538052c950 f reenable test vectors 26f95c556a f feed seckey that is actually signed with (i.e. perhaps negated) into nonce functions 2b36bf7db3 f sign -> is_positive dfce048bde f remove xonly_pubkey_to_pubkey 74bb3b4318 f don't use secp256k1_pubkeys in xonly_tweak api and instead use is_positive flag 5764b2b2b7 f test that pubkey is zeroed after xonly_pubkey_parse returned 0 e28b61c290 f const casting 84fe42737d f address some of pieter's comments 2e4ed392e1 f add tweak functions for xonly_pubkeys add8e78542 f use xonly_pubkeys in schnorrsig sign and verify 7eeb3aa498 f add xonly pubkey struct which is serialized as 32 byte and whose Y coordinate is a quadratic residue 2e76c5dc6d f don't allow counter != 0 in nonce function 639a8599ec f use tagged hashes in nonce derivation and signature hash 6bd94240b7 Add schnorrsig module which implements BIP-schnorr [0] compatible signing, verification and batch verification. 8fcee9ab05 add chacha20 function 96cd94e Merge bitcoin#337: variable sized precomputed table for signing dcb2e3b variable signing precompute table b4bff99 Merge bitcoin#661: Make ./configure string consistent a467047 Make ./configure string consistent e729cc7 Merge bitcoin#657: Fix a nit in the recovery tests b64a2e2 Fix a nit in the recovery tests e028aa3 Merge bitcoin#650: secp256k1/src/tests.c: Properly handle sscanf return value f1e11d3 Merge bitcoin#654: Fix typo (∞) ef83281 Merge pull request bitcoin#656 from real-or-random/patch-1 556caad Fix typo in docs for _context_set_illegal_callback 786dfb4 Merge bitcoin#583: JNI: fix use sig array e95f8ab Merge bitcoin#644: Avoid optimizing out a verify_check 384f556 Merge bitcoin#652: README.md: update instruction to run tests ee56acc Merge bitcoin#651: Fix typo in secp256k1_preallocated.h 7b9b117 Merge bitcoin#640: scalar_impl.h: fix includes d99bec2 Merge bitcoin#655: jni: Use only Guava for hex encoding and decoding 2abcf95 jni: Use only Guava for hex encoding and decoding 271582b Fix typo ce6d438 README.md: update instruction to run tests b1e68cb Fix typo in secp256k1_preallocated.h a11c76c secp256k1/src/tests.c: Properly handle sscanf return value 94ae7cb Moved a dereference so the null check will be before the dereferencing 2cb73b1 scalar_impl.h: fix includes fa33017 Merge bitcoin#634: Add a descriptive comment for secp256k1_ecmult_const. ee9e68c Add a descriptive comment for secp256k1_ecmult_const. d0d738d Merge bitcoin#631: typo in comment for secp256k1_ec_pubkey_tweak_mul () 6914c25 typo in comment for secp256k1_ec_pubkey_tweak_mul () e541a90 Merge bitcoin#629: Avoid calling _is_zero when _set_b32 fails. f34b0c3 Merge bitcoin#630: Note intention of timing sidechannel freeness. 8d1563b Note intention of timing sidechannel freeness. 1669bb2 Merge bitcoin#628: Fix ability to compile tests without -DVERIFY. ecc94ab Merge bitcoin#627: Guard memcmp in tests against mixed size inputs. 544435f Merge bitcoin#578: Avoid implementation-defined and undefined behavior when dealing with sizes 143dc6e Merge bitcoin#595: Allow to use external default callbacks e49f799 Add missing #(un)defines to base-config.h 77defd2 Add secp256k1_ prefix to default callback functions 908bdce Include stdio.h and stdlib.h explicitly in secp256k1.c 5db782e Allow usage of external default callbacks 6095a86 Replace CHECKs for no_precomp ctx by ARG_CHECKs without a return cd473e0 Avoid calling secp256k1_*_is_zero when secp256k1_*_set_b32 fails. 6c36de7 Merge bitcoin#600: scratch space: use single allocation 98836b1 scratch: replace frames with "checkpoint" system 7623cf2 scratch: save a couple bytes of unnecessarily-allocated memory a7a164f scratch: rename `max_size` to `size`, document that extra will actually be allocated 5a4bc0b scratch: unify allocations c2b028a scratch space: thread `error_callback` into all scratch space functions 0be1a4a scratch: add magic bytes to beginning of structure 92a48a7 scratch space: use single allocation 40839e2 Merge bitcoin#592: Use trivial algorithm in ecmult_multi if scratch space is small dcf3920 Fix ability to compile tests without -DVERIFY. a484e00 Merge bitcoin#566: Enable context creation in preallocated memory 0522caa Explain caller's obligations for preallocated memory 238305f Move _preallocated functions to separate header 695feb6 Export _preallocated functions 814cc78 Add tests for contexts in preallocated memory ba12dd0 Check arguments of _preallocated functions 5feadde Support cloning a context into preallocated memory c4fd5da Switch to a single malloc call ef020de Add size constants for preallocated memory 1bf7c05 Prepare for manual memory management in preallocated memory 248bffb Guard memcmp in tests against mixed size inputs. 36698dc Merge bitcoin#596: Make WINDOW_G configurable a61a93f Clean up ./configure help strings 2842dc5 Make WINDOW_G configurable 1a02d6c Merge bitcoin#626: Revert "Merge bitcoin#620: Install headers automatically" 662918c Revert "Merge bitcoin#620: Install headers automatically" 14c7dbd Simplify control flow in DER parsing ec8f20b Avoid out-of-bound pointers and integer overflows in size comparisons 01ee1b3 Parse DER-enconded length into a size_t instead of an int 912680e Merge bitcoin#561: Respect LDFLAGS and #undef STATIC_PRECOMPUTATION if using basic config 91fae3a Merge bitcoin#620: Install headers automatically 5df77a0 Merge bitcoin#533: Make sure we're not using an uninitialized variable in secp256k1_wnaf_const(...) 975e51e Merge bitcoin#617: Pass scalar by reference in secp256k1_wnaf_const() 735fbde Merge bitcoin#619: Clear a copied secret key after negation 16e8615 Install headers automatically 069870d Clear a copied secret key after negation 8979ec0 Pass scalar by reference in secp256k1_wnaf_const() 84a8085 Merge bitcoin#612: Allow field_10x26_arm.s to compile for ARMv7 architecture d4d270a Allow field_10x26_arm.s to compile for ARMv7 architecture 248f046 Make sure we're not using an uninitialized variable in secp256k1_wnaf_const(...) 9ab96f7 Use trivial algorithm in ecmult_multi if scratch space is small dbed75d Undefine `STATIC_PRECOMPUTATION` if using the basic config 310111e Keep LDFLAGS if `--coverage` 74e2dbd JNI: fix use sig array 3cb057f Fix possible integer overflow in DER parsing git-subtree-dir: src/secp256k1 git-subtree-split: 9d5373307cfad5fa1b53820d417a8155d2d557dc
1 parent 5424598 commit 544c1f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3371
-455
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
bench_inv
22
bench_ecdh
33
bench_ecmult
4+
bench_schnorrsig
45
bench_sign
56
bench_verify
6-
bench_schnorr_verify
77
bench_recover
88
bench_internal
99
tests

.travis.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,27 @@ cache:
1111
- src/java/guava/
1212
env:
1313
global:
14-
- FIELD=auto BIGNUM=auto SCALAR=auto ENDOMORPHISM=no STATICPRECOMPUTATION=yes 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 ECMULTGENPRECISION=auto ASM=no BUILD=check EXTRAFLAGS= HOST= ECDH=no RECOVERY=no EXPERIMENTAL=no JNI=no JNI=no SCHNORRSIG=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
18-
- SCALAR=32bit FIELD=32bit ECDH=yes EXPERIMENTAL=yes
18+
- SCALAR=32bit FIELD=32bit ECDH=yes EXPERIMENTAL=yes SCHNORRSIG=yes
1919
- SCALAR=64bit
20-
- FIELD=64bit RECOVERY=yes
20+
- FIELD=64bit RECOVERY=yes EXPERIMENTAL=yes SCHNORRSIG=yes
2121
- FIELD=64bit ENDOMORPHISM=yes
22-
- FIELD=64bit ENDOMORPHISM=yes ECDH=yes EXPERIMENTAL=yes
22+
- FIELD=64bit ENDOMORPHISM=yes ECDH=yes EXPERIMENTAL=yes SCHNORRSIG=yes
2323
- FIELD=64bit ASM=x86_64
2424
- FIELD=64bit ENDOMORPHISM=yes ASM=x86_64
2525
- FIELD=32bit ENDOMORPHISM=yes
2626
- BIGNUM=no
27-
- BIGNUM=no ENDOMORPHISM=yes RECOVERY=yes EXPERIMENTAL=yes
27+
- BIGNUM=no ENDOMORPHISM=yes RECOVERY=yes EXPERIMENTAL=yes SCHNORRSIG=yes
2828
- BIGNUM=no STATICPRECOMPUTATION=no
2929
- BUILD=distcheck
3030
- EXTRAFLAGS=CPPFLAGS=-DDETERMINISTIC
3131
- EXTRAFLAGS=CFLAGS=-O0
3232
- BUILD=check-java JNI=yes ECDH=yes EXPERIMENTAL=yes
33+
- ECMULTGENPRECISION=2
34+
- ECMULTGENPRECISION=8
3335
matrix:
3436
fast_finish: true
3537
include:
@@ -65,4 +67,4 @@ before_script: ./autogen.sh
6567
script:
6668
- if [ -n "$HOST" ]; then export USE_HOST="--host=$HOST"; fi
6769
- if [ "x$HOST" = "xi686-linux-gnu" ]; then export CC="$CC -m32"; fi
68-
- ./configure --enable-experimental=$EXPERIMENTAL --enable-endomorphism=$ENDOMORPHISM --with-field=$FIELD --with-bignum=$BIGNUM --with-scalar=$SCALAR --enable-ecmult-static-precomputation=$STATICPRECOMPUTATION --enable-module-ecdh=$ECDH --enable-module-recovery=$RECOVERY --enable-jni=$JNI $EXTRAFLAGS $USE_HOST && make -j2 $BUILD
70+
- ./configure --enable-experimental=$EXPERIMENTAL --enable-endomorphism=$ENDOMORPHISM --with-field=$FIELD --with-bignum=$BIGNUM --with-scalar=$SCALAR --enable-ecmult-static-precomputation=$STATICPRECOMPUTATION --with-ecmult-gen-precision=$ECMULTGENPRECISION --enable-module-ecdh=$ECDH --enable-module-recovery=$RECOVERY --enable-module-schnorrsig=$SCHNORRSIG --enable-jni=$JNI $EXTRAFLAGS $USE_HOST && make -j2 $BUILD

Makefile.am

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ else
88
JNI_LIB =
99
endif
1010
include_HEADERS = include/secp256k1.h
11+
include_HEADERS += include/secp256k1_preallocated.h
1112
noinst_HEADERS =
1213
noinst_HEADERS += src/scalar.h
1314
noinst_HEADERS += src/scalar_4x64.h
@@ -150,11 +151,11 @@ endif
150151
endif
151152

152153
if USE_ECMULT_STATIC_PRECOMPUTATION
153-
CPPFLAGS_FOR_BUILD +=-I$(top_srcdir)
154+
CPPFLAGS_FOR_BUILD +=-I$(top_srcdir) -I$(builddir)/src
154155

155156
gen_context_OBJECTS = gen_context.o
156157
gen_context_BIN = gen_context$(BUILD_EXEEXT)
157-
gen_%.o: src/gen_%.c
158+
gen_%.o: src/gen_%.c src/libsecp256k1-config.h
158159
$(CC_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -c $< -o $@
159160

160161
$(gen_context_BIN): $(gen_context_OBJECTS)
@@ -177,6 +178,10 @@ if ENABLE_MODULE_ECDH
177178
include src/modules/ecdh/Makefile.am.include
178179
endif
179180

181+
if ENABLE_MODULE_SCHNORRSIG
182+
include src/modules/schnorrsig/Makefile.am.include
183+
endif
184+
180185
if ENABLE_MODULE_RECOVERY
181186
include src/modules/recovery/Makefile.am.include
182187
endif

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ Implementation details
4545
* Optionally (off by default) use secp256k1's efficiently-computable endomorphism to split the P multiplicand into 2 half-sized ones.
4646
* Point multiplication for signing
4747
* Use a precomputed table of multiples of powers of 16 multiplied with the generator, so general multiplication becomes a series of additions.
48-
* Access the table with branch-free conditional moves so memory access is uniform.
49-
* No data-dependent branches
48+
* Intended to be completely free of timing sidechannels for secret-key operations (on reasonable hardware/toolchains)
49+
* Access the table with branch-free conditional moves so memory access is uniform.
50+
* No data-dependent branches
51+
* Optional runtime blinding which attempts to frustrate differential power analysis.
5052
* The precomputed tables add and eventually subtract points for which no known scalar (private key) is known, preventing even an attacker with control over the private key used to control the data internally.
5153

5254
Build steps
@@ -57,5 +59,14 @@ libsecp256k1 is built using autotools:
5759
$ ./autogen.sh
5860
$ ./configure
5961
$ make
60-
$ ./tests
62+
$ make check
6163
$ sudo make install # optional
64+
65+
Exhaustive tests
66+
-----------
67+
68+
$ ./exhaustive_tests
69+
70+
With valgrind, you might need to increase the max stack size:
71+
72+
$ valgrind --max-stackframe=2500000 ./exhaustive_tests

configure.ac

Lines changed: 114 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -85,42 +85,42 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
8585
])
8686

8787
AC_ARG_ENABLE(benchmark,
88-
AS_HELP_STRING([--enable-benchmark],[compile benchmark (default is yes)]),
88+
AS_HELP_STRING([--enable-benchmark],[compile benchmark [default=yes]]),
8989
[use_benchmark=$enableval],
9090
[use_benchmark=yes])
9191

9292
AC_ARG_ENABLE(coverage,
93-
AS_HELP_STRING([--enable-coverage],[enable compiler flags to support kcov coverage analysis]),
93+
AS_HELP_STRING([--enable-coverage],[enable compiler flags to support kcov coverage analysis [default=no]]),
9494
[enable_coverage=$enableval],
9595
[enable_coverage=no])
9696

9797
AC_ARG_ENABLE(tests,
98-
AS_HELP_STRING([--enable-tests],[compile tests (default is yes)]),
98+
AS_HELP_STRING([--enable-tests],[compile tests [default=yes]]),
9999
[use_tests=$enableval],
100100
[use_tests=yes])
101101

102102
AC_ARG_ENABLE(openssl_tests,
103-
AS_HELP_STRING([--enable-openssl-tests],[enable OpenSSL tests, if OpenSSL is available (default is auto)]),
103+
AS_HELP_STRING([--enable-openssl-tests],[enable OpenSSL tests [default=auto]]),
104104
[enable_openssl_tests=$enableval],
105105
[enable_openssl_tests=auto])
106106

107107
AC_ARG_ENABLE(experimental,
108-
AS_HELP_STRING([--enable-experimental],[allow experimental configure options (default is no)]),
108+
AS_HELP_STRING([--enable-experimental],[allow experimental configure options [default=no]]),
109109
[use_experimental=$enableval],
110110
[use_experimental=no])
111111

112112
AC_ARG_ENABLE(exhaustive_tests,
113-
AS_HELP_STRING([--enable-exhaustive-tests],[compile exhaustive tests (default is yes)]),
113+
AS_HELP_STRING([--enable-exhaustive-tests],[compile exhaustive tests [default=yes]]),
114114
[use_exhaustive_tests=$enableval],
115115
[use_exhaustive_tests=yes])
116116

117117
AC_ARG_ENABLE(endomorphism,
118-
AS_HELP_STRING([--enable-endomorphism],[enable endomorphism (default is no)]),
118+
AS_HELP_STRING([--enable-endomorphism],[enable endomorphism [default=no]]),
119119
[use_endomorphism=$enableval],
120120
[use_endomorphism=no])
121121

122122
AC_ARG_ENABLE(ecmult_static_precomputation,
123-
AS_HELP_STRING([--enable-ecmult-static-precomputation],[enable precomputed ecmult table for signing (default is yes)]),
123+
AS_HELP_STRING([--enable-ecmult-static-precomputation],[enable precomputed ecmult table for signing [default=auto]]),
124124
[use_ecmult_static_precomputation=$enableval],
125125
[use_ecmult_static_precomputation=auto])
126126

@@ -129,34 +129,61 @@ AC_ARG_ENABLE(module_ecdh,
129129
[enable_module_ecdh=$enableval],
130130
[enable_module_ecdh=no])
131131

132+
AC_ARG_ENABLE(module_schnorrsig,
133+
AS_HELP_STRING([--enable-module-schnorrsig],[enable schnorrsig module (experimental)]),
134+
[enable_module_schnorrsig=$enableval],
135+
[enable_module_schnorrsig=no])
136+
132137
AC_ARG_ENABLE(module_recovery,
133-
AS_HELP_STRING([--enable-module-recovery],[enable ECDSA pubkey recovery module (default is no)]),
138+
AS_HELP_STRING([--enable-module-recovery],[enable ECDSA pubkey recovery module [default=no]]),
134139
[enable_module_recovery=$enableval],
135140
[enable_module_recovery=no])
136141

142+
AC_ARG_ENABLE(external_default_callbacks,
143+
AS_HELP_STRING([--enable-external-default-callbacks],[enable external default callback functions [default=no]]),
144+
[use_external_default_callbacks=$enableval],
145+
[use_external_default_callbacks=no])
146+
137147
AC_ARG_ENABLE(jni,
138-
AS_HELP_STRING([--enable-jni],[enable libsecp256k1_jni (default is no)]),
148+
AS_HELP_STRING([--enable-jni],[enable libsecp256k1_jni [default=no]]),
139149
[use_jni=$enableval],
140150
[use_jni=no])
141151

142152
AC_ARG_WITH([field], [AS_HELP_STRING([--with-field=64bit|32bit|auto],
143-
[Specify Field Implementation. Default is auto])],[req_field=$withval], [req_field=auto])
153+
[finite field implementation to use [default=auto]])],[req_field=$withval], [req_field=auto])
144154

145155
AC_ARG_WITH([bignum], [AS_HELP_STRING([--with-bignum=gmp|no|auto],
146-
[Specify Bignum Implementation. Default is auto])],[req_bignum=$withval], [req_bignum=auto])
156+
[bignum implementation to use [default=auto]])],[req_bignum=$withval], [req_bignum=auto])
147157

148158
AC_ARG_WITH([scalar], [AS_HELP_STRING([--with-scalar=64bit|32bit|auto],
149-
[Specify scalar implementation. Default is auto])],[req_scalar=$withval], [req_scalar=auto])
150-
151-
AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|arm|no|auto]
152-
[Specify assembly optimizations to use. Default is auto (experimental: arm)])],[req_asm=$withval], [req_asm=auto])
159+
[scalar implementation to use [default=auto]])],[req_scalar=$withval], [req_scalar=auto])
160+
161+
AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|arm|no|auto],
162+
[assembly optimizations to use (experimental: arm) [default=auto]])],[req_asm=$withval], [req_asm=auto])
163+
164+
AC_ARG_WITH([ecmult-window], [AS_HELP_STRING([--with-ecmult-window=SIZE|auto],
165+
[window size for ecmult precomputation for verification, specified as integer in range [2..24].]
166+
[Larger values result in possibly better performance at the cost of an exponentially larger precomputed table.]
167+
[The table will store 2^(SIZE-2) * 64 bytes of data but can be larger in memory due to platform-specific padding and alignment.]
168+
[If the endomorphism optimization is enabled, two tables of this size are used instead of only one.]
169+
["auto" is a reasonable setting for desktop machines (currently 15). [default=auto]]
170+
)],
171+
[req_ecmult_window=$withval], [req_ecmult_window=auto])
172+
173+
AC_ARG_WITH([ecmult-gen-precision], [AS_HELP_STRING([--with-ecmult-gen-precision=2|4|8|auto],
174+
[Precision bits to tune the precomputed table size for signing.]
175+
[The size of the table is 32kB for 2 bits, 64kB for 4 bits, 512kB for 8 bits of precision.]
176+
[A larger table size usually results in possible faster signing.]
177+
["auto" is a reasonable setting for desktop machines (currently 4). [default=auto]]
178+
)],
179+
[req_ecmult_gen_precision=$withval], [req_ecmult_gen_precision=auto])
153180

154181
AC_CHECK_TYPES([__int128])
155182

156183
if test x"$enable_coverage" = x"yes"; then
157184
AC_DEFINE(COVERAGE, 1, [Define this symbol to compile out all VERIFY code])
158185
CFLAGS="$CFLAGS -O0 --coverage"
159-
LDFLAGS="--coverage"
186+
LDFLAGS="$LDFLAGS --coverage"
160187
else
161188
CFLAGS="$CFLAGS -O3"
162189
fi
@@ -387,6 +414,44 @@ case $set_scalar in
387414
;;
388415
esac
389416

417+
#set ecmult window size
418+
if test x"$req_ecmult_window" = x"auto"; then
419+
set_ecmult_window=15
420+
else
421+
set_ecmult_window=$req_ecmult_window
422+
fi
423+
424+
error_window_size=['window size for ecmult precomputation not an integer in range [2..24] or "auto"']
425+
case $set_ecmult_window in
426+
''|*[[!0-9]]*)
427+
# no valid integer
428+
AC_MSG_ERROR($error_window_size)
429+
;;
430+
*)
431+
if test "$set_ecmult_window" -lt 2 -o "$set_ecmult_window" -gt 24 ; then
432+
# not in range
433+
AC_MSG_ERROR($error_window_size)
434+
fi
435+
AC_DEFINE_UNQUOTED(ECMULT_WINDOW_SIZE, $set_ecmult_window, [Set window size for ecmult precomputation])
436+
;;
437+
esac
438+
439+
#set ecmult gen precision
440+
if test x"$req_ecmult_gen_precision" = x"auto"; then
441+
set_ecmult_gen_precision=4
442+
else
443+
set_ecmult_gen_precision=$req_ecmult_gen_precision
444+
fi
445+
446+
case $set_ecmult_gen_precision in
447+
2|4|8)
448+
AC_DEFINE_UNQUOTED(ECMULT_GEN_PREC_BITS, $set_ecmult_gen_precision, [Set ecmult gen precision bits])
449+
;;
450+
*)
451+
AC_MSG_ERROR(['ecmult gen precision not 2, 4, 8 or "auto"'])
452+
;;
453+
esac
454+
390455
if test x"$use_tests" = x"yes"; then
391456
SECP_OPENSSL_CHECK
392457
if test x"$has_openssl_ec" = x"yes"; then
@@ -452,6 +517,10 @@ if test x"$enable_module_ecdh" = x"yes"; then
452517
AC_DEFINE(ENABLE_MODULE_ECDH, 1, [Define this symbol to enable the ECDH module])
453518
fi
454519

520+
if test x"$enable_module_schnorrsig" = x"yes"; then
521+
AC_DEFINE(ENABLE_MODULE_SCHNORRSIG, 1, [Define this symbol to enable the schnorrsig module])
522+
fi
523+
455524
if test x"$enable_module_recovery" = x"yes"; then
456525
AC_DEFINE(ENABLE_MODULE_RECOVERY, 1, [Define this symbol to enable the ECDSA pubkey recovery module])
457526
fi
@@ -462,16 +531,24 @@ if test x"$use_external_asm" = x"yes"; then
462531
AC_DEFINE(USE_EXTERNAL_ASM, 1, [Define this symbol if an external (non-inline) assembly implementation is used])
463532
fi
464533

534+
if test x"$use_external_default_callbacks" = x"yes"; then
535+
AC_DEFINE(USE_EXTERNAL_DEFAULT_CALLBACKS, 1, [Define this symbol if an external implementation of the default callbacks is used])
536+
fi
537+
465538
if test x"$enable_experimental" = x"yes"; then
466539
AC_MSG_NOTICE([******])
467540
AC_MSG_NOTICE([WARNING: experimental build])
468541
AC_MSG_NOTICE([Experimental features do not have stable APIs or properties, and may not be safe for production use.])
469542
AC_MSG_NOTICE([Building ECDH module: $enable_module_ecdh])
543+
AC_MSG_NOTICE([Building schnorrsig module: $enable_module_schnorrsig])
470544
AC_MSG_NOTICE([******])
471545
else
472546
if test x"$enable_module_ecdh" = x"yes"; then
473547
AC_MSG_ERROR([ECDH module is experimental. Use --enable-experimental to allow.])
474548
fi
549+
if test x"$enable_module_schnorrsig" = x"yes"; then
550+
AC_MSG_ERROR([schnorrsig module is experimental. Use --enable-experimental to allow.])
551+
fi
475552
if test x"$set_asm" = x"arm"; then
476553
AC_MSG_ERROR([ARM assembly optimization is experimental. Use --enable-experimental to allow.])
477554
fi
@@ -490,6 +567,7 @@ AM_CONDITIONAL([USE_EXHAUSTIVE_TESTS], [test x"$use_exhaustive_tests" != x"no"])
490567
AM_CONDITIONAL([USE_BENCHMARK], [test x"$use_benchmark" = x"yes"])
491568
AM_CONDITIONAL([USE_ECMULT_STATIC_PRECOMPUTATION], [test x"$set_precomp" = x"yes"])
492569
AM_CONDITIONAL([ENABLE_MODULE_ECDH], [test x"$enable_module_ecdh" = x"yes"])
570+
AM_CONDITIONAL([ENABLE_MODULE_SCHNORRSIG], [test x"$enable_module_schnorrsig" = x"yes"])
493571
AM_CONDITIONAL([ENABLE_MODULE_RECOVERY], [test x"$enable_module_recovery" = x"yes"])
494572
AM_CONDITIONAL([USE_JNI], [test x"$use_jni" = x"yes"])
495573
AM_CONDITIONAL([USE_EXTERNAL_ASM], [test x"$use_external_asm" = x"yes"])
@@ -504,21 +582,25 @@ AC_OUTPUT
504582

505583
echo
506584
echo "Build Options:"
507-
echo " with endomorphism = $use_endomorphism"
508-
echo " with ecmult precomp = $set_precomp"
509-
echo " with jni = $use_jni"
510-
echo " with benchmarks = $use_benchmark"
511-
echo " with coverage = $enable_coverage"
512-
echo " module ecdh = $enable_module_ecdh"
513-
echo " module recovery = $enable_module_recovery"
585+
echo " with endomorphism = $use_endomorphism"
586+
echo " with ecmult precomp = $set_precomp"
587+
echo " with external callbacks = $use_external_default_callbacks"
588+
echo " with jni = $use_jni"
589+
echo " with benchmarks = $use_benchmark"
590+
echo " with coverage = $enable_coverage"
591+
echo " module ecdh = $enable_module_ecdh"
592+
echo " module recovery = $enable_module_recovery"
593+
echo " module schnorrsig = $enable_module_schnorrsig"
514594
echo
515-
echo " asm = $set_asm"
516-
echo " bignum = $set_bignum"
517-
echo " field = $set_field"
518-
echo " scalar = $set_scalar"
595+
echo " asm = $set_asm"
596+
echo " bignum = $set_bignum"
597+
echo " field = $set_field"
598+
echo " scalar = $set_scalar"
599+
echo " ecmult window size = $set_ecmult_window"
600+
echo " ecmult gen prec. bits = $set_ecmult_gen_precision"
519601
echo
520-
echo " CC = $CC"
521-
echo " CFLAGS = $CFLAGS"
522-
echo " CPPFLAGS = $CPPFLAGS"
523-
echo " LDFLAGS = $LDFLAGS"
602+
echo " CC = $CC"
603+
echo " CFLAGS = $CFLAGS"
604+
echo " CPPFLAGS = $CPPFLAGS"
605+
echo " LDFLAGS = $LDFLAGS"
524606
echo

contrib/lax_der_parsing.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1_ecdsa_
3232
lenbyte = input[pos++];
3333
if (lenbyte & 0x80) {
3434
lenbyte -= 0x80;
35-
if (pos + lenbyte > inputlen) {
35+
if (lenbyte > inputlen - pos) {
3636
return 0;
3737
}
3838
pos += lenbyte;
@@ -51,7 +51,7 @@ int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1_ecdsa_
5151
lenbyte = input[pos++];
5252
if (lenbyte & 0x80) {
5353
lenbyte -= 0x80;
54-
if (pos + lenbyte > inputlen) {
54+
if (lenbyte > inputlen - pos) {
5555
return 0;
5656
}
5757
while (lenbyte > 0 && input[pos] == 0) {
@@ -89,7 +89,7 @@ int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1_ecdsa_
8989
lenbyte = input[pos++];
9090
if (lenbyte & 0x80) {
9191
lenbyte -= 0x80;
92-
if (pos + lenbyte > inputlen) {
92+
if (lenbyte > inputlen - pos) {
9393
return 0;
9494
}
9595
while (lenbyte > 0 && input[pos] == 0) {

0 commit comments

Comments
 (0)