Skip to content

Commit d24ecf2

Browse files
committed
Merge #482: update secp to secp-zkp 53ad841cafa3bcb94b65409aec91fd7043533cf7
2d465aa Squashed 'src/secp256k1/' changes from 0b70241..53ad841 (Gregory Sanders)
2 parents 8a472b9 + ed1acfe commit d24ecf2

Some content is hidden

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

71 files changed

+7619
-364
lines changed

src/secp256k1/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
bench_inv
22
bench_ecdh
3+
bench_ecmult
34
bench_sign
45
bench_verify
56
bench_schnorr_verify

src/secp256k1/.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ 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
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
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
@@ -29,7 +29,7 @@ env:
2929
- BUILD=distcheck
3030
- EXTRAFLAGS=CPPFLAGS=-DDETERMINISTIC
3131
- EXTRAFLAGS=CFLAGS=-O0
32-
- BUILD=check-java ECDH=yes EXPERIMENTAL=yes
32+
- BUILD=check-java JNI=yes ECDH=yes EXPERIMENTAL=yes
3333
matrix:
3434
fast_finish: true
3535
include:
@@ -65,5 +65,5 @@ before_script: ./autogen.sh
6565
script:
6666
- if [ -n "$HOST" ]; then export USE_HOST="--host=$HOST"; fi
6767
- 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 $EXTRAFLAGS $USE_HOST && make -j2 $BUILD
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
6969
os: linux

src/secp256k1/Makefile.am

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ noinst_HEADERS += src/field_5x52_asm_impl.h
4242
noinst_HEADERS += src/java/org_bitcoin_NativeSecp256k1.h
4343
noinst_HEADERS += src/java/org_bitcoin_Secp256k1Context.h
4444
noinst_HEADERS += src/util.h
45+
noinst_HEADERS += src/scratch.h
46+
noinst_HEADERS += src/scratch_impl.h
4547
noinst_HEADERS += src/testrand.h
4648
noinst_HEADERS += src/testrand_impl.h
4749
noinst_HEADERS += src/hash.h
@@ -79,14 +81,17 @@ libsecp256k1_jni_la_CPPFLAGS = -DSECP256K1_BUILD $(JNI_INCLUDES)
7981

8082
noinst_PROGRAMS =
8183
if USE_BENCHMARK
82-
noinst_PROGRAMS += bench_verify bench_sign bench_internal
84+
noinst_PROGRAMS += bench_verify bench_sign bench_internal bench_ecmult
8385
bench_verify_SOURCES = src/bench_verify.c
8486
bench_verify_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
8587
bench_sign_SOURCES = src/bench_sign.c
8688
bench_sign_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
8789
bench_internal_SOURCES = src/bench_internal.c
8890
bench_internal_LDADD = $(SECP_LIBS) $(COMMON_LIB)
8991
bench_internal_CPPFLAGS = -DSECP256K1_BUILD $(SECP_INCLUDES)
92+
bench_ecmult_SOURCES = src/bench_ecmult.c
93+
bench_ecmult_LDADD = $(SECP_LIBS) $(COMMON_LIB)
94+
bench_ecmult_CPPFLAGS = -DSECP256K1_BUILD $(SECP_INCLUDES)
9095
endif
9196

9297
TESTS =
@@ -159,6 +164,7 @@ $(gen_context_BIN): $(gen_context_OBJECTS)
159164
$(libsecp256k1_la_OBJECTS): src/ecmult_static_context.h
160165
$(tests_OBJECTS): src/ecmult_static_context.h
161166
$(bench_internal_OBJECTS): src/ecmult_static_context.h
167+
$(bench_ecmult_OBJECTS): src/ecmult_static_context.h
162168

