Skip to content

Commit 6c0aecf

Browse files
Merge #174: Upstream PRs 1064, 1049, 899, 1068, 1072, 1069, 1074, 1026, 1033, 748, 1079, 1088, 1090, 731, 1089, 995, 1094, 1093
645d9c5 examples: let musig use random.h instead of /dev/urandom (Jonas Nick) eccba5b examples: relicense musig example to CC0 public domain (Jonas Nick) 7c5af74 ci: fix missing EXPERIMENTAL flags (Jonas Nick) 03bea1e configure: add -zkp modules to dev-mode and remove redundant code (Jonas Nick) 2adb741 examples: rename example_musig to musig_example for consistency (Jonas Nick) 37d3692 tests: Add tests for _read_be32 and _write_be32 (Tim Ruffing) 616b43d util: Remove endianness detection (Tim Ruffing) 8d89b9e hash: Make code agnostic of endianness (Tim Ruffing) 55512d3 doc: clean up module help text in configure.ac (Elliott Jin) d9d94a9 doc: mention optional modules in README (Elliott Jin) 7f09d0f README: mention that ARM assembly is experimental (Jonas Nick) 80cf4ee build: stop treating schnorrsig, extrakeys modules as experimental (Jonas Nick) b8f8b99 docs: Fix return value for functions that don't have invalid inputs (Tim Ruffing) f813bb0 schnorrsig: Adapt example to new API (Tim Ruffing) 99e6568 schnorrsig: Rename schnorrsig_sign to schnorsig_sign32 and deprecate (Tim Ruffing) fc94a2d Use SECP256K1_DEPRECATED for existing deprecated API functions (Tim Ruffing) 3db0560 Add SECP256K1_DEPRECATED attribute for marking API parts as deprecated (Tim Ruffing) f8d9174 Add SHA256 bit counter tests (Tim Ruffing) 9b514ce Add test vector for very long SHA256 messages (Tim Ruffing) 8e3dde1 Simplify struct initializer for SHA256 padding (Tim Ruffing) eb28464 Change SHA256 byte counter from size_t to uint64_t (Tim Ruffing) 21b2eba configure: Remove redundant pkg-config code (Tim Ruffing) 0d253d5 configure: Use modern way to set AR (Tim Ruffing) e0838d6 configure: Add hidden --enable-dev-mode to enable all the stuff (Tim Ruffing) fabd579 configure: Remove redundant code that sets _enable variables (Tim Ruffing) 0d4226c configure: Use canonical variable prefix _enable consistently (Tim Ruffing) 7c9502c Add a copy of the CC0 license to the examples (Elichai Turkel) 42e0343 Add usage examples to the readme (Elichai Turkel) 517644e Optionally compile the examples in autotools, compile+run in travis (Elichai Turkel) 422a7cc Add a ecdh shared secret example (Elichai Turkel) b0cfbcc Add a Schnorr signing and verifying example (Elichai Turkel) fee7d4b Add an ECDSA signing and verifying example (Elichai Turkel) e848c37 Update sage files for new formulae (Peter Dettman) d64bb5d Add fe_half tests for worst-case inputs (Peter Dettman) 4eb8b93 Further improve doubling formula using fe_half (Peter Dettman) 557b31f Doubling formula using fe_half (Pieter Wuille) 2cbb4b1 Run more iterations of run_field_misc (Pieter Wuille) 9cc5c25 Add test for secp256k1_fe_half (Pieter Wuille) 925f78d Add _fe_half and use in _gej_add_ge (Peter Dettman) 3531a43 ecdh: Make generator_basepoint test depend on global iteration count (Tim Ruffing) c881dd4 ecdh: Add test computing shared_secret=basepoint with random inputs (Tim Ruffing) e51ad3b ci: Retry `brew update` a few times to avoid random failures (Tim Ruffing) b1cb969 ci: Revert "Attempt to make macOS builds more reliable" (Tim Ruffing) e0db3f8 build: Replace use of deprecated autoconf macro AC_PROG_CC_C89 (laanwj) d9396a5 ci: Attempt to make macOS builds more reliable (Tim Ruffing) ebb1bee sage: Ensure that constraints are always fastfracs (Tim Ruffing) d8d5485 ci: Run sage prover on CI (Tim Ruffing) 77cfa98 sage: Normalize sign of polynomial factors in prover (Tim Ruffing) eae7586 sage: Exit with non-zero status in case of failures (Tim Ruffing) b54d843 sage: Fix printing of errors (Tim Ruffing) e108d00 sage: Fix incompatibility with sage 9.4 (Tim Ruffing) b797a50 Create a SECP256K1_ECMULT_TABLE_VERIFY macro. (Russell O'Connor) a731200 Replace ECMULT_TABLE_GET_GE_STORAGE macro with a function. (Russell O'Connor) fe34d9f Eliminate input_pos state field from ecmult_strauss_wnaf. (Russell O'Connor) 0397d00 Eliminate na_1 and na_lam state fields from ecmult_strauss_wnaf. (Russell O'Connor) 7ba3ffc Remove the unused pre_a_lam allocations. (Russell O'Connor) b3b57ad Eliminate the pre_a_lam array from ecmult_strauss_wnaf. (Russell O'Connor) ae7ba0f Remove the unused prej allocations. (Russell O'Connor) e5c1889 Eliminate the prej array from ecmult_strauss_wnaf. (Russell O'Connor) c9da1ba Move secp256k1_fe_one to field.h (Russell O'Connor) 070e772 Faster fixed-input ecmult tests (Pieter Wuille) 45f37b6 Modulo-reduce msg32 inside RFC6979 nonce fn to match spec. Fixes #1063. (Paul Miller) Pull request description: [bitcoin-core/secp256k1#1064]: Modulo-reduce msg32 inside RFC6979 nonce fn to match spec. Fixes #1063 [bitcoin-core/secp256k1#1049]: Faster fixed-input ecmult tests [bitcoin-core/secp256k1#899]: Reduce stratch space needed by ecmult_strauss_wnaf. [bitcoin-core/secp256k1#1068]: sage: Fix incompatibility with sage 9.4 [bitcoin-core/secp256k1#1072]: ci: Attempt to make macOS builds more reliable [bitcoin-core/secp256k1#1069]: build: Replace use of deprecated autoconf macro AC_PROG_CC_C89 [bitcoin-core/secp256k1#1074]: ci: Retry brew update a few times to avoid random failures [bitcoin-core/secp256k1#1026]: ecdh: Add test computing shared_secret=basepoint with random inputs [bitcoin-core/secp256k1#1033]: Add _fe_half and use in _gej_add_ge and _gej_double [bitcoin-core/secp256k1#748]: Add usage examples [bitcoin-core/secp256k1#1079]: configure: Add hidden --enable-dev-mode to enable all the stuff [bitcoin-core/secp256k1#1088]: configure: Use modern way to set AR [bitcoin-core/secp256k1#1090]: configure: Remove redundant pkg-config code [bitcoin-core/secp256k1#731]: Change SHA256 byte counter from size_t to uint64_t [bitcoin-core/secp256k1#1089]: Schnorrsig API improvements [bitcoin-core/secp256k1#995]: build: stop treating schnorrsig, extrakeys modules as experimental [bitcoin-core/secp256k1#1094]: doc: Clarify configure flags for optional modules [bitcoin-core/secp256k1#1093]: hash: Make code agnostic of endianness This PR can be recreated with `./sync-upstream.sh range 8746600`. ACKs for top commit: real-or-random: ACK 645d9c5 I rederived the tree, and tested it with MSVC, including the musig example Tree-SHA512: 3b771630806ed8481053958c21820dce6e869371833cd18a5c430a2768bda8064ad2bb247afbe38e3fa37320a8b1dbbe65ad68c8963efb995d96aa29ae574884
2 parents eafcd04 + 645d9c5 commit 6c0aecf

