PKGBUILDs/alarm/uboot-tools/0001-rsa-Fix-build-with-OpenSSL-1.1.x.patch

159 lines
3.8 KiB
Diff
Raw Normal View History

2017-05-13 15:18:47 +00:00
From 877e492587c558eb771e2d17491c779f94631238 Mon Sep 17 00:00:00 2001
2017-04-29 03:33:26 +00:00
From: Jelle van der Waa <jelle@vdwaa.nl>
2017-05-13 15:18:47 +00:00
Date: Mon, 8 May 2017 21:31:19 +0200
Subject: [PATCH 1/2] rsa: Fix build with OpenSSL 1.1.x
2017-04-29 03:33:26 +00:00
The rsa_st struct has been made opaque in 1.1.x, add forward compatible
code to access the n, e, d members of rsa_struct.
EVP_MD_CTX_cleanup has been removed in 1.1.x and EVP_MD_CTX_reset should be
called to reinitialise an already created structure.
---
2017-05-13 15:18:47 +00:00
lib/rsa/rsa-sign.c | 44 ++++++++++++++++++++++++++++++++++++++------
1 file changed, 38 insertions(+), 6 deletions(-)
2017-04-29 03:33:26 +00:00
diff --git a/lib/rsa/rsa-sign.c b/lib/rsa/rsa-sign.c
2017-05-13 15:18:47 +00:00
index 8c6637e328..1da4ef7fff 100644
2017-04-29 03:33:26 +00:00
--- a/lib/rsa/rsa-sign.c
+++ b/lib/rsa/rsa-sign.c
2017-05-13 15:18:47 +00:00
@@ -9,6 +9,7 @@
#include <string.h>
#include <image.h>
#include <time.h>
2017-04-29 03:33:26 +00:00
+#include <openssl/bn.h>
2017-05-13 15:18:47 +00:00
#include <openssl/rsa.h>
#include <openssl/pem.h>
#include <openssl/err.h>
@@ -20,6 +21,19 @@
2017-04-29 03:33:26 +00:00
#define HAVE_ERR_REMOVE_THREAD_STATE
#endif
2017-05-13 15:18:47 +00:00
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
2017-04-29 03:33:26 +00:00
+static void RSA_get0_key(const RSA *r,
+ const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
+{
+ if (n != NULL)
+ *n = r->n;
+ if (e != NULL)
+ *e = r->e;
+ if (d != NULL)
+ *d = r->d;
+}
+#endif
+
static int rsa_err(const char *msg)
{
unsigned long sslErr = ERR_get_error();
2017-05-13 15:18:47 +00:00
@@ -286,16 +300,22 @@ static int rsa_init(void)
2017-04-29 03:33:26 +00:00
{
int ret;
2017-05-13 15:18:47 +00:00
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
ret = SSL_library_init();
+#else
2017-04-29 03:33:26 +00:00
+ ret = OPENSSL_init_ssl(0, NULL);
2017-05-13 15:18:47 +00:00
+#endif
2017-04-29 03:33:26 +00:00
if (!ret) {
fprintf(stderr, "Failure to init SSL library\n");
return -1;
2017-05-13 15:18:47 +00:00
}
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
SSL_load_error_strings();
OpenSSL_add_all_algorithms();
OpenSSL_add_all_digests();
OpenSSL_add_all_ciphers();
+#endif
return 0;
}
@@ -335,12 +355,15 @@ err_set_rsa:
err_engine_init:
ENGINE_free(e);
err_engine_by_id:
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
ENGINE_cleanup();
+#endif
return ret;
}
static void rsa_remove(void)
{
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
CRYPTO_cleanup_all_ex_data();
ERR_free_strings();
#ifdef HAVE_ERR_REMOVE_THREAD_STATE
@@ -349,6 +372,7 @@ static void rsa_remove(void)
ERR_remove_state(0);
#endif
EVP_cleanup();
+#endif
}
static void rsa_engine_remove(ENGINE *e)
@@ -409,7 +433,11 @@ static int rsa_sign_with_key(RSA *rsa, struct checksum_algo *checksum_algo,
2017-04-29 03:33:26 +00:00
ret = rsa_err("Could not obtain signature");
goto err_sign;
}
- EVP_MD_CTX_cleanup(context);
2017-05-13 15:18:47 +00:00
+ #if OPENSSL_VERSION_NUMBER < 0x10100000L
2017-04-29 03:33:26 +00:00
+ EVP_MD_CTX_cleanup(context);
+ #else
+ EVP_MD_CTX_reset(context);
+ #endif
EVP_MD_CTX_destroy(context);
EVP_PKEY_free(key);
2017-05-13 15:18:47 +00:00
@@ -479,6 +507,7 @@ static int rsa_get_exponent(RSA *key, uint64_t *e)
2017-04-29 03:33:26 +00:00
{
int ret;
BIGNUM *bn_te;
+ const BIGNUM *key_e;
uint64_t te;
ret = -EINVAL;
2017-05-13 15:18:47 +00:00
@@ -487,17 +516,18 @@ static int rsa_get_exponent(RSA *key, uint64_t *e)
2017-04-29 03:33:26 +00:00
if (!e)
goto cleanup;
- if (BN_num_bits(key->e) > 64)
+ RSA_get0_key(key, NULL, &key_e, NULL);
+ if (BN_num_bits(key_e) > 64)
goto cleanup;
- *e = BN_get_word(key->e);
+ *e = BN_get_word(key_e);
- if (BN_num_bits(key->e) < 33) {
+ if (BN_num_bits(key_e) < 33) {
ret = 0;
goto cleanup;
}
- bn_te = BN_dup(key->e);
+ bn_te = BN_dup(key_e);
if (!bn_te)
goto cleanup;
2017-05-13 15:18:47 +00:00
@@ -527,6 +557,7 @@ int rsa_get_params(RSA *key, uint64_t *exponent, uint32_t *n0_invp,
2017-04-29 03:33:26 +00:00
{
BIGNUM *big1, *big2, *big32, *big2_32;
BIGNUM *n, *r, *r_squared, *tmp;
+ const BIGNUM *key_n;
BN_CTX *bn_ctx = BN_CTX_new();
int ret = 0;
2017-05-13 15:18:47 +00:00
@@ -548,7 +579,8 @@ int rsa_get_params(RSA *key, uint64_t *exponent, uint32_t *n0_invp,
2017-04-29 03:33:26 +00:00
if (0 != rsa_get_exponent(key, exponent))
ret = -1;
- if (!BN_copy(n, key->n) || !BN_set_word(big1, 1L) ||
+ RSA_get0_key(key, &key_n, NULL, NULL);
+ if (!BN_copy(n, key_n) || !BN_set_word(big1, 1L) ||
!BN_set_word(big2, 2L) || !BN_set_word(big32, 32L))
ret = -1;
--
2017-05-13 15:18:47 +00:00
2.13.0
2017-04-29 03:33:26 +00:00