@ 2022-09-23T15:55:59Z <?php
function test_native() {
$st = hrtime(true);
$h = hash_pbkdf2('sha256', 'password', 'salt', 100000);
$et = hrtime(true);
return [$h, $et - $st];
}
function test_emulated() {
$st = hrtime(true);
$K = str_pad('password', 64, "\0");
$K ^= str_repeat("\x36", 64);
$ictx = hash_init('sha256');
hash_update($ictx, $K);
$K ^= str_repeat("\x6a", 64);
$octx = hash_init('sha256');
hash_update($octx, $K);
$DK = str_repeat("\0", 32);
$prev = "salt\0\0\0\1";
for ($j = 0; $j < 100000; ++$j) {
$ctx = hash_copy($ictx);
hash_update($ctx, $prev);
$temp = hash_final($ctx, true);
$ctx = hash_copy($octx);
hash_update($ctx, $temp);
$prev = hash_final($ctx, true);
$DK ^= $prev;
}
$h = bin2hex($DK);
$et = hrtime(true);
return [$h, $et - $st];
}
$nr = test_native();
$er = test_emulated();
var_dump($nr[0]);
var_dump($er[0]);
var_dump($nr[1] <= $er[1]);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 8.3.6 0.013 0.371 16.75 8.3.5 0.017 0.380 20.44 8.3.4 0.013 0.376 20.34 8.3.3 0.007 0.391 18.70 8.3.2 0.007 0.200 24.18 8.3.1 0.003 0.216 24.66 8.3.0 0.003 0.202 26.16 8.2.18 0.013 0.384 25.92 8.2.17 0.000 0.403 19.04 8.2.16 0.013 0.376 22.96 8.2.15 0.003 0.209 25.66 8.2.14 0.003 0.202 24.66 8.2.13 0.007 0.201 26.16 8.2.12 0.003 0.203 26.16 8.2.11 0.003 0.248 22.13 8.2.10 0.003 0.316 20.70 8.1.28 0.007 0.388 25.92 8.1.27 0.003 0.204 24.66 8.1.26 0.003 0.203 26.35 8.1.25 0.007 0.200 28.09 8.1.24 0.007 0.235 18.70 8.1.23 0.010 0.237 18.67 8.1.10 0.005 0.266 17.46
preferences:dark mode live preview
44.04 ms | 401 KiB | 5 Q