38 files changed

+1711
-443
lines changed

.cirrus.yml

+19-14
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ env:
2828
BENCH: yes
2929
SECP256K1_BENCH_ITERS: 2
3030
CTIMETEST: yes
31+
# Compile and run the tests
32+
EXAMPLES: yes
3133

3234
cat_logs_snippet: &CAT_LOGS
3335
always:
@@ -70,12 +72,12 @@ task:
7072
<< : *LINUX_CONTAINER
7173
matrix: &ENV_MATRIX
7274
- env: {WIDEMUL: int64, RECOVERY: yes}
73-
- env: {WIDEMUL: int64, ECDH: yes, EXPERIMENTAL: yes, SCHNORRSIG: yes, ECDSA_S2C: yes, RANGEPROOF: yes, WHITELIST: yes, GENERATOR: yes, MUSIG: yes, ECDSAADAPTOR: yes}
75+
- env: {WIDEMUL: int64, ECDH: yes, SCHNORRSIG: yes, EXPERIMENTAL: yes, ECDSA_S2C: yes, RANGEPROOF: yes, WHITELIST: yes, GENERATOR: yes, MUSIG: yes, ECDSAADAPTOR: yes}
7476
- env: {WIDEMUL: int128}
75-
- env: {WIDEMUL: int128, RECOVERY: yes, EXPERIMENTAL: yes, SCHNORRSIG: yes}
76-
- env: {WIDEMUL: int128, ECDH: yes, EXPERIMENTAL: yes, SCHNORRSIG: yes, ECDSA_S2C: yes, RANGEPROOF: yes, WHITELIST: yes, GENERATOR: yes, MUSIG: yes, ECDSAADAPTOR: yes}
77+
- env: {WIDEMUL: int128, RECOVERY: yes, SCHNORRSIG: yes}
78+
- env: {WIDEMUL: int128, ECDH: yes, SCHNORRSIG: yes, EXPERIMENTAL: yes, ECDSA_S2C: yes, RANGEPROOF: yes, WHITELIST: yes, GENERATOR: yes, MUSIG: yes, ECDSAADAPTOR: yes}
7779
- env: {WIDEMUL: int128, ASM: x86_64}
78-
- env: { RECOVERY: yes, EXPERIMENTAL: yes, SCHNORRSIG: yes, ECDSA_S2C: yes, RANGEPROOF: yes, WHITELIST: yes, GENERATOR: yes, MUSIG: yes, ECDSAADAPTOR: yes}
80+
- env: { RECOVERY: yes, SCHNORRSIG: yes, EXPERIMENTAL: yes, ECDSA_S2C: yes, RANGEPROOF: yes, WHITELIST: yes, GENERATOR: yes, MUSIG: yes, ECDSAADAPTOR: yes}
7981
- env: {BUILD: distcheck, WITH_VALGRIND: no, CTIMETEST: no, BENCH: no}
8082
- env: {CPPFLAGS: -DDETERMINISTIC}
8183
- env: {CFLAGS: -O0, CTIMETEST: no}
@@ -98,8 +100,8 @@ task:
98100
HOST: i686-linux-gnu
99101
ECDH: yes
100102
RECOVERY: yes
101-
EXPERIMENTAL: yes
102103
SCHNORRSIG: yes
104+
EXPERIMENTAL: yes
103105
ECDSA_S2C: yes
104106
RANGEPROOF: yes
105107
WHITELIST: yes
@@ -148,7 +150,8 @@ task:
148150
## - rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
149151
##
150152
brew_valgrind_pre_script:
151-
- brew update
153+
# Retry a few times because this tends to fail randomly.
154+
- for i in {1..5}; do brew update && break || sleep 15; done
152155
- brew config
153156
- brew tap LouisBrunner/valgrind
154157
# Fetch valgrind source but don't build it yet.
@@ -188,8 +191,8 @@ task:
188191
WITH_VALGRIND: no
189192
ECDH: yes
190193
RECOVERY: yes
191-
EXPERIMENTAL: yes
192194
SCHNORRSIG: yes
195+
EXPERIMENTAL: yes
193196
ECDSA_S2C: yes
194197
RANGEPROOF: yes
195198
WHITELIST: yes
@@ -214,12 +217,11 @@ task:
214217
WITH_VALGRIND: no
215218
ECDH: yes
216219
RECOVERY: yes
217-
EXPERIMENTAL: yes
218220
SCHNORRSIG: yes
219221
CTIMETEST: no
220222
matrix:
221223
- env: {}
222-
- env: {ASM: arm}
224+
- env: {EXPERIMENTAL: yes, ASM: arm}
223225
<< : *MERGE_BASE
224226
test_script:
225227
- ./ci/cirrus.sh
@@ -235,7 +237,6 @@ task:
235237
WITH_VALGRIND: no
236238
ECDH: yes
237239
RECOVERY: yes
238-
EXPERIMENTAL: yes
239240
SCHNORRSIG: yes
240241
CTIMETEST: no
241242
<< : *MERGE_BASE
@@ -253,7 +254,6 @@ task:
253254
WITH_VALGRIND: no
254255
ECDH: yes
255256
RECOVERY: yes
256-
EXPERIMENTAL: yes
257257
SCHNORRSIG: yes
258258
CTIMETEST: no
259259
<< : *MERGE_BASE
@@ -271,7 +271,6 @@ task:
271271
WITH_VALGRIND: no
272272
ECDH: yes
273273
RECOVERY: yes
274-
EXPERIMENTAL: yes
275274
SCHNORRSIG: yes
276275
CTIMETEST: no
277276
<< : *MERGE_BASE
@@ -286,8 +285,8 @@ task:
286285
env:
287286
ECDH: yes
288287
RECOVERY: yes
289-
EXPERIMENTAL: yes
290288
SCHNORRSIG: yes
289+
EXPERIMENTAL: yes
291290
ECDSA_S2C: yes
292291
RANGEPROOF: yes
293292
WHITELIST: yes
@@ -340,11 +339,17 @@ task:
340339
CC: gcc
341340
MAKEFLAGS: -j4 CC=g++ CFLAGS=-fpermissive\ -g
342341
WERROR_CFLAGS:
343-
EXPERIMENTAL: yes
344342
ECDH: yes
345343
RECOVERY: yes
346344
SCHNORRSIG: yes
347345
<< : *MERGE_BASE
348346
test_script:
349347
- ./ci/cirrus.sh
350348
<< : *CAT_LOGS
349+
350+
task:
351+
name: "sage prover"
352+
<< : *LINUX_CONTAINER
353+
test_script:
354+
- cd sage
355+
- sage prove_group_implementations.sage

