Skip to content

Commit 3967d96

Browse files
Merge #838: Make autotools check for all the used openssl functions
3734b68 Configure echo if openssl tests are enabled (Elichai Turkel) e669277 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 (Elichai Turkel) Pull request description: I added all the openssl functions that we call in `tests.c` and in `bench_verify.c` to the m4 check, that way if any of them are missing it won't enable openssl. I also modified it a little to prevent a segmentation fault when running that program (not that it really matters for autotools) This should fix #836 ACKs for top commit: sipa: ACK 3734b68 real-or-random: ACK 3734b68 Tree-SHA512: c82aa96a4176061284dfa5fdb87ca874a25aa2e11f75c4ec6d1edebcc8a19e2bc940990f8a5cfa64776fd295b6fd3a140fa2afede29326564504bc8d1a3a6b69
2 parents 6f54e69 + 3734b68 commit 3967d96

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -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
@@ -503,6 +504,8 @@ echo "Build Options:"
503504
echo " with ecmult precomp = $set_precomp"
504505
echo " with external callbacks = $use_external_default_callbacks"
505506
echo " with benchmarks = $use_benchmark"
507+
echo " with tests = $use_tests"
508+
echo " with openssl tests = $enable_openssl_tests"
506509
echo " with coverage = $enable_coverage"
507510
echo " module ecdh = $enable_module_ecdh"
508511
echo " module recovery = $enable_module_recovery"

0 commit comments

Comments
 (0)