scrypt
Modulescrypt() of the PECL scrypt extension 2.0.1, which Utopia\Auth\Hashes\Scrypt and
ScryptModified call: the scrypt KDF of RFC 7914 (Colin Percival's crypto_scrypt), with
the extension's checks, in its order and with its messages.
PHP allocates scrypt's working memory with the system allocator (posix_memalign and an
anonymous mmap), outside memory_limit, and returns false when it cannot; so does
scrypt, whose buffers are reserved fallibly.
Contents
use utopia_auth::scrypt::Failure;pub enum Failure {
Error(String),
Warning(&'static str),
False,
}How scrypt() fails.
use utopia_auth::scrypt::scrypt;pub fn scrypt(
password: &[u8],
salt: &[u8],
n: i64,
r: i64,
p: i64,
key_length: i64,
) -> Result<Vec<u8>, Failure>scrypt($password, $salt, $N, $r, $p, $keyLength, true): the raw derived key (PHP's
default output is its hex, bin2hex() of this).
Errors
As PHP scrypt() fails: the Error its arguments raise ($N not a power of 2 greater
than 1, $r or $p below 1 or above 2^32 - 1, $keyLength below 16 or above
(2^32 - 1) * 32), the warning and false of crypto_scrypt's checks ($r * $p of
2^30 or more, or memory beyond the address space), and false when memory runs out.