uboot-envtools: update to 2018.03
[openwrt/openwrt.git] / tools / mkimage / patches / 210-openssl-1.1.x-compat.patch
1 --- a/lib/rsa/rsa-sign.c
2 +++ b/lib/rsa/rsa-sign.c
3 @@ -15,10 +15,25 @@
4 #include <openssl/ssl.h>
5 #include <openssl/evp.h>
6
7 -#if OPENSSL_VERSION_NUMBER >= 0x10000000L
8 +#if OPENSSL_VERSION_NUMBER < 0x10000000L
9 +#define HAVE_ERR_REMOVE_STATE
10 +#elif OPENSSL_VERSION_NUMBER < 0x10100000L
11 #define HAVE_ERR_REMOVE_THREAD_STATE
12 #endif
13
14 +#if (OPENSSL_VERSION_NUMBER < 0x10100005L) || defined(LIBRESSL_VERSION_NUMBER)
15 +static void RSA_get0_key(const RSA *r,
16 + const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
17 +{
18 + if (n != NULL)
19 + *n = r->n;
20 + if (e != NULL)
21 + *e = r->e;
22 + if (d != NULL)
23 + *d = r->d;
24 +}
25 +#endif
26 +
27 static int rsa_err(const char *msg)
28 {
29 unsigned long sslErr = ERR_get_error();
30 @@ -154,7 +169,8 @@ static void rsa_remove(void)
31 ERR_free_strings();
32 #ifdef HAVE_ERR_REMOVE_THREAD_STATE
33 ERR_remove_thread_state(NULL);
34 -#else
35 +#endif
36 +#ifdef HAVE_ERR_REMOVE_STATE
37 ERR_remove_state(0);
38 #endif
39 EVP_cleanup();
40 @@ -210,7 +226,6 @@ static int rsa_sign_with_key(RSA *rsa, s
41 ret = rsa_err("Could not obtain signature");
42 goto err_sign;
43 }
44 - EVP_MD_CTX_cleanup(context);
45 EVP_MD_CTX_destroy(context);
46 EVP_PKEY_free(key);
47
48 @@ -270,23 +285,26 @@ static int rsa_get_exponent(RSA *key, ui
49 BIGNUM *bn_te;
50 uint64_t te;
51
52 + const BIGNUM *bn_e;
53 + RSA_get0_key(key, NULL, &bn_e, NULL);
54 +
55 ret = -EINVAL;
56 bn_te = NULL;
57
58 if (!e)
59 goto cleanup;
60
61 - if (BN_num_bits(key->e) > 64)
62 + if (BN_num_bits(bn_e) > 64)
63 goto cleanup;
64
65 - *e = BN_get_word(key->e);
66 + *e = BN_get_word(bn_e);
67
68 - if (BN_num_bits(key->e) < 33) {
69 + if (BN_num_bits(bn_e) < 33) {
70 ret = 0;
71 goto cleanup;
72 }
73
74 - bn_te = BN_dup(key->e);
75 + bn_te = BN_dup(bn_e);
76 if (!bn_te)
77 goto cleanup;
78
79 @@ -319,6 +337,9 @@ int rsa_get_params(RSA *key, uint64_t *e
80 BN_CTX *bn_ctx = BN_CTX_new();
81 int ret = 0;
82
83 + const BIGNUM *bn_n;
84 + RSA_get0_key(key, &bn_n, NULL, NULL);
85 +
86 /* Initialize BIGNUMs */
87 big1 = BN_new();
88 big2 = BN_new();
89 @@ -337,7 +358,7 @@ int rsa_get_params(RSA *key, uint64_t *e
90 if (0 != rsa_get_exponent(key, exponent))
91 ret = -1;
92
93 - if (!BN_copy(n, key->n) || !BN_set_word(big1, 1L) ||
94 + if (!BN_copy(n, bn_n) || !BN_set_word(big1, 1L) ||
95 !BN_set_word(big2, 2L) || !BN_set_word(big32, 32L))
96 ret = -1;
97