Skip to content

Commit bc08599

Browse files
committed
Remove OpenSSL testing support
1 parent 10f9bd8 commit bc08599

File tree

6 files changed

+0
-275
lines changed

6 files changed

+0
-275
lines changed

.cirrus.yml

-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ task:
285285
EXPERIMENTAL: yes
286286
SCHNORRSIG: yes
287287
CTIMETEST: no
288-
EXTRAFLAGS: "--disable-openssl-tests"
289288
matrix:
290289
- name: "Valgrind (memcheck)"
291290
env:

Makefile.am

-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ if USE_BENCHMARK
8484
noinst_PROGRAMS += bench_verify bench_sign bench_internal bench_ecmult
8585
bench_verify_SOURCES = src/bench_verify.c
8686
bench_verify_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
87-
# SECP_TEST_INCLUDES are only used here for CRYPTO_CPPFLAGS
88-
bench_verify_CPPFLAGS = $(SECP_TEST_INCLUDES)
8987
bench_sign_SOURCES = src/bench_sign.c
9088
bench_sign_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
9189
bench_internal_SOURCES = src/bench_internal.c

build-aux/m4/bitcoin_secp.m4

-66
Original file line numberDiff line numberDiff line change
@@ -9,72 +9,6 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
99
AC_MSG_RESULT([$has_64bit_asm])
1010
])
1111

