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