tools: libressl: fix build on MacOS
[oweals/openwrt.git] / tools / mkimage / patches / 200-rsa-sign-add-support-for-libressl.patch
1 From 69176c8602e29f4bd30457240374800d88dc39ed Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sat, 14 Apr 2018 22:39:34 +0200
4 Subject: [PATCH] rsa-sign: add support for libressl
5
6 ---
7  lib/rsa/rsa-sign.c | 15 +++++++++------
8  1 file changed, 9 insertions(+), 6 deletions(-)
9
10 --- a/lib/rsa/rsa-sign.c
11 +++ b/lib/rsa/rsa-sign.c
12 @@ -21,7 +21,8 @@
13  #define HAVE_ERR_REMOVE_THREAD_STATE
14  #endif
15  
16 -#if OPENSSL_VERSION_NUMBER < 0x10100000L
17 +#if OPENSSL_VERSION_NUMBER < 0x10100000L || \
18 +    (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x2070000fL)
19  static void RSA_get0_key(const RSA *r,
20                   const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
21  {
22 @@ -300,7 +301,8 @@ static int rsa_init(void)
23  {
24         int ret;
25  
26 -#if OPENSSL_VERSION_NUMBER < 0x10100000L
27 +#if OPENSSL_VERSION_NUMBER < 0x10100000L || \
28 +    (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x2070000fL)
29         ret = SSL_library_init();
30  #else
31         ret = OPENSSL_init_ssl(0, NULL);
32 @@ -309,7 +311,7 @@ static int rsa_init(void)
33                 fprintf(stderr, "Failure to init SSL library\n");
34                 return -1;
35         }
36 -#if OPENSSL_VERSION_NUMBER < 0x10100000L
37 +#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
38         SSL_load_error_strings();
39  
40         OpenSSL_add_all_algorithms();
41 @@ -355,7 +357,7 @@ err_set_rsa:
42  err_engine_init:
43         ENGINE_free(e);
44  err_engine_by_id:
45 -#if OPENSSL_VERSION_NUMBER < 0x10100000L
46 +#if OPENSSL_VERSION_NUMBER < 0x10100000L ||  defined(LIBRESSL_VERSION_NUMBER)
47         ENGINE_cleanup();
48  #endif
49         return ret;
50 @@ -363,7 +365,7 @@ err_engine_by_id:
51  
52  static void rsa_remove(void)
53  {
54 -#if OPENSSL_VERSION_NUMBER < 0x10100000L
55 +#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
56         CRYPTO_cleanup_all_ex_data();
57         ERR_free_strings();
58  #ifdef HAVE_ERR_REMOVE_THREAD_STATE
59 @@ -433,7 +435,8 @@ static int rsa_sign_with_key(RSA *rsa, s
60                 ret = rsa_err("Could not obtain signature");
61                 goto err_sign;
62         }
63 -       #if OPENSSL_VERSION_NUMBER < 0x10100000L
64 +       #if OPENSSL_VERSION_NUMBER < 0x10100000L || \
65 +           defined(LIBRESSL_VERSION_NUMBER)
66                 EVP_MD_CTX_cleanup(context);
67         #else
68                 EVP_MD_CTX_reset(context);