Skip to content

Commit f22d8a3

Browse files
committed
add --with-openssl-argon2 build option
1 parent df13c81 commit f22d8a3

File tree

8 files changed

+42
-25
lines changed

8 files changed

+42
-25
lines changed

ext/openssl/config0.m4

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ PHP_ARG_WITH([openssl-legacy-provider],
1717
[no],
1818
[no])
1919

20+
PHP_ARG_WITH([openssl-argon2],
21+
[whether to enable argon2 password hashing (requires OpenSSL >= 3.2)],
22+
[AS_HELP_STRING([--with-openssl-argon2],
23+
[OPENSSL: Enable argon2 password hashing])],
24+
[no],
25+
[no])
26+
2027
if test "$PHP_OPENSSL" != "no"; then
2128
PHP_NEW_EXTENSION(openssl, openssl.c openssl_pwhash.c xp_ssl.c, $ext_shared)
2229
PHP_SUBST([OPENSSL_SHARED_LIBADD])
@@ -36,4 +43,14 @@ if test "$PHP_OPENSSL" != "no"; then
3643
if test "$PHP_OPENSSL_LEGACY_PROVIDER" != "no"; then
3744
AC_DEFINE(LOAD_OPENSSL_LEGACY_PROVIDER,1,[ Load legacy algorithm provider in addition to default provider ])
3845
fi
46+
47+
if test "$PHP_OPENSSL_ARGON2" != "no"; then
48+
if test "$PHP_THREAD_SAFETY" != "no"; then
49+
AC_MSG_ERROR([Not supported in ZTS mode for now])
50+
fi
51+
PHP_CHECK_LIBRARY([crypto], [OSSL_set_max_threads],
52+
[AC_DEFINE(HAVE_OPENSSL_ARGON2,1,[ Enable argon2 password hashing ])],
53+
[AC_MSG_ERROR([argon2 hashing requires OpenSSL 3.2])],
54+
[$OPENSSL_LIBS])
55+
fi
3956
fi

ext/openssl/openssl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,15 @@ static void php_openssl_pkey_free_obj(zend_object *object)
270270
zend_object_std_dtor(&key_object->std);
271271
}
272272

273-
#if PHP_OPENSSL_API_VERSION >= 0x30200
273+
#if defined(HAVE_OPENSSL_ARGON2)
274274
static const zend_module_dep openssl_deps[] = {
275275
ZEND_MOD_REQUIRED("standard")
276276
ZEND_MOD_END
277277
};
278278
#endif
279279
/* {{{ openssl_module_entry */
280280
zend_module_entry openssl_module_entry = {
281-
#if PHP_OPENSSL_API_VERSION >= 0x30200
281+
#if defined(HAVE_OPENSSL_ARGON2)
282282
STANDARD_MODULE_HEADER_EX, NULL,
283283
openssl_deps,
284284
#else
@@ -1341,7 +1341,7 @@ PHP_MINIT_FUNCTION(openssl)
13411341

13421342
REGISTER_INI_ENTRIES();
13431343

1344-
#if PHP_OPENSSL_API_VERSION >= 0x30200
1344+
#if defined(HAVE_OPENSSL_ARGON2)
13451345
if (FAILURE == PHP_MINIT(openssl_pwhash)(INIT_FUNC_ARGS_PASSTHRU)) {
13461346
return FAILURE;
13471347
}

ext/openssl/openssl.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ function openssl_spki_export_challenge(string $spki): string|false {}
679679
*/
680680
function openssl_get_cert_locations(): array {}
681681

682-
#if PHP_OPENSSL_API_VERSION >= 0x30200
682+
#if defined(HAVE_OPENSSL_ARGON2)
683683
function openssl_password_hash(string $algo, #[\SensitiveParameter] string $password, array $options = []): string {}
684684
function openssl_password_verify(string $algo, #[\SensitiveParameter] string $password, string $hash): bool {}
685685
#endif

ext/openssl/openssl_arginfo.h

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/openssl/openssl_pwhash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "ext/standard/php_password.h"
2323
#include "php_openssl.h"
2424

25-
#if PHP_OPENSSL_API_VERSION >= 0x30200
25+
#if defined(HAVE_OPENSSL_ARGON2)
2626
#include "Zend/zend_attributes.h"
2727
#include "openssl_pwhash_arginfo.h"
2828
#include <ext/standard/base64.h>
@@ -398,4 +398,4 @@ PHP_MINIT_FUNCTION(openssl_pwhash)
398398

399399
return SUCCESS;
400400
}
401-
#endif /* PHP_OPENSSL_API_VERSION >= 0x30200 */
401+
#endif /* HAVE_OPENSSL_ARGON2 */

ext/openssl/openssl_pwhash.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/** @generate-class-entries */
44

5-
#if PHP_OPENSSL_API_VERSION >= 0x30200
5+
#if defined(HAVE_OPENSSL_ARGON2)
66
/**
77
* @var string
88
*/

ext/openssl/openssl_pwhash_arginfo.h

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/openssl/php_openssl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static inline php_openssl_certificate_object *php_openssl_certificate_from_obj(z
158158

159159
#define Z_OPENSSL_CERTIFICATE_P(zv) php_openssl_certificate_from_obj(Z_OBJ_P(zv))
160160

161-
#if PHP_OPENSSL_API_VERSION >= 0x30200
161+
#if defined(HAVE_OPENSSL_ARGON2)
162162

163163
/**
164164
* MEMLIMIT is normalized to KB even though sodium uses Bytes in order to
@@ -189,7 +189,7 @@ PHP_MSHUTDOWN_FUNCTION(openssl);
189189
PHP_MINFO_FUNCTION(openssl);
190190
PHP_GINIT_FUNCTION(openssl);
191191
PHP_GSHUTDOWN_FUNCTION(openssl);
192-
#if PHP_OPENSSL_API_VERSION >= 0x30200
192+
#if defined(HAVE_OPENSSL_ARGON2)
193193
PHP_MINIT_FUNCTION(openssl_pwhash);
194194
#endif
195195

0 commit comments

Comments
 (0)