12-
dnl
13-
AC_DEFUN([SECP_OPENSSL_CHECK],[
14-
has_libcrypto=no
15-
m4_ifdef([PKG_CHECK_MODULES],[
16-
PKG_CHECK_MODULES([CRYPTO], [libcrypto], [has_libcrypto=yes],[has_libcrypto=no])
17-
if test x"$has_libcrypto" = x"yes"; then
18-
TEMP_LIBS="$LIBS"
19-
LIBS="$LIBS $CRYPTO_LIBS"
20-
AC_CHECK_LIB(crypto, main,[AC_DEFINE(HAVE_LIBCRYPTO,1,[Define this symbol if libcrypto is installed])],[has_libcrypto=no])
21-
LIBS="$TEMP_LIBS"
22-
fi
23-
])
24-
if test x$has_libcrypto = xno; then
25-
AC_CHECK_HEADER(openssl/crypto.h,[
26-
AC_CHECK_LIB(crypto, main,[
27-
has_libcrypto=yes
28-
CRYPTO_LIBS=-lcrypto
29-
AC_DEFINE(HAVE_LIBCRYPTO,1,[Define this symbol if libcrypto is installed])
30-
])
31-
])
32-
LIBS=
33-
fi
34-
if test x"$has_libcrypto" = x"yes" && test x"$has_openssl_ec" = x; then
35-
AC_MSG_CHECKING(for EC functions in libcrypto)
36-
CPPFLAGS_TEMP="$CPPFLAGS"
37-
CPPFLAGS="$CRYPTO_CPPFLAGS $CPPFLAGS"
38-
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
39-
#include <openssl/bn.h>
40-
#include <openssl/ec.h>
41-
#include <openssl/ecdsa.h>
42-
#include <openssl/obj_mac.h>]],[[
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);
54-
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);
58-
EC_KEY_free(eckey);
59-
EC_GROUP_free(group);
60-
ECDSA_SIG *sig_openssl;
61-
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);
65-
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-
}
72-
]])],[has_openssl_ec=yes],[has_openssl_ec=no])
73-
AC_MSG_RESULT([$has_openssl_ec])
74-
CPPFLAGS="$CPPFLAGS_TEMP"
75-
fi
76-
])
77-
7812
AC_DEFUN([SECP_VALGRIND_CHECK],[
7913
if test x"$has_valgrind" != x"yes"; then
8014
CPPFLAGS_TEMP="$CPPFLAGS"

configure.ac

-38
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,7 @@ case $host_os in
4343
# These Homebrew packages may be keg-only, meaning that they won't be found
4444
# in expected paths because they may conflict with system files. Ask
4545
# Homebrew where each one is located, then adjust paths accordingly.
46-
openssl_prefix=`$BREW --prefix openssl 2>/dev/null`
4746
valgrind_prefix=`$BREW --prefix valgrind 2>/dev/null`
48-
if test x$openssl_prefix != x; then
49-
PKG_CONFIG_PATH="$openssl_prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
50-
export PKG_CONFIG_PATH
51-
CRYPTO_CPPFLAGS="-I$openssl_prefix/include"
52-
fi
5347
if test x$valgrind_prefix != x; then
5448
VALGRIND_CPPFLAGS="-I$valgrind_prefix/include"
5549
fi
@@ -121,11 +115,6 @@ AC_ARG_ENABLE(tests,
121115
[use_tests=$enableval],
122116
[use_tests=yes])
123117

124-
AC_ARG_ENABLE(openssl_tests,
125-
AS_HELP_STRING([--enable-openssl-tests],[enable OpenSSL tests [default=auto]]),
126-
[enable_openssl_tests=$enableval],
127-
[enable_openssl_tests=auto])
128-
129118
AC_ARG_ENABLE(experimental,
130119
AS_HELP_STRING([--enable-experimental],[allow experimental configure options [default=no]]),
131120
[use_experimental=$enableval],
@@ -329,32 +318,6 @@ case $set_ecmult_gen_precision in
329318
;;
330319
esac
331320

332-
if test x"$use_tests" = x"yes"; then
333-
SECP_OPENSSL_CHECK
334-
if test x"$enable_openssl_tests" != x"no" && test x"$has_openssl_ec" = x"yes"; then
335-
enable_openssl_tests=yes
336-
AC_DEFINE(ENABLE_OPENSSL_TESTS, 1, [Define this symbol if OpenSSL EC functions are available])
337-
SECP_TEST_INCLUDES="$SSL_CFLAGS $CRYPTO_CFLAGS $CRYPTO_CPPFLAGS"
338-
SECP_TEST_LIBS="$CRYPTO_LIBS"
339-
340-
case $host in
341-
*mingw*)
342-
SECP_TEST_LIBS="$SECP_TEST_LIBS -lgdi32"
343-
;;
344-
esac
345-
else
346-
if test x"$enable_openssl_tests" = x"yes"; then
347-
AC_MSG_ERROR([OpenSSL tests requested but OpenSSL with EC support is not available])
348-
fi
349-
enable_openssl_tests=no
350-
fi
351-
else
352-
if test x"$enable_openssl_tests" = x"yes"; then
353-
AC_MSG_ERROR([OpenSSL tests requested but tests are not enabled])
354-
fi
355-
enable_openssl_tests=no
356-
fi
357-
358321
if test x"$enable_valgrind" = x"yes"; then
359322
SECP_INCLUDES="$SECP_INCLUDES $VALGRIND_CPPFLAGS"
360323
fi
@@ -519,7 +482,6 @@ echo " with ecmult precomp = $set_precomp"
519482
echo " with external callbacks = $use_external_default_callbacks"
520483
echo " with benchmarks = $use_benchmark"
521484
echo " with tests = $use_tests"
522-
echo " with openssl tests = $enable_openssl_tests"
523485
echo " with coverage = $enable_coverage"
524486
echo " module ecdh = $enable_module_ecdh"
525487
echo " module recovery = $enable_module_recovery"

src/bench_verify.c

-45
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@
1111
#include "util.h"
1212
#include "bench.h"
1313

14-
#ifdef ENABLE_OPENSSL_TESTS
15-
#include <openssl/bn.h>
16-
#include <openssl/ecdsa.h>
17-
#include <openssl/obj_mac.h>
18-
#endif
19-
20-
2114
typedef struct {
2215
secp256k1_context *ctx;
2316
unsigned char msg[32];
@@ -26,9 +19,6 @@ typedef struct {
2619
size_t siglen;
2720
unsigned char pubkey[33];
2821
size_t pubkeylen;
29-
#ifdef ENABLE_OPENSSL_TESTS
30-
EC_GROUP* ec_group;
31-
#endif
3222
} bench_verify_data;
3323

3424
static void bench_verify(void* arg, int iters) {
@@ -50,36 +40,6 @@ static void bench_verify(void* arg, int iters) {
5040
}
5141
}
5242

53-
#ifdef ENABLE_OPENSSL_TESTS
54-
static void bench_verify_openssl(void* arg, int iters) {
55-
int i;
56-
bench_verify_data* data = (bench_verify_data*)arg;
57-
58-
for (i = 0; i < iters; i++) {
59-
data->sig[data->siglen - 1] ^= (i & 0xFF);
60-
data->sig[data->siglen - 2] ^= ((i >> 8) & 0xFF);
61-
data->sig[data->siglen - 3] ^= ((i >> 16) & 0xFF);
62-
{
63-
EC_KEY *pkey = EC_KEY_new();
64-
const unsigned char *pubkey = &data->pubkey[0];
65-
int result;
66-
67-
CHECK(pkey != NULL);
68-
result = EC_KEY_set_group(pkey, data->ec_group);
69-
CHECK(result);
70-
result = (o2i_ECPublicKey(&pkey, &pubkey, data->pubkeylen)) != NULL;
71-
CHECK(result);
72-
result = ECDSA_verify(0, &data->msg[0], sizeof(data->msg), &data->sig[0], data->siglen, pkey) == (i == 0);
73-
CHECK(result);
74-
EC_KEY_free(pkey);
75-
}
76-
data->sig[data->siglen - 1] ^= (i & 0xFF);
77-
data->sig[data->siglen - 2] ^= ((i >> 8) & 0xFF);
78-
data->sig[data->siglen - 3] ^= ((i >> 16) & 0xFF);
79-
}
80-
}
81-
#endif
82-
8343
int main(void) {
8444
int i;
8545
secp256k1_pubkey pubkey;
@@ -104,11 +64,6 @@ int main(void) {
10464
CHECK(secp256k1_ec_pubkey_serialize(data.ctx, data.pubkey, &data.pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED) == 1);
10565

10666
run_benchmark("ecdsa_verify", bench_verify, NULL, NULL, &data, 10, iters);
107-
#ifdef ENABLE_OPENSSL_TESTS
108-
data.ec_group = EC_GROUP_new_by_curve_name(NID_secp256k1);
109-
run_benchmark("ecdsa_verify_openssl", bench_verify_openssl, NULL, NULL, &data, 10, iters);
110-
EC_GROUP_free(data.ec_group);
111-
#endif
11267

11368
secp256k1_context_destroy(data.ctx);
11469
return 0;

src/tests.c

-123
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@
2020
#include "testrand_impl.h"
2121
#include "util.h"
2222

23-
#ifdef ENABLE_OPENSSL_TESTS
24-
#include <openssl/bn.h>
25-
#include <openssl/ec.h>
26-
#include <openssl/ecdsa.h>
27-
#include <openssl/obj_mac.h>
28-
# if OPENSSL_VERSION_NUMBER < 0x10100000L
29-
void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps) {*pr = sig->r; *ps = sig->s;}
30-
# endif
31-
#endif
32-
3323
#include "../contrib/lax_der_parsing.c"
3424
#include "../contrib/lax_der_privatekey_parsing.c"
3525

@@ -5685,14 +5675,6 @@ void run_ecdsa_end_to_end(void) {
56855675

56865676
int test_ecdsa_der_parse(const unsigned char *sig, size_t siglen, int certainly_der, int certainly_not_der) {
56875677
static const unsigned char zeroes[32] = {0};
5688-
#ifdef ENABLE_OPENSSL_TESTS
5689-
static const unsigned char max_scalar[32] = {
5690-
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
5691-
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
5692-
0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b,
5693-
0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x40
5694-
};
5695-
#endif
56965678

56975679
int ret = 0;
56985680

@@ -5708,15 +5690,6 @@ int test_ecdsa_der_parse(const unsigned char *sig, size_t siglen, int certainly_
57085690
size_t len_der_lax = 2048;
57095691
int parsed_der_lax = 0, valid_der_lax = 0, roundtrips_der_lax = 0;
57105692

5711-
#ifdef ENABLE_OPENSSL_TESTS
5712-
ECDSA_SIG *sig_openssl;
5713-
const BIGNUM *r = NULL, *s = NULL;
5714-
const unsigned char *sigptr;
5715-
unsigned char roundtrip_openssl[2048];
5716-
int len_openssl = 2048;
5717-
int parsed_openssl, valid_openssl = 0, roundtrips_openssl = 0;
5718-
#endif
5719-
57205693
parsed_der = secp256k1_ecdsa_signature_parse_der(ctx, &sig_der, sig, siglen);
57215694
if (parsed_der) {
57225695
ret |= (!secp256k1_ecdsa_signature_serialize_compact(ctx, compact_der, &sig_der)) << 0;
@@ -5757,43 +5730,6 @@ int test_ecdsa_der_parse(const unsigned char *sig, size_t siglen, int certainly_
57575730
ret |= (!parsed_der_lax) << 16;
57585731
}
57595732

5760-
#ifdef ENABLE_OPENSSL_TESTS
5761-
sig_openssl = ECDSA_SIG_new();
5762-
sigptr = sig;
5763-
parsed_openssl = (d2i_ECDSA_SIG(&sig_openssl, &sigptr, siglen) != NULL);
5764-
if (parsed_openssl) {
5765-
ECDSA_SIG_get0(sig_openssl, &r, &s);
5766-
valid_openssl = !BN_is_negative(r) && !BN_is_negative(s) && BN_num_bits(r) > 0 && BN_num_bits(r) <= 256 && BN_num_bits(s) > 0 && BN_num_bits(s) <= 256;
5767-
if (valid_openssl) {
5768-
unsigned char tmp[32] = {0};
5769-
BN_bn2bin(r, tmp + 32 - BN_num_bytes(r));
5770-
valid_openssl = secp256k1_memcmp_var(tmp, max_scalar, 32) < 0;
5771-
}
5772-
if (valid_openssl) {
5773-
unsigned char tmp[32] = {0};
5774-
BN_bn2bin(s, tmp + 32 - BN_num_bytes(s));
5775-
valid_openssl = secp256k1_memcmp_var(tmp, max_scalar, 32) < 0;
5776-
}
5777-
}
5778-
len_openssl = i2d_ECDSA_SIG(sig_openssl, NULL);
5779-
if (len_openssl <= 2048) {
5780-
unsigned char *ptr = roundtrip_openssl;
5781-
CHECK(i2d_ECDSA_SIG(sig_openssl, &ptr) == len_openssl);
5782-
roundtrips_openssl = valid_openssl && ((size_t)len_openssl == siglen) && (secp256k1_memcmp_var(roundtrip_openssl, sig, siglen) == 0);
5783-
} else {
5784-
len_openssl = 0;
5785-
}
5786-
ECDSA_SIG_free(sig_openssl);
5787-
5788-
ret |= (parsed_der && !parsed_openssl) << 4;
5789-
ret |= (valid_der && !valid_openssl) << 5;
5790-
ret |= (roundtrips_openssl && !parsed_der) << 6;
5791-
ret |= (roundtrips_der != roundtrips_openssl) << 7;
5792-
if (roundtrips_openssl) {
5793-
ret |= (len_der != (size_t)len_openssl) << 8;
5794-
ret |= ((len_der != (size_t)len_openssl) || (secp256k1_memcmp_var(roundtrip_der, roundtrip_openssl, len_der) != 0)) << 9;
5795-
}
5796-
#endif
57975733
return ret;
57985734
}
57995735

@@ -6387,62 +6323,6 @@ void run_ecdsa_edge_cases(void) {
63876323
test_ecdsa_edge_cases();
63886324
}
63896325

6390-
#ifdef ENABLE_OPENSSL_TESTS
6391-
EC_KEY *get_openssl_key(const unsigned char *key32) {
6392-
unsigned char privkey[300];
6393-
size_t privkeylen;
6394-
const unsigned char* pbegin = privkey;
6395-
int compr = secp256k1_testrand_bits(1);
6396-
EC_KEY *ec_key = EC_KEY_new_by_curve_name(NID_secp256k1);
6397-
CHECK(ec_privkey_export_der(ctx, privkey, &privkeylen, key32, compr));
6398-
CHECK(d2i_ECPrivateKey(&ec_key, &pbegin, privkeylen));
6399-
CHECK(EC_KEY_check_key(ec_key));
6400-
return ec_key;
6401-
}
6402-
6403-
void test_ecdsa_openssl(void) {
6404-
secp256k1_gej qj;
6405-
secp256k1_ge q;
6406-
secp256k1_scalar sigr, sigs;
6407-
secp256k1_scalar one;
6408-
secp256k1_scalar msg2;
6409-
secp256k1_scalar key, msg;
6410-
EC_KEY *ec_key;
6411-
unsigned int sigsize = 80;
6412-
size_t secp_sigsize = 80;
6413-
unsigned char message[32];
6414-
unsigned char signature[80];
6415-
unsigned char key32[32];
6416-
secp256k1_testrand256_test(message);
6417-
secp256k1_scalar_set_b32(&msg, message, NULL);
6418-
random_scalar_order_test(&key);
6419-
secp256k1_scalar_get_b32(key32, &key);
6420-
secp256k1_ecmult_gen(&ctx->ecmult_gen_ctx, &qj, &key);
6421-
secp256k1_ge_set_gej(&q, &qj);
6422-
ec_key = get_openssl_key(key32);
6423-
CHECK(ec_key != NULL);
6424-
CHECK(ECDSA_sign(0, message, sizeof(message), signature, &sigsize, ec_key));
6425-
CHECK(secp256k1_ecdsa_sig_parse(&sigr, &sigs, signature, sigsize));
6426-
CHECK(secp256k1_ecdsa_sig_verify(&sigr, &sigs, &q, &msg));
6427-
secp256k1_scalar_set_int(&one, 1);
6428-
secp256k1_scalar_add(&msg2, &msg, &one);
6429-
CHECK(!secp256k1_ecdsa_sig_verify(&sigr, &sigs, &q, &msg2));
6430-
6431-
random_sign(&sigr, &sigs, &key, &msg, NULL);
6432-
CHECK(secp256k1_ecdsa_sig_serialize(signature, &secp_sigsize, &sigr, &sigs));
6433-
CHECK(ECDSA_verify(0, message, sizeof(message), signature, secp_sigsize, ec_key) == 1);
6434-
6435-
EC_KEY_free(ec_key);
6436-
}
6437-
6438-
void run_ecdsa_openssl(void) {
6439-
int i;
6440-
for (i = 0; i < 10*count; i++) {
6441-
test_ecdsa_openssl();
6442-
}
6443-
}
6444-
#endif
6445-
64466326
#ifdef ENABLE_MODULE_ECDH
64476327
# include "modules/ecdh/tests_impl.h"
64486328
#endif
@@ -6729,9 +6609,6 @@ int main(int argc, char **argv) {
67296609
run_ecdsa_sign_verify();
67306610
run_ecdsa_end_to_end();
67316611
run_ecdsa_edge_cases();
6732-
#ifdef ENABLE_OPENSSL_TESTS
6733-
run_ecdsa_openssl();
6734-
#endif
67356612

67366613
#ifdef ENABLE_MODULE_RECOVERY
67376614
/* ECDSA pubkey recovery tests */

0 commit comments

Comments
 (0)