.gitignore

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ exhaustive_tests
88
precompute_ecmult_gen
99
precompute_ecmult
1010
valgrind_ctime_test
11+
ecdh_example
12+
ecdsa_example
13+
schnorr_example
1114
*.exe
1215
*.so
1316
*.a
1417
*.csv
1518
!.gitignore
19+
*.log
20+
*.trs
1621

1722
Makefile
1823
configure
@@ -43,6 +48,7 @@ coverage.*.html
4348

4449
src/libsecp256k1-config.h
4550
src/libsecp256k1-config.h.in
51+
build-aux/ar-lib
4652
build-aux/config.guess
4753
build-aux/config.sub
4854
build-aux/depcomp
@@ -60,4 +66,4 @@ src/stamp-h1
6066
libsecp256k1.pc
6167
contrib/gh-pr-create.sh
6268

63-
example_musig
69+
musig_example

Makefile.am

+43-6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ noinst_HEADERS += contrib/lax_der_parsing.h
6565
noinst_HEADERS += contrib/lax_der_parsing.c
6666
noinst_HEADERS += contrib/lax_der_privatekey_parsing.h
6767
noinst_HEADERS += contrib/lax_der_privatekey_parsing.c
68+
noinst_HEADERS += examples/random.h
6869

6970
PRECOMPUTED_LIB = libsecp256k1_precomputed.la
7071
noinst_LTLIBRARIES = $(PRECOMPUTED_LIB)
@@ -141,13 +142,49 @@ exhaustive_tests_LDFLAGS = -static
141142
TESTS += exhaustive_tests
142143
endif
143144

