1
0

210-openssl-1.1.x-compat.patch 2.2 KB

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