Skip to content

Commit 6c0259f

Browse files
committed
Squashed 'src/secp256k1/' changes from c6b6b8f1bb..3967d96bf1
3967d96bf1 Merge #838: Make autotools check for all the used openssl functions 3734b68200 Configure echo if openssl tests are enabled 6f54e69f03 Merge #841: Avoids a potentially shortening size_t to int cast in strauss_wnaf_ 8893f42438 Avoids a potentially shortening size_t to int cast in strauss_wnaf_ e6692778d3 Modify bitcoin_secp.m4's openssl check to call all the functions that we use in the tests/benchmarks. That way linking will fail if those symbols are missing ac05f61fcf Merge #809: Stop treating ECDH as experimental e6e3d5da2f travis: add schnorrsig to valgrind and big endian platform test 353dff156f Stop treating ECDH as experimental git-subtree-dir: src/secp256k1 git-subtree-split: 3967d96bf184519eb98b766af665b4d4b072563e
1 parent 52380bf commit 6c0259f

File tree

5 files changed

+38
-16
lines changed

5 files changed

+38
-16
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ env:
3333
- CFLAGS=-O0 CTIMETEST=no
3434
- ECMULTGENPRECISION=2
3535
- ECMULTGENPRECISION=8
36-
- RUN_VALGRIND=yes BIGNUM=no ASM=x86_64 EXPERIMENTAL=yes ECDH=yes RECOVERY=yes EXTRAFLAGS="--disable-openssl-tests" BUILD=
36+
- RUN_VALGRIND=yes BIGNUM=no ASM=x86_64 ECDH=yes RECOVERY=yes EXPERIMENTAL=yes SCHNORRSIG=yes EXTRAFLAGS="--disable-openssl-tests" BUILD=
3737
matrix:
3838
fast_finish: true
3939
include:
@@ -81,7 +81,7 @@ matrix:
8181
- libc6-dbg:i386
8282
# S390x build (big endian system)
8383
- compiler: gcc
84-
env: HOST=s390x-unknown-linux-gnu ECDH=yes RECOVERY=yes EXPERIMENTAL=yes CTIMETEST=
84+
env: HOST=s390x-unknown-linux-gnu ECDH=yes RECOVERY=yes EXPERIMENTAL=yes SCHNORRSIG=yes CTIMETEST=
8585
arch: s390x
8686

8787
# We use this to install macOS dependencies instead of the built in `homebrew` plugin,

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Features:
1616
* Very efficient implementation.
1717
* Suitable for embedded systems.
1818
* Optional module for public key recovery.
19-
* Optional module for ECDH key exchange (experimental).
19+
* Optional module for ECDH key exchange.
2020

2121
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.
2222

build-aux/m4/bitcoin_secp.m4

+25-2
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,39 @@ if test x"$has_libcrypto" = x"yes" && test x"$has_openssl_ec" = x; then
3636
CPPFLAGS_TEMP="$CPPFLAGS"
3737
CPPFLAGS="$CRYPTO_CPPFLAGS $CPPFLAGS"
3838
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
39+
#include <openssl/bn.h>
3940
#include <openssl/ec.h>
4041
#include <openssl/ecdsa.h>
4142
#include <openssl/obj_mac.h>]],[[
42-
EC_KEY *eckey = EC_KEY_new_by_curve_name(NID_secp256k1);
43-
ECDSA_sign(0, NULL, 0, NULL, NULL, eckey);
43+
# if OPENSSL_VERSION_NUMBER < 0x10100000L
44+
void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps) {(void)sig->r; (void)sig->s;}
45+
# endif
46+
47+
unsigned int zero = 0;
48+
const unsigned char *zero_ptr = (unsigned char*)&zero;
49+
EC_KEY_free(EC_KEY_new_by_curve_name(NID_secp256k1));
50+
EC_KEY *eckey = EC_KEY_new();
51+
EC_GROUP *group = EC_GROUP_new_by_curve_name(NID_secp256k1);
52+
EC_KEY_set_group(eckey, group);
53+
ECDSA_sign(0, NULL, 0, NULL, &zero, eckey);
4454
ECDSA_verify(0, NULL, 0, NULL, 0, eckey);
55+
o2i_ECPublicKey(&eckey, &zero_ptr, 0);
56+
d2i_ECPrivateKey(&eckey, &zero_ptr, 0);
57+
EC_KEY_check_key(eckey);
4558
EC_KEY_free(eckey);
59+
EC_GROUP_free(group);
4660
ECDSA_SIG *sig_openssl;
4761
sig_openssl = ECDSA_SIG_new();
62+
d2i_ECDSA_SIG(&sig_openssl, &zero_ptr, 0);
63+
i2d_ECDSA_SIG(sig_openssl, NULL);
64+
ECDSA_SIG_get0(sig_openssl, NULL, NULL);
4865
ECDSA_SIG_free(sig_openssl);
66+
const BIGNUM *bignum = BN_value_one();
67+
BN_is_negative(bignum);
68+
BN_num_bits(bignum);
69+
if (sizeof(zero) >= BN_num_bytes(bignum)) {
70+
BN_bn2bin(bignum, (unsigned char*)&zero);
71+
}
4972
]])],[has_openssl_ec=yes],[has_openssl_ec=no])
5073
AC_MSG_RESULT([$has_openssl_ec])
5174
CPPFLAGS="$CPPFLAGS_TEMP"