145+
if USE_EXAMPLES
146+
noinst_PROGRAMS += ecdsa_example
147+
ecdsa_example_SOURCES = examples/ecdsa.c
148+
ecdsa_example_CPPFLAGS = -I$(top_srcdir)/include
149+
ecdsa_example_LDADD = libsecp256k1.la
150+
ecdsa_example_LDFLAGS = -static
151+
if BUILD_WINDOWS
152+
ecdsa_example_LDFLAGS += -lbcrypt
153+
endif
154+
TESTS += ecdsa_example
155+
if ENABLE_MODULE_ECDH
156+
noinst_PROGRAMS += ecdh_example
157+
ecdh_example_SOURCES = examples/ecdh.c
158+
ecdh_example_CPPFLAGS = -I$(top_srcdir)/include
159+
ecdh_example_LDADD = libsecp256k1.la
160+
ecdh_example_LDFLAGS = -static
161+
if BUILD_WINDOWS
162+
ecdh_example_LDFLAGS += -lbcrypt
163+
endif
164+
TESTS += ecdh_example
165+
endif
166+
if ENABLE_MODULE_SCHNORRSIG
167+
noinst_PROGRAMS += schnorr_example
168+
schnorr_example_SOURCES = examples/schnorr.c
169+
schnorr_example_CPPFLAGS = -I$(top_srcdir)/include
170+
schnorr_example_LDADD = libsecp256k1.la
171+
schnorr_example_LDFLAGS = -static
172+
if BUILD_WINDOWS
173+
schnorr_example_LDFLAGS += -lbcrypt
174+
endif
175+
TESTS += schnorr_example
176+
endif
144177
if ENABLE_MODULE_MUSIG
145-
noinst_PROGRAMS += example_musig
146-
example_musig_SOURCES = examples/musig.c
147-
example_musig_CPPFLAGS = -I$(top_srcdir)/include
148-
example_musig_LDADD = libsecp256k1.la
149-
example_musig_LDFLAGS = -static
150-
TESTS += example_musig
178+
noinst_PROGRAMS += musig_example
179+
musig_example_SOURCES = examples/musig.c
180+
musig_example_CPPFLAGS = -I$(top_srcdir)/include
181+
musig_example_LDADD = libsecp256k1.la
182+
musig_example_LDFLAGS = -static
183+
if BUILD_WINDOWS
184+
musig_example_LDFLAGS += -lbcrypt
185+
endif
186+
TESTS += musig_example
187+
endif
151188
endif
152189

