29#if SODIUM_LIBRARY_VERSION_MAJOR > 9 || (SODIUM_LIBRARY_VERSION_MAJOR == 9 && SODIUM_LIBRARY_VERSION_MINOR >= 6)
31static inline int get_options(
zend_array *
options,
size_t *memlimit,
size_t *opslimit) {
34 *opslimit = PHP_SODIUM_PWHASH_OPSLIMIT;
35 *memlimit = PHP_SODIUM_PWHASH_MEMLIMIT << 10;
42 if ((smemlimit < 0) || (smemlimit < crypto_pwhash_MEMLIMIT_MIN >> 10) || (smemlimit > (crypto_pwhash_MEMLIMIT_MAX >> 10))) {
46 *memlimit = smemlimit << 10;
49 *opslimit = zval_get_long(opt);
56 zend_value_error(
"A thread value other than 1 is not supported by this implementation");
63 size_t opslimit, memlimit;
66 if ((
ZSTR_LEN(password) >= 0xffffffff)) {
75 ret = zend_string_alloc(crypto_pwhash_STRBYTES - 1, 0);
78 zend_string_release(
ret);
96 size_t opslimit, memlimit;
101 return crypto_pwhash_str_needs_rehash(
ZSTR_VAL(
hash), opslimit, memlimit);
105 const char*
p =
NULL;
107 zend_long memory_cost = PHP_SODIUM_PWHASH_MEMLIMIT;
108 zend_long time_cost = PHP_SODIUM_PWHASH_OPSLIMIT;
115 if (!memcmp(
p,
"$argon2i$",
strlen(
"$argon2i$"))) {
117 }
else if (!memcmp(
p,
"$argon2id$",
strlen(
"$argon2id$"))) {
124 &
v, &memory_cost, &time_cost, &threads);
126 add_assoc_long(
return_value,
"memory_cost", memory_cost);
136 return php_sodium_argon2_hash(password,
options, crypto_pwhash_ALG_ARGON2I13);
141 php_sodium_argon2i_hash,
142 php_sodium_argon2_verify,
143 php_sodium_argon2_needs_rehash,
144 php_sodium_argon2_get_info,
151 return php_sodium_argon2_hash(password,
options, crypto_pwhash_ALG_ARGON2ID13);
156 php_sodium_argon2id_hash,
157 php_sodium_argon2_verify,
158 php_sodium_argon2_needs_rehash,
159 php_sodium_argon2_get_info,
168 zend_string_release(argon2i);
171 zend_string_release(argon2i);
173 register_sodium_pwhash_symbols(module_number);
sscanf(string $string, string $format, mixed &... $vars)
hash(string $algo, string $data, bool $binary=false, array $options=[])
#define crypto_pwhash_OPSLIMIT_MIN
const php_password_algo * php_password_algo_find(const zend_string *ident)
int php_password_algo_register(const char *ident, const php_password_algo *algo)
#define PHP_MINIT_FUNCTION
PHP_JSON_API size_t int options
struct _php_password_algo php_password_algo
ZEND_API ZEND_COLD void zend_value_error(const char *format,...)
ZEND_API zval *ZEND_FASTCALL zend_hash_str_find(const HashTable *ht, const char *str, size_t len)
struct _zend_string zend_string
struct _zend_array zend_array
#define ZSTR_INIT_LITERAL(s, persistent)