0098-tools-mkimage-fix-build-with-OpenSSL-1.1.x-FS-182.patch 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. From: Jo-Philipp Wich <jo@mein.io>
  2. Date: Wed, 30 Nov 2016 18:09:05 +0100
  3. Subject: tools: mkimage: fix build with OpenSSL 1.1.x (FS#182)
  4. The OpenSSL 1.1.x version series undergone some major API changes which made
  5. the RSA structure opaque and deprecated a number of methods, so add some
  6. conditional compat code to make the u-boot source build again.
  7. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
  8. Backport of LEDE 70b104f98c0657323b28fce140b73a94bf3eb756
  9. diff --git a/tools/mkimage/patches/210-openssl-1.1.x-compat.patch b/tools/mkimage/patches/210-openssl-1.1.x-compat.patch
  10. new file mode 100644
  11. index 0000000000000000000000000000000000000000..fa7c99f39b0a65f0d784473ca9b8fde836e4fa6e
  12. --- /dev/null
  13. +++ b/tools/mkimage/patches/210-openssl-1.1.x-compat.patch
  14. @@ -0,0 +1,97 @@
  15. +--- a/lib/rsa/rsa-sign.c
  16. ++++ b/lib/rsa/rsa-sign.c
  17. +@@ -15,10 +15,25 @@
  18. + #include <openssl/ssl.h>
  19. + #include <openssl/evp.h>
  20. +
  21. +-#if OPENSSL_VERSION_NUMBER >= 0x10000000L
  22. ++#if OPENSSL_VERSION_NUMBER < 0x10000000L
  23. ++#define HAVE_ERR_REMOVE_STATE
  24. ++#elif OPENSSL_VERSION_NUMBER < 0x10100000L
  25. + #define HAVE_ERR_REMOVE_THREAD_STATE
  26. + #endif
  27. +
  28. ++#if OPENSSL_VERSION_NUMBER < 0x10100005L
  29. ++static void RSA_get0_key(const RSA *r,
  30. ++ const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
  31. ++{
  32. ++ if (n != NULL)
  33. ++ *n = r->n;
  34. ++ if (e != NULL)
  35. ++ *e = r->e;
  36. ++ if (d != NULL)
  37. ++ *d = r->d;
  38. ++}
  39. ++#endif
  40. ++
  41. + static int rsa_err(const char *msg)
  42. + {
  43. + unsigned long sslErr = ERR_get_error();
  44. +@@ -154,7 +169,8 @@ static void rsa_remove(void)
  45. + ERR_free_strings();
  46. + #ifdef HAVE_ERR_REMOVE_THREAD_STATE
  47. + ERR_remove_thread_state(NULL);
  48. +-#else
  49. ++#endif
  50. ++#ifdef HAVE_ERR_REMOVE_STATE
  51. + ERR_remove_state(0);
  52. + #endif
  53. + EVP_cleanup();
  54. +@@ -210,7 +226,6 @@ static int rsa_sign_with_key(RSA *rsa, s
  55. + ret = rsa_err("Could not obtain signature");
  56. + goto err_sign;
  57. + }
  58. +- EVP_MD_CTX_cleanup(context);
  59. + EVP_MD_CTX_destroy(context);
  60. + EVP_PKEY_free(key);
  61. +
  62. +@@ -270,23 +285,26 @@ static int rsa_get_exponent(RSA *key, ui
  63. + BIGNUM *bn_te;
  64. + uint64_t te;
  65. +
  66. ++ const BIGNUM *bn_e;
  67. ++ RSA_get0_key(key, NULL, &bn_e, NULL);
  68. ++
  69. + ret = -EINVAL;
  70. + bn_te = NULL;
  71. +
  72. + if (!e)
  73. + goto cleanup;
  74. +
  75. +- if (BN_num_bits(key->e) > 64)
  76. ++ if (BN_num_bits(bn_e) > 64)
  77. + goto cleanup;
  78. +
  79. +- *e = BN_get_word(key->e);
  80. ++ *e = BN_get_word(bn_e);
  81. +
  82. +- if (BN_num_bits(key->e) < 33) {
  83. ++ if (BN_num_bits(bn_e) < 33) {
  84. + ret = 0;
  85. + goto cleanup;
  86. + }
  87. +
  88. +- bn_te = BN_dup(key->e);
  89. ++ bn_te = BN_dup(bn_e);
  90. + if (!bn_te)
  91. + goto cleanup;
  92. +
  93. +@@ -319,6 +337,9 @@ int rsa_get_params(RSA *key, uint64_t *e
  94. + BN_CTX *bn_ctx = BN_CTX_new();
  95. + int ret = 0;
  96. +
  97. ++ const BIGNUM *bn_n;
  98. ++ RSA_get0_key(key, &bn_n, NULL, NULL);
  99. ++
  100. + /* Initialize BIGNUMs */
  101. + big1 = BN_new();
  102. + big2 = BN_new();
  103. +@@ -337,7 +358,7 @@ int rsa_get_params(RSA *key, uint64_t *e
  104. + if (0 != rsa_get_exponent(key, exponent))
  105. + ret = -1;
  106. +
  107. +- if (!BN_copy(n, key->n) || !BN_set_word(big1, 1L) ||
  108. ++ if (!BN_copy(n, bn_n) || !BN_set_word(big1, 1L) ||
  109. + !BN_set_word(big2, 2L) || !BN_set_word(big32, 32L))
  110. + ret = -1;
  111. +