163169
src/ecmult_static_context.h: $(gen_context_BIN)
164170
./$(gen_context_BIN)
@@ -175,3 +181,19 @@ endif
175181
if ENABLE_MODULE_RECOVERY
176182
include src/modules/recovery/Makefile.am.include
177183
endif
184+
185+
if ENABLE_MODULE_GENERATOR
186+
include src/modules/generator/Makefile.am.include
187+
endif
188+
189+
if ENABLE_MODULE_RANGEPROOF
190+
include src/modules/rangeproof/Makefile.am.include
191+
endif
192+
193+
if ENABLE_MODULE_WHITELIST
194+
include src/modules/whitelist/Makefile.am.include
195+
endif
196+
197+
if ENABLE_MODULE_SURJECTIONPROOF
198+
include src/modules/surjection/Makefile.am.include
199+
endif

src/secp256k1/build-aux/m4/ax_jni_include_dir.m4

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ===========================================================================
2-
# http://www.gnu.org/software/autoconf-archive/ax_jni_include_dir.html
2+
# https://www.gnu.org/software/autoconf-archive/ax_jni_include_dir.html
33
# ===========================================================================
44
#
55
# SYNOPSIS
@@ -44,7 +44,7 @@
4444
# and this notice are preserved. This file is offered as-is, without any
4545
# warranty.
4646

47-
#serial 10
47+
#serial 14
4848

4949
AU_ALIAS([AC_JNI_INCLUDE_DIR], [AX_JNI_INCLUDE_DIR])
5050
AC_DEFUN([AX_JNI_INCLUDE_DIR],[
@@ -66,40 +66,45 @@ else
6666
fi
6767
6868
case "$host_os" in
69-
darwin*) _JTOPDIR=`echo "$_JTOPDIR" | sed -e 's:/[[^/]]*$::'`
70-
_JINC="$_JTOPDIR/Headers";;
71-
*) _JINC="$_JTOPDIR/include";;
69+
darwin*) # Apple Java headers are inside the Xcode bundle.
70+
macos_version=$(sw_vers -productVersion | sed -n -e 's/^@<:@0-9@:>@*.\(@<:@0-9@:>@*\).@<:@0-9@:>@*/\1/p')
71+
if @<:@ "$macos_version" -gt "7" @:>@; then
72+
_JTOPDIR="$(xcrun --show-sdk-path)/System/Library/Frameworks/JavaVM.framework"
73+
_JINC="$_JTOPDIR/Headers"
74+
else
75+
_JTOPDIR="/System/Library/Frameworks/JavaVM.framework"
76+
_JINC="$_JTOPDIR/Headers"
77+
fi
78+
;;
79+
*) _JINC="$_JTOPDIR/include";;
7280
esac
7381
_AS_ECHO_LOG([_JTOPDIR=$_JTOPDIR])
7482
_AS_ECHO_LOG([_JINC=$_JINC])
7583
7684
# On Mac OS X 10.6.4, jni.h is a symlink:
7785
# /System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers/jni.h
7886
# -> ../../CurrentJDK/Headers/jni.h.
79-
8087
AC_CACHE_CHECK(jni headers, ac_cv_jni_header_path,
8188
[
82-
if test -f "$_JINC/jni.h"; then
83-
ac_cv_jni_header_path="$_JINC"
84-
JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $ac_cv_jni_header_path"
85-
else
86-
_JTOPDIR=`echo "$_JTOPDIR" | sed -e 's:/[[^/]]*$::'`
87-
if test -f "$_JTOPDIR/include/jni.h"; then
88-
ac_cv_jni_header_path="$_JTOPDIR/include"
89+
if test -f "$_JINC/jni.h"; then
90+
ac_cv_jni_header_path="$_JINC"
8991
JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $ac_cv_jni_header_path"
9092
else
91-
ac_cv_jni_header_path=none
93+
_JTOPDIR=`echo "$_JTOPDIR" | sed -e 's:/[[^/]]*$::'`
94+
if test -f "$_JTOPDIR/include/jni.h"; then
95+
ac_cv_jni_header_path="$_JTOPDIR/include"
96+
JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $ac_cv_jni_header_path"
97+
else
98+
ac_cv_jni_header_path=none
99+
fi
92100
fi
93-
fi
94101
])
95102
96-
97-
98103
# get the likely subdirectories for system specific java includes
99104
case "$host_os" in
100105
bsdi*) _JNI_INC_SUBDIRS="bsdos";;
101-
darwin*) _JNI_INC_SUBDIRS="darwin";;
102106
freebsd*) _JNI_INC_SUBDIRS="freebsd";;
107+
darwin*) _JNI_INC_SUBDIRS="darwin";;
103108
linux*) _JNI_INC_SUBDIRS="linux genunix";;
104109
osf*) _JNI_INC_SUBDIRS="alpha";;
105110
solaris*) _JNI_INC_SUBDIRS="solaris";;
@@ -112,9 +117,9 @@ if test "x$ac_cv_jni_header_path" != "xnone"; then
112117
# add any subdirectories that are present
113118
for JINCSUBDIR in $_JNI_INC_SUBDIRS
114119
do
115-
if test -d "$_JTOPDIR/include/$JINCSUBDIR"; then
116-
JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $_JTOPDIR/include/$JINCSUBDIR"
117-
fi
120+
if test -d "$_JTOPDIR/include/$JINCSUBDIR"; then
121+
JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $_JTOPDIR/include/$JINCSUBDIR"
122+
fi
118123
done
119124
fi
120125
])

