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.

189 lines
5.8 KiB

  1. --- a/lib/crypto/c_src/crypto.c
  2. +++ b/lib/crypto/c_src/crypto.c
  3. @@ -41,6 +41,7 @@
  4. #include <openssl/des.h>
  5. #endif /* #ifndef OPENSSL_NO_DES */
  6. /* #include <openssl/idea.h> This is not supported on the openssl OTP requires */
  7. +#include <openssl/dh.h>
  8. #include <openssl/dsa.h>
  9. #include <openssl/rsa.h>
  10. #include <openssl/aes.h>
  11. @@ -177,7 +178,7 @@
  12. #endif
  13. #if OPENSSL_VERSION_NUMBER >= PACKED_OPENSSL_VERSION_PLAIN(1,1,0)
  14. -# ifndef HAS_LIBRESSL
  15. +# if !defined(OPENSSL_NO_CHACHA) || !defined(OPENSSL_NO_POLY1305)
  16. # define HAVE_CHACHA20_POLY1305
  17. # endif
  18. #endif
  19. @@ -197,8 +198,10 @@
  20. /* If OPENSSL_NO_EC is set, there will be an error in ec.h included from engine.h
  21. So if EC is disabled, you can't use Engine either....
  22. */
  23. +#if !defined(OPENSSL_NO_ENGINE)
  24. # define HAS_ENGINE_SUPPORT
  25. #endif
  26. +#endif
  27. #if defined(HAS_ENGINE_SUPPORT)
  28. @@ -910,7 +913,11 @@ static void engine_ctx_dtor(ErlNifEnv* env, struct engine_ctx* ctx) {
  29. static int verify_lib_version(void)
  30. {
  31. +#if OPENSSL_VERSION_NUMBER < PACKED_OPENSSL_VERSION_PLAIN(1,1,0)
  32. const unsigned long libv = SSLeay();
  33. +#else
  34. + const unsigned long libv = OpenSSL_version_num();
  35. +#endif
  36. const unsigned long hdrv = OPENSSL_VERSION_NUMBER;
  37. # define MAJOR_VER(V) ((unsigned long)(V) >> (7*4))
  38. @@ -1166,12 +1173,14 @@ static int initialize(ErlNifEnv* env, ERL_NIF_TERM load_info)
  39. funcp = &get_crypto_callbacks;
  40. #endif
  41. +#if OPENSSL_VERSION_NUMBER < PACKED_OPENSSL_VERSION_PLAIN(1,1,0)
  42. #ifdef OPENSSL_THREADS
  43. enif_system_info(&sys_info, sizeof(sys_info));
  44. if (sys_info.scheduler_threads > 1) {
  45. nlocks = CRYPTO_num_locks();
  46. }
  47. /* else no need for locks */
  48. +#endif
  49. #endif
  50. ccb = (*funcp)(nlocks);
  51. @@ -1183,15 +1192,21 @@ static int initialize(ErlNifEnv* env, ERL_NIF_TERM load_info)
  52. CRYPTO_set_mem_functions(ccb->crypto_alloc, ccb->crypto_realloc, ccb->crypto_free);
  53. +#if OPENSSL_VERSION_NUMBER < PACKED_OPENSSL_VERSION_PLAIN(1,1,0)
  54. #ifdef OPENSSL_THREADS
  55. if (nlocks > 0) {
  56. CRYPTO_set_locking_callback(ccb->locking_function);
  57. +#if OPENSSL_VERSION_NUMBER < 0x10000000
  58. CRYPTO_set_id_callback(ccb->id_function);
  59. +#else
  60. + CRYPTO_THREADID_set_callback(ccb->id_function);
  61. +#endif
  62. CRYPTO_set_dynlock_create_callback(ccb->dyn_create_function);
  63. CRYPTO_set_dynlock_lock_callback(ccb->dyn_lock_function);
  64. CRYPTO_set_dynlock_destroy_callback(ccb->dyn_destroy_function);
  65. }
  66. #endif /* OPENSSL_THREADS */
  67. +#endif
  68. init_digest_types(env);
  69. init_cipher_types(env);
  70. @@ -1391,7 +1406,11 @@ static ERL_NIF_TERM info_lib(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]
  71. static const char libname[] = "OpenSSL";
  72. unsigned name_sz = strlen(libname);
  73. +#if OPENSSL_VERSION_NUMBER < PACKED_OPENSSL_VERSION_PLAIN(1,1,0)
  74. const char* ver = SSLeay_version(SSLEAY_VERSION);
  75. +#else
  76. + const char* ver = OpenSSL_version(OPENSSL_VERSION);
  77. +#endif
  78. unsigned ver_sz = strlen(ver);
  79. ERL_NIF_TERM name_term, ver_term;
  80. int ver_num = OPENSSL_VERSION_NUMBER;
  81. --- a/lib/crypto/c_src/crypto_callback.c
  82. +++ b/lib/crypto/c_src/crypto_callback.c
  83. @@ -83,7 +83,7 @@ static void crypto_free(void* ptr CCB_FILE_LINE_ARGS)
  84. enif_free(ptr);
  85. }
  86. -
  87. +#if OPENSSL_VERSION_NUMBER < 0x10100000
  88. #ifdef OPENSSL_THREADS /* vvvvvvvvvvvvvvv OPENSSL_THREADS vvvvvvvvvvvvvvvv */
  89. static ErlNifRWLock** lock_vec = NULL; /* Static locks used by openssl */
  90. @@ -115,10 +115,17 @@ static void locking_function(int mode, int n, const char *file, int line)
  91. locking(mode, lock_vec[n]);
  92. }
  93. +#if OPENSSL_VERSION_NUMBER < 0x10000000
  94. static unsigned long id_function(void)
  95. {
  96. return (unsigned long) enif_thread_self();
  97. }
  98. +#else
  99. +static void id_function(CRYPTO_THREADID *id)
  100. +{
  101. + CRYPTO_THREADID_set_numeric(id, (unsigned long) enif_thread_self());
  102. +}
  103. +#endif
  104. /* Dynamic locking, not used by current openssl version (0.9.8)
  105. */
  106. @@ -136,6 +143,7 @@ static void dyn_destroy_function(struct CRYPTO_dynlock_value *ptr, const char *f
  107. }
  108. #endif /* ^^^^^^^^^^^^^^^^^^^^^^ OPENSSL_THREADS ^^^^^^^^^^^^^^^^^^^^^^ */
  109. +#endif
  110. DLLEXPORT struct crypto_callbacks* get_crypto_callbacks(int nlocks)
  111. {
  112. @@ -146,7 +154,8 @@ DLLEXPORT struct crypto_callbacks* get_crypto_callbacks(int nlocks)
  113. &crypto_alloc,
  114. &crypto_realloc,
  115. &crypto_free,
  116. -
  117. +
  118. +#if OPENSSL_VERSION_NUMBER < 0x10100000
  119. #ifdef OPENSSL_THREADS
  120. &locking_function,
  121. &id_function,
  122. @@ -154,9 +163,11 @@ DLLEXPORT struct crypto_callbacks* get_crypto_callbacks(int nlocks)
  123. &dyn_lock_function,
  124. &dyn_destroy_function
  125. #endif /* OPENSSL_THREADS */
  126. +#endif
  127. };
  128. if (!is_initialized) {
  129. +#if OPENSSL_VERSION_NUMBER < 0x10100000
  130. #ifdef OPENSSL_THREADS
  131. if (nlocks > 0) {
  132. int i;
  133. @@ -169,6 +180,7 @@ DLLEXPORT struct crypto_callbacks* get_crypto_callbacks(int nlocks)
  134. if (lock_vec[i]==NULL) return NULL;
  135. }
  136. }
  137. +#endif
  138. #endif
  139. is_initialized = 1;
  140. }
  141. --- a/lib/crypto/c_src/crypto_callback.h
  142. +++ b/lib/crypto/c_src/crypto_callback.h
  143. @@ -34,9 +34,15 @@ struct crypto_callbacks
  144. void (*crypto_free)(void* ptr CCB_FILE_LINE_ARGS);
  145. /* openssl callbacks */
  146. +#if OPENSSL_VERSION_NUMBER < 0x10100000
  147. #ifdef OPENSSL_THREADS
  148. void (*locking_function)(int mode, int n, const char *file, int line);
  149. + #if OPENSSL_VERSION_NUMBER < 0x10000000
  150. unsigned long (*id_function)(void);
  151. + #else
  152. + void (*id_function)(CRYPTO_THREADID *id);
  153. + #endif
  154. +#endif
  155. struct CRYPTO_dynlock_value* (*dyn_create_function)(const char *file,
  156. int line);
  157. void (*dyn_lock_function)(int mode, struct CRYPTO_dynlock_value* ptr,
  158. --- a/lib/crypto/c_src/otp_test_engine.c
  159. +++ b/lib/crypto/c_src/otp_test_engine.c
  160. @@ -42,8 +42,10 @@
  161. && !defined(OPENSSL_NO_EC) \
  162. && !defined(OPENSSL_NO_ECDH) \
  163. && !defined(OPENSSL_NO_ECDSA)
  164. +#if !defined(OPENSSL_NO_ENGINE)
  165. # define HAVE_EC
  166. #endif
  167. +#endif
  168. #if defined(HAVE_EC)
  169. /* If OPENSSL_NO_EC is set, there will be an error in ec.h included from engine.h