configure.ac

+7-8
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ AC_ARG_ENABLE(ecmult_static_precomputation,
122122
[use_ecmult_static_precomputation=auto])
123123

124124
AC_ARG_ENABLE(module_ecdh,
125-
AS_HELP_STRING([--enable-module-ecdh],[enable ECDH shared secret computation (experimental)]),
125+
AS_HELP_STRING([--enable-module-ecdh],[enable ECDH shared secret computation]),
126126
[enable_module_ecdh=$enableval],
127127
[enable_module_ecdh=no])
128128

@@ -395,8 +395,8 @@ esac
395395

396396
if test x"$use_tests" = x"yes"; then
397397
SECP_OPENSSL_CHECK
398-
if test x"$has_openssl_ec" = x"yes"; then
399-
if test x"$enable_openssl_tests" != x"no"; then
398+
if test x"$enable_openssl_tests" != x"no" && test x"$has_openssl_ec" = x"yes"; then
399+
enable_openssl_tests=yes
400400
AC_DEFINE(ENABLE_OPENSSL_TESTS, 1, [Define this symbol if OpenSSL EC functions are available])
401401
SECP_TEST_INCLUDES="$SSL_CFLAGS $CRYPTO_CFLAGS $CRYPTO_CPPFLAGS"
402402
SECP_TEST_LIBS="$CRYPTO_LIBS"
@@ -406,16 +406,17 @@ if test x"$use_tests" = x"yes"; then
406406
SECP_TEST_LIBS="$SECP_TEST_LIBS -lgdi32"
407407
;;
408408
esac
409-
fi
410409
else
411410
if test x"$enable_openssl_tests" = x"yes"; then
412411
AC_MSG_ERROR([OpenSSL tests requested but OpenSSL with EC support is not available])
413412
fi
413+
enable_openssl_tests=no
414414
fi
415415
else
416416
if test x"$enable_openssl_tests" = x"yes"; then
417417
AC_MSG_ERROR([OpenSSL tests requested but tests are not enabled])
418418
fi
419+
enable_openssl_tests=no
419420
fi
420421

421422
if test x"$set_bignum" = x"gmp"; then
@@ -458,14 +459,10 @@ if test x"$enable_experimental" = x"yes"; then
458459
AC_MSG_NOTICE([******])
459460
AC_MSG_NOTICE([WARNING: experimental build])
460461
AC_MSG_NOTICE([Experimental features do not have stable APIs or properties, and may not be safe for production use.])
461-
AC_MSG_NOTICE([Building ECDH module: $enable_module_ecdh])
462462
AC_MSG_NOTICE([Building extrakeys module: $enable_module_extrakeys])
463463
AC_MSG_NOTICE([Building schnorrsig module: $enable_module_schnorrsig])
464464
AC_MSG_NOTICE([******])
465465
else
466-
if test x"$enable_module_ecdh" = x"yes"; then
467-
AC_MSG_ERROR([ECDH module is experimental. Use --enable-experimental to allow.])
468-
fi
469466
if test x"$enable_module_extrakeys" = x"yes"; then
470467
AC_MSG_ERROR([extrakeys module is experimental. Use --enable-experimental to allow.])
471468
fi
@@ -507,6 +504,8 @@ echo "Build Options:"
507504
echo " with ecmult precomp = $set_precomp"
508505
echo " with external callbacks = $use_external_default_callbacks"
509506
echo " with benchmarks = $use_benchmark"
507+
echo " with tests = $use_tests"
508+
echo " with openssl tests = $enable_openssl_tests"
510509
echo " with coverage = $enable_coverage"
511510
echo " module ecdh = $enable_module_ecdh"
512511
echo " module recovery = $enable_module_recovery"

src/ecmult_impl.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ struct secp256k1_strauss_state {
443443
struct secp256k1_strauss_point_state* ps;
444444
};
445445

446-
static void secp256k1_ecmult_strauss_wnaf(const secp256k1_ecmult_context *ctx, const struct secp256k1_strauss_state *state, secp256k1_gej *r, int num, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng) {
446+
static void secp256k1_ecmult_strauss_wnaf(const secp256k1_ecmult_context *ctx, const struct secp256k1_strauss_state *state, secp256k1_gej *r, size_t num, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng) {
447447
secp256k1_ge tmpa;
448448
secp256k1_fe Z;
449449
/* Splitted G factors. */
@@ -454,8 +454,8 @@ static void secp256k1_ecmult_strauss_wnaf(const secp256k1_ecmult_context *ctx, c
454454
int bits_ng_128 = 0;
455455
int i;
456456
int bits = 0;
457-
int np;
458-
int no = 0;
457+
size_t np;
458+
size_t no = 0;
459459

460460
for (np = 0; np < num; ++np) {
461461
if (secp256k1_scalar_is_zero(&na[np]) || secp256k1_gej_is_infinity(&a[np])) {

0 commit comments

Comments
 (0)