153190
### Precomputed tables

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Features:
1717
* Suitable for embedded systems.
1818
* Optional module for public key recovery.
1919
* Optional module for ECDH key exchange.
20-
* Optional module for Schnorr signatures according to [BIP-340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki) (experimental).
20+
* Optional module for Schnorr signatures according to [BIP-340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki).
2121
* Optional module for ECDSA adaptor signatures (experimental).
2222

2323
Experimental features have not received enough scrutiny to satisfy the standard of quality of this library but are made available for testing and review by the community. The APIs of these features should not be considered stable.
@@ -36,6 +36,7 @@ Implementation details
3636
* Optimized implementation of arithmetic modulo the curve's field size (2^256 - 0x1000003D1).
3737
* Using 5 52-bit limbs (including hand-optimized assembly for x86_64, by Diederik Huys).
3838
* Using 10 26-bit limbs (including hand-optimized assembly for 32-bit ARM, by Wladimir J. van der Laan).
39+
* This is an experimental feature that has not received enough scrutiny to satisfy the standard of quality of this library but is made available for testing and review by the community.
3940
* Scalar operations
4041
* Optimized implementation without data-dependent branches of arithmetic modulo the curve's order.
4142
* Using 4 64-bit limbs (relying on __int128 support in the compiler).
@@ -70,6 +71,16 @@ libsecp256k1 is built using autotools:
7071
$ make check # run the test suite
7172
$ sudo make install # optional
7273

74+
To compile optional modules (such as Schnorr signatures), you need to run `./configure` with additional flags (such as `--enable-module-schnorrsig`). Run `./configure --help` to see the full list of available flags.
75+
76+
Usage examples
77+
-----------
78+
Usage examples can be found in the [examples](examples) directory. To compile them you need to configure with `--enable-examples`.
79+
* [ECDSA example](examples/ecdsa.c)
80+
* [Schnorr signatures example](examples/schnorr.c)
81+
* [Deriving a shared secret (ECDH) example](examples/ecdh.c)
82+
To compile the Schnorr signature and ECDH examples, you also need to configure with `--enable-module-schnorrsig` and `--enable-module-ecdh`.
83+
7384
Test coverage
7485
-----------
7586

build-aux/m4/bitcoin_secp.m4

+13
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,16 @@ AC_DEFUN([SECP_TRY_APPEND_CFLAGS], [
3838
unset flag_works
3939
AC_SUBST($2)
4040
])
41+
42+
dnl SECP_SET_DEFAULT(VAR, default, default-dev-mode)
43+
dnl Set VAR to default or default-dev-mode, depending on whether dev mode is enabled
44+
AC_DEFUN([SECP_SET_DEFAULT], [
45+
if test "${enable_dev_mode+set}" != set; then
46+
AC_MSG_ERROR([[Set enable_dev_mode before calling SECP_SET_DEFAULT]])
47+
fi
48+
if test x"$enable_dev_mode" = x"yes"; then
49+
$1="$3"
50+
else
51+
$1="$2"
52+
fi
53+
])

ci/cirrus.sh

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ valgrind --version || true
2121
--enable-module-ecdsa-s2c="$ECDSA_S2C" \
2222
--enable-module-rangeproof="$RANGEPROOF" --enable-module-whitelist="$WHITELIST" --enable-module-generator="$GENERATOR" \
2323
--enable-module-schnorrsig="$SCHNORRSIG" --enable-module-musig="$MUSIG" --enable-module-ecdsa-adaptor="$ECDSAADAPTOR" \
24+
--enable-module-schnorrsig="$SCHNORRSIG" \
25+
--enable-examples="$EXAMPLES" \
2426
--with-valgrind="$WITH_VALGRIND" \
2527
--host="$HOST" $EXTRAFLAGS
2628

ci/linux-debian.Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ RUN apt-get install --no-install-recommends --no-upgrade -y \
1919
gcc-arm-linux-gnueabihf libc6-dev-armhf-cross libc6-dbg:armhf \
2020
gcc-aarch64-linux-gnu libc6-dev-arm64-cross libc6-dbg:arm64 \
2121
gcc-powerpc64le-linux-gnu libc6-dev-ppc64el-cross libc6-dbg:ppc64el \
22-
wine gcc-mingw-w64-x86-64
22+
wine gcc-mingw-w64-x86-64 \
23+
sagemath
2324

2425
# Run a dummy command in wine to make it set up configuration
2526
RUN wine64-stable xcopy || true

0 commit comments

Comments
 (0)