src/secp256k1/build-aux/m4/bitcoin_secp.m4

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ if test x"$has_libcrypto" = x"yes" && test x"$has_openssl_ec" = x; then
4848
EC_KEY_free(eckey);
4949
ECDSA_SIG *sig_openssl;
5050
sig_openssl = ECDSA_SIG_new();
51-
(void)sig_openssl->r;
5251
ECDSA_SIG_free(sig_openssl);
5352
]])],[has_openssl_ec=yes],[has_openssl_ec=no])
5453
AC_MSG_RESULT([$has_openssl_ec])

src/secp256k1/configure.ac

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ 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 no)]),
88+
AS_HELP_STRING([--enable-benchmark],[compile benchmark (default is yes)]),
8989
[use_benchmark=$enableval],
90-
[use_benchmark=no])
90+
[use_benchmark=yes])
9191

9292
AC_ARG_ENABLE(coverage,
9393
AS_HELP_STRING([--enable-coverage],[enable compiler flags to support kcov coverage analysis]),
@@ -134,10 +134,30 @@ AC_ARG_ENABLE(module_recovery,
134134
[enable_module_recovery=$enableval],
135135
[enable_module_recovery=no])
136136

137+
AC_ARG_ENABLE(module_generator,
138+
AS_HELP_STRING([--enable-module-generator],[enable NUMS generator module (default is no)]),
139+
[enable_module_generator=$enableval],
140+
[enable_module_generator=no])
141+
142+
AC_ARG_ENABLE(module_rangeproof,
143+
AS_HELP_STRING([--enable-module-rangeproof],[enable Pedersen / zero-knowledge range proofs module (default is no)]),
144+
[enable_module_rangeproof=$enableval],
145+
[enable_module_rangeproof=no])
146+
147+
AC_ARG_ENABLE(module_whitelist,
148+
AS_HELP_STRING([--enable-module-whitelist],[enable key whitelisting module (default is no)]),
149+
[enable_module_whitelist=$enableval],
150+
[enable_module_whitelist=no])
151+
137152
AC_ARG_ENABLE(jni,
138-
AS_HELP_STRING([--enable-jni],[enable libsecp256k1_jni (default is auto)]),
153+
AS_HELP_STRING([--enable-jni],[enable libsecp256k1_jni (default is no)]),
139154
[use_jni=$enableval],
140-
[use_jni=auto])
155+
[use_jni=no])
156+
157+
AC_ARG_ENABLE(module_surjectionproof,
158+
AS_HELP_STRING([--enable-module-surjectionproof],[enable surjection proof module (default is no)]),
159+
[enable_module_surjectionproof=$enableval],
160+
[enable_module_surjectionproof=no])
141161

