1--TEST--
2Compatibility of password_hash (libsodium / openssl)
3--EXTENSIONS--
4openssl
5sodium
6--SKIPIF--
7<?php
8if (!function_exists('sodium_crypto_pwhash_str_verify')) {
9    echo "skip - No crypto_pwhash_str_verify";
10}
11
12if (!function_exists('openssl_password_hash')) {
13    echo "skip - No crypto_pwhash_str_verify";
14}
15?>
16--FILE--
17<?php
18
19echo 'Argon2 provider: ';
20var_dump(PASSWORD_ARGON2_PROVIDER);
21
22foreach([1, 2] as $mem) {
23    foreach([1, 2] as $time) {
24        $opts = [
25            'memory_cost' => PASSWORD_ARGON2_DEFAULT_MEMORY_COST / $mem,
26            'time_cost'   => PASSWORD_ARGON2_DEFAULT_TIME_COST / $time,
27            'threads'     => PASSWORD_ARGON2_DEFAULT_THREADS,
28        ];
29        $algo = 'argon2id';
30        $pass = "secret$mem$time$algo";
31
32        /* hash with libsodium / verify with openssl */
33        $hash = sodium_crypto_pwhash_str($pass, PASSWORD_ARGON2_DEFAULT_TIME_COST / $time, PASSWORD_ARGON2_DEFAULT_MEMORY_COST / $mem);
34        var_dump(openssl_password_verify($algo, $pass, $hash));
35
36        /* hash with openssl / verify with libsodium */
37        $hash = openssl_password_hash($algo, $pass, $opts);
38        var_dump(sodium_crypto_pwhash_str_verify($hash, $pass));
39    }
40}
41?>
42--EXPECTF--
43Argon2 provider: string(%d) "%s"
44bool(true)
45bool(true)
46bool(true)
47bool(true)
48bool(true)
49bool(true)
50bool(true)
51bool(true)
52
53