PHP Argon2内存使用率不反映在内存使用率上
我想在我的系统中使用Argon2作为密码的哈希算法,我正试图找到正确的参数来设置它。我正在使用PHP 在测试一些变体时,我试图了解使用Argon2对内存的影响 提到这一点:PHP Argon2内存使用率不反映在内存使用率上,php,passwords,php-7,password-hash,argon2-ffi,Php,Passwords,Php 7,Password Hash,Argon2 Ffi,我想在我的系统中使用Argon2作为密码的哈希算法,我正试图找到正确的参数来设置它。我正在使用PHP 在测试一些变体时,我试图了解使用Argon2对内存的影响 提到这一点: memory_cost (integer) - Maximum memory (in kibibytes) that may be used to compute the Argon2 hash. Defaults to PASSWORD_ARGON2_DEFAULT_MEMORY_COST. 然而,使用PHP的函数mem
memory_cost (integer) - Maximum memory (in kibibytes) that may be used to compute the Argon2 hash. Defaults to PASSWORD_ARGON2_DEFAULT_MEMORY_COST.
然而,使用PHP的函数memory\u get\u peak\u usage
我的脚本消耗的内存量似乎从未受到影响。以下是一个例子:
$hash = password_hash('password1', PASSWORD_ARGON2I, ['memory_cost' => (1024*100), 'time_cost' => 20, 'threads' => 2]); // Should require 100MiB
$memory_peak = memory_get_peak_usage(true);
echo $memory_peak / (1024*1024); // To have the result in MiB
在我的系统上,执行此操作需要约0.5秒,但内存使用量始终为2MB
有人能解释一下为什么使用Argon2的
memory\u cost
参数不会影响PHP内存使用吗?FYI,我删除了我的答案。经过一点实验,我意识到我也不知道这里到底发生了什么。这让我很困惑。请参见上的注释。memory_get_usage()跟踪通过PHP自己的分配器分配的内存。第三方库使用的内存没有被它跟踪。@NikiC是第三方吗password\u hash
和password\u ARGON2I
是PHP的核心,它只能使用--with-password-argon2
@MaxiWheat进行编译。ARGON2I实现由libargon2或libnaude提供,而libargon2不是PHP的一部分。