2222#include "ext/standard/php_password.h"
2323#include "php_openssl.h"
2424
25- #if defined( HAVE_OPENSSL_ARGON2 )
25+ #ifdef HAVE_OPENSSL_ARGON2
2626#include "Zend/zend_attributes.h"
2727#include "openssl_pwhash_arginfo.h"
2828#include <ext/standard/base64.h>
4646#define PHP_OPENSSL_HASH_SIZE 32
4747#define PHP_OPENSSL_DIGEST_SIZE 128
4848
49+ ZEND_EXTERN_MODULE_GLOBALS (openssl )
50+
4951static inline zend_result get_options (zend_array * options , uint32_t * memlimit , uint32_t * iterlimit , uint32_t * threads )
5052{
5153 zval * opt ;
@@ -98,8 +100,8 @@ static bool php_openssl_argon2_compute_hash(
98100 uint32_t oldthreads ;
99101 bool ret = false;
100102
101- oldthreads = OSSL_get_max_threads (NULL );
102- if (OSSL_set_max_threads (NULL , threads ) != 1 ) {
103+ oldthreads = OSSL_get_max_threads (PHP_OPENSSL_LIBCTX );
104+ if (OSSL_set_max_threads (PHP_OPENSSL_LIBCTX , threads ) != 1 ) {
103105 goto fail ;
104106 }
105107 p = params ;
@@ -111,7 +113,7 @@ static bool php_openssl_argon2_compute_hash(
111113 * p ++ = OSSL_PARAM_construct_octet_string (OSSL_KDF_PARAM_PASSWORD , (void * )pass , pass_len );
112114 * p ++ = OSSL_PARAM_construct_end ();
113115
114- if ((kdf = EVP_KDF_fetch (NULL , algo , NULL )) == NULL ) {
116+ if ((kdf = EVP_KDF_fetch (PHP_OPENSSL_LIBCTX , algo , PHP_OPENSSL_PROPQ )) == NULL ) {
115117 goto fail ;
116118 }
117119 if ((kctx = EVP_KDF_CTX_new (kdf )) == NULL ) {
@@ -127,7 +129,7 @@ static bool php_openssl_argon2_compute_hash(
127129fail :
128130 EVP_KDF_free (kdf );
129131 EVP_KDF_CTX_free (kctx );
130- OSSL_set_max_threads (NULL , oldthreads );
132+ OSSL_set_max_threads (PHP_OPENSSL_LIBCTX , oldthreads );
131133
132134 return ret ;
133135}
@@ -385,4 +387,5 @@ PHP_MINIT_FUNCTION(openssl_pwhash)
385387
386388 return SUCCESS ;
387389}
390+
388391#endif /* HAVE_OPENSSL_ARGON2 */
0 commit comments