Skip to Content
oxcrypto

scrypt

Create memory-hard password records or derive key bytes with scrypt.

from secrets import token_bytes

from oxcrypto.password.scrypt import SCRYPT

algorithm = SCRYPT.SCRYPT
key = algorithm.derive(b"passphrase", salt=token_bytes(16), log_n=17, r=8, p=1, length=32)

The raw KDF takes log_n (log₂ of the CPU and memory cost), r (block size), and p (parallelization). For password storage, use hash and verify.

hash takes the same keyword-only log_n, r and p (defaults 17, 8, 1) and a format: "phc" (default, $scrypt$ln=…) or "mcf" (the libxcrypt $7$ format used by mkpasswd --method=scrypt). verify accepts both formats.

encoded = algorithm.hash(b"passphrase", log_n=15, r=8, p=1, format="mcf")
assert algorithm.verify(b"passphrase", encoded)

scrypt is specified in RFC 7914 (Informational). The implementation is the RustCrypto scrypt crate 0.12.0, a stable release with no published audit. Tests use the RFC 7914 section 12 vectors and the $7$ record from the crate's own MCF tests.