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.

143 lines
4.4 KiB

  1. --- a/src/cipher.c
  2. +++ b/src/cipher.c
  3. @@ -8,6 +8,10 @@ cipher module for lua-openssl binding
  4. #include "openssl.h"
  5. #include "private.h"
  6. +#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
  7. +#define EVP_CIPHER_CTX_reset EVP_CIPHER_CTX_init
  8. +#endif
  9. +
  10. /***
  11. list all support cipher algs
  12. @@ -109,7 +113,7 @@ static LUA_FUNCTION(openssl_evp_encrypt)
  13. memcpy(evp_iv, iv, iv_len);
  14. }
  15. - EVP_CIPHER_CTX_init(c);
  16. + EVP_CIPHER_CTX_reset(c);
  17. ret = EVP_EncryptInit_ex(c, cipher, e, (const byte*)evp_key, iv_len > 0 ? (const byte*)evp_iv : NULL);
  18. if (ret == 1)
  19. {
  20. @@ -131,8 +135,12 @@ static LUA_FUNCTION(openssl_evp_encrypt)
  21. OPENSSL_free(buffer);
  22. }
  23. }
  24. +#if OPENSSL_VERSION_NUMBER >= 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
  25. + EVP_CIPHER_CTX_reset(c);
  26. +#else
  27. EVP_CIPHER_CTX_cleanup(c);
  28. EVP_CIPHER_CTX_free(c);
  29. +#endif
  30. return (ret == 1) ? ret : openssl_pushresult(L, ret);
  31. }
  32. else
  33. @@ -196,7 +204,7 @@ static LUA_FUNCTION(openssl_evp_decrypt)
  34. memcpy(evp_iv, iv, iv_len);
  35. }
  36. - EVP_CIPHER_CTX_init(c);
  37. + EVP_CIPHER_CTX_reset(c);
  38. ret = EVP_DecryptInit_ex(c, cipher, e, key ? (const byte*)evp_key : NULL, iv_len > 0 ? (const byte*)evp_iv : NULL);
  39. if (ret == 1)
  40. {
  41. @@ -220,8 +228,12 @@ static LUA_FUNCTION(openssl_evp_decrypt)
  42. OPENSSL_free(buffer);
  43. }
  44. }
  45. +#if OPENSSL_VERSION_NUMBER >= 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
  46. + EVP_CIPHER_CTX_reset(c);
  47. +#else
  48. EVP_CIPHER_CTX_cleanup(c);
  49. EVP_CIPHER_CTX_free(c);
  50. +#endif
  51. return (ret == 1) ? ret : openssl_pushresult(L, ret);
  52. }
  53. else
  54. @@ -292,7 +304,7 @@ static LUA_FUNCTION(openssl_evp_cipher)
  55. memcpy(evp_iv, iv, iv_len);
  56. }
  57. - EVP_CIPHER_CTX_init(c);
  58. + EVP_CIPHER_CTX_reset(c);
  59. ret = EVP_CipherInit_ex(c, cipher, e, (const byte*)evp_key, iv_len > 0 ? (const byte*)evp_iv : NULL, enc);
  60. if (ret == 1)
  61. {
  62. @@ -317,8 +329,12 @@ static LUA_FUNCTION(openssl_evp_cipher)
  63. OPENSSL_free(buffer);
  64. }
  65. }
  66. +#if OPENSSL_VERSION_NUMBER >= 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
  67. + EVP_CIPHER_CTX_reset(c);
  68. +#else
  69. EVP_CIPHER_CTX_cleanup(c);
  70. EVP_CIPHER_CTX_free(c);
  71. +#endif
  72. return (ret == 1) ? ret : openssl_pushresult(L, ret);
  73. }
  74. else
  75. @@ -376,7 +392,7 @@ static LUA_FUNCTION(openssl_cipher_new)
  76. memcpy(evp_iv, iv, iv_len);
  77. }
  78. c = EVP_CIPHER_CTX_new();
  79. - EVP_CIPHER_CTX_init(c);
  80. + EVP_CIPHER_CTX_reset(c);
  81. if (!EVP_CipherInit_ex(c, cipher, e, key ? (const byte*)evp_key : NULL, iv_len > 0 ? (const byte*)evp_iv : NULL, enc))
  82. {
  83. luaL_error(L, "EVP_CipherInit_ex failed, please check openssl error");
  84. @@ -431,7 +447,7 @@ static LUA_FUNCTION(openssl_cipher_encry
  85. memcpy(evp_iv, iv, iv_len);
  86. }
  87. c = EVP_CIPHER_CTX_new();
  88. - EVP_CIPHER_CTX_init(c);
  89. + EVP_CIPHER_CTX_reset(c);
  90. ret = EVP_EncryptInit_ex(c, cipher, e,
  91. key ? (const byte*)evp_key : NULL,
  92. iv_len > 0 ? (const byte*)evp_iv : NULL);
  93. @@ -491,7 +507,7 @@ static LUA_FUNCTION(openssl_cipher_decry
  94. memcpy(evp_iv, iv, iv_len);
  95. }
  96. c = EVP_CIPHER_CTX_new();
  97. - EVP_CIPHER_CTX_init(c);
  98. + EVP_CIPHER_CTX_reset(c);
  99. ret = EVP_DecryptInit_ex(c, cipher, e,
  100. key ? (const byte*)evp_key : NULL,
  101. iv_len > 0 ? (const byte*)evp_iv : NULL);
  102. @@ -937,8 +953,12 @@ static LUA_FUNCTION(openssl_cipher_ctx_f
  103. return 0;
  104. lua_pushnil(L);
  105. lua_rawsetp(L, LUA_REGISTRYINDEX, ctx);
  106. +#if OPENSSL_VERSION_NUMBER >= 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
  107. + EVP_CIPHER_CTX_reset(ctx);
  108. +#else
  109. EVP_CIPHER_CTX_cleanup(ctx);
  110. EVP_CIPHER_CTX_free(ctx);
  111. +#endif
  112. FREE_OBJECT(1);
  113. return 0;
  114. }
  115. --- a/src/openssl.c
  116. +++ b/src/openssl.c
  117. @@ -523,9 +523,7 @@ LUALIB_API int luaopen_openssl(lua_State
  118. #endif
  119. #ifndef OPENSSL_NO_ENGINE
  120. - ENGINE_load_dynamic();
  121. - ENGINE_load_openssl();
  122. - ENGINE_load_builtin_engines();
  123. + ENGINE_register_all_complete();
  124. #endif
  125. #ifdef LOAD_ENGINE_CUSTOM
  126. LOAD_ENGINE_CUSTOM
  127. --- a/src/th-lock.c
  128. +++ b/src/th-lock.c
  129. @@ -310,7 +310,7 @@ unsigned long irix_thread_id(void)
  130. /* Linux and a few others */
  131. #ifdef PTHREADS
  132. -#ifndef OPENSSL_SYS_WIN32
  133. +#if !defined(OPENSSL_SYS_WIN32) && (OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER))
  134. static pthread_mutex_t *lock_cs;
  135. static long *lock_count;