1--TEST--
2Check for libsodium argon2i
3--SKIPIF--
4<?php if (!extension_loaded("sodium")) print "skip";
5if (!defined('SODIUM_CRYPTO_PWHASH_SALTBYTES')) print "skip libsodium without argon2i"; ?>
6--FILE--
7<?php
8$passwd = 'password';
9
10$hash = sodium_crypto_pwhash_str
11  ($passwd, SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
12            SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE);
13var_dump(substr($hash, 0, strlen(SODIUM_CRYPTO_PWHASH_STRPREFIX)) ===
14         SODIUM_CRYPTO_PWHASH_STRPREFIX);
15
16$testHash = '$argon2i$v=19$m=4096,t=3,p=1$MzE4ODFiZWFlMjAzOWUAAA$FWUV6tsyJ32qThiLi1cCsLIbf3dIOG/RwXcTzt536KY';
17$c = sodium_crypto_pwhash_str_verify($testHash, $passwd);
18var_dump($c);
19
20$testHash = '$argon2i$v=19$m=4096,t=0,p=1$c29tZXNhbHQAAAAAAAAAAA$JTBozgKQiCn5yKAm3Hz0vUSX/XgfqhZloNCxDWmeDr0';
21$c = sodium_crypto_pwhash_str_verify($testHash, $passwd);
22var_dump($c);
23
24$c = sodium_crypto_pwhash_str_verify($hash, $passwd);
25var_dump($c);
26
27$c = sodium_crypto_pwhash_str_verify($hash, 'passwd');
28var_dump($c);
29
30$salt = random_bytes(SODIUM_CRYPTO_PWHASH_SALTBYTES);
31$out_len = 100;
32$key = sodium_crypto_pwhash
33  ($out_len, $passwd, $salt,
34   SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
35   SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE,
36   SODIUM_CRYPTO_PWHASH_ALG_DEFAULT);
37var_dump(strlen($key) === $out_len);
38$key2 = sodium_crypto_pwhash
39  ($out_len, $passwd, $salt,
40   SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
41   SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE);
42var_dump($key2 === $key);
43?>
44--EXPECT--
45bool(true)
46bool(true)
47bool(false)
48bool(true)
49bool(false)
50bool(true)
51bool(true)
52