xref: /PHP-7.3/ext/sodium/tests/pwhash_scrypt.phpt (revision 34df3cda)
1--TEST--
2Check for libsodium scrypt
3--SKIPIF--
4<?php if (!extension_loaded("sodium")) print "skip";
5if (!defined('SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_SALTBYTES')) print "skip libsodium without scrypt"; ?>
6--FILE--
7<?php
8$passwd = 'test';
9
10$hash = sodium_crypto_pwhash_scryptsalsa208sha256_str
11  ($passwd, SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_OPSLIMIT_INTERACTIVE,
12			SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_MEMLIMIT_INTERACTIVE);
13var_dump(substr($hash, 0, 3) ===
14		 SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_STRPREFIX);
15
16$c = sodium_crypto_pwhash_scryptsalsa208sha256_str_verify($hash, $passwd);
17var_dump($c);
18
19$c = sodium_crypto_pwhash_scryptsalsa208sha256_str_verify($hash, 'passwd');
20var_dump($c);
21
22$salt = random_bytes(SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_SALTBYTES);
23$out_len = 100;
24$key = sodium_crypto_pwhash_scryptsalsa208sha256
25  ($out_len, $passwd, $salt,
26   SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_OPSLIMIT_INTERACTIVE,
27   SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_MEMLIMIT_INTERACTIVE);
28var_dump(strlen($key) === $out_len);
29?>
30--EXPECT--
31bool(true)
32bool(true)
33bool(false)
34bool(true)
35