You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.7 KiB

  1. From a8523d83c242c6f71dbf69fab0ca91d768e78f05 Mon Sep 17 00:00:00 2001
  2. From: Andreas Schneider <asn@cryptomilk.org>
  3. Date: Sun, 6 Nov 2016 12:07:32 +0100
  4. Subject: [PATCH] threads: Use new API call for OpenSSL CRYPTO THREADID
  5. BUG: https://red.libssh.org/issues/222
  6. Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
  7. ---
  8. ConfigureChecks.cmake | 4 ++++
  9. config.h.cmake | 3 +++
  10. src/threads.c | 19 +++++++++++++++++--
  11. 3 files changed, 24 insertions(+), 2 deletions(-)
  12. diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
  13. index 0a53c5b1..43179d8f 100644
  14. --- a/ConfigureChecks.cmake
  15. +++ b/ConfigureChecks.cmake
  16. @@ -95,6 +95,10 @@ if (OPENSSL_FOUND)
  17. set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
  18. set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY})
  19. check_function_exists(CRYPTO_ctr128_encrypt HAVE_OPENSSL_CRYPTO_CTR128_ENCRYPT)
  20. +
  21. + set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
  22. + set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY})
  23. + check_function_exists(CRYPTO_THREADID_set_callback HAVE_OPENSSL_CRYPTO_THREADID_SET_CALLBACK)
  24. endif()
  25. if (CMAKE_HAVE_PTHREAD_H)
  26. diff --git a/config.h.cmake b/config.h.cmake
  27. index 3e7f7939..b87fea5c 100644
  28. --- a/config.h.cmake
  29. +++ b/config.h.cmake
  30. @@ -79,6 +79,9 @@
  31. /* Define to 1 if you have the `CRYPTO_ctr128_encrypt' function. */
  32. #cmakedefine HAVE_OPENSSL_CRYPTO_CTR128_ENCRYPT 1
  33. +/* Define to 1 if you have the `CRYPTO_THREADID_set_callback' function. */
  34. +#cmakedefine HAVE_OPENSSL_CRYPTO_THREADID_SET_CALLBACK 1
  35. +
  36. /* Define to 1 if you have the `snprintf' function. */
  37. #cmakedefine HAVE_SNPRINTF 1
  38. diff --git a/src/threads.c b/src/threads.c
  39. index 7f3a304e..062c3b84 100644
  40. --- a/src/threads.c
  41. +++ b/src/threads.c
  42. @@ -116,6 +116,15 @@ static void libcrypto_lock_callback(int mode, int i, const char *file, int line)
  43. }
  44. }
  45. +#ifdef HAVE_OPENSSL_CRYPTO_THREADID_SET_CALLBACK
  46. +static void libcrypto_THREADID_callback(CRYPTO_THREADID *id)
  47. +{
  48. + unsigned long thread_id = (*user_callbacks->thread_id)();
  49. +
  50. + CRYPTO_THREADID_set_numeric(id, thread_id);
  51. +}
  52. +#endif /* HAVE_OPENSSL_CRYPTO_THREADID_SET_CALLBACK */
  53. +
  54. static int libcrypto_thread_init(void){
  55. int n=CRYPTO_num_locks();
  56. int i;
  57. @@ -127,8 +136,14 @@ static int libcrypto_thread_init(void){
  58. for (i=0;i<n;++i){
  59. user_callbacks->mutex_init(&libcrypto_mutexes[i]);
  60. }
  61. - CRYPTO_set_id_callback(user_callbacks->thread_id);
  62. - CRYPTO_set_locking_callback(libcrypto_lock_callback);
  63. +
  64. +#ifdef HAVE_OPENSSL_CRYPTO_THREADID_SET_CALLBACK
  65. + CRYPTO_THREADID_set_callback(libcrypto_THREADID_callback);
  66. +#else
  67. + CRYPTO_set_id_callback(user_callbacks->thread_id);
  68. +#endif
  69. +
  70. + CRYPTO_set_locking_callback(libcrypto_lock_callback);
  71. return SSH_OK;
  72. }
  73. --
  74. 2.19.1