1--TEST--
2Test interoperability of password_hash('argon2id')
3--SKIPIF--
4<?php
5if (!function_exists('sodium_crypto_pwhash_str_verify')) {
6  echo "skip - No crypto_pwhash_str_verify";
7}
8if (!in_array('argon2id', password_algos(), true /* strict */)) {
9  echo "skip - No argon2id support in password_hash()";
10}
11--FILE--
12<?php
13
14echo 'Argon2 provider: ';
15var_dump(PASSWORD_ARGON2_PROVIDER);
16
17foreach([1, 2] as $mem) {
18  foreach([1, 2] 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, 'argon2id', $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?>
37--EXPECTF--
38Argon2 provider: string(%d) "%s"
39Using password: string(44) "%s"
40Hash: string(97) "$argon2id$v=19$m=65536,t=4,p=1$%s$%s"
41bool(true)
42bool(false)
43Using password: string(44) "%s"
44Hash: string(97) "$argon2id$v=19$m=65536,t=8,p=1$%s$%s"
45bool(true)
46bool(false)
47Using password: string(44) "%s"
48Hash: string(98) "$argon2id$v=19$m=131072,t=4,p=1$%s$%s"
49bool(true)
50bool(false)
51Using password: string(44) "%s"
52Hash: string(98) "$argon2id$v=19$m=131072,t=8,p=1$%s$%s"
53bool(true)
54bool(false)
55