1--TEST--
2Test interoperability of password_hash('argon2i')
3--SKIPIF--
4<?php
5if (!function_exists('sodium_crypto_pwhash_str_verify')) {
6  echo "skip - No crypto_pwhash_str_verify";
7}
8if (!in_array('argon2i', password_algos(), true /* strict */)) {
9  echo "skip - No argon2i support in password_hash()";
10}
11?>
12--FILE--
13<?php
14
15echo 'Argon2 provider: ';
16var_dump(PASSWORD_ARGON2_PROVIDER);
17
18foreach([1, 2] as $mem) {
19  foreach([1, 2] as $time) {
20    $opts = [
21      'memory_cost' => PASSWORD_ARGON2_DEFAULT_MEMORY_COST * $mem,
22      'time_cost'   => PASSWORD_ARGON2_DEFAULT_TIME_COST * $time,
23      'threads'     => PASSWORD_ARGON2_DEFAULT_THREADS,
24    ];
25    $password = random_bytes(32);
26    echo "Using password: ";
27    var_dump(base64_encode($password));
28    $hash = password_hash($password, 'argon2i', $opts);
29    echo "Hash: "; var_dump($hash);
30    var_dump(sodium_crypto_pwhash_str_verify($hash, $password));
31
32    // And verify that incorrect passwords fail.
33    $password[0] = chr(ord($password[0]) ^ 1);
34    var_dump(sodium_crypto_pwhash_str_verify($hash, $password));
35  }
36}
37?>
38--EXPECTF--
39Argon2 provider: string(%d) "%s"
40Using password: string(44) "%s"
41Hash: string(96) "$argon2i$v=19$m=65536,t=4,p=1$%s$%s"
42bool(true)
43bool(false)
44Using password: string(44) "%s"
45Hash: string(96) "$argon2i$v=19$m=65536,t=8,p=1$%s$%s"
46bool(true)
47bool(false)
48Using password: string(44) "%s"
49Hash: string(97) "$argon2i$v=19$m=131072,t=4,p=1$%s$%s"
50bool(true)
51bool(false)
52Using password: string(44) "%s"
53Hash: string(97) "$argon2i$v=19$m=131072,t=8,p=1$%s$%s"
54bool(true)
55bool(false)
56