Skip to content

Commit 31abd3a

Browse files
committed
Support OpenSSL versions >= 1.1 for ENABLE_OPENSSL_TESTS
The only reason OpenSSL 1.1 was not supported was the removal of direct access to r and s in ECDSA_SIG. This commit adds a simplified version of ECDSA_SIG_get0 for < 1.1 that can be used like ECDSA_SIG_get0 in >= 1.1
1 parent c95f6f1 commit 31abd3a

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

build-aux/m4/bitcoin_secp.m4

-1
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/tests.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include "openssl/ec.h"
2424
#include "openssl/ecdsa.h"
2525
#include "openssl/obj_mac.h"
26+
# if OPENSSL_VERSION_NUMBER < 0x10100000L
27+
void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps) {*pr = sig->r; *ps = sig->s;}
28+
# endif
2629
#endif
2730

2831
#include "contrib/lax_der_parsing.c"
@@ -4150,6 +4153,7 @@ int test_ecdsa_der_parse(const unsigned char *sig, size_t siglen, int certainly_
41504153

41514154
#ifdef ENABLE_OPENSSL_TESTS
41524155
ECDSA_SIG *sig_openssl;
4156+
const BIGNUM *r = NULL, *s = NULL;
41534157
const unsigned char *sigptr;
41544158
unsigned char roundtrip_openssl[2048];
41554159
int len_openssl = 2048;
@@ -4201,15 +4205,16 @@ int test_ecdsa_der_parse(const unsigned char *sig, size_t siglen, int certainly_
42014205
sigptr = sig;
42024206
parsed_openssl = (d2i_ECDSA_SIG(&sig_openssl, &sigptr, siglen) != NULL);
42034207
if (parsed_openssl) {
4204-
valid_openssl = !BN_is_negative(sig_openssl->r) && !BN_is_negative(sig_openssl->s) && BN_num_bits(sig_openssl->r) > 0 && BN_num_bits(sig_openssl->r) <= 256 && BN_num_bits(sig_openssl->s) > 0 && BN_num_bits(sig_openssl->s) <= 256;
4208+
ECDSA_SIG_get0(sig_openssl, &r, &s);
4209+
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;
42054210
if (valid_openssl) {
42064211
unsigned char tmp[32] = {0};
4207-
BN_bn2bin(sig_openssl->r, tmp + 32 - BN_num_bytes(sig_openssl->r));
4212+
BN_bn2bin(r, tmp + 32 - BN_num_bytes(r));
42084213
valid_openssl = memcmp(tmp, max_scalar, 32) < 0;
42094214
}
42104215
if (valid_openssl) {
42114216
unsigned char tmp[32] = {0};
4212-
BN_bn2bin(sig_openssl->s, tmp + 32 - BN_num_bytes(sig_openssl->s));
4217+
BN_bn2bin(s, tmp + 32 - BN_num_bytes(s));
42134218
valid_openssl = memcmp(tmp, max_scalar, 32) < 0;
42144219
}
42154220
}

0 commit comments

Comments
 (0)