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--FILE--
12<?php
13
14echo 'Argon2 provider: ';
15var_dump(PASSWORD_ARGON2_PROVIDER);
16
17foreach([1, 2, 4] as $mem) {
18  foreach([1, 2, 4] as $time) {
19    $opts = [
20      'memory_cost' => PASSWORD_ARGON2_DEFAULT_MEMORY_COST * $mem,
21      'time_cost'   => PASSWORD_ARGON2_DEFAULT_TIME_COST * $time,
22      'threads'     => PASSWORD_ARGON2_DEFAULT_THREADS,
23    ];
24    $password = random_bytes(32);
25    echo "Using password: ";
26    var_dump(base64_encode($password));
27    $hash = password_hash($password, 'argon2i', $opts);
28    echo "Hash: "; var_dump($hash);
29    var_dump(sodium_crypto_pwhash_str_verify($hash, $password));
30
31    // And verify that incorrect passwords fail.
32    $password[0] = chr(ord($password[0]) ^ 1);
33    var_dump(sodium_crypto_pwhash_str_verify($hash, $password));
34  }
35}
36--EXPECTF--
37Argon2 provider: string(%d) "%s"
38Using password: string(44) "%s"
39Hash: string(96) "$argon2i$v=19$m=65536,t=4,p=1$%s$%s"
40bool(true)
41bool(false)
42Using password: string(44) "%s"
43Hash: string(96) "$argon2i$v=19$m=65536,t=8,p=1$%s$%s"
44bool(true)
45bool(false)
46Using password: string(44) "%s"
47Hash: string(97) "$argon2i$v=19$m=65536,t=16,p=1$%s$%s"
48bool(true)
49bool(false)
50Using password: string(44) "%s"
51Hash: string(97) "$argon2i$v=19$m=131072,t=4,p=1$%s$%s"
52bool(true)
53bool(false)
54Using password: string(44) "%s"
55Hash: string(97) "$argon2i$v=19$m=131072,t=8,p=1$%s$%s"
56bool(true)
57bool(false)
58Using password: string(44) "%s"
59Hash: string(98) "$argon2i$v=19$m=131072,t=16,p=1$%s$%s"
60bool(true)
61bool(false)
62Using password: string(44) "%s"
63Hash: string(97) "$argon2i$v=19$m=262144,t=4,p=1$%s$%s"
64bool(true)
65bool(false)
66Using password: string(44) "%s"
67Hash: string(97) "$argon2i$v=19$m=262144,t=8,p=1$%s$%s"
68bool(true)
69bool(false)
70Using password: string(44) "%s"
71Hash: string(98) "$argon2i$v=19$m=262144,t=16,p=1$%s$%s"
72bool(true)
73bool(false)
74