142162
AC_ARG_WITH([field], [AS_HELP_STRING([--with-field=64bit|32bit|auto],
143163
[Specify Field Implementation. Default is auto])],[req_field=$withval], [req_field=auto])
@@ -167,6 +187,12 @@ else
167187
CFLAGS="$CFLAGS -O3"
168188
fi
169189

190+
AC_MSG_CHECKING([for __builtin_popcount])
191+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[void myfunc() {__builtin_popcount(0);}]])],
192+
[ AC_MSG_RESULT([yes]);AC_DEFINE(HAVE_BUILTIN_POPCOUNT,1,[Define this symbol if __builtin_popcount is available]) ],
193+
[ AC_MSG_RESULT([no])
194+
])
195+
170196
if test x"$use_ecmult_static_precomputation" != x"no"; then
171197
save_cross_compiling=$cross_compiling
172198
cross_compiling=no
@@ -195,6 +221,12 @@ else
195221
set_precomp=no
196222
fi
197223

224+
AC_MSG_CHECKING([for __builtin_clzll])
225+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[void myfunc() { __builtin_clzll(1);}]])],
226+
[ AC_MSG_RESULT([yes]);AC_DEFINE(HAVE_BUILTIN_CLZLL,1,[Define this symbol if __builtin_clzll is available]) ],
227+
[ AC_MSG_RESULT([no])
228+
])
229+
198230
if test x"$req_asm" = x"auto"; then
199231
SECP_64BIT_ASM_CHECK
200232
if test x"$has_64bit_asm" = x"yes"; then
@@ -435,6 +467,22 @@ if test x"$enable_module_recovery" = x"yes"; then
435467
AC_DEFINE(ENABLE_MODULE_RECOVERY, 1, [Define this symbol to enable the ECDSA pubkey recovery module])
436468
fi
437469

470+
if test x"$enable_module_generator" = x"yes"; then
471+
AC_DEFINE(ENABLE_MODULE_GENERATOR, 1, [Define this symbol to enable the NUMS generator module])
472+
fi
473+
474+
if test x"$enable_module_rangeproof" = x"yes"; then
475+
AC_DEFINE(ENABLE_MODULE_RANGEPROOF, 1, [Define this symbol to enable the Pedersen / zero knowledge range proof module])
476+
fi
477+
478+
if test x"$enable_module_whitelist" = x"yes"; then
479+
AC_DEFINE(ENABLE_MODULE_WHITELIST, 1, [Define this symbol to enable the key whitelisting module])
480+
fi
481+
482+
if test x"$enable_module_surjectionproof" = x"yes"; then
483+
AC_DEFINE(ENABLE_MODULE_SURJECTIONPROOF, 1, [Define this symbol to enable the surjection proof module])
484+
fi
485+
438486
AC_C_BIGENDIAN()
439487

