42 return zend_hash_add_ptr(&php_password_algos,
key, (
void *) algo) ?
SUCCESS :
FAILURE;
49static int php_password_salt_to64(
const char *str,
const size_t str_len,
const size_t out_len,
char *
ret)
53 if ((
int) str_len < 0) {
56 buffer = php_base64_encode((
unsigned char*) str, str_len);
77static zend_string* php_password_make_salt(
size_t length)
86 buffer = zend_string_alloc(length * 3 / 4 + 1, 0);
93 ret = zend_string_alloc(length, 0);
107 if (
options && zend_hash_str_exists(
options,
"salt",
sizeof(
"salt") - 1)) {
111 return php_password_make_salt(required_salt_len);
119 (h[0] ==
'$') && (h[1] ==
'2') && (h[2] ==
'y');
125 if (!php_password_bcrypt_valid(
hash)) {
141 if (!php_password_bcrypt_valid(
hash)) {
148 new_cost = zval_get_long(znew_cost);
151 return old_cost != new_cost;
163 zend_string_free(
ret);
173 zend_string_free(
ret);
178 char hash_format[10];
179 size_t hash_format_len;
190 cost = zval_get_long(zcost);
193 if (cost < 4 || cost > 31) {
226 php_password_bcrypt_hash,
227 php_password_bcrypt_verify,
228 php_password_bcrypt_needs_rehash,
229 php_password_bcrypt_get_info,
230 php_password_bcrypt_valid,
245 if (!memcmp(
p,
"$argon2i$",
sizeof(
"$argon2i$") - 1)) {
246 p +=
sizeof(
"$argon2i$") - 1;
247 }
else if (!memcmp(
p,
"$argon2id$",
sizeof(
"$argon2id$") - 1)) {
248 p +=
sizeof(
"$argon2id$") - 1;
254 v, memory_cost, time_cost, threads);
262 zend_long memory_cost = PHP_PASSWORD_ARGON2_MEMORY_COST;
263 zend_long time_cost = PHP_PASSWORD_ARGON2_TIME_COST;
264 zend_long threads = PHP_PASSWORD_ARGON2_THREADS;
266 extract_argon2_parameters(
hash, &
v, &memory_cost, &time_cost, &threads);
268 add_assoc_long(
return_value,
"memory_cost", memory_cost);
277 zend_long new_memory_cost = PHP_PASSWORD_ARGON2_MEMORY_COST, memory_cost = 0;
278 zend_long new_time_cost = PHP_PASSWORD_ARGON2_TIME_COST, time_cost = 0;
279 zend_long new_threads = PHP_PASSWORD_ARGON2_THREADS, threads = 0;
283 new_memory_cost = zval_get_long(option_buffer);
287 new_time_cost = zval_get_long(option_buffer);
291 new_threads = zval_get_long(option_buffer);
294 extract_argon2_parameters(
hash, &
v, &memory_cost, &time_cost, &threads);
296 return (new_time_cost != time_cost) ||
297 (new_memory_cost != memory_cost) ||
298 (new_threads != threads);
304 size_t time_cost = PHP_PASSWORD_ARGON2_TIME_COST;
305 size_t memory_cost = PHP_PASSWORD_ARGON2_MEMORY_COST;
306 size_t threads = PHP_PASSWORD_ARGON2_THREADS;
311 memory_cost = zval_get_long(option_buffer);
314 if (memory_cost > ARGON2_MAX_MEMORY || memory_cost < ARGON2_MIN_MEMORY) {
320 time_cost = zval_get_long(option_buffer);
323 if (time_cost > ARGON2_MAX_TIME || time_cost < ARGON2_MIN_TIME) {
329 threads = zval_get_long(option_buffer);
332 if (threads > ARGON2_MAX_LANES || threads == 0) {
341 out = zend_string_alloc(32, 0);
342 encoded_len = argon2_encodedlen(
351 encoded = zend_string_alloc(encoded_len - 1, 0);
365 ARGON2_VERSION_NUMBER
371 if (
status != ARGON2_OK) {
372 zend_string_efree(encoded);
388 return php_password_argon2_hash(password,
options, Argon2_i);
393 php_password_argon2i_hash,
394 php_password_argon2i_verify,
395 php_password_argon2_needs_rehash,
396 php_password_argon2_get_info,
407 return php_password_argon2_hash(password,
options, Argon2_id);
412 php_password_argon2id_hash,
413 php_password_argon2id_verify,
414 php_password_argon2_needs_rehash,
415 php_password_argon2_get_info,
446 if (!tsrm_is_main_thread()) {
487 case 2:
return &php_password_algo_argon2i;
488 case 3:
return &php_password_algo_argon2id;
494 zend_string_release(
n);
501 zend_string_release(
n);
511 const char *ident, *ident_end;
519 ident_end =
strchr(ident,
'$');
525 return zend_string_init(ident, ident_end - ident, 0);
537 zend_string_release(ident);
538 return (!algo || (algo->
valid && !algo->
valid(
hash))) ? default_algo : algo;
559 zend_string_release(ident);
568 zend_string_release(ident);
585 bool new_algo_is_null;
595 new_algo = php_password_algo_find_zval(new_algo_str, new_algo_long, new_algo_is_null);
602 if (old_algo != new_algo) {
622 algo = php_password_algo_identify(
hash);
644 algo = php_password_algo_find_zval(algo_str, algo_long, algo_is_null);
password_verify(#[\SensitiveParameter] string $password, string $hash)
password_get_info(string $hash)
sscanf(string $string, string $format, mixed &... $vars)
password_needs_rehash(string $hash, string|int|null $algo, array $options=[])
strchr(string $haystack, string $needle, bool $before_needle=false)
password_hash(#[\SensitiveParameter] string $password, string|int|null $algo, array $options=[])
PHPAPI zend_string * php_crypt(const char *password, const int pass_len, const char *salt, int salt_len, bool quiet)
hash(string $algo, string $data, bool $binary=false, array $options=[])
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
zend_string * php_password_algo_extract_ident(const zend_string *hash)
register_password_symbols(module_number)
void php_password_algo_unregister(const char *ident)
const php_password_algo * php_password_algo_find(const zend_string *ident)
const php_password_algo * php_password_algo_identify_ex(const zend_string *hash, const php_password_algo *default_algo)
int php_password_algo_register(const char *ident, const php_password_algo *algo)
const php_password_algo * php_password_algo_default(void)
const php_password_algo php_password_algo_bcrypt
#define PHP_MSHUTDOWN_FUNCTION
#define PHP_MINIT_FUNCTION
PHPAPI int php_safe_bcmp(const zend_string *a, const zend_string *b)
unsigned const char * pos
PHP_JSON_API size_t int options
#define PHP_PASSWORD_BCRYPT_COST
struct _php_password_algo php_password_algo
unsigned char key[REFLECTION_KEY_LEN]
bool(* valid)(const zend_string *hash)
int(* get_info)(zval *return_value, const zend_string *hash)
zend_string *(* hash)(const zend_string *password, zend_array *options)
bool(* needs_rehash)(const zend_string *password, zend_array *options)
bool(* verify)(const zend_string *password, const zend_string *hash)
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format,...)
ZEND_API ZEND_COLD void zend_value_error(const char *format,...)
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format,...)
ZEND_API zend_result add_next_index_str(zval *arg, zend_string *str)
#define ZEND_PARSE_PARAMETERS_END()
#define ZEND_PARSE_PARAMETERS_NONE()
#define Z_PARAM_STR(dest)
#define Z_PARAM_STR_OR_LONG_OR_NULL(dest_str, dest_long, is_null)
#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args)
#define RETURN_NEW_STR(s)
#define Z_PARAM_ARRAY_HT(dest)
zend_string_release_ex(func->internal_function.function_name, 0)
ZEND_API void ZEND_FASTCALL zend_hash_destroy(HashTable *ht)
ZEND_API zval *ZEND_FASTCALL zend_hash_str_find(const HashTable *ht, const char *str, size_t len)
ZEND_API zend_result ZEND_FASTCALL zend_hash_str_del(HashTable *ht, const char *str, size_t len)
ZEND_API zval *ZEND_FASTCALL zend_hash_find(const HashTable *ht, zend_string *key)
#define zend_hash_init(ht, nSize, pHashFunction, pDestructor, persistent)
#define ZEND_HASH_MAP_FOREACH_STR_KEY(ht, _key)
#define ZEND_HASH_FOREACH_END()
#define ZEND_LONG_FMT_SPEC
struct _zend_string zend_string
struct _zend_array zend_array
ZEND_API zend_string * zend_string_concat2(const char *str1, size_t str1_len, const char *str2, size_t str2_len)
ZEND_API zend_string_init_interned_func_t zend_string_init_interned
#define ZSTR_INIT_LITERAL(s, persistent)
struct _zend_array HashTable