440488
if test x"$use_external_asm" = x"yes"; then
@@ -447,6 +495,7 @@ AC_MSG_NOTICE([Using field implementation: $set_field])
447495
AC_MSG_NOTICE([Using bignum implementation: $set_bignum])
448496
AC_MSG_NOTICE([Using scalar implementation: $set_scalar])
449497
AC_MSG_NOTICE([Using endomorphism optimizations: $use_endomorphism])
498+
AC_MSG_NOTICE([Building benchmarks: $use_benchmark])
450499
AC_MSG_NOTICE([Building for coverage analysis: $enable_coverage])
451500
AC_MSG_NOTICE([Building ECDH module: $enable_module_ecdh])
452501
AC_MSG_NOTICE([Building ECDSA pubkey recovery module: $enable_module_recovery])
@@ -457,14 +506,45 @@ if test x"$enable_experimental" = x"yes"; then
457506
AC_MSG_NOTICE([WARNING: experimental build])
458507
AC_MSG_NOTICE([Experimental features do not have stable APIs or properties, and may not be safe for production use.])
459508
AC_MSG_NOTICE([Building ECDH module: $enable_module_ecdh])
509+
AC_MSG_NOTICE([Building NUMS generator module: $enable_module_generator])
510+
AC_MSG_NOTICE([Building range proof module: $enable_module_rangeproof])
511+
AC_MSG_NOTICE([Building key whitelisting module: $enable_module_whitelist])
512+
AC_MSG_NOTICE([Building surjection proof module: $enable_module_surjectionproof])
460513
AC_MSG_NOTICE([******])
514+
515+
if test x"$enable_module_generator" != x"yes"; then
516+
if test x"$enable_module_rangeproof" = x"yes"; then
517+
AC_MSG_ERROR([Rangeproof module requires the generator module. Use --enable-module-generator to allow.])
518+
fi
519+
fi
520+
521+
if test x"$enable_module_rangeproof" != x"yes"; then
522+
if test x"$enable_module_whitelist" = x"yes"; then
523+
AC_MSG_ERROR([Whitelist module requires the rangeproof module. Use --enable-module-rangeproof to allow.])
524+
fi
525+
if test x"$enable_module_surjectionproof" = x"yes"; then
526+
AC_MSG_ERROR([Surjection proof module requires the rangeproof module. Use --enable-module-rangeproof to allow.])
527+
fi
528+
fi
461529
else
462530
if test x"$enable_module_ecdh" = x"yes"; then
463531
AC_MSG_ERROR([ECDH module is experimental. Use --enable-experimental to allow.])
464532
fi
465533
if test x"$set_asm" = x"arm"; then
466534
AC_MSG_ERROR([ARM assembly optimization is experimental. Use --enable-experimental to allow.])
467535
fi
536+
if test x"$enable_module_generator" = x"yes"; then
537+
AC_MSG_ERROR([NUMS generator module is experimental. Use --enable-experimental to allow.])
538+
fi
539+
if test x"$enable_module_rangeproof" = x"yes"; then
540+
AC_MSG_ERROR([Range proof module is experimental. Use --enable-experimental to allow.])
541+
fi
542+
if test x"$enable_module_whitelist" = x"yes"; then
543+
AC_MSG_ERROR([Key whitelisting module is experimental. Use --enable-experimental to allow.])
544+
fi
545+
if test x"$enable_module_surjectionproof" = x"yes"; then
546+
AC_MSG_ERROR([Surjection proof module is experimental. Use --enable-experimental to allow.])
547+
fi
468548
fi
469549

470550
AC_CONFIG_HEADERS([src/libsecp256k1-config.h])
@@ -481,9 +561,13 @@ AM_CONDITIONAL([USE_BENCHMARK], [test x"$use_benchmark" = x"yes"])
481561
AM_CONDITIONAL([USE_ECMULT_STATIC_PRECOMPUTATION], [test x"$set_precomp" = x"yes"])
482562
AM_CONDITIONAL([ENABLE_MODULE_ECDH], [test x"$enable_module_ecdh" = x"yes"])
483563
AM_CONDITIONAL([ENABLE_MODULE_RECOVERY], [test x"$enable_module_recovery" = x"yes"])
564+
AM_CONDITIONAL([ENABLE_MODULE_GENERATOR], [test x"$enable_module_generator" = x"yes"])
565+
AM_CONDITIONAL([ENABLE_MODULE_RANGEPROOF], [test x"$enable_module_rangeproof" = x"yes"])
566+
AM_CONDITIONAL([ENABLE_MODULE_WHITELIST], [test x"$enable_module_whitelist" = x"yes"])
484567
AM_CONDITIONAL([USE_JNI], [test x"$use_jni" == x"yes"])
485568
AM_CONDITIONAL([USE_EXTERNAL_ASM], [test x"$use_external_asm" = x"yes"])
486569
AM_CONDITIONAL([USE_ASM_ARM], [test x"$set_asm" = x"arm"])
570+
AM_CONDITIONAL([ENABLE_MODULE_SURJECTIONPROOF], [test x"$enable_module_surjectionproof" = x"yes"])
487571

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

0 commit comments

Comments
 (0)